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

#define ll long long

int DP1(int N, int T, int* A, int* B, int t, int i, int* D_DP1){
  if(t <= 0) return 0;
  if(i <= 0) return 0;
  if(D_DP1[i*T+t] >= 0) return D_DP1[i*T+t];
  int ret = DP1(N, T, A, B, t, i-1, D_DP1);
  if(t >= A[i-1]){
    int ret2 = DP1(N, T, A, B, t - A[i-1], i-1, D_DP1) + B[i-1];
    if(ret < ret2) ret = ret2;
  }
  D_DP1[i*T+t] = ret;
  return ret;
}

int DP2(int N, int T, int* A, int* B, int t, int i, int* D_DP2){
  if(t <= 0) return 0;
  if(i >= N) return 0;
  if(D_DP2[i*T+t] >= 0) return D_DP2[i*T+t];
  int ret = DP2(N, T, A, B, t, i+1, D_DP2);
  if(t >= A[i]){
    int ret2 = DP2(N, T, A, B, t - A[i], i+1, D_DP2) + B[i];
    if(ret < ret2) ret = ret2;
  }
  //cout << "debug " << t << " " << i << " " << j << " " << ret << endl;
  D_DP2[i*T+t] = ret;
  return ret;
}

int main(){
  int N, T;
  cin >> N >> T;
  int A[N], B[N];
  for(int i = 0; i < N; ++i) cin >> A[i] >> B[i];
  int DP1_D[N*T], DP2_D[N*T];
  for(int i = 0; i < N*T; ++i){
    DP1_D[i] = -1;
    DP2_D[i] = -1;
  }

  int ret = 0;
  int tmp;
  for(int i = 0; i < N; ++i){
    //cout << 'i' << ' ' << i << endl;
    for(int t = 0; t < T-1; ++t){
      tmp = B[i];
      tmp += DP1(N, T, A, B, t, i, DP1_D);
      tmp += DP2(N, T, A, B, T-t-1, i+1, DP2_D);
      // cout << B[i] << " "
      // 	   << DP(N, T, A, B, t, 0, i) << " "
      // 	   << DP(N, T, A, B, T-t-1, i+1, N) << endl;
      // cout << 't' << ' ' << t << ' '  << tmp << endl;
      if(ret < tmp) ret = tmp;
    }
  }
  cout << ret << endl;

  return 0;
}


Measured memory_bytes: 70912
#include <iostream>
using namespace std;
int main(int argc, char** argv) {
    long long a, b; cin >> a >> b;
    if (a * b <= 0) cout << "Zero\n";
    else if (b < 0 && (b - a) % 2 == 0) cout << "Negative\n";
    else cout << "Positive\n";
}


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

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            //[summary]A - Rotation
            var C1 = Console.ReadLine();
            var C2 = Console.ReadLine();

            if (C1 == String.Join("", C2.Reverse()))
            {
                Console.WriteLine("YES");
            }
            else
            {
                Console.WriteLine("NO");
            }            
        }
    }
}

Measured memory_bytes: 13268
#include<bits/stdc++.h>
#define mod 1000000007
using namespace std;

using ll = long long;
using ld = long double;

const ll inf = LONG_LONG_MAX;

ll binpow(ll a, ll b) {
    ll res = 1;
    while (b > 0) {
        if (b & 1){
            res = (res * a)%mod;
        }
        a = (a * a)%mod;
        b >>= 1;
    }
    return (res%mod);
}

signed main(){
	ll t;
	//cin >> t;

	t = 1;
	while(t--){
		string s;
		cin >> s;

		if(s == "ABC"){
			cout << "ARC";
		}
		else{
			cout << "ABC";
		}
	}
	return 0;
}

Measured memory_bytes: 3512
# ITP1_7_B - How Many Ways
import sys


def dfs(A, n, x):
    global ans
    if len(A) == 3:
        if sum(A) == x:
            ans += 1
        return

    else:
        if A:
            mini = max(A) + 1
        else:
            mini = 1

        for i in range(mini, n+1):
            B = A.copy()
            B.append(i)
            dfs(B, n, x)


while True:
    n, x = map(int, sys.stdin.readline().strip().split())
    if (n == 0) & (x == 0):
        break

    A = []
    ans = 0
    dfs(A, n, x)
    print(ans)





Measured memory_bytes: 5604
#include <bits/stdc++.h>
using namespace std;
using lli = int_fast64_t;
using ulli = uint_fast64_t;
#define debug(x) cerr << #x << " : " << x << endl
#define debugv(x) cerr << #x << " : {";for(auto value_of_x:x){ cerr << value_of_x << ", ";}cerr << endl
#define debugvp(x) cerr << #x << " : {";for(auto value_of_x:x){ cerr << value_of_x.first << " : " << value_of_x.second << ", ";}cerr << endl
template<typename T>
T ncr(T left, T right) {
	right = min(left - right, right);
	T ans = 1;
	for (T i = 1; i <= right; i++) {
		ans = ans * (left - right + i) / i;
	}
	return ans;
}

const lli MOD = 1000000007;
const lli LIMIT = 1'0'000'000'000'000'000 * 5;
const int tenfive = 100000;

int main() {
	char c;
	cin >> c;
	switch (c)
	{
	case 'A':
		c = 'T';
		break;
	case 'G':
		c = 'C';
		break;
	case 'C':
		c = 'G';
		break;
	case 'T':
		c = 'A';
		break;
	}
	cout << c << endl;
	return 0;
}


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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, k;
  cin >> n >> k;
  int ans = k;
  for(int j = 1; j < n; j++)
    ans *= (k-1);
  cout << ans << "\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
typedef long long ll;
#define ALL(v) v.begin(), v.end()
#define vmax(v) *max_element(ALL(v))
#define vmin(v) *min_element(ALL(v))
#define chmax(x, a) x = max(x, a)
#define chmin(x, a) x = min(x, a)

int main() {
    int N, K; cin >> N >> K;
    set<int> s;
    int d, A;
    rep(i, K) {
        cin >> d;
        rep(j, d) {
            cin >> A;
            s.insert(A);
        }
    }
    cout << N - s.size() << endl;
}


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

// begin fast read template by CYJian (source: https://www.luogu.com.cn/paste/i11c3ppx)

