akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;

#define REP(i, n) for (int i = 0; i < (n); i++)

#include <stdio.h>

int main()
{
    uint64_t K;

    scanf("%ld", &K);

    const int N = 50;

    uint64_t k = K % N;
    uint64_t n = K / N;

    cout << N << endl;;

    for (unsigned int i=0; i<N; i++) {
      if (i < N - k) {
        cout << N - (k+1) + n;
      } else {
        cout << 2 * N - k + n;
      }

      if (i != N -1)
        cout << " ";
    }

    cout << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
#include<string.h>
#define max(x,y)(x>y?x:y)
#define min(x,y)(x>y?y:x)
#define MOD (int)1e9+7
int dx4[]={1,0,-1,0};
int dy4[]={0,-1,0,1};
typedef long long int ll;
typedef unsigned long long int ull;
ll gcd(ll x,ll y){if(!y)return x;return gcd(y,x%y);}
ll lcm(ll x,ll y){return x/gcd(x,y)*y;}
void swap(ll *x,ll *y){ll tmp=*x;*x=*y;*y=tmp;}
int asc_cmp(const void* X,const void* Y){ll x=*(int*)X,y=*(int*)Y;if(x<y)return -1;else if(x==y)return 0;else return 1;}
int desc_cmp(const void* X,const void* Y){ll x=*(int*)X,y=*(int*)Y;if(x<y)return 1;else if(x==y)return 0;else return -1;}
typedef struct pair_{
    int x;
    int y;
}pair_t;

int main(){
    char s[10];scanf("%s",s);
    if(s[2]==s[3]&&s[4]==s[5]){
        printf("Yes\n");
    }else{
        printf("No\n");
    }
}

Measured memory_bytes: 128
def get_int_array
    gets.strip.split(' ').map(&:to_i)
end

n, m = get_int_array

ps = get_int_array
ns = Array.new(n, false)

m.times{|i|
    a, b = get_int_array.map{|i| i - 1 }
    ns[b] |= ps[a] >= ps[b]
    ns[a] |= ps[b] >= ps[a]
    # p ns
}

puts ns.count{|i| !i }

Measured memory_bytes: 24988
import std.stdio;
import std.string;
import std.conv;
import std.algorithm;
import std.array;
 
void main() {
	auto data = readln().split();
	auto A = data[0].to!int(), B = data[1].to!int(), K = data[2].to!int();
	int[] list;
	foreach_reverse(i;  1 .. min(A, B)+1) {
		if (A % i == 0 && B % i == 0) list ~= i;
	}
	writeln(list[K-1]);
}

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


int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    ll m = 1000;
    for(int i = 0 ; i+1 < n; ++i) {
        if(a[i]>=a[i+1]) continue;
        else {
            ll k = m/a[i];
            m %=a[i];
            m += a[i+1] * k;
        }
    }
    cout << m << endl;
    return 0;
}

Measured memory_bytes: 3584
#include <iostream>
#include <string>
#include <cmath>

using namespace std;

struct COLOR {
	int R;
	int G;
	int B;
};

int main() {
	string b;

	string co = "0123456789abcdef";


	COLOR samp[] = {{0,0,0},{0,0,255},{0,255,0},{0,255,255},{255,0,0}, 
					{255, 0, 255},{255,255,0},{255,255,255}};

	double d;
	string name[] = {"black","blue","lime","aqua","red","fuchsia","yellow","white"};
	while (1) {
		cin >> b;
		if (b[0] != '#') {
			break;
		}
		int color[3] = {0};
		int count = 0; 
		double MIN = 100000.0;
		int mc;
		for (int i = 1; i < 7; i++) {
			if (i % 2 != 0) {
				for (int j = 0; j < co.size(); j++) {
					if (b[i] == co[j]) {
						color[count] += j*16;
						break;
					}
				}
			} else {
				for (int j = 0; j < co.size(); j++) {
					if (b[i] == co[j]) {
						color[count] += j;
						break;
					}
				}
				count++;
			}
		}
		for (int i = 0; i < 8; i++) {
			d = sqrt((double)pow(samp[i].R-color[0],2)+(double)pow(samp[i].G-color[1],2)+(double)pow(samp[i].B-color[2],2));
			if (d < MIN) {
				MIN = d;
				mc = i;
			}
		}
		cout << name[mc] << endl;
	}

	return 0;
}

Measured memory_bytes: 1188
N, M, X, Y = map(int, input().split())
x = list(map(int, input().split()))
y = list(map(int, input().split()))

x.sort()
y.sort()

if x[-1] < y[0]:
	for i in range(x[-1]+1, y[0]+1):
		if X < i <= Y:
			print("No War")
			exit()
		else:
			continue
	print("War")
else:
	print("War")
	


Measured memory_bytes: 38256
import java.util.HashSet;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		StringBuilder sb = new StringBuilder();
		int n = sc.nextInt();
		HashSet<String> hs = new HashSet<>();
		char last = ' ';
		String str;
		boolean b = true;
		for (int i = 0; i < n; i++) {
			str = sc.next();
			if (hs.add(str)) {
				if (i != 0) {
					if (last != str.charAt(0)) {
						b = false;
						break;
					} else {
						last = str.charAt(str.length() - 1);
					}
				} else {
					last = str.charAt(str.length() - 1);
				}
			} else {
				b = false;
				break;
			}
		}
		if (b) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}


