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

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)

using ll = long long;
ll INF = LLONG_MAX;
 
using vc = vector<char>;
using vi = vector<int>;
using vb = vector<bool>;
ll N, M;
vector<vi> graph; 
vi inDegree;
vi parent;
vb visited; 
void search(int cur, int par) {
    parent[cur] = par;
    visited[cur] = true;
    for (int n : graph[cur]) {
        --inDegree[n];
    }
    for (int n : graph[cur]) {
        if (!visited[n] && inDegree[n] == 0) search(n, cur);
    }
}

int main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin >> N >> M;
    graph.resize(N);
    inDegree.resize(N);
    parent.resize(N);
    visited.resize(N);
    F0R(i, N-1+M) {
        int a, b; cin >> a >> b; --a; --b;
        graph[a].push_back(b);
        ++inDegree[b];
    }
    F0R(i, N) if (inDegree[i] == 0) {search(i, -1); break;}    
    F0R(i, N) cout << parent[i] + 1 << endl;
}

Measured memory_bytes: 11776
n, k = map(int,input().split())
d_lst = []
a_lst = []
for i in range(k):
    d = int(input())
    a = list(map(int,input().split()))
    d_lst.append(d)
    a_lst.append(a)

sun_lst = [0] * n
for i in range(k):
    d = d_lst[i]
    a = a_lst[i]

    for j in range(d):
        sun = a[j]
        sun_lst[sun-1] = 1

ans = 0
for i in range(n):
    if sun_lst[i]==0:
        ans += 1

print(ans)