namespace io {
	const int __SIZE = (1 << 21) + 1;
	char ibuf[__SIZE], *iS, *iT, obuf[__SIZE], *oS = obuf, *oT = oS + __SIZE - 1, __c, qu[55]; int __f, qr, _eof;
	#define Gc() (iS == iT ? (iT = (iS = ibuf) + fread (ibuf, 1, __SIZE, stdin), (iS == iT ? EOF : *iS ++)) : *iS ++)
	inline void flush () { fwrite (obuf, 1, oS - obuf, stdout), oS = obuf; }
	inline void gc (char &x) { x = Gc(); }
	inline void pc (char x) { *oS ++ = x; if (oS == oT) flush (); }
	inline void pstr (const char *s) { int __len = strlen(s); for (__f = 0; __f < __len; ++__f) pc (s[__f]); }
	inline void gstr (char *s) { for(__c = Gc(); __c < 32 || __c > 126 || __c == ' ';)  __c = Gc();
		for(; __c > 31 && __c < 127 && __c != ' '; ++s, __c = Gc()) *s = __c; *s = 0; }
	template <class I> inline bool gi (I &x) { _eof = 0;
		for (__f = 1, __c = Gc(); (__c < '0' || __c > '9') && !_eof; __c = Gc()) { if (__c == '-') __f = -1; _eof |= __c == EOF; }
		for (x = 0; __c <= '9' && __c >= '0' && !_eof; __c = Gc()) x = x * 10 + (__c & 15), _eof |= __c == EOF; x *= __f; return !_eof; }
	template <class I> inline void print (I x) { if (!x) pc ('0'); if (x < 0) pc ('-'), x = -x;
		while (x) qu[++ qr] = x % 10 + '0',  x /= 10; while (qr) pc (qu[qr --]); }
	struct Flusher_ {~Flusher_(){flush();}}io_flusher_;
} using io::pc; using io::gc; using io::pstr; using io::gstr; using io::gi; using io::print;

// end fast read template by CYJian

#define iter(i, a, b) for(int i=(a); i<(b); i++)
#define rep(i, a) iter(i, 0, a)
#define rep1(i, a) iter(i, 1, (a)+1)
#define log(a) cerr<<"\033[32m[DEBUG] "<<#a<<'='<<(a)<<" @ line "<<__LINE__<<"\033[0m"<<endl
#define all(a) a.begin(), a.end()
#define fi first
#define se second
#define pb push_back
#define mp make_pair
 
using ll=long long;
using pii=pair<int, int>;
//#define int ll
const int MOD = 1000000007;

int cnt[200005];
int aray[200005];

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    ll ans = 0;
	int n; gi(n);
	rep(i, n) {
		gi(aray[i]);
		cnt[aray[i]]++;
	}
	rep1(i, n) ans += 1ll*cnt[i]*(cnt[i]-1)/2;
	rep(i, n) {
		print(ans - (cnt[aray[i]]-1)); pc('\n');
	}
}


Measured memory_bytes: 7168
def calc_ans(x):
    if x < 0:
        return 0
    elif x < X:
        return x
    else:
        return X


if __name__ == '__main__':
    # 砂の合計量
    X = int(input())

    # ひっくり返す回数
    K = int(input())
    # ひっくり返す秒数
    r = list(map(int, input().split()))
    # クエリの個数
    Q = int(input())

    # r の制御のための変数
    j = 0
    sign = -1
    s = 0
    e = X
    y = 0
    sand_quantity = [r[0]]
    for i in range(1, K):
        sand_quantity.append(r[i] - r[i - 1])

    chasm_time = 0
    for i in range(Q):
        # t:時刻 a:初期に A に入っている砂の量
        t, a = list(map(int, input().split()))
        while j < K and r[j] < t:
            y += sign * sand_quantity[j]
            # sについて更新
            if y < 0:
                s += -y
                if e < s:
                    s = e
                y = 0
            # eについて更新
            if X < y + e - s:
                tmp_diff = (y + e - s) - X
                e -= tmp_diff
                if e < s:
                    e = s
            if X < y:
                y = X

            chasm_time = r[j]
            j += 1
            sign *= -1

        tmp_time = t - chasm_time

        if a < s:
            ret = y
        elif a < e:
            ret = y + a - s
        else:
            ret = y + e - s

        ret += tmp_time * sign

        print(calc_ans(ret))
        # print("s:" + str(s) + " e:" + str(e) + " y:" + str(y) + " a:" + str(a) + " ret:" + str(ret))


Measured memory_bytes: 14716
#include <stdio.h>

int min(int a,int b){
  if(a < b){
    return a;
  }
  return b;
}

int max(int a,int b){
  if(a > b){
    return a;
  }
  return b;
}

int main(void){
  int N,K,X,Y;
  scanf("%d%d%d%d",&N,&K,&X,&Y);

  printf("%d\n",min(N,K)*X+max(N-K,0)*Y);

  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i = 0; i < (ll)(n); i++)
#define repi(i,a,b) for(ll i = (ll)(a); i < (ll)(b); i++)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll INF = 1LL << 60;
int main(){
    string s,t; cin >> s >> t;
    cout << t << s << endl;
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <vector>
#include <iostream>
#include <fstream>
#include <string>
#include <cmath>
#include <functional>
#include <queue>

using namespace std;

void Show(vector<vector<bool>> S) {
	for (int i = 0; i < S.size(); i++) {
		for (int j = 0; j < S[i].size(); j++) {
			if ((S[i][j])) {
				cout << '.';
			} else {
				cout << '#';
			}
		}
		cout << endl;
	}
}
int main() {
	string S;
	cin >> S;
	int Price = 700;
	for (int i = 0; i < 3; i++) {
		if (S[i] == 'o')Price += 100;
	}
	cout << Price << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define pb push_back
typedef long long ll;
typedef long double ld;

int main()
{
    //ios_base::sync_with_stdio(false);
    //cin.tie(NULL);

    ll N = 1e3 + 10, r, c, i, j;
    cin >> r >> c;
    char x;

    ll dp[N][N];
    for (i = 0; i < N; i++)
    {
        for (j = 0; j < N; j++)
        {
            dp[i][j] = -1;
        }
    }
    for (i = 0; i < N; i++)
    {
        dp[i][0] = dp[0][i] = 0;
    }
    dp[1][1] = 1;

    for (i = 1; i <= r; i++)
    {
        for (j = 1; j <= c; j++)
        {
            cin >> x;
            if (x == '#')
                dp[i][j] = 0;
        }
    }

    for (i = 0; i <= r; i++)
    {
        for (j = 0; j <= c; j++)
        {
            if (dp[i][j] == -1)
                dp[i][j] = (dp[i - 1][j] + dp[i][j - 1]) % mod;
        }
    }
    cout << dp[r][c] << "\n";

    return 0;
}

Measured memory_bytes: 8192
#include <bits/stdc++.h>
#define LOCAL
using namespace std;
template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
out << "(" << a.first << "," << a.second << ")";
return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << ": " << arg1 << " |";
__f(comma + 1, args...);
}
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
#define int long long
using P = pair<int,int>;
//#########################################
signed main(){
    char a;cin >> a;
    if(isupper(a))cout << 'A' << endl;
    else cout << 'a' << endl;
    return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
int num=0;	
string s;
int main()
{
	cin>>s;
int tt=s.size();
	int ok=0;
while(tt>2&&ok!=1)
{	int cs=0;
	for(int i=1;i<tt-1;i++)
	{
		if(s[i-1]!=s[i+1])
		{
			s.erase(i,1);
			num++;
			tt=s.size();
			break;
		}
		else
		{
			cs++;
		}
		if(cs==tt-2)
		{
		ok=1;
		break;
		}
         
	}
	}
	if(num%2==0)
	cout<<"Second";
	else
	cout<<"First";
	return 0;
}

Measured memory_bytes: 512
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
      // 準備するよ！
      Scanner sc = new Scanner(System.in);
      String s = sc.next();
      String t = sc.next();
      char[] sAry = new char[s.length()];
      char[] tAry = new char[t.length()];

      for(int i=0; i < sAry.length; ++i) sAry[i] = s.charAt(i);
      for(int i=0; i < tAry.length; ++i) tAry[i] = t.charAt(i);

      // 解くよ！
      int ans = 1001;

      // 比較開始位置のfor文（1文字目～S-T+1文字目まで)
      // 注意：この"文字目"は問題文が示す文字数。添え字ではない。
      for(int i=0; i <= sAry.length - tAry.length; ++i) {
        int answk = 0;

        // T文字分比較するよ
        for(int j=0; j<tAry.length; ++j) {
          if(sAry[i+j] != tAry[j]) ++answk;
        }

        if(answk < ans) ans = answk;

      }

      if(ans == 1001) ans = 0;

      System.out.println(ans);

    }
}

