akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <vector>
using namespace std;

vector<int> G;
int cnt = 0;
void insertionSort(int*p,int n,int g) {
	for (int i = g; i < n; i++) {
		int v = p[i];
		int j = i - g;
		while (j >= 0 && p[j] > v) {
			p[j + g] = p[j];
			j -= g;
			cnt=cnt+1;
		}
		p[j + g] = v;
	}
}

void shellSort(int*p, int n) {
	for (int h = 1;;) {
		if (h > n) break;
		G.push_back(h);
		h = 3 * h + 1;
	}
	
    for (int i= G.size()-1;i>=0;i--)
	{
		insertionSort(p, n, G[i]);
	}
}

int main()
{
	int n;
	int*seq;
	scanf("%d", &n);
	seq = new int[n];
	for (int i = 0; i < n; i++)
		scanf("%d", &seq[i]);


	shellSort(seq, n);
	printf("%d \n", G.size());
	for (int i = G.size()-1; i >= 0; i--) {
		printf("%d ", G[i]);
		if (i) printf(" ");
	}
	printf("\n%d\n", cnt);
	for (int i = 0; i < n; i++)
		printf("%d\n", seq[i]);



    return 0;
}

Measured memory_bytes: 6548
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;

#define MOD 1000000007

typedef long long ll;

ll fac[222222] = {1, 1};
ll inv[222222] = {1, 1};
ll fiv[222222] = {1, 1};


//ll combination(ll n, ll r)
//{
//    return fac[n] * fiv[r] % MOD * fiv[n - r] % MOD;
//}

ll permutation(ll n, ll r)
{
	ll i, ret = 1;

	for (i = n; i >= n - r + 1; i--)
		ret = ret * i % MOD;

	return ret;
}

ll pow2(ll n)
{
	if (!n)
		return 1;

	ll t = pow2(n / 2);

	if (n % 2 == 0)
		return t * t % MOD;
	else
		return t * t % MOD * 2 % MOD;
}

int main(void)
{
	ll n, a, b, i;

	scanf("%lld %lld %lld" ,&n, &a, &b);

	for (ll i = 2; i <= max(a, b); i++)
	{
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = inv[MOD % i] * (MOD - MOD / i) % MOD;
		fiv[i] = fiv[i - 1] * inv[i] % MOD;
	}

	ll ans = pow2(n) - permutation(n, a) * fiv[a] % MOD - permutation(n, b) * fiv[b] % MOD - 1;

	printf("%lld" ,(ans + 2 * MOD) % MOD);
	return 0;
}

Measured memory_bytes: 4864
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <bitset>
using namespace std;

typedef pair<int, int> P;
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define index(xs, x) (int)(lower_bound(all(xs), x) - xs.begin())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
vector<P> group(vector<P> all, int D) {
  vector<P> ret;
  if (D%2) {
    // (x+y)%2
    for (P p : all) if ((p._1+p._2)%2 == 0) ret.pb(p);
  }
  else if (D%4 == 2) {
    // x%2
    for (P p : all) if (p._1%2 == 0) ret.pb(p);
  }
  else {
    rep(a, 2) rep(b, 2) {
      vector<P> seq;
      for (P p : all) if (p._1%2 == a && p._2%2 == b) seq.pb(P((p._1-a)/2, (p._2-b)/2));
      vector<P> q = group(seq, D/4);
      for (P p : q) ret.pb(P(p._1*2+a, p._2*2+b));
    }
  }
  return ret;
}

int N, D1, D2;
int T[600][600];
vector<P> G[4];

signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  cin >> N >> D1 >> D2;
  vector<P> all;
  rep(i, 2*N) rep(j, 2*N) all.pb(P(i, j));
  vector<P> g1 = group(all, D1);
  for (P p : g1) T[p._1][p._2] |= 1;
  vector<P> g2 = group(all, D2);
  for (P p : g2) T[p._1][p._2] |= 2;
  for (P p : all) G[T[p._1][p._2]].pb(p);

  rep(k, 4) if (G[k].size() >= N*N) {
    rep(i, N*N) {
      cout << G[k][i]._1 << " " << G[k][i]._2 << "\n";
    }
    return 0;
  }
  abort();
}


Measured memory_bytes: 17516
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        String[] t = new String[]{"dream", "dreamer", "erase", "eraser"};
        
        int i = s.length();
        while(i > 0) {
            int j = 0;
            for(; j < t.length; j++) {
                String str = t[j];
                if(i - str.length() >= 0 && s.substring(i - str.length(), i).equals(str)) {
                    i = i - str.length();
                    break;
                }
            }
            if(j == t.length) {
                System.out.println("NO");
                return;
            }
        }
        
        System.out.println("YES");
    }
}


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

int main(){
  ll N,X,T ;
  cin >> N >> X >> T;
  
  cout << int(ceil(N*1.0/X)*T) << endl;
  return 0; 
}

Measured memory_bytes: 3628
s = list(input())
del s[-1]

for i in range(1,len(s)):
    if len(s) % 2 == 1:
        del s[-1]
    else:
        if s[:int(len(s)/2)] == s[int(len(s)/2):]:
            print(len(s))
            exit()
        else:
            del s[-1]


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

using namespace std;

class DisjointSet {
    public:
        vector<int> rank, p;
        
        DisjointSet() {}
        DisjointSet(int size){
            rank.resize(size, 0);
            p.resize(size, 0);
            for(int i = 0; i < size; i++) makeSet(i);
        }
        
        void makeSet(int x){
            p[x] = x;
            rank[x] = 0;
        }
        
        bool same(int x, int y){
            return findSet(x) == findSet(y);
        }
        
        int findSet(int x){
            if(x != p[x]){
                p[x] = findSet(p[x]);
            }
            
            return p[x];
        }
        
        void unite(int x, int y){
            link(findSet(x), findSet(y));
        }
        
        void link(int x, int y){
            if(rank[x] > rank[y]){
                p[y] = x;
            } else {
                p[x] = y;
                if(rank[x] == rank[y]){
                    rank[y]++;
                }
            }
        }
};

