akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<string>

#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<limits.h>
using ll = long long;
using namespace std;
int main(){
  ll n,ii,jj;
  cin >> n;
  vector<ll> v;
  v.resize(n);

  for(ii=0;ii<n;ii++){
    cin >> v[ii];
  }

  ll s1,s2,min=LONG_MAX;

  for(ii=0;ii<n;ii++){
    s1 = 0;
    s2 = 0;
    
    for(jj=0;jj<n;jj++){

      if(jj<=ii){
	//cout << "s1" << v[jj] << endl;
	s1 += v[jj];
      }
      else{
	//cout << "s2" << v[jj] << endl;
	s2 += v[jj];
      }

    }
    //cout << "s1:" << s1 << "s2:" << s2 << endl;

    //cout << abs(s1-s2) << endl;;
    if(min >= abs(s1-s2)){
      min = abs(s1-s2);
    }
  }
  cout << min << endl;
  return 0;
}


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

using namespace std;

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define REP(i, n) FOR(i, 0, n)
#define RFOR(i, a, b) for(int i=(a);i>=(b);i--)
#define RREP(i, n) RFOR(i, n, 0)
#define MFOR(i, m) for(auto i=(m).begin();i!=(m).end();i++)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((int)(x).size())

typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;

const double eps = 1e-10;
const int MOD = 1000000007;
const ll INF = 1ll << 50;

template<typename T>
void printv(vector<T> const& s) {
  REP(i, SZ(s)) {
    cout << s[i] << " ";
  }
  cout << endl;
}

vvll g;

void warshall_floyd() {
  int n = g.size();
  REP(i, n) {
    REP(j, n) {
      REP(k, n) {
        g[j][k] = min(g[j][k], g[j][i] + g[i][k]);
      }
    }
  }
}

signed main () {
  cin.tie(0);
  cout << setprecision(10);

  int n; cin >> n;
  vvll a(n);
  g.resize(n);
  REP(i, n) {
    g[i].resize(n);
    a[i].resize(n);
    REP(j, n) {
      cin >> g[i][j];
      a[i][j] = g[i][j];
    }
  }

  warshall_floyd();

  ll ans = 0;

  REP(i, n) {
    FOR(j, i+1, n) {
      if(a[i][j] > g[i][j]) {
        cout << -1 << endl;
        return 0;
      } else {
        bool ok = true;
        REP(k, n) {
          if(k != i && k != j && g[i][k] + g[k][j] == a[i][j]) ok = false;
        }
        if(ok) ans += a[i][j];
      }
    }
  }

  cout << ans << endl;

  
}


Measured memory_bytes: 1792
#import math
#import bisect
#import numpy as np
#import itertools
#import copy
import sys

ipti = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)

def main():
    n = int(input())

    for i in range(1, 10):
        if n % i == 0:
            temp = n // i
            if 1 <= temp <= 9:
                print('Yes')
                sys.exit()

    print('No')

if __name__ == '__main__':
    main()

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

using namespace std;

int main() {
	int n; cin >> n;
	int cnt = 0, a = 0, b = 0, ab = 0;
	for (int i = 0; i < n; ++i) {
		string s; cin >> s;
		bool f = false;
		for (int j = 0; j < s.size() - 1; ++j)
			if (s.substr(j, 2) == "AB") ++cnt;
		if (s.back() == 'A') ++a, f = true;
		if (s.front() == 'B') ++b;
		else f = false;
		if (f) ++ab;
	}
	cout << max(0, cnt + min(a, b) - (ab && ab == a && ab == b ? 1 : 0)) << endl;

	return 0;
}

Measured memory_bytes: 256
// Scc Puzzle
#include <iostream>
#include <algorithm>
using namespace std;

long long s,c;

int main(){
    cin>>s>>c;
    long long ans=0;
    ans+=min(s,c/2);
    s-=ans;
    c-=(ans*2);
    ans+=(c/4);
    cout<<ans;
    return 0;
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
int main() {
    int N;
    cin >> N;
    long long A[N],B[N];
    long long count = 0;
    rep(i,N){
        cin >> A[i] >> B[i];
    }
    for(int i=N-1;i>=0;i--){
        if((count + A[i]) % B[i] == 0) continue;
        count += B[i] - (count + A[i]) % B[i];
    }

    cout << count << endl;
} 

Measured memory_bytes: 1920
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define F first
#define S second
#define pb push_back
mt19937 rnd;


int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
#endif

    string s, t;
    cin >> s >> t;
    int n = s.size();
    for (int i = 0; i < n; i++) {
        if (s[i] != t[i]) {
            cout << "No\n";
            return 0;
        }
    }
    cout << "Yes\n";

#ifdef LOCAL
    cerr << "\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
    return 0;
}


Measured memory_bytes: 3612
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush, heapify
import math
import itertools
import random
 
# NO, PAY-PAY
#import numpy as np
#import statistics
#from statistics import mean, median,variance,stdev
 
INF = float('inf')
def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
 
def main():
    O = input()
    E = input()
    
    tmp = len(E)
    ind = 0
    
    ans = ""
    for i,val in enumerate(O):
        ans += val
        ind = i
        if tmp > i:
            ans += E[i]
        
    print(ans)
    
    
if __name__ == "__main__":
	main()


Measured memory_bytes: 38512
h, w = gets.chomp.split.map(&:to_i)

ans = h * w

def min(a,b)
  a < b ? a : b
end

def max(a,b)
  a > b ? a : b
end



# 分割は4パターンということがわかる
# HとWの大きさを入れ替えたりすれば同じやりかたでいけるので2パターンについて考察する
# たて3つに分割した場合でも、T時の場合でも一番上の大きさは同じ

#  たて
1.upto(h-1) do |i|
  s_1 = i * w
  s_2 = (w/2) * (h-i)
  s_3 = (w-w/2)* (h-i)

  s = [s_1, s_2, s_3]
  ans = min(s.max - s.min, ans)


  s_2 = ((h-i)/2) * w
  s_3 = ((h-i)-(h-i)/2)* w

  s = [s_1, s_2, s_3]


  ans = min(s.max - s.min, ans)
end



