akhauriyash/Code-Regression huggingface dataset:
n,x = map(int, input().split())
a = list(map(int, input().split()))

ans = 0
for i in range(0,n-1):
    if a[i] + a[i+1] > x:
        rem = (a[i]+a[i+1]) - x
        if rem <= a[i+1]:
            ans += rem
            a[i+1] -= rem
        else:
            ans += rem
            a[i+1] = 0

print(ans)

Measured memory_bytes: 85808
N = int(input())

X = list(map(int,input().split()))

X.sort()
min_cost = float('inf')
sum_cost = 0
m = X[N-1]
for i  in range(m):
  i += 1
  for xi in X:
    sum_cost +=  (i-xi)**2
  if min_cost > sum_cost:
    min_cost = sum_cost
  sum_cost = 0
    
print(int(min_cost))

Measured memory_bytes: 3064
M, D = map(int, input().split())
ans = 0
for d in range(10, D+1):
    d1 = d % 10
    d2 = d // 10
    if d1 >= 2 and d2 >= 2 and d1*d2 <= M:
        #print(d1*d2, d1, d2)
        ans += 1
print(ans)

Measured memory_bytes: 38384
#pragma region cp-helper
#include <bits/stdc++.h>
using namespace std;
#define AC ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define ll long long
#define ull unsigned long long
#define ii pair<int, int>
#define lll pair<ll, ll>
#define vi vector<int>
#define vvi vector<vi>
#define vl vector<ll>
#define vll vector<lll>
#define vvl vector<vl>
#define vii vector<ii>
#define all(a) a.begin(), a.end()
#define qsort(a) sort(all(a))
#define qsortd(a) sort(all(a), greater<>())
#define qsortf(a, f) sort(all(a), f)
#define pb(n) push_back(n)
#define eb(n) emplace_back(n)
#define pp(a, b) emplace_back(make_pair(a, b))
#define umap unordered_map
#define nl '\n'
#define fileio(in, out) freopen(in, "r", stdin); freopen(out, "w", stdout)
#define qmod %mod
#define pls int
#define give main()
const int mod = 1000000007;
#pragma endregion


pls give {
    AC;
    ll n;
    cin >> n;
    vector<pair<string, ii>> arr(n);
    for (int i=0; i<n; i++) {
        cin >> arr[i].first >> arr[i].second.first;
        arr[i].second.first = -arr[i].second.first;
        arr[i].second.second = i+1;
    }
    qsort(arr);
    for (auto i : arr) cout << i.second.second << nl;


}

Measured memory_bytes: 256
//code by lynmisakura.wish to be accepted
/****************************/
#include<set>
#include<queue>
#include<stack>
#include<bitset>
#include<vector>
#include<stdio.h>
#include<iostream>
#include<algorithm>
using namespace std;
/***************************/
typedef long long ll;
typedef pair<int,int> pi;
typedef vector<pair<int,int>> vpi;

const long long Mod = 998244353;
const long long mod = 1000000007;
const long long INF = 10000000000000;

#define pb push_back
#define mp make_pair
#define mins(x,y) x = min(x,y)
#define maxs(x,y) x = max(x,y)
#define all(x) (x).begin(),(x).end()
#define Rep(n) for(int i = 0;i < n;i++)
#define rep(i,n) for(int i = 0;i < n;i++)
	
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll qp(ll a, ll b) { int ans = 1; do { if (b & 1)ans = 1ll * ans*a; a = 1ll * a*a; } while (b >>= 1); return ans; }
ll qp(ll a, ll b, int mo) { int ans = 1; do { if (b & 1)ans = 1ll * ans*a%mo; a = 1ll * a*a%mo; } while (b >>= 1); return ans; }

#define _GLIBCXX_DEBUG
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
/***************************/
/*
・変数重複（特にfor文のネストが離れてる場合のindexダブりに注意）
・配列の境界値のindexに注意せよ
・逆for文のデクリメントに注意(i++にしてないか？)
・boolの真偽は間違えてないか？/ == になってるか？
・オーバーフローは大丈夫か？
*/
//最頻値とランレングス圧縮

