akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
public class Main{
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    long N = sc.nextLong();
    Long A = sc.nextLong();
    long B = sc.nextLong();
    long x = N/(A+B);
    long y = N%(A+B);
    if(y==0){
      System.out.println(x*A);
    }else{
      if(A>=y){
        System.out.println((x*A)+y);
      }else{
        System.out.println((x*A)+A);
      }
    }

  }
}


Measured memory_bytes: 23252
#include <bits/stdc++.h>
using namespace std;
const long long mod=1e9+7;
long long po[60];
int main(){
	long long n,k;
	long long aa[1000];
	cin>>n>>k;
	vector<long long> v;
	for(int i=0;i<n;i++){
		cin>>aa[i];
		v.push_back(aa[i]);
	}
	for(int i=1;i<n;i++){
		aa[i]+=aa[i-1];
	}
	for(int i=0;i<n;i++){
		for(int j=i+1;j<n;j++){
			if(i==0){
				v.push_back(aa[j]);
			}else{
				v.push_back(aa[j]-aa[i-1]);
			}
		}
	}
//	sort(v.begin(),v.end());
	int cnt[60];
	memset(cnt,0,sizeof(cnt));
	vector<long long> a[60];
	for(int i=0;i<v.size();i++){
		bitset<60> bit=v[i];
		for(int j=0;j<60;j++){
			if(bit[j]){
				cnt[j]++;
				a[j].push_back(v[i]);
			}
		}
	}
	long long re=1;
	for(int i=0;i<60;i++){
		po[i]=re;
		re*=2;
	}
//	for(int i=0;i<60;i++){
//		cout<<cnt[i]<<" ";
//	}
//	cout<<endl;
	for(int i=59;i>=0;i--){
		if(cnt[i]>=k){
			long long ans=po[i];
			int now=i-1;
			while(now>=0){
//				cout<<now<<" ";
//				cout<<ans<<endl;
		//		cout<<now<<endl;
				vector<long long> b[60];
				memset(cnt,0,sizeof(cnt));
				for(int i=0;i<a[now+1].size();i++){
					bitset<60> bit=a[now+1][i];
					for(int j=0;j<=now;j++){
						if(bit[j]){
							cnt[j]++;
							b[j].push_back(a[now+1][i]);
						}
					}
				}
//				for(int j=0;j<60;j++){
//					cout<<cnt[j]<<" ";
//				}
//				cout<<endl;
				bool f=true;
				for(int j=now;j>=0;j--){
					if(cnt[j]>=k){
						ans+=po[j];
						now=j-1;
						f=false;
						a[now+1]=b[now+1];
						break;
					}
				}
				if(f){
					break;
				}
			}
			cout<<ans<<endl;
			return 0;
		}
	}
	cout<<0<<endl;
	return 0;
}

Measured memory_bytes: 102508
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<cctype>
#include<climits>
#include<string>
#include<bitset>
#include<cfloat>
#include<iomanip>
#include<numeric>

//#define int long long
#define repi(i,start,end) for(int (i)=(start),TemPNuM=(int)(end);(i)<TemPNuM;++(i))
#define rep(i,end) repi((i),0,(end))
#define rfor(x,v) for(auto& (x) : (v))
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define fsort(v,lambda) sort(all((v)),(lambda))
#define vin(v) rep(i,(v).size())cin >> (v)[i];
#define vpin(v) rep(i,(v).size())cin>>v[i].first>>v[i].second

using namespace std;
using ll =  long long;
using pint =  pair<int,int>;
using vint = vector<int>;
using vvint = vector<vint>;
using vpint = vector<pint>;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<class T>void put_double(T a){if(cout.precision()!=12)cout<<setprecision(12);cout<<a<<endl;}
template<class T>void print(T a){cout << a << endl;}
//lambda: [](int x, int y){return x<y;}

signed main(void) {
    int n; cin >> n;
    vector<vpint> xy;
    rep(i, n) {
        int a; cin >> a;
        vpint t(a); vpin(t);
        xy.push_back(t);
    }
    int ans = 0;
    rep(bits, 1 << n) {
        vector<int> s(n, 0);
        rep(i, n) if(bits & (1 << i)) s[i] = 1;
        //rfor(x, s) cout << x << " ";
        //print("");
        bool flag = true;
        rep(i, n) {
            if(s[i] == 0) continue;
            rfor(p, xy[i]) {
                if(s[p.first - 1] != p.second) flag=false;
            }
        }
        if(flag) {
            //print(accumulate(all(s), 0));
            chmax(ans, accumulate(all(s), 0));
        }

    }
    print(ans);

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long a,b,k;
int main()
{
	cin>>a>>b>>k;
	if(k<a)
	{
		cout<<a-k<<" "<<b;
		return 0;
	}
	k=k-a;a=0;
	if(k>b)
	{
		cout<<a<<" "<<'0';
		return 0;
	}
	cout<<a<<" "<<b-k;
	return 0;
}

Measured memory_bytes: 256
import sys

read = sys.stdin.buffer.read
input = sys.stdin.buffer.readline
inputs = sys.stdin.buffer.readlines


# rstrip().decode('utf-8')
# INF=float("inf")
# MOD=10**9+7
# sys.setrecursionlimit(2147483647)
# import math
import numpy as np
# import operator
# import bisect
# from heapq import heapify,heappop,heappush
# from math import gcd
# from fractions import gcd
# from collections import deque
# from collections import defaultdict
# from collections import Counter
# from itertools import accumulate
# from itertools import groupby
# from itertools import permutations
# from itertools import combinations
# from scipy.sparse import csr_matrix
# from scipy.sparse.csgraph import floyd_warshall
# from scipy.sparse.csgraph import csgraph_from_dense
# from scipy.sparse.csgraph import dijkstra
# map(int,input().split())


def main():
	N, T = map(int, input().split())
	AB = [list(map(int, input().split())) for _ in range(N)]
	AB = sorted(AB)
	
	dp = np.zeros(T, np.int64)
	ans = 0
	for a, b in AB:
		ans = max(ans, dp.max() + b)
		np.maximum(dp[a:], dp[:-a] + b, out=dp[a:])
	print(ans)



if __name__ == '__main__':
	main()


Measured memory_bytes: 14448
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
#define rep(i,n) for (ll i=0;i<n;++i)
#define rep2(i,a,b) for (ll i=a;i<b;++i)
const ll MOD=1e9+7;
const ll INF=1e9;
const ll IINF=1e18;
const double EPS=1e-8;
const double pi=acos(-1);

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;
}

