akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;
 //Compiler version g++ 6.3.0

 int main() {
 	int n;
 	cin >> n;
 	int m = n;
 	int sum = 0;
 	while(m > 0) {
 		sum += m % 10;
	 	m /= 10;
 	}
	 if(n % sum == 0){
	 cout << "Yes";
 	}else{
 	cout << "No";
 	}
 }

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


int main()
{
  int A,B;
  cin>>A>>B;

  if(A<=5)
  {
    cout<<"0\n";
    return 0;
  }
  if(A>=6 && A<=12)
  {
    cout<<B/2<<endl;
    return 0;
  }
  else
  cout<<B;
  return 0;
}

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

#define rep(i, N) for (ll i = 0; i < N; i++)
#define rep1(i, N) for (ll i = 1; i <= N; i++)
#define repr(i, N) for (ll i = N-1; i >= 0; i--)
#define repr1(i, N) for (ll i = N; i > 0; i--)

#define MOD 1000000007

using ll = long long;
using namespace std;

typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<P> vpi;


int main() {
    ll N,K,ans = 0,num = 0;
    cin >> N >> K;
    vpi a(N);
    rep(i,N) cin >> a[i].first >> a[i].second;
    sort(a.begin(), a.end());

    rep(i,N){
        num += a[i].second;
        if(num >= K){
            ans = a[i].first;
            break;
        }
    }

    cout << ans;
    //printf("%.15lf", ans);
    cout << "\n";
    return 0;
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef double R;//double long double ??????????????? cmath?????¢??°??????????????????????????????????????????????????§????????????
typedef complex<R> Point;
typedef pair<Point , Point> Line;
typedef pair<Point ,R > Circle;
typedef vector<Point> Poly;

#define EPS (1e-10)//??????
#define EQ(a,b) (abs((a)-(b)) < EPS)//??????????????°???????????????
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )//????????????????????????????????????
#define ft first
#define sd second
#define pb push_back
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};
 
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define MAX_N 24
int n;
Circle c[MAX_N];
char color[MAX_N];
char memo[1<<MAX_N];
bool done[1<<MAX_N];

bool input(){
    cin >> n;
    int x,y,r;
    REP(i,n){
        cin >> x >> y >> r >> color[i];
        c[i] = Circle(Point(x,y),r);
    }

    return n!=0;
}

bool intersection_cc(Circle c1,Circle c2){
    return abs(c1.ft - c2.ft) - (c1.sd + c2.sd) < -EPS;
}

int saiki(int S){
    if(done[S])
        return memo[S];
    bool toreru[MAX_N];
    REP(i,n){
        toreru[i] = true;
        if(S&(1<<i)){
            toreru[i] = false;
            continue;
        }
        REP(j,i){
            if(!(S&(1<<j)) && intersection_cc(c[i],c[j])){
                toreru[i] = false;
                break;
            }
        }
    }
    int maxi = 0;
    REP(i,n){
        if(!toreru[i])
            continue;
        FOR(j,i+1,n){
            if(toreru[j] && color[i] == color[j]){
                maxi = max(maxi,saiki(S|(1<<i)|(1<<j)) + 2);
            }
        }
    }
    done[S] = true;
    return memo[S] = maxi;
}

void solve(){
    REP(i,(1<<n))
        done[i] = false; 
    printf("%d\n",saiki(0));
}
int main(){
    while(input())
        solve();
    return 0;
}

Measured memory_bytes: 35840
//phoenix




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


#define spdio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define pp pop_back
#define mp make_pair
#define fr(i,j,n) for(ll i=j; i<n; i++)
#define rfr(i,j,n) for(ll i=n-1; i>=0; i--)
#define vsort(v) sort(v.begin(),v.end())
#define asort(a) sort(a,a+n);


typedef long double ld;
typedef long long int ll;


//getline(cin,string);
const ll inf = (ll) 1e18 + 19;




ll solveDp(ll i,ll a[],ll n,ll k,vector <ll> &dp) {
    if(i>=n-1)
        return 0;
    if(dp[i]!=-1)
        return dp[i];
    else {
        ll mn=inf;
        fr(j,1,min(k+1,n-i))
            mn=min(mn,abs(a[i+j]-a[i])+solveDp(i+j,a,n,k,dp));
        return dp[i]=mn;
    }
}




void cazz() {
    ll t,n,i,j,k,ans=0,f=0,b;
    cin>>n>>k;
    ll a[n];
    fr(i,0,n) cin>>a[i];
    vector <ll> dp(n,-1);
    cout<<solveDp(i,a,n,k,dp)<<"\n";
}




int main() {
    spdio;
	cazz();
	return 0;
}





Measured memory_bytes: 11136
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<limits>
#include<set>
#include<queue>

using namespace std;
#define int long  long int
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

signed main()
{
	int A, B;
	cin >> A >> B;
	int wa = A + B;
	int sa = A - B;
	int seki = A * B;
	int ans = max({ wa,sa,seki });
	cout << ans;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<cstring>
using namespace std;
int main()
{
    int i,k=0;
   string s,t;
   cin>>s>>t;
   for(i=0;i<s.size();i++)

   {
       if(s[i]!=t[i])
    k++;
   }
   if(k>0)
    cout<<"No"<<endl;
   else
    cout<<"Yes"<<endl;
   return 0;
}


Measured memory_bytes: 3588
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
typedef long long ll;
typedef pair<int, int> P;
 
int main(){
  int n, m;
  cin >> n >> m;
  vector<int> a(n);
  
  int vote=0;
  int v;
  rep(i, n){
    cin >> v;
    vote += v;
    a.at(i) = v;
  }
  sort(a.begin(), a.end());
  if(a.at(n-m) >= (float)(vote/((float)(4*m)))) cout << "Yes" << endl;
  else                        cout << "No"  << endl;
  
  return 0;
}



Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
  long x, b;
  int cnt = 0;

  scanf("%ld", &x);

  b = 100;
  
  do {
    b =  b + (b / 100);
    cnt++;
  } while (b < x);

  printf("%d", cnt);
  
  return 0;
}

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

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

    int N, K;
    cin >> N >> K;

    vector<long long> h(N);
    for (int i=0; i<N; ++i) cin >> h[i];

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

    long long d = LLONG_MAX;
    for (int i=0; i+K-1<N; ++i) {
        d = min(d, h[i+K-1]-h[i]);
    }

    cout << d << endl;

    return 0;
}

Measured memory_bytes: 1024
import numpy as np
import sys
def input(): return sys.stdin.readline().rstrip()


