akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<iostream>
#include<string.h>
#include<algorithm>
#include<queue>
#include<stack>
#include<math.h>
#include<map>
typedef long long int ll;
using namespace std;
#define maxn 0x3f3f3f3f
const ll N = 200010;
struct sf
{
    ll e,v,last;
}edge[2*N];
ll n,m,cnt;
ll d[2*N];
ll head[2*N];
ll vis[2*N];
void star(ll f,ll e)
{
    edge[cnt].e=e;
    edge[cnt].last=head[f];
    head[f]=cnt++;
}
void SPFA(int pos)
{
    queue<ll>q;
    ll now,nex;
    q.push(pos);
    while(q.size())
    {
        now=q.front();
        q.pop();
        vis[now]=1;
        for(nex=head[now];nex!=-1;nex=edge[nex].last)
        {
            ll y = edge[nex].e;
           if(!vis[y]) {
           d[y]+=d[now];
           q.push(y);
        }
    }
}
}
int main()
{
    ll a,b,c,f,t,i;
    scanf("%lld%lld",&n,&m);
        cnt=1;
        memset(vis,0,sizeof(vis));
        memset(d,0,sizeof(d));
        memset(head,-1,sizeof(head));
        for(int i=1;i<=n-1;i++)
        {
            scanf("%lld%lld",&a,&b);
            star(a,b);
            star(b,a);
        }
        for(i=1;i<=m;++i)
       {
         scanf("%lld%lld",&f,&t);
         d[f]+=t;
       }
        SPFA(1);
        for(i = 1;i<=n;++i)
        printf("%lld ",d[i]);
    }


Measured memory_bytes: 21136
#pragma  warning (disable:4996)
#include<iostream>
#include<cstdio>
#include<queue>
#include<cstring>
#include<string>
#include<cmath>
using namespace std;
int m, c, n;
int k[102];
int b[102][52];
vector<int> desk[12];//&#27599;&#24352;&#26700;子上放的&#20070;&#32534;号
int amount[12];
int que[5005];//拿&#20070;&#39034;序
int maxk;
int max(int a, int b){
	if (a > b)return a;
	else return b;
}
int main(){
	while (cin >> m >> c >> n){
		if (!m&&!n&&!c) break;
		int i, j,p;
		
		memset(b, 0, sizeof(b));
		memset(desk, 0, sizeof(desk));
		memset(amount, 0, sizeof(amount));
		memset(que, 0, sizeof(que));
		memset(k, 0, sizeof(k));
		maxk = -10;

		for ( i = 1; i <= n; i++){
			cin >> k[i];
			maxk = max(maxk, k[i]);
			for ( j = 1; j <= k[i]; j++)
				cin >> b[i][j];
		}
		

		int ans = 0;
		int num = 0;

		for (j = 1; j <= maxk; j++){
			for (i = 1; i <= n; i++){
				if (b[i][j] != 0)
				{
					que[num++] = b[i][j];
					
				}
			}
		}
		
		int id;
		int mm = 0;
		
		
		while (mm < num){
			id = que[mm];
			int flag = 0;
			//找&#20070;
			/*for (j = 1; j <= m; j++){
				cout << "desk["<<j<<"]:";
				for (i = 0; i < desk[j].size(); i++)
					cout << desk[j][i] << " ";
				cout << endl;
			}*/
				
			for (i = 1; i <= m; i++){
				for (j = 0; j < desk[i].size(); j++){
					if (desk[i][j] == id) {
						flag = 1;
						ans += i;
						//cout << "第"<<mm<<"cinashu"<<i << endl;
						amount[i]--;
						desk[i][j] = 0;//拿走了
						break;
					}
				}
				if (flag)break;
			}
			if (!flag){
				ans += (m + 1); //cout << "第" << mm << "cinashu" << m+1 << endl;
			}

			//放&#20070;
			int temp;
			if (amount[1] < c){
				desk[1].push_back(id);
				ans += 1;
				amount[1]++;
				
			}
			else{
				for (i = 2; i <= m + 1; i++){
					if (amount[i] < c || (i == m + 1))
					{

						temp = i;//&#26242;&#26102;放的位置
						amount[i]++;
						
						break;
					}
				}
				int longestid;//很久没用的&#20070;

				for (i = 0; i < desk[1].size(); i++){
					if (desk[1][i])
					{
						longestid = desk[1][i];
						desk[1][i] = 0;
					
						break;
					}
				}
				desk[1].push_back(id);
				

				int temp2;	
				for (p = temp ; p <= m + 1; p++){
					if (amount[p] < c || p == m + 1){

						temp2 = p;
						desk[p].push_back(longestid);
						amount[p]++;
						break;
					}
				}
				amount[temp]--;
				ans += (2 * temp + temp2 + 2);
				//cout << temp <<" "<< temp2 <<" "<<2 * temp + temp2 + 2<< endl;


			}mm++;
		}
				
		cout << ans << endl;

		
	}return 0;
}

Measured memory_bytes: 1672
#include "bits/stdc++.h"
using namespace std;
#define rep(i, a, n) for(int i = a; i <= n; i++) 
const int maxH = 1010;
const long long MOD = (long long)1e9 + 7LL;
int h, w;
char grid[maxH][maxH];
long long dp[maxH][maxH];
int main()
{
	cin >> h >> w;
	rep(i, 1, h) rep(j, 1, w) cin >> grid[i][j];
	rep(i, 2, h) if(grid[i][1] == '.') dp[i][1] = 1LL; else break;
	rep(j, 2, w) if(grid[1][j] == '.') dp[1][j] = 1LL; else break;
	rep(i, 2, h) rep(j, 2, w) if(grid[i][j] == '.') dp[i][j] = (dp[i - 1][j] + dp[i][j - 1]) % MOD;
	cout << dp[h][w] << endl;
	return 0;
}

Measured memory_bytes: 9216
#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 FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)

#define INF 100000000
#define MOD 1000000007
#define writeln(n) cout<<n<<endl
//setprecision(10);
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
//vector<tuple<long long, long long, long long>>vec;

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

llong pownew(llong m, llong n) {
    if (n == 0) { return 1; }
    if (n % 2 == 0) { return pow(m*m, n/2); }
    return pow(m, n-1) * m;
}

bool isprime(int p) {
    if (p == 1) return false;
    for (int i = 2; i < p; i++) {
        if (p%i == 0) return false;
    }
    return true;
}

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

const int inf=100000000;

