akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define END '\n'
#define int long long
#define pb push_back
#define pii pair<int, int>
#define ff first
#define ss second
#define bug(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define loop(i, a, b) for(int i = (a); i < (b); i++)
#define loopb(i, b, a) for(int i = (b); i > (a); --i) 
const int mod = 1e9+7;
const int mod1 = 998244353;
const int inf = 9223372037ll;

void solve()
  {
    int x,k,d;
    cin>>x>>k>>d;
    x = abs(x);
    int best;
    if(x%d != 0)
       {
        if(k<=x/d)
           best = x - k*d;
        else 
           {
            k -= x/d;
            if(k%2)
               best = abs(x%d - d);
            else
               best = x%d;
           }
       }
    else
       {
        if(k<=x/d)
           best = x - k*d;
        else 
           {
            k -= x/d;
            if(k%2)
               best = d;
            else
               best = 0;
           }
       }
    cout<<best;

  } 
signed main()
 {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0); 
     solve();
  //cerr<<END<<1.0*clock();
  return 0;
} 

Measured memory_bytes: 3636
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define int long long
using namespace std;
typedef vector<int>   vint;
typedef pair<int,int> pint;

int sumE[300005];
int sumW[300005];

signed main()
{
    int N; cin>>N;
    string s; cin>>s;

    sumE[0]=sumW[0]=0;
    REP(i,N){
        if(s[i]=='E') sumE[i+1]++;
        if(s[i]=='W') sumW[i+1]++;
        sumE[i+1]+=sumE[i];
        sumW[i+1]+=sumW[i];
    }

    int ans=1e9;
    REP(i,N){
        ans=min(ans,sumW[i]+sumE[N]-sumE[i+1]);
    }
    cout<<ans<<endl;
 
}


Measured memory_bytes: 5380
#include<iostream>
#include<time.h>
#include<stdlib.h>
#include<string>

using namespace std;

int main(){
    int n = 0; cin >> n;
    string a; cin >> a;
    string b; cin >> b;
    for(int i = 0; i < n; i++){
        cout << a[i]; cout << b[i];
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long ll;
#define mod 1000000007

using namespace std;

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);

    // code comes here
    ll c;
    cin>>c;
   ll rem=c/500;
   ll ans=0;
   ans+=rem*1000;
   c=c-rem*500;
   
   ll f=c/5;
   ans+=f*5;
   cout<<ans<<endl;
    


    return 0;
}





