akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
#define repr(i, n) for (int i = (int)n - 1; i >= 0; --i)
#define ALL(a) (a).begin(), (a).end()
const ll mod = 1e9 + 7;

int n;

struct Edge {
  int to, id;
};

vector<vector<Edge>> graph;
vector<int> ans;

void dfs(int v, int c = -1, int p = -1) {
  int k = 1;
  rep(i, graph[v].size()) {
    int u = graph[v][i].to, ei = graph[v][i].id;
    if (u == p) continue;
    if (k == c) k++;  //すでに色が使用済みだったらインクリメント
    ans[ei] = k;
    k++;
    dfs(u, ans[ei], v);
  }
}

void bfs(int v) {
  queue<int> que;
  vector<int> used(n);
  que.push(0);
  used[0] = 1;
  while (!que.empty()) {
    int v = que.front();
    que.pop();
    int c = -1;
    rep(i, graph[v].size()) {
      int u = graph[v][i].to, ei = graph[v][i].id;
      if (used[u]) c = ans[ei];
    }
    int k = 1;
    rep(i, graph[v].size()) {
      int u = graph[v][i].to, ei = graph[v][i].id;
      if (used[u]) continue;
      if (k == c) k++;
      ans[ei] = k;
      k++;
      que.push(u);
      used[u] = 1;
    }
  }
}

int main() {
  cin >> n;
  graph.resize(n);
  ans.resize(n - 1);
  rep(i, n - 1) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    graph[a].push_back(Edge{b, i});
    graph[b].push_back(Edge{a, i});
  }
  bfs(0);
  int mx = 0;
  rep(i, n) mx = max(mx, int(graph[i].size()));  //次数の最大値を計算
  cout << mx << endl;
  rep(i, n - 1) cout << ans[i] << endl;
  return 0;
}

Measured memory_bytes: 7168
A, B, C = map(int, input().split())
K = int(input())

tmp = K
for i in range(K):
  if A < B:
    tmp = i
    break
  B = B * 2
  
if B < C:
  print('Yes')
elif B < C * (2 ** (K - tmp)):
  print('Yes')
else:
  print('No')
   

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

using namespace std;

long long prime = 1000000007;

bool all_chars_equal(string s) {
    for (char c : s) {
        if (c != s[0]) {
            return false;
        }
    }
    return true;
}

vector<int> get_runs(string s) {
    vector<int> runs;
    int current_run = 0;
    for (char c : s) {
        if (c == s[0]) {
            ++current_run;
        } else if (current_run > 0) {
            runs.push_back(current_run);
            current_run = 0;
        }
    }
    return runs;
}
    
long long f(int n, int k) {
    vector<long long> pow_2(2 * k + 4);
    pow_2[0] = 1LL;
    for (int i = 1; i < 2 * k + 4; ++i) {
        pow_2[i] = pow_2[i - 1] * 2 % prime;
    }

    vector<long long> f1(max(n + 1, 2 * k + 4), 0);
    for (int i = 1; i <= k; ++i) {
        f1[i] = pow_2[i];
    }
    f1[k + 1] = (pow_2[k+1] - 1 + prime) % prime;
    for (int n1 = k + 2; n1 <= 2 * k + 3; ++n1) {
        f1[n1] = ((pow_2[n1] - 1 - n1 * pow_2[n1 - k - 2]) % prime + prime) % prime;
    }
    for (int n1 = 2 * k + 4; n1 <= n; ++n1) {
        f1[n1] = ((2 * f1[n1 - 1] - f1[n1 - k - 2]) % prime + prime) % prime;
    }
    return f1[n];
}

/*
f(n, k) = antal cirkler af længde n med højst k røde i streg (ingen andre begrænsninger)

f(n, k) = 2^n for n <= k
f(n, k) = 2^n - 1 for n = k+1
f(n, k) = 2^n - 1 - n * 2^{n-k-2} for k+2 <= n <= 2k+3
f(n, k) = 2f(n-1, k) - f(n-k-2, k) for n >= 2k + 4

*/

long long different_case(int n, int k) {
    return f(n / 2, (k - 1) / 2) * 2LL % prime;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m;
    string s;
    cin >> n >> m;
    cin >> s;
    auto t0 = clock();
    if (all_chars_equal(s)) {
        cout << f(n, 1) << endl;  // OK since n >= 2
        cerr << "Time used: " << clock() - t0 << " ms" << endl;
        return 0;
    }
    if (n % 2 != 0) {
        cout << 0 << endl;
        return 0;
    }
    vector<int> runs = get_runs(s);
    int bound = runs[0] / 2 * 2 + 1;
    bound = min(bound, n - 1);
    for (int run : runs) {
        if (run % 2 == 1) {
            bound = min(bound, run);
        }
    }
    cout << different_case(n, bound) << endl;

    cerr << "Time used: " << clock() - t0 << " ms" << endl;
    return 0;
}


Measured memory_bytes: 3792
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
 
class Program {
    static List<long> rep;
    static void Main(string[] args){
        //入力を受け取る
        var N = long.Parse(Console.ReadLine());
        var A = Console.ReadLine().Split().Select(a => long.Parse(a)).ToArray();
         
         var count = 0;
         for(int i = 0;i < N;i++){
             if(A[i] == count+1){
                 count++;
             }
         }
       
         if(count == 0){
             Console.WriteLine(-1);
         }else{
             Console.WriteLine(N-count);
         }
       　
    }
    
    static int LowerBound(long num){
        
        var l = 0;
        var r = rep.Count()-1;
      
        while(l <= r){
            
            var mid = l+(r-l)/2;
            if(rep[mid] < num){
                l = mid+1;
            }else{
               
                r = mid-1;
            }
        }
        return l;
    }     
}


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

#define MEM(a, b) memset(a, b, sizeof a);
#define REP(i, k) for(int i = (0); i < int(k); i++ )
#define FOR(i, a, b) for(int i = (a); i <= int(b); i++)

#define ALL(cont) cont.begin(), cont.end()
#define RALL(cont) cont.begin(), cont.end()
#define FOREACH(it, l) for(auto it=l.begin(); it != l.end(); it++)
#define mp make_pair
#define pb push_back
#define INF (int)INT_MAX
#define EPS (int)1e-9
#define PI acos(-1)
#define MOD 1000000007

#ifdef DEBUG
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

typedef long L;
typedef unsigned long UL;
typedef long long LL;
typedef unsigned long long ULL;