long long modpow(long long a, long long n, long long mod)
{
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

llong extgcd(llong a,llong b,llong& x,llong& y){
    llong d=a;
    if(b!=0){
        d=extgcd(b,a%b,y,x);
        y-=(a/b)*x;
    }
    else{
        x=1;y=0;
    }
    return d;
}

llong  mod_inverse(llong  a,llong m){
    long long int x,y;
    extgcd(a,m,x,y);
    return (m+x%m)%m;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a,b,c; cin>>a>>b>>c;
    int v=max({a,b,c});
    int vv=v*3;
    int cnt=a+b+c;
    int ans=0;
    if(vv%2==cnt%2)
    {
        ans=vv-a-b-c;
    }
    else ans=vv+3-a-b-c;
    cout<<ans/2<<endl;
    return  0;
}


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

#define db(x) cout<<x<<'\n'
#define db1(x) cout<<#x<<"="<<x<<'\n'
#define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<'\n'
#define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<'\n'
#define repi(i,n) for(int i=0;i<(n);++i)
//#define repA(i,a,n) for(int i=a;i<=(n);++i)
//#define repD(i,a,n) for(int i=a;i>=(n);--i)
#define ll long long int
#define endl '\n'
#define lld long long double
#define vi vector<int> 
#define vl vector<ll> 
#define vb vector<bool> 
#define vvi vector<vector<int>  >
#define err(t) cout<<"Error : "<<t<<endl;
#define all(v) v.begin(),v.end()
#define mp make_pair
#define M 100000
#define MD 1000000007
#define pb push_back
#define rep(i,a,b) for(ll i = a; i <= (b); i++)
#define pii pair<int,int>
#define pll pair<ll,ll> 
#define vec(a) vector<a >
#define se second
#define fi first
#define inf 0xffffffff
#define inchar getchar_unlocked
#define outchar(x) putchar_unlocked(x)

int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);cout.tie(NULL);
	// int n;cin>>n;
	// string s;cin>>s;
	
	//ll n;cin>>n; vl a(n); repi(i,n) cin>>a[i];
	int n,k;cin>>n>>k;
	vb vis(n,false);int c=0;
	int t,m;
	while(k--){
	    cin>>t;
		while(t--) {
			cin>>m;
			m--;
			vis[m]=1;
		}
	}repi(i,n) if(!vis[i]) c++;
	db(c);
	/*
	int q;cin>>q;while(q--){ 
		
	 }
	 //*/
return 0;
}



Measured memory_bytes: 3648
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<functional>
#include<math.h>
#include<random>
#include <bitset>
using namespace std;
#define N (1000000000+7)
//#define N 998244353
#define INF 1e16
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> Q;
 
const int inf = (int)1e9; 
 
ll gcd(ll a, ll b) {
	if (b > a) {
		ll tmp = b;
		b = a;
		a = tmp;
	}
	if (a%b == 0)return b;
	else return gcd(b, a%b);
}