# よこ
1.upto(w-1) do |j|
  s_1 = h * j
  s_2 = (h/2) * (w-j)
  s_3 = (h-h/2)* (w-j)

  s = [s_1, s_2, s_3]
  ans = min(s.max - s.min, ans)

  s_2 = ((w-j)/2) * h
  s_3 = ((w-j)-(w-j)/2)* h

  s = [s_1, s_2, s_3]


  ans = min(s.max - s.min, ans)
end

p ans

Measured memory_bytes: 3836
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

#define _max(_x, _y) ((_x)>(_y)?(_x):(_y))
#define _min(_x, _y) ((_x)>(_y)?(_y):(_x))

int main(void)
{
long a, b, index, ans;
long x,  y;
  scanf("%ld %ld", &a, &b);
  x = _min(a, b);
  y = _max(a, b);
  for (index = 0; index < y; ++index) {
    ans += x;
    ans *= 10;
  }
  ans /= 10;
  printf("%ld\n", ans);
  
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>

using namespace std;

int main() {
  for (;;) {
    string r, a;
    cin >> r >> a;
    if (r.length() != 4) return 0;
    int H = 0, B = 0;
    for (int i = 0; i < 4; i++)
      for (int j = 0; j < 4; j++)
        if (a[i] == r[j])
          if (i == j)
            H++;
          else
            B++;
    cout << H << ' ' << B << endl;
  }
}

Measured memory_bytes: 912
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = (A); I < (B); ++I)
#define FORR(I,A,B) for(ll I = ((B)-1); I >= (A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(a%b==0)return b;return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}//saisyo kobaisu
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=1e18+7;
const ll MOD=1e9+7;
#define pri(a) cout << (a) << endl
class Seg_Tree{
public:
	vector<int> dat;
	int n;
	void initsize(int n0){
		int k=1;
		while(1){
			if(n0<=k){
				n=k;
				dat.resize(2*n-1);
				for(int i=0;i<2*n-1;i++)dat[i]=INT_MAX;
				break;
			}
			k*=2;
		}
	}

	//i banme wo x nisuru
	void update(int i,int x){
		i += n-1;
		dat[i] = x;
		while(i>0){
			i = (i-1) / 2;
			dat[i] = min(dat[i*2+1],dat[i*2+2]);
		}
	}

	//[a,b)
	int query0(int a,int b,int k,int l,int r){
		if(r<=a || b<=l)return INT_MAX;
		if(a<=l && r<=b)return dat[k];
		else{
			int vl = query0(a,b,k*2+1,l,(l+r)/2);
			int vr = query0(a,b,k*2+2,(l+r)/2,r);
			return min(vl,vr);
		}
	}

	//return min [a,b)
	int query(int a,int b){
		return query0(a,b,0,0,n);
	}
};



int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll N,x,ans=INF;
	cin >> N >> x;
	Seg_Tree sgt;
	sgt.initsize(3*N);
	vector<ll> a(N),b(N);
	FOR(i,0,N){
		cin >> a[i];
		b[i] = a[i];
	}
	FOR(xx,0,N+1){
		ll ansp = xx*x;
		FOR(j,0,N){
			ll k = (j-xx+N)%N;
			b[j] = min(b[j],a[k]);
			ansp += b[j];
		}
		ans = min(ans,ansp);
	}
	cout << ans << endl;
}

Measured memory_bytes: 384
#include <iostream>
using namespace std;
int main()
{
	int a, b, k, n = 0;
	cin >> a >> b >> k;
	for (int i = 100; i>0; i--) {
		if (a%i==0 && b%i==0) {
			n = n + 1;
			if (n == k) {
				cout << i << endl;
				return 0;
		}
		}
	}
}

Measured memory_bytes: 3600
n,m = map(int,input().split())
a = list(map(int,input().split()))
p = [[aa,1] for aa in a]
for _ in range(m):
  b = list(map(int,input().split()))
  b.reverse()
  p.append(b)
p.sort()
p.reverse()
rest = n
score = 0
for pp in p:
  use = min(pp[1],rest)
  rest -= use
  score += pp[0] * use
  if rest==0: break
print(score)

Measured memory_bytes: 42452
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define f(i,x,n) for(int i=x;i<(int)(n);++i)
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=200005,INF=1<<30;

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    while(1){
        int N,H,W;cin>>N>>H>>W;
        vector<int> S(20005,0);
        
        for(int i=0;i<N;i++){
            int a;cin>>a;
            if(i%2==0){
                for(int j=i*W+1+a;j<i*W+1+a+W;j++) S[j]=1;
            }else{
                for(int j=i*W+1-a;j<i*W+1-a+W;j++) S[j]=1;
            }
        }
        
        int ans=0;
        
        for(int i=1;i<=N*W;i++){
            if(S[i]==0) ans+=H;
        }
        
        cout<<ans<<endl;
        
        break;
    }
}



Measured memory_bytes: 3300
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

//B: Brave Force Story
public class Main{

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int[][] move = {{0, 1}, {1, 1}, {-1, 0}, {1, 0}, {-1, -1}, {0, -1}};
		while(true){
			int t = sc.nextInt();
			int n = sc.nextInt();
			if(t==0&&n==0)break;
			boolean[][] map = new boolean[200][200];
			while(n--!=0){
				int x = sc.nextInt()+100;
				int y = sc.nextInt()+100;
				map[x][y] = true;
			}
			int x = sc.nextInt()+100;
			int y = sc.nextInt()+100;
			map[x][y] = true;
			int c = 1;
			List<int[]> list = new ArrayList<int[]>();
			list.add(new int[]{x, y});
			while(t--!=0){
				List<int[]> next = new ArrayList<int[]>();
				for(int[] a:list){
					for(int k=0;k<6;k++){
						int nx = a[0]+move[k][0];
						int ny = a[1]+move[k][1];
						if(!map[nx][ny]){
							map[nx][ny] = true;
							c++;
							next.add(new int[]{nx, ny});
						}
					}
				}
				list = next;
			}
			System.out.println(c);
		}
	}
}

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