int main(){
    ll n,m;
    cin >> n >> m;
    vector<ll> a(n);
    rep(i,n) cin >> a[i],--a[i];
    vector<vector<ll>> dat(m,vector<ll>(2,0));
    rep2(i,1,n){
        if (a[i]==m-1) continue;
        ++dat[a[i]+1][0];
        ll x=a[i]-a[i-1];
        if (a[i-1]>a[i]) x+=m;
        dat[a[i]+1][1]+=x;
    }
    vector<ll> covered(m,0);
    rep2(i,1,n){
        if (a[i]-a[i-1]==1||(a[i]==m-1&&a[i]==0)) continue;
        if (a[i-1]<a[i]){
            ++covered[a[i-1]+2];
            if (a[i]<m-1) --covered[a[i]+1];
        }
        else {
            ++covered[0],--covered[a[i]+1];
            if (a[i-1]<m-2) ++covered[a[i-1]+2];
        }
    }
    rep(i,m-1) covered[i+1]+=covered[i];
    ll cnt=0;
    rep2(i,1,n){
        if (a[i-1]<=a[i]) cnt+=a[i]-a[i-1];
        else cnt+=a[i]+1;
    }
    ll ans=cnt;
    rep2(i,1,m){
        cnt-=covered[i];
        cnt+=dat[i][1]-dat[i][0];
        chmin(ans,cnt);
    }
    cout << ans << endl;
}

Measured memory_bytes: 7296
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int MAXN=300005,MOD=1000000007;

char S[MAXN];
long long dp[MAXN][6],ans;

int main()
{
	scanf("%s",S+1);
	int n=strlen(S+1);
	if(n==1)
	{
		printf("%d\n",S[1]!='0');
		return 0;
	}
	dp[1][0]=1;
	for(int i=1;i<=n;i++)
	{
		if(S[i]=='?')
			(ans*=2)%=MOD;
		for(int j=0;j<6;j++)
		{
			if(dp[i][j]==0)
				continue;
			if(S[i]!='1')//0
			{
				if(j==0)(dp[i+1][2]+=dp[i][j])%=MOD;
				if(j==1)(dp[i+1][4]+=dp[i][j])%=MOD;
				if(j==2)(dp[i+1][3]+=dp[i][j])%=MOD;
				if(j==3)(dp[i+1][2]+=dp[i][j])%=MOD;
				if(j==4)(dp[i+1][5]+=dp[i][j])%=MOD;
				if(j==5)(dp[i+1][4]+=dp[i][j])%=MOD;
			}
			if(S[i]!='0')//1
			{
				if(j==0)(dp[i+1][1]+=dp[i][j])%=MOD;
				if(j==1)(ans+=dp[i][j])%=MOD;
				if(j==2)(dp[i+1][0]+=dp[i][j])%=MOD;
				if(j==3)(dp[i+1][2]+=dp[i][j])%=MOD;
				if(j==4)(dp[i+1][1]+=dp[i][j])%=MOD;
				if(j==5)(dp[i+1][4]+=dp[i][j])%=MOD;
			}
			dp[i][j]%=MOD;
			//printf("dp[%d][%d]=%I64d\n",i,j,dp[i][j]);
		}
	}
	(ans+=dp[n+1][1])%=MOD;
	printf("%lld\n",ans);
	
	return 0;
}


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

int main()
{
	//freopen("main.inp", "r", stdin);
	//freopen("main.out", "w", stdout);
	int n, m; cin >> n >> m;	
	cout << (m * (m - 1) + n * (n - 1)) / 2;
	return 0;
}

Measured memory_bytes: 256
N = int(input())
A = [int(a) for a in input().split()]
ans = 0
for i in range(N):
    for j in range(i):
        for k in range(j):
            if abs(A[i] - A[j]) < A[k] < A[i] + A[j] and A[i] != A[j] and A[j] != A[k] and A[k] != A[i]:
                ans += 1
print(ans)

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

#define rep(i,n) for(int i=0 ; i<(n) ; i++)
#define repr(i,n) for(int i=(n) ; i>=0 ; i--)
#define FOR(i,m,n) for(int i=(m) ; i<(n) ; i++)
#define FORR(i,m,n) for(int i=(m) ; i>=(n) ; i--)

#define All(x) (x).begin(),(x).end()

typedef long long ll;
typedef unsigned long long ull;

const int INF = 1e9;

int main(){
   int a,b;
   cin >> a >> b;
   int ans = 0;
   for(int i=a;i<=b;i++){
      string tmp = to_string(i);
      string tmpR = tmp;
      reverse(tmpR.begin(),tmpR.end());
      if(tmp == tmpR){
         ans++;
      }
   }
   cout << ans << endl;
   return 0;
}


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

using namespace std;
typedef long long ll;
bool cmp(int x,int y){return x>y;}
int main()
{
    int n,k;
    int a[200100];
   scanf("%d%d",&n,&k);
   for(int i=1;i<=n;i++){
    scanf("%d",&a[i]);
   }
   int kk=1;
   double sum=0;
   for(int i=1;i<=k;i++) sum+=a[i];
   int sum1=sum;
   for(int i=1,j=k;j<n;i++,j++)
        {
            sum1-=a[i];
            sum1+=a[j+1];
            if(sum1>sum) kk=i,sum=sum1;
        }
   //cout<<sum<<endl;
   sum+=k;
   printf("%.6f",sum/2);
    return 0;
}


Measured memory_bytes: 1024
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using datas=pair<ll,ll>;
using ddatas=pair<double,double>;
using tdata=pair<ll,datas>;
using vec=vector<ll>;
using mat=vector<vec>;
using pvec=vector<datas>;
using pmat=vector<pvec>;
#define For(i,a,b) for(i=a;i<b;i++)
#define bFor(i,a,b) for(i=a;i>=b;i--)
#define rep(i,N) For(i,0,N)
#define rep1(i,N) For(i,1,N)
#define brep(i,N) bFor(i,N-1,0)
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define vsort(v) sort(all(v))
#define vrsort(v) sort(allr(v))
#define endl "\n"
#define output(v) do{bool f=0;for(auto i:v){cout<<(f?" ":"")<<i;f=1;}cout<<endl;}while(0)
const ll mod=1000000007;
const ll inf=1LL<<60;

long mmid(long a,long b,long c){return a<b?(b<c?b:max(a,c)):(b>c?b:min(a,c));}

ll modinv(ll a) {
  ll b=mod,u=1,v=0,t;
  while(b){
    t=a/b;
    a-=t*b; swap(a,b);
    u-=t*v; swap(u,v);
  }
  return (u+mod)%mod;
}

ll moddevide(ll a,ll b){return (a*modinv(b))%mod;}

ll modncr(ll n,ll r){
  ll i,plus=1;
  rep(i,r){
    plus=(plus*(n-i))%mod;
    plus=moddevide(plus,i+1);
  }
  return plus;
}

ll euclidean_gcd(ll a, ll b) {
  if(a<b) return euclidean_gcd(b, a);
  ll r;
  while ((r=a%b)){a=b;b=r;}
  return b;
}

