akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <stdio.h>
#include <cmath>
using namespace std;
#define N 3 
#define PN 9
#define LIMIT 50

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

struct Puzzle{ int f[PN], space, MD;};
Puzzle state;

int sumMD(Puzzle p){
    int sum = 0;
    for(int i = 0; i < PN; i++){
        if(p.f[i] == PN) continue;
        sum += MDT[i][p.f[i]-1];
    }
    return sum;
}

bool dfs(int depth, int prev){
    if(state.MD == 0) return true;
    if(depth+state.MD > limit) return false;

    int sx = state.space/N;
    int sy = state.space%N;
    Puzzle tmp = state;

    for(int r = 0; r < 4; r++){
        int tx = sx + dx[r];
        int ty = sy + dy[r];
        if(tx < 0 || ty < 0 || tx >= N || ty >= N) continue;
        if((r+2)%4 == prev) continue;
        tmp = state;
        state.MD -= MDT[tx*N+ty][state.f[tx*N+ty]-1];
        state.MD += MDT[sx*N+sy][state.f[tx*N+ty]-1];
        swap(state.f[tx*N+ty],state.f[sx*N+sy]);
        state.space = tx*N+ty;
        if(dfs(depth+1,r)) return true;
        //if(dfs(depth+1,r)){path[depth] = r; return true;}
        state = tmp;
    }

    return false;
}

int main(){
    Puzzle p;

    for(int i = 0; i < PN; i++){
        cin >> p.f[i];
        if(p.f[i] == 0){
            p.f[i] = PN;
            p.space = i;
        }
    }

    for(int i = 0; i < PN; i++){
        for(int j = 0; j < PN; j++){
            MDT[i][j] = abs(i/N - j/N) + abs(i%N - j%N);
        }
    }

    p.MD = sumMD(p);

    for(limit = 0; limit < LIMIT; limit++){
        state = p;
        if(dfs(0,-1)){
            cout << limit << endl;
            return 0;
        }
    }

    return 0;
}


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

int main() {
  int n;
  int a=1;
  cin >> n;
  vector<int> vec(n);
  for(int i=0;i<n;i++){
    cin >> vec.at(i);
  }
  sort(vec.begin(),vec.end());
  
  for(int i=1;i<n;i++){
    if(vec.at(i-1)==vec.at(i)){}
    else{a++;}
  }
  cout << a << endl;
}


Measured memory_bytes: 256
// Template from https://techracho.bpsinc.jp/jhonda/2019_08_05/78537

// input macro for competive-programming from https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

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

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

#[allow(unused_macros)]
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

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

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

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

    ($iter:expr, bytes) => {
        read_value!($iter, String).into_bytes()
    };

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

fn main() {
    use std::io::Read;
    let mut s = String::new();
    std::io::stdin().read_to_string(&mut s).unwrap();

    println!("{}", solve(&s));
}

macro_rules! test {
    ($($input:expr => $output:expr),* $(,)*) => {
        #[test]
        fn solve_test() {
            $(
                assert_eq!(solve($input), $output);
            )*
        }
    };
}

test! {
// r#"4 3 6"# => "safe",
// r#"6 5 1"# => "delicious",
// r#"3 7 12"# => "dangerous",
}

fn solve(src: &str) -> String {
    input! {
        source = src,
        n: usize,
    }

    format!("ABC{}", n)
}

Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n;
  int dif = INT_MIN;
  int price_min = INT_MAX;
  int input;
  scanf("%d",&n);
  while(n--){
    scanf("%d",&input);
    if(dif < input - price_min)dif = input - price_min;
    if(price_min > input)price_min = input;
  }
  printf("%d\n",dif);
}
    
    
    

Measured memory_bytes: 1188
//#include<bits/stdc++.h>
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<numeric>
#include<vector>
#include<set>
#include<map>
#include<unordered_map>
#include<stack>
#include<queue>
#include<list>
using namespace std;

typedef long long ll;

#define MOD 1000000007


class Comb{
private:
  ll *fac,*finv,*inv;
public:
  Comb(){
    fac = new ll[1000000];
    finv = new ll[1000000];
    inv = new ll[1000000];
    fac[0] = 1;
    for(int i=1;i<1000000;i++){
      fac[i] = i*fac[i-1];
      fac[i] %= MOD;
    }
    inv[1] = 1;
    for(int i=2;i<1000000;i++){
      inv[i] = MOD-inv[MOD%i]*(MOD/i)%MOD;
    }
    finv[0] = 1;
    for(int i=1;i<1000000;i++){
      finv[i] = inv[i]*finv[i-1];
      finv[i] %= MOD;
    }
  }
  ll calc(ll n,ll k){
    ll c = fac[n];
    c *= finv[k];c %= MOD;
    c *= finv[n-k];c %= MOD;
    return c;
  }
};

int main(){
  int n,m;
  cin >> n >> m;
  int good[n];
  int ans = 0;
  ll height[n];
  pair<ll,int> h[n];
  vector<int> graph[n];
  for(int i=0;i<n;i++){
    cin >> h[i].first;
    height[i] = h[i].first;
    h[i].second = i;
    good[i] = 1;
  }
  int a,b;
  for(int i=0;i<m;i++){
    cin >> a >> b;
    a--;
    b--;
    graph[a].push_back(b);
    graph[b].push_back(a);
  }
  sort(h,h+n);
  reverse(h,h+n);
  int now;
  for(int i=0;i<n;i++){
    now = h[i].second;
    if(good[now] != 1) continue;
    for(int j=0;j<graph[now].size();j++){
      good[graph[now][j]] = 0;
      if(height[graph[now][j]] >= h[i].first) good[now] = 0;
    }
    ans += good[now];
  }
  cout << ans << endl;
  return 0;
}


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

using namespace std;

template <class T> inline T updmax(T& a, T b) { return a = max(a, b); }
template <class T> inline T updmin(T& a, T b) { return a = min(a, b); }

class Solution {
public:
	using graph = vector<vector<int>>;
	vector<int> ans, f;
	graph g;
	void dfs(int u, int val) {
		ans[u] = val + f[u];
		for (auto v : g[u])
			if (ans[v] == -1) dfs(v, ans[u]);
	}