int main(){
  
  int n;
  cin >>n;
  int h[n+1];
  for(int i=1;i<=n;i++) cin >>h[i];
  int dp[n+1]={10000000};
  dp[1]=0;
  dp[2]=abs(h[2]-h[1]);
  for(int i=3;i<=n;i++){
  	dp[i]=min((dp[i-2]+abs(h[i]-h[i-2])),(dp[i-1]+abs(h[i]-h[i-1])));
  }
  cout << dp[n]<<endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(n);i++)
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
const int INF=1e9;
const int MOD=1e9+7;
const double pi=acos(-1);

int main(){
  int n;
  cin >>n;
  map<string,int>mp;
  string w;
  cin >> w;
  mp[w]++;
  
  bool ok=true;
  rep(i,n-1){
    string s;
    cin >> s;
    if(w[w.size()-1]!=s[0]){
      ok=false;
      break;
    }
    mp[s]++;
    w=s;
  }
  for(auto p:mp){
    if(p.second>=2)ok=false;
  }
  if(ok)cout<<"Yes"<<endl;
  else cout << "No"<<endl;
}


Measured memory_bytes: 256
import math
n = int(input())

def get_ans2(tpl1, tpl2):
    ans2 = abs(tpl1[0]-tpl2[0])+abs(tpl1[1]-tpl2[1])
    return ans2

lst=[]
mx_dis1, mn_dis1 = 0, 10**9
mx_y = 0
mn_y = 10**9
mx_y_idx = -1
mn_y_idx = -1
mx_x = 0
mn_x = 10**9
mx_x_idx = -1
mn_x_idx = -1
for i in range(n):
    x, y = map(int, input().split())
    lst.append((x,y))
    dis1 = x + y
    dis2 = abs(x-y)
    mx_dis1 = max(dis1, mx_dis1)
    mn_dis1 = min(dis1, mn_dis1)
    if x>=y:
        if dis2 > mx_x:
            mx_x = dis2
            mx_x_idx = i
        if dis2 < mn_x:
            mn_x = dis2
            mn_x_idx=i
    else:
        if dis2 > mx_y:
            mx_y = dis2
            mx_y_idx = i
        if dis2 < mn_y:
            mn_y = dis2
            mn_y_idx = i
    

ans1 = mx_dis1-mn_dis1

if mx_x_idx<0:
    ans2 = get_ans2(lst[mx_y_idx], lst[mn_y_idx])
elif mn_y_idx<0:
    ans2 = get_ans2(lst[mx_x_idx], lst[mn_x_idx])
else:
    ans2 = get_ans2(lst[mx_x_idx], lst[mx_y_idx])

print(max(ans2, ans1))

Measured memory_bytes: 35884
#include<iostream>
#include<vector>
#include<bitset>
#include<string>
#include<cmath>
#include<algorithm>
#include<stack>
#include<list>
#include<queue>
#include<map>
#include<numeric>
#include<set>
#include<iterator>
#include<cstdio>
using namespace std;
#define rep(i,x) for(int i=0;i<x;i++)
#define re(i,x,y) for(int i=x;i<y;i++)
int INF=1e9;
const long long mod=1e9+7;
#define ll long long

int main(){
  int n,q,time,cnt_time=0;
  string name;
  cin>>n>>q;
  queue<pair<string,int> >que;
  while(n--){
    cin>>name>>time;
    que.push(make_pair(name,time));
  }
  while(!que.empty()){
    pair<string,int>top=que.front();
    que.pop();
    if(top.second<=q){
      cnt_time+=top.second;
      cout<<top.first<<" "<<cnt_time<<endl;
    }
    else{
      cnt_time+=q;
      que.push(make_pair(top.first,top.second-q));
    }
  }
}


Measured memory_bytes: 6240
from sys import stdin
import queue
import sys
import math

n=int(input())
num=list(map(int,input().split()))
ans=0
now=1
for i in range(n):
    if num[i]==now:
        now+=1
    else:
        ans+=1
if now==1:
    print(-1)
else:
    print(ans)

Measured memory_bytes: 76876
#![allow(unused_imports, unused_variables, dead_code)]
use std::io::*;
use std::fmt::*;
use std::str::*;
use std::cmp::*;
use std::collections::*;

trait InputValue {
    fn parse(s: &str) -> Self;
}

fn read<T: InputValue>() -> T {
    let mut buf = String::new();
    let _ = stdin().read_line(&mut buf);
    T::parse(&buf.trim())
}

fn readnc<T: InputValue>() -> Vec<T> {
    let mut vec = vec![];
    let line: String = read();
    for token in line.split_whitespace() {
        vec.push(T::parse(token));
    }
    vec
}

fn readn<T: InputValue>(n: usize) -> Vec<T> {
    let mut vec = vec![];
    for _ in 0..n {
        vec.push(read());
    }
    vec
}

macro_rules! parse_single_value {
    ($($t:ty),*) => {
        $(
            impl InputValue for $t {
                fn parse(s: &str) -> $t { s.parse().unwrap() }
            }
        )*
	}
}
parse_single_value!(i32, i64, f32, f64, usize, String);

macro_rules! parse_tuple {
	($($t:ident),*) => {
		impl<$($t),*> InputValue for ($($t),*) where $($t: InputValue),* {
			fn parse(s: &str) -> ($($t),*) {
				let mut tokens = s.split_whitespace();
				let t = ($($t::parse(tokens.next().unwrap())),*);
				t
			}
		}
	}
}
parse_tuple!(A, B);
parse_tuple!(A, B, C);

// ===

fn main() {
    let n: usize = read();
    let mut a: Vec<i64> = readnc();

    let mut max = 0;
    let mut inc_set: Vec<(usize, i64)> = vec![];
    inc_set.push((0, 0));

    for i in 0..n {
        if max < a[i] {
            max = a[i];
            inc_set.push((i, a[i]));
        }
    }

    a.sort();
    a.reverse();

    let ln = inc_set.len();
    let mut current = inc_set[ln-1].1;
    let mut head: usize = 0;
    let mut ans = vec![0; n];
    for i in (1..ln).rev() {
        let mut to = inc_set[i-1].1;
        let mut cnt = head as i64 * (inc_set[i].1 - to);
        while head < n && a[head] >= to {
            cnt += a[head] - to;
            head += 1;
        }
        ans[inc_set[i].0] = cnt;
    }

    for i in 0..n {
        println!("{}", ans[i]);
    }
}

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


