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

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

#define p_ary(ary,a,b,i) do { cout << "["; for (int (i) = (a);(i) < (b);++(i)) cout << ary[(i)] << ((b)-1 == (i) ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)

struct edge {
    int to,rev;
    ll cap;
};
 
vector<edge> G[210];
bool used[210];
 
void add_edge(int from,int to,ll cap) {
    G[from].push_back((edge){to,(int)G[to].size(),cap});
    G[to].push_back((edge){from,(int)G[from].size()-1,0});
}
 
ll dfs(int v,int t,ll f) {
    if (v == t) return f;
    used[v] = true;
    for (int i = 0;i < G[v].size();++i) {
        edge &e = G[v][i];
        if (!used[e.to] && e.cap > 0) {
            ll d = dfs(e.to,t,min(f,e.cap));
            if (d > 0) {
                e.cap -= d;
                G[e.to][e.rev].cap += d;
                return d;
            }
        }
    }
    return 0;
}
 
ll max_flow(int s,int t) {
    ll flow = 0;
    for (;;) {
        memset(used,0,sizeof(used));
        ll f = dfs(s,t,INT64_MAX);
        if (f == 0) return flow;
        flow += f;
    }
}

int main() {
    int h,w;
    cin >> h >> w;
    for (int i = 0;i < h;++i) {
        string a;
        cin >> a;
        for (int j = 0;j < w;++j) {
            if (a[j] == 'o') {
                add_edge(i,j+100,1);
                add_edge(j+100,i,1);
            } else if (a[j] == 'S') {
                add_edge(200,i,100000);
                add_edge(200,j+100,100000);
            } else if (a[j] == 'T') {
                add_edge(i,201,100000);
                add_edge(j+100,201,100000);
            }
        }
    }
    ll ans = max_flow(200,201);
    if (ans < 100000) cout << ans << endl;
    else cout << "-1" << endl;
    return 0;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
int main( ){
    string a, b;
    cin >> a;
    cin >> b;
    int n = (int)a.length() + 1;
    int m = (int)b.length() + 1;
    int dp[n] [m];
    for(int i = 0; i < n; i++){
        for(int j = 0; j < m; j++){
            if(i == 0 || j == 0)
                dp[i] [j] = 0;
            else if(a[i - 1] == b[j - 1])
                dp[i] [j] = dp[i - 1] [j - 1] + 1;
            else
                dp[i] [j] = max(dp[i] [j - 1], dp[i - 1] [j]); 
        }
    }
    string ans;
    int i = n - 1, j = m - 1;
    while(i != 0 && j != 0){
        if(dp[i] [j] > dp[i - 1] [j] && dp[i] [j] > dp[i] [j - 1]){
            --i;
            --j;
            ans += a[i];
        }else if(dp[i] [j] == dp[i - 1] [j])
            --i;
        else if(dp[i] [j] == dp[i] [j - 1])
            --j;
    }
    reverse(ans.begin(), ans.end());
    cout << ((int)ans.size() == 0 ? " " : ans ) << '\n';
    return 0;
}

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

using namespace std;

int main(void) {
	int a, b, c, x;
	cin >> a >> b >> c >> x;
	int count = 0;
	for (int i = 0; i <= a; i++) {
		for (int j = 0; j <= b; j++) {
			for (int k = 0; k <= c; k++) {
				if (x == 500 * i + 100 * j + 50 * k) {
					count++;
					break;
				}
			}
		}
	}
	cout << count;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
using namespace std;
constexpr int mod=1e9+7;
using P=pair<int,int>;
int dx[]={0,1,-1,0},dy[]={1,0,0,-1};
signed main(){
    int h,w;
    string s[20];
    cin>>h>>w;
    for(int i=0;i<h;i++)
        cin>>s[i];
    int ans=0;
    for(int sx=0;sx<h;sx++){
        for(int sy=0;sy<w;sy++){
            for(int gx=0;gx<h;gx++){
                for(int gy=0;gy<w;gy++){
                    if(sx==gx&&sy==gy||s[sx][sy]=='#'||s[gx][gy]=='#')
                        continue;
                    int dist[20][20];
                    for(int i=0;i<h;i++)
                        for(int j=0;j<w;j++)
                            dist[i][j]=-1;
                    dist[sx][sy]=0;
                    queue<P>que;
                    que.emplace(sx,sy);
                    while(!que.empty()){
                        P p=que.front();
                        que.pop();
                        for(int i=0;i<4;i++){
                            int nx=p.first+dx[i],ny=p.second+dy[i];
                            if(0<=nx&&nx<h&&0<=ny&&ny<w&&s[nx][ny]=='.'&&dist[nx][ny]==-1){
                                que.emplace(nx,ny);
                                dist[nx][ny]=dist[p.first][p.second]+1;
                            }
                        }
                    }
                    ans=max(ans,dist[gx][gy]);
                }
            }
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 384
import heapq

N,M=map(int,input().split())
AB=[list(map(int,input().split())) for i in range(N)]
L=[[] for i in range(M+1)]

for i in range(N):
    if AB[i][0]<=M:
        L[AB[i][0]].append(-AB[i][1])

LL=[]
money=0

for i in range(1,M+1):
    for j in L[i]:
        heapq.heappush(LL,j)
    if len(LL)==0:
        continue
    money+=heapq.heappop(LL)

print(-money)

Measured memory_bytes: 39660
s = input()
N = len( s)
ans = 0
l = 0
r = N-1
while l < r:
    lx = 0
    rx = 0
    while l <= N-1:
        if s[l] == "x":
            lx += 1
            l += 1
        else:
            break
    while 0 <= r:
        if s[r] == "x":
            rx += 1
            r -= 1
        else:
            break
    if l == r:
        ans += abs( lx - rx)
    if l < r:
        if s[l] == s[r]:
            ans += abs(lx - rx)
        else:
            ans = -1
            break
    l += 1
    r -= 1
print( ans)

Measured memory_bytes: 3316
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <list>
#include <queue>
#include <tuple>
#include <deque>
#include <algorithm>
#include <numeric>
#include <utility>
#include <complex>
#include <functional>
using namespace std;
const int MOD = 1000000007;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = (1 << 28);
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
int n, m;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    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];
    }
    for (int i = 0; i <= n - m; i++)
    {
        for (int j = 0; j <= n - m; j++)
        {
            bool c = false;
            for (int k = 0; k < m; k++)
            {
                for (int h = 0; h < m; h++)
                {
                    if (a[i + k][j + h] != b[k][h])
                    {
                        c = true;
                        break;
                    }
                    if (k == m - 1 && h == m - 1)
                    {
                        yes;
                        return 0;
                    }
                }
                if (c == true)
                    break;
            }
        }
    }
    no;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
using vi = vector<int>;
using vic = vector<int> const;

int reconstruct_a_tree(int n, vic & preorder, vic & inorder, vi & parent, vi & left, vi & right);
int process_subtree(int preL, int preR, int inL, int inR, vic & preorder, vic & inorder, vic & val2inorder_idx, vi & parent, vi & left, vi & right);
void postorder_walk(int root, vi & postorder, vic & parent, vic & left, vic & right);

void pprint(vector<int> vs){
    cout << vs[0];
    for (auto it = vs.begin()+1; it != vs.end(); ++it) cout << ' ' << *it;
    cout << endl;
}

int main()
{
    // read data
    int n = 0;
    cin >> n;
    vector<int> preorder(n);
    for (auto & val : preorder) cin >> val;
    vector<int> inorder(n);
    for (auto & val : inorder) cin >> val;
    
    // reconstruct a tree
    vector<int> parent(n + 1);
    vector<int> left(n + 1);
    vector<int> right(n + 1);
    int root = reconstruct_a_tree(n, preorder, inorder, parent, left, right);
    parent[0] = 0;
    
    // post_order walk
    vector<int> postorder;
    postorder_walk(root, postorder, parent, left, right);
    pprint(postorder);
    return 0;
}

int reconstruct_a_tree(int n, vic & preorder, vic & inorder, vi & parent, vi & left, vi & right){
    vector<int> val2inorder_idx(n + 1);
    for (int idx = 0; idx != n; ++idx) val2inorder_idx[inorder[idx]] = idx;
    return process_subtree(0, n, 0, n, preorder, inorder, val2inorder_idx, parent, left, right);
}

int process_subtree(int preL, int preR, int inL, int inR, vic & preorder, vic & inorder, vic & val2inorder_idx, vi & parent, vi & left, vi & right){
    if (preL == preR) return 0;
    int root = preorder[preL];
    int inM = val2inorder_idx[root];
    int preM = preL + 1 + inM - inL;
    int left_child = process_subtree(preL + 1, preM, inL, inM, preorder, inorder, val2inorder_idx, parent, left, right);
    int right_child = process_subtree(preM, preR, inM + 1, inR, preorder, inorder, val2inorder_idx, parent, left, right);
    left[root] = left_child;
    right[root] = right_child;
    parent[left_child] = root;
    parent[right_child] = root;
    return root;
}


void postorder_walk(int root, vi & postorder, vic & parent, vic & left, vic & right){
    if (root == 0) return;
    postorder_walk(left[root], postorder, parent, left, right);
    postorder_walk(right[root], postorder, parent, left, right);
    postorder.push_back(root);
}

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

int main() {

    const int p = 3;
    vector<vector<int>> c(p, vector<int>(p));
    for (int i = 0; i < p; i++) {
        for (int j = 0; j < p; j++) {
            cin >> c[i][j];
        }
    }
    
    bool can = true;
    if (!(c[1][0] - c[0][0] == c[1][1] - c[0][1] && c[1][1] - c[0][1] == c[1][2] - c[0][2])) {
        can = false;
    }
    if (!(c[2][0] - c[0][0] == c[2][1] - c[0][1] && c[2][1] - c[0][1] == c[2][2] - c[0][2])) {
        can = false;
    }

    if (can) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		sc.close();

		System.out.println(a*b);
	}
}


Measured memory_bytes: 26908
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>

using namespace std;
int main() {
    int r = 0;
    string S;
    cin >> S;
    for (int j=0; j < 4; ++j) {
        if (S[j] == '+') {
            r += 1;
        } else {
            r -= 1;
        }
    }
    cout << r << endl;
}

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

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
#define in std::cin
#define ou std::cout
struct st{
        int val;
        bool b;
};
int main() {
    struct st A[3][3];
    int N,t;
    rep(i, 3)
        rep(j, 3) {
            in >> A[i][j].val;
            A[i][j].b = false;
        }
    in >> N;
    rep(i, N) {
        in >> t;
        rep(j, 3)
            rep(k,3){
                if(A[j][k].val == t)
                    A[j][k].b = true;
            }
    }
    rep(i, 3) {
        rep(j,3) {
            if(i==0 && (A[i][j].b && A[i+1][j].b && A[i+2][j].b)) {
                ou << "Yes";
                return 0;
            }
            if(j==0 && (A[i][j].b && A[i][j+1].b && A[i][j+2].b)){
                ou << "Yes";
                return 0;
            }
            if(i == 0 && j==0 &&(A[i][j].b && A[i+1][j+1].b && A[i+1][j+1].b)) {
                ou << "Yes";
                return 0;
            }
            if(i==2&&j==0 &&(A[i][j].b && A[i-1][j+1].b && A[i-2][j+2].b)){
                ou << "Yes";
                return 0;
            }
        }
    }
    ou << "No";
    return 0;
}

Measured memory_bytes: 888
#include <iostream>
#include <vector>
#include <cstdio>

using namespace std;

int main(){
	while(true){
		int n;
		cin >> n;
		if(n == 0){ break; }
		vector< vector<int> > mat(n + 1, vector<int>(n + 1));
		for(int i = 0; i < n; ++i){
			int sum = 0;
			for(int j = 0; j < n; ++j){
				cin >> mat[i][j];
				sum += mat[i][j];
			}
			mat[i][n] = sum;
		}
		for(int i = 0; i <= n; ++i){
			int sum = 0;
			for(int j = 0; j < n; ++j){ sum += mat[j][i]; }
			mat[n][i] = sum;
		}
		for(int i = 0; i <= n; ++i){
			for(int j = 0; j <= n; ++j){
				printf("%5d", mat[i][j]);
			}
			puts("");
		}
	}
	return 0;
}

Measured memory_bytes: 0
#include <stdio.h>
long long n;

int main()
{
	long long ans = 0;
	scanf("%lld", &n);

	for (long long i = 1; i*i <= n; i++)
	{
		if (n % i == 0)
		{
			long long t = n / i;
			long long m = t - 1;
			if(i < m)
				ans += m;
		}
	}

	printf("%lld", ans);


	return 0;
}

Measured memory_bytes: 128
#include<iostream>
using namespace std;
int main()
{
	int n,q;
	cin>>n;
	long long S[n];
	for(int i=0;i<n;i++)
		cin>>S[i];
	cin>>q;
	long long T[q];
	for(int i=0;i<q;i++)
		cin>>T[i];
	int count=0;
	for(int i=0;i<q;i++)
	{
		int start=0;
		int end=n-1;
		while(!(end<start))
		{
			int itemp=(start+end)/2;
 			if(T[i]>S[itemp])
				start=itemp+1;
			else if(T[i]<S[itemp])
				end=itemp-1;
			else
			{
				count++;
				break;
			}
		}	
	}
	cout<<count<<endl;
	return 0;
}


Measured memory_bytes: 4220
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;
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; }

int main(){
	int n;cin>>n;
	vector<int> a(n);
	for(int i = 0; i < n; i++) {
		cin>>a[i];
		a[i]--;
	}
	int ans = 0;
	for(int i = 0; i < n; i++) {
		if (a[a[i]] == i && a[i] > i)ans++;
	}
	cout << ans << endl;
	return 0;
}

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

long long S;

int main () {
	scanf("%lld", &S);
	int l = 1, r = 1e9, mid;
	while (l <= r) {
		mid = (l + r) >> 1;
		if (1ll * mid * mid >= S) r = mid - 1;
		else l = mid + 1;
	}
	int d = l - 1;
	if (abs(1ll * l * l - S) > abs(1ll * d * d - S)) {
		printf("%d %d %d %d %d %d", 0, 1, S - 1ll * d * d, d + 1, d, 0);
	} else {
		printf("%d %d %d %d %d %d", 0, 0, l, 1, 1ll * l * l - S, l);
	}
 	return 0;
}

Measured memory_bytes: 128
import sys
sys.setrecursionlimit(100001)
def input():
    return sys.stdin.readline()[:-1]
from heapq import *

INF = 10 ** 20
def dijkstra(s, edges):
    dist = [INF for _ in range(len(edges))]
    dist[s], h = 0, []
    heappush(h, (0, s))
    while (len(h)):
        dv, v = heappop(h)
        if dv > dist[v]:
            continue
        for u, cost in edges[v]:
            if dv + cost < dist[u]:
                dist[u] = dv + cost
                heappush(h, (dist[u], u))
    return dist

N = int(input())
es = [[] for i in range(N+1)]
for i in range(N-1):
    a, b, c = map(int, input().split())
    es[a].append((b, c))
    es[b].append((a, c))
Q, K = map(int, input().split())
xy = [list(map(int, input().split())) for i in range(Q)]
dist = dijkstra(K, es)
for i in range(Q):
    print(dist[xy[i][0]] + dist[xy[i][1]])


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

using namespace std;

typedef long long ll;

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    string s;
    cin >> s;
    vector<int> cnt(26);
    for (int i = 0; i < s.size(); i++) cnt[s[i] - 'a'] ^= 1;
    if (accumulate(cnt.begin(), cnt.end(), 0) == 0) cout << "Yes";
    else cout << "No";
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cstdio>
#include <map>
#include <algorithm>
#include <cmath>
using namespace std;

#define ll long long

#define si(x) scanf("%d", &x)
#define sll(x) scanf("%lld", &x)

#define pi(x) printf("%d", x)

int main()
{
    ll t, n, count = 0, m;
    sll(n);

    ll a10 = 1, a9 = 1, a8 = 1, prime = 1000000007;

    for (ll i = 0; i < n; i++)
    {
        a10 = (a10 % prime * 10) % prime;
        a9 = (a9 % prime * 9) % prime;
        a8 = (a8 % prime * 8) % prime;
    }

    a9 = (2 * a9 % prime) % prime;

    ll ans = (a10 % prime - a9 % prime + a8 % prime) % prime;
    if (ans < 0)
    {
        ans += prime;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3768
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define int long long
#define w(t) int t;cin>>t;while(t--)
#define pb push_back
#define mk make_pair
#define ascSort(v) sort(v.begin(), v.end())
#define descSort(v) sort(v.begin(), v.end(), greater<int>())
#define ff first
#define ss second
#define pi pair<int,int>
#define vi vector<int>
#define umapi unordered_map<int,int>
#define INF 1000000007
#define PI 3.14159265
const int mod=998244353;
using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>PBDS;

void FIO(){
	#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);	
}
bool cmp(int a, int b){
	return a>b;
}
int32_t main(){
	
	FIO();
	
		int a,b,c,d;cin>>a>>b>>c>>d;
		int cnt=0;
		while(a>=0&&c>0){
			if(cnt&1)
				a-=d;
			else
				c-=b;
			cnt++;
		}
		if(a<=0)
			cout<<"No";
		else
			cout<<"Yes";

	return 0;
	
		
}


Measured memory_bytes: 3608
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		Scanner stdIn = new Scanner(System.in);
		int[] result = new int[10000];
		int index = 0;
		int n = stdIn.nextInt();
		while( n != 0 ){
			int[] a = new int[n];
			for(int i = 0; i < n; i++){
				a[i] = stdIn.nextInt();
			}
			
			int max = a[0];
			for(int i = 0; i < n; i++){
				int sum = 0;
				for(int j = i; j < n; j++){
					sum += a[j];
					if( sum > max ){
						max = sum;
					}
				}
			}
			result[index] = max;
			index++;
			n = stdIn.nextInt();
		}
		for(int i = 0; i < index; i++){
			System.out.println(result[i]);
		}
	}
}

Measured memory_bytes: 13000
import java.util.Scanner;
class Main{


	static char[][] map;

	static long[][] c;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);			//文字の入力
		int n = sc.nextInt();
		int[] a = new int[n+1];
		int[] b = new int[n];

		for(int i = 0;i < n+1;i++){
			a[i] = sc.nextInt();	
		}
		for(int i = 0;i < n;i++){
			b[i] = sc.nextInt();
		}
		long ans = 0;
		long sup = 0;
		long calc = 0;
		for(int i = 0;i < n;i++){
			calc = a[i];
			if(sup > 0){
				calc -= sup;
			}
			if(calc < 0){				//あまり分で全部倒した時
				sup = b[i];
				ans += a[i];
			}else{
				calc -= b[i];
				if(calc <= 0){			//あまり+i番目の勇者の力で全部倒した時
					sup = -calc;
					ans += a[i];
				}else{
					sup = 0;
					ans += a[i]- calc;
				}
			}
			
			//System.out.println("sup " + sup);
			
		}
		
		if(a[n] - sup > 0){
			ans += sup;
			
		}else{
			ans += a[n];
		}
		System.out.println(ans);
		
		
		
		
		
		
	}
	static boolean check(int[] cc){
		for(int i = 0;i < cc.length-1;i++){
			if(cc[i] > cc[i+1]){
				return false;
			}
		}
		return true;
	}



	static int gcd(int a,int b){				//最大公約数を返す
		if(b == 0){
			return a;
		}else{
			return gcd(b, a%b);
		}
	}
	static long gcd(long a,long b){
		if(b == 0){
			return a;
		}else{
			return gcd(b, a%b);
		}
	}



	static long lcm (long a, long b) {
		long g = gcd(a,b);
		return a/g*b;
	}




}



