akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <bitset>
#include <cmath>
#include <ctime>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <vector>
#define rep(i,n) for(int i = 0; i < (n); i++)
#define all(a) a.begin(),a.end()
using namespace std;
using ll = long long;
using P = pair<int,int>;
using vi = vector<int>;
using vvi = vector<vi>;

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

template <typename T>
bool chmax(T &a, T &b) {
  if(a < b) {
    a = b;
    return true;
  }
  return false;
}

template <typename T>
bool chmin(T &a, T &b) {
  if(a > b) {
    a = b;
    return true;
  }
  return false;
}






#define FOR(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i>b;i--)
#define vint vector<int> 
#define vvint vector<vint>
#define CST(x) cout<<fixed<<setprecision(x)//小数点以下の桁数指定
#define ct(a) cout<<a<<endl
static const double pi = 3.141592653589793;
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const int INF = 1e9+7;
const int mod= 1e9 + 7;

ll RepeatedSquaring(ll N, ll P, ll M) {
  if(P==0) return 1;
  if(P%2==0) {
    ll t = RepeatedSquaring(N, P/2, M);
    return t*t % M;
  }
  return N*RepeatedSquaring(N, P-1, M)%M;
}



ll modre(ll num) {
  num %= MOD;
  if(num < 0) num += MOD;
  return num;
}

ll mod_pow(ll x,ll n) {
	if (n == 0) return 1;
	ll res = mod_pow(x*x % mod, n / 2);
	if (n & 1) res = res * x % mod;
	return res;
}
 

 
ll comb(ll n, ll x) {
	ll ret = 1,k=1;
	rep(i,x)ret = (ret * (n - i))%mod;
	rep(i,x)k = (k * (x-i))%mod;
	// k = RepeatedSquaring(k, MOD-2, MOD);
	k = mod_pow(k, mod - 2);
	ret = (ret*k + mod) % mod;
	return ret;
}
  
int main() {
  ll a,b,n;
  cin >> n >> a >> b;
  ll ans = RepeatedSquaring(2, n, MOD) - 1;
  a = comb(n,a);
  b = comb(n,b);
  cout << modre(ans - a - b) << endl;
}






Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<sstream>
#include<utility>
#include<map>
#include<vector>
#include<queue>
#include<algorithm>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
char I[1000],*p;
int R[15],N;
double B,EPS=0.00001,dp[1<<13][13];

double calc(int a,int b)
{
	if(a==-1)return R[b];
	if(b==-1)return R[a];
	int x=R[a]+R[b],y=R[a]-R[b];
	return sqrt((double)(x*x-y*y));
}

double dfs(int f,int s,int d)
{
	if(s>=0&&dp[f][s]>0)return dp[f][s];
	if(d==N)
	{
		return R[s];
	}
	double res=1000000;
	for(int i=0;i<N;i++)
	{
		if(!(f>>i&1))
		{
			res=min(res,dfs(f|1<<i,i,d+1)+calc(s,i));
		}
	}
	if(s>=0)dp[f][s]=res;
	return res;
}

int main()
{
	for(;gets(I);)
	{
		memset(dp,0,sizeof(dp));
		p=strtok(I," ");
		B=(double)atoi(p);
		for(N=0;(p=strtok(NULL," "))!=NULL;)
			R[N++]=atoi(p);
		puts(B-dfs(0,-1,0)>=-EPS?"OK":"NA");
	}
}

Measured memory_bytes: 1936
#include <stdio.h>
#include <stdlib.h>

int main()
{
    char c;
    int Lowercase;
    scanf("%c",&c);

    Lowercase = (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u');
    if (Lowercase)
     printf("vowel");
    else
    printf("consonant");

    return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<queue>
#include<deque>
#include<cmath>
#include<map>
#include<unordered_map>
#include<set>
#include<cstring>
#include<iomanip> //cout << fixed << setprecision(15) << x << endl;

using namespace std;
typedef long long ll;
const ll INF = 1e9 + 6;
const ll MOD = 1e9 + 7;
const ll LLINF = 1LL<<60;
#define Pint pair<int, int>
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
/* -- template -- */

int main() {
    int N; cin >> N;
    int A[N];
    rep(i, N) {
        cin >> A[i];
    }
    sort(A, A + N);
    int posPlus = -1;
    rep(i, N) {
        if(A[i] > 0) {
            posPlus = i;
            break;
        }
    }
    if(posPlus == 0) {//plus only
        vector<Pint> ans;
        rep(i, N - 2) {
            ans.pb(mp(A[i], A[i + 1]));
            A[i + 1] = A[i] - A[i + 1];
        }
        ans.pb(mp(A[N - 1], A[N - 2]));
        cout << A[N - 1] - A[N - 2] << endl;
        rep(i, N - 1)
            cout << ans[i].first << ' ' << ans[i].second << endl;
    }else if(posPlus == -1) { //minusonly
        vector<Pint> ans;
        rep(i, N - 1) {
            ans.pb(mp(A[N - 1], A[i]));
            A[N - 1] = A[N - 1] - A[i];
        }
        cout << A[N - 1] << endl;
        rep(i, N - 1)
            cout << ans[i].first << ' ' << ans[i].second << endl;
    }else {
        vector<Pint> ans;
        for(int i = posPlus - 1; i < N - 2; ++i) {
            ans.pb(mp(A[i], A[i + 1]));
            A[i + 1] = A[i] - A[i + 1];
            A[i] = INF;
        }

        rep(i, N - 1) {
            if(A[i] == INF) continue;
            ans.pb(mp(A[N - 1], A[i]));
            A[N - 1] = A[N - 1] - A[i];
        }
        cout << A[N - 1] << endl;
        rep(i, N - 1)
            cout << ans[i].first << ' ' << ans[i].second << endl;
    }
}


Measured memory_bytes: 3188
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <queue>
#include <map>
#include <stack>
#include <bitset>
#include <numeric> //lcm
#include <iomanip> //double精度 setprecision

using namespace std;

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = n-1; i >= 0; --i)
#define rep1(i,n) for(int i = 1; i <= (n); ++i)
#define rrep1(i,n) for(int i = (n); i >= 1; --i)
#define REP(i,n,m) for(int i = (n); i < (m); ++i)
#define all(vec) (vec).begin(),(vec).end()

#define debug(vec) for(auto v : vec) cerr << v << " "; cerr << endl;
#define debug2D(vec2D) for(auto vec : vec2D) { for (auto v : vec) cerr << v << " "; cerr << endl; } 
#define debugP(vec) for(auto v : vec) cerr << "(" << v.first << "," << v.second << ") "; cerr << endl;
#define debug2DP(vec2D) for(auto vec : vec2D) { for (auto v : vec) cerr << "(" << v.first << "," << v.second << ") "; cerr << endl; } 

typedef long long ll;

constexpr ll INF = 1000000000; //10^10
//const ll MOD = 998244353;
constexpr ll MOD = 1000000007;

template<class T>inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } else return false; }
template<class T>inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } else return false; }


