akhauriyash/Code-Regression huggingface dataset:
/*
created on 21/4/2020
*/
#include<bits/stdc++.h>
using namespace std;
#define Endl '\n'
typedef long long int lli;
void solve();
int main(int argc, char const *argv[]){
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  solve();
}
int const mxlen = 1e5 + 5;
int a[mxlen][3];
int dp[mxlen][3];
void solve(){
  int n;
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>a[i][0]>>a[i][1]>>a[i][2];
  }
  dp[0][0] = a[0][0];
  dp[0][1] = a[0][1];
  dp[0][2] = a[0][2];
 for(int i=1;i<n;i++){
   dp[i][0] = a[i][0] +max(dp[i-1][1], dp[i-1][2]);
   dp[i][1] = a[i][1] + max(dp[i-1][0], dp[i-1][2]);
   dp[i][2] = a[i][2] + max(dp[i-1][1], dp[i-1][0]);
 }
 int ans = max(dp[n-1][0], max(dp[n-1][1], dp[n-1][2]));
 cout<<ans<<Endl;
}


Measured memory_bytes: 2560
n,m=map(int,input().split())
MOD=10**9+7
def comb(n,k):
    if n<k:
        return 0
    if n<0 or k<0:
        return 0
    k=min(n-k,k)
    ans=1
    inv=[1]*(k+1)
    if k>=1:
        ans*=(n-k+1)%MOD
    for i in range(2,k+1):
        inv[i]=MOD-inv[MOD%i]*(MOD//i)%MOD
        ans=ans*(n-k+i)*inv[i]%MOD
    return ans

tmp=comb(n,2)+comb(m,2)
print(tmp)

Measured memory_bytes: 3064
import java.util.Arrays;
import java.util.Scanner;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n=sc.nextInt();
    long count=0;
    long[] a=new long[n],b=new long[n],c=new long[n];
    for(int i=0;i<n;i++)a[i]=sc.nextInt();
    for(int i=0;i<n;i++)b[i]=sc.nextInt();
    for(int i=0;i<n;i++)c[i]=sc.nextInt();
    Arrays.sort(a);
    Arrays.sort(b);
    Arrays.sort(c);
    for(int i=0;i<n;i++) {
    	long lc=n-B_search(c,b[i]+1);
    	long la=A_search(a,b[i])+1;
    	count+=lc*la;
    	//System.out.println(la+" "+lc);
    }
    System.out.println(count);
  }
  //okはv以上の最小index、ngはv未満の最大index。aに検索対象の配列、vに検索値を入れる。
	public static int B_search(long[] a,long v) {
		int ng=-1,ok=a.length;

		while(Math.abs(ok-ng)>1) {
			int mid=(ok+ng)/2;

			if(a[mid]>=v) ok=mid;
			else ng=mid;
		}
		return ok;
	}
	public static int A_search(long[] a,long v) {
		int ng=-1,ok=a.length;

		while(Math.abs(ok-ng)>1) {
			int mid=(ok+ng)/2;

			if(a[mid]>=v) ok=mid;
			else ng=mid;
		}
		return ng;
	}
}


Measured memory_bytes: 99308
#include <bits/stdc++.h>
#define FOR(i,a,b) for(ut i=(a);i<(int)(b);i++)
#define REP(i,b) FOR(i,0,b)
#define ALL(c) c.begin(),c.end()
#define PB push_back
#define cat //cout << __LINE__ << endl;
using namespace std;
typedef long long LL;
typedef double ld;
typedef int ut;
typedef vector<ut> VI;
typedef pair<ut,ut> pr;
typedef pair<ut,pr> ppr;
typedef vector<pr> Vpr;
typedef vector<ppr> Vppr;
typedef priority_queue<pr,Vpr,greater<pr> > PQ;
const int SIZE=2*1e5;
const int INF=1LL<<30;
const LL p=7+1e9;
const int rev=10000;
const int rev2=rev*2;
Vpr edges[SIZE];
int dist[SIZE];
ld nokori[SIZE];
LL V,E;
ld dfs(int now,ld nowflow){
	ld ans=0;
	if(now==V-1){
		return nowflow;
	}
	REP(i,edges[now].size()){
		int next=edges[now][i].first;
		int noko=edges[now][i].second;
		if(dist[next]!=dist[now]+1) continue;
		if(nokori[noko]==0) continue;
		ld inc=dfs(next,min(nokori[edges[now][i].second],nowflow));
		nowflow-=inc;
		nokori[noko]-=inc;
		nokori[(noko+rev)%rev2]+=inc;
		ans+=inc;
	}
	return ans;
}
int bfs(){
	queue<int> qu;
	dist[0]=0;
	qu.push(0);
	while(!qu.empty()){
		int now=qu.front();
		qu.pop();
		REP(i,edges[now].size()){
			int next=edges[now][i].first;
			ld noko=nokori[edges[now][i].second];
			if(noko>0 && dist[next]==INF){
				dist[next]=dist[now]+1;
				qu.push(next);
			}
		}
	}
	return dist[V-1];
}
ld dinic(){
	ld ans=0;
	while(true){
		int dists;
		REP(i,V) dist[i]=INF;
		dists=bfs();
		//cout << dists << endl;
		if(dists==INF) return ans;
		ans+=dfs(0,INF);	
		//cout << ans << endl;
	}

}
LL solve(){
	cin >> V >> E;
	LL s,t;
	ld c;
	REP(i,E){
		cin >> s >> t >> c;
		//if(c==1) c-=0.00001;
		nokori[i]=c;
		edges[s].PB(pr(t,i));
		edges[t].PB(pr(s,i+rev));
	}
	ld ans=dinic();
	return (int)ans;
}
int main(){
	int ans=solve();
	if(0 && ans>1e4){
		cout << -1 << endl;
	}
	else{
		cout << ans << endl;
	}
	return 0;
}

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

using ll = long long;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  ll n;
  cin >> n;
  
  vector<char> x(20, '#');
  int it = 0;
  while (n > 0) {
    x.at(it) = ((n - 1) % 26) + 'a';
    n--;
    n /= 26;
    it++;
  }
  
  for (int i = 19; i >= 0; i--) {
    if (x.at(i) == '#') continue;
    cout << x.at(i);
  }
  cout << '\n';
}

Measured memory_bytes: 3652
#include <iostream>
#include <map>
#include <algorithm>
using namespace std;
using llong = long long;

