akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int N;
    cin >> N;
	vector<int> A(N);
    for (int i=0; i<N; i++) {
        cin >> A.at(i);
    }

    int ANS = 0;
    int start = 0;
    int flag = 0;
    for (int state=1; state<200001; state++) {
        for (int i=start; i<N; i++) {
            if (A.at(i) == state) {
                flag = 1;
                ANS++;
                start = i+1;
                break;
            }
        }
        if (flag) {
          flag = 0;
        } else {
          break;
        }
    }

    if (ANS == 0) {
        cout << -1 << endl;
    } else {
        cout << N - ANS << endl;
    }
}


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

#define watch(x) cout << (#x) << " = " << x << endl;
#define mkp make_pair
#define mkt make_tuple
#define pb push_back
#define ll long long
#define ld long double

using namespace std;

int main(){

	int n, k, dp[100010], h[100010];

	scanf("%d%d", &n, &k);

	for(int i = 1; i <= n; i++) scanf("%d", &h[i]);

	dp[0] = 1e9;
	dp[1] = 0;
	
	for(int i = 2; i <= n; i++){
		dp[i] = 1e9;
		for(int j = 1; j <= k; j++){
			if(i - j > 0) dp[i] = min(dp[i], abs(h[i] - h[i - j]) + dp[i - j]);
		}
	}

	printf("%d\n", dp[n]);

	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 1e5+7;
set<int> tirar[MAXN];
int n, f, b, pai[MAXN], tam[MAXN];

int raiz(int x){return (x==pai[x]) ? x : pai[x] = raiz(pai[x]);}
void unite(int x, int y){
    x = raiz(x); y = raiz(y);
    if(x==y)return;
    tam[y] += tam[x];
    pai[x] = y;
}

int main(){
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    cin>>n>>f>>b;
    for(int i=1; i<=n; i++){
        pai[i] = i;
        tirar[i].insert(i);
        tam[i] = 1;
    }
    for(int i=1; i<=f; i++){
        int xi, yi;
        cin>>xi>>yi;
        tirar[xi].insert(yi);
        tirar[yi].insert(xi);
        unite(xi, yi);
    }
    for(int i=1; i<=b; i++){
        int xi,yi;
        cin>>xi>>yi;
        if(raiz(xi) != raiz(yi))continue;
        tirar[xi].insert(yi);
        tirar[yi].insert(xi);
    }
    for(int i=1; i<=n; i++){
        if(i>1)cout<<" ";
        int j = raiz(i);
        cout<<tam[j] - (int)tirar[i].size();
    }
    cout<<endl;
}

Measured memory_bytes: 30336
import numpy as np
N , M = map(int, input().split())
P = [0]*M
Y = [0]*M
for i in range(M):
    P[i],Y[i] =  map(int, input().split())

Y_ = np.argsort(Y)
count = [1]*(N+1)
ans = [0]*M
for i in range(M):
    ans[Y_[i]] = str(P[Y_[i]]).zfill(6) + str(count[P[Y_[i]]]).zfill(6)
    count[P[Y_[i]]] = count[P[Y_[i]]] +1
 
for i in range (M):
    print(ans[i])

Measured memory_bytes: 30888
#include <iostream>
#include <iterator>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <numeric>
#include <iomanip>
#include <limits>

using namespace std;

int main(){

    int n;
    cin>>n;

    vector<int> a;

    for(int i=0;i<n;i++){
        int b=0;
        cin>>b;
        a.push_back(b);
    }

    bool ans=true;

    for(int i=0;i<n;i++){
        if(a[i]%2==0){
            if(a[i]%3!=0 && a[i]%5!=0){
                ans=false;
            }
        }
    }

    if(ans){
        cout<<"APPROVED"<<endl;

    }
    else{
        cout<<"DENIED"<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
typedef long long ll;

ll h, w, n;
string s, t;
int ch_sum_s[300];
int ch_sum_t[300];

ll u, l, r, d;

int main()
{
    ll sx, sy;
    bool f = true;
    
    cin >> h >> w >> n;
    cin >> sy >> sx;
    cin >> s;
    cin >> t;

    u = d = sy;
    l = r = sx;

    for (int i = 0; i < n; i++) {

        switch(s[i]) {
        case 'U':
            u--;
            break;
        case 'L':
            l--;
            break;
        case 'R':
            r++;
            break;
        case 'D':
            d++;
            break;
        }

        if (u <= 0 || d > h ||
            l <= 0 || r > w) {
            f = false;
        }

        switch(t[i]) {
        case 'U':
            d = max(d - 1, 1ll);
            break;
        case 'L':
            r = max(r - 1, 1ll);
            break;
        case 'R':
            l = min(l + 1, w);
            break;
        case 'D':
            u = min(u + 1, h);
            break;
        }
    }

    puts(f ? "YES" : "NO");

    return 0;
}


Measured memory_bytes: 776
#include<iostream>
#include<unordered_map>
#include<bitset>
#include<math.h>
#include<vector>
#include<set>
#include<algorithm>
#include<ctype.h>
#include<unordered_set>
#include<string>
#include<iomanip>
#include<queue>
#include<limits>
#include<map>
#include<stack>
#include<iterator>
#include<cstring>
#include<deque>
#include<chrono>
using namespace std;
#define pi 3.141592653589793238


#define MOD 1000000007
#define INF 999999999999999999 
#define pb push_back
#define ff first
#define ss second
#define mt make_tuple
#define ll long long
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define f0 get<0>
#define f1 get<1>
#define f2 get<2>
typedef vector<ll> vi;
typedef vector<vi> vvi;


////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
const int N = 1e6 + 1;
ll m2[N];
ll m[N];
ll cnt[N];
int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    fast;
    ll T = 1, i, j;
    
    
    //cin >> T;
    while (T--) {
       ll n;
       cin >> n;
       vector<ll> v(n);
       
       for(i =0; i < n; i++){
           cin >> v[i];
           m[v[i]] = 1;
           cnt[v[i]]++;
       } 
       
        for(i = 1;i < N; i++){
            for(j = i; j < N; j+= i){
                if(cnt[j] == 1){
                    if(j == i){
                        continue;
                    }
                }
                if(m[i] == 1){
                    m2[j] = 1;
                }
            }
        }
        ll count = 0;
        for(i = 0; i < n; i++){
            if(m2[v[i]] == 0){
                count++;
                //cout << i + 1 <<" ";
            }
        }
        cout << count;
    }

    return 0;
}


Measured memory_bytes: 28232
import bisect
import math

N,K = map(int, input().split())
X = list(map(int, input().split()))
a = bisect.bisect_left(X,0)
X.insert(a,0)

ans = math.inf

for i in range(max(0,a+K-N), min(a+1,K+1)):
    ans = min(ans, -X[a-i]*2+X[a+K-i], -X[a-i]+X[a+K-i]*2)

print(ans)

Measured memory_bytes: 20288
n = int(input())
import math as m
if n < 4:
  print(1)
  exit(0)
  
perfect = 1
for b in range(2,int(n**0.5)+1):
  p = int(m.log(n,b))
  x = b**(p+1)
  if x > n:
    x = b**p
  perfect = max(perfect,x)
  #print(b,x)
  if perfect == n:
    break

print(perfect)


Measured memory_bytes: 9436
#include <bits/stdc++.h>
     
    using namespace std;
     
    typedef long long ll;
    typedef long double ld;
     
    int main()
    {
        ios_base::sync_with_stdio(false);
        cin.tie(0);
        int n;
        cin>>n;
        if(n%2==0)cout<<n<<"\n";
        else
            cout<<2*n<<"\n";
        return 0;
    }
    /**
     
    **/

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <iomanip>
#include <bitset>
#include <set>
#include <map>
#include <stdio.h>
#include <numeric>
#include <cstring>

#define rep(i,n) for (int i = 0; i < (n); i++)
#define rep1(i,n) for (int i = 1; i < (n); i++)
#define FOR(i,a,b) for (int i=(a); i < (b); i++)
#define MOD 1000000007 //10^9+7
#define TEN5 100000 //10^5
#define TEN9 1000000000 //10^9
using namespace std;
using ll = long long;
using PII = pair<int, int>;
const int INF = numeric_limits<int>::max();

// 負の数にも対応した % 演算
long long mod(long long val, long long m) {
    long long res = val % m;
    if (res < 0) res += m;
    return res;
}

//greatest common divisor
long long gcd(ll a, ll b) 
{
    if (a % b == 0) {
        return b;
    } else {
        return gcd(b, a % b);
    }
}

//least common multiple
long long lcm(ll a, ll b)
{
    return a / gcd(a, b) * b ;
}

int main()
{
    int a, b, c;
    cin >> a >> b >> c;
    for(int i = a; i <= a * b; i+=a) {
        if (i % b == c) {
            cout << "YES" << endl;
            return 0;
        }
    }
    cout << "NO" << endl;
    return 0;
}



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

int main() {
  string S;
  long int y;
  long int a, b, c;
  cin >> a >> b >> c;
  
  if (a%2!=0 && b%2 !=0 && c%2 !=0) {
    y= min(a*b, b*c);
    y= min(y, a*c);
  }
  else y=0;
  
  cout << y << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    char c;
    cin>>c;
    if (c=='a') {
        cout<<'b'<<endl;
    } else if (c=='b') {
        cout<<'c'<<endl;
    } else if (c=='c') {
        cout<<'d'<<endl;
    } else if (c=='d') {
        cout<<'e'<<endl;
    } else if (c=='e') {
        cout<<'f'<<endl;
    } else if (c=='f') {
        cout<<'g'<<endl;
    } else if (c=='g') {
        cout<<'h'<<endl;
    } else if (c=='h') {
        cout<<'i'<<endl;
    } else if (c=='i') {
        cout<<'j'<<endl;
    } else if (c=='j') {
        cout<<'k'<<endl;
    } else if (c=='k') {
        cout<<'l'<<endl;
    } else if (c=='l') {
        cout<<'m'<<endl;
    } else if (c=='m') {
        cout<<'n'<<endl;
    } else if (c=='n') {
        cout<<'o'<<endl;
    } else if (c=='o') {
        cout<<'p'<<endl;
    } else if (c=='p') {
        cout<<'q'<<endl;
    } else if (c=='q') {
        cout<<'r'<<endl;
    } else if (c=='r') {
        cout<<'s'<<endl;
    } else if (c=='s') {
        cout<<'t'<<endl;
    } else if (c=='t') {
        cout<<'u'<<endl;
    } else if (c=='u') {
        cout<<'v'<<endl;
    } else if (c=='v') {
        cout<<'w'<<endl;
    } else if (c=='w') {
        cout<<'x'<<endl;
    } else if (c=='x') {
        cout<<'y'<<endl;
    } else if (c=='y') {
        cout<<'z'<<endl;
    }
}


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

using namespace std;
const int maxn = 1e5+10;

int n, k;
int niz[maxn];

int main() {
    scanf("%d%d", &n, &k);
    for (int i = 0; i < n; i++)
        scanf("%d", niz+i);

    int cnt = 0;
    for (int i = 0; i < n; i++)
        cnt += (niz[i] >= k);
    printf("%d", cnt);
    return 0;
}


Measured memory_bytes: 640
using System;
using System.Collections.Generic;
using System.Linq;

namespace ABC145C_2
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            int[] x = new int[N];
            int[] y = new int[N];
            for (int i = 0; i < N; i++)
            {
                var xy = ReadInt();
                x[i] = xy[0];
                y[i] = xy[1];
            }

            double ans = 0;
            List<int> towns = new List<int>();
            for (int i = 0; i < N; i++)
            {
                towns.Add(i);
            }
            foreach (var item in GetPermutation(towns))
            {
                double distance = 0;
                for (int i = 1; i < item.Length; i++)
                {
                    int d1 = x[item[i]] - x[item[i - 1]];
                    int d2 = y[item[i]] - y[item[i - 1]];
                    distance += Math.Pow(d1 * d1 + d2 * d2, 0.5);
                }
                ans += distance;
            }
            for (int i = 0; i < N; i++)
            {
                ans /= i + 1;
            }

            Console.WriteLine(ans);
            Console.ReadKey();
        }

        public static IEnumerable<T[]> GetPermutation<T>(IEnumerable<T> collection)
        {
            // 未確定要素が一個のみ
            if (collection.Count() == 1)
            {
                yield return new T[] { collection.First() };
            }

            foreach (var item in collection)
            {
                var selected = new T[] { item };
                var unused = collection.Except(selected);

                // 確定した要素以外の組み合わせを再帰で取り出し連結
                foreach (var rightside in GetPermutation(unused))
                {
                    yield return selected.Concat(rightside).ToArray();
                }
            }
        }



        static int[] ReadInt()
        {
            int[] ret = Console.ReadLine().Split().Select(int.Parse).ToArray();
            return ret;
        }
        static long[] ReadLong()
        {
            long[] ret = Console.ReadLine().Split().Select(long.Parse).ToArray();
            return ret;
        }
    }
}


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




