akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Linq;
using System.Collections.Generic;
using System.Text.RegularExpressions;

class Program
{
    const string Yes = "Yes";
    const string No = "No";
    const long Mod = 1000000007;

    static void Main(string[] args) {
#if DEBUG
        MyDebugger.Test(process, "../TextFile1.txt");
#else
        object ret = process(new StreamReader(Console.OpenStandardInput()));
        Console.WriteLine(ret);
#endif
    }

    static object process(TextReader input) {
        var n = int.Parse(input.ReadLine());
        var aa = ToIntArray(input.ReadLine(), n);

        long sum = 0;
        foreach(var a in aa) {
            sum += a - 1;
        }

        return sum;
    }

    static int[] ToIntArray(string strs, int n) {
        var ret = new int[n];
        var spl = strs.Split(' ');
        for (int i = 0; i < n; i++)
            ret[i] = int.Parse(spl[i]);
        return ret;
    }
}


Measured memory_bytes: 13200
#include <iostream>
using namespace std ;
int main(){
    int t ,r ;
    cin >> t >> r ;
    int s[r] ;
    int t2 =0;
    for(int i=0 ;i<r;i++){
        cin >> s[i];
        t2 =t2 +s[i];
    }
    if (t2>t)cout << "-1";
    else
        cout << t-t2;


    return 0;
}


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

int main(){

	int in;
	stack<int> st;

	while(cin>>in){
		if(in == 0){
			cout<<st.top()<<endl;
			st.pop();
		}else{
			st.push(in);
		}
	}
	return 0;

}

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

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define LCM(a, b) (a) / __gcd((a), (b)) * (b)
#define CEIL(a, b) (a)/(b)+(((a)%(b))?1:0)
#define ln '\n'

using namespace std;
using LL = long long;
using ldouble = long double;
using P = pair<int, int>;
using LP = pair<LL, LL>;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1e9 + 7;
static const int SIZE = 200005;

const int dx[] = {0, -1, 1, 0};
const int dy[] = {-1, 0, 0, 1};

vector<LL> Div(LL n) {
    vector<LL> ret;
    for(LL i = 1; i * i <= n; ++i) {
        if(n % i == 0) {
            ret.pb(i);
            if(i * i != n) ret.pb(n / i);
        }
    }
    sort(all(ret));
    return ret;
}

int mp[2005][2005], light[2005][2005];

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

    int H, W;
    cin >> H >> W;
    for(int i = 1; i <= H; ++i) {
        for(int j = 1; j <= W; ++j) {
            char c;
            cin >> c;
            if(c == '.') mp[i][j] = 1;

        }
    }

    for(int i = 1; i <= H; ++i) {
        int sum = 0;
        for(int j = 1; j <= W; ++j) {
            if(mp[i][j] == 1) {
                ++sum;
                light[i][j] += sum;

            } else {
                sum = 0;

            }
        }

        sum = 0;
        for(int j = W; j >= 1; --j) {
            if(mp[i][j] == 1) {
                light[i][j] += sum;
                ++sum;

            } else {
                sum = 0;

            }
        }
    }

    for(int j = 1; j <= W; ++j) {
        int sum = 0;
        for(int i = 1; i <= H; ++i) {
            if(mp[i][j] == 1) {
                light[i][j] += sum;
                ++sum;

            } else {
                sum = 0;

            }
        }

        sum = 0;
        for(int i = H; i >= 1; --i) {
            if(mp[i][j] == 1) {
                light[i][j] += sum;
                ++sum;

            } else {
                sum = 0;

            }
        }
    }

    int mx = 0;
    for(int i = 1; i <= H; ++i) {
        for(int j = 1; j <= W; ++j) {
            mx = max(mx, light[i][j]);

        }
    }
    cout << mx << endl;
    return 0;
}



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

using namespace std;
using ll =long long;
constexpr int mod = 1e9+7;
constexpr int md = mod;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    double T,A;
    cin>>n>>T>>A;
    int ans;
    double diff = 1000000;
    for(int i=0;i<n;++i){
        double x;cin>>x;
        if(diff > abs(A - (T - x*0.006)))diff = abs(A - (T - x*0.006)),ans=i;
    }
    cout << ans+1 << endl;
    return 0;
}



Measured memory_bytes: 256
#include <iostream>

using namespace std;

struct item
{
	int id;
	int price;
};

struct recipe
{
	int id;
	int size;
	int price;
	int ingre[100];
};

item I[100];
recipe R[100];
string T[100];

int solve(int id, int n, int m);

int main(int argc, char** argv)
{
	
	string name, o, q;
	int n, m, p, k;
	
	while( 1 )
	{
		cin >> n;
		if(n==0) break;
		for(int i=0; i<n; i++)
		{
			cin >> T[i];
			I[i].id = i;
			cin >> I[i].price;
		}
		
		cin >> m;
		for(int i=0; i<m; i++)
		{
			cin >> name;
			for(int j=0; j<n; j++)
			{
				if(T[j]==name)
				{
					R[i].id = j;
				}
			}
			cin >> R[i].size;
			
			R[i].price = 0;
			for(int j=0; j<R[i].size; j++)
			{
				cin >> name;
				for(int k=0; k<n; k++)
				{
					if(T[k]==name)
					{
						R[i].ingre[j] = k;
						R[i].price += I[k].price;
					}
				}
			}
		}
		
		cin >> name;
		for(int i=0; i<n; i++)
		{
			if(name==T[i])
			{
				cout << solve(i, n, m) << endl;
			}
		}
	}
	
	return 0;
}

int solve(int id, int n, int m)
{
	int money = 0;
	int min = I[id].price;
	bool is_proc = false;
	
	for(int j=0; j<m; j++)
	{
		if(R[j].id == id)
		{
			is_proc = true;
			money = 0;
			for(int k=0; k<R[j].size; k++)
			{
				money += solve(R[j].ingre[k], n, m);
			}
			if(money < min) min = money;
			break;
		}
	}
	
	if(is_proc) return min;
	else return I[id].price;
}

Measured memory_bytes: 0
# import numpy as np
from collections import deque