string to_string(string s) {
    return '"' + s + '"';
}

string to_string(const char* s) {
    return to_string((string) s);
}

string to_string(bool b) {
    return (b ? "true" : "false");
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
    return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A>
string to_string(A v) {
    bool first = true;
    string res = "{";
    for (const auto &x : v) {
        if (!first) {
            res += ", ";
        }
        first = false;
        res += to_string(x);
    }
    res += "}";
    return res;
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << to_string(H);
    debug_out(T...);
}

void solve(__attribute__((unused)) int tc = 0) {
    int n, y;
    cin >> n >> y;
    int p = -1, q = -1, r = -1;

    REP(a, n + 20) {
        REP (b, n + 20) {
            int c = (y - (1000 * a + 5000 * b)) / 10000;
            if (a + b + c == n && (1000 * a + 5000 * b + 10000 * c) == y && c >= 0)  {
                p = a;
                q = b;
                r = c;
                goto output;
            }
        }
    }

output:
    cout << r << " " << q << " " <<  p << endl;
    return;
}

int main() {
#ifdef FILE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    cin.tie(0);
    ios_base::sync_with_stdio(false);

    /*int TC;
      cin >> TC;
      REP(tc, TC) {
      solve(tc);
      }*/
    solve();
#ifdef TIME
    cout << "Execution time(second) : " << int(clock() * 1000.0 / CLOCKS_PER_SEC) << " ms" << endl;
#endif
}


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

using namespace std;

int main() {
  int N;
  int cnt = 0;
  cin >> N;
  for (int i = 0; i < N; ++i) {
    int x;
    cin >> x;
    cnt += (x % 2);
  }
  if (cnt % 2 == 0) cout << "YES" << endl;
  else cout << "NO" << endl;
}

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

typedef long long int ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef vector<string>vst;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;

#define fastio ios_base::sync_with_stdio(false);cin.tie(0)
#define all(ct) ct.begin() , ct.end()
#define endl "\n"
#define fr(i,a) for(auto i:a)
#define f(i,a,b) for(int i=a;i<b;++i)
#define fd(i,a,b) for(int i=a;i>=b;--i)
#define pb push_back
#define in(d,v) d.find(v)!=d.end()
#define mp make_pair
#define size(a) int(a.size())

const int mod = 1e9 + 7;
const ll inf = ll(1e18);
const double PI = acos(-1);

ll modexp(ll x,ll n,int md){
    if(n==0)return 1;
    if(n%2==0)return modexp((x*x)%md,n/2,md);
    return (x*modexp((x*x)%md,n/2,md))%md;
}

int main(){
    fastio;
    //clock_t tm = clock();
    ll n,a,b;
    cin>>a>>b;
    for(int i=1;i<=1250;++i){
        if(int(i*0.08)==a and int(i*0.1)==b){
            cout<<i<<endl;
            return 0;
        }
    }
    cout<<-1<<endl;
    //cout<<((clock()-tm)*1.0)/CLOCKS_PER_SEC<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,t;
    cin>>n>>t;
    vector<int>vec(n);
    for(int i=0;i<n;i++)
      cin>>vec[i];
    int sum=0;
    for(int i=0;i<n-1;i++)
      sum+=min(t,vec[i+1]-vec[i]);
    sum+=t;
    cout<<sum<<endl;
    return 0;
}

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

int main() {
    int n, a;
    cin >> n;
    vector<int> x(100001, 0);
    long long sum = 0;
    for (int i = 0; i < n; i++) {
        cin >> a;
        sum += a;
        x[a]++;
    }
    int q, b, c;
    cin >> q;
    for (int i = 0; i < q; i++) {
        cin >> b >> c;
        sum += (c - b) * x[b];
        x[c] += x[b];
        x[b] = 0;
        cout << sum << endl;
    }
}

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

vector<int> paths[200001];

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

    int n, m, x, y;

    cin >> n >> m;

    for (int i = 0; i < m; ++i)
    {
        cin >> x >> y;
        paths[x].push_back(y);
    }

    for (auto it : paths[1])
        for (auto it2 : paths[it])
            if (it2 == n)
            {
                cout << "POSSIBLE\n";
                return 0;
            }
    
    cout << "IMPOSSIBLE\n";
}

Measured memory_bytes: 8576
let sub hs b = List.map (fun a -> a - b) hs 

let divide hs = 
  (*
  Printf.printf "hs@divide: %s\n" (List.fold_left (fun acc h -> (string_of_int h) ^ "; " ^ acc) "" hs);
   *)
  let rec inner left temp min_h = function
  | [] -> temp::left, min_h
  | h::hs when h = 0 -> inner (temp::left) [] 101 hs
  | h::hs -> inner left (h::temp) (min min_h h) hs
  in inner [] [] 101 hs

let rec solve = function
  | [] -> 0
  | hs -> 
     match divide hs with
     | [], min_h -> 0
     | hss, min_h when List.length hss = 1 -> min_h + (solve @@ sub hs min_h)
     | hss, _ -> List.fold_left (fun acc hs -> acc + solve hs) 0 hss

let _ =
  let n = Scanf.scanf "%d\n" (fun n -> n) in
  let hs = ref [] in
  for i = 0 to n - 1 do
    Scanf.scanf (if i <> n - 1 then "%d " else "%d\n") (fun h -> hs := h::!hs)
  done;
  solve !hs |> print_int


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

#define int long long
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define pb push_back
#define fi first
#define se second
template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