void testcase()
{
	ll d,t,s;
	float f;
	cin>>d>>t>>s;
	f = (float)d/s;
	if(f<=t)
		cout<<"Yes";
	else
		cout<<"No";
}


int main()
{
	ll t,test;
	//cin>>test;
	//for(t=0;t<test;t++)
		testcase();
}


Measured memory_bytes: 3620
from itertools import accumulate, permutations

import bisect
# ----------

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

N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

A = [0] + list(accumulate(A))
B = [0] + list(accumulate(B))

ans = 0
for i in range(N+1):
    a = A[i]
    if a > K:
        break
    r = K - a
    j = bisect.bisect(B, r) - 1
    ans = max(ans, i + j)

print(ans)


Measured memory_bytes: 41192
def main():
    from sys import setrecursionlimit, stdin, stderr
    from os import environ
    from collections import defaultdict, deque, Counter
    from math import ceil, floor
    from itertools import accumulate, combinations, combinations_with_replacement
    setrecursionlimit(10**6)
    dbg = (lambda *something: stderr.write("\033[92m{}\033[0m".format(str(something)+'\n'))) if 'TERM_PROGRAM' in environ else lambda *x: 0
    input = lambda: stdin.readline().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    P = 10**9+7
    INF = 10**18+10

    N,K = LMIIS()
    A = LMIIS()
    out = []
    for i in range(K,N):
        if A[i-K] < A[i]:
            out.append('Yes')
        else:
            out.append('No')
    print('\n'.join(out))



    