void printmap(vector<ll>& a,ll H,ll W){
  ll i,j;
  For(i,0,H+2){
    For(j,0,W+2){cout<<a[i*(W+2)+j];}
    cout<<endl;
  }
}
void inputmap(vector<ll>& a,ll H,ll W){
  ll i,j;
  string ss;
  For(i,1,H+1){
    cin>>ss;
    For(j,1,W+1){
      if(ss[j-1]=='#'){
        a[i*(W+2)+j]=1;
      }else{
        a[i*(W+2)+j]=0;
      }
    }
  }
}

int main(){
  ll i=0,j,N,M,sum=0;
  cin>>N>>M;
  pvec a(N+1);
  rep1(i,N+1){
    cin>>a[i].first>>a[i].second;
    sum+=a[i].second;
  }
  mat dp(N+1,vec(sum+1,inf));
  dp[0][0]=0;
  rep1(i,N+1){
    rep(j,a[i].second)dp[i][j]=dp[i-1][j];
    For(j,a[i].second,sum+1){
      dp[i][j]=min(dp[i-1][j],dp[i-1][j-a[i].second]+a[i].first);
    }
  }
  brep(j,sum+1){
    if(dp[N][j]<=M){
      cout<<j<<endl;
      return 0;
    }
  }
}

Measured memory_bytes: 80256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i,n) for (int i = 0; i < (n); ++i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll INF=1LL<<60;
const int inf=(1<<30)-1;
const int mod=1e9+7;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,k;cin >> n >> k;
    vector<int> a(n),b(n);
    rep(i,n){
        cin >> a[i] >> b[i];
    }
    vector<int> p;
    int v=0;
    for(int i=30;i>0;i--){
        if(k&(1<<i)){
            v+=1<<i;
        }
        if(v+(1<<(i-1))-1<=k){
            p.push_back(v+(1<<(i-1))-1);
        }
    }
    p.push_back(k);
    ll ans=0;
    for(int x:p){
        ll res=0;
        rep(i,n){
            if((x|a[i])==x){
                res+=b[i];
            }
        }
        chmax(ans,res);
    }
    cout << ans << endl;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define IOS ios_base::sync_with_stdio(false); cin.tie(0);
#define pb push_back
#define pf push_front
#define PI acos(-1)
#define EPS 1e-5
#define sz(v) ((int)(v).size())
#define all(v) v.begin(),v.end()
#define forn(i, n) for(ll i=0;i<(ll)n;i++)
#define fi first
#define se second
 

int main() {
	int a, b;
	cin >> a >> b;
	if(a == b) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}



Measured memory_bytes: 3636
#include<stdio.h>
int main()
{
    int W,H,x,y,r;
    scanf("%d%d%d%d%d",&W,&H,&x,&y,&r);
    if((x+r)<=W && (x-r)>=0 && (y+r)<=H && (y-r)>=0)
    {
        printf("Yes\n");
    }
    else printf("No\n");



    return 0;
}


Measured memory_bytes: 2112
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i = a; i < (b); ++i)
#define rrep(i,a,b) for(int i = b; i --> (a);)
#define all(v) v.begin(),v.end()
#define trav(x,v) for(auto &x : v)
#define sz(v) (int)(v).size()
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	
	string s;
	cin >> s;
	cout << (s.substr(0,4)=="YAKI" ? "Yes" : "No") << endl;
}

Measured memory_bytes: 764
/*mjytxdy!*/
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fir first
#define sec second
#define all(x) x.begin(),x.end()
#define size(x) ((int)x.size())
#define pii pair<int,int>
#define pil pair<int,ll>
#define pli pair<ll,int>
#define pll pair<ll,ll>
#define inl inline
#define rep(i,l,r) for(int i=(l);i<=(r);i++)
#define per(i,r,l) for(int i=(r);i>=(l);i--)
#define travel(i,u) for(int i=head[u];i;i=e[i].next)
#define lb(x) ((x)&(-(x)))
#define lson root<<1
#define rson root<<1|1
#define Mid (l+r>>1)
#define debug(x) cout<<#x":"<<x<<'\n'
#define myput puts("QaQ")
#define file(x) freopen(#x".in","r",stdin),freopen(#x".out","w",stdout);
typedef long long ll;
char s[110];int n,ans;
inl char read(){
	static const int IO_LEN=1024*1024;
	static char buf[IO_LEN],*ioh,*iot;
	if(ioh==iot){
		iot=(ioh=buf)+fread(buf,1,IO_LEN,stdin);
		if(ioh==iot) return -1;
	}
	return *ioh++;
}
template<class T>inl void read(T &x){
	static int iosig;static char ioc;
	for(iosig=0,ioc=read();!isdigit(ioc);ioc=read()) if(ioc=='-') iosig=1;
	for(x=0;isdigit(ioc);ioc=read())x=(x<<1)+(x<<3)+(ioc^'0');
	if(iosig) x=-x;
}
int main(){
	//freopen("in.txt","r",stdin);
	scanf("%s",s+1);n=strlen(s+1);
	rep(i,1,n/2) if(s[i]!=s[n-i+1]) ans++;
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    char c;
    cin >> c;
    
    if(c == 'a' ||c == 'e'||c == 'i'||c =='o'||c == 'u'){
        cout << "vowel" << endl;
    }
    else{
        cout << "consonant" << endl;
    }
}

Measured memory_bytes: 256
#include <numeric>
#include <iostream>

using namespace std;


int search_max(int a[], int size){
    int max=a[0];
    for(int i=0; i<size; i++){
        if(max < a[i]){
            max = a[i];
        }
    }

    return max;
}

int search_min(int a[], int size){
    int min=a[0];
    for(int i=0; i<size; i++){
        if(a[i] < min){
            min = a[i];
        }
    }

    return min;
}
    
int main(){
    
    int n;
    int a[10000];

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

    cout << search_min(a, n) << " " << search_max(a, n) << " " << accumulate(a, a+n, 0LL) << endl;


    return 0;
}




Measured memory_bytes: 3124
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
#define F  first
#define S  second
#define ff(i,n) for(i=0;i<n;i++)
ll bg = 10000020930000;
int main()
{ 
	ll t;
	t=1;
	while(t--)
	{
		ll i,j,n,q;
		ll a[5];
		ff(i,5)
		   cin>>a[i];
		ff(i,5)
		{
			if(a[i]==0)
			   cout<<(i+1);
		}
	}
	return 0;
}

Measured memory_bytes: 3584
# include <bits/stdc++.h>
# define INF 1e9
using namespace std;

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

int main(){

  int H, W, A, B;
  cin >> H >> W >> A >> B;

  for(int i=0;i<H;i++){
    string s = "";
    for(int j=0; j<W; j++){
      if(i<B){
        if(j < A) s += '0';
        else s += '1';
      } else {
        if(j < A) s += '1';
        else s += '0';
      }
    }
    cout << s << endl;
  }

}

