akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define len(v) ((int)((v).size()))
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define chmax(x, v) x = max((x), (v))
#define chmin(x, v) x = min((x), (v))
using namespace std;
using ll = long long;

const int upTo = 201*1000;
const int lg = 18;
int nbNode;
int origRed, origBlue;
vector<int> adjRed[upTo];
vector<int> adjBlue[upTo];

int depth[upTo];
int anc[lg][upTo];

void dfs(int node, int parent) {
	anc[0][node] = parent;
	for (int i = 1; i < lg; ++i) {
		int tmp = anc[i-1][node];
		anc[i][node] = (tmp == -1 ? -1 : anc[i-1][tmp]);
	}
	for (int nei : adjBlue[node]) if (nei != parent) {
		depth[nei] = depth[node] + 1;
		dfs(nei, node);
	}
}

int dist(int u, int v) {
	int res = depth[u]+depth[v];
	if (depth[u] < depth[v]) swap(u,v);
	for (int i = lg-1; i >= 0; --i) {
		if (depth[u]-depth[v] >= (1<<i)) {
			u = anc[i][u];
		}	
	}
	if (u == v) {
		return res - 2*depth[v];
	}
	for (int i = lg-1; i >= 0; --i) {
		int nu = anc[i][u], nv = anc[i][v];
		if (min(nu,nv) != -1 && nu != nv) {
			u = nu; v = nv;
		}
	}
	int lca = anc[0][u];
	return res - 2*depth[lca];
}

int res = 0;
void esc(int node, int parent, int tps) {
	if (depth[node] <= tps) return;
	chmax(res, depth[node]);
	for (int nei : adjRed[node]) if (nei != parent) {
		int d = dist(node, nei);
		if (d >= 3) res = 3*upTo;
		esc(nei, node, tps+1);
	}
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> nbNode;
	cin >> origRed >> origBlue;
	--origRed; --origBlue;
	for (int i = 0; i < 2; ++i) {
		auto adj = (i ? adjBlue : adjRed);
		for (int iEdge = 0; iEdge < nbNode-1; ++iEdge) {
			int u, v;
			cin >> u >> v;
			--u; --v;
			adj[u].push_back(v);
			adj[v].push_back(u);
		}
	}	
	dfs(origBlue, -1); 
	esc(origRed, -1, 0);
	res *= 2;
	if (res == 6*upTo) res = -1;
	cout << res << "\n";
}


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

using namespace std;

int main(){
    int n,m; cin>>n>>m;
    int sum = m,ans = m;
    bool flg = 0;
    while(n--){
        int a,b; cin>>a>>b;
        sum = sum + a - b;
        if(sum < 0){
            flg = 1;
        }
        ans = max(ans,sum);
    }
    if(flg)cout<<0<<endl;
    else cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1160
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
    using namespace std;

    int main(){
      int n;
      cin >> n;
      int a[n];
      rep(i,n){
       cin >> a[i]; 
      }
      sort(a,a+n);
      int ans=inf;
      for(int i=a[0];i<=a[n-1];i++){
       int score=0;
        rep(j,n){
         score+=(i-a[j])*(i-a[j]); 
        }
        ans=min(ans,score);
      }
              cout << ans << endl;
      return 0;}

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

int main(void){
  llint h,n;
  llint ans=0;
  cin >> h >> n;
  for(int i=0;i<n;i++){
    llint x;
    cin >> x;
    ans+=x;
  }
  if(ans>=h)cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


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

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

Measured memory_bytes: 1160
#include <iostream>
#include <vector>
#include <cmath>
#include <queue>

using namespace std;

int gcd(int a,int b){
  if(a<=0||b<=0) return -1;
  if(a<b) gcd(b,a);
   
  int r=a%b;
  while(r){
    a=b;
    b=r;
    r=a%b;
  }
  return b;
}

int main(){
  int N,X;
  cin >> N >>X;
  int D;
  vector<int> diff;
  for(int i=0;i<N;i++){
    int temp;
    cin>>temp;
    diff.push_back(abs(temp-X));
  }
  D=diff[0];
  for(auto it=diff.begin();it!=diff.end();it++){
    D=gcd(D,*it);
  }
  
  cout <<D<<endl;
  return 0;
}


Measured memory_bytes: 892
#include<bits/stdc++.h>
using namespace std;
#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--)
vector<int>L;
int main(){
	int N;
        cin>>N;
	REP(i,N){
            int a;
            cin>>a;
            int b;
            cin>>b;
            L.push_back(a);
            L.push_back(b);
        }
        sort(L.begin(),L.end());
        int ans=0;
        for(int i=0;i<N;i++){
             ans+=L[2*i];
        }
        cout<<ans<<endl;
	return(0);
}

Measured memory_bytes: 256
n = gets.chomp.to_i
c = []
s = []
f = []

1.upto(n-1) do |i|
  c[i], s[i], f[i] = gets.chomp.split.map(&:to_i)
end

ans = Array.new(n+1, 0)

def to_next(now, c, s, f)
  if now <= s
    c + s - now
  else
    over = now - s
    a = over % f
    if a.zero?
      c
    else
      f - a + c
    end
  end
end

1.upto(n-1) do |i|
  i.upto(n-1) do |t|
    ans[i] += to_next(ans[i], c[t], s[t], f[t])
  end
end

1.upto(n) do |i|
  p ans[i]
end


Measured memory_bytes: 1916
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>

int main()
{
	int n, s = 0;
	std::cin >> n;
	for (int i = n; i > 0; i /= 10)
	{
		s += i % 10;
	}
	if (n % s == 0)
		std::cout << "Yes" << std::endl;
	else
		std::cout << "No" << std::endl;
	return 0;
}

Measured memory_bytes: 256
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(long long i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) {rep(_,v.size())cout<<" "<<v[_];cout<<endl;}
#define show2d(v) {rep(__,v.size())show1d(v[__]);}
using namespace std;
//kaewasuretyuui
typedef long long ll;
#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<int,int,int> tp;
typedef vector<tp> vt;
typedef vector<vt>vvt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={-1,0,1,0};
int dy[]={0,1,0,-1};
#define yes cout<<"Yes\n"
#define no cout<<"No\n"

// const int MOD=1000000007;
const int MOD=998244353;
const int M=300000;
vi fact,rev;
bool do_init=false;
ll powmod(ll a,ll b,ll m=MOD){
	ll out=1;
	ll p=a%m;
	while(b){
		if(b&1)out=out*p%m;
		p=p*p%m;
		b>>=1;
	}
	return out;
}
void init(){
	do_init=true;
	fact=rev=vector<ll>(M);
	fact[0]=fact[1]=1;
	loop(i,2,M)fact[i]=fact[i-1]*i%MOD;
	rev[M-1]=powmod(fact[M-1],MOD-2,MOD);
	for(int i=M-2;i>=0;i--)rev[i]=rev[i+1]*(i+1)%MOD;
}
//nCr
ll nCr(ll n,ll r,ll m=MOD){
	if(!do_init)init();
	if(n<0||r<0||n<r)return 1; // 0 or 1
	ll out=fact[n]*rev[r]%m*rev[n-r]%m;;
	return out;
}
int gcd(int a,int b){
	if(b==0)return a;
	return gcd(b,a%b);
}
int lcm(int a,int b){
	return a/gcd(a,b)*b;
}
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);

	int n,m,k;
	cin>>n>>m>>k;
	int out=0;
	rep(i,k+1){
		int s=m*powmod(m-1,n-1-i)%MOD*nCr(n-1,i)%MOD;
		(out+=s)%=MOD;
	}

	cout<<out<<endl;
}