main()

Measured memory_bytes: 106708
#include<bits/stdc++.h> //Ithea Myse Valgulious
namespace chtholly{
typedef long long ll;
#define re0 register int
#define rel register ll
#define rec register char
#define gc getchar
#define pc putchar
#define p32 pc(' ')
#define pl puts("")
/*By Citrus*/
inline int read(){
  int x=0,f=1;char c=gc();
  for (;!isdigit(c);c=gc()) f^=c=='-';
  for (;isdigit(c);c=gc()) x=(x<<3)+(x<<1)+(c^'0');
  return f?x:-x;
  }
template <typename mitsuha>
inline bool read(mitsuha &x){
  x=0;int f=1;char c=gc();
  for (;!isdigit(c)&&~c;c=gc()) f^=c=='-';
  if (!~c) return 0;
  for (;isdigit(c);c=gc()) x=(x<<3)+(x<<1)+(c^'0');
  return x=f?x:-x,1;
  }
template <typename mitsuha>
inline int write(mitsuha x){
  if (!x) return 0&pc(48);
  if (x<0) pc('-'),x=-x;
  int bit[20],i,p=0;
  for (;x;x/=10) bit[++p]=x%10;
  for (i=p;i;--i) pc(bit[i]+48);
  return 0;
  }
inline char fuhao(){
  char c=gc();
  for (;isspace(c);c=gc());
  return c;
  }
}using namespace chtholly;
using namespace std;
 
int main(){
int n,k;
cin>>n>>k;
cout<<(n%k?1:0)<<endl;
}

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

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vi d(n);
  for (int i = 0; i < n; i++) {
    cin >> d[i];
  }
  sort(d.begin(), d.end());
  if (d[n / 2] == d[n / 2 - 1]) {
    cout << 0 << endl;
  } else {
    cout << d[n / 2] - d[n / 2 - 1] << endl;
  }
  return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double PI = acos(-1);
const ll MOD = 1000000007;

int w,h;
using Graph = vector<vector<int>>;

void dfs(Graph &G, int y, int x) {
  G[y][x] = 0;
  const vector<int> dy = {-1,-1,-1,0,0,1,1,1};
  const vector<int> dx = {-1,0,1,-1,1,-1,0,1};
  for (int i = 0; i < 8; i++) {
    int yy = y + dy[i];
    int xx = x + dx[i];
    if (yy < 0 || yy >= h || xx < 0 || xx >= w) continue;
    if (G[yy][xx] == 0) continue;
    dfs(G,yy,xx);
  }
  return;
}

int main() {
  while (true) {
    cin >> w >> h;
    if (w == 0 && h == 0) break;
    Graph G(h, vector<int>(w));
    for (int i = 0; i < h; i++) {
      for (int j = 0; j < w; j++) cin >> G[i][j];
    }
  
    int count = 0;
    for (int i = 0; i < h; i++) {
      for (int j = 0; j < w; j++) {
        if (G[i][j] == 0) continue;
        dfs(G,i,j);
        count++;
      }
    }
  
    cout << count << endl;
  }
}


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

int main(){

int N;
int ans=1;
scanf("%d",&N);
int A[N];

for (int i = 0; i < N; i++){
    scanf("%d",&A[i]);
    if(A[i]%2==0){
      A[i] = A[i]/2;
    }else{
      puts("0");
      exit(0);
    }
}

while (1)
{
  for (int i = 0; i < N; i++){
    if(A[i]%2==0){
      A[i] = A[i]/2;
    }
    else{
      printf("%d",ans);
      exit(0);
    }
  }
  ans++;
}

return 0;

}

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

int main() {
 int a;
 cin >> a;
 if(a == 25) cout << "Christmas" << endl;
 else if(a == 24) cout << "Christmas Eve" << endl;
 else if(a == 23) cout << "Christmas Eve Eve" << endl;
 else cout << "Christmas Eve Eve Eve" << endl; 
}

  

  


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

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

    double n = 100;
    int ans = 0;
    while(n<x){
        n +=  floor(n * 0.01);
        ans++;
    }
    
    cout << ans << endl;
}

Measured memory_bytes: 3636
class Integer
  def combination(k = self) # 4C2 = 6
    return 1 if k.zero?
    (self - k + 1..self).inject{|i,m|i * m % (10**9 + 7)} * k.factorial.modinv % (10**9 + 7)
  end

  def factorial(step = 1) # 4! = 24
    return 1 if self.zero?
    (1..self).inject{|i,m|i * m % (10**9 + 7)}
  end

  def modinv(m = 10**9 + 7)
    a = self
    b = m
    u = 1
    v = 0
    while b > 0
      t = a / b
      a -= t * b
      a, b = b, a
      u -= t * v
      u, v = v, u
    end
    u %= m
    u += m if u < 0
    u
  end
