akhauriyash/Code-Regression huggingface dataset:
#include <stack>
#include <string>
#include <vector>
#include <iostream>
using namespace std;

struct S { int bg, ed, ar; };

int main()
{
    string s;
    cin >> s;

    stack<int> st;
    vector<S> v;

    bool f = false;
    for (int i = 0; i < s.size(); i++){
        if (s[i] == '\\'){
            st.push(i);
        }
        if (s[i] == '/'){
            if (st.empty()) continue;
            int ar = i - st.top();
            while (!v.empty() && st.top() < v.back().bg){
                ar += v.back().ar;
                v.pop_back();
            }

            S s;
            s.bg = st.top();
            s.ed = i;
            s.ar = ar;
            v.push_back(s);
            st.pop();
        }
    }

    int area = 0;
    for (S &a : v) area += a.ar;
    cout << area << endl;

    cout << v.size();
    for (S &a : v) cout << " " << a.ar;
    cout << endl;
}



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

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

using namespace std;

int main(){
	int n,k; cin>>n>>k;
	vector<vector<int>> B(2*k+1,vector<int>(2*k+1));
	vector<vector<int>> W(2*k+1,vector<int>(2*k+1));
	rep(i,n){
		int x,y;
		char c; cin>>x>>y>>c;
		if(c=='B') B[y%(2*k)+1][x%(2*k)+1]++;
		else       W[y%(2*k)+1][x%(2*k)+1]++;
	}
	rep(i,2*k) rep(j,2*k) {
		B[i+1][j+1]+=B[i+1][j]+B[i][j+1]-B[i][j];
		W[i+1][j+1]+=W[i+1][j]+W[i][j+1]-W[i][j];
	}

	int ans=0;
	rep(i,k+1) rep(j,k+1) {
		int bcnt=0,wcnt=0;
		bcnt+=B[k+i][k+j]-B[i][k+j]-B[k+i][j]+B[i][j];
		bcnt+=B[2*k][2*k]-B[k+i][2*k]-B[2*k][k+j]+B[k+i][k+j];
		bcnt+=B[i][j];
		bcnt+=B[i][2*k]-B[i][k+j];
		bcnt+=B[2*k][j]-B[k+i][j];
		wcnt+=W[k+i][2*k]-W[k+i][k+j]-W[i][2*k]+W[i][k+j];
		wcnt+=W[2*k][k+j]-W[k+i][k+j]-W[2*k][j]+W[k+i][j];
		wcnt+=W[i][k+j]-W[i][j];
		wcnt+=W[k+i][j]-W[i][j];
		ans=max({ans,bcnt+wcnt,n-bcnt-wcnt});
	}
	cout<<ans<<endl;

	return 0;
}


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

using namespace std;

typedef long long ll;

const ll NMAX = ll(10e18) + 1;

int solve();

ll getNextGrad(const ll k, const ll a);

ll binarySearch(const ll k, const ll target);

ll jsearch(const ll k, const ll low, const ll high, const ll target);

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

int solve() {

	ll N, k;
	cin >> N >> k;

	ll next = 1;

	//	コーナーケース
	{
		if (N == 1)
		{
			next = 0;
		}
		else if (N == 2)
		{
			next = 1;
		}
	}
	for (int i = 0; i < N - 2; i++)
	{
		const ll m = binarySearch(k, next - 1);
		const ll M = binarySearch(k, next + 1);
		next = jsearch(k, m, M, next);
	}

	cout << next << endl;


	return 0;
}

ll binarySearch(const ll k, const ll target)
{
	ll low = 0,
		high = NMAX,
		mid = (low+high)/2;

	while (getNextGrad(k,mid) != target)
	{
		mid = (low + high) / 2;

		if (getNextGrad(k, mid) > target)
		{
			high = mid;
		}
		else
		{
			low = mid;
		}

	}

	return mid;
}

ll jsearch(const ll k, const ll low, const ll high, const ll target)
{
	for (ll i = low; i <= high; i++)
	{
		if (getNextGrad(k, i) != target) { continue; }
		if (i % k == 0) { continue; }
		return i;
	}
	return -114514;
}

ll getNextGrad(const ll k, const ll a)
{
	return (a - (a / k + 1));
}



Measured memory_bytes: 3120
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll cnt[30];
int main() {
	// your code goes here
	string s;cin >> s;int n=s.length();
	for(int i=0;i<s.length();i++){cnt[s[i]-'a']++;}
	ll ans = (n*(n-1LL))/2;
	for(int i=0;i<26;i++){ans-=(cnt[i]*(cnt[i]-1LL))/2;}
	cout<<ans+1<<endl;
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

int compute(string s) {
    int n = 0;
    int nest = 0;
    vector<int> vote[1000];
    for (int i=0; i<(int)s.length(); i++) {
        if (s[i] == '[') {
            nest++;
        }
        else if (s[i] == ']') {
            if (vote[nest].size() == 0) {
                n = n/2+1;
            }
            else {
                sort(vote[nest].begin(), vote[nest].end());
                n = 0;
                for (int i=0; i<=(int)vote[nest].size()/2; i++) {
                    n += vote[nest][i];
                }
            }
            vote[nest].clear();
            nest--;
            vote[nest].push_back(n);
            n = 0;
        }
        else {
            n *= 10;
            n += s[i]-'0';
        }
    }
    return vote[0][0];
}

int main() {
    int n;
    string s;
    cin >> n;
    for (int i=0; i<n; i++) {
        cin >> s;
        cout << compute(s) << endl;
    }
    return 0;
}

Measured memory_bytes: 1308
import fractions

n = int(input())
a = list(map(int, input().split()))

l = [0]
r = [0]
for i in range(n):
    l.append(fractions.gcd(l[i], a[i]))
    r.append(fractions.gcd(r[i], a[-(i+1)]))
    
m = [fractions.gcd(l[i], r[-(i+2)]) for i in range(n)]
print(max(m))

Measured memory_bytes: 16148
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
#define int long long
int gcd(int a, int b) {
    if (b > a) return gcd(b, a);
    else if (b == 0) return a;
    else return gcd(b, a % b);
}

int f(int A, int C) {
    return A / C;
}

int f2(int B, int C, int D) {
    return B - f(B, C) - f(B, D) + f(B, C * D / gcd(C, D));
}

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int A, B, C, D;
    cin >> A >> B >> C >> D;
    cout << f2(B, C, D) - f2(A - 1, C, D) << endl;


    return 0;
}


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