Measured memory_bytes: 256
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#include <bits/stdc++.h>
using namespace std;
#define clr(s, x) memset(s, x, sizeof(s))
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
inline int read(){int r=0;char c=getchar();while(c<'0'||c>'9') {c=getchar();}while(c>='0'&&c<='9') {r=r*10+c-'0';c=getchar();}return r;}
inline ll readll(){ll r=0;char c=getchar();while(c<'0'||c>'9') {c=getchar();}while(c>='0'&&c<='9') {r=r*10+c-'0';c=getchar();}return r;}
inline ll qpow(ll a,ll b,ll mod){ll res=1;while(b){if(b&1)res = (res*a)%mod;a=(a*a)%mod;b>>=1;}return res;}
inline ll gcd(ll a,ll b){while(b^=a^=b^=a%=b);return a;}
const double eps = 1e-8;
const ll LLINF = 0x3f3f3f3f3f3f3f3f;
const int INF = 0x3f3f3f3f;
const int mod = 1e9+7;
const int MAXN = 1e6+100;
const int MAXM = 1e5;
ll n,m;
struct node{
	ll x,y;
};
char maze[500][500];
set<pair<pair<ll,ll>,pair<ll,ll> > > sst;
map<pair<pair<ll,ll>,pair<ll,ll> >,ll > ms;
ll dir[4][2]={{-1,0},{1,0},{0,1},{0,-1}};
bool check(ll x,ll y){
	return x>=0&&x<n&&y>=0&&y<m;
}
bool vis[500][500];
ll ans=0;
ll bb,ww;
void bfs(ll x,ll y){
//	memset(vis,0,sizeof(vis));
	queue<node> que;
	node st;st.x=x;st.y=y;
	vis[x][y]=1;
	que.push(st);
	bb++;
	while(!que.empty()){
		node rt=que.front();que.pop();
		for(ll i=0;i<4;i++){
			ll dx=rt.x+dir[i][0];
			ll dy=rt.y+dir[i][1];
			if(check(dx,dy)&&maze[dx][dy]!=maze[rt.x][rt.y]&&!vis[dx][dy]){
				if(maze[dx][dy]=='.') ww++;
				else bb++;
				st.x=dx;st.y=dy;
				vis[dx][dy]=1;
				que.push(st);
			} 
		}
	}
}
int main(){
	cin>>n>>m;
	for(ll i=0;i<n;i++){
		cin>>maze[i];
	} 
	for(ll i=0;i<n;i++){
		for(ll j=0;j<m;j++){
			if(maze[i][j]=='#'&&!vis[i][j]){
				bb=ww=0;
				bfs(i,j);
//				cout<<ww<<" "<<bb<<endl;
				ans+=ww*bb;
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}



Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main()
{
  int k;
  string S, t;
  cin >> k;
  cin >> S;

  if ((int)S.size() <= k)
  {
    cout << S << endl;
  }
  else
  {
    t.resize(k);
    for (int i = 0; i < k; i++)
    {
      t[i] = S[i];
    }
    t += "...";
    cout << t << endl;
  }

  return 0;
}

Measured memory_bytes: 3600
/*
Problem Source : agc-030D
Author : oier_hzy
Time : Nov 24 2019
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

template <typename _tp> inline void read(_tp&x) {
	char ch = getchar(), sgn = 0; x = 0;
	while(ch != '-' and !isdigit(ch)) ch = getchar(); if(ch == '-') ch = getchar(), sgn = 1;
	while(isdigit(ch)) x = x * 10 + (ch ^ 48), ch = getchar(); if(sgn) x = -x;
}

const int N = 3001, p = 1e9+7, inv2 = p+1>>1;
int f[N][N], g[N][N];
int a[N];
int n, Q;

int main() {
	read(n), read(Q);
	for(int i = 1; i <= n; ++ i) read(a[i]);
	for(int i = 1; i <= n; ++ i)
	for(int j = 1; j <= n; ++ j)
		f[i][j] = bool(a[i] < a[j]);
	
	int x, y, cas = 1;
	while(Q--) {
		read(x), read(y);
		for(int i = 1; i <= n; ++ i) {
			if(i != y) {
				g[i][x] = (ll)(f[i][x] + f[i][y]) * inv2%p;
				g[x][i] = (ll)(f[x][i] + f[y][i]) * inv2%p;
			}
			if(i != x) {
				g[i][y] = (ll)(f[i][x] + f[i][y]) * inv2%p;
				g[y][i] = (ll)(f[x][i] + f[y][i]) * inv2%p;
			}
		}
		g[x][y] = g[y][x] = (ll)(f[x][y] + f[y][x]) * inv2%p;
		for(int i = 1; i <= n; ++ i) {
			f[i][x] = g[i][x], f[x][i] = g[x][i];
			f[i][y] = g[i][y], f[y][i] = g[y][i];
		}
		cas = (cas << 1)%p;
	}
	ll sum = 0ll;
	for(int i = 1; i <= n; ++ i)
	for(int j = 1; j < i; ++ j)
		sum += f[i][j];
	sum %= p;
	printf("%lld\n", sum * cas%p);
	return 0;
}

Measured memory_bytes: 70656
a, b, c = map(int, input().split())
k = int(input())
n = 0
while True:
    if b <= a:
        b *= 2
        n += 1
    else:
        break
while True:
    if c <= b:
        c *= 2
        n += 1
    else:
        break
if k >= n:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 9176
#include <iostream>
#include <string>
#include <math.h>
#include <cmath>
#include <string.h>
#include <cstring>
#include <vector>
#include <map>
#include <unordered_map>
#include <iomanip>
#include <queue>
#include <stack>
#include <algorithm>
#define INF 1000000000
#define rep(i,n) for(int (i) = 0; (i) < (n); (i)++)
typedef long long int ll;
using namespace std;

int main(){

	vector<char> ss;
	map<char, int> a = {};
	for (int i = 0; i < 4; i++) {
		char s; cin >> s;
		ss.emplace_back(s);
		a[s]++;
	}
	for (int i = 0; i < 4; i++) {
		if (a[ss[i]] != 2) { cout << "No" << endl; return 0; }
	}
	cout << "Yes" << endl;

	return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second

const int mx=200010;
const ll mod=1e9+7;

int main(){
  int n,k;
  cin >> n >> k;
  cout << (n%k==0?0:1) << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int const MOD = 1000000007;

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
   
    int n; cin>>n; int a[n]; for (int i = 0; i < n; i++)cin>>a[i];
    int dp[n]; fill(dp,dp+n,MOD); dp[0]=0; dp[1]=abs(a[1]-a[0]);
    for (int i = 0; i < n-2; i++){
        dp[i+1]=min(dp[i+1],dp[i]+abs(a[i+1]-a[i]));
        dp[i+2]=min(dp[i+2],dp[i]+abs(a[i+2]-a[i]));
    }
    dp[n-1]=min(dp[n-1],dp[n-2]+abs(a[n-1]-a[n-2]));
    cout<<dp[n-1]<<'\n';
}

Measured memory_bytes: 1024
#include<iostream>
using namespace std;
typedef long long ll;
#define NODE_MAX 100001
int par[NODE_MAX],rk[NODE_MAX];
void init(){
  for(int i=0;i<NODE_MAX;i++){
    par[i]=i;
    rk[i]=0;
  }
}
int root(int x){
  if(x==par[x]) return x;
  return par[x]=root(par[x]);
}
void unite(int x,int y){
  x = root(x);
  y = root(y);
  if(x==y) return;

  if(rk[x]<rk[y]){
    par[x] = y;
  }else{
    par[y] = x;
    if(rk[x]==rk[y]) rk[x]++;
  }
}
bool same(int x,int y){
  return root(x)==root(y);
}
int main(){
  ll n,m,cnt=0;
  cin >> n >> m;
  init();
  ll p[n],x[m],y[m];
  for(int i=0;i<n;i++){
    cin >> p[i];
  }
  for(int i=0;i<m;i++){
    cin >> x[i]>>y[i];
    unite(x[i],y[i]);
  }
  for(int i=0;i<n;i++){
    if(same(i+1,p[i])){
      cnt++;
    }
  }
  cout << cnt << endl;
}


Measured memory_bytes: 3328
K, N = map(int, input().split())
A = list(map(int, input().split()))
num = 0

for i in range(N-1):
  if i == 0:
    num = K-A[N-1]+A[i]
  else:
    num = max(num, A[i+1]-A[i])

print(K-num)

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

using namespace std;

int main(){
  string s;
  string t;
  bool flag=false;
  cin >> s >> t;

  for(int i=0;i<s.size();i++){
    if(s.size()+1 != t.size()){
      flag=true;
      break;
    }
    if(s.at(i)!=t.at(i)){
      flag = true;
      break;
    }
  }
  if(!flag){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
  return 0;
}


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

int main(){
    int x;
    cin>>x;
    switch(x%7){
        case 0:cout<<"thu"<<endl; break;
        case 1:cout<<"fri"<<endl; break;
        case 2:cout<<"sat"<<endl; break;
        case 3:cout<<"sun"<<endl; break;
        case 4:cout<<"mon"<<endl; break;
        case 5:cout<<"tue"<<endl; break;
        case 6:cout<<"wed"<<endl; break;
    }
    return 0;
}


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

int main(void){
  int N;
  cin>>N;
  int max=0;
  bool duplicate=false;
  int A;
  int index=0;
  int second=0;
  for(int i=0;i<N;i++){
    cin>>A;
    if(A==max){
      duplicate=true;
    }
    else if(A>max){
      second=max;
      max=A;
      duplicate=false;
      index=i;
    }
    else if(A>second){
      second=A;
    }
  }
  for(int j=0;j<N;j++){
    if(duplicate){
      cout<<max<<endl;
    }
    else{
      if(index==j){
        cout<<second<<endl;
      }
      else{
        cout<<max<<endl;
      }
    }
  }
  return 0;
}


Measured memory_bytes: 1664
N = int(input())
A, B = map(int, input().split())
probs = [0] * 3
for p in map(int, input().split()):
    if p <= A:
        probs[0] += 1
    elif p <= B:
        probs[1] += 1
    else:
        probs[2] += 1
print(min(probs))


Measured memory_bytes: 2940
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <valarray>
#include <vector>

#define EPS 1e-9
#define INF 1070000000LL
#define MOD 1000000007LL
#define fir first
#define foreach(it,X) for(auto it=(X).begin();it!=(X).end();it++)
#define ite iterator
#define mp make_pair
#define mt make_tuple
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define pb push_back
#define sec second
#define sz(x) ((int)(x).size())

using namespace std;

struct timer{
	time_t start;
	timer(){start=clock();}
	~timer(){cerr<<1.*(clock()-start)/CLOCKS_PER_SEC<<" secs"<<endl;}
};

typedef istringstream iss;
typedef long long ll;
typedef pair<ll,ll> pi;
typedef stringstream sst;
typedef vector<ll> vi;

int n,p[111],q[111],r[111],b[111];

int gcd(int a,int b){
	return b?gcd(b,a%b):a;
}

int f(int cur){
	if(cur==-1)return 1;
	int left=f(r[cur]),right=f(b[cur]);
	int g=gcd(left*p[cur],right*q[cur]);
	return right*q[cur]/g*left+left*p[cur]/g*right;
}

int main2(){
	cin.tie(0);
	ios_base::sync_with_stdio(0);
	
	cin>>n;
	if(n==0)return 1;
	int appear[111]={};
	rep(i,n){
		cin>>p[i]>>q[i]>>r[i]>>b[i];
		int g=gcd(p[i],q[i]);
		p[i]/=g,q[i]/=g;
		r[i]--,b[i]--;
		if(r[i]!=-1)appear[r[i]]=1;
		if(b[i]!=-1)appear[b[i]]=1;
	}
	int par;
	rep(i,n)if(!appear[i])par=i;
	cout<<f(par)<<endl;
	return 0;
}

int main(){
	while(!main2());
}

Measured memory_bytes: 1196
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
#define rrep(i,n) for(int i=1; i<=(n); ++i)
#define drep(i,n) for(int i=(n)-1; i>=0; --i)
#define srep(i,s,t) for (int i=s; i<t; ++i)
#define pb push_back
using namespace std;
using P = pair<int,int>;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef tuple<int,int,int> T;
typedef vector<P> vp;
typedef vector<T> vt;

// head
int main(){
  int x,y,z;
  cin >> x >> y >> z;
  int ans=0;
  ans=max(ans,(x-z)/(y+z));
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <complex>
using namespace std;
typedef complex<double> P;
typedef vector<P> VP;
#define X real()
#define Y imag()
namespace std{
    bool operator < (const P& a, const P& b){
        return (a.X!=b.X) ? a.X<b.X : a.Y<b.Y;
    }
}

int main(){
    int n;
    cin >> n;
    VP a(n);
    for(int i=0; i<n; i++){
        int x,y;
        cin >> x >> y;
        a[i] = P(x, y);
    }
    sort(a.begin(), a.end());
    
    double ans = 1e9;
    for(int i=1; i<n; i++){
        for(int j=i-1; j>=0; j--){
            if((a[j].X -a[i].X)*(a[j].X -a[i].X) > ans) break;
            ans = min(ans, norm(a[i] -a[j]));
        }       
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 10580
#include <bits/stdc++.h>
using namespace std;
#define ALL(A) (A).begin(),(A).end()
#define ll long long
const ll mod = 1e9+7;
const ll INF = 2*1e18;
const int inf = 1e9+7;

int main(void){
	int N;
	cin >> N;
	vector<int> v(N),ans;
	for(int i=0;i<N;i++)cin >> v[i];
	bool ok = 1;
	while(ok){
		ok = 0;
		for(int i=v.size()-1;i>=0;i--){
			if(v[i]==i+1){
				ans.push_back(i);
				v.erase(v.begin()+i);
				ok = 1;
				break;
			}
		}
	}
	if(v.size()==0){
		for(int i=ans.size()-1;i>=0;i--)cout << ans[i]+1 << endl;
	}else{
		cout << -1 << endl;
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>


using namespace std;

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define REPO(i, n) for(int i = 1;i <= n;i++)
#define ll long long
#define INF 1999999999
#define MINF -1999999999
#define INF64 1999999999999999999
#define ALL(n) n.begin(),n.end()
#define MOD 1000000007


ll n, q, k, pa[110000], si[110000];
map<pair<ll, ll>, ll> m;
vector<vector<ll>> s(110000);


void dfs(ll a, ll b) {
	si[a] = b;
	REP(i, s[a].size()) {
		if (s[a][i] != pa[a]) {
			pa[s[a][i]] = a;
			dfs(s[a][i], b + m[make_pair(a, s[a][i])]);
		}
	}
}
int main() {
	cin >> n;
	REP(i, n - 1) {
		ll a, b, c;
		cin >> a >> b >> c;
		a--; b--;
		m[make_pair(a, b)] = c;
		m[make_pair(b, a)] = c;
		s[a].push_back(b);
		s[b].push_back(a);
	}
	cin >> q >> k;
	k--;
	pa[k] = k;
	dfs(k, 0);
	REP(i, q) {
		ll a, b;
		cin >> a >> b;
		a--; b--;
		cout << si[a] + si[b] << endl;
	}
}

Measured memory_bytes: 32512
import Data.Fixed
main = interact $ unlines . map (show' . ab_problem . map read . words) . lines
 where show' (d,m,f) = show d ++ " " ++ show m ++ " " ++ (showFixed False f)
ab_problem [a,b] = (div a b, mod a b, ((fromIntegral a)/(fromIntegral b))::Nano)

Measured memory_bytes: 4056
import sys
cs = { c : 0 for c in list("abcdefghijklmnopqrstuvwxyz")}
for c in list(sys.stdin.read()):
    c = c.lower()
    if c in cs.keys():
        cs[c] = cs[c] + 1
for (c,cnt) in sorted(list(cs.items())):
    print('{0} : {1}'.format(c,cnt))

Measured memory_bytes: 7496
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())
#define endl "\n"

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    ll n;
    cin >> n;
    ll ans = 0;
    reps(i, 100, 1000) {
        string s = to_string(i);
        bool f = true;
        rep(j, len(s)) {
            ll v = s[j] - '0';
            if ((v == 0) || (v > n)) f = false;
        }
        if (f) ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
n, m = map(int, input().split())

matrix = []
for x in range(n):
    matrix.append(list(map(int, input().split())))

vector = []
for x in range(m):
    vector.append(int(input()))

for x in range(n):
    ans = 0
    for y in range(m):
        ans += matrix[x][y] * vector[y]

    print(ans)


Measured memory_bytes: 6008
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define jizz ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define pb push_back
#define MP make_pair
#define F first
#define S second
#define ET cout << "\n"
#define MEM(i,j) memset(i,j,sizeof i)
#define ALL(v) v.begin(),v.end()
#define DB(a,s,e) {for(int i=s;i<e;++i) cerr << a[i] << " ";ET;}
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

int main()
{jizz
	int a,b,c;
	cin >> a >> b >> c;
	if((a-c)*(b-c)<0) cout << "Yes\n";
	else cout << "No\n";
}

Measured memory_bytes: 256
import java.io.IOException;
import java.util.ArrayList;
import java.util.Scanner;
class Main{
	public static void main(String[] args)throws NumberFormatException, IOException{
		//System.out.print(" ");
		Scanner scan = new Scanner(System.in);
		String Ward =scan.nextLine();
		String tem = "";
		int out = 0;
		ArrayList<String> T = new ArrayList<String>();
		while(!tem.equals("END_OF_TEXT")){
			tem = scan.next();
			T.add(tem) ;
		}
		for(int i=0; i<T.size()-1; i++){
			if(T.get(i).equalsIgnoreCase(Ward)){
				out += 1 ;
			}
		}
		System.out.println(out);
	}
}

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

int main() {
    long long x;
    cin >> x;
    long long money = 100;
    int year = 0;
    while (money < x) {
        money *= 1.01;
        year++;
    }
    cout << year << endl;
}

Measured memory_bytes: 3620
// https://atcoder.jp/contests/ddcc2020-qual/tasks/ddcc2020_qual_b
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define DIV(a, b) ((a - 1) / b + 1)

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N;
    cin >> N;
    vector<int> A(N);
    int sum = 0;
    for (auto &x : A) {
        cin >> x;
        sum += x;
    }
    int half = sum / 2;
    int idx = 0, sum1 = 0, sum2 = 0;
    REP(i, N) {
        sum1 += A[i];
        if (sum1 >= half) {
            idx = i;
            break;
        }
    }
    sum2 = sum - sum1;
    int sum3 = sum1 - A[idx];
    int sum4 = sum - sum3;
    cout << min(abs(sum2 - sum1), abs(sum4 - sum3)) << endl;

    return 0;
}


Measured memory_bytes: 1792
/*************************************************************************
	> File Name: B.cpp
	> Author: Knowledge_llz
	> Mail: 925538513@qq.com 
	> Created Time: 2020/4/19 20:41:09
 ************************************************************************/

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<algorithm>
#define For(i,a,b) for(register int i=(a);i<=(b);++i)
#define LL long long
using namespace std;
int read(){
	char x=getchar(); int u=0,fg=0;
	while(!isdigit(x)){ if(x=='-') fg=1; x=getchar(); }
	while(isdigit(x)){ u=(u<<3)+(u<<1)+(x^48); x=getchar(); }
	return fg?-u:u;
}
const LL mod=1e9+7;
int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.in", "r", stdin);
	freopen("output.out", "w", stdout);
#endif
	LL ans=0;
	int n,m;
	n=read(); m=read();
	For(i,m,n){
		LL u=i,v=n-i+1;
		(ans+=(u*v%mod+1ll)%mod)%mod;
	}
	(ans+=1)%=mod;
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 3760
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define x first
#define y second
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define sz(v) (int)v.size()
#define up_b upper_bound
#define low_b lower_bound
#define nl '\n'

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;

typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;

const int N=1e5+11;
const int M=2e6+11;
const int W=1e3+11;
const int inf=1e9;
const ll INF=1e18;
const ll mod=1e9+7;
const ld EPS=1e-9;

ll p[N],q[N],r[N];

int main(){
  ios_base::sync_with_stdio(0);
  cin.tie(0),cout.tie(0);
  int x,y,a,b,c;
  cin>>x>>y>>a>>b>>c;
  for(int i=1;i<=a;i++){
    cin>>p[i];
  }
  for(int i=1;i<=b;i++){
    cin>>q[i];
  }
  for(int i=1;i<=c;i++){
    cin>>r[i];
  }
  sort(p+1,p+a+1);
  sort(q+1,q+b+1);
  sort(r+1,r+c+1);
  reverse(p+1,p+a+1);
  reverse(q+1,q+b+1);
  reverse(r+1,r+c+1);
  vector<int>v;
  ll sum=0;
  for(int i=1;i<=x;i++){
    sum+=p[i];
    v.pb(p[i]);
  }
  for(int i=1;i<=y;i++){
    sum+=q[i];
    v.pb(q[i]);
  }
  sort(all(v));
  ll s1=0,s2=0;
  ll ans=0;
  for(int i=0;i<min(c,x+y);i++){
    s1+=v[i];
    s2+=r[i+1];
    ans=max(ans,s2-s1);
  }
  cout<<sum+ans;
}


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

using namespace std;

int n, k, top, t[5000], a[1000], b[1000];

bool check(int u)
{
    for (int i=1; i<=n; i++)
        a[i] = b[i], a[i] %= u;

    sort(a + 1, a + n + 1);

    int l = 1, r = n, cou = 0;

    while (l < r)
    {
        int o = min(a[l], u - a[r]);
        a[l] -= o, a[r] += o, cou += o;

        if (a[l] == 0) l++;
        if (a[r] == u) r--;
    }

    if (cou <= k) return true;
    return false;
}

void Process()
{
    int o = 0;
    for (int i=1; i<=n; i++)
    {
        b[i] = a[i];    o += a[i];
    }

    for (int i=1; i<=(int) sqrt(o); i++)
        if (o % i == 0) t[++top] = o / i, t[++top] = i;

    sort(t + 1, t + top + 1);

    for (int i=top; i>=1; i--)
        if (check(t[i]) == true)
        {
            cout << t[i];   return;
        }
}

void Input()
{
    ios_base::sync_with_stdio(0);   cin.tie(0);

    cin >> n >> k;
    for (int i=1; i<=n; i++) cin >> a[i];
}

int main()
{
    Input();
    Process();
    return 0;
}


Measured memory_bytes: 256
#pragma warning (disable : 4996 4018)

//#include <thread>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cmath>
#include <cstdio>
#include <vector>
#include <bitset>
#include <limits>
#include <iomanip>
#include <sstream>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;

int n, co[100009], sh = 3;

int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(0);
	cin >> n;
	for (int i = 0; i < n; i++) {
		int nm;
		cin >> nm;
		co[sh + nm]++;
	}
	int mx = 0;
	for (int i = 1; i < 100008; i++)
		mx = max(mx, co[i] + co[i - 1] + co[i + 1]);
	cout << mx << '\n';
	return 0;
}

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

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++) cin >> A.at(i);
  int X = 1, ans = 0;
  while (true) {
    ans++;
    X = A.at(X - 1);
    if (X == 2) {
      cout << ans << endl;
      break;
    }
    else if (ans >= N) {
      cout << -1 << endl;
      break;
    }
  }
}