Measured memory_bytes: 35636
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair < ll, ll > PLL;
#define rep(i,n) for (int i = 0; i < (n); ++i)
ll MOD = 1e9+7;
int main() {
    int h, w;
    cin >> h >> w;
    vector<vector<char>> hw(h, vector<char>(w));
    vector<pair<int, int>> sep;
    rep(i, h) rep(j, w) {
        cin >> hw[i][j];
        if ( hw[i][j] == '.' ) sep.emplace_back(i, j);
    }
    int dx[4] = {1, -1, 0, 0};
    int dy[4] = {0, 0, 1, -1};
    int ans = 0;
//    vector<int> ans;
    rep(i, sep.size()) rep(j, sep.size()) {
        if ( i == j ) continue;
        bool ok = false;
        pair<int, int> sp = sep[i];
        pair<int, int> ep = sep[j];
        vector<vector<int>> cnt(h, vector<int>(w, 1e8));
        queue<pair<int, int>> que;
        que.push(sp);
        cnt[sp.first][sp.second] = 0;
        while(!que.empty()) {
            pair<int, int> np = que.front();
            que.pop();
            if ( np.first == ep.first && np.second == ep.second ) {
                ok = true;
                break;
            }
            rep(k, 4) {
                int next_y = np.first + dy[k];
                int next_x = np.second + dx[k];
                if ( next_y >= h || next_y < 0 || next_x >= w || next_x < 0 ) continue;
                if ( hw[next_y][next_x] == '#' ) continue;
                if ( cnt[next_y][next_x] != 1e8 ) continue;
                que.push(make_pair(next_y, next_x));
                cnt[next_y][next_x] = min(cnt[next_y][next_x], cnt[np.first][np.second] + 1);
            }
        }
//        rep(l, h) {
//            rep(m, w) cout << cnt[i][j] << " ";
//            cout << endl;
//        }
        ans = max(ans, cnt[ep.first][ep.second]);
//        if ( ok ) ans.push_back(cnt[ep.first][ep.second]);
    }
    cout << ans << endl;
//    rep(i, ans.size()) cout << ans[i] << endl;
    return 0;
}


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

int main() {
    long long A, B, C, K;
    cin >> A >> B >> C >> K;

    long long i, j, k;

    if (K >= A) {
        // K=4, B=2
        i = A;
    } else {
        // K=2, B=3
        i = K;
    }
    K -= i;
    // cout << K << endl;

    if (K >= B) {
        // K=4, B=2
        j = B;
    } else {
        // K=2, B=3
        j = K;
    }
    K -= j;
    // cout << K << endl;

    if (K >= C) {
        // K=4, C=2
        k = C;
    } else {
        // K=2, C=3
        k = K;
    }
    K -= k;
    // cout << K << endl;

    long long res = i*1 + 0*j + -1*k;
    cout << res << endl;
}

Measured memory_bytes: 3092
//連想コンテナ setによる解法
#include <iostream>
#include <set>
#include <vector>
using namespace std;

int main(){
    int N,res;
    cin >> N;
    res = 0;
    vector<int> vec(110);
    for(int i = 0;i < N;i++) cin >> vec.at(i);

    set<int> values;
    for(int i = 0;i < N;i++) values.insert(vec.at(i));

    cout << values.size() << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,a[105],b[105];
int main()
{
	cin>>n;
	int flag=0;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i]>>b[i];
		if(a[i]==b[i]) flag++;
		else flag=0;
		if(flag==3)
		{
			cout<<"Yes"<<endl;
			return 0;
		}
	}
	cout<<"No"<<endl;
}

Measured memory_bytes: 3628
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<stack>
#include<bitset>
#include<cstdlib>
#include<cmath>
#include<set>
#include<list>
#include<deque>
#include<map>
#include<queue>
using namespace std;
typedef long long ll;
const double PI = acos(-1.0);
const double eps = 1e-6;
const int INF = 1000000000;
const int mod = 1e9+7;
const int maxn = 2e5+5;
ll sr[maxn];
ll sb[maxn];
ll sg[maxn];
int main() {
	int n;
	cin>>n;
	string s;
	cin>>s;
	if(s[0]=='R') sr[1] = 1;
	if(s[0]=='G') sg[1] = 1;
	if(s[0]=='B') sb[1] = 1;
	for(int i=1;i<s.length();i++){
		sr[i+1] = sr[i];
		sg[i+1] = sg[i];
		sb[i+1] = sb[i];
		if(s[i]=='R') sr[i+1]++;
		if(s[i]=='G') sg[i+1]++;
		if(s[i]=='B') sb[i+1]++;
	}
	ll ans = 0;
	for(int i=1;i<n;i++){
		if(s[i]=='G'){
			ll add = 0;
			for(int j=1;(i-j)>=0&&(i+j)<n;j++){
				if(s[i-j]=='R'&&s[i+j]=='B'){
					add++;
				}
				if(s[i-j]=='B'&&s[i+j]=='R'){
					add++;
				}
			}
			ll sum = (sr[i]*(sb[n]-sb[i]))+(sb[i]*(sr[n]-sr[i]));
			sum-=add;
			ans+=sum;
		}
		if(s[i]=='R'){
			ll 	add = 0;
			for(int j=1;(i-j)>=0&&(i+j)<n;j++){
				if(s[i-j]=='G'&&s[i+j]=='B'){
					add++;
				}
				if(s[i-j]=='B'&&s[i+j]=='G'){
					add++;
				}
			}
			ll sum = (sg[i]*(sb[n]-sb[i]))+(sb[i]*(sg[n]-sg[i]));
			sum-=add;
			ans+=sum;
		}
		if(s[i]=='B'){
			ll add = 0;
			for(int j=1;(i-j)>=0&&(i+j)<n;j++){
				if(s[i-j]=='G'&&s[i+j]=='R'){
					add++;
				}
				if(s[i-j]=='R'&&s[i+j]=='G'){
					add++;
				}
			}
			ll sum = (sg[i]*(sr[n]-sr[i]))+(sr[i]*(sg[n]-sg[i]));
			sum-=add;
			ans+=sum;
		}
	}
	cout<<ans<<endl;
    return 0;
}

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

