akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

struct edge {int u, v, cost;};

int n;
vector<edge> G;

bool comp(const edge& e1, const edge& e2) {
    return e1.cost < e2.cost;
}

class UnionFind {
 public:
    int g_num;
    vector<int> rank, par;

    UnionFind() {}
    UnionFind(int size) {
        rank.resize(size, 0);
        par.resize(size, 0);
        for (int i = 0; i < size; i++) {
            par[i] = i;
            rank[i] = 0;
        }
        g_num = size;
    }

    bool same(int x, int y) {
        return find(x) == find(y);
    }

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

        g_num--;
        if (rank[x] > rank[y]) {
            par[y] = x;
        } else {
            par[x] = y;
            if (rank[x] == rank[y]) rank[y]++;
        }
    }

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

    int group_num() {
        return g_num;
    }
};

int kruskal() {
    sort(G.begin(), G.end(), comp);
    UnionFind uf(n);
    int res = 0;
    for (auto e: G) {
        if (!uf.same(e.u, e.v)) {
            uf.unite(e.u, e.v);
            res += e.cost;
        }
    }
    return res;
}

int main(void) {
    cin >> n;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            int cost;
            cin >> cost;
            if (cost == -1) continue;
            G.push_back(edge {i, j, cost});
        }
    }
    int ans = kruskal();
    cout << ans << endl;
    return 0;
}

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

int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  
  if ( A + B > C + D ) {
  	cout << "Left" << endl;
  }
  
  else if ( A + B == C + D ) {
  	cout << "Balanced" << endl;
  }
  
  else if ( A + B < C + D ) {
  	cout << "Right" << endl;
  }
  
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
	int a,b,c,i;
	scanf("%d%d%d",&a,&b,&c);
	for(i=1;i<b;i++){
		if(a*i%b==c){
			puts("YES");
			return 0;
		}
	}
	puts("NO");
	return 0;
}

Measured memory_bytes: 128
///*****************************************************///
///*.......................Faiyaj Bin Amin............................*///
///*...................................................................*///
///*.........................KUET CSE 2K17......................*///
///*...................................................*///
///*****************************************************///

#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>

#define fastio      ios_base::sync_with_stdio(0);cin.tie(0),cout.tie(0)
#define ret return
#define rep(q, i, n) for(int q=i; q<n; q++)
#define forn(i, n) for(int i=0; i<n; i++)
#define mems(a,x) memset(a,x,sizeof(a))
#define ll long long
#define pb push_back
#define em emplace_back
#define mp make_pair
#define all(v) (v).begin(), (v).end()
#define ff first
#define ss second
#define pii pair<int,int>
#define pdd pair<double, double>

#define see(x)        cerr<< __LINE__ << ": " << (#x) << " is "<< (x) <<'\n';
#define seecontent(v) for(auto x : v) { cout << x << " ";} cout << "\n\n";

#define PI 2*acos(0.0)
#define lcm(a, b)  ((a / __gcd(a, b) ) * b)

#define filein freopen ("input.txt", "r", stdin)
#define fileout freopen ("output.txt", "w", stdout)

#define mx 100005
#define INF 1e18
#define MOD 1000000007
#define MIN 0

//template <typename T>  using orderedSet =
//    tree<T, null_type, less_equal<T>,
//    rb_tree_tag, tree_order_statistics_node_update>; //find_by_order, order_of_key


/*------------------------------Graph Moves----------------------------*/
//const int fx[]={+1,-1,+0,+0}; // Directional
//const int fy[]={+0,+0,+1,-1};
//const int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};   // Kings Move
//const int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};  // Kings Move
//const int fx[]={-2, -2, -1, -1,  1,  1,  2,  2};  // Knights Move
//const int fy[]={-1,  1, -2,  2, -2,  2, -1,  1}; // Knights Move
/*---------------------------------------------------------------------*/

/**------------------------------------BITMASK------------------------------------------**/
//int Change(int N, int pos){return N= N^(1<<pos);}
//bool Check(int N, int pos){return (bool)(N &(1<<pos));}  /// check bit 0 or 1
/**-----------------------------------------------------------------------------------------------**/

//using namespace __gnu_pbds;
using namespace std;

int main()
{
    fastio;

    ll n;
    cin>>n;

    ll b[n-1], a[n]= {0};

    forn(i, n-1)
    {
        cin >> b[i];
    }

    a[0]=b[0];
    a[1]=b[0];
    for(int i=1; i<n-1; i++)
    {
        a[i+1]=b[i];
        if(b[i]<a[i])
            a[i]=b[i];
    }


    ll cnt=0;
    forn(i, n)
    {
        cnt += a[i];
    }
    cout<< cnt << "\n";

    return 0;
}


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

using namespace std;
void dfs(vector<int> graph[], int v, int vis[], vector<int> &vec)
{
    vis[v] = 1;
    for(auto j : graph[v])
        if(!vis[j])
            dfs(graph, j, vis, vec);
    vec.push_back(v);
}
int main() {
    int n, m;
    cin >> n >> m;
    vector<int> graph[n+1];
    int i;
    for(i=1;i<=m;i++)
    {
        int x, y;
        cin >> x >> y;
        graph[x].push_back(y);
    }
    vector<int> vec;
    int vis[n+1] = {0};
    for(i=1;i<=n;i++)
        if(!vis[i])
            dfs(graph, i, vis, vec);
    int dp[n+1] = {0};
    reverse(vec.begin(), vec.end());
    for(auto j : vec)
    {
        vis[j] = 1;
        for(auto x : graph[j])
            dp[x] = max(dp[x], 1 + dp[j]);
    }
    cout << *max_element(dp, dp+n+1);
}

Measured memory_bytes: 12620
fun main(args: Array<String>) {
    val input = readLine()!!.split(" ").map(String::toInt)
    var a = input[0]
    val b = input[1]
    var c = input[2]
    val d = input[3]

    run loop@{
        while(true){
            a -= d
            c -= b 
            if(c <= 0){
                println("Yes")
                return@loop
            }else if(a <= 0){
                println("No")
                return@loop
            }
        }
    }
}


