akhauriyash/Code-Regression huggingface dataset:
/*
首先显然我们确定了其中两种， 第三种的选择就确定了， 我们把第三种的贡献想办法统计到另外两种身上
考虑每个ai， bi 都要减去ci， 然后想办法得到现在aibi的最大值， 然后加上sumci这个常数就好了， 这样答案就是最优答案
那么我们就把问题减少到了两个信息
考虑按照ai - bi 排序， 加入有两个元素 ai - bi < aj - bj, 则一定不会出现第i个选a， 第j个选b的情况 ,因为颠倒后可能会更优， 所以排序后可以看做是在一个前缀中选X个a， 在一个后缀中
选择y个b 前缀后缀不能相交
那么我们可以枚举这个分界点， 找到前缀最优选择方式， 后缀最优选择方式， 然后枚举分割点统计答案

*/
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<queue>
#define ll long long
#define M 100010
using namespace std;
int read() {
	int nm = 0, f = 1;
	char c = getchar();
	for(; !isdigit(c); c = getchar()) if(c == '-') f = -1;
	for(; isdigit(c); c = getchar()) nm = nm * 10 + c - '0';
	return nm * f;
}
struct Note {
	ll a, b, c;
	bool operator < (const Note &b) const {
		return (this->a - this->b) > b.a - b.b;
	}
} note[M]; 
int x, y, z, n;
ll la[M], rb[M], sum;
priority_queue< ll, vector<ll>, greater<ll> > que;
int main() {
	x = read(), y = read(), z = read(), n = x + y + z;
	for(int i = 1; i <= n; i++) note[i].a = read(), note[i].b = read(), note[i].c = read(), note[i].a -= note[i].c, note[i].b -= note[i].c;
	sort(note + 1, note + n + 1);
//	for(int i = 1; i <= n; i++)note[i].a += note[i].c, note[i].b += note[i].c;
	for(int i = 1; i <= x; i++) {
		que.push(note[i].a);
		sum += note[i].a;
	}
	la[x] = sum;
	for(int i = x + 1; i <= n; i++) {
		que.push(note[i].a);
		sum += note[i].a - que.top();
		que.pop();
		la[i] = sum;
	}
	while(!que.empty()) que.pop();
	sum = 0;
	for(int i = n - y + 1; i <= n; i++) que.push(note[i].b), sum += note[i].b;
	rb[n - y + 1] = sum;
	for(int i = n - y; i >= 1; i--) {
		que.push(note[i].b);
		sum += note[i].b - que.top();
		que.pop();
		rb[i] = sum;
	}
	ll ans = -10000000000000000ll;
	for(int i = x; i <= n - y; i++) ans = max(ans, la[i] + rb[i + 1]);
	for(int i = 1; i <= n; i++) ans += note[i].c;
	cout << ans << "\n";
	return 0;
}

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

#define ln '\n'
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define FOR(i, a, b) for (int i = (a); i <= (int)(b); ++i)
#define FORR(i, a, b) for (int i = (a); i >= (int)(b); --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
typedef vector<P> VP;
typedef vector<PL> VPL;
typedef vector<string> VS;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    VVI vertex(n);
    VI landmark(n, -1);
    REP(i, m) {
        int a, b;
        cin >> a >> b;
        vertex[a - 1].push_back(b - 1);
        vertex[b - 1].push_back(a - 1);
    }

    // BFS
    queue<int> vertex_queue;
    vertex_queue.push(0);
    landmark[0] = 0;
    while (!vertex_queue.empty()) {
        int target = vertex_queue.front();
        vertex_queue.pop();
        for (auto& v : vertex[target]) {
            if (landmark[v] == -1) {
                landmark[v] = target;
                vertex_queue.push(v);
            }
        }
    }

    cout << "Yes" << ln;
    FOR(i, 1, n - 1) cout << landmark[i] + 1 << ln;
    return 0;
}


Measured memory_bytes: 10272
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#include<math.h>
#include<string>
#include <iomanip>
#include<deque>
#include<queue>

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
const ll LINF = 1e18;
const int INF = 1e8;

using namespace std;


//マクロ定義
#define vvint(vec,n,m,l) vector<vector<int>> vec(n, vector<int>(m,l));	// lで初期化
#define vvll(vec,n,m,l) vector<vector<ll>> vec(n,vector<ll>(m,l));
#define vint vector<int>
#define pint pair<int,int>
#define rep(i,a) for(int i=0;i<(a);i++)
#define all(x) (x).begin(),(x).end()
#define debug system("pause")				//デバッグ用


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

	ll n, m;
	cin >> n >> m;

	vector<pair<ll, ll>> a(n);
	rep(i, n)
	{
		cin >> a[i].first >> a[i].second;
	}
	sort(a.begin(), a.end());

	priority_queue<ll> pq;
	ll start = 0;
	ll ans = 0;
	for (ll i = 1; i <= m; i++)
	{
		for (ll j = start; j < n; j++)
		{
			if (a[j].first <= i)
			{
				pq.push(a[j].second);
              	start=j+1;
			}
			else
			{
				break;
			}
		}
		if (!pq.empty())
		{
			ans += pq.top();
			pq.pop();
		}
	}
	cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 2936
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i, s, n) for (int i = (s); i < (n); ++i)
#define rrep(i, n, g) for (int i = (n)-1; i >= (g); --i)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define len(x) (int)(x).size()
#define dup(x, y) (((x) + (y)-1) / (y))
#define pb push_back
#define Field(T) vector<vector<T>>
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  if (abs(a-c) <= d) cout << "Yes" << endl;
  else if(abs(a-b) <= d && abs(c-b) <= d) cout << "Yes" << endl;
  else cout << "No" << endl;
}

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