end

n, k = gets.split.map(&:to_i)
ao  = k
aka = n - k
1.upto(ao) do |i|
  p (aka+1).combination(i) % (10**9 + 7) * (ao-1).combination(i-1) % (10**9 + 7)
end


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

//~ const int MOD=998244353;
const int MOD=1000000007;
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;


void convert(vector<ll>&A){
	int idx=0;
	for(int i=60;i>=0;i--){
		bool flag=false;
		for(int j=idx;j<A.size();j++){
			if(A[j]>>i&1){
				flag=true;
				swap(A[idx],A[j]);
				break;
			}
		}
		for(int j=idx+1;j<A.size();j++){
			if(A[j]>>i&1){
				A[j]^=A[idx];
			}
		}
		if(flag)idx++;
	}	
}

bool can_make(vector<ll>A,ll x){
	convert(A);
	int j=0;
	for(int i=60;i>=0;i--){
		if(x>>i&1){
			for(;j<A.size();j++){
				if(A[j]>=(1LL<<(i+1)))continue;
				if(A[j]>>i&1){
					x^=A[j];
					j++;
					break;
				}
			}
			if(x>>i&1)return false;
		}
	}
	return true;
}

int n;
ll a[3000];
string s;

int main(){
	int T;cin>>T;
	rep(Case,T){
		scanf("%d",&n);
		rep(i,n)scanf("%lld",&a[i]);
		cin>>s;
		vector<ll>v;
		for(int i=n-1;i>=0;i--){
			if(s[i]=='0')v.push_back(a[i]);
			else{
				if(!can_make(v,a[i])){
					puts("1");goto g;
				}
			}
		}
		puts("0");
		g:;
	}
}

Measured memory_bytes: 3720
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a,b;
  
  // 変数aで入力を受け取る
  cin >> a;
  cin >> b;
  if (a % 500 <= b){
    cout << "Yes" << endl;}
  else {
    cout << "No" << endl;}
    


}

Measured memory_bytes: 3644
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

/**
 * Main
 */
public class Main {

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

        int N = sc.nextInt();


        Map<Integer, Integer> A = new HashMap<Integer, Integer>();
        for(int i=0; i < N; i++){
            A.put(sc.nextInt(),i+1);
        }


        for(int i = 1; i < N+1; i++){
            System.out.println(A.get(i));
        }
    }
}

Measured memory_bytes: 71220
#include <iostream>

using namespace std;

int main(){
	int r, c;
	cin >> r >> c;
	int table[101][101] = {};
	for(int i = 0; i < r; i++){
		for(int j = 0; j < c; j++){
			int e;
			cin >> e;
			table[i][j] = e;
			table[r][j] += e;
			table[i][c] += e;
			table[r][c] += e;
		}
	}

	for(int i = 0; i < r + 1; i++){
		for(int j = 0; j < c + 1; j++){
			cout << table[i][j];
			if(j != c) cout << " ";
		}
		cout << endl;
	}

	return 0;
}

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

int main() {
	int N, X, T;
	cin >> N >> X >> T;
	int A = N / X;

	if (N % X == 0) {
		cout << A * T;
	}
	else {
		cout << (A + 1) * T;
	}

	return 0;
}

Measured memory_bytes: 3564
ABCD = input()


a,b,c,d = [int(s) for s in ABCD]

def f():
    for i in [-1,1]:
        for j in [-1,1]:
            for k in [-1,1]:
                if a + i*b + j*c + k*d == 7:
                    return i,j,k
i,j,k = f()

def conv(v):
    if v == 1:
        return "+"
    else:
        return "-"

print("{}{}{}{}{}{}{}=7".format(a,conv(i),b,conv(j),c,conv(k),d))


Measured memory_bytes: 3064
c11,c12,c13=map(int,input().split())
c21,c22,c23=map(int,input().split())
c31,c32,c33=map(int,input().split())
f=0
if not c11-c12==c21-c22==c31-c32:
    f=1
if not c11-c13==c21-c23==c31-c33:
    f=1
if not c12-c13==c22-c23==c32-c33:
    f=1
if not c11-c21==c12-c22==c13-c23:
    f=1
if not c11-c31==c12-c32==c13-c33:
    f=1
if not c21-c31==c22-c32==c23-c33:
    f=1
print("Yes" if f==0 else "No")


Measured memory_bytes: 61664
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl "\n"
#define MOD 1000000007
void fastio(){ios_base::sync_with_stdio(false);cin.tie(NULL);}
ll int power(ll int x, ll int y, ll int p)  
{  
   ll int res = 1;     // Initialize result  
 
    x = x % p; // Update x if it is more than or  
                // equal to p
   
    if (x == 0) return 0; // In case x is divisible by p;
 
    while (y > 0)  
    {  
        // If y is odd, multiply x with result  
        if (y & 1)  
            res = (res*x) % p;  
 
        // y must be even now  
        y = y>>1; // y = y/2  
        x = (x*x) % p;  
    }  
    return res;  
}  
ll int dp[2005];
ll int solve(ll int n)
{
  if(n<0)
    return 0ll;
  if(n==0)
    return 1;
  if(dp[n]!=-1)
    return dp[n];
  ll int ans=0;ll int i;
  for(i=3;i<=n;i++)
    {ans+=solve(n-i);ans%=MOD;}
  dp[n]=ans;
  return ans;
}
int main()
{
   ll int T;
T=1;


    while(T--)
    {
      ll int n;
      cin>>n;
       int i;
      vector< int>v1,v2;
      //map<ll int,ll int> mx,mn;

      for(i=0;i<n;i++)
      {
        ll int p,q;
        cin>>p>>q;
        v1.push_back(p);
        v2.push_back(q);

      }
      int m1=INT_MIN;
        int m3=INT_MIN;
        int m5=INT_MIN;
        int m7=INT_MIN;
        int m2=INT_MAX;
        int m4=INT_MAX;
        int m6=INT_MAX;
        int m8=INT_MAX;
       // ll int i;
        for(int i=0;i<v1.size();i++){
            m1=max(m1,v1[i]+v2[i]);
            m2=min(m2,v1[i]+v2[i]);
            m3=max(m3,v1[i]-v2[i]);
            m4=min(m4,v1[i]-v2[i]);
            m5=max(m5,v1[i]+v2[i]);
            m6=min(m6,v1[i]+v2[i]);
            m7=max(m7,v1[i]-v2[i]);
            m8=min(m8,v1[i]-v2[i]);
        }
        
        int val1=m1-m2;
        int val2=m3-m4;
        int val3=m5-m6;
        int val4=m7-m8;
        ll int ans= max(max(val1,val2),max(val3,val4));
        cout<<ans<<endl;
     
    }

    return 0;
       }

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