class Pair implements Comparable{
	int from;
	int end;
	@Override
	public int compareTo(Object other) {
		Pair otherpair = (Pair)other;

		return   end- otherpair.end;
	}








}






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

using namespace std;


long long ans(long long a, long long b, int f) {
    long long x[2][3] = {};
    x[0][2] = a;
    x[1][2] = b;

    int ans = 0;
    int idx = 0;
    while (true) {
        long long p = x[idx][1] + x[idx][2];

        if (f == idx) {
            //　殺しムーブ
            {
                long long k2 = min(x[idx ^ 1][1], p);
                x[idx ^ 1][1] -= k2;
                p -= k2;

                long long total_kill = min(x[idx ^ 1][2], p / 2);
                p -= total_kill * 2;
                x[idx ^ 1][2] -= total_kill;
            }

            {
                long long k = min(x[idx ^ 1][2], p);
                p -= k;
                x[idx ^ 1][2] -= k;
                x[idx ^ 1][1] += k;

                long long k2 = min(x[idx ^ 1][1], p);
                x[idx ^ 1][1] -= k2;
                p -= k2;
            }

        } else {
            // 活かしムーブ
            long long k = min(x[idx ^ 1][2], p);
            p -= k;
            x[idx ^ 1][2] -= k;
            x[idx ^ 1][1] += k;

            long long k2 = min(x[idx ^ 1][1], p);
            x[idx ^ 1][1] -= k2;
            p -= k2;
        }

        if (x[idx ^ 1][1] == 0 && x[idx ^ 1][2] == 0) {
            return ans;
        }
        ans++;
        idx ^= 1;
    }

}


