akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>

int main(void)
{
	int n1, n2, n3;

	scanf("%d %d %d", &n1, &n2, &n3);

	if(n1 + n2 + n3 == 17 && n1 * n2 * n3 == 175){
		puts("YES");
	}else{
		puts("NO");
	}
	return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define NMAX 100000
#define INF 1e+6
#define scan(arg) cin>>arg
#define prin(arg) cout<<arg<<"\n"
#define prin2(arg1,arg2) cout<<arg1<<" "<<arg2<<"\n"
using namespace std;
typedef long long ll;
int n,k;
int x[100010],y[100010];
char c[100010];
/****二次元累積和********/
int a[2010][2010];
int s[2010][2010];
void acc_sum2(){//二次元累積和 O(n*m)
  rep(i,2*k+1){
    s[i][0]=0;
  }
  rep(i,2*k+1){
    s[0][i]=0;
  }
  rep1(i,2*k){
    rep1(j,2*k){
      s[i][j]=s[i-1][j]+s[i][j-1]+a[i-1][j-1]-s[i-1][j-1];
    }
  }
}
int sec_sum2(int xl,int xr,int yl,int yr){
  if(0<=xl&&xl<=xr&&0<=yl&&yl<=yr){
    return s[xr+1][yr+1]-s[xr+1][yl]-s[xl][yr+1]+s[xl][yl];
  }
  return 0;
}
/**********/
int main(){
  scan(n);scan(k);
  rep(i,n){
    scan(x[i]);scan(y[i]);scan(c[i]);
  }
  rep(i,n){
    if(c[i]=='W'){
      y[i]+=k;
    }
  }
  rep(i,n){
    x[i]%=(2*k);
    y[i]%=(2*k);
  }
  rep(i,2*k){
    rep(j,2*k){
      a[i][j]=0;
    }
  }
  rep(i,n){
    a[x[i]][y[i]]++;
  }
  /*  rep(i,2*k){
    rep(j,2*k){
      cout<<a[j][2*k-1-i]<<" ";
    }
    cout<<"\n";
    }*/
  acc_sum2();
  int ans=0;
  rep(i,k){
    rep(j,k){
      int sum=0;
      sum+=sec_sum2(i,k-1+i,j,k-1+j)+sec_sum2(0,i-1,0,j-1)+sec_sum2(i+k,2*k-1,0,j-1)+sec_sum2(0,i-1,j+k,2*k-1)+sec_sum2(i+k,2*k-1,j+k,2*k-1);
      sum=max(sum,n-sum);
      ans=max(ans,sum);
    }
  }
  prin(ans);

  /*  rep(i,2*k+1){
    rep(j,2*k+1){
      cout<<s[j][2*k-i]<<" ";
    }
    cout<<"\n";
    }*/
      


  

  return 0;
}


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

int main(){
    int a,b,c,ans=0;
    scanf("%d %d %d",&a,&b,&c);
    for (int i=a;i<=b;i++) if (c%i==0) ans++;
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 3228
#include <iostream>  
using namespace std;
long long n,a,b,x=0;
int main() 
{
	cin>>n>>a>>b;
	if(n>1&&b>=a||n==1&&b==a)
		cout<<(n-2)*(b-a)+1<<endl;
	else
		cout<<x<<endl ;
	return 0;
}

Measured memory_bytes: 256
import sys
from collections import Counter


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


sys.setrecursionlimit(20000000)

MOD = 10 ** 9 + 7
INF = float("inf")


def main():
    N = int(input())
    D = list(map(int, input().split()))
    D.append(0)

    count = Counter(D)
    items = count.items()
    times = []
    times_def = []

    for k, v in items:
        if k == 0:
            if v >= 2:
                print(0)
                return
            else:
                times_def.append(0)

        elif k == 12:
            if v >= 2:
                print(0)
                return
            else:
                times_def.append(12)

        elif v == 2:
            times_def.append(24 - k)
            times_def.append(k)

        elif v >= 3:
            print(0)
            return

        else:
            times.append(k)
            continue
    answer = []
    for i in range(2 ** (len(times)) + 1):
        d = []
        ans = INF
        for j in range(len(times)):
            if (i >> j) & 1:
                d.append(24 - times[j])
            else:
                d.append(times[j])
        t = times_def + d
        # print(len(t))
        # print(t)
        for a in range(N):
            for b in range(a + 1, N + 1):
                diff = min(abs(t[a] - t[b]), 24 - (abs(t[a] - t[b])))
                if diff < ans:
                    ans = diff
        answer.append(ans)
    print(max(answer))


if __name__ == "__main__":
    main()


Measured memory_bytes: 3436
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import math

# NO, PAY-PAY
#import numpy as np
#import statistics
#from statistics import mean, median,variance,stdev


def main():
	N = int(input())
	abc = []
	for i in range(N):
		a,b,c = map(int, input().split(" "))
		abc.append((a,b,c))
		
	DP = [[0 for _ in range(3)] for _ in range(N)]
	
	for i, val in enumerate(abc):
		a, b, c = val
		if i == 0:
			DP[i][0] = a
			DP[i][1] = b
			DP[i][2] = c
			continue
		DP[i][0] = max(DP[i-1][1] + a, DP[i-1][2] + a)
		DP[i][1] = max(DP[i-1][0] + b, DP[i-1][2] + b)
		DP[i][2] = max(DP[i-1][0] + c, DP[i-1][1] + c)
		
	print(max(DP[N-1][0], DP[N-1][1], DP[N-1][2]))
	
	
	
if __name__ == "__main__":
	main()


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

class Program {
    internal static void Main(string[] args) {
        var inp = ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
        Array.Sort(inp);

        WriteLine(Math.Abs(inp[1] - inp[0]) + Math.Abs(inp[2] - inp[1]));

    }
}

Measured memory_bytes: 13396
#include <stdio.h>
int main() {
   int a, b;
   scanf("%d %d", &a, &b);
    
   if(a == b){
      for(int i = 0; i < a; i++){
         printf("%d", a);
      }
   }else if(a > b){
      for(int i = 0; i < a; i++){
         printf("%d", b);
      }
   }else if(a < b){
      for(int i = 0; i < b; i++){
         printf("%d", a);
      }
   }
   printf("\n");
   return 0;
}

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

int main(void) {
  int N;
  string S;
  cin >> N >> S;
  
  for(int i=0; i<S.size(); i++){
    S[i] += N;
    if(int(S[i]) > 90) S[i] -= 26;
  }
  
  cout << S << endl;
  
  return 0;
}

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


int main(){
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    a--;
    cout<<(b-b/c-b/d+b/(c*d/__gcd(c,d)))-(a-a/c-a/d+a/(c*d/__gcd(c,d)));
    return 0;
}

Measured memory_bytes: 256
#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[i];
  }

  double total = 0;

  for(int i=0;i<N;i++) {
    total += (1.0 / A[i]);
  }

  cout << setprecision(20) << 1.0 / total << endl;
}

