akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define REP(i,st,ed) for(register int i=st,i##end=ed;i<=i##end;++i)
#define DREP(i,st,ed) for(register int i=st,i##end=ed;i>=i##end;--i)
typedef long long ll;
template<typename T>inline bool chkmin(T &x,T y){return (y<x)?(x=y,1):0;}
template<typename T>inline bool chkmax(T &x,T y){return (y>x)?(x=y,1):0;}
inline int read(){
	int x;
	char c;
	int f=1;
	while((c=getchar())!='-' && (c>'9' || c<'0'));
	if(c=='-') f=-1,c=getchar();
	x=c^'0';
	while((c=getchar())>='0' && c<='9') x=(x<<1)+(x<<3)+(c^'0');
	return x*f;
}
inline ll readll(){
	ll x;
	char c;
	int f=1;
	while((c=getchar())!='-' && (c>'9' || c<'0'));
	if(c=='-') f=-1,c=getchar();
	x=c^'0';
	while((c=getchar())>='0' && c<='9') x=(x<<1ll)+(x<<3ll)+(c^'0');
	return x*f;
}
const int maxn=2e5+10;
int a[maxn];
int main(){
	int n=read();
	REP(i,1,n) a[i]=read()-i;
	sort(a+1,a+n+1);
	ll ans=0;
	int Mid=a[(1+n)>>1];
	REP(i,1,n) ans+=abs(a[i]-Mid);
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s;
	cin>>s;
	if(s=="SUN")
	cout<<'7';
	if(s=="MON")
	cout<<'6';
	if(s=="TUE")
	cout<<'5';
	if(s=="WED")
	cout<<'4';
	if(s=="THU")
	cout<<'3';
	if(s=="FRI")
	cout<<'2';
	if(s=="SAT")
	cout<<'1';
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using ll = long long;
using namespace std;

int main() {
    int n, k;
    cin >> n >> k;
    int temp;
    int count = 0;
    rep(i, n) {
        cin >> temp;
        if(temp >= k)
            count++;
    }

    cout << count << endl;
}

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

using namespace std;

#define N 4
#define N2 16
#define LIMIT 100

const int dx[4]={0,-1,0,1};
const int dy[4]={1,0,-1,0};
const char dir[4]={'r','u','l','d'};

int MDT[N2][N2];

struct puzzle{
    int f[N2],space,MD;
};

puzzle state;
int limit;
int path[LIMIT];

int getALLMD(puzzle pz)
{
    int sum=0;
    for(int i=0;i<N2;i++){
        if(pz.f[i]==N2){
            continue;
        }
        sum+=MDT[i][pz.f[i]-1];
    }
    return sum;
}

bool dfs(int depth,int prev)
{
    if(state.MD==0){
        return true;
    }
    if(depth+state.MD>limit){
        return false;
    }
    int sx=state.space/N;
    int sy=state.space%N;
    puzzle tmp;
    for(int r=0;r<4;r++){
        int tx=sx+dx[r];
        int ty=sy+dy[r];
        if(tx<0||ty<0||tx>=N||ty>=N){
            continue;
        }
        if(max(prev,r)-min(prev,r)==2){
            continue;
        }
        tmp=state;
        //计算曼哈顿距离的差值，同时交换拼图块
        state.MD-=MDT[tx*N+ty][state.f[tx*N+ty]-1];
        state.MD+=MDT[sx*N+sy][state.f[tx*N+ty]-1];
        swap(state.f[tx*N+ty],state.f[sx*N+sy]);
        state.space=tx*N+ty;
        if(dfs(depth+1,r)){
            path[depth]=r;
            return true;
        }
        state=tmp;
    }
    return false;
}

string iterative_deepening(puzzle in)
{
    in.MD=getALLMD(in);//初始状态的曼哈顿距离
    for(limit=in.MD;limit<=LIMIT;limit++){
        state=in;
        if(dfs(0,-100)){
            string ans="";
            for(int i=0;i<limit;i++){
                ans+=dir[path[i]];
            }
            return ans;
        }
    }
    return "unsolvable";
}

int main()
{
    for(int i=0;i<N2;i++){
        for(int j=0;j<N2;j++){
            //曼哈顿距离，此法太妙
            MDT[i][j]=abs(i/N-j/N)+abs(i%N-j%N);
        }
    }
    puzzle in;
    for(int i=0;i<N2;i++){
        cin>>in.f[i];
        if(in.f[i]==0){
            in.f[i]=N2;
            in.space=i;
        }
    }
    string ans=iterative_deepening(in);
    cout<<ans.size()<<endl;
    return 0;
}
/*
1 2 3 4
6 7 8 0
5 10 11 12
9 13 14 15
*/



Measured memory_bytes: 3224
#include<stdio.h>

int main(){
    int n,k,i,j,l,t,ans=0;
    int p[1000];
    scanf("%d %d",&n,&k);
    for(i=0;i<n;i++)
    	scanf("%d",&p[i]);
    for(j=0;j<n-1;j++)
		for(l=j+1;l<n;l++)
    	if(p[l]<p[j]){
    		t=p[j];
    		p[j]=p[l];
    		p[l]=t;
		}
	for(i=0;i<k;i++)
		ans=ans+p[i];
	printf("%d",ans);
    return 0;
}


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

using Vi = vector<int>;
using Vs = vector<string>;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
typedef pair<int, int> P;
typedef long long ll;

const int INF = 10000000, MAX_N = 200000, MAX_M = 1000, MAX_W = 10000;

int asc(const void* a, const void* b) {
    return *(int*)a - *(int*)b;
}


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

    ll ans = -1;
    while (h) {
        h /= 2;
        ans += 1;
    }

    ll p = 1;
    rep(i, ans+1)
        p *= 2;

    cout << p - 1 << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int N, M, a[5009], b[5009];
int main() {
	cin >> N >> M;
	for (int i = 0; i < N; i++) cin >> a[i];
	for (int i = 0; i < M; i++) cin >> b[i];
	int ret = 0;
	for (int i = 0; i <= M - ret; i++) {
		int ptr = i;
		for (int j = 0; ptr < M && j < N; j++) {
			if (a[j] == b[ptr]) ptr++;
		}
		ret = max(ret, ptr - i);
	}
	cout << ret << endl;
	return 0;
}

Measured memory_bytes: 3076
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int i, j,n,q,mid,left,right;
		int cnt=0;
		n = sc.nextInt();
		int [] S = new int [n];
		for(i=0;i<n;i++){
			S[i] = sc.nextInt();
		}
		q = sc.nextInt();
		int [] T = new int[q];
		for(i=0;i<q;i++){
			T[i] = sc.nextInt();
		}
		
	    for(i=0;i<q;i++){
	    	left =0;
	    	right = S.length;
	    	while(left < right){
	    		 mid = (left + right)/2;
	    		 if(T[i]==S[mid]){
	    			 cnt++;
	    			 break;
	    		 }
	    		 if(T[i]>S[mid]) left = mid +1;
	    		 else if(T[i] < S[mid])  right = mid;
	    	}
	    }
		
	    System.out.println(cnt);
	}

}


