akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include<math.h>
#define ll long long
#define fi first
#define se second
#define ld long double
#define mod 1000000007
using namespace std;
int main()
{
     ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
string s,c,ss="";
cin>>s>>c;
ll i,j,n=s.size(),m=c.size();
ll v[n+1][m+1];
for(i=0;i<=n;i++)
{
    for(j=0;j<=m;j++)
    {
        if(i==0 || j==0)
            v[i][j]=0;
        else if(s[i-1]==c[j-1])
        {
            v[i][j]=v[i-1][j-1]+1;
        }
        else
        {
            v[i][j]=max(v[i-1][j],v[i][j-1]);
        }
    }
}
i=n,j=m;
while(i>0 && j>0)
{
    if(s[i-1]==c[j-1])
    {
        ss+=s[i-1];
        i--;
        j--;

    }
    else
    {
      if(v[i-1][j]>v[i][j-1])
        i--;
      else
        j--;
    }
}
reverse(ss.begin(),ss.end());
cout<<ss;
}



Measured memory_bytes: 70656
/*
  This C++ Source Is
  Writen By syksykCCC
  (2020)
*/
#include <bits/stdc++.h>
#define rep(i, x, y) for(register int i = x; i < y; i++)
#define REP(i, x, y) for(register int i = x; i <= y; i++)
#define per(i, x, y) for(register int i = x; i > y; i--)
#define PER(i, x, y) for(register int i = x; i >= y; i--)
#define repl(i, x, y) for(register long long i = x; i < y; i++)
#define REPL(i, x, y) for(register long long i = x; i <= y; i++)
#define perl(i, x, y) for(register long long i = x; i > y; i--)
#define PERL(i, x, y) for(register long long i = x; i >= y; i--)
#define LLL __int128
#define int128 __int128
#define DEBUG(x) cerr << #x << " : " << x << endl
using namespace std;
typedef unsigned int uint;
typedef long long int64;
typedef long long LL;
typedef unsigned long long uint64;
typedef long long ULL;
typedef long double LLF;
template<typename T> inline void read(T &val)
{
	val = 0; char c = getchar(); int f = 1;
	while(!isdigit(c)) { if(c == '-') f = -1; c = getchar(); }
	while(isdigit(c)) { val = (val << 3) + (val << 1) + (c ^ 48); c = getchar(); }
	val *= f;
}
template<typename T> void write_(T val) { if(!val) return; write_(val / 10); putchar(val % 10 + 48); }
template<typename T> inline void write(T val)
{
	if(val == 0) putchar(48);
	else if(val < 0) { putchar('-'); write_(-val); }
	else write_(val);
}

vector<int> even, odd;

int main()
{
#ifdef LOCAL
//	freopen("in.txt", "r", stdin);
//	freopen("out.txt", "w", stdout);
#endif
	ios::sync_with_stdio(false);
	int n, m;
	cin >> n >> m;
	REP(i, 1, m)
	{
		if(i & 1) odd.push_back(i);
		else even.push_back(i);
	}
	for(unsigned i = 0; i < odd.size(); i++)
	{
		cout << i + 1 << ' ' << i + 1 + odd[odd.size() - i - 1] << endl;
	}
	for(unsigned i = 0; i < even.size(); i++)
	{
		cout << odd.back() + 2 + i << ' ' << odd.back() + 2 + i + even[even.size() - i - 1] << endl;
	}
	return 0;
}


Measured memory_bytes: 3852
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define repr(i,n) for(ll i=(n-1);i>=0;i--)
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define br cout << "\n";
using namespace std;
const int INF = 1e9;
const int MOD = 1e9+7;
using Graph = vector<vector<ll>>;
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;}

// 0 false, 1 true 
// string to int : -48
// ceil(a)  1.2->2.0
// c++17	g++ -std=c++17 a.cpp

int main() {
    std::cout << std::fixed << std::setprecision(15);
    double l;
    cin >> l;
    double tmp = l / 3;
    cout << tmp * tmp * tmp << endl;
}

Measured memory_bytes: 256
N, X = map(int, input().split())

ans = 0
for i in range(N, -1, -1):
    if X < 2**(i + 1) - 1:
        X -= 1
    elif X > 2 ** (i + 1) - 1:
        X -= 2 ** (i + 1) - 1
        ans += 2 ** i
    else:
        ans += 2 ** i
        break
    if X == 0:
        break
    #print(X, ans)


print(ans)

Measured memory_bytes: 9164
m, k = map(int, input().split())

if k >= 2**m:
    print(-1)
elif m == 1:
    if k == 0:
        print("0 0 1 1")
    elif k == 1:
        print(-1)
else:
    l = list(range(2**m))
    l.remove(k)
    ret = l + [k] + l[::-1] + [k]
    print(*ret)


Measured memory_bytes: 16232
#include <iostream>

using namespace std;

int main()
{
    int N;
    char A[101];
    char B[101];
    char C[101];
    cin >> N;
    for (int i =0;i<N;i++){
        cin >> A[i];
    }
    for (int i =0;i<N;i++){
        cin >> B[i];
    }
    for (int i =0;i<N;i++){
        cin >> C[i];
    }
    int cnt;
    cnt = 0;
    for (int i =0;i<N;i++){
        int temp=0;
        if (A[i] != B[i]){
            temp++;
        }
        else{
            temp--;
        }
        if (A[i] != C[i]){
            temp++;
        }
        else{
            temp--;
        }
        if (B[i] != C[i]){
            temp++;
        }
        else{
            temp--;
        }
        if (temp < 0){
            temp = 0;
        }
        else if (temp > 2){
            temp = 2;
        }
        cnt = cnt + temp;
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner scan = new java.util.Scanner(System.in);
        int a = scan.nextInt();
        int b = scan.nextInt();
        if((a + b) % 2 != 0){
            System.out.println("IMPOSSIBLE");
            System.exit(0);
        }else{
            System.out.println((a + b) / 2);
        }
    }
}

Measured memory_bytes: 21844
#include <array>
#include <bitset>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <functional>
#include <string>
#include <iostream>
#include <sstream>
#include <random>
#include <cmath>
#include <cstring>
using namespace std;
#define U(v) cerr << #v << ": " << (v) << endl