def solve(H, W, CH, CW, DH, DW, S):
	# 後の条件分岐を簡略化するためワープしても迷路外に出ないように壁で囲む
	S = ['##{}##'.format(row) for row in S]
	S.insert(0, '##{}##'.format('#' * W))
	S.insert(0, '##{}##'.format('#' * W))
	S.append('##{}##'.format('#' * W))
	S.append('##{}##'.format('#' * W))


	MAX_COST = 10 ** 9
	Cost=[ [ MAX_COST for _ in range(W+4)] for _ in range(H+4)]
	# Cost = np.full((H,W),MAX_COST)

	# print(S)

	ans = -1

	cost0 = deque()

	cost0.append((CH+1,CW+1,0))
	Cost[CH+1][CW+1] = 0;

	# used = set()
	walk=[(1,0),(0,1),(-1,0),(0,-1)]
	warp = [ (i,j) for i in range(-2,3) for j in range(-2,3) if (i, j) not in [(0, 0)] + walk ]
	# print(warp)

	cost1 = deque()

	while cost0:
		h,w,c=cost0.popleft()
		cost1.append((h,w,c))

		for i,j in walk:
			dh = h+i
			dw = w+j
			if S[dh][dw] == '.' and c < Cost[dh][dw]:
				Cost[dh][dw] = c
				# print("updl ", i,j,dh,dw,c)
				cost0.appendleft((dh,dw,Cost[dh][dw]))

		if len(cost0) == 0:

			while cost1:
				h,w,c=cost1.popleft()
				# print(h,w,c)
				for i,j in warp:
					dh = h+i
					dw = w+j
					# print(i,j)
					if S[dh][dw] == '.' and c + 1 < Cost[dh][dw]:
						Cost[dh][dw] = c + 1
						cost0.append((dh,dw,Cost[dh][dw]))


	if Cost[DH+1][DW+1] == MAX_COST:
		print(-1)
	else:
		print(Cost[DH+1][DW+1])


if __name__ == "__main__":
	H,W=map(int,input().split())
	CH,CW=map(int,input().split())
	DH,DW=map(int,input().split())

	S=[input() for _ in range(H)]

	solve(H, W, CH, CW, DH, DW, S)


Measured memory_bytes: 25656
#include <stdio.h>
typedef long long ll;

int main(void) {
  ll i, n, ans = 100000;
  scanf("%lld", &n);
  for(i = 0; i < n; ++i) {
    ans = ans + ans / 20;
    if(ans % 1000) ans -= ans % 1000, ans += 1000;
  }
  printf("%lld\n", ans);
  return 0;
}


Measured memory_bytes: 2572
fun readString() = readLine()!!
fun readInt() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readIntList() = readLine()!!.split(" ").map(String::toInt)
fun readLongList() = readLine()!!.split(" ").map(String::toLong)
fun <T> Array<Array<T>>.print() {
    this.forEach {
        println(it.joinToString(" "))
    }
}

fun isPalindrome(s: String): Boolean {
    for (i in 0 until s.count()) {
        if (s[i] != s[s.count() - i - 1]) return false
    }
    return true
}

fun main() {
    val s = readString()
    val n = s.count()
    val res = isPalindrome(s) && isPalindrome(s.substring(0 until ((n - 1) / 2))) && isPalindrome(s.substring(((n + 3) / 2 - 1) until n))
    println(if (res) {
        "Yes"
    } else {
        "No"
    })
}

Measured memory_bytes: 35980
import sys

H, W = map(int, input().split())
A = [list(map(int, sys.stdin.readline().rsplit())) for _ in range(H)]

res = []
for i in range(H):
    for j in range(W):
        if A[i][j] % 2 != 0 and j < W - 1:
            A[i][j] -= 1
            A[i][j + 1] += 1
            res.append([i + 1, j + 1, i + 1, j + 2])
        elif A[i][j] % 2 != 0 and i != H - 1 and j == W - 1:
            A[i][j] -= 1
            A[i + 1][j] += 1
            res.append([i + 1, j + 1, i + 2, j + 1])
print(len(res))
for i in range(len(res)):
    print(*res[i])


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

typedef long long ll; // -9,223,372,036,854,775,808 から 9,223,372,036,854,775,807

template <class T> using vec = std::vector<T>;
template <class T> using vec2 = vec<vec<T>>;
template <class T> using vec3 = vec<vec<vec<T>>>;

// #define DEBUG



void solve(long long N, long long K, long long C, std::string S){
    vec<pair<ll, ll>> kokomade;
    vec<pair<ll, ll>> kokokara;

    // kokomadeをつくる
    ll disabled = -1;
    ll num = 0;
    for(int i=0; i < N; i++){
        if(i <= disabled){
            kokomade.push_back(pair<ll, ll>(num, disabled));
            continue;
        }
        if(S[i] =='o'){
            num++;
            disabled = i + C;
            kokomade.push_back(pair<ll, ll>(num, disabled));
        }else{
            kokomade.push_back(pair<ll, ll>(num, disabled));
        }
    }
    #ifdef DEBUG
    printf("*START: kokomade\n");
    for(auto iter: kokomade){
        printf("(%d, %d), ", iter.first, iter.second);
    }
    printf("\n");
    printf("*END: kokomade\n");
    #endif

    disabled = N;
    num = 0;
    for(int i=N-1; i >= 0; i--){
        if(i >= disabled){
            kokokara.push_back(pair<ll, ll>(num, disabled));
            continue;
        }
        if(S[i] =='o'){
            num++;
            disabled = i - C;
            kokokara.push_back(pair<ll, ll>(num, disabled));
        }else{
            kokokara.push_back(pair<ll, ll>(num, disabled));
        }
    }
    reverse(kokokara.begin(), kokokara.end());
    #ifdef DEBUG
    printf("*START: kokokara\n");
    for(auto iter: kokokara){
        printf("(%d, %d), ", iter.first, iter.second);
    }
    printf("\n");
    printf("*END: kokokara\n");
    #endif


    if(N == 1){
        cout << 1 << endl;
    }else{
        for(int i=0; i < N; i++){
            if(S[i] == 'x'){
                continue;
            }
            if(i == 0){
                if(kokokara.at(1).first < K){
                    cout << i + 1 << endl;
                }
            }else{
                auto made = kokomade.at(i-1);
                auto karaId = max((ll)(i+1), made.second + 1);
                auto kara = (karaId < kokokara.size() ? kokokara.at(karaId) : pair<ll, ll>(0, 0));
                if(made.first + kara.first < K){
                    cout << i + 1 << endl;
                }
            } 
        }
    }
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    long long K;
    scanf("%lld",&K);
    long long C;
    scanf("%lld",&C);
    std::string S;
    std::cin >> S;
    solve(N, K, C, S);
    return 0;
}


Measured memory_bytes: 12784
#include <iostream>
#include <stdio.h>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <numeric>
#include <queue>
#include <numeric>
#include <iomanip>
#include <sstream>
#include <cmath>
#include <map>
#include <functional>
#include <limits>
#include <set>
#include <stack>
#define rep(i,a,b) for((i)=a;i<(int)(b);i++)
#define Max(a,b) ((a) < (b) ? (b) : (a))
#define Min(a,b) ((a) > (b) ? (b) : (a))
#define AAA (1000000007) 