int main() {
    long long a, b;
    cin >> a >> b;
    cout << min(ans(a, b, true), ans(a, b, false)) << endl;
}


Measured memory_bytes: 3104
#include <iostream>
#include <vector>
#include <string>
#include <math.h>
#include <algorithm>
#include <queue>
#define INF 9999999999
using namespace std;
typedef long long int ll;

int main() {
	int N;
	cin >> N;
	char S[100];
	int flag[4] = {0};
	for (int i = 0; i < N; i++) {
		cin >> S[i];
		if (S[i] == 'P') flag[0] = 1;
		if (S[i] == 'W') flag[1] = 1;
		if (S[i] == 'G') flag[2] = 1;
		if (S[i] == 'Y') flag[3] = 1;
	}

	if (flag[0] + flag[1] + flag[2] + flag[3] == 4) cout << "Four" << endl;
	else cout << "Three" << endl;

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
#define rep(i,x) for(int i = 0; i < (int)(x); i++)
#define pb push_back
#define mp make_pair
#define debug(x) cerr << #x << ": " << (x) << "\n";
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
const ll MOD = 1e9+7;
const int n_max = 1e5+10;

int main(){
    ll n; cin >> n;
    string s;cin >> s;
    ll op = 0, ed = 0;
    rep(i,n){
        if(s[i] == '(')op++;
        else{
            if(op == 0)ed++;
            op = max(0LL,op-1);
        }
    }
    string sop, sed;
    rep(i,ed)sop += "(";
    rep(i,op)sed += ")";
    cout << sop + s + sed << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>
#include <random>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define RREP(i,m,n) for(int i=int(n)-1;i>=int(m);--i)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
//#define int long long

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int dfs(VVI &es, VI &d, VI &par, int i, int cnt = 0) {
    d[i] = cnt;
    int mv = 1;
    for (const int &dst: es[i]) {
        if (dst == par[i]) continue;
        par[dst] = i;
        mv = max(mv, dfs(es,d,par,dst,cnt+1));
    }
    return 0;
    //return d[i] = mv;
}

int getd(VVI &es, VI &d, VI &par, int i) {
    int ret = d[i];
    for (const int &dst: es[i]) {
        if (dst == par[i]) continue;
        ret = max(ret, getd(es,d,par,dst));
    }
    return ret;
}

void solve() {
    int n,u,v;
    cin >> n >> u >> v;
    --u; --v;
    VVI es(n);
    int a,b;
    REP(i,0,n-1) {
        cin >> a >> b;
        --a; --b;
        es[a].push_back(b);
        es[b].push_back(a);
    }
    VI par(n, -1), d(n);
    dfs(es,d,par,u);

    int pp = v;
    while (par[pp] != u) pp = par[pp];
    int ans = d[v] - 1;
    for (const int &dst: es[u]) {
        if (dst == pp) continue;
        int gd = getd(es,d,par,dst);
        ans = max(ans, gd + d[v] - 1);
    }

    int td = (d[v] - 1) / 2 + 1;
    //dump(td);
    //dump(d[v]);
    //dump(ans);
    int t = v, prev = -1;
    while (d[t] != td) {
        prev = t;
        t = par[t];
    }
    while (par[t] != u) {
        for (const int &dst: es[par[t]]) {
            if (dst == par[par[t]]) continue;
            if (dst == t) continue;
            if (dst == prev) continue;
            int gd = getd(es,d,par,dst);
            //dump(gd);
            //dump(d[par[t]]);
            ans = max(ans, gd + d[v] - d[par[t]] * 2 - 1);
        }
        prev = t;
        t = par[t];
    }
    
    cout << ans << endl;
}

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

Measured memory_bytes: 11648
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

import numpy as np

N = int(readline())
S = np.frombuffer(b'-'+readline().rstrip(),'S1')
Q = int(readline())
query = map(int,read().split())

isD = S == b'D'
isM = S == b'M'
isC = S == b'C'

cumD = isD.cumsum(dtype=np.int64)
cumM = isM.cumsum(dtype=np.int64)

for K in query:
    x = cumD.copy(); x[K:] -= cumD[:-K]
    x *= isM
    x[K+1:] -= isD[1:-K] * (cumM[K:-1] - cumM[:-K-1])
    print((x.cumsum() * isC).sum())

Measured memory_bytes: 57076
n = int(input())
a = list(map(int,input().split()))

si = set()
do = set()
for i in range(n):
    if(a[i] in si):
        do.add(a[i])
    else:
        si.add(a[i])
m = max(si)

li = [1]*m

for i in si:
    if(i in do):
        li[i-1] = 0
    for j in range(i*2,m+1,i):
        li[j-1] = 0

ans = 0
for i in si:
    if(li[i-1]==1):
        ans += 1
print(ans)

Measured memory_bytes: 35864
n =  int(input())
ls = []
for _ in range(n):
    a, b = map(int, input().split())
    ls.append([b,a])
ls = sorted(ls)
t=0
for i in ls:
    t += i[1]
    if t > i[0]:
        print('No')
        exit(0)
print('Yes')

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

int main(){
  int64_t n, a, b; cin >> n >> a >> b;
  int64_t c = a+b;
  int64_t m = n/c;
  if(m!=0){
    int64_t i = n-m*c;
    if (i >= a) cout << m*a+a;
    else cout << m*a+i;
  }
  else{
  if(n > a)cout << a;
    else cout << n;
  }
}

Measured memory_bytes: 256
#include <stdio.h>

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

  scanf("%d", &n);

  for(i = 0; i < n; i++){
    scanf("%d %d %d", &a, &b, &c);
    if(((a * a) + (b * b)) ==(c * c) || ((a * a) + (c * c)) == (b * b) || ((c * c) + (b * b)) ==(a * a)){
      printf("YES\n");
    }
    else{
      printf("NO\n");
    }
  }
  return(0);
}

Measured memory_bytes: 580
#include <stdio.h>
#include <math.h>

#define distance(x1,y1,x2,y2) hypot(x2-x1,y2-y1)

int main(void) {
	double x[100], y[100];
	int n, i;
	double a, b, c, z, s = 0.0;
	for (n = 0; scanf("%lf,%lf", &x[n], &y[n]) != EOF; n++);
	for (i = 2; i < n; i++) {
		a = distance(x[0],y[0],x[i-1],y[i-1]);
		b = distance(x[i-1],y[i-1],x[i],y[i]);
		c = distance(x[i],y[i],x[0],y[0]);
		z = (a+b+c)/2.0;
		s += sqrt(z*(z-a)*(z-b)*(z-c));
	}
	printf("%f\n", s);
	return 0;
}

Measured memory_bytes: 664
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using lb = long double;
using P = pair<ll,ll>;
//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
#define debug(x) cerr << #x << ": " << x << "\n"//手動デバッグ
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define inf 2147483647 //int値の最大値
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
#define endl "\n"//endlを置き換える
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素
#define CST(x) cout<<fixed<<setprecision(x)//小数点以下の桁数指定
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;
}
int gcd(int a, int b) {
    if (b==0) return a;
    else return gcd(b, a%b);
}
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}
int two(int n){
  ll ans=1;
  rep(i,n){
    ans*=2;
  }
  return ans;
}
bool check(vector<ll> v,vector<ll> lim){
  bool nuke=0;
  rep(i,4){
    if(v[i]>lim[i]){
      nuke=1;
      break;
    }
  }
  return nuke;
}
int main() {
  cin.tie(0);
  cout.tie(0);
  ios::sync_with_stdio(0);
  //##########################################################CODE_START
  string s;cin>>s;
  vector<int> v(26,0);
  rep(i,s.size()){
    v[int(s[i])-97]++;
  }
  rep(i,26){
    if(!v[i]){
      cout<<char(i+97)<<endl;
      return 0;
    }
  }
  cout<<"None"<<endl;
  
  
  
  
  
  
  
  
  //##########################################################CODE_END
  return 0;
}

