akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll MOD = (1e+9)+7;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-11;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
typedef pair<ld, ld> LDP;
typedef pair<P, int> PP;
ll p[100002];
void init() {
	p[0] = 1;
	for (ll i = 1; i < 100002; i++) {
		p[i] = p[i - 1] * i%MOD;
	}
}
//x,yがax+by=gcd(a,b)の解になる
ll extgcd(ll a, ll b, ll& x, ll& y) {
	ll d = a;
	if (b != 0) {
		d = extgcd(b, a%b, y, x);
		y -= (a / b)*x;
	}
	else {
		x = 1; y = 0;
	}
	return d;
}
//aの逆元を求める
ll mod_inverse(ll a) {
	ll x, y;
	extgcd(a, MOD, x, y);
	return (MOD + x % MOD) % MOD;
}
//y個からxを選ぶ
ll count(int x, int y) {
	if (x > y)return 0;
	ll res = p[y];
	(res *= mod_inverse(p[x])) %= MOD;
	(res *= mod_inverse(p[y - x])) %= MOD;
	return res;
}
int main(){
	init();
	int n; cin >> n;
	int a[100001]; int used[100001] = {};
	int chk;
	rep(i, n + 1) {
		cin >> a[i]; a[i]--;
		if (used[a[i]])chk = a[i];
		else used[a[i]] = 1;
	}
	int cnt = 0;
	bool f = true;
	rep(i, n + 1) {
		if (f)cnt++;
		if (a[i] == chk)f = !f;
	}
	cnt--;
	rep1(k, n + 1) {
		cout << (count(k, n + 1) - count(k - 1, cnt) + MOD) % MOD << endl;
	}
	return 0;
}

Measured memory_bytes: 2816
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication33
{
    class Program
    {
        static void Main()
        {
            string[] a = Console.ReadLine().Split();int b = 0,f=0,m=0; string r = null, p = null;
            for(int c = 0; c < a.Length; c++)
            {
                if (a[c].Length > b) { b = a[c].Length; r = a[c]; }
                for(int t = 0; t < a.Length; t++)
                {
                    if (a[c] == a[t]) f++;
                }
                if (m < f) { m = f; p = a[c]; }
                f = 0;
            }
            Console.WriteLine(p+" "+r);
        }
    }
}

Measured memory_bytes: 8780
using System;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] nk = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); 
            long[] p = Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse);

            double[] sums = new double[nk[0]+nk[1]];
            double temp = 0;
            for (int i = 0; i < nk[0]; i++)
            {
                sums[i] = temp + ((double)(p[i]+1)/2);
                temp = sums[i];
            }

            double res = sums[0+nk[1]-1];
            for (int i = 1; i < nk[0]; i++)
            {
                res = Math.Max(res, sums[i + nk[1]-1] - sums[i-1]);
            }
            Console.WriteLine(res);
        }
    }
}


Measured memory_bytes: 30556
#include<stdio.h>
int main(void){
  int n=0,i;
  char s[5];
  scanf("%s",s);
  for(i=0;i<4;i++){
    if(s[i]=='+'){
      n ++;
    }
    else n--;
  }
  printf("%d",n);
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <cstring>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<long long, long long> P;
#define rep(i, n) for(long long i=0; i<n; i++)
#define reps(i, s, e) for(long long i=s; i<e; i++)
#define repr(i, n) for(long long i=n-1; i>=0; i--)
#define reprs(i, s, e) for(long long i=e-1; i>=s; i--)

int main(){

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

    ll n, m; cin >> n >> m;
    ll a[m], b[m];
    rep(i, m){
        cin >> a[i] >> b[i];
        a[i]--; b[i]--;
    }

    vector<ll> g[n];
    rep(i, m){
        g[a[i]].push_back(b[i]);
        g[b[i]].push_back(a[i]);
    }

    ll signal[n];
    memset(signal, -1, sizeof(signal));

    queue<ll> que;
    que.push(0);

    while(!que.empty()){
        ll p_now = que.front();
        que.pop();

        for(ll p_nxt : g[p_now]){
            if(signal[p_nxt] != -1) continue;

            signal[p_nxt] = p_now;
            que.push(p_nxt);
        }
    }

    cout << "Yes" << endl;
    reps(i, 1, n){
        cout << signal[i] + 1 << endl;
    }

    return 0;
}

Measured memory_bytes: 16084
#include <stdio.h>

int main(void)
{
    int N,i,f=0,harf;
    char S[200];

    scanf("%d",&N);
    harf=N/2;
    
    scanf("%s",S);
    
    if(N%2 == 0){
        for(i=0; i<N/2; i++){
            if(S[i] != S[harf+i]){
                f=1;
            }
        }
    } else {
        f=1;
    }
    
    
    if(f==0){
        printf("Yes\n");
    } else {
        printf("No\n");
    }
    
    return 0;
}

Measured memory_bytes: 128
#include <cstdio>
#include <cmath>

long long p[19][19];
long long sum[20][20];

int main(){
    double x;
    long long a;
    int n;
    scanf("%d", &n);
    int i;
    for(i = 0; i < n; ++i){
        scanf("%lf", &x);
        x *= 1000000000;
        a = llround(x);
        int n2 = 0, n5 = 0;
        while(a % 2 == 0){
            ++n2;
            a /= 2;
        }
        while(a % 5 == 0){
            ++n5;
            a /= 5;
        }
        if(n2 > 18)
            n2 = 18;
        if(n5 > 18)
            n5 = 18;
        ++p[n2][n5];
    }
    int j;
    for(i = 18; i >= 0; --i)
        for(j = 18; j >= 0; --j)
            sum[i][j] = p[i][j] + sum[i + 1][j] + sum[i][j + 1] - sum[i + 1][j + 1];
    long long ans = 0;
    for(i = 18; i >= 0; --i)
        for(j = 18; j >= 0; --j){
            if(i >= 18 - i && j >= 18 - j)
                ans += p[i][j] * (sum[18 - i][18 - j] - 1);
            else
                ans += p[i][j] * sum[18 - i][18 - j]; 
        }
    printf("%lld\n", ans / 2);
    return 0;
}


Measured memory_bytes: 2160
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using ll = long long;
using namespace std;

int main() {
    string s, t;
    cin >> s >> t;

    int length = s.length();
    int ans = 0;
    rep(i, length) {
        // 一致したら終わり
        if(s == t) {
            break;
        }

        if(s[i] != t[i]) {
            s[i] = t[i];
            ans++;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 3836
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <climits>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <fstream>

using namespace std;
#define SZ(x) (int)(x).size()
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REPR(i,n) for(int i=(n)-1;i>=0;i--)
#define ALL(s) (s).begin(), (s).end()
#define so(V) sort(ALL(V))
#define rev(V) reverse(ALL(V))
#define uni(v) v.erase( unique(ALL(v)) , v.end());

typedef long long unsigned int llu;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<bool> vb;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;
const int INF = (1 << 29);
const ll LINF = 1e18;
const double PI = acos(-1);

template<typename T>vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T, typename... Ts>auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...)); }
template<typename T, typename U, typename... V>
typename enable_if<is_same<T, U>::value != 0>::type
fill_v(U & u, const V... v) { u = U(v...); }
template<typename T, typename U, typename... V>
typename enable_if<is_same<T, U>::value == 0>::type
fill_v(U & u, const V... v) { for (auto& e : u) fill_v<T>(e, v...); }
template<class T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T& a, const T& b) { if (a > b) { a = b; return 1; } return 0; }

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


