akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <queue>
#include <deque>
#include <string>
#include <stack>
#include <unordered_set>
#include <cmath>
#define endl '\n'
#define ll long long
//#define mod 1000000007
#define NCONS 100001

using namespace std;

int alpha[26];

int main(void)
{
	cin.tie(NULL); ios_base::sync_with_stdio(false);
	int N; cin >> N;
	vector<int> vec;
	for (int i = 0; i < N; i++)
	{
		int temp; cin >> temp; vec.push_back(temp);
	}
	sort(vec.begin(), vec.end());
	int a = 0, b = 0;
	while (vec.size() >= 2)
	{
		auto fst = vec.back(); vec.pop_back();
		auto snd = vec.back();
		if (fst == snd)
		{
			a = fst;
			vec.pop_back();
			break;
		}
	}
	while (vec.size() >= 2)
	{
		auto fst = vec.back(); vec.pop_back();
		auto snd = vec.back();
		if (fst == snd)
		{
			b = fst;
			vec.pop_back();
			break;
		}
	}
	cout << (ll)a * b;
	return 0;
}

Measured memory_bytes: 1016
#include <iostream>
#include <cstdlib>
#include <vector>
using namespace std;

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

int lcm(int a, int b) {
    return (a * b) / gcd(a, b);
}

int main()
{
    int a, b;
    cin >> a >> b;
    cout << gcd(a, b) << endl;
    return 0;
}


Measured memory_bytes: 3100
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int K = sc.nextInt();
		int S = sc.nextInt();
		int cnt = 0;

		for (int x = 0; x <= K; x++) {
			for (int y = 0; y <= K; y++) {
				int z = S - x -y;
				if(0 <= z && z <= K) {
					cnt++;
				}
			}
		}
		System.out.println(cnt);
	}
}


Measured memory_bytes: 22612
N, M = map(int, input().split())
A = [input() for _ in range(N)]
B = [input() for _ in range(M)]
ans = 'No'

for h in range(N - M + 1):
    for i in range(N - M + 1):
        count = 0
        for j in range(M):
            if A[i + j][h:M + h] == B[j]:
                count += 1

                if count == M:
                    ans = 'Yes'

print(ans)


Measured memory_bytes: 3060
#include<cstdio>

int a, b, c;