int main() {
  int n,m;
  cin >> n >> m;
  int love[m+1]={};
  for(int i=0;i<n;i++){
    int k;
    cin >> k;
    for(int j=0;j<k;j++){
      int ryouri;
      cin >> ryouri;
      love[ryouri]++;
    }
  }
  int count = 0;
  for(int i=0;i<m;i++){
    if(love[i+1]==n) count++;
  }
  cout << count << endl;
  return 0;
}


Measured memory_bytes: 256
import sys
import re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

A, B, C, D = MAP()

while True:
    C = C - B
    if C <= 0:
        print('Yes')
        break
    else:
        A = A - D
        if A <= 0:
            print('No')
            break


Measured memory_bytes: 10628
#include <iostream>
#include <vector>
#include <queue>
#include <utility>
#include <algorithm>
using namespace std;

#define mkp(a,b) make_pair((a),(b))
#define fi first
#define se second

#define INF 10000000000000

int main() {
	int V, E, r;
	vector<vector<pair<long long,long long> > > v; // v[from][] ... fi = to, se = cost
	vector<pair<long long,bool> > cost; // fi = cost, se = flag

	cin >> V >> E >> r;
	v.resize(V);
	cost.resize(V);

	for(int i = 0; i < V; i++) {cost[i].fi = INF; cost[i].se = false;}

	for(int i = 0; i < E; i++) {
		int s, t, d;
		cin >> s >> t >> d;
		v[s].push_back(mkp(t,d));
	}

	priority_queue<pair<long long,long long> , vector<pair<long long,long long> >, greater< pair<long long,long long> > > q; // fi = cost, se = virtex 
	q.push(mkp(0,r));
	cost[r].fi = 0;

	while(!q.empty()) {
		pair<long long,long long> tmp = q.top(); q.pop();
		if(cost[tmp.se].se)
			continue;

		cost[tmp.se].fi = tmp.fi;
		cost[tmp.se].se = true;
		for(int i = 0; i < v[tmp.se].size(); i++) {
			q.push(mkp(cost[tmp.se].fi + v[tmp.se][i].se , v[tmp.se][i].fi));
		}
	}

	for(int i = 0; i < cost.size(); i++) {
		if(cost[i].fi == INF)
			cout << "INF" << endl;
		else
			cout << cost[i].fi << endl;
	}

	return 0;
}

Measured memory_bytes: 22004
N = int(input())
adj_list = []
for _ in range(N):
    line = list(input().split(" "))
    adj_list.append([int(k) - 1 for k in line[2:]])

d = [-1 for _ in range(N)]
f = [-1 for _ in range(N)]
time = 1

visited = set()

def dfs(p):
    global time
    if p in visited:
        return

    d[p] = time
    time += 1
    visited.add(p)
    for ad in adj_list[p]:
        if ad not in visited:
            dfs(ad)
    f[p] = time
    time += 1

for i in range(N):
    dfs(i)

for i in range(N):
    print(f"{i + 1} {d[i]} {f[i]}")


Measured memory_bytes: 5648
#include <bits/stdc++.h>
#include<cmath>
#define N 100005
#define A 1000005
#define MOD 998244353 //1000000007 // //100000000
#define inf 1000000000000000000
#define ll long long
//#define M_PI 3.141592653589793238463

using namespace std;

#define pii pair<ll, ll>
#define piii pair<ll, pii>
#define ft first
#define sd second
#define pb push_back
#define rep(i, n) for(ll i = 0; i < n; i++)
#define repr(i, n) for(ll i = n-1; i >= 0; i--)
#define itr(it, x) for(auto it = x.begin(); it != x.end(); it++)
#define mem(a, b) memset(a, (ll)b, sizeof(a))
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define edge(v, x, y) v[x].pb(y); v[y].pb(x);
#define popcount __builtin_popcount
#define ANS(s) {cout << s << "\n"; return;}

//~~~~~~fancy print~~~~~~~//
#define printpii(a) cout << a.ft << " " << a.sd << endl;
#define printpiii(a) cout << a.ft << " " << a.sd.ft << " " << a.sd.sd << endl;
#define print(a, n) rep(i, n) cout << a[i] << " "; cout << endl;
#define printv(v) for(auto x: v)cout << x << " "; cout << endl;
#define printm(a, n, m) rep(i, n) { rep(j, m) cout << a[i][j] << "\t"; cout << endl;}

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

void fast(){ios_base::sync_with_stdio(false);cin.tie(0);cout << setprecision(12) << fixed;}


void solve(){
    ll n;
    cin >> n;
    ll a[n+1];
    rep(i, n+1) cin >> a[i];
    ll ans = 0;
    rep(i, n)
    {
        ll x ; cin >> x;
        ll k = min(a[i], x);
        ans += k;
        x -= k;
        k = min(a[i+1], x);
        ans += k;
        a[i+1] -= k;
    }
    cout << ans;

}
main(){
    /*#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif*/
    fast();
    ll t = 1; //cin >> t;
    while(t--){
        solve();
    }
}


Measured memory_bytes: 1024
// A.

#include <iostream>
#include <algorithm>
#include <sstream>
#include <cstdio>
#include <cstring>

using namespace std;

int main(int argc, char *argv[])
{
	int p[3];
	cin >> p[0] >> p[1] >> p[2];
	sort(p, p + 3);
	cout << (p[0] + p[1]) << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define loop(i,b,e) for(int i=b;i<=e;i++)
#define loop2(i,e,b) for(int i=e;i>=b;i--)
#define io ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define fi first
#define se second
#define X real()
#define Y imag()
#define cp(a,b)	( (conj(a)*(b)).imag() )
#define length(a) (hypot((a).imag(), (a).real()))
typedef complex<double> point;
typedef long long ll;
typedef unsigned long long ull;
double PI = 3.141592653589793;
const double EPS = 1e-9;
const int N = 1e6 + 5;
const ll mod = 1e9 + 7;
const int oo = 1e9;
int dx[] = { 0, 0, 1, -1, 1, -1, 1, -1 };
int dy[] = { 1, -1, 0, 0, -1, 1, 1, -1 };

int r;

int main() {
	scanf("%d",&r);
	if (r < 1200) printf("ABC");
	else if(r < 2800) printf("ARC");
	else  printf("AGC");
}

Measured memory_bytes: 256
import sys
import numpy as np
import math as mt

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

n, a, b = map(int, readline().split())

ans = a * (n//(a + b))
if n%(a+b) < a:
  ans += n%(a+b)
else:
  ans += a
print(ans)

    


Measured memory_bytes: 27076
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
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; }

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n;
	cin >> n;
	ll ans = n*(n-1)/2;
	cout << ans << endl;
	return 0;
}


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

