akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int main() {
  int k,n; cin >> k >> n;
  
  vector<int> houses(n);
  for(int i = 0; i < n; i++) {
    cin >> houses.at(i);
  }
  
  int longest = 0;
  int ans = 0;
  for(int i = 1; i <= n; i++) {
   int distance;
   if(i == n) {
     distance = k - houses.at(i-1) + houses.at(0);
   } else {
     distance = houses.at(i) - houses.at(i-1);
   }
    if(longest < distance) {
      longest = distance;
    }
    ans += distance;
  }
 
  cout << ans - longest << endl;
  
  return 0; 
}

Measured memory_bytes: 4048
import itertools
n,m,q = map(int,input().split())
a = [0] * q
b = [0] * q
c = [0] * q
d = [0] * q
for i in range(q):
    a[i],b[i],c[i],d[i] = map(int,input().split())
ans = 0

for li in itertools.combinations_with_replacement(range(1,m+1),n):
    sum_d = 0
    for i in range(q):
        if li[b[i]-1]-li[a[i]-1] == c[i]:
            sum_d+=d[i]
    if sum_d > ans:
        ans = sum_d
print(ans)

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

struct UnionFind
{
    vector<int> par;
    vector<int> size;
    int node_num;

    UnionFind(int n)
    {
        node_num = n;

        for (auto i = 0; i < node_num; i++)
        {
            par.push_back(i);
            size.push_back(1);
        }
    }

    int getSize(int x)
    {
        return size[root(x)];
    }

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

    void unite(int x, int y)
    {
        int rx = root(x);
        int ry = root(y);
        if (rx == ry)
        {
            return;
        }
        else
        {
            par[rx] = ry;
        }
        size[ry] += size[rx];
    }

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

int main()
{
    long long n, m;
    cin >> n >> m;

    int edges[m][2];
    UnionFind uf(n);
    for (auto i = 0; i < m; i++)
    {
        int a, b;
        cin >> a >> b;
        edges[i][0] = a - 1;
        edges[i][1] = b - 1;
    }

    long long ans[m];
    ans[m - 1] = n * (n - 1) / 2;

    for (auto i = m - 1; i > 0; i--)
    {
        int u = edges[i][0];
        int v = edges[i][1];

        if (!uf.same(u, v))
        {
            ans[i - 1] = ans[i] - uf.getSize(u) * uf.getSize(v);
            uf.unite(u, v);
        }
        else
        {
            ans[i - 1] = ans[i];
        }
    }

    for (auto i = 0; i<m; i++)
    {
        cout << ans[i] << endl;
    }
}

Measured memory_bytes: 3828
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)

using namespace std;
typedef long long int lli;

int main() {
	int N, K;
	cin >> N >> K;
	int ans = 1;
		rep(i, N) {
		if (ans <= K) ans *= 2;
		else ans += K;
	}
	cout << ans;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
#define pb push_back
#define pii pair < int , int >
#define F first
#define S second
#define endl '\n'
#define int long long
#define sync ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#define kill(x) return cout<<x<<'\n', 0;
using namespace std;
const int N=305,mod=998244353;
ll dp[N][N][N][2];
ll par[N][N][N];
int32_t main(){
    ll n;
    cin >> n;
    ll z=__gcd(n,(ll)360);
    ll a=n*360/z;
    cout << a/n << endl;
}


Measured memory_bytes: 3628
a,b,c,d,e,f=map(int,input().split())
w=set()
for i in range(0,f,100*a):
    for j in range(0,f,100*b):
        if i+j<=f:
            w.add(i+j)
        else:
            break
s=set()
for i in range(0,f,c):
    for j in range(0,f,d):
        if i+j<=f:
            s.add(i+j)
        else:
            break
n=100*a
m=0
l=0
for x in w:
    for t in s:
        if x+t!=0 and x+t<=f and 100*t<=e*x and t/(x+t)>l:
            n=x+t
            m=t
            l=t/(x+t)
print(n,m)


Measured memory_bytes: 9188
N, A, B = map(int, input().split())

result = 0

if A == B:
    print(0)
    exit()

if A > B:
    A, B = B, A

if abs(A - B) % 2 != 0:
    a1 = N - A if N - A < A else A - 1
    b1 = N - B if N - B < B else B - 1
    if a1 < b1:
        B -= A
        result += A
        A = 1
    else:
        A += b1 + 1
        result += b1 + 1
        B = N

if A != B:
    result += abs(A - B) // 2

print(result)

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

#define taskname ""
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define for0(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

using namespace std;

typedef long long ll;
typedef long double ld;
typedef complex <ld> cd;
typedef vector <cd> vcd;
typedef vector <int> vi;

template<class T> using v2d = vector <vector <T> >;
template<class T> bool uin(T &a, T b)
{
    return a > b ? (a = b, true) : false;
}
template<class T> bool uax(T &a, T b)
{
    return a < b ? (a = b, true) : false;
}

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

const int maxN = 4e3 + 10;

int n, fr[256];
char s[maxN];
ll ans = 0;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> n >> (s + 1);
    for1(i, n - 2)
    {
        fr['R'] = fr['G'] = fr['B'] = 0;
        ++fr[s[i + 1]];
        fore(j, i + 2, n)
        {
            if (s[i] != s[j])
            {
                char t = s[i] ^ s[j] ^ 'R' ^ 'G' ^ 'B';
                ans += fr[t];
                if ((i + j) % 2 == 0 && s[(i + j) / 2] == t)
                {
                    --ans;
                }
            }
            ++fr[s[j]];
        }
    }
    cout << ans;
    return 0;
}


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

using namespace std;
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define MAXN 201010
typedef long long int ll;
typedef pair<int, int> pii;

int main(){
	string s, t;
	cin >> s >> t;
	
	int sz = s.size();
	for (int i = 0; i < sz+1; i++)
	{
		//~ cout << s << endl;
		if(s == t){
			cout << "Yes\n";
			return 0;
		}
		int c = s[sz - 1];
		s.erase(--(s.end()));
		s.insert(s.begin(), c);
	}
	cout << "No\n";
	
	
	return 0;
}


Measured memory_bytes: 256
use proconio::{fastout, input, marker::Chars};

#[fastout]
fn main() {
    input!(s: Chars);

    let sss = vec!['A', 'C', 'G', 'T'];

    let mut count = 0;
    let mut count_max = 0;
    for v in &s {
        if sss.contains(v) {
            count += 1;
        } else {
            count_max = std::cmp::max(count_max, count);
            count = 0;
        }
    }
    count_max = std::cmp::max(count_max, count);

    println!("{}", count_max);
}


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

int main()
{
    string s;
    cin >> s;
    char flag = '0';
    char color = '0';
    int temp = 0;

    for (int i = 0; i < s.length(); i++) {
        color = (char)s[i];

        if (flag == color) temp += 1;

        if (flag == '1') flag = '0';
        else flag = '1';
    }

    int alt = s.length() - temp;
    cout << min(temp, alt) << endl;

    return 0;
}


Measured memory_bytes: 512
N, T = gets.split(" ").map{|s| s.to_i}
a = gets.split(" ").map{|s| s.to_i}
sum = 0
class Hoge
    def self.min(a,b)
       if a > b
          b
       else
          a
       end
    end
end

(N-1).times do |i|
  sum += Hoge.min(T, a[i+1]-a[i])
end
sum += T
puts sum

Measured memory_bytes: 16004
#include<iostream>
using namespace std;
int main(){
    long n,ans=0;
    cin>>n;
    long a[n],b[n];
    for(int i=0;i<n;i++)cin>>a[i]>>b[i];
    for(int i=n-1;i>=0;i--,a[i]+=ans)ans+=(b[i]-a[i]%b[i])%b[i];
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1792
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        for (;;) {
            int n = sc.nextInt();
            if (n == 0) {
                break;
            }
            int[] l = new int[10];
            while (n-- > 0) {
                l[sc.nextInt()]++;
            }
            for (int i : l) {
                    for (int j = 0; j < i; j++) {
                        System.out.print("*");
                    }
                System.out.println(i==0?"-":"");
            }
        }
    }
}


