akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

#define SIZE 100005
#define PI acosl(-1) //3.14159265358979323846264338327950L 
#define rep(i, N) for (i = 0; i < N; i++) //制御変数iを用いてN回転
#define array(N, t) (t*)calloc(N, sizeof(t)) //t型N要素の1次元配列を動的確保後0クリア(freeを忘れずに)
#define zero(a); {int iter; rep(iter, sizeof(a)/sizeof((a)[0])) (a)[iter]=0;} //1次元配列aのゼロ初期化?

typedef long long ll; typedef long double ld;
typedef struct node { int data; struct node *next; } Node;

Node *list[SIZE];
int queue[SIZE]; int q_head = 0, q_tail = 0;

void print_log(); //とりあえず文字を出力してどこまで実行できているか確認(for debug)
void printa_int(int *a, int size); //int型の1次元配列aを出力(for debug)
void printl_int(int size); //リンクリストを出力(for debug)
Node* add_node(int i, int data); void free_list(Node* head);
int queue_empty(); int queue_full();
void enqueue(int data); int dequeue();

int main() {
    ll A, ans = 0;
    ll t[3];
    char B[5];
    scanf("%lld %s", &A, &B);
    t[0] = A * (B[0] - '0');
    t[1] = A * (B[2] - '0');
    t[2] = A * (B[3] - '0');
    t[1] = (t[1] * 10 + t[2]) / 10;
    t[0] = (t[0] * 10 + t[1]) / 10;
    printf("%lld\n", t[0]);
    return 0;
}

void print_log() {
    printf("=== print log ===\n");
}
void printa_int(int *a, int size) {
    int i;
    printf("[");
    for (i = 0; i < size; i++)
        printf("%d, ", a[i]);
    printf("]\n");
}
void printl_int(int size) {
    int i;
    Node *t;
    rep(i, size) {
        printf("[%d] ", i);
        for (t = list[i]; t; t = t->next) printf("%d, ", t->data);
        printf("\n");
    }
}
Node* add_node(int i, int data) {
    if (!list[i]) {
        list[i] = (Node*)malloc(sizeof(Node*));
        list[i]->data = data;
    } else {
        Node *t;
        t = list[i];
        list[i] = (Node*)malloc(sizeof(Node*));
        list[i]->data = data;
        list[i]->next = t;
    }
    return list[i];
}
void free_list(Node* head) {
    Node *prev = NULL, *t = head;
    while (t) {
        prev = t;
        t = t->next;
        free(prev);
    }
}
int queue_empty() {
    return q_head == q_tail;
}
int queue_full() {
    return (q_head - 1) % SIZE == q_tail % SIZE;
}
void enqueue(int data) {
    if (queue_full()) {
        printf("full!\n");
        return;
    }
    queue[q_tail++] = data;
    q_tail %= SIZE;
}
int dequeue() {
    if (queue_empty()) {
        printf("empty!\n");
        return -444444;
    }
    int data = queue[q_head++];
    q_head %= SIZE;
    return data;
}

Measured memory_bytes: 1732
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <queue>
#include <utility>
#include <map>
#include <bitset>
#include <iomanip>
#define ll long long
using namespace std;
using p = pair<ll, ll>;
ll dx[4] = {-1, 0, 1, 0};
ll dy[4] = {0, 1, 0, -1};

