akhauriyash/Code-Regression huggingface dataset:
using System;
class Program {
    static void Main(string[] args) {
        string[] input = Console.ReadLine().Split();
        long x = long.Parse(input[0]);
        long y = long.Parse(input[1]);
        long mod = 1000000007;

        if ((x + y) % 3 != 0) {
            Console.WriteLine("0");
            return;
        }

        long a = (2 * x - y) / 3;
        long b = (2 * y - x) / 3;

        //片方でも負の数があれば、答えはゼロとなる
        if (a < 0 || b < 0) {
            Console.WriteLine("0");
            return;
        }
        //片方でも0があれば、答えは1となる
        if (a == 0 || b == 0) {
            Console.WriteLine("1");
            return;
        }
        //a >= bとなるように順番を操作する（順番は関係ないため）
        if (a < b) {
            long temp = b;
            b = a;
            a = temp;
        }

        //long ans = 1;
        //for (long i = 0; i < b; i++) {
        //    ans = (ans * (a + b - i)) % mod;
        //}

        //まずは分子のmodを計算する
        long ans = FactorialMod(a + b, mod);

        //for (long i = 2; i <= b; i++) {
        //    ans = ans * Modinv(i, mod) % mod;
        //}

        ans = ans * FactoricalModInv(a, mod) % mod * FactoricalModInv(b, mod) % mod;

        Console.WriteLine(ans);
    }

    //mod付き階乗の計算
    static long FactorialMod(long n, long m) {
        if (n == 1) {
            return 1;
        }
        return n * FactorialMod(n - 1, m) % m;
    }

    // mod. m での a の逆元 a^{-1} を計算する
    static long Modinv(long a, long M) {
        long b = M;
        long u = 1;
        long v = 0;

        while (b > 0) {
            long t = a / b;
            a -= t * b;
            long temp = a;
            a = b;
            b = temp;
            u -= t * v;
            long temp2 = u;
            u = v;
            v = temp2;
        }
        u %= M;
        if (u < 0) u += M;
        return u;
    }

    static long ModInv(long a, long M) {
        if (a == 1) {
            return 1;
        }
        return (-(ModInv(M % a, M) * (M / a))) % M;
    }

    static long FactoricalModInv(long a, long M) {
        if (a == 1) {
            return 1;
        }
        return FactoricalModInv(a - 1, M) * Modinv(a, M) % M;
    }
}

Measured memory_bytes: 31956
#include<bits/stdc++.h>
using namespace std;
int main() {
    int t;
    cin>>t;
    int ac=0, wa=0, tle=0, re=0;
    while (t--) {
        string s;
        cin>>s;
        if (s=="AC") {
            ac++;
        }
        else if (s == "WA") wa++;
        else if (s=="TLE") tle++;
        else re++;
    }
    cout<<"AC"<<" "<<"x"<<" "<<ac<<endl;
    cout<<"WA"<<" "<<"x"<<" "<<wa<<endl;
    cout<<"TLE"<<" "<<"x"<<" "<<tle<<endl;
    cout<<"RE"<<" "<<"x"<<" "<<re<<endl;

}

Measured memory_bytes: 3560
N = int(input())
A = list(map(int,input().split()))

A = [0]+A+[0]
L = 0
for i in range(1,N+2):
    L += abs(A[i] - A[i-1])

for i in range(1,N+1):
    if A[i-1] <= A[i]:
        if A[i] <= A[i+1]:
            print(L)
        else:
            print(L-abs(A[i]-A[i-1]) - abs(A[i]-A[i+1]) + abs(A[i-1]-A[i+1]))
    else:
        if A[i] >= A[i+1]:
            print(L)
        else:
            print(L-abs(A[i]-A[i-1]) - abs(A[i]-A[i+1]) + abs(A[i-1]-A[i+1]))

Measured memory_bytes: 64876
//#pragma GCC optimize ("O3")
//#pragma GCC target ("avx")
//#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread_unlocked(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	int A = 0;
	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}

int dp[10001];
int AB[10001];
int main() {
	//cin.tie(0);
	//ios::sync_with_stdio(false);


	int H = getint(), N = getint();
	rep1(i, 10000) dp[i] = 1e9;
	rep1(i, 10000) AB[i] = 2e9;

	rep(i, N) {
		int a = getint(), b = getint();
		chmin(AB[a], b);
	}

	double saikou = 1e20;
	rep1(i, 10000) {
		int k = AB[i];
		if (k < 1e9) {
			int ima = k;
			for (int j = i + i; j <= 10000; j += i) {
				ima += k;
				if (AB[j] >= ima) AB[j] = 2e9;
			}
			chmin(saikou, 1.0 * k / i);
		}
	}

	int kotae = 2e9;
	for (int i = 10000; i >= 1; i--) {
		int k = AB[i];
		if (k < 1e9) {
			double kouritu1 = 1.0 * k / i;
			double kouritu2 = 1.0 * kotae / H;
			double are = H * (kouritu2 - saikou) / (kouritu1 - saikou);
			if (are > i) {
				auto dp2 = dp + i;
				int kazu = max(0, H - i);
				for (int j = 0; j < kazu; j++) if (dp2[j] > dp[j] + k) dp2[j] = dp[j] + k;
				for (int j = kazu; j <= H; j++) if (kotae > dp[j] + k) kotae = dp[j] + k;
			}
		}
	}
	printf("%d", kotae);

	Would you please return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<vector>
using namespace std;
 
int main() {
  int a,b,c,g=INT_MAX,h=INT_MAX,j=INT_MAX,k=INT_MAX;
  cin>>a>>b>>c;
  int d[a];
  int e[b];
  int f[3][c];
  for(int i=0;i<a;i++){
    cin>>d[i];
    j=min(j,d[i]);
  }
  for(int i=0;i<b;i++){
    cin>>e[i];
    k=min(k,e[i]);
  }
  g=k+j;
  for(int i=0;i<c;i++){
      for(int o=0;o<3;o++){
      cin>>f[o][i];
      }
    h=min(h,d[f[0][i]-1]+e[f[1][i]-1]-f[2][i]);
  }
  cout<<min(g,h);
}


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

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

	int N;
	int i,j;
	int tmp;
	int answer;
	int counter=0;
	double ave;
	vector<int> given;
	string S,T;

	cin >> N;
	cin >> S >> T;

	for(i=0;i<S.size();i++){
		cout << S[i];
		cout << T[i];
	}

	cout << endl;

	return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<map>
#include<string.h>
#include<queue>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<cstdlib>
#include<math.h>
#include<set>
#include<array>
using namespace std;

template<class T>inline bool chmax(T&a, T b) { if (a < b) { a = b; return 1; }return 0; }
template<class T>inline bool chmin(T&a, T b) { if (a > b) { a = b; return 1; }return 0; }



#define rep(n) for(int i=0;i<n;i++)
typedef pair<int, int> pii;

typedef long long ll;
typedef pair<ll, ll>pll;
const int MOD = 1000000007;
const int INF = 1 << 29;

long long gcd(long long x, long long y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}

int main() {
	
	
	long long a, b,cnt=0;
	cin >> a >> b;
	
	long long g = gcd(a, b);
	
	for (long long i = 2; i*i <= max(a, b); i++) {

		if (g%i == 0) {
			g /= i;
			cnt++;
			while (g%i == 0)g /= i;
		}
	}
	if (g > 1)cnt++;
	
		cout << cnt + 1 << endl;
	
	

	return 0;
}


Measured memory_bytes: 384
# -*- coding: utf-8 -*-
# abc126/abc126_c
import sys
from math import *

s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in list(ss)]
ss2nnn = lambda ss: [s2nn(s) for s in list(ss)]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [i2s() for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))