Measured memory_bytes: 23764
import heapq
t = int(input())
for i in range(t):
    n = int(input())
    ans = 0
    cl,cr = 0,0
    lisl = []
    lisr = []
    rs = 0
    ls = 0
    for i in range(n):
        k,l,r = map(int,input().split())
        a = r-l
        s = (l>r)
        if a<0:
            lisl.append([k,l,r,-a,s])
            rs += r
        else:
            lisr.append([k,l,r,a,s])
            ls += l
    # lisl.sort(key=lambda x: x[3])
    lisl.sort(key=lambda x: x[0])
    # lisr.sort(key=lambda x: x[3])
    lisr.sort(key=lambda x: x[0],reverse=1)
    # print(lis)
    h = []
    cntl = 0
    cntr = 0
    # print(lisl)
    # print(lisr)
    for i in lisl:
        heapq.heappush(h,i[3])
        cntl += 1
        if cntl > i[0]:
            heapq.heappop(h)
            cntl -= 1
    # print(h)
    hr = []
    for i in lisr:
        heapq.heappush(hr,i[3])
        cntr += 1
        if cntr > n-i[0]:
            heapq.heappop(hr)
            cntr -= 1
    # print(hr)
    # heapq.heappop(hr)
    # print(hr)
    print(rs+sum(h)+ls+sum(hr))



Measured memory_bytes: 132496
n,k=map(int,input().split())
from operator import itemgetter as it
l=sorted([list(map(int,input().split()))for i in range(n)],reverse=1,key=it(1))
from collections import defaultdict
c=defaultdict(int)
from heapq import heapify, heappop, heappush
now=[]
S=0
kind=0
for i in range(k):
    a,s=l[i]
    S+=s
    c[a]+=1
    if c[a]>1:heappush(now,(s,a))
    kind+=c[a]==1
ans=S+kind**2
for i in range(k,n):
    if not now:break
    x,y=l[i]
    if c[x]:continue
    s,a=heappop(now)
    c[x]+=1
    kind+=1
    S+=y-s
    ans=max(ans,S+kind**2)
print(ans)

Measured memory_bytes: 33196
/**
 *    author        : Saurav-Paul 
 *    created       : September 19, 2020 6:05 PM
 *    Problem Name  : C - A x B + C
 *    Problem Limit : 2000 ms , 1024 MB
 *    Problem Url   : https://atcoder.jp/contests/abc179/tasks/abc179_c
 *    @genarated by : ai-virtual-assistant
**/

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

using ll = long long int ;

class TC{

    public :
    void solve(){
        ll N ;
        cin >> N ;
        ll ans = 0 ;

        for(ll i = 1 ; i <= N ; i++){
            for(ll j = 1; j <= N ; j++){
                if(i * j >= N) break ;
                ans ++ ;
            }
        }

        cout << ans << endl ;

    }
};

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

    int testcases = 1;
    for(int i = 1 ; i <= testcases ; i ++){
        TC tc;
        tc.solve() ;
    }

    return 0 ;
}


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

using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

#define REP(i, l, n) for(int i=(l), i##_len=(n); i<i##_len; ++i)
#define ALL(x) (x).begin(),(x).end()
#define pb push_back

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

char alpha[26] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};

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

int main(){
    int n; cin >> n;
    ll mid;
    REP(i, 1, n+1){
        if(n <= (i*(i+1))/2){
            mid = i;
            break;
        }
    }
    for(int k = mid; k >= 1; k--){
        if(n == 0){
            break;
        }
        if(n >= k){
            cout << k << endl;
            n -= k;
        }
    }
}

Measured memory_bytes: 256
import math

a, b, h, m = input().split()
a = int(a)
b = int(b)
h = int(h)
m = int(m)

t = 2*math.pi
x1 = m*t/60
x2 = h*t/12+m*t/12/60
c = abs(x1-x2)
s = a*a+b*b-2*a*b*math.cos(c)
print("%.20f" %math.sqrt(s))


Measured memory_bytes: 9508
import math

k = int(input())

ans = 0
for a in range(1, k + 1):
    for b in range(1, k + 1):
        _gcd = math.gcd(a, b)

        if _gcd == 1:
            ans += k
        else:
            for c in range(1, k + 1):
                ans += math.gcd(_gcd, c)

print(ans)

Measured memory_bytes: 9184
#!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf')
ans = 0 ;count = 0 ;pro = 1

n,m=map(int,input().split())
ab=[tuple(map(int,input().split())) for i in range(n)]
cd=[tuple(map(int,input().split())) for i in range(m)]
for a,b in ab:
    tmp=inf
    candi=0
    for j in range(m):
        c=cd[j][0]
        d=cd[j][1]
        k=abs(a-c)+abs(b-d)
        if tmp>k:
            tmp=k
            candi=j
    print(candi+1)




Measured memory_bytes: 39408
#define _USE_MATH_DEFINES
#include <math.h>
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <numeric>
#include <stdio.h>
#include <vector>
#include <map>
#include <queue>

using namespace std;
typedef long long ll;
using Graph = vector<vector<ll>>;

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)

ll modpow(ll a,ll n,ll m) {
    if(n==1) return a%m;
    if(n%2==1) return (a*modpow(a,n-1,m))%m;
    ll b = modpow(a,n/2,m)%m;
    return (b*b)%m;
}