signed main(){
    int T;
    cin>>T;
    while(T--){
        int N,D;
        cin>>N>>D;
        int ans=(N-1)*127;
        if(N&1)ans+=D;
        else ans+=D^127;
        cout<<ans<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
/**
 * We'll, once again, tackle this using DP.  Let P(n, k) be the probability
 * that, among the first n coins tossed, there are k heads.  Then on the nth
 * coin toss, we have two possibilities: either the nth coin comes up heads,
 * in which case we will have k heads if the previous n-1 coins yielded k-1
 * heads, or the nth coin comes up tails, in which case we will have k heads
 * if the previous n-1 coin tosses yielded k heads.  Then:
 * 
 * P(n, k) = p_n*P(n-1, k-1) + (1 - p_n)*P(n-1, k)
 * P(0, 0) = 1
 * P(0, k) = 0 for n < k
 * P(n, 0) = (1 - p_n)*P(n-1, 0)
 */

#include <stdio.h>
#include <stdlib.h>

double get_prob(double *p, int n)
{
    double head_probs[n+1][n+1];
    int i, j;
    
    head_probs[0][0] = 1.0;
    
    for (i=1; i<=n; i++)
    {
        head_probs[i][0] = (1 - p[i-1])*head_probs[i-1][0];
    }
    
    for (i=1; i<=n; i++)
    {
        head_probs[0][i] = 0.0;
    }
    
    for (i=1; i<=n; i++)
    {
        for (j=1; j<=n; j++)
        {
            head_probs[i][j] = p[i-1]*head_probs[i-1][j-1] + (1 - p[i-1])*head_probs[i-1][j];
        }
    }
    
    double prob = 0.0;
    
    for (i=(n/2)+1; i<=n; i++)
    {
        prob += head_probs[n][i];
    }
    
    return prob;
}

int main(int argc, char **argv)
{
    int n;
    double *p;
    int i;
    
    scanf("%d", &n);
    
    p = (double *)malloc(sizeof(double)*n);
    
    for (i=0; i<n; i++)
    {
        scanf("%lf", &p[i]);
    }
    
    printf("%.10f", get_prob(p, n));
    
    return 0;
}

Measured memory_bytes: 70528
#include <bits/stdc++.h>
#define MAXN 2550
#define pii pair<int, int>
#define ff first
#define ss second
#define ll long long
#define in_range(x, y, n) (x >= 0 and x < n and y >= 0 and y < n)
using namespace std;
const ll mod = 1e9 + 7;

int main() {
    ios_base::sync_with_stdio(false);
    int n;
    cin >> n;

    int ans = 0;
    vector<int> a(n), b(n), c(n-1), visited(n, 0);
    for (int& x : a) cin >> x;
    for (int& x : b) cin >> x, ans+=x;
    for (int& x : c) cin >> x;


    for (int x = 0; x<a.size() - 1; x++){
        if (a[x+1] -1 == a[x]) ans+=c[a[x] - 1];
    }

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

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

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    long long a, b, c, d;
    cin >> a >> b >> c >> d;
    long long e = (c*d) / __gcd(c,d);
    auto calc = [&](long long x) {
        // number of integers 0,1, ..., x-1 not divisible by c nor d
        return x - ((x+c-1)/c + (x+d-1)/d) + (x+e-1)/e;
    };
    cout << calc(b+1) - calc(a) << endl;
    return 0;
}


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


int main(){
    int n;
    string s;
    cin >> n >> s;
    int cnt = 0;
    rep(i, n-2){
        string tmp;
        for(int j = i; j < i+3; j++){
            tmp += s[j];
        }
        if (tmp == "ABC") cnt ++;
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5;
int n, L, ans = 1;
int x[maxn + 10], t[maxn + 10];
int a[maxn + 10], acnt;
int mn, sum[maxn + 10], f[maxn + 10];
int res = 1e9;

int main() {
	scanf("%d%d", &n, &L);
	for (int i = 1; i <= n; ++i) scanf("%d", &x[i]);
	a[++acnt] = 1;
	for (int i = 1; i <= n; ++i) {
		scanf("%d", &t[i]);
		int w = (t[i] - 1) / (2 * L);
		ans += w * 2; t[i] -= w * 2 * L;
		bool isl, isr;
		if (t[i] <= (L - x[i]) * 2) isl = 1;
		else isl = 0;
		if (t[i] <= x[i] * 2) isr = 1;
		else isr = 0;
		if (isl && isr) {
			a[++acnt] = 0; ++ans;
		} else if (!isl && !isr) ans += 2;
		else if (isl) {
			a[++acnt] = -1; ++ans;
		} else {
			a[++acnt] = 1; ++ans;
		}
		if (i == n && !isl) {
			a[++acnt] = -1; ++ans;
		}
	}
	for (int i = 1; i <= acnt; ++i) 
		sum[i] = sum[i - 1] + (a[i] ? a[i] : -1);
	for (int i = acnt; i >= 1; --i)
		f[i] = min(f[i + 1], sum[i] - (i != acnt));
	for (int i = 0, now = 0, tot = sum[acnt], mn = 0; i <= acnt; ++i) {
		int l = min(now + f[i + 1] - sum[i], mn), v = 0;
		if (l < 0) {
			v -= l; v += tot - l;
		} else v += tot;
		res = min(res, v);
		now += a[i + 1] ? a[i + 1] : 1;
		tot += a[i + 1] ? 0 : 2;
		mn = min(mn, now - (i + 1 != acnt));
	}
	printf("%lld", 1ll * (ans + res) * L);
}


Measured memory_bytes: 6144
import java.util.Scanner;
public class Main {
	public static void main(String args[]) {

		Scanner sc = new Scanner(System.in);
		int[] n = new int[6];

		for (int i = 0; i < 6; i++) {
			n[i] = sc.nextInt();
		}
		if ((n[4] - n[0]) <= n[5]) {
			System.out.println("Yay!");
		} else {
			System.out.println(":(");
		}

	}
}

Measured memory_bytes: 23892
def main():
    l, r = map(int, input().split())
    minv = 2019
    if r - l > 2019+1:
        print(0)
    else:
        for i in range(l, r+1):
            for j in range(l, r+1):
                if i < j:
                    minv = min(minv, (i*j)%2019)
        print(minv)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
# -*- coding: utf-8 -*-
"""
Spyderエディタ

これは一時的なスクリプトファイルです
"""

strT, pwT, strA, pwA = map(int, input().split())

while strT > 0 or strA > 0:
    strA -= pwT
    if strA <= 0:
        break
    strT -= pwA

if strT > 0:
    print('Yes')
else:
    print('No')

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

using namespace std;

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

  int a, b;
  cin >> a >> b;
  if (a <= b) {
    cout << a << "\n";
  } else {
    cout << a - 1 << "\n";
  }
}


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

#define MP make_pair
#define PB push_back
#define ALL(x)      (x).begin(),(x).end()
#define REP(i,n)    for(int i=0;i<(n);i++)
#define REP1(i,n)   for(int i=1;i<(n);i++)
#define REP2(i,d,n) for(int i=(d);i<(n);i++)
#define RREP(i,n)   for(int i=(n);i>=0;i--)
#define CLR(a)      memset((a),0,sizeof(a))
#define MCLR(a)     memset((a),-1,sizeof(a))
#define RANGE(x,y,maxX,maxY) (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY))
 
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI > VVI;
typedef vector<string> VS;
typedef vector<LL> VLL;
typedef pair<int,int> PII;
 
const int INF = 0x3f3f3f3f;
const LL INFL = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-9;
 
const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};

const string YES = "Yes";
const string NO = "No";

void solve(std::string S){
    sort(ALL(S));
    cout << (S[0] == S[1] && S[2] == S[3] && S[1] != S[2] ? YES : NO ) << endl;
}

int main(){
    std::string S;
    std::cin >> S;
    solve(S);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,n) for(long long i=0;i<n;++i)
#define REPP(i,m,n) for(long long i=m;i<n;++i)
#define rep(i,n) for(long long i = n-1;i>=0;--i)
#define repp(i,n,m) for(long long i = n-1; i >= m; --i)
#define ALL(N) (N.begin(),N.end())
#define de cout << "line : " << __LINE__ << " debug" << endl;
#define pb push_back
#define pq priority_queue
#define fi first
#define se second
#define Dcout(N) cout << setprecision(20) << N << endl
constexpr int INF = 2147483647;
constexpr long long INFF = 9223372036854775807;

signed main() {
    cin.tie(0);
	ios::sync_with_stdio(false);
    int N;cin >> N;
    int A[N];
    REP(i,N){
        cin >> A[i];
        if(A[i] % 2 == 1){
            cout << "first" << endl;
            return 0;
        }
    }
    cout << "second" << endl;
}


Measured memory_bytes: 640
#include<iostream>
#include<string>
#include<vector>
#include<math.h>
#include<algorithm>
#include<cstdio>
#include<stdio.h>
#include<stack>
#include<sstream>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<list>
#include<numeric>
typedef long long ll;

#define pi 3.14159265358979323846
#define VI vector<int>
#define VLL vector<long long>
#define MAX max_element
#define MIN min_element
#define all(v) v.begin(), v.end()
const ll MOD = 1e9 + 7;
using namespace std;
template<typename T>
T gcd(T a, T b) {
	return b ? gcd(b, a % b) : a;
}
template<typename T>
T lcm(T a, T b) {
	return a * b / gcd(a, b);
}

template<typename T>
T binarysearch(vector<T> A, T key) {
	ll left = 0;ll right = 4;ll mid;
	while (left < right) {
		mid = (left + right) / 2;
		if (key == A[mid]) return 1;
		if (key > A[mid]) left = mid + 1;
		else if (key < A[mid]) right = mid;
	}
	return 0;
}

template<typename T>
T finder(vector<T> vec, T number) {
	auto itr = find(vec.begin(), vec.end(), number);
	size_t index = distance(vec.begin(), itr);
	if (index != vec.size()) { // 発見できたとき
		return 1;
	}
	else { // 発見できなかったとき
		return 0;
	}
}
ll frac(ll n)//階乗
{
	if (n == 0) {
		return 1;
	}
	return (n * frac(n - 1)) % MOD;
}

template<typename T>
T keta(T a) {
	ll kazu = 1;
	while (1) {
		if (a / 10 != 0) { a /= 10;kazu++; }
		else break;
	}
	return kazu;
}//桁数


template<typename T>
T nCr(ll n, T r) {
	ll ans = 1;
	for (int i = n; i > n - r; --i) {
		ans = ans * i;
	}
	for (int i = 1; i < r + 1; ++i) {
		ans = ans / i;
	}
	return ans;
}
/*char r[4];
int yaju[4];
char op[3];
int sum = 0;
scanf("%s", r);
for (int i = 0;i < 4;i++) {
	yaju[i] = r[i] - '0';
}
*/
int main() {
	ll N, K;cin >> N >> K;
	vector<ll>A(3);
	A[0] = N;A[1] = N % K;A[2] = abs(K - N % K);
	sort(all(A));
	cout << A[0] << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define fastIO          ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define ll              long long
#define rep(i,a)        for(ll i = 0 ; i < a ; i++)
#define repe(i,a,b)     for(ll i = a ; i < b ; i++)
#define bac(i,a)        for(ll i = a ; i >= 0 ; i--)
#define bace(i,a,b)     for(ll i = a ; i >= b ; i--)
#define pb              push_back
#define mp              make_pair
#define in              insert
#define ff              first
#define ss              second
#define vv              vector
#define vll             vector <ll>
#define pll             pair <ll,ll>
#define vpll            vector <pll>
#define umap            unordered_map
#define uset            unordered_set
#define mset            multiset
#define pqueue          priority_queue
#define stk             stack<ll>
#define que             queue<ll>
#define setbit(x)       __builtin_popcountll(x)
#define init(c,a)       memset(c,a,sizeof(c))
#define all(c)          c.begin(),c.end()
#define lb              lower_bound
#define ub              upper_bound
#define maxe            *max_element
#define mine            *min_element
#define gcd(a,b)        __gcd(a,b)
#define rev             reverse
#define Y               "YES"
#define N               "NO"
#define br              "\n"
#define sp              " "
#define debug(x)        cout << #x << " : " << x << endl;
const ll mod = 1000000007;
const ll MOD = 998244353;
const ll inf = 1e18;
const ll MAX = 2e5 + 1;


// ====== int_1024t begins ======
// #include <boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision;
// ====== int_1024t ends ======

inline ll add(ll a, ll b) {return ((a % mod) + (b % mod)) % mod;}
inline ll sub(ll a, ll b) {return ((a % mod) - (b % mod) + mod) % mod;}
inline ll mul(ll a, ll b) {return ((a % mod) * (b % mod)) % mod;}
ll pwr(ll x, ll n) {
	x = x % mod;
	if (!n) return 1;
	if (n & 1) return mul(x, pwr(mul(x, x), (n - 1) / 2));
	else return pwr(mul(x, x), n / 2);
}
// O(nlogn) for [1,n]
ll modinv(ll n) {
	return pwr(n, mod - 2);
}
// O(logn) for[1,n]
ll inv(ll i) {
	if (i == 1) return 1;
	return (MOD - (MOD / i) * inv(MOD % i) % MOD) % MOD;
}
// =============================

const int INF = 1e9 + 5;
vector<int> cost;
int n, k;
int dp[100005];
int f(int i)
{
	if (i == ( n - 1))
		return 0;

	if (dp[i] != -1)
		return dp[i];

	int ans = INF;
	for (int j = i + 1; j <= min(n - 1, i + k ); j++)
	{
		//cout << j << endl;
		ans = min(ans, f(j) + abs(cost[j] - cost[i]));
		//cout << ans << endl;
	}

	return dp[i] = ans;
}

void solve()
{

	cin >> n >> k;
	for (int i = 0; i <= n; i++)
		dp[i] = -1;
	cost.resize(n);
	for (int i = 0; i < n; i++)
		cin >> cost[i];
	cout << f(0) ;


}

int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int t;
	// cin >> t;
	// while (t--)
	// {
	solve();
	// }

	return 0;
}

Measured memory_bytes: 11852
import java.util.*;
 
public class Main {
 
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
         
        while(true){
            int n = sc.nextInt();
            if(n==0) break;
            int cnt = 0;
            boolean flag = false;
            for(int i=0;i<n;i++){
                int k = sc.nextInt();
                if(k>0) cnt++;
                if(k>1) flag = true;
            }
            if(!flag) System.out.println("NA");
            else System.out.println(cnt+1);
        }
    }
}

Measured memory_bytes: 158608
import java.util.*;
public class Main{
	public static void main(String[] args){
      Scanner sc = new Scanner(System.in);
      String s = sc.next();
      int len = s.length();
      
      String str = "";
      StringBuilder sb = new StringBuilder();
      for(int i=0; i<len; i++){
        if(i%2==0){
	        sb.append(s.substring(i,i+1));
        }
      }  
      System.out.println(sb.toString());
    }  
}  

Measured memory_bytes: 32304
n, k = map(int, input().split())
A = list(map(int, input().split()))
L = [0] * n
L[0] = 1
i = A[0] - 1
j = 1
while j < k:
    if L[i] < 2:
        L[i] += 1
    else:
        break
    i = A[i] - 1
    j += 1
if j == k:
    print(i + 1)
else:
    loop = L.count(2)
    k = (k - L.count(1)) % loop
    while k > 0:
        i = A[i] - 1
        k -= 1
    print(i + 1)


Measured memory_bytes: 32240
#include <bits/stdc++.h>
#define repl(i, l, r) for (int i = l; i < r; i++)
#define rep(i, n) repl(i, 0, n)
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<int, int>;

int a[101];

int main()
{
    int n;
    cin >> n;
    rep(i, n) {
        int d;
        cin >> d;
        a[d]++;
    }
    int ans = 0;
    rep(i, 101) {
        if(a[i] != 0) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import sys
X,Y = map(int,input().split())
if(X == 1 and Y == 1):
    print(0)
    sys.exit()
elif(Y == 1):
    print(int(X/2))
    sys.exit()
elif(X == 0 and Y ==2):
    print(1)
    sys.exit()
print(int((X * (X-1))/2 + int((Y * (Y-1))/2 )))


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

int main () {
  int K, X;
  cin >> K >> X;
  
  int y;
  y= X-(K-1);
  
  for (int i = 0; i < K-1; i++)
    cout << y++ <<" " ;
  
  for (int i = 0; i < K; i++)
    cout << X++ <<" " ;
  cout << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-11;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

int n;

int main(){
	cin>>n;
	for(int i=0;i<n;i++){
		string s,t;
		cin>>s>>t;
		int m=s.size();
		int N=t.size();
		for(int j=m-1;j>=0;j--){
			string u;
			if(s[j]=='J') u=t[N-1]+t.substr(0,N-1);
			if(s[j]=='C') u=t.substr(1,N-1)+t[0];
			if(s[j]=='E'){
				if(N%2==0) u=t.substr(N/2,N/2)+t.substr(0,N/2);
				else u=t.substr(N/2+1,N/2)+t[N/2]+t.substr(0,N/2);
			}
			if(s[j]=='A'){
				u=t;
				reverse(u.begin(),u.end());
			}
			if(s[j]=='P'){
				u=t;
				for(int k=0;k<N;k++) if(isdigit(u[k])){
					if(u[k]=='0') u[k]='9';
					else u[k]--;
				}
			}
			if(s[j]=='M'){
				u=t;
				for(int k=0;k<N;k++) if(isdigit(u[k])){
					if(u[k]=='9') u[k]='0';
					else u[k]++;
				}
			}
			t=u;
		}
		cout<<t<<endl;
	}
}


Measured memory_bytes: 3180
import sys
sys.setrecursionlimit(10**6)

N = int(input())
uvw = []
for _ in range(N-1):
    uvw.append(tuple(map(int, input().split())))


H=[[] for _ in range(N+1)]
for el in uvw:
    H[el[0]].append((el[1], el[2]))
    H[el[1]].append((el[0], el[2]))
#print(H)

seen=[False]*(N+1)
color=[0]*(N+1)
def dfs(n):
    seen[n]=True
    for nxt in H[n]:
        if seen[nxt[0]] == False:
            if nxt[1] % 2 == 0:
                color[nxt[0]]=color[n]
            else:
                color[nxt[0]]=color[n] ^ 1
            dfs(nxt[0])

dfs(1)
#print(distance)
#print(seen)

for i in range(1,N+1):
    print(color[i])



Measured memory_bytes: 87456
#include<cstdio>
#define MAX 505
using namespace std;

int main(){
  int n, m, q, a[MAX][MAX], i, j, l, r;
  scanf("%d%d%d", &n, &m, &q);
  for(i = 1; i <= n; i++)
    for(j = 1; j <= n; j++)
      a[i][j] = 0;
  for(i = 0; i < m; i++){
    scanf("%d%d", &l, &r);
    a[1][r]++; a[l+1][r]--;
  }
  for(i = 1; i <= n; i++)
    for(j = 1; j <= n-1; j++)
      a[i][j+1] += a[i][j];
  for(j = 1; j <= n; j++)
    for(i = 1; i <= n-1; i++)
      a[i+1][j] += a[i][j];
  for(i = 0; i < q; i++){
    scanf("%d%d", &l, &r);
    printf("%d\n", a[l][r]);
  }
}

Measured memory_bytes: 1792
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
#include <random>
#include <cassert>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
#define MEM(a,b) memset((a),(b),sizeof(a))
const LL INF = 1e9 + 7;
const int N = 2e3 + 10;
int a[N];
int b[N];
LL dp[N][N];
int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int n, m;
	cin >> n >> m;
	for (int i = 1; i <= n; i++) cin >> a[i];
	for (int i = 1; i <= m; i++) cin >> b[i];
	dp[n][m] = 1;
	for (int i = 1; i <= n; i++)
	{
		for (int j = 1; j <= m; j++)
		{
			dp[i][j] += dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - 1];
			if (a[i] == b[j]) dp[i][j] += 1 + dp[i - 1][j - 1];
			while (dp[i][j] >= INF) dp[i][j] -= INF;
			if (dp[i][j] < 0) dp[i][j] += INF;
		}
	}
	cout << dp[n][m] << endl;
	return 0;
}

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

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using pll = pair<ll,ll>;

#define INF (1LL << 60)
#define MOD 1000000007
#define PI 3.14159265358979323846

#define REP(i,m,n) for(ll (i)=(m),(i_len)=(n);(i)<(i_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define REV(x) reverse(ALL((x)))
#define ASC(x) sort(ALL((x)))
#define DESC(x) ASC((x)); REV((x))
#define pb push_back
#define eb emplace_back

vector<bool> chk(ll n)
{
    vector<bool> f(10, false);
    string s = to_string(n);
    REP(i,0,SZ(s)) f[s[i]-'0'] = true;
    return f;
}

int main()
{
    ll N, K;
    cin >> N >> K;
    vec F(10, true);
    REP(i,0,K) {
        ll d;
        cin >> d;
        F[d] = false;
    }

    REP(i,N,100000) {
        vector<bool> G = chk(i);
        bool f = true;
        REP(j,0,10) {
            if((!F[j]) && G[j]) {
                f = false;
                break;
            } 
        }
        if(f) {
            PR(i);
            break;
        }
    }

    return 0;
}

/*



*/

Measured memory_bytes: 3700
#include <stdio.h>
#include <math.h>
 
#define PI 3.141592653589793
 
int main(void){
    int a,b,c;
    double s,l,h;
     
    scanf("%d%d%d",&a,&b,&c);
     
    s = sin(c * PI / 180.0)*a*b/2;
    l = a + b + sqrt(a*a + b*b - 2*a*b * cos(c * PI / 180.0));
    h = s/a*2;
     
    printf("%lf %lf %lf\n" ,s,l,h);
     
    return 0;
}


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

#include<string>

int main(){
 string src;
 int n, cnt = 0;
 cin >> src >> n;

 for(int i = 0; i < n; ++i){
  string str;
  cin >> str;
  str += str;
  if(str.find(src) != -1){ ++cnt; }
 }

 cout << cnt << endl;

 return 0;
}

Measured memory_bytes: 3096
N = input()
Ws = list(map(int, input().split()))

S1 = 0
goukei = sum(Ws)
S2 = goukei
difs = [] 

for W in Ws:
    S1 += W
    S2 = goukei - S1
    dif = max(S1, S2)-min(S1, S2)
    difs.append(dif)
    
print(min(difs))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ULL;
typedef long long LL;
struct point{
	ULL x,y;
	point (ULL _x,ULL _y){
		x=_x;
		y=_y;
	}
	point(){
	}
};
ULL absminus(ULL a,ULL b){
	if(a>b)
		return a-b;
	else
		return b-a;
}
ULL jarak(point a,point b){
	return (absminus(a.x,b.x)+absminus(a.y,b.y));
}
int ans[100];
point murid[100],guru[100];
int main()
{
	LL tambah=1000000000000000000LL;
	int n,m;
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)
	{
		LL x,y;
		cin>>x>>y;
		x+=tambah,y+=tambah;
		murid[i]=point(x,y);
	}
	for(int i=1;i<=m;i++)
	{
		LL x,y;
		cin>>x>>y;
		x+=tambah,y+=tambah;
		guru[i]=point(x,y);
	}
	for(int i=1;i<=n;i++)
	{
		int ansnow=1;
		ULL best=jarak(murid[i],guru[1]);
		for(int j=2;j<=m;j++)
		{
			if(jarak(murid[i],guru[j])<best)
			{
				best=jarak(murid[i],guru[j]);
				ansnow=j;
			}
		}
		printf("%d\n",ansnow);
	}
}

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

#define rep(i,n) for(ll i=0;i<(n);++i)
#define reps(i,n) for(ll i=1;i<=(n);++i)
using ll = long long;
using str = string;
constexpr long long INF = (1LL<<60);
constexpr long long MOD = (1e9+7);
template<class T>inline T gcd(T a,T b){if(b==0)return a; return(gcd(b,a%b));}
template<class T>inline T lcm(T a,T b){return a/gcd(a,b)*b;}
template<class T>inline bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}
inline void dump(){cout<<endl;}
template<class Head,class... Tail>inline void dump(Head&& head, Tail&&... tail){cout<<head<<", ";dump(forward<Tail>(tail)...);}
template<typename T>inline istream &operator>>(istream&input,vector<T>&v){for(auto &elemnt:v)input>>elemnt;return input;}
using vertex = struct vertex{ll to,cost;vertex(ll to,ll cost):to(to),cost(cost){}};
using _vertex = struct _vertex{ll to;_vertex(ll to):to(to){}};
using edge = struct edge{ll from,to,cost;edge(ll from,ll to,ll cost):from(from),to(to),cost(cost){}};
using _edge = struct _edge{ll from,to;_edge(ll from,ll to):from(from),to(to){}};
using un_weighted_adjlist = vector<vector<_vertex>>;
using weighted_adjlist = vector<vector<vertex>>;
using un_weighted_edge = vector<_edge>;
using weighted_edge = vector<edge>;