def main():
    N, K = i2nn()
    if N >= K:
        s = N - K + 1
        n = K
    else:
        s = 0
        n = N + 1
    for d in range(1, n):
        s += 2**(-ceil(log2(K/d)))
    print(s/N)

main()


Measured memory_bytes: 3064
// header {{{
// #define NDEBUG
#include <bits/stdc++.h>
using namespace std;

// {U}{INT,LONG,LLONG}_{MAX,MIN}
#define ALPHABET    (26)
#define INF         INT_MAX
#define MOD         (1000000007LL)
#define EPS         (1e-10)
#define EQ(a, b)        (abs((a)-(b)) < EPS)
#define CILING(a, b)    (((a)+(b)-1)/(b))

template<class T>
using PIT = pair<int, T>;
template<class T>
using PTI = pair<T, int>;
using PII = pair<int, int>;
using PDI = pair<double, int>;
using LL  = long long;
using ULL = unsigned long long;
// }}}

int main() {
    int a, b, h;cin >> a >> b >> h;
    cout << (a+b)*h/2 << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = n-1; i >= 0; i--)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
using P = pair<int,int>;
using VI = vector<int>;
using VVI = vector<vector<int>>;
using VL = vector<ll>;
using VVL = vector<vector<ll>>;
using VP = vector<P>;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