def main():
    n, t = map(int, input().split())
    dp = np.zeros(t,dtype=int)
    food = []
    for _ in range(n):
        a, b = map(int, input().split())
        food.append([a, b])
    food.sort(key=lambda x: x[0]*-1)
    for j in range(n):
        a, b = food[j][0], food[j][1]
        a=min(a,t)
        dptmp=np.zeros(t,dtype=int)
        dptmp[a:] = np.maximum(dp[a:],dp[:-a]+b)
        dptmp[:a] = np.maximum(np.full(a,b,dtype=int), dp[:a])
        dp=dptmp
    print(dp[-1])


if __name__ == '__main__':
    main()

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

int main(void){
	vector<int> a(9);
	int n;
	for(int i = 0; i < 9; i++) cin >> a[i];
	cin >> n;
	vector<int> b(n);
	for(int i = 0; i < n; i++) cin >> b[i];
	for(int i : b){
		for(int j = 0; j < 9; j++){
			if(i == a[j]){
				a[j] = -1;
			}
		}
	}
	string ans = "No";
	if(a[0] == -1 && a[1] == -1 && a[2] == -1) ans = "Yes";
	if(a[3] == -1 && a[4] == -1 && a[5] == -1) ans = "Yes";
	if(a[6] == -1 && a[7] == -1 && a[8] == -1) ans = "Yes";
	if(a[0] == -1 && a[3] == -1 && a[6] == -1) ans = "Yes";
	if(a[1] == -1 && a[4] == -1 && a[7] == -1) ans = "Yes";
	if(a[2] == -1 && a[5] == -1 && a[8] == -1) ans = "Yes";
	if(a[0] == -1 && a[4] == -1 && a[8] == -1) ans = "Yes";
	if(a[2] == -1 && a[4] == -1 && a[6] == -1) ans = "Yes";
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3612
n,m = map(int,input().split())
A = list(map(int,input().split()))
tehuda = []
for i in range(m):
    b,c = map(int,input().split())
    tehuda.append((b,c))
# とりあえず和
sumA = sum(A)
import heapq
heapq.heapify(A)
tehuda = sorted(tehuda,key = lambda x:x[1])
#print(tehuda)
over = True
while tehuda:
    if not over:
        break
    b,c = tehuda.pop()
    while True:
        m = heapq.heappop(A)
        #print(m,c)
        if m >= c:
            over = False
            break
        else:
            b -= 1
            sumA -= m
            sumA += c
            heapq.heappush(A,c)
            if b == 0:
                break
print(sumA)


Measured memory_bytes: 94872
#include <algorithm>
#include <bits/stdc++.h>
#include <bitset>
#include <cassert>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <memory>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <vector>
using namespace std;
#define REP(i, n) for (int64_t i = 0; i < (int64_t)n; i++)
#define REP_FOR(i, a, b) for (int64_t i = (int64_t)a; i < (int64_t)b; i++)
#define REP_REV(i, a, b) for (int64_t i = (int64_t)a; i > (int64_t)b; i--)
#define FORALL(v) (v).begin(), (v).end()
#define mp(a, b) make_pair(a, b)
#define eb(x) emplace_back(x)
#define F first
#define S second
typedef long long ll;
typedef long double ld;
typedef pair<int64_t, int64_t> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<int64_t> vii;
typedef vector<vii> vvii;
const ll mod = 1e9 + 7;
const int64_t infi = 1147483600;
const ll infl = 4e18 + 5;
const char EOL = '\n';
//cout << fixed << setprecision(17) << res << endl;
const ll MOD = 998244353;
 
int main() {
    string s;
    cin >> s;
    sort(s.begin(), s.end());
    if (s[0] == s[1] && s[2] == s[3] && s[0] != s[2]) {
        cout << "Yes" <<endl;
    } else {
        cout << "No" << endl;
    }

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;typedef long long ll;typedef string str;
typedef vector<str> vst;typedef vector<ll> vll;
ll mod = 1000000007, INF = 10000000000000000;
ll gcd(ll a, ll b){if(b==0){return a;}return gcd(b, a%b);}
// for (ll i = 0; i < n; i++) {
// sort(.begin(), .end());
int main(){
  ll a,b,c,d;
  cin >> a>>b>>c>>d;
  ll C,D,CD,cd;
  C=b/c-(a-1)/c, D=b/d-(a-1)/d;
  cd=c*d;
  cd/=gcd(c,d);
  CD=b/cd-(a-1)/cd;
  
  cout << b-a+1-(C+D-CD) << endl;
  
}

Measured memory_bytes: 256
#include <iostream>
#include <atcoder/dsu>

using namespace std;
using namespace atcoder;

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

    dsu graph = dsu(n);
    for (int i = 0; i < m; i++)
    {
        int a, b;
        cin >> a >> b;
        graph.merge(a - 1, b - 1);
    }
    
    cout << graph.groups().size() - 1 << endl;
}


Measured memory_bytes: 8916
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <cstring>

using namespace std;
// ascending order
#define vsort(v) sort(v.begin(), v.end())
// descending order
#define vsort_r(v) sort(v.begin(), v.end(), greater<int>())
#define vunique(v) unique(v.begin(), v.end())
#define mp make_pair
#define ts(x) to_string(x)
#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define repm(i, a, b) for(int i = (int)a; i > (int)b; i--)
#define bit(a) bitset<8>(a)
#define des_priority_queue priority_queue<int, vector<int>, greater<int> >
#define all(v) (v).begin(), (v).end()
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1e18;

ll dp[100010][4];
int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);

	string s;
	cin >> s;
	int mod = 1e9 + 7;
	memset(dp, 0, sizeof(dp));
	dp[0][0] = 1;
	rep(i, 0, s.size()) {
		rep(j, 0, 4) {
			if(s[i] != '?') (dp[i + 1][j] += dp[i][j]) %= mod;
			else (dp[i + 1][j] += (dp[i][j] * 3 % mod)) %= mod;
		}
		if(s[i] == 'A' or s[i] == '?') (dp[i + 1][1] += dp[i][0]) %= mod;
		if(s[i] == 'B' or s[i] == '?') (dp[i + 1][2] += dp[i][1]) %= mod;
		if(s[i] == 'C' or s[i] == '?') (dp[i + 1][3] += dp[i][2]) %= mod;
	}

	cout << dp[s.size()][3] << endl;

}


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

