akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<tuple>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define Per(i,sta,n) for(int i=n-1;i>=sta;i--)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;

int n,x[100010];
vector<int> s;

void solve(){
    cin >> n;
    //cout << "" << endl;
    int k=0;
    rep(i,n){
        cin >> x[i];
        if (x[i]>=2*k+1) {
            x[i]=2*k+1;
            k+=1;
        }
        //cout << x[i] << " ";
        if (x[i]%2==0) s.push_back(i+1);
    }
    //cout << "" << endl;
    while(s.size()<n){
        s.push_back(n);
    }
    // rep(i,n){
    //     //cout << s[i] << " ";
    // }
    //cout << "" << endl;
    ll ans=1;
    rep(i,n){
        ans*=s[i]-i;
        ans%=mod;
    }
    cout << ans << endl;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(50);
    solve();
}

Measured memory_bytes: 1276
import scala.io.StdIn.{readLine,readInt}

object Main {

  def main(args: Array[String]) = {
    val n = readInt
    val a = Array.ofDim[Int](4,3,10)

    1 to n foreach { _ =>
      val Array(b,f,r,v) = readLine.split(" ").map(_.toInt)
      a(b-1)(f-1)(r-1) += v
    }

    for(i <- 0 to 3) {
      for(j <- 0 to 2) {
        for(k <- 0 to 9) {
          print(" "+a(i)(j)(k))
        }
        println()
      }
      if(i<3) {
        println("####################")
      }
    }
  }
}

