akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <algorithm>
#include <iomanip>
using namespace std;
 
#define ll long long
#define ull unsigned long long
#define ld long double
 
#define mp make_pair
#define pb push_back

#define rep(i,a,b) for(ll i=a;i<b;i++)
#define repb(i,a,b) for(ll i=a;i>=b;i--)
 
#define ft first
#define sd second
#define endl "\n"
 
#define pll pair<ll,ll>
#define V vector<ll>
#define S set<ll>
#define VV vector<V>
const long double pi=asin(1)*2;
 
const ll M=1000000007;
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
 
ll pow1(ll a,ll b){
    int res=1;
    while(b>0){
        if(b&1){
        	res=(res*a)%M;
		}
        a=(a*a)%M;
        b>>=1;
    }
    return res%M;
}
const ll N =100001;



int main()
{
	fast;
	int t;
	t=1;
//	cin>>t;
	while(t--)
	{
		string s;
		cin>>s;
		ll n=s.length();
		ll a=0;
		rep(i,0,n){
			ll x=(ll)(s[i]-'0');
			a=(a+x)%9;
		}
		if(a==0){
			cout<<"Yes"<<endl;
		}
		else{
			cout<<"No"<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3744
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
using namespace std;
const long long int INF = 1e18;
const long long int mod = 1e9+7;

int main(){
    ll n, m;
    cin>>n>>m;
    vector<ll> h(n);
    for(ll i=0;i<n;++i){
        cin>>h[i];
    }
    vector<ll> g[n];
    for(ll i=0;i<m;++i){
        ll a, b;
        cin>>a>>b;
        a--;
        b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    ll ans = 0;
    for(ll i=0;i<n;++i){
        bool flag = true;
        for(auto val : g[i]){
            if(h[i] <= h[val]){
                flag = false;
                break;
            }
        }
        if(flag){
            ans++;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 9860
#include <stdio.h>
#define MAX 100
#define INFTY 10000000
 
void compute(int );
int min(int, int);
 
int A[MAX];
int B[MAX][MAX];
 
 
int main(void){
 
  int i,j,k,n,r,c;
 
  scanf("%d",&n);
 
 
  for(i=0; i<n; i++){   
 
    scanf("%d %d",&r,&c);
    A[i]=r;
    A[i+1]=c;
  }
   
  compute(n);
   
   
  printf("%d\n",B[1][n]);
 
  return 0;
}
 
void compute(int n) {
 
  int i,j,k,l,q;
 
  for(i=1; i<=n; i++)
    B[i][i]=0;
 
  for(l=2; l<=n; l++){
 
    for(i=1; i<=n-l+1; i++){
      j=i+l-1;
      B[i][j]=INFTY;
 
      for(k=i; k<=j-1; k++){
 
    q=B[i][k]+B[k+1][j]+A[i-1]*A[k]*A[j];
 
    B[i][j]=min(B[i][j],q);
      }
    }
  }
}
 
 
 
int min(int x,int y){
  if(x<y)
    return x;
  else
    return y;
}

Measured memory_bytes: 636
#include <bits/stdc++.h>
using namespace std;
const int MOD=1e9+7;
long long modpow(long long b, long long i){
  long long s=1;
  while(i){
    if(i%2) s=(s*b)%MOD;
    b=(b*b)%MOD;
    i/=2;
  }
  return s;
}
int main(){
  //clock_t start,end;
  //start=clock();

  int n; cin >>n; int sum=0;
  vector<long long>v(n);
  for(int i=0; i<n; i++) cin >>v[i];
  for(int i=0; i<60; i++){
    long long odd=0,even=0;
    for(int j=0; j<n; j++){
      if(v[j]%2) odd++;
      else even++;
      v[j]/=2;
    }
    sum=(sum+(((odd*even)%MOD)*modpow(2,i))%MOD)%MOD;
  }
  cout <<sum<<endl;

  //end=clock();
  //double time_taken=double(end-start)/double(CLOCKS_PER_SEC); 
  //cout <<"Time taken: "<<fixed<<setprecision(5);
  //cout <<time_taken<<"s/"<<time_taken*1000<<"ms"<<endl;
return 0;}

Measured memory_bytes: 2560
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) throws Exception {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int N = scan.nextInt();
        int K = scan.nextInt();
        double answer = 0;
        for (int i = 1; i <= N; i++) {
            double temp = (double) 1/N;
            int score = i;
            if (K <= i) {
                answer += (double) 1/N;
                continue;
            }
            while (score < K) {
                score *= 2;
                temp *= 0.5;
            }
            answer += temp;
        }
        System.out.printf("%.12f", answer);
    }
}


Measured memory_bytes: 23764
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
//#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;



int main(){
	int N; cin >> N;
	ll nowT = 1;
	ll nowA = 1;
	rep(i,N){
		int T,A; cin >> T >> A;
		ll a = (nowT+T-1)/T;
		ll b = (nowA+A-1)/A;
		nowT = max(a,b)*T;
		nowA = max(a,b)*A;
	}
	ll ans = nowT + nowA;
	cout << ans << endl;
}



Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define mymalloc(p,n) {p = malloc((n)*sizeof(*p));if ((p)==NULL) {printf("not enough memory?\n"); exit(1);};}

typedef struct obj{
	int value;
	struct obj *next;
	struct obj *prev;
}obj;

typedef struct{
	obj *root;
}stack;

obj *createObj(int v,obj *pre,obj *nex){
	obj *ob;
	mymalloc(ob,1);
	ob->value=v;
	ob->prev=pre;
	ob->next=nex;
	return ob;
}

int pop(stack *S){
	int value;
  obj *temp;
	value=S->root->next->value;
	temp=NULL;
	if(S->root->next->next!=NULL){
		temp=S->root->next->next;
	}
	free(S->root->next);
	S->root->next=temp;
	if(S->root->next!=NULL){
		S->root->next->prev=S->root;
	}
	return value;
}

void push(stack *S,int v){
	obj *ob;
	ob=createObj(v,S->root,S->root->next);
	if(S->root->next!=NULL){
		S->root->next->prev=ob;
	}
	S->root->next=ob;
}

stack *createStack(){
	stack *S;
	mymalloc(S,1);
	S->root=createObj(0,NULL,NULL);
	return S;
}


void calcPoland(stack *S,char *v){
	int i,j,value;
	if(isdigit(v[0])){
		i=atoi(v);
		push(S,i);
	}
	else{
		j=pop(S);
		i=pop(S);
		switch(v[0]){
			case '+':
				value=i+j;break;
			case '-':
				value=i-j;break;
			case '*':
				value=i*j;break;
		}
		push(S,value);
	}
}

main(){
	char v[10];
	stack *S;
	S=createStack();
	while(scanf("%s",v)!=EOF){
		calcPoland(S,v);
	}
	printf("%d\n",pop(S));
	free(S);
	return 0;
}

Measured memory_bytes: 580
#include <cstdio>

int main(){
    int a,b,c;
    scanf("%d %d %d",&a,&b,&c);
    if(a == b){
        printf("%d\n",c);
    }else if(a == c){
        printf("%d\n",b);
    }else{
        printf("%d\n",a);
    }

    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define int long long
#define double long double
#define mod 1000000007
#define F first
#define S second
#define P pair<long long,long long>
#define all(a) a.begin(),a.end()
#define INF 10000000000000000
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using namespace std;

signed main(void){
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);

    int n; cin>>n;
    vector<int> d(n);
    rep(i,n)cin>>d[i];

    if(n>=24){
        cout<<0<<endl;
        return 0;
    }

    int ans=0;
    for(int bit=0; bit<(1<<n); bit++){
        bitset<24> st;
        int tmp=30;
        rep(i,n){
            if(d[i]==0){
                tmp=0; break;
            }
            if((1<<i)&bit){
                if(st[d[i]]){
                    tmp=0; break;
                }
                st[d[i]]=true;
            }else{
                if(st[24-d[i]]){
                    tmp=0; break;
                }
                st[24-d[i]]=true;
            }
        }
        int cur=0;
        rep(i,24){
            if(st[i]){
                chmin(tmp,i-cur);
                chmin(tmp,24-i);
                cur=i;
            }
        }
        chmax(ans,tmp);
    }
    cout<<ans<<endl;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll>pll;

const int N=1e7;

ll v[N+10];

ll a[N+10];


bool compare(string  &a, string &b)
{
     string f=a+b,c=b+a;

     return f<c;
}

int main()
{
    ll n;

    cin>>n;

    ll ara[n+10];

    for(ll i=0;i<n;i++)
    {
        cin>>ara[i];
    }
    ll lcm=ara[0],gcd=0,sum=0;

      for(ll i=1;i<n;i++)
      {
          gcd=__gcd(lcm,ara[i]);
          
          lcm=(lcm*ara[i])/gcd;
      }

      for(ll i=0;i<n;i++)
      {
          sum+=(lcm/ara[i]);
      }

      double ans=0,ans2=0;

      ans=sum,ans2=lcm;

      ans2=ans2/ans;

      cout<<setprecision(10)<<fixed;

      cout<<ans2<<endl;



}








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

int main(){
  int N;cin>>N;
  bool ans=false;
  while(N>0){
    int X=N%10;
    if(X==7){
      ans=true;
      break;
    }
    N/=10;
  }
  if(ans) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}


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

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

    return 0;
}



Measured memory_bytes: 3100
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 X = sc.nextInt();
		int Y = sc.nextInt();
		int total = 0;
		if (N > K) total = K*X + (N-K)*Y;
		else  total = N*X;
		System.out.println( total );
	}
}


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

int gcd(int s,int t){
  if(t == 0){
    return s;
  }
  return gcd(t, s%t);
}

int main(void){
  long int a,b; cin >> a >> b;
  long int ans = gcd(a, b);
  cout << a*b/ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#define range(i, r) for(int i=0;i<r;i++)
#define ranges(i, l, r) for(int i=l;i<r;i++)
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi std::vector<std::vector<int> >
#define vvl std::vector<std::vector<ll> >
#define MODs (int)1000000007;
#define MODn (int)1000000009;
typedef long long int ll;
using namespace std;

int main(int argc, char const *argv[]) {
  //cin.tie(0);
  //ios::sync_with_stdio(false);
  ll N, M, tmp, count;
  std::cin >> N >> M;
  vvl ken = vv(M, 3, 0, ll);
  vvl ID = vv(M, 2, 0, ll);
  range(i, M) {
    std::cin >> ken[i][1] >> ken[i][0];
    ken[i][2] = i;
  }
  sort(ken.begin(), ken.end());
  range(i, M){
    tmp = ken[i][1];
    ken[i][1] = ken[i][0];
    ken[i][0] = tmp;
  }
  sort(ken.begin(), ken.end());
  tmp = 0;
  range(i, M){
    if(tmp != ken[i][0]){
      count = 1;
      tmp = ken[i][0];
      ID[i][1] = ken[i][0] * 1000000 + count;
      ID[i][0] = ken[i][2];
    }else{
      count += 1;
      ID[i][1] = ken[i][0] * 1000000 + count;
      ID[i][0] = ken[i][2];
    }
  }
  sort(ID.begin(), ID.end());
  int zero;
  range(i, M) {
    zero = 12 - to_string(ID[i][1]).size();
    std::cout << string(zero, '0') << ID[i][1] << '\n';
  }
  return 0;
}


Measured memory_bytes: 12416
#include <iostream>
#include <queue>
#include <map>
#include <set>
#include <cstdio>

using namespace std;

#define LIMIT 300

int len;
string str;

bool check(string s){
  char ch = s[0];

  for(int i = 1 ; i < len ; i++){
    if(ch != s[i]) return false;
  }
  return true;
}

int bfs(){
  string ans;
  queue<string> Q;
  Q.push(str);

  bool found = false;
  set<string> used;
  used.insert(str);
  map<string,int> dist;
  dist[str] = 0;

  while(!Q.empty()){
    string s = Q.front(); Q.pop();
    
    if(check(s)){
      found = true;
      ans = s;
      break;
    }

    for(int i = 1 ; i < len ; i++){
      string next = s;
      if(s[i-1] == 'b' && s[i] == 'r' ||
	 s[i-1] == 'r' && s[i] == 'b'){
	next[i-1] = next[i] = 'g';
      }else if(s[i-1] == 'b' && s[i] == 'g' ||
	       s[i-1] == 'g' && s[i] == 'b'){
	next[i-1] = next[i] = 'r';
      }else if(s[i-1] == 'r' && s[i] == 'g' ||
	       s[i-1] == 'g' && s[i] == 'r'){
	next[i-1] = next[i] = 'b';
      }
      
      if(!used.count(next)){
	dist[next] = dist[s] + 1;
	used.insert(next);
	Q.push(next);
      }
    }
  }

  if(!found) return -1;
  return dist[ans];
}

int main(){
  while(cin >> str,str != "0"){
    len = (int)str.size();
    int res = bfs();
    if(res == -1){
      puts("NA");
    }else{
      printf("%d\n" ,bfs());
    }
  }
  return 0;
}

Measured memory_bytes: 4232
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) {rep(_,v.size())cout<<" "<<v[_];puts("");}
#define show2d(v) {rep(__,v.size())show1d(v[__]);}
using namespace std;
//kaewasuretyuui
typedef long long ll;
#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<int,int,int,int> tp;
typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
//template<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
// int dx[]={0,1,0,-1};
// int dy[]={1,0,-1,0};//RDLU
#define yes puts("YES")
#define no puts("NO")

//nCr mod m
#define MOD 1000000007
#define M 1000000
vector<ll> fact;
bool h=false;
void init(){
	h=true;
	fact=vector<ll>(M);
	fact[0]=fact[1]=1;
	loop(i,2,M)fact[i]=fact[i-1]*i%MOD;
}
// a^b mod MOD
ll powmod(ll a,ll b,ll m=MOD){
	ll out=1;
	ll p=a%m;
	while(b){
		if(b&1)out=out*p%m;
		p=p*p%m;
		b>>=1;
	}
	return out;
}
//nCr
ll nCr(ll n,ll r,ll m=MOD){
	if(!h)init();
	if(n<0||r<0||n<r)return 0;//??????
	ll out=fact[n]*powmod(fact[r]*fact[n-r]%m,m-2,m)%m;
	return out;
}
//nHr
ll nHr(ll n,ll r){
	if(!r&&n!=r)return 0;
	if(!r)return 1;
	return nCr(n+r-1,r-1);
}
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);

	int n,m;
	cin>>n>>m;
	vi f(1000000,1);
	rep(i,1000000-1)(f[i+1]=f[i]*2)%=MOD;
	int x=0,y=0;
	rep(i,n+m){
		cout<<shosu(9)<<(1+MOD-x+y)*powmod(2,MOD-2,MOD)%MOD<<endl;
		(x+=nCr(i,n-1)*powmod(f[i+1],MOD-2,MOD))%=MOD;
		(y+=nCr(i,m-1)*powmod(f[i+1],MOD-2,MOD))%=MOD;
	}
}


Measured memory_bytes: 17792
let n, k = Scanf.scanf " %d %d" @@ fun a b -> a, b
let xys = Array.init n @@ fun _ -> Scanf.scanf " %d %d" @@ fun a b -> a, b
let ans, xs, ys = ref max_int, ref [], ref []
let _ = Array.iteri (fun i (xi, yi) -> for j = i + 1 to n - 1 do let xj, yj = xys.(j) in xs := (xi, xj) :: !xs; ys := (yi, yj) :: !ys done) xys; List.(iter (fun (xi, xj) -> iter (fun (yi, yj) -> if Array.fold_left (fun c (x, y) -> if (xi <= x && x <= xj || xj <= x && x <= xi) && (yi <= y && y <= yj || yj <= y && y <= yi) then c + 1 else c) 0 xys >= k then ans := min !ans @@ abs (xi - xj) * abs (yi - yj)) !ys) !xs); Printf.printf "%d\n" !ans

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

int N;
string s[10000];

int par[26],sz[26];

void init(){
    for(int i=0;i<26;i++){
        par[i]=i;
        sz[i]=1;
    }
}

int find(int x){
    return x==par[x]?x:par[x]=find(par[x]);
}

void unite(int x,int y){
    x=find(x);y=find(y);
    if(x==y)return;

    if(sz[x]<sz[y])swap(x,y);
    par[y]=x;
    sz[x]+=sz[y];
}

int in[26]={0};
int out[26]={0};
vector<int>G[26];
void dfs(int p){
    in[p]--;
    for(int i=0;i<G[p].size();i++){
        int to=G[p][i];
        if((!in[to])||(!out[to]))continue;
        out[to]--;
        dfs(to);
    }
}
void solve(){
    for(int i=0;i<26;i++){
        in[i]=out[i]=0;
        G[i]=vector<int>();
    }
    int start;
    for(int i=0;i<N;i++){
        int o=s[i][0]-'a';
        int e=s[i][s[i].size()-1]-'a';

        in[o]++;
        out[e]++;
        unite(o,e);

        start=o;
        G[o].push_back(e);
    }

    int cnt=0;

    for(int i=0;i<26;i++){
        if(in[i]!=out[i]){
            cout<<"NG"<<endl;
            return;
        }

        if(in[i]&&i==par[i])cnt++;
    }

    dfs(start);


    for(int i=0;i<26;i++){
        if(in[i]){
            cout<<"NG"<<endl;
            return;
        }
    }

    cout<<"OK"<<endl;

}

int main(){
    while(cin>>N,N){
        for(int i=0;i<N;i++)cin>>s[i];
        solve();
    }
    return 0;
}

Measured memory_bytes: 2204
import java.util.*;
public class Main {

  public static void main(String[] args) { 
      Scanner sc = new Scanner(System.in);
      int n = sc.nextInt();
      int m = sc.nextInt();

      int res = 1;
      for(int i = m / n; i >= 1; i--) {
        if(m % i == 0) {
          System.out.println(i);
          return;
        }
      }
      System.out.println(res);
  }
}

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

using namespace std;

int main(){
    long long int a,b,n,ans = 0;

    cin >> a >> b >> n;

    if(b-1 < n){
        cout << (((a*(b-1))/b) - a*((b-1)/b)) << endl;
    }else{
        cout << (((a*n)/b) - a*(n/b)) << endl;
    }
  
    return 0;
}

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

int main(){

    int n,m,q;
    cin >> n >> m >> q;

    vector<int> lr[n+1];

    rep(i,m){
        int t1,t2;
        cin >> t1 >> t2;
        lr[t1].push_back(t2);
    }

    rep(i,n+1){
        sort(lr[i].begin(),lr[i].end());
    }

    rep(i,q){
        int ans=0;
        int t1,t2;
        cin >> t1 >> t2;
        for(int i=t1;i<=t2;i++){
            ans+=distance(lr[i].begin(),upper_bound(lr[i].begin(),lr[i].end(),t2)--);

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

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

using namespace std;

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

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

	if (a <= 0 && b >= 0) {
		cout << "Zero" << endl;
	}
	else {
		if (a > 0 || (b - a + 1) % 2 == 0)
			cout << "Positive" << endl;
		else
			cout << "Negative" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

void bubblesort(int A[], int n);
int count;

int main(){
  int n, k;
  int A[100];

  scanf("%d", &n);
  for(k = 0; k < n; k++){
    if(k == n-1){
      scanf("%d", &A[k]);
    }else{
      scanf("%d ", &A[k]);
    }
  }

  count = 0;
  for(k = 0; k < n; k++){
    bubblesort(A, n);
  }

  for(k = 0; k < n; k++){
    if(k == n-1){
      printf("%d\n", A[k]);
    }else{
      printf("%d ", A[k]);
    }
  }

  printf("%d\n", count);

  return 0;
}

void bubblesort(int A[], int n){
  int i, j, flag;
  int tmp;

  flag = 1;
  i = 0;

  while(flag == 1){
    flag = 0;
    for(j = n-1; j >= i+1; j--){
      if(A[j] < A[j-1]){
        tmp = A[j];
        A[j] = A[j-1];
        A[j-1] = tmp;
        flag = 1;
        count++;
      }
    }
    i++;
  }
}



Measured memory_bytes: 2096
/**
 *    author:  FromDihPout
 *    created: 2020-08-13
**/

#include <bits/stdc++.h>
using namespace std;


int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
     
    char c;
    cin >> c;
    c++;
    cout << c << '\n';
}

Measured memory_bytes: 3592
/* AOJ 0054
 *
 * http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0054
 *
 */

#include <stdio.h>


int s(int a, int b, int n){
    int i;
    int sum;
    sum = 0;


    for(i=0;i<n;i++){
        /* printf("%d %d\n", a, i);*/
        sum += a/b;
        a = (a%b)*10;
    }
    return sum;
}


int main(){
    int a, b, n;
    while(scanf("%d %d %d",&a, &b, &n) == 3){
        printf("%d\n", s((a%b)*10, b, n));
    }

    return 0;
}

Measured memory_bytes: 0
//#pragma comment(linker, "/stack:200000000")

#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>

#define int long long
#define ll long long
#define ull unsigned long long
#define ld long double
#define rep(i, l, r) for (int i = l; i < r; i++)
#define repb(i, r, l) for (int i = r; i > l; i--)
#define sz(a) (int)a.size()
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define pb push_back
#define mp(a, b) make_pair(a, b)
#define ret(a) return cout<<a,0;

using namespace std;

mt19937 mrand(random_device{}()); 
const ll mod=1000000007;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b,ll mod) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}

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

const int N = 2e5 + 123;	
int n, m, h;
int a[N],b[N];
string s;
int dp[N];

main(){
	ios::sync_with_stdio(0); cin.tie(0);cout.tie(0);
	for(int i = 1; i <= 1e5;i++)
		dp[i] = 1e9;
	cin >> n >> h;
	swap(n,h);
	for(int i = 1; i <= n; i++){
		cin >> a[i] >> b[i];
//		swap(a[i],b[i]);
		for(int w = 0; w <= h ;w++){
			if(dp[w + a[i]] > dp[w] + b[i])
				dp[w + a[i]] = dp[w] + b[i];
		}
	}
	int ans = 1e9;
	for(int i = h; i <= 1e5;i++)
		ans = min(ans , dp[i]);
	cout << ans;	
}
	                             


Measured memory_bytes: 3200
N,M=map(int,input().split())


ans=1 if(abs(N-M)<2) else 0
n=max(N,M)

fa=0
for i in range(1,n+1):
    fa=ans
    ans=ans*i%(10**9+7)
    
if(N==M):
    ans=(ans*ans*2)%(10**9+7)
else:
    ans=((ans)*fa)%(10**9+7)
print(ans)

Measured memory_bytes: 3064
import collections
n=int(input())
D=list(map(int,input().split()))
m=max(D)
MOD=998244353
if D[0] != 0:
  print(0)
  exit()
D=collections.Counter(D)
if D[0] >= 2:
  print(0)
  exit()
cnt=1
for i in range(1,m):
  cnt *= D[i] ** D[i+1]
print(cnt % MOD)

Measured memory_bytes: 19928
import java.util.Scanner;

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

		length = sc.nextInt();
		width = sc.nextInt();
		while (width + length != 0) {
			a = new int[length][width];
			for (int i = 0; i < length; i++) {
				for (int j = 0; j < width; j++) {
					a[i][j] = sc.nextInt();
				}
			}
			System.out.println(f(a, width, length, 0));
			length = sc.nextInt();
			width = sc.nextInt();
		}
	}

	public static int f(int a[][], int width, int length, int k) {
		int line, sum = 0;
		int max = 0;
		int change;

		if (length <= k) {
			for (int i = 0; i < width; i++) {
				line = 0;
				for (int j = 0; j < length; j++) {
					line += a[j][i];
				}
				sum += Math.max(line, length - line);
			}
			return sum;
		}

		for (int i = 0; i < width; i++) {
			a[k][i] = (a[k][i] + 1) % 2;
		}
		change = f(a, width, length, k + 1);
		for (int i = 0; i < width; i++) {
			a[k][i] = (a[k][i] + 1) % 2;
		}
		max = Math.max(change, f(a, width, length, k + 1));
		return max;
	}
}