llong ans;
llong n;
llong d[200005];
llong sum[200005];
map<llong, llong> s2il;
map<llong, llong> s2ir;

int main() {
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> d[i];
    }

    s2il[0] = 0;
    for (int i = 1; i <= n; i++) {
        sum[i] = sum[i - 1] + d[i];
        
        s2ir[sum[i]] = i;
        if(s2il.count(sum[i]) == 0) {
            s2il[sum[i]] = i;
        }
    }

    for (int i = 1; i <= n; i++) {
        llong l1 = i - s2il[sum[i]];
        llong l2 = s2ir[sum[i]] - i;
        ans = max({ans, l1, l2});
    }

    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 31108
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n;
    cin >> n;
    vector<int> v(n);
    for (int i = 0; i < n; i++) cin >> v[i];
    int Q; cin >> Q;
    while (Q--) {
        int q, s, t; cin >> q >> s >> t;
        if (q == 0) {
            cout << *min_element(&v[s], &v[t]) << endl;
        } else {
            cout << *max_element(&v[s], &v[t]) << endl;
        }
    }
}


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

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

const int INT_INF = 2147483646;
const ll LL_INF = 9223372036854775807;


const int SIZE = 1e2+100;

ll h,w;
string s[SIZE];
ll cou[30];

int main(){
    cin >> h >> w;
    for(int i = 0; i < h; i++){
        cin >> s[i];
        for(int j = 0; j < s[i].length(); j++){
            ++cou[s[i][j]-'a'];
        }
    }
    int mm = h*w;

    int f = 0;
    if(h % 2 == 0 && w%2 == 0){
        int hitu = h*w/4;
        for(int i = 0; i < 30; i++){
            if(cou[i] % 4 != 0){
                f = 2;
                break;
            }
        }
        if(f != 2)  f = 1;
    }
    else if((h%2 == 0 && w%2 == 1) || (h%2 == 1 && w%2 == 0)){
        int ki,gu;
        if(h%2 == 1){
            ki = h;
            gu = w;
        }
        else{
            ki = w;
            gu = h;
        }
        int hitu_ni = gu/2;
        int hitu_yon = h*w-hitu_ni;

        int yon = 0, niko = 0;

        for(int i = 0; i < 30; i++){
            if(cou[i] %2 == 1){
                f = 2;
                break;
            }
            if(cou[i] % 4 == 0){
                ++yon;
            }
            else{
                ++niko;
            }
        }

        if(f == 0){
            if(niko <= hitu_ni){
                hitu_ni -= niko;
                if(hitu_ni%2 == 0)  f = 1;
            }
        }
    }
    else{
        int yon = 0, ichi = 0, niko = 0;
        int hitu_yon = (h*w-1-h+1-w+1)/4;
        int hitu_ni = (h-1+w-1)/2;

        for(int i = 0; i < 30; i++){
            if(cou[i] % 2 == 1){
                ++ichi;
            }
            else{
                if(cou[i] % 4 == 0){
                    ++yon;
                }
                else{
                    ++niko;
                }
            }
        }

        if(ichi == 1){
            if(niko <= hitu_ni){
                hitu_ni -= niko;
                if(hitu_ni%2 == 0)  f = 1;
            }
        }
    }

    if(f == 1){
        cout << "Yes\n";
    }
    else{
        cout << "No\n";
    }
}

Measured memory_bytes: 256
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define repLRE(i, l, r) for (ll i = (l); i <= (r); ++i)
#define rrepLRE(i, l, r) for (ll i = (l); i >= (r); --i)
#define Sort(v) sort(v.begin(), v.end())
#define rSort(v) sort(v.rbegin(), v.rend())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

ll dx[9] = {-1, 1, 0, 0, -1, -1, 1, 1, 0};
ll dy[9] = {0, 0, -1, 1, -1, 1, -1, 1, 0};

/* Macros reg. ends here */

const ll INF = 1LL << 50;

static const long long mod = 1000000007;