main(){
  cin.tie(0);
  ios::sync_with_stdio(0);
  cout<<fixed<<setprecision(10);
  
  ll n;
  cin>>n;
  weighted_adjlist adj(n);
  rep(i,n-1){
    ll u,v,w;
    cin>>u>>v>>w;
    u--;v--;
    adj[u].emplace_back(v,w);
    adj[v].emplace_back(u,w);
  }

  vector<ll> dist(n,INF);
  queue<pair<ll,ll>>que;
  que.emplace(0,0);
  while(!que.empty()){
    ll w,v;
    tie(w,v)=que.front();
    que.pop();
    dist[v]=w;
    for(const auto& nv:adj[v]){
      if(nv.cost+w < dist[nv.to]){
        que.emplace(nv.cost+w,nv.to);
      }
    }
  }

  rep(i,n){
    cout<<dist[i]%2<<endl;
  }


}


Measured memory_bytes: 8704
#include<iostream>
using namespace std;
int main()
{
    int n, ans = 0;
    int a[20], b[20], c[20];
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> a[i];
        a[i]--;
    }
    for(int i = 0; i < n; i++){
        cin >> b[i];
    }
    for(int i = 0; i < n-1; i++){
        cin >> c[i];
    }
    for(int i = 0; i < n; i++){
        ans += b[a[i]];
        if(i && a[i-1] + 1 == a[i]){
            ans += c[a[i-1]];
        }
    }
    cout << ans << endl;
    return 0;
}

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