int main() {
  string N;
  cin >> N;
  
  int sum = 0;
  for (int i = 0; i < N.size(); i++) {
    int x = N.at(i) - '0';
    sum = sum + x;
  }
  string ans = "No";
  if (atoi(N.c_str()) % sum == 0) {
    ans = "Yes";
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
<?php
// B
fscanf(STDIN, '%d', $n);
for ($i  = 0; $i < $n; $i++) {
    fscanf(STDIN, '%s', $s);
    if (isset($a[$s])) $a[$s]++;
    else $a[$s] = 1;
}
fscanf(STDIN, '%d', $m);
for ($i  = 0; $i < $m; $i++) {
    fscanf(STDIN, '%s', $t);
    if (isset($a[$t])) $a[$t]--;
    else $a[$t] = -1;
}
echo max(0, max($a));

Measured memory_bytes: 4728
#include <stdio.h>

int main()
{
 int a, b, c, n;

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

// printf("%d,%d,%d\n",a,b,c);

 if(b-a<=c){
     printf("Yay!");
 }else
     {
        printf(":("); /* code */
     }
return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace std;
using namespace __gnu_pbds;
 
#define mp make_pair
#define sz(x) (int)((x).size())
#define all(x) (x).begin(),(x).end()
#define FO(x) {freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);}
#define eb emplace_back
 
typedef pair< int, int > pii;
typedef pair< long long, long long > pll;
typedef long long ll;
typedef unsigned long long ull;
typedef vector< int > vi;
typedef vector< vi > vvi;
typedef vector< ll > vll;
typedef vector< vll > vvll;
typedef vector< pii > vpii;
typedef vector< vpii > vvpii;
typedef vector< pll > vpll;
typedef long double ld;
typedef vector< ld > vld;
typedef unsigned int uint;
 
template <uint MD> struct ModInt {
    using M = ModInt;
    const static M G;
    uint v;
    ModInt(ll _v = 0) { set_v(uint(_v % MD + MD)); }
    M& set_v(uint _v) {
        v = (_v < MD) ? _v : _v - MD;
        return *this;
    }
    explicit operator bool() const { return v != 0; }
    M operator-() const { return M() - *this; }
    M operator+(const M& r) const { return M().set_v(v + r.v); }
    M operator-(const M& r) const { return M().set_v(v + MD - r.v); }
    M operator*(const M& r) const { return M().set_v(uint(ull(v) * r.v % MD)); }
    M operator/(const M& r) const { return *this * r.inv(); }
    M& operator+=(const M& r) { return *this = *this + r; }
    M& operator-=(const M& r) { return *this = *this - r; }
    M& operator*=(const M& r) { return *this = *this * r; }
    M& operator/=(const M& r) { return *this = *this / r; }
    bool operator==(const M& r) const { return v == r.v; }
    const bool operator<(const M& o) const {return v < o.v; }
    M pow(ll n) const {
        M x = *this, r = 1;
        while (n) {
            if (n & 1) r *= x;
            x *= x;
            n >>= 1;
        }
        return r;
    }
    M inv() const { return pow(MD - 2); }
    friend ostream& operator<<(ostream& os, const M& r) { return os << r.v; }
};
 
using Mint = ModInt<(int)1e9 + 7>;


int main() { 
    #ifdef BLAT
        freopen("stdin", "r", stdin);
        freopen("stderr", "w", stderr);
    #endif

    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int n, k;
    cin >> n >> k;

    vi a(n);

    for(auto &x : a) cin >> x;

    for(int rep = 1; rep <= 100 && rep <= k; ++ rep) {
        vi b(n, 0);

        for(int i = 0; i < a.size(); ++i) {
            b[max(0, i-a[i])] ++;
            if(i+a[i]+1 < n) b[i+a[i]+1] --;
        }

        for(int i = 1; i < n; ++i) {
            b[i] += b[i-1];
        }

        a = b;
    }

    for(auto &x : a) cout << x << ' ';
    return 0; 
}

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

using namespace std;

#define intt long long
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

const int N = 105;

int n, a[N], cnt[N];

int main() {

	FAST;

	cin >> n;
	for (int i = 0; i < n; i ++) {
		cin >> a[i];
		cnt[a[i]] ++;
	}
	int ans = 0;
	for (int i = 1; i < N; i ++) {
		if (cnt[i]) {
			ans ++;
			cnt[i] = 0;
		}
	}
	cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
	int a[7];
	int b[7];
	int c[7];
	int x;
	
	for(x=0;x<7;x++){
		scanf("%d %d",&a[x],&b[x]);
	}
	for(x=0;x<7;x++){
		printf("%d\n",a[x]-b[x]);
	}
	return 0;
}

Measured memory_bytes: 600
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from bisect import bisect, bisect_left, bisect_right

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

X = INT()

A = []
for i in range(1, 2 * (int(sqrt(X))+1)):
    a =  i * (i + 1) // 2
    # print(a)
    if a <= X:
        A.append(a)
    else:
        ans = len(A)
        mi = A.pop()
        ma = a
        break
# print(mi, ma)
# print(ans)
if mi == X:
    print(ans)
else:
    print(ans+1)
        
    








Measured memory_bytes: 12284
H,W = map(int,input().split())
Ch,Cw = map(int,input().split())
Dh,Dw = map(int,input().split())
grid = ""
for i in range(H):
    grid += input()
grid = list(grid)

def convert_1d_to_2d(l, cols):
    return [l[i:i + cols] for i in range(0, len(l), cols)]

grid = convert_1d_to_2d(grid, W)

ans = [[1000000]*W for i in range(H)]
ans[Ch-1][Cw-1]=0

from collections import deque
ans = [[1000000]*W for i in range(H)]
ans[Ch-1][Cw-1]=0

from collections import deque

que = deque([[Ch-1,Cw-1]])
que2 = deque([[Ch-1,Cw-1]])

while que or que2:
    if que:
        x,y=que.popleft()
        for i,j in [(1,0),(0,1),(-1,0),(0,-1)]:
            nextx,nexty=x+i,y+j
            check = ans[x][y]

            if nextx>=0 and nexty>=0 and nextx<=H-1 and nexty<=W-1:
                dist=grid[nextx][nexty]
                if dist!='#':
                    if check<ans[nextx][nexty]:
                        ans[nextx][nexty]=check
                        que.append([nextx,nexty])

        for i,j in [(2,2),(2,1),(2,0),(2,-1),(2,-2),(1,2),(1,1),(1,-1),(1,-2),(0,2),(0,-2),(-2,2),(-2,1),(-2,0),(-2,-1),(-2,-2),(-1,2),(-1,1),(-1,-1),(-1,-2)]:
            nextx,nexty=x+i,y+j
            check = ans[x][y]+1

            if nextx>=0 and nexty>=0 and nextx<=H-1 and nexty<=W-1:
                dist=grid[nextx][nexty]
                if dist!='#':
                    if check<ans[nextx][nexty]:
                        ans[nextx][nexty]=check
                        que2.append([nextx,nexty])
            
    else:
        x,y=que2.popleft()
        for i,j in [(1,0),(0,1),(-1,0),(0,-1)]:
            nextx,nexty=x+i,y+j
            check = ans[x][y]

            if nextx>=0 and nexty>=0 and nextx<=H-1 and nexty<=W-1:
                dist=grid[nextx][nexty]
                if dist!='#':
                    if check<ans[nextx][nexty]:
                        ans[nextx][nexty]=check
                        que.append([nextx,nexty])

        for i,j in [(2,2),(2,1),(2,0),(2,-1),(2,-2),(1,2),(1,1),(1,-1),(1,-2),(0,2),(0,-2),(-2,2),(-2,1),(-2,0),(-2,-1),(-2,-2),(-1,2),(-1,1),(-1,-1),(-1,-2)]:
            nextx,nexty=x+i,y+j
            check = ans[x][y]+1

            if nextx>=0 and nexty>=0 and nextx<=H-1 and nexty<=W-1:
                dist=grid[nextx][nexty]
                if dist!='#':
                    if check<ans[nextx][nexty]:
                        ans[nextx][nexty]=check
                        que2.append([nextx,nexty])
        
                    
if ans[Dh-1][Dw-1]==1000000:
    print("-1")
else:
    print(ans[Dh-1][Dw-1])

Measured memory_bytes: 175676
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,a,b) for(int i =(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
#define REPm(i,n) for(int i=(n)-1;i>=0;i--)
#define REP1(i,n) for(int i=1;i<=(n);i++)

int main(){
    int scount=0;
    int tcount=0;
    string X;
    cin >> X;
    REP(i,X.length()){
        if(X[i] == 'S') scount++;
        else{
            if(tcount < scount) tcount++;
        }
    }
    cout << X.length()-2*tcount << endl;
    return 0;
}


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

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

  vector<int> vec_c(N);
  vector<int> vec_t(N);

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

  int min = 100000;
  int cost = 100000;
  for(int i=0;i<N;i++){
    if(cost > vec_c.at(i) && T >= vec_t.at(i)){
      cost = vec_c.at(i);
      min = vec_t.at(i);
    }
  }

  if(T<min){
    cout << "TLE" << endl;
  } else {
    cout << cost << endl;
  }
}


Measured memory_bytes: 764
#include <iostream>
#include <vector>
#include <cstring>
#include <algorithm> // sort

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

using namespace std;

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


    char ima = S[0];
    ll cnt = 0;

    for(ll i = 1; i < S.size(); i++)
    {
        if( S[i] != ima)
        {
            cnt++;
            ima = S[i];
        }
    }
    cout << cnt << endl;

    return 0;

}

Measured memory_bytes: 512
#include <iostream>

int main(int argc, char const* argv[])
{
	int mat_size, vec_size;
	int mat[100][100] = {};
	int vec[100] = {};

	std::cin >> mat_size >> vec_size;

	for (size_t i = 0; i < mat_size; i++)
		for (size_t j = 0; j < vec_size; j++)
			std::cin >> mat[i][j];

	for (size_t j = 0; j < vec_size; j++)
		std::cin >> vec[j];

	for (size_t i = 0; i < mat_size; i++)
	{
		int element_val = 0;
		for (size_t j = 0; j < vec_size; j++)
		{
			element_val += mat[i][j] * vec[j];
		}
    std::cout << element_val << std::endl;
	}

	return 0;
}

Measured memory_bytes: 1208
#include<stdio.h>
int main(){
    int v, h;
    for(scanf("%d %d", &v, &h); v!=0||h!=0; scanf("%d %d", &v, &h)){
        for(int i=0; i<v; i++){
            for(int j=0; j<h; j++){
                putchar('#');
            }
            putchar('\n');
        }
        putchar('\n');
    }
}


Measured memory_bytes: 2112
#include <algorithm>
#include <fstream>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>

#include <cmath>
#include <climits>
#include <queue>

using namespace std;


int main() {
    int n; cin >> n;
    int m; cin >> m;
    vector<int> l(m);
    vector<int> r(m);
    vector<int> canpath(n);
    for(int i = 0; i < m; ++i){
        cin >> l[i];
        cin >> r[i];
    }
    sort(l.begin(), l.end());
    sort(r.begin(), r.end());
    int minimum = l[m - 1];
    int maximum = r[0];

    int ans = max(0, maximum - minimum + 1);
    cout << ans << "\n";

    return 0;
}

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

#define M ll(998244353)
#define maxn 4003

using namespace std;
typedef long long ll;

int k, n;

ll d[maxn][maxn];
ll c[maxn][maxn];
ll p[maxn];

int main(){
  ios_base::sync_with_stdio(0);

  cin >> k >> n;

  p[0] = 1;
  for (int i = 1; i <= 2 * k; ++i)
    p[i] = (p[i - 1] * 2) % M;

  c[0][0] = 1;
  for (int i = 1; i <= 2 * k; ++i)
    for (int j = 0; j <= 2 * k; ++j)
      c[i][j] = ((j ? c[i - 1][j - 1] : 0) + c[i - 1][j]) % M;


  for (int i = 1; i <= 2 * k; ++i)
    d[0][i] = 1;

  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= 2 * k; ++j)
      d[i][j] = (d[i - 1][j] + d[i][j - 1]) % M;

  for (int i = 2; i <= 2 * k; ++i) {
    ll ans = 0;
    ll ok = 1 - i % 2;
    ll a = 0;

    for (int j = 1; j <= k; ++j)
      if (1 <= i - j && i - j <= k && j < i - j)
        a++;

    ll b = k - 2 * a - ok;

    for (int j = 0; j <= a; ++j) {
      ll sign = ((a - j)&1 ? -1 : 1);

      ans = (ans + ((c[a][j] * d[n][b + j] % M) * p[j] % M) * sign + M) % M;
      if (ok)
        ans = (ans + ((c[a][j] * d[n - 1][b + j] % M) * p[j] % M) * sign + M) % M;
    }

    cout << (ans + M) % M << '\n';
  }

  return 0;

}


Measured memory_bytes: 188672
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  ll n;
  cin >> n;
  vector<vl> g(10, vl(10, 0));
  rep2(i, 1, n + 1) {
    string s = to_string(i);
    ll a = s[0] - '0';
    ll b = s.back() - '0';
    g[a][b]++;
  }
  ll ans = 0;
  rep(i, 10) rep(j, 10) ans += g[i][j] * g[j][i];
  cout << ans << endl;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    public static void main(String args[]) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        if(n % 3 == 0){
            System.out.println(n/3);
        }
        else{
            System.out.println(n/3);
        }
    }
}