Measured memory_bytes: 13000
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

int cnt[200001];
vector<int> tree[200001];

void dfs(int v, int sum){
    if(tree[v].size() == 0)     return;
    
    for(int i = 0; i < tree[v].size(); ++i){
        int nv = tree[v][i];
        cnt[nv] += sum;
        dfs(nv, cnt[nv]);
    }
}

int main(){
    int n, q;
    cin >> n >> q;
    for(int i = 0; i < n - 1; ++i){
        int a, b;
        cin >> a >> b;
        --a;
        --b;
        tree[a].push_back(b);
    }
    for(int i = 0; i < q; ++i){
        int x, y;
        cin >> x >> y;
        --x;
        cnt[x] += y;
    }

    dfs(0, cnt[0]);
    
    for(int i = 0; i < n; ++i){
        cout << cnt[i] << (i==n-1 ? "\n" : " ");
    }
}

Measured memory_bytes: 23424
n,k=list(map(int,input().split()))
m=list(map(int,input().split()))
a=[]
p=1
vis=[0]*n
while vis[p-1]==0:
    a.append(p)
    vis[p-1]=1
    p=m[p-1]

l=a.index(p)

if k<len(a):
    print(a[k])
else:
    k-=l
    print(a[l+k%(len(a)-l)])

            
            
        
    

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