Measured memory_bytes: 44352
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define itrfor(itr,A) for(auto itr = A.begin(); itr !=A.end();itr++)
typedef long long llong;
char moji[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
char moji2[26]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
char moji3[10]={'0','1','2','3','4','5','6','7','8','9'};
#define Sort(a) sort(a.begin(),a.end());
#define Reverse(a) reverse(a.begin(),a.end());
#define print(a) cout << a << endl;


int main(){
    string s;
    cin >> s;
    int a=s.length()/2;
    int b=0;
    REP(i,s.length()) if(s[i] =='p') b+=1;
    cout << a-b << endl;
}

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

//sort(v.rbegin(), v.rend(), [](auto& x, auto& y){return x[1] < y[1];});
typedef long long ll;


int main(){
    int N,r=0,a;
    cin >> N;

    map<int,int> mp;

    for (int i=0;i<N;++i){
        cin >> a;
        mp[a] += 1;
    }

    for (auto x=mp.begin();x!=mp.end();++x){
        if(x->first < x->second) r += - x->first + x->second;
        else if(x->first > x->second) r += x->second;
        }
        cout << r << endl;
  }


Measured memory_bytes: 4736
T1, T2 = map(int, input().split())
A1, A2 = map(int, input().split())
B1, B2 = map(int, input().split())

P = (A1 - B1) * T1
Q = (A2 - B2) * T2

if P > 0:
    P *= -1
    Q *= -1
    
if P + Q < 0:
    print(0)
elif P + Q == 0:
    print("infinity")
else:
    S = -P // (P + Q)
    T = -P % (P + Q)
    if T != 0:
        print(S * 2 + 1)
    else:
        print(S * 2)



Measured memory_bytes: 38384
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <utility>
#include <vector>
#include <cmath>
using namespace std;
typedef pair<double, double> P;
typedef pair<P, int> PP;

const double pi = acos(-1);

double dist(P a, P b){
    return sqrt((a.first - b.first) * (a.first - b.first) + (a.second - b.second) * (a.second - b.second));
}

double argument(P p1, P p2, P p3){
    double a = dist(p1, p3);
    double b = dist(p1, p2);
    double c = dist(p2, p3);
    return pi - acos((b * b + c * c - a * a) / (2 * b * c));
}

int main()
{
    int n;
    cin >> n;
    double x[102], y[102];
    PP pp[102];
    for(int i = 0; i < n; i++){
        cin >> x[i] >> y[i];
        pp[i] = PP(P(x[i], y[i]), i);
    }
    sort(pp, pp + n);
    vector<int> vl;
    for(int i = 0; i < n; i++){
        int k = vl.size();
        while(k > 1 &&
              (pp[i].first.first - pp[vl[k - 1]].first.first) * (pp[vl[k - 2]].first.second - pp[vl[k - 1]].first.second) -
              (pp[vl[k - 2]].first.first - pp[vl[k - 1]].first.first) * (pp[i].first.second - pp[vl[k - 1]].first.second) <= 0){
            vl.pop_back();
            k--;
        }
        vl.push_back(i);
    }
    vector<int> vh;
    for(int i = n - 1; i >= 0; i--){
        int k = vh.size();
        while(k > 1 &&
              (pp[i].first.first - pp[vh[k - 1]].first.first) * (pp[vh[k - 2]].first.second - pp[vh[k - 1]].first.second) -
              (pp[vh[k - 2]].first.first - pp[vh[k - 1]].first.first) * (pp[i].first.second - pp[vh[k - 1]].first.second) <= 0){
            vh.pop_back();
            k--;
        }
        vh.push_back(i);
    }
    double arg[102];
    fill(arg, arg + n, 0.0);
    int k;
    k = vl.size();
    for(int i = 1; i < k - 1; i++){
        arg[pp[vl[i]].second] = argument(pp[vl[i - 1]].first, pp[vl[i]].first, pp[vl[i + 1]].first);
    }
    k = vh.size();
    for(int i = 1; i < k - 1; i++){
        arg[pp[vh[i]].second] = argument(pp[vh[i - 1]].first, pp[vh[i]].first, pp[vh[i + 1]].first);
    }
    arg[pp[0].second] = argument(pp[vl[1]].first, pp[0].first, pp[vh[k - 2]].first);
    k = vl.size();
    arg[pp[n - 1].second] = argument(pp[vh[1]].first, pp[n - 1].first, pp[vl[k - 2]].first);
    for(int i = 0; i < n; i++){
        cout << fixed << setprecision(15) << arg[i] / (pi * 2) << endl;
    }
}

Measured memory_bytes: 640
n,m = map(int,input().split())
if n == m == 1:
  print(1)
elif n == 1:
  print(m-2)
elif m == 1:
  print(n-2)
elif n == 2 or m == 2:
  print(0)
else:
  print(n*m -(n+m-2)*2)    

Measured memory_bytes: 2940
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main(){
  int n;cin>>n;
  vector<long long>A(n);
  vector<long long>B(n+2);
  for(int i = 0; n > i; i++){
    cin>>A[i];
  }
  sort(A.begin(),A.end());
  B[0] = 0;
  for(int i = 0; n > i; i++){
    B[i+1] = B[i]+A[i];
  }
  B[n+1] = 0;
  for(int i = n-1; 0 < i; i--){
    if(B[i]*2 < A[i]){
      cout << n-i << endl;
      return 0;
    }
  }
  cout << n << endl;
}


Measured memory_bytes: 1792
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
using namespace std;
#ifndef FAST_IO
 #define IOS ios_base::sync_with_stdio(false);cin.tie(nullptr);
#endif

#define FILE_IO freopen("input.txt","r",stdin)
#define int long long
#define f first
#define s second
#define endl '\n'
#define all(c) c.begin(),c.end()
#define bp __builtin_popcount
#define debug(x) cerr << #x << " = " << x << endl;

const int MOD = 1e9 + 7;
const int INF = 1e18;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template <typename T>void print(T t){for(auto &it : t)cout<<it<<" ";}
inline int powerexp(int a, int b, int m = MOD){ int res = 1;while(b){if(b&1)res = res * a % m;a = a * a % m,b >>= 1;}return res % m;}
inline int modinv(int a){ return powerexp(a,MOD-2,MOD);}
inline int lcm(int a, int b){ int g = __gcd(a,b);return a/g*b;}
inline int add(int x, int y){ x += y; if (x >= MOD) x -=  MOD; return x;}
inline int mul(int x, int y){ return (x * 1ll * y) % MOD;}
inline int sub(int x, int y){ x -= y; if (x<0) x += MOD; return x ;}

//-------------------< start here >-------------------------// 

void solve(){
    int n, q;
    cin >> n >> q;
    vector< vector<int> > v(n);
    for(int i = 0; i < q; i++){
	   int x;
	   cin >> x;
	   if (x == 0){
		   int l, r;
		   cin >> l >> r;
		   v[l].push_back(r);  
		 }
	   if (x == 1){
		   int t;
		   cin >> t;
		   for(int i = 0; i < (int)v[t].size(); i++){
			   if(i) cout <<  " ";
			   cout << v[t][i];
			 }
          cout << endl;
	    }
	   if (x == 2){
		    int t;
		    cin >> t;
		    v[t].clear(); 
		  }	
	}
	
}

//-----------------------------
//comment from here for TOPCODER 
int32_t main(){
   IOS;
   solve();
   //find();
   #ifdef LOCAL_DEFINE
   cerr << "time elapsed " << (double)clock()/CLOCKS_PER_SEC << endl;
   #endif
}



Measured memory_bytes: 9024
#include <stdio.h>

void p(int s,int n,int a[],int* m,int j) {
	int i;
	int hokanj=0;
	if(s<0)return;
	if(s==0 && n==0){(*m)++;return;}
	for(i=j+1;i<=9;i++){
		if(a[i]==0){a[i]=1;s-=i;hokanj=j;j=i;p(s,--n,a,m,j);}
		a[i]=0;s+=i;++n;j=hokanj;
	}
	return;
	
}
int partition(int s,int n) {
	int m=0;
	int a[]={0,0,0,0,0,0,0,0,0,0};
	p(s,n,a,&m,-1);
	return m;
}

int main(void){
	int s=1,n=1;
	while(scanf("%d %d",&n,&s)>0 && (n!=0 || s!=0)){
		printf("%d\n",partition(s, n));
	}
	return 0;
}



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

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define SORT(v, n) sort(v, v+n)
#define pb(a) push_back(a)
#define eb(a) emplace_back(a)
#define vi vector<int>
#define ddvi vector<vector<int>>

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

#define INF 1000

int main(){
	#define int ll
	cin.tie(0);
	ios::sync_with_stdio(false);
	// ここに処理を記述

	int H, W;
	cin >> H >> W;

	// ddvi field(W,vi(H,0));
	int field[W][H];
	char temp;
	REP(i,H){
		REP(j,W){
			cin >> temp;
			if(temp == '.') field[j][i] = 1;
			else field[j][i] = 0;
		}
	}

	// dpテーブルの初期化
	// ddvi dp(W,vi(H,INF));
	int dp[W][H];
	REP(i,W){
		REP(j,H){
			dp[i][j] = INF;
		}
	}

	if(field[0][0] == 0){
		dp[0][0] = 1;
	}
	else{
		dp[0][0] = 0;
	}

	// dpを回す (行ごとに左から埋める)
	REP(i,H){
		REP(j,W){
			if(i == 0 && j == 0) continue;
			if(i == 0){
				dp[j][i] = dp[j-1][i]
					+ ((field[j][i] == 0)? 1 : 0) 
					- ((field[j-1][i] == 0 && field[j][i] == 0)? 1 : 0);
			}
			else if(j == 0){
				dp[j][i] = dp[j][i-1]
					+ ((field[j][i] == 0)? 1 : 0) 
					- ((field[j][i-1] == 0 && field[j][i] == 0)? 1 : 0);
			}
			else{
				/*
				int x, y, prev;
				prev = min(dp[j-1][i], dp[j][i-1]);
				if(prev == dp[j][i-1]){
					x = j;
					y = i-1;
				}
				else{
					x = j-1;
					y = i;
				}

				dp[j][i] = prev
					+ ((field[j][i] == 0)? 1 : 0) 
					- ((field[x][y] == 0 && field[j][i] == 0)? 1 : 0);
				*/
				int left, up;
				left = dp[j][i] = dp[j-1][i]
					+ ((field[j][i] == 0)? 1 : 0) 
					- ((field[j-1][i] == 0 && field[j][i] == 0)? 1 : 0);
				up = dp[j][i] = dp[j][i-1]
					+ ((field[j][i] == 0)? 1 : 0) 
					- ((field[j][i-1] == 0 && field[j][i] == 0)? 1 : 0);

				dp[j][i] = min(left, up);
			}
		}
	}

	/*
	REP(i,H){
		REP(j,W){
			cout << dp[j][i];
		}
		cout << "\n";
	}
	*/

	cout << dp[W-1][H-1] << "\n";

	return 0;
}

Measured memory_bytes: 384
#include<stdio.h>
int main(){
	int n,s=0,a,b,i,M=86400,d[100010]={};
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d %d",&a,&b);
		s=(s+a)%M;
		d[s]++;
		s=(s+b)%M;
	}
	for(i=s=0;i<10801;i++)s+=d[i];
	a=s;
	for(i=0;i<M;i++){
		s+=d[(i+10801)%M]-d[i];
		if(a<s)a=s;
	}
	printf("%d\n",a);
	return 0;
}