Measured memory_bytes: 7956
// https://atcoder.jp/contests/arc096/tasks/arc096_a
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define DIV(a, b) ((a - 1) / b + 1)

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int A, B, C, X, Y;
    cin >> A >> B >> C >> X >> Y;
    int ans = INT32_MAX;
    ans = min(ans, A * X + B * Y);
    // ABピザを買う枚数
    int t = min(X, Y) * 2;
    ans = min(ans, C * t + A * (X - t / 2) + B * (Y - t / 2));
    t = max(X, Y) * 2;
    ans = min(ans, C * t + A * max(0LL, X - t / 2) + B * max(0LL, Y - t / 2));
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
object Main {

  def main(args: Array[String]): Unit = {
    val sc = new java.util.Scanner(System.in)

    val s = sc.nextLong()

    def f(n: Long): Long =
      if (n % 2 == 0) n / 2
      else 3 * n + 1

    val MMAX = 1000000

    def solve(): Int = {
      val A = scala.collection.mutable.Set[Long](s)
      var i = 1
      var a = s
      while (i < MMAX) {
        a = f(a)
        if (A.contains(a))
          return i + 1
        else
          A.add(a)
        i += 1
      }
      -1
    }

    println(solve())
  }

}


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

using namespace std;
int N,K,h[100010],x=0;
int main(){
  cin >>N>>K;
  for(int i=0;i<N;i++){
    cin>>h[i];
  }

  for(int i=0;i<N;i++){
    if(K<=h[i]){
      x=x+1;
    }
  }
  cout<<x;


 return 0;
}


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

int table[]={1,5,10,50,100,500};

