akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>
#define MAX 10000
#define NIL -1

int parent[MAX],left[MAX],right[MAX];
int n,D[MAX],H[MAX];

void setDepth(int u,int d){
  if(u== NIL) return;
  D[u]=d;
  setDepth(left[u],d+1);
  setDepth(right[u],d+1);
}

int setHeight(int u){
  int h1=0,h2=0;
  if(left[u]!=NIL){
  h1 = setHeight(left[u])+1;}
  if(right[u]!=NIL){
  h2 = setHeight(right[u])+1;}
  return H[u]=(h1>h2 ? h1 : h2);
}

int getSibling(int u){
  if(parent[u]==NIL)return NIL;
  if(left[parent[u]] != u && left[parent[u]] != NIL){
  return left[parent[u]];}
  if(right[parent[u]] != u && right[parent[u]] != NIL){
  return right[parent[u]];}
  return NIL;
}

void print(int u){
  int degree =0;
  printf("node %d: ",u);
  printf("parent = %d, ",parent[u]);
  printf("sibling = %d, ",getSibling(u));
  if(left[u]!=NIL)degree++;
  if(right[u]!=NIL)degree++;
  printf("degree = %d, ",degree);
  printf("depth = %d, ",D[u]);
  printf("height = %d, ",H[u]);

  if(parent[u]==NIL){
    printf("root\n");
  }
  else if (left[u]==NIL && right[u]==NIL){
    printf("leaf\n");
  }
  else printf("internal node\n");
}

int main(){
  int i,v,l,r,root=0;
  scanf("%d",&n);

  for (i=0;i<n;i++) parent[i]=NIL;

for (i=0;i<n;i++) {
  scanf("%d %d %d",&v,&l,&r);
  left[v]=l;
  right[v]=r;
  if (l!=NIL) parent[l]=v;
  if (r!=NIL) parent[r]=v;
}

for (i=0;i<n;i++) if(parent[i] == NIL) root=i;

setDepth(root,0);
setHeight(root);

for (i=0;i<n;i++) print(i);

return 0;
}



Measured memory_bytes: 2048
#include<stdio.h>
int s;
int m;
int h;

int main(void){

	scanf("%d",&s);
	h = s / 3600;
	m = (s % 3600) / 60;
	s = ((s % 3600) % 60);
	printf("%d:%d:%d\n",h,m,s);
	return 0;
}

Measured memory_bytes: 592
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <cmath>
#include <cassert>
using namespace std;