	void solve() {
		int n, Q;
		cin >> n >> Q;
		g = graph(n);
		f = vector<int>(n);
		ans = vector<int>(n, -1);
		for (int i = 0; i < n - 1; i++) {
			int a, b;
			cin >> a >> b;
			a--, b--;
			g[a].emplace_back(b);
			g[b].emplace_back(a);
		}
		for (int i = 0; i < Q; i++) {
			int p, x;
			cin >> p >> x;
			f[p - 1] += x;
		}
		dfs(0, 0);
		for (int i = 0; i < n; i++) cout << ans[i] << " ";
		cout << "\n";
	}
};

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	Solution sol;
	sol.solve();
	return 0;
}

Measured memory_bytes: 20096
n = int(input())
m = 0
a = 0
r = 0
c = 0
h = 0
for i in range(n):
  s = input()
  if s[0] == "M":
    m += 1
  if s[0] == "R":
    r += 1
  if s[0] == "A":
    a += 1
  if s[0] == "C":
    c += 1
  if s[0] == "H":
    h += 1
    
from itertools import combinations
march = [m,a,r,c,h]
base = list(combinations(march,3))

result = 0
for b in base:
  result += b[0] * b[1] * b[2]
  
print(result)
  

Measured memory_bytes: 49896
#include <iostream>
#include <algorithm>
#include <numeric>
#include <vector>

using namespace std;

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

	//現時点でのminを格納 min
	int min = a[0];
	int sa_m = -2000000000;
	//現時点での最高の差分を格納 sa_m
	for (int i = 1; i < n; ++i)
	{
		if(sa_m < a[i] - min)
			sa_m = a[i] - min;
		if(min > a[i])
			min = a[i];
	}
	cout << sa_m << endl;

	return 0;
}


Measured memory_bytes: 3596
#include<iostream>

using namespace std;
int main(){
  int N, M, X, Y, x, y;
  cin >>N >>M >>X >>Y;
  for(int i = 0; i < N; ++i){
    cin >>x;
    if(X < x) X = x;
  }
  for(int j = 0; j < M; ++j){
    cin >>y;
    if(Y > y) Y = y;
  }
  if(X >= Y) cout << "War" << endl;
  else cout << "No War" <<endl;
    return 0;
}


Measured memory_bytes: 256
N = int(input())
# 素数の登場回数を記録する
ps = [0] * (N+1)

for i in range(2,N+1):
  x = i
  p = 2
  while x > 1 :
    while x % p == 0:
      ps[p] += 1
      x //= p
    p += 1
ans = 1
for c in ps:
  ans = (ans * (c+1)) % 1000000007
print(ans)

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

int main() {
  long long A,B,C,K,ans;
  cin >> A >> B >> C >> K;
  if (A + B > K) {
    ans = min(A,K);
  }
  else {
    ans = A - (K-A-B);
  }
  
  cout << ans << endl;
  return 0;
}


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

int main(void){
    int s5 = 0, s7 = 0, t;
    for (int i = 0; i < 3; i++) {
        scanf("%d", &t);
        if (t == 5) s5 += 5;
        else if (t == 7) s7 += 7;
    }
    (s5 + s7 == 17) ? printf("YES\n") : printf("NO\n");
    return 0;
}


Measured memory_bytes: 1656
/*Rabbi Zidni Ilma*/

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define scl(n) scanf("%lld",&n)
#define scll(n,m) scanf("%lld %lld",&n,&m)
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define mod 1000000007
#define read freopen("input.txt","r",stdin)
#define write freopen("output.txt","w",stdout)

ll dp[105][100005],w[100005],p[100005];

int main()
{
	ll n,c,i,j;
    scll(n,c);
    for(i=1;i<=n;i++)
    scll(w[i],p[i]);
    
    for(i=n+1;i>=1;i--)
    {
    	for(j=1;j<=100000;j++)
    	{
    		
    		dp[i][j]=INT_MAX;
		}
	}
    for(i=n;i>=1;i--)
    {
    	for(j=1;j<=100000;j++)
    	{
    		if(j-p[i]>=0)
    		dp[i][j]=min(dp[i+1][j],dp[i+1][j-p[i]]+w[i]);
    		else
    		dp[i][j]=dp[i+1][j];
		}
	}
	for(i=100000;i>=1;i--)
	{
		if(dp[1][i]<=c)
		{
			printf("%lld\n",i);
			break;
		}
	}
    
}

Measured memory_bytes: 82640
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <map>
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
using namespace std;
int main() {
	int a, b;
	cin >> a >> b;
	if (a%b == 0) {
		cout << -1;
		return 0;
	}
	FOR(i, 1, b + 1)if ((a*i) % b != 0) {cout << a*i; return 0;};
	cout << -1;
	return 0;
}

Measured memory_bytes: 768
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <functional>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <cassert>
#include <exception>
using namespace std;

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


    string s1, s2, s3;

    cin >> s1 >> s2 >> s3;

    transform ( s1.begin(), s1.end() ,s1.begin() , ::toupper);
    transform ( s2.begin(), s2.end() ,s2.begin() , ::toupper);
    transform ( s3.begin(), s3.end() ,s3.begin() , ::toupper);
    
    cout << s1[0] <<s2[0] <<s3[0] << endl;

}


Measured memory_bytes: 256
import fractions
A, B = map(int, input().split())
n = fractions.gcd(A, B)