Measured memory_bytes: 640
#include<stdio.h>
int main(void)
{
  int i,n;
  int a[100];
  scanf("%d",&n);
  for(i=0;i<n;i++)
    scanf("%d",&a[i]);
  for(i=0;i<n;i++){
      if(a[i]%2==0)
        if(a[i]%3!=0&&a[i]%5!=0){
        puts("DENIED");
        return 0;}}
    puts("APPROVED");
    return 0;
}


Measured memory_bytes: 128
#include "bits/stdc++.h"
#define PRECISION(x) cout << fixed << setprecision(x)
#define FAST_IO ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define ALLR(X) (X).rbegin(), (X).rend()
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define F first
#define S second

using namespace std;
 
template<class T> void max_self(T & a, const T & b) { if(a < b) a = b; }
template<class T> void min_self(T & a, const T & b) { if(a > b) a = b; }
typedef long long LL;
const int INF = 1e9 + 7;
const double PI = acos(-1.0);
const double EPS = (1e-9);


int main(){
  FAST_IO  
  string a, b;
  int num, sq;
  cin >> a >> b;
  num = stoi(a) * pow(10, SZ(b)) + stoi(b);

  sq = (int)sqrt(num);
  if(num == sq * sq) cout << "Yes\n";
  else cout << "No\n";
   


  return 0;
}

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