int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N;
	cin >> N;
	while (N != 0) {
		int n, d;
		//答え格納用ペア、第一引数が最小値、第二引数が最大値
		pair<int, int> X = make_pair(0, 0);
		pair<int, int> Y = make_pair(0, 0);
		int x = 0, y = 0;
		vector<pair<int, int> > Map;
		Map.push_back(make_pair(0, 0));
		REP(i, N - 1) {
			cin >> n >> d;
			x = Map[n].first + dx[d];
			y = Map[n].second + dy[d];
			Map.push_back(make_pair(x, y));
			chmin(X.first, x); chmax(X.second, x);
			chmin(Y.first, y); chmax(Y.second, y);
		}
		cout << (X.second - X.first + 1) << " " << (Y.second - Y.first + 1) << endl;
		cin >> N;
	}
	return 0;
}



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



signed main(){
    int x,y;
    string s;
    cin >> s>>x>>y;
    vector<int> w0,w1;
    int p=0,q=0;
    int i0=0;
    while(i0<s.length()&&s[i0]=='F'){
        i0++;
        p++;
    }
    w0.push_back(abs(x-p));
    w1.push_back(abs(y));
    int maxs=max(abs(x-p),abs(y));
    q=1;p=0;
    
    for(int i=i0+1;i<s.length();i++){
        if(s[i]=='F')p++;
        else{
            if(p!=0){
                if(q==0)w0.push_back(p);
                else w1.push_back(p);
                
                maxs=max(maxs,p);
            }
            p=0;
            q=  !q;
        }
    }
    if(q==0)w0.push_back(p);
    else w1.push_back(p);
                
    maxs=max(maxs,p);
    int k1[w0.size()][2*maxs+1];
    for(int i=0;i<w0.size();i++){
        for(int j=0;j<2*maxs+1;j++)k1[i][j]=0;
    }
    k1[0][maxs+w0[0]]=1;k1[0][maxs-w0[0]]=1;
    for(int i=1;i<w0.size();i++){
        for(int j=0;j<2*maxs+1-w0[i];j++){
            k1[i][j]=k1[i-1][j+w0[i]];
        }
        for(int j=0;j<2*maxs+1-w0[i];j++){
            k1[i][j+w0[i]]+=k1[i-1][j];
        }
    }
    int k2[w1.size()][2*maxs+1];
    for(int i=0;i<w1.size();i++){
        for(int j=0;j<2*maxs+1;j++)k2[i][j]=0;
    }
    k2[0][maxs+w1[0]]=1;k2[0][maxs-w1[0]]=1;
    for(int i=1;i<w1.size();i++){
        for(int j=0;j<2*maxs+1-w1[i];j++){
            k2[i][j]=k2[i-1][j+w1[i]];
        }
        for(int j=0;j<2*maxs+1-w1[i];j++){
            k2[i][j+w1[i]]+=k2[i-1][j];
        }
    }
    if(k1[w0.size()-1][maxs]!=0&&k2[w1.size()-1][maxs]!=0)cout << " Yes ";
    else cout << " No ";
   // cerr << maxs << endl;
    //for(int i=0;i<2*maxs+1;i++){
    //    cerr << w0[0]<<' ';
  //      cerr << k1[0][i]<<' ';
    //}

    return 0;
}

Measured memory_bytes: 247808
#include <iostream>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
#define MOD 1000000007
#define LL long long

//a^bをmodで割った剰余を返す
LL mod_pow(LL a, LL b){
  LL ret = 1;
  while(b > 0){
    if(b%2 == 1)
      ret = ret * a % MOD;
    a = a * a % MOD;
    b /= 2;
  }
  return ret;
}


//aCbを返す
LL mod_comb(LL a, LL b){
  LL num = 1; //numerator
  LL den = 1; //denominator
  //分子の計算
  rep(i, b)
    num = (num*a--)%MOD;

  //分母(=逆元 mod)の計算
  //階乗 mod MODの計算
  rep(i, b)
    den = den*(i+1)%MOD;
  //フェルマーの小定理による
  den = mod_pow(den, MOD-2);
  
  return num*den%MOD; 
}


int main(void){
  int X, Y; cin >> X >> Y;

  //X+Yが3の倍数でなければ(X, Y)にたどり着くことはできない
  if((X+Y)%3 != 0){
    cout << 0 << endl;
    return 0;
  }
    
  //(+1, +2)の移動をn回，(+2, +1)の移動をm回する
  int n = (2*Y-X)/3;
  int m = (2*X-Y)/3;

  //
  if(n<0 || m<0){
    cout << 0 << endl;
    return 0;
  }
  
  cout << mod_comb((LL)(n+m), (LL)n) << endl;

  return 0;
}


Measured memory_bytes: 256
n = input()