class timer {
    vector<timer> timers;
    int n = 0;
public:
    double limit = 9.8;
    double t = 0;
    timer() {}
    timer(int size) : timers(size) {}
    bool elapses() const {
        return time() - t > limit;
    }
    void measure() {
        t = time() - t;
        ++n;
    }
    void measure(char id) {
        timers[id].measure();
    }
    void print() {
        if (n % 2)
            measure();
        for (int i = 0; i < 128; ++i) {
            if (timers[i].n)
                cerr << (char)i << ' ' << timers[i].t << 's' << endl;
        }
        cerr << "  " << t << 's' << endl;
    }
    static double time() {
#ifdef LOCAL
        return __rdtsc() / 3.3e9;
#else
        unsigned long long a, d;
        __asm__ volatile ("rdtsc" : "=a" (a), "=d" (d));
        return (d << 32 | a) / 2.8e9;
#endif
    }
} timer(128);

class {
    unsigned y = random_device()();
public:
    unsigned next() {
        return y ^= (y ^= (y ^= y << 13) >> 17) << 5;
    }
    int next(int b) {
        return next() % b;
    }
    int next(int a, int b) {
        return next(b - a) + a;
    }
    double nextDouble(double b = 1) {
        return b * next() / 4294967296.0;
    }
    double nextDouble(double a, double b) {
        return nextDouble(b - a) + a;
    }
    int operator() (int b) {
        return next(b);
    }
} rando;

int main() {
    int n, m, d;
    while (cin >> n >> m >> d) {
        if (d == 0) {
            printf("%.30f\n", (double)n * (m - 1) / n / n);
        } else {
            printf("%.30f\n", 2.0 * (n - d) * (m - 1) / n / n);
        }
    }
    return 0;
}


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

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define SORT(v, n) sort(v, v+n)
#define pb(a) push_back(a)
#define eb(a) emplace_back(a)
#define vi vector<int>
#define ddvi vector<vector<int>>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;

void debug_out() { cout << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
	cout << H << " ";
	debug_out(T...);
}

#ifdef _DEBUG
#define debug(...) debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

// コンパイル時、コマンド「debug」を使用 --> マクロが使えるように

int main(){
	#define int ll
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	// ここに処理を記述
	// コンパイル時はコマンド「gpp」--> c++17でコンパイル

	int H, A;
	cin >> H >> A;

	debug("E_HP =",H,"/POWER =",A);

	cout << (H + (A-1))/A << endl;
	
	return 0;
}

Measured memory_bytes: 256
// #pragma GCC target("avx2")  // CPU 処理並列化
// #pragma GCC optimize("O3")  // CPU 処理並列化
// #pragma GCC optimize("unroll-loops")  // 条件処理の呼び出しを減らす
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
#include<numeric>
#include<unordered_set>
#include<complex>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const double EPS=1e-10;
const double INF=1e+10;
const double PI=acos(-1.0);
const int C_SIZE = 3121000;
namespace{
	long long fact[C_SIZE];
	long long finv[C_SIZE];
	long long inv[C_SIZE];
	long long Comb(int a,int b){
	 	if(a<b||b<0)return 0;
	 	return fact[a]*finv[b]%mod*finv[a-b]%mod;
	}
	void init_C(int n){
		fact[0]=finv[0]=inv[1]=1;
		for(int i=2;i<n;i++){
			inv[i]=(mod-(mod/i)*inv[mod%i]%mod)%mod;
		}
		for(int i=1;i<n;i++){
			fact[i]=fact[i-1]*i%mod;
			finv[i]=finv[i-1]*inv[i]%mod;
		}
	}
	long long pw(long long a,long long b){
		if(a<0LL)return 0;
		if(b<0LL)return 0;
		long long ret=1;
		while(b){
			if(b%2)ret=ret*a%mod;
			a=a*a%mod;
			b/=2;
		}
		return ret;
	}
	long long pw_mod(long long a,long long b,long long M){
		if(a<0LL)return 0;
		if(b<0LL)return 0;
		long long ret=1;
		while(b){
			if(b%2)ret=ret*a%M;
			a=a*a%M;
			b/=2;
		}
		return ret;
	}
	int pw_mod_int(int a,int b,int M){
		if(a<0)return 0;
		if(b<0)return 0;
		int ret=1;
		while(b){
			if(b%2)ret=(long long)ret*a%M;
			a=(long long)a*a%M;
			b/=2;
		}
		return ret;
	}
	int ABS(int a){return max(a,-a);}
	long long ABS(long long a){return max(a,-a);}
	double ABS(double a){return max(a,-a);}
	int sig(double r) { return (r < -EPS) ? -1 : (r > +EPS) ? +1 : 0; }
}
// ここから編集しろ
int p[210000];
int s[210000];
int main(){
	int a;scanf("%d",&a);
	int t=0;
	for(int i=0;i<a;i++){
		int x,y;scanf("%d%d",&x,&y);
		t=(t+x)%86400;
		p[t]++;
		p[t+86400]++;
		t=(t+y)%86400;
	}
	for(int i=0;i<205000;i++){
		s[i+1]=s[i]+p[i];
	}
	int ret=0;
	for(int i=0;i<86400;i++){
		ret=max(ret,s[i+10801]-s[i]);
	}
	printf("%d\n",ret);
}


Measured memory_bytes: 1664
#include <iostream>
#include <numeric>
#include <iomanip>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)




int main() {
	string S, D;
	cin >> S;
	D = "CODEFESTIVAL2016";
	int k = 0;
	rep(i, 16) {
		if (S.at(i) != D.at(i)) {
			k++;
		}
	}

	cout << k << endl;
}


Measured memory_bytes: 256
// ABC171B.cpp
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
    int n;
    cin >> n; // 果物　ｎ種類
    int k;
    cin >> k; // 買う果物　ｋ種類
    int p[1000];
    for (int i = 0; i < n; i++) {
        cin >> p[i];
    }
    for (int i = n; i < 1000; i++)
    {
        p[i] = 9999;
    }
    //sort(p, p + 1000,greater<>());
    sort(p, p + 1000);
    int ans = 0;
    for (int i = 0; i < k; i++)
    {
        ans += p[i];
    }
    cout << ans << endl;
}


Measured memory_bytes: 3196
#include<iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <cmath>
#include <math.h>
#include <iomanip>
using namespace std;
int main()
{
    double a,b,x;
    cin >> a >> b >> x;
    if(x<=(pow(a,2)*b)/2){
        cout << setprecision(15) << atan(b/((x*2)/(a*b)))*(180/M_PI); 
    }else{
        cout << setprecision(15) << atan((b-((x/pow(a,2))*2-b))/a)*(180/M_PI); 
    }

}

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

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> ii;
typedef tuple<ll, ll, ll> iii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
#define REP(i,n) for (ll i = 0; i < n; ++i)
#define REPR(i,n) for (ll i = n-1; i >= 0; --i)
#define FOR(i,m,n) for (int i = m; i < n; ++i)
#define FORR(i,m,n) for (ll i = n-1; i >= m; --i)
#define FORE(x,xs) for (const auto& x : xs)
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define ALL(v) v.begin(), v.end()
#define rALL(v) v.rbegin(), v.rend()

