akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
using namespace std;
//________
#define pb        emplace_back
#define fi        first
#define se        second
#define ALL(x)    x.begin(),x.end()
#define err(...)  fprintf(stderr, __VA_ARGS__ )
#define show(x)   cerr << #x << ':' << (x) << endl
#define outl(x)   cout << (x) << '\n'
#define FAST()    cin.tie(0), ios::sync_with_stdio(false)
#define rep(i,n)     for(int i=0; i<(n); ++i)
#define reps(i,f,n)  for(int i=(f); i<=(n); ++i)
template<class A, class B>inline bool chmax(A &a, B b){return b>a ? a=b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, B b){return b<a ? a=b,1 : 0;}
inline bool inside(int y, int x, int H, int W){return(y>=0 && x>=0 && y<H && x<W);}
constexpr int dx[] = {1, 0, -1, 0,  1, 1, -1, -1};
constexpr int dy[] = {0, 1, 0, -1,  -1, 1, 1, -1};
typedef long long ll;
typedef pair<int,int> pii;
#define let const auto
#define INF  0x3f3f3f3f
#define LINF 0x3f3f3f3f3f3f3f3f
#define NIL -1
//________


signed main()
{
   FAST();
   int N, M;
   map<string, int> a, b;

   cin >> N;
   rep(i, N) {
      string s;
      cin >> s;
      a[s]++;
   }

   cin >> M;
   rep(i, M) {
      string t;
      cin >> t;
      a[t]--;
   }

   int maxv = 0;
   for (auto it=a.begin(); it != a.end(); it++){
      maxv = max(it->second, maxv);
   }
   outl(maxv);
}



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

int main()
{
    int m, f, r;
    string ans;
    while (1) {
        cin >> m >> f >> r;
        if (m == -1 && f == -1 && r == -1) break;

        if (m == -1 || f == -1) {
            ans = "F";
        }
        else if (m + f >= 80) {
            ans = "A";
        }
        else if (m + f >= 65) {
            ans = "B";
        }
        else if (m + f >= 50) {
            ans = "C";
        }
        else if (m + f >= 30) {
            if (r >= 50) {
                ans = "C";
            }
            else {
                ans = "D";
            }
        }
        else {
            ans = "F";
        }

        cout << ans << endl;
    }
}


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

#define ll              long long
#define Ull             unsigned long long
#define pb              push_back
#define INF             2e16
#define PI              acos(-1.0)
#define mk              make_pair
#define pii             pair<int,int>
#define pll             pair<ll,ll>
#define min3(a,b,c)     min(a,min(b,c))
#define max3(a,b,c)     max(a,max(b,c))
#define min4(a,b,c,d)   min(a,min(b,min(c,d)))
#define max4(a,b,c,d)   max(a,max(b,max(c,d)))
#define SQR(a)          ((a)*(a))
#define MEM(a,x)        memset(a,x,sizeof(a))
#define ABS(x)          ((x)<0?-(x):(x))

#define SORT(v)         sort(v.begin(),v.end())
#define REV(v)          reverse(v.begin(),v.end())
#define FastRead        ios_base::sync_with_stdio(0);cin.tie(nullptr);

const int N = 2;
const ll MOD = 1e9 + 7;


void Solve()
{
	string s1, s2;
	cin >> s1 >> s2;
	ll n = s1.length();
	ll m = s2.length();
	ll dp[n + 1][m + 1];
	for (ll i = 0; i <= n; i++)
		dp[i][0] = 0;

	for (ll i = 0; i <= m; i++)
		dp[0][i] = 0;

	for (ll i = 1; i <= n; i++)
	{
		for (ll j = 1; j <= m; j++)
		{
			if (s1[i - 1] == s2[j - 1])
				dp[i][j] = 1 + dp[i - 1][j - 1];

			else
				dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
		}
	}
	string ans = "";
	ll i = n, j = m;
	while (i > 0 && j > 0)
	{
		if (dp[i][j] != dp[i - 1][j] && dp[i][j] != dp[i][j - 1])
		{
			ans += s1[i - 1];
			i -= 1;
			j -= 1;
		}
		else if (dp[i][j] == dp[i - 1][j])
			i -= 1;

		else if (dp[i][j] == dp[i][j - 1])
			j -= 1;

	}
	reverse(ans.begin(), ans.end());
	cout << ans << "\n";


}


int main()
{

	FastRead;
	int T = 1;
	//cin>>T;
	while (T--)
	{
		Solve();
	}

	return 0;
}