lst = []
for i in range(1, int(n**0.5)+1):
    if n % i == 0:
        lst.append(i)
        if i != n // i:
            lst.append(n//i)
lst.sort()
cnt = []
for i in range(1, len(lst)):
    if lst[i] == 2:
        cnt.append(lst[i])
    flag = 0
    for j in cnt:
        if lst[i]%j == 0:
            flag = 1
            break
    if flag == 0:
        cnt.append(lst[i])
print(len(cnt) + 1)

Measured memory_bytes: 5304
# include "bits/stdc++.h"
using namespace std;
using LL = long long;
using ULL = unsigned long long;
const double PI = acos(-1);
template<class T>constexpr T INF() { return ::std::numeric_limits<T>::max(); }
template<class T>constexpr T HINF() { return INF<T>() / 2; }
template <typename T_char>T_char TL(T_char cX) { return tolower(cX); };
template <typename T_char>T_char TU(T_char cX) { return toupper(cX); };
const int vy[] = { -1, -1, -1, 0, 1, 1, 1, 0 }, vx[] = { -1, 0, 1, 1, 1, 0, -1, -1 };
const int dx[4] = { -1,0,1,0 }, dy[4] = { 0,-1,0,1 };
const char dir[4] = { 'u','l','d','r' };
int popcnt(unsigned long long n) { int cnt = 0; for (int i = 0; i < 64; i++)if ((n >> i) & 1)cnt++; return cnt; }
int d_sum(LL n) { int ret = 0; while (n > 0) { ret += n % 10; n /= 10; }return ret; }
int d_cnt(LL n) { int ret = 0; while (n > 0) { ret++; n /= 10; }return ret; }
LL gcd(LL a, LL b) { if (b == 0)return a; return gcd(b, a%b); };
LL lcm(LL a, LL b) { LL g = gcd(a, b); return a / g*b; };
# define ALL(qpqpq)           (qpqpq).begin(),(qpqpq).end()
# define UNIQUE(wpwpw)        (wpwpw).erase(unique(ALL((wpwpw))),(wpwpw).end())
# define LOWER(epepe)         transform(ALL((epepe)),(epepe).begin(),TL<char>)
# define UPPER(rprpr)         transform(ALL((rprpr)),(rprpr).begin(),TU<char>)
# define FOR(i,tptpt,ypypy)   for(LL i=(tptpt);i<(ypypy);i++)
# define REP(i,upupu)         FOR(i,0,upupu)
# define INIT                 std::ios::sync_with_stdio(false);std::cin.tie(0)
# pragma warning(disable:4996)

int d;
int p[11], c[11];
int g;

int main() {
	cin >> d >> g;
	REP(i, d)cin >> p[i] >> c[i];
	int ans = INF<int>();
	REP(i, (1 << d)) {
		int num = 0;
		int cnt = 0;
		REP(j, d) {
			if (i&(1 << j)) {
				num += c[j];
				num += p[j] * (j + 1) * 100;
				cnt += p[j];
			}
		}
		if (num >= g) {
			ans = min(ans, cnt);
		}
		else {
			for (int j = d - 1; j >= 0; j--) {
				if (!(i&(1 << j))) {
					int e = min(p[j] - 1, (g - num) / ((j + 1) * 100));
					cnt += e;
					num += e*(j + 1) * 100;
					if (num >= g)break;
				}
			}
			if (num >= g)ans = min(ans, cnt);
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
price = [int(x) for x in input().split()];
N = int(input());
price_d = price[3];
price_s = 2*price[2];
price_h = 4*price[1];
price_q = 8*price[0];
p = min([price_q,price_h,price_s]);
if price_d < p :
    if N%2 == 1 :
        ans = (N-1)//2*price_d + p//2;
    else :
        ans = N//2*price_d;
else :
    ans = N*p//2;

print(ans);



Measured memory_bytes: 9176
n,m = map(int, input().split())
A = [[]for i in range(n)]
b = [0 for i in range(m)]

for i in range(n):
   A[i] = list(map(int, input().split()))
   A[i].append(sum(A[i]))

for i in range(m):
    for j in range(n):
        b[i] += A[j][i]

b.append(sum(b))

for i in range(n):
    print(' '.join(map(str, A[i])))
print(' '.join(map(str, b)))


Measured memory_bytes: 5712
#include <bits/stdc++.h>
using namespace std;
int main(){
int a, b, c; 
cin >> a >> b >> c; 
if(a == b && b == c) cout << 1 << endl; 
else if(a == b || b == c || c == a) cout << 2 << endl; 
else cout << 3 << endl; 
}

Measured memory_bytes: 256
// https://atcoder.jp/contests/agc026/tasks/agc026_b
//
#![allow(unused_imports)]
use std::io::*;
use std::fmt::*;
use std::str::*;
use std::cmp::*;
use std::collections::*;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

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

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

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

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

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

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

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

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

fn isok((initial, purchase, threshold, fill): (i64, i64, i64, i64)) -> bool {
    if purchase > fill || purchase > initial {
        return false;
    }
    if threshold >= purchase-1 {
        return true;
    }

    // initial >= purchase > threshold
    assert!(initial >= purchase);
    assert!(purchase > threshold);


    let g = gcd(purchase, fill);
    let tot = initial - threshold;
    let mx = tot / g;

    let mut left = initial - mx * g;
    if left == threshold {
        left += g;
    }
    // threshold < left
    assert!(threshold < left);

    if left < purchase {
        return false;
    }
    true
}

fn gcd(a: i64, b: i64) -> i64 {
    if b == 0 {
        a
    } else {
        gcd(b, a%b)
    }
}

fn main() {
    input! {
        t: usize,
        tests: [(i64, i64, i64, i64); t]
    };

    for t in tests {
        if isok(t) {
            println!("Yes");
        } else {
            println!("No");
        }
    }
}


Measured memory_bytes: 4352
#include <stdio.h>

#define Mod 1000000007

long long div_mod(long long x, long long y, long long z)
{
	if (x % y == 0) return x / y;
	else return (div_mod((1 + x / y) * y - x, (z % y), y) * z + x) / y;
}

int main()
{
	int i, l, K;
	char S[1000001];
	scanf("%d", &K);
	scanf("%s", S);
	for (l = 0; S[l] != 0; l++);
	
	long long pow[2][1000001], fact[2000001], fact_inv[2000001], ans = 0;
	for (i = 1, pow[0][0] = 1, pow[1][0] = 1; i <= K; i++) {
		pow[0][i] = pow[0][i-1] * 25 % Mod;
		pow[1][i] = pow[1][i-1] * 26 % Mod;
	}
	for (i = 1, fact[0] = 1; i <= K + l; i++) fact[i] = fact[i-1] * i % Mod;
	for (i = K + l - 1, fact_inv[K+l] = div_mod(1, fact[K+l], Mod); i >= 0; i--) fact_inv[i] = fact_inv[i+1] * (i + 1) % Mod; 
	for (i = 0; i <= K; i++) ans = (ans + pow[0][K-i] * pow[1][i] % Mod * fact[K+l-i-1] % Mod * fact_inv[K-i] % Mod * fact_inv[l-1]) % Mod;
	printf("%lld\n", ans);
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 49500
s = input()
t = s.replace('BC', 'D')

a = 0 # 連続するaの数
ans = 0 # 答え

for i in t:
    if i == 'A':
        a += 1
    elif i == 'D':
        ans += a
    else:
        a = 0

print(ans)

Measured memory_bytes: 3500
import java.util.Scanner;
 
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		int[] x = new int[4];
		char[] y = new char[3];

		x[0] = Integer.parseInt(s.substring(0,1));
		x[1] = Integer.parseInt(s.substring(1,2));
		x[2] = Integer.parseInt(s.substring(2,3));
		x[3] = Integer.parseInt(s.substring(3,4));


		for(int i = 0 ; i < 8 ; i++) {
			int sum = x[0];    
			for(int j = 0 ; j < 3 ; j++) {
				if((1 & (i>>j)) == 1) {
					sum += x[3-j];
					y[2-j] = '+';

				} else {
					sum -= x[3-j];
					y[2-j] = '-';
				}
			}
			if(sum == 7) {
				System.out.print(x[0]);
				System.out.print(y[0]);
				System.out.print(x[1]);
				System.out.print(y[1]);
				System.out.print(x[2]);
				System.out.print(y[2]);
				System.out.print(x[3]);
				System.out.print("=7");
				return;
			}
		}
	}
}

Measured memory_bytes: 23764
#include<bits/stdc++.h>
#define F first
#define S second
#define MP make_pair
#define pb push_back
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair< int, int > P;
typedef pair< LL, LL > LP;
typedef pair< int, P > iP;
typedef pair< P, P > PP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;
static const int SIZE = 100005;

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int pr[SIZE] = {};
    vector< int > prime;
    for( int i = 2; i < SIZE; ++i ) {
        if( pr[i] == 0 ) {
            if( i != 2 ) prime.pb( i );

        }
        for( int j = i * 2; j < SIZE; j += i ) {
            pr[j] = 1;

        }
    }
    int like_2017[SIZE] = {};
    for( int i = 0; i < prime.size(); ++i ) {
        if( pr[( prime[i] + 1 ) / 2] == 0 ) {
            like_2017[prime[i]] = 1;

        }
    }

    for( int i = 3; i < SIZE; ++i ) {
        like_2017[i] += like_2017[i - 1];

    }

    int q;
    cin >> q;
    for( int i = 0; i < q; ++i ) {
        int l, r;
        cin >> l >> r;
        cout << like_2017[r] - like_2017[l - 1] << endl;

    }
    return 0;
}



Measured memory_bytes: 1536
def solve(string):
    n, k = map(int, string.split(" "))
    ans = 0
    """
    for a in range(1, n + 1):
        for b in range(1, n + 1):
            for c in range(1, n + 1):
                if (a + b) % k == 0 and (b + c) % k == 0 and (c + a) % k == 0:
                    ans.append((a, b, c))
    """
    if k % 2 == 1:
        ans = (n // k)**3
    else:
        ans = (n // k)**3 + ((n // k) + 1)**3 if n % k >= (k // 2) else 2 * ((n // k)**3)
    return str(ans)


if __name__ == '__main__':
    print(solve(input()))



Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>


using namespace std;

int n, s[10001] = {0}, q, t[500] = {0};
int key;

int linear_search(int *s,int key,int n)
{
	int i = 0,count = 0;
	s[n] = key;

	while(1)
	{
		if (i == n)
		{
			return 0;
		}

		if (s[i] == key)
		{
			count++;
			break;
		}

		i++;
	}

	return count;

}

int main()
{
	int sum = 0;

	scanf("%d", &n);

	for(int i = 0; i < n; i++)
	{
		scanf("%d", &s[i]);
	}

	scanf("%d", &q);

	for(int i = 0; i < q; i++)
	{
		scanf("%d", &key);
		sum += linear_search(s,key,n);
	}

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


	return 0;
}
	

Measured memory_bytes: 3224
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
int main() {
    int n, m; cin >> n >> m;
    vector<long long> v(n+10, 0);
    v[0] = 1;
    for (int i = 0; i < m; i++) {
        int c; cin >> c; v[c] = -1;
    }
    for (int i = 0; i < n; i++) {
        if (v[i] == -1) continue;
        if (v[i+1] != -1) {
            v[i+1] = (v[i+1] + v[i]) % mod;
        }
        if (v[i+2] != -1) {
            v[i+2] = (v[i+2] + v[i]) % mod;
        }
    }
    cout << v[n] << endl;
    return 0;
}

Measured memory_bytes: 1024
#include<iostream>
using namespace std;
int main(){
    int n,i,j,m,s=0;
    cin>>n;
    
    int d[n];
    for(i=0;i<n;i++) cin>>d[i];
    for(i=0;i<n-1;i++){
        for(j=i+1;j<n;j++){
            m=d[i]*d[j];
            s =s + m;
        }
    }
    cout<<s<<endl;

  return 0;
	}
    

Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <algorithm>
#include <queue>
using namespace std;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define REP(i,n) for(ll i=0;i<n;i++)
#define REPR(i,n) for(ll i=n-1;i>=0;i--)

typedef long long ll;
#define INF 1e18

int main(){
	ll n; cin>>n;
	vector<ll> a(n);
	REP(i,n) cin>>a[i];

	vector<ll> num(n+1);
	REP(i,n){
		num[a[i]]++;
	}
	ll ans=0;
	REP(i,n+1){
		ans+=num[i]*(num[i]-1)/2;
	}
	REP(i,n){
		cout<<ans-(num[a[i]]-1)<<endl;
	}
	return 0;
}


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

int n;
char s[105];

int main()
{
    scanf("%s",s+1);
    n=strlen(s+1);
    int flag=1;
    for(int i=1;i<=(n-1)/2;i++)
        if(s[i]!=s[(n-1)/2-i+1]) flag=0;
    for(int i=(n+3)/2;i<=n;i++)
        if(s[i]!=s[n+(n+3)/2-i]) flag=0;
    for(int i=1;i<=n;i++)
        if(s[i]!=s[n-i+1]) flag=0;
    if(flag) printf("Yes"); else printf("No");
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi std::vector<std::vector<int> >
#define vvl std::vector<std::vector<ll> >
#define MODs 1000000007;
typedef long long int ll;
using namespace std;

int main(int argc, char const *argv[]) {
  int N;
  std::cin >> N;
  std::vector<int> A(N), B(N);
  for(int i=0;i<N;i++) {
    std::cin >> A[i];
    B[i] = A[i];
  }
  sort(B.begin(), B.end());
  ll ans = 0;
  for(int i=0;i<N;i++){
    int now = lower_bound(B.begin(), B.end(), A[i]) - B.begin();
    ans += ((now-i)%2==0?0:1);
  }
  std::cout << ans/2 << '\n';
  return 0;
}


Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define in(x,y,h,w) x >= 0 && x < h && y >= 0 && y < w

#define int long long
//typedef    long long          ll;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      P;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
 
const int INF=2e+18;
const double EPS=1e-9;
const int MOD=1000000007;

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

signed main(){
	int q;
	cin >> q;
	for(int i = 0;i < q;i++){
		int a,b;
		cin >> a >> b;
		if(a > b) swap(a,b);
		if(a == b) cout << (a - 1) * 2 << endl;
		else{
			int low = a,up = INF;
			while(up - low > 1){
				int mid = (up + low) / 2;
				if(mid > (a * b - 1) / mid) up = mid;
				else low = mid;
			}
			cout << up + (a * b - 1) / up - 2 << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 764
N, M = map(int,input().split())
H=list(map(int,input().split()))

A=[0]*(N+1)
for i in range(M):
    x,y=map(int,input().split())
    A[x]=max(A[x],H[y-1])
    A[y]=max(A[y],H[x-1])

count=0
for i in range(1,N+1):
    if H[i-1]>A[i]:
        count+=1

print(count)

Measured memory_bytes: 20008
/*
  AOJ 2441
  Title:FizzBuzz
  @kankichi573
*/
#include <stdio.h>
#include <string.h>

long long table[20];
char testbuf[1000];

long long expt10(int n)
{
  if(n==1)
    return(1);
  else
    return(10*expt10(n-1));
}

long long string_length_n_digits(int n)
{
  long long all,c3,c5,c15,low,next,ret;

  low=expt10(n);
  next=low*10;

  all=next-low;
  c15=((next-10)-(low+5 ))/15 + 1;
  c3 =((next-1) -(low+2 ))/3  + 1;
  c5 =((next-5) - low    )/5  + 1;
  //printf("%d: %lld %lld %lld %lld\n",n,all,c3,c5,c15);


  ret = (all-(c3-c15)-(c5-c15)-c15)*n;
  
  ret += (c3-c15)*4;
  ret += (c5-c15)*4;
  ret += c15*8;
  return(ret);
}




void make_fizzbuzz_string(long long from,int count)
{
  long long i;
  long long low,next;
  char buf[20];

  //printf("mk f=%lld c=%d\n",from ,count);

  for(i=from;i<from+count;i++)
    {
      memset(buf,0,20);
      sprintf(buf,"%lld",i);
      if((i % 15)==0)
	strcat(testbuf,"FizzBuzz");
      else if((i % 5)==0)
	strcat(testbuf,"Buzz");
      else if((i % 3)==0)
	strcat(testbuf,"Fizz");
      else
	strcat(testbuf,buf);
    }

}
void prepare()
{
  int i;

  table[1]=0;    // 1 digits
  table[2]=21;   // 2 digits
  //printf("%d::%lld\n",2,table[2]);
  for(i=3;i<=18;i++)
    {
      table[i]=table[i-1]+string_length_n_digits(i-1);
      //printf("%d::%lld\n",i,table[i]);
    }
}

int get_keta(long long s)
{
  int i;
  for(i=17;i>=1;i--)
    if(s > table[i])
      return(i);
  return(0);
}

main()
{
  int n,keta;
  long long ret,s,q,r;
  char outbuf[21];

  prepare();
  scanf("%lld",&s);
  if(s<=21)
    {
      make_fizzbuzz_string(1,21);
    }
  else
    {
      keta=get_keta(s);
      //printf("keta=%d\n",keta);
      s -= table[keta];
      //printf("s=%lld\n",s);
      if(s<=3*keta+8) // between 100..00 and 10..05
	make_fizzbuzz_string(expt10(keta),15);
      else
	{
	  s -= 3*keta+8;
	  q = s/(8+4*4+4*2+keta*8);
	  s %=  (8+4*4+4*2+keta*8);
	  //printf("s2=%lld\n",s);
	  make_fizzbuzz_string(expt10(keta)+5+15*q,30);
	}
    }
  
  strncpy(outbuf,testbuf+s-1,20);
  outbuf[20]='\0';
  printf("%s\n",outbuf);
  
  return(0);
}

Measured memory_bytes: 632
def solve():
    B = [0]*N
    for i in range(N):
        B[i] = a[i] - (i+1)
    B.sort()
    b = B[N//2]
#    print(b)
    scr = 0
    for l in range(N):
        scr += abs(B[l] - b)
    print(scr)

if __name__ == "__main__":
    N = int(input())
    a = list(map(int, input().split()))  
    solve()


Measured memory_bytes: 30900
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);++i)
class BellmanFord{
    private:
    typedef std::pair<std::pair<int,int>,long long> P;
    int V,E;
    long long INF = (1LL<<61);
    std::vector<std::pair<std::pair<int,int>,long long>> es;
    
    public:
    void init(std::vector<std::pair<std::pair<int,int>,long long>> edge){
        //辺数をもとめる　
        E=edge.size();
        //頂点数を決定する
        V=0;
        for(int i=0;i<edge.size();i++){
            V=std::max(V,edge[i].first.first+1);
            V=std::max(V,edge[i].first.second+1);
        }
        es=edge;
    }
    
    std::vector<std::pair<long long,bool>> solve(int s){
        std::vector<std::pair<long long,bool>> d;
        //INFで初期化する
        for(int i=0;i<V;i++){
            d.push_back({INF,false});
        }
        d[s].first=0;
        for(int j=0;j<2*V;j++){
             bool update=false;
            for(int i=0;i<E;i++){
                P k=es[i];
                if(d[k.first.first].first!=INF && d[k.first.second].first>d[k.first.first].first+k.second){
                    d[k.first.second].first=d[k.first.first].first+k.second;
                    if(j>=V){
                        d[k.first.second].second=true;
                    }
                    update=true;
                }
            }
            if(!update)break;
        }
        return d;
    }
    
    //init:{{int,int},longlong}のvectorを渡すことで有向グラフを構築する
    //solve:始点を渡すとinitで構築したグラフでベルマンフォードをし、コストのvectorを返す
};

int main(){
    int N,M,p;
    int A[5040],B[5040],C[5040];
    std::vector<std::pair<std::pair<int,int>,long long>> G;
    std::vector<std::pair<long long,bool>> D;
    cin >> N >> M >> p;
    REP(i,M){
        cin >> A[i] >> B[i] >> C[i];
        A[i]--;B[i]--;
        G.push_back({{A[i],B[i]},-C[i]+p});
    }
    BellmanFord bell;
    bell.init(G);D=bell.solve(0);
    
    
    
    bool c[5040]={},d[5040]={};
    queue<int> P;
    
    vector<int> H[5040];
    REP(i,M){
        H[A[i]].push_back(B[i]);
    }
    P.push(0);
    while(!P.empty()){
        int q=P.front();
        P.pop();
        if(c[q]){
            continue;
        }else{
            c[q]=true;
        }
        REP(i,H[q].size()){
            P.push(H[q][i]);
        }
    }
    
    REP(i,M){
        H[i].clear();
    }
    REP(i,M){
        H[B[i]].push_back(A[i]);
    }
    P.push(N-1);
    while(!P.empty()){
        int q=P.front();
        P.pop();
        if(d[q]){
            continue;
        }else{
            d[q]=true;
        }
        REP(i,H[q].size()){
            P.push(H[q][i]);
        }
    }
    
    REP(i,N){
        if(c[i] && d[i] && D[i].second){
            cout << -1 << endl;
            return 0;
        }
    }
    cout << max(-D[N-1].first,0LL) << endl;
    return 0;
}


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

int main(){

    int N;
    cin >> N;

    int l = (int)(N/1.08) - 5;
    int r = l + 10;
    bool check = false;

    for(int i=l; i<r; i++){
        if((int)(i*1.08) == N){
            cout << i << endl;
            check = true;
            break;
        }
    }
    if(check != true)
        printf(":(\n");
}

Measured memory_bytes: 3656
def main():
    n = int(input())
    a = sorted(list(map(int,input().split())),reverse=True)

    inf = 10**18
    res = a[0]
    if 0 in a:
        print(0)
        return 0
    for i in range(1,n):
        res *= a[i]
        if res > inf:
            print(-1)
            return 0

    if res > inf:
        print(-1)
        return 0
    else:
        print(res)

if __name__ == '__main__':
    main()



Measured memory_bytes: 84764
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**13
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    n = I()
    a = [LI() for _ in range(n)]
    for i in range(101):
        for j in range(101):
            rh = inf
            for x,y,h in a:
                th = h + abs(i-x) + abs(j-y)
                if rh > th:
                    rh = th
            f = True
            for x,y,h in a[1:]:
                if max(rh - abs(i-x) - abs(j-y),0) != h:
                    f = False
                    break
            if f:
                return '{} {} {}'.format(i,j,rh)

    return -1


print(main())


Measured memory_bytes: 5464
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 998244353
dd = [(0,-1),(1,0),(0,1),(-1,0)]
ddn = [(0,-1),(1,-1),(1,0),(1,1),(0,1),(-1,-1),(-1,0),(-1,1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


s = S()
k = I()
n = len(s)
res = []

def push(res,s):
    if s not in res:
        for i in range(len(res)):
            if s<res[i]:
                res.insert(i,s)
                break
        res.append(s)
    return(res[0:k])

for i in range(n):
    for j in range(i,n)[0:5]:
        s1 = s[i:j+1]
        res = push(res,s1)

print(res[-1])



Measured memory_bytes: 7232
root = [len(i) for i in input().split("T")]
xi_set, yi_set = [root[0]], [0]
xg, yg = map(int, input().split())
x_list, y_list = root[2::2], root[1::2]

for delta_x in x_list:
    xi_set = set([xi+delta_x for xi in xi_set] + [xi-delta_x for xi in xi_set])
if not xg in xi_set:
    print("No")
    exit()
    
for delta_y in y_list:
    yi_set = set([yi+delta_y for yi in yi_set] + [yi-delta_y for yi in yi_set])
if not yg in yi_set:
    print("No")
    exit()

print("Yes")

Measured memory_bytes: 4132
n, m, k = map(int, input().split())
a = [0] + list(map(int, input().split()))
b = [0] + list(map(int, input().split()))

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

ans = 0
b_cnt = m
for a_cnt in range(n+1):
    if a[a_cnt] > k:
        continue
    while a[a_cnt] + b[b_cnt] > k:
        b_cnt -= 1
    ans = max(ans, a_cnt + b_cnt)
print(ans)


Measured memory_bytes: 40084
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(begin, i, end) for (int i = begin; i < (int)(end); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1000000007;

int main()
{
    ll N, K;
    cin >> N >> K;
    vector<ll> p(N), c(N);

    rep(0, i, N)
    {
        cin >> p.at(i);
        p.at(i)--;
    }
    rep(0, i, N)
    {
        cin >> c.at(i);
    }

    ll ans = -1000000000000000;
    rep(0, i, N)
    {
        ll now = p.at(i);
        vector<ll> sub;
        while (now != i)
        {
            sub.push_back(c.at(now));
            now = p.at(now);
        }
        sub.push_back(c.at(now));

        if (sub.size() >= K)
        {
            ll sum = 0;
            rep(0, j, K)
            {
                sum += sub.at(j);
                ans = max(ans, sum);
            }
        }
        else
        {
            ll subsum = 0;
            rep(0, j, sub.size())
            {
                subsum += sub.at(j);
                ans = max(ans, subsum);
            }
            ll sum = subsum * (K / sub.size());
            if (K % sub.size() == 0)
            {
                sum -= subsum;
                rep(0, j, sub.size())
                {
                    sum += sub.at(j);
                    ans = max(ans, sum);
                }
            }
            else
            {
                rep(0, j, K - sub.size() * (K / sub.size()))
                {
                    sum += sub.at(j);
                    ans = max(ans, sum);
                }
            }
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 3808
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
REP(i,v.size()){if(i)os<<" ";os<<v[i];}return os;}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
REP(i,v.size()){if(i)os<<endl;os<<v[i];}return os;}

int main() {
	int n,a,b; cin >> n >> a >> b;
	cout << min(a*n,b) << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <vector> 
# include <cstdint>
#define FOR(i,l,r) for(int i=(l);i<(r);++i)
#define RFOR(i,l,r) for(int i=(l);i>=(int)(r);i--)
#define rep(i,n)  FOR(i,0,n)
#define rrep(i,n)  RFOR(i,n-1,0)

#define int long long
using namespace std;
const int MX = 1e6;
const int inf = 1e13;
const int mod = 1e9+7;
#define ll long long

signed main() {
    int n;
    cin >> n;
    vector<int> a(n);
    vector<int> b(n);
    rep(i,n) cin>> a[i] >>b[i];
    int sum = 0;
    rrep(i,n) {
        int x, y;
        x = a[i]+sum;
        y = b[i];
        if(y==1 || x==0) continue; 
        if(x%y==0) continue;
        sum += (y-x%y);
       // cout << x << " "<< y << " "<< sum << endl;
    }
    cout << sum << endl;
    
    return 0;
}



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

int main(){
    string a , b;
    cin >> a >> b;
    
    int n = a.size() , m = b.size();
    
    vector<vector<int>> dp(n + 1 , vector<int>(m + 1 , 0));
    dp[0][0] = 0;
    for(int i = 0 ; i <= n ; i++)
        for(int j = 0 ; j <= m ; j++)
            if(i < n && j < m && a[i] == b[j]){
                dp[i + 1][j + 1] = 1 + dp[i][j];
                dp[i + 1][j] = max(dp[i + 1][j] , dp[i][j]);
                dp[i][j + 1] = max(dp[i][j + 1] , dp[i][j]);
            }else{
                if(i + 1 <= n)
                dp[i + 1][j] = max(dp[i + 1][j] , dp[i][j]);
                if(j + 1 <= m)
                dp[i][j + 1] = max(dp[i][j + 1] , dp[i][j]);
            }

    int ans = 0;
    int I = n , J = m;
//    for(int i = 0 ; i <= n ; i++){
//        for(int j = 0 ; j <= m ; j++) 
//            cout << dp[i][j] << " " ;
//        cout << '\n';
//    }
    string strans = "";
    
    while(1){
       // cout << i << " " << j << '\n';
        if(I == 0 || J == 0)
            break;
        
        if(dp[I][J] == dp[I][J - 1]){
            J = J - 1;
            continue;
        }
        
        if(dp[I][J] == dp[I - 1][J]){
            I = I - 1;
            continue;
        }
        
        I = I - 1;
        J = J - 1;

        strans+=a[I];
    }

    //cout << ans << '\n';
    reverse(strans.begin() , strans.end());
    cout << strans << '\n';
    return 0;
}


Measured memory_bytes: 38636
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
const int maxn=1e5+1;
const int inf=1e9+7;
int n,m,degIn[maxn],f[maxn];
vector<int> adj[maxn];
inline void Enter(){
    cin>>n>>m;
    for(int u,v;m--;){
        cin>>u>>v;
        adj[u].push_back(v);
        degIn[v]++;
    }
}
inline void Solve(){
    fill(f+1,f+n+1,-inf);
    queue<int> q;
    for(int i=1;i<=n;i++) if(!degIn[i]) q.push(i),f[i]=0;
    while(q.size()){
        int u=q.front();
        q.pop();
        for(int v: adj[u]){
            f[v]=max(f[v],f[u]+1);
            degIn[v]--;
            if(!degIn[v]) q.push(v);
        }
    }
    int res=-inf;
    for(int i=1;i<=n;i++) res=max(res,f[i]);
    cout<<res;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    Enter();
    Solve();
    return 0;
}

Measured memory_bytes: 6528
#include<bits/stdc++.h>
using namespace std;
int n,m,a[101];
vector<int>v;
int main()
{
    scanf("%d%d",&n,&m);
    for(int i=1;i<=m;i++) scanf("%d",&a[i]);
    for(int i=1;i<=m;i++)
        if(a[i]&1) v.push_back(i);
    if(v.size()>2) {printf("Impossible\n");return 0;}
    if(v.size()==1) swap(a[v[0]],a[1]);
    else if(v.size()==2) swap(a[v[0]],a[1]),swap(a[v[1]],a[m]);
    if(a[m]==1) swap(a[1],a[m]);
    for(int i=1;i<=m;i++)
        printf(i==m?"%d\n":"%d ",a[i]);
    if(m==1)
    {
        if(a[1]==1) printf("1\n1\n");
        else printf("2\n1 %d\n",a[1]-1);
    }
    else if(a[1]==1&&a[m]==1)
    {
        if(m==2) printf("1\n2\n");
        else
        {
            printf("%d\n",m-1);
            printf("2 ");
            for(int i=2;i<=m-1;i++)
                printf(i==m-1?"%d\n":"%d ",a[i]);
        }
    }
    else
    {
        printf("%d\n",m);
        printf("%d ",a[1]+1);
        for(int i=2;i<=m-1;i++)
            printf("%d ",a[i]);
        printf("%d\n",a[m]-1);
    }
}


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

int int_cmp(const int *a, const int *b){
	if(*a<*b) return 1;
	else if(*a<*b) return -1;
	return 0;
}

int main(void){
	while(1){
		int n, m, i;
		int p[1000];
		long ans=0;
	
		scanf(" %d %d", &n, &m);
		if(n==0) break;
		
		for(i=0; i<n; i++) scanf(" %d", &p[i]);
		qsort(p, n, sizeof(int), (int(*)(const void*, const void*))int_cmp);
		
		for(i=0; i<n; i++)
			if((i+1)%m!=0) ans+=p[i];
			
		printf("%ld\n", ans);
	}
	return 0;
}

Measured memory_bytes: 648
/*
 * じょえチャンネル
 * 高評価・チャンネル登録よろしくおねがいします！
 * https://www.youtube.com/channel/UCRXsI3FL_kvaVL9zoolBfbQ
 */
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define all(v) v.begin(),v.end()
#define inf (int)(3e18)
#define P pair<int,int>
#define mod (int)(1e9+7)
template<class T> inline void chmin(T &a, T b) {
	a = min(a, b);
}
template<class T> inline void chmax(T &a, T b) {
	a = max(a, b);
}

int N,M;
int s[5];
char c[5];
signed main(){
	cin>>N>>M;
	rep(i,M){
		cin>>s[i]>>c[i];
		s[i]--;
	}
	int mi,mx;
	if(N==1){mi=0,mx=9;}
	else if(N==2){mi=10,mx=99;}
	else {mi=100,mx=999;}
	for(int i=mi;i<=mx;i++){
		string t=to_string(i);
		rep(j,M){
			if(t[s[j]]!=c[j]){
				goto ng;
			}
		}
		cout<<i<<endl;return 0;
		ng:;
	}
	cout<<-1<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cassert>
#include <limits>
#include <numeric>
#include <type_traits>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <functional>
#include <utility>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <complex>
#include <climits>

using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef pair<ll, ll> P;
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define REP(i,n)  FOR(i,0,n)

ll gcd(ll a, ll b) {
  while (a && b) {
    if (a >= b) a %= b;
    else b %= a;
  }
  return a + b;
}
ll ketasum(ll n) { //桁の数字全ての和を返す 例: 112 -> 4
	ll sum=0;
	if (n<0) return 0;
	while (n>0) {
		sum += n%10;
		n /= 10;
	}
	return sum;
}

typedef pair<ll, ll> pair_t;

bool comp(const pair_t &a, const pair_t &b) {
        return a.first < b.first;
}

void sort2vectors(vector<ll> &av, vector<ll> &bv)
{ // ふたつの配列をまとめてそーと A[2,1] B[3,4] -> 1,4 2,3
        ll n = av.size();
        vector<pair_t> p(n);
        vector<ll> av2(n), bv2(n);
        for (ll i = 0; i < n; i++)
                p[i] = make_pair(av[i], bv[i]);
        sort(p.begin(), p.end(), comp);
        for (ll i = 0; i < n; i++) {
                av2[i] = p[i].first;
                bv2[i] = p[i].second;
        }
        av = av2;
        bv = bv2;
}
ll facctorialMethod(ll k){ //階乗
	ll s;
	if(k > 1){
		s = k*facctorialMethod(k-1);
	} else {
		s = 1;
	}
	return s;
}
vl primes(ll n){
	vl x(n);
	REP(i, n){
		x[i] = 0;
	}
	for(ll i = 2; i < sqrt(n) + 2; i++){
		while(n % i == 0){
			n /= i;
			x[i-1] += 1;
		}
	}
	if(n > 1){
		x[n-1] += 1;
	}
	return x;
}


void solve(){
	ll N, K, Q;
	cin >> N >> K >> Q;
	vl A(Q);
	REP(i, Q){
		cin >> A[i];
	}
	vl count(N);
	REP(i, Q){
		count[A[i]-1]++;
	}
	vl than(N);
	REP(i, N){
		than[i] = Q - count[i] + 1;
		if(than[i] > K){
			cout << "No" << endl;
		} else {
			cout << "Yes" << endl;
		}
	}
}


const ll mod = 1000000007;
int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	solve();
}


Measured memory_bytes: 2944
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue>
#include <climits>


int main(){
    long H,W,Ks;
    std::cin >> H >> W >> Ks;
    char S[6][6];
    for(long i=0; i<H; i++){
        for(long j=0; j<W; j++){
            char temp;
            std::cin >> temp;
            S[i][j]=temp;
        }
    }
    long numW=std::pow(2,W);
    long numH=std::pow(2,H);
    long kouhoW[6],kouhoH[6];
    long counts;
    long result=0;
    for(long i=0; i<numH;i++){
        for(long k=0; k<H; k++){
            kouhoH[k]=(i>>k)&1;
            //std::cout << kouhoH[k] << std::endl;
        }
        for(long j=0; j<numW;j++){
            for(long k=0; k<W; k++){
                kouhoW[k]=(j>>k)&1;
            }
            counts=0;
            
            for(long k=0; k<H; k++){
                for(long l=0; l<W; l++){
                    if(S[k][l]=='#'){
                        counts++;
                        if(kouhoH[k]==1 || kouhoW[l]==1){
                            counts--;
                        }
                    }
                }
            }
            
            //std::cout << counts << std::endl;
            if(counts==Ks){
                result++;
            }
        }

    }
    std::cout << result << std::endl;
    return 0;
}

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

using namespace std;

int n;

int main()
{
	ios::sync_with_stdio(false), cin.tie(0);
	
	cin >> n;
	int tmp = n % 10;
	if (tmp == 3) cout << "bon\n";
	else if (tmp == 0 || tmp == 1 || tmp == 6 || tmp == 8) cout << "pon\n";
	else cout << "hon\n";
	
	return 0;
}

Measured memory_bytes: 3624