typedef unsigned long long ull;

int main(){
#ifdef _DEBUG
	freopen("in" , "r", stdin );
	freopen("out", "w", stdout);
#endif
	ios::sync_with_stdio(0); cin.tie(0);
	ull a = 1, b = 1;
	int n; cin >> n;
	for(int i = 0; i < n; i++){
		ull x, y; cin >> x >> y;
		ull l = 1, r = 1e19, s = 1;
		while(l <= r){
			ull m = (l + r) / 2;
			if(x >= (a + m - 1) / m && y >= (b + m - 1) / m){
				s = m;
				r = m - 1;
			} else l = m + 1;
		}
		a = x * s; b = y * s;
	}
	cout << a + b << '\n';
}


Measured memory_bytes: 256
#define __LOCAL_DEBUG__
#include<bits/stdc++.h>
using namespace std;
#ifdef __LOCAL_DEBUG__
# define _debug(x) { cerr << "\033[94m" << __func__ << " " << #x << ": " << (x) << "\n\033[0m"; }
#else
# define _debug(x) {((void) 0);}
#endif
#define REP(i, n) for (int i = (0); i < (n); i++)
#define REPP(i, a, b) for (int i = (a); i < (b); i++)
#define EACH(x, arr) for (auto& x : arr) 
#define ITR(i, c) for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); i++)
#define CLR(x, v) memset(x, v, sizeof (x))
#define ALL(x) x.begin(), x.end()
#define SZ(x) (int) x.size()
template<class T> inline void amin(T &x, const T &y) { if (y<x) x=y; }
template<class T> inline void amax(T &x, const T &y) { if (x<y) x=y; }
using ll = signed long long;
using PII = pair<int, int>;
using VI = vector<int>;
using VVI = vector<VI>;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const int MAXN = 700;