Measured memory_bytes: 60644
/*
关于点分治的层数，有一个经典的转化方法：将点分治的层数看成点的编号，那么任意两个编号相等的不同点之间一定有一个编号小于它们的点
这里为了方便，可以把点的编号看作max层数 - 点的层数，叶子的编号是0，根的编号是max层数
那么任意两个编号相等的不同点之间一定有一个编号大于它们的点
直接点分治一定是一个合法的方案，故答案是O(log N)级别的
考虑直接从叶子到根贪心决策每个点的编号，在树上dfs，对于每个x，记录子树中是否有编号为x的点，满足其到子树的根的路径上没有编号大于x的点
对于当前点的编号，只要找到满足以其为lca的路径均合法的最小编号即可
（当前点的所有儿子的子树中所有的路径均合法，以其为lca的路径也合法，就可以保证当前点的子树中的所有路径均合法）
*/

#include <cstdio>
#include <algorithm>

using namespace std;

void Get_Val(int &Ret)
{
	Ret = 0;
	char ch;
	while (ch = getchar(), ch > '9' || ch < '0')
		;
	do
	{
		(Ret *= 10) += ch - '0';
	}
	while (ch = getchar(), ch >= '0' && ch <= '9');
}

const int Max_N(100050);

int N, Head[Max_N], Total, To[Max_N << 1], Next[Max_N << 1], Val[Max_N];

inline void Add_Edge(const int &s, const int &t)
{
	++Total, To[Total] = t, Next[Total] = Head[s], Head[s] = Total;
}

void init()
{
	Get_Val(N);
	for (int i = 1, u, v;i != N;++i)
		Get_Val(u), Get_Val(v), Add_Edge(u, v), Add_Edge(v, u);
}

int Ans;

void dfs(const int &u, const int &fa)
{
	int All(0), Lca(0);
	for (int i = Head[u], v;i;i = Next[i])
		if ((v = To[i]) != fa)
		{
			dfs(v, u);
			Lca |= (All & Val[v]);
			All |= Val[v];
		}
	for (int x = 0;;++x)
	{
		if (x - 1 >= 0)
			if (Lca & (1 << (x - 1)))
				Lca ^= (1 << (x - 1));
		if (Lca == 0 && (All & (1 << x)) == 0)
		{
			Val[u] = (All | (1 << x));
			for (int j = 0;j <= x - 1;++j)
				if (Val[u] & (1 << j))
					Val[u] ^= (1 << j);
			Ans = max(Ans, x);
			break;
		}
	}
}

int main()
{
	init();
	dfs(1, -1);
	printf("%d", Ans);
	return 0;
}

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