int main(void){
    int N, M;
    cin >> N >> M;
    int a[M], b[M];
    
    for(int i = 0; i < M; i++){
        cin >> a[i] >> b[i];
        a[i]--;
        b[i]--;
    }
    
    int ans = 0;
    for(int i = 0; i < M; i++){
        DisjointSet ds = DisjointSet(N);
        for(int j = 0; j < M; j++){
            if(j != i && !ds.same(a[j], b[j])){
                ds.unite(a[j], b[j]);
            } 
        }
        
        int cnt = 0;
        for(int k = 0; k < N; k++){
            if(k==ds.findSet(k)) cnt++;
        }
        if (cnt > 1) ans++;
    }
    
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 256
n, k = map(int, input().split())
mod = 10**9+7
g1 = [1, 1]
g2 = [1, 1]
inv = [0, 1]
for i in range(2, n+1):
    g1.append((g1[-1] * i) % mod)
    inv.append((-inv[mod%i] * (mod//i)) % mod)
    g2.append((g2[-1] * inv[-1]) % mod)

def comb(n, r):
    if r<0 or r>n:
        return 0
    return g1[n] * g2[r] * g2[n-r] % mod

li = []
for i in range(min(k, n-1)+1):
    li.append(comb(n-1, i))
ans = 0
pre = 0
for cur in li:
    ans += (pre+cur)*cur
    pre = cur
print(ans%mod)

Measured memory_bytes: 35016
n, k = gets.chop.split.map(&:to_i)


h = Hash.new(0)

n.times do |i|
  a, b = gets.chop.split.map(&:to_i)
  h[a] += b
end


num = 0

h.sort.each do |key, value|

  num += value

  if num >= k
    p key
    exit
  end
end


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

ans = N
for i in range(M - 1):
    p = [0] * M
    for j in range(N):
        p[A[j][0] - 1] += 1
    mp = max(p)
    MM = p.index(mp) + 1
    ans = min(ans, mp)
    for j in range(N):
        A[j].remove(MM)

print(ans)

Measured memory_bytes: 4212
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <set>
#include <queue>
using namespace std;
int main(void){
    int n;
    cin>>n;
    vector<string> u(n);
    for(int i=0;i<n;i++)cin>>u[i];
    int m;
    cin>>m;
    int a=0;
    for(int i=0;i<m;i++){
        string t;
        cin>>t;
        for(int j=0;j<n;j++){
            if(t==u[j]){
                if(a==0){
                    cout<<"Opened by "<<t<<endl;
                    a=1;
                }
                else{
                    cout<<"Closed by "<<t<<endl;
                    a=0;
                }
                break;
            }
            if(j==n-1)cout<<"Unknown "<<t<<endl;
        }
    }
    return 0;
}



Measured memory_bytes: 3212
//is there any case of -1 or any special corner cases ?
#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";
#define test int t;cin>>t;while(t--) 
const int maxx  = 3*1e5 , limit = 9*1e18 , MOD=1e9+7;
#define boost  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl '\n';
int32_t main(){
    boost;
    
    
    int a,b;
    cin>>a>>b;
    cout<<a*b<<endl;
}

Measured memory_bytes: 3640
//Sani buyuk Osman Pasa Plevneden cikmam diyor.
//Bismillahirrahmanirrahim
#include <bits/stdc++.h>

using namespace std;

typedef long long int lo;
typedef pair< int,int > PII;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define FOR for(int i=1;i<=n;i++)
#define mid (bas+son)/2

const lo MAX = -1000000000000000000; 
const lo MIN = 1000000000000000000; 
const lo inf = 1000000000; 
const lo KOK = 100000; 
const lo LOG = 30; 
const lo li = 100005; 
const lo mod = 1000000007; 

lo n,m,cev,b,a[li],k;
string s;
vector<int> v;

int main(){
	scanf("%lld %lld %lld %lld",&n,&m,&k,&b);
	printf("%lld\n",n*m-(k*m+n*b-k*b));
	return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.math.*;

public class Main {
	public static void main(String[] args){
		
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
      
      if(s.equals("ABC")) {System.out.println("ARC");}
      else if(s.equals("ARC")) {System.out.print("ABC");}
       
	}
}

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

int main()
{
    int N;
    cin >> N;
    int A[101];
    for(int i=0;i<N;i++)
    {
        cin >> A[i];
        if(A[i]%2==0)
        {
            if(A[i]%3==0 || A[i]%5==0)
            {
                continue;
            } else {
                cout << "DENIED" << endl;
                return 0;
            }
        }
    }
    cout << "APPROVED" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef int64_t LL;
#define rep(i,N) for(LL i=0;i<(int)N;i++)
const int MOD=1e9+7;
const LL SCORE=1LL<<20,Z=pow(SCORE,2)+SCORE+1;
int main()
{
  int N;
  LL A=0,x,y;
  vector<LL> bit(20,0);
  cin>>N;
  while(cin>>x)rep(i,20)bit.at(i)+=x>>i&Z,x>>1;
  rep(i,20){x=bit.at(i);rep(j,3){y=x&SCORE-1;x/=SCORE;A=fmod(A+fmod(y%MOD*(N-y)%MOD*pow(2,i+20*j),MOD),MOD);}}
  return cout<<A<<endl,0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define rep(i,s,n) for(int i = (s); i < (n); i++)
#define all(v) v.begin(), v.end()
#define allg(v) v.begin(), v.end(), greater<int>()



signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  string s;
  int x, y, z;
  cin >> x >> y >> z;
  
  //vector<int> a(n);  rep(i, 0, n) cin >> a[i];
  
  cout << z << " " << x << " " << y << "\n";
  
  //cout << (  ?"Yes" :"No") << "\n";
  
  //cout << fixed << setprecision(15) << n << "\n";

}

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

// 総数を1000000007（素数）で割った余り
const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

int main(){
    int k, a, b;
    cin >> k >> a >> b;
    if (a <= b/k*k) cout << "OK" << endl;
    else cout << "NG" << endl;
    return 0;
}


Measured memory_bytes: 3628
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdio>
#include<sstream>
#include<iomanip>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef pair<int,pii> pip;
typedef vector<pip>vip;
const double PI=acos(-1);
const double EPS=1e-8;
const int inf=1e8;
struct UnionFind{
    vector<int> data;
    UnionFind(int size) : data(size, -1) {}
    bool unionSet(int x,int y){
        x=root(x);y=root(y);
        if(x==y)return 0;
        if(data[y]<data[x])swap(x,y);
        data[x]+=data[y],data[y]=x;
        return 1;
    }
    bool findSet(int x,int y){
        return root(x)==root(y);
    }
    int root(int x){
        return data[x]<0 ? x : data[x]=root(data[x]);
    }
    int size(int x){
        return -data[root(x)];
    }
};
class KRK{//c++11
	public:
	struct edge{
		int from,to,cost;
	};
	vector<edge>G;
	int n,m;
	KRK(int size1,int size2){
		n=size1;
		m=size2;
	}
	void add_edge(int a,int b,int c){
		edge e={a,b,c};
		G.pb(e);
	}
	int krk(){
		int sum=0;
		sort(all(G),[](edge a,edge b){
			return a.cost<b.cost;
		});
		UnionFind uf(n+m);
		rep(i,G.size()){
			edge e=G[i];
			bool h1=false,h2=false;
			rep(j,n){
				if(uf.findSet(e.from,m+j))h1=true;
				if(uf.findSet(e.to,m+j))h2=true;
			}
			if(h1+h2!=2&&!uf.findSet(e.from,e.to)){
				sum+=e.cost;
				uf.unionSet(e.from,e.to);
			}
		}
		return sum;
	}
};
int main(){
	int n,m;
	while(cin>>n>>m,n||m){
		KRK krk(n,m);
		rep(i,n)rep(j,m){
			int a;cin>>a;
			if(a)krk.add_edge(j,m+i,a);
		}
		rep(i,m-1)rep(j,m-i-1){
			int a;cin>>a;
			if(a)krk.add_edge(i,i+j+1,a);
		}
		cout<<krk.krk()<<endl;
	}
}

Measured memory_bytes: 3188
/*
 * author :Sadik Hassan(_sad_)
 *
*/
#include "bits/stdc++.h"
using namespace std;
using ll=            long long;
using ld=            long double;
#define nl            "\n"
#define pb            push_back
#define fi            first
#define se            second
#define MP            make_pair
#define PI            (acos(-1.0))
#define rep1(i,n)     for(int i=1;i<=n;i++)
#define rep(i,n)      for(int i=0;i<n;i++)
#define SZ(s)         (int)s.size()
#define all(x)        (x).begin(), (x).end()
#define rall(x)       (x).rbegin(), (x).rend()
#define w(t)          int t;cin>>t;while(t--)
#define TSU(s)        transform(s.begin(),s.end(),s.begin(),::toupper);
#define TSL(s)        transform(s.begin(),s.end(),s.begin(),::tolower);
#define _SAD()     	  ios::sync_with_stdio(0),cin.tie(0),cout.tie(0),cout<<fixed<<setprecision(15);

typedef vector<int> vi;
typedef vector<ll> vii;
typedef set<int> si;
typedef set<ll> sii;
/*---------------------------------------------------------------------*/

const int N = (int)1e6+1;
const int MOD =(int)1e9+7;
const ll INF = (ll)1e18+5;

int main()
{
    _SAD()
    int n;
    cin>>n;
    vi a(n),b(n);
    rep(i,n)
    {
        cin>>a[i];
        b[i]=a[i];
    }
    sort(all(b));
    int x=b[n-1],y=b[n-2];
    for(int i=0;i<n;i++)
    {
        if(a[i]==x)
        {
            cout<<y<<nl;
        }
        else cout<<x<<nl;
    }
    return 0;
}


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

string s;
stack<int>st;
bool f;
int a;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> s;
	for(auto i:s){
		if(i == '*'){
			f = true;
		}else if(i == '('){
			if(!f){
				st.push(1);
			}else{
				st.push(0);
			}
		}else{
			if(f){
				a += st.top();
			}
			st.pop();
		}
	}
	cout << a << "\n";
}


Measured memory_bytes: 3220
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int Max = 1000000;
int main(){
  	ll N;
    cin >> N;
    char S[N];
    vector<ll> R, G, B;

    for(ll i=0;i<N;i++){
      cin >> S[i];
      if(S[i]=='R'){
        R.push_back(i);
      }else if(S[i]=='G'){
        G.push_back(i);
      }else{
        B.push_back(i);
      }
    }

    ll cR = R.size();
    ll cG = G.size();
    ll cB = B.size();

    ll ans = 0;
    for(ll i=0;i<cR;i++){
      for(ll j=0;j<cG;j++){
        ll tmp = cB;
        if((R[i]+G[j])%2==0){
          if(S[(R[i]+G[j])/2]=='B') tmp -= 1;
        }
        if(0<= 2*R[i]-G[j] && 2*R[i]-G[j]<N && S[2*R[i]-G[j]]=='B'){
          tmp -= 1;
        }
        if(0<= 2*G[j]-R[i] && 2*G[j]-R[i]<N && S[2*G[j]-R[i]]=='B'){
          tmp -= 1;
        }
        ans += max(tmp, ll(0));
      }
    }
    cout << ans <<endl;

  	return 0;
}

Measured memory_bytes: 3628
using System;
class Program{
	static void Main(){
		int[] s=Array.ConvertAll(Console.ReadLine().Split(),int.Parse);
		bool[] b=new bool[s[0]+1];
		int[] h=new int[s[0]+1];
		int ans=1;
		b[1]=true;
		for(int i=1;i<=s[0];i++){h[i]=1;}
		for(int i=0;i<s[1];i++){
			int[] q=Array.ConvertAll(Console.ReadLine().Split(),int.Parse);
			h[q[0]]--;
			h[q[1]]++;
			if(b[q[0]]&&(!b[q[1]])){b[q[1]]=true;ans++;}
			if(h[q[0]]==0&&b[q[0]]){b[q[0]]=false;ans--;}
		}
		Console.WriteLine("{0}",ans);
	}
}

Measured memory_bytes: 17408
s = input()
if len(set(s)) <= 1:
    print(0)
    import sys
    sys.exit()

def resolve(target):
    depth = 0
    now = s
    while len(set(now)) > 1:
        result = list(now[:-1])
        for i, x in enumerate(now[:-1]):
            result[i] = now[i + 1] if now[i + 1] == target else now[i]
        now = "".join(result)
        depth += 1
    return "".join(result), depth


print(min([resolve(chr(target)) for target in range(ord("a"), ord("x") + 1)], key=lambda x: x[1])[1])


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
long long n,k,ans=0,a=1;
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>n>>k;
	while(n>=a) {
		a*=k;
		ans++;
	}
	cout<<ans<<endl;
	return 0;
}



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

typedef 
struct {
  size_t index;
  char suit;
  int num;
} card;

void swap(card* p, size_t n, size_t m) {
  card t = {p[n].index,
    p[n].suit,
    p[n].num};

  p[n].index = p[m].index;
  p[n].suit = p[m].suit;
  p[n].num = p[m].num;

  p[m].index = t.index;
  p[m].suit = t.suit;
  p[m].num = t.num;
}


void bubble_sort(card* inout_arr, size_t n) {
  for (int p = 0; p < n; p++) {
    for (int q = n - 1; p < q; q--) {
      if (inout_arr[q].num < inout_arr[q - 1].num) {
        swap(inout_arr, q, q - 1);
      }
    }
  }
}

void selection_sort(card* p, size_t n) {
  for (int m = 0; m < n; m++) {
    int minj = m;

    for (int k = m; k < n; k++) {
      if (p[k].num < p[minj].num) {
        minj = k;
      }
    }

    swap(p, minj, m);
  }
}

void show_cards(card* in_arr, size_t n) {
  for (size_t m = 0; m < n - 1; m++) {
    printf("%c%d ", in_arr[m].suit, in_arr[m].num);
  }

  printf("%c%d\n", in_arr[n - 1].suit, in_arr[n - 1].num);
}

int stablep(card* in_arr, size_t n) {
  int rv = 1;
  
  for (int p = 1; p < n; p++) {
    if (in_arr[p - 1].num == in_arr[p].num) {
      if (in_arr[p].index < in_arr[p - 1].index) {
        rv = 0;
      }
    }
  }

  return rv;
}

void answer(card* in_p, size_t n) {
  show_cards(in_p, n);
  printf("%s\n", stablep(in_p, n) ? "Stable" : "Not stable");
}

int main() {
  int n = 0;

  scanf("%d\n", &n);

  card *p_cards = calloc(n, sizeof(card));
  card *p_bsort = calloc(n, sizeof(card));
  card *p_ssort = calloc(n, sizeof(card));
 
  for (int m = 0 ; m < n; m++) {
    char c;
    int k;
    
    scanf("%c%d ", &c, &k);
    p_cards[m].index = m;
    p_cards[m].suit = c;
    p_cards[m].num = k;
  }

  memmove(p_bsort, p_cards, n * sizeof(card));
  memmove(p_ssort, p_cards, n * sizeof(card));

  bubble_sort(p_bsort, n);
  answer(p_bsort, n);

  selection_sort(p_ssort, n);
  answer(p_ssort, n);

  free(p_ssort); p_ssort = NULL;
  free(p_bsort); p_bsort = NULL;
  free(p_cards); p_cards = NULL;

  return 0;
}



Measured memory_bytes: 2104
k = 1
while true
  n = gets.to_i
  break if n == 0
  p = []
  n.times{ p << gets.split.map(&:to_f) }
  n.times{ |i| p[i] += p[(i+1) % n] }
  s = p.map{ |x0, x1, y0, y1| x1*y0 - x0*y1 }.inject(:+) / 2
  puts "#{k} %.1f" % s
  k += 1
  gets
end

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

#define ll long long
#define INF 99999999
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

template < typename T > std::string to_string( const T& n )
{
    std::ostringstream stm ;
    stm << n ;
    return stm.str() ;
}

int main()
{
    int N,X;
    cin >> N >> X;

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

    vector<int> dp(1,0);
    ll ans = 1;
    rep(i,N)
    {
        dp.push_back(dp[dp.size()-1] + L[i] );
        if( dp[dp.size()-1] <= X )ans++;
    }
    cout << ans << endl;

}


Measured memory_bytes: 256
N,Q=map(int,input().split())
S=input()
LR=[]
for i in range(Q):
    LR.append(list(map(int, input().split())))

L=[0]*N
R=[0]*N
for i in range(N-1):
    if S[i]=='A' and S[i+1]=='C':
        L[i]+=1
for i in range(1,N):
    L[i]+=L[i-1]

for i in range(1,N):
    if S[i]=='C' and S[i-1]=='A':
        R[i]+=1
for i in range(1,N):
    R[i]+=R[i-1]

for i in range(Q):
    print(min(L[LR[i][1]-1],R[LR[i][1]-1])-\
          min(L[LR[i][0]-1],R[LR[i][0]-1]))

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

using namespace std;
typedef long long ll;
#define rep(i,j,n) for (ll i = j; i < (n); i++)
#define CLR(mat,f) memset(mat, f, sizeof(mat))
#define IN(a, b, x) (a<=x&&x<b)
#define out(ans) cout << ans << endl
typedef pair<ll,ll>P;
const ll mod=1e9+7;
const int INF = 1000000;
const double PI=3.14159265359;

int main(){

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

  out(t+s);

  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cstring>
const int maxn=2000+10;
int cnt[maxn][maxn],cntr[maxn][maxn],cntd[maxn][maxn];
int query(int cnt[maxn][maxn],int x1,int y1,int x2,int y2)
{
    return cnt[x2][y2]-cnt[x2][y1-1]-cnt[x1-1][y2]+cnt[x1-1][y1-1];
}
int read()
{
    char ch=getchar();
    int x=0,f=1;
    while(!isdigit(ch))
    {
        f=((ch=='-')?-f:f);
        ch=getchar();
    }
    while(isdigit(ch))
    {
        x=x*10+ch-'0';
        ch=getchar();
    }
    return f<0?-x:x;
}
int get01()
{
    char ch=getchar();
    while(ch!='0'&&ch!='1') ch=getchar();
    return ch-'0';
}
int n,m,q;
int main()
{
    memset(cnt,0,sizeof cnt);
    memset(cntd,0,sizeof cntd);
    memset(cntr,0,sizeof cntr);
    n=read();m=read();q=read();
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++) cnt[i][j]=get01();
    }
    for(int i=1;i<=n;i++)
        for(int j=1;j<m;j++)
            if(cnt[i][j]==1&&cnt[i][j+1]==1) cntr[i][j]=1;else cntr[i][j]=0;
    for(int i=1;i<n;i++)
        for(int j=1;j<=m;j++)
            if(cnt[i][j]==1&&cnt[i+1][j]==1) cntd[i][j]=1;else cntd[i][j]=0;
    for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++)
        {
            cnt[i][j]+=cnt[i-1][j]+cnt[i][j-1]-cnt[i-1][j-1];
            cntr[i][j]+=cntr[i-1][j]+cntr[i][j-1]-cntr[i-1][j-1];
            cntd[i][j]+=cntd[i-1][j]+cntd[i][j-1]-cntd[i-1][j-1];
        }
    for(int i=1;i<=q;i++)
    {
        int x1=read(),y1=read(),x2=read(),y2=read();
        printf("%d\n",query(cnt,x1,y1,x2,y2)-query(cntr,x1,y1,x2,y2-1)-query(cntd,x1,y1,x2-1,y2));
    }
    return 0;
}


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

using namespace std;

#define int long long

#define rep(i,x) for(int i=0;i<x;++i)
#define rrep(i,x) for(int i=x-1;i>=0;--i)
#define all(a) a.begin(),a.end()

int N;

int J[100010], O[100010], I[100010];

signed main()
{
    cin >> N;
    
    string s; cin >> s;

    rep(i, N) {
        J[i + 1] = (s[i] == 'J') + J[i];
        O[i + 1] = (s[i] == 'O') + O[i];
        I[i + 1] = (s[i] == 'I') + I[i];
    }

    int ma = 0;

    // J
    {
        int curO = 0, curI = 0;

        rep(i, N) {
            if (s[i] == 'O') {
                curO += J[i + 1] + 1;
            }
            if (s[i] == 'I') {
                curI += curO;
            }
        }

        ma = max(ma, curI);
    }

    // I
    {
        int curO = 0, curJ = 0;

        rrep(i, N) {
            if (s[i] == 'O') {
                curO += (I[N] - I[i + 1]) + 1;
            }
            if (s[i] == 'J') {
                curJ += curO;
            }
        }

        ma = max(ma, curJ);
    }

    // O zentansaku
    {
        int curJ=0, curO=0, curI=0;

        rep(i, N) {
            if (s[i] == 'J') {
                curJ++;
            }
            if (s[i] == 'O') {
                curO += curJ;
            }
            if (s[i] == 'I') {
                curI += curO;
            }
        }

        int v = curI;

        rep(i, N+1) {
            ma = max(ma, v + J[i + 1] * (I[N] - I[i + 1]));
        }
    }

    cout << ma << endl;
}

Measured memory_bytes: 5624
#![allow(non_snake_case)]
#![allow(unused_imports)]

use proconio::{input, fastout};
use proconio::marker::*;
use whiteread::parse_line;
use std::collections::*;
use num::*;

use itertools::Itertools;
use itertools_num::ItertoolsNum;

#[fastout]
fn main() {
    input!{
        s: String
    }

    println!("{}", s[..3].to_string());
}


Measured memory_bytes: 2172
#include<stdio.h>
int main(){
  long long n,a,b=0,s=0;
  scanf("%lld",&n);
  while(n--){
    scanf("%lld",&a);
    b+=a;
    s+=b/2;
    b=a?b%2:0;
  }
  printf("%lld\n",s);
  return 0;
}


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

int main(){
  int N , X ; 
  cin >> N >> X ; 
  vector<int> m(N) ; 
  int cnt = 0 ; 
  for(int i =0 ; i < N ; i++){
    cin >> m.at(i) ; 
    cnt+= m.at(i) ; 
  }
  X -= cnt ; 
  
  sort(m.begin(),m.end()) ;
  
  cout << N + X/m.at(0) << endl ; 
  
}

Measured memory_bytes: 3620
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
using Graph=vector<vector<int>>;
using edge= struct{int to;ll cost;};


template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}


int main()
{
  int N;
  cin>>N;
  string s;
  cin>>s;
  char tmp;
  int l;
  l=s.size();
  REP(i,l)
  {
    tmp=s[i]+N;
    s[i]=tmp;
    if(s[i]>'Z')
    {
      s[i]=s[i]-26;
    }
  }
  cout<<s<<endl;

}

Measured memory_bytes: 256
x, y, a, b, c = map(int, input().split())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))
p.sort(reverse = True)
q.sort(reverse = True)
r.sort(reverse = True)
p = p[: x]
q = q[: y]
t = []
for i in p: t.append(i)
for i in q: t.append(i)
t.sort()
it = 0
for i in range(x + y):
    if it == c: break
    if t[i] < r[it]:
        t[i] = r[it]
        it -= -1
