akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

#define pb         push_back

typedef long long ll;
const ll INF = 1000000000000000000ll;
const ll MOD = 1000000007ll;
const double EPS = 1e-8;

long long gcd(long long a, long long b){
  long long c;
  while ( a != 0 ) {
	 c = a; a = b%a; b = c;
  }
  return b;
}

const int MAX_N = 100;
ll fact[MAX_N];
ll factinv[MAX_N];
ll ans = 0;
long long mod_pow(long long x, long long n, long long mod){
	long long res = 1;
	while(n > 0){
		if(n & 1) res = res * x % mod;
		x = x*x % mod;
		n >>= 1;
	}
	return res;
}

//???????????????????????????
void make_fact_tbl(long long n, long long mod){
	fact[0] = 1;
	for(long long i=1; i<=n; i++){
		fact[i] = fact[i-1] * i;
		fact[i] %= mod;
	}
}

//????????????????????????????????????
void make_factinv_tbl(long long n, long long mod){
	factinv[0] = 1; //0?????????????????¨?????????
	for(long long i=1; i<=n; i++){
		factinv[i] = mod_pow(fact[i], mod-2, mod);
	}
}

//???????????????????¨?????????????????????±?????????
void comb_init(long long n, long long mod){
	make_fact_tbl(n, mod);
	make_factinv_tbl(n, mod);
}

//???????????????????¨????
long long comb(long long n, long long k, long long mod){
	if(n < k) return 0;
	if(k == 0 || n-k == 0) return 1;
	//printf("n:%lld k:%lld n-k:%lld\n", fact[n], factinv[k], factinv[n-k]);
	return ((fact[n] * factinv[k]) % mod) * factinv[n-k] % mod;
}

vector<int> x;
vector<int> y;

void dfs(int idx, queue<int> nouse, map<pair<int, int>, int> para){
	int num = nouse.size();
	//printf("num: %d\n", num);
	for(int i=0; i<num; i++){
		queue<int> next = nouse;
		map<pair<int, int>, int> next_para = para;
		int tgt = next.front();
		next.pop();
		nouse.pop();
		nouse.push(tgt);

		pair<int, int> a;
		if(x[tgt] == x[idx]){
			//printf("%d %d %lld\n", tgt, idx, x[tgt]);
			a = make_pair(1, 0);
		}else if(y[tgt] == y[idx]){
			a = make_pair(0, 1);
		}else{
			ll dy = y[tgt] - y[idx];
			ll dx = x[tgt] - x[idx];
			a = make_pair(dy/gcd(dy, dx), dx/gcd(dy, dx));
		}
		next_para[a] += 1;

		if(next.size() != 0){
			int src = next.front();
			next.pop();
			dfs(src, next, next_para);
		}else{
			//????????¶????????????????????¨
			ll cnt = 0;
			for(auto it=next_para.begin(); it != next_para.end(); it++){
				//printf("second:%d\n", it->first);
				if(it->second >= 2){
					cnt += comb(it->second, 2, MOD);
				}
			}

			ans = max(ans, cnt);
		}
	}
}