Measured memory_bytes: 70656
#include<bits/stdc++.h>
using namespace std;
const long long int INF = 1e18L + 5;
int main(){
    int n,W,sum=0;
    cin>>n>>W;
    int wt[n];
    int val[n];
    for(int i=0;i<n;i++){
        cin>>wt[i]>>val[i];
        sum += val[i];
    }
    int N = sum + 1;
    vector<long long int> dp(N,INF);
    dp[0]=0;
    for(int i=0;i<n;i++){
        for(int j = sum;j>=val[i];j--){
            dp[j] = min(dp[j],wt[i]+dp[j-val[i]]);
        }
    }
//    for(int i=9;i<20;i++){
//        cout<<dp[i]<<" ";
//    }
//    cout<<endl;
    int ans = 0;
    for(int i=0;i<=sum;i++){
        if(dp[i]<=W){
            ans = max(ans,i);
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define max1(a,b) a > b ? a : b;
using namespace std;
typedef long long ll;
ll a, b, n;
int main()
{
	ios::sync_with_stdio(false);
	cin >> a >> b >> n;
	ll jieguo=0;
	if (n < b)
		jieguo = (ll)a * n / b;
	else  if (n == b)
		jieguo = (ll)a * (n - 1) / b;
	else jieguo = (ll)a * (b-1)/ b;
	cout << jieguo;
	return 0;
}

Measured memory_bytes: 3652
from collections import deque
n = int(input())
ls = [list(input()) for i in range(n)]
graph = [[] for i in range(n+1)]
visited = [0 for i in range(n+1)]
parity = [-1 for i in range(n+1)]
dist = [0 for i in range(n+1)]
for i in range(n):
  for j in range(i,n):
    if ls[i][j] == "1":
      graph[i+1].append(j+1)
      graph[j+1].append(i+1)
que = deque([(1,0)])
parity[1] = 0
visited[1] = 1
while que:
  x,cnt = que.popleft()
  dist[x] = cnt
  for y in graph[x]:
    if visited[y] == 0:
      que.append((y,cnt+1))
      visited[y] = 1
      parity[y] = 1-parity[x]
# k = max(dist)
# farls = []
# for i in range(1,n+1):
#   if dist[i] == k:
#     farls.append(i)
ans = []
for far in range(1,n+1):
  que.append((far,0))
  visited = [0 for i in range(n+1)]
  visited[far] = 1
  dist = [0 for i in range(n+1)]
  while que:
    x,cnt = que.popleft()
    dist[x] = cnt
    for y in graph[x]:
      if visited[y] == 0:
        que.append((y,cnt+1))
        visited[y] = 1
      if parity[y] == parity[x]:
        print(-1)
        exit()
  ans.append(max(dist))
print(max(ans)+1)

Measured memory_bytes: 4084
IDENTIFICATION DIVISION.
      PROGRAM-ID. 156B.
      DATA DIVISION.
      WORKING-STORAGE SECTION.
      01 INP PIC X(100).
      01 N PIC 9(10).
      01 K PIC 9(2).
      01 SHO  PIC 9(9).
      01 AMA  PIC 9(2).
      01 CNT  PIC 9(9).
      01 CNTX PIC ZZZZZZZZ9.
      PROCEDURE DIVISION.
      ACCEPT INP.
      UNSTRING INP DELIMITED BY " "
      INTO N K.
            
      MOVE 1 TO CNT.
      PERFORM UNTIL N < K
      DIVIDE K BY N GIVING SHO REMAINDER AMA
      COMPUTE SHO = N / K
      MOVE SHO TO N
      ADD 1 TO CNT
      END-PERFORM.
      
      MOVE CNT TO CNTX.
      DISPLAY FUNCTION TRIM(CNTX).
      
      STOP RUN.
      


Measured memory_bytes: 384
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#define dlog(str) cout << "====" << str << endl;
#else
#define dlog(str)
#endif
#define INF 999999999
#define MOD 1000000007
#define REP(i, n) for(int i = 0, i##_l = (n); i < i##_l; i++)
#define FOR(i, s, e) for(int i = s, i##_l = (e); i < i##_l; i++)
#define LLI long long int
#define _min(a,b) ((a<b)?a:b)
#define _max(a,b) ((a<b)?b:a)
#define chmax(a, b) a = _max(a, b)
#define chmin(a, b) a = _min(a, b)
#define bit(a, shift) ((a>>shift)&1))
#define pm(a) ((a)?1:-1)
#define SORT(v) sort(v.begin(),v.end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
// int 2.14E±9    lli 9.2E±18    double 1.7E±380


struct Node
{
	int h;
	int m = 0;
	vector<int> to;
};

int main()
{
	cout << fixed << setprecision(10);

	int n, m;
	cin >> n >> m;
	vector<Node> v(n);

	REP(i, n)
	{
		cin >> v[i].h;
	}

	REP(i, m)
	{
		int a, b;
		cin >> a >> b;
		a--;
		b--;

		chmax(v[a].m, v[b].h);
		chmax(v[b].m, v[a].h);
	}

	int ans = 0;

	REP(i, n)
	{
		if (v[i].m < v[i].h)
		{
			ans++;
		}
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 6428
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <stack>
#include <cctype>
#include <complex>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <cassert>

using namespace std;


bool solve(){
	while(1){
		int n,p;
		cin>> n>> p;
		if(n==0 && p==0) break;
		
		vector<int> a(n,0);
		int k=0;
		while(1){
			if(p){
				a[k]++;
				p--;
				if(p==0){
					int flag=1;
					for(int i=0;i<n;i++){
						if(i==k) continue;
						if(a[i]){
							flag=0;
							break;
						}
					}
					if(flag) break;
				}
			}else{
				p += a[k];
				a[k]=0;
			}
			k++;
			k %= n;
		}
		cout<< k<< endl;
	}
	
	return true;
}

int main(){
	cout.setf(ios::fixed);
	cout.precision(10);
	solve();

	return 0;
}

 

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

ans = 0
pre = -1

for i in A:
  ans += B[i-1]
  if (i == pre + 1):
    ans += C[i-2]
  pre = i

print(ans)

Measured memory_bytes: 3060
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author tatsumack
 */

#include <iostream>
#include <fstream>

#include <iostream>
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>

#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <queue>
#include <unordered_map>
#include <unordered_set>

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(12)

using namespace std;

typedef pair<int, int> P;

class CGoToSchool {
public:
    static constexpr int kStressIterations = 0;
    static void generateTest(std::ostream& test) {
    }

    void solve(std::istream& cin, std::ostream& cout) {
        int N;
        cin >> N;
        set<P> s;
        FOR(i, 1, N) {
            int a;
            cin >> a;
            s.insert({a, i});
        }
        for(auto kv : s) {
            cout << kv.second << " ";
        }
        cout << endl;
    }
};


signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    std::istream& in(std::cin);
    std::ostream& out(std::cout);

    CGoToSchool solver;
    solver.solve(in, out);
    return 0;
}


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

#define IOS ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define I insert
#define endl '\n'

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;


using vvll = vector< vector<ll> >;
using vll = vector<ll> ;

const ll maxs = 1e6+5;
const ll lmaxs = 20;
ll mod = 1e9+7;
ll oo = 1e15;


void pre(){



}


void solve(){

    ll n;
    cin >> n;
    ll a[n+1];
    ll z=0;
    for(ll i=1;i<=n;i++){
        cin >> a[i];
        if(a[i] == 0)
            z++;
    }
    if(z){
        cout << 0;
        return;
    }
    ll pre=1;
    ll flg=1;
    ll MAX = 1e18;
    for(ll i=1;i<=n;i++){
        if( a[i] > MAX/pre ){
            flg=0;
            break;
        }
        pre *= a[i];
    }

    if(flg==0){
        cout << -1 << endl;
    }else{
        cout << pre << endl;    
    }

}

int main(){
    // #ifndef ONLINE_JUDGE
    // freopen("input00.txt","r",stdin);
    // #endif
    IOS;
    pre();
    ll T = 1;
    //cin>>T;
    while(T--){
        solve();   
    }
    return 0;
}

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

// エイリアス
using  ll = long signed long;
using ull = long unsigned long;
using  ld = long double;
using   P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;

// 汎用マクロ
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define FOREACH(i,q) for (auto &i : q)
#define UNIQUE(v) do { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); } while (false)
#define SZ(x) ((int)(x).size())
template <class T>inline bool chmin(T &a, const T b) {if (a > b) { a = b; return true;} return false;}
template <class T>inline bool chmax(T &a, const T b) {if (a < b) { a = b; return true;} return false;}
template <class T>inline void line_out(const vector<T> vec) {int n = SZ(vec); rep(i, n) { cout << vec[i]; if(i < n-1) cout << " ";}cout << endl;}
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 28;
const ll INF64 = 1ll << 60;
const int mod = 1000000007;
//const int mod = 998244353;
//const int mod = 100000;
struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint &operator++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};

int main()
{
  int n; cin >> n;
  vector<int> p(n), q(n);
  rep(i, n) cin >> p[i];
  rep(i, n) cin >> q[i];
  if(p == q) {
    cout << 0 << endl;
    return 0;
  }
  vector<int> vec(n);
  rep(i, n) vec[i] = i+1;
  vector<int> idx;
  int i = 1;
  do {
    if(vec == p || vec == q) idx.push_back(i);
    ++i;
  } while(next_permutation(ALL(vec)));
  cout << abs(idx[0]-idx[1]) << endl;
}


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

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

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

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

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

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

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

typedef pii P;
const vi dy = { -1, 0, 1, 0 }, dx = { 0, 1, 0, -1 };

int main(){
    int h, w;
    cin >> h >> w;
    vs s(h);
    rep(i, h) cin >> s[i];
    int ans = 0;
    rep(si, h) rep(sj, w) {
        queue<P> q;
        vector<vi> dist(h, vi(w, INF));
        auto update = [&] (int ny, int nx, int nd) {
            if (dist[ny][nx] <= nd) return;
            q.emplace(ny, nx);
            dist[ny][nx] = nd;
        };
        if (s[si][sj] == '#') continue;
        update(si, sj, 0);
        while (!q.empty()) {
            int y = q.front().first, x = q.front().second; q.pop();
            rep(i, 4) {
                int ny = y + dy[i], nx = x + dx[i];
                if (ny<0 || ny>=h || nx<0 || nx>=w) continue;
                if (s[ny][nx] == '#') continue;
                update(ny, nx, dist[y][x]+1);
            }
        }
        rep(i, h) rep(j, w) {
            if (dist[i][j] == INF) continue;
            ans = max(ans, dist[i][j]);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3556
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
#define mp make_pair
typedef long long ll;
typedef pair<int,int> pint;

ll a[100001],sum[100001],sum2[100001];
int main(){
    int n,k;
    cin>>n>>k;
    rep(i,n) cin>>a[i];
    rep(i,n){
        sum[i+1]+=sum[i]+a[i];
        sum2[i+1]+=sum2[i]+(a[i]>=0?a[i]:0);
    }
    ll mx=0;
    FOR(i,k,n+1){
        ll cur=max(0ll,sum[i]-sum[i-k]);
        cur+=sum2[i-k];
        cur+=sum2[n]-sum2[i];
        mx=max(mx,cur);
    }
    cout<<mx<<endl;
    return 0;
}

Measured memory_bytes: 2560
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());
        int[] X = new int[N];
        int minSum = 2000000;
        int sum = 0;

        for (int i = 0; i < N; i++) {
            X[i] = Integer.parseInt(sc.next());
        }
        Arrays.sort(X);

        for (int i = X[0]; i <= X[N - 1]; i++) {
            for (int j = 0; j < N; j++) {
                sum += (X[j] - i) * (X[j] - i);
            }

            if (sum < minSum) {
                minSum = sum;
            }
            sum = 0;
        }

        PrintWriter out = new PrintWriter(System.out);
        out.println(minSum);
        sc.close();
        out.flush();
    }
}

Measured memory_bytes: 35740
import sys
readline = sys.stdin.buffer.readline

def main():
    n, m = map(int, readline().split())
    inf = 10**11
    dp = [inf] * (1000 * n + 1)
    dp[0] = 0

    for i in range(n):
        w, v = map(int, input().split())
        for j in range(1000 * n - v, -1, -1):
            if dp[j] != inf:
                dp[j + v] = min(dp[j + v], dp[j] + w)
    ans = 0
    for a, b in enumerate(dp):
        if b <= m:
            ans = max(ans, a)
    print(ans)

if __name__ == "__main__":
    main()

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

int main() {
	int n;
	cin >> n;
	
	switch (n) {
	case 0:
		puts("1");
		break;
	case 1:
		puts("2");
		break;
	case 2:
		puts("1");
		break;
	default:
		puts("0");
		break;
	}
	
	return 0;
}

Measured memory_bytes: 1120
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>
#include <cstring>
#include <cassert>


using namespace std;
#define SZ(x) (int)(x.size())
#define REP(i, n) for(int i=0;i<n;++i)
#define FOR(i, a, b) for(int i=a;i<b;++i)
#define RREP(i, n) for(int i=n-1;i>=0;--i)
#define RFOR(i, a, b) for(int i=b-1;i>=a;--i)

#define all(x) begin(x),end(x)
#define dump(x) cerr<<#x<<" = "<<(x)<<endl
#define debug(x) cerr<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<< endl;

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<int, int>;
const double eps = 1e-8;
const ll MOD = 1000000007;
const int INF = INT_MAX / 2;
const ll LINF = LLONG_MAX / 2;

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

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


template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> p) {
    os << p.first << ":" << p.second;
    return os;
}

template<class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
    os << "[";
    REP(i, SZ(v)) {
        if (i) os << ", ";
        os << v[i];
    }
    return os << "]";
}

template<class T1, class T2>
ostream &operator<<(ostream &os, const map<T1, T2> &mp) {
    os << "[";
    for (auto it = mp.begin(); it != mp.end(); ++it) {
        if (it != mp.begin()) {
            os << ", ";
        }
        os << *it;
    }
    return os << "]";
}

// edit

void solve() {
    int N;
    cin >> N;

    vector<ll> A(N);

    REP(i, N) cin >> A[i];

    ll neri = 0;
    REP(i, N) {
        neri ^= A[i];
    }

    REP(i, N){
        ll tmp = neri ^ A[i];
        cout << tmp << " ";
    }
    cout << endl;

}


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
//    std::ifstream in("input.txt");
//    std::cin.rdbuf(in.rdbuf());

    solve();


    return 0;
}