int main() {
    ll n;
    std::cin >> n;
    
    vector<ll> a(n);
    vector<pair<ll,ll>> b(n);
    for (int i = 0; i < n; i++) {
        std::cin >> a[i];
        b[i] = {a[i],i};
    }
    sort(b.rbegin(),b.rend());
    
    // map<pair<ll,ll>,ll> memo;
    vector<vector<ll>> memo(n+1,vector<ll>(n+1,0));
    // memo[{0,0}] = 0;
    // memo[0][0] = 0;
    function<ll(ll, ll)> rec = [&] (ll l, ll r) {
        if(l+r>n) return 0ll;
        if(l==0&&r==0)return 0ll;
        if(memo[l][r]!=0)return memo[l][r];
        
        if(l==0){
            return memo[l][r]=
                rec(l,r-1)+b[l+r-1].first*abs(b[l+r-1].second-(n-r));
        }
        if(r==0){
            return memo[l][r]= 
                rec(l-1,r)+b[l+r-1].first*abs(b[l+r-1].second-l+1);
        }
        
        return memo[l][r]= max(
            rec(l-1,r)+b[l+r-1].first*abs(b[l+r-1].second-l+1),
            rec(l,r-1)+b[l+r-1].first*abs(b[l+r-1].second-(n-r))
        );
    };
    ll tmp = 0;
    
    for (int i = 0; i <= n; i++) {
        tmp = max(tmp,rec(i,n-i));   
    }
    std::cout << tmp << std::endl;
}



Measured memory_bytes: 34952
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);

        int cnt=0;
        int length;
        int a;
        int i;
        int[] num;
        num = new int[1000];
        while(true){
            String line = sc.nextLine();
            if(line.equals("0")){
                break;
            }
            length = line.length();
            num[cnt] = 0;
            for(i=0; i<length; i++){
                a = Character.getNumericValue(line.charAt(i));
                num[cnt] += a;
            }
            cnt++;
        }
        for(i=0; i<cnt; i++){
            System.out.println(num[i]);
        }

        sc.close();
    }
}


Measured memory_bytes: 26356
import java.util.*;

public class Main {
	static class Elem {
		int prev, val;

		public Elem(int val, int prev) {
			this.val = val;
			this.prev = prev;
		}
	}

	int N, M;
	int ketasuu;
	Set<Integer> A;
	int[] cost = { 6, 2, 5, 5, 4, 5, 6, 3, 7, 6 };
	int[] dp;
	int keta = 0;

	Main() {
		Scanner in = new Scanner(System.in);
		String[] tokens = in.nextLine().split(" ");
		N = Integer.parseInt(tokens[0]);
		M = Integer.parseInt(tokens[1]);
		A = new HashSet<>();
		tokens = in.nextLine().split(" ");
		for (int i = 0; i < M; ++i) {
			A.add(Integer.parseInt(tokens[i]));
		}
		in.close();
	}

	void calcKeta() {
		dp = new int[N + 1];
		Arrays.fill(dp, -1);
		dp[0] = 0;
		for (int i = 1; i <= N; ++i) {
			for (Integer a : A) {
				if (i - cost[a] >= 0) {
					dp[i] = Math.max(dp[i], dp[i - cost[a]] + 1);
				}
			}
		}
		keta = dp[N];
	}

	void show() {
		List<Integer> list = new ArrayList<>();
		int n = N;
		for (int i = 0; i < keta; ++i) {
			int num = -1;
			for (Integer a : A) {
				if (n >= cost[a] && dp[n] - dp[n - cost[a]] == 1) {
					num = Math.max(num, a);
				}
			}
			list.add(num);
			n -= cost[num];
		}
		Collections.sort(list, new Comparator<Integer>() {
			@Override
			public int compare(Integer o1, Integer o2) {
				if (o1 < o2) {
					return 1;
				} else if (o1 > o2) {
					return -1;
				} else {
					return 0;
				}
			}
		});
		StringBuilder strBuilder = new StringBuilder();
		for (int i = 0; i < list.size(); ++i) {
			strBuilder.append(Integer.toString(list.get(i)));
		}
		System.out.println(strBuilder.toString());
	}

	public static void main(String[] args) {
		Main ins = new Main();
		ins.calcKeta();
		ins.show();
	}
}

Measured memory_bytes: 23508
package main
import(
  "fmt"
  "sort"
)
func main(){
  var n, i int
  fmt.Scan(&n)
  a:=make([]int, n)
  for i=0;i<n;i++{
    fmt.Scan(&a[i])
  }
  sort.Sort(sort.IntSlice(a))
  fmt.Println(a[n/2]-a[n/2-1])
}


Measured memory_bytes: 5504
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		String s = in.next();
		in.close();
		int n = s.length()-1;
		long result = 0;

		for (int i=0; i<(Math.pow(2,n)); i++) {
			String str= s;
			for (int j=n; 0<j; j--) {
				if ((1&i>>j-1) == 1) {
					str = str.substring(0,j) + "," + str.substring(j,str.length());
				}
			}
			String[] ary = str.split(",");
			for(String ch: ary){
				result = result + Long.parseLong(ch);
			}
		}
		System.out.println(result);
	}
}


Measured memory_bytes: 20052
#include <bits/stdc++.h>
using namespace std;
int main() {
  string S;
  cin >> S;
  bool b = true;
  for (int i = 0; i < 3; i++) {
    if (S.at(i) == S.at(i + 1)) {b = false;}
  }
  if (b) {cout << "Good" << endl;}
  else {cout << "Bad" << endl;}
}

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

#ifdef ARTEM
	#define deb(x) x
#else
	#define deb(x)
	const int inf = 1000500;
#endif

void solve();

int main() {
	solve();
}

/* ================ actual code starts here ================ */

int ans = inf;
set<int> can_use;

void rec(int a, int b) {
	if(a >= b) {
		ans = min(ans, a);
		return;
	}

	for(int i : can_use) {
		if(!a && !i)
			continue;

		rec(a * 10 + i, b);
	}
}

void solve() {
	int n, k;
	cin >> n >> k;
	for(int i = 0; i < 10; i++)
		can_use.insert(i);

	for(int i = 0, x; i < k; i++) {
		cin >> x;
		can_use.erase(x);
	}

	rec(0, n);
	cout << ans << endl;
}

Measured memory_bytes: 3600
# 入力が10**5とかになったときに100ms程度早い
import sys
read = sys.stdin.readline


def read_ints():
    return list(map(int, read().split()))


def read_a_int():
    return int(read())


def read_matrix(H):
    '''
    H is number of rows
    '''
    return [list(map(int, read().split())) for _ in range(H)]