int main() {
  
  int64_t A, B, K; cin >> A >> B >> K;
  
  vector<int64_t> vec(0);
  
  for (int64_t i = A; i <= min(A + K - 1, B); i++) vec.push_back(i);
  
  for (int64_t i = max(A, B - K + 1); i <= B; i++) {
    bool flag = true;
    for (int j = 0; j < vec.size(); j++) {
      if (vec.at(j) == i) flag = false;
    }
    if (flag) vec.push_back(i);
  }
  
  for (int64_t x : vec) cout << x << endl;
  
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
using namespace std;
long long arr[100010];
int main() {
    long long sum = 1;
    long long n;
    cin >> n;
    long long max = pow(10, 18);
    for (int i = 0; i < n; i++) {
        cin >> arr[i];   
    }
    for (int i = 0; i < n; i++) {
        if (arr[i] == 0) {
            cout << 0 << endl;
            return 0;
        }
    }
    for (int i = 0; i < n; i++) {
        if (arr[i] <= max/sum) {
            sum *= arr[i];
        }
        else {
           cout << -1 << endl;
           return 0;
        }
    }
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 4392
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
const ll MOD=1e9+7;
ll powmod(ll a, ll k){
    ll ap=a, ans=1;
    while(k){
        if(k&1){
            ans*=ap;
            ans%=MOD;
        }
        ap=ap*ap;
        ap%=MOD;
        k>>=1;
    }
    return ans;
}
int main()
{
	int n; cin>>n;
	map<P, P> mp;
	ll ans=0;
	for(int i=0; i<n; i++){
		ll a0, b0; cin>>a0>>b0;
		if(a0==0 && b0==0){
			ans++;
			continue;
		}
		ll g=gcd(abs(a0), abs(b0));
		a0/=g, b0/=g;
		if(b0<0) a0=-a0, b0=-b0;
		if(b0==0 && a0<0) a0=-a0;
		if(a0>0) mp[{a0, b0}].first++;
		else mp[{b0, -a0}].second++;
	}
	ll ans1=1;
	for(auto p:mp){
		ll x=p.second.first, y=p.second.second;
		(ans1*=(powmod(2, x)+powmod(2, y)-1))%=MOD;
	}
	cout<<(ans+ans1+MOD-1)%MOD<<endl;
	return 0;
}

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

int main(){
    int in[6];
    for(int i=0; i<6; i++){
        cin>>in[i];
    }
    if(in[4]-in[0]<=in[5]){
        cout<<"Yay!"<<endl;
    }
    else{
        cout<<":("<<endl;
    }
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,c) for(int i=0;i<c;++i)
int main(){
 string s,t;
 cin >> s >> t;
 int count = 0;
 int i;
 rep(i,3)
 if(s[i]==t[i]){
     count ++;
 }
 cout << count << endl;
return 0;
}

Measured memory_bytes: 256
import kotlin.math.ceil

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

fun main() {
    val n = readInt()
    println(ceil(n.toDouble()/2).toInt())
}

Measured memory_bytes: 34600
#include <cstdio>
#include <string>
using namespace std;

int main(){
	string target;
	char tmp[11];
	scanf("%s", tmp);
	target = tmp;
	int targetsize = target.size();

	int n;
	scanf("%d", &n);
	int numberoffind = 0;
	for (int i=0; i<n; i++){
		string ring;
		char tmp[11];
		scanf("%s", tmp);
		ring = tmp;

		ring = ring + ring.substr(0, target.size() - 1);
		if ( (int)ring.find(target) != -1 ){
			numberoffind++;
		}
	}
	printf("%d\n", numberoffind);

	return 0;
}

Measured memory_bytes: 1076
#pragma warning (disable:4996)
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
using namespace std;
typedef long long ll;

int main()
{
	string S;
	ll w;
	cin >> S >> w;
	string Z;
	for (ll i = 0; w*i<S.size(); i++)
	{
		Z.push_back(S[w * i]);
	}
	cout << Z << endl;
	return 0;
}

Measured memory_bytes: 256
import sys
from collections import Counter
from operator import itemgetter, attrgetter
n=0
 
n = input()
d_list= list(map(int, input().split()))
cou=sorted(Counter(d_list).most_common())
total=len(d_list)
# print(n)
# print(cou)
# print(total)
index=0
before=0
after=0
first=True
t=0
for c in cou:
#     print(c)
    if first:
        before = c
        first=False
    else:
        before = cou[index-1]
    after = c
    t+=c[1]
    if t > total/2:
        break
    index+=1
# print(before)
# print(after)
# print(len(cou[index:]))
if not(sum(n for _, n in cou[index:]) == sum(n for _, n in cou[:index])):
    print(0)
else:
    print(after[0]-before[0])

Measured memory_bytes: 16088
package main

import (
	"fmt"
	"math"
	"sort"
)

func main() {
	var n int

	fmt.Scan(&n)

	s := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&s[i])
	}

	t := make([]int, n)
	for j, x := range s {
		k := 0
		for {
			if x%int(math.Pow(2, float64(k+1))) == 0 {
				k++
			} else {
				break
			}
		}
		t[j] = k
	}
	sort.Ints(t)

	fmt.Println(t[0])
}


Measured memory_bytes: 1852
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
#define sz(x) int(x.size())
typedef long long ll;
typedef pair<int,int> P;

int main(){ 
  ll a, b, x;
  cin >> a >> b >> x;
  if (a == 0) {
    cout << b / x + 1 << endl;
  } else {
    cout << b/x - (a-1)/x << endl;
  }
  return 0;
} 

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define stpn setprecision
using namespace std;
typedef long long ll;
int a,b,c,num[10],i;
int main()
{
	cin>>a>>b>>c;
	num[a]++;
	num[b]++;
	num[c]++;
	for (i=1;i<=9;i++)
	if (num[i]==2)
	{
		cout<<"Yes";
		return 0;
	 } 
	 cout<<"No";
	return 0;
}


Measured memory_bytes: 256
def solve():
    n = input()
    l = list(map(int, input().split()))
    a = l.pop()
    for b in l:
        a = gcd(a,int(b))
    return a

def gcd(a,b):
    a,b = max(a,b), min(a,b)
    while b!=0:
        a,b = b,a%b
    return a

if __name__ == '__main__':
    print(solve())

Measured memory_bytes: 14252
#include<bits/stdc++.h>
using namespace std;
 
int main()
{
    int n,w;
    cin>>n>>w;
    
    int a[n][2];
    for(int i=0;i<n;i++)
    {
        cin>>a[i][0];
        cin>>a[i][1];
    }
    
    long long int dp[n+1][w+1];
    
    for(int i=0;i<=n;i++)
    {
        for(int j=0;j<=w;j++)
        {
            if(i==0 || j==0)
            {
                dp[i][j]=0;
            }
            
            else if(a[i-1][0]<=j)
            {
                dp[i][j] = max(dp[i-1][j], a[i-1][1] + dp[i-1][j-a[i-1][0]]);
            }
            
            else
            {
                dp[i][j] = dp[i-1][j];
            }
        }
    }

    cout<<dp[n][w];
    
    return 0;
}

Measured memory_bytes: 82432
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define RFOR(i, a, b) for (int i = (a); i >= (b); i--)
#define LFOR(i, a, b) for (long long int i = (a); i <= (b); i++)
#define LRFOR(i, a, b) for (long long int i = (a); i >= (b); i--)
#define MOD 1000000007
#define INF 1000000000           // 2000000000
#define LINF 1000000000000000000 // 9000000000000000000
#define DINF 1000000000000000.0
#define PI 3.14159265358979

//.size()はunsigned int　0-1をするとオーバーフローする

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

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