op_cnt = len(n) -1
for i in range(2**op_cnt):
    op = ["-"] * op_cnt
    for j in range(op_cnt):
        if ((i >> j) & 1):
            op[op_cnt -1 -j] = "+"
    
            
    formula = ""
    for p_n,p_o in zip(n, op + [""]):
        formula += (p_n + p_o)
    if eval(formula) == 7:
        s = formula+"=7"
        print(s)
        break

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

int main(void){
  int N, A, B;
  cin >> N >> A >> B;
  
  
  if ((A + B) % 2 == 0) {
    cout << "Alice" << endl;
  }
  else {
    cout <<  "Borys" << endl;
  }
  
}

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

int main(void) {
    double a, b, c, C, S, L, h;
    scanf("%lf %lf %lf", &a, &b, &C);
    c = C * M_PI / 180;
    S = a * b * sin(c) / 2;
    L = a + b + sqrt(a * a + b * b - 2 * a * b * cos(c));
    h = b * sin(c);
    printf("%f %f %f", S, L, h);
    return 0;
}

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

using namespace std;

int l[105];

int main(){
	int n,x; scanf("%d %d",&n,&x);
	for(int i=1; i<=n; i++) scanf("%d",&l[i]);
	int cur = 0;
	int ans = 1;
	for(int i=1; i<=n; i++){
		if(cur + l[i] > x){
			break;
		}
		ans++;
		cur += l[i];
	}
	printf("%d\n",ans);
	return 0;
}

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

#define fi first
#define se second
#define forn(i,n) for(int i=0; i< (int)n; ++i)
#define for1(i,n) for(int i=1; i<= (int)n; ++i)
#define fore(i,l,r) for(int i=(int)l; i<= (int)r; ++i)
#define ford(i,n) for(int i=(int)(n) - 1; i>= 0; --i)
#define fored(i,r,l) for(int i=(int)r; i>= (int)l; --i)
#define pb push_back
#define el '\n'
#define d(x) cout<< #x<< " " << x<<el

using namespace std;

typedef long long ll;
typedef pair<int,int> ii;
typedef pair<char,int> pci;
typedef tuple<int, int, int> tiii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;

const ll INF = LONG_LONG_MAX;
const double PI = atan(1)*4;
const int MAXN = 1e5+20;
const double EPS= 1e-10;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    cout<< setprecision(2)<< fixed;
    int p,q,r;
    cin>>p>>q>>r;
    int minimo= p+q;
    minimo= min(minimo, p+r);
    minimo= min(minimo, q+r);
    cout<<minimo<<el;
}



Measured memory_bytes: 256
N = int(input())

class Node():
    def __init__(self, parent=-1, left=-1, right=-1):
        self.parent = parent
        self.left = left
        self.right = right

T = [Node() for _ in range(N)]

for _ in range(N):
    id, left, right = map(int, input().split())

    T[id].left = left
    T[id].right = right

    if left != -1:
        T[left].parent = id
    if right != -1:
        T[right].parent = id


def preorder(id):
    preorder_list.append(id)

    if T[id].left != -1:
        preorder(T[id].left)
    if T[id].right != -1:
        preorder(T[id].right)

def inorder(id):
    left = T[id].left
    right = T[id].right

    if left != -1:
        inorder(T[id].left)
    inorder_list.append(id)

    if right != -1:
        inorder(right)

def postorder(id):
    left = T[id].left
    right = T[id].right

    if left != -1:
        postorder(left)

    if right != -1:
        postorder(right)

    postorder_list.append(id)

preorder_list = []
inorder_list = []
postorder_list = []
for id in range(N):
    if T[id].parent == -1:
        preorder(id)
        inorder(id)
        postorder(id)
        break


print("Preorder")
print(" "+" ".join(map(str, preorder_list)))
print("Inorder")
print(" "+" ".join(map(str, inorder_list)))
print("Postorder")
print(" "+" ".join(map(str, postorder_list)))


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

int main() {
  cout << fixed << setprecision(10);
  long double a, b, x;
  cin >> a >> b >> x;
  if (2*x - (a*a*b) >= 0) 
  	cout << atan(2.0 * (a*a*b - x) / (a * a * a)) * 180.0 / M_PI << endl;
  else
    cout << atan((a * b*b) / (2 * x)) * 180.0 / M_PI << endl;
}
  

Measured memory_bytes: 256
n,m=[int(_) for _ in input().split()]
ld=1
rd=n
for iii in range(m):
  l,r=[int(_) for _ in input().split()]
  if ld<l:
    ld=l
  if rd>r:
    rd=r
if ld<=rd:
  print(rd-ld+1)
else:
  print(0)

Measured memory_bytes: 3188
import java.util.Scanner;
class Main{
public static void main(String[] args)
{
  Scanner sc=new Scanner(System.in);
  int[] a=new int[3];
  a[0]=sc.nextInt();
  a[1]=sc.nextInt();
  a[2]=sc.nextInt();
  //swpaing
  int temp;
  temp=a[0];
  a[0]=a[1];
  a[1]=temp;
  int temp2;
  temp2=a[0];
  a[0]=a[2];
  a[2]=temp2;
  for(int i=0;i<a.length;i++)
  {
    System.out.print(a[i]+" ");
  }
}
}

Measured memory_bytes: 22612
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC061C
{
    class Program
    {
        class Number
        {
            public int a, b;
        }

        static void Main(string[] args)
        {
            int N;
            long K;
            string[] vals = Console.ReadLine().Split(' ');

            N = int.Parse(vals[0]);
            K = long.Parse(vals[1]);

            List<Number> list = new List<Number>();
            for (int i = 0; i < N; i++)
            {
                vals = Console.ReadLine().Split(' ');
                Number n = new Number();
                n.a = int.Parse(vals[0]);
                n.b = int.Parse(vals[1]);
                list.Add(n);
            }

            list.Sort((n,m) => n.a - m.a);

            long count = 0;
            foreach(var n in list)
            {
                count += n.b;
                if(K <= count)
                {
                    Console.WriteLine(n.a);
                    return;
                }
            }

        }
    }
}


Measured memory_bytes: 23108
#include <iostream>

long long gcd(long long a, long long b) {
    long long r = a % b;
    return r ? gcd(b, r) : b;
}

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