int main() {
	scanf("%d%d%d", &a, &b, &c);
	int cnt = 0;
	while(a%2==0 && b%2==0 && c%2==0 && (a!=b || b!=c)) {
		int A = b/2 + c/2;
		int B = a/2 + c/2;
		int C = a/2 + b/2;
		a=A; b=B; c=C;
		cnt++;
	}
	if(a%2 || b%2 || c%2) printf("%d\n", cnt);
	else puts("-1");
	
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define REP(x,y,z) for(int x=y;x<=z;x++)
#define MSET(x,y) memset(x,y,sizeof(x))
#define M 10005
using namespace std;
int n,sum,in[M],dp[M];
int main()
{
    while (~scanf("%d", &n)) {
        sum = 0;
        REP(i,1,n) {
            scanf("%d", &in[i]);
            sum += in[i];
        }

        int ans = M;
        REP(t,1,n-1) {
            int s1=0, s2=0;
            REP(i,1,t) s1+=in[i];
            REP(i,t+1,n) s2+=in[i];
            ans = min(ans, abs(s1-s2));
        }
        printf("%d\n", ans);
    }
    return 0;
}


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

int main() {
  int N;
  cin >> N;
  
  vector<int> Meal(N);
  for (int i=0; i<N; i++) {
    cin >> Meal[i];
  }
  
  int ans = 0;
  for (int i=0; i<N; i++) {
    int B;
    cin >> B;
    ans += B;
  }
  
  vector<int> Add(N-1);
  for (int i=0; i<N-1; i++) {
    cin >> Add[i];
  }
  
  for (int i=0; i<N-1; i++) {
    if (Meal[i+1] == 1 + Meal[i]) {
      ans += Add[Meal[i]-1];
    }
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
	using namespace std;
	typedef long long ll;
	#define PI 3.14159265358979
	#define EPS 1e-8
	#define mod 
	#define fi first
	#define se second
	#define mp make_pair
	#define pb push_back
	#define endl "\n"
		 
	const ll INF=1e15;	
	const int N=1e5+5;
	 

	 
	long long binpow(long long a, long long b, long long m) {
		a %= m;
		long long res = 1;
		while (b > 0) {
			if (b & 1)
				res = res * a % m;
			a = a * a % m;
			b >>= 1;
		}
		return res;
	}
	
	
	int main()
	{
		ios_base::sync_with_stdio(false);
		cin.tie(NULL);cout.tie(0);
		
		int n;
		cin>>n;
		
		vector<int> v(n);
		
		vector<int> cnt(1000050,0);
		
		for(int i=0;i<n;i++)
		{
			cin>>v[i];
			cnt[v[i]]++;
		}
		int ans=0;
		for(int i=0;i<n;i++)
		{
			if(cnt[v[i]]>1 || (cnt[1] && v[i]!=1))
				continue;
			int f=1;	
			for(int j=2;j*j<=v[i];j++)
			{
				if(v[i]%j==0)
				{
					if(cnt[j] || cnt[v[i]/j])
						{
							f=0;
							break;
						}
				}
			}
			if(f)
			{
				ans++;
			}
		}
		cout<<ans;
	
	}
		
		
	


Measured memory_bytes: 7884
import sys
import math
import collections
import bisect
import itertools
import decimal
import copy
import heapq

# import numpy as np

# sys.setrecursionlimit(10 ** 6)
INF = 10 ** 20
MOD = 10 ** 9 + 7
# MOD = 998244353

ni = lambda: int(sys.stdin.readline().rstrip())
ns = lambda: map(int, sys.stdin.readline().rstrip().split())
na = lambda: list(map(int, sys.stdin.readline().rstrip().split()))
na1 = lambda: list(map(lambda x: int(x) - 1, sys.stdin.readline().rstrip().split()))
flush = lambda: sys.stdout.flush()


# ===CODE===
def main():
    s = ni()
    dp = [0 for _ in range(s + 1)]
    dp[s] = 1

    for i in range(s, 0, -1):
        if dp[i] != 0:
            for j in range(3, i + 1):
                dp[i - j] += dp[i]
                dp[i - j] %= MOD

    print(dp[0] % MOD)


if __name__ == '__main__':
    main()


Measured memory_bytes: 72828
import heapq
import sys
from collections import deque
input = sys.stdin.readline

INF = float('inf')

class Edge():
    def __init__(self, start, end, cost):
        self.start = start
        self.end = end
        self.cost = cost

def dijkstra(n, G, s):
    dist = [INF] * n
    dist[s] = 0
    h = []
    heapq.heappush(h, (0, s))

    while h:
        # 使っていない頂点のうち、現時点で最も距離の近いものを選びvとする
        d, v = heapq.heappop(h)
        if dist[v] < d:
            continue
        # vから到達可能な頂点について、距離が短くなれば更新
        for e in G[v]:
            if dist[e.end] > dist[v] + e.cost:
                dist[e.end] = dist[v] + e.cost
                heapq.heappush(h, (dist[e.end], e.end))
    return dist

n, m, p = map(int, input().split())

g1 = [[] for _ in range(n)]
g2 = [[] for _ in range(n)]
es = []

abc = []

for _ in range(m):
    a, b, c = map(int, input().split())
    abc.append((a-1, b-1, c))
    g1[a-1].append(Edge(a-1, b-1, 1))
    g2[b-1].append(Edge(b-1, a-1, 1))

dist1 = dijkstra(n, g1, 0)
dist2 = dijkstra(n, g2, n-1)

# print(dist1)
# print(dist2)

ng = set({})

for i in range(n):
    if dist1[i] == INF or dist2[i] == INF:
        ng.add(i)

for a, b, c in abc:
    if a in ng or b in ng:
        continue
    es.append(Edge(a, b, p-c))

def bellman_ford(n, es, s):
    dist = [INF] * n
    dist[s] = 0
    # 更新が止まるまで繰り返す O(V*E)
    # i度目の更新までにsを始点として0~i個の辺からなる経路が探索され、その時点の最短経路が計算される
    # 最短経路は最大でもV-1個の頂点しか通らないため、最悪でもv-1回で収束する
    while True:
        update = False
        # 辺をすべて見る
        for e in es:
            # aに到達可能かつa経由の方が近ければ更新する
            if dist[e.start] != INF and dist[e.end] > dist[e.start] + e.cost:
                dist[e.end] = dist[e.start] + e.cost
                update = True
        # 一度も更新されなければ終了
        if not update:
            break
    return dist

def find_negative_loop(n, es):
    dist = [0] * n
    for i in range(n):
        for e in es:
            if dist[e.end] > dist[e.start] + e.cost:
                dist[e.end] = dist[e.start] + e.cost
                if i == n - 1:
                    return True
    return False

if find_negative_loop(n, es):
    print(-1)
    sys.exit()

dist = bellman_ford(n, es, 0)
print(max(0, -dist[n-1]))


Measured memory_bytes: 61144
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int k = in.nextInt();
        String s = in.next();
        if (s.length() <= k) {
            System.out.println(s);
        } else {
            System.out.println(s.substring(0, k) + "...");
        }
    }
}

Measured memory_bytes: 38372
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

class pair{
	int a;
	int b;
	pair(int x,int y)
	{
		a=x;
		b=y;
	}
}

class compare implements Comparator<pair>{

	@Override
	public int compare(pair o1, pair o2) {
		if(o1.b>o2.b)
		{
			return -1;
			
		}
		else if(o1.b<o2.b)
		{
			return 1;
		}else
		{
			return 0;
		}
	}
	
}
public class Main {

	public static void main(String args[])
	{
		Scanner scan=new Scanner(System.in);
		int n=scan.nextInt();
		int m=scan.nextInt();
		int ar[]=new int[n];
		for(int i=0;i<n;i++)
		{
			ar[i]=scan.nextInt();
		}
		pair cng[]=new pair[m];
		
		for(int i=0;i<m;i++)
		{
		cng[i]=new pair(scan.nextInt(),scan.nextInt());	
		}
		Arrays.parallelSort(cng,new compare());
		//try to change the smallest values of orginal arrays with the biggest values form array m
		Arrays.parallelSort(ar);
		int x=0;
		int y=0;
		while(x<m)
		{
			int times=cng[x].a;
			int val=cng[x].b;
			while(times>0 && y<n&&ar[y]<val)
			{
				ar[y]=val;
				y++;
				times--;
			}
			x++;
		}
		long sum=0;
		for(int i=0;i<n;i++)
		{
			sum+=ar[i];
		}
		System.out.println(sum);
	}
	
}


Measured memory_bytes: 90948
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ll long long
#define lld long double
#define ALL(x) x.begin(), x.end()
using namespace std;

int main(int argc, char const *argv[])
{
    int n, l;
    cin >> n >> l;
    vector<string> v(n);
    rep(i, n) cin >> v[i];
    sort(ALL(v));
    rep(i, n)
    {
        cout << v[i];
    }
    cout << endl;

    return 0;
}


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

#define get_variable_name(x) #x
#define debug(x) cout << #x << " = " << x << endl
#define rep(i, begin, end) for(int (i) = (begin); (i) < (end); (i)++)

#define ALL(x) (x).begin(), (x).end()
#define SORT(x) sort((x).begin(), (x).end())
#define REVERSE(x) reverse( (x).begin(),(x).end())
#define UNIQUE(x) (x).erase(unique(ALL((x))), (x).end())
#define PW(x) (1LL<<(x))

using namespace std;
using ll = int64_t;
using P = pair<int, int>;

template<class T,class U>
ostream& operator<<(ostream &os, const pair<T, U> &p) {
    os << get_variable_name(p) << " = (" << p.first <<", " << p.second << ")";
    return os;
}

template<class T>
ostream& operator <<(ostream& os, const vector<T> &v){
    cout << get_variable_name(v) << " = [";
    for(auto i : v) 
        os << " " << i;
    os << " ]";
    return os;
}


const int INF = 1e8;

int main() {
    ios::sync_with_stdio(false);

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iostream>
using namespace std;
int main()
{
    vector<int>v;
    int t;
    cin>>t;
    for(int i=0; i<t; i++)
    {
        int x;
        cin>>x;
        v.push_back(x);
    }
    reverse(v.begin(),v.end());
    cout<<v[0];
    for(int i=1; i<t; i++)
    {
        cout<<" "<<v[i];
      }
        cout<<endl;

    return 0;
}



Measured memory_bytes: 3164
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using Graph = vector<vector<int>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Rep(i, k, n) for (int i = k; i < (int)(n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
long long dp[100010];
long long h[100010];

int n, m, q;
vector<ll> a, b, c, d;

ll score(const vector<int> &A)
{
    ll res = 0;
    rep(i, q) if (A[b[i]] - A[a[i]] == c[i]) res += d[i];
    return res;
}


ll dfs(vector<int> &A)
{
    if (A.size() == n)
    {
        return score(A);
    }

    ll res = 0;
    int last = (A.empty() ? 0 : A.back());
    Rep(v, last, m)
    {
        A.push_back(v);
        res = max(res, dfs(A));
        A.pop_back();
    }
    return res;
}



int main()
{
    cin >> n >> m >> q;
    a.resize(q); b.resize(q); c.resize(q); d.resize(q);
    rep(i, q)
    {
        cin >> a[i] >> b[i] >> c[i] >> d[i];
        --a[i], --b[i];
    }
    vector<int> A;
    cout << dfs(A) << endl;
}

Measured memory_bytes: 3624
#include<stdio.h>

void quicksort1(int data1[],int left,int right);//降順
void quicksort2(int data2[],int left,int right);//昇順

int main()
{
    int i,j,n,m,x,y;
	int a[110],b[110];
	scanf("%d %d %d %d",&n,&m,&x,&y);
	for(i=0;i<n;i++)
	{
		scanf("%d",&(a[i]));
	}
	for(j=0;j<m;j++)
	{
		scanf("%d",&(b[j]));
	}
	quicksort1(a,0,n-1);
	quicksort2(b,0,m-1);
	
	//printf("%d %d\n",a[0],b[0]);
    if((a[0]<b[0])&&(x<=a[0])&&(b[0]<=y))printf("No War");
	else printf("War");
}

void quicksort1(int data[],int left,int right)
{
	int i,j;
	int std,work;
	if(left<right)
	{
		i=left,j=right;
		std=data[(i+j)/2];//基準
		do
		{
			while(data[i] > std)i++;
			while(data[j] < std)j--;
			if(i<=j)
			{
				if(i<j)
				{
					work=data[i];
					data[i]=data[j];
					data[j]=work;
				}
				i++; j--;
			}
		}while(i<=j);
		if(left<j)quicksort1(data,left,j);
		if(i<right)quicksort1(data,i,right);
	}
}
void quicksort2(int data[],int left,int right)
{
	int i,j;
	int std,work;
	if(left<right)
	{
		i=left,j=right;
		std=data[(i+j)/2];//基準
		do
		{
			while(data[i] < std)i++;
			while(data[j] > std)j--;
			if(i<=j)
			{
				if(i<j)
				{
					work=data[i];
					data[i]=data[j];
					data[j]=work;
				}
				i++; j--;
			}
		}while(i<=j);
		if(left<j)quicksort2(data,left,j);
		if(i<right)quicksort2(data,i,right);
	}
}

Measured memory_bytes: 128
import sys
sys.setrecursionlimit(2 ** 30)
N, M, K = map(int, input().split())

groups = [None] * N
visited = set()

# 連結成分を求める
def dfs(group, i):
  if i in visited:
    return
  
  visited.add(i)
  group.add(i)
  groups[i] = group
  # 他のノード
  for c in graph[i]:
    if not c in visited:
      dfs(group, c)
  

graph = [set() for _ in range(N)]

friends_count = [0] * N
block_count = [0] * N

for _ in range(M):
  a, b = map(int, input().split())
  a, b = a - 1, b - 1
  friends_count[a] += 1
  friends_count[b] += 1
  graph[a].add(b)
  graph[b].add(a)
  
for i in range(N):
  dfs(set(), i)
      
for _ in range(K):
  c, d = map(int, input().split())
  c, d = c - 1, d - 1
  
  # 同じ連結成分に含まれないブロック関係は無視してok
  if d in groups[c]:
    block_count[c] += 1
    block_count[d] += 1

candidates = []

for i in range(N): 
  candidates.append(
    len(groups[i]) - friends_count[i] - block_count[i] - 1
  )
    
print(' '.join(str(x) for x in candidates))

Measured memory_bytes: 77096
/*input
1
3 3
1 2 3
*/

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PII;
typedef pair<ll , ll> PLL;
typedef long double ld;

#define pb push_back
#define all(c) c.begin(),c.end()
#define allr(c) c.rbegin(),c.rend()
int mod = 1000000007;
#define PI 3.14159265
#define endl '\n'
#define debug(x) cout << #x << " = " << x << endl;
#define MAX 100001

template < typename T > T GCD(T a, T b)            { ll t; while(a) { t = a; a = b % a; b = t; } return b; }
template < typename T > string toString(T a)       { return to_string(a); }
template < typename T > void toInt(string s, T &x) { stringstream str(s); str >> x;}
inline int add(ll a, ll b) {a += b; if (a < 0) a += mod; return a;}
inline int sub(ll a, ll b) {a -= b; if (a < 0) a += mod; return a;}
inline int mul(ll a, ll b) {return (a * 1ll * b) % mod;}
inline int pwr(ll x, ll y) {
    int ans = 1 % mod;
    while (y) {
        if (y & 1) ans = mul(ans, x);
        x = mul(x, x);
        y >>= 1;
    }
    return ans;
}
inline int inv(int a) {return pwr(a, mod - 2);}

vector <int> adj[MAX];


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

    string str;
    cin >> str;
    int n = str.size();
    int z = 0, o = 0;
    int ans = 0;
    for (int i = 0; i < n; i++) {
        z += (str[i] == '0');
        o += (str[i] == '1');
        ans += min(z, o) * 2;
        int m = min(z, o);
        z -= m;
        o -= m;
    }
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 2816
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

N,M=MI()
H=LI()
Michi=[[] for i in range(N)]
OK=[1]*N
for _ in range(M):
  a,b=MI()
  Michi[a-1].append(b-1)
  Michi[b-1].append(a-1)
for i in range(N):
  for j in Michi[i]:
    if H[j]>=H[i]:
      OK[i]=0
      break
ans=sum(OK)
print(ans)

Measured memory_bytes: 30056
#include<iostream>	// 入出力
#include<math.h>	// 数学の関数
#include<vector>	// 配列
#include<string>	// 文字列
#include<map>		// 連想配列
#include<stack>		// スタック
#include<queue>		// キュー
#include<algorithm> // ソートとか


using namespace std;


int main()
{
	int A, B, C;
	cin >> A >> B >> C;

	if (C >= A&&C <= B) {
		cout << "Yes" << endl;
		return 0;
	}

	cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
using ll = long long;
#define vl vector<long long>
#define vvl vector<vector<long long>>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using pll = pair<long long,long long>;
const long long INF = 1LL << 60;
const long long MOD = 1000000007;
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;
}
//以上テンプレ

int main(){
    ll D,G;
    cin>>D>>G;
    vl a(D);
    vl b(D);
    rep(i,D) cin>>a.at(i)>>b.at(i);
    ll ans=INF;//回数
    for(ll bit=0;bit<(1<<D);++bit){
        ll sum=0;
        ll ifans=0;
        rep(i,D){
            if(bit&(1<<i)){//全完フラグ
                sum+=a.at(i)*100*(i+1)+b.at(i);
                ifans+=a.at(i);
            }
        }
            if(sum>=G){
                chmin(ans,ifans);
            }else{
                for(ll j=D-1;j>=0;--j){//高い順
                    if(bit&(1<<j)){//全完なら
                        continue;
                    }
                    rep(k,a.at(j)){//高いのを１問ずつ
                      if(sum>=G){
                        break;
                    }
                    sum+=100*(j+1);
                    ifans++;
                    }
                }
            chmin(ans,ifans);
        }
    }
    cout<<ans<<endl;
}


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

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	vector<int> a(5);
	int res = 1e2;
	rep(i, 5) {
		cin >> a[i];
		if (a[i] % 10 != 0) {
			res = min(res, a[i] % 10);
			a[i] += 10 - a[i] % 10;
		}
	}
	int ans = 0;
	if (res == 1e2) res = 10;
	for (int i = 0; i < 5; i++) {
		ans += a[i];
	}
	cout << ans -10 + res << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, a, n) for(ll i=a; i<n; i++)
#define RREP(i, a, n) for(ll i=n-1; i>=a; i--)
typedef long long ll;
const ll mod =1e9+7;
const ll inf =1e18;
using namespace std;

ll n, k;
ll t[101010], d[101010];
//vector<vector<pair<ll, ll>>> vvp; // d_i, index
vector<pair<ll, ll>> all, selected; // order of <d_i, index>
ll used[101010];
ll var, ans;
int main() {
    cin>>n>>k;
    REP(i, 0, n){
        cin>>t[i]>>d[i];
        all.emplace_back(d[i], t[i]);
    }

    sort(all.begin(), all.end());
    reverse(all.begin(), all.end());

    set<ll> st;
    REP(i, 0, k){
        selected.emplace_back(all[i].first, all[i].second);
        ans+=all[i].first;
        used[all[i].second]++;
        st.insert(all[i].second);
    }
    var=st.size();
    ans+=(var*var);

    ll cur=ans, idx=k;
    RREP(i, 0, k){
        if(used[selected[i].second]<=1) continue;

        while(idx<n){
            if(used[all[idx].second]<=0){
                used[all[idx].second]=1;
                used[selected[i].second]--;
                break;
            }
            idx++;
        }
        if(idx==n) break;

        cur-=selected[i].first;
        cur-=(var*var);
        var++;
        cur+=all[idx].first;
        cur+=(var*var);

        ans=max(ans, cur);
    }

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

Measured memory_bytes: 8944
#include <iostream>
#include <string>
#include <vector>
#define PB push_back
using namespace std;
int MF(string str)
{
  vector<int> ans;
  ans.PB(str[0]-'0');
  for(int i=1;i<str.size();i+=2){
    if(str[i]=='*')
      ans[ans.size()-1]*=str[i+1]-'0';
    else ans.PB(str[i+1]-'0');
  }
  int answer=0;
  for(int i=0;i<ans.size();++i)
    answer+=ans[i];
  return answer;
}
int LF(string str)
{
  int answer;
  answer=str[0]-'0';
  for(int i=1;i<str.size();i+=2){
    if(str[i]=='*')
      answer*=str[i+1]-'0';
    else answer+=str[i+1]-'0';;
  }
  return answer;
}
int main(void)
{
  string line;
  int canans;
  cin >> line;
  cin >> canans;
  int tmp=0;
  if(MF(line)==canans) tmp+=1;
  if(LF(line)==canans) tmp+=2;
  string answer[4]={"I","M","L","U"};
  cout << answer[tmp] << endl;
  return 0;
}

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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int INF = 1e9;

int main() {
  int a, b;
  cin >> a >> b;
  if (a == 1) a = 14;
  if (b == 1) b = 14;
  string ans;
  if (a > b)
    ans = "Alice";
  else if (a == b)
    ans = "Draw";
  else
    ans = "Bob";

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


Measured memory_bytes: 384
#include<iostream>

using namespace std;

int main() {
	int A, B;
	int buf;

	cin >> A >> B;
	buf = A + B;
	buf = (buf > A - B) ? buf : A - B;
	buf = (buf > A * B) ? buf : A * B;

	cout << buf << endl;

	return 0;
}

Measured memory_bytes: 764
#include <bits/stdc++.h>
#define sz(c)      int(c.size())
#define rep(i,a,b) for (int i=a; i<(b); ++i)
#define per(i,a,b) for (int i=(b)-1; i>=(a); --i)
using namespace std;
using ll = long long;

int const MD=998244353;

int madd(int x,int y) {
	if (x+y<MD) return x+y; else return x+y-MD;
}
int msub(int x,int y) {
	if (x-y>=0) return x-y; else return x-y+MD;
}
int mmul(int x,int y) {
	return int(ll(x)*y % MD);
}
int mpow(int x,int p) {
	int res=1;
	while (p>0) {
		if (p%2) res=mmul(res,x);
		x=mmul(x,x);
		p/=2;
	}
	return res;
}
int minv(int x) {
	return mpow(x,MD-2);
}
int mdiv(int x,int y) {
	return mmul(x,mpow(y,MD-2));
}

int const MAXN=2.2e6;
int fact[MAXN];
int invfact[MAXN];
void mfact_init() {
	fact[0]=invfact[0]=1;
	rep(i,1,MAXN) {
		fact[i]=mmul(fact[i-1],i);
		invfact[i]=minv(fact[i]);
	}
}
int mcomb(int x,int y) {
	if (x<y) return 0;
	return mmul(fact[x],mmul(invfact[x-y],invfact[y]));
}
int mdistr(int x,int y) {
	return mcomb(x+y-1,y-1);
}

int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(0);
	cout<<fixed<<setprecision(10);

	mfact_init();

	int N,M;
	cin>>N>>M;
	
	int res=0;
	rep(i,0,min(N,M)+1) if ((3*M-i)%2==0) {
		int add=mmul(mcomb(N,i),mdistr((3*M-i)/2,N));
		res=madd(res,add);
	}
	rep(i,0,min(N,M)+1) if ((M-i)%2==0) {
		int sub=mmul(mcomb(N,i),mdistr((M-i)/2,N));
		res=msub(res,mmul(sub,N));
	}
	rep(i,0,min(N,M)+1) if ((M-i)%2==0) {
		int add=mmul(mcomb(N-1,i),mdistr((M-i)/2,N-1));
		res=madd(res,mmul(add,N));
	}
	cout<<res<<'\n';
}


Measured memory_bytes: 17408
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <iomanip>
#include <map>
#include <set>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <iterator>
#include <string>
#include <limits>

using namespace std;

using i64 = int64_t;
using P = pair<i64, i64>;
//i64 mod = 1000000007;
i64 mod = 998244353;
int int_max = 2147483647;
i64 INF = 1e16;
int max_n = 1e5;


int main(int argc, char **argv) {
    i64 n;
    cin >> n;
    vector<i64> as(n);
    for (int i=0; i<n; ++i) {
        cin >> as[i];
    }

    i64 xor_sum{0};
    for (auto a : as) {
        xor_sum ^= a;
    }

    for (int i=0; i<n; ++i) {
        cout << (xor_sum ^ as[i]) << " ";
    }
    cout << endl;

    return 0;
}


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

int main(){
	int a[4], b[4], hit, blow, i, j;
	while(cin>>a[0]>>a[1]>>a[2]>>a[3]>>b[0]>>b[1]>>b[2]>>b[3]){
		hit=0;
		blow = 0;
		for(i=0;i<4;i++){
			for(j=0;j<4;j++){
				if(a[j] == b[i]){
					if(i==j){
						hit++;
					}else{
						blow++;
					}
				}
			}
		}
		cout << hit << " " << blow << endl;
	}
	return 0;
}

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

signed main(void)
{
	string s;
	cin >> s;
	if (s == "ABC")
		cout << "ARC" << endl;
	else
		cout << "ABC" << endl;
	return 0;
}


Measured memory_bytes: 3596
#[test]
fn test_solve() {
    assert_eq!(solve("4\n3 3 3 3\n"), "0\n");
    assert_eq!(solve("3\n1 0 3\n"), "1\n");
    assert_eq!(solve("2\n2 2\n"), "2\n");
    assert_eq!(solve("7\n27 0 0 0 0 0 0\n"), "3\n");
    assert_eq!(solve("10\n1000 193 256 777 0 1 1192 1234567891011 48 425\n"), "1234567894848\n");
}

fn solve(src: &str) -> String {
    let mut sc = Scanner::from_str(src);

    let n: usize = sc.read();
    let mut a: Vec<usize> = (0..n).map(|_| sc.read()).collect();

    let mut m = 0;
    let mut mi = 0;
    let mut k = 0;
    while {
        m = 0;
        for i in 0..n {
            if a[i] >= m {
                m = a[i];
                mi = i;
            }
        }
        m >= n
    } {
        let d = m / n;
        k += d;
        for i in 0..n {
            a[i] += d;
        }
        a[mi] -= d*(n+1);
    }

    format!("{}\n", k)
}

fn main() {
    let mut buf = String::new();
    use std::io;
    use std::io::{Read, Write};
    io::stdin().read_to_string(&mut buf).unwrap();
    io::stdout().write_all(solve(&buf).as_bytes()).unwrap();
}

struct Scanner<'a>(std::str::SplitWhitespace<'a>);
impl<'a> Scanner<'a> {
    fn from_str(src: &str) -> Scanner {
        Scanner(src.split_whitespace())
    }
    fn get(&mut self) -> &str {
        self.0.next().unwrap()
    }
    fn read<T: std::str::FromStr>(&mut self) -> T {
        self.get().parse().ok().unwrap()
    }
}

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

int main() {
	int n;
	string s,t;
	cin>>n;
	cin>>s>>t;
	
	string ans;
	rep(i,n){
		ans+=s[i];
		ans+=t[i];
	}
	
	cout<<ans<<endl;
}


Measured memory_bytes: 256
// In the name of God
#include <bits/stdc++.h>

using namespace std;
#define Size(x) ((int)(x).size())
#define pb push_back
typedef long long ll;
typedef long double ld;
typedef pair<int,int>pii;
const int INF = 1e9 + 10;

int main()
{
	ios_base :: sync_with_stdio(false) ,cin.tie(0) , cout.tie(0);
	int counter = 0;
	int n;cin>>n;
	int sv = n;
	while(n--){
		int t;cin>>t;
		counter += (t&1);
	}
	if(sv == 1 || counter%2 == 0) cout << "YES\n";
	else cout << "NO\n";
	return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
 
# 以下を記述しないとTLEになる, 何故？
import numpy
import itertools
# ---- ここまで -----------------------

S = input()
T = input()
lenS = len(S)
lenT = len(T)
F1 = [False]*26
F2 = [False]*26
alpha = 'abcdefghijklmnopqrstuvwxyz'
for i in range(lenS):
    F1[alpha.index(S[i])] = True
for i in range(lenT):
    F2[alpha.index(T[i])] = True
for i in range(26):
    if not F1[i] and F2[i]:
        print(-1)
        exit()

ind = S.index(T[0])
ans = ind+1
for i in range(1,lenT):
    S = S[ind+1:] + S[:ind+1]
    ind = S.index(T[i])
    ans += ind+1

print(ans)


Measured memory_bytes: 14920
#include<iostream>

using namespace std;

int main() {
	int a, b, c, x;
	int cnt = 0;
	cin >> a >> b >> c >> x;
	for (int i = 0;i <= a;i++) {
		for (int j = 0;j <= b;j++) {
			for (int l = 0;l <= c;l++) {
				if (i * 500 + j * 100 + l * 50 == x) {
					cnt++;
				}
			}
		}
	}
	cout << cnt << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>

using namespace std;

template <typename T>
static inline void ArrayInput(vector<T> *A) {
  for (auto itr = A->begin(); itr < A->end(); ++itr) cin >> *itr;
}

template <typename T>
static inline void ArrayPut(vector<T> *A) {
  for (auto itr = A->begin(); itr < A->end(); ++itr) cout << *itr << " ";
  cout << endl;
}

static inline void MainTask() {
  uint32_t n;
  cin >> n;
  vector<uint32_t> p(n);
  ArrayInput(&p);
  vector<uint32_t> v(3);
  uint32_t res = 0;
  for (uint32_t i = 1; i < n - 1; ++i) {
    v[0] = p[i - 1];
    v[1] = p[i];
    v[2] = p[i + 1];
    sort(v.begin(), v.end());
    if (v[1] == p[i]) {
      ++res;
    }
  }
  cout << res << endl;
}

int main() {
  MainTask();

  return 0;
}


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

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

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

int main() {
    int n;
    cin >> n;
    vector<int> v(n);
    for (auto &&i : v) scanf("%d", &i);
    int ans = 0;
    for (int i = 1; i+1 < n; ++i) {
        vector<int> u = {v[i-1], v[i], v[i+1]};
        sort(u.begin(),u.end());
        if(u[1] == v[i]) ans++;
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
# -*- coding: utf-8 -*-


def main():
    N, K = map(int, input().split())
    H = [int(input()) for _ in range(N)]

    H.sort()
    result = float("inf")

    for i in range(K, N + 1):
        result = min(H[i - 1] - H[i - K], result)
    print(result)


if __name__ == "__main__":
    main()


Measured memory_bytes: 7444
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define pi pair<int,int>
#define ff first
#define ss second
#define boost ios::sync_with_stdio(false);cin.tie(nullptr)
#include "string"
#define int long long



vector<int>v = {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};
int32_t main() { 
   boost;
   int k;
   cin>>k;
   cout<<v[k-1]<<endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for(int i = a; i < b; i++)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
typedef long long int lli;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

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

int main(){
    int n;
    cin >> n;
    vector<int> h(n);
    int hMax = 0;
    rep(i,n){
        cin >> h[i];
        hMax = max(hMax, h[i]);
    } 
    int ans = 0;
    for(int i = 1; i <= hMax; i++){
        bool ok = false;
        for (int j = 0; j < n; j++){
            if (h[j] >= i && !ok){
                ok = true;
            }
            else if (h[j] < i && ok){
                ok = false;
                ans++;
            }
        }
        if (ok) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3624
#include <iostream>
#include <string> 
#include <vector> 
#include <algorithm> 
#include <utility> 
#include <tuple> 
#include <cstdint> 
#include <cstdio> 
#include <map> 
#include <queue> 
#include <set> 
#include <stack> 
#include <deque> 
#include <unordered_map> 
#include <unordered_set> 
#include <bitset> 
#include <cctype> 
#include<math.h>
using namespace std;

//#define int long long
#define endl "\n"
#define fir first
#define sec second
#define fro front
#define m_p make_pair
#define mod 1000000007
#define rep(i,n)  for(int i=0; i<(int) (n); i++)
//#define all(v)  v.begin(),v.end()
#define vecin(v) for(int i=0; i<(int)v.size(); i++)cin>>v[i];
using namespace std;

const int MAX = 510000;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];
int jousu(int x00, int y00) {
	int z00 = 1;
	for (int i = 0; i < y00; i++) {
		z00 *= x00;
	}
	return z00;
}
int keta(int x00) {
	int z00 = x00;
	int w00 = 0;
	while (z00 != 0) {
		z00 /= 10;
		w00++;
	}
	return w00;
}

int modinv(int a, int m) {
	int b = m, u = 1, v = 0;
	while (b) {
		int t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
int modpow(int a, int n) {
	int res = 1;
	while (n > 0) {
		if (n & 1) res* a% mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}
int gcd(int xx, int yy) {
	int p = xx;
	int q = yy;
	if (q > p)swap(p, q);
	while (p % q != 0) {
		p %= q;
		swap(p, q);
	}
	return q;
}
int lcm(int xx, int yy) {
	return xx * yy / gcd(xx, yy);
}
bool prime(int xx) {
	int a = xx;
	for (int i = 2; i * i <= xx; i++) {
		if (xx % i == 0) {
			return 0;
		}
	}
	return 1;
}
int com(int xx, int yy) {
	int zz = 1;
	for (int i = xx; i > xx - yy; i--) {
		zz *= i;
		zz %= mod;
	}
	for (int i = 1; i <= yy; i++) {
		zz *= modinv(i, mod);
		zz %= mod;
	}
	return zz;
}


int main() {
	string n;
	cin >> n;
	if (n[0] == '7' || n[1] == '7' || n[2] == '7') {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}





Measured memory_bytes: 3632
import java.util.*;
import java.awt.*;
import static java.lang.System.*;
import static java.lang.Math.*;
public class Main {
    public static void main(String[]$){
        Scanner sc = new Scanner(in);
        int x=sc.nextInt();
        int y=sc.nextInt();
        int ans1=(int)1e9+4;
        int ans2=(int)1e9+4;
        int ans3=(int)1e9+4;
        int ans4=(int)1e9+4;
        if(-x<=-y)ans1=-y+x+2;
        if(-x<=y)ans2=y+x+1;
        if(x<=y)ans3=y-x;
        if(x<=-y)ans4=-y-x+1;
        out.println(min(min(ans1,ans2),min(ans3,ans4)));
    }
}

Measured memory_bytes: 22996
#include <iostream>
#include <string>

using namespace std;

int N;
string S[100005];
long long int C[7];

long long int SUM;

string march = "#MARCH";

int COUNT(int i) {
	int ret = 0;

	for (int j = 1; j <(1<< 5);j*=2) {
		if ((i & j) != 0) { ret++; }
	}
	return ret;
}

void OPE(int i) {

	long long int num = 1;

	for (int k = 0; k <5 ; k++) {
		if ((i & (1 << k)) != 0) { num *= C[k + 1]; }
	}

	SUM += num;
}

int main(void) {

	cin >> N;

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

	for (int i = 1; i <= N; i++) {
		for (int j = 1; j <= 5; j++) {
			if (S[i][0] == march[j]) { C[j]++; }
		}
	}

/*	for (int i = 1; i <= 5; i++) {
		cout <<march[i]<<" "<< C[i] << endl;
	}*/
	SUM = 0;

	for (int i = 1; i < (1 << 5); i++) {
		if (COUNT(i) == 3) {
			//cout << i << endl;
			OPE(i);
		}
	}
	
	cout << SUM << endl;

	//system("pause");
	return 0;
}

Measured memory_bytes: 6144
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define ll long long int
#define vi vector<int>
#define vl vector<ll>
#define ppi pair<int,int>
#define ppl pair<ll,ll>
#define all(x) x.begin(),x.end()
#define ii int,int 
#define ff first    
#define ss second
#define forn(i,a,b) for(int i=a;i<b;i++)
#define forr(i,a,b) for(int i=a;i>=b;i--)
#define forv(i,m) for(auto i : m)
#define imx INT_MAX
#define imn INT_MIN
#define inf LONG_MAX
#define minf LONG_MIN
#define endl "\n"
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define sze size()
#define rvs reverse 
#define itr iterator 
#define pre cout<<fixed<<setprecision(10);
#define umap unordered_map
#define uset unordered_set

/*
#define MODM(a,b,md) ((a%md)*(b%md))%md
#define MODA(a,b,md) ((a%md)+(b%md))%md
#define ull unsigned long long int
#define si short int
*/

/*
bool compare(int a,int b) {return a > b;}
bool compare1(ppi a,ppi b) {return a.ff > b.ff;}
bool compare2(ppi a,ppi b) {return a.ss < b.ss;}
ll Npower(ll a,ll b) {ll product = 1; while(b){if(b&1){product = product*a;}a = a*a;b = b>>1;} return product;}
ll power(ll a,ll b,ll md) {ll product = 1; while(b){if(b&1){product = MODM(product,a,md);}a = MODM(a,a,md);b = b>>1;} return product%md;}
ll GCD(ll a,ll b) {return b==0 ? a:GCD(b,a%b);}
ll LCM(ll a,ll b) {return (a/GCD(a,b))*b; }
*/


int main()
{
    fast

    string str;
    cin>>str;

    int mini = imx;
    forn(i,0,str.sze-2)
    {
        mini = min(mini, abs((str[i]-'0')*100+(str[i+1]-'0')*10+str[i+2]-'0' - 753)       );
    }

    cout<<mini;
    return 0;
}

Measured memory_bytes: 256
n,m=map(int,input().split())
A=[]
for i in range(n):
    A.append(list(map(int,input().split())))
b=[]
for j in range(m):
    b.append([int(input())])
Ab=[[0]for i in range(n)]
for i in range(n):
    for j in range(m):
        Ab[i][0]+=A[i][j]*b[j][0]
    print(Ab[i][0])


Measured memory_bytes: 6028
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp(x) fixed << setprecision(x)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const int inf = (1<<30)-1;
const ll INF = (1LL<<60)-1;
const ld EPS = 1e-10;
template<typename T> bool chmax(T &x, const T &y) {return (x < y)? (x = y, true) : false;};
template<typename T> bool chmin(T &x, const T &y) {return (x > y)? (x = y, true) : false;};

template<typename Monoid>
struct Segment_Tree{
    Monoid f(Monoid a, Monoid b){
        return min(a, b);
    }
    const Monoid unit;
    int n;
    vector<Monoid> seg;
    
    Segment_Tree(int N, const Monoid &x) : unit(x){
        n = 1;
        while(n < N) n <<= 1;
        seg.assign(2*n, unit);
    }
    
    void change(int i, const Monoid &x){
        i += n;
        seg[i] = x;
        while(i > 0){
            i /= 2;
            seg[i] = f(seg[2*i], seg[2*i+1]);
        }
    }

    Monoid query(int a, int b, int i = 1, int l = 0, int r = -1){
        if(r < 0) r = n;
        if(a >= r || b <= l) return unit;
        if(a <= l && r <= b) return seg[i];
        Monoid vl = query(a, b, 2*i, l, (l+r)/2);
        Monoid vr = query(a, b, 2*i+1, (l+r)/2, r);
        return f(vl, vr);
    }
    
    Monoid operator [] (int i) const {return seg[n+i];}
    
    void clear(){
        fill(seg.begin(), seg.end(), unit);
    }
};

int main(){
    int N, Q, A, B;
    cin >> N >> Q >> A >> B;
    A--, B--;
    Segment_Tree<ll> seg(N, INF), seg1(N, INF), seg2(N, INF);
    seg.change(B, 0), seg1.change(B, -B), seg2.change(B, B);
    ll sum = 0; int pre = A;
    while(Q--){
        int now; cin >> now; now--;
        int d = abs(pre-now);
        sum += d;
        ll tmp = seg[pre];
        chmin(tmp, seg1.query(0, now)+now-d);
        chmin(tmp, seg2.query(now, N)-now-d);
        seg.change(pre, tmp), seg1.change(pre, tmp-pre), seg2.change(pre, tmp+pre);
        pre = now;
    }
    cout << seg.query(0, N)+sum << endl;
}

Measured memory_bytes: 15652
import java.util.Scanner

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val n = sc.nextInt()
    val k = sc.nextInt()

    val a = IntArray(n)
    var minIndex: Int = -1
    for (i in 0 until n) {
        a[i] = sc.nextInt()
        if (a[i] == 1) {
            minIndex = i
        }
    }

    println(replaceLeft(minIndex, minIndex, n, k))
}

fun replaceLeft(leftIndex: Int, rightIndex: Int, n: Int, k: Int): Int {
    if (leftIndex - k + 1 <= 0) {
        val right = if (k - 1 > rightIndex) {
            k - 1
        } else {
            rightIndex - (leftIndex - k + 1)
        }
        return replaceRight(right, n, k) + 1
    }
    return replaceLeft(leftIndex - k + 1, rightIndex, n, k) + 1
}

fun replaceRight(rightIndex: Int, n: Int, k: Int): Int {
    if (rightIndex >= n - 1) {
        return 0
    }
    return replaceRight(rightIndex + k - 1, n, k) + 1
}

Measured memory_bytes: 54228
import java.util.Scanner

object Main extends App { 
  val sc = new Scanner(System.in)
  val _N, _Q = sc.nextInt()
  val _An = (for (i <- 0 until _N) yield sc.nextLong()).toArray
  val _Xq = (for (i <- 0 until _Q) yield sc.nextLong()).toList

  def count(x:Long, n:Int, arr:Array[Long]):Long = {
    def iter(l:Int, r:Int, ac:Long, cnt:Long):Long = {
      if (l == n) cnt
      else if (r < n && ac + arr(r) <= x) iter(l, r+1, ac + arr(r), cnt)
      else iter(l+1, r, ac - arr(l), cnt + r - l)
    }
    iter(0, 0, 0, 0)
  } 

  def solver(list:List[Long], acc:List[Long]):List[Long] = {
    if (list.isEmpty) acc.reverse
    else solver(list.tail, count(list.head, _N, _An)::acc)
  }

  solver(_Xq, Nil).foreach(println)

}



Measured memory_bytes: 135608
#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>
#include <map>
#include <string>

using namespace std;

int main(){
  int n,m,i,j,k;
  string s;
  cin >> s;
  int cnt=0;
  for(i=0;i<4;i++)if(s[i]=='2')cnt++;
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std; inline void fileio(const char* in, const char* out) { freopen(in, "r", stdin); freopen(out, "w", stdout); } 
#define TD typedef
#define forx(i,n) for(int i = 0; i < (n); ++i)
TD long long ll; TD long double ld; TD pair<int,int> pii; TD pair<ll, ll> pll; TD vector<int> VI; TD vector<bool> VB; TD vector<ll> VL;
const char nl = '\n'; const int INF = 0x3f3f3f3f; const ll LINF = 0x3f3f3f3f3f3f3f3fll; const ld EPS = 1e-9, PI = acos(-1);
#define ff first
#define ss second

#ifndef NDEBUG
#define trace(var)  {cerr << "Line " << __LINE__ << ": " << #var << "=" << (var) << nl;}
#else
#define trace(var)	{}
#endif

string LCS(string a, string b) {
  vector<VI> len(a.size()+1, VI(b.size()+1, 0));
  // len[i][j] = lcs length using a[:i-1], b[:j-1]
  forx(i,a.size()) {
    forx(j,b.size()) {
      len[i+1][j+1] = max(len[i][j] + (a[i]==b[j]), max(len[i][j+1], len[i+1][j]));
    }
  }
  int i = a.size(), j = b.size(), idx = len[i][j];
  string ans(idx, '*');
  while(idx > 0) {
    if (len[i][j] == len[i-1][j]) {
      i--;
    } else if (len[i][j] == len[i][j-1]) {
      j--;
    } else {
      ans[--idx] = a[i-1];
      i--;
      j--;
    }
  }
  return ans;
}

int main() {
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  // Emily <3
  string s, t;
  cin >> s >> t;
  string ans = LCS(s,t);
  cout << ans << nl;
  
  cerr << "Time: " << (ld)clock() / CLOCKS_PER_SEC << nl;
  return 0;
}



Measured memory_bytes: 35584
import std.algorithm;
import std.bigint;
import std.bitmanip;
import std.concurrency : generator = Generator, yield;
import std.container;
import std.conv;
import std.functional;
import std.format;
import std.math;
import std.meta;
import std.numeric;
import std.random;
import std.range;
import std.stdio;
import std.string;
import std.traits;
import std.typecons;


auto solve(long[] A) {
    return sum(A) <= 21 ? "win" : "bust";
}


void main() {
    auto input = stdin.byLine.map!split.joiner;

    long[] A = new long[](cast(size_t) (3));
    foreach (i; 0 .. cast(size_t) (3)) {
        A[i] = input.front.to!long;
        input.popFront;
    }

    static if (is(ReturnType!solve == void))
        solve(A);
    else {
        auto ans = solve(A);

        static if (isFloatingPoint!(ReturnType!solve))
            writeln(format("%.9f", ans));
        else static if (is(ReturnType!solve == bool))
            writeln(ans ? YES : NO);
        else
            writeln(ans);
    }
}


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

using namespace std;
#define rep(i, n) for(int i=0;i<n;i++)
#define REP(i, n) for(int i=1;i<=n;i++)
typedef long long ll;

const ll mod = 1000000007;

int main() {
	ll n, m;
	cin >> n >> m;
	if (abs(n - m) >= 2) {
		cout << 0 << endl;
		return 0;
	}
	ll M = min(m, n);
	ll N = max(m, n);
	ll ans = 1;
	if (M == N) {
		ans *= 2;
	}
	rep(i, N) {
		ans *= i + 1;
		ans %= mod;
	}
	rep(i, M) {
		ans *= i + 1;
		ans %= mod;
	}
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 3596
#include<bits/stdc++.h>
using namespace std;
list<char>lst;
string s;
int q;
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>s>>q;
	int n=s.size();
	bool re=0;
	for(int i=0;i<n;i++) lst.push_back(s[i]);
	while(q--) {
		int t;
		cin>>t;
		if(t==1) re=!re;
		else {
			int f;
			char c;
			cin>>f>>c;
			f--;
			f^=re;
			if(f==0) lst.push_front(c);
			else lst.push_back(c);
		}
	}
	if(re==0)
		for(list<char>::iterator i=lst.begin();i!=lst.end();i++) cout<<*i;
	else
		for(list<char>::reverse_iterator i=lst.rbegin();i!=lst.rend();i++) cout<<*i;
	return 0;
}

Measured memory_bytes: 10064
import sys
import math
from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN
from collections import deque
def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def S(): return sys.stdin.readline().rstrip()
def LS(): return sys.stdin.readline().split()
def LS2(N): return [sys.stdin.readline().split() for i in range(N)]
def FILL(i,h): return [i for j in range(h)]
def FILL2(i,h,w): return [FILL(i,w) for j in range(h)]
def FILL3(i,h,w,d): return [FILL2(i,w,d) for j in range(h)]
def FILL4(i,h,w,d,d2): return [FILL3(i,w,d,d2) for j in range(h)]
def sisha(num,digit): return Decimal(str(num)).quantize(Decimal(digit),rounding=ROUND_HALF_UP)
#'0.01'や'1E1'などで指定、整数に戻すならintをかます
MOD = 1000000007
INF = float("inf")
sys.setrecursionlimit(10**5+10)
input = sys.stdin.readline

K,N = MI()
l = LI()
max_dis = 0
for i in range(N):
    if i < N-1:
        next_dis = l[i+1]-l[i]
    else:
        next_dis = l[0]+(K-l[i])
    max_dis = max(max_dis,next_dis)
print(K-max_dis)


Measured memory_bytes: 92536
#include<iostream>
#include <string>
#include<vector>
#include<algorithm>
#include <cstdlib>
using namespace std;
int main(){
    int n,t,ans=2000;
    cin >> n >> t;
    vector<int> a(n);
    vector<int> b(n);
    for(int i=0;i<n;i++){
        cin >> a[i] >> b[i];
        if(b[i] <= t && ans > a[i]){
            ans = a[i];
        }
    }
    if(ans == 2000){
        cout << "TLE" << endl;
    }
    else{
        cout << ans << endl;
    }

return 0;
    
}

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

#ifdef LOCAL
#define debug(var) cerr << (#var) << " = " << (var) << endl;
#else
#define debug(var)
#endif

void init() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
}

long long dp[4][123][2];
string n;
int k;

long long rek(int cnt, int pos, bool f) {
  if (cnt > k) return 0;
  if (pos == n.size()) return cnt == k;
  long long &ret = dp[cnt][pos][f];
  if (ret != -1) return ret;
  ret = 0;
  int lmt = f?9:(n[pos]-'0');
  for (int i = 0; i <= lmt; ++i) {
    int ncnt = cnt;
    if (i) ++ncnt;
    bool nf = f;
    if (!f && i < lmt) nf = 1;
    ret += rek(ncnt, pos+1, nf);
  }
  return ret;
}

void solve() {
  cin >> n >> k;
  memset(dp, -1, sizeof(dp));
  cout << rek(0,0,0);
}

int main() {
  init();
  int t = 1; //scanf("%d", &t);
  while (t--) {
    solve();
  }
  return 0;
}


Measured memory_bytes: 3556
import sys

input = sys.stdin.readline
H, W = map(int, input().split())
grid = []
for _ in range(H):
    grid.append(list(input().strip()))

h_set = set()
for i in range(H):
    flag = True
    for j in range(W):
        if grid[i][j] == "#":
            flag = False
            break
    if flag:
        h_set.add(i)

w_set = set()
for j in range(W):
    flag = True
    for i in range(H):
        if grid[i][j] == "#":
            flag = False
            break
    if flag:
        w_set.add(j)

for i in range(H):
    if i in h_set:
        continue
    for j in range(W):
        if j in w_set:
            continue
        print(grid[i][j], end="")
    print("")

Measured memory_bytes: 9236