int main(void){
    ll n, q;
    cin >> n >> q;
    vector<vector<ll>> g(n+1);
    vector<ll> w(n+1, 0);
    for(ll i = 0; i < n-1; i++){
        ll a, b;
        cin >> a >> b;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    for(ll i = 0; i < q; i++){
        ll a, b;
        cin >> a >> b;
        w[a] += b;
    }
    vector<ll> dist(n+1, -1);
    queue<ll> que;
    dist[1] = w[1];
    que.push(1);
    while(!que.empty()){
        ll v = que.front();
        que.pop();
        for(ll nv : g[v]){
            if(dist[nv] != -1) continue;
            dist[nv] = dist[v]+w[nv];
            que.push(nv);
        }
    }
    for(ll i = 1; i <= n; i++)
        cout << dist[i] << " ";
    cout << endl;
    return 0;
}


Measured memory_bytes: 19440
#include <stdio.h>
#include <string.h>
int main()
{
	long long n;
	long long k;
	long long s=0;
	scanf("%lld",&k);
	while(k--)
	{
		scanf("%lld",&n);
		s=s+n-1;
	}
	printf("%lld",s);
	return 0;
}

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

using namespace std;

bool ar[100001];

int main()
{
    int n,l,r,maxi=0,count=0;

    cin>>n;
    while(n--)
    {
        cin>>l>>r;
        if(maxi<r)
            maxi=r;

        for(int i=l;i<=r;i++)
            ar[i]=1;

    }
    for(int i=1;i<=maxi;i++)
    {
        if(ar[i]==1)
            count++;
    }
    cout<<count<<endl;

}

Measured memory_bytes: 384
w=[]
for i in range(10):
    n=int(input())
    w.append(n)
wa = sorted(w, reverse=True)
W=sum(wa[:3])

k=[]
for j in range(10):
    m=int(input())
    k.append(m)
ka = sorted(k, reverse=True)
K=sum(ka[:3])

print(W, K)



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

int main(){
  int N;
  cin >> N;
  vector<int> A(N);
  priority_queue<int> pq;
  for(int i=0;i<N;i++){
    cin >> A.at(i);
    pq.push(A.at(i));
  }
  for(int i=0;i<N;i++){
    if(A.at(i)==pq.top()){
      pq.pop();
      cout << pq.top() << endl;
      pq.push(A.at(i));
    }else{
      cout << pq.top() << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 3316
s = input()
k = int(input())
l = len(s)
ans = 0
if k <= 3: s = s*k
else:
    if k % 2 == 0: s = s*4
    else: s = s*5
a = [0]*len(s)
for i in range(len(s)):
    if i > 0 and s[i] == s[(i-1)]: a[i] += 2
    if i < len(s)-1 and s[i] == s[(i+1)]: a[i] += 1
for i in range(len(s)):
    if a[i] == 3:
        a[i] = -1
        if a[i+1] >= 2: a[i+1] -= 2
        if a[i-1] == 1: a[i-1] = 0
#print(a)
for i in range(len(s)-1):
    if a[i] == 1 and a[i+1] == 2:
        a[i] = -1
        a[i+1] = 0
#print(a)
if k <= 3: 
    ans = len([i for i in range(len(s)) if a[i] == -1])
else:
    if k % 2 == 0:
        ans += len([i for i in range(l) if a[i] == -1])
        ans += len([i for i in range(3*l,4*l) if a[i] == -1])
        ans += len([i for i in range(l, 3*l) if a[i] == -1]) * (k//2-1)
    else:
        ans += len([i for i in range(l) if a[i] == -1])
        ans += len([i for i in range(4*l,5*l) if a[i] == -1])
        ans += len([i for i in range(l, 2*l) if a[i] == -1]) * (k//2)
        ans += len([i for i in range(2*l, 3*l) if a[i] == -1]) * (k//2-1)
print(ans)

Measured memory_bytes: 3192
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <set>
#include <string>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <utility>
using namespace std;

typedef unsigned int uint;
typedef long long int64;
typedef unsigned long long uint64;
typedef pair<int, int> ii;
typedef pair<int64, int64> int64int64;
typedef vector<int> vint;
typedef vector<int64> vint64;
typedef vector<uint64> vuint64;
typedef vector<vint> vvint;
typedef vector<vint64> vvint64;
typedef vector<vuint64> vvuint64;
typedef vector<ii> vii;
typedef vector<vector<ii>> vvii;

#define mp make_pair
#define pb push_back
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
#define fori(n) for(int i = 0; i < n; ++i)
#define forj(n) for(int j = 0; j < n; ++j)
#define fork(n) for(int k = 0; k < n; ++k)
#define INF9 (int64)(1e9)
#define INF18 (int64)(1e18)

template<typename T>
struct compF{
	bool operator()(const pair<T, T> &a, const pair<T, T> &b){
		return a.first < b.first;
	}
};

template<typename T>
struct compS{
	bool operator()(const pair<T, T> &a, const pair<T, T> &b){
		return a.second < b.second;
	}
};

template<typename T>
void printMatrix(const string &txt, vector<vector<T>> &a){
	cout << txt;
	fori(a.size()){
		forj(a[i].size())
			cout << a[i][j] << ' ';

		cout << endl;
	}
}

template<typename T>
void printVector(const string &txt, vector<T> &a){
	cout << txt;
	for (int i = 0; i < a.size(); ++i)
		cout << a[i] << ' ';
	cout << endl;
}

template<typename T>
void readVector(int n, vector<T> &a){
	if (a.size() < n)
		a.resize(n);

	fori(n) cin >> a[i];
}

template<typename T1, typename T2>
bool exist(map<T1, T2> &m, T1 x){
	if (m.find(x) == m.end())
		return false;

	return true;
}

int64 gcd(int64 a, int64 b){
	while (a != 0 && b != 0){
		if (b > a)
			b %= a;
		else
			a %= b;
	}

	return a + b;
}

int64 minFactor(int64 x){
	for (int64 i = 2; i * i <= x; ++i)
		if (x % i == 0)
			return i;

	return x;
}

int64 allFactors(int64 x, vint64 &prms, vint64 &prm_cnt){
	prms.clear();
	prm_cnt.clear();
	while (x > 1){
		int64 t = minFactor(x);
		prms.push_back(t);
		int s = prms.size() - 1;
		prm_cnt.push_back(0);
		while (x % t == 0){
			x /= t;
			++prm_cnt[s];
		}
	}

	return 0;
}

int main(){

	ios_base::sync_with_stdio(0);
	cin.tie();
	
	int n, k;
	cin >> n >> k;
	vint a(n);
	fori(n)
		cin >> a[i];
	sort(ALL(a));
	int64 res = 0;
	fori(k)
		res += a[i];
	cout << res << endl;


	return 0;
}


Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int k;
	string s;
	cin>>k;
	cin>>s;
	if(k>=s.size()){
		cout<<s<<"\n";
	}
	else{
		for(int i=0;i<k;i++)
	{
		cout<<s[i];
	}
		cout<<"..."<<"\n";
	};
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
#define ll long long int
#define ld long double
#define pi pair<int,int>
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()
#define sz(x) ((int)x.size())
#define ln(x) ((int)x.length())
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define endl '\n'
#define dbg(x) cout<<#x<<": "<<x<<endl
#define clr(x,v) memset(x, v, sizeof(x))
#define FASTIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
const double eps = 1e-9;
const double PI = acos(-1.0);
const ll mod = 1e9 + 7;
const int MAXN = 1e6 + 5;
int n, m, k;
char arr[7][7];
int ans;
vector<pi> pick;
void rec(int i, vector<pi> subset)
{
    if(i == sz(pick))
    {
        vector<int> row, col;
        for(pi x : subset)
            if(x.ss == 1)
                row.pb(x.ff);
            else
                col.pb(x.ff);
        char temp[n][m];
        for(int i = 0; i < n; i++)
            for(int j = 0; j < m; j++)
                temp[i][j] = arr[i][j];
        for(int r : row)
            for(int j = 0; j < m; j++)
                temp[r][j] = 'R';
        for(int c : col)
            for(int i = 0; i < n; i++)
                temp[i][c] = 'R';
        int cnt = 0;
        for(int i = 0; i < n; i++)
            for(int j = 0; j < m; j++)
            	if(temp[i][j] == '#')
            		cnt++;
        if(cnt == k)
        	ans++;
    }
    else
    {
        rec(i + 1, subset);
        subset.pb(pick[i]);
        rec(i + 1, subset);
    }
}



void cp()
{
    cin >> n >> m >> k;
    for(int i = 0; i < n; i++)
        for(int j = 0; j < m; j++)
            cin >> arr[i][j];
    for(int i = 0; i < n; i++)
        pick.pb({i, 1});
    for(int i = 0; i < m; i++)
        pick.pb({i, 2});
    rec(0,vector<pi>());
    cout<<ans;
}

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

Measured memory_bytes: 3644
#include <stdio.h>
int main(void)
{
int i,sum=0;
int flag=0;

char x[1002];
scanf("%s",x);
do{
for(i=0;i<1002;i++){
if(x[i]==0){
  printf("%d\n",sum);
  break;
}else{
sum+=x[i]-0X30;
}
}
sum=0;
scanf("%s",x);
}while(x[0]!=0X30);

return 0;
}

Measured memory_bytes: 2596
#include<stdio.h>
int main()
{
  int num;
  int a,b;

  int ans=0;
  scanf("%d%d",&a,&b); 
  for(num=a;num<=b;num++){
    int reverse = 0;
    int remaind;
    int tmp;
    tmp = num;
    while(tmp!=0)
    {
      remaind = tmp % 10;
      reverse = reverse * 10 + remaind;
      tmp /= 10;
    }
    if(reverse==num)ans++;
}
 printf("%d\n",ans);
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MM = 1000000000;
const int MOD = MM + 7;
const int MAX = 510000;
#define rep(i, n) for(ll i=0; i<n; i++)
#define Rep(i, j, n) for(ll i=j; i<n; i++)
#define all(vec) vec.begin(), vec.end()
template<class T> inline bool chmin(T& a, T b) {if(a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if(a < b) {a = b; return true;} return false;}
const ll INF = 1LL << 60;
const double pi = acos(-1.0);

int main() {
    ll x, t; cin >> x >> t;
    cout << max<ll>(0, x-t) << endl;
}

Measured memory_bytes: 3628
N = int(input())
A = list(map(int, input().split())) 

A = sorted(A)
sumA = sum(A)

for n in range(0, N-1, 2):
    v = A[n] + A[n+1]
    if v < 0:
        sumA = sumA - (2* v)
    else:
        break
print(sumA)


Measured memory_bytes: 14412
import sys
readline = sys.stdin.readline

V, E = map(int, readline().split())
inf = float("inf")
vertices = [[inf if i!=j else 0 for j in range(V)] for i in range(V)]

for _ in [None]*E:
    s, t, d = map(int, readline().split())
    vertices[s][t] = d

for k in range(V):
    for i in range(V):
        for j in range(V):
            c1, c2, c3 = vertices[i][j], vertices[i][k], vertices[k][j]
            vertices[i][j] = c1 if c1 < c2+c3 else c2+c3

ans = []
for i, a in enumerate(vertices):
    if a[i] < 0:
        print("NEGATIVE CYCLE")
        break
    ans.append(" ".join([str(n) if n != inf else "INF" for n in a]))
else:
    print("\n".join(ans))

Measured memory_bytes: 8496
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#define MOD 1000000007LL
using namespace std;

int main(){
	int n, m;
	cin >> n >> m;
	string a[n];
	string b[m];
	for(int i = 0; i < n; i++) cin >> a[i];
	for(int i = 0; i < m; i++) cin >> b[i];
	int ans = 0;
	for(int i = 0; i <= n-m; i++){
		for(int j = 0; j <= n-m; j++){
			int x = 1;
			for(int k = 0; k < m; k++){
				for(int l = 0; l < m; l++){
					if(b[k][l] != a[k+i][l+j]) x = 0;
				}
			}
			if(x == 1) ans = 1;
		}
	}
	if(ans == 1) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <cmath>
#include <cstdarg>
#include <cstdlib>
#include <string>

#include <vector>
#include <tuple>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;

int main(int argc, char const *argv[]) {
    long long n;
    cin >> n;
    long long a[n];
    for (auto &x : a) {
        cin >> x;
    }
    long long money = 1000;
    long long have = 0;
    for (int i = 0; i < n-1; i ++) {
        if (have == 0 && a[i] < a[i + 1]) {
            have = money / a[i];
            money -= have * a[i];
        } else if (have > 0 && a[i] > a[i + 1]) {
            money += have * a[i];
            have = 0;
        }
    }
    money += a[n-1] * have;
    cout << money << endl;
    return 0;
}

Measured memory_bytes: 3600
N, M = map(int, input().split())
A = list(map(lambda x: int(x) * (-1), input().split()))

import heapq

heapq.heapify(A)

for _ in range(M):
    tmp = heapq.heappop(A) * (-1) // 2
    heapq.heappush(A, tmp*(-1))

ans = 0
for i in range(N):
    ans += heapq.heappop(A)

print(-ans)


Measured memory_bytes: 74392
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        int d, n;
        try (Scanner cin = new Scanner(System.in)) {
            d = cin.nextInt();
            n = cin.nextInt();
        }
        if (n == 100)
            System.out.println((int) Math.pow(100.0, (double) d) * 101);
        else
            System.out.println((int) Math.pow(100.0, (double) d) * n);
    }
}

Measured memory_bytes: 23124
import java.util.Scanner;
class Main {
    public static void main (String[] args) {
        Scanner sc = new Scanner(System.in);
        while (true) {
        	int a = sc.nextInt();
        int b = sc.nextInt();
        if (a==0 && b==0) break;
        for (int i=0; i<a; i++) {
        		if(i%2 == 0) {
        			for(int j=0; j<b;j++) {
        				if(j%2 == 0) System.out.print("#");
            			if(j%2 == 1) System.out.print(".");
            			if(j == b-1) System.out.println();
        			}
        		} 
        		if(i%2 == 1) {
        			for(int j=0; j<b;j++) {
            			if(j%2 == 0) System.out.print(".");
            			if(j%2 == 1) System.out.print("#");
            			if(j == b-1) System.out.println();
        			}
        		}
        		if(i == a-1) System.out.println();
        }
        }
    }
}


Measured memory_bytes: 35604
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int sp[111][111];
int dp[111][111][1<<5];
int w,h;
int in(int y,int x){
  return 0<=y&&y<h&&0<=x&&x<w;
}
struct sta{
  int y,x,b,d;
  sta(){}
  sta(int y,int x,int b,int d):y(y),x(x),b(b),d(d){}
  bool operator<(const sta& a) const{
    return d>a.d;
  }
};
typedef pair<int,int> P;
int main(){
  memset(sp,0,sizeof(sp));
  memset(dp,-1,sizeof(dp));
  cin>>w>>h;
  string st[h];
  for(int i=0;i<h;i++) cin>>st[i];
  int sy,sx,gy,gx,n=0;
  map<P,int> m;
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      sp[i][j]=max(sp[i][j],1);
      if(st[i][j]=='M') m[P(i,j)]=n++;
      if(st[i][j]=='S') sy=i,sx=j;
      if(st[i][j]=='G') gy=i,gx=j;
      if(st[i][j]=='#'){
	for(int k=1;k<=3;k++){
	  for(int a=-(4-k);a<=4-k;a++){
	    if(in(i-(4-k),j+a)) sp[i-(4-k)][j+a]=max(sp[i-(4-k)][j+a],k);
	    if(in(i+(4-k),j+a)) sp[i+(4-k)][j+a]=max(sp[i+(4-k)][j+a],k);
	    if(in(i+a,j-(4-k))) sp[i+a][j-(4-k)]=max(sp[i+a][j-(4-k)],k);
	    if(in(i+a,j+(4-k))) sp[i+a][j+(4-k)]=max(sp[i+a][j+(4-k)],k);
	  }
	}
      }
    }
  }
  /*//
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      cout<<sp[i][j];
    }
    cout<<endl;
  }
  //*/
  priority_queue<sta> q;
  q.push(sta(sy,sx,0,0));
  dp[sy][sx][0]=0;
  int ax[]={1,-1,0,0};
  int ay[]={0,0,1,-1};
  while(!q.empty()){
    sta s=q.top();q.pop();
    if(dp[s.y][s.x][s.b]<s.d) continue;
    //cout<<s.y<<" "<<s.x<<" "<<s.b<<" "<<s.d<<endl;
    for(int k=0;k<4;k++){
      int ny=s.y+ay[k],nx=s.x+ax[k],nb=s.b,nd=s.d+sp[s.y][s.x];
      if(!in(ny,nx)) continue;
      if(st[ny][nx]=='#') continue;
      if(m.count(P(ny,nx))) nb|=1<<m[P(ny,nx)];
      if(dp[ny][nx][nb]<0||dp[ny][nx][nb]>nd){
	dp[ny][nx][nb]=nd;
	q.push(sta(ny,nx,nb,nd));
      }
    }
  }
  cout<<dp[gy][gx][(1<<n)-1]<<endl;
  return 0;
}

Measured memory_bytes: 4900
/*input
1000000000000000 1000000000000000 1000000000000000
*/

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

int main() {
    ll x, k, d;
    cin>> x >> k >> d;

    x = abs(x);
    if (k%2 == 1) x = abs(x-d), --k;
    ll ans = x%(2*d);
    auto f = [](ll a, ll b){ return abs(a) < abs(b);};
    ans = min(ans, ans-2*d, f);
    if ((x-ans)/d > k) ans = x-k*d;
    // ans = max(ans, x-k*d);
    ans = abs(ans);
    cout << ans << endl;
}

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

int main(){
  
  string S;
  cin >> S;
  
  for(int i = 0; i < S.size(); i++){
    if(S[i] == '1'){
      cout << '9';
    }else if(S[i] == '9'){
      cout << '1';
    }else{
      cout << S[i];
    }
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 3624
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int N;
int F[100][14];
int P[100][15];

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

    int N;scanf("%d",&N);
    int array[210];
    for(int i=0;i<N;i++){
        scanf("%d",&array[i]);
    }

    bool isOk=true;
    int count=0;
    while(isOk){
        for(int i=0;i<N;i++){
            if(array[i]%2!=0){
                isOk=false;
                break;
            }
            array[i]=array[i]/2;
        }
        count++;
    }

    printf("%d\n",count-1);
    return 0;
}

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

#define QSIZE 100000

struct _q{
  int  t;
  char n[12];
} q[QSIZE];
int qs=0,qe=0;

void enqueue(struct _q *ptq){
  q[qe].t=ptq->t;
  strncpy(q[qe].n,ptq->n,10);
  qe++; if (qe==QSIZE) qe=0;
  return;
}

struct _q *dequeue(){
  int qc=qs;
  if (qs==qe) return NULL;
  qs++; if (qs==QSIZE) qs=0;
  return &q[qc];
}

int main(){
  int N,Q,t=0;
  struct _q tq, *ptq;
  scanf("%d %d\n",&N,&Q);
  while(scanf("%s %d\n",tq.n,&tq.t) != EOF){
    if(tq.t>Q){
      t+=Q; tq.t-=Q;
      enqueue(&tq);
    }
    else{
      t+=tq.t;
      printf("%s %d\n",tq.n, t);
    }
  }

  ptq = &tq;
  while ((ptq=dequeue()) != NULL) {
    if(ptq->t>Q){
      t+=Q;
      ptq->t-=Q;
      enqueue(ptq);
    }
    else{
      t+=ptq->t;
      printf("%s %d\n",ptq->n, t);
    }
  }
  return 0;
}

Measured memory_bytes: 2176
#include <iostream>
#include <vector>
#include <map>
#include <queue>
#include <string>
#include <algorithm>

using namespace std;
typedef pair<int, int> P;

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

unsigned long long int lcm(unsigned long long int a, unsigned long long int b)
{
	return(a / gcd(a, b) * b);
}

void solve()
{
	int N;
	cin >> N;
	vector<unsigned long long int > T(N);
	unsigned long long int ans = 1;
	for (int i = 0; i < N; ++i)
	{
		cin >> T[i];
		ans = lcm(ans, T[i]);
	}
	cout << ans << endl;
}

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

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

using namespace std;

typedef long long ll;

// i: (x+y) %3, j: color
int cnt[3][31];

int main(){
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  int N, C; cin >> N >> C;
  int d[C+1][C+1];
  for(int i=1;i<=C;i++){
    for(int j=1;j<=C;j++){
      cin >> d[i][j];
    }
  }
  for(int i=1;i<=N;i++){
    for(int j=1;j<=N;j++){
      int c; cin >> c;
      cnt[(i + j) %3][c]++;
    }
  }
  int ans = 1000000000;
  for(int a=1;a<=C;a++){
    for(int b=1;b<=C;b++){
      if(a == b) continue;
      for(int c=1;c<=C;c++){
        if(a == c || b == c) continue;
        int sum = 0;
        // (x + y) %3 == 0
        for(int j=1;j<=C;j++){
          sum += cnt[0][j] * d[j][a];
        }
        for(int j=1;j<=C;j++){
          sum += cnt[1][j] * d[j][b];
        }
        for(int j=1;j<=C;j++){
          sum += cnt[2][j] * d[j][c];
        }
        ans = min(sum, ans);
      }
    }
  }
  cout << ans << endl;
}

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

using namespace std;

const int MAXN = 1e2 + 5;

int n, m;
int a[MAXN][MAXN];

void read_input()
{
	scanf("%d %d", &n, &m);

	for(int i = 0; i < n; i++)
	{
		for(int j = 0; j < m; j++)
		{
			scanf("%d", &a[i][j]);
			a[i][j]--;
		}
		sort(a[i], a[i] + m);
	}
}
bool used[MAXN];
int par[MAXN];

int k;
vector <int> graph[MAXN];
int tr[MAXN];

bool try_kuhn(int p)
{
	if(used[p]) return false;
	used[p] = true;

	int z = graph[p].size();
	for(int i = 0; i < z; i++)
	{
		int to = graph[p][i];
		if(par[to] == -1 || try_kuhn(par[to]))
		{
			par[to] = p;
			tr[p] = to;
			return true;
		}
	}
	return false;
}

bool mark[MAXN][MAXN];
int b1[MAXN][MAXN], b2[MAXN][MAXN];

void solve()
{
	bool fl = true;
	for(int z = 0; z < m; z++)
	{
        memset(par, -1, sizeof(par));

		for(int i = 0; i < n; i++)
        {
            graph[i].clear();
            for(int j = 0; j < m; j++)
            {
                if(!mark[i][j])
                {
                    int temp = a[i][j] / m;
                    graph[i].push_back(temp);
                }
            }
        }

		for(int j = 0; j < n; j++)
		{
			memset(used, 0, sizeof(used));
			fl &= try_kuhn(j);
		}
		for(int i = 0; i < n; i++)
		{
			int temp = tr[i];

			for(int j = 0; j < m; j++)
            {
                if(a[i][j] / m == temp && !mark[i][j])
                {
                    mark[i][j] = true;
                    b1[i][z] = a[i][j];
                    break;
                }
            }
		}
	}

	if(!fl)
	{
	    printf("DSA");
		return;
	}
	for(int i = 0; i < n; i++)
	{
		for(int j = 0; j < m; j++)
		{
			printf("%d ", b1[i][j] + 1);
			b2[j][i] = b1[i][j] + 1;
		}
		printf("\n");
	}
	for(int i = 0; i < m; i++)
	{
		sort(b2[i], b2[i] + n);
	}

	for(int i = 0; i < n; i++)
	{
		for(int j = 0; j < m; j++)
		{
			printf("%d ", b2[j][i]);
		}
		printf("\n");
	}

}
int main()
{
	read_input();
	solve();

	return 0;
}


Measured memory_bytes: 512
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>

#define REP(i,p,n) for(int i=p;i<n;++i)
#define rep(i,n) REP(i,0,n)

using namespace std;

int main()
{
    string s;
    cin >> s;
    rep(i, 19)
    {
        if(s[i] == ',')
        {
            s[i] = ' ';
        }
    }
    cout << s << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define HAIRETU(N,A) for(int i=0;i<N;i++) cin >>A[i]
using namespace std;

int main(){
    int N, Y;
    cin >> N >> Y;
    int a = -1, b = -1, c = -1;
    for (int i = 0; i <= N; i++) {
        for (int j = 0; j <= N; j++) {
            int k = N - i - j;
            if (10000*i+5000*j+1000*k==Y && 0 <= k && k <= N) {
                a = i;
                b = j;
                c = k;
            }
        }
    }
    cout << a << ' ' << b << ' ' << c << endl;

    return 0;
}



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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, int> P;
typedef pair<ll, pair<ll, ll> > P3;

const ll MOD = ll(1e9 + 7);
const ll LLINF = LLONG_MAX;
const int IINF = INT_MAX;
const int MAX_N = int(1e5) + 5;
const double EPS = 1e-8;
int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
#define SORT(v) sort((v).begin(), (v).end())
#define SORTR(v) sort((v).rbegin(), (v).rend())
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (ll i = m; i < n; i++)

int dp[105][10005];

int main() {
    int n, W, V = 0, v[105], w[105];
    cin >> n >> W;
    REP(i, n) {
        cin >> v[i] >> w[i];
        V += v[i];
    }
    REP(i, n + 1) fill(dp[i], dp[i] + 10005, IINF/2);
    dp[0][0] = 0;
    REP(i, n) {
        REP(j, V + 1) {
            if (j >= v[i]) dp[i+1][j] = min(dp[i+1][j],dp[i][j-v[i]]+w[i]);
            dp[i+1][j] = min(dp[i+1][j],dp[i][j]);
        }
    }
    REPR(i,V){
        if(dp[n][i]<=W){
            cout << i << endl;
            break;
        }
    }
    return 0;
}



Measured memory_bytes: 7040
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define LLINF 9223372036854775807
#define MOD ll(1e9+7)


int main(){
    int n;
    cin >> n;
    vector<double> p(n);
    for(int i = 0; i < n; i++){
        cin >> p[i];
    }
    vector<vector<double>> dp(n+1,vector<double>(n+1,0.0));
    dp[0][0] = 1.0;
    for(int i = 1; i <= n; i++){
        for(int j = 0; j < i+1; j++){
            if(j!=0){
                dp[i][j] = dp[i-1][j]*(1-p[i-1])+dp[i-1][j-1]*p[i-1];
            }else{
                dp[i][j] = dp[i-1][0]*(1-p[i-1]);
            }
        }
    }
    double ans = 0;
    for(int i = n/2+1; i <= n; i++){
        ans += dp[n][i];
    }
    printf("%.10f\n",ans );
    return 0;
}


Measured memory_bytes: 70656
#動的計画法
#B 問題 - Frog 2
n, k = list(map(int,input().split()))
h = list(map(int,input().split()))
dp = [float("INF")]*(n)
dp[0] = 0
for i in range(1,n):
    for j in range(min(k,i)+1):
        dp[i] = min(dp[i],(dp[i-j]+abs(h[i]-h[i-j])))
    
print(dp[n-1])

Measured memory_bytes: 55264
#include<stdio.h>

int main(void)
{
   long long int n,q,a[1000001],b[1000001],c[1000001],i,j,sum[1000001]={0},wa=0;
  
  scanf("%lld", &n);
  
  for(i=0;i<n;i++){
    scanf("%lld", &a[i]);
    sum[a[i]]++;
    wa+=a[i];
  }
  
    scanf("%lld", &q);
  
  for(i=0;i<q;i++){
    scanf("%lld%lld", &b[i],&c[i]);
    if(b[i]>c[i]){
      wa = wa - (b[i] - c[i])*sum[b[i]];
      sum[c[i]]+=sum[b[i]];
      sum[b[i]] = 0;
    }else{
      wa = wa + (c[i] - b[i])*sum[b[i]];
      sum[c[i]]+=sum[b[i]];
      sum[b[i]] = 0;
    }
    printf("%lld\n", wa);
  }
  
  return 0;
}


Measured memory_bytes: 11872
object Main extends App {
  val src = io.Source.stdin.getLines.map(_.split(" ").map(_.toInt).toList)

  for (List(rows, elems) <- src if rows != 0)
    println(src.take(rows).toList
      .transpose.map(_.sum).zip(Stream from 1)
      .sortWith((tup1, tup2) => tup1._1 > tup2._1)
      .unzip._2.mkString(" "))
}



Measured memory_bytes: 72504
#include <bits/stdc++.h>
#define rep(i, n) for(int i= 0; i < (n); i++)
using ll= long long int;
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
ll mod= 1e9 + 7;


int main() {
  int k;
  cin >> k;
  rep(i,k){cout << "ACL";}
  cout << endl;
}

Measured memory_bytes: 3556
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++)
        cin>>a[i];
      //  cout<<count(a,a+n,1)<<endl;
    if(count(a,a+n,1)==0)
    {
        cout<<-1;
        return 0;
    }
    int i=0;
    int p=0;
    while(p!=n)
    {
        i++;
        p=find(a+p,a+n,i)-a;

    }
    //cout<<i<<endl;
    cout<<n-i+1;
    return 0;
}


Measured memory_bytes: 1024
#include<stdio.h>
#include<string.h>
#include<math.h>
int main(void)
{
	int a,s,d;
	char z[2];
	scanf("%s",z);
	if(z[0]=='a'||z[0]=='i'||z[0]=='u'||z[0]=='e'||z[0]=='o')
		printf("vowel\n");
	else
		printf("consonant\n");
	return 0;
}

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

using namespace std;

int main(void) {
  int n, k;
  cin >> n >> k;
  auto sn = vector<bool>(n, false);
  for (int i = 0; i < k; i++) {
    int d;
    cin >> d;
    for (int j = 0; j < d; j++) {
      int a;
      cin >> a;
      sn[a-1] = true;
    }
  }
  int res = 0;
  for (int i = 0; i < n; i++) {
    if (!sn[i]) res++;
  }
  cout << res << endl;
}


Measured memory_bytes: 3632
import java.util.Scanner;
import java.util.Arrays;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		
		int cnt = 0;
		for (int i = 0; i < S.length(); i++) {
			if (S.charAt(i) == '1') {
				cnt++;
			}
		}
				System.out.println(cnt);
			
			
		
	}
}	

Measured memory_bytes: 21844
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <array>
#include <unordered_set>
#include <unordered_map>
#include <map>
#include <math.h>
#include <queue>
#include <stdio.h>
#include <sstream>
using namespace std;
using i64 = int64_t;
#define rep(i, n) for(int i=0;i<n;++i)
#define rep2(i, x, n) for(int i=x;i<n;++i)

int main()
{        
    int n;
    cin >> n;
    vector<int> a(n);
    vector<int> b(n);
    vector<int> c(n);
    vector<int> d(n);
    rep(i,n) cin >> a[i] >> b[i];
    rep(i,n) cin >> c[i] >> d[i];

    vector<vector<int>> gred(n);
    vector<vector<int>> gblue(n);

    rep(i,n)
        rep(j,n)
            if(a[i]<c[j] && b[i]<d[j])
            {
                gred[i].push_back(j);
                gblue[j].push_back(i);
            }

    vector<int> sred(n);
    vector<int> sblue(n);
    int rcnt = 0;
    rep(i,n)
    {
        sred[i] = 0;
        for(auto& idx:gred[i])
            sred[i] += (int)gblue[idx].size();
        if(sred[i]>0) rcnt++;

        sblue[i] = 0;
        for(auto& idx:gblue[i])
            sblue[i] += (int)gred[idx].size();
    }

    int pair_cnt = 0;
    while(rcnt>0)
    {
        int min_ridx = 0;
        int min_cnt = 1000;
        rcnt = 0;

        rep(i,n)
        {
            int tmp_cnt = gred[i].size();
            if(tmp_cnt==0) continue;
            if(tmp_cnt < min_cnt)
            {
                min_cnt = tmp_cnt;
                min_ridx = i;
            }
            rcnt++;
        }
        if(rcnt==0) break;

        int min_bidx = 0;
        int min_bs = 100000;
        for(auto& idx:gred[min_ridx])
        {
            int tmp_score = sblue[idx];
            if(tmp_score < min_bs)
            {
                min_bs = tmp_score;
                min_bidx = idx;
            }
        }        

        int rsize = gred[min_ridx].size();
        int bsize = gblue[min_bidx].size();

        for(auto& idx:gred[min_ridx])
        {
            auto itr = find(gblue[idx].begin(),gblue[idx].end(),min_ridx);
            if(itr==gblue[idx].end()) continue;
            gblue[idx].erase(itr);
            sblue[idx] -= rsize;
        }
        for(auto& idx:gblue[min_bidx])
        {
            auto itr = find(gred[idx].begin(),gred[idx].end(),min_bidx);
            if(itr==gred[idx].end()) continue;
            gred[idx].erase(itr);
            sred[idx] -= bsize;
        }
        gred[min_ridx].clear();
        sred[min_ridx] = 0;
        gblue[min_bidx].clear();
        sblue[min_bidx] = 0;

        ++pair_cnt;
    }

    cout << pair_cnt << endl;
    return 0;
}

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

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=2019
    L,R=MI()
    
    if R-L>=2019:
        print(0)
        exit()
    a=L%mod
    b=R%mod
    if b<=a:
        print(0)
        exit()
    
    ans=mod
    for i in range(a,b+1):
        for j in range(i+1,b+1):
            temp=(i*j)%mod
            ans=min(ans,temp)
            
    print(ans)
            

main()


Measured memory_bytes: 64376
S = input()
T = input()
# print(S, T)

# NUMBER_OF_ALPHABETS = 26
# S_length = len(S)
# if S_length < NUMBER_OF_ALPHABETS:
#     print('Yes')
#     exit()

ALPHABETS = 'abcdefghijklmnopqrstuvwxyz'
answer = 'Yes'
for alphabet in ALPHABETS:
    i = S.find(alphabet)
    if i == -1: continue

    replaced_S = S.replace(S[i], '')
    replaced_T = T.replace(T[i], '')
    # print(replaced_S, replaced_T)
    if len(replaced_S) != len(replaced_T):
        answer = 'No'
        break
print(answer)

# for i in range(S_length):
#     replaced_S = S.replace(S[i], '')
#     replaced_T = T.replace(T[i], '')
#     if len(replaced_S) != len(replaced_T):
#         answer = 'No'
#         break
# print(answer)

# 同一文字は同一位置でなければならない
# 未使用文字が存在する場合: スワップしながら可能か？
# 未使用文字が存在しない場合: 他文字と被るかどうか？


Measured memory_bytes: 4160
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,k) for(int i = j;i <= k;++i)
#define repp(i,j,k) for(int i = j;i >= k;--i)
#define ll long long
void gi(int &sum){
    sum = 0;char c = getchar();bool flag = true;
    while(c < '0' || c > '9') {if(c == '-') flag = false;c = getchar();}
    while(c >= '0' && c <= '9') sum = sum * 10 + c - 48,c = getchar();
    if(!flag) sum = -sum;
}
int n,a,b;
int ans[201000];
void work(int x,int y,int l,int r,int n,int det) {
//	printf("#%d %d %d %d %d\n",l,r,x,y,det);
	ans[l] = x^det; ans[r] = y^det;
	if(n == 1) {
		if(x == 0) ans[l+2] = 3^det,ans[l+1] = 2^(y==1?0:3)^det;
		else if(x == 2) ans[l+2] = 1^det,ans[l+1] = 3^(y==0?0:3)^det;
		else if(x == 3) ans[l+2] = 0^det,ans[l+1] = 1^(y==2?0:3)^det;
		else if(x == 1) ans[l+2] = 2^det,ans[l+1] = (y==3?0:3)^det;
		return;
	}
	int f1 = (x>>n&1) , f2 = (y>>n&1) , toy;
	toy = (f1==f2) ? y : y^(1<<n);
	repp(i,n-1,0) if( (toy^(1<<i)) != x ) {toy = y ^ (1<<i);break;} 
	if( f1^f2 ) {
		work( x-(f1?(1<<n):0) , toy - (f2?(1<<n):0) , l , l+(1<<n)-1 , n-1 , det+(f1?(1<<n):0) );
		work( toy-(f2?(1<<n):0) , y - (f2?(1<<n):0) , l+(1<<n) , r , n-1 , det+(f2?(1<<n):0) );
	}
	else {
		work( x-(f1?(1<<n):0) , y - (f2?(1<<n):0) , l+(1<<n) , r , n-1 , det+(f1?(1<<n):0) );
		work( x-(f1?(1<<n):0) , (det^ans[l+(1<<n)+1])-(f1?(1<<n):0) , l+1 , l+(1<<n) , n-1 , det+(f1?0:(1<<n)) );
	}
}
int main(){
	gi(n); gi(a); gi(b);
	if(n == 1) {
		printf("YES\n");
		printf("%d %d\n",a,b);
		return 0;
	}
	a ^= b;int cnt = 0;rep(i,0,n-1) cnt += a>>i&1;
//	printf("*%d\n",cnt);
	if(!(cnt&1)) {printf("NO\n");return 0;} a ^= b;
	work(a,b,1,(1<<n),n-1,0);
	printf("YES\n");
	rep(i,1,(1<<n)) printf("%d ",ans[i]);
	return 0;
}

Measured memory_bytes: 1536
#include <iostream>

using namespace std;

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

    int xt = -1, yt = -1, zt = -1;
    for (int x = 0; x <= N; x++) {
        for (int y = 0; y <= N-x; y++) {
            int z = N - x - y;
            int otoshidama = 10000 * x + 5000 * y + 1000 * z;
            if (otoshidama == Y) {
                xt = x;
                yt = y;
                zt = z;
            }
        }
    }

    cout << xt << " " << yt << " " << zt << "\n";
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
import java.lang.Math;
public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        while(true){
            int n = sc.nextInt();
            int r = sc.nextInt();
            if(n==0&&r==0){
                break;
            }
            char[] s_char = new char [n];
            for(int i=0;i<n;i++){
                s_char[i] ='0';
                s_char[i]+=i+1;
            }
            String s = String.valueOf(s_char);
            for(int i=0;i<r;i++){
                int p = sc.nextInt();
                int c = sc.nextInt();
                String s1 = s.substring(0,p-1);
                String s2 = s.substring(p-1,p-1+c);
                String s3 = s.substring(p-1+c,s.length());
                s = s2+s1+s3;
                //System.out.println(s);
            }
            //System.out.println(s);
            System.out.println(n+1-(s.charAt(0)-'0'));
        }
        sc.close();
    }
}



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

using namespace std;
using ll = long long;
using v1 = vector<int>;
using vl = vector<long long>;
using v2 = vector<vector<int>>;
using v3 = vector<vector<char>>;

ll gcd(ll a, ll b){
    if(a % b == 0) return b;
    else return gcd(b, a%b);
}
ll lcm(ll a, ll b){
 return a/gcd(a, b)*b;
}

int main(){
    ll a, b;
    cin >> a >> b;
    ll ans = lcm(a, b);
    cout << ans << endl;
 }

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

int main() {
  string S;
  cin >> S;
  if(S[0] == S[1] && S[1] != S[2] && S[2] == S[3]){
  cout << "Yes" << endl;
  }

  
  else if(S[0] == S[2] && S[2] != S[1] && S[1] == S[3]){
cout << "Yes" << endl;
  }

  
  else if(S[0] == S[3] && S[3] != S[1] && S[1] == S[2]){
    cout << "Yes" << endl;
  }
  
  else{
    cout << "No" << endl;
  }
 
}


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

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define watch(a) { std::cout << #a << " = " << a << "\n"; }
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }
template<class T, class V> istream& operator>> (istream& ist, pair<T, V>& p) { return ist >> p.first >> p.second; }
template<class T> ostream& operator<< (ostream& ost, pair<T, T>& p) { return ost << p.first << ", " << p.second; }
template<class T> istream& operator>> (istream& ist, vector<T>& vs) { for(auto& e: vs) ist >> e; return ist; }

typedef long long ll;
int const inf = INT_MAX / 2;

ll level[55];

ll F(int N) {
  auto& ret = level[N];
  if (ret) return ret;
  if (N == 0) return ret = 1;
  return ret = F(N - 1) * 2 + 3;
}

ll dfs(int N, ll X) {
  if (N == 0) {
    assert(X == 1);
    return 1;
  }
  if (X == 1) {
    return 0;
  }

  auto cnt_N_1 = F(N - 1);
  if (X <= cnt_N_1 + 1) {
    return dfs(N - 1, X - 1);
  }
  else if (X == 2 + cnt_N_1) {
    return dfs(N - 1, cnt_N_1) + 1;
  }
  else if (X <= 2 + 2 * cnt_N_1) {
    return dfs(N - 1, cnt_N_1) + dfs(N - 1, X - 2 - cnt_N_1) + 1;
  }

  return dfs(N - 1, cnt_N_1) * 2 + 1;
}

int main() {
  /*
    5 .. B
    4 .. (N - 1)
    3 .. P
    2 .. (N - 1)
    1 .. B

    X層目が 1 ~ 5 のどのブロックにあるかを決める。
    これを N 回繰り返して、...
  */
  int N; ll X; cin >> N >> X;
  cout << dfs(N, X) << "\n";
}


Measured memory_bytes: 256
#include <iostream>

void doAllProcess() {
	for(int i = 1; i <= 9; ++i)
		for(int j = 1; j <= 9; ++j)
			std::cout << i << "x" << j << "=" << (i*j) << std::endl;
}


auto main() -> int {
	doAllProcess();
	return 0;
}


Measured memory_bytes: 3088
#include <bits/stdc++.h>
#define f(i,j,k) for(int i=j;i<k;i++)
#define f2(i,j,k) for(int i=j;i>k;i--)
using namespace std;
int main(){
    long long n;
    cin>>n;
    map <long long,long long> b;
    long long a[n],ans=0;
    f(i,0,n){
        cin>>a[i];
        ans+=b[a[i]];
        b[a[i]]++;
    }
    f(i,0,n){
        cout<<ans-b[a[i]]+1<<endl;
    }
    return 0;
}


Measured memory_bytes: 13096
x,y=map(int,input().split())
mod=10**9+7

def modinv(a, mod=10**9+7):
    return pow(a, mod-2, mod)
def mod_combinations_count(n, r, mod):
    r = min(r, n-r)
    res = 1
    for i in range(r):
        res = res * (n - i) * modinv(i+1, mod) % mod
    return res

if (x+y)%3!=0:
    print(0)
else:
    n=(x+y)//3
    m=(-x+2*y)//3
    if n<0 or m<0 or n<m:
        print(0)
        exit()
    else:
        print(mod_combinations_count(n,m,mod)%mod)


Measured memory_bytes: 3188
// This is the start of shubhams template//
#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
#define int long long int
void input(){
#ifndef ONLINE_JUDGE 
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout); 
#endif
}
#define vll vector<int>
#define pb push_back
#define pll pair<int,int>
#define mp(a,b) make_pair(a,b)
#define ff first
#define ss second
#define INF LONG_LONG_MAX
#define mod 1000000007
#define all(x) x.begin(),x.end()
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define cases int t; cin>>t; while(t--)
#define array(a,n) vll a(n); rep(i,0,n) cin>>a[i];
#define sortall(a) sort(a.begin(),a.end())
#define printall(a) rep(i,0,a.size()) cout<<a[i]<<" "; cout<<endl;
//this is the end of shubhams template //