int main(void){
	ll n,d;
    cin>>n>>d;
    int ans = 0;
    for(int i=0;i<n;i++){
        ll x,y;
        cin>>x>>y;
        if(x*x+y*y<=d*d)ans++;
    }
    cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3628
#include<iostream>
#include<bits/stdc++.h>
#include<climits>

#define forn(x,n,s) for(int i = x; i < n; i += s )
#define forr(x,n,s) for(int i = x; i>=n; i -= s)

using namespace std;

void go(){
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  #ifndef ONLINE_JUDGE
       freopen("input.txt","r",stdin);
       freopen("output.txt","w",stdout);
  #endif
}

int main(){
    go();

    // code here
    int n;cin>>n;
    long long arr[n];
    forn(0,n,1) cin>>arr[i];
    int cnt = 0;
    for(int i = 0;i < n;i++){
        for(int j = i + 1;j < n;j++){
            for(int k = j + 1; k < n;k++){
                if(arr[i]!=arr[j] and arr[i]!=arr[k] and arr[j]!=arr[k]){
                    if(arr[i]+arr[j] > arr[k] and arr[i]+arr[k] > arr[j] and arr[j]+arr[k]>arr[i]) cnt++;
                }
            }
        }
    }
    cout<<cnt;

}






Measured memory_bytes: 3636
#include <cstdio>
#include <cmath>

using namespace std;

int main() {
	double c = 0.0;
	double A = 0.0;
	double p = 0.0;
	double h = 0.0;
	int a = 0;
	int b = 0;
	int C = 0;

	scanf("%d%d%d", &a, &b, &C);
	c = static_cast<double>(C)*M_PI/180;
	c = sqrt(a*a + b*b - 2*a*b*cos(c));
	p = a + b + c;
	A = p/2;
	A = sqrt(A*(A-a)*(A-b)*(A-c));
	h = 2*A/a;
	printf("%.6f\n", A);
	printf("%.6f\n", p);
	printf("%.6f\n", h);
}



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

int main(){
  int N, R;
  cin>>N>>R;
  if(N>=10){
      cout<<R<<endl;
  }
  else{
      cout<<R+100*(10-N)<<endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a) for(int i=0;i<int(a);++i)
#define REP(i,a,b) for(int i=int(a);i<int(b);++i)
#define pb push_back
#define mp make_pair
#define F first
#define S second
using ll = long long;
using itn = int;
using namespace std;
static const long double GRATIO=(long double)(1+sqrt(5))/2;
ll GCD(ll a, ll b){
    return b ? GCD(b, a%b) : a;
}
ll LCM(ll a, ll b){
    return a/GCD(a,b)*b;
}
int main(){
    string S,T;
    cin>>S>>T;
    vector<string> str;
    bool ok=false;
    rep(i,S.size()-T.size()+1){
        rep(j,T.size()){
            if(S.at(i+j)!='?' && S.at(i+j)!=T.at(j)) break;
            if(j+1==T.size()){
                ok=true;
                string s=S;
                s.replace(i,T.size(),T);
                str.push_back(s);
            }
        }
    }
    if(ok){
        rep(i,str.size()){
            replace(str.at(i).begin(),str.at(i).end(),'?','a');
        }
        sort(str.begin(),str.end());
        cout<<str.at(0)<<endl;
    }else{
        cout<<"UNRESTORABLE"<<endl;
    }
}


Measured memory_bytes: 256
let input = readLine()!.split(separator: " ").map { Int($0)! }

let N = input[0]
let K = input[1]

let A = readLine()!.split(separator: " ").map { Int($0)! }

var dp: [Int] = .init(repeating: 0, count: K + 1)
for i in 1...K {
  for a in A {
    if i - a < 0 || dp[i - a] == 1 {
      continue
    }
    dp[i] = 1
  }
}
print(dp[K] == 1 ? "First" : "Second")

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

typedef long long ll;
typedef unsigned long long ull;
typedef double dd;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;

const int mx=1e6+11;
const double PI = acos(-1);
#define MOD 1000000007

#define nl '\n'
#define pb push_back
#define F first
#define S second
#define I insert
#define mp make_pair

#define sz(x) x.size()
#define tt int t; cin>>t; while(t--)
#define be(a) (a).begin(),(a).end()
#define rbe(a) (a).rbegin(),(a).rend()
#define mem(a,b) memset(a,b,sizeof(a))
#define yes cout<<"YES"<<nl
#define no cout<<"NO"<<nl

#define su ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define file freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define frac cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);

void f()
{
  ll a,b,c,d;
  cin>>a>>b>>c>>d;
  cout<<max({a*c,a*d,b*c,b*d})<<nl;
}

int main()
{
    su;
    f();
    return 0;
}


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

int main(){
    long N,P;cin>>N>>P;
    map<long,long> product;
    product[1]=1;
    long i=2;
    long Ps=P;
    int count=0;
    while(i<sqrt(P)){
        if(Ps%i==0){
            Ps/=i;
            product[i]++;
          count=1;
        }
        else i++;
        if(Ps==1)break;    
    }
  product[Ps]=1;
    long ans=1;
    auto begin=product.begin(); auto end=product.end();
    for(auto i=begin;i!=end;i++){
        if((i->second)>=N){
            for(int j=0;j<(i->second/N);j++)ans=ans*(i->first);
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <queue>
#include <vector>
#include <map>
#include <set>
#define MAXN 1005
#define MAXM 10005
#define INF 0x3f3f3f3f
#define rint register int
#define LL long long
#define LD long double
using namespace std;

int n;
LL ans, f[MAXM*2];

struct A {int w, s, v;} a[MAXN];

bool CMP(A x, A y)
{
    return x.w+x.s<y.w+y.s;
}

int main()
{
    scanf("%d", &n);
    for(rint i=1; i<=n; ++i) scanf("%d%d%d", &a[i].w, &a[i].s, &a[i].v);
    sort(a+1, a+n+1, CMP);
    for(rint i=1; i<=n; ++i)
	for(rint j=a[i].s; j>=0; j--) f[j+a[i].w]=max(f[j+a[i].w], f[j]+a[i].v);
    for(rint i=0; i<=20000; ++i) ans=max(ans, f[i]);
    printf("%lld\n", ans);
    return 0;
}


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

int main()
{
    int fee,n,k,x,y;
    scanf("%d %d %d %d",&n,&k,&x,&y);
    if(n>k)
        fee=(k*x)+(n-k)*y;
    else if(n<=k)
        fee=n*x;
    printf("%d\n",fee);
    return 0;
}


Measured memory_bytes: 128
S = list(str(input()))
# 101010... or 010101... とすう必要がある。両方のパターンで調べて、どっちか小さい方でいいんじゃないか？

a1 = 0
a2 = 1
re1 = 0
re2 = 0
for s in S:
    if int(s) != a1:
        re1 += 1
    if int(s) != a2:
        re2 +=1
        
    a1 = (a1+1) % 2
    a2 = (a2+1) % 2
    
if re1 < re2:
    print(re1)
else:
    print(re2)

Measured memory_bytes: 3956
/*
 * d.cc: 
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>

using namespace std;

/* constant */

/* typedef */

/* global variables */

/* subroutines */

void call(int n) {
  for (int i = 1; i <= n; i++) {
    int x = i;
    if (x % 3 == 0)
      cout << " " << i;
    else
      do {
	if (x % 10 == 3) {
	  cout << " " << i;
	  break;
	}
	x /= 10;
      } while (x);
  }
  cout << endl;
}

/* main */

int main() {
  int n;
  cin >> n;

  call(n);
  return 0;
}

Measured memory_bytes: 1164
/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <iostream>

using namespace std;

int main()
{
    int n, temp;
    cin >> n;
    for(int i = 0; i < n; i++) {
        cin >> temp;
        if(temp%2 == 0) {
            if(temp%3 != 0 && temp%5 != 0) {
                cout << "DENIED";
                return 0;
            }
        }
    }
    cout << "APPROVED";
    return 0;
}


Measured memory_bytes: 256
from collections import *

def factorize(n):
    fct = []
    
    for i in range(2, int(n**0.5)+1):
        c = 0
        
        while n%i==0:
            n //= i
            c += 1
            
        if c>0:
            fct.append((i, c))
    
    if n>1:
        fct.append((n, 1))
    
    return fct
    
N = int(input())
cnt = defaultdict(int)

for i in range(1, N+1):
    fct = factorize(i)
    
    for p, c in fct:
        cnt[p] += c

ov74, ov24, ov14, ov4, ov2 = 0, 0, 0, 0, 0

for v in cnt.values():
    if v>=74:
        ov74 += 1
    
    if v>=24:
        ov24 += 1
        
    if v>=14:
        ov14 += 1
    
    if v>=4:
        ov4 += 1
    
    if v>=2:
        ov2 += 1

ans = ov74+ov24*(ov2-1)+ov14*(ov4-1)+ov4*(ov4-1)//2*(ov2-2)
print(ans)

Measured memory_bytes: 9736
import collections
import bisect

d = collections.defaultdict(list)
s = input()
t = input()
for i,S in enumerate(s,1):
    d[S].append(i)
k=0
ans=0
for ch in t:
    l = d[ch]
    if len(l)==0:
        print(-1)
        exit(0)
    if l[-1]<=ans:
        ans=l[0]
        k+=1
    else:
        ans=l[bisect.bisect_right(l,ans)]

print(len(s)*k+ans)

Measured memory_bytes: 7924
/*
このコード、と～おれ!
Be accepted!
∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
 　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
		  　　　　　　　　　　(¸.·´ (¸.·'* ☆
*/

#include <cstdio>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>
#include <numeric>
#include <iostream>
#include <random>
#include <map>
#include <unordered_map>
#include <queue>
#include <regex>
#include <functional>
#include <complex>
#include <list>
#include <cassert>
#include <iomanip>
#include <set>
#include <stack>
/*多倍長整数/cpp_intで宣言
#include <boost/multiprecision/cpp_int.hpp>
using namespace boost::multiprecision;
*/

//#pragma gcc target ("avx2")
//#pragma gcc optimization ("o3")
//#pragma gcc optimization ("unroll-loops")
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define rep1(i, n) for(int i = 1; i <= (n); ++i)
#define rep2(i, n) for(int i = 2; i < (n); ++i)
#define repr(i, n) for(int i = n; i >= 0; --i)
#define reprm(i, n) for(int i = n - 1; i >= 0; --i)
#define printynl(a) printf(a ? "yes\n" : "no\n")
#define printyn(a) printf(a ? "Yes\n" : "No\n")
#define printYN(a) printf(a ? "YES\n" : "NO\n")
#define printim(a) printf(a ? "possible\n" : "imposible\n")
#define printdb(a) printf("%.50lf\n", a) //少数出力
#define printLdb(a) printf("%.50Lf\n", a) //少数出力
#define printdbd(a) printf("%.16lf\n", a) //少数出力(桁少なめ)
#define prints(s) printf("%s\n", s.c_str()) //string出力
#define all(x) (x).begin(), (x).end()
#define allsum(a, b, c) ((a + b) * c / 2LL) //等差数列の和、初項,末項,項数
#define pb push_back
#define priq priority_queue
#define rpriq priq<int, vector<int>, greater<int>>
#define deg_to_rad(deg) (((deg)/360.0L)*2.0L*PI)
#define rad_to_deg(rad) (((rad)/2.0L/PI)*360.0L)
#define Please return
#define AC 0
#define manhattan_dist(a, b, c, d) (abs(a - c) + abs(b - d)) /*(a, b) から (c, d) のマンハッタン距離 */


using ll = long long;

constexpr int INF = 1073741823;
constexpr int MINF = -1073741823;
constexpr ll LINF = ll(4661686018427387903);
constexpr ll MOD = 1000000007;
const long double PI = acosl(-1.0L);

using namespace std;

void scans(string& str) {
	char c;
	str = "";
	scanf("%c", &c);
	if (c == '\n')scanf("%c", &c);
	while (c != '\n' && c != -1 && c != ' ') {
		str += c;
		scanf("%c", &c);
	}
}

void scanc(char& str) {
	char c;
	scanf("%c", &c);
	if (c == -1)return;
	while (c == '\n') {
		scanf("%c", &c);
	}
	str = c;
}

double acot(double x) {
	return PI / 2 - atan(x);
}

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

ll lcm(ll number1, ll number2) {
	return number1 / gcd(number1, number2) * number2;
}

ll LSB(ll n) { return (n & (-n)); }

/*-----------------------------------------ここからコード-----------------------------------------*/



int main() {

	int n;
	scanf("%d", &n);
	vector<pair<ll, ll>> a(n);
	rep(i, n)scanf("%lld%lld", &a[i].first, &a[i].second);
	reverse(all(a));
	ll cnt = 0;
	rep(i, n) {
		if (a[i].second == 1 or a[i].first == 0 or (a[i].first + cnt) % a[i].second == 0)continue;
		ll need = a[i].second - (a[i].first % a[i].second);
		need -= cnt;
		if (need < 0)need = a[i].second - (abs(need) % a[i].second);
		cnt += need;
	}
	printf("%lld\n", cnt);

	Please AC;
}


Measured memory_bytes: 2040
#include <bits/stdc++.h>
using namespace std;
#define x first
#define y second
#define ll long long
#define pi pair<int,int>
#define pl pair<ll,ll>
#define pd pair<double,double>
#define ld long double
#define pld pair<ld,ld>
#define lg length()
#define sz size()
#define vi vector<int>
#define vl vector<ll>
#define vp vector<pi>
#define vpl vector<pl>
#define pb push_back
#define INF 1000000005
#define LINF 1000000000000000005
using namespace std;
const int maxn = 1e5 + 100;
ll dp[maxn];
int32_t main()
{
	ios_base::sync_with_stdio(0); cin.tie(); cout.tie();
#ifdef LOCAL_DEFINE
	ifstream cin("input.txt");
#endif
	int N,W;
	cin >> N>>W;
	int ans = 0;
	for (int i = 1; i <= N; i++)
	{
		ll a, b;
		cin >> a >> b;
		for (int j = W; j >= a; j--)
		{
			//cout << dp[j] << dp[j - a] + b<<'\n';
			dp[j] = max(dp[j], dp[j - a] + b);
		}
	}
	cout << dp[W] << "\n";
}


Measured memory_bytes: 1024
#include <iostream>

#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <functional>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <iomanip>
#include <numeric>

using namespace std;

#define DescSort(a) sort(a.begin(),a.end(),std::greater<int>())
#define Sort(a) sort(a.begin(),a.end())

typedef long long LL;

int main(int argc, const char * argv[]) {

	cin.tie(0);
	ios::sync_with_stdio(false);

	LL N, M;
	LL ans = 0;

	cin >> N >> M;

	vector<LL>X(M);

	for (int i = 0; i < M; i++) {
		cin >> X.at(i);
	}

	Sort(X);

	vector<LL>A(M, 0);

	for (int i = 1; i < M; i++) {
		A[i] = X[i] - X[i - 1];
	}

	Sort(A);

	for (int i = 0; i < M - N + 1; i++) {
		ans += A[i];
	}

	cout << ans << endl;

	return 0;

}

Measured memory_bytes: 1792
import sys
input = sys.stdin.readline


def read():
    N = int(input().strip())
    T, A = map(int, input().strip().split())
    H = list(map(int, input().strip().split()))
    return N, T, A, H


def solve(N, T, A, H):
    ans = -1
    vmin = 10**7
    for i in range(N):
        h = H[i]
        v = abs(T - h * 0.006 - A)
        if vmin > v:
            ans = i
            vmin = v
    return ans+1


if __name__ == '__main__':
    inputs = read()
    outputs = solve(*inputs)
    if outputs is not None:
        print("%s" % str(outputs))


Measured memory_bytes: 9084
#include<iostream>
#include<vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <functional>
using namespace std;

int main(){
	long long N;
	long long A;
	bool is = false;
	
	A = 1000000000000;

	cin >> N;

	for (long long i = sqrt(N); i >= 1; i--){
		if (N % i == 0){
			long long tmp = N / i;
			if (A > i + tmp){
				A = (i - 1) + (tmp - 1);
				is = true;
			}
		}
	}
	
	cout << A << endl;
	return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<string>
#include<vector>
#include<iomanip>
#include<algorithm>
#include<queue>
#include<stack>
#include<map>
using namespace std;
#define ll long long
int main(){
    ll N,W;
    cin >> N >> W;
    ll ans[N+1][W+1];
    ll i,j;
    for(j=0;j<=W;j++){
      ans[0][j]=0;
    }
    ll w,v;
    for(i=1;i<=N;i++){
      cin >> w >> v;
      for(j=0;j<=W;j++){
        ans[i][j]=ans[i-1][j];
        if(j>=w && ans[i][j]<ans[i-1][j-w]+v)ans[i][j]=ans[i-1][j-w]+v;
      }
    }
    cout << ans[N][W];
    return 0;
}


Measured memory_bytes: 79104
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) throws IOException {
		// TODO 自動生成されたメソッド・スタブ
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line = "";

		while ((line = br.readLine()) != null) {

			int[] a = new int[4];
			int[] b = new int[4];
			int hit = 0;
			int blow = 0;

			String[] as = line.split(" ");
			for (int i = 0; i < a.length; i++) {
				a[i] = Integer.parseInt(as[i]);
			}

			String[] bs = br.readLine().split(" ");
			for (int i = 0; i < b.length; i++) {
				b[i] = Integer.parseInt(bs[i]);
			}

			//
			for (int i = 0; i < a.length; i++) {
				for (int j = 0; j < b.length; j++) {
					if (a[i] == b[j] && i == j)
						hit++;
					else if (a[i] == b[j] && i != j)
						blow++;
				}
			}
			//
			System.out.println(hit + " " + blow);
		}
	}
}

Measured memory_bytes: 17080
import java.util.HashSet;
import java.util.Scanner;

public class Main {

	static Scanner sc = new Scanner(System.in);
	static char[][] plate = new char[10][];
	static int[][] plateI = new int[10][2];
	static int ans;
	static HashSet<Integer> used = new HashSet<Integer>();

	public static void main(String[] args) {
		while (true) {
			plate[0] = sc.next().toCharArray();
			if (plate[0].length == 3) break;
			for (int i = 1; i < 10; ++i) {
				plate[i] = sc.next().toCharArray();
			}
			for (int i = 0; i < 10; ++i) {
				plateI[i][0] = plateI[i][1] = 0;
				for (int j = 0; j < 5; ++j) {
					if (plate[i][j] == '1') {
						plateI[i][0] += 1 << j;
						plateI[i][1] += 1 << (4 - j);
					}
				}
			}
			System.out.println(solve());
		}
	}

	static int solve() {
		ans = 0;
		used.clear();
		boolean[] selected = new boolean[10];
		dfs(0, 0, selected);
		return ans;
	}

	static void dfs(int state, int depth, boolean[] selected) {
		if (depth == 5) {
			finish(state, selected);
			return;
		}
		for (int i = 0; i < 10; ++i) {
			if (selected[i]) continue;
			selected[i] = true;
			dfs(state + ((0x1F - plateI[i][0]) << (depth * 5)), depth + 1, selected);
			if (plateI[i][0] != plateI[i][1]) {
				dfs(state + ((0x1F - plateI[i][1]) << (depth * 5)), depth + 1, selected);
			}
			selected[i] = false;
		}
	}

	static void finish(int state, boolean[] selected) {
		if (used.contains(state)) return;
		int[] rev = new int[5];
		for (int i = 0; i < 25; ++i) {
			if ((state & (1 << i)) != 0) {
				rev[i % 5] += 1 << (i / 5);
			}
		}
		//		System.out.println(Integer.toBinaryString(state));
		//		for (int i = 0; i < 5; ++i) {
		//			System.out.println(Integer.toBinaryString(rev[i]));
		//		}
		boolean[] rest = selected.clone();
		for (int i = 0; i < 5; ++i) {
			boolean found = false;
			for (int j = 0; j < 10; ++j) {
				if (!rest[j] && (rev[i] == plateI[j][0] || rev[i] == plateI[j][1])) {
					rest[j] = true;
					found = true;
					break;
				}
			}
			if (!found) return;
		}
		int all = (1 << 25) - 1;
		used.add(state);
		used.add(all - state);
		int mir = mirror(state);
		used.add(mir);
		used.add(all - mir);
		for (int i = 0; i < 3; ++i) {
			state = rotate(state);
			mir = rotate(mir);
			used.add(state);
			used.add(all - state);
			used.add(mir);
			used.add(all - mir);
		}
		++ans;
	}

	static int rotate(int v) {
		int ret = 0;
		for (int i = 0; i < 25; ++i) {
			if ((v & (1 << i)) != 0) {
				ret += 1 << ((i % 5) * 5 + (4 - i / 5));
			}
		}
		return ret;
	}

	static int mirror(int v) {
		int ret = 0;
		for (int i = 0; i < 25; ++i) {
			if ((v & (1 << i)) != 0) {
				ret += 1 << ((i / 5) * 5 + (4 - i % 5));
			}
		}
		return ret;
	}

	static void print(int v) {
		for (int i = 0; i < 5; ++i) {
			for (int j = 0; j < 5; ++j) {
				System.out.print((v >> (i * 5 + j)) & 1);
			}
			System.out.println();
		}
	}

}

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

int main() {
  int N,
  	  A = 0,
  	  B = 0;
  vector<int> vec;
  
  cin >> N;
  vec = vector<int>(N);
  
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
  }
  
  sort(vec.begin(), vec.end());
  reverse(vec.begin(), vec.end());
  
  for (int i = 0; i < N; i++) {
    if (i % 2 == 0) {
      A += vec.at(i);
    } else {
      B += vec.at(i);
    }
  }
  
  cout << A - B << endl;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task solver = new Task();
        solver.solve(in, out);
        out.close();
    }

    static class Task {
    	long A, B, C;
    	
        void solve(InputReader in, PrintWriter out) {
    		A = in.nextLong();
    		B = in.nextLong();
    		C = in.nextLong();
    		
    		if ((A % 2)*(B % 2)*(C % 2) == 0) {
    			out.println(0);
    		} else {
    			out.println(A*B >= B*C ? 
    					(B*C >= C*A ? C*A : B*C) : (A*B >= C*A ? C*A : A*B));
    		}
    	}
    }

    static class InputReader {
        BufferedReader reader;
        StringTokenizer tokenizer;

        InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream));
            tokenizer = null;
        }

        String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        int[] nextIntArray(int size) {
            int[] arr = new int[size];
            for (int i = 0; i < size; i++) {
                arr[i] = nextInt();
            }
            return arr;
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        long[] nextLongArray(int size) {
            long[] arr = new long[size];
            for (int i = 0; i < size; i++) {
                arr[i] = nextLong();
            }
            return arr;
        }
    }
}