Measured memory_bytes: 512
n, x = map(int, input().split())
a = list(map(int, input().split()))

cnt, a[0] = sum(a), min(a[0], x)
for i in range(1, n):
    if a[i - 1] + a[i] > x:
        a[i] = x - a[i - 1]
print(cnt - sum(a))


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

using namespace std;

int main(){
    int N,M,total=0;
    cin >> N >> M;
    int A[M];
    for(int i=0;i<M;i++){
        cin >> A[i];
        total += A[i];
    }
    if(total > N)cout << -1 << endl;
    else cout << N - total << endl;
    
}

Measured memory_bytes: 3652
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
    const int kNumSide = 12;
    vector<int> side(kNumSide);

    for(int i = 0; i < kNumSide; i++)
    {
        cin >> side[i];
    }
    sort(side.begin(), side.end());

    bool canMakeCuboid = true;
    for(int i = 1; i < 4; i++)
    {
        if(side[0] != side[i])
        {
            canMakeCuboid = false;
            break;
        }
        if(side[4] != side[4+i])
        {
            canMakeCuboid = false;
            break;
        }
        if(side[8] != side[8+i])
        {
            canMakeCuboid = false;
            break;
        }
    }

    if(canMakeCuboid)
    {
        cout << "yes" << endl;
    }
    else
    {
        cout << "no" << endl;
    }

    return 0;
}

Measured memory_bytes: 3148
#include <stdio.h>

int main(void) {
	int A = 0;
	int B = 0;
	int C = 0;
	int K = 0;
	long int num = 0;

	scanf("%d %d %d %d", &A, &B, &C, &K);

	int j;
	int count = 0;

	
	for(j=1; j<=A; j++) {
		count++;
		if(count > K) {
			break;
		}
		num = num + 1;
	}

	for(j=1; j<=B; j++) {
		count++;
		if(count > K) {
			break;
		}
	}

	for(j=1; j<=C; j++) {
		count++;
		if(count > K) {
			break;
		}
		num = num - 1;
	}
	
	printf("%ld", num);

	return 0;
}

Measured memory_bytes: 1732
#include<iostream>
#include <vector>
// #include "cxx-prettyprint/prettyprint.hpp"
#define MSG(x) std::cout << (x) << std::endl;

using namespace std;

int main() {
    int K, S, count;
    cin >> K >> S;
    count = 0;
    std::vector<std::vector<int>> list;

    for (int x=0; x<=K; x++) {
        int YplusZ = S - x;
        for (int y=0; y<=YplusZ; y++) {
            int z = YplusZ - y;
            if (y > K || z > K) {
                continue;
            }
            count++;
        }
    }

    MSG(count);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<ll,pll> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-9;
const ll mod=1e9+7;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

int n;
vi x,y;
vector<pair<double,int>> a;

int main(){
	cin>>n;
	x=y=vi(n);
	int B=0;
	for(int i=0;i<n;i++){
		cin>>x[i]>>y[i];
		if(x[i]==0&&y[i]==0) B++;
		else a.push_back(make_pair(atan2(y[i],x[i]),i));
	}
	n-=B;
	if(n==0){
		cout<<0<<endl;
		return 0;
	}
	sort(a.begin(),a.end());
	ll res=0;
	for(int i=0;i<n;i++){
		ll X=0,Y=0;
		for(int j=0;j<n;j++){
			X+=x[a[(i+j)%n].second];
			Y+=y[a[(i+j)%n].second];
			res=max(res,X*X+Y*Y);
		}
	}
	cout<<syosu(12)<<sqrt(res)<<endl;
}

Measured memory_bytes: 384
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

int main(void){

    int n, max = 0, sum = 0;

    cin >> n;

    vector<int> l(n);

    for(int i = 0;i < n;i++){
        cin >> l[i];
    }

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

    max = l[n-1];

    for(int i = 0;i < n-1;i++){
        sum += l[i];
    }

    cout << (max < sum?"Yes":"No") << endl;

    return 0;
}

Measured memory_bytes: 256
import numpy as np
N,C=map(int, input().split())

#s~tでc
L=np.zeros((C, 10**5+1))

for i in range(N):
    s,t,c=map(int, input().split())
    L[c-1,s-1]+=1
    L[c-1,t]-=1

L=np.cumsum(L, axis=1)
print(int((L>0).sum(axis=0).max()))


Measured memory_bytes: 59224
board = [int(s) for _ in range(4) for s in input().split()]
move_piece = [None]* 46
GOAL = list(range(1,16)) + [0]


def create_adjacent(h, w):
  adjacent = [[] for _ in range(h*w)]
  for i in range(h * w):
    if i % w != w-1:
      adjacent[i].append(i+1)
    if i % w != 0:
      adjacent[i].append(i-1)
    if i // h < h-1:
      adjacent[i].append(i+w)
    if i // h > 0:
      adjacent[i].append(i-w)
  return adjacent

def id_search(limit, move, space, lower):
  if move == limit:
    if board == GOAL:
      global count
      count += 1
      print(move)
      exit()
  else:
    for x in adjacent[space]:
      p = board[x]
      if move_piece[move] == p:
        continue
      board[space], board[x] = p, 0
      move_piece[move + 1] = p
      new_lower = lower - distance[p][x] + distance[p][space]

      if new_lower + move <= limit:
        id_search(limit, move+1, x, new_lower)
      board[space], board[x] = 0, p

def create_distance(h, w):
  distance = [[0] * h * w for _ in range(h *w)]
  for i in range(h*w):
    if i == 0:
      continue
    ye, xe = divmod(i-1, w)
    for j in range(h *w):
      y, x = divmod(j,w)
      distance[i][j] = abs(ye-y) + abs(xe-x)
  return distance

def get_distance(board):
  v = 0
  for x in range(len(board)):
    p = board[x]
    if p == 0:
      continue
    v += distance[p][x]
  return v

adjacent = create_adjacent(4, 4)
distance = create_distance(4,4)
n = get_distance(board)
count = 0
for x in range(n,46):
  id_search(x, 0, board.index(0), n)
  if count > 0:
    break




Measured memory_bytes: 5624
// IO library
#include <cstdio>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>
#include <cmath>
#include <numeric>

// container library
#include <deque>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>

// namespace
using namespace std;

// typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<VB> VVB;

// conversion
#define INT(c) static_cast<int>(c)
#define CHAR(n) static_cast<char>(n)
#define LL(n) static_cast<ll>(n)

// container
#define EACH(i, c) for (auto i = (c).begin(); i != (c).end(); i++)
#define SORT(c) sort((c).begin(), (c).end())
#define GSORT(c) sort((c).begin(), (c).end(), greater<decltype((c).front())>())
#define SZ(x) (INT((x).size()))
#define MEMSET(c, v) memset((c), v, sizeof(c))

// repetition
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define NREP(i, n) FOR(i, 1, n + 1)
#define RFOR(i, a, b) for (ll i = (a); i >= (b); i--)
#define RREP(i, n) RFOR(i, n, 0)
#define RNREP(i, n) RFOR(i, n, 1)

// constant
const ll MOD = 1e9 + 7;
// const int INF = 1<<25;
// const ll INF = 1LL<<50;
// const int dx[4] = {0, -1, 1, 0};
// const int dy[4] = {-1, 0, 0, 1};
// const int dx[8] = {-1, 0, 1, -1, 1, -1, 0, 1};
// const int dy[8] = {-1, -1, -1, 0, 0, 1, 1, 1};

// debug
#define test(x) cout << #x << " = " << x << endl

// answer output
#define Yes(c) cout << ((c) ? "Yes" : "No") << endl;
#define YES(c) cout << ((c) ? "YES" : "NO") << endl;
#define yes(c) cout << ((c) ? "yes" : "no") << endl;

#define possible(c) cout << ((c) ? "possible" : "impossible") << endl;
#define POSSIBLE(c) cout << ((c) ? "POSSIBLE" : "INPOSSIBLE") << endl;


// --------------------------------------------------------

VVL powdp(401, VL(401));

void calc_pow() {
  REP(i, 401) {
    powdp[i][0] = 1;
  }

  NREP(j, 400) {
    REP(i, 401) {
      powdp[i][j] = powdp[i][j - 1] * i;
      powdp[i][j] %= MOD;
    }
  }
}

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

  calc_pow();

  ll N, C;
  cin >> N >> C;
  VL A(N + 1), B(N + 1);
  NREP(i, N) {
    cin >> A[i];
  }
  NREP(i, N) {
    cin >> B[i];
  }

  VVL dp(N + 1, VL(C + 1, 0));

  dp[0][0] = 1;
  NREP(j, C) {
    dp[0][j] = 0;
  }

  NREP(i, N) {
    REP(k, C + 1) {
      ll powAB = 0;
      FOR(n, A[i], B[i] + 1) {
        powAB += powdp[n][k];
        powAB %= MOD;
      }
      // powAB = A[i]^k + A[i+1]^k + ... + B[i]^k

      REP(j, C - k + 1) {
        dp[i][C - j] += dp[i - 1][C - j - k] * powAB % MOD;
        dp[i][C - j] %= MOD;
      }
    }
  }

  cout << dp[N][C] << endl;
  return 0;
}