int main(){
    int n, m, k;
    cin >> n >> m >> k;
    for(int l = 0; l <= n; l++){
        for(int r = 0; r <= m; r++){
            int sum = l * (m - r) + r * (n - l);
            if (sum == k){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
    return 0;
}

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

int main() {
	string S, a;
	cin >> S;
	if ("keyence" == S) cout << "YES";
	else {
		int i, j;
		for (i = 0; i < S.size(); ++i) {
			for (j = 1; j <= S.size() - i; ++j) {
				a = S;
				a.erase(i, j);
				if ("keyence" == a) break;
			}
			if (S.size() - i >= j) break;
		}
		if (S.size() == i) cout << "NO";
		else cout << "YES";
	}
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
using namespace std;
int ans,A;
void Init(){
    char ch=getchar();
    if(ch=='\n')return;
    if(ch=='I')++A,ans=max(A,ans);
    if(ch=='D')--A,ans=max(A,ans);
	Init();
}
int main(){
    int n;
    scanf("%d\n",&n);
    Init();
    printf("%d\n",ans);
    return 0;
}

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


int main(){
  ll a;
  long double b;
  cin >> a >> b;
  ll nb = b*100+0.5;
  ll ans = a*nb;
  ans = (ans-ans%100)/100;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3696
import sys
input = sys.stdin.readline


def read():
    N = int(input().strip())
    S = input().strip()
    return N, S


def solve(N, S):
    Z = 26
    cl = [[0 for j in range(Z)] for i in range(N)]  # [0, l)
    cr = [[0 for j in range(Z)] for i in range(N)]  # [l, N)
    for i in range(N):
        if i > 0:
            for j in range(Z):
                cl[i][j] = cl[i-1][j]
        s = ord(S[i]) - ord('a')
        cl[i][s] += 1
    for i in range(N-1, -1, -1):
        if i < N-1:
            for j in range(Z):
                cr[i][j] = cr[i+1][j]
        s = ord(S[i]) - ord('a')
        cr[i][s] += 1

    max_chars = 0
    for i in range(1, N):
        chars = 0
        for j in range(Z):
            if cl[i-1][j] > 0 and cr[i][j] > 0:
                chars += 1
        max_chars = max(max_chars, chars)
    return max_chars


if __name__ == '__main__':
    inputs = read()
    outputs = solve(*inputs)
    if outputs is not None:
        print("%s" % str(outputs))


Measured memory_bytes: 3188
#include<iostream>
#include <string>

using namespace std;

int main(){
    string s, t;
    int len=0;

    cin >> s >> t;
    len = s.size();
    t = t.erase(len);

    if(s == t){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    return 0;
}

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

int n;
//vector<pair<int, int>> robots(100010);
int res = 0;

int main(){
  cin >> n;
  vector<pair<int, int>> robots(n);
  rep(i, n){
    int x, l;
    cin >> x >> l;
    robots.at(i).second = x - l; //始点
    robots.at(i).first = x + l; //終点
    //cout <<robots.at(i).second <<" "<< robots.at(i).first<<" "<<endl;
  }
  sort(robots.begin(), robots.end());
  //rep(i, n) cout <<robots.at(i).second <<" "<< robots.at(i).first<<" "<<endl;
  
  int right = -1500000000; //もっとも右の点 
  rep(i, n){
    if(right <= robots.at(i).second){
      res++;
      right = robots.at(i).first;
      //cout << robots.at(i).first <<" ";
    }
  }
  
  cout << res << endl;
  return 0;
}

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

map<ll, ll> _map;
map<ll, ll> _nap;
set<ll> _set;

int main() {
	int n, x;
	cin>>n;
	for(int i = 1; i <= n; i++) {
		cin>>x;
		_map[x + i] += 1;
		_nap[i - x] += 1;
		_set.insert(i + x);
	}
	ll ans = 0;
	set<ll>::iterator it = _set.begin();
	for(;it!=_set.end();++it) {
//		cout<<(*it)<<endl;
		ans += (_map[*it]*_nap[*it]);
	}
	cout<<ans<<endl;
	
}

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

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

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


int main()
{
	cin.tie(0); ios_base::sync_with_stdio(false);
	int n;
	cin >>n;
	VI a(n);
	rep(i,n) cin >>a[i];
	auto b = a;
	sort(all(b));
	int f1 = b[n/2-1], f2 =b[n/2];
	rep(i, n) cout << (a[i] <=f1? f2: f1) <<"\n";
	
	return 0;
}


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

using namespace std;

typedef long long ll;
typedef long double ld;

const int N = 1e5 + 7;

int p[N], sz[N];

int get(int a) {
    return (a == p[a] ? a : p[a] = get(p[a]));
}

int cmp;

void join(int a, int b) {
    a = get(a);
    b = get(b);
    if (a != b) {
        --cmp;
        p[a] = b;
        sz[b] += sz[a];
    }
}

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0); cout.setf(ios::fixed); cout.precision(20);
    #ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    int n, q; ll m;
    cin >> n >> m >> q;
    for (int i = 0; i < n; ++i) {
        p[i] = i;
        sz[i] = 1;
    }
    cmp = n;
    vector <int> a(q), b(q), c(q);
    bool fl = false;
    for (int i = 0; i < q; ++i) {
        cin >> a[i] >> b[i] >> c[i];
        if (c[i] == 0) {
            join(a[i], b[i]);
        } else {
            fl = true;
        }
    }
    for (int i = 0; i < q; ++i) {
        if (c[i] == 1 && get(a[i]) == get(b[i])) {
            cout << "No\n";
            return 0;
        }
    }
    ll mn, mx;
    if (!fl) {
        mn = n - 1;
    } else {
        mn = n;
    }
    mx = 0;
    vector <int> cm;
    for (int i = 0; i < n; ++i) cm.push_back(get(i));
    sort(cm.begin(), cm.end());
    cm.resize(unique(cm.begin(), cm.end()) - cm.begin());
    for (auto x : cm) {
        mx += 2 * (sz[x] - 1);
        mx += cmp - 1;
    }
    mx /= 2;
    if (mn <= m && m <= mx) {
        cout << "Yes\n";
    } else {
        cout << "No\n";
    }
}

Measured memory_bytes: 2812
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cwchar>
#include <cwctype>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <codecvt>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep2(i, n) for(int i = 1; i <= (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize("Ofast")
using namespace std;
typedef int64_t ll;
typedef long double ld;
const ll INF=(1LL<<60);
const ld pi=acosl(1);
const ll mod = 1000000007;
const int dx[4]={0,1,0,-1};
const int dy[4]={1,0,-1,0};
const int ddx[8]={1,0,-1,-1,-1,0,1,1};
const int ddy[8]={1,1,1,0,-1,-1,-1,0};

using P=pair<ll,ll>;

bool check(P p,ll sx,ll gx,ll sy,ll gy){
  ll x=p.first;
  ll y=p.second;
  return sx<=x and x<=gx and sy<=y and y<=gy;
}

ll mycount(vector<P>&v,ll sx,ll gx,ll sy,ll gy){
  ll n=v.size();
  ll ret=0;
  rep(i,n){
    if(check(v[i],sx,gx,sy,gy))ret++;
  }
  return ret;
}

void solve(){
  ll n,k;cin>>n>>k;
  vector<P>v(n);
  ll ans=__LONG_LONG_MAX__;
  rep(i,n)cin>>v[i].first>>v[i].second;
  rep(a,n)rep(b,n)rep(c,n)rep(d,n){
    ll sx=v[a].first;
    ll gx=v[b].first;
    ll sy=v[c].second;
    ll gy=v[d].second;
    if(mycount(v,sx,gx,sy,gy)>=k){
      ans=min(ans,abs(sx-gx)*abs(sy-gy));
    }
  }
  cout<<ans<<endl;
}

signed main(){
	ios::sync_with_stdio(false);
  cin.tie(nullptr);cout<<fixed;
  cout<<setprecision(30);
	solve();
}


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

using namespace std;

typedef long long LL;
const int N = 60;

bool mat[N][N];
int n, m, s;
LL mod;

LL pow_mod(LL x, int p){
    LL s = 1;
    while(p){
		if(p & 1) 	s = s * x % mod;
		x = x * x % mod;
		p >>= 1;
    }
    return s;
}

int query(int a, int b, int c, int d){
    printf("? %d %d %d %d\n", a, b, c, d);
    fflush(stdout);
    int ret;
    scanf("%d", &ret);
    return ret;
}

void solve(int x1, int x2, int y1, int y2, int sum){
    int area = (x2 - x1 + 1) * (y2 - y1 + 1);
    if(sum == 0 || x1 > x2 || y1 > y2)	return;
    if(area == sum){
		for(int i=x1; i<=x2; i++){
			for(int j=y1; j<=y2; j++){
				mat[i][j] = 1;
			}
		}
		return;
    }

    if(x1 == x2){
		int mid = y1 + y2 >> 1;
		int g = query(x1, y1, x2, mid);
		solve(x1, x2, y1, mid, g);
		solve(x1, x2, mid+1, y2, sum - g);
	} else if(y1 == y2){
		int mid = x1 + x2 >> 1;
		int g = query(x1, y1, mid, y2);
        solve(x1, mid, y1, y2, g);
        solve(mid+1, x2, y1, y2, sum - g);
    } else {
        int mid1 = x1 + x2 >> 1;
        int g1 = query(x1, y1, mid1, y2);
        int d1 = abs(sum-g1-g1);

        int mid2 = y1 + y2 >> 1;
        int g2 = query(x1, y1, x2, mid2);
        int d2 = abs(sum-g2-g2);

        if(d1 >= d2){
            solve(x1, mid1, y1, y2, g1);
            solve(mid1+1, x2, y1, y2, sum - g1);
        } else {
			solve(x1, x2, y1, mid2, g2);
			solve(x1, x2, mid2+1, y2, sum - g2);
        }
    }
}

int main(){
    while(~scanf("%d %d %d %lld", &n, &m, &s, &mod)){
        memset(mat, 0, sizeof(mat));
        solve(0, n-1, 0, m-1, s);
        LL ans = 0;
        for(int i=0; i<n; i++){
			for(int j=0; j<m; j++){
				if(mat[i][j]){
					ans = ans + pow_mod(2, i * m + j) % mod;
					ans %= mod;
				}
			}
        }
        printf("! %lld\n", ans);
        fflush(stdout);
    }
	return 0;
}


Measured memory_bytes: 720
#include<stdio.h>
int zettaichi(int num1,int num2)
{
  int r;
  if(num1>num2)
  {
    r = num1 - num2;
  }else
  {
    r = num2 - num1;
  }
  return r;
}
    
int main(void)
{
  int house,shop1,shop2,A,B;
  char str[32];
  
  fgets(str,sizeof(str),stdin);
  sscanf(str,"%d%d%d",&house,&shop1,&shop2);
  
  A = zettaichi(house,shop1);
  B = zettaichi(house,shop2);
  
  if(A < B)
  {
    puts("A");
  }else
  {
    puts("B");
  }
  return 0;
}

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

int N, Y;

int main(){
    cin >> N >> Y;
    
    int ansa=-1;
    int ansb=-1;
    int ansc=-1;


    for(int i=0;i<=N;i++){ //10000の数
        for(int j=0; j<=(N-i);j++){ //5000円の数
            if(Y== (10000*i+5000*j+1000*(N-i-j)) ){
                ansa=i;
                ansb=j;
                ansc=N-i-j;
            }
        } 
    }

    cout << ansa << " " << ansb << " " << ansc << endl;
}

Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

func Scan() string {
	sc.Scan()
	return sc.Text()
}
func iScan() int {
	n, _ := strconv.Atoi(Scan())
	return n
}
func fScan() float64 {
	n, _ := strconv.ParseFloat(Scan(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func SScan(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scan()
	}
	return a
}
func iSScan(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = iScan()
	}
	return a
}
func abs(x int) int {
	if x < 0 {
		x = -x
	}
	return x
}
func larger(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}
func smaller(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}
func max(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x < a[i] {
			x = a[i]
		}
	}
	return x
}
func min(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x > a[i] {
			x = a[i]
		}
	}
	return x
}
func sum(a []int) int {
	x := 0
	for _, v := range a {
		x += v
	}
	return x
}
func fSum(a []float64) float64 {
	x := 0.
	for _, v := range a {
		x += v
	}
	return x
}

var mod int = 1000000007

func main() {
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	n := iScan()
	a := iSScan(n)
	c := make([]int, n)
	ans := make([]int, 0, n)
	for i := n - 1; i >= 0; i-- {
		x := 0
		for j := (i+1)*2 - 1; j < n; j += i + 1 {
			x += c[j]
		}
		c[i] = abs(a[i] - x%2)
		if c[i] == 1 {
			ans = append(ans, i+1)
		}
	}
	fmt.Println(len(ans))
	if len(ans) != 0 {
		fmt.Println(strings.Trim(fmt.Sprint(ans), "[]"))
	}
}


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

int main(void){
    string S,T;
    cin>>S>>T;
    vector<int> s(26,-1);
    vector<int> g(26,-1);
    
    for(int i=0;i<S.size();i++){
        
        int a=S[i]-'a';
        int b=T[i]-'a';
        
        if(s[a]!=-1||g[b]!=-1){
            if(s[a]!=b||g[b]!=a){
                cout<<"No"<<endl;
                return 0;
            }
        }
        else{
            s[a]=b;
            g[b]=a;
        }
    }
    
    cout<<"Yes"<<endl;
}

Measured memory_bytes: 776
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}
template <class C>
void print(const C &c, std::ostream &os = std::cout) {
    std::copy(std::begin(c), std::end(c), std::ostream_iterator<typename C::value_type>(os, " "));
    os << std::endl;
}

int main() {
    int n;
    cin >> n;
    vi a(n), b(n), c(n - 1);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        a[i]--;
    }
    for (int i = 0; i < n; ++i) {
        cin >> b[i];
    }
    for (int i = 0; i < n - 1; ++i) {
        cin >> c[i];
    }
    int ret = 0;
    ret += b[a[0]];
    for (int i = 1; i < n; ++i) {
        ret += b[a[i]];
        if (a[i] == a[i - 1] + 1)
            ret += c[a[i - 1]];
    }
    cout << ret << "\n";
    return 0;
}

Measured memory_bytes: 256
x,y,a,b,c=map(int,input().split())
p=list(map(int,input().split()))
q=list(map(int,input().split()))
r=list(map(int,input().split()))
p=sorted(p)
q=sorted(q)
r=sorted(r)
p=p[-x:]
q=q[-y:]
ans=p+q+r
ans=sorted(ans)
ans=ans[-(x+y):]
print(sum(ans))

Measured memory_bytes: 115564
using namespace std;

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
#include <iostream>
#include <string>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cmath>
#include <climits>
#include <bitset>
#include <array>
#include <deque>
#include <queue>
#define all(x) (x).begin(),(x).end()

void solve(){

}
int main(){
    int r;
    cin >> r;
    if (r < 1200){
        cout << "ABC" << endl;
    } else if (r < 2800){
        cout << "ARC" << endl;
    } else {
        cout << "AGC" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long A,B,Q,s[1<<17],t[1<<17],i,j,k,x,c,d,ans,INF=1e18;
main(){
  cin>>A>>B>>Q;
  for(i=1;i<=A;i++)cin>>s[i];
  s[0]=-INF;s[A+1]=INF;
  for(i=1;i<=B;i++)cin>>t[i];
  t[0]=-INF;t[B+1]=INF;
  for(i=0;i<Q;i++){
    cin>>x;
    c=lower_bound(s,s+A+2,x)-s;
    d=lower_bound(t,t+B+2,x)-t;
    ans=INF;
    for(j=c-1;j<c+1;j++){
      for(k=d-1;k<d+1;k++){
        ans=min(ans,abs(x-s[j])+abs(s[j]-t[k]));
        ans=min(ans,abs(x-t[k])+abs(t[k]-s[j]));
      }
    }
    cout<<ans<<endl;
  }
}


Measured memory_bytes: 2944
# Combination
MOD = 10**9+7
MAX = 10**6+3
fac = [1,1] + [0]*MAX
finv = [1,1] + [0]*MAX
inv = [0,1] + [0]*MAX
for i in range(2,MAX+2):
    fac[i] = fac[i-1] * i % MOD
    inv[i] = -inv[MOD%i] * (MOD // i) % MOD
    finv[i] = finv[i-1] * inv[i] % MOD

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

X, Y = map(int, input().split())
p1, p2 = -1, -1
for i in range(10**6+1):
    x, y = X-i, Y-2*i
    if x < 0 or y < 0: continue
    if x%2 == 0:
        q = x//2
        if y == q:
            p1, p2 = i, q
if p1 == -1:
    print(0)
else:
    print(comb(p1+p2, p1))

Measured memory_bytes: 115852
#n idカード　m ゲート
n,m = map(int, input().split())
maxlist = []
minlist = []

for i in range(m):
	#l　ゲートの下限　r ゲートの上限
	l , r = list(map(int, input().split()))
	minlist.append(l)
	if r > 0:
		maxlist.append(r)

minid = max(minlist)
maxid = min(maxlist)
okgate = maxid - minid + 1

if okgate >= 0:
	print(okgate)
else:
	print(0)

Measured memory_bytes: 11020
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	int k,a,b;
	cin>>k>>a>>b;
	int flag=0;
	for(int i=a;i<=b;i++)
	{
		if(i%k==0)
		{
			cout<<"OK";
			flag=1;
			return 0;
		}
	}
	if(flag==1) cout<<"OK";
	else cout<<"NG";
	return 0;
 } 

Measured memory_bytes: 3652
// Created by sz
#include <bits/stdc++.h>
using namespace std;

const int maxn = 3005, mod = 1e9+7;
int N, dp[maxn][maxn], sum[maxn][maxn];
string s;

int main(){
#ifdef LOCAL
    freopen("./input.txt", "r", stdin);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin>>N>>s;
    
    dp[1][1] =1;
    sum[1][1] = 1;
    for(int i = 2; i <= N; i++){
        for(int j = 1; j<= i; j++){
            if(s[i-2] == '<')(dp[i][j] = sum[i-1][j-1])%=mod;
            else (dp[i][j] = sum[i-1][i-1] - sum[i-1][j-1]+mod)%=mod;
        }
        for(int j = 1;j<=i; j++)(sum[i][j] = sum[i][j-1] + dp[i][j])%=mod;
    }
    cout<<sum[N][N]<<endl;
    
    return 0;
}



Measured memory_bytes: 69504
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; i++)
#define vv(T) vector<vector<T>>
using namespace std;
using ll = long long;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using vll = vector<long long>;
using vvll = vector<vector<long long>>;
using vbool = vector<bool>;
using vvbool = vector<vector<bool>>;
using qint = queue<int>;
using sint = stack<int>;
using pii = pair<int, int>;

const string YES = "Yes";
const string NO = "No";

int main(){
    int x, y;
    string ans = NO;
    cin >> x >> y;
    for(int crane = 0; crane <= x; crane++){
        int turtle = x - crane;
        int legs = turtle * 4 + crane  * 2;
        if(legs == y){
            ans = YES;
            break;
        }
    }

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3600
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		String l1 = scan.nextLine();
		String l2 = scan.nextLine();
		scan.close();

		long n = Long.valueOf(l1.split(" ")[0]);
		long k = Long.valueOf(l1.split(" ")[1]);
		String strH = l2;
		List<Long> h = new ArrayList<Long>();
		for (String element : strH.split(" ")) {
			h.add(Long.valueOf(element));
		}

		Collections.sort(h, Collections.reverseOrder());

		Map<Integer, Long> hMap = new HashMap<>();
		int li = 0;
		for (Long element : h) {
			hMap.put(li, element);
			li++;
		}

		for (int i = 0; i < k; i++) {
			hMap.put(i, Long.valueOf(0));
		}

		long result = 0;
		for (Long element : hMap.values()) {
			result += element;
		}

		System.out.println(result);
	}
}


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

int main() {

  int A,B,C;
  cin >> A >> B >>C;
  
  if(A==B){
  cout << C << endl;
  }else if(A==C){
    cout << B << endl;
  }else{
    cout << A << endl;
  }
}

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

using namespace std;

#define B       (cout << "Sehen Sie mich!" << endl)
#define VB(val) (cout << val << endl)

int main()
{
        int a, b;
        cin >> a >> b;
        VB((int)((a+b+1)/2));
}

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

ll t[100001][101];

ll knapsackdpTab(ll val[], ll wt[], ll w, ll n) // Tabulation
{
    for (int i = 0; i < w + 1; i++)
    {
        for (int j = 0; j < n + 1; j++)
        {
            if (i == 0 || j == 0)
                t[i][j] = 0;
        }
    }

    for (int i = 1; i < w + 1; i++)
    {
        for (int j = 1; j < n + 1; j++)
        {
            if (wt[j - 1] <= i)
                t[i][j] = max(val[j - 1] + t[i - wt[j - 1]][j - 1], t[i][j - 1]);
            else
                t[i][j] = t[i][j - 1];
        }
    }

    return t[w][n];
}

int main()
{
    memset(t, -1, sizeof(t));
    ll n, w;
    cin >> n >> w;
    ll wt[n];
    ll val[n];
    for(int i=0; i<n; i++)
        cin >> wt[i] >> val[i];


    cout << knapsackdpTab(val, wt, w, n);
}


Measured memory_bytes: 82540
using System;

namespace AtCoder {

    class Program {
        static void Main(string[] args) {

            var temp = Console.ReadLine().Split(' ');

            var A = int.Parse(temp[0]);
            var B = int.Parse(temp[1]);
            var K = int.Parse(temp[2]);

            for(int i = 0; i < K; i++) {

                if(i % 2 == 0) {

                    if (A % 2 == 1) {

                        A -= 1;
                    }
                    var t = A / 2;
                    A -= t;
                    B += t;
                } else {

                    if (B % 2 == 1) {

                        B -= 1;
                    }
                    var t = B / 2;
                    B -= t;
                    A += t;
                }
            }
            Console.WriteLine(A + " " + B);
        }
    }
}


Measured memory_bytes: 13140
#include<iostream>
#include <stdlib.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <vector>
#include <numeric>
typedef long long int ll;
using namespace std;
int main(){
	int a;
	vector<int> k={0,0};
	for(int i=0;i<3;i++){
		cin >> a;
		if(a==5){
			k[0]++;
		}else if(a==7){
			k[1]++;
		}
	}
	if((k[0]==2)&&(k[1]==1)){
		cout<<"YES"<<endl;
	}else{
		cout<<"NO"<<endl;
	}
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int k = in.nextInt();
        String s = in.next();

        if (s.length() <= k) {
            System.out.println(s);
        } else {
            System.out.println(s.subSequence(0, k) + "...");
        }
    }
}