def read_map(H):
    '''
    H is number of rows
    文字列で与えられた盤面を読み取る用
    '''
    return [read() for _ in range(H)]


def read_col(H, n_cols):
    '''
    H is number of rows
    n_cols is number of cols

    A列、B列が与えられるようなとき
    '''
    ret = [[] for _ in range(n_cols)]
    for _ in range(H):
        tmp = list(map(int, read().split()))
        for col in range(n_cols):
            ret[col].append(tmp[col])

    return ret


N = read_a_int()
A = read_ints()

from fractions import gcd
# 累積GCDを使って解く
# 累積の概念は広く使えるxor,min,max,積等...
# 差ではなく左右から挟み込んで演算という概念をしっかりと身につけよう

left = []
right = []
tmp_fo = 0
tmp_re = 0
for fo, re in zip(A, A[::-1]):
    tmp_fo = gcd(tmp_fo, fo)
    tmp_re = gcd(tmp_re, re)
    left.append(tmp_fo)
    right.append(tmp_re)

right = right[::-1]

ans = 0
for i in range(1, N-1):
    ans = max(ans, gcd(left[i - 1], right[i + 1]))

ans = max(ans, right[1], left[-2])

print(ans)


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

#define MAX_N (10000)
#define MAX_M (9)

int comp(int nd1s[10], int nd2s[10]) {
  int total_nd1 = 0, total_nd2 = 0;
  for (int k = 0; k < 10; k++) {
    total_nd1 += nd1s[k];
    total_nd2 += nd2s[k];
  }
  if (total_nd1 < total_nd2) {
    return -1;
  } else if (total_nd1 > total_nd2) {
    return 1;
  }
  for (int k = 9; k > 0; k--) {
    if (nd1s[k] < nd2s[k]) {
      return -1;
    } else if (nd1s[k] > nd2s[k]) {
      return 1;
    }
  }
  return 0;
}

int main(int argc, char *argv[]) {
  // read inputs
  int N, M, as[MAX_M];
  scanf("%d %d", &N, &M);
  for (int i = 0; i < N; i++) {
    scanf("%d", &as[i]);
  }

  // the number of matches required to make each digit
  int num_matches[10] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};

  // solve dp
  int dpss[MAX_N + 1][10];
  for (int k = 0; k < 10; k++) {
    dpss[0][k] = 0;
  }
  for (int n = 1; n <= N; n++) {
    int num_digits[10] = {}, total_num_digits = 0;
    int max_num_digits[10] = {-1}, max_total_num_digits = -1;
    for (int i = 0; i < M; i++) {
      const int a = as[i], num_a = num_matches[a];
      if (num_a <= n && dpss[n - num_a][0] >= 0) {
        // try creating as[i]
        for (int k = 0; k < 10; k++) {
          num_digits[k] = dpss[n - num_a][k];
          total_num_digits += dpss[n - num_a][k];
        }
        num_digits[a]++;
        total_num_digits++;
        // if it is better than the current solution, record it
        if (max_total_num_digits < 0 || comp(num_digits, max_num_digits) > 0) {
          for (int k = 0; k < 10; k++) {
            max_num_digits[k] = num_digits[k];
          }
          max_total_num_digits = total_num_digits;
        }
      }
    }
    for (int k = 0; k < 10; k++) {
      dpss[n][k] = max_num_digits[k];
    }
  }
  for (int k = 9; k > 0; k--) {
    while (dpss[N][k] > 0) {
      printf("%d", k);
      dpss[N][k]--;
    }
  }
  printf("\n");

  return 0;
}


Measured memory_bytes: 512
#include "bits/stdc++.h"
#define rep(i,a,n) for(int (i) = (a);(i) < (n);(i)++)

typedef long long ll;
using namespace std;

int main(){
    int n,check = 0,memo = 0;
    cin >> n;
    bool flag[n];
    int p[n][3];
    
    
    rep(i,0,n){
        flag[i] = true;
        cin >> p[i][0] >> p[i][1] >> p[i][2];
        sort(p[i],p[i]+3);
    }
    
    rep(i,0,n){
        rep(j,i+1,n){
            check = 0;
            if(flag[j]){
                rep(k,0,3){
                    if(p[i][k] == p[j][k]){
                        check++;
                    }
                
                }
            }
            
            if(check == 3){
                flag[j] = false;
            }
        }
        
        
    }
    
    rep(i,0,n){
        if(flag[i]){
            memo++;
        }
    }
    
    cout << n - memo << endl;
}


Measured memory_bytes: 3188
import sys
import numpy as np
read = sys.stdin.read


class UnionFind():
    # 作りたい要素数nで初期化
    # 使用するインスタンス変数の初期化
    def __init__(self, n):
        self.n = n
        # root[x]<0ならそのノードが根かつその値が木の要素数
        # rootノードでその木の要素数を記録する
        self.root = [-1]*(n+1)
        # 木をくっつける時にアンバランスにならないように調整する
        self.rnk = [0]*(n+1)

    # ノードxのrootノードを見つける
    def Find_Root(self, x):
        if self.root[x] < 0:
            return x
        else:
            # ここで代入しておくことで、後の繰り返しを避ける
            self.root[x] = self.Find_Root(self.root[x])
            return self.root[x]

    # 木の併合、入力は併合したい各ノード
    def Unite(self, x, y):
        # 入力ノードのrootノードを見つける
        x = self.Find_Root(x)
        y = self.Find_Root(y)
        # すでに同じ木に属していた場合
        if x == y:
            return
        # 違う木に属していた場合rnkを見てくっつける方を決める
        elif self.rnk[x] > self.rnk[y]:
            self.root[x] += self.root[y]
            self.root[y] = x

        else:
            self.root[y] += self.root[x]
            self.root[x] = y
            # rnkが同じ（深さに差がない場合）は1増やす
            if self.rnk[x] == self.rnk[y]:
                self.rnk[y] += 1

    # xとyが同じグループに属するか判断
    def isSameGroup(self, x, y):
        return self.Find_Root(x) == self.Find_Root(y)

    # ノードxが属する木のサイズを返す
    def Count(self, x):
        return -self.root[self.Find_Root(x)]


N, *xy = map(int, read().split())
xy = np.array(xy, np.int64).reshape(N, 2)
x = xy[:, 0]
y = xy[:, 1]

arg_x = np.argsort(x)
arg_y = np.argsort(y)

edges_x = x[arg_x[1:]] - x[arg_x[:-1]]
edges_y = y[arg_y[1:]] - y[arg_y[:-1]]

