akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <cstring>
#include <queue>

using namespace std;

typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vii;
typedef pair<int,int> pii;

#define FASTIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb push_back
#define ff it->first
#define ss it->second
#define all(v) (v).begin(),(v).end()
#define rep(i,n) for(auto i=0;i<n;++i)
#define LOOP_IT(it,s) for(auto it=(s).begin();it!=(s).end();++it)


#ifdef LOCAL
#define cerr cout
#else
#endif

#define TRACE

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif


void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif


const int M = 1e9+7;
int main(int argc,char* argv[])
{
    FASTIO


    ll n,k,sum=0;
    cin>>n>>k;
    for(ll i=k;i<=(n+1);++i)
    {
        ll a = ((i*(i-1))/2);
        ll b = (a+((n+1-i)*i));
        sum+=(b-a+1);
        sum%=M;
    }
    cout<<sum;


    return 0;
}



Measured memory_bytes: 3644
#include <iostream>

using namespace std;

#define int long long

int gcd(int a,int b){
	if(b==0){
		return a;
	}
	return gcd(b,a%b);
}

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

signed main(){
	int n=0;
	int data=0;
	cin >> n;
	cin >> data;
	for(int i=1;i<n;i++){
		int temp=0;
		cin >> temp;
		data=lcm(data,temp);
		//cout << "Now:" << data << endl;
	}
	cout << data << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 1000000000000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


#define SIZE 1000005


ll fact[SIZE],inv_fact[SIZE];

ll extgcd(ll a,ll b,ll &x,ll &y){
	ll d = a;
	if(b != 0){
		d = extgcd(b,a%b,y,x);
		y -= (a/b)*x;
	}else{
		x = 1;
		y = 0;
	}
	return d;
}

ll mod_inverse(ll a,ll m){
    ll x,y;
    extgcd(a,m,x,y);
    return (m+x%m)%m;
}

ll nCk(ll n,ll k){

	ll ret = fact[n]*inv_fact[k];
	ret %= MOD;
	ret *= inv_fact[n-k];

	return ret%MOD;
}



int main(){

	fact[0] = 1;
	for(ll i = 1; i < SIZE; i++){
		fact[i] = i*fact[i-1];
		fact[i] %= MOD;
	}
	inv_fact[SIZE-1] = mod_inverse(fact[SIZE-1],MOD);
	for(ll i = SIZE-1; i >= 1; i--){

		inv_fact[i-1] = inv_fact[i]*i;
		inv_fact[i-1] %= MOD;
	}

	ll H,W,A,B;
	scanf("%lld %lld %lld %lld",&H,&W,&A,&B);

	ll ans = 0;

	ll row = H-A,col = B+1;

	while(row >= 1 && col <= W){

		ll work = nCk(row+col-2,row-1);
		work *= nCk(A+W-(B+1),H-row);
		work %= MOD;
		ans += work;
		ans %= MOD;

		row--;
		col++;
	}

	printf("%lld\n",ans);

	return 0;
}


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

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

  int n;
  cin >> n;
  vector<int> t(n);
  for (int i = 0; i < n; i++) {
    cin >> t[i];
  }
  int m;
  cin >> m;
  int tot = accumulate(t.begin(), t.end(), 0);
  int p, x;
  for (int i = 0; i < m; i++) {
    cin >> p >> x;
    cout << tot + (x - t[p-1]) << '\n';
  }
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <climits>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#define INF_INT (INT_MAX / 2)
#define INF_LONG (LONG_MAX / 2)
//#define DEBUG true
#define DEBUG false
using namespace std;

typedef long long ll;

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

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

  ll sum = 0;
  for(int i = 0; i < n; i++){
    sum += a[i];
  }

  if(sum % ((ll)n * (n + 1) / 2) != 0){
    cout << "NO" << endl;
    return 0;
  }

  int k = (int)(sum / ((ll)n * (n + 1) / 2));

  int d[n];
  for(int i = 0; i < n; i++){
    d[i] = a[(i + 1) % n] - a[i] - k;
  }

  bool ans = true;
  for(int i = 0; i < n; i++){
    if(d[i] > 0 || d[i] % n != 0){
      ans = false;
      break;
    }
  }

  if(ans) cout << "YES" << endl;
  else cout << "NO" << endl;

  return 0;
}


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

vector<int> sieve(int n){
    vector<int> ret;
    vector<bool> is_prime(n+1);
    for(int i=2; i<=n; i++) is_prime[i] = true;
    for(int i=2; i<=n; i++){
        if(is_prime[i]){
            ret.push_back(i);
            for(int j=2*i; j<=n; j+=i) is_prime[j] = false;
        }
    }
    return ret;
}

int main(){
    int N;
    int A[10001];
    cin >> N;
    for(int i=N; i>=0; i--) cin >> A[i];

    auto cand = sieve(N);

    int a = abs(A[N]);
    for(int p=2; p*p<=a; p++){
        if(a % p == 0){
            if(p > N) cand.push_back(p);
            while(a % p == 0) a /= p;
        }
    }
    if(a > N) cand.push_back(a);

    for(int p : cand){
        if(A[0] % p) continue;
        vector<int64_t> sum(N+1, 0);
        for(int i=1; i<=N; i++){
            int d = (i-1) % (p-1) + 1;
            sum[d] += A[i];
        }
        bool ok = true;
        for(int i=1; i<=N; i++) if(sum[i] % p) ok = false;
        if(ok) cout << p << endl;
    }
    return 0;
}


Measured memory_bytes: 384
import sys
sys.setrecursionlimit(4100000)
import math
import itertools
INF = float('inf')
from heapq import heapify, heappop, heappush

def main():
    a,b,c,d = map(int, input().split())

    print(max(0, min(b,d)-max(a,c)))


if __name__ == '__main__':
    main()


Measured memory_bytes: 62840
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
int main(void){
    
    long long N;
    
    cin >> N;
    
    long long sN = sqrt(N);
    
    long long ans = N;
    long long calc;
    for(long long a = 1; a <= sN;a++){
        //cout << a  << endl;
        //cout << N  << endl;
        if(N%a == 0){
            //cout << a  << endl;
            //cout << ans << endl;
            calc = a + N/a - 2;
            ans = min(ans, calc);
        }
    }
    cout << ans  << endl;
    
}


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

