Search is not available for this dataset
name
stringlengths
2
112
description
stringlengths
29
13k
source
int64
1
7
difficulty
int64
0
25
solution
stringlengths
7
983k
language
stringclasses
4 values
603_A. Alternative Thinking
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is not...
2
7
#include <bits/stdc++.h> using namespace std; int min(int a, int b) { return (a < b) ? a : b; } int main() { int i, n, size = 0; string seq; char c; scanf("%d", &n); cin >> seq; c = seq[0]; size++; for (i = 1; i < n; i++) if (seq[i] != c) { size++; c = seq[i]; } int ans = min(n, si...
CPP
603_A. Alternative Thinking
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is not...
2
7
#include <bits/stdc++.h> using namespace std; int n, cnt, dbl; string s; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n >> s; cnt = 1; for (int i = 1; i < n; ++i) { if (s[i] != s[i - 1]) ++cnt; else { ++dbl; } } if (dbl >= 2) cout << cnt + 2; else if (...
CPP
603_A. Alternative Thinking
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is not...
2
7
import java.util.*; public class A { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); sc.nextLine(); String s = sc.nextLine(); int len = 1; for(int i=1;i<s.length();i++) { if(s.charAt(i)!=s.charAt(i-1)) ...
JAVA
603_A. Alternative Thinking
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is not...
2
7
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.util.stream.IntStream; import java.io.OutputStream; import java.io.PrintWriter; import java.io.BufferedWriter; import java.util.InputMismatchException; import java.io.IOException; import java.io.Writer; import java.io.Outpu...
JAVA
603_A. Alternative Thinking
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is not...
2
7
import java.io.BufferedReader; import java.io.DataInputStream; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.PriorityQueue; import java.util.Rando...
JAVA
603_A. Alternative Thinking
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is not...
2
7
n, s = int(input()), input() print(min(n, s.count("01") + s.count("10") + 3))
PYTHON3
603_A. Alternative Thinking
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is not...
2
7
import java.io.*; import java.util.StringTokenizer; public class C { public static BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); public static StringTokenizer tok; public static int nextInt() throws IOException { return Integer.parseInt(nextToken()); } public ...
JAVA
603_A. Alternative Thinking
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is not...
2
7
n=int(input()) a=input() print(min(n,3+a.count('01')+a.count('10')))
PYTHON3
625_D. Finals in arithmetic
Vitya is studying in the third grade. During the last math lesson all the pupils wrote on arithmetic quiz. Vitya is a clever boy, so he managed to finish all the tasks pretty fast and Oksana Fillipovna gave him a new one, that is much harder. Let's denote a flip operation of an integer as follows: number is considered...
2
10
var str = readline(); var len = str.length; function work(type, beg, end) { var arr = new Array(len); for (var i = 0; i < len; ++i) { arr[i] = Number(str[i]); } var ans = new Array(len); var down = false; while (true) { if (beg > end) { if (type === 1 && !down || ty...
JAVA
625_D. Finals in arithmetic
Vitya is studying in the third grade. During the last math lesson all the pupils wrote on arithmetic quiz. Vitya is a clever boy, so he managed to finish all the tasks pretty fast and Oksana Fillipovna gave him a new one, that is much harder. Let's denote a flip operation of an integer as follows: number is considered...
2
10
#include <bits/stdc++.h> using namespace std; int T; string s; int a[100005]; int main() { T = 1; while (T--) { cin >> s; for (int i = 0; i < s.size(); ++i) a[i] = s[i] - '0'; int l = 0, r = s.size() - 1; if (a[l] != a[r]) { a[l]--; a[l + 1] += 10; if (!a[l]) l++; } while (...
CPP
625_D. Finals in arithmetic
Vitya is studying in the third grade. During the last math lesson all the pupils wrote on arithmetic quiz. Vitya is a clever boy, so he managed to finish all the tasks pretty fast and Oksana Fillipovna gave him a new one, that is much harder. Let's denote a flip operation of an integer as follows: number is considered...
2
10
#include <bits/stdc++.h> using namespace std; const double eps = 1e-8; const int INF = (1 << 30) - 1; const int MAXN = 100010; const int MAX_LOG = 18; const long long mod = 10007; char s[100010]; int num[100010]; int res[100010]; int ans[100010]; int sum[100010]; int L, len; bool Solve(int l, int r, int c) { int tl =...
CPP
625_D. Finals in arithmetic
Vitya is studying in the third grade. During the last math lesson all the pupils wrote on arithmetic quiz. Vitya is a clever boy, so he managed to finish all the tasks pretty fast and Oksana Fillipovna gave him a new one, that is much harder. Let's denote a flip operation of an integer as follows: number is considered...
2
10
#include <bits/stdc++.h> using namespace std; const int N = (int)2e5 + 5; const int inf = (int)1e9 + 7; string s; int SZ, SHIFT; int dp[N][2][2], ans[N]; pair<int, int> pr[N][2][2]; int solve(int p, int lc, int rc) { if (dp[p][lc][rc] != -1) { return dp[p][lc][rc]; } dp[p][lc][rc] = 0; int l = p + SHIFT; ...
CPP
625_D. Finals in arithmetic
Vitya is studying in the third grade. During the last math lesson all the pupils wrote on arithmetic quiz. Vitya is a clever boy, so he managed to finish all the tasks pretty fast and Oksana Fillipovna gave him a new one, that is much harder. Let's denote a flip operation of an integer as follows: number is considered...
2
10
#include <bits/stdc++.h> using namespace std; const int INF = 1e9; const long long LINF = 1e18; const long double EPS = 1e-10; const long double PI = 3.141592653589; const int N = 1e6; int d[N + 1]; int a[N + 1]; int b[N + 1]; void cut(int &x) { if (x >= 10) { x -= 10; } if (x < 0) { x += 10; } } void a...
CPP
625_D. Finals in arithmetic
Vitya is studying in the third grade. During the last math lesson all the pupils wrote on arithmetic quiz. Vitya is a clever boy, so he managed to finish all the tasks pretty fast and Oksana Fillipovna gave him a new one, that is much harder. Let's denote a flip operation of an integer as follows: number is considered...
2
10
#include <bits/stdc++.h> using namespace std; int ans[100001]; pair<int, int> p[100001][2][2]; int dp[100001][2][2]; int was[100001][2][2]; void go(string const& s, int i, int pl, int pr) { if (i == s.size() / 2 && s.size() % 2 == 0) { if (pl == pr) dp[i][pl][pr] = 1; return; } if (i == s.size() / 2 && s....
CPP
625_D. Finals in arithmetic
Vitya is studying in the third grade. During the last math lesson all the pupils wrote on arithmetic quiz. Vitya is a clever boy, so he managed to finish all the tasks pretty fast and Oksana Fillipovna gave him a new one, that is much harder. Let's denote a flip operation of an integer as follows: number is considered...
2
10
#include <bits/stdc++.h> using namespace std; deque<int> ans; char input[100010]; int su[100010], n; bool possible() { for (int i = 1; i <= n / 2; i++) { if (su[i] - su[n - i + 1] == 1) { su[i]--; su[i + 1] += 10; } else if (su[i] - su[n - i + 1] >= 10) { su[n - i]--; su[n - i + 1] += ...
CPP
625_D. Finals in arithmetic
Vitya is studying in the third grade. During the last math lesson all the pupils wrote on arithmetic quiz. Vitya is a clever boy, so he managed to finish all the tasks pretty fast and Oksana Fillipovna gave him a new one, that is much harder. Let's denote a flip operation of an integer as follows: number is considered...
2
10
#include <bits/stdc++.h> using namespace std; long long powmod(long long a, long long b, long long MOD) { long long res = 1; a %= MOD; for (; b; b >>= 1) { if (b & 1) res = res * a % MOD; a = a * a % MOD; } return res; } const int N = 1E5 + 5; char s[N]; int a[N]; int out[N]; bool solve(int n) { for...
CPP
625_D. Finals in arithmetic
Vitya is studying in the third grade. During the last math lesson all the pupils wrote on arithmetic quiz. Vitya is a clever boy, so he managed to finish all the tasks pretty fast and Oksana Fillipovna gave him a new one, that is much harder. Let's denote a flip operation of an integer as follows: number is considered...
2
10
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:102400000,102400000") using namespace std; const int INF = 0x3f3f3f3f; const long long INFF = 0x3f3f; const double pi = acos(-1.0); const double inf = 1e18; const double eps = 1e-8; const long long mod = 1e9 + 7; const unsigned long long mx = 133333331; inline vo...
CPP
625_D. Finals in arithmetic
Vitya is studying in the third grade. During the last math lesson all the pupils wrote on arithmetic quiz. Vitya is a clever boy, so he managed to finish all the tasks pretty fast and Oksana Fillipovna gave him a new one, that is much harder. Let's denote a flip operation of an integer as follows: number is considered...
2
10
#include <bits/stdc++.h> using namespace std; char str1[100013], str2[100013], ans[100013]; int N; bool over(char s[], int i, int mi) { while (i >= mi) { if (s[i]) { s[i]--; return false; } s[i] = 9; i--; } return true; } bool solve(char s[], int k, bool ex) { if (k * 2 >= N) { r...
CPP
625_D. Finals in arithmetic
Vitya is studying in the third grade. During the last math lesson all the pupils wrote on arithmetic quiz. Vitya is a clever boy, so he managed to finish all the tasks pretty fast and Oksana Fillipovna gave him a new one, that is much harder. Let's denote a flip operation of an integer as follows: number is considered...
2
10
#include <bits/stdc++.h> using namespace std; const int maxn = 1000005; char s[maxn], res[maxn]; int num[maxn]; bool check(int n) { for (int i = 0; i < n / 2;) { if (num[i] == num[n - i - 1]) i++; else if ((num[i] == num[n - i - 1] + 1) || (num[i] == num[n - i - 1] + 11)) { num[i]--; ...
CPP
625_D. Finals in arithmetic
Vitya is studying in the third grade. During the last math lesson all the pupils wrote on arithmetic quiz. Vitya is a clever boy, so he managed to finish all the tasks pretty fast and Oksana Fillipovna gave him a new one, that is much harder. Let's denote a flip operation of an integer as follows: number is considered...
2
10
#include <bits/stdc++.h> using namespace std; string s; int a, b, f, i, j, n, u, v; int ans[100000]; bool check(int i, int p1, int j, int p2) { if (i > j) return p1 == p2; if (i == j) { for (u = 9; u >= 0; u--) if (((2 * u + p2) % 10) + '0' == s[i] && (2 * u + p2) / 10 == p1) { ans[i] = u; ...
CPP
625_D. Finals in arithmetic
Vitya is studying in the third grade. During the last math lesson all the pupils wrote on arithmetic quiz. Vitya is a clever boy, so he managed to finish all the tasks pretty fast and Oksana Fillipovna gave him a new one, that is much harder. Let's denote a flip operation of an integer as follows: number is considered...
2
10
var str = readline(); var len = str.length; function work(type, beg, end) { var arr = new Array(len); for (var i = 0; i < len; ++i) { arr[i] = Number(str[i]); } var ans = new Array(len); var down = false; while (true) { if (down) { if (arr[end] !== 0) { ...
JAVA
625_D. Finals in arithmetic
Vitya is studying in the third grade. During the last math lesson all the pupils wrote on arithmetic quiz. Vitya is a clever boy, so he managed to finish all the tasks pretty fast and Oksana Fillipovna gave him a new one, that is much harder. Let's denote a flip operation of an integer as follows: number is considered...
2
10
import java.awt.geom.AffineTransform; import java.awt.geom.Point2D; import java.io.*; import java.util.*; public class C342D { private static StringTokenizer st; public static void nextLine(BufferedReader br) throws IOException { st = new StringTokenizer(br.readLine()); } public stat...
JAVA
625_D. Finals in arithmetic
Vitya is studying in the third grade. During the last math lesson all the pupils wrote on arithmetic quiz. Vitya is a clever boy, so he managed to finish all the tasks pretty fast and Oksana Fillipovna gave him a new one, that is much harder. Let's denote a flip operation of an integer as follows: number is considered...
2
10
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; char s[N]; int jw[N]; int A[N], n; bool solve(int n) { for (int i = 2; i < n; ++i) { int j = n - i + 1; if (i > j) break; int nx = A[i - 1] + A[j + 1]; int wL = jw[i - 1] ? s[i] - '1' : s[i] - '0'; if (nx % 10 != s[j + 1] - '0' &...
CPP
625_D. Finals in arithmetic
Vitya is studying in the third grade. During the last math lesson all the pupils wrote on arithmetic quiz. Vitya is a clever boy, so he managed to finish all the tasks pretty fast and Oksana Fillipovna gave him a new one, that is much harder. Let's denote a flip operation of an integer as follows: number is considered...
2
10
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 5; int n, a[maxn], res[maxn]; string s; void zero() { bool c = false; for (int i = 0; i < n - 1 - i; i++) { if (c) { res[i] = 9; res[n - 1 - i] = (10 + a[n - 1 - i] - 9) % 10; if (a[n - 1 - i] < 9) { --a[n - 1 - i - 1...
CPP
625_D. Finals in arithmetic
Vitya is studying in the third grade. During the last math lesson all the pupils wrote on arithmetic quiz. Vitya is a clever boy, so he managed to finish all the tasks pretty fast and Oksana Fillipovna gave him a new one, that is much harder. Let's denote a flip operation of an integer as follows: number is considered...
2
10
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; const int maxn = 100000 + 5; const long double eps = 1e-6; long double PI = acos((long double)(-1)); char s[maxn]; int l, r, sz; int main() { while (scanf("%c", &s[++sz]) == 1 && isdigit(s[sz])) s[sz] -= '0'; l = 1, r = --sz; if (s[l] != s[r])...
CPP
625_D. Finals in arithmetic
Vitya is studying in the third grade. During the last math lesson all the pupils wrote on arithmetic quiz. Vitya is a clever boy, so he managed to finish all the tasks pretty fast and Oksana Fillipovna gave him a new one, that is much harder. Let's denote a flip operation of an integer as follows: number is considered...
2
10
#include <bits/stdc++.h> using namespace std; char str1[100013], str2[100013], ans[100013]; int N; bool over(char s[], int i, int mi) { while (i >= mi) { if (s[i]) { s[i]--; return false; } s[i] = 9; i--; } return true; } bool solve(char s[], int k, bool ex) { if (k * 2 >= N) { r...
CPP
625_D. Finals in arithmetic
Vitya is studying in the third grade. During the last math lesson all the pupils wrote on arithmetic quiz. Vitya is a clever boy, so he managed to finish all the tasks pretty fast and Oksana Fillipovna gave him a new one, that is much harder. Let's denote a flip operation of an integer as follows: number is considered...
2
10
#include <bits/stdc++.h> using namespace std; const int maxn = 1e6 + 7; char s[maxn]; char ans[maxn]; int sum[maxn]; int n; int check() { for (int i = 0; i < n / 2;) { int l = i, r = n - 1 - i; if (sum[l] == sum[r]) i++; else if (sum[l] == sum[r] + 1) { sum[l]--; sum[l + 1] += 10; } ...
CPP
625_D. Finals in arithmetic
Vitya is studying in the third grade. During the last math lesson all the pupils wrote on arithmetic quiz. Vitya is a clever boy, so he managed to finish all the tasks pretty fast and Oksana Fillipovna gave him a new one, that is much harder. Let's denote a flip operation of an integer as follows: number is considered...
2
10
#include <bits/stdc++.h> using namespace std; int main() { char s[100005]; int n = 0, l, r; while (scanf("%c", &s[++n]) == 1 && s[n] >= '0' && s[n] <= '9') s[n] -= '0'; l = 1; r = --n; if (s[l] != s[r]) { s[l]--; s[l + 1] += 10; if (s[l] == 0) l++; } while (l <= r) { if (s[l] != s[r]) { ...
CPP
625_D. Finals in arithmetic
Vitya is studying in the third grade. During the last math lesson all the pupils wrote on arithmetic quiz. Vitya is a clever boy, so he managed to finish all the tasks pretty fast and Oksana Fillipovna gave him a new one, that is much harder. Let's denote a flip operation of an integer as follows: number is considered...
2
10
import java.util.*; public class ProblemD2 { private static String ans; private static void pretreat(StringBuilder s){ for(int i = 0; i < s.length(); ++i){ if(s.charAt(i) != '0'){ s = s.delete(0, i); ...
JAVA
625_D. Finals in arithmetic
Vitya is studying in the third grade. During the last math lesson all the pupils wrote on arithmetic quiz. Vitya is a clever boy, so he managed to finish all the tasks pretty fast and Oksana Fillipovna gave him a new one, that is much harder. Let's denote a flip operation of an integer as follows: number is considered...
2
10
#include <bits/stdc++.h> using namespace std; const int NMAX = 100005; char B[NMAX]; int A[NMAX]; int ans[NMAX]; char fans[NMAX]; bool solve(int left, int right) { if (left > right) return false; int l = left, r = right; for (int i = 1; i <= right; ++i) { A[i] = B[i] - '0'; } memset(ans, 0, sizeof ans); ...
CPP
625_D. Finals in arithmetic
Vitya is studying in the third grade. During the last math lesson all the pupils wrote on arithmetic quiz. Vitya is a clever boy, so he managed to finish all the tasks pretty fast and Oksana Fillipovna gave him a new one, that is much harder. Let's denote a flip operation of an integer as follows: number is considered...
2
10
#include <bits/stdc++.h> template <typename T> bool domax(T &a, T b) { return (b > a ? (a = b, true) : false); } template <typename T> bool domin(T &a, T b) { return (b < a ? (a = b, true) : false); } const int MaxN = 100005; char ss[MaxN]; int N, n[MaxN], sum[MaxN], ans[MaxN]; int startl, startr; void go(int l, in...
CPP
625_D. Finals in arithmetic
Vitya is studying in the third grade. During the last math lesson all the pupils wrote on arithmetic quiz. Vitya is a clever boy, so he managed to finish all the tasks pretty fast and Oksana Fillipovna gave him a new one, that is much harder. Let's denote a flip operation of an integer as follows: number is considered...
2
10
#include <bits/stdc++.h> using namespace std; const int maxn = 100010; char s[maxn]; int dig[maxn], l, r, R; void tn(int x) { dig[x - 1]--; dig[x] += 10; } void solve() { scanf("%s", s + 1); l = 1, R = r = strlen(s + 1); for (int i = l; i <= r; ++i) { dig[i] = s[i] - '0'; } if (dig[l] != dig[r]) { ...
CPP
625_D. Finals in arithmetic
Vitya is studying in the third grade. During the last math lesson all the pupils wrote on arithmetic quiz. Vitya is a clever boy, so he managed to finish all the tasks pretty fast and Oksana Fillipovna gave him a new one, that is much harder. Let's denote a flip operation of an integer as follows: number is considered...
2
10
#include <bits/stdc++.h> using namespace std; string S; int carry[101010]; int sum[101010]; int decdec(int l, string& S) { while (1) { if (l >= S.size()) return 0; S[l]--; if (S[l] >= 0) break; S[l] += 10; l++; } return 1; } string trytry(int L, string S) { int i, j; for (i = 0; i < ((L + ...
CPP
625_D. Finals in arithmetic
Vitya is studying in the third grade. During the last math lesson all the pupils wrote on arithmetic quiz. Vitya is a clever boy, so he managed to finish all the tasks pretty fast and Oksana Fillipovna gave him a new one, that is much harder. Let's denote a flip operation of an integer as follows: number is considered...
2
10
#include <bits/stdc++.h> using namespace std; int al[1100000]; int r[1100000]; int n; void printSolution() { for (int i = 0; i < n; i++) { printf("%c", (char)(r[i] + '0')); } printf("\n"); } bool weirdAssFunctionWhatTheFuck() { for (int i = 0; i < n / 2; i++) { while (al[i] != al[n - 1 - i]) { if ...
CPP
625_D. Finals in arithmetic
Vitya is studying in the third grade. During the last math lesson all the pupils wrote on arithmetic quiz. Vitya is a clever boy, so he managed to finish all the tasks pretty fast and Oksana Fillipovna gave him a new one, that is much harder. Let's denote a flip operation of an integer as follows: number is considered...
2
10
#include <bits/stdc++.h> using namespace std; char s[100100]; int x[100100], m; char ans[100100]; char y[100100], e[100100], d[100100]; bool get() { memcpy(e, y, sizeof e); reverse(e, e + m); int k = 0; for (int i = 0; e[i]; i++) { int a = e[i] - 48, b = y[i] - 48; a += b + k; if (a > 9) a -= ...
CPP
625_D. Finals in arithmetic
Vitya is studying in the third grade. During the last math lesson all the pupils wrote on arithmetic quiz. Vitya is a clever boy, so he managed to finish all the tasks pretty fast and Oksana Fillipovna gave him a new one, that is much harder. Let's denote a flip operation of an integer as follows: number is considered...
2
10
#include <bits/stdc++.h> using namespace std; bool debug = 0; int n, m, k; int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0}; string direc = "RDLU"; long long ln, lk, lm; char s[100005]; int out[100005]; int st; int vp[100005]; bool cal(int i, int j, int h, int t) { if (j < i) return h == t; vp[i] += 10 * h; vp[j]...
CPP
625_D. Finals in arithmetic
Vitya is studying in the third grade. During the last math lesson all the pupils wrote on arithmetic quiz. Vitya is a clever boy, so he managed to finish all the tasks pretty fast and Oksana Fillipovna gave him a new one, that is much harder. Let's denote a flip operation of an integer as follows: number is considered...
2
10
#include <bits/stdc++.h> using namespace std; int n, h, l, r, f, a[100010], ans[100010]; char s[100010]; int main() { scanf("%s", &s); n = strlen(s); for (int i = 1; i <= n; i++) a[i] = s[i - 1] - '0'; l = 1, r = n, f = 1; if (a[l] != a[r]) { a[l]--; a[l + 1] += 10; if (a[l] == 0) l++; } while...
CPP
625_D. Finals in arithmetic
Vitya is studying in the third grade. During the last math lesson all the pupils wrote on arithmetic quiz. Vitya is a clever boy, so he managed to finish all the tasks pretty fast and Oksana Fillipovna gave him a new one, that is much harder. Let's denote a flip operation of an integer as follows: number is considered...
2
10
#include <bits/stdc++.h> using namespace std; const int maxn = 100100; int n; string s; int a[maxn]; int ans[maxn], done; void check(int l, int dl, int r, int dr) { while (1) { if (l == r) { if ((a[l] - dr) & 1) return; ans[l] = (dl * 10 + a[l]) / 2; done = true; return; } else if (l =...
CPP
625_D. Finals in arithmetic
Vitya is studying in the third grade. During the last math lesson all the pupils wrote on arithmetic quiz. Vitya is a clever boy, so he managed to finish all the tasks pretty fast and Oksana Fillipovna gave him a new one, that is much harder. Let's denote a flip operation of an integer as follows: number is considered...
2
10
import java.io.BufferedReader; import java.io.OutputStream; import java.io.PrintWriter; import java.io.IOException; import java.util.StringTokenizer; import java.io.InputStream; import java.io.InputStreamReader; /** * Built using CHelper plug-in * Actual solution is at the top */ public class Main { public static ...
JAVA
625_D. Finals in arithmetic
Vitya is studying in the third grade. During the last math lesson all the pupils wrote on arithmetic quiz. Vitya is a clever boy, so he managed to finish all the tasks pretty fast and Oksana Fillipovna gave him a new one, that is much harder. Let's denote a flip operation of an integer as follows: number is considered...
2
10
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 5; int a[maxn], b[maxn]; bool f(int l, int r, int lc, int rc) { int lz = 1; while (l <= r) { a[l] += 10 * lc; a[r] -= rc; if (a[l] - a[r] > 9) a[r] += 10, rc = 1; else rc = 0; if (a[l] > a[r]) a[l]--, lc = 1; ...
CPP
625_D. Finals in arithmetic
Vitya is studying in the third grade. During the last math lesson all the pupils wrote on arithmetic quiz. Vitya is a clever boy, so he managed to finish all the tasks pretty fast and Oksana Fillipovna gave him a new one, that is much harder. Let's denote a flip operation of an integer as follows: number is considered...
2
10
#include <bits/stdc++.h> using namespace std; char aim1[100010]; int aim2[100010]; int ans[100010]; int n; void print(int beg) { for (int i = beg; i < n; i++) { if (i <= (beg + n - 1) >> 1) { if ((n - beg) % 2 && i == (beg + n - 1) >> 1) { printf("%d", ans[i] / 2); continue; } if...
CPP
625_D. Finals in arithmetic
Vitya is studying in the third grade. During the last math lesson all the pupils wrote on arithmetic quiz. Vitya is a clever boy, so he managed to finish all the tasks pretty fast and Oksana Fillipovna gave him a new one, that is much harder. Let's denote a flip operation of an integer as follows: number is considered...
2
10
#include <bits/stdc++.h> using namespace std; char str[1000005]; int num[1000005]; int main() { scanf("%s", str); int len = strlen(str); for (int i = 0; i < len; i++) num[i] = str[i] - '0'; int l = 0, r = len - 1; if (num[l] != num[r]) { num[l]--; num[l + 1] += 10; if (num[l] == 0) l++; } whil...
CPP
625_D. Finals in arithmetic
Vitya is studying in the third grade. During the last math lesson all the pupils wrote on arithmetic quiz. Vitya is a clever boy, so he managed to finish all the tasks pretty fast and Oksana Fillipovna gave him a new one, that is much harder. Let's denote a flip operation of an integer as follows: number is considered...
2
10
#include <bits/stdc++.h> using namespace std; int main() { char input[100005]; int n[100005]; cin >> input; int len = strlen(input); for (int i = 0; i < len; i++) n[i] = input[i] - '0'; int sum[len]; memset(sum, 0, sizeof(sum)); int flag = 0; if (n[0] == 1 && n[len - 1] != 1) { flag = 2; } else ...
CPP
625_D. Finals in arithmetic
Vitya is studying in the third grade. During the last math lesson all the pupils wrote on arithmetic quiz. Vitya is a clever boy, so he managed to finish all the tasks pretty fast and Oksana Fillipovna gave him a new one, that is much harder. Let's denote a flip operation of an integer as follows: number is considered...
2
10
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; char s[N]; int a[N], b[N], n; int f[N][2][2]; pair<int, int> g1[N][2][2], g2[N][2][2]; void solve() { for (int l = 0, r = n + 1; l <= r; l++, r--) { if (l + 1 == r || l == r) break; int i = l; for (int j = 0; j < 2; j++) { for (int...
CPP
625_D. Finals in arithmetic
Vitya is studying in the third grade. During the last math lesson all the pupils wrote on arithmetic quiz. Vitya is a clever boy, so he managed to finish all the tasks pretty fast and Oksana Fillipovna gave him a new one, that is much harder. Let's denote a flip operation of an integer as follows: number is considered...
2
10
#include <bits/stdc++.h> const int MN = 1e5 + 44; char n[MN]; char res[MN]; void check(char tab[], int len, bool start) { bool isdone = false, isneeded = start; for (int i = 0; i * 2 < len - 1; ++i) { int dig = tab[len - i - 1] - (isdone ? 1 : 0); int aim = tab[i] + (isneeded ? 10 : 0); if (aim == dig) ...
CPP
625_D. Finals in arithmetic
Vitya is studying in the third grade. During the last math lesson all the pupils wrote on arithmetic quiz. Vitya is a clever boy, so he managed to finish all the tasks pretty fast and Oksana Fillipovna gave him a new one, that is much harder. Let's denote a flip operation of an integer as follows: number is considered...
2
10
#include <bits/stdc++.h> using namespace std; template <typename T> T in() { char ch; T n = 0; bool ng = false; while (1) { ch = getchar(); if (ch == '-') { ng = true; ch = getchar(); break; } if (ch >= '0' && ch <= '9') break; } while (1) { n = n * 10 + (ch - '0'); ...
CPP
625_D. Finals in arithmetic
Vitya is studying in the third grade. During the last math lesson all the pupils wrote on arithmetic quiz. Vitya is a clever boy, so he managed to finish all the tasks pretty fast and Oksana Fillipovna gave him a new one, that is much harder. Let's denote a flip operation of an integer as follows: number is considered...
2
10
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 10; char s[maxn]; int a[maxn], res[maxn], n; int first; int d[maxn][2][2]; bool dfs(int l, int r, int curl, int curr) { if (curr >= 2) return false; int &ans = d[r][curl == 10][curr]; if (ans != -1) return ans; if (r + 1 >= l) { if (l == r...
CPP
625_D. Finals in arithmetic
Vitya is studying in the third grade. During the last math lesson all the pupils wrote on arithmetic quiz. Vitya is a clever boy, so he managed to finish all the tasks pretty fast and Oksana Fillipovna gave him a new one, that is much harder. Let's denote a flip operation of an integer as follows: number is considered...
2
10
#include <bits/stdc++.h> using namespace std; deque<int> check(deque<int> mas) { int l = 0, r = mas.size() - 1; bool flag = true; for (; l < mas.size() / 2; l++, r--) { if (mas[r] < 0) { mas[r - 1]--; mas[r] += 10; } if (mas[l] == mas[r] + 1 && l != r - 1) { mas[l + 1] += 10; m...
CPP
625_D. Finals in arithmetic
Vitya is studying in the third grade. During the last math lesson all the pupils wrote on arithmetic quiz. Vitya is a clever boy, so he managed to finish all the tasks pretty fast and Oksana Fillipovna gave him a new one, that is much harder. Let's denote a flip operation of an integer as follows: number is considered...
2
10
import java.util.Scanner; public class Solution { static int[] A; public static void main(String[] args) { Scanner in = new Scanner(System.in); String s = in.next(); if (s.equals("1")) { System.out.println(0); return; } A = new int[s.length()];...
JAVA
625_D. Finals in arithmetic
Vitya is studying in the third grade. During the last math lesson all the pupils wrote on arithmetic quiz. Vitya is a clever boy, so he managed to finish all the tasks pretty fast and Oksana Fillipovna gave him a new one, that is much harder. Let's denote a flip operation of an integer as follows: number is considered...
2
10
#include <bits/stdc++.h> using namespace std; const int N = 100 * 1000 + 2; char s[N], ans[N]; int sum[N], n; void input() { scanf("%s", s); n = strlen(s); reverse(s, s + n); for (int i = 0; i < n; i++) sum[i] = s[i] - '0'; } bool solve() { for (int i = 0; i < n / 2; i++) { if (sum[i] == sum[n - 1 - i]) c...
CPP
625_D. Finals in arithmetic
Vitya is studying in the third grade. During the last math lesson all the pupils wrote on arithmetic quiz. Vitya is a clever boy, so he managed to finish all the tasks pretty fast and Oksana Fillipovna gave him a new one, that is much harder. Let's denote a flip operation of an integer as follows: number is considered...
2
10
#include <bits/stdc++.h> using namespace std; string s; int a[100005]; int ans[100005]; bool judge(int n) { for (int i = 0; i < (n) / 2;) { if (a[i] == a[n - i - 1]) i++; else if (a[i] == a[n - i - 1] + 1 || a[i] == a[n - i - 1] + 11) { a[i + 1] += 10; a[i]--; } else if (a[i] == a[n - i ...
CPP
625_D. Finals in arithmetic
Vitya is studying in the third grade. During the last math lesson all the pupils wrote on arithmetic quiz. Vitya is a clever boy, so he managed to finish all the tasks pretty fast and Oksana Fillipovna gave him a new one, that is much harder. Let's denote a flip operation of an integer as follows: number is considered...
2
10
#include <bits/stdc++.h> using namespace std; char st[100020], ans[100020]; int n; int check() { memset(ans, 0, sizeof(ans)); int nowx = 0, nowy = 0, nextx = 0, nexty = 0; for (int i = 0; i < n / 2; i++) { nowx = nextx; nowy = nexty; nextx = 0; nexty = 0; nowx += st[i]; nowy += st[n - i - ...
CPP
625_D. Finals in arithmetic
Vitya is studying in the third grade. During the last math lesson all the pupils wrote on arithmetic quiz. Vitya is a clever boy, so he managed to finish all the tasks pretty fast and Oksana Fillipovna gave him a new one, that is much harder. Let's denote a flip operation of an integer as follows: number is considered...
2
10
#include <bits/stdc++.h> using namespace std; bool done; bool dp[100005][3][3]; int A[100050], n; string num; bool rec(int idx, int rem, int mustOverFlow) { if (idx == (n - 1) >> 1) { if (idx == n - idx - 1) { int value = num[idx] - '0' - rem; for (int i = 0; i < 10; ++i) if ((2 * i) % 10 == (...
CPP
625_D. Finals in arithmetic
Vitya is studying in the third grade. During the last math lesson all the pupils wrote on arithmetic quiz. Vitya is a clever boy, so he managed to finish all the tasks pretty fast and Oksana Fillipovna gave him a new one, that is much harder. Let's denote a flip operation of an integer as follows: number is considered...
2
10
#include <bits/stdc++.h> using namespace std; char num[100100], ans[100100]; int sum[100100], n; bool f() { if (n == 1) { if (sum[0] & 1) return false; sum[0] /= 2; ans[0] = sum[0] + '0'; return true; } for (int i = 0; i < n / 2;) { if (sum[i] == sum[n - i - 1]) { i++; } else if (sum...
CPP
625_D. Finals in arithmetic
Vitya is studying in the third grade. During the last math lesson all the pupils wrote on arithmetic quiz. Vitya is a clever boy, so he managed to finish all the tasks pretty fast and Oksana Fillipovna gave him a new one, that is much harder. Let's denote a flip operation of an integer as follows: number is considered...
2
10
#include <bits/stdc++.h> using namespace std; char s[100005]; int n, a[100005], b[100005], ans[100005]; bool work() { int i, j, temp, flag; for (i = 0; i < n / 2; i++) { flag = 0; if (a[n - i - 1] > 19 || a[n - i - 1] < 0) return 0; temp = a[i]; if (a[n - i - 1] - temp >= 2 || temp < 0) temp += 10, ...
CPP
625_D. Finals in arithmetic
Vitya is studying in the third grade. During the last math lesson all the pupils wrote on arithmetic quiz. Vitya is a clever boy, so he managed to finish all the tasks pretty fast and Oksana Fillipovna gave him a new one, that is much harder. Let's denote a flip operation of an integer as follows: number is considered...
2
10
import java.util.Scanner; public class CodeforcesD { static int[] A; public static void main(String[] args){ Scanner in = new Scanner(System.in); String s = in.next(); if(s.equals("1")){ System.out.println(0); return; } A = new int[s.length()]; for(int i=0; i<A.length; i++){ A[i] = s.charAt(i) ...
JAVA
625_D. Finals in arithmetic
Vitya is studying in the third grade. During the last math lesson all the pupils wrote on arithmetic quiz. Vitya is a clever boy, so he managed to finish all the tasks pretty fast and Oksana Fillipovna gave him a new one, that is much harder. Let's denote a flip operation of an integer as follows: number is considered...
2
10
#include <bits/stdc++.h> using namespace std; vector<int> toVec(string n) { vector<int> res; res.reserve(n.size()); for (int i = 0; i < int(n.size()); i++) { res.push_back(int(n[i] - '0')); } return res; } void go(vector<int> num) { int L = int(num.size()); for (int i = 0, j = L - 1; i < j;) { if ...
CPP
625_D. Finals in arithmetic
Vitya is studying in the third grade. During the last math lesson all the pupils wrote on arithmetic quiz. Vitya is a clever boy, so he managed to finish all the tasks pretty fast and Oksana Fillipovna gave him a new one, that is much harder. Let's denote a flip operation of an integer as follows: number is considered...
2
10
#include <bits/stdc++.h> using namespace std; const int N = 100010; bool flag[N][2][2]; bool vis[N][2][2]; char s[N]; struct point { int l, r, p, c; point() {} point(int l, int r, int p, int c) : l(l), r(r), p(p), c(c) {} } ans[N][2][2]; int st; bool solve(int l, int r, int pre, int carry) { if (l > r) return p...
CPP
625_D. Finals in arithmetic
Vitya is studying in the third grade. During the last math lesson all the pupils wrote on arithmetic quiz. Vitya is a clever boy, so he managed to finish all the tasks pretty fast and Oksana Fillipovna gave him a new one, that is much harder. Let's denote a flip operation of an integer as follows: number is considered...
2
10
#include <bits/stdc++.h> using namespace std; int a[100005], n; void solve(int l, int r) { int x = l, y = r; while (r >= l) { if (a[l] - a[r] >= 10) { a[r] += 10; a[r - 1]--; } if (a[l] - a[r] == 1) { a[l]--; a[l + 1] += 10; } if (a[l] != a[r]) return; if (l == r) { ...
CPP
625_D. Finals in arithmetic
Vitya is studying in the third grade. During the last math lesson all the pupils wrote on arithmetic quiz. Vitya is a clever boy, so he managed to finish all the tasks pretty fast and Oksana Fillipovna gave him a new one, that is much harder. Let's denote a flip operation of an integer as follows: number is considered...
2
10
#include <bits/stdc++.h> const int Maxn = 100005; int digit[Maxn], len, ans[Maxn]; int check() { for (int i = 0; i < len / 2;) { int l = i, r = len - i - 1; if (digit[l] == digit[r]) ++i; else if (digit[l] == digit[r] + 1 || digit[l] == digit[r] + 11) { digit[l] -= 1; digit[l + 1] += 10;...
CPP
625_D. Finals in arithmetic
Vitya is studying in the third grade. During the last math lesson all the pupils wrote on arithmetic quiz. Vitya is a clever boy, so he managed to finish all the tasks pretty fast and Oksana Fillipovna gave him a new one, that is much harder. Let's denote a flip operation of an integer as follows: number is considered...
2
10
#include <bits/stdc++.h> using namespace std; int main() { char s[100005]; int n, l, r; while ((scanf("%c", &s[++n]) == 1) && (s[n] >= '0') && (s[n] <= '9')) s[n] -= '0'; l = 1; r = --n; if (s[l] != s[r]) { s[l]--; s[l + 1] += 10; if (s[l] == 0) l++; } while (l <= r) { if (s[l] != s[...
CPP
625_D. Finals in arithmetic
Vitya is studying in the third grade. During the last math lesson all the pupils wrote on arithmetic quiz. Vitya is a clever boy, so he managed to finish all the tasks pretty fast and Oksana Fillipovna gave him a new one, that is much harder. Let's denote a flip operation of an integer as follows: number is considered...
2
10
def check(s): # print s n = len(s) i, j = 0, n - 1 while i < j: if s[i] == s[j]: pass elif s[i] == s[j] - 1 and i + 1 != j: s[j] -= 1 s[j - 1] += 10 elif s[i] == s[j] - 10 and i + 1 != j: s[i + 1] -= 1 s[i] += 10 ...
PYTHON
625_D. Finals in arithmetic
Vitya is studying in the third grade. During the last math lesson all the pupils wrote on arithmetic quiz. Vitya is a clever boy, so he managed to finish all the tasks pretty fast and Oksana Fillipovna gave him a new one, that is much harder. Let's denote a flip operation of an integer as follows: number is considered...
2
10
#include <bits/stdc++.h> using namespace std; using LL = long long; using LD = long double; using PII = pair<int, int>; using PLL = pair<LL, LL>; using PLD = pair<LD, LD>; using VI = vector<int>; using VLL = vector<LL>; using VLD = vector<LD>; using VPII = vector<PII>; using VPLL = vector<PLL>; using VPLD = vector<PLD>...
CPP
625_D. Finals in arithmetic
Vitya is studying in the third grade. During the last math lesson all the pupils wrote on arithmetic quiz. Vitya is a clever boy, so he managed to finish all the tasks pretty fast and Oksana Fillipovna gave him a new one, that is much harder. Let's denote a flip operation of an integer as follows: number is considered...
2
10
#include <bits/stdc++.h> using namespace std; string add(string a, string b) { string res = ""; while (a.length() < b.length()) a = "0" + a; while (b.length() < a.length()) b = "0" + b; int carry = 0; for (int i = a.length() - 1; i >= 0; i--) { int tmp = a[i] - 48 + b[i] - 48 + carry; carry = tmp / 10...
CPP
625_D. Finals in arithmetic
Vitya is studying in the third grade. During the last math lesson all the pupils wrote on arithmetic quiz. Vitya is a clever boy, so he managed to finish all the tasks pretty fast and Oksana Fillipovna gave him a new one, that is much harder. Let's denote a flip operation of an integer as follows: number is considered...
2
10
#include <bits/stdc++.h> using namespace std; const int N = 100000 + 10; char s[N]; int sum[N], a[N], b[N]; void solve(int l, int r, int len) { if (l > r) return; if (len == r - l + 1) { b[r] = a[r]; if (l != r && a[l] >= 10 && a[r] != 9) b[r] += 10; a[r] -= b[r]; if (l != r) a[l] -= b[r]; int n...
CPP
625_D. Finals in arithmetic
Vitya is studying in the third grade. During the last math lesson all the pupils wrote on arithmetic quiz. Vitya is a clever boy, so he managed to finish all the tasks pretty fast and Oksana Fillipovna gave him a new one, that is much harder. Let's denote a flip operation of an integer as follows: number is considered...
2
10
#include <bits/stdc++.h> using namespace std; const long long N = 1e5 + 10; long long dp[N][2][2]; pair<long long, long long> prevv[N][2][2]; pair<long long, long long> sel[N][2][2]; signed main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); string s; cin >> s; long long n = (long long)(s.size()); ...
CPP
625_D. Finals in arithmetic
Vitya is studying in the third grade. During the last math lesson all the pupils wrote on arithmetic quiz. Vitya is a clever boy, so he managed to finish all the tasks pretty fast and Oksana Fillipovna gave him a new one, that is much harder. Let's denote a flip operation of an integer as follows: number is considered...
2
10
import java.util.Arrays; import java.util.Scanner; /** * Created by mmaikovych on 07.02.16. */ public class Round_342_Task_D { public static void main(String[] args) { Scanner input = new Scanner(System.in); String nString = input.nextLine(); char[] nChars = nString.toCharArray(); ...
JAVA
625_D. Finals in arithmetic
Vitya is studying in the third grade. During the last math lesson all the pupils wrote on arithmetic quiz. Vitya is a clever boy, so he managed to finish all the tasks pretty fast and Oksana Fillipovna gave him a new one, that is much harder. Let's denote a flip operation of an integer as follows: number is considered...
2
10
#include <bits/stdc++.h> using namespace std; int pos[131072][2][2]; char txt[131072]; char ans[131072]; int mem[131072][2][2][4]; int n; void recall(int x, int c1, int c2) { int y = n - x - 1; if (x == y) { ans[x] = mem[x][c1][c2][0] + '0'; return; } if (x + 1 == y) { ans[x] = mem[x][c1][c2][0] + '...
CPP
625_D. Finals in arithmetic
Vitya is studying in the third grade. During the last math lesson all the pupils wrote on arithmetic quiz. Vitya is a clever boy, so he managed to finish all the tasks pretty fast and Oksana Fillipovna gave him a new one, that is much harder. Let's denote a flip operation of an integer as follows: number is considered...
2
10
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5, SQRT = 320, LOGN = 20, MOD = 1e9 + 7; int dp[N][2][2], ans[N], len; pair<int, int> val[N][2][2], nxt[N][2][2]; string a; bool solve(int l, int r, bool ten_dig, bool carry) { if (l > r) return true; bool ok = false; if (dp[l][ten_dig][carry] != -...
CPP
625_D. Finals in arithmetic
Vitya is studying in the third grade. During the last math lesson all the pupils wrote on arithmetic quiz. Vitya is a clever boy, so he managed to finish all the tasks pretty fast and Oksana Fillipovna gave him a new one, that is much harder. Let's denote a flip operation of an integer as follows: number is considered...
2
10
#include <bits/stdc++.h> using namespace std; string num; string filla(int prpr, int ind1, int ind2, int zdpr) { if (ind1 > ind2) { if (prpr == zdpr || prpr - zdpr == 9) { return ""; } else { return "-"; } } if (ind1 == ind2) { int ch = num[ind1] - '0'; ch += prpr; ch -= zdpr; ...
CPP
625_D. Finals in arithmetic
Vitya is studying in the third grade. During the last math lesson all the pupils wrote on arithmetic quiz. Vitya is a clever boy, so he managed to finish all the tasks pretty fast and Oksana Fillipovna gave him a new one, that is much harder. Let's denote a flip operation of an integer as follows: number is considered...
2
10
#include <bits/stdc++.h> using namespace std; string CH(string x) { int L, R, L1, R1, DL, DR; string D = x; for (L = L1 = R1 = 0, R = x.size() - 1; L < R; L++, R--) { DL = x[L] - '0'; DR = x[R] - '0'; if (L1) DL += 10; if (R1) DR--; if (DR < 0) { DR += 10; R1 = 2; } if (DL ...
CPP
625_D. Finals in arithmetic
Vitya is studying in the third grade. During the last math lesson all the pupils wrote on arithmetic quiz. Vitya is a clever boy, so he managed to finish all the tasks pretty fast and Oksana Fillipovna gave him a new one, that is much harder. Let's denote a flip operation of an integer as follows: number is considered...
2
10
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Arrays; import java.util.Scanner; public class CF_342D { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String number...
JAVA
625_D. Finals in arithmetic
Vitya is studying in the third grade. During the last math lesson all the pupils wrote on arithmetic quiz. Vitya is a clever boy, so he managed to finish all the tasks pretty fast and Oksana Fillipovna gave him a new one, that is much harder. Let's denote a flip operation of an integer as follows: number is considered...
2
10
#include <bits/stdc++.h> char s[100010]; char ans[100010]; int sum[100010]; int n; bool check() { for (int i = 0; i < n / 2;) { if (sum[i] == sum[n - 1 - i]) { ++i; } else if (sum[i] == sum[n - 1 - i] + 1) { sum[i]--; sum[i + 1] += 10; } else if (sum[i] == sum[n - 1 - i] + 10) { su...
CPP
625_D. Finals in arithmetic
Vitya is studying in the third grade. During the last math lesson all the pupils wrote on arithmetic quiz. Vitya is a clever boy, so he managed to finish all the tasks pretty fast and Oksana Fillipovna gave him a new one, that is much harder. Let's denote a flip operation of an integer as follows: number is considered...
2
10
#include <bits/stdc++.h> using namespace std; const int maxn = 1e6 + 7; char s[maxn]; char ans[maxn]; int sum[maxn]; int n; int check() { for (int i = 0; i < n / 2;) { int l = i, r = n - 1 - i; if (sum[l] == sum[r]) i++; else if (sum[l] == sum[r] + 1 || sum[l] == sum[r] + 11) { sum[l]--; ...
CPP
625_D. Finals in arithmetic
Vitya is studying in the third grade. During the last math lesson all the pupils wrote on arithmetic quiz. Vitya is a clever boy, so he managed to finish all the tasks pretty fast and Oksana Fillipovna gave him a new one, that is much harder. Let's denote a flip operation of an integer as follows: number is considered...
2
10
#include <bits/stdc++.h> using namespace std; int n, arr[100010], ans[100010]; char aa[100010]; bool run(int *abb) { int beg = 1, end = n; while (beg < end) { if (abb[beg] < 0) return false; if (abb[end] < 0) { if (abb[end] == -1) { abb[end - 1] -= 1; abb[end] += 10; } else ...
CPP
625_D. Finals in arithmetic
Vitya is studying in the third grade. During the last math lesson all the pupils wrote on arithmetic quiz. Vitya is a clever boy, so he managed to finish all the tasks pretty fast and Oksana Fillipovna gave him a new one, that is much harder. Let's denote a flip operation of an integer as follows: number is considered...
2
10
#include <bits/stdc++.h> using namespace std; const int N = 111111; string str; char ans_str[N]; bool dfs(int l, int r, int c1, int c2) { if (l > r) { if (l - r == 1) return c1 == c2; return true; } int a = str[l] - '0' + c1 * 10; int b = str[r] - '0' - c2; int nc1 = 0, nc2 = 0; if (a - b >= 10) { ...
CPP
625_D. Finals in arithmetic
Vitya is studying in the third grade. During the last math lesson all the pupils wrote on arithmetic quiz. Vitya is a clever boy, so he managed to finish all the tasks pretty fast and Oksana Fillipovna gave him a new one, that is much harder. Let's denote a flip operation of an integer as follows: number is considered...
2
10
#include <bits/stdc++.h> using namespace std; const int N = 100005; char num[N]; int n; int c[N]; int ans[N]; bool judge() { if (n == 0) return false; int i = 0; while (i < n / 2) { int j = n - i - 1; if (c[i] == c[j]) { i++; j--; } else if (c[i] == c[j] + 1 || c[i] == c[j] + 11) { c...
CPP
625_D. Finals in arithmetic
Vitya is studying in the third grade. During the last math lesson all the pupils wrote on arithmetic quiz. Vitya is a clever boy, so he managed to finish all the tasks pretty fast and Oksana Fillipovna gave him a new one, that is much harder. Let's denote a flip operation of an integer as follows: number is considered...
2
10
#include <bits/stdc++.h> using namespace std; const int MaxN = int(2e5) + 256; const int INF = int(1e9); const int mod = (int)(1e9) + 7; int n, a[MaxN], m, t; int ans1[MaxN], ans2[MaxN]; string second; vector<int> v; int rec(int x) { int ans = 0; while (x) { ans = ans * 10 + x % 10; x /= 10; } return an...
CPP
625_D. Finals in arithmetic
Vitya is studying in the third grade. During the last math lesson all the pupils wrote on arithmetic quiz. Vitya is a clever boy, so he managed to finish all the tasks pretty fast and Oksana Fillipovna gave him a new one, that is much harder. Let's denote a flip operation of an integer as follows: number is considered...
2
10
#include <bits/stdc++.h> using namespace std; char s[100010]; int a[100010]; int anss[100010]; void sub(int pos) { int i; for (i = pos;; i++) { if (a[i]) { a[i]--; return; } else a[i] = 9; } } void solve(int l, int r) { if (l > r) { if (a[l]) { puts("0"); exit(0); }...
CPP
625_D. Finals in arithmetic
Vitya is studying in the third grade. During the last math lesson all the pupils wrote on arithmetic quiz. Vitya is a clever boy, so he managed to finish all the tasks pretty fast and Oksana Fillipovna gave him a new one, that is much harder. Let's denote a flip operation of an integer as follows: number is considered...
2
10
#include <bits/stdc++.h> using namespace std; const int maxn = 111111; char str[maxn], ans[maxn]; char sol[2][2][maxn]; int first; pair<int, int> last[2][2][maxn]; bool solve(int l, int r, bool flg1, bool flg2) { if (l > r) return flg1 == flg2; if (sol[flg1][flg2][l] > 0) return true; if (sol[flg1][flg2][l] < 0) ...
CPP
625_D. Finals in arithmetic
Vitya is studying in the third grade. During the last math lesson all the pupils wrote on arithmetic quiz. Vitya is a clever boy, so he managed to finish all the tasks pretty fast and Oksana Fillipovna gave him a new one, that is much harder. Let's denote a flip operation of an integer as follows: number is considered...
2
10
#include <bits/stdc++.h> using namespace std; struct edge { int u, v; char c; }; long long MOD = 1000000007; long long _MOD = 1000000009; double EPS = 1e-10; string f(string s, int l) { int n = s.length(), r = 0; vector<int> z(n); for (int i = 0, j = n - 1; i <= j; i++, j--) { int a = s[i] - '0', b = s[j]...
CPP
625_D. Finals in arithmetic
Vitya is studying in the third grade. During the last math lesson all the pupils wrote on arithmetic quiz. Vitya is a clever boy, so he managed to finish all the tasks pretty fast and Oksana Fillipovna gave him a new one, that is much harder. Let's denote a flip operation of an integer as follows: number is considered...
2
10
import java.io.*; import java.util.*; public class D { InputStream is; int __t__ = 1; int __f__ = 0; int __FILE_DEBUG_FLAG__ = __f__; String __DEBUG_FILE_NAME__ = "src/D4"; FastScanner in; PrintWriter out; String calc(int[] s, int cu, int l, int r) { if (l > r) return "-1"; char[] t = new char[r-l+1]; ...
JAVA
625_D. Finals in arithmetic
Vitya is studying in the third grade. During the last math lesson all the pupils wrote on arithmetic quiz. Vitya is a clever boy, so he managed to finish all the tasks pretty fast and Oksana Fillipovna gave him a new one, that is much harder. Let's denote a flip operation of an integer as follows: number is considered...
2
10
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.StringTokenizer; import java.io.IOException; import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.InputStream; /** * Built using CHelper plug-in * Actual soluti...
JAVA
625_D. Finals in arithmetic
Vitya is studying in the third grade. During the last math lesson all the pupils wrote on arithmetic quiz. Vitya is a clever boy, so he managed to finish all the tasks pretty fast and Oksana Fillipovna gave him a new one, that is much harder. Let's denote a flip operation of an integer as follows: number is considered...
2
10
#include <bits/stdc++.h> using namespace std; const int maxn = 100100; char s[maxn]; int a[maxn]; int main() { scanf("%s", &s); int n = strlen(s); for (int i = 0; i < n; ++i) { a[i] = s[i] - '0'; } int l = 0, r = n - 1; if (a[l] != a[r]) { a[l + 1] += 10; a[l]--; if (!a[l]) l++; } while ...
CPP
625_D. Finals in arithmetic
Vitya is studying in the third grade. During the last math lesson all the pupils wrote on arithmetic quiz. Vitya is a clever boy, so he managed to finish all the tasks pretty fast and Oksana Fillipovna gave him a new one, that is much harder. Let's denote a flip operation of an integer as follows: number is considered...
2
10
#include <bits/stdc++.h> using namespace std; bool calc(string s, string &ans) { bool status = true; int i, j; ans = s; for (i = 0, j = s.size() - 1; i < (s.size() + 1) / 2 - 1; i++, j--) { if (s[i] == s[j]) { if (s[i] < '0' || s[i] > '0' + 18) { status = false; break; } an...
CPP
625_D. Finals in arithmetic
Vitya is studying in the third grade. During the last math lesson all the pupils wrote on arithmetic quiz. Vitya is a clever boy, so he managed to finish all the tasks pretty fast and Oksana Fillipovna gave him a new one, that is much harder. Let's denote a flip operation of an integer as follows: number is considered...
2
10
#include <bits/stdc++.h> using namespace std; char s[111111]; int a[111111]; int ans[111111]; int main() { memset(a, 0, sizeof a); memset(ans, 0, sizeof ans); scanf("%s", &s); int len = strlen(s); for (int i = 1; i <= len; i++) { a[i] = s[i - 1] - '0'; } int l = 1, r = len; int fa = 1; if (a[l] !=...
CPP
625_D. Finals in arithmetic
Vitya is studying in the third grade. During the last math lesson all the pupils wrote on arithmetic quiz. Vitya is a clever boy, so he managed to finish all the tasks pretty fast and Oksana Fillipovna gave him a new one, that is much harder. Let's denote a flip operation of an integer as follows: number is considered...
2
10
#include <bits/stdc++.h> using namespace std; template <typename T> inline bool upmin(T &x, T y) { return y < x ? x = y, 1 : 0; } template <typename T> inline bool upmax(T &x, T y) { return x < y ? x = y, 1 : 0; } const long double eps = 1e-11; const long double pi = acos(-1); const int oo = 1 << 30; const long lon...
CPP
625_D. Finals in arithmetic
Vitya is studying in the third grade. During the last math lesson all the pupils wrote on arithmetic quiz. Vitya is a clever boy, so he managed to finish all the tasks pretty fast and Oksana Fillipovna gave him a new one, that is much harder. Let's denote a flip operation of an integer as follows: number is considered...
2
10
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; const double eps = 1e-10; const int inf = 0x3f3f3f3f; const int mif = 0xcfcfcfcf; const double PI = 3.14159265358979323846264338; long long mul_mod(long long first, long long second) { long long t = 0; while (second) { if (second & 1) ...
CPP
625_D. Finals in arithmetic
Vitya is studying in the third grade. During the last math lesson all the pupils wrote on arithmetic quiz. Vitya is a clever boy, so he managed to finish all the tasks pretty fast and Oksana Fillipovna gave him a new one, that is much harder. Let's denote a flip operation of an integer as follows: number is considered...
2
10
#include <bits/stdc++.h> using namespace std; const int N = 100010; int a[N], ans[N]; char s[N]; bool Dfs(int l, int r, bool p, bool q) { int i, s1, s2; if (l > r) return (p == q); else if (l == r) { s1 = a[l] + (p ? 10 : 0) + (q ? -1 : 0); if (s1 == -1 || s1 & 1) return false; else { ...
CPP
625_D. Finals in arithmetic
Vitya is studying in the third grade. During the last math lesson all the pupils wrote on arithmetic quiz. Vitya is a clever boy, so he managed to finish all the tasks pretty fast and Oksana Fillipovna gave him a new one, that is much harder. Let's denote a flip operation of an integer as follows: number is considered...
2
10
#include <bits/stdc++.h> using namespace std; char s[100010]; int a[100010], ans[100010]; int main() { memset(a, 0, sizeof(a)); memset(ans, 0, sizeof(ans)); scanf("%s", &s); int n = strlen(s); for (int i = 1; i <= n; i++) a[i] = s[i - 1] - '0'; int l = 1, r = n, flag = 1; if (a[l] != a[r]) { a[l]--; ...
CPP
625_D. Finals in arithmetic
Vitya is studying in the third grade. During the last math lesson all the pupils wrote on arithmetic quiz. Vitya is a clever boy, so he managed to finish all the tasks pretty fast and Oksana Fillipovna gave him a new one, that is much harder. Let's denote a flip operation of an integer as follows: number is considered...
2
10
#include <bits/stdc++.h> const int N = 1e5 + 5; char str[N]; char ans[N]; int s[N]; int n; bool judge(void) { for (int i = 0; i < n / 2;) { int l = i, r = n - 1 - i; if (s[l] == s[r]) ++i; else if (s[l] == s[r] + 1 || s[l] == s[r] + 11) { s[l]--; s[l + 1] += 10; } else if (s[l] == s[...
CPP
625_D. Finals in arithmetic
Vitya is studying in the third grade. During the last math lesson all the pupils wrote on arithmetic quiz. Vitya is a clever boy, so he managed to finish all the tasks pretty fast and Oksana Fillipovna gave him a new one, that is much harder. Let's denote a flip operation of an integer as follows: number is considered...
2
10
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 1; char s[N], a[N]; bool slv(int i, int j, int l, int r) { if (i > j) return l == r; s[i] += 10 * l, s[j] -= r; if (s[i] - s[j] > 9) s[j] += 10, r = 1; else r = 0; if (s[i] > s[j]) s[i]--, l = 1; else l = 0; if (s[i] != s[j]...
CPP
625_D. Finals in arithmetic
Vitya is studying in the third grade. During the last math lesson all the pupils wrote on arithmetic quiz. Vitya is a clever boy, so he managed to finish all the tasks pretty fast and Oksana Fillipovna gave him a new one, that is much harder. Let's denote a flip operation of an integer as follows: number is considered...
2
10
//package round342; import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.Arrays; import java.util.InputMismatchException; public class D { InputStream is; PrintWriter out; String INPUT = ""; void solve() { char[] sb = ns().to...
JAVA
625_D. Finals in arithmetic
Vitya is studying in the third grade. During the last math lesson all the pupils wrote on arithmetic quiz. Vitya is a clever boy, so he managed to finish all the tasks pretty fast and Oksana Fillipovna gave him a new one, that is much harder. Let's denote a flip operation of an integer as follows: number is considered...
2
10
#include <bits/stdc++.h> const int N = 100005; char str[N], ans[N]; bool solve(int m, int len, bool st) { int i; bool carry; if (!st && str[len] == '0') return false; for (i = carry = st; i < m; i++) { int t = str[i] - str[len - i]; if (str[len - i] < '0') { ans[i] = '9'; ans[len - i] = '0';...
CPP
625_D. Finals in arithmetic
Vitya is studying in the third grade. During the last math lesson all the pupils wrote on arithmetic quiz. Vitya is a clever boy, so he managed to finish all the tasks pretty fast and Oksana Fillipovna gave him a new one, that is much harder. Let's denote a flip operation of an integer as follows: number is considered...
2
10
#include <bits/stdc++.h> using namespace std; int n; char st[100010]; int s[100010], A[100010], ans[100010]; int put(int v, int a, int b) { if (v > 18 || (a == b && v & 1)) return 1; ans[a] = ans[b] = v / 2; ans[a] += v & 1; return 0; } int ok() { memset(ans, 0, sizeof(ans)); for (int i = 1; i <= (n + 1) / ...
CPP
625_D. Finals in arithmetic
Vitya is studying in the third grade. During the last math lesson all the pupils wrote on arithmetic quiz. Vitya is a clever boy, so he managed to finish all the tasks pretty fast and Oksana Fillipovna gave him a new one, that is much harder. Let's denote a flip operation of an integer as follows: number is considered...
2
10
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; char memo[N][2][2]; int lst; string s; string ansL, ansR; bool sh; char dp(int ind, bool c1, bool c2) { if (ind > lst - ind) return c1 == c2; char &ret = memo[ind][c1][c2]; if (ret != -1) return ret; ret = 0; if (ind == lst - ind) { for ...
CPP
625_D. Finals in arithmetic
Vitya is studying in the third grade. During the last math lesson all the pupils wrote on arithmetic quiz. Vitya is a clever boy, so he managed to finish all the tasks pretty fast and Oksana Fillipovna gave him a new one, that is much harder. Let's denote a flip operation of an integer as follows: number is considered...
2
10
import java.util.*; public class ProblemD2 { private static String ans; private static void pretreat(StringBuilder s){ for(int i = 0; i < s.length(); ++i){ if(s.charAt(i) != '0'){ s = s.delete(0, i); ...
JAVA
625_D. Finals in arithmetic
Vitya is studying in the third grade. During the last math lesson all the pupils wrote on arithmetic quiz. Vitya is a clever boy, so he managed to finish all the tasks pretty fast and Oksana Fillipovna gave him a new one, that is much harder. Let's denote a flip operation of an integer as follows: number is considered...
2
10
#include <bits/stdc++.h> using namespace std; const int maxn = 100010; char s[maxn], a[maxn]; bool slv(int i, int j, int l, int r) { if (i > j) return l == r; s[i] += 10 * l, s[j] -= r; if (s[i] - s[j] > 9) s[j] += 10, r = 1; else r = 0; if (s[i] > s[j]) s[i]--, l = 1; else l = 0; if (s[i]...
CPP
625_D. Finals in arithmetic
Vitya is studying in the third grade. During the last math lesson all the pupils wrote on arithmetic quiz. Vitya is a clever boy, so he managed to finish all the tasks pretty fast and Oksana Fillipovna gave him a new one, that is much harder. Let's denote a flip operation of an integer as follows: number is considered...
2
10
#include <bits/stdc++.h> using namespace std; vector<int> n; vector<int> ans; int offset = 0; int dp[100001][2][2]; bool f(int id, bool l, bool r) { if (dp[id][l][r]) return false; int ltarget = n[id + offset]; int rtarget = n[n.size() - id - 1]; int len = n.size() - offset; int last = (len % 2) ? len / 2 : (...
CPP
625_D. Finals in arithmetic
Vitya is studying in the third grade. During the last math lesson all the pupils wrote on arithmetic quiz. Vitya is a clever boy, so he managed to finish all the tasks pretty fast and Oksana Fillipovna gave him a new one, that is much harder. Let's denote a flip operation of an integer as follows: number is considered...
2
10
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 10; char a[N], ans[N]; int n, sum[N]; bool judge() { for (int i = 1; i <= n / 2;) { int k = n - i + 1; if (sum[i] == sum[k]) i++; else if (sum[i] - 1 == sum[k] || sum[i] - 11 == sum[k]) { sum[i]--; sum[i + 1] += 10; } ...
CPP