const int MAXN = 1e5 + 7;
set<int> G[MAXN]; 
set<int> T[MAXN];

int main() {
    //ifstream cin("E.in");

    int n; cin >> n;

    for(int i = 0; i < n - 1; ++i) {
        int a, b; cin >> a >> b;
        a--, b--;
        G[a].insert(b);
        G[b].insert(a);
    }

    for(int i = 0; i < n - 1; ++i) {
        int a, b; cin >> a >> b;
        a--, b--;
        T[a].insert(b);
        T[b].insert(a);
    }

    queue<pair<int, int>> Q;
    set<pair<int, int>> seen;

    for(int i = 0; i < n; ++i)
        for(auto node : G[i])
            if(T[i].find(node) != T[i].end()) {
                auto edge = make_pair(min(node, i), max(node, i));
                if(seen.find(edge) == seen.end()) {
                    Q.push(edge);
                    seen.insert(edge);
                }
            }
    
    int many = 0;

    while(not Q.empty()) {
        auto edge = Q.front();
        Q.pop();

        int a = edge.first, b = edge.second;
            
        if(T[a].empty() or T[b].empty())
            continue;

        many++;

        if(T[a].size() + G[a].size() > T[b].size() + G[b].size())
            swap(a, b);
        
        vector<pair<int, int>> check;

        for(auto node : T[a]) {
            if(node != b) {
                T[b].insert(node);
                T[node].insert(b);
                T[node].erase(a);
                check.push_back(make_pair(min(b, node), max(b, node)));
            }
        }

        for(auto node : G[a]) {
            if(node != b) {
                G[b].insert(node);
                G[node].insert(b);
                G[node].erase(a);
                check.push_back(make_pair(min(b, node), max(b, node)));
            }
        }
        
        T[b].erase(a);
        G[b].erase(a);

        T[a].clear();
        G[a].clear();
        
        for(auto temp : check) {
            int x = temp.first;
            int y = temp.second;
            if(G[x].find(y) != G[x].end() and T[x].find(y) != T[x].end()) {
                if(seen.find(temp) == seen.end()) {
                    Q.push(temp);
                    seen.insert(temp);
                }
            }
        }
    }
        
    if(many == n - 1) {
        cout << "YES\n";
    } else {
        cout << "NO\n";
    }    
}

Measured memory_bytes: 30592
oddsteps = "RUD"
evensteps = "LUD"
s = input()
n = len(s)
odd = [1 if s[i] in oddsteps else 0 for i in range(0, n, 2)]
even = [1 if s[i] in evensteps else 0 for i in range(1, n, 2)]
if sum(odd) + sum(even) == n:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#define int long long
#define rep(i, n) for(i = 0; i < n; i++)
using namespace std;

int n;
int x[100], y[100], h[100];

bool check(int h0, int cx, int cy) {
	int i;
	rep(i, n) {
		int tmp = max(0LL, h0 - abs(cx - x[i]) - abs(cy - y[i]));
		if (tmp > h[i]) return false;
	}
	return true;
}

signed main() {
	int i, j, k;
	
	cin >> n;
	rep(i, n) cin >> x[i] >> y[i] >> h[i];
	
	rep(i, 101) {
		rep(j, 101) {
			int st = 1, ed = 2000000000, mid;	//oooxxx, [st, ed)
			while (ed - st >= 2) {
				mid = (st + ed) / 2;
				if (check(mid, i, j)) st = mid;
				else ed = mid;
			}
			
			int h0 = st;
			rep(k, n) {
				int tmp = max(0LL, h0 - abs(i - x[k]) - abs(j - y[k]));
				if (tmp != h[k]) break;
			}
			if (k == n) {
				cout << i << " " << j << " " << h0 << endl;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 256
S = input()
d = {'N': 0, 'W': 0, 'S': 0, 'E': 0}
prev = 'null'
for s_i in S:
    d[s_i] = 1
    if sum(d.values()) == 4:
        break
y = False
x = False
if (d['N'] and d['S']) or not(d['N'] or d['S']):
    y = True
if (d['W'] and d['E']) or not(d['W'] or d['E']):
    x = True
print('Yes' if y and x else 'No')

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


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

#define EPS 1e-6

using namespace std;

int a[105][105];
int v[105][105];

int main(){

	int w,h;
	cin >> w >> h;
	REP(i,1,h)
	REP(j,1,w)
	cin >> a[i][j];

    queue<int>x;
    queue<int>y;

	x.push(0);
	y.push(0);
	v[0][0]=1;


    int c=0;
    while(!x.empty()){

    	int p=x.front();
    	int q=y.front();
    	x.pop();
    	y.pop();

    	if(p%2==0){

    	if(p!=0 && q!=0){ if(a[p-1][q-1]==1) c++;  else if(v[p-1][q-1]==0){x.push(p-1); y.push(q-1); v[p-1][q-1]=1;};};

    	if(p<=h){ if(a[p+1][q]==1) c++;    else if(v[p+1][q]==0){x.push(p+1); y.push(q); v[p+1][q]=1;};};

    	if(p!=0){ if(a[p-1][q]==1) c++;    else if(v[p-1][q]==0){x.push(p-1); y.push(q); v[p-1][q]=1;};};

    	if(p<=h && q!=0){ if(a[p+1][q-1]==1) c++;  else if(v[p+1][q-1]==0){x.push(p+1); y.push(q-1); v[p+1][q-1]=1;};};

    	if(q!=0){ if(a[p][q-1]==1) c++;    else if(v[p][q-1]==0){x.push(p); y.push(q-1); v[p][q-1]=1;};};

        if(q<=w){ if(a[p][q+1]==1) c++;    else if(v[p][q+1]==0){x.push(p); y.push(q+1); v[p][q+1]=1;};};

    	}

    	else{

    	if(p!=0){ if(a[p-1][q]==1) c++;  else if(v[p-1][q]==0){x.push(p-1); y.push(q); v[p-1][q]=1;};};

        if(p<=h && q<=w){ if(a[p+1][q+1]==1) c++;    else if(v[p+1][q+1]==0){x.push(p+1); y.push(q+1); v[p+1][q+1]=1;};};

        if(p!=0 && q<=w){ if(a[p-1][q+1]==1) c++;    else if(v[p-1][q+1]==0){x.push(p-1); y.push(q+1); v[p-1][q+1]=1;};};

        if(p<=h){ if(a[p+1][q]==1) c++;  else if(v[p+1][q]==0){x.push(p+1); y.push(q); v[p+1][q]=1;};};

        if(q!=0){ if(a[p][q-1]==1) c++;    else if(v[p][q-1]==0){x.push(p); y.push(q-1); v[p][q-1]=1;};};

        if(q<=w){ if(a[p][q+1]==1) c++;    else if(v[p][q+1]==0){x.push(p); y.push(q+1); v[p][q+1]=1;};};

    	}

    }

        cout << c << endl;

    	return 0;
    }

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

int v[21];
int c[21];

int main(){
	int n,i,j,value=0;
	cin >> n;
	for(i=0;i<n;i++)
		cin >> v[i];
	for(i=0;i<n;i++)
		cin >> c[i];
	for(i=0;i<n;i++){
		if(v[i]>c[i])
			value = value + (v[i]-c[i]);
	}
	cout << value;
		
	
}


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

bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return false;
        }
    }

    // 素数である
    return true;
}

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

    bool flag= true ;
    int ans = x ;
    while(flag)
    {
        flag = !IsPrime(ans) ;
        ans++;
    }

    cout << ans-1 << endl ;
}