int32_t main() 
{ 
	input();
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
   	int curr=0,k;
   	cin>>k;
   	
   	rep(i,1,1000001)
   	{
   		curr*=10;
   		curr+=7;
   		curr=curr%k;
   		if(curr==0)
   		{
   			cout<<i<<endl;
   			return 0;
   		}
   	}
   	cout<<-1<<endl;
    return 0; 
} 

Measured memory_bytes: 3620
#include <stdio.h>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef vector<vector<int>> v2int;
typedef vector<vector<vector<int>>> v3int;
typedef vector<ll> vll;
typedef vector<vector<ll>> v2ll;
typedef vector<vector<vector<ll>>> v3ll;
typedef list<int> liint;
typedef pair<int, int> pint;
typedef vector<pair<int, int>> vpint;
typedef vector<pair<ll, ll>> vpll;
typedef vector<pair<ll, int>> vpll_int;
typedef vector<pair<int, ll>> vpint_ll;
typedef set<pair<int, int>> spint;
typedef set<pair<ll, int>> spll;
typedef unordered_map<int, unordered_set<int>> Graph;
const int INF = int(2e9);
const ll LINF = ll(2e9) * ll(2e9);
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b) { a > b ? : a = b; }
template<class T, class C> void chmin(T& a, C b) { a < b ? : a = b; }