int main(){
    int x = 0;
    int n = 0;
    cin >> x >> n;

    if (0 == n){
        cout << x << endl;
        return 0;
    }

    int p[n];
    int num[102] = {0};
    int tmp = 0;

    for (int i = 0; i < n; i++){
        cin >> p[i];
        num[p[i]] = 1;
    }

    int dif0 = 100;
    int dif = 0;
    int target = 100;
    for(int i = 0; i <= 101; ++i){
        if(0 == num[i]){
            dif = abs(i - x);
            if(dif < dif0){
                dif0 = dif;
                target = i;
            }
            else if(dif == dif0){
                if(i + 1 < target){
                    target = i;
                }
            }
        }
    }
    cout << target << endl;
    
    return 0;
}

Measured memory_bytes: 3580
#include <iostream>

using namespace std;

#define ll long long
#define double long double
#define FOR(i,a,b) for(long i = a; i <= b; i++)
#define FOD(i,b,a) for(long i = b; i >= a; i--)

#define DEBUG(x) cerr << #x << " = " << x << endl

#define mod 1000000007

int main(){
	ios_base::sync_with_stdio(0);
	ll n, a[100005];
	ll mi = 1001, ma = -1;
	cin >> n;
	FOR(i,1,n) cin >> a[i], mi = min(mi,a[i]), ma = max(ma,a[i]);
	cout << ma - mi;
	

	return 0;
}





Measured memory_bytes: 256
class Combination:
    def __init__(self, n, mod):
        self.n = n
        self.mod = mod
        self.fac = [1 for i in range(self.n + 1)]
        self.finv = [1 for i in range(self.n + 1)]
        for i in range(2, self.n+1):
            self.fac[i] = (self.fac[i - 1] * i) % self.mod
            self.finv[i] = (self.finv[i-1] * pow(i, -1, self.mod)) % self.mod

    def comb(self, n, m):
        return self.fac[n] * (self.finv[n-m] * self.finv[m] % self.mod) % self.mod
def iparse():
    return list(map(int, input().split()))


if __name__ == "__main__":
    n = int(input())
    ml = 1
    last = [0,0]
    for i in range(n):
        x = iparse()
        # print(len(x))
        l = (last[0] + x[0] - 1) // x[0]
        r = (last[1] + x[1] - 1) // x[1]
        m = max(l, r)
        if m == 0:
            m = 1
        x[0] *= m
        x[1] *= m
        
        last = x
    print(sum(last))
    
        
    


Measured memory_bytes: 9084
import sys
import collections
from functools import lru_cache

sys.setrecursionlimit(10 ** 7 + 1)
xy = []
d = collections.defaultdict(list)

@lru_cache(maxsize=None)
def alg_memoization_recursion(f):
    mt = 0
    for v in d[f]:
        mt = max(mt, alg_memoization_recursion(v) + 1)
    return mt


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    n, m = list(map(int, readline().split()))
    for i in range(m):
        x, y = list(map(int, readline().split()))
        d[x-1] += [y-1]
    mt = 0
    for i in range(n):
        mt = max(mt, alg_memoization_recursion(i))
    print(mt)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 653824
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> VI;
 
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()

int main() {
    int n, m;
    cin >> n >> m;
    vector<vector<int>> A(n, vector<int>(n)), B(m, vector<int>(m));
    rep (i, n) {
        string a;
        cin >> a;
        rep (j, n) {
            if (a[j] == '#') {
                A[i][j] = 1;
            }
            else {
                A[i][j] = 0;
            }
        }
    }
    rep (i, m) {
        string b;
        cin >> b;
        rep (j, m) {
            if (b[j] == '#') {
                B[i][j] = 1;
            }
            else {
                B[i][j] = 0;
            }
        }
    }
    rep (i, n - m + 1) {
        rep (j, n - m + 1) {
            bool flag = true;
            rep (k, m) {
                rep (l, m) {
                    if (A[i+k][j+l] != B[k][l]) {
                        flag = false;
                    }
                }
            }
            if (flag) {
                cout << "Yes" << endl;
                exit(0);
            }
        }
    }
    cout << "No" << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int a[3];
	int max = -1;
	int min = 100001;
	int i, j, k;
	for (i = 0; i < 3; i++)
	{
		scanf("%d", &a[i]);
		if (max < a[i])
		{
			max = a[i];
			j = i;
		}
		if (min > a[i])
		{
			min = a[i];
			k = i;
		}
		
	}
	a[k] = 0; 
	a[j] = 0;
	printf("%d %d %d\n", min, a[0] + a[1] + a[2], max);

	return 0;
}

Measured memory_bytes: 1824
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i,n) for(int i = 0; i < (int)(n); ++i)
#define DEBUG(x) cerr << #x << " = " << x << endl
int X[30], W[30];
signed main() {
  int L, N; cin >> L >> N;
  REP(i,N) cin >> X[i] >> W[i];
  cout << N << endl;
  REP(i,N) {
    cout << -X[i] << ' ' << W[i] << endl;
  }
}

Measured memory_bytes: 3088
from collections import deque
n, q = map(int, input().split())
Q =[]
for i in range(n):
    Q.append(deque())
for i in range(q):
    a = input().split()
    a[1] =int(a[1])
    if a[0] == "0":
        Q[a[1]].append(a[2])
    elif a[0] == "1" and Q[a[1]]:
        print(Q[a[1]][0])
    elif a[0] == "2" and Q[a[1]]:
        Q[a[1]].popleft()