Measured memory_bytes: 20692
#include<iostream>
#include<algorithm>
#include<vector>
#include<stdio.h>
#include<cstring>
#include<math.h>
#include<map>
#include<bitset>
#include<iomanip>
#include<queue>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
using P = pair<int, int>;

int H, W;
int c[10][10];
int A[200][200];

int main() {
  cin >> H >> W;
  rep(i, 10) {
    rep(j, 10) {
      cin >> c[i][j];
    }
  }
  rep(i, H) {
    rep(j, W) {
      cin >> A[i][j];
    }
  }

  rep(k, 10) {
    rep(i, 10) {
      rep(j, 10) {
        c[i][j] = min(c[i][k] + c[k][j], c[i][j]);
      }
    }
  }

  int ans = 0;
  rep(i, H) {
    rep(j, W) {
      if(A[i][j] == -1) continue;
      ans += c[A[i][j]][1];
    }
  }
  cout << ans << endl;
  return 0;
}

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

int main(){
    int N,M;
    cin >> N >> M;
    int k[M];
    int s[M][N];
    int p[M];
    for(int i = 0; i < M; i++) {
        cin >> k[i];
        for (int j = 0; j < k[i]; j++){
            cin >> s[i][j];
        }
    }
    for(int i = 0; i < M; i++) {
        cin >> p[i];
    }

     int maxv = pow(2,N);
     int ans = 0;

    //  for(int i = 0; i < M; i++) {
         
    //     for (int j = 0; j < k[i]; j++){
    //         cout << s[i][j] << " ";
    //     }
    //     cout << p[i];
    //     cout << endl;
    //  }
     
    for(int i = 0; i < maxv; i++) {
        int v = i;
        int itr = 0;
        vector<int> onoff(N, 0);

        int bit = v % 2;
        onoff[N - 1 -itr] = bit;
        while(v / 2 > 0){
            itr++;
            v /= 2;

            bit = v % 2;
            onoff[N - 1 -itr] = bit;
        }

        bool success = true;
        for(int j = 0; j < M; j++) {
            //cout << "j:" <<  j << endl;
            int on = 0;
            for(int l = 0; l < k[j]; l++){
                //cout << "s[j][i]:" << s[j][l] << endl;
                if(onoff[s[j][l]-1] == 1){
                    on += 1;
                }
            }

            //cout << on << endl;
            if(on%2 != p[j]){
                success = false;
                break;
            }
        }

        if(success){
            ans++;
        }
    }

    cout << ans << endl;
    

    return 0;
}

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