#define int long long

signed main() {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    int ans = min(b,d) - max(a, c);
    if(ans<0) ans = 0;
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

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

		int x = sc.nextInt();
		int y = sc.nextInt();

		System.out.println(gcd(x, y));
		sc.close();

	}
	private static int gcd(int x, int y) {
		int x_tmp = 0;

		do {
			x_tmp = x;

			x = y;
			y = x_tmp % y;

		}while(y > 0);

		return x;
	}

}


Measured memory_bytes: 26256
#include<map>
#include<set>
#include<cmath>
#include<climits>
#include<vector>
#include<queue>
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<unordered_map>
#define mod 1000000007
#define mo 998244353
using namespace std;
#define LL long long int
int main() 
{

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    LL N , x , M;
    cin >> N >> x >> M;
    vector<LL> arr;
    set<LL> hash;
    LL repeating=-1;
    while(hash.find(x)==hash.end())
    {
        arr.push_back(x) ;
        hash.insert(x);
        x=(x*x)%M;
    }
    repeating=x;
    if(arr.size() >=N )
    {
        LL sum=0;
        for(LL i=0;i<N;i++)
        {
            sum = (sum + arr[i]); 
        }
        cout<<sum<<endl;
    }
    else
    {
        LL s=0;
        for(auto it:arr)
            s+=it;
        LL sum = 0;
        bool ok = true;
        LL index= -1;
        for(LL i=0;i<arr.size();i++)
        {
            if(arr[i] == repeating)
            {
                ok=false;
                index=i;
                sum=arr[i];
            }
            else if(!ok)
            {
                sum+=arr[i];
            }
        }
        LL M=arr.size()-index;
        N=N-arr.size();
        s= s + sum*(N/M);
        for(LL i=index ;i<index+(N%M);i++)
        {
            s=  s+ arr[i];
        } 
        cout<<s<<endl;
    }
}


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

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