int main() {
    long long A, B, C, D;
    std::cin >> A >> B >> C >> D;

    long long E = lcm(C, D);

    long long ans = B - A + 1;
    ans -= B / C - (A - 1) / C;
    ans -= B / D - (A - 1) / D;
    ans += B / E - (A - 1) / E;
    std::cout << ans << "\n";
}

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

move = [-1] * N
point = 0
count = 0
L = [0]
while True:
    if move[point] != -1:
        break
    move[point] = A[point] - 1
    point = move[point]
    L.append(point)
    count += 1
loop_start = L.index(move[point])
loop_L = L[loop_start:]

if K <= count:
    print(L[K] + 1)
    exit()
print(loop_L[(K - count - 1) % len(loop_L)] + 1)




Measured memory_bytes: 32408
#include <iostream>
#include <algorithm>//sort
#include <vector>
#include <string>
#include <map>//pair
#define rep(i, n) for(int i = 0; i < n; i++)

using namespace std;

int main(){
  int N, A[102];
  cin >> N;
  rep(i, N){
    cin >> A[i];
  }
  bool flag = true;
  rep(i, N){
    if(A[i] % 2 == 0){
      if(A[i] % 3 != 0 && A[i] % 5 != 0){
        flag = false;
        //cout << A[i] << endl;
      }
    }
  }
  if(flag) cout << "APPROVED" << endl;
  else cout << "DENIED" << endl;
}


Measured memory_bytes: 256
/*
for (int i = 0; i < N; ++i){}

// 各桁の和を計算する関数
int findSumOfDigits(int n) {
  int sum = 0;
  while (n > 0) { // n が 0 になるまで
    sum += n % 10;
    n /= 10;
  }
  return sum;
}

sort(a, a + N, greater<int>());  // a[0:N] を大きい順にソート

int num[110] = {0};  // バケット
for (int i = 0; i < N; ++i) {
    num[d[i]]++;  // d[i] が 1 個増える
}

map<string, int> mp; // 連想配列 map<キー型, 値型> オブジェクト名
for (int i = 0; i < N; ++i) {
    auto itr = mp.find(s[i]);        // s[i] が設定されているか？
    if(itr != mp.end() ) {
         mp[s[i]] += 1;
    }
    else {
         mp[s[i]] += 1 ;
    }
}
stack<int> s;	//intをデータとするスタックを用意
s.push(1);		//{} -> {1}
printf("%d\n", s.top());	// 3
s.pop();

queue<int> que;	//intをデータとするキューを用意
que.push(1);		//{} -> {1}
printf("%d\n", que.front());	// 1
que.pop();
*/
#include <iostream>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>

using namespace std;

// #define for(i,a,b) for (int i=(a);i<(b);++i)
typedef long long ll;
typedef pair<int,int> point;
#define rep(i,n) for(i,0,n)

// int 
// // 各桁の和を計算する関数
// int findSumOfDigits(int n) {
//   int amari = 0;
//   int keta = 0;
//   while (n > 0) { // n が 0 になるまで
//     amari += n % 2;
//     if (keta%2==0)
//     n /= 10;
//   }
//   return sum;
// }
 
ll gcd(ll m, ll n){
	// 引数に０がある場合は０を返す
	if ( ( 0 == m ) || ( 0 == n ) )
		return 0;
	
	// ユークリッドの方法
	while(m!=n){
		if (m>n) m = m - n;
		else n = n - m;
	}
	return m;
}

ll lcm( ll m, ll n )
{
	// 引数に０がある場合は０を返す
	if ( ( 0 == m ) || ( 0 == n ) )
		return 0;
	
	return ((m / gcd(m, n)) * n); // lcm = m * n / gcd(m,n)
}//lcm


int main() {
	// 入力
	ll N, M;
	string S, T;
	cin >> N >> M >> S >> T;
 
	// 解法
	ll ans = lcm(N, M);
	ll GCD = gcd(N, M);
	ll L_per_N = ans/N;
	ll L_per_M = ans/M;
	// cout << ans << endl;
	// cout << GCD << endl;
	for (int i = 0; i < GCD; ++i){
		// cout << "i " << i << " S " << S[L_per_M*i] << " T " << T[L_per_N*i] << endl;
		if (S[L_per_M*i]!=T[L_per_N*i]) ans = -1;
	}
	cout << ans << endl;
}
 


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

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

#define forn(i, a, n) for (int i = a; i < n; ++i)
#define ford(i, a, n) for (int i = n - 1; i >= a; --i)
#define fore(i, a, n) for (int i = a; i <= n; ++i)
#define all(a) (a).begin(), (a).end()
#define fs first
#define sn second
#define trace(a)\
	for (auto i : a) cerr << i << ' ';\
	cerr << '\n'
#define eb emplace_back

#ifndef M_PI
const ld M_PI = acos(-1.0);
#endif

const ld eps = 1e-9;
const int INF = 2000000000;
const ll LINF = 1ll * INF * INF;
const ll MOD = 1000000007;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	string s;
	cin >> s;
	map<char, int> m;
	for (char c : s) m[c]++;
	bool ok = true;
	ok &= (bool)m.count('W') == (bool)m.count('E');
	ok &= (bool)m.count('S') == (bool)m.count('N');
	cout << (ok ? "Yes\n" : "No\n");
	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
#define rep(i,n) for (int i=0; i<n;++i)
#define rep_down(i,n) for (int i=n-1; i>=0;--i)
typedef long long ll;
using namespace std;
const ll MOD = 1000000007LL;
const int INF = 1000000007;
int N;
ll T[101];
ll L[101];

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