Measured memory_bytes: 4396
#include <iostream>
#include <string>

using namespace std;

int main()
{
    while (1)
    {
        int n, ans=0;
        string s[110];
        cin>>n;
        if (n==0) break;
        for (int i=0; i<n; i++) cin>>s[i];
        for (int i=0; i<n; i+=2)
        {
            if ((s[i]=="lu" && s[i+1]=="ru") || (s[i]=="ru" && s[i+1]=="lu") || (s[i]=="ld" && s[i+1]=="rd") || (s[i]=="rd" && s[i+1]=="ld")) ans++;
        }
        cout<<ans<<'\n';
    }
    return 0;
}



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

int main() {
	int n;
	cin >> n;
	vector<int> s(n);
	rep(i, n) cin >> s[i];
	int ans = 0;
	rep(i, n) ans += s[i];
	sort(s.begin(), s.end());
	if (ans % 10 != 0) {
		cout << ans << endl;
		return 0;
	}
	rep(i, n) {
		ans -= s[i];
		if (ans % 10 != 0) {
			cout << ans << endl;
			return 0;
		}
		ans += s[i];
	}
	cout << 0 << endl;
	return 0;
}


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

int main(){
        int a,b;
        bool fin=false;
        cin >> a >> b;
        for(int i=0;i<=a;i++){
                for(int ii=0;ii<=a-i;ii++){
                        if(10000*i+5000*ii+1000*(a-i-ii)==b){
                                cout << i << "  " << ii << "  " << a-i-ii << endl;
                                fin=true;
                                break;
                        }
                }
                if(fin){
                        break;
                }
        }
        if(!fin){
                cout << -1 << "  " << -1 << "  "  << -1 << endl;
        }
}


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

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
ll max(ll a, ll b){ 
	if(a >= b) return a;
	else if(a < b) return b;
}

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