ll ans = 0;

bool is_ok(int H, int W, int K, unordered_set<int>& red_row_col, vector<vector<char>>& field) {
    int cnt = 0;
    rep(i, H) {
        if (red_row_col.count(i) != 0) continue;
        rep(j, W) {
            if (red_row_col.count(H + j) != 0) continue;
            if (field[i][j] == '#') cnt++;
        }
    }
    if (cnt == K) return true;
    return false;
}

void calc(int H, int W, int K, unordered_set<int>& red_row_col, int t , vector<vector<char>>& field) {
    //cout << "red_row:";
    //for (auto& i : red_row_col) {
    //    cout << i << " ";
    //}
    //cout << endl;


    //cout << endl;
    if (is_ok(H, W, K, red_row_col, field) == true)
        ans++;
    REP(i, t + 1,  H + W) {
        if (red_row_col.count(i) == 0) {
            auto new_red_row_col = red_row_col;
            new_red_row_col.insert(i);
            calc(H, W, K, new_red_row_col, i, field);
        }
    }
    //rep(j, W) {
    //    if (red_col.count(j) == 0) {
    //        auto new_red_row = red_row;
    //        auto new_red_col = red_col;
    //        new_red_col.insert(j);
    //        calc(H, W, K, new_red_row, new_red_col, field);
    //    }
    //}
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int H, W, K;
    cin >> H >> W >> K;
    vector<vector<char>> field(H, vector<char>(W));
    rep(i, H) rep(j, W) cin >> field[i][j];
    unordered_set<int> red_row_col;
    calc(H, W, K, red_row_col, -1, field);

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

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
#define re register
int p[100100],bp[100100],q[100100],bq[100100],q1[100100],q2[100100],la[200100],tot=2,cnt=1;
struct eg{int to,c,nx;}e[1000100];
inline void addE(re int a,re int b,re int c,re int c1)
{
	e[++cnt]=(eg){b,c,la[a]};la[a]=cnt;
	e[++cnt]=(eg){a,c1,la[b]};la[b]=cnt;
}
int d[200100],qq[200100],cur[200100];
bool bfs()
{
	re int ta=1;
	memcpy(cur,la,(tot+1)<<2);
	memset(d,0,(tot+1)<<2);
	qq[1]=2;d[2]=1;
	for(re int i=1;i<=ta;i++)
	{
		re int x=qq[i];
		for(re int j=la[x];j;j=e[j].nx)if(e[j^1].c&&!d[e[j].to])
		{
			d[e[j].to]=d[x]+1;
			if(e[j].to==1)return 1;
			else qq[++ta]=e[j].to;
		}
	}
	return 0;
}
int dfs(re int a,re int fl)
{
	if(a==2)return fl;
	re int fa=fl;
	for(re int&i=cur[a];i;i=e[i].nx)if(e[i].c&&d[e[i].to]==d[a]-1)
	{
		re int c=dfs(e[i].to,min(fa,e[i].c));
		e[i].c-=c;e[i^1].c+=c;fa-=c;
		if(!fa)return fl;
	}
	return fl-fa;
}
int dinic()
{
	re int ans=0;
	while(bfs())ans+=dfs(1,1<<30);
	return ans;
}
int main()
{
	re int n;
	scanf("%d",&n);
	for(re int i=1;i<=n;i++)scanf("%d",&p[i]),p[i]++,bp[p[i]]=i;
	for(re int i=1;i<=n;i++)scanf("%d",&q[i]),q[i]++,bq[q[i]]=i;
	for(re int i=1;i<=n;i++)
	{
		if(!q1[i])
		{
			q1[i]=++tot;
			for(re int j=p[i];j!=i;j=p[j])q1[j]=tot;
		}if(!q2[i])
		{
			q2[i]=++tot;
			for(re int j=q[i];j!=i;j=q[j])q2[j]=tot;
		}
		if(p[i]==i)addE(1,q1[i],1<<30,0);
		if(q[i]==i)addE(q2[i],2,1<<30,0);
		addE(q1[i],q2[i],1,bp[i]==bq[i]);
	}
	printf("%d",n-dinic());
}

Measured memory_bytes: 12160
//#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast,no-stack-protector") 
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>


#define ll long long
//#define int ll
#define ull unsigned long long
#define ld long double
#define rep(i, l, r) for (int i = l; i < r; i++)
#define repb(i, r, l) for (int i = r; i > l; i--)
#define sz(a) (int)a.size()
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define pb push_back
#define mp(a, b) make_pair(a, b)
#define ret(a) {cout << a; exit(0);}

using namespace std;

mt19937 mrand(random_device{}()); 
const ll mod=1000000007;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b,ll mod) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}

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

