akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;
using ii  = pair<int, int>;
using vii = vector<ii>;

int const NMAX = 1e5 + 11;

int n, color[NMAX];
vii g[NMAX];

void dfs(int u, int p = -1, int d = 0)
{
    color[u] = d;
    for (auto [v, c] : g[u])
    {
        if (v == p)
            continue;
        dfs(v, u, (d + c) % 2);
    }
}

int main(void)
{
    int u, v, c;
    cin >> n;

    for (int i = 0; i < n - 1; ++i)
    {
        cin >> u >> v >> c, --u, --v;
        g[u].emplace_back(v, c);
        g[v].emplace_back(u, c);
    }

    dfs(0);

    for_each(color, color + n, [](int x) { cout << x << endl; });
    return 0;
}


Measured memory_bytes: 11388
import java.util.*;
class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int[] S = new int[N];
    
    for (int i = 0; i < N; i++){
 		S[i] = sc.nextInt();     
    }
    String message = "APPROVED";
    for (int j = 0; j < N; j++){
    	if(S[j] %2 == 0){
  			if (S[j] %3 != 0 && S[j] %5 != 0){
             	message = "DENIED";  break;
            }
        }
     
    
    }
     System.out.println(message);
  }
}


Measured memory_bytes: 36004
#include <iostream>
#include <climits>
#include <stack>
#include <queue>
#include <string>
#include <utility>
#include <string.h>
#include <iomanip>
#include <stdlib.h>
#include <algorithm>
using namespace std;
typedef pair<int, int> P;
const int INF = 100000000;
char maze[51][51];
int d[50][50];
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };

int bfs(int H,int W) {
	int i, j, k, l, m, nx, ny;
	queue<P> que;
	for (i = 0; i < 50; i++) {
		for (j = 0; j < 50; j++) {
			d[i][j] = INF;
		}
	}
	que.push(P(0, 0));
	d[0][0] = 0;
	while (que.size()) {
		P p = que.front();
		que.pop();
		if (p.first == 49 && p.second == 49)
			break;
		for (i = 0; i < 4; i++) {
			nx = p.first + dx[i];
			ny = p.second + dy[i];

			if (nx >= 0 && nx < H&&ny >= 0 && ny < W&&d[nx][ny] == INF && maze[nx][ny] != '#') {
				que.push(P(nx, ny));
				d[nx][ny] = d[p.first][p.second] + 1;
			}
		}
	}
	return d[H-1][W-1];
}



int main()
{
	int H, W,black;
	cin >> H >> W;
	int i, j, k;
  black=0;
	for (i = 0; i < H; i++) {
		for (j = 0; j < W; j++) {
			cin >> maze[i][j];
          if(maze[i][j]=='#')black++;
		}
	}
	k = bfs(H, W);
	if (k == INF)
		cout << "-1" << endl;
	else
		cout << H * W - k-black-1 << 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 k = sc.nextInt();
    int[] box = new int[k];
    int n = 7 % k;
    int ans = 1;
    while (true) {
      if (n == 0) {
        System.out.println(ans);
        break;
      } else if (box[n] == 1) {
        System.out.println("-1");
        break;
      }
      box[n] = 1;
      n = (n * 10 + 7) % k;
      ans++;
    }
  }
}


Measured memory_bytes: 39728
from collections import defaultdict
N=int(input())
A=list(map(int,input().split()))
dic=defaultdict(int)
for i in range(0,N):
    dic[A[i]]+=1

ans=0
for key in dic.keys():
    if dic[key]>=key:
        ans+=dic[key]-key
    else:
        ans+=dic[key]

print(ans)


Measured memory_bytes: 68776
#include<bits/stdc++.h>
using namespace std;
#define int long long int 
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define vi vector<int>
#define pi pair<int,int>
#define all(v) v.begin(),v.end()
#define zeros(arr) memset(arr,0,sizeof(arr));
#define precise(num)  cout<<fixed; cout << std::setprecision(num)
#define nl cout<<"\n";
int32_t main(){
    int n,m;
    cin>>n>>m;
    int sum = 0;
    for(int i =0 ; i< m;i++){
        int x;cin>>x;
        sum+=x;
    }
    int res = n - sum;
    if(res<0)cout<<-1<<endl;
    else cout<<res<<endl;
    
}

Measured memory_bytes: 3620
import math
import numpy as np

def cmb(n, r, mod):
  r = min(r, n-r)
  return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 
N = 10**6
g1 = [1, 1] 
g2 = [1, 1] 
inverse = [0, 1] 

for i in range( 2, N + 1 ):
  g1.append( ( g1[-1] * i ) % mod )
  inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
  g2.append( (g2[-1] * inverse[-1]) % mod )

x,y = map(int,input().split()) 

if (x+y) % 3 == 0:

  A = np.array([[1, 2],[2, 1]])
  b = np.array([x, y])
  N = np.linalg.solve(A, b)
  if N[0].is_integer() == True and N[1].is_integer() == True and N[0] >=0 and N[1] >=0:
      print(cmb(int(N[0]+N[1]),int(N[0]),mod))
  else:
      print(0)
else:
  print(0)

Measured memory_bytes: 133884
#include<bits/stdc++.h>
using namespace std;
//#define limit 400001
main()
{
    int q;
    long long int n,p;
    deque <int> A;
    cin>>q;
    while(q--)
    {
    cin>>n;
    if(n==0)
    {
        int d;
        cin>>d>>p;
        if(d==0)
            A.push_front(p);
        else
            A.push_back(p);
    }
    else if(n==1)
    {
        cin>>p;
        cout<<A[p]<<endl;
    }
    else if(n==2)
    {
        int e;
        cin>>e;
        if(e==0)
            A.pop_front();
        else
        A.pop_back();
    }

    }
}




Measured memory_bytes: 4668
#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 ALL(v) v.begin(), v.end()
#define downque(que) priority_queue<ll> que;
#define upque(que) priority_queue<ll, vector<int>, greater<int>> que;
typedef long long ll;
typedef vector<vector<int>> Matrix;
const int MOD = 1e9 + 7;
const int MAX = 1e7;
const int INF = numeric_limits<int>::max();