Measured memory_bytes: 3680
if __name__ == "__main__":
    N, M = map(int, input().split())
    key_data = list()
    INF = 1001001001
    for i in range(M):
        a, b = map(int, input().split())
        c = sum(1 << (ci - 1) for ci in map(int, input().split()))
        key_data.append([a, c])

    dp = [INF] * 2 ** N
    dp[0] = 0

    for j in range(2**N):
        for i in range(M):
            k = j | key_data[i][1]
            cost = dp[j] + key_data[i][0]
            if dp[k] > cost:
                dp[k] = cost

    if dp[2**N - 1] == INF:
        print('-1')
    else:
        print(dp[2**N - 1])


Measured memory_bytes: 3188
import std.stdio, std.conv, std.string, std.algorithm, std.array, std.range;

void dump(long[][] arr) {
  for(int i = 0; i < arr.length; i++)
    for(int j = 0; j < arr[i].length; j++)
      writef("%2d%s", arr[i][j], j == arr[i].length - 1 ? "\n" : " ");
  writeln;
}

void main() {
  int t = readln.chomp.to!(int);
  long ans = long.min;
  long[][] arr;
  long[][] dp = new long[][](t + 1, t + 1);
  long region[4];
  for(long i = 0; i < t; i++)
    arr ~= (readln.chomp.split(" ").map!(to!(long)).array) ~ [0L];
  arr ~= repeat(0L).take(t + 1).array;
  for(int i = t - 1; i >= 0; i--) {
    for (int j = t - 1; j >= 0; j--) {
      dp[i][j] += arr[i][j] + dp[i + 1][j] + dp[i][j + 1] - dp[i + 1][j + 1];
    }
  }
  for(int i = t; i >= 0; i--) {
    for(int j = t; j >= 0; j--) {
      for(int n = i + 1; n <= t; n++) {
        for(int m = j + 1; m <= t; m++) {
          long v = dp[i][j] - dp[n][j] - dp[i][m] + dp[n][m];
          if (ans < v) {            
            ans = v;
            region = [i, j, n - 1, m - 1];
          }
        }
      }
    }
  }
  // dump(dp);
  // writeln(region);
  writeln(ans);
}

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

int a[1000][1000], dp[1000][1000];
int main() {
	int h, w, n;
	while (scanf("%d%d%d", &h, &w, &n), h) {
		rep(i, h)rep(j, w)scanf("%d", &a[i][j]);
		memset(dp, 0, sizeof(dp));
		dp[0][0] = n - 1;
		rep(i, h)rep(j, w) {
			if (i) {
				if (a[i - 1][j])dp[i][j] += dp[i - 1][j] / 2;
				else dp[i][j] += (dp[i - 1][j] + 1) / 2;
			}
			if (j) {
				if (a[i][j - 1])dp[i][j] += (dp[i][j - 1] + 1) / 2;
				else dp[i][j] += dp[i][j - 1] / 2;
			}
		}
		rep(i, h)rep(j, w) {
			if (dp[i][j] & 1)a[i][j] = !a[i][j];
		}
		int x = 0, y = 0;
		while (x < h&&y < w) {
			if (a[x][y])y++;
			else x++;
		}
		printf("%d %d\n", x + 1, y + 1);
	}
}

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

int main()
{
  int n;
  cin >> n;
  set<int> data;
  for(int i = 0; i < n; i++)
  {
    int x; cin >> x;
    data.insert(x);
  }
  cout << data.size() << endl;
}


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

template <class lambda_type>
class make_recursive
{
    const lambda_type &func;
public:
    make_recursive(lambda_type &&f) : func(std::move(f)) {}
    template <class... Args> auto operator()(Args &&... args) const
    {
        return func(*this, std::forward<Args>(args)...);
    }
};

main()
{
    int n; cin>>n;
    vector<int> a(n);
    for(auto &e: a) cin>>e;
    vector<vector<int>> tree(n);
    for(int i=0; i<n-1; ++i)
    {
        int u,v; cin>>u>>v; --u,--v;
        tree[v].emplace_back(u);
        tree[u].emplace_back(v);
    }
    vector nlow(n, INT_MAX),ans(n,0);
    make_recursive([&](const auto &dfs, int v=0, int p=-1)->void
    {
        auto ptr=lower_bound(begin(nlow), end(nlow), a[v]);
        const int plow=*ptr;
        *ptr=a[v];
        ans[v]=lower_bound(begin(nlow), end(nlow), INT_MAX)-begin(nlow);
        for(int u: tree[v]) if(p!=u) dfs(u,v);
        *ptr=plow;
    })();
    for(int e: ans) cout << e << "\n";
}


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

using namespace std;



