akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Set;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;

public class Main {
	
	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner(System.in);
		
		final int n = sc.nextInt();
		final int k = sc.nextInt();
		
		long sum = 0;
		long max = Long.MIN_VALUE;
		int[] ws = new int[n];
		
		for(int i = 0; i < n; i++){
			final int w = sc.nextInt();
			ws[i] = w;
			sum += w;
			max = Math.max(max, w);
		}
		
		long lower = max - 1; // 
		long upper = sum;
		
		while(upper - lower != 1){
			long mid = (lower + upper) / 2;
			
			int count = 1;
			long can_use = mid;
			for(int i = 0; i < n; i++){
				if(can_use < ws[i]){
					count++;
					can_use = mid - ws[i];
				}else{
					can_use -= ws[i];
				}
			}
			
			if(count <= k){
				upper = mid;
			}else{
				lower = mid;
			}
		}
		
		System.out.println(upper);
		
	}
	
	public static class Scanner {
	    private BufferedReader br;
	    private StringTokenizer tok;

	    public Scanner(InputStream is) throws IOException {
	        br = new BufferedReader(new InputStreamReader(is));
	    }

	    private void getLine() throws IOException {
	        while (!hasNext()) { tok = new StringTokenizer(br.readLine()); }
	    }

	    private boolean hasNext() {
	        return tok != null && tok.hasMoreTokens();
	    }

	    public String next() throws IOException {
	        getLine(); return tok.nextToken();
	    }

	    public int nextInt() throws IOException {
	        return Integer.parseInt(next());
	    }
	    
	    public long nextLong() throws IOException {
	    	return Long.parseLong(next());
	    }
	    
	    public void close() throws IOException {
	        br.close();
	    }
	}

}

Measured memory_bytes: 33032
#include <bits/stdc++.h>
using namespace std;
#define N 200005
int A[N],Ans[N];
int main() {
	int n,tot = 0;
	cin >> n;
	for(int i=1; i<=n; i++) scanf("%d",&A[i]);
	for(int i=n; i>=1; i--) {
		if(!A[i]) continue;
		Ans[++tot] = i;
		for(int j=1; j*j<=i; j++) {
			if(i%j) continue;
			A[j] = !A[j];
			if(j*j != i) A[i/j] = !A[i/j];
		}
	}
	sort(A+1,A+tot+1);
	cout<<tot<<endl;
	for(int i=1;i<=tot;i++) printf("%d ",Ans[i]);
	return 0;
}

Measured memory_bytes: 2304
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

a, b = map(str, input().split())
print(sorted([a*int(b), b*int(a)])[0])

Measured memory_bytes: 5144
#include<bits/stdc++.h>
using namespace std;
typedef pair<double,double> pi;
pi arr[10];
double sqr(double a){
	return a*a;
}
double fac(int n){
	int ret = 1;
	for(int i=1; i<=n; i++) ret*=i;
	return (double)ret;
}
int main(){
	int n;
	cin>>n;
	for(int i=1; i<=n; i++) cin>>arr[i].first>>arr[i].second;
	vector<int>order;
	for(int i=1; i<=n; i++) order.push_back(i);
	double ret = 0;
	do{
		for(int i=1; i<order.size(); i++){
			int previ = order[i-1];
			int curr = order[i];
			double d = sqr(arr[previ].first-arr[curr].first);
			d+=sqr(arr[previ].second-arr[curr].second);
			ret+=sqrt(d);
		}
	}while(next_permutation(order.begin(),order.end()));
	cout.precision(10);
	cout<<ret/fac(n);
}

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

