akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <map>
#include <cmath>
#include <numeric>

#define rep(i,n) for(int i = 0;i < (n);i++)
#define repp(i,j, n) for(int i = (j);i < (n);i++)
#define all(x) (x).begin(),(x).end()
#define pb(x) push_back(x)
#define mp(a,b) make_pair(a,b)
#define INF 1e9

using namespace std;

typedef long long int ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<pair<int, int> > vpi;
typedef vector<pair<ll, ll> > vpl;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  vi path(n);
  rep(i, m){
    int a, b;
    cin >> a >> b;
    if(b==1||b==n) path[a]++;
    if(a==1||a==n) path[b]++;
  }
  rep(i, n){
    if(path[i]==2){
      cout << "POSSIBLE" << endl;
      return 0;
    }
  }
  cout << "IMPOSSIBLE" << endl;
  return 0;
}


Measured memory_bytes: 1152
#include <cstdio>

char S[100001];

int main() {
  scanf("%s",S);

  bool app[26];
  for (int i = 0;  i < 26; ++i){
    app[i] = false;
  }
  for (int i = 0; S[i] != '\0'; ++i){
    app[S[i] - 'a'] = true;
  }
  for (int i = 0; i < 26; ++i){
    if (!app[i]) {
      printf("%c\n",(char)(i + 'a'));
      return 0;
    }
  }
  puts("None");
  return 0;
}


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

long pow(long x, long y){
    long z=1;
    for(int i=0;i<y;i++){
        z = z*x;
    }
    return z;
}

int main(){
    long N,size=1,all=0;
    cin >> N;
    for(int i=0;pow(26,i+1)+all<N;i++){
        size += 1;
        all += pow(26,i+1);
    }
    vector<int>x(size,0);
    all = N-all;
    for(int i=0;i<size;i++){
        for(int j=0;pow(26,size-i-1)<all;j++){
            all -= pow(26,size-i-1);
            x[i]++;
        }
    }
    for(int i=0;i<size;i++){
        cout << (char)('a'+x[i]);
    }
}

Measured memory_bytes: 3652
#include <iostream>
#include <math.h>

using namespace std;

long long int f(long long int H){
  if(H==1) return 1;
  return ( 2*f(H/2) + 1 );
}