int main(){


 
 ios_base::sync_with_stdio(NULL); 
 cin.tie(0);
  #ifndef ONLINE_JUDGE
  freopen ("input.txt", "r", stdin);
  freopen ("outt.txt", "w", stdout);
#endif

  

int n;
cin>>n;
map<long long , int  > mp ;

for(int i=0;i<n;i++){
  long long a;
  cin>>a;
  mp[a]+=1;

}

for(map<long long  , int > :: iterator it = mp.begin();it!= mp.end();it++){
  if(it->second >= 2){
    cout<<"NO\n";
    return 0;
  }
}

cout<<"YES\n";


}

Measured memory_bytes: 16016
#include <iostream>
#include <iomanip>
#include <cassert>

#include <utility>
#include <vector>
#include <limits>
#include <algorithm>
using namespace std;

#define rep_init(i, init, n) for(int i = (init); i < n; ++i)
#define rep(i, n) rep_init(i, 0, n)

constexpr int INF = numeric_limits<int>::max();

void Main()
{
	string A, B;
	cin >> A >> B;

	int judge = 0;
	if (A.size() > B.size()) judge = 1;
	else if (A.size() < B.size()) judge = -1;
	else
	{
		rep(i, A.size())
		{
			if (A[i] > B[i]) judge = 1;
			else if (A[i] < B[i]) judge = -1;

			if (judge != 0)
			{
				break;
			}
		}
	}

	if (judge == 1) cout << "GREATER" << endl;
	else if (judge == 0) cout <<  "EQUAL" << endl;
	else cout << "LESS" << endl;
}

int main()
{
	std::cin.tie(nullptr);
	std::ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);

	Main();
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
    static List<List<Integer>> list;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        list = new ArrayList<>();
        for (int i = 0; i <= n; i++) {
            list.add(new ArrayList<>());
        }
        for (int i = 0; i < n - 1; i++) {
            int a = sc.nextInt();
            int b = sc.nextInt();
            list.get(a).add(b);
            list.get(b).add(a);
        }

        // System.out.println(list);
        int[] d1 = bfs(1, 0, new int[n + 1]);
        //System.out.println("--d2--");
        int[] d2 = bfs(n, 0, new int[n + 1]);
        //System.out.println(Arrays.toString(d1));
        //System.out.println(Arrays.toString(d2));
        int cnt1 = 0;
        int cnt2 = 0;
        for (int i = 1; i <= n; i++) {
            if(d1[i] == 0 || d2[i] == 0){
                continue;
            }
            if (d1[i] <= d2[i]) {
                cnt1++;
                continue;
            }
            cnt2++;
        }
        //System.out.println(cnt1);
        //System.out.println(cnt2);

        if (cnt1 > cnt2) {
            System.out.println("Fennec");
            return;
        }
        System.out.println("Snuke");
    }
    public static int[] bfs(int s, int p, int[] ret) {
        //System.out.println("--bfs--");
        List<Integer> edge = list.get(s);
        //System.out.println("s = " + s);
        //System.out.println(edge);
        for (int v : edge) {
            if (p != v) {
                ret[v] += ret[s] + 1;
                bfs(v, s, ret);
            }
        }
        return ret;
    }
}


Measured memory_bytes: 113064
#include <iostream>
#include <map>
#include <queue>
#include <vector>
#include <set>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <cmath>
#define INF 1000000007
using namespace std ;

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

	long long int a,b,k ;
	cin>>a>>b>>k ;

	if(k >= a+b) cout<<"0 0"<<endl ; 
	else 
	{
		if(k >= a)
		{
			cout<<"0 " ;
			k-=a ;
			cout<< b-k<<endl ;
		}
		else
		{
			cout<<a-k<<" " ;
			cout<<b<<endl ; 
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
using namespace std;

int main(){
  int n,k,x,y;
  cin >> n >> k >> x >> y;
  if(n<=k){
    cout << n*x <<endl;
  }
  else{
    cout << (k*x)+(n-k)*y << endl;
  }
  return 0;
}


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

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

  vector<int> c(n+1),s(n+1),f(n+1),a(n+1);
  for (int i = 0; i < n-1; i++) {
    cin >> c[i] >> s[i] >> f[i];
  }
  for(int i=0;i<n;i++)
    {
      int t=0;
      for(int j=i;j<n-1;j++)
	{
	  if(t<s[j])t=s[j];
	  else if(t%f[j]==0);
	  else t=t+f[j]-t%f[j];
	  t+=c[j];
	}
      printf ("%d\n",t);
    }
  return 0;
}


Measured memory_bytes: 256
# writer解(c++)を写経した．
# https://atcoder.jp/contests/m-solutions2020/submissions/15122924
import sys
input = sys.stdin.readline
INF = 10**13


def main():
    N = int(input())
    T = [[int(i) for i in input().split()] for j in range(N)]
    X_dist = [[0]*N for _ in range(1 << N)]
    Y_dist = [[0]*N for _ in range(1 << N)]

    # bitという道路群を建設したときの，各集落の評価距離
    # bit 001001 とかの1が立っている集落に道を作る
    for bit in range(1 << N):
        cur_x = [0]
        cur_y = [0]
        for i in range(N):
            if bit & (1 << i):
                cur_x.append(T[i][0])
                cur_y.append(T[i][1])
        for i, (x, y, p) in enumerate(T):
            X_dist[bit][i] = p*min(abs(cx - x) for cx in cur_x)
            Y_dist[bit][i] = p*min(abs(cy - y) for cy in cur_y)

    answer = [INF] * (N+1)
    for i in range(1 << N):
        cnt = 0
        for j in range(N):
            if (i >> j) & 1:
                cnt += 1
        # 道路を立てる本数確定
        # https://twitter.com/vp_o_l/status/1289027612103151616
        j = i
        while j >= 0:
            j &= i
            cost = 0
            for k in range(N):
                if not((i >> k) & 1):
                    cost += min(X_dist[j][k], Y_dist[i - j][k])
            answer[cnt] = min(answer[cnt], cost)
            j -= 1
    for ans in answer:
        print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 88280
// lower_bound
// upper_bound を使う
// 中段を固定して考える方法
//  main.cpp
//  ABC077C
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;
int main(int argc, const char * argv[]) {
    ll n;
    cin>>n;
    vector<ll>S(n),M(n),L(n);
    for(ll i=0;i<n;i++){
        cin>>S.at(i);
    }
    for(ll i=0;i<n;i++){
        cin>>M.at(i);
    }
    for(ll i=0;i<n;i++){
        cin>>L.at(i);
    }
    sort(S.begin(),S.end());
    sort(M.begin(), M.end());
    sort(L.begin(), L.end());
    ll ans=0;
    for(ll i=0;i<M.size();i++){
        ll now=M.at(i);
        ll ss=lower_bound(S.begin(), S.end(), now)-S.begin();
        ll ls=L.end()-upper_bound(L.begin(), L.end(), now);
        ans+=ss*ls;
    }
    cout<<ans<<endl;
    return 0;
}


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

using namespace std;

int n;
char x[100005];
queue<int> q;
bool g;

int main() {
	scanf("%s", x + 1);
	n = strlen(x + 1);
	if (x[n] == '1')
		g = 1;
	for (int i = 1; i < n; i++)
		if (x[i] != x[n - i])
			g = 1;
	if (x[1] == '0')
		g = 1;
	
	if (g)
		printf("-1\n");
	else {
		for (int i = 1; i <= n; i++)
			q.push(i);
		for (int i = 2; i <= n; i++)
			if ((i <= n - i && x[i] == '1') || i == n)
				while (q.front() < i) {
					printf("%d %d\n", q.front(), i);
					q.pop();
				}
	}
	return 0;
}

Measured memory_bytes: 2048
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;
public class Main {
    public static void main(String[] args){

    Scanner sc = new Scanner(System.in);
        String S = sc.next();
        char[]ss = S.toCharArray();
        ArrayList<Integer>ans  = new ArrayList<>();
        
        int cou = 0;
        for(int i=0; i<S.length(); i++) {
        if(ss[i]=='A' || ss[i]=='C' || ss[i]=='G' || ss[i]=='T') {
        	cou++;
        }else {
        	ans.add(cou);
                cou = 0;
        }
        }
        Collections.sort(ans,Collections.reverseOrder());
        if(ans.size()==0){	 
        	System.out.println(S.length());
        }else {
        	System.out.println(Math.max(cou,ans.get(0)));
    }
}
}


Measured memory_bytes: 35564
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
#define F  first
#define S  second
#define ff(i,n) for(i=0;i<n;i++)
int main()
{ 
	ll t;
	t=1;
	while(t--)
	{
		ll i,n;
		char s;
		cin>>s;
		if(s>='A' && s<='Z')
		{
		
			cout<<"A";
		}
		else
		{
			ll ss = s-'a';
			char a = ss+'A';
			cout<<"a";
		}
	}
	return 0;
}

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

int64_t solve(int64_t n,int64_t k){
	int64_t num=k;
	if(num<n)num=n/k*k;
	n-=num;
	if(n<0)n*=-1;
	if(n>k/2)solve(n,k);
	else return n;
}

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int64_t n,k;
	cin>>n>>k;
	cout<<solve(n,k)<<"\n"s;
}

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