Measured memory_bytes: 3716
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Convert;
using static System.Math;

class Program
{
    static void Main(string[] args)
    {
        var abc = Array.ConvertAll(ReadLine().Split(' '), int.Parse);
        var ka = (long)abc[0] + abc[1];
        if (ka >= abc[2]) { WriteLine(abc[1] + abc[2]); }
        else { WriteLine(ka+abc[1]+1); }
    }

    private const string ALFA = "abcdefghijklmnopqrstuvwxyz";
    private const int MOD = 1000000007;
}


Measured memory_bytes: 13140
#include<stdio.h>
int main(void)
{
	int a,b,c,d,s;
	scanf("%d%d%d%d",&a,&b,&c,&d);
	s=a+b+c+d;
	printf("%d\n%d\n",s/60,s%60);
	return 0;
}

Measured memory_bytes: 2688
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
typedef long long ll;
ll n,d,x,a[100];
int main(void){
    cin>>n>>d>>x;
    ll ans=x;
    for(ll i=-1;++i-n;)cin>>a[i];
    for(ll i=-1;++i-n;)ans+=(d-1)/a[i]+1;
    cout<<ans;
}

Measured memory_bytes: 888
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <cstring>
#include <cassert>
#define N (ll)(2e6+5)
#define INF (ll)(1e18+3)
 