int n, m;
const int N = 105;
int a[N];
void add(int x, int v) {
    for (; x <= n; x += x & -x) a[x] += v;
}
int sum(int x) {
    int ret = 0;
    for (; x; x -= x & -x) ret += a[x];
    return ret;
}
void MAIN() {
    cin >> n;
    VI a(n + 1);
    for (int i = 1; i <= n; i++) cin >> a[i];
    VI answer(n + 1);
    REP(i, n) {
        int find = -1;
        for (int j = n - i; j >= 1; j--) {
            if (a[j] == j) {
                find = j;
                break;
            }
        }
        if (find == -1) { cout << -1 << endl; return; }
        answer[n - i] = find; 
        for (int j = find; j < n - i; j++) a[j] = a[j + 1];
    }
    for (int i = 1; i <= n; i++) cout << answer[i] << endl;
} 

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int TC = 1;
    // cin >> TC;
    REP(tc, TC) {
    // while (cin >> n, n) {
        // cout << "Case " << tc + 1 << ": ";
        MAIN();
    }
    return 0;
}



Measured memory_bytes: 256
import java.util.*;class Main{public static void main(String[]z){Scanner s=new Scanner(System.in);String y="%02d:%02d:%02d\n";for(int i,n,t=3600,r;(n=2-s.nextInt())<3;)for(r=t*n-s.nextInt()*60-s.nextInt(),i=0;i++<2;r*=3)System.out.printf(y,r/t,r%t/60,r%60);}}