int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	long long x;
	cin>>x;
	long long y = 100;
	int res = 0;
	while (y < x){
		y += y * 0.01;
		++res;
	}
	cout<<res<<endl;
}


Measured memory_bytes: 3612
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;

//typedef
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

//conversion
inline LL toLong(string s) {LL v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) LL((a).size())
#define EACH(i,c) for(auto i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define UNTIL(p) while(!(p))

//constant
const double EPS = 1e-5;
const double PI  = acos(-1.0);

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

#define PUTS(x) cout << (x) << endl;

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a1,a2,a3;
    cin>>a1>>a2>>a3;
    PUTS(a1 + a2 + a3 >= 22 ? "bust" : "win");
}

Measured memory_bytes: 256
#include <stdio.h>
#define A 21

int Back(int, int);

int n,s,N[A];

int main(){
    
    int i, q, ans;
    
    scanf("%d", &n);
    
    for(i = 0; i < n; i++){
        scanf("%d", &N[i]);
    }
    
    scanf("%d", &q);
    
    for(i = 0; i < q; i++){
        
        scanf("%d", &s);
        
        ans = Back(0,0);
        
        if(ans == 1)
            printf("yes\n");
        else
            printf("no\n");
        
    }
    
    return 0;
    
}

int Back(int i, int sum){
    
    if(sum == s)
        return 1;
    
    if(i == n)
        return 0;
    
    if(Back((i + 1), N[i] + sum) == 1)
        return 1;
    
    if(Back((i + 1), sum) == 1)
        return 1;
    
    return 0;
    }



