akhauriyash/Code-Regression huggingface dataset:
#include <math.h>
#include <regex>
#include "bits/stdc++.h"
#define FOR(i, s, e) for (int i = int(s); i < int(e); ++i)
#define REP(i, e) FOR(i, 0, e)
#define INF (INT_MAX / 2)
#define LINF (LLONG_MAX / 2)
#define EPS (1.0e-8)
const int MGN = 10;
const int ARY_SZ_MAX = (int)1e7;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>;
using vb = vector<bool>; using vvb = vector<vb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>; using psl = pair<string, ll>;


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

  ll MOD = (ll)1e9+7;
  int N; cin>>N;
  vi A = vi(N+1); FOR(i,1,N+1) cin>>A[i];
  // A[i] := i より前にある、i と同じ色の数

  ll ans = 1L;
  vi dp = vi(N+1, 0);
  // dp[i] := i 個置いてある色の数はいくつか (0<= dp[i] <= 3)
  dp[0] = 3;

  FOR(i,1,N+1) {
    int j = A[i];
    ans *= dp[j];
    ans %= MOD;

    dp[j] -= 1;
    dp[j+1] += 1;
  }
  
  cout << ans << endl;

  
  return 0;
}


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

#pragma optimize("O3")

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef long double ld;

#define sync                    \
ios_base::sync_with_stdio(0); \
cin.tie(0);                   \
cout.tie(0)
#define ALL(V) V.begin(), V.end()
#define SZ(V) (int)V.size()
#define pb push_back
#define mp make_pair
#define fopen freopen("input.txt", "r", stdin); freopen("output.txt","w", stdout)
#define FOR(i, a, b) for(ll i = (a); i < (b); ++i)
#define FORR(i, b, a) for(ll i = (b) - 1; i >= (a); --i)
#define REP(i, N) FOR(i, 0, N)
#define REPR(i, N) RFOR(i, N, 0)
#define FILL(A,value) memset(A,value,sizeof(A))
#define ff first
#define ss second
#define pii pair<int,int>
#define pll pair<ll, ll>
#define MP make_pair
#define endl '\n'

const ll MOD = 1e9 + 7;
const ll INF = 2*1e9 + 7;
const int base = 2e5+1;
const int MAX =1e5+2;
const double EPS = 1e-9;
const double PI = acos(-1.);
const int MAXN = 2*1e6+1;

bool was[1000], used[1000];
int deg[1000], deg2[1000];
vector<vi> g(1000), g2(1000);
vi v;

bool cmp(int x, int y)
{
    return deg[x] <= deg[y];
}

int main()
{
    int n;
    cin >> n;
    vector<pii> r(n), b(n);
    FOR(i,0,n) cin >> r[i].ff >> r[i].ss;
    FOR(i,0,n) cin >> b[i].ff >> b[i].ss;
    int cnt = 0;
    set<pii> s;
    FOR(i,0,n)
    {

        FOR(j,0,n)
        {
            if(r[i].ff < b[j].ff && r[i].ss < b[j].ss){
                g[i].pb(j);
                deg[i]++;
                deg2[j]++;
                g2[j].pb(i);
            }
        }
    }
    FOR(k,0,n)
    {
        int mn = 1100, ind = 0;
        FOR(i,0,n)
        {
            if(used[i]) continue;
            if(deg[i] < mn)
            {
                mn = deg[i];
                ind = i;
            }
        }
        int m = 1100, j = 0;
        for(auto y: g[ind])
        {
            if(!was[y])
            {
                if(deg2[y] < m)
                {
                    m = deg2[y];
                    j = y;
                }
            }
        }
        if(m != 1100)
        {
            cnt++;
            was[j] = 1;
            for(auto to: g2[j]) deg[to]--;
        }
        for(auto to: g[ind]) deg2[to]--;
        used[ind] = 1;
    }
    cout << cnt;
    return 0;
}




Measured memory_bytes: 384
import sys
input = sys.stdin.readline

import collections, bisect

n, m = map(int, input().split())
p = [[int(j) for j in input().split()] for i in range(m)]
a = collections.defaultdict(list)
for x, y in sorted(p):
  a[x] += [y]
for x, y in p:
  z = bisect.bisect(a[x], y)
  print("%06d%06d"%(x,z))
  


Measured memory_bytes: 41112
N = int(input())
times = list(map(int, input().split()))
M = int(input())
sum_t = sum(times)
for _ in range(M):
  dist, time = map(int, input().split())
  if times[dist-1] >= time:
    print(sum_t-(times[dist-1]-time))
  else:
    print(sum_t+(time-times[dist-1]))