int main(){
	ll a, b, c;
	cin >> a >> b >> c;
	string ans = (b-a == c-b)?"YES": "NO";
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
const int INF = 2147483647;//int max
const int MOD = 1000000007;
using namespace std;
using ll = long long;
using P = pair<int,int>;


int main() {
    ll a,b,c;
    cin >> a >> b >> c;
    if((a+b-c) < 0 && (a+b-c)*(a+b-c) > 4*a*b){
        cout << "Yes\n";
    }else cout << "No\n";
    return 0;
}
/*
やっほい！
　　　　　　　やほほい！
　　　　+　　 　*
　　　 ∧∧　　. ∧∞∧　*
*　ヽ(=´ω｀)人(´ω｀*)ﾉ
　.～（ O x.） （ 　 O)～　+
。*　 　∪　　　　∪
*/

Measured memory_bytes: 256
S = input()
ans= 0
if S == "SSS":
    ans = 0
elif S == "RSS":
    ans = 1
elif S == "SRS":
    ans = 1
elif S == "SSR":
    ans = 1
elif S == "RRS":
    ans = 2
elif S == "RSR":
    ans = 1
elif S == "SRR":
    ans = 2
elif S == "RRR":
    ans = 3

print(ans)

Measured memory_bytes: 9000
main(i){double p[8];while(~scanf("%lf %lf %lf %lf %lf %lf %lf %lf",p,p+1,p+2,p+3,p+4,p+5,p+6,p+7))printf(!(p[0]> p[6] ||p[0] >p[7] || p[2]<p[4] ||p[3] <p[5])?"YES\n":"NO\n");return 0;}

Measured memory_bytes: 616
import java.io.PrintWriter;
import java.util.*;

public class Main {
    PrintWriter out = new PrintWriter(System.out);
    final long mod = 1000000000+7;
    ArrayList<Integer>[] tree;
    long ans = 1;
    int n,k;
    public static void main(String[] args) {
        Main main = new Main();
        System.out.println(main.solve());
    }
    long solve(){
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt(); k = sc.nextInt();
        tree = new ArrayList[n];
        for(int i=0;i<n;i++) tree[i] = new ArrayList<>();
        for(int i=0;i<n-1;i++){
            int a = sc.nextInt()-1, b = sc.nextInt()-1;
            tree[a].add(b); tree[b].add(a);
        }
        ans *= k;
        int cnt = 0;
        for(int to:tree[0]){
            dfs(to,0,k-1-cnt);
            cnt++;
        }
        return ans;
    }
    // dfs starts from the child of a chosen root
    void dfs(int cur_vertex, int from, int val){
        ans = ans*Math.max(0,val)%mod;
        int cnt = 0;
        for(int to:tree[cur_vertex]){
            if(to==from) continue;
            dfs(to,cur_vertex,k-(cnt+2));
            cnt++;
        }
    }
}

Measured memory_bytes: 112888
N=int(input())
A=list(map(int,input().split()))
from collections import Counter
c=sorted(Counter(A).most_common(),reverse=True)
r=0
if len(c)==2 and c[0][0]==c[1][0]+1 and 0<c[0][0]-c[1][1]<=c[0][1]//2:
    r=1
elif len(c)==1 and (c[0][0]==c[0][1]-1 or c[0][0]<=c[0][1]//2):
    r=1
print(['No','Yes'][r])

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

void solve(std::istream &in, std::ostream &out);

int main() {
#ifdef LOCAL
  freopen("../IO/f.in", "r", stdin);
//  freopen("../IO/f.out", "w", stdout);
#else
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(nullptr);
  std::cout.tie(nullptr);
#endif
  solve(std::cin, std::cout);
  return 0;
}


void solve(std::istream &in, std::ostream &out) {
  int n;
  in >> n;
  int64_t s1 = 0;
  for (int i = 0; i < n - 1; ++i) {
    int u, v;
    in >> u >> v;
    if (u > v) swap(u, v);
    s1 += (int64_t) u * (n - v + 1);
  }
  int64_t s2 = 0;
  for (int i = 1; i <= n; ++i) {
    s2 += (int64_t) i * (n - i + 1);
  }
  out << s2 - s1 << '\n';
}

Measured memory_bytes: 3648
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp21
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            int a = Convert.ToInt32(input[0]);
            int b = Convert.ToInt32(input[1]);
            int i = 1;
            int c = 0;

            while(i<b)
            {
                i= i+a-1;
                c++;
            }
            Console.WriteLine(c);
            Console.Read();
        }
    }
}