Measured memory_bytes: 20832
#include <bits/stdc++.h>
#define mod 1000000007
using namespace std;
typedef long long int ll;
int main(){
    ll n;
    cin>>n;
    ll a[n];
    ll x=0;
    for(ll i=0;i<n;i++){
        cin>>a[i];
        x^=a[i];
    }
    for(ll i=0;i<n;i++){
        cout<<(x^a[i])<<" ";
    }
    cout<<"\n";
}


Measured memory_bytes: 5116
#include <iostream>

using namespace std;

int main()
{
    int n;
    cin >> n;
    bool ok = true;
    int nr = 4;
    if(((n/1000) % 10 == (n / 100) % 10) || ((n/100) % 10 == (n/10) % 10) || ((n / 10) % 10 == n % 10))
        cout << "Bad";
    else
        cout << "Good";
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

void quickSort(int arr[], int low , int high){//mencari posisi pivot 
	int i,j,pivot,temp;
	if(low<high){
		pivot = low;//pivot sebagai data pertama
		i = low;
		j = high;
		
		while(i<j){
		//menyusun array dengan menaruh data yang lebih kecil dari pivot pada satu sisi dan sisi lainnya untuk yang lebih besar dair pivot
			while(arr[i]<=arr[pivot]&&i<high){
				i++;
			}
			while(arr[j]>arr[pivot]){
				j--;
			}
			if(i<j){
				temp=arr[i];
				arr[i]=arr[j];
				arr[j]=temp;
			}
		}
		//menaruh pivot di tempat yang membagi array
		temp = arr[pivot];
		arr[pivot]=arr[j];
		arr[j]=temp;
		quickSort(arr,low,j-1);
		quickSort(arr,j+1,high);
	}
}

int main(){
	int k,n;
	
	scanf("%d %d",&k,&n);
	
	int i,data[2000];
	for(i=0;i<k;i++){
		scanf("%d ",&data[i]);
	}
	quickSort(data,0,k-1);
	int sum=0;
	
	for(i=0;i<n;i++){
		sum+=data[i];
	}
	printf("%d",sum);
	
	
	
	
	return 0;
}


Measured memory_bytes: 1724
#include <bits/stdc++.h>
#define LL long long
#define FOR(i,a,b) for(int i=a; i<=b; i++)
#define FOD(i,a,b) for(int i=a; i>=b; i--)
#define pa pair<int,int>
#define fi first
#define se second
#define MOD xxx
#define getbit(n,i) ((n>>(i-1))&1)
#define offbit(n,i) ((n^(1<<(i-1))
#define onbit(n,i) (n|(1<<(i-1)))
#define cntone(x) (__builtin_popcount(x))

using namespace std;
string s;
int n,ans(0);
int main()
{
    cin >> s;
    n = s.size();
    for(int i = 0; i < s.size(); i++)
    if(s[i]!=s[n-i-1]) ans++;
    cout << ans/2;
	return 0;
}


Measured memory_bytes: 3632
use std::io::*;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
  let stdin = stdin();
  let stdin = stdin.lock();
  let token: String = stdin
    .bytes()
    .map(|c| c.expect("failed to read char") as char)
    .skip_while(|c| c.is_whitespace())
    .take_while(|c| !c.is_whitespace())
    .collect();
  token.parse().ok().expect("failed to parse token")
}

use std::cmp::{max, min};

fn main() {
  let a = read::<i64>();
  let b = read::<i64>();
  let c = read::<i64>();
  let x = read::<i64>();
  let y = read::<i64>();

  if a + b <= 2 as i64 * c {
    println!("{}", x * a + y * b);
  } else {
    let min1 = min(x, y);
    let min2 = min(2 * c, a);
    let min3 = min(2 * c, b);
    println!("{}", min1 * c * 2 + (x - min1) * min2 + (y - min1) * min3);
  }

}



Measured memory_bytes: 4352
#include <iostream>
using namespace std;
int main(int argc, const char * argv[]) {
    int a, b, c, d;
    d=0;
    cin >> a >> b >> c;
    for(int i =a; i<=b; i++){
        if(c%i ==0){
            
            d = d +1;
        }
    
        
    }
    cout << d <<endl;
     return 0;
}

Measured memory_bytes: 1164
#include<bits/stdc++.h>
using namespace std;
using i64 = int_fast64_t;
#define rep(i, N) for(int (i) = 0; (i) < (N); (i)++)
#define all(v) (v).begin(), (v).end()
#define eb emplace_back

int main(){
    int N;
    cin >> N;
    vector<int> B(N);
    rep(i,N) cin >> B[i];
    vector<int> ans;

    for(int i = N; i > 0; i--){
        for(int j = i; j > 0; j--){
            if(j-1 >= B.size()) continue;
            if(B[j-1] == j){
                ans.emplace_back(j);
                B.erase(B.begin() + j-1);
                break;
            }
        }
    }
    if(B.size() != 0) cout << -1 << endl;
    else {
        reverse(all(ans));
        for(auto& a : ans) cout << a << endl;
    }
    
}



Measured memory_bytes: 256
#ifndef ___Class_RangeTree
#define ___Class_RangeTree

// ------ Includes ------ //
#include <limits>
#include <vector>
#include <algorithm>

template<typename Type> class RangeTree {
private:
	int size_;
	std::vector<std::vector<Type> > dat;
	std::vector<std::vector<int> > vl;
	inline int query_(int a, int b, Type x, int k, int l, int r, int e) {
		// Find range [a, b) : value < x : Now k-th node and the range is [l, r) and e integers below x in the range
		if (r <= a || b <= l || e == 0) return 0;
		if (a <= l && r <= b) return e;
		int lc = query_(a, b, x, k << 1, l, (l + r) >> 1, vl[k][e - 1]);
		int rc = query_(a, b, x, k << 1 | 1, (l + r) >> 1, r, e - vl[k][e - 1]);
		return lc + rc;
	}
public:
	RangeTree() : size_(0), dat(std::vector<Type>()) {};
	template<class T>
	RangeTree(T begin_, T end_) {
		int n = (end_ - begin_);
		for (size_ = 1; size_ < n; size_ <<= 1);
		dat.resize(size_ << 1);
		vl.resize(size_);
		for (int i = 0; i < n; i++) dat[i + size_].push_back(*(begin_ + i));
		for (int i = size_ - 1; i > 0; i--) {
			dat[i].resize(dat[i << 1].size() + dat[i << 1 | 1].size());
			vl[i].resize(dat[i].size());
			int cl = 0;
			for (int j = 0; j < dat[i].size(); j++) {
				if (j - cl == dat[i << 1 | 1].size() || (cl != dat[i << 1].size() && dat[i << 1][cl] < dat[i << 1 | 1][j - cl])) dat[i][j] = dat[i << 1][cl++];
				else dat[i][j] = dat[i << 1 | 1][j - cl];
				vl[i][j] = cl;
			}
		}
	}
	inline int size() { return size_; }
	inline int query(int l, int r, Type x) {
		// Find range [a, b) : value < x
		int ptr = lower_bound(dat[1].begin(), dat[1].end(), x) - dat[1].begin();
		return query_(l, r, x, 1, 0, size_, ptr);
	}
};