Measured memory_bytes: 67552
#include <bits/stdc++.h>
#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 INF 2e9
#define MOD 1000000007
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
using P = pair<int,int>;
  
int main()
{
  ll R, G, B, N;
  cin >> R >> G >> B >> N;
 
  ll cnt = 0;
  REP(i,N/R+2){
    REP(j,N/G+2){
      if((N-R*i-G*j)%B==0&&N-R*i-G*j>=0){
        cnt++;
      }
    }
  }
  cout << cnt << endl;
}

Measured memory_bytes: 256
import bisect
# from collections import Counter, defaultdict, deque, namedtuple
# import copy
# from heapq import heappush, heappop, heapify
# from fractions import gcd
import itertools
# from operator import attrgetter, itemgetter
# import math

import sys

# import numpy as np

ipti = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)

def main():
    h, w = list(map(int,ipti().split()))
    hw = [sys.stdin.readline().rstrip("\n") for _ in range(h)]
    l = [[0] * w for _ in range(h)]
    r = [[0] * w for _ in range(h)]
    u = [[0] * w for _ in range(h)]
    d = [[0] * w for _ in range(h)]

    for i in range(h):
        s = hw[i]
        for j in range(w):
            if s[j] == "#":
                l[i][j] = 0
                d[i][j] = 0
            else:
                if j == 0:
                    l[i][j] = 1
                else:
                    l[i][j] = l[i][j-1] + 1
                if i == 0:
                    u[i][j] = 1
                else:
                    u[i][j] = u[i-1][j] + 1

    for i in range(h-1, -1, -1):
        s = hw[i]
        for j in range(w-1, -1, -1):
            if s[j] == "#":
                r[i][j] = 0
                u[i][j] = 0
            else:
                if j == (w-1):
                    r[i][j] = 1
                else:
                    r[i][j] = r[i][j+1] + 1
                if i == (h-1):
                    d[i][j] = 1
                else:
                    d[i][j] = d[i+1][j] + 1

    ans = 0

    for i in range(h):
        for j in range(w):
            temp = l[i][j] + r[i][j] + u[i][j] + d[i][j]
            ans = max(ans, temp)

    print(ans-3)

if __name__ == '__main__':
    main()

Measured memory_bytes: 176008
#include <stdio.h>
#define max(X, Y) ((X)>(Y)?(X):(Y))
int main(void)
{
    int w, d;
    while (scanf("%d%d", &w, &d), w) {
        int i, a[21]={0}, b[21]={0}, res;
        for(i=0;i<w;++i) { int t; scanf("%d", &t); a[t]++; }
        for(i=0;i<d;++i) { int t; scanf("%d", &t); b[t]++; }
        res=0;
        for(i=1;i<=20;++i) res+=i*max(a[i], b[i]);
        printf("%d\n", res);
    }
    return 0;
}

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

int main(){
	int N; cin>> N;
  	int M=0, ans=0, temp;
	for(int i=0;i<N;i++){
    	cin>>temp;
      	M=max(temp,M);
      	ans+=temp;
    }
  cout<< ans-M+M/2<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cstring>
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const long double EPS = 1e-9;
const ll mod = 1e9 + 7;
const ll INF = 1e9;

#define rep(i, n) for(ll i = 0; i < n ; i++ )
#define For(i, a, b) for(ll i = (a); i < (b) ; i++ )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

const ll MAX_N = 100;

int main(void){
    ll N, M;
    ll answer;

    cin >> N >> M;

    answer = 1900 * M + 100 * (N - M);
    rep(i, M) answer *= 2;

    cout << answer << endl;

    return 0;
}


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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}

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

    ll P, Q, R;
    cin >> P >> Q >> R;

    ll ma = P;
    ma = max(ma, Q);
    ma = max(ma, R);
    cout << P + Q + R - ma << endl;
    return 0;
}

Measured memory_bytes: 256
n = int(input())
l = [input() for i in range(n)]
ans = 'Yes'
if len(set(l)) != n:
  ans = 'No'
else:
  for i in range(1,n):
    if l[i][0] != l[i-1][-1]:
      ans = 'No'
print(ans)

Measured memory_bytes: 3060
Q, H, S, D = map(int, input().split())
N = int(input())
l_1 = min((Q * 4), (H * 2), (S * 1))
l_2 = min((Q * 8), (H * 4), (S * 2), (D * 1))
ans = 0

if N == 1:
    ans = int(l_1)