Measured memory_bytes: 36336
from fractions import gcd
n=int(input())
a=list(map(int,input().split()))
GA=[a[0]]
GB=[a[n-1]]
G=gcd(a[0],a[1])
GA.append(G)
for i in range(2,n-1):
  G=gcd(G,a[i])
  GA.append(G)
G=gcd(a[n-1],a[n-2])
GB.append(G)
for j in range(n-3,0,-1):
  G=gcd(G,a[j])
  GB.append(G)
GB.reverse()
ans=[]
for i in range(len(GA)-1):
  ans.append(gcd(GA[i],GB[i+1]))
ans.append(GA[len(GA)-1])
ans.append(GB[0])
if n!=2:
  print(max(ans))
else:
  print(max(a))

Measured memory_bytes: 16156
n,m=map(int,input().split())
a={}
for i in range(m):
    b,c=map(int,input().split())
    a[i]=(b,c-1)
a=sorted(a.items(),key=lambda x:x[1])
b=[0]*(n+1);c=[0]*(n+1)
for i in range(n):b[i]=c[i]=i
for i in range(m):
    x=a[i][1][1]
    b[x]=max(b[x],b[x+1])
    c[x+1]=min(c[x],c[x+1])
print(*[b[i]-c[i]+1 for i in range(n)])

Measured memory_bytes: 43892
N, M = list(map(int, input().split()))
ks = [list(map(int, input().split())) for _ in range(M)]
p = list(map(int, input().split()))

ans = 0
B = 1 << N
for i in range(B):
  L = [0] * M
  for j in range(M):
    for k in ks[j][1:]:
      if i >> (k - 1) & 1:
        L[j] = (L[j] + 1) % 2
  for j in range(M):
    if L[j] != p[j]:
      break
  else:
    ans += 1

print(ans)

Measured memory_bytes: 74344
#include <bits/stdc++.h>
#include <cstdlib>
using namespace std;
typedef signed long long ll;
#define FOR(i,to) for(i=0;i<(to);i++)

int dp[3000+10][3000+10];
const ll mod=998244353;
int main() {
	int i,j,k,l,r,x,y; string s;

    int N;
    int S;
    cin >> N;
    cin >> S;

    int sr[N];
    FOR(i,N) cin>>sr[i];

    dp[0][0]=1;

    for(i=1;i<=N;i++){
        for(j=0;j<=S;j++){
            (dp[i][j]=dp[i-1][j]*2)%=mod;
            if(j>=sr[i-1]){
                y=j-sr[i-1];
                (dp[i][j]+=dp[i-1][y])%=mod;
            }
        }
    }
    std::cout << dp[N][S];
}



Measured memory_bytes: 38888
#include <bits/stdc++.h>
#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 INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main()
{
    int a,b;
    cin >> a >> b;
    if(a<b){
        for(int i = 0; i<b; i++){
            cout << a;
        }
    }
    else
    {
        for(int i=0; i<a; i++){
            cout << b;
        }
    }
    cout << endl;

    return 0;    
}

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

int map[10][10]={};
int sx[] = { 0,-1,0,1,0 } , sy[] = { -1,0,0,0,1 } ;
int mx[] = { -1,0,1 }, my[] = { -1,0,1 } ;
int lx[] = { 0,-1,0,1,-2,-1,0,1,2,-1,0,1,0 } ;
int ly[] = { -2,-1,-1,-1,0,0,0,0,0,1,1,1,2 } ;

int main(){
	
	int x,y,size ;
	char temp;
	int empty=0,max=0;
	
	while(1){
		cin >> x ;
		if( cin.eof() ) break;
		cin >> temp >> y ;
		cin >> temp >> size ;
		
		if( size==1 ){
			for( int i=0 ; i<5 ; i++ ){
				if( x+sx[i]>=0 && x+sx[i]<=9 && y+sy[i]>=0 && y+sy[i]<=9 )
					map[x+sx[i]][y+sy[i]]++;
			}
		}
		else if( size==2 ){
			for( int i=0 ; i<9 ; i++ ){
				if( x+mx[i%3]>=0 && x+mx[i%3]<=9 && y+my[i/3]>=0 && y+my[i/3]<=9 )
					map[x+mx[i%3]][y+my[i/3]]++;
			}
		}
		else if( size==3 ){
			for( int i=0 ; i<13 ; i++ ){
				if( x+lx[i]>=0 && x+lx[i]<=9 && y+ly[i]>=0 && y+ly[i]<=9 )
					map[x+lx[i]][y+ly[i]]++;
			}
		}
	}
	
	for( int i=0 ; i<10 ; i++ ){
		for( int j=0 ; j<10 ; j++ ){
			if( map[i][j]==0 ) empty++;
			if( map[i][j]>max ) max=map[i][j] ;
		}
	}
	
	cout << empty << endl ;
	cout << max << endl ;
	
return 0;
}

Measured memory_bytes: 1160
#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstring>
#include <fstream>
#include <iostream>
#include <iomanip>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

const int MAX = 507;
const int MOD = 1000000007;