const int INF = 2000000;

struct LineTable{
  int cost;
  int times;
  LineTable(){
    cost = INF;
    times = INF;
  }
};

int main(){

    int n,m;
    while(1){
      cin >> n >> m;
      if(n==0&&m==0){
        break;
      }
      LineTable table[m][m];

      for(int i=0;i<m;i++){
        table[i][i].cost = 0;
        table[i][i].times = 0;
      }

      for(int i=0;i<n;i++){
        int a,b,cost,times;
        cin >> a >> b >> cost >> times;
        table[a-1][b-1].cost = cost;
        table[a-1][b-1].times = times;
        table[b-1][a-1].cost = cost;
        table[b-1][a-1].times = times;
      }

      for(int k=0;k<m;k++){
        for(int i=0;i<m;i++){
          for(int j=0;j<m;j++){
            if(table[i][j].cost > table[i][k].cost + table[k][j].cost){
              table[i][j].cost = table[i][k].cost + table[k][j].cost;
            }
          }
        }
      }

      for(int k=0;k<m;k++){
        for(int i=0;i<m;i++){
          for(int j=0;j<m;j++){
            if(table[i][j].times > table[i][k].times + table[k][j].times){
              table[i][j].times = table[i][k].times + table[k][j].times;
            }
          }
        }
      }

      for(int k=0;k<m;k++){
        for(int i=0;i<m;i++){
          for(int j=0;j<m;j++){
            if(table[j][i].cost > table[j][k].cost + table[k][i].cost){
              table[j][i].cost = table[j][k].cost + table[k][i].cost;
            }
          }
        }
      }

      for(int k=0;k<m;k++){
        for(int i=0;i<m;i++){
          for(int j=0;j<m;j++){
            if(table[j][i].times > table[j][k].times + table[k][i].times){
              table[j][i].times = table[j][k].times + table[k][i].times;
            }
          }
        }
      }

      for(int k=m-1;k>=0;k--){
        for(int i=m-1;i>=0;i--){
          for(int j=m-1;j>=0;j--){
            if(table[i][j].cost > table[i][k].cost + table[k][j].cost){
              table[i][j].cost = table[i][k].cost + table[k][j].cost;
            }
          }
        }
      }

      for(int k=m-1;k>=0;k--){
        for(int i=m-1;i>=0;i--){
          for(int j=m-1;j>=0;j--){
            if(table[i][j].times > table[i][k].times + table[k][j].times){
              table[i][j].times = table[i][k].times + table[k][j].times;
            }
          }
        }
      }

      int k,p,q,r;
      cin >> k;
      /*cin >> p >> q >> r;
      if(r==0){
        cout << table[p-1][q-1].cost;
      }
      else{
        cout << table[p-1][q-1].times;
      }
      for(int i=1;i<k;i++){
        cin >> p >> q >> r;
        if(r==0){
          cout << ' ' <<table[p-1][q-1].cost;
        }
        else{
          cout << ' ' <<table[p-1][q-1].times;
        }
      }
      cout << endl;*/

      for(int i=0;i<k;i++){
        cin >> p >> q >> r;
        if(r==0){
          cout << table[p-1][q-1].cost << endl;;
        }
        else{
          cout << table[p-1][q-1].times << endl;
        }
      }
    }
    return 0;
}