int main(void) {
	//ios_base::sync_with_stdio(false);
	//cin.tie(0);
	comb_init(30, MOD);

	int m;
	cin >> m;

	queue<int> nouse;
	for(int i=0; i<m; i++){
		int tx, ty;
		cin >> tx >> ty;
		x.pb(tx);
		y.pb(ty);

		nouse.push(i);
	}
	map<pair<int, int>, int> para;
	nouse.pop();
	dfs(0, nouse, para);
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 3184
import java.util.*;

public class Main {

	public static void main(String[] args) {

	Scanner s = new Scanner(System.in);
		int m = s.nextInt();
		int n = s.nextInt();

		ArrayList<Integer> arr = new ArrayList<Integer>();
		int sum = 0;
		for (int i = 0; i < n; i++)
			sum += s.nextInt();

		if (sum > m)
			System.out.println(-1);
		else
			System.out.println(m - sum);
}

}


Measured memory_bytes: 46580
dishes = []
5.times do
  dishes.push(gets.to_i)
end

dishes = dishes.sort_by{|i| (i - 1) % 10}

ans = dishes[0]
(1..4).each do |i|
  if dishes[i] % 10 == 0
    ans += dishes[i]
  else
    ans += (dishes[i] + (10 - dishes[i] % 10))
  end
end

puts ans

Measured memory_bytes: 1788
/**
n×m  の行列 A  と m×l  の行列 B  を入力し、それらの積である n×l  の
 を出力するプログラムを作成してください。行列 C  の各要素 c ij   は次の式で得られます：

 １行目に n 、m 、l  が空白区切りで与えられます。

続く行に n×m  の行列 A  と m×l  の行列 B  が与えられます。

 */

//スキャナつかうため

import java.util.Scanner;

public class Main {
	// プログラムのエントリポイント
	public static void main(String[] args) {
		// 入力ストリームの生成
		Scanner sc = new Scanner(System.in);
		// 3つの数値を受け取る
		int intN = sc.nextInt();
		int intM = sc.nextInt();
		int intL = sc.nextInt();
		// 受け取った数値で配列をつくる
		// Aの行列
		int[][] gyoua = new int[intN][intM];
		// Bの行列
		int[][] gyoub = new int[intM][intL];
		// Cの行列
		long[][] gyouc = new long[intN][intL];
		// 数値をAの配列の数受け取る
		for (int i = 0; i < intN; i++) {
			for (int j = 0; j < intM; j++) {
				gyoua[i][j] = sc.nextInt();
			}
		}
		// Bの配列の数数値を受け取る
		for (int i = 0; i < intM; i++) {
			for (int j = 0; j < intL; j++) {
				gyoub[i][j] = sc.nextInt();
			}
		}
		// 計算
		for (int i = 0; i < intN; i++) {
			for (int j = 0; j < intL; j++) {

				for (int k = 0; k < intM; k++) {
					// Cの配列に計算結果を入れていく
					gyouc[i][j] += gyoua[i][k] * gyoub[k][j];
				}
				System.out.print(gyouc[i][j]);
				if (j != intL - 1) {
					// 空白
					System.out.print(" ");
				}
			}
			// 改行
			System.out.println();
		}

	}
}

Measured memory_bytes: 44924
#include<bits/stdc++.h>
#pragma warning(disable:4996)
using namespace std;
using ll = long long;
using ld = long double;
const int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
//const long double PI = acos(-1.0);
#define int long long
signed main() {
	int n;
	cin >> n;
	vector<int>v(n);
	for (int i = 0; i < n; i++) {
		cin >> v[i];
	}
	int r = 0;
	int now_sum = 0;
	int now_xor = 0;
	ll ans = 0;
	for (int l = 0; l < n; l++) {
		while (r < n && (now_sum + v[r]) == (now_xor^v[r])) {
			now_sum += v[r];
			now_xor ^= v[r];
			r++;
		}
		ans += r - l;
		now_sum -= v[l];
		now_xor ^= v[l];//(A xor B xor C) xor B = (A xor C)
	}

	cout << ans << endl;
}

Measured memory_bytes: 1792
import java.io.*;
import java.util.*;
public class    Main      {
	public static void main(String[] args) 
	{
		InputReader in = new InputReader(System.in);
		PrintWriter w = new PrintWriter(System.out);
		Scanner sc = new Scanner(System.in);
		int n = in.nextInt();
		int k=in.nextInt();
		int res=1;
		for (int i = 0; i < n; i++) {
			if (res*2>res+k) {
				res=res+k;
			}
			else
				res=res*2;
		}
		System.out.println(res);
		//w.println(res);
		w.close();
		sc.close();
	}
	static class InputReader {
		private final InputStream stream;
		private final byte[] buf = new byte[8192];
		private int curChar, snumChars;
		public InputReader(InputStream st) {
			this.stream = st;
		}
		public int read() {
			if (snumChars == -1)
				throw new InputMismatchException();
			if (curChar >= snumChars) {
				curChar = 0;
				try {
					snumChars = stream.read(buf);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (snumChars <= 0)
					return -1;
			}
			return buf[curChar++];
		}
		
		public int nextInt() {
			int c = read();
			while (isSpaceChar(c)) {
				c = read();
			}
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			int res = 0;
			do {
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}
		
		public long nextLong() {
			int c = read();
			while (isSpaceChar(c)) {
				c = read();
			}
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			long res = 0;
			do {
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}
		
		public int[] nextIntArray(int n) {
			int a[] = new int[n];
			for (int i = 0; i < n; i++) {
				a[i] = nextInt();
			}
			return a;
		}
		
		public String readString() {
			int c = read();
			while (isSpaceChar(c)) {
				c = read();
			}
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isSpaceChar(c));
			return res.toString();
		}
		
		public String nextLine() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isEndOfLine(c));
			return res.toString();
		}
		
		public boolean isSpaceChar(int c) {
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}
		
		private boolean isEndOfLine(int c) {
			return c == '\n' || c == '\r' || c == -1;
		}
		
	}
	
}

Measured memory_bytes: 21844
#include <assert.h>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <algorithm>
#include <numeric>
#include <functional>
#include <iostream>
#include <string>
#include <array>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <complex>
#include <bitset>
typedef long long ll;
typedef unsigned long long ull;

# define INF 0x3f3f3f3f

#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define DEBUG(vec) for (auto v : vec) { cout << v << " "; } cout << endl;

using namespace std;

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

  ll N, K;
  cin >> N >> K;
  ll zero = 0;
  ll two = 0;
  for (int i = 1; i <= N; i++) {
    if (i % K == 0) {
      zero++;
    }
    if (i % K == K / 2) {
      two++;
    }
  }
  if (K % 2 == 0) {
    cout << zero * zero * zero + two * two * two << endl;
  } else {
    cout << zero * zero * zero << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<bitset>
#include<vector>
#include<deque>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cmath>
#include<iomanip>
#include <functional>
using namespace std;
typedef long long ll;
const int mod = 1000000007;
const int INF = 1 << 30;
const double EPS = 1e-10;
//cout << fixed << std::setprecision(9)
//memset(a, 0, sizeof(a));
//--------------------------

int a, b, c;

int main()
{
	cin >> a >> b >> c;
	if ( (b - a) == (c - b) ) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}

	return 0;
}


Measured memory_bytes: 256
// SeeAlso: 

#include <bits/stdc++.h>

using namespace std;

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

#define MAX 100000
#define NIL -1
#define MOD 1000000007

typedef int _loop_int;
#define rep(i,n) for(int i = 0; i < n; i++)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define debug(x) cout<<#x<<": "<<x<<endl
#define debig_vec(v) cout<<#v<<":";rep(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

// 最大公約数
inline constexpr ll gcd(ll a,ll b){if(!a||!b)return 0;while(b){ll c=b;b=a%b;a=c;}return a;}
// 最小公倍数
inline constexpr ll lcm(ll a,ll b){if(!a||!b)return 0;return a*b/gcd(a,b);}

#define print2D(h, w, arr) rep(i, h) { rep(j, w) cout << arr[i][j] << " "; cout << endl; }
template<class T> void print(const T& x){cout << setprecision(12) << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }

int main() {
    int a,b;
    cin >> a >> b;    
    int ans = max(a*b, max(a+b, a-b));
    print(ans);
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  char a;
  cin >> a;
  if(a == 'A'){
    cout << 'T' << endl;
  }
  else if(a == 'T'){
    cout << 'A' << endl;
  }
  else if(a == 'G'){
    cout << 'C' << endl;
  }
  else if(a == 'C'){
    cout << 'G' << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//typedef int64_t int;
#define all(x) x.begin(), x.end()
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define precise cout.precision(10); cout << fixed;
#define pb push_back
#define mk make_pair
#define endl "\n"
#define int int64_t
#define ll long long
#define in(num,n) std::vector<int> num(n); for (int i = 0; i < n; i++)cin >> num[i]
const ll Inf = 1e9 + 7;
std::vector<int> num;
std::vector<int> vis(1e5 + 1, -1);
int n, k;
int DP(int i) {
    if (vis[i] != -1)
        return vis[i];
    if (i == num.size() - 2) {
        return abs(num[i] - num[i + 1]);
    }

    if (i == num.size() - 1)
        return 0;
    int ans = 1e9;
    for (int j = 1; j <= k; j++) {
        if ((i + j) < n)
            ans = min(ans, DP(i + j) + abs(num[i + j] - num[i]));
    }

    return vis[i] = ans;
}



void solve() {


    cin >> n >> k;
    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        num.push_back(x);
    }
    cout << DP(0) << endl;



}


int32_t main()
{
    fastio;
    precise;

    //int test; cin >> test; while (test--)
    solve();
    return 0;
}

Measured memory_bytes: 9472
using System;

class MainClass
{
    public static void Main()
    {
        int[][] scoreJaggedArray = new int[0][];

        while (true)
        {
            int[] inputs = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
            if (inputs.Length != 3 || (inputs[0] == -1 && inputs[1] == -1 && inputs[2] == -1))
                break;

            Array.Resize(ref scoreJaggedArray, scoreJaggedArray.Length + 1);
            scoreJaggedArray[scoreJaggedArray.Length - 1] = inputs;
        }

        for (int i = 0; i < scoreJaggedArray.Length; i++)
        {
            if (scoreJaggedArray[i][0] == -1 || scoreJaggedArray[i][1] == -1)
                Console.WriteLine('F');
            else if (scoreJaggedArray[i][0] + scoreJaggedArray[i][1] >= 80)
                Console.WriteLine('A');
            else if (65 <= scoreJaggedArray[i][0] + scoreJaggedArray[i][1] && scoreJaggedArray[i][0] + scoreJaggedArray[i][1] < 80)
                Console.WriteLine('B');
            else if (50 <= scoreJaggedArray[i][0] + scoreJaggedArray[i][1] && scoreJaggedArray[i][0] + scoreJaggedArray[i][1] < 65 || scoreJaggedArray[i][2] >= 50)
                Console.WriteLine('C');
            else if (30 <= scoreJaggedArray[i][0] + scoreJaggedArray[i][1] && scoreJaggedArray[i][0] + scoreJaggedArray[i][1] < 50)
                Console.WriteLine('D');
            else if (scoreJaggedArray[i][0] + scoreJaggedArray[i][1] < 30)
                Console.WriteLine('F');
        }
    }
}

Measured memory_bytes: 8952
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin>>N;
  vector<int64_t> data(N+1);
  data.at(0)=2;
  data.at(1)=1;
   for(int i=2;i<N+1;i++){
    data.at(i)=data.at(i-1)+data.at(i-2);
   } 
  cout<<data.at(N)<<endl;
}




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

bool ok[100150];
int ans[600][600];
using namespace std;

int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N,k=2,big=0;
	cin >> N;
	if(N==1){
		cout << "Yes" << endl;
		cout << 2 << endl;
		cout << 1 << " " << 1 << endl;
		cout << 1 << " " << 1 << endl;
		return 0;
	}
	int cnt=1;
	int g = 2;
	vector<int> test;
	while(cnt+g<=N){
		ok[cnt+g] = 1;
		test.push_back(cnt+g);
		cnt = cnt+g;
		g++;
		k++;
		big= cnt + g;
	}
	ans[0][0] = 1;
	ans[0][1] = 2;
	ans[1][0] = 2;
	ans[1][1] = 3;
	ans[2][0] = 3;
	ans[2][1] = 1;
	int a = 4;
	for(int i=3;i<600;i++){
		for(int j=0;j<i;j++){
			ans[i][j] = a;
			a++;
		}
	}
	a = 4;
	for(int i=2;i<600;i++){
		for(int j=0;j<i+1;j++){
			ans[j][i] = a;
			a++;
		}
	}
	if(ok[N]){
		cout << "Yes" << endl;
		cout << k << endl;
		for(int i=0;i<k;i++){
			cout << k-1 << " ";
			for(int j=0;j<k-1;j++){
				cout << ans[i][j] <<" ";
			}
			cout << endl;
		}
	}else{
		cout << "No" << endl;
	}
}