#define ll long long
#define rep(i,a,n) for(ll i = a; i < n; i++)
#define per(i,a,n) for(ll i = n-1; i >= a; i--)
 
using namespace std;
 
ll D, fin;
ll dd[20];
 
ll work(ll digits) {
    //try all carries
    ll mask = (1<<(digits-1));
    ll ans = 0;
 
    rep(z,0,mask) {
        ll m[20] = {0};
        ll cnt[20] = {0};
        rep(i,0,20)
            m[i] = !!((1<<i)&z);
 
        // rep(i,0,digits) {
        //     cout << m[i] << " ";
        // }
        // cout << endl;
        bool zero = false;
        rep(i,0,(digits+1)/2) {
            ll b0 = m[i];
            ll b1 = m[digits-1-i];
 
            ll b0p = i-1>=0? m[i-1] : 0;
            ll b1p = digits-2-i>=0? m[digits-2-i] : 0;
 
            ll cur = dd[i] + b0p;
            ll rev = dd[digits-1-i] + b1p;
            //rev = n + cur;
 
            rep(j,0,10) {
                ll k = (j+cur)%10;
                if (i == digits-1-i && j!=k) continue;
                ll c0 = (j+cur)/10;
                ll c1 = (k+rev)/10;
                if (c0 != b0 || c1 != b1) continue;
                if (j == (k+rev)%10 && k == (j+cur)%10) {
                    //cout << j << " " << k << " " << cur << " " << rev << endl;
                    cnt[i]++;
                    if (!i && !k)
                        zero = true;
                }
            }
        }
        ll sum = 1;
        rep(i,1,(digits+1)/2) {
            sum *= cnt[i];
        }
        sum *= (cnt[0]-zero);
        ans += sum;
    }
    return ans;
}
 
