akhauriyash/Code-Regression huggingface dataset:
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;
import java.util.PriorityQueue;

public class Main {
	private static FastScanner sc = new FastScanner();

	public static void main(String[] args) {
		int n = sc.nextInt();
		
		Node[] V = new Node[n];
		PriorityQueue<Node> que = new PriorityQueue<>((a, b) -> a.d - b.d);
		for(int i=0; i<n; i++) {
			sc.nextInt();
			int k = sc.nextInt();
			int[] v = new int[n];
			int[] c = new int[n];
			for(int j=0; j<k; j++) {
				v[j] = sc.nextInt();
				c[j] = sc.nextInt();
			}
			V[i] = new Node(i == 0 ? 0 : Integer.MAX_VALUE, v, c);
			que.add(V[i]);
		}
		
		while(!que.isEmpty()) {
			Node node = que.poll();
			node.dijkstra(V,que);
		}
		
		StringBuilder ans = new StringBuilder();
		for(int i=0; i<n; i++) {
			ans.append(i);
			ans.append(" ");
			ans.append(V[i].d);
			ans.append("\n");
		}
		System.out.print(ans);
	}
	
	static class Node {
		int d;
		int[] v;
		int[] c;
		
		Node(int d, int[] v, int[] c) {
			this.d = d;
			this.v = v;
			this.c = c;
		}
		
		public void dijkstra(Node[] V, PriorityQueue<Node> que) {
			for(int i=0; i<v.length; i++) {
				Node node = V[v[i]];
				if(node.d > d + c[i]) {
					que.remove(node);
					node.d = d + c[i];
					que.add(node);
				}
			}
		}
	}

	static class FastScanner {
	    private final InputStream in = System.in;
	    private final byte[] buffer = new byte[1024];
	    private int ptr = 0;
	    private int buflen = 0;
	    private boolean hasNextByte() {
	        if (ptr < buflen) {
	            return true;
	        }else{
	            ptr = 0;
	            try {
	                buflen = in.read(buffer);
	            } catch (IOException e) {
	                e.printStackTrace();
	            }
	            if (buflen <= 0) {
	                return false;
	            }
	        }
	        return true;
	    }
	    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
	    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
	    private void skipUnprintable() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;}
	    public boolean hasNext() { skipUnprintable(); return hasNextByte();}
	    public String next() {
	        if (!hasNext()) throw new NoSuchElementException();
	        StringBuilder sb = new StringBuilder();
	        int b = readByte();
	        while(isPrintableChar(b)) {
	            sb.appendCodePoint(b);
	            b = readByte();
	        }
	        return sb.toString();
	    }
	    public long nextLong() {
	        return Long.parseLong(next());
	    }
	    public int nextInt(){
	    	return Integer.parseInt(next());
	    }
	}
}

Measured memory_bytes: 31464
M = list(map(int,input().split()))
N = M[0]
K = M[1]
h = list()
for x in range(0,N):
    h.append(int(input()))
sorted_h = sorted(h)
sub_h_org = sorted_h[N-1] - sorted_h[0]
for y in range(0,N-K+1):
    sub_h = sorted_h[y+K-1] - sorted_h[y]
    if sub_h < sub_h_org:
        sub_h_org = sub_h
print(sub_h_org)

Measured memory_bytes: 8280
#include <stdio.h>
#include <string.h>
#include <algorithm>

#define BUF 200002
#define LIM_N 101

char str[BUF];

int N, M;
int k[LIM_N];
int s[LIM_N][11];
int p[LIM_N];

int flag[11];

void receive_input() {
	fgets(str, sizeof(str), stdin);
	sscanf(str, "%d %d", &N, &M);

	for (size_t i = 1; i <= M; i++) {
		scanf("%d", &k[i]);
		for (size_t j = 1; j <= k[i]; j++) {
			scanf("%d", &s[i][j]);
		}
	}

	for (size_t i = 1; i <= M; i++) {
		scanf("%d", &p[i]);
	}
}

int increment(int n) {
	if (n == N+1) {
		return 0;
	}

	if (flag[n] == 0) {
		flag[n] = 1;
		return 1;
	} else {
		flag[n] = 0;
		return increment(n+1);
	}
}

int is_all_light() {
	for (size_t i = 1; i <= M; i++) {
		int count = 0;
		for (size_t j = 1; j <= k[i]; j++) {
			if (flag[s[i][j]]) {
				count++;
			}
		}

		if (count % 2 != p[i]) {
			return 0;
		}
	}
	return 1;
}

int solve() {
	int ans = 0;
	do {
		if (is_all_light()) {
			ans++;
		}
	} while (increment(1));
	return ans;
}

int main(void) {
	receive_input();

	// solve();
	printf("%d\n", solve());

	return 0;
}


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

int main() {
    long long x;
    cin >> x;
    long long ans = ((x - 1) / 11 + 1) * 2;
    if ((ans - 2) / 2 * 11 + 6 >= x) ans--;
    cout << ans << endl;
}   

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <unordered_map>
using namespace std;

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

template<class T> vector<T> make_vec(size_t a) { return vector<T>(a); }
template<class T, class... Ts> auto make_vec(size_t a, Ts... ts) {
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template<class T, class V>
typename enable_if<is_class<T>::value == 0>::type fill(T &t, const V &v) {
    t = v;
}
template<class T, class V>
typename enable_if<is_class<T>::value != 0>::type fill(T &t, const V &v){
    for (auto &e : t) fill(e, v);
}

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }

#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }




int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    string S;
    while (cin >> S) {
        if (S[0] == S[1] || S[1] == S[2] || S[2] == S[3]) puts("Bad");
        else puts("Good");
    }
}


















Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;

int n, a[N], b[N], axor[N], bxor[N];
int c[N], pi[3 * N];

int main() {
  ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  cin >> n;
  for (int i = 0; i < n; ++i) cin >> a[i];
  for (int i = 0; i < n; ++i) cin >> b[i];
  for (int i = 0; i < n; ++i) {
    axor[i] = a[i] ^ a[(i + 1) % n];
    bxor[i] = b[i] ^ b[(i + 1) % n];
  }
  for (int i = 0; i < n; ++i) c[i] = bxor[i];
  c[n] = -1;
  for (int i = 0; i < n; ++i) c[n + 1 + i] = c[2 * n + 1 + i] = axor[i];

  int m = 3 * n;
  for (int i = 1; i <= m; ++i) {
    int j = pi[i - 1];
    while (j > 0 && c[i] != c[j]) j = pi[j - 1];
    if (c[i] == c[j]) ++j;
    pi[i] = j;
  }

  for (int i = 2 * n; i < m; ++i) {
    if (pi[i] == n) {
      int k = i - 2 * n;
      cout << k << " " << (a[k] ^ b[0]) << "\n";
    }
  }
  return 0;
}

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