int main(){
  int m,d;
  cin >> m >> d;
  int ans=0;
  
  for(int i=1;i<=m;i++){
    for(int r=1;r<=d;r++){
      int d1=r%10;
      int d2=r/10;
      if(d1>=2 && d2 >=2 && d1*d2 ==i){++ans;}
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
using System;
using System.Linq;

class C
{
	static void Main() => Console.WriteLine(string.Join("\n", new int[int.Parse(Console.ReadLine())].Select(_ => Console.ReadLine()).GroupBy(x => x).GroupBy(g => g.Count(), g => g.Key).OrderBy(g => -g.Key).First().OrderBy(x => x)));
}


Measured memory_bytes: 71732
import sys
import itertools
# import numpy as np
import time
import math

sys.setrecursionlimit(10 ** 7)

from collections import defaultdict

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

n = int(readline())
s = input()

counter = [(0, 0, 0)]
for c in s:
    rgb = counter[-1]
    r, g, b = 0, 0, 0
    if c == 'R':
        r = 1
    if c == 'G':
        g = 1
    if c == 'B':
        b = 1
    new_rgb = (rgb[0] + r, rgb[1] + g, rgb[2] + b)
    counter.append(new_rgb)

ans = 0
MAX = 4002
x = []
for i in range(1, min(len(s) + 1, MAX)):
    for j in range(i + 1, min(len(s) + 1, MAX)):
        if s[i - 1] == s[j - 1]:
            continue
        x.append((i, j))

y = []
for p in x:
    i = p[0]
    j = p[1]
    rgb = {'R', 'G', 'B'}
    sub = {s[i - 1], s[j - 1]}

    k_s = rgb.difference(sub).pop()
    k_idx = 0
    if k_s == 'R':
        k_idx = 0
    if k_s == 'G':
        k_idx = 1
    if k_s == 'B':
        k_idx = 2

    j_cnt = counter[j]
    k_cnt = counter[len(s)]
    omit = 0
    if (2 * j - i) <= len(s):
        omit = counter[2* j - i][k_idx] - counter[2 * j - i - 1][k_idx]
    ans += (k_cnt[k_idx] - j_cnt[k_idx] - omit)

print(ans)


Measured memory_bytes: 360132
import java.util.Scanner;

public class Main {

	static char[] s;
	static char[] var;
	static int[] PQR;
	static int[] tuf = {0, 1, 2};// true, unknown, false
	static int idx;
	static int varCount;
	public static void main(String[] args) {
		Scanner cin = new Scanner(System.in);
		while(true){
			varCount=idx=0;
			String str = cin.next();
			if(str.equals(".")){
				break;
			}
			s = new char[80];
			var = new char[80];
			PQR=new int[3];
			for(int i = 0; i < str.length(); i++){
				char c = str.charAt(i);
				if(c == '-' || c == '*' || c == '+' || c == '(' || c == ')'){
					s[idx++]=c;
				}
				else if(c=='P'){
					var[varCount++]=0;
				}
				else if(c=='Q'){
					var[varCount++]=1;
				}
				else if(c=='R'){
					var[varCount++]=2;
				}
				else if(c=='0'){
					var[varCount++]=3;
				}
				else if(c=='1'){
					var[varCount++]=4;
				}
				else if(c=='2'){
					var[varCount++]=5;
				}
			}

			int count=0;
			for(int i = 0; i < 3; i++){
				for(int j = 0; j < 3; j++){
					for(int k = 0; k < 3; k++){
						varCount=idx=0;
						PQR[0]=tuf[i];
						PQR[1]=tuf[j];
						PQR[2]=tuf[k];
						if(expression()==2){
							count++;
						}
					}
				}
			}
			System.out.println(count);
		}
	}
	static int expression(){
		int res = term();
		if(s[idx]=='+'){
			idx++;
			res = or(res, expression());
		}
		return res;
	}
	static int term(){
		int res = fact();
		if(s[idx]=='*'){
			idx++;
			res = and(res, term());
		}
		return res;
	}
	static int fact(){
		int res;
		if(s[idx]=='('){
			idx++;
			res=expression();
			idx++;
		}
		else if(s[idx]=='-'){
			idx++;
			res = not(fact());
		}
		else{
			res = variable();
		}
		return res;
	}
	static int variable(){
		if(var[varCount]>=3){
			return var[varCount++]-3;
		}
		return PQR[var[varCount++]];
	}
	static int or(int x, int y){
		if(x <= 1 && y <= 1){
			if(x == 0 && y == 0){
				return 0;
			}
			else{
				return 1;
			}
		}
		else{
			return 2;
		}
		
	}
	static int and(int x, int y){
		if(x >= 1 && y >= 1){
			if(x == 2 && y == 2){
				return 2;
			}
			else{
				return 1;
			}
		}
		else{
			return 0;
		}
	}
	static int not(int x){
		if(x ==0){
			return 2;
		}
		else if(x==1){
			return 1;
		}
		else{
			return 0;
		}
	}
}

Measured memory_bytes: 12000
/*
Looking from a window above
It's like a story of love
Can you hear me?
Came back only yesterday
I'm moving further away
Want you near me
All I needed was the love you gave
All I needed for another day
And all I ever knew
Only you
Sometimes when I think of her name
When it's only a game
And I need you
Listen to the words that you say
It's getting harder to stay
When I see you
All I needed was the love you gave
All I needed for another day
And all I ever knew
Only you, only you
Uh uh uh only you, only you
Only you, only you, only you
This is going to take a long time
And I wonder what's mine
Can't take no more
Wonder if you'll understand
It's just the touch of your hand
Behind a closed door
And all I needed was the love you gave
All I needed for another day
And all I ever knew
Only you, only you, only you
All I needed was the love you gave
All I needed for another day
And all I ever knew
Only you, only you, only you
Only you
*/

#include <bits/stdc++.h>

using namespace std;

#define int long long
#define ld long double
#define endl '\n'
#define rep(x,s,e) for(int x=s;x<=(e);x++)
#define repn for(int x=0;x<n;x++)
#define rep1n for(int x=1;x<=n;x++)
#define rep1m for(int y=1;y<=m;y++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(), x.rend()
#define precise(x) cout << fixed << setprecision(x)
#define bits(x) __builtin_popcountll(x)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define sz(x) ((int)(x.size()))
#define test int t; cin>>t; while(t--)
#define FAST                          \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL)

typedef vector<int> vi;
typedef vector<pair<int,int>> vii;
typedef pair<int,int> pii;


void __print(int x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}


template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define see(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define see(x...)
#endif

const int inf = 3e18;
const int N = 5e5 + 100;




int32_t main(){ 
   FAST;
   string s;   cin >> s;
   if(s[0] == s[1] and (s[1] == s[2]))
      cout << "Yes";
   else if(s[1] == s[2] and (s[2] == s[3]))
      cout << "Yes";
   else cout << "No";
}

Measured memory_bytes: 256
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
 
int main()
{
    int e[101][101];
    int R, C, r, c;
    int s, total;
 
    scanf("%d%d", &R, &C);
    for (r = 1; r <= R; r++) {
        for (c= 1; c <= C; c++) scanf("%d", &e[r][c]);
    }
     
    for (r = 1; r <= R; r++) {
        s = 0;
        for (c = 1; c <= C; c++) s += e[r][c];
        e[r][0] = s;
    }
    total = 0;
    for (c = 1; c <= C; c++) {
        s = 0;
        for (r = 1; r <= R; r++) s += e[r][c];
        e[0][c] = s;
        total += s;
    }
    for (r = 1; r <= R; r++) {
        for (c = 1; c <= C; c++) printf("%d ", e[r][c]);
        printf("%d\n", e[r][0]);
    }
    for (c = 1; c <= C; c++) printf("%d ", e[0][c]);
    printf("%d\n", total);
    return 0;
}


Measured memory_bytes: 2064
#include <iostream>
#include <algorithm>
#include <cmath>
#include<string>
#include <array>
#include <vector>
using namespace std;

int main() {
	string str = "CODEFESTIVAL2016";
	string a;
	int i,j=0;
	cin >> a;

	for (i = 0; i < 16; i++) {
		if (str[i] != a[i]) {
			j++;
		}
	}
	cout << j << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <bitset>
#include <iomanip>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
#include <algorithm>

using namespace std;

int main()
{
	long long n;
	long long a[32] = { 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 };

	cin >> n;

	cout << a[n-1] << endl;
}

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

void Main()
{
    long LARGE = 1L<<60;

    long n, m, s;
    cin >> n >> m >> s;

    vector<vector<tuple<long, long, long>>> p(n); // p[出発地] = <到着地, 料金, 乗車時間>
    long smax = 0;
    for (long i = 0; i < m; i++)
    {
        long u, v, a, b;
        cin >> u >> v >> a >> b;
        --u; --v;
        p[u].push_back(make_tuple(v, a, b));
        p[v].push_back(make_tuple(u, a, b));
        smax += a;
    }
    s = min(s, smax);

    vector<long> c(n), d(n);
    for (long i = 0; i < n; i++)
    {
        cin >> c[i] >> d[i];
    }
    
    vector<vector<long>> time(n, vector<long>(smax+1, LARGE)); // i番目の都市に銀貨j枚持って到着する最短時間
    priority_queue<tuple<long, long, long>, 
        vector<tuple<long, long, long>>, 
        greater<tuple<long, long, long>>> q; // <経過時間, 所持金, 到着地>　所持金はマイナスで管理
    vector<long> min_time(n, LARGE);
    long num_went = 0;
    q.push(make_tuple(0, -s, 0));
    while(!q.empty())
    {
        long ut, us, u;
        tie(ut, us, u) = q.top(); q.pop();
        us = - us;
        if(time[u][us] > ut){
            time[u][us] = ut;
            if(min_time[u] == LARGE)
            {
                min_time[u] = ut;
                num_went++;
            }
            if(num_went == n) break;
            if(us < smax)
                q.push(make_tuple(ut+d[u], -min(smax, us+c[u]), u));
            for(auto i: p[u])
            {
                long v, va, vb;
                tie(v, va, vb) = i;
                if(us >= va)
                    q.push(make_tuple(ut + vb, -(us - va), v));
            }
        }
    }
    
    for (long i = 1; i < n; i++)
    {
        cout << min_time[i] << endl;
    }
   
}

int main(int argc, char **argv)
{
    Main();
    return 0;
}


Measured memory_bytes: 16464
# from math import factorial,sqrt
# from itertools import permutations as permus
# from fractions import gcd
# from collections import deque,Counter
# from decimal import Decimal, getcontext
# # getcontext().prec = 1000
# # eps = Decimal(10) ** (-100)

# import numpy as np
# import scipy as scp

# strlist = "abcdefghijklmnopqrstuvwxyz"
n,x,y = map(int,input().split())

ans = [0 for _ in range(n)]

for i in range(1,n):
    for j in range(i+1,n+1):
        kyori = min(j-i,abs(x-i)+1+abs(y-j),abs(i-y)+1+abs(x-j))
        ans[kyori] +=1

print(*ans[1:],sep="\n")
# print("{:.10f}".format(ans))
# print(*ans)   # unpackして出力。間にスペースが入る
# for row in board:
#     print(*row,sep="")    #unpackして間にスペース入れずに出力する



Measured memory_bytes: 47068
#include <stdio.h>

int A[101][101],B[101][101];

int main()
{
	int N,a,b;
	scanf ("%d %d %d",&N,&a,&b);

	for (int i=1;i<=N;i++) for (int j=1;j<=N;j++) A[i][j] = B[i][j] = 2;
	A[1][2] = B[N-1][N] = 0;

	for (int k=0;k<=5050;k++){
		for (int i=1;i<=N;i++) for (int j=1;j<=N;j++) if (i != j){
			{
				int p = 1, q = 1;
				if (i-1 >= 1 && i-1 != j) p = B[i-1][j];
				if (i+1 <= N && i+1 != j) q = B[i+1][j];
				if (p == 0 || q == 0) A[i][j] = 1;
				else if (p == 1 && q == 1) A[i][j] = 0;
			}
			{
				int p = 1, q = 1;
				if (j-1 >= 1 && j-1 != i) p = A[i][j-1];
				if (j+1 <= N && j+1 != i) q = A[i][j+1];
				if (p == 0 || q == 0) B[i][j] = 1;
				else if (p == 1 && q == 1) B[i][j] = 0;
			}
		}
	}
	puts(A[a][b]?"Alice":"Borys");

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

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

  int n, x;
  cin >> n >> x;
  vector<int> v(n + 1);
  rep(i, 0, n) cin >> v[i];
  v[n] = x;
  sort(v.begin(), v.end());

  vector<int> w(n);
  rep(i,1,n+1)
    w[i-1]=v[i]-v[i-1];
  
  int ggcd = w[0];
  rep(i, 0, n) { ggcd = __gcd(ggcd, w[i]); }

  cout << ggcd << endl;
}


Measured memory_bytes: 3948
#include <iostream>
#include <numeric>
#include <cmath>
#include <limits>
#include <stdio.h>
#include <iomanip>
#include <cstdlib>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;
using ll = long long;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
ll Max(ll(a), ll(b), ll(c)) {
	return max(max(a, b), c);
}
ll Min(ll(a), ll(b), ll(c)) {
	return min(min(a, b), c);
}

vector<ll> fact, factinv, inv;
ll mod = 998244353;
void prenCkModp(ll n) {
	fact.resize(n + 5);
	factinv.resize(n + 5);
	inv.resize(n + 5);
	fact.at(0) = fact.at(1) = 1;
	factinv.at(0) = factinv.at(1) = 1;
	inv.at(1) = 1;
	for (ll i = 2; i < n + 5; i++) {
		fact.at(i) = (fact.at(i - 1) * i) % mod;
		inv.at(i) = mod - (inv.at(mod % i) * (mod / i)) % mod;
		factinv.at(i) = (factinv.at(i - 1) * inv.at(i)) % mod;
	}

}
ll nCk(ll n, ll k) {
	return (fact.at(n) * ((factinv.at(k) * factinv.at(n - k)) % mod)) % mod;
}
int modPow(long long a, long long n, long long p) {
	if (n == 0) return 1; // 0乗にも対応する場合
	if (n == 1) return a % p;
	if (n % 2 == 1) return (a * modPow(a, n - 1, p)) % p;
	long long t = modPow(a, n / 2, p);
	return (t * t) % p;
}

int main() {
	ll an;
	rep(i, 5) {
		ll A;
		cin >> A;
		if (A == 0) {
			an = i + 1;
		}
	}
	cout << an << endl;
}

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

int main() {
  int A, B, C;
  cin >> A >> B >> C;
  if (A == B && B == C && A % 2 == 0) {
    cout << -1 << endl;
  }
  else if (A % 2 == 1 || B % 2 == 1 || C % 2 == 1) {
    cout << 0 << endl;
  }
  else {
    vector<int> vec = { A, B, C };
    vector<int> next(3);
    int cnt = 0;
    while (1) {
      cnt++;
      next.at(0) = (vec.at(1) + vec.at(2)) / 2;
      next.at(1) = (vec.at(2) + vec.at(0)) / 2;
      next.at(2) = (vec.at(0) + vec.at(1)) / 2;
      if (next.at(0) % 2 == 1 || next.at(1) % 2 == 1 || next.at(2) % 2 == 1) break;
      vec.swap(next);
    }
    cout << cnt << endl;
  }
}

Measured memory_bytes: 256
N,M = map(int,input().split())
D = tuple(tuple(int(i) for i in input().split())for _ in range(M)) 
# 各電球から見た:D[][0]はつながっているスイッチの個数なことに注意
S = [[]for i in range(N)]
# 各スイッチから見る
for i in range(M):
    for j in D[i][1:]:
        S[j-1].append(i)
P = tuple(int(i) for i in input().split())
ans = 0
for i in range(2**N):
    bit = bin(i)[2:][::-1]
    L = [0 for _ in range(M)]
    for j,s in enumerate(list(bit)):
        if s == '1':
            for k in S[j]:
                L[k] += 1
    flag = True
    for j in range(M):
        if L[j]%2 != P[j]:
            flag = False
    if flag:
        ans += 1
print(ans)

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

#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define mem(x,val) memset((x),(val),sizeof(x))
#define all(x) x.begin(),x.end()
#define pb push_back
#define mp make_pair
#define PI acos(-1.0) 
#define N 111111

const int INF = 1 << 30 ;
typedef long long ll ;
typedef pair < int , int > pii ;

int a[200] ;

int main() {
  int n ,x, sum = 0,min_element = INT_MAX  ;
  cin >> n >> x;
  for(int i = 0 ;i<n ; i++){
    cin >> a[i] ;
    sum+=a[i] ;
    min_element = min(min_element, a[i]) ;
  }
  cout << n+(x-sum)/min_element << endl ;
  return 0 ;
}

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

int main()
{
  ll n, m;
  cin >> n >> m;
  vector<pair<ll, ll>> p(n);
  for (ll i = 0; i < n; i++)
  {
    ll a, b;
    cin >> a >> b;
    p[i] = make_pair(a, b);
  }
  sort(p.begin(), p.end());
  ll ans = 0;
  ll buf = m;
  for (ll i = 0; i < n; i++)
  {
    if (p[i].second >= buf)
    {
      ans += p[i].first * buf;
      break;
    }
    else
    {
      ans += p[i].first * p[i].second;
      buf -= p[i].second;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 4784
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int x[5];
	int ans;
	for(int i=0;i<5;i++){
	    cin>>x[i];
	    if(x[i]==0){
	        ans=i+1;
	    }
	}
	cout<<ans;
}


Measured memory_bytes: 3552
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i,n) for (int i = 0; i < (n); ++i)
int n, m;
int main() {
    cin >> n >> m;
    vector<tuple<ll, ll, ll>> xyz(n);
    rep(i, n) {
        ll x, y, z;
        cin >> x >> y >> z;
        xyz[i] = make_tuple(x, y, z);
    }
    vector<ll> num;
    ll tmp_num = 0;
    ll tmp_ans = 0;
    ll ans = 0;
    rep(i, (1<<3)) {
        tmp_ans = 0;
        num.clear();
        rep(j, n) {
            tmp_num = 0;
            if ( i & (1<<0) ) tmp_num += get<0>(xyz[j]);
            else              tmp_num -= get<0>(xyz[j]);
            if ( i & (1<<1) ) tmp_num += get<1>(xyz[j]);
            else              tmp_num -= get<1>(xyz[j]);
            if ( i & (1<<2) ) tmp_num += get<2>(xyz[j]);
            else              tmp_num -= get<2>(xyz[j]);
            num.push_back(tmp_num);
        }
        sort(num.begin(), num.end());
        rep(j, m) tmp_ans += num[m-1-j];
        ans = max(ans, abs(tmp_ans));
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("faild to read char") as char)
        .take_while(|c| !c.is_whitespace())
        .collect();
    token
        .parse()
        .ok()
        .expect("faild to parse token")
}

fn main(){
    let x: i64 = read();
    let y: i64 = read();

    let b = (y - 2 * x) / 2;
    let a = x - b;
    if b < 0 || a < 0 || (y - 2 * x) % 2 == 1 {
        println!("No");
    } else {
        println!("Yes");
    }
}


Measured memory_bytes: 2116
#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; }

/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
*/

int main(){
    int a,b; cin >> a >> b;
    if(a+b >= 10) cout << "error" << endl;
    else cout << a+b << endl;

}


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
from math import *
from itertools import *
from collections import *
from functools import *
try:
    from math import gcd
except Exception:
    from fractions import gcd

MOD = 1000000007  # type: int

def solve(H: int, W: int, K: int):
    dp = [[0] * (W + 2) for _ in range(H+1)]
    dp[0][1] = 1

    for h in range(H):
        for i in range(0, (1 << W), 2):
            f = True
            c = [0] * (W + 2)
            for w in range(1, W + 1):
                if ((i >> (w-1)) & 0x03) == 3:
                    f = False
                    break
                if i & (1 << (w - 1)):
                    c[w-1] += dp[h][w]
                elif i & (1 << w):
                    c[w+1] += dp[h][w]
                else:
                    c[w] += dp[h][w]
            if f:
                for j, cc in enumerate(c):
                    dp[h+1][j] += cc

    return dp[-1][K] % MOD


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    H = int(next(tokens))  # type: int
    W = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    result = solve(H, W, K)
    print(result)

if __name__ == '__main__':
    main()


Measured memory_bytes: 5124
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(x) x.begin(), x.end()
#define mod 1000000007
typedef long long ll;

int main(){
  int n;
  cin >> n;
  string str;
  cin >> str;
  vector<int> leftVec(26, 0);
  vector<int> rightVec(26, 0);
  rep(i, n) rightVec[str[i]-'a']++;
  int biggest = 0;
  rep(i, n){
    rightVec[str[i]-'a']--;
    leftVec[str[i]-'a']++;
    int cnt = 0;
    rep(j, 26){
      if(leftVec[j] != 0 && rightVec[j] != 0) cnt++;
    }
    biggest = max(biggest, cnt);
  }
  cout << biggest << endl;
  return 0;
}
        
      
      
      
      
      
      
      
  

Measured memory_bytes: 3596
#pragma region RegionDefs
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#include "boost/multi_array.hpp"
#define rep(i,n) for(int i=0,i##_len=(n);i<i##_len;++i)
#define reps(i,j,n) for(int i=(j),i##_len=(n);i<i##_len;++i)
#define repr(i,n) for(int i=(n);i>=0;--i)
#define all(x) begin(x),end(x)
using namespace std;
template<class T=int> using P  = pair<T, T>;
template<class T=int> using V  = vector<T>;
template<class T=int> using PQ = priority_queue<T>;
template<class T=int> using PQG = priority_queue<T, V<T>, greater<T>>;
typedef long long ll;
const int INF = 1e9;
const ll MOD = 1000000007LL;
void in() {}
template<class Head, class... Tail>
void in(Head&& head, Tail&&... tail)
{
    cin >> head;
    in(move(tail)...);
}
#define IN(...) int __VA_ARGS__; in(__VA_ARGS__)
//オーバーフロー対策
#define INL(...) ll __VA_ARGS__; in(__VA_ARGS__)
#define VIN(T, v, n) V<T> v(n); for(auto& _elem:v)cin>>_elem
template<class T>bool chmax(T &a, const T &b) {if (a<b) {a=b; return 1;} return 0;}
template<class T>bool chmin(T &a, const T &b) {if (a>b) {a=b; return 1;} return 0;}
#define y0 y__0
#define y1 y__1
#define j0 j__0
#define j1 j__1
#define next asdnext
#define prev asdprev
#pragma endregion RegionDefs

void solve()
{
    IN(n);
    int dp[100010][3];
    rep(i, n)
    {
        cin >> dp[i][0] >> dp[i][1] >> dp[i][2];
    }
    rep(i, n)
    {
        dp[i+1][0] = max(dp[i][1]+dp[i+1][0], dp[i][2]+dp[i+1][0]);
        dp[i+1][1] = max(dp[i][2]+dp[i+1][1], dp[i][0]+dp[i+1][1]);
        dp[i+1][2] = max(dp[i][0]+dp[i+1][2], dp[i][1]+dp[i+1][2]);
    }
    cout << max({dp[n-1][0], dp[n-1][1], dp[n-1][2]}) << endl;
}

int main()
{
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(numeric_limits<double>::max_digits10);

    solve();

    return 0;
}

Measured memory_bytes: 1408
fun main(args: Array<String>) {
    val N = readLine()!!.toInt()
    val a = readLine()!!.split(" ")
            .mapIndexed { index, s -> s.toLong() - (index + 1) }
            .sorted()
            .apply { println(map { Math.abs(it - get(N/2)) }.sum()) }
}

Measured memory_bytes: 82584
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <unordered_map>
#include <utility>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <cstdio>
#include <math.h>
#include <stdio.h>
#include <deque>

using namespace std;

#define REP(i,n,m) for( long long int i = (n); i < (m); i++ )
#define REV(v) for (auto itr = v.rbegin(); itr != v.rend(); itr++)
#define ll long long
#define ALL(a) (a).begin(), (a).end()
#define SORT(v) sort( ALL(v) );
#define LAST(v) v[v.size()-1]
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,-1,sizeof(a))
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define pi pair<int, int>
#define MP make_pair
#define PB push_back
#define IIN(a) int a; cin >> a;
#define LIN(a) ll a; cin >> a;
#define SIN(a) string a; cin >> a;
#define VL(v,n) vector<ll> v(n);
#define Read_VL(v,n) vector<ll> v(n);REP(i,0,n)cin>>v[i];
#define sumV(v,n) Vl(acm,n) REP(i,0,n) acm[i] = v[i] + ( i == 0 ? 0 : acm[i - 1]);
#define EPS (1e-10)
#define INF 1000000000000LL

void YN(bool b){cout<<(b?"YES":"NO")<<"\n";}
void Yn(bool b){cout<<(b?"Yes":"No")<<"\n";}
void yn(bool b){cout<<(b?"yes":"no")<<"\n";}

template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}

template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}


template<class T=ll>struct Graph{
	int n;
	vector<vector<tuple<ll,T>>>edge;
	Graph(int N=1):n(N){edge.resize(n);}
	void add(ll f,ll t,T c,bool d=false){
		edge[f].emplace_back(t,c);
		if(!d)edge[t].emplace_back(f,c);
	}
	void view(){
		REP(i,0,n)for(auto&e:edge[i])
			puta(i,"=>",get<0>(e),", cost :",get<1>(e));
	}
};

ll StoLL( string s )
{
	ll num=0;
  REP( i, 0, s.size() ){
    num = num*10 + ( s[i]^48 );
  }
  return num;
}

ll CtoLL( char c )
{
	if( 'a' <= c && c <= 'z'){
		return (ll)( c ^ 96 ) ;
	}
	else if( 'A' <= c && c <= 'Z'){
		return (ll)( c ^ 64 );
	}
  return 0;
}

int MOD=1000000007;
int dx[4] = {0, 0, -1, 1};
int dy[4] = {1, -1, 0, 0};
//I ASCII code: '0' = 48; 'A' = 65; 'a' = 97

signed main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    SIN(s)
    ll n = s.size() ;
    ll ans = n * ( n - 1 ) / 2 + 1;
    map< char, ll > mp;
    REP( i, 0, n ){
      mp[ s[i] ]++;
    }
    for( auto it = mp.begin(); it != mp.end(); it++ ){
      ll m = it->second;
      ans -= m * ( m - 1 ) / 2;
    }

    puta( ans );
    return 0;
}


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

int main(){
    int n,a[101][101],u,k,v;
    cin>>n;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            a[i][j]=0;
        }
    }
    for(int i=0;i<n;i++){
        cin>>u>>k;
        for(int j=0;j<k;j++){
            cin>>v;
            a[u][v]=1;
        }
    }
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            cout<<a[i][j]<<((j==n)?'\n':' ');
        }
    }
}