int main(){
  int i,j;ll cnt=0;
  int n;
  cin>>n;
  ll a[n];
  for(i=0;i<n;i++)cin>>a[i];
  sort(a,a+n);
  ll s[n+1];
  s[0]=0;
  for(i=1;i<=n;i++)s[i]=s[i-1]+a[i-1];
  for(i=n-1;i>=0;i--){
    if(2*s[i]<a[i]){
      cnt=i;
      break;
    }
  }
  cout<<n-cnt<<endl;
}

Measured memory_bytes: 1792
parseInt(x) = parse(Int, x)
parseBigInt(x) = parse(BigInt, x)
parseFloat(x) = parse(Float64, x)
parseBigFloat(x) = parse(BigFloat, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
    n,k=parseMap(split(readline()))
    println(min(n%k,abs(n%k-k)))
end
main()

Measured memory_bytes: 109716
integer N,K
integer,allocatable,dimension(:)::H
integer DP(10**5)
read*,N,K
allocate(H(N))
read*,H

DP=huge(DP)/2
DP(1)=0
DP(2)=abs(H(2)-H(1))
if(N==2)then
  print"(i0)",DP(N)
  STOP
endif
do i=3,N
  do j=1,min(K,i-1)
    DP(i)=min(DP(i-j)+abs( H(i)-H(i-j) ),DP(i))
  end do
end do
print"(i0)",DP(N)
end


Measured memory_bytes: 1536
#include "bits/stdc++.h"
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define BUGAVOID(x) x
#define rep(...) BUGAVOID(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c) c.begin(),c.end()
#define mp make_pair
#define write(x) cout<<(x)<<"\n"
using namespace std; typedef long long ll;
typedef vector<int> vi; typedef vector<ll> vll; template<class T>using vv = vector<vector<T>>;
template<class T>vv<T> vvec(size_t n, size_t m, T v) { return vv<T>(n, vector<T>(m, v)); }
template<class T>bool chmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
template<class T>bool chmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
constexpr int INF = 1 << 28, MOD = 1e9 + 7; constexpr ll LINF = 1ll << 60; constexpr double EPS = 1e-6;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); }; }aaaa;