Measured memory_bytes: 3060
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#define rep(i,a,b) for(register int i=a;i<=b;i++)
#define dep(i,a,b) for(int i=a;i>=b;i--)
#define ll long long
#define mem(x,num) memset(x,num,sizeof x)
#define reg(x) for(int i=last[x];i;i=e[i].next)
using namespace std;
inline ll read(){
    ll f=1,x=0;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
//******head by yjjr******
const int maxn=2e2+6,maxX=1e5+6;
const ll mod=1e9+7;
int n,X;
ll f[maxn][maxX],a[maxn],ans=0;
inline bool cmp(ll x,ll y){return x>y;}
int main(){
    n=read(),X=read();
    rep(i,1,n)a[i]=read();
    sort(a+1,a+1+n,cmp);
    f[0][X]=1;
    rep(i,1,n)
        rep(j,0,X){
            f[i][j%a[i]]=((f[i][j%a[i]]+f[i-1][j])%mod+mod)%mod;
            f[i][j]=((f[i][j]+1ll*f[i-1][j]*(n-i))%mod+mod)%mod;
        }
    rep(i,0,X)ans=((ans+1ll*f[n][i]*i%mod)+mod)%mod;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 157184
{-# OPTIONS_GHC -O2 -funbox-strict-fields #-}

main :: IO ()
main = do
  [a, b, k] <- map read . words <$> getLine
  print $ solve a b k

solve :: Int -> Int -> Int -> Int
solve a b k = [i | i <- reverse [1 .. min a b], divisible a b i] !! (k - 1)

divisible :: Int -> Int -> Int -> Bool
divisible a b i = a `mod` i == 0 && b `mod` i == 0


Measured memory_bytes: 508
#include <cmath>
#include <cstdio>
#include <vector>
#include <iterator>
#include <iostream>
#include <algorithm>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <stdio.h>
#include <chrono>
using namespace std;

#define rep(i,s,n) for(ll i=s;i<(n);++i)
using ll = long long;
using pll = pair<ll, ll>;
constexpr ll INF = (1LL << 60);
constexpr ll MOD = (1e9 + 7);
//constexpr ll MOD = (998244353);

using vl = vector<ll>;
using vvl = vector<vector<ll>>;

template<class T>
vector<vector<T>> vvt(T init, ll m, ll n) {
	vector<vector<T>> ans = vector<vector<T>>(m, vector<T>(n, init));
	return move(ans);
}

template<class T>
vector<T> vt(T init,ll n) {
	vector<T> ans = vector<T>(n, init);
	return move(ans);
}

template<class T>
T maxVec(vector<T> &v) {
	T ans = -INF;
	rep(i,0, v.size()) {
		ans = max(ans, v[i]);
	}
	return ans;
}

// 素数判定
bool judge(ll n) {
	for (ll i = 2; i * i <= n; i++) if (n %= i)return false;
	return true;
}


template <class C>
void print(const C& c, std::ostream& os = std::cout)
{
	std::copy(std::begin(c), std::end(c), std::ostream_iterator<typename C::value_type>(os, ", "));
	os << std::endl;
}

ll count(ll n,ll r) {
	ll ans = 0,check = 1;
	rep(i,0, r) {
		if ((n & check) > 0) {
			ans++;
		}
		check = check << 1;
	}
	return ans;
}

ll gcd(ll a, ll b) {
	if (a < b) return gcd(b, a);
	ll r;
	while ((r = a % b)) {
		a = b;
		b = r;
	}
	return b;
}

class UnionFind {
public:
	vl parent;
	UnionFind(ll n) {
		parent = vl(n, -1);
	}

	ll root(ll n) {
		if (parent.at(n) < 0)return n;
		parent.at(n) = root(parent.at(n));
		return parent.at(n);
	}

	ll size(ll n) {
		return -parent.at(root(n));
	}

	bool connect(ll a, ll b) {
		if (root(a) == root(b))return false;
		a = root(a); b = root(b);
		if (size(a) < size(b))swap(a,b);
		parent[a] += parent[b];
		parent[b] = a;
		return true;
	}
};


int main() {
	ll n, m;
	cin >> n >> m;
	vl p(n, 0);
	rep(i, 0, n) {
		cin >> p[i];
	}
	UnionFind uni = UnionFind(n);
	rep(i, 0, m) {
		ll x, y;
		cin >> x >> y;
		uni.connect(x - 1, y - 1);
	}
	
	ll ans = 0;
	rep(i, 0, n) {
		if (uni.root(p[i] - 1) == uni.root(i))ans++;
	}
	printf("%lld\n", ans);
}

Measured memory_bytes: 1792
s = gets.chomp.split('')
h = {}
s.each do |v|
  if h[v].nil?
    h[v] = 1
  else
    h[v] += 1
  end
end

ok = true
h.each do |_, v|
  ok = ok && v == 2
end
if ok
  puts 'Yes'
else
  puts 'No'
end

Measured memory_bytes: 1788
#include<bits/stdc++.h>
#include <iostream>
#include <string>
using namespace std;
int main(){
  string s;
  int sum=0;
  cin >> s;
  for(int i=0;i<3;i++){
    if(s[i]=='1') sum=sum+1;
    }
  cout << sum << endl;
}

Measured memory_bytes: 256
open Batteries
open Printf

let ($) g f x = g (f x)

module MyList = struct
  include List
  let foldl = fold_left
  let foldli = fold_lefti
  let foldr = fold_right
  let foldri = fold_righti
  
  let flatmap = concat_map

  let zipf = map2
  let zipfi = map2i
end

module L = MyList

let atoi = int_of_string
let itoa = string_of_int
let atof = float_of_string
let ftoa = string_of_float
let ctoi = int_of_char
let itoc = char_of_int

let stocl = String.to_list
let cltos = String.of_list
let spsp s = String.split_on_char ' ' s

module MyString = struct
  include String

  let map' f s = L.map f (stocl s)
  let mapi' f s = L.map f (stocl s)

  let zipf f a b = L.zipf f (stocl a) (stocl b)
  let zipfi f a b = L.zipfi f (stocl a) (stocl b)

  let mkstr f sep ls =
    L.foldl (fun acc x -> acc ^ sep ^ (f x)) (f @@ L.hd ls) (List.tl ls)
end

module S = MyString

let rds () = read_line ()

let rdi () = atoi @@ rds ()

let rdhs () = spsp @@ rds ()
let rdhi () = rdhs () |> L.map atoi

let rdi2 () = match rdhi () with
  | a::b::_ -> (a, b)
  | _ -> (0, 0)

let rdi3 () = match rdhi () with
| a::b::c::_ -> (a, b, c)
| _ -> (0, 0, 0)

let rdi4 () = match rdhi () with
| a::b::c::d::_ -> (a, b, c, d)
| _ -> (0, 0, 0, 0)

let rdv n rdf =
  let rec rdv' n =
    if n <= 0 then []
    else (
      let s = rdf () in
      s::(rdv' (n - 1))
    )
  in rdv' n

let rdvi n = rdv n rdi
let rdvi2 n = rdv n rdi2
let rdvi3 n = rdv n rdi3
let rdvi4 n = rdv n rdi4

let puts s = print_endline s
let putyn b = puts (if b then "Yes" else "No")
let puti i = puts @@ itoa i

let set_power ls =
  let rec set_power' ls pls =
    match ls with
    | [] -> pls
    | hd::tl -> set_power' tl (L.flatmap (fun p -> [p; hd::p]) pls)
  in set_power' ls [[]]

let _ =
  let (n,m,x) = rdi3 () in
  let cas = rdv n rdhi in
  let selections = set_power @@ L.range 0 `To (n - 1) in
  
  let read_books sel = cas
    |> L.foldli (fun ca i bk ->
      if L.mem i sel then L.map2 (+) bk ca
      else ca) (L.make (m + 1) 0) in

  let costs = selections
    |> L.filter_map (fun sel ->
      let ca = read_books sel in
      if (L.min @@ L.tl ca) >= x then Some (L.hd ca)
      else None) in

  let result = match costs with
  | [] -> -1
  | cs -> L.min cs
  in

  puti result;;


Measured memory_bytes: 7556
/*
URL : https://onlinejudge.u-aizu.ac.jp/courses/library/3/DSL/1
*/

#include<stdio.h>

int n;

void unite(int x, int y, int *N);
void same(int x, int y, int *N);

int main(void)
{
	int q;
	int i;
	int c,x,y;
	scanf("%d %d",&n, &q);
	
	int N[n];
	
	for(i = 0; i < n; i++){
		N[i] = i;
	}
	
	while(q--){
		scanf("%d %d %d",&c, &x, &y);
		
		switch(c){
		case 0:
			unite(x, y, N);
			break;
			
		case 1:
			same(x, y, N);
			break;
		}
	}
	return 0;
}

void unite(int x, int y, int *N)
{
	int i;
	int z = N[x];
	for(i = 0; i < n; i++){
		if(z == N[i]){
			N[i] = N[y];
		}
	}
}

void same(int x, int y, int *N)
{
	if(N[x] == N[y]){
		printf("%d\n",1);
	} else {
		printf("%d\n",0);
	}

}


Measured memory_bytes: 2112
A,B,C,D=map(int,input().split())
x=A-D #高橋の残りHP
y=C-B #青木の残りHP

while True:
  if y<=0:
    print("Yes") #高橋win
  elif x<=0:
    print("No") #y>0,高橋lose
  else:
      x=x-D
      y=y-B
      continue
  break

Measured memory_bytes: 61688
#include <stdio.h>
#include <math.h>

int f(int x, int y, int z) {
	return x * x + y * y + z * z + x * y + y * z + z * x;
}

int main() {
	int n, ans[100000] = {0};
	scanf("%d", &n);
	for (int x = 1; x <= sqrt(n); x++) {
		for (int y = 1; y <= sqrt(n); y++) {
			for (int z = 1; z <= sqrt(n); z++) {
				ans[f(x, y, z)]++;
			}
		}
	}
	for (int i = 1; i <= n; i++) printf("%d\n", ans[i]);
	return 0;
}

Measured memory_bytes: 2524
#include<iostream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdlib>

using namespace std;

int main() {
	long long N;
	cin >> N;
	string S;
	cin >> S;

	long long ans = N + 1;
	long long* white = new long long[N];
	long long* black = new long long[N];
	white[0] = 0;
	black[0] = 0;
	if (S[0] == '.') { 
		white[0] = 1; 
		black[0] = 0;
	}
	else {
		black[0] = 1;
		white[0] = 0;
	}

	for (int i = 1; i < N; i++) {
		white[i] = white[i - 1];
		black[i] = black[i - 1];
		if (S[i] == '.') { white[i]++; }
		else { black[i]++; }
		//cout << "white[" << i << "] = " << white[i] << ", " << flush;
		//cout << "black[" << i << "] = " << black[i] << endl;
	}

	long long change = 0;
	for (int i = 0; i < N; i++) {
		change = white[N - 1] - white[i] + black[i] - black[0];
		if (S[0] == '#' && white[N - 1] != 0 && i != 0) { change++; }
		//cout << "change = " << change << endl;
		if (ans > change) {
			ans = change;
		}
	}

	cout << ans << endl;

	delete[] white;
	delete[] black;
}

Measured memory_bytes: 3716
import java.util.Scanner;

class Main {
    public static void main(final String[] args) {
        Scanner scan = new Scanner(System.in);
        int W = scan.nextInt();
        int H = scan.nextInt();
        int x = scan.nextInt();
        int y = scan.nextInt();

        double area =(double)W * H/2;

        int flag =  0;
        if (x*2==W && y*2==H) {
            flag = 1;
        }

        System.out.println(area + " " + flag);

    }
}


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

using namespace std;

const int INF=100000000;

int main(){

	int n;
	while(cin>>n&&n!=0){
	vector<int> v;
	for(int i = 0; i < n; i++){
		int t;
		cin>>t;
		v.push_back(t);
	}
	int maxDel=INF;
	for(int i = 0; i < n; i++){
		for(int j = 1; j <= 3; j++){
			//if(i==5&&j==2){
			//	cout<<endl;
			//}
			if(v[i]==j)
				continue;
			int up=i-1;
			int down=i+1;
			int sum=0;
			int c=1;
			bool first=true;
			int col=j;
			// ¼[ÖTõð©¯é
			while(1){
				// upeer
				int nCal=-1;
				while(1){
					if(up<0)
						break;
					if(v[up]!=col){
						nCal=v[up];
						break;
					}
					up--;
					c++;
				}
				// lower
				while(1){
					if(down>=n)
						break;
					if(v[down]!=col){
						if(nCal==-1)
							nCal=v[down];
						break;
					}
					down++;
					c++;
				}
				// àµvª4ÈãÈçíðs¤
				if(c>=4){
					sum+=c;
				}
				else{
					break;
				}
				c=0;
				if(nCal==-1)
					break;
				else
					col=nCal;
			}
			//if(first){
			//	first=false;
			//}
			maxDel=min(maxDel,n-sum);
		}
	}
	cout<<maxDel<<endl;
	}

	return 0;
}

Measured memory_bytes: 0
#include<iostream>
using namespace std;
int main(){
  int a=0,b=0, n[150], nos, sum[150]={0};
  char str[150][100][3];
  while(1){
    cin >> n[a];
    if (n[a]==0) break;
    for(b=0;b<n[a];b++){
      cin >> str[a][b];
    }
    a++;
  }
  nos = a;
  for(a=0;a<nos;a++)
    {  
     for(b=0;b+1<n[a];b+=2)
       {
         if (str[a][b][0]-str[a][b+1][0]) sum[a]++;
       }
     cout << sum[a] << endl;
    }
  return 0;
}

Measured memory_bytes: 1204
#include<cstdio>
#include<algorithm>
using namespace std;
int n;
int Query(int ans)
{
    char ret[20];
    printf("%d\n", ans);
	fflush(stdout);
    scanf("%s", ret);
    if(ret[0] == 'V') exit(0);
    return ret[0] == 'M' ? 1 : 0;
}
int main()
{
	scanf("%d",&n);
	int l=0,r=n-1,f=Query(0);
	while(l<=r)
	{
		int mid=(l+r)>>1;
		int p=Query(mid);
		if(p==f)
		{
			if(mid%2) r=mid-1;
			else l=mid+1;
		}
		else
		{
			if(mid%2) l=mid+1;
			else r=mid-1;
		}
	}
}

Measured memory_bytes: 760
#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;

int main()
{
	int N;
	cin >> N;
	vector<int> x(N), a(N * N, -1);
	priority_queue<pii, vector<pii>, greater<pii>> pq;
	for (int i = 0; i < N; i++) {
		cin >> x[i]; --x[i];
		a[x[i]] = i;
		for (int j = 0; j < N - 1; j++) {
			if (j < i) {
				pq.emplace(x[i] - 1, i);
			}
			else {
				pq.emplace(N * N + x[i] - 1, i);
			}
		}
	}
	bool ng = false;
	for (int i = 0; i < N * N; i++) if (a[i] == -1) {
		auto p = pq.top(); pq.pop();
		if (p.first < i) {
			ng = true;
			break;
		}
		a[i] = p.second;
	}
	if (ng) {
		cout << "No" << endl;
		return 0;
	}
	vector<vector<int>> pos(N);
	for (int i = 0; i < N * N; i++) {
		pos[a[i]].push_back(i);
	}
	for (int i = 0; i < N; i++) {
		if (pos[i][i] != x[i]) {
			ng = true;
			break;
		}
	}
	if (ng) {
		cout << "No" << endl;
		return 0;
	}
	cout << "Yes" << endl;
	for (int i = 0; i < N * N; i++) {
		printf("%d%c", a[i] + 1, " \n"[i + 1 == N * N]);
	}
	return 0;
}


Measured memory_bytes: 5108
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <limits>
#include <sstream>
#include <fstream>
#include <climits>
#include <map>
#include <numeric>
#include <functional>
#include <utility>

using namespace std;

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

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

  int x = 1;
  rep(i, n) {
    if (a[i] == x) {
      ++x;
    }
  }

  cout << (x >= 2 ? n - (x - 1) : -1) << endl;
 
  return 0;
}

Measured memory_bytes: 1024
import sys
sys.setrecursionlimit(10**7)
input = lambda: sys.stdin.readline().strip()

def main():
    N = int(input())
    A_list = list(input().split())
    buka_dict = {str(i+1): 0 for i in range(N)}
    for i in A_list:
        buka_dict[str(i)] += 1
    for i in buka_dict.values():
        print(i)


main()


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

using namespace std;

int main() {
    int a,b;
    cin>>a>>b;
    for(int i=1;i<=1009;i++){
        if(floor(i*0.08)==a && floor(i*0.1)==b){
            cout<<i;
            return 0;
        }
    }
    cout<<-1;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <assert.h>
#include <vector>
#include <unordered_map>
#include <queue>
#include <climits>
#include <cmath>
#include <algorithm>
using namespace std;
int main(){
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);
  string S;
  cin >> S;
  cout << S[0] << S[1] << S[2] << endl;

  return 0;

}



Measured memory_bytes: 3612
import sys


def parallelism(x1, y1, x2, y2, x3, y3, x4, y4):
    if x2 - x1 == 0.0 or x4 - x3 == 0.0:
        return x2 - x1 == 0.0 and x4 - x3 == 0.0
    else:
        return ((y2 - y1) / (x2 - x1)) == ((y4 - y3) / (x4 - x3))


#lines = sys.stdin.readlines()
#lines.pop(0)

for i in range(input()):
    x1, y1, x2, y2, x3, y3, x4, y4 = tuple(map(float, raw_input().split(' ')))
    if parallelism(x1, y1, x2, y2, x3, y3, x4, y4):
        print "YES"
    else:
        print "NO"

Measured memory_bytes: 4256
#include <cstdio>
#include <queue>
#include <cstring>
#include <vector>
#define INF 1000
using namespace std;

int n,m,type[3];
vector<int> G[101];
vector<int> step[101][3];
bool used[101];
int dp[101];

void bfs(int v,int st){
	queue<int> que[151];
	que[0].push(v);
	for(int i=0;i<type[st];i++){
		memset(used,false,sizeof(used));
		while(que[i].size()){
			int now=que[i].front();
			que[i].pop();
			for(int j=0;j<G[now].size();j++){
				int nw=G[now][j];
				if(!used[nw]){
					used[nw]=true;
					que[i+1].push(nw);
				}
			}
		}
	}
	while(que[type[st]].size()){
		step[v][st].push_back(que[type[st]].front());
		que[type[st]].pop();
	}
}

int func(int v){
	if(v==n-1)return 0;
	if(dp[v]>=0)return dp[v];
	if(used[v])return INF;
	int res=0;
	used[v]=true;
	for(int i=0;i<3;i++){
		int rr=INF;
		for(int j=0;j<step[v][i].size();j++){
			rr=min(rr,func(step[v][i][j]));
		}
		res=max(res,rr);
	}
	used[v]=false;
	return dp[v]=(res+1);
}

int main(void){
	scanf("%d%d",&n,&m);
	for(int i=0;i<3;i++){
		scanf("%d",&type[i]);
	}
	for(int i=0;i<m;i++){
		int f,t;
		scanf("%d%d",&f,&t);
		f--;
		t--;
		G[f].push_back(t);
	}
	for(int i=0;i<n;i++){
		for(int j=0;j<3;j++){
			bfs(i,j);
		}
	}
	for(int i=0;i<n;i++){
		dp[i]=INF;
	}
	dp[n-1]=0;
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			int lr=0;
			for(int k=0;k<3;k++){
				int rr=INF;
				for(int l=0;l<step[j][k].size();l++){
					rr=min(rr,dp[step[j][k][l]]+1);
				}
				lr=max(lr,rr);
			}
			dp[j]=min(dp[j],lr);
		}
	}
	
	memset(used,false,sizeof(used));
	//int res=func(0);
	if(dp[0]>=INF)printf("IMPOSSIBLE\n");
	else printf("%d\n",dp[0]);
	return 0;
}

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

int main() {
    int n;string s;cin>>n>>s;
    int r,g,b;r=g=b=0;
    for (char c:s) {
        if (c=='R') r++;
        else if (c=='G') g++;
        else b++;
    }
    ll ans=(ll)r*g*b;
    for (int i=0;i<n;i++)
        for (int j=i+1;j+j-i<n;j++) {
            int k=j+j-i;
            if (s[i]!=s[j]&&s[j]!=s[k]&&s[i]!=s[k])
                ans--;
        }
    cout<<ans<<endl;
    return 0;
}

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

int main() 
{
	int m, f, r;
	while (cin >> m >> f >> r)
	{
		if (m == -1 && f == -1 && r == -1)break;
		if (m == -1 || f == -1)cout << "F" << endl;
		else if (m + f >= 80)cout << "A" << endl;
		else if (m + f >= 65)cout << "B" << endl;
		else if (m + f >= 50)cout << "C" << endl;
		else if (m + f >= 30)
		{
			if (r >= 50)cout << "C" << endl;
			else cout << "D" << endl;
		}
		else cout << "F" << endl;
	}
	return 0;

}

Measured memory_bytes: 1156
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < (int)(b); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1e9 + 7;
const int INF = 1e9;
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

int main() {
    int D; //365
    cin >> D;
    int c[26];
    rep(i, 0, 26) {
        cin >> c[i];
    }
    int s[D][26];
    int t[D] = {};
    rep(i, 0, D) {
        int mx = -1;
        rep(j, 0, 26) {
            cin >> s[i][j];
            /*if (mx < s[i][j]) {
                mx = s[i][j];
                t[i] = j;
            }*/
        }
    }


    rep(i, 0, D) {
        srand(time(NULL));
        t[i] = rand() % 26;
    }

    /*ll mx_score = -1;
    int cnt = 100;
    while (cnt--) {
        srand(time(NULL));
        int d = rand() % 365;
        int q = rand() % 26;
        int old = t[d];
        t[d] = q;

        ll score[D] = {};
        vector<int> last_day(26, -1);
        rep(i, 0, D) {
            if (i != 0) score[i] = score[i - 1];
            score[i] += s[i][t[i]];
            last_day[t[i]] = i;
            int decrease = 0;
            rep(j, 0, 26) {
                decrease += c[j] * (i - last_day[j]);
            }
            score[i] -= decrease;
        }
        if (mx_score > score[D - 1]) {
            t[d] = old;
        } else {
            mx_score = score[D - 1];
        }
    }*/

    rep(i, 0, D) cout << t[i] + 1 << endl;

    return 0;
}


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

int main() {
    int n;
    cin >> n;
    int64_t a[n];
    map<int64_t, int64_t> mp;
    rep(i,n) {
        cin >> a[i];
        mp[a[i]]++;
    }
    int64_t sum_choice = 0;
    for(auto itr = mp.begin(); itr != mp.end(); itr++) {
        sum_choice += itr->second * (itr->second-1) / 2;
    }
    rep(i,n) {
        int64_t c = mp[a[i]];
        int64_t ans = sum_choice - c*(c-1)/2 + max((c-1)*(c-2)/2, 0l);
        cout << ans << endl;
    }
}

Measured memory_bytes: 11008
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
const int INF = 100100100;
using namespace std;

int main()
{
  int A, B;
  bool res=true;
  cin >> A >> B;

  if(A>8 || B>8) res = false;

  if(res) cout << "Yay!"  << endl;
  else cout << ":(" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define each(a,x) for(auto a : (x))
#define all(a) (a).begin(),(a).end()
#define chmin(a,b) ((a) = min((a),(b)))
#define chmax(a,b) ((a) = max((a),(b)))
#define in_range(x,l,r) ((l)<=(x) && (x)<(r))
#define printvec(a) rep(i,a) cout << a[i] << " \n"[i+1==(a).size()];
#define fs first
#define sc second
#define em emplace
#define eb emplace_back
#define sz size()
#define MP make_pair
using namespace std;
typedef long long ll;
typedef double D;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vs;

const ll INF = 1e8;
const D EPS = 1e-8;
const ll MOD = 1e9+7;

int main(){
  rep(i,3){
    string s;
    cin >> s;
    cout << s[0];
  }
  cout << endl;
}


Measured memory_bytes: 256
// https://atcoder.jp/contests/abc154/tasks/abc154_e

#include "algorithm"
#include "bitset"
#include "cmath"
#include "functional"
#include "iomanip"
#include "iostream"
#include "map"
#include "numeric"
#include "queue"
#include "set"
#include "string"
#include "vector"
#define rep(i, to) for (ll i = 0; i < (to); ++i)
#define rep1(i, to) for (ll i = 1; i <= (to); ++i)
#define repf(i, from, to) for (ll i = from; i < (to); ++i)
#define repr(i, from) for (ll i = from - 1; i >= 0; --i)
#define all(vec) vec.begin(), vec.end()
#define unless(cond) if (!(cond))
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef long double ld;
template <typename T>
using V = vector<T>;
using VL = V<ll>;
using VVL = V<VL>;
template <typename T, typename U>
using P = pair<T, U>;
using PL = P<ll, ll>;
using VPL = V<PL>;
template <typename T>
inline bool chmax(T& a, T b);
template <typename T>
inline bool chmin(T& a, T b);
void print_ints(vector<ll> v);
template <typename T>
void drop(T a);

const ll INF = 1e18;

void solve() {
  string N;
  ll K;
  cin >> N >> K;

  // dp[i][k][strict]: 上から i 桁目までで k 個使った場合
  V<VVL> dp(N.size() + 1, VVL(K + 1, VL(2)));
  dp[0][0][1] = 1;

  ll len = N.size();
  rep(i, len) {
    // 次の桁
    ll num = N[i] - '0';

    // 今の所
    rep(k, K + 1) {
      if (num == 0) {
        // 0 をとる場合
        dp[i + 1][k][1] += dp[i][k][1];
        dp[i + 1][k][0] += dp[i][k][0];

        // 0 以外
        if (k >= K) continue;

        dp[i + 1][k + 1][0] += 9 * dp[i][k][0];
      } else {
        // 0 をとる場合
        dp[i + 1][k][0] += dp[i][k][0] + dp[i][k][1];

        // 0 以外
        if (k >= K) continue;

        dp[i + 1][k + 1][1] += dp[i][k][1];
        dp[i + 1][k + 1][0] += dp[i][k][0] * 9 + dp[i][k][1] * (num - 1);
      }
    }
  }

  ll res = dp[N.size()][K][1] + dp[N.size()][K][0];
  cout << res << endl;
}

void solve2() {
  string N;
  ll K;
  cin >> N >> K;

  // dp[i][k][strict]: 上から i 桁目までで k 個使った場合
  V<VVL> dp(N.size() + 1, VVL(K + 1, VL(2)));
  dp[0][0][1] = 1;

  ll len = N.size();
  // 配る DP
  rep(i, len) {
    ll digit_num = N[i] - '0';

    // num については貰う
    rep(k, K + 1) rep(strict, 2) rep(num, 10) {
      if (strict && num > digit_num) continue;
      ll nk = k + (num != 0);
      if (nk > K) continue;
      dp[i + 1][nk][strict && digit_num == num] += dp[i][k][strict];
    }
  }

  ll res = dp[N.size()][K][1] + dp[N.size()][K][0];
  cout << res << endl;
}

struct exit_exception : public std::exception {
  const char* what() const throw() { return "Exited"; }
};

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

  try {
    solve2();
  } catch (exit_exception& e) {
  }

  return 0;
}
#endif

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

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

void print_ints(vector<ll> v) {
  rep(i, v.size()) {
    if (i > 0) {
      cout << " ";
    }

    cout << v[i];
  }

  cout << endl;
}

template <typename T>
void drop(T res) {
  cout << res << endl;
  throw exit_exception();
}


Measured memory_bytes: 256
// atcoder/abc153/B/main.cpp
// author: @___Johniel
// github: https://github.com/johniel/

#include <bits/stdc++.h>

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { each (i, v) is >> i; return is; }

template<typename T> ostream& operator << (ostream& os, set<T> s) { os << "("; each (i, s) os << i << ","; os << ")"; return os; }
template<typename K, typename V> ostream& operator << (ostream& os, map<K, V> m) { os << "("; each (i, m) os << i << ","; os << ")"; return os; }

template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }
template<typename P, typename Q> inline pair<Q, P> swap(pair<P, Q> p) { return make_pair(p.second, p.first); }

constexpr lli mod = 1e9 + 7;

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  lli h, n;
  while (cin >> h >> n) {
    vector<lli> a(n);
    cin >> a;
    each (i, a) {
      h -= i;
      if (h <= 0) break;
    }
    cout << (h <= 0 ? "Yes" : "No") << endl;
  }

  return 0;
}


Measured memory_bytes: 1024
while True:
    n, m = map(int, input().split())
    ex = [0] * 11
    if n == 0: break
    for i in range(n):
        d, p = map(int, input().split())
        ex[p] += d
    ex.reverse()
    for i in range(len(ex)):
        m -= ex[i]
        if m <= 0:
            ex[i] = abs(m)
            break
        else:
            ex[i] = 0
    ex.reverse()
    ans = 0
    for i in range(len(ex)):
        ans += ex[i] * i
    print(ans)

Measured memory_bytes: 6720
//#include "IntMod.h"
//typedef IntMod<1000000007> MInt;

//#include "Union_Find.h"

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <algorithm>
#include <functional>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
#include <sstream>
#include <numeric>
#include <list>
#include <bitset>

using namespace std;
#define REP(i,a,n) for(int i = (a); i < (int)(n); ++i)
#define REPM(i,n,a) for(int i = ((n) - 1); i >= (a); --i)
#define EPS 0.0001
#define INF 0x3FFFFFFF
#define INFLL 0x3FFFFFFF3FFFFFFF
#define INFD 1.0e+308
#define FLOAT setprecision(16)
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<LL, LL> PP;

template <class T, class U>
istream& operator>>(istream& ist, pair<T, U>& right) { return ist >> right.first >> right.second; }
template <class T, class U>
ostream& operator<<(ostream& ost, pair<T, U>& right) { return ost << right.first << ' ' << right.second; }
template <class T, class TCompatible, size_t N>
void Fill(T(&dest)[N], const TCompatible& val) { fill(begin(dest), end(dest), val); }
template <class T, class TCompatible, size_t M, size_t N>
void Fill(T(&dest)[M][N], const TCompatible& val) { for (int i = 0; i < M; ++i) Fill(dest[i], val); }
//sum, 累積和
// 負のときの割り算に注意
#if 1
#include <array>
#include <unordered_set>
#include <unordered_map>
template<class T>
using PriorityQ = priority_queue<T, vector<T>, greater<T> >;	// コスト小を優先
#endif

//#include "Union_Find.h"

int N;
map<LL, vector<int>, greater<LL>> M;
LL A[100001];
int main() {
	cin >> N;
	REP(i, 0, N) {
		int a;
		cin >> a;
		M[a].push_back(i);
	}
	M[0].push_back(1);

	LL c = 0;
	int mn = INF;
	for (auto it = M.begin(); it != prev(M.end()); ++it){
		LL diff = it->first - next(it)->first;
		c += it->second.size();
		mn = min(mn, it->second[0]);
		A[mn] += c * diff;
	}
	REP(i, 0, N) {
		cout << A[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 12800
/*　　　　　　　{:i:i:|i:i:/l/l--　 　 　--l/li:i:i|i:i:i:i}
　　　　　　 　 {:rx|:i:i ィi芥ミ 　 　 .ィi芥ミｉ:ｉ|ﾍ:i:i:}
.　　　 　 　 　 ｛ﾏ|ｉ:  {::’:} 　 　 　{:‘::} :ｉ:i:|〉｝:/
　　 　 　 　 　 乂|:i:| ｀¨¨¨¨´ 　 　　｀¨¨¨´  :i:ｉ:|ｼ/
　 　 　 　 　 　 ﾉ:|:i|　　　　　　′　　　 　   |:i:i:|ﾂ
　　　　　　　　/:/|:i:| ､　　　 　_ _ 　　　　  |:i:i:|
　 　 　　 　 /:/ .|:i:|/ ＼　　　 　 　     ｨ〔|:i:/
　　 　 　  　 〈;/ く刈＿ 个 　   -   　＜}　./|/_〉
　　     　　 r-っ'~ﾞ~ﾞ~ﾞ~ﾞ~ﾞ~ﾞ~ﾞ~ﾞ~ﾞ~ﾞ~ﾞ~ﾞ~ﾞ~ﾞ~ﾞ~ﾞ~ﾞ|___
　　 　     /／ニつ　　　　　　 ､　　　　　　　ノﾆﾆ　＼
.　　　     |　　ニ⊃ 　./　/　 ──   /　/　　..⊆ﾆﾆ　　:|
.　　　     |　　丁´　 /|￣|￣  ─‐ /|￣|￣ 　 .￣|丁 　|
.　　　     |　　ﾉ.  　 |￣|￣  ─‐  |￣|￣ 　 　.|八 　|
.　　　     |　　||. 　 |￣|￣ |￣| |￣|￣ 　   .|　|
.　 　 　   |  　||   　￣￣￣　￣ 　￣￣￣　　  .|　|  |
.　 　 　  　    ||＿＿＿＿＿＿＿＿＿＿＿＿______|__　　 ',
　 　      ,′　 | ７ﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆ}  ,′
.　　     {　　　|/　}ﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆ{/ 　 　
*///讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐。
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>
#include <limits>

using namespace std;

#define rep(b) for(int i=0;i<int(b);i++)
#define ll long long
#define fst first
#define snd second
#define pf(b) printf("%.12f\n",(double)b)
#define _GLIBCXX_DEBUG
const double pai = 3.1415926535897;
#define _cos(n) cos(n*pai/180)
#define l_b lower_bound
#define u_b upper_bound
#define b_s binary_search

//factorial(練習)　階乗
int fact(int n) {
	int a = 1;
	for (int i = 1;i <= n;i++) a *= i;
	return a;
}
int sa(int n, int m) {      //差！
	if (n < m)return m - n;
	else return n - m;
}
int keta(int num) {
	int n = 0;
	if (num == 0) {
		return 1;
	}
	while (num != 0) {
		num /= 10;
		n++;
	}
	return n;
}

string s,t;
int ans;
signed main() {
	cin >> s >> t;
	int n = s.size();
	rep(n) {
		if (s[i] != t[i])ans++;
	}cout << ans << endl;
}

Measured memory_bytes: 3832
PROGRAM ATCODER

implicit none
integer(16) :: n, w_max, i, j, sum_w
integer(16), allocatable :: w(:), v(:), dp(:,:)

read(*,*) n, w_max
allocate(dp(0:n,0:w_max), w(0:n), v(0:n))

dp = 0

do i = 0, n-1
	read(*,*) w(i), v(i)
end do

do i = 0, n-1
	do sum_w = 0, w_max
    	if (sum_w-w(i) >= 0) then
        	call chmax(dp(i+1,sum_w), dp(i,sum_w-w(i))+v(i))
		end if
		call chmax(dp(i+1,sum_w), dp(i,sum_w))
    end do
end do

write(*,'(i0)') maxval(dp)

END PROGRAM ATCODER

subroutine chmax(dp,x)
implicit none
integer(16) :: dp, x

if (dp < x) then
	dp = x
	return
end if

end subroutine

Measured memory_bytes: 158080
#include<iostream>
#include<string>
#include<algorithm>
#include<math.h>

using namespace std;

int main(void)
{
	int i,lr,rl, N, K,maxnumber=0;
	char s[100001];
	cin >> N;
	cin >> K;
	for (i = 0; i < N; i++)
		cin >> s[i];
	s[i] = '\0';
	lr = rl = 0;
	for (i = 0; i < N; i++)
	{
		if (s[i] == 'L')
		{
			if (s[i - 1] == 'L')
				maxnumber++;
			if (s[i + 1] == 'R')
				lr++;
		}
		else
		{
			if (s[i + 1] == 'R')
				maxnumber++;
			if (s[i + 1] == 'L')
				rl++;
		}
	}
	maxnumber += 2 * (min(rl, lr) > K ? K:min(rl,lr));
	if (min(rl, lr) < K)
		maxnumber += min(K - min(rl, lr), abs(rl - lr));
	cout << maxnumber << endl;
}

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

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int 
#define pb push_back
void solve()
{
    int n;
    cin>>n;
    n=n%10;
    if(n==2||n==4||n==5||n==7||n==9){
        cout<<"hon"<<endl;
    }
    else if(n==0||n==1||n==6||n==8){
        cout<<"pon"<<endl;
    }
    else{
        cout<<"bon"<<endl;
    }
       
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    solve();
    return 0;
}


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

int main() {
  string s;
  cin >> s;
  int ans = 0;
  if (s =="RRR") ans = 3;
  if (s =="RRS") ans = 2;
  if (s =="RSR") ans = 1;
  if (s =="SRR") ans = 2;
  if (s =="RSS") ans = 1;
  if (s =="SRS") ans = 1;
  if (s =="SSR") ans = 1;
  if (s =="SSS") ans = 0;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3596
#include <stdio.h>


int main()
{
    int a,b;
    scanf("%d %d", &a,&b); 
    
    
    if(a==b){
        printf("a == b");
        
    }else if(a>b){
        printf("a > b");
    }else{
        printf("a < b");
    }
    printf("\n");
    return 0;
    
}




Measured memory_bytes: 2060
#include <iostream>
#include <cmath>
#include <vector>
#define rep(i,n) for(int i=0;i<(n);++i)

using namespace std;
typedef long long ll;

typedef vector<vector<int> > Graph;

bool flag;




void dfs(Graph& g,int x,vector<int>& vec,int& count,int& ans){
    
    vec[x]=1;
    
    ++count;
    //cout<<"first:"<<count<<endl;
    /*rep(i,vec.size())cout<<vec[i]<<" ";
    cout<<endl;*/
    if(count==vec.size())++ans;
    
    for(int i=0;i<g[x].size();++i){
        int y=g[x][i];
        if(vec[y]==1)continue;
        dfs(g,y,vec,count,ans);
    }
  
    --count;
    //cout<<"second:"<<count<<endl;
    vec[x]=0;
    /*rep(i,vec.size())cout<<vec[i]<<" ";
       cout<<endl;*/
    
}





int main(){
    
    int N,M;
    cin>>N>>M;
    
    Graph g;
    vector<int> vec;
    int count=0;
    int ans=0;
    g.resize(N);
    vec.assign(N,false);
    
    for(int i=0;i!=M;++i){
        int a,b;
        cin>>a>>b;
        --a;
        --b;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    
   /* rep(i,N)rep(j,g[i].size())cout<<g[i][j]<<" ";
    cout<<endl;
    */
    
    dfs(g,0,vec,count,ans);
    
    cout<<ans<<endl;
 

}

Measured memory_bytes: 3608
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;
using ll = long long int;
using int64 = long long int;
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const int INF = 1LL << 29;
const ll LONGINF = 1LL << 60;
const ll MOD = 1000000007LL;

int solve_testcase() {
    ll N; scanf("%lld", &N);
    if(N == 0) return 1;
    
    ll a0 = -1, a1 = -1;
    for(ll d=1; d<=N; d++) {
        if(d*(d+1)/2 > N) break;

        ll lb1 = 0, ub1 = N;
        while(ub1 - lb1 > 1) {
            ll m = (ub1 + lb1) >> 1;
            ll l = m-1, r = l+d;
            ll s = r*(r+1)/2 - l*(l+1)/2;
            if(s >= N) ub1 = m;
            else lb1 = m;
        }

        // fprintf(stderr, "d = %lld, ub1 = %lld\n", d, ub1);
        {
            ll l = ub1-1, r = l+d;
            ll s = r*(r+1)/2 - l*(l+1)/2;
            // fprintf(stderr, "s = %lld\n", s);
            if(s == N) {
                a0 = l + 1;
                a1 = d;
            }
        }
    }
    printf("%lld %lld\n", a0, a1);
    return 0;
}

int main() {
    while(!solve_testcase());
    return 0;
}



Measured memory_bytes: 3172
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();
// freopen("input.txt", "r", stdin);

int main() {
    string s;
    for(int i = 0; i < 3; i++) {
        cin >> s;
        cout << s[i];
    }
    cout << endl;
    return 0;
}



Measured memory_bytes: 256
K = int(input())
if K < 13:
    print(K)
    quit()

now = list(range(1, 10))

count = 9
while True:
    nxt = []
    for l in now:
        tail = l % 10
        for t in range(max(0, tail - 1), min(10, tail + 2)):
            nxt.append(l * 10 + t)
            count += 1
            if count == K:
                print(l * 10 + t)
                quit()
    now = nxt


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

struct Unionfind {
  // tree number
  vector<int> par;
  // tree rank
  vector<int> treerank;
  // constructor
  Unionfind(int n = 1) { stree(n + 1); }
  // make and initialization
  void stree(int n = 1) {
    par.assign(n, -1);
    treerank.assign(n, 0);
  }
  // search root
  int root(int x) {
    if(par[x] < 0) return x;
    return par[x] = root(par[x]);
  }
  // is same?
  bool issame(int x, int y) { return root(x) == root(y); }

  // add
  // already added, return 0
  bool uni(int x, int y) {
    x = root(x);
    y = root(y);
    if(x == y) return 0;
    if(treerank[x] > treerank[y]) swap(x, y);
    if(treerank[x] == treerank[y]) ++treerank[y];
    par[y] -= size(x);
    par[x] = y;
    return 1;
  }
  int size(int x) { return -par[root(x)]; }
};

struct bomb {
  int a;
  bool b;
  bomb(int _a = 0, bool _b = 0) : a(_a), b(_b) {}
  bool operator<(const bomb& r) const { return a < r.a; }
};

struct cod {
  int l, r;
};

int n, m;
vector<bomb> bombs;
vector<cod> v;
vector<bool> dif, used;
vector<int> res;
vector<vector<int>> edges;
Unionfind uf;

bool solve();
bool dfs(int now);

int main() {
  cin >> n >> m;
  bombs.resize(n);
  for(int i = 0; i < n; ++i)
    cin >> bombs[i].a >> bombs[i].b;
  bombs.push_back({-1, 0});
  sort(bombs.begin(), bombs.end());
  bombs.push_back({(int)1e9 + 1, 0});
  v.resize(m);
  for(int i = 0; i < m; ++i) {
    int l, r;
    cin >> l >> r;
    l = lower_bound(bombs.begin(), bombs.end(),
                    bomb(l, 0)) -
        bombs.begin();
    r = upper_bound(bombs.begin(), bombs.end(),
                    bomb(r, 1)) -
        bombs.begin();
    v[i] = {l - 1, r - 1};
  }
  for(int i = 0; i < bombs.size() - 1; ++i)
    dif.push_back(bombs[i].b ^ bombs[i + 1].b);
  if(solve()) {
    cout << res.size() << endl;
    for(int i = 0; i < res.size(); ++i) {
      if(i != 0) cout << " ";
      cout << res[i] + 1;
    }
    cout << endl;
  }
  else
    cout << -1 << endl;
  return 0;
}

bool solve() {
  n = dif.size();
  uf = Unionfind(n);
  edges.resize(n);
  for(int i = 0; i < m; ++i)
    if(!uf.issame(v[i].l, v[i].r)) {
      uf.uni(v[i].l, v[i].r);
      edges[v[i].l].push_back(i);
      edges[v[i].r].push_back(i);
    }
  used.assign(n, 0);
  for(int i = 0; i < n; ++i)
    used[uf.root(i)] = used[uf.root(i)] ^ dif[i];
  for(int i = 0; i < n; ++i)
    if(used[i]) return 0;
  for(int i = 0; i < n; ++i)
    if(!used[i]) {
      used[i] = 1;
      dfs(i);
    }
  sort(res.begin(), res.end());
  return 1;
}

bool dfs(int now) {
  for(auto e : edges[now]) {
    int nextp;
    if(v[e].l == now)
      nextp = v[e].r;
    else
      nextp = v[e].l;
    if(used[nextp]) continue;
    used[nextp] = 1;
    if(dfs(nextp)) {
      res.push_back(e);
      dif[now] = dif[now] ^ 1;
    }
  }
  return dif[now];
}

Measured memory_bytes: 9712
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define all(a) (a).begin(), (a).end()

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

using ll = long long;

ll N;
std::vector<ll> G[100010];
ll dp[100010];
bool used[100010];

ll dfs( ll v, ll p )
{
  used[v] = true;

  std::vector<ll> vs;

  for( auto u : G[v] ) if( u != p && !used[u] )
    vs.emplace_back( dfs( u, v ) );
  
  std::sort( vs.rbegin(), vs.rend() );

  rep( i, vs.size() )
    chmax( dp[v], vs[i]+i+1 );

  return dp[v];
}

int main()
{
  std::cin >> N;

  rep( i, N-1 )
  {
    ll a;
    std::cin >> a;
    --a;

    G[a].emplace_back( i+1 );
  }

  dfs( 0, -1 );

  std::cout << dp[0] << std::endl;

  return 0;
}

Measured memory_bytes: 17536
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define int long long
#define x first
#define y second
#define pb push_back
#define speed ios_base::sync_with_stdio(0);cin.tie(0);
using namespace std;
template<class L,class R> ostream& operator<<(ostream& cout,pair<L, R> P)
{return cout<<'('<<P.x<<','<< P.y<<')';}
template<class T> ostream& operator<<(ostream& cout,vector<T> V)
{cout<<"[ ";for(auto v:V)cout<<v<<' ';return cout<<']';}


signed main()
{
	speed
	int n;cin>>n;
	std::vector<int> inp(n);
	for (int i = 0; i < n; ++i)
	{
		cin>>inp[i];
	}
	int mini=INT_MAX,ans=0;
	for(auto it:inp)
	{
		if(it<mini)
		{
			mini=it;++ans;
		}
	}
	cout<<ans<<"\n";
}

Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
using namespace std;
const int maxN = 110;
char f[110][110];
int h,w;
int main()
{
	scanf("%d%d",&h,&w);
	for(int i=1;i<=h;i++)
		scanf("%s",f[i]);
	for(int i=0;i<=1+w;i++)
		printf("#");
	printf("\n");
	for(int i=1;i<=h;i++)
	{
		printf("#");
		printf("%s",f[i]);
		printf("#\n");
	}
	for(int i=0;i<=1+w;i++)
		printf("#");
	printf("\n");
	return 0;
} 


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


using namespace std;

int main(){
    vector<long long>a(10000000);
    long long n ,min ,max, sum;
    max = -10000000000;
    min = 100000000000;
    sum = 0;
    cin >> n;
    for (int i=0;i < n;i++){
        cin >> a[i];
        if (max < a[i]){
            max = a[i];
        }
        if (min > a[i]){
            min = a[i];
        }
        sum += a[i];
    }

    cout << min << " " << max << " " << sum << endl;
    return 0;
}


Measured memory_bytes: 80788
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
using namespace std;
typedef long long int llint;
typedef double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
//cout<<setprecision(20)
const llint mod=1000000007;
const llint big=2.19e15+1;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-15;
template <class T,class U>void mineq(T& a,U b){if(a>b){a=b;}}
template <class T,class U>void maxeq(T& a,U b){if(a<b){a=b;}}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){return a/gcd(a,b)*b;}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
int LBI(vector<lldo>&ar,lldo in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();}
int UBI(vector<lldo>&ar,lldo in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();}
int main(void){
	int a,b,c;cin>>a>>b>>c;
	int sai=max(a,max(b,c));
	int ans=sai*3-(a+b+c);
	if(ans%2){ans+=3;}
	ans/=2;
	cout<<ans<<endl;
	return 0;
}

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

int main(){
    int a,b;
    char op;
    
    while(op!='?'){
        cin >>a>>op>>b;
        if(op=='+'){
        cout <<a+b<<endl;
    }else if(op=='-'){
        cout <<a-b<<endl;
    }else if(op=='*'){
        cout<<a*b<<endl;
    }else if(op=='/'){
        cout <<a/b<<endl;
    }
    }
    return 0;
}


Measured memory_bytes: 3120