int main(){
    int sum=0;
    for(int i=0;i<6;i++){
        int a;
        cin>>a;
        sum+=a*table[i];
    }

    cout<<(sum>=1000)<<endl;
    return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main() {
	int n;cin>>n;
	vector<int>v;
	for(int i=0;i<n;i++){
		int vi;cin>>vi;
		v.push_back(vi);
	}
	cin>>n;
	for(int i=0;i<n;i++){
		int p;cin>>p;
		auto t = lower_bound(v.begin(),v.end(),p);
		cout<<t-v.begin()<<endl;
	}
	return 0;
}


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

int main()
{
	const int DIGIT = 4;			// 入力の桁数
	const int CONTINUE_LENGTH = 3;	// Good Integerと判定されるための桁数
	int N[DIGIT] = {-1};			// 入力Nを1桁ずつ格納する配列
	
	// 入力Nを受け取って配列に入れる
	int temp = 0;
	cin >> temp;	
	for(int i = 0; i < DIGIT; ++i){
		N[i] = temp % 10;
		temp /= 10;
	}
	
	// 連続性の判定
	for(int i = 0; i <= DIGIT - CONTINUE_LENGTH; ++i){

		bool bGood = true;
		for(int j = 1; j < CONTINUE_LENGTH; ++j){
			if(N[i] != N[i + j]){
				bGood = false;
				break;
            }
		}
		
		if(bGood){
			cout << "Yes" << endl;
			return 0;
		}
	}
	
	cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
import fractions, math
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr.append([i, cnt])
    if temp != 1:
        arr.append([temp, 1])
    if arr == []:
        arr.append([n, 2])
    return arr
A, B = map(int, input().split())
N = fractions.gcd(A, B)
prime_list = factorization(N)
if N == 1:
    print(1)
else:
    print(len(prime_list)+1)


Measured memory_bytes: 5092
#include <bits/stdc++.h>
#include <vector>
#include <queue>
#include <numeric>
using namespace std;

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

    long long sum = 0;
    for(int i=0; i<N; i++){
        sum += A[i];
    }
    typedef pair<long long, long long> lengths;
    priority_queue<lengths, vector<lengths>, greater<lengths>> que;
    long long val = 0;
    for(int i=0; i<N; i++){
        val += A[i];
        lengths tmp = lengths(abs(sum-2*val), val);
        que.push(tmp);
    }

    lengths target = que.top();
    long long length = target.first;
    cout << length << endl;
    return 0;

}

Measured memory_bytes: 9004
n = int(input())
p = input().split()
p = list(map(int,p))
ans=0
for i in range(n-2):
    if p[i] < p[i+1] < p[i+2]:
        ans += 1
    elif p[i] > p[i+1] > p[i+2]:
        ans += 1
print(ans)

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

int main()
{
    string o,e;
    cin >> o >> e;
    string ans;
    for(int a = 0;a < o.size();a++){
        ans+=o.at(a);
        if(a < e.size()){
        ans+=e.at(a);
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
using namespace std;
typedef long long ll;
const ll mod = 1e9 + 7;
const int maxn = 3e6 + 10;
int N , M , L , R;
ll fac[maxn] , ifac[maxn]; //fac[i] = i! % mod , ifac[i] * fac[i] = 1 % mod
// count number of seq of A1 ... AN , Ai is non negative st
// 1. L <= A1 + A2 + ... + AN <= R
// 2. AM = AM + 1 , A1 >= A2 >= ... >= AN after sorting

ll qpow(ll a , int n){ //a ^ n % mod
  if(n <= 0)return 1ll;
  ll ret = qpow(a , n / 2);
  if(n % 2 == 1){
    return ((ret * ret) % mod) * a % mod;
  }
  return ret * ret % mod;
}

ll C(int n , int r){
  return (fac[n] * ifac[r] % mod) * ifac[n - r] % mod;
}

ll G(int N , int M , int S , int x , int y){ // A1 ... AM are at least x and AM+1 ... AN are less than y
  if(1ll * x * M > S)return 0ll;
  S -= x * M;
  ll ret = 0;
  ll sign = 1ll;
  for(int k = 0; k <= N - M && S >= 0; ++k , sign = 1ll * sign * (mod - 1) % mod , S -= y){
    ret = (ret + sign * C(S + N , N) % mod * C(N - M , k) % mod + mod) % mod;
  }
  return ret * C(N , M) % mod;
}

ll F(int N , int M , int S){
  ll ret = C(N + S , N);
  for(int x = 0; x < S; ++x){
    ll c = (G(N , M , S , x , x) - G(N , M , S , x + 1 , x) + mod) % mod;
    ret = (ret - c + mod) % mod;
  }
  return ret;
}

int main(){
  cin >> N >> M >> L >> R;
  fac[0] = 1ll;
  for(int i = 1; i < maxn; ++i){
    fac[i] = fac[i - 1] * i % mod;
  }
  ifac[maxn - 1] = qpow(fac[maxn - 1] , mod - 2);
  for(int i = maxn - 2; i >= 0; --i){
    ifac[i] = ifac[i + 1] * (i + 1) % mod;
  }
  cout << (F(N , M , R) - F(N , M , L - 1) + mod) % mod << endl;
  return 0;
}


Measured memory_bytes: 47232
#include <stdio.h>
 int main (void){
   int a,b,c,d,e;
   scanf("%d",&a);
   scanf("%d",&b);
   c=a+b;
   d=a-b;
   e=a*b;
   if(c>=d && c>=e){
     printf("%d",c);
       }
   if(d>c && d>=e){
     printf("%d",d);
      }
   if(e>c && e>d){
     printf("%d",e);
     }
   return 0;
   }

Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
#include<sstream>
#include<vector>
using namespace std;

long long int gcd(long long int a, long long int b) {
	long long int tmp;
	long long int r = 1;
	if (b > a) {
		tmp = a;
		a = b;
		b = tmp;
	}
	r = a % b;
	while (r != 0) {


		a = b;
		b = r;
		r = a % b;

	}
	return b;
}

int main() {
	//cout << fixed << setprecision(10);
	long long int a, b, c, d, n,GCD, m, k[300009] = {}, x[100][100] = {}, like[100] = {},res=0;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> k[i];
	}
	GCD = k[0];
	for (int i = 1; i < n; i++) {
		GCD = gcd(GCD, k[i]);
	}
	cout << GCD;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define sqr(x) ((x)*(x))
#define mp make_pair
#define ones(x) __builtin_popcount(x)
#define fast_io() ios_base::sync_with_stdio(0);cin.tie(0);
#define debug(x) cerr << #x << ": " << x << endl;
#define REP(i,x,y) for(int (i)=(x);(i)<(y);(i)++)
#define REPIT(it,A) for(auto it = (A.begin()); it!=A.end();it++)
#define fst first
#define snd second
#define itm1 fst.fst
#define itm2 fst.snd
#define itm3 snd
#define mt(a,b,c) mp(mp(a,b),c)
#define sz(v) int(v.size())
 
 
typedef pair<int,int> ii;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair< ii, int > tri;
typedef unsigned int uint;
typedef vector<int> vi;
typedef unsigned int ui;
typedef vector<ii> vii;

 

const long double PI = acos(-1);
const int  INF = 2e9 + 5;
const ll LINF = 1e18 + 5;
const ll MOD = 1e9 + 7;



ll go(ll a, ll b) {
	if(a > b) swap(a, b);
	ll q = b / a;
	if(b % a == 0) {
		return (2 * q - 1) * a;
	}
	
	return 2 * a  * q + go(b % a, a);	
}


int main() {
	ll n, x; cin >> n >> x;
	cout << n + go(x, n - x) << endl;

	return 0;
}











Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set>
#include <string>
#include <algorithm>
#include <queue>
#include <utility>
#include <climits>
#include <bitset>
#include <cmath>
#include <map>
#include <tuple>
#include <complex>

#define MOD 1000000007

using namespace std;

typedef long long ll;

typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<vl> vvl;
typedef vector<vi> vvi;
typedef vector<string> vs;

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

typedef vector<pll> vpl;
typedef vector<pi> vpi;

typedef queue<ll> ql;
typedef queue<int> qi;

template <class T>
void printv(vector<T> vc)
{
    for (auto e : vc)
        cout << e << " ";
    cout << endl;
}

template <class T>
void printvv(vector<T> vvc)
{
    for (auto vc : vvc)
    {
        for (auto e : vc)
            cout << e << " ";
        cout << endl;
    }
}

template <class T>
void printvp(vector<pair<T, T> > vp)
{
    for (auto pT : vp)
        cout << pT.first << " " << pT.second << endl;
}

int main() {
    int n;
    cin >> n;
    vector<tuple<int, int, int>> v;
    for (int i = 0; i < n; ++i) {
        int t, x, y;
        cin >> t >> x >> y;
        tuple<int, int, int> tpl(t, x, y);
        v.push_back(tpl);
    }

    auto ans = true;
    tuple<int, int, int> current(0, 0, 0);
    for (int i = 0; i < n; ++i) {
        auto next_time = get<0>(v[i]);
        auto next_x = get<1>(v[i]);
        auto next_y = get<2>(v[i]);
        auto diff_time = next_time - get<0>(current);
        auto diff_x = next_x - get<1>(current);
        auto diff_y = next_y - get<2>(current);
        auto diff_point = abs(diff_x) + abs(diff_y);
        if (diff_time < diff_point) {
            ans = false;
            break;
        } else if (diff_time > diff_point) {
            if ((diff_time - diff_point) % 2 != 0) {
                ans = false;
                break;
            }
        }
        current = tuple<int, int, int>(next_time, next_x, next_y);
    }

    cout << (ans ? "Yes" : "No") << endl;
    return 0;
}


Measured memory_bytes: 1912
#include<bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
int n,m;int a[224514],b[224514];
map<int,int>mp;
signed main(){
	cin>>n>>m;
	rep(i,m)cin>>a[i]>>b[i];
	rep(i,m){
		if(a[i]==1)mp[b[i]]++;
	}
	rep(i,m){
		if(b[i]==n&&mp[a[i]]){
			mp[a[i]]--;
			if(!mp[a[i]]){
				puts("POSSIBLE");
				return 0;
				}
			}
		}
	puts("IMPOSSIBLE");
}
	


Measured memory_bytes: 15872
package main

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

//util
var sc = bufio.NewScanner(os.Stdin)

func nextStr() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func printList(list []int) {
	buf := bufio.NewWriter(os.Stdout)
	for _, v := range list {
		buf.Write([]byte(fmt.Sprintf(" %d", v)))
	}
	buf.Write([]byte("\n"))
	buf.Flush()
}

//solve
func insert(k int) {
	H++
	//新しいキーを、一旦最後尾に挿入
	A[H] = -1
	heapIncreaseKey(H, k)
}

//二分ヒープの要素iのキー値を増加させる処理
func heapIncreaseKey(i, k int) {
	//kが親より小さい場合は整列済み
	if k < A[i] {
		return
	}
	A[i] = k
	//kが親より大きい場合は、入れ替える
	for i > 1 && A[i/2] < A[i] {
		tmp := A[i/2]
		A[i/2] = A[i]
		A[i] = tmp
		i = i / 2
	}
}

func heapExtractMax() {
	if H < 1 {
		return
	}
	//二分ヒープの根が、最大
	max := A[1]
	A[1] = A[H]
	H--
	maxHeapfy(1, H)

	fmt.Println(max)

}

func maxHeapfy(i int, n int) {
	//fmt.Println(A, i)
	largest := i
	l := 2 * i
	r := 2*i + 1

	//keyが最大のノードを、トップに持ってくる
	if l <= n && A[l] > A[i] {
		largest = l
	}
	if r <= n && A[r] > A[largest] {
		largest = r
	}

	if largest != i {
		tmp := A[i]
		A[i] = A[largest]
		A[largest] = tmp
		maxHeapfy(largest, n)
	}

}

func buildHeap(A []int, n int) {
	for i := n / 2; i >= 1; i-- {
		maxHeapfy(i, n)
		//fmt.Println(i, A)
	}
}

const MAX = 3000000

var A [MAX]int
var H int

func main() {
	sc.Split(bufio.ScanWords)
	flag := true
	for flag {
		verb := nextStr()
		switch verb {
		case "insert":
			k := nextInt()
			insert(k)
		case "extract":
			heapExtractMax()
		case "end":
			flag = false
		}
	}

	return
}



Measured memory_bytes: 15152
#include <iostream>
using namespace std;
int main (){

  int a,b,c,d,e,f;
  char op;
  
  while(0<=a && b<=20000){

    cin >> a >> op >> b;

    if( op == '+' ){
    
      c=a+b;
      cout <<c<<"\n";
 
    } else if( op == '-' ){

      d=a-b;
      cout <<d<<"\n";

    } else if( op == '*'){

      e=a*b;
      cout <<e<<"\n";

    } else if( op == '/'){

      f=a/b;
      cout <<f<<"\n";
 
    } else if( op =='?'){

      break;

    }
  }

  return 0;

}

Measured memory_bytes: 1164
from collections import deque
from collections import Counter
from itertools import product, permutations,combinations
from operator import itemgetter
from heapq import heappop, heappush
from bisect import bisect_left, bisect_right, bisect
#pypyではscipy, numpyは使えない
#from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson, minimum_spanning_tree
#from scipy.sparse import csr_matrix, coo_matrix, lil_matrix
#import numpy as np
from fractions import gcd
from math import ceil,floor, sqrt, cos, sin, pi, factorial
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**8)
INF = float('inf')
from datetime import datetime as dt

def main():
  n = input()
  ans = ''
  for i in range(len(n)):
    if n[i]=='1':
      ans += '9'
    else:
      ans += '1'
  print(ans)
  
  
  
  
if __name__ == '__main__':
  main()

Measured memory_bytes: 5332
#include <algorithm>
#include <cmath>
#include <iostream>
#include <queue>
#include <stdio.h>
#include <string>
#include <vector>

#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

/* a と b の最大公約数を返す関数 */
long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}


int main()
{	
	int a, b, c, d;
	cin >> a >> b >> c >> d;

	while (true)
	{
		c -= b;
		if (c <= 0)
		{
			cout << "Yes" << endl;
			break;
		}
		a -= d;
		if (a <= 0)
		{
			cout << "No" << endl;
			break;
		}
	}
	return 0;
}

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

int main() {
	// freopen("./input.txt", "r", stdin);
    int N, K;
    cin >> N >> K;
    if (K <= (N + 1) / 2) {
        cout << "YES\n";
    } else {
        cout << "NO\n";
    }
    
	return 0;
}

Measured memory_bytes: 256
a, b = map(int, input().split())
l = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
s = input()
flag = True
for i in range(len(s)):
    if i == a:
        if s[i] != '-':
            flag = False
    elif s[i] not in l:
        flag = False
if flag:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 61580
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<climits>//long long型の最大値(LLONG_MAX)など
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

using namespace std;
typedef long long ll;
typedef long double ld;

#define rep(i,n) for(ll i=0;i<(ll)(n);i++)


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

    ll AB = B-A;
    
    ll ans=0;
    if(AB % 2 == 0){
        ans = AB/2;
    }else{
        ans = min(A-1,N-B) + 1 + ((AB-1)/2);
    }
    cout << ans << endl;
}

Measured memory_bytes: 3620
// https://atcoder.jp/contests/abc164/tasks/abc164_d

#include "algorithm"
#include "bitset"
#include "cmath"
#include "functional"
#include "iomanip"
#include "iostream"
#include "map"
#include "numeric"
#include "queue"
#include "set"
#include "string"
#include "vector"
#define rep(i, to) for (ll i = 0; i < (to); ++i)
#define rep1(i, to) for (ll i = 1; i <= (to); ++i)
#define repf(i, from, to) for (ll i = from; i < (to); ++i)
#define repr(i, from) for (ll i = from - 1; i >= 0; --i)
#define all(vec) vec.begin(), vec.end()
#define unless(cond) if (!(cond))
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef long double ld;
template <typename T>
using V = vector<T>;
using VL = V<ll>;
using VVL = V<VL>;
template <typename T, typename U>
using P = pair<T, U>;
using PL = P<ll, ll>;
using VPL = V<PL>;

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

struct exit_exception : public std::exception {
  const char* what() const throw() { return "Exited"; }
};

template <typename T>
void drop(T res) {
  cout << res << endl;
  throw exit_exception();
}

const ll INF = 1e18;

void solve();
void solve2();

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

  try {
    solve2();
  } catch (exit_exception& e) {
  }

  return 0;
}
#endif