int main() {
    int M, K, N;
    cin >> M >> K;
    N = 1 << M;

    if (K >= N) {
        write(-1);
        return 0;
    }
    else if (M == 1) {
        if (K == 1) {
            write(-1);
        }
        else {
            write("0 0 1 1");
        }
        return 0;
    }

    rep(i, N) {
        if (i != K) {
            cout << i << " ";
        }
    }
    cout << K << " ";
    for (int i = N - 1; i >=0; --i) {
        if (i != K) {
            cout << i << " ";
        }
    }

    cout << K << endl;
}

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

int main() {

  int n,m;

  cin >> n;
  vector<string> s(n);
  for(int i = 0; i < n; i++)
    cin >> s.at(i);
  
  cin >> m;
  vector<string> t(m);
  for(int i = 0; i < m; i++)
    cin >> t.at(i);

  int max = 0;

  for(int i = 0; i < n; i++){
      
      int point = 0;
      string word = s.at(i);

      for(int j = 0; j < n; j++){
          if( word == s.at(j) )
              point++;
      }

      for(int j = 0; j < m; j++){
          if( word == t.at(j) )
              point--;
      }

      if( max < point )
        max = point;

  }

  cout << max << endl;

}



Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
int T[1001];

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

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

	for(int i = 0; i < N; i++ ){
		for(int j = N-1; j > i; j-- ){
			if(T[j] < T[j -1]){
				int t;
				t = T[j];
				T[j] = T[j-1];
				T[j-1] = t;

			}
		}
	}

	//for(int i = 0; i < N; i++) cout << T[i] <<endl;

	int ans = T[N-1] - T[0];
	cout << ans <<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin >> n;
    int ac = 0, tle = 0, wa = 0, re = 0;
    while (n--)
    {
        string s;
        cin >> s;
        if ("AC" == s)
            ac++;
        else if ("TLE" == s)
            tle++;
        else if ("RE" == s)
            re++;
        else
            wa++;
        /* code */
    }
    cout << "AC x " << ac << endl;
    cout << "WA x " << wa << endl;
    cout << "TLE x " << tle << endl;
    cout << "RE x " << re << endl;

    return 0;
}