void solve() {
ll mm =0;
    cin >> D;
    ll z = D;
    rep(i,0,20) {
        dd[i] = D%10;
        D/=10;
 if (dd[i]) mm = i;
    }
 
    ll fin = 0;
    rep(i,mm+1,19) {
        fin += work(i);
    }
 
    if (z%9) {
        cout << 0 << endl;
        return;
    }
    cout << fin << endl;
}
 
int main() {
    solve();
}

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

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

    vector<int> stick(n);
    for(int i = 0; i < n; i++){
        cin >> stick[i];
    }
    sort(stick.begin(), stick.end());

    int sum = 0;
    for(int i = n - 1; i > n - k - 1; i--){
        sum += stick[i];
        //cout << "stick:" << stick[i] << endl;
    }

    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 256
import numpy as np

s = np.array(list(input()))
t = np.array(list(input()))

equal = (s[:, None] == t[None, :])
ls, lt = len(s), len(t)
dp = np.zeros((ls + 1, lt + 1), dtype=int)

for i in range(ls):
    dp[i + 1][1:] = np.maximum(dp[i][1:], dp[i][:-1] + equal[i])
    dp[i + 1] = np.maximum.accumulate(dp[i + 1])

ans = ''
i, j = ls, lt
while i > 0 and j > 0:
    if dp[i][j] == dp[i - 1][j]:
        i -= 1
    elif dp[i][j] == dp[i][j - 1]:
        j -= 1
    else:
        ans = s[i - 1] + ans
        i -= 1
        j -= 1
print(ans)


Measured memory_bytes: 91596
import sys
input = sys.stdin.readline
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
# A = [ int(input()) for _ in range(N) ]
##############################

sx, sy, tx, ty = map(int, input().split())

dy = ty-sy
dx = tx-sx

ans = ''
ans += dy*'U' + dx*'R'
ans += dy*'D' + dx*'L'
ans += 'L' + (dy+1)*'U' + (dx+1)*'R' + 'D'
ans += 'R' + (dy+1)*'D' + (dx+1)*'L' + 'U'

print(ans)


Measured memory_bytes: 3060
#include<stdio.h>

#define Max 10000
#define NIL -1

typedef struct Node{
  int parent, l, r;
}Node;

Node T[Max];
int n, D[Max], H[Max];

void setDepth(int u, int d){
  if(u == NIL) return;
  D[u] = d;
  setDepth(T[u].l, d + 1);
  setDepth(T[u].r, d + 1);
}

int setHeight(int u){
  int h1 = 0, h2 = 0;

  if(T[u].l != NIL) h1 = setHeight(T[u].l) + 1;
  if(T[u].r != NIL) h2 = setHeight(T[u].r) + 1;
  return H[u] = (h1 > h2 ? h1 : h2);
}


int getSibling(int u){
  if(T[u].parent == NIL) return NIL;
  if(T[T[u].parent].l != u && T[T[u].parent].l != NIL) return T[T[u].parent].l;
  if(T[T[u].parent].r != u && T[T[u].parent].r != NIL) return T[T[u].parent].r;

  return NIL;
}

void print(int u){
  printf("node %d: ", u);
  printf("parent = %d, ", T[u].parent);
  printf("sibling = %d, ", getSibling(u));
  int deg = 0;
  if(T[u].l != NIL) deg++;
  if(T[u].r != NIL) deg++;
  printf("degree = %d, ", deg);
  printf("depth = %d, ", D[u]);
  printf("height = %d, ", H[u]);

  if(T[u].parent == NIL){
    printf("root\n");
  }
  else if(T[u].l == NIL && T[u].r == NIL){
    printf("leaf\n");
  }
  else{
    printf("internal node\n");
  }
}


int main(){
  int i, v, l, r, root = 0;

  scanf("%d", &n);
  for(i = 0 ; i < n ; i++) T[i].parent = NIL;

  for(i = 0 ; i < n ; i++){
    scanf("%d %d %d", &v, &l, &r);
    T[v].l = l;
    T[v].r = r;
    if(l != NIL) T[l].parent = v;
    if(r != NIL) T[r].parent = v;
  }

  for(i = 0 ; i < n ; i++){
    if(T[i].parent == NIL) root = i;
  }

  setDepth(root, 0);
  setHeight(root);

  for(i = 0 ; i < n ; i++) print(i);

  return 0;
}


Measured memory_bytes: 2104
#include <iostream>
#include <vector>
using namespace std;
int main(){
    int A, B;
    cin >> A >> B;
    int a = 2 * A - 1, b = 2 * B - 1, c = A + B;
    int ans = max(a, max(b, c));
    cout << ans << endl;
}

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