using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pairII;


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

ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}
ll powD(ll a, ll b) {
	ll ans = 1;
	a %= AAA;
	for (int i= 0; i <b; i++)
	{
		ans *= a;
		ans %= AAA;
	}
	return ans;
}

int main() {
	int i, j, k;

	int N, M, K;

	int B[100000] = { 0 };
	
	cin >> N;
	rep(i, 0, N) {
		int a;
		cin >> a;
		B[a]++;
	}

	int sum = 0;

	if (N % 2 == 0) {
		if (B[1] != 2) {
			cout << 0;
			return 0;
		}
		sum += 2;
		i = 3;
	}
	else {
		if (B[0] != 1) {
			cout << 0;
			return 0;
		}
		sum += 1;
		i = 2;
	}
	
	for (; i < 100000 && sum <N; i+=2) {
		if (B[i] != 2) {
			cout << 0;
			return 0;
		}
		sum += 2;
	}
	if (sum != N) {
		cout << 0;
		return 0;
	}
	cout << powD(2, N / 2);
	return 0;
}

Measured memory_bytes: 640
#include <stdio.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <unordered_map>
#include <numeric>
#include <cmath>
#include <tuple>

int main() {
  int n, m;
  std::vector<int> x;

  std::cin >> n >> m;
  for (auto i=0; i < m; i++) {
    int tmp;
    std::cin >> tmp;
    x.push_back(tmp);
  }

  auto max = *std::min_element(x.begin(), x.end());
  auto min = *std::min_element(x.begin(), x.end());
  auto abs = 0;
  for (auto v : x) {
    abs += std::abs(v);
  }

  std::sort(x.begin(), x.end());

  for (auto v : x) {
    //std::cout << v << " ";
  }

  std::vector<std::tuple<size_t, size_t, unsigned int>> tuples;
  std::vector<unsigned int> distances;
  for (auto i=0; i < x.size()-1; i++) {
    //tuples.push_back(std::make_tuple(i+1, i, x[i+1] - x[i]));
    distances.push_back(x[i+1] - x[i]);
  }

  std::sort(distances.begin(), distances.end(), std::greater<int>());

  //std::cout << std::endl;

  auto result = 0;
  for (auto i=(n-1); i < distances.size(); i++) {
    result += distances[i];
  }

  for (auto v : distances) {
    //std::cout << v << " ";
    //std::cout << "(" << std::get<0>(v) << " " << std::get<1>(v) << " " << std::get<2>(v) << " )" << std::endl;
  }

  /*
  std::vector<unsigned int> distances_r2;
  for (auto i=0; i < distances.size()-1; i++) {
    distances_r2.push_back(distances[i+1] - distances[i]);
  }

  std::cout << std::endl;

  for (auto v : distances_r2) {
    std::cout << v << " ";
    //std::cout << "(" << std::get<0>(v) << " " << std::get<1>(v) << " " << std::get<2>(v) << " )" << std::endl;
  }

  std::cout << std::endl;

  std::vector<std::vector<int>> sets = {};
  for (auto i=0; i < n; i++) {

  }

  int sets[n];


  //const auto ooo = (abs - n) / n;
  //std::cout << abs << std::endl;
  //std::cout << ooo << std::endl;


  std::cout << std::endl;
  */

  //std::cout << std::endl;
  std::cout << result << std::endl;

  return 0;
}

Measured memory_bytes: 1400
#include<stdio.h>

int main()
{
  int n,m;
  scanf("%d %d",&n,&m);
  int tmp=0;
  for(int i=0;i<m;i++){
    int c;
    scanf("%d",&c);
    tmp+=c;
  }
  int ans=n-tmp;
  if(ans<0){
    printf("%d",-1);
  }
  else{
    printf("%d",ans);
  }
  return 0; 
}

Measured memory_bytes: 1732
#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

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, K;
    cin >> N >> K;
    int a[1010];
    rep(i, N) cin >> a[i];
    vector<int> v;

    // 連続する部分列の総和の全パターンを計算する。
    rep(i, N) {
        int sum = 0;
        REP(j, i, N - 1) {
            sum += a[j];
            v.push_back(sum);
        }
    }


    int ans = 0;
    // 最上位bit(最重要bit)から考えていく。
    // 注目しているbitが1にできるのならば、1を立てる。
    RREP(i, 50, 0) {
        vector<int> nx_v;
        rep(j, v.size()) {
            if (v[j] & (1LL << i)) nx_v.push_back(v[j]);
        }
        // 注目しているbitに対して、1が立っている個数がK個未満の時は何もしない。
        if(nx_v.size() < K) continue;

        ans += (1LL << i);
        v = nx_v;
    }

    cout << ans << endl;

    return 0;
}

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

int main() {
  string S = "";
  cin >> S;
  
  int dp[13] = {};
  dp[0] = 1;
  int mod = 1000000007;
  for (int i = 0; i < S.length(); i++)
  {
    int dp2[13] = {};
    char c = S[i];
    if (c == '?')
    {
      for (int n = 0; n <= 9; n++)
      {
        for (int m = 0; m <= 12; m++)
        {
          dp2[(m * 10 + n) % 13] += dp[m];
          dp2[(m * 10 + n) % 13] %= mod;
        }
      }
    }
    else
    {
      int k = c - '0';
      for (int m = 0; m <= 12; m++)
      {
        dp2[(m * 10 + k) % 13] += dp[m];
        dp2[(m * 10 + k) % 13] %= mod;
      }
    }
    for (int l = 0; l < 13; l++)
    {
      dp[l] = dp2[l];
    }
  }
  
  cout << dp[5] << endl;
  return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
 
int main(void){
    int A, B;
    cin >> A >> B;
    int cnt = 0;
    for (int num = A; num <=B; num++)
    {
        string str = to_string(num);
        if (str[0] == str[4] && str[1] == str[3])  cnt++;
    }
    cout << cnt << endl;
    
    return 0;
}

Measured memory_bytes: 256
/*
ID: anonymo14
TASK: wormhole
LANG: C++                 
*/
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<pair<int,int>> vpii;

#define F first
#define S second
#define PU push
#define PUF push_front
#define PUB push_back
#define PO pop
#define POF pop_front
#define POB pop_back

#define REP(i,a,b) for(int i=a; i<=b; i++)

#define MOD 1000000007

void solve(int test_case) {
	int a,b;
	cin>>a>>b;
	if(a>b) {
		if(b==1)cout<<"Bob";
		else cout<<"Alice";
	} else if(b>a) {
		if(a==1)cout<<"Alice";
		else cout<<"Bob";
	} else {
		cout<<"Draw";
	}
}

int main() {
	
	////// FILE BASED IO////
	//freopen("wormhole.in", "r", stdin);
	//freopen("wormhole.out", "w", stdout);
	///////////////
	
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t=1;
	//cin>>t;
	REP(i,1,t) {
		solve(i);
	}
	return 0;
}	


Measured memory_bytes: 3604
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
using ll = long long;
using P = pair<int,int>;
template <class T> void chmin(T &a, const T &b) noexcept { if (b < a) a = b; }
template <class T> void chmax(T &a, const T &b) noexcept { if (a < b) a = b; }
void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) { cout << H << " "; debug_out(T...); }
#ifdef _DEBUG
  #define debug(...) debug_out(__VA_ARGS__)