int N;

int main() {
    cin >> N;
    cout << (N-1)/2 << endl;
}

Measured memory_bytes: 256
#C
import math
#入力
A,B=map(int,input().split())

#処理
c=0
d=0
c=max([math.floor(A/0.08),math.floor(B/0.1)])
d=min([math.ceil((A+1)/0.08),math.ceil((B+1)/0.1)])
z=-1
for i in range(c,d+1):
    if math.floor(i*0.08)==A and math.floor(i*0.1)==B:
        z=i
        break
print(z)

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

using namespace std;

#define REP(i,n) for(int i=0;i<(n);i++)
#define REP1(i,n) for(int i=1;i<(n);i++)
#define ALL(a)  (a).begin(),(a).end()
using ll = long long;
using ld = long double;
using Pint = pair<int, int>;
const ll mod = 1e9+7;

int main(int argc, char const* argv[])
{
  int n;
  cin>>n;

  map<string,int> m;
  int max_count = 0;
  REP(i,n) {
    string s;
    cin>>s;
    m[s]++;
    if(max_count<m[s]) max_count = m[s];
  }

  vector<string> ans;
  for(auto p: m) {
    if(p.second==max_count) ans.push_back(p.first);
  }

  // sort(ALL(ans));

  for(auto s: ans) {
    cout << s << endl;
  }

  return 0;
}


Measured memory_bytes: 26868
#include <algorithm>
#include <iostream>
#include <math.h>
#include <queue>
#include <string>
#include <vector>

using namespace std;

#define INF 210000000

static long long gcd(long long a, long long b) {
  int amari = a % b;
  int c = b;
  if (amari == 0) {
    return b;
  } else {
    return gcd(b, amari);
  }
}

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

int main() {
  int a;
  cin >> a;
  cout << 3 * a * a;
}


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

using namespace std;
typedef long long ll;

ll A,B;

ll Solve(int t,ll mx,ll u,ll v){
	if(t==-1)return 1;
	ll d=1ll<<t;
	if(mx<d)return Solve(t-1,mx,u,v);
	if(u>=d)return Solve(t-1,mx-d,u-d,v-d);
	if(v<d)return Solve(t-1,d-1,u,v);
	if(u+d<=v)return mx-u+1;
	return d-u+max(mx-d-u+1,0ll)+Solve(t-1,u-1,0,v-d);
}

int main(){
	cin>>A>>B;
	cout<<Solve(59,(1ll<<60)-1,A,B)<<endl;
	return 0;
}

Measured memory_bytes: 256
def inpl(): return list(map(int, input().split()))

N, C = inpl()
stc = [inpl() for _ in range(N)]
stc.sort()

num = [(-1, -1)]
for s, t, c in stc:
    for i, Tuple in enumerate(num):
        # print(s, t)
        ch = Tuple[0]
        ti = Tuple[1]
        if ch != c and s - 0.5 >= ti:
            num[i] = (c, t)
            break
        elif ch == c and s >= ti:
            num[i] = (c, t)
            break
    else:
        num.append((c, t))
print(len(num))

Measured memory_bytes: 28156
import java.util.*

open class MainKt {
    companion object Static {
        @JvmStatic
        fun main(args: Array<String> = arrayOf()) {
            MainKt().solve()
        }
    }

    val scanner = Scanner(System.`in`)

    fun printf(pattern: String, vararg args: Any): Unit {
        println(String.format(pattern, *args))
    }

    open fun println(line: String) {
        kotlin.io.println(line)
    }

    fun println(line: Int) {
        println(line.toString())
    }

    fun println(line: Long) {
        println(line.toString())
    }

    open fun readLine(): String {
        return scanner.nextLine()
    }

    fun readArg(): String {
        return readLine()
    }

    fun readInt(): Int {
        return readArg().toInt()
    }

    fun readLong(): Long {
        return readArg().toLong()
    }

    fun readIntList(): List<Int> {
        return readArgList().map { it.toInt() }
    }

    fun readLongList(): List<Long> {
        return readArgList().map { it.toLong() }
    }

    fun readArgList(): List<String> {
        return readLine().split(" ")
    }

    fun solve(): Unit {
        readLine()
        var a = readIntList()
        for (i in 0..a.lastIndex) {
            if (i != 0) print(" ")
            if (i < (a.size + 1) / 2) {
                print(a[a.lastIndex - i * 2])
            } else {
                print(a[i * 2 - a.size])
            }
        }
    }
}

Measured memory_bytes: 106116
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <iomanip> // setprecision
#include <complex> // complex
#include <math.h> 
#define enld '\n'
using namespace std;
using ll = long long;
using P = pair<int,int>;
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const int dx[8] = {1, 0, -1, 0,1,1,-1,-1};
const int dy[8] = {0, 1, 0, -1,1,-1,1,-1};
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; }
// ---------------------------------------------------------------------------

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  vector<int> A(3);
  for(int i=0; i<3; i++){
   cin >> A[i];
  }
  sort(A.begin(),A.end());
  cout << A[0] + A[1] << "\n";
  return 0;
}