Measured memory_bytes: 2944
a = input()
b = int(input())
ar = set(list(a))
arr = sorted(ar)
br = []
for i in range(len(a)):
    if a[i] == arr[0]:
        try:
            for j in range(1,b+1):
                br.append(a[i:i+j])
        except indexError:
            break
cr = set(br)
if len(cr) < b:
    for i in range(len(a)):
        if a[i] == arr[1]:
            try:
                for j in range(1,b+1):
                    br.append(a[i:i+j])
            except indexError:
                break
dr = set(br)
er = sorted(dr)
print(er[b-1])

Measured memory_bytes: 4340
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

//long longのシフト演算には気をつけよう

const int MAX = 100;
const ll INF = (1LL<<32);

int n;
ll d[MAX][MAX];

void floyd(){
    for(int k=0; k<n; k++){
        for(int i=0; i<n; i++){
            if(d[i][k] == INF) continue;
            for(int j=0; j<n; j++){
                if(d[k][j] == INF) continue;
                d[i][j] = min(d[i][j], d[i][k]+d[k][j]);
            }
        }
    }
}

int main(){
    int e,u,v,c; cin >> n >> e;

    for(int i=0; i<n; i++) for(int j=0; j<n; j++) d[i][j] = ((i == j)? 0 : INF);

    for(int i=0; i<e; i++){
        cin >> u >> v >> c;
        d[u][v] = c;
    }

    floyd();

    bool negative = false;
    for(int i=0; i<n; i++) if(d[i][i] < 0) negative = true;

    if(negative){
        cout << "NEGATIVE CYCLE" << endl;
    }
    else{
        for(int i=0; i<n; i++){
            for(int j=0; j<n; j++){
                if(j) cout << " ";
                if(d[i][j] == INF) cout << "INF";
                else cout << d[i][j];
            }
            cout << endl;
        }
    }
}



Measured memory_bytes: 3172
#include<bits/stdc++.h>
#define ll  long long
#define ff first
#define ss second
#define pb push_back
#define mp make_pair

using namespace std;
ll ma=1000000007;
ll power(ll p,ll t){
if(t==0)
    return 1;
ll y=power(p,t/2);
y=(y*y)%ma;
if(t%2==1)
    y=(y*p)%ma;
return y;
}


int mod(int a){
if(a>=0)
    return a;
else return -a;
}


ll b[200001];
bool comp(int x,int y){
return b[x]<b[y];
}


 int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin>>n;
ll a[n];
vector<int> c;
for(int i=0;i<n;i++){
    cin>>a[i]>>b[i];
c.pb(i);
}
    sort(c.begin(),c.end(),comp);

ll x=0;
for(int i=0;i<n;i++){
    int y=c[i];
    x+=a[y];
    if(b[y]<x){
        cout<<"No"<<endl;
        return 0;
    }

}
cout<<"Yes"<<endl;


}











Measured memory_bytes: 4340
#include <iostream>

#define ll long long
#define INF 100000000000000

using namespace std;

ll calc(ll H, ll W) {
  ll s1, s2, s3;
  ll mxs, mns;
  ll res = INF;
  for (int i = 1; i < H; i++) {
    s1 = i * W;
    s2 = (H - i) * (W / 2);
    s3 = (H - i) * (W - (W / 2));
    mxs = max(s1, max(s2, s3));
    mns = min(s1, min(s2, s3));
    res = min(res, mxs - mns);
  }

  s1 = (H / 3) * W;
  s2 = (H - (H / 3) * 2) * W;
  res = min(res, abs(s1 - s2));

  return res;
}