edges = np.concatenate([edges_x, edges_y])
towns_1 = np.concatenate([arg_x[:-1], arg_y[:-1]])
towns_2 = np.concatenate([arg_x[1:], arg_y[1:]])

arg_edges = np.argsort(edges)
graph = zip(edges[arg_edges], towns_1[arg_edges], towns_2[arg_edges])

tree = UnionFind(N)
answer = 0

for d, t1, t2 in graph:
    if tree.isSameGroup(t1, t2):
        continue

    tree.Unite(t1, t2)
    answer += d

print(answer)

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

using namespace std;
typedef long long ll;

int main(void)
{
    string s;
    unsigned long long k;
    cin >> s >> k;

    for (int i = 0; i < min((unsigned long long)s.size(), k);i++){
        if(s.at(i)>='2'){
            cout << s.at(i) << endl;
            return 0;
        }
    }
    cout << '1' << endl;

    return 0;
}

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

using namespace std;

#define REP(i, a, b) for ( int i = (a), _end_ = (b); i <= _end_; ++ i )
#define mem(a) memset ( (a), 0, sizeof ( a ) )
#define str(a) strlen ( a )
typedef long long LL;
template<class T> int maxx(T a, T b) { return a > b ? a : b; }
template<class T> int minn(T a, T b) { return a < b ? a : b; }
template<class T> int abss(T a) { return a > 0 ? a : -a; }
#define max maxx
#define min minn
#define abs abss
const int maxn = 400010;

int main()
{
    char s[10];
    scanf("%s", s + 1);
    if ( s[1] == 'S' ) puts("Cloudy");
    else if (s[1] == 'C' ) puts("Rainy");
    else puts("Sunny");
	return 0;
}


Measured memory_bytes: 764
#! /usr/bin/env python3
# -*- coding:utf-8 -*-

def min_needed_value(values, skills, X):
    import sys
    ans = sys.maxsize
    for i in range(2**len(values)):
        get_skill = [0] * len(skills[0])
        get_value = 0
        for j in range(len(values)):
            if (i >> j) & 1:
                get_skill = [x + y for (x, y) in zip(get_skill, skills[j])]
                get_value += values[j]
        # print(i, get_skill, get_value)
        if all([s >= X for s in get_skill]): ans = min(ans, get_value)
    if ans == sys.maxsize: return -1
    else: return ans

def main():
    N, M, X = map(int, input().split())
    values = []
    skills = []
    for _ in range(N):
        Book = list(map(int, input().split()))
        values.append(Book[0])
        skills.append(Book[1:])
    print(min_needed_value(values, skills, X))

if __name__ == "__main__":
    main()


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

using namespace std;
#define INF 1e16
typedef long long lint;

bool went[5]={0};
lint tm[5];
lint S[5];
lint dist;
lint D[5];
int n,m;
lint answer = INF;
lint pre;

void judge(){
    vector<pair<lint,lint> > meet;
    rep(i,n-1){
        for(int j = i + 1;j < n;j++){
            int hoge = 0;
            if(S[i] < S[j]||tm[j]-tm[i] >= (S[i]-S[j])*dist)
                continue;
            rep(k,m){
                if(tm[i]-tm[j] == (S[j]-S[i])*D[k]){
                    meet.push_back(make_pair(tm[j]+S[j]*D[k],k));
                    hoge = 1;
                    break;
                }
            }
            if(!hoge){
                return;
            }
        }
    }
    if(!meet.empty()){
        sort(meet.begin(),meet.end());
        rep(i,meet.size()-1){
            if(meet[i] == meet[i+1])
                return;
        }
    }
    pre = 0;
    rep(i,n){
        pre = max(pre,tm[i]+dist*S[i]);
    }
    answer = min(answer,pre);
}

void search(int p){
    if(p == 0){
        tm[0] = 0;
        went[0]=1;
        search(1);
        return;
    }
    rep(i,n-1){
        if(went[i] && went[i+1] && tm[i] >= tm[i+1])
            return;
    }
    if(p == n){
        judge();
        return;
    }
    rep(i,n-1){
        if(went[i] && !went[i+1]){
            tm[i+1] = tm[i]+1;
            went[i+1] = 1;
            search(p+1);
            went[i+1] = 0;
        }
        if(!went[i] && went[i+1]){
            tm[i] = tm[i+1]-1;
            went[i] = 1;
            search(p+1);
            went[i] = 0;
        }
    }
    rep(i,n){
        if(!went[i]){
            rep(j,n){
                if((i < j && S[i]<S[j])||(i > j && S[i]>S[j]))
                    continue;
                if(went[j]){
                    rep(k,m){
                        tm[i] = tm[j]+(S[j]-S[i])*D[k];
                        went[i] = 1;
                        search(p+1);
                        went[i] = 0;
                    }
                    tm[i] = tm[j]+(S[j]-S[i])*dist;
                    went[i] = 1;
                    search(p+1);
                    went[i] = 0;
                }
            }
        }
    }
}

int main(){
    cin  >> dist;
    cin >> n;
    rep(i,n){
        cin >> S[i];
    }
    cin >> m;
    rep(i,m){
        cin >> D[i];
    }
    search(0);
    cout << answer << endl;
}

Measured memory_bytes: 1204
def main():
    _ = int(input())
    nums = [int(i) for i in input().split()]
    # nums = map(int, input().split())
    counter = 0
    loop = True
    while loop:
        for i, n in enumerate(nums):
            if n % 2 == 0:
                nums[i] = n / 2
            else:
                loop = False
                break
        if loop:
            counter += 1
    print(counter)


if __name__ == '__main__':
    main()

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

int main() {
  vector<int> vec = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  int x;
    cin >> x;
  cout << vec.at(x - 1) << endl;
  }
  

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

using namespace std;

int main(){
    int N, K;
    cin >> N >> K;
    
    vector<bool> has(N, false);
    for(int i=0;i<K;i++){
        int d;
        cin >> d;
        for(int j=0;j<d;j++){
            int a;
            cin >> a;
            a--;
            has[a] = true;
        }
    }

    int ans =0;
    for(int i=0;i<N;i++){
        if(!has[i]){
            ans++;
        }
    }
    cout << ans <<endl;
    return 0;
}

Measured memory_bytes: 3632
a,b,c,x,y=[int(x) for x in input().split()]
p=0
if a>=c and b>=c:
  p_1=c*min(x,y)*2
  if x>y:
    p_1+=a*(x-y)
  elif y>x:
    p_1+=b*(y-x)
  p_2=c*max(x,y)*2
  p=min(p_1,p_2)