int main(){
  int n,res=0; cin>>n; 
  string s; cin>>s;
  bool flag[3]={0};
 REP(i,10){
   REP(j,10){
     REP(k,10){
	  bool flag[3]={0};
       REP(x,n){
         
         int num=s[x]-'0';
         if(i==num&&!flag[0])flag[0]=1;
         else if(j==num&&!flag[1]&&flag[0])flag[1]=1;
         else if(k==num&&!flag[2]&&flag[1]){flag[2]=1;break;}
       }
       if(flag[2]){
         res++;
       //cout<<i<<" "<<j<<" "<<k<<" "<<endl;
       }
     }
   }
 }

cout<<res<<endl; 

}

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

int main()
{
	int n;
	for (cin >> n; n; n--) {
		vector<int> tri;
		for (int i = 0; i < 3; i++) {
			int a;
			cin >> a;
			tri.push_back(a);
		}
		sort(tri.begin(), tri.end());
		cout << (pow(tri[2], 2) == pow(tri[1], 2) + pow(tri[0], 2) ? "YES" : "NO") << endl;
	}

	return 0;
}

Measured memory_bytes: 1208
#include<map>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
using namespace std;
long long k,i,n,a[20000],sum;
int main(){
	scanf("%lld",&n);
	for(i=0;i<n;i++){
		scanf("%lld",&a[i]);
		k=a[i];
	    while(k%2==0){
	    	k/=2;
	    	sum++;
		}
	}
	printf("%lld",sum);
}

Measured memory_bytes: 384
#pragma GCC optimize("Ofast")
#include<stdio.h>
int main(void)
{
  char buf[400002];
  int i = 0;
  while(1) if(EOF == (buf[++i] = getchar_unlocked())) break;
  int ans = 0;
  i >>= 1;
  char* x = buf + i;
  while(--i) ans += buf[i] != x[i];
  printf("%d", ans);
}


Measured memory_bytes: 1992
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> pii;
const ll INF = 1e9+100;
const ll MOD = 1e9+7;
const bool debug = 0;
//-----------------------------------------------//

void func(int cnt, bool flip) {
	char c[2] = {'.', '#'};
	REP(i, 50) {
		REP(j, 100) {
			if (i & j & 1) {
				if (cnt) { putchar(c[flip^1]); cnt--; }
				else putchar(c[flip]);
			}
			else putchar(c[flip]);
		}
		puts("");
	}
}

int main() {
	int A, B; cin >> A >> B;
	
	if (A == 0 && B == 1) puts("1 1\n#");
	else if (A == 1 && B == 0) puts("1 1\n.");
	else {
		puts("100 100");
		bool flip = false;
		if (A > B) {
			swap(A, B);
			flip = true;
		}
		func(B - 1, flip);
		func(A - 1, flip^1);
	}
	
	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 n=sc.nextInt();
        long t;
        long a;
        long anst=1;
        long ansa=1;
        long tmp;
        for(int i=0;i<n;i++){
            t=sc.nextInt();
            a=sc.nextInt();
            tmp=Math.max((anst-1)/t+1, (ansa-1)/a+1);
            anst=t*tmp;
            ansa=a*tmp;
        }
        System.out.println(anst+ansa);
    }
    
    
}

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

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t=1,i,j;
   // cin>>t;
    while(t--)
    {
        int n,m,k,a,b,count=0,sum=0,maxi=0,mini=1e18;
        double x;
        cin>>x;
        
        int cnt=0;
        n=100;
        while(n<x)
        {
            cnt++;
            n=n*(1+(0.01));
        }
        cout<<cnt;
    }
}

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

#define ll long long int

ll dp[100][100001];

int main(){
	ll n,w,i,j;
	cin>>n>>w;
	pair <ll,ll> p[n];
	for(i=0;i<n;i++){
		cin>>p[i].first>>p[i].second;
	}
	sort(p,p+n);
	for(i=0;i<n;i++)
		dp[i][0]=0;
	for(i=1;i<=w;i++){
		if(i<p[0].first)
			dp[0][i]=0;
		else
			dp[0][i]=p[0].second;
	}
	for(i=1;i<n;i++){
		for(j=1;j<=w;j++){
			if(j<p[i].first)
				dp[i][j]=dp[i-1][j];
			else{
				dp[i][j]=max(dp[i-1][j],p[i].second+dp[i-1][j-p[i].first]);
			}
		}
	}
	cout<<dp[n-1][w];
}


Measured memory_bytes: 81672
n=int(input())
a=list(map(int,input().split()))


a

import collections
pair_list=collections.Counter(a).most_common()

mass=0
for pair in pair_list:
        mass+=pair[1]*(pair[1]-1)/2

d={str(s[0]): s[1]-1  for s in pair_list}

for  k in range(1,n+1):
    print(int(mass-d[str(a[k-1])]))

Measured memory_bytes: 41464
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace std;
using namespace __gnu_pbds; 
#define ll          long long int
#define ull         unsigned long long int
#define pb          push_back
#define pii         pair<int,int>
#define F           first
#define S           second
#define vi          vector<int>
#define vli          vector<ll>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define M_PI        3.14159265358979323846
#define mp          make_pair
#define sz(x)       (int)x.size()
#define matrix      vector<vector<ll>>
#define forn(i,a,b)  for(int i=a;i<b;i++)
#define eps 0.0000000001
#define all(a)      (a).begin(),(a).end()
#define ordered_set     tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> 

const long long INF = (long long) 1e11+1;
const long long mod = (long long) 100000000 ;
const long long hell = (long long) 1000000007;


ll power(ll x,ll y)
{
  ll res=1;
  while(y>0){
    if(y%2) res=(x%mod*res%mod)%mod;
    x=(x%mod*x%mod)%mod;    
    y=y/2;
  }
  return res;
}

ll modinv(ll x){
  return power(x,mod-2);
}

void solve();


void fastIO() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}

ll gcd(ll a,ll b)
{
    while( b != 0)
	{
		ll  t = b;
		b= a %t;
		a = t;
	}
	return a;
}

int main(){
   fastIO();
   int test;
   //cin>>test;
   test=1;
   
   while(test--)
   solve();
}



void solve(){
    ll k;
    int n;
    cin>>k>>n;
    ll a[n];
    forn(i,0,n)
    cin>>a[i];
    ll ans=INT_MAX;
    forn(i,1,n){
       ans=min(ans,k-(a[i]-a[i-1]));
    }
    ll x=k-a[n-1];
    x+=a[0];
    ans=min(ans,k-x);
    cout<<ans;
}    


///Before submit=>
///    *check for integer overflow,array bounds
///    *check for n=1