Measured memory_bytes: 3188
parseInt(x) = parse(Int, x)
parseBigInt(x) = parse(BigInt, x)
parseFloat(x) = parse(Float64, x)
parseBigFloat(x) = parse(BigFloat, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
    n,m,x=parseMap(split(readline()))
    data=[parseMap(split(readline())) for i in 1:n]
    ans=2<<32
    for i in 0:(1<<n)-1
        pat=Vector{Int}()
        for j in 0:n-1
            if i & (1<<j) == 0
                # jは0-startだがJuliaの配列は1-indexedなので
                push!(pat,j+1)
            end
        end
        res=zeros(Int,1,m)
        cnt=0
        for j in pat
            cnt+=data[j][1]
            for k in 1:m
                res[k]+=data[j][k+1]
            end
        end
        flg=true
        for i in res
            if i<x
                flg=false
                break
            end
        end
        if flg
            ans=min(ans,cnt)
        end
    end
    if ans==2<<32
        ans=-1
    end
    println(ans)
end
main()

Measured memory_bytes: 176748
#include<cstdio>

#define MAX 10000
#define NIL -1

struct Node{
  int parent;
  int left;
  int right;
};

Node T[MAX];
int n, D[MAX], H[MAX];

void setDepth(int u, int d) {
  if(u == NIL) return;
  D[u] = d;
  setDepth(T[u].left, d + 1);
  setDepth(T[u].right, d + 1);
}

int setHeight(int u) {
  int h1 = 0, h2 = 0;
  if(T[u].left != NIL) h1 = setHeight(T[u].left) + 1;
  if(T[u].right != NIL) h2 = setHeight(T[u].right) + 1;
  return H[u] = ((h1 > h2) ? h1 : h2);
}

int getSibling(int u) {
  if(T[u].parent == NIL) return NIL;
  if(T[T[u].parent].left != u && T[T[u].parent].left != NIL)
    return T[T[u].parent].left;
  if(T[T[u].parent].right != u && T[T[u].parent].right != NIL)
    return T[T[u].parent].right;
  return NIL;
}

void print(int u) {
  printf("node %d: ", u);
  printf("parent = %d, ", T[u].parent);
  printf("sibling = %d, ", getSibling(u));
  int deg = 0;
  if(T[u].left != NIL) deg++;
  if(T[u].right != NIL) deg++;
  printf("degree = %d, ", deg);
  printf("depth = %d, ", D[u]);
  printf("height = %d, ", H[u]);

  if(T[u].parent == NIL) {
    printf("root\n");
  } else if (T[u].right == NIL && T[u].left == NIL) {
    printf("leaf\n");
  } else {
    printf("internal node\n");
  }
}

int main() {
  int v, l, r, root = 0;
  scanf("%d", &n);

  for(int i = 0; i < n; i++) T[i].parent = NIL;

  for(int i = 0; i < n; i++) {
    scanf("%d %d %d", &v, &l, &r);
    T[v].left = l;
    T[v].right = r;
    if(l != NIL) T[l].parent = v;
    if(r != NIL) T[r].parent = v;
  }

  for(int i = 0; i < n; i++) {
    if(T[i].parent == NIL) root = i;
  }

  setDepth(root, 0);
  setHeight(root);

  for(int i = 0; i < n; i++) print(i);

  return 0;
}



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

int main() {
  int N;
  cin >> N;
  long long int m;
  vector<long long int> a(N);
  priority_queue<long long int> q;
  for (int i = 0; i < N; i++) {
    long long int v;
    cin >> v;
    if (v < 0) {
      q.push(v);
      v *= -1;
    }
    if (i == 0) {
      m = v;
    }
    else {
      m = min(v, m);
    }
    a.at(i) = v;
  }
  long long int count = 0;
  for (int i = 0; i < N; i++) {
    count += a.at(i);
  }
  if (q.size() % 2 != 0) {
    count -= 2 * m;
  }
  printf("%lld\n", count);
}

Measured memory_bytes: 2168
#include<stdio.h>
int main(void){
  int S,a,b,c,d;
  scanf("%d",&S);
  a=S/1000;
  b=S/100-a*10;
  c=S/10-a*100-b*10;
  d=S%10;
  if(a==b){
    printf("Bad");
  }else if(b==c){
    printf("Bad");
  }else if(c==d){
    printf("Bad");
  }else{
    printf("Good");
  }

  return 0;
 }
      

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

N = int(input())
A = list(map(int, input().split()))
A.append(100000000000)
cnt=0
ans=0
for i in range(N):
    if A[i] >= A[i+1]:
        cnt+=1
    else:
        ans=max(ans,cnt)
        cnt=0
print(ans)


Measured memory_bytes: 14172
#include <bits/stdc++.h>
using namespace std;
#define rep(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(v) v.begin(), v.end()
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; }
using ll = long long;
const ll MOD = 1e9+7; ll LLINF = 1LL << 60; int INF = INT_MAX;

//

int main(){
    int n; cin>>n;
    if(n>=1000) cout<<"ABD"<<endl;
    else cout<<"ABC"<<endl;
}

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

using namespace std;

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

int main(void){
  //initialize
  long long dp[3][100010];
  for(int i=0;i<100010;i++){
    for(int j=0;j<3;j++){
      dp[j][i] = 0;
    }
  }
  //input
  int N;
  long long val[3][100010];
  cin >> N;
  for(int i=0;i<N;i++){
    cin >> val[0][i] >> val[1][i] >> val[2][i];
  }
  //dp
  for(int i=0;i<N;i++){
    for(int j=0;j<3;j++){
      for(int k=0;k<3;k++){
        if(j!=k){
          chmax(dp[k][i+1],dp[j][i]+val[k][i]);
        }
      }
    }
  }
  long long ans = 0;
  for(int j=0;j<3;j++) chmax(ans, dp[j][N]);
  cout << ans << "\n";
}


Measured memory_bytes: 4992
# include <stdio.h>
# include <string.h>

int main(){
    char S[10];
    int flg = 0;

    scanf("%s", S);

    if (S[0] != 'A') flg = 1;
    else S[0] = 'a';

    int ct = 0;
    for (int i = 2; i < strlen(S)-1; ++i){
        if (S[i] == 'C'){
            S[i] = 'c';
            ct++;
        }
    }
    if (ct != 1) flg = 1;

    if (flg == 0){
        for (int i = 0; i < strlen(S); ++i){
            if ('a' <= S[i] && S[i] <= 'z')
                continue;
            else{
                flg = 1;
                break;
            }
        }
    }

    if (flg == 0) printf("AC");
    else printf("WA");

    return 0;
}


Measured memory_bytes: 128
import java.util.Scanner;

public class Main{


	static int n;

	public static void main(String[] args) {

		Scanner scanner = new Scanner(System.in);
		n = Integer.parseInt(scanner.next());

		System.out.println(defs("0"));
	}

	public static int defs(String s) {

		int count = 0;
		if(Long.parseLong(s) > n) {
			return 0;
		}

		if(s.contains("7") && s.contains("5") && s.contains("3")) {
			count = 1;
		}

		count += defs(s + "3");
		count += defs(s + "7");
		count += defs(s + "5");




		return count;
	}

}

Measured memory_bytes: 36564
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,srt,end) for(ll i=(ll)(srt); i<(ll)(end); i++)

int main(){
    ll N,Y;
    cin>>N>>Y;
    ll z;
    vector<ll> ans(3,-1);
    rep(x,0,Y/10000+2){
        rep(y,0,Y/5000+2){
            z = (Y - 10000*x - 5000*y)/1000;
            if(0<=z&&z<=N&&x+y+z==N){
                ans[0]=x;
                ans[1]=y;
                ans[2]=z;
            }
        }
    }
    cout<<ans[0]<<" ";
    cout<<ans[1]<<" ";
    cout<<ans[2]<<" ";
    cout<<endl;
    return 0;
}

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