elif a<=c and b<=c:
  p=a*x+b*y
elif a<=c and c<=b:
  p_1=a*x+b*y
  p_2=c*min(x,y)*2
  if x>y:
    p_2+=a*(x-y)
  elif y>x:
    p_2+=b*(y-x)
  p_3=c*max(x,y)*2
  p=min(p_1,p_2,p_3)
elif b<=c and c<=a:
  p_1=a*x+b*y
  p_2=c*min(x,y)*2
  if x>y:
    p_2+=a*(x-y)
  elif y>x:
    p_2+=b*(y-x)
  p_3=c*max(x,y)*2
  p=min(p_1,p_2,p_3)
print(p)

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

typedef long long ll;
const int INF = 1e9;
const ll LINF = 1e18;
const int mod = 1e9+7;

#define pi pair<int,int>
#define pl pair<lld,lld>

#define dump(x) cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define SANKOU(n,a,b) cout << ((n) ? (#a) : (#b) ) << endl

#define mem0(x) memset(x,0,sizeof(x))
#define fillnum(x,n) fill(begin(x),end(x),n)
#define asort(x) sort(x.begin(),x.end())
#define dsort(x,t) sort(x.begin(),x.end(),greater<t>())
#define vuniq(x) x.erase(unique(x.begin(), x.end()), x.end())

#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)

int main() {
    ll N[4];
    ll C[10];
    mem0(C);
    for (int i = 0; i < 4; i++) {
        cin >> N[i];
        C[N[i]]++;
    }
    YES(C[1] && C[9] && C[7] && C[4]);
}

Measured memory_bytes: 3580
#include <bits/stdc++.h>
#define int long long

int sumofdigits(int x) {
  int sum = 0;
  while (x > 0) {
    sum += x % 10;
    x /= 10;
  }
  return sum;
}

signed main() {
  int n;
  std::cin >> n;
  
  std::vector<int> a(3*n);
  for (int i = 0; i < 3*n; i++) {
    std::cin >> a.at(i);
  }
  std::sort(a.begin(), a.end(), std::greater<int>());
  
  int sum = 0;
  for (int i = 0; i < n; i++) {
    sum += a.at(2*i+1);
  }
  
  std::cout << sum << '\n';
}

Measured memory_bytes: 2560
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
char ss[100010];
int ans=10000000;
int main()
{
	cin>>ss;
	int len=strlen(ss);
	for(int i=1;i<=len-1;i++)
	    if(ss[i]==ss[i-1]) continue;
	    else
		    ans=min(ans,max(i,len-i));
    if(ans==10000000) cout<<len;
	else cout<<ans;
}

Measured memory_bytes: 384
fun main(args: Array<String>) {
    val inp = readLine()!!.split(" ").map {
        it.toInt()
    }
    if(inp.get(0) == inp.get(1) && inp.get(0) == inp.get(2)) {
        println("0")
        return
    }
    if(inp.all{it.mod(2) == 0} || inp.all{it.mod(2) == 1}) {
        foo(inp, false)
        return
    }
    val odd = inp.filter { it.mod(2) == 0 }
    val noOdd = inp.filterNot { it.mod(2) == 0 }
    if(odd.size == 2) {
        var l = mutableListOf<Int>()
        for(i in odd) {
            l.add(i+1)
        }
        l.add(noOdd.get(0))
        foo(l,true)
    } else {
        var l = mutableListOf<Int>()
        for(i in noOdd) {
            l.add(i+1)
        }
        l.add(odd.get(0))
        foo(l,true)
    }
}

fun foo(l: List<Int>, b:Boolean) {
        val max =  l.max()
        var c = 0
        for(i in l) {
            c += if(max!! - i == 0) {
                0
            } else {
                (max - i) / 2
            }
        }
        if(b) {
            println(c+1)
            return
        }
        println(c)
}

Measured memory_bytes: 35952
N,M = map(int, input().split())
pro_pen = [0]*N
pro_ac  = [0]*N
for i in range(M):
    p_i,s_i = map(str, input().split())
    if pro_ac[int(p_i)-1] == 0 and s_i == "WA":
        pro_pen[int(p_i)-1] += 1
    if pro_ac[int(p_i)-1] == 0 and s_i == "AC":
        pro_ac[int(p_i)-1] = 1
wa = 0
for i in range(N):
    if pro_ac[i] == 1:
        wa += pro_pen[i]
print(sum(pro_ac),wa)

Measured memory_bytes: 47448
fun main(args: Array<String>) {
    val mod = 1000000007
    val (n, m) = readInputLine().split(" ").map{it.toInt()}
    
    val dp = IntArray(n + 1)
    dp[0] = 1
    
    val aSet = mutableSetOf<Int>()
    
    for (i in 1..m) {
        aSet.add(readInputLine().toInt())
    }
    if (!aSet.contains(1)) {
        dp[1] = 1
    }
    
    for (i in 2..n) {
        if (aSet.contains(i)) {
            continue
        }
        
        dp[i] = dp[i - 2]
        dp[i] += dp[i - 1]
        dp[i] %= mod
    }

    println(dp[n])
}

fun readInputLine(): String {
    return readLine()!!
}


Measured memory_bytes: 47892
#include <bits/stdc++.h>
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;

long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

ll nCr(ll n, ll r) {
	ll ans = 1;
	for (ll i = n; i > n - r; --i) {
		ans = (ans * i) % mod;
	}
	for (ll i = 1; i < r + 1; ++i) {
		ans = ans * modinv(i, mod) % mod;
	}
	return ans;
}

long long modpow(long long a, long long n, long long modo) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % modo;
        a = a * a % modo;
        n >>= 1;
    }
    return res;
}

int main() {
    int n, a, b;
    cin >> n >> a >> b;
    ll ans = modpow(2, n, mod)-1;
    ans = ((ans + mod) - nCr(n, a) % mod) % mod;
    ans %= mod;
    ans = ((ans + mod) - nCr(n, b) % mod) % mod;
    ans %= mod;
    cout << ans % mod << endl;
}

Measured memory_bytes: 256
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var Arr=(input.trim()).split("\n");
var n=Arr.shift()-0;
var arr=Arr.shift().split("");
var cnt=0;
for(var i=0;i<n;i++){
   var str=Arr.shift();
   var a="";
   for(var j=0;j<47;j++){
      var s=arr.join(a);
      if(s>=100)break;
      var re = new RegExp(s);
      if(re.test(str)){cnt++;break;}
      a+=".";
   }
}
console.log(cnt);

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