int main() {
  ll n, a, b; cin >> n >> a >> b;

	string s; cin >> s;
  int ac = 0; 
	int ac1 = 0;
	for (char c : s) {
		if(c == 'a' && ac < a + b) {cout << "Yes" << endl; ac++;}
		else if(c == 'b' && ac < a + b && ac1 < b) {cout << "Yes" << endl; ac++; ac1++; }
		else cout << "No" << endl;
	}
}

Measured memory_bytes: 896
import sys

def input():
    return sys.stdin.readline().rstrip()

if __name__ == "__main__":
    s = input()

    dict = {}
    for l in s:
        if l in dict.keys():
            dict[l] = dict[l] + 1
        else:
            dict[l] = 1

    if len(dict.keys()) == 2:
        is_ok = True
        for v in dict.values():
            if v != 2:
                is_ok = False
                break
        print("Yes" if is_ok else "No")
    else:
        print("No")


Measured memory_bytes: 3060
import java.util.*;
import java.io.*;
import java.nio.charset.StandardCharsets;

public class Main {
	char[] T, result;
	int N;

	public static void main(String[] args) throws IOException {
		InputStreamReader reader = new InputStreamReader(System.in, StandardCharsets.UTF_8);
		BufferedReader in = new BufferedReader(reader);
		Main ins = new Main(in);
		ins.calc();
		ins.showResult();
	}

	Main(BufferedReader in) throws IOException {
		T = in.readLine().toCharArray();
		N = T.length;
		result = new char[N];
	}

	void init() {
		// 最初を埋める
		if (T[0] == '?') {
			if (T[1] == '?') {
				result[0] = 'P';
			} else if (T[1] == 'P') {
				result[0] = 'D';
			} else {
				result[0] = 'P';
			}
		} else {
			result[0] = T[0];
		}
	}

	void calc() {
		if (N == 1) {
			if (T[0] == '?') {
				System.out.println('D');
			} else {
				System.out.println(T[0]);
			}
		} else {
			init();
			for (int i = 1; i + 1 < N; ++i) {
				if (result[i - 1] == 'P') {
					if (T[i] == '?') {
						result[i] = 'D';
					} else {
						result[i] = T[i];
					}
				} else {
					if (T[i] == '?') {
						if (T[i + 1] == '?' || T[i + 1] == 'D') {
							result[i] = 'P';
						} else {
							result[i] = 'D';
						}
					} else {
						result[i] = T[i];
					}
				}
			}
			if (T[N - 1] == '?') {
				result[N - 1] = 'D';
			} else {
				result[N - 1] = T[N - 1];
			}
			for (int i = 0; i < N; ++i) {
				System.out.print(result[i]);
			}
			System.out.println("");
		}
	}

	void showResult() {
	}
}