int main() {
  ll H, W;
  cin >> H >> W;

  ll ans = min(H, W);
  ans = min(ans, calc(H, W));
  ans = min(ans, calc(W, H));

  cout << ans << endl;
}


Measured memory_bytes: 256
n = int(input())
matrix = [[ 0 for i in range(10)] for j in range(10)]

for i in range(n+1):
    matrix[int(str(i)[0])][int(str(i)[-1])] +=1

cnt = 0
for i in range(1,10):
    for j in range(1,10):
        cnt += matrix[i][j]*matrix[j][i]
print(cnt)

Measured memory_bytes: 3188
#include <stdio.h>
#define MAX 500001

void exchange(int *,int *);
void maxHeapify(int *,int,int);
void buildMaxHeap(int *,int);

int main(){
  int A[MAX],k,i;
  scanf("%d",&k);
  for(i=1;i<=k;i++) {scanf("%d",&A[i]);}
  buildMaxHeap(A,k);
  for(i=1;i<=k;i++) {printf(" %d",A[i]);}
  printf("\n");
  return 0;
}

void exchange(int *a,int *b){
  int temp;
  temp=*a;
  *a=*b;
  *b=temp;
}

void maxHeapify(int A[],int i,int H){
  int c,d,largest;
  c = 2*i;
  d = 2*i+1;
  
  if (c <= H && A[c] > A[i]){ largest = c; }
  else 	{largest = i;}
  if (d <= H && A[d] > A[largest])
   { largest = d; }
  if (largest != i){ 
    exchange(&A[i],&A[largest]);
    maxHeapify(A, largest,H); 
  }
}

void buildMaxHeap(int A[],int H){
  int i;
  for (i = H/2;i>=1;i--){
    maxHeapify(A,i,H);
  }
}



Measured memory_bytes: 3672
#include<bits/stdc++.h>
#include<algorithm>
#include<math.h>
#include<string>
#include<iostream>
#include<vector>
#include<cstdlib>
using namespace std;
 
template <class T> using V = vector<T>;
 
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
 
const long long INF = 1LL << 60;
 
using ll = long long;
using db = double;
using st = string;
using ch = char;
using bl = bool;
using vll = V<ll>;
using vpll =V<pair<ll,ll>>;
using vst = V<st>;
using vdb = V<db>;
using vch = V<ch>;
using vbl = V<bl>;
 
 
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define rFOR(i,a,b) for(ll i=(a);i>(b);i--)
#define oFOR(i,a,b) for(ll i=(a);i<(b);i+=2)
#define bgn begin()
#define en end()
#define SORT(a) sort((a).bgn,(a).en)
#define REV(a) reverse((a).bgn,(a).en)
#define M(a,b) max(a,b)
#define rM(a,b) min(a,b)
#define fi first
#define se second
#define sz size()
#define gcd(a,b) __gcd(a,b)
#define co(a) cout<<a<<endl;
#define ci(a) cin>>a;
 

vll dp(100100);

ll sum(ll n) {
  ll m=0;
  FOR(i,0,20){
    m+=n%10;
    n/=10;
    if(n==0){
      break;
    }
  }
  return m;
}
 
 
const int MAX = 510000;
const int MOD = 1000000007;
 
long long fac[MAX], finv[MAX], inv[MAX];
 
void Comuse() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
 
 
#define comuse Comuse()
 
ll combi(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
 
 
 
 
ll lcm(ll a,ll b){
  ll n;
  n=a/gcd(a,b)*b;
  return n;
}
 
 
/****************************************\
| Thank you for viewing my code:)        |
| Written by RedSpica a.k.a. RanseMirage |
| Twitter:@asakaakasaka                  | 
\****************************************/
 
 
signed main() {
  st s;
  	ci(s);
  if(s.sz==2){
    co(s)
  }
  else{
    REV(s);
    co(s)
  }
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)


void solve(long long D){
    if(D==25) cout << "Christmas" << endl;
    if(D==24) cout << "Christmas Eve" << endl;
    if(D==23) cout << "Christmas Eve Eve" << endl;
    if(D==22) cout << "Christmas Eve Eve Eve" << endl;
}

int main(){

    long long D;
    scanf("%lld",&D);
    solve(D);
    return 0;
}



Measured memory_bytes: 256
N,K=list(map(int,input().split()))
S=input()

if S[K-1]=="A":
    print(S[:K-1]+"a"+S[K:])
elif S[K-1]=="B":
    print(S[:K-1]+"b"+S[K:])
elif S[K-1]=="C":
    print(S[:K-1]+"c"+S[K:])


Measured memory_bytes: 3060
N, M = map(int, input().split())
p = [int(i) for i in input().split()]
t = [[] for _ in range(N+1)]
for _ in range(M):
    x, y = [int(i) for i in input().split()]
    t[x].append(y)
    t[y].append(x)
l = [0]*(N+1)
stack = []
seen = [False]*(N+1)
c = 1
for i in range(1, N+1):
    if not seen[i]:
        stack.append(i)
        seen[i] = True
        c = i
    while len(stack):
        n = stack.pop()
        l[n] = c
        for v in t[n]:
            if not seen[v]:
                stack.append(v)
                seen[v] = True
ans = 0
for i, n in enumerate(p):
    if l[i+1] == l[n]:
        ans += 1
print(ans)


Measured memory_bytes: 73452
/**
 *     ____              _    
 *    / __ \____ _____  (_)___
 *   / /_/ / __ `/ __ \/ /_  /
 *  / _, _/ /_/ / /_/ / / / /_
 * /_/ |_|\__,_/ .___/_/ /___/
 *            /_/             
 *           code@rapiz.me
*          Sat, 24 Aug 2019 21:15:02 +0800
 */
#include <bits/stdc++.h>
#define xxx(x) cerr<<(#x)<<": "<<x<<endl;
#define iosfast ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
typedef long long ll;
using namespace std;
const ll MOD = 1e9 + 7;
const int N = (1e5 + 10)*2;
string s;
int a[N], n, c[N][2];
// 0 left, 1 right
int main() {
  cin >> n >> s;
  if (s[0] == 'W' || s[(int)s.size()-1] == 'W') {
    cout << 0 << endl;
    return 0;
  }
  s = 'X' + s;
  a[1] = 0;
  for (int i = 2; i <= 2*n; i++) {
    if (s[i] == s[i-1]) {
      a[i] = a[i-1]^1;
    }
    else {
      a[i] = a[i-1];
    }
  }
  for (int i = 1; i <= 2*n; i++){
    c[i][0] = c[i-1][0];
    c[i][1] = c[i-1][1];
    c[i][a[i]]++;
  }
  if (c[2*n][0] != c[2*n][1]) {
    cout << 0 << endl;
    return 0;
  }
  ll cnt = 1;
  for (int i = 2; i <= 2*n ;i++ ){
    if (a[i] == 1) {
      cnt*= c[i-1][0] - c[i-1][1];
      cnt %= MOD;
    }
  }
  ll fac = 1;
  for (int i = 1; i <= n; i++) {
    fac = (fac*i)%MOD;
  }
  cout << (cnt*fac)%MOD;
}

Measured memory_bytes: 2884
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		//Aの価格
		int A = sc.nextInt();
		//Bの価格
		int B = sc.nextInt();
		//ABの価格
		int C = sc.nextInt();
		//必要なAの枚数
		int X = sc.nextInt();
		//必要なBの枚数
		int Y = sc.nextInt();

		int max = Math.max(X, Y);

		int result = C * 2 * max;

		//Aの枚数
		int x = max;
		//Bの枚数
		int y = max;

		for(int i=0; i<max; i++) {
			//ABを一枚減らしてAかBの片方もしくは両方を一枚増やしたときの合計価格
			int temp = result;
			temp -= 2 * C;
			if(--x<X) {
				x++;
				temp += A;
			}
			if(--y<Y) {
				y++;
				temp += B;
			}

			if(temp >= result) {
				break;
			} else {
				result = temp;
			}
		}

		System.out.println(result);

	}



}


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