Measured memory_bytes: 13268
#include <bits/stdc++.h>
using namespace std;
#define pb(x) push_back(x)
#define faster ios::sync_with_stdio(false)
#define ll long long int
#define sz 200005
#define mp(x,y) make_pair(x,y) 
#define pii pair<long long int,long long int>
#define tor ::iterator
#define letsgo long long  int i,j,k,q=0,t,tmp,n,flg=0,cntr=0,maxxer = 0
#define fi first
#define se second
#define be begin()
#define en end()
#define mod 1000000007
#define debug(x) cout<<" "<<x<<endl
ll dp[100005];
// ll lcs(int i,int j,string s1,string s2){
// 	if(i<0 || j<0)
// 		return 0;
// 	if(dp[i]!=-1)
// 		return dp[i][j];
// 	if(s1[i]==s2[j])
// 		dp[i] = 1 + lcs(i-1,j-1,s1,s2);
// 	else
// 		dp[i] = max(lcs(i-1,j,s1,s2),lcs(i,j-1,s1,s2));
// 	return dp[i];
// }
void trav(vector <ll> v[],ll ind,ll cnt){
	if(v[ind].size()==0)
		dp[ind] = 0;
	for(ll i = 0;i<v[ind].size();i++){
		if(dp[v[ind][i]]==-1)
			trav(v,v[ind][i],dp[ind]+1);
		dp[ind] = max(dp[ind],1 + dp[v[ind][i]]);
	}
}
int main(){
	faster;
	letsgo; 
	string s1,s2;
	ll m;
	cin>>n>>m;
	for(i=0;i<=n;i++)
		dp[i]=-1;
	vector <ll> v[100005];
	for(i=0;i<m;i++){
		cin>>j>>k;
		v[j].pb(k);
	}
	for(i=1;i<=n;i++){
		if(dp[i]== -1)
			trav(v,i,0);
	}
	// for(i=1;i<=n;i++)
		// cout<<dp[i]<<" ";
	cout<<*(max_element(dp,dp+n+1));
		
}


Measured memory_bytes: 8576
import java.util.*;

class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
	int n = sc.nextInt();
    int[] cnt = new int[4];
    for (int i=0; i<4; i++){
      cnt[i]=0;
    }
    String[] s = new String[n];
    for (int i=0; i<n; i++) {
      s[i] = sc.next();
      switch (s[i]) {
        case "AC":cnt[0]++;break;
        case "WA":cnt[1]++;break;
        case "TLE":cnt[2]++;break;
        case "RE":cnt[3]++;break;
      }
    }
    sc.close();
    System.out.println("AC x " + cnt[0]);
    System.out.println("WA x " + cnt[1]);
    System.out.println("TLE x " + cnt[2]);
    System.out.println("RE x " + cnt[3]);
  }
}

Measured memory_bytes: 64336
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n];
		for(int i = 0 ; i < n ; i++) a[i] = sc.nextInt();
		int ans = 0;
		for(int i = 0 ; i < n ; i++) {
			while(a[i] % 2 == 0) {
				a[i] /= 2;
				ans++;
			}
		}
		System.out.println(ans);
	}
}


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

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  set<int> X;
  for(int i = 0; i < N; i++){
    cin >> A.at(i);
    X.insert(A.at(i));
  }
  if(X.size() == N) cout << "YES" << endl;
  else cout << "NO" << endl;
}

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

int main(){
	int n;
	cin >> n;
	
	if ( n % 1000 == 0){
		cout << '0' << endl;
		return 0;
	}
	else{
		int diff = n % 1000;
		cout << 1000 - diff << endl;
	}

	return 0;
}

Measured memory_bytes: 3628
// Created by sz
#include <bits/stdc++.h>
using namespace std;

const int N = 1e5 + 5;
long long n,c, x[N], v[N], sum[N], mx[N];