elif N % 2 == 0:
    ans = int(l_2 * (N // 2))
else:
    ans = int(((N - 1) // 2) * l_2 + l_1)
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, s, n) for(int i = (int)(s); i < (int)(n); i++)
typedef long long int ll;

using namespace std;

int main() {
    int N;
    vector<int> B;

    cin >> N;
    rep(i, N - 1) {
        int val;
        cin >> val;
        B.push_back(val);
    }
    
    int ans = B[0] + B[N - 2];
    rep(i, N) ans += min(B[i], B[i + 1]);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
# coding: utf-8
while 1:
    date=[[0,i] for i in range(101)]
    n,q=map(int,input().split())
    if n==0:
        break
    for i in range(n):
        t = list(map(int,input().split()))
        for num in t[1:]:
            date[num][0]+=1
    ans = sorted(date,key=lambda x:(-x[0],x[1]))[0]
    print(ans[1] if ans[0]>=q else 0)


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

int main() {
  string c1, c2, c3;
  cin >> c1 >> c2 >> c3;

  cout << c1[0] << c2[1] << c3[2] << endl;
  return 0;
}

Measured memory_bytes: 3528
package main

import (
	"fmt"
)

func main() {
	var n, m int
	fmt.Scan(&n, &m)
	bs := make([]tuple, m)
	uf := newUnionFind(n)
	for i := 0; i < m; i++ {
		var x, y int
		fmt.Scan(&x, &y)
		bs[i] = tuple{x, y}
		uf.unite(x, y)
	}
	sz := uf.size(1)
	count := 0
	for i := 0; i < m; i++ {
		u := newUnionFind(n)
		for j := 0; j < m; j++ {
			if i == j {
				continue
			}
			u.unite(bs[j].x, bs[j].y)
		}
		if sz != u.size(1) {
			count++
		}
	}
	fmt.Println(count)
}

type tuple struct {
	x, y int
}

type unionFind struct {
	par    []int
	length []int
}

func newUnionFind(n int) *unionFind {
	return &unionFind{make([]int, n + 1), make([]int, n + 1)}
}

func (u *unionFind) root(x int) int {
	if u.par[x] == 0 {
		return x
	}
	u.par[x] = u.root(u.par[x])
	return u.par[x]
}

func (u *unionFind) unite(x, y int) {
	xr, yr := u.root(x), u.root(y)
	xs, ys := u.size(x), u.size(y)
	if xr == yr {
		return
	} else if xr > yr {
		u.par[xr] = yr
	} else {
		u.par[yr] = xr
	}
	u.length[xr] += ys
	u.length[yr] += xs
}

func (u *unionFind) size(x int) int {
	r := u.root(x)
	if u.length[r] == 0 {
		u.length[r]++
	}
	return u.length[r]
}

Measured memory_bytes: 512
N = int(input())
S = input()

CW = 0

for s in S:
    if s == '.' : CW += 1
    
CB = 0
ans = (CB+CW)
for s in S:
    if s == '.' : CW -= 1
    if s == '#' : CB += 1
    ans = min(ans,CB+CW)
    
print(ans)
    


Measured memory_bytes: 3500
import numpy as np
 
h,w = map(int,input().split())
a = [list(input()) for i in range(h)]

arr=[]
arr2=[]
for i in a:
  if '#' in i:
    arr.append(i)
    
ar = np.array(arr)
arT = ar.T
 
for i in arT:
  if '#' in i:
    arr2.append(i)
    
arr3 = np.array(arr2)
arr4 = arr3.T
 
arr5=arr4.tolist()

for i in range(len(arr5)):
    print("".join(arr5[i]))

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

int main(){
  string S;
  cin >> S;
  
  int ans = 0;
  
  for(int i = 0; i < 4; i++){
    if(S.at(i) == '+'){
      ans++;
    }
    if(S.at(i) == '-'){
      ans--;
    }
  }
  
  cout << ans << endl;
}
      

Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
#include<functional>
using namespace std;
int main()
{
	int N, t[100100], x[100100], y[100100], sum[100100];
	scanf("%d", &N);
	for (int i = 1; i <= N; i++) {
		scanf("%d%d%d", &t[i], &x[i], &y[i]);
		sum[i] = 0;
		sum[i] += x[i] + y[i];
	}
	for (int i = 1; i <= N; i++) {
		if (t[i] % 2 == 0) {
			if (sum[i] % 2 == 1 || sum[i] > t[i]) {
				printf("No");
				return 0;
			}
		}
		else{
			if (sum[i] % 2 == 0 || sum[i] > t[i]) {
				printf("No");
				return 0;
			}
		}
	}
	printf("Yes");
	return 0;
}

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

#define rep(i, a, b) for (int i = a; i < (int)(b); ++i)
#define rrep(i, a, b) for (int i = b - 1; i >= (int)(a); --i)

using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;

constexpr int MOD = 1000000007;

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

    int n, w;
    cin >> n >> w;

    int vmax = 1000 * 100;
    vll dp(vmax + 1, INT_MAX);

    ll vsum = 0;
    dp[0] = 0;
    rep(i, 0, n) {
        ll wi, vi;
        cin >> wi >> vi;
        vsum += vi;
        rrep(j, vi, vsum + 1) { dp[j] = min(dp[j], dp[j - vi] + wi); }
        rrep(j, 1, vi) { dp[j] = min(dp[j], ll(wi)); }
    }
    rep(i, 1, vsum + 1) {
        if (dp[i] > w) {
            cout << i - 1 << endl;
            return 0;
        }
    }
    cout << vsum << endl;
    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main(){
  int k;
  cin>>k;
  vector<int>vec={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
	cout<<vec.at(k-1)<<endl;
}

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

int main(){
  int m,f,r;
  while(true){
    cin>>m>>f>>r;
    if(m+f+r==-3) break;
    bool flg=false;
    if(m==-1){m=0;flg=true;}
    if(f==-1){f=0;flg=true;}
    int sum=m+f;
    if(flg||sum<30) cout<<"F"<<endl;
    else if(sum>=80) cout<<"A"<<endl;
    else if(sum>=65) cout<<"B"<<endl;
    else if(sum>=50) cout<<"C"<<endl;
    else if(sum>=30) r>=50?cout<<"C"<<endl:cout<<"D"<<endl;
  }
  return 0;
}

Measured memory_bytes: 3072
#include <iostream>
#include <sstream>
#include <cstdio>
#include <stdlib.h>
#include <string>
#include <vector>
#include <algorithm>
#define MAX 10002
using namespace std;
int p[MAX];
int root(int x){
    if(p[x]==x)return x;
    return p[x] = root(p[x]);
}

int main(){
  int n,q,x,y,i;
  bool com;
  cin>>n>>q;
  for(i=1;i<n+1;i++)p[i]=i;
  for (i=0;i<q;i++){
    cin>>com>>x>>y;
    if(com)cout<<(root(x) == root(y))<<endl;
    else p[root(x)] = root(y);
  }
  return 0;
}


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

using namespace std;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

typedef long long  ll;
#define endl '\n'




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


const int MOD = 1000000007;

//////////////////////////////////////////


ll A, B, C, D;

ll lcm(ll a, ll b) {

    return (a * b/__gcd(a, b));
}
void Input() {

    cin >> A >> B >> C >> D;
}



void Solve() {

    ll a1 = (A-1)/C;
    ll a2 = (A-1)/D;
    ll a3 = (A-1)/lcm(C, D);

    ll b1 = B/C;
    ll b2 = B/D;
    ll b3 = B/lcm(C, D);

    ll aa = (A-1) - a1 - a2 + a3;
    ll bb = B - b1 - b2 + b3;

    cout << bb - aa << endl;

}

int main() {

  cin.tie(0);
  ios::sync_with_stdio(false);
  Input();
  Solve();


  return 0;

}



Measured memory_bytes: 256
#include<map>
#include<iostream>
#include<string.h>
#include<cstdio>
#include<vector>
using namespace std;
int main()
{
    int n;
    int num;
    scanf("%d",&n);
    if(n%1000==0)
        cout<<"0"<<endl;
    else
    {
        num=1000-(n%1000);
        printf("%d",num);
    }
    return 0;
}

Measured memory_bytes: 3756
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int [] a = new int[n];
        List<Integer> list = new ArrayList<>();
        for(int i = 0; i < n; i++) {
        	a[i] = sc.nextInt();
        	list.add(a[i]);
        }
        Collections.sort(list);
        int [] ans = {list.get(n/2-1),list.get(n/2)};
        for(int i = 0; i < n; i++) {
        	System.out.println(ans[judge(a[i],ans)]);
        }
    }

    static int judge(int x, int[]ans) {
    	if(x <= ans[0]) {
    		return 1;
    	}
    	return 0;
    }
}

Measured memory_bytes: 95124
#include  <stdio.h>

int main(int argc, char* argv[]){
  int n,k,x,y;
  scanf("%d\n%d\n%d\n%d",&n,&k,&x,&y);
  int ans;
  if(k>=n) ans = x*n;
  else ans = x*k + y*(n-k);
  printf("%d\n",ans);
  return 0;
}


Measured memory_bytes: 128
#![allow(non_snake_case)]

fn read_line() -> String {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

fn read_vec() -> Vec<i32> {
    read_line()
        .split_whitespace()
        .map(|e| e.parse().unwrap())
        .collect()
}

fn main() {
    let N: usize = read_line().parse().unwrap();
    let mut v: Vec<f64> = read_vec().iter().map(|e| *e as f64).collect();
    v.sort_by(|a, b| a.partial_cmp(b).unwrap());
    let ans = v.iter().fold(v[0], |x, y| (x+y) / 2.0);
    println!("{}", ans);
}


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

int main()
{
  int m1(0), m2(0), m4(0);
  int n;
  cin >> n;

  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    int m = __builtin_ctz(a);
    if (m >= 2) {
      m4++;
    } else if (m == 1) {
      m2++;
    } else {
      m1++;
    }
  }

  string ans = m4 + 1 - m1 - (m2 > 0) >= 0 ? "Yes" : "No";
  cout << ans << endl;
}


Measured memory_bytes: 256
n = int(input())
prime_list = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97]
divider_list = []
for i in range(1,n+1):
    while i > 1:
        for j in prime_list:
            if i % j == 0:
                divider_list.append(j)
                i = i // j
                break
            else:
                continue
divider_dic = {}
for k in divider_list:
    if k in divider_dic:
        divider_dic[k] = divider_dic[k] + 1
    else:
        divider_dic[k] = 1

key_list = []
for k in divider_dic:
    key_list.append(divider_dic[k])
a, b, c, d, e = 0, 0, 0, 0, 0
for k in key_list:
    if k == 1:
        continue
    elif k < 4:
        a += 1
    elif k < 14:
        b += 1
    elif k < 24:
        c += 1
    elif k < 74:
        d += 1
    else:
        e += 1

def nCr(n, r):
    if n < r:
        return 0
    r = min(r, n - r)
    if r == 0: return 1;
    if r == 1: return n;
    numerator = [n - r + i + 1 for i in range(r)]
    denominator  = [i + 1 for i in range(r)]
    for p in range(2, r + 1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p - 1, r, p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot
    result = 1
    for k in range(r):
        if numerator[k] > 1: 
            result *= numerator[k]
    return result

ans = int(a*nCr(b+c+d+e,2)+nCr(b+c+d+e,2)*(b+c+d+e-2)+b*(c+d+e)+(c+d+e)*(c+d+e-1)+(a+b+c)*(d+e)+(d+e)*(d+e-1)+e)
print(ans)

Measured memory_bytes: 3192
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long ll;
// Welcome to my source code!

typedef pair<int, int> P;
const int INF = 1e9;
int dx[4] = { 1, 0, -1, 0 }, dy[4] = { 0, 1, 0, -1 };

int main() {
    int h, w;
    cin >> h >> w;
    char maze[h][w];
    int d[h][w];
    for (int i = 0; i < h; i++)for (int j = 0; j < w; j++) cin >> maze[i][j];
    queue<P> que;
    int sx, sy, maxd = -1;
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            sx = i, sy = j;
            if (maze[i][j] == '#') continue;
            for (int f = 0; f < h; f++)for (int k = 0; k < w; k++) d[f][k] = INF;
            que.push(P(sx, sy));
            d[sx][sy] = 0;
            while (que.size()) {
                P p = que.front(); que.pop();
                for (int f = 0; f < 4; f++) {
                    int nx = p.first + dx[f], ny = p.second + dy[f];
                    if (0 <= nx && nx < h && 0 <= ny && ny < w && maze[nx][ny] != '#' && d[nx][ny] == INF) {
                        que.push(P(nx, ny));
                        d[nx][ny] = d[p.first][p.second] + 1;
                    }
                }
            }
            for (int f = 0;f < h; f++)for (int k = 0; k < w; k++) {
                if (d[f][k] != INF) maxd = max(maxd, d[f][k]);
            }
        }
    }
    cout << maxd << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int MOD = pow(10, 9) + 7;
//const int MOD = 998244353;
//const int MOD = ;
int mod(int A, int M) {return (A % M + M) % M;}
const int INF = 1LL << 60;
template <class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template <class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
int divCeil(int A, int B) {return (A + (B - 1)) / B;}
int myctoi(char C) {return C - 48;}
char myitoc(int N) {return '0' + N;}

signed main()
{
  int N, K;
  cin >> N >> K;
  vector<int> A(N);
  int suma = 0;
  for (int i = 0; i < N; i++)
  {
    cin >> A.at(i);
    suma += A.at(i);
  }

  vector<int> div;
  for (int i = 1; i * i <= suma; i++)
  {
    if (suma % i == 0)
    {
      div.push_back(i);
      if (i * i != suma) div.push_back(suma / i);
    }
  }
  sort(div.begin(), div.end(), greater<int>());
  
  for (int i = 0; i < div.size(); i++)
  {
    int d = div.at(i);
    vector<int> x(N), y(N);
    int sumx = 0;
    for (int i = 0; i < N; i++)
    {
      x.at(i) = d - A.at(i) % d;
      sumx += x.at(i);
      y.at(i) = d - x.at(i);
    }
    
    if (sumx % d != 0) continue;
    
    sort(y.begin(), y.end());
    int sumy = 0;
    for (int i = 0; i < sumx / d; i++)
    {
      sumy += y.at(i);
    }
    
    if (sumy <= K)
    {
      cout << d << endl;
      return 0;
    }
  }
  
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#define LEN 100000

typedef struct p{
  char name[100];
  int time;
} P;

P Q[LEN];
int head, tail, n;

void enqueue(P x){
  Q[tail] = x;
  tail = (tail+1) % LEN;
}

P dequeue(){
  P x = Q[head];
  head = (head+1) % LEN;
  return x;
}

int min(int a, int b){
  return a < b ? a : b;
}

int main(){
  int elaps = 0, c;
  int i, q;
  P u;
  scanf("%d %d", &n, &q);

  for(int i=1; i<=n; i++){
    scanf("%s", Q[i].name);
    scanf("%d", &Q[i].time);
  }
  head = 1;
  tail = n+1;
  while(head!=tail){
    u = dequeue();
    c = min(q, u.time);
    u.time -= c;
    elaps += c;
    if(u.time > 0) enqueue(u);
    else{
      printf("%s %d\n", u.name, elaps);
    }
  }
  return 0;
}

Measured memory_bytes: 11880
#include <bits/stdc++.h>
using namespace std ;
#define N 5010
#define ll long long
const int mod=1e9+7 ;
char s[N];
int f[N][N],n;
ll power(ll a,ll b){
	ll ans=1,base=a;
	while(b){
		if(b&1) ans=(ans*base)%mod ;
		base=(base* base)%mod;
		b/=2;
	}
	return ans%mod ;
}
int main(){
	scanf("%d%s",&n,s+1);
	int len=strlen(s+1) ;
	f[0][0]=1;
	for( int i=0;i<=n;i++) {
		for( int j=0;j<=i;j++){
			f[i+1][j+1]+=2*f[i][j];
			f[i+1][j+1]%=mod;
			f[i+1][max(j-1,0)]+=f[i][j];
			f[i+1][max(j-1,0)]%=mod ;
		}
	}
	ll ans=1ll*power(power(2,len),mod-2)%mod*f[n][len];
	ans%=mod;
	printf("%lld",ans);
	return 0 ;
} 

Measured memory_bytes: 70636
#include<bits/stdc++.h>
using namespace std;
#define int long long
struct QuickFind{
  vector<int> r,p;
  vector<vector<int> > v;
  QuickFind(){}
  QuickFind(int size){init(size);}
  void init(int size){
    r.resize(size,0);
    p.resize(size,0);
    v.resize(size);
    for(int i=0;i<size;i++){
      r[i]=1,p[i]=i;
      v[i].resize(1,i);
    }
  }
  bool same(int x,int y){
    return p[x]==p[y];
  }
  void unite(int x,int y){
    x=p[x];y=p[y];
    if(x==y) return;
    if(r[x]<r[y]) swap(x,y);
    r[x]+=r[y];
    for(int i=0;i<(int)v[y].size();i++){
      p[v[y][i]]=x;
      v[x].push_back(v[y][i]);
    }
    v[y].clear();
  }
};
signed main(){
  int n;
  cin>>n;
  vector<int>a(n);
  for(int i=0;i<n;i++) cin>>a[i];
  vector<int>b(a);
  sort(b.begin(),b.end());
  map<int,int>p,q;
  for(int i=0;i<n;i++){
    p[a[i]]=i;
    q[b[i]]=i;
  }
  QuickFind qf(n);
  for(int i=0;i<n;i++)
    qf.unite(i,p[b[i]]);
  int ans=0;
  for(int i=0;i<n;i++){
    int k=qf.v[i].size();
    if(qf.p[i]!=i||k==1) continue;
    int m=a[qf.v[i][0]];
    int tmp=0;
    for(int j=0;j<k;j++){
      tmp+=a[qf.v[i][j]];
      m=min(m,a[qf.v[i][j]]);
    }
    ans+=min(tmp+m*(k-2),tmp+m+b[0]*(k+1));
  }
  cout<<ans<<endl;
  return 0;
}



Measured memory_bytes: 3424
N = int(input())
xy = [list(map(int, input().split())) for _ in range(N)]
x, y = [], []
for i, j in xy:
    x += [i]
    y += [j]
ans = 0
for i in range(N):
    for j in range(N):
        if i == j:
            continue
        p = x[j] - x[i]
        q = y[j] - y[i]
        c = 0
        for k in range(N):
            for l in range(N):
                if k == l:
                    continue
                if (x[k] - x[l]) == p and (y[k] - y[l]) == q:
                    c += 1
        ans = max(ans, c)
if N != 1:
    print(N-ans)
else:
    print('1')

Measured memory_bytes: 3064
#include<bits/stdc++.h>
             
using namespace std;
typedef long long int lld;
#define INF 1000000000000000000
#define MOD 1000000007
#define rep(i,a,b) for(int i=a;i<b;i++)
int n;
lld table[50][50];
lld ans[50][50];
lld nxt[50][50];
void conv(){
	rep(i,0,n){
		rep(j,0,n){
			nxt[i][j]=0;
		}
	}
	rep(i,0,n){
		rep(j,0,n){
			rep(k,0,n){
				nxt[i][j]+=table[i][k]*ans[k][j];
				nxt[i][j]%=MOD;
			}
		}
	}
	rep(i,0,n){
		rep(j,0,n){
			ans[i][j]=nxt[i][j];
		}
	}
}
void sq(){
	rep(i,0,n){
		rep(j,0,n){
			nxt[i][j]=0;
		}
	}
	rep(i,0,n){
		rep(j,0,n){
			rep(k,0,n){
				nxt[i][j]+=ans[i][k]*ans[k][j];
				nxt[i][j]%=MOD;
			}
		}
	}
	rep(i,0,n){
		rep(j,0,n){
			ans[i][j]=nxt[i][j];
		}
	}
}
void calc(lld k){
	if(k==1)return;
	if(k%2==1){
		calc(k-1);
		conv();
		return;
	}
	calc(k/2);
	sq();
	return;
}
int main(){
	lld k;
	cin>>n>>k;
	rep(i,0,n){
		rep(j,0,n){
			cin>>table[i][j];
			ans[i][j]=table[i][j];	
		}
	}
	calc(k);
	lld A=0;
	rep(i,0,n){
		rep(j,0,n){
			A+=ans[i][j];
			//cout<<ans[i][j]<<" ";
			A%=MOD;
		}//cout<<endl;
	}
	cout<<A<<endl;
	return 0;
}

Measured memory_bytes: 256
# include "bits/stdc++.h"
using namespace std;
using LL = long long;
using ULL = unsigned long long;
const double PI = acos(-1);
template<class T>constexpr T INF() { return ::std::numeric_limits<T>::max(); }
template<class T>constexpr T HINF() { return INF<T>() / 2; }
template <typename T_char>T_char TL(T_char cX) { return tolower(cX); };
template <typename T_char>T_char TU(T_char cX) { return toupper(cX); };
const int vy[] = { -1, -1, -1, 0, 1, 1, 1, 0 }, vx[] = { -1, 0, 1, 1, 1, 0, -1, -1 };
const int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
int popcnt(unsigned long long n) { int cnt = 0; for (int i = 0; i < 64; i++)if ((n >> i) & 1)cnt++; return cnt; }
int d_sum(LL n) { int ret = 0; while (n > 0) { ret += n % 10; n /= 10; }return ret; }
int d_cnt(LL n) { int ret = 0; while (n > 0) { ret++; n /= 10; }return ret; }
LL gcd(LL a, LL b) { if (b == 0)return a; return gcd(b, a%b); };
LL lcm(LL a, LL b) { LL g = gcd(a, b); return a / g*b; };
# define ALL(qpqpq)           (qpqpq).begin(),(qpqpq).end()
# define UNIQUE(wpwpw)        sort(ALL((wpwpw)));(wpwpw).erase(unique(ALL((wpwpw))),(wpwpw).end())
# define LOWER(epepe)         transform(ALL((epepe)),(epepe).begin(),TL<char>)
# define UPPER(rprpr)         transform(ALL((rprpr)),(rprpr).begin(),TU<char>)
# define FOR(i,tptpt,ypypy)   for(LL i=(tptpt);i<(ypypy);i++)
# define REP(i,upupu)         FOR(i,0,upupu)
# define INIT                 std::ios::sync_with_stdio(false);std::cin.tie(0)

int a, b;

int main(){
	cin >> a >> b;
	cout << (b - 1)/(a - 1) + ((b - 1)%(a - 1) != 0) << endl;
}

Measured memory_bytes: 256
from collections import deque

N = int(input())
tree = [[] for i in range(N)]

for _ in range(N):
    tmp = list(map(int, input().split()))
    for i in range(2, len(tmp)):
        tree[tmp[0]-1].append(tmp[i]-1)

q = deque(tree[0])
cnt = deque([1]*len(tree[0]))
s = {}
ans = [-1]*N

ans[0] = 0
s[0] = True
while len(q) != 0:
    g = q.popleft()
    c = cnt.popleft()
    if ans[g] == -1:
        ans[g] = c
        s[g] = True

    for tmp in tree[g]:
        if not(tmp in s):
            q.append(tmp)
            cnt.append(c+1)

for i in range(N):
    print(i+1, ans[i])



Measured memory_bytes: 6712
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.util.*;

public class Main implements Runnable {

    public static void main(String[] args) throws Exception {
        Thread.setDefaultUncaughtExceptionHandler((t, e)->System.exit(1));
        new Thread(null, new Main(), "", 16 * 1024 * 1024).start();
    }

    public void run() {
        int age = 0;
        // 入力
        try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in));) {
            age = Integer.parseInt(br.readLine());
        } catch (Exception e) {
            e.printStackTrace();
        }

        // 出力
        String result = "NO";
        switch(age) {
            case 7:
            case 5:
            case 3:
                result = "YES";
                break;
        }
        System.out.println(result);
    }
}


