akhauriyash/Code-Regression huggingface dataset:
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Scanner;

public class Main {
	InputStream in = System.in;
	PrintStream out = System.out;

	long f(long a) {
		long ans = 0;
		if (a <= 0)
			return 0;

		// 0～aの個数は a+1
		long n = a + 1;

		//桁ごとに1の個数をしらべる
		for (int i = 0; i < 50; i++) {

			// i桁目の周期
			long period = 1L << (i + 1);

			// 1周期に含まれる１（または０）の数
			long numInPeriod = period / 2;

			// nまでに何周期含まれるか
			long numOfPeriod = n / period;

			// 周期に含まれない部分の個数。
			long amari = n % period;

			// 周期の前半は0、後半は1なので、amariから周期の長さの半分を引いたものが1の個数。
			// ただし、0以下になる場合があるので、その場合は0とする。
			long amari1 = Math.max(amari - period / 2, 0);

			long cnt = numInPeriod * numOfPeriod + amari1;

			if (cnt % 2 == 1) {
				ans += 1L << i;
			}
		}
		return ans;
	}

	public void _main(String[] args) {
		Scanner sc = new Scanner(in);

		long a = sc.nextLong();
		long b = sc.nextLong();

		long ans = f(b) ^ f(a - 1);

		out.println(ans);
		sc.close();

	}

	public static void main(String[] args) {
		new Main()._main(args);
	}

}


Measured memory_bytes: 22996
#include <iostream>
#include <stdio.h>

using namespace std;