Measured memory_bytes: 1280
macro_rules ! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; input_inner ! { iter , $ ( $ r ) * } } ; ( iter = $ iter : ident , $ ( $ r : tt ) * ) => { let s = { use std :: io :: Read ; let mut s = String :: new ( ) ; std :: io :: stdin ( ) . read_to_string ( & mut s ) . unwrap ( ) ; s } ; let mut $ iter = s . split_whitespace ( ) ; input_inner ! { $ iter , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let s = { use std :: io :: Read ; let mut s = String :: new ( ) ; std :: io :: stdin ( ) . read_to_string ( & mut s ) . unwrap ( ) ; s } ; let mut iter = s . split_whitespace ( ) ; input_inner ! { iter , $ ( $ r ) * } } ; }
macro_rules ! input_inner { ( $ iter : expr ) => { } ; ( $ iter : expr , ) => { } ; ( $ iter : expr , mut $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let mut $ var = read_value ! ( $ iter , $ t ) ; input_inner ! { $ iter $ ( $ r ) * } } ; ( $ iter : expr , mut $ var : ident $ ( $ r : tt ) * ) => { input_inner ! { $ iter , mut $ var : usize $ ( $ r ) * } } ; ( $ iter : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ iter , $ t ) ; input_inner ! { $ iter $ ( $ r ) * } } ; ( $ iter : expr , $ var : ident $ ( $ r : tt ) * ) => { input_inner ! { $ iter , $ var : usize $ ( $ r ) * } } ; }
macro_rules ! read_value { ( $ iter : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ iter , $ t ) ) ,* ) } ; ( $ iter : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ iter , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ iter : expr , { chars : $ base : expr } ) => { read_value ! ( $ iter , String ) . chars ( ) . map ( | c | ( c as u8 - $ base as u8 ) as usize ) . collect ::< Vec < usize >> ( ) } ; ( $ iter : expr , { char : $ base : expr } ) => { read_value ! ( $ iter , { chars : $ base } ) [ 0 ] } ; ( $ iter : expr , chars ) => { read_value ! ( $ iter , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ iter : expr , char ) => { read_value ! ( $ iter , chars ) [ 0 ] } ; ( $ iter : expr , usize1 ) => { read_value ! ( $ iter , usize ) - 1 } ; ( $ iter : expr , $ t : ty ) => { $ iter . next ( ) . unwrap ( ) . parse ::<$ t > ( ) . unwrap ( ) } ; }
use std::cmp::max;
fn main() {
    input! { n, k, ab: [(usize, usize); n] };
    const D: usize = 30;
    let mut ok = vec![true; n];
    let mut ans = 0;
    for i in (0..D).rev() {
        if k & 1 << i != 0 {
            ans = max(
                ans,
                (0..n)
                    .map(|j| ab[j].1 * (ok[j] && ab[j].0 & 1 << i == 0) as usize)
                    .sum(),
            );
        } else {
            for j in 0..n {
                ok[j] &= ab[j].0 & 1 << i == 0;
            }
        }
    }
    ans = max(ans, (0..n).map(|j| ab[j].1 * ok[j] as usize).sum());
    println!("{}", ans);
}


Measured memory_bytes: 8444
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <regex>
#include <numeric>
using namespace std;


/*--- Macro ---*/
#define rep(i, n) for(int i=0; i<(int)n; i++)
#define rep1(i, n) for(int i=1; i<(int)n; i++)
#define mp make_pair
#define pb push_back


/*---  Type ---*/
typedef long long ll;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;


/*--- Constants ---*/
template <typename T> const T INF = numeric_limits<T>::max() / 10;
const int MOD = (int)1e9 + 7;

// 4-direction
int dy4[] = {0,  1, -1,  0};
int dx4[] = {1,  0,  0, -1};

// 8-direction
int dy8[] = {0,  1,  1,  1,  0, -1, -1, -1};
int dx8[] = {1,  1,  0, -1, -1, -1,  0,  1};

// Floating
const double EPS = 1e-11;
#define EQ0(x) (abs(x) < EPS)
#define EQ(x, y) (abs(a-b) < EPS)

int main() {
  int n, k;
  cin >> n >> k;
  if(k == 1) cout << 0 << endl;
  else cout << n - k << endl;
  return 0;
}

Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;
 
int secs = 0, station = 0, transit=0, n;
vector<int> c, s, f, wait;
 
void step(int t) {
	// t is either wait[station] or transit
	secs+=t;
	if (t == transit) {
		wait[station]-=secs;
		transit=0;
	}
	else wait[station]=0;
 
	if (wait[station]<=0) {
		//wait[station] = abs(wait[station])%f[station];
		while (wait[station]<0) wait[station]+=f[station];
	}
	if (wait[station]==0) {
		transit=c[station];
		station++;
	}
}
 
void reset() {
	secs=0;
	station=0;
	transit=0;
	for (int i=0; i<n; i++)
		wait[i]=s[i];
}
 
int main() {
	cin>>n;
	c.resize(n);
	s.resize(n);
	f.resize(n);
	wait.resize(n);
 
	for (int i=0; i<n-1; i++)
		cin>>c[i]>>s[i]>>f[i];
 
	//simulate v99
	for (int i=0; i<n; i++) {
		reset();
		station=i;
		while (station < n-1) {
			if (transit > 0) step(transit);
			else step(wait[station]);
		}
		cout << secs+transit << endl;
	}
 
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 100000000000000000
#define int long long
typedef pair<int, int> P;
vector<P> G[2][100010];

int d[2][100010];
int ans[100010];
int dijkstra(int s, int p) {
    priority_queue<P, vector<P>, greater<P>> que;
    rep(i, 100010) d[p][i] = INF2;
    d[p][s] = 0;
    que.push({0, s});
    while(que.size()) {
        P pp = que.top(); que.pop();
        int u = pp.second;
        int cost = pp.first;
        
        if(cost > d[p][u]) continue;
        //cout << u << " " << cost << endl;
        for(auto e: G[p][u]) {
            int to = e.first;
            int add = e.second;
            if(d[p][to] > cost + add) {
                d[p][to] = cost + add;
                que.push({d[p][to], to});
            }
        }
    }
}


signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m, s, t;
    cin >> n >> m >> s >> t;
    s--; t--;
    rep(i, m) {
        int u, v, a, b;
        cin >> u >> v >> a >> b;
        u--; v--;
        G[0][u].push_back({v, a});
        G[0][v].push_back({u, a});
        G[1][u].push_back({v, b});
        G[1][v].push_back({u, b});
    }
    dijkstra(s, 0);
    dijkstra(t, 1);
    rep(i, n) {
        ans[i] = d[0][i] + d[1][i];
    }
    RREP(i, n - 2, 0) ans[i] = min(ans[i + 1], ans[i]);
    rep(i, n) {
        cout << (int)(1e+15) - ans[i] << endl;
    } 


    return 0;
}