int main()
{
 int k,ans=0;
  cin>>k;
  
  for(int a=1;a<=k;a++)
    for(int b=1;b<=k;b++)
      for(int c=1;c<=k;c++)
        ans+=__gcd(a,__gcd(b,c));
  cout<<ans;
  
}

Measured memory_bytes: 3628
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<queue>
#include<deque>
#include<cmath>
#include<map>
#include<set>
#include<cstring>
#include<iomanip> //cout << fixed << setprecision(15) << x << endl;

using namespace std;
typedef long long ll;
const ll INF = 1e9 + 6;
const ll MOD = 1e9 + 7;
const ll LLINF = 1LL<<60;
#define P pair<int, int>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
/* -- template -- */

int main() {
    int x; cin >> x;
    if(x < 1200) {
        cout << "ABC" << endl;
    }else {
        cout << "ARC" << endl;
    }
}


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

char field[12][12];
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

void dfs(int x, int y){
	if(0 <= x && x < 12 && 0 <= y && y < 12 && field[x][y] == '1'){
		field[x][y] = '0';
		for(int i=0; i < 4; i++){
			dfs(x + dx[i], y + dy[i]);
		}
	}
}

int main(){
	while(cin >> field[0][0]){
		int ans = 0;
		for(int i=0; i < 12; i++){
			for(int j=0; j < 12; j++){
				if(i == 0 && j == 0) continue;
				cin >> field[i][j];
			}
		}

		for(int i=0; i < 12; i++){
			for(int j=0; j < 12; j++){
				if(field[i][j] == '1'){
					dfs(i, j);
					ans++;
				}
			}
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 1144
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
int n,bit[200005],cnt[26];
bool vis[200005];
string s;
vector<int> v[26];
ll ans=0;
void add(int x,int v){
	while(x<=n){
		bit[x]+=v;
		x+=x&(-x);
	}
}
int ask(int x){
	int res=0; 
	while(x){
		res+=bit[x];
		x-=x&(-x);
	}
	return res;
}
int main(){
	cin>>s;
	n=s.size();
	s=' '+s;
	for(int i=1;i<=n;++i){
		cnt[s[i]-'a']++;
		v[s[i]-'a'].push_back(i);
	}
	int r=0;
	for(int i=0;i<26;++i){
		r+=cnt[i]%2;
	}
	if(r>1){
		cout<<"-1\n";
		return 0;
	}
	for(int i=1;i<=n+1;++i){
		add(i,1);
	}
	for(int i=1;i<=n;++i){
		if(!vis[i]){
			int c=s[i]-'a';
			int x=v[c][v[c].size()-1];
			if(i==x){
				ans+=(ask(n)-ask(i))/2;
			}
			else{
				ans+=(ask(n)-ask(x));
			}
			add(i,-1);
			add(x,-1);
			vis[i]=vis[x]=1;
			v[c].erase(v[c].end()-1);
		}
	}
	cout<<ans<<'\n';
	return 0;
}

Measured memory_bytes: 2620
#include <bits/stdc++.h>
 
using namespace std;
 
#define lli long long int
#define REP(i,s,l) for(lli i=s;i<l;i++)
#define DEBUG 0
#define INF (1LL<<50)
#define MOD 1000000007

signed main(){

	lli n;
	cin>>n;
	vector<lli> a(n+1),b(n);
	REP(i,0,n+1)cin>>a[i];
	REP(i,0,n)cin>>b[i];

	/*けつからシバき倒せばOK*/

	lli sum=0;

	for(lli i=n-1;i>=0;i--){
		/*敵がまだいるならそいつを足そう*/
		if(a[i+1]>=0) {
			sum += min(a[i+1],b[i]);
			b[i] -= min(a[i+1],b[i]);
		}
		if(a[i]>=0){
			sum += min(a[i],b[i]);
			a[i] -= min(a[i],b[i]);
		}
	}
	cout<<sum<<endl;

	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define MAXN 10005
using namespace std;
int cnt;
int N;

void DFS(int start, int ch){
    if(start > N) return;
    if(ch == 07)
        cnt++;

    if(start < 99999999){
        DFS(start*10 + 3, ch|01);
        DFS(start*10 + 5, ch|02);
        DFS(start*10 + 7, ch|04);
    }
}
int main()
{
    cin >> N;
    DFS(0, 0);
    cout << cnt;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>

#define rep(i,n) for(int i = 0; i < (n); ++i)

#define debug(vec) for(auto v : vec) cout << v << " "; cout << endl;

#define debug2D(vec2D) for(auto vec : vec2D) { for (auto v : vec) cout << v << " "; cout << endl; } 

using namespace std;

typedef long long ll;

const long long int INF = 1 << 30; //10^10
//const ll MOD = 998244353;
const ll MOD = 1000000007;

int main() {
	char c;
	cin >> c;

	cout << static_cast<char>(c+1) << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5;
int n,m,k,f[N],ans[N];
int getf(int x){return f[x]==x?x:f[x]=getf(f[x]);}
vector<int>v[N],e[N];
bitset<N>b1,b2;
int main()
{
    scanf("%d%d%d",&n,&m,&k);
    for(int i=1;i<=n;i++) f[i]=i;
    for(int i=1;i<=m;i++)
    {
        int u,v;scanf("%d%d",&u,&v);
        e[u].push_back(v);
        e[v].push_back(u);
        u=getf(u);v=getf(v);
        if(u==v) continue;
        f[u]=v;
    }
    for(int i=1;i<=k;i++)
    {
        int u,v;scanf("%d%d",&u,&v);
        e[u].push_back(v);
        e[v].push_back(u);
    }
    for(int i=1;i<=n;i++)
        v[getf(i)].push_back(i);
    for(int i=1;i<=n;i++)
        if(f[i]==i)
    {
        b1.reset();
        for(int u:v[i]) b1[u]=1;
        for(int u:v[i])
        {
            b2.reset();
            for(int x:e[u]) b2[x]=1;
            b2[u]=1;
            b2=~b2;
            ans[u]=(b2&b1).count();
        }
    }
    for(int i=1;i<=n;i++)
        printf(i==n?"%d\n":"%d ",ans[i]);
}


Measured memory_bytes: 12408
#include <bits/stdc++.h>
#define FOR(i, a, n) for(ll i = (ll)a; i < (ll)n; i++)
#define rep(i, n) FOR(i, 0, n)
#define ALL(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;

constexpr ll Mod = 998244353;
constexpr ll mod = 1e9 + 7;
constexpr ll inf = 1LL << 60;

template <typename T> constexpr bool chmax(T &a, const T b) {
    if(a >= b) return false;
    a = b;
    return true;
}
template <typename T> constexpr bool chmin(T &a, const T b) {
    if(a <= b) return false;
    a = b;
    return true;
}

/*-------------------------------------------*/

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

    ll I, O, T, J, L, S, Z;
    cin >> I >> O >> T >> J >> L >> S >> Z;

    ll ans = (I / 2 + J / 2 + L / 2) * 2;
    if(I && J && L)
        chmax<ll>(ans, ((I - 1) / 2 + (J - 1) / 2 + (L - 1) / 2) * 2 + 3);

    cout << ans + O << endl;

    return 0;
}

Measured memory_bytes: 256
a = []
while line = gets
  c = line.chomp.split.map(&:to_f)
  a[0] = ((c[2]*c[4] - c[1]*c[5])/(c[0]*c[4] - c[1]*c[3])).round(3)
  a[1] = ((c[2]*c[3] - c[0]*c[5])/(c[1]*c[3] - c[0]*c[4])).round(3)
  a.map! {|v| v == 0 ? 0 : v}
  puts sprintf("%.3f %.3f", a[0], a[1]) 
end

Measured memory_bytes: 6196
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>

#define _USE_MATH_DEFINES
#include <math.h>


int main(void) {

	double result[1001] = { 0 };
	int kurikaesi = 0;

	int n = 0;

	scanf("%d%*[^\n]%*c", &n);



	int x[100] = { 0 };
	int y[100] = { 0 };

	int xy[100] = { 0 };

	int count = 0;


	while (count < n) {
		scanf("%d", &x[count++]);
	}
	count = 0;
	while (count < n) {
		scanf("%d", &y[count++]);
	}


	int i = 0;
	for (; i < n; i++) {
		xy[i] = fabs(x[i] - y[i]);
	}

	// p = 1
	double D1 = 0;

	for (i = 0; i < n; i++) {
		D1 += xy[i];
	}

	// p = 2
	double tempD2 = 0;
	double D2 = 0;
	for (i = 0; i < n; i++) {
		tempD2 += pow(xy[i], 2);
	}
	D2 = sqrt(tempD2);

	// p = 3
	double tempD3 = 0;
	double D3 = 0;
	for (i = 0; i < n; i++) {
		tempD3 += pow(xy[i], 3);
	}
	D3 = cbrt(tempD3);

	// p = ∞
	double max = 0;
	double D = 0;
	for (i = 0; i < n; i++) {

		if (max < xy[i]) {
			max = xy[i];
		}
		
	}
	D = max;

	printf("%lf\n%lf\n%lf\n%lf\n", D1, D2, D3, D);



	return 0;
}



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

int main(){
	int i,j,k,n,m,l,f,x,y,z; string s;
	cin >> n;

	int a[205];
	rep(i, 2*n) cin >> a[i];

	sort(a, a+2*n);

	int total = 0;
	rep(i, 2*n){
		if(i%2 == 0){
			total +=  min(a[i], a[i+1]);
		}
	}

	cout << total << endl;
}

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

int main() {
  int N,M;
  cin >> N;
  vector<string> vec1(N);
  vector<string> vec2(M);
  
  for (int i = 0;i < N;i++) {
    cin >> vec1.at(i);
  }
  
  cin >> M;
  
  for (int i = 0;i < M;i++) {
    cin >> vec2.at(i);
  }
  
  int max = 0;
  max -= 100;
  
  for (int i = 0;i < N;i++) {
    int x = 0;
    for (int j = 0;j < N;j++) {
      if (vec1.at(i) == vec1.at(j)) {
        x++;
      }
    }
    
    for (int k = 0;k < M;k++) {
      if (vec1.at(i) == vec2.at(k)) {
        x--;
      }
    }
    
    if (x > max) {
      max = x;
    }
  }
  
  if (max > 0) {
    cout << max << endl;
  }
  
  else {
    cout << 0 << endl;
  }
  
    
}


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

struct Fast {Fast(){cin.tie(0);ios::sync_with_stdio(0);}} fast;
using intpair = pair<int, int>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define ceiv(a, b) ((int)((a) + (b) - 1)/(int)(b))
#define int long long

signed main(){
    int a, b, c;
    cin >> a >> b >> c;
    if(a == b){
        cout << c << endl;
    }else if(b == c){
        cout << a << endl;
    }else{
        cout << b << endl;
    }
}

Measured memory_bytes: 256
A=int(input())  #500の枚数
B=int(input())  #100の枚数
C=int(input())  #50の枚数
X=int(input())  #合計金額
num=0
#(i,j,k)
for i in range(0,A+1):
    Y=X-500*i
    for j in range(0,B+1):
        Z=Y-100*j
        for k in range(0,C+1):
            W=Z-50*k
            if W==0:
#                print(i,j,k)
                num=num+1
            else: 
                num=num+0
print(num)        

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

#define ll long long int
int main()
{
	ll a,b,c;
	cin>>a>>b>>c;
	map<ll,ll>m;
	m[a]++;
	m[b]++;
	m[c]++;
	if(m.size()==2)
	cout<<"Yes";
	else
	cout<<"No";
	
}

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

int main(){
    int n;cin >> n;
    char s[n];cin >> s;
    int w=0,b=0;
    for(int i=0;i<n;i++){
        if(s[i] == '.'){
            w ++;
        }
    }
    int ans = w;
    int tans;
    for(int i =0;i<n;i++){
        if(s[i] == '#'){
            b ++;
        }
        else{
            w --;
        }
        tans = w + b;
        if(tans < ans){
            ans = tans;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i=0;i < (int)(n);i++)

int dp[1010][1010];
char maze[1010][1010];
const int mod = 1e9+7;

int main(){
   int h,w;
   cin >> h >> w;
   rep(i,h) rep(j,w) cin >> maze[i][j];
   dp[0][0] = 1;
   rep(i,h) rep(j,w){
      if (maze[i][j] == '#') continue;
      if (maze[i+1][j] == '.'){
         dp[i+1][j] += dp[i][j];
         dp[i+1][j]%=mod;
      }
      if (maze[i][j+1] == '.'){
         dp[i][j+1] += dp[i][j];
         dp[i][j+1]%=mod;
      }
   }
   cout << dp[h-1][w-1] << endl;

  
  return 0;
}


Measured memory_bytes: 8392
n, k = [int(i) for i in input().strip().split(" ")]
As = [int(i) for i in input().strip().split(" ")]
M = len(bin(max(As+ [k]))[2:])
As = ['0' * (M - len(bin(int(i))[2:])) + bin(int(i))[2:] for i in As]
As = [[int(i) for i in a] for a in As]
As = list(zip(*As))
k = '0' * (M - len(bin(int(k))[2:])) + bin(int(k))[2:]
ok = False
result = 0
for i, a in enumerate(As):
    x = sum(a)
    if x > n / 2:
        y = "0"
    elif x - n/2 == 0.0:
        y = "0"
    else:
        y = "1"
    if ok:
        if y == "1":
            result += (n - x) * pow(2, (M - i - 1))
        else:
            result += x * pow(2, (M - i - 1))
        continue
    if k[i] == "0" and y == "1":
        y = "0"
    if y == "1":
        result += (n - x) * pow(2, (M - i - 1))
    else:
        result += x * pow(2, (M - i - 1))
    if k[i] == "1" and y == "0":
        ok = True
print(result)


Measured memory_bytes: 171668
package main

import "fmt"

func main() {
	var n, t int
	fmt.Scan(&n, &t)
	as := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&as[i])
	}

	ds := make(map[int]int)
	mx := 0
	mn := as[0]
	for i := 1; i < n; i++ {
		d := as[i] - mn
		ds[d]++
		mx = max(mx, d)
		mn = min(mn, as[i])
	}
	fmt.Println(ds[mx])
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}


Measured memory_bytes: 9088
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author silviase
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        AKthTerm solver = new AKthTerm();
        solver.solve(1, in, out);
        out.close();
    }

    static class AKthTerm {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt() - 1;
            int[] ar = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
            out.println(ar[n]);
        }

    }
}



Measured memory_bytes: 21716
package main

import (
    "bufio"
    "fmt"
    "os"
    "strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
    sc.Scan()
    i, e := strconv.Atoi(sc.Text())
    if e != nil {
        panic(e)
    }
    return i
}

var rdr = bufio.NewReaderSize(os.Stdin, 1000000)

func readLine() string {
    buf := make([]byte, 0, 1000000)
    for {
        l, p, e := rdr.ReadLine()
        if e != nil {
            panic(e)
        }
        buf = append(buf, l...)
        if !p {
            break
        }
    }
    return string(buf)
}

func nextLine() string {
    sc.Scan()
    return sc.Text()
}

func CvM(n int) int {
	if n==1{
		return 1
	}

	return 2*CvM(n/2)+1




}

func main(){
	var H int
	fmt.Scan(&H)
	res:=CvM(H)
	fmt.Println(res)
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int a[26];
int main()
{
	string s;
	cin>>s;
	int n=s.size(),sum=n;
	for(int i=0;i<n;i++)a[s[i]-'a']++;
	long long ans=1;
	for(int i=0;i<n;i++)
	{
		sum--;
		a[s[i]-'a']--;
		ans+=(long long)(sum-a[s[i]-'a']);
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 640
#include <iostream>

using namespace std;
using LL = long long;

int main() {
    int N;
    cin >> N;

    LL a = 1, b = 0;

    while (N--) {
        int q, x;
        cin >> q >> x;

        switch (q) {
            case 1:
                a *= x;
                b *= x;
                break;
            case 2:
                b += x;
                break;
            case 3:
                b -= x;
        }
    }

    cout << -b << " " << a << endl;
}


Measured memory_bytes: 3096
#include<iostream>
#include<vector>
#include<cstring>
#include<algorithm>
using namespace std;
#define MIN(j,k) (((j)>(k))?(k):(j))
int n,ma,mb,a[50],b[50],c[50],dp[45][455][455];
int main(){
	cin>>n>>ma>>mb;
	int xb,x2,x3;
	for(xb=0;xb<n;xb++){
		cin>>a[xb]>>b[xb]>>c[xb];
	}
	for(xb=0;xb<=n*11;xb++){
		for(x2=0;x2<=n*11;x2++){
			if(xb==0 && x2==0){
				dp[0][xb][x2]=0;
			} 
			else if(xb==a[0] && x2==b[0]){
				dp[0][xb][x2]=c[0];
			}
			else dp[0][xb][x2]=1e9;
		}
	}
	for(xb=1;xb<n;xb++){
		for(x2=0;x2<=n*11;x2++){
			for(x3=0;x3<=n*11;x3++){
				dp[xb][x2][x3]=1e9;
				if(x2-a[xb]>=0 && x3-b[xb]>=0)
					dp[xb][x2][x3]=MIN(dp[xb][x2][x3],dp[xb-1][x2-a[xb]][x3-b[xb]]+c[xb]);
				dp[xb][x2][x3]=MIN(dp[xb][x2][x3],dp[xb-1][x2][x3]);
			}
		}
	}
	int RES=1e9;
	for(xb=1;xb<405;xb++){
		int na=ma*xb,nb=mb*xb;
		if(na<=n*11 && nb<=n*11){
			RES=MIN(RES,dp[n-1][na][nb]);
		}
	}
	if(RES==1e9) cout<<-1<<endl;
	else cout<<RES<<endl;
	return 0;
}

Measured memory_bytes: 33024
#include<bits/stdc++.h>
using namespace std;
int main(){
int X,Y;
  cin>>X>>Y;
  int c,t;
  t=(Y/2)-X;
  c=X-t;
  if((t>=0 && c>=0) && (Y%2==0 && c+t==X)){
  cout<<"Yes";}else{
  cout<<"No";}

}


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

int main(){
  char c;
  cin >> c;
  switch(c){
  case 'A':
      cout << 'T' << '\n';
      break;
  case 'T':
      cout << 'A' << '\n';
      break;
  case 'G':
      cout << 'C' << '\n';
      break;
  case 'C':
      cout << 'G' << '\n';
      break;
  }
}

Measured memory_bytes: 256
N,M=map(int,input().split())
S=input()
T=input()

def gcd(a, b):
	while b:
		a, b = b, a % b
	return int(a)

def lcm(a, b):
	return int(a * b // gcd (a, b))
answer =lcm(N,M)

G =gcd(N,M)

for k in range(G):
    if S[int(k*N/G)] !=  T[int(k*M/G)]:
        answer =-1

print(answer)

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

int main(){
  bool flag;
  string S;
  string T[4] = {"maerd", "remaerd", "esare", "resare"};
  cin >> S;
  
  reverse(S.begin(), S.end());
  
  for(int i = 0;i < S.size();){
    flag = false;
    for(int j = 0;j < 4;j++){
      if(S.substr(i,T[j].size()) == T[j]){
        i += T[j].size();
        flag = true;
      }
    }
    
    if(!flag){
      flag = false;
      break;
    }
  }
  
  if(flag){
    cout << "YES" << endl;
  }else{
    cout << "NO"<< endl;
  }
}
  

Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <algorithm>
#include <cstdio>
#include <iomanip>
#include <queue>
#include <deque>
#include <stack>
#include <fstream>
#include <cmath>
#include <random>
#include <complex>
#include <functional>

#define ll int64_t
#define Rep(i, n) for (ll i = 0; i < n; i++)
using namespace std;
typedef vector<ll> vec;
typedef vector<vec> mat;

const ll inf = 1LL << 60;

template<class T> inline void chmin(T& a, T b) {
    if (a > b) {
        a = b;
    }
}
template<class T> inline void chmax(T& a, T b) {
    if (a < b) {
        a = b;
    }
}

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

    string T;
    cin >> T;

    for (char &c : T) {
        if (c == '?') c = 'D';
    }

    cout << T << "\n";
}

Measured memory_bytes: 3740
#include<bits/stdc++.h>
using namespace std;
int main(){
int x,y;
cin >> x >> y;
  int ans=0;
if(x==1)ans+=300000;
if(x==2)ans+=200000;
if(x==3)ans+=100000;
if(y==1)ans+=300000;
if(y==2)ans+=200000;
if(y==3)ans+=100000;
if(x==1 && y==1)ans+=400000;
  cout << ans <<endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
using namespace std;
using int64 = long long;

int main() {
  int N;
  cin >> N;
  vector<int> L(N);
  for (int i = 0; i < N; i++) {
    cin >> L[i];
  }
  int max_of_L = *max_element(L.begin(), L.end());
  int sum_of_L = accumulate(L.begin(), L.end(), 0);
  if (sum_of_L > 2 * max_of_L) {
    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)
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Pl = pair<long long,long long>;
using veci = vector<int>;
using vecl = vector<long long>;
using vecveci = vector<vector<int>>;
using vecvecl = vector<vector<long long>>;

int main() {
    int N; cin >> N;
    veci A(N);
    REP(i,N) cin >> A[i];
    int ans = 0;
    REP(i,N) {
        if(i%2 == 0 && A[i]%2 != 0) ans++;
        
    }
    cout << ans << endl;
}

Measured memory_bytes: 3600
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
// #define int long long

template <class T>
bool INRANGE(T x, T a, T b) { return a <= x && x <= b; }
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define RREP(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define RFOR(i, a, b) for (int i = (a); i >= (b); --i)
#define ALL(v) (v).begin(), (v).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
                      << " " << __FILE__ << endl;

typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

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

    int a, b, c, d;
    cin >> a >> b >> c >> d;

    while (true) {
        c -= b;
        if (c<=0) break;
        a -= d;
        if (a<=0) break;
    }

    if (c<=0) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 3648
#include<stdio.h>

int main(void) {

	int m1, m2;
	int d1, d2;

	scanf("%d %d", &m1, &d1);
	scanf("%d %d", &m2, &d2);

	if (m1 == m2) {
		printf("0\n");
	}
	else {
		printf("1\n");
	}

	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("O3")
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define EPS (1e-9)
#define INF (1e17)
#define PI (acos(-1))
//const double PI = acos(-1);
//const double EPS = 1e-15;
//long long INF=(long long)1E17;
#define i_7 (long long)(1e9+7)
//#define i_7 998'244'353
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
long long po(long a, long b){
    if(b==0){
        return 1;
    }
    
    long long z = po(a,b/2);
    z = mod(z*z);
    if(b%2!=0){
        z = mod(a*z);
    }
    return z;
}
 
bool prime_(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=std::sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}
 
long long gcd_(long long a, long long b){
  if(a<b){
    std::swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd_(b,a%b);
  }
}
 
long long lcm_(long long x, long long y){
  return (x/gcd_(x,y))*y;
}
 
//using namespace std;
//using namespace boost::multiprecision;
//using namespace __gnu_pbds;
 
int main(){
  using namespace std;
  int h, w, k;
  cin>>h>>w>>k;
  vector<string> s(h);
  REP(i, h){
    cin>>s[i];
  }
  
  long long ans = INF;
  REP(div, 1<<h){
    if(div>>(h-1)&1)continue;
    int gid[h];
    int g = 0;
    REP(i, h){
      gid[i] = g;
      if(div>>i&1) g++;
    }
    g++;
    
    int c[10][1000] = {};
    //vector<vector<int>> c(g, vector<int>(w, 0));
    REP(i, h) REP(j, w) c[gid[i]][j] += s[i][j] - '0';
    vector<int> cnt(g, 0);
    
    long long temp = g - 1;
    auto add = [&](int j){
      REP(i, g) cnt[i] += c[i][j];
      bool ok = true;
      REP(i, g) if(cnt[i] > k) ok = false;
      return ok;
    };
    REP(j, w){
      if(!add(j)){
        temp++;
        cnt = vector<int>(g, 0);
        if(!add(j)){
          temp = INF;
          break;
        }
      }
    }
    ans = min(ans, temp);
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
using namespace std;
#include <vector>
#include <string>
#include <iostream>
#include <algorithm>
#define ll long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)

int main(){
    
    int N;
    cin >> N;
    ll A[N];
    
    int mc = 0;
    ll ans = 0;
    for(int i=0;i<N;i++){
        cin >> A[i];
        if(A[i]<0){
            mc++;
            A[i] = -A[i];
        }
        ans += A[i];
    }

    sort(A,A+N);
    if(mc%2==0){
        
    }else{
        ans -= A[0];
        ans -= A[0];
    }
    cout << ans << endl;
    return 0;
}


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

int n,u,v,il,ir,x[N],y[N],ly,q[N],fl[N];ll Ans;
struct T
{
	int x,y,id;
};
bool operator<(T a,T b)
{
	return a.x==b.x?a.y==b.y?a.id<b.id:a.y<b.y:a.x<b.x;
}
set<T>s[N*2];
vector<T>h[N*2];
map<int,int>p,e;
void del(int i)
{
	fl[i]=1;
	q[++ir]=i;
	s[p[x[i]+y[i]]].erase((T){x[i],y[i],i});
	s[e[-x[i]+y[i]]].erase((T){x[i],y[i],i});
}
void mov(int k,int l,int r)
{
	set<T>::iterator i;
	i=s[k].upper_bound((T){l,0,0});
	while(i!=s[k].end()&&(*i)<(T){r+1,0,0})
	{
		del((*i).id);
		i=s[k].upper_bound((T){l,0,0});
	}
}
int sum(int k,int l,int r)
{
	if (!k) return 0;
	return lower_bound(h[k].begin(),h[k].end(),(T){r+1,0,0})-upper_bound(h[k].begin(),h[k].end(),(T){l,0,0});
}
int main()
{
	scanf("%d%d%d",&n,&u,&v);
	for (int i=1;i<=n;i++)
	{
		scanf("%d%d",&x[i],&y[i]);
		if (!p[x[i]+y[i]])p[x[i]+y[i]]=++ly;
		s[p[x[i]+y[i]]].insert((T){x[i],y[i],i});
		if (!e[-x[i]+y[i]])e[-x[i]+y[i]]=++ly;
		s[e[-x[i]+y[i]]].insert((T){x[i],y[i],i});
	}
	il=0;ir=0;
	//q[1]=u;q[2]=v;
	int len=abs(x[u]-x[v])+abs(y[u]-y[v]);
	del(u);del(v);
	while(il<ir)
	{
		il++;
		int tmp=q[il];

		mov(p[x[tmp]+y[tmp]+len],x[tmp],x[tmp]+len);
		mov(p[x[tmp]+y[tmp]-len],x[tmp]-len,x[tmp]);
		mov(e[-x[tmp]+y[tmp]+len],x[tmp]-len,x[tmp]);
		mov(e[-x[tmp]+y[tmp]-len],x[tmp],x[tmp]+len);
	}
	for (int i=1;i<=n;i++)
		if (fl[i])
		{
			h[p[x[i]+y[i]]].push_back((T){x[i],y[i],i});
			h[e[-x[i]+y[i]]].push_back((T){x[i],y[i],i});
		}
	for (int i=1;i<=ly;i++)
		sort(h[i].begin(),h[i].end());
	for (int i=1;i<=n;i++)
	if (fl[i])
	{
		Ans+=sum(p[x[i]+y[i]+len],x[i],x[i]+len-1);
		Ans+=sum(p[x[i]+y[i]-len],x[i]-len,x[i]-1);
		Ans+=sum(e[-x[i]+y[i]+len],x[i]-len+1,x[i]-1);
		Ans+=sum(e[-x[i]+y[i]-len],x[i],x[i]+len);
		//cout<<i<<' '<<Ans<<endl;
	}
	printf("%lld\n",Ans/2);
}


Measured memory_bytes: 70912
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <limits>
#include <map>
#define REP(i,n) for(long (i)=0;(i)<(n);(i)++)
#define REPI(i,a,b) for(long (i)=(a);(i)<(b);(i)++)
#define INF numeric_limits<double>::infinity()
constexpr long MOD = 1e9 + 7;
using namespace std;
using P = pair<long, long>;
using VI = vector<long>;

int main() {
    int cnt = 0;
    int a, b;
    cin >> a >> b;
    REPI(i,a,b+1) {
        string s = to_string(i);
        string t(s);
        reverse(s.begin(), s.end());
        if (t == s) cnt++;
    }
    cout << cnt << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int a = sc.nextInt();
        int b = sc.nextInt();

        int num = 1;
        int cnt = 0;
        while (num < b) {
            num += a - 1;
            cnt++;
        }

        System.out.println(cnt);
    }
}

Measured memory_bytes: 21972
indata = []

indata.append(int(input()))

i = 0

while(indata[i] != 0):
    indata.append(int(input()))
    i += 1

for i in range(len(indata)):
    if indata[i] != 0:
        print("Case {0}: {1}".format((i+1),indata[i]))

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

typedef long long LL;

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(x) (x).begin(),(x).end()
const int IINF = 1e9;
const LL LINF = 1e18;
const LL mod = 1e9+7;

int main() {
    string s;
    cin >> s;
    int a = s.find('A');
    reverse(ALL(s));
    int z = s.size() - s.find('Z');
    cout << z - a << endl;
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; 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 rng(a) a.begin(),a.end()
#define sz(x) (int)(x).size()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define EPS (1e-10)
#define equals(a, b) (fabs((a)-(b)) < EPS)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
  
int main() {
  string s;
  cin >> s;
  int ans = 0;
  for(char c:s) {
    ans += c-'0';
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;

#define REP(i, n) for (int i = 0; i < (n); i++)
#define REP1(i, n) for (int i = 1; i < (n); i++)
#define RREP(i, n) for (int i = (n) - 1; 0 <= i; i--)
#define CIN(A) int A; cin >> A;
#define CIN2(A, B) int A, B; cin >> A >> B;
#define CIN3(A, B, C) int A, B, C; cin >> A >> B >> C;
#define CINVEC(A, N) vector<int> A(N); REP(i, N) cin >> A[i]
#define ANS(ans) cout << (ans) << endl
#define SORT(V) sort(V.begin(), V.end())
#define RSORT(V) sort(V.rbegin(), V.rend())

#define DEBUGV(V) REP(i, V.size()) cout << V.at(i) << " "; cout << endl 

ull
gcd(ull a, ull b)
{
  if (a < b) { ull tmp = a; a = b; b = tmp; }
  if (b) return gcd(b, a % b);
  return a;
}

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

int
main()
{
  CIN(N);
  vector<ull> T(N); REP(i, N) cin >> T[i];

  ull ans = 1;
  for (int i = 0; i < N; i++) {
    ans = lcm(ans, T[i]);
  }

  ANS(ans);

  return 0;
}


Measured memory_bytes: 256
import sys
readline = sys.stdin.readline

N,M,K = map(int,readline().split())
A = [0] + list(map(int,readline().split()))
B = [0] + list(map(int,readline().split()))

for i in range(1, len(A)):
  A[i] += A[i - 1]

for i in range(1, len(B)):
  B[i] += B[i - 1]
  
import bisect
ans = 0
for i in range(len(A)):
  # Aをi冊読んだとき
  rest = K - A[i]
  if rest < 0:
    continue
  # 残りrest分ある
  b_read = bisect.bisect_right(B, rest) - 1
  if i + b_read > ans:
    ans = i + b_read
    
print(ans)
  

Measured memory_bytes: 40888
#include "bits/stdc++.h"
#define rep(i, a) for (int i = 0; i < (a); ++i)
#define REP(i, a, b) for (int i = (a); i < (b); ++i)
#define FORV(a, A) for (auto &a : A)

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


void Main() {
  int h, w;
  cin >> h >> w;
  vector<vector<int>> S(h, vector<int>(w));
  int K = 0;
  {
    vector<vector<int>> A(h, vector<int>(w));
    vector<vector<int>> B(h, vector<int>(w));
    rep(i, h) rep(j, w){
      cin >> A[i][j];
    }
    rep(i, h) rep(j, w){
      cin >> B[i][j];
    }
    rep(i, h) rep(j, w){
      S[i][j] = abs(A[i][j] - B[i][j]);
      K = max(K, S[i][j]);
    }
  }
  K *= h + w;
  K++;

  vector<vector<bool>> dp[h];
  rep(i, h) dp[i].resize(w, vector<bool>(K, false));
  dp[0][0][S[0][0]] = true;
  rep(i, h) rep(j, w) rep(k, K - S[i][j]) if (dp[i][j][k]) {
    if (i!=h-1)
      dp[i+1][j][k + S[i+1][j]] = dp[i+1][j][abs(k-S[i+1][j])] = true;
    if (j!=w-1)
      dp[i][j+1][k + S[i][j+1]] = dp[i][j+1][abs(k-S[i][j+1])] = true;
  }
  rep(k, K) {
    if (dp[h-1][w-1][k]) {
      cout << k << endl;
      return;
    }
  }
}

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  Main();
  return 0;
}



Measured memory_bytes: 10624
using System.Collections.Generic;
using System.Linq;
using System;
using static System.Console;

class Program
{
  static void Main() => new Program().solve();

  void solve()
  {
    var map = new Dictionary<string,string>
    {
      {"A", "T"},
      {"C", "G"},
      {"G", "C"},
      {"T", "A"}
    };
    var b = ReadLine();
    WriteLine(map[b]);
  }
}

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

int main(){
  int A,B,C,K;
  cin >> A >> B >> C >> K;
  int i=0;
  if(A>=K){
    i = K;
  }
  else if(B>=K-A){
    i = A;
  }
  else i = A-(K-A-B);
  
  cout << i << endl;
}

Measured memory_bytes: 3636
#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);
  }
  for(int i=0; i<N; i++){
    if(A.at(i)%2==0){
      if(A.at(i)%3 != 0 && A.at(i)%5 != 0){
        cout << "DENIED" << endl;
        return 0;
      }
    }
  }
  
  cout << "APPROVED" << endl;
  
}

// int型の2次元配列(3×4要素の)の宣言
  //vector<vector<int>> data(3, vector<int>(4));

  // 入力 (2重ループを用いる)
  //for (int i = 0; i < 3; i++) {
    //for (int j = 0; j < 4; j++) {
      //cin >> data.at(i).at(j);
    //}
  //}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <math.h>
#include <stdio.h>
#include <ctype.h>
#include <ios> 
#include <iomanip>
using namespace std;

#define N_MAX   (100000)
#define LL_MAX_NUM (1LL<<60)
#define INF 1e7

typedef long long ll;
typedef long long int lli;

int main() {
    int N, Rnum, Bnum;
    string s;
	cin >> N >> s;
    Rnum = 0;
    for (int i = 0; i < N; i++) {
        if (s[i] == 'R') {
            Rnum++;
        }
    }
    Bnum = N - Rnum;
    if (Rnum > Bnum) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define forn(i,b) for(int i=0 ; i< b ;i++)
#define for1(i,b) for(int i=1 ; i<=b ;i++)
#define reps(i,a,b) for(int i=a ; i< b.length() ;i++)
typedef long long ll;
#define MOD 1000000007

using namespace std;




int main()
{

  int a,b;
  cin >> a >> b;
  if(a<2*b)cout<<0;
  else {
    cout<< a-2*b;
  }

  return 0 ;
}


Measured memory_bytes: 256
N, K = map(int, input().split())
 
lm = 300001
 
# N: 処理する区間の長さ
N0 = 2**(lm-1).bit_length()
INF = 0
data = [INF]*(2*N0)
# a_k の値を x に更新
def update(k, x):
    k += N0-1
    data[k] = x
    while k >= 0:
        k = (k - 1) // 2
        data[k] = max(data[2*k+1], data[2*k+2])
# 区間[l, r)の最小値
def query(l, r):
    L = l + N0; R = r + N0
    s = 0
    while L < R:
        if R & 1:
            R -= 1
            s = max(s, data[R-1])
 
        if L & 1:
            s = max(s, data[L-1])
            L += 1
        L >>= 1; R >>= 1
    return s
 
for _ in range(N):
    a = int(input())
    x = query(max(0, a-K), min(lm, a+K+1))
    update(a, x+1)
 
print(query(0, lm))

Measured memory_bytes: 110644
#include <algorithm>
#include <iostream>

using namespace std;

int main() {
    string s, t;
    cin >> s >> t;

    sort(s.begin(), s.end());
    sort(t.begin(), t.end(), greater<char>());

    if (s < t)
        cout << "Yes\n";
    else
        cout << "No\n";
}


Measured memory_bytes: 256
N = int(input())
A = list(map(int,input().split()))
mod = 10**9 + 7
m = 62
d =[0]*m
ans = 0
for i in range(N):
    for j in range(m):
        if A[i]&(1<<j):
            ans += (1<<j)*(i-d[j])%mod
            d[j] += 1
        else:
            ans += (1<<j)*d[j]%mod
    ans %= mod
print(ans%mod)

Measured memory_bytes: 122808
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
    int a[5];
    for(int i =0;i<5;i++){
        int b;
        cin >> b;
        a[i] = b;
    }
    int k;
    cin >> k;
    string frag = "Yay!";
    for(int i = 0;i<5;i++){
        for(int j = i+1;j<5;j++){
               if(abs(a[j] - a[i]) > k){
                   frag = ":(";
               }
        }
    }
    cout << frag << endl;
}


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

#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ll long long
#define rep(i,n) for(int i=0; i<n; i++)
#define INF 1000000000000
const ll mod=1e9+7;

int main()
{
	int nT; nT=1; //cin>>nT;
	while(nT--)
	{
		int n,k; cin>>n>>k;
		ll a[n]; ll dp[n]; rep(i,n) dp[i]=INF;
		rep(i,n) cin>>a[i];
		if(n==1) cout<<"0";
		else
		{
			dp[0]=0;
			dp[1]=abs(a[1]-a[0]);
			for(int i=2; i<n; i++) 
				{
					for(int j=k; j>0; j--) if(i-j>=0) dp[i]=min(dp[i], dp[i-j]+abs(a[i]-a[i-j]));
				}
			cout<<dp[n-1];
		}
	}
	return 0;
}


Measured memory_bytes: 1792
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;
import std.bigint;


void main()
{
  auto n = readln.chomp.to!int;
  auto a = readln.chomp.split.to!(int[]);
  int odd, even, even4;
  foreach (i; 0..n) {
    if (a[i] % 4 == 0) {
      even4++;
    } else if (a[i] % 2 == 0) {
      even++;
    } else {
      odd++;
    }
  }
  if (even4 >= n / 2) {
    writeln("Yes");
  } else if (even4 - odd >= 0) {
    writeln("Yes");
  } else {
    writeln("No");
  }
}


Measured memory_bytes: 4276
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <cstring>
#include <cstdint>
#include <vector>
#include <algorithm>
using namespace std;
static const long long MOD = 1000000007LL;
typedef long long ll;
#define REP(i,n) for(int i = 0; i < (int)(n); i++)

int main()
{
	int a,b,c;
	cin>>a>>b>>c;
	int ans;
	if(c<a-b)
		ans=0;
	else
		ans=c-a+b;
	cout<<ans<<endl;


	return 0;
}


Measured memory_bytes: 256
# https://atcoder.jp/contests/abc122/tasks/abc122_c

import sys


def input():
    return sys.stdin.readline().strip()


n, q = [int(i) for i in input().split()]
S = input()

ac_table = [0] * (n + 1)  # その位置までにACが何個含まれているかを算出する。

prev = ""
for i in range(1, n + 1):
    if prev == "A" and S[i - 1] == "C":
        ac_table[i] = ac_table[i - 1] + 1
    else:
        ac_table[i] = ac_table[i - 1]
    prev = S[i - 1]

for _ in range(q):
    l, r = [int(i) for i in input().split()]
    print(ac_table[r] - ac_table[l])


Measured memory_bytes: 78380
#include <bits/stdc++.h>
#define int long long
#define pb push_back
#define mp make_pair
using namespace std;
const int inf = 1e18 + 7;
const int N = 1e5 + 1;
const int md = 1e9 + 7;
//dist[0] - takahashi, dist[1] - aoki
std::vector<vector<int>> dist(2, vector<int>(N, 0));
vector <int> g[N];
void dfs(int from, int l, int par, int q) {
  dist[q][from] = l;
  for(int to : g[from]) {
    if(to == par) 
      continue;
    dfs(to, l + 1, from, q);
  }
}
void sol() {
  int n, T, A, u, v;
  int ans = 0;
  cin >> n >> T >> A;
  for(int i=0; i<n; i++) {
    cin >> u >> v;
    g[u].pb(v);
    g[v].pb(u);  
  }
  dfs(T, 0, T, 0);
  dfs(A, 0, A, 1);
  for(int i=1; i<=n; i++) {
    if(dist[0][i] < dist[1][i]) {
      ans = max(ans, dist[1][i]);
    }
  }
  ans--;
  cout << ans;
}

int32_t main() 
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int T = 1;
  //cin >> T; while(T--) 
  sol();
  return 0;
}


Measured memory_bytes: 12656
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    long k = sc.nextLong();
    long a = sc.nextLong();
    long b = sc.nextLong();
    long ans = -1;
    if(a > b) {
      if(a >= k) {
        ans = 1;
      } else {
        long s = 0;
        if((k - a) % (a - b) == 0) {
          s = (k - a) / (a - b);
        } else {
          s = (k - a) / (a - b) + 1;
        }
        ans = 2 * s + 1;
      }
    } else {
      if(a >= k) ans = 1;
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 21844
#undef NDEBUG
#include <bits/stdc++.h>

using namespace std;

#define all(v) (v).begin(), (v).end()

using li = long long;
using ld = long double;

void solve(bool);

int main() {
#ifdef YA
    auto s = clock();
    assert(freopen("input.txt", "r", stdin));
#else
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
#endif

    cout << fixed << setprecision(20);

    solve(true);

#ifdef YA1
    while (true) solve(false);
#endif

#ifdef YA
    cout << endl << endl << "time = " << (clock() - s) / (double)CLOCKS_PER_SEC << endl;
#endif

    return 0;
}

const li linf = 1e18;
const int maxn = 2e5 + 5;

li d[maxn][5];
int n;
li a[maxn];

void solve(bool __attribute__((unused)) read) {
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    for (int i = 0; i <= n; ++i) {
        for (int j = 0; j < 5; ++j) {
            d[i][j] = linf;
        }
    }
    d[0][0] = 0;
	for (int i = 0; i < n; ++i) {
        for (int j = 0; j < 5; ++j) {
            if (d[i][j] == linf)
                continue;
            if (j < 4)
                d[i][j + 1] = min(d[i][j + 1], d[i][j]);
            if (j == 0 || j == 4) {
                d[i + 1][j] = min(d[i + 1][j], d[i][j] + a[i]);
                // cout << "j == 0 || j == 4 " << d[i][j] + a[i] << endl;
            } else if (j == 1 || j == 3) {
                d[i + 1][j] = min(d[i + 1][j], d[i][j] + a[i] % 2 + 2 * (a[i] == 0));
            } else {
                d[i + 1][j] = min(d[i + 1][j], d[i][j] + (a[i] % 2 == 0));
            }
        }
        // cout << endl;
    }
    li ans = linf;
    for (int j = 0; j < 5; ++j) {
        ans = min(ans, d[n][j]);
    }
    cout << ans << "\n";
}

// IDI OBRATNO KOD SMOTRET, RANO POKA SUBMITIT


Measured memory_bytes: 9600