namespace ConsoleApp6
{
    class Program
    {
        static void Main(string[] args)
        {
            int count = int.Parse(Console.ReadLine());
            List<Temp> array = new List<Temp>();
            for (int i = 0; i < count; i++)
            {
                array.Add(new Temp() { Index = i, Value = int.Parse(Console.ReadLine()) });
            }

            // 単純に1版大きいのは同じでそのindexの時だけ2番目が必要
            var groups = array.OrderByDescending(item => item.Value).GroupBy(item => item.Value);
            var indicies = groups.First().Select(group => group.Index);
            var first = groups.First().Key;


            // 2つ以上ある場合はすべて同じ値
            if (indicies.Count() > 1)
            {
                for (int i = 0; i < count; i++)
                {
                    Console.WriteLine(first);
                }
            }
            // 1つしかないときは必ず2爪がある
            else
            {
                var second = groups.ElementAt(1).Key;
                for (int i = 0; i < count; i++)
                {
                    Console.WriteLine(indicies.Contains(i) ? second : first);
                }

            }
        }
    }
    struct Temp { public int Index { get; set; } public int Value { get; set; } }
}


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

int main(){
	int n; //<30000 なのでN^2までか・・・
	if(scanf("%d", &n)==EOF){return 0;}
	
	char s[n+1];
	if(scanf("%s", s)==EOF){return 0;}
	
	
	int ten [10] = {0};
	
	//数だけではなく数字も記録する必要がありそうな・・・
	int left[n][10];
	int right[n][10]; 
	memset(left, 0, sizeof(left));
	memset(right, 0, sizeof(right));
	
	for(int i = 0; i< n-1; i++){
		if(ten[(int)s[i]-48] == 0){
			ten[(int)s[i]-48] = 1;
			for(int j = i+1; j< n; j++){
				left[j][(int)s[i]-48] = 1;
			}
		}	
	}
	
	memset(ten, 0, sizeof(ten));
	
	for(int i = n-1; i > 0; i--){
		if(ten[(int)s[i]-48] == 0){
			ten[(int)s[i]-48] = 1;
			for(int j = i-1; j >= 0; j--){
				right[j][(int)s[i]-48] = 1;
			}
		}	
	}
	
	/*
	
	printf("left\n");
	for(int i = 0; i<n; i++){
		for(int j = 0; j <10; j++ ){printf("%d ", left[i][j]);}
		printf("\n");
	}
	
	printf("right\n");
	for(int i = 0; i<n; i++){
		for(int j = 0; j <10; j++ ){printf("%d ", right[i][j]);}
		printf("\n");
	}
	*/
	
	int check[10][10][10]= {0};
	int count = 0;
	
	for(int i = 1; i < n-1; i++){
		int center = (int)s[i]-48;
		for(int j = 0; j <10; j++ ){
			for(int k = 0; k <10; k++ ){
				if(check[j][center][k] == 0){
					if(left[i][j] == 1 && right[i][k] == 1){
						check[j][center][k] =1;
						//printf("%d%d%d\n", j,center, k);
						count ++;
					}
				}
			}	
		}
	}

	printf("%d\n", count);
	return 0;

}


	/*
	全探索 O(N^3)
	//for(int i = 0; i< n; i++){printf("%d ", (int)s[i]);}
	//printf("%d\n", check[(int)s[n-3]-48] [(int)s[n-2]-48] [(int)s[n-1]-48]);
	for(int i = 0; i< n-2; i++){
		for(int j = i+1; j< n-1; j++){
			for(int k = j+1; k< n; k++){
				if(check[(int)s[i]-48] [(int)s[j]-48] [(int)s[k]-48] ==0){
					check[(int)s[i]-48] [(int)s[j]-48] [(int)s[k]-48] =1;
					count ++;
					//printf("%d, ", count);
				}
			}	
		}
	}*/

Measured memory_bytes: 4092
#include <iostream>

using namespace std;


int main() {
	int n,x;

	cin >> n >> x;

	if (x == 1 || x == 2 * n -1) {
		cout << "No" << endl;
		return 0;
	}
	cout << "Yes" << endl;

	int len = 2 * n - 1;

	int s = (x - n + 1 + len) % len;
	if (s == 0) {
		s = len;
	}

	for (int i = 0; i < 2 * n - 1; i++) {
		cout << s << endl;
		s++;
		if (s > len) {
			s = 1;
		}
	}
	return 0;
}

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

#define ll long long;