void solve() {
    int n;
    cin >> n;
    cout << (1000 - n % 1000) % 1000;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    //int tt; cin >> tt; for (int i = 1; i <= tt; i++) {solve(); cout << endl;}
    solve();
}

Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
const int N =100000;
int odd[100005],even[100005];
int main() {
    
    int n;
    cin>>n;
    int temp;
    for(int i=1;i<=n;i++)
    {
        cin>>temp;
        if(i%2)
            odd[temp]++;
        else
            even[temp]++;
    }

    int maxOdd=INT_MIN;
    int indexOdd=0;
    for(int i=1;i<=N;i++)
    {
        if(odd[i]> maxOdd)
         {   maxOdd=odd[i];
             indexOdd=i;
         }
    }
    int maxEven=INT_MIN;
    int indexEven=0;
    for(int i=1;i<=N;i++)
    {
        if(even[i]> maxEven)
        {
            maxEven=even[i];
            indexEven=i;
        }
    }
    int ans=0,l2,l1=max(maxEven,maxOdd);
    
    if(indexEven==indexOdd)
    {
        
            odd[indexOdd]=0;
            int maxOdd2=INT_MIN;
            indexOdd=0;
            for(int i=1;i<=N;i++)
            {
                if(odd[i]> maxOdd2)
                 {   maxOdd2=odd[i];
                     indexOdd=i;
                 }
            }
        
            even[indexEven]=0;
            int maxEven2=INT_MIN;
            indexEven=0;
            for(int i=1;i<=N;i++)
            {
                if(even[i]> maxEven2)
                 {   maxEven2=even[i];
                     indexEven=i;
                 }
            }
            
            l2=max(maxEven2,maxOdd2);
            ans=n-l1-l2;
        
    }
    if(!ans)
        ans=n-maxOdd-maxEven;
    cout<<ans;
}

Measured memory_bytes: 1024
#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 ab;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) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsps(s) int 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 gcd(int x,int y){
	
	if(x%y==0){
		return y;
	}else{
		return gcd(y,x%y);
	}
	
}

int main() {
	
	int N;
	cin>>N;
	vec(A)
	int ans=1000000000;
	fx(N){
		vecp(A)
		ans=min(ans,A.at(x));

	}
	if(ans==1){
		ce(1)
	}else{
	while(true){
		int flag=true;
		int mini=ans;
		fx(N){
			if(A.at(x)==ans&&flag){
				flag=false;
				continue;
			}
			A.at(x)%=ans;
          if(A.at(x)==0){continue;}
			mini=min(A.at(x),mini);

		}
		if(ans==mini){break;}
		ans=mini;
	}
	ce(ans)
	}
}


Measured memory_bytes: 892
n1, n2 = [int(i) for i in input().split()]
n3 = [int(i) for i in input().split()]

n3.sort(reverse = True)

c1 = 0
while True:
    n3[0] = n3[0] // 2
    c1 += 1
    if c1 >= n2:
        break
    t2 = 1
    while len(n3) != 1:
        if n3[t2] >= n3[0]:
            n3[t2] = n3[t2] // 2
            t2 += 1
            c1 += 1
            if c1 >= n2 or t2 >= len(n3):
                break
        else:
            break

    if c1 >= n2:
        break

    n3.sort(reverse = True)

r1 = 0
for i2 in range(n1):
    r1 += n3[i2]

print(r1)

Measured memory_bytes: 14432
#include<stdio.h>
#include<stdlib.h>
#include<bits/stdc++.h>
#define ll long long
#define fast_io cin.tie(0);cout.tie(0);ios::sync_with_stdio(0)
using namespace std;

int main(){
	fast_io;
	ll a,b;
	cin>>a>>b;
	if(a>=13){
		cout<<b;
	}
	else if(a>=6 && a<=12){
		cout<<b/2;
	}
	else{
		cout<<"0";
	}
}

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

int main(){
  ll X,K,D;cin>>X>>K>>D;
  X=abs(X);
  ll A=X/D;
  if(A<K){
  K-=A;
  X-=A*D;
  if(K%2==0) cout<<X<<endl;
  else cout<<abs(X-D)<<endl;
  }
  else cout<<abs(X-K*D)<<endl;
} 

Measured memory_bytes: 3632
#include "bits/stdc++.h"
#pragma GCC optimize "03"
using namespace std;

#define int long long int
#define pb push_back
#define pii pair<int,int>
#define fi first
#define se second
#define rep(i,a,b) for (int i = a; i < b; ++i)
#define IOS ios::sync_with_stdio(false); cin.tie(NULL);
#ifndef LOCAL
#define dbg(...) ;
#define endl '\n'
#endif

const int inf = 1e15;
const int MOD = 1e9 + 7;
const int N = 2e5 + 5;

set<int> divisors(int n) {
    set<int> s;
    for (int i = 2; i <= sqrt(n); i++) {
        if (n % i == 0) s.insert(i);
        while (n % i == 0) n/=i;
    }
    if (n >= 2) s.insert(n);
    return s;
}