Measured memory_bytes: 3632
#include<iostream>
#include<iomanip>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
 
using namespace std;
 
#define P(p) cout<<(p)<<endl
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.begin(), v.end(),greater<int>());
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return
#define C(i) cin>>i
#define C2(i,j) cin>>i>>j
#define C3(i,j,k) cin>>i>>j>>k
#define C4(i,j,k,m) cin>>i>>j>>k>>m
////////////////////////////////////////////////////////////

int main(){
	string a,b;
	cin >> a >> b;
	
	a += b;

	int c = stoi(a);
	
	rep(i,0,100000){
		if(c == i*i){
			Yes;
			ret 0;
		}
	}
	No;
	ret 0;
}

Measured memory_bytes: 256
object Main{
	def main(args:Array[String]){
		val s = new java.util.Scanner(System.in)
		val n=s.nextInt
		val t=s.next
		val a= (0 to n-1).filter(i=>t(i)=='R')
		val b= (0 to n-1).filter(i=>t(i)=='B')
		println(if(a.size>b.size)"Yes" else "No")
	}
}

Measured memory_bytes: 27296
#include <bits/stdc++.h>
using namespace std;
int n,a[100002],dp[100002];
int main(){
	cin>>n;
	for(int i=1;i<=n;i++)	cin>>a[i];
	memset(dp,0x3f3f3f3f,sizeof(dp));
	dp[1]=0;dp[2]=abs(a[1]-a[2]);
	for(int i=3;i<=n;i++){
		dp[i]=min(dp[i-1]+abs(a[i]-a[i-1]),dp[i-2]+abs(a[i]-a[i-2]));
	}
	cout<<dp[n]<<endl;
}

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

int main(){
    int a,b;
    cin>>a>>b;
    for(int i=0;i<2000;i++) if(floor(i*0.08)==a && floor(i*0.1)==b) cout<<i<<endl,exit(0);
    cout<<-1<<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<cassert>
#define PB push_back
#define MP make_pair
#define sz(v) (in((v).size()))
#define forn(i,n) for(in i=0;i<(n);++i)
#define forv(i,v) forn(i,sz(v))
#define fors(i,s) for(auto i=(s).begin();i!=(s).end();++i)
#define all(v) (v).begin(),(v).end()
using namespace std;
typedef long long in;
typedef vector<in> VI;
typedef vector<VI> VVI;
int main(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  in n;
  cin>>n;
  map<in,in> m;
  in t;
  forn(z,n){
    cin>>t;
    ++m[t];
  }
  in sm=1;
  fors(i,m)
    sm+=i->second-1;
  sm/=2;
  n-=sm*2;
  cout<<n<<endl;
  return 0;
}


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

int main(){
    int n;
    while(1){
        scanf("%d",&n);
        if(n==0) break;
        double s[n],sum=0,m,a=0;
        for(int i=0;i<n;i++){
            scanf("%lf",&s[i]);
            sum+=s[i];
        }
        m=sum/n;
        for(int i=0;i<n;i++){
            a+=(s[i]-m)*(s[i]-m)/n;
        }
        printf("%lf\n",sqrt(a));
    }
}


Measured memory_bytes: 3232
#include <iostream>
#include <cstdio>
#include <cstdlib>
using namespace std;
#define MAX 2000000
#define VMAX 10000



int main(){
	unsigned short *A, *B;
	int C[VMAX+1];
	int n;
	cin>>n;
	A = (unsigned short *)malloc(sizeof(unsigned short)*n+1);
	B = (unsigned short *) malloc(sizeof(unsigned short)*n+1);

	for(int i=0; i<=VMAX; i++) C[i] = 0;

	for(int i=0; i<n; i++){
		cin>>A[i];
		C[A[i]]++;
	}
	for(int i=1; i<=VMAX; i++) C[i] = C[i]+C[i-1]; //这里必须有等号

	for(int i=0; i<n; i++){
		B[C[A[i]]] = A[i];
		C[A[i]]--;
	}

	for(int i=1; i<=n; i++){
		if(i!=1) cout<<" ";
		cout<<B[i];
	}
	cout<<endl;

	return 0;
}


Measured memory_bytes: 10936
#include <stdio.h>

int main( void ) {
	int n, a, b, c, d, sum;

	for ( ; scanf( "%d", &n ) == 1; printf( "%d\n", sum ) ) {
		sum = 0;
		for ( a = 0; a < 10; a++ )
			for ( b = 0; b < 10; b++ )
				for ( c = 0; c < 10; c++ )
					sum += 0 <= ( d = n - a - b - c ) && d <= 9 ;
	}

	return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
// iostream is too mainstream
#include <cstdio>
// bitch please
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <cmath>
#include <iomanip>
#include <time.h>
#define dibs reserve
#define OVER9000 1234567890
#define ALL_THE(CAKE,LIE) for(auto LIE =CAKE.begin(); LIE != CAKE.end(); LIE++)
#define tisic 47
#define soclose 1e-8
#define chocolate win
// so much chocolate
#define patkan 9
#define ff first
#define ss second
#define abs(x) ((x < 0)?-(x):x)
#define uint unsigned int
#define dbl long double
#define pi 3.14159265358979323846
using namespace std;
// mylittledoge

typedef long long cat;

#ifdef DONLINE_JUDGE
	// palindromic tree is better than splay tree!
	#define lld I64d
#endif

cat pw(cat a, cat e, cat mod) {
	if(e <= 0) return 1;
	cat x = pw(a, e/2, mod);
	x = (x*x)%mod;
	if(e&1) x = (x*a)%mod;
	return x;
}

int main() {
	cin.sync_with_stdio(0);
	cin.tie(0);
	cout << fixed << setprecision(10);
	int N, K;
	cin >> N >> K;
	cat mod = 998244353, ans = 0;
	vector<cat> fac(K+1, 1), inv(K+1, 1);
	for(int i = 1; i <= K; i++) {
		fac[i] = (i * fac[i-1]) % mod;
		inv[i] = pw(fac[i], mod-2, mod);
	}
	vector<cat> C(K+1, 0), Cs(K+2, 0);
	for(int i = 0; i <= K; i++) {
		C[i] = inv[i]*inv[K-i+1]%mod*(K+1-2*i)%mod;
		if(C[i] < 0) C[i] += mod;
		Cs[i+1] = (Cs[i] + C[i]) % mod;
	}
	for(int r = 0; r <= K; r++) {
		int b = K-r;
		if(b > r) continue;
		int D = r-b;
		int x = N-D;
		if(x <= 0) {
			ans = (ans + inv[b] * inv[r]) % mod;
			continue;
		}
		else if(x <= K-r) {
			if(D != 0) ans = (ans + Cs[K-r+1] - Cs[x]) % mod;
			else for(int p = x; p <= K-r; p++) ans = (ans + inv[p-1]%mod*inv[K-p+1]%mod*(K-2*p+2)%mod*inv[K]%mod*fac[K-1]) % mod;
		}
	}
	ans = (ans * fac[K]) % mod;
	if(ans < 0) ans += mod;
	cout << ans << "\n";
	return 0;}

// look at my code
// my code is amazing


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

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define lcm( a, b ) (a)/__gcd((a),(b))*(b)
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair< int, int > P;
typedef pair< LL, LL > LP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;
static const int SIZE = 200005;

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

LL fac[SIZE], finv[SIZE], inv[SIZE];
void combInit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for( int i = 2; i < SIZE; ++i ) {
        fac[i] = (fac[i - 1] * i) % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = (finv[i - 1] * inv[i]) % MOD;

    }
}

LL comb(int n, int k) {
    if( n < k ) return 0;
    if( n < 0 || k < 0 ) return 0;
    return (fac[n] * (finv[k] * finv[n - k] % MOD)) % MOD;

}

vector< int > Div( int n ) {
    vector< int > ret;
    for( int i = 1; i * i <= n; ++i ) {
        if( n % i == 0 ) {
            ret.pb( i );

            if( i * i != n ) ret.pb( n / i );
        }
    }
    sort( all( ret ) );
    return ret;
}

int dp[3005][3005];

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

    string s, t;
    cin >> s >> t;
    for( int i = 1; i <= s.size(); ++i ) {
        for( int j = 1; j <= t.size(); ++j ) {
            if( s[i - 1] == t[j - 1] ) {
                dp[i][j] = dp[i - 1][j - 1] + 1;

            } else {
                dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);

            }
        }
    }

    int n, m;
    n = s.size(); m = t.size();
    vector< char > res;
    while( n > 0 && m > 0 ) {
        if( dp[n][m] == dp[n - 1][m] ) {
            --n;

        } else if( dp[n][m] == dp[n][m - 1] ) {
            --m;

        } else {
            --n;
            --m;
            res.pb(s[n]);

        }
    }
    reverse(all(res));
    for( int i = 0; i < res.size(); ++i ) cout << res[i];
    cout << endl;
    /*
    cout << "  ";
    for( int i = 0; i < t.size(); ++i ) cout << t[i] << " ";
    cout << endl;
    for( int i = 1; i <= s.size(); ++i ) {
        cout << s[i - 1] << " ";
        for( int j = 1; j <= t.size(); ++j ) {
            cout << dp[i][j] << " ";

        }
        cout << endl;

    }
    */
    return 0;
}



