akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <array>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

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

    int n;
    cin >> n;

    vector<array<char, 10>> s(n);
    for (int i = 0; i < n; i++) {
        char c[11];
        cin >> c;

        sort(c, c + 10);
        for (int j = 0; j < 10; j++) {
            s[i][j] = c[j];
        }
    }

    sort(s.begin(), s.end());

    ll r = 0, t = 0;
    for (int i = 0; i < n; i++) {
        t++;
        if (i == n - 1 || s[i] != s[i + 1]) {
            r += t * (t - 1) / 2;
            t = 0;
        }
    }

    cout << r << endl;

    return 0;
}

Measured memory_bytes: 1280
#include<stdio.h>
#include<string.h>
#define LEN 100005 //十分な大きさ

typedef struct process { //プロセスの構造体
  char name[100];
  int t; //プロセスが必要な時間
} P; //以降Pでprocessを意味する

P Q[LEN];
int head,tail,n;

void enqueue(P x){
  Q[tail] = x;
  tail = (tail + 1)%LEN;
}

P dequeue(){
  P x = Q[head];
  head = (head + 1) % LEN;
  return x;
}

int min(int a,int b){ return a < b ? a : b;}

int main(){
  int elaps = 0,c;
  int i,q;
  P u;
  scanf("%d %d",&n,&q);
  for (i = 1;i <= n;i++){
    scanf("%s",Q[i].name);
    scanf("%d",&Q[i].t);
  }
  head = 1; tail = n + 1;

  while (head != tail){
    u = dequeue();
    c = min(q,u.t);
    u.t -= c;
    elaps += c;
    if (u.t > 0) enqueue(u);
    else {
      printf("%s %d\n",u.name,elaps);
    }
  }

  return 0;
}


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

long long n,opt,c[1000001][2],sz[1000001],f[1000001],num[1000001],root,len,v[1000001];
long long a[1000001],res,sum;
void add(long long x,long long fa)
{
    ++len;
    v[len]=x;
    sz[len]=1;
    num[len]=1;
    f[len]=fa;
    if(x<v[fa])
    c[fa][0]=len;
    else
    c[fa][1]=len;
    c[len][0]=c[len][1]=0;
}
void pushup(long long x)
{
    sz[x]=sz[c[x][0]]+sz[c[x][1]]+num[x];	
}
long long findip(long long d)
{
    long long x=root;	
    while(v[x]!=d)
    {
//		cout<<c[x][0]<<" "<<c[x][1]<<endl;
        if(d<v[x])
        {
            if(c[x][0]==0)
            break;
            else
            x=c[x][0];
        }
        else
        {
            if(c[x][1]==0)
            break;
            else
            x=c[x][1];
        }
    }
    return x;
}
void rotate(long long x)
{
    long long y=f[x],z=f[y],k=c[y][1]==x,w=c[x][!k];
    if(y!=root)
    c[z][c[z][1]==y]=x;
    c[x][!k]=y;
    c[y][k]=w;
    if(w)
    f[w]=y;
    f[y]=x;
    f[x]=z;
    pushup(y);
}
void splay(long long x,long long rt)
{
    while(f[x]!=rt)
    {
        int y=f[x],z=f[y];
        if(f[y]!=rt)
        {
            if(c[z][0]==y ^ c[y][0]==x)
            rotate(x);
            else
            rotate(y);
        }
        rotate(x);
        if(rt==0)
        root=x;
    }
    pushup(x);
}
void ins(long long x)
{
    if(root==0)
    {
        add(x,0);
        root=len;
        return;
    }
    long long y=findip(x);
    if(v[y]==x)
    {
        num[y]++;
        pushup(y);
        splay(y,0);
    }
    else
    {
        add(x,y);
        pushup(y);
        splay(len,0);
    }
}
long long findpaiming(long long k)
{
    long long x=findip(k);
    splay(x,0);
    if(k==v[x])
    return num[x];
    else 
    return 0;
}
int main()
{
    scanf("%lld",&n);
    for(int i=1;i<=n;i++)
    scanf("%lld",&a[i]);
    ins(0);
    for(int i=1;i<=n;i++)
    {
    	sum+=a[i];
    	long long x=findpaiming(sum);
//    	cout<<x<<endl;
    	
    	ins(sum);
    	res+=x;
	}
	printf("%lld\n",res);
    return 0;
}

Measured memory_bytes: 22272
#include<cstdio>
#include <algorithm>

using namespace std;
const int N = 1e6, INF = -1e9;
int r[N];

int main() {
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        scanf("%d", &r[i]);
    }
    int minv = r[0], maxv = INF;
    for (int i = 1; i < n; i++) {
        maxv = max(maxv, r[i] - minv);
        minv = min(minv, r[i]);
    }
    printf("%d\n", maxv);
    return 0;
}


Measured memory_bytes: 3468
#include <bits/stdc++.h>
// #include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <math.h>

using namespace std;
typedef long long int ll;

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

template<class T> inline void chmin(T& a, T b) {if (a > b) a = b;}
template<class T> inline void chmax(T& a, T b) {if (a < b) a = b;}
const ll inf = 1LL<<60;

int main(){
  ios_base::sync_with_stdio(false); 
  cin.tie(NULL);
  ll n,W;cin>>n>>W;

  vector<ll> w(n+10);
  vector<ll> v(n+10);
  rep(i,n){
    cin>>w[i]>>v[i];
  }
  
 
  ll dp[n+10][W+10];
   rep(i,W+1){
    dp[0][i]=0;
  }

  for(ll i=0;i<n;i++){
    ll now_w=w[i];
    ll now_v=v[i];
    for(ll j=0;j<=W;j++){
      if(now_w<=j){
        dp[i+1][j]=max(dp[i][j],dp[i][j-now_w]+now_v);
      }else{
        dp[i+1][j]=dp[i][j];
      }
    }
  }
  cout<<dp[n][W]<<endl;
}


Measured memory_bytes: 80384
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>

using namespace std;

int N;
vector<vector<int>> all(3);
vector<vector<int>> memo(3);

enum Key {
	KeyA = 0,
	KeyB = 1,
	KeyC = 2
};