#define k 10001

int main(){
  int *A, *B;
  int C[k];
  int n, i, j;
  
  scanf("%d", &n);

  A = malloc( sizeof(int) *n+1 );
  B = malloc( sizeof(int) *n+1 );

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

  for ( i=0 ; i<n ; i++ ){
    scanf("%d", &A[i+1]);
    C[A[i+1]]++;
  }

  for ( i=1 ; i<=k ; i++ ) C[i] += C[i-1];

  for ( j=1 ; j<=n ; j++ ){
    B[C[A[j]]] = A[j];
    C[A[j]]--;
  }

  for ( i=1 ; i<=n ; i++ ){
    if ( i>1 ) printf(" ");
    printf("%d", B[i]);
  }
  printf("\n");

  return 0;
}

Measured memory_bytes: 16272
def div(n):
    lower_div, upper_div = [], []
    i = 1
    while i * i <= n:
        if n % i == 0:
            lower_div.append(i)
            if i != n // i:
                upper_div.append(n // i)
        i += 1
    return lower_div + upper_div[::-1]

def main():
    n = int(input())
    A = list(map(int, input().split()))
    L = [0] * n
    b = []
    for i in reversed(range(n)):
        if A[i] != L[i] % 2:
            b.append(i+1)
            d = div(i + 1)
            for j in d:
                L[j-1] += 1
    print(len(b))
    print(*b)

main()


Measured memory_bytes: 69852
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define irep(i, a, n) for (int i = a; i < (int)(n); ++i)
#define rrep(i, n) for (int i = (int)(n)-1; i >= 0; --i)
#define rrep1(i, n) for (int i = (int)(n); i >= 1; --i)
#define allrep(V, v) for (auto &&V : v)
#define all(x) (x).begin(), (x).end()
using lint = long long;
const int INF = 1 << 29;
const double EPS = 1e-9;
using namespace std;

int main(void) {
  int a, b;
  cin >> a >> b;
  int ans = b;
  if (a <= 12) {
    ans /= 2;
    if (a <= 5) {
      ans = 0;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        int xx = x / 100;
        if (100 * xx <= x && x <= 105 * xx) {
            System.out.println(1);
        } else {
            System.out.println(0);
        }
    }
}

Measured memory_bytes: 35484
N = gets.to_i

if N < 600 then
  puts 8
elsif N < 800 then
  puts 7
elsif N < 1000 then
  puts 6
elsif N < 1200 then
  puts 5
elsif N < 1400 then
  puts 4
elsif N < 1600 then
  puts 3
elsif N < 1800 then
  puts 2
else
  puts 1
end

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

using namespace std;
typedef long long ll;
typedef pair<ll, ll> p_ll;

template<class T>
void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; }
#define repr(i,from,to) for (int i=(int)from; i<(int)to; i++)
#define rep(i,N) repr(i,0,N)
#define per(i,N) for (int i=(int)N-1; i>=0; i--)

const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;
const int R_MAX = pow(10,5);

struct edge { int to; ll v; };
bool ok = true;
vector<ll> num(2*R_MAX, LLINF);
vector<vector<edge>> adj;
ll xmin = LLINF, ymin = LLINF;

void dfs(int n, ll v=0) {
  if (num[n]!=LLINF) {
    if (num[n]!=v) ok = false;
    return;
  }
  num[n] = v;
  if (n<R_MAX) xmin = min(xmin, v);
  else ymin = min(ymin,v);
  for (auto x: adj[n]) dfs(x.to, x.v-v);
  return;
}

int main() {
  int R, C; cin >> R >> C;
  int N; cin >> N;

  adj.resize(2*R_MAX);
  rep(i,N) {
    int r, c, a; cin >> r >> c >> a; r--; c--;
    adj[r].push_back({c+R_MAX,a});
    adj[c+R_MAX].push_back({r,a});
  }
  
  rep(i,R_MAX*2) {
    xmin = LLINF; ymin = LLINF;
    if (num[i]==LLINF) dfs(i);
    if (xmin+ymin<0) ok = false;
  }
  // rep(i,10) cout << num[i] << " "; cout << endl;
  // rep(i,10) cout << num[R_MAX+i] << " "; cout << endl;

  string result = ok ? "Yes" : "No";
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 14848
#include <iostream>

#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = 1; i <= (n); i++)
#define drep(i,n) for(int i = (n)-1; i >= 0; i--)
#define srep(i,s,t) for (int i = s; i < t; i++)
#define rng(a) a.begin(),a.end()
using ll = long long;

using namespace std;



int main() {
    int n,x,t;
    cin>>n>>x>>t;
    cout<<((n+x-1)/x)*t<<endl;

    return 0;
}


Measured memory_bytes: 3592
import math
import collections
import bisect
from collections import deque
from copy import copy, deepcopy
 
 
def main():
    N = int(input())
    L = list(map(int,input().split()))
    ans=0
    for i in range(len(L)):
        for j in range(i,len(L)):
            for k in range(j,len(L)):
                if L[i]==L[j] or L[j]==L[k] or L[k]==L[i]:
                    continue
                l = sorted([L[i],L[j],L[k]])
                if l[2]>=l[1]+l[0]:
                    continue

                #print(l,i,j,k)
                ans+=1
    print(ans)

 
if __name__ == '__main__':
    main()


Measured memory_bytes: 9620
#include <iostream>
using namespace std;
int main() {
    int a,b;
    while (cin>>a>>b) {
        if (a<b) {
            cout<<"a < b"<<endl;
        } else if((a==b)){
            cout<<"a == b"<<endl;
        } else cout<<"a > b"<<endl;
    }
    return 0;
}



Measured memory_bytes: 3080
//#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>

using namespace std;

//vector string deque break continue
#define forn(i, s, f) for (int i = (int)s; i < (int)f; i++)
#define ll long long
#define ull unsigned long long
#define ld long double
#define pii pair <int, int>
#define fs first
#define sc second
#define pf push_front
#define pb push_back
#define pop_f pop_front
#define pop_b pop_back
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()

#ifdef DEBUG
#else
    #define cerr if (false) cerr
#endif

template <typename T> istream& operator>>(istream& in, vector <T>& a) {for (auto& i : a) in >> i; return in;}
template <typename T> ostream& operator<<(ostream& out, vector <T>& a)  {for (auto& i : a) out << i << " "; return out;}
template <typename T, typename U> void chkmin(T& a, U b) {if (a > b) a = b;}
template <typename T, typename U> void chkmax(T& a, U b) {if (a < b) a = b;}

const int MOD = 1e9 + 7;

int add(int x, int y) {
    x += y;
    if (x >= MOD)
        return x - MOD;
    return x;
}

int sub(int x, int y) {
    x -= y;
    if (x < 0)
        return x + MOD;
    return x;
}

int mul(int x, int y) {
    return (1LL * x * y) % MOD;
}

int bin_pow(int a, int p) {
    if (!p)
        return 1;
    if (p % 2)
        return (1LL * bin_pow(a, p - 1) * a) % MOD;
    int t = bin_pow(a, p / 2);
    return (1LL * t * t) % MOD;
}

int inv(int x) {
    return bin_pow(x, MOD - 2);
}

const int N = 1e5;

vector <int> f;

int c(int n, int k) {
    return mul(f[n], inv(mul(f[k], f[n - k])));
}

int get(int x, int y) {
    --x, --y;
    return c(x + y, x);
}

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0);
    int n, m, a, b;
    cin >> n >> m >> a >> b;
    f.resize(2 * N + 5);
    f[0] = 1;
    forn (i, 1, sz(f))
        f[i] = mul(f[i - 1], i);
    int ans = 0;
    for (int x = n - a, y = b + 1; x > 0 && y <= m; --x, ++y)
        ans = add(ans, mul(get(x, y), get(n - x + 1, m - y + 1)));
    cout << ans;
    return 0;
}