int main() {
	int N,an=0,m=0;
	cin >> N;
	vector<ll> vec(N);
	for (int i = 0; i < N; i++) {
		cin >> vec.at(i);
		if (m <= vec.at(i)) {
			an++;
			m = vec.at(i);
		}
	}
	


	cout << an << endl;

	
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split( )))

dp = [[0]*n for i in range(n)]

for i in range(n):#奇数偶数で最終手番は変わる
    dp[i][i] = a[i]

for d in range(1,n):
    for j in range(n-d):
        if d%2 == 1:#最後打たない方
            dp[j][j+d] = min(dp[j][j+d-1]-a[j+d],dp[j+1][j+d]-a[j])
        else:#最後打つ方
            dp[j][j+d] = max(dp[j][j+d-1]+a[j+d],dp[j+1][j+d]+a[j])
if n%2==1:
	 print(dp[0][n-1])
else:
  	print(-dp[0][n-1])

Measured memory_bytes: 113696
#include<iostream>
#include<vector>
#include<algorithm>
#include <queue>
#include<string>
#include<utility>
#include<iterator>

#define lli long long
#define all(i) i.begin(),i.end()
#define rall(i) i.rbegin(),i.rend()
#define rep0(i,j) for(lli i=0;i<j;i++)
#define rep1(i,j) for(lli i=1;i<=j;i++)
#define rep0d(i,j) for(lli i=j-1;i>=0;i--)
#define MAX 1000000007
typedef struct tree Tree;