int main (void)
{
    int a, b, c, d;

    cin >> a >> b >> c >> d;

    if (a + b > c + d) {
        cout << "Left" << endl;
    } else if (a + b < c + d){
        cout << "Right" << endl;
    } else {
        cout << "Balanced" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

#define MAX 200000
#define INFTY 2000000000

int L[MAX/2 + 2],R[MAX/2 + 2];

long long merge(int A[], int n, int left, int mid,int right){
	int i,j,k;
	long long count = 0;
	int n1 = mid - left;
	int n2 = right - mid;
	for(i = 0;i < n1; i++){
	L[i] = A[left + i];
	}
	for( i = 0;i < n2; i++){
	R[i] = A[mid + i];
	}
	L[n1] = R[n2] = INFTY;
	i = j = 0;
	for(k = left; k < right; k++){
	if(L[i] <= R[j]){
		A[k] = L[i++];
	}else{
		A[k] = R[j++];
	count += n1-i;
	}
	}
	return count;
	
}

long long mergeSort(int A[], int n,int left,int right){
	int mid;
	long long v1,v2,v3;
	if(left + 1 < right){
	mid = (left + right) /2;
	v1 = mergeSort(A,n,left,mid);
	v2 = mergeSort(A,n,mid,right);
	v3 = merge(A,n,left,mid,right);
	return v1+v2+v3;
	}else{
	return 0;
	}

}

int main(void){
	int A[MAX],n,i;

	scanf("%d",&n);

	for(i = 0;i < n ;i++){
	scanf("%d",&A[i]);
	}
	
	long long res = mergeSort(A,n,0,n);
	printf("%ld\n",res);

	return 0;

}


Measured memory_bytes: 3420
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.container;

void main()
{
	auto n = readln.chomp.to!int;
	foreach (c; 1..n+1) {
		readln;
		auto area = new char[][](8, 8);
		foreach (i; 0..8) {
			area[i] = readln.chomp.map!(to!char).array;
		}
		auto y = readln.chomp.to!int - 1;
		auto x = readln.chomp.to!int - 1;

		void solve(int i, int j) {
			area[i][j] = '0';
			foreach (h; max(i-3,0)..min(i+4, 8)) {
				if (area[h][j] == '1') solve(h, j);
			} 
			foreach (w; max(j-3,0)..min(j+4, 8)) {
				if (area[i][w] == '1') solve(i, w);
			} 
		}
		solve(x, y);

		writeln("Data ", c, ":");
		foreach (i; 0..8) {
			foreach (j; 0..8) {
				write(area[i][j]);
			}
			writeln("");
		}
	}
}

Measured memory_bytes: 1088
from collections import deque
h,w = map(int,input().split())
a = []
d = []
que = deque()
for i in range(h):
    a.append(list(input()))
    d.append([1e100]*w)
    for j in range(w):
        if a[i][j] == '#':
            que.append([i,j])
            d[i][j] = 0
di = [-1,0,1,0]
dj = [0,1,0,-1]
ans = 0

while que:
    i,j = que.popleft()
    for k in range(4):
        ni = i + di[k]
        nj = j + dj[k]
        if 0 <= ni < h and 0 <= nj < w and d[ni][nj] == 1e100:
            d[ni][nj] = d[i][j] + 1
            ans = max(ans, d[ni][nj])
            que.append([ni,nj])
print(ans)


Measured memory_bytes: 168712
#include <iostream>
#include <vector>
#include <chrono>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <random>
#include <map>
#include <string>

using namespace std;

typedef long long ll;
typedef long double ld;

#define fastInp cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);

const ll SIZE = 1e5 * 3, MOD = 1e9 + 7, INF = 1e9;
vector<vector<ll>> graph;
bool used[SIZE];
ll ans = 0;

ll pw(ll a, ll b, ll md = MOD) { ll res = 1; while (b) { if (b & 1) { res = (a*res) % md; }a = (a*a) % md; b >>= 1; }return(res); }

int main()
{
    fastInp;

    ll n, k;
    cin >> n >> k;

    vector<pair<ll, ll>> vec;
    bool z = 0;
    for (int i = 0; i < n; i++) {
        ll num;
        cin >> num;
        if (num == 0) {
            z = 1;
            continue;
        }
        vec.push_back({ abs(num), num / (abs(num)) });
    }
    
    ll curCh = 1, cnt[2], curM = 1, mn[2];
    cnt[0] = 0;
    cnt[1] = 0;
    mn[0] = 0;
    mn[1] = 0;
    sort(vec.rbegin(), vec.rend());
    n = vec.size();
    if (k > vec.size()) {
        cout << "0";
        return 0;
    }
    for (int i = 0; i < k; i++) {
        if (vec[i].second == 1) {
            cnt[0]++;
            mn[0] = vec[i].first;
        }
        else {
            cnt[1]++;
            mn[1] = vec[i].first;
        }
        curCh *= vec[i].second;
        curM *= vec[i].first;
        curM %= MOD;
    }

    if (curCh == 1) {
        cout << curM;
        return 0;
    }

    if (curCh == -1) {
        pair<ll, ll> bst = { -1, -1 }, bst2 = { -1, -1 };
        for (int i = k; i < n; i++) {
            if (vec[i].second == 1) {
                if (cnt[1] != 0) {
                    if (bst == make_pair(-1ll, -1ll)) {
                        bst = { mn[1], vec[i].first };
                    }
                }
            }
            else if (vec[i].second == -1) {
                if (cnt[0] != 0) {
                    if (bst2 == make_pair(-1ll, -1ll)) {
                        bst2 = { mn[0], vec[i].first };
                    }
                }
            }
        }

        if (bst != make_pair(-1ll, -1ll) || bst2 != make_pair(-1ll, -1ll)) {
            if (bst.second * bst2.first >= bst2.second * bst.first) {
                cout << ((curM * pw(bst.first, MOD - 2, MOD)) % MOD * bst.second) % MOD;
            }
            else {
                cout << ((curM * pw(bst2.first, MOD - 2, MOD)) % MOD * bst2.second) % MOD;
            }
            return 0;
        }

        if (z) {
            cout << "0";
            return 0;
        }

        reverse(vec.begin(), vec.end());
        ll vl = 1;
        for (int i = 0; i < k; i++) {
            vl *= (vec[i].second * vec[i].first + MOD) % MOD;
            vl %= MOD;
        }

        cout << vl;
        return 0;
    }
    return 0;
}

Measured memory_bytes: 7400
N,A,B,C = map(int, input().split())
l = [int(input()) for i in range(N)]
INF = 10**9

def dfs(cur, a, b, c):
    if cur == N:
        return abs(a-A)+abs(b-B)+abs(c-C)-30 if min(a,b,c)>0 else INF
    ret0 = dfs(cur+1, a, b, c)
    ret1 = dfs(cur+1, a+l[cur], b, c) + 10
    ret2 = dfs(cur+1, a, b+l[cur], c) + 10
    ret3 = dfs(cur+1, a, b, c+l[cur]) + 10
    return min(ret0, ret1, ret2, ret3)

print(dfs(0, 0, 0, 0))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  
  vector<int> vec(N - 1);
  vector<int> vec2(N);
  for (int i = 0; i < N - 1; i++) {
    cin >> vec.at(i);
    vec2.at(vec.at(i) - 1)++;
  }
  
  for (int i = 0; i < N; i++) {
  cout << vec2.at(i) << endl;
  }
}

Measured memory_bytes: 4840
#include<stdio.h>
#define N 2000000
void counting_sort(int);

int B[N + 1];
int A[N + 1];
int length;
int print(int j){
  int max, i;
  max = 0; 
  for(i = 1; i <= j; i++){
    scanf("%d", &A[i]);
    if(max < A[i]){
      max = A[i];
    }
  }
  return max;
}
main(){
  int i, max;
  scanf("%d", &length);
  
  max = print(length);

  counting_sort(max);

  for(i = 1; i <= length; i++){
    printf("%d", B[i]);
    if(i != length) printf(" ");
  }
  printf("\n");
  return 0;
}

void counting_sort(int k){
  int i, j, a;
  int C[k + 1];

  for(i = 0; i < k + 1; i++){
    C[i] = 0;
  } 

  for(j = 1; j < length + 1; j++){
    i = A[j];
    C[i]++;
  } 

  for(i = 1; i < k + 1; i++){
    C[i] += C[i - 1];
  }
  
  for(j = length; j > 0; j--){
    i = A[j];
    a = C[i];
    B[a] = A[j];
    C[i]--;
  }

}

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

int n,m,X,tot=0,root,r[100005];
int lch[8000005],rch[8000005];
int minv[8000005],maxv[8000005];
int set[8000005],add[8000005];
struct Question{
	int t,a,id;
}q[100005];
int ans[100005];

bool comp(Question a,Question b){return a.t<b.t;}

int newnode(int &o,int x,int y){
	o=++tot,minv[o]=x,maxv[o]=y,set[o]=-1;
}

void pushup(int o){
	minv[o]=min(minv[lch[o]],minv[rch[o]]);
	maxv[o]=max(maxv[lch[o]],maxv[rch[o]]);
}

void pushdown(int o,int l,int r){
	int mid=l+r>>1;
	int &lc=lch[o],&rc=rch[o];
	if(!lc)newnode(lc,l,mid-1);
	if(!rc)newnode(rc,mid,r-1);
	if(~set[o]){
		minv[lc]=maxv[lc]=set[lc]=set[o];
		minv[rc]=maxv[rc]=set[rc]=set[o];
		add[lc]=add[rc]=0,set[o]=-1;
	}
	if(add[o]){
		minv[lc]+=add[o],maxv[lc]+=add[o],add[lc]+=add[o];
		minv[rc]+=add[o],maxv[rc]+=add[o],add[rc]+=add[o];
		add[o]=0;
	}
}

void Sub(int &o,int l,int r,int x){
	if(o==0)newnode(o,l,r-1);
	if(maxv[o]<=x)
		maxv[o]=minv[o]=add[o]=set[o]=0;
	else if(minv[o]>=x)
		maxv[o]-=x,minv[o]-=x,add[o]-=x;
	else{
		pushdown(o,l,r);
		int mid=l+r>>1;
		Sub(lch[o],l,mid,x),Sub(rch[o],mid,r,x);
		pushup(o);
	}
}

void Add(int &o,int l,int r,int x){
	if(o==0)newnode(o,l,r-1);
	if(minv[o]>=X-x)
		maxv[o]=minv[o]=set[o]=X,add[o]=0;
	else if(maxv[o]<=X-x)
		maxv[o]+=x,minv[o]+=x,add[o]+=x;
	else{
		pushdown(o,l,r);
		int mid=l+r>>1;
		Add(lch[o],l,mid,x),Add(rch[o],mid,r,x);
		pushup(o);
	}
}

int query(int o,int l,int r,int x){
	if(o==0)newnode(o,l,r-1);
	if(r-l==1)return minv[o];
	pushdown(o,l,r);
	int mid=l+r>>1;
	if(x<mid)return query(lch[o],l,mid,x);
	else return query(rch[o],mid,r,x);
}

int main(){
	scanf("%d%d",&X,&n);
	for(int i=1;i<=n;i++)scanf("%d",r+i);
	r[n+1]=1e9;
	scanf("%d",&m);
	for(int i=1;i<=m;i++){
		scanf("%d%d",&q[i].t,&q[i].a);
		q[i].id=i;
	}
	sort(q+1,q+m+1,comp);
	for(int i=0,j=1,rev=0;i<=n;i++,rev^=1){
		while(j<=m&&q[j].t<=r[i+1]){
			int tmp=query(root,1,X+1,q[j].a);
			if(rev)tmp=min(X,tmp+q[j].t-r[i]);
			else tmp=max(0,tmp-q[j].t+r[i]);
			ans[q[j++].id]=tmp;
		}
		if(j>m)break;
		int tmp=r[i+1]-r[i];
		if(rev)Add(root,1,X+1,tmp);
		else Sub(root,1,X+1,tmp);
	}
	for(int i=1;i<=m;i++)printf("%d\n",ans[i]);
} 

Measured memory_bytes: 131456
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<array>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<functional>
#include<limits>
#include<list>
#include<map>
#include<numeric>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<unordered_map>
#include<queue>
#include<vector>
using namespace std;

using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()
#define dump(o) {cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) {cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
const int MOD = 1e9 + 7;

#define PI 3.1415926535

signed main() {
	for (int n; cin >> n&&n != -1;) {
		double x = 1, y = 0;
		rep(i, 1, n) {
			double _x = 0 - x, _y = 0 - y;
			double r = sqrt(_x *_x + _y *_y);
			x = _y / r + x; y = -_x / r + y;
		}
		cout << x << endl << y << endl;
	}
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define Abs(x)((x) < 0 ? (x) * -1 : (x))
#define rep(x, y) for ((x) = 0; (x) < (y); (x)++)
#define repin(x, y) for ((x) = 0; (x) <= (y); (x)++)
#define nep(x, y) for ((x) = (y) - 1; 0 <= (x); (x)--)
#define nepi(x, y, z) for ((x) = (y) - 1; (z) <= (x); (x)--)
#define repi(x, y, z) for ((x) = (z); (x) < (y); (x)++)
#define repiin(x, y, z) for ((x) = (z); (x) <= (y); (x)++)
#define reps(x, y, z) for ((x) = 0; (x) < (y); (x) += (z))
#define repit(x) for (__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define All(x) (x).begin(),(x).end()
#define Mem0(x) memset(x, 0, sizeof(x))
#define Mem1(x) memset(x, -1, sizeof(x))
#define End '\n'
#define Out(x) cout<<(x)<<End
template<typename T> inline bool Max(T &x, const T &y) { return x < y ? x = y, 1 : 0; }
template<typename T> inline bool Min(T &x, const T &y) { return x > y ? x = y, 1 : 0; }
template<typename T> using V = vector<T>;
template<typename T> using VV = V<V<T> >;

#define pb push_back
#define mp make_pair
#define X first
#define Y second

static const ll MOD = 1e9 + 7;
static const double PI = 3.141592653589793;

#define LOCAL 0

int main()
{
#if LOCAL
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    freopen("debug.txt", "w", stderr);
#endif

    cin.tie(0);
    ios::sync_with_stdio(false);

    ll a, b, c, k;
    static ll M = 1e18;

    cin >> a >> b >> c >> k;

    if (a == b && b == c) {
        Out(0);
    } else if (k == 0) {
        if (M < Abs(a - b)) Out("Unfair");
        else Out(a - b);
    } else {
        if (k % 2 == 1) {
            if (M < Abs(b - a)) Out("Unfair");
            else Out(b - a);
        } else {
            if (M < Abs(a - b)) Out("Unfair");
            else Out(a - b);
        }
    }

    return 0;
}


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

int main() {
    int W, H, x, y, r;

    cin >> W >> H >> x >> y >> r;

    if (y+r <= H && x+r <= W && y-r >= 0 && x-r >= 0) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 3108
#include <iostream>
#include <fstream>
#include <typeinfo>
#include <vector>
#include <stack>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <iomanip>
#include <cctype>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<25;
const ll INF=1ll<<50;
const double pi=acos(-1);
const double eps=1e-8;
const int mod=1e9+7;
const vi emp;
const int dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};

int a,b,c,d,p;

int main(){
	cin>>a>>b>>c>>d>>p;
	cout<<min(a*p,b+((c<p)?d*(p-c):0))<<endl;
}

Measured memory_bytes: 3104
package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	sc.Split(bufio.ScanWords)
	sc.Scan()
	n, _ := strconv.Atoi(sc.Text())
	for i := 0; i < 100; i++ {
		for j := 0; j < 100; j++ {
			if 4*i+7*j == n {
				fmt.Println("Yes")
				return
			}
		}
	}
	fmt.Println("No")
}


Measured memory_bytes: 640
from operator import itemgetter

NM = list(map(lambda x: int(x), input().split()))
N = NM[0]
M = NM[1]

stores = [list(map(lambda x: int(x), input().split())) for i in range(N)]
stores = sorted(stores, key=itemgetter(0))

answer = 0
stock = 0
for store in stores:
  if (M > store[1]):
    M = M - store[1]
    answer += store[0] * store[1]
  else:
    answer += store[0] * M
    break

print(answer)


Measured memory_bytes: 29868
#include<iostream>
#include <cstdlib>
#include <algorithm>
using namespace std;
int main(int argc, char const *argv[])
{
    char S[3];

    cin>>S;
    int val=700;
    for(int i=0;i<3;i++){
    if(S[i]=='o'){
        val+=100;
    }
    }
    cout<<val<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define f(i,n) for(int i=0;i<n;i++)
#define P pair<int,int>
#define F first
#define S second
#define int long long
#define mod 1000000007
#define mmod 998244353
#define all(v) v.begin(), v.end()
#define INF LLONG_MAX/3
using namespace std;
int mypow(int fa, int fb, int fc) {
	if (fb == 0)return 1;
	if (fb % 2)return mypow(fa, fb - 1, fc)*fa%fc;
	int z = mypow(fa, fb / 2, fc);
	return z * z%fc;
}
int k(int fa) {
	int x = 0;
	while (fa) {
		x++;
		fa /= 10;
	}
	return x;
}
int gcd(int fa, int fb) {
	if (fb == 0)return fa;
	return gcd(fb, fa%fb);
}
signed main() {
	int a, ans = 0;
	cin >> a;
	f(i, a) {
		i++;
		if (i % 3 && i % 5)ans += i;
		i--;
	}
	cout << ans << endl;
}


Measured memory_bytes: 3624
// Created by ...
#include <bits/stdc++.h>

#define db1(x) cout<<#x<<"="<<x<<'\n'
#define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<'\n'
#define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<'\n'

#define vll vector< ll >
#define M 100000
#define MD 1000000007
#define pb push_back
#define rep(i,a,b) for(ll i = a; i <= b; ++i)
#define fo(i,a,b) for(int i = a; i<= b; ++i)
#define pii pair<ll,ll> 
#define vec(a) vector<a >
#define all(a) a.begin(),a.end()
#define se second
#define fi first
#define inf 0xffffffff
#define inchar getchar_unlocked
#define outchar(x) putchar_unlocked(x)
#define int long long
#define endl '\n'
#define IOS ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

using namespace std;
using ll = long long;
ll md=MD;

ll exp(ll a,ll b){ll r=1ll;while(b>0){if(b&1){r=r*(a%md);r=(r+md)%md;}b>>=1;a=(a%md)*(a%md);a=(a+md)%md;}return (r+md)%md;}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll Min(ll a,ll b){if(a<b)return a; return b;}
ll Max(ll a,ll b){if(a>b)return a; return b;}
int32_t main() {
    IOS;

        int n,k,len=1,s,et;
        cin>>n>>k;
        int a[n+1],pos[n+1]; rep(i,1,n)cin>>a[i];
        set<int> st; st.insert(1); memset(pos,0,sizeof(pos));
        int prev=1;pos[1]=1;
        while(1)
        {
        	if(st.find(a[prev])==st.end())
        	{
        		st.insert(a[prev]);
        		pos[a[prev]]=pos[prev]+1;
        		prev=a[prev];
        	}
        	else
        	{
        		et=pos[prev],s=pos[a[prev]];
        		prev=a[prev];
        		break;        		
        	}
        }
        //db3(s,et,prev);
        if(k<s)
        {
        	int prev=1;
        	rep(i,0,k-1)prev=a[prev];
        	cout<<prev; return 0;
        }
        k-=(s-1);
        k%=(et-s+1);
        rep(i,0,k-1)prev=a[prev];
        cout<<prev;
        cout<<'\n';
    return 0;
}

Measured memory_bytes: 16012
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define imfor(i, n) for(int i = 0; i < n; i++)
using namespace std;
 
int main() {
    long long n, a[100000];
    cin >> n;
    for (long long i = 0; i < n; i++) {
        cin >> a[i];
    }
    sort(a, a + n, greater<long long>());
    long long x = 0, y = 0;
    for (long long i = 0; i < n; i++) {
        if (a[i] == a[i + 1]) {
            if (x == 0) {
                x = a[i];
                i++;
            }
            else {
                y = a[i];
                cout << x * y << endl;
                return 0;
            }
        }
    }
    cout << 0 << endl;
}

Measured memory_bytes: 1024
#include <stdio.h>
 
long long int gcd(long long int a, long long int b) {
    if(b == 0) return a;
    return gcd(b, a % b);
}
 
long long int lcm(long long int a,long long int b) {
    return a / gcd(a, b) * b ;
}
 
int main(void) {
	long long int t[100];
	int n,i;
	long long int ans=1;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%lld",&t[i]);
		ans=lcm(ans,t[i]);
	}
	printf("%lld",ans);
	return 0;
}


Measured memory_bytes: 128
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<algorithm>


using namespace std;
using ll=long long;
using vll=vector<ll>;


int min_u(ll&m, ll v)
{
	if(m>v)
	{
		m=v;
		return 1;
	}
	return 0;
}


int main(void)
{
	int n;

	while(scanf("%d", &n)==1)
	{
		vll a(n+1);
		vll t(n+1);
		vll w(4);

		for(int i=1;i<=n;i++)
		{
			scanf("%lld", &a[i]);
			t[i]=t[i-1]+a[i];
		}
		ll ans=t[n];

		int l=1, r=3;
		for(int c=2;c+1<n;c++)
		{
			if(r<c+1) r=c+1;
			for(;l<c;l++)
			{
				if(t[c]-t[l]<=t[l]-t[0]) break;
			}
			for(;r<n;r++)
			{
				if(t[n]-t[r]<=t[r]-t[c]) break;
			}
			w[0]=t[l]-t[0];
			w[1]=t[c]-t[l];
			w[2]=t[r]-t[c];
			w[3]=t[n]-t[r];
			sort(w.begin(), w.end());
			min_u(ans, w[3]-w[0]);

			if(l>1)
			{
				w[0]=t[l-1]-t[0];
				w[1]=t[c]-t[l-1];
				w[2]=t[r]-t[c];
				w[3]=t[n]-t[r];
				sort(w.begin(), w.end());
				min_u(ans, w[3]-w[0]);
				if(r-1>c)
				{
					w[0]=t[l-1]-t[0];
					w[1]=t[c]-t[l-1];
					w[2]=t[r-1]-t[c];
					w[3]=t[n]-t[r-1];
					sort(w.begin(), w.end());
					min_u(ans, w[3]-w[0]);
				}
			}

			if(r-1>c)
			{
				w[0]=t[l]-t[0];
				w[1]=t[c]-t[l];
				w[2]=t[r-1]-t[c];
				w[3]=t[n]-t[r-1];
				sort(w.begin(), w.end());
				min_u(ans, w[3]-w[0]);
			}
		}

		printf("%lld\n", ans);
	}

	return 0;
}


Measured memory_bytes: 3328
#include<iostream>
#include<algorithm>
#include<string>

using namespace std;

/**
 * F - LCS
 * https://atcoder.jp/contests/dp/tasks/dp_f
 **/
const int MAX_S = 3000;
const int MAX_T = 3000;

int dp[MAX_S+1][MAX_T+1];
string s, t;

void solve() {
    int s_len = s.length();
    int t_len = t.length();
    for (int i = 0; i < s_len; i++) {
        for (int j = 0; j < t_len; j++) {
            if (s[i] == t[j]) {
                dp[i+1][j+1] = dp[i][j] + 1;
            } else {
                dp[i+1][j+1] = max(dp[i+1][j], dp[i][j+1]);
            }
        }
    }

    int x = s_len;
    int y = t_len;
    string ans;
    while (x > 0 && y > 0) {
        if (dp[x][y] == dp[x-1][y]) {
            x--;
        } else if (dp[x][y] == dp[x][y-1]) {
            y--;
        } else {
            x--;
            y--;
            ans.push_back(s[x]);
        }
    }
    reverse(ans.begin(), ans.end());
    cout << ans << endl;
}

int main() {
    cin >> s;
    cin >> t;
    solve();
}

Measured memory_bytes: 35456
#include <bits/stdc++.h>
#define eps 1e-3
#define pi acos(-1.0)
#define inf 0x3f
#define INF 0x3f3f3f3f
#define pb push_back
#define debug1 cout<<"&&";
#define debug2 cout<<"**";
#define ms(a, x) memset(a, x, sizeof(a))
#define for0(i, n) for(int i = 0; i < n; ++i)
#define for1(i, n) for(int i = 1; i <= n; ++i)
using namespace std;
typedef double db;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<long long, int> pli;
typedef pair<long long, long long> pll;
const int mod = 1e9 + 7;
const int N = 2e5+10;
const int M = 1e6+10;
/*=================================================================================*/

ll s[N << 2], t[N << 2];
vector<pair<int, int> > a[N];
void add(int x, int L, int R, int l, int r, ll c) {
    if (l <= L && R <= r) return (void)(s[x] += c, t[x] += c);
    int mid = (L + R) >> 1;
    if (l <= mid) add(x << 1, L, mid, l, r, c);
    if (r > mid) add(x << 1 | 1, mid + 1, R, l, r, c);
    s[x] = max(s[x << 1], s[x << 1 | 1]) + t[x];
}
int n, m;
int main() {
    scanf("%d%d", &n, &m);
    for (int i = 1, x, y, z; i <= m; i++) {
        scanf("%d%d%d", &x, &y, &z);
        a[y].emplace_back(x, z);
    }
    for (int i = 1; i <= n; i++) {
        add(1, 1, n, i, i, s[1]);
        for (auto &it : a[i]) add(1, 1, n, it.first, i, it.second);
    }
    printf("%lld\n", max(s[1], 0ll));
    return 0;
}

Measured memory_bytes: 21788
#include <iostream>
#include <vector>

using namespace std;

void solve (int n, int y)
{
for ( int i = 0; i <= n; ++i ) {
for ( int j = 0; j + i <= n; ++j ) {
int k = n - i - j;
if ( y == 10000 * i + 5000 * j + 1000 * k ) {
cout << i << ' ' << j << ' ' << k << endl;
return;
}
}
}
cout << -1 << ' ' << -1 << ' ' << -1 << endl;
return;
}
int main ()
{
int n, y;
while ( cin >> n >> y ) {
solve(n, y);
}
return 0;
}

Measured memory_bytes: 256
//  atcodder.xcode
//  main.cpp
//  Created by conan1024hao on 2019/11/11.
//  Copyright © 2019 conan1024hao. All rights reserved.
//  専用ライブラリ
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll>P;
#define INF 10e16
#define MOD 1000000007
#define rep(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define fi first
#define se second
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define PI acos(-1.0)
long long GCD(long long a, long long b) { return b ? GCD(b, a%b) : a; }
long long LCM(long long a, long long b)  {return a/GCD(a,b)*b;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
ll cmp(pair<ll,string>a,pair<ll,string> b){
        if(a.fi!=b.fi)
        return a.fi<b.fi;
        else
        return a.se<b.se;
}
//---------------------------------------------------------------------------
ll n,s;
vector<ll>a(10001);
vector<ll>b(10001);
vector<ll>t(100100);
ll solve(){
    b.resize(n);
    ll ans=0;
    bool v[100001];
    for(int i=0;i<n;i++){
        b[i]=a[i];
        v[i]=false;
    }
    sort(all(b));
    for(int i=0;i<n;i++)
        t[b[i]]=i;
    for(int i=0;i<n;i++){
        if(v[i])continue;
        ll cur=i;
        ll S=0;
        ll m=INF;
        ll an=0;
        while(1){
            v[cur]=true;
            an++;
            ll V=a[cur];
            chmin(m,V);
            S+=V;
            cur=t[V];
            if(v[cur])break;
        }
        ans+=mmin(S+(an-2)*m,m+S+(an+1)*s);
    }
    return ans;
}
//---------------------------------------------------------------------------
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------
    cin>>n;
    s=INF;
    
    for(int i=0;i<n;i++)
    { cin>>a[i];
        chmin(s,a[i]);}
    ll ans=solve();
    cout<<ans<<endl;
    
    //-------------------------------
    return 0;
}
//---------------------------------------------------------------------------



Measured memory_bytes: 3776
#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, n) for(int i = 1; i <= (int)(n); i++)
#define rrep(i, n) for(int i = ((int)(n)-1); i >= 0; i--)
#define srep(i, from, to) for(int i = from; i < (int)(to); i++)
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;

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

  sort(a.begin(), a.end());

  bool ok = true;
  rep(i, n - 1) {
    if(a[i] == a[i + 1]) {
      ok = false;
      break;
    }
  }

  if(ok) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }

  return 0;
}