Measured memory_bytes: 21204
#include<stdio.h>
#include <string.h>
#include<iostream>
using namespace std;
 
int gcd(int a, int b) {
    if (b==0) return a;
    else return gcd(b, a%b);
}

int main()
{
    int N;
  int sum=0;
  	cin>>N;
 
    for(int i=1;i<=N;i++){
       for(int j=1;j<=N;j++){
          	for(int k=1;k<=N;k++){
              int g;
              g=gcd(i,j);
			  sum+=gcd(k,g);
    }}}
  
	cout<<sum<<endl;
  
    return 0;
}

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

int f(int n) {
    if (n % 2 != 0){
        return 1; // 1を返すのがダメだった。
    }
    return f(n / 2) + 1;
}

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

    int ans  = 1;
    for (int i = 1; i <= n; i++) {
        if ( f(i) > f(ans) ) {
            ans = i;
        }
    }

    cout << ans << endl;

    return 0;
}

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

int main(){
    string s,t;
    int k=0;
    cin>>s;
    cin>>t;
    if(s[0] == t[0]) k++;
    if(s[1] == t[1]) k++;
    if(s[2] == t[2]) k++;
    cout<<k<<endl;
    return 0;
}

Measured memory_bytes: 256
def function(values, num):
    count = int(input())

    for i in range(count):
        name = input()
        if name in values:
            values[name] += num
        else:
            values[name] = 1

    