int dp(int index, Key key) {
	if (memo[key][index] > 0) {
		return memo[key][index];
	}
	if (index == 0) {
		if (key == KeyA) { return max(all[KeyB][0], all[KeyC][0]); }
		if (key == KeyB) { return max(all[KeyA][0], all[KeyC][0]); }
		if (key == KeyC) { return max(all[KeyA][0], all[KeyB][0]); }
	} else {
		if (key == KeyA) {
			int r = all[KeyA][index] + max(dp(index-1, KeyB), dp(index-1, KeyC));
			memo[key][index] = r;
			return r;
		}
		if (key == KeyB) {
			int r = all[KeyB][index] + max(dp(index-1, KeyA), dp(index-1, KeyC));
			memo[key][index] = r;
			return r;
		}
		if (key == KeyC) {
			int r = all[KeyC][index] + max(dp(index-1, KeyA), dp(index-1, KeyB));
			memo[key][index] = r;
			return r;
		}
	}
}

int main() {
	cin >> N;

	vector<int> a(N), b(N), c(N);
	vector<int> memo_a(N, -1), memo_b(N, -1), memo_c(N, -1);
	for (int i = 0; i < N; i++) {
		cin >> a[i] >> b[i] >> c[i];
	}
	all[KeyA] = a; all[KeyB] = b; all[KeyC] = c; 
	memo[KeyA] = memo_a; memo[KeyB] = memo_b; memo[KeyC] = memo_c;

	memo[KeyA][0] = max(all[KeyB][0], all[KeyC][0]);
	memo[KeyB][0] = max(all[KeyC][0], all[KeyC][0]);
	memo[KeyC][0] = max(all[KeyA][0], all[KeyB][0]);

	int res = max({dp(N-1, KeyA), dp(N-1, KeyB), dp(N-1, KeyC)});

	std::cout << res << endl;
}


Measured memory_bytes: 9600
#include <iostream>
#include <cmath>
#include <cstdio>
using namespace std;

int main(void){
  int x, h;
  while(cin >> x){
	cin >> h;
	if(x == 0 && h == 0) break;
	printf("%.6f\n",sqrt((double)x/2 * (double)x/2 + h*h) * x * 2 + x * x);
  }
}

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

int main()
{
	unsigned int a[100], n,alc,bb;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	for (int i = n; i < 100; i++) {
		a[i] = 0;
	}
	sort(a, a+100,greater<>());

	alc = bb = 0;
	for (int i = 0; i < n; i++) {
		if (i%2==0) {
			alc += a[i];
		}
		else {
			bb += a[i];
		}
	}
	cout << (alc - bb) <<endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
long long powmod(long long y,long long x){
	long long ans=1;
	while(x){
		if(x&1)
			ans=(y*ans)%1000000007;
		x/=2;
		y=(y*y)%1000000007;
		
	}
	return ans;
}
int main(){
	int n;
	while(~scanf("%d",&n)){
		int flag=0; 
		int a[100005];
	
		memset(a,0,sizeof(a));
		for(int i=0;i<n;i++){
			scanf("%d",&a[i]);
		}
		sort(a,a+n);
		if(n%2){
			if(a[0]!=0||a[1]==0){
				flag=1;
			}
		}
		for(int i=1;i<n;i++){
			if(flag==1) break;
			if((n-1-a[i])%2) {
				flag=1;
				break;
			}
			if((a[i]==a[i+1]||a[i]==a[i-1])&&a[i+1]!=a[i-1])
				continue;
			else {
				flag=1;	
				break;
				}
		}
		if(n==1)
			printf("1\n");		
		else if(flag)printf("0\n");
		else printf("%lld\n",powmod((long long)2,(long long)n/2));
		
	}
	return 0;
}

Measured memory_bytes: 512
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (sc.hasNext()) {
            int n = sc.nextInt();
            int l = 0;
            for (int a = 0; a < 10; a++) {
                for (int b = 0; b < 10; b++) {
                    for (int c = 0; c < 10; c++) {
                        for (int d = 0; d < 10; d++) {
                            if (a + b + c + d == n) {
                                l += 1;
                            }
                        }
                    }
                }
            }
            System.out.println(l);
        }
    }
}

Measured memory_bytes: 26592
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define rep(i,n) for(ll i=0;i<(n);i++)
int main(){
  ll n;cin>>n;
  vector<ll> v(n);
  rep(i,n) cin>>v[i];
  ll dp[n];
  rep(i,n) dp[i]=1e10;
  dp[0]=0;
  rep(i,n-1){
    rep(j,2){
      if(i>=j) dp[i+1]=min(dp[i+1],dp[i-j]+abs(v[i+1]-v[i-j]));
    }
  }
  cout<<dp[n-1]<<endl;
}

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