namespace test
{
    class MainClass
    {
        public static void Main(string[] args)
        {

            //問題156

            int n = int.Parse(Console.ReadLine());

            string[] line = Console.ReadLine().Split(' ');

            int[] x = new int[n];

            int min = 100;
            int max = 1;
            for (int i = 0; i < n; i++)
            {
                x[i] = int.Parse(line[i]);

                min = Math.Min(min, x[i]);
                max = Math.Max(max, x[i]);
            }

            long ans = 0;

            for (int i = min; i <= max; i++)
            {
                long count = 0;

                for (int j = 0; j < n; j++)
                {

                    count += (x[j] - i) * (x[j] - i);
                }

                if (i == min)
                {
                    ans = count;
                }

                ans = Math.Min(ans, count);
                
            }

            Console.WriteLine(ans);

        }

    }





    
}


Measured memory_bytes: 27332
//****** @mdazmat9 **********
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define int long long
#define UB upper_bound
#define LB lower_bound
#define BS binary_search
#define EB emplace_back
#define PB push_back
#define endl "\n"
#define MOD 1000000007
#define MOD2 998244353
#define F first
#define S second
#define ALL(a) (a).begin(),(a).end()
typedef pair<int, int> pr;
typedef vector<int> VI;
typedef vector<pr> VP;
typedef vector<string> VS;
typedef vector<vector<int>> VV;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define trace1(x)                cout<<#x<<": "<<x<<endl
#define trace2(x, y)             cout<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cout<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
#define trace(v) for(auto it=v.begin();it!=v.end();it++)cout<<*it<<" ";cout<<endl;
const int INF = 1e9;
int fast_pow(int x, int y, int p);

int n,k,dp[100005];
void solve() {
	cin>>n>>k;
	int a[n];
	for(int i=0;i<n;i++)cin>>a[i];
	int ans =0;
	for(int i=1;i<=k;i++){
		for(int j=0;j<n;j++){
			if(i-a[j]>=0){
				dp[i]|=(!dp[i-a[j]]);
			}
		}
	}
	if(dp[k])
		cout<<"First"<<endl;
	else
		cout<<"Second"<<endl;
	
	
}

int32_t main() {

	IOS;
	int test = 1;
	// cin>>test;
	for (int i = 1; i <= test; i++) {
//        cout<<"Case #"<<i<<": ";
		solve();
	}
	return 0;
}
int fast_pow(int x, int y, int p) {
	int res = 1;
	x = x % p;
	while (y > 0) {
		if (y & 1)
			res = (res * x) % p;
		y = y >> 1;
		x = (x * x) % p;
	}
	return res;
}

Measured memory_bytes: 1152
def resolve():
    n,m= map(int, input().split())
    a=[]
    b=[]
    i=2
    l=1
    while m!=1:
      while m%i!=0:
        i+=1
      a.append(i)
      m=m//i
    au=list(set(a))
    for j in range(len(au)):
        b.append(a.count(au[j]))
    from operator import mul
    from functools import reduce

    def cmb(n, r):
        r = min(n - r, r)
        if r == 0: return 1
        over = reduce(mul, range(n, n - r, -1))
        under = reduce(mul, range(1, r + 1))
        return over // under

    for k in b:
        l*=cmb(k+n-1,n-1)

    print(l%(10**9+7))
resolve()

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


using namespace std;


int main() {
    int n; cin >> n;
    vector<pair<int, int>> a(n);

    int ai;
    for (int i=0; i<n; i++) {
        cin >> ai;
        a[i] = make_pair(ai, i);
    }

    sort(a.begin(), a.end());
    for (auto e: a) cout << e.second+1 << ' '; cout << endl;

    return 0;
}



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

int main(void)
{
    int n,d;
    set<int> s;

    cin >> n;
    for(int i = 0;i < n;i++){
      cin >> d;
      s.insert(d);
    }

    cout << s.size() << '\n';

    return 0;
}

Measured memory_bytes: 256
#include "stdio.h"
#include <stdlib.h>

int main (){
  int a, b, c;
  char x,y,z;
  //  scanf("%c%c%c", &x, &y, &z);                                                                            
  scanf("%d",&a);
  int d=3*a*a;

  printf("%d\n",d);
  return 0;
}

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

int main(void) {
	char N[3];
	int flag = 0;
	for (int i = 0; i < 3; i++) {
		cin >> N[i];
		if (N[i] == '7') flag = 1;
	}
	
	if (flag) cout << "Yes" << endl;
	else cout << "No"<< endl;
	return 0;
}

Measured memory_bytes: 3632
n = int(input())
li = list(map(int,input().split()))
li.sort(reverse = True)
ans = acc = 0
for x in li:
    if x%2 == 0:
        ans += x//2
    elif acc != 0:
        ans += (acc+x)//2
        acc = 0
    else:
        acc = x
print(ans)


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

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << setprecision(20);

  int n;
  cin >> n;
  vector<int> a(n+1);
  rep(i, n) { cin >> a[i+1]; }

  vector<int> b(n+1);
  for (int i = n; i >= 1; --i) {
    int sum = 0;
    for (int j = i+i; j <= n; j += i) {
      sum ^= b[j];
    }
    b[i] = sum^a[i];
  }

  vector<int> ans;
  for (int i = 1; i <= n; ++i) {
    if (b[i]) ans.push_back(i);
  }
  cout << ans.size() << endl;
  if (ans.size() == 0) return 0;
  rep(i, ans.size()) {
    if (i != 0) cout << " ";
    cout << ans[i]; 
  }
  cout << endl;
  return 0;
}


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

int main(){
  int n,ans;
  string s,r;

  cin >> s;
  cin >> n;
  ans = 0;
  for(int i=0;i<n;i++){
    cin >> r;
    string tmp = r;
    do{
      if(r.substr(0,s.size()) == s){
	ans++;
	break;
      }
      rotate(r.begin(),r.begin()+r.size()-1,r.end());
    }while(tmp!=r);
  }
  cout << ans << endl;
}