Measured memory_bytes: 2816
import sys
import heapq
import math
import fractions
import bisect
import itertools
from collections import Counter
from collections import deque
from operator import itemgetter
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))

n=int(input())
a=lmp()
b=lmp()
c=lmp()
ans=b[a[0]-1]
for i in range(1,n):
    ans+=b[a[i]-1]
    if a[i]-a[i-1]==1:
        ans+=c[a[i]-2]
print(ans)

Measured memory_bytes: 5880
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <cmath>
using namespace std;
typedef vector<int> VI;
#define REP( i, m, n ) for ( int i = (int)( m ); i < (int)( n ); ++i )

int sumDigit(int n) {
    int ret = 0;

    while (n) {
        ret += n % 10;
        n /= 10;
    }
    return ret;
}

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

    VI nums;
    
    int t;
    while (cin >> t) {
        nums.push_back(t);
    }
    
    for (auto n : nums) {
        int ans = 0;
        REP(i, 0, 10000) {
            if (n == sumDigit(i))   ++ans;
        }
        cout << ans << endl;
    }
    
    return 0;
}

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

using namespace std;

int main()
{
	int n, tmp, m = 0, count = 0;
	map<int, bool> mp;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> tmp;
		m = max(m, tmp);
		if (mp[tmp]) {
			mp[tmp] = false;
		}
		else {
			mp[tmp] = true;
		}
	}
	for (auto x : mp) {
		if (x.second) {
			count++;
		}
	}
	cout << count << endl;
	return 0;
}



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

int main(void){
    int a,b,c,x,y;
    cin>>a>>b>>c>>x>>y;

    int cost = 0;
    for(int i=0;i<=100000;i++){
        int j = max(x-i,0);
        int l = max(y-i,0);
        int tmp = a*j+b*l+2*c*i;
        if(cost>tmp || cost==0) cost = tmp;
    }

    cout << cost << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define F first
#define S second
#define PB push_back
#define ALL(a) a.begin(), a.end()
#define REP(i,a) for(ll i(0), _##i(a); i < _##i; ++i)
#define FOR(i,a,b) for(ll i(a), _##i(b); i <= _##i; ++i)
using namespace std;
using ll = long long;

void solve(){
    int k;
    cin >> k;

    string s = "0";
    while(k--){
        bool add = true;
        for(int i = 1; i < s.size(); ++i){
            if (s[i] != s[i - 1] + 1) {
                add = false;
                break;
            }
        }
        add |= (s == string(s.size(), '9'));

        if (add){
            if (s[0] != '9'){
                ++s[0];
                for(int i = 1; i < s.size(); ++i){
                    if (s[i-1] == '0') s[i] = '0';
                    else s[i] = s[i-1] - 1;
                }
            } else {
                s = string(s.size() + 1, '0');
                s[0] = '1';
            }
        } else {
            int last = (int)s.size() - 1;
            bool check = true;
            if (last - 1 >= 0 && s[last] <= s[last - 1] && s[last] != '9'){
                ++s[last];
                check = false;
            }
            if (check){
                last = (int)s.size() - 1;
                while (last - 1 >= 0){
                    char xx = (last - 2 >= 0 ? s[last - 2] : s[last]);
                    if (s[last] != s[last - 1] && abs(s[last] - xx) <= 1){
                        swap(s[last], s[last - 1]);
                        for(int i = last + 1; i < s.size(); ++i){
                            if (s[i-1] == '0') s[i] = '0';
                            else s[i] = s[i-1] - 1;
                        }
                        break;
                    }
                    --last;
                }
            }
        }
    }
    cout << s << "\n";
}

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

    int T = 1;
    //cin >> T;
    FOR(i,1,T){
        solve();
    }
}


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