print(sum(t))

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

using namespace std;

int main()
{
	int a,b;
	cin >> a >> b;
	cout << ((a<10 and b<10) ? a*b : -1) << endl;




}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

N=int(input())
a=list(map(int,input().split()))
ans=0
for i in range(0,N,2):
    if a[i]%2==1:
        ans+=1
print(ans)

Measured memory_bytes: 61828
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define ALL(A) A.begin(), A.end()
#define INF ((int)1e9)

using namespace std;

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

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int N, K; cin >> N >> K;
	vector<int> x(N, 0);
	rep (i, N){
		cin >> x[i];
	} // end rep

	int res = INF;
	rep (i, N - K + 1){
		int xl = x[i];
		int xr = x[i + K - 1];
		if (xl >= 0){
			res = min(res, xl + abs(xr - xl));
		}else
		if (xr <= 0){
			res = min(res, abs(xr) + abs(xr - xl));
		}else{
			res = min(res, 2 * abs(xl) + xr);
			res = min(res, abs(xl) + 2 * xr);
		} // end if
	} // end rep

	cout << res << endl;

	return 0;
}

Measured memory_bytes: 640
#include<iostream>
using namespace std;
int main()
{
	int max = 0;
	int b;
	int a[10];
	for(int i = 0;i<=9;i++)
	{
		cin >> a[i];
	}
	for(int k = 1;k<=3;k++)
	{
	  for(int j = 0;j<=9;j++)
	  {
		if(a[j]>max)
		{
			max=a[j];
			b=j;
		}

	  }
	  cout << max << endl;
	  a[b] = 0;
	  max = 0;
	}
	return 0;
}