int main() {
    ll mod = 1000000007;
    ll X,Y;
    cin >> X >> Y;
    ll out = 0;
    vector<pair<ll,ll>> p;
    rep(i,X+1){
        if((X-i)%2==0&&(X-i)/2==Y-2*i&&Y-2*i>=0){
            p.push_back(make_pair(i,(X-i)/2));
        }
    }
    rep(i,p.size()){
        ll A = 1;
        rep(j,p[i].first+p[i].second) A = (A*(j+1))%mod;
        ll B = 1;
        rep(j,p[i].first) B = (B*(j+1))%mod;
        ll C = 1;
        rep(j,p[i].second) C = (C*(j+1))%mod;
        out = (A*modpow((B*C)%mod,mod-2,mod))%mod;
    }
    cout << out << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main() {
	char A[10];
	int result = 0;
	scanf("%s", &A);
	for (int a = 0; a < 4; a++) {
		if ('-' == A[a]) {
			result = result - 1;
		}
		else if ('+' == A[a]) {
			result = result+1;
		}
	}
	printf("%d", result);
	return 0;
}

Measured memory_bytes: 128
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String {
            bytes
                .by_ref()
                .map(|r| r.unwrap() as char)
                .skip_while(|c| c.is_whitespace())
                .take_while(|c| !c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        n: usize,
        m: usize,
        v: [usize; n-1],
        w: [[i64; m]; n]
    }
    let mut wt = vec![vec![0; n]; m];
    for i in 0..m {
        for j in 0..n {
            wt[i][j] = w[j][i];
        }
    }
    let mut dist = vec![0; n];
    for i in 1..n {
        dist[i] = dist[i - 1] + v[i - 1];
    }
    let mut tab: Vec<Vec<i64>> = vec![vec![0; n+1]; n+1];
    for i in 0..m {
        fill(&mut tab, 0, n, &wt[i]);
    }

    for i in 1..n+1 {
        tab[i][0] += tab[i - 1][0];
        tab[0][i] += tab[0][i - 1];
    }
    for i in 1..n+1 {
        for j in 1..n+1 {
            tab[i][j] += tab[i - 1][j] + tab[i][j - 1] - tab[i - 1][j - 1];
        }
    }

    let mut ans = 0;
    for i in 0..n {
        for j in i..n {
            let a = dist[j] - dist[i];
            let b = tab[i][j] as usize;
            if b > a && ans < b - a {
                ans = b - a;
            }
        }
    }
    println!("{}",ans);
}

fn fill(tab: &mut Vec<Vec<i64>>, l: usize, r: usize, v: &Vec<i64>) {
    if l >= r {
        return;
    }
    let mut k = 0;
    let mut max = 0;
    for i in l..r {
        if v[i] > max {
            k = i;
            max = v[i];
        }
    }
    tab[l][k] += max;
    tab[l][r] -= max;
    tab[k + 1][k] -= max;
    tab[k + 1][r] += max;
    fill(tab, l, k, v);
    fill(tab, k + 1, r, v);
}


Measured memory_bytes: 250108
import java.util.Scanner;
public class Main {
@SuppressWarnings("resource")
public static void main(String[] args) {
	Scanner sc =new Scanner(System.in);
	int N=sc.nextInt();
	int[] P=new int[N];
	int min=2000001;
	int ans=0;
	for(int i=0;i<N;i++) {
		P[i]=sc.nextInt();
		if(P[i]<=min) {
			ans++;
			if(P[i]<min) {
				min=P[i];
			}
		}
	}
	System.out.println(ans);

}
}

Measured memory_bytes: 82544
#include<stdio.h>
#include<string.h>

int main(){
  int n;
  char s[56];
  char key[4] = "ABC";
  char *p;
  int i;
  int cnt = 0;
  
  scanf("%d %s", &n, s);

  p = s;
  while(*p != '\0'){
    if(strncmp(p,key,3) == 0) cnt++;

    p++;
  }

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

Measured memory_bytes: 128
#include <cstdio>
#include <vector>
#include <utility>
#include <algorithm>
#define ll long long
using namespace std;

vector< pair<ll, ll> > items;
ll result;
ll memo[101][100001];
ll recurse(int n, int c)
{
    if(memo[n][c] != 0) return memo[n][c];
    if (n == 0 || c == 0)
        result = 0;
    else if(items[n].first > c)
        result = recurse(n-1, c);
    else{
        ll x = recurse(n-1, c);
        ll y = items[n].second + recurse(n-1, c-items[n].first);
        result = max(x, y);
    }
    memo[n][c] = result;
    return result;
}
int main()
{
    int n, w;
    scanf("%d%d", &n, &w);
    items.push_back(make_pair(0, 0));
    for(int i=0; i<n; i++)
    {
        int val, weight;
        scanf("%d%d", &weight, &val);
        items.push_back(make_pair(weight, val));
    }
    ll ans = recurse(n, w);
    printf("%lld", ans);
}


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

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define MOD 1000000007
#define INF (1LL << 25) // 33554432
#define PI 3.14159265359
#define EPS 1e-12
//#define int ll

signed main(void) {
  while (true) {
    int h, b[13][5];
    cin >> h;
    if (!h)
      break;
    REP(i, h) REP(j, 5) cin >> b[i][j];

    int ret = 0;
    REP(i, h) {
      REP(j, h) {
        int c = 1;
        FOR(k, 1, 5) {
          if (b[j][k] == b[j][k - 1] && b[j][k] != 0)
            c++;
          else {
            if (c >= 3) {
              ret += b[j][k - 1] * c;
              for (int l = k - 1; l >= k - c; --l)
                b[j][l] = -1;
            }
            c = 1;
          }
        }
        if (c >= 3) {
          ret += b[j][4] * c;
          for (int l = 4; l > 4 - c; --l)
            b[j][l] = -1;
        }
      }
      /*cout << "kesu:" << endl;
      REP(i, h) {
        REP(j, 5) {
          cout << b[i][j] << " ";
        }
        cout << endl;
      }*/
      REP(j, 5) {
        int c = 0;
        for (int k = h - 1; k >= 0; --k) {
          if (b[k][j] == -1) {
            c++;
          } else if (c) {
            int ii = 0;
            while (ii != c) {
              b[k + c - ii][j] = b[k][j];
              b[k][j] = 0;
              ++ii;
            }
          }
        }
        if (c) {
          REP(k, c) b[k][j] = 0;
        }
      }
      /*cout << "otosu:" << endl;
      REP(i, h) {
        REP(j, 5) {
          cout << b[i][j] << " ";
        }
        cout << endl;
      }*/
    }

    cout << ret << endl;
  }

  return 0;
}

Measured memory_bytes: 3080
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <functional>

using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define VI vector<int>
#define debug(x) cout<<#x<<": "<<x<<endl
#define DEBUG(x) cout<<#x<<": "<<x<<endl

string S;



int main()
{

	cin >> S;


	int iter = 0;
	bool flag = true;
	int acount = 0;
	int num = 0;
	REP(i,S.length()){
		if(S[i]=='A'){
			if(acount==1){
				flag = false;
				break;
			}
			acount++;
			continue;
		}

		switch(iter){
		case 0:
			if(!(i<S.length()-2 && ( S[i]=='K' && S[i+1] == 'I' && S[i+2] == 'H')))
				flag = false;
			acount=0;
			iter++;
			i+=2;
			num++;
			break;
		case 1:
			if(S[i]!='B')
				flag = false;
			acount = 0;
			iter++;
			num++;
			break;
		case 2:
			if(S[i]!='R')
				flag = false;
			acount = 0;
			iter++;
			num++;
			break;
		default:
			flag = false;
			break;
		}
	}
	if(flag && num == 3){
		cout << "YES";

	} else {
		cout << "NO";
	}



}



Measured memory_bytes: 256
package main

import (
	"fmt"
	"math"
)

func main() {
	for {
		var n, a, sum float64
		fmt.Scan(&n)
		if n == 0 {
			break
		}
		s := make([]float64, int(n))
		for i := range s {
			fmt.Scan(&s[i])
			sum += s[i]
		}
		m := sum / n
		for _, si := range s {
			a += (si - m) * (si - m)
		}
		fmt.Println(math.Sqrt(a / n))
	}
}



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

#define ll long long int
int main()
{
    	
	ll a,b,c,k;
	cin>>a>>b>>c>>k;
	
	if(k<=a)
	cout<<k;
	else if(k<=(a+b))
	cout<<a;
	else if(k<=(a+b+c))
	cout<<(a-(k-a-b));
	    
	return 0;
}


Measured memory_bytes: 3632
#include<iostream>
using namespace std;
string str[12],s;
bool vd[12][12];
int cnt;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};

bool inField(int y,int x){
  return (0<=y&&y<12&&0<=x&&x<12);
}

void rec(int y,int x){
  vd[y][x]=true;
  int nx,ny;
  for(int i=0;i<4;i++){
    ny=y+dy[i];nx=x+dx[i];
    if(inField(ny,nx)&&vd[ny][nx]==false)rec(ny,nx);
  }
}

int main(){
  while(cin>>str[0]){
    for(int i=1;i<12;i++)cin>>str[i];
    for(int i=0;i<12;i++){
      s=str[i];
      for(int j=0;j<12;j++){
	vd[i][j]=(s[j]=='0'?true:false);
      }
    }
    /*
    for(int i=0;i<12;i++){
      for(int j=0;j<12;j++){
	cout<<vd[i][j]<<" ";
      }
      cout<<endl;
    }
    */
    cnt=0;
    for(int i=0;i<12;i++){
      for(int j=0;j<12;j++){
	if(vd[i][j]==false){
	  cnt++;
	  rec(i,j);
	}
      }
    }
    cout<<cnt<<endl;
  }
  return 0;
}

Measured memory_bytes: 1192
n = int(input())
A=[int(i) for i in input().split()]
ans = 0
for i in range(n-2):
    if (A[i+1]<A[i+2] and A[i+1]>A[i]) or (A[i+1]<A[i] and A[i+1]>A[i+2]):
        ans+=1
print(ans)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define REP(i,N) for(int i=0;i<N;i++)
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

int main(void){
  string s,t;cin >> s >> t;
  int n = s.length(), m = t.length();
  ll dp[2][m+1];
  //0:左,1:上,2:左上
  ll pre[n+1][m+1];
  ll *prev = dp[0];
  ll *next = dp[1];
  REP(i,n+1) pre[i][0] = 1;
  REP(j,m+1){
    prev[j] = 0;
    next[j] = 0;
    pre[0][j] = 0;
  }
  REP(i,n){
    REP(j,m){
      if(s[i] == t[j]){
        next[j+1] = prev[j]+1;
        pre[i+1][j+1] = 2;
      }
      else{
        if(next[j]>prev[j+1]){
          next[j+1] = next[j];
          pre[i+1][j+1] = 0;
        }else{
          next[j+1] = prev[j+1];
          pre[i+1][j+1] = 1;
        }
      }
    }
    swap(next,prev);
  }
  swap(next,prev);
  vector<char> ans;
  for(int i=n,j=m; i>=0 && j>=0;){
    if(pre[i][j] == 0)j--;
    else if(pre[i][j] == 1)i--;
    else{
      i--;
      j--;
      ans.push_back(s[i]);
    }
    if(ans.size()==next[m])break;
  }
  reverse(ans.begin(),ans.end());
  REP(i,ans.size()) cout << ans[i];
  cout << endl;
  return 0;
}


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

#define int long long
#define rep(i,l,r) for(int i=(int)(l);i<(int)(r);i++)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)x.size())
template<class T>bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,T b){if(a>b){a=b;return 1;}return 0;}