Measured memory_bytes: 38620
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define REPL(i,m,n) for(ll i=(ll)(m); i<(ll)(n); i++)
#define repl(i,n) REP(i,0,n)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;


int main(){

  int N;
  cin >> N;
  int ans;

  if ( (N % 2) == 0 ) { // even
    ans = (N / 2) - 1;
  }
  else { // odd
    ans = (N - 1) / 2;
  }

  cout << ans << endl;

  return 0;
}


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

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<bool> vb;

template <typename T, typename U> std::istream&operator>>(std::istream&i, pair<T,U>&p) {i >> p.x >> p.y; return i;}
template<typename T>std::istream&operator>>(std::istream&i,vector<T>&t) {for(auto&v:t){i>>v;}return i;}
template <typename T, typename U> std::ostream&operator<<(std::ostream&o, const pair<T,U>&p) {o << p.x << ' ' << p.y; return o;}
template<typename T>std::ostream&operator<<(std::ostream&o,const vector<T>&t) {if(t.empty())o<<'\n';for(size_t i=0;i<t.size();++i){o<<t[i]<<" \n"[i == t.size()-1];}return o;}

#define deb(x) cout << '>' << #x << ':' << x << endl;
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define END '\n'
#define inf 9e18
#define ff first
#define ss second
#define pb push_back