signed main(){
    IOS;
    int a, b;
    cin >> a >> b;
    set<int> c, d;
    c = divisors(a);
    d = divisors(b);
    int ans = 0;
    for (auto i : c) {
        if (d.find(i) != d.end()) ans++;
    }
    cout << ans + 1 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iomanip>
using namespace std;

typedef long long ll;

#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=(b-1);i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;

#define MOD 1000000007

int main() {
  vector<ll> v;
  rep(i,0,3){
    ll a;
    cin>>a;
    v.pb(a);
  }
  ll k;
  cin>>k;
  sort(all(v));
  reverse(all(v));
  rep(i,0,k){
    v[0]*=2;
  }
  ll ans = 0;
  rep(i,0,3){
    ans += v[i];
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using vec=vector<ll>;
using mat=vector<vec>;
#define For(i,a,b) for(i=a;i<b;i++)
#define rep(i,N) For(i,0,N)
#define rep1(i,N) For(i,1,N)
#define all(v) (v).begin(),(v).end()
#define vsort(v) sort(all(v))
#define mod 1000000007
using data=pair<ll,ll>;

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

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

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

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

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

ll countdigits(ll n){
  ll ans=0;
  while(n){n/=10;ans++;}
  return ans;
}

ll sumdigits(ll n){
  ll ans=0;
  while(n){ans+=n%10;n/=10;}
  return ans;
}

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


int main(){
  ll i,j,N,M,x,ans=0,bf=-10000000000;
  cin>>N>>M;
  rep(i,N){
    cin>>x;
    if(x-bf>M){ans+=M;}
    else{ans+=x-bf;}
    bf=x;
  }
  cout<<ans<<endl;
  return 0;
}

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

typedef struct{ char suit; int value; } Card;

void result(Card A[], int N){
    rep(i, N - 1) cout << A[i].suit << A[i].value << " ";
    cout << A[N - 1].suit << A[N - 1].value << endl;
}

int selectionSort(Card A[], int N){
    int sw = 0;
    rep(i, N - 1){
        int minj = i;
        for(int j = i; j < N; ++j){
            if(A[j].value < A[minj].value) 
                minj = j;
        }
        if(i != minj){
            swap(A[i], A[minj]);
            ++sw;
        }
    }
    return sw;
}

int bubbleSort(Card A[], int N){
    int sw = 0;
    bool flag = true;
    int i = 0;
    while(flag){
        flag = false;
        for(int j = N - 1; j >= i + 1; --j){
            if(A[j].value < A[j - 1].value){
                swap(A[j], A[j - 1]);
                flag = true;
                ++sw;
            }
        }
        ++i;
    }
    return sw;
}

int main(void){
    int N;     cin >> N;
    Card A[N]; rep(i, N) cin >> A[i].suit >> A[i].value;
    Card B[N]; rep(i, N) B[i] = A[i];
    
    
    bubbleSort(A, N);
    selectionSort(B, N);
    
    rep(i, N - 1) cout << A[i].suit << A[i].value << " ";
    cout << A[N - 1].suit << A[N - 1].value << endl;
    cout << "Stable" << endl;
    
    bool flag = true;
    rep(i, N - 1){ 
        cout << B[i].suit << B[i].value << " ";
        if(A[i].suit != B[i].suit || A[i].value != B[i].value) flag = false;
    }
    cout << B[N - 1].suit << B[N - 1].value << endl;
    cout << (flag ? "Stable" : "Not stable") << endl;
    
    return 0;
}


Measured memory_bytes: 3064
n=int(input())
result=0
for i in range(1,n+1):
  if 1<=i<=9:
    result+=1
  else:
    num=str(i)
    a=int(num[0])
    b=int(num[len(num)-1])
    middle=(i-10**(len(num)-1)*a-b)//10
    numbers=0
    if b!=0:
      for j in range(2,len(num)):
        numbers+=10**(j-2)
      if a==b:
        numbers+=2+middle
        result+=numbers*2-1
      elif a>b:
        numbers +=10**(len(num)-2)
        result+=numbers*2
      else:
        result+=numbers*2
print(result)

Measured memory_bytes: 3064
K = input()
D = int(input())
N = len(K)
mod = 10 ** 9 + 7

dp = [[[0]*2 for _ in range(D)] for _ in range(10000 + 5)]
dp[0][0][0] = 1

for i in range(N):
    nd = int(K[i])
    for j in range(D):
        for k in range(2):
            for d in range(10):
                ni = i + 1
                nj = (j+d) % D
                nk = k
                if nk == 0:
                    if d > nd:
                        continue
                    if d < nd:
                        nk += 1
                dp[ni][nj][nk] += dp[i][j][k]
                dp[ni][nj][nk] %= mod

ans = (dp[N][0][0] + dp[N][0][1] - 1 + mod) % mod
print(ans)


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

		String ss = sc.next();
		int[] num = new int[4];
		for( int i=0; i<4; i++ ){
			String str = String.valueOf(ss.charAt(i));
			num[i] = Integer.parseInt(str);
		}
		for( int i=0; i<1; i++ ){
			if( num[0]+num[1]+num[2]+num[3]==7 ){
				System.out.println(num[0]+"+"+num[1]+"+"+num[2]+"+"+num[3]+"=7");
				break;
			}
			if( num[0]+num[1]-num[2]+num[3]==7 ){
				System.out.println(num[0]+"+"+num[1]+"-"+num[2]+"+"+num[3]+"=7");
				break;
			}
			if( num[0]+num[1]+num[2]-num[3]==7 ){
				System.out.println(num[0]+"+"+num[1]+"+"+num[2]+"-"+num[3]+"=7");
				break;
			}
			if( num[0]+num[1]-num[2]-num[3]==7 ){
				System.out.println(num[0]+"+"+num[1]+"-"+num[2]+"-"+num[3]+"=7");
				break;
			}
			if( num[0]-num[1]+num[2]+num[3]==7 ){
				System.out.println(num[0]+"-"+num[1]+"+"+num[2]+"+"+num[3]+"=7");
				break;
			}
			if( num[0]-num[1]-num[2]+num[3]==7 ){
				System.out.println(num[0]+"-"+num[1]+"-"+num[2]+"+"+num[3]+"=7");
				break;
			}
			if( num[0]-num[1]+num[2]-num[3]==7 ){
				System.out.println(num[0]+"-"+num[1]+"+"+num[2]+"-"+num[3]+"=7");
				break;
			}
			if( num[0]-num[1]-num[2]-num[3]==7 ){
				System.out.println(num[0]+"-"+num[1]+"-"+num[2]+"-"+num[3]+"=7");
				break;
			}
		}
	}
}


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

int sumnum(int num)
{
    int dig = 0;
    int sum = 0;
    while (num)
    {
        dig = num % 10;
        sum = sum + dig;
        num = num / 10;
    }
    return sum;
}

int main()
{
    int N, A, B;
    cin >> N >> A >> B;
    int ans = 0;
    for (int i = 0; i <= N; ++i)
    {
        if (A <= sumnum(i) && sumnum(i) <= B)
        {
            ans += i;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
// 2014/07/25 Tazoe

#include <iostream>
#include <cctype>
using namespace std;

int main()
{
	int cnt[26] = { 0 };

	while (true){
		char c;
		cin >> c;

		if (cin.eof())
			break;

		if (islower(c)){
			cnt[c - 'a']++;
		}
		else if (isupper(c)){
			cnt[c - 'A']++;
		}
	}

	for (int i = 0; i<26; i++){
		cout << (char)(i + 'a') << " : " << cnt[i] << endl;
	}

	return 0;
}

Measured memory_bytes: 1144
#include <stdio.h>
#include <stdlib.h>
 
void push(int);
int pop();
 
int num[1000];
int n=0;
 
int main(){
 
  
  int i,x,y,ans;
  char c[100];
 
  for(i=0 ; i<100 ; i++){
    num[i]=0;
  }
 
 
  while(scanf("%s",c)!=EOF){
    //if(c=='\n') break;
    //if(c==' ') continue;
     
    
    if(c[0]=='+'){
      x=pop();
      y=pop();
      push(x+y);
    }
       
      else if(c[0]=='-'){
    x=pop();
    y=pop();
    push(y-x);
      }
      else if(c[0]=='*'){
    x=pop();
    y=pop();
    push(x*y);
      }
      else push(atoi(c));
  }
   
  ans=pop();
  printf("%d\n",ans);
 
 
  return 0;
}
 
void push(int x){
  n++;
  num[n]=x;
}
 
int pop(){
  n--;
  return num[n+1];
}

Measured memory_bytes: 548
// 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")

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

	vi a(4);
	rep(i,6){
		int b;cin>>b;
		b--;a[b]++;
	}
	sort(all(a));
	vi c={1,1,2,2};
	if(a==c)yes;
	else no;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/pb_ds/tree_policy.hpp"
using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
#define int long long
#define pb push_back
#define fi first
#define se second
#define fr(i, a, b) for(int i = a; i <= b; i++)
#define all(x) x.begin(), x.end()
#define IO ios :: sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define pii pair<int,int>
#define sz(x) (int)x.size()
const int mod = 1e9 + 7;
const int mod1 = 998244353;
typedef long double f80;

#ifndef LOCAL
#pragma GCC optimize ("O2")
#define endl '\n'
#endif

template<typename T>
using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int rand(int l, int r){
    uniform_int_distribution<int> uid(l, r);
    return uid(rng);
}

ll pwr(ll a,ll b, ll mod){
    a %= mod;
    int ans = 1;
    while(b){
        if(b & 1) ans = (ans * a) % mod;
        a = (a * a) % mod;
        b >>= 1;
    }
    return ans;
}

string to_string(string s) {
  return '"' + s + '"';
}

string to_string(const char* s) {
  return to_string((string) s);
}

string to_string(bool b) {
  return (b ? "true" : "false");
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

vector<string> v;

void solve(){
	string s;
	cin >> s;
	int k;
	cin >> k;
	int n = sz(s);
	fr(i, 0, n - 1){
		string ss = "";
		fr(j, i, min(i + k, n) - 1){
			ss += s[j];
			v.pb(ss);
		}
	}
	sort(all(v));
	unique(all(v));
	cout << v[k - 1];
}
signed main(){
    IO;
    #ifdef LOCAL
        freopen("inp.txt","r", stdin);
        freopen("out.txt", "w", stdout);
    #endif
    cout << setprecision(10) << fixed;
    int t = 1;
    // cin >> t;
    fr(tt, 1, t){
        solve();
    }
    return 0;
}

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

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


int N,L;
double T,V;
map<ll,ll> M;
double TV,TT;


void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>L;
	
	deque<pair<double,double>> D;
	
	FOR(i,N) {
		cin>>T>>V;
		
		if(i) {
			double del=V;
			
			while(del>0) {
				if(D.front().second<=del) {
					del -= D.front().second;
					TV -= D.front().second;
					TT -= D.front().first*D.front().second;
					D.pop_front();
				}
				else {
					D.front().second -= del;
					TV -= del;
					TT -= D.front().first*del;
					del = 0;
				}
			}
		}
		
		TV += V;
		TT += T*V;
		_P("%.12lf\n",1.0*TT/TV);
		
		while(D.size() && D.back().first>T) {
			double TTT = T*V + D.back().first*D.back().second;
			V = V + D.back().second;
			T = TTT/V;
			D.pop_back();
		}
		D.push_back({T,V});
		
		
	}
	
}


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


Measured memory_bytes: 19856
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = uint32_t;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max() / 32 * 15 + 208;

using P = array<char, 8>;
P merge(P a, P b){
    P c;
    for (int i = 0; i < 8; ++i) {
        c[i] = a[b[i]];
    }
    return c;
}


int main() {
    string s;

    P p = {3, 2, 6, 7, 0, 1, 5, 4}, q = {1, 5, 6, 2, 0, 4, 7, 3};
    set<P> perm;
    stack<P> S;
    S.emplace(P{0, 1, 2, 3, 4, 5, 6, 7});
    while(!S.empty()){
        P x = S.top(); S.pop();
        perm.emplace(x);
        P y = merge(x, p), z = merge(x, q);
        if(!perm.count(y)){
            S.emplace(y);
            perm.emplace(y);
        }
        if(!perm.count(z)){
            S.emplace(z);
            perm.emplace(z);
        }
    }
    while(cin >> s){
        vector<string> v;
        v.emplace_back(s);
        for (int i = 0; i < 7; ++i) {
            string t;
            cin >> t;
            v.emplace_back(t);
        }
        auto u = v;
        sort(u.begin(), u.end());
        u.erase(unique(u.begin(), u.end()), u.end());
        P x;
        for (int i = 0; i < 8; ++i) {
            x[i] = lower_bound(u.begin(),u.end(), v[i])- u.begin();
        }
        set<P> Q;
        sort(x.begin(),x.end());
        do {
            int ok = 1;
            for (auto &&j : perm) {
                if(Q.count(merge(x, j))){
                    ok = 0;
                }
            }
            if(ok){
                Q.emplace(x);
            }
        }while(next_permutation(x.begin(),x.end()));
        cout << Q.size() << "\n";
    }
    return 0;
}


Measured memory_bytes: 3248
def LI(): return list(map(int,input().split()))
N,M = LI()
H = LI()
AB = [LI() for _ in range(M)]
ans = 0
graph = {i:[] for i in range(1,N+1)} #1_indexed
for a,b in AB:
    graph[a].append(b)
    graph[b].append(a)
for i in range(1,N+1):
    if len(graph[i])==0:
        ans += 1
        continue
    height = []
    for x in graph[i]:
        height.append(H[x-1])
    if H[i-1] > max(height):
        ans += 1
print(ans)


Measured memory_bytes: 49776
#include <stdio.h>
int main(void) {
	int i,j,a,b,c,d,e,tmp,x[5]={};
	scanf("%d %d %d %d %d",&a,&b,&c,&d,&e);
	x[0]=a;
	x[1]=b;
	x[2]=c;
	x[3]=d;
	x[4]=e;
	for(j=4;j>0;j--){
		for(i=0;i<j;i++){
			if(x[i]<x[i+1]){
				tmp=x[i];
				x[i]=x[i+1];
				x[i+1]=tmp;
			}
		}
	}
	for(i=0;i<5;i++){
		if(i>=1) printf(" ");
		printf("%d",x[i]);
	}
	putchar('\n');
	return 0;
}


Measured memory_bytes: 2040
//#include <bits/stdc++.h>
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
//#include "boost/multiprecision/cpp_int.hpp"
//typedef boost::multiprecision::cpp_int LL;
typedef long double dd;
//#define i_7 (ll)(1E9+7)
//#define i_7 998244353
ll i_7;
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
typedef pair<dd,dd> d_d;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define fi first
#define se second
#define endl "\n"
#define SORT(v) sort(v.begin(),v.end())
#define ERASE(v) v.erase(unique(v.begin(),v.end()),v.end())
#define POSL(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define POSU(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}

void mod_print(ll k){
    ll P=1000;
    rep(y,1,P){
        ll x=mod(y*k);
        if(x+P>=i_7){
            x-=i_7;
        }
        if(abs(x)<=P){
            cout<<x<<"/"<<y<<endl;
            return;
        }
    }
    cout<<"nun"<<endl;
}
//////////////////////////

int main(){fastio
    ll n,m,q;cin>>n>>m>>q;
    string s[n];
    rep(i,0,n-1)cin>>s[i];
    ll a[n+1][m+1];memset(a,0,sizeof(a));
    rep(i,1,n)rep(j,1,m){
        a[i][j]+=a[i][j-1];
        if(s[i-1][j-1]=='1')a[i][j]++;
    }
    rep(j,1,m)rep(i,1,n){
        a[i][j]+=a[i-1][j];
    }
    //rep(i,0,n){rep(j,0,m)cout<<a[i][j]<<" ";cout<<endl;}
    ll b[n+1][m];memset(b,0,sizeof(b));
    rep(i,0,n-1){
        rep(j,0,m-2){
            b[i+1][j+1]+=b[i+1][j];
            if(s[i][j]==s[i][j+1]&&s[i][j]=='1')b[i+1][j+1]++;
        }
    }
    rep(i,0,n-1)rep(j,0,m-1)b[i+1][j]+=b[i][j];
    
    ll c[n][m+1];memset(c,0,sizeof(c));
    rep(j,0,m-1){
        rep(i,0,n-2){
            c[i+1][j+1]+=c[i][j+1];
            if(s[i][j]==s[i+1][j]&&s[i][j]=='1')c[i+1][j+1]++;
        }
    }
    rep(i,0,n-1)rep(j,0,m-1)c[i][j+1]+=c[i][j];
    
    while(q--){
        ll x1,y1,x2,y2;cin>>x1>>y1>>x2>>y2;x1--;y1--;x2--;y2--;
        ll ans=a[x2+1][y2+1]+a[x1][y1]-a[x1][y2+1]-a[x2+1][y1];
        ll m1=0,m2=0;
        if(y1<y2){
            m1=b[x2+1][y2]+b[x1][y1]-b[x1][y2]-b[x2+1][y1];
        }
        if(x1<x2){
            m2=c[x2][y2+1]+c[x1][y1]-c[x1][y2+1]-c[x2][y1];
        }
        cout<<ans-m1-m2<<endl;
        
    }
    
    
    return 0;
}


Measured memory_bytes: 99840
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#define ll long long
using namespace std;
int main(){
    vector<int> abc(3);
    vector<int> sumabc(3);
    for(int i=0;i<abc.size();i++){
        cin>>abc[i];
    }
    sort(abc.begin(),abc.end());
    int k;
    cin>>k;
    int sum=0;
    for(int i=0;i<abc.size()-1;i++){
        sum+=abc[i];
    }
    
    cout<<sum+pow(2,k)*abc.back()<<endl;
    return 0;
}

Measured memory_bytes: 256
def c_splitting_pile(N, A):
    # Aの要素の総和をX、カードの山の先頭i枚の総和をxとすると、
    # |y-x|=|X-2x|である。各i(1<=i<=N-1)についてこの値を計算すればよい
    from itertools import accumulate
    total = sum(A)
    return min([abs(total - 2 * x) for x in accumulate(A[:-1])])

N = int(input())
A = [int(i) for i in input().split()]
print(c_splitting_pile(N, A))

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

void solve()
{
    int n;
    cin >> n;
    string s;
    map<string, int> m;
    m["AC"] = 0;
    m["WA"] = 0;
    m["TLE"] = 0;
    m["RE"] = 0;
    for (int i = 0; i < n; i++)
    {
        cin >> s;
        m[s]++;
    }
    cout << "AC x " << m["AC"] << endl;
    cout << "WA x " << m["WA"] << endl;
    cout << "TLE x " << m["TLE"] << endl;
    cout << "RE x " << m["RE"] << endl;
}

int main()
{
    int t = 1;
    // cin >> t;
    while (t--)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int k,n;
	cin>>k>>n;
	int a[n+1];
	for(int i=1;i<=n;++i)
		cin>>a[i];
	int b[n+1];
	for(int i=1;i<=n-1;++i)
		b[i]=a[i+1]-a[i];
	b[n]=k-a[n]+a[1];
	int maxv=0;
	for(int i=1;i<=n;++i)
		maxv=max(maxv,b[i]);
	cout<<k-maxv<<endl;
	return 0;
}

Measured memory_bytes: 1792
#include<iostream>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<math.h>
#include<cstring>
using namespace std;

int main()
{
	
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    int k;
    cin>>k;
    
    string s;
    cin>>s;
    
    int n=s.size();
    int i;
    if(n<=k){
      cout<<s<<endl;	
	}
	
	else if(n>k){
	  for(i=0;i<k;i++){
	     cout<<s[i];	
	  }	
	  cout<<"..."<<endl; 
	  	
	}
    
     return 0;
     
}

Measured memory_bytes: 3632
# ABC127D - Integer Cards
import sys
input = sys.stdin.readline

n, m = list(map(int, input().rstrip().split()))
num = sorted(list(map(int, input().rstrip().split())))
lst = sorted([tuple(map(int, input().rstrip().split())) for _ in range(m)], key=lambda x:x[1], reverse=True)
ans = 0
idx = 0
flg = False
for i, j in lst:
    for _ in range(i):
        if idx < n and num[idx] < j:
            ans += j
            idx += 1
        else:
            flg = True
            break
    if flg:
        break
if idx < n:
    ans += sum(num[idx:])
print(ans)

Measured memory_bytes: 23224
// #includes {{{
#include <bits/stdc++.h>
using namespace std;
// }}}
// pre-written code {{{
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define RREP(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();++i)
#define LET(x,a) __typeof(a) x(a)
//#define IFOR(i,it,c) for(__typeof((c).begin())it=(c).begin();it!=(c).end();++it,++i)
#define ALL(c) (c).begin(), (c).end()
#define MP make_pair

#define EXIST(e,s) ((s).find(e)!=(s).end())

#define RESET(a) memset((a),0,sizeof(a))
#define SET(a) memset((a),-1,sizeof(a))
#define PB push_back
#define DEC(it,command) __typeof(command) it=command

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define debug2(x) cerr << #x << " = [";REP(__ind,(x).size()){cerr << (x)[__ind] << ", ";}cerr << "] (L" << __LINE__ << ")" << endl;

const int INF=0x3f3f3f3f;

typedef long long Int;
typedef unsigned long long uInt;
typedef long double rn;

typedef pair<int,int> pii;

/*
#ifdef MYDEBUG
#include"debug.h"
#include"print.h"
#endif
*/
// }}}

const int mod = 1000000007;

//{{{ modular algebra
struct Num{
	int v;
	Num(int n):v(n){}
	Num(){}
	operator int() const {return v;}
	operator long long() const {return v;}
	void operator =(int n){v=n;}

	template<class T>
		inline void operator *=(const T &a) {
			v = (v*(long long)a)%mod;
		}
	template<class T>
		inline Num operator *(const T &a) {
			Num n(*this);n*=a;
			return n;
		}
	template<class T>
		inline void operator+=(const T &a){
			v+=(int)a;
			if(v>=mod)v-=mod;
			//	assert(0<=v and v<mod);
		}
	template<class T>
		inline Num operator+(const T &a){
			Num n(*this);n+=a;
			return n;
		}
	inline Num operator -(){
		if(v==0)return v;
		else return Num(mod-v);
	}
	template<class T>
		inline void operator -=(const T &a){
			v-=(int)a;
			if(v<0)v+=mod;
		}
	template<class T>
		inline Num operator -(const T &a){
			Num n(*this);n-=a;
			return n;
		}
#ifdef __GCD_H
	inline Num inv(){
		return invMod(this->v,mod);
	}
	template<class T>
		inline void operator /=(const T &a){
			(*this)*=invMod((int)a,mod);
		}
	template<class T>
		inline Num operator /(const T &a){
			Num n(*this);n/=a;
			return n;
		}
#endif
};

ostream& operator <<(ostream &os,const Num &n){
	os<<(int)n.v;
	return os;
}

istream& operator >>(istream &is, const Num &n){
	is>>(int)n.v;
	return is;
}
//}}}

const int N=1000;
int pdiv[N];
//{{{ eratosthenes
void sieve_of_eratosthenes(int n) {
	for (int i = 2; i < n; ++i)
		pdiv[i] = i;
	for (int i = 2; i*i < n; ++i)
		if (pdiv[i]==i)
			for (int j = i*i; j < n; j+=i)
				pdiv[j] = i;
}
//}}}

int main(){
	sieve_of_eratosthenes(N);
	Num ans(1);
	int n;
	cin>>n;
	for(int p=2;p<=n;p++){
		if(pdiv[p]!=p)continue;
		int n_ = n, s = 0;
		while(n_>0){
			n_/=p;
			s+=n_;
		}
		ans*=s+1;
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n,a,k,ans;
int find(int a,int k){
	if(!(a%k))return a/k;
	if(a < k)return 0;
	int by = a/k + 1;
	if(a/k > (a - by)/k)return find(a - by,k);
	int to = a%k + by - 1;
	return find(a - to/by*by,k);
}
int main(){
//	freopen("readin.txt","r",stdin);
	scanf("%d",&n);
	for(int i = 0;i < n;i++){
		scanf("%d%d",&a,&k);
		ans^=find(a,k);
	}
	puts(ans ? "Takahashi" : "Aoki");
}

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

using namespace std ;

const int MAX = 2e5 + 10 ;

int arr[MAX] ;
int n , k ;

int main()
{
	ios_base::sync_with_stdio(0) ;
	cin.tie(0) ;
	cin>>k>>n ;
	for(int i = 0 ; i < n ; ++i)
		cin>>arr[i] ;
	int ans = 1e9 ;
	for(int i = 0 ; i < n ; ++i)
	{
		int x = 1e9 ;
		if(i != 0)
			x = min(x , k - arr[i] + arr[i-1]) ;
		if(i == 0)
			x = min(x , arr[n-1] - arr[i]) ;
		if(i != n-1)
			x = min(x , arr[i] + k - arr[i+1]) ;
		if(i == n-1)
			x = min(x , arr[i] - arr[0]) ;
		ans = min(ans , x) ;
	}
	return cout<<ans<<"\n" , 0 ;
}		

Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <array>
#include <vector>

using namespace std;

typedef long long int LLI;

void swap( vector<LLI> &vs, int i, int j ) {
  int val = vs[ i ];
  vs[ i ] = vs[ j ];
  vs[ j ] = val;
}

void print( vector<LLI> vs ) {
  cerr << "[";
  for ( LLI val : vs ) {
    cerr << val << ", ";
  }
  cerr << "]" << endl;
}

int calc ( vector<LLI> &vs, int k, int n ) {
  LLI prod = 1;
  for ( int i = 0; i < k; i++ ) {
    prod *= vs[ i ];
  }
  LLI ans = prod;
  for ( int i = k; i < n; i++ ) {
    prod /= vs[ i - k ];
    prod *= vs[ i ];
    ans = max( prod, ans );
  }
  return ans;
}

int main() {
  while( true ) {
    int n, k;
    cin >> n >> k;
    if ( n == 0 and k == 0 ) break;
    vector<LLI> vs( n );
    for ( int i = 0; i < n; i++ ) {
      cin >> vs[ i ];
    }
    int init_score = calc( vs, k, n );
    int max_score = -10000;
    for ( int i = 0; i < n; i++ ) {
      for ( int j = i + 1; j < n; j++ ) {
	swap( vs, i, j );
	int score = calc( vs, k, n );
	max_score = max( max_score, score );
	swap( vs, i, j );
      }
    }
    if ( max_score < init_score ) {
      cout << "NO GAME" << endl;
    } else {
      cout << max_score - init_score << endl;
    }
  }
}

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

int main() {
    int x, y, z;
    cin >> x >> y >> z;
    int i, sum;

    i = 0;
    sum = z;
    while (sum <= x) {
        sum += y + z;
        ++i;
    }
    cout << i - 1 << endl;

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void){
    int i;
    int n;
    int orig[1000];
    int x;
    int sum;
    int m;
    int key;
    int d;
    scanf("%d",&n);
    orig[0]=0;
    sum=0;
    for (i=0;i<n;i++) {
        scanf("%d",&x);
        sum+=x;
        orig[i+1]=x;
    }
    scanf("%d",&m);
    for(i=0;i<m;i++){
        scanf("%d %d",&key,&d);
        printf("%d\n",sum-orig[key]+d);
    }
    return 0;
}


Measured memory_bytes: 128
#include<cstdio>
#include<iostream>
#include<vector>
#include<algorithm>
typedef long long ll;
using namespace std;

int main() {
	vector<int> a;
	int N,n;
	scanf("%d", &N);
	for (int i = 0; i < 2 * N; i++) {
		scanf("%d", &n);
		a.push_back(n);
	}
	sort(a.begin(), a.end());
	int sum = 0;
	for (int i = 0; i < N; i++) {
		sum += a[2 * i];
	}
	cout << sum << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main () {
    int h, w;

    while (true) {
        cin >> h >> w;

        if (h == 0 && w == 0) break;

        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                if (i == 0 || i == h - 1 || j == 0 || j == w - 1) cout << '#';
                else cout << '.';
            }
            cout << endl;
        }
        cout << endl;
    }
}


Measured memory_bytes: 3068
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include<algorithm>
#include <iomanip>

using namespace std;
typedef long long ll;
///定義場所///
int i, j, k, l, m, n;
int N, M, K;
ll MOD = 1000000007;
int ans = 0;
//関数リスト//
int ctoi(char c) {
	switch (c) {
	case '0': return 0;
	case '1': return 1;
	case '2': return 2;
	case '3': return 3;
	case '4': return 4;
	case '5': return 5;
	case '6': return 6;
	case '7': return 7;
	case '8': return 8;
	case '9': return 9;
	default: return 0;
	}
}
//(注)pairの型・比較する場所(first/second)は毎回変えて使用する
bool pairCompare(const pair<ll, ll> firstElof, pair<ll, ll> secondElof)
{
	return firstElof.second > secondElof.second;
}
//////////////
int main()
{
	int A, P;
	cin >> A >> P;
	cout << (A * 3+P) / 2;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
using namespace std;
using ll = long long;
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; }
const ll INF = 1e9;
const ll MOD = 1e9 + 7;



int main(){
    int a, b, c, x, y;
    cin >> a >> b >> c >> x >> y;

    int ans = INF;
    rep(i, max(x, y) + 1){
        int cost = a*max(0, x-i) + b*max(0, y-i) + 2*c*i;
        chmin(ans, cost);
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include<algorithm>
#include <stdio.h>
#include <string>
#include <string.h>
#include <map>
#include <math.h>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <deque>
//#include <bits/stdc++.h>
using namespace std;
typedef  long long ll;
int main()
{
    int n,a,b;
    cin>>n>>a>>b;
    cout<<min(n*a,b)<<endl;
    return 0;
}

Measured memory_bytes: 256
N, K = map(int, input().split())
p = list(map(int, input().split()))


def calc(x):
    return (x+1)/2


pe = []
for i in range(N):
    pe.append(calc(p[i]))

cs = [pe[0]] + [0]*(N-1)

for i in range(1, N):
    cs[i] = pe[i] + cs[i-1]

ans = cs[K-1]
for i in range(K, N):
    wa = cs[i] - cs[i-K]
    ans = max(ans, wa)

print(ans)





Measured memory_bytes: 33972
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
using namespace std;
constexpr int kMod = 1000000007;
typedef long long LL;

int N;

LL dfs(LL x, bool b3, bool b5, bool b7) {
  if (x > N) return 0;
  LL cnt = (b3 && b5 && b7) ? 1 : 0;

  x *= 10;
  cnt += dfs(x + 3, true, b5, b7);
  cnt += dfs(x + 5, b3, true, b7);
  cnt += dfs(x + 7, b3, b5, true);
  return cnt;
}

int main() {
  cin >> N;
  LL cnt = dfs(3, true, false, false);
  cnt += dfs(5, false, true, false);
  cnt += dfs(7, false, false, true);
  cout << cnt <<endl;
}


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

Measured memory_bytes: 584