akhauriyash/Code-Regression huggingface dataset:
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */


#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <set>
#include <functional>
#include <cmath>
#include <numeric>
#include <iterator>
#include <fstream>
#define SIZE 100005
#define MOD 1000000007

using namespace std;

class BK {
public:
    static void solve(std::istream& cin, std::ostream& cout) {
      int64_t k, t;
      cin >> k >> t;
      vector<int64_t> vec(t);
      for (int i = 0; i < t; ++i) {
        cin >> vec[i];
      }
      sort(vec.begin(), vec.end());
      int64_t max_vec = vec.back();
      vec.pop_back();
      int64_t sum = accumulate(vec.begin(), vec.end(), 0l);
      cout << max(max_vec - sum - 1, 0l) << endl;
    }
};


int main() {
    BK solver;
    std::istream& in(std::cin);
    std::ostream& out(std::cout);
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bits/stdc++.h>
#include <cstdint>
#include <iostream>
#include <iterator>
#include <vector>

// lib/util.hpp
#ifndef UTIL_HPP
#define UTIL_HPP


typedef std::int_fast64_t i64;

namespace tools {
  template <typename T>
  void read(std::vector<T>& vector, const typename std::vector<T>::size_type size) {
    vector.reserve(size);
    std::copy_n(std::istream_iterator<T>(std::cin), size, std::back_inserter(vector));
  }

  template <typename T, std::size_t N>
  void read(std::array<T, N>& array) {
    std::copy_n(std::istream_iterator<T>(std::cin), N, array.begin());
  }
}

#endif

// main.cpp

int main() {
  std::array<i64, 3> N;
  tools::read(N);

  std::sort(N.begin(), N.end());
  constexpr std::array<i64, 3> diff = {0, 1, -2};
  constexpr std::array<i64, 3> first = {0, 1, 1};
  const i64 odds = (N[2] - N[0]) % 2 + (N[2] - N[1]) % 2;
  std::cout << ((N[2] - N[0]) + (N[2] - N[1]) + diff[odds]) / 2 + first[odds] << std::endl;
  return 0;
}

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

#define mem(dp,a)           memset(dp,a,sizeof dp)
#define rep(i,a,b)          for(ll i=a;i<b;i++)
#define pb(x)               push_back(x)
#define mp(x,y)             make_pair(x,y)
#define xlr8                ios_base::sync_with_stdio(false);cin.tie(NULL)
#define F                   first
#define S                   second
#define all(c)              (c).begin(),(c).end()

int main()
{
    int n,l;cin>>n>>l;
    int a[n];
    int sum=0;
    rep(i,0,n)
    {
        a[i]=l+i;
        sum+=a[i];
    }
    int ans=sum;
    rep(i,0,n)
    {
        if(abs(a[i])<abs(ans))
            ans=a[i];
    }
    cout<<sum-ans;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define fi first
#define se second
#define ll long long
#define dbg(v) cerr<<#v<<" = "<<v<<'\n'
#define vi vector<int>
#define vl vector <ll>
#define pii pair<int,int>
#define mp make_pair
#define db long double
#define pb push_back
#define all(s) s.begin(),s.end()
int main(void)
{
    int n;
    cin>>n;
    ll ans = 1;
    for (int i = 1;i <= n;++i)
        ans *= 3;
    ll shit = 1;
    for (int i = 1;i <= n;++i)
        {
            int v;
            cin>>v;
            shit *= (v & 1 ? 1 : 2);
        }
    ans -= shit;
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 256
import java.io.*;
import java.util.*;
import static java.lang.System.in;

public class Main {
    static Scanner sc = new Scanner(System.in);
    static PrintWriter out = new PrintWriter(System.out);
    public static void main(String[] args){
        int n = sc.nextInt(), ans = 0;
        int maxi = -1;
        for(int i=0;i<n;i++){
            int cur = sc.nextInt();
            maxi = Math.max(maxi,cur);
            if(cur==maxi) ans++;
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 23636
#include <iostream>

using namespace std;
long long n,i,a[200005],dp[2][200005];
int main()
{
    cin>>n;
    for(i=1;i<=n;i++)
        cin>>a[i];
    dp[0][1]=a[1];
    dp[1][1]=-a[1];
    for(i=2;i<=n;i++)
    {
        dp[0][i]=max(dp[0][i-1]+a[i], dp[1][i-1]+-a[i]);
        dp[1][i]=max(dp[0][i-1]+-a[i], dp[1][i-1]+a[i]);
    }
    cout<<dp[0][n];
    return 0;
}

Measured memory_bytes: 3584
#include <stdio.h>

int main()
{
  int r, D, x;
  scanf("%d %d %d\n", &r, &D, &x);

  for (int i = 1; i <= 10; i++)
  {
    x = r * x - D;
    printf("%d\n", x);
  }

  return 0;
}

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

// Function Macros:
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define all(v) (v).begin(), (v).end()
#define setpre(n) cout << fixed << setprecision(n)

// Type / Class / Struct Definitions:
using namespace std;

using ll = long long;
using ull = unsigned long long;

// Constants:
const int INF = (1ll << 30) - 1;  // approx 1.07e9
const ll INFLL = 1ll << 60;       // approx 1.15e18
const int MOD = 1e9 + 7;          // 998244353
const long double EPS = 1.0e-14;

// Global Variables:

// Prototype Declarations:
int gcd(int, int);
template <class T>
inline bool chmin(T&, T);
template <class T>
inline bool chmax(T&, T);

// ================ Main Loop ================
int main() {
    int n, m;
    cin >> n >> m;
    vector<int> a(n);
    int sum = 0;
    rep(i, n) {
        cin >> a[i];
        sum += a[i];
    }
    int sel = 0;
    rep(i, n) {
        if(a[i] < sum / (4.0 * m)) {
            continue;
        } else {
            sel++;
        }
    }

    if(sel >= m)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}
// ===========================================

//Functions:
int gcd(int a, int b) {
    return b ? gcd(b, a % b) : a;
}

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;
}


Measured memory_bytes: 256
#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 <list>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <deque>

#define dump(x) cerr << #x << "=" << (x) << endl;
using namespace std;
using ll = long long;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define IN(x) int (x); cin >> x
#define INS(x) string (s); cin >> s
#define INL(x) ll (x); cin >> x
#define VINT(a,n) vector<int> a(n)
#define VIN(a,n) VINT(a,n); REP(i,n){cin >> a[i];}
#define ALL(x) (x).begin(),(x).end()

int main () {
  IN(w);
  IN(h);
  IN(x);
  IN(y);

  cout << (double)((ll)w*(ll)h)/2.0 <<' ';
  if(x==w/2.0&&y==h/2.0)
    cout<<1;
  else
    cout<<0;
  
}


Measured memory_bytes: 256
num_set=[]
num=input()

while int(num)!=0:
    num_set.append(num)
    num=input()
for i in range(len(num_set)):
    num_sum=0
    j=0
    for j in num_set[i]:
        num_sum=num_sum+int(j)
    print(num_sum)



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

#define rep(i,n,m) for(int i=n; i<=m; i++)
#define per(i,n,m) for(int i=n; i>=m; i--)
#define print(x) printf("%d ", x);
#define println(x) printf("%d\n", x);
#define printarray(a,n) for(int i=0; i<n-1; i++){printf("%d ", a[i]);} printf("%d\n", a[n-1]);
#define scan(x) scanf("%d", &x);
#define scanarray(a,n) for(int i=0; i<n-1; i++){scanf("%d", &a[i]);}
#define printcard(C,n) for(int i=0; i<n-1; i++) {printf("%c%d ", C[i].suit, C[i].value);}printf("%c%d\n", C[n-1].suit, C[n-1].value);

typedef struct {
    char suit;
    int value;
} Card;

void bubblesort(Card *C, int n);
void selectionsort(Card *C, int n);
int isStable(Card *C, int n);
void printcheck(void);

//making check array to judge whether STABLE or not
char check[10][4];

int main() {
    int n;
    scan(n);

    rep(i,1,10) {
        rep(j,0,3) {
            check[i][j] = 'X';
        }
    }

    Card C[n];
    rep(i,0,n-1) {
        scanf(" %c%d", &C[i].suit, &C[i].value);
        int j = 0;
        while(j < 4) {
            if (check[C[i].value][j] == 'X') {
                check[C[i].value][j] = C[i].suit;
                break;
            }
            j++;
        }
    }



    bubblesort(C,n);

    selectionsort(C,n);


    return 0;
}

void bubblesort(Card *D, int n) {
    Card C[n];
    rep(i,0,n-1) {
        C[i].suit = D[i].suit;
        C[i].value = D[i].value;
    }

    rep(i,0,n-1) {
        per(j,n-1,i+1) {
            if(C[j].value < C[j-1].value) swap(C[j],C[j-1]);
        }
    }

    printcard(C,n);
    if(isStable(C,n) == 1) cout << "Stable" << endl;
    else cout << "Not stable" << endl;

}

void selectionsort(Card *D, int n) {
    Card C[n];
    rep(i,0,n-1) {
        C[i].suit = D[i].suit;
        C[i].value = D[i].value;
    }

    int minj = 0;
    rep(i,0,n-1) {
        minj = i;
        rep(j,i,n-1) {
            if(C[j].value < C[minj].value) minj = j;
        }
        swap(C[i],C[minj]);
    }

    printcard(C,n);
    if(isStable(C,n) == 1) cout << "Stable" << endl;
    else cout << "Not stable" << endl;
}

int isStable(Card *C, int n) {
    int beforevalue = 0;
    int valuecount = 0;
    int flag = 1;
    rep(i,0,n-1) {
        if(C[i].value != beforevalue) {
            beforevalue = C[i].value;
            valuecount = 0;
        } else {
            valuecount++;
        }

        if(check[C[i].value][valuecount] == C[i].suit) ;//do nothing
        else {
            flag = 0;
            break;
        }
    }

    return flag;
}

void printcheck(void) {
    rep(i,1,10) printf("%d ", i);
    cout << endl;
    rep(j,0,3) {
        rep(i,1,10) {
            if(check[i][j] != 'X') printf("%c ", check[i][j]);
            else printf("  ", check[i][j]);
        }
        cout << endl;
    }
}



Measured memory_bytes: 3316
N,A,B,C,D=map(int,input().split())

a=int(N//A)
c=int(N//C)
if N%A==0:
    a=a
else:
    a=a+1
if N%C==0:
    c=c
else:
    c=c+1
    

x=a*B
y=c*D

if x>=y:
    print(int(y))
else:
    print(int(x))



Measured memory_bytes: 5596
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace AtCoder
{
	public class ABC
	{
		static readonly int mod = 1000000007;  // 10^9+7

		static void Main(string[] args)
		{
			Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });


			//int n = int.Parse(Console.ReadLine());
			//string s = Console.ReadLine();
			//int[] vs = Console.ReadLine().Split().Select(int.Parse).ToArray();
			//long[] a = Console.ReadLine().Split().Select(long.Parse).ToArray();
			int a = int.Parse(Console.ReadLine());
			int b = int.Parse(Console.ReadLine());
			if (a != 1 && b != 1) {
				Console.WriteLine("1");
			} else if (a != 2 && b != 2) {
				Console.WriteLine("2");
			} else {
				Console.WriteLine("3");
			}


			Console.Out.Flush();
		}
	}
}


Measured memory_bytes: 13140
t = int(input())
a,b = map(int, input().split())
ss = list(map(int, input().split()))
p = 0
mi= 99999999999999

for i in range(len(ss)):
    if mi > abs(b - (a - 0.006*ss[i])):
        p = i
        mi = abs(b - (a - 0.006*ss[i]))
print(p+1)



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

int main(void){
	int N;
	cin >> N;
	int t, x, y;
	//cin >> t >> x >> y;
	t = x = y = 0;
	int t_new, x_new, y_new;
	bool good = true;
	for(int i=0; i<N; ++i){
		cin >> t_new >> x_new >> y_new;
		int dis = abs(x_new - x) + abs(y_new - y);
		if(t_new - t < dis){
			good = false;
			break;
		}
		int mod_dis = dis % 2;
		int mod_t   = (t_new - t) % 2;
		if(mod_dis != mod_t){
			good = false;
			break;
		}
		t = t_new;
		x = x_new;
		y = y_new;
	}
	if(good) cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<cstddef>
#include<queue>
#include<math.h>
#include<iomanip>
using namespace std;

int main()
{
    int N;
    cin >> N;
    string S;
    cin >> S;
    /*
    long long ans = 0;
    if(N == 1 || N == 2) cout << 0 << endl;
    else
    {
        for(int i = 2; i < N; ++i)
        {
            for(int j = 1; j < i; ++j)
            {
                if(S.at(i) == S.at(j)) continue;
                else
                {
                    for(int k = 0; k < j; ++k)
                    {
                        if((j - i) != (k - j) && S.at(j) != S.at(k) && S.at(k) != S.at(i)) ans++;
                    }
                }
            }
        }
    }
    */
    //R, G, Bを0, 1, 2に置き換え
    vector<int> a(N);
    for(int i = 0; i < N; ++i)
    {
        if(S.at(i) == 'R') a.at(i) = 0;
        if(S.at(i) == 'G') a.at(i) = 1;
        if(S.at(i) == 'B') a.at(i) = 2;
    }
    //ans = r*g*b
    vector<long long> cnt(3);
    for(int i = 0; i < N; ++i) cnt.at(a.at(i))++;
    long long ans = 1;
    for(int i = 0; i < 3; ++i) ans *= cnt.at(i);
    //条件1を満たし条件2を満たさない組をansから引く
    for(int j = 0; j < N; ++j)
    {
        for(int i = 0; i < j; ++i)
        {
            int k = j + (j - i);
            if(k < N)
            {
                if(a.at(i) == a.at(j)) continue;
                if(a.at(j) == a.at(k)) continue;
                if(a.at(k) == a.at(i)) continue;
                ans--;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3636
from collections import deque

n,m=list(map(int,input().split()))
g=[[] for _ in range(10*(n+1)+3)]


for _ in range(m):
    u,v=list(map(int,input().split()))
    g[10*u].append(10*v+1)
    g[10*u+1].append(10*v+2)
    g[10*u+2].append(10*v)

s,t=list(map(int,input().split()))
inf=10**10
q=deque([10*s])
d=[inf]*(10*(n+1)+3)
d[10*s]=0

while len(q)>0:
    u=deque.pop(q)
    res=u%10
    for i in range(3):
        nres=(res+i)%3
        for v in g[u]:
            if d[v]<inf:
                continue
            d[v]=min(d[v],d[u]+1)
            deque.appendleft(q,v)

if d[10*t]==inf:
    print(-1)
else:
    print(d[10*t]//3)

Measured memory_bytes: 165800
from itertools import permutations as perm
from collections import deque, Counter as cnt
from collections import defaultdict as dd
from operator import itemgetter as ig
from bisect import bisect_right as bsr
from math import factorial, ceil, floor
import sys
sys.setrecursionlimit(1000000)

# お約束
args = None
INF = float("inf")
MOD = int(1e9 + 7)


def input(*ps):
    if type(ps[0]) is list:
        return [input(*ps[0][:-1]) for _ in range(ps[0][-1])]
    elif len(ps) == 1:
        return ps[0](next(args))
    else:
        return [p(next(args)) for p in ps]


def nlist(n, v):
    if not n:
        return [] if type(v) is list else v
    return [nlist(n[1:], v) for _ in range(n[0])]


def yesno(v, yes="Yes", no="No", upper=False):
    if upper:
        print([yes.upper(), no.upper()][not v])
    else:
        print([yes, no][not v])


def main():
    """エントリーポイント"""
    N, K, R, S, P, T = input([int, 5]) + input([str, 1])
    hand = []
    ans = 0
    for c, t in enumerate(T):
        temp = {"r": "p", "s": "r", "p": "s"}[t]
        if 0 <= c - K:
            if temp == hand[c - K]:
                hand.append("-")
                continue
        hand.append(temp)
        ans += {"r": P, "s": R, "p": S}[t]
    print(ans)


if __name__ == '__main__':
    args = iter(sys.stdin.read().split())
    main()


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

const int N = 40005;
const long double eps = 1e-12;

bool eq(long double a, long double b) { return abs(a - b) <= eps; }

struct line {
	long double a; long double b; long double c; // ax + by = c
	line(long double a = 0.0, long double b = 0.0, long double c = 0.0):
		a(a), b (b), c(c) {}
	long double intersectY(line d) {
		long double inter = (long double)(d.c * a - c * d.a) / (d.b * a - b * d.a);
		if (eq(inter, 0.0)) return 0.0; return inter;
	}
	bool operator < (const line &d) { return a / b > d.a / d.b; }
} l[N];

int n;
long long tot;

int T[N];
void upd(int x) { for (; x < N; x += x & -x) T[x]++; } 
int get(int x) { int res = 0; for (; x > 0; x -= x & -x) res += T[x]; return res; }

long long check(double val) {
	line med = {1, 0, val};
	vector< pair<long double, int> > coor;
	for (int i = 1; i <= n; ++i) {
		coor.push_back(make_pair(med.intersectY(l[i]), i));
	}
	sort(coor.begin(), coor.end());
	memset(T, 0, sizeof T);

	long long ans = 0;
	for (auto &cur : coor) {
		int pos = cur.second; ans += get(pos); upd(pos);
	}
	return ans;
}

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0);
	cin >> n;
	tot = 1LL * n * (n - 1) / 2;
	for (int i = 1; i <= n; ++i) cin >> l[i].a >> l[i].b >> l[i].c;
	sort(l + 1, l + n + 1);
	
	// find X
	long double lo = -1e9, hi = 1e9;
	for (int i = 1; i <= 70; ++i) {
		long double mid = (lo + hi) * 0.5;
		if (check(mid) >= (tot + 1) / 2) hi = mid; else lo = mid;
	}
	double X = lo;

	// find Y
	for (int i = 1; i <= n; ++i) l[i] = line(-l[i].b, l[i].a, l[i].c);
	sort(l + 1, l + n + 1);
	lo = -1e9, hi = 1e9;
	for (int i = 1; i <= 70; ++i) {
		long double mid = (lo + hi) * 0.5;
		if (tot - check(mid) <= tot - (tot + 2) / 2) hi = mid; else lo = mid;
	}
	double Y = -lo;
	cout << setprecision(9) << fixed << X << ' ' << Y << endl;
}

Measured memory_bytes: 7636
N = int(input())
if N==1 or N==2 or N==3 or N==4 or N==5 or N==6 or N==7 or N==8 or N==9 or N==4 or N==6 or N==8 or N==10 or N==12 or N==14 or N==16 or N==18 or N==9 or N==12 or N==15 or N==18 or N==21 or N==24 or N==27 or N==16 or N==20 or N==24 or N==28 or N==32 or N==36 or N==25 or N==30 or N==35 or N==40 or N==45 or N==36 or N==42 or N==48 or N==54 or N==49 or N==56 or N==63 or N==64 or N==72 or N==81:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 38256
#include<iostream>

bool isuru( int y )
{
 	return ( y % 4 == 0 && y % 100 != 0 ) || y % 400 == 0;
}

int main()
{
	int a, b;
	bool init = true;
	
	while( 1 ){
		std::cin >> a >> b;
		
		if( !a && !b )break;
		
		if( !init ) std::cout << std::endl;
		
		init = false;
		
		bool f = false;
		
		for( int i = a; i <= b; i++ ){
			if( isuru( i ) ){
				std::cout << i << std::endl;
				f = true;
			}
		}
		
		if( !f ){
		 	std::cout << "NA" << std::endl;
		}
	}

 	return 0;
}

Measured memory_bytes: 1160
import collections
n=int(input())
a=list(map(int,input().split()))
dic=collections.Counter(a)
m=int(input())

s=sum(a)

for i in range(m):
    p,q=map(int,input().split())
    s=s-p*dic[p]+q*dic[p]
    dic[q]+=dic[p]
    dic[p]=0
    print(s)


Measured memory_bytes: 93788
#include <iostream>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <cstdio>
#include <fstream>
#include <map>
#include <vector>
//#include <unordered_map>
//#include <unordered_set>
#include <stack>
#include <set>
#include <queue>
#include <list>
#define LL long long
#define N 100100
#define M 110
#define MOD 1000000007
#define FOR(i,l,r) for (int i = (l); i <= (r); i ++)
#define CLR(a,x) memset(a,x,sizeof(a))
#define INF 0x3f3f3f3f
#define ALL(x) x.begin(),x.end()
#define pb push_back
#define X first
#define Y second
using namespace std;
set<int>ans;
int main()
{
    int n;
    cin>>n;
    while(n--)
    {
        int x;
        cin>>x;
        if(ans.count(x)) ans.erase(x);
        else ans.insert(x);
    }
    cout<<ans.size()<<endl;
	return 0;
}


Measured memory_bytes: 4864
n,s=map(int,input().split())
a=list(map(int,input().split()))
mod=998244353
dp=[[0]*(s+1) for i in range(n+1)]
dp[0][0]=pow(2,n,mod)
x=pow(2,mod-2,mod)
for i in range(n):
  for j in range(s+1):
    if j>=a[i]:
      dp[i+1][j]=(dp[i][j-a[i]]*x+dp[i][j])%mod
    else:
      dp[i+1][j]=dp[i][j]%mod
print(dp[n][s])

Measured memory_bytes: 132472
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(10);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
constexpr int MOD=1000000007;
//constexpr int MOD=998244353;
#define INF (1<<30)
#define LINF (lint)(1LL<<56)
#define endl "\n"
#define rep(i,n) for(lint (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(lint (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcount(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
#define plint pair<lint,lint>
#define fi first
#define se second
typedef long long lint;
int dx[8]={1,1,0,-1,-1,-1,0,1};
int dy[8]={0,1,1,1,0,-1,-1,-1};
const int MAX_N=2e5+5;

lint fac[2100000],finv[2100000],inv[2100000];
void COMinit(){
  fac[0]=fac[1]=1;
  finv[0]=finv[1]=1;
  inv[1]=1;
  for(int i=2;i<2100000;i++){
    fac[i]=fac[i-1]*i%MOD;
    inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
    finv[i]=finv[i-1]*inv[i]%MOD;
  }
}
lint COM(lint n,lint k){
  if (n<k) return 0;
  if (n<0 || k<0) return 0;
  return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}
lint facdiv(lint n,lint k){
  if (n<k) return 0;
  if (n<0 || k<0) return 0;
  return (fac[n]*finv[k])%MOD;
}

lint powmod(lint a,lint b){
  return b?powmod(a*a%MOD,b/2)*(b%2?a:1)%MOD:1;
}

int main(void){
    COMinit();
    lint K;
    string S;
    cin >> K >> S;
    lint N=S.length();
    lint ans=0;
    for(int i=0;i<=K;i++){
        lint add=(powmod(26,i)*powmod(25,K-i))%MOD;
        add=add*COM(N+K-1-i,N-1);
        ans=(ans+add%MOD)%MOD;
    }
    cout << ans << endl;
}

Measured memory_bytes: 53476
#include<stdio.h>

int main(void)
{
  int A,B,C,K;
  scanf("%d %d %d %d",&A,&B,&C,&K);
  
  if(A>=K){
    printf("%d\n",K);
  }
  else if((A+B) >= K){
    printf("%d\n",A);
  }
  else{
    printf("%d\n",A-(K-(A+B)));
  }
  return 0;
}


Measured memory_bytes: 1728
import java.io.*;
import java.math.*;
import java.util.*;
 
public class Main {
    private static boolean debug = false;
    private static boolean elapsed = false;
 
    private static PrintWriter _out = new PrintWriter(System.out);
    private static PrintWriter _err = new PrintWriter(System.err);
 
    private void solve(Scanner sc) {
        int x = sc.nextInt();
        _out.println((x < 1200 ? "ABC" : "ARC"));
    }
    private static BigInteger C(long n, long r) {
        BigInteger res = BigInteger.ONE;
        for (long i = n; i > n - r; --i) {
            res = res.multiply(BigInteger.valueOf(i));
        }
        for (long i = r; i > 1; --i) {
            res = res.divide(BigInteger.valueOf(i));
        }
        return res;
    }
    private static BigInteger P(long n, long r) {
        BigInteger res = BigInteger.ONE;
        for (long i = n; i > n - r; --i) {
            res = res.multiply(BigInteger.valueOf(i));
        }
        return res;
    }
    /*
     * 10^10 > Integer.MAX_VALUE = 2147483647 > 10^9
     * 10^19 > Long.MAX_VALUE = 9223372036854775807L > 10^18
     */
    public static void main(String[] args) {
        long S = System.currentTimeMillis();
 
        Scanner sc = new Scanner(System.in);
        new Main().solve(sc);
        _out.flush();
 
        long G = System.currentTimeMillis();
        if (elapsed) {
            _err.println((G - S) + "ms");
        }
        _err.flush();
    }
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0; i<n; i++)
typedef long long ll;
typedef long long unsigned int llu;
ll mod = 1000000007;
ll INF = 1000000009;


void solve(){
    int n;
    cin >> n;
    int a[n+10];
    rep(i,n){
        cin >> a[i];
    }
    int ans = 0;
    rep(i,n){
        while(a[i]%2==0){
            a[i] = a[i]/2;
            ans++;
        }
    }
    cout << ans << endl;
}

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


Measured memory_bytes: 256
#include <stdio.h>

int main(void) {

  long n,k;
  scanf("%ld %ld", &n, &k);
  long s[k][2];
  for (long i = 0; i < k; i++) {
    scanf("%ld %ld", &s[i][0], &s[i][1]);
  }
  long mod = 998244353;
  long dp[n+1],sum[n+1],start,end;
  dp[0] = 0;
  dp[1] = 1;
  sum[0] = 0;
  sum[1] = 1;
  for (long i = 2; i <= n; i++) {
    dp[i] = 0;
    for (long j = 0; j < k; j++) {
      start = s[j][0];
      if (i-start < 1) {
        continue;
      }
      end = s[j][1];
      if (i-end < 1) {
        end = i-1;
      }
      dp[i] += (sum[i-start]+mod-sum[i-end-1])%mod;
      dp[i] %= mod;
    }
    sum[i] = (sum[i-1]+dp[i])%mod;
  }
  printf("%ld\n", dp[n]);

  return 0;
}

Measured memory_bytes: 4788
#include "bits/stdc++.h"
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,x,n) for(int i=x;i<n;i++)
#define ALL(v) (v).begin(),(v).end()
#define MP(a,b) make_pair(a,b)
typedef long long LL;
typedef pair<int, int> PI;
typedef vector<int> VI;
const LL MOD = 1000000007LL;
int A[100000];
int main() {
	int N;
	cin >> N;
	rep(i, N) cin >> A[i];
	sort(A, A + N);
	int l = -1, r = N - 1;
	while (r - l > 1) {
		int m = (l + r) / 2;
		bool OK = 1;
		LL sum = 0;
		rep(i, m + 1) sum += A[i];
		REP(i, m + 1, N) {
			if (A[i] <= 2 * sum) {
				sum += A[i];
			}
			else {
				OK = 0;
				break;
			}
		}
		if (OK) r = m; else l = m;
	}
	cout << N - r << endl;
}

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

int n, m, arr[100002];
const int MOD = 1000000007;

int main(){

    arr[0] = arr[1] = 1;

    scanf("%d %d", &n, &m);
    for(int i = 0, act; i < m; i++){
        scanf("%d", &act);
        arr[act] = -1;
    }

    for(int i = 2; i <= n; i++){
        if(arr[i] != -1){
            if(arr[i - 1] != -1){
                arr[i] = (arr[i] + arr[i - 1]) % MOD;
            }
            if(arr[i - 2] != -1){
                arr[i] = (arr[i] + arr[i - 2]) % MOD;
            }
        }
    }

    printf("%d\n", arr[n]);

    return 0;
}


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

using namespace std;

int main()
{
    string S;
    
    getline(cin, S);
    
    for(int i = 0; i < S.size(); i++)
    {
        if(islower(S[i]))
        {
            cout << (char)toupper(S[i]);
        }
        else if(isupper(S[i]))
        {
            cout << (char)tolower(S[i]);
        }
        else
        {
            cout << S[i];
        }
    }
    
    cout << endl;
    
    return 0;
}

Measured memory_bytes: 1176
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int main(){
  string str;
  cin >> str;
  if(str == "ABC"){
    printf("ARC\n");
  }
  else if(str == "ARC"){
    printf("ABC\n");
  }
  return 0;
}


Measured memory_bytes: 3108
#include <iostream>

using namespace std;

int main()
{
    int A , B , C , x ;
    cin>> A , cin>> B , cin>> C;
    if ( B/A > 0 ){
        x = B/A;
        if ( x>C ) {
            cout<< C;
        }
        else {
            cout<< x;
        }
    }
    else {
        cout<< 0;
    }
    return 0;
}


Measured memory_bytes: 3628
#include<iostream>
#include<algorithm>
#include<vector>
#include<set>
#include<string>
using namespace std;
#define rep(i,n) for(int i = 0 ; i < n ; i++)
int main(){
  int n, k;
  while(cin >> n >> k , n){
    vector< string > vc(n);
    for(int i = 0 ; i < n ; i++ ) cin >> vc[i];
    set< string > ret;
    if(k == 1){
      rep(i,n) ret.insert(vc[i]);
    }else if(k == 2){
      rep(i,n) rep(j,n) if(i!=j) ret.insert(vc[i]+vc[j]);
    }else if(k == 3){
      rep(i,n) rep(j,n) if(i!=j) rep(k,n) if(i!=k&&j!=k) ret.insert(vc[i]+vc[j]+vc[k]);
    }else if(k == 4){
      rep(i,n) rep(j,n) if(i!=j) rep(k,n) if(i!=k&&j!=k) rep(l,n) if(i!=l&&j!=l&&k!=l) ret.insert(vc[i]+vc[j]+vc[k]+vc[l]);
    }
    cout << ret.size() << endl;
  }
}

Measured memory_bytes: 1456
#K-th Substring

#入力
s = input()
k = int(input())
 
 #計算
sub = set()

for i in range(len(s)):
	for j in range(i+1, min(i+6,len(s)+1)):
		sub.add(s[i:j])

sub = list(sub) 
sub.sort()

#出力
print(sub[k-1])

Measured memory_bytes: 4464
n,a,b=map(int,input().split())
ans=pow(2,n)-1
mod=10**9+7
def ncr(n,r,mod):
    cnt=1
    for i in range(n-r+1,n+1):
        cnt*=i
        cnt%=mod
    for i in range(1,r+1):
        cnt*=pow(i,mod-2,mod)
        cnt%=mod
    return cnt
comb1=ncr(n,a,mod)
comb2=ncr(n,b,mod)
ans=(ans-comb1-comb2)%mod
print(ans)

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

int main(){
    int a, b;
    cin >> a >> b;
    int dim;
    if(b / 10 == 0)dim = a * 10 + b;
    else if(b / 100 == 0)dim = a * 100 + b;
    else dim = a * 1000 + b;
    for(int i = 0;i < 1000;i++){
        if(i * i == dim){
            cout << "Yes" << endl;
            return 0;
        }
        else if(i * i > dim){
            cout << "No" << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 3636
// DAMM HOT 
// #pragma GCC target ("avx2")
// #pragma GCC optimization ("O3")
// #pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>
using namespace std;
#define FastRead ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int
#define ll int
#define bits_count __builtin_popcountll
#define endl '\n'
#define double long double
#define ld double
#define FOR(i,a,n) for (ll i=(a);i<=(n);++i)
#define RFOR(i,a,n) for (ll i=(n);i>=(a);--i)
#define FI(i,n) for (ll i=0; i<(n); ++i)
#define ZERO(a) memset((a),0,sizeof((a)))
#define MINUS(a) memset((a),-1,sizeof((a)))
#define f first
#define s second
#define pb push_back
#define mk make_pair
#define all(g) g.begin(),g.end()
#define sz(x) (ll)x.size()
#define pr pair<int,int>
int fastMax(int x, int y) { return (((y-x)>>(32-1))&(x^y))^y; }
int fastMin(int x, int y) { return (((y-x)>>(32-1))&(x^y))^x; }

// #include <ext/pb_ds/assoc_container.hpp> // Common file
// #include <ext/pb_ds/tree_policy.hpp>     // Including tree_order_statistics_node_updat
// using namespace __gnu_pbds;
// typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

void solve(){
    int n,k,c; cin>>n>>k>>c;
    string s; cin>>s;
    s = 'P' + s;

    set<int> from_front,from_back;

    int rem = 0;
    FOR(i,1,n){
        if(rem > 0) rem--;
        else {
            if(s[i] == 'o'){
                from_front.insert(i);
                rem = c;
            }
        }
    }

    rem = 0;
    RFOR(i,1,n){
        if(rem > 0) rem--;
        else {
            if(s[i] == 'o'){
                from_back.insert(i);
                rem = c;
            }
        }
    }

    if(sz(from_back) > k || sz(from_front) > k) return;

    for(int v:from_front){
        if(from_back.find(v) != from_back.end()){
            cout<<v<<endl;
        }
    } 
}

signed main(){

   FastRead;    

    int t = 1; 
    // cin>>t;
    FOR(i,1,t){
        // cout<<"Case #"<<i<<": ";
        solve();
    }
}



Measured memory_bytes: 20432
//#include<bits/stdc++.h>
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<numeric>
#include<vector>
#include<set>
#include<map>
#include<unordered_map>
#include<stack>
#include<queue>
#include<list>
using namespace std;

typedef long long ll;

#define MOD 1000000007

class Comb{
private:
  ll *fac,*finv,*inv;
public:
  Comb(){
    fac = new ll[1000000];
    finv = new ll[1000000];
    inv = new ll[1000000];
    fac[0] = 1;
    for(int i=1;i<1000000;i++){
      fac[i] = i*fac[i-1];
      fac[i] %= MOD;
    }
    inv[1] = 1;
    for(int i=2;i<1000000;i++){
      inv[i] = MOD-inv[MOD%i]*(MOD/i)%MOD;
    }
    finv[0] = 1;
    for(int i=1;i<1000000;i++){
      finv[i] = inv[i]*finv[i-1];
      finv[i] %= MOD;
    }
  }
  ll calc(ll n,ll k){
    ll c = fac[n];
    c *= finv[k];c %= MOD;
    c *= finv[n-k];c %= MOD;
    return c;
  }
};

int main(){
  int x,y,a,b,c;
  cin >> x >> y >> a >> b >> c;
  ll ans = 0;
  ll p[a],q[b],r[c];
  for(int i=0;i<a;i++) cin >> p[i];
  for(int i=0;i<b;i++) cin >> q[i];
  for(int i=0;i<c;i++) cin >> r[i];
  vector<ll> s;
  sort(p,p+a);
  sort(q,q+b);
  for(int i=0;i<x;i++) s.push_back(p[a-1-i]);
  for(int i=0;i<y;i++) s.push_back(q[b-1-i]);
  for(int i=0;i<c;i++) s.push_back(r[i]);
  sort(s.begin(),s.end());
  for(int i=0;i<x+y;i++) ans += s[x+y+c-1-i];
  cout << ans << endl;
  return 0;
}


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

using ll = long long;

template<typename T>
using vec = vector<T>;
template<typename T>
using mat = vector<vec<T>>;
template<typename T>
using val = valarray<T>;

using pi = pair<int,int>;

#define rep(a,b) for(int a=0; a<b; ++a)
#define Rep(a,b,c) for(int a=b; a<c; ++a)
#define all(v) v.begin(),v.end()

vec<int> divisor(int n){
	vec<int> ret;
	for(int i=1; i*i<=n; ++i){
		if(n%i==0){
			ret.emplace_back(i);
			if(i*i!=n) ret.emplace_back(n/i);
		}
	}
	sort(begin(ret),end(ret));
	return (ret);
}

int main(){
	int N; cin>>N;
	val<int> t(N);
	rep(i,N) cin>>t[i];
	auto div=divisor(t.max());
	int ans=0;
	rep(i,N){
		int p=lower_bound(all(div),t[i])-div.begin();
		ans+=(div[p]-t[i]);
	}
	cout<<ans<<endl;
}



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

using namespace std;

typedef long long int ll;
typedef pair<ll, ll> pll;

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

ll A[100005];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    REP(i, N) {
        cin >> A[i];
    }
    ll ans = 0;
    ll x = 1;
    REP(i, N) {
        if (A[i] == x) {
            x++;
            continue;
        }
        ll p = A[i] / x;
        ans += p;
        A[i] -= p * x;
        if (A[i] == 0) {
            A[i]++;
            ans--;
        }
        x = std::max(A[i] + 1, x);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
#include<stdio.h>
#include<stdlib.h>

int compare_int(const void *a,const void *b){
	long long x=*(long long*)a;
	long long y=*(long long*)b;
	if(y>x)return 1;
	else if(x==y)return 0;
	else return -1;
}

#define N 300000

int main(){
	int n,i,c=0;
	long long a[N],ans=0;
	scanf("%d",&n);
	for(i=0;i<3*n;i++)scanf("%lld",&a[i]);
	qsort(a,3*n,sizeof(long long),compare_int);
	for(i=1;i<3*n;i+=2){
		if(c>=n)break;
		ans+=a[i];
		c++;
	}
	//for(i=0;i<n*3;i++)printf("%lld,",a[i]);
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 4860
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
void solve(){
    int n,m;
    cin>>n>>m;
    int r=n/2;
    if(r%2!=0) r--;
    int x=r/2;
    int y=x+1;
    while(m>0 && x>=1 && y<=r){
        if(2*abs(x-y)==n){
            x--; y++;
            continue;
        }
        cout<<x<<' '<<y<<'\n';
        x--; y++;
        m--;
    }
    int g=n-r;
    x=r+g/2;
    y=x+2;
    while(m>0){
        if(2*abs(x-y)==n){
            x--; y++;
            continue;
        }
        cout<<x<<' '<<y<<'\n';
        x--; y++;
        m--;
    }
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    int tc;
 //   cin>>tc;
    tc=1;
    while(tc--){
        solve();
    }
return 0;
}


Measured memory_bytes: 3688
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<map>

using namespace std;

int main(){
    vector<long long> cap(5);
    long long N;   
    cin>>N>>cap[0]>>cap[1]>>cap[2]>>cap[3]>>cap[4];
    sort(cap.begin(),cap.end());
  	cout<<5+(N-1)/cap[0]<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <math.h>
using namespace std;
using ll = long long;
int main() {
    int N; cin >> N;
    vector<ll> A(N);
    for (int i=0;i<N;i++) {
        cin >> A[i];
    }
    vector<ll> B(N);
    B[0] = A[0]+A[N-1];
    for (int i=1;i<N-1;i++){
        if (i%2==1) B[0] -= A[i];
        else B[0] += A[i];
    }
    for (int i=1;i<N;i++){
        B[i] = (A[i-1] - B[i-1]/2)*2;   
    }
    for (int i=0;i<N;i++) {
        cout << B[i];
        if (i!=N-1) cout << " ";
        else cout << endl;
    }
    return 0;
}

Measured memory_bytes: 2944
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
    ll i,j,k,n,m,a,b;
    cin>>n;
    if(n&1)cout<<"Hello World"<<endl;
    else{
        cin>>a>>b;
        cout<<a+b<<endl;
    }
    return 0;

}


Measured memory_bytes: 256
/**/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define ii pair<int, int>
#define X first
#define Y second
#define all(x) (x).begin(), (x).end()
#define set_vect(a,n); vector<int>a(n); for(int i=0;i<n;i++)cin>>a[i];
#define db(x) cerr << #x << " = "  << (x) << ' ';
const int N = 200005;

int n;
void solve(){
    cin >> n;
    set_vect(a,n);
    int Max = a[0];
    ll ans = 0;
    for(int i: a){
        Max = max(Max,i);
        ans += Max - i;
    }
    cout << ans;
}

int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);
    
    int t = 1; //cin >> t;
    while(t--){solve();}
    return 0;
}

// Code By Pain (Bao Trung)

Measured memory_bytes: 3988
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
#include<map>
#include<queue>
#include<set>
#include<bitset>
#include<stdio.h>
#include<deque>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
typedef long long ll;
 
int main()
{
   int a;
   cin >> a;
   if(a == 25) cout << "Christmas" << endl;
   else if(a == 24)cout << "Christmas Eve" << endl;
   else if(a == 23)cout << "Christmas Eve Eve" << endl;
   else cout << "Christmas Eve Eve Eve" << endl;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
	public static void main(String[] args) {
		FastScanner sc = new FastScanner(System.in);
		int n = sc.nextInt();
		int ac = 0, wa = 0, tle = 0, re = 0;
		for(; n > 0; n--) {
			String s = sc.next();
			if(s.equals("AC")) {
				ac++;
			}else if(s.equals("WA")) {
				wa++;
			}else if(s.equals("TLE")) {
				tle++;
			}else {
				re++;
			}
		}
		System.out.println("AC x "+ac);
		System.out.println("WA x "+wa);
		System.out.println("TLE x "+tle);
		System.out.println("RE x "+re);
	}

	static class FastScanner {
		private BufferedReader reader = null;
	    private StringTokenizer tokenizer = null;
	    public FastScanner(InputStream in) {
	        reader = new BufferedReader(new InputStreamReader(in));
	        tokenizer = null;
	    }

	    public String next() {
	        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
	            try {
	                tokenizer = new StringTokenizer(reader.readLine());
	            } catch (IOException e) {
	                throw new RuntimeException(e);
	            }
	        }
	        return tokenizer.nextToken();
	    }

	    public String nextLine() {
	        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
	            try {
	                return reader.readLine();
	            } catch (IOException e) {
	                throw new RuntimeException(e);
	            }
	        }

	        return tokenizer.nextToken("\n");
	    }

	    public long nextLong() {
	        return Long.parseLong(next());
	    }

	    public int nextInt() {
	        return Integer.parseInt(next());
	    }

	    public double nextDouble() {
	         return Double.parseDouble(next());
	     }

	    public int[] nextIntArray(int n) {
	        int[] a = new int[n];
	        for (int i = 0; i < n; i++)
	            a[i] = nextInt();
	        return a;
	    }

	    public long[] nextLongArray(int n) {
	        long[] a = new long[n];
	        for (int i = 0; i < n; i++)
	            a[i] = nextLong();
	        return a;
	    }
	}
}


Measured memory_bytes: 48360
#include <iostream>
#include <algorithm>

using namespace std;

int main(){
  int n;
  
  while(1){
    cin >> n;
    if(n == 0) break;

    int a[n];
    for(int i = 0 ; i < n ; i++){
      cin >> a[i];
    }
    
    sort(a, a+n);
    int sa, min = 1000000;
    for(int i = 0 ; i < n - 1 ; i++){
      sa = (a[i+1] - a[i]);
      if(min > sa) min = sa;
    }
    cout << min << endl;
  }
}

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

int main(){
    int N;
    cin >> N;
    int ans = 0;
    for(int i=0; i<N; i++){
        int a;
        cin >> a;
        while(a % 2 == 0){
            ans++;
            a /= 2;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <cassert>
#include <memory>
#include <stack>
#include <set>
#include <map>
#include <queue>

#define INF 1000000000
#define MOD 1000000007
typedef long long ll;
typedef unsigned long long ull;
using namespace std;

int N;
int A,B,C;
vector<int> ls;

void chmin(int& x, int y) {
  if(x > y) x = y;
}

int dfs(int idx, int a, int b, int c) {
  if(idx == N) {
    if(a == 0 || b == 0 || c == 0) {
      return INF;
    } else {
      // diffを取るのは最後でよい
      return abs(a-A) + abs(b-B) + abs(c-C);
    }
  }

  int ret = INF;
  chmin(ret, dfs(idx + 1, a, b, c));
  chmin(ret, dfs(idx + 1, a + ls[idx], b, c) + (a? 10 : 0));
  chmin(ret, dfs(idx + 1, a, b + ls[idx], c) + (b? 10 : 0));
  chmin(ret, dfs(idx + 1, a, b, c + ls[idx]) + (c? 10 : 0));
  return ret;
}

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

  int n,a,b,c; cin>>n>>a>>b>>c;
  N = n;
  A = a, B = b, C = c;
  ls.resize(N);
  for(int i=0; i<N; i++) {
    int l; cin>>l;
    ls[i] = l;
  }

  int ans = dfs(0,0,0,0);
  cout << ans << endl;
}


Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
ans=0
for i in range(n):
    if a[i]>=b[i]:
        ans+=b[i]
    else:
        ans+=a[i]
        b[i]-=a[i]
        if a[i+1]<b[i]:
            ans+=a[i+1]
            a[i+1]=0
        else:
            ans+=b[i]
            a[i+1]-=b[i]
print(ans)

Measured memory_bytes: 18624
#include <queue>
#include <cstdio>
#include <iostream>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <sstream>
#include <algorithm>
#include <iomanip>
#include <stack>
using namespace std;
typedef long long int ll;

#define EPS (1e-9)
#define INF (1e9)
#define PI (acos(-1))
#define REP(i,n) for(int i=0;i<n;i++)

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

ll beki(ll a, ll b) {
	ll tmp = 1;
	REP(i, b) tmp *= a;
	return tmp;
}

ll S;

int main() {
	cin >> S;

	cout << 0 << " " << 0 << " ";

	long double tmp = sqrtl(S);
	ll tmp2 = ll(tmp);
	if (tmp - tmp2 != 0) {
		tmp2++;
	}

	ll x2 = tmp2 * tmp2 - S;
	ll y1 = 1;
	ll x1 = tmp2;
	ll y2 = tmp2;

	cout << x1 << " " << y1 << " " << x2 << " " << y2 << endl;

//	ll S2 = (x1 * y2 - x2 * y1);
//	cout << S2 << endl;
}

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

using namespace std;

class UnionFind
{
public:
    vector<int> parent;
    vector<int> rank;
    
    UnionFind(int n): parent(n), rank(n)
    {
        for(int i=0;i<n;i++)
            parent[i] = i,
            rank[i] = 0;
    }

    int root(int x)
    {
        return parent[x]==x ? x : parent[x] = root(parent[x]);
    }

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

    void unite(int x, int y)
    {
        x = root(x);
        y = root(y);
        if (x != y)
        {
            if (rank[x] < rank[y])
                parent[x] = y;
            else
                parent[y] = x;
            if (rank[x]==rank[y])
                rank[x]++;
        }
    }
};

int main()
{
    int N, M;
    cin>>N>>M;
    vector<long long> X(N);
    for (int i=0; i<N; i++)
        cin>>X[i];
    vector<int> A(M);
    vector<int> B(M);
    vector<long long> Y(M);
    for (int i=0; i<M; i++)
    {
        cin>>A[i]>>B[i]>>Y[i];
        A[i]--;
        B[i]--;
    }

    vector<pair<long long, pair<int, int>>> T;
    for (int i=0; i<M; i++)
        T.push_back(make_pair(Y[i], make_pair(A[i], B[i])));
    sort(T.begin(), T.end());
    for (int i=0; i<M; i++)
    {
        A[i] = T[i].second.first;
        B[i] = T[i].second.second;
        Y[i] = T[i].first;
    }

    vector<int> S(M);
    
    vector<long long> W(N);
    for (int i=0; i<N; i++)
        W[i] = X[i];
    UnionFind UF(N);
    for (int i=0; i<M; i++)
    {
        if (!UF.same(A[i], B[i]))
        {
            long long w = W[UF.root(A[i])] + W[UF.root(B[i])];
            UF.unite(A[i], B[i]);
            W[UF.root(A[i])] = w;
        }
        if (W[UF.root(A[i])] >= Y[i])
            S[i] = 1;
    }

    vector<vector<int>> E(N);
    vector<vector<long  long>> EI(N);
    for (int i=0; i<M; i++)
    {
        E[A[i]].push_back(B[i]);
        E[B[i]].push_back(A[i]);
        EI[A[i]].push_back(i);
        EI[B[i]].push_back(i);
    }

    function<void(int, int, long long)> mark = [&](int c, int p, long long w)
    {
        for (int i=0; i<(int)E[c].size(); i++)
        if (E[c][i] != p && Y[EI[c][i]] <= w && S[EI[c][i]] != 2)
        {
            S[EI[c][i]] = 2;
            mark(E[c][i], c, w);
        }
    };

    for (int i=M-1; i>=0; i--)
        if (S[i] == 1)
        {
            S[i] = 2;
            mark(A[i], B[i], Y[i]);
            mark(B[i], A[i], Y[i]);
        }

    int ans = 0;
    for (int i=0; i<M; i++)
        if (S[i] == 0)
            ans++;
    cout<<ans<<endl;
}


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

int main() {
  int n, h, w;
  cin >> n >> h >> w;
  
  int ans = 0;
  for(int i = 0; i < n; i++){
    int a, b;
    cin >> a >> b;
    if(a < h) continue;
    if(b < w) continue;
    ans++;
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 3592
import java.io.PrintStream;
import java.util.Scanner;
import java.util.stream.Stream;

public class Main {
	final static PrintStream so = System.out;
	final static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {
		int n = sc.nextInt();
		
		int k = sc.nextInt();
		String[] b = new String[k];
		for (int i = 0; i < k; i++) {
			b[i] = sc.next();
		}
		
		for (int i = n; ; i++) {
			if (!containtsDigit(i, b)) {
				so.println(i);
				return;
			}
		}
	}
	
	static boolean containtsDigit(final int in, final String[] digits) {
		return Stream.of(digits).anyMatch(s -> String.valueOf(in).contains(s));
	}
}


Measured memory_bytes: 39416
#pragma GCC optimize("Ofast", "unroll-loops")

#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define ld long double

constexpr ll mod = 1000000007LL;

ll solve(int S){
	if (S == 0) return 1;
	if (S <= 2) return 0;
	static map<int, ll> memo;
	if (memo[S]) return memo[S];
	ll ret = 0;
	for (int i = 3; i <= S; ++i)
		ret = (ret + solve(S - i)) % mod;
	return memo[S] = ret;
}

int main(void){
	int S; cin >> S;
	cout << solve(S) << endl;
	return 0;
}

Measured memory_bytes: 3800
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <numeric>
#define ll long long int
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
using namespace std;
int mx4[] = {0,1,0,-1};
int my4[] = {1,0,-1,0};
int mx2[] = {1,0};
int my2[] = {0,1};

class C {
public:
	void solve(istream& in, ostream& out) {
        int n;
        in >> n;
        vector<int> a(n);
        double sum = 0;
        rep(i,n){
            in >> a[i];
            sum += a[i];
        }
        double b = sum / n;
        int c = round(b);
        ll ans = 0;
        rep(i,n){
            ans += (a[i] - c) * (a[i] - c);
        }
        out << ans << endl;



	}
};

int main() {
	C solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<iomanip>
#include<algorithm>
#include<map>
#include<utility>
#include<cmath>
#include<tuple>
#include<string>
#include<bitset>
#include<set>
using namespace std;
typedef long long ll;

int main(){
    int n; cin>>n;
    vector<int> p(n);
    int m=1e9;
    for(int i=0;i<n;i++){
        cin>>p[i];
    }

    int ans=n;
    for(int i=1;i<n;i++){
        if(p[i-1]<p[i]){
            ans--;
            swap(p[i-1],p[i]);
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 1024