Measured memory_bytes: 3068
#include<iostream>
#include<stdio.h>
//#include <bits/stdc++.h>
#include<vector>
#include<float.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cstring>
#include<math.h>
#include<cmath>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include<cassert>
#include<cmath>
#include<cstdint>

#define INF 1e9
#define rep(i,n)for(int i=0;(i)<(int)(n);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
#define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define vec(type,n) vector<type>(n)
#define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
#define ALL(a)  (a).begin(),(a).end()

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<char,int>;

//最大公約数
ll gcd(ll a,ll b){
    if(a % b == 0)return b;
    else return gcd(b, a % b);
}

ll lcm(ll a, ll b){
    return a  / gcd(a, b) * b;
}
int main(){
   ll n, m;
   cin >> n >> m;
   vector<ll> a(n);
   ll LCM = 1;
   vector<ll> beki_2(n);
   rep(i, n){
       cin >> a[i];
       while(a[i] % 2 == 0){
           a[i] /= 2;
           beki_2[i]++;
       }
       if(i != 0){
           if(beki_2[i] != beki_2[i - 1]){
               cout << 0 << endl;
               return 0;
           }
       }
       LCM = lcm(LCM, a[i]);
       if(LCM > m){
           cout << 0 << endl;
           return 0;
       }
   }
    m /= (ll)(pow(2, beki_2[0] - 1));
    ll res = m / (2 * LCM);
    if(m % (2 * LCM) >= LCM)res++;
    cout << res << endl;

}



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