#endif

#include <cstdio>
#include <vector>
#pragma warning(disable : 4996)
using namespace std;
struct query {
	int l, r;
};
bool compare(const query& q1, const query& q2) {
	return q1.r < q2.r;
}
// rc[k] : number of q[i].r < k
int N, M, dat[300009], rc[300009], ret[300009]; query q[300009];
int main() {
	scanf("%d%d", &N, &M);
	for (int i = 0; i < N; i++) scanf("%d%d", &q[i].l, &q[i].r);
	sort(q, q + N, compare);
	for (int i = 0; i < N; i++) dat[i] = q[i].l;
	int ptr = 0;
	for (int i = 1; i <= M; i++) {
		while (ptr < N && q[ptr].r < i) ptr++;
		rc[i] = ptr;
	}
	RangeTree<int> Q(dat, dat + N);
	for (int i = 1; i <= M; i++) {
		for (int j = i; j <= M; j += i) {
			ret[i] += Q.query(rc[j], N, j + 1);
			ret[i] -= Q.query(rc[j], N, j - i + 1);
		}
	}
	for (int i = 1; i <= M; i++) printf("%d\n", ret[i]);
	return 0;
}

Measured memory_bytes: 107904
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>

#define REP(i, n) for(int i = 0;i < n;i++)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define ALL(a) (a).begin(), (a).end()

using namespace std;

int count_from_v(const vector<vector<int>> &graph, int v, int except)
{
    //cout << v << ":" << except << endl;

    int sum = 1;

    const auto &edges = graph[v];

    REP(i, edges.size())
    {
        if( edges[i] == except ) continue;

        sum += count_from_v(graph, edges[i], v);
    }

    return sum;
}

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

    vector<vector<int>> graph(N);

    REP(i, N - 1) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;

        graph[a].push_back(b);
        graph[b].push_back(a);
    }

    vector<int> distance_from_f(N, -1);

    // vertex, current_cost
    queue<pair<int, int>> next;
    next.push(make_pair(0, 0));

    while(!next.empty())
    {
        auto front = next.front(); next.pop();

        if( distance_from_f[front.first] != -1 ) continue;
        distance_from_f[front.first] = front.second;

        const auto &edges = graph[front.first];

        REP(i, edges.size())
        {
            int next_vertex = edges[i];
            next.push(make_pair(next_vertex, front.second + 1));
        }
    }

    int current = N - 1;
    vector<int> route; route.reserve(N);
    while(true)
    {
        route.push_back(current);

        const auto &edges = graph[current];
        int prev_v = -1;

        REP(i, edges.size())
        {
            if( distance_from_f[edges[i]] + 1 == distance_from_f[current] )
            {
                prev_v = edges[i];
                break;
            }
        }

        if( prev_v == -1 )
        {
            // reached
            break;
        }
        else
        {
            current = prev_v;
        }
    }

    reverse(ALL(route));

    /*REP(i, route.size())
    {
        cout << route[i] << endl;
    }*/

    int fennec;
    if( route.size() % 2 == 0 )
    {
        fennec = count_from_v(graph, route[route.size() / 2 - 1], route[route.size() / 2]);
    }
    else
    {
        fennec = count_from_v(graph, route[route.size() / 2], route[route.size() / 2 + 1]);
    }

    int snuke = N - fennec;

    if( fennec > snuke )
    {
        cout << "Fennec" << endl;
    }
    else
    {
        // equal -> 先攻が塗れなくなるので，後攻が勝つ
        cout << "Snuke" << endl;
    }

    return 0;
}


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

#define rep(i,n) for(int i = 0; i < n; i++)
#define REP(i,n) for(int i = 1; i < n; i++)
#define sz(x) int(x.size())
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define YesorNo(a) printf(a ? "Yes\n" : "No\n")
#define endl '\n'
#define fi first
#define se second
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
using vi = vector<int>;
using vii = vector<vi>;
using vl = vector<ll>;
using vll = vector<vl>;
using vs = vector<string>;
using vb = vector<bool>;
using vc = vector<char>;
using vcc = vector<vc>;
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
const int inf = (1<<30)-1;
const ll infll = (1LL<<62)-1;
ll ceil(const ll &a, const ll &b){return ((a)+(b)-1)/b;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }



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

  int n, k;
  cin >> n >> k;
  vi snuke(n);
  rep(i,k) {
    int d;
    cin >> d;
    rep(j,d) {
      int a;
      cin >> a;
      snuke[a-1]++;
    }
  }
  int ans = 0;
  rep(i,n) {
    if(snuke[i] == 0) ans++;
  }
  cout << ans << endl;
}

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

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long s = 0;

		int[] numArr = new int[100005];

		for (int i = 0; i < n; i++) {
			int a = sc.nextInt();
			numArr[a] ++;
			s+=a;
		}

		int q = sc.nextInt();
		int[][] qs = new int[q][2];
		for (int i = 0; i < q; i++) {
			qs[i][0] = sc.nextInt();
			qs[i][1] = sc.nextInt();
		}

		for (int i = 0; i < qs.length; i++) {
			int b = qs[i][0];
			int c = qs[i][1];

			long bCnt = numArr[b];
			long bMinus = bCnt*b;
			numArr[b] = 0;

			long cPlus = bCnt*c;
			numArr[c] +=bCnt;

			s -=bMinus;
			s +=cPlus;

			System.out.println(s);
		}
	}

}

Measured memory_bytes: 58952
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <string>
#include <unordered_map>
using namespace std;

long long gcd(long long a, long long b){
    long long tmp;
    if (a < b){
        tmp = b;
        b = a;
        a = tmp;
    }
    while (b > 0){
        tmp = b;
        b = a % b;
        a = tmp;
    }
    return a;
}