/*{
  }*/

using vi = vector<int>;
using vvi = vector<vi>;
using P = pair<int,int>;

int n;
vi es[101010];

int d0[101010];
int d1[101010];

void dfs0(int v, int p, int c){
  d0[v] = c;
  for(int to : es[v]) if(to != p){
    dfs0(to, v, c+1);
  }
}

void dfs1(int v, int p, int c){
  d1[v] = c;
  for(int to : es[v]) if(to != p){
    dfs1(to, v, c+1);
  }
}

signed main() {
  cin >> n;
  rep(i, 0, n-1){
    int a, b;
    cin >> a >> b;
    a--; b--;
    es[a].emplace_back(b);
    es[b].emplace_back(a);
  }

  dfs0(0, -1, 0);
  dfs1(n-1, -1, 0);

  int f = 0, s = 0;
  rep(i, 0, n){
    if(d0[i] <= d1[i]) s++;
    else f++;
  }

  if(f >= s) cout << "Snuke" << endl;
  else cout << "Fennec" << endl;

  return 0;
}



Measured memory_bytes: 12032
#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>;
using Graph = vector<vector<int>>;

int main() {
    int n,cnt=0;
    cin >> n;
    vector<P> a(n);
    vector<P> c(n);
    rep(i,n) cin >> a[i].first >> a[i].second;
    rep(i,n) cin >> c[i].first >> c[i].second;
    sort(a.begin(),a.end());
    sort(c.begin(),c.end());
    rep(i,n){
        bool ok=false;
        int pr=-1,t;
        rep(j,n){
            if(c[i].first<a[j].first) continue;
            if(c[i].second<a[j].second) continue;
            if(pr<=a[j].second){
                pr=a[j].second;
                t=j;
                ok=true;
            }
        }
        if(ok){
            ++cnt;
            a[t].first=1000;
        }
    }
    cout << cnt << "\n";
    return 0;
}