if __name__ == '__main__':
    values = {}

    function(values, 1)
    function(values, -1)

    max_num = max(values.values())

    if max_num < 0:
        print(0)
    else:
        print(max_num)

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

#define llong long long
#define inf 999999999
#define mp make_pair
#define pb push_back
#define fn fill_n
typedef pair<int, int> P;
typedef pair<P, int> PP;
typedef pair<PP, int> PPP;
typedef struct data{
	int now;
	int cost;
}data;
int nh[4] = {1, 0, -1, 0};
int nw[4] = {0, 1, 0, -1};





int main(){
	string in;
	char before = 'a' - 10;
	vector<char> a;
	cin >> in;
	for(int i = 0; i < in.length(); i++) a.pb(in[i]);
	while(a.size()){
	for(int i = 0; i < 26; i++){
		if(count(a.begin(), a.end(), (char)('a'+i)) == 0 && (char)('a'+i) > before){
			for(int j = 0; j < a.size(); j++) cout << a[j];
			cout << (char)('a'+i) << endl;
			return 0;
		}
	}
	before = a[a.size()-1];
	a.erase(a.end()-1);
}
if(before != 'z'){
	cout << (char)(before+1) << endl;
	return 0;
}
cout << -1 << endl;
return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#define max(a,b)(a>b?a:b)
int dp[3004][3004];
int main()
{
    char s[3002],t[3002],ans[3002];
    scanf("%s",s);
    scanf(" %s",t);
   int m=strlen(s),n=strlen(t),count=0;
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            if(t[i-1]==s[j-1])
            {
                dp[i][j]=dp[i-1][j-1]+1;
            }
            else
            {
                dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
            }
        }
    }
    int i=n,j=m;
    while(i!=0 && j!=0)
    {
        if(t[i-1]==s[j-1])
        { ans[count++]=t[i-1];i--;j--;}
        else if(dp[i-1][j] > dp[i][j-1])
            i--;
        else j--;
    }
  for(int i=count-1;i>=0;i--)
    printf("%c",ans[i]);
  printf("\n");
return 0;
}



Measured memory_bytes: 35328
#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<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n,m;cin >> n >> m;
  vector<ll> edge[n];
  bool isr[n];
  ll in[n];
  REP(i,n){
      isr[i] = true;
      in[i] = 0;
  }
  REP(i,n+m-1){
      ll a,b;
      cin >> a >> b;
      a--;b--;
      edge[a].push_back(b);
      in[b]++;
      isr[b] = false;
  }
  ll root;
  REP(i,n){
      if(isr[i]) root = i;
  }
  ll dis[n],par[n];
  REP(i,n){
      dis[i] = 0;
      par[i] = 0;
  }
  stack<ll> pq;
  pq.push(root);
  while(pq.size()){
      ll now = pq.top();
      pq.pop();
      REP(i,edge[now].size()){
          ll to = edge[now][i];
          in[to]--;
      }
      REP(i,edge[now].size()){
          ll to = edge[now][i];
          if(in[to] == 0 ){
              dis[to] = dis[now] + 1;
              par[to] = now;
              pq.push(to);
          }
      }
  }
  REP(i,n){
      if(i==root)cout << 0 << endl;
      else cout << par[i] +1 << endl;
  }


}

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