Measured memory_bytes: 55432
#include <bits/stdc++.h>
using namespace std;
#define SZ(x) (int)(x.size())
#define REP(i, n) for(int i=0;i<(n);++i)
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define RREP(i, n) for(int i=(int)(n)-1;i>=0;--i)
#define RFOR(i, a, b) for(int i=(int)(b)-1;i>=(a);--i)
#define ALL(a) a.begin(),a.end()
#define DUMP(x) cerr<<#x<<" = "<<(x)<<endl
#define DEBUG(x) cerr<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<< endl;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<int, int>;
const double eps = 1e-8;
const ll MOD = 1000000007;
const int INF = INT_MAX / 2;
const ll LINF = LLONG_MAX / 2;
template <typename T1, typename T2>
bool chmax(T1 &a, const T2 &b) {
    if (a < b) { a = b; return true; }
    return false;
}
template <typename T1, typename T2>
bool chmin(T1 &a, const T2 &b) {
    if (a > b) { a = b; return true; }
    return false;
}
template<typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
    os << "[";
    REP(i, SZ(v)) {
        if (i) os << ", ";
        os << v[i];
    }
    return os << "]";
}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const map<T1, T2> &mp) {
    os << "{";
    int a = 0;
    for (auto &tp : mp) {
        if (a) os << ", "; a = 1;
        os << tp;
    }
    return os << "}";
}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
    os << p.first << ":" << p.second;
    return os;
}

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

    int n; cin >> n;
    vi a(n); REP(i, n) cin >> a[i];

    ll ans = 0;
    ll sum = 0;
    int r = 0;
    REP(l, n) {
        while (r < n and (sum & a[r]) == 0) sum |= a[r], ++r;
        ans += r - l;
        sum &= ~a[l];
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>

using namespace std;
typedef long long ll;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    int N, M;
    cin >> N >> M;
    int ans = (N*(N-1))/2 + (M*(M-1))/2;
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define rep(i, n) repd(i, 0, n)

using namespace std;

namespace mp = boost::multiprecision;

using ll = long long;
using Bint = mp::cpp_int;
ll mod = pow(10, 9) + 7;

int main() {
    // source
    ll n;
    string s;
    cin >> n;
    cin >> s;

    rep(i, s.length()) {
        char temp = s[i];
        int num = temp - 'A';
        num += n;
        num %= 26;
        temp = 'A' + num;

        s[i] = temp;
    }

    cout << s << endl;
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(),v.end()
#define RALL(v) v.rbegin(),v.rend()
#define check(v) rep(i,v.size()) cout << v[i] << " ";\
cout << endl
#define INF 1e9
typedef long long ll;
using namespace std;
//オーバーフローに気をつけろよおおおおおお
//確認忘れるなよおおおおおお

int main() {
    vector<string> v(3);
    rep(i,3) cin >> v[i];
    bool bol = true;
    int flag = 0;
    char ans;
    while(bol){
        if(v[flag].size()==0) {
            if(flag==0) ans = 'A';
            if(flag==1) ans = 'B';
            if(flag==2) ans = 'C';

            bol = false;
        }
        else if(v[flag][0]=='a') {
            v[flag] = v[flag].substr(1,v[flag].size());
            flag = 0;
        }
        else if(v[flag][0]=='b') {
            v[flag] = v[flag].substr(1,v[flag].size());
            flag = 1;
        }
        else if(v[flag][0]=='c') {
            v[flag] = v[flag].substr(1,v[flag].size());
            flag = 2;
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
import sys, math
from collections import defaultdict, deque, Counter
from bisect import bisect_left, bisect_right
from itertools import combinations, permutations, product
from heapq import heappush, heappop
from functools import lru_cache
input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(input())
rl = lambda: list(map(int, input().split()))
mat = lambda x, y, v: [[v]*y for _ in range(x)]
ten = lambda x, y, z, v: [mat(y, z, v) for _ in range(x)]
mod = 1000000007
sys.setrecursionlimit(1000000)

N = ri()
D = []
for i in range(N):
	d = rl()
	D.append(d)

c = 0
for a, b in D:
	if a == b:
		c += 1
	else:
		c = 0
	if c >= 3:
		print('Yes')
		exit()
print('No')

Measured memory_bytes: 67956
#define _USE_MATH_DEFINES

#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <bitset>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef tuple<ll, ll, ll> tl3;



const int BIG_NUM = 1e9;
const ll INF = 1000000000000000000;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;

ll a, b, c, d;

map<ll, ll> m;
ll dist(ll k) {
	if (m.find(k) != m.end()) {
		return m[k];
	}

	if (k == 0) {
		m[0] = 0;
		return 0;
	}
	if (k == 1) {
		m[1] = d;
		return d;
	}

	ll r = d * k;
	if (INF / d < k) {
		r = INF;
	}

	for (int i = -1; i <= 1; ++i) {
		ll num = k + i;

		if (num >= 0 && num % 2 == 0) {
			r = min(r, dist(num / 2) + a + d * abs(i));
		}
	}

	for (int i = -2; i <= 2; ++i) {
		ll num = k + i;
		if (num >= 0 && num % 3 == 0) {
			r = min(r, dist(num / 3) + b + d * abs(i));
		}
	}
	for (int i = -3; i <= 3; ++i) {
		ll num = k + i;
		if (num >= 0 && num % 5 == 0) {
			r = min(r, dist(num / 5) + c + d * abs(i));
		}
	}
	m[k] = r;

	return m[k];
}




int main() {
	int t;
	cin >> t;
	for (int i = 0; i < t; i++) {
		ll n;
		cin >> n;

		cin >> a >> b >> c >> d;
		m.clear();
		cout << dist(n) << endl;
	}


}

Measured memory_bytes: 4332
nums = [int(e) for e in input().split()]
a=nums[0]
b=nums[1]
c=nums[2]
d=nums[3]
max = a*c
if a * d > max:
    max = a * d
if b * c > max:
    max = b * c
if b * d > max:
    max = b * d

print(max)

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

int main() {
    int n; cin >>n;
    vector<int> a(n+1);
    for (int i = 0; i < n+1; i++) cin >>a.at(i);
    long long ret = 0;
    int over = 0;
    for (int i = 0; i < n; i++) {
        ret += min(over,a.at(i));
        a.at(i) = max(a.at(i) - over, 0);

        int b; cin >>b;
        ret += min(b, a.at(i));
        over = max(b-a.at(i), 0);
    }
    ret += min(over, a.at(n));
    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 640
N, M = map(int ,input().split())

i = 1
A = []
B = []

while i*i <= M:
  if M % i == 0:
    A.append(i)
    B.append(M//i)
  i += 1 
    
for i in range(len(B)):
  if A[i] >= N:
    print(B[i])
    exit()
    
for i in range(len(A)-1,-1,-1):
  if B[i] >= N:
    print(A[i])
    exit()

Measured memory_bytes: 63596
from bisect import *
from collections import *
from fractions import gcd
from math import factorial
from itertools import *

N=int(input())

if N==3:
    print(2,5,63)
elif N==4:
    print(2,5,20,63)
elif N==5:
    print(2,5,20,63,30)
else:
    lst=[2,3,4,6,9,12]
    count=N-6
    div2=[i for i in range(10,30001,2) if i%6!=0]
    div2.append(8)
    #if len(div2)%2==1:
    #    div2.pop()
    div3=[i for i in range(15,30001,6)]
    #if len(div3)%2==1:
    #    div3.pop()
    div6=[i for i in range(18,30001,6)]
    #print(len(div2),len(div3),len(div6))
    while count>=2 and len(div2)>=2:
        lst.append(div2.pop())
        lst.append(div2.pop())
        count-=2
    while count>=2 and len(div3)>=2:
        lst.append(div3.pop())
        lst.append(div3.pop())
        count-=2
    while count>=1:
        lst.append(div6.pop())
        count-=1
    print(" ".join(list(map(str,lst))))


Measured memory_bytes: 67436
# -*- coding: utf-8 -*-
import math

#入力
N = input()
S = input()

if S[0] == ")" :
  S = "(" + S
if S[-1] == "(" :
  S = S + ")"

r = S.count("(")
l = S.count(")")

if r < l :
  for i in range(l-r) :
    S = "(" + S
elif r > l :
  for i in range(r-l) :
    S = S + ")"

nowS = S
endflag = 0
while endflag == 0 :
  S = nowS
  while (len(S) != 0) :
    S = S.replace("()", "")
    if "()" not in S :
      break
    
  if len(S) == 0 :
    print (nowS)
    endflag = 1
  else :
    nowS = "(" + nowS + ")"

Measured memory_bytes: 3064
program ABC167_D
  integer(8)::N,K,X,Y,Z
  integer(8),allocatable::A(:),S(:),T(:)
  read(*,*)N,K
  allocate(A(N),S(N),T(N))
  read(*,*)A
  M=1
  L=1
  S=0
  T=0
  T(1)=1
  S(1)=1
  do i=1,N
     M=A(M)
     S(M)=S(M)+1
     if(S(M)==2) then
        do j=1,N
           if(L==M) then
              X=i-j+1
              Y=i
              Z=j
              go to 10
           end if
           L=A(L)
        end do
     end if
  end do
10 if(K>N) then
      K=mod(K-Z+1,X)+Z-1
      end if
      
      
  M=1
  do i=1,K
     M=A(M)
  end do
  write(*,*)M
end program ABC167_D

Measured memory_bytes: 7764
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define int long long
#define double long double
#define mod 1000000007
#define F first
#define S second
#define P pair<long long,long long>
#define all(a) a.begin(),a.end()
#define INF 1000000000000000000
#define endl '\n'
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; }
using namespace std;

signed main(){
    int n; cin>>n; n--;
    vector<int> c(n),s(n),f(n),ans(n);
    rep(i,n)cin>>c.at(i)>>s.at(i)>>f.at(i);
    rep(i,n){
        int tmp=0,place=i;
        while(place<n){
            if(tmp<s.at(place)){
                tmp=s.at(place)+c.at(place);
                place++;
            }else{
                tmp=((tmp+f.at(place)-1)/f.at(place))*f.at(place)+c.at(place);
                place++;
            }
        }
        ans.at(i)=tmp;
    }
    rep(i,n){
        cout<<ans.at(i)<<endl;
    }
    cout<<0<<endl;
}

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

d = {}
for i in range(1,N+1):
    s,p = input().split()
    if s in d.keys():
        d[s].append([i,int(p)])
    else:
        d[s] = [[i,int(p)]]

for s in sorted(list(d.keys())):
    for c in sorted(d[s],key=lambda x:-x[1]):
        print(c[0])

Measured memory_bytes: 3060
A, B, C, X = [int(input()) for _ in range(4)]
ans = 0

for a in range(A+1):
    for b in range(B+1):
        for c in range(C+1):
            if 500*a + 100*b + 50*c == X:
                ans = ans + 1
                
print(ans)

Measured memory_bytes: 9076
using CompLib.Util;
using System;

public class Program
{

    public void Solve()
    {
        var sc = new Scanner();
        int n = sc.NextInt();
        int k = sc.NextInt();

        long a = 1;
        for (int i = 0; i < n; i++)
        {
            if(a <= k)
            {
                a *= 2;
            }
            else
            {
                a += k;
            }
        }
        Console.WriteLine(a);
    }

    public static void Main(string[] args) => new Program().Solve();
}

namespace CompLib.Util
{
    using System;
    using System.Linq;
    class Scanner
    {
        private int _index;
        private string[] _line;
        const char separator = ' ';

        public Scanner()
        {
            _index = 0;
            _line = new string[0];
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(separator);
                _index = 0;
            }
            return _line[_index++];
        }
        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(separator);
            _index = _line.Length;
            return _line;
        }
        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
    }
}

Measured memory_bytes: 13140
#include <iostream>
#include <climits>
#include <cstring>
#include <cstdio>
using namespace std;

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

const int inf = INT_MAX/3;
int riku[210][210];
int umi[210][210];
int dp[1010][210]; // [ツ妥ョツ配][ツ船ツづ個暗環置]

int main(){
  int n,m;
  int taku[1010];

  while(cin>>n>>m,n|m){
    //init
    rep(i,210)rep(j,210)riku[i][j]=umi[i][j]=inf;
    rep(i,210)riku[i][i]=umi[i][i]=0;
    rep(i,1010)rep(j,210)dp[i][j]=inf;

    rep(i,m){
      int a,b,c; char l;
      scanf(" %d %d %d %c ",&a,&b,&c,&l);
      a--, b--;
      if( l=='S' ){
	int d = min(umi[a][b],c);
	umi[a][b] = umi[b][a] = d;
      }else{
	int d = min(riku[a][b],c);
	riku[a][b] = riku[b][a] = d;
      }
    }
    int R; cin>>R;
    rep(i,R){
      int r; cin>>r; r--;
      taku[i] = r;
    }

    // worshal
    rep(k,n)rep(i,n)rep(j,n){
      if( riku[i][k]!=inf && riku[k][j]!=inf ){
	riku[i][j] = min(riku[i][j], riku[i][k]+riku[k][j]);
      }
      if( umi[i][k]!=inf && umi[k][j]!=inf ){
	umi[i][j] = min(umi[i][j], umi[i][k]+umi[k][j]);
      }
    }

    dp[1][taku[0]] = 0;
    REP(r,1,R){
      int v = taku[r-1];
      int u = taku[r];
      rep(j,n){
	if( riku[v][u]!=inf ) dp[r+1][j] = min(dp[r+1][j], dp[r][j]+riku[v][u]);
	if( riku[v][j]==inf ) continue;
	rep(i,n){
	  if( umi[j][i]==inf || riku[i][u]==inf )continue;
	  dp[r+1][i] = min(dp[r+1][i], dp[r][j]+riku[v][j]+umi[j][i]+riku[i][u]);
	}
      }
    }
    int ans = inf;
    rep(i,n)ans=min(ans,dp[R][i]);
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 2092
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
ll a,b,c,i,j,k,l,m,n,x,y,z,ans,tmp,hoge,fuga,piyo;
ll xx[10010],yy[10010];
ll aa[13][13],cc[13],skill[13],ab[13],ac;
string s,str;
int main(){
  cin>>n>>m>>x;
  ll acmin=1000000000000;
  for(int i=0;i<n;i++){
    cin>>cc[i];
    for(int j=0;j<m;j++){
      cin>>aa[i][j];
      skill[j]+=aa[i][j];
    }
  }
  for(int i=0;i<m;i++){
    if(skill[i]<x){
      cout<<"-1";
      return 0;
    }
  }
  for (int bit = 0; bit < (1<<n); ++bit) {
      vector<int> S;
      for (int i = 0; i < n; ++i) {
          if (bit & (1<<i)) {
              S.push_back(i);
          }
      }
      for (int i = 0; i < (int)S.size(); ++i) {
          for(int j=0;j<m;j++){
            ab[j]+=aa[S[i]][j];
          }
          ac+=cc[S[i]];
      }
      for(int j=0;j<m;j++){
          if(ab[j]<x)ans++;
      }
      if(ans==0){
        if(acmin>ac)acmin=ac;
      }
      for(int j=0;j<m;j++){
          ab[j]=0;
      }
      ac=0;
      ans=0;
  }
  cout<<acmin;
  return 0;
}

Measured memory_bytes: 3648
o = input()
e = input()
a = ''
O = len(o)
E = len(e)
if O == E:
    for i in range(O):
        a += o[i]
        a += e[i]
    print(a)
else:
    for i in range(O-1):
        a += o[i]
        a += e[i]
    a += o[O-1]
    print(a)

Measured memory_bytes: 3060
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        MyScanner in = new MyScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        A solver = new A();
        solver.solve(1, in, out);
        out.close();
    }

    static class A {
        public void solve(int testNumber, MyScanner in, PrintWriter out) {
            int r = in.nextInt();
            out.println(r * r);
        }

    }

    static class MyScanner {
        private BufferedReader in;
        private StringTokenizer st;

        public MyScanner(InputStream stream) {
            in = new BufferedReader(new InputStreamReader(stream));
        }

        public String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    String rl = in.readLine();
                    if (rl == null) {
                        return null;
                    }
                    st = new StringTokenizer(rl);
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return st.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}



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

using namespace std;

const int N = 100005;

int n;

int mat[10][10];

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

	for(int i = 1; i <= n; i++) {
		int tmp = i;
		while(tmp >= 10) tmp /= 10;
		mat[i % 10][tmp]++;
	}


	long long ans = 0;
	for(int i = 0; i < 10; i++) {
		for(int j = 0; j < 10; j++) {
			ans += 1LL * mat[i][j] * mat[j][i];
		}
	}

	printf("%lld\n", ans);
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
N = int(input())
e = [[] for _ in range(N + 1)]
for _ in range(N - 1):
  u, v = map(int, input().split())
  e[u].append(v)
  e[v].append(u)

a = [1]
b = []
s = [1]
vis = [0] * (N + 1)
table = [-1] * (N + 1)
table[1] = 1
vis[1] = 1
while len(s):
  x = s.pop()
  for y in e[x]:
    if vis[y]: continue
    vis[y] = 1
    table[y] = table[x] ^ 1
    if table[y]: a.append(y)
    else: b.append(y)
    s.append(y)
if len(a) > len(b): a, b = b, a
res = [0] * (N + 1)
if len(a) <= N // 3:
  ss = set([x for x in range(1, N + 1)])
  x = 3
  for y in a:
    res[y] = x
    ss.discard(x)
    x += 3
  ss = list(ss)
  for i in range(1, N + 1):
    if res[i]: continue
    res[i] = ss.pop()
  print(*res[1: ])
else:
  ss = set([x for x in range(1, N + 1)])
  x = 2
  for y in a:
    res[y] = x
    ss.discard(x)
    x += 3
    if x > N: break
  x = 3
  for y in a:
    if res[y]: continue
    res[y] = x
    ss.discard(x)
    x += 3
  ss = list(ss)
  for i in range(1, N + 1):
    if res[i]: continue
    res[i] = ss.pop()
  print(*res[1: ])


Measured memory_bytes: 170692
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**6)
INF = 10 ** 9 + 1  # sys.maxsize # float("inf")
MOD = 10 ** 9 + 7


def debug(*x):
    print(*x, file=sys.stderr)


def solve(S):
    table = [0] * 2020
    table[0] = 1
    # [1], [2] = 0
    for i in range(3, S + 1):
        # table[i] = sum(table[i - d] for d in range(3, 10)) % MOD
        table[i] = sum(table[i - d] for d in range(3, i + 1))
    # debug("table[:S + 1]", table[:S + 1])
    return table[S] % MOD


def main():
    # parse input
    S = int(input())
    print(solve(S))


# tests
T1 = """
7
"""
TEST_T1 = """
>>> as_input(T1)
>>> main()
3
"""

T2 = """
2
"""
TEST_T2 = """
>>> as_input(T2)
>>> main()
0
"""

T3 = """
1729
"""
TEST_T3 = """
>>> as_input(T3)
>>> main()
294867501
"""

T4 = """
4
"""
TEST_T4 = """
>>> as_input(T4)
>>> main()
1
"""

T4 = """
5
"""
TEST_T4 = """
>>> as_input(T4)
>>> main()
1
"""

T5 = """
6
"""
TEST_T5 = """
>>> as_input(T5)
>>> main()
2
"""


def _test():
    import doctest
    doctest.testmod()
    g = globals()
    for k in sorted(g):
        if k.startswith("TEST_"):
            doctest.run_docstring_examples(g[k], g, name=k)


def as_input(s):
    "use in test, use given string as input file"
    import io
    f = io.StringIO(s.strip())
    g = globals()
    g["input"] = lambda: bytes(f.readline(), "ascii")
    g["read"] = lambda: bytes(f.read(), "ascii")


input = sys.stdin.buffer.readline
read = sys.stdin.buffer.read

if sys.argv[-1] == "-t":
    print("testing")
    _test()
    sys.exit()

main()


Measured memory_bytes: 68300
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, from, to) for (int i = from; i < (to); ++i)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
using ll = long long;
using vin=vector<int>;
using vll=vector<ll>;
using P = pair<int, int>;
const int inf=1e9+7;
const ll INF=1e18;
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() {
 ll n;
 cin>>n;
  ll ans=0;
  vll yaku(0);
  for(ll i=1;i*i<=n;i++){
    if(n%i==0) yaku.push_back(i);
    if(i*i!=n)yaku.push_back(n/i);
  }
  sort(all(yaku));
  for(auto x:yaku){
    ll m;
    m=n/x-1;
    if(x<m)ans+=m;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 11648
#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 INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main()
{
  int n;
  cin >> n;
  vector<int> vec(n);
  rep(i, n) cin >> vec[i];
  rep(i, n) {
    if (vec[i] % 2 == 0) {
      if (vec[i] % 3 == 0 || vec[i] % 5 == 0) continue;

      cout << "DENIED" << endl; 
      return 0;
    }
  }
  cout << "APPROVED" << endl; 
  return 0;
}

Measured memory_bytes: 3628
def f(k):
    if 1 <= k <= 9:
        print(k)
    else:
        nxt = [[0,1], [0,1,2], [1,2,3], [2,3,4], [3,4,5], [4,5,6], [5,6,7], [6,7,8], [7,8,9], [8,9]]
        cum_npi = [0, 9, 35, 110, 327, 956, 2782, 8089, 23527, 68468, 199368]
        for length, begin in enumerate(cum_npi):
            if k < begin:
                found = cum_npi[length - 1]
                break
        begin = 10 ** (length - 1)
        # length, begin, found
        k -= found
        x = [[]] * (length + 1)
        x[1] = list(range(1, 10))
        # x

        terminate = False
        i = 1
        while True:
            #print(f"a) i = {i}  x = {x}")
            if len(x[i]): # len(x[i])
                digit = x[i][0]
                if i < length: # i, length
                    i += 1
                    x[i] = nxt[digit].copy()
                    #print(f"x) digit = {digit}  nxt[digit] = {nxt[digit]}  i = {i}  x[i] = {x[i]}")
                    #print(f"b) i = {i}  x = {x}")
                    if i == length: # i, length
                        while len(x[i]): # i, x[i]
                            k -= 1
                            #print(f"c) i = {i}  x = {x}, k = {k}")
                            if k == 0:
                                x.pop(0)
                                #print("answer =", x)
                                ans = "".join([str(j.pop(0)) for j in x])
                                print(ans)
                                terminate = True
                                break
                            else:
                                x[i].pop(0)
                            #print(f"d) i = {i}  x = {x}")
                        else:
                            #print(f"e) i = {i}  x = {x}")
                            while len(x[i]) == 0:
                                i -= 1
                                x[i].pop(0)
                        if terminate:
                            break

f(int(input()))


Measured memory_bytes: 9320
#include<bits/stdc++.h>
#define fi first
#define se second
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define rrep(i, n) for (int (i) = 1; (i) <= (n); (i++))
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define yn {puts("Yes");}else {puts("No");}
#define printd(x) printf("%.12f\n", ans);
template<class T> bool chmin(T& a, const T& b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> bool chmax(T& a, const T& b) {if (a < b) {a = b; return 1;} return 0;}
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main(void) {
	ll n, k;
	cin >> n >> k;

	ll tmp = n - n / k * k;

	if (abs(tmp - k) < tmp) cout << abs(tmp - k) << endl;
	else cout << tmp << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

#define N 100001

//SENTINEL is too big number
#define SENTINEL 999999998

//Merge function
void Merge(int a[],char c[],int left,int mid,int right){
  
  int n1,n2,i,j;
  int L[N],R[N];
  char Lc[N],Rc[N];
  n1=mid-left;
  n2=right-mid;

  for(i=0;i<n1;i++){
    L[i]=a[left+i];
    Lc[i]=c[left+i];
  }

  for(i=0;i<n2;i++){
    R[i]=a[mid+i];
    Rc[i]=c[mid+i];
  }

  //L[n1]=SENTINEL,R[n2]=SENTINEL
  L[n1]=SENTINEL;
  R[n2]=SENTINEL;

  i=0;
  j=0;
  for(int k=left;k<right;k++){

    if(L[i]<=R[j]){
      a[k]=L[i];
      c[k]=Lc[i];
      i++;
    }
    else{
      a[k]=R[j];
      c[k]=Rc[j];
      j++;
    }
  }

}

//MergeSort function
void MergeSort(int a[],char c[],int left,int right){
  int mid;
  if(left+1<right){
    mid=(left+right)/2;
    MergeSort(a,c,left,mid);
    MergeSort(a,c,mid,right);
    Merge(a,c,left,mid,right);
  }

}

//Partition function 
int Partition(int a[],char c[],int p,int r){
  int x,i,j,st;
  char stc;

  x=a[r];
  i=p-1;

  for(j=p;j<=r-1;j++){
    if(a[j]<=x){
      i++;

      //exchange a[i] and a[j]
      st=a[i];
      a[i]=a[j];
      a[j]=st;

      stc=c[i];
      c[i]=c[j];
      c[j]=stc;

    }
  }

  //exchange a[i] and a[j]
    st=a[i+1];
    a[i+1]=a[r];
    a[r]=st;

    stc=c[i+1];
    c[i+1]=c[r];
    c[r]=stc;

    return i+1;

}


//qurick sort function
void QuickSort(int a[],char c[],int p,int r){
  int q;
  if(p<r){
    q=Partition(a,c,p,r);
    QuickSort(a,c,p,q-1);
    QuickSort(a,c,q+1,r);
  }
}

int main(){
 
  int n,i,a1[N],a2[N];
  char c1[N],c2[N];
  //flag
  bool flag=true;
  //load number
  cin >>n;

  //load data and copy
  for(i=0;i<n;i++){
    cin >>c1[i]>>a1[i];
    a2[i]=a1[i];
    c2[i]=c1[i];
  }

  //execute
  QuickSort(a1,c1,0,n-1);
  MergeSort(a2,c2,0,n);

  //decide stable or not stable

  for(i=0;i<n;i++){
    if(c1[i]!=c2[i]){
      cout <<"Not stable"<<endl;
      flag=false;
      break;
    }
  }

  if(flag==true) cout <<"Stable"<<endl;

  //print
  for(i=0;i<n;i++){
    cout <<c1[i]<<" "<<a1[i]<<endl;;
  }

  return 0;
}

Measured memory_bytes: 2348
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
typedef long long ll;
int main() {
  int n,cnt=0,ans=0;
  string s,t;
  cin>>n>>s;
  rep(i,n){
    if(s[i]=='R'){
      cnt++;
      t+='R';
    }
  }
  rep(i,n-cnt)t+='W';
  rep(i,n){
    if(s[i]!=t[i])ans++;
  }
  cout<<(ans+1)/2;
}

Measured memory_bytes: 3848
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define MOD 1000000007
#define INF (1<<30)
#define LINF (1LL<<60)
#define endl "\n"
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcount(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
typedef unsigned long long int ull;
typedef long long lint;
 
int main(void){
    int N;
    cin >> N;
    int A[N];
    rep(i,N) cin >> A[i];
    sort(A,A+N,greater<int>());
    int ans=0;
    rep(i,N){
        if(i%2==0) ans+=A[i];
        else ans-=A[i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int H,W,D;
  cin>>H>>W>>D;
  int a[H+1][W+1];
  int x[H*W+1],y[H*W+1];
  for(int i=1; i<=H; i++){
    for(int j=1; j<=W; j++){
      cin>>a[i][j];
      x[a[i][j]]=i,y[a[i][j]]=j;
    }
  }
  int S[H*W+1];
  for(int i=1; i<=H*W-D; i++){
      S[i+D]=S[i]+(abs(x[i+D]-x[i])+abs(y[i+D]-y[i]));
  }
  int Q;
  cin>>Q;
  for(int i=0; i<Q; i++){
    int a,b;
    cin>>a>>b;
    cout<<S[b]-S[a]<<endl;
  }
} 

Measured memory_bytes: 2560
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
ll const INF = 1LL << 60;

int main() {
  string S, T;
  cin >> S >> T;
  ll ans = 0;
  for (int i = 0; i < S.size(); i++) {
    if (S[i] == T[i]) ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3540
#include <iostream>
#include <map>
#include <string>

int main() {
    int N;
    std::cin >> N;

    std::map<std::string, int> map_blue;
    std::string s;
    for (int i = 0; i < N; ++i) {
        std::cin >> s;
        ++map_blue[s];
    }

    int M;
    std::cin >> M;

    std::map<std::string, int> map_red;
    std::string t;
    for (int i = 0; i < M; ++i) {
        std::cin >> t;
        ++map_red[t];
    }

    int ret = 0;
    for (const auto& iPair : map_blue) {
        int tmp = iPair.second;
        const auto it = map_red.find(iPair.first);
        if (it != map_red.cend()) {
            tmp -= it->second;
        }

        ret = std::max(ret, tmp);
    }

    std::cout << ret << std::endl;
}


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

// #define int long long
#define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i)
#define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i)
#define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--)
#define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i)
#define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) long long(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

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 ll INF = 1e9+10;
const ll MOD = 1e9+7;
const ll LINF = 1e18;

const ll maxn_eratosthenes = 1000005;
bool _is_prime[maxn_eratosthenes];
vector<ll> P;

void eratosthenes(const ll N)
{
  P.clear();
  for (ll i = 0; i <= N; i++) {
    _is_prime[i] = true;
  }
  _is_prime[0]=_is_prime[1]=false;
  for (ll i = 2; i <= N; i++) {
    if (_is_prime[i]) {
      for (ll j = 2 * i; j <= N; j += i) {
        _is_prime[j] = false;
      }
      P.emplace_back(i);
    }
  }
}

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  
  ll x; cin>>x;
  eratosthenes(1000000);
  for(auto e: P){
    if(e>=x){
      cout<<e<<endl;
      return 0;
    }
  }
  
}

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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define deg_to_rad(deg) (((deg) / 360) * 2 * M_PI)
#define rad_to_deg(rad) (((rad) / 2 / M_PI) * 360)

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

typedef long long ll;

void solve(long long N, long long L) {
  int tmp = 0;
  long long apple = INF;
  int tot = 0;
  rep(i, N) {
    tot += L + i;
    if (apple > abs(L + i)) {
      apple = abs(L + i);
      tmp = L + i;
    }
  }
  cout << tot - tmp << endl;
}

int main() {
  long long N;
  scanf("%lld", &N);
  long long L;
  scanf("%lld", &L);
  solve(N, L);
  return 0;
}


Measured memory_bytes: 256
str = input()
q = int(input())

for i in range(q):
    com = input().split()
    a = int(com[1])
    b = int(com[2])
    if com[0] == 'print':
        print(str[a:b+1])
    elif com[0] == 'reverse':
        str = str[0:a] + str[a:b+1][::-1] + str[b+1:]
    elif com[0] == 'replace':
        str = str[0:a] + com[3] + str[b+1:]

Measured memory_bytes: 7700
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

bool ok(int i) {
  if(i/100==(i%100)/10 && i/100==i%10) return true;
  else return false;
}

int main() {
  int N;
  cin>>N;
  for(int i=N;i<=999;++i) {
    if(ok(i)) {
      cout<<i<<endl;
      return 0;
    }
  }
  return 0;
}



Measured memory_bytes: 3568
{-# LANGUAGE BangPatterns #-}
import Control.Arrow (second)
import Control.Monad
import Control.Monad.Fix
import Data.Foldable (foldl')
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM
import qualified Data.ByteString.Char8 as B
import Data.ByteString.Internal (accursedUnutterablePerformIO)
import Debug.Trace

uread :: VUM.Unbox a => Int -> VUM.IOVector a -> a
uread !i !v = accursedUnutterablePerformIO $ VUM.unsafeRead v i

uwrite :: VUM.Unbox a => Int -> a -> VUM.IOVector a -> VUM.IOVector a
uwrite !i !a !v =
  accursedUnutterablePerformIO $ VUM.unsafeWrite v i a >> return v

uswap :: VUM.Unbox a => Int -> Int -> VUM.IOVector a -> VUM.IOVector a
uswap !i !j !v =
  accursedUnutterablePerformIO $ VUM.unsafeSwap v i j >> return v

ufreeze :: VUM.Unbox a => VUM.IOVector a -> VU.Vector a
ufreeze !v = accursedUnutterablePerformIO $ VU.unsafeFreeze v

uthaw :: VUM.Unbox a => VU.Vector a -> VUM.IOVector a
uthaw !v = accursedUnutterablePerformIO $ VU.unsafeThaw v

newtype UnionFind = UnionFind (VUM.IOVector Int, VUM.IOVector Int)

new :: Int -> UnionFind
new !n = UnionFind
  ( uthaw $! VU.fromList [0 .. n - 1]
  , accursedUnutterablePerformIO $! VUM.replicate n 1
  )

findUF :: UnionFind -> Int -> Int
findUF (UnionFind (!elems, !_)) k = fix
  ( \f (elems, k, path) -> case uread k elems of
    n | n == k -> foldl' (\(!acc) !p -> uwrite p n acc) elems path `seq` n
    n          -> f (elems, n, n : path)
  )
  (elems, k, [k])

sizeUF :: UnionFind -> Int -> Int
sizeUF uf@(UnionFind (!_, !sizes)) !i =
  let j = findUF uf i in j `seq` uread j sizes

unionUF :: UnionFind -> Int -> Int -> UnionFind
unionUF uf@(UnionFind (!elem, !sizes)) !i !j =
  let pi = findUF uf i
      pj = findUF uf j
      si = uread pi sizes
      sj = uread pj sizes
  in  if pi == pj
        then uf
        else
          let (t1, t2) = if si < sj then (pi, pj) else (pj, pi)
          in  UnionFind (uwrite t1 t2 elem, uwrite t2 (si + sj) sizes)

solve :: Int -> Int -> VU.Vector (Int, Int) -> VU.Vector Int
solve n m !abs = VU.init $ ufreeze $ (\(_, _, _, acc) -> acc) $ VU.foldr'
  go
  ( new n
  , m - 1
  , nC2
  , uwrite m nC2 $ accursedUnutterablePerformIO $ VUM.unsafeNew (m + 1)
  )
  abs
 where
  go (!a, !b) (!uf, !k, !prev, !acc) =
    let ga  = findUF uf a
        gb  = findUF uf b
        n1  = sizeUF uf a
        n2  = sizeUF uf b
        res = prev - (if ga == gb then 0 else n1 * n2)
    in  (unionUF uf a b, k - 1, res, uwrite k prev acc)

  nC2 = n * (n - 1) `div` 2

main = do
  let readInt = fmap (second B.tail) . B.readInt

  (n, m) <-
    (\vec -> (vec VU.! 0, vec VU.! 1)) . VU.unfoldrN 2 readInt <$> B.getLine
  abs <- VU.replicateM
    m
    (   (\vec -> (vec VU.! 0 - 1, vec VU.! 1 - 1))
    .   VU.unfoldrN 2 readInt
    <$> B.getLine
    )

  VU.mapM_ print $ solve n m abs


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

const int N = 1e5+5;

int in[N];
void solve() {
   int n;
   scanf("%d",&n);
   for(int i=0;i<n;++i) {
      scanf("%d",&in[i]);
   }
   sort(in,in+n);
   if(in[n-1]- in[0] >1) {
      printf("No\n");
      return;
   }
   if(in[n-1]== in[0]) {
      int x = in[0];
      if(x+1==n || n/x>1) {
         printf("Yes\n");
      } else {
         printf("No\n");
      }
   } else {
      int cc = 0;
      for(int i=0;i<n;++i) {
         if(in[i]==in[0]) {
            ++cc;
         }
      }
      int k = n - (cc);
      if(k==1) {
         printf("No\n");
         return;
      }
      int t = k/2;
      if(cc >in[0]) {
         printf("No\n");
         return;
      }
      if(cc<=in[0] && in[n-1] <= cc + k/2){
         printf("Yes\n");
         return;
      }
      printf("No\n");
   }
}
int main() {
   //freopen("input.txt","r",stdin);
   solve();
}

Measured memory_bytes: 640
N = int(input())
a = list(map(int, input().split()))
x = a[0]
y = sum(a)-a[0]
res = abs(x-y)
for i in range(1,N-1):
    x += a[i]
    y -= a[i]
    if abs(x-y) < res:
        res = abs(x-y)
print(res)

Measured memory_bytes: 76752
// Try AtCoder
// author: Leonardone @ NEETSDKASU

fn main() {
    let mut stdin = String::new();
    std::io::Read::read_to_string(&mut std::io::stdin(), &mut stdin).unwrap();
    let mut stdin = stdin.split_whitespace();
    let mut get = || stdin.next().unwrap();
    macro_rules! get { () => (get().parse().unwrap()) }
    
    let n = get!();
    let c: usize = get!();
    let mut ss = vec![vec![]; 300_000];
    let mut ts = vec![vec![]; 300_000];
    for _ in 0..n {
        let si: usize = get!();
        let ti: usize = get!();
        let ci: usize = get!();
        ss[si*2-1].push(ci);
        ts[ti*2].push(ci);
    }
    let mut ans = 0;
    let mut cur = vec![0_i32; c+1];
    for i in 0..ss.len() {
        for &ci in &ss[i] {
            cur[ci] += 1;
        }
        let mut sum = 0;
        for &v in &cur {
            if v > 0 {
                sum += 1;
            }
        }
        ans = std::cmp::max(ans, sum);
        for &ti in &ts[i] {
            cur[ti] -= 1;
        }
    }
    println!("{}", ans);
}

Measured memory_bytes: 28924