void solve(){
    int n;
    cin >> n;
    vi T(n);
    cin >> T;
    int sum = accumulate(all(T), 0);
    int m;
    cin >> m;
    while(m--){
        int a, b;
        cin >> a >> b;
        cout << sum - T[a - 1] + b << END;
    }
}
int main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    int t = 1;
    // cin >> t;
    while(t--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 3584
from sys import stdin, stdout

n, m = map(int, raw_input().strip().split())
inp = stdin.readlines()
out = []

ed = []
for line in inp:
    a, b = map(int, line.strip().split())
    ed.append((a, b))

MAX = n + 1
root = [i for i in xrange(MAX)]
rank = [0 for i in xrange(MAX)]
sz = [1 for i in xrange(MAX)]

s = n * n
sq = n
 
def find(x):
    global root
    if root[x] != x: root[x] = find(root[x])
    return root[x]
 
def union(x, y):
    global root, rank, sq
    x_root = find(x)
    y_root = find(y)

    if x_root == y_root: return

    a, b = sz[x_root], sz[y_root]
 
    if rank[x_root] > rank[y_root]:
        root[y_root] = x_root
        sz[x_root] += sz[y_root]
        sz[y_root] = 0
    else:
        root[x_root] = y_root
        if rank[x_root] == rank[y_root]: rank[y_root] += 1
        sz[y_root] += sz[x_root]
        sz[x_root] = 0

    sq = sq - a * a - b * b
    sq = sq + (a + b) * (a + b)

for i in xrange(m - 1, -1, -1):
    ans = (s - sq) // 2
    ans = max(0, ans)
    u, v = ed[i]
    union(u, v)
    out.append(str(ans))

stdout.write("\n".join(out[::-1]))

Measured memory_bytes: 71828
#ABC071B
import sys

s=raw_input()
l=[False for i in xrange(26)]
for i in xrange(len(s)):
 temp=ord(s[i])-97
 l[temp]=True
if len(set(s))==26:
 print 'None'
 sys.exit()
for i in xrange(26):
 if not l[i]:
  print chr(i+97)
  break


Measured memory_bytes: 2692
#include<stdio.h>
int main(){
  int a=0,S=0,R=0;
  char k[3]={};
  scanf("%s",k);
  if(k[0]=='R'&&k[1]=='R'&&k[2]=='R'){
    a=3;
  }
  else if(k[0]=='R'&&k[1]=='R'){
    a=2;
  }
  else if(k[1]=='R'&&k[2]=='R'){
    a=2;
  }
  else if(k[0]=='S'&&k[1]=='S'&&k[2]=='S'){
    a=0;
  }
  else{
    a=1;
  }
  printf("%d",a);
  return 0;
}


Measured memory_bytes: 2080
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main(void) {

	char A[3], B[3];
	scanf("%s\n%s", &A, &B);
	if (A[0] == B[2] && A[1] == B[1] && A[2] == B[0])
		printf("YES\n");
	else printf("NO\n");

	return 0;
}

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

#define REP(i, e) for(int (i) = 0; (i) < (e); ++(i))
#define FOR(i, b, e) for(int (i) = (b); (i) < (e); ++(i))
#define ALL(c) (c).begin(), (c).end()
#define ACC(c) (accumulate(ALL(c), 0LL))
#define PRINT(x) cout << (x) << "\n"

using namespace std;
using ll = long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;

inline int in(int& a) {return scanf("%d", &a);}
auto pint_compare = [](pint x, pint y) -> bool{return (x.first < y.first);};


int N;
string S[100000];

signed main(){
    cin >> N;
    string str;
    char ch[10];
    REP(i, N){
        cin >> str;
        REP(j, 10) ch[j] = str[j];
        sort(ch, ch + 10);
        REP(j, 10) str[j] = ch[j];
        S[i] = str;
    }
    sort(S, S + N);
    REP(i, N) cerr << S[i] << endl;
    ll cnt = 1, ans = 0;
    REP(i, N){
        if(i < N - 1 && S[i] == S[i + 1]) cnt++;
        else{
            ans += cnt * (cnt - 1) / 2;
            cnt = 1;
        }
    }
    PRINT(ans);
    return 0;
}

Measured memory_bytes: 5760
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
using namespace __gnu_pbds;
using namespace std;
 
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
 
typedef long long ll;
typedef long double ld;
typedef pair<long long ,long long> ii; 	
 

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll a,b,c,d;
	cin >> a >> b >> c >> d;
	if (a != c) cout << 1 << endl;
	else cout << 0 << endl;
}