Measured memory_bytes: 0
#include<bits/stdc++.h> //ABC 171_a
#define ll long long
using namespace std;
string a;
int main(){
	cin>>a;
	if(a=="a"||a=="b"||a=="c"||a=="d"||a=="e"||a=="f"||a=="g"||a=="h"||a=="i"||a=="j"||a=="k"||a=="l"||a=="m"||a=="n"||a=="o"||a=="p"||a=="q"||a=="r"||a=="s"||a=="t"||a=="u"||a=="v"||a=="w"||a=="x"||a=="y"||a=="z")
		cout<<"a";
	else
		cout<<"A";
	return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
int main() {
	int64_t X;
	cin >> X;
	int64_t t = 2;
	for(int i = 0; i < X; i++) {
		t = 2 * (t + 1);
	}
	cout << t << endl;
	return 0;
}

Measured memory_bytes: 256
// 🐋💭
import Foundation

func readInts() -> [Int] {
    return readLine()!.split(separator: " ").map { Int($0)! }
}

func readInt() -> Int {
    return Int(readLine()!)!
}

func readDoubles () -> [Double] {
    return readLine()!.split(separator: " ").map { Double($0)! }
}

func readDouble() -> Double{
    return Double(readLine()!)!
}
///最大公約数を返す
func gcd(_ m:Int, _ n:Int) -> Int {
    if n == 0 {return m}
    return gcd(n, m % n)
}

///最大公約数を返す
func gcd(_ array: [Int]) -> Int {
    var value = array[0]
    if array.count > 1 {
        for i in 1..<array.count {
            value = gcd(value, array[i])
        }
    }
    return value
}

///最小公倍数を返す
func lcm(_ m:Int, _ n:Int) -> Int {
    return m * n / gcd(m, n)
}

///素数判定(試し割り)
func isPrime(_ x:Int) -> Bool {
    if x <= 1 || x % 2 == 0 { return false }
    if x == 2 { return true }
    for i in stride(from: 3, to: Int(ceil(sqrt(Double(x)))), by: 2){
        if x % i == 0 {
            return false
        }
    }
    return true
}

//https://program-life.com/669
///実行速度の計測
func exectionTime(action: () -> Void) {
    let startDate = Date()
    action()
    let endDate = Date()
    print(endDate.timeIntervalSince(startDate))
}

// https://melheaven.hatenadiary.jp/entry/atcoder144
///約数の配列を返す
func makeDivisors(_ n:Int) -> [Int] {
    var divisors = [Int]()
    for i in 1..<Int(pow(Double(n), 0.5)) + 1 {
        if n % i == 0{
            divisors.append(i + n / i)
        }
    }
    
    return divisors
}

//https://riptutorial.com/ja/swift/example/14738/インデックスを知らずに配列から要素を削除する
extension Array where Element: Equatable {
    
    mutating func remove(_ element: Element) {
        _ = firstIndex(of: element).flatMap {
            self.remove(at: $0)
        }
    }
}

func binarySearch(rifgt:Int, key:Int, ary:[String]) -> Int{
    var left = 0
    var right = rifgt
    
    while abs(right - left) > 1 {
        let mid = left + (right - left) / 2
        
        if Int(ary[mid])! < key {
            left = mid
            
        } else {
            right = mid
        }
    }
    return left
}

func arrangement (prev:String, ary:[String], returnVal:[String]) -> [String] {
    var returnVal = returnVal
    if ary.count == 0 {
        returnVal.append(prev)
        return returnVal
    }
    
    for s in ary {
        let wprev = prev + s
        var wary = ary
        wary.remove(s)
        returnVal = arrangement(prev: wprev, ary: wary, returnVal: returnVal)
    }
    return returnVal
}

func main() {
    let n = readInt()
    let aryS = readLine()!.map { String($0) }
    //＿＿＿＿＿＿＿＿＿＿＿＿＿＿ここまで入力
    var countLeft = 0
    var countRight = 0
    for i in 1..<n {
        if aryS[i] == "E" {
            countRight += 1
        }
    }
    var ans = countLeft + countRight
    // i = リーダのindex
    for i in 1..<n {
        if aryS[i - 1] == "W" {
            countLeft += 1
        }
        if aryS[i] == "E" {
            countRight -= 1
        }
        ans = min(ans, countLeft + countRight)
    }
    print(ans)
}
main()


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

int main() {
  ll N, i, a, b; cin >> N >> a >> b;
  ll ans = min(N%(a+b), a) + N/(a+b) * a;
  cout << ans << endl;
  return 0;
}


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

using namespace std;

#define fio ios_base::sync_with_stdio(false);cin.tie(NULL)
#define watch(x) cout << (#x) << " is " << (x) << endl
#define f(t) for(ll i =0;i<t;i++)
#define bs(a,x) binary_search(a.begin(),a.end(),x)
#define ll long long int
#define ul unsigned long int
#define ld long double
#define umpi unordered_map<int,int> 
#define umpl unordered_map<ll,ll> 
#define vi vector<int>
#define vl vector<ll>
#define pb push_back
#define mod 1000000007 
#define N 10000000
#define all(a) a.begin(),a.end()
#define point pair<int,int>
const int inf = 1000000007;
const ll linf = 1ll * inf * inf;

inline ll mul(ll a, ll b){ return (a * 1ll * b) % mod; }
inline ll sub(ll a, ll b){ ll c = a - b; if(c < 0) c += mod; return c; }
inline ll add(ll a, ll b){ ll c = a + b; if(c > mod) c -= mod; return c; }

struct hash_pair { 
    template <class T1, class T2> 
    size_t operator()(const pair<T1, T2>& p) const
    { 
        auto hash1 = hash<T1>{}(p.first); 
        auto hash2 = hash<T2>{}(p.second); 
        return hash1 ^ hash2; 
    } 
};

int main()
{	
	fio;
	ll t;t=1;
	while(t--)
	{
		ll n;cin>>n;
		vl a(n);
		f(n)cin>>a[i];
		pair<ll,ll> dp[n][n];
		memset(dp,0,sizeof(dp));
		for(ll i=0;i<n;i++)
		{
			dp[i][i].first=a[i];
			dp[i][i].second=0;
		}
		for(ll k=1;k<n;k++)
		{
			for(ll i=0;i+k<n;i++)
			{
				ll j=i+k;
				if(a[i]+dp[i+1][j].second>a[j]+dp[i][j-1].second)
				{
					dp[i][j].first=a[i]+dp[i+1][j].second;
					dp[i][j].second=dp[i+1][j].first;
				}
				else
				{
					dp[i][j].first=a[j]+dp[i][j-1].second;
					dp[i][j].second=dp[i][j-1].first;
				}
			}
		}
		cout<<dp[0][n-1].first-dp[0][n-1].second<<"\n";
	}
}


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

int main()
{
    unsigned long long int n,sum=0;
    cin>>n;
    n++;
    vector<unsigned long long int>a(n,0),b(n,0),adj(n,0),abv(n,0);
    for(ull i=0;i<n;i++)cin>>a[i];
    for(ull i=0;i<n-1;i++)cin>>b[i];
    b[n-1]=0;abv[0]=0;
    if(a[0]<=b[0])
    {
     adj[0]=a[0];
     b[0]-=a[0];
    }
    else
    {
     adj[0]=b[0];
     b[0]=0;
    }
    for(ull i=1;i<n;i++)
    {
        if(a[i]>b[i-1])
        {
          abv[i]=b[i-1];
          a[i]-=abv[i];
          adj[i]=(b[i]>a[i]?a[i]:b[i]);
          b[i]-=adj[i];
        }
        else
        {
          abv[i]=a[i];
          adj[i]=0;
        }
    }
    for(ull  i=0;i<n;i++){sum+=adj[i]+abv[i];}
    cout<<sum;
    return 0;
}


Measured memory_bytes: 3328
'''
Problem Link - https://atcoder.jp/contests/abc178/tasks/abc178_a
'''
from sys import stdin,stdout
from math import *
from collections import *

mod = 1000000007

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

def lcm(a,b): return (a*b) // gcd(a,b)

def set_bits(X):
	c = 0
	while X:
		X &= (X-1);c += 1
	return c

def compute_MOD(N,M): return (N%M + M) % M

def get_array(): return list(map(int, stdin.readline().split()))
 
def get_ints(): return map(int, stdin.readline().split())

def get_int(): return int(stdin.readline())

def get_input(): return stdin.readline().strip()

def main():
	x = get_int()
	if x:stdout.write('0\n')
	else:stdout.write('1\n')

if __name__ == "__main__":
    main()

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

#define rep(i, n) REP(i, 0, n)
#define REP(i, k, n) for(auto i = k; i != n; i++)
#define rrep(i, n) RREP(i, n, 0)
#define RREP(i, n, k) for(auto i = n; i != k; i--)
#define all(x, r) (x), (x)+(r)
#define ALL(x) (x).begin(), (x).end()
#define debug(x) cerr << #x << " " << x << endl
#define exst(x, data) (data).find(x) != (data).end()
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
#define np next_permutation
#define b32 bitset<32>

using ll = long long;
using Pii = pair<int,int>;
using Tiii = tuple<int, int, int>;
template<class T>using V = vector<T>;

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

    ll N, K; cin >> N >> K;
    V<int> x = V<int>(N+1);
    REP(i,1,N+1) {
        cin >> x[i];
    }

    if(K == 1) {
        ll ans = LLONG_MAX;
        REP(i,1,N+1)
            ans = min(ans, llabs(x[i]));
        cout << ans << endl;
        return 0;
    }

    ll ans = LLONG_MAX;
    REP(j,1,N+2-K) {
        ll r = x[j+K-1], l = x[j];
        if(l < 0 && r < 0) {
            ans = min(ans, llabs(l));
        } else if(l < 0) {
            ans = min(ans, llabs(l)+r+min(llabs(l),r));
        } else {
            ans = min(ans, r);
        }
        // cout << j << endl;
    }

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


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

typedef pair<bool,int> RESULT;

int main() {
  //input
  int N, M;
  cin >> N >> M;
  vector<RESULT> result(N,make_pair(false,0));
  int pp;
  string SS;
  RESULT cur;
  rep(i,M) {
    cin >> pp >> SS;
    cur = result.at(pp-1);
    if ( SS == "AC" ) {
      result.at(pp-1) = make_pair(true, cur.second);
    }
    else if ( cur.first == false ) {
      result.at(pp-1) = make_pair(cur.first, cur.second+1);
    }
  }
  //calc
  int ac = 0;
  int penalty = 0;
  for ( auto r : result ) {
    if ( r.first ) {
      ac++;
      penalty += r.second;
    }
  }
  //output
  cout << ac << " " << penalty << endl;
}

Measured memory_bytes: 1024
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
typedef long long ll;

const ll INF = 1e16 + 10;
const int A = 1e6 + 10;
class Gra{
public:
    int v,next;
    ll w;
}G[A<<2];
int head[A],tot;
ll Ans[A];

void add(int u,int v,ll w){
    G[tot].v = v;
    G[tot].w = w;
    G[tot].next = head[u];
    head[u] = tot++;
}

void dfs(int u,int pre,ll dep){
    Ans[u] = min(Ans[u],dep);
    for(int i=head[u] ;i!=-1 ;i=G[i].next){
        int v = G[i].v;
        if(v == pre) continue;
        ll w = G[i].w;
        dfs(v,u,dep+w);
    }
}

int main(){
    //freopen("input","r",stdin);
    int n;
    scanf("%d",&n);
    memset(head,-1,sizeof(head));tot = 0;
    for(int i=1 ;i<n ;i++){
        int u,v;
        ll w;
        scanf("%d%d%lld",&u,&v,&w);
        add(u,v,w);add(v,u,w);
    }
    int q,k;
    scanf("%d%d",&q,&k);
    fill(Ans,Ans+n+1,INF);
    dfs(k,0,0);
    for(int i=1 ;i<=q ;i++){
        int u,v;
        scanf("%d%d",&u,&v);
        ll ans = Ans[u] + Ans[v];
        printf("%lld\n",ans);
    }
    return 0;
}


Measured memory_bytes: 17408
'''
自宅用PCでの解答
'''
import math
#import numpy as np
import itertools
import queue
import bisect
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)
mod = 10**9+7
dir = [(-1,0),(0,-1),(1,0),(0,1)]
alp = "abcdefghijklmnopqrstuvwxyz"