void solve() {
  string S;
  cin >> S;

  ll N = S.size();
  ll MOD = 2019;
  VL mods(N + 1);

  rep(i, N) mods[i + 1] = (mods[i] * 10 + (S[i] - '0')) % MOD;

  {
    ll ten_mod = 1;
    repr(i, N + 1) {
      mods[i] = (mods[i] * ten_mod) % MOD;
      ten_mod = ten_mod * 10 % MOD;
    }
  }

  ll res = 0;

  map<ll, ll> m;

  rep(i, N + 1) {
    res += m[mods[i]];
    m[mods[i]]++;
  }

  cout << res << "\n";
}

void solve2() {
  string S;
  cin >> S;

  ll N = S.size();
  ll MOD = 2019;

  VL dp(MOD);
  ll res = 0;

  for (auto c : S) {
    ll num = c - '0';
    VL dp2(MOD);

    // 配る DP
    rep(m, MOD) dp2[(10 * m + num) % MOD] += dp[m];

    ++dp2[num];  // 一桁の場合

    res += dp2[0];
    swap(dp, dp2);
  }

  cout << res << "\n";
}


Measured memory_bytes: 3712
#include<iostream>
#include<cstdio>

using namespace std;

int main(void){
	int s[5];
	int maxs,mins;
	int n;
	int a;
	while(1){
		cin >> n;
		if(n==0)break;
		cin >> s[0] >> s[1] >> s[2] >> s[3] >> s[4];
		maxs=s[0]+s[1]+s[2]+s[3]+s[4];
		mins=s[0]+s[1]+s[2]+s[3]+s[4];
		for(a=1;a<n;a++){
			cin >> s[0] >> s[1] >> s[2] >> s[3] >> s[4];
			maxs=max(maxs,s[0]+s[1]+s[2]+s[3]+s[4]);
			mins=min(mins,s[0]+s[1]+s[2]+s[3]+s[4]);
		}
		cout << maxs << ' ' << mins << endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include <cmath>
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<set>
#include<tuple>
#include<bitset>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
ll inf = 1000000007;
int main(void) {
	int l, r, d;
	cin >> l >> r >> d;
	ll count = 0;
	for (int i = l; i <= r; i++) {
		if (i % d == 0) {
			count++;
		}
	}
	cout << count << endl;
	return 0;
}

Measured memory_bytes: 3592
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdlib>
#include <string>
#include <cstring>
#include <cmath>
#include <climits>
#include <ctime>
#define endl '\n'
#define ll long long
#define mod 10007
#define NCONS 200001
//#define NCONS 100001
//#define NCONS 1001
//#define NCONS 10
#define MCONS 2001
#define LIMIT 1000000000
#define TRUE 1
#define FALSE 0

using namespace std;

int main(void)
{
    cin.tie(NULL); ios_base::sync_with_stdio(false);
    int n; cin >> n;
    vector<int> h(n, 0); for(int i = 0; i < n; i++) cin >> h[i];
    
    int ret = 0;
    int prev = -1;
    
    for(int i = 0; i < h.size(); i++)
    {
        if(prev <= h[i])
        {
            prev = h[i];
            ret += 1;
        }
    }
    
    cout << ret << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main() {
    int a[3], tmp, i, j;
    scanf("%d %d %d", &a[0], &a[1], &a[2]);
    for (i = 0; i < 3; i++) {
        for (j = i; j < 3; j++) {
            if (a[j] < a[i]) {
                tmp = a[j];
                a[j] = a[i];
                a[i] = tmp;
            }
        }
    }
    printf("%d %d %d\n", a[0], a[1], a[2]);
    return 0;
}


Measured memory_bytes: 2100
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int m = in.nextInt();
            int[] ar = new int[n];
            int sum = 0;
            for (int i = 0; i < n; i++) {
                ar[i] = in.nextInt();
                sum += ar[i];
            }
            Arrays.sort(ar);
            for (int i = n - 1, c = 0; c < m; i--, c++)
                if (ar[i] < (1.0 * sum / (4.0 * m))) {
                    out.println("No");
                    return;
                }
            out.println("Yes");
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

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

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

    }
}



Measured memory_bytes: 22740
n=int(input())
t_won=0
h_won=0
for _ in range(n):
    t_wd,h_wd = input().split()
    if   t_wd > h_wd: t_won += 1
    elif t_wd < h_wd: h_won += 1
print(t_won*3 + (n-t_won-h_won), h_won*3 + (n-t_won-h_won))

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

int main()
{
    int n, k, count = 0;
    cin >> n >> k;
    vector<int> a(n);

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

    for (int i = 0; i < k; i++)
    {
        int d;
        cin >> d;

        for (int j = 0; j < d; j++)
        {
            int l;
            cin >> l;
            a[l - 1] = 1;
        }
    }

    for (int i = 0; i < n; i++)
    {
        if (a[i] == 0)
            count++;
    }

    cout << count << endl;
}


Measured memory_bytes: 3196
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<math.h>

using namespace std;

typedef long long ll;

#define rep(i, n) for (ll i = 0; i < n; i++)

const ll INF = 1LL << 60;


signed main() {

	ll n;
	cin >> n;
	ll ans = 0;
	ll a = 0;
	while (n > 0) {
		n /= 2;
		a++;
	}
	rep(i, a) {
		ans += pow(2, i);
	}
	cout << ans;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define sz(x) int(x.size())
#define pb push_back
#define ff first
#define ss second
typedef long long ll;
typedef pair<int,int> ii;
typedef pair<ii,ii> qu;

qu op(qu a,qu b){
	set<ii>g;
	g.insert(a.ff);g.insert(a.ss);
	g.insert(b.ff);g.insert(b.ss);
	vector<ii>vec;
	for(ii s: g)vec.pb(s);
	return qu(vec[sz(vec)-1],vec[sz(vec)-2]);
}

int main(){
	int n;cin>>n;
	int lim=1<<n;
	qu neutro={{-1,-1},{-1,-1}};
	vector<qu>dp(lim);
	for(int i=0;i<lim;i++){
		dp[i]=neutro;
		cin>>dp[i].ff.ff;
		dp[i].ff.ss=i;
		dp[i].ss.ss=i;
	}
	for(int i=0;i<lim;i++){
		//cout<<"i "<<i<<endl;
		for(int j=0;j<n;j++)if(((i>>j)&1)==0){
			int see=i|(1<<j);
			dp[see]=op(dp[see],dp[i]);
		}
		//cout<<dp[i].ff<<" "<<dp[i].ss<<endl;
	}
	int ans=0;
	for(int i=1;i<lim;i++){
		ans=max(ans,dp[i].ff.ff+dp[i].ss.ff);
		cout<<ans<<endl;
	}
	return 0;
}


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

using namespace std;
#define ll long long
const int N = 2e5 + 5;

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    string a, b;
    cin >> a >> b;
    for(int i = 0 ; i < a.size() ; i++) {
        if (a[i] != b[i]) return cout << "No", 0;
    }
    cout << "Yes";
    return 0;
}

Measured memory_bytes: 3652
import java.io.*;
import java.util.Random;
import java.util.StringTokenizer;

public class Main {
    //Solution by Sathvik Kuthuru
    public static void main(String[] args) throws FileNotFoundException {
        FastReader scan = new FastReader();
        PrintWriter out = new PrintWriter(System.out);
        Task solver = new Task();
        int t = 1;
        for(int tt = 1; tt <= t; tt++) solver.solve(tt, scan, out);
        out.close();
    }

    static class Task {

        public void solve(int testNumber, FastReader scan, PrintWriter out) {
            out.println(2 * Math.PI * scan.nextLong());
        }
    }

    static void shuffle(int[] a) {
        Random get = new Random();
        for (int i = 0; i < a.length; i++) {
            int r = get.nextInt(a.length);
            int temp = a[i];
            a[i] = a[r];
            a[r] = temp;
        }
    }

    static void shuffle(long[] a) {
        Random get = new Random();
        for (int i = 0; i < a.length; i++) {
            int r = get.nextInt(a.length);
            long temp = a[i];
            a[i] = a[r];
            a[r] = temp;
        }
    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        public FastReader(String s) throws FileNotFoundException {
            br = new BufferedReader(new FileReader(new File(s)));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

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

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

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }

}

Measured memory_bytes: 33284
s = input()
for i in s:
    if ord('A') <= ord(i) <= ord('Z'):
        print(chr(ord(i)+32) ,end = '')
    elif ord('a') <= ord(i) <= ord('z'):
        print(chr(ord(i)-32) ,end = '')
    else:
        print(i ,end = '')
print('')



Measured memory_bytes: 5724
#include<cstdio>
#include<functional>
#include<algorithm>
using namespace std;
int main(void)
{
	int n,i,j,sum,k,t[100000],sa[100000],x;
	scanf("%d %d",&n,&k);
	for(i=0;i<n;i++)	scanf("%d",&t[i]);
	for(i=0;i<n-1;i++)	sa[i]=t[i+1]-t[i];
	sort(sa,sa+n-1);
	sum=k;	
	for(i=0;i<n-k;i++)	sum+=sa[i];
	printf("%d\n",sum);
	return 0;
}


Measured memory_bytes: 3520
//Dragon_warrior7(IITK)
#pragma GCC optimize ("Ofast")
#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize ("-ffloat-store")
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//using namespace __gnu_pbds;
#define umap unordered_map
#define uset unordered_set
#define ll long long
#define pb push_back
#define nl cout << '\n'
#define sor(x) sort(x.begin(), x.end())
#define rev(v) reverse(v.begin(), v.end())
#define lb(v, temp) lower_bound(v.begin(), v.end(), temp)
#define ub(v, temp) upper_bound(v.begin(), v.end(), temp)
#define fi first
#define se second
#define llmax 1000000000000000000
#define pll pair<ll, ll> 
#define ull unsigned ll
#define vll vector<ll> 
#define rub cout << "\n------------------------------------\n"
#define deb(x) cout<<#x<<' '<<'='<<' '<<x<<'\n'
#define fo(i,a,b) for(int i=a;i<b;i++)
//typedef  tree < int ,  null_type ,  greater<int> ,  rb_tree_tag ,  tree_order_statistics_node_update > oset;
void read(vector<ll> &v)
{
	for (int i = 0; i < v.size(); i++)
		cin >> v[i];
}
// const int mod=1e9+7;
// ll power(ll a,ll b) {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;}
// ll modInverse(ll a){return power(a,mod-2);}
ll n,m,a,b,c,k,temp,x,y;
const int MAXN=100000+11;
void solveforthiscase(const int & test)
{//deb(test);
cin>>n>>m;
cout<<(n*(n-1))/2+(m*(m-1))/2;





return ;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int test=1;
// 	cin>>test;
    for(int i=1;i<=test;i++)
    {
        solveforthiscase(i);
    }
}

Measured memory_bytes: 256
from collections import deque
s = list(input())
ans = deque(s)
Q = int(input())
is_reverse = False
for _ in range(Q):
    q = list(map(str,input().split()))
    if q[0] == '1':
        is_reverse = True ^ is_reverse # 反転
        #ans = ans[::-1]
    else:
        if is_reverse: # 反転してた場合
            if q[1] == '1':
                #ans = ans + q[2]
                ans.append(q[2])
            else:
                #ans = q[2] + ans
                ans.appendleft(q[2])
        else:
            if q[1] == '1':
                #ans = q[2] + ans
                ans.appendleft(q[2])
            else:
                #ans = ans + q[2]
                ans.append(q[2])
ans_s = ''.join(ans)
if is_reverse:
    print(ans_s[::-1])
else:
    print(ans_s)

#    print(ans)
#print(ans)


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

using namespace std;

#define debug(n) cerr << #n << ':' << n << endl;
#define dline    cerr << __LINE__ << endl;

using ll = long long;
template<class T, class U> using P = pair<T,U>;
template<class T> using Heap = priority_queue<T>;
template<class T> using heaP = priority_queue<T,vector<T>,greater<T>>;
template<class T,class U> using umap = unordered_map<T,U>;
template<class T> using uset = unordered_set<T>;

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

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

template<class T, size_t N, class U>
void Fill(T (&a)[N], const U&v){
    fill((U*)a,(U*)(a+N),v);
}

template<class T>
istream& operator >> (istream&is, vector<T>&v){
  for(auto&e:v)is >> e;
  return is;
}

int main(){
  long double l; cin >> l;
  cout << setprecision(10) << pow(l,3) / 27.0 << endl;
  return 0;
}


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

using namespace std;

typedef long long ll;
typedef long double Double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

// chmax, chmin
template<class T>
inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}

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

void solve(long long N, long long A, long long B, long long C,
           std::vector<long long> l) {
    long long len[4] = {0, A, B, C};

    int lp = 1 << (2 * N);

    int ans = 1e9;
    for (int i = 0; i < lp; i++) {
        int sm[4] = {};
        int cnt = 0;
        for (int j = 0; j < N; j++) {
            int x = (i >> (2 * j)) & 3;
            sm[x] += l[j];
            cnt += x != 0;
        }
        if( sm[1] == 0 || sm[2] == 0 || sm[3] == 0 ) continue;

        int sub = (cnt-3) * 10;
        for(int j = 1 ; j < 4 ; j++){
            sub += abs(len[j] - sm[j]);
        }
        ans = min(sub, ans);
    }
    cout << ans << endl;
}

int main() {
    long long N;
    scanf("%lld", &N);
    long long A;
    scanf("%lld", &A);
    long long B;
    scanf("%lld", &B);
    long long C;
    scanf("%lld", &C);
    std::vector<long long> l(N);
    for (int i = 0; i < N; i++) {
        scanf("%lld", &l[i]);
    }
    solve(N, A, B, C, std::move(l));
    return 0;
}


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

int main() {
	int n;
	cin>>n;
	set<string> s;
	for(int i=0;i<n;i++)
	{
		string s1;
		cin>>s1;
		s.insert(s1);
	}
	cout<<s.size()<<endl;
	return 0;
}

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

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

int main(){
	
	int N;cin>>N;
	
	int p[N];for(int i=0;i<N;i++)cin>>p[i];
	
	int cnt=0;
	for(int b=1;b<(1<<N);b++){
		long x=1;
		for(int i=0;i<N;i++){
			if(((b>>i)&1)!=0){
				const long g=gcd(x,p[i]);
				x*=p[i];
				x/=g;
			}
		}
		
		bool yes=true;
		for(int i=0;i<N;i++){
			if(((b>>i)&1)==0&&x%p[i]==0){
				yes=false;
				break;
			}
		}
		
		if(yes){
			cnt++;
		}
	}
	cout<<cnt<<endl;
}


Measured memory_bytes: 3120
import math


def combination(n, r):
    if n <= 1:
        return 0
    elif n == 2:
        return 1
    else:
        return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


def count_list(lst):
    count_lst = [0] * (max(lst) + 1)

    for i in lst:
        count_lst[i] += 1

    return count_lst


def main():
    n = int(input())
    a_lst = list(map(int, input().split()))
    lst1 = count_list(a_lst)
    lst2 = [0] * len(lst1)
    for i in range(len(lst1)):
        lst2[i] = combination(lst1[i], 2)
    tmp = sum(lst2)

    for i in range(n):
        a = a_lst[i]
        print(tmp - (lst1[a] - 1))


if __name__ == '__main__':
    main()

Measured memory_bytes: 32176
from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations # (string,3) 3回
from collections import deque
from collections import defaultdict
import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def main():
    s = input()
    t = input()
    print('Yes' if s == t[:-1] else 'No')

if __name__ == '__main__':
  main()


Measured memory_bytes: 10880
#include <stdio.h>

int main(void) {
	int hei[10],i,j,tmp;
	for(i=0;i<=9;i++)scanf("%d",&hei[i]);
	
	for(i=0;i<=8;i++){
		for(j=0;j<=8;j++){
			if(hei[j] < hei[j+1])tmp=hei[j],hei[j]=hei[j+1],hei[j+1]=tmp;
		}
	}
	printf("%d\n%d\n%d\n",hei[0],hei[1],hei[2]);
	return 0;
}



Measured memory_bytes: 2036
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll ans = 0;
void mergesort(vector<ll> & b, int lo, int hi) {
	if (lo >= hi) {
		return;
	}
	int mid = (lo + hi) / 2;
	mergesort(b, lo, mid);
	mergesort(b, mid + 1, hi);
	vector <ll> temp;
	int i = lo, j = mid + 1;
	while (i <= mid && j <= hi) {
        if (b[i] <= b[j]) { // big to small
			temp.push_back(b[j++]);
			ans += mid - i + 1;
        } else {
        	temp.push_back(b[i++]);
        }
	}
	while (i <= mid) {
		temp.push_back(b[i++]);
	}
	while (j <= hi) {
		temp.push_back(b[j++]);
	}
	for (int k = 0; k < hi - lo + 1; k++) {
		b[lo + k] = temp[k];
	}
}
int main() {
    std::ios::sync_with_stdio(false);
    int n, k;
    cin >> n >> k;
    vector <ll> b(n + 1);
    ll temp;
    b[0] = 0;
    for (int i = 1; i <= n; i++) {
		cin >> temp;
        b[i] = b[i - 1] + temp -k;
    }
    mergesort(b, 0, n);
    cout << ans << endl;
	return 0;
}


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

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

int main() {
  ll A, B, C, D;
  cin >> A >> B >> C >> D;
  A--;

  ll l    = lcm(C, D);
  ll ac   = A / C;
  ll ad   = A / D;
  ll al   = A < l ? 0 : A / l;
  ll ansA = A - (ac + ad - al);

  ll bc   = B / C;
  ll bd   = B / D;
  ll bl   = B < l ? 0 : B / l;
  ll ansB = B - (bc + bd - bl);

  cout << ansB - ansA << endl;
}

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

typedef long long ll;

int main() {
  int n, m;
  std::cin >> n >> m;
  std::vector<ll> vx(n);
  std::vector<ll> vy(m);
  ll mod = 1000000007;

  ll x_sum = 0;
  for (int i = 0; i < n; i++) {
    std::cin >> vx[i];
    x_sum += (i*vx[i] - (n-i-1)*vx[i]);
    x_sum = x_sum % mod;
  }
  ll y_sum = 0;
  for (int i = 0; i < m; i++) {
    std::cin >> vy[i];
    y_sum += (i*vy[i] - (m-i-1)*vy[i]);
    y_sum = y_sum % mod;
  }

  std::cout << x_sum * y_sum % mod;

  return 0;
}

Measured memory_bytes: 1792
# Problem https://atcoder.jp/contests/abc068/tasks/abc068_b
# Ruby 3rd Try
n = gets.chomp.to_i
ni = Array.new(n+1,0)
for k in 1..n do
    count = 0
    checknum = k
    while true
        oddcheck = checknum%2
        if oddcheck==1
            break
        else
            count = count+1
            checknum = checknum/2
        end
    end
    ni[k]=count
end
maxdivide = 0
answer = 0
for k in 0..n do
    if maxdivide <=ni[k] 
       answer = k
        maxdivide = ni[k]
    end
end
puts(answer)

Measured memory_bytes: 1788
#include <cstdio>
using namespace std;
int N, M, K;
int main() {
  scanf("%d %d %d", &N, &M, &K);
  int k[N*M+1] = {0};
  for(int i= 1; i <= N; ++i) {
    int on = i*M, diff = N-2*i;
    for(int j = 0; j <= M; ++j) {
      k[on+diff*j] = 1;
    }
  }
  printf("%s\n", (k[K]>0?"Yes":"No"));
}

Measured memory_bytes: 4096
from fractions import gcd
a, b, c, d = (int(i) for i in input().split())
def lcm(x, y):
    return (x * y) // gcd(x, y)

all = b-a+1
c_cnt = b//c-(a-1)//c
d_cnt = b//d-(a-1)//d
lcm_cnt = b//lcm(c,d)-(a-1)//lcm(c,d)
#print(c_cnt,d_cnt,lcm_cnt)
print(all-(c_cnt+d_cnt)+lcm_cnt)


Measured memory_bytes: 5244
// In the name of GOD
 
#include <bits/stdc++.h>
#define ll long long
#define pp pair <int, int>
using namespace std;
const int N = 1e5 + 10;
const ll INF = 1e18;
string s;
int n;

void solve() {
	int n, W;
	cin >> n >> W;
	vector <ll> w(n), val(n);
	int s = 0;
	for (int i = 0; i < n; ++i) {
		cin >> w[i] >> val[i];
		s += val[i];
	}
	vector <vector <ll>> dp(n + 1, vector <ll>(s + 1, INF));
	for (int i = 0; i <= n; ++i)
		dp[i][0] = 0;
	for (int i = 1; i <= n; ++i) {
		for (int j = 0; j <= s; ++j) {
			dp[i][j] = dp[i - 1][j];
			if (j - val[i - 1] >= 0)
				dp[i][j] = min (dp[i - 1][j - val[i - 1]] + w[i - 1], dp[i][j]);
		}
	}
	ll ans = 0LL;
	for (int i = 0; i <= n; ++i) {
		for (int j = 0; j <= s; ++j) {
			// cout << dp[i][j] << " ";
			if (dp[i][j] <= W)
				ans = max (1LL*j, ans);
		}
		// cout << "\n";
	}
	cout << ans;
}
int main () {
	ios_base::sync_with_stdio(false); 
    cin.tie(NULL); 
    int tt = 1;
    // cin >> tt;
    for (int tc = 1; tc <= tt; ++tc) {
        solve();
    }
}                                  

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

int main(){
    double a,b,x,PI = acos(-1);
    cin >> a >> b >> x;
    x /= a;
    cout <<fixed << setprecision(10);
    if(a * b /2 < x){
        cout << atan2(2*(a * b - x),a * a) * 180 / PI << endl;
    }else{
        cout << atan2(b * b,2 * x) * 180 / PI << endl;
    }
}


Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
typedef long long ll;
using namespace std;

int main(void){
    ll N,M;cin>>N>>M;
    ll S_TOTAL = min(M / 2, N);
    M = M - 2 * S_TOTAL;
    ll M_TOTAL = M / 4;
    cout << S_TOTAL + M_TOTAL << endl;
    return 0;
}

Measured memory_bytes: 256