#else
  #define debug(...) 
#endif

ll gcd (ll x, ll y) { return y ? gcd(y,x%y) : x; }

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  int k;
  cin >> k;
  ll ans = 0;
  for (int a = 1; a <= k; ++a) {
    for (int b = 1; b <= k; ++b) {
      for (int c = 1; c <= k; ++c) {
        ll temp = gcd(a,b);
        ans += gcd(temp, c);
      }
    }
  }
  cout << ans << endl;
  return 0;
}

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

int main(){
    int N;  cin >> N;
    vector<int> p(N+1);
    for(int i=1; i<=N; i++) cin >> p[i];
    
    vector<int> a(N+1), b(N+1);
    int M = 3e4;
    for(int i=1; i<=N; i++){
        a[i] = M*(i-1) + 1;
        b[i] = M*(N-i) + 1;
    }
    for(int i=1; i<=N; i++){
        a[p[i]]+=i;
    }

    for(int i=1; i<=N-1; i++){
        cout << a[i] << " ";
    }cout << a[N] << endl;
    for(int i=1; i<=N-1; i++){
        cout << b[i] << " ";
    }cout << b[N] << endl;
}


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

#define each(i, c) for (auto& i : c)
#define mkp(a, b) make_pair(a, b)

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> Pll;
const ll MOD = 1e9+7;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << ": " << p.second << ")"; return os; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ", "; os << ")"; return os; }
template<typename K, typename V> ostream& operator << (ostream& os, map<K, V> m) { os << "{"; each (i, m) os << i << ", "; os << "}"; return os; }

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

  ll a, b;
  cin >> a >> b;

  string u;
  cin >> u;

  if (s == u) --a;
  if (t == u) --b;

  cout << a << " " << b << endl;

  return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#pragma comment(linker, "/STACK:1024000000")
#pragma warning( disable : 6031)
#pragma warning( disable : 4244)
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <cassert>
#include <string>
#include <vector>
#include <iostream>
#include <map>
#include <stack>
#include <set>
#include <queue>
#include <numeric>
#include <algorithm>
#include <utility>
#include <bitset>
#include <cmath>
#include <sstream>
#include <functional>
#include <iomanip>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <chrono>

#define all(a) (a).begin(),(a).end()
#define sz(a) (int)(a).size()
#define eps (1e-15)

using namespace std;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef long long ll;
typedef vector<int> vi;
typedef vector< vi > vvi;
typedef vector<double> vd;
typedef vector< vd > vvd;
typedef vector< string > vs;
typedef pair< int, int > pii;
typedef vector< pii > vpii;
typedef vector<ll> vll;
typedef vector<vector<long long>> vvll;
typedef tuple<int, int, int> tiii;
const long long mod = int(1e9) + 7;
const double eps9 = 1e-9;



int main() {
#ifdef LOCAL_MACHINE
	freopen("input.txt", "rt", stdin);
	freopen("output.txt", "wt", stdout);
#endif
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); cout << setprecision(18) << fixed;
	int m1, d1, m2, d2;
	cin >> m1 >> d1 >> m2 >> d2;
	if (m2 > m1)
		cout << 1;
	else
		cout << 0;
	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

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

	long long ans = M / N;

	for (; ans >= 1; --ans) {
		if (M > (N - 1) * ans) {
			if ((M - (N - 1) * ans) % ans == 0) {
				break;
			}
		}
	}
	cout << ans << endl;
}


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