int main(){
  int N, D;
  cin >> N >> D;
  vector<vector<int>> X;
  for(int i = 0; i < N; ++i){
    vector<int> x(D);
    for(int j = 0; j < D; ++j){
      cin >> x[j];
    }
    X.push_back(x);
  }
  int ans = 0;
  for(int i = 0; i < N; ++i){
    for(int j = i+1; j < N; ++j){
      long long d = 0;
      for(int k = 0; k < D; ++k){
        d += (X[i][k]-X[j][k])*(X[i][k]-X[j][k]);
      }
      long long s = sqrt(d);
      if(s*s == d){
        ++ans;
      }
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
import itertools

n,m,q = input().split()
n = int(n)
m = int(m)
q = int(q)
num_list = []
a = list(range(1, n+1))
for i in range(q):
    num_list.append(list(map(int,input().split())))
ff = list(itertools.combinations_with_replacement(range(1, m + 1), n))
max = 0
for i in range(len(ff)):
  s = 0
  for j in range(q):
    a,b,c,d = num_list[j]
    if ff[i][b-1] - ff[i][a-1] == c:
      s = s + d
  if max < s:
        max = s
print(max)
  

Measured memory_bytes: 21496
def gcd(x,y):
    if y==0:
        return x
    else:
        return gcd(y,x%y)
def lcm(x,y):
    return x*y//gcd(x,y)

n,m=map(int,input().split())
s,t=input(),input()
g,l=gcd(n,m),lcm(n,m)
for i in range(g):
    if s[(n//g)*i]!=t[(m//g)*i]:
        print(-1)
        break
else:
    print(l)

Measured memory_bytes: 3316
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <list>
#include <cmath>
#include <stack>
#include <string>
#include <cstring>
#include <numeric>
#include <iomanip>
using namespace std;
//
const int inf=1e9+7;//0x3f
//
int main(){
	int W,H;
	long long P[100000],Q[100000];
	vector<pair<long long,int>> V;
	cin>>W>>H;
	for(int i=0;i<W;i++){
		cin>>P[i];
		V.push_back(make_pair(P[i],i));
	}
	for(int i=0;i<H;i++){
		cin>>Q[i];
		V.push_back(make_pair(Q[i],i+W));
	}
	sort(V.begin(),V.end());
	int w=W+1,h=H+1;
	long long ans=0;
	for(int i=0;i<V.size();i++){
		if(V[i].second>=W){
			ans+=w*V[i].first;
			h--;
		}else{
			ans+=h*V[i].first;
			w--;
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 7536
import numpy as np

import sys
input = sys.stdin.buffer.readline

n, k = map(int, input().split())
a = np.array(input().split(), np.int64)
f = np.array(input().split(), np.int64)

a.sort()
f.sort()

f_ = f[::-1]

left = -1
right = (a*f).sum()
while left + 1 < right:
  mid = (left + right) // 2
  r = np.maximum(0, a - mid//f_).sum() <= k
  if r:
    right = mid
  else:
    left = mid
print(right) 

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

int main(void)
{
	int L;
	cin >> L;
	double D = (double)L;
	D = (D)/((double)3);

	long double V;
	V = D*D*D;
	printf("%0.12Lf\n", V);



	return 0;
}

Measured memory_bytes: 256
/* "It's okay if you hate me. I hate me too." */

#include <bits/stdc++.h>

using namespace std;

const int maxN = (int)2E5+5;

int a[maxN];
int b[maxN];
int n;

int main() {
	scanf("%d", &n);
	for (int i = 0; i < n; ++i) 
		scanf("%d", &a[i]);
	int p = n/2;
	int l = p, r = p-1;
	for (int i = 0; i < n; ++i)
		if (i%2 == 0)
			b[++r] = a[i];
		else
			b[--l] = a[i];
	if (n%2 == 0)
		for (int i = l; i <= r; ++i)
			printf("%d ", b[i]);
	else
		for (int i = r; i >= l; --i)
			printf("%d ", b[i]);
	return 0;
}


Measured memory_bytes: 3712
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <numeric>
#include <math.h>
#include <algorithm>
#include <functional>
#include <string>
#include <array>
#include <vector>
#include <list>
#include <stack>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <deque>
#include <queue>
#include <complex>
#define full(c) c.begin(), c.end()
#define vector2d(name,type,h,w,init) vector<vector<type>> name(h,vector<type>(w,init)) 
const int PRIME = 1000000007;
const int INT_INF = 2147483647;
const long long int LL_INF = 9223372036854775807;
const double PI = acos(-1);
const double EPS = 0.000000001;
typedef unsigned long long int ull;
typedef long long int ll;
using namespace std;

int main() {
	ll CY, CX, H, i, n;
	cin >> n;
	vector<ll> x(n);
	vector<ll> y(n);
	vector<ll> h(n);
	for (i = 0; i < n; i++) {
		cin >> x[i] >> y[i] >> h[i];
	}
	for (CX = 0; CX <= 100; CX++) {
		for (CY = 0; CY <= 100; CY++) {
			i = 0;
			while (h[i] == 0) i++;
			H = h[i] + abs(x[i] - CX) + abs(y[i] - CY);
			for (i = 0; i < n; i++) {
				if (h[i] == 0) {
					if (h[i] + abs(x[i] - CX) + abs(y[i] - CY) < H) break;
				}
				else {
					if (h[i] + abs(x[i] - CX) + abs(y[i] - CY) != H) break;
				}
			}
			if (i == n) {
				cout << CX << " " << CY << " " << H << endl;
				return 0;
			}
		}
	}
	return 0;
}




Measured memory_bytes: 256
/*
***************************************************************************
 name  : ITP1_01_C.cpp
 title : Rectangle
 make  : 2018/08/01 tanabe
***************************************************************************
*/

// Library
#include <iostream> // standard input output object

main(void){
  int h; // height
  int w; // width

  std::cin >> h >> w;                              // input "h w"
  std::cout << h*w << " " << 2*(h+w) << std::endl; // output "a p"

}



Measured memory_bytes: 3096
#include<iostream>
#include<cstring>
#include<queue>
#include<cstdio>
#include<algorithm>
#include<vector>
using namespace std;
const int N=200010;
 typedef pair<int,int> pii;
 int k;
 long long  f[N];
 vector<int>v;
 pair<int,int>q[12];
 long long tr[N];
 int n;
 int lowbit(int x)
 {
    return x&-x;
 } 
 const int mod=998244353;
 void add(int x,int d)
 {
    for(int i=x;i<=n;i+=lowbit(i))
        tr[i]=(tr[i]+d)%mod;
 } 

 int query(int x)
 {
    long long  res=0;
    for(int i=x;i;i-=lowbit(i))
        res=(res+tr[i])%mod;
    return res;
 }

int main()
{
    //get_prime(1000000);
    cin>>n>>k;
    f[1]=1;
    for(int i=1;i<=k;i++)
    {
        int l,r;
        cin>>l>>r;
        q[i]={l,r};

    }
    sort(q+1,q+1+k);
    //v.push_back(0);
    for(int i=1;i<=k;i++)
        for(int j=q[i].first;j<=q[i].second;j++)
        v.push_back(j);
    add(1,1);
    for(int i=2;i<=n;i++)
    {
        //int pos=lower_bound(v.begin(),v.end(),i)-v.begin();
     //   cout<<i<<' '<<pos<<' '<<v[pos]<<endl;
        //if(v[0]>i)
          //  continue;
        //if(i-v[pos-1]-1)    
            //if(pos==0)  pos++;
        for(int j=1;j<=k;j++)
        {
            int rr=i-q[j].first;
            int ll= i-q[j].second;
            if(rr<=0)   continue;
            ll=max(ll,1);
            f[i] =(f[i] + (query(rr)-query(ll-1))%mod+mod)%mod;
        }
        add(i,f[i]);
    }
    cout<<f[n]<<endl;
    return 0;
}  

Measured memory_bytes: 7296
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

using namespace std;

typedef long long ll;

const ll INF = 1e18;
const int BIG = 1e9;
const int maxN = 100 * 1000 + 9;
const string FILENAME = "sample";

int n;

void read(){
	cin >> n;
}

void solv(){
	cout << (n - 2) * 180 << '\n';
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	
#ifdef h4h4
	freopen((FILENAME + ".inp").c_str(), "r", stdin);
	freopen((FILENAME + ".out").c_str(), "w", stdout);
#endif

	read();
	solv();

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <math.h>


using namespace std;

int n,k,w[100000] = {0};

bool search(int p)
{
	int track[100000] = {0},j = 0;

	for(int i = 0; i < n; i++)
	{
		if (track[j] + w[i] > p)
		{
			if (j == k-1)
			{
				return false;
			}

			j++;
			track[j] += w[i];
		}else
		{
			track[j] += w[i];
		}
	}

	return true;
}

int main()
{
	int max,left,right,center = 0,sum = 0;

	cin >> n >> k;

	max = 0;

	for(int i = 0; i < n; i++)
	{
		cin >> w[i];
		sum += w[i];
		if (max < w[i])
		{
			max = w[i];
		}
	}

	left = max;
	right = sum;

	while(left < right)
	{
		center = (left + right) / 2;
		//cout << "center=" << center << endl;

		if (search(center))
		{
			right = center;
		}else
		{
			left = center+1;
		}
	}

	cout << left << endl;

	return 0;
}
	

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

typedef long long int ll;

int main(void) {
	string str;
	int len, comb, sig, bit, chr;
	ll ans, sum, num;

	cin >> str;

	len = str.length();
	comb = (1 << (len - 1));
	ans = 0;
	for (int i = 0; i < comb; ++i) {
		sig = i | (1 << (len - 1));
		sum = 0;
		num = 0;
		for (int j = 1; j <= len; ++j) {
			chr = (int)(str[j - 1] - '0');
			bit = (1 << (j - 1));
			num = num * 10 + chr;
			if ((sig & bit) != 0) {
				sum += num;
				num = 0;
			}
		}
		ans += sum;
	}

	cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 256
"""#自分で考えたやつ
N, M = map(int, input().split())
AB = []
for i in range(N):
    a, b =  (int(x) for x in input().split())
    AB.append([a, b])
AB.sort(key=lambda x: x[1])

dic = {}
for i in range(M):
"""

import heapq

N, M = map(int, input().split())

# 仕事の制約が厳しい順にリストに格納する
Blist = [[] for _ in range(M)]
for i in range(N):
    A, B = map(int, input().split())
    if A <= M: # AがMより大きいといつやっても間に合わない
        Blist[A-1].append(-B) # heapdを使うことを考慮して-倍しておく

ans = 0
q = [] # heapd.heapify(q)でリストのヒープ化ができるがここではlen(q)を使いたいためにしないでおく

# 可能な仕事をqに入れて扱う。その中でもBが最大(「-」倍しているのでここでは最小)のものを優先して取り出す。
for i in range(M):
    for b in Blist[i]: # ヒープ化されたリストqに2次元のBlistのi番目のリストの要素を全て入れる
        heapq.heappush(q, b)
    if len(q) > 0: # qに要素があるならば、qから最小の要素を取り出して(「-」倍してあるので)それを引き算する
        ans -= heapq.heappop(q)

print(ans)


Measured memory_bytes: 17604
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <set>
#include <cstdio>
#include <string.h>
using namespace std;

#define FOR(i, n) for(int i = 0; i < n; i++)
#define bit(i) static_cast<bitset<8> >(i)

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> VI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<long long, long long>PLL;
typedef queue<int> QI;
typedef priority_queue<int> maxpq;
typedef priority_queue<int, vector<int>, greater<int> > minpq;

struct edge{int to, cost;};

void begin(){cin.tie(0); ios::sync_with_stdio(false);};
int gcd(int a, int b){if(a%b==0){return(b);}else{return(gcd(b,a%b));}};
int lcm(int m, int n){if((0 == m)||(0 == n)){return 0;} return ((m / gcd(m, n)) * n);};
unsigned long long comb(long n, long m){unsigned long long c = 1; m = (n - m < m ? n - m : m);
    for(long ns = n - m + 1, ms = 1; ms <= m; ns ++, ms ++){c *= ns; c /= ms;} return c;};

// ワーシャルフロイド法
void warshallFloyd(int d[100][100], int n){
    for(int k = 0; k < n; ++k)
        for(int i = 0; i < n; ++i)
            for(int j = 0; j < n; ++j)
                if(d[i][k] != -1 && d[k][j] != -1){
                    if(d[i][j] == -1){
                        d[i][j] = d[i][k] + d[k][j];
                    }else{
                        d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
                    }
                }
};


// d:隣接行列  n:グラフのサイズ  s:始点  dist:始点からの距離が入る配列
void dijkstra(int d[1000][1000], int n, int s, int dist[1000]){
    FOR(i, n) dist[i] = -1;
    dist[s] = 0;
    priority_queue<PII, vector<PII>, greater<PII> > q;
    q.push(PII(0, s));
    while (!q.empty()) {
        PII p = q.top(); q.pop();
        int i = p.second;
        if(dist[i] < p.first) continue;
        for(int j = 0; j < n; j++){
            if(d[i][j] == -1) continue;
            if(dist[j] == -1){
                dist[j] = dist[i] + d[i][j];
                q.push(PII(dist[j], j));
            }else if(dist[j] > dist[i] + d[i][j]){
                dist[j] = dist[i] + d[i][j];
                q.push(PII(dist[j], j));
            }
        }
    }
};

// 線分の交差判定
bool isCross(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4){
    // 並行な場合
    int m = (x2-x1)*(y4-y3)-(y2-y1)*(x4-x3);
    if(m == 0) return false;
    // 媒介変数の値が0より大きく1以下なら交差する、これは問題の状況によって変わるかも。
    double r =(double)((y4-y3)*(x3-x1)-(x4-x3)*(y3-y1))/m;
    double s =(double)((y2-y1)*(x3-x1)-(x2-x1)*(y3-y1))/m;
    return (0 < r && r <= 1 && 0 < s && s <= 1);
};

/**
 * start
 * @author yoshikyoto
 */
void solve(int n){
    int sumA = 0, sumB = 0, a, b;
    FOR(i, n){
        cin >> a >> b;
        if(a > b){
            sumA += a + b;
        }else if(a < b){
            sumB += a + b;
        }else{
            sumA += a;
            sumB += b;
        }
    }
    cout << sumA << " " << sumB << endl;
}

int main(int argc, const char * argv[]){
    while(true){
        int n;
        cin >> n;
        if(n == 0) return 0;
        solve(n);
    }
}

Measured memory_bytes: 1164
//url:
//problem name:

#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); ++i)
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;}
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Pl = pair<long long,long long>;
using veci = vector<int>;
using vecl = vector<long>;
using vecveci = vector<vector<int>>;
using vecvecl = vector<vector<long long>>;

int pow(int a,int n) {
    int ans = 1;
    REP(i,n) ans *= a;
    return ans;
}

int main() {
    int N,M; cin >> N >> M;
    int start;
    if(N == 1) start = 0;
    else start = pow(10,N-1);
    vector<P> res(M);
    REP(i,M) cin >> res.at(i).first >> res.at(i).second;
    string ans = "-1";
    for(int i = start; i < pow(10,N); i++) {
        string S = to_string(i);
        //cout << S << endl;
        bool ok = true;
        REP(j,M) {
            int s = res.at(j).first-1;
            int c = res.at(j).second;
            //cout << S[s] << " " << c << endl;
            if(S[s]-'0' != c) {
                ok = false;
                break;
            }
        }
        if(ok) {ans = S; break;}
    } 
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) 				for(int i=0; i<(n); ++i)
#define repAB(i,a,b) 			for(int i=a; i<=(b); ++i)
#define repBA(i,b,a)	 		for(int i=b; i>=(a); --i)
#define all(c) 				(c).begin(),(c).end()
#define sortall(x)                 sort(all(x))
#define tr(c,i) 				for( typeof( (c).begin() ) i = (c).begin();  i != (c).end(); ++i)
#define pb 					push_back
#define sz(a) 					int((a).size())
#define mp                         make_pair
#define ll                         long long
#define F                          first
#define S                          second
#define PI                         3.1415926535897932384626
// Input macros
#define s(n)                       scanf("%d",&n)
#define sc(n)                      scanf("%c",&n)
#define sl(n)                      scanf("%lld",&n)
#define sf(n)                      scanf("%lf",&n)
#define ss(n)                      scanf("%s",n)

// Others
#define test(t) 				int t; cin>>t; while(t--)
#define endl 					"\n"

using namespace std;

typedef pair<int, int> 			pii;
typedef pair<ll, ll> 	          pll;
typedef vector<int> 			vi;
typedef vector<ll>                 vl;

const int mod = 1000000007;
const int INF = 1e9+5;

int main(){
     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);

     ll n,k;
     sl(n);
     sl(k);
     
     vl h(n);
     ll*dp = new ll[n];
     rep(i,n){
		sl(h[i]);
		dp[i] = INF;
	 }
	 
	 dp[0] = 0;
	 dp[1] = abs(h[1]-h[0]);
	 
	 for(int i=2 ; i<n ; i++){
		for(int j=i-1 ; j>=(i-k>0?i-k:0) ; j--){
			ll temp = dp[j] + abs(h[j]-h[i]);
			dp[i] = min(dp[i], temp);
		}
	 }
	 
	 printf("%lld\n",dp[n-1]);

     return 0;

}


Measured memory_bytes: 4848
/**
*	created: 15.08.2020 21:02:36
**/
#include <bits/stdc++.h>
// #include <boost/multiprecision/cpp_int.hpp>
// using bint = boost::multiprecision::cpp_int;
using namespace std;
using P = pair<int,int>;
#define int long long
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define rep2(i,s,n) for (int i = (s); i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define pcnt(bit) __builtin_popcountll(bit)
template<class T> bool chmax(T &a, const T &b) {if (a < b) {a = b; return 1;} return 0;}
template<class T> bool chmin(T &a, const T &b) {if (b < a) {a = b; return 1;} return 0;}
const long double pi = acos(-1.0);
const int MAX = 1000010;
const int INF = 1LL << 60;
const int MOD = 1000000007;
// const int MOD = 998244353;

signed main() {

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

    int n; cin >> n;
    vector<int> v(n);
    rep(i,n) cin >> v[i];
    int cnt = 0;
    rep(i,n) rep2(j,i+1,n) rep2(k,j+1,n) {
        if (i == j || j == k || k == i) continue;
        else if (v[i] == v[j] || v[j] == v[k] || v[k] == v[i]) continue;
        if (abs(v[i]-v[j]) < v[k] && v[k] < v[i]+v[j]) cnt++;
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 3656
from fractions import gcd  # python<=3.4

MOD=1000000007

def ADD(x, y):
  return (x + y) % MOD

def SUB(x, y):
  return (x - y + MOD) % MOD

def MUL(x, y):
  return x * y % MOD

def POW(x, e):
  v = 1
  while e:
    if e & 1:
      v = MUL(v, x)
    x = MUL(x, x)
    e >>= 1
  return v

def INV(x):
  return POW(x, MOD-2)

def DIV(x, y):
  return MUL(x, INV(y))


n = int(input().rstrip())
a = [int(x) for x in input().rstrip().split()]

el = 1
for ai in a:
  g = gcd(el,ai)
  el = el // g * ai

el %= MOD

sum = 0
for ai in a:
  sum += DIV(el, ai)

sum %= MOD
print(sum)


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

long long ans = 0;
void solve(string S, long long n)
{
  ans += (n + stoll(S));
  for (int i = 1; i <= S.size() - 1; i++)
  {
    solve(S.substr(i), n + stoll(S.substr(0, i)));
  }
}

int main()
{
  string S;
  cin >> S;
  int n = S.size();
  solve(S, 0);
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define llt long long int
#define pb push_back
int dp[100000];
int a[100000];
int k;
int fun(int n){
	if(dp[n]!=-1)return dp[n];
	else if(n==0)return 0;
	else{
		int m=INT_MAX;
		for(int i=n-1;n-i<=k&&i>=0;i--){
			m=min(m,fun(i)+abs(a[n]-a[i]));
		}
		dp[n]=m;
		return dp[n];
	}
}
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int n;
	cin>>n>>k;
	memset(dp,-1,n*sizeof(dp[0]));
	for(int i=0;i<n;i++)cin>>a[i];
	int x=fun(n-1);
	cout<<x;
	return 0;
}


Measured memory_bytes: 5760
n = int(input())
s = [2]
q = 1

for i in range(n+1):
	if i<3:
		continue
	t = []
	for j in range(len(s)):
		t.append((i)%s[j])
	if 0 in t:
		q = 3
	else:
		s.append(i)

x = 1

for i in range(len(s)):
	m = 0
	for j in range(10):
		m += n//(s[i]**(j+1))
	x *= m+1
print(x%(10**9+7))


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

int main(){
 int n;
 cin >> n;
 for(int i=1; i<=n; i++){
  int x = i;
  if(x%3 == 0) cout<<" "<<i;
  else{
   while(x){
    if(x%10 ==3){
     cout<<" "<<i;
     break;
    }
    x /= 10;
   }
  }
 }
 cout << endl;
}


Measured memory_bytes: 3136
#include<iostream>
#define int long long
const int p=1e9+7;
int f[55][55][55],c[55][55];
signed main(){
	int n;	
	std::cin>>n;
	f[1][1][1]=1;
	for(int i=0;i<=n;++i){
		c[i][0]=c[i][i]=1;
		for(int j=1;j<i;++j)c[i][j]=(c[i-1][j]+c[i-1][j-1])%p;
	}
	for(int i=1;i<n;++i){
		for(int j=1;j<=i;++j){
			for(int k=0;k<=j;++k){
				for(int l=0;l<=j;++l){
					for(int w=k-l>0?k-l:0;w+l-k+w+i<=n;++w){
						if(w+l-k+w>0){
							(f[w+l-k+w+i][w+l-k+w][w]+=f[i][j][k]*c[j][l]%p*c[w+l-k+w+i][i])%=p;
						}
					}
				}
			}
		}		
	}
	int ans=0;
	for(int i=1;i<=n;++i){
		for(int j=0;j<=i;++j)
			ans=(ans+f[n][i][j]*c[i][j])%p;
	}
	std::cout<<ans;
	return 0;
}



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

int main(void)
{
  int N;
  char s[101];
  int count = 0;

  scanf("%d", &N);
  scanf("%s", s);

  for (int i = 0; i < N; i++) {
    if (s[i] == 'B')
      count++;
  }
  if (count < N - count)
    puts("Yes");
  else
    puts("No");

  return 0;
}

Measured memory_bytes: 128
#include <cstdio>

const int N = 500;

char s[N][N + 1];

int main()
{
    int n, m;
    scanf("%d%d", &n, &m);
    for (int i = 0; i < n; ++ i) {
        scanf("%s", s[i]);
    }
    for (int i = 0; i < n; ++ i) {
        for (int j = 0; j < m; ++ j) {
            putchar(".#"[i == 0 || i != n - 1 && (j & 1) || s[i][j] == '#']);
        }
        puts("");
    }
    puts("");
    for (int i = 0; i < n; ++ i) {
        for (int j = 0; j < m; ++ j) {
            putchar(".#"[i == n - 1 || i != 0 && (~j & 1) || s[i][j] == '#']);
        }
        puts("");
    }
}


Measured memory_bytes: 896
#include <bits/stdc++.h> 
using namespace std; 
#define ll long long
bool compare(const pair<int,int> &a,  
               const pair<int,int> &b) 
{ 
       return (a.second > b.second); 
}
int findmax(int arr[], int n){
	int curr_max = -1;
	for(int i=0;i<n;i++){
		curr_max = max(curr_max, arr[i]);
		}
	return curr_max;
	}
int findmin(int arr[], int n){
	int curr_max = INT_MAX;
	for(int i=0;i<n;i++){
		curr_max = min(curr_max, arr[i]);
		}
	return curr_max;
	}
bool help(int arr[], int mid, int n, int c){
	int last_pos = arr[0];
	int cows = 1;
	for(int i=0;i<n;i++){
		if(abs(arr[i]-last_pos) >= mid){
			last_pos = arr[i];
			if(++cows == c)
				return true;
			last_pos = arr[i];
		}
	}
	return false;
}
ll calc(ll a, ll b, ll c){
	return abs(a-b)+abs(b-c)+abs(c-a);
	}
ll nc2(ll n){
	return n*(n-1)/2;
	}
int main() 
{ 
	ll t;
	t=1;
	while(t--){
		ll n; cin>>n;
		ll a[n];
		map<ll, ll> m;
		for(int i=0;i<n;i++){
			cin>>a[i];
			m[a[i]]++;
			}
		map<ll, ll> ans;
		map<ll, ll>::iterator it;
		map<ll, ll> yo;
		ll sum = 0;
		for(it=m.begin();it!=m.end();it++){
			//ans[it->first]=nc2(it->second-1);
			yo[it->first]=nc2(it->second);
			sum+=yo[it->first];
			}
		for(it=m.begin();it!=m.end();it++){
			//cout<<sum-ans[a[i]]-1<<endl;
			//cout<<"sum "<<sum<<"ans "<<ans[a[i]]<<"yo "<<yo[a[i]]<<endl;
			ans[it->first]=sum - nc2(it->second) + nc2(it->second - 1);
			}
		for(int i=0;i<n;i++){
			cout<<ans[a[i]]<<endl;
			}
	}
} 


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

int main() {
    int h, w, n, ans;
    cin >> h >> w >> n;
    ans = n / max(h, w);
    if(n % max(h, w) > 0) ans++;
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cstring>
#include <cstdio>
using namespace std;
const int Maxn = 2005;

int lena, lenb, cnta, cntb, cnt;
int ans = 0x3f3f3f3f;
char a[Maxn], b[Maxn];
int l[Maxn], r[Maxn], mx[Maxn];

inline void solve(int x) {
  memset(mx, cnt = 0, sizeof mx);
  for (int i = 0; i < lena; ++ i) if (a[i] ^ b[(x + i) % lena])
    mx[l[i]] = max(mx[l[i]], r[i]), ++ cnt;
  for (int i = lena - 1, j = 0; ~i; j = max(j, mx[i --]))
    ans = min(ans, i + i + j + abs(x - j) + cnt);
}

int main() {
  scanf("%s\n%s", a, b), lena = strlen(a), lenb = strlen(b);
  for (char *c = a; *c; ++ c) cnta += (*c - '0');
  for (char *c = b; *c; ++ c) cntb += (*c - '0');
  if (!cntb) return printf("%d\n", -(cnta > 0)) & 0;
  for (int i = 0; i < lena; ++ i) {
    for (r[i] = 0; b[(i + r[i]) % lena] == 48; ++ r[i]);
    for (l[i] = 0; b[(i - l[i] + lena) % lena] == 48; ++ l[i]);
  } for (int i = 0; i < lena; ++ i) solve(i);
  reverse(a, a + lena), reverse(b, b + lenb);
  for (int i = 0; i < lena; ++ i) {
    for (r[i] = 0; b[(i + r[i]) % lena] == 48; ++ r[i]);
    for (l[i] = 0; b[(i - l[i] + lena) % lena] == 48; ++ l[i]);
  } for (int i = 0; i < lena; ++ i) solve(i);
  return printf("%d\n", ans) & 0;
}

Measured memory_bytes: 128
if __name__ == '__main__':
    n, m = tuple([int(i) for i in input().split()])
    a = [int(i) for i in input().split()]
    total = float(sum(a))

    selected = [float(i) >= (total / (4.0 * m)) for i in a]
    result = len([r for r in selected if r])

    print("Yes" if result >= m else "No")


Measured memory_bytes: 3060
x,n=map(int,input().split())
if n>0:
    
    a=list(map(int,input().split()))
        
    z=x+1
    y=x-1
    if x not in a:
        print(x)
    else:
        while True:
            if y not in a:
                print(y)
                break
            elif z not in a:
                print(z)
                break
        
            z+=1
            y-=1
        
else:
    print(x)

Measured memory_bytes: 9128
#include <bits/stdc++.h>
#define ALL(a)  (a).begin(),(a).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
template <typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template <typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
const int INT_INF = 1 << 30;
#define MOD 1000000007LL

//ベクトルがすっかり抜けていた

int main(){
  ll S;
  cin >> S;

  ll x1 = 0LL, y1 = 0LL;
  ll x2 = 1000000000LL, y2 = 1LL;
  ll x3 = 1000000000LL - S % 1000000000LL;
  ll y3 = S / 1000000000LL + 1;
  if(S % 1000000000LL == 0LL){
    x3 = 0LL;
    y3 = S / 1000000000LL;
  }
  cout << x1 << ' ' << y1 << ' ' << x2 << ' ' << y2 << ' ' << x3 << ' ' << y3 << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <algorithm>
#define rep(i, a, b) for (int i = (a), _ = (b); i <= _; ++ i)
#define per(i, a, b) for (int i = (a), _ = (b); i >= _; -- i)
#define For(i, a, b) for (int i = (a), _ = (b); i < _; ++ i)
#define ri rd<int>
const int maxN = 2e3 + 7;
const int mod = 924844033;
const int N = 2001;
using namespace std;

inline int pls(int x, int y) { return (x += y) >= mod ? x - mod : x; }
inline int mns(int x, int y) { return (x -= y) < 0 ? x + mod : x; }
inline int mul(int x, int y) { return 1LL * x * y % mod; }
inline void Add(int &x, int y) { x = pls(x, y); }
inline void Mul(int &x, int y) { x = mul(x, y); }
inline void Minus(int &x, int y) { x = mns(x, y); }

template<class T> inline T rd() {
	bool f = 1; char c = getchar(); for (; !isdigit(c); c = getchar()) if (c == '-') f = 0;
	T x = 0; for (; isdigit(c); c = getchar()) x = x * 10 + c - 48; return f ? x : -x;
}

int n, m;
int fac[maxN], ifac[maxN], iv[maxN];
int f[2][2][maxN][maxN], F[maxN][maxN];
int g[maxN], G[maxN];

inline int sgn(int x) { return (x & 1) ? mod - 1 : 1; }

void init() {
	iv[1] = 1; rep (i, 2, N) iv[i] = mul(iv[mod % i], mod - mod / i);
	fac[0] = 1; rep (i, 1, N) fac[i] = mul(fac[i-1], i);
	ifac[0] = 1; rep (i, 1, N) ifac[i] = mul(ifac[i-1], iv[i]);
}

void pre() {
	f[0][0][1][0] = 1;
	rep (i, 2, N) rep (u, 0, 1) rep (v, 0, 1) rep (x, 0, u ^ 1) rep (y, 0, v ^ 1) For (j, 0, i)
		Add(f[v][u][i][j+u+v], f[x][y][i-1][j]);

	rep (i, 1, N) rep (j, 0, i) rep (u, 0, 1) rep (v, 0, 1)
		Add(F[i][j], f[u][v][i][j]);
	rep (i, 1, N) rep (j, 0, i)
		Mul(F[i][j], sgn(j));
}

int main() {

	init();
	pre();

	n = ri(), m = ri();
	int cur = 0, len = 0;
	G[0] = 1;
	rep (i, 1, m) {
		len = (n - i) / m + 1;
		cur += len;
		rep (j, 0, cur) g[j] = 0;
		rep (j, 0, len) per (k, cur, j)
			Add(g[k], mul(G[k-j], F[len][j]));
		rep (j, 0, cur) G[j] = g[j];
	}

	int res = 0;
	rep (i, 0, n) Add(res, mul(fac[n-i], G[i]));
	printf("%d\n", res);

	return 0;
}


Measured memory_bytes: 77952
#include <iostream>
#include <algorithm>
 
using namespace std;
 
int main() {
    int L, R;
    cin >> L >> R;
    int cnt = 2019;
    for(long long i = L; i < R; i++) {
        for(long long j = i+1; j <= R; j++) {
            cnt = min((int)(i*j%2019), cnt);
            if(!cnt) {
              cout << 0 << endl;
              return 0;
            };
        }
    }
    cout << cnt << endl;
 
    return 0;
}


Measured memory_bytes: 256
//#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast,no-stack-protector") 
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>
/*#include <x86intrin.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template <typename T> using ordered_set = tree<T, null_type, std::less<T>, rb_tree_tag, tree_order_statistics_node_update>;*/
#define ll long long
#define ull unsigned long long
//#define int ll
#define ld long double
#define rep(i, l, r) for (int i = l; i <= r; i++)
#define repb(i, r, l) for (int i = r; i >= l; i--)
#define sz(a) (int)a.size()
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define pb push_back
#define mp(a, b) make_pair(a, b)
#define ret(a) {cout << a; exit(0);}

using namespace std;

mt19937 mrand(random_device{}()); 
const ll mod=1000000007;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b,ll mod) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
                                                                    
typedef pair < int , int > pii ;
typedef pair < long long  , long long > pll ;

const int N = 4e3 + 5;
int n , X;
int a[N];
ll f(int x){
	deque < pii > dq;
	rep(i , n - x , n){
		while(!dq.empty() != 0 and dq.back().fi >= a[i])
			dq.pop_back();
		dq.push_back({a[i] , i});
	}

	ll res = 0;

	rep(i, n + 1 , n + n){
		while(!dq.empty() != 0 and dq.back().fi >= a[i])
			dq.pop_back();
		dq.push_back({a[i] , i});
		while(sz(dq) != 0 and dq.front().se < i - x)
			dq.pop_front();
		res += dq.front().fi;
	}
	return res + 1ll * x * X;
}
main(){
//	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	scanf("%d%d" , &n , &X);
	rep(i , 1 , n){
		scanf("%d" , a + i);
		a[n + i] = a[i];
	}

	ll ans = f(0) , cur1 , cur2 ;
	int l = 0 , r = n , m;
	
	while(l <= r){
		m = (l + r) >> 1;
		cur1 = f(m) , cur2 = f(m + 1);		
		if(cur1 > cur2){
			ans = min(ans , cur2);
			l = m + 1;
		}else r = m - 1;
	}

	printf("%lld" , ans);
}

Measured memory_bytes: 256
#include "iostream"
#include "vector"
#include "iomanip"
#include "algorithm"
#include "vector"
#include "cmath"

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

	std::vector<int>k(m);
	std::vector<std::vector<int>>s(m, std::vector<int>());
	for (int i = 0; i < m; ++i) {
		std::cin >> k.at(i);
		for (int j = 0; j < k.at(i); ++j) {
			int num;
			std::cin >> num;
			num--;
			s.at(i).push_back(num);
		}
	}

	std::vector<int>p(m);
	for (int i = 0; i < m; ++i)
		std::cin >> p.at(i);

	int ans = 0;
	for (int push = 0; push < 1 << n; ++push) {
		bool itti = true;
		for (int i = 0; i < m; ++i) {
			int push_num = 0;
			for (int j = 0; j < k.at(i); ++j)
				if (push & 1U << s.at(i).at(j))
					push_num++;
			if ((push_num & 1U) != p.at(i)) {
				itti = false;
				break;
			}
		}
		if (itti)
			ans++;
	}
	std::cout << ans;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1000000010
#define EPS 1e-9
#define F first
#define S second

#define debug(x) cout<<x<<endl;
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define lp(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
#define int long long
#define endl "\n"

typedef pair<int,int> PII;
typedef pair<int,string> PIS;
typedef pair<string,int> PSI;


signed main(){
  cin.tie(0);	
  ios::sync_with_stdio(false);
  int k;
  string s;
  cin>>k>>s;
  rep(i,s.size()){
    if(k>i) cout<<s[i];
    else{
      cout<<"...";
      break;
    }
  }
  cout<<endl;
  


  return 0;
}


Measured memory_bytes: 3644
#include<bits/stdc++.h>
#define int long long
using namespace std;
class event{
public:
  int wt,val;  
};
int32_t main(){
    int n,w;
    cin>>n>>w;
    event arr[n+1];
    for(int i=1;i<=n;i++){
        cin>>arr[i].wt;
        cin>>arr[i].val;
    }
    int dp[n+1][w+1];
    for(int j=0;j<=w;j++){
        dp[0][j]=0;
    }
    for(int i=0;i<=n;i++){
        dp[i][0]=0;
    }
    for(int i=1;i<=n;i++){
        for(int j=1;j<=w;j++){
            dp[i][j]=dp[i-1][j];
            if(arr[i].wt<=j){
                dp[i][j]=max(dp[i][j],arr[i].val+dp[i-1][j-arr[i].wt]);
            }
        }
    }
    cout<<dp[n][w]<<endl;
	return 0;
}

Measured memory_bytes: 79104
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <set>
#include <map>
#include <algorithm>

#define int long long
#define MOD7 1000000007
#define MOD9 1000000009

#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(a) (a).begin(), (a).end()

using namespace std;

int nextInt() {int a; cin >> a; return a;}
char nextChar() {char a; cin >> a; return a;}
double nextDouble() {double a; cin >> a; return a;}
string nextString() {string a; cin >> a; return a;}

void inputVector(vector<int> &v, int &n) {rep(i,n){v.push_back(nextInt());}}
void inputVector(vector<double> &v, int &n) {rep(i,n){v.push_back(nextDouble());}}
void inputVector(vector<string> &v, int &n) {rep(i,n){v.push_back(nextString());}}

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

signed main() {
	while (true) {
		int W, H;
		cin >> W >> H;

		if (W == 0) break;

		int sx, sy;

		vector<string> board;
		rep(y, H) {
			board.push_back(nextString());
			rep(x, board[y].size()) {
				if (board[y][x] == '@') {
					sx = x;
					sy = y;
				}
			}
		}

		auto visit = vector< vector<bool> >(H, vector<bool>(W, false));
		visit[sy][sx] = true;

		int cnt = 0;
		queue<int> q;
		q.push(sy * 100 + sx);
		while (!q.empty()) {
			int n = q.front();
			q.pop();

			int x = n % 100;
			int y = n / 100;

			cnt++;

			rep(dir, 4) {
				int nx = x + dx[dir];
				int ny = y + dy[dir];
				if (nx < 0 || nx >= W || ny < 0 || ny >= H) continue;
				if (visit[ny][nx]) continue;
				if (board[ny][nx] != '.') continue;

				q.push(ny * 100 + nx);
				visit[ny][nx] = true;
			}
		}

		cout << cnt << endl;
	}

    return 0;
}

Measured memory_bytes: 3108
#include<cstdio>
#include<algorithm>
#include<queue>
using namespace std;
const int MAX = 100000 + 10;
int rec[MAX];
int cnt[MAX];
priority_queue<int> q;
int main(){
  int n, ans = 0;
  scanf("%d", &n);
  for(int i = 0 ; i < n ; i++){
    scanf("%d", &rec[i]);
    cnt[rec[i]]++;
  }
  ans = n;
  for(int i = 1 ; i <= 100000 ; i++) {
    if(cnt[i] > 1) {
      q.push(cnt[i]);
    }
  }
  while(!q.empty()) {
    if(q.size() == 1) {
      int tmp = q.top();
      q.pop();
      if(tmp % 2 == 1) {
        //3
        ans -= tmp-1;
      } else {
        //2
        ans -= tmp;
      }
      break;
    }
    int t1 = q.top();
    q.pop();
    int t2 = q.top();
    q.pop();
    int pick = min(t1, t2);
    t1 -= pick-1;
    t2 -= pick-1;
    ans -= (pick-1) * 2;
    if(max(t1, t2) > 1) {
      q.push(max(t1, t2));
    }
  }
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1000000007;



int main(){
    ll A, B, C, D;
    cin >> A >> B >> C >> D;
    while(1){
        C -= B;
        if(C <= 0) {
            cout << "Yes" << endl;
            return 0;
        } 
        A -= D;
        if(A <= 0){
            cout << "No" << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 3596
let _ =
  try
    while true do
      let a, b = Scanf.scanf "%d %d\n" (fun x y -> (x,y)) in
      let rec digit_number r n =
        let m = (n / 10) in
        if m = 0 then r else digit_number (r + 1) m in
      Printf.printf "%d\n" (digit_number 1 (a+b))
    done
  with
    End_of_file -> ()

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

vector<P> G[MAX_N];
vector<int> c;
void dfs(int v, int color = 0) {
  c[v] = color;
  for (auto p : G[v]) {
    if (c[p.first] != -1) continue;
    if (p.second%2) dfs(p.first, color^1);
    else dfs(p.first, color);
  }
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  int n;
  cin >> n;
  c.assign(n, -1);
  rep(_, n-1) {
    int u, v, w;
    cin >> u >> v >> w;
    --u, --v;
    G[u].emplace_back(v, w);
    G[v].emplace_back(u, w);
  }
  dfs(0);
  rep(i, n) cout << c[i] << endl;
}

Measured memory_bytes: 8448
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(x),end(x)
#define show(obj) {for(auto x:obj)cout<<x<<' ';cout<<endl;}
#define line "----------"
typedef long long ll;
typedef pair<int,int> P;
const int inf = 1001001000;
const ll INF = 1LL<<60;
const ll MOD = 1e9 + 7;

string s;

void solve( int pos){
	if(pos != 0){
		if(s[pos-1] == '?'){
			if(s[pos]== 'D'){
				s[pos-1] = 'P';
			}else{
				s[pos-1] = 'D';
			}
			solve(pos-1);
		}
	}
	if(pos != s.size()-1){
		if(s[pos+1] == '?'){
			if(s[pos]== 'D'){
				s[pos+1] = 'P';
			}else{
				s[pos+1] = 'D';
			}
			solve(pos+1);
		}
	}
}

int main(){
	cin>>s;
	rep(i, s.size()){
		if(s[i] == '?')s[i] = 'D';
	}
	// rep(i,s.size()){
	// 	if(s[i] != '?'){
	// 		solve(i);
	// 	}
	// }	
	cout<<s<<endl;
	return 0;
}

Measured memory_bytes: 3740
#include <iostream>
#include <vector>
#include <unordered_set>

using namespace std;

// https://atcoder.jp/contests/sumitrust2019/tasks/sumitb2019_d

int main() {
  int n;
  string s;
  cin >> n >> s;
  vector<string> candidates;
  for (int i = 0; i < 10; ++i) {
    string candidate(to_string(i));
    for (int j = 0; j < 10; ++j) {
      if (candidate.size() == 1) {
        candidate += to_string(j);
      } else {
        candidate = candidate[0] + to_string(j);
      }
      for (int k = 0; k < 10; ++k) {
        candidates.emplace_back(candidate + to_string(k));
      }
    }
  }

  int res = 0;
  for (const auto& candidate : candidates) {
    int index = 0;
    for (int i = 0; i < s.size(); ++i) {
      if (candidate[index] == s[i]) {
        ++index;
        if (index == 3) {
          ++res;
          break;
        }
      }
    }
  }
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 3752
import java.util.*;
class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int cnt = 0;
        int pre = 0;
        while(N>0) {
            if(N%10==pre) cnt++;
            else cnt=1;
            if(cnt==3) {
                System.out.println("Yes");
                return;
            }
            pre = N%10;
            N/=10;
        }

        System.out.println("No");
    }
}

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

using namespace std;


char tolower(char ch){
  if('A' <= ch && ch <= 'Z'){
    return ch-'A'+'a';
  }else{
    return ch;
  }
}

  
int main(){
  int count=0;
  string W;
  cin >> W;
  string str;
  while(1){

    cin>>str;
    if(str=="END_OF_TEXT")break;
    for(int i=0;i<(int)str.size();i++){
      str[i] = tolower(str[i]);
    }
    if(str==W){
      count++;
    }
  }
  cout << count << endl;
  return 0;
  }


Measured memory_bytes: 3200
#include <cmath>
#include <cstdio>
#include <limits>
#include <tuple>
#include <stack>
#include <queue>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <numeric>
#include <string>
#include <array>
#include <iomanip>

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rrep(i, n) for (int i = n-1; i >= 0; --i)
#define REP(i, s, n) for (int i = s; i< (int)(n); ++i)
#define all(x) x.begin(), x.end()

using namespace std;
using ll = long long;
using ll1d = vector<ll>;
using ll2d = vector<ll1d>;
using ll3d = vector<ll2d>;

ll inf = ll(1e18);

void solve(istream &ccin = cin, ostream &ccout = cout) {
  ll n, ma, mb;
  ccin >> n >> ma >> mb;
  vector<ll> a(n), b(n), c(n);
  rep(i, n) {
    ccin >> a.at(i) >> b.at(i) >> c.at(i);
  }

  ll3d dp(n + 1, ll2d(402, ll1d(402, inf)));
  dp.at(0).at(0).at(0) = 0;
  REP(i, 1, n+1){
    rep(ca, 402){
      rep(cb, 402){

        dp[i][ca][cb] = min(dp[i][ca][cb], dp[i-1][ca][cb]);
        if (ca >= a[i-1] and cb >= b[i-1]){
          if (dp[i-1][ca-a[i-1]][cb-b[i-1]] != inf)
          dp[i][ca][cb] = min(dp[i][ca][cb], c[i-1]+dp[i-1][ca-a[i-1]][cb-b[i-1]]);
        }
      }
    }

  }



  ll cost = inf;
  ll range = min(400 / ma, 400 / mb);
  REP(j, 1, n + 1) {
    REP(i, 1, range) {
      cost = min(cost, dp.at(j).at(i * ma).at(i * mb));
    }
  }

  if (cost == inf) {
    ccout << -1 << endl;
  } else {
    ccout << cost << endl;
  }
}

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


Measured memory_bytes: 54016
#include <iostream>

int main(int argc, char *argv[])
{
	int a = 0;
	int b = 0;

	std::cin >> a >> b;

	int c = a * b;
	int d = a * 2 + b * 2;
	
	std::cout << c << " " << d << std::endl;
	return 0;
}

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

const ll mod=1000000007;

int main() {
  int a;
  cin >> a ;
  cout<< a + a * a + a * a * a<<endl;
}

Measured memory_bytes: 3592
use proconio::input;

fn gcd(x: isize, y: isize) -> isize {
    if y == 0 {
        x.abs()
    } else {
        gcd(y, x % y)
    }
}

fn main() {
    input! {
        k: isize,
    }

    let mut ans = 0;

    for a in 1..=k {
        for b in 1..=k {
            for c in 1..=k {
                ans += gcd(gcd(a, b), c);
            }
        }
    };

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


Measured memory_bytes: 2172
# ABC121C - Energy Drink Collector
import sys
input = sys.stdin.readline

n, m = list(map(int, input().rstrip().split()))
lst = sorted([list(map(int, input().rstrip().split())) for _ in range(n)])
ans = 0
for i in lst:
    while i[1] > 0 and m > 0:
        ans += i[0]
        i[1] -= 1
        m -= 1
print(ans)

Measured memory_bytes: 28648