Measured memory_bytes: 4000
#include<bits/stdc++.h>
using namespace std;
void solve()
{
	int n;
	cin>>n;
	string s;
	map<string, int> mp;
	for(int i = 0; i<n; i++)
	{
		cin>>s;
		mp[s]++;
	}
	cout<<"AC x "<<mp["AC"]<<"\n";
	cout<<"WA x "<<mp["WA"]<<"\n";
	cout<<"TLE x "<<mp["TLE"]<<"\n";
	cout<<"RE x "<<mp["RE"]<<"\n";
}
int main()
{
	solve();
	return 0;
}

Measured memory_bytes: 3596
use warnings;
    use Data::Dumper;
    
    sub GetInputData{
    
        my @array_data;
    
        my $line = <STDIN>;
    
        chomp($line);
    
        while($line ne ""){
    
           push(@array_data,$line);
    
           $line = <STDIN>;
    
           chomp($line);
    
    }
    
        return @array_data;
    
    }
    
    sub GetSpaceInputData{
    
        my @array_temp=GetInputData();
    
        my @array_buf;
    
        for(@array_temp){
    
            #戻りは配列スペース区切りを分解
            # myを先頭につける必要あり
            my @array_work=split(" ",$_);

            # リファレンスを配列に代入
            push(@array_buf,\@array_work);
        }
    
        return @array_buf;
    
    }
    
    my @arr_result = GetSpaceInputData();

    my $d = $arr_result[0][0];
    
    my $cnt= 25 - $d;

    print "Christmas" . " Eve " x $cnt;

 

Measured memory_bytes: 1920
a=input().split()
b=[]
for i in range(len(a)):
    if a[i]=='*':
        b.append(int(b.pop()) *int(b.pop()))
    elif a[i]=='+':
        b.append(int(b.pop()) +int(b.pop()))
    elif a[i]=='-':
        b.append(-int(b.pop()) +int(b.pop()))
    else:
        b.append(int(a[i]))
print(b[0])


Measured memory_bytes: 5600
n, k, c = map(int, input().split())
s = input()
dpl = []
dpr = []
ans = []
count = 0
i = 0
while count < k:
    if s[i]=="o":
        dpl.append(i)
        count += 1
        i += c+1
    else: i += 1
count = 0
i = n-1
while count < k:
    if s[i]=="o":
        dpr.append(i)
        count += 1
        i += -c-1
    else: i -= 1
dpr.sort()
for i in range(len(dpl)):
    if dpl[i] == dpr[i]: ans.append(dpl[i]+1)
print(*ans, sep="\n")

Measured memory_bytes: 65020
N,M,C = map(int, input().split())
B = [int(b) for b in input().split()]
A = []
for i in range(N):
    A.append([int(a) for a in input().split()])
    
ans = 0
for i in range(N):
    temp = C
    for j in range(M):
        temp += A[i][j]*B[j]
    if temp > 0:
        ans += 1

print(ans)

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

int main(void){

    long int x, count, sum;
    count = 0;
    sum = 100;

    scanf("%ld",&x);

    while(1){
        sum += sum/100;
        count++;
        if(sum >= x){
            printf("%ld",count);
            break;
        }
    }

    return 0;
}

Measured memory_bytes: 1700
#[allow(unused_imports)]
use proconio::{input, marker::*};

#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};

#[allow(unused_imports)]
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*).unwrap();
    }
}

fn main() {
    input! {
        n: String,
    }
    let mut sum = 0usize;
    for c in n.chars() {
        sum += c as usize - '0' as usize;
    }
    if sum % 9 == 0 {
        println!("Yes");
    } else {
        println!("No");
    }
}


Measured memory_bytes: 2316
#include <stdio.h>

int main(){
  int i, j, temp, N, A[100], num=0;
  
  // input
  scanf("%d",&N);
  for(i = 0; i <= N-1; i++)
    scanf("%d",&A[i]);
  
  
  // sort
  for(i = 0; i < (N-1); i++){
    for(j = (N-1); j > i; j--){
      if(A[j-1] > A[j]){
	temp = A[j-1];
	A[j-1] = A[j];
	A[j] = temp;
	num++;
      }
    }
  }
  

  // output
  for(i = 0; i <= N-1; i++){
    if(i == N-1)
      printf("%d",A[i]);
    else
      printf("%d ",A[i]);
    
  }
  printf("\n");
  printf("%d\n",num);
  return 0;
  
} 

Measured memory_bytes: 604