Measured memory_bytes: 12000
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)
#define repa(i,n) for (auto& i: n)

template<class T> inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}

#ifdef DEBUG
template <class T, class N> void verr(const T& a, const N& n) { rep(i, n) cerr << a[i] << " "; cerr << "\n" << flush; }
ll dbgt = 1; void err() { cerr << "passed " << dbgt++ << "\n" << flush; }
template<class H, class... T> void err(H&& h,T&&... t){ cerr<< h << (sizeof...(t)?" ":"\n") << flush; if(sizeof...(t)>0) err(forward<T>(t)...); }
#endif

const ll INF = 4e18;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
//--------------------------------------------------------------------------------//

int main() {
    init();
    ll X, K, D;
    cin >> X >> K >> D;

    if (X < 0) X *= -1;

    ll c = X / D;

    chmin(c, K);

    X -= D * c;
    K -= c;

    if (K % 2) X = abs(X - D);

    cout << X << endl;
}

Measured memory_bytes: 3656
#include <cstdio>
#include <functional>
#include <algorithm>
#include <vector>
#include <limits>
#include <numeric>
#include <type_traits>
#include <iostream>
#include <queue>
#include <math.h>
#include <bits/stdc++.h>
#include <queue>
#include <map>

using namespace std;

#define INF (1ll<<60)
#define INFint (1<<30)
#define MOD 1000000007
#define BOUND 27182818284

typedef long long ll;
typedef long long int lli;
typedef pair<int,int> P;

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

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

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

// gcd
template<typename T>
T gcd(T a, T b){
    if(a==0)
        return b;
    return gcd(b%a,a);
}

// gcd array
int findGCD(int arr[], int n){
    int result = arr[0];
    for (int i=1; i < n; i++)
        result = gcd(arr[i], result);
    return result;
}

template<typename T>
T lcm( T m, T n ){
    // 引数に0がある場合は0を返す
    if ( ( 0 == m ) || ( 0 == n ) )
        return 0;
    return ((m/gcd(m, n)) * n); // lcm = m * n / gcd(m,n)
}

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    fill( (T*)array, (T*)(array+N), val );
}


int dx[5]={1,0,-1,0};
int dy[5]={0,1,0,-1};
// v.front() = -BOUND;
// v.back() = BOUND;
int D[101][101];
int main(){
    int H,W,N;
    cin >> H >> W >> N;
    vector<int>a(N);
    rep(i,N){
        cin >> a[i];
    }
    int painted=0;
    int color=0;
    int currentH=0;
    while(true){
        for(int i=0; i < W; i++){
            D[currentH][i]=color+1;
            a[color]--;
            painted++;
            if(a[color]==0)
                color++;
        }
        currentH++;
        if(currentH==H){
            break;
        }
        for(int i=W-1; i>=0; i--){
            D[currentH][i]=color+1;
            a[color]--;
            painted++;
            if(a[color]==0)
                color++;
        }
        currentH++;
        if(currentH==H){
            break;
        }
    }

    rep(i,H){
        rep(j,W){
            cout << D[i][j] << " ";
        }
        cout << endl;
    }
    return 0;
}