Measured memory_bytes: 1160
n = int(input())
a = list(map(int, input().split()))
c = [0]*(10**6 + 1)

for i in a:
    c[i] += 1

cnt = 0

for i in range(2, 10**6 + 1):
    s = sum(c[i::i])
    if s == n:
        print("not coprime")
        exit()
    elif s > 1:
        cnt += 1

if cnt > 0:
    print("setwise coprime")
else:
    print("pairwise coprime")

Measured memory_bytes: 127356
#![allow(non_snake_case, unused)]
use std::cmp::*;
use std::collections::*;
use std::f64::consts::*;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        n: usize,
        k: usize,
        mut l: [u64; n],
    }
    l.sort();
    l.reverse();
    l.split_off(k);

    println!("{}", l.iter().sum::<u64>());
}


Measured memory_bytes: 4352
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int n, m; unsigned ok[250009];
int main() {
	while (cin >> m >> n, m) {
		fill(ok, ok + 250000, -1);
		for (int i = 0; i < m; i++) ok[i >> 5] &= ~(1U << (i & 31));
		for (int i = m; i < 7368800; i++) {
			if (!(ok[i >> 5] & (1 << (i & 31)))) continue;
			for (int j = i * 2; j < 7368800; j += i) ok[j >> 5] &= ~(1U << (j & 31));
			if (n-- == 0) {
				cout << i << endl;
				break;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 3984
W, H, N = map(int, input().split())

rect = [(p%W, p//W) for p in range(W*H)]
for i in range(N):
    xi, yi, ai = map(int, input().split())
    if(ai==1):
        cond = lambda x_y: x_y[0] >= xi
    elif(ai==2):
        cond = lambda x_y: x_y[0] < xi
    elif(ai==3):
        cond = lambda x_y: x_y[1] >= yi
    else:
        cond = lambda x_y: x_y[1] < yi
    rect = list(filter(cond , rect))
        
print(len(rect))


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

using ll = long long;
const int mod = 998244353, mxN = 2e5;

int f[mxN+1];

int add (int a, int b) {
	a += b;
	if (a >= mod) a -= mod;
	return a;
}

int mul (ll a, ll b) {
	a *= b;
	if (a >= mod) a %= mod;
	return a;
}

int binpow (int a, int b) {
	int res = 1;
	while (b) {
		if ((b&1)) {
			res = mul(res, a);
		}
		b >>= 1;
		a = mul(a, a);
	}
	return res;
}

int C (int n, int k) {
	int res = mul(f[n], binpow(mul(f[n-k], f[k]), mod-2));
	return res;
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int n, m, k, ans = 0;
	cin >> n >> m >> k;
	if (m == 1) {
		if (n-1 > k) {
			cout << 0;
		} else {
			cout << 1;
		}
		return 0;
	}
	f[0] = 1;
	for (int i=1; i<=n; i++) {
		f[i] = mul(f[i-1], i);
	}
	for (int i=0; i<=k; i++) {
		int blocks = n-i-1;
		int res = C(n-1, blocks);
		int mid = n-i;
		res = mul(res, binpow(m-1, mid-1));
		res = mul(res, m);
		ans = add(ans, res);
	}
	cout << ans;
	return 0;
}


Measured memory_bytes: 4376
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        long total = 0L;
        long tmp = sc.nextLong();
        for(int i=1; i<N; i++) {
            long now = sc.nextLong();
            if(now==tmp) continue;
            if(now<tmp) {
                total += tmp - now;
            } else {
                tmp = now;
            }
        }
        System.out.println(total);
    }
}


Measured memory_bytes: 58820
#include <bits/stdc++.h>
using namespace std;
#define ALL(obj) obj.begin(),obj.end()
#define SORT(obj) sort(obj.begin(),obj.end())
#define pb(obj) push_back(obj)
#define REP(i,N) for(int i=0;i<N;i++)
typedef long long ll;
ll const MOD=1e9+7;

int main(){
  ll a,b,c,k;
  cin>>a>>b>>c>>k;
  if(k<=a){
    cout<<k<<endl;
  }
  else if(a<k&&k<=a+b){
    cout<<a<<endl;
  }
  else if(a+b<k){
    cout<<a-(k-a-b)<<endl;
  }
}


Measured memory_bytes: 3608
import java.util.*;

public class Main {
    public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);
	int n = sc.nextInt();
	String s = sc.next();
	int count = 1;
	char mae = s.charAt(0);
	for (int i=1; i<n; i++) {
	    if (s.charAt(i) != mae) {
		count++;
		mae = s.charAt(i);
	    }
	}
	System.out.print(count);
    }
}


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

using namespace std;
typedef long long int ll;
typedef vector<int> vi;
typedef vector<vi> vvi;

#define INF (1e9)

int N, A, B, C;

int main() {
    cin >> N >> A >> B >> C;

    vi L(N);
    for (int i = 0; i < N; i++) {
        cin >> L[i];
    }

    ll ans = INF;

    int n1, n2, n3, s1, s2, s3;
    for (int i = 0; i < 1 << (N * 2); i++) {
        n1 = 0, n2 = 0, n3 = 0;
        s1 = 0, s2 = 0, s3 = 0;
        for (int j = 0; j < N; j++) {
            if ((i >> (2 * j) & 3) == 1) {
                n1++;
                s1 += L[j];
            } else if ((i >> (2 * j) & 3) == 2) {
                n2++;
                s2 += L[j];

            } else if ((i >> (2 * j) & 3) == 3) {
                n3++;
                s3 += L[j];
            }
        }
        if (n1 == 0 or n2 == 0 or n3 == 0) continue;
        ll a = 0;
        a += max(0, (n1 - 1) * 10);
        a += max(0, (n2 - 1) * 10);
        a += max(0, (n3 - 1) * 10);
        a += abs(s1 - A);
        a += abs(s2 - B);
        a += abs(s3 - C);

        ans = min(ans, a);
    }

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


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <vector>

using namespace std;

//[-60,60] -> [0,120]
int f[121][121];

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

int main(){
    int t,n;
    
    while(cin >> t >> n){
        if((t|n) == 0) break;
        memset(f,0,sizeof(f));
        int x,y;
        vector<pair<int,int> > diff;

        for(int i=0;i<n;i++){
            cin >> x >> y;
            f[x+60][y+60] = -1;
        }

        cin >> x >> y;
        x += 60;
        y += 60;
        f[x][y] = 1;
        
        for(int i=0;i<t;i++){
            for(int p=0;p<121;p++){
                for(int q=0;q<121;q++){
                    if(f[p][q] == 1){
                        for(int k=0;k<6;k++){
                            x = p + dx[k];
                            y = q + dy[k];

                            if(0 <= x && x < 121 &&
                               0 <= y && y < 121 &&
                                f[x][y] != -1){
                                diff.push_back(make_pair(x,y));
                            }
                        }
                    }
                }
            }
            for(int j=0;j<diff.size();j++){
                f[diff[j].first][diff[j].second] = 1;
            }
            diff.clear();
        }
        int ret = 0;

        for(int i=0;i<121;i++){
            for(int j=0;j<121;j++){
                if(f[i][j] == 1) ret++;
            }
        }
        cout << ret << endl;
    }
}

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

int main(){
  long a,b,k;
  cin >> a >> b >> k;
  if(k<=a) cout << a-k <<' '<< b << endl;
  else if(b-k+a>0) cout << 0 <<' '<< b-k+a << endl;
  else cout << 0 << ' ' << 0 << endl;
}

Measured memory_bytes: 256
x, k, d = map(int, input().split())
x = abs(x)
if x//d > k:
    ans = x -d*k
else:
    e = x//d
    k -= e
    x -= e*d
    if k % 2 == 1:
        x = abs(x-d)
        ans = x
    else:
        ans = x
print(ans)


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

int main(void){
    ll h;
    cin >> h;
    
    ll ans = 0;
    int count = 0;
    while (h != 0) {
        ans += pow(2, count);
        h /= 2;
        count++;
    }
    
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){

  int n,i, m=100000;

  scanf("%d",&n);

  for(i=0;i<n;i++){
    m=m*1.05;
    m=(m+999)/1000;
    m*=1000;
  }
  printf("%d\n",m);

  return 0;
}

Measured memory_bytes: 592
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef tree<pair<int,int>, null_type, less<pair<int,int>>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
#define int long long
#define ld long double
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define all(x) (x).begin(), (x).end()
#define forn(i,n) for(int i=0;i<(int)(n);i++)
#define for1(i,n) for(int i=1;i<=(int)(n);i++)
const int MOD = 1e9 + 7 ;
int mpow(int a,int b,int p=MOD){a=a%p;int res=1;while(b>0){if(b&1)res=(res*a)%p;a=(a*a)%p;b=b>>1;}return res%p;}
const int N=20000001;
int n,x,y;

int32_t main(){
      ios_base::sync_with_stdio(false);
      cin.tie(NULL);
      vector<int> a(3);
      for(int i=0;i<3;i++) cin>>a[i];
      sort(all(a));
      cout<<a[0]+a[1];
}
// nothing is impossible

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	ll N,W;cin>>N>>W;vector<ll> Va(N);vector<ll> Wt(N);ll Sum=0;for(ll i=0;i<N;i++){cin>>Wt[i]>>Va[i];Sum+=Va[i];}
	vector < vector<ll> >  dp ( N+1 , vector <ll> (Sum,INT_MAX));
	for(ll i=0;i<=N;i++)
	{
		for(ll j=0;j<=Sum;j++)
		{
			if(j==0 and i==0)
			{
				dp[i][j]=0;
			}
			else if(i==0)
			{
				dp[i][j]=INT_MAX;
			}
			else if(j==0)
			{
				dp[i][j]=0;
			}
			else if(Va[i-1]>j)
			{
				dp[i][j]=dp[i-1][j];
			}
			else
			{
				dp[i][j]=min(dp[i-1][j],Wt[i-1]+dp[i-1][j-Va[i-1]]);
			}
			
		}
	}
	for(ll i=Sum;i>=0;i--)
	{
		if(dp[N][i]<=W)
		{
			cout<<i;
			break;
		}
	}
}

Measured memory_bytes: 83184
# import sys
import numpy as np
# input = sys.stdin.readline

def main():
    N, M, Q = map(int, input().split())

    check = np.zeros((N+1, N+1))

    for i in range(M):
        l, r = map(int, input().split())
        check[r][l] += 1

    # print(check)
    for i in range(1, N+1):
        check[i] += check[i-1]
    for i in range(1, N+1):
        check[:,i] += check[:,i-1]
    # print(check)

    for i in range(Q):
        p, q = map(int, input().split())
        print(int(check[q][q] - check[q][p-1] - check[p-1][q] + check[p-1][p-1]))

if __name__ == "__main__":
    main()


Measured memory_bytes: 15064
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mod 998244353
#define ff first
#define ss second
#define endl '\n'
using namespace std;
const ll inf=1e18;
ll power(ll x,ll y)
{
    ll res=1;
    while(y>0)
    {
        if(y%2==1)
            res=(res*x)%mod;
        x=(x*x)%mod;
        y=y/2;
    }
    return res;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll n;
    cin>>n;
   vector<ll>v;
   ll i,m,s=0,a,b,c,r,k;
   for(i=0;i<n;i++)
   {
       cin>>m;
       v.pb(m);
       if(m==0)
        s++;
   }
   if(v[0]!=0 || s>1)
   {
       cout<<0<<endl;
       return 0;
   }
   ll arr[n+1]={0},arr1[n+1];
   arr[0]=1;
   fill(arr1,arr1+n+1,1);
   sort(v.begin(),v.end());
   for(i=1;i<n;)
   {
       a=v[i];
       while(i<n && v[i]==a)
       {
           arr[a]++;
           i++;
       }
       r=power(arr[a-1],arr[a]);
       r=(r*arr1[a-1])%mod;
       arr1[a]=r;
   }
   cout<<arr1[v[n-1]]<<endl;
}


Measured memory_bytes: 2676
//#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <cmath>
#include <vector>
#include <cstring>
#include <climits>
#include <queue>
#include <algorithm>
#include <utility>
#define INF INT_MAX / 2
using namespace std;

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

//1000/1/1
//3で割り切れる時全部大の月
//大の月　20　小の月　19

//20*5 + 19*5
//20*10

int solve(int y,int m,int d){
	int ny = (y - 1) * (20*5 + 19*5) + ((y-1)/3)*5;

	int n2 = 0;
	if(y%3==0){
		n2 = (m-1)*20 + d;
	}else{
		for(int i=1;i<m;i++){
			if(i%2==0)n2 += 19;
			else n2 += 20;
		}
		n2 += d;
	}
	return ny + n2;
}

int main(void) {
	int n;
	cin >> n;
	for(int i=0;i<n;i++){
		int y,m,d;
		cin >> y >> m >> d;
		cout << 196470 - solve(y,m,d) + 1 << endl;
	}
}

// command shift d duplicate
// command ctrl 上下
// command D
// command caps G → '' ""
// vector<vector<int>> a(N,vector<int>(M,-1));

Measured memory_bytes: 1164
#include"bits/stdc++.h"
using namespace std;
typedef long long ll;
#define int ll
int32_t main()
{
  #ifndef ONLINE_JUDGE
  freopen("in","r",stdin);
  freopen("out","w",stdout);
  #endif


  int n,k;
  cin>>n>>k;
  vector<int> x(k);
  for(int &i:x)cin>>i;
  if(k==1){cout<<0;return 0;}
  sort(x.begin(),x.end());
  vector<int> diff(k-1);
  for(int i=1;i<k;i++)diff[i-1]=abs(x[i]-x[i-1]);

  int ans=0;
  sort(diff.begin(),diff.end());
 
for(int i=0;i<(k-n);i++)ans+=diff[i];
  cout<<ans;
}

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

int main(void) {
  map<string, int> si;
  map<int, string> is;

  si["S"] = 0, si["H"] = 1, si["C"] = 2, si["D"] = 3;
  is[0] = "S", is[1] = "H", is[2] = "C", is[3] = "D";

  int n, col;
  string row;

  int isHas[4][13] = {{0}};

  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> row >> col;
    isHas[si[row]][col - 1] = 1;
  }

  for (int i = 0; i < 4; i++) {
    for (int j = 0; j < 13; j++) {
      if(isHas[i][j] == 0)
        cout << is[i] << " " << j + 1 << endl;
    }
  }
}



Measured memory_bytes: 3132
n,k = map(int,input().split())
if n % k ==0:
    print(0)
else:
    l = [n]
    p = n//k
    c = n-(p*k)
    half = k//2
    while c > half:
        c = abs(c-k)
    l.append(c)
    print(min(l))

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <numeric>
#include <set>
#include <cstdlib>
#include <queue>
#include <map>
#include <cstdio>

using namespace std;

typedef long long llint;
typedef long double ld;
#define inf 1e18
#define mod 1000000007
//priority_queue<llint,vector<llint>,greater<llint>> que;
//priority_queue<llint> q;

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

llint a,b;

void solve(){
  while(1){
    cin >> a >> b;
    if(a==0 && b==0)break;
    cout << min(a,b) << " " << max(a,b) << endl;
  }
}

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



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

using namespace std;

#define debug(x) cout << #x << "::" << x << endl;
#define debug2(x, y) cout << #x << "::" << x << " " << #y << "::" << y << endl;
#define debug3(x, y, z) cout << #x << "::" << x << " " << #y << "::" << y <<" "<< #z << "::" << z << endl;

#define For(i, a, b) for (int i = a; i < b; i++)

typedef long long ll;
const ll mod = 1e9 + 7;
const int MAX = 5 * 1e3 + 5;
typedef pair<int, int> pii;
vector<ll> tree;
void add(ll &a, ll b)
{
    a = (a + b) % mod;
    if (a < 0) a += mod;
}

ll query(int ss,int se,int qs,int qe,int si) {

    if(ss > se || ss > qe || qs > se) return 0;

    if(ss >= qs && qe >= se) {
        return tree[si];
    }

    int mid = ss + (se - ss)/2;

    return max(query(ss,mid,qs,qe,2*si+1),query(mid+1,se,qs,qe,2*si+2));

}

void update(int ss,int se,int id,ll val,int si) {

    if(ss > se) return;

    if(ss == se && ss == id) {
        tree[si] = max(tree[si],val);
        return;
    }

    int mid = ss + (se - ss)/2;
    if(mid >= id) update(ss,mid,id,val,2*si+1);
    else update(mid+1,se,id,val,2*si+2);

    tree[si] = max(tree[2*si+1],tree[2*si+2]);
}

int main() {

    int n;
    cin>>n;
    vector<int> a(n);
    For(i,0,n) cin>>a[i];
    vector<int> b(n);
    For(i,0,n) cin>>b[i];

    vector<ll> dp(n+1);
    ll sum = 0;
    int base = 1;
    while(base <= n) base*=2;
    //debug(base);
    tree.resize(4*(n+1));

    For(i,0,n){
        

        // dp[i] is the max value 1...dp[height-1] + b[i];

        /*int start = a[i] + base;
        ll best = 0;
        while(start > 1)
        {
            
            if(start%2)
            {
                best = max(best,tree[start-1]);
            }
            start/=2;
        
        }
        
        dp[a[i]] = best + b[i];
        
        /*for(int j=base + a[i];j>=1;j/=2)
        {
            tree[j] = max(tree[j],dp[a[i]]);
        }*/

        dp[a[i]] = query(0,n-1,0,a[i]-1,0) + b[i];

        //debug(dp[a[i]]);

        update(0,n-1,a[i]-1,dp[a[i]],0);

        sum = max(sum,dp[a[i]]);


    }

    

    cout<<sum<<endl;

    return 0;

}

Measured memory_bytes: 9600