def main():
    n = int(ipt())
    a = [int(i) for i in ipt().split()]
    ma = 0
    ans = 0
    for i in a:
        if i > ma:
            ma = i
        else:
            ans += ma-i

    print(ans) 

    return None

if __name__ == '__main__':
    main()


Measured memory_bytes: 95456
#define _CRT_SECURE_NO_WARNINGS

#define N (1<<18)
#define MODULO (1000000007)
#define HA1 (2420609)
#define HA2 (19260817)

#include <cstdio>
#include <iostream>
#include <fstream>
#include <sstream>
#include <queue>
#include <map>
#include <set>
#include <deque>
#include <vector>
#include <stack>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <string>
using namespace std;

inline int GetRand()
{
	int Res = rand()*rand()*rand();
	Res -= rand()*rand();
	Res += rand();
	return Res;
}

int n, m;
set<int> S;
vector<int> qu;

int main()
{
	scanf("%d%d", &n, &m);
	for (int i = 0;i < m;i++)
	{
		int uu, vv;
		scanf("%d%d", &uu, &vv);
		uu--, vv--;
		if (uu == 0)
		{
			S.insert(vv);
		}
		else if (vv == n - 1)
		{
			qu.push_back(uu);
		}
	}
	for (int i = 0;i < qu.size();i++)
	{
		if (S.find(qu[i]) != S.end())
		{
			printf("POSSIBLE\n");
			return 0;
		}
	}
	printf("IMPOSSIBLE\n");
	//system("pause");
	return 0;

}



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