int main(void){
	string s;cin >> s; 
	int ans = s.size();
	bool al = true;
	for(int i = 1;i < s.size();i++){
		if(s[i] != s[i-1]) al = false;
	}
	if(al){
		cout << 0 << endl; return 0;
	}
	string cp = s;
	for(int i = 0;i < 26;i++){
		s = cp;
		char t = 'a' + i;
		int c = 0;
		while(true){
			c++;
			string p = "";
			for(int j = 0;j < s.size()-1;j++){
				if(s[j] == t || s[j+1] == t){
					p.push_back(t);
				}else{
					p.push_back(s[j]);
				}
			}
			s = p;
			bool check = true;
			for(int j = 0;j < s.size();j++){
				if(s[j] != t){ check = false; break;}
			}
			if(check){
				ans = min(ans,c);
				break;
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
if __name__ == '__main__':
    n = int(input())
    x = list(map(int, input().split()))
    p = []

    for i in range(100):
        cnt = 0
        for j in range(n):
            cnt = cnt + (x[j]-i)**2
        p.append(cnt)

    print(sorted(p)[0])


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

char Array[2000][2000];
int count;

void DFS(int h,int w,char c){

  if(Array[h][w] != c || Array[h][w] == '.'){
    return;
  }

  char tmp=Array[h][w];

  Array[h][w] = '.';

  DFS(h-1,w,tmp);
  DFS(h,w+1,tmp);
  DFS(h+1,w,tmp);
  DFS(h,w-1,tmp);

}

int main(){
    int H,W;

    while(1){
      cin >> H >> W;

      if(H == 0 && W == 0){
        break;
      }
      for(int i=1;i<=H;i++){
        for(int j=1;j<=W;j++){
          cin >> Array[i][j];
        }
      }

      for(int i=1;i<=H;i++){
        for(int j=1;j<=W;j++){
          if(Array[i][j] != '.'){
            count++;
            DFS(i,j,Array[i][j]);
          }
        }
      }
      cout << count << endl;

      for(int i=1;i<=H;i++){
        for(int j=1;j<=W;j++){
          Array[i][j] = '.';
        }
      }
      count = 0;
  }
    return 0;
}

Measured memory_bytes: 3564
def check_prime(k):
    '''
    素数の時1、合成数の時0を返す
    '''
    if k == 1:return 0
    num = int(k ** 0.5 // 1)
    for i in range(2, num + 1):
        if k % i == 0:return 0
    return 1

q = int(input())
lr = []
l_min = 10 ** 9
r_max = 0
for i in range(q):
    l, r = map(int,input().split())
    lr.append((l, r))
    if l < l_min:l_min = l
    if r > r_max:r_max = r

pre_cal = [0] * (r_max - l_min + 2)
dic = {}#一度素数と判定したもの
for num in range(l_min, r_max + 1):
    pre_cal[num - l_min + 1] = pre_cal[num - l_min]
    if num % 2 == 0:continue
    if not check_prime(num):continue
    dic[num] = 1
    temp = (num + 1) // 2

    if dic.get(temp, 0):
        pre_cal[num - l_min + 1] = pre_cal[num - l_min + 1] + 1 if num != l_min else 1
    else:
        if check_prime(temp):
            dic[temp] = 1
            pre_cal[num - l_min + 1] = pre_cal[num - l_min + 1] + 1 if num != l_min else 1

for l, r in lr:
    ans = pre_cal[r - l_min + 1] - pre_cal[l - l_min]
    print(ans)

#print(pre_cal)

Measured memory_bytes: 62168
#include<stdio.h>

int main(){
long int N;
scanf ("%d",&N);
long long int A[N];
long long int B = 1;
long long int x = 1000000000000000000;

for (int i = 0; i < N; i++ ){
scanf ("%lld",&A[i]);
if (A[i]==0){
    printf ("0\n");
    return 0; 
}
}
for (int i = 0; i< N; i++){
    if ( x < A[i] ){
        printf ("-1\n"); 
        return 0;
    }
     else {
	x= x/ A[i];
	B = B*A[i];
}
}
printf ("%lld\n",B);
return 0;
}

Measured memory_bytes: 2932
A=input()
a=int(A)
b=round(a*(1/2))
n2=1
for i in range(2,b):
    for x in range(2,b):
        if n2 <= a:
            n1=(i)**(x)
            if n2 <= n1 and n1 <= a:
                n2 = n1
                #print(n2)
                n1
print(n2)

Measured memory_bytes: 3060
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		String[] line = sc.nextLine().split(" ");
		int N = Integer.parseInt(line[0]);
		int M = Integer.parseInt(line[1]);
		
		ArrayList <Shop> al = new ArrayList<>();
		
		int[] A = new int[N];
		int[] B = new int[N];
		for(int i= 0;i<N;i++) {
			line = sc.nextLine().split(" ");
			al.add(new Shop(Integer.parseInt(line[0]),Integer.parseInt(line[1]))); 
		}
		sc.close();
		
		al.sort((s1,s2)-> s1.a - s2.a );
		
		long amount =0;
		for(Shop s:al) {
			if(s.b<M) {
				amount += (long)s.a*s.b;
				M -= s.b;
			}else {
				amount += (long)s.a*M;
				break;
			}
		}
		
		System.out.println(amount);

	}

}

class Shop{
	int a;
	int b;
	
	public Shop(int a, int b) {
		this.a = a;
		this.b = b;
	}
}

Measured memory_bytes: 126944
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <queue>
#include <math.h>

using namespace std;

int main() {
	int n, y;
	cin >> n >> y;

	int a, b, c;
	// a + b + c = n
	// a * 10000 + b * 5000 + c * 1000 = y　があり得るかどうか

	bool can = false;

	for (int i = 0; i <= n; i++) {
		for (int j = 0; j <= n - i; j++) {
			c = n - i - j;

			if (c >= 0 && i*10000+j*5000+c*1000 == y) {
				a = i;
				b = j;
				can = true;
				break;
			}
		}
		if (can)
			break;
	}
	
	if (can)
		cout << a << " " << b << " " << c << endl;
	else
		cout << "-1 -1 -1" << endl;
}

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

int main(){
  int a, b ,c , y;
  y = 0;
  cin >> a >> b >> c;
  for(int x = a; x <= b; x++){
    if ( c % x == 0)  y++;
  }
cout << y << endl;
 return 0;
}


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

int slime(string & s)
{
	if (s.size() <= 1) return s.size();
	int pre = 0;
	for (size_t i = 1; i < s.size(); ++i){
		if (s[i] != s[pre]){
			s[++pre] = s[i];
		}
	}

	return pre + 1;
}

int main()
{
	int n;
	cin >> n;
	string s;
	cin >> s;
	int result = slime(s);
	cout << result << endl;

	return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    int n;
    cin >> n;
    for (int i = 0; i <= n; ++i) {
        if(i*108/100 == n){
            cout << i << "\n";
            return 0;
        }
    }
    puts(":(");
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <queue>
#include <climits>
#include <set>
#include <map>
#include <stack>
#include <iomanip>
#include <tuple>
#define ll long long
using namespace std;
using graph =vector<vector<ll>>;
/*階乗*/
ll factorial(ll n){
    if(n==0){
        return 1;
    }
    else{
        return n*factorial(n-1)%1000000007;
    }
}

/* ユークリッドの互除法 最大公約数*/
/*ll gcd(ll a, ll b) {
	ll r;
	r = a % b;
	while (r != 0) {
		a = b;
		b = r;
		r = a % b;
	}
	return b;
}
*/


/*最小公倍数*/
/*
ll lcm(ll a,ll b){
	return a/gcd(a,b)*b;
}
*/

/*二点間の距離*/
double dist(pair<double,double> a,pair<double,double> b){
	return sqrt(pow((a.first - b.first) ,2) + pow((a.second - b.second),2));
}

//繰り返し自乗法
double ism(double aa,ll p){
    double ap=aa;
    double ans=1;
    while(p>0){
        //cout<<"p="<<p<<",ap="<<ap<<endl;
        if(p&1){//奇数が真
            ans*=ap;
        }
        p/=2;
        ap=ap*ap;
    }
    return ans;

}
//繰り返し自乗法(アマリトリバージョン)
ll ismm(ll aa,ll p,ll m){
    ll ap=aa;
    ll ans=1;
    while(p>0){
        //cout<<"p="<<p<<",ap="<<ap<<endl;
        if(p&1){//奇数が真
            ans=(ans*ap)%m;    
        }
        p/=2;              
        ap=(ap*ap)%m;
    }
    return ans;

}
/*
ll solve(ll i,ll m,vector<ll>t,ll n){
    if(m==0){
        return 1;
    }
    if(i>=n){
        return 0;
    }
    
    
    cout<<i+1<<" "<<m<<endl;
    cout<<i+1<<" "<<m-t[i]<<endl;
    ll res=solve(i+1,m,t,n)||solve(i+1,m-t[i],t,n);
    return res;
}
*/

//小数点12桁
struct all_init
{
    all_init()
    {
        cout << fixed << setprecision(12);
    }
} All_init;


int main()
{
    ll n,w;
    cin>>n>>w;
    vector<ll>v(n,0),we(n,0);
    vector<vector<ll>>dp(n+1,vector<ll>(10001,0));
    for(ll i=0;i<n;i++){
        cin>>v[i]>>we[i];
    }
    for(ll j=0;j<w;j++){
        dp[0][j]=0;
    }

    for(ll i=0;i<n;i++){
        for(ll j=0;j<=w;j++){
            if(j-we[i]>=0){
                dp[i+1][j]=max(dp[i][j-we[i]]+v[i],dp[i][j]);
            }
            else{
                dp[i+1][j]=dp[i][j];
            }
        }
    }
    cout<<dp[n][w]<<endl;



    
    
    
    
}


Measured memory_bytes: 10808
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <map>
#include <functional>
#include <cmath>
#include <cstdint>
#include <mutex>
#include <thread>
#include <bitset>
#include <utility>

using namespace std;

int main()
{
	unsigned long long  int x, y, a, b, c;
	vector<pair<unsigned long long  int, int>> w;

	cin >> x >> y >> a >> b >> c;
	for (unsigned long long int i = 0; i < a; i++)
	{
		pair<unsigned long long  int, int> tmp;
		cin >> tmp.first;
		tmp.second = 0;
		w.push_back(tmp);
	}
	for (unsigned long long int i = 0; i < b; i++)
	{
		pair<unsigned long long  int, int> tmp;
		cin >> tmp.first;
		tmp.second = 1;
		w.push_back(tmp);
	}
	for (unsigned long long int i = 0; i < c; i++)
	{
		pair<unsigned long long  int, int> tmp;
		cin >> tmp.first;
		tmp.second = 2;
		w.push_back(tmp);
	}
	sort(w.begin(), w.end(), greater<pair<unsigned long long  int, int>>());

	unsigned long long  int x_cnt = 0, y_cnt = 0, z_cnt = 0;
	unsigned long long  int sum = 0;
	for (unsigned long long int i = 0;; i++)
	{
		if (w[i].second == 0)
		{
			// 赤リンゴ
			if (x_cnt < x)
			{
				x_cnt++;
				sum += w[i].first;
			}
		}
		else if (w[i].second == 1)
		{
			// 青りんご
			if (y_cnt < y)
			{
				y_cnt++;
				sum += w[i].first;
			}
		}
		else
		{
			// 無色
			z_cnt++;
			sum += w[i].first;
		}

		if (x_cnt + y_cnt + z_cnt >= x + y)
			break;
	}
	cout << sum << endl;
	return 0;
}


Measured memory_bytes: 10604
#include <stdio.h>

int main(void)
{
	int a,b;
	char op;
	while(1){
		scanf("%d %c %d",&a,&op,&b);
		if(op=='+'){
			printf("%d\n",a+b);
		}
		else if(op=='-'){
			printf("%d\n",a-b);
		}
		else if(op=='*'){
			printf("%d\n",a*b);
		}
		else if(op=='/'){
			printf("%d\n",a/b);
		}
		else if(op=='?'){
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 600
#include <iostream>
#include <string.h>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <functional>
#include <cassert>
#include <utility>
#include <stack>
#include <queue>
using namespace std;
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,n1,n2) for(int i=n1;i<n2;i++)
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
typedef pair<int,int> Pi;
typedef long long int ll;
const int INF=(ll)(1<<30)-1;
const ll INFl=(ll)9223372036854775807;
const int MAX=10000;
const ll MOD=(ll)1e9+7;
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;}

string s;
int main(){
	cin>>s;
	int t=0;
	for(int i=0;i<s.size();i++){
		if(i%2==0&&s[i]=='0'){
			t++;
		}
		if(i%2==1&&s[i]=='1'){
			t++;
		}
	}
	cout<<min(t,s.size()-t)<<endl;
	return 0;
}

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

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

const int N = 100005;
const int M = 200005;
int n, a[N], f[M];

void update(int i, int x, int sz){
	// cout<<i<<endl;
	while(i <= sz){
		f[i] += x;
		i += i&(-i);
	}
}

int query(int i){
	int ret = 0;
	while(i){
		ret += f[i];
		i &= (i - 1);
	}
	return ret;
}

ll count(int m){
	int sz = 2*(n + 1);
	for(int i = 0; i <= sz; i++){
		f[i] = 0;
	}
	ll ret = 0;
	update(n + 1, 1, sz);
	int cur = 0;
	for(int i = 1; i <= n; i++){
		if(a[i] <= m)cur--;
		else cur++;
		ret += i - query(n + 1 + cur);
		update(n + 1 + cur, 1, sz);
 	}
 	return ret;
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cout<<setprecision(32);

	cin>>n;
	for(int i = 1; i <= n; i++){
		cin>>a[i];
	}
	ll req = n*1LL*(n + 1)/2;
	req = req/2 + 1;
	int lo = 1, hi = 1e9;
	while(lo < hi){
		int mi = lo + (hi - lo)/2;
		if(req <= count(mi))hi = mi;
		else lo = mi + 1;
	}
	cout<<lo<<'\n';


	return 0;
}

Measured memory_bytes: 1408
//競技プログラミング用のテンプレート
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <string>
#include <math.h>

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

using namespace std;
using ll = long long int;
using p = pair<int, int>;
using pl = pair<ll, ll>;
using v = vector<int>;
using vd = vector<double>;
using vs = vector<string>;
using vl = vector<ll>;

int main()
{
    int n, m;
    cin >> n >> m;
    vl a(n);
    rep(i, n)
    {
        cin >> a[i];
    }
    priority_queue<ll> pq;
    rep(i, n)
    {
        pq.push(a[i]);
    }
    rep(i, m)
    {
        ll temp = pq.top();
        pq.pop();
        temp = temp / 2;
        pq.push(temp);
    }
    ll result = 0;
    rep(i, n)
    {
        result += pq.top();
        pq.pop();
    }
    cout << result << endl;
}

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

#define rep(X,N) for(int X = 0; X < (N); X++)
#define PI (acos(-1.0))
#define MODN 1000000007
#define MODN2 998244353
#define ALL(V) (V).begin(),(V).end()
#define INT_MAX_HALF (INT_MAX / 2)
#define EPS (1e-10)

using namespace std;
typedef long long ll;

int main(){

    ll a;
    string b;
    cin >> a >> b;

    ll ans = 0;

    ans += a * (ll)(b[0] - '0') * 100;
    ans += a * (ll)(b[2] - '0') * 10;
    ans += a * (ll)(b[3] - '0');

    cout << ans / 100 << endl;

    return 0;
}


Measured memory_bytes: 3624
#include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<algorithm>
#include<functional>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cassert>
using namespace std;

#define mind(a,b) (a>b?b:a)
#define maxd(a,b) (a>b?a:b)
#define absd(x) (x<0?-(x):x)
#define pow2(x) ((x)*(x))
#define rep(i,n) for(int i=0; i<n; ++i)
#define repr(i,n) for(int i=n-1; i>=0; --i)
#define repl(i,s,n) for(int i=s; i<=n; ++i)
#define replr(i,s,n) for(int i=n; i>=s; --i)
#define repf(i,s,n,j) for(int i=s; i<=n; i+=j)
#define repe(e,obj) for(auto e : obj)

#define SP << " " <<
#define COL << " : " <<
#define COM << ", " <<
#define ARR << " -> " <<
#define PNT(STR) cout << STR << endl
#define POS(X,Y) "(" << X << ", " << Y << ")"
#define DEB(A) " (" << #A << ") " << A
#define DEBREP(i,n,val) for(int i=0; i<n; ++i) cout << val << " "; cout << endl
#define ALL(V) (V).begin(), (V).end()
#define INF 1000000007
#define INFLL 100000000000000007LL
#define EPS 1e-9

typedef unsigned int uint;
typedef unsigned long ulong;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
//typedef pair<ll, ll> P;
typedef pair<P, int> PI;
typedef pair<int, P> IP;
typedef pair<P, P> PP;
typedef priority_queue<P, vector<P>, greater<P> > pvqueue;

template<class T>
class DequeSlide {
  T *data;
  int *deq;
  int n, l, s, t;
  int cur;

public:
  DequeSlide(int n, int l) {
    data = new T[n];
    deq = new int[n];
    this->n = n;
    this->l = l;
    s = t = cur = 0;
  }

  void push(T x) {
    if(s<t && deq[s] == cur-l) s++;
    while(s<t && data[deq[t-1]] >= x) t--;
    deq[t++] = cur;
    data[cur++] = x;
  }

  T get() {
    assert(s<t);
    return data[deq[s]];
  }

  void debug() {
    cout << s << " " << t << " [";
    repl(i, s, t-1) {
      cout << " " << data[deq[i]];
    }
    cout << " ]" << endl;
  }

};

#define N 2000
int main() {
  ll n, x; cin >> n >> x;
  ll A[N], ans = 0;
  rep(i, n) {
    cin >> A[i];
    ans += A[i];
  }
  repl(l, 2, n) {
    DequeSlide<ll> deq(2*n, l);
    ll res = 0;
    rep(i, n) {
      deq.push(A[i]);
    }
    rep(i, n) {
      deq.push(A[i]);
      res += deq.get();
    }
    ans = mind(ans, (res+(l-1)*x));
  }
  cout << ans << endl;
  return 0;
}


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

#define NDEBUG
#include <cassert>


typedef long long ll;
typedef long double Double;
typedef unsigned long long ull;
typedef pair<int,int> ii;
typedef pair<ll,ll> llll;
typedef pair<double,double> dd;

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ii> vii;
typedef vector<vector<ii>> vvii;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<long double> vD;

#define sz(a)  int((a).size())
#define pb  push_back
#define eb  emplace_back
#define FOR(var,from,to) for(int var=(from);var<=(to);++var)
#define rep(var,n)  for(int var=0;var<(n);++var)
#define rep1(var,n)  for(int var=1;var<=(n);++var)
#define repC2(vari,varj,n)  for(int vari=0;vari<(n)-1;++vari)for(int varj=vari+1;varj<(n);++varj)
#define ALL(c)  (c).begin(),(c).end()
#define RALL(c)  (c).rbegin(),(c).rend()
#define tr(i,c)  for(auto i=(c).begin(); i!=(c).end(); ++i)
#define found(s,e)  ((s).find(e)!=(s).end())
#define mset(arr,val)  memset(arr,val,sizeof(arr))
#define mid(x,y) ((x)+((y)-(x))/2)
#define IN(x,a,b) ((a)<=(x)&&(x)<=(b))
#define cons make_pair

#define PQ(T) priority_queue<T>
#define RPQ(T) priority_queue<T,vector<T>,greater<T>>

template<class T> inline void amin(T & a, T const & b) { a = min(a, b); }
template<class T> inline void amax(T & a, T const & b) { a = max(a, b); }

inline ll square(ll x) { return x * x; }
inline ll gcd(ll a, ll b) { while(a) swap(a, b%=a); return b; }
template <typename T>
inline T mod(T a, T b) { return ((a % b) + b) % b; }



ll solve(int N,int M,vi& a,vi& b) {
    priority_queue<ii, vii, greater<ii>> pq;
    rep(i,N) pq.emplace(a[i], b[i]);

    int rest = M;
    ll ans = 0;
    while (!pq.empty()){
        if (rest == 0) break;
        ii t = pq.top(); pq.pop();
        int price=t.first, num=t.second;
        int tobuy = min(num, rest);
        ans += (ll)price * tobuy;
        rest -= tobuy;
    }
    return ans;
}

int main() {
    int N, M; scanf("%d%d", &N, &M);
    vi a(N),b(N);
    rep(i,N) scanf("%d%d", &a[i], &b[i]);
    cout << solve(N,M,a,b) << endl;
    return 0;
}


Measured memory_bytes: 2168
#include<stdio.h>
#include<string.h>
int main(void)
{
    int q,a,b,i,j,num;
    char str[1001],S[8],C[1001];
    scanf("%s",str);
    scanf("%d",&q);
    for(j=0;j<1001;j++){if(str[j]=='\0'){break;}}
    num=j;
    for(i=0;i<q;i++)
    {
        for(j=0;j<1001;j++){C[j]='\0';}
        scanf("%s %d %d",S,&a,&b);
        if(!strcmp(S,"print")){
            for(j=a;j<=b;j++){printf("%c",str[j]);}
            printf("\n");
            continue;
        } else if(!strcmp(S,"reverse")){
            for(j=a;j<=b;j++){C[j]=str[b-j+a];}
            for(j=a;j<=b;j++){str[j]=C[j];}
            continue;
        } else if(!strcmp(S,"replace")){
            scanf("%s",C);
            for(j=a;j<=b;j++){str[j]=C[j-a];}
            continue;
        }
    }
    return 0;
}


Measured memory_bytes: 2052
#include <iostream>
#include <map>
using namespace std;
 
int main()
{
    int n , T , c , t ;
    map <int , int> mp;
    cin >> n >> T ;
    while(n--){
        cin>>c>>t;
        mp[c]=t;
    }
    int ans = -1;
    map <int , int> :: iterator it ;
    for(it = mp.begin() ; it!=mp.end() ; it++){
        if(it->second <= T){
            ans = it->first;
            break;
        }
    }
    if(ans == -1) cout<<"TLE"<<endl;
    else cout << ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl; 
#define INF 1000000000
#define mod 1000000007
typedef long long ll;
const ll LINF = 1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

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

    string s;cin>>s;
    int k;cin>>k;

    //各文字に対してaにするか操作しないかしかない
    rep(i,s.size()){
        if(s[i]=='a') continue;
        int cost=1+('z'-s[i]);
        if(k>=cost){
            k-=cost;
            s[i]='a';
        }
    }
    if(k>0){
        s[s.size()-1]='a'+(s[s.size()-1]-'a'+k)%26;
    }
    cout<<s<<endl;
    return 0;
}


Measured memory_bytes: 592
n,x = gets.split.map(&:to_i)
m =[]
count = 0
for i in 0..n - 1
    m[i] = gets.to_i
end
m = m.sort!
for i in 0..n - 1
   x = x - m[i]
    count += 1
end
loop{
       if x < m[0]
        break
    end 
    x = x - m[0]
    count += 1
}
puts count
  

Measured memory_bytes: 1788
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <cstdio>
#include <numeric>
#include <iomanip>

using namespace std;

using ll = long long;

ll cnt[10001];

int main()
{
    ll N;
    cin >> N;
    for(ll x = 1;x < 100;x++)
        for(ll y = 1;y <100;y++)
            for(ll z = 1;z < 100;z++)
            {
                ll s = x*x+y*y+z*z+x*y+y*z+z*x;
                if(s <= N)
                {
                    cnt[s]++;
                }
            }

    for(ll i = 1;i <= N;i++)
    {
        cout << cnt[i] <<endl;
    }

    return 0;
}

Measured memory_bytes: 3164
import fractions
a,b,c,d=map(int,input().split())
a-=1
y=int(c*d/fractions.gcd(c,d))

p=a-((a//c)+(a//d)-(a//y))

q=b-((b//c)+(b//d)-(b//y))

print(int(q-p))

Measured memory_bytes: 5432
// ConsoleApplication1.cpp : コンソール アプリケーションのエントリ ポイントを定義します。
//

#include<cmath>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<iostream>
#include<queue>
typedef long long  i64;
using namespace std;
int n;
int m;
int a[2000];
int b[2000];
i64 c[2000];
struct Edge {
	int src, dst;
	i64 cost;
public:
	Edge(int src, int dst, i64 cost) {
		this->src = src;
		this->dst = dst;
		this->cost = cost;
	}
};
struct State {
	int cur;
	i64 cost;
public:State(int cur, i64 cost) {
	this->cur = cur;
	this->cost = cost;
}
};
int main() {
	scanf("%d%d", &n, &m);
	for (int i = 0; i < m; ++i) {
		scanf("%d%d%lld", a + i, b + i, c + i);
		--a[i];
		--b[i];
		c[i] *= -1;
	}
	vector<vector<Edge>> g;
	vector<vector<int>> rev;
	g.resize(n);
	rev.resize(n);
	for (int i = 0; i < m; ++i) {
		Edge e = { a[i],b[i],c[i] };
		g[a[i]].push_back(Edge(a[i], b[i], c[i]));
		rev[b[i]].push_back(a[i]);
	}

	i64 d[1000];
	for (int i = 0; i < n; ++i) {
		d[i] = 1LL << 60;
	}

	d[0] = 0;
	vector<queue<State>> pend;
	pend.resize(n + 2);
	pend[0].push(State(0, 0));
	for (int i = 0; i < n; ++i) {
		while (!pend[i].empty()) {
			State s = pend[i].front();
			pend[i].pop();
			if (d[s.cur] < s.cost)
				continue;
			for (Edge e : g[s.cur]) {
				if (d[e.dst] > d[s.cur] + e.cost) {
					d[e.dst] = d[s.cur] + e.cost;
					State ns = { e.dst, d[e.dst] };
					pend[i + 1].push(ns);
				}
			}
		}
	}
	bool reach[1000];
	queue<int> q;
	q.push(n - 1);
	reach[n - 1] = true;
	while (q.size() > 0) {
		int v = q.front();
		q.pop();
		for (int dst : rev[v]) {
			if (!reach[dst]) {
				reach[dst] = true;
				q.push(dst);
			}
		}
	}
	bool f = false;
	while (!pend[n].empty()) {
		State s = pend[n].front();
		pend[n].pop();
		f |= reach[s.cur];
	}
	if (!f) {
		printf("%lld\n", -d[n - 1]);
	}
	else {
		printf("inf\n");
	}


	return 0;
}

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

int main() {
  char c;
  cin >> c;
  if(c == 'a' || c == 'e' ||c == 'i' ||c == 'o' ||c == 'u' ){
    cout << "vowel" <<endl;
  }else{
    cout << "consonant" <<endl;
  }
}

Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <x86intrin.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define V vector
template <typename T> bool chmin(T &a, const T &b) {if(a > b){a = b; return true;} return false;}
template <typename T> bool chmax(T &a, const T &b) {if(a < b){a = b; return true;} return false;}
template<typename A, size_t N, typename T> void Fill (A (&array)[N], const T & val) {fill ((T*)array, (T*)(array+N), val);}
V<int> dx = {-1, 1,  0, 0, -1, -1,  1, 1};
V<int> dy = { 0, 0, -1, 1, -1,  1, -1, 1};

// UnionFind
// coding: https://youtu.be/TdR816rqc3s?t=726
// comment: https://youtu.be/TdR816rqc3s?t=6822
struct UnionFind {
    vector<int> d;
    UnionFind(int n=0): d(n,-1) {}
    int find(int x) {
        if (d[x] < 0) return x;
        return d[x] = find(d[x]);
    }
    bool unite(int x, int y) {
        x = find(x); y = find(y);
        if (x == y) return false;
        if (d[x] > d[y]) swap(x,y);
        d[x] += d[y];
        d[y] = x;
        return true;
    }
    bool same(int x, int y) { return find(x) == find(y);}
    int size(int x) { return -d[find(x)];}
};

int main () {
    int n, m; cin >> n >> m;
    V<int> p(n);
    rep(i, n) cin >> p[i], p[i]--;
    UnionFind uf(n);
    rep(i, m) {
        int x, y; cin >> x >> y; x--; y--;
        uf.unite(x, y);//移動可能なindexをグループ化する
    }
    int ans = 0;
    rep(i, n) {//いまi番目にあるp[i]をp[i]番目に持ってこれるか
        if (uf.same(i, p[i])) ans++;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3888
//初めはvectorで実装したが、listにしたら早くなりTLEが消えた
//listの存在を知った(双方向連結リスト)
//先頭または末尾へのアクセスが多い場合はlistを使う
//実際にstructで実装するとちょっど面倒かも

#include<list>
#include<iostream>
#include<string>

using namespace std;

//参照しなければ
void insertx(int x,list<int>& v){
  v.push_front(x);
}

void deletex(int x,list<int>& v){
  for(auto i=v.begin();i!=v.end();i++){
    if(*i==x){v.erase(i);break;}
  }
}

void deleteFirst(list<int>& v){
  v.pop_front();
}

void deleteLast(list<int>& v){
  v.pop_back();
}

int main(){
  int n;cin >> n;
  string s;int c;
  list<int> v;
  for(int i=0;i<n;i++){
    cin >> s;
    if(s=="insert"){
      cin >> c;insertx(c,v);
    }else if(s=="delete"){
      cin >> c;deletex(c,v);
    }else if(s=="deleteFirst"){
      deleteFirst(v);
    }else{
      deleteLast(v);
    }
  }
  //線形リストではポインタが連続してるとは限らないので、不等号は使えない
  for(auto i=v.begin();i!=v.end();i++){
    if(i==--v.end()) cout << *i << endl;
    else cout << *i << " ";
  }
}



Measured memory_bytes: 34368
#include <bits/stdc++.h>
#define R register
#define mp make_pair
#define ll long long
#define pii pair<int, int>
using namespace std;
const int mod = 998244353;

int n, m, x;

inline int addMod(int a, int b) {
	return (a += b) >= mod ? a - mod : a;
}

inline ll quickpow(ll base, ll pw) {
	ll ret = 1;
	while (pw) {
		if (pw & 1) ret = ret * base % mod;
		base = base * base % mod, pw >>= 1;
	}
	return ret;
}

template <class T>
inline void read(T &x) {
	x = 0;
	char ch = getchar(), w = 0;
	while (!isdigit(ch)) w = (ch == '-'), ch = getchar();
	while (isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
	x = w ? -x : x;
	return;
}

int main() {
	read(n), read(m);
	while (m--) read(x), n -= x;
	printf("%d\n", n >= 0 ? n : -1);
	return 0;
}

Measured memory_bytes: 3764
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,m;
  cin>>n>>m;
  vector<int> ac(n);
  vector<int> wa(n);
  for(int i=0;i<m;i++){
    int p;
    string s;
    cin>>p>>s;
    if(s=="AC")
      ac.at(p-1)=1;
    if(s=="WA"&&ac.at(p-1)==0)
      wa.at(p-1)++;
  }
  int acs=0;
  int was=0;
  for(int i=0;i<n;i++){
    acs+=ac.at(i);
    was+=ac.at(i)*wa.at(i);
  }
  cout<<acs<<" "<<was<<endl;
}

Measured memory_bytes: 1024
"""
N = list(map(int,input().split()))
S = [str(input()) for _ in range(N)]
S = [list(map(int,list(input()))) for _ in range(h)] 
print(*S,sep="")
"""

import sys
sys.setrecursionlimit(10**6)
input = lambda: sys.stdin.readline().rstrip()

n = int(input())
print((n*(n+1))//2)

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


int main(){
    int n;
    cin >> n;
    set<string> s;
    string si;
    rep(i, n){
        cin >> si;
        s.insert(si);
    }
    cout << s.size() << endl;
    return 0;
}

Measured memory_bytes: 19120
#include <algorithm>
#include <cassert>
#include <chrono>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<double, int> pdi;
typedef pair<int, pii> pipii;
typedef vector<vector<ll>> matrix;

int bit[1000000];
void upd(int idx) {
  idx += 2;
  while(idx < 1000000) {
    bit[idx]++;
    idx += idx & -idx;
  }
}
int qry(int idx) {
  idx += 2;
  int ret = 0;
  while(idx) {
    ret += bit[idx];
    idx -= idx & -idx;
  }
  return ret;
}

ll l[1000000];
void solve() {
  map<ll, int> dp;
  int n;
  cin >> n;
  ll k;
  cin >> k;
  for(int i = 1; i <= n; i++) {
    cin >> l[i];
    l[i] += l[i-1] - k;
  }
  {
    set<ll> s;
    s.insert(0);
    for(int i = 1; i <= n; i++) s.insert(l[i]);
    int idx = 0;
    for(ll out: s) dp[out] = idx++;
  }
  ll ret = 0;
  upd(dp[0]);
  for(int i = 1; i <= n; i++) {
    ret += qry(dp[l[i]]);
    upd(dp[l[i]]);
  }
  cout << ret << "\n";
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);
  solve();
}


Measured memory_bytes: 27776
#![allow(unused_macros)]
#![allow(dead_code)]
#![allow(unused_imports)]

use itertools::Itertools;

const U_INF: usize = 1 << 60;
const I_INF: isize = 1 << 60;

fn main() {
    let mut sc = Scanner::new();
    let mut b = sc.next_usize();
    let mut a = sc.next_usize();

    let mut v = vec![vec!['#'; 100]; 100];
    for i in 0..50 {
        for j in 0..100 {
            v[i][j] = '.';
        }
    }

    a -= 1;
    b -= 1;

    let i = a / 50;
    let j = a % 50;
    for ii in 0..i {
        for jj in 0..50 {
            v[ii * 2][jj * 2] = '#';
        }
    }

    for jj in 0..j {
        v[i * 2][jj * 2] = '#';
    }

    let i = b / 50;
    let j = b % 50;
    for ii in 0..i {
        for jj in 0..50 {
            v[ii * 2 + 51][jj * 2] = '.';
        }
    }

    for jj in 0..j {
        v[i * 2 + 51][jj * 2] = '.';
    }

    println!("{} {}", 100, 100);
    v.into_iter()
        .for_each(|v| println!("{}", v.into_iter().collect::<String>()));
}

pub struct Scanner {
    buf: std::collections::VecDeque<String>,
}

impl Scanner {
    pub fn new() -> Self {
        Self {
            buf: std::collections::VecDeque::new(),
        }
    }

    fn scan_line(&mut self) {
        let mut flag = 0;
        while self.buf.is_empty() {
            let mut s = String::new();
            std::io::stdin().read_line(&mut s).unwrap();
            let mut iter = s.split_whitespace().peekable();
            if iter.peek().is_none() {
                if flag >= 5 {
                    panic!("There is no input!");
                }
                flag += 1;
                continue;
            }

            for si in iter {
                self.buf.push_back(si.to_string());
            }
        }
    }

    pub fn next<T: std::str::FromStr>(&mut self) -> T {
        self.scan_line();
        self.buf
            .pop_front()
            .unwrap()
            .parse()
            .unwrap_or_else(|_| panic!("Couldn't parse!"))
    }

    pub fn next_usize(&mut self) -> usize {
        self.next()
    }

    pub fn next_isize(&mut self) -> isize {
        self.next()
    }

    pub fn next_chars(&mut self) -> Vec<char> {
        self.next::<String>().chars().collect()
    }

    pub fn next_string(&mut self) -> String {
        self.next()
    }

    pub fn next_char(&mut self) -> char {
        self.next()
    }

    pub fn next_float(&mut self) -> f64 {
        self.next()
    }
}


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

int main(){
    int k,s,b;cin>>k>>s;
    int cnt = 0;
    fol(i,k+1){
        fol(j,k+1){
            b = s-i-j;
            if(b>=0&&b<=k) cnt++;
        }
    }
    cout << cnt << endl;
    return 0;
}


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

int main() {
  string s;
  cin >> s;
  
  for(int i=0;i<4;i++){
    cout << s.at(i);
  }
  
  cout << " ";
  
  for(int j=4;j<12;j++){
    cout << s.at(j);
  }
  cout << endl;
}

Measured memory_bytes: 256
from collections import deque, defaultdict
n, x, y = map(int, input().split())

edges = defaultdict(lambda: [])
for i in range(1, n):
    edges[i].append(i+1)
    edges[i+1].append(i)
edges[x].append(y)
edges[y].append(x)

# 幅優先
counter = [0 for i in range(n)]
for i in range(1, n+1):
    d = deque()
    is_checked = [False for _ in range(n+1)]
    dist = [-1 for _ in range(n+1)]
    dist[i] = 0
    d.append((i, 0))
    while len(d) > 0:
        e, pre_dist = d.popleft()
        if is_checked[e]:
            continue
        else:
            is_checked[e] = True
            dist[e] = pre_dist + 1
            for next_e in edges[e]:
                if not is_checked[next_e]:
                    d.append((next_e, pre_dist+1))
    for j in range(i+1, n+1):
        counter[dist[j]-1] += 1
print("\n".join(list(map(str, counter[1:]))))


Measured memory_bytes: 51804
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <numeric> // accumulate(v.begin(), v.end(), 0)

using namespace std;
#define ll long long

int main(){
  int N;
  int T, A;
  cin >> N >> T >> A;
  vector<int> H(N);
  double min = 1000;
  int ind = -1;
  for(int i=0; i<N; i++) {
    cin >> H[i];
    if(abs(T - H[i] * 0.006 - A) < min) {
      min = abs(T - H[i] * 0.006 - A);
      ind = i + 1;
    }
  }
  cout << ind << endl;
  return 0;
}


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

using ll = long long;
using pll = pair<ll, ll>;
#define rep(i, j) for(int i=0; i < (int)(j); i++)

class Solver {
  public:
    const int SUM_MAX = 9 * 14 + 1;
    enum {
        SMALL = 0,
        EQUAL = 1,
        BIG   = 2,
    };
    
    bool solve() {
        string s; cin >> s;
        for(auto &c: s) c -= '0';
        int s_sum = 0; for(auto &c : s) s_sum += c;
        ll s_prod = 1; for(auto &c : s) s_prod *= (c + 1);
        
        // n?????????, int??¨??????s?????? or equal or big, ??????, ??????, 
        // [int][bool][int][ll]        
        vector<vector<vector<map<ll, ll>>>> dp;

        // ?????????
        dp.resize(s.size() + 1);
        rep(i, dp.size()) {
            dp[i].resize(3);
            rep(j, dp[i].size()) {
                dp[i][j].resize(SUM_MAX);
                if(i == 0 and j == EQUAL) {
                    dp[i][j][0][1] = 1;
                }
            }
        }
        
        // ?¨????
        rep(n, s.size()) { 
            rep(comp, 3) { 
                rep(sum, SUM_MAX) {
                    for(pll p :dp[n][comp][sum]) {
                        ll prod = p.first, cnt = p.second;                
                        rep(i, 10) {
                            if(comp == EQUAL) {
                                int next_comp = i == s[n] ? EQUAL : (i > s[n] ? BIG : SMALL);
                                dp[n + 1][next_comp][sum + i][prod * (i + 1)] += cnt;
                            } else {
                                dp[n + 1][comp][sum + i][prod * (i + 1)] += cnt;
                            }                                
                        }
                    }
                }
            }
        }
        ll ans_sum = 0;
        for(int comp : {SMALL, EQUAL, BIG}) {
            rep(sum, s_sum) {
                for(pll p : dp[s.size()][comp][sum]) {
                    ans_sum += p.second;                    
                }
            }
        }
        ll ans_prod = 0;
        for(int comp : {SMALL, EQUAL, BIG}) {
            for(pll p : dp[s.size()][comp][s_sum]) {
                if(p.first < s_prod) {
                    ans_prod += p.second;
                }
            }
        }
        ll ans_int = 0;
        ans_int = dp[s.size()][SMALL][s_sum][s_prod];

        cout << ans_sum + ans_prod + ans_int << endl;
        
        return 0;
    }    
};

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

Measured memory_bytes: 74444
using System;
using System.Collections.Generic;
using System.Linq;

namespace ABC045_B
{
    class Program
    {
        static void Main(string[] args)
        {
            var a = new Queue<char>();
            var b = new Queue<char>();
            var c = new Queue<char>();
            var aaa = Console.ReadLine().ToCharArray();
            var bbb = Console.ReadLine().ToCharArray();
            var ccc = Console.ReadLine().ToCharArray();
            for(var i=0;i<aaa.Count();i++)
            {
                a.Enqueue(aaa[i]);
            }
            for (var i = 0; i < bbb.Count(); i++)
            {
                b.Enqueue(bbb[i]);
            }
            for (var i = 0; i < ccc.Count(); i++)
            {
                c.Enqueue(ccc[i]);
            }
            var d = a.Dequeue();
            while(true)
            {
                if(d == 'a')
                {
                    if(a.Count() == 0)
                    {
                        Console.WriteLine("A");
                        return;
                    }
                    d = a.Dequeue();
                }
                else if ( d == 'b')
                {
                    if(b.Count() == 0)
                    {
                        Console.WriteLine("B");
                        return;
                    }
                    d = b.Dequeue();
                }
                else
                {
                    if(c.Count() == 0)
                    {
                        Console.WriteLine("C");
                        return;
                    }
                    d = c.Dequeue();
                }
                
            }
        }
    }
}


Measured memory_bytes: 11348
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define mod 1000000007
ll power(ll x,ll y){
  ll res=1;
  while(y>0){
    if(y&1)
      res=(res*x)%mod;
    y=y/2;
    x=(x*x)%mod;
  }
  return res;
}
int main() {
  ll n,k;
  cin>>n>>k;
  ll ans=k;
  ll a[k+1];
  a[k]=1;
  ll i,j;
  for(i=k-1;i>=1;i--){
    a[i]=power(k/i,n);
    for(j=i+i;j<=k;j+=i){
     	a[i]=a[i]+mod-a[j];
     	if(a[i]>=mod)
       	a[i]=a[i]-mod;
  	}
    
  }
  for(int i=1;i<=k-1;i++){
    ans=ans+(1LL * a[i]*i);
    ans%=mod;
  }
  cout<<ans;         
  return 0;
}

Measured memory_bytes: 4352
import java.io.*;
import java.util.*;

public class Main {

	public static void main(String[] args)
			throws java.io.IOException{
		Scanner scan = new Scanner(System.in);
		int n;
		int ans;
		int m=0;
		while (scan.hasNext()){
			ans =0;
			n=scan.nextInt();
		for(int i=0;i<10;i++)
			for(int j=0;j<10;j++)
				for(int k=0;k<10;k++)
					for(int l=0;l<10;l++)
						if(i+j+k+l == n)ans++;
						
		System.out.println(ans);
		}
		
					}
						
	}

Measured memory_bytes: 12000
#include <bits/stdc++.h>  // g++ -std=c++14 -o a a.cpp

using namespace std;

typedef pair<int, int> P;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define repto(i, n) for(int i = 0; i <= (n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end()) // ユニークなvectorにする。連続した値を除去して切り出す。
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007
#define DEBUG(x) cout << #x << ": " << x << endl;

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

int main() {
  int D, L;
  cin >> D >> L;
  cout << ((D / L) + (D % L)) << endl;
}



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

int main (){
  string E, O;
  cin >> E >> O;
  for (int i=0; i < E. size () ; i++) {
    cout << E[i];
    if(i < O. size () ) cout << O[i];
  }
  return 0;
}
//これでちゃんとE[0],O[0],E[1],E[1]と出力される

Measured memory_bytes: 256
#coding:utf-8

k = int(input())
count = 0

def gcd(a,b):
    if a >= b:
        k1, k2 = a, b
    elif a < b:
        k1, k2 = b, a

    r = k1 % k2
    if r != 0:
        return gcd(k2,r)
    elif r == 0:
        return k2

for a in range(1,k+1):

    for b in range(1,a+1):

        f = gcd(a,b)

        for c in range(1,b+1):

            g = gcd(f,c)
            
            if a == b and b != c:
                count += g * 3
            elif b == c and c != a:
                count += g * 3
            elif c == a and a != b:
                count += g * 3
            elif a == b and b == c:
                count += g
            else:
                count += g * 6

print("{}".format(count))

Measured memory_bytes: 9220
from collections import defaultdict

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

C=[]
A=[]
min_price=-1

for i in range(N):
   x=list(map(int,input().split()))
   C.append(x[0])
   A.append(x[1:])

for j in range(2**N):
    kekka=True
    taisho=[]
    for k in range(N):
        if ((j>>k)&1):
            taisho.append(k)
    
    #理解度および値段
    price=0
    rikai=defaultdict(int)
    for l in taisho:
        price += C[l]
        for m in range(M):
            rikai[m] += A[l][m]
    
    #理解度の確認
    for n in range(M):
        if rikai[n]<X:
            kekka=False
            break
    
    #理解度が充足しているとき
    if kekka == True:
        if min_price==-1 or price<min_price:
            min_price=price

print(min_price)


        

        
    





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

int main() {
  ios::sync_with_stdio(false);
  int N;
  cin >> N;

  int A = 0, B = 0, C = 0;

  for (int i = 0; i < N; i++) {
    int a, b, c;
    cin >> a >> b >> c;
    a += max(B, C), b += max(A, C), c += max(A, B);
    A = a, B = b, C = c;
  }

  cout << max({A, B, C}) << "\n";
}

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

#define ll long long

using namespace std;
const ll mod = 1e9 + 7;
const int MAXN = 1e6 + 5;
const int inf  = 0x3f3f3f3f;
const ll  INF  = 0x3f3f3f3f3f3f3f3f;

int main()
{
    char a;
    scanf("%c",&a);
    printf("%c",a+1);
    return 0;
}


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

double a, b, h, m;

int main() {
	cin >> a >> b >> h >> m;
	double rad = 2*M_PI*(h/12+m/(12*60)-m/60-h);
	cout << setprecision(10) << sqrt(a*a+b*b-2*a*b*cos(rad));
}

Measured memory_bytes: 4232
/*
* Note: This template uses some c++11 functions , so you have to compile it with c++11 flag.
*       Example:-   $ g++ -std=c++11 c++Template.cpp
*
* Author : Akshay Pratap Singh
* Handle: code_crack_01
*
*/
 
/********   All Required Header Files ********/
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>

using namespace std;

/*******  All Required define Pre-Processors and typedef Constants *******/
#define SCD(t) scanf("%d",&t)
#define SCLD(t) scanf("%ld",&t)
#define SCLLD(t) scanf("%lld",&t)
#define SCC(t) scanf("%c",&t)
#define SCS(t) scanf("%s",t)
#define SCF(t) scanf("%f",&t)
#define SCLF(t) scanf("%lf",&t)
#define MEM(a, b) memset(a, (b), sizeof(a))
#define FOR(i, j, k, in) for(int i=j ; i<k ; i+=in)
#define RFOR(i, j, k, in) for(int i=j ; i>=k ; i-=in)
#define REP(i, j) FOR(i, 0, j, 1)
#define RREP(i, j) RFOR(i, j, 0, 1)
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define IN(A, B, C) assert( B <= A && A <= C)
#define MP make_pair
#define PB push_back
#define INF (int)1e9
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define read(type) readInt<type>()
typedef long long int ll;
typedef unsigned long long int  ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<pii> vii;
typedef vector<ll> vll;
typedef vector<vi> vvi;

int main(){

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

  ll res = 0;

  FOR(i, K+1, N+1, 1){

    res += (i-K) * (N/i);
    if( K != 0 and N%i > 0 )
      res += max((N%i)-(K-1), 0);
    else if ( K == 0 )
      res += max((N%i)-(K), 0);

  }

  cout << res << endl;

  return 0;
}


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

typedef long long ll;

int main() {
    int N, a;
    cin >> N;
    string ans = "second\n";
    rep(i, N) {
        cin >> a;
        if (a % 2) ans = "first\n";
    }
    cout << ans;
}

Measured memory_bytes: 256