Measured memory_bytes: 28884
#include <bits/stdc++.h>
// statics
using namespace std;
using int64 = int_fast64_t;
using PAIR = pair<int64, int64>;
constexpr int INF = 1 << 30;
constexpr int64 LINF = 1LL << 60;
constexpr int MOD = 1e9 + 7;
constexpr int MAX_N = 3e5 + 1;

// init/input
#define int int64
#define INIT ios::sync_with_stdio(false);cin.tie(0);
#define VAR(type, ...) type __VA_ARGS__;MACRO_VAR_Scan(__VA_ARGS__);
template<typename T> void MACRO_VAR_Scan(T &t) {cin>>t;}
template<typename First, typename...Rest> void MACRO_VAR_Scan(First &first, Rest&...rest) {cin>>first;MACRO_VAR_Scan(rest...);}
#define VEC(type, c, n) vector<type> c(n);for(auto &&i:c)cin>>i;

// out
#define OUT(dist) cout<<(dist);
#define FOUT(n, dist) cout<<fixed<<setprecision(n)<<(dist);
#define SP cout<<" ";
#define BR cout<<endl;
#define zero(n) cout<<setfill('0')<<right<<setw(n)
#define debug(x) cerr<<#x<<":"<< (x);BR;

// utility
#define ALL(a) (a).begin(), (a).end()
#define EACH(i, a) for(auto &&i:(a))
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define RFOR(i, a, b) for(int i=(b)-1;i>=0;--i)
#define REP(i, n) for(int i=0;i<(n);++i)
#define RREP(i, n) for(int i=(n)-1;i>=0;--i)