Measured memory_bytes: 3152
import Data.Maybe
import qualified Data.ByteString.Char8 as BS
import Data.List
import Data.Int
import Control.Monad
import Control.Monad.ST
import qualified Data.Array.IArray as Array
import Data.Array.MArray
import Data.Array.ST

getInts :: IO [Int]
getInts = map (fst . fromJust . BS.readInt) . BS.words <$> BS.getLine

main :: IO ()
main = do
  [h, n] <- getInts :: IO [Int]
  [a, b] <- transpose <$> replicateM n getInts

  
  let ans = runSTUArray $ do
        dp <- newArray (0, 10000) (10 ^ 9) :: ST s (STUArray s Int Int)

        writeArray dp 0 0

        forM_ (zip a b) $ \(a', b') -> do
          forM_ [0..10000] $ \i -> do
            when (i - a' >= 0) $ do
              s <- readArray dp i
              t <- readArray dp (i - a')

              writeArray dp i $ minimum [s, t + b']
        
        return dp

  print $ (!! h) $ scanr min (10 ^ 9) (Array.elems ans)

  return ()


Measured memory_bytes: 2940
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <unordered_map>
#include <set>
#include <map>
#define INCANT cin.tie(0), cout.tie(0), ios::sync_with_stdio(0), cout << fixed << setprecision(20);
#define rep(i,n) for (int i=0; i<n;++i)
#define ALL(a)  (a).begin(),(a).end()
#define PI 3.14159265358979
typedef long long ll;
using namespace std;
const ll MOD = 1e9+7LL;
const int INF = 2e9;
int H, W, K;
char s[301][301];
int a[301][301];

void calc() {
  int idx = 1;
  rep(i, H) {
    queue<int> que;
    rep(j, W) {
      if (s[i][j]=='#') que.push(idx++);
    }
    if (que.empty()) continue;
    int tmp=que.front();
    rep(j, W) {
      if (s[i][j] == '#') {
        tmp = que.front();
        que.pop();
        a[i][j] = tmp;
      } else {
        a[i][j] = tmp;
      }
    }
  }
}

void calc2() {
  for (int i=1; i<H; i++) {
    if (a[i][0]==0) {
      rep(j, W) a[i][j] = a[i-1][j];
    }
  }
  for (int i=H-2; i>= 0; i--) {
    if (a[i][0]==0) {
      rep(j, W) a[i][j] = a[i+1][j];
    }
  }
}

int main() {
  INCANT;
  cin >> H >> W >> K;
  rep(i, H) rep(j, W) cin >> s[i][j];
  calc();
  calc2();
  rep(i, H) {
    rep(j, W) {
      cout << a[i][j] << ' ';
    }
    cout << endl;
  }

  return 0;
}

Measured memory_bytes: 1280
#include <stdio.h>

int main(void)
{
    int n, m;
    scanf("%d %d", &n, &m);

    int A[100][100], B[100], C[100] = {0};

    int i, j;
    for(i = 0; i < n; ++i)
    {
        for(j = 0; j < m; ++j)
        {
            scanf("%d", &A[i][j]);
        }
    }

    for(i = 0; i < m; ++i)
    {
        scanf("%d", &B[i]);
    }

    for(i = 0; i < n; ++i)
    {
        for(j = 0; j < m; ++j)
        {
            C[i] += A[i][j] * B[j];
        }

        printf("%d\n", C[i]);
    }

    return 0;
}

Measured memory_bytes: 640
#include <cstdio>

using namespace std;

int main() {
  size_t T;
  scanf("%llu", &T);
  for (size_t i=0; i<T; ++i) {
    int N, D;
    scanf("%d %d", &N, &D);
    int res=(N-1)*127;
    if (N & 1) {
      res += D;
    } else {
      res += 127 ^ D;
    }
    printf("%d\n", res);
  }
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1001001001;
const ll LINF = 1LL << 60;

template <typename T>
void print(const T &v)
{
    for (int i = 0; i < v.size(); i++)
    {
        if (i)
            cout << ' ';
        cout << v[i];
    }
    cout << endl;
}

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

set<int> cnt[26];

int main()
{
    int n, q;
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        char c;
        cin >> c;
        cnt[c - 'a'].insert(i + 1);
    }
    cin >> q;

    for (int i = 0; i < q; i++)
    {
        int mode;
        cin >> mode;
        if (mode == 1) // 文字を変更する
        {
            int idx;
            char c;
            cin >> idx >> c;
            for (int j = 0; j < 26; j++)
            {
                if (cnt[j].count(idx))
                {
                    cnt[j].erase(idx);
                    cnt[c - 'a'].insert(idx);
                    break;
                }
            }
        }
        else // 範囲内の種類数を出力する
        {
            int left, right;
            cin >> left >> right;
            int ret = 0;
            for (int j = 0; j < 26; j++)
            {
                if (cnt[j].size() == 0)
                {
                    continue;
                }
                auto iter = cnt[j].lower_bound(left);
                if (iter == cnt[j].end())
                {
                    continue;
                }
                else
                {
                    if (*iter <= right)
                    {
                        ++ret;
                    }
                }
            }
            cout << ret << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 27084
#include<iostream>
#include<algorithm>
using namespace std;
static const int MAX = 100;

main(){
  int N, A, B, C;
  int V[MAX];
  cin >> N >> A >> B >> C;
  for ( int i = 0; i < N; i++ ) cin >> V[i];
  int sum = 0;
  double ans = 0;
  sort(V, V + N);
  reverse(V, V + N);

  for ( int i = 0; i < N; i++ ){
    sum += V[i];
    ans = max(ans, 1.0*(sum + C)/(A+(i+1)*B));
  }

  cout << (int)ans << endl;
}

Measured memory_bytes: 1176
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cstdint>
#include <cassert>
#include <random>

using namespace std;
using i64 = int64_t;
using i32 = int32_t;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0) 
{ v = vector<T>(n+o); for (size_t i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> void read_n(T a[], size_t n, size_t o = 0)
{ for (size_t i=o; i<n+o; ++i) cin >> a[i]; }
template<class T> T gabs(const T& x) { return max(x, -x); }
#define abs gabs

i64 n, a, b;
int main() {
    cin >> n >> a >> b;
    i64 d = b - a;
    if (d % 2 == 0) {
        cout << d / 2 << endl;
    } else {
        i64 x = a + (d - 1) / 2, 
            y = (n - b + 1) + (d - 1) / 2;
        cout << min(x, y) << endl;
    }
    return 0;
}

Measured memory_bytes: 256
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.container, std.range;

Tuple!(N, N)[] prime_division(N)(N n)
{
    auto nn = n;
    Tuple!(N, N)[] res;
    for (N i = 2; i^^2 <= nn; ++i) {
        if (n%i == 0) {
            N cnt;
            while (n%i == 0) {
                ++cnt;
                n /= i;
            }
            res ~= tuple(i, cnt);
        }
    }
    if (n != cast(N)1) res ~= tuple(n, cast(N)1);
    return res;
}

N[] all_divisors(N)(N n)
{

    auto ps = prime_division(n);
    N[] ds;
    void run(int i, N x) {
        if (i == ps.length) {
            ds ~= x;
        } else {
            foreach (j; 0..ps[i][1]+1) run(i+1, x * ps[i][0]^^j);
        }
    }
    run(0, 1);
    return ds;
}

void main()
{
    auto nk = readln.split.to!(long[]);
    auto N = nk[0];
    auto K = nk[1];
    long[] AS;
    long s;
    foreach (a; readln.split.to!(long[])) {
        AS ~= a;
        s += a;
    }
    auto ds = all_divisors(s);
    sort!"a > b"(ds);

    bool check(long d) {
        long[] ds;
        foreach (a; AS) if (a != d) ds ~= a%d;
        if (ds.empty) return true;

        sort(ds);
        size_t i, j = ds.length-1;
        int k;
        while (i < j) {
            auto r = ds[i++]%d;
            k += r;
            while (r) {
                auto b = ds[j];
                ds[j] += r;
                r = 0;
                if (ds[j]/d > b/d) {
                    r = ds[j]%d;
                    --j;
                }
            }
        }
        return k <= K;
    }
    foreach (d; ds) if (check(d)) {
        writeln(d);
        return;
    }
}

Measured memory_bytes: 4452
package main
import (
  "fmt"
  "sort"
)

func main() {
  var n int
  fmt.Scan(&n)
  a := aArray(n)
  b := make([]int, 0)
  for _, v := range a {
    b = append(b, v)
  }
  sort.Sort(sort.IntSlice(b))
  size := len(b)
  max := b[size-1]
  big := b[size-2]
  ind := index(max, a)
  switch {
    case max == big:
    for i := 0; i < n; i++{
      fmt.Println(max)
    }
    case max != big:
    for i := 0; i < n; i++{
        if i == ind {
          fmt.Println(big)
        }else{
          fmt.Println(max)
        }
      }
    }
}

func aArray(n int) []int{
  var d int
  a := make([]int, 0)
  for i := 0; i < n; i++ {
    fmt.Scan(&d)
   	a = append(a, d)
  	}
  return a
}
  

func index(m int, a []int) int {
  var ind int
  for i, v := range a {
    if ind == 0 {
      switch {
    	case v == m :
      		ind = i
      }
    }
  }
  return ind
}

Measured memory_bytes: 11140
import sys
sys.setrecursionlimit(int(1e6))

N = int(input())

import math
a = int(math.sqrt(N))
while (a > 1):
    if (N % a) == 0:
        break
    a -= 1

b = N // a
ans = a - 1 + b - 1
print(ans)


Measured memory_bytes: 2940
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cassert>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
#include <cassert>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
ll d,t[20];
int main(){
	cin >> d;
	t[0] = 1;
	for(int i=1;i<=18;i++) t[i] = t[i-1]*10LL;
	ll res = 0;
	for(int i=1;i<=19;i++){
		vector<ll>vec;
		for(int j=1;j<i+1-j;j++){
			vec.pb(t[i-j]-t[j-1]);
		}
		ll ans = 1; if(i%2 == 1) ans = 10;
		vector<pair<ll,vector<int> > >vi;
		vi.pb(mp(d,vector<int>()));
		for(int i=0;i<vec.size();i++){
			vector<pair<ll,vector<int> > >vi2;
			for(int k=0;k<vi.size();k++){
				ll zan = vi[k].fi;
				for(ll j=-9;j<=9;j++){
					if( abs(zan-1LL*j*vec[i]) < vec[i]){
						vector<int>r = vi[k].sc;
						r.pb(j);
						vi2.pb(mp(zan-1LL*j*vec[i],r));
					}
				}
			}
			vi = vi2;
		}
		ll sum = 0;
		for(int i=0;i<vi.size();i++){
			if(vi[i].fi != 0LL) continue;
			ll val = 1;
			for(int j=0;j<vi[i].sc.size();j++){
				int x = (vi[i].sc)[j];
				if(j==0){
					if(x>=0) val *= (9-x);
					else val *= (10+x);
				}
				else{
					if(x>=0) val *= (10-x);
					else val *= (10+x);
				}
			}
			sum += val;
		}
		res += sum*ans;
	}
	cout << res << endl;
}

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

using namespace std;

#define forn for (ll i = 0; i < n; i++)
#define form for (ll j = 0; j < m; j++)
#define NO cout << "NO\n";
#define YES cout << "YES\n";
#define pb push_back
#define mp make_pair
#define rep(i,a,b) for (ll i = a; i < b; i++)

typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll, ll> pi;

ll gcd(ll a, ll b){
    ll r;
    while (b != 0){
        r = a % b;
        a = b;
        b = r;
    }
    return a;
}


ll *calc_z(string s){
    ll n = s.size();
    ll *z = new ll[n] {0};
    ll l = 0, r = 0;
    for (ll i = 1; i < n; i++){
        if (r >= i) z[i] = min(z[i-l], r-i+1);
        while (z[i]+i < n && s[z[i]] == s[z[i]+i]) z[i]++;
        if (i + z[i] - 1 > r){
            l = i;
            r = i+z[i]-1;
        }
    }
    return z;
}

int find_lower(int *a, int n, int v){
    int l = -1, r = n;

    while (r-l > 1){
        int m = (l+r)/2;
        if (a[m] <= v) l = m;
        else r = m;
    }
    return l;
}

void init(){
}

int bin(int *p, int n, int x){
    int l = 0, r = n-1;
    while (r >= l){
        int m = (l+r)/2;
        if (p[m] == x) return m;
        if (p[m] > x) r = m-1;
        else l = m+1;
    }
    return -1;
}

void solve(){
    int n,m;
    cin >> n >> m;
    if (n == m) cout << "Yes\n";
    else cout << "No\n";
}

int main(){
    //init();

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

    //ll t; cin >> t; while (t--)
        solve();
    return 0;
}


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

int main(){
    int n,x,ans=1,d=0;
    cin >> n >> x;
    for(int i = 0;i < n;i ++){
        int l;
        cin >> l;
        d += l;
        if(d<=x) ans ++;
        else break;
    } 
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int ms = 1e5+9;
bitset<ms> bs;
int vet[ms];

void sieve(){
	bs[0] = bs[1] = 1;
	for(int i = 2;i<ms;i++){
		if(!bs[i])
			for(int j = i+i;j<ms;j+=i)
				bs[j] = 1;
	}
	
}

int main(){
	int q,a,b;
	
	sieve();
	
	for(int i = 1;i<ms;i++){
		if(!bs[i] and !bs[(i+1)/2])
			vet[i]++;
	}
	for(int i = 1;i<ms;i++)
		vet[i] += vet[i-1];

	cin >> q;
	while(q--){
		cin >> a >> b;
		cout<<(vet[b]-vet[a-1])<<endl;
		
	
	}
}

Measured memory_bytes: 1024
from fractions import gcd
from collections import Counter, deque, defaultdict
from heapq import heappush, heappop, heappushpop, heapify, heapreplace, merge
from bisect import bisect_left, bisect_right, bisect, insort_left, insort_right, insort
from itertools import accumulate, product, permutations, combinations

def main():
    N = int(input())

    print(sum([i for i in range(N+1)]))

if __name__ == '__main__':
    main()

Measured memory_bytes: 10380
#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 ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main()
{
  //cout << "Hello" << endl;
  int a;
  REP(i,5){
    cin >> a;
    if(a==0){
      cout << i+1 << endl;
      return 0;
  }
  }
  return 0;
}

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

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

typedef long long ll;

#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= (ll)(b); i++)
#define FORD(i, a, b) for (ll i = a; i >= (ll)(b); i--)
//定数
#define INF 1000000000 //10^9:極めて大きい値,∞
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first      //pairの一つ目の要素
#define S second　   //pairの二つ目の要素

int main(){
    int n,m;
    cin>>n>>m;
    int wa[n]={};
    int ac[n]={};
    rep(i,m){
        int p;
        string s;
        cin>>p>>s;
        p--;
        if(s=="AC") ac[p]++;
        else if(ac[p]==0)wa[p]++;
    }
    int crrect=0;
    int pena=0;
    rep(i,n){
        if(ac[i]){ 
            crrect++;
            pena+=wa[i];
        }
    }
   cout<<crrect<<" "<<pena<<endl;
   return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main(){
  long N,M;cin>>N>>M;
  vector<bitset<10>>B(M);
  for(int i=0;i<M;i++){
    long k;cin>>k;
    for(int j=0;j<k;j++){long t;cin>>t;B[i].set(t-1);}
  }
  vector<long>P(M);
  for(int i=0;i<M;i++)cin>>P[i];
  long ans=0;
  for(int i=0;i<(1<<N);i++){
    bitset<10>b(i);
    bool ok=1;
    for(int j=0;j<M;j++)if((b&B[j]).count()%2!=P[j])ok=0;
    if(ok)ans++;
  }cout<<ans;
  
}

Measured memory_bytes: 256
import scala.io.StdIn._
object Main extends App {
  val s = readLine
  val k = readInt
  var set = Set.empty[String]
  for (i <- 1 to k) {
    s.toSeq
      .sliding(i)
      .foreach(w => {
        set = set + w.mkString
      })
  }
  val l = set.toList.sorted
  println(l(k - 1))
}


Measured memory_bytes: 44568
#include <algorithm>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <vector>

using namespace std;

#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
#define irep(i, n) for (int64_t i = 0; i <= (int64_t)(n); i++)
#define rrep(i, n) for (int64_t i = (n)-1; i >= 0; i--)
#define rirep(i, n) for (int64_t i = n; i >= 0; i--)

#define chmax(a, b) (a) = max(a, b)
#define chmin(a, b) (a) = min(a, b)

int64_t gcd(int64_t a, int64_t b) {
  if (b == 0) {
    return a;
  }
  return gcd(b, a % b);
}

int main() {
  int X;
  cin >> X;
  cout << 360 / gcd(X, 360) << endl;
  return 0;
}

Measured memory_bytes: 3636