akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef long long ll;
const long long INF = 1LL << 60;
typedef pair<int, int> P;
int main()
{
    int N, M;
    cin >> N >> M;

    vector<vector<int>> G(N);
    rep(i, M) {
        int A, B;
        cin >> A >> B;
        A--; B--;
        G[A].push_back(B);
        G[B].push_back(A);
    }

    vector<int> ans(N, -1);
    queue<int> que;
    que.push(0);
    ans[0] = 0;
    while(!que.empty()) {
        int v = que.front(); que.pop();
        for (auto to : G[v]) {
            if (ans[to] != -1) continue;
            ans[to] = v + 1;
            que.push(to);
        }
    }

    bool flag = true;
    repd(i, 1, N) {
        if (ans[i] == -1) flag = false;
    }

    if (flag) {
        cout << "Yes" << endl;
        repd(i, 1, N) cout << ans[i] << endl;
    }
    else cout << "No" << endl;
    return 0;
}

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

int main(){
    
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    int a,b,c;
    cin >> a >> b >> c;
    
    if(a == b && a != c){
        cout<<"Yes"<<" ";
    }
    else if(a == c && a != b)
    {
        cout<<"Yes"<<" ";
    }
    else if(b == c && b != a)
    {
        cout<<"Yes"<<" ";
    }
    else{
        cout<<"No"<<" ";
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>

using namespace std;
#define int long long int
const int INF = 1001001001001001LL;
const int MOD = 1000000007;

string f(char c){
    if(c == '0') return "0000";
    if(c == '1') return "0001";
    if(c == '2') return "0010";
    if(c == '3') return "0011";
    if(c == '4') return "0100";
    if(c == '5') return "0101";
    if(c == '6') return "0110";
    if(c == '7') return "0111";
    if(c == '8') return "1000";
    if(c == '9') return "1001";
    if(c == 'a') return "1010";
    if(c == 'b') return "1011";
    if(c == 'c') return "1100";
    if(c == 'd') return "1101";
    if(c == 'e') return "1110";
    if(c == 'f') return "1111";
    return "error";
}

int hgoe(int huga){
    if(huga == 0) return 5000000;
    if(huga == 1) return 2500000;
    if(huga == 2) return 1250000;
    if(huga == 3) return  625000;
    if(huga == 4) return  312500;
    if(huga == 5) return  156250;
    if(huga == 6) return   78125;
}

string g1(char c){
    if(c == '1') return "-";
    else return "";
}

string g2(string s){
    reverse(s.begin(), s.end());
    double mul = 1;
    int ret = 0;
    for(int i = 0; i < (int)s.size(); i++){
        ret += mul * (s[i] == '1');
        mul *= 2;
    }
    
    
    return to_string(ret);
}

string g3(string s){
    int ret = 0;
    for(int i = 0; i < (int)s.size(); i++){
        ret += hgoe(i) * (s[i] == '1');
    }

    string str = to_string(ret);
    while(str.size() != 7) str = "0" + str;

    while(str.size() != 1){
        if(str.back() == '0') str.pop_back();
        else break;
    }
    return str;
}

signed main(){
    
    int n; cin >> n;
    for(int i_ = 0; i_ < n; i_++){
        string s; cin >> s;
        string bin;
        for(int i = 0; i < 8; i++){
            bin = bin + f(s[i]);
        }
        cout << g1(bin[0]) << g2(bin.substr(1, 24)) << "." << g3(bin.substr(25, 7)) << endl;
    }
    
    

    return 0;
}



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

#define rep2(x,fr,to) for(int x=(fr);x<(to);x++)
#define rep(x,to) for(int x=0;x<(to);x++)
#define repr(x,fr,to) for(int x=(fr);x>=(to);x--)
#define all(c) c.begin(),c.end()
#define sz(v) (int)v.size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
typedef vector<ll> VL; const int MD = 1e9 + 7;
void dbg(){ cerr << "\n"; } template <typename T,typename ...T2> void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }



int main()
{
	cin.tie(0); ios_base::sync_with_stdio(false);
	ll n;
	cin >>n;
	cout << (n-1)* n /2 <<"\n";
	return 0;
	
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <map>

#define MAX_V 600000
#define LL long long
using namespace std;

const int INF = 1000000000;

struct edge { int to, cost; };
typedef pair<int, int> P;






int V;
vector<edge> G[MAX_V];
int d[MAX_V];

void dijkstra(int s){
    priority_queue<P, vector<P>, greater<P> > que;
    fill(d,d+V, INF);
    d[s] = 0;
    que.push(P(0,s));
    while(!que.empty()){
        P p = que.top(); que.pop();
        int v = p.second;
        if(d[v]<p.first) continue;
        for(int i=0;i<G[v].size();i++){
            edge e = G[v][i];
            if(d[e.to]>d[v]+e.cost){
                d[e.to] = d[v]+e.cost;
                que.push(P(d[e.to],e.to));
            }
        }
    }
}

int input[3][6*200000];
map<P, int> m;
int cnt2 = 0;
int N, M;
void f(P x, P y, int c){
    input[0][cnt2] = m[x]; input[1][cnt2] = m[y], input[2][cnt2] = c;
    cnt2++; 
}

int main(void)
{
    
    cin >> N >> M;
    int cnt1 = 1;
    
    for(int i=0;i<N;i++){
        m.insert(make_pair(make_pair(i,-1), cnt1++));
    }
    
    
    
    for(int i=0;i<M;i++){
        int a,b,c;
        scanf(" %d %d %d", &a, &b, &c);
        a--; b--;
        P eg0 = make_pair(a,c), eg1 = make_pair(b,c); 
        P ng0 = make_pair(a,-1), ng1 = make_pair(b,-1);
        if(m[eg0]==0){
            m[eg0] = cnt1;
            cnt1++;
            f(eg0,ng0,0); f(ng0,eg0,1);
        }
        if(m[eg1]==0){
            m[eg1] = cnt1;
            cnt1++;
            f(eg1,ng1,0); f(ng1,eg1,1);
        }
        f(eg0,eg1,0);
        f(eg1,eg0,0);
    }
    int end = m[make_pair(N-1,-1)];
    for(int i=0;i<cnt2;i++){
        edge *e = new edge;
        e->to = input[1][i]; e->cost = input[2][i];
        G[input[0][i]].push_back(*e);
    }
    V = cnt1;
    dijkstra(1);
    
    
    int ans =(d[end]==INF?-1:d[end]);
    cout << ans << endl;
    return (0);
}


Measured memory_bytes: 119284
#include <bits/stdc++.h>
#define DAU  ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define PLEC return 0;
using namespace std;
using VI = vector<int>;
using VVI = vector<VI>;
VI cnt;
VVI g;
int n, x, y;
int main() {
    DAU
    cin >> n >> x >> y;
    g = VVI(n + 1);
    for (int i = 1; i < n; ++i) {
        g[i].emplace_back(i + 1);
        g[i + 1].emplace_back(i);
    }
    g[x].emplace_back(y);
    g[y].emplace_back(x);
    cnt = VI(n + 1);
    for (int i = 1; i <= n; ++i) {
        VI d(n + 1, 1e9);
        queue<int> q;
        q.emplace(i);
        d[i] = 0;
        while (!q.empty()) {
            x = q.front();
            q.pop();
            for (const int& y : g[x])
                if (d[y] > d[x] + 1)
                    d[y] = d[x] + 1, q.emplace(y);
        }
        for (int i = 1; i <= n; ++i)
            if (d[i] < n)
                ++cnt[d[i]];
    }
    for (int i = 1; i < n; ++i)
        cout << cnt[i] / 2 << '\n';
    PLEC
}


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

int main()
{
    int n;
    cin>>n;
    vector<long double>vec(n);
    for(int i=0;i<n;i++){
        cin>>vec[i];
    }
    long double dp[(n/2)+2][n+2],ans=0;
    memset(dp,0,sizeof dp);
    dp[0][0]=1;
    for(int i=0;i<=n/2;i++){
    for(int j=1;j<=n;j++){
        if(i==0){
            dp[i][j]=vec[j-1]*dp[i][j-1];
        }else{
        if(i==j){
            dp[i][j]=dp[i-1][j-1]*(1-vec[j-1]);
        }
        else{
            dp[i][j]=dp[i-1][j-1]*(1-vec[j-1])+dp[i][j-1]*vec[j-1];
        }
        }
    }

    }
    for(int i=0;i<=n/2;i++)ans+=dp[i][n];
    cout.precision(15);
    cout<<ans;

    return 0;
}


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

int main() {
  int x,n;
  cin >> x >> n;
  
  vector<int>	map(102);
  for(int i=0;i<n;i++){
    int key;
    cin >> key;
    map.at(key)=key;
  }
  
  for(int sa=0;sa<100;sa++){
    if(map.at(x-sa)==0){
      cout << x-sa;
      return 0;
    }
    if(map.at(x+sa)==0){
      cout << x+sa;
      return 0;
    }
  }
    
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = (int)(a); i <= (int)(n); ++i)
#define rrep(i, a, n) for (int i = (int)(a); i >= (int)(n); --i)
#define debug(x) cerr << #x << " = " << x << "\n"
#define debugv(x) \
  rep(f, 0, (x.size() - 1)) cerr << x[f] << (f == (x.size() - 1) ? "\n" : " ")
#define debug2(x, y)                       \
  cerr << "(" << #x << "," << #y << ") = " \
       << "(" << x << "," << y << ")\n"
#define all(x) x.begin(), x.end()
#define each(a, x) for (auto& a : (x))
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define int long long
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
const int MX = 1e5 + 5, INF = 1e9, MOD = 1e9 + 7;

int N, M;
vi va, vb;
int K, S;
void input() {
  cin >> N >> K >> S;
  ;
  ;
}
void solve() {
  if (S == INF) {
    rep(i, 1, N) {
      if (i <= K) {
        cout << S << " ";
      } else {
        cout << S - 111 << " ";
      }
    }
    cout << endl;
    return;
  } else {
    rep(i, 1, N) {
      if (i <= K) {
        cout << S << " ";
      } else {
        cout << INF << " ";
      }
    }
    cout << endl;
    return;
  }

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

Measured memory_bytes: 1280
import java.util.Scanner;

public class Main {
	public static void main (String[] args) {
		Scanner scanner = new Scanner(System.in);
		int a = scanner.nextInt();
		String op = scanner.next();
		int b = scanner.nextInt();
		int ans = 0;
		if (op.equals("+")) ans = a + b;
		if (op.equals("-")) ans = a - b;
		System.out.println(ans);
	}
} 

Measured memory_bytes: 23124
#include <stdio.h>
int main() {
	int n,ans=0,p[20]={};
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d", &p[i]);
	}
	for (int i = 1; i < n-1; i++) {
		if(((p[i-1]<p[i])&&(p[i]<p[i+1]))||
			((p[i+1]<p[i])&&(p[i]<p[i-1]))){
			ans++;
		}
	}
	printf("%d\n", ans);
	return 0;
}


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

#define dump(x) cout << (x) << endl
#define Int int64_t
#define fi first
#define se second
 
Int INF = 1e18;
Int mod = 1e9+7;
//Int mod = 998244353;

int main() {
    Int h, w, d;
    cin >> h >> w >> d;
    Int a[301][301] = {};
    map<Int, pair<Int, Int>> mp;
    for (Int i = 0; i < h; i++) {
        for (Int j = 0; j < w; j++) {
            cin >> a[i][j];
            mp[a[i][j]] = {i + 1, j + 1};
        }
    }
    vector<Int> e(h * w + 1, 0);
    for (Int i = d + 1; i <= h * w; i++) {
        e[i] = abs(mp[i].fi - mp[i - d].fi) + abs(mp[i].se - mp[i - d].se);
    }
    for (Int i = 1; i <= h * w - d; i++) {
        e[i + d] += e[i];
    }
    // for (Int i = 1; i <= h * w; i++) {
    //     cout << i << " " << e[i] << endl;
    // }
    Int q;
    cin >> q;
    vector<Int> l(q), r(q);
    for (Int i = 0; i < q; i++) {
        cin >> l[i] >> r[i];
    }
    for (Int i = 0; i < q; i++) {
        dump(e[r[i]] - e[l[i]]);
    }
    return 0;
}

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

#define reps(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   reps(i,0,n)
#define all(x) (x).begin(),(x).end()
#define INF (2000000000)
#define MOD (1000000007)
#define PI (acos(-1))

int main(){
  int x,y;
  cin >> x >> y;
  if(x%y==0){
    cout << -1 << endl;
  }else{
    cout << x << endl;
  }
}

Measured memory_bytes: 256
N, M = map(int, input().split())
mod = 10**9 + 7

def comb(n, r, mod):
    if r<0 or r>n:
        return 0
    r = min(r, n-r)
    return fac[n] * (finv[r] * finv[n-r] % mod) % mod

def perm(n, r, mod):
    if r<0 or r>n:
        return 0
    return (fac[n] * finv[n-r]) % mod

fac = [1, 1]
finv = [1, 1]
inv = [0, 1]
for i in range(2, max(N + 1, M + 1)):
    fac.append((fac[-1] * i) % mod)
    inv.append((-inv[mod%i] * (mod//i)) % mod)
    finv.append((finv[-1] * inv[-1]) % mod)
ans = 0
for i in range(N+1):
    ans += (-1)**i * ((comb(N, i, mod) * perm(M, i, mod))%mod * (perm(M-i, N-i, mod)**2)%mod)%mod
    ans %= mod
print(ans)

Measured memory_bytes: 166696
S=input()
d={}
for c in S:
    if c not in d.keys():
        d[c]=1
    else:
        d[c] += 1
j=True
for i in d.values():
    if i!=2:
        j=False
        break

if j:
    print("Yes")
else:
    print("No") 

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

 int main(){
    int i,j,m,h,k;
    char card[201],card1[201],card2[201];

    for(i=0;;i++){
       scanf("%s",&card);
       if(strcmp(card,"-")==0)break;

       scanf("%d",&m);
       for(j=0;j<m;j++){
            scanf("%d",&h);
            strcpy(card1,card);
            strcpy(card,card1+h);
            strncat(card,card1,h);
            }
       printf("%s\n",card);
       }
    return 0;
    }


Measured memory_bytes: 2120
// g++ -I ~/Documents/AtCoder -std=gnu++14 -o test ~/Documents/AtCoder/test.cpp && ./test && rm test
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define all(v)    (v).begin(), (v).end()
#define in        ([]{int n; cin>>n; return n;}())
using namespace std;
using lint = int64_t;

int main() { cin.tie(0); ios::sync_with_stdio(false);
    int N = in;

    vector<vector<pair<int,bool>>>  to(N);
    rep( i, N-1 ) {
        int u=in-1, v=in-1; bool w=in%2;
        to[u].push_back( make_pair(v,w) );
        to[v].push_back( make_pair(u,w) );
    }

    vector<int> ans(N, -1); ans[0] = 0;
    queue <int> q;          q.push(0);
    while( !q.empty() ) {
        int u = q.front(); q.pop();
        for( pair<int,bool> p : to[u] ) {
            int v = p.first;
            if( ans[v] != -1 ) continue;
            ans[v] = ans[u] != p.second;
            q.push(v);
        }
    }

    rep( i, N ) cout << ans[i] << '\n';
}


Measured memory_bytes: 6784
import sys
stdin = sys.stdin
sys.setrecursionlimit(10 ** 7)
 
i_i = lambda: int(i_s())
i_l = lambda: list(map(int, stdin.readline().split()))
i_s = lambda: stdin.readline().rstrip()

x,y,a,b,c = i_l()
p = i_l()
q = i_l()
r = i_l()

d = []
d.extend(sorted(p)[::-1][:x])
d.extend(sorted(q)[::-1][:y])
d.extend(sorted(r)[::-1])
print(sum(sorted(d)[::-1][:x+y]))

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

int main()
{
    int N, P;
    string S;
    cin >> N >> P >> S;

    vector<int> digit(N);
    for (int i = 0; i < N; i++)
    {
        digit[i] = S[i] - '0';
    }

    if (P == 2 || P == 5)
    {
        long long ans = 0;
        for (int i = 0; i < N; i++)
        {
            if (digit[i] % P == 0)
            {
                ans += i + 1;
            }
        }
        cout << ans << endl;
        return 0;
    }

    reverse(digit.begin(), digit.end());
    vector<int> mod(N + 1, 0);
    int pow = 1;
    for (int i = 1; i <= N; i++)
    {
        mod[i] = (mod[i - 1] + digit[i - 1] * pow) % P;
        pow *= 10;
        pow %= P;
    }

    long long ans = 0;
    vector<int> count(P, 0);
    for (int m : mod)
    {
        ans += count[m];
        count[m]++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 2180
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
 
vector<int> dp;
 
 
int main() {
	// your code goes here
	
	int n;
	
	cin>>n;
	
		int k;
	cin>>k;
	
	int arr[n];
	
	for(int i=0;i<n;i++)
	cin>>arr[i];
	

	
	dp.assign(n, INT_MAX);
	
	dp[0]=0;
	
	dp[1]=abs(arr[0]-arr[1]);
	
	for(int i=2;i<n;i++)
	{
		for(int j=1;j<=k&&i-j>=0;j++)
		{
			
		dp[i]=min(dp[i],abs(arr[i]-arr[i-j])+dp[i-j]);
		
		}
	}
	
	cout<<dp[n-1];
	
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define pi 2*acos(0.0)
#define ll long long
#define sf1(a); scanf("%d",&a);
#define sf2(a,b); scanf("%d %d",&a, &b);
#define sf3(a,b,c); scanf("%d %d %d",&a, &b,&c);
#define sf4(a,b,c,d); scanf("%d %d %d %d",&a, &b,&c,&d);
#define pf1(a); printf("%d\n",a);
#define pf2(a,b); printf("%d %d\n",a,b);
#define pf3(a,b,c); printf("%d %d %d\n",a,b,c);
#define pf4(a,b,c,d); printf("%d %d %d %d\n",a,b,c,d);

using namespace std;

int main()
{
    int n,i;
    sf2(n,i);
    int ans = n-i+1;
    pf1(ans);
    return 0;
}


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

int f(int A){
    int rec = 0;
    while(A > 0){
        rec += A % 10;
        A /= 10;
    }

    return rec;
}

int main(){

    int n; cin >> n;
    int ans = 100100100;
    for(int A = 1; A < n; A++){
        int B = n - A;
        int tmp = f(A) + f(B);
        ans = min(ans, tmp);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import itertools

n,m = map(int,input().split())

ab = []
ans = 0
for _ in range(m):
	ab.append(list(map(int,input().split())))

l = list(itertools.permutations(range(1,n+1)))

for i in range(len(l)):
	count = 0
	for j in range(len(l[i])-1):
		tmp = [l[i][j],l[i][j+1]]
		if j == 0:
			if tmp[0] != 1:
				break
		tmp.sort()
		if tmp not in ab:
			break
		count += 1
		if count == n-1:
			ans += 1

print(ans)


Measured memory_bytes: 8052
a, b, c, x, y = map(int, input().split())

if a >= 2*c and b >= 2*c:
    print(max(x, y) * 2*c)
elif a >= 2*c:
    print(x * 2*c + max(0, (y - x) * b))
elif b >= 2*c:
    print(y * 2*c + max(0, (x - y) * a))
elif a + b > 2*c and x < y:
    print(x * 2*c + (y - x) * b)
elif a + b > 2*c:
    print(y * 2*c + (x - y) * a)
else:
    print(x * a + y * b)

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

using namespace std;

int main()
{
    int n,m;
    map<string,int> check;
    
    cin >> n;
    for(int i=0;i<n;i++){
        string s;
        cin >> s;
        check[s]++;
    }
    
    cin >> m;
    for(int i=0;i<m;i++){
        string t;
        cin >> t;
        check[t]--;
    }

    int ans=0;
    for(auto m: check){
        if(ans<m.second) ans=m.second;
    }

    cout << ans << endl;
}

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

int main(void){
  int n,m[4]={0};
  
  cin >> n;
  for (int i=0; i<n; i++){
    int t; cin >> t;
    m[t%4]++;
  }
  if (m[2]+m[0]==n) cout << "Yes" << endl;
  else if (m[0]>=n/2) cout << "Yes" << endl;
  else if (m[0]>=(n-m[2]+1)/2) cout << "Yes" << endl;
  else cout << "No" << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <climits>
#include <iostream>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <vector>
#include <sstream>
#include <typeinfo>
#include <fstream>

#define DIV 1000000007

using namespace std;

string T;
const unsigned long long B = 1000000007;
unsigned long long hs[100005];
unsigned long long pw[100005];

// 部分文字列[l, r)のローリングハッシュ値計算
// O(1)
unsigned long long hhash(int l, int r) {
	return ((hs[r] - hs[l] * pw[r - l]));
}



int cal(int len){
	set<unsigned long long> done;
	for(int i = 0; i <= T.size() - len; i++){
		//cout << T.substr(i, len) << endl;
		done.insert(hhash(i, i + len));
	}
	return done.size();
}

int main(){
	cin >> T;
	int ans = 0;

	int left = 0;
	int right = T.size();

	hs[0] = 0;
	pw[0] = 1;
	for (int j = 0; j < T.size(); j++) {
		pw[j + 1] = pw[j] * B;
		hs[j + 1] = (hs[j] * B + T[j]);
	}
 

	while(left + 10 < right){
		//cout << "left = " << left << "right = " <<  right << endl;
		int x0 = left;
		int x3 = right;
		int x1 = (x0 + (x3-x0)/3);
		int x2 = (x0 + (x3-x0)*2/3);
		//cout << "cal(" << x1 << ") = " << cal(x1) << endl;
		//cout << "cal(" << x2 << ") = " << cal(x2) << endl;
		if(cal(x1) > cal(x2)){
			right = x2;
		}else{
			left = x1;
		}
	}
	for(int i = left; i <= min((int)T.size(), left + 10); i++){
		//cout << "cal(" << i << ")=" << cal(i) << endl;
		ans = max(cal(i), ans);
	}
	cout << ans << endl;
}


Measured memory_bytes: 6656
import java.util.Scanner;

public class Main {
	public static void main(String[]args) {
		try(Scanner scan = new Scanner(System.in)){
			
			int N = scan.nextInt();
			int x = scan.nextInt();
			int[]a = new int[N];
			for(int i = 0;i<N;i++)a[i] = scan.nextInt();
			
			long goukei = 0;
			
			for(int i = 0;i<N-1;i++) {
				if(a[i]==0&&a[i+1]==0)continue;
				if(a[i]==0&&a[i+1]>x) {
					goukei+=a[i+1]-x;
					a[i+1] = x;
				}else if(a[i+1]==0&&a[i]>x) {
					goukei+=a[i]-x;
					a[i] = x;
				}else if(a[i]+a[i+1]>x) {
					int h = a[i]+a[i+1]-x;
					if(a[i+1]>=h) {
						goukei+=h;
						a[i+1]-=h;
					}else {
						goukei+=a[i+1];
						h-=a[i+1];
						a[i+1]=0;
						goukei+=h;
						a[i]-=h;
					}
				}
			}
			
			for(int i = 0;i<N;i++) {
				//System.out.print(a[i]+" ");
			}
			
			System.out.println(goukei);
			
			
			
		}
		
		
	}
		

}


Measured memory_bytes: 50868
import math

def get_gcd(a, b):
    while b:
        a, b = b, a % b
    return a

def get_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        #if ((i == 2 or i % 2 != 0) and n % i == 0):
        if (n % i == 0):
            divisors.append(i)
            #if (((n // i) == 2 or (n // i) % 2 != 0) and i != n // i):
            if (i != n // i):
                divisors.append(n//i)

    return sorted(divisors)[::-1]

a, b = map(int, input().split())

gcd = get_gcd(a, b)
list = get_divisors(gcd)

#print(list)

count = 0
length = len(list)
for i in range(length):
    is_ok = True
  
    for j in range(i+1, length):
        if (get_gcd(list[i], list[j]) != 1):
            is_ok = False
            break
    
    if is_ok:
        count += 1

print(count)


Measured memory_bytes: 3388
N = int(input())
xy = [map(int, input().split()) for _ in range(N)]
x, y = [list(i) for i in zip(*xy)]
ans="No"
for i in range(0,N-2):
    if x[i]==y[i] and x[i+1]==y[i+1] and x[i+2]==y[i+2]:
        ans="Yes"
print(ans)

Measured memory_bytes: 9188
#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<deque>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const int inf=1e9+7;
const ll INF=1LL<<60 ;
const ll mod=1e9+7 ;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
#define debug(x)  cout << #x << " = " << (x) << endl;
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; }
//#define int long long

void solve() {
	int n, m; cin >> n >> m;
    vector<vector<int>> G(n);
    rep(i, m) {
        int s, t; cin >> s >> t; --s; --t;
        G[s].push_back(t);
    }
    vector<double> dp(n, 0);
    //DAGなのでdp
    for(int i = n - 2; i >= 0; --i) {
        int cnt = (int)G[i].size();
        for(auto e: G[i]) {
            dp[i] += (dp[e] + 1.0) / (double)cnt;
        }
    }
    double ans = dp[0];
    //探索するもののを減らすべし
    rep(i, n - 1) {
        vector<double> dp2(n, 0);
        int k = 0;
        double d = -1;
        for(auto e: G[i]) {
            if(dp[e] > d) k = e, d = dp[e];
        }
        if(G[i].size() == 1) continue;
        for(int j = n - 2; j >= 0; --j) {
            if(j > i) dp2[j] = dp[j];
            else if(j == i) {
                int cnt = (int) G[j].size();
                for(auto e: G[j]) {
                    if(e != k) dp2[j] += (dp2[e] + 1.0) / (double)(cnt - 1);
                }
            }
            else {
                int cnt = (int)G[j].size();
                for(auto e: G[j]) {
                    dp2[j] += (dp2[e] + 1.0) / (double)cnt;
                }
            }
        }
        chmin(ans, dp2[0]);
    }
    cout << ans << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(10);
	//init();
	solve();
	//cout << "finish" << endl;
    return 0;
}

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

const int MAXN = 100010;
int B[MAXN], A[MAXN], n, idx, fa[MAXN], ans;
std::map<int, int> M;
int find(int x) { return x == fa[x] ? x : fa[x] = find(fa[x]); }
void merge(int x, int y) {
	x = find(x), y = find(y); ++ans;
	if (x != y) fa[x] = y, --ans;
}
int g(int x) { if (!M[x]) M[x] = ++idx, fa[idx] = idx, ++ans; return M[x]; }
int main() {
	std::ios_base::sync_with_stdio(false), std::cin.tie(0);
	std::cin >> n;
	for (int i = 1; i <= n; ++i) std::cin >> A[i], A[n + 1] ^= A[i];
	for (int i = 1; i <= n; ++i) std::cin >> B[i], B[n + 1] ^= B[i];
	for (int i = 1; i <= n + 1; ++i) ++M[A[i]], --M[B[i]];
	for (auto t : M) if (t.second) return std::cout << -1 << std::endl, 0;
	for (int i = 1; i <= n + 1; ++i) if (A[i] != B[i]) merge(g(A[i]), g(B[i]));
	std::cout << ans - (!!M[A[n + 1]]) - (A[n + 1] != B[n + 1]) << std::endl;
	return 0;
}


Measured memory_bytes: 7680
#include<iostream>

using namespace std;

int main(){
	
	int i ,a, sum1=0,sum2=0;
	
	for(i=0;i<4;i++){
		cin >> a;
		sum1+= a;
	}
	for(i=0;i<4;i++){
		cin >> a;
		sum2+= a;
	}
	if(sum1>=sum2)cout<<sum1<<endl;
	else cout<<sum2<<endl;
	
	return 0;
	
}
	

Measured memory_bytes: 0
#!/usr/bin/env python3
# N,M = map(int,sys.stdin.readline().split())
# a = tuple(map(int,sys.stdin.readline().split())) # single line with multi param
# a = tuple(int(sys.stdin.readline()) for _ in range(N)) # multi line with single param
# a = tuple(tuple(map(int,sys.stdin.readline().rstrip().split())) for _ in range(N)) # multi line with multi param
# s = sys.stdin.readline().rstrip()
# N = int(sys.stdin.readline())
# INF = float("inf")
import sys,collections

N = int(sys.stdin.readline())
A = tuple(map(int,sys.stdin.readline().split())) # single line with multi param
Q = int(sys.stdin.readline())
BC = tuple(tuple(map(int,sys.stdin.readline().rstrip().split())) for _ in range(Q)) # multi line with multi param
co = collections.Counter(A)
s = sum(A)

for b,c in BC:
    if b in co:
        n = co[b]
        del(co[b])
        co[c] += n
        s += (c-b)*n
    print(s)


Measured memory_bytes: 32728
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using V = vector<ll>;
#define _GLIBCXX_DEBUG
#define rep(i, a, b) for(int i = a; i < b; i++)
#define ALL(v) v.begin(), v.end()

int main(){
    int n; cin>>n;
    cout<<800*n-200*(n/15)<<endl;
}


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

export class Reader {
    lines: string[];
    currentLine: number;

    constructor() {
        this.lines = fs.readFileSync("/dev/stdin", "utf8").trim().split("\n");
        this.currentLine = 0;
    }

    readLine(): string {
        return this.lines[this.currentLine++];
    }

	readChars(): string[] {
		let S = this.readLine();
		return new Array(S.length).fill(null).map((_, i) => S.charAt(i));
	}

    readInt(): number {
        return Number(this.readLine());
    }

    readInts(): number[] {
        return this.readLine().split(" ").map(Number);
    }
} 


let reader = new Reader();
let [A, B, Q] = reader.readInts();

let S: number[] = [],
	T: number[] = [];

for(let i=0; i<A; i++) {
	S.push(reader.readInt());
}

for(let i=0; i<B; i++) {
	T.push(reader.readInt());
}

function upperBound(array: number[], value: number): number {
	let low = 0,
		high = array.length-1;
	while (low < high) {
		let mid = Math.floor((low+high)/2);
		if (array[mid] < value) {
			low = mid+1;
		} else {
			high = mid;
		}
	}
	return low;
}

// console.log('S', S);
// console.log('T', T);

function distance(x: number, s: number, t: number): number {
	return Math.min(Math.abs(x-s)+Math.abs(s-t),
	     			Math.abs(x-t)+Math.abs(t-s));
}

for(let i=0; i<Q; i++) {
	let x = reader.readInt();
	let upperS = upperBound(S, x),
		upperT = upperBound(T, x);
	// console.log('upperS', 'upperT', upperS, upperT);
	let answer = distance(x, S[upperS], T[upperT]);
	if (upperS > 0) {
		answer = Math.min(answer, distance(x, S[upperS-1], T[upperT]));
	}
	if (upperT > 0) {
		answer = Math.min(answer, distance(x, S[upperS], T[upperT-1]));
	}
	if (upperS > 0 && upperT > 0) {
		answer = Math.min(answer, distance(x, S[upperS-1], T[upperT-1]));
	}
	console.log(answer);
}


Measured memory_bytes: 88692
n, m, k = map(int, input().split())
a_list = list(map(int, input().strip().split()))
b_list = list(map(int, input().strip().split()))

a, b = [0], [0]
for i in range(n):
    a.append(a[i] + a_list[i])
for j in range(m):
    b.append(b[j] + b_list[j])

ans, j = 0, m
for i in range(n + 1):
    if a[i] > k:
        break
    while b[j] > k - a[i]:
        j -= 1
    ans = max(ans, i + j)
print(ans)

Measured memory_bytes: 47140
#include <iostream>
#include <string>
using namespace std;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s,t;
    cin >> s >> t;
    string ans,b;
    for(int i = 0; i < 50; ++i) ans += 'z';
    b = ans;
    for(int i = 0; i < s.size(); ++i){
        bool flag = true;
        for(int j = 0; j < t.size(); j++){
            if(i+j > s.size() -1) {
                flag = false;
                break;
            }
            if(s[i+j] == '?') continue;
            if(s[i+j] != t[j]) flag = false;
        }
        if(flag){
            string tmp = s;
            for(int k = 0; k < s.size(); ++k){
                if(i <= k && k < i+t.size()) tmp[k] = t[k-i];
                else if(tmp[k] == '?') tmp[k] = 'a';
            }
            ans = min(ans, tmp);
        }
    }
    if(ans == b) cout << "UNRESTORABLE" << endl;
    else cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#include <complex>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,Q,A,B,C,L,R;
string S,T;
const ll MOD = (1e+9) + 7;
const ll INF = 1LL << 60;
const long double EPS = 1e-9;
typedef pair<ll,ll> P;

typedef vector<P> vp;
typedef vector<vp> matP;

bool ok(ll len){
    vector<string> dic(N - len + 1);
    set<string> sub;
    rep(i,N - len + 1){
        dic[i] = S.substr(i,len);
        if(sub.find(dic[i]) != sub.end()) return true;
        if(i - len + 1 >= 0) sub.insert(dic[i - len + 1]);
    }
    return false;
}
int main() {
    cin>>N>>S;
    ll lb = 0, ub = N/2 + 1;
    while(ub - lb > 1){
        ll cen = (ub + lb)/2;
        (ok(cen) ? lb : ub) = cen;
    }
    cout<<lb<<endl;
}

Measured memory_bytes: 6540
import Control.Applicative
import Data.List
import qualified Control.Monad as Monad

main :: IO ()
main = loopPutNumbers  

loopPutNumbers :: IO ()
loopPutNumbers = do
  [x,y] <- (map read).words <$> getLine
  Monad.when(x /= 0 || y /= 0) $ do
    putStrLn  $ if (x < y)
      then unwords $ show <$> [x,y]
      else unwords $ show <$> [y,x]
    loopPutNumbers


Measured memory_bytes: 4008
#include <vector>
#include <iostream>
#include <iomanip>
#include <map>
#include <string.h>
#include <cstring>
#include <queue>
#include <limits>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <cmath>
#include <stdio.h>
#include <set>
#include <cstdio>
#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()
#define pb push_back
#define FOR(i, a) for(int i = 0; i < (a); i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef long double ld;
const int N = 55;
string s;
int a, b;
int main() {
    while (cin >> a >> b >> s) {
        int n = s.size();
        bool ok = true;
        for (int i = 0; i < a; i++) ok &= (s[i] >= '0' && s[i] <= '9');
        ok &= s[a] == '-';
        for (int i = a + 1; i < n; i++) ok &= (s[i] >='0' && s[i] <= '9');
        puts(ok ? "Yes" : "No");
    }
    return 0;
}




Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <string>
#include <numeric>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <limits>
using namespace std;
#define INF 1000000007
#define ll long long
#define rep(i_, start, end) for(ll i_=(ll)start; i_<(ll)end; i_++)
#define print(a) cout << a << endl;
#define printarray(a, len) rep(ii,0,len) cout << a[ii] << " ";
#define printarray2(aa, len) rep(ij,0,len) printarray(aa[ij], aa[ij].size()); print("");

int main(){
  ll n, k, h, ans=0;
  cin >> n >> k;
  rep(i, 0, n){
    cin >> h;
    if (h >= k) ans++;
  }
  print(ans);
  
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#define MOD 1000000007

int main()
{
	int n,m,i,j,x;
	int slst[2010],tlst[2010];
	int dp[2010][2010]={0};
	int ans;
	scanf("%d %d",&n,&m);
	for(i=0;i<n;i++)
	{
		scanf("%d",slst+i);
	}
	for(j=0;j<m;j++)
	{
		scanf("%d",tlst+j);
	}
	for(i=0;i<=n;i++)
	{
		for(j=0;j<=m;j++)
		{
			if(i==0||j==0)dp[i][j]=1;//空集合ぶん
			else if(slst[i-1]==tlst[j-1])dp[i][j]=(dp[i-1][j]+dp[i][j-1])%MOD;
			else 
			{
				x=(dp[i-1][j]+dp[i][j-1])%MOD;
				if(x>=dp[i-1][j-1])dp[i][j]=(x-dp[i-1][j-1]);
				else dp[i][j]=((x+MOD)-dp[i-1][j-1])%MOD;
			}
			//printf("%d ",dp[i][j]);
		}
		//printf("\n");
	}
	
	
	printf("%d",dp[n][m]);
	return 0;
}


Measured memory_bytes: 16000
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <string>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
#include <numeric>
#include <queue>
using namespace std;
#define loop(i,N) for(ll (i)=0; (i)<(N);++(i))
struct TEMP_OMAZINAI_ { TEMP_OMAZINAI_() { std::ios::sync_with_stdio(false); std::cin.tie(0); } } TEMP__omazinai_instance__;
#define INF ((1LL<<61) + (1<<29))
#define YesNo(x) {std::cout << ((x)?"Yes":"No") << std::endl;}
#define YESNO(x) {std::cout << ((x)?"YES":"NO") << std::endl;}
#define OddEven(x) {std::cout << ((x)%2?"Odd":"Even") << std::endl;}
#define ODDEVEN(x) {std::cout << ((x)%2?"ODD":"EVEN") << std::endl;}
typedef long long int ll;
ll my_gcd(ll a, ll b) { return b ? my_gcd(b, a%b) : a; };
void TEMP_INPUT_IMPL_() {};
template <class T, class... Args> void TEMP_INPUT_IMPL_(T& dest, Args&... args) { cin >> dest; TEMP_INPUT_IMPL_(args...); }
void TEMP_OUTPUT_IMPL_() {};
template <class T, class... Args> void TEMP_OUTPUT_IMPL_(T dest, Args... args) { cout << dest << (sizeof...(Args) ? " " : ""); TEMP_OUTPUT_IMPL_(args...); }
#define in(type, ...) type __VA_ARGS__; TEMP_INPUT_IMPL_(__VA_ARGS__)
#define in_v(type, name, cnt) vector<type> name(cnt); loop(i, cnt) cin >> name[i];
#define sort_v(v) std::sort(v.begin(), v.end())
#define rsort_v(v) std::sort(v.rbegin(), v.rend())
#define unique_v(v) v.erase(std::unique(v.begin(), v.end()), v.end()) //必ずソート後に実行
#define out(...) (TEMP_OUTPUT_IMPL_(__VA_ARGS__), std::cout<<std::endl)
#define set_fix(x) ((std::cerr<<std::fixed<<std::setprecision(x)),(std::cout<<std::fixed<<std::setprecision(x)))
//小さい方に寄る
#define space_op(x, y, a, b, c) ([](auto x_, auto y_, auto a_, auto b_, auto c_){if(x_<y_)return a_;if(x_>y_)return c_;return b_;}(x,y,a,b,c))
#define space_out(x, y, a, b, c) out(space_op(x, y, a, b, c))

// ^^^ Template ^^^ //

int main() {
	in(ll, N);
	vector<ll> A(N), B(N);
	vector<pair<ll, ll>> C(N);
	ll all = 0;
	loop(i, N) {
		in(ll, a, b);
		A[i] = a;
		B[i] = b;
		C[i] = { a + b, i };
		all += a + b;
	}
	rsort_v(C);
	ll ans = 0;
	loop(i, N){
		ll n = C[i].second;
		if (i & 1) {
			ans -= B[n];
		} else {
			ans += A[n];
		}
	}
	out(ans);
}

Measured memory_bytes: 3456
using System;
using System.Collections.Generic;
namespace I_am_the_brown_coder{
    class Inonoa{
        static void Main(){
            int n = int.Parse(Console.ReadLine());
            int[][] xy = new int[n][];
            for(int i=0;i<n;i++){
                string[] x_y = Console.ReadLine().Split();
                xy[i] = new int[2]{int.Parse(x_y[0]),int.Parse(x_y[1])};
            }

            Array.Sort(xy,Compare);

            int ans = 100;

            if(n==1){
                        Console.WriteLine(1);
                        return;
                    }

            for(int i=0;i<n-1;i++){
                for(int j=i+1;j<n;j++){
                    int[] pq = new int[2]{xy[j][0]-xy[i][0],xy[j][1]-xy[i][1]};
                    List<int[]> lst = new List<int[]>();
                    lst.AddRange(xy);
                    int ima = 0;
                    int k = 1;
                    int cost = 0;
                    
                    while(lst.Count>0){
                        while(true){
                            if(ima+k==lst.Count){
                                lst.Remove(lst[ima]);
                                ima = 0;
                                k = 1;
                                cost ++;
                                break;
                            }
                            if(lst[ima+k][0]-lst[ima][0]==pq[0]){
                                if(lst[ima+k][1]-lst[ima][1]==pq[1]){
                                    lst.Remove(lst[ima]);
                                    ima = ima+k-1;
                                    k = 1;
                                    continue;
                                }else{
                                    k++;
                                    continue;
                                }
                            }else if(lst[ima+k][0]-lst[ima][0]>pq[0]){
                                lst.Remove(lst[ima]);
                                ima = 0;
                                k = 1;
                                cost ++;
                                break;
                            }else{
                                k++;
                                continue;
                            }
                        }
                    }
                    if(ans>cost){
                        ans = cost;
                    }
                }
            }
            Console.WriteLine(ans);
        }

        static int Compare(int[] a, int[] b){
            if(a[0]>b[0]){return 1;}
            else if(a[0]<b[0]){return -1;}
            else{
                if(a[1]>b[1]){
                    return 1;
                }else if(a[1]<b[1]){
                    return -1;
                }
                return 0;
            }
        }
    }
}

Measured memory_bytes: 13396
#[allow(unused_macros)]
macro_rules! input {
    ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; let mut next = || { iter . next ( ) . unwrap ( ) } ; input_inner ! { next , $ ( $ r ) * } };
    ( $ ( $ r : tt ) * ) => { let stdin = std :: io :: stdin ( ) ; let mut bytes = std :: io :: Read :: bytes ( std :: io :: BufReader :: new ( stdin . lock ( ) ) ) ; let mut next = move || -> String { bytes . by_ref ( ) . map ( | r | r . unwrap ( ) as char ) . skip_while ( | c | c . is_whitespace ( ) ) . take_while ( | c |! c . is_whitespace ( ) ) . collect ( ) } ; input_inner ! { next , $ ( $ r ) * } };
}
#[allow(unused_macros)]
macro_rules! input_inner {
    ( $ next : expr ) => { };
    ( $ next : expr , ) => { };
    ( $ next : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } };
}
#[allow(unused_macros)]
macro_rules! read_value {
    ( $ next : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ next , $ t ) ) ,* ) };
    ( $ next : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ next , $ t ) ) . collect ::< Vec < _ >> ( ) };
    ( $ next : expr , chars ) => { read_value ! ( $ next , String ) . chars ( ) . collect ::< Vec < char >> ( ) };
    ( $ next : expr , usize1 ) => { read_value ! ( $ next , usize ) - 1 };
    ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) };
}

fn main() {
    input!{
        a: u64,
        b: u64,
        c: u64,
        x: u64,
        y: u64
    }

    let mut x_rest = x;
    let mut y_rest = y;
    let mut ret = 0;

    if a + b > 2 * c {
        let k = std::cmp::min(x_rest, y_rest);
        ret += k * 2 * c;
        x_rest = if x_rest < k {0} else {x_rest - k};
        y_rest = if y_rest < k {0} else {y_rest - k};
    }

    if a > 2 * c {
        let k = x_rest;
        ret += k * 2 * c;
        x_rest = if x_rest < k {0} else {x_rest - k};
        y_rest = if y_rest < k {0} else {y_rest - k};
    }

    if b > 2 * c {
        let k = y_rest;
        ret += k * 2 * c;
        x_rest = if x_rest < k {0} else {x_rest - k};
        y_rest = if y_rest < k {0} else {y_rest - k};
    }

    ret += x_rest * a + y_rest * b;
    println!("{}", ret);
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;

#define INX(x) (cin >> x)
#define OUTX(x) (cout << x << endl)

#define ADD emplace_back
#define MP make_pair
#define VVEC(type) vector<vector<type>>


int main()
{
    ll N;
    INX(N);

    vll A(N);
    for (ll i = 0; i < N; i++)
    {
        INX(A[i]);
    }

    ll kane = 1000;
    ll kabu = 0;
    for (ll i = 0; i < N - 1; i++)
    {
        if(A[i] < A[i + 1])
        {
            ll buy = kane / A[i];
            kabu += buy;
            kane -= buy * A[i];
        }
        else if(A[i] > A[i + 1])
        {
            kane += kabu * A[i];
            kabu = 0;
        }
    }
    kane += kabu * A[N - 1];
    kabu = 0;
    OUTX(kane);


    return 0;
}


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

using namespace std;

class dsu {
 public:
  vector<int> p;
  int n;

  dsu(int n): n(n) {
    p.resize(n);
    for (int i = 0; i < n; ++i) {
      p[i] = i;
    }
  }

  inline int find(int x) {
    while (x != p[x]) {
      x = p[x] = p[p[x]];
    }
    return x;
  }

  inline bool unite(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y) {
      return false;
    } else {
      p[x] = y;
      return true;
    }
  }
};

int main() {
#ifdef wxh010910
  freopen("input.txt", "r", stdin);
#endif
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, m, q, md;
  cin >> n >> m >> q >> md;
  int g = md;
  vector<int> from(m), to(m), cost(m);
  for (int i = 0; i < m; ++i) {
    cin >> from[i] >> to[i] >> cost[i];
    --from[i];
    --to[i];
    g = __gcd(g, abs(cost[i] - cost[0]));
  }
  if ((md / g) % 3 == 0) {
    md = g * 3;
  } else {
    md = g;
  }
  int z = cost[0] % g;
  dsu p(n * 6);
  for (int i = 0; i < m; ++i) {
    int w = (cost[i] - z) / g % 3;
    for (int j = 0; j < 3; ++j) {
      p.unite(from[i] * 6 + j * 2 + 0, to[i] * 6 + (2 * j + w) % 3 * 2 + 1);
      p.unite(from[i] * 6 + j * 2 + 1, to[i] * 6 + (2 * j + w) % 3 * 2 + 0);
      p.unite(to[i] * 6 + j * 2 + 0, from[i] * 6 + (2 * j + w) % 3 * 2 + 1);
      p.unite(to[i] * 6 + j * 2 + 1, from[i] * 6 + (2 * j + w) % 3 * 2 + 0);
    }
  }
  vector<vector<bool>> can(2, vector<bool>(md));
  for (int i = 0, j = z; i < md * 2; ++i, j = j * 2 % md) {
    can[i & 1][j] = true;
  }
  while (q--) {
    int s, t, r;
    cin >> s >> t >> r;
    --s;
    --t;
    bool ans = false;
    for (int i = 0; i < 3; ++i) {
      for (int j = 0; j < 2; ++j) {
        if (p.find(t * 6) == p.find(s * 6 + i * 2 + j)) {
          if (can[j][(r + z + (3 - i) * g) % md]) {
            ans = true;
          }
        }
      }
    }
    cout << (ans ? "YES" : "NO") << "\n";
  }
  return 0;
}


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

int main()
{
	unsigned N;
	std::cin >> N;
	
	std::vector<unsigned> A(N);
	for (unsigned n = 0; n < N; ++n) {
		std::cin >> A[n];
	}
	
	unsigned long long int count = 0;
	
	unsigned sum1 = 0, sum2 = 0;
	unsigned left = 0, right = 0;
	while (left < N) {
		while ((right < N) && ((sum1 ^ A[right]) == (sum2 + A[right]))) {
			sum1 ^= A[right];
			sum2 += A[right];
			++right;
		}
		
		count += right - left;
		
		sum1 ^= A[left];
		sum2 -= A[left];
		++left;
	}
	
	std::cout << count << std::endl;
	
	return 0;
}

Measured memory_bytes: 1024
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;

public class Main {
  private static Map<String, Integer> memo = new HashMap<>();

  public static void main(String[] args) throws Exception {
    try (final var stdin = new InputStreamReader(System.in);
         final var br = new BufferedReader(stdin)) {
      final var n = Integer.parseInt(br.readLine());
      final var pow = Math.sqrt(n);
      final var result = new int[n];

      for (int i = 1; i < pow; i++) {
        for (int j = 1; j < pow; j++) {
          for (int k = 1; k < pow; k++) {
            final var sum = i * i + j * j + k * k + i * j + j * k + k * i;
            if (sum <= n) {
              result[sum - 1]++;
            }
          }
        }
      }

      for (int i = 0; i < result.length; i++) {
        System.out.println(result[i]);
      }
    }
  }
}


Measured memory_bytes: 35928
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define all(x) (x).begin(), (x).end()
#define INF 1000000007
#define mod 1005
#define ll long long int
int arr[16][16];
int main()
{
	int t = 1;
//	cin>>t;
	
	while(t--)
	{	
		int noTest;
		int x, y;
		REP(i,16)
			REP(j,16)
				arr[i][j] = -1;
		int n;
		cin>>n;
		int maxCount = 0;
		REP(i,n)
		{
			cin>>noTest;
			while(noTest--)
			{
				cin>>x>>y;
				x--;
				arr[i][x] = y;
			}
		}
//		REP(i,n)
//		{
//			REP(j,n)
//				cout<<arr[i][j]<<" ";
//			cout<<"\n";
//		}
		for(int i = 0; i<(1<<n);i++)
		{
//			cout<<"i is"<<i<<"\n";
			bool flag = true;
			int count = 0;
			for(int j=0; j<n;j++)
			{
				if((i>>j)&1)
				{
//					cout<<"Considering person honests: "<<j+1<<"\n";
					count++;
					for(int k=0; k<n;k++)
					{
//						cout<<"For person: "<<j+1<<" the testimony is: "<<arr[j][k]<<" but in the bitset : "<<((i>>k)&1)<<"\n";
						if(arr[j][k]==0 && (i&(1<<k)))
						{
							flag = false;
						}
						if(arr[j][k]==1 && (i&(1<<k))==0)
						{
							flag = false;
						}
						if(flag)
						{
//							cout<<"For "<<j+1<<" -> "<<k+1<<" is honest\n";
						}
					}
				}
			}
//			cout<<"Count is : "<<count<<"but flag is "<<flag<<"\n";
			if(flag)
			{
//				cout<<"flag is true:"<<" "<<count<<" \n";
				maxCount = max(count, maxCount);
			}
//			cout<<"--------------------------\n";
		}
		cout<<maxCount<<"\n";
	}
	
}

Measured memory_bytes: 256