int main() {
  int N;
  string S;
  cin >> N >> S;
  string::size_type pos = 0;
  int ans = 0;
  while(true) {
    pos = S.find("ABC", pos);
    if(pos == string::npos) {
      break;
    }
    ans++;
    pos++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
using LL = long long;
const LL LINF = 1e18;
using namespace std;
#define COUT(v) cout<<(v)<<endl
#define CIN(n)  int(n);cin >> (n)
#define SCIN(n) string(n);cin >> (n)
#define YES(n) cout<<((n)? "YES" : "NO")<<endl
#define Yes(n) cout<<((n)? "Yes" : "No")<<endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) <<endl

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

#define FOREACH(x,a) for(auto& (x) : (a) )

#define ALL(obj) (obj).begin(),(obj).end()

#define P pair<int,int>
#define I vector<int>
#define S set<int>
#define pb(v) push_back(v)
#define V vector
#define rt return
#define rmsame(a) sort(ALL(a)),a.erase(unique(ALL(a)), a.end())

typedef string::const_iterator State;
class PalseError {};
class Edge{
public:
    int from,to,value;
    Edge(int a,int b,int c){
        from = a;
        to = b;
        value = c;
    }
    Edge(int a,int b){
        from = a;
        to = b;
    }
};
int calc(int n,I vec){
    int ins = 0;
    REP(a,vec.size()){
        ins += abs(vec.at(a)-n);
    }
    return ins;
}
int main(){
    CIN(N);
    string str;
    cin >> str;
    int ins = 0;
    int ins1 = 0;
    REP(a,N){
        if(str.at(a) == ')'){
            if(ins >= 1)ins--;
        }else{
            ins++;
        }
    }
    for(int a = str.size()-1;a >= 0;a--){
        if(str.at(a) == '('){
            if(ins1 >= 1)ins1--;
        }else{
            ins1++;
        }
    }
    REP(a,ins1){
        cout<<"(";
    }
    cout<<str;
    REP(a,ins){
        cout<<")";
    }
    cout<<endl;
    return 0;
}


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

using ll = long long;
#define ff first
#define ss second

void solve()
{
	int n;
	cin>>n;
	int x = (n - 1) / 3 + 1;
	if (n % 3 != 0) x--;
	cout<<x<<endl;
}

int main()
{
	int t = 1;
	//cin>>t;
	while(t--)
	{
		solve();
	}
}


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

# define REP(i,n) for (int i=0;i<(n);++i)
# define rep(i,a,b) for(int i=a;i<(b);++i)
# define p(s) std::cout << s ;
# define pl(s)  std::cout << s << endl;
# define printIf(j,s1,s2) cout << (j ? s1 : s2) << endl;
# define YES(j) cout << (j ? "YES" : "NO") << endl;
# define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
# define yes(j) std::cout << (j ? "yes" : "no") << endl;
# define all(v) v.begin(),v.end()
# define showVector(v) REP(i,v.size()){p(v[i]);p(" ")} pl("")
template<class T> inline bool chmin(T &a, T b){ if(a > b) { a = b; return true;} return false;}
template<class T> inline bool chmax(T &a, T b){ if(a < b) { a = b; return true;} return false;}
typedef long long int ll;
typedef pair<ll,ll> P_ii;
typedef pair<double,double> P_dd;

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<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}

template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
  for(auto &e:t) fill_v(e,v);
}


const int MOD = 1000000007;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;

void addM(long long &a, long long b) {
    a += b;
    if (a >= MOD) a -= MOD;
}

void mulM(long long &a, long long b) {
    a = ((a%MOD)*(b%MOD))%MOD ;
}

const int MAX = 510000;
long long fac[MAX], finv[MAX], inv[MAX];

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

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

vector<pair<long long, long long> > prime_factorize(long long n) {
    vector<pair<long long, long long> > res;
    for (long long p = 2; p * p <= n; ++p) {
        if (n % p != 0) continue;
        int num = 0;
        while (n % p == 0) { ++num; n /= p; }
        res.push_back(make_pair(p, num));
    }
    if (n != 1) res.push_back(make_pair(n, 1));
    return res;
}


int main() {
    int N, K;
    cin >> N >> K;

    int ans = 0;
    REP(i, N) {
        int h;
        cin >> h;
        if(h >= K) ans++;
    }

    cout << ans << endl;

    return 0;
}


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

void solve() {
    cin >> N;
    set<string> s;
    for (int i = 0; i < N; ++i) {
        string x;
        cin >> x;
        s.insert(x);
    }
    cout << s.size() << endl;
}

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


Measured memory_bytes: 19228
import sys
input = sys.stdin.readline
from collections import deque


def read():
    N = int(input().strip())
    S = []
    for i in range(N):
        s = input().strip()
        S.append(s)
    return N, S


def solve(N, S):
    count = 0
    for s in S:
        for j in range(len(s)):
            if s[j:j+2] == "AB":
                count += 1
    head_b = []
    tail_a = []
    for i, s in enumerate(S):
        if s[0] == "B":
            head_b.append(i)
        if s[-1] == "A":
            tail_a.append(i)
    head_b = list(sorted(head_b))
    tail_a = list(sorted(tail_a))
    if len(head_b) == 0 or len(tail_a) == 0:
        return count
    # is_same?
    if len(head_b) == len(tail_a):
        is_same = True
        for b, a in zip(head_b, tail_a):
            if b != a:
                is_same = False
                break
        if is_same:
            count -= 1
    return count + min(len(head_b), len(tail_a))


if __name__ == '__main__':
    inputs = read()
    print(solve(*inputs))


Measured memory_bytes: 4716
#include<stdio.h>
#include<limits.h>
#include <stdlib.h>
#include<string.h>
#include<stdbool.h>

#define CARD_TOTAL_NUM (52)
enum Card_types {
	S,
	H,
	C,
	D,
	TOTAL
};