/*
  For freq or prime factors

for(auto pri:prime){
  while(k%pri==0){
    pcnt[pri]++;
    k/=pri;
  }
}*/
// gcd of strings
/*
string getgcd(string s1,string s2){
    
    while(true){
        if(s1.length()<s2.length()){
            swap(s1,s2);
            continue;
        }
        if(s2.empty())
        return s1;
        
        if(s1.substr(0,s2.length())!=s2)
        return "";
        
        s1=s1.substr(s2.length());
    }
}
*/
/*
// for user defined DS hashmap and set
 
struct hash_pair{
      size_t operator()(const pair<int,pair<int,int>>& p) const{
          auto hash1=hash<int>()(p.F) ;
          auto hash2=hash<int>()(p.S.F) ;
          auto hash3=hash<int>()(p.S.S) ;
          return (hash1^hash2)^hash3;
      }  
};
struct pair_hash
{
	template <class T1, class T2>
	std::size_t operator () (std::pair<T1, T2> const &pair) const
	{
		std::size_t h1 = std::hash<T1>()(pair.first);
		std::size_t h2 = std::hash<T2>()(pair.second);

		return h1 ^ h2;
	}
};
*/



Measured memory_bytes: 1792
#include <iostream>
#include <bitset>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <cmath>
#include <regex>
using namespace std;
using ll = long long int;
using dd = long double;
const ll MOD = 1e9 + 7;

vector<string> dfs(string s, ll depth, vector<char> symbol)
{
    vector<string> ret;
    if (depth == 0)
    {
        ret.push_back(s);
        return ret;
    }

    for (ll i = 0; i < symbol.size(); i++)
    {
        auto vec = dfs(s + symbol[i], depth - 1, symbol);
        for (auto &&e : vec)
        {
            ret.push_back(e);
        }
    }
    return ret;
}

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

int main()
{
    ll A, B, C;
    cin >> A >> B >> C;
    cout << (A + B >= C ? "Yes" : "No") << endl;
}

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

using namespace std;

using ll = long long;
using ld = long double;

const int INF = (1 << 30) - 1;
const ll INF64 = ((ll)1 << 62) - 1;
const double PI = 3.1415926535897932384626433832795;

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

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

	int n;
	cin >> n;

	priority_queue<int, vector<int>, greater<int>> pq;
	for (int i = 0; i < 2 * n; i++) {
		int l;
		cin >> l;

		pq.emplace(l);
	}

	int ans = 0;
	while (!pq.empty()) {
		int a = pq.top(); pq.pop();
		int b = pq.top(); pq.pop();
		ans += min(a, b);
	}

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


Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<iomanip>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<algorithm>
#include<string>
#include<math.h>
#include<numeric>
#include<complex>

using namespace std;
typedef long long ll;

#define REP(i,n) for(int i=0;i<n;++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define pn(s) cout << (#s) << " " << (s) << endl

const ll mod = 1e9 + 7;
const ll inf = 1e18;

void printVector(vector<ll> A){
    cout << "[vector]" << endl;
    for(int i=0; i<A.size(); i++){
        cout << A[i] << " ";
    }
    cout << endl;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    // input
    int A, B;
    cin >> A >> B;
    
    int rest = A * B - A - B + 1;

    p(rest);
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
  using namespace std;
#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) cin>>aa;(p).push_back(aa);
#define vecpl2(p) long long a	b;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define set0(k,n) for(int nn=0;nn<(n);nn++){ (k).push_back(0); }
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define vecsize(b,size) vector<int> (b)((size));
#define pb(b,a) (b).push_back((a));
#define doublece(a,b) cout<<(a)<<' '<<(b)<<endl;
#define pairs(s) vector<pair<int,int>> (s);
#define pairsl(s) vector<pair<ll,ll>> (s);
#define pairss(s) vector<pair<string,string>> (s);
#define pairsp(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairspl(s) ll aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsps(s) string aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsREV(s) (s).push_back(make_pair(bb,aa));
#define pairslREV(s) (s).push_back(make_pair(bb,aa));
#define pairssREV(s) (s).push_back(make_pair(bb,aa));
#define MOD 1000000007

int main() {
	
	int N;
	cin>>N;
	vecl(A)
	fx(N){
		vecpl(A)
	}

	if(A.at(0)==0){
		ll ans1=1,ans2=1;
		vecl(B)
		fx(N){
		pb(B,A.at(x))
		}
		A.at(0)=1;
		B.at(0)=-1;
		fyg(N,1){
			A.at(y)+=A.at(y-1);
			if(A.at(y)*A.at(y-1)>=0){
				ans1+=abs(A.at(y))+1;
				if(A.at(y-1)<0){
					A.at(y)=1;
				}else{
					A.at(y)=-1;
				}
			}
		}
		fyg(N,1){
			B.at(y)+=B.at(y-1);
			if(B.at(y)*B.at(y-1)>=0){
				ans2+=abs(B.at(y))+1;
				if(B.at(y-1)<0){
					B.at(y)=1;
				}else{
					B.at(y)=-1;
				}
			}
		}
		ce(min(ans1,ans2))
	}else{
		ll ans1=0,ans2=0;
		vecl(B)
		fx(N){
		pb(B,A.at(x))
		}
      ans2=abs(B.at(0))+1;
      if(B.at(0)<0){
        B.at(0)=1;
      }else{
         B.at(0)=-1;
      }
		fyg(N,1){
			A.at(y)+=A.at(y-1);
			if(A.at(y)*A.at(y-1)>=0){
				ans1+=abs(A.at(y))+1;
				if(A.at(y-1)<0){
					A.at(y)=1;
				}else{
					A.at(y)=-1;
				}
			}
		}
		fyg(N,1){
			B.at(y)+=B.at(y-1);
			if(B.at(y)*B.at(y-1)>=0){
				ans2+=abs(B.at(y))+1;
				if(B.at(y-1)<0){
					B.at(y)=1;
				}else{
					B.at(y)=-1;
				}
			}
		}
		ce(min(ans1,ans2))
	}

}

Measured memory_bytes: 2548
#include <iostream>

using namespace std;

int main() {
   int n;
   cin>>n;
   int ara[n];
   long long ans=0;
   for(int i=0;i<n;i++){
       cin>>ara[i];
       if(i){
           if(ara[i]<ara[i-1]){
               ans+=ara[i-1]-ara[i];
               ara[i]=ara[i-1];
           }
       }
   }
   cout<<ans<<endl;
    
    
}

Measured memory_bytes: 4356
/*Shivam Bhalla */
/* f2016941@pilani.bits-pilani.ac.in */

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cctype>
#include <algorithm>
#include <map>
#include <vector>
#include <list>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <iostream>
#include <string>
#include <cmath>
#include <cassert>
#include <bits/stdc++.h>
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL)
using namespace std;
long long maxv = 1e9;