ll lcm(ll a, ll b) {
    ll g = gcd(a, b);
    return a / g * b;
}

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

  cin >> N;
  ll ans = 1ll;
  rep(i, N){
    cin >> T[i];
    ans = lcm(ans, T[i]);
    L[i] = ans;
  }

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
double H, N, A;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin >> H >> N;
	for (int i = 0; i < N; i++)
	{
		cin >> A;
		H -= A;
	}
	cout << (H > 0 ? "No" : "Yes") << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main{
  public static void main(String[] args) {
    Scanner sc=new Scanner(System.in);
    String n=sc.next();
    boolean ans=false;
    for (int i=0;i<2;i++) {
      if (n.charAt(i)==n.charAt(i+1)) {
        if (n.charAt(i+1)==n.charAt(i+2)) {
          ans=true;
        }
      }
    }

    if (ans==false) {
      System.out.println("No");
    }else{
      System.out.println("Yes");
    }
  }
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
typedef long long ll;
long long mod = 1e9 + 7;
const int iINF = 0x3f3f3f3f;
const long long INF = 1LL << 60;
using namespace std;
using pint = pair<int, int>;

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

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

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

  reverse(x.begin(), x.end());
  int t_count = 0;
  int ans = 0;

  for (char c : x)
  {
    if (c == 'S')
    {
      if (t_count > 0)
      {
        t_count--;
      }
      else
      {
        ans++;
      }
    }
    else
    {
      t_count++;
    }
  }

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

Measured memory_bytes: 3688
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
typedef pair<int, int> P;
ll Mod = 1000000007;
int N,M,R;
int Graph[250][250];
int dist[250][250];


void dijkstra() {
  for (int i = 0; i < N; i++) {
    int nowd[N];
    for (int j = 0; j < N; j++) {
      nowd[j] = 99999999;
    }
    
    priority_queue<P, vector<P>, greater<P>> Q;
    while (!Q.empty()) {
      Q.pop();
    }
    Q.push(make_pair(0,i));
    while (!Q.empty()) {
      P p = Q.top();
      Q.pop();
      if (nowd[p.second] < p.first) {
        continue;
      }
      for (int j = 0; j < N; j++) {
        if (i == j) {
          continue;
        }
        if (nowd[j] > p.first + Graph[p.second][j]) {
          nowd[j] = p.first + Graph[p.second][j];
          Q.push(make_pair(p.first + Graph[p.second][j],j));
        }
      }
    }
    for (int j = 0; j < N; j++) {
      if (i == j) {
        dist[i][j] = 0;
      }
      dist[i][j] = nowd[j];
    }
  }
}

int main() {
  cin >> N >> M >> R;
  int r[R];
  for (int i = 0; i < R; i++) {
    cin >> r[i];
    r[i]--;
  }
  sort(r,r+R);
  for (int i = 0; i < 250; i++) {
    for (int j = 0; j < 250; j++) {
      Graph[i][j] = 99999999;
      dist[i][j] = 99999999;
    }
  }
  for (int i = 0; i < 250; i++) {
    Graph[i][i] = 0;
  }
  for (int i = 0; i < M; i++) {
    int a,b,c;
    cin >> a >> b >> c;
    a--;
    b--;
    Graph[a][b] = c;
    Graph[b][a] = c;
  }
  
  dijkstra();
  
  int ans = 99999999;
  do {
    int result = 0;
    for (int i = 1; i < R; i++) {
      result += dist[r[i-1]][r[i]];
    }
    ans = min(ans,result);
} while(next_permutation(r,r + R));
  cout << ans << endl;
  return 0; 
}

Measured memory_bytes: 4060
#include <stdio.h>
#include <algorithm>
#include <queue>
using namespace std;

struct phase{
	int x,y,d; pair<int, int> c;
  bool operator <(const phase &t) const{
    if (c.first == t.c.first) return c.second < t.c.second;
return c.first > t.c.first;
  }
};

int n,m,k;
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};
int sx,sy, ex,ey;

char map[10001001];
pair<int, int> e[1001001][2];

priority_queue<phase> q;
void enque(int x, int y, int d, pair<int, int> c)
{
  if (e[x*m+y][d] > c){
e[x*m+y][d] = c;
    q.push({x,y,d,c});
  }
}

int main()
{
  scanf ("%d %d %d",&n,&m,&k);
  scanf ("%d %d %d %d",&sx,&sy,&ex,&ey); sx--; sy--; ex--; ey--;
  for (int i=0;i<n;i++) scanf ("%s",map+i*m);
  for (int i=0;i<n*m;i++) e[i][0] = e[i][1] = {100000000, 0};
enque(sx, sy, 0, {0,0});
enque(sx, sy, 1, {0,0});
  while (!q.empty()){
int x = q.top().x;
int y = q.top().y;
int d = q.top().d;
    auto c = q.top().c;
    q.pop();
    
    if (e[x*m+y][d] < c) continue;
    for (int f=0;f<4;f++){
int px= x+dx[f];
      int py = y + dy[f];
      if (px < 0 || px >= n || py < 0 || py >= m || map[px*m+py] == '@') continue;
      if (c.second < 0 && f % 2 == d) enque(px,py,f%2,{c.first,c.second+1});
      else enque(px,py,f%2,{c.first+1,1-k});
    }
  }
  
  int ans = min(e[ex*m+ey][0].first,e[ex*m+ey][1].first);
  if (ans == 100000000) ans = -1;
  printf ("%d\n",ans);
  
 return 0; 
}


Measured memory_bytes: 22112
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <utility>
#include <tuple>
#include <cctype>
#define INF 0x3f3f3f3f
#define MOD 1000000007
#define PI 4*atan(1.0)
typedef long long ll;
typedef long double ld;
using namespace std;
int dx[4]={0,0,-1,1};
int dy[4]={-1,1,0,0};
const int SIZE=205;
//int arr[SIZE]={};
//ここまでテンプレ
int main(){
	char s[10];
	cin>>s;
	if(s[0]==s[2])
		cout<<"Yes"<<endl;
	else
		cout<<"No"<<endl;
    return 0;
}


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

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

/*-------------------------------------------*/

int ans=0;

int n,x[100009];