int main(){
#ifdef LOCAL
    freopen("./input.txt", "r", stdin);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    cin>>n>>c;
    
    for (int i = 1; i <= n; i++)cin>>x[i]>>v[i];
    
    x[n+1] = c;
    v[n+1] = 0;
    
    for (int i = 1; i <= n+1; i++){
        sum[i] = sum[i-1] + v[i];
        mx[i] = max(mx[i-1], sum[i] - x[i]);
    }
    
    long long ans = mx[n+1];
    for (int i = n; i >= 0; i--){
        long long cc = sum[n+1] - sum[i-1] - 2*(c - x[i]);
        ans = max(ans, cc + mx[i-1]);
    }
    
    memset(sum, 0, sizeof(sum));
    memset(mx, 0, sizeof(sum));

    
    
    for (int i = n; i >= 0; i--){
        sum[i] = sum[i+1] + v[i];
        mx[i] = max(mx[i+1], sum[i] - ( c - x[i]));
    }
    
    ans = max(ans,mx[0]);
    for (int i = 0; i<= n; i++){
        long long cc = sum[0] - sum[i+1] - 2*x[i];
        ans = max(ans, cc + mx[i+1]);
    }
    
    cout<<ans<<endl;

    
    
    
    
    
    
    return 0;
}



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

int v[112];