using namespace std;

bool cmpf(pair<lli, lli> left, pair<lli, lli> right) {
	return left.first < right.first;
}

lli check(vector<lli>& vec, lli n,lli cmp, lli num) {
	if (num > 26)return -1;
	if (vec[n] == cmp)return 1;
	else return check(vec, vec[n], cmp, num + 1);
}

int main() {
	lli n, k;
	cin >> n >> k;
	
	if (k % 2 == 0) {
		cout << ((n / (k / 2) - n / k) * (n / (k / 2) - n / k) * (n / (k / 2) - n / k) + (n / k) * (n / k) * (n / k));
	}
	else {
		cout << (n / k) * (n / k) * (n / k);
	}
}


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

using namespace std;

int main() {
	int x[4], y[4];

	for (int i = 0; i < 2; i++) {
		cin >> x[i] >> y[i];
	}

	for (int i = 2; i < 4; i++) {
		int disX = x[i - 1] - x[i - 2];
		int disY = y[i - 1] - y[i - 2];

		// cout << "disX : " << disX << ", disY : " << disY << endl;

		if (disX > 0 && disY > 0) {
			// 右上 -> 左上
			swap(disX, disY);
			disX *= -1;
		}
		else if (disX < 0 && disY > 0) {
			// 左上 -> 左下
			swap(disX, disY);
			disX *= -1;
		}
		else if (disX < 0 && disY < 0) {
			// 左下 -> 右下
			swap(disX, disY);
			disX *= -1;
		}
		else if (disX > 0 && disY < 0) {
			// 右下 -> 右上
			swap(disX, disY);
			disX *= -1;
		}
		else if (disX == 0 && disY > 0) {
			// 上 -> 左
			swap(disX, disY);
			disX *= -1;
		}
		else if (disX < 0 && disY == 0) {
			// 左 -> 下
			swap(disX, disY);
		}
		else if (disX == 0 && disY < 0) {
			// 下 -> 右
			swap(disX, disY);
			disX *= -1;
		}
		else if (disX > 0 && disY == 0) {
			// 右 -> 上
			swap(disX, disY);
		}

		x[i] = x[i - 1] + disX;
		y[i] = y[i - 1] + disY;
	}

	cout << x[2] << " " << y[2] << " " << x[3] << " " << y[3] << endl;

	return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  int n, a, tmp;
  long long ans=0;
  cin >> n >> a;
  if(a){
    cout << -1 << endl;
  }
  else{
    for(int i=1; i<n; i++, a=tmp){
      cin >> tmp;
      if(tmp<=a){
        ans += tmp;
      }
      else if(tmp==a+1){
        ans += 1;
      }
      else{
        ans = -1;
        break;
      }
    }
    cout << ans << endl;
  }
}

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

using ld = long double;
using point = std::complex<ld>;
using polygon = std::vector<point>;

constexpr ld eps = 1e-10;
constexpr ld pi = std::acos(-1.0);