int main(){
	int N;
	cin>>N;
	vector<int>V(N);
	vector<int>C(N);
	for(int i=0;i<N;i++)
		cin>>V[i];
	for(int i=0;i<N;i++)
		cin>>C[i];
	int total=0;
	for(int i=0;i<N;i++){
		if((V[i]-C[i])>0)
			total+=(V[i]-C[i]);
	}
	cout<<total;	
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define x first
#define y second
#define all(v) v.begin(), v.end()
#define compress(v) sort(all(v)), v.erase(unique(all(v)), v.end())
using namespace std;

typedef long long ll;

int n, a[101010], res[101010];

int valid(int t1, int t2, int t3){
    res[1] = t1; res[2] = t2; res[3] = t3;
    for(int i=3; i<n; i++){
        if(res[i]){
            if(a[i]) res[i+1] = res[i-1];
            else res[i+1] = !res[i-1];
        }
        else{
            if(!a[i]) res[i+1] = res[i-1];
            else res[i+1] = !res[i-1];
        }
    }
    for(int i=1; i<=n; i++){
        int j = i-1 > 0 ? i-1 : n;
        int k = i+1 <= n ? i+1 : 1;
        if(res[i]){
            if(a[i] && res[j] != res[k]) return 0;
            if(!a[i] && res[j] == res[k]) return 0;
        }
        else{
            if(!a[i] && res[j] != res[k]) return 0;
            if(a[i] && res[j] == res[k]) return 0;
        }
    }
    for(int i=1; i<=n; i++) cout << (res[i] ? 'S' : 'W');
    return 1;
}

int main(){
    ios_base::sync_with_stdio(false); cin.tie(nullptr);
    cin >> n;
    for(int i=1; i<=n; i++){
        char c; cin >> c; a[i] = c == 'o';
    }
    
    for(int i=0; i<2; i++) for(int j=0; j<2; j++) for(int k=0; k<2; k++) {
        if(valid(i, j, k)) return 0;
    }
    cout << -1;
}

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

using namespace std;

namespace {

    /** whole range */
    #define whole(xs) (xs).begin(), (xs).end()

    struct Graph {
        static const int INF = 1<<28;
        struct Edge {
            int to, cap;
            Edge* rev;
        };
        vector<vector<Edge*>> vs;
        vector<int> level, iter;
        Graph(int v) { 
            vs = vector<vector<Edge*>>(v); 
            level = vector<int>(v);
            iter = vector<int>(v);
        }
        ~Graph() {
            for (auto& v : vs) for (auto& e : v) {
                delete(e);
            }
        }
        void addEdge(int from, int to, int cap) {
            auto e = new Edge();
            auto rev = new Edge();
            e->to = to; e->cap = cap; e->rev = rev;
            rev->to = from; rev->cap = 0; rev->rev = e;
            vs[from].push_back(e);
            vs[to].push_back(rev);
        }

        void bfs(int s) {
            fill(whole(level), -1);
            queue<int> Q;
            level[s] = 0;
            Q.push(s);
            while (not Q.empty()) {
                auto i = Q.front(); Q.pop();
                for (auto& e : vs[i]) {
                    if (e->cap > 0 and level[e->to] < 0) {
                        level[e->to] = level[i] + 1;
                        Q.push(e->to);
                    }
                }
            }
        }

        int dfs(int v, int t, int f) {
            if (v == t) return f;
            auto& i = iter[v];
            for (; i < vs[v].size(); i++) {
                auto& e = vs[v][i];
                if (e->cap > 0 and level[v] < level[e->to]) {
                    auto d = dfs(e->to, t, min(f, e->cap));
                    if (d > 0) {
                        e->cap -= d;
                        e->rev->cap += d;
                        return d;
                    }
                }
            }
            return 0;
        }
        
        int maxFlow(int s, int t) {
            auto flow = 0;
            while (true) {
                bfs(s);
                if (level[t] < 0) return flow;
                fill(whole(iter), 0);
                while (true) {
                    auto f = dfs(s, t, INF);
                    if (f <= 0) break;
                    flow += f;
                }
            }
        }
    };

    int V, E;
    Graph* g;
    void input() {
        cin >> V >> E;
        g = new Graph(V);
        for (auto i = 0; i < E; i++) {
            int u, v, c;
            cin >> u >> v >> c;
            g->addEdge(u, v, c);
        }
    }

    void solve() {
        cout << g->maxFlow(0, V - 1) << endl;
        delete(g);
    }
}

int main() {
    input(); solve();
    return 0;
}

Measured memory_bytes: 3160
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    n = int(readline())
    a = list(map(int, readline().split()))
    b = list(map(int, readline().split()))

    cnt = 0
    for x, y in zip(a, b):
        diff = x - y
        if diff < 0:
            cnt += abs(diff) // 2

    for x, y in zip(a, b):
        diff = x - y
        if diff > 0:
            cnt -= diff

    if cnt >= 0:
        print("Yes")
    else:
        print("No")


if __name__ == '__main__':
    main()


Measured memory_bytes: 73576
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main() {
	//min(a,b)...a,bの小さいほう
	//max(a,b)...     大きいほう
	int a;
	int b;
	//int c;
	//int d;
	int e;
	cin >> a >> b;
	//string s;
	//std::cin >> s;
	if ((a + b) % 2 == 0) {
		cout << (a + b) / 2 << "\n";
	}
	else {
		cout << (a + b) / 2 + 1 << "\n";
	}
	std::cin >> e;
}

Measured memory_bytes: 256
///スマホコーディング
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
typedef long long ll;
const int inf=1e9;
int main(){
  int n=0;
  rep(i,0,4){
    char c;cin>>c;
    if(c=='+')n++;
    else n--;
  }
  cout<<n<<endl;
  return 0;
}


Measured memory_bytes: 256
N = gets.to_i
ts = gets.split.map(&:to_i)
M = gets.to_i
ps, xs = [], []
M.times do |i|
    ps[i], xs[i] = gets.split.map(&:to_i)
end

sum = ts.inject(:+)

M.times do |i|
    puts sum - ts[ps[i] - 1] + xs[i]
end

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

int digit(long long x){
    int wa;
    while(x > 0){
        wa += x % 10;
        x/= 10;
    }
    return wa;
}

int main(){
    long long N,sumN;
    cin >> N;
    sumN = digit(N);
    if(N % sumN == 0)
        cout << "Yes" << endl;
    else 
        cout << "No" << endl;
}

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

int cmp1(const void *,const void *);
int cmp2(const void *,const void *);

int
main()
{
  	int n,m;
  	scanf("%d %d",&n,&m);
  	int x[m];
  	int i;
  	int goukei=0;
	int margin[m-1];
 	
  	if(m==1){
      	goukei=0;
        goto NEXT;
    }
  
  	for(i=0;i<m;i++){
      	scanf("%d",&x[i]);
    }
  	qsort(x,sizeof(x)/sizeof(int),sizeof(int),cmp1);
  
  	for(i=0;i<m-1;i++){
      	margin[i]=x[i+1]-x[i];
    }

  
  	qsort(margin,sizeof(margin)/sizeof(int),sizeof(int),cmp2);

  	
  	for(i=n-1;i<m-1;i++){
      	goukei += margin[i];
    }
  
  NEXT:
  	printf("%d",goukei);
  
  	return 0;
  
}

int
cmp1(const void *a,const void *b){
	return *(int *)a-*(int *)b;
}

int
cmp2(const void *a,const void *b){
	return *(int *)b-*(int *)a;
}
      
      
      
      
      
      
  

Measured memory_bytes: 1268
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <time.h>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <string.h>
#define sf scanf
#define pf printf
#define lf double
#define ll long long
#define p123 printf("123\n");
#define pn printf("\n");
#define pk printf(" ");
#define p(n) printf("%d",n);
#define pln(n) printf("%d\n",n);
#define s(n) scanf("%d",&n);
#define ss(n) scanf("%s",n);
#define ps(n) printf("%s",n);
#define sld(n) scanf("%lld",&n);
#define pld(n) printf("%lld",n);
#define slf(n) scanf("%lf",&n);
#define plf(n) printf("%lf",n);
#define sc(n) scanf("%c",&n);
#define pc(n) printf("%c",n);
#define gc getchar();
#define re(n,a) memset(n,a,sizeof(n));
#define len(a) strlen(a)
using namespace std;
//https://codeforces.com/contest/1213/problems
//https://codeforces.com/contest/1213/submit
ll a[100];
    ll n;
bool is(){

    for(ll i = 0; i < 50; i ++){
        if(a[i] >= n){
            return false;
        }
    }
    return true;
}
int main(){
    sld(n)
    for(ll i = 0; i < n; i ++){
        sld(a[i])
    }
    ll count0 = 0ll;
    while(1){
        if(is()){
            break;
        }
        ll maxi = 0ll;
        for(ll i = 0; i < n; i ++){
            if(a[maxi] < a[i]){
                maxi = i;
            }
        }
        ll x = a[maxi]/n;
        //ll y = a[maxi]%n;
        //pld(x) pn
        count0 += x;
        for(ll i = 0; i < n; i ++){
            //pld(a[i]) pk
            if(maxi != i){
                a[i] += x;
            }else{
                a[i] -= n*x;
            }
        }
        //pn
    }
    /*for(ll i = 0; i < n; i ++){
            pld(a[i]) pk

        }*/
        //pn
    pld(count0) pn





    return 0;
}


Measured memory_bytes: 256
/*
** 本题算法分析很有借鉴的必要，详见本书 p143-145
*/

# include <iostream>
# include <algorithm>
# include <cstdio>
# include <cstring>
using namespace std;

const int maxn = 1000 + 5;
const int vmax = 10000 + 10;

int a[maxn], b[maxn], n, t[maxn], minv;

int solve() {
    int ans = 0;
    sort(b, b + n);
    for (int i = 0; i < n; i++) {
        if (t[i] != 0 || a[i] == b[i]) {
            continue;
        }

        int m = vmax, an = 0, sum = 0;
        int j = i;
        while (true) {
            t[j] = 1;
            m = min(m, a[j]);
            ++an;
            sum += a[j];
            j = lower_bound(b, b + n, a[j]) - b;
            if (j == i) {
                ans += min(sum + (an - 2) * m, sum + m + (an + 1) * minv);
                break;
            }
        }
    }
    return ans;
}

int main() {
    // freopen("infile", "r", stdin);
    // freopen("outfile", "w", stdout);
    cin >> n;
    minv = vmax;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        minv = min(minv, a[i]);
        b[i] = a[i];
    }
    memset(t, 0, sizeof(t));

    cout << solve() << endl;

    return 0;
}


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