int main(){
  int n,k;//nはすぬけ君の人数、kはお菓子の数
  cin >> n >> k;
  
  set<int> A;
  int a;
  
  for(int j = 0;j < k;j++){
    int d;//お菓子を持ってるすぬけ君の数or人数の更新
    cin >> d;

    for(int i = 0; i < d;i++){
      cin >> a;
      A.insert(a);
      //cout << i << " " << A.size() << endl;
    }
    
  }
  cout << n - A.size() << endl;
  

}

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

void split(string &s, vector<string> &v) {
  string tmp;
  for (auto &&ch : s) {
    if (ch == ' ') {
      if (!tmp.empty()) {
        v.push_back(tmp);
        tmp.clear();
      }
    } else {
      tmp += ch;
    }
  }
  if (!tmp.empty()) {
    v.push_back(tmp);
  }
}

char normalize(char &c, int n) {
  if (c == '.')
    return c;
  int t;
  t = (int(c) + n) % 26;
  return (t > 18) ? char(t + 78) : char(t + 104);
}

void print(vector<string> &v) {
  for (auto i = v.begin(), e = v.end(); i != e; i++) {
    if (i == e - 1)
      cout << *i << endl;
    else
      cout << *i << " ";
  }
}

int main() {
  string s;
  while (getline(cin, s)) {
    int n;
    vector<string> v;
    split(s, v);
    for (int i = 0; i < 26; i++) {
      vector<string> ret;
      for (auto &&ss : v) {
        string tmp;
        for (auto &&c : ss) {
          tmp += normalize(c, i);
        }
        ret.push_back(tmp);
      }
      if (find(ret.begin(), ret.end(), "this") != ret.end() ||
          find(ret.begin(), ret.end(), "that") != ret.end() ||
          find(ret.begin(), ret.end(), "the") != ret.end()) {
        print(ret);
        break;
      }
    }
    s.clear();
  }

  return 0;
}



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

int main(){
	int n;
	cin >> n;
	
	
	vector<int> d(n);
	rep(i,n){
		d[i] = i+1;
	}
	
	vector<int> p(n);
	vector<int> q(n);
	
	rep(i,n){
		cin >> p[i];
	}
	rep(i,n){
		cin >> q[i];
	}
	
	int a = 0;
	int b = 0;
	int count = 0;
	
	do{
		bool ok1 = true;
		rep(i,n){
			if (d[i] != p[i]) ok1 = false;
		}
		if(ok1) a = count;
		bool ok2 = true;
		rep(i,n){
			if(d[i] != q[i]) ok2 = false;
		}
		if(ok2) b = count;
		count++;
	}while(next_permutation(d.begin(),d.end()));
	
	cout << abs(a-b) << endl;
	
	
	
}

Measured memory_bytes: 256
local function meld(a,b)
    if not a then
        return b
    elseif not b then
        return a
    elseif a[1]<b[1] then
        b[4]=a[3]
        a[3]=b
        return a
    else
        a[4]=b[3]
        b[3]=a
        return b
    end
end

local function pair(a)
    local b,c,d,e
    while a do
        c=false
        b=a
        a=a[4]
        b[4]=false
        if a then
            c=a
            a=a[4]   
            c[4]=false
        end
        b=meld(b,c)
        b[4]=d
        d=b
    end
    while d do
        e=d
        d=d[4]
        a=meld(a,e)
    end
    return a
end


local PairingHeap={}

PairingHeap.empty=function(self)
    return not self[1]
end

PairingHeap.push=function(self,key,value)
    self[1]=meld(self[1],{key,value,false,false})
end

PairingHeap.top=function(self)
    return self[1][2]
end

PairingHeap.pop=function(self)
    self[1]=pair(self[1][3])
end

PairingHeap.join=function(self,other)
    if self[1][1]<other[1][1]then
		other[1][4]=self[1][3]
        self[1][3]=other[1]
	else
		self[1][4]=other[1][3]
        other[1][3]=self[1]
        self[1]=other[1]
    end
    return self
end

PairingHeap.new=function(self)
    local obj={}
    setmetatable(obj,{__index=PairingHeap})
    return obj
end

----------

local n=io.read("n")
local a={}
for i=1,3*n do
    a[i]=io.read("n")
end

local lsum={[0]=0}
local minq=PairingHeap:new()
for i=1,n do
    local A=a[i]
    lsum[i]=lsum[i-1]+A
    minq:push(A,A)
end
for i=n+1,2*n do
    local P=minq:top()
    local A=a[i]
    if A>P then
        lsum[i]=lsum[i-1]+A-P
        minq:pop()
        minq:push(A,A)
    else
        lsum[i]=lsum[i-1]
    end
end

local rsum={[0]=0}
local maxq=PairingHeap:new()
for i=1,n do
    local A=a[3*n-i+1]
    rsum[i]=rsum[i-1]+A
    maxq:push(-A,A)
end
for i=n+1,2*n do
    local P=maxq:top()
    local A=a[3*n-i+1]
    if A<P then
        rsum[i]=rsum[i-1]+A-P
        maxq:pop()
        maxq:push(-A,A)
    else
        rsum[i]=rsum[i-1]
    end
end
local max=-10^16
for i=n,2*n do
    max=math.max(max,lsum[i]-rsum[3*n-i])
end
print(max)

