akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<map>
#include<vector>
#include<algorithm>
#include<cmath>
#include<climits>
#include<ctime>
#include<cstring>
#include<numeric>

#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define dump(a) (cerr << #a << "=" << (a) << endl)
#define DUMP(list) cout << "{ "; for(auto nth : list){ cout << nth << " "; } cout << "}" << endl;

using namespace std;

int main(){
  int n, r;
  int a[51];
  int p, c;
  while(cin >> n >> r && n > 0){
    rep(i, n){
      a[i] = n-i;
    }

    rep(i, r){
      cin >> p >> c;
      rotate(a, a+p-1, a+p-1+c);
    }

    cout << a[0] << endl;
  }



}


Measured memory_bytes: 3088
def divisors(n):
  ret=[]
  for i in range(2,int(n**0.5)+1):
    if n%i==0:
      ret.append(i)
      if n//i!=i:
        ret.append(n//i)
  return ret

n=int(input())
if n==2:
  print(1)
else:
  divs1=divisors(n)
  divs2=divisors(n-1)
  cand=divs2
  for val in divs1:
    tmp=n
    while tmp%val==0:
      tmp=tmp//val
    if tmp%val==1:
      cand.append(val)
  if n not in cand:
    cand.append(n)
  if n-1 not in cand:
    cand.append(n-1)
  print(len(cand))

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

const int MAX = 210000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main()
{
    COMinit();
    long long n, k, res = 0LL;
    cin >> n >> k;
    for(long long i = 0; i <= min(n-1, k); ++i) {
        res += COM(n,i)*COM(n-1, n-i-1) % MOD;
        res %= MOD;
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 5248
#include <stdio.h>
#include <string.h>
int main(void)
{
    int  a,b[200000],i,j,n=0,m,x,y,z=0;
    char c[10100],s[10100];

    scanf("%d%d%d%d",&n,&x,&m,&y);//n,m hp  x,y at

    while(1){
        m=m-x;
        if(m<=0){printf("Yes"); break;}
        n=n-y;
        if(n<=0){printf("No"); break;}
    }
    
    printf("\n");
    return 0;
}

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

#define constdif 10000000007
int main()
{
	int n, d;
	cin >> n >> d;
	int ans = n / (2 * d + 1);
	if (n % (2 * d + 1) > 0)
		ans++;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<math.h>
#define rep(i,n) for (int i = 0; i < (n) ; ++i)
using namespace std;
using ll = long long ;
using P = pair<int, int> ;
#define PI 3.14159265358979323846264338327950
#define INF 100000000000000000

int main (){
    int n, W;
    cin >> n >> W ;
    vector<int> v (n);
    vector<int> w (n) ;
    rep(i, n){
        cin >> v[i] >> w[i] ;
    } 
    vector<vector<int>> dp (n + 1, vector<int> (W + 1) ) ;
    rep(i, n ){
        rep(j, W + 1){
            if(j < w[i]){
                dp[i + 1][j] = dp[i][j] ;
            }
            else {
            dp[i + 1][j] = max(dp[i][j], dp[i + 1][j - w[i]] + v[i]) ;
        }}
    }
    cout << dp[n][W] << endl ;
}


Measured memory_bytes: 6808
# 問題文、rとlは固定かと思ったけど毎回指定するってのがサンプルから分かった
# 操作逆にしてぜんぶ0にするまでを数える
# NもHも小さいので「山になっている部分を減らす」を毎回やっても大丈夫だと思う
# しゃくとり的にやったけどちょっと雑
n = int(input())
h = list(map(int, input().split()))
ans = 0
s = sum(h)
while s > 0:
    left = 0
    while left < n and h[left] == 0:
        left += 1
    h[left] -= 1
    s -= 1
    right = left + 1
    while right < n and h[right] != 0:
        h[right] -= 1
        s -= 1
        right += 1
    ans += 1
print(ans)

Measured memory_bytes: 9200
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

#define F first
#define S second
#define pb push_back
#define eb emplace_back
#define PI 3.14159265359
#define sz(c) (int)c.size()
#define len(c) (int)c.length()
#define hcf(a, b) __gcd(a, b)
#define all(c) c.begin(), c.end()
#define vint vector<int>
#define vll vector<ll>
#define vpint vector<pair<int, int>>
#define vpll vector<pair<ll, ll>>
#define fr(it, a, b) \
    for (int it = (a); it < (b); it++)
#define tr(con, it) \
    for (auto it = con.begin(); it != con.end(); it++)
#define present(con, ele) (con.find(ele) != con.end())
#define cpresent(con, ele) (find(all(con), ele) != con.end())
#define maximum(a, b, c) (a > b ? (a > c ? a : c) : (b > c ? b : c))
#define minimum(a, b, c) (a < b ? (a < c ? a : c) : (b < c ? b : c))
typedef long long ll;
typedef long double lf;
typedef pair<int, int> pi;
typedef unsigned long long lu;
const ll mod = 1e9 + 7;
int32_t main()
{
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int a;
    cin >> a;
    cout << a + a * a + a * a * a << "\n";
    return 0;
}

Measured memory_bytes: 3652
function main()
	n = parse(readline())
	m = n
	s = 0
	i = 1
	while n >= 10^(i-1)
		s += (m%10^i)/(10^(i-1))
		m -= m%10^i
		i += 1
	end
	if n%s == 0
		print("Yes")
	else
		print("No")
	end
end
 
main()

Measured memory_bytes: 167916
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
const ll M = 1e18;
int si[] = {-1, 0, 1, 0};
int sj[] = {0, -1, 0, 1};

int main(){
  string s;
  cin >> s;

  if(s =="hi") {
    cout << "Yes" << endl; return 0;
  }

  if(s =="hihi") {
    cout << "Yes" << endl; return 0;
  }

  if(s =="hihihi") {
    cout << "Yes" << endl; return 0;
  }
  
  if(s =="hihihihi") {
    cout << "Yes" << endl; return 0;
  }

  if(s =="hihihihihi") {
    cout << "Yes" << endl; return 0;
  }

  cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 3520
#include<bits/stdc++.h>
using namespace std;
int n, a[200005], g, vis[200005], f, b[200005];
long long k;
int main(){
	scanf("%d%lld", &n, &k);
	for(int i=1; i<=n; i++){
		scanf("%d", &a[i]);
	}
	for(int i=1; ; g++){
		if(vis[i]){
			g--;
			f=i;
			break;
		}
		b[g]=i;
		vis[i]=g;
		i=a[i];
	}
	if(k<vis[f]){
		cout<< b[k];
		return 0;
	}
	k=k-vis[f]+1;
	k%=g-vis[f]+1;
	if(k) cout<< b[vis[f]+k-1];
	else cout<< b[g];
	return 0;
}

Measured memory_bytes: 6080
N, M = map( int, input().split())
Q = []
for i in range(M):
    a,b = map(int,input().split())
    Q.append([a,b])
Q = sorted(Q)
ans = 1
LQ = len(Q)
stan = Q[0][1]
while LQ != 0:
    k = 1
    if Q[0][0] < stan:
        stan = min(stan,Q.pop(0)[1])
        LQ -= 1
    else:
        ans += 1
        if LQ == 0:
            break
        else:
            stan = Q[0][1]
print(ans)

Measured memory_bytes: 21196
data = {
        'S': [int(x) for x in range(1,14)],
        'H': [int(x) for x in range(1,14)],
        'C': [int(x) for x in range(1,14)],
        'D': [int(x) for x in range(1,14)],
        }

count = int(input())

for c in range(count):
    (s, r) = input().split()
    r = int(r)
    del data[s][data[s].index(r)]


for i in ('S', 'H', 'C', 'D'):
    for v in data[i]:
        print(i, v)

Measured memory_bytes: 6724
import numpy as np 

N,M = map(int,input().split())
AB = []
for i in range(N):
    a,b = map(int,input().split())
    AB.append([a,b])

need = M
cost = 0

AB.sort()

for i in range(N):
    if need - AB[i][1] >= 0:
        need -= AB[i][1]
        cost += AB[i][0]*AB[i][1]
    else:
        cost += AB[i][0]*need 
        break    

print(cost)

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

using namespace std;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	string s, c;
	int n = 0;
	cin >> s >> c;
	for(int i = 0; i < 3; i++){
		if(s[i] == c[i]){
			n++;
		}
	}
	cout << n;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <cstring>
#include <functional>

using namespace std;

#define REP(i,a,b) for((i)=(a);(i)<(int)(b);(i)++)
#define rep(i,n) REP(i,0,n)
#define foreach(itr,c) for(typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
template<class T> inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}

typedef long long ll;

int main(){
  int i,j,k;
  ll n,tmp;

  while(1){
    cin >> n; if(n == 0) break;

    ll acnt = 0;
    REP(i,1,n+1){
      tmp = i;
      while(tmp % 2 == 0 && tmp){ tmp /= 2; acnt++;}
    }

    ll bcnt = 0;
    REP(i,1,n+1){
      tmp = i;
      while(tmp % 5 == 0 && tmp){ tmp /= 5; bcnt++;}
    }

    if(acnt >= bcnt) cout << bcnt << endl;
    else cout << "0" << endl;
  }

  return 0;
}

Measured memory_bytes: 0
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define SORT(a) sort((a).begin(), (a).end())
#define RSORT(a) sort((a).rbegin(), (a).rend())
#define REP(i, n) for (int i = 0; i < n; i++)
#define RREP(i, n) for (int i = n; 0 <= i; i--)
#define FOR(i, start, end) for (int i = start; i < end; i++)
#define FORSTEP(i, start, end, step) for (int i = start; i < end; i += step)
#define ALL(a) a.begin(), a.end()
typedef long long ll;
const int INF32 = 2147483647;
const ll INF64  = 9223372036854775807;
using namespace std;

// パティとバーガーの総数
ll p[50], a[50];

ll solve(int n, ll x) {
    if (n == 0 && x <= 0)
        return 0;
    else if (n == 0 && x == 1)
        return 1;
    else if (x <= 1 + a[n - 1])
        return solve(n - 1, x - 1);
    else if (x == 2 + a[n - 1])
        return p[n - 1] + 1;
    else if (x <= 2 + 2 * a[n - 1])
        return p[n - 1] + 1 + solve(n - 1, x - 2 - a[n - 1]);
    else
        return 2 * p[n - 1] + 1;
}

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

    int N;
    ll X;
    cin >> N >> X;

    p[0] = 1;
    a[0] = 1;

    FOR(i, 1, N) {
        p[i] = 2 * p[i - 1] + 1;
        a[i] = 2 * a[i - 1] + 3;
    }

    ll ans = solve(N, X);

    cout << ans << endl;

    return 0;
}

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

using ll=long long;
using namespace std;

#define rep_i(i, n) for (int i = 0; i < (n); ++i)
#define rep_ll(i, n) for (long long i = 0; i < (n); ++i)
#define r_rep_i(i, start, end) for (int i = (start); i < (end); ++i)
#define r_rep_ll(i, start, end) for (long long i = (start); i < (end); ++i)
#define debug_vi(v) copy((v).begin(), (v).end(), ostream_iterator<int>(cout, " "));
#define debug_vll(v) copy((v).begin(), (v).end(), ostream_iterator<long long>(cout, " "));
#define debug_vd(v) copy((v).begin(), (v).end(), ostream_iterator<double>(cout, " "));
#define sort_v(v) sort((v).begin(), (v).end()); //昇順
#define d_sort_vi(v) sort((v).begin(), (v).end(), greater<int>()); //降
#define d_sort_vll(v) sort((v).begin(), (v).end(), greater<long long>()); //降
#define d_sort_vd(v) sort((v).begin(), (v).end(), greater<double>()); //昇順
#define say(t) cout << (t) << endl;
#define sum_vi(v) accumulate((v).begin(), (v).end(), 0);
#define sum_vll(v)accumulate((v).begin(), (v).end(), 0LL);

ll gcd(ll a, ll b) { return b?gcd(b, a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a, b)*b;}

const int IINF=(1<<30);
const ll LLINF = 1LL<<60;

char BigAlphaToSmall(char a){
    if (a >= 65 && a <= 90){
        return a + 32;
    }
    return a;
}

char SmallAlphaToBig(char a){
    if (a >= 97 && a <= 122){
        return a - 32;
    }
    return a;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    int n; cin >> n;
    vector<int> hoge(n);
    rep_i(i, n) cin >> hoge[i];
    int q; cin >> q;
    int b, e, k;
    rep_i(i, q){
        cin >> b >> e >> k;
        cout << count(&hoge[b], &hoge[e], k) << endl;
    }
}


Measured memory_bytes: 3228
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define range(a) a.begin(),a.end()

int main(){
	int N,L;cin>>N>>L;
	int sum=N*L+N*(N-1)/2;
	if(L>=0){
		cout<<sum-L<<endl;
	}else if(L+N-1>=0){
		cout<<sum<<endl;
	}else{
		cout<<sum-(L+N-1)<<endl;
	}
}


Measured memory_bytes: 256
#include <stdio.h>
int sum;
void set(int a,int b,int c,int n){
    a*=10;
    if(c==n)
        return;
    sum+=a/b;
    set(a%b,b,c+1,n);
}

int main(void){
    int a,b,n;
    for(;sum=0,scanf("%d %d %d",&a,&b,&n)!=EOF;){
        a>=b?set(a%b,b,0,n):set(a,b,0,n);
        printf("%d\n",sum);
    }
    return 0;
}

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

int main() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  int ans = 0;
  for (int i = 1; i < n; ++i) {
    string s1 = s.substr(0, i);
    string s2 = s.substr(i, s.size() - i);
    set<char> set_s1, set_s2;
    vector<char> result;
    for (char c : s1) set_s1.insert(c);
    for (char c : s2) set_s2.insert(c);
    set_intersection(set_s1.begin(), set_s1.end(), set_s2.begin(), set_s2.end(), back_inserter(result));
    ans = max(ans, static_cast<int>(result.size()));
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <math.h>
using namespace std;
void A(void);
void B(void);
void C(void);
void D(void);

int main(void){
    D();
}

void D(void){
    long long int a,b,n,x,f;
    cin>>a>>b>>n;
    if(b<=n)x=b-1;
    else x=n;
    f=floor(a*x/b)-a*(x/b);
    cout<<f<<endl;
}

Measured memory_bytes: 3596
n, k = map(int,input().split())
d = list(map(int,input().split()))

for i in range(n,10*n):
    ans = str(i)
    for j in range(len(ans)):
        if int(ans[j]) in d:
            break

        if j == len(ans) - 1:
            print(i)
            exit()

Measured memory_bytes: 40924
using System;
using System.Collections.Generic;

namespace _120_ABC
{
    class Program02
    {
        static void Main(string[] args)
        {
            string[] Input = Console.ReadLine().Split(' ');
            int A = int.Parse(Input[0]);
            int B = int.Parse(Input[1]);
            int K = int.Parse(Input[2]);

            var AnswerList = new List<int>();

            for(int i = 1; i <= 100; i++)
            {
                if(A % i == 0 && B % i == 0)
                {
                    AnswerList.Add(i);
                }
            }

            Console.WriteLine(AnswerList[AnswerList.Count-K]);

        }
    }
}


Measured memory_bytes: 13140
use proconio::input;

fn main() {
	input! {
		q: usize,
		queries: [(usize, usize); q],
	}

	let mut counts = vec![0; 100001];
	let mut prime_set = vec![false; 100001];
	prime_set[2] = true;
	let mut primes: Vec<usize> = vec![2];
	for i in (3..100000).step_by(2) {
		if primes.iter().all(|&q| i % q != 0 ) {
			primes.push(i);
			prime_set[i] = true;
			if prime_set[(i+1)/2] {
				counts[i] = 1;
			}
		}
	}

	for i in 0..100000 {
		counts[i+1] += counts[i];
	}

	for (l, r) in queries {
		println!("{}", counts[r] - counts[l-1]);
	}
}

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

using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  n %= 1000;
  if (n == 0) {
    cout << 0 << '\n';
    exit(0);
  }
  cout << 1000 - n << '\n';
}


Measured memory_bytes: 3664
#include <stdio.h>

int n, A[20];

int solve(int i, int b){
  if(b == 0) return 1;
  if(i >= n) return 0;
  int res = solve(i + 1, b)||solve(i + 1, b - A[i]);
  return res;
}


int main(){
  int q, i, B, j;

  scanf("%d", &n);
  for(i = 0; i < n; i++) scanf("%d", &A[i]);
  scanf("%d", &q);
  for(i = 0; i < q; i++){
    scanf("%d", &B);
    j = solve(0, B);
    if(j == 1) printf("yes\n");
    else printf("no\n");
  }
  
  return 0;
}


Measured memory_bytes: 2108
# -*- coding: utf-8 -*-

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

def bisearch_min(mn, mx, func):
    """ 条件を満たす最小値を見つける二分探索 """

    ok = mx
    ng = mn
    while ng+1 < ok:
        mid = (ok+ng) // 2
        if func(mid):
            # 下を探しに行く
            ok = mid
        else:
            # 上を探しに行く
            ng = mid
    return ok

N = INT()
A = LIST()

def check1(m):
    sm = m
    for a in A:
        sm = (sm // a) * a
    return sm >= 2

def check2(m):
    sm = m
    for a in A:
        sm = (sm // a) * a
    return sm > 2

l = bisearch_min(0, 10**18, check1)
r = bisearch_min(0, 10**18, check2) - 1

if l > r:
    print(-1)
else:
    print(l, r)


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

int main() {
  int N;
  cin >> N;
  vector<int> a(N);
  for (int i = 0; i<N; i++){
    cin >> a.at(i);
  }
  int ans = 0;
  for (int i = 0; i < N; i +=2){
    if (a.at(i) % 2 == 1)
      ans++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 3624
// Last Change: 04/27/2019 21:07:55.
#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using ll = long long;

namespace NS {
void LoopUntilZeroInpput() {
  int hogegegege = 0;
  while (cin >> hogegegege && hogegegege != 0) {
  }
}
} // namespace NS

int main() {
  ll N;
  cin >> N;
  vector<ll> V(N);
  for (auto &&e : V) {
    cin >> e;
  }

  ll ans = 0;
  for (auto &&e : V) {
    ll ipt;
    cin >> ipt;
    ans += max(0LL, e - ipt);
  }

  cout << ans << endl;
  //NS::LoopUntilZeroInpput();
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define X first
#define Y second
using namespace std;

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

const ll Q = (ll)(1e9) + 7;
const int MAXN = 2002;


ll c[MAXN][MAXN];

int main() {
	ios_base::sync_with_stdio(0);

	int N, K;
	cin >> N >> K;

	c[0][0] = 1; 
	for(int n = 1; n <= N+1; n++) {
		c[n][0] = 1;
		for(int k = 1; k <= K+1; k++) {
			c[n][k] = (c[n-1][k] + c[n-1][k-1]) % Q;
		}
	}

	for(int k = 1; k <= K; k++) {
		cout << (c[N-K+1][k] * c[K-1][k-1]) % Q << '\n';
	}

	return 0;
}

Measured memory_bytes: 31616
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

class Main{

	static class FastReader {

		BufferedReader br;
		StringTokenizer st;

		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

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

		long nextLong() {
			return Long.parseLong(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}
	}

	public static void main(String[] args) throws IOException {
		FastReader sc = new FastReader();
		int a=sc.nextInt(),b=sc.nextInt();
		int cnt=0;
		for(int i=a;i<=b;i++){
			String aa=i+"";
			int ind=aa.length()-1;
			boolean f=true;
			for(int j=0;j<aa.length()/2;j++){
				if(aa.charAt(j) !=aa.charAt(ind)){
					f=false;
					break;
				}
				ind--;
			}
			if(f)cnt++;
		}
		System.out.println(cnt);
	}
}

Measured memory_bytes: 32084
import java.util.Scanner;

public class Main {

    public static void main (String[] args) {
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        long m = sc.nextLong();
        long result;
        if (n * m == 1) {
            result = 1;
        } else if (n == 1 || m == 1) {
            result = n * m - 2;
        } else {
            result = (n - 2) * (m - 2);
        }
        System.out.println(result);
    }
    
}


Measured memory_bytes: 22100
#include <bits/stdc++.h>
using namespace std;
const int maxN = 1e5+5;
const int inf = 1001*1000*1000;
#define pb push_back
#define mp make_pair
vector<int> obj[maxN];
vector<int> bre;
int n,e,mark[maxN],fa[maxN],dp[maxN],hig[maxN],diba[maxN];
int k=0;
void dfs(int u)
{
	mark[u] =1;
	dp[u]=inf;
	for(int v:obj[u])
	{
		if(!mark[v])
		{
			if(!fa[u]&&!u){k++;}
			hig[v]=hig[u]+1;
			fa[v]=u;
			dfs(v);
			dp[u]=min(dp[u],dp[v]);
		}
		else if(v!=fa[u]&&hig[v]<hig[u])
		{
			dp[u]=min(dp[u],hig[v]);
		}
	}
	if(dp[u]>=hig[fa[u]]&&fa[u]&&!diba[fa[u]])
	{
		bre.push_back(fa[u]);
		diba[fa[u]]=1;
	}
}
int main()
{
	cin>>n>>e;
	int u,v;
	for(int i=0;i<e;i++)
	{
		cin>>u>>v;
		obj[u].pb(v);
		obj[v].pb(u);
	}
	dfs(0);
	sort(bre.begin(),bre.end());
	if(k>1)cout<<"0"<<endl;
	for(int i=0;i<bre.size();i++)
	{
		cout<<bre[i]<<endl;
	}
}



Measured memory_bytes: 6856
int main(){

  int n,i,j,k,key;

  //array length
  scanf("%d",&n);

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

  //insertion sort
  for(i=1;i<n;i++){

    //display result
    for(k=0;k<n;k++){
      if(k==n-1){
        printf("%d\n",A[k]);
        break;
      }
      printf("%d ",A[k]);
    }

    key = A[i];
    j = i - 1;
    while(j>=0 && A[j]>key){
      A[j+1] = A[j];
      j--;
    }
    A[j+1] = key;
  }

  //display last result
  for(k=0;k<n;k++){
    if(k==n-1){
      printf("%d\n",A[k]);
      break;
    }
    printf("%d ",A[k]);
  }

  return 0;
}

Measured memory_bytes: 600
def main():
    from itertools import accumulate

    n, k, *ab = map(int, open(0).read().split())
    c = list(zip(ab[::2], ab[1::2]))
    c.sort(key=lambda x: x[0])
    count = 0
    for i, j in c:
        count += j
        if k <= count:
            print(i)
            break


if __name__ == '__main__':
    main()


Measured memory_bytes: 31856
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define COUT(x) cout<<(x)<<endl
#define dump(x)  cout << #x << " = " << (x) << endl;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;
using M = map<int,int>;
using PQ = priority_queue<int>;
using PQG = priority_queue<int, vector<int>, greater<int>>;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

int main() {
  int k; cin >> k;
  int n; cin >> n;
  vector<int> a(n);
  REP(i,n) cin >> a[i];

  ll ans = LINF;
  REP(i,n) {
    ll pos = 0, neg = 0;
    int next = i-1;
    if (next < 0) next = n-1;
    if (a[i] < a[next]) {
      pos = a[next] - a[i];
    } else {
      pos = k - (a[i] - a[next]);
    }

    next = i+1;
    if (next >= (n-1)) next % (n-1);
    if (a[i] < a[next]) {
      neg = k - (a[next] - a[i]);
    } else {
      neg = a[i] - a[next];
    }
    ans = min(ans, min(neg, pos ));
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef pair<int, int> pii;
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define vv(type, c, m, n, i) vector<vector<type>> c(m, vector<type>(n, i))
#define mat(type, c, m, n) vector<vector<type>> c(m, vector<type>(n));for(auto& r:c)for(auto& i:r)cin>>i;
#define rep(i,a,n) for(int i=(a), i##_len=(n); i<i##_len; ++i)
#define rrep(i,a,n) for(int i=(a), i##_len=(n); i>i##_len; --i)
#define each(x,y) for(auto &(x):(y))
#define var(type, ...)type __VA_ARGS__;Scan(__VA_ARGS__);
template<typename T> void Scan(T& t) { cin >> t; }
template<typename First, typename...Rest>void Scan(First& first, Rest&...rest) { cin >> first; Scan(rest...); }
#define vec(type, c, n) vector<type> c(n);for(auto& i:c) cin>>i;
#define len(x) ((int)(x).size())
#define mp make_pair
#define eb emplace_back
#define em emplace
#define pb pop_back
#define fi first
#define se second
#define get(a, i) get<i>(a)
#define bit_count __builtin_popcount
#define mt make_tuple
inline string zero(int a,string s,char c='0'){return string(a-len(s),c)+s;}
inline string zero(int a,int t,char c='0'){return zero(a, to_string(t), c);}
inline string zero(int a,ll t,char c='0'){return zero(a, to_string(t), c);}
#define mini min_element
#define maxi max_element
#define sum accumulate
#define chmax(a,b) if(a<b)a=b
#define chmin(a,b) if(a>b)a=b
template <class T> inline void print(T t){cout << t << '\n';}
template <class H, class... T> inline void print(H h, T... t){cout << h << " ";print(t...);}
ll powMod(ll n, ll p, ll mod) {
	ll res = 1;
	while (p) {
		if (p & 1) (res *= n) %= mod;
		(n *= n) %= mod;
		p >>= 1;
	}
	return res;
}
const constexpr ll mod = 1000000007;
ll n,x,h[200001],ans=0,r=1;
int main() {
	cin>>n;
	for (ll i = 1; i < n + 1; ++i) {
		h[i]=(h[i-1]+powMod(i,mod-2, mod))%mod;
	}
	for (ll i = 1; i < n + 1; ++i) {
		cin>>x;
		(ans+=x*(h[i]+h[n-i+1]-1+mod))%=mod;
		(r*=i)%=mod;
	}
	print(ans * r % mod);
	return 0;
}


Measured memory_bytes: 1024
# https://atcoder.jp/contests/diverta2019/tasks/diverta2019_d
import itertools
from collections import Counter
from collections import defaultdict
import bisect

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

    ans = 0
    i = 1
    while i * i <= N:
        if N % i == 0:
            opo1 = i - 1
            if opo1 > 0 and N // opo1 == N % opo1:
                ans += opo1
            opo2 = N // i - 1
            if opo2 > 0 and N // opo2 == N % opo2:
                ans += opo2

        i += 1

    print(ans)


if __name__ == '__main__':
    main()


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

int main(){
  string s;
  cin >> s;
  for(int i=0;i<s.size();i++){
    if(s.at(i)==',')
      cout << " ";
    else
      cout << s.at(i);
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 3560
#include <iostream>
#include <cassert>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
using namespace std;
#define REP(i, j) for(int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
typedef long long int Int;
typedef complex<double> P;
typedef pair<int, P> PP;
typedef pair<Int, bool> PIB;
const double EPS = 1e-12;

struct L : public vector<P> {
  L(const P &a, const P &b) {
    push_back(a); push_back(b);
  }
};

double cross(const P& a, const P& b) { return imag(conj(a)*b); }
double dot(const P& a, const P& b) { return real(conj(a)*b); }
Int distance2(P &a, P &b){ return (a.real() - b.real()) * (a.real() - b.real()) * (a.imag() - b.imag()) * (a.imag() - b.imag()); }

int ccw(P a, P b, P c) {
  b -= a; c -= a;
  if (cross(b, c) > 0)   return +1;       // counter clockwise
  if (cross(b, c) < 0)   return -1;       // clockwise
  if (dot(b, c) < 0)     return +2;       // c--a--b on line
  if (norm(b) < norm(c)) return -2;       // a--b--c on line
  return 0;
}

bool intersectSS(const L &s, const L &t) {
  return ccw(s[0],s[1],t[0])*ccw(s[0],s[1],t[1]) <= 0 &&
    ccw(t[0],t[1],s[0])*ccw(t[0],t[1],s[1]) <= 0;
}

PP crosspointLL(const L &l, const L &m) {
  double A = cross(l[1] - l[0], m[1] - m[0]);
  double B = cross(l[1] - l[0], l[1] - m[0]);
  if (abs(A) < EPS && abs(B) < EPS) return PP(1, m[0]); // same line
  if (abs(A) < EPS) PP(0, P(0, 0));
  return PP(1, m[0] + B / A * (m[1] - m[0]));
}

P inputP(){
  int x, y; cin >>x >>y;
  return P(x, y);
}

int main() {
  int T; cin >>T;
  while(T--){
    P a = inputP(), b = inputP();
    int N; cin >>N;
    vector<PIB> ps;
    REP(i, N){
      P s = inputP(), t = inputP();
      int o, l; cin >>o >>l;
      L l1 = L(a, b), l2 = L(s, t);
      if(!intersectSS(l1, l2)) continue;
      PP r = crosspointLL(l1, l2);
      if(r.first == 0) continue;
      bool f = 0;
      if((o == 1 && l == 1) || (o == 0 && l == 0)) f = 1;
      ps.push_back(PIB(distance2(a, r.second), f));
    }
    SORT(ps);
    int ans = 0;
    FOR(i, 1, ps.size()) if(ps[i].second != ps[i - 1].second) ++ans;
    cout <<ans <<endl;
  }
  return 0;
}

Measured memory_bytes: 1224
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using static System.Console;

class Program
{
    static void Main(string[] args)
    {
        var NM = ReadLine().Split(' ').Select(s => long.Parse(s)).ToArray();
        var (N, M) = (NM[0], NM[1]);
        var AB = new (long a, long b)[N];
        for (int i = 0; i < N; i++)
        {
            var _AB = ReadLine().Split(' ').Select(s => long.Parse(s)).ToArray();
            AB[i] = (_AB[0], _AB[1]);
        }

        var sortedAB = AB.OrderBy(x => x.a).ToArray();
        var ans = 0L;

        foreach (var (a, b) in sortedAB)
        {
            if(M <= b)
            {
                ans += a * M;
                break;
            }
            else
            {
                ans += a * b;
                M -= b;
            }
        }

        WriteLine(ans);
    }
}


Measured memory_bytes: 52896
#include<iostream>
#include<algorithm>
#include<cmath>
#include<string>
#include<array>
#include<vector>
#include<functional>
#include<unordered_map>
#include<map>
#include<numeric>
#include<limits>
#include<utility>
#include<queue>
#include<random>
using namespace std;

int main(){
    int N;
    
cin >> N;
    
  
    cout << "ABC" << N << endl;
    
    return 0;

}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int main(void)
{
    long long ans = 0;
    int n;
    
    cin >> n;
    
    vector<int> a(n);
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    vector<int> b(n);
    for (int i = 0; i < n; i++)
    {
        cin >> b[i];
    }
    vector<int> c(n-1);
    for (int i = 0; i < n - 1; i++)
    {
        cin >> c[i];
    }

    for (int i = 0; i < n; i++)
    {
        ans += b[a[i] - 1];
        if (i != 0 && a[i - 1] == a[i] - 1) {
            ans += c[a[i-1] - 1];
        }
    }
    
    cout << ans << endl;
    return 0;
}


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


long long f(vector<long long> a){
	int idx = max_element(a.begin(),a.end()) - a.begin();
	if( a[idx] < a.size() ) return 0;
	a[idx] -= a.size();
	a[idx^1] += 1;
	return 1 + f(a);
}

int main(){
	long long N;
	cin >> N;
	vector<long long> a(50,49 + N / 50);
	for(int i = 0 ; i < N % 50 ; i++){
		sort(a.begin(),a.end());
		a[0] += 50;
		for(int j = 1 ; j < 50 ; j++)
			a[j] -= 1;
	}
	cout << 50 << endl;
	for(int i = 0 ; i < 50 ; i++) cout << a[i] << (i + 1 == 50 ? "\n" : " ");
	// 4 4 4 4 | 4
	// 5 5 5 0 | 3
	// 1 6 6 1 | 2
	// 2 2 7 2 | 1
	// 3 3 3 3 | 0
	// 3 3 3 3  


}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
const int nmax = 1e6 + 10;
const int INF = 0x3f3f3f3f;
typedef long long ll;
typedef double db;

int main() {
	vector<string> t;
	string s;
	int k;
	cin >> s >> k;
	for(int i=0; i<s.size(); i++){
		for(int j=1; j<=5; j++){
			t.push_back(s.substr(i, j));
		}
	}
	sort(t.begin(), t.end());
	unique(t.begin(), t.end());
	cout << t[k-1] << endl;
	return 0;
}

Measured memory_bytes: 1660
import java.util.*;

class Main{
	static Scanner s=new Scanner(System.in);
	public static void main(String[] $){
		int n=s.nextInt()+1;
		int[]a=new int[n];
		for(int i=1;i<n;++i)
			a[i]=s.nextInt();
		int sum=Arrays.stream(a).sum();
		int r=0;
		while(sum>0) {
			for(int i=n-1;i>0;--i) {
				if(a[i]>0) {
					if(a[i-1]<1)
						++r;
					--sum;
					--a[i];
				}
			}
		}
		System.out.println(r);
	}
}

Measured memory_bytes: 27988
#include "bits/stdc++.h"
using namespace std;
using     ll=long long;
using    vll=vector<   ll>;
using   vvll=vector<  vll>;
using  vvvll=vector< vvll>;
using vvvvll=vector<vvvll>;
constexpr ll INF = 1LL << 60;
struct Fast{ //cin,cout高速化のおまじない＋桁数指定
	Fast(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(std::numeric_limits<double>::max_digits10); }
} fast;
#define rep(i, S, E)  for (ll i = (S); i <= (E); i++)
#define dep(i, E, S)  for (ll i = (E); i >= (S); i--)
#define each(e, v) for (auto&& e : v)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
template<class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; }return false; }
template<class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; }return false; }
template<class T> inline T MaxE(vector<T>&v,ll S,ll E){ T m=v[S]; rep(i,S,E)chmax(m,v[i]); return m; }
template<class T> inline T MinE(vector<T>&v,ll S,ll E){ T m=v[S]; rep(i,S,E)chmin(m,v[i]); return m; }
template<class T> inline T MaxE(vector<T> &v) { return MaxE(v,0,(ll)v.size()-1); }
template<class T> inline T MinE(vector<T> &v) { return MinE(v,0,(ll)v.size()-1); }
template<class T> inline T Sum(vector<T> &v,ll S,ll E){ T s=T(); rep(i,S,E)s+=v[i]; return s; }
template<class T> inline T Sum(vector<T> &v) { return Sum(v,0,v.size()-1); }
template<class T> inline ll sz(T &v){ return (ll)v.size(); }
template<class T> inline T POW(T a, ll n){ T r=1; for (; n>0; n>>=1, a*=a){ if (n&1)r*=a; } return r; }
inline ll POW(int a, ll n){ return POW((ll)a, n); }
inline ll CEIL(ll a, ll b){ return (a+b-1)/b; }



void solve()
{
	string s;  cin >> s;
	ll n=sz(s);

	char seed;
	if (n%2==1){
		seed=s[n/2];
	}
	else{
		if (s[n/2]!=s[n/2-1]){
			cout << n/2 << '\n'; return;
		}
		seed=s[n/2];
	}

	ll m=(n-1)/2-1;
	rep(i,0,m){
		if (s[m-i]==seed and s[n-1-(m-i)]==seed){
			continue;
		}
		cout << n-1-(m-i) << '\n'; return;
	}
	cout << n << '\n';
}


int main(){
#if 1
	solve();
#else
	ll t;  cin >> t;
	rep(i, 0, t-1){
		solve();
	}
#endif
	return 0;
}


Measured memory_bytes: 3788
n,d = gets.chomp.split(' ').map(&:to_i)

x = []
y = []
count = 0


(0...n).each{|i|
x[i], y[i] = gets.chomp.split(' ').map(&:to_i)
if(Math.sqrt(x[i]**2 + y[i]**2) <= d)
count += 1
end
}

puts count


Measured memory_bytes: 17532
#include<bits/stdc++.h>
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize ("Ofast")
#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
/* Uncomment only if you are not using GNU compiler->
#include <map> #include <algorithm> #include <vector> #include <string.h> #include <math.h> #include <stdio.h> #include <stdlib.h> #include <chrono> #include <thread> #include <iomanip>
*/ 
using namespace std;

#define endl "\n"
#define rep(i,a,b) for(ll i=a; i<b; ++i)
#define re(i,a) for(ll i=0; i<a; ++i)
#define tr(i,v) for(auto &i: v)
#define mem(a,val) memset(a,val,sizeof(a))
#define all(c) c.begin(),c.end()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define in(v,n) vll v(n);re(i,n) cin>>v[i]
#define printVec(v,s) cout << s; tr(i, v) cout << i << " ";
#define sz(a) int((a).size())
#define dbgv(c, v) cout << c << " = " << v << endl;

typedef long long int ll;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef pair<ll, ll> pll;
typedef vector< pll > vpll;
typedef vector< ll > vll;
typedef complex<double> point;

const long long MOD = 1000000007;
const long long inf = 1e18;

void solve(){
	ll a, b,c,k;
    cin>>a>>b>>c>>k;
    ll ans = min(a, k);
    k -= (a + b);
    if(k > 0){
        ans -= k;
    }
    cout << ans;
}

int main()
{

    std::ios::sync_with_stdio(false);
    cin.tie(0);
    cin.exceptions(cin.failbit);

    	solve();

    return 0;
}


Measured memory_bytes: 3652
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_map>
#include<fstream>
#include<list>
#include<functional>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
typedef pair<double,ll> pdl;
#define F first
#define S second
const ll E=1e18+7;
const ll MOD=998244353; /*1000000007;*/







int main(){
    ll a,b;
    cin>>a>>b;
    vector<vector<ll>> A(100,vector<ll>(100,0));
    for(int i=0;i<100;i++){
        A[i][49]=1;
    }
    a--; b--;
    for(int i=0;i<100;i++){
        for(int t=0;t<100;t++){
            if(t==49 || t==50){continue;}
            if(t<49 && (i%2 || t%2)){
                A[i][t]=1;
            }
            if(t>50 && i%2==0 && t%2==1){
                A[i][t]=1;
            }
        }
    }
    for(int i=0;i<100;i++){
        for(int t=0;t<49;t++){
            if(a==0){
                A[i][t]=1;
            }
            else if(A[i][t]==0){a--;}
        }
    }
    for(int i=0;i<100;i++){
        for(int t=51;t<100;t++){
            if(b==0){
                A[i][t]=0;
            }
            else if(A[i][t]){b--;}
        }
    }
    cout<<100<<" "<<100<<endl;
    for(int i=0;i<100;i++){
        for(int t=0;t<100;t++){
            cout<<(A[i][t]?'#':'.');
        }
        cout<<endl;
    }
    
    
    
    return 0;
}


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

// Function Macros:
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define all(v) (v).begin(), (v).end()
#define setpre(n) cout << fixed << setprecision(n)

// Type / Class / Struct Definitions:
using namespace std;

using ll = long long;
using ull = unsigned long long;

// Constants:
const int INF = (1ll << 30) - 1;  // approx 1.07e9
const ll INFLL = 1ll << 60;       // approx 1.15e18
const int MOD = 1e9 + 7;          // 998244353
const long double EPS = 1.0e-14;
const int FACN = 5e5 + 10000;

// Global Variables:
ll fac[FACN], finv[FACN], inv[FACN];

// Prototype Declarations:
int gcd(int, int);
template <class T>
inline bool chmin(T&, T);
template <class T>
inline bool chmax(T&, T);
ll modAdd(ll, ll, ll);
ll modSub(ll, ll, ll);
ll modTms(ll, ll, ll);
ll modInv(ll, ll);
ll modDiv(ll, ll, ll);
ll modPow(ll, ll, ll);
void combInit(int);
ll comb(int, int, ll);
ll perm(int, int, ll);

// ================ Main Loop ================
int main() {
    int n, m;
    cin >> n >> m;
    combInit(MOD);
    ll ans = 0, mpk = 1;
    int sgn = -1;
    for(int k = 0; k <= n; k++) {
        sgn *= -1;
        ans += ((comb(n, k, MOD) * sgn * perm(m, k, MOD)) % MOD) * modPow(perm(m - k, n - k, MOD), 2, MOD) % MOD;
        ans %= MOD;
        if(ans < 0) ans += MOD;
    }
    cout << ans << endl;
    // cout << perm(5, 3, MOD) << endl;
    return 0;
}
// ===========================================

// Functions:
int gcd(int a, int b) {
    return b ? gcd(b, a % b) : a;
}

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

ll modAdd(ll a, ll b, ll m) {
    return (a + b) % m;
}

//引き算:a - b O(1)
ll modSub(ll a, ll b, ll m) {
    return (a > b) ? (a - b) % m : (a - b) % m + m;
}

//掛け算:a * b O(1)
ll modTms(ll a, ll b, ll m) {
    return a * b % m;
}

//逆関数
//Extended Euclid Algorithm O(log a)
ll modInv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while(b) {
        ll t = a / b;
        a -= t * b;
        swap(a, b);
        u -= t * v;
        swap(u, v);
    }
    u %= m;
    if(u < 0) u += m;
    return u;
}

//割り算:a/b O(log b)
ll modDiv(ll a, ll b, ll m) {
    return modTms(a, modInv(b, m), m);
}

//冪乗:a^n O(log n)
ll modPow(ll a, ll n, ll m) {
    ll res = 1;
    while(n > 0) {
        if(n & 1) res = res * a % m;
        a = a * a % m;
        n >>= 1;
    }
    return res;
}

void combInit(int m) {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i = 2; i < FACN; i++) {
        fac[i] = fac[i - 1] * i % m;
        inv[i] = m - inv[m % i] * (m / i) % m;
        finv[i] = finv[i - 1] * inv[i] % m;
    }
    return;
}

//組み合わせ:nCk O(1)
ll comb(int n, int k, ll m) {
    if(n < k) return 0;
    if(n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % m) % m;
}

ll perm(int n, int k, ll m) {
    if(n < k) return 0;
    if(n < 0 || k < 0) return 0;
    return fac[n] * (finv[n - k] % m) % m;
}

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

using namespace std;
typedef long long ll;

struct UnionFind {
  vector<int> data;
  UnionFind(int size) : data(size, -1) { }
  bool unionSet(int x, int y) {
    x = root(x); y = root(y);
    if (x != y) {
      if (data[y] < data[x]) swap(x, y);
      data[x] += data[y]; data[y] = x;
    }
    return x != y;
  }
  bool findSet(int x, int y) {
    return root(x) == root(y);
  }
  int root(int x) {
    return data[x] < 0 ? x : data[x] = root(data[x]);
  }
  int size(int x) {
    return -data[root(x)];
  }
};

int c[100000];
int N, M, K;
typedef pair<ll, pair<int, int>> P;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    cin >> N >> M >> K;
    for(int i = 0; i < N; i++){
        cin >> c[i];
        c[i]--;
    }
    vector<P> v;
    for(int i = 0; i < M; i++){
        int a, b;
        ll w;
        cin >> a >> b >> w;
        a--; b--;
        int a_ = c[a] == -1 ? K+a : c[a];
        int b_ = c[b] == -1 ? K+b : c[b];
        v.push_back(P(w, pair<int, int>(a_, b_)));
    }
    sort(v.begin(), v.end());
    UnionFind uf(K+N);
    ll ans = 0;
    int cnt = 0;
    int cnt_free = 0;
    for(int i = 0; i < M; i++){
        int a = v[i].second.first;
        int b = v[i].second.second;
        ll w = v[i].first;
       // cout << a << ' ' << b << endl;
        if(!uf.findSet(a, b)){
            ans += w;
            cnt++;
            uf.unionSet(a, b);
        }
        if(cnt == K-1){
            cout << ans << endl;
            return 0;
        }
        //cout << cnt+cnt_free << endl;
    }
    cout << -1 << endl;
}

Measured memory_bytes: 3828
S,N,A,K,i,T;
main()
{
	scanf("%d",&N);
	for(i=0;i<N;i++)
	{
		scanf("%d%d",&A,&K);
		while(T=A/K+1,A%K%T)A=A/K*K-T+A%K%T;
		S^=T-1;
	}
	puts(S?"Takahashi":"Aoki");
}

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

int main(){
  long long int n, k;
  long long int rem;
  long long int x;

  cin >> n >> k;

  rem = n % k;

  if (rem > k){
    x = rem - k;
  } else {
    x = k - rem;
  }

  if (x > rem) cout << rem << endl;
  else cout << x << endl;

  return 0;
}


Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
 
int main() {
    int N;
    cin >> N;
    int A[N], B[N];
    for(int i = 0; i < N; i++) {
        B[i] = 0;
    }
    for(int i = 1; i < N; i++) {
        cin >> A[i];
        B[A[i] - 1]++;
    }
    for(int i = 0; i < N; i++) {
        cout << B[i] << endl;
    }
}


Measured memory_bytes: 5204
// #include <bits/stdc++.h>
#include <algorithm>
#include <cmath>
#include <deque>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;
typedef long long ll;

#define all(x) begin(x), end(x)
#define rep(i,n) for(int i=0; i<n; i++)

int main() {
    char a;
    cin >> a;

    if (isupper(a)) cout << 'A' << endl;
    else cout << 'a' << endl;

    return 0;
}

Measured memory_bytes: 3668
#include"stdio.h"
#include"string.h"
#include"stdlib.h"
#include"ctype.h"
#include"queue"
#include"algorithm"
using namespace std;
struct mmm
{
	int x,y;
}vv;
int dir[4][2] = {0,-1,-1,0,0,1,1,0};
char xx[1001][1001];
int vis[1001][1001],m,n;
int check(int x0,int y0)
{
	if(x0 < 0|| y0 < 0 || x0 >= m || y0 >= n)
		return 0;
	else
		return 1;
}
int bfs(int xp,int yp,int k)
{
	queue <mmm> qq;
	int n;
	vv.x = xp;
	vv.y = yp;
	qq.push(vv);
	vis[xp][yp] = 0;
	while(!qq.empty())
	{
		vv = qq.front();
		qq.pop();
		int x0 = vv.x;
		int y0 = vv.y;
		if(xx[x0][y0] == k + '0')
		{
			n = vis[x0][y0];
			break;
		}
		for(int  i = 0;i < 4;i ++)
		{
			int xt = x0 + dir[i][0];
			int yt = y0 + dir[i][1];
			if(check(xt,yt) && vis[xt][yt] == -1 && xx[xt][yt] != 'X')
			{
				vv.x = xt;
				vv.y = yt;
				qq.push(vv);
				vis[xt][yt] = vis[x0][y0] + 1;
			}
		}
	}
	return n;
}
int main()
{
	int a,b,c,d,x1,y1;
	int mm[10][2];
	while(~scanf("%d %d %d",&m,&n,&a))
	{
		for(int i = 0;i < m;i ++)
		{
			scanf("%s",xx[i]);
		}
		for(int i = 0;i < m;i ++)
		{
			for(int j = 0;j < n;j ++)
			{
				if(xx[i][j] == 'S')
				{
					x1 = i;
					y1 = j;
				}
				else if(isdigit(xx[i][j]))
				{
					int l = xx[i][j] - '0';
					mm[l][0] = i;
					mm[l][1] = j;
				}
			}
		}
		int sum = 0;
		memset(vis,-1,sizeof(vis));
		sum += bfs(x1,y1,1);
		for(int i = 2;i <= a;i ++)
		{
			memset(vis,-1,sizeof(vis));
			sum += bfs(mm[i - 1][0],mm[i - 1][1],i);
		}
		printf("%d\n",sum);
	}
	return 0;
}

Measured memory_bytes: 5948
N = gets.chomp.to_i
A = gets.chomp.to_i
B = gets.chomp.to_i
C = gets.chomp.to_i
D = gets.chomp.to_i
E = gets.chomp.to_i

min_num = [A, B, C, D, E].min
group_num = N / min_num + (N % min_num == 0 ? 0 : 1)
minutes = group_num + 4
p minutes


Measured memory_bytes: 3836
#include<bits/stdc++.h>
#include <math.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
int main() {
int N;
  cin >>N;
  vector<int> vec(N);
  rep(i,N) {
cin >>vec.at(i);
  }

  
  sort(all(vec));
  cout<<vec.at(N-1)-vec.at(0) << endl;
}

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

using namespace std;

#define pb push_back
#define mp make_pair
constexpr int INF = 1 << 29;
constexpr int MOD = 1000000007;
typedef long long ll;
typedef unsigned long long ull;

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

int main() {
    int N;
    scanf("%d", &N);
    vector<ll> A(N);
    for (int i = 0; i < N; i++) {
        scanf("%lld", &A[i]);
    }
    vector<ll> acc(N + 1);
    for (int i = 0; i < N; i++) {
        acc[i + 1] = acc[i] + A[i];
    }
    ll ans = 1LL << 62;
    int i = 1, k = 3;
    for(int j = 2; j < N - 1; j++) {
        while(i + 1 < j) {
            ll newarea = acc[i + 1] - acc[0];
            ll area = acc[i] - acc[0];
            if (abs(newarea - (acc[j] - newarea)) > abs(area - (acc[j] - area))) break;
            i++;
        }
        while(k + 1 < N) {
            ll newarea = acc[k + 1] - acc[j];
            ll area = acc[k] - acc[j];
            if (abs(newarea - (acc[N] - acc[j] - newarea)) > abs(area - (acc[N] - acc[j] - area))) break;
            k++;
        }
        vector<ll> area;
        area.push_back(acc[i]);
        area.push_back(acc[j] - acc[i]);
        area.push_back(acc[k] - acc[j]);
        area.push_back(acc[N] - acc[k]);
        sort(area.begin(), area.end());
        ans = min(ans, area.back() - area[0]);
    }
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 3328
N = int(input())
a = list(map(int, input().split())) + [0]
c = [0] * (N + 2)
for i in range(N):
    c[i + 1] = abs(a[i] - a[i - 1])
c[-1] = abs(a[-2])
s = sum(c)
for i in range(N):
    print(s - c[i + 1] - c[i + 2] + abs(a[i + 1] - a[i - 1]))

Measured memory_bytes: 14048