int main(){
    string s, t;
    cin >> s >> t;
    int N = s.size();
    string s2 = s + s;

    set<int> s_set, t_set;
    for(auto x : s) s_set.insert(x);
    for(auto x : t) t_set.insert(x);
    for(auto x : t)
        if(s_set.find(x) == s_set.end()){
            cout << -1 << endl;
            return 0;
        }

    vector<int> vec[26];
    for(int i=0; i<N; i++){
        vec[s[i]-'a'].push_back(i);
        vec[s[i]-'a'].push_back(i+N);
    }
    for(int i=0; i<26; i++)
        sort(vec[i].begin(), vec[i].end());

    vector<vector<int>> tab(N, vector<int>(26));
    long long ans = 0;
    int cur = -1;
    for(int i=0; i<t.size(); i++){
        int id = t[i] - 'a';
        int nxt = *upper_bound(vec[id].begin(), vec[id].end(), cur);
        ans += nxt - cur;
        cur = nxt % N;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 14912
n = int(input())
a = input()
b = []
att = 1
for i in range(n):
  b.append(int(a[i])-1)
#print(b)
for i in range(n):
  if b[i] % 2 == 1:
    break
else:
  att = 2
  for i in range(n):
    b[i] //= 2
for i in range(n):
  if b[i] == 2:
    b[i] = 0
#print(b)
pre = [0 for _ in range(10**6)]
now = 2
while now < 10**6 + 5:
  for k in range(10**6):
    try:
      pre[k*now] += 1
    except:
      now *= 2
      break
#print(pre)
nm = [0]
for i in range(1,n):
  nm.append(nm[-1]-pre[i]+pre[n-i])
for i in range(n):
  if nm[i]:
    nm[i] = 0
  else:
    nm[i] = 1
#print(nm)
ans = 0
for i in range(n):
  ans ^= b[i]*nm[i]
print(ans*att)

Measured memory_bytes: 122752
#include <cstdio>
#include <algorithm>
#include <vector>

void printInt(int& value);
void br();
void scanInt(int* value);
void scanIntArray(int* array, int count);
void scanIntVector(std::vector<int>* v, int count);

int main() {
	int N;
	scanInt(&N);
	std::vector<int> A(N), a(N);
	scanIntVector(&A, N);
	std::copy(A.begin(), A.end(), a.begin());
	std::sort(a.begin(), a.end());

	for (int i = 0; i < N; ++i) {
		bool same = false;
		for (int j = N - 1; j >= 0; --j) {
			if (a[j] != A[i] || same) {
				printInt(a[j]);
				break;
			} else {
				same = true;
			}
		}
		br();
	}
}

void printInt(int& value) {
	printf("%d", value);
}

void br() {
	printf("\n");
}

void scanIntArray(int* array, int count) {
	for (int i = 0; i < count; ++i) {
		scanInt(array + i);
	}
}

void scanIntVector(std::vector<int>* v, int count) {
	for (int i = 0; i < count; ++i) {
		int value;
		scanInt(&value);
		(*v)[i] = value;
	}
}

void scanInt(int* value) {
	scanf("%d", value);
}

Measured memory_bytes: 3200
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
    int n;
    cin >> n;
    map<int, int> m{};
    rep(i,n) {
        int x;
        cin >> x;
        m[x]++;
    }
    int ans = 0;
    for(auto itr = m.begin(); itr != m.end(); itr++) {
        if (itr->second % 2 == 1) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>


using namespace std;
#define rep(i,n) for (int i = 0; i < (int)(n); ++i)
#define reps(i,n) for (int i = 1; i <= (int)(n); ++i)
#define repd(i,n) for (int i = (int)(n - 1); i >= 0; --i)
#define repds(i,n) for (int i = (int)(n); i > 0; --i)
#define loop(i,x,n) for (int i = (int)(x); i < (n); ++i)
#define loops(i,x,n) for (int i = (int)(x); i <= (n); ++i)
#define loopd(i,x,n) for (int i = (int)(x); i > (n); --i)
#define loopds(i,x,n) for (int i = (int)(x); i >= (n); --i)
#define itrep(i,s) for (auto i = begin(s); i != end(s); ++i)
#define itrepd(i,s) for (auto i = --end(s); i != begin(s); --i)
#define all(f,x,...) [&](decltype(x)& whole) { return (f)(begin(whole), end(whole), ##__VA_ARGS__); }(x)
#define rall(f,x,...) [&](decltype(x)& whole) { return (f)(rbegin(whole), rend(whole), ##__VA_ARGS__); }(x)
using ll = long long;
using ld = long double;
constexpr ll inf = static_cast<ll>(1e17);
constexpr int iinf = static_cast<int>(1e9);
constexpr double dinf = 1e10;
constexpr ld ldinf = 1e17;
ll mod = static_cast<ll>(1e9 + 7);
std::ostream& endn(std::ostream& os) { return os.put(os.widen('\n')); }
template<class T> constexpr int sz(const T& a) { return (int)a.size(); }
template<class T> constexpr T pow2(const T a) { return a * a; }
template<class T, class ... Args> constexpr T mins(T& a, Args... args) { return a = min<T>({ a, args... }); }
template<class T, class... Args> constexpr T maxs(T& a, Args... args) { return a = max<T>({ a,args... }); }

int n;
ll a[200005];
void solve() {
    cin >> n;

    rep(i, n) cin >> a[i];
    rep(i, n) a[i + 1] += a[i];

    ll ans = inf;
    rep(i, n) {
        ll val = min(a[i], a[n] - a[i]);
        mins(ans, a[n] - val * 2);
    }

    cout << ans << endn;

}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
    cout << flush;
    return 0;
}


Measured memory_bytes: 1792
#include<iostream>
#include<string>
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include <functional>
using namespace std;

#define rep(p,q) for(int i = p; i < q;i++)

//3
int main(void) {
	int num;
	cin >> num;
	rep(0, num) {
		vector<int> line = vector<int>();
		rep(0, 3){
			int a;
			cin >> a;
			line.push_back(a);
		}
		sort(line.begin(),line.end());
		if (pow(line[0],2.0)  + pow(line[1],2.0) == pow(line[2],2.0)) cout << "YES" << endl;
		else cout << "NO" << endl;
	}
}



Measured memory_bytes: 3048
/*Always success does not build on success,success build on failure and hardwork*/
#include <bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define vec         vector<long long>
#define map         map<long long,long long>
#define scn(t)      scanf("%d",&t);
#define lscn(t)      scanf("%lld",&t);
#define mod         1000000007
#define rep(i,a,b)  for(long long i=a;i<b;i++)
#define endl        "\n"
using namespace std;
const long long N=2e5+5;
long long n,k,arr[N];
bool check(long long mid)
{
    long long ans=0;

    for(long long i=0;i<n;i++)
    {
        ans=ans+arr[i]/mid;

        if(arr[i]%mid==0)
        ans--;
    }

    if(ans<=k)
    return 1;
    else
    return 0;
}
int main()
{
      lscn(n);
      lscn(k);

      long long low=1,high=INT_MAX,mid;

      for(long long i=0;i<n;i++)
      {
          lscn(arr[i]);
      }

      while(low<high)
      {
          mid=(low+high)/2;

          if(check(mid))
          high=mid;
          else
          low=mid+1;

        //   cout<<mid<<endl;
      }

      if(check(low))
      cout<<low<<endl;
      else
      cout<<low+1<<endl;
}

Measured memory_bytes: 5304
#include<stdio.h>
long long a[2]={101,103};
long long M[2]={1e9+7,1e9+9};
long long d[2][300010],k[2][300010];
int R=1,C=1,H[2000010],N[2000010],h[300010];
//評価関数（いまはMIN）
int hyouka(int a,int b){
  if(C<b)return 1;
  if(C<a||b==0)return 0;
  return N[H[a]]<N[H[b]]||N[H[a]]==N[H[b]]&&h[H[a]]<h[H[b]]?1:0;
}
//挿入関数
void hin(int a){
  int i=C++;
  for(N[H[0]=R]=a;hyouka(0,i/2);i/=2)H[i]=H[i/2];
  H[i]=R++;
}
//取り出す関数
int hout(){
  int rt=H[1],i,j=2,k=H[--C];
  for(i=1;hyouka(i,C);i=j)H[i]=H[j=i*2+1-hyouka(i*2,i*2+1)];
  H[j/2]=k;
  return rt;
}
void init(char *s){//!
  int i,j;
  for(i=0;i<2;i++){
    k[i][0]=1;
    for(j=d[i][0]=0;s[j];j++){
      d[i][j+1]=(d[i][j]*a[i]+(s[j]-'a'+1))%M[i];
      k[i][j+1]=(k[i][j]*a[i])%M[i];
    }
  }
}
int getlr(int l,int r,int i){return (M[i]*M[i]+d[i][r]-d[i][l]*k[i][r-l])%M[i];}
void gets(char *s,int *h){
  int i,j;
  for(i=0;i<2;i++){
    for(j=h[i]=0;s[j];j++)h[i]+=k[i][j]*(s[j]-'0');
  }
}
int match(int l,int r,int *h){
  int i,j=1;
  for(i=0;i<2;i++)j*=getlr(l,r,i)-h[i]?1:0;
  return j;
}
int main(){
  int n=0,m,a,b,i,j,l=0,r=1;
  char s[300010],q[5];
  scanf("%*d %d %s",&m,s);
  init(s);//printf("%s\n",s);
  //for(i=0;s[i];i++)printf("%lld ",k[0][i+1]);printf("\n");
  //printf("%lld %lld %lld\n",d[0][3],d[0][4],k[0][2]);return 0;
  //printf("%lld %lld\n",getlr(0,2,0),getlr(2,4,0));return 0;
  for(i=0;i<m;i++){
    scanf("%s",q);
    if(q[0]=='L')l+=q[1]-'-'?1:-1;
    else         r+=q[1]-'-'?1:-1;//printf("%d %d!",l,r);
    h[R]=getlr(l,r,0);
    hin(getlr(l,r,1));//printf("%lld %lld\n",h[R-1],N[R-1]);
  }
  a=hout();
  for(i=1;i<m;i++){
    b=hout();//printf("%lld %lld %lld %lld\n",N[a],N[b],h[a],h[b]);
    if(N[b]==N[a]&&h[b]==h[a])n++;
    a=b;
  }
  printf("%d\n",m-n);
  return 0;
}



Measured memory_bytes: 15044
def main():
    n = int(input())
    n %= 10
    hon = [2, 4, 5, 7, 9]
    pon = [0, 1, 6, 8]
    if n in hon:
        print("hon")
    elif n in pon:
        print("pon")
    else:
        print("bon")

if __name__ == "__main__":
    main()


Measured memory_bytes: 9172
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
int n, a, b, c, d;
int main(){
	scanf("%d", &n);
	a = n / 1000;
	b = n / 100 % 10;
	c = n / 10 % 10;
	d = n % 10;
	if((a == b && b == c) || (b == c && c == d)) puts("Yes");
	else puts("No");
	return 0;
} 

Measured memory_bytes: 256
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib> 
#include <ctime>
#include <unordered_map>
#include <limits.h>
using namespace std;
typedef long long ll;
int N, A[80][80], B[80][80], R, C, dp[80][80][12804];
int f(int rr, int cc, int val) {
	if (rr == (R - 1) && cc == (C - 1)) {
		int x = abs(A[rr][cc] - B[rr][cc]);
		return abs(val - x);
	}
	int& ret = dp[rr][cc][val];
	if (ret != -1) return ret;
	ret = INT_MAX;
	if (cc != (C - 1)) {
		ret = min(ret, min(f(rr, cc + 1, val + abs(A[rr][cc] - B[rr][cc])), f(rr, cc + 1, abs(val - abs(A[rr][cc] - B[rr][cc])))));
	}
	if (rr != (R - 1)) {
		ret = min(ret, min(f(rr+1, cc, val + abs(A[rr][cc] - B[rr][cc])), f(rr+1, cc, abs(val - abs(A[rr][cc] - B[rr][cc])))));
	}
	return ret;
}
int main() {
	cin >> R >> C;
	int i, j, k;
	for (i = 0; i < R; i++) for (j = 0; j < C; j++) cin >> A[i][j];
	for (i = 0; i < R; i++) for (j = 0; j < C; j++) cin >> B[i][j];
	for (i = 0; i < R; i++) for (j = 0; j < C; j++) for (k = 0; k <= 12800; k++) dp[i][j][k] = -1;
	cout << f(0, 0, 0) << endl;
}

Measured memory_bytes: 320384
#include <bits/stdc++.h>
using namespace std;
//型に気を付けよう
//a=0x61=97
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long  ll;
typedef long double  ld;
typedef string str;
typedef pair<int,int> pairii;
typedef vector<int> veci;
const double pi=3.1415926535;
const ll  mod=1000000007;
//桁数指定　cout << fixed << setprecision(2)
int main() {
  int n,m1,m2;
  cin>>n;int cnt;
  veci p(n);
  veci q(n);
  veci r(n);
  {rep(i,n)r[i]=i+1 ;}
  {rep(i,n)cin>>p[i];}
  {rep(i,n)cin>>q[i];}
  do {cnt++;
    if(r==p)m1=cnt;
    if(r==q)m2=cnt;  
  } while (next_permutation(r.begin(), r.end()));
  cout<<abs(m2-m1);
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <utility>
#include <vector>
using namespace std;

int main() {
  int n;
  long long k;
  cin >> n >> k;

  vector<int> a(n);
  vector<int> f(n);
  for (int i = 0; i < n; ++i)
    cin >> a[i];
  for (int i = 0; i < n; ++i)
    cin >> f[i];

  sort(a.rbegin(), a.rend());
  sort(f.begin(), f.end());

  long long lower = -1;
  long long upper = 1'000'000'000'000;

  while (lower + 1 < upper) {
    long long team_score = lower + (upper - lower) / 2;

    long long t = 0;
    for (int i = 0; i < n; ++i) {
      auto ai = team_score / f[i]; // make ai*fi <= target_score
      auto train = max(0LL, a[i] - ai);
      t += train;
    }
    if (t <= k) {
      upper = team_score;
    } else {
      lower = team_score;
    }
  }

  cout << upper;
  return 0;
}


Measured memory_bytes: 1792
/*  ex3_2
    potter0723sw  */

#include <stdio.h>

int main(void) {
	int N,poo;
	scanf("%d", &N);
	poo = N % 10; //poOはplace of Oneの略
	if(poo == 2 || poo == 4 || poo == 5 || poo == 7 || poo == 9){//１の位を参照するために%10をした
    	printf("hon\n");
    }else if(poo == 0 || poo == 1 || poo == 6 || poo == 8){
    	printf("pon\n");
    }else printf("bon\n");
	return 0;
}


Measured memory_bytes: 1632
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<cctype>
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<stack>
#include<queue>
#include<map>

using namespace std;
const int dx[] = {1,0,-1,0},dy[] = {0,1,0,-1};
#define INF 999999
#define rep(i,j) for(int i=0;i<(j);i++)
#define reps(i,j,k) for(int i=j;i<(k);i++)
typedef long long ll;
typedef unsigned long long ull;
void dfs(int y,int x);
char stage[16][16];

int main(){
	int n;
	scanf("%d",&n);
	rep(q,n){
		getchar();
		memset(stage,0,sizeof(stage));
		rep(i,8)scanf("%s",stage[i]);
		int x,y;
		scanf("%d%d",&x,&y);
		dfs(y-1,x-1);
		printf("Data %d:\n",q+1);
		rep(i,8)printf("%s\n",stage[i]);
	}
	return 0;
}
void dfs(int y,int x){
    rep(i,4){
        if(x+i > 7)break;
        if(stage[y][x+i] == '1'){
            stage[y][x+i] = '0';
            dfs(y,x+i);
        }
    }
    rep(i,4){
        if(x-i < 0)break;
        if(stage[y][x-i] == '1'){
            stage[y][x-i] = '0';
            dfs(y,x-i);
        }
    }
    rep(i,4){
        if(y+i > 7)break;
        if(stage[y+i][x] == '1'){
            stage[y+i][x] = '0';
            dfs(y+i,x);
        }
    }
    rep(i,4){
        if(y-i < 0)break;
        if(stage[y-i][x] == '1'){
            stage[y-i][x] = '0';
            dfs(y-i,x);
        }
    }
    return ;
}

Measured memory_bytes: 1200
# include <iostream>
# include <algorithm>
#include <array>
# include <cassert>
#include <cctype>
#include <climits>
#include <numeric>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <tuple>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
# include <chrono>
# include <random>
# include <limits.h>
# include <unordered_map>
# include <unordered_set>
# include <deque>
# include <cstdio>
# include <cstring>
#include <stdio.h>
#include<time.h>
#include <stdlib.h>
#include <cstdint>
#include <cfenv>
#include<fstream>
//#include <bits/stdc++.h>
using namespace std;
using LL =long long;
using ULL = unsigned long long;
long long MOD = 1000000000 + 9; //924844033 1000000000 + 7;
constexpr long long INF = numeric_limits<LL>::max();
const double PI = acos(-1);
#define fir first
#define sec second
#define thi third
#define debug(x) cerr<<#x<<": "<<x<<'\n'
typedef pair<LL, LL> Pll;
typedef pair<double, double> Dll;
typedef pair<LL, pair<LL, LL>> Ppll;
typedef pair<LL, pair<LL, bitset<100001>>> Pbll;
typedef pair<LL, pair<LL, vector<LL>>> Pvll;
typedef pair<LL, LL> Vec2;
struct Tll { LL first, second, third; };
struct Fll { LL first, second, third, fourth; };
typedef pair<LL, Tll> Ptll;
#define rep(i,rept) for(LL i=0;i<rept;i++)
#define Rrep(i,mf) for(LL i=mf-1;i>=0;i--)
LL h, w, n, m, k, t, s, p, q, last, first, cnt, sum, ans,dp[200000], a[200000], b[200000];
string str, ss;
bool f;
char c[800][800];
int di[4][2] = { { 0,1 },{ 1,0 },{ 0,-1 },{ -1,0 } };
struct Edge { LL to, cost; };
struct edge { LL from, to, cost; };
vector<Edge>vec[20000];
vector<edge>ed;
vector<LL>v;
map<string,LL>ma;
set<LL>st;
void YN(bool f) {
	if (f)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
}
void yn(bool f) {
	if (f)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}

int main() {
	cin >> n;
	rep(i, n) {
		cin >> a[i];
	}
	rep(i, n+1)dp[i] = INF;
	dp[0] = 0;
	rep(i, n) {
		dp[i + 1] = min(dp[i + 1], dp[i] + abs(a[i] - a[i + 1]));
		//if(i+2<=n)
		dp[i + 2] = min(dp[i + 2], dp[i] + abs(a[i] - a[i + 2]));
	}
	cout << dp[n-1] << endl;
	return 0;
}


Measured memory_bytes: 3584
# ABC 104: B – AcCepted
s = input()
alphabets = 'abcdefghijklmnopqrstuvwxyz'

isMeet = 'AC'

if s[0] == 'A':
    if s[2:-1].count('C') == 1:
        t = s[1:].replace('C', '')
        for c in t:
            if c not in alphabets:
                isMeet = 'WA'
                break
    else:
        isMeet = 'WA'
else:
    isMeet = 'WA'

print(isMeet)

Measured memory_bytes: 3060
#include <iostream>
 
using namespace std;
 
int main(void){
  int n, x[100000];
  int i, c = 0;
  
  cin >> n >> x[0];
  for(i = 1; i < n; i++){
    cin >> x[i];
    if(x[i-1] < x[i]){
      x[i]--;
    }
    else if(x[i-1] == x[i]){
    }
    else{
      c = 1;
      break;
    }
  }
  if(c == 0){
    cout << "Yes";
  }
  else{
    cout << "No";
  }
  return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int main(){
    IOS;
    long long a;
    cin >> a;
    long long pow = 1;
    long long ans = 0;
    while(a>0){
        ans += pow;
        a /= 2;
        pow *= 2;
    }
    cout << ans <<endl;
}

Measured memory_bytes: 3612
#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define mx 200005

int ar[mx];
char ch[mx];

int n,x,y;

void solve()
{
  scanf("%d%d%d",&n,&x,&y);
  for(int i=1;i<=n;i++)
  for(int j=i+1;j<=n;j++)ar[min({abs(i-j),abs(x-i)+1+abs(j-y),abs(y-i)+1+abs(x-j)})]++;
  for(int i=1;i<n;i++)printf("%d\n",ar[i]);
}

int main()
{
    int t=1;
    while(t--)solve();

    return 0;
}


Measured memory_bytes: 256
S = input()

count = 0
top = 0
end = 0

while True:
    if S[count] == 'A':
        top = count
        break
    count += 1

count = -1
while True:
    if S[count] == 'Z':
        end = count + 1
        break
    count -= 1

if end == 0:
    print(len(S[top:]))
else:
    print(len(S[top:end]))

Measured memory_bytes: 3516
#include<bits/stdc++.h>

using namespace std;

int main(){
int n;
cin>>n;
int k,p;
for (int i = 0; i < n; ++i) {
	cin>>k>>p;
	if(k<=p){
		cout<<k<<endl;
	}else if(k%p==0){
		cout<<p<<endl;
	}else{
		cout<<k%p<<endl;
	}
}
}

Measured memory_bytes: 3116
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define mx2 102
#define mx3 1003
#define mx4 10004
#define mx5 100005
#define mx6 1000006
#define mod 1000000007
#define PI 3.14159265
#define fo(i,n) for(int i=0 ; i<n ; i++)
#define Fo(i,k,n) for(int i=k ; i<n ; i++)
 
typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<pair<int,int>,int> piii;

int n ,k, ans , sum ;
ll a , b , c;
pii arr[mx5];
string str;
 
int main() {
	ios::sync_with_stdio(false);
	//int t;cin>>t;while(t--)
	{
		cin>>a>>b;
		c=__gcd(a,b);
		// ll d=c;
		if(c%2==0)ans++;
		while(c%2==0)
		{
			c/=2;
		}
		for(int i=3 ; i<=sqrt(c) ; i+=2)
		{
			if(c%i==0)ans++;
			while(c%i==0)c/=i;
		}
		if(c>2)ans++;
		cout<<ans+1;
	}
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>

using namespace std;
#define REP(i,n) for((i)=0;(i)<(int)(n);(i)++)
using ll = long long;
using P = pair<int,int>;

int main(void) {
  int x, y;
  cin >> x >> y;

  cout << x + y/2 << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.PriorityQueue;
import java.util.Scanner;


@SuppressWarnings("unchecked")
class Dijkstra{
    class Edge{
        int to,cost;
        Edge(int to,int cost){this.to=to;this.cost=cost;}
    }
    class Node{
        int v,dis;
        Node(int v,int dis){this.v=v;this.dis=dis;}
    }
    List<Edge> edges[];
    int[] d;
    void add_edge(int from,int to,int cost){
        edges[from].add(new Edge(to,cost));
    }
    Dijkstra(int N){
        edges = new ArrayList[N];
        d = new int[N];
        for(int i=0;i<N;++i)edges[i]=new ArrayList<>();
    }
    Dijkstra(int N,int[] from, int[] to,int[] cost){
        edges = new ArrayList[N];
        d = new int[N];
        for(int i=0;i<N;++i)edges[i]=new ArrayList<>();
        for(int i=0;i<from.length;++i)edges[from[i]].add(new Edge(to[i],cost[i]));
    }

    int shortest(int s,int t){
        Arrays.fill(d, Integer.MAX_VALUE);
        d[s]=0;
        PriorityQueue<Node> que = new PriorityQueue<>((a,b)->a.dis-b.dis);
        que.add(new Node(s,0));
        while(!que.isEmpty()){
            Node node = que.poll();
            if(node.dis > d[node.v])continue;
            for(Edge e : edges[node.v]){
                if(d[e.to]<=d[node.v]+e.cost)continue;
                d[e.to]=d[node.v]+e.cost;
                que.add(new Node(e.to, d[e.to]));
            }
        }
        return d[t];
    }



    // AIZU ONLINE JUDGE
    // 単一始点最短経路
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int V = scan.nextInt();
        int E = scan.nextInt();
        int s = scan.nextInt();
        int[] from = new int[E];
        int[] to = new int[E];
        int[] c = new int[E];
        for(int i=0;i<E;++i){
            from[i]=scan.nextInt();
            to[i]=scan.nextInt();
            c[i]=scan.nextInt();
        }
        Dijkstra dijkstra = new Dijkstra(V, from, to, c);
        dijkstra.shortest(s, 0);
        for(int i=0;i<V;++i)System.out.println((dijkstra.d[i]<Integer.MAX_VALUE ? String.valueOf(dijkstra.d[i]):"INF"));
    }

}

class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int V = scan.nextInt();
        int E = scan.nextInt();
        int s = scan.nextInt();
        int[] from = new int[E];
        int[] to = new int[E];
        int[] c = new int[E];
        for(int i=0;i<E;++i){
            from[i]=scan.nextInt();
            to[i]=scan.nextInt();
            c[i]=scan.nextInt();
        }
        Dijkstra dijkstra = new Dijkstra(V, from, to, c);
        dijkstra.shortest(s, 0);
        for(int i=0;i<V;++i)System.out.println((dijkstra.d[i]<Integer.MAX_VALUE ? String.valueOf(dijkstra.d[i]):"INF"));
    }
}


Measured memory_bytes: 300552
#include "bits/stdc++.h"
using namespace std;
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define int long long

int H, W;
char a[51][51];
string s;
int ans;

using State = tuple<int, int, int, int>; // index, i,j , 向き
set<State> st;

int di[4] = { -1,0,1,0 };
int dj[4] = { 0,1,0,-1 };

int ci, cj, d;
int gi, gj;



using namespace std::chrono;

struct Parser {
	using Iter = string::const_iterator;
	int id;
	int n;
	time_t start;
	Parser(string s) :id(0), n(s.size()) {
		start = time(NULL);
	}

	// 戻り値: 終了するとき false 続行するなら true
	bool program(bool exec = true) {
		if (time(NULL) - start >= 1)return false;
		while (id < n && s[id] != '}' && s[id] != ']') {
			bool res = statement(exec);
			if (!res)return false;
		}
		return true;
	}

	bool statement(bool exec) {
		if (s[id] == '[') {
			return s_if(exec);
		}
		else if (s[id] == '{') {
			return s_while(exec);
		}
		else {
			return instruction(exec);
		}
	}

	bool s_if(bool exec) {
		id++;

		bool cond = condition();
		bool ret = program(exec & cond);

		id++;
		return ret;
	}

	bool s_while(bool exec) {
		id++; // {
		int start_id = id;
		//cerr << "s_while " << s[id] << endl;

		bool cond;
		bool ret;
		while (true) {
			cond = condition();
			ret = program(exec & cond);
			if (!(exec & cond))break;
			if (!ret)return false;
			id = start_id;
		}

		id++; // }
		return ret;

	}

	bool iswall(int i, int j) {
		return a[i][j] == '#';
	}

	int char_to_dir(char c) {
		if (c == 'N')return 0;
		if (c == 'E')return 1;
		if (c == 'S')return 2;
		if (c == 'W')return 3;
	}

	// 戻り値: 条件を満たしているかどうか
	bool condition() {
		bool neg = s[id] == '~';
		if (neg)id++;
		bool ret;
		if (s[id] == 'C') {
			int i = ci + di[d];
			int j = cj + dj[d];
			ret = iswall(i, j);
		}
		else if (s[id] == 'T') {
			ret = true;
		}
		else {
			ret = char_to_dir(s[id]) == d;
		}
		id++;
		return ret ^ neg;
	}

	bool instruction(bool exec) {

		//cerr << s[id] << endl;

		if (exec) {
			ans++;
			if (s[id] == '^') {
				int ni = ci + di[d], nj = cj + dj[d];
				if (!iswall(ni, nj))
					ci = ni, cj = nj;
			}
			else if (s[id] == 'v') {
				int ni = ci - di[d], nj = cj - dj[d];
				if (!iswall(ni, nj))
					ci = ni, cj = nj;
			}
			else if (s[id] == '<') {
				d = (d + 3) % 4;
			}
			else if (s[id] == '>') {
				d = (d + 1) % 4;
			}

			//cerr << "(" << ci << "," << cj << ") " << d << endl;
		}
		if (ci == gi && cj == gj)
			return false;

		id++;

		return true;
	}

};

signed main() {

	for (; cin >> H >> W && H;) {
		ans = 0;
		st.clear();
		d = 0;
		rep(i, 0, H)rep(j, 0, W) {
			cin >> a[i][j];
			if (a[i][j] == 's') {
				ci = i, cj = j;
			}
			else if (a[i][j] == 'g') {
				gi = i, gj = j;
			}
		}

		cin.ignore();
		getline(cin, s);

		Parser parser(s);
		parser.program();

		if (!(ci == gi && cj == gj))
			ans = -1;

		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 3240
#include <bits/stdc++.h>
#define ll long long
#define ulli unsigned long long int
#define ld long double  
#define endl "\n"
using namespace std; 


void solve() {
    int n, x;
    cin >> n >> x;

    vector<int> v(n);
    for (int &x: v) {
        cin >> x;
    }

    sort(v.begin(), v.end());

    int count = 0;
    for (int i = 0; i < n; i++) {
        x -= v[i];
        count++;
        if (x <= 0) break;
    }

    cout << ((x == 0) ? count : count - 1) << endl;
}

int main() 
{ 
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL); 
  
    int t = 1; 
    //cin >> t; 
    while (t--) { 
        solve(); 
    } 
  
    cerr << "time taken : " << (float)clock() / CLOCKS_PER_SEC << " secs" << endl; 
    return 0; 
} 


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll>
#define lque queue<ll>
#define lpque priority_queue<ll>
#define dlpque priority_queue<ll,lvector,greater<ll>>
#define P pair<ll,ll> 
#define ALL(a) (a).begin(),(a).end()
#define rep(i,n) for(ll (i)=0; (i)<(n); ++(i))
#define print(a) cout << (a) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll h,w;cin>>h>>w;
  lvector alph(26,0);
  string s;
  rep(i,h) {
    cin>>s;
    rep(j,w) alph[s[j]-'a']++;
  }
  ll g1=(h%2)*(w%2),g2=(h%2)*(w/2)+(w%2)*(h/2),g4=(h/2)*(w/2);
  rep(i,26) if(g1>0&&alph[i]%2==1) {alph[i]-=1;g1--;}
  rep(i,26) if(g2>0&&alph[i]%4==2) {alph[i]-=2;g2--;}
  g4+=g2/2;
  rep(i,26) if(g4>0&&alph[i]>0&&alph[i]%4==0) {g4-=alph[i]/4;alph[i]=0;} 
  puts((accumulate(ALL(alph),0)==0)?"Yes":"No");
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<bitset>
#include<vector>
#include<deque>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cmath>
#include<iomanip>
#include <functional>
using namespace std;
typedef long long ll;
const int mod = 1000000007;
const double EPS = 1e-10;
//cout << fixed << std::setprecision(9)
//memset(a, 0, sizeof(a));
//--------------------------

int main()
{
	int ans = 0;
	int n;
	cin >> n;
	for (int i = 0;i < n;i++) {
		int l, r;
		cin >> l >> r;
		ans += (r - l + 1);
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
import java.io.{BufferedReader, InputStream, InputStreamReader, PrintWriter}
import java.util.StringTokenizer

import scala.collection.mutable
import scala.util.Sorting
import math.{abs, max, min}
import scala.collection.mutable.{ArrayBuffer, ListBuffer}
import scala.reflect.ClassTag

object Main {
  val MOD = 1000000007
  val out = new PrintWriter(System.out)
  def solve(): Unit = {
    val sc = new InputReader(System.in)
    val N = sc.nextInt()
    val A = Array.ofDim[Int](2, N)
    rep(2) { i =>
      rep(N) {j =>
        A(i)(j) = sc.nextInt()
      }
    }
    val ans = map(N) {i =>
      A(0).take(i + 1).sum + A(1).drop(i).sum
    }.max

    out.println(ans)
  }


  def main(args: Array[String]): Unit = {
    solve()
    out.flush()
  }


  class InputReader(val stream: InputStream) {
    private val reader = new BufferedReader(new InputStreamReader(stream), 32768)
    private var tokenizer: StringTokenizer = null

    def next: String = {
      while (tokenizer == null || !tokenizer.hasMoreTokens)
        tokenizer = new StringTokenizer(reader.readLine)
      tokenizer.nextToken
    }

    def nextInt(): Int = next.toInt
    def nextLong(): Long = next.toLong
    def nextChar(): Char = next.charAt(0)
  }

  private def rep(n: Int)(f: Int => Unit): Unit = {
    var i = 0
    while(i < n) {
      f(i)
      i += 1
    }
  }

  private def map[@specialized A: ClassTag](n: Int)(f: Int => A): Array[A] = {
    val res = Array.ofDim[A](n)
    var i = 0
    while(i < n) {
      res(i) = f(i)
      i += 1
    }
    res
  }

  private implicit class ArrayOpts[A](val as: Array[A]) extends AnyVal {
    def maxByOpt[B: Ordering](f: A => B): Option[A] = {
      if (as.nonEmpty) Some(as.maxBy(f)) else None
    }
  }
}


Measured memory_bytes: 25492
#include<iostream>
#include<vector>
using namespace std;

int main() {
	int n;
	cin >> n;
	
	vector<int> ans(n + 1);
	for(int x=1;x<=100;x++)
		for (int y = 1; y <= 100; y++)
			for (int z = 1; z <= 100; z++) {
				int s = x * x + y * y + z * z + x * y + y * z + z * x;
				if (s > n)
					break;
				ans[s]++;
			}
	for (int i = 1; i <= n; i++)
		cout << ans[i] << endl;

}

Measured memory_bytes: 3552
#include <iostream>
#include <iomanip>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <cmath>
#include <algorithm>
#include <iterator>
#define r(i,n) for(int i=0;i<n;i++)
#define R(i,c,n) for(int i=c;i<n;i++)
#define DEBUG(x) cerr << #x << ": " << x << endl;
#define DUMP(a) REP(d,a.size()){cout<<a[d];if(d!=a.size()-1)cout<<" ";else cout<<endl;}
#define ALL(v) v.begin(),v.end()
#define UNIQUE(v)  sort(ALL(v));v.erase(unique(ALL(v)),v.end());
#define pb push_back
using namespace std;
const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, -1, 1};
const double PI = 3.14159265358979323846;

int main(){
  ios::sync_with_stdio(false);
	cin.tie(0);
  int n;
  cin >> n;
  double sum=0;
  int max=0;
  int tmp;
  r(i,n){
    cin >> tmp;
    max = tmp > max ? tmp : max;
    sum += tmp;
  }
  sum -= max/2;
  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<iomanip>
#include<map>
using namespace std;
int n,m,i,ans,c4,c2,c1;
char c;
map<char,int> cnt;
int main()
{
	cin>>n>>m;
	if ((n&1)&&(m&1))
	{
		c1=1;
		c2=((n-1)+(m-1))/2;
		c4=(n-1)*(m-1)/4;
	}
	if ((n&1)&&(!(m&1)))
	{
		c2=m/2;
		c4=(n*m-m)/4;
	}
	if ((!(n&1))&&(m&1))
	{
		c2=n/2;
		c4=(n*m-n)/4;
	}
	if ((!(n&1))&&(!(m&1))) c4=n*m/4;
	for (i=1;i<=n*m;i++)
	{
	 	cin>>c;
		cnt[c]++;
	}
	for (map<char,int>::iterator it=cnt.begin();it!=cnt.end();it++)
	{
		int x=it->second;
		while (c4&&x>=4)
		{
			x-=4;
			c4--;
		}
		while (c2&&x>=2)
		{
			x-=2;
			c2--;
		}
		while (c1&&x>=1)
		{
			x-=1;
			c1--;
		}
		if (x)
		{
			cout<<"No";
			return 0;
		}
	}
	cout<<"Yes";
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define sz(x) ((int)(x).size())
#define rep(i,a,b) for (int i=(a); i<(b); i++)
#define per(i,a,b) for (int i=(b-1); i>=(a); i--)
#define debug(x) cout << #x << " => " << x << endl
using namespace std;

#define fi first
#define se second
#define mp make_pair
typedef pair<int,int> pii;

#define pb push_back
typedef vector<int> vi;

typedef long long ll;
typedef long double ld;

const int MAX_N = 7 + 50;
///----------------------------------------------
int dig[MAX_N];
int sum[MAX_N];
ll  f[MAX_N][MAX_N][MAX_N*MAX_N];
int main() {

	///read
	int n, A; cin>>n>>A;
	rep(i,1,n+1) scanf("%d",&dig[i]);
	rep(i,1,n+1) sum[i] = sum[i-1] + dig[i];
	
	///work
	rep(i,0,n+1) f[i][0][0]=1;
	rep(i,1,n+1) rep(j,1,i+1) rep(k,0,sum[i]+1) {
		f[i][j][k] = f[i-1][j][k];
		if (k>=dig[i])
			f[i][j][k] += f[i-1][j-1][k-dig[i]];
	}
	///debug(233);
	///print
	ll ans=0;
	rep(i,1,n+1) if (i*A<=sum[n]) ans+=f[n][i][i*A];
	cout << ans;

}

Measured memory_bytes: 71936
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef vector<vector<pii> > vvpii;

#define pb push_back
#define endl '\n'
#define INF (int)1e9
#define EPS 1e-9
#define gcd __gcd
#define rs resize
#define FOR(i,a,b) for(int i = a; i < b; i++)
#define by(T, x) [](const T& a, const T& b) { return a.x < b.x; } //for struct sorting

void printV(vector<int> v){
	for(int i = 0; i < v.size(); i++){
		cout << v[i] << " " ;
	}
	cout << endl;
}

void print2V(vvi v){
	FOR(i, 0, v.size()){
		FOR(j, 0, v[i].size()){
			cout << v[i][j] << " ";
		}
		cout << endl;
	}
}

int n, m, indegree[200000], outdegree[200000], dist[200000];
vector<int> adj[200000];

int distance(int cur){
	if(outdegree[cur] == 0){
		return 0;//maybe 1
	}
	if(dist[cur] != -1){
		return dist[cur];
	}
	for(int i = 0; i < adj[cur].size(); i++){
		dist[cur] = max( dist[cur], distance(adj[cur][i])+1 );
	}
	return dist[cur];
}

int main(){
	memset(dist, -1, sizeof dist);
	cin >> n >> m;
	int a, b;
	for(int i = 1; i <= m; i++){
		cin >> a >> b;
		adj[a].push_back(b);
		indegree[b]++;
		outdegree[a]++;
	}
	int ans = 0;
	for(int i = 1; i <= n; i++){
		if(indegree[i] == 0){
			ans = max(ans, distance(i));
		}
	}
	cout << ans;
}

Measured memory_bytes: 14592
def sumdic(dic):
  s=0
  for k, v in dic.items():
    s+=int(k)*v
  return s

a=int(input())
dic={}
for x in input().split():
  if x in dic:
    dic[x]+=1
  else:
    dic[x]=1
s=sumdic(dic)
d=int(input())
for i in range(d):
  (b,c)=[x for x in input().split()]
  if c in dic and b in dic:
    dic[c]+=dic[b]
    s+=(int(c)-int(b))*dic[b]
    dic.pop(b)
  elif b in dic:
    dic[c]=dic[b]
    s+=(int(c)-int(b))*dic[b]
    dic.pop(b)
  print(s)

Measured memory_bytes: 20916
# coding: utf-8
dic = {}
for i in range(int(input())):
    s = input()
    if s in dic:
        dic[s] = (dic[s] + 1) % 2
    else:
        dic[s] = 1
ans = 0
for n in dic.items():
    if n[1] == 1:
        ans += 1
print(ans)

Measured memory_bytes: 17884
#include<stdio.h>
int main(){
  int a,b,c;
  scanf("%d%d",&a,&b);
  if(a>b){c=a,a=b,b=c;}
  while(b>0){
    c=a%b;
    a=b;
    b=c;
  }
  printf("%d\n",a);
  return 0;
}



Measured memory_bytes: 2756
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <array>
#include <vector>
#include <functional>
#include <unordered_map> 
#include <map> 
#include <numeric>
#include <limits>
#include <utility>
#include <queue>
#include <random>
using namespace std;
typedef long long LL;

int main(void) {
	string a;
	cin >> a;
	cout << a[0] << a.size() - 2 << a[a.size() - 1] << endl;
	return 0;
}

Measured memory_bytes: 256
#include<algorithm>
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cmath>
#include<map>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<string>
#include<vector>
using namespace std;
int n,m;
int main(){
	cin>>n>>m;
	if(n+m==15) cout<<'+';
	else if(n*m==15) cout<<'*';
	else cout<<'x';
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
#define int long long 
#define ll long long 
#define pb push_back
#define mp make_pair
#define pii pair<ll,ll>
#define ff first
#define ss second
#define vi vector<ll>
#define mod 1000000007
#define MOD 1000000007
#define full(a) a.begin(),a.end()
#define inf INT_MAX
#define minf INT_MIN
#define dd double
#define fori(x,n) for(ll i=x;i<n;i++)
#define modd 998244353
#define umap unordered_map<ll,ll>
#define mmap map<ll,ll>

ll power(ll a, ll n) 
{ 
    if (n == 0) 
        return 1; 
    ll p = power(a, n / 2); 
    p = (p * p) ; 
    if (n & 1) 
        p = (p * a) ; 
    return p; 
} 

int32_t main() 
{ 
  
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
 
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif

    
 
       ll n;
       cin>>n;
       
       string s="";

       while(n){

        ll k = n/26;         // we are actually decreasing one digit from last
        ll rem = n%26;       // last digit 
        
        if(rem==0){          // considering the corner case of rem being = 26
          k--;
          s+='z';
        }
        else s+='a'+rem-1;
        n=k;
       }

       reverse(full(s));

       cout<<s;

      
 

     
 
return 0;
}     


Measured memory_bytes: 3656
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define ff first
#define ss second
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define fr(j, n)for(int i=j; i<=n; i++)
#define scan(cr)for(auto &it:cr)cin >> it
#define all(cr)cr.begin(), cr.end()
#define F cout << "First\n"
#define S cout << "Second\n"

int main()
{	
	int n, ans;
	cin >> n;
	if(n%1000!=0){
		if(n>1000)ans = ((n/1000)+1)*1000 - n;
		else ans = 1000-n;
	}else {
		ans = 0;
	}
	cout << ans;
	return 0;
}


Measured memory_bytes: 3608
#include <stdio.h>
#include <string>
#include <iostream>
#include <iomanip>
#include <map>
#include <algorithm>
#include <vector>
#include <math.h>
#define MOD 1000000007
using namespace std;

int main(void){
    int n,W;
    cin >> n >> W;
    long long dp[102][200005];
    long long w,v;
    for(int i=0; i<=n; i++){
    	for(int j=0; j<=W; j++){
        dp[i][j]=0;
        }
    }
    for(int i=1; i<=n; i++){
        cin >> w >> v;
        dp[i][w]=max(dp[i-1][w],v);
        for(int j=1; j<=W; j++){
          	dp[i][j]=max(dp[i-1][j],dp[i][j]);
            dp[i][j+w]=max(dp[i-1][j+w],dp[i-1][j]+v);
        }
    }
    long long ans=0;
    for(int i=0; i<=W; i++){
      ans=max(ans,dp[n][i]);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 158720
#include <bits/stdc++.h>
using namespace std;

int main(void)
{
    int n,m;
    cin>>n>>m;
    int t=1900*m+100*(n-m);
    for(int i=1;i<=m;++i)
    {
        t*=2;
    }
    cout <<t <<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef complex<double> P;
typedef pair<int,int> pii;
#define REP(i,n) for(ll i=0;i<n;++i)
#define REPR(i,n) for(ll i=1;i<n;++i)
#define FOR(i,a,b) for(ll i=a;i<b;++i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define MOD (ll)(1e9+7)
#define ADD(a,b) a=((a)+(b))%MOD
#define FIX(a) ((a)%MOD+MOD)%MOD

int main(){
  string a,b;
  int k;
  cin >> a >> b >> k;
  int n = a.size();
  while(b.size() < n)b="0"+b;

  int result = 0;
  REP(mask,1<<n){
    if(__builtin_popcount(mask)>k)continue;
    int bor = 0;
    int ret = 0;
    int base = 1;
    REP(i,n){
      int ca = a[n-1-i]-'0';
      int cb = b[n-1-i]-'0';
      if(ca-bor >= cb){
        ret += (ca-bor-cb)*base;
        bor = 0;
      }else{
        ret += (ca-bor+10-cb)*base;
        bor = 1;
        if(mask & (1<<i)) bor = 0;
      }
      base *= 10;
    }
    result = max(result,ret);
  }

  cout << result << endl;

  return 0;
}

Measured memory_bytes: 1216
import java.util.*;

class Main{
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int a[] = new int[n];
    for(int i=0;i<n;i++){
      a[i] = sc.nextInt();
    }
    Arrays.sort(a);

    int sum_a=0;
    int sum_b=0;

    for(int i=0;i<n;i++){
      if((i%2)==0){
        sum_b += a[i];
      }else{
        sum_a += a[i];
      }
    }
    System.out.println(Math.abs(sum_a - sum_b));
  }
}

Measured memory_bytes: 22100
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

const int MOD = 1000000007, MAXN = 1000 * 1000 + 100;

int ans[MAXN], fact[MAXN], inv[MAXN];

void PreWorks();
int power(int a, int b);
int chose(int k, int n);

int main() {
	PreWorks();
	int n;
	ll all = 0;
	cin >> n;
	for (int i = 0; i <= n; i++)
		ans[i] = (ll)chose(n - i - 1, i - 1) * fact[i] % MOD * fact[n - i - 1] % MOD;
	for (int i = 1; i < n; i++) {
		all += (ll)(ans[i] - ans[i - 1]) * i % MOD;
		//cerr << ans[i] << ' ';
		all %= MOD;
	}
	//cerr << endl;
	cout << (all + MOD) % MOD;
}

int power(int a, int b) {
	if (!b)
		return 1;
	int t = power(a, b / 2);
	return b % 2? (ll)t * t % MOD * a % MOD: (ll)t * t % MOD;
} 

void PreWorks() {
	fact[0] = 1;
	inv[0] = 1;
	for (int i = 1; i < MAXN; i++) {
		fact[i] = (ll)fact[i - 1] * i % MOD;
		inv[i] = power(fact[i], MOD - 2);
	}
}

int chose(int k, int n) {
	if(k >= 0 && n >= k) return (ll)fact[n] * inv[n - k] % MOD * inv[k] % MOD;
	return 0;
}



Measured memory_bytes: 11904
#include<iostream>
#include<iomanip>
#include<math.h>
#include<algorithm>
#include<utility>
#include<functional>
#include<queue>
#include<string.h>
#include<string>
#include<set>
#include<map>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll INF=2e18;

ll N,D;
string s;
int a,b,c;
int main(){
    cin>>N>>D;
    cout<<(N-1)/(2*D+1)+1<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;

#define sz(x) (int)(x.size())
#define int long long

const int N = 1e5 + 2, inf = 1e18;

const double PI = 3.141592653589793;

double calcAngle(double h, double m)  
{  
    // validate the input  
    if (h <0 || m < 0 || h >12 || m > 60)  
        printf("Wrong input");  
  
    if (h == 12) h = 0;  
    if (m == 60) m = 0;  
  
    // Calculate the angles moved  
    // by hour and minute hands  
    // with reference to 12:00  
    double hour_angle = 0.5 * (h * 60.0 + m);  
    double minute_angle = 6.0 * m;  
  
    // Find the difference between two angles  
    double angle = abs(hour_angle - minute_angle);  
  
    // Return the smaller angle of two possible angles  
    angle = min(360.0 - angle, angle);  
  
    return angle;  
}  

int32_t main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);  

    double a, b, h, m;
    cin >> a >> b >> h >> m;
    double theta = calcAngle(h, m);
    theta *= PI/180.0;
    double val = a * a + b * b - (2.0 * a * b * cos(theta));
    val = sqrt(val);
    cout << fixed << setprecision(12);
    cout << val << '\n';
}


Measured memory_bytes: 4236
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(int)(n); i++)

using namespace std;

int main(){
	int A[3][3];
	rep(i,3){
		rep(j,3) cin >> A[i][j];
	}
	int N;
	cin >> N;
	int b[15];
	rep(i,N) cin >> b[i];
	bool ans=false;
	bool S[3][3];
	rep(i,3){
		rep(j,3) S[i][j]=false;
	}
	rep(i,N){
		rep(j,3){
			rep(k,3){
				if(b[i]==A[j][k]) S[j][k]=true;
			}
		}
	}
	if(S[0][0]==true&&S[0][1]==true&&S[0][2]==true) ans=true;
	if(S[1][0]==true&&S[1][1]==true&&S[1][2]==true) ans=true;
	if(S[2][0]==true&&S[2][1]==true&&S[2][2]==true) ans=true;
	if(S[0][0]==true&&S[1][0]==true&&S[2][0]==true) ans=true;
	if(S[0][1]==true&&S[1][1]==true&&S[2][1]==true) ans=true;
	if(S[0][2]==true&&S[1][2]==true&&S[2][2]==true) ans=true;
	if(S[0][0]==true&&S[1][1]==true&&S[2][2]==true) ans=true;
	if(S[2][0]==true&&S[1][1]==true&&S[0][2]==true) ans=true;
	if(ans) cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll w,h,s[100000],t[100001],ans,a;
vector<ll>v;
int main(void){
    cin>>w>>h;
    for(int i=0;i<w;i++){
        cin>>a;
        v.push_back(a);
        ans+=a;
    }
    for(int i=0;i<h;i++){
        cin>>s[i];
    }
    //cout<<ans<<endl;
    sort(v.begin(),v.end());
    for(int i=0;i<w;i++)t[i+1]=t[i]+v[i];
    for(int i=0;i<h;i++){
        a=lower_bound(v.begin(),v.end(),s[i])-v.begin();
        //cout<<w+1<<a<<endl;
        //cout<<(w+1)<<" "<<a<<" "<<s[i]<<" "<<t[a]<<" "<<endl;
        ans+=(w-a+1)*s[i]+t[a];
        //
        //cout<<ans<<endl;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 2676
#include<bits/stdc++.h>
using namespace std ;

#define M 1000000007
#define MM 998244353 
#define ll long long 
#define pb push_back
#define mem0(a) memset(a,0,sizeof(a))
#define mem1(a) memset(a,-1,sizeof(a))
#define memf(a) memset(a,false,sizeof(a))
#define all(v) v.begin(),v.end()
#define sz(a) (ll)a.size()
#define F first
#define S second
#define PI 3.1415926536
#define INF 2000000000000000000
#define endl "\n"
#define _time_ 1.0 * clock() / CLOCKS_PER_SEC
#define popcount(x) __builtin_popcountll(x)
//RNG based on mersenne_twister 
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
ll power(ll b,ll e,ll m)
{
	if(e==0) return 1;
	if(e&1) return b*power(b*b%m,e/2,m)%m;
	return power(b*b%m,e/2,m);
}
ll power( ll b, ll e)
{
	if(e==0) return 1;
	if(e&1) return b*power(b*b,e/2);
	return power(b*b,e/2);
}
template<typename T, typename U> static inline void amin(T &x, U y){ if(y<x) x=y; }
template<typename T, typename U> static inline void amax(T &x, U y){ if(x<y) x=y; }


int _runtimeTerror_()
{
	string s;
	cin>>s;
	ll n=sz(s);
	ll a[n],i;
	ll val=1,mod=0;
	map<ll,ll> m;
	m[0]++;
	for(i=n-1;i>=0;--i)
	{
		mod+=val*(s[i]-'0');
		mod%=2019;
		val*=10;
		val%=2019;
		a[i]=mod;
		m[mod]++;
	}
	ll ans=0;
	//for(i=0;i<n;++i)
	//	cout<<a[i]<<" ";
	//cout<<endl;
	for(i=0;i<n;++i)
	{
		//cout<<m[a[i]]<<endl;
		ans+=m[a[i]]-1;
		--m[a[i]];
	}
	cout<<ans<<endl;
	return 0;
}

int main()
{
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	#ifdef runSieve
		sieve();
	#endif
	#ifdef NCR
		initialize();
	#endif
	int TESTS=1;
	//cin>>TESTS;
	while(TESTS--)
		_runtimeTerror_();
	cerr<<"\n"<<_time_;
	return 0;
}


Measured memory_bytes: 5440
public class Main {
    	public static void main(String[] args) {
    	    java.util.Scanner scanner = new java.util.Scanner(System.in);
    	    int n = scanner.nextInt();
    	    long l0 = 2;
    	    long l1 = 1;
    	    if (n == 1) {
    	    	System.out.println(l1);
    	    	return;
    	    }
    	    long l2 = l1 + l0;
    	    if (n == 2) {
    	    	System.out.println(l2);
    	    	return;
    	    }
    	    for (int i = 2; i < n; i++) {
    	    	long next = l2 + l1;
    	    	l0 = l1;
    	    	l1 = l2;
    	    	l2 = next;
    	    }
    	    System.out.println(l2);
    	}
}

Measured memory_bytes: 23764