int main(){
    int N, M, s[100];
    long long sum = 0;
    // vector<int> T(100, 0);
    // vector<int> P(100, 0);
    // vector<int> X(100, 0);
    cin >> N;
    for(int i = 0; i < N; ++i){
        cin >> s[i];
        sum += s[i];
    }
    cin >> M;
    for(int i = 0; i < M; ++i){
        int a, b;
        cin >> a >> b;
        cout << sum + b -s[a-1] <<endl;
    }
    // for(int i=0; i < N; i++){
    //     cin >> T[i];
    //     sum += T[i];
    // }
    // cin >> M;
    // for(int i = 0; i < M; i++){
    //     cin >> P[i] >> X[i];
    //     cout << sum + X[i] - T[P[i]] << endl;
    // }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repd(i,a,b) for (int i = (a); i < (b); i++)
#define INF LLONG_MAX
#define mod 1000000007
typedef long long ll;
int main(void)
{
	int N, K;
	cin >> N >> K;
	vector<int> p(N);
	vector<double> a(N);
	rep(i, N) cin >> p[i];
	double sum=0, max=0;
	rep(i, N) a[i] = (double)(p[i]*(p[i]+1)/2)/p[i];

	rep(i, K) sum += a[i];
	max = sum;
	repd(i, K, N)
	{
		sum -= a[i-K];
		sum += a[i];
		if(max<sum) max = sum;
	}
	cout<<fixed<<setprecision(10);
	cout << max << endl;
}


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

int main() {
  int A, B, C;
  cin >> A >> B >> C;
  if(A==5&&B==7&&C==5){
    cout << "YES" << endl;
  }
  else if(A==5&&B==5&&C==7){
    cout << "YES" << endl;
  }
  else if(A==7&&B==5&&C==5){
    cout << "YES" << endl;
  }
  else{
    cout <<"NO"<<endl;
  }
}


Measured memory_bytes: 256
#include <ctype.h>
#include <limits.h>
#include <math.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define min(a, b) ((a) < (b) ? (a) : (b))

static void reverse(char *s, size_t len) {
  for (int i = 0; i < len >> 1; i++) {
    int j = len - i - 1;
    char w = s[i];
    s[i] = s[j];
    s[j] = w;
  }
}

int main(int argc, char **argv) {
  char n[1000003];
  n[0] = '0';
  scanf("%s", n + 1);
  int m = strlen(n);
  reverse(n, m);
  int dp[m + 1][2];
  for (int i = 0; i < m + 1; i++) {
    dp[i][0] = 100000000;
    dp[i][1] = 100000000;
  }
  dp[0][0] = 0;
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < 2; j++) {
      int d = n[i] - '0' + j;
      if (d < 10) {
        dp[i + 1][0] = min(dp[i + 1][0], dp[i][j] + d);
      }
      if (0 < d) {
        dp[i + 1][1] = min(dp[i + 1][1], dp[i][j] + 10 - d);
      }
    }
  }
  printf("%d\n", dp[m][0]);
  return EXIT_SUCCESS;
}


Measured memory_bytes: 8960
#include"bits/stdc++.h"
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define eb emplace_back

using ll = long long;
using vll = vector<ll>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using P = pair<int, int>;

void Main(){
    int k; cin >> k;
    vi a(k); rep(i, k) cin >> a[i];
    ll mn = 2, mx = 2;
    
    auto f = [&](ll x, ll y){
        // x 以上の最も小さい y の倍数
        return y * ((x+y-1)/y);
    };

    auto g = [&](ll x, ll y){
        // x より大きい最も小さい y の倍数 - 1
        return f(x+1, y) - 1;
    };
    
    rep3rev(i, k-1, 0){
        mn = f(mn, a[i]);
        mx = g(mx, a[i]);
        if(mn > mx){
            cout << -1 << endl;
            return;
        }
        // cout << mn << " " << mx << endl;
    }
    cout << mn << " " << mx << endl;    
    return;
}

int main(){
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}

Measured memory_bytes: 3712
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, j) for(int i = 0; i < (int)(j); i++)
constexpr int INF = 1 << 28;
struct Edge{
    int to;
    ll cost;
    int from; // from ????????????????????¨?????????
    Edge(int to, ll cost, int from = -1):to(to), cost(cost), from(from) {}
};
using EdgeList = vector<vector<Edge>>;
constexpr ll INFL = 1LL << 60;
bool operator < (Edge a, Edge b) {
    return a.cost < b.cost;
}
bool operator > (Edge a, Edge b) {
    return a.cost > b.cost;
}
// ??£???????????°?????? E ???????°???¨?????¨????????????????±???????
// O(ElogV)
vector<Edge> prim(const EdgeList &E) {
    int N = E.size(), start = 0;      
    vector<Edge> ans;
    priority_queue<Edge, vector<Edge>, greater<Edge>> que;
    vector<bool> visited(N);
    int visited_num = 0;    
    que.emplace(start, 0);
    
    while(visited_num < N and not que.empty()){
        Edge now = que.top(); que.pop();
        if(visited[now.to]) continue;
        visited[now.to] = true;
        visited_num++;
        ans.push_back(now);
        for(Edge e : E[now.to]){
            if(not visited[e.to]) {
                que.emplace(e.to,  e.cost);
            }
        }
    }
    assert(visited_num == N); // ??£????????§?????? 
    return ans;
}
// for kruskal
struct UnionFind{
    int n;
    vector<int> p;
    UnionFind(int nn):n(nn) {
        p.resize(n);
        rep(i, n) p[i] = i;
    }
    int root(int x) {
        return p[x] == x ? x : (p[x] = root(p[x]));
    }
    void unite(int x,int y) {
        x = root(x); y = root(y);
        if(x != y) p[y] = x;
    }
    bool query(int x,int y){
        return root(x) == root(y);
    }
};
// ??£???????????°?????? E ???????°???¨?????¨???????????????????????§?±???????
// ?????£?????°???????????´??????????°???£????£?????±???????
// O(ElogV)
vector<Edge> kruskal(const EdgeList &E) {
    vector<Edge> edges;    
    rep(i, E.size()) for(auto &e : E[i]) edges.push_back(Edge(e.to, e.cost, i));
    sort(begin(edges), end(edges));
    
    vector<Edge> ans;
    UnionFind uf(E.size());
    for(auto &e : edges) {
        if(not uf.query(e.from, e.to)) {
            ans.push_back(e);
            uf.unite(e.from, e.to);
        }
    }
    return ans;
}
// round robin algorithm ??? EloglogV ?????????
int main() {
    int N, M; cin >> N >> M;
    EdgeList E(N);
    rep(i, M) {
        int a, b, c; cin >> a >> b >> c;
        E[a].push_back(Edge(b, c));
        E[b].push_back(Edge(a, c));
    }
    auto mst = kruskal(E);
    ll ans = 0;
    for(auto &e : mst) ans += e.cost;
    cout << ans << endl;
    return 0;
}

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

#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define fst first
#define snd second
#define pb push_back
#define ALL(x) x.begin(),x.end()
#define EPS (1e-9)
#define equals(a,b) (fabs((a)-(b))<EPS)

using namespace std;

bool LT(double a,double b) { return !equals(a,b) && a < b; }
bool LTE(double a,double b) { return equals(a,b) || a < b; }