typedef int64_t Int;
#define all(x) (x).begin(), (x).end()
 
const double EPS = 1e-10;
const Int INF = 1e18;
const int inf = 1e9;
const Int mod = 1e9+7;

bool print_space_enable = false;
void print() { 
    cout << '\n'; 
    print_space_enable = false;
}

template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
    if (print_space_enable) cout << " ";
    cout << fixed << setprecision(15) << head;
    print_space_enable = true;
    print(std::forward<Tail>(tail)...);
}

template<typename T>
void print(vector<T> v) {
    for (size_t i = 0; i < v.size(); i++) {
        if (i > 0) std::cout << " ";
        std::cout << v[i];
    }
    std::cout << std::endl;
}

int main() {
    Int n, m, q;
    cin >> n >> m >> q;
    vector<pair<Int, Int>> a(m);
    for (Int i = 0; i < m; i++) {
        cin >> a[i].first >> a[i].second;
        a[i].first--, a[i].second--;
    }
    vector<pair<Int, Int>> b(q);
    for (Int i = 0; i < q; i++) {
        cin >> b[i].first >> b[i].second;
        b[i].first--, b[i].second--;
    }
    vector<vector<Int>> v(n);
    for (Int i = 0; i < m; i++) {
        v[a[i].first].push_back(a[i].second);
    }
    for (Int i = 0; i < n; i++) {
        sort(all(v[i]));
        v[i].push_back(INF);
    }
    for (Int i = 0; i < q; i++) {
        Int res = 0;
        for (Int j = 0; j < n; j++) {
            if (j < b[i].first) continue;
            if (b[i].second < j) break;
            res += upper_bound(all(v[j]), b[i].second) - v[j].begin();
        }
        print(res);
    }
    return 0;
}


Measured memory_bytes: 10648
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main {

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int n = scanner.nextInt(), k = scanner.nextInt();
			int[] x = new int[n];
			IntStream.range(0, n).forEach(i -> x[i] = scanner.nextInt());
			System.out.println(IntStream.range(0, n - k + 1).map(i -> {
				// 解説通りの計算式
				return Math.min(Math.abs(x[i]), Math.abs(x[i + k - 1])) + Math.abs(x[i + k - 1] - x[i]);
			}).min().getAsInt());
		}
	}
}


Measured memory_bytes: 59920
#ifndef _WIN32
#include<iostream>
#endif // !_WIN32

#include<algorithm>
#include<vector>
#include<string>
#include<iomanip>
#include<map>
#include<stack>
#include<queue>
#include<math.h>
#include<tuple>
using namespace std;
#define FOR(i,bg,ed) for(int i=(bg);i<(ed);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()



double dist(double dx, double dy, double dz) {
	return sqrt(dx*dx + dy*dy + dz*dz);
}
typedef vector<double> V;
typedef tuple<double, int, int> P;
const double EPS = 1e-8;
double f(double a) { return a*a; }
int main() {
	int n;
	cout << fixed;
	cout << setprecision(10);
	while (cin >> n, n) {
		V x(n),y(n),z(n),r(n),vx(n),vy(n),vz(n),vr(n);
		REP(i, n) {
			cin >> x[i] >> y[i] >> z[i];
			cin >> vx[i] >> vy[i] >> vz[i];
			cin >> r[i] >> vr[i];
		}
		vector<double> t(n, -1);
		vector<P> sq;
		REP(i, n)REP(j, n) {
			if (i != j) {
				double c = 
					+ f(x[i] - x[j])
					+ f(y[i] - y[j])
					+ f(z[i] - z[j])
					- f(r[i] + r[j]);
				double b =
					+ (x[i] - x[j])*(vx[i] - vx[j])
					+ (y[i] - y[j])*(vy[i] - vy[j])
					+ (z[i] - z[j])*(vz[i] - vz[j])
					+ (r[i] + r[j])*(vr[i] + vr[j]);
				double a =
					+ f(vx[i] - vx[j])
					+ f(vy[i] - vy[j])
					+ f(vz[i] - vz[j])
					- f(vr[i] + vr[j]);
				//cout << a << " " << b << " " << c << endl;
				if (b*b - a*c >= 0) {
					double latte = sqrt(b*b - a*c);
					double t1 = (-b + latte) / a;
					double t2 = (-b - latte) / a;
					if (t1 > 0)sq.push_back(P(t1, i, j));
					if (t2 > 0)sq.push_back(P(t2, i, j));
				}
			}
			else {
				sq.push_back(P(r[i] / vr[i], i, i));
			}
		}
		sort(ALL(sq));
		for (auto &it : sq) {
			double tt; int a, b;
			tie(tt, a, b) = it;
			if (t[a] < 0 && t[b] < 0) {
				t[a] = t[b] = tt;
			}

		}

		REP(i, n) {
			cout << t[i] << endl;

		}
	}


}

Measured memory_bytes: 4868
//By Tushar Gautam
#pragma GCC optimize ("-O2")
#include <bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define memreset(a) memset(a,0,sizeof(a))
#define testcase(t) int t;cin>>t;while(t--)
#define forstl(i,v) for(auto &i: v)
#define forn(i,e) for(int i = 0; i < e;++i)
#define forsn(i,s,e) for(int i = s; i < e;++i)
#define rforn(i,s) for(int i = s; i >= 0;--i)
#define rforsn(i,s,e) for(int i = s; i >= e;--i)
#define bitcount(a) __builtin_popcount(a) // set bits (add ll)
#define ln '\n'
#define getcurrtime ((double)clock()/CLOCKS_PER_SEC)
#define dbgarr(v,s,e) cerr<<#v<<" = "; forsn(i,s,e) cerr<<v[i]<<", "; cerr<<endl
#define inputfile freopen("input.txt", "r", stdin)
#define outputfile freopen("output.txt", "w", stdout)
#define dbg(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); \
stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) { cerr<<endl; }
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << "\t"; err(++it, args...);
}
template<typename T1,typename T2>
ostream& operator <<(ostream& c,pair<T1,T2> &v){
	c<<"("<<v.fi<<","<<v.se<<")"; return c;
}
template <template <class...> class TT, class ...T>
ostream& operator<<(ostream& out,TT<T...>& c){
    out<<"{ ";
    forstl(x,c) out<<x<<" ";
    out<<"}"; return out;
}
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll,ll> p64;
typedef pair<int,int> p32;
typedef pair<int,p32> p96;
typedef vector<ll> v64;
typedef vector<int> v32; 
typedef vector<v32> vv32;
typedef vector<v64> vv64;
typedef vector<p32> vp32;
typedef vector<p64> vp64;
typedef vector<vp32> vvp32;
typedef map<int,int> m32;
const int LIM=1e5+5,MOD=1e9+7;
int t,n,m,k,x,y,w;
signed main(){
	fastio;
	cin>>x>>y;
	int to=3*x+y;
	cout<< to/2<<ln;
	return 0;
}

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