Measured memory_bytes: 19196
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>

typedef long long ll;
const ll INF = 1e18;

ll N;
std::vector< char > vc;

ll dfs(std::string s) {
  if (atoll(s.c_str()) > N) {
    return 0LL;
  }

  ll ret = 0;
  if (std::string::npos != s.find("3") &&
      std::string::npos != s.find("5") &&
      std::string::npos != s.find("7")) {
    ret++;
  }

  for (ll c = 0; c < 3; c++) {
    ret += dfs(s + vc[c]);
  }
  return ret;
}

int main()
{
  std::cin >> N;
  vc.push_back('3');
  vc.push_back('5');
  vc.push_back('7');

  std::cout << dfs("") << std::endl;

  return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int ans = 0;
    for(int i = 1; i <= 5; i++) {
      int x = sc.nextInt();
      if(x == 0) ans = i;
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 35700
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <string>
using namespace std;


int main(){
vector<int> v(5);
cin>>v[0]>>v[1]>>v[2]>>v[3]>>v[4];
int max=0;
for(int i=0;i<v.size();i++){
    if((10-v[i]%10)>max&&v[i]%10!=0)max=10-v[i]%10;
}

int ans=0;
for(int i=0;i<v.size();i++){
    if(v[i]%10){
        ans+=(v[i]/10+1)*10;
    }
    else ans+=v[i];
}
ans-=max;
cout<<ans<<endl;

}

Measured memory_bytes: 256
/* 
	Author: ankrypt
*/


#include <bits/stdc++.h>

using namespace std;

#define MOD 1000000007
#define ll long long int
#define u64 unsigned long long int

ll N, M, X;
ll arr[105];
ll val;

int main() {
	scanf("%lld %lld %lld", &N, &M, &X);
	for(int i = 0; i < M; i++) {
		scanf("%lld", &val);
		arr[val]++;
	}
	ll cnt = 0;
	ll cnt1 = 0;
	for(int i = X; i <= N; i++) {
		if(arr[i]) {
			cnt++;
		}
	}
	for(int i = X; i >= 1; i--) {
		if(arr[i]) {
			cnt1++;
		}
	}
	ll ans = min(cnt, cnt1);
	printf("%lld\n", ans);
	return 0;
}
/*
	Powered by Buggy Plugin
*/


Measured memory_bytes: 256
{-# LANGUAGE BangPatterns #-}
import Control.Monad
import Data.Maybe
import Debug.Trace
import Data.List
import qualified Data.Map.Strict as Map
import qualified Data.IntMap.Strict as IntMap
import qualified Data.Set as Set
import qualified Data.IntSet as IntSet
import Data.Functor
import Data.Array
-- import Data.Array.Unboxed
import Control.Monad.ST
import Data.Array.ST
import qualified Data.ByteString.Char8 as B
import Data.Maybe (fromJust)
readInt = fst . fromJust . B.readInt
readInts = map (fst . fromJust . B.readInt) . B.words <$> B.getLine :: IO [Int]

main :: IO ()
main = do
  n <- readLn :: IO Int
  as <- readInts :: IO [Int]
  bs <- readInts :: IO [Int]
  print $ solve n as bs

solve :: Int -> [Int] -> [Int] -> Int
solve n as bs = x + min y (last as)
  where
    (x, y) = foldl' f (0, 0) $ zip as bs
    f :: (Int, Int) -> (Int, Int) -> (Int, Int)
    f !(!count, !left) !(!a, !b) =
      (
        count + min a (b + left),
        max 0 $ b - max 0 (a - left)
      )



Measured memory_bytes: 8700
n = int(input())
mod = 10**9+7
d = [{},{}]

def judge(s):
    if s[:3] == 'AGC' or s[:3] == 'GAC' or s[:3] == 'ACG' or s[0]+s[2:]=='AGC' or s[:2]+s[3]=='AGC':
        return False
    return True

d[0] = {'TTT':1}

for i in range(n):
    d[(i+1)%2] = {}
    for ne in 'AGCT':
        for elt in d[i%2]:
            if judge(ne+elt[:3]):
                if ne+elt[:2] in d[(i+1)%2]:
                    d[(i+1)%2][ne+elt[:2]] = (d[(i+1)%2][ne+elt[:2]]+d[i%2][elt])%mod
                else:
                    d[(i+1)%2][ne+elt[:2]] = d[i%2][elt]
res = 0
for e in d[n%2]:
    res = (res + d[n%2][e])%mod
print(res%mod)

        

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
const int N = 200;
int h,w,n,a[N*N],M[N][N];
int main() {
    scanf("%d%d%d",&h,&w,&n);
    for(int i=1;i<=n;i+=1) scanf("%d",a+i);
    int cur=0,now=1;
    for(int i=1;i<=h;i+=1) {
        if(i&1) {
            for(int j=1;j<=w;j+=1) {
                M[i][j]=now; cur+=1; if(cur==a[now]) cur=0,now+=1;
            }
        }
        else {
            for(int j=w;j>=1;j-=1) {
                M[i][j]=now; cur+=1; if(cur==a[now]) cur=0,now+=1;
            }            
        }
    }
    for(int i=1;i<=h;i+=1) {
        for(int j=1;j<=w;j+=1) {
            printf("%d ",M[i][j]);
        }
        puts("");
    }
    return 0;
}


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

int main(){

    int N, k;
    int h[100007];
    cin >> N >> k;
    long long int dp[100007];
    for (int i=0;i<N;i++){
        cin >> h[i];
        dp[i] = 0;
    }

    dp[1] = abs(h[1] - h[0]);
    
    for(int low=2; low < N; low++){
        long long int ans = INT_MAX;
        for(int j=1;j<=k;j++){
            if(low >= j)
                ans = min(ans, dp[low-j] + abs(h[low] - h[low-j]));
        }
        dp[low] = ans;
    }
    cout << dp[N-1] << "\n";
    
    return 0;
}

Measured memory_bytes: 1408
N, M, C = map(int, input().split())
B = list(map(int, input().split()))
A = []
for i in range(N):
    A.append(list(map(int, input().split())))

cnt = 0
for i in range(N):
    ans = 0
    for j in range(M):
        ans += A[i][j] * B[j]
    ans += C
    
    if ans > 0:
        cnt += 1

print(cnt)

Measured memory_bytes: 3064
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <set>
#include <vector>
#include <queue>

using namespace std;

#define ll long long

void preambule() {
  cin.tie(0);
  cout.precision(16);
  cout << fixed;
}

string s;

void input() {
  cin >> s;
}

void solve1() {
  int ans1 = 0;
  int ans2 = 0;

  for (int i = 0; i < (int)s.size(); ++i) {
    if (i % 2 == 0) {
      ans1 += s[i] == '1';
      ans2 += s[i] == '0';
    } else {
      ans1 += s[i] == '0';
      ans2 += s[i] == '1';
    }
  }

  cout << min(ans1, ans2);
}

int main() {
#ifdef _DEBUG
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif

  preambule();
  input();
  solve1();
}


Measured memory_bytes: 512
#[test]
fn test_solve() {
    assert_eq!(solve("4\n0\n1\n1\n2\n"), "3\n");
    assert_eq!(solve("3\n1\n2\n1\n"), "-1\n");
    assert_eq!(solve("9\n0\n1\n1\n0\n1\n2\n2\n1\n2\n"), "8\n");
}
fn solve(src: &str) -> String {
    let mut sc = Scanner::from_str(src);

    let fault = "-1\n".to_string();

    let n: usize = sc.read();
    let a: Vec<usize> = (0..n).map(|_| sc.read()).collect();

    if a[0] != 0 {
        return fault;
    }

    let mut ans = 0;
    for i in 1..n {
        if a[i] == a[i - 1] + 1 {
            ans += 1;
        } else if a[i] < a[i - 1] + 1 {
            ans += a[i];
        } else {
            return fault;
        }
    }

    format!("{}\n", ans)
}
fn main() {
    let mut buf = String::new();
    use std::io::{Read, Write};
    std::io::stdin().read_to_string(&mut buf).unwrap();
    std::io::stdout().write_all(solve(&buf).as_bytes()).unwrap();
}
struct Scanner<'a>(std::str::SplitWhitespace<'a>);
impl<'a> Scanner<'a> {
    fn from_str(src: &str) -> Scanner {
        Scanner(src.split_whitespace())
    }
    fn get(&mut self) -> &str {
        self.0.next().unwrap()
    }
    fn read<T: std::str::FromStr>(&mut self) -> T {
        self.get().parse().ok().unwrap()
    }
}


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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

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

using ll = long long;
using R = long double;
const R EPS = 1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r) {return (r > EPS) - (r < -EPS);}
inline R sq(R x) {return sqrt(max(x, 0.0L));}

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

// Problem Specific Parameter:

int main(void) {
	int x, y;
	cin >> x >> y;
	if (x % y == 0)
		cout << -1 << endl;
	else
		cout << x  << endl;
	return 0;
}

Measured memory_bytes: 256
void main() {
    dchar[] s = readln.chomp.to!(dchar[]);
    auto g = s.sort!"a < b".group.array;
    writeln(s.length == g.length ? "yes" : "no");
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.container;
import std.typecons;
import std.ascii;
import std.uni;

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

#define for_(i,a,b) for(int i=a;i<b;++i)
#define allof(a) a.begin(),a.end()
#define minit(a,b) memset(a,b,sizeof(a))
#define size_of(a) (int)a.size()

typedef long long lint;
typedef pair<int, int> pii;

int V, E;
char ans[100010];
vector< vector<int> > edges;

set<char> cand[100010];

void solve() {
	for_(i,0,V) {
		cand[i].clear();
		if (ans[i] != '?') continue;
		for_(j,0,26) {
			cand[i].insert('a' + j);
		}
	}
	
	for_(i,0,V) {
		if (ans[i] != '?') {
			int e_size = size_of(edges[i]);
			for_(j,0,e_size) {
				int u = edges[i][j];
				cand[u].erase(ans[i]);
			}
		}
	}
	
	for_(i,0,V) {
		if (ans[i] == '?') {
			char c = *cand[i].begin();
			ans[i] = c;
			int e_size = size_of(edges[i]);
			for_(j,0,e_size) {
				int u = edges[i][j];
				cand[u].erase(c);
			}
		}
		
		cout << ans[i];
	}
	cout << endl;
}

int main() {
	cin >> V >> E;
	for_(i,0,V) {
		char c; cin >> c;
		ans[i] = c;
	}
	edges.assign(V, vector<int>());
	for_(i,0,E) {
		int s, t; cin >> s >> t;
		edges[s].push_back(t);
		edges[t].push_back(s);
	}
	solve();
	return 0;
}


Measured memory_bytes: 134260
#include<stdio.h>
#include<math.h>
int main(void){
        int a[10][10],n,d,i,j,k,l=0,p=0;
        double s[1000],b[10][10];
        scanf("%d%d",&n,&d);
        for(i=0;i<n;i++){
            for(j=0;j<d;j++){
                scanf("%d",&a[i][j]);
                b[i][j]=a[i][j];
            }
        }
       for(i=0;i<n-1;i++){
            for(k=i+1;k<n;k++){
                for(j=0;j<d;j++){
                    s[p]=s[p]+(pow((b[i][j]-b[k][j]),2));
                }
                s[p]=sqrt(s[p]);
                if(round(s[p])-(s[p])==0){
                    l++;
                }
                p++;
            }
       }
       printf("%d",l);
       return 0;
}


Measured memory_bytes: 2160
// #include {{{
#include <iostream>
#include <cassert>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <ctime>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <string>
#include <bitset>
#include <vector>
#include <complex>
#include <algorithm>
using namespace std;
// }}}
// #define {{{
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define de(x) cout << #x << "=" << x << endl
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define per(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
// }}}

const int N = 5e5 + 10;
char s[N];
int n;

int main(){
  scanf("%s",s);
  n=strlen(s);
  reverse(s,s+n);
  for(int i=0,carry=0;i<n;++i) {
    int d=int(s[i]-'0')*9+carry;
    s[i]='0'+(d%10);
    carry=d/10;
    if(carry&&i+1==n) {
      s[n++]='0';
    }
  }
  int sum=0;
  rep(i,0,n) sum+=s[i]-'0';
  for(int i=0;;++i) {
    if(sum<=9*i) return printf("%d\n",i),0;
    int carry=9;
    for(int i=0;i<n&&carry;++i){
      int d=s[i]-'0'+carry;
      if(d>=10) d-=10,carry=1;
      else carry=0;
      sum-=s[i]-'0';
      s[i]=d+'0';
      sum+=s[i]-'0';
      if(carry&&i+1==n) {
        s[n++]='0';
      }
    }
  }
  return 0;
}


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

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  
  bool con1 = ((a == 7) and (b == 5) and (c == 5));
  bool con2 = ((a == 5) and (b == 7) and (c == 5));
  bool con3 = ((a == 5) and (b == 5) and (c == 7));
  
  if(con1 or con2 or con3)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
//#pragma GCC optimize ("Ofast")
//#pragma GCC target ("avx,avx2")
#define rep(i, n)    for(ll i = 0; i < (n); ++i)
#define repA(i, a, n)  for(ll i = a; i <= (n); ++i)
#define repD(i, a, n)  for(ll i = a; i >= (n); --i)
#define pb push_back
#define X first
#define Y second
typedef long long int ll;
typedef long double ld;
typedef pair<ll, ll> pii;
typedef vector<ll> vi;
typedef vector<pii> vii;
const ll INF = 1e18+1;
const ll MOD = 1000000007L;
#ifdef umang99m
    #include "/home/umang/Desktop/folder/home/.templates/header.h"
#else
    #define dbg(args...)
    #define timer()
#endif
int main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    string s,t;
    cin>>s;
    cin>>t;
    ll sl=s.length(), tl=t.length();
    ll dp[sl+1][tl+1];
    ll p[sl+1][tl+1];
    rep(i,sl+1) dp[i][0] = 0;
    rep(i, tl+1) dp[0][i]=  0;
    repA(i,1,sl){
        repA(j,1,tl){
            if(s[i-1] == t[j-1]){
                dp[i][j] = dp[i-1][j-1] + 1;
                p[i][j] = 1;
            }
            else {
                if(dp[i-1][j] > dp[i][j-1]){
                    dp[i][j] = dp[i-1][j];
                    p[i][j] = 2;
                } else {
                    dp[i][j] = dp[i][j-1];
                    p[i][j] = 3;
                }
            }
        }
    }
    string ans = "";
    ll i=sl,j=tl;
    while(i>0 && j>0){
        if(p[i][j] == 1) {
            ans.pb(s[i-1]);
            i--;j--;
        } else if(p[i][j] == 2){
            i--;
        } else {
            j--;
        }
    }
    reverse(ans.begin(), ans.end());
    cout<<ans<<endl;

    timer();
    return 0;
}

Measured memory_bytes: 140928
#include <bits/stdc++.h>
using namespace std;
#ifdef _DEBUG
#define dlog(str) cout << "====" << str << endl;
#else
#define dlog(str)
#endif
#define INF 999999999
#define MOD 1000000007
#define REP(i, n) for(int i = 0, i##_l = (n); i < i##_l; i++)
#define FOR(i, s, e) for(int i = s, i##_l = (e); i < i##_l; i++)
#define LLI long long int
#define _min(a, b) ((a < b) ? a : b)
#define _max(a, b) ((a < b) ? b : a)
#define chmax(a, b) a = _max(a, b)
#define chmin(a, b) a = _min(a, b)
#define bit(a, shift) ((a>>shift)&1))
#define pm(a) ((a) ? 1 : -1)
#define SORT(v) sort(v.begin(), v.end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
// int 2.14E±9    lli 9.2E±18    double 1.7E±380

int main() {
    cout << fixed << setprecision(10);
    int N;
    string s;
    cin >> N >> s;
    REP(i, s.length()) {
        s[i] = ((s[i] - 'A') + N) % 26 + 'A';
    }
    cout << s;

    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		long Acont = 0;
		long count = 0;
		S = S.replace("BC", "D");
		for(int i = 0; i < S.length(); i++) {
			if(S.charAt(i) == 'A') {
				Acont++;
			} else if(S.charAt(i) == 'D') {
				count += Acont;
			} else {
				Acont = 0;
			}
		}
		System.out.println(count);
	}

}


Measured memory_bytes: 34216
#include <cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
int a[200005],b[200005];
int main()
{
    int n,i,j,x,y;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d",&a[i]);
        b[i]=a[i];
    }
    sort(b,b+n);
    x=b[n/2-1];
    y=b[n/2];
    for(i=0;i<n;i++)
    {
        if((lower_bound(b,b+n,a[i])-b)<=n/2-1)
        printf("%d\n",y);
        else printf("%d\n",x);
    }
    return 0;
}