int main(){
  long long int H;
  cin >> H;
  long long int a = f(H);
  cout << a << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <math.h>
using namespace std;

int main(){
    string s;
    cin >> s;
    int n = s.size();
    for (int i = n-2; i > 0; i-=2) {
        string ss = s.substr(0,i);
        if(ss.substr(0,i/2) == ss.substr(i/2,i/2)){
            cout << i << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    int coin[] = {500, 100, 50, 10, 5, 1};

    for(;;){
        int n;
        cin >> n;
        if(n == 0)
            return 0;

        n = 1000 - n;
        int ret = 0;
        for(int i=0; i<6; ++i){
            while(n >= coin[i]){
                n -= coin[i];
                ++ ret;
            }
        }
        cout << ret << endl;
    }
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define l long
#define pb push_back
#define mp make_pair
#define mt make_tuple


int main() {
	
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int t=1;
	//cin>>t;
	while(t--)
	{
	    int a,b,c;
	    cin>>a>>b>>c;
	    int tp;
	    tp=a;
	    a=b;
	    b=tp;
	    tp=a;
	    a=c;
	    c=tp;
	    
	    cout<<a<<" "<<b<<" "<<c<<endl;
	}
	
	return 0;
}


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

int main()
{
	int count= 0, num, *friend, i, j;

	scanf("%d", &num);
	friend= (int *)malloc(sizeof(int)* num);

	for(i= 0; i< num; i++)
		scanf("%d", &friend[i]);

	for(i= 0; i< num; i++)
	{
		if(!friend[i])
			continue;

		if(friend[friend[i]- 1]== i+ 1)
		{
			count++;
			friend[friend[i]- 1]= 0;
		}
	}

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

	free(friend);

	return 0;
}


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

typedef long long ll;
typedef pair<int, int> P;

int MOD = 1e9 + 7;
ll INF = 1e18;

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

int main(){
    int h, w; cin>>h>>w;
    char a[110][110];
    for(int i=0; i<h; i++){
        for(int j=0; j<w; j++){
            cin>>a[i][j];
        }
    }

    int i=0;
    while(i<h){ //yoko
        int sum=0;
        for(int j=0; j<w; j++){
            if(a[i][j] == '.'){
                sum++;
            }
        }

        if(sum == w){
            h--;
            for(int k=i; k<h; k++){
                for(int j=0; j<w; j++){
                    a[k][j] = a[k+1][j];
                }
            }
        }
        else{
            i++;
        }
    }

    i=0;
    while(i<w){
        int sum=0;
        for(int j=0; j<h; j++){
            if(a[j][i] == '.'){
                sum++;
            }
        }

        if(sum == h){
            w--;
            for(int k=i; k<w; k++){
                for(int j=0; j<h; j++){
                    a[j][k] = a[j][k+1];
                }
            }
        }
        else{
            i++;
        }
    }

    for(int i=0; i<h; i++){
        for(int j=0; j<w; j++){
            cout << a[i][j];
        }
        cout << endl;
    }
}

Measured memory_bytes: 256
BIG_NUM = 2000000000
 
 
N = int(input())
x = 0
 
for i in range(1,N+1):
 
    if i%3 == 0:
            print(" %d"%i,end = "");
    else:
        x = i
        while (x):
            if x%10 == 3:
                print(" %d"%i,end = "")
                break
            x //= 10
print()


Measured memory_bytes: 5872
use proconio::input;
use fixedbitset::FixedBitSet;

struct Solve {
    n: usize,
    m: usize,
    x: usize,
    c: Vec<usize>,
    a: Vec<Vec<usize>>,
}

impl Solve {
    fn new() -> Self {
        input! {
            n: usize, m: usize, x: usize,
            ca: [[usize; m+1]; n],
        }

        let mut c = Vec::with_capacity(n);
        let mut a = Vec::with_capacity(n);

        for i in 0..n {
            c.push(ca[i][0]);
            a.push(ca[i][1..m+1].to_owned());
        }

        Self { n, m, x, c, a }
    }

    fn check(&self, flag: &FixedBitSet) -> isize {
        let mut check = vec![0; self.m];
        let mut cost = 0;
        for i in 0..self.n {
            if flag[i] {
                cost += self.c[i];
                for j in 0..self.m {
                    check[j] += self.a[i][j];
                }
            }
        }
        for x in check {
            if x < self.x {
                return -1;
            }
        }
        cost as isize
    }

    fn dfs(&self, mut flag: FixedBitSet, bit: usize, enabled: bool) -> isize {
        if bit == self.n {
            return self.check(&flag);
        }

        flag.set(bit, enabled);

        let a = self.dfs(flag.clone(), bit+1, true);
        let b = self.dfs(flag.clone(), bit+1, false);

        if a == -1 && b == -1 {
            -1
        } else if a == -1 {
            b
        } else if b == -1 {
            a
        } else {
            a.min(b)
        }
    }

    fn solve(&self) -> isize {
        let flag = FixedBitSet::with_capacity(self.n);
        let a = self.dfs(flag.clone(), 0, true);
        let b = self.dfs(flag.clone(), 0, false);

        if a == -1 && b == -1 {
            -1
        } else if a == -1 {
            b
        } else if b == -1 {
            a
        } else {
            a.min(b)
        }
    }
}

fn main() {
    println!("{}", Solve::new().solve());
}


Measured memory_bytes: 2200
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string.h>
#include <set>
#include <algorithm>
using namespace std;
int main(){
   int N,A;
   cin>>N; cin>>A;
   cout<<N*N-A<<endl;
   return 0;
}

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


int MOD=1000000007;


int main(){
	int N,A;
  cin >> N >> A;
  long long d[N+10][N+10][2510],ans=0;
  vector<int> x(N);
  for(int i=0; i<N; i++) cin >> x[i];
 
  d[0][0][0] = 1;
  for(int i = 0; i < N; i++){ 
    for(int j = 0; j < N; j++){ 
      for(int k = 0; k < 2510; k++){ 
	d[i+1][j][k]+=d[i][j][k];

	d[i+1][j+1][k+x[i]]+=d[i][j][k];
      }
    }
  }
 
  for(int i = 1; i<=N; i++){
    ans += d[N][i][i*A];
  }
 
  cout << ans << endl;
}

Measured memory_bytes: 61696
#include <stdio.h>
#define mod 1000000007
typedef long long ll;

int main(void) {
  ll i, j, n, ans = 1;
  scanf("%lld", &n);
  ll t[n], a[n];
  bool bt[n], ba[n];
  for(i = 0; i < n; ++i) scanf("%lld", &t[i]), bt[i] = false;
  for(i = 0; i < n; ++i) scanf("%lld", &a[i]), ba[i] = false;
  bt[0] = ba[n - 1] = true;
  for(i = 1; i < n; ++i) if(t[i] != t[i - 1]) bt[i] = true;
  for(i = n - 2; i >= 0; --i) if(a[i] != a[i + 1]) ba[i] = true;
  for(i = 0; i < n; ++i) {
    if(bt[i] && ba[i]) {
      if(a[i] != t[i]) ans = 0;
    } else if(bt[i]) {
      if(t[i] > a[i]) ans = 0;
    } else if(ba[i]) {
      if(a[i] > t[i]) ans = 0;
    } else {
      ans *= a[i] < t[i] ? a[i] : t[i];
    }
    ans %= mod;
  }
  printf("%lld", ans);
  return 0;
}

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

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;

int MOD=1e9+7;
ll INF=1e18;

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

int main(){
    int n, d, x; cin>>n>>d>>x;
    for(int i=0; i<n; i++){
        int a; cin>>a;
        for(int j=1; j<=d; j+=a) x++;
    }
    cout << x << endl;
}

Measured memory_bytes: 256
def main():
    s = input()
    t = input()

    len_s = len(s)
    len_t = len(t)

    # dp[i][j] = the maximum length of common part of s[:i] and t[:j]
    dp = [[0] * (len_t + 1) for _ in range(len_s + 1)]
    for i in range(1, len_s + 1):
        for j in range(1, len_t + 1):
            if s[i-1] == t[j-1]:
                dp[i][j] = dp[i-1][j-1] + 1
            else:
                dp[i][j] = max(dp[i-1][j], dp[i][j-1])

    i, j = len_s, len_t
    ans = ''
    while dp[i][j] > 0:
        while dp[i-1][j] == dp[i][j]:
            i -= 1
        while dp[i][j-1] == dp[i][j]:
            j -= 1

        ans += s[i-1]
        i -= 1
        j -= 1

    print(ans[::-1])

main()


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

int main(void){
    int k=1;
    char s[100];
    cin >> k;
    cin >> s;
    int count=0;

    int judge=0;
    while(judge==0){
        if(s[count]!='\0'){
            count++;
        }else{
            judge=1;
        }
    }

    if(count<=k){
        cout << s << endl;
    }else{
        for(int i=0;i<k;i++){
            cout << s[i];
        }
        cout << "..." << endl;
    }
}


Measured memory_bytes: 3616
#include <iostream>
#include <set>
#include <vector>
#include <utility>

using namespace std;

#define FOR(i,n) for(int i=0; i<n; i++)
#define FOR2(i, z, n) for(int i=z; i<n; i++)

int find_index(vector<int> &subsequence, int length, int start, int value) {
  while(length - start > 1) {
    int medium = start + (length - start) / 2;
    if (subsequence[medium] >= value)
      length = medium;
    else
      start = medium;
  }
  return length;
}

int main() {
  int nbr;
  cin >> nbr;
  vector<int> sequence(nbr);
  vector<int> subsequence(nbr, 0);
  int length = 1;

  FOR(i, nbr) {
    int val;
    cin >> val;
    sequence[i] = val;
  }

  subsequence[0] = sequence[0];

  for (int i = 1; i < sequence.size(); i++) {
    if (sequence[i] < subsequence[0])
      subsequence[0] = sequence[i];
    else if (sequence[i] > subsequence[length - 1])
      subsequence[length++] = sequence[i];
    else {
      subsequence[find_index(subsequence, length - 1, -1, sequence[i])] = sequence[i];
    }
  }

  cout << length << endl;
}


Measured memory_bytes: 3588
#include <iostream>
#include <string>
#include <cstdlib>
using namespace std;


void change(string s, string &tmp){
	int pos = 0, count;
	char c;
	while(pos < s.size())
	{
		count = 0;
		c = s[pos];
		for(; pos < s.size(); pos++)
		{
			if(c == s[pos])
			{
				count++;
			}
			else
			{
				break;
			}
		}
		char num[20];
		sprintf(num, "%d", count);
		tmp += num;
		tmp += c;
	}
}


int main(){
	int n;
	string s;
	
	while(cin>>n, n){
		cin>>s;
		while(n--){
			string tmp;
			change(s, tmp);
			s = tmp;
		}
		cout<<s<<endl;
	}	
	return 0;
}

Measured memory_bytes: 0
def inpf() a=gets.chomp.split(" ").map(&:to_f)end

def inps() a=gets.chomp.split(" ")end

def copy(a) Marshal.load(Marshal.dump(a)) end

def kaijo(n,r = 10**9+7)(n < 2)? 1 : (2..n).inject{|memo,u|memo=(memo*u)%r} end

def na(n,d=0) Array.new(n,d)end

def na2(n,m,d=0) Array.new(n){Array.new(m,d)}end

def na3(n,m,l,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end

def inp() a=gets.chomp.split(" ").map(&:to_i)end

def r_up(a, b) (a+b-1)/b end

def sum(a) a.inject(:+) end

h, w = inp
n = inp[0]
a = inp
s  = []
a.each.with_index do |d,i|
  s += [(i+1)] * d
end
c = 0
ans = na2(h,w,"")
h.times do |i|
  w.times do |j|
    j=w-1-j if(i.even?)
    ans[i][j] = s[c]
    c += 1
  end
end
ans.each do |aa|
  puts aa.join(" ")
end

Measured memory_bytes: 50100
import java.io.IOException;
import java.util.*;

class Main {
    static int count;
    public static void sort(int[] A,int left,int mid,int right){
        int i,j,k;
        int n1=mid-left;
        int n2=right-mid;
        int[] L=new int[n1+1];
        int[] R=new int[n2+1];
          
        for(i=0;i<n1;i++){
            L[i]=A[left+i];
        }
        for(i=0;i<n2;i++){
            R[i]=A[mid+i];
        }
        L[n1]=Integer.MAX_VALUE;
        R[n2]=Integer.MAX_VALUE;
        i=0;
        j=0;
           
        for(k=left;k<right;k++){
            if(L[i]<=R[j]){
                A[k]=L[i++];
            }
            else{
                A[k]=R[j++];
            }
            count++;
        }  
    }
   
    public static void margesort(int[] A,int left,int right){
        if(left+1 < right){
            int mid=(left+right)/2;
            margesort(A,left,mid);
            margesort(A,mid,right);
            sort(A,left,mid,right);
        }
    }
   
    public static void main(String[] args) throws IOException{
        int[] A;
        Scanner scan = new Scanner(System.in);
        int a=scan.nextInt();
        A=new int[a];
        for(int i=0;i<a;i++){
            A[i]=scan.nextInt();
        }

        margesort(A,0,a);
           
        for(int i=0;i<a;i++){
            if(i<a-1) System.out.print(A[i]+" ");
            else System.out.println(A[i]);
        }
        System.out.println(count);
    }   
}

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

int main() {

	//float A, B, H, M,kaku;

	char a;
	cin >> a;

	if (isupper(a)) {
		cout << "A" << endl;
	}
	else
	{
		cout << "a" << endl;
	}

	return 0;

}



Measured memory_bytes: 3592
s = input()
k = int(input())

n = len(s)
array = []

for i in range(n):
    for j in range(i + 1, i + 6):
        end = min(n, j)
        ss = s[i:end]
        array.append(ss)

array = set(array)
array = sorted(array)
print(array[k - 1])


Measured memory_bytes: 4964
#include <stdio.h>

int main(){
  int a[100],i,j,rank[100],n,w,x,y,z,game;

  scanf("%d",&n);
  for(i = 0 ; i < n ; i++){
    a[i] = 0;
    rank[i] = 1;
  }
  game = n * (n - 1) / 2;
  for(i = 0 ; i < game ; i++){
    scanf("%d%d%d%d",&w,&x,&y,&z);
    if(y > z)
      a[w-1] += 3;
    else if(y == z){
      a[w-1] += 1;
      a[x-1] += 1;
    }
    else a[x-1] += 3;
  }
  for(i = 0 ; i < n ; i++){
    for(j = 0 ; j < n ; j++){
      if(a[i] < a[j])
	rank[i]++;
    }
    printf("%d\n",rank[i]);
  }
  return 0;
}

Measured memory_bytes: 600
import java.util.Scanner;

public class Main {

    public static void main(String[] args){

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[][] a = new int[2][n];
        for(int i=0; i<2; i++) {
            for(int j=0; j<n; j++) {
                a[i][j] = sc.nextInt();
            }
        }
        int res = 0;
        for(int x=0; x<n; x++) {
            int sum = 0;
            for(int i=0; i<=x; i++) {
                sum += a[0][i];
            }
            for(int i=x; i<n; i++) {
                sum += a[1][i];
            }
            res= Math.max(sum, res);
        }
        System.out.println(res);
    }

}


Measured memory_bytes: 21844
import java.util.Map;
import java.util.Scanner;

public class Main {

    /**
     * 本処理を実行します。
     */
    public static void execute() {
        Scanner sc = new Scanner(System.in);

        int n = nextInt(sc);
        int m = nextInt(sc);

        int okAnswer = n - m;
        int result = 1900 * m * (int)Math.pow(2, m) + (okAnswer * 100 * (int)Math.pow(2, m));

        out(result);

    }

    /**
     * 次の標準入力をintで受け取ります。
     * @return 標準入力値(int)
     */
    public static int nextInt(Scanner sc) {
        return sc.nextInt();
    }

    /**
     * 次の標準入力をStringで受け取ります。
     * @return 標準入力値(String)
     */
    public static String nextString(Scanner sc) {
        return sc.next();
    }

    /**
     * 次の標準入力を指定回数分intで受け取ります。
     * @param n 取得回数
     * @return 取得した標準入力値の配列(int)
     */
    public static int[] nextInts(Scanner sc, int n) {
        int[] arr = new int[n];

        for (int i = 0; i < n; i++) {
            arr[i] = nextInt(sc);
        }

        return arr;
    }

    /**
     * 標準出力にオブジェクトを出力します。
     * @param o 出力対象
     */
    public static void out(Object o) {
        System.out.println(o);
    }

    public static void main(String[] args) {
        execute();
    }

    public static void putCountMap(Map<Integer, Integer> map, int value) {
        if (map.containsKey(value)) {
            map.put(value, map.get(value) + 1);
        } else {
            map.put(value, 1);
        }
    }
}

Measured memory_bytes: 21844
#include <iostream>
#include <string>
#include <cstdio>

#include <algorithm>
#include <vector>
using namespace std;



int main()
{
	
	int h = 0;
	int w = 0;

	cin >> h >> w;

	const int MAX_HEIGHT = 100;
	const int MAX_WIDTH = 100;
	

	string str1[MAX_HEIGHT];
	string str2[MAX_HEIGHT*2];


	for (int i = 0; i < h; i++) {
		cin >> str1[i];

	}

	//(i+1)/2,j

	//座標計算
	for (int i = 1; i <= h * 2; i++) {


		int x = (i+1)/ 2 -1 ;//配列は0はじまり

		char temp;
		for (int j = 0; j < w; j++) {
			temp = str1[x][j];
			str2[i-1] += temp;
		}
	}
	
	for (int i = 0; i < 2 * h; i++) {

		cout << str2[i] << endl;
	}


	return 0;


}


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

int main(void) {
    int N;
    cin >> N;
    vector< int > A(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }
    bool ok = true;
    for (int i = 0; i < N; i++) {
        if (A[i] % 2 == 0) {
            if (A[i] % 3 != 0 && A[i] % 5 != 0) {
                ok = false;
                break;
            }
        }
    }
    if (ok) {
        printf("APPROVED\n");
    } else {
        printf("DENIED\n");
    }
    return 0;
}


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

typedef long long ll;

int main() {
	int a, b;
	cin >> a >> b;
	int cnt = 0;
	int value = 0;
	while (b > 0 && a > 0) {
		//cnt++;
		value += (b % 10) * pow(10.0000001,cnt);
		b /= 10;
		cnt++;
		if (b == 0) {
			while (a > 0) {
				//cnt++;c
			//	cout << value << endl;
				value += (a % 10) * pow(10 + 0.0000001,cnt);
				a /= 10;
				cnt++;
			}
		}
		//cout << value << endl;
	}
	int k = sqrt(value);
	if (k * k == value) {
		cout << "Yes";
	}else {
		cout << "No";
	}
}


Measured memory_bytes: 384
#include<iostream>

using namespace std;

int compare_by_a(const void* a, const void* b){
    typedef pair<int, int> mypair;
    return ((mypair*)a)->first -((mypair*)b)->first;
}

int main(){
    int N ,M;
    cin >> N >> M ;
    typedef pair<long, int > store;
    store data[N];

    for(int i = 0; i<N;i++){
        cin >> data[i].first >> data[i].second ;
    }

    qsort(data, N, sizeof(store), compare_by_a);

    int n=0;  //本数
    int store_n=0;
    long sum=0;
    int add;
    while( 0 < M ){
        if( data[store_n].second <= M ){
            add = data[store_n].second;
        }
        else{
            add = M;
        }
        sum += data[store_n].first * add;

        M -= add;
        store_n ++;
    }

    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 3324
#include <bits/stdc++.h>
 
#define rep(i,n) for(ll i=0;i<n;++i)
#define all_map(pos,mp) for(ll pos=mp.begin();pos!=mp.end();pos -++)
#define ALL(a) (a).begin(),(a).end()

using namespace std;
using ll  = long long;
using pll = pair<ll, ll>;

const ll MOD  = 1e9 + 7;
const ll LINF = 1LL << 62;
const int INF = 1e9 + 7;

int main(){
    ll n;
    cin >> n;

    vector<ll> a(n);
    rep(i, n)cin >> a[i];

    reverse(ALL(a));

    vector<ll> dp(n, INF);

    rep(i, n){
        ll pos = upper_bound(ALL(dp), a[i]) - dp.begin();

        dp[pos] = a[i];
    }

    ll ans = lower_bound(ALL(dp), INF) - dp.begin();

    cout << ans << endl;
}

Measured memory_bytes: 4840
#include <iostream>

int main()
{
  unsigned long long x;
  std::cin >> x;
  
  unsigned long long yen = 100;
  int year = 0;
  while(yen < x)
  {
    ++year;
    yen = (unsigned long long)(yen * 1.01);
  }
  
  std::cout << year << std::endl;
  return 0;
}


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

int main(){
	unsigned long long s,p=-1;
	cin>>s;
	unsigned long long ts=s;
	while(ts){
		ts/=10;
		++p;
	}
	unsigned long long ans=0;
	for(int i=0,k;i<(1<<p);++i){
		ts=s,k=10;
		for(int j=0;j<p;++j){
			if(i&(1<<j)){
				ans+=ts%k;
				ts/=k;
				k=1;
			}
			k*=10;
		}
		ans+=ts;
	}
	cout<<ans<<"\n"s;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const ll inf =1LL << 62;
const ll mod=1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b,const ll &mod) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b,const ll &mod) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b,const ll &mod) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b,const ll &mod) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
random_device rd;
mt19937 mt(rd());
uniform_int_distribution<int> dice(1,6);
uniform_real_distribution<double> score(0.0,10.0);

using vvi = vector<vi>;
const int kMax_n = 1001; //頂点数の最大値

int n; //頂点数
vvi G(kMax_n);
vi match(kMax_n); //マッチングのペア
vi used(kMax_n);

// uとvを結ぶ辺をグラフに追加する
void add_edge(int u, int v){
    G[u].push_back(v);
    G[v].push_back(u);
}

// 増加パスをDFSで探す
bool dfs(int v){
    used[v] = true;
    
    for(auto u : G[v]){
        int w = match[u];

        if(w < 0 || (!used[w] && dfs(w))){
            match[v] = u;
            match[u] = v;

            return true;
        }
    }

    return false;
}

//二分グラフの最大マッチングを求める
int b_match(void){
    int res = 0;

    fill(_all(match), -1);

    rep(i, n){
        if(match[i] < 0){
            fill(_all(used), false);

            if(dfs(i)) res++;
        }
    }

    return res;
}

void init_G(void){
    for(auto & g : G) g.clear();
}

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

    init_G();
    int m; cin >> m;
    n = 2 * m;
    vi a(n), b(n);
    rep(i, n){
        cin >> a[i] >> b[i];
    }

    rep(i, m){
        rep(_, m){
            int j = m + _;
            if(a[i] < a[j] and b[i] < b[j]){
                add_edge(i, j);
            }
        }
    }

    cout << b_match() << endl;

    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <climits>
#include <algorithm>

// namespace
using namespace std;

int main() {
    long long dist[105][105];
    for (int i = 0; i < 105; ++i)  {
        for (int j = 0; j < 105; ++j) {
            dist[i][j] = INT_MAX;
            if (i == j) dist[i][j] = 0;
        }
    }
    int v, e, s, t, d;
    cin >> v >> e;
    for (int i = 0; i < e; ++i) {
        cin >> s >> t >> d;
        dist[s][t] = d;
    }

    // cout << " debug1" << endl;
    for (int k = 0; k < v; ++k) {
        for (int i = 0; i < v; ++i) {
            for (int j = 0; j < v; ++j) {
                // cout << i << " " << k  << " " << j << endl;
                if (dist[i][k] != INT_MAX && dist[k][j] != INT_MAX)
                    dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
            }
        }
    }
    // cout << " debug2" << endl;

    for (int i = 0; i < v; ++i) {
        if (dist[i][i] < 0) {
            cout << "NEGATIVE CYCLE" << endl;
            return 0;
        }
    }
    // cout << " debug3" << endl;
    for (int i = 0; i < v; ++i) {
        for (int j = 0; j < v; ++j) {
            if (dist[i][j] == INT_MAX) cout << "INF" << (j != v - 1 ? " " : "");
            else cout << dist[i][j] << (j != v - 1 ? " " : "");
        }
        cout << endl;
    }
    return 0;
}



Measured memory_bytes: 3208
n, k = map(int, input().split())
D = set(input().split())
use = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'}
use -= D
use = list(use)
l = len(str(n))

ans = use.copy()
prev = use.copy()
digit = 0
while digit <= l:
    temp = []
    for x in prev:
        for v in use:
            temp.append(x+v)
    ans += temp
    prev = temp
    digit += 1

ans = list(map(int, ans))
ans.sort()

for num in ans:
    if num >= n:
        print(num)
        break

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

int main(){
    int N, M;
    int sum = 0;

    cin >> N >> M;
    std::vector<int> data(N);

    for(int i = 0; i < N; i++){
        cin >> data.at(i);
        sum += data.at(i);
    }

    double th = sum*1.0/(4*M);
    int count=0;
    for(int i = 0; i < data.size(); i++){
        if(data[i] >= th) count++;
    }
    if(count >= M){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
N,M = map(int, input().split())

min_id = 0
max_id = N+1
for i in range(M):
    l, r = map(int, input().split())
    if min_id < l:
        min_id = l
    if max_id > r:
        max_id = r

result = max_id - min_id
if result < 0:
    print(0)
else:
    print(result+1)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define REP(i,s,e) for(int i=(s); i<(e);i++)
#define rep(i,n) REP(i,0,n)
#define rep1(i,n) REP(i,1,n)
#define repe(i,n) for(auto &&i:n)
#define all(v) (v).begin(),(v).end()
#define decimal fixed<<setprecision(20)
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)
using namespace std;
using LL = long long;
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 = 1e9;
const LL LLINF = 1e16;

int main(){
    string s;
    cin >> s;
    bool ans = 1;
    rep(i, s.size()){
        if(i%2 == 0){
            if(s[i] == 'L') ans = 0;
        }
        else{
            if(s[i] == 'R') ans = 0;
        }
    }
    cout << (ans ? "Yes" : "No") <<endl;

}

Measured memory_bytes: 256
n, m, c = map(int, input().split())

b = [int(x) for x in input().split()]
ans = 0
for i in range(n):
    a = [int(x) for x in input().split()]
    cnt = c
    for aa, bb in zip(a, b):
        cnt += aa * bb
    if cnt > 0: ans += 1
print(ans)

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


int main(void)
{ int n,a[1000],b[1000],c[1000],t;
	scanf("%d",&n);
	for(t=0;t<n;t++){
		scanf("%d %d %d",&a[t],&b[t],&c[t]);
	}
	
	for(t=0;t<n;t++){
		if((a[t] == hypot(b[t],c[t])) ||( b[t] == hypot(a[t],c[t])) || (c[t] == hypot(a[t],b[t]))){
			printf("YES\n");
		}
		else{
			printf("NO\n");
		}
	}
	
	return 0;
}

Measured memory_bytes: 604
#include <vector>
#include <iostream>
#include <cmath>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <fstream>
#include <unistd.h>
#include <string.h>
#include <string>
#include <numeric>
#include <queue>
#include <deque>
#include <sstream>
#include <iomanip>
#include <set>
#include <stack>
#include <cassert>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vvb> vvvb;
typedef vector<vvvb> vvvvb;
typedef vector<string> vs;
typedef vector<vs> vvs;
typedef vector<vvs> vvvs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<vvd> vvvd;
typedef pair<ll, ll> PL;
typedef vector<PL> vpl;
typedef vector<vector<PL>> vvpl;
const int INF = 1001001001;
const ll LINF = 1e17;
const double pi = 3.1415926535897932;
const string endstr = "\n";
#define FOR(i, a, b) for(ll i = (a); i < b; i++)
#define RFOR(i, a, b) for(ll i = (a); i > b; i--)
#define rep(i, n) for(ll i = 0; i < n; i++)
#define rrep(i, n) for(ll i = n-1; i > -1; i--)
#define FORMAP(it, m) for(auto it = m.begin(); it != m.end(); it++)
#define ff first
#define ss second
#define pb push_back
#define epb emplace_back
#define ALL(X) (X).begin(),(X).end()

template <typename T>
T gcd(T a, T b) {
    return (a == 0) ? b : gcd(b%a, a);
}
template <typename T>
T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}

bool p_comp_fs(const PL p1, const PL p2){ return p1.first < p2.first;};
bool p_comp_fg(const PL p1, const PL p2){ return p1.first > p2.first;};
bool p_comp_ss(const PL p1, const PL p2){ return p1.second < p2.second;};
bool p_comp_sg(const PL p1, const PL p2){ return p1.second > p2.second;};
template <typename T>
vector<T> uniquen(vector<T> vec){
    sort(ALL(vec));
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
    return vec;
}

inline ll popcnt(ll x){return __builtin_popcountll((unsigned long long)x);};
template<class T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
//friend bool operator<(const stc& lhs, const stc& rhs){
//    return std::tie(lhs.l, lhs.r) < std::tie(rhs.l, rhs.r);
//}

const ll mod = 1e9+7;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    ll N, K; cin >> N >> K;
    vl A(N); rep(i, N) cin >> A[i];
    
    ll ans = 0;
    rep(i, N){
        ll now = A[i];
        ll tot = 0;
        rep(j, N) if(A[j] < now) tot++;
        ll a = 0;
        FOR(j, i+1, N) if(A[j] < now) a++;
        ans = (ans + a*K%mod + (K*(K-1)/2)%mod*tot%mod)%mod;
    }
    cout << ans%mod << endstr;
    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll (i) = 0; (i) < (n); (i)++)
#define rep1(i, n) for(ll (i) = 1; (i) <= (n); (i)++)
#define rrep(i, n) for(ll (i) = (n) - 1; (i) >= 0; (i)--)
#define rrep1(i, n) for(ll (i) = (n); (i) >= 1; (i)--)
const ll INF = 1145141919;
const ll MOD = 1000000007;
template<class T> void chmax(T &a, const T &b){if(a < b){a = b;}}
template<class T> void chmin(T &a, const T &b){if(a > b){a = b;}}

ll A[20];
ll x[20][20];
ll y[20][20];

int main(){

    ll N;
    cin >> N;
    rep(i, N){
        cin >> A[i];
        rep(j, A[i]){
            cin >> x[i][j] >> y[i][j];
            x[i][j]--;
        }
    }
    ll ans = 0;
    rep(i, 1 << N){
        ll flg = 1;

        rep(j, N)if(i & (1 << j))rep(k, A[j]){
            ll p = x[j][k];
            ll s = y[j][k];
            ll t = (0 != (i & (1 << p)));
            if(s != t)flg = 0;
        }
        
        ll cnt = 0;
        rep(j, N)if(i & (1 << j))cnt++;
        if(flg)chmax(ans, cnt);
    }
    cout << ans << endl;

    return 0;
}

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

bool isPrime(ll num){
    if(num < 2) return false;
    else if(num == 2) return true;
    else if (num % 2 == 0) return false;

    long double sqrtN = sqrt(num);
    for(ll i = 3; i <= sqrtN; i += 2){
        if(num % i == 0) return false;
    }
    return true;
}

int main(){
    ll x; cin >> x;
    for(ll i = x; ; i++){
        if(isPrime(i)){
            cout << i << endl;
            return 0;
        }
    }


}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define all(v) (v).begin() , (v).end()
#define popcnt(x) __builtin_popcount(x)
#define inf 0x3f3f3f3f
#define watch(x) cout << (#x) << " is " << (x) << endl
#define rand() (rand() << 15 | rand())
using namespace std;
typedef long long  ll;

int main(){
    ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0);
    int n , m;
    cin >> n >> m;
    int mn = 0 , mx = 1e9;
    for(int i = 0 ; i < m ; ++i){
        int l , r;
        cin >> l >> r;
        mn = max(l , mn);
        mx = min(mx , r);
    }

    cout << max(0 , mx - mn + 1) << endl;
}


Measured memory_bytes: 256
//============================================================================
// Name        : Hello5.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <vector>
#include <bits/stdc++.h>
#include <numeric>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using p = pair<int,int>;//<key,value>


int main() {
int n,m,l;
cin>>n;
for (m = 1; m <= 9; ++m)for (l = 1; l <=9; ++l) {
if(n==m*l){
	cout<<"Yes"<<endl;
	return 0;
}}
cout<<"No"<<endl;


return 0;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n,m,a[109],r[109],b[109],sum[109],sumr,sumb;
bool cmp(int x,int y){return x>y;}
int f[69][69][3009];

//f[i][j][k]表示r匹配到i，b匹配到j，与r匹配的a之和为k 

int main() {
	scanf("%d%d",&n,&m);sum[0]=sumr=sumb=0;
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
	for(int i=1;i<=m;i++) scanf("%d",&r[i]);
	for(int i=1;i<=m;i++) scanf("%d",&b[i]);
	sort(a+1,a+n+1,cmp);
	sort(r+1,r+m+1,cmp);sort(b+1,b+m+1,cmp);
	for(int i=1;i<=n;i++) sum[i]=sum[i-1]+a[i];
	for(int i=1;i<=m;i++) sumr+=r[i],sumb+=b[i];
	memset(f,-1,sizeof(f));
	f[0][0][0]=0;int ans=-1;
	for(int i=0;i<=m;i++){
		for(int j=0;j<=m;j++){
			if(i+j>n) continue;
			for(int k=0;k<=sum[i+j];k++){
				if(f[i][j][k]==-1) continue;
				if(i+j==n){
					if(sumr>=k&&sumb>=sum[n]-k) ans=max(ans,f[i][j][k]+sumr+sumb-sum[n]);
					continue;
				} 
				if(sumr>=k+a[i+j+1]&&i<m) f[i+1][j][k+a[i+j+1]]=max(f[i+1][j][k+a[i+j+1]],f[i][j][k]+min(a[i+j+1],r[i+1]));
				if(sumb>=sum[i+j+1]-k&&j<m) f[i][j+1][k]=max(f[i][j+1][k],f[i][j][k]+min(a[i+j+1],b[j+1])); 
			}
		}
	}
	printf("%d\n",ans==-1?ans:(sumr+sumb-ans));	
	return 0;
}



Measured memory_bytes: 59236
#include <iostream>
#include <stdio.h>
using namespace std;
int main(void){
    int n,m;
    scanf("%d %d",&n,&m);
    int c=0;
    
    int A[n][m];
    int B[m];
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            scanf("%d",&A[i][j]);
        }
    }
    
    
    for(int i=0;i<m;i++){
        scanf("%d",&B[i]);
    }
    
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            c+=A[i][j]*B[j];
        }
        cout<<c<<endl;
        c=0;
    }
    
    return 0;
}