const string YES = "";
const string NO  = "";

typedef long long ll;

void solve() {

}

int main() {
  ll n,a,b;
  cin >> n >> a >> b;
  ll coef = n / (a+b);
  ll ans = coef * a;
  n -= ( coef * (a+b) );
  ans += min(a,n);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<queue>
#include<algorithm>
#define rep(i,n) for(int i=0;i<n;i++)
#define INF -1
using namespace std;

typedef vector< vector<int> > table;

bool bfs(table& M,int n,int m,int s,vector<int>& r)
{
    vector<int> dist(n+1,0);
    queue<int> q;
    for (int i = 1; i <= n; i++) dist[i]=INF;
    dist[s]=0;
    q.push(s);
    vector<int> h;
    
    int now=0;
    while (!q.empty())
    {
        int u=q.front(); q.pop();
        h.push_back(u);
        for (int v = 1; v <= n; v++)
        {
            if(M[u][v]==0)continue;
            if(dist[v]!=INF)continue;
            if(v!=r[now])continue;
            dist[v]=dist[u]+1;
            q.push(v);
            now++;
            break;
        }
    }
    if(now==r.size()) return true;
    return false;
}

int main()
{
    int n,m;
    cin>>n>>m;
    vector<int> r; 
    for (int i = 2; i <= n; i++) r.push_back(i);
    table M(n+1,vector<int>(n+1,0));
    
    rep(i,m)
    {
        int a,b;
        cin>>a>>b;
        M[a][b]=M[b][a]=1;
    }

    int count=0;
    do
    {
        if(bfs(M,n,m,1,r))count++;
    } while (next_permutation(r.begin(),r.end()));
    cout<<count<<endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (sc.hasNextInt()) {
            int a = sc.nextInt();
            int b = 0;
            int c[] = new int[a + 1];
            if (a < 2) {
                System.out.println("0");
            } else {
                for (int i = 2; i <= a; i++) {
                    if (c[i] == 0) {
                        for (int j = i * 2; j <= a; j = j + i) {
                            c[j] = 1;


                        }
                    }
                }
                for (int i = 2; i <= a; i++) {
                    if (c[i] == 0)
                        b++;

                }
                System.out.println(b);
            }
        }
    }
}

Measured memory_bytes: 54184
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long long ll;

template<class T> inline void read(T &x){
	int f=0;x=0;char ch=getchar();
	for(;!isdigit(ch);ch=getchar())f|=(ch=='-');
	for(;isdigit(ch);ch=getchar())x=x*10+ch-'0';
	if(f)x=-x;
}

const int N=500005;
struct node{
	ll v; int k,c;
	friend bool operator < (node a,node b){
		return a.v>b.v||a.v==b.v&&a.k>b.k;
	}
} x[N];
int nxt[N],las[N],n,K,m,a,b,cnt;
ll ans[N],sum;
vi w[N];

set<pair<ll,int> > sig,dou,tri;
ll s1,s2;

int main(){
	read(n),read(K);
	rep(i,1,n){
		read(a),read(b);
		w[a].pb(b*2);
	}
	rep(i,1,K){
		sort(w[i].begin(),w[i].end(),greater<int>());
		x[++m]=(node){((ll)w[i][0]+w[i][1])/2,2,i};
		for(int k=2;k<w[i].size();k++) x[++m]=(node){w[i][k],1,i};
	}
	sort(x+1,x+m+1);
	per(i,m,1) nxt[i]=las[x[i].c],las[x[i].c]=i;
	//rep(i,1,m) cout<<i<<" "<<x[i].v<<" "<<x[i].k<<" "<<x[i].c<<endl;
	rep(i,1,K){
		dou.insert(mp((ll)w[i][0]+w[i][1],i));
		if(w[i].size()>2) tri.insert(mp((ll)w[i][0]+w[i][1]+w[i][2],i));
	}
	rep(i,1,m){
		if(x[i].k==2){
			if(!sig.empty()){
				ans[cnt+1]=max(ans[cnt+1],sum+sig.rbegin()->fi);
			}
			if(s1&&!dou.empty()){
				ans[cnt+1]=max(ans[cnt+1],sum+dou.rbegin()->fi-s1);
			}
			if(s2&&!tri.empty()){
				ans[cnt+1]=max(ans[cnt+1],sum+tri.rbegin()->fi-s2);
			}
		}
		cnt+=x[i].k;
		sum+=x[i].v*x[i].k;
		ans[cnt]=sum;
		if(x[i].k==2){
			s2=x[i].v*2;
			if(nxt[i]){
				sig.insert(mp(x[nxt[i]].v,x[i].c));
				tri.erase(mp(x[i].v*2+x[nxt[i]].v,x[i].c));
			}
			dou.erase(mp(x[i].v*2,x[i].c));
		}
		else{
			s1=x[i].v;
			sig.erase(mp(x[i].v,x[i].c));
			if(nxt[i]) sig.insert(mp(x[nxt[i]].v,x[i].c));
		}
	}
	rep(i,1,n) printf("%lld\n",!ans[i]?-1:ans[i]/2);
	return 0;
}

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

long long N, A[1 << 18];

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

	long long minx = S, sum = 0;
	for (int i = 1; i <= N; i++) {
		sum += A[i];
		minx = min(minx, abs(sum - (S - sum)));
	}
	cout << minx << endl;
	return 0;
}


Measured memory_bytes: 1792
//#define _GLIBCXX_DEBUG
#include "bits/stdc++.h"

using namespace std;

//------------------------------- Type Names -------------------------------//

using i64 = int_fast64_t;

using seika = string;
//{akari : 1D, yukari : 2D, maki : 3D} vector
template <class kizuna>
using akari = vector<kizuna>;
template <class yuzuki>
using yukari = akari<akari<yuzuki>>;
template <class tsurumaki>
using maki = akari<yukari<tsurumaki>>;
//{akane : ascending order, aoi : decending order} priority queue
template <class kotonoha>
using akane = priority_queue<kotonoha, akari<kotonoha>, greater<kotonoha>>;
template <class kotonoha>
using aoi = priority_queue<kotonoha>;

//------------------------------- Libraries ---------------------------------//

//------------------------------- Dubug Functions ---------------------------//

inline void print()
{
    cout << endl;
}
template <typename First, typename... Rest>
void print(const First &first, const Rest &... rest)
{
    cout << first << ' ';
    print(rest...);
}

//------------------------------- Solver ------------------------------------//