Measured memory_bytes: 3712
#include <iostream>
#include <map>
#include <algorithm>
#include <string>
#include <vector> 
#include <numeric>
#include <cmath>
#include <queue>
#include <iomanip>
#include <functional>


#define CHMAX(a,b) a = std::max(a,b)
#define CHMIN(a,b) a = std::min(a,b)
#define MAXMIN(a,b,c) std::max(a,min(b,c))
#define CHABS(a) a = std::abs(a) 
#define COUT(a) std::cout << a << std::endl
#define CERR(a) std::cerr << a << std::endl
#define FOR(n) for(lli i = 0; i < n; i++)

using namespace std;
using lli = long long int;
using pll = pair<lli, lli>;
using tlll = tuple<lli, lli, lli>;
using vll = vector<lli>;

lli mod197 = 1000000007LL;
lli INF = 10000000000000;

// ax + by = gcd(a,b) 最大公約数
template< typename T >
T extgcd(T a, T b, T& x, T& y) {
	T d = a;
	if (b != 0) {
		d = extgcd(b, a % b, y, x);
		y -= (a / b) * x;
	}
	else {
		x = 1;
		y = 0;
	}
	return d;
}

bool check(string s) {

	for (int i = 0; i < s.size(); i++) {
		if (s[i] != s[s.size() - i - 1]) {
			return false;
		}
	}

	return true;
}