Measured memory_bytes: 384
<?php 
  	$index = trim(fgets(STDIN));
	$line = "1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51";
  	$numbers = explode(", ", $line);
	echo $numbers[$index-1];

Measured memory_bytes: 3576
#include <iostream>
#include <algorithm>
#include <string>

using namespace std;



int main(){

  int n,i,j;
  cin >> n;
  int a[n];
  for(i=0;i<n;i++){
    cin >> a[i];
  }
  int b[n];
  for(i=n-1;i>=n/2;i--){
    b[i] = a[i];
  }


  for(i=n/2;i>0;i--){
    int sum = 0;
    int j = 2*i;
    while(j<=n){
      sum += b[j-1];
      j += i;
    }
    b[i-1] = (sum+a[i-1])%2;
  }

  int m=0;
  for(i=0;i<n;i++){
    m += b[i];
  }

  cout << m << endl;
  for(i=0;i<n;i++){
    if(b[i]){
      cout << i+1 << " ";
    }
  }
  cout << endl;

  return 0;

}

Measured memory_bytes: 2432
S = input()
k = "keyence"

res = False

if S[0:7] == k:
    res = True
elif S[-7:0] == k:
    res = True
    
for i in range(1,7):
    if S[0:i] == k[0:i] and S[i-7:] == k[i-7:]:
        res = True
        
if res:
    print("YES")
else:
    print("NO")

Measured memory_bytes: 3060
package main

import (
	"fmt"
)

var n = [4]int{}

func main() {
	fmt.Scanf("%1d%1d%1d%1d", &n[0], &n[1], &n[2], &n[3])
	ans := dfs(1, n[0], fmt.Sprintf("%d", n[0]))
	fmt.Println(ans)
}

func dfs(c, v int, s string) string {
	if c == 4 {
		if v == 7 {
			return fmt.Sprintf("%s=7", s)
		}
		return ""
	}
	a := dfs(c+1, v+n[c], fmt.Sprintf("%s+%d", s, n[c]))
	b := dfs(c+1, v-n[c], fmt.Sprintf("%s-%d", s, n[c]))
	if a != "" {
		return a
	}
	return b
}


Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <sstream>
#include <map>
#include <queue>
#define rep(i,n) for(int i = 0; i < n; i++)
#define rep1(i,n) for(int i = 1; i <= n; i++)
#define co(x) cout << x <<endl
#define cs(x) cout << x <<" "
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
using namespace std;
ll mod = 1e9 + 7;

int main()
{
	int N;
	cin >> N;
	vector<int> h(N);
	rep(i, N) cin >> h[i];
	int ans = 0;
	while (true)
	{
		int bunch = 0;
		rep(i, N)
		{
			if (h[i] != 0 && (h[i+1] == 0 || i == N - 1))
			{
				bunch++;
			}
		}
		rep(i, N)
		{
			if (h[i] > 0)h[i]--;
		}
		ans += bunch;
		if (bunch==0)break;
	}
	co(ans);
	return 0;
}


Measured memory_bytes: 256
#include<iostream>

using namespace std;

const int INF=10000000;
int map[21][21];

int main(void){
	int a,b,c;
	int d[4];
	int ans;
	int n,m;
	for(a=0;a<=20;a++){
		for(b=0;b<=20;b++){
			map[b][a]=INF;
			if(b==a)map[b][a]=0;
		}
	}
	cin >> n;
	cin >> m;
	for(a=0;a<m;a++){
		scanf("%d,%d,%d,%d",&d[0],&d[1],&d[2],&d[3]);
		map[d[0]][d[1]]=d[2];
		map[d[1]][d[0]]=d[3];
	}
	for(a=1;a<=n;a++){
		for(b=1;b<=n;b++){
			for(c=1;c<=n;c++){
				map[a][b]=min(map[a][b],map[a][c]+map[c][b]);
			}
		}
	}
	for(a=1;a<=n;a++){
		for(b=1;b<=n;b++){
			for(c=1;c<=n;c++){
				map[a][b]=min(map[a][b],map[a][c]+map[c][b]);
			}
		}
	}
	scanf("%d,%d,%d,%d",&d[0],&d[1],&d[2],&d[3]);
	ans=d[2]-d[3]-map[d[0]][d[1]]-map[d[1]][d[0]];
	cout << ans <<endl;
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <bitset>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <queue>
#include <functional>

#define mp make_pair
#define pb push_back


typedef long long ll;
typedef long long llong;
typedef long double ld;

using namespace std;

#ifndef LOCAL
#define cerr _cer
struct _cert
{
    template <typename T> _cert& operator << (T) { return *this; }
};
_cert _cer;
#endif

template <typename T> void dprint(T begin, T end) {
    for (auto i = begin; i != end; i++) {
        cerr << (*i) << " ";
    }
    cerr << "\n";
}

int n;
int W;
int w[120];
int v[120];
int dp[120][350];

int main() {
    cin >> n >> W;
    for (int i = 0; i < n; ++i)
        cin >> w[i] >> v[i];
    int ans = 0;
    int mx = 3 * n;
    for (int i = 0; i < n; ++i) {
        int c = w[i] - w[0];
        for (int j = i; j >= 0; --j) {
            for (int k = mx - c; k >= 0; --k)
                dp[j + 1][k + c] = max(dp[j + 1][k + c], dp[j][k] + v[i]);
        }
    }
    for (int i = 1; i <= n; ++i) {
        if (w[0] * i > W)
            break;
        ans = max(ans, dp[i][min(mx, W - w[0] * i)]);
    }
    cout << ans << "\n";
    return 0;
}




Measured memory_bytes: 384
import sys


def problem():
    N = int(input())
    activityList = []
    for i in range(N):
      row = list(map(int, input().split()))
      activityList.append(row)

    print(algorithm(N,activityList))

def algorithm(N, activityList):
  dp = [[0, 0, 0] for i in range(N+ 1)]

  for index in range(1, N + 1):
    for j in range(3):
      for k in range(3):
        if j == k:
          continue
        if dp[index][j] < dp[index - 1][k] + activityList[index-1][j]:
          dp[index][j] = dp[index - 1][k] + activityList[index-1][j]
      
  return max(dp[N])

problem()

Measured memory_bytes: 47332
#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
#define dbg(x) cerr << #x << " = " << x << endl
#define _ << ' ' <<
using namespace std;
using ll = long long;
using vi = vector<int>;

int a[100000];

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i)
        cin >> a[i];

    ll sol = 0;
    for (int i = 0; i < n - 1; ++i)
    {
        sol += a[i] / 2;
        a[i] %= 2;
        int k = min(a[i], a[i + 1]);
        sol += k;
        a[i] -= k;
        a[i + 1] -= k;
    }
    cout << sol + a[n - 1] / 2;
}