int main () {

	int n, x;
	cin >> n >> x;

	int sum = 0;
	for (int i = 0; i < n; ++i)
		scanf ("%d", v + i);

	sort (v, v + n);

	int ans = 0;
	for (int i = 0; i < n; ++i) {
		sum += v[i];
		if (sum > x) break;
		++ans;
	}

	if (sum < x) --ans;

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <stdio.h>
#include <vector>
#include <numeric>

const int kN = 3000 + 5;
int a[kN];
int n;
std::vector<int> edges[kN];
bool dp[kN];

int main()
{
    scanf("%d", &n);
    for (int i = 0; i < n; ++ i) scanf("%d", a + i);
    for (int i = 0; i < n - 1; ++ i) {
        int a, b;
        scanf("%d%d", &a, &b); a --; b --;
        edges[a].emplace_back(b);
        edges[b].emplace_back(a);
    }
    std::vector<int> idx(n);
    std::iota(idx.begin(), idx.end(), 0);
    std::sort(idx.begin(), idx.end(), [&](int x, int y) {return a[x] < a[y];});
    std::vector<int> result;
    for (int i = 0; i < n; ++ i) {
        int u = idx[i];
        for (int v : edges[u])
            dp[u] |= a[u] > a[v] && dp[v] == false;
        if (dp[u]) result.emplace_back(u);
    }
    std::sort(result.begin(), result.end());
    for (int i = 0; i < result.size(); ++ i)
        printf("%d%c", result[i] + 1, " \n"[i + 1 == result.size()]);
}


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

// {U}{INT,LONG,LLONG}_{MAX,MIN}
#define INF         INT_MAX/3
#define LLINF       LLONG_MAX/3
#define MOD         (1000000007LL)
#define MODA(a, b)  a=((a)+(b))%MOD
#define MODP(a, b)  a=((a)*(b))%MOD
#define inc(i, l, r)   for(int i=(l);i<(r);i++)
#define dec(i, l, r)   for(int i=(r)-1;i>=(l);i--)
#define pb          push_back
#define se          second
#define fi          first
#define mset(a, b)  memset(a, b, sizeof(a))

using LL  = long long;
using G   = vector<vector<int>>;

int di[] = {0, -1, 0, 1};
int dj[] = {1, 0, -1, 0};
// }}}

int cnt_min[26];

int main() {
    cin.tie(0);ios::sync_with_stdio(false);
    int n;cin >> n;
    inc(i, 0, n){
        string s;cin >> s;
        vector<int> cnt(26, 0);
        for(auto c : s){
            cnt[c-'a']++;
            if(i == 0){
                cnt_min[c-'a'] = cnt[c-'a'];
            }
        }
        inc(i, 0, 26){
            cnt_min[i] = min(cnt_min[i], cnt[i]);
        }
    }
    inc(i, 0, 26){
        inc(j, 0, cnt_min[i]){
            cout << char(i+'a');
        }
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<cstdio>
#include<sstream>
#include<iomanip>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef pair<int,pii> pip;
typedef vector<pip>vip;
const double PI=acos(-1);
const double EPS=1e-8;
const int inf=1e8;
int main(){
	int n;
	int dx[]={0,1,0,-1};
	int dy[]={-1,0,1,0};
	while(cin>>n,n){
		n--;
		vvi in(500,vi(500,-1));
		in[250][250]=0;
		rep(i,n){
			int a,b;
			cin>>a>>b;
			rep(j,500)rep(k,500)if(a==in[j][k]){
				in[j+dx[b]][k+dy[b]]=i+1;
			}
		}
		int sx=inf,sy=inf,gx=-inf,gy=-inf;
		rep(i,500)rep(j,500)if(in[i][j]+1){
			sx=min(sx,i);
			sy=min(sy,j);
			gx=max(gx,i);
			gy=max(gy,j);
		}
		cout<<gy-sy+1<<" "<<gx-sx+1<<endl;
	}
}

Measured memory_bytes: 2128
using System;
using System.Linq;

namespace aizu
{
    class OnlineJudge
    {
        static void Main()
        {
            string input;
            int count = 0;
            while((input = Console.ReadLine()) != null) {
                count += input.SequenceEqual(input.Reverse().ToArray()) ? 1 : 0;
            }
            Console.WriteLine(count);
        }
    }
}

Measured memory_bytes: 20604
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long int;
using ull = unsigned long long int;
using P = pair<int, int>;
using P3 = pair<double,P>;
using PP = pair<P ,P>;
constexpr ll MOD = ll(1e9+7);
constexpr int IINF = INT_MAX;
constexpr ll LLINF = LLONG_MAX;
constexpr int MAX_N = int(1e6) + 5;
constexpr double EPS = 1e-8;
constexpr int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define SORTR(v) sort((v).rbegin(), (v).rend())
#define ALL(v) (v).begin(), (v).end()

ll power(ll x, ll n){
    x %= MOD;
    ll res = 1;
    while(n > 0){
        if(n&1){
            res = res*x%MOD;
        }
        x = x*x%MOD;
        n >>= 1;
    }
    return res;
}

int main(){
    ll n;
    cin >> n;
    vector<ll> x(n);
    for(int i=0;i<n;i++){
        cin >> x[i];
    }
    ll ans = 0;
    vector<ll> h(n);
    for(int i=1;i<n;i++){
        h[i] = h[i-1] + power(i,MOD-2);
    }
    for(int i=0;i<n-1;i++){
        ans += h[i+1] * (x[i+1]-x[i]) % MOD;
        ans %= MOD;
    }
    for(int i=1;i<=n-1;i++){
        ans *= i;
        ans %= MOD;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <functional>
#include <numeric>
#include <iomanip>
#define fi first
#define se second
#define fcout(n) cout<<fixed<<setprecision((n))
#define cinl(str) getline(cin,(str))
using namespace std;
bool value(int y,int x,int R,int C){return 0<=y&&y<R&&0<=x&&x<C;}
typedef pair<int,int> pii;
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long > vll;
typedef vector< vi > vvi;
double pie=acos(-1);
int INF=1000000007;
int dx[4] = { 0,-1,0,1 };
int dy[4] = { -1,0,1,0 };


int main() {
	char a[105][105];
	int h,w;
	cin>>h>>w;
	for(int i=1;i<=h;i++){
		for(int j=1;j<=w;j++){
			cin>>a[i][j];
		}
	}
	for(int i=0;i<=h+1;i++){
		a[i][0]='#';
	}
	for(int i=0;i<=w+1;i++){
		a[0][i]='#';
	}
	for(int i=0;i<=h+1;i++){
		a[i][w+1]='#';
	}
	for(int i=0;i<=w+1;i++){
		a[h+1][i]='#';
	}

	for(int i=0;i<=h+1;i++){
		for(int j=0;j<=w+1;j++){
			cout<<a[i][j];
		}
		cout<<endl;
	}
}

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

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


Measured memory_bytes: 256
# ARC097D - Equals (ABC097D)
import sys

input = sys.stdin.readline
sys.setrecursionlimit(10 ** 9)


def dfs(v: int, color: int) -> None:
    seen[v] = 1  # make vertex v searched
    group[v] = color
    for u in G[v]:  # search vertices available from v recursively
        if not seen[u]:  # skip if already searched
            dfs(u, color)


def main():
    # check i and Pi are connected components or not
    global G, seen, group
    N, M = tuple(map(int, input().split()))
    P = tuple(map(int, input().split()))
    E = tuple(tuple(map(int, input().split())) for _ in range(M))
    G = [[] for _ in range(N + 1)]  # construct a graph (1-idx)
    for v, u in E:
        G[v] += [u]
        G[u] += [v]
    seen, group = [0] * (N + 1), [0] * (N + 1)
    color = 1
    for i in range(1, N + 1):  # connected components have the same color
        if not seen[i]:
            dfs(i, color)
            color += 1
    ans = sum(group[i] == group[p] for i, p in enumerate(P, 1))
    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 90944
n,m = map(int, input().split())
ans=1
div=10**9+7

def func(ans,x):
  for i in range(1,x+1):
    ans*=i
    ans%=div
  return ans

if abs(n-m)>1:
  ans = 0
else:
  ans = func(ans,n)
  ans = func(ans,m)
  if abs(n-m)==0:
    ans*=2
    ans%=div

print(ans)

Measured memory_bytes: 9140
n, q = gets.chomp.split(" ").map(&:to_i)
processes = []
n.times do |i|
  name, time = gets.chomp.split(" ")
  time = time.to_i
  processes << [name, time]
end
endtime = 0
until processes.empty?
  task = processes.shift
  if task[1] <= q then
    endtime += task[1]
    puts "#{task[0]} #{endtime}"
  else
    endtime += q
    task[1] -= q
    processes.push(task)
  end
end

Measured memory_bytes: 14860
import * as fs from 'fs';

//in
// SASA
//out
// Yes
const main: any = (inp: string) => {
    const s :string[] = inp.split('');
    const tbl: { [s:string]: number } = {};
    for (let wl  of s) {
        tbl[wl] = 0;
    }
    for (let wl of s ) {
        tbl[wl]++;
    }
    let ans :string = 'Yes';
    for (let wl of s ) {
        if (tbl[wl] !==2) {
            ans = 'No';
        }
    }
    console.log(ans);
};
main(fs.readFileSync('/dev/stdin', 'utf8').trim());

Measured memory_bytes: 7372
s=list(input())

ch=[]
for i in range(len(s)):
    if s[i]!='x':
        ch.append(s[i])

if len(ch)==0:
    print(0)
    exit()
for i in range(len(ch)//2):
    if ch[i]!=ch[len(ch)-i-1]:
        print(-1)
        exit()

ans=0
li=0
ri=0
for i in range(len(ch)//2+1):
    x=0
    while s[li]!=ch[i]:
        x += 1
        li += 1
    li += 1
    y=0
    while s[len(s)-1-ri]!=ch[len(ch)-1-i]:
        y += 1
        ri += 1
    ri += 1
    ans += abs(x-y)

print(ans)

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
using P = pair<ll, ll>;
using V = vector<ll>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep1(i, n) for(ll i=1;i<=(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
#define ALL(obj) (obj).begin(), (obj).end()
#define MOD 1000000007
#define INF 1000000000

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
struct mint {
	ll x; // typedef long long ll;
	mint(ll x = 0) :x((x% mod + mod) % mod) {}
	mint operator-() const { return mint(-x); }
	mint& operator+=(const mint a) {
		if ((x += a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator-=(const mint a) {
		if ((x += mod - a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator*=(const mint a) {
		(x *= a.x) %= mod;
		return *this;
	}
	mint operator+(const mint a) const {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint a) const {
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint a) const {
		mint res(*this);
		return res *= a;
	}
	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}

	// for prime mod
	mint inv() const {
		return pow(mod - 2);
	}
	mint& operator/=(const mint a) {
		return (*this) *= a.inv();
	}
	mint operator/(const mint a) const {
		mint res(*this);
		return res /= a;
	}
};

// nCr
// combination mod prime
// https://www.youtube.com/watch?v=8uowVvQ_-Mo&feature=youtu.be&t=1619
struct combination {
	vector<mint> fact, ifact;
	combination(int n) :fact(n + 1), ifact(n + 1) {
		assert(n < mod);
		fact[0] = 1;
		for (int i = 1; i <= n; ++i) fact[i] = fact[i - 1] * i;
		ifact[n] = fact[n].inv();
		for (int i = n; i >= 1; --i) ifact[i - 1] = ifact[i] * i;
	}
	mint operator()(int n, int k) {
		if (k < 0 || k > n) return 0;
		return fact[n] * ifact[k] * ifact[n - k];
	}
};

void solve_abc145() {
	ll x, y;
	cin >> x >> y;

	mint ans = 0;

	if ((x + y) % 3 != 0) {
		ans = 0;
	}
	else {
		mint a, b;
		b.x = (2 * x - y) / 3;
		a.x = x - 2 * b.x;

		if (a.x < 0 || b.x < 0) {
			ans = 0;
		}
		else {
			combination c(a.x + b.x + 5);

			ans = c(a.x + b.x, a.x);
		}
	}


	cout << ans.x << "\n";
}

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

	solve_abc145();

	return 0;
}

Measured memory_bytes: 10752
#include<iostream>
#include<cstdio>
#include<string.h>
#include<algorithm>
#include<vector>
#include<cstdlib>
#include<cmath>
using namespace std;
int main() {
    int n;
    cin>>n;
    vector<int> num(n);
    for(int i=0;i<n;i++) {
        cin>>num[i];
    }
    sort(num.begin(),num.end());
    cout<<num.back()<<" ";
    int mn=num[0];
    double mid=num.back()/2.0;
    for(int i=1;i<n;i++) {
        if(abs(1.0*mn-mid)>abs(1.0*num[i]-mid)){
            mn=num[i];
        }
    }
    cout<<mn<<"\n";
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define PUTS(x) cout << (x) << endl;
#define ALL(v) (v).begin(), (v).end()
#define rep(i, n) for (int i = 0, i##_len = (int)(n); i < i##_len; i++)
#define reps(i, n) for (int i = 1, i##_len = (int)(n); i <= i##_len; i++)
#define PB push_back
#define perm(c)   \
    sort(ALL(c)); \
    for (bool c##p = 1; c##p; c##p = next_permutation(ALL(c)))
int main() {
    int n;
    cin >> n;
    auto v = vector<int>();
    reps(i, n) {
        v.PB(i);
    }
    auto a = vector<int>();
    auto b = vector<int>();
    rep(i, n) {
        int x;
        cin >> x;
        a.PB(x);
    }
    rep(i, n) {
        int x;
        cin >> x;
        b.PB(x);
    }
    int x, y;
    int c = 0;
    perm(v) {
        if (v == a) x = c;
        if (v == b) y = c;
        c++;
    }
    PUTS(abs(x - y));
}


Measured memory_bytes: 256
import numpy as np

MOD = 998244353

N, S = map(int, input().split())
As = list(map(int, input().split()))

dp = np.zeros((N+1, S+1), np.int64)
dp[0][0] = 1
for n, A in enumerate(As):
    dp[n+1, :] = dp[n, :] * 2
    dp[n+1, A:] += dp[n, :-A]
    dp[n+1] %= MOD

print(dp[N, S])

Measured memory_bytes: 97416
# 3で割ります
# -> 割れました -> おわり NHK
# -> 割れません -> 商を越えるまでwかhをageていって近い方を抜く
# 2で割ります
# -> 割れました -> おわり NHK
# -> 割れません -> 商を越えるまでre
# って手続き的に考えて実装したんだけどどうにもうまくいかんし自尊心が死んだので諦めた

# 解説みたらパターンで全探索らしい は？

h, w = gets.chomp.split.map(&:to_i)
def f(h, w)
  minimum = 10**10
  1.upto(h-1) do |hi|
    sa = hi*w
    # 横に分割
    sb = (w/2)*(h-hi)
    sc = h*w-(sa+sb)
    # 適当に分割しただけなのでこれら3つからa,b,cを同定
    # puts "横に分割"
    # p [sa, sb, sc]
    ssc, ssa = [sa, sb, sc].minmax
    minimum = [minimum, ssa-ssc].min
    # 縦に分割
    sb = ((h-hi)/2)*w
    sc = h*w-(sa+sb)
    # 適当に略
    # puts "縦に分割"
    # p [sa, sb, sc]
    ssc, ssa = [sa, sb, sc].minmax
    minimum = [minimum, ssa-ssc].min
  end
  return minimum
end

puts [f(h, w), f(w, h)].min


Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include <boost/multiprecision/cpp_ll.hpp>
//typedef boost::multiprecision::cpp_ll ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
string alp="abcdefghijklmnopqrstuvwxyz";
#define endl "\n"
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);


int main(){
    ll n;cin>>n;
    ll a[3*n];rep(i,0,3*n-1)cin>>a[i];
    sort(a,a+3*n);
    ll sum=0;
    for(ll i=n;i<3*n;i=i+2){
        sum+=a[i];
    }
    cout<<sum<<endl;
    
    return 0;
}






Measured memory_bytes: 2560
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <math.h>
#include <cmath>
#include <limits.h>
#include <map>
#include <unordered_map>
#include <set>
#include <queue>
#include <algorithm>
#include <functional>
#include <stdio.h>
using namespace std;

long long MOD = 1000000007;

int main() {
    
    int N;
    cin >> N;
    vector<long long> A(N);
    for ( int i = 0; i < N; i++ ) {
        cin >> A[i];
        A[i] -= i+1;
    }

    sort( A.begin(), A.end() );

    long long a = A[(N-1)/2];

    long long ans = 0;
    for ( int i = 0; i < N; i++ ) {
        ans += abs(a-A[i]);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <algorithm>
#include <cmath>
#include <iomanip>

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

int main()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    
    int x; std::cin >> x;
    int p = x;
    while(!is_prime(p)) p++;

    std::cout << p << std::endl;
    
    return 0;
}


Measured memory_bytes: 256