Measured memory_bytes: 256
x = int(input())
ans = []
while x>0:
	tmp = x%26
	ans.append(tmp)
	if tmp==0:
		x -= 26
	else:
		x -= tmp
	x //= 26

l = len(ans)
for i in range(l-1):
	if ans[l-i-1]==0:
		print('z',end="")
	else:
		print(chr(ord('a')+ans[l-i-1]-1),end="")

if ans[0]==0:
	print('z')
else:
	print(chr(ord('a')+ans[0]-1))

Measured memory_bytes: 9076
a,b=gets.split.map &:to_i
s=[]
y=[]
a.times{|i|s[i],y[i]=gets.split.map &:to_i}
ans=s.zip(y).sort
hai=0
kai=0
ans.each{|x|
  if x[1]<=b
    kai=x[0]
    hai=1
    break
  end
}
puts hai==1 ? kai: "TLE"


Measured memory_bytes: 14384
from collections import defaultdict
import sys
sys.setrecursionlimit(1000000)

d = defaultdict(list)
cost = defaultdict(int)
N = int(input())

for _ in range(N-1):
    u, v, w = map(int, input().split())
    d[u].append(v)
    d[v].append(u)
    cost[(u, v)] = w

visited = [False]*(N+1)
color = [-1]*(N+1)
color[1] = 0

def dfs(x):
    visited[x]=True
    for y in d[x]:
        if visited[y]:continue
        c = cost[(x, y) if x<y else (y, x)]
        color[y] = color[x]^1 if c%2 else color[x]  
        dfs(y)

dfs(1)
print(*color[1:], sep="\n")

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

#define forn(i,m,n) for(int i=m;i<n;i++)
#define vv vector
#define vi vv<int>
#define ii pair<int,int>
#define vii vv<ii>
#define mp make_pair
#define pb push_back
#define PI 3.141592653589
#define ll long long
#define pll pair<ll,ll>
#define vl vv<ll>
#define ff first
#define ss second
#define MOD 1000000007

bool is_prime[1000001];
vi prime;
void sieve(int n)
{
    memset(is_prime,true,sizeof(is_prime));
    for(int i=2;i*i<=n;i++)
    {
        if(is_prime[i])
        {
            for(int j=i*i;j<=n;j+=i)
            {
                is_prime[j]=false;
            }
        }
    }
    forn(i,2,n+1)
    {
        if(is_prime[i])
            prime.pb(i);
    }
}


ll ex(ll a,ll b)
{
    ll res=1;
    a=a%MOD;
    while(b)
    {
        if(b%2){res=(res*a)%MOD;b--;}
        b/=2;
        a=(a*a)%MOD;
    }
    return res;
}

ll fermat_inv(ll a){ return ex(a,MOD-2); }



int main()
{
    ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        #ifndef ONLINE_JUDGE
            freopen("input.txt", "r", stdin);
            freopen("output.txt", "w", stdout);
        #endif
    //sieve(1000000);
    int te=1;
    //cin>>te;
    while(te--)
    {

        
        int n,k;
        cin>>n>>k;
        int a[n];
        forn(i,0,n)
        {
            cin>>a[i];
        }
        int dp[n];
        dp[0]=0;
        dp[1]=abs(a[0]-a[1]);
        forn(i,2,n)
        {
            dp[i]=INT_MAX;
            int l=min(k,i);
            forn(j,1,l+1)
                dp[i]=min(dp[i],dp[i-j]+abs(a[i]-a[i-j]));
        }
        cout<<dp[n-1];
    }
}


Measured memory_bytes: 4360
#include <stdio.h>

int main(void)
{

  int a,b,c;
  
  scanf("%d %d %d",&a ,&b ,&c);

  if(a < b && b < c) printf("%d %d %d\n",a ,b ,c);
  else if(a <= c && c <= b) printf("%d %d %d\n",a ,c ,b);
  else if(b <= a && a <= c) printf("%d %d %d\n",b ,a ,c);
  else if(b <= c && c <= a) printf("%d %d %d\n",b ,c ,a);
  else if(c <= a && a <= b) printf("%d %d %d\n",c ,a ,b);
  else if(c <= b && b <= a) printf("%d %d %d\n",c ,b ,a);

  return 0;

}

Measured memory_bytes: 596
#!/usr/bin/env python3
import sys


def solve(K: int, S: int):
    cnt=0
    x_max = S if K >= S else K
    for x in range(0, x_max+1):
        y_max = S-x if K >= S-x else K
        for y in range(0, y_max+1):
            z = S - x - y
            if z <= K:
                cnt+=1
    return cnt


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

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
package main

import (
        "bufio"
        "fmt"
        "log"
        "os"
        "strconv"
        "strings"
)

func main() {
        rd := bufio.NewReader(os.Stdin)
        line, err := rd.ReadString('\n')
        if err != nil {
                log.Fatal(err)
        }
        val, err := strconv.ParseInt(strings.Trim(line, "\n"), 10, 32)
        if err != nil {
                log.Fatal(err)
        }
        val = val * val * val
        fmt.Println(val)
}



Measured memory_bytes: 1112
#include<cstdio>
using namespace std;

int K, N;
int A[100000];
int One;

int main() {
  scanf("%d%d", &N, &K);
  for (int i = 0; i < N; i++) {
    scanf("%d", &A[i]);
    if (A[i] == 1) One = i;
  }
  int ans = One / (K - 1);
  if (One % (K - 1) != 0) ans++;
  int temp = N - ans * (K - 1) - 1;
  if (temp >= 0) {
    ans += temp / (K - 1);
    if (temp % (K - 1) != 0) ans++;
  }
  printf("%d\n", ans);
}


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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

int n,k;
int h[125252], s[125252], p[125252], l[125252];
vi children[125252];