Measured memory_bytes: 9156
//   _/                _/                 _/_/_/   _/
//_/_/_/_/   _/_/   _/_/_/_/   _/_/    _/       _/_/
// _/     _/    _/   _/     _/    _/  _/_/_/     _/
//_/     _/    _/   _/     _/    _/  _/    _/   _/
// _/_/   _/_/       _/_/   _/_/      _/_/     _/
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;
using ll=long long;
const int MOD=1e9+7;
const double pi=3.14159265358979323846;
const int inf=1e9;
const ll INF=1e18;
using P=pair<int,int>;
int main() {
  cin.tie(0),cout.tie(0);
  ios::sync_with_stdio(false);
  ll n,k,a[100005]={},ans=inf,cnt;
  cin >> n >> k;
  for(int i=0; i<n; i++) {
    cin >> a[i];
  }
  for(int i=0; i<n-k+1; i++) {
    cnt=min(abs(a[i])+abs(a[i]-a[i+k-1]),abs(a[i+k-1])+abs(a[i]-a[i+k-1]));
    ans=min(ans,cnt);
  }
  cout << ans << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <cstring>
#include <map>
#include <algorithm>
#include <math.h>
#include <iostream>     // std::cout, std::fixed
#include <iomanip>
#include<queue>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <iostream>
#include <sstream>
using namespace std;
typedef long long ll;

int main () {
    ios_base::sync_with_stdio(false);
    int n;
    cin>>n;
    vector<pair<int, pair<int, int>>> t_p(n);
    for(int i=0;i<n;i++)
    {
        int t,x,y;
        cin>>t>>x>>y;
        t_p[i]={t,{x,y}};
    }
    sort(t_p.begin(), t_p.end());
    bool ok=true;
    pair<int, int> cur={0,0};
    ll cur_time=0;
    for(auto p:t_p)
    {
        ll time_to_be=p.first;
        pair<int, int> next=p.second;
        ll dist=abs(cur.first-next.first)+abs(cur.second-next.second);
        ll time_have=time_to_be-cur_time;
        if(time_have-dist<0)
            ok=false;
        if ((time_have-dist)%2==1)
            ok=false;
    }
    if(ok)
        cout<<"Yes";
    else
        cout<<"No";
    
    return 0;
}


Measured memory_bytes: 1408
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cstdlib>
#include<queue>
#include<set>
#include<cstdio>

using namespace std;

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

typedef vector<int> vec;
typedef vector<vec> mat;

const ll mod = 2019;


// 0~nでmodで割ったときにx余る数の数
ll f(ll n, ll x){
    if(n < x) return 0;
    ll res = (n - x) / mod + 1;
    return res;       
}

int main(){
    ll l, r;
    cin >> l >> r;
    ll ans = 2500;
    if(r - l >= 2019){
        ans = 0;
    }else{
        for (ll i = l; i < r; i++){
            for (ll j = i + 1; j <= r; j++){
                ll m = (i % mod) * (j % mod);
                m %= mod;
                ans = min(ans, m);
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3584
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;

int n, w, g;
long long ans = 0, sum[100005], add;

void solve(int i) {

    if(i + g > w)
        return;

    solve(i+1);

    if(sum[i] != 0){

        if(sum[i + g] < sum[i] + add)
            sum[i + g] = sum[i] + add;

        ans = max(ans, sum[i + g]);
    }
}


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

    for (int i = 1; i <= n; ++i) {
        cin >> g >> add;

        solve(1);

        sum[g] = max(sum[g], add);
        ans = max(ans, add);
    }


    cout << ans;
    return 0;
}


Measured memory_bytes: 5456
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int arr[100009],n;
ll dp[100009][3];
ll f(int from,int to)
{
    if(to>n) return 0;
    if(from>=n) return 0;
    if(from==n-1) {dp[from][2] = 0;return dp[from][to]=abs(arr[n]-arr[n-1]);}
    if(dp[from][to]!=-1) return dp[from][to];
    if(to==1)
    {
        return dp[from][to] = abs(arr[from+1]-arr[from]) + min(f(from+1,1),f(from+1,2));
    }
    else if (to==2)return dp[from][to] = abs(arr[from+2]-arr[from]) + min(f(from+2,2),f(from+2,1));
    return 0;
   // return dp[pos] = min(abs(arr[pos+1]-arr[pos])+f(pos+1),abs(arr[pos+2]-arr[pos])+f(pos+2));
}
int main()
{
    int i;
    scanf("%d",&n);
    for(i=1;i<=n;i++)
    {
        scanf("%d",&arr[i]);
    }
    memset(dp,-1,sizeof dp);
    printf("%lld\n",min(f(1,1),f(1,2)));
}


Measured memory_bytes: 6144
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

int main(){
  int R, G, B, n;
  cin >> R >> G >> B >> n;
  int ans = 0;
  rep(i, n+1){
    int now = i*R;
    if(now > n) break;
    rep(j, n+1){
      int nx = now + j * G;
      if(nx > n) break;
      if((n-nx) % B == 0){
        // cerr << i << " " << j << endl;
        ans++;
      }
    }
  }
  cout << ans << endl;
  return 0;
}

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

int main()
{
    int n;
    cin >> n;
    vector<int> c(n - 1), s(n - 1), f(n - 1);
    for (int i = 0; i < n - 1; i++)
    {
        cin >> c[i] >> s[i] >> f[i];
    }

    for (int i = 0; i < n; i++)
    {
        long long ans = 0;
        for (int j = i; j < n - 1; j++)
        {
            if(ans < s[j])
            {
                ans = s[j] + c[j];
                //cout << s[j] + c[j] << " ";
            }
            else
            {
                if((ans - s[j]) % f[j] == 0)
                {
                    ans += c[j];
                    //cout << c[j] << " ";
                }
                else
                {
                    ans += f[j] - (ans - s[j]) % f[j] + c[j];
                    //cout << f[j] - (ans - s[j]) % f[j] + c[j] << " ";
                }
                
            }
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 3644
N=gets.to_i
A=gets.split.map(&:to_i)

zero=false
cnt=0
abssum=0
absmin=Float::INFINITY
A.each do |a|
    zero=true if a == 0
    cnt += 1 if a < 0
    t = a.abs
    abssum += t
    absmin = t if t < absmin
end

if cnt % 2 == 0 || zero
    puts abssum
else
    puts abssum - absmin * 2
end


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

int c1, c2, c3;

bool cards[11];

void solve() {
	memset(cards, false, sizeof cards);
	cards[c1] = cards[c2] = cards[c3] = true;
	
	int able_num = 20 - (c1 + c2);
	int count = 0;
	for (int i = 1; i < 11; i++) {
		if (cards[i]) continue;

		if (able_num >= i) {
			count++;
		}
	}
	if (count >= 4) {
		cout<<"YES";
	} else {
		cout<<"NO";
	}
	cout<<endl;
}

int main(int argc, const char *argv[]) {
	while (cin>>c1>>c2>>c3) {
		solve();
	}
	return 0;
}

Measured memory_bytes: 804
#include <iostream>

using namespace std;

int main()
{
    unsigned long dp[31] = { 1, 1, 2 };
    for( int i=3; i<31; ++i )
        dp[i] = dp[i-3] + dp[i-2] + dp[i-1];

    int n;
    while( cin >> n ) {
        if ( n == 0 )
            break;
        cout << dp[n] / 3650 + ( dp[n] % 3650 != 0 ) << endl;
    }
}

Measured memory_bytes: 1156
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>
#include <tuple>

#define DEBUG(x) cout<<#x<<": "<<x<<endl

using namespace std;

class UnionFind {
	public:
		vector<int> Parent;

		UnionFind(int N){
			Parent = vector<int>(N, -1);
		}

		int root(int A){
			if (Parent[A] < 0) return A;
			else return Parent[A] = root(Parent[A]);
		}

		int size(int A){
			return -Parent[root(A)];
		}

		bool connect(int A, int B){
			A = root(A);
			B = root(B);
			if( A == B ) return false;

			if( size(A) < size(B) ) swap(A, B);
			Parent[A] += Parent[B];
			Parent[B] = A;
			return true;
		}
};

int main(){

	int N, M;
	cin >> N >> M;
	vector<int> A(M), B(M);

	for(int i = 0; i < M ; i++){
		cin >> A[i] >> B[i];
		A[i]--;
		B[i]--;
	}

	vector<long long> ans(M);
	ans[M-1] = (long long)N * (N - 1) / 2;

	UnionFind Uni(N);

	for( int i = M - 1 ; i >= 1 ; i-- ){
		ans[ i - 1 ] = ans[i];
		if( Uni.root(A[i]) != Uni.root(B[i]) ) {
			ans[ i - 1 ] -= (long long)Uni.size(A[i]) * Uni.size(B[i]);
			Uni.connect(A[i], B[i]);
		}
	}

	for(int i = 0; i < M; i++){
		cout << ans[i] << endl;
	}
		
	return 0;
}


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

int main() {
	int n;
	cin >> n;
	long long x[300000];
	long long y[300000];
	long long d;
	cin >> d;
	d *= d;
	int cnt = 0;
	long long z;
	re(i, n) {
		cin >> x[i] >> y[i];
		z = x[i] * x[i] + y[i] * y[i];
		if (z <= d)cnt++;
	}
	
	cout << cnt << endl;
	

	return 0;
}

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

#define pb push_back
#define all(a) (a).begin(), (a).end()

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

int main() {
    ios::sync_with_stdio(false);cin.tie(nullptr);
    ll n, a, b; cin >> n >> a >> b;
    ll ans = a * (n / (a + b));
    ans += min(a, n % (a + b));
    cout << ans << '\n';
}

Measured memory_bytes: 256
#include <stdio.h>
int main()
{
	int n;
	scanf("%d",&n);
	n=n%10;
	if(n==2||n==4||n==5||n==7||n==9) printf("hon");
	else if(n==3) printf("bon");
	else printf("pon");
	return 0;
} 

Measured memory_bytes: 1736
A, B, C = list(map(int, input().split()))
K = int(input())

for i in range(K):
    if B <= A:
        B = B * 2
        #print("B=",B)
    else:
        C = C * 2
        #print("C=",C)
        

if C > B and B > A:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 61620
#include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define pb push_back
#define MP(a, b) make_pair((a), (b))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;

ll mod_pow(ll x, ll n, ll mod) {
    if(n == 0)
        return 1;
    ll res = mod_pow(x * x % mod, n / 2, mod);
    if(n & 1)
        res = res * x % mod;
    return res;
}

int main() {
    ll N;
    cin >> N;
    vector<ll> A(N);
    rep(i, N) cin >> A[i];
    map<int, int> mp;
    rep(i, N) mp[A[i]]++;
    int ok = 1;
    if(N % 2) {
        if(mp[0] != 1)
            ok = 0;
        for(int i = 2; i < N; i += 2) {
            if(mp[i] != 2)
                ok = 0;
        }
    } else {
        for(int i = 1; i < N; i += 2) {
            if(mp[i] != 2)
                ok = 0;
        }
    }
    if(ok) {
        cout << mod_pow(2LL, N / 2, MOD) << endl;
    } else {
        cout << 0 << endl;
    }
    return 0;
}

Measured memory_bytes: 4864
def p_factors(n):
    if n < 2:
        return []
    
    d = 2
    result = []
    while n > 1 and d*d <= n:
        if n % d == 0:
            result.append(d)
        while n % d == 0:
            n //= d
        d += 1
        
    if n > 1:
        # n is a prime
        result.append(n)
    return result

def sieve_of_eratosthenes(ub):
    # O(n loglog n) implementation.
    # returns prime numbers <= ub.
    if ub < 2:
        return []
    prime = [True]*(ub+1)
    prime[0] = False
    prime[1] = False
    p = 2
    while p*p <= ub:
        if prime[p]:
            # don't need to check p+1 ~ p^2-1 (they've already been checked).
            for i in range(p*p, ub+1, p):
                prime[i] = False
        p += 1
    return [i for i in range(ub+1) if prime[i]]

def gcd(a, b):
    if a < b:
        a, b = b, a
    while b:
        a, b = b, a%b
    return a

def gcd_list(lst):
    if len(lst) == 0:
        return 0
    if len(lst) == 1:
        return lst[0]
    g = abs(lst[0])
    for l in lst[1:]:
        g = gcd(g, abs(l))
    return g

N = int(input())
A = [int(input()) for _ in range(N+1)]

cands = set(sieve_of_eratosthenes(N) + p_factors(gcd_list(A)))
answer = []
A = list(reversed(A))

for p in cands:
    flag = True
    # f(x) = Q(x) (x^p - x) + \sum_{i = 0}^{p-1} h_i x^i (mod p), 
    # where 
    # h_0 = a_0 (i = 0)
    # h_i = \sum_{j < N, j % (p-1) = i} a_j (i = 1, ..., p-2)
    # h_{p-1} = \sum_{j < N, j % (p-1) = 0} a_j - a_0 (i = p-1)
    if A[0] % p != 0:
        flag = False
    else:
        for i in range(1, min(N, p-1) + 1):
            h = 0  
            j = i
            while j <= N:
                h = (h + A[j]) % p
                j += p - 1
            if h != 0:
                flag = False
                break
                
    if flag:
        answer.append(p)

if answer:
    answer = sorted(answer)
print(*answer, sep='\n')

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

char P[500][500];
char R[500][500];
char B[500][500];

int main() {
    int H, W;
    cin >> H >> W;
    REP(i, H) REP(j, W) cin >> P[i][j];

    REP(i, H) REP(j, W) R[i][j] = (j % 2 == 1 || P[i][j] == '#') ? '#' : '.';
    REP(i, H) REP(j, W) B[i][j] = (j % 2 == 0 || P[i][j] == '#') ? '#' : '.';
    REP(j, W) R[0][j] = B[H-1][j] = '#', R[H-1][j] = B[0][j] = '.';

    REP(i, H) {
        REP(j, W) cout << R[i][j];
        cout << endl;
    }
    
    cout << endl;
    
    REP(i, H) {
        REP(j, W) cout << B[i][j];
        cout << endl;
    }
    
    return 0;
}


Measured memory_bytes: 1408
import java.util.*;
import java.io.*;
class Main
{
	public static void main (String[] args) throws Exception
	{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer t = new StringTokenizer(br.readLine());
		int n = Integer.parseInt(t.nextToken());
		int W = Integer.parseInt(t.nextToken());
		int[] w = new int[n+1], v = new int[n+1];
		for(int i = 1 ; i <= n ; i++)
		{
		      t = new StringTokenizer(br.readLine());
		      w[i] = Integer.parseInt(t.nextToken());
		      v[i] = Integer.parseInt(t.nextToken());
		}
		long[][] dp = new long[n+1][W+1];
		dp[0][0] = 0;
		for(int i = 0 ; i < W+1 ; i++) dp[0][i] = 0;
		for(int i = 1 ; i < n+1 ; i++)
		{
		      for(int j = 1 ; j < W+1 ; j++)
		      {
		            if(j-w[i] < 0) dp[i][j] = dp[i-1][j];
		            else dp[i][j] = Math.max(dp[i-1][j-w[i]]+v[i],dp[i-1][j]);
		      }
		}
		System.out.println(dp[n][W]);
	}
}

Measured memory_bytes: 127828
#include <stdio.h>

int main(void)
{
    int i=0; /*loop var*/
    int N; /*size of string(S,T)*/
    char S[100]={}, T[100]={}; /*user input string init*/
    
    scanf("%d",&N);
    scanf("%s %s",S,T);
    
    for(i=0;i<N;i++)    printf("%c%c",S[i],T[i]); /*main handling*/
    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
const int dx[] = {1,0,-1,0}, dy[] = {0,1,0,-1}; 

int main(){
    int h,w;
    cin >> h >> w;
    char field[51][51];
    bool used[51][51] = {};
    queue<tuple<int,int,int>> q;
    int cnt_dot = 0;

    for(int x = 0;x < h; x++){
        for(int y = 0;y < w; y++){
            cin >> field[x][y];
            if(field[x][y] == '.') cnt_dot++;
        }
    }
    
    q.push(make_tuple(0,0,1));
    int goal = 0;
    while(!q.empty()){
        int x,y,d;
        tie(x,y,d) = q.front(); q.pop();
        if(x == h-1 && y == w-1){
            goal = d;
            break;
        }

        if(used[x][y]) continue;
        used[x][y] = true;

        for(int i = 0; i < 4; i++){
            if(x + dx[i] < 0 || y + dy[i] < 0 || x + dx[i] >= h || y + dy[i] >= w || used[x + dx[i]][y + dy[i]] || field[x][y] == '#') continue;
            q.push(make_tuple(x + dx[i],y + dy[i], d+1));
        }
    }
    cout << (goal? cnt_dot - goal : -1) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <array>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>
#include <iomanip>

#define FOR(i, a, b) for(decltype(b) i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;

using namespace std;

#ifdef INPUT
#include <sstream>
stringstream input(R"(
31 10
)");
#define cin input
#endif

int main()
{
	int n, a, b, c;
	cin >> n >> a >> b >> c;
    int l[8];
    REP (i, n)
        cin >> l[i];

    int o = 0;
    int y = 10000000;
    while (true)
    {
        int x = o++;
        int m[4] = {};
        int p = 0;
        REP (i, n)
        {
            if (x % 4 != 3 && m[x % 4])
                p += 10;
            m[x % 4] += l[i];
            x /= 4;
        }
        if (x)
            break;
        if (!m[0] || !m[1] || !m[2])
            continue;
        p += abs(a - m[0]);
        p += abs(b - m[1]);
        p += abs(c - m[2]);
        y = min(y, p);
    }

    cout << y << endl;

	return 0;
}


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

void Sort(int arr[], int n)
{
    //cout << endl;
    int i, j, key;
    for(i = 1; i < n; i++)
    {
        // for(int k = 0; k < n; k++)  cout << arr[k] << " ";
        for(int k=0;k<n;k++) cout << arr[k] << (k==n-1?'\n':' ');


        key = arr[i];
        j = i-1;

        while(j >= 0 && arr[j] > key)
        {
            arr[j+1] = arr[j--];
        }
        arr[j+1] = key;
    }
    for(int k=0;k<n;k++) cout << arr[k] << (k==n-1?'\n':' ');

}
int main()
{
    int n, i;
    cin >> n;
    int arr[n];
    for(i = 0; i < n; i++)
        cin >> arr[i];
    Sort(arr, n);

    return 0;
}


Measured memory_bytes: 3088
#include<cstdio>

int calc(int a, int b, int s){
	switch(s){
		case 0 :
			return a + b;
		case 1 :
			return a - b;
		case 2:
			return a * b;
	}
	return 0;
}

bool dicision(int a, int b, int c, int d){
	int sum;
	char sym[] = "+-*";
	for(int i = 0; i < 3; i++){
		for(int j = 0; j < 3; j++){
			for(int k = 0; k < 3; k++){
				sum = calc(calc(calc(a,b,i), c, j), d, k);
				if(sum == 10){
					printf("((%d %c %d) %c %d) %c %d\n", a, sym[i], b, sym[j], c, sym[k], d);
					return true;
				}
			}
		}
	}
	for(int i = 0; i < 3; i++){
		for(int j = 0; j < 3; j++){
			for(int k = 0; k < 3; k++){
				sum = calc(calc(a,b,i), calc(c,d,k), j);
				if(sum == 10){
					printf("(%d %c %d) %c (%d %c %d)\n", a, sym[i], b, sym[j], c, sym[k], d);
					return true;
				}
			}
		}
	}
	return false;
}

int main(){
	int a[4], b[4], c[4], d[4];
	scanf("%d %d %d %d", &a[0],&a[1],&a[2],&a[3]);
	int t[4];
	while(a[0]){
		for(int i = 0; i < 4; i++){
			int b[] = {a[0], a[1], a[2]};
			t[0] = a[i];
			b[i] = a[3];
			for(int j = 0; j < 3; j++){
				int c[] = {b[0], b[1]};
				t[1] = b[j];
				c[j] = b[2];
				for(int k = 0; k < 2; k++){
					t[2] = c[k];
					t[3] = c[(1 + k) % 2];
					if(dicision(t[0], t[1], t[2], t[3])){
						i += 4;
						j += 4;
						k += 4;
					}
					if(!((i -3) + (j - 2) + (k - 1))){
						printf("0\n");
					}
				}
			}
		}
		scanf("%d %d %d %d", &a[0],&a[1],&a[2],&a[3]);
	}
}

Measured memory_bytes: 1040
/*
 *  author : Atul Anand   
 *  created on : Fri Apr 03 2020
 */

import java.io.*;
import java.util.*;

public class Main{

    public static void main(String[] args) throws IOException {
        int N = in.nextInt();
        int p[] = new int[N];
        int mismatch = 0;
        for(int i = 0; i < N; i++){
            p[i] = in.nextInt() - 1;
            if(p[i] != i){
                mismatch++;
            }
        }
        if(mismatch <= 2){
            println("YES");
        }
        else{
            println("NO");
        }
        in.close();
        out.close();
    }

    static int MIN = Integer.MIN_VALUE;
    static int MAX = Integer.MAX_VALUE;
    static Reader in = new Reader();
    static PrintWriter out = new PrintWriter(System.out);

    static void read(int arr[], int N) throws IOException { 
    	for(int i = 0; i < N; i++){ 
    		arr[i] = in.nextInt(); 
    	} 
    }
    
    static void read(long arr[], int N) throws IOException { 
    	for(int i = 0; i < N; i++){ 
    		arr[i] = in.nextLong(); 
    	} 
    }
    
    static void read(String arr[], int N) throws IOException { 
    	for(int i = 0; i < N; i++){ 
    		arr[i] = in.next(); 
    	} 
    }
    
    static void print(Object O) {  
    	out.print(O); 
    }
    
    static void println(Object O) { 
    	out.println(O); 
    }
    
    static void println(int arr[]) { 
    	for(int i = 0; i < arr.length; i++){ 
    		print(arr[i]+" "); 
    	} 
    	println(""); 
    }

    static void println(int arr[][]) { 
    	for(int i = 0; i < arr.length; i++){ 
    		println(arr[i]); 
    	}
    }
    
    static void debug(Object O) { 
    	System.out.println(O); 
    }
}

class Reader {
    BufferedReader reader;
    StringTokenizer tokenizer;

    Reader() {
        reader = new BufferedReader(new InputStreamReader(System.in));
        tokenizer = new StringTokenizer("");
    }

    String next() throws IOException {
        while (!tokenizer.hasMoreTokens() ) { 
            tokenizer = new StringTokenizer(reader.readLine()); 
        }
        return tokenizer.nextToken();
    }

    int nextInt() throws IOException { 
        return Integer.parseInt(next()); 
    }
    
    double nextDouble() throws IOException { 
        return Double.parseDouble(next());
    }
    
    long nextLong() throws IOException { 
        return Long.parseLong(next()); 
    }
    
    String nextLine() throws IOException { 
        return reader.readLine(); 
    }
    
    void close() throws IOException { 
        reader.close(); 
    }
}

Measured memory_bytes: 21332
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);++i)
#define ALL(v)   (v).begin(),(v).end()
#define debug(x) cerr<<#x<<": "<<(x)<<endl
#define INF      (int)1e9
#define EPS      (double)1e-9
#define MOD      ((int)1e9+7)
using namespace std;
typedef long long     llong;
typedef vector<int>   vi;
typedef vector<vi >   vvi;
typedef vector<vvi >  vvvi;
typedef pair<int,int> pii;
template<class Type> void line(const Type &a){int cnt=0;for(const auto &elem:a){if(cnt++)cout<<' ';cout<<elem;}cout<<endl;}

int main(){
	int k,n;
	cin>>k>>n;
	
	vi a(n);
	REP(i,n) cin>>a[i];
	
	int ma=a[0]+(k-a[n-1]);
	REP(i,n-1) ma=max(ma,a[i+1]-a[i]);
	
	cout<<k-ma<<endl;
}

Measured memory_bytes: 1024
#include <algorithm>
#include <iostream>
#include <string>
#include <cstring>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iomanip>
#include <limits>
#include <map>
#include <queue>
#include <stack>
#include <vector>

#define FOR(i,k,n) for(int (i) = (k); (i) < (n); ++(i))
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define all(v) begin(v), end(v)
#define debug(x) cerr << #x << ": " << x << endl
#define debug2(x,y) cerr << #x << ": " << x << ", " << #y << ": " << y << endl

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<i_i, int> p_i;
typedef vector<int> vi;
typedef vector< vector<int> > vvi;
template<class T> using vv=vector< vector<T> >;
typedef deque<int> di;
typedef deque< deque<int> > ddi;

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

int c[55][55] = {};

void dfs(i_i p) {
    c[p.first][p.second] = 0;
    rep(i,3) {
        rep(j,3) {
            if(c[p.first+dx[i]][p.second+dy[j]] == 1) {
                dfs(make_pair(p.first+dx[i], p.second+dy[j]));
            }
        }
    }
}

int main() {
    int w,h;
    while(cin >> w >> h,w) {
        memset(c,0,sizeof(c));
        FOR(i,1,h+1) {
            FOR(j,1,w+1) {
                cin >> c[i][j];
            }
        }
        int sum = 0;
        FOR(i,1,h+1) {
            FOR(j,1,w+1) {
                if(c[i][j] == 1) {
                    dfs(make_pair(i,j));
                    sum += 1;
                }
            }
        }
        cout << sum << endl;
    }
	return 0;
}

Measured memory_bytes: 3208
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define pb push_back
using namespace std;
using ll = long long;
const char E = '\n';
const int N = 3005;

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	string s, t;
	pair <int, pair <int, int> > dp[N][N];
	cin >> s >> t;
	s = '#' + s;
	t = '#' + t;
	for (int i=1; i<=s.size()-1; i++) {
        for (int j=1; j<=t.size()-1; j++) {
            if (s[i] == t[j]) dp[i][j] = {dp[i-1][j-1].first + 1, {i-1, j-1}};
            else {
                if (dp[i][j-1].first >= dp[i-1][j].first) dp[i][j] = {dp[i][j-1].first, {i, j-1}};
                else dp[i][j] = {dp[i-1][j].first, {i-1, j}};
            }
        }
	}
	vector <char> ans;
	pair <int, int> in = {s.size()-1, t.size()-1};
	while (in.first > 0 && in.second > 0)
    {
        if (s[in.first] == t[in.second]) {
            ans.pb (s[in.first]);
        }
        in = dp[in.first][in.second].second;
    }
    reverse (ans.begin(), ans.end());
    for (auto i:ans) {
        cout << i;
    }
    return 0;
}


Measured memory_bytes: 106112
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep_inv(i, n, m) for(int i = (int)(n); i > (int)(m); i--)
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vc = vector<char>;
using vvl = vector<vl>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;

int main(){
  string A, B, C;
  cin >> A >> B >> C;

  if((A[A.size() - 1] == B[0]) && (B[B.size() - 1] == C[0]))
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
  
  return 0;
}


Measured memory_bytes: 256
z[4000],*a=z,*b=z+2000,m,i,j;main(n){for(;scanf("%d",&n),n;m=!printf("%d\n",m))for(i=++n;i--;j=a,a=b,b=j)for(j=n;j--;)m=fmax(m,b[j]=n+~i&&getchar()>45?1+fmin(fmin(b[j+1],a[j+1]),a[j]):0);exit(0);}

Measured memory_bytes: 420
import sys
def input():
    return sys.stdin.readline()[:-1]

H = int(input())
A = list(map(int, input().split()))

def maxHeapify(A, i):
    c = i
    l = 2*(i+1)-1 if 2*(i+1)<=H  else H+1
    r = 2*(i+1)+1-1 if 2*(i+1)+1<=H else H+1 

    # select maximum node from left, me, right
    if (l<=H) and (A[l]>A[c]):
        largest = l
    else:
        largest = c
    if (r<=H) and (A[r]>A[largest]):
        largest = r
        
    if largest!=c:
        A[c],A[largest] = A[largest],A[c]
        if 2*(largest+1)<=H:
            maxHeapify(A, largest)
    return A

def buildMaxHeap(A):
    for i in range(H//2-1, -1, -1):
        A = maxHeapify(A,i)
        
buildMaxHeap(A)
print(' '+' '.join([str(a) for a in A]))


Measured memory_bytes: 63992
A, B = map(int, input().split())

check = False
for i in range(1, 10000):
    a_check = A <= i * 0.08 and i * 0.08 < (A+1)
    b_check = B <= i * 0.1 and i * 0.1 < (B+1)
    if a_check and b_check:
        print(i)
        check = True
        break

if check == False:
    print(-1)


Measured memory_bytes: 2940
#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 MSVC_UNKO(x) x
#define rep(...) MSVC_UNKO(_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; template<class T>using vv = vector<vector<T>>;
template<class T>auto vvec(int n, int m, T v) { return vv<T>(n, vector<T>(m, v)); }
template<class T, class U>bool chmax(T& a, U&& b) { return a < b ? a = b, 1 : 0; }
template<class T, class U>bool chmin(T& a, U&& b) { return b < a ? a = b, 1 : 0; }
constexpr int INF = 1 << 29, MOD = int(1e9) + 7; constexpr ll LINF = 1LL << 60;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); }; }aaaa;

int N, M;
vector<vector<int>> graph, igraph;
vector<int> vs, cmp;
vector<bool> visited;

void dfs(int v) {
    visited[v] = true;
    for (int u : graph[v]) {
        if (!visited[u]) dfs(u);
    }
    vs.push_back(v);
}
void rdfs(int v, int k) {
    visited[v] = true;
    cmp[v] = k;
    for (int u : igraph[v]) {
        if (!visited[u]) rdfs(u, k);
    }
}

void sccd() {
    cmp.resize(N);
    visited.assign(N, false);
    for (int v = 0; v < N; ++v) {
        if (!visited[v]) dfs(v);
    }
    visited.assign(N, false);
    int k = 0;
    for (int i = (int)vs.size() - 1; i >= 0; --i) {
        if (!visited[vs[i]]) rdfs(vs[i], k++);
    }
}

int main() {
    cin >> N >> M;
    graph.resize(N);
    igraph.resize(N);
    rep(i, M) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        graph[a].push_back(b);
        igraph[b].push_back(a);
    }

    sccd();

    vector<int> tmp;
    rep(i, N) {
        tmp.resize(0);
        rep(j, N) {
            if (cmp[j] == cmp[i]) tmp.push_back(j + 1);
        }
        rep(j, tmp.size()) {
            cout << tmp[j] << (j == tmp.size() - 1 ? '\n' : ' ');
        }
    }
}


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using pi = pair<int, int>;
const ll INF = 1LL << 60;


int main() {
    string s;
    int mins = 10000000;
    cin >> s;
    int len = s.size();
    rep(i, len - 2) {
        mins = min(mins, abs(753 - stoi(s.substr(i, 3))));
    }
    cout << mins << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>

using namespace std ;

struct students
{
	int num[ 200000 ] ;
} ;

int main()
{
	students prev ,next ;
	int n ,m ,q ;
	int o ,p = 0 ;
	
	cin >> n >> m >> q ;
	
	for( int i = 0 ; i < n ; i++ )
	{
		prev.num[ i ] = ( i - 1 + n ) % n ;
		next.num[ i ] = ( i + 1 ) % n ;
	}
	
	for( int i = 0 ; i < m ; i++ )
	{
		cin >> n ;
		
		for( int j = 0 ; j < n ; j++ )
		{
			p = n % 2 > 0 ? prev.num[ p ] : next.num[ p ] ;
		}
		
		o = p ;
		next.num[ prev.num[ p ] ] = next.num[ p ] ;
		prev.num[ next.num[ p ] ] = prev.num[ p ] ;
		p = next.num[ p ] ;
		next.num[ o ] = -1 ;
		prev.num[ o ] = -1 ;
		
	}
	
	for( int i = 0 ; i < q ; i++ )
	{
		cin >> m ;
		cout << ( prev.num[ m ] < 0 ? 0 : 1 ) << endl ;
	}
	
	return 0 ;
}

Measured memory_bytes: 4592
local mmi, mma = math.min, math.max
local mod = 1000000007
local mfl = math.floor

local function badd(x, y)
  return (x + y) % mod
end
local function bmul(x, y)
  return (x * y) % mod
end
local function bsub(x, y)
  return x < y and x - y + mod or x - y
end

local function modpow(src, pow)
  local res = 1
  while 0 < pow do
    if pow % 2 == 1 then
      res = bmul(res, src)
      pow = pow - 1
    end
    src = bmul(src, src)
    pow = mfl(pow / 2)
  end
  return res
end

local function modinv(src)
  return modpow(src, mod - 2)
end

local function getComb(n, k)
  local ret = 1
  local inv = 1
  for i = 1, k do
    ret = bmul(ret, n + 1 - i)
    inv = bmul(inv, i)
  end
  return bmul(ret, modinv(inv))
end

local n, a, b = io.read("*n", "*n", "*n")

local ret = modpow(2, n) - 1
ret = bsub(ret, getComb(n, a))
ret = bsub(ret, getComb(n, b))
print(ret)


Measured memory_bytes: 888
from collections import deque
import sys

h, w = [int(_) for _ in input().split()]
s = []
M = -1
for i in range(h):
    s.append(input())
for i in range(h):
    for j in range(w):
        if s[i][j] == '#':
            continue
        dp = [[-1 for _ in range(w)] for i in range(h)]
        dp[i][j] = 0
        que = deque([(i, j)])
        # c = 0
        while len(que) != 0:
            i_f, j_f = que.popleft()
            # print(que)
            d_f = dp[i_f][j_f]
            l = [(i_f, j_f + 1),(i_f, j_f - 1), (i_f - 1, j_f), (i_f + 1, j_f)]
            for p in range(len(l)):
                i_t, j_t = l[p]
                if 0 <= i_t <= h - 1 and 0 <= j_t <= w - 1:
                    # print(i_t, j_t)
                    # print(dp)
                    # print(s)
                    # print(dp[0][1])
                    # print(s[0][1])
                    if dp[i_t][j_t] == -1 and s[i_t][j_t] == '.':
                        que.append((i_t, j_t))
                        dp[i_t][j_t] = d_f + 1
            # c += 1
            # print(que)
            # print(dp)
            # print(l)
            # if c == 2:
            #     sys.exit()
        # print('**********')
        # print(i, j)
        # for i in range(h):
        #     print(dp[i])
        # print('**********')
        for i_q in range(h):
            for j_q in range(w):
                M = max(dp[i_q][j_q], M)
print(M)


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

int main()
{
  int group[] = {1, 3, 1, 2, 1, 2, 1, 1, 2, 1, 2, 1};
  int x, y;
  cin >> x >> y;
  cout << ((group[x - 1] == group[y - 1]) ? "Yes" : "No");
  return 0;
}


Measured memory_bytes: 256
import math
a,b,h,m = map(int,input().split())
num1 = m * 6
num2 = h * 30 + m * 0.5
if num1 >= num2:
  sita = num1 - num2
else:
  sita = num2 - num1
c2 = a**2 + b**2 - 2*a*b*math.cos(math.radians(sita))
c = math.sqrt(c2)
print(c)


Measured memory_bytes: 9500
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<cstring>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<string>
#include<cmath>
using namespace std;
typedef long long ll;
const int maxn = 5e5 + 5;
const int inf = 0x3f3f3f3f;
int main() {
    string s;
    cin>>s;
    map<char,int> mp;
    for(auto it:s)
    mp[it]++;
    for(auto it:mp)
    {
        if(it.second%2!=0)
        {
            cout<<"No";
            return 0;
        }
    }
    cout<<"Yes\n";
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MM 1000000000
#define MOD MM+7
#define MAX 101000
#define MAP 110
#define initial_value -1
#define Pair pair<int,int>
#define lPair pair<ll,ll>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
int dx[4] = {-1,0,1,0};
int dy[4] = {0,-1,0,1};
int C[200200];
int pre[200200];
ll dp[200200];
int main(){
    int N; cin >> N;
    for(int i = 1; i <= N; i++) cin >> C[i];
    dp[0] = 1;
    for(int i = 1; i <= N; i++){
        dp[i] = dp[i-1];
        int cur = C[i];
        if(pre[cur] && pre[cur] != i-1){
            dp[i] += dp[pre[cur]];
            dp[i] %= MOD;
        }
        pre[cur] = i;
    }
    cout << dp[N] << endl;
    return 0;
}


Measured memory_bytes: 3328
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
//#include <regex>

/* g++ -g -std=c++0x */
/* g++ -g -std=c++11 */

using namespace std;

// freopen("input.txt", "rt", stdin);
// freopen("output.txt", "wt", stdout);

#define ALL(c)          (c).begin(), (c).end()
#define ALLR(c)         (c).rbegin(), (c).rend()
#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 FOR_ALL(i,c)    for (__typeof((c).begin()) i=(c).begin();   \
                             i != (c).end(); ++i)
#define FOR_ALLR(i,c)   for (__typeof((c).rbegin()) i=(c).rbegin(); \
                             i != (c).rend(); ++i)
#define SZ(array)       (sizeof(array)/sizeof(array[0]))
#define lc(x)           (x<<1)     /* 2*x */
#define rc(x)           (x<<1 | 1) /* 2*x+1 */
#define lowbit(x)       (x & (-x)) /* 0b10100 -> 0b100 */

typedef long long       LL;
typedef map<int,int>    MII;
typedef pair<int,int>   PII;
typedef set<int>        SI;
typedef vector<bool>    VB;
typedef vector<double>  VD;
typedef vector<int>     VI;
typedef vector<string>  VS;

/* check if a key is in container C */
template <class C>
inline bool in_(const typename C::key_type& k, const C& A)
{ return A.find(k) != A.end(); }
inline bool in_(const string& s, const string& S)
{ return S.find(s) != string::npos; }

int main()
{
/* #ifndef ONLINE_JUDGE */
/*     freopen("foo", "rt", stdin); */
/* #endif */
    std::ios::sync_with_stdio(false);

    int N;
    cin >> N;
    if (N % 2 == 0)
        cout << N << endl;
    else
        cout << 2*N << endl;
    
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
    int n, res = 0;
    n = 5;
    int a[n+2];
    for(int i = 1; i <= n; i++)
    {
        cin>>a[i];
        if(!a[i])res = i;
    }
    cout<<res<<endl;
}


Measured memory_bytes: 3572
#include<cstdio>

using namespace std;

int n,ms[15][15];

void solve(int x,int y,int i)
{
	if(i>n*n)	return;
	if(n<=x)		solve(0,y,i);
	else if(x<0)	solve(n-1,y,i);
	else if(n<=y)	solve(x,0,i);
	else if(ms[y][x]!=0)	solve(x-1,y+1,i);
	else		ms[y][x]=i,	solve(x+1,y+1,i+1);
}

int main()
{
	for(;scanf("%d",&n),n;){
		for(int i=0;i<n;i++)for(int j=0;j<n;j++)ms[i][j]=0;
		solve(n/2,n/2+1,1);
		for(int i=0;i<n;i++){
			for(int j=0;j<n;j++)printf("%4d",ms[i][j]);
			puts("");
		}
	}
	return 0;
}

Measured memory_bytes: 0
import numpy
N,M,X = map(int,input().split())
A = numpy.array([[int(i) for i in input().split()] for _ in range(N)])
ans = 10**8
for i in range(2**N) :
    i = format(i,'b').zfill(N)
    check = numpy.array([0]*(M+1))
    for j in range(N) :
        if i[j] == '0' :
            continue
        check +=  A[j][0:]
    if all (check[m] >= X for m in range(1,M+1)) :
        ans = min(ans,check[0])

if ans == 10**8 :
    print(-1)
else :
    print(ans)

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

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

  vector<int> A(M);

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

  int left = 0;
  int right = 0;
  for(int i=0; i<M; i++){
    if(A.at(i) < X) left++;
    if(X < A.at(i)) right++; 
  }

  cout << min(left, right) << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	int a,b,c,d,e,f;
	scanf("%d %d %d",&a,&b,&c);
	d=a+b;
	e=a+c;
	f=b+c;
	
	if(d<=e && d<=f)
	{
		printf("%d\n",d);
	}
	else if(e<=d && e<=f)
	{
		printf("%d\n",e);
	}
	else if(f<=e && f<=d)
	{
		printf("%d\n",f);
	}
}

Measured memory_bytes: 128
#include <iostream>
#include <stdio.h>
#include <string.h>
#define LEN 100005

struct Process{
	char name[100];
	int t;
};

Process Q[LEN];
int head,tail,n;

void enqueue(Process x){
	Q[tail] = x;
	tail = (tail+1) % LEN;
}
Process deque(){
	Process x = Q[head];
	head = (head + 1) % LEN;
	return x;
}

int min(int a,int b){
	return  a < b ? a : b;
}
int main(){
	int elaps = 0;
	int i,q;
	int c;
	Process u;
	scanf("%d %d",&n,&q);
	for( i = 1;i <= n;i++){
		scanf("%s",Q[i].name);
		scanf("%d",&Q[i].t);
	}
	head = 1;tail = n+1;
	while( head != tail){
		u = deque();
		c = min(q,u.t);
		u.t -=c;
		elaps += c;
		if(u.t > 0) enqueue(u);
		else{
			printf("%s %d\n",u.name,elaps);
		}
	}
	

	return 0;
}

Measured memory_bytes: 13360
#include <iostream>
#include <vector>
#include <algorithm>
#define ll long long
using namespace std;
int main(){
    int n;
    cin>>n;
    vector<string> s(n);
    vector<int> p(n);
    for(int i=0;i<n;i++){
        cin>>s[i]>>p[i];
    }
    vector<string> s_buffer;
    for(int i=0;i<n;i++){
        if(s_buffer.end()==find(s_buffer.begin(),s_buffer.end(),s[i])){
            s_buffer.push_back(s[i]);
        }
    }
    sort(s_buffer.begin(),s_buffer.end());
    vector<int> p_b;

    for(int i=0;i<s_buffer.size();i++){
        for(int j=0;j<n;j++){
            if(s_buffer[i]==s[j]){
                p_b.push_back(p[j]);
            }
        }
        sort(p_b.begin(),p_b.end());
        reverse(p_b.begin(),p_b.end());
        for(int j=0;j<p_b.size();j++){
            int ite=distance(p.begin(),find(p.begin(),p.end(),p_b[j]));
            cout<<ite+1<<endl;
        }
        p_b.clear();
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
int main(void){
  int n,m,i,j,a,b;
  unsigned long long ans=0;
  cin >> n >> m;
  vector<P> ab;
  for (i=0;i<n;i++){
    cin >> a >> b;
    ab.push_back(P(a,b));
  }
  sort(ab.begin(),ab.end());
  i=0;
  while (1){
    a=ab.at(i).first;
    b=ab.at(i).second;
    if (m>b){
      ans+=(long long)a*b;
      m-=b;
      i++;
    }else{
      ans+=(long long)m*a;
      break;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1400
#include <iostream>
#include <stdio.h>

using namespace std;

int main() {

  int n=0, p=0;
  char d;
  int card[4][13]={0};
  char q[4]={'S', 'H', 'C', 'D'};

  cin >> n;

  for(int i=0; i<n; i++) {

    cin >> d >> p;

    if(d=='S') {

      card[0][p-1]=1;

    } else if(d=='H') {

      card[1][p-1]=1;

    } else if(d=='C') {

      card[2][p-1]=1;

    } else {

      card[3][p-1]=1;
      
    }
    
  }

  for(int i=0; i<4; i++) {

    for(int j=0; j<13; j++) {

      if(card[i][j]==0) {

        cout << q[i] << ' ' << j+1 << endl;
        
      }
      
    }
    
  }
    
  return 0;
  
}


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

typedef long long                   ll;
typedef pair<int,int>               pii;
typedef pair<ll,ll>                 pll;
typedef pair<string , string>       pss;

#define all(x)                      (x).begin(),(x).end()
#define Sort(x)                     sort(all((x)))
#define F                           first
#define S                           second
#define sep                         ' '
#define file_io                     freopen("input.txt" , "r+" , stdin) ; freopen("output.txt" , "w+" , stdout);
#define fast_io                     ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define error(x)                    cerr << "$$$ " << x << '\n';
#define error2(x,y)                 cerr << "#F : " << x << "      #S : " << y << '\n';
#define pb                          push_back

const ll MX5 = 1*1e5+3;
const ll MX6 = 2*1e6+3;
const ll INF = 8e18;
const ll MOD = 1e9 + 7;
const ll MOD2= 998244353;

ll power(ll a, ll b, ll md) {
    return (!b ? 1 : (b & 1 ? a * power(a * a % md, b / 2, md) % md : power(a * a % md, b / 2, md) % md));
}
ll bmm(ll a,ll b){
    return (a%b==0 ? b : bmm(b,a%b));
}

ll A[103],W[103];
ll dp[103][MX5];
int main(){
    fast_io
    //file_io
    ll n,w,ans=0;
    cin >> n >> w;
    for(int i=1;i<=n;i++){
        cin >> W[i] >> A[i];
    }
    for(int i=1;i<=n;i++){
        for(int j=1;j<=w;j++){
            dp[i][j]=max(dp[i][j],dp[i-1][j]);
            if(j>=W[i]){
                dp[i][j]=max(dp[i][j],dp[i-1][j-W[i]]+A[i]);
            }
            ans=max(ans,dp[i][j]);
        }
    }
    /*
    for(int j=1;j<=w;j++){
        for(int i=1;i<=n;i++){
            cerr << dp[i][j] << sep;
        }
        cerr << endl;
    }*/
    cout << ans;
    return 0;
}


Measured memory_bytes: 79360
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let d :i64 = read();
    let t :i64 = read();
    let s :i64 = read();
    let mut ans = "No";
    if d <= t * s {
        ans = "Yes";
    }
    print!("{}", ans);
}


Measured memory_bytes: 2076
#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <numeric>
#include <algorithm>

using namespace std;
using lint = long long;
constexpr int MOD = 1000000007, INF = 1010101010;
constexpr lint LINF = 1LL << 60;

template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
	for (const auto &e : vec) os << e << (&e == &vec.back() ? "\n" : " ");
	return os;
}

#ifdef _DEBUG
template <class T>
void dump(const char* str, T &&h) { cerr << str << " = " << h << "\n"; };
template <class Head, class... Tail>
void dump(const char* str, Head &&h, Tail &&... t) {
	while (*str != ',') cerr << *str++; cerr << " = " << h << "\n";
	dump(str + (*(str + 1) == ' ' ? 2 : 1), t...);
}
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

template<class T>
inline bool chmax(T &a, const T b) { return a < b && (a = b, true); }
template<class T>
inline bool chmin(T &a, const T b) { return a > b && (a = b, true); }

int naive(const vector<pair<int, int>> &AB, const int T) {

	int res = 0;
	for (int bit = 0; bit < (1 << AB.size()); bit++) {

		int last = 0, sum = 0, time = 0;
		for (int i = 0; i < AB.size(); i++) {

			if (bit & (1 << i)) {
				int tmp = last;
				if (chmax(last, AB[i].first)) time += tmp;
				else time += AB[i].first;
				sum += AB[i].second;
			}
			if (time >= T) break;
		}

		if (time < T) if(chmax(res, sum)) DMP(bit);

	}

	return res;

}

template<class T>
vector<T> make_vec(size_t s, T val) { return vector<T>(s, val); }
template<class... Size>
auto make_vec(size_t s, Size... tail) {
	return vector<decltype(make_vec(tail...))>(s, make_vec(tail...));
}

int main() {

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

	int N, T;
	cin >> N >> T;

	vector<pair<int, int>> AB(N);
	for (int i = 0; i < N; i++) cin >> AB[i].first >> AB[i].second;
	sort(AB.begin(), AB.end());
	
	auto dp = make_vec(N + 1, T + 1, 0);
	for (int i = 1; i <= N; i++) {
		dp[i] = dp[i - 1];
		for (int j = 0; j < T; j++) {
			chmax(dp[i][min(j + AB[i - 1].first, T)], dp[i - 1][j] + AB[i - 1].second);
		}
	}
	
	cout << dp[N][T] << "\n";
	DMP(naive(AB, T));

	return 0;
}


Measured memory_bytes: 35584
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
  std::vector< pair<int,int> > a;
  int N,h,m,M;
  pair<int,int> time;

  cin >> N;
  for(int i = 0; i < N ;i++){
    cin >> h >> m;
    time.first = h;
    time.second = m;
    a.push_back(time);
  } 
  cin >> M;
  for(int i = 0; i < M ;i++){
    cin >> h >> m;
    time.first = h;
    time.second = m;
    a.push_back(time);
  }
  std::sort(a.begin(),a.end());//テヲツ伉?ゥツ??」ツつステ」ツδシテ」ツδ?

  cout << a[0].first << ":";
     if( a[0].second < 10 ){ cout << "0";}
    cout << a[0].second;

  for(int i = 1 ; i < a.size() ; i++){
    if(a[i].second == a[i-1].second && a[i].first == a[i-1].first ) continue;

    cout << " " << a[i].first << ":";
     if( a[i].second < 10 ){ cout << "0";}
    cout << a[i].second;

  }	
  cout << endl;

  return 0;
}

Measured memory_bytes: 1208