int main(){
    ll n, k;
    cin >> n >> k;
    n = n%k;
    ll ans = min(n, k-n);
    cout << ans << endl;
    return 0;
}

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

#define rep(i,a,b) for(ll i=a;i<b;i++)
typedef long long ll;
         int main()
         { 
              ll n; cin>>n;
            string s; cin>>s;
            ll j=0,k=0;
            rep(i,0,n)
            {
               if(s[i]=='R')
                  j++;
               else
                  k++;
            }
            ll h=0,m=0;
            rep(i,0,j)
            {
               if(s[i]=='W')
                  h++;
            }
            for(ll i=n-1;i>=max(0ll,n-k);i--)
               if(s[i]=='R')
                  m++;
            cout<<min(h,m);
               return 0; 
         }

Measured memory_bytes: 3732
import sys
sys.setrecursionlimit(10000000)
import heapq
import math

def main():
    N, K = map(int, input().split())
    A = [int(c) for c in input().split()]
    F = [int(c) for c in input().split()]
    
    A.sort()
    F.sort(reverse=True)

    num = 0
    sum_ = []
    for i in range(len(A)):
        sum_.append(A[i] * F[i])
    left = 0
    right = 10 ** 12
    while(num < 50):
        number = 0
        mid = (left + right) // 2
        # print(mid)
        for i in range(len(A)):
            if sum_[i] <= mid:
                continue
            else:
                number += math.ceil((sum_[i] - mid) / F[i])
            # print(number)
        if number > K:
            # 最大値をmidより小さくできない -> 最大値はもっとでかい
            left = mid + 1
        else:
            right = mid
        num += 1
    print(mid)
                

if __name__ == '__main__':
    main()


Measured memory_bytes: 120140
#include <bits/stdc++.h>
#define all(v) (v).begin(),(v).end()
using namespace std;
using LL = long long;
const int INF = 1e9;