Measured memory_bytes: 34212
#include <iostream>
#include <string>
using namespace std;
int main(){
    string A, B, C;
    cin >> A >> B >> C;
    if(A.back() == B.front() && B.back() == C.front()){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()
using namespace std;
int main() {
    int n;
    cin >> n;
    int A[n+10];
    rep(i, n){
        cin >> A[i];
    }
    int l[n+10], r[n+10];
    l[0] = A[0];
    r[0] = A[n-1];
    for(int i = 1; i < n; i++){
        l[i] = max(A[i], l[i-1]);
        r[i] = max(A[n-i-1], r[i-1]);
    }
    cout << r[n-2] << endl;
    rep(i, n-2){
        cout << max(l[i], r[n-i-3]) << endl;
    }
    cout << l[n-2] << endl;
}

Measured memory_bytes: 3968
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

long long gcd(long long a, long long b)
{
    if(a < b){
        swap(a, b);
    }
    if((a % b) == 0){
        return b;
    }
    return gcd(b, (a % b));
}

long long lcm(long long a, long long b)
{
    return (a * (b / gcd(a, b)));
}

int main() {
    //cout.precision(10);
    int n;
    cin >> n;
    long long ans = 1;
    for(int i = 1; i <= n; i++){
        long long in;
        cin >> in;
        ans = lcm(ans, in);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>

int main(){
  unsigned short *A,*B;

  int C[10001];
  int i,j,n;
  scanf("%d",&n);

  A = malloc(sizeof(short)*n+1);
  B = malloc(sizeof(short)*n+1);

  for(i=0; i<=10000; i++) C[i] = 0;

  for(i=0; i<n; i++){
    scanf("%hu",&A[i+1]);
    C[A[i+1]]++;
  }

      for(i=1; i<=10000; i++){ C[i] = C[i]+C[i-1]; }

    for(j=1; j<=n; j++){
      B[C[A[j]]] = A[j];
      C[A[j]]--;
    }

    for(i=1; i<=n; i++){
      if(i > 1) printf(" ");
      printf("%d", B[i]);
    }
    printf("\n");

    return 0;
}

Measured memory_bytes: 8460
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
using namespace std;

int n;

signed main(){
    while(1){
        cin >> n;
        if(n == 0) break;
        int t[10010];
        rep(i, 0, n) cin >> t[i];
        sort(t, t + n);
        int ans = 0;
        rep(i, 0, n){
            ans += t[i] * (n - 1 - i);
        }
        cout << ans << endl;
    }

}

Measured memory_bytes: 3088
import bisect
n = int(input())
X = tuple(map(int,input().split()))
Xs = list(X)
Xs.sort()
for x in X:
    a = bisect.bisect_left(Xs,x)
    if a >= n/2:
        print(Xs[int(n/2)-1])
    else:
        print(Xs[int(n/2)])

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

int main() {
	set<int> s;
	rep(i,3) {
		int a; cin >> a;
		s.insert(a);
	}
	cout << s.size() << endl;
}

Measured memory_bytes: 3640
import scala.io.StdIn._
object Main extends App {
  val Mod = 1000000007
  val s = readLine

  def dp(rems: Array[Long], digit: Char): Array[Long] = {
    val ret = new Array[Long](13)
    val is = if (digit == '?') (0 to 9) else Seq((digit - '0').toInt)
    for {
      i <- is
      j <- (0 to 12)
    } {
      ret((j * 10 + i) % 13) += rems(j)
      ret((j * 10 + i) % 13) %= Mod
    }
    ret
  }

  val init = s.head match {
    case '?' => Array.tabulate(13)(i => if (i < 10) 1L else 0L)
    case c => Array.tabulate(13)(i => if (i == c - '0') 1L else 0L)
  }

  val result = s.tail.foldLeft(init){(z, d) => dp(z, d)}
  println(result(5))
}

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

int main(){
    int n, a, b, c, q;
    scanf("%d",&n);
    unordered_map<int,int> cnt;
    ll sum = 0;
    for(int i=0;i<n;i++) {
        scanf("%d",&a);
        cnt[a]++;
        sum += a;
    }
    scanf("%d",&q);
    while(q--) {
        scanf("%d %d",&b,&c);
        int bc = cnt[b];
        ll tot = 1LL*b*bc;
        ll add = 1LL*c*bc;
        sum -= tot;
        sum += add;
        cnt[c] += bc;
        cnt[b] = 0;
        printf("%lld\n", sum);
    }
}


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

using ll = long long;

#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define pb push_back
#define mp make_pair
#define fill(x, y) memset(x, y, sizeof(x))
#define even(x) x % 2 == 0
#define odd(x) x % 2 != 0
#define all(x) x.begin(), x.end()
#define pcnt __builtin_popcount
#define buli(x) __builtin_popcountll(x)
#define F first
#define S second
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());

ll qp(ll a, ll b, int mo) { ll ans = 1; do { if (b & 1) ans = 1ll * ans * a % mo; a = 1ll * a * a % mo; } while (b >>= 1); return ans; }
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

template <typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template <typename T, typename... Ts>
auto make_v(size_t a, size_t b, Ts... ts) { return vector<decltype(make_v<T>(b, ts...))>(a, make_v<T>(b, ts...)); }
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }
template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v) { for (auto &e : t) fill_v(e, v); }
// auto dp = make_v<int>(4, h, w);
// fill_v(dp, 0);

const ll INF_LL = (1ll << 60);
const int INF_INT = (int)1e9;
const ll MOD_CONST = (ll)(1e9 + 7);

template <class T>
bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template <class T>
bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }

inline tuple<ll, ll> rotate45(tuple<ll, ll> p) { ll x = get<0>(p), y = get<1>(p); return tuple<ll, ll>(x + y, x - y); }

int lcp(const string &s1, const string &s2) {
	int cnt = 0, n = min(s1.size(), s2.size());
	REP(i, n) {
		if (s1[i] == s2[i]) cnt++;
		else break;
	}
	return cnt;
}

