akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>

#define int long long
#define MOD7 1000000007
#define MOD9 1000000009

#define rep(i, n) for (int i = 0; i < (n); i++)
#define itrep(i, a) for (auto i = (a).begin(); i != (a).end(); i++)
#define REP(i, a, n) for (int i = (a); i <= (n); i++)
#define all(a) (a).begin(), (a).end()
#define mp(a, b) make_pair((a), (b))

using namespace std;

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

template<class T> void inputVector(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < v.size(); i++) cin >> v[i];
}

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

    vector<int> A(N), B(N);
    rep(i, N) cin >> A[i] >> B[i];

    vector<pair<int, int>> pr(N);
    rep(i, N) {
        pr[i].first = A[i] + B[i];
        pr[i].second = i;
    }

    sort(all(pr));
    reverse(all(pr));

    int scoreA = 0;
    int scoreB = 0;
    rep(i, N) {
        int idx = pr[i].second;
        if (i % 2 == 0) {
            scoreA += A[idx];
        } else {
            scoreB += B[idx];
        }
    }

    cout << scoreA - scoreB << endl;

    return 0;
}


Measured memory_bytes: 3328
#include "bits/stdc++.h"
using namespace std;

int main(){
    int c[3][3],a[3],b[3];
    int i,j,ans = 1;
    for(i=0;i<3;i++){
        for(j=0;j<3;j++){
            cin >> c[i][j];
        }
    }
    b[0] = c[0][0]-c[0][2];
    b[1] = c[0][1]-c[0][2];
    b[2] = 0;
    for(i=0;i<3;i++) a[i] = c[i][2];

    for(i=0;i<3;i++){
        for(j=0;j<3;j++){
            if(c[i][j] != a[i] + b[j]) ans = 0;
        }
    }

    if(ans) cout << "Yes" << endl;
    else cout << "No" << endl;
    
    return 0;
}

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

int main() {
    const int MAX_COLOR_COUNT = 8;
    vector<int> existing_color(MAX_COLOR_COUNT, 0);

    int N;
    cin >> N;
    vector<int> a(N);
    for (auto& ai : a) cin >> ai;

    int count_over_red = 0;
    for (auto& ai : a) {
        int d = ai / 400;
        if (d >= MAX_COLOR_COUNT) {
            ++count_over_red;
            continue;
        }
        existing_color[d] = 1;
    }

    int min = 0;
    for (auto& c : existing_color) if (c) ++min;

    int max = min + count_over_red;

    cout << (min != 0 ? min : 1) << " " << max << endl;

    return 0;
}

Measured memory_bytes: 256
#include <array>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main(int argc, const char *argv[]) {
  using ll = long long;
  ll n, p;
  string s;
  cin >> n >> p >> s;

  ll ans = 0;
  if (p == 2 || p == 5) {
    for (int i = 0; i < s.size(); ++i) {
      int d = s[i] - '0';
      if (d % p != 0) {
        continue;
      }

      ans += i + 1;
    }

    cout << ans << '\n';
    return 0;
  }

  vector<ll> mods(p, 0);
  mods[0] = 1;

  ll md = 0, pow10 = 1;
  for (int i = s.size() - 1; i >= 0; --i) {
    ll d = s[i] - '0';
    md = (pow10 * d + md) % p;
    mods[md]++;
    pow10 = pow10 * 10 % p;
  }

  for (int i = 0; i < mods.size(); ++i) {
    if (mods[i] >= 2) {
      ans += mods[i] * (mods[i] - 1) / 2;
    }
  }

  cout << ans << "\n";
}

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int H,W,K;
string S[808];
int SY,SX;

int dist[808][808];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>H>>W>>K;
	FOR(y,H) {
		cin>>S[y];
		FOR(x,W) {
			if(S[y][x]=='S') {
				S[y][x]='.';
				SY=y;
				SX=x;
			}
			dist[y][x]=1<<20;
		}
	}
	
	dist[SY][SX]=0;
	queue<int> Q;
	Q.push(SY*1000+SX);
	int mi=1<<20;
	
	while(Q.size()) {
		int cy=Q.front()/1000;
		int cx=Q.front()%1000;
		Q.pop();
		
		mi=min(mi,1+(cy+K-1)/K);
		mi=min(mi,1+(cx+K-1)/K);
		mi=min(mi,1+((H-1-cy)+K-1)/K);
		mi=min(mi,1+((W-1-cx)+K-1)/K);
		if(dist[cy][cx]==K) continue;
		
		FOR(i,4) {
			int dd[]={1,0,-1,0};
			int ty=cy+dd[i];
			int tx=cx+dd[i^1];
			if(ty<0 || tx<0 || ty>=H || tx>=W) continue;
			if(S[ty][tx]=='#') continue;
			if(dist[ty][tx]>dist[cy][cx]+1) {
				dist[ty][tx]=dist[cy][cx]+1;
				Q.push(ty*1000+tx);
			}
		}
	}
	cout<<mi<<endl;
	
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n';
	FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	solve(); return 0;
}


Measured memory_bytes: 3456
#include <stdio.h>
int l, m, n;
int main() {
	while (true) {
		scanf("%d", &l);
		if (l == 0) break;
		bool flag = false;
		for (int i = 0; i < 12; i++) {
			scanf("%d%d", &m, &n);
			l -= (m - n);
			if (l <= 0 && !flag) {
				printf("%d\n", i + 1); flag = true;
			}
		}
		if (!flag) printf("NA\n");
	}
	return 0;
}

Measured memory_bytes: 2748
def base(a, f=False):
    k = 0
    for i in range(64):
        for ind in range(k, len(a)):
            j = a[ind]
            if (j >> i) & 1 == 1:
                break
        else:
            continue

        a[ind], a[k] = a[k], a[ind]
        for ind, j in enumerate(a):
            if ind == k:
                continue
            if (j >> i) & 1 == 1:
                a[ind] ^= a[k]
        k += 1
        if k >= len(a):
            break
    return a[:k]


t = int(input())
for _ in range(t):
    n = int(input())
    a = [int(i) for i in input().split()]
    s = input()

    b = []
    for i in reversed(range(n)):
        if s[i] == '0':
            b = base(b + [a[i]])

        else:
            c = base(b[:] + [a[i]])
            if len(c) != len(b):
                print(1)
                break

    else:
        print(0)


Measured memory_bytes: 69348
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	string s;
	cin >> s;
	for(int i = 0; i < 3; i++){
		if(s[i] == '1'){
			s[i] = '9';
		}else if(s[i] == '9'){
			s[i] = '1';
		}
	}
	cout << s;
}

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

import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline
read = sys.stdin.read