Measured memory_bytes: 3608
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <tuple>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;
 
ll dp[2][10005][105];  /* dp[id][i+1][j] : 先頭からi桁目(iは0-index)までで各桁の数字の総和をdで割った余りがjとなる0以上の数の個数
                                           ただし、id = 0 のとき現時点でsと等しい。
                                           id = 1 のとき現時点でsより小さいことが確定。 */

int main() {
    string s;
    ll d;
    cin >> s >> d;
    ll n = s.size();
    
    dp[0][0][0] = 1;
    rep(id, 2) {
        rep(i, n) {
            rep(j, d) {
                ll lim = s[i] - '0';  //  先頭からi桁目にはlim以下の数を置ける
                if(id) {
                    lim = 9;
                }
                exrep(x, 0, lim) {  // 先頭からi桁目にxを置くとする
                    dp[id || x < lim][i+1][(j + x)%d] += dp[id][i][j];
                    dp[id || x < lim][i+1][(j + x)%d] %= mod;
                }
            }
        }
    }
    
    dp[1][n][0] = (dp[1][n][0] + mod -1)%mod;  // 0を余計にカウントしているので除く
    
    ll ans = 0;
    rep(id, 2) {
        ans += dp[id][n][0];
        ans %= mod;
    }
    
    out(ans);
    re0;
}

Measured memory_bytes: 16640
#include<bits/stdc++.h>
#pragma target("trapv")
using namespace std;
#define bs ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define ll long long int
#define pb push_back
// #define LOCAL_DEFINE
// #define LOCAL
#define deb(a) cout << #a << " = " << a << '\n'
#define deb2(a, b) cout << #a << " = " << a << ", " << #b << " = " << b << '\n'
#define rep(var,start,end) for(int var=start;var<end;var++)
#define erep(var,start,end) for(int var=start;var<=end;var++)
#define rrep(var,start,end) for(int var=start;var>=end;var--)
#define all(x) x.begin(),x.end()
#define pii pair<int,int>
#define pci pair<char,int>
#define pll pair<ll,ll>
#define test int t;cin>>t;while(t--)

ll modularExponentiation(ll n, ll p, ll M){
    ll res = 1;
    while(p){
        if(p&1)
            res = (res * n)%M;
        n = (n*n)%M;
        p >>= 1;
    }
    return res;
}

void solve(){
    int n,k;
    cin >> n >> k;
    int a[n], dp[n];
    
    for(int i = 0; i < n; ++i) cin >> a[i];
    dp[0] = 0;
    for(int i = 1; i < n; ++i){
        dp[i] = INT_MAX;
        for(int j = i; j >= i-k && j >= 0; --j)
            dp[i] = min(dp[i], dp[j] + abs(a[i] - a[j]));
    }
    cout << dp[n-1];
}

int main()
{
    bs;
    #ifdef LOCAL
    freopen("Contest/input.txt","r",stdin);
    freopen("Contest/output.txt","w",stdout);
    #endif
    solve();
    // test{
    //    solve(); 
    // }
    #ifdef LOCAL_DEFINE
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
    #endif
}

Measured memory_bytes: 4396
#include "bits/stdc++.h"
// Begin Header {{{
#define all(x) (x).begin(), (x).end()
#define rep(i, s, n) for (i64 i = (s), i##_limit = (n); i < i##_limit; ++i)
#define repr(i, s, t) for (i64 i = (s), i##_limit = (t); i >= i##_limit; --i)
#define var(type, ...) \
    type __VA_ARGS__;  \
    read(__VA_ARGS__);
#ifndef DBG
#define dump(...)
#endif
using namespace std;
using i64 = int_fast64_t;
using pii = pair<i64, i64>;
template <class T, class U>
inline bool chmax(T &a, const U &b) {
    return b > a && (a = b, true);
}
template <class T, class U>
inline bool chmin(T &a, const U &b) {
    return b < a && (a = b, true);
}
constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;

template <class T>
inline vector<T> makeV(const T &initValue, size_t sz) {
    return vector<T>(sz, initValue);
}

template <class T, class... Args>
inline auto makeV(const T &initValue, size_t sz, Args... args) {
    return vector<decltype(makeV<T>(initValue, args...))>(
        sz, makeV<T>(initValue, args...));
}

template <class T>
inline istream &operator>>(istream &is, vector<T> &vec) {
    for (auto &e : vec) is >> e;
    return is;
}

inline void read() {}

template <class Head, class... Tail>
inline void read(Head &head, Tail &... tail) {
    cin >> head;
    read(tail...);
}