int main() {
    int N;
    cin >> N;
    string ans = "No";
    for (int i = 1; i < 10; i++) {
        for (int j = 1; j < 10; j++) {
            int tmp = i * j;
            if (tmp == N) {
                ans = "Yes";
                break;
            }
        }
        if (ans == "Yes") break;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <climits>
#include <string>
#include <unordered_map>
using namespace std;


int main() {

    int H, N;
    cin >> H >> N;

    int A[N];
    for (int i = 0; i < N; i++)
    {
        cin >> A[i];
    }
    
    int sum = 0;
    for (int i = 0; i < N; i++){
        sum += A[i];
    }

    if (H <= sum){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 640
mod scanner {
    use std;
    use std::io::Read;
    pub struct Scanner<R: Read> {
        pub input: R,
    }
    impl<R: Read> Scanner<R> {
        pub fn next<T: std::str::FromStr>(&mut self) -> T {
            let v = self.input.by_ref().bytes()
                .map(|x| x.unwrap())
                .skip_while(|&x| x == b' ' || x == b'\n')
                .take_while(|&x| x != b' ' && x != b'\n')
                .collect::<Vec<_>>();
            match std::str::from_utf8(&v) {
                Ok(v) => {
                    v.parse().ok().expect("scanner error: parse")
                },
                Err(e) => {
                    panic!("scanner error: from_utf8\n{}", e);
                },
            }
        }
    }
}

fn main() {
    let sc = std::io::stdin();
    let mut sc = scanner::Scanner{input: sc.lock()};
    let n: usize = sc.next();
    let m: usize = sc.next();
    let mut a = vec![(false, false); n];
    for _ in 0..m {
        let x: usize = sc.next();
        let y: usize = sc.next();
        if x == 1 {
            a[y - 1].0 = true;
        }
        if y == n {
            a[x - 1].1 = true;
        }
    }
    for (a, b) in a {
        if a && b {
            println!("POSSIBLE");
            return;
        }
    }
    println!("IMPOSSIBLE");
}


Measured memory_bytes: 4352
import java.util.*;
import java.util.Map.Entry;

import javax.swing.text.Segment;
import javax.xml.ws.WebEndpoint;

import java.io.*;
import java.lang.reflect.Array;
import java.math.BigInteger;

import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;
 
public class Main //implements Runnable
{
//    static int dx[]={-1,0,1,0};
//    static int dy[]={0,-1,0,1};

    public static void main(String[] args)   throws Exception, IOException{        
        long mod=1000000007;
        Reader sc = new Reader(System.in);
        PrintWriter out=new PrintWriter(System.out);
        PriorityQueue<Integer> q=new PriorityQueue<>();
        
        int n=sc.nextInt();


        out.println(n*n);
     	out.flush();
    }
    
    static void ret(String ans) {
    	System.out.println(ans);
    	System.exit(0);
    }
    
    static boolean validpos(int x,int y,int r, int c){
        return x<r && 0<=x && y<c && 0<=y;
    }

    static void db(Object... os){
        System.err.println(Arrays.deepToString(os));
    }
}


class P {
	int x, y, d;
	P(int  x, int y, int d) {
	  this.x=x;
	  this.y=y;
	  this.d=d;
	}
}

//class P implements Comparable<P>{
//    int a,b;
//    P(int a, int b) {
//    	this.b=b;
//    	this.a=a;
//    }
//
//    public int compareTo(P p){
//        return p.a-a;//des
//    }
//}

class Reader
{ 
    private BufferedReader x;
    private StringTokenizer st;
    
    public Reader(InputStream in)
    {
        x = new BufferedReader(new InputStreamReader(in));
        st = null;
    }
    public String nextString() throws IOException
    {
        while( st==null || !st.hasMoreTokens() )
            st = new StringTokenizer(x.readLine());
        return st.nextToken();
    }
    public int nextInt() throws IOException
    {
        return Integer.parseInt(nextString());
    }
    public int[] nextIntArray(int size) throws IOException{
        int r[] = new int[size];
        for (int i = 0; i < size; i++) {
            r[i] = this.nextInt(); 
        }
        return r;
    }
    public long[] nextLongArray(int size) throws IOException{
        long r[] = new long[size];
        for (int i = 0; i < size; i++) {
            r[i] = this.nextLong(); 
        }
        return r;
    }
    public char[] getCharSet() throws IOException{
        return this.nextString().toCharArray();
    }    
    public long nextLong() throws IOException
    {
        return Long.parseLong(nextString());
    }
    public double nextDouble() throws IOException
    {
        return Double.parseDouble(nextString());
    }
}


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

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

    // スコア行列：score[y][x]は白チェッカー左下が(x, y)のときの正解数-誤答数
    int score[K][K] = {};
    // 白チェッカー左下が(0, 0)のときの希望の数
    int base_hope = 0;
    for (int i = 0; i < N; i++) {
        int x, y, x_div, y_div, x_mod, y_mod;
        char c;
        cin >> x >> y >> c;
        x_div = x / K, y_div = y / K;
        x_mod = x % K, y_mod = y % K;
        if (((x_div + y_div) % 2 == 0 && c == 'W') || ((x_div + y_div) % 2 == 1 && c == 'B')) {
            base_hope++;
            score[y_mod][x_mod]++;
        } else {
            score[y_mod][x_mod]--;
        }
    }

    //スコア行列の累積和を求める
    for (int y = 0; y < K; y++) {
        for (int x = 0; x < K; x++) {
            int accum = score[y][x];
            if (x > 0)          accum += score[y][x-1];
            if (y > 0)          accum += score[y-1][x];
            if (x > 0 && y > 0) accum -= score[y-1][x-1];
            score[y][x] = accum;
        }
    }

    // 白チェッカー左下を移動させたときの希望の数を計算
    int max_hope = 0;
    for (int y = 0; y < K; y++) {
        for (int x = 0; x < K; x++) {
            int diff = 0, hope = base_hope;
            if (x > 0)          diff += score[K-1][x-1];
            if (y > 0)          diff += score[y-1][K-1];
            if (x > 0 && y > 0) diff -= 2 * score[y-1][x-1];
            hope -= diff;
            int larger_hope = hope > N - hope ? hope : N - hope;
            if (larger_hope > max_hope)
                max_hope = larger_hope;
        }
    }

    cout << max_hope << endl;
}

Measured memory_bytes: 4096
X = int(input())
ans = set()
for i in range(1,int(X)):
	for j in range(2,11):
		if i**j <= X:
			ans.add(i**j)

ans_list = list(ans)
if len(ans_list)==0:
	print(1)
else:
	print(max(ans_list))

Measured memory_bytes: 3060
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
using namespace std;
#define MOD 1000000007
#define INF (1<<29)
#define EPS (1e-10)
typedef long long Int;
typedef pair<Int, Int> P;

#define max(x, y) ((x)>(y)?(x):(y))
#define min(x, y) ((x)<(y)?(x):(y))


vector<int> edge[216000];
queue<int> q;
int n, m, a, b;
bool removed[216000];
bool loop[216000];
string s;
int cnt[216000][2];
int main(){
  cin >> n >> m >> s;
  for(int i = 0;i < m;i++){
    cin >> a >> b;a--,b--;
    if(a == b){
      loop[a] = true;
    }
    else{
      edge[a].push_back(b);
      edge[b].push_back(a);
    }
  }
  for(int i = 0;i < n;i++){
    for(int j = 0;j < edge[i].size();j++){
      int to = edge[i][j];
      cnt[i][s[to]-'A']++;
    }
    if(loop[i])cnt[i][s[i]-'A']++;
    if(cnt[i][0] == 0 || cnt[i][1] == 0){
      q.push(i);
    }
  }
  int remain = n;
  while(!q.empty()){
    int x = q.front();q.pop();
    if(removed[x])continue;
    removed[x] = true;
    remain--;
    for(int i = 0;i < edge[x].size();i++){
      int to = edge[x][i];
      if(removed[to])continue;
      if(--cnt[to][s[x]-'A'] == 0){
	q.push(to);
      }
    }
  }
  if(remain)cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

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

int main(){
  int N, K;
  int num=1;
  
  cin >> N >> K;
  
  for ( int i=0;i<N;i++ ){
    if ( num*2 < num+K )
      num *= 2;
    else
      num += K;
  }
  
  cout << num << endl;
  
}

Measured memory_bytes: 3604
#![allow(unused_imports)]
use std::cmp::*;
use std::num::*;
use std::collections::*;
use itertools::Itertools;
use num::clamp;
use proconio::{input, marker::*, fastout};
use superslice::*;
#[allow(non_snake_case)]
#[allow(non_upper_case_globals)]
#[allow(non_camel_case_types)]
#[fastout()]
fn main(){
    input!{
        n:usize,
    }
    let mut k:usize=0;
    for i in 1..n+1{
        if i*(i+1)==2*n{
            k=i;
            break;
        }
    }
    if k==0{
        println!("No");
        return;
    }
    println!("Yes\n{}",k+1);
    let mut ans:Vec<Vec<i32>>=vec![Vec::new();k+1];
    let mut num=1;
    for i in 0..k+1{
        for j in 0..k-i{
            ans[i].push(num);
            num+=1;
        }
    }
    num=1;
    for i in 0..k+1{
        for j in i+1..k+1{
            ans[j].push(num);
            num+=1;
        }
    }
    for i in 0..k+1{
        print!("{} ",k);
        for j in 0..k{
            print!("{} ",ans[i][j]);
        }
        println!();
    }
}

Measured memory_bytes: 2756
import sys
sys.setrecursionlimit(10**9)
l=list(input())
n=len(l)
p=10**9+7
ans=0
d=0
def f(n,k,q):
    if k==0:
        return 1
    elif k%2==0:
        return ((f(n,k//2,q))**2)%q
    else:
        return (n*f(n,k-1,q))%q

for i in range(n):
    if l[i]=="1":
        x=n-i-1
        ans+=(f(3,x,p)*f(2,d,p))%p
        d+=1
    else:
        continue

ans+=f(2,d,p)
print(ans%p)


Measured memory_bytes: 80756
#include <algorithm>
#include <bitset>
#include <complex>
#include <cstdio>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)n; ++i)
#define FOR(i, a, b) for(int i = a; i < (int)b; ++i)

typedef long long ll;

const int Inf = 100100100;
const double EPS = 1e-9;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a, b, c;
    cin >> a >> b >> c;
    cout << min(a + b, min(b + c, c + a));

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,k) for(int i=j;i<=k;++i)
typedef long long ll;
char cch;
inline ll rd(){
	ll x=0,fl=1;
	cch=getchar();
	while(cch>'9'||cch<'0'){
		if(cch=='-') fl=-1;
		cch=getchar();
	}
	while(cch>='0'&&cch<='9') x=(x<<3)+(x<<1)+cch-'0',cch=getchar();
	return x*fl;
}
const int N=1e5+3;
struct abc{
	int i;
	ll d;
}a[N];
int fr[N],head[N],to[N],nxt[N],cnt,sz[N];
ll re,c[N];
inline bool cmp(const abc &a,const abc &b){
	return a.d<b.d;
}
inline void adde(int u,int v){
	to[++cnt]=v,fr[cnt]=u,nxt[cnt]=head[u],head[u]=cnt;
}
inline void dfs(int u,int fa,int dep){
	re+=dep;
	for(int i=head[u];i;i=nxt[i]){
		dfs(to[i],u,dep+1);
	}
}
int main(){
	int n;
	scanf("%d",&n);
	rep(i,1,n) a[i].d=rd(),a[i].i=i,sz[i]=1;
	sort(a+1,a+1+n,cmp);
	rep(i,1,n) c[i]=a[i].d;
	int pos;
	ll tmp;
	for(int i=n;i>1;--i){
		tmp=a[i].d-(n-sz[a[i].i])+sz[a[i].i];
		pos=lower_bound(c+1,c+n+1,tmp)-c;
		if(c[pos]!=tmp){
			puts("-1");return 0;
		}
		else sz[a[pos].i]+=sz[a[i].i],adde(a[pos].i,a[i].i);
	}
	dfs(a[1].i,0,0);
	if(re!=a[1].d){
		puts("-1");return 0;
	}
	for(int i=1;i<n;++i){
		printf("%d %d\n",fr[i],to[i]);
	}
}

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

using namespace std;

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

	int rate[9] = { 0 };

	for (int i = 0; i < N; i++) {
		if (a[i] > 3600)
			a[i] = 3599;
		rate[a[i] / 400]++;
	}

	int ans = 0;
	for (int i = 0; i < 8; i++) {
		if (rate[i] != 0) {
			ans++;
		}
	}

	cout << max(1, ans) << " " << ans + rate[8] << endl;

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define rep(i, n) for(int i=0; i<n; i++)
#define REP(i, n) for(int i=0; i<=n; i++)
#define repr(i, n) for(int i=n; i>0; i--)
#define REPR(i, n) for(int i=n; i>=0; i--)
const ll INF = 1LL<<60;
const int INT_INF = 1e9;
const ll MOD = 1e9+7;
template<class T> void puts(T x) { std::cout << x << std::endl; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using namespace std;

int n, a[100010];
map<int, int> dict;

int main() {
    cin >> n;
    rep(i, n) dict[i] = 0;
    rep(i, n) {
        int a; cin >> a;
        dict[a] += 1;
    }

    bool flg = true;
    if (n % 2 == 0) {
        for (int i = 1; i < n; i += 2) {
            if (dict[i] != 2) {
                flg = false;
                break;
            }
        }
    } else {
        for (int i = 0; i < n; i += 2) {
            if ((i == 0 && dict[i] != 1) || (i > 0 && dict[i] != 2)) {
                flg = false;
                break;
            }
        }
    }

    ll ans = 0;
    if (flg) {
        ++ans;
        rep(i, n / 2) {
            ans *= 2;
            ans %= MOD;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 4992
function myin(){return require("fs").readFileSync("/dev/stdin", "utf8").trim();}

//0:何もしない  1:数値へ変換  2:半角SPで分割  3:改行で分割  4:半角SPで分割し、数値配列へ
//5:改行で分割し、数値配列へ  6:1文字に分割  7:1文字に分割し、数値配列へ
function myconv(i, no){
  switch(no){
    case 0: return i;
    case 1: return parseInt(i);
    case 2: return i.split(" ");
    case 3: return i.split("\n");
    case 4: return i.split(" ").map((a)=>Number(a));
    case 5: return i.split("\n").map((a)=>Number(a));
    case 6: return i.split("");
    case 7: return i.split("").map((a)=>Number(a));
  }}
function Main(input) {
  S = myconv(input, 0);
  len = S.length
  let ans = 999999999
  for(let i = 0; i < len; i++ ){
    num = parseInt(S.substr(i, 3), 10);
    ans = Math.min(ans, Math.abs(num - 753));
  }
  console.log(ans);

}
// Main(myin());
Main(require("fs").readFileSync("/dev/stdin", "utf8").trim());

Measured memory_bytes: 29512
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <deque>
#include <list>
#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;


#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repr(i,n) for(int (i)=(n); (i)>=(0); (i)--)
#define SIZE(x) ((int)(x).size())
#define GCD(a, b) int gcd(int a,int b){return b?gcd(b,a%b):a;}
#define QP(a, b) int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define all(v) (v).begin(),(v).end()


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;}
template<typename A, size_t N, typename T>
void FILL(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

typedef vector<int, int> vint;
typedef pair<int,int> pint;
typedef vector<pint>vpint;
typedef long long ll;

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1LL << 60;
const ll MOD = 1000000007LL;


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, K; cin >> N >> K;
    int ans = 1;
    rep(i, N){
        if(2*ans < ans+K) ans *= 2;
        else ans += K;
    }
    cout << ans;
    cout << endl;
    return 0;
}




Measured memory_bytes: 256
N,Q = map(int,input().split(" "))
A = [0]*N

B = [0 for j in range(N)]
for i in range(N-1):
    a,b = map(int,input().split(" "))
    A[b-1] = a-1
    
for j in range(Q):
    tmp = list(map(int,input().split(" ")))
    B[tmp[0]-1] += tmp[1]

for i in range(1,N):
        B[i] += B[A[i]]
for i in range(N):
        print(B[i],end=" ")


Measured memory_bytes: 69836
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <algorithm>
#include <queue>

using namespace std;
typedef long long ll;

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

    ll t, a, b;
    ll min = 0;
    priority_queue<ll> p;
    priority_queue<ll, vector<ll>, greater<ll>> q;

    for (int i = 0; i < Q; i++) {
        cin >> t;
        if (t == 1) {
            cin >> a >> b;
            if (p.empty() || p.top() > a) {
                p.push(a);
                min += p.top() - a + b;
                if (p.size() > q.size() + 1) {
                    q.push(p.top());
                    p.pop();
                }
            }
            else if (q.empty() || q.top() < a) {
                q.push(a);
                if (q.size() > p.size()) {
                    p.push(q.top());
                    q.pop();
                }
                min += a - p.top() + b;
            }
            else {
                if (p.size() == q.size()) {
                    min += b;
                    p.push(a);
                }
                else {
                    min += a - p.top() + b;
                    q.push(a);
                }
            }
        }
        else {
            cout << p.top() << " " << min << endl;
        }
    }

    return 0;
}



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

const int block = 4;
const int floor = 3;
const int room = 10;

int main() {
  int b, f, r, v;
  int h[block][floor][room] = {0};
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> b >> f >> r >> v;
    h[b -1][f -1][r -1] += v;
  }
  for (int j = 0; j < block; j++) {
    for (int k = 0; k < floor; k++) {
      for (int l = 0; l < room; l++) {
        cout << " " << h[j][k][l];
      }
      cout << endl;
    }
    if (j == block - 1) break;
    cout << "####################" << endl;
  }
  return 0;
}

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

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define Eunique(v) v.erase(unique(all(v)),v.end())
#define Eback(s) s.erase(s.end()-1,s.end())
#define pb push_back
#define pf push_front
#define mod 1000000007
#define m_p make_pair
#define DOUBLE fixed << setprecision(15)
#define OK puts("OK")
#define OK1 puts("OK1")
#define OK2 puts("OK2")
#define SIZE(s) (int)s.size()
#define Cout(n) cout<<(n)<<endl
#define INF 1000000000000000000LL

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef vector<pair<int,int>> vpii;
typedef vector<pair<ll,ll>> vpll;
typedef vector<string> vs;
const double pi = acos(-1.0);

template<class A, class B>
ostream& operator<<(ostream& ost, const pair<A, B>&p) {
	ost << "{" << p.first << ", " << p.second << "} ";
	return ost;
}

template<class T>
ostream& operator<<(ostream& ost, const vector<T>&v) {
	ost << "{";
	for (int i = 0; i<(int)v.size(); i++) {
		if (i)ost << " ";
		ost << v[i];
	}
	ost << "} \n";
	return ost;
}

template<class A, class B>
ostream& operator<<(ostream& ost, const map<A, B>&v) {
	ost << "{";
	for (auto p:v) {
		ost << "{" << p.first << ", " << p.second << "} ";
	}
	ost << "} ";
	return ost;
}

ll gcd(ll x, ll y) { return (y == 0) ? x : gcd(y, x % y); }
ll lcm(ll x, ll y) { return x * y / gcd(x, y); }

int main()
{
	ll n,m,p,wa=0,ac=0;
	string s;
	map<ll,string> mp;
	map<ll,ll> mp2;
	cin >> n >> m;
	rep(i,m){
		cin >> p >> s;
		if(s=="AC" && mp[p]!="AC"){
			ac++;
			mp[p]="AC";
			wa+=mp2[p];
		}
		if(s=="WA" && mp[p]!="AC"){
			mp2[p]++;
		}
	}
	cout << ac << " " << wa << endl;
	return 0;
}


Measured memory_bytes: 17408
/* Dsingh_24 */

#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define	endl		'\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define rep(i,a,b)	for(ll int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define ios	    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;

#define N  500005

int main()
{
	ios
	ll a,b,c;
	cin>>a>>b>>c;
	cout<<b+min(a+b+1,c);
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define LINF (ll)INF*INF
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef vector<pii> vp;

int gcd(int a, int b){
    if(b==0) return a;
    return gcd(b,a%b);
}
int lcm(int a, int b){
    return a*b/gcd(a,b);
}


int ans = 0;
vector<vp> v;

void dfs(vi used, vs s, int cnt){
    ans = max(ans, cnt);
    rep(i,26)if(used[i] == 0 && v[i].size()){
        int diff = abs(v[i][0].first - v[i][1].first) + abs(v[i][0].second - v[i][1].second);
        if(diff <= 1)continue;
        bool c = true;
        if(v[i][0].first == v[i][1].first){
            int x = v[i][0].first;
            int mi = min(v[i][0].second,v[i][1].second);
            int ma = max(v[i][0].second,v[i][1].second);
            loop(y,mi+1,ma){
                if(s[x][y] != '.')c = false;
            }
        }else if(v[i][0].second == v[i][1].second){
            int y = v[i][0].second;
            int mi = min(v[i][0].first,v[i][1].first);
            int ma = max(v[i][0].first,v[i][1].first);
            loop(x,mi+1,ma){
                if(s[x][y] != '.')c = false;
            }
        }else{
            bool f = false;
            int xmi = min(v[i][0].first,v[i][1].first);
            int xma = max(v[i][0].first,v[i][1].first);
            int ymi = min(v[i][0].second,v[i][1].second);
            int yma = max(v[i][0].second,v[i][1].second);
            rep(z,2){
                int p = v[i][z].first, q = v[i][!z].second;
                if(s[p][q] != '.')continue;
                bool cc = true;
                loop(y,ymi+1,yma){
                    if(s[p][y] != '.')cc = false;
                }
                loop(x,xmi+1,xma){
                    if(s[x][q] != '.')cc = false;
                }
                if(cc){
                    f = true;
                }
            }
            if(f == false)c = false;
        }
        if(c){
            used[i]++;
            rep(j,2)s[v[i][j].first][v[i][j].second] = '.';
            cnt++;
        }
    }
    if(ans < cnt)dfs(used,s,cnt);
}

signed main(void) {
    int n,m;
    cin >> n >> m;
    vs s(n);
    rep(i,n) cin >> s[i];
    v = vector<vp> (26);
    rep(i,n)rep(j,m)if(s[i][j] != '.'){
        int a = s[i][j] - 'A';
        v[a].push_back(pii(i,j));
    }
    dfs(vi(26,0),s,0);
    cout << ans*2 << endl;
}



Measured memory_bytes: 3888
#include<bits/stdc++.h>
using namespace std;
using UL = unsigned int;
using ULL = unsigned long long;
using LL = long long;
#define rep(i, n) for(UL i = 0; i < (n); i++)

struct Problem {
public:

	void Solve() {
		ULL A, B;
		double b;
		cin >> A >> b;
		B = b * 100 + 0.2;
		A *= B;
		A /= 100;
		cout << A << endl;
	}
};

int main() {
	unique_ptr<Problem> p(new Problem());
	p->Solve();
	return 0;
}


Measured memory_bytes: 3680
#include<stdio.h>
int main(){
    int A[101][101],B[101][101];
    long int sum;
    int n,m,l,k;
    int i,j;
    scanf("%d %d %d",&n,&m,&l);
    for(i=0;i<n;i++){
        for(j=0;j<m;j++){
            scanf("%d",&A[i][j]);
        }
    }
    for(i=0;i<m;i++){
        for(j=0;j<l;j++){
            scanf("%d",&B[i][j]);
        }
    }
    for(i=0;i<n;i++){
        for(j=0;j<l;j++){
            sum=0;
            for(k=0;k<m;k++){
                sum += A[i][k] * B[k][j];
            }
            printf("%ld",sum);
            if(l-j>1){
                printf(" ");
            }
        }
        printf("\n");
    }
}


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

int main(){
    int n,r,naibu;
    cin >> n >> r;

    if(n >= 10) naibu = r;
    else naibu = r + 100*(10-n);

    cout << naibu << endl;
}

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

main(){
	while(true){
		int n;
		cin>>n;
		
		if(n<=0){
			break;
		}
		
		int cnt[10]={0};
		
		for(int i=0; i<n; ++i){
			int c;
			cin>>c;
			
			cnt[c]++;
		}
		
		for(int c=0; c<=9; ++c){
			if(cnt[c]==0){
				puts("-");
			}else{
				for(int j=0; j<cnt[c]; ++j){
					cout<<'*';
				}
				cout<<endl;
			}
		}
	}
}


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

#define nl '\n'

using namespace std;

int n, a, x, y;

int main(){

    cin >> n;

    vector<int> v;

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

    sort(v.rbegin(), v.rend());



    for(int i = 0; i < v.size(); i++){
        if(i%2 == 0 || i == 0){
            x = x + v[i];
        } else{
            y = y + v[i];
        }
    }

    cout << x-y;






}

//g++ -std=c++14 comp.cpp -o b; ./b.exealso

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

const ll MOD = 1000000007;

int main(){
    int n,k; cin >> n >> k;
    vector<ll> h(n); rep(i,n) cin >> h[i];
    if(k >= n){
        cout << 0 << endl;
        return 0;
    }
    sort(h.begin(),h.end(),greater<ll>());
    rep(i,k) h[i] = 0;    
    ll ans = 0LL;
    rep(i,n) ans += h[i];
    cout << ans << endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
using VI = vector<int>;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)
#define all(v) v.begin(), v.end()

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

  int n, q; cin >> n >> q;
  VI c(n); rep(i, n) cin >> c[i];
  vector<pair<int, int>> lr(q); rep(i, q) cin >> lr[i].first >> lr[i].second;
  rep(i, q) lr[i].first--;

  const int sq = 10;
  VI ri(q), lri(q);
  VI cnt(n+1);
  rep(i, q) cnt[lr[i].second]++;
  rep(i, n) cnt[i+1] += cnt[i];
  repr(i, q) ri[--cnt[lr[i].second]] = i;
  fill(all(cnt), 0);
  rep(i, q) cnt[lr[i].first >> sq]++;
  rep(i, n) cnt[i+1] += cnt[i];
  repr(i, q) lri[--cnt[lr[ri[i]].first >> sq]] = ri[i];
  fill(all(cnt), 0);

  VI ans(q);

  int prev = -1;
  int lx, rx;
  int sum = 0;
  for (auto i : lri) {
    auto [l, r] = lr[i];
    if (l >> sq != prev) {
      fill(all(cnt), 0);
      lx = rx = r;
      prev = l >> sq;
      sum = 0;
    }
    int cx;
    while (lx > l) if (cnt[cx=c[--lx]]++ == 0) sum += 1;
    while (lx < l) if (--cnt[c[lx++]] == 0) sum -= 1;
    while (rx < r) if (cnt[cx=c[rx++]]++ == 0) sum += 1;
    ans[i] = sum;
  }
  rep(i, q) cout << ans[i] << "\n";
}


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

using namespace std;

using ll = long long;

int main() {
	
	ll A, B, C, K;
	cin >> A >> B >> C >> K;

	ll k = pow(2, K);
	
	if (A >= B and A >= C)
		A *= k;
	else if (A <= B and B >= C)
		B *= k;
	else
		C *= k;
	cout << A + B + C << '\n';

	return 0;
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=(n)-1;i>=0;i--)
#define VSORT(v) sort(v.begin(), v.end())
#define DVSORT(v) sort(v.begin(), v.end(),greater<int>())
#define SORT(v, n) sort(v, v+n)
#define DSORT(v,n) sort(v, v+n,greater<int>())
#define vi vector<int>
#define pb push_back
#define P pair<int,int>


template <class T> void chmin(T&a, const T&b) { a = min(a,b); }
template <class T> void chmax(T&a, const T&b) { a = max(a,b); }

const double EPS =1e-9;
const long INF =999999999;
const long MOD =1000000007; //10^9+7
#define PI 3.14159265258979

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

int main(){
	int A,B;
	cin>>A>>B;
	if(A+B>=10) puts("error");
	else printf("%d\n",A+B);
	return 0;
}



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

int main() {
  int N, A, B;
  
  cin >> N >> A >> B;
  
  int X = N * A;
  
  if(X > B){
    cout << B << endl;
  }
  
  else{
    cout << X << endl;
  }
  
}


Measured memory_bytes: 256
// AOJ DPL_5_B Balls and Boxes 2
// 2019.3.10 bal4u

#include <stdio.h>
#include <stdlib.h>

#define MOD 1000000007

int perm(int n, int k)  // n(n-1)...(n-k+1)
{
	long long ans = 1;
	while (k) ans = (ans * n) % MOD, n--, k--;
	return (int)ans;
}

int main()
{
	int n, k;

	scanf("%d%d", &n, &k);
	if (n > k) puts("0");
	else printf("%d\n", perm(k, n));
	return 0;
}


Measured memory_bytes: 2112
#include<stdio.h>
int main(){
	 int K,A,B,i;
	 int Count= 0;
	 scanf("%d",&K);
	 scanf("%d %d",&A,&B);
	 for(i=A;i<=B;i++){
	 	if(i%K==0){
	 		Count++;
		 }
	 }	if(Count>0){
	 	     printf("OK\n");
	 }else{
	 	     printf("NG\n");
	 }
	 
	 
	 	
	 
	
	return 0;
}

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

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

using namespace std;

int main(){
  int w,h,n;
  cin>>w>>h>>n;
  int u=h, d=0, l=0, r=w;

  rep(i,n){
    int x,y,a;
    cin>>x>>y>>a;
    if(a==1 && l<x)l=x;
    if(a==2 && r>x)r=x;
    if(a==3 && d<y)d=y;
    if(a==4 && y<u)u=y;
  }

//  cout<<u<<' '<<d<<' '<<l<<' '<<r<<' '<<endl;
  if( u-d<0 || r-l<0){
    cout<<0;
    return 0;
  }
  int result = (u-d)*(r-l);
  cout<<result;

  return 0;
}

Measured memory_bytes: 256
//Zory-2019
#include<bits/stdc++.h>
using namespace std;
namespace mine
{
    typedef long long ll;
    #define pr pair<int,int>
    #define FR first
    #define SE second
    #define MP make_pair
    #define PB push_back
    #define vc vector
    #define all(x) (x).begin(),(x).end()
    #define sz(x) ((int)(x).size())
    #define bin(x) (1ll<<(x))
    #define GG(x) if(x) {puts("error");exit(666);}
    #define fo(i,l,r) for(int i=(l),I=(r);i<=I;i++)
    #define fd(i,r,l) for(int i=(r),I=(l);i>=I;i--)
    ll qread()
    {
        ll ans=0,f=1;char c=getchar();
        while(c<'0' or c>'9') {if(c=='-')f=-1;c=getchar();}
        while('0'<=c and c<='9') ans=ans*10+c-'0',c=getchar();
        return ans*f;
    }
    void write(ll num)
    {
        if(num<0) putchar('-'),num=-num;
        if(num>=10) write(num/10);
        putchar('0'+num%10);
    }
    void write1(ll num){write(num);putchar(' ');}
    void write2(ll num){write(num);putchar('\n');}
    template<typename T> void chmax(T &x,const T y) {x=(x>y?x:y);}
    template<typename T> void chmin(T &x,const T y) {x=(x<y?x:y);}
    ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}

    const int INF=0x3f3f3f3f;
    const int MOD=1e9+7;
    int mm(const int x){return x>=MOD?x-MOD:x;}
    template<typename T> void add(T &x,const int &y){x=(x+y>=MOD?x+y-MOD:x+y);}
    ll qpower(ll x,ll e,int mod=MOD){ll ans=1;GG(e<0)while(e){if(e&1)ans=ans*x%mod;x=x*x%mod;e>>=1;}return ans;}
    ll invm(ll x){return qpower(x,MOD-2);}
    const int N=1e6+10;

    int a[N],n,m;bool ok=0;
    void work(int l,int r){ok|=(l<=n and n<=r);}
    vc<pr> uu;
    bool check(int mid)
    {
        // printf("check(%d)\n",mid);
        if(a[1]>=mid) {bool bk=1;fo(i,2,m) bk&=(a[i-1]>=mid)^(a[i]>=mid);if(bk) return 1;}//special
        else {bool bk=1;fo(i,2,m) bk&=(a[i-1]>=mid)^(a[i]>=mid);if(bk) return 0;}//special

        uu.clear();int lst=(a[1]>=mid),ln=1;
        fo(i,2,m) if(lst^(a[i]>=mid)) uu.PB(MP(ln,i-1-ln+1)),ln=1,lst^=1; else ln++;uu.PB(MP(ln,m-ln));
        for(int i=0,j=0;i<sz(uu);i++)
        {
            if(uu[i].FR>=2) {if(uu[i].SE<=n and n<=uu[i].SE+uu[i].FR-1)
                return a[n]>=mid;continue;}
            chmax(j,i);
            while(j+1<sz(uu) and uu[j+1].FR==1) j++;
            // printf("i=%d j=%d\n",i,j);
            int fir=uu[i].SE,ln=j-i+1;
            if(ln&1) {
                if(fir<=n and n<=fir+ln-1) return a[fir]<mid;}
            else {
                if(fir<=n and n<=fir+ln/2-1) return a[fir]<mid;
                if(fir+ln/2<=n and n<=fir+ln-1) return a[fir]>=mid;}
            i=j;
        }
        assert(0);return -1;
    }
	void main()
	{
        n=qread(),m=n+n-1;fo(i,1,m) a[i]=qread();
        int fl=1,fr=m,ans=-1;
        while(fl<=fr)
        {
            int mid=(fl+fr)/2;
            if(check(mid)) ans=mid,fl=mid+1;
            else fr=mid-1;
        }write(ans);
	}
};//(ans+MOD)%MOD
signed main()
{
    srand(time(0));
    mine::main();
}


Measured memory_bytes: 4212
#include <bits/stdc++.h>
    using namespace std;
     
    int main(){
      int a[3];
      cin >> a[0] >> a[1] >> a[2];
      sort(a, a + 3);
      cout << a[2] * 10 + a[1] + a[0] << endl;
      return 0;
    }

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>

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

int main(){
  int N, Q; cin >> N >> Q;
  string S; cin >> S;

  //累積和
  vector<int> s(N+1, 0);
  for (int i=0; i<N; ++i){
    if (i+1 < N && S[i] == 'A' && S[i+1] == 'C') s[i+1] = s[i]+1;
    else s[i+1] = s[i];
  }

  //クエリ
  for (int q=0; q<Q; ++q){
    int l, r; cin >> l >> r;
    --l; --r;
    cout << s[r] - s[l] << endl;
  }
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;;
#define ll long long
#define rep(i, n) for(int i = 0;i < n;i++)
#define repr(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define INF 1<<30
#define LINF 1LL<<62
#define all(x) (x).begin(), (x).end()
#define mp make_pair
#define pb push_back
const int MOD = 1000000007;
 
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll x,a; cin >> x >> a;
  if(x<a){
      cout << 0 << endl;
  }else{
      cout << 10 << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
#include <queue>
#include <ctime>
#include <cassert>
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
#define fs first
#define sc second
#define INF 1000000000
#define MOD 1000000007
#define EPS 0.00000001


int main(){
    string S, T; cin >> S >> T;
    int N = (int)S.size();
    int M = (int)T.size();
    vector<vector<int>> A(26);
    for(int i=0; i<N; i++){
        A[S[i]-'a'].push_back(i);
    }
    
    for(int i=0; i<M; i++){
        if(A[T[i]-'a'].size()==0){
            cout << -1 << endl;
            return 0;
        }
    }
    
    int cur = -1;
    int cnt = 0;
    string now;
    for(int i=0; i<M; i++){
        vector<int>::iterator it = upper_bound(A[T[i]-'a'].begin(), A[T[i]-'a'].end(), cur);
        if(it==A[T[i]-'a'].end()){
            cur = -1;
            cnt++;
            i--;
            now = "";
        }
        else{
            cur = *it;
            now += T[i];
        }
    }
    cnt++;
    
    
    int p = 0;
    int last = 0;
    for(int i=0; i<N; i++){
        if(now[p]==S[i]){
            if(p==now.size()-1){
                last = i;
                break;
            }
            p++;
        }
    }
    
    cout << (ll)N * cnt - (N - 1 - last) << endl;
    return 0;
}





Measured memory_bytes: 1216
#include<bits/stdc++.h>
#define ll long long int
#define ull unsigned long long int
#define pb push_back
#define faster ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define mem(ara,n) memset(ara,n,sizeof(ara))
#define memb(ara) memset(ara,false,sizeof(ara))
#define all(x) (x).begin(),(x).end()
#define fr freopen("input.txt","r",stdin);
#define fw freopen("output.txt","w",stdout);
const double PI  =3.141592653589793238463;
using namespace std;

int main()
{
    faster;
    ll a,b,c,d,e,f=0,ans=0,sum=0,m,n,p,q,r,t,w,x,y,z;
    string s;
    cin>>s;
     for(int i=0;i<s.length()-1;i++)
     {
         if(s[i]==s[i+1])
         {
             f=1;
             continue;
         }
         if(s[i]!=s[i+1])
         {
             f=0;
             sum++;

         }
     }
     cout<<sum<<endl;

    return 0;
}







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

#include <list>
#include <queue>
#include <algorithm>

#define INF 1000000000

using namespace std;

int main(void)
{
    int n;
    long long a[100000];
    cin >> n;
    bool flag = false;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    for (int i = 0; i < n; i++) {
        if (a[i] == 0) {
            flag = true;
            break;
        }
    }
    if (flag == true) {
        cout << 0;
        return 0;
    }
    long long ans = 1;
    
    for (int i = 0; i < n; i++) {
        long long origin = ans;
        if (a[i] == 0) {
            ans = 0;
            break;
        }
        ans *= a[i];
        if (ans / a[i] != origin) {
            // cout << i << " overflow" << endl;
            ans = -1;
            break;
        }
        if (a[i] > 1000000000000000000 / origin) {
            // cout << i << " over" << endl;
            ans = -1;
            break;
        }
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 4412