int main(void) {
    int n;
    int count=0;

    cin>>n;

    FOR(i,1,n){
        if(i<=9){
            count++;
        }else if(i>=100&&i<=999){
            count++;
        }else if(i>=10000&&i<=99999){
            count++;
        }
    }
    cout<<count<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include<cmath>
using namespace std;
void arraycout(int *arrayy,int n){
    for(int u=0;u<n;u++){//出力
        if(u==n-1){
            cout<<arrayy[u]<<endl;
        }else{
            cout<<arrayy[u]<<' ';
        }
    }
    
}
int Bubble(int* suu,int n){
    int ans=0;
    int flag=1;
    while(flag){
        flag=0;
        for(int j=n-1;j>=0;j--){
            if(suu[j]<suu[j-1]){
                swap(suu[j],suu[j-1]);
                flag=1;
                ans++;
            }
        }
    }
    return ans;
    
}





int main(){
    int n;
    cin>>n;
    int suu[n];
    for(int i=0;i<n;i++){
        cin>>suu[i];
    }
    
    int ans=Bubble(suu,n);
    arraycout(suu,n);
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3108
// 5/6
// 個数制限なしナップサック問題

#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>;
using Graph = vector<vector<int>>;

int dp[110][10010];

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

    vector<int> w(n), v(n);
    rep(i, n) cin >> v[i] >> w[i];

    memset(dp, 0, sizeof(dp));

    rep(i, n) {
        rep(j, W + 1) {
            if (w[i] <= j) {
                dp[i + 1][j] = max(dp[i + 1][j - w[i]] + v[i], dp[i][j]);
            } else {
                dp[i + 1][j] = dp[i][j];
            }
        }
    }

    cout << dp[n][W] << endl;
}


Measured memory_bytes: 7404
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();


int main() {
    int n;
    cin >> n;
    vector<int> arr(n, 0);
    vector<int> dq(n, 0);
    for(int i = 0; i < n; i++) {
        cin >> arr[i];
        dq[i] = i;
    }
    ll ans = 0;
    int slow = 0, acc = 0, xxor = 0;
    for(int fast = 0; fast < n; fast++) {
        acc += arr[fast];
        xxor ^= arr[fast];
        while (acc != xxor) {
            acc -= arr[slow];
            xxor ^= arr[slow];
            slow++;
        }
        // printf("(l, r) = (%d, %d)\n", slow, fast);
        int len = fast-slow+1;
        ans += len;
    }
    cout << ans << endl;
    return 0;
}




Measured memory_bytes: 1792
/* ALDS1_7_C:TreeWalk */
/* 20181125 AOJ */

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#define N 25
#define NIL -1

typedef struct {
	int parent;
	int left;
	int right;
} Tree;

void Preorder(Tree *node, int id);
void Inorder(Tree *node, int id);
void Postorder(Tree *node, int id);

int main(void) {
	Tree *node = (Tree *)malloc(sizeof(Tree) * N);
	int i, n, id, left, right, root;

	scanf("%d", &n);
	for(i = 0; i < n; i++) node[i].parent = NIL;

	for(i = 0; i < n; i++) {
		scanf("%d %d %d", &id, &left, &right);
		node[id].left = left;
		node[id].right = right;
		if(left != NIL) node[left].parent = id;
		if(right != NIL) node[right].parent = id;
	}

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

	printf("Preorder\n");
	Preorder(node, root);
	printf("\n");
	printf("Inorder\n");
	Inorder(node, root);
	printf("\n");
	printf("Postorder\n");
	Postorder(node, root);
	printf("\n");

	return 0;
}


void Preorder(Tree *node, int id) {
	if(id == NIL) return;
	printf(" %d", id);
	Preorder(node, node[id].left);
	Preorder(node, node[id].right);
}

void Inorder(Tree *node, int id) {
	if(id == NIL) return;
	Inorder(node, node[id].left);
	printf(" %d", id);
    Inorder(node, node[id].right);
}

void Postorder(Tree *node, int id) {
	if(id == NIL) return;
	Postorder(node, node[id].left);
    Postorder(node, node[id].right);
	printf(" %d", id);
}


Measured memory_bytes: 2104
#include<stdio.h>
#define SIZE 1000
#define MAX 1000
int stack[SIZE];
int stack_size = 0;

int pop()
{
  if(stack_size<=0)return 0;
  else return stack[--stack_size];
}
int push(int k)
{
 return  stack[stack_size++]=k;
}
int hantei(char *s)
{
  if(*s=='+' || *s=='-'){
    s++;
    if(*s>='0' && *s<='9')return 1;
    return 0;
  }
  if(*s>='0' && *s<='9')return 1;
  return 0;
}

int get(char *s)
{
  int flag=0,n=0;
  if(*s=='+'){
    s++;
  }
  else if(*s=='-'){
    flag=1;
    s++;
  }
  while(*s>='0' && *s<='9'){
    n=n*10+(*s-'0');
    s++;
  }
  if(flag)return -n;
  return n;
}
int calc(char *s)
{
  int a,b,n;
  while(*s){
    if(hantei(s)){
      n=get(s);
      push(n);
      while(*s=='-' || *s=='+'){
	s++;
      }
      while(n){
	n/=10;
	s++;
      }
    }
    else {
      switch(*s){
	case '+':
	a=pop();
	b=pop();
	push(b+a);
	break;
	case '-':
	a=pop();
	b=pop();
	push(b-a);
	break;
	case '*':
	a=pop();
	b=pop();
	push(b*a);
	break;
	case '/':
	a=pop();
	b=pop();
	push(b/a);
	break;
      }
      s++;
    }
  }
  return pop();
}

int main(){
  char s[MAX];
  scanf("%[^\n]*s",s);
  printf("%d\n",calc(s));
}



Measured memory_bytes: 2004
import sys
stdin = sys.stdin

sys.setrecursionlimit(10**5)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

a = list(li())
k = ni()
a.sort()

for i in range(k):
    a[2] *= 2
    a.sort()
    
print(sum(a))

Measured memory_bytes: 3064
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cstdio>
#include<cmath>
#define pb push_back
#define len(i,j) sqrt((a[i]-a[j])*(a[i]-a[j])+(b[i]-b[j])*(b[i]-b[j]))
using namespace std;
int main(){
vector<double>in,a,b;
double c,d,sum=0;
char x;
for(int i=0;i<2;i++){
cin>>c>>x>>d;
a.pb(c);
b.pb(d);
}
in.pb(len(1,0));
for(int i=2;scanf("%lf,%lf",&c,&d)!=EOF;i++){
double e;
a.pb(c);
b.pb(d);
in.pb(len(i,0));
e=len(i,i-1);
double z=(e+in[i-2]+in[i-1])/2;
sum+=sqrt(z*(z-e)*(z-in[i-2])*(z-in[i-1]));
}
cout<<sum<<endl;
}

Measured memory_bytes: 1352
#include <stdio.h>

#define Num 200000
int main(void){

    int l, n, i, j, max, min;
    int a[Num];

    scanf("%d", &l); 

    for(i = 0; i <= l-1; i++){
        scanf("%d", &n); 
        a[i] = n;
    }

    max = a[1] - a[0];
    if(a[1] > a[0]){
        min = a[0];
    }else{
        min = a[1];
    }

    for (i = 2; i <= l-1; i++) {
        if (a[i] < min){
            min = a[i];
        }else if(max < a[i]-min) {
            max = a[i]-min;
        }
    }

    printf("%d\n", max);

    return 0;
}


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

#define REP(i,n) for(int i=0;i< (n);i++)
#define REPR(i, n) for(int i = (n);i >= 0;i--)
#define FOR(i, m, n) for(int i = (m);i < (n);i++)
#define FORR(i, m, n) for(int i = (m);i >= (n);i--)
#define SORT(v, n) std::sort(v, v+n);
#define VSORT(v) std::sort(v.begin(), v.end());
#define VRSORT(v) std::sort(v.rbegin(), v.rend());
#define ll long long
#define pb(a) push_back(a)
#define ALL(obj) (obj).begin(),(obj).end()

using namespace std;

const int INF = 99999999;
const ll LINF = 9999999999999;

typedef pair<ll, ll> LP;
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };


ll N;
vector<ll> A;
int main() {
	cin >> N;
	REP(i, N) {
		ll tmp;
		cin >> tmp;
		A.push_back(tmp);
	}

	VRSORT(A);
	ll score = 0;

	REP(i, N)
	{
		if (i == 0) continue;
		if (i == 1) score += A[0];
		else score += A[i / 2];
	}

	cout << score << endl;


	return 0;

}

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

const int N = 0;
int limit,sum;
int ans = 0;

int main()
{
	cin >> limit >> sum;
	
	for(int i=0;i<=limit;i++)
	{
		for(int j=0;j<=limit;j++)
		{
			if(sum - i - j <= limit && sum - i - j >= 0) ans++;
		}
	}
	cout << ans;
}

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

using namespace std;

int main() {
  int n;
  cin >>n;
  vector<int> v(n);
  for(auto &it :v){
    cin >>it;
  }
  int ans=0;
  sort(v.rbegin(),v.rend() );
  
  for(int i=0;i<n;i++){
    if(i%2 ==0)
      ans+= v.at(i);
    else
      ans-= v.at(i);
  }
  cout << ans <<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a,n,maxA=0,maxAi=0,submaxA=0; cin>>n;
  for(int i=0;i<n;i++){
    cin>>a;
    if(maxA<=a&&submaxA<=a){
      submaxA=maxA;
      maxA=a;
      maxAi=i;
    }else if(submaxA<=a){
      submaxA=a;
    }
  }
  for(int i=0;i<n;i++) cout<<(maxAi==i?submaxA:maxA)<<endl;
}

Measured memory_bytes: 3600
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm>
#include <queue>
using namespace std;

int main(){
    int N;
    cin >> N;
    vector<int> a(N);
    for(int i=0;i<N;i++){
        cin >> a.at(i);
    }
    int count = 0;
    for(int i=0;i<N;i++){
        for(int j=0;j<N;j++){
            for(int k=0;k<N;k++){
                if(a.at(i) != a.at(j) && a.at(j) != a.at(k) && a.at(i) != a.at(k)){
                    priority_queue<int> q;
                    q.push(a.at(i));
                    q.push(a.at(j));
                    q.push(a.at(k));
                    int max = q.top();
                    q.pop();
                    int mid = q.top();
                    q.pop();
                    int min = q.top();
                    if(max < min + mid){
                        //cout << max << " " << mid << " " << min << endl;
                        count++;
                    }
                }
            }
        }
    }
    count = count / 6;
    cout << count << endl;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
#define FI first
#define SE second
#define EPS 1e-9
#define ALL(a) a.begin(),a.end()
#define SZ(a) int((a).size())
#define MS(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define WHATIS(x) cout << #x << " is " << x << endl;
#define ERROR(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
//__builtin_ffs(x) return 1 + index of least significant 1-bit of x
//__builtin_clz(x) return number of leading zeros of x
//__builtin_ctz(x) return number of trailing zeros of x

using namespace std;
using ll = long long;
using ld = double;
typedef pair<int, int> II;
typedef pair<ll, II> III;
typedef complex<ld> cd;
typedef vector<cd> vcd;

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cout << *it << " = " << a << endl;
    err(++it, args...);
}

const ll MODBASE = 1000000007LL;
const int MAXN = 110;
const int MAXM = 100010;
const int MAXK = 510;
const int MAXQ = 200010;

struct Res {
    string s;
    int sc, cs;
    Res(string s = "", int sc = 0, int cs = 0) : s(s), sc(sc), cs(cs) {}
} a[MAXN];

bool operator< (Res a, Res b) {
    if (a.s == b.s) return a.sc > b.sc;
    return a.s < b.s;
}

int n;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    cin >> n;
    FOR(i,1,n) {
        cin >> a[i].s >> a[i].sc; a[i].cs = i;
    }
    sort(a+1, a+n+1);

    FOR(i,1,n) cout << a[i].cs << "\n";
    return 0;
}

Measured memory_bytes: 256
jpy_per_btc = 380000.0

n = int(input())
money = []
for _ in range(n):
    (x, u) = input().split()
    is_jpy = ("JPY" == u)
    money.append([int(x) if is_jpy else float(x), is_jpy])

sum = 0
for i in money:
    sum += i[0] if i[1] else (i[0] * jpy_per_btc)
print(sum)


Measured memory_bytes: 3060
A=input().strip()
B=input().strip()
C=input().strip()

turn=0

while True:
  if turn==0:
    if len(A)==0:
      print('A')
      break
    else:
      if A[0]=='a':
        turn=0
        A=A[1:]
      elif A[0]=='b':
        turn=1
        A=A[1:]
      else:
        turn=2
        A=A[1:]
  elif turn==1:
    if len(B)==0:
      print('B')
      break
    else:
      if B[0]=='a':
        turn=0
        B=B[1:]
      elif B[0]=='b':
        turn=1
        B=B[1:]
      else:
        turn=2
        B=B[1:]
  else:
    if len(C)==0:
      print('C')
      break
    else:
      if C[0]=='a':
        turn=0
        C=C[1:]
      elif C[0]=='b':
        turn=1
        C=C[1:]
      else:
        turn=2
        C=C[1:]

Measured memory_bytes: 3064
import sys
from collections import Counter

read = sys.stdin.read
readline = sys.stdin.readline

N, *A = map(int, read().split())

A.sort()
a = Counter(A)
answer = 0
# 可能な最大の2冪
limit = 1 << ((2 * 10 ** 9 + 1).bit_length() - 1)