signed main() {
  INIT;
	VAR(string,s);
	if(s.substr(0,4)>"2019") cout<<"TBD"<<endl;
	else if(s.substr(0,4)<"2019") cout<<"Heisei"<<endl;
	else {
		if(s.substr(5,2)>"04") cout<<"TBD"<<endl;
		else if(s.substr(5,2)<"04") cout<<"Heisei"<<endl;
		else {
			if(s.substr(8,2)>"30") cout<<"TBD"<<endl;
			else cout << "Heisei" << endl;
		}
	}
	
  return 0;
}


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

int main() {
    int l, r, d;
    cin >> l >> r >> d;
    int ans = 0;
    for (int i = l; i <= r; ++i) {
        if (i % d == 0) ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3648
import math
a,b = map(int,input().split())
flg = 1

for i in range(1,1001):
    x1 = math.floor(i*0.08)
    x2 = math.floor(i*0.10)
    if x1 == a and x2 == b:
        print(i)
        flg = 0
        break
    else:
        pass
    
if flg:
    print(-1)

Measured memory_bytes: 9160
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
int main() {
    int N;
    cin >> N;
    vector<int> L(N);
    rep(i,N){
        cin >> L.at(i);
    }
    sort(L.begin(),L.end());
    int i,j,k;
    int count = 0;
    for(i=0;i<N-2;i++){
        for(j=i+1;j<N-1;j++){
            for(k=j+1;k<N;k++){
                if(L.at(i) + L.at(j) > L.at(k) && L.at(i) != L.at(j) && L.at(j) != L.at(k)){
                    count++;
                }
            }
        }
    }

    cout << count << endl;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
#pragma region Macros
typedef long long ll;
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(x) (x).begin(),(x).end()
const long long MOD=1e9+7;
// const long long MOD=998244353;
const int INF=1e9;
const long long IINF=1e18;
const int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
const char dir[4]={'D','R','U','L'};
#define LOCAL

template<typename T>
istream &operator>>(istream &is,vector<T> &v){
    for (T &x:v) is >> x;
    return is;
}
template<typename T>
ostream &operator<<(ostream &os,const vector<T> &v){
    for (int i=0;i<v.size();++i){
        os << v[i] << (i+1==v.size()?"": " ");
    }
    return os;
}
template<typename T,typename U>
ostream &operator<<(ostream &os,const pair<T,U> &p){
    cout << '(' << p.first << ',' << p.second << ')';
    return os;
}
template<typename T,typename U>
ostream &operator<<(ostream &os,const map<T,U> &m){
    os << '{';
    for (auto itr=m.begin();itr!=m.end();++itr){
        os << '(' << itr->first << ',' << itr->second << ')';
        if (++itr!=m.end()) os << ',';
        --itr;
    }
    os << '}';
    return os;
}
template<typename T>
ostream &operator<<(ostream &os,const set<T> &s){
    os << '{';
    for (auto itr=s.begin();itr!=s.end();++itr){
        os << *itr;
        if (++itr!=s.end()) os << ',';
        --itr;
    }
    os << '}';
    return os;
}

void debug_out(){cerr << '\n';}
template<class Head,class... Tail>
void debug_out(Head&& head,Tail&&... tail){
    cerr << head;
    if (sizeof...(Tail)>0) cerr << ", ";
    debug_out(move(tail)...);
}
#ifdef LOCAL
#define debug(...) cerr << " ";\
cerr << #__VA_ARGS__ << " :[" << __LINE__ << ":" << __FUNCTION__ << "]" << '\n';\
cerr << " ";\
debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

template<typename T> T gcd(T x,T y){return y!=0?gcd(y,x%y):x;}
template<typename T> T lcm(T x,T y){return x/gcd(x,y)*y;}

template<class T1,class T2> inline bool chmin(T1 &a,T2 b){
    if (a>b){a=b; return true;} return false;
}
template<class T1,class T2> inline bool chmax(T1 &a,T2 b){
    if (a<b){a=b; return true;} return false;
}
#pragma endregion

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    char c; cin >> c;
    cout << (c<'a'?'A':'a') << '\n';
}

Measured memory_bytes: 3636
n = int(input())
a = input().split()
a = [int(i) for i in a]
a = sorted(a)

last = None
d = {}
for i in a:
  if last != i:
    d[i] = 1
    last = i
  else:
    d[i] += 1

out = -1
for x in range(a[0], a[-1]+1):
  s = 0
  if x-1 in d.keys():
    s += d[x-1]
  if x in d.keys():
    s += d[x]
  if x+1 in d.keys():
    s += d[x+1]
  if out < s:
    out = s
  
print(out)

Measured memory_bytes: 13964
#include <bits/stdc++.h>
#define chmin(a, b) ((a)=min((a), (b)))
#define chmax(a, b) ((a)=max((a), (b)))
#define fs first
#define sc second
#define eb emplace_back
using namespace std;
 
typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
 
const ll MOD=1e9+7;
const ll INF=1e18;
 
int dx[]={1, -1, 0, 0};
int dy[]={0, 0, 1, -1};


int main(){
    int m;
    cin >> m;
    string train;
    while(cin >> train){
        set<string> s;
        s.insert(train);
        for(int i = 1;i < train.length();i++){
            string a,b,t_a,t_b;
            for(int j = 0;j < i;j++){
                a += train[j];
            }
            for(int j = 0;j < i;j++){
                t_a += a[i - 1 - j];
            }
            for(int j = i;j < train.length();j++){
                b += train[j];
            }
            for(int j = 0;j < train.length() - i;j++){
                t_b += b[train.length() - i - 1 - j];
            }
            s.insert(a + b);
            s.insert(b + a);
          
            s.insert(t_a + t_b);
            s.insert(t_a + b);
            s.insert(a + t_b);
            s.insert(t_b + t_a);
            s.insert(t_b + a);
            s.insert(b + t_a);
        }
        cout << s.size() << endl;
    }
}


Measured memory_bytes: 3228
#include<bits/stdc++.h>
using namespace std;
#define faster_io ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long long ll;
#define bug(a)       cerr << #a << " : " << a << endl;
template<class T>void ExEuclid(T n, T m, T &a, T &b, T &gcd){if(m==0){gcd=n;a=1;b=0;return;}ExEuclid(m,n%m,a,b,gcd);T x=a;a=b;b=x-(n/m)*a;}
template<class T>T gcd(T n, T m){if(m==0){return n;}gcd(m,n%m);}
template<class T>T lcm(T n, T m){return (n*m)/gcd(n,m);}
template<class T>string to_string(T n){string s="";while(n)s+=((n%10)+'0'),n/=10;reverse(s.begin(),s.end());return s;}
template<class T>ll to_int(T s){ll num=0,power=0;for(int i=s.size()-1; i>=0; i--)num+=(pow(10.0,power++)*(s[i]-'0'));return num;}
template<class T>bool is_mod(T n, T m){if(n%m==0)return true;return false;}
template<class T>bool is_upper(T s){for(int i=0; i<s.size(); i++)if(s[i]>90 || s[i]<65)return false;return true;}
template<class T>bool is_lower(T s){for(int i=0; i<s.size(); i++)if(s[i]>122 || s[i]<97)return false;return true;}
template<class T>T mod(T n, T m){return ((n%m)+m)%m;}
template<class T>T Big_mod(T base, T power, T MOD){
    if(power==1)return base;
    if(power & 1)return ((base%MOD)*(Big_mod(base,power-1,MOD))%MOD)%MOD;
    else {T temp=(Big_mod(base,power>>1,MOD));return ((temp%MOD)*(temp%MOD))%MOD;}
}



int main()
{
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    faster_io;
    ll n,mx=1000000000,cnt=0;
    string s;
    cin>>s;
    char c='0';
    ll l=s.size(),mn=l;
    for(int i=0; i<l; i++){
        if(s[i]!=c)cnt++;
        if(c=='0')c='1';
        else c='0';
    }
    mn=cnt,cnt=0;
    c='1';
    for(int i=0; i<l; i++){
        if(s[i]!=c)cnt++;
        if(c=='0')c='1';
        else c='0';
    }
    cout<<min(cnt,mn)<<endl;
    return 0;
}




Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c=0,d=1;
  cin>>a>>b;
  while(d<b){
    d--;
    d=d+a;
    c++;
  }
    
 
  cout<<c<<endl;
  return(0);
}
    

Measured memory_bytes: 256
//AtCoder ABC067 B - Snake Toy
#include <bits/stdc++.h>
using namespace std;
using ll=int64_t;

int main() {
    ll N,K;
    cin>>N>>K;
    vector<ll> ltbl(N,0);
    for(auto&& l:ltbl){
        cin>>l;
    }
    sort(ltbl.begin(),ltbl.end(),greater<ll>());
    ll ans=0;
    for(int i=0;i<K;++i){
        ans+=ltbl[i];
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair<ll, ll> pll;
#define mod 1000000007
#define all(x) (x).begin(), (x).end()
#define call(x) (x).cbegin(), (x).cend()
#define pb push_back
#define yes(a) printf(a ? "yes\n" : "no\n")
#define Yes(a) printf(a ? "Yes\n" : "No\n")
#define YES(a) printf(a ? "YES\n" : "NO\n") 
const long double PI = acos(-1);
const long long INF = (1 << 30);
ll gcd(ll a,ll b){return b ? gcd(b,a%b) : a;}
ll lcm(ll a,ll b){return a / gcd(a,b) * b;}
ll stringcount(string s, char c){return count(s.cbegin(), s.cend(), c);}
bool isInteger(double x){return floor(x) == x;}
ll ceil(const ll a, const ll b){return ((a)+(b)-1)/b;}


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

  ll n, a, b;
  cin >> n >> a >> b;
  string s;
  cin >> s;

  ll cntab = 0, cntb = 0;
  for(ll i = 0; i < n; i++){
    if(s[i] == 'a'){
      if(cntab < a+b){
        cout << "Yes" << endl;
        cntab++;
      }else cout << "No" << endl;
    }else if(s[i] == 'b'){
      if(cntab < a+b && cntb < b){
        cout << "Yes" << endl;
        cntab++;
        cntb++;
      }else cout << "No" << endl;
    }else{
      cout << "No" << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 848
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

int main(){
  int l;
  cin >> l;
  double x = l/3.0;
  double ans = x*x*x;
  cout << fixed << setprecision(10) << ans << endl;
  return 0;
}

Measured memory_bytes: 3796
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long int n,x;
  cin >> n >> x;
  long long int a[n];
  for(int i=0; i<n; i++){
    cin >> a[i];
  }
  long long int cnt = 0;
  for(int i=0; i<n-1; i++){
    if(a[i]+a[i+1] > x){
      cnt += min(a[i+1],a[i]+a[i+1]-x);
      a[i+1] -= min(a[i+1],a[i]+a[i+1]-x);
        if(a[i]>x){
        cnt += a[i]-x;
        a[i] -= a[i]-x;
      }
      //for(int i=0; i<n; i++){
        //cout << a[i] << " ";
      //}
      //cout << endl;
    }
  }
  cout << cnt << endl;
}

Measured memory_bytes: 1024
// 基本テンプレート

#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define int long long int

template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}

typedef pair<int, int> pii;
typedef long long ll;

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
constexpr ll INF = 1001001001001001LL;
constexpr ll MOD = 1000000007LL;

int N, x;
int s[] = {1, 0, -1, 2}, t[] = {-1, 0, 1, -2};

signed main() {
    cin >> N >> x;
    if(x == 1 || x == 2*N-1) cout << "No" << endl;
    else {
        cout << "Yes" << endl;
        vector<int> v(2*N-1);
        int center = N-1;
        set<int> S;
        if(x == 2) {
            rep(i,0,4) {
                if(center-1+i < 0 || center-1+i >= 2*N-1) continue;
                v[center-1+i] = x+s[i];
                S.insert(x+s[i]);
            }
        }
        else {
            rep(i,0,4) {
                if(center-1+i < 0 || center-1+i >= 2*N-1) continue;
                v[center-1+i] = x+t[i];
                S.insert(x+t[i]);
            }
        }

        int val = 1;
        rep(i,0,2*N-1) {
            if(v[i] != 0) continue;
            while(S.count(val)) val++;
            v[i] = val;
            S.insert(val);
        }
        rep(i,0,2*N-1) cout << v[i] << endl;
    }
    return 0;
}

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

int main () {
  int n;
  cin >> n;
  priority_queue<long long> pq;
  for(int i=0;i<n;i++){
    int a;
    cin >> a;
    pq.push(a);
  }
  queue<long long> q;
  long long ans=0;
  q.push(pq.top());
  pq.pop();
  while(!pq.empty()){
    q.push(pq.top());
    q.push(pq.top());
    pq.pop();
    ans+=q.front();
    q.pop();
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 6404
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

int main(){

	int n, m, x, y, xma=-110, ymi=110, inn;

	cin>> n >> m >> x >> y;

	for(int i=0;i<n;i++){
		cin>> inn;
		xma=max(xma, inn);
	}
	for(int i=0;i<m;i++){
		cin>> inn;
		ymi=min(ymi, inn);
	}

	for(int i=x+1;i<=y;i++){
		if(xma<i && i<=ymi){
			cout<< "No War" << endl;
			return 0;
		}
	}

	cout<< "War" << endl;


}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys


def solve(A: int, B: int):
    if A <= 2 * B:
        print(0)
    else:
        print(A - 2 * B)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word

    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    solve(A, B)


if __name__ == "__main__":
    main()


Measured memory_bytes: 2940
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using ll = int64_t;
using ld = long double;
using ull = uint64_t;
using namespace std;
using namespace __gnu_pbds;

string s[302];

int main() {
#ifdef PAUNSVOKNO
    freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); cout.setf(ios::fixed); cout.precision(20);  
    int n;
    cin >> n;
    ll s = 0;
    map<ll, int> m = { {0, 1} };
    ll ans = 0;
    for (int i = 0; i < n; ++i) {
        int x;
        cin >> x;
        ans += m[s += x]++;
    }

    cout << ans << "\n";
}

Measured memory_bytes: 12800