Measured memory_bytes: 1024
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
typedef pair<int, int> P;
ll mod_pow(ll a, ll n) {
	if (n == 0) return 1;
	if (n % 2 == 0) {
		ll tmp = mod_pow(a, n / 2);
		return (tmp * tmp) % MOD;
	}
	return (a * mod_pow(a, n - 1)) % MOD;
}

vector<ll> fact;
vector<ll> inv_fact;

void comb_init(int n) {
	fact.resize(n + 1);
	inv_fact.resize(n + 1);
	fact[0] = inv_fact[0] = 1;
	for (int i = 1; i <= n; i++) {
		fact[i] = (fact[i - 1] * i) % MOD;
		inv_fact[i] = (inv_fact[i - 1] * mod_pow(i, MOD - 2)) % MOD;
	}
}

ll comb(int n, int k) {
	if (n < k) return 0;
	ll ret = fact[n];
	(ret *= inv_fact[k]) %= MOD;
	(ret *= inv_fact[n - k]) %= MOD;
	return ret;
}
ll dp[3001][3001];
int cnt[3001];
int main() {
	int N, M;
	cin >> N >> M;
	string S;
	cin >> S;
	for (int i = 0; i < S.size(); i++) {
		cnt[i + 1] = S[i] - '0' + cnt[i];
	}
	vector<P> v;
	v.emplace_back(0, 0);
	int prev_r = 0;
	for (int i = 0; i < M; i++) {
		int l, r;
		cin >> l >> r;
		if (prev_r < r) {
			v.emplace_back(l, r);
			prev_r = r;
		}
	}
	v.emplace_back(N + 1, N + 1);
	comb_init(N);
	dp[0][0] = 1;
	for (int i = 0; i + 2 < v.size(); i++) {
		int now = max(v[i].second - v[i + 1].first + 1, 0);
		int nxt = max(v[i + 1].second - v[i + 2].first + 1, 0);
		int now_len = v[i + 1].second - v[i + 1].first + 1;
		for (int j = 0; j <= now; j++) {
			int one = j + cnt[v[i + 1].second] - cnt[v[i + 1].second - (now_len - now)];
			for (int k = 0; k <= min(one, now_len - nxt); k++) {
				if (one - k > nxt) continue;
				(dp[i + 1][one - k] += (dp[i][j] * comb(now_len - nxt, k)) % MOD) %= MOD;
			}
		}
	}
	cout << dp[v.size() - 2][0] << endl;
}