ll arr[125][125252];
ll beg[125252];

ll tmp[125252];

int di[125252];
ll dv[125252];

void lk(ll *v, ll a, ll n, ll *ret){
  REP(i,k+1)ret[i] = v[i];
  int s = 0, t = 0;
  REP(i,k+1){
    ll v = ret[i] - i*a;
    while(s<t && dv[t-1] <= v)t--;
    di[t] = i;
    dv[t] = v;
    t++;
    ret[i] = dv[s] + i*a;
    if(di[s] == i-n)s++;
  }
}

void dfs(int p, ll *iv){
  // use s[p], max h[p]
  lk(iv, s[p], h[p], arr[p]);
  // children
  for(int c : children[p]){
    dfs(c, iv);
    iv = arr[c];
    ll adv = (ll)l[c] * s[p];
    lk(iv, s[p], h[p]-l[c], tmp);
    REP(i,k+1-l[c])CHMAX(arr[p][i+l[c]], tmp[i]+adv);
  }
}

int main(){
  while(true){
    scanf("%d%d", &n, &k);
    if(n==0 && k==0)break;
    REP(i,n)scanf("%d",h+i);
    REP(i,n)scanf("%d",s+i);
    FOR(i,1,n)scanf("%d",p+i), p[i]--;
    FOR(i,1,n)scanf("%d",l+i);
    p[0] = -1;
    REP(i,n)children[i].clear();
    FOR(i,1,n)children[p[i]].push_back(i);
    REP(i,n)sort(ALL(children[i]),[&](int a,int b){
      return l[a] < l[b];
    });
    REP(i,k+1)beg[i]=-1ll<<60;
    beg[0] = 0;
    dfs(0, beg);
    printf("%lld\n",*max_element(arr[0],arr[0]+k+1));
    // fflush(stdout);
  }
  return 0;
}



Measured memory_bytes: 87452
import math
A, B, C, D = map(int, input().split())

c = (B//C) - ((A+C-1)//C) + 1
d = (B//D) - ((A+D-1)//D) + 1
lcm = int(C * D / math.gcd(C, D))
m = (B//lcm) - ((A+lcm-1)//lcm) + 1
ans = (B-A+1) - (c+d-m)
print(int(ans))

Measured memory_bytes: 9132
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
//ll a[200007], b[200007];
//ll m[30][(2 * 100000)+7], M[200];
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	ll i, j, k, l, test, r, a, b, c, d;
	ll n;
	cin >> n;
	map<string, ll> m;
	ll count = 0;
	while (n--) {
		string a;
		cin >> a;
		if (m[a] == 0) {
			m[a] = 1;
			count++;
		}
	}
	cout << count << "\n";
}



Measured memory_bytes: 19288
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <cctype>
#include <cmath>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <stdio.h>
#include <string.h>
#include <cstdlib>
#include <math.h>
#include <bitset>
#include <iterator>	
#include <iomanip>
#include <sstream>
#include <numeric>
#include <cassert>
#define INF 2000000000
#define MOD 1000000007
#define sym cout<<"---------"<<endl;
#define ll long long
#define mk make_pair
#define en endl
#define RE return 0
#define int ll
#define P pair<int,int>
using namespace std;
int dx[5]={1,0,-1,0,0},dy[5]={0,1,0,-1,0};
int gcd(int a,int b){if(a%b==0){return b;}else return gcd(b,a%b);}
int lcm(int a,int b){if(a==0){return b;} return a/gcd(a,b)*b;}

int n;
int a[2005];
int dp[2005][2005];

int calc(int l,int r,int s){
	if(~dp[l][r]) return dp[l][r];
	if(l==r){
		if(s) return dp[l][r]=0;
		return dp[l][r]=a[l];
	}
	if(s){
		if(a[l]>a[r]){
			return dp[l][r]=calc((l+1)%n, r, 0);
		}else{
			return dp[l][r]=calc(l, (r+n-1)%n, 0);
		}
	}
	return dp[l][r]=max(calc((l+1)%n, r, 1)+a[l],calc(l, (r+n-1)%n, 1)+a[r]);
}

signed main(){
	cin>>n;
	for(int i=0; i<n; i++) cin>>a[i];
	
	for(int i=0; i<2001; i++) for(int j=0; j<2001; j++) dp[i][j]=-1;
	int ret=0;
	for(int i=0; i<n; i++){
		ret=max(ret, calc((i+1)%n, (i+n-1)%n, 1)+a[i]);
	}
	cout<<ret<<en;
}
	
	


Measured memory_bytes: 34488
N = int(raw_input())
T = [0]
X = [0]
Y = [0]
for i in range(N):
  t, x, y = map(int, raw_input().split())
  T.append(t)
  X.append(x)
  Y.append(y)
ret = "Yes"
for i in range(N):
  d = abs(X[i+1]-X[i]) + abs(Y[i+1]-Y[i])
  dt = T[i+1]-T[i]
  if d > dt or (dt-d)%2==1:
    ret = "No"
print ret

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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

struct edge {
    int from, to;
    ll cost;
};

class Dijkstra {
    int V;
    vector<vector<edge>> edges;
    vector<ll> dist;
    vector<ll> prev;
    vector<ll> route_cnt;

public:
    Dijkstra(int v) : V(v) {
        edges.resize(V);
        dist.resize(V, INF);
        prev.resize(V, INF);
        route_cnt.resize(V, 0);
    }

    void add_edge(int from, int to, ll cost) {
        edges[from].push_back({from, to, cost});
    }

    /**
     * @param goal 0-indexed
     * @return return cost to reach the goal. return INF if the goal is unreachable.
     */
    ll get_cost(int goal) {
        return dist[goal];
    }

    ll get_route_cnt(ll goal) {
        return route_cnt[goal];
    }

    void exec(int start) {
        dist[start] = 0;
        route_cnt[start] = 1;
        priority_queue<P, vector<P>, greater<>> queue;
        queue.push({dist[start], start});
        while (!queue.empty()) {
            P p = queue.top();
            queue.pop();
            ll prev_cost = p.first;
            ll src = p.second;
            if (dist[src] < prev_cost) continue;

            for (edge &e : edges[src]) {
                ll to = e.to;
                ll cost = e.cost;
                if (cost != INF && dist[to] > dist[src] + cost) {
                    dist[to] = dist[src] + cost;
                    queue.push({dist[to], to});
                    prev[to] = src;
                }
                if (dist[to] == dist[src] + cost) {
                    route_cnt[to] += route_cnt[src];
                }
            }
        }
    }
};

void Main() {
    int H, W;
    cin >> H >> W;
    vector<string> grid(H);
    rep(i, H) cin >> grid[i];
    Dijkstra dijkstra(H * W+1000);
    ll cnt = 0;
    rep(i, H) {
        rep(j, W) {
            if (grid[i][j] == '#') continue;
            else cnt++;
            rep(d, 4) {
                int x = dx[d];
                int y = dy[d];
                if (0 <= i + y && i + y <= H - 1 && 0 <= j + x && j + x <= W - 1 && grid[i + y][j + x] != '#') {
                    dijkstra.add_edge(i * W + j, (i + y) * W + (j + x), 1);
                }
            }
        }
    }
    dijkstra.exec(0);
    ll ans = dijkstra.get_cost(H * W - 1);
    if (ans == INF) {
        cout << -1 << '\n';
    } else {
        cout << cnt - (ans + 1) << '\n';
    }

}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}


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

using namespace std;

#define ll long long
#define pb push_back
#define fi first
#define se second

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

    int n;
    cin >> n;
    set<string> st;
    for(int i = 0; i < n; i++)
    {
        string s;
        cin >> s;
        st.insert(s);
    }

    cout << st.size();

    return 0;
}