Measured memory_bytes: 640
#!/usr/bin/env python3
import sys


def solve(A: int, B: int, K: int):
    diviser = []
    for i in range(1, min(A, B) + 1):
        if A % i == 0 and B % i == 0:
            diviser.append(i)
    diviser.sort(reverse=True)
    print(diviser[K - 1])

    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word

    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    solve(A, B, K)


if __name__ == "__main__":
    main()


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

//#define int long long
#define DBG 1
#define dump(o) if(DBG){cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define each(it,c) for(auto it=(c).begin();it!=(c).end();it++)
#define all(c) c.begin(),c.end()
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);
int N(10010);
signed main() {
	vector<bool>p(N, true); p[0] = p[1] = false;
	for (int i = 2; i < sqrt(N); i++) {
		if (p[i]) {
			for (int j = i + i; j < N; j += i) {
				p[j] = false;
			}
		}
	}
	int n;
	while (cin >> n) {
		int ans(0);
		for (int i = 1; i <= n; i++) {
			if (p[i] && p[n - i + 1])ans++;
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 2980
#include <stdio.h>
int a[100001],b[100000];

int main(void){
  int n,i,x;
  long int output=0;
  scanf("%d",&n);
  for(i=0;i<=n;i++){
    scanf("%d",&a[i]);
  }
  for(i=0;i<n;i++){
    scanf("%d",&b[i]);
  }

  for(i=0;i<n;i++){
    if(a[i]>b[i]) x=b[i];
    else x=a[i];
    b[i] -= x;
    output += x;

    x=0;
    if(a[i+1]>b[i]) x=b[i];
    else x=a[i+1];
    a[i+1] -= x;
    output += x;
  }
  printf("%ld\n",output);
  return 0;
}

Measured memory_bytes: 896
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define pa pair<int,int>
const int Maxn=100010;
const int inf=2147483647;
const int mod=998244353;
int inv2=(mod+1)/2;
int read()
{
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9')x=(x<<3)+(x<<1)+(ch^48),ch=getchar();
	return x*f;
}
int Pow(int x,int y)
{
	if(!y)return 1;
	int t=Pow(x,y>>1),re=(LL)t*t%mod;
	if(y&1)re=(LL)re*x%mod;
	return re;
}
unordered_map<int,int>mp[Maxn];
int n,m;
struct P{int x,y;}p[Maxn];
int main()
{
	n=read(),m=read();
	for(int i=1;i<=m;i++)
	{
		p[i].x=read(),p[i].y=read();
		mp[p[i].x][p[i].y]=read()+1;
	}
	int ans=1;
	for(int i=1;i<=m;i++)
	{
		int t=abs(p[i].x-p[i].y);
		if(t!=2)continue;
		int z=(p[i].x+p[i].y)/2;
		if(mp[p[i].y][p[i].x])
		{
			int v=(mp[p[i].x][p[i].y]+mp[p[i].y][p[i].x])&1;
			if(!mp[z][z])mp[z][z]=v+1;
			else if(mp[z][z]-1!=v)return puts("0"),0;
			if(p[i].x>p[i].y)ans=(LL)ans*inv2%mod;
		}
		else ans=(LL)ans*inv2%mod; 
	}
	for(int i=2;i<=n;i++)
	if(mp[i-1][i-1]&&mp[i-1][i]&&mp[i][i-1])
	{
		int v=(mp[i-1][i-1]+mp[i-1][i]+mp[i][i-1]-3)&1;
		if(mp[i][i])
		{
			if(mp[i][i]-1!=v)return puts("0"),0;
		}
		else mp[i][i]=v+1;
	}
	
	for(int i=n-1;i;i--)
	if(mp[i+1][i+1]&&mp[i+1][i]&&mp[i][i+1])
	{
		int v=(mp[i+1][i+1]+mp[i+1][i]+mp[i][i+1]-3)&1;
		if(mp[i][i])
		{
			if(mp[i][i]-1!=v)return puts("0"),0;
		}
		else mp[i][i]=v+1;
	}
	for(int i=2;i<=n;i++)
	{
		int t=0;
		if(!mp[i][i])t++;
		if(!mp[i-1][i])t++;
		if(!mp[i][i-1])t++;
		if(i==2&&!mp[1][1])t++;
		ans=(LL)ans*Pow(2,max(0,t-1))%mod;
	}
//	printf("%d\n",ans);
	for(int i=1;i<=n-2;i++)ans=(LL)ans*Pow(2,i)%mod;
	
	int cnt=0;
	for(int i=1;i<=m;i++)
	{
		int t=abs(p[i].x-p[i].y);
		if(t<3)continue;
		if(mp[p[i].y][p[i].x])
		{
			if(mp[p[i].x][p[i].y]!=mp[p[i].y][p[i].x])return puts("0"),0;
			if(p[i].x>p[i].y)cnt++;
		}
		ans=(LL)ans*inv2%mod;
	}
	ans=(LL)ans*Pow(2,cnt)%mod;
	printf("%d",ans);
}

Measured memory_bytes: 26368
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <bitset>
using namespace std;

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	long N;
	cin >> N;
  	long Array[N];
  	int idx = 0;
  	while(cin >> Array[idx]) idx++;
  	int count = 0;
  	for(int i = 0; i< N;i++)
    {
      long key = Array[i];
      for(int j=N-1;j>=i+1;j--)
      {
        if(Array[j] < Array[j-1])
        {
          long tmp = Array[j];
          Array[j] = Array[j-1];
          Array[j-1] = tmp;
          count++;
        }
      }
    }
	for(int i=0;i<N-1;i++)
    {
      cout << Array[i] << " ";
    }
  	cout << Array[N-1] << endl;
  	cout << count << endl; 
  	return 0;
}



Measured memory_bytes: 3164
#include <bits/stdc++.h>
#define ll long long int
#define MOD 1000000007
#define INF 1e18
#define PI 3.14159265358979

using namespace std;

ll power(ll n, ll k);
ll inv(ll n);
ll genfact(ll n, ll k);
ll fact(ll n);
ll nck(ll n, ll k);

int main(void){
  int n, k;
  cin >> n >> k;

  if ((n - 2)*(n - 1)/2 < k){
    cout << -1 << endl;
    return 0;
  }

  cout << n * (n - 1)/2 - k << endl;
  int t = 0;
  for (int i = n; i > 0; i--){
    for (int j = i - 1; j > 0; j--){
      cout << i << " " << j << endl;
      t++;
      if (t == n * (n - 1)/2 - k)
        break;
    }
    if (t == n * (n - 1)/2 - k)
      break;
  }

  return 0;
}


ll power(ll n, ll k){
  ll res = 1;
  while(k > 0){
    if (k & 1) 
      res = res * n % MOD;
    n = n * n % MOD;
    k >>= 1;
  }
  return res;
}

ll genfact(ll n, ll k){

  ll res = 1;
  while (k >= 0){
    res = (res * (n - k)) % MOD;
    k--;
  }

  return res;
}

ll inv(ll n){
  return power(n, MOD - 2);
}

ll fact(ll n){
  return genfact(n, n - 1);
}

ll nck(ll n, ll k){
  if (k == 0)
    return 1;

  return ((genfact(n, k) % MOD) * inv(fact(k))) % MOD;
}






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

int n, d, x, a;
int c;

int main(){
    cin >> n >> d >> x;
    for(int i = 0; i < n; i++){
        cin >> a;
        c = c + 1 + (d - 1) / a;
    }
    cout << c + x << endl;
    return 0;
}

Measured memory_bytes: 256
import bisect
w=20000000001
a,b,q=map(int,input().split())
s=[int(input()) for i in range(a)]
t=[int(input()) for i in range(b)]
#bisect.bisect_left

for i in range(q):
    x=int(input())
    ans=w
    tmp=x
    ls=bisect.bisect_left(s,tmp)
    lt=bisect.bisect_left(t,tmp)
    if (s[ls-1]<=tmp and t[lt-1]<=tmp): ans=min(ans,tmp-min(s[ls-1],t[lt-1]))
    if (s[ls-1]<=tmp and lt<b and t[lt]>=tmp): ans=min(ans,(tmp-s[ls-1])+(t[lt]-s[ls-1]),(t[lt]-tmp)+(t[lt]-s[ls-1]))
    if (ls<a and s[ls]>=tmp and t[lt-1]<=tmp): ans=min(ans,(tmp-t[lt-1])+(s[ls]-t[lt-1]),(s[ls]-tmp)+(s[ls]-t[lt-1]))
    if (ls<a and lt<b and s[ls]>=tmp and t[lt]>=tmp): ans=min(ans,max(s[ls],t[lt])-tmp)
    print(ans)

Measured memory_bytes: 12100
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef int ll;
typedef long double ld;
const ll N = 50005;
char en = '\n';
ll inf = 1e16;
ll mod = 1e9 + 7;
ll power(ll x, ll n, ll mod) {
  ll res = 1;
  x %= mod;
  while (n) {
    if (n & 1)
      res = (res * x) % mod;
    x = (x * x) % mod;
    n >>= 1;
  }
  return res;
}

struct node {
  ll s, t, x;
  node() {}
  node(ll s, ll t, ll x) : s(s), t(t), x(x) {}
};

struct node2 {
  ll indx, d;
  node2() {}
  node2(ll indx, ll d) : indx(indx), d(d) {}
};
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  ll n, q;
  cin >> n >> q;

  node arr[n + 5];
  map<ll, ll> par;
  for (ll i = 1; i <= n; i++) {

    ll s, t, x;
    cin >> s >> t >> x;
    t--;
    arr[i] = node(s, t, x);
    par[s - x];
    par[t - x];
  }

  ll arr2[q + 5];
  for (ll i = 1; i <= q; i++) {
    cin >> arr2[i];
    par[arr2[i]];
  }

  ll cnt = 0;
  for (auto &it : par)
    it.second = ++cnt;

  vector<node> event1[par.size() + 5];
  vector<node2> event2[par.size() + 5];
  vector<node> event3[par.size() + 5];

  for (ll i = 1; i <= n; i++) {

    event1[par[arr[i].s - arr[i].x]].push_back(arr[i]);

    event3[par[arr[i].t - arr[i].x]].push_back(arr[i]);
  }

  for (ll i = 1; i <= q; i++) {

    event2[par[arr2[i]]].push_back(node2(i, arr2[i]));
  }
  ll res[q + 5];
  map<ll, ll> par2;
  for (ll i = 1; i <= par.size(); i++) {
    for (node &curr : event1[i]) {
      par2[curr.x]++;
    }

    for (node2 &curr : event2[i]) {
      if (par2.size() == 0)
        res[curr.indx] = -1;
      else
        res[curr.indx] = par2.begin()->first;
    }
    for (node &curr : event3[i]) {
      par2[curr.x]--;
      if (par2[curr.x] == 0)
        par2.erase(curr.x);
    }
  }
  for (ll i = 1; i <= q; i++)
    cout << res[i] << en;

  return 0;
}

/*
1
11 5 8 3 4
NEESSWWNESE
 */

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

int main() {
  string A;
  int count = 0;
  cin >> A;
  
  for (int i = 0; i < 3; i++) {
    if (A.at(i) == '1'){
      count++;
    }
  }
  
  cout << count << endl;
  
}


Measured memory_bytes: 256
N = int(input())
S = [input() for i in range(N)]
ac = 0
wa = 0
tle = 0
re = 0
for s in S:
    if s == "AC":
        ac += 1
    if s == "TLE":
        tle += 1
    if s == "WA":
        wa += 1
    if s == "RE":
        re += 1
print("AC x {0}".format(ac))
print("WA x {0}".format(wa))
print("TLE x {0}".format(tle))
print("RE x {0}".format(re))

Measured memory_bytes: 16160