int main(void) {

	string s;
	cin >> s;

	string before_copy = s.substr(0, (s.size() - 1) / 2),
		after_copy = s.substr((s.size() + 1) / 2, s.size());

	if (check(s) && check(before_copy) && check(after_copy)) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}


	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (ll i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define m1(x) memset(x,-1,sizeof(x))
const int INF = 1e9;
const int MOD = 1e9 + 7;

//移動A:(i+1, j+2)
//移動B:(i+2, j+1);
//Aをx回、Bをy回した時、座標は(x+2y, 2x+y)
//x+2y = X, 2x+y = Yとなる(x, y)の組
//3y = 2X - Y, 3x = 2Y - X
//これの並び替え
//x+y C x (or x+y C y);
//逆元の利用

ll ans = 0;
int X, Y;
int x, y;
int main(){
  cin >> X >> Y;
  if((2*X - Y) % 3 == 0 && (2*Y - X) % 3 == 0 && 2*X - Y >= 0 && 2*Y - X >= 0){
    x = (2*X - Y) / 3;
    y = (2*Y - X) / 3;
  
    if(x < y) swap(x, y);
    //分子
    ll numerator = 1;
    for(ll i = x+1; i <= x+y; i++){
      numerator = (i * numerator) % MOD;
    }
    //分母
    ll denominator = 1;
    for(int i = 1; i <= y; i++){
      denominator = i * denominator % MOD;
    }
    //逆元の計算
    int p = MOD - 2, res = 1;
    while(p > 0){
      if(p&1) res = res * denominator % MOD;
      denominator = denominator * denominator % MOD;
      p >>= 1;
    }
    ans = res * numerator % MOD;
  }
  cout << ans <<endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define mFOR(i, a, b) for (int i = a; i > b; i--)
#define MP make_pair
#define PB push_back
#define ALL(v) v.begin(), v.end()
#define N 100007
#define INF 1000000007
using namespace std;

typedef long long ll;

ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll fceil(ll a, ll b) { return (a % b == 0 ? a / b : a / b + 1); }
int main()
{
   ll a, b, g;
   cin >> a >> b;
   g = gcd(a,b);
   cout << a*b/g << endl;
   return 0;
}


Measured memory_bytes: 256
import math
n,d = map(int,input().split())
x = [list(map(int,input().split())) for i in range(n)]
cnt = 0
for k in range(n):
  for i in range(n):
    a = 0
    if i > k:
      for j in range(d):
        a += abs(x[k][j]-x[i][j])**2
      b = math.sqrt(a)
      if int(b)**2 == a:
        cnt += 1
print(cnt)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
typedef vector<ll> VI;
typedef vector<VI> VVI;
const ll MOD = 1000000007;
const ll INF = 4611686018427387903;
#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()

int main(){
	int x, ans;
	REP(i,5){
		cin >> x;
		if(x==0)
			ans=i+1;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3584
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
#define N 100010
ll k,n,q,a[N],b[N];
namespace subseg{
    ll dat[2*N];
    void init(){
	for(int i=0;i<2*N;i++)dat[i]=0;
    }
    void upd(ll i,ll x){
	i+=N; dat[i]=x;
	for(;i;i>>=1){
	    dat[i/2]=dat[i]+dat[i^1];
	}
    }
    ll qry(ll l,ll r){
	l+=N,r+=N+1;
	ll res=0;
	for(ll a=l,b=r;a<b;a>>=1,b>>=1){
	    if(a&1)res+=dat[a++];
	    if(b&1)res+=dat[--b];
	}
	return res;
    }
};

namespace Segtree{
  ll dat[2*N],laz[2*N];
  void init(){
      for(int i=0;i<2*N;i++)dat[i]=0,laz[i]=1;
      for(int i=0;i<n;i++)dat[i+N]=b[i];
      for(int i=N-1;i;i--)dat[i]=dat[i*2]+dat[i*2+1];
  }
  ll eval(ll k){
      if(k<N){
	  laz[k*2]*=laz[k];
	  laz[k*2+1]*=laz[k];
      }
      dat[k]*=laz[k]; laz[k]=1;
      return dat[k];
  }
  void upd(ll i,ll x){
      i+=N;
      for(ll d=20;~d;d--)eval(i>>d);
      if(subseg::qry(0,i-N-1)%2==0)dat[i]=x;
      else dat[i]=-x;
      for(ll a=i;a;a>>=1){
	  dat[a/2]=eval(a)+eval(a^1);
      }
  }
  void flip(ll l,ll r){
     l+=N,r+=N+1;
     for(ll a=l,b=r;a<b;a>>=1,b>>=1){
	 if(a&1)laz[a++]*=-1;
	 if(b&1)laz[--b]*=-1;
     } 
     for(ll a=l,b=r;a+b;a>>=1,b>>=1){
	 dat[a/2]=eval(a)+eval(a^1);
	 dat[b/2]=eval(b)+eval(b^1);
     }
  }
  ll sum(ll l,ll r){
      l+=N,r+=N+1;
      for(ll d=20;~d;d--){eval(l>>d); eval(r>>d);}
      ll res=0;
      for(ll a=l,b=r;a<b;a>>=1,b>>=1){
	  if(a&1)res+=eval(a++);
	  if(b&1)res+=eval(--b);
      }
      return res;
  }
};

int main(){
    cin>>k>>n>>q;
    subseg::init();
    ll zero=0;
    for(int i=0;i<n;i++){
	cin>>a[i]; a[i]*=-1;
	if(zero%2==0)b[i]=a[i]; else b[i]=a[i]*-1;
	if(a[i]==0){
	    zero++;
	    subseg::upd(i,1);
	}
    }
    Segtree::init();
    for(int u=0;u<q;u++){
	ll l,r;cin>>l>>r; l--,r--;
	if(a[l]==0&&a[r]==0){}
	else if(a[l]!=0&&a[r]!=0){
	    swap(a[l],a[r]);
	    Segtree::upd(l,a[l]);
	    Segtree::upd(r,a[r]);
	}
	else{
	    if(a[l]==0){subseg::upd(l,0);subseg::upd(r,1);}
	    if(a[r]==0){subseg::upd(r,0);subseg::upd(l,1);}
	    swap(a[l],a[r]);
	    Segtree::upd(l,a[l]);
	    Segtree::upd(r,a[r]);
	    Segtree::flip(l+1,r-1);
	}
	ll ans=1+Segtree::sum(0,n-1);
	ans%=k; if(ans<=0)ans+=k;
	if(zero%2==0)cout<<ans<<endl;
	if(zero%2==1)cout<<-ans<<endl;
    }
    return 0;
}



Measured memory_bytes: 9368
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }
    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int N = scan.nextInt();
        int[] a = new int[N-1];
        int[] b = new int[N-1];
        int remain = N;
        boolean[] finished = new boolean[N];
        int[] point = new int[N];
        HashMap<Integer, List<Integer>> edges = new HashMap<>();
        for (int i = 0; i < N - 1; i++) {
            a[i] = scan.nextInt() - 1;
            b[i] = scan.nextInt() - 1;
            if (!edges.containsKey(a[i])) {
                edges.put(a[i], new ArrayList<Integer>());
            }
            edges.get(a[i]).add(b[i]);
            if (!edges.containsKey(b[i])) {
                edges.put(b[i], new ArrayList<Integer>());
            }
            edges.get(b[i]).add(a[i]);
        }
        int[] data = new int[N];
        for (int i = 0; i < N; i++) {
            data[i] = scan.nextInt();
        }
        Arrays.sort(data);
        int M = 0;
        PriorityQueue<Integer> p = new PriorityQueue<>(Comparator.reverseOrder());
        for (int i = 0; i < N - 1; i++) {
            M += data[i];
            p.add(data[i]);
        }
        p.add(data[N-1]);
        Queue<Integer> queue = new LinkedList<>();
        for(int x : edges.keySet()) {
            if (edges.get(x).size() > 1) {
                queue.add(x);
                break;
            }
        }
        while (0 < remain && !queue.isEmpty()) {
            int current = queue.poll();
            if (finished[current]) {
                continue;
            }
            finished[current] = true;
            point[current] = p.poll();
            remain -= 1;
            List<Integer> next = edges.get(current);
            for(int x : next) {
                queue.add(x);
            }
        }

        List<String> list = new ArrayList<String>();
        for (int i = 0; i < N; i++) {
            list.add(Integer.toString(point[i]));
        }
        System.out.println(M);
        System.out.println(String.join(" ", list));
    }
}


Measured memory_bytes: 45928