int main() {
  // ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cout << fixed << setprecision(15);

  string s;
  ll w;
  cin >> s >> w;

  string ans = "";
  for (ll i = 0; i < (ll)s.size(); i += w) {
    ans += s[i];
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
inputs = readlines

input=[]
for i in 1..inputs.size do
    input.push(inputs[i-1].split)
    input[i-1].map!(&:to_i)
end

a = input[0][0]
b = input[0][1]

coins = 0


if a > b
    coins = 2*a -1
elsif a == b
    coins = 2*a        
else
    coins = 2*b -1
end

p coins

Measured memory_bytes: 1788
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ll long long
#define lld long double
#define ALL(x) x.begin(), x.end()
using namespace std;

const ll MOD = 1000000000 + 7;

ll mpow(ll base, ll n)
{
    if (n == 0)
        return 1;
    ll prev = mpow(base, n / 2);
    if (n % 2 == 1)
    {
        return (prev * prev * base) % MOD;
    }
    else
    {
        return (prev * prev) % MOD;
    }
}

int main()
{
    ll n, k;
    cin >> n >> k;
    vector<ll> v(n);
    rep(i, n) cin >> v[i];
    vector<ll> num(n, 0);
    vector<ll> invnum(n, 0);
    vector<ll> smaller(n, 0);
    rep(i, n) rep(j, i + 1, n)
    {
        if (v[i] > v[j])
        {
            num[i]++;
            invnum[j]++;
        }
    }
    rep(i, n)
    {
        rep(j, n)
        {
            if (v[i] > v[j])
            {
                smaller[i]++;
            }
        }
    }
    ll ans = 0;
    rep(i, n)
    {
        //cerr << i << " " << num[i] << " " << smaller[i] << endl;
        ans += num[i] * k;
        ans %= MOD;
        ll tmp = smaller[i];
        tmp *= ((k - 1) * k / 2) % MOD;
        tmp %= MOD;
        assert(tmp >= 0);

        ans += tmp;
        ans %= MOD;
        assert(ans >= 0);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 384
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		String a = sc.next();
		String b = sc.next();
		String c = sc.next();

		char[] aList = a.toCharArray();
		char[] bList = b.toCharArray();
		char[] cList = c.toCharArray();

		int count = 0;
		for(int i = 0; i < n; i++) {
			char aChar = aList[i];
			char bChar = bList[i];
			char cChar = cList[i];

			if(aChar == bChar) {
				if(aChar == cChar) {
					// 3つ一緒なら変えない
				} else {
					// 2つ一緒なら1個変える
					count++;
				}
			} else if(aChar == cChar) {
				// 2つ一緒なら1個変える
				count++;

			} else if(bChar == cChar) {
				// 2つ一緒なら1個変える
				count++;

			} else {
				// 全部違ったら2つ変える
				count += 2;
			}

		}


		System.out.println(count);


	}

}


Measured memory_bytes: 23252
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace AtCoder
{
	public class ABC
	{
		static public void Main(string[] args)
		{
			Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
			Solve(args);
			Console.Out.Flush();
		}

		const int mod = 1000000007;  // 10^9+7
		static int Mod(long x, int m) { return (int)((x % m + m) % m); }
		static long Mod(long x, long m) { return (x % m + m) % m; }

		static public void Solve(string[] args)
		{
			//string s = Console.ReadLine();
			//int n = int.Parse(Console.ReadLine());
			//long x = long.Parse(Console.ReadLine());
			//int[] vs = Console.ReadLine().Split().Select(int.Parse).ToArray();
			//long[] vs = Console.ReadLine().Split().Select(long.Parse).ToArray();

			int a = int.Parse(Console.ReadLine());
			Console.WriteLine(a + a * a + a * a * a);

		}
	}
}


Measured memory_bytes: 27368
// C - Coloring Colorfully

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const ll MOD = 1e9 + 7;

int main() {
	string S;
	cin >> S;

	int cnt1 = 0;
	int cnt2 = 0;

	for (int i=0; i<S.size(); i++) {
		if (i % 2 == 0) {
			if (S[i] == '0') cnt1++;
			else cnt2++;
		} else {
			if (S[i] == '1') cnt1++;
			else cnt2++;
		}
	}

	int ans = min(cnt1, cnt2);

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3752
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;

char s[100005];
int n,cnt;
char c;

int main(void)
{
	cin>>n;
	scanf("%s",s);
	for (int i=0; i<=n-1; i++)
	{
		if (c!=s[i])
		{
			cnt++;
			c=s[i];
		}
	}
	cout<<cnt;
	return 0;
}

Measured memory_bytes: 384
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		
		String S = in.next();
		String T = in.next();
		int n = 0;
		
		String SArray[] = S.split("");
		String TArray[] = T.split("");
		
		for(int i = 0;i < SArray.length;i++) {
			if(!SArray[i].equals(TArray[i])) {
				n++;
			}
		}
		
		System.out.println(n);
	}
}

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

int main() {
  int n; cin >> n;
  vector<long long> a(n);
  for (auto& e : a) cin >> e;
  sort(a.begin(), a.end());
  int ans = 0;
  for (int i = 0; i < n - 2; i++) {
    for (int j = i + 1; j < n - 1; j++) {
      for (int k = j + 1; k < n; k++) {
        ans += ((a.at(i) + a.at(j)) > a.at(k)) && a.at(i) != a.at(j) && a.at(j) != a.at(k) && a.at(k) != a.at(i);
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3636
process.stdin.resume();
process.stdin.setEncoding("utf8");
process.stdin.on("data", function (chunk) {
    var input = chunk.trim().split("\n");
    var n = input.shift();
    var button = ["", ".,!? ", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"];
    button = button.map(function (key) {
        return key.split("");
    });
    for (var i = 0; i < n; i++) {
        var data = input[i].split("").map(Number);
        var message = "";
        var character = "";
        var count = 0;
        data.forEach(function (key) {
            if (key > 0) {
                character = button[key][count % button[key].length];
                count++;
            } else {
                message += character;
                character = "";
                count = 0;
            }
        });
        console.log(message);
    }
});

Measured memory_bytes: 17784
//07
#include<iostream>
#include<map>

using namespace std;

int main(){
  for(int n,s,w,q;cin>>n>>s>>w>>q,n|s|w|q;){
    int g=s;
    int a[100000];
    for(int i=0;i<n;i++){
      a[i]=g/7%10;
      g=g/2^(g%2?w:0);
    }
    int ans=0;
    if(q==2||q==5){
      int ac=0;
      for(int i=0;i<n;i++){
	ac+=a[i]!=0;
	if(a[i]%q==0){
	  ans+=ac;
	}
      }
    }else{
      map<int,int> m;
      m[0]=1;
      long long r=1;
      int c=0;
      for(int i=n-1;i>=0;i--){
	c=(c+r*a[i])%q;
	if(a[i]){
	  ans+=m[c];
	}
	m[c]++;
	r=(r*10)%q;
      }
    }
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 5804
N=int(input())
s=['']*N
t=[0]*N
for i in range(N):
    s[i],t[i]=input().split()
X=str(input())
switch=0
total=0
for i in range(N):
    if X==s[i]:
        switch=1
        total-=int(t[i])
    if switch==1:
        total+=int(t[i])
print(total)

Measured memory_bytes: 3064
import math
N, M = map(int,input().split())
ans = 0
# 偶数、偶数
if N >= 2:
    ans = math.factorial(N)/(2*math.factorial(N-2))
    
    # N*(N-1)/N
# 奇数、奇数
if M >= 2:
    ans += math.factorial(M)/(2*math.factorial(M-2))
print(int(ans))


Measured memory_bytes: 2940
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long[] a = new long[n];
        for(int i=0; i<n; i++) {
            a[i] = sc.nextLong();
        }

        int ans = 0;
        for(int i=0; i<n; i++) {
            while(i+1 < n && a[i] == a[i+1]) i++;
            if(i+1 < n && a[i] < a[i+1]) {
                while(i+1 < n && a[i] <= a[i+1]) i++;
            } else if(i+1 < n && a[i] > a[i+1]) {
                while(i+1 < n && a[i] >= a[i+1]) i++;
            }
            ans++;
        }
        System.out.println(ans);
    }
}


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

int main(void){
    int n;
    cin >> n;
    string c;
    cin >> c;
    
    ll ans = 0;
    ll r = 0,w = 0,r2 = 0,w2 = 0;
    rep(i,c.size()){
        if(c[i] == 'R')r++;
        else w++;
    }
    
    rep(i,c.size()){
        if(i < r){
            if(c[i] == 'W')w2++;
        } else {
            if(c[i] == 'R')r2++;
        }
    }
    ans = min(min(r,w),r2+w2);
    
    ll ans2 = min(r2,w2) + r2 - min(r2,w2) + w2 - min(r2,w2);
    
    cout << min(ans,ans2);
}

Measured memory_bytes: 3720
N = gets.chomp.to_i
str = gets.split
v = Array.new(N)
for i in 0...N do
    v[i] = str[i].to_f
end

v.sort!
a = (v[0] + v[1]) / 2.0
for i in 2...N do
    a = (a + v[i]) / 2.0
end

puts a

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

using i64=int64_t;

#define rep(i,x,y) for(i64 i=i64(x),i##_max_for_repmacro=i64(y); i<i##_max_for_repmacro; ++i)
#define debug(x) #x << "=" << (x)
 
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif
 
const int inf=1.01e9;
const i64 inf64=4.01e18;
const double eps=1e-9;
 
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
        os << v << ",";
    }
    os << "]";
    return os;
}

void solve(){
    i64 N;
    cin >> N;

    vector<i64> a(N),b(N);
    rep(i,0,N) cin >> a[i];
    rep(i,0,N) cin >> b[i];

    vector<vector<i64>> sorted(29,vector<i64>(N));
    rep(i,0,29){
        sorted[i]=b;
        rep(j,0,N) sorted[i][j]%=1<<(i+1);
        i64 mask=1<<(i+1);
        sort(begin(sorted[i]),end(sorted[i]));
    }

    i64 ans=0;
    rep(k,0,29){
        i64 x=1<<k,s=0;
        rep(i,0,N){
            i64 a_=a[i]%(x*2);
            s+=lower_bound(begin(sorted[k]),end(sorted[k]),2*x-a_)-lower_bound(begin(sorted[k]),end(sorted[k]),x-a_);
            s+=lower_bound(begin(sorted[k]),end(sorted[k]),4*x-a_)-lower_bound(begin(sorted[k]),end(sorted[k]),3*x-a_);
        }
        ans|=(s%2)<<k;
    }

    cout << ans << endl;
}

int main(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    solve();
    return 0;
}


Measured memory_bytes: 50788
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
#define EPS 1e-10
using namespace std;
typedef long long llong;

int main() {
	int n, m, a;
	while (cin >> n >> m >> a, a) {
		vector<vector<int> >v(1010, vector<int>(110,0));
		int h, p, q;
		int st = 0;
		for (int i = 0; i < m; i++) {
			cin >> h >> p >> q;
			v[h][p] = q;
			v[h][q] = p;
			st = max(st, h);
		}
		
		int x = a;

		for (int i = st; i > 0; i--) {
			if (v[i][x]) {
				x = v[i][x];
			}
		}
		cout << x << endl;

	}
	return 0;
}

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

int main() {
	int n;
	int a[1000];
	cin>>n;
	int i;
	for(i=0;i<n;i=i+1){
		cin>>a[i];
	}
	for(i=1;i<=n-1;i=i+1){
		cout<<a[n-i]<<" ";
	}
	cout<<a[0]<<endl;
	return 0;
}

Measured memory_bytes: 3072
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) debug(x) debug(y);
#define repn(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) for(int i = 0; i < (int)(a); i++)
#define all(v) v.begin(), v.end() 
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define sq(x) ((x) * (x))

template<class T> T gcd(T a, T b){ return ((b == 0) ? a : gcd(b, a % b)); }

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
	ll a, b, n;
	cin >> a >> b >> n;
	cout << ((a * min(n, b - 1)) / b + a * (min(n, (b - 1)) / b)) << endl;
	return 0;
}
/*
Things to look out for:
	- Integer overflows
	- Array bounds
	- Special cases
Be careful!
*/


Measured memory_bytes: 3648
#include <iostream>
#include <cstdio>
using namespace std;
#define MAX 2000000

int H, A[MAX + 1];

void maxHeapify(int i)
{
  int l, r, largest;
  l = 2 * i;
  r = 2 * i + 1;

  if (l <= H && A[l] > A[i])
    largest = l;
  else
    largest = i;
  if (r <= H && A[r] > A[largest])
    largest = r;

  if (largest != i)
  {
    swap(A[i], A[largest]);
    maxHeapify(largest);
  }
}

int main()
{
  scanf("%d", &H);
  for (int i = 1; i <= H; i++)
    scanf("%d", &A[i]);
  for (int i = H / 2; i >= 1; i--)
    maxHeapify(i);

  for (int i = 1; i <= H; i++)
  {
    printf(" %d", A[i]);
  }
  printf("\n");
  return 0;
}


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

using namespace std;

struct random_class {
	struct xorshift {
		using result_type = unsigned int;
		result_type x=123456789u,y=362436069u,z=521288629u,w;
		static constexpr result_type min() {return 0u;}
		static constexpr result_type max() {return UINT_MAX;}
		xorshift(result_type a) : w(a) {}
		result_type operator()() {
			result_type t;
			t = x ^ (x << 11);
			x = y; y = z; z = w;
			return w = (w ^ (w >> 19)) ^ (t ^ (t >> 8));
		}
	};
	random_device rd;
	xorshift xor128;
	random_class() : rd(), xor128(rd()) {}
	random_class(unsigned int seed) : rd(), xor128(seed) {}
	double make_random(double min_v, double max_v) { return uniform_real_distribution<double>(min_v, max_v)(xor128);}
};

random_class R;

template<class T>
struct Treap {
	struct node {
		T val;
		double pri;
		node *lch, *rch;
		int cnt;
		node(T v) : val(v), lch(nullptr), rch(nullptr), cnt(1) {
			pri = R.make_random(DBL_MIN, DBL_MAX);
		}
	};
	node* top;
	Treap(node* t = nullptr) : top(t) {}
	node* update(node* n) {
		n->cnt = count(n->lch) + count(n->rch) + 1;
		return n;
	}
	inline int count(node* n) {
		return !n ? 0 : n->cnt;
	}
	node* merge(node* l, node* r) {
		if (!l || !r) return !l ? r : l;
		if (l->pri > r->pri) {
			l->rch = merge(l->rch, r);
			return update(l);
		} else {
			r->lch = merge(l, r->lch);
			return update(r);
		}
	}
	pair<node*, node*> split(node* t, int k) {
		if (!t) return make_pair(nullptr, nullptr);
		if (k <= count(t->lch)) {
			pair<node*, node*> s = split(t->lch, k);
			t->lch = s.second;
			return make_pair(s.first, update(t));
		} else {
			pair<node*, node*> s = split(t->rch, k - count(t->lch) - 1);
			t->rch = s.first;
			return make_pair(update(t), s.second);
		}
	}
	void insert(const T&& val) {
		int pos = 0;
		node* n = top;
		while (n) {
			if (val < n->val) n = n->lch;
			else pos += count(n->lch) + 1, n = n->rch;
		}
		auto t = split(top, pos);
		n = merge(t.first, new node(val));
		top = update(merge(n, t.second));
	}
	void insert(const T& val) { insert((T&&) val);}
	const T& at(int idx) {
		node* n = top;
		for (int sz = count(n->lch) + 1; sz != idx + 1; sz = count(n->lch) + 1) {
			if (sz <= idx) idx -= sz, n = n->rch;
			else n = n->lch;
		}
		return n->val;
	}
	inline const int size() {
		return count(top);
	}
};

int main() {
	Treap<int> T;
	int N;
	cin >> N;
	vector<int> v;
	for (int i = 0; i < N; i++) {
		int t; cin >> t;
		t -= i;
		T.insert(t);
		v.push_back(t);
	}
	int b = T.at(N / 2);
	long long res = 0;
	for (auto x : v) {
		res += abs(x - b);
	}
	cout << res << endl;
}

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

#define ld long double
#define int long long
#define pii pair<int,int>
#define X first
#define Y second
#define mp make_pair
#define MOD 1000000007ll
#define inf 1000000000000000ll

using namespace std;

inline int binexp(int a,int b,int m)
{
	int res=1;
	a%=m;
	while(b)
	{
		if(b&1)
		{
			res=(res*1ll*a)%m;
		}
		a=(a*1ll*a)%m;
		b>>=1;
	}
	return res;
}

inline int digsum(int n)
{
	int ans=0;
	while(n)
	{
		ans+=n%10;
		n/=10;
	}
	return ans;
}

signed main()
{
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	int n,mn=inf;
	cin>>n;
	for(int i=1;i<n;i++)
	{
		int a=i,b=n-i;
		mn=min(mn,digsum(a)+digsum(b));
	}
	cout<<mn;
	return 0;
}  


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

int main()
{
  string S;
  cin >> S;
  
  int year, month, day;
  
  year = stoi(S.substr(0, 4));
  month = stoi(S.substr(5, 2));
  day = stoi(S.substr(8, 2));
  
  if(year > 2019)
  {
    cout << "TBD" << endl;
    return 0;
  }
  else if(year == 2019)
  {
    if(month > 4)
    {
      cout << "TBD" << endl;
      return 0;
    }
    else
    {
      cout << "Heisei" << endl;
      return 0;      
    }
  }
  else
  {
    cout << "Heisei" << endl;
    return 0;
  }
  
}

Measured memory_bytes: 256
// This amazing code is by Eric Sunli Chen.
#include<bits/stdc++.h>
using namespace std;
template<typename T> bool get_int(T &x)
{
	char t=getchar();
	bool neg=false;
	x=0;
	for(; (t>'9'||t<'0')&&t!='-'&&t!=EOF; t=getchar());
	if(t=='-')neg=true,t=getchar();if(t==EOF)return false;
	for(; t<='9'&&t>='0'; t=getchar())x=x*10+t-'0';
	if(neg)x=-x;return true;
}
template<typename T> void print_int(T x)
{
	if(x<0)putchar('-'),x=-x;
	short a[20]= {},sz=0;
	while(x>0)a[sz++]=x%10,x/=10;
	if(sz==0)putchar('0');
	for(int i=sz-1; i>=0; i--)putchar('0'+a[i]);
}
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define get1(a) get_int(a)
#define get2(a,b) (get1(a)&&get1(b))
#define get3(a,b,c) (get1(a)&&get2(b,c))
#define printendl(a) print_int(a),puts("")
typedef long long LL;
typedef unsigned long long uLL;
typedef pair<int,int> pii;
typedef vector<int> vi;
const int inf=0x3f3f3f3f;
const LL Linf=1ll<<61;
const double pi=acos(-1.0);

int main()
{
	LL n,a,b;
	cin>>n>>a>>b;
	if(a>b)swap(a,b);
	if(a%2==b%2)cout<<abs(b-a)/2<<endl;
	else cout<<min((a+b-1)/2,(n-a+1+n-b+1-1)/2)<<endl;
	return 0;
}

Measured memory_bytes: 256
s = input()
q = int(input())

cnt = 0
llst = []
rlst = []
for i in range(q):
  line = input()
  if line == '1':
    cnt += 1
  else:
    elems = line.split()
    if cnt % 2 == 0:
      # 指示通り追加
      if elems[1] == '1':
        llst.append(elems[2])
      else:
        rlst.append(elems[2])
    else:
      # 指示の向きと逆に追加
      if elems[1] == '1':
        rlst.append(elems[2])
      else:
        llst.append(elems[2])
        
if cnt % 2 == 0:
  res = ''.join(llst[::-1]) + s + ''.join(rlst)
  print(res)
else:
  res = ''.join(llst[::-1]) + s + ''.join(rlst)
  print(res[::-1])

Measured memory_bytes: 6384
import java.util.Scanner;

public class Main {

  static Scanner sc = new Scanner(System.in);


  public static void main(String[] args) {
    int a = sc.nextInt();
    int b = sc.nextInt();
    int c = sc.nextInt();
    String answer = "No";
    if (a + b >= c) {
      answer = "Yes";
    }
    System.out.println(answer);
  }
}


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

#define fi first
#define se second

const int N = 1000010;
const long long mod = 998244353;

using namespace std;


int main()
{
        //freopen("input.txt", "r", stdin);
        //freopen("output.txt", "w", stdout);

        ios_base::sync_with_stdio(0);

        long long n, a, b;
        cin >> n >> a >> b;
        if(a > b){
                swap(a, b);
        }
        if((a & 1) == (b & 1)){
                cout << (b - a) / 2 << "\n";
        } else{
                cout << (b - a) / 2 + min(a, n - b + 1) << "\n";
        }
}


Measured memory_bytes: 256
from collections import deque

S=input()
Q=int(input())

t=deque(S)
flag_r=0
for _ in range(Q):
    Query=input().split()
    if int(Query[0])==1:
        flag_r=(flag_r+1)%2
    elif int(Query[1])==1+flag_r:
        t.appendleft(Query[2])
    else:
        t.append(Query[2])
result=''.join(t)
if flag_r:# reverseは最後にやる
    result=result[::-1]
print(result)

Measured memory_bytes: 8820
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cstring>

using namespace std;

#define x first
#define y second
#define mp make_pair
#define pb push_back

typedef long long ll;

const ll MOD = 1e9+7;

int n;
int a[100005];

bool check() {
	int od = a[0];
	for (int i=1 ; i<n ; i++) od = __gcd(od, a[i]);
	bool ok = false;
	int br = 0;
	int pos = -1;
	for (int i=0 ; i<n ; i++) {
		br += a[i] % 2;
		if (a[i] % 2 and a[i]>od) pos = i;
		if (a[i] > od) ok = true;
	}
	if (!ok) return false;
	int par = n - br;
	if (par%2) return true;
	if (br > 1 or pos == -1) {
		return false;
	}
	a[pos]-=od;
	while (1) {
		bool con = true;
		for (int i=0 ; i<n ; i++) {
			a[i] /= 2;
			if (a[i]%2) con = false;
		}
		if (!con) break;
	}
	return !check();
}

int main() {
	scanf("%d", &n);
	for (int i=0 ; i<n ; i++) {
		scanf("%d", a+i);
	}
	if (n == 1) {
		if (a[0]%2) printf("Second\n");
		else printf("First\n");
		return 0;
	}
	if (n == 2) {
		if (abs(a[0] - a[1]) % 2) printf("First\n");
		else printf("Second\n");
		return 0;
	}
	if (check()) printf("First\n");
	else printf("Second\n");
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <numeric>
#include <set>
#include <cstdlib>
#include <queue>

using namespace std;

typedef long long llint;
typedef long double ld;
#define inf 1e18

priority_queue<int,vector<int>,greater<int>> que;


llint a,b,c,k;

void solve(){
	cin >> a >> b >> c >> k;
	if(k%2==0)cout << a-b << endl;
	else cout << b-a << endl;
}

int main(int argc, char *argv[]) {
  solve();
  return 0;
}


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

int main() {
	string s;
	cin >> s;
	bool flag;
	while (s.length() > 1) {
		flag = true;
		for (int i = 0; i < 2; i++) {
			s.pop_back();
		}
		for (int i = 0; i < s.length() / 2; i++) {
			if (s[i] != s[i + s.length()/2]) {
				flag = false;
				break;
			}
		}
		if (flag == true) {
			cout << s.length() << endl;
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second

const int mx=200010;
const ll mod=1e9+7;

 
int main(){
  int n,q;
  cin >> n >> q;
  vector<pair<int,pair<int,int>>> ev; //time type pos
  rep(i,n){
    int s,t,x; cin >> s >> t >> x; s-=x; t-=x;
    ev.push_back({s,{1,x}});
    ev.push_back({t,{-1,x}});
  }
  while(q--){
    int d; cin >> d;
    ev.push_back({d,{inf,0}});
  }
  sort(ev.begin(),ev.end()); 
  multiset<int> st;
  for(auto it:ev){
    if(it.S.F==1){
      st.insert(it.S.S);
    } else if(it.S.F==-1){
      st.erase(st.lower_bound(it.S.S));
    } else {
      if(!st.empty()){
        cout << *st.begin() << endl;
      } else {
        cout << -1 << endl;
      }
    }
  }
  return 0;
}


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

using namespace std;

bool correct(string s, int i, char bol){
    for(int j = i; j >= 0; --j){
        if(s[j] == bol){
            return false;
        }
    }
    return true;
}

string funk(string s){
    for(int i = s.size() - 1; i >= 0; --i){
        char bol = s[i];
        bool may = false;
        while(bol < 'z' && may == false){
            bol++;
            //cout << bol << i << endl;
            may = correct(s, i, bol);
        }
        if(may){
            string ans =  s.substr(0, i) + bol;
            return ans;
        }

    }
    return "-1";
}

int main()
{
    string s;
    cin >> s;
    if(s == "zyxwvutsrqponmlkjihgfedcba"){
        cout << -1;
        return 0;
    }
    set<char> se;
    char x = 'a';
    for(int i = 0; i < 26; ++i){
        se.insert(x);
        x++;
    }
    for(int i = 0; i < s.size(); ++i){
        se.erase(s[i]);
    }
    if(se.empty()){
            cout << funk(s);
        return 0;
    }

    cout << s << *se.lower_bound('a');
    return 0;
}


Measured memory_bytes: 256
use io::*;

fn main() {
    let input = read_string();
    let mut sc = Scanner::new(&input);
    let s = sc.next_vec_char();
    let n = s.len();
    let M = 1000000007;
    let mut va: Vec<usize> = vec![0;n+1];
    let mut vb: Vec<usize> = vec![0;n+1];
    let mut vc: Vec<usize> = vec![0;n+1];
    let mut tot: Vec<usize> = vec![1;n+1];
    for i in 0..n {
        if s[i] == 'A' {
            tot[i+1] = tot[i];
            va[i+1] = (va[i] + tot[i]) % M;
            vb[i+1] = vb[i];
            vc[i+1] = vc[i];
        } else if s[i] == 'B' {
            tot[i+1] = tot[i];
            va[i+1] = va[i];
            vb[i+1] = (vb[i] + va[i]) % M;
            vc[i+1] = vc[i];
        } else if s[i] == 'C' {
            tot[i+1] = tot[i];
            va[i+1] = va[i];
            vb[i+1] = vb[i];
            vc[i+1] = (vc[i] + vb[i]) % M;
        } else if s[i] == '?' {
            tot[i+1] = 3 * tot[i] % M;
            va[i+1] = (3 * va[i] + tot[i]) % M;
            vb[i+1] = (3 * vb[i] + va[i]) % M;
            vc[i+1] = (3 * vc[i] + vb[i]) % M;
        }
    }
    let ans = vc[n];
    println!("{}", ans);
}

pub mod io {
    use std;
    use std::str::FromStr;

    pub struct Scanner<'a> {
        iter: std::str::SplitWhitespace<'a>,
    }

    impl<'a> Scanner<'a> {
        pub fn new(s: &'a str) -> Scanner<'a> {
            Scanner {
                iter: s.split_whitespace(),
            }
        }

        pub fn next<T: FromStr>(&mut self) -> T {
            let s = self.iter.next().unwrap();
            if let Ok(v) = s.parse::<T>() {
                v
            } else {
                panic!("Parse error")
            }
        }

        pub fn next_vec_len<T: FromStr>(&mut self) -> Vec<T> {
            let n: usize = self.next();
            self.next_vec(n)
        }

        pub fn next_vec<T: FromStr>(&mut self, n: usize) -> Vec<T> {
            (0..n).map(|_| self.next()).collect()
        }

        pub fn next_mat<T: FromStr>(&mut self, w: usize, h: usize) -> Vec<Vec<T>> {
            (0..h).map(|_| self.next_vec(w)).collect()
        }

        pub fn next_vec_char(&mut self) -> Vec<char> {
            self.next::<String>().chars().collect()
        }

        pub fn next_mat_char(&mut self, n: usize) -> Vec<Vec<char>> {
            (0..n).map(|_| self.next_vec_char()).collect()
        }
    }

    pub fn read_string() -> String {
        use std::io::Read;

        let mut s = String::new();
        std::io::stdin().read_to_string(&mut s).unwrap();
        s
    }

    pub fn read_line() -> String {
        let mut s = String::new();
        std::io::stdin().read_line(&mut s).unwrap();
        s.trim_right().to_owned()
    }
}


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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,a,b) for(int i=(a);i<(b);i++)
#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second

using vint=vector<int>;
using pint=pair<int,int>;
using vpint=vector<pint>;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

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

template<class T>
ostream& operator<<(ostream& ost,const vector<T>&v){
    ost<<"{";
    for(int i=0;i<v.size();i++){
        if(i)ost<<",";
        ost<<v[i];
    }
    ost<<"}";
    return ost;
}

signed main(){
    string s;cin>>s;
    int ans=0;
    for(int i=0;i<s.size()-1-i;i++){
        if(s[i]!=s[s.size()-1-i])ans++;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<vector>
#include<string>
using namespace std;
#define l long long
#define pb push_back
#define mem(a,n) memset(a,n,sizeof(a))
#define find(v,n) find(v.begin(),v.end(),n)
#define sort1(v) sort(v.begin(),v.end())
#define lb(v,i,n) lower_bound(v.begin()+i,v.end(),n)
#define ub(v,n) upper_bound(v.begin(),v.end(),n)
#define mod 998244353
#define reverse(s) reverse(s.begin(),s.end())
//#define pi pair<l,l> 
const double pi=3.141592653589793;
bool isprime(l n)
{
	for(l i=2;i*i<=n;i++)
	{
		if(n%i==0)
			return false;
	}
	return true;
}
vector<l> fact(l n)
{
	vector<l> v;
	for(l i=1;i*i<=n;i++)
	{
		if(n%i==0)
		{
			v.pb(i);
		}
	}
	return v;
}
l power(l a,l b)
{
	l ans=1;
	while(b>0)
	{
		if(b&1)
		{
			ans=(ans*a)%mod;
		}
		b>>=1;
		a=(a%mod*a%mod)%mod;
	}
	return ans;
}//prefixsums
void frooty()
{
	l x,n;
	cin>>x>>n;
	vector<l> v;
	for(l i=0;i<n;i++)
	{
		l a;
		cin>>a;
		v.pb(a);
	}
	sort1(v);
	l pos=-1;
	for(l i=0;i<n;i++)
	{
		if(x==v[i])
		{
			pos=i;
			break;
		}
	}
	if(pos==-1)
	{
		cout<<x<<"\n";
		return ;
	}
	l temp=pos;
	l val=x;
	l minn=LLONG_MAX;
	l ans=INT_MAX;
	l ans2=INT_MAX;
	while(temp<n&&v[temp]==val)
	{
		temp++;
		val++;
	}
	if(temp==n)
	{
		ans=v[n-1]+1;
	}
	else
		ans=val;
	temp=pos;
	val=x;
	while(temp>=0&&v[temp]==val)
	{
		temp--;
		val--;
	}
	if(temp<0)
	{
		ans2=v[0]-1;
	}
	else
		ans2=val;
	if(x-ans2<=ans-x)
		cout<<ans2<<"\n";
	else
		cout<<ans<<"\n";
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int q=1;
	//cin>>q;
	while(q--)
	{
		frooty();
	}
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
#define pb push_back
#define ld long double
#define f first
#define s second
#define in insert
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int INF = 1e18 + 5;
const int mod = 1e9 + 7;
const int  N = 2e5 + 314;
const long double pi = 3.1415926535897932384626433832795;
void solve(){
	int n;
	cin>>n;
	vi v(n),a(n);
	for(int i = 0; i < n; i++)cin>>v[i];
	sort(all(v));
	reverse(all(v));
	int x = v[0];
	for(int i = 1; i < n; i++){
		if(v[0]%v[i])x=x/__gcd(x, v[i])*v[i];
	}
	cout<<x;
}
signed main(){
	speed;
	int t=1;
	//cin>>t;
	while(t--)solve();
}

Measured memory_bytes: 3620
// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
// #define main int main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vpii = vector<pii>;
using vvi = vector<vi>;
using vvb = vector<vb>;
using vvpii = vector<vpii>;
template<typename A> using fn = function<A>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int &n) { return n & 1; }
constexpr bool even(const int &n) { return !odd(n); }
template<typename V> constexpr typename V::value_type sum(const V &v) { return accumulate(all(v), 0); }
void solve();
main { solve(); return 0; }
// clang-format on

void solve() {
  int x;
  stack<int> s;
  queue<int> q;
  while (cin >> x) {
    if (x == 0) {
      q.push(s.top());
      s.pop();
    } else {
      s.push(x);
    }
  }
  for (; q.size(); q.pop()) cout << q.front() << endl;
}

Measured memory_bytes: 3052
#include <iostream>
#include <cassert>
#include <algorithm>
#include <cstdlib>
#include <cstdio>
#include <vector>
#include <set>
#include <map>
#include <iomanip>
#include <math.h>
#include <unordered_map>
#include <unordered_set>
#include <queue>

#define REP(i, n) for (int i = 0; i < n; ++i)
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define DB(x) cerr << #x << ": " << x << endl;
#define pb push_back
#define mp make_pair
#define fi first
#define se second

using namespace std;

typedef long long LL;
typedef long double LD;

const int MAXN = 100000;
const int MOD = 1000 * 1000 * 1000 + 7;

void solve();

int main()
{
    auto start = clock();
    cout.sync_with_stdio(0);
    cin.tie(0);
    cout.precision(10);
    cout << fixed;

#ifdef HOME
    freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
#endif

    int t = 1;
    //cin >> t;
    while (t--) {
        solve();
    }

    cerr << "\nTime: " << (clock() - start) / 1.0 / CLOCKS_PER_SEC << "\n";

    return 0;
}

void solve()
{
    string s;
    cin >> s;
    vector<char> has(256, false);
    for (char c : s) {
        has[c] = true;
    }
    if (has['N'] xor has['S']) {
        cout << "No" << endl;
        return;
    }
    if (has['W'] xor has['E']) {
        cout << "No" << endl;
        return;
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rrep(i,n) for (int i = n-1; i >= 0; i--)
#define rep2(i,s,n) for (int i = s; i < n; ++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define tmax(a,b,c) max(a,max(b,c))
#define tmin(a,b,c) min(a,min(b,c))
#define pb push_back
using namespace std;
using ll = long long;
using P = pair<int,int>;
using LP = pair<ll,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;}
const int inf = 1001001001;
const ll linf = 1001001001001001001;
const int dx[4] = {0,1,0,-1};
const int dy[4] = {1,0,-1,0};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int h,w;
    cin >> h >> w;
    vector<string> a(h);
    rep(i,h) cin >> a[i];
    vector<vector<int>> dist(h,vector<int>(w,0));
    int sh,sw;
    rep(i,h) rep(j,w) if(a[i][j] == '#') {
        sh = i;
        sw = j;
        break;
    }
    deque<P> q;
    q.emplace_back(sh,sw);
    vector<vector<bool>> seen(h,vector<bool>(w,false));
    auto add = [&](int nh,int nw,int d) {
        if(nh < 0 || nh >= h || nw < 0 || nw >= w) return;
        if(a[nh][nw] == '#') {
            if(seen[nh][nw]) return;
            q.emplace_front(nh,nw);
        } else {
            if(dist[nh][nw] != 0 && dist[nh][nw] <= d) return;
            dist[nh][nw] = d;
            q.emplace_back(nh,nw);
        }
    };
    while(!q.empty()) {
        int nh = q.front().first;
        int nw = q.front().second;
        q.pop_front();
        seen[nh][nw] = true;
        rep(i,4) {
            int ch = nh+dx[i];
            int cw = nw+dy[i];
            add(ch,cw,dist[nh][nw]+1);
        }
    }
//    rep(i,h) {
//        rep(j,w) cout << dist[i][j];
//        cout << endl;
//    }
    int ans = 0;
    rep(i,h) rep(j,w) chmax(ans,dist[i][j]);
    cout << ans << endl;
}


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

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll X, K, D;
    cin >> X >> K >> D;

    if(X < 0) X *= -1;
    ll cnt = X / D;
    if(cnt > K)
    {
        cout << X - K * D << endl;
    }
    else
    {
        X = X - cnt * D;
        K -= cnt;
        if(K%2==0) cout << X << endl;
        else cout << -X + D << endl;
    }
    

    return 0;
}


Measured memory_bytes: 3632
#if defined(__GNUC__)
#include <bits/stdc++.h>
#define __int32 __int32_t
// __GNUC__
#else
#include "bits/stdc++.h"
#endif
using namespace std;

#define int long long

#define itn __int32
#define REP(i, n) for(itn (i) = 0; (i) < (n); ++(i))
#define REP2(i, x, n) for(itn (i) = x; (i) < (n); ++(i))
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define SORT(x) std::sort(ALL(x))
#define RSORT(x) std::sort(ALL(x), greater<decltype(x)::value_type>())
#define RSORT2(x, T) std::sort(ALL(x), greater<T>())
#define REVERCE(x) std::reverce(ALL(x))
#define ACM(x, y) std::accumulate(ALL(x), y)

#define INT_POW(x, y) [](int a, int b) -> int {int c = a; REP(i, b - 1){c *= a;} return c;}(x, y)
#define INT_POWM(x, y, m) [](int a, int b, int m) -> int {int c = a; REP(i, b - 1){c *= a; c %= m;} return c;}(x, y, m)
#define FCT(x) [](int a) -> int {int r = 1; REP(i, a){r *= i;} return r;}(x)

struct vertex
{
	int next;
	int cost;
	bool visit = false;
};

itn main() {
	std::ios::sync_with_stdio(false);

	int k;

	cin >> k;

	vector<vector<vertex>> grp(k);

	REP(i, k) {
		grp[i].push_back(vertex{ (i + 1) % k, 1 });
		grp[i].push_back(vertex{ (i * 10) % k, 0 });
	}

	deque<pair<int , int>> q;

	q.push_front(pair<int, int>(1, 0));

	int res = 1e9;

	while (!q.empty()) {
		auto d = q.front();
		q.pop_front();

		for (auto &v : grp[d.first]) {
			if (!v.visit) {
				if (v.next) {
					if (v.cost) {
						q.push_back(pair<int, int>(v.next, d.second + 1));
					}
					else {
						q.push_front(pair<int, int>(v.next, d.second));
					}
				}
				else {
					if (v.cost) {
						res = min(res, d.second + 2);
					}
					else {
						res = min(res, d.second + 1);
					}
				}
			}
			v.visit = true;
		}
	}

	cout << res;

	return 0;
}


Measured memory_bytes: 10496
import java.io.*;
public class Main {
    public static void main(String[] args) {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        String line;
        int x;
        try{
        line = reader.readLine();
        x = Integer.parseInt(line);
        x=x*x*x;
        System.out.println(x);
        }catch (NumberFormatException e) {
            System.out.println(e);
        } catch (IOException e) {
            System.out.println(e);
        }

    
    }
}



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

int main(void) {
    char N[5];
    cin >> N;

    if(N[0] == N[1] && N[1] == N[2]) cout << "Yes" << endl;
    else if (N[1] == N[2] && N[2] == N[3]) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

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

using namespace std;

int main()
{
	int X, Y, Z;
	int ans = 1;
	cin >> X >> Y >> Z;

	while (ans * Y + (ans + 1) * Z <= X)
	{
		ans++;
	}
	ans--;

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<utility>
#include<limits>

int main(){
  	int n,h;
  	std::cin>>n>>h;
  	std::vector<std::pair<int,int>> damages(n);
  	int Ma=-1;
  	int num_throw=0;
  	for(auto&damage : damages){
      	std::cin >> damage.first >> damage.second;
      	Ma = std::max(damage.first, Ma);
    }
  	std::sort(damages.begin(),damages.end(),[](auto &&a, auto&&b)->bool{ return a.second > b.second; });
  	for(auto&damage : damages){
      	if(damage.second > Ma){
          	num_throw++;
          	h-=damage.second;
          	if(h <= 0){ std::cout << num_throw << "\n"; return 0;}
        }
    }
  	std::cout << num_throw + int(h/Ma) + ((h%Ma>0)? 1: 0) << "\n";
  	return 0;
}

Measured memory_bytes: 3608