int c[1010],k[1010];
int dp[1<<13];
main(){
	int n,m,t,ipt;
	
	
	cin>>n>>m;
	for(int i=1;i<=m;i++){
		cin>>c[i]>>t;
		while(t--){
			cin>>ipt;
			k[i] |= 1<<(ipt-1);
		}
	}
	
	dp[0] = 0;
	for(int i=1;i<(1<<n);i++){
		dp[i] = 1e9;
		for(int j=1;j<=m;j++){
			if((i&k[j]) == 0)	continue;
			dp[i] = min(dp[i], dp[i - (i&k[j])] + c[j]);
		}
	}
	if(dp[(1<<n)-1] == 1e9)
		cout<<-1;
	else
		cout<<dp[(1<<n)-1];
	
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using  namespace std;
typedef long long ll;
int main(){
    ll h, w, pase1, pase2, pase3, max_pase, min_pase;
    ll ans = pow(10, 10);
    cin >> h >> w;
    for(ll i=1;i<h;i++){
        pase1 = i*w;
        if(w%2==0){
            pase2 = (h-i)*(w/2);
            ans = min(ans, abs(pase1-pase2));
        }else{
            pase2 = (h-i)*(w/2);
            pase3 = (h-i)*(w/2+1);
            max_pase = max(pase1, pase2);
            max_pase = max(max_pase, pase3);
            min_pase = min(pase1, pase2);
            min_pase = min(min_pase, pase3);
            ans = min(ans, (max_pase-min_pase));
        }
    }
    for(ll i=1;i<w;i++){
        pase1 = i*h;
        if(h%2==0){
            pase2 = (w-i)*(h/2);
            ans = min(ans, abs(pase1-pase2));
        }else{
            pase2 = (w-i)*(h/2);
            pase3 = (w-i)*(h/2+1);
            max_pase = max(pase1, pase2);
            max_pase = max(max_pase, pase3);
            min_pase = min(pase1, pase2);
            min_pase = min(min_pase, pase3);
            ans = min(ans, (max_pase-min_pase));
        }
    }
    if(h%3==0){
        cout << 0 << endl;
        return 0;
    }else {
        ans = min(w, ans);
    }
    if(w%3==0){
        cout << 0 << endl;
        return 0;
    }else {
        ans = min(h, ans);
    }

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


Measured memory_bytes: 256
#include<stdio.h>

int main(){
	long int A, B, C, K;
	scanf("%ld %ld %ld %ld", &A, &B, &C, &K);
	if(K <= A)
		printf("%ld", K);
	else if(K <= A + B)
		printf("%ld", A);
	else
		printf("%ld", 2 * A + B - K);
	return 0;
}

Measured memory_bytes: 1708
package main

import "fmt"
import "sort"

func main(){
    var a, b, c int

    fmt.Scan(&a)
    fmt.Scan(&b)
    fmt.Scan(&c)

    nums := []int{a, b, c}
    sort.Sort(sort.IntSlice(nums))

    fmt.Printf("%d\n", nums[0]*nums[1]/2)
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#include <fstream>
#include <cstdio>
using namespace std;
// vector<pair<int,int> > v;
// cin.ignore();//twice getline(cin,s);
// g++ iterator.cpp -std=c++17
// cout<<(A + B == C ? "YES" : "NO")<<endl;
// __gcd(a,b)
// string s=to_string(n);
// string p=s.substr(0,len);
// string q=s.insert(0,str);
// sort(arr, arr+n, greater<int>());
// cout<<fixed<<setprecision(9)<<pi<<endl
// const  double pi = acos(-1.0);
// sort(v.rbegin(),v.rend());
#define ff first
#define ss second
#define pb push_back
#define mk make_pair
#define vll vector<ll>
#define mll map<ll,ll >
#define mlli map<ll,ll>::iterator
#define size size()
#define endl "\n"
#define ll long long int
#define ld long double
void fast(){ios_base::sync_with_stdio(false);
cin.tie(NULL);cout.tie(NULL);}


int main(void)
{
	fast();
	string s;
	cin>>s;
	if(s[s.size-1]=='s')
	{
		cout<<s+"es"<<endl;
	}
	else
	{
		cout<<s+"s"<<endl;
	}
}

Measured memory_bytes: 3660
import math
from collections import deque
from collections import defaultdict

#自作関数群
def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))
def readChar():
	return input()
def readChars():
	return input().split()
def factorization(n):
	res = []
	if n%2==0:
		res.append(2)
	for i in range(3,math.floor(n//2)+1,2):
		if n%i==0:
			c = 0
			for j in res:
				if i%j==0:
					c=1
			if c==0:
				res.append(i)
	return res
def fact2(n):
	p = factorization(n)
	res = []
	for i in p:
		c=0
		z=n
		while 1:
			if z%i==0:
				c+=1
				z/=i
			else:
				break
		res.append([i,c])
	return res
def fact(n):#階乗
	ans = 1
	m=n
	for _i in range(n-1):
		ans*=m
		m-=1
	return ans
def comb(n,r):#コンビネーション
	if n<r:
		return 0
	l = min(r,n-r)
	m=n
	u=1
	for _i in range(l):
		u*=m
		m-=1
	return u//fact(l)
def combmod(n,r,mod):
	return (fact(n)/fact(n-r)*pow(fact(r),mod-2,mod))%mod
def printQueue(q):
	r=copyQueue(q)
	ans=[0]*r.qsize()
	for i in range(r.qsize()-1,-1,-1):
		ans[i] = r.get()
	print(ans)
class UnionFind():
	def __init__(self, n):
		self.n = n
		self.parents = [-1]*n

	def find(self, x): # root
		if self.parents[x]<0:
			return x
		else:
			self.parents[x] = self.find(self.parents[x])
			return self.parents[x]

	def union(self,x,y):
		x = self.find(x)
		y = self.find(y)

		if x==y:
			return

		if self.parents[x]>self.parents[y]:
			x,y = y,x

		self.parents[x]+=self.parents[y]
		self.parents[y]=x

	def size(self,x):
		return -1*self.parents[self.find(x)]

	def same(self,x,y):
		return self.find(x)==self.find(y)

	def members(self,x): # much time
		root = self.find(x)
		return [i for i in range(self.n) if self.find(i)==root]

	def roots(self):
		return [i for i,x in enumerate(self.parents) if x<0]

	def group_count(self):
		return len(self.roots())

	def all_group_members(self):
		return {r: self.members(r) for r in self.roots()} # 1~n
def bitArr(n):#ビット全探索
	x = 1
	zero = "0"*n
	ans = []
	ans.append([0]*n)
	for i in range(2**n-1):
		ans.append(list(map(lambda x:int(x),list((zero+bin(x)[2:])[-1*n:]))))
		x+=1
	return ans;
def arrsSum(a1,a2):
	for i in range(len(a1)):
		a1[i]+=a2[i]
	return a1
def maxValue(a,b,v):
	v2 = v
	for i in range(v2,-1,-1):
		for j in range(v2//a+1): #j:aの個数
			k = i-a*j
			if k%b==0:
				return i
	return -1
def copyQueue(q):
	nq = queue.Queue()
	n = q.qsize()
	for i in range(n):
		x = q.get()
		q.put(x)
		nq.put(x)
	return nq
def get_sieve_of_eratosthenes(n):
	#data = [2]
	data = [0,0,0]
	for i in range(3,n+1,2):
		data.append(i)
		data.append(0)
	for i in range(len(data)):
		interval = data[i]
		if interval!=0:
			for j in range(i+interval,n-1,interval):
				data[j] = 0
	#ans = [x for x in data if x!=0]
	ans = data[:]
	return ans

n = readInt()
d = defaultdict(int)
p="0"
for i in range(n):
	x = input()
	if p[-1]!=x[0]:
		if p!="0":
			print("No")
			exit()
	d[x]+=1
	p = x

for i in d:
	if d[i]>1:
		print("No")
		exit()

print("Yes")

Measured memory_bytes: 3572
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define FORR(i,a,b) for (int i=(a);i>=(b);i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pcnt __builtin_popcount
#define sz(x) (int)(x).size()
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define show(x) cout<<#x<<" = "<<x<<endl;
#define rng(a) (a.begin()),(a.end())
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef set<int> si;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pll> vpll;
typedef set<ll> sl;
typedef __int128_t lll;
typedef pair<lll,lll> plll;
typedef vector<lll> vlll;
template<typename T>string join(vector<T>&v){stringstream s;FOR(i,0,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename A,size_t N,typename T>void Fill(A (&array)[N],const T&v){fill((T*)array,(T*)(array+N),v);}
lll gcd(lll a,lll b,lll &x,lll &y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll gcd(ll a,ll b){lll x=0,y=0;return gcd(a,b,x,y);}
ll modpow(lll a,lll n,ll m){if(a==0)return a;lll p=1;for(;n>0;n<<=1,a=a*a%m)if(n&1)p=p*a%m;return(ll)p;}
void dout(double d){printf("%.12f\n",d);}
void YN(bool z){cout<<(z?"YES\n":"NO\n");}
void Yn(bool z){cout<<(z?"Yes\n":"No\n");}
void yn(bool z){cout<<(z?"yes\n":"no\n");}

const int iinf = 1e9;
const ll linf = 1e18;
const int mod = 1e9+7;
const double pi = acos(-1);
const double eps = 1e-10;
const int N = 1e5;
int n, m, Q, q[N][3], v[N][2];
vi e[N];
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n >> m;
  FOR(i, 0, m){
    int a, b;
    cin >> a >> b;
    a--; b--;
    e[a].pb(b);
    e[b].pb(a);
  }
  cin >> Q;
  FOR(i, 0, Q)FOR(j, 0, 3) cin >> q[i][j];
  FOR(i, 0, n) v[i][1] = -1;
  FORR(i, Q-1, 0){
    queue<int> qu, tmp;
    int f = q[i][0]-1, dist = q[i][1], c = q[i][2];
    if(v[f][1] >= dist) continue;
    qu.push(f);
    if(!v[f][0]) v[f][0] = c;
    v[f][1] = dist;
    while(dist){
      dist--;
      while(!qu.empty()){
        int p = qu.front();
        qu.pop();
        for(int pp: e[p]){
          if(v[pp][1] >= dist) continue;
          tmp.push(pp);
          if(!v[pp][0]) v[pp][0] = c;
          v[pp][1] = dist;
        }
      }
      swap(qu, tmp);
    }
  }
  FOR(i, 0, n) printf("%d\n", v[i][0]);
  return 0;
}

Measured memory_bytes: 8824
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader input =new BufferedReader (new InputStreamReader (System.in));
		String str = input.readLine( );
		long x = Long.parseLong(str);
		long a = x / 11;
		long b = x % 11;

		if(b>6){
			System.out.println(a*2 + 2);
		}else if(b>0){
			System.out.println(a*2 + 1);
		}else{
			System.out.println(a*2);
		}
	}

}


Measured memory_bytes: 21076
#include<bits/stdc++.h>
using namespace std;
#define  ft  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define  ll  long long
#define  pi  pair<int,int>
#define  pb  push_back
#define  F   first
#define  S   second
#define  B   begin()
#define  E   end()
const int N=2e5+3;
//string s,p;
//vector<int>v;
//map<int,int>mp;
void go(ll t)
{
    if(t)
    {
        go((t-1)/26);
        putchar(97+(t-1)%26);
    }
}
int main()
{
    ft
    ll t,i,j,n,m,l,r;
    cin>>n;
    go(n);
    return 0;
}



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

int cnt[3][4005];

int main(int argc, char *argv[]) { ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
  int n;cin>>n;
  string s;cin>>s;
  string rgb="RGB";
  int dbg=0;
  map<char, int> mp;for(int i=0;i<3;i++)mp[rgb[i]]=i;
  for(int i=n-1;i>=0;i--){
    int pos = mp[s[i]];
    for(int j=0;j<3;j++){
      cnt[j][i]+=cnt[j][i+1];
    }
    cnt[pos][i]++;
  }
  
  ll ans=0;
  for(int i=0;i<n;i++){
    for(int j=i+1;j<n;j++){
      if(s[i]==s[j])continue;
      for(int k=0;k<3;k++){
        if(s[i]==rgb[k]||s[j]==rgb[k])continue;
        ans += cnt[mp[rgb[k]]][j+1];
        if(j+j-i<n&&s[j+j-i]==rgb[k])ans--;
      }
    }
  }
  cout<<ans<<endl;
  
  return 0;
}


Measured memory_bytes: 3684
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <queue>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <stdio.h>
#include <complex>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<int, PII> TIII;
typedef long long LL;
typedef vector<LL> VLL;

//container util

//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define MT(a,b,c) MP(a, MP(b, c))

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

int n,m,p,a,b;
VI t;
map<int, vector<PII> > s;
map<pair<int, VI>, double> v;

int main(){
	while(1){
		t.clear();
		s.clear();
		v.clear();
		cin>>n>>m>>p>>a>>b;
		if(m==0)break;
		t = VI(n);
		double ret = -1.0;
		REP(i,n)cin>>t[i];
		sort(ALL(t));
		REP(i,p){
			int x,y,z;
			scanf("%d %d %d", &x, &y, &z);
			s[x].PB(MP(y,z));
			s[y].PB(MP(x,z));
		}
		priority_queue<pair<double, pair<int, VI> >, vector<pair<double, pair<int, VI> > >, greater<pair<double, pair<int, VI> > > > q;
		q.push(MP(0.0, MP(a, t)));
		while(!q.empty()){
			pair<double, pair<int, VI> > tmp = q.top();
			q.pop();
			if(EXIST(v, tmp.second))continue;
			if(tmp.second.first ==b){
				ret = tmp.first;
				break;
			}
			int c = tmp.second.first;
			v[tmp.second] = tmp.first;
			REP(i,s[c].size()){
				REP(j, n){
					VI ts = tmp.second.second;
					if(ts[j] == 0)continue;
					double tt = tmp.first + (s[c][i].second*1.0)/(ts[j]*1.0);
					ts[j]=0.0;
					SORT(ts);
					q.push(MP(tt, MP(s[c][i].first, ts)));
				}
			}
		}
		if(ret >= 0.0)cout << ret << endl;
		else cout << "Impossible" << endl;
	}
	return 0;
}

Measured memory_bytes: 14300
#include <bits/stdc++.h>
#include <variant>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/adaptor/indexed.hpp>
#define FOR(i,k,n)  for(int i = (k);i < (n);++i)
#define REP(i,n)    FOR(i,0,n)
#define ALL(x) begin(x),end(x)

using namespace std;
using namespace boost::adaptors;
using namespace std::string_literals;
using ll = int64_t;
using vecint = vector<int>;
using vecll = vector<ll>;
using boost::irange;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n,k;
  cin>>n>>k;
  vecint a(n);
  REP(i,n)cin>>a[i];
  double le = 1e-10;
  double gt = 1e10;
  REP(i,100) {
    double mid = (gt + le) / 2.;
    ll cnt = 0;
    REP(i,n) {
      cnt += (a[i] / mid) - 1e-10;
    }
    if (cnt <= k) {
      gt = mid;
    } else {
      le = mid;
    }
  }
  cout << static_cast<ll>(ceil(le)) << endl;
  return 0;
}


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

#define int long long
#define endl "\n"
#define REP(i,a,n) for(int i=a;i<n;++i)
#define REPR(i,a,n) for(int i=a;i>n;--i)
#define RUP(a,b) ((a+b-1)/(b))
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define MOD 1000000007

typedef long long ll;
typedef pair<int,int> Pii;
typedef tuple<int,int,int> Tiii;
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef vector<Pii> VPii;
typedef vector<string> Vs;

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;}
template<class T> void YesNo(T a) {cout<<(a?"Yes":"No")<<endl;}
template<class T> void YESNO(T a) {cout<<(a?"YES":"NO")<<endl;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a,b)*b;}
void uniq(Vi &v){sort(v.begin(),v.end()); v.erase(unique(v.begin(),v.end()),v.end());}

signed main(){cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);
    int n;
    cin>>n;
    cout<<n*(n-1)/2<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <map>
#include <set>
#include <cmath>
#include <queue>
using namespace std;

void solve(){
  int n, m; cin >> n >> m;
  vector<int> a(n);
  int sum = 0, ans = 0;
  for(int i = 0; i < n; i++){
    cin >> a[i];
    sum += a[i];
  }
  for(int i = 0; i < n; i++){
    if(a[i] * 4 * m >= sum) ans++;
  }
  if(ans >= m) cout << "Yes\n";
  else cout << "No\n";
  return;
}

int main(){
  solve();
  return 0;
}


Measured memory_bytes: 384
#include<iostream>

using namespace std;

int main(void)
{
	int n,ans;
	cin>>n;
	ans=10*10000;
	for(int i=1;i<=n;i++){
		ans=ans*1.05;
		if(ans%1000!=0){
			ans=ans-(ans%1000)+1000;
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 1160
#include<iostream>
#include <string.h>
#include <algorithm>
#include <string>
#include <math.h>
typedef long long ll;
using namespace std;

double gcd( double m, double n )
{
	// 引数に０がある場合は０を返す
	if ( ( 0 == m ) || ( 0 == n ) )
		return 0;
	
    double p=0;
	// ユークリッドの方法
	while( m > n )
	{
        m = m/2;
        p+=1;
	}
	return p;
}//gcd

int main()
{
    int a[3];
    memset(a,0,sizeof(a));
    for(int i = 0; i < 3; i++)
    {
        cin >> a[i];
    }
    sort (a,a+3);

    cout << a[0]+a[1] << endl;




    return 0;
}

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

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n, k;
	cin >> n >> k;
	map<int,int> a;
	for(int i = 0; i < n; ++i) {
		int x;
		cin >> x;
		++a[x];
	}
	int ans = 0;
	vector<int> v;
	for(auto i : a) v.push_back(i.second);
	sort(v.begin(), v.end());
	for(int i = 0; i < (int)v.size() - k; ++i) {
		ans += v[i];
	}
	cout << ans << endl;
}


Measured memory_bytes: 10744
#include "bits/stdc++.h"
// Begin Header {{{
#define all(x) (x).begin(), (x).end()
#define rep(i, s, n) for (i64 i = (s), i##_limit = (n); i < i##_limit; ++i)
#define repr(i, s, t) for (i64 i = (s), i##_limit = (t); i >= i##_limit; --i)
#define repc(i, s, t) for (i64 i = (s), i##_limit = (t); i <= i##_limit; ++i)
#define var(type, ...) \
    type __VA_ARGS__;  \
    read(__VA_ARGS__);
#ifndef DBG
#define dump(...)
#endif
using namespace std;
using i64 = int_fast64_t;
using pii = pair<i64, i64>;
template <class T, class U>
inline bool chmax(T &a, const U &b) {
    return b > a && (a = b, true);
}
template <class T, class U>
inline bool chmin(T &a, const U &b) {
    return b < a && (a = b, true);
}
constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;

template <class T>
inline vector<T> makeV(const T &initValue, size_t sz) {
    return vector<T>(sz, initValue);
}

template <class T, class... Args>
inline auto makeV(const T &initValue, size_t sz, Args... args) {
    return vector<decltype(makeV<T>(initValue, args...))>(
        sz, makeV<T>(initValue, args...));
}

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

inline void read() {}

template <class Head, class... Tail>
inline void read(Head &head, Tail &... tail) {
    cin >> head;
    read(tail...);
}

inline void print() { cout << "\n"; }

template <class Head, class... Tail>
inline void print(Head &&head, Tail &&... tail) {
    cout << head;
    if (sizeof...(tail)) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
inline ostream &operator<<(ostream &os, const vector<T> &vec) {
    static constexpr const char *delim[] = {" ", ""};
    for (const auto &e : vec) os << e << delim[&e == &vec.back()];
    return os;
}

template <class Container>
struct Rev {
    Container &x_;
    inline Rev(Container &x) : x_(x) {}
    inline auto begin() { return rbegin(x_); }
    inline auto end() { return rend(x_); }
};
// }}} End Header

int N;
vector<int> a;

vector<vector<int>> G;
vector<int> ans;

vector<i64> lis;

vector<i64> f(const vector<i64> &vec) {
    auto res = vec;
    for (auto &e : res)
        if (e == LINF) e = -1;
    return res;
}

bool visited[200010];
void dfs(int u) {
    if (visited[u]) return;
    visited[u] = true;

    const int i = lower_bound(all(lis), a[u]) - begin(lis);
    const auto tmp = lis[i];
    lis[i] = a[u];
    ans[u] = lower_bound(all(lis), LINF) - begin(lis);

    for (int ch : G[u]) {
        dfs(ch);
    }

    lis[i] = tmp;
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.setf(ios_base::fixed);
    cout.precision(12);

    read(N);
    a.resize(N);
    read(a);

    G.resize(N);
    rep(i, 0, N - 1) {
        var(int, u, v);
        --u, --v;
        G[u].push_back(v);
        G[v].push_back(u);
    }

    lis.assign(N + 2, LINF);

    ans.resize(N);
    dfs(0);

    rep(i, 0, N) { print(ans[i]); }

    return 0;
}


Measured memory_bytes: 25852
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <sstream>
#include <set>
using namespace std;

int main(){
  int n, k;
  while(cin >> n >> k){
    if(n == 0 && k == 0) break;
    string s;
    vector<string> data;
    for(int i = 0 ; i < n ; i++){
      cin >> s;
      data.push_back(s);
    }
    sort(data.begin(), data.end());
    set<int> res;
    do{
      int t = 0;
      for(int i = 0 ; i < k ; i++){
	for(int j = 0 ; j < data[i].size() ; j++){
	  t *= 10;
	  t += data[i][j] - '0';
	}
      }
      res.insert(t);
    }while(next_permutation(data.begin(), data.end()));
    
    cout << res.size() << endl;
  }
  return 0;
}

  
      

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

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

  string s;
  cin >> s;

  int cnt = count(s.begin(), s.end(), '1');

  cout << cnt << endl;

  return 0;
}

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

int main() {
    int n;cin>>n;
    int ans[6]={2,4,8,16,32,64};
    int answer=1;
    for(int i=1;i<n+1;i++) {
        for(int j=0;j<6;j++) {
            if(ans[j]<=i) answer=ans[j];
        }
    }
    cout<<answer<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i,n) for(int i=0, i##_len=(int)(n); i<i##_len; i++)
#define reps(i,n) for(int i=1 , i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;i--)
#define rreps(i,n) for(int i=((int)(n));i>0;i--)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define solve(a) ((a)?"Yes":"No")
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long , long long> P;
typedef vector<P> VP;
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;}
const long long INFLL = 1LL<<62;
const int INF = 1<<30;
const double PI=acos(-1);
int main(){
	double n;
	int ans=0;
	cin >>n;

	//cout<<n*2.0*PI<<endl;
	printf("%.8lf",n*2.0*PI);
}


Measured memory_bytes: 3788
import java.util.*;
import static java.lang.System.*;

public class Main {
	static Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		int[] a = new int[4];
		for (int i=0; i<4; i++) a[i] = sc.nextInt();
		int[] b = new int[2];
		for (int i=0; i<2; i++) b[i] = sc.nextInt();
		Arrays.sort(a);
		Arrays.sort(b);
		int total = 0;
		for (int i=3; i>=1; i--) {
			total += a[i];
		}
		out.println(total+b[1]);
	}
}


Measured memory_bytes: 26284
def main():
    
    a = int(input())
    b = int(input())

    if a == 1 and b == 2:
        print(3)
    elif a == 2 and b == 1:
        print(3)
    elif a == 2 and b == 3:
        print(1)
    elif a == 3 and b == 2:
        print(1)
    else:
        print(2)

if __name__ == '__main__':
    main()



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

using namespace std;
typedef long long ll;

#define REP(i, n) for (ll i = 0; i < (n); i++)
#define REPR(i, n) for (ll i = (n); i >= 0; i--)
#define FOR(i, m, n) for (ll i = (m); i < (n); i++)
#define FORR(i, m, n) for (ll i = (m); i >= (n); i--)
#define INF 1e9
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((ll)(x).size())
#define SORT(x) sort((x).begin(), (x).end())
#define dump(x) cerr << #x << " = " << (x) << endl
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
                      << " " << __FILE__ << endl

int main(int argc, char const *argv[])
{
    ll a, b;
    cin >> a >> b;
    ll res = b;
    if (a >= 6 && a <= 12)
        res = b / 2;
    else if (a <= 5)
        res = 0;
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 256