Measured memory_bytes: 256
n = STDIN.gets.to_i
matrix = Array.new(n) { Array.new(n) }
n.times do
	vertex, degree, *adjacent_info = STDIN.gets.split.map(&:to_i)
	degree.times do
		adjacency, weight = adjacent_info.shift(2)
		matrix[vertex][adjacency] = weight
	end
end

# ダイクストラ法
MAX_WEIGHT = 100_001
distances = Array.new(n)
visited   = Array.new(n, false)
parent    = Array.new(n)

distances[0] = 0
loop do
	vertex = matrix.each_index.
		select { |i| !visited[i] }.
		min_by { |i| distances[i] || MAX_WEIGHT }

	break if vertex.nil?
	visited[vertex] = true

	matrix.each_index do |i|
		next if visited[i] || matrix[vertex][i].nil?

		tmp_distance = distances[vertex] + matrix[vertex][i]
		if distances[i].nil? || tmp_distance < distances[i]
			distances[i] = tmp_distance
			parent[i] = vertex
		end
	end
end

matrix.each_index { |i| puts "#{i} #{distances[i]}" }

Measured memory_bytes: 6212
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <type_traits>
#include <map>

using namespace std;



int main(int argc, const char * argv[]) {
  long long n, y;
  cin >> n >> y;
  for(int i = 0; i <= n; i++){
    for(int j = 0; j <= n - i; j++){
      if(i*10000 + j*5000 + (n-j-i)*1000 == y){
        cout << i << " " << j << " " << n-j-i << endl;
        return 0;
      }
    }
  }
  cout << "-1 -1 -1" << endl;
  return 0;
  
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<queue>
#include<vector>
#include<string.h>
#include<algorithm>
#include <cmath>


using namespace std;

long long N,M;
int i,j,k,n,m;
vector<int> A,B,par;
vector<long long> V,num;

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

int unite(int x,int y)
{
  x=root(x);
  y=root(y);
  if(x==y)
  {
    return 0 ;
  }
  
  par[x]=y;
  num[y]+=num[x];
  
  return 0;
}

int main()
{
  cin >> N >> M;
  
  A.assign(M,0);
  B.assign(M,0);
  par.assign(N,0);
  num.assign(N,1);
  V.assign(M,0);
   
  V[M-1]=N*(N-1)/2;
  for(i=0;i<M;i++)
  {
    cin >> j >> k;
    j--;
    k--;
    A[i]=j;
    B[i]=k;
  }
  
  for(i=0;i<N;i++)
  {
    par[i]=i;
  }
    
  for(i=M-1;i>0;i--)
  {  
    n=root(A[i]);
    m=root(B[i]);
    if(n==m)
    {
      V[i-1]=V[i];
    }
    else
    {
      V[i-1]=V[i]-num[n]*num[m];
      
      unite(n,m);
    }
  }
  
  for(i=0;i<M;i++)
  {
    cout << V[i] <<endl;
  }
  
}

Measured memory_bytes: 4096
// #ifdef DEBUG
// #define _GLIBCXX_DEBUG
// #endif
#include <iostream>
#include <iomanip>
#include <vector>
#include <valarray>
#include <map>
#include <set>
#include <list>
#include <queue>
#include <stack>
#include <bitset>
#include <utility>
#include <numeric>
#include <algorithm>
#include <functional>
#include <complex>
#include <string>
#include <sstream>

#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cstring>

// these require C++11
#include <unordered_set>
#include <unordered_map>
#include <random>
#include <thread>
#include <chrono>

using namespace std;

#define int long long

#define all(c) c.begin(), c.end()
#define repeat(i, n) for (int i = 0; i < static_cast<int>(n); i++)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define dump(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define dump(x) 
#endif

template<typename A,typename B>
ostream &operator<<(ostream&os,const pair<A,B>& p){
    os << "(" << p.first << "," << p.second << ")";
    return os;
}

typedef complex<double> point;

template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
    os << "[";
    for (const auto &v : vec) {
        os << v << ",";
    }
    os << "]";
    return os;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n,q;
    cin >> n >> q;
    vector<int> year(n+1);
    vector<string> name(n+1);
    year[0] = 0;
    name[0] = "kogakubu10gokan";
    for(int i=1;i<=n;i++){
        cin >> year[i] >> name[i];
    }
    
    for(int i=1;i<=n;i++){
        if(year[i] > q){
            cout << name[i-1] << endl;
            return 0;
        }
    }
    cout << name.back() << endl;
    return 0;
}