int main(){
    int n;
    cin >> n;
    long long a[n];
    for (int i = 0; i < n; i++){
        cin >> a[i];
    }
    long long l[n], r[n];
    l[0] = a[0];
    for (int i = 1; i < n; i++){
        l[i] = gcd(a[i], l[i - 1]);
    }

    r[n - 1] = a[n - 1];
    for (int i = n - 2; i >= 0; i--){
        r[i] = gcd(a[i], r[i + 1]);
    }

    long long answer = 1;
    for (int i = 0; i < n; i++){
        if (i == 0){
            answer = max(answer, r[i + 1]);
        }
        else if (i == n - 1){
            answer = max(answer, l[i - 1]);
        }
        else {
            answer = max(answer, gcd(l[i - 1], r[i + 1]));
        }
    }
    cout << answer << endl;
    return 0;
}

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

#include <boost/multiprecision/cpp_int.hpp>

// increment
#define rep_n(_1, _2, _3, NAME, ...) NAME
#define rep_2(i, n) for (int(i) = 0; (i) < (int)(n); ++(i))
#define rep_3(i, initial, n) \
  for (int(i) = (int)(initial); (i) < (int)(n); ++(i))
#define rep(...) rep_n(__VA_ARGS__, rep_3, rep_2, rep_1)(__VA_ARGS__)
// decrement
#define rep_r_n(_1, _2, _3, NAME, ...) NAME
#define rep_r_2(i, n) for (int(i) = (int)(n); (i) > 0; (i)--)
#define rep_r_3(i, initial, n) \
  for (int(i) = (int)(initial); (i) > (int)(n); (i)--)
#define rep_r(...) rep_r_n(__VA_ARGS__, rep_r_3, rep_r_2)(__VA_ARGS__)
// define type definition
using namespace std;
typedef long long ll;
using mpint = boost::multiprecision::cpp_int;  // 多倍長整数（任意精度）
typedef pair<int, int> P;

// define construct variable
const double EPS = numeric_limits<double>::epsilon();
// 10^9 + 7
const ll MOD = ll(1e9) + 7;
const ll INF = ll(1e10);
const string ALPHABET = "abcdefghijklmnopqrstuvwxyz";
const double PI = acos(-1);

// define methods
// 最大公約数
ll gcd(const ll a, const ll b) { return b ? gcd(b, a % b) : a; }
// 最小公倍数
ll lcm(const ll a, const ll b) { return a / gcd(a, b) * b; }
// char -> int
int ctoi(char c) { return (int)(c - '0'); }
// 素因数分解
vector<pair<ll, ll>> prime_factorize(ll n) {
  vector<pair<ll, ll>> p;
  for (ll i = 2; i * i <= n; i++) {
    if ((n % i) != 0) continue;
    pair<ll, ll> a = make_pair(i, 0);
    while ((n % i) == 0) {
      n /= i;
      a.second += 1;
    }
    p.push_back(a);
  }

  if (n != 1) p.push_back(make_pair(n, 1));
  return p;
}
// 組み合わせの整合性を保つ（後ほど解析する）
ll modinv(ll a) {
  ll b = MOD, u = 1, v = 0;
  while (b) {
    ll t = a / b;
    a -= t * b;
    swap(a, b);
    u -= t * v;
    swap(u, v);
  }
  u %= MOD;
  if (u < 0) {
    u += MOD;
  }
  return u;
}
// 順列
ll permutation(const ll n, const ll m) {
  ll result = 1;
  for (ll i = n; i > n - m; i--) {
    result = (result * i) % MOD;
  }
  return result;
}

// 繰り返し n 乗法
ll repeat_square(const ll n, const ll x) {
  if (x == 0) return 1;
  ll res = repeat_square(n, x / 2);
  res = res * res % MOD;
  if ((x % 2) == 1) res = res * n % MOD;
  return res;
}
// 組み合わせ nCm
ll combination(ll n, ll m) {
  ll p = permutation(n, m);
  ll div = 1;
  for (ll i = 2; i <= m; i++) {
    div = (div * i) % MOD;
  }
  return (p * modinv(div)) % MOD;
}

// アルファベットの取得
string get_alphabet(ll n) {
  n--;
  return string(1, 'a' + (n % 26));
}

int main() {
  string S;
  ll K;
  ll sum = 0;
  cin >> S >> K;

  // ll flag = ll(1e18);
  // ll x = 2, c = 0;
  // while (true) {
  //   x *= 2;
  //   c++;
  //   if (x > flag) {
  //     cout << x << endl;
  //     cout << c << endl;
  //     break;
  //   }
  // }

  rep(i, S.length()) {
    if (i+1 == K) {
      cout << S[i] << endl;
      return 0;
    }
    if (S[i] != '1') {
      cout << S[i] << endl;
      return 0;
    }
  }
  cout << "1" << endl;
  return 0;
}


Measured memory_bytes: 3556
#include<bits/stdc++.h>
using namespace std;
long long n;
void solve(long long x) 
{
	if(x!=0)
	 {
		int d=x%26;
		if(d==0) 
		solve(x/26-1);
		else solve(x/26);
		if(d==0) putchar('z');
		else putchar(d+'a'-1);
	}
}
int main()
{
	cin>>n;
	solve(n);
	return 0;
}

Measured memory_bytes: 3564
#include<iostream>
#include<iomanip>
#include<math.h>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<tuple>
#include<complex>
#define REP(i, N) for(ll i = 0; i < N; ++i)
#define FOR(i, a, b) for(ll i = a; i < b; ++i)
#define ALL(a) (a).begin(),(a).end()
#define pb push_back
#define INF (long long)1000000000
#define MOD 1000000007
#define EPS (long double) 1e-8
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
int dh[4] = {1, 0, -1, 0};
int dw[4] = {0, 1, 0, -1};

using namespace std;