n,x,y = [int(i) for i in read().split()]
x -= 1
y -= 1

ans = [0]*n
for p in range(n):
    for q in range(p+1,n):
        d = min(q-p,abs(p-x)+1+abs(q-y),abs(p-y)+1+abs(q-x))
        ans[d] += 1

print(*ans[1:],sep="\n")


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

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

int main() {
  int n, k;
  cin >> n >> k;
  priority_queue<int> q;
  rep(i,n) {
    int a;
    cin >> a;
    q.push(a);
  }
  rep(i,k) {
    if(q.empty()) continue;
    q.pop();
  }
  long long ans = 0;
  while(!q.empty()) {
    ans += q.top();
    q.pop();
  }
  cout << ans << endl;
}

Measured memory_bytes: 1400
#include<bits/stdc++.h>
using namespace std;
using p = pair<int,int>;
using pp = pair<p,int>;
using ll = long long;
const auto INF =(ll)1e5;

int main(){
  int n;
  cin >>n;
  int i;
  for(i=1;i*i<n;i++);
  cout << (i*i==n?i*i:(i-1)*(i-1));
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<utility>
#include<set>
#include<stack>
#include<queue>
#include<deque>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<bitset>
#include<sstream>
#include<list>
#include<climits>

using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define nrep(i,i0,n) for(int i=(i0);i<(int)(n);++i)
typedef vector<int> vi; typedef pair<int,int> pii; typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vii;
typedef long long ll;
#define MAX 100000
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int main(){
	int h,w;
	scanf("%d%d",&h,&w);
	char col[51][51];
	int cnt=0;
	int dp[51][51];
	rep(i,h){
		scanf("%s",&col[i]);
		rep(j,w){
			if(col[i][j]=='#')cnt++;
			dp[i][j]=MAX;
		}
	}
	queue<pair<int,int> > q;
	q.push(pii(0,0));
	dp[0][0]=1;
	while(!q.empty()){
		pii cur=q.front();q.pop();
		rep(i,4){
			int x=cur.first+dx[i],y=cur.second+dy[i];
			if(0<=x&&x<h&&0<=y&&y<w){
				if(col[x][y]=='.'&&dp[x][y]==MAX){
					dp[x][y]=dp[cur.first][cur.second]+1;
					q.push(pii(x,y));
				}
			}
		}
	}
	int ret=dp[h-1][w-1]!=MAX?(h*w-cnt-dp[h-1][w-1]):-1;
	printf("%d\n",ret);
	return 0;
}



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

string march = "MARCH";

int main(){
    int n;
    cin >> n;
    map<char, long long int> mp;
    for(int i=0;i<n;++i){
        string s;
        cin >> s;
        if(s[0] == 'M' || s[0] == 'A' || s[0] == 'R' || s[0] == 'C' || s[0] == 'H'){
            mp[s[0]]++;
        }
    }

    if(n < 3)cout << 0 << endl;
    else{
        long long int ans = 0;
        if(mp.size() >= 3){
            for(int i=7;i<32;++i){
                long long int tmp = 1;
                if(__builtin_popcount(i) != 3)continue;
                for(int j=0;j<5;++j){
                    if((i>>j)&1)tmp *= mp[march[j]];
                }
                ans += tmp;
            }
        }
        cout << ans << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
using LL = long long;
const LL LINF = 1e18;
const double EPS = 1e-10;
using namespace std;
#define COUT(v) cout<<(v)<<endl
#define CIN(n)  int(n);cin >> (n)
#define LCIN(n) LL(n);cin >> (n)
#define SCIN(n) string(n);cin >> (n)
#define YES(n) cout<<((n)? "YES" : "NO")<<endl
#define Yes(n) cout<<((n)? "Yes" : "No")<<endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) <<endl

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)

#define FOREACH(x,a) for(auto& (x) : (a) )

#define ALL(obj) (obj).begin(),(obj).end()

#define rt return
#define ENDL cout<<endl
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

typedef string::const_iterator State;
class PalseError {};
class Edge{
public:
    int from,to,value;
    Edge(LL a,LL b,LL c){
        from = a;
        to = b;
        value = c;
    }
    Edge(LL a,LL b){
        from = a;
        to = b;
    }
};



int main(){
    int N;cin >> N;
    string s;cin >> s;
    map<char,LL> mp;
    for(int a = 0;a < s.size();a++){
        mp[s.at(a)]++;
    }
    LL ans = 1;
    for(auto a:mp){
        ans *= (a.second+1);
        ans %= MOD;
    }
    cout<<(ans-1)%MOD<<endl;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
#include <iostream>
using namespace std;
#define ll long long
int main() {
	ll n;
	cin>>n;
	ll arr[n];
	
	for(int i=0;i<n;i++){
	    cin>>arr[i];
	}
	ll dp[n][n];
	
	for(int i=0;i<n;i++)
	dp[i][i]=arr[i];
	
	for(int d=1;d<n;d++){
	    for(int i=0;i<n-d;i++){
	        dp[i][i+d]=max(arr[i]-dp[i+1][i+d],arr[i+d]-dp[i][i+d-1]);
	    }
	}
	
	cout<<dp[0][n-1];
	
	return 0;
}

Measured memory_bytes: 70528
#include "stdio.h"

int main()
{
    char s[3];
    int counter = 0;

    scanf("%s", s);

    if (s[0] == '1')
        counter++;
    if (s[1] == '1')
        counter++;
    if (s[2] == '1')
        counter++;

    printf("%d\n", counter);
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> P;
typedef priority_queue<P,vector<P>,greater<P>> P_queue;

#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define mp make_pair
#define ALL(a) a.begin(),a.end()
#define SORT(a) sort(ALL(a))
#define U_ERASE(V) V.erase(unique(ALL(V)), V.end());

const ll MOD=998244353;
const ll mod=1000000007;
const ll INF=1e10;
vec dx={1,0,-1,0};
vec dy={0,1,0,-1};

int main(){
  ll N,M; cin>>N>>M;
  vec H(N);
  rep(i,N) cin>>H[i];
  vector<bool> good(N,true);
  rep(i,M){
    ll x,y; cin>>x>>y;
    x--; y--;
    if(H[x]>=H[y]) good[y]=false;
    if(H[x]<=H[y]) good[x]=false;
  }
  ll ans=0;
  rep(i,N) if(good[i]) ans++;
  cout<<ans<<endl;
}

Measured memory_bytes: 4000
#include<bits/stdc++.h>
using namespace std;
const int Mod=1e9+7;
int dp[2050];
int main()
{
    int n;
    cin>>n;
    dp[0]=1;
    for(int i=0;i<=n;i++)
    {
        for(int j=3;j+i<=n;j++)
        {
            dp[i+j]=(dp[i+j]+dp[i])%Mod;
        }
    }
    cout<<dp[n];
    system("pause");
    return 0;
}

Measured memory_bytes: 3716
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
char s[305];
int n,dp[305][305][305],ans=0,vis[305][305],sum[2][305],add[2][305][305][305];
int sump[305][305][305];
int cr[305][305][305];
const int mod=998244353;
int M(int x){return x>=mod?x-mod:x;}
int main()
{
	scanf("%s",s+1);
	n=strlen(s+1);
	for(int i=1;i<=n;i++)
	{
		sum[0][i]=sum[0][i-1];
		sum[1][i]=sum[1][i-1];
		if(s[i]=='0')sum[0][i]++;
		else sum[1][i]++;
	}
	for(int i=0;i<=n;i++)for(int j=0;j<=i;j++)for(int k=0;k<=i-j;k++)cr[i][j][k]=-2;
	cr[0][0][0]=0;
	vis[sum[0][n]][sum[1][n]]=1;
	//w/b
	for(int i=0;i<=n;i++)
	{
		for(int j=0;j<=i;j++)
		{
			for(int k=0;k<=i-j;k++)
			{
				if(cr[i][j][k]==-2)continue;
				if(j+k&&cr[i][j][k]>=0)vis[j+sum[0][n]-sum[0][i]][k+sum[1][n]-sum[1][i]]=i+1;
				if(cr[i][j][k]==-1)cr[i+1][j][k]=max(cr[i+1][j][k],0);
				else cr[i+1][j][k]=max(cr[i+1][j][k],cr[i][j][k]+1);
				if(i<n&&cr[i][j][k]>-1)
				{
					if(s[i+1]=='0')cr[i+1][j+1][k]=max(cr[i+1][j+1][k],max(-1,cr[i][j][k]-1-(cr[i][j][k]%2==0)));
					else cr[i+1][j][k+1]=max(cr[i+1][j][k+1],max(-1,cr[i][j][k]-1-(cr[i][j][k]%2==0)));
					if(cr[i][j][k]>0&&cr[i][j][k]%2==0&&i<n-1)
					{
						if(s[i+1]=='0')cr[i+2][j+1][k]=max(cr[i+2][j+1][k],cr[i][j][k]);
						else cr[i+2][j][k+1]=max(cr[i+2][j][k+1],cr[i][j][k]);
					}
				}
			}
		}
	}
	dp[0][0][0]=1;
	for(int i=0;i<=n;i++)
	{
		for(int j=0;j<=n;j++)
		{
			for(int k=0;k<=n;k++)
			{
				if(j)add[0][i][j][k]=M(add[0][i][j][k]+add[0][i][j-1][k]);
				if(k)add[1][i][j][k]=M(add[1][i][j][k]+add[1][i][j][k-1]);
				dp[i][j][k]=M(dp[i][j][k]+M(add[0][i][j][k]+add[1][i][j][k]));
				sump[i][j][k]=M(sump[i][j][k]+dp[i][j][k]);
				sump[i][j+1][k]=M(sump[i][j+1][k]+sump[i][j][k]);
				sump[i][j][k+1]=M(sump[i][j][k+1]+sump[i][j][k]);
				if(i==n)continue;
				if(s[n-i]=='0')add[1][i+1][j][k]=M(add[1][i+1][j][k]+dp[i][j][k]);
				else add[0][i+1][j][k]=M(add[0][i+1][j][k]+dp[i][j][k]);
			}
		}
	}
	//printf("@%d\n",dp[2][0][0]);
	for(int i=0;i<=n;i++)
	{
		for(int j=0;j<=n;j++)
		{
			if(i==0&&j==0)continue;
			if(!vis[i][j])continue;
			//printf("%d %d %d %d\n",i,j,vis[i][j],sump[n-vis[i][j]+1][i-sum[0][n]+sum[0][vis[i][j]-1]][j-sum[1][n]+sum[1][vis[i][j]-1]]);
			ans=M(ans+sump[n-vis[i][j]+1][i-sum[0][n]+sum[0][vis[i][j]-1]][j-sum[1][n]+sum[1][vis[i][j]-1]]);
		}
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 493692
#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
using namespace std;
using ll = long long;
using ld = long double;

constexpr int MOD=1000000007;
//constexpr int MOD=998244353;
class modint{
public:
  long long x;
  constexpr modint(long long x=0):x((x%MOD+MOD)%MOD){}
  constexpr modint operator-() const{return modint(-x);}
  constexpr modint& operator+=(const modint& a){
    if((x+=a.x)>=MOD) x-=MOD;
    return *this;
  }
  constexpr modint& operator-=(const modint& a){
    if((x+=MOD-a.x)>=MOD) x-=MOD;
    return *this;
  }
  constexpr modint& operator*=(const modint& a){
    (x*=a.x)%=MOD;
    return *this;
  }
  constexpr modint operator+(const modint& a) const{return modint(*this)+=a;}
  constexpr modint operator-(const modint& a) const{return modint(*this)-=a;}
  constexpr modint operator*(const modint& a) const{return modint(*this)*=a;}
  constexpr bool operator==(const modint& a) const{return this->x==a.x;}
  constexpr bool operator!=(const modint& a) const{return this->x!=a.x;}
  constexpr modint pow(long long expo) const{
    if(expo==0)  return 1;
    modint a=pow(expo>>1);
    a*=a;
    if(expo&1)  a*=(*this);
    return a;
  }
  //for prime MOD
  constexpr modint inv() const{return pow(MOD-2);}
  constexpr modint& operator/=(const modint& a){return (*this)*=a.inv();}
  constexpr modint operator/(const modint& a) const{return modint(*this)/=a;}
};
istream& operator>>(istream& is,const modint& a){return is >> a.x;}
ostream& operator<<(ostream& os,const modint& a){return os << a.x;}

struct matrix{
  vector<vector<modint>> val;
  matrix(int N=50){
    val=vector<vector<modint>>(N,vector<modint>(N,0));
  }
};
matrix I;
matrix operator*(const matrix& a,const matrix& b){
  matrix ans;
  for(int i=0;i<50;i++){
    for(int j=0;j<50;j++){
      for(int k=0;k<50;k++){
        ans.val.at(i).at(j)+=a.val.at(i).at(k)*b.val.at(k).at(j);
      }
    }
  }
  return ans;
}
matrix matrix_pow(const matrix& a,long long expo){
  if(expo==0) return I;
  matrix ans=matrix_pow(a,expo>>1);
  ans=ans*ans;
  if(expo&1)  ans=ans*a;
  return ans;
}

int main(){
  ios_base::sync_with_stdio(false);cin.tie(0);
  int N;
  ll K;
  cin >> N >> K;
  matrix a;
  for(int i=0;i<N;i++){
    for(int j=0;j<N;j++){
      int tmp;
      cin >> tmp;
      a.val.at(i).at(j)=tmp;
    }
  }

  for(int i=0;i<50;i++)  I.val.at(i).at(i)=1;
  matrix x=matrix_pow(a,K);
  modint ans=0;
  for(int i=0;i<N;i++){
    for(int j=0;j<N;j++){
      ans+=x.val.at(i).at(j);
    }
  }
  cout << ans << endl;

  return 0;
}

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

using namespace std;

int main() {
	int t = 1; 
	//cin>>t;
	while (t--) {
		string s, t;
		cin>>s>>t;
		int len_s = s.length(), len_t = t.length();
		int answer = -1;
		if (s == t) {
			cout<<0;
			return 0;
		}
		if (len_s == len_t) {
			int ans = 0;
			for (int i = 0; i < len_s; i++) {
				if (s[i] != t[i]) ans++ ;
			}
			cout<<ans;
			return 0;
		}
		for (int i = 0; i < len_s - len_t; i++) {
			int count = 0;
			for (int j = 0; j < len_t; j++) {
				if (s[i + j] == t[j]) count++;
			}
			answer = max(answer, count);
		}
		cout<<len_t-answer;
	}
}

Measured memory_bytes: 3612
#include <iostream>
#include <algorithm>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <cstring>
#include <utility>
#include <vector>
#include <complex>
#include <valarray>
#include <fstream>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <numeric>
#include <climits>
#include <random>

#define _overload(a, b, c, d, ...) d
#define _rep1(X, A, Y) for (int (X) = (A);(X) <= (Y);++(X))
#define _rep2(X, Y) for (int (X) = 0;(X) < (Y);++(X))
#define rep(...) _overload(__VA_ARGS__, _rep1, _rep2)(__VA_ARGS__)
#define rrep(X,Y) for (int (X) = Y-1;(X) >= 0;--(X))
#define all(X) (X).begin(),(X).end()
#define len(X) ((int)(X).size())
#define mod(n, m) (((n)%(m)+(m))%m)
#define fi first
#define sc second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
const int INFINT = 1 << 30;                          // 1.07x10^ 9
const ll INFLL = 1LL << 60;                          // 1.15x10^18
const double EPS = 1e-10;
const int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

const int MAX_N = 2000, MAX_M = 2000;
int N, M;
int S[MAX_N+1], T[MAX_M+1];

ll dp[MAX_N+1][MAX_M+1];

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

  cin >> N >> M;
  rep(i, 1, N) cin >> S[i];
  rep(i, 1, M) cin >> T[i];

  for (int i = 1; i <= N; ++i) {
    for (int j = 1; j <= M; ++j) {
      dp[i][j] = mod(dp[i-1][j] + dp[i][j-1], MOD);
      if (S[i] != T[j]) dp[i][j] = mod(dp[i][j]-dp[i-1][j-1], MOD);
      else dp[i][j] = mod(dp[i][j]+1, MOD);
    }
  }

  cout << mod(dp[N][M] + 1, MOD) << endl;

  return 0;
}


Measured memory_bytes: 31488
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<set>
#include<map>
#include<queue>
#define REP(i,a) for (int i = 0;i < (a);++i)
#define FOR(i,a,b) for (int i = (a);i < (b); ++i)
#define FORR(i,a,b) for (int i = (a);i >= (b); --i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SORT(list) sort(ALL((list)));
#define MOD 1000000007
using namespace std;
using ll = long long;
int main(){
    string s;
    cin >> s;
    if(s.length()%2==1){
        cout << "No" << endl;
        return 0;
    }
    REP(i,s.length()){
        if(i%2){
            if(s[i]!='i'){
                cout << "No" << endl;
                return 0;
            }
        }
        else{
            if(s[i]!='h'){
                cout << "No" << endl;
                return 0;
            }
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define pp push_back
#define ff first
#define ss second

using namespace std;

ll t,n,m,r,l,h,i,j,x[1000001],y[1000001],z,g,a,b,c,d,dp[1000001],k,q;
vector <ll> v[1000001];
vector <pair <ll,ll> > vv;
queue <pair <ll,ll> > qq;
pair <ll,ll> p[1000001];
map <ll,ll> mp,mpp,mppp,mx,vis;
set <pair<ll,ll>, greater<pair<ll,ll> > > se;
set <ll> :: iterator it;
string s[1000001],sss;
char cc;

int main()
{
    ios::sync_with_stdio(0);
    cin >> n;
    for(i=0;i<n;i++)
        cin >> x[i];
    memset(dp,-1,sizeof(dp));
    dp[0]=0;
    for(i=0;i<n;i++)
    {
        if(i+1<n)
        {
            if(dp[i+1]==-1)
                dp[i+1]=dp[i]+abs(x[i]-x[i+1]);
            else
                dp[i+1]=min(dp[i+1],dp[i]+abs(x[i]-x[i+1]));
        }
        if(i+2<n)
        {
            if(dp[i+2]==-1)
                dp[i+2]=dp[i]+abs(x[i]-x[i+2]);
            else
                dp[i+2]=min(dp[i+2],dp[i]+abs(x[i]-x[i+2]));
        }
    }
    cout << dp[n-1];
    return 0;
}


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

int main() {
  string O, E;
  cin >> O >> E;
  for (int i = 0; i < O.size(); ++i) {
    cout << O.at(i);
    if (i < E.size())
      cout << E.at(i);
  }
  cout << endl;
}


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

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

    string s, t;
    cin >> s >> t;

    map<char, vector<int>> chars;
    for (int i = 0; i < s.size(); i++) {
        chars[s[i]].push_back(i);
    }
    for (int i = 0; i < s.size(); i++) {
        chars[s[i]].push_back(i + s.size());
    }
    int64_t ret = 0;
    for (int i = 0; i < t.size(); i++) {
        if (chars[t[i]].empty()) {
            ret = -1;
            break;
        }
        int p = ret % s.size();
        auto it = lower_bound(chars[t[i]].begin(), chars[t[i]].end(), p);
        ret += *it - p + 1;
    }

    cout << ret << endl;

    return 0;
}


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

const int M = 1000010;

signed main() {
    int N;
    cin >> N;
    vector<int > A(N);
    rep (i ,N) cin >> A[i];

    vector<int> cnt(M);
    for (int x : A) {
        if (cnt[x] != 0) {
            cnt[x] = 2;
            continue;
        }
        for (int i=x; i<M; i += x) cnt[i]++;
    }

    int ans = 0;
    for (int x : A) {
        if (cnt[x] == 1) ans++;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 8020
#include "bits/stdc++.h"
using namespace std;
int main() {
	vector<long long>Lucas(87);
	Lucas.at(0) = 2;
	Lucas.at(1) = 1;
	for (int i = 2; i <= 86; i++) {
		Lucas.at(i) = Lucas.at(i - 1) + Lucas.at(i - 2);
	}
	int N;
	cin >> N;
	cout << Lucas.at(N) << endl;
}

Measured memory_bytes: 256
N = int(input())


def question(i):
    print(i)
    s = input()
    if s == 'Male':
        return 0
    elif s == 'Female':
        return 1
    exit()


a = question(0)
A = ([a, 1 - a] * N)[:N]
lb = -1
rb = N
while True:
    mid = (lb + rb) // 2
    if question(mid) == A[mid]:
        lb = mid
    else:
        rb = mid


Measured memory_bytes: 5960
N = int(input())
a = [int(i) for i in input().split()]
zeros = [0] * N
length = len(a)

for i, ai in zip(a[::-1], range(length, -1, -1)):
    s = 0
    for j in range(ai, length+1, ai):
        s += zeros[j-1]
    if s % 2 == i:
        pass
    else:
        zeros[ai-1] = 1

print(sum(zeros))
for i, v in enumerate(zeros, 1):
    if v:
        print(i, end=" ")


Measured memory_bytes: 8380
import java.util.*;

public class Main {
    static Scanner scanner;

    public static void main(String[] args) {
        scanner = new Scanner(System.in);
        int a = nextInt();
        int b = nextInt();
        int h = nextInt();
        int m = nextInt();
        double hDegree = (h * 60 + m) *360/(12.0*60.0);
        double minDegree = m * (360 / 60.0);
        if (hDegree ==  minDegree) System.out.println(Math.abs(a - b));
        else {
            double hRad = Math.toRadians(hDegree);
            double hX = Math.cos(hRad) * a;
            double hY = Math.sin(hRad) * a;
            double mRad = Math.toRadians(minDegree);
            double minX = Math.cos(mRad) * b;
            double minY = Math.sin(mRad) * b;
            double r = distance(hX,hY,minX,minY);
            System.out.println(r);
        }
    }

    public static int nextInt() {
        return Integer.parseInt(scanner.next());
    }

    public static long nextLong() {
        return Long.parseLong(scanner.next());
    }

    public static double nextDouble() {
        return Double.parseDouble(scanner.next());
    }

    public static short nextShort() {
        return Short.parseShort(scanner.next());
    }

    public static float nextFloat() {
        return Float.parseFloat(scanner.next());
    }

    public static void printYes() {
        System.out.println("Yes");
    }

    public static void printYES() {
        System.out.println("YES");
    }

    public static void printNo() {
        System.out.println("No");
    }

    public static void printNO() {
        System.out.println("NO");
    }

    public static void nextLine() {
        scanner.nextLine();
    }

    public static double distance(double x, double y, double x2, double y2) {
        return Math.sqrt((x2 - x) * (x2 - x) + (y2 - y) * (y2 - y));
    }
}

Measured memory_bytes: 27120
import java.util.Scanner;

public class Main {
  public static void main(String[] args ){
    Scanner scanner = new Scanner(System.in);
    int x = scanner.nextInt();
    int y = scanner.nextInt();
    int z = x*y;
    int w = 2*x + 2*y;
    System.out.printf("%d %d\n",z,w);
  }
}


Measured memory_bytes: 26244
n, k = map(int, input().split())
pList = list(map(int, input().split()))
pKList = [(1 + p)/2 for p in pList]
pListMax = 0

for i in range(n-k+1):
    if i == 0:
        res = sum(pKList[i:i+k])
    else:
        res = res - pKList[i-1] + pKList[i+k-1]
    pListMax = max(pListMax, res)
print(pListMax)


Measured memory_bytes: 25060
#include<iostream>
#include<string>
using namespace std;
int main(){
  int n;
  cin >>n;
  cin.ignore();
  while(n--){
    string s;
    getline(cin,s);
    for(;;){
      string::size_type x = s.find("Hoshino");
      if(x == string::npos){break;}
      s[x+6] = 'a';
    }
    cout <<s<<endl;
  }
  return 0;
}

Measured memory_bytes: 1208
#include <iostream>
#include <vector>

using std::cin;
using std::cout;
using std::endl;
using std::vector;

int min_route(const vector<int>& xs) {
  int longest = 0;
  int sum = 0;
  for (int x : xs) {
    sum += x;
    longest = std::max(longest, x);
  }
  return sum - longest;
}

int main(int argc, char* argv[]) {
  std::vector<int> xs(3);
  cin >> xs[0] >> xs[1] >> xs[2];
  cout << min_route(xs) << endl;
  return 0;
}


Measured memory_bytes: 256
function main(input) {
  let args = input.split('\n');
  let a = 0;
  let flag = false;
  let [x, y] = args[a++].split(' ').map((e) => +e);
  for (let i = 0; i <= x; ++i) {
    if (i * 2 + (x - i) * 4 == y) {
      flag = true;
      break;
    }
  }
  console.log(flag ? 'Yes' : 'No');
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 29612
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int main()
{
    int n,m;
    cin>>n>>m;
    string s[105];
   for(int i=0;i<n;i++)
       cin>>s[i];
       sort(s,s+n);
for(int i=0;i<n;i++)
    cout<<s[i];
    cout<<endl;
return 0;
}


Measured memory_bytes: 256
//omajinai c++ atcoder
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define itn int
typedef long long ll;
constexpr auto mod = 1000000007;
using namespace std;
int main() {

long long int n,k;
  cin>>n>>k;
  long int ans =min(n%k,k-n%k);
  cout<<ans;
}

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

using ll = long long;
using vi = vector<int>;

int func(int x){
	if( x%3 == 2) return x/3+1;
	return x/3;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	string s;
	cin >> s;
	int n = s.size();
	vi v,u;
	int cnt = 1;
	for(int i = 1;i<n;i++){
		if(s[i] != s[i-1]){
			v.push_back(cnt);
			cnt = 1;
		}
		else cnt++;
	}
	v.push_back(cnt);
	int res = 0;
	for(int i = 0;i<v.size();i++){
		res+= func(v[i]);
		if( v[i]%3 == 2) u.push_back(i);
	}
	for(int i=1;i<u.size();i++){
		int fail = 0;
		for(int j=u[i]-1;j>u[i-1];j--){
			if(v[j]%3){
				fail = 1;
				break;
			}
		}
		if( fail ) continue;
		res--;
		i++;
	}
	cout << n - res << endl;
}



Measured memory_bytes: 1680
import math
import sys

n = int(sys.stdin.readline())
a = list(map(int, sys.stdin.readline().rstrip().split()))
flag = "Init"
ans = 0
for i in range(1, n):
    if flag == "Init":
        if a[i - 1] == a[i]:
            pass
        elif a[i - 1] > a[i]:
            flag = "-"
        else:
            flag = "+"
    elif flag == "-":
        if a[i - 1] < a[i]:
            ans += 1
            flag = "Init"
    else:
        if a[i - 1] > a[i]:
            ans += 1
            flag = "Init"
print(ans + 1)

Measured memory_bytes: 15020
/**
*    created: 14.06.2020 20:53:42
**/

#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
const int inf =1000000000;

int vector_finder(std::vector<int> vec, int number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) { // 発見できたとき
    return 1;
  }
  else { // 発見できなかったとき
    return 0;
  }
}

int main() {
    int x,n;
    cin >> x>>n;
    vector<int> p(n);
    rep(i, n) cin >> p[i];
    int ans = inf;
    int annns;
    for (int i = -200; i <= 200; i++)
    {
        if (!vector_finder(p, i))
        {
            if (ans > abs(i - x))
            {
                annns = i;
            }
            ans = min(ans, abs(i - x));
        }
            }
            /*
    sort(p.begin(), p.end());
    int j=0;
    for (int k = j; k < n;k++){
        for (int i = 1; i <= 100;i++){
            if(p[k]!=i){
                ans = min(ans, abs(i - x));
                cout << ans << endl;
                break;
            }
        }
    }*/
    cout << annns << endl;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,t;
  cin>>n>>t;
  int a[n];
  int ans=0;
  for(int i=0;i<n;++i) cin>>a[i];
  for(int i=0;i<n;++i){
    if(i){
      if(a[i]-a[i-1]>t) ans+=t;
      else ans+=a[i]-a[i-1];
    }
  }
  cout<<ans+t<<endl;
  return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<cmath>
#include<iomanip>
using namespace std;

double Third_Root( double x , double q )
{
    if( fabs( x * x * x  - q ) < 0.00001 * q )
        return x;

    return Third_Root( x - ( x * x * x - q ) / ( 3 * x * x ), q );
}

int main()
{
    double x, q;

    while( cin >> q )
    {
        if( q == -1 )
            break;
        x = q / 2;
        cout << fixed << setprecision(6) << Third_Root( x, q ) << endl; 
    }
    return 0;
}


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

#define FLASH ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ll long long int
#define MAX 1e9
#define MIN -1e9
#define mod 1000000007
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define debug(x) cerr<<#x<<'='<<(x)<<endl;
#define mxn 200005
#define f first
#define s second
using namespace std;
vector<ll> v;
int main()
{
    FLASH
    string s;
    ll a,b = 0;
    cin >> a >> s;
    for(auto i : s)
    {
        if(i != '.')
        {
            b = b * 10 + (i - '0');
        }
    }
    cout << (a * b) /100;
    return 0;
}

Measured memory_bytes: 3660
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
// 標準入力からデータを読み込む準備
try (Scanner sc = new Scanner(System.in)) { 
	int w = sc.nextInt();
int n = sc.nextInt();
int[] values = new int[w];
for (int i = 0; i < values.length; i++) { 
	values[i] = i + 1;
}
for (int i = 0; i < n; i++) {
String str = sc.next();
String[] ab = str.split(",");
int a = Integer.parseInt(ab[0]) - 1; 
int b = Integer.parseInt(ab[1]) - 1; 
// aとbを使ってvaluesを操作しよう
 int tmp=values[a];
values[a]=values[b];
values[b]=tmp;
}
for (int j=0;j<values.length;j++){
	System.out.println(values[j]);
}
} }
}


Measured memory_bytes: 26100
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int mod = 1e9 + 7;
const int MAX = 510000;

int main() {
    ll n; cin >> n;
    vl t(n),x(n),y(n);
    rep(i,n){
        cin >> t[i] >> x[i] >> y[i];
    }
    bool flag = true;
    rep(i,n){
        if(i==0){
            ll dis = t[i]-(x[i]+y[i]);
            if(dis<0) {
                flag = false;
                break;
            }else{
                if(dis % 2 != 0){
                    flag = false;
                    break;
                }
            }
        }else{
            ll dis = t[i]-t[i-1]-(abs(x[i]-x[i-1])+abs(y[i]-y[i-1]));
            if(dis<0){
                flag = false;
                break;
            }else{
                if(dis % 2 != 0){
                    flag = false;
                    break;
                }
            }
        }
    }
    if(flag) puts("Yes");
    else puts("No");
}

Measured memory_bytes: 2560
class Dice():
    def __init__(self, labels):
        self.top = labels[0]
        self.front = labels[1]
        self.right = labels[2]
        self.left = labels[3]
        self.back = labels[4]
        self.bottom = labels[5]

    def roll(self, axis, count=1):
        while count < 0:
            count += 4
        if axis == "X":
            for _ in range(count):
                self.top, self.back, self.bottom, self.front = self.front, self.top, self.back, self.bottom
        elif axis == "Y":
            for _ in range(count):
                self.top, self.right, self.bottom, self.left = self.left, self.top, self.right, self.bottom
        elif axis == "Z":
            for _ in range(count):
                self.front, self.left, self.back, self.right = self.right, self.front, self.left, self.back
        elif axis == "N":
            self.roll("X", 1)
        elif axis == "W":
            self.roll("Y", -1)
        elif axis == "S":
            self.roll("X", -1)
        elif axis == "E":
            self.roll("Y", 1)


def solve(d, top, front):
    for _ in range(4):
        if d.top == top and d.front == front:
            return d.right
        d.roll("Z")
    d.roll("X")
    for _ in range(4):
        if d.top == top and d.front == front:
            return d.right
        d.roll("Y")
    d.roll("X")
    for _ in range(4):
        if d.top == top and d.front == front:
            return d.right
        d.roll("Z")
    d.roll("X")
    for _ in range(4):
        if d.top == top and d.front == front:
            return d.right
        d.roll("Y")
    d.roll("X")
    d.roll("Y")
    for _ in range(4):
        if d.top == top and d.front == front:
            return d.right
        d.roll("X")
    d.roll("Y", 2)
    for _ in range(4):
        if d.top == top and d.front == front:
            return d.right
        d.roll("X")


labels = [int(c) for c in input().split()]
d = Dice(labels)
q = int(input())
for _ in range(q):
    top, front = map(int, input().split())
    print(solve(d, top, front))



Measured memory_bytes: 5620
import java.util.Scanner;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);

    int N = sc.nextInt();
    int K = sc.nextInt();
    
    int sunu[] = new int[N];
    for(int i=0;i<K;i++){
      int d =  sc.nextInt();
      // System.out.println(i+"iii"); 
      for(int j=0; j<d; j++){
        // System.out.println(j+"ssd");  
        sunu[sc.nextInt()-1]++;
        // System.out.println(j+"aaa"); 
      }
    }
    int count = 0;
    for(int i=0;i<N;i++){
      if(sunu[i]==0){
        count++;
      }
    }
    System.out.println(count);  
  }
}





Measured memory_bytes: 46296
import sys
sys.setrecursionlimit(10**7) #再帰関数の上限,10**5以上の場合python
import math
from copy import copy, deepcopy
from copy import deepcopy as dcp
from operator import itemgetter
from bisect import bisect_left, bisect, bisect_right#2分探索
#bisect_left(l,x), bisect(l,x)#aはソート済みである必要あり。aの中からx未満の要素数を返す。rightだと以下
from collections import deque
#deque(l), pop(), append(x), popleft(), appendleft(x)
#q.rotate(n)で → にn回ローテート
from collections import Counter#文字列を個数カウント辞書に、
#S=Counter(l),S.most_common(x),S.keys(),S.values(),S.items()
from itertools import accumulate,combinations,permutations#累積和
#list(accumulate(l))
from heapq import heapify,heappop,heappush
#heapify(q),heappush(q,a),heappop(q) #q=heapify(q)としないこと、返り値はNone
#import fractions#古いatcoderコンテストの場合GCDなどはここからimportする
from functools import lru_cache#pypyでもうごく
#@lru_cache(maxsize = None)#maxsizeは保存するデータ数の最大値、2**nが最も高効率
from decimal import Decimal

def input(): 
    x=sys.stdin.readline()
    return x[:-1] if x[-1]=="\n" else x
def printl(li): _=print(*li, sep="\n") if li else None
def argsort(s, return_sorted=False): 
    inds=sorted(range(len(s)), key=lambda k: s[k])
    if return_sorted: return inds, [s[i] for i in inds]
    return inds
def alp2num(c,cap=False): return ord(c)-97 if not cap else ord(c)-65
def num2alp(i,cap=False): return chr(i+97) if not cap else chr(i+65)
def matmat(A,B):
    K,N,M=len(B),len(A),len(B[0])
    return [[sum([(A[i][k]*B[k][j]) for k in range(K)]) for j in range(M)] for i in range(N)]
def matvec(M,v):
    N,size=len(v),len(M)
    return [sum([M[i][j]*v[j] for j in range(N)]) for i in range(size)]
def T(M):
    n,m=len(M),len(M[0])
    return [[M[j][i] for j in range(n)] for i in range(m)]
def main():
    mod = 1000000007
    #w.sort(key=itemgetter(1),reversed=True)  #二個目の要素で降順並び替え

    #N = int(input())
    #N, K = map(int, input().split())
    #A = tuple(map(int, input().split())) #1行ベクトル
    #L = tuple(int(input()) for i in range(N)) #改行ベクトル
    #S = tuple(tuple(map(int, input().split())) for i in range(N)) #改行行列

    s=input()
    t=input()
    cnt=0
    for si,ti in zip(s,t):
        if si!=ti:cnt+=1

    print(cnt)

if __name__ == "__main__":
    main()

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

int main(){
  string s;
  cin >> s;
  for(int i=0; i<s.length(); i++){
    char c = (s[i]-'A'+23)%26 + 'A';
    cout << c;
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 1176
import sys
def grid(p, level):
    c = 3 ** level
    return ((p[0] % (3 * c)) // c, (p[1] % (3 * c)) // c)

def sub(p1, p2, level):
    # print('sub',(p1, p2, level))
    if level < 0:
        return abs(p1[0] - p2[0]) + abs(p1[1] - p2[1])
    g1, g2 = grid(p1, level), grid(p2, level)
    assert 0 <= g1[0] < 3
    assert 0 <= g1[1] < 3
    assert 0 <= g2[0] < 3
    assert 0 <= g2[1] < 3
    if g1[0] != g2[0]:
        return abs(p1[0] - p2[0]) + abs(p1[1] - p2[1])
    if g1[0] == 1:
        c = 3 ** level
        y1, y2 = p1[1] // c, p2[1] //c
        if abs(y1 - y2) < 2:
            return sub(p1, p2, level - 1)
        i1, i2 = p1[0] % c, p2[0] % c
        xp = min(i1 + i2 + 2, 2 * c - i1 - i2)
        return xp + abs(p1[1] - p2[1])
    return sub(p1, p2, level - 1)

def solve(p1, p2, level):
    g1, g2 = grid(p1, level), grid(p2, level)
    if g1 == g2:
        if level == 0:
           return 0 
        return solve(p1, p2, level - 1)
    if g1[0] == g2[0]:
        return sub(p1, p2, level)
    elif g1[1] == g2[1]:
        return sub((p1[1], p1[0]), (p2[1], p2[0]), level)
    else:
        return abs(p1[0] - p2[0]) + abs(p1[1] - p2[1])

q = int(input())
for i in range(q):
    a, b, c, d = [int(x) - 1 for x in input().split()]
    print(solve((a, b), (c, d), 30))


Measured memory_bytes: 3316
#include<bits/stdc++.h>
#define maxn 5010
#define ll long long
using namespace std;
int a[maxn], pre[maxn][maxn];
ll f[maxn];
int main()
{
	int n, A, B;
	scanf("%d%d%d", &n, &A, &B);
	for (int i = 1; i <= n; i++)
		scanf("%d", &a[i]);
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= n; j++)
			if (j >= a[i]) pre[i][j] = pre[i - 1][j] + 1;
			else pre[i][j] = pre[i - 1][j];
	f[0] = 0;
	for (int i = 1; i <= n; i++)
	{
		f[i] = 1e18;
		for (int j = 0; j <= i - 1; j++)
		{
			if (a[j] >= a[i]) continue;
			int t1, t2;
			if (j == 0) t1 = 0;
			else t1 = pre[i - 1][a[j] - 1] - pre[j][a[j] - 1];
			t2 = (i - j - 1) - t1;
			f[i] = min(f[i], f[j] + (ll)t1 * B + (ll)t2 * A);
		}
	}
	ll res = 1e18;
	for (int i = 0; i <= n; i++)
	{
		int t1, t2;
		if (i == 0) t1 = 0;
		else t1 = pre[n][a[i] - 1] - pre[i][a[i] - 1];
		t2 = (n - i) - t1;
		res = min(res, f[i] + (ll)t1 * B + (ll)t2 * A);
	}
	printf("%lld\n", res);
	return 0;
}

Measured memory_bytes: 98304
#include <iostream> // cin, cout, cerr, clog
#include <algorithm> // minmax, sort, swap
#include <numeric> // iota, gcd, lcm 
#include <cstdio> // printf, scanf
#include <climits> // INT_MIN, LLONG_MIN
#include <cmath> // long, trig, pow
#include <vector> // vectors
#include <string> // string
#include <queue> // queue
#include <stack> // stack
#include <map> // key-value pairs sorted by keys
#include <unordered_map> // hashed by keys
#include <iomanip> //cout<<setprecision(n)
#define rep(i,n) for(int i = 0; i < n; i++)

typedef long long ll; // at least int64 > 9*10^18
typedef unsigned long long ull; // at least uint64

template <typename T>
std::vector<size_t> sort_indexes(const std::vector<T> &v) {
  std::vector<size_t> idx(v.size());
  std::iota(idx.begin(), idx.end(), 0);
  std::sort(idx.begin(), idx.end(), [&v](size_t i1, size_t i2) {return v[i1] < v[i2];});
  return idx;
}

int main() {
  int n;
  std::cin >> n;
  std::vector<std::pair<std::string,int> > list;
  list.reserve(n);
  std::string s;
  int p;
  rep(i,n) {
    std::cin >> s >> p;
    list.emplace_back(s,-p);
  }
  std::vector<size_t> idx = sort_indexes(list);
  rep(i,n) {
    std::cout << idx[i]+1 << std::endl;
  }
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
public static void main(String[]srgs) {
	Scanner scan=new Scanner(System.in);
	int a=scan.nextInt();
	String A[]=new String[a];
	int ans=0;
	for(int i=0;i<a;i++) {
		A[i]=scan.next();
	}
	int b=scan.nextInt();
	String B[]=new String[b];
	for(int i=0;i<b;i++) {
		B[i]=scan.next();
	}
	for(int i=0;i<a;i++) {
		String str=A[i];
		int count=0;
		for(int j=0;j<a;j++) {
			if(str.equals(A[j])) {
				count++;
			}
		}
		for(int j=0;j<b;j++) {
			if(str.equals(B[j])) {
				count--;
			}
		}
		if(count>ans) {
			ans=count;
		}
	}
	System.out.println(ans);
	scan.close();
}
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
typedef long long i64;
const int N = 1e5+5;
int n, q, flg, cnt, c[N], a[N], b[N], fa[N]; i64 m;
int fd(int x) { return x == fa[x]?x:fa[x] = fd(fa[x]); }
int main()
{
    scanf("%d%lld%d", &n, &m, &q), cnt = n;
    for(int i = 1; i <= n; ++i) fa[i] = i;
    for(int i = 1; i <= q; ++i) scanf("%d%d%d", a+i, b+i, c+i), ++a[i], ++b[i], flg |= c[i];
    for(int i = 1; i <= q; ++i) if(!c[i]&&fd(a[i]) != fd(b[i])) fa[fd(a[i])] = fd(b[i]), --cnt;
    if(m < n-1) return puts("No"), 0;
    if(m == n-1) return puts(!flg?"Yes":"No"), 0;
    for(int i = 1; i <= q; ++i) if(c[i]&&fd(a[i]) == fd(b[i])) return puts("No"), 0;
    puts(m <= n-cnt+(cnt-1ll)*cnt/2?"Yes":"No");
    return 0;
}

Measured memory_bytes: 5308
c = [tuple(map(int, input().split( ))) for _ in range(3)]

for i in range(2):
    for j in range(2):
        if c[i][j] -c[i+1][j]!=c[i][j+1] -c[i+1][j+1]:
            print("No")
            exit()
print("Yes")

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define loop(i,a,b) for(int i=a;i<b;i++)
#define test() int t;cin>>t;loop(test,1,t+1)
#define pb push_back
#define eb emplace_back
#define mkp make_pair
#define nl cout<<"\n"
#define sp cout<<" "
#define F first
#define S second
#define vi vector<int>
#define vl vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<pii>
#define vll vector<pll>
#define MOD 1000000007
#define all(x) x.begin(),x.end()

template<class C> void min_self( C &a, C b ){ a = min(a,b); }
template<class C> void max_self( C &a, C b ){ a = max(a,b); }

ll mod( ll n, ll m=MOD ){ n%=m,n+=m,n%=m;return n; }

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }
    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

unordered_map<long long, int, custom_hash> safe_map;

const int MAXN = 1e5+5;
const int LOGN = 21;
const ll INF = 1e14;
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};

int main() 
{
    fastio();

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

    puts( a+b+c>=22 ? "bust" : "win" );

    return 0;
}

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

#define pb push_back
#define mp make_pair
#define fs first
#define se second
#define pi 2*acos(0)
#define PI 3.14159265358979323846264338

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

const int N = 100010;
const int MX = 123456;
const int mod = (int)1e9 + 7;
const int base = 1023456789;
const ull BS1 = 10000019ULL;
const int INF = (1 << 29);

template < class T > inline void fastScan(T &x){
    register char c = getchar();
    int neg = 0; x = 0;
    for(   ; (c < 48 || c > 57) && (c != '-'); c = getchar());
    if(c == '-') { neg = 1; c = getchar(); }
    for(   ; c > 47 && c < 58; c = getchar()){
        x = (x << 1) + (x << 3) + c - 48;
    }
    if(neg) x = -x;
}

int n;
int taken[55];

ll ans;

char str[55];

map < pair < string , string > , int > RED, BLUE, mymap;

void secondHalf(int pos){
    if(pos >= n + n){
        string red = "", blue = "";
        for(int i = n; i < n + n; i++) if(taken[i] == 1) red += str[i];
        for(int i = n + n - 1; i >= n; i--) if(taken[i] == 0) blue += str[i];
        mymap[mp(blue, red)]++;
        return ;
    }
    taken[pos] = 1;
    secondHalf(pos + 1);
    taken[pos] = 0;
    secondHalf(pos + 1);
}

void firstHalf(int pos){
    if(pos >= n){
        string red = "", blue = "";
        for(int i = 0; i < n; i++) if(taken[i] == 1) red += str[i];
        for(int i = n - 1; i >= 0; i--) if(taken[i] == 0) blue += str[i];
        ans += mymap[mp(red , blue)];
        return ;
    }
    taken[pos] = 1;
    firstHalf(pos + 1);
    taken[pos] = 0;
    firstHalf(pos + 1);
}

int main(){
    fastScan(n);
    scanf("%s", str);
    secondHalf(n);
    firstHalf(0);
    printf("%lld\n", ans);
}


Measured memory_bytes: 91904