namespace Lsk {
#define _auto_ template <typename T>

// fast io
#define writesp(x) (write(x), putchar(' '))
#define writeln(x) (write(x), putchar('\n'))
_auto_ inline void read(T &x) {
	x = 0; bool sgn = false; char ch = getchar();
	while(!isdigit(ch)) (ch == '-') && (sgn = true), ch = getchar();
	while(isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
	if(sgn) x = -x;
}
_auto_ inline void write(T x) {
	if(x < 0) putchar('-'), x = -x;
	static char buf[40]; int o = 0;
	for(x; x > 9; x /= 10, ++o) buf[o] = x % 10 + '0'; buf[o] = x + '0';
	for(o; ~o; --o) putchar(buf[o]);
	return;
}

// cmin / cmax / swap
_auto_ inline void cmin(T &u, const T v) { if(u > v) u = v; }
_auto_ inline void cmax(T &u, const T v) { if(u < v) u = v; }
_auto_ inline T min(const T u, const T v) { return u < v ? u : v; }
_auto_ inline T max(const T u, const T v) { return u > v ? u : v; }
_auto_ inline void swap(T &u, T &v) { T tmp(u); u = v, v = tmp; }

// math
const int mod = 998244353, mod_2 = 1996488706;
//const int mod = 1000000007, mod_2 = 2000000014;
//const int mod = 1000000009, mod_2 = 2000000018;
_auto_ inline T abs(T x) { return x > 0 ? x : -x; }
_auto_ inline T gcd(T u, T v) {	return v ? gcd(v, u % v) : u; }
_auto_ inline T Mod(T u) { return u >= mod_2 ? u % mod : (u > mod ? u - mod : u); }
_auto_ inline T inmod(T u) { return u >= mod ? u - mod : (u < 0 ? u + mod : u); }
inline long long fpm(long long base, long long mi) {
	long long res = 1;
	while(mi) {
		if(mi & 1) res = Mod(res * base);
		base = Mod(base * base), mi >>= 1;
	}
	return res;
}

} using namespace Lsk;
#define N 200005
using std :: sort;

int n;
int a[N], f[N];
long long K;

inline bool check(long long mid) {
	long long res = 0;
	for(int i = 1; i <= n; ++i) {
		long long to = mid / f[i];
		if(to < a[i]) res += a[i] - to;
	}
	return res <= K;
}

int main() {
	read(n), read(K);
	for(int i = 1; i <= n; ++i) read(a[i]);
	for(int i = 1; i <= n; ++i) read(f[i]);

	sort(a + 1, a + 1 + n);
	sort(f + 1, f + 1 + n, std :: greater<long long>());

	long long l = 0, r = 1e12, mid, minp = 1e18;
	while(l <= r) {
		mid = l + r >> 1;
		//writesp(l), writeln(r);
		if(check(mid)) {
			cmin(minp, mid);
			r = mid - 1;
		} else {
			l = mid + 1;
		}
	}

	writeln(minp);
	return 0;
}


Measured memory_bytes: 1792
fun main(args : Array<String>) {
    val (N, M) = readLine()!!.split(" ").map { it.toInt() }
    val A = readLine()!!.split(" ").map { it.toInt() % M }.toIntArray()
    var answer = 0L
    (1 until N).forEach {
        A[it] = (A[it] + A[it - 1])% M
    }

    val countMap = hashMapOf<Int, Long>()
    A.forEach {
        if (countMap[it] == null) {
            countMap[it] = 1
        } else {
            countMap[it] = countMap[it]!! + 1
        }
    }

    if (countMap[0] != null) {
        answer += countMap[0]!!
    }
    countMap.entries.forEach {
        val (num, size) = it
        if (size > 1) {
            answer += size * (size - 1) / 2
        }
    }

    println(answer)
}


Measured memory_bytes: 55972
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
#include<ctime>
#include<cmath>
#include<utility>
#include<cstdlib>
#include<bitset>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<iomanip>
using namespace std;                       

#define ll long long
#define pb push_back
#define mp make_pair

#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)

const ll M = 1e9 + 7;

ll add(ll a, ll b){
    (a += b)%=M;
    (a += M)%=M;
    return a;
}

ll mul(ll a, ll b){
    (a *= b)%=M;
    (a += M)%=M;
    return a;
}

ll fastpo(ll a, ll x){
    if(x == 0) return 1ll;
    if(x == 1) return a;
    ll y = fastpo(a, x/2);
    if(x%2 == 0){
        return y*y;
    }
    return y*y*a;
}

ll inv(ll a, ll M){
    return fastpo(a, M-2);
}

ll gcdExtended(ll a, ll b, ll *x, ll *y) 
{ 
    if (a == 0) 
    { 
        *x = 0, *y = 1; 
        return b; 
    } 
  
    ll x1, y1; 
    ll gcd = gcdExtended(b%a, a, &x1, &y1); 
  
    *x = y1 - (b/a) * x1; 
    *y = x1; 
  
    return gcd; 
}

ll modInverse(ll a, ll m) 
{ 
    ll x, y; 
    ll g = gcdExtended(a, m, &x, &y); 
    if (g != 1) 
        return -1; 
    else
    { 
        ll res = (x%m + m) % m; 
        return res;
    } 
}


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

ll lcm(ll a, ll b){
    return (a*b)/gcd(a, b);
}

void print(vector<int> &a){
    int n = a.size();
    for(int i=0; i<n; i++){
        cout<<a[i]<<" ";
    }
    cout<<endl;
}

int main(){
//    clock_t time_req;
//     time_req = clock();
    fastio;
    int n;
    cin>>n;
    string s;
    cin>>s;
    int ans = 0;
    int a = -1, b = n;
    bool ma = true, mb = true;
    while(a < b){
        if(ma && mb){
            a++;
            b--;
        }
        else if(ma){
            a++;
        }
        else if(mb){
            b--;
        }
        else{
            swap(s[a], s[b]);
            ma = true;
            mb = true;
            ans++;
        }
        if(s[a] == 'W') ma = false;
        if(s[b] == 'R') mb = false; 
    }
    cout<<ans<<endl;
    // time_req = clock()-time_req;
    // cout<<"Time taken: "<<(float)time_req/CLOCKS_PER_SEC<<"s"<<endl;
    return 0;
}

Measured memory_bytes: 3776
#include <iostream>
#include <string>
#include <vector>
#include <iomanip>
#include <set>
#include <map>
#include <numeric>
#include <bitset>
#include <sstream>
#include <iomanip>
#include<fstream>
#include <cmath>
#include <algorithm>
#include <iterator>
#include <utility>   // std::pair, std::make_pair
#include <stdlib.h>  //atoi
using namespace std;
typedef long long ll;
const  double PI = 3.141592654;
#define rep(i,x) for(int(i)=0;(i)<(ll)(x);(i)++)
#define all(s)      (s).begin(),(s).end()
#define allv(v)      (v).begin(),(v).end()
#define pb          push_back
#define sz          s.size()
#define ssz          ss.size()
#define vz          v.size()
//x = atoi(a.c_str())
void fast()
{
	ios_base::sync_with_stdio(0);
	cin.tie(NULL), cout.tie(NULL);
}
int main()
{
	fast();
	ll x;
	cin >> x;
	ll a = 2, b = 1, z = a + b;
	if (x == 1)
		cout << 1 << endl;
	else if (x == 2)
		cout << 3 << endl;
	else
	{
		x -= 2;
		for (int i = 0; i < x; i++)
		{
			a = b, b = z;
			z = a + b;
		}
		cout << z << endl;
	}
	return 0;
}

Measured memory_bytes: 256
import Data.List
import Data.Bits ((.&.))
import Data.Maybe (fromJust)
import qualified Data.ByteString.Lazy.Char8 as B
import qualified Data.Vector.Unboxed as V
import qualified Data.Vector.Unboxed.Mutable as VM
import Control.Monad
import Control.Monad.ST
import Debug.Trace

type Elem = Int
type BIT s = VM.MVector s Elem
{-
BITについて
それぞれPは一点、Rは範囲の操作
fが群の演算ならば（逆元が存在すれば）、任意の範囲を取り出すことが可能
モノイドならば(1,n)のような範囲を取り出し可能
-}

newBIT :: Int -> Elem -> ST s (BIT s)
newBIT n e = VM.replicate (n+1) e

--logN
--(1,i)の範囲で取得
readRBIT' :: BIT s -> Int -> ST s Elem
readRBIT' bit i = sub i 0
  where
    sub 0 partial = return partial
    sub i partial = do
      --let f = max
      a <- VM.unsafeRead bit i
      sub (i-(i .&. (-i))) (max a partial)

readPBIT :: BIT s -> Int -> ST s Elem
readPBIT bit i = sub i 0
  where
    sub i partial
      | (VM.length bit)-1 < i = return partial
      | otherwise = do
        --let f = max
        a <- VM.unsafeRead bit i
        sub (i+(i .&. (-i))) (max a partial)

--(1,i)の範囲で更新
modifyRBIT' :: BIT s -> (Elem -> Elem) -> Int -> ST s ()
modifyRBIT' bit f i
  | i < 1 = return ()
  | otherwise  = do
   VM.unsafeModify bit f i
   modifyRBIT' bit f (i-(i .&. (-i)))

modifyPBIT :: BIT s -> (Elem -> Elem) -> Int -> ST s ()
modifyPBIT bit f i = sub i
  where
    sub i' | (VM.length bit)-1 < i' = return ()
           | otherwise = do
             VM.unsafeModify bit f i'
             sub (i'+(i' .&. (-i')))

solve :: Int -> [Int] -> [Int] -> ST s Elem
solve n hs as = do
  bit <- newBIT n 0
  let solve' h a = do
        a' <- readRBIT' bit h
        modifyPBIT bit (max $ a+a') h
  forM_ (zip hs as) $ \(h,a) -> solve' h a
  readRBIT' bit n

readBInt :: B.ByteString -> Int
readBInt = fst . fromJust . B.readInt

tmain :: B.ByteString -> Int
tmain cont =
   let remLines0 = map B.words (B.lines cont)
       [n']:remLines1 = remLines0
       n = readBInt n'
       line2:remLines2 = remLines1
       hs = map readBInt line2
       line3:remLines3 = remLines2
       as = map readBInt line3
   in runST $ solve n hs as

main :: IO ()
main = print . tmain =<< B.getContents


Measured memory_bytes: 6652
import java.util.*;

// https://beta.atcoder.jp/contests/arc102/submissions/3118322

class Edge{
	int a,b,c;
	public Edge(int A,int B,int C){
		a=A;
		b=B;
		c=C;
	}
	@Override
	public String toString(){
		return a+" "+b+" "+c;
	}
}

class Main{
	static int nextBit(BitSet sb,int idx,int n){
		int v=sb.nextSetBit(idx);
		return v==-1?n:v;
	}

	public static void main(String[] $){
		int L=new Scanner(System.in).nextInt()-1;
		if(L==1){
			System.out.println("2 2\n1 2 0\n1 2 1");
			return;
		}

		int n=Integer.numberOfTrailingZeros(Integer.highestOneBit(L));

		BitSet sb=new BitSet();

		for(int i=n;i>=0;i--){
			sb.set(n-i,(L&(1<<i))>0);
		}

		List<Edge> ret=new ArrayList<>();

		for(int i=1;i<=n;++i){
			ret.add(new Edge(i,i+1,0));
			ret.add(new Edge(i,i+1,1<<(n-i)));
		}

		int num=0;
		for(int i=0;i<=n;++i){
			if(!sb.get(i))
				continue;
			num+=1<<(n-i);
			ret.add(new Edge(1,nextBit(sb,i+1,n)+1,num));
		}

		System.out.println(n+1+" "+ret.size());
		ret.forEach(System.out::println);
	}
}


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

int main()
{
    int a,b,c,d;
    cin >> a >> b >> c >> d;

    int ans = min(b,d) - max(a,c);
    if(ans < 0) cout << 0 << endl;
    else cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3576
#include <bits/stdc++.h>
using namespace std;
#define MD 1000000007
typedef long long int ll;
typedef pair<ll, ll> P;
template <typename T>
std::string tostr(const T &t){std::ostringstream os;os << t;return os.str();}
int dx[4]={1, 0, -1, 0}, dy[4]={0, 1, 0, -1};

//親の場合parには，-(集合のサイズ)を格納
vector<ll> par(1e6,-1),dep(1e6,0);

//木の根を求める
ll find(ll x){
    if(par[x]<0){
        return x;
    }else{
        //return find(par[x])でも可能だが
        //根をつなぎなおして計算量を落としている
        return par[x]=find(par[x]);
    }
}

//xとyが同じ集合に属するか否か
bool same(ll x, ll y){
    return find(x)==find(y);
}

//xとyの属する集合を併合
void unite(ll x, ll y){
    //同じ集合なら意味なし
    x=find(x);
    y=find(y);
    if(x==y) return;
    //rankの大小でどちらにくっつけるかを判定
    if(dep[x]<dep[y]){
        par[y]+=par[x];
        par[x]=y;
    }else{
        par[x]+=par[y];
        par[y]=x;
        //同じdepのときは，yをxにくっつけ
        //xのdepをプラスする
        if(dep[x]==dep[y]) dep[x]++;
    }
}

//xの属する集合のサイズを求める
ll size(ll x){
    return -par[find(x)];
}

int main()
{
    ll n,m;
    cin>>n>>m;
    vector<P> pa(m+2);
    vector<ll> ans(m+2);
    for(int i=0;i<m;i++){
        int a,b;
        cin>>a>>b;
        a--;
        b--;
        pa[i]={a,b};
    }
    //m番目の辺から順につなげていく
    //UnionFind利用
    for(int i=m-1;i>=0;i--){
        //全ての橋が壊れている場合
        if(i==m-1){
            ans[i]=n*(n-1)/2;
        }else{
            if(ans[i+1]==0 || same(pa[i+1].first,pa[i+1].second)) {
                ans[i]=ans[i+1];
            }else{
                ll tmp=size(pa[i+1].first)*size(pa[i+1].second);
                ans[i]=ans[i+1]-tmp;
                unite(pa[i+1].first,pa[i+1].second);
            }
        }
    }
    //答え出力
    for(int i=0;i<m;i++){
        cout<<ans[i]<<endl;
    }
    return 0;
}

Measured memory_bytes: 19328
import java.util.Scanner;


class Node{
	int children;
	int brother;
	int parent;
	int deap;
	String tape;


	Node(){
		children=-1;
		brother=-1;
		parent=-1;
		deap=-1;
		tape="";
	}


}

public class Main{
	static Node[] N;

	static int Deapsif(int i) {

		int deap = 0;
		while(N[i].parent!=-1) {
			deap++;
			i=N[i].parent;
		}
		return deap;

	}

	static void Tapetest(int i) {
		if(N[i].parent==-1) {
			N[i].tape="root";
		}
		else if(N[i].children!=-1) {
			N[i].tape="internal node";
		}
		else if(N[i].children==-1){
			N[i].tape="leaf";
		}


	}

	static void Print_brother(int i) {
		int count=0;
		if(N[i].children!=-1) {
			i = N[i].children;
			while(i!=-1) {
				if(count==0) {
					System.out.print(i);
					i=N[i].brother;
				}
				else {
					System.out.print(", "+i);
					i=N[i].brother;
				}
				count=1;
			}
		}
		System.out.println("]");
	}



	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int  n = sc.nextInt();
		N=new Node[n];
		for(int i=0;i<n;i++)N[i]=new Node();


		for(int i=0;i<n;i++) {
			int i1=sc.nextInt();
			int dataN = sc.nextInt();
			int l=0;
			for(int j=0;j<dataN;j++) {
				int c= sc.nextInt();
				N[c].parent=i1;
				if(j==0)N[i1].children=c;
				else N[l].brother =c;
				l=c;
			}
		}


		for(int i=0;i<n;i++)N[i].deap=Deapsif(i);
		for(int i=0;i<n;i++)Tapetest(i);

		for(int i=0;i<n;i++) {
			
			System.out.print("node "+i+": parent = "+N[i].parent+", depth = "+N[i].deap+", "+N[i].tape+", [");

			Print_brother(i);
				
				
				
		}






		sc.close();
	}
}




Measured memory_bytes: 122712
#include<bits/stdc++.h> 
//#define <- プログラムの文字列を置換する
//typedef <- 新しい型に名前を付けるためのキーワード

using namespace std;

#define MAX_N 1

typedef long long ll;

const double PI = 3.141592653589793;
const long long MOD = 1e9 + 7;
const long long INF = 1e15;
const int INF_INT = 1e9;

int main(){
    string s;
    cin >> s;
    cout << "ABC" + s << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <algorithm>
#include <numeric>
#include <random>
#include <vector>
#include <array>
#include <bitset>
#include <queue>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <stack>

using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
constexpr ll TEN(int n) { return (n==0) ? 1 : 10*TEN(n-1); }
template<class T> using V = vector<T>;
template<class T> using VV = V<V<T>>;
#define pb push_back
using pii = pair<int, pair<int,int>>;
#define fi first
#define se second
const int N = 1e5 + 10;
long long bar[N];
int n;
int a[N], b[N], c[N];
int main() {
    while (scanf("%d", &n) == 1) {
        for (int i = 0; i < n; i++) scanf("%d", a + i);
        for (int i = 0; i < n; i++) scanf("%d", b + i);
        for (int i = 0; i < n; i++) scanf("%d", c + i);

        sort(a, a + n);
        sort(b, b + n);
        sort(c, c + n);

        int j = 0;
        for (int i = 0; i < n; i++) {
            while (j < n && c[j] <= b[i]) j++;
            bar[i] = n - j;
        }
        for (int i = n - 2; i >= 0; i--) {
            bar[i] += bar[i + 1];
        }
        long long res = 0;
        j = 0;
        for (int i = 0; i < n; i++) {
            while (j < n && b[j] <= a[i]) j++;
            res += bar[j];
        }
        cout << res << endl;
    }

    return 0;
}


Measured memory_bytes: 2304
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(I,A,B) for(ll I = (A); I < (B); ++I)
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //ai>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //ai>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define REV(x) (reverse(x.begin(),x.end())) //reverse
#define TO(x,t,f) ((x)?(t):(f))
#define CLR(mat) memset(mat, 0, sizeof(mat))
#define FILV(x,a) fill(x.begin(),x.end(),a)
#define FILA(ar,N,a) fill(ar,ar+N,a)
#define NEXTP(x) next_permutation(x.begin(),x.end())
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(a%b==0)return b;else return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}//saisyo kobaisu
#define pb push_back
#define pri(aa) cout<<(aa)<<endl
const ll INF=1e9+7;
const ll N = 100002;

template<class Abel> struct UnionFind {
    vector<int> par;
    vector<int> rank;
    vector<Abel> diff_weight;

    UnionFind(int n = 1, Abel SUM_UNITY = 0) {
        init(n, SUM_UNITY);
    }

    void init(int n = 1, Abel SUM_UNITY = 0) {
        par.resize(n); rank.resize(n); diff_weight.resize(n);
        for (int i = 0; i < n; ++i) par[i] = i, rank[i] = 0, diff_weight[i] = SUM_UNITY;
    }

    int root(int x) {
        if (par[x] == x) {
            return x;
        }
        else {
            int r = root(par[x]);
            diff_weight[x] += diff_weight[par[x]];
            return par[x] = r;
        }
    }

    Abel weight(int x) {
        root(x);
        return diff_weight[x];
    }

    bool issame(int x, int y) {
        return root(x) == root(y);
    }

    bool merge(int x, int y, Abel w) {
        w += weight(x); w -= weight(y);
        x = root(x); y = root(y);
        if (x == y) return false;
        if (rank[x] < rank[y]) swap(x, y), w = -w;
        if (rank[x] == rank[y]) ++rank[x];
        par[y] = x;
        diff_weight[y] = w;
        return true;
    }

    Abel diff(int x, int y) {
        return weight(y) - weight(x);
    }
};

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n,m;
	cin>>n>>m;
	UnionFind<int> uf(n);
	FOR(i,0,m){
		int l,r,d;
		cin>>l>>r>>d;
		--l;--r;
		if(uf.issame(l,r)){
			int diff = uf.diff(l,r);
			if(diff!=d){
				cout<<"No"<<endl;
				return 0;
			}
		}else{
			uf.merge(l,r,d);
		}
	}
	cout<<"Yes"<<endl;
	return 0;
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
#define rrep(i, n) for(int i=n-1; i>=0; i--)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define ALL(v) v.begin(),v.end()
#define pb push_back
#define eb emplace_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = 1e9+7;
template<class T> void puts(T x) { std::cout << x << std::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; }

struct WeightedUnionFind {
    vector<int> par, rank, weight;

    WeightedUnionFind(int n) {
        par.resize(n);
        rep(i, n) par[i] = i;
        rank.resize(n);
        weight.resize(n);
    }

    int find(int x) {
        if (par[x] == x) return x;

        int y = find(par[x]);
        weight[x] += weight[par[x]];
        par[x] = y;
        return y;
    }

    void relate(int x, int y, int w) {
        // a[y] = a[x] + w
        int rx = find(x);
        int ry = find(y);
        if (rank[rx] < rank[ry]) {
            par[rx] = ry;
            weight[rx] = w - weight[x] + weight[y];
        } else {
            par[ry] = rx;
            weight[ry] = -w - weight[y] + weight[x];
            if (rank[rx] == rank[ry]) rank[rx]++;
        }
    }

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

    int diff(int x, int y) {
        return weight[x] - weight[y];
    }
};

int main() {
    int n, q;
    cin >> n >> q;
    WeightedUnionFind tree(n);

    int t, x, y, z;
    vector<string> ans;
    rep(i, q) {
        cin >> t;
        if (t == 0) {
            cin >> x >> y >> z;
            tree.relate(x, y, z);
        } else {
            cin >> x >> y;
            if (tree.same(x, y)) {
                ans.pb(to_string(tree.diff(x, y)));
            } else {
                ans.pb("?");
            }
        }
    }

    rep(i, ans.size()) {
        cout << ans[i] << endl;
    }
}



Measured memory_bytes: 9704
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <set>
#include <algorithm>
#include <array>
#include <complex>
#include <string>
#include <utility>
#include <map>
#include <queue>
#include <list>
#include <functional>
#include <numeric>
#include <stack>
#include <tuple>
#include <fstream>
using namespace std;
int dx[4] = { -1,0,1,0 };
int dy[4] = { 0,1,0,-1 };
const int INF = 100000000;
const int BINF = 100000000000000001;
const long long LINF = 1000000000000000000;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-6;
const double pi = 3.14159265359;
using pii = std::pair<int, int>;
using ll = long long;
using pLL = std::pair<ll, ll>;
#define SORT(v) std::sort(v.begin(), v.end())
#define RSORT(v) std::sort(v.rbegin(), v.rend())


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<int>  a(N);
    ll ans = 0;
    for (int i = 0; i < N; ++i)cin >> a[i];
    SORT(a);
    for (int i = 0; i <=N ; ++i) {
        for (int j = i+1; j<N; ++j) {
            int k = lower_bound(a.begin(), a.end(), a[i] + a[j])-a.begin();
            ans += max(k - (j + 1), 0);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define MOD 1e9 + 7

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);

    int a[3],k;

    cin >> a[0] >> a[1] >> a[2] >> k;

    sort(a,a+3);

    cout << a[0]+a[1]+(1<<k)*a[2];

}


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

int main() {
  int M,N;
  cin>>M>>N;
  int i = 2*N+1;
  if(M%i ==0){
    cout<<M/i<<endl;
  }
  else{
    cout<<M/i +1<<endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
string s;
int a,b,x,y,xx,yy;

int  main(){
    cin>>s;
    for(int i=0;i<s.length();i++){
        if(i%2==0&&s[i]=='0')x++;
        else if(i%2==1&&s[i]=='1')x++;
    }

    for(int i=0;i<s.length();i++){
        if(i%2==0&&s[i]=='1')y++;
        else if(i%2==1&&s[i]=='0')y++;
    }
    cout<<min(x,y)<<endl;
}




Measured memory_bytes: 512
import Data.List

isFavoriteNumber :: Int -> [Int] -> Bool
isFavoriteNumber x ds =
  all (\d -> not(elem (head $ show d) strX)) ds
  where
    strX = show x

main = do
  [n, k] <- map	read . words <$> getLine
  ds <-	map (read :: String -> Int) . words <$> getLine
  putStrLn $ show $ head $ filter (\x -> isFavoriteNumber x ds) [n..]

Measured memory_bytes: 1020
#include "bits/stdc++.h"

using namespace std;
  
typedef unsigned long long ULL;
typedef long long LL;
typedef pair<int, int> pr;
typedef pair<LL, LL> lpr;
typedef pair<double, double> dpr;
typedef pair<long double, long double> ldpr;
typedef double db;
typedef long double ld;
typedef complex<double> cp;
typedef pair<ld,ld> pt;
  
#define dbgs(x) #x << " = " << x
#define dbgs2(x, y) dbgs(x) << ", " << dbgs(y)
#define dbgs3(x, y, z) dbgs2(x, y) << ", " << dbgs(z)
#define dbgs4(w, x, y, z) dbgs3(w, x, y) << ", " << dbgs(z)
 
#define mst(s, x) memset(s, x, sizeof(s))
#define fi first
#define se second
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define mp make_pair
#define all(x) x.begin(), x.end()
#define unq(x) x.erase(unique(x.begin(), x.end()), x.end())
#define rg register
#define fp(i, a, b) for (rg int i = (a), I = (b) + 1; i < I; ++i)
#define fd(i, a, b) for (rg int i = (a), I = (b)-1; i > I; --i)
#define ub upper_bound
#define lb lower_bound
#define bitcount __builtin_popcount
#define sqr(x) ((x)*(x))
 
#define go(u) for (rg int i = pre[u], v = e[i].v; i; i = e[i].next, v = e[i].v)
#define gow(u) for (rg LL i = pre[u], v = e[i].v, w = e[i].w; i; i = e[i].next, v = e[i].v, w = e[i].w)
#define EDGE(N,M) struct edge{int u,v,w,next;}e[M];int pre[N],edge_cnt=0;void addedge(int u,int v,int w=0){edge_cnt=edge_cnt+1,e[edge_cnt].u=u,e[edge_cnt].v=v,e[edge_cnt].w=w,e[edge_cnt].next=pre[u],pre[u]=edge_cnt;}
#define CLEAR_EDGE(N) {edge_cnt=0,memset(pre,0,sizeof(int)*(N+1));}
 
#define MAXSIZE (1 << 20)
#define isdigit(x) (x >= '0' && x <= '9')
 
#define MC int _CASE;scanf("%d",&_CASE);fp(case_num,1,_CASE)
  
const int next_x[8] = {0, 1, -1, 0, 1, 1, -1, -1};
const int next_y[8] = {1, 0, 0, -1, 1, -1, -1, 1};
const int inf = 1e9+5;//7;
const LL linf = 1e18;
const double PI = acos(-1.0);
  
const int MAXN = 1005+5;
const int N    = 1e6+5;

#define mid ((l+r)/2)
#define ls ((cnt<<1))
#define rs ((cnt<<1|1))
  
/*----------head----------*/

int n;
int work()
{
    scanf("%d",&n);
    printf("%d\n",((n/1000+(n%1000!=0))*1000-n));
    return 0;
}

// 小数 二分/三分 注意break条件
// 浮点运算 sqrt(a^2-b^2) 可用 sqrt(a+b)*sqrt(a-b) 代替，避免精度问题
// long double -> %Lf 别用C11 (C14/16)
// 控制位数 cout << setprecision(10) << ans;
// reverse vector 注意判空 不然会re
// 分块注意维护块上标记 来更新块内数组a[]
// vector+lower_bound常数 < map/set
// map.find不会创建新元素 map[]会 注意空间
// 别对指针用memset
// 用位运算表示2^n注意加LL  1LL<<20
// 注意递归爆栈
// 注意边界
// 注意memset 多组样例会T
  
//#define ONLINE_JUDGE

int main()
{
    // ios::sync_with_stdio(false);
    // cin.tie(0);
#ifdef ONLINE_JUDGE
    //freopen("triatrip.in", "r",stdin );
    //freopen("triatrip.out","w",stdout);
#endif // ONLINE_JUDGE
#ifndef ONLINE_JUDGE
    int size = 512 << 20; // 512MB  
    char *p = (char*)malloc(size) + size;  
    __asm__("movl %0, %%esp\n" :: "r"(p));
    freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
#endif
    work();
#ifndef ONLINE_JUDGE
    cout << "time:" << clock() << "ms" << endl;
    freopen("CON", "r", stdin);
    freopen("CON", "w", stdout);
    system("pause");
    fflush(stdout);
#endif
    return 0;
}

Measured memory_bytes: 3828
#include <iostream>

int main() {
	std::uint16_t A, B, C;
	std::cin >> A >> B >> C;

	bool haiku = (A == 5 && B == 5 && C == 7) ||
	             (A == 5 && B == 7 && C == 5) ||
	             (A == 7 && B == 5 && C == 5);

	std::cout << (haiku ? "YES" : "NO") << std::endl;

	return 0;
}

Measured memory_bytes: 256