typedef long long int lli;
typedef long int li;

void solve(){
    int x, ans;
    for(int i = 0; i <= 4; i++){
        cin >> x;
        if(x == 0) ans = i + 1;
    }
    cout << ans << '\n';
}

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

/*
  check for corner cases.
  When using log check for zeros.
  Use queues and stacks if they are helping.

    (___)
    . . )____________
   _|__/\           |\
  (o_o_) \__________| \
           /|     ||   )
          < |     ||
*/


Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
int const MX = 2e5 + 2, MOD = 1e9 + 7;
long long a[MX];
int main()
{
    int n;
    cin>>n;
    long long sum = 0;
    for(int i = 0; i < n; i++){
        cin>>a[i];
        sum += a[i];
    }
    long long ans = 0;
    for(int i = 0; i < n; i++){
        long long s = (((sum - a[i]) % MOD)*a[i]) % MOD;
        ans = ans + s;
        sum -= a[i];
        ans = ans % MOD;
    }
    cout<<ans % MOD;
}




Measured memory_bytes: 5060
i = list(map(int, input().split()))
if i[0] == 7:
  if i[1] == 5 and i[2] ==5:
    print('YES')
  else:
    print('NO')
elif i[0] == 5:
  if (i[1] == 7 and i[2] == 5) or (i[2] == 7 and i[1] == 5):
    print('YES')
  else:
    print('NO')
else:
  print('NO')

Measured memory_bytes: 38256
#include<stdio.h>
int main(){
	int i,j,m,n,k,w[51]={0},b[51]={0},r[51]={0};
	int min=2501,wh=0,bl=0,re=0;
	char fl[51][51];
	scanf("%d%d",&n,&k);
	for(i=0;i<n;i++)scanf("%s",fl[i]);
	for(i=0;i<n;i++){
		for(j=0;j<k;j++){
			if(fl[i][j]=='W')++w[i];
			if(fl[i][j]=='B')++b[i];
			if(fl[i][j]=='R')++r[i];
		}
	}
	for(i=0;i<n-2;i++){//白
		wh+=k-w[i];
		for(j=i+1;j<n-1;j++){//青
			bl+=k-b[j];
			for(m=j+1;m<n;m++){//赤
				re+=k-r[m];
			}
			if(min>wh+bl+re)min=wh+bl+re;
			re=0;
		}
		bl=0;
	}
	printf("%d\n",min);
	return 0;
}


Measured memory_bytes: 2104
def main():
    MOD = 10 ** 9 + 7
    N, K = list(map(int, input().split(' ')))
    A = list(map(int, input().split(' ')))
    dp = [[0 for _ in range(K + 1)] for _ in range(N + 1)]
    for n in range(N + 1):
        dp[n][0] = 1
    for n in range(1, N + 1):
        dp_left = dp[n][0]  # dp[n][k - 1]
        for k in range(1, K + 1):
            val = dp_left + dp[n - 1][k]
            kk = k - A[n - 1] - 1
            if kk >= 0:
                val -= dp[n - 1][kk]
            val %= MOD
            dp[n][k] = val
            dp_left = val
    print(dp[N][K])


if __name__ == '__main__':
    main()

Measured memory_bytes: 171144
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);++(i))
#define all(x) (x).begin(),(x).end()
#define dump(x) cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define yes(n) cout << ((n) ? "yes" : "no") << endl

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

const int INF = 1001001001;
const vector<int> di = {-1,  0, 1, 0};
const vector<int> dj = { 0, -1, 0, 1};

void chmin(int &a, int b) { if (a > b) a = b; }

ll GCD(ll a, ll b) {
    if (b == 0) return a;
    else return GCD(b, a % b);
}
ll LCM(ll a, ll b) {
    ll g = GCD(a, b);
    return a / g * b;
}


int main() {
    int n; cin >> n;
    vector<ll> b(n-1);
    rep(i, n-1) cin >> b[i];

    ll ans = b[0] + b.back();
    for (int i=0;i+1<b.size();++i) {
        ans += min(b[i], b[i+1]);
    }
    cout << ans << endl;
}

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

namespace ABC112A
{
    class Program
    {
        static void Main(string[] args)
        {
            int A, B, N ;
            N = int.Parse(Console.ReadLine());

            if (N == 1)
               
                Console.WriteLine("Hello World");
            else
               
            {
                A = int.Parse(Console.ReadLine());
                B = int.Parse(Console.ReadLine());
                Console.WriteLine(A + B);
            }
            Console.ReadKey();
        }
    }
}


Measured memory_bytes: 13140
def insertion_sort(a, n, g):
    count = 0
    for i in range(g, n):
        j = i
        while j >= g and a[j-g] > a[j]:
                a[j-g], a[j] = a[j], a[j-g]
                j -= g
                count += 1

    return a, count


if __name__ == "__main__":
    import sys
    n = int(input())
    a = list(map(int, sys.stdin))
    count = 0

    G = [1]
    while n >= 3*G[-1] + 1:
        G.append(3*G[-1] + 1)

    for g in G[::-1]:
        a, cnt = insertion_sort(a, n, g)
        count += cnt

    print(len(G))
    print(*G[::-1])
    print(count)
    print(*a, sep="\n")


Measured memory_bytes: 53372
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<functional>
#include<queue>
#include <iomanip>
#include<cstring>
#include<map>
#include<limits>
#include<cmath>
#include<algorithm>
#include<bitset>
#include<utility>
#include<complex>
#include<cstdlib>
#include<set>
#include<cctype>

#define DBG cerr << '!' << endl;
#define REP(i,n) for(int (i) = (0);(i) < (n);++i)
#define rep(i,s,g) for(int (i) = (s);(i) < (g);++i)
#define rrep(i,s,g) for(int (i) = (s);i >= (g);--(i))
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int i = 0;i < (n);i++)cerr << v[i] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()

using namespace std;

typedef long long ll;
typedef vector<int> iv;
typedef vector<iv> iiv;
typedef vector<string> sv;


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

Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <vector>
#define ALL(l)  (l).begin(),(l).end()
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long ll;
 

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

Measured memory_bytes: 256