int main() {
	ll n;
	cin>>n;
	vector<P> p(n);
	REP(i, n) cin>>p[i].first>>p[i].second;
	vector<bool> used(n, false);
	set<P> x;
	set<P> y;
	REP(i, n) {
		P xi, yi;
		xi.first = p[i].first;
		xi.second = i;
		yi.first = p[i].second;
		yi.second = i;
		x.insert(xi);
		y.insert(yi);
	}
	ll res = 0;
	priority_queue<P, vector<P>, greater<P> > q;
	used[0] = true;
	set<P>::iterator itex = x.find(P(p[0].first, 0));
	set<P>::iterator itey = y.find(P(p[0].second, 0));
	if(itex !=  x.begin()) {
		ll cx = (*itex).first;
		--itex;
		ll nx = (*itex).first;
		q.push(P((cx - nx), (*itex).second));
		++itex;
	}
	if(itex !=  --(x.end())) {
		ll cx = (*itex).first;
		++itex;
		ll nx = (*itex).first;
		q.push(P((nx - cx), (*itex).second));
		--itex;
	}
	if(itey !=  y.begin()) {
		ll cy = (*itey).first;
		--itey;
		ll ny = (*itey).first;
		q.push(P((cy - ny), (*itey).second));
		++itey;
	}
	if(itey !=  --(y.end())) {
		ll cy = (*itey).first;
		++itey;
		ll ny = (*itey).first;
		q.push(P((ny - cy), (*itey).second));
		--itey;
	}
	x.erase(itex);
	y.erase(itey);
	while(!q.empty()) {
		P cp = q.top();
		q.pop();
		if(used[cp.second]) continue;
		used[cp.second] = true;
		res += cp.first;
		itex = x.find(P(p[cp.second].first, cp.second));
		itey = y.find(P(p[cp.second].second, cp.second));
		if(itex !=  x.begin()) {
			ll cx = (*itex).first;
			--itex;
			ll nx = (*itex).first;
			q.push(P((cx - nx), (*itex).second));
			++itex;
		}
		if(itex != --(x.end())) {
			ll cx = (*itex).first;
			++itex;
			ll nx = (*itex).first;
			q.push(P((nx - cx), (*itex).second));
			--itex;
		}
		if(itey !=  y.begin()) {
			ll cy = (*itey).first;
			--itey;
			ll ny = (*itey).first;
			q.push(P((cy - ny), (*itey).second));
			++itey;
		}
		if(itey !=  --(y.end())) {
			ll cy = (*itey).first;
			++itey;
			ll ny = (*itey).first;
			q.push(P((ny - cy), (*itey).second));
			--itey;
		}
		x.erase(itex);
		y.erase(itey);
	}
	cout<<res<<endl;
}

Measured memory_bytes: 20464
import sys
N, M = list(map(int, input().split()))
A = [-1] * N
flg = True
for i in range(M):
    s, c = list(map(int, input().split()))
    if A[s - 1] == -1 or A[s - 1] == c:
        A[s - 1] = c
    else:
        flg = False
    if N > 1 and s == 1 and c == 0:
        flg = False
if not flg:
    print(-1)
    sys.exit()
if A[0] == -1:
    if N > 1:
        A[0] = 1
    else:
        A[0] = 0
for a in A:
    if a == -1:
        print(0, end='')
    else:
        print(a, end='')
print()


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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int n;
	cin>>n;
	vector<bool>c(8,false);
	int gm=0;
	for(int i=0,t;i<n;++i){
		cin>>t;
		if(t<3200)c.at(t/400)=true;
		else ++gm;
	}
	int color=count(c.begin(),c.end(),true);
	int mn,mx;
	if(color==0&&gm>0)mn=1;
	else mn=color;
	mx=color+gm;
	cout<<mn<<" "s<<mx<<"\n"s;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

// input scanner
var sc = bufio.NewScanner(os.Stdin)

const (
	initialBufSize = 10e4
	maxBufSize     = 10e6
)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}

func nextInt64() int64 {
	a, _ := strconv.ParseInt(next(), 10, 64)
	return a
}

func nextFloat64() float64 {
	a, _ := strconv.ParseFloat(next(), 64)
	return a
}

func nextInts(n int) []int {
	ret := make([]int, n)
	for i := 0; i < n; i++ {
		ret[i] = nextInt()
	}
	return ret
}
func nextFloats(n int) []float64 {
	ret := make([]float64, n)
	for i := 0; i < n; i++ {
		ret[i] = nextFloat64()
	}
	return ret
}
func nextStrings(n int) []string {
	ret := make([]string, n)
	for i := 0; i < n; i++ {
		ret[i] = next()
	}
	return ret
}

// util
func max(l []int) int {
	ans := l[0]
	for _, n := range l {
		if n > ans {
			ans = n
		}
	}
	return ans
}

func min(l []int) int {
	ans := l[0]
	for _, n := range l {
		if n < ans {
			ans = n
		}
	}
	return ans
}

// main
func main() {
	buf := make([]byte, initialBufSize)
	sc.Buffer(buf, maxBufSize)
	sc.Split(bufio.ScanWords)
	h := nextInt()
	w := nextInt()
	n := nextInt()
	if h > w {
		fmt.Println((n + h - 1) / h)
	} else {
		fmt.Println((n + w - 1) / w)
	}
}


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

//--------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define LL long long
#define INF INT_MAX/3

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

//--------------------------------------------

int main(){
  string s;

  cin >> s;

  REP (i, int(s.size())) {
    if (i % 2 == 0) cout << s.at(i);
  }
  cout << "\n";
}


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

using namespace std;
set<int> s1;
const int MAXN = 3e5+5;
int obs[MAXN];
int h[MAXN];
int ans;
int main(){
    int n,m;
    cin>>n>>m;
    for(int i=1;i<=n;i++){
        cin>>h[i];
    }
    for(int i=1;i<=m;i++){
        int x,y;
        cin>>x>>y;
        obs[x] = max(obs[x],h[y]);
        obs[y] = max(obs[y],h[x]);
    }
    for(int i=1;i<=n;i++){
        if(obs[i]<h[i]){
            ans++;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 4384
X, Y, Z, K = [int(x) for x in input().split()]
A = [int(a) for a in input().split()]
B = [int(b) for b in input().split()]
C = [int(c) for c in input().split()]
A = sorted(A, reverse=True)
B = sorted(B, reverse=True)
C = sorted(C, reverse=True)
ABC = []
for a in range(len(A)):
    if a+1 > K:
        break
    for b in range(len(B)):
        if b+1 > K:
            break
        elif (a+1)*(b+1) > K:
            break
        for c in range(len(C)):
            if c+1 > K:
                break
            elif (a+1)*(c+1) > K:
                break
            elif (b+1)*(c+1) > K:
                break
            elif (a+1)*(b+1)*(c+1) > K:
                break
            ABC.append(A[a] + B[b] + C[c])
ABC = sorted(ABC, reverse=True)
for i in range(K):
    print(ABC[i])

Measured memory_bytes: 9548
#include<bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T>
using vec = vector<T>;

#define FOR(i,a,b) for(int i=((int)(a));i<((int)(b));i++)
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define all(x) (x).begin(),(x).end()

int SumOfDigits(int a){
  int sum=0;
  while(a){
    sum += a%10;
    a /= 10;
  }

  return sum;
}

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

  string ans="No";
  int f=SumOfDigits(n);
  if(n%f == 0) ans = "Yes";

  cout <<ans <<endl;
}


Measured memory_bytes: 256
N = int(input())
A = []
for i in range(N):
  A.append(int(input())-1)
    
ans = -1
push = 0
count = set()
 
for i in range(N+1):
 
    if A[push] == 1:
        ans = i+1
        break
        
    elif A[push] in count:
      break
      
    else:
      count.add(push)
      push = A[push]
        
print(ans)


Measured memory_bytes: 19080