typedef long long ll;
typedef pair<ll,ll> P;

#define fr first
#define sc second

const ll MOD[2] = {1000000007,1000000009};

ll modpow(ll x,ll k,int t){
	if(k==0)return 1;
	ll ret=modpow(x,k/2,t);
	ret*=ret; ret%=MOD[t];
	if(k%2==1){
		ret*=x; ret%=MOD[t];
	}
	return ret;
}

int main(){
	int n;
	string s;
	cin>>n>>s;
	
	srand((unsigned)time(NULL));
	ll r[2]={rand()+n,rand()+n};
	
	P hash[250010],h=P(0,0);
	ll loc[250010],p=0;
	for(int i=0;i<n;i++){
		if(s[i]=='+'){
			h.fr+=modpow(r[0],p+MOD[0]-1,0);
			if(h.fr>=MOD[0])h.fr-=MOD[0];
			h.sc+=modpow(r[1],p+MOD[1]-1,1);
			if(h.sc>=MOD[1])h.sc-=MOD[1];
		}
		else if(s[i]=='-'){
			h.fr+=MOD[0]-modpow(r[0],p+MOD[0]-1,0);
			if(h.fr>=MOD[0])h.fr-=MOD[0];
			h.sc+=MOD[1]-modpow(r[1],p+MOD[1]-1,1);
			if(h.sc>=MOD[1])h.sc-=MOD[1];
		}
		else if(s[i]=='>'){
			p++;
		}
		else {
			p--;
		}
		hash[i]=h;
		loc[i]=p;
	}
	
	ll ret=0;
	map<P,ll> cnt;
	for(int i=n-1;i>=0;i--){
		P nex=hash[i];
		P dif=hash[n-1];
		dif.fr*=modpow(r[0],loc[i]+MOD[0]-1,0); dif.fr%=MOD[0];
		dif.sc*=modpow(r[1],loc[i]+MOD[1]-1,1); dif.sc%=MOD[1];
		nex.fr+=dif.fr; nex.fr%=MOD[0];
		nex.sc+=dif.sc; nex.sc%=MOD[1];
		ret+=cnt[nex];
		cnt[hash[i]]++;
	}
	cout<<ret+cnt[hash[n-1]]<<endl;
}



Measured memory_bytes: 37636
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#ifndef LOCAL
#define debug(x) ;
#else
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

template <typename T1, typename T2>
ostream &operator<<(ostream &out, const pair<T1, T2> &p) {
  out << "{" << p.first << ", " << p.second << "}";
  return out;
}

template <typename T>
ostream &operator<<(ostream &out, const vector<T> &v) {
  out << '{';
  for (const T &item : v) out << item << ", ";
  out << "\b\b}";
  return out;
}
#endif

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 200010


int main(){
  int a, b;

  cin >> a >> b;

  if(b%a == 0)
    cout << a + b << endl;
  else
    cout << b - a << endl;

  return 0;
}


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

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

int main(void)
{
	long a, b, ans;

	cin >> a >> b;

	ans = (a >= b ? gcd(a, b) : gcd(b, a));

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1164
class Dice
	def initialize(labels)
		@labels = labels
		@top    = labels[0]
		@front  = labels[1]
		@right  = labels[2]
		@left   = labels[3]
		@back   = labels[4]
		@bottom = labels[5]
	end
	attr_reader :top, :front, :right, :left, :back, :bottom

	def roll(op)
		case op
		when "E"
			@t      = @top
			@top    = @left
			@left   = @bottom
			@bottom = @right
			@right  = @t
		when "W"
			@t      = @top
			@top    = @right
			@right  = @bottom
			@bottom = @left
			@left   = @t
		when "N"
			@t      = @top
			@top    = @front
			@front  = @bottom
			@bottom = @back
			@back   = @t
		when "S"
			@t      = @top
			@top    = @back
			@back   = @bottom
			@bottom = @front
			@front  = @t
		when "R" # Roll around front and back
			@f      = @front
			@front  = @left
			@left   = @back
			@back   = @right
			@right  = @f 
		end
	end

	def same?(dice2)
		if dice2.top == @top && dice2.left == @left && dice2.front == @front &&
		   dice2.right == @right && dice2.back == @back && dice2.bottom == @bottom 
		   return true
		else
		   return false
		end
	end
end

def same_rolled?(dice1, dice2)
	for i in 0..3
		i.times{dice1.roll("E")}
		for j in 0..3
			j.times{dice1.roll("N")}
			for k in 0..3
				k.times{dice1.roll("W")}
				for l in 0..3
					l.times{dice1.roll("S")}
					return "Yes" if dice1.same?(dice2)
				end
			end
		end
	end
	return "No"
end

labels = gets.strip.split(" ").map{|i| i.to_i}
dice1 = Dice.new(labels)
labels = gets.strip.split(" ").map{|i| i.to_i}
dice2 = Dice.new(labels)

puts same_rolled?(dice1, dice2)


Measured memory_bytes: 6884
S = input()
T = input()
n = len(S)
m = len(T)
set_S = set(list(S))
for i in range(m):
    if T[i] not in set_S:
        print(-1)
        exit()

# 必ず再現できることが確定
res = [[n]*26 for _ in range(n+1)]
for i in reversed(range(n)):
    for j in range(26):
        res[i][j] = res[i+1][j]
    res[i][ord(S[i])-ord("a")] = i

# print(*res, sep="\n")
cnt = 0
tmp = 0
for i in range(m):
    # tmpがnに到達する or このループでは次の文字がもう現れないなら次のループに進む
    if tmp == n or res[tmp][ord(T[i])-ord("a")] == n:
        cnt += n
        tmp = 0
    tmp = res[tmp][ord(T[i])-ord("a")]  # T[i]が現れる場所がわかる
    tmp += 1  # 次の文字へ
cnt += tmp  # ループを抜ける直前でtmp+=1しているので0-indexとも辻褄が合う
print(cnt)


Measured memory_bytes: 37332