Measured memory_bytes: 2052
#include<bits/stdc++.h>
using namespace std;
int main(){
	long long n,q,i,j,k,d,m,d_m,ans;
	char s[1000005];
	cin>>n>>s>>q;
	for(i=0;i<q;i++)
	{
		cin>>k;
		d=m=d_m=ans=0;
		for(j=0;j<n;j++)
		{
			if(j>=k)
			{
				if(s[j-k]=='D')
				{
					d--;
					d_m-=m;
				}
				if(s[j-k]=='M')
					m--;
			}
			if(s[j]=='D')
				d++;
			if(s[j]=='M')
			{
				m++;
				d_m+=d;
			}
			if(s[j]=='C')
				ans+=d_m; 
		}
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
void main_sub(void);
int main(int argc, char *argv[]) {
    cout << std::fixed << std::setprecision(12);
    main_sub();
    return 0;
}
// int を int64_t にする
// g++ に -DUSE_STRICT_INT をつけるか、
// 下のコメントアウトを外すと無効化
// #define USE_STRICT_INT
using i64 = int64_t;
#ifndef USE_STRICT_INT
#define int i64
#endif
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
constexpr int INF = (1 << 30);
constexpr i64 INFL = (1LL << 62);
constexpr i64 MOD = 1000000007;

struct V {
    double x, y;
    V(double x = 0, double y = 0) : x(x), y(y) {}
    V &operator+=(const V &v) {
        x += v.x;
        y += v.y;
        return *this;
    }
    V operator+(const V &v) const { return V(*this) += v; }
    double dot(const V &v) const { return v.x * x + v.y * y; }
    double cross(const V &v) const { return x * v.y - v.x * y; }
    int ort() const {  // orthant
        if (y > 0) {
            return x > 0 ? 1 : 2;
        } else {
            return x > 0 ? 4 : 3;
        }
    }
    double norm2() const { return x * x + y * y; }
    double norm() const { return sqrt(norm2()); }

    bool operator<(const V &v) const {
        int o = ort(), vo = v.ort();
        if (o != vo) return o < vo;
        return cross(v) > 0;
    }
    friend ostream &operator<<(ostream &os, const V &v) {
        os << "(" << v.x << ", " << v.y << ")";
        return os;
    }
    friend istream &operator>>(istream &is, V &v) {
        is >> v.x >> v.y;
        return is;
    }
};

void main_sub(void) {
    int n;
    cin >> n;
    vector<V> v(n);
    rep(i, n) cin >> v[i];
    sort(all(v)); // 偏角ソート
    double ans = 0;
    rep(l, n) {
        int r = l;
        V now;
        rep(i, n) {
            now += v[r];
            ans = max(ans, now.norm());
            r = (r + 1) % n;
        }
    }
    cout << ans << endl;
    return;
}

Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
typedef long long ll;
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
using namespace std;
const ll MAX_N=99;
ll N,A[MAX_N],c[MAX_N*2];
ll ask(){
	cout<<"?";
	REP(i,N){
		cout<<' '<<A[i]+1;
	}
	cout<<endl;
	ll res;
	string s;
	cin>>s;
	if(s[0]=='R'){
		res=0;
	}else{
		res=1;
	}
	return res;
}
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>N;
	REP(i,N*2)c[i]=-1;
	REP(i,N)A[i]=i;
	ll flg=ask();
	ll lb=0,ub=N;
	while(ub-lb>1){
		ll m=(lb+ub)>>1;
		REP(i,N)A[i]=i+m;
		ll f=ask();
		if(f==flg){
			lb=m;
		}else{
			ub=m;
		}
	}
	c[lb]=flg;
	c[lb+N]=1-flg;
	A[0]=lb;
	A[1]=lb+N;
	REP(i,N-1){
		ll n=2;
		REP(j,N-1){
			if(j!=i){
				A[n++]=lb+1+j;
			}
		}
		ll f=ask();
		c[lb+i+1]=1-f;
	}
	ll rn=1,bn=1,n=2;
	REP(i,N-1){
		if(c[lb+1+i]==0){
			if(rn<(N-1)/2){
				rn++;
				A[n++]=lb+1+i;
			}
		}else{
			if(bn<(N-1)/2){
				bn++;
				A[n++]=lb+1+i;
			}
		}
	}
	REP(i,N*2){
		if(i<lb||i>=lb+N+1){
			A[N-1]=i;
			c[i]=ask();
		}
	}
	cout<<"! ";
	REP(i,N*2){
		cout<<(c[i]==0?'R':'B');
	}
	cout<<endl;
}

Measured memory_bytes: 724
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define sz(v) v.size()
#define INF 1000000009
// aよりもbが大きいならばaをbで更新する
// (更新されたならばtrueを返す)
template <typename T>
bool chmax(T &a, const T& b) {
  if (a < b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}
// aよりもbが小さいならばaをbで更新する
// (更新されたならばtrueを返す)
template <typename T>
bool chmin(T &a, const T& b) {
  if (a > b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}

vector<vector<vector<ll>>> dp(102, vector<vector<ll>>(4, vector<ll>(2)));

int main(){
  string N;
  int K;
  cin >> N >> K;
  dp.at(0).at(0).at(0) = 1;
  rep(i, sz(N)){
    rep(j, K+1){
      rep(k, 2){
        rep(d, (k ? 9 : N.at(i)-'0')+1){
          if(d != 0 && j == K){
            break;
          }
          if(d != 0){
            dp.at(i+1).at(j+1).at(k || (d < N.at(i)-'0')) += dp.at(i).at(j).at(k);
          }
          else{
            dp.at(i+1).at(j).at(k || (d < N.at(i)-'0')) += dp.at(i).at(j).at(k);
          }
        }
      }
    }
  }
  cout << dp.at(sz(N)).at(K).at(0)+dp.at(sz(N)).at(K).at(1) << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;

namespace abc163
{
  class Program
  {
    static void Main()
    {
      var n = int.Parse(Console.ReadLine());
      var aStrList = Console.ReadLine().Split(' ');
      var numTable = new List<int>();
      for (var i = 0; i <= n; ++i)
      {
        numTable.Add(0);
      }
      foreach (var aStr in aStrList)
      {
        ++numTable[int.Parse(aStr)];
      }
      for (var i = 1; i <= n; ++i)
      {
        Console.WriteLine(numTable[i]);
      }
    }
  }
}

Measured memory_bytes: 43288
#include <iostream>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <climits>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <cassert>
#include <unordered_map>

#define _(x) { cout << #x << " = " << x << " "; }

const double E = 1e-8;
const double PI = acos(-1);

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int k, x;
    cin >> k >> x;
    cout << (500*k<x ? "No\n" : "Yes\n");
    return 0;
}



Measured memory_bytes: 256
// Problem : A - Red or Not
// Contest : AtCoder Beginner Contest 138
// URL : https://atcoder.jp/contests/abc138/tasks/abc138_a
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cp-editor)

#include<bits/stdc++.h>
#define int long long
#define mod 1000000007
#define trace(x) cerr<<#x<<": "<<x<<" "<<endl
#define tarce(x) cerr<<#x<<": "<<x<<" "<<endl
#define trace2(x, y) cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z) cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define sa(a,n) for(int i =0 ; i<n ; i++) cin>>a[i]
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define pb push_back
#define inf 2e18
#define scan() int n; cin>>n ; int a[n]; for(int i = 0 ; i<n ; i++) cin>>a[i]
#define print(a,n) for(int i = 0 ; i < n ; i++) cout<<a[i]<<' '
#define mem(a,v) memset(a,v,sizeof(a))
#define pii pair<int,int>
#define mkp make_pair
using namespace std;
#define N 200005


int32_t main(){
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        cout.tie(NULL);
        
        int n;
        cin >> n;
        string s;
        cin >> s;
        if(n<3200)cout << "red" << '\n';
        else cout << s << '\n';
        
        
        
        
        
        

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
struct cmp{
    bool operator()(pair<int, int> a, pair<int, int> b){
        return (a.first + a.second) < (b.first + b.second);
    }
};
struct cmp1{
    bool operator()(pair<int, int> a, pair<int, int> b){
        return (a.first - a.second) < (b.first - b.second);
    }
};
struct cmp2{
    bool operator()(pair<int, int> a, pair<int, int> b){
        return (-a.first + a.second) < (-b.first + b.second);
    }
};
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin >> n;
    vector<pair<int, int>> v(n);
    for(int i = 0; i < n; i++){
        cin >> v[i].first >> v[i].second;
    }
    sort(v.begin(), v.end(), cmp());
    int ans = abs(v[0].first - v[n - 1].first) + abs(v[0].second - v[n - 1].second);

    sort(v.begin(), v.end(), cmp1());
    ans = max(ans, abs(v[0].first - v[n - 1].first) + abs(v[0].second - v[n - 1].second));

    sort(v.begin(), v.end(), cmp2());
    ans = max(ans, abs(v[0].first - v[n - 1].first) + abs(v[0].second - v[n - 1].second));
    cout << ans;
    return 0;
}



Measured memory_bytes: 4784
#include <bits/stdc++.h>
#define rep(i, l, r) for(register int i = l; i < r; i++)
#define hrp(i, l, r) for(register int i = l; i <= r; i++)
#define rev(i, r, l) for(register int i = r; i >= l; i--)
#define ms(n, t) memset(n, t, sizeof(n))
#define U 10050
#define pb push_back
#define int ll
#ifndef JOEON
#define D(...)
#define R(x, l)
#define sp
#endif
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
template<typename tn> inline tn next(void);
template<typename tn> inline ostream& operator << (ostream& os, const vector<tn>& v);
signed main(void)
{
	#ifdef JOEON
//		freopen("C:\\Users\\Joeon\\Desktop\\IN.txt", "r", stdin);
//		freopen("C:\\Users\\Joeon\\Desktop\\OUT.txt", "w", stdout);
	#endif
	ios::sync_with_stdio(false);
	cin.tie(0);
	int cnt = 0;
	string s, t;
	cin>>s>>t;
	rep(i, 0, s.length()) if(s[i] != t[i]) cnt++;
	cout<<cnt<<endl;
	return 0;
}
template<typename tn> inline tn next(void)
{
	tn k;
	cin>>k;
	return k;
}
template<typename tn> inline ostream& operator << (ostream& os, const vector<tn>& v)
{
	rep(i, 0, v.size()) os<<v[i]<<' ';
	return os;
}

Measured memory_bytes: 3780
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())

const int MAX = 510000;
const int MOD = 1000000007;

int main(){
  ll a,b;cin>>a>>b;
  ll ans= max(a+b,max(a-b,a*b));
  cout<<ans<<endl;


}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  for(int i=1;i<=a;i++){
    for(int j=1;j<=b;j++){
	  if((i<=d&&j<=c)||(i>d&&j>c)) cout<<"1";
      else cout<<"0";
    }
    cout<<"\n";
  }
  return 0;
}