void solve()
{
    int x;
    cin >> x;
    int as[] = {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 << as[x - 1] << endl;
}

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long n,i,j,k,t,s,a[51];
	cin>>n>>k;
	for(i=1;i<=n;i++) cin>>a[i];
	for(i=1;i<n;i++)
	 for(j=i+1;j<=n;j++)
	  if(a[i]<a[j])
	   {
	   	 t=a[i];
	   	 a[i]=a[j];
	   	 a[j]=t;
	   }
	for(i=1;i<=k;i++) s+=a[i];
	cout<<s<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
#include<string.h>
char x[10000];
using namespace std;
int main(void){
	while(scanf("%s",&x)!=EOF){;
		int i,len;
		len=strlen(x);
		int jcnt=0,icnt=0;
		for(i=0;i<len;i++){
			if(x[i]=='J' && x[i+1]=='O' && x[i+2]=='I' && i+1<len && i+2<len){
				jcnt++;
			}
			if(x[i]=='I' && x[i+1]=='O' && x[i+2]=='I' && i+1<len && i+2<len){
				icnt++;
				//printf("%d\n",icnt);
			}
		}
		printf("%d\n%d\n",jcnt,icnt);
	}
	return 0;
}

Measured memory_bytes: 976
#include <bits/stdc++.h>
using namespace std;
#define REP(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) REP(i, 0, n)
#define rrep(i, n) for (int i = (int)(n-1); i >= 0; i--)
#define sz(x) int(x.size())
#define bitsz(x) int(__builtin_popcount(x))
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define INF 2e9
#define LINF 1e18
#define mod 1000000007
template<class T> inline bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b) { if (a > b) { a = b; return 1; } return 0; }
template < typename T > inline string toString( const T &a ) { ostringstream oss; oss << a; return oss.str(); };
typedef long long ll;
typedef pair<int, int> P;
const int di[4] = {1,0,-1,0};
const int dj[4] = {0,1,0,-1};


int main() {
    int n; cin >> n;
    set<int> st;
    rep(i,n) {
        int d; cin >> d;
        st.insert(d);
    }
    cout << sz(st) << endl;
}

Measured memory_bytes: 3612
#include <iostream>
#include <math.h>
#include <algorithm>
#include <vector>
#include <numeric>
#include <string>
using namespace std;
const double PI = acos(-1.0);
const string alp = "abcdefghijklmnopqrstuvwxyz";
const string ALP = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define SUM(c) accumulate((c).begin(),(c).end(),0)
#define Yn(b) puts(b?"Yes":"No")
#define YN(b) puts(b?"YES":"NO")

int main(){
  string s;
  int t;
  cin >> s;
  REP(i,3){
    if (s[i]=='1') {
      t++;
    }
  }
  cout << t;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <iostream>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <iomanip>
#include <math.h>
#include <time.h>
#include <chrono>
#include <random>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define repf(i, a, b) for (int i = (int)a; i < (int)b; i++)
#define repr(i, a, b) for (int i = (int)a; i > (int)b; i--)
#define all(v) (v).begin(), (v).end()
#define mp(a, b) make_pair(a, b)
#define eb(x) emplace_back(x)
#define F first
#define S second
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<int> vii;
typedef vector<vii> vvii;
const ll mod = 1e9 + 7;
const int infi = 1147483600;
const ll infl = 4e18 + 5;
const char ENDL = '\n';
//cout << fixed << setprecision(17) << res << endl;
const ll MOD = 998244353;

bool debug = false;

random_device rnd;
mt19937_64 mt(rnd());

ll c[26], s[370][26], D, last[26];

void input(){
    cin >> D;
    rep(i, 26) cin >> c[i];
    rep(i, D) rep(j, 26) cin >> s[i][j];
}

void make_input(){
    rep(i, 365) c[i] = mt() % 101;
    rep(i, 365) rep(j, 26) s[i][j] = mt() % 20001;
}

ll calc_v(vll t){
    vll v(D, 0);
    rep(i, 26) last[i] = -1;
    rep(i,D){
        if (i>0)
            v[i] = v[i - 1];
        v[i] += s[i][t[i]];
        last[t[i]] = i;
        rep(j, 26) v[i] -= c[j] * (i - last[j]);
    }
    return v[D-1];
}



//note:ランダム

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    clock_t start = clock();
    D = 365;
    if(debug)
        make_input();
    else
        input();
    rep(i, 26) last[i] = -1;

    ll mx = -infl;
    vll ans(D, 0);

    //ans:答えをＤ日分入力
    //last[i]:i番目のコンテストを最後に行ったのはlast[i]日
    rep(i, D) ans[i] = (mt() % 26);
    ll v;
    v = calc_v(ans);
    if (debug)
        cout << "start value:" << v << ENDL;
    ll q = 200000;
    rep(i,q){
        ll d, x1, x2;
        d = (mt() % D);
        x1 = ans[d];
        x2 = (mt() % 26);
        ans[d] = x2;
        ll v2 = calc_v(ans);
        if (v<v2)
            v = v2;
        else
            ans[d] = x1;
    }

    clock_t end = clock();
    if (debug){
        cout << "end value :" << v << ENDL;
        cout << "check :" << ((*min_element(all(ans)) >= 0) && (*max_element(all(ans)) <= 25)) << ENDL;
        ld time = static_cast<ld>(end - start) / CLOCKS_PER_SEC * 1000.0;

        cout << "time :" << fixed << setprecision(3) << time << "ms" << ENDL;
        }
    else 
        rep(i, D) cout << ans[i] + 1 << ENDL;
}


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

int main(){
    string S,T;
    cin >> S >> T;
    vector<int> l1(26,-1);
    vector<int> l2(26,-1);
    for(int i=0;i<S.size();i++){
        int a = S[i] - 'a';
        int b = T[i] - 'a';

        if(l1[a]!=-1 || l2[b]!=-1){
            if(l1[a]!=b || l2[b]!=a){
                cout << "No";
                return 0;
            }
        }
        else{
            l1[a] = b;
            l2[b] = a;
        }
    }
    cout << "Yes";
}

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

typedef long long ll;

using namespace std;

const string no = "NO";
const string yes = "YES";

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


  int result = 0;
  int cur_number = 1;
  int next_number = 100;
  while (next_number <= n) {
    result += cur_number * 9;

    cur_number = next_number;
    next_number *= 100;
  }

  result += min((n - cur_number + 1), cur_number * 9);
  cout << result << endl;

  return 0;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
int main() {
  int cnt = 0;
  int K, S;
  cin >> K >> S;
  for (size_t i = 0; i <= K; i++) {
    for (size_t j = 0; j <= K; j++) {
      if (S - i - j >= 0 && S - i - j <= K) cnt++;
    }
  }
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 256