bool comp(point a, point b) {
    return std::real(a) < std::real(b) || (std::real(a) <= std::real(b) && std::imag(a) < std::imag(b));
}

std::vector<point> unique(std::vector<point> ps) {
    std::sort(std::begin(ps), std::end(ps), comp);
    std::vector<point> res;
    for(auto& p : ps) {
        if(res.empty() || abs(res.back() - p) > eps) {
            res.push_back(p);
        }
    }
    return res;
}

ld dot(point const& a, point const& b) {
    return std::real(std::conj(a) * b);
}
ld cross(point const& a, point const& b) {
    return std::imag(std::conj(a) * b);
}

int ccw(point a, point b, point c) {
    b -= a; c -= a;
    if(cross(b, c) > eps) return 1;            // a -> b -> c : counterclockwise
    if(cross(b, c) < -eps) return -1;          // a -> b -> c : clockwise
    if(dot(b, c) < 0) return 2;                // c -> a -> b : line
    if(std::norm(b) < std::norm(c)) return -2; // a -> b -> c : line
    return 0;                                  // a -> c -> b : line
}

struct segment {
    segment() : a(0, 0), b(0, 0) {}
    segment(point a, point b) : a(a), b(b) {}
    point a, b;
};

struct line {
    line() : a(0, 0), b(0, 0) {}
    line(point a, point b) : a(a), b(b) {}
    line(segment s) : a(s.a), b(s.b) {}
    point a, b;
};


bool isis_ll(line l, line m) {
    return cross(l.b - l.a, m.b - m.a) < eps;
}

bool isis_ls(line l, segment s) {
    return (cross(l.b - l.a, s.a - l.a) * cross(l.b - l.a, s.b - l.a) < eps);
}

bool isis_lp(line l, point p) {
    return (std::abs(cross(l.b - p, l.a - p)) < eps);
}

bool isis_sp(segment s, point p) {
    return (std::abs(s.a - p) + std::abs(s.b - p) - std::abs(s.b - s.a) < eps);
}

bool isis_ss(segment s, segment t) {
    return ccw(s.a, s.b, t.a) * ccw(s.a, s.b, t.b) <= 0
        && ccw(t.a, t.b, s.a) * ccw(t.a, t.b, s.b) <= 0;
}

point proj(line l, point p) {
    long double t = dot(p - l.a, l.a - l.b) / std::norm(l.a - l.b);
    return l.a + t * (l.a - l.b);
}

point is_ll(line s, line t) {
    point sv = s.b - s.a, tv = t.b - t.a;
    assert(cross(sv, tv) != 0);
    return s.a + sv * cross(tv, t.a - s.a) / cross(tv, sv);
}

point is_ss(segment s1, segment s2) {
    assert(isis_ss(s1, s2));
    point sv = s1.b - s1.a, tv = s2.b - s2.a;
    if(cross(sv, tv) == 0) {
        if(std::abs(s1.a - s2.a) < eps || std::abs(s1.a - s2.b) < eps) {
            return s1.a;
        } else {
            return s1.b;
        }
    } else {
        return is_ll(line(s1), line(s2));
    }
}

using namespace std;

int main() {
    int q;
    cin >> q;
    while(q--) {
        vector<segment> segs(2);
        for(int i = 0; i < 2; ++i) {
            ld x1, y1, x2, y2;
            cin >> x1 >> y1 >> x2 >> y2;
            segs[i] = segment(point(x1, y1), point(x2, y2));
        }
        cout << isis_ss(segs[0], segs[1]) << endl;
    }
}



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


int main(){
  int N;
  vector<int> A(110);

  cin >> N;

  bool flag = true;
  for(int i=0; i<N; i++){
    cin >> A[i];
    if(A[i] % 2 == 0 && A[i] % 3 != 0 && A[i] % 5 != 0) flag = false;
  }

  if(flag){
    cout << "APPROVED" << endl;
  } else {
    cout << "DENIED" << endl;
  }

}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Scanner;

import org.omg.CORBA.IntHolder;

// ?????°???
// shell sort
public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		int[] A = new int[N];
		for (int i = 0; i < N; i++) {
			A[i] = scan.nextInt();
		}
		shellSort(A, N);
		for (int i = 0; i < A.length; i++) {
			System.out.println(A[i]);
		}
		scan.close();
	}

	static int cnt = 0;

	public static void shellSort(int[] A, int N) {
		// G(n+1)=3G(n)+1 n=0,1,2,,,



		//int[] G = new int[max];
		


//		for (int i = 0; ; i++) {
//			
//			//G[i] = 3 * h + 1;
//			//h = G[i];
//			//G[i] = max - 3*i;
//			
//			temp[index] = 3 * h + 1;
//			h = temp[index];
//			index++;
//			if (h > N) {
//				break;
//			}
//		}
		ArrayList<Integer> list = new ArrayList<>();
		int h = 1;
		do{
			list.add(h);
			h = 3 * h + 1;
		}while(N > h);
		
		int[] G = new int[list.size()];
		for (int i = 0; i < G.length; i++) {
			G[i] = list.get(i);
		}
		int max = G.length;
		System.out.println(max);
		
		for (int i = G.length - 1; i >= 0; i--) {
			// ??????
			System.out.print(G[i]);
			if (i != 0) {
				System.out.print(" ");
			} else {
				System.out.println();
			}
			insertionSort(A, N, G[i]);
		}
		System.out.println(cnt);
	}

	public static void insertionSort(int[] A, int N, int g) {

		for (int i = g; i < N; i++) {
			int v = A[i];
			int j = i - g;
			// ?????§???????????????????????°???????????????????????\????????????????????????????????§??????
			while (j >= 0 && A[j] > v) {
				A[j + g] = A[j];
				j -= g;
				cnt++;
			}
			A[j + g] = v;
		}
	}
}

Measured memory_bytes: 299484
import java.util.Scanner;


public class Main {

    public static void find(final String s, final long k) {
        if (s.length() == 1) {
            System.out.println(s.charAt(0));
            return;
        }
        if (s.charAt(0) == '1') {
            if (k <= 1) {
                System.out.println(1);
            } else {
                find(s.substring(1), k - 1);
            }
        } else {
            System.out.println(s.charAt(0));
        }
    }

    public static void main(String[] args){
        final Scanner sc = new Scanner(System.in);
        final String s = sc.next();
        final long k = sc.nextLong();
        find(s, k);
    }
}


Measured memory_bytes: 23892