int dp[105][4][2];

int main() {
    string s;
    cin >> s;
    int n = s.size();
    int K;
    cin >> K;

    dp[0][0][0] = 1;
    for(int i=0; i<n; i++) {
        for(int j=0; j<4; j++) {
            for(int k=0; k<2; k++) {
                int nd = s[i] - '0';
                for(int d=0; d<10; d++) {
                    int ni = i+1, nj = j, nk = k;
                    if (d != 0) nj++;
                    if (nj > K) continue;
                    if (k == 0) {
                        if (d > nd) continue;
                        if (d < nd) nk = 1;
                    }
                    dp[ni][nj][nk] += dp[i][j][k];
                }
            }
        }
    }

    int ans = dp[n][K][0] + dp[n][K][1];
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
main(){
    int N;
    cin >> N;
    string S;
    cin >> S;
    int cnt = 0;
    for(auto c:S){
        if(c == 'R')cnt++;
        else cnt--;
    }
    if(cnt >= 1)cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
N, X = map(int, input().split())
L = list(map(int, input().split()))
d = [0]*(N+1)
d[0] = 0

for i in range(1, N+1):
  d[i] = d[i-1] + L[i-1]

print(sum(1 for x in d if x<=X))

Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, M, X;
  cin >> N;
  M = N%100;
  X = (N-M)/100;
  if(5*X < M) {
    cout << 0 << endl;
  }
  else {
    cout << 1 << endl;
  } 
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main(void)
{
	int i,a,b,n,x,y;
	char o[51],e[51];
	scanf("%s %s",o,e);
	a=strlen(o);
	b=strlen(e);
	n=a+b;
	x=0;
	y=0;
	for(i=1;i<=n;i++){
		if(i%2!=0){
			printf("%c",o[x]);
			x++;
		}
		else{
			printf("%c",e[y]);
			y++;
		}
	}
	printf("\n",y);
	return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>


int descending_compare(const void *a, const void *b){
    if (*(int*)a > *(int*)b){
        return -1;
    }else if (*(int*)a == *(int*)b){
        return 0;
    }else{
        return 1;
    }
}

int ascending_compare(const void *a, const void *b){
    if (*(int*)a < *(int*)b){
        return -1;
    }else if (*(int*)a == *(int*)b){
        return 0;
    }else{
        return 1;
    }
}


int lower_bound(int *a, int n, int key){
    int left, mid, right;
    left = 0, right = n;
    mid = (left + right)/2;
    while ((left+1 != mid || mid+1 != right) && mid != left){
        if (key > a[mid]){
            left = mid;
        }else{
            right = mid+1;
        }
        mid = (left + right)/2;
    }
    if (a[left] >= key)return left;
    if (a[mid] >= key)return mid;
    if (a[right] >= key)return right;
    return n;
}

//greatest common divisor
unsigned long  gcd(unsigned long x, unsigned long y){
    if (y == 0){ 
        return x;
    }else if (x > y){
        return gcd(y, x % y);
    }else{
        return gcd(x, y % x);
    }
}



long long factorial(int x){
    long long rtn = 1;
    int i;
    for (i = x; i > 1; i--){
        rtn = (rtn*i);
    }
    return rtn;
}

/*
int struct_ascending_compare(const void *p, const void *q) {
    return ((struct_name*)p)->member_name - ((struct_name*)q)->member_name;
}*/
char s[100100];

int main(void){
    scanf("%s", s);
    int len = strlen(s);
    int topcoder = 0;
    int atcoder = len/2;
    for (int i = 0; i < len; i++){
        if (s[i] == 'p'){
            topcoder++;
        }
    }
    printf("%d\n", atcoder-topcoder);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define MIN -1000000
using namespace std;
typedef long long ll;
vector<int> d;
const double eps=1e-9;
int mxd=0;
int ans=0;
int N,D;
int X[15][25];
int main(void)
{
  cin >> N >> D;
  for(int i=0;i<N;i++)
  {
    for(int j=0;j<D;j++)
    {
      cin >> X[i][j];
    }
  }
  int ans=0;
  double dis;
  for(int i=0;i<N;i++)
  {
    for(int j=i+1;j<N;j++)
    {
      dis=0.0;
      for(int d=0;d<D;d++)
      {
        dis+=(X[i][d]-X[j][d])*(X[i][d]-X[j][d]);
      }
      dis=sqrt(dis);
      int idis=floor(dis);
      if(abs(dis-idis)<1e-9) ans++;
    }
  }
  cout << ans << endl;
  
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
#define MAX_T 30
#define MAX_N 100
#define INF 1e9
 
int N,T,dp[MAX_N+1][MAX_T];
int arr[MAX_N],t[MAX_T],d;
 
int solve(int idx,int pos){
    if(idx == d+1) return 0;
    if(dp[idx][pos] != -1){
	return dp[idx][pos];
    }
    int res = INF;
    for(int i = 0 ; i < T ; i++){
	if(t[pos] <= arr[idx]){
	    res = min(res,solve(idx+1,(pos+1)%T));
	}
	res = min(res,solve(idx+1,1)+1);
    }
    return dp[idx][pos] = res;
}
 
int main(){
    while(cin >> T, T){
	for(int i = 0 ; i < MAX_N ; i++){
	    arr[i] = INF;
	}
	for(int i = 0 ; i < T ; i++){
	    cin >> t[i];
	}
	int D,M;
	d = 0;
	cin >> N;
	for(int i = 0 ; i < N ; i++){
	    cin >> D >> M; D--;
	    d = max(d,D);
	    arr[D] = min(arr[D],M);
	}
	memset(dp,-1,sizeof(dp));  
	cout << solve(0,0) << endl;
    }
    return 0;
}

Measured memory_bytes: 3084
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <array>
#include <vector>
#include <utility>
#include <bitset>
#include <queue>
#include <unordered_map>
#include <unordered_set>

using namespace std;

using ll = long long;
using p = pair<ll, ll>;

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

    ll N, M;
    cin >> N >> M;

    ll ans = 0;
    if (N == 1 && M == 1) {
        ans = 1;
    } else if (N == 1 || M == 1) {
        if (M == 1) {
            swap(N, M);
        }
        ans += M - 2;
    } else {
        ans += (M - 2) * (N - 2);
    }

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



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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  for (int i = 0; i < 5; i++) {
    int x;
    cin >> x;
    if (x == 0) {
      cout << i + 1 << '\n';
      return 0;
    }
  }
  return 0;
}

Measured memory_bytes: 3580
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_set>
#include<unordered_map>
#include<fstream>
#include<list>
#include<functional>
#include<bitset>
#include<complex>
#include<tuple>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef long double D;
#define F first
#define S second
const ll E=1e18+7;
const ll MOD=1000000007;

ll cul(ll a,ll b,ll x){
    ll l=0,r=b+1;
    while(r-l>1){
        ll m=l+(r-l)/2;
        if(m*x>a || m>b || (b-m)/x>a-(m*x)){r=m;}
        else{l=m;}
    }
    return l;
}

//1-indexed
string cul(ll a,ll b,ll c,ll d){
    string ret;
    ll x=(a+b)/(b+1);
    if(a==b || x==1){
        for(ll i=c;i<=d;i++){ret.push_back(i&1?'A':'B');}
        return ret;
    }
    ll L=cul(a,b,x),R=cul(b,a,x);
    for(ll i=c;i<=d;i++){
        if(i<=L*(x+1)){
            ret.push_back(i%(x+1)?'A':'B');
        }
        else if(a+b-i+1<=R*(x+1)){
            ret.push_back((a+b-i+1)%(x+1)?'B':'A');
        }
        else{
            ll I=i-(x+1)*L;
            ll A=a-L*x-R;
            ll B=b-L-R*x;
            //cout<<i<<" "<<L<<" "<<R<<" "<<A<<" "<<B<<endl;
            assert(A<=x && B<=x);
            ret.push_back(I<=A?'A':'B');
        }
    }
    return ret;
}


int main(){
    ll q;
    cin>>q;
    while(q--){
        ll a,b,c,d;
        cin>>a>>b>>c>>d;
        string ans;
        if(a>b){
            ans=cul(a,b,c,d);
        }
        else{
            ans=cul(b,a,a+b-d+1,a+b-c+1);
            reverse(ans.begin(),ans.end());
            for(auto &I:ans){I=(I=='A'?'B':'A');}
        }
        cout<<ans<<endl;
    }
    
    
    return 0;
}


Measured memory_bytes: 384
#include <iostream>
using namespace std;
int main()
{
    int A,B,C;
    cin >> A >> B;
    C = A + B;
    if(A%3==0 || B%3==0 || C%3==0) cout << "Possible" << endl;
    else cout << "Impossible" << endl;
	return 0;
}

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

int main(void){

    int n;
    cin >> n;

    int result = n;
    for(int i=0; i<=n; i++) {
        
        int count = 0;
        int t = i;
        while(t > 0) {
            count += t % 6;
            t /= 6;
        }
        t = n - i;
        while(t > 0) {
            count += t % 9;
            t /= 9;
        }
        
        if(result > count) result = count;
        
    }
    
    cout << result << endl;
    
    return 0;
}


Measured memory_bytes: 256
# import bisect
# import heapq
# from copy import deepcopy
# from collections import deque
# from collections import Counter
# from itertools import accumulate
# from itertools import permutations
# import numpy as np
# import math
mod = 10**9 + 7

n = int(input())
a = list(map(int, input().split()))

ans = 0
for i in range(n):
    a[i] = bin(a[i])[2:].zfill(60)

for i in range(60):
    count = 0
    for j in range(n):
        count += 1 if a[j][i] == '1' else 0

    ans += (pow(2, 59-i, mod) * count * (n-count)) % mod

print(ans % mod)

Measured memory_bytes: 135312
n,k=map(int,input().split())
l=[]
for i in range(n):
    l.append(list(map(int,input().split())))
l.sort(key=lambda x: x[0]*1000000000000+x[1])
l.append([-1,-1])
a=[]
b=[]
for i in range(n):
    if l[i][0]==l[i+1][0]:
        b.append(l[i][1])
    else:
        a.append(l[i][1])
ans=len(a)*len(a)+sum(a)
#print(ans)
if len(b)>0:
    ans+=sum(b)
    b.sort()
    a.sort()
    i=0
    ai=0
    bi=0
    an=len(a)
    bn=len(b)
    while i<n-k:
        if ai<an and bi<bn:
            ap=a[ai]
            bp=b[bi]
            if ap+2*(an-ai-1)+1>=bp:
                bi+=1
                ans-=bp
            else:
                ans-=ap+2*(an-ai-1)+1
                ai+=1
        elif ai<an:
            ap=a[ai]
            ans-=ap+2*(an-ai-1)+1
            ai+=1
        elif bi<bn:
            ans-=b[bi]
            bi+=1
        i+=1
    print(ans)
else:
    a.sort(reverse=True)
    print(sum(a[:k])+k*k)


Measured memory_bytes: 70104
#include <bits/stdc++.h>
#define rep(i,a,b) for(ll i=ll(a);i<ll(b);i++)
using ll = long long;
using namespace std;
ll n,k,s=0,a[550],b[550],ans=0;
ll f(ll w){
    ll s2=0,s3=0;
    rep(i,0,n){b[i]=a[i]%w;s2+=b[i];} 
    sort(b,b+n);
    rep(i,0,n-s2/w)s3+=b[i];  //s2/w ... 
    if(s3<=k) return w;
    else return 0;
}
int main(){
    cin>>n>>k;
    rep(i,0,n) {cin>>a[i];s+=a[i];}
    for(ll p=1;(p*p)<=s;p++) if(s%p==0){//自信を除くsの約数の最大は√s1よりp*p<=s
        ans=max(ans,f(p));              //前から
        if(s%p==0)ans=max(ans,f(s/p)); //後ろから
    }
    cout<<ans;
}


Measured memory_bytes: 256
import java.util.*;

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

    sc.close();

    if (a.length() + 1 == b.length() && b.indexOf(a) == 0) {
      System.out.println("Yes");
    } else {
      System.out.println("No");
    }
  }
}


Measured memory_bytes: 35740
#include<iostream>
#include<vector>
#include<string>
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<limits.h>
using namespace std;
int main(void){
    int n,a;
    string s;
    cin>>n>>s;
    if(s.size()<=n){
        cout<<s<<endl;
    }else{
        a=s.size()-n;
        s.erase(s.size()-a);
        cout<<s<<"..."<<endl;
    }
}

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

using namespace std;

stack <char> Alice;
stack <char> Bob;
stack <char> Charlie;

string winner = "";

void CheckCharlie();
void CheckBob();
void CheckAlice();


void CheckCharlie()
{
    if (!Charlie.size()) {
         winner +='C';
         return;
    }

    if(Charlie.top() == 'a'){
        Charlie.pop();
        return (CheckAlice());
    }
    if(Charlie.top() == 'b'){
        Charlie.pop();
        return CheckBob();
    }
    if(Charlie.top() == 'c'){
        Charlie.pop();
        return CheckCharlie();
    }
}


void CheckBob()
{
    if (!Bob.size()) {
     winner +='B';
     return;
    }

    if(Bob.top() == 'a'){

        Bob.pop();
        return CheckAlice();
    }
    if(Bob.top() == 'b'){
        Bob.pop();
        return CheckBob();
    }
    if(Bob.top() == 'c'){
        Bob.pop();
        return CheckCharlie();
    }
}

void CheckAlice()
{
    if (!Alice.size()){

        winner +='A';
        return;

    }

    if(Alice.top() == 'a'){

        Alice.pop();
        return CheckAlice();
    }
    if(Alice.top() == 'b'){

        Alice.pop();
        return CheckBob();
    }
    if(Alice.top() == 'c'){
     Alice.pop();
       return CheckCharlie();
    }
}



int main(){

    //freopen("input.txt","r",stdin);

    string al, bo, cha;

    cin >> al;
    cin >> bo;
    cin >> cha;


    reverse(al.begin(),al.end());
    reverse(bo.begin(),bo.end());
    reverse(cha.begin(),cha.end());

    int len = 0;


    while(len < al.length()){
        Alice.push(al[len++]);
    }

    len = 0;

    while(len < bo.length()){
        Bob.push(bo[len++]);
    }

    len = 0;

    while(len < cha.length()){
        Charlie.push(cha[len++]);
    }

    CheckAlice();

    cout << winner << endl;

    return 0;
}


Measured memory_bytes: 256
//package atcoder;
 
import java.util.*;
//import java.math.BigDecimal;
 
public class Main{
	 static List <String> z;
	public static void main(String[] args) {
		z = new ArrayList<String>();
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		StringBuilder P_sb = new StringBuilder();
        StringBuilder Q_sb = new StringBuilder();
        for (int n = 0; n < N; n++) {
            P_sb.append(sc.nextInt());
        }
        for (int n = 0; n < N; n++) {
            Q_sb.append(sc.nextInt());
        }
       // System.out.println(P_sb);
        StringBuilder sb = new StringBuilder();
        for(int n=0;n<N;n++) {
        	sb.append(n+1);
        }
        //System.out.println(sb);
        permutation(sb.toString(),"");
        
        int a = 0; int b = 0;
        for (int i = 0; i < z.size(); i++) {
//            System.out.println(z.get(i));
            if ( P_sb.toString().equals(z.get(i)) ) a = i;
            if ( Q_sb.toString().equals(z.get(i)) ) b = i;
        }
        System.out.println(Math.abs(b - a));
	}
	public static void permutation(String q,String ans) {
		
		if(q.length()<=1) {
			z.add(ans+q);
		}else {
			for(int i=0;i<q.length();i++) {
				permutation(q.substring(0,i)+q.substring(i+1),ans+q.charAt(i));
			}
		}
	}
}

Measured memory_bytes: 48272
using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static void Main(string[] args)
    {
        var input = Console.ReadLine().Split(' ');
        var N = int.Parse(input[0]);
        var K = long.Parse(input[1]);

        var array = Console.ReadLine().Split(' ');

        var list = new List<int>();
        var flag = new int[N];
        foreach(var n in array)
        {
            list.Add(int.Parse(n));
        }

        var cities = new List<int>();
        var city = 1;
        var i = 0;
        var start = 0;
        var visitedCity = new List<int>();
        visitedCity.Add(1);
        while (true)
        {
            city = list[city - 1];
            if(flag[city - 1] == 0)
            {
                flag[city - 1] = i + 1;
                visitedCity.Add(city);
            }
            else
            {
                start = flag[city - 1];
                break;
            }
            i++;
        }

        var newPath = new List<int>();

        for (var j = start; j < visitedCity.Count; j++)
        {
            newPath.Add(visitedCity[j]);
        }

        long count = K;

        if (count < start)
        {
            Console.WriteLine(visitedCity[(int)count]);
        }
        else
        {
            count -= start;

            count = count % newPath.Count;
            Console.WriteLine(newPath[(int)(count)]);
        }

        Console.ReadLine();
    }


}


Measured memory_bytes: 40604
#include<iostream>
#include<stdio.h>
using namespace std;

int main(){
  int N,A,B,C;
  cin>>N>>A>>B;
  C=N*A;
  if(C<=B){
    cout<<C;
  }else{
    cout<<B;
  }
  cout<<endl;
return 0;
}

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

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

  ll n,m,s; cin>>n>>m>>s;
  struct Train {
    ll s, c, d;
    Train(ll s,ll c,ll d):s(s),c(c),d(d){}
    bool operator>(const Train& x) const {return d>x.d;}
  };
  vector<Train> graph[n];
  for (int i = 0; i < m; i++) {
    ll u,v,a,b; cin>>u>>v>>a>>b; u--; v--;
    graph[u].emplace_back(v,a,b);
    graph[v].emplace_back(u,a,b);
  }
  for (int i = 0; i < n; i++) {
    int c,d; cin>>c>>d;
    graph[i].emplace_back(i,-c,d);
  }
  constexpr ll MAX = 200;
  constexpr ll INF = 1e18;
  vector<array<ll, MAX+1>> dp(n);
  for (auto& arr:dp) arr.fill(INF);
  dp[0][min(s,MAX)] = 0;
  priority_queue<Train, vector<Train>, greater<>> qs;
  qs.emplace(0,s,0);
  while (not qs.empty()) {
    auto [s,c,d] = qs.top(); qs.pop();
    if (d > dp[s][min(c,MAX)]) continue;
    for (auto t:graph[s]) {
      if (c-t.c<0) continue;
      if (d+t.d >= dp[t.s][min(c-t.c,MAX)]) continue;
      dp[t.s][min(c-t.c,MAX)] = d+t.d;
      qs.emplace(t.s, c-t.c, d+t.d);
    }
  }
  for (int i = 1; i < n; i++) {
    cout << *min_element(dp[i].begin(), dp[i].end()) << '\n';
  }

  return 0;
}