int main(){
    cin>>n;
    rep(i,n+1){
        cin>>x[i];
        if(i){
            ans=__gcd(ans,abs(x[i]-x[i-1]));
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 640
#include "bits/stdc++.h"
using namespace std;


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

int main() {
    int n;
    scanf("%d", &n);

    for(int i = 1, p = 11; i <= n; ++i) {
        while(isPrime(p) == false) p += 10;
        printf("%d ", p);
        p += 10;
    }
}

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

using namespace std;
typedef long long LL;

int main(){
	int N;
	cin >> N;
	map<string,int> m;
	for(int i=0; i<N; i++){
		string s;
		cin >> s;
		m[s]++;
	}
	int ans=0;
	for(auto itr=m.begin(); itr!=m.end(); itr++){
		if(itr->second>ans) ans=itr->second;
	}
	for(auto itr=m.begin(); itr!=m.end(); itr++){
		if(itr->second==ans) cout << itr->first << endl;
	}

	return 0;
}

Measured memory_bytes: 25216
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for(int i = (a); i < (int)(b); i++)
#define pw(x) (1LL<<(x))
static const int fast_io = [](){ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);return 0;}();
static const int precise_doubles = [](){cout<<fixed<<setprecision(20);return 0;}();
typedef pair<int, int> PII;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
// find_by_order(k) - iterator to kth largest, order_of_key(k) - #things < k
typedef long double LD;
typedef long long LL;
#define EVAL(x) x
#define SPA(x) EVAL({cout << #x" = " << x << ' ';})
#define NEWL EVAL({cout << '\n';})
#define SPAR(a, b) EVAL({cout<<#a" = ";for(auto it=a;it!=b;)cout<<*(it++)<<" ";cout<<'\n';})
#define SPAV(v) EVAL({cout<<#v" = ";for(auto it=v.begin();it!=v.end();)cout<<*(it++)<<" ";cout<<'\n';})
const int INF = 0x3f3f3f3f; // 1.0e9
const LL LINF = 0x3f3f3f3f3f3f3f3fll; // 4.5e18
const LD eps = 1e-20;
const int mod = 1e9 + 7;
inline int msum(int x, int y) {return (x+y<mod ? x+y : x+y-mod);}
inline int mdif(int x, int y) {return (x>=y ? x-y : x-y+mod);}
inline int mprod(int x, int y) { return (1ll*x*y) % mod; }
inline int mpow(int x, LL y) {LL r=1;while(y){if(y&1)r=mprod(r,x);x=mprod(x,x);y>>=1;}return r;}
inline int minv(int x) { return mpow(x, mod-2); }
//------------------------------------------------------------------------------------------------------

const int N = 1e5 + 10;
const int LOG = 17;
int n, L;
int x[N];
int jmp[LOG][N];

void build() {
    int far = 0;
    REP(i, n) {
        while(far+1 < n and x[far+1] - x[i] <= L) far++;
        jmp[0][i] = far;
    }
    FOR(log, 1, LOG) {
        REP(i, n) {
            jmp[log][i] = jmp[log-1][jmp[log-1][i]];
        }
    }
}

int main() {
    cin >> n;
    REP(i, n) cin >> x[i];
    cin >> L;

    build();

    int q;
    cin >> q;
    while(q--) {
        int source, dest;
        cin >> source >> dest;
        if(--source > --dest) {
            swap(source, dest);
        }
        int ans = 0;
        for(int log = LOG-1; log >= 0; log--) {
            if(jmp[log][source] < dest) {
                source = jmp[log][source];
                ans += 1<<log;
            }
        }
        cout << ans+1 << '\n';
    }
}
























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

//for(i=0;i<N;i++)

int main() {
	long T,i,j,N,M,D,Q,K,flag,counti,maxm,minm,sum;
	cin>>N>>D;
	counti=0;
	long X,Y;
	for(i=0;i<N;i++){
	    cin>>X>>Y;
	    if(sqrt(X*X+Y*Y)<=D){
	        counti++;
	    }
	}
	cout<<counti<<endl;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
const long long INF = 1LL << 60;
const long long MOD = 1000000007;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rep1(i, n) for (ll i = 1; i <= (n); ++i)
#define rrep(i, n) for (ll i = (n - 1); i >= 0; --i)
#define perm(c) sort(ALL(c));for(bool c##p=1;c##p;c##p=next_permutation(ALL(c)))
#define ALL(obj) (obj).begin(), (obj).end()
#define pb push_back
#define to_s to_string
#define len(v) (ll)v.size()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define print(x) cout << (x) << '\n'
#define drop(x) cout << (x) << '\n', exit(0)
#define debug(x) cout << #x << ": " << (x) << '\n'
using namespace std;
using ll = long long;
typedef pair<ll, ll> P;
typedef vector<ll> vec;
typedef vector<vector<ll>> vec2;
typedef vector<vector<vector<ll>>> vec3;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll devc(ll x, ll y) { return 1 + (x - 1) / y; }

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

    ll N;
    cin >> N;
    map<ll, ll> mp;
    rep(i, N){
        ll a;
        cin >> a;
        ++mp[a];
    }

    ll ans = 0;
    for(auto m : mp){
        if(m.second % 2 == 1) ++ans;
    }
    print(ans);

    return 0;
}

Measured memory_bytes: 6528
#include<iostream>

int main(){
    int n,a,b,c,d;
    
    std::cin >> n >> a >> b >> c >> d;
    
    int A = (n+(a-1))/a*b;
    int B = (n+(c-1))/c*d;
    
    if(A<B) std::cout << A << std::endl;
    else std::cout << B << std::endl;
}


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

typedef long long ll;

const ll N = 17;
int n, A, B;
int cnt[1 << 17];

vector <int> get(int l, int r, int mask, int num) {
	vector <int> res;
	if (num == 1) {
		res.push_back(l);
		res.push_back(r);
		return res;
	}

	int id = __builtin_ctz(l ^ r);
	int id2 = 0;
	for (int i = 0; i < n; i++)
		if ((((mask >> i) & 1) == 0) && i != id) {
			id2 = i;
			break;
		}
	res = get(l, l ^ (1 << id2), mask ^ (1 << id), num-1);
	for (int tmp: get(l ^ (1 << id2) ^ (1 << id), r, mask ^ (1 << id), num-1))
		res.push_back(tmp);

	return res; 
}

int main() {
	ios::sync_with_stdio(false), cin.tie(0);
	cin >> n >> A >> B;
	int p = 0;
	for (int i = 0; i < n; i++)
		if (((A >> i) & 1) != ((B >> i) & 1))
			p++;

	if (p % 2 == 0) {
		cout << "NO\n";
		return 0;
	}

	cout << "YES\n";
	vector <int> res = get(A, B, 0, n);
	for (int i = 0; i + 1 < res.size(); i++) 
		if (__builtin_popcount(res[i] ^ res[i + 1]) != 1)
			assert(false);

	for (int i = 0; i < res.size(); i++) {
		if (cnt[res[i]])
			assert(false);
		cnt[res[i]]++;
	}
		
	for (int a: res)
		cout << a << " ";
	return 0;
}

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

#define rint register int
inline int read(){int r;int s=0,c;for(;!isdigit(c=getchar());s=c);for(r=c^48;isdigit(c=getchar());(r*=10)+=c^48);return s^45?r:-r;}
bool g[705][705], book[705], bel[705]; vector<int> A, B; int c[2], n, m, Ans = 0x3f3f3f3f; bool f[705][705];
void DFS(int p, int f){++c[f]; bel[p] = f; book[p] = true; for(int i = 1; i <= n; i++) if(g[p][i]){if(!book[i])DFS(i,f^1);else if(bel[i]==f){puts("-1");exit(0);}}}
int main()
{
	n = read(); m = read(); for(rint i = 1, a, b; i <= m; a = read(), b = read(), g[a][b] = g[b][a] = 1, i++); for(rint i = 1, j; i <= n; i++) for(j = 1; j <= n; i^j?g[i][j]^=1:0, j++);
	A.push_back(0); B.push_back(0); for(rint i = 1; i <= n; i++) if(!book[i]){c[0] = c[1] = 0; DFS(i,0); A.push_back(c[0]); B.push_back(c[1]);} f[0][0] = 1;
	for(rint i = 1, j; i < A.size(); i++) for(j = 0; j <= n; f[i][j] = (j>=A[i]?f[i-1][j-A[i]]:0)||(j>=B[i]?f[i-1][j-B[i]]:0), j++);
	for(rint i = 0; i <= n; i++) if(f[A.size()-1][i]) Ans = min(Ans,(i*~-i>>1)+((n-i)*(n-i-1)>>1)); return !printf("%d\n",Ans);
}

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

int main(void){
  int n,m; cin >> n >> m;
  int a[n];
  rep(i,n){
    cin >> a[i];
  }
  sort(a,a+n);
  while(m != 0 && a[n-1] != 0){
    int chk = a[n-1]/2;
    for(int i = n-1; i >= 0; i--){
      if(chk >= a[i]) break;
      a[i] /= 2;
      m--;
      if(m == 0) break;
    }
    sort(a,a+n);
  }
  ll ans = 0;
  for(int i = 0; i < n; i++){
    ans += a[i];
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 640
#include <iostream>
using namespace std;
int main(){
  int a,b,c;
  int x;
  cin >> a >> b >> c;
  cin >> x;
  int i,j,k;
  int y;
  int copy;
  int copy_2;
  int counter;
  for(i=0;i<=a;i++){
    y = 0;
    y += 500*i;
    copy = y;
    for(j=0;j<=b;j++){
      y = copy;
      y += 100*j;
      copy_2 = y;
      for(k=0;k<=c;k++){
        y = copy_2;
      	y += 50*k;
          if(y==x)counter++;
      }
    }
  }
  cout << counter << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define double long double
#define endl "\n"
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb(x) push_back(x)
#define mp(a,b) make_pair(a,b)
#define ms(v,x) memset(v,x,sizeof(v))
#define ff first
#define ss second
#define frr(i,n) for(int i=0;i<n;i++)
#define td(v) v.begin(),v.end()
#define M   1000000007 // 1e9 + 7
#define MAXN 200100
using namespace std;
typedef pair<int,int> pii;
typedef pair<int,double> pdd;
inline int mod(int n, int m){int ret = n%m; if(ret < 0) ret += m; return ret;}
int gcd(int a, int b){return (b == 0 ? a : gcd(b, a%b));}
int exp(int a,int b,int m){
    if(b==0) return 1;
    if(b==1) return mod(a,m);
    int k = mod(exp(a,b/2,m),m);
    if(b&1){
        return mod(a*mod(k*k,m),m);
    }    else return mod(k*k,m);
}

int ok[30];
#define PI 3.14159265

int k,n;

int F[MAXN];
int A[MAXN];

int check(int x){
	int custo=0;
	for(int i=1;i<=n;i++){
		if(A[i]*F[n-i+1]>x){
			custo+=(A[i]*F[n-i+1] - x  + F[n-i+1] - 1)/F[n-i+1];
		}
	}
	if(custo>k)return false;
	return true;
}

int32_t main(){
//	fastio;

	cin>>n>>k;
	for(int i=1;i<=n;i++)cin>>A[i];
	for(int i=1;i<=n;i++)cin>>F[i];


	sort(A+1,A+n+1);
	sort(F+1,F+n+1);
	int l=0,r=1e12;
	int ans=-1;
	while(l<=r){
		 int m = (l+r)/2;
		 if(check(m)){
		    r = m-1;
			ans = m;	 
		 }else{
			 l = m+1;
		 }
	}
	cout<<ans<<endl;

	
}

Measured memory_bytes: 3456
from sys import setrecursionlimit
setrecursionlimit(10 ** 9)

N, A, B, C = [int(i) for i in input().split()]
L = [int(input()) for i in range(N)]

INF = 10 ** 9

def dfs(n, a, b, c):
    if n == N:
        return abs(a-A) + abs(b-B) + abs(c-C) - 30 if min(a, b, c) > 0 else INF
    res = dfs(n+1, a+L[n], b, c) + 10
    res = min(res, dfs(n+1, a, b+L[n], c) + 10)
    res = min(res, dfs(n+1, a, b, c+L[n]) + 10)
    res = min(res, dfs(n+1, a,  b, c))

    return res

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

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#include <math.h>
#include <map>
#include <unordered_map>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define pb(s) push_back(s)
#define ci(x) cin >>x
#define co(x) cout<<x<<endl
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}

long long fac(ll a) {
 long long ans=1;
 while(a>1){
 ans*=a;
 ans%=1000000007;
     a--;
    }
    return ans;
     }
int main() {
  ll A;
  ll B;
     ll C;
    cin >>A>>B>>C;
  
  ll K;
  cin >>K;
  
  
  ll x;
  
  
  if(K%2==0) {
    x=A-B;
  }
  else {
x=B-A;
  }
  
  if(abs(x)>1000000000000000000) {
    cout<<"Unfair"<<endl;
  }
  else {
    cout<<x<<endl;
  }
}
  


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

//Cyber Guardian
public class Main{

	boolean match(String s, String t){
		for(int i=0;i<16;i++){
			if(s.charAt(i)=='?'||t.charAt(i)=='?')continue;
			if(s.charAt(i)!=t.charAt(i))return false;
		}
		return true;
	}

	class P{
		String s, t, m;
		public P(String s, String t, String m) {
			this.s = s;
			this.t = t;
			this.m = m;
		}
	}

	void run(){
		Scanner sc = new Scanner(System.in);
		while(true){
			int n = sc.nextInt();
			int m = sc.nextInt();
			if((n|m)==0)break;
			String[] rule = new String[n];
			String[] d = new String[n];
			for(int i=0;i<n;i++){
				rule[i] = sc.next();
				d[i] = sc.next()+sc.next();
			}
			List<P> l = new ArrayList<P>();
			while(m--!=0){
				P p = new P(sc.next(), sc.next(), sc.next());
				String z = p.s+p.t;
				for(int i=n-1;i>=0;i--){
					if(match(z, d[i])){
						if(rule[i].equals("permit"))l.add(p);
						break;
					}
				}
			}
			System.out.println(l.size());
			for(P p:l)System.out.println(p.s+" "+p.t+" "+p.m);
		}
	}

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

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

int main() {
    int N;
    cin >> N;
    ll inf = 1e18;
    vector<ll> X(N+2), Y(N+2), P(N+2, 0);
    vector<vector<ll>> house(N+2, vector<ll>(3, 0));
    for (int i = 1; i <= N; i++) cin >> house[i][0] >> house[i][1] >> house[i][2];
    house[0] = {-inf, -inf, 0};
    house[N+1] = {inf, inf, 0};
    sort(house.begin(), house.end());
    for (int i = 0; i <= N+1; i++) {
        X[i] = house[i][0];
        Y[i] = house[i][1];
        P[i] = house[i][2];
    }
    
    vector<ll> ans(N+1, inf);
    
    for (int i = 0; i < (1<<N); i++) {
        int tate = 0;
        vector<ll> dist(N+1, inf);
        for (int j = 1; j <= N; j++) dist[j] = min(abs(X[j]), abs(Y[j]));
        for (int j = 1; j <= N; j++) {
            if (((i>>(j-1))&1) == 0) continue;
            tate++;
            for (int k = 1; k <= N; k++) dist[k] = min(dist[k], abs(Y[j]-Y[k]));
        }
        vector<vector<vector<ll>>> dp(N+2, vector<vector<ll>>(N+2,vector<ll>(N+1, inf)));
        dp[0][0][tate] = 0;
        for (int j = 1; j <= N; j++) {
            for (int k = 0; k < j; k++) {
                for (int l = 0; l <= N; l++) {
                    if (dp[j-1][k][l] == inf) continue;
                    dp[j][k][l] = dp[j-1][k][l];
                    if (l == N) continue;
                    ll cand = dp[j][k][l];
                    for (int m = k+1; m <= j; m++) {
                        cand += P[m]*min(dist[m], min(abs(X[m]-X[k]), abs(X[m]-X[j])));
                    }
                    dp[j][j][l+1] = min(dp[j][j][l+1], cand);
                }
            }
        }
        for (int j = 0; j <= N; j++) {
            for (int k = 0; k <= N; k++) {
                if (dp[N][j][k] == inf) continue;
                ll cand = dp[N][j][k];
                for (int l = j+1; l <= N; l++) cand += P[l]*min(dist[l], abs(X[l]-X[j]));
                ans[k] = min(ans[k], cand);
            }
        }
    }
    
    for (int i = 0; i <= N; i++) cout << ans[i] << endl;
    
    return 0;
}

Measured memory_bytes: 3692
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n,k = LI()
ans = 0
tmp = n*(n-1)//2
l = k*(k-1)//2
r = ((n-k+1)+n)*k//2
tmp = n-k
tmp2 = k
for i in range(k,n+2):
    ans += r-l+1
    ans %= mod
    l += tmp2
    r += tmp
    tmp2 += 1
    tmp -= 1
print(ans)

Measured memory_bytes: 67960
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <iomanip>
#include <cassert>

using namespace std;
typedef long long ll;

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
struct mint {
  long long x; // typedef long long ll;
  mint(long long x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

// combination mod prime
// https://www.youtube.com/watch?v=8uowVvQ_-Mo&feature=youtu.be&t=1619
struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
  assert(n < mod);
  fact[0] = 1;
  for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
  ifact[n] = fact[n].inv();
  for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
  if (k < 0 || k > n) return 0;
  return fact[n]*ifact[k]*ifact[n-k];
  }
};

int main(){
  int K;
  string S;
  cin >> K >> S;
  int length = S.size();
  mint ans=0;
  combination comb(2000001);
  for(int i = 0 ; i <= K; i++){
    mint a=26;
    int rest = K-i;
    mint b=25;
    ans += a.pow(i)*b.pow(rest)*comb(rest+length-1,length-1);
  }
  cout << ans << endl;
  return 0;
}


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

int main(){
	int n;
	int res;
	
	while((scanf("%d", &n)) != EOF){
		res = 0;
		for(int a = 0; a < 10; a++){
			for(int b = 0; b < 10; b++){
				for(int c = 0; c < 10; c++){
					for(int d = 0; d < 10; d++){
						if(a + b + c + d == n) res++;
					}
				}
			}
		}
		
		printf("%d\n", res);
	}
	
	return 0;
}

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

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;

int a[51][27];
int b[27];


int main() {
    ios_base::sync_with_stdio(false);
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        string s;
        cin >> s;
        for (int j = 0; j < s.length(); ++j) {
            a[i][s[j]-'a']++;
        }
    }
    for (int i = 0; i < 26; ++i) {
        int t = 51;
        for (int j = 0; j < n; ++j) {
            t = min(a[j][i], t);
        }
        b[i] = t;
    }
    for (int i = 0; i < 26; ++i) {
        if (b[i] > 0) {
            char c = 'a'+i;
            while (b[i] > 0) {
                cout << c;
                b[i]--;
            }
        }
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 256