const int N = 600 + 1;

int n , m , k , q;
ld dp[N] , dp1[N];
vector < int > g[N];

int Bu = -1 , Bv = -1 , u[N*N] , v[N*N];
ld ans = 0;
void solve(){
	dp1[n] = 0; 
	for(int i = n - 1 ; i != 0; i--){
		ld C = sz(g[i]) - (ll)(i == Bu);
		dp1[i] = 0;
		for(auto to : g[i]){
			if(Bu == i and to == Bv)
				continue;
			dp1[i] += dp1[to];
		}
	    dp1[i] /= C;
	    dp1[i]++;
	}
	ans = min(ans, dp1[1]);
}

main(){

	ios::sync_with_stdio(0); cin.tie(0);cout.tie(0);
	cin >> n >> m;
    for(int i = 1 ; i <= m; i++){
		cin >> u[i] >> v[i];
		g[u[i]].pb(v[i]);
	}
	dp[n] = 0; 
	for(int i = n - 1 ; i != 0; i--){
		ld C = sz(g[i]) - (ll)(i == Bu);
		dp[i] = 0;
		for(auto to : g[i]){
			if(Bu == i and to == Bv)
				continue;
			dp[i] += dp[to];
		}
	    dp[i] /= C;
	    dp[i]++;
	}
	ans = dp[1];
	
	for(int i = 1 ; i < n; i++){
		if(sz(g[i]) > 1){
			int best = -1;ld val = -1;
			for(auto to : g[i])
				if(dp[to] > val)
					val = dp[to] , best = to;
			Bu = i , Bv = best,solve();
		}
	}
	cout << setprecision(9) << fixed <<  ans;
}

Measured memory_bytes: 2944