Measured memory_bytes: 37120
#include <numeric>
#include<iostream>
#include<set>
#include<queue>
#include<vector>
#include<map>
#include<stack>
#include<algorithm>
#include <sstream>
#include<string.h>
#include <cmath>
#include <iomanip>
using namespace std;
#define inf 1000000007
#define int long long
#define rep(i,j,n) for(int i=j;i<n;i++)
typedef pair<int,int>  P;
struct edge{int from,to,cost;};
double pi = 3.141592653589793;
//使うやつはここから下に置こうな
signed main(){
    int n,x;cin>>n>>x;
    int a[114514];
    rep(i,0,n)cin>>a[i];
    int ans=0;
    rep(i,0,n-1){
        if(a[i]+a[i+1]>=x){
            if(a[i]>x){
                ans+=a[i+1]+a[i]-x;
                a[i+1]=0;
                a[i]=x;
            }
            else {
                ans+=a[i+1]+a[i]-x;
                a[i+1]=x-a[i];
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {
    static String s;
    static int len;
    static Character[] c;

    private static void init() {
        Scanner scanner = new Scanner(System.in);
        s = scanner.nextLine();
        len = s.length();
        c = new Character[len];
        for(int i = 0; i < len; i++) {
            c[i] = s.charAt(i);
        }
        scanner.close();
    }


    public static void main(String args[]) {
        init();

        boolean ok = true;
        for(int i = 0; i < len; i++) {
            if(i % 2 == 0 && !(c[i].equals('R') || c[i].equals('U') || c[i].equals('D'))) {
                ok = false;
                break;
            }
            if(i % 2 == 1 && !(c[i].equals('L') || c[i].equals('U') || c[i].equals('D'))) {
                ok = false;
                break;
            }
        }

        if(ok) System.out.println("Yes");
        else System.out.println("No");
    }
}


Measured memory_bytes: 25172
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
signed main(){
  Int n;
  cin>>n;
  vector<Int> as(n),bs(n);
  for(Int i=0;i<n;i++) cin>>as[i]>>bs[i];

  const Int DAY = 86400;
  vector<Int> cnt(DAY,0);
  Int sum=0;
  for(Int i=0;i<n;i++){
    sum+=as[i];
    sum%=DAY;
    cnt[sum]++;
    sum+=bs[i];
  }

  vector<Int> sm(DAY*2+1,0);
  for(Int i=0;i<DAY*2;i++) sm[i+1]=sm[i]+cnt[i%DAY];

  Int ans=0;
  const Int V = 10801;
  for(Int i=0;i+V<=DAY*2;i++)
    chmax(ans,sm[i+V]-sm[i]);

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


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

int main()
{
    int N;
    cin >> N;
    vector<int> a(N);
    for (int i = 0; i < N; i++)
    {
        cin >> a.at(i);
    }

    int a_s = a.at(0), a_l = a.at(0);
    map<int, int> m;
    for (int i = 0; i < N; i++)
    {
        a_s = min(a_s, a.at(i));
        a_l = max(a_l, a.at(i));
        m[a.at(i)]++;
    }
    if (m.size() > 2 || a_l - a_s > 1)
    {
        cout << "No" << endl;
        return 0;
    }

    if (m.size() == 1)
    {
        int ai = a.at(0);
        if (ai == N - 1)
            cout << "Yes" << endl;
        else if (ai <= N / 2)
            cout << "Yes" << endl;
        else
            cout << "No" << endl;
        return 0;
    }

    int n_solo = m[a_s];
    int n_color = a_l;
    if (n_solo + 1 <= n_color && n_color <= n_solo + (N - n_solo) / 2)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 8240