inline void print() { cout << "\n"; }

template <class Head, class... Tail>
inline void print(Head &&head, Tail &&... tail) {
    cout << head;
    if (sizeof...(tail)) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
inline ostream &operator<<(ostream &os, const vector<T> &vec) {
    static constexpr const char *delim[] = {" ", ""};
    for (const auto &e : vec) os << e << delim[&e == &vec.back()];
    return os;
}

template <class Container>
struct Rev {
    Container &x_;
    inline Rev(Container &x) : x_(x) {}
    inline auto begin() { return rbegin(x_); }
    inline auto end() { return rend(x_); }
};
// }}} End Header

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    var(string, s);
    if (s == "SUN") print(7);
    if (s == "MON") print(6);
    if (s == "TUE") print(5);
    if (s == "WED") print(4);
    if (s == "THU") print(3);
    if (s == "FRI") print(2);
    if (s == "SAT") print(1);

    return 0;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline 

#m = int(input())
h,w,t = [int(i) for i in readline().split()]

MOD = 10**9+7
from fractions import gcd

gh = gcd(h,t)

gw = gcd(w,t)

c = h//gh * w//gw

ans = pow(2,w//gw,MOD) + pow(2,h//gh,MOD) + pow(2,gcd(h//gh,w//gw),MOD) - 2 - 1

print(pow(ans,h*w//c,MOD))

Measured memory_bytes: 5168
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#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) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

template<typename T>
void print(const vector<T> &x) {
    int n = x.size();
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x) {
    int n = x.size();
    rep(i,n) {
        rep(j,x[i].size()) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

template<typename T>
void print(const vector<T> &x, int n) {
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x, int n, int m) {
    rep(i,n) {
        rep(j,m) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

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

void input_init() {
    cin.tie(0); ios::sync_with_stdio(false);
}

int change(int x, int n) {
    x += n;
    if (x>=26) x = x-26;
    return x;
}

int main(int argc, char const *argv[]) {
    int n; cin>>n; 
    string s; cin>>s;
    rep(i,s.length()) {
        char c = s[i];
        int x = s[i]-'A';
        x = change(x,n);
        s[i] = x+'A';
    }
    cout << s << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

using ll = long long;

int main() {
  int n;
  cin >> n;
  ll vsum = 0;
  for (int i = 1; i <= n; ++i)
    if (i % 3 && i % 5)
      vsum += i;
  cout << vsum << endl;
}

Measured memory_bytes: 3620
#include <iostream>
#include <cstdio>
#include <algorithm>
#define N 10001
using namespace std;

void Counting_Sort(int *A, int n, int *B, int k){
	int *C = new int[N];
	for(int i=0; i<=k; i++) C[i]=0;
	for(int j=0; j<n; j++) C[A[j]] = C[A[j]]+1;
	for(int i=1; i<=k; i++) C[i] = C[i]+C[i-1];
	for(int j=n-1; j>=0; j--){
		B[C[A[j]]] = A[j];
		C[A[j]] = C[A[j]]-1;
	}
	delete[] C;
}

int main(){
	int n;
	cin >> n;
	int *A = new int[n];
	int *B = new int[n+1];
	for(int i=0;i<n;i++){
		cin >> A[i];
	}
	Counting_Sort(A, n, B, N-1);
	for(int i=1;i<n+1;i++){
		cout << B[i];
		if(i == n) cout<< endl;
		else cout<< " ";
	}
	delete[] A;
	delete[] B;
	return 0;
}

Measured memory_bytes: 16800
#include <bits/stdc++.h>
#define pb push_back

using namespace std;

void debug_out() { cerr << '\n'; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << H; debug_out(T...);}
#define dbg(...) cerr << #__VA_ARGS__ << " ->", debug_out(__VA_ARGS__)
#define dbg_v(x, n) do{cerr<<#x"[]: ";for(int _=0;_<n;++_)cerr<<x[_]<<" ";cerr<<'\n';}while(0)
#define dbg_ok cerr<<"OK!\n"

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

const int DMAX = 2e5+10;

inline int two(int n) { return 1 << n; }
inline int test(int n, int pos) { return (bool) (n & two(pos)); }
inline void set_bit(int &n, int b) { n |= two(b); }
inline void unset_bit(int &n, int b) { n &= ~two(b); }
inline int last_bit(int n) { return n & (-n); }

long long int n,ans;

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

    int x,y,i,nr=1;

    cin>>n;

    if(n & 1){
       cout<<"0\n";
       return 0;
    }
    if(n <= 4){
       cout<<"0\n";
       return 0;
    }
    for(ll i=10;i<=n;i*=5)
        ans+=n/i;
    cout<<ans<<'\n';

    return 0;
}


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

int main(){
   int N, M, C;
   std::cin >> N >> M >> C;
   std::vector<int> B(M);
   for (int j=0; j<M; j++){
      std::cin >> B.at(j);
   }
   std::vector<std::vector<int>> A(N, std::vector<int> (M));
   for (int i=0; i<N; i++){
      for (int j=0; j<M; j++){
         std::cin >> A.at(i).at(j);
      }
   }
   int cnt=0;
   for (int i=0; i<N; i++){
      int temp = 0;
      for (int j=0; j<M; j++){
         temp = temp + A.at(i).at(j) * B.at(j);
      }
      temp = temp + C;
      if (temp > 0){
         cnt++;
      }
   }
   std::cout << cnt << std::endl;

}



Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
#include<string>
typedef long long ll;
const ll LINF = 1e18;
const int INF = 1e8;
using namespace std;

#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No" ) << endl



int main(void)
{
	int a, b, c;

	cin >> a >> b >> c;
	if (b / a >= c)
	{
		cout << c << endl;
	}
	else if (b / a < c)
	{
		cout << b / a << endl;
	}

}

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

typedef long long ll;

int main()
{
    ll n,a,b,i,c=1;
    map<char,int>mp;
    string st;
    cin >> st;
    for(i=1; i<st.size(); i++)
    {
        if(st[i]==st[i-1]){
            c++;
        }
        else c=1;
        if(c>=3){
            cout << "Yes\n";
            return 0;
        }
    }

    cout << "No\n";

    return 0;
}



Measured memory_bytes: 256
/*

                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                    prayer
*/

// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(long long i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) {rep(_,v.size())cout<<" "<<v[_];cout<<endl;}
#define show2d(v) {rep(__,v.size())show1d(v[__]);}
using namespace std;
//kaewasuretyuui
typedef long long ll;
#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<int,int,int,int> tp;
typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
#define yes cout<<"Yes\n"
#define no cout<<"No\n"

template< typename T >
istream &operator>>(istream &is, vector< T > &v) {
  for(T &in : v) is >> in;
  return is;
}

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

    int n;
    cin>>n;
    string s;
    cin>>s;
    int x=0,y=0;
    rep(i,n){
        if('a'<=s[i]&&s[i]<='m')x++;
        if('n'<=s[i]&&s[i]<='z')x--;
        if('A'<=s[i]&&s[i]<='M')y++;
        if('N'<=s[i]&&s[i]<='Z')y--;
    }
    string t="";
    if(x>0)t+=string(x,'a');
    if(x<0)t+=string(-x,'z');
    if(y>0)t+=string(y,'A');
    if(y<0)t+=string(-y,'Z');
    cout<<t.size()<<endl;
    cout<<t<<endl;
}



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

int main(){
	ll H,N;
	ll sum=0;
	ll i;
	cin>>H>>N;
	vector<ll>waza(N);
	rep(i,N){
		cin>>waza[i];
	}
	rep(i,N){
		sum+=waza[i];
	}
	if(H-sum>0)cout<<"No"<<endl;
	else cout<<"Yes"<<endl;

	return 0;

}

Measured memory_bytes: 1024
using System;

class Program
{
    static void Main(string[] args)
    {
        var ab = Console.ReadLine().Split();
        var a = long.Parse(ab[0]);
        var b = long.Parse(ab[1]);

        var g = gcd(a, b);
        var ans = m1(g) + 1;

        Console.WriteLine(ans);
    }

    static long m1(long n)
    {
        var ans = 0L;
        for (long i = 2; i * i <= n; i++)
        {
            if (n % i != 0) continue;

            ans++;
            while (n % i == 0) n /= i;
        }

        if (n != 1) ans++;
        return ans;
    }

    static long gcd(long a, long b)
    {
        return b == 0 ? a : gcd(b, a % b);
    }
}


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

#define llong long long
#define inf 999999999
#define mp make_pair
#define pb push_back
#define fn fill_n
typedef pair<int, int> P;
typedef pair<P, int> PP;
typedef pair<PP, int> PPP;
typedef struct data{
	int now;
	int cost;
}data;
int nh[4] = {1, 0, -1, 0};
int nw[4] = {0, 1, 0, -1};





int main(){
	int n, k;
	llong int ans = 0;
	cin >> n >> k;
	for(int i = 1; i <= n; i++){
		ans += n/i*max(0, i - k) + max(0, n%i - k + 1);
	}
	if(k == 0) ans -= n - k;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
use std::fmt;
type NodeNum = i32;

#[derive(Debug)]
struct Node {
    id: NodeNum,
    parent: Option<NodeNum>,
    depth: usize,
    children: Vec<NodeNum>,
}

impl fmt::Display for Node {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        let node_type = if self.depth == 0 {
            "root"
        } else if self.children.len() == 0 {
            "leaf"
        } else {
            "internal node"
        };

        let p = match self.parent {
            Some(val) => val,
            None => -1,
        };

        write!(f, "node {}: parent = {:?}, depth = {}, {}, {:?}", self.id, p, self.depth, node_type, self.children)
    }
}

struct Tree {
    nodes: Vec<Node>,
}

impl Tree {
    fn update_node(&mut self, id: NodeNum, childs: Vec<NodeNum>) {
        if childs.len() == 0 { return; }

        let copy_childs = childs.clone();

        self.nodes[id as usize].children = childs;

        for child in copy_childs {
            self.nodes[child as usize].parent = Some(id);
        }
    }

    fn find_root(&self) -> NodeNum {
        let mut current: NodeNum = 0;
        loop {
            match self.nodes[current as usize].parent {
                Some(id) => current = id,
                None => break,
            }
        }
        current
    }

    fn fill_depth(&mut self, root_id: NodeNum, depth: usize) {
        self.nodes[root_id as usize].depth = depth;

        let copy_childs = self.nodes[root_id as usize].children.clone();

        for child in copy_childs {
            self.fill_depth(child, depth + 1);
        }
    }
}

fn main() {
    let n = read::<i32>();

    let mut nodes = Vec::<Node>::new();
    for i in 0..n {
        nodes.push( Node{
            id: i,
            parent: None,
            depth: 0,
            children: Vec::new(),
        });
    }
    let mut tree = Tree { nodes: nodes };


    for _ in 0..n {
        let lines = read_vec::<NodeNum>();

        let childs = if lines.len() < 3 {
            [].to_vec()
        } else {
            lines[2..].to_vec()
        };
        tree.update_node(lines[0], childs);
    }

    let root = tree.find_root();
    tree.fill_depth(root, 0);

    for id_node in 0..n {
        let node = &tree.nodes[id_node as usize];
        println!("{}", node);
    }
}

/// 標準入力から一行を読み取り、指定の型に変換する関数
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut line = String::new();
    std::io::stdin().read_line(&mut line)
        .ok()
        .expect("Faild to read Vec");
    line.trim().split_whitespace()
        .map(|i| i.parse().ok().unwrap()).collect()
}


Measured memory_bytes: 14468
#include <stdio.h>

int main(void)

{
int a,b,c,x,y,z;
   
  scanf("%d%d%d",&a,&b,&c);
   
  if(a > b){ 
    x = a;
    a = b;
    b = x;
  }
   
  if(b > c){
    y = b;
    b = c;
    c = y;
  }
   
  if(a > b){
    z = a;
    a = b;
    b = z;
  }
   
  printf("%d %d %d\n",a,b,c);
   
  return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i < (b); i++)
#define rrep(i, a, b) for (int i = a; i >= (b); i--)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
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;
}
void hr() {
   cerr << "--------------" << endl;
}
const int INF = 1001001001;
const int MOD = 1000000007;

int dp[105][4][2];
int main() {
   cin.tie(0);
   ios_base::sync_with_stdio(0);

   string s;
   int K;
   cin >> s >> K;
   int n = s.size();
   dp[0][0][0] = 1;
   rep(i, 0, n) rep(j, 0, 4) rep(k, 0, 2) {
      int nd = s[i] - '0';
      rep(d, 0, 10) {
         int ni = i + 1, nj = j, nk = k;
         if (d != 0) nj++;
         if (nj > K) continue;
         if (k == 0) {
            if (d > nd) continue;
            if (d < nd) nk = 1;
         }
         dp[ni][nj][nk] += dp[i][j][k];
      }
   }
   cout << dp[n][K][0] + dp[n][K][1] << endl;
   return 0;
}

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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}


int nextInt() { int x; scanf("%d", &x); return x;}
ll nextLong() { ll x; scanf("%lld", &x); return x;}

int t[505][505];

int main2() {
  CLR(t, 0);

  int N = nextInt();
  int M = nextInt();
  int Q = nextInt();

  REP(i, M) {
    int L = nextInt();
    int R = nextInt();
    t[N - L + 1][R] += 1;
  }

  for (int i = 1; i <= N; i++) {
    for (int j = 1; j <= N; j++) {
      t[i][j] += t[i-1][j] + t[i][j-1] - t[i-1][j-1];
    }
  }

  REP(i, Q) {
    int p = nextInt();
    int q = nextInt();
    int ans = t[N - p  + 1][q];
    printf("%d\n", ans);
  }
  return 0;
}

int main() {

#ifdef LOCAL
  for (;!cin.eof();cin>>ws)
#endif
    main2();
  return 0;
}

Measured memory_bytes: 1920
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rep1(i,n) for(int i=1; i<=(n); ++i)
#define repi(i,a,b) for(int i=a; i<=(b); ++i)
#define rrep(i,n) for(int i=(n-1); i>=0; --i)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define pb push_back
#define mp make_pair
#define to_s to_string
#define sz(v) (int)v.size()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )
#define pr(x) cout<<(x)<<'\n'
#define debug(x) cout << #x << ": " << (x) << '\n'
#define yes "Yes"
#define no "No"
using namespace std;
using ll = long long;
using Edge = pair<int,long long>;
using Graph = vector<vector<Edge>>;
typedef pair<int,int> P;
struct aaa{aaa(){ cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);};}aaaaaaa;
int MOD = 1e9 + 7;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return (a*b)/gcd(a,b);}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int N;
Graph G;

vector<int> dir;
void dfs(int v, int p, int c){
    dir[v] = c;
    
    for (auto e : G[v]) {
        if (e.first == p) continue;
        if (e.second & 1) dfs(e.first, v, 1-c);
        else dfs(e.first, v, c);
    }
}


int main(){
    cin >> N;
    G.assign(N, vector<Edge>());
    rep(i,N-1){
        int u,v;
        ll w;
        cin >> u >> v >> w;
        --u, --v;
        G[u].pb(Edge(v,w));
        G[v].pb(Edge(u,w));
    }
    dir.assign(N,0);
    
    dfs(0, -1, 1);
    for (auto v : dir) pr(v);
    
}

Measured memory_bytes: 10496
A,B = map(int,input().split())

mod4diff = (B+1-A)%4
if mod4diff == 0:
    ans = 0
elif mod4diff == 1:
    ans = A%2
elif mod4diff == 2:
    ans = 1
else:
    ans = (A+1)%2

for k in range(1,40):
    am = A % (2**(k+1))
    bm = B % (2**(k+1))
    a = am // (2**k)
    b = bm // (2**k)
    if a and b:
        ans += (2**k) * ((A+B+1)%2)
    elif a:
        ans += (2**k) * (A%2)
    elif b:
        ans += (2**k) * ((B+1)%2)
print(ans)

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

int main() {
  for (int i = 1; i <= 10000; i ++) {
    int x; cin >> x;
    if (x == 0) {
      break;
    } else {
      cout << "Case " << i << ": " << x << endl;
    }
  }
}



Measured memory_bytes: 3088
def main():
    K, S = map(int, input().split())
    ans = 0
    for x in range(K + 1):
        for y in range(K + 1):
            z = S - x - y
            if z >= 0 and z <= K:
                ans += 1
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 9164
(let* ((n (read))
    (h (make-array n :initial-element 0))
    (ans 0)
    (tmp 0))
    (loop for i below n do
        (setf (aref h i) (read))
    )

    (loop for i from 0 below (- n 1) do
        (progn
            (if (>= (aref h i) (aref h (+ i 1)))
                (incf tmp)
                (progn
                    (if (> tmp ans)
                        (setq ans tmp)
                    )
                    (setq tmp 0)
                )
            )
        )
    )
    (if (> tmp ans)
        (setq ans tmp)
    )
    (format t "~D~%" ans)
)

Measured memory_bytes: 76992