Measured memory_bytes: 3884
#include<cstdio>
#include<vector>
#include<algorithm>

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

using namespace std;

int d[1500][1500];

int N,deg[1500];
void solve(int root,vector<int> V){
	int n=V.size();
	if(V.empty()) return;

	// root と u を両端とする列を作る
	// 残りの頂点は root-u 間にある d[root][u]+1 個の頂点のどれかにぶら下がる
	int u=V[0];
	vector<int> ch[32];
	for(int i=1;i<V.size();i++){
		int v=V[i];
		ch[(d[root][u]+d[root][v]-d[u][v])/2].push_back(v);
	}

	// 列の各頂点を根にして, 再帰的に木の形を求める
	int par;
	rep(i,d[root][u]+1){
		int v; // 次の根
		if(i==0){
			v=root;
		}
		else if(i==d[root][u]){
			v=u;
		}
		else{
			v=N++;
			rep(j,ch[i].size()){
				int w=ch[i][j];
				d[v][w]=d[w][v]=d[root][w]-i;
			}
		}

		if(i!=0){
			deg[par]++;
			deg[ v ]++;
		}

		solve(v,ch[i]);

		par=v;
	}
}

int main(){
	for(int n;scanf("%d",&n),n;){
		rep(u,n) rep(v,n) scanf("%d",d[u]+v);

		vector<int> V;
		rep(i,n-1) V.push_back(i+1);
		N=n;
		rep(u,1500) deg[u]=0;
		solve(0,V);

		vector<int> ans(deg+n,deg+N);
		sort(ans.begin(),ans.end());
		rep(i,ans.size()) printf("%d%c",ans[i],i+1<ans.size()?' ':'\n');
	}

	return 0;
}

Measured memory_bytes: 1488
#include <iostream>
using std::cin;
using std::cout;
using std::endl;

int main()
{
    int N, input;
    cin >> N;
    int A[N];
    for (int i = 0; i < N; i++)
    {
        cin >> input;
        A[input - 1] = i + 1;
    }
    for (int i = 0; i < N; i++)
    {
        cout << A[i] << " ";
    }
    cout << endl;
    return EXIT_SUCCESS;
}

Measured memory_bytes: 1152