Measured memory_bytes: 3236
// -----------------------------------------------
// Framework <https://github.com/vain0x/procon>
//
// See the bottom of file for solution.
// -----------------------------------------------

#![allow(unused_imports)]
#![allow(non_snake_case)]

use std::cell::RefCell;
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::fmt::{Debug, Formatter, Write as FmtWrite};
use std::io::{stderr, stdin, BufRead, Write};
use std::mem::{replace, swap};
use std::ops::*;
use std::rc::Rc;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), stderr());
            writeln!(err, "\x1B[33m{}\x1B[0m = {:?}", e, $e).unwrap()
        })*
    };
}

#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

#[allow(dead_code)]
fn rl() -> String {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    buf.trim_right().to_owned()
}

// -----------------------------------------------
// Solution
// -----------------------------------------------

fn main() {
    let X = read!(i32);
    println!(
        "{}",
        if X == 7 || X == 3 || X == 5 {
            "YES"
        } else {
            "NO"
        }
    )
}


Measured memory_bytes: 4352
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<limits>
#include<set>
#include<queue>
using namespace std;
#define int long  long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

signed main()
{
	int N, L;
	cin >> N >> L;
	vector<int>v(N);
	int sum = 0;
	rep(i, N)
	{
		v[i] = L + i;
		sum += v[i];
	}
	int a = 1e5;
	rep(i, N)if (abs(a) > abs(v[i]))a = v[i];
	cout << sum - a;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int inf=0x3f3f3f3f;
const int MOD=1e9+7;
int par[100005],ranks[100005],ans[100005];
void init(int n)
{
	for(int i=0;i<n;i++)
	{
		par[i]=i;
		ranks[i]=1;
	}
}
int find(int x)
{
	if(par[x]==x)
	return x;
	else
	return par[x]=find(par[x]);
}
void Union(int x,int y)
{
	x=find(x);y=find(y);
	if(x==y) return ;
	if(ranks[x]<ranks[y])
	swap(x,y);
	par[y]=x;
	ranks[x]+=ranks[y];
}
int size(int x)
{
	return ranks[find(x)];
}
int main()
{
	int n,m,k;cin>>n>>m>>k;
	vector<int> friends[n];
	vector<int> block[n];
	int x,y;
	memset(ans,0,sizeof(ans));
	init(n);
	for(int i=0;i<m;i++)
	{
		cin>>x>>y;
		x--;y--;
		Union(x,y);
		friends[x].push_back(y);
		friends[y].push_back(x);
	}
	for(int i=0;i<k;i++)
	{
		cin>>x>>y;
		x--,y--;
		block[x].push_back(y);
		block[y].push_back(x);
	}
	for(int i=0;i<n;i++)
	{
		ans[i]=size(i)-1;
		for(auto x:block[i])
		{
			if(find(i)==find(x))
			ans[i]--;
		}
		for(auto x:friends[i])
		{
			if(find(i)==find(x))
			ans[i]--;
		}
		cout<<ans[i]<<' ';
	}
	cout<<endl;
}

Measured memory_bytes: 13048
#include<iostream>
#include<cstdio>
#include<algorithm>

using namespace std;
#define MAX 100005
#define NIL -1

typedef struct{
  int parent;
  int left;
  int right;
}Node;

Node T[MAX];
int n,D[MAX],H[MAX];

void setDepth(int u,int d){
  if(u==NIL)return;
  D[u]=d;
  setDepth(T[u].left,d+1);
  setDepth(T[u].right,d+1);
}

int setHeight(int u){
  int h1=0;
  int h2=0;
  
  if(T[u].left!=NIL) h1= setHeight(T[u].left)+1;
  if(T[u].right!=NIL) h2=setHeight(T[u].right)+1;

  return H[u]=max(h1,h2);
}

int getSibling(int u){
  if(T[u].parent==NIL)return NIL;
  if(T[T[u].parent].left!=u&&T[T[u].parent].left!=NIL) return T[T[u].parent].left;
  if(T[T[u].parent].right!=u&&T[T[u].parent].right!=NIL) return T[T[u].parent].right;
  return NIL;
}

void print(int u){
  cout<<"node "<<u;
  cout<<": parent = "<<T[u].parent;
  cout<<", sibling = "<<getSibling(u);

  int deg=0;
  if(T[u].left!=NIL)deg++;
  if(T[u].right!=NIL)deg++;
  cout<<", degree = "<<deg;
  cout<<", depth = "<<D[u];
  cout<<", height = "<<H[u];

  if(T[u].parent==NIL){
    cout<<", root"<<endl;
  }else if(T[u].left==NIL&&T[u].right==NIL){
    cout<<", leaf"<<endl;
  }else{
    cout<<", internal node"<<endl;
  }
}

int main(){
  int n,id,left,right;
  int root=0;

  cin>>n;

  for(int i=0;i<n;i++){
    T[i].parent=NIL;
  }

  for(int i=0;i<n;i++){
    cin>>id>>left>>right;
    T[id].left=left;
    T[id].right=right;
    if(left!=NIL)T[left].parent=id;
    if(right!=NIL)T[right].parent=id;
  }

  for(int i=0;i<n;i++){
    if(T[i].parent==NIL){
      root=i;
    }
  }

  setDepth(root,0);
  setHeight(root);

  for(int i=0;i<n;i++) print(i);

  return 0;

}

Measured memory_bytes: 1168
#include <stdio.h>


int main()
{
  int a, b, c, cnt=0;

  scanf("%d %d %d", &a, &b, &c);

  for (int i=a; i<=b; ++i)
    {
      if (c%i == 0) ++cnt;
    }

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

  
  return 0;
}



Measured memory_bytes: 2760
import bisect

N, K = map(int, raw_input().split())
V = map(int, raw_input().split())

score = -1e100

M = min(N, K)
for A in range(0, M + 1):
    for B in range(0, M - A + 1):
        S = []
        if A > 0:
            S += V[:A]
        if B > 0:
            S += V[-B:]
        S.sort()
        score = max(score, sum(S) - sum(filter(lambda x: x < 0, S)[:max(0, K - A - B)]))

print score


Measured memory_bytes: 2688
n = gets.to_i
s = gets.chomp.chars
r = 0
g = 0
b = 0
all = 0

s.each do |i|
  r += 1 if i == "R"
  g += 1 if i == "G"
  b += 1 if i == "B"
end
all = r*g*b

for j in 0..n
   for i in 0..j
     k = j*2 -i
    if(k < n)
      next if (s[i] == s[j])
      next if (s[i] == s[k])
      next if (s[k] == s[j])
      all -= 1
    end
  end
end

puts all


Measured memory_bytes: 14640
# -*- coding: utf-8 -*-
#AGC038A
import sys
#sys.setrecursionlimit(100000)

#n=int(input())
tmp = input().split()
h,w,a,b = list(map(lambda a: int(a), tmp))



for i in range(h):
	outh=""
	if(i<b):
		for j in range(w):
			if(j<a):
				outh+="1"
			else:
				outh+="0"
#			if(j!=w-1):
#				outh+=" "
		print(outh)
	else:
		for j in range(w):
			if(j<a):
				outh+="0"
			else:
				outh+="1"
#			if(j!=w-1):
#				outh+=" "
		print(outh)




Measured memory_bytes: 3956
import sys
readline = sys.stdin.readline
sys.setrecursionlimit(10**8)
#mod = 10**9+7
#mod = 998244353
#INF = 10**18
#eps = 10**-7

def main():
    N,K = map(int,readline().split())
    A = list(map(int,readline().split()))
    F = list(map(int,readline().split()))
    A.sort()
    F.sort(reverse=True)
    
    ng = -1
    ok = 10**12+100
    while ok - ng > 1:
        mid = (ok + ng) // 2
        if sum(max(0,a-mid//f) for a,f in zip(A,F)) <= K:
            ok = mid
        else:
            ng = mid
    print(ok)

if __name__ == '__main__':
    main()


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

void solve () {
    int n;
    cin >> n;
    long long ans;
    long long t;
    cin >> t;
    ans += t;
    for (int i = 1; i < n - 1; i++) {
        long long x;
        cin >> x;
        ans += min (x, t);
        t = x;
    }
    ans += t;
    cout << ans;
}

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


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

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

    ll minv = a * (n - 1) + b;
    ll maxv = a + b * (n - 1);
    ll ans = maxv - minv + 1;

    cout << max(ans, 0ll) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e3+100;
typedef double db;
int n;
db p[maxn];
db dp[maxn][maxn];
int main(){
    cin>>n;
    for (int i=1;i<=n;i++){
        cin>>p[i];
    }
    dp[0][0] = 1;
    for (int i=1;i<=n;i++){
        for (int j=0;j<i;j++){
            dp[i][j] += dp[i-1][j]* (1 - p[i]);
            dp[i][j+1] += dp[i-1][j] * p[i];
        }
    }
    db ans = 0;
    for (int i=(n+1)/2;i<=n;i++){
        ans += dp[n][i];
    }
    printf("%.10lf\n",ans);
    return 0;
}

Measured memory_bytes: 72320
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=4e5+10;
int n,w[N],head[N],nxt[N];
void add(int f,int t){
	static int cnt=0;
	w[++cnt]=t;
	nxt[cnt]=head[f];
	head[f]=cnt;
}
char tp[N];
long long ans;
int mp[N],cp[N],up[N];
void dfs(int x,int fa){
    for (int i=head[x];i;i=nxt[i]){
        int v=w[i];
        if (v==fa) continue;
        dfs(v,x);
        if (up[v]>up[mp[x]]) cp[x]=mp[x],mp[x]=v;else
        if (up[v]>up[cp[x]]) cp[x]=v;
    }
    up[x]=up[mp[x]]+1;
}
int Max[N],Min[N];
void getmax(int x,int fa){
    for (int i=head[x];i;i=nxt[i]){
        int v=w[i];
        if (v==fa) continue;
        up[x]=up[v==mp[x]?cp[x]:mp[x]]+1;
        Max[v]=min(up[v]+1,up[x]);
        if (up[x]>up[mp[v]]) cp[v]=mp[v],mp[v]=x;else
        if (up[x]>up[cp[v]]) cp[v]=x;
        up[v]=up[mp[v]]+1;
        getmax(v,x);
        up[v]=up[x==mp[v]?cp[v]:mp[v]]+1;
        up[x]=up[mp[x]]+1;
    }
}
int ma[N],ci[N];
void DFS(int x,int fa){
	if (tp[x]=='0') ma[x]=ci[x]=1e9;else ma[x]=ci[x]=1;
	for (int i=head[x];i;i=nxt[i]){
		int v=w[i];
		if (v==fa) continue;
		up[x]=up[v==mp[x]?cp[x]:mp[x]]+1;
		up[v]=up[mp[v]]+1;
		DFS(v,x);
		up[v]=up[x==mp[v]?cp[v]:mp[v]]+1;
		if (tp[x]=='0'&&ma[v]<1e9){
			int R=max(ma[v],min(up[v]+2,up[x]+1));
			R=max(min(R,up[v])+1,min(R-1,up[x]));
			if (R<ma[x]) ci[x]=ma[x],ma[x]=R;else ci[x]=min(ci[x],R);
		}
		up[x]=up[mp[x]]+1;
	}
}
void getmin(int x,int fa){
	Min[x]=ma[x];
	if (Max[x]>=Min[x]) ans+=Max[x]-Min[x]+1;
	for (int i=head[x];i;i=nxt[i]){
		int v=w[i];
		if (v==fa) continue;
		up[x]=up[v==mp[x]?cp[x]:mp[x]]+1;
		if (tp[v]=='0'&&ma[x]<1e9){
			int R=max(ma[x],min(up[x]+2,up[v]+1));
			R=max(min(R,up[x])+1,min(R-1,up[v]));
			if (R<ma[v]) ci[v]=ma[v],ma[v]=R;else ci[v]=min(ci[v],R);
		}
		up[v]=up[mp[v]]+1;
		getmin(v,x);
		up[v]=up[x==mp[v]?cp[v]:mp[v]]+1;
        up[x]=up[mp[x]]+1;
	}
}
int main()
{
	scanf("%d",&n);
	for (int i=1;i<n;i++){
		int u,v;
		scanf("%d%d",&u,&v);
		add(u,v);add(v,u);
	}
	scanf("%s",tp+1);
	int root=0;
	for (int i=1;i<=n;i++)
	if (tp[i]=='1') root=i;
	dfs(root,0);getmax(root,0);Max[root]=up[root];
	DFS(root,0);getmin(root,0);
	//for (int i=1;i<=n;i++) printf("[%d,%d]\n",Min[i],Max[i]);
	printf("%lld\n",ans);
	return 0;
}

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int W,H; cin >> W >> H;
    vector<pair<ll,int>> R;
    for (int i=0;i<W;++i){
        ll p; cin >> p;
        R.emplace_back(p,0);
    }
    for (int i=0;i<H;++i){
        ll q; cin >> q;
        R.emplace_back(q,1);
    }
    sort(R.begin(),R.end());
    vector<ll> cnt(2);
    cnt[0]=W+1,cnt[1]=H+1;
    ll ans=0;
    for (int i=0;i<H+W;++i){
        ans+=cnt[R[i].second^1]*R[i].first;
        --cnt[R[i].second];
    }
    cout << ans << '\n';
}

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

using namespace std;
using ll = long long;


int main()
{
    int n;
    cin >> n;
    vector<int> pos(n);
    for(int i = 0; i < n; i++) {
        int a; cin >> a; a--; 
        pos[a] = i;
    }
    multiset<int> st;
    for(int i = 0; i < 2; i++){st.insert(-1),st.insert(n);}


    ll sum = 0;
    for(int i = n - 1; i >= 0; i--) {
        auto itr = st.lower_bound(pos[i]);
        ll l2 = *prev(itr, 2), l1 = *prev(itr, 1);
        ll r2 = *next(itr, 1), r1 = *itr;
        st.insert(pos[i]);

        ll cur = (l1 - l2) * (r1 - pos[i]);
        cur +=   (r2 - r1) * (pos[i] - l1);
        sum += cur * (i + 1);
    }
    cout << sum << endl;
}

Measured memory_bytes: 8284