akhauriyash/Code-Regression huggingface dataset:
from sys import stdin

def nC2(n):
    return n*(n-1)//2

def main():
    #入力
    readline=stdin.readline
    s=readline().strip()

    d=dict()
    p=1
    t=0
    for i in range(len(s)-1,-1,-1):
        n=int(s[i])
        m=(n*p+t)%2019
        t=m
        p*=10
        p%=2019
        if m not in d:
            d[m]=1
        else:
            d[m]+=1
        
    if 0 in d:
        ans=d[0]
    else:
        ans=0
    for v in d.values():
        ans+=nC2(v)
    print(ans)
    
if __name__=="__main__":
    main()

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

constexpr int MAX_N = 15;
int matrix[MAX_N][MAX_N];

int main() {
  fill_n(&matrix[0][0], MAX_N * MAX_N, -1);
  int N;
  cin >> N;
  for (int i{}; i < N; ++i) {
    int A;
    cin >> A;
    for (int j{}; j < A; ++j) {
      int x, y;
      cin >> x >> y;
      --x;
      matrix[i][x] = y;
    }
  }

  int ans{};
  for (int i{1}; i < (1 << N); ++i) {
    int num{};
    bool lier{};
    for (int j{}; j < N; ++j) {
      if (i & (1 << j)) {
        for (int k{}; k < N; ++k) {
          if (matrix[j][k] == -1) continue;
          if ((matrix[j][k] && !(i & (1 << k))) ||
              (!matrix[j][k] && (i & (1 << k)))) {
            lier = true;
            break;
          }
        }
        if (lier) break;
        ++num;
      }
    }
    if (!lier)
      ans = max(ans, num);
  }

  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3568
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace aizu1
{
    public class Solution
    {
        public static void Main(string[] args)
        {
            int q = int.Parse(Console.ReadLine());
            char[] X = new char[1000];
            char[] Y = new char[1000];
            int[,] M ;

            while (q--!=0)
            {
                M = new int[1001, 1001];
                X = Console.ReadLine().ToCharArray();
                Y = Console.ReadLine().ToCharArray();

                Console.WriteLine(LCS(X, Y,M, X.Length, Y.Length));
            }
        }

        public static int LCS(char[] X, char[] Y,int[,]M, int length1, int length2)
        {
            if (length1 == 0 || length2 == 0) return 0;

            if (M[length1, length2] != 0) return M[length1, length2];
            else
            {
                int res1 = LCS(X, Y, M, length1, length2 - 1);
                int res2 = 0;
                for (int i = length1 - 1; i >= 0; i--)
                {
                    if (X[i] == Y[length2 - 1])
                    {
                        res2 = LCS(X, Y, M, i, length2 - 1) + 1;
                        break;
                    }
                }

                var res = (res1 > res2) ? res1 : res2;
                M[length1, length2] = res;
                return res;
            }
        }
    }
}

Measured memory_bytes: 18312
n = int(input())
S = input()
p = 10**9+7
DP = [[0 for j in range(n+1)] for i in range(n+1)]
for j in range(n):
    DP[1][j] = 1
for i in range(2, n+1):
    A = [0]
    for j in range(n):
        A.append(A[-1]+DP[i-1][j])
    for j in range(n-i+1):
        if S[i-2] == '<':
            DP[i][j] = (A[n-(i-1)+1]-A[j+1]) % p
        else:
            DP[i][j] = A[j+1] % p
print(DP[n][0])


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

long long a[100000];

int main()
{
	long long i,k,l,r;
	cin >> k;
	for(i=0;i<k;i++)
		cin >> a[i];
	if(a[k-1]!=2)
	{
		puts("-1");
		return 0;
	}
	for(i=k-2,l=2,r=3;i>=0;i--)
	{
		if(a[i]>r)
		{
			puts("-1");
			return 0;
		}
		r-=r%a[i];
		if(a[i]>=l) l=a[i];
		else if(l%a[i]) l+=a[i]-l%a[i];
		r+=a[i]-1;
		if(l>r)
		{
			puts("-1");
			return 0;
		}
	}
	cout << l << " " << r << "\n";
}

Measured memory_bytes: 1024
#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 a, b, c, d;
    cin >> a >> b >> c >> d;
    while (1) {
        c-=b;
        if (c <= 0) {
            cout << "Yes" << endl;
            return 0;
        }
        a-=d;
        if (a <= 0) {
            cout << "No" << endl;
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 3588
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MAXN = 100005;
struct ii {
	ll a, b;
	bool operator < (ii o) const {
		return tie(a, b) < tie(o.a, o.b);
	}
};

ll N;
ii arr[MAXN];
vector<ll> urutan[MAXN];
vector<ii> urut;

int main() {
	ios::sync_with_stdio(0); cin.tie(0);
	
	cin >> N;
	ll kiri = 0, kanan = 0;
	for (ll i = 0; i < N; i++) {
		cin >> arr[i].a >> arr[i].b;
		kiri += arr[i].a;
		kanan += arr[i].b;
		urut.push_back({arr[i].a, i});
		urut.push_back({arr[i].b, i});
	}
	sort(urut.begin(), urut.end());
	
	for (ll i = 0; i < (ll)urut.size(); i++) {
		urutan[urut[i].b].push_back(i);
	}
	
	ll ans = min(kiri, kanan);
	ll base = 0;
	for (int i = 0; i < N-2; i++) base += urut[i].a;
	for (int i = 0; i < N; i++) {
		if (urutan[i].back() < N-2) {
			ans = min(ans, base+urut[N-2].a+urut[N-1].a);
		} else if (urutan[i][0] < N-2) {
			if (urut[N-2].b == i) ans = min(ans, base + max(arr[i].a, arr[i].b) + urut[N-1].a);
			else ans = min(ans, base + max(arr[i].a, arr[i].b) + urut[N-2].a);
		} else {
			ans = min(ans, base+arr[i].a+arr[i].b);
		}
	}
	cout << ans << "\n";
	
	return 0;
 }


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

//const double PI = acos(-1);
using ll = long long;
using ull = unsigned long long;
const int inf = 2e9;
const ll INF = 2e18;
const ll MOD = 1e9+7;

#define REP(i,n) for (int i = 0; i < (n); i++)
#define sz(s) (s).size()
#define pb push_back
#define fi first
#define se second

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

  int n, m;
  cin >> n >> m;
  pair<ll,int> a[n];
  REP(i,n) {
    cin >> a[i].fi >> a[i].se;
  }
  sort(a,a+n);
  ll ans = 0;
  REP(i,n) {
    ans += min(a[i].se,m) * a[i].fi;
    m -= min(a[i].se, m);
    if (m <= 0) break;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0; i<n; i++)
typedef long long ll;
typedef long long unsigned int llu;
ll MOD = 1000000007;
ll INF = 1000000009;

char maze[25][25];

void solve(){
    int h,w;
    cin >> h >> w;
    rep(i,w+2){
        maze[0][i]='#';
    }
    rep(i,w+2){
        maze[h+1][i]='#';
    }
    rep(i,h+2){
        maze[i][0]='#';
    }
    rep(i,h+2){
        maze[i][w+1]='#';
    }

    rep(i,h){
        rep(j,w){
            cin >> maze[i+1][j+1];
        }
    }

    rep(i,h+2){
        rep(j,w+2){
            //cout << maze[i][j];
        }
        //cout << endl;
    }

    int score=0;
    rep(i,h+2){
        rep(j,w+2){
            
            if(maze[i][j]=='.'){

                queue<pair<int,int>> q;
                int dis[22][22];
                rep(p,22){
                    rep(q,22){
                        dis[p][q]=-1;
                    }
                }
                bool visit[22][22];
                rep(p,22){
                    rep(q,22){
                        visit[p][q]=false;
                    }
                }
                visit[i][j]=true;
                q.push(make_pair(i,j));
                while(!q.empty()){
                    auto p = q.front();
                    q.pop();
                    auto x = p.first;
                    auto y = p.second;
                    if(maze[x+1][y]=='.' && visit[x+1][y]==false){
                        dis[x+1][y]=dis[x][y]+1;
                        q.push(make_pair(x+1,y));
                        visit[x+1][y]=true;
                    }
                    if(maze[x-1][y]=='.' && visit[x-1][y]==false){
                        dis[x-1][y]=dis[x][y]+1;
                        q.push(make_pair(x-1,y));
                        visit[x-1][y]=true;
                    }
                    if(maze[x][y+1]=='.' && visit[x][y+1]==false){
                        dis[x][y+1]=dis[x][y]+1;
                        q.push(make_pair(x,y+1));
                        visit[x][y+1]=true;
                    }
                    if(maze[x][y-1]=='.' && visit[x][y-1]==false){
                        dis[x][y-1]=dis[x][y]+1;
                        q.push(make_pair(x,y-1));
                        visit[x][y-1]=true;
                    }
                }
                rep(i,h+2){
                    rep(j,w+2){
                        score=max(score,dis[i][j]);
                    }
                }

            }
        }
    }

    cout << score+1 << endl;
    
}

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


Measured memory_bytes: 256
//  ____            _                  _                       _       _
// |  _ \ _   _ ___| |_    ___ _ __   | |_ ___ _ __ ___  _ __ | | __ _| |_ ___
// | |_) | | | / __| __|  / __| '_ \  | __/ _ \ '_ ` _ \| '_ \| |/ _` | __/ _ \
// |  _ <| |_| \__ \ |_  | (__| |_) | | ||  __/ | | | | | |_) | | (_| | ||  __/
// |_| \_\\__,_|___/\__|  \___| .__/___\__\___|_| |_| |_| .__/|_|\__,_|\__\___|
//                            |_| |_____|               |_|

//https://github.com/manta1130/Competitive_Programming_Template_Rust

#[macro_use]
mod input {

    use std;
    use std::io;

    const SPLIT_DELIMITER: char = ' ';

    #[macro_export]
    #[allow(unused_macros)]
    macro_rules! input {
    ( $($x:expr ),*) => {
        {
            let temp_str = input_line_str();
            let mut split_result_iter = temp_str.split_whitespace();
                $(
                let buf_split_result = split_result_iter.next();
                let buf_split_result = buf_split_result.unwrap();
                    ($x) = buf_split_result.parse().unwrap();
                )*
        }
    };
}

    #[allow(dead_code)]
    pub fn input_line_str() -> String {
        let mut s = String::new();
        io::stdin().read_line(&mut s).unwrap();
        s.trim().to_string()
    }

    #[allow(dead_code)]
    pub fn p<T>(t: T)
    where
        T: std::fmt::Display,
    {
        println!("{}", t);
    }

    #[allow(dead_code)]
    pub fn input_vector2d<T>(line: usize) -> Vec<Vec<T>>
    where
        T: std::str::FromStr,
    {
        let mut v: Vec<Vec<T>> = Vec::new();

        for _ in 0..line {
            let vec_line = input_vector();
            v.push(vec_line);
        }
        v
    }

    #[allow(dead_code)]
    pub fn input_vector<T>() -> Vec<T>
    where
        T: std::str::FromStr,
    {
        let mut v: Vec<T> = Vec::new();

        let s = input_line_str();
        let split_result = s.split(SPLIT_DELIMITER);
        for z in split_result {
            let buf = match z.parse() {
                Ok(r) => r,
                Err(_) => panic!("Parse Error"),
            };
            v.push(buf);
        }
        v
    }

    #[allow(dead_code)]
    pub fn input_vector_row<T>(n: usize) -> Vec<T>
    where
        T: std::str::FromStr,
    {
        let mut v = Vec::with_capacity(n);
        for _ in 0..n {
            let buf = match input_line_str().parse() {
                Ok(r) => r,
                Err(_) => panic!("Parse Error"),
            };
            v.push(buf);
        }
        v
    }

    pub trait ToCharVec {
        fn to_charvec(&self) -> Vec<char>;
    }

    impl ToCharVec for String {
        fn to_charvec(&self) -> Vec<char> {
            self.to_string().chars().collect::<Vec<_>>()
        }
    }
}

use input::*;

fn main() {
    let s = input_line_str().to_charvec();
    if s.len() % 2 == 1 {
        println!("No");
        return;
    }
    let mut flag = true;
    for i in 0..s.len() / 2 {
        if s[i * 2] != 'h' || s[i * 2 + 1] != 'i' {
            println!("No");
            return;
        }
    }
    println!("Yes");
}


Measured memory_bytes: 4352
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

bool[1000001] MEMO;

void main()
{
    auto s = readln.chomp.to!int;

    int i;
    for (;;) {
        ++i;
        if (MEMO[s]) {
            writeln(i);
            return;
        }
        MEMO[s] = true;
        s = s % 2 == 0 ? s / 2 : s * 3 + 1;
    }
}

Measured memory_bytes: 1280
N = int(input())
A = list(map(int, input().split()))
P = 1000000007
dp = [0] *(N + 1)
dp[0] = 1
color = [0, 0, 0]
for i in range(N):
    count = 0
    check= True
    for j in range(3):
        if color[j] == A[i]:
            count += 1
            if check:
                color[j] += 1
                check = False
    dp[i + 1] += (dp[i] * count)%P
print(dp[-1])

Measured memory_bytes: 13964
N, M = map(int, input().split())
Z = [None for _ in range(N)]
for i in range(M):
  s, c = map(int, input().split())
  if Z[s-1] == None or Z[s-1] == c:
    Z[s-1] = c
  else:
    print(-1)
    break
else:
  if N == 1 and (M == 0 or Z[0] == 0):
    print(0)
  elif Z[0] == 0:
    print(-1)
  elif Z[0] == None:
    Z[0] = 1
    for l in range(N):
      if Z[l] == None:
        Z[l] = 0
    print("".join(map(str, Z)))
  else:
    for p in range(N):
      if Z[p] == None:
        Z[p] = 0
    print("".join(map(str, Z)))


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

using namespace std;

typedef long long ll;


void solve(ll test_num) {
  (void) test_num;
  ll N;
  cin >> N;
  ll hig = 1;
  while (hig * (hig + 1) / 2 < N) {
    ++hig;
  }
  vector<ll> res;
  ll rem = N;
  for (ll x = hig; x > 0; --x) {
    if (x <= rem) {
      rem -= x;
      res.push_back(x);
    }
  }
  for (ll x : res)cout << x << ' ';
  cout << endl;
}

void init() {

}

int main() {
#ifdef AZN
  freopen("/home/azneye/Documents/Stuff/input.txt", "r", stdin);
#endif
  init();
  ll tests = 1;
  //cin >> tests;
  for (ll test = 1; test <= tests; ++test) {
    solve(test);
  }
  return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
#define Mod 1000000007
using namespace std;
int n,K;
long long dp[55][2505][55];
int main() {
	scanf("%d%d",&n,&K);
	dp[0][0][0]=1;
	for(int i=0; i<=n; i++)
		for(int j=0; j<=K; j++)
			for(int k=0; k<=n; k++) {
				if(j+2*k>K)continue;
//				printf("%d %d %d %lld\n",i,j,k,dp[i][j][k]);
				dp[i+1][j+2*k][k]=(dp[i+1][j+2*k][k]+dp[i][j][k])%Mod;
				dp[i+1][j+2*k][k+1]=(dp[i+1][j+2*k][k+1]+dp[i][j][k])%Mod;
				if(k){
					dp[i+1][j+2*k][k-1]=(dp[i+1][j+2*k][k-1]+k*k*dp[i][j][k]%Mod)%Mod;
					dp[i+1][j+2*k][k]=(dp[i+1][j+2*k][k]+2*k*dp[i][j][k])%Mod;
//					printf("%lld\n",dp[i+1][j+2*k][k-1]);
				} 
			}
	printf("%lld\n",dp[n][K][0]);
	return 0;
}

Measured memory_bytes: 56576
N,H = [int(i) for i in input().split()]
a = [0]*N
b = [0]*N
hp = 0
ans = 0
for i in range(N):
    a[i],b[i] = [int(j) for j in input().split()]
a.sort()
b.sort()
b.reverse()
judge = a[-1]
for i in range(N):
    if b[i] >= judge:
        hp += b[i]
        ans +=1
        if hp >= H:
            print(ans)
            exit()
        continue
    break
if (H-hp)%judge == 0:
    d = (H-hp)//judge
else:
    d = (H-hp)//judge +1
print(ans+d)

Measured memory_bytes: 11312
import java.util.Scanner;
import java.util.function.LongUnaryOperator;

final class Solver {
	static final Solver INSTANCE = new Solver();

	void solve(Scanner sc) {
		long A = sc.nextLong();
		long B = sc.nextLong();
		int C = sc.nextInt();
		int D = sc.nextInt();
		long lcm = (long) C * D / gcd(C, D);
		LongUnaryOperator f = x -> (x / C) + (x / D) - (x / lcm);
		long b = f.applyAsLong(B);
		long a = f.applyAsLong(A - 1);
		System.out.println((B - (A - 1)) - (b - a));
	}

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

class Main {
	public static void main(String... args) {
		Scanner in = new Scanner(System.in);

		Solver.INSTANCE.solve(in);

		in.close();
	}
}

Measured memory_bytes: 26964
N = int(input())

mod = 10**9 + 7

total = pow(10, N, mod)
not_0 = pow(9, N, mod)
not_9 = not_0
not_9_and_0 = pow(8, N, mod)

ans = ( total - (not_0 + not_9 - not_9_and_0) ) % mod

print(ans)


Measured memory_bytes: 9160
import Control.Monad

main ::IO ()
main = do
  n <- readLn
  if n == 0
    then return ()
    else do
      ls <- replicateM n getLine
      let ls' = map (map (read :: String -> Int)) (map words ls)
          bmiL = map bmiTuple ls'
          ans = format (foldl1 choice bmiL)
      putStrLn ans
      main

bmiTuple :: [Int] -> (Int,Double)
bmiTuple [p,h,w] = (p,bmi)
  where h' = fromIntegral h
        w' = fromIntegral w
        bmi = (w' * 10000.0) / (h'*h')

choice :: (Int,Double) -> (Int,Double) -> (Int,Double)
choice (p1,v1) (p2,v2)
  | (abs (v1 - 22)) < (abs (v2 - 22)) = (p1,v1)
  | (abs (v1 - 22)) > (abs (v2 - 22)) = (p2,v2)
  | p1 < p2 = (p1,v1)
  | otherwise = (p2,v2)

format :: (Int,Double) -> String
format (p,v) = show p

Measured memory_bytes: 5512
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define FOR(i,start,end) for(int i=start;i<=end;i++)
const int INF = 1001001001;
using namespace std;
typedef long long ll;

int main()
{
  int N;
  int a[110000];
  int res=0;
  cin >> N;

  FOR(i,1,9) {
    int num= N/i;
    if(N%i==0 && 1<=num && num <=9){
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
}


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

int main() {
    int N; cin >> N;
    vector<int> L(N+5);
    for(int i=0;i<N;i++){
        cin >> L[i];
    }
    sort(L.begin(),L.begin()+N);
    int sum=0;
    for(int i=0;i<N-1;i++){
        sum+=L[i];
    }
    cout << (sum>L[N-1]?"Yes":"No") << endl;
}

Measured memory_bytes: 764
from collections import defaultdict

s=input()
K=int(input())

d=defaultdict(list)
for i, si in enumerate(s):
    d[si].append(i)

sub=set()
for code in range(ord('a'),ord('z')+1):
    for right in d[chr(code)]:
        for sl in range(min(K,len(s[right:]))):
            sub.add(s[right:right+sl+1])
    if len(sub)>=K:
        sub=sorted(list(sub))
        print(sub[K-1])
        break


Measured memory_bytes: 3700
program main
	implicit none
	character(100010) :: S
	integer :: i, counter_F0, counter_E1, counter_F1, counter_E0
	read(*, *) S
	counter_F0 = 0
	counter_F1 = 0
	counter_E0 = 0
	counter_E1 = 0
	do i = 1, len_trim(S), 2
		if(S(i:i) == "1") then
			counter_F0 = counter_F0 + 1
		end if
	end do
	do i = 2, len_trim(S), 2
		if(S(i:i) == "0") then
			counter_E1 = counter_E1 + 1
		end if
	end do
	counter_F0 = counter_F0 + counter_E1
	
	do i = 1, len_trim(S), 2
		if(S(i:i) == "0") then
			counter_F1 = counter_F1 + 1
		end if
	end do
	do i = 2, len_trim(S), 2
		if(S(i:i) == "1") then
			counter_E0 = counter_E0 + 1
		end if
	end do
	counter_F1 = counter_F1 + counter_E0
	
	write(*, *) min(counter_F0, counter_F1)
end program main

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

int main(){
  int A,B,C,K;
  cin >> A >> B >> C >> K;
  //int sum = 0;
  if(A+B > K)
    cout << K << endl;
  else{
    int sum = K - A - B;
    cout << A - sum << endl;
  }
}

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

int main() {
    int a, b; 
    cin >> a >> b;

    // if (a == b) cout << "Yay!";
    // else {
    //     if (a > b) {
    //         if (b >= a / 2) cout << "Yay!";
    //         else cout << ":(";
    //     }
    //     else {
    //         if (a >= b / 2) cout << "Yay!";
    //         else cout << ":(";
    //     }
    // }


    int m = max(a, b);
    m > 8 ? cout << ":(" : cout <<"Yay!";
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;
struct Pr{
	ll x,y;
}l_r[210000],r_l[210000];

struct Te{
	int ls,rs,lv,rv;
}t[210000];

int n;
ll mid;
vector<Pr>V[210000];

void insert(int x,Pr y){
	//x sorted
	//compare y is ok
	int i=V[x].size()-1;
	if(V[x].empty()){V[x].push_back(y);return;}
	if(V[x][i].y<=y.y)return;
	while(!V[x].empty()&&V[x][i].x>=y.x)V[x].pop_back();
	V[x].push_back(y);
}

int dfs(int u){
	V[u].clear();
	int i,j,ltor=0,rtol=0,dt=t[u].lv+t[u].rv;
	int ls=t[u].ls,rs=t[u].rs,lv=t[u].lv,rv=t[u].rv;
	if(t[u].ls==0){
		insert(u,(Pr){0,0});
		return 1;
	}int jud=dfs(t[u].ls)|dfs(t[u].rs);
	if(jud==0)return 0;
	//stay x/ y\
	//using combine
	for(i=V[ls].size()-1,j=V[rs].size()-1;i>=0;i--){while(j>=0&&V[ls][i].y+V[rs][j].x+dt>mid)j--;if(j>=0)l_r[++ltor]=(Pr){V[ls][i].x+lv,V[rs][j].y+rv};}
	for(i=V[ls].size()-1,j=V[rs].size()-1;j>=0;j--){while(i>=0&&V[ls][i].x+V[rs][j].y+dt>mid)i--;if(i>=0)r_l[++rtol]=(Pr){V[rs][j].x+rv,V[ls][i].y+lv};}
	reverse(l_r+1,l_r+ltor+1);
	reverse(r_l+1,r_l+rtol+1);
	i=1;j=1;
	while(i<=ltor&&j<=rtol){
		if(l_r[i].x<r_l[j].x){insert(u,l_r[i]);i++;}
		else {insert(u,r_l[j]);j++;}
	}while(i<=ltor){insert(u,l_r[i]);i++;}
	while(j<=rtol){insert(u,r_l[j]);j++;}
	return !V[u].empty();
}

int main(){
	int x,y;
	scanf("%d",&n);
	ll L=-1,R=17179869184ll;
	for(int i=2;i<=n;i++){
		scanf("%d %d",&x,&y);
		if(t[x].ls==0)t[x].ls=i,t[x].lv=y;
		else t[x].rs=i,t[x].rv=y;
	}while(L+1<R){
		mid=(L+R)>>1;
		if(dfs(1)){
			R=mid;
		}else L=mid;
	}printf("%lld\n",R);
	return 0;
}

Measured memory_bytes: 35368
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
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; }
const int INF=1001001001;
const int mod=1e9+7;

struct Unionfind{
  vector<int>d;
  Unionfind(int n):d(n,-1){}
  int root(int x){
    if(d[x]<0){return x;}
    return d[x]=root(d[x]);
  }
  bool unite(int x,int y){
    x=root(x);y=root(y);
    if(x==y){return false;}
    if(d[x]>d[y]){swap(x,y);}
    d[x]+=d[y];
    d[y]=x;
    return true;
  }
  bool same(int x,int y){return root(x)==root(y);}
  int size(int x){return -d[root(x)];}
};

int main(){
  int N,M,K;
  cin>>N>>M>>K;
  Unionfind uf(N);
 
  vector<int>fre(N);
  for(int i=0;i<M;i++){
    int a,b;
    cin>>a>>b;
    a--;b--;
    fre[a]++;
    fre[b]++;
    uf.unite(a,b);
  }
  vector<vector<int>>block(N);
  for(int i=0;i<K;i++){
    int c,d;
    cin>>c>>d;
    c--;d--;
    block[c].push_back(d);
    block[d].push_back(c);
  }
  for(int i=0;i<N;i++){
    int sum=uf.size(i)-1-fre[i];
    for(int c:block[i]){
      if(uf.same(i,c)){sum--;}
    }
    cout<<sum<<endl;
  }
  return 0;                       
}

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

typedef long long ll;
typedef long double ld;
//#define int ll
//#define endl '\n'

// use unique(x) - removec consecutive items, returns vec.begin() + number of items
// for vector: sort(all(vec)); vec.erase(unique(all(vec)), vec.end());
// use iota(all(vec), 0) for filling a vector with 0,1,2...
// use fill(all(vec), 1) for filling a vector with 1,1,1...
// use rotate(vec.begin(), vec.begin() + 1, vec.end()) to rotate a vector | middle arg becomes first
// print number in binary -> cout << bitset<20>(n);

const int N=200010,K=11,mod=998244353;
int n,k;
ll dp[N],cum[N];
int l[K],r[K];
main(){
	cin.tie(0);cin.sync_with_stdio(0);
	cin>>n>>k;
	for(int i=0;i<k;++i)cin>>l[i]>>r[i];
	dp[0]=1;
	for(int i=0;i<n;++i,cum[i]=(cum[i-1]+dp[i-1])%mod)
		for(int j=0;j<k;++j)
			if(max(0,i-r[j])<=i-l[j])
				dp[i]=(dp[i]+cum[i-l[j]+1]-cum[max(0,i-r[j])]+mod)%mod;
	cout<<dp[n-1]<<endl;
}


Measured memory_bytes: 6696
N, M, X, Y = gets.split.map(&:to_i)

xx = gets.split.map(&:to_i).max()
yy = gets.split.map(&:to_i).min()

xx = [X, xx].max()
yy = [Y, yy].min()

war = (yy - xx) >= 1

puts war ? 'No War' : 'War'


Measured memory_bytes: 1788
#include "bits/stdc++.h"
#include <cmath>
#include <iomanip>
using namespace std;
 
#define f first
#define s second
 
#define pb push_back
#define pp pop_back
#define mp make_pair
 
#define sz(x) (int)x.size()
#define sqr(x) ((x) * 1ll * (x))
#define all(x) x.begin(), x.end()
#define clr(a,v) memset(a, v, sizeof(a))
 
#define rep(i, l, r) for (int i = (l); i <= (r); i++)
#define per(i, l, r) for (int i = (l); i >= (r); i--)
#define reflex ios_base::sync_with_stdio(false)
 
#define nl '\n'
#define ioi exit(0);
 

#define PI 3.14159265

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
 
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int N= (int)2e5 + 7;
const int inf = (int)1e9 + 7;
//const int mod = (int)1e9 + 7;
//const int mod = 1000000007;
const ll linf = (ll)1e18 + 7;
 
const int dx[] = {-1, 0, 1, 0, 1, -1, -1, 1};
const int dy[] = {0, 1, 0, -1, 1, -1, 1, -1};
const int kx[] = {-1,1,2,2,1,-1,-2,-2};
const int ky[] = {2,2,1,-1,-2,-2,-1,1};

const int mod = 998244353;

struct dsu{
	int parent[N];
	int cont;
	void make_set(int n){
		for(int i = 1; i <= n; i++)
			parent[i] = i;
		cont = n;
	}
	
	int find_set(int v){
		if(v == parent[v])
			return v;
		return find_set(parent[v]);
	}
	
	void union_sets(int a, int b){
		a = find_set(a);
		b = find_set(b);
		if(a != b){
			parent[b] = a;
			cont--;
		}
	}
};

int m[13] ={0,100,101,102,103,104,105 };
bool dp[100007];
int main(){
	int x; cin>> x;
	clr(dp,0);
	dp[0] = true;
	for(int i = 1; i <= x; i++){
		bool f = false;
		for(int k = 1; k<= 6; k++){
			if(i - m[k] >=0 ){
				f |= dp[i-m[k]];
			}
		}
		dp[i] = f;
	}
	cout<<dp[x];
	return 0;
}


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

c =[abs(a[i]-b[i]) for i in range(n)]

for p in range(1,4):
    total=0
    for d in c:
        total+=d**p
    ans=total**(1/p)
    print(ans)

print(max(c))



Measured memory_bytes: 5648
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

ll dp[301][301][301];

int main(void){
	int n,m,i,j,k;
	cin >> n >> m;
	dp[0][n-1][1] = 1ll;
	for(i=0; i<m; ++i){
		for(j=0; j<n; ++j){
			for(k=0; k<n; ++k){
				if(j+k+1>n){
					continue;
				}
				add_mod(dp[i+1][j][k+1],dp[i][j+1][k+1]*(j+1)%MOD);
				add_mod(dp[i+1][j][k+1],dp[i][j][k+1]*(n-j-k-1)%MOD);
				add_mod(dp[i+1][j][n-j],dp[i][j][k+1]*(k+1)%MOD);
			}
		}
	}
	cout << dp[m][0][n] << endl;
	return 0;
}


Measured memory_bytes: 212608
#include <bits/stdc++.h>
    #define ll long long
    using namespace std;
    const int Mod = 1e9+7;
    ll AA(ll x){
        ll ans = 1, i = 1;
        while(i <= x){
            ans = (ans*i)%Mod;
            i++;
        }
        return ans%Mod;
    }
    int main(){
     
        ll n,m;
        //cout << AA(100000) << endl;
        cin >> n >> m;
        if(abs(n-m) > 1){
            cout << 0 << endl;
            return 0;
        }
        if(abs(n-m) == 1){
            cout << (AA(n)*AA(m))%Mod << endl;
        }else {
            cout << ((AA(n)*2%Mod)*AA(m))%Mod << endl;
        }
        return 0;
    }

Measured memory_bytes: 256
//

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const ll MOD = 1e9 + 7;

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

	int ans = (N+1) / 2;

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
const ld eps = 1e-9;


template<typename T>
vector<vector<T>> keisann(const vector<vector<T>>l, const vector<vector<T>>r) {
	vector<vector<T>>ans(l.size(), vector<T>(r[0].size()));
	assert(l[0].size() == r.size());
	for (unsigned int h = 0; h < l.size(); ++h) {
		for (unsigned int i = 0; i < r.size(); ++i) {
			for (unsigned int w = 0; w < r[0].size(); ++w) {

				ans[h][w] |= l[h][i] * r[i][w];
			}
		}
	}
	return ans;
}

template<typename T>
vector<vector<T>>powgyou(vector<vector<T>>a, const long long int n) {
	assert(a.size() == a[0].size());
	if (!n) {
		vector<vector<T>>e(a.size(), vector<T>(a[0].size()));
		for (unsigned int i = 0; i < a.size(); ++i) {
			e[i][i] = 1;
		}
		return e;
	}
	if (n == 1)return a;
	else {
		vector<vector<T>>ans(a.size(), vector<T>(a[0].size(), 0));
		ans = powgyou(a, n / 2);
		ans = keisann(ans, ans);
		if (n % 2) {
			ans = keisann(ans, a);
		}
		return ans;
	}
}


int main() {
	while (1) {
		int N, M, Z; cin >> N >> M >> Z;
		if (!N)break;
		vector<pair<int, int>>edges;
		edges.push_back(make_pair(-1, 0));
		for (int i = 0; i < M; ++i) {
			int s, d; cin >> s >> d; s--; d--;
			edges.push_back(make_pair(s, d));
			edges.push_back(make_pair(d, s));
		}
		vector<vector<int>>field(edges.size(), vector<int>(edges.size()));
		for (int i = 0; i < edges.size(); ++i) {
			for (int j = 0; j <edges.size(); ++j) {
				auto a = edges[i];
				auto b = edges[j];
				if (a.second == b.first&&a.first != b.second) {
					field[j][i] = true;
				}
			}
		}
		vector<vector<int>>start(edges.size(), vector<int>(1));
		start[0][0] = true;
		vector<vector<int>>kake = powgyou<int>(field, Z);
		vector<vector<int>>ans = keisann<int>(kake, start);
		bool ok = false;
		for (int i = 0; i <edges.size(); ++i) {
			if (edges[i].second == N - 1 && ans[i][0])ok = true;
		}
		if (ok)cout << "yes" << endl;
		else cout << "no" << endl;
	}
	return 0;
}

Measured memory_bytes: 5636
// Problem : A - Don't be late
// Contest : AtCoder - AtCoder Beginner Contest 177
// URL : https://atcoder.jp/contests/abc177/tasks/abc177_a
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define sort(a) sort(all(a))
#define ff first
#define ss second
#define vi vector<int>
#define pii pair<int, int>
#define vll vector<ll>
#define pll pair<ll,ll>
#define mod (int)1e9+7
#define FAST std::ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define repf(i,a,b) for(i=a;i<b;i++)
#define repb(i,a,b) for(i=a;i>=b;i--)
#define N 100005
int main()
{
	FAST
    int t=1;
    // cin>>t;
    while(t--)
    {
		int d,t,s;
		cin>>d>>t>>s;
		if(s*t < d) cout<<"No";else cout<<"Yes";
    }
    return 0;
} 


Measured memory_bytes: 3612
N = int(input())

memo = list(range(N+1))

temp = [0]*(N+1)
temp[0] = 1
temp[1] = 1

for x,c in enumerate(memo):
    if temp[x] == 0:
        for y in range(x,N+1,x):
            memo[y] *= temp[y]+1
            temp[y] = 1
        k = 2
        while x**k <= N:
            for y in range(x**k,N+1,x**k):
                temp[y] += 1
            k += 1
    memo[x] *= temp[x]+1

print(sum(memo)-1)

Measured memory_bytes: 224744
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cassert>
#include <cctype>
using namespace std;
typedef long long lint;
#define cout cerr
#define ni (next_num<int>())
template<class T>inline T next_num(){
	T i=0;char c;
	while(!isdigit(c=getchar())&&c!='-');
	bool flag=c=='-';
	flag?(c=getchar()):0;
	while(i=i*10-'0'+c,isdigit(c=getchar()));
	return flag?-i:i;
}
const int N=3010,O=1000000007;
inline int fpow(int x,int n){
	int a=1;
	for(;n;n>>=1,x=(lint)x*x%O){
		if(n&1){
			a=(lint)a*x%O;
		}
	}
	return a;
}
inline int inv(int x){
	return fpow(x,O-2);
}
int f[N][N];
int lpos[N],rpos[N],sum[N];
char s[N];
int fac[N],invfac[N];
inline void gmath(int n){
	fac[0]=1;
	for(int i=1;i<=n;i++){
		fac[i]=(lint)fac[i-1]*i%O;
	}
	invfac[n]=inv(fac[n]);
	for(int i=n;i>=1;i--){
		invfac[i-1]=(lint)invfac[i]*i%O;
	}
}
inline int C(int n,int k){
	assert(n>=k);
	return (lint)fac[n]*invfac[k]%O*invfac[n-k]%O;
}
int main(){
	int n=ni,tot=ni;
	scanf("%s",s+1);
	sum[0]=lpos[0]=rpos[0]=0;
	for(int i=1;i<=n;i++){
		sum[i]=sum[i-1]+(s[i]=='1');
	}
	for(int i=1;i<=tot;i++){
		lpos[i]=ni,rpos[i]=ni;
		if(rpos[i]<=rpos[i-1]){
			i--,tot--;
		}else if(lpos[i]==lpos[i-1]){
			rpos[i-1]=rpos[i];
			i--,tot--;
		}
	}
	lpos[tot+1]=n+1;
	memset(f,0,sizeof(f));
	gmath(n);
	f[0][0]=1;
	int lo=0,hi=0;
	for(int i=1;i<=tot;i++){
		int nxtl=min(lpos[i+1],rpos[i]+1);
		int one=sum[rpos[i]]-sum[max(lpos[i]-1,rpos[i-1])];
		int len1=nxtl-lpos[i],len2=rpos[i]-nxtl+1;
		int nlo=max(lo+one-len1,0),nhi=min(hi+one,len2);
		assert(nlo<=nhi);
		for(int j=nlo;j<=nhi;j++){
			lint tmp=0;
			for(int k=max(lo,j-one),tk=min(hi,len1+j-one);k<=tk;k++){
				tmp+=(lint)f[i-1][k]*C(len1,k+one-j)%O;
			}
			f[i][j]=tmp%O;
		}
		lo=nlo,hi=nhi;
	}
	printf("%d\n",f[tot][0]);
	return 0;
}

Measured memory_bytes: 35712
#include <bits/stdc++.h>
using namespace std;
using Graph_c = vector<vector<char>>;
using ll=long long;
// 幅優先探索
struct Z{
  ll y;
  ll x;
  bool black;
};

ll H,W,y,x,b,w,ans=0;
vector<ll> y_vec={1,0,-1,0};
vector<ll> x_vec={0,1,0,-1};
Graph_c A;
queue<Z> q;
bool black;
ll bfs(){
  while(!q.empty()){
    Z now=q.front(); q.pop();
    y=now.y, x=now.x, black=now.black;
    for(int k=0; k<4; k++){
      if(black==true){
        Z next={y+y_vec[k], x+x_vec[k], false};
        if(A[next.y][next.x]=='.'){
          w++;
          A[next.y][next.x]='0';
          q.push(next);
        }
      }
      else{
        Z next={y+y_vec[k], x+x_vec[k], true};
        if(A[next.y][next.x]=='#'){
          b++;
          A[next.y][next.x]='0';
          q.push(next);
        }
      }
    }
  }
  return 0;
}

int main(){
  cin>>H>>W;
  A.assign(H+2, vector<char>(W+2, '0'));
  for(int i=1; i<=H; i++){
    string S; cin>>S;
    for(int j=1; j<=W; j++){
      A[i][j]=S[j-1];
    }
  }
  for(int i=1; i<=H; i++){
    for(int j=1; j<=W; j++){
      if(A[i][j]!='#') continue;
      black=true;
      b=1, w=0;
      A[i][j]='0';
      Z start={i,j,black};
      q.emplace(start);
      bfs();
//      cout<<"i:"<<i<<" j:"<<j<<" b:"<<b<<" w:"<<w<<endl;
      ans+=b*w;
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
using namespace std;

int main()
{
	int N;
	cin>>N;
	if(N<105){
		cout<<0;
	}else if(N<135){
		cout<<1;
	}else if(N<165){
		cout<<2;
	}else if(N<189){
		cout<<3;
	}else if(N<195){
		cout<<4;
	}else{
		cout<<5;
	}
}


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

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	
	int ba = b-a;
	int cb = c-b;
	if(ba==cb)cout<< "YES";
	else cout <<"NO";
	cout << endl;
	
	return 0;
}

Measured memory_bytes: 256
// finish date: 2018/07/01
#include <iostream>
#include <cmath>
#include <vector>
#include <bitset>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <climits>
#include <functional>

using namespace std;

#define FOR(i, a, b) for(int (i)=a;(i)<(b);(i)++)
#define rep(i, n)  FOR(i,0,n)
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<double> vd;
typedef vector<vector<double>> vvd;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef pair<int, int> pii;
const int bigmod = 1000000007;
const int INF = 1050000000;


int main() {
    int N;
    cin >> N;
    vi A(N);
    rep(i, N) cin >> A[i];
    rep(i, N) A[i] -= i + 1;
    sort(A.begin(), A.end());
    int b = A[N / 2];
    ll sum = 0;
    rep(i, N) {
        sum += abs(A[i] - b);
    }
    cout<<sum<<endl;

    return 0;

}


Measured memory_bytes: 1024
#include <iostream>
#include <iomanip>
#include <string>
#include <string.h>
#include <math.h>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <utility>
#include <deque>
#include <queue>

#define rep(i, n) for(int i = 0; i < n; ++i)
#define REP(i, m, n) for(int i = m; i < n; ++i)
#define rrep(i,n) for(int i = n; i >= 0; --i)
#define RREP(i, m, n) for(int i = n; i >= m; --i)

using ll = long long;
using ull = unsigned long long;
using pii = std::pair<int, int>;
using pll = std::pair<long long, long long>;

using namespace std;

const long long MOD = 998244353;

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

	int n, a, b, c, d;
	string s;
	cin >> n >> a >> b >> c >> d >> s;


	bool ok = true;
	if (c > d) {
		REP(i, a, c - 1) {
			if (s[i] == '#' && s[i + 1] == '#') {
				ok = false;
				break;
			}
		}

		if (ok) {
			ok = false;
			REP(i, b - 2, d - 1) {
				if (s[i] == '.' && s[i + 1] == '.' && s[i + 2] == '.') {
					ok = true;
					break;
				}
			}
		}
	}
	else {
		REP(i, a, c - 1) {
			if (s[i] == '#' && s[i + 1] == '#') {
				ok = false;
				break;
			}
		}

		if (ok) {
			REP(i, b, d - 1) {
				if (s[i] == '#' && s[i + 1] == '#') {
					ok = false;
					break;
				}
			}
		}
	}

	if (ok) cout << "Yes" << "\n";
	else cout << "No" << "\n";

	return 0;
}


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

int main() {
  int N;
  cin >> N;
  string S;
  cin >> S;
  int r = 0;//右にあり取り換えておくもの,あらかじめ数える
  int w = 0;//左にあるのを見つけたらカウント
  int ans = 200001;
  
  for(int i = 0; i < S.size(); i++){
    if(S.at(i) == 'R'){
      r++;
    }
  }
  if(ans > max(r,w)) ans = max(r,w);
 
  for(int i = 0; i < S.size(); i++){
    if(S.at(i) == 'R'){
      r--;
    }
    else w++;
    
    if(ans > max(r,w)) ans = max(r,w);
  }
  
  cout << ans << endl;
  
}

Measured memory_bytes: 3748
from collections import deque,defaultdict,Counter
from itertools import accumulate
import bisect
from heapq import heappop,heappush
from fractions import gcd
from copy import deepcopy
import math
import queue
#import numpy as np
#import sympy as syp(素因数分解とか)
Mod = 1000000007
import sys

sys.setrecursionlimit(100000) 
  
def sieve_of_eratosthenes(n):
    if not isinstance(n,int):
        raise TypeError("n is not int")
    if n<2:
        raise ValueError("n is not effective")
    prime = [1]*(n+1)
    for i in range(2,int(math.sqrt(n))+1):
        if prime[i] == 1:
            for j in range(2*i,n+1):
                if j%i == 0:
                    prime[j] = 0
    res = []
    for i in range(2,n+1):
        if prime[i] == 1:
            res.append(i)
    return res

def factorial(i):
    if i == 1:
        return 1
    else:
        return i*factorial(i-1)
 
class UnionFind:
    def __init__(self,n):
        self.parent = [i for i in range(n+1)]
        self.rank = [0 for i in range(n+1)]
    
    def findroot(self,x):
        if x == self.parent[x]:
            return x
        else:
            y = self.parent[x]
            y = self.findroot(self.parent[x])
            return y
    
    def union(self,x,y):
        px = self.findroot(x)
        py = self.findroot(y)
        if px < py:
            self.parent[py] = px
        else:
            self.parent[px] = py
 
    def same_group_or_no(self,x,y):
        return self.findroot(x) == self.findroot(y)




def main(): #startline--------------------------------------------        ]
    N = int(input())
    X1 = math.floor(N/1.08)
    X2 = math.ceil(N/1.08)
    if math.floor(X1*1.08) == N:
        print(X1)
    elif math.floor(X2*1.08) == N:
        print(X2)
    else:
        print(":(")
if __name__ == "__main__":
    main() #endline===============================================
    

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

#define ll long long
#define ld long double
#define pb push_back
#define mod 1000000007
#define mk make_pair
#define sz size

ll find(ll x,vector<ll> &root){
    while(root[x]!=x){
        root[x]=root[root[x]];
        x=root[x];
    }
    return x;
}

ll union_find(ll x,ll y,vector<ll>&root,vector<ll> &arr){
    ll r1=find(x,root);
    ll r2=find(y,root);
    if(arr[r1]>arr[r2]){
        root[r2]=r1;
    }else if(arr[r1]<arr[r2]){
        root[r1]=r2;
    }
}

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

    ll i,n,k;
    cin>>n;
    vector<ll> v(n+1);
    map<ll,ll> m;
    for(i=1;i<=n;i++)
    {    cin>>v[i];
        m[v[i]]=i;
    }
    for(i=1;i<=n;i++)
        cout<<m[i]<<" ";
    return 0;  
}

Measured memory_bytes: 7936
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
#define mp make_pair

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

int a[110],b[110];
int k[110];
int N;

int f(string str,int n,int m){
//cout<<str<<" "<<n<<" "<<m<<endl;
	if(n>=N-1&&(str=="a"&&a[n]!=2||str=="b"&&b[n]!=2))return m;
	if(str=="a"&&k[n]>0)return 100100100;
	if(str=="a")k[n]++;
	if(str=="a"){
		if(a[n]==0) return f("b",n+2,m+1);
		if(a[n]==1){
			if(a[n+1]==1) return f("a",n+1,m);
			else return f("b",n+2,m+1);
		}
		if(a[n]==2) return f("a",n-1,m);
	}else{
		if(b[n]==0) return f("a",n+2,m+1);
		if(b[n]==1){
			if(b[n+1]==1) return f("b",n+1,m);
			else return f("a",n+2,m+1);
		}
		if(b[n]==2) return f("b",n-1,m);
	}
}

int main() {
	while(N=in()){
		int i;
		for(i=0;i<N;i++)cin>>a[i];
		for(i=0;i<N;i++)cin>>b[i];
		int res=0;
		memset(k,0,sizeof(k));
		res=f("a",0,0);
		memset(k,0,sizeof(k));
		chmin(res,f("b",0,0));
		if(res>=100000)cout<<"NA"<<endl;
		else cout<<res<<endl;
	}
	return 0;
}

Measured memory_bytes: 0
import java.util.*;
public class Main {
 
		public static void main(String[] args){
			Scanner sc = new Scanner(System.in);
			// 整数の入力
			int N = sc.nextInt();
			// スペース区切りの整数の入力
			int M = sc.nextInt();
			System.out.println((N*3+M)/2);
		}
 
	}

Measured memory_bytes: 23124
#include<cstdio>
#include<vector>
const int N=1e5+6,V=2e5+6;
struct edge{int v,c,nxt;}g[800003];
int n,m,head[V],k,iter[V],S,T,d[V],q[V],l,r,f[N],x[N],vis[N];
std::vector<int>e[N];
inline void Insert(int u,int v){
	g[k]=(edge){v,1,head[u]},head[u]=k++;
	g[k]=(edge){u,0,head[v]},head[v]=k++;
}
inline bool Bfs(){
	int u,v;
	for(u=1;u<=T;u++)d[u]=0;
	d[q[l=r=0]=S]=1;
	for(;l<=r;){
	  u=q[l++];
	  for(int i=head[u];~i;i=g[i].nxt)if(g[i].c&&!d[v=g[i].v])
		d[v]=d[u]+1,q[++r]=v;
	}return d[T];
}
int Dfs(int u,int f){
	if(!f||u==T)return f;
	int v,res=0,tmp;
	for(int&i=iter[u];~i;i=g[i].nxt)
	  if(g[i].c&&d[v=g[i].v]>d[u]&&(tmp=Dfs(v,std::min(f,g[i].c)))){
		g[i].c-=tmp,g[i^1].c+=tmp;
		f-=tmp,res+=tmp;
		if(!f)return res;
	  }
	return res;
}
inline int Maxflow(){
	int res=0;
	for(;;){
	  if(!Bfs())return res;
	  for(int u=1;u<=T;u++)iter[u]=head[u];
	  res+=Dfs(S,n-1);
	}
}
void Ans(int u){
	vis[u]=1;
	for(int i=0;i<e[u].size();i++)if(!vis[f[e[u][i]]])
	  x[e[u][i]]=u,Ans(f[e[u][i]]);
}
int main(){
	int u;
	scanf("%d",&n);
	S=n+n-1,T=n+n;
	for(u=1;u<=T;u++)head[u]=-1;
	for(int i=1;i<n;i++){
	  scanf("%d",&m);
	  for(;m--;){
		scanf("%d",&u);
		if(u<n)Insert(u,i+n-1);
		e[u].push_back(i);
	  }
	  Insert(i+n-1,T);
	}
	for(u=1;u<n;u++)Insert(S,u);
	if(Maxflow()!=n-1)return 0*puts("-1");
	for(int u=1;u<n;u++)
	  for(int i=head[u];~i;i=g[i].nxt)if(!g[i].c)
		f[g[i].v-n+1]=u;
	Ans(n);
	for(int u=1;u<=n;u++)if(!vis[u])return 0*puts("-1");
	for(int i=1;i<n;i++)printf("%d %d\n",x[i],f[i]);
	return 0;
}

Measured memory_bytes: 28288
#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;
	vector<int>A(N);
	vector<int>B(N);
	rep(i,N){
		cin>>A.at(i)>>B.at(i);
	}
	sort(A.begin(),A.end());
	sort(B.begin(),B.end());
	/*rep(i,N){
		cout<<A.at(i)<<" "<<B.at(i)<<endl;
	}*/
	cout<<(A.at(0)-1)+(A.at(N-1)-A.at(0)+1)+B.at(0);
return 0;}

/*compile
g++ code.cpp
./a.out
run*/

Measured memory_bytes: 1024
INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))
def do():
    a,b=INTM()
    print(int((a+b)/2+(a+b)%2))
if __name__ == '__main__':
    do()

Measured memory_bytes: 3060
#include <cstdio>
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <deque>
#include <bitset>
#include <iomanip>
#include <limits>
#include <chrono>
#include <random>
#include <array>
#include <unordered_map>
#include <functional>
#include <complex>
#include <numeric>
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; }

constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int inf = 1 << 28;
constexpr long long mod = 1000000007LL;
//constexpr long long mod = 998244353LL;

using namespace std;
typedef unsigned long long ull;
typedef long long ll;

struct Data {
	ll t, s, d;
	Data(ll _t, ll _s, ll _d) :t(_t), s(_s), d(_d) {}
	bool operator<(const Data& e) {
		return t < e.t;
	}
};
int main()
{
	/*
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	*/

	int kkt = 89;
	while (kkt) {
		int n, m; scanf("%d %d", &n, &m); if (n == 0 && m == 0) break;
		vector<Data> vd;
		for (int i = 0; i < m; i++) {
			ll x, y, z; scanf("%lld %lld %lld", &x, &y, &z);
			y--; z--;
			vd.emplace_back(x, y, z);
		}
		sort(vd.begin(), vd.end());
		vector<bool> vir(n, false);
		vir[0] = true;
		for (int i = 0; i < m; i++) {
			if (!vir[vd[i].s]) continue;
			vir[vd[i].d] = true;
		}
		int res = 0; for (int i = 0; i < n; i++) if (vir[i]) res++;
		printf("%d\n", res);
	}
	return 0;

}



Measured memory_bytes: 4200
package main

import (
	"io"
	"bufio"
	"strconv"
	"fmt"
	"os"
)

func binary_search(S []int, n, target int) bool {
	left, mid, right := 0, 0, n
	for left < right {
		mid = (left + right) / 2
		if target == S[mid] {
			return true
		} else if S[mid] < target {
			left = mid + 1
			continue
		}
		right = mid
	}
	return false
}

func answer(r io.Reader) int {
	count := 0
	scanner := bufio.NewScanner(r)
	scanner.Split(bufio.ScanWords)
	n := nextInt(scanner)
	S := make([]int, n)
	for i := range S {
		S[i] = nextInt(scanner)
	}
	q := nextInt(scanner)
	for j := 0; j < q; j++ {
		target := nextInt(scanner)
		if !binary_search(S, n, target) {
			continue
		}
		count++
	}
	return count
}

func nextInt(scanner *bufio.Scanner) int {
	scanner.Scan()
	n, err := strconv.Atoi(scanner.Text())
	if err != nil {
		panic(err)
	}
	return n
}

func main() {
	fmt.Println(answer(os.Stdin))
}


Measured memory_bytes: 2716
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC116_B
{
    class Program
    {
        static void Main(string[] args)
        {
            int s = int.Parse(Console.ReadLine());

            int[] ans = new int[10000];

            int count = 1;

            int number = s;

            while(true)
            {
                ans[number] = 1;

                ++count;

                if (number % 2 == 0)
                {
                    number /= 2;
                }
                else
                {
                    number = 3 * number + 1;
                }

                if (ans[number] != 0) { break; }
            }

            Console.WriteLine("{0}", count);
        }
    }
}


Measured memory_bytes: 13220
#include<stdio.h>
#include<string.h>
int main()
{
	char str1[200], str2[100],str3[100];
	
	scanf("%s", str1);
	scanf("%s", str2);

	strcpy(str3,str1);
	strcat(str1,str3);
	

	
	if ( strstr(str1, str2) == NULL ) 
		printf("No\n");
	else
	    printf("Yes\n");


return 0;
}


Measured memory_bytes: 2100
#include<bits/stdc++.h>
#include<atcoder/all>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) \
  for (ll i = static_cast<int>(a); i < static_cast<int>(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, ) (__VA_ARGS__)  // NOLINT
#define chmax(x, a)  do { x = max(x, a); } while(0)
#define chmin(x, a)  do { x = min(x, a); } while(0)

using namespace std;
using namespace atcoder;
typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<ll,ll> PLL;

void solve() {
  ll n,m,a,b;
  cin >> n >> m >> a >> b;
  cout << floor_sum(n,m,a,b)<<endl;
}

int main() {
  ll T;
  cin >> T;
  rep(_,T)
    solve();
  return 0;
}


Measured memory_bytes: 3668