Measured memory_bytes: 1280
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0593

"""
import sys
from sys import stdin
from collections import namedtuple, Counter
input = stdin.readline


class RMQ(object):
    INT_MAX = 2**31 - 1

    def __init__(self, nn, init_val=0):
        self.n = 1
        while self.n < nn:
            self.n *= 2
        self.dat = [init_val] * ((2 * self.n)-1)

    def update(self, k, a):
        # A[k]???a?????´??°?????????????????°???????????¨?????´??°
        k += (self.n - 1)
        self.dat[k] = a

        while k > 0:
            k = (k - 1) // 2        #  ??????index??????
            self.dat[k] = min(self.dat[k * 2 + 1], self.dat[k * 2 + 2]) #  ???????????¨??????????????????????°?????????????????????´??°

    def query(self, a, b, k, l, r):
        # [a, b)???????°????????±??????? (0????????§b???????????????)
        # ??????????????¨?????????query(a, b, 0, 0, n)?????¢??§??????????????????k, l, r???????????????????????´??°?????????
        if r <= a or b <= l:        #  ?????????????????§??¨??????????????????
            return RMQ.INT_MAX
        if a <=l and r <= b:
            return self.dat[k]           #  ???????????°???????????????????????§????????°????????¨??????????????????????°?????????????????????????
        else:
            vl = self.query(a, b, k*2+1, l, (l+r)//2) #  ????????°????????????????°????
            vr = self.query(a, b, k*2+2, (l+r)//2, r) #  ????????°????????????????°????
            return min(vl, vr)

    def find(self, s, t):
        return self.query(s, t+1, 0, 0, self.n)


event = namedtuple('event', ['num', 'cost'])
def main(args):
    N, M = map(int, input().split())
    rq = RMQ(1001, 999999)
    events = [event(i+1, int(input())) for i in range(N)] #  ??¶????????????1??????????????§???i+1???????????????
    events.reverse()            #  ??¢?????????????????????????????¶???????????¨?????????????????????
    #  ?????????(e.cost)??§????????§????????¶????????????(e.num)??§RMQ?????´??°????????????
    # events???????´????????????????????????¢??????????????\??£??????????????§???????????????????????¶???????????£?????´????????¢??????????????¶???????????§??????????????????
    for e in events:
        rq.update(e.cost, e.num)

    # ????\¨
    # votes = []
    # for _ in range(M):
    #     v = int(input())
    #    result = rq.find(0, v)  #  ?????????v?????§???????????????????????§??????????????¢????????¶????????????
    #    votes.append(result)
    votes = [rq.find(0, int(input())) for _ in range(M)]
    ans = Counter(votes).most_common(1)[0][0]
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])

Measured memory_bytes: 8276
#include <iostream>
#include<map>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#define INF 1e16
#define rep(i,n) for(int i=0;i<n;i++)
#define NO cout<<"NO"<<endl;
#define YES cout << "YES"<<endl;
#define No cout << "No"<<endl;
#define Yes cout << "Yes"<<endl;
#define all(a) a.begin(),a.end()
#define P pair<int,int>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

//(int)'a'は97 (int)'A'は65 (int)'1'は49
//おまじない
//UnionFind

const int maxn=500;

int main(){
    
    int grid[maxn][maxn]={0};
    vector<P> ans1;
    vector<P> ans2;
    int h,w;
    cin >> h>>w;
    
    rep(i,h){
        rep(j,w){
            cin >> grid[i][j];
        }
    }
    
    int s=0;
    
    rep(i,h){
        if(s==0){
            rep(j,w-1){
                if(grid[i][j]%2==1){
                    grid[i][j+1]++;
                    ans1.push_back(P(i+1,j+1));
                    ans2.push_back(P(i+1,j+2));
                }
            }
            
            if(i+1<h&&grid[i][w-1]%2==1){
                grid[i+1][w-1]++;
                ans1.push_back(P(i+1,w));
                ans2.push_back(P(i+2,w));
            }
            s=w-1;
        }else{
            for(int j=w-1;j>0;j--){
                if(grid[i][j]%2==1){
                    grid[i][j-1]++;
                    ans1.push_back(P(i+1,j+1));
                    ans2.push_back(P(i+1,j));
                }
            }
            if(i+1<h&&grid[i][0]%2==1){
                grid[i+1][0]++;
                ans1.push_back(P(i+1,1));
                ans2.push_back(P(i+2,1));
            }
            
            s=0;
        }
    }
    
    cout << ans1.size()<<endl;
    
    rep(i,ans1.size()){
        cout << ans1[i].first << ' '<<ans1[i].second<<' '<<ans2[i].first<<' '<<ans2[i].second<<endl;
    }
    
    
    
    return 0;
}


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

class DisjointSet{
        public:
                int rank[10000],parent[10000];

                int find(int x){
                        if(x == parent[x]) return x;
                        else{
                                return parent[x] = find(parent[x]);
                        }
                }

                bool same(int x, int y){
                        return find(x) == find(y);
                }

                void unite(int x, int y){
                        x = find(x);
                        y = find(y);
                        if(rank[x] <= rank[y]){
                                parent[x] = y;
                        }else{
                                parent[y] = x;
                        }
                        if(rank[x] == rank[y]){
                                rank[y]++;
                        }
                }
                DisjointSet(){
                        for(int i = 0; i < 10000; i++){
                                parent[i] = i;
                                rank[i] = 0;
                        }
                }

};

int main(){
        int n,q;
        cin >> n >> q;
        DisjointSet dis;
        while(q--){
                int c,x,y;
                cin >> c >> x >> y;
                if(c == 0) dis.unite(x,y);
                else{
                        if(dis.same(x,y)) puts("1");
                        else puts("0");
                }
        }
        return 0;
}


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

int main()
{
    int N;
    cin >> N;
    vector<vector<long int>> dist(N, vector<long int>(N));
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) cin >> dist[i][j];
    }
    
    long int ans = 0;
    for (int i = 0; i < N-1; i++) {
        for(int j = i+1; j < N; j++) {
            bool use = true;
            for (int k = 0; k < N; k++) {
                if (i == k || j == k) continue;
                if (dist[i][j] > dist[i][k] + dist[k][j]) {
                    cout << "-1\n";
                    return 0;
                } else if (dist[i][j] == dist[i][k] + dist[k][j]) {
                    use = false;
                }
            }
            if (use) ans += dist[i][j];
        }
    }
    cout << ans << "\n";
}

Measured memory_bytes: 1024
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <iostream>
#include <cstring>
#include <string>
#include <vector>
#include <map>
#include <set>
#define MIN 1<<31-1
#define HMAX 1000000000000000000
#define MOD 1000000007
#define REP(i,n) for(ll i = 0; i < (n); i++)
#define RSET(s) for(set<ll>::iterator it=s.begin();it!=s.end();it++)
typedef long long int ll;
using namespace std;
struct D
{
	ll w;
	ll v;
	bool operator <(const D&one )const{
		return w<one.w;
	}
}Q[200000];
ll S[200000];
ll N[200000];
int main()
{
	ll n,c;
	cin>>n>>c;
	for(ll i=0;i<n;i++)
		cin>>Q[i].w>>Q[i].v;
	sort(Q,Q+n);
	ll MAX=0;ll now=0;ll las=0;
	for(ll i=0;i<n;i++)
	{
		now+=Q[i].v;
		now-=(Q[i].w-las);
		las=Q[i].w;
		MAX=max(MAX,now);
		S[i]=MAX;
	}
	las=c;
	MAX=0;now=0;
	for(ll i=n-1;i>=0;i--)
	{
		now+=Q[i].v;
		now-=(las-Q[i].w);
		las=Q[i].w;
		MAX=max(MAX,now);
		N[i]=MAX;
	}
	ll ans=max(N[0],S[n-1]);
	for(int i=0;i<n;i++)
	{
		ans=max(ans,S[i]-Q[i].w+N[i+1]);
	}
	for(int i=n-1;i>0;i--)
	{
		ans=max(ans,N[i]-(c-Q[i].w)+S[i-1]);
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 5632
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include <cmath>
#include <limits>
#include<set>
#include <iomanip>
#include <queue>
#include <map>
#include <string>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long long ll;
const long long INF=200000000000000;
const double inf=pow(10,10);
double pi=3.141592653589793;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const ll MOD = 1000000007;
void init(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout<<fixed;
}

ll getdigit(ll n){
	string s=to_string(n);
	return s.size();
}
	
int main(){
	init();
	ll N;
	cin>>N;
	ll ans=INF;
	for(ll i=1;i*i<=N;i++){
		if(N%i!=0)continue;
		ll a=i;
		ll b=N/i;
		ll num=max(getdigit(a),getdigit(b));
		ans=min(ans,num);
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define all(v) v.begin(),v.end()
#define P pair<int,int>
#define siz(s) (int)s.size()
#define pb push_back

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;
}
void cmps(vector<int>&v,int &i){
	i=lower_bound(all(v),i)-v.begin();
}
constexpr int mod = 1e9+7;
constexpr int inf = 3e18;

int f(int a,int b,int x){
	return (a*x/b)-a*(x/b);
}
signed main(){
	int A,B,N;
	cin>>A>>B>>N;
	int p=N/B*B-1;
	if(p==-1)cout<<f(A,B,N)<<endl;
	else cout<<max(f(A,B,N),f(A,B,p))<<endl;
}


Measured memory_bytes: 3584
n = int(input())
butnum = {}
for i in range(1,n+1):
    butnum[i] = int(input())
pushbut = 1
pushedbut =[]
jud = 0
for j in range(1,n+1):
    pushbut = butnum[pushbut]
    if pushbut == 2:
        print(j)
        jud = 1
        break
if jud == 0:
    print(-1)

Measured memory_bytes: 22112