int main() {
	int n,k;
	cin >> n >> k;
	vector<ll> h(n);
	rep(i, n) cin >> h[i];

	sort(h.rbegin(), h.rend());
	
	if (n <= k) {
		cout << 0 << endl;
		return 0;
	}
	ll ans = 0;
	for (int i = k; i < n; i++) {
		ans += h[i];
	}
	cout << ans << endl;
}


Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <vector>
#include <deque>
#include <queue>
#include <list>
#include <stack>
#include <string>
#include <functional>
#include <numeric>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
#include <cstdlib>
#define INF 100000000
#define _INF -100000000
#define INFLL (long long)1e14
#define _INFLL (long long)-1e14
#define Loop(i, n) for(int i = 0; i < (int)n; i++)
#define Loop1(i, n) for(int i = 1; i <= (int)n; i++)
#define Loopr(i, n) for(int i = (int)n - 1; i >= 0; i--)
#define Loopr1(i, n) for(int i = (int)n; i >= 1; i--)
using namespace std;
typedef long long int ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef pair<int, int> P;



int main() {
	string s;
	cin >> s;
	string t = "CODEFESTIVAL2016";
	int ans = 0;
	Loop(i, s.length()) {
		if (s[i] != t[i]) ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 384
use proconio::*;
use std::collections::BinaryHeap;

fn main() {
    input! {
        mut a: usize,
        mut b: usize,
        mut c: usize,
        k: usize,
    };

    let mut cnt = 0;
    let mut ans = true;

    while b <= a {
        cnt += 1;
        b *= 2;

        if cnt > k {
            ans = false;
            break;
        }
    }

    while c <= b {
        cnt += 1;
        c *= 2;
        if cnt > k {
            ans = false;
            break;
        }
    }

    println!("{}", if ans { "Yes" } else { "No" });
}


Measured memory_bytes: 2176
#include <bits/stdc++.h>
using namespace std;
int main(){
    int a,b;
    a=b=0;
    char aa[10005];
    gets(aa);
    for(int i=0;i<strlen(aa);i++){
        if(aa[i]=='C'){
            for(int j=i;j<strlen(aa);j++){
                if(aa[j]=='F'){
                    cout<<"Yes"<<endl;
                    return 0;
                }
            }
        }
    }
    cout<<"No"<<endl;
    return 0;
}

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

Lmax = 1
Rmin = N
for m in range(M):
    L, R = list(map(int, input().split()))
    Lmax = max(Lmax, L)
    Rmin = min(Rmin, R)

print(max(0, Rmin - Lmax + 1))

Measured memory_bytes: 3060
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <functional>

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...) 42
#endif

#define rep_(i, a_, b_, a, b, ...) for (int i = (a), i##_len = (b); i < i##_len; ++i)
#define rep(i, ...) rep_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define reprev_(i, a_, b_, a, b, ...) for (int i = (b-1), i##_min = (a); i >= i##_min; --i)
#define reprev(i, ...) reprev_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define all(x) (x).begin(), (x).end()
template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
// template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int,int> P;
typedef long double ld;

int main (void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s, t; cin >> s >> t;
    if (s.size() == t.size() - 1 && t.substr(0, s.size()) == s) cout << "Yes\n";
    else cout << "No\n";
    // cout << t.substr(0, s.size());
    return 0;
}

Measured memory_bytes: 3652
import fs = require('fs');
if(process.argv[1].match(/Main.js$/)) { console.log(main(fs.readFileSync('/dev/stdin', 'utf8').split(/[\r\n\t ]/))); }

export function main(strings: string[]): string {
	const ret: any[] = [];
	const numbers = strings.map(Number);

	const [H, W, h, w] = numbers

	ret.push((H-h)*(W-w));


	return ret.join('\n') + '\n';
}

Measured memory_bytes: 7372
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <deque>
#include <set>
#include <numeric>
using namespace std;
using ll = long long;
using ld = long double;

const ll MOD = 998244353;
const ld PI = acos((long double)(-1));

#define no "no"
#define No "No"
#define NO "NO"
#define yes "yes"
#define Yes "Yes"
#define YES "YES"
#define next '\n'
#define sp " "
#define print(x) cout << (x)
#define println(x) cout << (x) << next
#define stop return(0)
#define rep(i, n) for(int (i) = (0); (i) < (n); (++i))
#define FOR(i, start, end) for(int (i) = (start); (i) < (end); (++i))
#define foreach(elem, _list) for(auto& (elem) : (_list))
#define view(_list) foreach(e, _list){ cout << e << sp; } cout << next
#define FAST ios::sync_with_stdio(false); cin.tie(nullptr)
#define size(s) (s).size()
#define ALL(vec) (vec).begin(), (vec).end()
#define pb(e) push_back(e)
#define INF 1e+9
#define EPS 0.00000001

const int mx = 1000000 + 10;
vector<int> dp(mx, 0);

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

    // 数列Aのa[i]について、a[i]の約数を調べる
    for(int i = 0; i < n; ++i){
        int A = a[i];

        // 同じ値を複数回行わないようにする
        // すでに同じ値を調べているならば、a[i]は2になっている
        if(dp[A] != 0){
            dp[A] = 2;
            continue;
        }

        // a[i]の倍数をインクリメントしていく
        for (int j = A; j < mx; j += A) {
            dp[j]++;
        }
    }

    int ans = 0;
    for(int i = 0; i < n; ++i){
        if(dp[a[i]] == 1){
            ans++;
        }
    }
    println(ans);
}


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

int main()
{
    ll n, p, c;
    cin >> n;
    vector<ll> freq(n+1, 0);
    for(int i = 0; i < n-1; i++){
        cin >> p;
        freq[p]++;
    }
    for(int i = 1; i <= n; i++){
        cout << freq[i] << "\n";
    }
}


Measured memory_bytes: 4840