while A:
    n = A.pop()
    if a[n] == 0:
        continue

    a[n] -= 1
    s = limit
    while n < s:
        b = s - n
        if a[b] > 0:
            answer += 1
            a[b] -= 1
            break
        s //= 2

print(answer)


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

int main()
{
        int n; cin>>n;
        int c1=0,c2=0;
        rep(i,n){
                string s; cin>>s;
                if(s=="A") c1++;
                else c2++;
                if(c1<c2){
                        cout<<"NO"<<endl;
                        goto g;
                }
        }
        if(c1==c2) cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
g:;
}

Measured memory_bytes: 3160
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
const ld eps = 1e-9;

vector<string>a(vector<string>b) {
	vector<string>ans(8, string(8, 'a'));
	for (int i = 0; i < 8; ++i) {
		for (int j = 0; j < 8; ++j) {
			ans[7 - j][i] = b[i][j];
		}
	}
	return ans;
}

int main() {
	vector<string>sts(8);
	for (int i = 0; i < 8; ++i) {
		cin >> sts[i];
	}
	for (int i = 0; i < 3; ++i) {
		cout << 90+90 * i << endl;
		sts = a(a(a(sts)));
		for (int j = 0; j < 8; ++j) {
			cout << sts[j] << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3112
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <utility>
#include <iomanip>
using namespace std;
typedef long long ll;

const ll MOD = 1e9+7;
int b[100];
int a[100];
int main()
{
	int n;
	ll ans=0;
	cin>>n;
	for(int i=0;i<n-1;i++)
		cin>>b[i];
	a[0]=b[0];
	a[n-1]=b[n-2];
	for(int i=1;i<n-1;i++)
	{
		a[i]=min(b[i],b[i-1]);
	}
	for(int i=0;i<n;i++)
		ans+=a[i];
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
/*
  ------------------------- Hachiikung ---------------------------------
  ---------------------- Worrachate Bosri ------------------------------
  ------ Faculty of Computer Engineering Chulalongkorn University ------
*/
#include <bits/stdc++.h>
using namespace std;
#define REP(i,FN) for(int i=0;i<FN;i++)
#define FOR(i,ST,FN) for(int i=ST;i<=FN;i++)
#define FORD(i,FN,ST) for(int i=FN;i>=ST;i--)
#define FORX(i,c) for(typeof(c.begin())i=c.begin();i!=c.end();i++)
#define pause system("pause")
#define S scanf
#define P printf
#define X first
#define Y second
#define pb push_back
#define PII pair<int,int>
#define mp make_pair
#define sz size()
#define eps 1e-8

const int MOD(1000000007);
const int INF((1<<30)-1);
const int MAXN();

int a[55][26];

int main(){

    int n;
    S("%d",&n);

    REP(i,n)
    {
        string s;
        cin >> s;
        REP(j,s.sz)
            a[i][s[j]-'a']++;
    }

    REP(j,26)
    {
        int MIN = INF;
        REP(i,n)
             MIN = min(MIN, a[i][j]);
        REP(i,MIN)
            P("%c",'a'+j);
    }

    P("\n");

}


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

#define rep(i,N) repf(i,0,N)
#define reps(i,N) repfs(i,0,N)
#define repf(i,a,b) for(int i=a;i<b;i++)
#define repfs(i,a,b) for(int i=a+1;i<=b;i++)
#define repr(i,N) for(int i=N-1;i>=0;i--)
#define reprs(i,N) for(int i=N;i>0;i--)

#define d(a) if(isDebugMode) cout<<#a<<"="<<a<<","
#define d2(a,b) if(isDebugMode) cout<<#a<<"="<<a<<","<<#b<<"="<<b
#define d3(a,b,c) if(isDebugMode) cout<<#a<<"="<<a<<","<<#b<<"="<<b<<","<<#c<<"="<<c
#define d4(a,b,c,d) if(isDebugMode) cout<<#a<<"="<<a<<","<<#b<<"="<<b<<","<<#c<<"="<<c<<","<<#d<<"="<<d
#define da(arr,N){if(isDebugMode){rep(i,N){if(arr[i]==INF)printf("INF ");else cout<<arr[i]<<" ";} cout<<endl;}}
#define da2(arr,N,M){if(isDebugMode)rep(i,N){rep(j,M){if(arr[i][j]==INF)printf(" INF");else printf(" %3d",arr[i][j]);}cout<<endl;}}
#define pb push_back
#define pob pop_back

auto chmax =[](int &a,int b){ a = max(a, b);};
auto chmin =[](int &a,int b){ a = min(a, b);};

typedef long long ll;
typedef pair<int,int> P;
const int INF = 100000000;
const int MOD = 1000000007;
const int dx[4] = { 0, 1, 0,-1};
const int dy[4] = { 1, 0,-1, 0};

bool isDebugMode=1;
//--------------------------------------//
//https://beta.atcoder.jp/contests/agc010/tasks/agc010_a
int n;
int a;

int main(){
	cin>>n;
	int c=0;
	rep(i,n) {
		int a;
		cin>>a;
		if(a%2==1) c++;
	}
	if(c%2==0) cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i,n) for(long long i = 0;i < n;++i)
#define FOR(i,a,b) for(long long i = a;i < b;++i)
using namespace std;
using ll = long long;
using point = pair< int,int >;

int main(){
    int n, T, ans, cnt = 1;
    cin >> n >> T;
    ans = 0;
    int t[n];
    REP(i, n) {
        cin >> t[i];
        if (!i) continue;
        if (t[i] - t[i - 1] >= T) {
            cnt++;
        } else {
            ans += t[i] - t[i - 1];
        }
    }

    printf("%d\n", ans + cnt * T);
    return 0;
}



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

int main() {
    int N;
    cin >> N;
    int K;
    cin >> K;
    int A = 1;
    for (int i = 0; i < N; i++){
        if (A < K){
            A = A * 2;
        }
        else {
            A = A + K;
        }
    }
    cout << A << endl;
}



Measured memory_bytes: 256
def run():
  N = int(input())
  P_li = list(map(int, input().split()))
  smallest = P_li[0]
  ans = 0
  for p in P_li:
    if smallest >= p:
      ans += 1
      smallest = p
    else:
      continue
  print(ans)
    

if __name__ == '__main__':
  run()

Measured memory_bytes: 24744
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		if(n % k == 0)System.out.println(0);
		else System.out.println(1);
	}
}

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

#define ll long long
#define mx  100005
#define mod 1000000009
#define lim 10000000
#define inf 1000000000
#define N 18

using namespace std;

int main(){
	ios_base::sync_with_stdio(false);
     int n,g;cin>>n>>g;

	if(n%g)cout<<"1\n";
	else cout<<"0\n";
	return 0;
}





Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cctype>

using namespace std;

int main() {
  string input_str;

  getline(cin, input_str);

  for (int input_i = 0; input_i < input_str.size(); input_i++)
    if (input_str[input_i] >= 'a' && input_str[input_i] <= 'z')
      input_str[input_i] = toupper(input_str[input_i]); 

  cout << input_str << endl;

  return 0;
}

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

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

  priority_queue<int> q;
  for(int i = 1; i <= 2e6; i++){
    string s; cin >> s;
    if(s == "end") break;
    if(s[0] == 'e'){
      cout << q.top() << endl;
      q.pop();
    }
    else {
      int k; cin >> k;
      q.push(k);
    }
  }

  return 0;
}



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

bool cmp(int a,int b){
	return a>b;
}

int main(){
	int s=0,k,i,n,x;
	
	cin>>n>>k;
	
	int a[200005]={0};
	
	for(i=1;i<=n;i++){
		cin>>x;
		
		a[x]++;
	}
	
	sort(a+1,a+200000,cmp);
	
	for(i=k+1;i<=200000;i++){
		s+=a[i];
	}
	
	cout<<s<<endl;
	
	
	return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>
int main(void){
	int w,h,x,y,r;
	scanf("%d %d %d %d %d",&w,&h,&x,&y,&r);
	if(h>=r+y&&y-r>=0&&w>=r+x&&x-r>=0)puts("Yes");
	else puts("No");
	return 0;
}



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

int main(){
  vector<string>s(3);
  cin>>s.at(0)>>s.at(1)>>s.at(2);
  vector<int>a(3,0);
  char tmp=s.at(0).at(0);
  char tmp2;
  if(s.at(0).size()==1){
    cout <<"A"<<endl;
    return 0;
  }
  while(1){
    if(a.at(tmp-'a')==s.at(tmp-'a').size()){
      cout <<(char)(int)('A'+tmp-'a')<<endl;
      return 0;
    }
    tmp2=tmp;
    tmp=s.at(tmp-'a').at(a.at(tmp-'a'));
    a.at(tmp2-'a')++;
  }
}

Measured memory_bytes: 3600
#include<stdio.h>
	int main(){
		int S,h,m,s;
		scanf("%d",&S);
		h = S/3600;
		m = (S-(h*3600))/60;
		s = (S-(m*60+h*3600));
		printf("%d:%d:%d\n",h,m,s);
	}

Measured memory_bytes: 1852
#include<bits/stdc++.h>
#define sc scanf
using namespace std;
const int N=1e5+5;
const int mod=1e9+7;
typedef unsigned long long ull;
typedef long long ll;
template <typename it>int o(it a){cout<<a<<endl;return 0;}
ll a,b,c,d;
ll lcm(ll x,ll y){return x*y/__gcd(x,y);}
ll cal(ll x){
    return x/c+x/d-x/lcm(c,d);
}
int main(){
    cin>>a>>b>>c>>d;
    o(b-a+1-(cal(b)-cal(a-1)));
}


Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include "bits/stdc++.h"

using namespace std;

//------------------------------- Type Names -------------------------------//

using i64 = int_fast64_t;

using seika = string;
//{akari : 1D, yukari : 2D, maki : 3D} vector
template <class kizuna>
using akari = vector<kizuna>;
template <class yuzuki>
using yukari = akari<akari<yuzuki>>;
template <class tsurumaki>
using maki = akari<yukari<tsurumaki>>;
//{akane : ascending order, aoi : decending order} priority queue
template <class kotonoha>
using akane = priority_queue<kotonoha, akari<kotonoha>, greater<kotonoha>>;
template <class kotonoha>
using aoi = priority_queue<kotonoha>;
//------------------------------- Libraries --------------------------------//

//------------------------------- Dubug Functions ---------------------------//
inline void print()
{
    cout << endl;
}
template <typename First, typename... Rest>
void print(const First &first, const Rest &... rest)
{
    cout << first << ' ';
    print(rest...);
}
//------------------------------- Solver ------------------------------------//

void solve()
{
    int N, X;
    cin >> N >> X;
    //Xからスタート
    //N個の都市を全て巡る
    //abs(x - X)は全てDの倍数である
    //Dは全てのabs(x-X)についての公約数
    int ans = -1;
    for (int i = 0; i < N; i++)
    {
        int x;
        cin >> x;
        if (i == 0)
        {
            ans = abs(x - X);
        }
        else
        {
            ans = __gcd(ans, abs(x - X));
        }
    }
    cout << ans << endl;
}

int main()
{
    solve();
    return 0;
}


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

int main() {
    vector<int> a(3);
    scanf("%d%d%d", &a[0], &a[1], &a[2]);
    sort(a.begin(), a.end());
    int ans = a[1] - a[0];
    ans += a[2] - a[1];
    printf("%d\n", ans);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp(x) fixed << setprecision(x)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const int inf = (1<<30)-1;
const ll INF = (1LL<<60)-1;
const ld EPS = 1e-10;
template<typename T> bool chmax(T &x, const T &y) {return (x < y)? (x = y, true) : false;};
template<typename T> bool chmin(T &x, const T &y) {return (x > y)? (x = y, true) : false;};

int main(){
    int N, K, S, T;
    cin >> N >> K >> S >> T;
    int A[N];
    rep(i, N) cin >> A[i];
    if((T|S) != T) {cout << 0 << endl; return 0;}
    vector<int> check;
    int zero = (1<<18)-1, one = 0;
    rep(i, 18){
        if(S&(1<<i)) one |= 1<<i;
        elif(!(T&(1<<i))) zero &= ~(1<<i);
        else check.pb(i);
    }
    vector<int> a;
    rep(i, N){
        if((A[i]|one) != A[i]) continue;
        if((zero|A[i]) != zero) continue;
        a.pb(A[i]);
    }
    int n = sz(check), m = sz(a);
    ll bt[n][2];
    fill(bt[0], bt[n], 0);
    rep(i, n){
        rep(j, m){
            if(a[j]&(1<<check[i])) bt[i][1] |= (1LL<<j);
            else bt[i][0] |= (1LL<<j);
        }
    }
    ll comb[100][100];
    rep(i, 100){
        comb[i][0] = comb[i][i] = 1;
        rep2(j, 1, i-1){
            comb[i][j] = comb[i-1][j-1]+comb[i-1][j];
        }
    }
    ll sum[100]; //i個からK-1個以下を選ぶ方法
    rep(i, 100){
        sum[i] = 0;
        rep(j, min(i, K-1)+1){
            sum[i] += comb[i][j];
        }
    }
    ll ans = 0;
    rep(j, m){
        int b[n];
        rep(i, n){
            if(a[j]&(1<<check[i])) b[i] = 0;
            else b[i] = 1;
        }
        rep(i, 1<<n){
            ll ng = (1LL<<(j+1))-1;
            rep(k, n){
                if(!(i&(1<<k))) continue;
                ng |= bt[k][b[k]];
            }
            ll tmp = sum[m-__builtin_popcountll(ng)];
            if(__builtin_popcount(i)&1) ans -= tmp;
            else ans += tmp;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3688
//#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
 
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define endl '\n'
#define ll long long int
#define ld long double
#define vec vector
#define forn(a) for(ll a=0; a<n; a++)
#define all(x) x.begin(), x.end()
#define deb(x) cerr<<#x<<" = "<<x<<endl
 
using namespace std;
 
int main() {
    IOS;

    int a; cin>>a;
    string s; cin>>s;

    if(a>=3200) cout<<s<<endl;
    else cout<<"red"<<endl;


    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fst first
#define snd second
#define fore(i,a,b) for(int i=a,ThxDem=b;i<ThxDem;++i)
#define pb push_back
#define ALL(s) s.begin(),s.end()
#define FIN ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define SZ(s) int(s.size())
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;

int main(){FIN;
	int n,k; cin>>n>>k;
	vector<ll> a(n),c(n);
	fore(i,0,n) cin>>a[i],a[i]--;
	fore(i,0,n) cin>>c[i];
	
	ll mx=-1e18,mn=1e18;
	fore(i,0,n) mx=max(mx,c[i]),mn=min(mn,c[i]);
	
	if(mx<0){
		cout<<mx<<"\n";
		exit(0);
	}
	ll ans=0;
	
	vector<int> vis(n);

	fore(i,0,n) if(!vis[i]){
		vector<ll> cyc;
		int pp=i;
		while(!vis[pp]) vis[pp]=1,cyc.pb(c[pp]),pp=a[pp];
		
		ll all=0;
		for(auto x:cyc)all+=x;
		
		
		ll bst=0;
		fore(st,0,SZ(cyc)){
			ll ac=0,ps=st;
			//prefijo de largo j+1 empezando en st
			fore(j,0,min(SZ(cyc),k)){
				ac+=cyc[ps]; ps++; if(ps==SZ(cyc)) ps=0;
				
				bst=max(bst,ac);
				bst=max(bst,ac+((k-j-1)/SZ(cyc))*all);	//usar todo
			}
		}
		ans=max(ans,bst);
	}
	cout<<ans<<"\n";
}

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

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> dislike(K);
  for (int i=0; i<K; i++) { //嫌いな数字集合
    cin >> dislike.at(i);
  }
  vector<int> like; //使える数字集合
  for (int i=0; i<=9; i++) {
    bool count = true;
    for (int j=0; j<dislike.size(); j++) {
      if (i==dislike.at(j))
        count = false;
    }
    if (count){
      like.push_back(i);
    }
  }
  int i = 0;
  vector<int> num;  //Nの各桁数字
  int n=N;  //元のNは残しておく
  while (n>0){
    num.push_back(n%10);
    i++;
    n /= 10;
  }
  reverse(num.begin(), num.end());  //上から順に並べ替え
  int max_eq =0;
  for (int i=0; i<num.size(); i++) {
    max_eq = max_eq*10 + like.at(like.size()-1);  //同じ桁の最大数
  }

  if (N<=max_eq){
  //各桁数字が嫌いな数字集合に入っていれば、入っていない最小の数字に置き換える
  for (int i=0; i<num.size(); i++) {
    bool inc=false;  //数字を上げたらtrue
    for (int j=0; j<K; j++) {
      if (num.at(i)==dislike.at(j)) {
        num.at(i)++;
        inc = true;
      }
    }
    if (inc) {  //数字を上げたら下の桁は好きな数字の最小でよい
      for (int k=i+1; k<num.size(); k++) {
        num.at(k)=like.at(0);
      }
    break;
    }
  }
  }
  if (N>max_eq){
    for (int i=0; i<num.size(); i++){
      num.at(i)=like.at(0);
    }
    num.push_back(like.at(0));
    if (like.at(0)==0)
      num.at(0)=like.at(1);
  }
  //払う金額
  int sum = 0;
  for (int i=0; i<num.size(); i++) {
    sum = sum*10 + num.at(i);
  }
  cout << sum << endl;
}

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

int main(){
	int n;
	cin >> n;
	
	vector<int> t;
	
	for(int i = 0; i < n; i++){
		int a;
		cin >> a;
		t.push_back(a);
	}
	
	int m;
	cin >> m;
	for(int i = 0; i < m; i++){
		int a, b;
		cin >> a >> b;
		
		int ans = 0;
		for(int j = 0; j < t.size(); j++){
			if(j + 1 == a){
				ans += b;
			}else{
				ans += t[j];
			}
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define pb push_back
#define pii pair<long long,long long>
#define endl '\n'
#define N 100001
int mod=1000000007;
int dx[]={1,-1,0,0};
int dy[]={0,0,1,-1};
vector<int> parent(N),sz(N);
int modexp(int x,int n,int M)
{
    if(n==0)
        return 1;
    else if(n%2 == 0)        
        return modexp((x*x)%M,n/2,M);
    else                             
        return (x*modexp((x*x)%M,(n-1)/2,M))%M;
}
void make_set(int s)
{
    parent[s]=s;
    sz[s]=1;
}
int find_parent(int p)
{
    if(p==parent[p])
    return p;
    return parent[p]=find_parent(parent[p]);
}
void union_set(int a,int b)
{
    a=find_parent(a);b=find_parent(b);
    if(a!=b)
    {
        if(a<b)
        swap(a,b);
        parent[b]=parent[a];
        sz[a]+=sz[b];
    }
}
void solve()
{
    int n,m; cin>>n>>m;
    if(n<=m)
    cout<<"unsafe";
    else
    cout<<"safe";
}
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int test; test=1;
    while(test--)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 4688