Measured memory_bytes: 1208
import numpy as np

i = 0
j = 0

nums = []
first_digits = []
min_first_digit = 9
index = 0
sum = 0

while i < 5:
  x = int(input())
  nums.append(x)
  
  if x % 10 <= min_first_digit and x % 10 != 0:
    min_first_digit = x % 10
    index = i
  i += 1
  
while j < 5:
  if j == index:
    sum += nums[j]
  else:
    if nums[j] % 10 == 0:
      sum += nums[j]
    else:
      sum += (nums[j] + 10 - (nums[j] % 10))
  j += 1
    
print(sum)

  


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

typedef long long ll;
typedef pair<int,int> pii;
int main(){
  int A,B,C,D;
  int x,y;
  cin >> A >> B >> C >> D;
  x = max(A,C);
  y = min(B,D);
  
  if(x < y) cout << y - x << endl;
  else cout << 0 << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
int ans[202020];
bool u[202020];
void work(int x,int v)
{
	ans[x]=v;
	u[v]=true;
}
int main()
{
	int n,x,now=1;
	scanf("%d%d",&n,&x);
	memset(u,0,sizeof(u));
	if(x==1||x==2*n-1)
	{
		printf("No");
		return 0;
	}
	if(n==2)
	{
		printf("Yes\n1\n2\n3");
		return 0;
	}
	work(n,x);
	work(n+1,x+1);
	work(n-1,x-1);
	if(x==2*n-2)
		work(n+2,x-2);
	else
		work(n-2,x+2);
	for(int i=1;i<=2*n-1;i++)
	{
		if(ans[i])
			continue;
		while(u[now])
			now++;
		work(i,now);
	}
	printf("Yes\n");
	for(int i=1;i<=2*n-1;i++)
		printf("%d\n",ans[i]);
	return 0;
}

Measured memory_bytes: 2432
from fractions import gcd


def main():
    n = int(input())
    A = list(map(int, input().split()))

    L = []
    R = []
    for i in range(n):
        if i == 0:
            L.append(A[0])
            R.append(A[-1])
            continue
        L.append(gcd(L[i-1],A[i]))
        R.append(gcd(R[i-1],A[-i-1]))
    R.reverse()

    for i in range(n):
        if i == 0:
            gcd_max = R[1]
        elif i != n-1:
            gcd_max = max(gcd_max, gcd(L[i-1], R[i+1]))
        else:
            gcd_max = max(gcd_max, L[-2])
    print(gcd_max)


if __name__ == '__main__':
    main()


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

// Shrotening
#define fst first
#define snd second
#define pb push_back

// Loop
#define FOR(i,a,b) for(long i=(a);i<(b);++i)
#define RFOR(i,a,b) for(long i=(a);i>=(b);--i)

#define REP(i,a) FOR(i,0,a)
#define RREP(i,a) RFOR(i,a,0)

#define EACH(i,a) for(auto (i)=(a).begin(),_END=(a).end();i!=_END;++i)
#define REACH(i,a) for(auto (i)=(a).rbegin(),_END=(a).rend();i!=_END;++i)

//Algorithm
#define ALL(a) (a).begin(), a.end()
#define RALL(a) (a).rbegin(), a.rend()
#define EXIST(a,x) ((a).find(x)!=(a).end())
#define SORT(a) sort(ALL(a))
#define UNIQUE(a) SORT(a), a.erase(std::unique(ALL(a)), a.end());

//Setting
#define OPT std::cin.tie(0);std::ios::sync_with_stdio(false);

//debug message
bool debug = true;
#define MSG(s)   if(debug){std::cout << s << std::endl;}
#define DEBUG(x) if(debug){std::cout << "debug(" << #x << "): " << x << std::endl;}

//alias
typedef long long LL;
typedef std::vector<char> VC;
typedef std::vector< VC > VCC;
typedef std::vector<int>  VI;
typedef std::vector< VI > VII;
typedef std::vector<long> VL;
typedef std::vector<long> VL;
typedef std::vector<long long> VLL;
typedef std::pair<int,int> PII;

int N, K;
std::vector< PII > coord;
VI X;
VI Y;

inline int cont(int xl, int xr, int yd, int yu) {
    int ans = 0;
    EACH(it, coord) {
        if(it->fst >= xl && it->fst <= xr && it->snd >= yd && it->snd <= yu) {
            ans++;
        }
    }
    return ans;
}


int main() {
    std::cin >> N >> K;
    coord.resize(N);
    X.resize(N);
    Y.resize(N);
    
    int x, y;
    REP(i, N) {
        std::cin >> x >> y;
        coord[i].fst = x;
        coord[i].snd = y;
        X[i] = x;
        Y[i] = y;
    }
    SORT(X);
    SORT(Y);

    LL ans = LLONG_MAX;
    EACH(xl, X) EACH(xr, X) {
        if(*xl >= *xr) continue;

        EACH(yd, Y) EACH(yu, Y) {
            if(*yd >= *yu) continue;

            int a = cont(*xl,*xr,*yd,*yu);
            if(a >= K) {
                LL s = std::abs((LL)*xr-(LL)*xl)*std::abs((LL)*yu-(LL)*yd);
                ans = std::min(ans, s);
            }
        }
    }
    std::cout << ans << std::endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
/*{{{*/  //template
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1<<29
#define LINF LLONG_MAX/3
#define mp make_pair
#define pb push_back
#define EB emplace_back
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define sz(x) (int)(x).size()
#define debug(x) cerr<<#x<<":"<<x<<endl
#define debug2(x,y) cerr<<#x<<","<<#y":"<<x<<","<<y<<endl
//struct fin{ fin(){ cin.tie(0); ios::sync_with_stdio(false); } } fin_;
struct Double{ double d; explicit Double(double x) : d(x){} };
ostream& operator<<(ostream& os,const Double x){ os << fixed << setprecision(20) << x.d; return os; }
template<typename T> ostream& operator<<(ostream& os,const vector<T>& vec){ os << "["; for(const auto& v : vec){ os << v << ","; } os << "]"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os,const pair<T,U>& p){ os << "(" << p.first << ","<< p.second <<")"; return os; }
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
ll gcd(ll a,ll b){ if(b==0) return a; else return gcd(b,a%b); }
constexpr double eps = 1e-14; 
constexpr ll mod = 1e9+7;
const int dx[]={1,0,-1,0} ,dy[] = {0,1,0,-1};
/*}}}*/

int main(){
    string t,p;
    cin >> t >> p;
    rep(i,t.size()){
        string s = t.substr(i,p.size());
        if(p==s){
            cout << i << endl;
        }
    }
}

Measured memory_bytes: 3188