int main(void)
{
    int X, Y;
    cin >> X >> Y;
    int p = 0;
    if (X == 3) p = 100000;
    else if (X == 2) p = 200000;
    else if (X == 1) p = 300000;
    if (Y == 3) p += 100000;
    else if (Y == 2) p += 200000;
    else if (Y == 1) p += 300000;
    if (X == 1 && Y == 1) p += 400000;
    cout << p << endl;
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>
#include <set>
#include <functional>
#include <iomanip>

using namespace std;

#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ;
#endif

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back

//#define int long long

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

const int MOD = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;

signed main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    VI p(n); REP(i,n) cin >> p[i];

    int ans = 0;
    REP(i,n-2){
        int tmin = min({p[i],p[i+1],p[i+2]});
        int tmax = max({p[i],p[i+1],p[i+2]});
        if(tmin != p[i+1] && tmax != p[i+1]){
            ans++;
        }

    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int k,s,a=0,i,j,l;
	scanf("%d %d", &k, &s);
	for(i=0; i<=k; i++)
	{
		for(j=0; j<=k; j++)
		{
			if(i+j<=s&&s-i-j<=k)
			a++;
		}
	}
	printf("%d\n", a);
	
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int main()
{
  string S; cin >> S;
  string T; cin >> T;

  int cnt = 0;
  if (S[0] == T[0]) cnt++;
  if (S[1] == T[1])cnt++;
  if (S[2] == T[2])cnt++;

  cout << cnt << endl;
}

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

signed main(){
  lint N; cin >> N;
  string s; cin >> s;
  lint cg = 0, cr  =0, cb = 0;
  for(lint i = 0; i < N; i++){
    if(s[i] == 'R') cr++;
    if(s[i] == 'G') cg++;
    if(s[i] == 'B') cb++;
  }
  lint ans = cg * cr * cb;
  for(lint i = 1; i <= N/2; i++){
    for(lint j = 0; j < N; j++){
      lint x = j, y = j + i, z = j + 2*i;
      if(y >= N || z >= N) continue;
      else if(s[x] != s[y] && s[y] != s[z] && s[x] != s[z]) ans--;
     }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3628
#include <iostream>
using namespace std;
int main()
{
	long long A, B, C;
	cin >> A >> B >> C;
	if (A % 2 == 0 || B % 2 == 0 || C % 2 == 0)	{
		cout << 0 << endl;
		return 0;
	}
	if (A >= B&&A >= C)	{
		cout << B*C << endl;
		return 0;
	}
	else if (B >= C){
		cout << A*C << endl;
		return 0;
	}
	else{
		cout << A*B << endl;
		return 0;
	}
	return 0;
}

Measured memory_bytes: 256
n=int(input())
ta=[list(map(int,input().split())) for _ in range(n)]
tv,av=1,1
#print('-----')
for t,a in ta:
  i=(t+tv-1)//t
  j=(a+av-1)//a
  k=max(i,j)
  tv=t*k
  av=a*k
print(tv+av)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(LL)(b);i++)
#define REP(i,b) FOR(i,0,b)
#define ALL(c) c.begin(),c.end()
#define PB push_back
#define cat 
using namespace std;
typedef long long LL;
typedef double ld;
typedef int ut;
typedef vector<ut> VI;
typedef pair<ut,ut> pr;
typedef pair<ut,pr> ppr;
typedef vector<pr> Vpr;
typedef priority_queue<pr,Vpr,greater<pr> > PQ;
const int INF=1<<30;
const int BITSIZE=1<<17;
const LL p=7+1e9;
const int SIZE=2*1e5;
int a[SIZE];
int minium=INF,N;
int main(){
	string s;
	cin >> s;
	s+="  ";
	REP(i,s.size()-2){
		if(s[i]==s[i+1]){
			cout << i+1 <<" " << i+2 << endl;
			return 0;
		}
		if(s[i]==s[i+2]){
			cout << i+1 <<" " << i+3 << endl;
			return 0;
		}
	}
	cout << -1 <<" " << -1 << endl;

	return 0;
}

Measured memory_bytes: 512
import java.util.Scanner;
import java.util.HashMap;
import java.util.List;
import java.util.Arrays;
import java.util.ArrayList;
import java.lang.Math;

public class Main {

    static Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        long a = sc.nextLong();
        long b = sc.nextLong();
        long c = sc.nextLong();
        if (a % 2 == 0 || b % 2 == 0 || c % 2 == 0) {
            System.out.println(0);
        } else {
            if (a*b*1 <= b*c*1) {
                if (a*b*1 <= c*a*1) {
                    System.out.println(a*b*1);
                } else {
                    System.out.println(c*a*1);
                }
            } else {
                if (b*c*1 <= c*a*1) {
                    System.out.println(b*c*1);
                } else {
                    System.out.println(c*a*1);
                }
            }
        }
    }

}


Measured memory_bytes: 21716
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define ll long long
#define ld long double
#define MOD 1000000007
#define nl cout << bl
#define rt ll Q[100005] = {0}
#define mp make_pair
#define test() \
    ull t;     \
    cin >> t;  \
    while (t--)
#define pb push_back
#define ff first
#define ss second
#define all(v) v.begin(), v.end()
#define s(ar, n) sort(ar, ar + n)
#define rs(ar, n) sort(ar, ar + n, greater<ll>())
#define oa(a, n)               \
    for (ll i = 0; i < n; i++) \
        cout << a[i] << " ";
#define cn(a, n)               \
    for (ll i = 0; i < n; i++) \
        cin >> a[i];
#define ov(a, n)                    \
    for (ll i = n - 1; i >= 0; i--) \
        cout << a[i] << " ";        \
    nl
#define ovp(a, n)              \
    for (ll i = 0; i < n; i++) \
        cout << a[i].ff << " " << a[i].ss << bl;
#define maxa(ar, N) *max_element(ar, ar + N)
#define mina(ar, N) *min_element(ar, ar + N)
#define present(c, x) ((c).find(x) != (c).end())
#define fastio()                  \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0)
typedef pair<int, int> pii;
ll fast_exp(ll base, ll exp)
{
    ll res = 1;
    while (exp > 0)
    {
        if (exp % 2 == 1)
            res = (res * base) % MOD;
        base = (base * base) % MOD;
        exp /= 2;
    }
    return res % MOD;
}
ll fib(ll n)
{
    if (n < 2)
        return n;
    ll a = 0, b = 1, pre;
    int i = 1;
    while (i < n)
    {
        pre = (a + b) % MOD;
        a = b;
        b = pre;
        i++;
    }
    return pre;
}
ll fac(ll n)
{
    if (n % 2 == 0)
        return 2;

    for (ll i = 3; i * i <= n; i += 2)
    {
        if (n % i == 0)
            return i;
    }

    return n;
}
ll fact(ll n)
{
    if (n > 1)
        return n * fact(n - 1);
    else
        return 1;
}
long long moduloMultiplication(long long a,
                               long long b,
                               long long mod)
{
    long long res = 0; // Initialize result

    // Update a if it is more than
    // or equal to mod
    a %= mod;

    while (b)
    {
        // If b is odd, add a with result
        if (b & 1)
            res = (res + a) % mod;

        // Here we assume that doing 2*a
        // doesn't cause overflow
        a = (2 * a) % mod;

        b >>= 1; // b = b / 2
    }

    return res;
}
int main()
{
    fastio();
    int n;
    cin >> n;
    bool flag = false;
    int count = 0;
    int x, y;
    for (int i = 0; i < n; i++)
    {
        cin >> x >> y;
        if (x == y)
        {
            count++;
        }
        else
        {
            count = 0;
        }
        if (count == 3)
        {
            flag = true;
        }
    }
    if (flag)
    {
        cout << "Yes";
    }
    else
    {
        cout << "No";
    }
}


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


int main(){
	int n, d, i, j, ans = 0;
	cin >> n >> d;
	int x[n][d];

	for (i = 0; i < n; i++){
		for (j = 0; j < d; j++){
			cin >> x[i][j];
		}
	}

	int dis;
	for (i = 0; i < n - 1; i++){
		for(j = i + 1; j < n; j++){
			dis = 0;
			for (int k = 0; k < d; k++) dis += pow(x[i][k] - x[j][k], 2);
			int newdis = sqrt(dis);
			if (pow(newdis, 2) == dis) ans++;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
import sys
from sys import exit
from collections import deque
from copy import deepcopy
from bisect import bisect_left, bisect_right, insort_left, insort_right
from heapq import heapify, heappop, heappush
from itertools import product, permutations, combinations, combinations_with_replacement
from functools import reduce
from math import gcd, sin, cos, tan, asin, acos, atan, degrees, radians

sys.setrecursionlimit(10**6)
INF = 10**20
eps = 1.0e-20
MOD = 10**9+7

def lcm(x,y):
    return x*y//gcd(x,y)
def lgcd(l):
    return reduce(gcd,l)
def llcm(l):
    return reduce(lcm,l)
def powmod(n,i,mod):
    return pow(n,mod-1+i,mod) if i<0 else pow(n,i,mod)
def div2(x):
    return x.bit_length()
def div10(x):
    return len(str(x))-(x==0)
def intput():
    return int(input())
def mint():
    return map(int,input().split())
def lint():
    return list(map(int,input().split()))
def ilint():
    return int(input()), list(map(int,input().split()))
def judge(x, l=['Yes', 'No']):
    print(l[0] if x else l[1])
def lprint(l, sep='\n'):
    for x in l:
        print(x, end=sep)
def ston(c, c0='a'):
    return ord(c)-ord(c0)
def ntos(x, c0='a'):
    return chr(x+ord(c0))
class counter(dict):
    def __init__(self, *args):
        super().__init__(args)
    def add(self,x,d=1):
        self.setdefault(x,0)
        self[x] += d
    def list(self):
        l = []
        for k in self:
            l.extend([k]*self[k])
        return l
class comb():
    def __init__(self, n, mod=None):
        self.l = [1]
        self.n = n
        self.mod = mod
    def get(self,k):
        l,n,mod = self.l, self.n, self.mod
        k = n-k if k>n//2 else k
        while len(l)<=k:
            i = len(l)
            l.append(l[i-1]*(n+1-i)//i if mod==None else (l[i-1]*(n+1-i)*powmod(i,-1,mod))%mod)
        return l[k]
def pf(x,mode='counter'):
    C = counter()
    p = 2
    while x>1:
        k = 0
        while x%p==0:
            x //= p
            k += 1
        if k>0:
            C.add(p,k)
        p = p+2-(p==2) if p*p<x else x
    if mode=='counter':
        return C
    S = set([1])
    for k in C:
        T = deepcopy(S)
        for x in T:
            for i in range(1,C[k]+1):
                S.add(x*(k**i))
    if mode=='set':
        return S
    if mode=='list':
        return sorted(list(S))

N=intput()
C=[[0]*10 for _ in range(10)]
for x in range(1,N+1):
    r=x%10
    t=int(str(x)[0])
    if r!=0:
        C[t][r]+=1
ans=0
for t in range(1,10):
    for r in range(1,10):
        ans+=C[t][r]*C[r][t]
print(ans)

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

vector<vector<int>> E;
vector<int> V;

void dfs(int v, int p) {
  V.at(v) += V.at(p);
  for (int e : E.at(v)) if (p != e) dfs(e, v);
}

int main() {
  ios::sync_with_stdio(false);
  int N, Q;
  cin >> N >> Q;
  E.resize(N + 1);
  for (int i = 1, a, b; i < N && cin >> a >> b; i++) E.at(a).push_back(b), E.at(b).push_back(a);
  V.resize(N + 1);
  for (int i = 0, p, x; i < Q && cin >> p >> x; i++) V.at(p) += x;

  dfs(1, 0);

  for (int i = 1; i <= N; i++) cout << V.at(i) << "\n";
}

Measured memory_bytes: 23552
#include<algorithm>
#include <iostream>
using namespace std;
int main()
{
    int n, m,k,i;cin >> m >> n >> k;
    int c = 0;
    for (i = min(m, n);i >= 1;i--) {
        if (n % i == 0 && m % i == 0) {
            ++c;
            if (c == k)
                break;
        }
   }
    cout << i << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
 
int main() {
   int s, i = 0, j = 0, cnt = 0;
   int a[1000000];
   
   scanf("%d",&s);
   a[i] = s;

   if((s < 1) || (s > 100)) {
      return 0;
   }
   
   while (i < 1000000) {
     j = 0;
     cnt = 0;
     while (j < i) {
        if (a[i] == a[j] ) {
           cnt++;
           if(cnt == 2) {
              printf("%d\n",j + 1);
              return 0;
           }
        }
        j++;
     }
     if (a[i] % 2 == 0)  {
        a[i + 1] = a[i] / 2;
     }
     else if (a[i] % 2 != 0)  {
        a[i + 1] = 3 * a[i] + 1;
     }
     
     i++;
   }
}


Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <cmath>
#include <math.h>

using namespace std;
int dp[100010] = {0};
int main() {
    int n;
    cin >> n;
    int high[n] = {0};
    for (int i=0;i<n;i++){
        cin >> high[i];
    }
    dp[1] = 0;
    dp[2] = abs(high[1] - high[0]);
    for (int i=3;i<=n;i++){
        dp[i] = min(abs(high[i-1] - high[i-2])+dp[i-1],abs(high[i-1]-high[i-3])+dp[i-2]);
    }
    cout << dp[n];
}



Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
#include<numeric>
#include<vector>
#include<set>
#include<map>
#include<math.h>
#include <string>
#define cinf(n,x,y) for(int i=0;i<(n);i++) cin >> x[i] >>y[i];
typedef long long int ll;
using namespace std;
ll mod=1e9+7;
int cnt[100000];
int main(){
	int n; 
	while(1){
		cin >> n; 
		if(n==0)break;
		for(int i=0;i<100000;i++){
			cnt[i]=0;
		}
		for(int i=0;i<n;i++){
			int h,m,s;
			scanf("%02d:%02d:%02d",&h,&m,&s);
			int a=h*3600+m*60+s;
			scanf("%02d:%02d:%02d",&h,&m,&s);
			int b=h*3600+m*60+s;
			cnt[a]++; cnt[b]--;
		}
		int ans=0;
		for(int i=1;i<99999;i++){
			cnt[i]+=cnt[i-1];
			ans=max(ans,cnt[i]);
		}
		cout << ans << endl;
	}
	return 0;
}


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

typedef long long          ll;
typedef long double        ld;
typedef unsigned long long ull;
typedef vector<ll>         vl;
typedef vector<vl>         vvl;
typedef pair<ll,ll>        pll;
typedef vector<pll>        vpll;

#define ff          first
#define ss          second
#define mp          make_pair
#define mt          make_tuple
#define pb          push_back
#define eb          emplace_back
#define fr(i,n)     for(ll i = 0; i < n; ++i)
#define frs(i,s,n)  for(ll i = s; i < n; ++i)
#define frb(i,s,e)  for(ll i = s; i <= e; ++i)
#define rfr(i,n)    for(ll i = n-1; i >= 0; i--)
#define frbr(i,e,s) for(ll i = e; i >= s; i--)
#define all(x)      (x).begin(), (x).end()
#define sz(x)       ((ll)(x).size())

#ifdef LOCAL
#include </home/udaya_bhaskar/Desktop/debugger.h>
#else
#define dbg(x...)      {}
#define dbg_arr(a,n)   {}
#define dbg_mat(m,r,c) {}
#define dbg_time()     {}
#endif

const ll MOD  = 1e9+7; // 998244353;
const ll INF  = 1e18;
const ll MAX  = 100100;




void pre()
{
  // factorizer::sieve();
  // prepare_factorials();
}




void solve()
{
  ll n; cin >> n;
  vl arr(n, 0);
  fr(i, n)
  {
  	ll x, y; cin >> x >> y;
  	arr[i] = (x == y); 
  } 
  fr(i, n - 2)
  {
    if(arr[i] + arr[i + 1] + arr[i + 2] == 3)
    {
      cout << "Yes" << "\n";
      return;
    }
  }
  cout << "No" << "\n";
}




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

#ifdef LOCAL
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif

  // cout << fixed << setprecision(15);
  
  pre();

  ll t = 1;
  // cin >> t;
  frb(CASE, 1, t)
  {
    // cout << "Case #" << CASE << ": ";
    // dbg(CASE);
    solve();
  }

  dbg_time();
  
  return 0;
}     
     


Measured memory_bytes: 3664
#include<stdio.h>

int main(){

	int a[3],i,b,c;

	scanf("%d %d %d", &a[0], &a[1],&a[2]);

	for (i = 2; i >= 0; i--)
	{
		for (b = 0; b < i; b++)
		{
			if (a[b]>a[b+1])
			{
				c=0;
				c = a[b];
				a[b] = a[b+1];
				a[b+1] = c;

			}
		}

		
		
	}
	
		printf("%d %d %d\n", a[0],a[1],a[2]);
	
	return 0;
}

Measured memory_bytes: 596
#include <iostream>
#include <map>
#include <vector>

using namespace std;

int main() {
	int N; cin >> N;
	map<string, int> tbl;
	vector<string> to(N);
	for (int i = 0; i < N; ++i) {
		string str; cin >> str;
		if (str == "goto") {
			cin >> str;
			str = str.substr(0, str.size()-1);
			to[i] = str;
		}
		else {
			str = str.substr(0, str.size()-1);
			tbl[str] = i;
			to[i] = "";
		}
	}
	int m[101][101]; fill(&m[0][0], &m[0][0]+101*101, 1e9);
	for (int i = 0; i < N; ++i) {
		if (to[i] == "") {
			m[i][i+1] = 0;
		}
		else {
			m[i][i+1] = 1;
			m[i][tbl[to[i]]] = 0;
		}
	}

	for (int i = 0; i < N+1; ++i) m[i][i] = 0;
	for (int k = 0; k < N+1; ++k) for (int i = 0; i < N+1; ++i) for (int j = 0; j < N+1; ++j) {
		m[i][j] = min(m[i][j], m[i][k] + m[k][j]);
	}
	cout << m[0][N] << endl;
}

Measured memory_bytes: 1268
"""
与えられた二分木の全ての節点を体系的に訪問する
"""
import copy

class Node:
    def __init__(self):
        self.parent = -1
        self.depth = 0
        self.children = []

#空の木の構成
#node_idをインデックスに持たせる
n = int(input())
nodes = []
for _ in range(n):
    node = Node()
    nodes.append(node)

#木の構成
for i in range(n):
    l = list(map(int, input().split()))
    node_id = l[0]

    for j in range(2):
        try:
            child = l[1+j] #l[1+j]というのは子供の番号
            nodes[node_id].children.append(child) 
            if not child == -1:
                nodes[child].parent = node_id #子一人当たり親は必ず一人
        except:
            pass #エラー回避
    else:
        pass #子がいないとき

def getRoot(node_id):
    target = nodes[node_id]
    if target.parent == -1:
        return node_id

def preParse(node_id):
    if node_id == -1:
        return
    print(' '+str(node_id), end='')
    preParse(nodes[node_id].children[0])
    preParse(nodes[node_id].children[1])

def inParse(node_id):
    if node_id == -1:
        return
    inParse(nodes[node_id].children[0])
    print(' '+str(node_id), end='')
    inParse(nodes[node_id].children[1])

def postParse(node_id):
    if node_id == -1:
        return
    postParse(nodes[node_id].children[0])
    postParse(nodes[node_id].children[1])
    print(' '+str(node_id), end='')

root_id = 0
for i in range(n):
    target = nodes[i]
    if target.parent == -1:
        root_id = i
        break

print('Preorder')
preParse(root_id)
print('\nInorder')
inParse(root_id)
print('\nPostorder')
postParse(root_id)
print()





Measured memory_bytes: 6352
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pl;
typedef vector<pl> vp;
const ll INF=1001001001;
const ll LINF=1001001001001001001;
const ll D4[]={0,1,0,-1,0};
const ll D8[]={0,1,1,0,-1,-1,1,-1,0};
#define _overload3(_1,_2,_3,name,...) name
#define _rep2(i,n) for(ll i=0;i<(n);++i)
#define _rep3(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(...) _overload3(__VA_ARGS__,_rep3,_rep2)(__VA_ARGS__)
#define _repe2(i,n) for(ll i=0;i<=(n);++i)
#define _repe3(i,a,b) for(ll i=(a);i<=(b);++i)
#define repe(...) _overload3(__VA_ARGS__,_repe3,_repe2)(__VA_ARGS__)
#define _rrep2(i,n) for(ll i=(n)-1;i>=0;i--)
#define _rrep3(i,a,b) for(ll i=(b)-1;i>=(a);i--)
#define rrep(...) _overload3(__VA_ARGS__,_rrep3,_rrep2)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
template<class T>
bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>
bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
template<class T>
using pq=priority_queue<T,vector<T>,greater<T>>;

void solve();

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

void solve(){
    ll n;cin>>n;
    vl a(n);
    rep(i,n)cin>>a[i];
    list<ll> b;
    rep(i,n){
        if(i%2)b.push_back(a[i]);
        else b.push_front(a[i]);
    }

    if(n%2==0){
        reverse(all(b));
    }

    ll idx=0;
    for(ll x:b){
        if(idx>0)cout<<' ';
        cout<<x;
        ++idx;
    }
    cout<<endl;
}

Measured memory_bytes: 9984
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
#include <iostream>
#include <sstream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <bitset>
#include <complex>
#include <array>
#include <list>
#include <stack>
#include <valarray>

using namespace std;

typedef unsigned uint;
typedef long long Int;
typedef unsigned long long UInt;

const int INF = 1001001001;
const Int INFLL = 1001001001001001001LL;

template<typename T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<typename T> void chmin(T& a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T& a, T b) { if (a < b) a = b; }
int in() { int x; scanf("%d", &x); return x; }
double fin() { double x; scanf("%lf", &x); return x; }
Int lin() { Int x; scanf("%lld", &x); return x; }

int A[100050], P[100050];
vector<int> X[100050];

int calc(int a, int b) {
  if (X[a].size() > X[b].size()) {
    swap(a, b);
  }
  int as = X[a].size(), bs = X[b].size();
  int res = 0;
  for (int i = 0; i <= as; ++i) {
    chmax(res, i + min(P[a], (as - i) / 2) + min(P[b], (bs - i) / 2));
  }
  return res;
}

int main() {
  int N = in();
  int M = in();

  for (int i = 0; i < N; ++i) {
    A[i] = in();
    X[A[i] % M].push_back(A[i]);
  }

  for (int i = 0; i < M; ++i) {
    sort(X[i].begin(), X[i].end());
    for (int j = 0; j + 1 < X[i].size(); ++j) {
      if (X[i][j] == X[i][j + 1]) {
        ++P[i];
        ++j;
      }
    }
  }

  int res = 0;
  for (int i = 0; i <= M - i; ++i) {
    int j = (M - i) % M;
    if (i == j) {
      res += X[i].size() / 2;
    } else {
      res += calc(i, j);
    }
  }

  printf("%d\n", res);

  return 0;
}


Measured memory_bytes: 6144
n, k = map(int, input().split())
a = list(map(int, input().split()))
mod = 10 ** 9 + 7

mia = sorted([i for i in a if i < 0], reverse=True)
pla = sorted([i for i in a if i >= 0])
ans, num, cnt = 1, [], 0

if len(pla) == 0 and k % 2 == 1:
    for i in mia[:k]:
        ans = ans * i % mod
    print(ans)
    exit()

for _ in range(k):
    if len(mia) == 0 or (len(pla) > 0 and abs(mia[-1]) <= pla[-1]):
        tmp = pla.pop()
    elif len(pla) == 0 or (len(mia) > 0 and abs(mia[-1]) > pla[-1]):
        tmp = mia.pop()
        cnt += 1
    num.append(tmp)
    ans = ans * tmp % mod

if cnt % 2 == 1:
    p, q, r, s = 1, 0, -1, 0
    if len(mia) > 0 and cnt != k:
        p, q = min(i for i in num if i >= 0), mia[-1]
    if len(pla) > 0:
        r, s = max(i for i in num if i < 0), pla[-1]
    if len(mia) > 0 or (len(pla) > 0 and cnt != k):
        if q * r >= p * s:
            ans *= q * pow(p, mod - 2, mod)
        if q * r < p * s:
            ans *= s * pow(r, mod - 2, mod)
    ans %= mod
print(ans)


Measured memory_bytes: 31704
import numba

@numba.njit(numba.i8(numba.i8), cache=True)
def solve(k):
  def gcd(a, b):
    if a < b:
      a,b = b,a
    while b:
      a, b = b, a%b
    return a

  ans = 0
  for a in range(1, k+1):
    for b in range(1, k+1):
      for c in range(1, k+1):
        ans += gcd(gcd(a,b),c)
  return ans

print(solve(int(input())))

Measured memory_bytes: 106116
#include <iostream>
#include <string>
#include <cstring>
#include <stdio.h>
#include <algorithm>
using namespace std;

int main(){
    int n;
    cin >> n;

    string t, h;
    int tt = 0, hh = 0;
    for(int i = 0; i < n; i++){
        cin >> t >> h;
        if(t < h) hh+=3;
        else if(t > h) tt+=3;
        else if(t == h){
            tt++; hh++;
        }
    }

    printf("%d %d\n", tt, hh);
    return 0;
}


Measured memory_bytes: 3352
#include<iostream>
using namespace std;
using ll = long long;

int main() {
	ll n;
	cin >> n;
	for (ll h = 1;h <= 3500;h++) {
		for (ll w = 1;w <= 3500;w++) {
			ll t = n * w*h;
			if (4 * h*w - n * w - n * h <= 0) continue;
			if (t % (4 * h*w - n * w - n * h) == 0) {
				printf("%d %d %d\n", h, w, t / (4 * h*w - n * w - n * h));
				return 0;
			}
		}
	}
}


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

using namespace std;

const int MX = 200000, md = 1000000007;

char s[MX + 1];
int dp[MX + 1], sum[MX + 1];

int main() {
	int n, m;
	ignore = scanf("%d %d %s", &n, &m, s);
	
	char R = s[0];
	
	vector<int> sizes;
	for (int i = 0, sz = 0; i < m; i++) {
		if (s[i] == R) sz++;
		else if (sz > 0) {
			sizes.push_back(sz);
			sz = 0;
		}
	}
	
	if (sizes.empty()) {
		auto count = [](int n, int first) {
			int f = first, g = 1 - first;
			for (int i = 1; i < n; i++) {
				tie(f, g) = make_pair(f + g, f);
				f %= md;
				g %= md;
			}
			
			return (f + first * g) % md;
		};
		
		int ans = count(n, 0) + count(n, 1);
		ans %= md;
		printf("%d\n", ans);
		
		return 0;
	}
	
	int maxSize = sizes[0] + 1;
	for (int sz : sizes) if (sz % 2 == 1) maxSize = min(maxSize, sz);
	
	if (maxSize % 2 == 0) maxSize--;
	
	for (int i = 2; i <= n; i++) {
		dp[i] = sum[i - 2];
		
		if (i - maxSize - 3 >= 0) {
			dp[i] += md - sum[i - maxSize - 3];
			dp[i] %= md;
		}
		
		if (1 <= i - 1 && i - 1 <= maxSize && i % 2 == 0) {
			dp[i] += i;
			dp[i] %= md;
		}
		
		sum[i] = dp[i];
		if (i - 2 > 0) {
			sum[i] += sum[i - 2];
			sum[i] %= md;
		}
	}
	
	printf("%d\n", dp[n]);
	
	return 0;
}


Measured memory_bytes: 2300
x,y,a,b,c=map(int,input().split())
p=[int(i) for i in input().split()]
q=[int(i) for i in input().split()]
r=[int(i) for i in input().split()]
p.sort(reverse=True)
q.sort(reverse=True)
for i in range(x):
    r.append(p[i])
for i in range(y):
    r.append(q[i])
r.sort(reverse=True)
print(sum(r[:x+y]))


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

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> inline T sqr(T x) {return x*x;}

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair
#define each(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define exist(s,e) ((s).find(e)!=(s).end())
#define range(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  range(i,0,n)
#define clr(a,b) memset((a), (b) ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const double eps = 1e-10;
const double pi  = acos(-1.0);
const ll INF =1LL << 62;
const int inf =1 << 29;

struct edge{int to,cost;};
string vertex[110];
vector<edge> graph[110];
int dist[110];

int main(void){
	int n;
	cin >> n; cin.ignore();

	rep(i,n)getline(cin,vertex[i]);
	rep(i,n) vertex[i]=vertex[i].substr(0,vertex[i].size()-1);
	rep(i,n){
		// cerr << vertex[i] << endl;
		if(vertex[i].find("goto")==string::npos)
			graph[i].push_back({i+1,0});
		else{
			string nxt=vertex[i].substr(5);
			// cerr << nxt << endl;
			int idx=-1;
			rep(j,n) if(nxt==vertex[j]) idx=j;
			graph[i].push_back({idx,0});
			graph[i].push_back({i+1,1});
		}
	}
	rep(i,n+1) dist[i]=inf;
	dist[0]=0;
	rep(loop,n)rep(i,n)for(auto &e:graph[i]) dist[e.to]=min(dist[e.to],dist[i]+e.cost);
	cout << dist[n] << endl;
	return 0;
}

Measured memory_bytes: 1240
#n=int(input())
a,b,k=map(int,input().split())
#l=list(map(int,input().split()))
#l=[list(map(int,input().split())) for i in range(n)]
l=[]
for i in range(1,min(a,b)+1):
    if a%i==0 and b%i==0:
        l.append(i)

l.sort(reverse=True)

print(l[k-1])


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

int main(){
    int n;
    cin >> n;
    ll a[n], b[n];
    ll amx = 0;
    ll cnt;
    rep(i, n){
        cin >> a[i] >> b[i];
        amx = max(amx, a[i]);
    }
    rep(i, n){
        if (amx == a[i]) cnt = i;
    }
    cout << b[cnt] + amx << endl;
    return 0;
}

Measured memory_bytes: 1792
#include<iostream>
#include<algorithm>
#include<string>
#include<map>
#define rep(i, n) for(int i=0; i<n; i++)
using namespace std;
typedef long long ll;

int main(){
    int a, b, c, k; cin >> a >> b >> c >> k;
    if(k<=a) cout << k << endl;
    else if(a<k && k<=a+b) cout << a << endl;
    else cout << 2*a+b-k << endl;
}

Measured memory_bytes: 3672
import sys
N, M, *PS = sys.stdin.read().strip().split()
N = int(N)
ac = [0] * N
wa = [0] * N
for p, s in zip(*[iter(PS)] * 2):
  p = int(p) -1
  if s == "AC":
    ac[p] = 1
  elif ac[p] == 0:
    wa[p] += 1
penalties = sum([w if a > 0 else 0 for a, w in zip(ac, wa)])
print("{} {}".format(sum(ac), penalties))

Measured memory_bytes: 17992
#include <bits/stdc++.h>
using namespace std;
// type alias
typedef long long LL;
typedef pair<int,int> II;
typedef tuple<int,int,int> III;
typedef vector<int> VI;
typedef vector<string> VS;
typedef unordered_map<int,int> MAPII;
typedef unordered_set<int> SETI;
template<class T> using VV=vector<vector<T>>;
// minmax
template<class T> inline T SMIN(T& a, const T b) { return a=(a>b)?b:a; }
template<class T> inline T SMAX(T& a, const T b) { return a=(a<b)?b:a; }
// repetition
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define REPE(i,n)  for(int i=0;i<=(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORR(x,arr) for(auto& x:arr)
#define SZ(a) int((a).size())
// collection
#define ALL(c) (c).begin(),(c).end()
// DP
#define MINUS(dp) memset(dp, -1, sizeof(dp))
#define ZERO(dp) memset(dp, 0, sizeof(dp))
// stdout
#define println(args...) fprintf(stdout, ##args),putchar('\n');
// debug cerr
template<class Iter> void __kumaerrc(Iter begin, Iter end) { for(; begin!=end; ++begin) { cerr<<*begin<<','; } cerr<<endl; }
void __kumaerr(istream_iterator<string> it) { (void)it; cerr<<endl; }
template<typename T, typename... Args> void __kumaerr(istream_iterator<string> it, T a, Args... args) { cerr<<*it<<"="<<a<<", ",__kumaerr(++it, args...); }
template<typename S, typename T> std::ostream& operator<<(std::ostream& _os, const std::pair<S,T>& _p) { return _os<<"{"<<_p.first<<','<<_p.second<<"}"; }
#define __KUMATRACE__ true
#ifdef __KUMATRACE__
#define dump(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); __kumaerr(_it, args); }
#define dumpc(ar) { cerr<<#ar<<": "; FORR(x,(ar)) { cerr << x << ','; } cerr << endl; }
#define dumpC(beg,end) { cerr<<"~"<<#end<<": "; __kumaerrc(beg,end); }
#else
#define dump(args...)
#define dumpc(ar)
#define dumpC(beg,end)
#endif

// $ cp-batch BallDistribution | diff BallDistribution.out -
// $ g++ -std=c++14 -Wall -O2 -D_GLIBCXX_DEBUG -fsanitize=address BallDistribution.cpp && ./a.out

/*
 
 6/15/2019
 
 5:00-
 
 */

int N,K;

int solve() {
  if(K==1) return 0;
  return N-K;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout<<setprecision(12)<<fixed;
  
  cin>>N>>K;
  cout<<solve()<<endl;
  
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(i,n) for(int i=0;i<n;i++)
int N, heights[100005];
ll dp[100005];
int main()
{
    cin >> N;
    loop(i, N)
    {
        cin >> heights[i];
    }
    if (N == 1)
    { 
        cout << 0;
        return 0; 
    }
    dp[1] += abs(heights[0] - heights[1]);
    for (int i=2;i<N;i++)
    {
        dp[i] = min(dp[i-2] + abs(heights[i] - heights[i - 2]), dp[i-1] + abs(heights[i] - heights[i - 1]));
    }
    /*loop(i, N)
        cout << dp[i] << " ";
    cout << endl;*/
    cout << dp[N - 1];
}



Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define dunk(a) cout << (a) << endl
#define rall(a) (a).rbegin(),(a).rend()
const int INF = 2e9;
using namespace std;
using Graph = vector<vector<int>>;
typedef pair<int,int> P;
typedef long long ll;

int main(){
    int h; cin >> h;
    vector<int> high(h);
    int tmp = 0;
    int ans = 0;

    rep(i,h){
        cin >> high[i];
        if(tmp <= high[i]) ans++;
        tmp = max(tmp,high[i]);
    }

    dunk(ans);
}


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

int main() {
    int n;
    cin >> n;
    vector<vector<int>> a(n,vector<int>(3));
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < 3; j++) {
            cin >> a[i][j];
        }
    }
    vector<vector<long>> dp(n,vector<long>(3));
    for (int i = 0; i < 3; i++) {
        dp[0][i] = a[0][i];
    }
    for (int i = 1; i < n; i++) {
        for (int j = 0; j < 3; j++) {
            dp[i][j] = 0;
        }
    }
    for (int i = 1; i < n; i++) {
        for (int j = 0; j < 3; j++) {
            for (int k = 0; k < 3; k++) {
                if (j==k) {
                    continue;
                }
                else {
                    dp[i][j] = max(dp[i][j],dp[i-1][k]+a[i][j]);
                }
            }
        }
    }
    cout << max(max(dp[n-1][0],dp[n-1][1]),dp[n-1][2]) << endl;
}


Measured memory_bytes: 11136
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

ans = 0
for i in range(N):
    diff = 0
    if A[i] < B[i]:
        diff = B[i] - A[i]
        tmp = min(A[i+1], diff)
        A[i+1] = A[i+1] - tmp
        ans += A[i] + tmp
    else:
        ans += B[i]

print(ans)

Measured memory_bytes: 82020
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define F first
#define S second

using namespace std;
using P = pair<int,int>;
using ivec = vector<int>;
using Graph = vector<vector<int>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }

const int MOD=1000000007;
int INF=100100100100100;
int add(int a,int b){
  return (a+b)%MOD;
}
int prod(int a,int b){
  return (a*b)%MOD;
}

int beki(int a,int b)
{
	if(b==0)return 1;
	int x=beki(a,b/2);
	if(b%2==0)return (x*x)%MOD;
	else return (((a*x)%MOD)*x)%MOD;
}

int inv(int a)
{
	return beki(a,MOD-2);
}

int kaijou(int a)
{
	int ans=1;
	for(int i=1;i<=a;i++)
	{
		ans=(ans*i)%MOD;
	}			
	return ans;
}

/*int combi(int a,int b)
{
	int ret=1;
	for(int i=1;i<=b;i++)
	{
		ret=(((ret*(a+1-i))%MOD)*inv(i))%MOD;
	}
	return ret;
}*/
/*
const int MAX_a=200010;
int cb[MAX_a+1]
void combi(int a,int b)
{
    int ret=1;
    cb[0]=1;
    for(int i=1;i<=b;i++)
    {
	ret=(((ret*(a+1-i))%MOD)*inv(i))%MOD;
        cb[i]=ret;
    }
	
}*/

vector<P> prime_factorize(int N)
{
	vector<P> res;
	for(int a=2;a*a<=N;a++)
	{
		if(N%a!=0)continue;
		int ex=0;
		while(N%a==0)
		{
			ex++;N/=a;
		}
		res.push_back(P(a,ex));
	}
	if(N!=1)res.push_back(P(N,1));
	return res;
}

//ここから書く
signed main(){
  int l,r,d;cin>>l>>r>>d;
  cout<<r/d-(l-1)/d<<endl;
  return 0;
}

Measured memory_bytes: 3592
#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define ll long long
#define maxn 1000005
#define inf 1e9
#define eps 1e-10
using namespace std;

inline int read()
{
	int x=0,w=1; char c=getchar();
	while(c<'0'||c>'9') {if(c=='-') w=-1; c=getchar();}
	while(c<='9'&&c>='0') {x=(x<<1)+(x<<3)+c-'0'; c=getchar();}
	return w==1?x:-x;
}

int f[maxn],ind[maxn],cnt[maxn];

inline int F(int x)
{
	if(f[x]==x) return x;
	return f[x]=F(f[x]);
}

int main()
{
	int n=read(),m=read(),k=read();
	for(int i=1;i<=n;i++) f[i]=i;
	for(int i=1;i<=m;i++)
	{
		int u=read(),v=read(),fu=F(u),fv=F(v);
		if(fu!=fv) f[fu]=fv; ind[u]++; ind[v]++;
	}
	//for(int i=1;i<=n;i++) cout<<F(i)<<" "; cout<<endl;
	for(int i=1;i<=n;i++)
	{
		int x=F(i); cnt[x]++;
	}
	//for(int i=1;i<=n;i++) cout<<cnt[i]<<" "; cout<<endl;
	for(int i=1;i<=k;i++)
	{
		int u=read(),v=read(),fu=F(u),fv=F(v);
		if(fu!=fv) continue;
		else ind[u]++,ind[v]++;
	}
	for(int i=1;i<=n;i++)
	{
		int x=F(i);
		printf("%d ",cnt[x]-ind[i]-1);
	}
	return 0;
}

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

int main(){
	long long e;
	while ((cin >> e), e){
		long long  x,y, z, min = 1000000;
		for (z = 0; z*z*z <= e; z++){
			for (y = 0; y*y <= e; y++){
				x = e - z*z*z - y*y;
				if (x >= 0 && min > x + y + z)min = x + y + z;
			}
		}
		cout << min << endl;
	}
}

Measured memory_bytes: 1160
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <complex>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#define debug(x) cerr << #x << " = " << (x) << endl;


#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 1010

vector<int> chi[SIZE];
int p[SIZE], x[SIZE];

pair<int,int> dfs(int now){
  
  if(chi[now].size() == 0){
    return {0, x[now]};
  }

  int sum = 0;

  vector<vector<int> > dp(chi[now].size() + 1, vector<int>(x[now]+1, 0));

  dp[0][0] = 1;
  
  for(int i=0;i<chi[now].size();i++){
    auto ret = dfs(chi[now][i]);

    if(ret.first == -1) return {-1,-1};

    int A = ret.first;
    int B = ret.second - ret.first;

    for(int j=0;j<=x[now]-A;j++)
      dp[i+1][j + A] |= dp[i][j];

    for(int j=0;j<=x[now]-B;j++)
      dp[i+1][j + B] |= dp[i][j];

    sum += ret.second;
  }

  for(int i=x[now];i>=0;i--){
    if(dp[chi[now].size()][i]){
      return {x[now], sum + (x[now] - i)};
    }
  }
  
  return {-1, -1};  
}

int main(){
  int n;

  scanf("%d",&n);
  
  p[0] = -1;
  for(int i=1;i<n;i++){
    scanf("%d",p+i);
    chi[p[i]-1].push_back(i);
  }

  for(int i=0;i<n;i++){
    scanf("%d",x+i);
  }

  auto ret = dfs(0);

  if(ret.first != -1){
    puts("POSSIBLE");
  }else{
    puts("IMPOSSIBLE");
  }
  
  return 0;
}



Measured memory_bytes: 13288
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<numeric>
#include<cmath>
#include<queue>
#include<stack>
#include<list>
#include<unordered_map>
#include<unordered_set>

using namespace std;
typedef long long int ll;typedef pair<int, int> P;
const long long mod = 1e9 + 7;
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define ALL(a) (a).begin(),(a).end()

int main(void) {
	ll N, A, B, C, D, E;
	cin >> N >> A >> B >> C >> D >> E;
	cout << max({ (N - 1) / A, (N - 1) / B, (N - 1) / C, (N - 1) / D, (N - 1) / E }) + 5 << endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int a,b,i,j;
  char d[110][110]={};
  scanf("%d %d",&a,&b);
  a--;
  b--;
  printf("100 100\n");
  for(i=0;i<50;i+=2){
    for(j=0;j<100;j+=2){
      d[i][j]=d[i+1][j]=d[i][j+1]=d[i+1][j+1]='#';
      if(a){
	d[i][j]='.';
	a--;
      }
    }
  }
  for(i=50;i<100;i+=2){
    for(j=0;j<100;j+=2){
      d[i][j]=d[i+1][j]=d[i][j+1]=d[i+1][j+1]='.';
      if(b){
	d[i+1][j]='#';
	b--;
      }
    }
  }
  for(i=0;i<100;i++)printf("%s\n",d[i]);
  return 0;
}


Measured memory_bytes: 128