Measured memory_bytes: 19152
#include<bits/stdc++.h>
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define MOD 1000000007
#define EPS (1e-10)
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef pair<int, int>P;

int a[100000], cnt[100000], d[100000];//iが試合をした回数
vector<int>E[100000];

int dfs(int u) {
	vector<int>V;
	for (int v : E[u]) {
		V.push_back(dfs(v));
	}
	sort(V.begin(), V.end(), greater<>());
	int a = 1;
	int res = 0;
	for (int t : V) {
		res = max(res, a + t);
		a++;
	}
	return d[u] = res;
}
signed main() {
	int n; scanf("%d", &n);
	for (int i = 1; i < n; i++) {
		cnt[i]++;//負けた回数分
		scanf("%d", &a[i]); a[i]--;
		cnt[a[i]]++; E[a[i]].push_back(i);
	}
	printf("%d\n", dfs(0));
}

Measured memory_bytes: 16256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <algorithm>
using namespace std;

int H, W;
int n;
int a[10005];
int ans[105][105];
int main()
{
	while(scanf("%d %d", &H, &W) != EOF)
	{
		scanf("%d", &n);
		for(int i = 1; i <= n; i++) 
			scanf("%d", &a[i]);
		int now = 1;
		int cnt = 0;
		for(int i = 1; i <= H; i++) {
			if(i & 1) {
				for(int j = 1; j <= W; j++) {
					cnt++;
					ans[i][j] = now;
					if(cnt == a[now]) {
						now++;
						cnt = 0;
					}
				}
			}
			else {
				for(int j = W; j >= 1; j--){ 
					cnt++;
					ans[i][j] = now;
					if(cnt == a[now]) {
						cnt = 0;
						now++;
					}
				}
			}
		}
		for(int i = 1; i <= H; i++) {
			for(int j = 1; j <= W; j++) {
				if(j == 1) printf("%d", ans[i][j]);
				else printf(" %d", ans[i][j]);
			}
			printf("\n");
		}
		memset(a, 0, sizeof(a));
		memset(ans, 0, sizeof(ans));
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define SORT(x) sort(x.begin(),x.end())
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000000
#define mod 1000000007
typedef long long ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
int main(){
    int n,k;
    cin>>n>>k;
    if(k>(n-2)*(n-1)/2){
        cout<<-1<<endl;return 0;
    }
    vector<pair<int,int>> ans;
    int edgeOf2=(n-2)*(n-1)/2;
    for(int i=2;i<=n;i++)   ans.push_back(make_pair(1,i));
    int a=2,b=3;
    while(edgeOf2>k){
        ans.push_back(make_pair(a,b));
        edgeOf2--;
        b++;
        if(b>n){
            a++;b=a+1;
        }
    }
    cout<<ans.size()<<endl;
    rep(i,ans.size()){
        cout<<ans[i].first<<' '<<ans[i].second<<endl;
    }
    return 0;
}


Measured memory_bytes: 384
// 1こずつ無視したとしたときの全探索
package main

import "fmt"

type Edge struct {
	A, B int
}

func main() {
	var N, M int
	fmt.Scan(&N, &M)
	E := make([]Edge, M)
	for i := 0; i < M; i++ {
		var A, B int
		fmt.Scan(&A, &B)
		E[i] = Edge{A: A, B: B}
	}
	ans := 0
	for i := 0; i < M; i++ {
		T := make([][]int, N+1)
		for j := 0; j < N+1; j++ {
			T[j] = []int{}
		}
		for j := 0; j < M; j++ {
			if i == j {
				continue
			}
			T[E[j].A] = append(T[E[j].A], E[j].B)
			T[E[j].B] = append(T[E[j].B], E[j].A)
		}
		used := make(map[int]bool)
		queue := []int{1}
		used[1] = true
		for len(queue) > 0 {
			cur := queue[len(queue)-1]
			queue = queue[:len(queue)-1]
			for _, nex := range T[cur] {
				if _, ok := used[nex]; !ok {
					used[nex] = true
					queue = append(queue, nex)
				}
			}
		}
		if len(used) != N {
			ans++
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 768
import math
class segment_tree:
    
    # self.table is 1-indexed
    # math.log2 not implemented 3.2.3
    def __init__(self, dat, query, default=0):
        self.offset = 2 ** math.ceil(math.log(len(dat), 2))
        self.table = [default] * self.offset + dat + [default] * (self.offset - len(dat))
        self.query = query
        for i in reversed(range(1, self.offset)):
            self.table[i] = self.query(self.table[2 * i], self.table[2 * i + 1])

    # [l, r] closed-interval
    def find(self, l, r):
        return self.query(self.__range(l,r))

    def __range(self, l, r):
        l += self.offset
        r += self.offset
        while l <= r:
            if l & 1:
                yield self.table[l]
                l += 1
            l >>= 1
            if r & 1 == 0:
                yield self.table[r]
                r -= 1
            r >>= 1
        
    def update(self, i, x):
        i += self.offset
        self.table[i] = x
        while 1 < i:
            i >>= 1
            self.table[i] = self.query(self.table[2 * i], self.table[2 * i + 1])

import sys
f = sys.stdin

n, q = map(int, f.readline().split())

rmq = segment_tree([(1 << 31) - 1] * n, min, float('inf'))

function = (rmq.update, lambda x, y:print(rmq.find(x, y)))
for com, x, y in (map(int, f.readline().split()) for _ in range(q)):
    function[com](x, y)

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

int main(){

    while(true){
            
    int a, b;
    string op;
    
        cin >> a >> op >> b;
        
        if(op == "?") break;
        
        int r;
        
        if(op == "+") r = a + b;
        if(op == "-") r = a - b;
        if(op == "*") r = a * b;
        if(op == "/") r = a / b;
        
        cout << r << endl;
    }
    
    
    return 0;
}


Measured memory_bytes: 3172
using System;

class MainClass
{
	public static void Main (string[] args)
	{
		string str = Console.ReadLine ();
		string[]spStr = str.Split(' ');

		int a = int.Parse (spStr[0]);
		int b = int.Parse (spStr[1]);

		int d = a / b;
		int r = a % b;
		double f = (double)a/ b;

		string s = f.ToString("0.#########");

		Console.WriteLine (d + " " + r + " " + s);
	}
}

Measured memory_bytes: 9340
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define o(a) cout << a << endl
#define int long long
#define fi first
#define se second
using namespace std;
typedef pair<int, int> P;

int n, k;
vector<int> a;

bool check(int m){
    bool dp[5010];
    memset(dp, 0, sizeof(dp));
    dp[0] = true;
    rep(i, 0, n){
        if(i == m) continue;
        repb(j, 5000, 0){
            if(j - a[i] >= 0){
                dp[j] |= dp[j - a[i]];
            }
        }
    }
    rep(i, max((int)0, k - a[m]), k) if(dp[i]) return true;
    return false;
}

signed main(){
    cin >> n >> k;
    a.resize(n);
    bool f = true;
    rep(i, 0, n){
        cin >> a[i];
    }
    sort(all(a));
    int ng = -1, ok = n, m;
    while(ok - ng > 1){
        m = (ok + ng) / 2;
        if(check(m)) ok = m;
        else ng = m;
    }
    cout << ng + 1 << endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
  char s[10010];
  cin >> n;
  cin >> s;
  int len = strlen(s);
  for (int i = 0; i < len; i++) {
    int x = s[i] -'A';
    x = (x + n) % 26;
    cout << char('A' + x);
  }
  cout << endl;
}

Measured memory_bytes: 3648
from collections import deque
n=int(input())
a=deque([int(i) for i in input().split()])
b=deque()

if n%2==0:
    for i in range(n):
        if i % 2 == 0:
            b.append(a.popleft())
        else:
            b.appendleft(a.popleft())
else:
    for i in range(n):
        if i % 2 == 0:
            b.appendleft(a.popleft())
        else:
            b.append(a.popleft())
print(*b)

Measured memory_bytes: 100888
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
using namespace std;

void solve(){
  char c; cin >> c;
  if(c == 'S') cout << "Cloudy" << endl;
  else if(c == 'C') cout << "Rainy" << endl;
  else cout << "Sunny" << endl;
  return;
}

int main(){
  solve();
  return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
mod = 10**9 + 7
n, k = [int(x) for x in input().split()]
red = n - k
blue = k

def make_tables(n, mod = 10 ** 9 + 7):
    fac = [1, 1] # 階乗テーブル
    finv = [1, 1] #逆元の階乗テーブル
    inv = [0, 1] #逆元テーブル

    for i in range(2, n + 1):
        fac.append((fac[-1] * i) % mod)
        inv.append((mod -inv[mod % i] * (mod // i)) % mod)
        finv.append((finv[-1] * inv[-1]) % mod)
    return fac, finv

def nCk(n, k, mod = 10 ** 9 + 7):
    k = min(k, n-k)
    return fac[n] * finv[k] * finv[n-k] % mod

fac, finv = make_tables(n)

for i in range(1, k + 1):
    red_, blue_ = red, blue
    red_ -= (i - 1)
    blue_ -= i
    if red_ < 0 or blue_ < 0:
        print(0)
        continue
    ans = nCk(blue_ + i - 1, i - 1) * nCk(red_ + i, i)
    print(ans % mod)
    




Measured memory_bytes: 42480
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
#define tr(it, a) for (auto it = a.begin(); it != a.end(); it++)
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define fo(i, n) for (int i = 0; i < n; i++)
#define Fo(i, k, n) for (int i = k; k < n ? i < n : i > n; k < n ? i += 1 : i -= 1)
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef pair<int, pair<int, int>> pipii;
typedef priority_queue<pii, vector<pii>, greater<pii>> minpq;
typedef priority_queue<pii> maxpq;
//const double PI = acos(-1);
const int mod = 1000000007;

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

template <typename T, typename V>
void __print(const pair<T, V> &x)
{
	cerr << '{';
	__print(x.first);
	cerr << ',';
	__print(x.second);
	cerr << '}';
}
template <typename T>
void __print(const T &x)
{
	int f = 0;
	cerr << '{';
	for (auto &i : x)
		cerr << (f++ ? "," : ""), __print(i);
	cerr << "}";
}
void _print() { cerr << "]\n"; }
template <typename T, typename... V>
void _print(T t, V... v)
{
	__print(t);
	if (sizeof...(v))
		cerr << ", ";
	_print(v...);
}
#ifndef ONLINE_JUDGE
#define debug(x...)               \
	cerr << "[" << #x << "] = ["; \
	_print(x)
#else
#define debug(x...)
#endif
// ----------------------DEBUG TEMPLATE--------------------------
#define N 3000
vector<double>heads(N),tails(N);
// double heads[N];
// double tails[N];
double dp[N][N];
double solve(int n){
	memset(dp,0.0,sizeof(dp));
	
	dp[0][0]=1.0;
	for(int i=1;i <=n;i++){
		dp[0][i]=dp[0][i-1]*tails[i];
	}
	for(int i =1;i <=n;i++){
		dp[i][i]=dp[i-1][i-1]*heads[i];
	}
	// debug(heads,tails);
	

	for(int col=2;col<=n;col++){
		int row = 1;
		while(row<col){
			dp[row][col] = dp[row-1][col-1]*heads[col] + dp[row][col-1]*tails[col];
			row++;
		}
	}
	// fo(i,n+1){
	// 	fo(j,n+1){
	// 		cout<<dp[i][j]<<" ";
	// 	}
	// 	cout<<endl;
	// }

	double ans=0;
	for(int i = ceil(n/2.0);i<=n;i++){
		ans+=dp[i][n];
	}
	return ans;	

}



int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int n;
	cin>>n;
	Fo(i,1,n+1){
		cin>>heads[i];
		tails[i] = 1-heads[i];
	}
	cout<<fixed<<setprecision(10)<<solve(n)<<endl;

}

Measured memory_bytes: 74204
#include<stdio.h>
int main(void)
{
	int s[11][11],d,f,g,h,i,j;
	long long int a;
	while(scanf("%ld",&a)!=EOF){
	for(i=10;i>=1;i--){
		s[1][i]=a%10;
		a=a/10;

	}
	f=10;
	for(j=1;j<=10;j++){
		for(i=1;i<=f;i++){
			s[j+1][i]=s[j][i]+s[j][i+1];
			s[j+1][i]=s[j+1][i]%10;
		//printf(" %d",s[j][i]);
		}
		//printf("\n");
		f--;
	}
	printf("%d\n",s[10][1]);
	}
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;
int main(void){
    // Here your code !
  int n;
  long long int S=0LL;
  cin>>n;
  vector<long int>a(n);
  for(int i=0;i<n;i++){
      cin>>a[i];
  }
  sort(&a[0],&a[n]);
  for(int i=0;i<n;i++){
      S+= a[i];
}
cout<<a[0]<<" "<<a[n-1]<<" "<<S<<endl;
}

Measured memory_bytes: 1296
from collections import deque
n = int(input())
route = [[] for i in range(n+1)]
for i in range(n-1):
    u , v , w = map(int,input().split())
    route[u].append((v,w))
    route[v].append((u,w))

ans = [-1 for i in range(n+1)]

d = deque()
d.append(1)
ans[1] = 0
while d:
    now = d.popleft()
    for i , j in route[now]:
        if ans[i] == -1:
            if j % 2 == 0:
                ans[i] = ans[now]
            elif j % 2 == 1:
                ans[i] = (ans[now]+1)%2
            d.append(i)

for i in range(1,n+1):
    print(ans[i])

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

//Ｏ(log(max(a,b))
// aとbの最大公約数
int gcd(int a, int b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}

// aとbの最小公倍数
int lcm(int a, int b) {
  int x = gcd(a, b);
  return (a / x) * b;
}

signed main() {
  int A, B;
  cin >> A >> B;
  cout << lcm(A, B) << endl;
  return 0;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
V = [[] for _ in range(N)]
ans = [0] * M

for i in range(M):
    p, y = map(int, input().split())
    V[p-1].append((y, i))

for i, v in enumerate(V, start=1):
    v.sort()
    for k, (y, j) in enumerate(v, start=1):
        ans[j] = format(str(i), "0>6") + format(str(k), "0>6")

for a in ans:
    print(a)

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

using namespace std;

int main(void){
    int n;

    cin >> n;
    vector<long long> a(n, 0);

    for(int i=0; i<n; i++)
        cin >> a[i];

    sort(a.begin(), a.end());

    for(int i=1; i<n; i++){
        if(a[i-1] == a[i]){
            cout << "NO";
            return 0;
        }
    }

    cout << "YES" << endl;

    return 0;
}

Measured memory_bytes: 1792
#include <iostream>
using namespace std;
int main(){
  int k,s,cnt=0;
  cin >> k>>s;
for(int i=0;i<=k;i++){
  for(int j=0;j<=k;j++){
    if(s-i-j<=k&&s-i-j>=0) cnt++;
  }
}
cout << cnt<<endl;
}


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

using namespace std;
using ll = long long;

#define REP(i, n) for (ll i = 0; i < n; i++)
#define INF 9223372036854775807
#define all(x) (x).begin(), (x).end()

ll ts = 1000000007;

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

  string o, e;
  cin >> o >> e;

  REP(i, o.size()) {
    cout << o[i];
    if (o.size() - e.size() == 1 && i == o.size() - 1) break;
    cout << e[i];
  }
  cout << "\n";
}

Measured memory_bytes: 384
/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

int main()
{
    ll a;
    cin>>a;
    cout<<a+(a*a)+(a*a*a);
    

    return 0;
}


Measured memory_bytes: 3620
n, k = map(int, input().split())
p = list(map(int, input().split()))
e = []
for i in range(n):
    e.append((p[i]+1)/2)
cumsum  = []
sm = 0
for j in range(n):
    sm += e[j]
    cumsum.append(sm)
ans = cumsum[k-1]
for i in range(n-k):
    s = cumsum[i+k] - cumsum[i]
    if ans < s:
        ans = s
print(ans)

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

int x, y;

int a1[] = {1, 3, 5, 7, 8, 9, 10, 12};
int a2[] = {4, 6, 9, 11};

int main() {
    cin >> x >> y;

    // group1
    int count_a1 = 0;
    for (int i = 0; i < 8; i++) {
        if (x == a1[i] || y == a1[i]) count_a1++; 
    }

    int count_a2 = 0;
    // group2
    for (int i = 0; i < 4; i++) {
        if (x == a2[i] || y == a2[i]) count_a2++; 
    }

    if (count_a1 == 2 || count_a2 == 2) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 256
N, M = map(int, (input().split()))
n = [0] * (N+1)
for i in range(M):
    n[int(input())] = True
f = [1]
for i in range(1, N+1):
    if n[i]:
        f.append(0)
    elif i == 1:
        f.append(f[0])
    else:
        f.append((f[i-1]+f[i-2])%(10**9+7))
print(f[N])


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

int32_t main(){
  int x;
  cin>>x;
  for(int a=-1000;a<=1000;a++){
    for(int b=-1000;b<=1000;b++){
      int a1 = a*a*a*a*a;
      int b1 = b*b*b*b*b;
      if(a1-b1 == x){
      	cout<<a<<" "<<b<<endl;
        return 0;
      }
    }
  }
}

Measured memory_bytes: 3636
#include <iostream>

 

using namespace std;

 

int main()
{
    int a, b;
    
    cin >> a >> b;
    if (a < b)
      cout << "a < b" << endl;
    else if (a > b)     
      cout << "a > b" << endl;
    else 
      cout << "a == b" << endl;
   
    return 0;
}


Measured memory_bytes: 3116
#include<bits/stdc++.h>
#define int long long
#define double long double
#define vi vector<int>
#define vpi vector<pair<int,int> >
#define mii map<int,int>
#define mpi map<pair<int,int>,int>
#define msi map<string,int>
#define set set<int>
#define u_set unordered_set<int>
#define pb push_back
#define endl "\n"
#define ll long long int
#define vll vector<long long int>
#define vi vector<int>
#define vvi vector<vector<int>>
#define io ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define umap unordered_map 
#define mod 1000000007
#define fori(a,n) for(int i=a;i<n;i++)
#define forj(a,n) for(int j=a;j<n;j++)
#define MAX 300303
using namespace std;

string s,t,ans = "";
vvi dp(3000,vi(3000,INT_MIN));
int fun(int ssize,int tsize){
    if(ssize<0 || tsize<0) return 0;
    if(dp[ssize][tsize] != INT_MIN) return dp[ssize][tsize];
    if(s[ssize] == t[tsize]){
        return dp[ssize][tsize] = 1 + fun(ssize-1,tsize-1);
    }
    return dp[ssize][tsize] = max( fun(ssize-1,tsize) , fun(ssize,tsize-1) );
}
signed main()
{
    io
    cin >> s >> t;
    int ssiz = s.size();
    int tsiz = t.size();
    fun(ssiz-1,tsiz-1);
    int ii =  ssiz-1 , jj = tsiz-1;
    // fori(0,ssiz){
    //     forj(0,tsiz){
    //         cout << i << " " << j << " | " << dp[i][j] << endl;
    //     }
    // }
    while(ii >= 0 && jj >= 0)
    {
        // cout << ii << "|" << jj << endl;
        if(s[ii] == t[jj])
        {
            // cout  << dp[ii][jj] << " ayo"<<endl;
            ans = s[ii] + ans;
            ii--; jj--;
        }
        else if(ii>0 && jj >0 && dp[ii-1][jj] >= dp[ii][jj-1]){
            // cout  << dp[ii][jj] << " ayo"<<endl;
            ii--;
        }
        else if(jj>0 && ii>0 && dp[ii-1][jj] <= dp[ii][jj-1])jj--;
        else if(jj>=0)jj--;
        else if(ii>=0)ii--;
    }
    cout << ans << endl;
    
}

Measured memory_bytes: 71040
<?php
//error_reporting(0);
$N = trim(fgets(STDIN));
//list($A,$B) =  explode(" ",trim(fgets(STDIN)));
$H=explode(" ",trim(fgets(STDIN)));

$r=0;
$m = $H[0];
for($i=1;$i<$N;$i++) {
  if ($m<=$H[$i] && $H[$i-1]<=$H[$i]) {
    $r++;
  }
  if ($H[$i]>$m) {
    $m=$H[$i];
  }
}
printf("%d\n",$r+1);


Measured memory_bytes: 4604
//Ruthless Coding 
#include <bits/stdc++.h>

#define uni(x)      (x).resize(unique(all(x)) - (x).begin())
#define fprint(v)   for(auto x : v) cout << x << ' '
#define ALL(x)      (x).begin(), (x).end()
#define MP(x, y)    make_pair(x, y)
#define PII         pair<int, int>
#define SZ(x)       int((x).size())
#define PB(x)       push_back(x)
#define ll          long long
#define S           second 
#define F           first
#define nl          '\n'

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

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

const int N = 2e5 + 5;

int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    for(auto &x : a){
        cin >> x;
    }
    sort(ALL(a));
    int ans = INT_MAX;
    for(int i = 0; i + k - 1 < n; i++){
        ans = min(ans, a[i + k - 1] - a[i]);
    }
    cout << ans;
    return 0;
}
/*
    *** Most Impo.. -> check base case always
    1. Overflow Check (*, +)
    2. Index check (0 - based or 1 - based)
    3. Check for n = 1, 2, 3, 4....
    4. Corner Cases
*/

Measured memory_bytes: 640
#   AtCoder abc067 a
#   ストレッチ課題

#   入力
a, b = map(int, input().split())

#   判定
if (a % 3 == 0) or (b % 3 == 0) or ((a + b) % 3 == 0):
    print("Possible")
else:
    print("Impossible")


Measured memory_bytes: 9100
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<string>
#include<stack>
#include<cstdio>
#include<cmath>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<int,P> P1;

#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define rep(i,x) for(int i=0;i<x;i++)
#define rep1(i,x) for(int i=1;i<=x;i++)
#define rrep(i,x) for(int i=x-1;i>=0;i--)
#define rrep1(i,x) for(int i=x;i>0;i--)
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
#define mp1(a,b,c) P1(a,P(b,c))

const int INF=1000000000;
const int dir_4[4][2]={{1,0},{0,1},{-1,0},{0,-1}};
const int dir_8[8][2]={{1,0},{1,1},{0,1},{-1,1},{-1,0},{-1,-1},{0,-1},{1,-1}};

const ll M = 1000000007;

ll modpow(ll x,ll k){
	if(k == 0)return 1;
	ll ret = modpow(x,k/2);
	ret *= ret; ret %= M;
	if(k%2 == 1){
		ret *= x;
		ret %= M;
	}
	return ret;
}

int main(){
	ll n,q;
	ll a[3002];
	scanf("%lld%lld",&n,&q);
	for(int i = 1 ; i <= n ; i ++){
		scanf("%lld",&a[i]);
	}
	
	static ll dp[3002][3002] = {};
	for(int i = 1 ; i <= n ; i ++){
		for(int j = 1 ; j <= n ; j ++){
			if(a[i] < a[j])dp[i][j] ++;
		}
	}
	
	ll div2 = modpow(2,M-2);
	for(int t = 0 ; t < q ; t ++){
		int x,y;
		scanf("%d%d",&x,&y);
		for(int i = 1 ; i <= n ; i ++){
			if(i == x || i == y)continue;
			dp[i][x] = (dp[i][x]+dp[i][y])*div2;
			dp[i][x] %= M;
			dp[i][y] = dp[i][x];
			dp[x][i] = (dp[x][i]+dp[y][i])*div2;
			dp[x][i] %= M;
			dp[y][i] = dp[x][i];
		}
		dp[x][y] = (dp[x][y]+dp[y][x])*div2;
		dp[x][y] %= M;
		dp[y][x] = dp[x][y];
		
		/*for(int i = 1;  i <= n ; i ++){
			for(int j = 1 ; j <= n ; j ++){
				printf("%lld ",dp[i][j]);
			}
			puts("");
		}*/
	}
	ll ret = 0;
	for(int i = 1 ; i <= n ; i ++){
		for(int j = 1 ; j < i ; j ++){
			ret += dp[i][j];
			if(ret > M)ret -= M;
		}
	}
	ret *= modpow(2,q);
	cout << ret%M << endl;
}



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

int main(){
	int n;
	int omori[10];
	omori[0] = 1;
	for(int i = 1; i < 10; i++){
		omori[i] = omori[i-1]*2;
	}
	while(cin >> n){
		int k = 0;
		stack<int> st;
		for(int i = 9; i >=0; i--){
			if(omori[i] <= n){
				st.push(omori[i]);
				n = n - omori[i];
				k++;
			}
		}
		cout << st.top();
		st.pop();
		for(int i = 1; i < k; i++){
			cout << " " << st.top();
			st.pop();
		}
		cout << endl;
	}
}

Measured memory_bytes: 1200
#include<bits/stdc++.h>
#define int long long
#define for0(i, n) for(int i = 0; i < (n); i++)
#define for1(i, n) for(int i = 1; i <= (n);i++)
#define mp make_pair
#define all(x) x.begin(),x.end()
using namespace std;
double x, y;
vector<pair<double, double>>v1;
vector<pair<double, pair<double, double>>>v2;
stack<pair<double, double>>st;
void input() {
	string s; cin >> s;
	double k = 1, r[3];
	r[0] = 0; r[1] = 0;
	s += ',';int c = 0;
	bool b = 0;
	int sign = 1;
	for (char ch : s) {
		if (ch == ',') {
			r[c++] *= sign;
			b = 0; k = 1; sign = 1;
		}
		else if (ch == '.')b = 1;
		else if (ch == '-')sign = -1;
		else if (b) {
			k /= 10;
			r[c] += k * (ch - '0');
		}
		else {
			r[c] *= 10; r[c] += ch - '0';
		}
	}
	x = r[0]; y = r[1]; return;
}
signed main() {
	int n;
	while (cin >> n, n) {
		for0(i, n) { input(); v1.push_back(mp(x, y)); }
		sort(all(v1));
		for1(i, n - 1) {
			v1[i].first -= v1[0].first;
			v1[i].second -= v1[0].second;
		}
		v1[0] = mp(0, 0);
		for1(i, n - 1) {
			x = v1[i].first; y = v1[i].second;
			v2.push_back(mp(asin(y / sqrt(x * x + y * y)), v1[i]));
		}
		sort(all(v2));
		st.push(mp(0, 0));
		for0(i, n - 1) {
			if (st.size() <= 1)st.push(v2[i].second);
			else {
				x = v2[i].second.first; y = v2[i].second.second;
				double x2 = st.top().first, y2 = st.top().second; st.pop();
				double x1 = st.top().first, y1 = st.top().second; st.pop();
				while ((x - x1) * (y1 - y2) <= (y - y1) * (x1 - x2) && st.size()) {
					x2 = x1; y2 = y1;
					x1 = st.top().first, y1 = st.top().second; st.pop();
				}
				st.push(mp(x1, y1));
				st.push(mp(x2, y2));
				st.push(mp(x, y));
			}
		}
		cout << n - st.size() << endl;
		v1.clear(); v2.clear(); while (st.size())st.pop();
	}
}


Measured memory_bytes: 3168
#include<bits/stdc++.h>
#define int long long
#define for1(i, n) for(int i = 1; i <= (n);i++)
#define puts(x) cout << x << endl
using namespace std;
int input() {
	int r;
	scanf("%lld", &r);
	return r;
}
int n, k, a[123456], sum, p = 1099511627776, ans;
signed main() {
	cin >> n >> k; for1(i, n)a[i] = input();
	while (p) {
		if (sum + p <= k) {
			int cnt = 0;
			for1(i, n)cnt += a[i] / p % 2;
			if (cnt < n - cnt)sum += p;
		}
		p /= 2;
	}
	for1(i, n)ans += a[i] ^ sum;
	puts(ans);
}

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

int main(){
 while(true){
	int N;
	cin>>N;

	if(N==0)break;

	int n[10]={0};
	int m=0;

	for(int i=0;i<100;i++){
		char c;
		cin>>c;

		n[i%N]++;

		if(c=='S'){
			m+=n[i%N];
			n[i%N]=0;
		}else if(c=='L'){
			n[i%N]+=m;
			m=0;
		}

	}
	sort(n,n+N);

	for(int i=0;i<N;i++){
		cout<<n[i]<<' ';
 	}
 	cout<<m<<endl;
 }
 return 0;
}

Measured memory_bytes: 3088
use std::io::*;
use std::str::FromStr;
 
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

#[allow(dead_code)]
fn str2vec(s: &str) -> Vec<char> {
    let mut v: Vec<char> = Vec::new();
    for c in s.chars() {
        v.push(c);
    }
    v
}

fn main() {
	let s: String = read();
    let v = str2vec(&s);
    let mut ans = 700;
    for z in v {
        if z == 'o' {
            ans += 100;
        }
    }
    println!("{}", ans);
}

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

#define ALL(v) (v).begin(), (v).end()
#define rep(i, l, r) for (int i = (l); i < (r); ++i)
typedef long long ll;
const int maxn = 200200;
int w[200],v[200];

void solve()
{
    int n,W;
    cin >> n >> W;
    ll dp[n + 1][W + 1];
    for (int i = 0; i < n; i++)
        cin >> w[i] >> v[i];
    
    for (int i = 0; i <= n; i++){
        for (int w1 = 0; w1 <= W; w1++){
            if (!i || !w1){
                dp[i][w1] = 0;
            }else if (w[i - 1] <= w1)
                dp[i][w1] = max(v[i - 1] + dp[i - 1][w1 - w[i - 1]], dp[i - 1][w1]);
            else
                dp[i][w1] = dp[i - 1][w1];
        }
    }
    cout << dp[n][W] << endl;
}

int main()
{
    solve();
    return (0);
}





Measured memory_bytes: 79104