Measured memory_bytes: 33408
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;

int main(){
    int N, X;
    int m;
    cin >> N >> X;
    
    int mm = 1<<30;
    for (int i=0; i < N; i++){
        cin >> m;
        if (mm>m) mm=m;
        X -= m;
    }
    
    cout << N + X / mm << endl;
}

Measured memory_bytes: 256
N, C, K, *T = map(int, open(0).read().split())
T.sort()
# print(N, C, K, T)

if C == 1:
    print(N)
    exit()

ans = 0
for i in range(N):
    t = T[i]
    if t == -1:
        continue
    remain = C - 1
    for j in range(i + 1, N):
        tj = T[j]
        if tj == -1:
            continue
        if tj > t + K:
            break
        remain -= 1
        T[j] = -1
        if remain == 0:
            break
    ans += 1

print(ans)


Measured memory_bytes: 14052
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
typedef long long ll;

int main() {
    int A, B;
    cin >> A >> B;
    if(A >= 10 || B >= 10) {
        cout << -1 << endl;
    } else {
        cout << A * B << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define finish(x) return cout << x << endl, 0
#define ll long long
 
int n;
ll base = 137, mod = 5729857252333;
vector <string> a;
unordered_map <ll, int> cnt;
 
ll add(ll hash, char c){
    return (1LL * hash * base + c - 'a' + 1) % mod;
}
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> n;
    a.resize(n);
    for(auto &i : a) cin >> i;
    sort(a.begin(), a.end(), [&](string &l, string &r){
        return l.size() > r.size();
    });
    for(auto &i : a){
        reverse(i.begin(), i.end());
    }
    unordered_set <ll> all;
    for(auto &i : a){
        ll h = 0;
        for(auto &j : i){
            h = add(h, j);
        }
        all.insert(h);
    }
    ll ans = 0;
    vector <int> cs(200);
    for(auto &i : a){
        ll h = 0;
        for(auto &j : i){
            h = add(h, j);
        }
        ans += cnt[h];
        h = 0;
        for(auto &j : i) cs[j]++;
        for(int j = 0 ; j < (int)i.size() ; j++){
            for(char k = 'a' ; k <= 'z' ; k++){
                if(cs[k] == 0) continue;
                ll cur = add(h, k);
                if(all.count(cur)) cnt[cur]++;
            }
            h = add(h, i[j]);
            cs[i[j]]--;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 26004
#include <bits/stdc++.h>
using namespace std;
void print() {
    cout << endl;
}
template <class Head, class... Tail>
void print(Head &&head, Tail &&... tail) {
    cout << head;
    if (sizeof...(tail) != 0)
        cout << " ";
    print(forward<Tail>(tail)...);
}
template <class T>
void print(vector<T> &vec) {
    for (auto &a : vec) {
        cout << a;
        if (&a != &vec.back())
            cout << " ";
    }
    cout << endl;
}
template <class T>
void print(vector<vector<T>> &df) {
    for (auto &vec : df) {
        print(vec);
    }
}
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define xrep(i, a, b) for (int i = int(a); i < int(b); ++i)
using ll = long long;
const int INF = 1001001001;

int main() {
    int N;
    cin >> N;
    vector<int> P(N);
    vector<int> Q(N);

    rep(i, N) {
        cin >> P[i];
    }
    rep(i, N) {
        cin >> Q[i];
    }
    auto Pd = P;
    auto Qd = Q;

    sort(P.begin(), P.end());
    sort(Q.begin(), Q.end());
    int cnt_a = 0;
    do {
        cnt_a++;
        if(P==Pd) break;
    } while(next_permutation(P.begin(), P.end()));
    int cnt_b = 0;
    do {
        cnt_b++;
        if(Q==Qd) break;;
    } while(next_permutation(Q.begin(), Q.end()));
    print(abs(cnt_a-cnt_b));
    return 0;
}

Measured memory_bytes: 3628
a,b,m=map(int,input().split(" "))
freezers=list(map(int,input().split(" ")))
microwaves=list(map(int,input().split(" ")))
cooponList=[list(map(int,input().split(" "))) for i in range(m)]

minimum=min(freezers)+min(microwaves)
cost=0
for i in range(m):
    cost=freezers[cooponList[i][0]-1]+microwaves[cooponList[i][1]-1]-cooponList[i][2]
    if cost<minimum:
        minimum=cost

print(minimum)

Measured memory_bytes: 38564
string = gets.chomp.split("")
even = []
odd = []

string.each_index do |idx|
  if idx % 2 != 0
    even.push(string[idx]).uniq
    even.delete("U")
    even.delete("D")
    even.delete("L")
  else
    odd.push(string[idx]).uniq
    odd.delete("U")
    odd.delete("D")
    odd.delete("R")
  end
end

even.empty? && odd.empty? ? answer = "Yes" : answer = "No"

puts answer

Measured memory_bytes: 1788
import sys

input()
a = list(map(int, sys.stdin.readline().split()))

c = 0
ans = 0
for i in a:
    if i == 0:
        ans = max(c, ans)
        c = 0
    else:
        c += 1
if c != 0:
    ans = max(c, ans)
    
print(ans+1)


Measured memory_bytes: 5596
#include <bits/stdc++.h> 
using namespace std; 
#define vll vector<long long>
#define mll map<long long,long long>
#define pb push_back
typedef  long long ll;
typedef long double ld;
long double pi=3.14159265358979323846;

vll al[500005];
ll vis[500005],color[500005],I[101][101];

ll gcd(ll a,ll b)
{
    if (b==0) return a;
    return gcd(b,a%b);
}

bool isPrime(int n)
{
    if (n<=1) return false; 
    if (n<=3) return true; 
    if (n%2==0||n%3==0) return false; 
    for (int i=5;i*i<=n;i=i+6) if (n%i==0||n%(i+2)==0) return false; 
    return true; 
}

ll bpow(ll n, ll po)
{
	ll res=1;
	while(po>0)
	{
		if(po%2)
		{
			res*=n;
			po--;
		}
		else
		{
			n*=n;
			po/=2;
		}
	}
	return res;
}

ll binpow(ll n, ll po, ll mod)
{
	ll res=1;
	while(po>0)
	{
		if(po%2)
		{
			res=(res*n)%mod;
			po--;
		}
		else
		{
			n=(n*n)%mod;
			po/=2;
		}
	}
	return res;
}

ll swap(ll a, ll b)
{
	a=a+b;
	b=a-b;
	a=a-b;
}

ll fact(ll n) { 
   if ((n==0)||(n==1))
      return 1;
   else
      return n*fact(n-1);
}

ll C(ll n, ll r) {
    if(r > n - r) r = n - r; 
    ll ans = 1;
    ll i;

    for(i = 1; i <= r; i++) {
        ans *= n - r + i;
        ans /= i;
        ans=ans%1000000007;
    }

    return ans;
}

//bool bipartite_dfs(ll node, ll flag)
//{
//	vis[node]=1;
//	ll cflag=flag;
//	color[node]=cflag;
//	for(ll child : al[node])
//	{
//		if(!vis[child])
//		{
//			bool n=bipartite_dfs(child,1-cflag);
//			if(n==false) return false;
//		}
//		else if(color[child]==color[node]) return false;
//	}
//	return true;
//}

void mmul(ll A[][101], ll B[][101], ll dim)
{
	ll res[dim][dim];
	for(ll i=0;i<dim;i++) for(ll j=0;j<dim;j++)
	{
		res[i][j]=0;
		for(ll k=0;k<dim;k++) res[i][j]=(res[i][j]+A[i][k]*B[k][j])%1000000007;
	}
	for(ll i=0;i<dim;i++) for(ll j=0;j<dim;j++) A[i][j]=res[i][j];
}

void mpow(ll A[][101],ll dim, ll po)
{
	for(ll i=0;i<dim;i++) for(ll j=0;j<dim;j++)
	{
		if(i==j) I[i][j]=1;
		else I[i][j]=0;
	}
	while(po>0)
	{
		if(po%2==1)
		{
			mmul(I,A,dim);
			po--;
		}
		else
		{
			mmul(A,A,dim);
			po/=2;
		}
	}
	for(ll i=0;i<dim;i++) for(ll j=0;j<dim;j++) A[i][j]=I[i][j];
}



int main()
{
	ll k,a,b;
	cin>>k>>a>>b;
	ll flag=0;
	for(ll i=a;i<=b;i++)
	{
		if(i%k==0) flag=1;
	}
	if(flag) cout<<"OK";
	else cout<<"NG";
}


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

using namespace std;

#define rep(i, n) REP(i, 0, (n))
#define REP(i, a, n) for(typeof(n) i=(a); i<(n); i++)

int main() {
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	if((abs(a-b)<=d && abs(b-c) <= d) || abs(a-c) <= d) cout << "Yes" << endl;
	else cout << "No" << endl;
}


Measured memory_bytes: 256
def insertionSort(L, n):
  for i in range(n):
    v = L[i]
    j = i - 1
    while j >= 0 and L[j] > v:
      L[j+1] = L[j]
      j -= 1
    L[j+1] = v
    print(' '.join(map(str, L)))

N = int(input())
A = list(map(int, input().split()))
insertionSort(A, N)


Measured memory_bytes: 5604
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string a,b;
    cin>>a>>b;
    int one=stoi(a);
    int two=stoi(b);

    string ans1,ans2;
    for(int i=0;i<two;i++)ans1+=a[0];
    for(int i=0;i<one;i++)ans2+=b[0];

    if(ans1.size() >ans2.size())cout<<ans1<<endl;
    else cout<<ans2<<endl;









    return 0;







}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#define N 100005
using namespace std;
typedef long long ll;

ll n, vt[N], ans[N];
vector<ll> tr[N], tw[N];

void f(ll p, ll q) {
	if(vt[p]) return;
	vt[p] = 1;
	ans[p] = q%2;
	for(ll i=0; i<tr[p].size(); i++) {
		f(tr[p][i], q + tw[p][i]);
	}
}

int main() {
	ll i, u, v, w;
	cin >> n;
	for(i=0; i<n-1; i++) {
		scanf("%lld%lld%lld", &u, &v, &w);
		tr[u].push_back(v); tw[u].push_back(w);
		tr[v].push_back(u); tw[v].push_back(w);
	}
	f(1, 0);
	for(i=1; i<=n; i++) printf("%lld\n", ans[i]);
	return 0;
}


Measured memory_bytes: 14720
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-9;
const ll mod=1e9+7;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

int a[5],k;

int main(){
	for(auto &i:a) cin>>i;
	sort(a,a+5);
	cin>>k;
	if(a[4]-a[0]>k) cout<<":("<<endl;
	else cout<<"Yay!"<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define data_type long long
#define endl "\n"
#define mod 1000000007
int main()
{
    data_type n,sum=0;
    cin>>n;
    vector<data_type>vc(n),prefix(n);
    for(auto &i:vc)
        cin>>i;
    prefix=vc;
    for(int i=n-2; i>=0; i--)
        prefix[i]+=prefix[i+1],prefix[i]%=mod;
    for(int i=0; i<n-1; i++)
        sum+=(vc[i]*prefix[i+1])%mod,sum%=mod;

    cout<<sum<<endl;

    return 0;

}



Measured memory_bytes: 6356
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
using ll = long long ;
using P = pair<int,int> ;
using pll = pair<long long,long long>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e17;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979323846;

#include <atcoder/all>
using namespace atcoder;

int main(){
    int n,q;
    cin >> n >> q;
    fenwick_tree<ll> ft(n);
    rep(i,n){
        int a;
        cin >> a;
        ft.add(i,a);
    }

    while(q--){
        int t;
        cin >> t;
        if(t==0){
            int p,x;
            cin >> p >> x;
            ft.add(p,x);
        }else{
            int l,r;
            cin >> l >> r;
            cout << ft.sum(l,r) << endl;
        }
    }
}

Measured memory_bytes: 8212
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
A=[0]
B=[0]
for i in range(n):
    A.append(a[i]+A[i])
for j in range(m):
    B.append(b[j]+B[j])

i=0
j=m
ans=0
tmp=0
while(i<n+1 and j>=0):
    if(k>=A[i]):
        tmp=k-A[i]
        if(tmp-B[j]>=0):
            ans=max(ans,i+j)
            i+=1
        else:
            j-=1
    else:
        break
print(ans)
        
    

            


Measured memory_bytes: 47492
/*
 _ _ _   _    _   _    _   _ _ _   _    _   _ __ _   __       __
|  _ _| | |  | | | |  | | |  _  | | |  | | |  __  | |   \   /   |
| |_ _  | |__| | | |  | | | |_| | | |__| | | |__| | | |\ \_/ /| |
|_ _  | |  __  | | |  | | |  _ <  |  __  | |  __  | | | \   / | |
 _ _| | | |  | | | |__| | | |_| | | |  | | | |  | | | |  \_/  | |  _   _   _
|_ _ _| |_|  |_| |_ __ _| |_ _ _| |_|  |_| |_|  |_| |_|       |_| |_| |_| |_|

*/

#include <bits/stdc++.h>
using namespace std;

#define ll long long int
#define fi first
#define se second
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define debug(a) cout << #a << " = " << a << " ";
#define endl "\n"
const int  MOD=1000000007;

const int N=100010;
vector<long > g[N];
long tak[N],aok[N];

void dfs1(long nd,long cnt){
    for(int i=0;i<g[nd].size();i++){
        long nex=g[nd][i];
        if(tak[nex]!=0)
            continue;
        tak[nex]=cnt+1;
        dfs1(nex,cnt+1);
    }
}

void dfs2(long nd,long cnt){
    for(int i=0;i<g[nd].size();i++){
        long nex=g[nd][i];
        if(aok[nex]!=0)
            continue;
        aok[nex]=cnt+1;
        dfs2(nex,cnt+1);
    }
}

void solve(){
    long n;
    cin>>n;
    long u,v;
    cin>>u>>v;
    for(int i=0;i<n-1;i++){
        long x,y;
        cin>>x>>y;
        g[x].pb(y);
        g[y].pb(x);
    }
    tak[u]=1,aok[v]=1;
    dfs1(u,1);
    dfs2(v,1);
    long ans=0;
    for(int i=1;i<=n;i++){
        if(aok[i]>tak[i])
            ans=max(ans,aok[i]);
    }
    cout<<ans-2<<endl;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    long int t = 1;
    // cin>>t;
    for (long int tt = 1; tt <= t; tt++) {
        solve();
    }
    return 0;
}


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

int main(){
    int ans=0, a=0, b=0, c=0;
    char tmp;
    vector<char> S;
    string T;
    cin >> T;
    for(int i=0; i<T.size(); i++){
		
	if(T[i]=='B'){
	    if(S.size() == 0)
		continue;
	    S.pop_back();
	}
	else
	    S.push_back(T[i]);
    }
    
    for(int i=0; i<S.size(); i++){
	cout <<S[i];
    }
    cout << endl;;

    
}


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

typedef vector<int> vi;

const int INF = (int)(1e+9);
int N;
vi B;
vi A;

void input_init(void) {
	cin >> N;
	B.resize(N + 1);
	for (int i = 1; i < N; ++i)
		cin >> B[i];
	A.resize(N + 1, INF);
}

int solve(void) {
	if (N == 2)
		return 2 * B[1];
	for (int i = 1; i < N; ++i) {
		A[i - 1] = min(B[i], A[i - 1]);
		A[i] = B[i];
	}
	int sum = 0;
	for (int i = 0; i < N; ++i)
		sum += A[i];
	return sum;
}

int main(void) {
	input_init();
	int ans = solve();
	cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <stack>
#include <vector>
using namespace std;
typedef long long ll;

int gcd(int a,int b){
  if(b == 0)return a;
  return gcd(b,a%b);
}

int main(){
  int n,k;
  cin >> n >> k;
  vector<int> a(n);
  for(int i = 0;i < n;i++)cin >> a[i];

  if(n == 1){
    if(a[0] == k)cout << "POSSIBLE" << endl;
    else cout << "IMPOSSIBLE" << endl;
  }
  else{
    int all_gcd = gcd(a[0],a[1]);

    for(int i = 0;i < n;i++){
      all_gcd = gcd(all_gcd,a[i]);
    }

    if(k <= *max_element(a.begin(),a.end()) && k % all_gcd == 0)cout << "POSSIBLE" << endl;
    else cout << "IMPOSSIBLE" << endl;
  }
}

Measured memory_bytes: 640
from functools import lru_cache
mod=1000000007

n,k=[int(i) for i in input().split(" ")]

@lru_cache()
def power(m,n,mod):
    if n==0:
        return 1
    elif n==1:
        return m
    elif n%2==0:
        return ((power(m,n//2,mod)%mod) * (power(m,n//2,mod)%mod))%mod
    else:
        return (power(m,n-1,mod)*m)%mod

print(power(k,n,mod))



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

int main() {
    int a, b, c, k;
    cin >> a >> b >> c >> k;
    if (a + b >= k) {
        cout << min(a, k) << endl;
    } else {
        cout << a - (k - a - b) << endl;
    }
}


Measured memory_bytes: 3604
import itertools

n = int(input())
a = [ str(x) for x in range(1,n+1)]
jun = list(itertools.permutations(a))
p = list(map(str, input().split()))
q = list(map(str, input().split()))
p = ''.join(p)
q = ''.join(q)
a = []

for i in jun:
    i = list(i)
    a.append(''.join(i))
x = a.index(p)
y = a.index(q)
print(abs(x-y))





Measured memory_bytes: 10868
def cross_product(a,b):
  return (a.conjugate()*b).imag
P = [] #頂点列
try:
    while True:
        x,y = map(float,input().split(','))
        P.append(complex(x,y))
except EOFError:
    pass
N=len(P)#頂点の個数
total = 0.0
for i in range(1,N-1):
    a,b,c = P[0],P[i],P[i+1]
    total += cross_product(b-a,c-a)
print("%.6f" % (abs(total)/2.0))




Measured memory_bytes: 5584
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define INF ((1LL<<62)-(1LL<<31))
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define bit(n,m)(((n)>>(m))&1)
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}
ll pom(ll a,ll n,int m){ll x=1;for(a%=m;n;n/=2)n&1?x=x*a%m:0,a=a*a%m;return x;}
//#define MOD 998244353
#define MOD 1000000007
#define invp(a,p)pom(a,p-2,p)

ll n;
ll a[2010];
int f(ll x){
	if(a[0]>=x)return 0;
	int l=0,r=n;
	while(r-l>1){
		int m=(l+r)/2;
		if(a[m]>=x)r=m;
		else l=m;
	}
	return r;
}
ll ans;
int main(){
	scanf("%lld",&n);
	rep(i,0,n)scanf("%lld",a+i);
	sortup(a,n);
	rep(i,0,n)rep(j,i+1,n){
		//a[i]+a[j]以上になる最小のindex
		int k=f(a[i]+a[j]);
		ans+=max(0,k-j-1);
	}
	printf("%lld",ans);
}

Measured memory_bytes: 252
/*
これを入れて実行
g++ code.cpp
./a.out
 */
 
#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <cmath>
#include <math.h>
#include <tuple>
#include <iomanip>
 
using namespace std;
typedef long long ll;
typedef long double ld;
 
int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};
 
const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;
 
bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}
 
ll gcd(ll a, ll b){
	if (b == 0)return a;
	return gcd(b, a % b);
}
 
ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}
 
ll nCr(ll n, ll r){
    if(r == 0 || r == n){
        return 1;
    } else if(r == 1){
        return n;
    }
    return (nCr(n - 1, r) + nCr(n - 1, r - 1));
}
 
ll nPr(ll n, ll r){
    r = n - r;
    ll ret = 1;
    for (ll i = n; i >= r + 1; i--) ret *= i;
    return ret;
}
 
//-----------------------ここから-----------

bool comp(const pair<int, int>& f, const pair<int, int>& s){
    return f.second < s.second;
}

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

    vector<pair<int,int>> p(n);

    for(int i = 0; i < n; i++){
        cin >> p[i].second >> p[i].first;
    }

    priority_queue<int, vector<pair<int,int>>> q;

    sort(p.begin(), p.end(), comp);

    int cnt = 0;
    ll ans = 0;
    for(int i = 1; i <= m; i++){
        while(cnt < n){
            if(p[cnt].second <= i){
                q.push(p[cnt]);
                // cout << p[cnt].first << p[cnt].second << endl;
                cnt++;
            } else {
                break;
            }
        }
        if(q.empty()) continue;
        pair<int, int> tmp = q.top();
        q.pop();
        // cout << tmp.first << tmp.second << endl;
        ans += tmp.first;
    }

    cout << ans << endl;
}

Measured memory_bytes: 2168