int main(){
	int n=0;


	bool Poss_card[TOTAL][CARD_TOTAL_NUM/4]={false};


	scanf("%d",&n);

	for(int i=0;i<n;i++){
		char card_type=0;
		int num=0;

		scanf("\n%c %d",&card_type,&num);
		//printf("i=%2d: num=%d\n",i,num);
		switch (card_type) {
		case 'S':
			Poss_card[S][num-1]=true;
			break;
		case 'H':
			Poss_card[H][num-1]=true;
			break;
		case 'C':
			Poss_card[C][num-1]=true;
			break;
		case 'D':
			Poss_card[D][num-1]=true;
			break;
		default:
			break;
		}
		for(int i=0;i<TOTAL;i++){
		}
	}
	for(int i=0;i<TOTAL;i++){
		for(int j=0;j<CARD_TOTAL_NUM/4;j++){
			if(Poss_card[i][j]==false){
				switch (i){
				case S:
					printf("S ");
					break;
				case H:
					printf("H ");
					break;
				case C:
					printf("C ");
					break;
				case D:
					printf("D ");
					break;
				default:
					break;
				}
				printf("%d\n",j+1);
			}
		}
	}


	return 0;
}




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

int main(void){
    int N, M, Q, abuf, bbuf, cbuf, dbuf;
    vector<int> a, b, c, d;
    cin >> N >> M >> Q;
    for(int i=0; i<Q; i++){
        cin >> abuf >> bbuf >> cbuf >> dbuf;
        a.push_back(abuf);
        b.push_back(bbuf);
        c.push_back(cbuf);
        d.push_back(dbuf);
    }
    vector<int> A(N, 1);
    int dmax = 0;
    while(A[0]<M){
        dbuf = 0;
        for(int i=0; i<Q; i++){
            if(A[b[i]-1]-A[a[i]-1]==c[i])dbuf+=d[i];
        }
        if(dmax < dbuf)dmax=dbuf;
        bool nextinc = true;
        for(int i=1; i<=N; i++){
            if(!nextinc)break;
            A[N-i]++;
            if(i<N){
                if(A[N-i]>M){
                    for(int j=i; j>0; j--){
                        A[N-j]=A[N-i-1]+1;
                    }
                }else{
                    nextinc = false;
                }
            }
        }
    }
    dbuf = 0;
    for(int i=0; i<Q; i++){
        if(A[b[i]-1]-A[a[i]-1]==c[i])dbuf+=d[i];
    }
    if(dmax < dbuf)dmax=dbuf;
    cout << dmax << endl;
    return 0;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,n,s) for(int i = s; i < (n); ++i)
#define rsrep(i,n,s) for(int i = (n)-1; i >= s; --i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aall(a) (a), (a)+countof(a)//for array sorting
#define raall(a) (a), (a)+countof(a), greater<>()
#define show(x) cout<<#x<<" = "<<x<<endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) { if (f) puts("YES"); else puts("NO"); }
#define yns(f) { if (f) puts("Yes"); else puts("No"); }
#define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define out_ary(...) { for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define argmax(v) distance((v).begin(), max_element(all(v)))
#define argmin(v) distance((v).begin(), min_element(all(v)))
#define vmax(v) *max_element(all(v))
#define vmin(v) *min_element(all(v))
typedef long long int ll;
typedef vector<int> vint;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef vector<vint> vvint;
typedef vector<vstr> vvstr;
const ll LINF = 2000000000000000000ll;
const int INF = 1000000100;
const ll MOD = 1e9+7;

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

    ll ans = 1;
    rep(i, n) {
        ans *= (i + 1);
        ans %= MOD;
    }
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long n,a,b;
long long h[100100],tmp[100100];
bool check(long long mid){
	for(int i=1;i<=n;i++)
		tmp[i]=max(h[i]-b*mid,0LL);
	for(int i=1;i<=n;i++){
		if(tmp[i]>0){
			mid=mid-(tmp[i]-1)/(a-b)-1;
		}
	}
	return mid>=0;
}
int main(){
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>n>>a>>b;
	for(int i=1;i<=n;i++){
		cin>>h[i];
	}
	long long le=0,ri=1e9;
	while(le!=ri){
		long long mid=(le+ri)/2;
		if(check(mid))
			ri=mid;
		else
			le=mid+1;
	}
	cout<<le<<endl;
	return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=int(a);i<int(b);i++)
typedef long long ll;


int main(){
    ll n;cin>>n;
    set<string> s;
    rep(i,0,n){
        string a;cin>>a;
        s.insert(a);
    }
    cout<<s.size()<<endl;
    
}
    









Measured memory_bytes: 19220
#include <iostream>
#include <vector>
#include <unordered_map>
#include <map>
#include <algorithm>
#include <set>
#include <unordered_set>
#include <deque>
#include <cmath>
#include <stack>
#include <queue>
#include <string>
#include <locale>
#include <iomanip>

#define nl '\n';

using namespace std;

string s;

int main(){

    cin >> s;

    if(s == "SUN"){
        cout << 7;
        return 0;
    } else if(s == "MON"){
        cout << 6;
        return 0;
    } else if(s == "TUE"){
        cout << 5;
        return 0;
    } else if(s == "WED"){
        cout << 4;
        return 0;
    } else if(s == "THU"){
        cout << 3;
        return 0;
    } else if(s == "FRI"){
        cout << 2;
        return 0;
    } else if(s == "SAT"){
        cout << 1;
        return 0;
    }




}

//g++ -std=c++14 comp.cpp -o b; ./b.exe
//g++ -std=c++14 comp.cpp && ./a.out

// char** arr = new char*[r];
// for(long long i = 0; i < r; i++) arr[i] = new char[c];

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

int main() {
	int n, taroP, hanakoP;
	string taroC, hanakoC;

	taroP = 0;
	hanakoP = 0;
	cin >> n;

	for (int i = 0;i < n;i++) {
		cin >> taroC >> hanakoC;

		if (taroC > hanakoC)
			taroP += 3;
		else if (taroC < hanakoC)
			hanakoP += 3;
		else {
			taroP += 1;
			hanakoP += 1;
		}
	}
	cout << taroP << " " << hanakoP << endl;
	return 0;
}