int main(void)
{
	cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(20);

	string str; cin >> str;
	int ans = 700;
	REP(i, 3) if (str[i] == 'o') ans += 100;
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define L long long
using namespace std;
int n,m,a[100010];
L b[100010],p;
int main()
{
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	int i,j,k,l=0;
	scanf("%d%d",&n,&m);
	for(i=1;i<=n;i++)
	  scanf("%d%lld",&a[i],&b[i]);
	for(i=1,j=n;i<=j;)
	  if((b[i]>=b[j] || a[i]>m) && a[j]>m)
	    {
         b[i]+=b[j];
         if(l)
           p+=abs(k-a[j]);
         k=a[j];
         l=1;
         j--;
        }
      else
        {
         b[j]+=b[i];
         if(l)
           p+=abs(k-a[i]);
         k=a[i];
         l=1;
         i++;
        }
    p+=abs(k-m);
    printf("%lld\n",p);
	return 0;
}


Measured memory_bytes: 1408
inputs = input().split()
n, a, b = list(map(int, inputs))
count=0
for num in range(n+1):
    num_str = str(num)
    all = 0
    for i in range(len(num_str)):
       all += int(num_str[i])
    if a <= all <= b:
      count+=num
print(count)

Measured memory_bytes: 3060
# coding: utf-8
while True:
    m,f,r = map(int,input().split())
    
    if m == f == r == -1:
        break
    
    if m == -1 or f == -1 or (m + f) < 30:
        print("F")
    elif (m + f) >= 80:
        print("A")
    elif (m + f) >= 65:
        print("B")
    elif (m + f) >= 50 or r >= 50:
        print("C")
    else:
        print("D")

Measured memory_bytes: 7624
# coding: utf-8
# Your code here!

#n = int(input())
#s = input()
#a = [int(i) for i in input().split()]
#m = [[int(i) for i in input().split()] for j in range(n)] # 縦「n」行

MOD = 10**9+7

n,m = [int(i) for i in input().split()]
a = {int(input()) for i in range(m)}

#print(a)

dp = [0]*(n+10)
dp[0] = 1

for i in range(n):
    if i+1 not in a:
        dp[i+1] += dp[i]
        dp[i+1] %= MOD
    if i+2 not in a:
        dp[i+2] += dp[i]
        dp[i+2] %= MOD

#print(dp)
print(dp[n])








Measured memory_bytes: 50904
import java.util.*;

public class Main {

	public static void main (String[] args)  {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long[] arrA = new long[n + 1];
		for (int i = 0; i <= n; i++) {
			arrA[i] = sc.nextInt();
		}
		long total = 0;
		for (int i = 0; i < n; i++) {
			long b = sc.nextInt();
			if (b > arrA[i]) {
				total += arrA[i];
				b -= arrA[i];
				total += Math.min(arrA[i + 1], b);
				arrA[i + 1] = Math.max(0, arrA[i + 1] - b);
			} else {
				total += b;
			}
		}
		System.out.println(total);
	}
}


Measured memory_bytes: 64736
N = int(input())
A = list(map(int, input().split()))

ans, r = 0, 0
XOR, SUM = 0, 0
for l in range(N):
    while r < N and XOR ^ A[r] == SUM + A[r]:
        XOR ^= A[r]
        SUM += A[r]
        r += 1

    ans += r - l
    XOR ^= A[l]
    SUM -= A[l]

print(ans)


Measured memory_bytes: 24840
// スタックサイズ: 100MB

#define _USE_MATH_DEFINES
#include <iostream>
#include <fstream>
#include <vector>
#include <map>
#include <unordered_map>
#include <string>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <functional>
#include <numeric>
#include <iomanip>
#include <queue>
#include <list>
#include <set>
using namespace std;

typedef int64_t ll;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
const ll INF = 1e18;
const double EPS = 1e-10;
const ll mod = 1e9 + 7;
#define fastio  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define fori(i, a, b) for (ll i = (a); i < (b); ++i)
#define ford(i, a, b) for (ll i = (b - 1); (a) <= i; --i)
#define rep(i, n) fori(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define fst first
#define snd second
ll pw(ll x, ll y) { ll r = 1;  rep(i, y) { r *= x; }; return r; }




int main() {
	fastio;

	string s;
	cin >> s;
	if (s == "SUN") cout << 7 << endl;
	if (s == "MON") cout << 6 << endl;
	if (s == "TUE") cout << 5 << endl;
	if (s == "WED") cout << 4 << endl;
	if (s == "THU") cout << 3 << endl;
	if (s == "FRI") cout << 2 << endl;
	if (s == "SAT") cout << 1 << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
string s;
int lens,p;
int main(){
	cin>>s;
	lens=s.size();p=0;
	while(p<lens and s[p]!='C')p++;
	if(p>=lens-1){cout<<"No"<<endl;return 0;} 
	p++;
	while(p<lens and s[p]!='F')p++;
	if(p>=lens)cout<<"No"<<endl;
	else cout<<"Yes"<<endl;
}

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



int main(){
    int n;
    cin >> n;
    int a[n];
    rep(i, n)   cin >> a[i];
    int minN = 105;
    int maxN = -105;
    rep(i, n){
        if(a[i] < minN) minN = a[i];
        if(maxN < a[i]) maxN = a[i];
    }
    int bestS = 0;
    rep(i, n)   bestS += (pow(a[i] - minN, 2));

    for(int d = minN+1; d <= maxN; d++){
        ll sum = 0;
        rep(i, n)   sum += (pow(a[i] - d, 2));
        if(sum < bestS) bestS = sum;
    }
    cout << bestS << endl;

    return 0;
}


Measured memory_bytes: 256
from math import factorial
N, M = map(int,input().split())

# 素因数分解(小さい方から順に割っていく。sqrt(2)まで)
def factorize(n):
    i = 2
    table = [0]
    cnt= [0]
    while i * i <= n:
        while n % i == 0:
            n /= i
            if table[-1] != i:
                table.append(i)
                cnt.append(0)
            cnt[-1] += 1
        i += 1
    if n > 1:
        table.append(n)
        cnt.append(1)
    return table,cnt


fs,ns = factorize(M)
ans = 1
for n in ns[1:]:
    a = 1
    for i in range(N,n+N):
        a *= i
    ans *= a//factorial(n)
print(ans%(10**9+7))


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

using namespace std;

#define REP(var, n)  for (decltype(n) var = 0; var < (n); var++)
#define RREP(var, n)  for (auto var = n - 1; var != static_cast<decltype(var)>(-1); var--)
#define FOR(var, a, b)  for (auto var = (a); var < (b); var++)
#define RFOR(var, a, b)  for (auto var = b - 1; var != a; var--)

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;

#define all(c) begin(c),end(c)

#define D(x) do { std::cerr << x; } while (0)
#define D2(x) do { std::cerr << #x << ": " << x << std::endl; } while (0)


template<typename T>
std::ostream &operator<<(std::ostream &out, const std::vector<T> &v) {
    if (!v.empty()) {
        out << '[';
        std::copy(v.begin(), v.end(), std::ostream_iterator<T>(out, ", "));
        out << "\b\b]";
    }
    return out;
}


template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
    return os << '(' << p.first << ',' << p.second << ')';
}


auto solve() {
    int n;
    cin >> n;
    vector<string> st(3);
    for (auto &&e: st) cin >> e;
    int res = 0;
    REP(j, n) {
        set<char> diff;
        REP(i, 3) {
            diff.insert(st[i][j]);
        }

        res += diff.size() - 1;
    }

    return res;
}


int main() {
    cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);

//    cout << (solve() ? "Yes" : "No") << endl;
//    cout << (solve() ? "YES" : "NO") << endl;
    cout << solve() << endl;
//    solve();

    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;
string s;
int main()
{
    cin >> s;
    if(s == "abc" || s == "acb" || s == "bac" || s == "bca" || s == "cab" || s == "cba"){
        cout << "Yes";
    } else {
        cout << "No";
    }
    return 0;
}


Measured memory_bytes: 256