Measured memory_bytes: 1208
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits>
#include <set>
#include <sstream>
#include <vector>
using namespace std;

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

    int A, B, C, X, Y;
    cin >> A >> B >> C >> X >> Y;

    int min = numeric_limits<int>::max();

    int larger = (X >= Y) ? 2 * X : 2 * Y;
    for (int c = 0; c <= larger; c += 2)
    {
        int a = X - c / 2;
        int b = Y - c / 2;
        a = (a > 0) ? a : 0;
        b = (b > 0) ? b : 0;

        int price = A * a + B * b + C * c;

        //cout << "c: " << c << " a:" << a << " b:" << b << " price:" << price << endl;

        if (price < min)
        {
            min = price;
        }
    }

    cout << min << endl;
    return 0;
}


Measured memory_bytes: 256
K, S = gets.split.map &:to_i

ans = 0
mn = [0, S-K*2].max
mx = [K, S].min

for x in mn..mx
  rest = S-x
  if rest <= K
    a = rest + 1
  else
    d = rest-K
    a = K - d + 1
  end
  ans += a
  #p x: x, rest: rest, a: a
end
p ans


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

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

a.sort()

if n%2==1:
    b=a[(n-1)//2]
else:
    b=a[n//2]

ans=0
for i in range(n):
    ans+=abs(a[i]-b)

print(ans)

Measured memory_bytes: 30840
#include <bits/stdc++.h>
#define ll          long long int
#define uu          first
#define vv          second
#define pii         pair<int,int>
#define pll         pair<ll,ll>
#define tp          tuple<int,int,int>
#define fastio      ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;
const int INF = 1e9;
const ll MOD = 1e9 + 7;

const int N = 1e6 + 6;

int main()  {
    fastio;
    int n;
    cin>>n;
    int cnt= 0;
    for(int i =0 ; i < n ; i++ ) {
        int a , b;
        cin>>a>>b;
        if(a == b ) cnt++;
        else cnt = 0;
        if(cnt == 3) {
            cout<<"Yes\n";
            return 0;
        }
        
    }
    cout<<"No\n";
    return 0;

    
    
}

Measured memory_bytes: 3648
#include<bits/stdc++.h>
#define up(l,r,i) for(int i=l;i<=r;i++)
#define dn(r,l,i) for(int i=r;i>=l;i--)
using namespace std;
const int MAXN =100 +3;
const int MAXM =100000 +3;
int N,W,w[MAXN],v[MAXN];
map <pair<int,int>,pair<bool,int> > mp;
int dfs(int i,int j){
	if(i==1) return j>=w[1]?v[1]:0;
	if(mp[make_pair(i,j)].first) 
	return mp[make_pair(i,j)].second;
	mp[make_pair(i,j)].first=true;
	int t0=dfs(i-1,j),t1=j-w[i]>=0?dfs(i-1,j-w[i])+v[i]:0;
	return mp[make_pair(i,j)].second=max(t0,t1);
}
int main()
{
	scanf("%d%d",&N,&W);
	up(1,N,i) scanf("%d%d",&w[i],&v[i]);
	printf("%d\n",dfs(N,W));
	return 0;
} 


Measured memory_bytes: 6016
//----------------------------おまじない
#pragma GCC optimize ("O3")
#pragma GCC target ("tune=native")
#pragma GCC target ("avx")
//----------------------------
#define FOR(i,j,n) for (int i=(j);i<(n);i++)
#define REP(i,n) for (int i=0;i<(n);i++)
#define REPN(i,n) for (int i=(n);i>=0;i--)
#define I(n) scanf("%d", &(n))
#define LL(n) scanf("%lld", &(n))
#define pb(n) push_back((n))
#define mp(i,j) make_pair((i),(j))
#include <bits/stdc++.h>
using namespace std;

//------------------------------typedef集
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vpi;
typedef vector<vi> vvi;
typedef vector<vpi> vvpi;
typedef vector<vvi> vvvi;
typedef long long ll;

ll n,x,a[100010],sm[100010],pre,ret;

int main(){
    LL(n); LL(x);
    LL(a[0]);
    pre += a[0];
    REP(i,n-1){
        LL(a[i+1]);
        pre += a[i+1];
        sm[i] = max(0LL, a[i] + a[i+1] - x);
    }

    REP(i,n-2){
        if (sm[i] > 0 and sm[i+1] > 0){
            int decl = min(a[i+1], min(sm[i], sm[i+1]));
            a[i+1] -= decl;
            sm[i] -= decl;
            sm[i+1] -= decl;
        }
    }

    REP(i,n-1){
        if (sm[i] > 0) {
            int decl = min(a[i],sm[i]);
            a[i] -= decl;
            sm[i] -= decl;
            if(i) sm[i-1] -= decl;
            if (sm[i] > 0){
                a[i+1] -= sm[i];
                sm[i+1] -= sm[i];
                sm[i] = 0;
            }
        }
    }
    REP(i,n) ret += a[i];
    cout << pre-ret << endl;
}


Measured memory_bytes: 1792
#include <iostream>
#include <cstdio>
#include <vector>
using namespace std;
typedef long long ll;

ll n, k, ans=1, M=1e9+7;
vector<int> gr[100005];

ll dfs(ll p, ll q, ll r) {
	ll c;
	if(k-r>0) ans = ans * (k-r) % M;
	else ans = 0;
	c = q ? 2 : 1;
	for(int x:gr[p]) {
		if(x!=q) dfs(x, p, c++);
	}
}

int main() {
	ll i, t1, t2;
	cin >> n >> k;
	while(--n) {
		scanf("%lld%lld", &t1, &t2);
		gr[t1].push_back(t2);
		gr[t2].push_back(t1);
	}
	dfs(1, 0, 0);
	cout << ans;
	return 0;
}

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

using namespace std;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define eee(a) (cerr << (#a) << ": " << (a) << endl);


using ll = long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
using mint = map<int, int>;

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

const char sp = ' ';
const char cmm = ',';
const int MOD = 1e9+7;
const int INF = 1e9;
const ll LINF = 1e18;

ll mod(ll a, ll b){return (a%b+b)%b;}
ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b){return a*b/gcd(a,b);}
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void Judge(bool b){b?Yes():No();}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void JUDGE(bool b){b?YES():NO();}
ll powMod(ll b, ll e, ll m){ll r=1;while(e>0){if(e&1)r=(r%m)*(b%m)%m;b=(b%m)*(b%m)%m;e>>=1;}return r;}
double distance(ll x1, ll y1, ll x2, ll y2){return sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));}

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<typename T>
void ppp(T n){cout << n << endl;}
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {return s << "(" << p.first << ", " << p.second << ")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
    int len = v.size();
    s << '[';
    for (int i = 0; i < len; ++i) {
        s << v[i]; if (i < len-1) s << ", ";
    }
    s << ']';
    return s;
}

struct aaa{
    aaa(){
        cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(15);
    };
}fastio;

ll f(ll b, ll n){
    if(b <= 1) return LINF;
    ll res = 0LL;
    while(n){
        res += n%b;
        n /= b;
    }
    return res;
}

int main(){
    ll n, s;
    cin >> n >> s;
    if(n == s) {
        ppp(n+1);
        return 0;
    }

    ll ans = LINF;
    for(ll i = 2; i <= sqrt(n); ++i){
        if(f(i, n) == s) chmin(ans, i);
    }
    for(ll i = 1; i < sqrt(n); ++i){
        ll x = (n-s)/i+1;
        if(f(x, n) == s) chmin(ans, x);
    }

    if(ans == LINF) ppp(-1);
    else ppp(ans);

    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <vector>
#include <list>
#include <cmath>
#include <fstream>
#include <algorithm>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <complex>
#include <iterator>
#include <cstdlib>
#include <cstring>
#include <sstream>
#include <stack>

using namespace std;

const double EPS=(1e-10);
typedef long long ll;
typedef pair<int,int> pii;
bool EQ(double a,double b){
  return abs((a)-(b))<EPS;
}
void fast_stream(){
	std::ios_base::sync_with_stdio(0);
}

int N;
int c[11][11];

const int MAX_SIZE = 10000;

struct edge{
	int to;
	int cost;
};

class Situation{
public:
    vector<int> seq;
	int cost;
	Situation(int cost_,vector<int> &seq_){
		cost=cost_;
        seq=seq_;
    }
	Situation();
	bool operator<(const Situation &s)const{
		return s.cost < this->cost;
	}
};

int V;
const int MAX_V = 5000;
map<vector<int>,int> d;
const int INF = 1000000000;
int res;

void dijkstra(vector<int> s){
	priority_queue<Situation> que;
    d[s] = 0;
    que.push(Situation(0,s));
	while(!que.empty()){
		Situation p = que.top();
		que.pop();
        if(d.count(p.seq)!=0&&d[p.seq] < p.cost)
			continue;
        // ツ各ツ偲ュツ禿シツづェツ妥鳴つヲ
        for(int i=0;i<N;i++){
            for(int j=i+1;j<N;j++){
                vector<int> nseq=p.seq;
                swap(nseq[i],nseq[j]);
                int ct=c[i][j];
                if(d.count(nseq)==0||d[nseq]>d[p.seq]+ct){
                    d[nseq]=d[p.seq]+ct;
                    que.push(Situation(d[nseq],nseq));
                }
            }
        }
	}
}

void solve(){
    cin>>N;
    for(int i=0;i<N;i++)for(int j=0;j<N;j++)cin>>c[i][j];
    vector<int> v;
    for(int i=0;i<N;i++)v.push_back(i);
    res=0;
    dijkstra(v);
    for(map<vector<int>,int>::iterator it=d.begin();it!=d.end();it++)res=max(res,it->second);
    cout<<res<<endl;
}


int main(){
    solve();

    return 0;
}

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

#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0, a1, a2, a3, a4, x, ...) x
#define dump_1(x1) cerr << #x1 << ": " << x1 << endl
#define dump_2(x1, x2) \
  cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << endl
#define dump_3(x1, x2, x3)                                                \
  cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \
       << x3 << endl
#define dump_4(x1, x2, x3, x4)                                            \
  cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \
       << x3 << ", " #x4 << ": " << x4 << endl
#define dump_5(x1, x2, x3, x4, x5)                                        \
  cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \
       << x3 << ", " #x4 << ": " << x4 << ", " #x5 << ": " << x5 << endl
#define dump(...) \
  CHOOSE((__VA_ARGS__, dump_5, dump_4, dump_3, dump_2, dump_1, ~))(__VA_ARGS__)
#define check(s) cerr << s << endl

#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define unique(v) v.erase(unique(v.begin(), v.end()), v.end());
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)

using namespace std;

using ll = long long;

vector<int> dx = {0, 1, 0, -1};
vector<int> dy = {1, 0, -1, 0};

const ll LINF = 2e18;
const int INF = 1e9;

// Binary Indexed Tree (Fenwick Tree)
// https://youtu.be/lyHk98daDJo?t=7960
template <typename T>
struct BIT {
  int n;
  vector<T> d;
  BIT(int n = 0) : n(n), d(n + 1) {}
  void add(int i, T x = 1) {
    for (i++; i <= n; i += i & -i) {
      d[i] += x;
    }
  }
  T sum(int i) {
    T x = 0;
    for (i++; i; i -= i & -i) {
      x += d[i];
    }
    return x;
  }
  T sum(int l, int r) { return sum(r - 1) - sum(l - 1); }
};

void solve(ll N, ll Q, std::vector<ll> c, std::vector<ll> l,
           std::vector<ll> r) {
  vector<int> pi(N + 1, -1);
  vector<vector<int>> ps(N);
  rep(i, N) {
    int l = pi.at(c.at(i));
    if (l != -1) ps.at(l).push_back(i);
    pi.at(c.at(i)) = i;
  }

  vector<vector<pair<int, int>>> qs(N);
  rep(i, Q) { qs.at(l.at(i)).emplace_back(r.at(i), i); }

  BIT<int> d(N);
  vector<int> ans(Q);

  for (int x = N - 1; x >= 0; --x) {
    for (int y : ps.at(x)) d.add(y, 1);
    for (auto query : qs.at(x)) {
      int r = query.first, i = query.second;
      ans.at(i) = (r - x + 1) - d.sum(r);
    }
  }

  rep(i, Q) { cout << ans.at(i) << endl; }

  return;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  ll N;
  scanf("%lld", &N);
  ll Q;
  scanf("%lld", &Q);
  std::vector<ll> c(N);
  for (int i = 0; i < N; i++) {
    scanf("%lld", &c[i]);
  }
  std::vector<ll> l(Q);
  std::vector<ll> r(Q);
  for (int i = 0; i < Q; i++) {
    scanf("%lld", &l[i]);
    scanf("%lld", &r[i]);
    l[i]--;  // 0-indexed
    r[i]--;  // 0-indexed
  }
  solve(N, Q, std::move(c), std::move(l), std::move(r));
  return 0;
}


Measured memory_bytes: 69680