akhauriyash/Code-Regression huggingface dataset:
import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 7)


class BinaryIndexTree:  # 1-indexed
    def __init__(self, N):
        """
        INPUT
        N [int] -> 全部0で初期化
        N [list] -> そのまま初期化
        """
        if isinstance(N, int):
            self.N = N
            self.depth = N.bit_length()
            self.tree = [0] * (N + 1)
            self.elem = [0] * (N + 1)
        elif isinstance(N, list):
            self.N = len(N)
            self.depth = self.N.bit_length()
            self.tree = [0] + N
            self.elem = [0] + N
            self._init()
        else:
            raise "INVALID INPUT: input must be int or list"

    def _init(self):
        size = self.N
        for i in range(1, self.N):
            if i + (i & -i) > size:
                continue
            self.tree[i + (i & -i)] += self.tree[i]

    def show(self):
        print(*self.elem)

    def add(self, i, x):
        self.elem[i] += x
        while i <= self.N:
            self.tree[i] += x
            i += i & -i

    def sum(self, i):
        res = 0
        while i > 0:
            res += self.tree[i]
            i -= i & -i
        return res

    def lower_bound(self, val):
        if val <= 0:
            return 0
        i = 0
        k = 1 << self.depth
        while k:
            if i + k <= self.N and self.tree[i + k] < val:
                val -= self.tree[i + k]
                i += k
            k >>= 1
        return i + 1


N, Q = map(int, input().split())
A = list(map(int, input().split()))
bit = BinaryIndexTree(A)

for _ in range(Q):
    t, a, b = map(int, input().split())
    if t == 0:
        bit.add(a + 1, b)
    else:
        print(bit.sum(b) - bit.sum(a))

Measured memory_bytes: 59420
#include <iostream>

int main(){
    int N, M, tmp, ans = 0;
    std::cin >> N >> M;
    for(auto i = 0; i < M; i++){
        std::cin >> tmp;
        ans += tmp;
    }

    if(ans > N){
        ans = -1;
    }
    else{
        ans = N - ans;
    }

    std::cout << ans << std::endl;

    return 0;
}


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

int main() {

    int A,B;

    char a;

    cin >> A >> a >> B;

    if ( a == '+' ){

        cout << A + B << endl;

    }

    else if ( a == '-' ){

        cout << A - B << endl;

    }

    else {

        cout << "error" << endl;

    }

}

Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<string>

using namespace std;
int main()
{
	int n;
	cin >> n;
	long long  sum = 0;
	for(int i = 1; i <= n; i++)
	{
		int l, r;
		cin >> l >> r;
		sum += r-l+1;
	}
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 256
import std.stdio;
import std.conv;
import std.string;

void main()
{
	while(true)
	{
		string[] input = split(chomp(readln()));
		int N = to!int(input[0]);
		if(N==0) break;

		char[] from = new char[N];
		char[] toto = new char[N];

		for(int i=0; i<N; i++) {
			input = split(chomp(readln()));
			from[i] = to!char(input[0]);
			toto[i] = to!char(input[1]);
		}

		input = split(chomp(readln()));
		int M = to!int(input[0]);

		string s;
		for(int i=0; i<M; i++) {
			input = split(chomp(readln()));
			s ~= input[0];
		}

		writeln(translate(s, maketrans(from, toto), ""));
	}
		
}

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

namespace Practice
{
    class Program
    {
        private static int ReadAndParseInt()
        {
            return int.Parse(Console.ReadLine());
        }
        private static int[] ReadAndParseIntArr()
        {
            return Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
        }
        private static long ReadAndParseLong()
        {
            return long.Parse(Console.ReadLine());
        }
        private static long[] ReadAndParseLongArr()
        {
            return Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse);
        }
        static void Main(string[] args)
        {
            SolveA(args);
            //SolveB(args);
            //SolveC(args);
            //SolveD(args);


        }
        static void SolveA(string[] args)
        {
            int[] abk = ReadAndParseIntArr();
            int a = abk[0];
            int b = abk[1];
            int k = abk[2];
            var list = new List<int>();

            int smallEnd = a + k;
            int bigStart = b - k;
            for(int i=a;i<=b;++i)
            {
                if(i < smallEnd || bigStart < i)
                {
                    list.Add(i);
                }
            }
            foreach(int i in list)
            {
                Console.WriteLine(i);
            }
        }
        
    }
}


Measured memory_bytes: 13268
#include <stdio.h>
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <string>
#include <cstring>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <ctime>
#include <vector>
#include <fstream>
#include <list>
#include <iomanip>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define ms(s) memset(s, 0, sizeof(s))
const int INF = 1e9;
inline int read(){
	int X = 0,w = 0 ;
	char ch = 0;
	while(!isdigit(ch)) {w |= ch == '-';ch = getchar();}
	while(isdigit(ch)) X = (X<<3) + (X<<1) + (ch ^ 48),ch = getchar();
	return w ? -X : X;
}

string tar="keyence";
int main() 
{
	string s;
	cin>>s;
	if(s==tar)
	{
		cout<<"YES";
		return 0;
	}
	for(int i=1;i<=7;i++)
	{
		string a=s.substr(0,i);
		for(int j=i;j<s.size();j++)
		{
			string b=s.substr(j,s.size()-j);
			if(a+b==tar)
			{
				cout<<"YES";
				return 0;
			}
		}
	}
	cout<<"NO";
    return 0;
}

Measured memory_bytes: 256
/*
  参考元：構文解析 Howto
  (https://gist.github.com/draftcode/1357281)

  構文解析
  <四則演算の式> ::= <乗算除算の式> (+ or -) <乗算除算の式> (+ or -) ...
  <乗算除算の式> ::= <括弧か数> (* or / ) <括弧か数> (* or / ) ...
  <括弧か数> ::= '(' <四則演算の式> ')' or <数>
  <数> ::= ...
*/

#include <iostream>
#include <string>
#include <cctype>

using namespace std;

typedef string::const_iterator State;
class ParseError {};

int number(State &begin);
int factor(State &begin);
int term(State &begin);
int expression(State &begin);


// 数字の列をパースして，その数を返す．
int number(State &begin)
{
    int ret = 0;

    while (isdigit(*begin)) {
        ret *= 10;
        ret += *begin - '0';
        begin++;
    }
    return ret;
}

// 括弧か数をパースして，その評価結果を返す．
int factor(State &begin)
{
    if (*begin == '(') {
        begin++;  // '('を飛ばす
        int ret = expression(begin);
        begin++; // ')'を飛ばす
        return ret;
    }
    else
        return number(begin);
}

// 乗算除算の式をパースして，その評価結果を返す．
int term(State &begin)
{
    int ret = factor(begin);

    while (true) {
        if (*begin == '*') {
            begin++;
            ret *= factor(begin);
        }
        else if (*begin == '/') {
            begin++;
            ret /= factor(begin);
        }
        else
            break;
    }

    return ret;
}

// 四則演算の式をパースして，その評価結果を返す．
int expression(State &begin)
{
    int ret = term(begin);

    while (true) {
        if (*begin == '+') {
            begin++;
            ret += term(begin);
        }
        else if (*begin == '-') {
            begin++;
            ret -= term(begin);
        }
        else
            break;
    }

    return ret;
}


int main()
{
    int N;

    cin >> N;
    cin.ignore();
    for (int i = 0; i < N; i++) {
        string s;
        getline(cin, s);

        State begin = s.begin();
        int ans = expression(begin);

        cout << ans << endl;
    }

    return 0;
}

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

int main() {
    int n;
    cin >> n;
    int ans = 800*n - n/15*200;
    cout << ans << endl; 
}

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

#define all(s) s.begin(), s.end()
#define pb push_back
#define ii pair<int, int>
#define x first
#define y second
#define bit(x, y) ((x >> y) & 1)
#define sz(s) ((int) (s).size())

int main() {
    ios::sync_with_stdio(false); cin.tie(0); 
    cout.tie(0);
    int n;
    cin >> n;
    string s;
    cin >> s;
    s = " " + s;
    vector<int> cnt(n + 1, 0);
    for (int i = 1; i <= n; i++) {
        cnt[i] = cnt[i - 1] + (s[i] == '.');
    }
    int ans = 1e9;
    for (int i = 0; i <= n; i++) {
        int foo = i - cnt[i];
        foo += (cnt[n] - cnt[i]);
        ans = min(ans, foo); 
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 1360
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define watch(x) cout<<"->"<<#x<<" : "<<x<<endl;
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c)) 
typedef long long ll;
typedef unsigned long long llu;
const double PI = 2*acos(0.0);

signed main()
{
	//freopen("","r",stdin);
	//freopen("","w",stdout);
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int d;
	cin>>d;
	if(d==25)
		cout<<"Christmas"<<endl;
	else if(d==24)
		cout<<"Christmas Eve"<<endl;
	else if(d==23)
		cout<<"Christmas Eve Eve"<<endl;
	else if(d==22)
		cout<<"Christmas Eve Eve Eve"<<endl;
	return 0;
}

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

int main(void){
    int n;
    cin >> n;
    vector<int> a(n);

    int mnum = 0;
    for(int i=0;i<n;i++){
        cin >> a[i];
        if(a[i]<0){
            a[i] *= -1;
            mnum++;
        }
    }
    sort(a.begin(),a.end());

    ll ans = 0;
    if(mnum%2==1) ans -= a[0];
    else ans += a[0];
    for(int i=1;i<n;i++) ans += a[i];
    cout << ans << endl;

}

Measured memory_bytes: 640
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, M = map(int, readline().split())
    S = readline().strip()

    S = S[::-1]
    idx = 0
    ans = []
    while idx < N:
        step = 0
        for i in range(1, M + 1):
            if S[idx + i] == '0':
                step = i
            if idx + i == N:
                break
        if step == 0:
            print(-1)
            return
        ans.append(step)
        idx += step

    print(*reversed(ans))
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 84804
import sys
from collections import defaultdict

read = sys.stdin.read
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7


def main():
    X, Y = map(int, readline().split())
    ans = 0
    if X==1:
        ans += 300000
    elif X==2:
        ans += 200000
    elif X==3:
        ans += 100000
    else:
        pass
    if Y==1:
        ans += 300000
    elif Y==2:
        ans += 200000
    elif Y==3:
        ans += 100000
    else:
        pass
    if X==Y==1:
        ans += 400000
    print(ans)


if __name__ == '__main__':
    main()


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

int main(){
    int N, K, s=0;
    string S;
    vector<int> v;
    cin >> N >> K;
    cin >> S;
    bool st = false;
    repc(i, S.begin(), S.end()){ // 2i - 2i+2K+1
        if(st){
            if(*i == '0'){
                s++;
            }else{
                v.push_back(s);
                s = 1;
                st = false;
            }
        }else{
            if(*i == '1'){
                s++;
            }else{
                v.push_back(s);
                s = 1;
                st = true;
            }
        }
    }
    v.push_back(s);
    int max = 0;
    if(v.size() % 2 == 0){
        v.push_back(0);
    }
    if(v.size() < 2*K+3){
        cout << accumulate(v.begin(), v.end(), 0) << endl;
    }else{
        int sum = accumulate(v.begin(), v.begin() + 2 * K + 1, 0);
        int max = sum;
        for(auto i = v.begin(); i+2*K+1 != v.end(); i+=2){
            sum = sum - *(i) - *(i+1) + *(i+2*K+1) + *(i+2*K+2);
            if (max < sum){
                max = sum;
            }
        }
    cout << max << endl;
    }
    return 0;
}

Measured memory_bytes: 1020
import java.util.*;

public class Main {
  public static void main(String args[]) {
    Scanner sc = new Scanner(System.in);
    int A=0, Z=0;
    String S = sc.next();
    int s = S.length();
    for(int i=0; i<s; i++) {
      if(S.substring(i,i+1).equals("Z")) {
        Z= i+1;
      }
    }
    for(int j=0; j<s; j++) {
      if(S.substring(j,j+1).equals("A")) {
        A= j+1;
        break;
      }
    }
    System.out.println(Z - A + 1);
  }
}

Measured memory_bytes: 52356
# 二項係数のmod
def cmb(n, r, mod):
    if (r < 0 or r > n):
        return 0
    r=min(r,n-r)

    return g1[n] * g2[r] * g2[n - r] % mod

mod = 10 ** 9 + 7
N = 10 ** 6 # 出力の制限
g1 = [1, 1]  # 元テーブル
g2 = [1, 1]  # 逆元テーブル
inverse = [0, 1]  # 逆元テーブル計算用テーブル

for i in range(2, N + 1):
    g1.append((g1[-1] * i) % mod)
    inverse.append((-inverse[mod % i] * (mod // i)) % mod)
    g2.append((g2[-1] * inverse[-1]) % mod)

x,y= map(int, input().split())

v=abs(x-y)
if min(x,y)-v>=0 and (min(x,y)-v)%3==0:
    r=(min(x,y)-v)//3+v
    l=(min(x,y)-v)//3
    ans=cmb(r+l,l,mod)
    print(ans)
else:
    print(0)

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


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

  long long ans = 0;
  for(long long ii=2; ii*ii<=N; ii++){
    if(N%ii==0){
      long long num = 0;
      while(N%ii==0){
        num++;
        N /= ii;
      }
      ans += (long long) ((sqrt(1 + 8*num) - 1) / 2);
    }
  }
  if(N>1) ans++;

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


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

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

    priority_queue<int,vector<int>,greater<int>> que;

    int sum=0;
    for(int i=0;i<N;i++){
        int s;
        cin >> s;
        sum+=s;
        que.push(s);
    }

    if(sum%10){
        cout << sum;
    }else{
        for(int i=0;i<N;i++){
            if((sum-que.top())%10){
                sum -= que.top();
                break;
            }
            que.pop();
        }

        if(sum%10){
            cout << sum;
        }else{
            cout << 0;
        }
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <set>
#include <cmath>
#include <map>
#include <cstring>
#include <stack>
#include <cstdio>
#include <complex>
#include <iomanip>
#include <cctype>
#include <cassert>
#include <numeric>
#include <climits>
#include <deque>
#include <random>
#include <functional>
#include <unordered_map>
#define rep(i,n) for(int i=0;i < (int)(n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define show(x) cout << #x << " = " << x << endl;
int main(){
    string s;
    cin >> s;
    rep(i,2){
        if(!(stoi(s.substr(i,3))%111)){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout <<"No" << endl;
}

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

int main() {
  int n, k; cin >> n >> k;
  for (int i = 0; i < n; ++i) {
    int t; cin >> t;
  }
  cout << ceil(float(n-1)/float(k-1)) << endl;
  return 0;
}


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

int main() {
    int n;
    cin >> n;
    int v[n];
    int even[100001] = {}, odd[100001] = {};
    rep(i, 0, n) {
        cin >> v[i];
        if (i % 2 == 0) even[v[i]]++;
        else odd[v[i]]++;
    }

    if (n == 2) {
        if (v[0] == v[1]) cout << 1 << endl;
        else cout << 0 << endl;
        return 0;
    }

    vector<pair<int, int>> ev, od;
    rep(i, 0, 100001) {
        if (even[i] != 0) {
            ev.push_back(make_pair(even[i], i));
        }
        if (odd[i] != 0) {
            od.push_back(make_pair(odd[i], i));
        }
    }

    sort(all(ev));
    sort(all(od));

    int len_ev = ev.size();
    int len_od = od.size();

    int ans = 0;
    if (ev[len_ev - 1].second != od[len_od - 1].second) {
        ans = (n / 2) - ev[len_ev - 1].first + (n / 2) - od[len_od - 1].first;
    } else {
        if (len_ev == 1 && len_od == 1) {
            ans = n / 2;
        } else if (len_ev == 1) {
            ans = (n / 2) - od[len_od - 1].first;
        } else if (len_od == 1){
            ans = (n / 2) - ev[len_ev - 1].first;
        } else {
            int x = (n / 2) - ev[len_ev - 2].first + (n / 2) - od[len_od - 1].first;
            int y = (n / 2) - ev[len_ev - 1].first + (n / 2) - od[len_od - 2].first;
            ans = min(x, y);
        }

    }

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


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

signed main(){
  int N;cin>>N;
  int a,b;cin>>a;
  for(int i=0;i<N-1;i++){
    cin>>b;
    a=__gcd(a,b);
  }
  cout<<a<<endl;
}


Measured memory_bytes: 256
fiblist = [0] * 100001
fiblist[0] = 1
fiblist[1] = 1
for p in range(2,100001):
    fiblist[p] = (fiblist[p-1]+fiblist[p-2]) % 1000000007

n,m = map(int,input().split())

if m == 0:
    print(fiblist[n])
else:
    a = []
    for i in range(m):
        a.append(int(input()))

    d = [a[0]-1]
    for j in range(1,m):
        d.append(a[j]-a[j-1]-2)

    d.append(n-a[m-1]-1)




#print(d)

    if (-1 in d) or (-2 in d):
        print(0)
    else:
        ans = 1
        for k in range(m+1):
            ans = (ans * fiblist[d[k]]) % 1000000007

        print(ans)


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

int main(){
	int X, A, B;
	cin >> X >> A >> B;
	if(A>=B) cout << "delicious" << endl;
	if(B>A&&A+X>=B) cout << "safe" << endl;
	if(B>A&&B>A+X) cout << "dangerous" <<endl;
}


Measured memory_bytes: 256
import sys, math
from functools import lru_cache
import numpy as np
import heapq
from collections import defaultdict
sys.setrecursionlimit(10**9)
MOD = 10**9+7

def input():
    return sys.stdin.readline()[:-1]

def mi():
    return map(int, input().split())

def ii():
    return int(input())

def i2(n):
    tmp = [list(mi()) for i in range(n)]
    return [list(i) for i in zip(*tmp)]


def lcm(a, b):
    return a*b//math.gcd(a, b)


def main():
    N, A, B = mi()
    if A > B or (N == 1 and A != B):
        print(0)
        return

    print((B-A)*(N-2)+1)

if __name__ == '__main__':
    main()


Measured memory_bytes: 27064
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define mfill(x,y) memset(x,y,sizeof(x))
#define all(v) v.begin(), v.end()
#define y0 y12345
#define y1 y54321

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

using ul = unsigned long;
using ll = long long;
using P = pair<int, int>;
using vint = vector<int>;
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(a>b){a=b;return 1;}return 0;}

vint dx = {-1, 0, 1, 0}, dy = {0, -1, 0, 1};
vint dx8 = {-1, -1, -1, 0, 1, 1, 1, 0}, dy8 = {-1, 0, 1, 1, 1, 0, -1, -1};

int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
	debug("debug test\n");
   	int n,m;int k;
	cin>>n>>m>>k;
	if(n<=k && k <= m){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}
	return 0;
}


Measured memory_bytes: 256
import Control.Monad
import Control.Applicative
import Data.Functor
import Data.List
import Data.Char

readInt = readLn :: IO Int
readInts = map read . words <$> getLine :: IO [Int]

cond t f c = if c then t else f

judge s = a ^ 2 + b ^ 2 == c ^ 2
  where
    [a,b,c] = sort s

main = readLn >>= flip replicateM readInts >>= mapM_ (putStrLn . cond "YES" "NO" . judge)

Measured memory_bytes: 4428
T = [int(input()) for _ in range(5)]
T_0 = [t for t in T if t % 10 == 0]
T_non_0 = [t for t in T if t % 10 != 0]
T_non_0.sort(key=lambda x: x % 10)

time = 0
time += sum(T_0)
head = 1
for t in T_non_0:
    if head:
        time += t
        head = 0
    else:
        time += -(-t // 10) * 10

print(time)


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

using ll = long long;

#define for_(i, a, b) for(int i = (a);i < (b);++i)
#define rfor_(i, a, b) for(int i = (b)-1;i >= (a);--i)
#define rep(i, n) for_(i, 0, n)
#define rrep(i, n) rfor_(i, 0, n)

int K;

int main() {
  cin.tie(0);cout.tie(0);
  ios_base::sync_with_stdio(false);
  
  cin>>K;
  
  int e = K/2;
  int o = K - e;
  
  cout<<e*o<<endl;

  return 0;
}


Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Split(bufio.ScanWords)
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func DupToken(x string) []string {
	tokens := []string{}

	i := 0
	for ; i < len(x); {
		j := i+1
		for ; j < len(x); {
			if x[i] != x[j] {
				break
			}
			j ++
		}

		tokens = append(tokens, x[i:j])
		i = j
	}

	return tokens
}

func main() {
	var n int
	fmt.Scanf("%d", &n)
	var s string
	fmt.Scanf("%s", &s)
	fmt.Printf("%d", len(DupToken(s)))
}


Measured memory_bytes: 7552
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cmath>
#include <algorithm>
#include <utility>
#include <functional>
#define debug(x) cout << #x << " = " << x << endl
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define repr(i,n) for(int i = (n); i > -1; i--)
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const double EPS = 1e-9;

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

  string s,t;
  cin>>s>>t;
  char sc[s.size()], tc[t.size()];
  rep(i, s.size()) sc[i] = s[i];
  rep(i, t.size()) tc[i] = t[i];
  sort(sc, sc + s.size());
  sort(tc, tc + t.size(), greater<char>());
  rep(i, s.size()) s[i] = sc[i];
  rep(i, t.size()) t[i] = tc[i];
  if(s < t) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }


  return 0;
}


Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;
class Program
{
    static void Main(string[] args)
    {
        string[] s = Console.ReadLine().Split(' ');
        Console.WriteLine(
            s[0][0] == s[1][0] ? "=" :
            s[0][0] > s[1][0] ?
            ">" : "<");

    }
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
vector <int> dish(5);
vector <int> order;
int ans = INT_MAX;
int getTime(){
    int ret = 0;
    for(int i = 0; i < 4; i++){
        ret+=dish[order[i]];
        if(ret%10!=0){
            ret+=(10-ret%10);
        }
        //cout << ret << " ";
    }
    ret+=dish[order[4]];
    //cout << ret << endl;
    return ret;
}
bool isValid(){
    for(int i = 0; i < 5; i++){
        for(int j = i+1; j < 5; j++){
            if(i!=j){
                if(order[i]==order[j]){
                    return false;
                }
            }
        }
    }
    return true;
}
void dfs(int index){
    order.push_back(index);
    if(order.size()==5){
        if(isValid()){
            for(int i = 0; i < 5; i++){
                //cout << dish[order[i]] << " ";
            }
            //cout << endl;
            //cout << getTime() << endl;
            ans = min(ans,getTime());
        }
        return;
    }
    for(int i = 0; i < 5; i++){
        dfs(i);
        order.pop_back();
    }
}
int main(){
    for(int i = 0; i < 5; i++){
        cin >> dish[i];
    }
    for(int i = 0; i < 5; i++){
        dfs(i);
        order.pop_back();
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3656
import sys
from collections import Counter
from collections import deque
import heapq
import math
import fractions
import bisect
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))

h,w,d=mp()
l=[[]for i in range(h*w+1)]
for i in range(h):
    a=lmp()
    for k in range(w):
        l[a[k]]=[i,k]
ans=[0]*(h*w+1)
for i in range(1,d+1):
    for k in range((h*w-i)//d):
        ans[i+(k+1)*d]=ans[i+k*d]+abs(l[i+k*d][0]-l[i+(k+1)*d][0])+abs(l[i+k*d][1]-l[i+(k+1)*d][1])
q=int(input())
for i in range(q):
     l,r=mp()
     print(ans[r]-ans[l])

Measured memory_bytes: 90616
using System;
using System.Collections.Generic;
using System.Linq;

namespace AtcoderCS
{
    class Program
    {
        static void Main(string[] args)
        {
            string s = Console.ReadLine();
            var arg = s.Split().Select(a => long.Parse(a)).ToArray();

            long N = arg[0];
            long K = arg[1];

            string s1 = Console.ReadLine();
            long[] P = s1.Split().Select(a => long.Parse(a)).ToArray();

            string s2 = Console.ReadLine();
            long[] C = s2.Split().Select(a => long.Parse(a)).ToArray();

            bool[] flags = new bool[N];

            for(int i = 0; i < N; i++)
            {
                flags[i] = false;
            }

            long answer = -10000000000;
            for(int i = 0; i < N; i++)
            {
                if (!flags[i])
                {
                    List<long> series = new List<long>();
                    series.Add(i);
                    int lastIndex = i;
                    flags[i] = true;
                    while (!series.Contains(P[lastIndex] - 1))
                    {
                        series.Add(P[lastIndex] - 1);

                        lastIndex = (int)P[lastIndex] - 1;

                        flags[lastIndex] = true;
                    }


                    long circleTotal = 0;

                    foreach(var c in series)
                    {
                        circleTotal += C[c];
                    }

                    int count = series.Count;


                    for (int k = 0; k < count; k++)
                    {
                        long modTotal = 0;
                        for (int j = 0; j < Math.Min(K, count); j++)
                        {
                            modTotal += C[series[(j + k) % count]];



                            long add = Math.Max(circleTotal * ((K-j-1) / count), 0);


                            if (modTotal + add > answer)
                            {
                                answer = modTotal + add;
                            }
                        }
                    }


                }
            }

            Console.WriteLine(answer);
        }
    }
}


Measured memory_bytes: 29516
N, T = map(int, input().split())
CT = [tuple(map(int, input().split())) for _ in range(N)]

*CTf, = filter(lambda ct: ct[1] <= T, CT)
if not CTf:
	print("TLE")
	exit()

minimum = min(CTf, key=lambda ct:ct[0])
print(minimum[0])


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

using namespace std;

int main(){
    int n, m;
    cin >> n >> m;
    string S;
    cin >> S;
    vector<int> zeros;

    for (int i = n; i >= 0; i--){
        if (S[i] == '0')
            zeros.push_back(i);
    }

    vector<int> ans;

    int cur = 0;
    while(cur != zeros.size() - 1){
        int next = cur;
        for (; next < zeros.size(); next++){
            if (next == zeros.size() - 1)
                break;
            
            if (zeros[cur] - zeros[next + 1] > m)
                break;
        }
        if (next == cur){
            cout << -1 << endl;
            return 0;
        }
        ans.push_back(zeros[cur] - zeros[next]);
        cur = next;
    }
    
    copy(ans.rbegin(), ans.rend(), ostream_iterator<int>(cout, " "));
}

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

#define INF ((int)1e9)

struct Edge {
  int to, cost;
  Edge(int t, int c) : to(t), cost(c) {}
};

typedef pair<int, int> Pii;
typedef pair<int, Pii> Piii; // cost, node, cnum

vector<Edge> G[100];
int memo[100][10];

int dijkstra(int src, int dst, int cnum) {
  
  fill(memo[0], memo[0]+1000, INF);
  
  priority_queue<Piii> pq;
  memo[src][cnum] = 0;
  pq.push(Piii(0, Pii(src, -cnum)));
  while(!pq.empty()) {
    const Piii get = pq.top(); pq.pop();
    int cost = get.first;
    int cn = -get.second.second;
    int now = get.second.first;
    
    for(int i=0; i<G[now].size(); i++) {
      int next = G[now][i].to;
      int add_c = G[now][i].cost;
      if(memo[next][cn] > cost + add_c) {
	pq.push(Piii(cost+add_c, Pii(next, -cn)));
	memo[next][cn] = cost + add_c;
      }
      if(cn-1<0) continue;
      add_c /= 2;
      if(memo[next][cn-1] > cost + add_c) {
	pq.push(Piii(cost+add_c, Pii(next, 1-cn)));
	memo[next][cn-1] = cost + add_c;
      }
    }
  }
  
  return *min_element(memo[dst], memo[dst]+10);
}

int main() {
  int C, N, M, S, D;
  while(cin >> C >> N >> M >> S >> D && (N|M)) {
    for(int i=0; i<N; i++) {
      G[i].clear();
    }
    for(int i=0; i<M; i++) {
      int a, b, c; cin >> a >> b >> c; a--, b--;
      G[a].push_back(Edge(b, c));
      G[b].push_back(Edge(a, c));
    }
    
    S --, D --;
    cout << dijkstra(S, D, C) << endl;
  }
  
  return 0;
}

Measured memory_bytes: 1232
X,Y=map(int,input().split())
count=0
for x1 in range(X+1):
    for x2 in range(X+1):
        if x1+x2<=X and x1+x2>=X:
            if (x1*2)+(x2*4)==Y: count+=1
if count!=0: print("Yes")
else: print("No")

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

int ans=1001001001;

int n,m,x;
vector<vector<int>> a(n,vector<int>(m));
vector<int> c(n);
//vector<ll> ri(n);

void dfs(int i,int cal,vector<ll> ri){
  if(n==i){
    bool ok=true;
    for(int p=0;p<m;++p){
      //cout << ri[p] << " ";
      if(ri[p]<x) ok=false;
    }
    //cout << endl;
    if(ok){
      ans=min(ans,cal);
    }
    return;
  }
  if(cal>0){
    dfs(i+1,cal,ri);
    cal+=c[i];
    for(int j=0;j<m;++j){
      ri[j]+=a[i][j];
    }
    dfs(i+1,cal,ri);
  }else{
    cal+=c[i];
    for(int j=0;j<m;++j){
      ri[j]+=a[i][j];
    }
    dfs(i+1,cal,ri);
  }
}

int main(){
  cin >> n >> m >> x;
  a=vector<vector<int>>(n,vector<int>(m));
  c=vector<int>(n);
  vector<ll> ri(m);
  for(int i=0;i<n;++i){
    cin >> c[i];
    for(int j=0;j<m;++j){
      cin >> a[i][j];
    }
  }
  for(int i=0;i<m;++i){
    int num=0;
    bool ok=true;
    for(int j=0;j<n;++j){
      num+=a[j][i];
    }
    //cout << num << endl;
    if(num<x){
      cout << "-1" << endl;
      return 0;
    }
  }
  for(int i=0;i<n;++i){
    dfs(i,0,ri);
  }
  cout << ans << endl;
  return 0;

}


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

int N, M, mem[100005];
bool vis[100005];
vector<int> adj[100005];

int dp(int n) {
	if (mem[n] != -1) return mem[n];
	mem[n] = 0;
	for (auto u : adj[n])
		mem[n] = max(mem[n], dp(u) + 1);
	return mem[n];
}

main() {
	memset(mem, -1, sizeof mem);
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> N >> M;
	for (int u, v; M--; ) {
		cin >> u >> v;
		adj[v].push_back(u);
	}
	for (int i = 1; i <= N; i++) dp(i);
	cout << *max_element(mem + 1, mem + 1 + N) << '\n';
}


Measured memory_bytes: 9472
#include <bits/stdc++.h>
#define pb push_back
#define cmin(a,b) (a>b?a=b:a)
#define cmax(a,b) (a<b?a=b:a)
#define mem(a,k) memset(a,k,sizeof(a))
#define lop(i,s,t) for(int i=s;i<(t);++i)
#define rep(i,s,t) for(int i=s;i<=(t);++i)
#define dec(i,s,t) for(int i=s;i>=(t);--i)
#define fore(i,v) for(int i=g[v],d=es[i].d;i;i=es[i].nxt,d=es[i].d)
using namespace std;

typedef long long ll;

template<typename T>
void read(T &x){
	x=0; 
	char c;
	for(c=getchar();!isdigit(c);c=getchar()); 
	for(;isdigit(c);c=getchar())x=x*10+c-'0'; 
}

const int N=4005,P=924844033; 

int mul(int a,int b){ return 1ll*a*b%P; } 
int add(int a,int b){ a+=b; return a>=P?a-P:a; }

int ans,n,k,m,e[N],fac[N],f[N][N][2],vis[N][N];

int main(int argc,char *argv[]){
#ifdef CURIOUSCAT
	//freopen("dat.in","r",stdin);
	//freopen("my.out","w",stdout);
#endif
	read(n);
	read(k); 
	fac[0]=1; 
	rep(i,1,n+n)fac[i]=mul(fac[i-1],i);
	
	rep(i,1,n)rep(j,0,1)if(!vis[i][j]){
		int x,y,c;
		for(x=i,y=j,c=0;x<=n&&!vis[x][y];x+=k,y^=1)vis[x][y]=1,++c;
		e[(m+=c)+1]=1;
	}	

	f[0][0][1]=1;
	rep(i,1,m)rep(j,0,i){
		f[i][j][0]=add(f[i-1][j][1],f[i-1][j][0]); 
		if(!e[i]&&j)f[i][j][1]=f[i-1][j-1][0];
	}
	rep(k,0,n){
		int t=add(f[m][k][0],f[m][k][1]); 
		ans=add(ans,mul((k&1)?-1+P:1,mul(t,fac[n-k])));
	}
	printf("%d\n",ans); 
	return 0;
}


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

int main(){
  int a,count=0;
  cin >> a;
  vector<int> mama(a);
  for (int i=0;i<a;i++){
    cin >> mama.at(i);
  }
  sort(mama.begin(),mama.end());
  for (int i=0;i<a;i++){
    for (int j=i+1;j<a;j++){
      if (mama.at(i)==mama.at(j)) continue;
      for (int k=j+1;k<a;k++){
        if (mama.at(j)==mama.at(k)) continue;
        if (mama.at(i)+mama.at(j) > mama.at(k)) count ++;
      }
    }
  }
  
  cout << count << endl;
}

Measured memory_bytes: 3600
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
#define N 20010
#define inf 2^32-1
char a[81];
int main()
{
    int x,t;
    while(cin>>x>>t){
        int s;
        if(x<=t) s=0;
        else s=x-t;
        cout<<s<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
using ll = long long;
using P = pair<int,int>;
using PP = pair<int,pair<int,int>>;
using T = tuple<string,int,int>;
const ll INF = 1LL<<60;
const int ny[4] = {-1,1,0,0}, nx[4] = {0,0,-1,1};
int sy,sx,gy,gx;

int main(){
  int n; cin >> n;
  double jpy = 0, btc = 0;
  rep(i,n){
    double x;
    string s;
    cin >> x >> s;
    if(s == "JPY") jpy += x;
    else btc += x;
  }
  double x = btc * 380000.0;
  double ans = x + jpy;
  printf("%.10f\n%", ans);
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
using namespace std;
int ans,a,b,c,p[100001],n,m,q[100001],k=0;
signed main()
{
    cin>>n>>m;
    cin>>p[1];
    for(int i=2;i<=m;++i)
    {
        cin>>p[i];
        int x=min(p[i],p[i-1]);
        int y=max(p[i],p[i-1]);
        q[x]++;
        q[y]--;
    }
    q[0]=0;
    for(int i=1;i<n;++i)
    {
        cin>>a>>b>>c;
        q[i]+=q[i-1];
        ans+=min(a*q[i],b*q[i]+c);
    }
    cout<<ans<<endl;
}

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

#define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define int long long int
#define fi first
#define se second
#define pub push_back
#define mkp make_pair
#define pi pair<int,int>
#define push push
#define all(v) v.begin(),v.end()
#define rep(i,l,r) for(int i = (int)(l) ; i < (int)(r) ; i++)
#define clr(a,x) memset(a,x,sizeof(a));
#define rr(v) for(auto &val:v)
#define print(v) for(const auto itr:v){ cout << itr << ' ';} cout << endl;
#define init(v,x) for(auto &itr:v){ itr = x; }
#define minpq(x) x,vector<x>,greater<x>
#define ln length()
#define sz size()
#define infinity 1e18;
#define elif else if

void addEdge(vector<pi> adj[],int u,int v,int wt) {
    adj[u].pub(mkp(v,wt));
    adj[v].pub(mkp(u,wt));
}


int32_t main(){
    fastIO
    int n;
    string ans;
    
    cin >> n;
    
    while(n > 0) {
        n -= 1;
        ans += ('a' + n%26);
        n /= 26;
    }
    
    reverse(all(ans));
    
    cout << ans << endl;
    
    return 0;
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define ceiv(a, b) (1 + (int)((a) - 1)/(int)(b))
//#define int long long

signed main(){
    int n; cin >> n;
    vector<int> place(n+2), dist(n+2);
    
    place[0] = place[n+1] = dist[0] = 0;
    rep(i,n){
        cin >> place[i+1];
        dist[i+1] = dist[i] + abs(place[i+1] - place[i]);
    }
    
    dist[n+1] = dist[n] + abs(place[n]);
    
    reps(i, 1, n){
        int d = dist[n+1];
        d -= dist[i+1] - dist[i-1];
        d += abs(place[i+1] - place[i-1]);
        cout << d << endl;
    }
}

Measured memory_bytes: 2048
from math import gcd
from collections import Counter
n = int(input())
a = list(map(int,input().split()))
a.sort()
if n == 1:
    print(1)
    quit()
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a
M = max(a)
cnt = [0]*(M+1)
ans = 0
for i in range(n):
    if cnt[a[i]]:
        continue
    j = a[i]
    if i == 0:
        if a[i] == a[i+1]:
            1
        else:
            ans += 1
    elif i == n-1:
        if a[i-1] == a[i]:
            1
        else:
            ans += 1
    elif a[i] == a[i+1] or a[i-1] == a[i]:
        1
    else:
        ans += 1
    while j <= M:
        cnt[j] = 1
        j += a[i]
print(ans)

Measured memory_bytes: 104052
#include<bits/stdc++.h>
#define ll long long
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define dump(a) (cerr << #a << "=" << (a) << endl)
#define DUMP(list) cout << "{ "; for(auto nth : list){ cout << nth << " "; } cout << "}" << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }


using namespace std;

int main(){
     ll N;
     cin >> N;
     ll ans = 1000;
     for(ll i = 1; i*i <= N; i++) {
         if (N % i == 0){
             ll res = i;
             ll res1 = N/i;
             ll l = 0;
             while(res > 0) {
                 res/= 10;
                 l++;
             }
             ll l1 = 0;
             while(res1 > 0) {
                 res1/= 10;
                 l1++;
             }
             chmin(ans, max(l, l1));
         }
     }

     cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <climits>
using namespace std;
 
int main(){
 
    int n;
    cin >> n;
 
    vector<int> a(n);
    for(int i = 0; i < n; i++) cin >> a[i];
 
    int max = *max_element(a.begin(), a.end());
    
    if(n % 2 == 1){
        int mid = (max / 2) + 1;
 
        int nearest, min = INT_MAX;
        for(int i = 0; i < n; i++){
            if(min >= abs(mid - a[i]) && a[i] != max){
                min = abs(mid - a[i]);
                nearest = a[i];
            }
        }
 
        cout << max << " " << nearest << endl;
    }else{

        int mid1 = (max / 2);
        int mid2 = mid1 + 1;
 
        int nearest, min = INT_MAX;
        for(int i = 0; i < n; i++){
            if(min >= abs(mid1 - a[i]) && a[i] != max){
                min = abs(mid1 - a[i]);
                nearest = a[i];
            }
            if(min >= abs(mid2 - a[i]) && a[i] != max){
                min = abs(mid2 - a[i]);
                nearest = a[i];
            }
        }
 
        cout << max << " " << nearest << endl;
    }
 
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
const int INF = 100010001;
const ll LINF = (ll)INF*INF*10;
 
int main() {
    fastIO
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, t;
    cin >> n >> t;
    vector<P> a(n);
    rep(i, n) {
        cin >> a[i].first >> a[i].second;
    }
 
    sort(all(a));
 
    vi dp(t, -1);
    dp[0] = 0;
    int ans = 0;
    rep(i, n) {
        for(int j = t-1; j >= 0; --j) {
            if(dp[j] != -1) {
                if(j+a[i].first < t) {
                    dp[j+a[i].first] = max(dp[j+a[i].first], dp[j]+a[i].second);
                } else {
                    ans = max(ans, dp[j]+a[i].second);
                }
            }
        } 
    }
 
    rep(i, t) {
        ans = max(ans, dp[i]);
    }
 
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>
#include <numeric>
#include <queue>
#include <stack>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9) + 7;

int main(void) {
	int n, h;
	cin >> n >> h;
	
	vector<int> a(n), b(n);
	for(int i = 0; i < n; ++i) {
		cin >> a[i] >> b[i];
	}

	sort(b.begin(), b.end(), greater<int>());
	
	int x = *max_element(a.begin(), a.end());
	int ans = 0;
	
	for(int i = 0; i < n; ++i) {
		if( h > 0 && x < b[i] ) {
			h -= b[i];
			ans++;
		}
	}
	
	if( h > 0 ) { 
		if( h % x == 0 ) ans += h / x;
		else ans += h / x + 1;
	}
	
	cout << ans << endl;
	
	return 0;
}


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

using ll=long long;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  int ans = -1;
  int sum = 0;
  rep(i,m){
    int A;
    cin >> A;
    sum += A;
  }
  if(sum <= n) ans = n-sum ;
  cout << ans << endl;
}

Measured memory_bytes: 3652
#include<stdio.h>
int main()
{
  int i,n,a[100];
  
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
  }
  for(i=0;i<n;i++){
    if(a[i]%2==0&&a[i]%3!=0&&a[i]%5!=0){
      puts("DENIED");
      return 0;
    }
  }
  puts("APPROVED");
  return 0;
}

Measured memory_bytes: 1640
#include <bits/stdc++.h>
#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 SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VRSORT(v) sort(v.begin(), v.end(),greater<long long>());
#define ALL(X) (X).begin(),(X).end()
#define INF 99999999
#define M_PI 3.14159265358979323846
#define MOD 1000000007

#ifdef __LOCAL
    #define DBG(X) cout << #X << " = " << (X) << endl;
    #define SAY(X) cout << (X) << endl;
#else
    #define DBG(X)
    #define SAY(X)
#endif

#ifdef __LOCAL
    #include <filesystem>
    namespace fs = std::filesystem;
#endif

using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

int dx[]={1, 0, -1, 0, 0};
int dy[]={0, 1, 0, -1, 0};
const int INT_INF = (int)(2e9);
const ll  LL_INF = (ll)(2e18);
const int NIL = -1;
static mt19937 _g(time(nullptr));
 
std::string pad(int num){ char buffer[4]; std::snprintf(buffer, sizeof(buffer), "%03d", num); return buffer;}
inline ll randint(ll a, ll b) { ll w = (_g() << 31LL) ^ _g(); return a + w % (b - a + 1); }
inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T> inline T sign(T x) { return T(x > 0) - T(x < 0); }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const map<T, S> p) { for (auto el : p) os << "[" << el.first << " " << el.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) os << el << " "; return os; }
template<typename T> inline T fetch() { T ret; cin >> ret; return ret; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; }

string s,t;

void input(){
    fast_io();
    #ifdef __LOCAL
        fs::path p = __FILE__;
        fs::path input,output;
        input = output = p.parent_path();
        input += string("/input/") + string(p.stem()) + string(".txt");
        output += string("/output/") + string(p.stem()) + string(".txt");
        freopen(input.c_str(), "r", stdin);
        freopen(output.c_str(), "w", stdout);
    #endif
    cin >> s >> t;
}

int solve(){
  int n = s.size();
  int m = t.size();
  vector<vector<int>> dp(n+1,vector<int>(m+1));
  for (int  i = 1; i <= n; i++)
  {
    for (int j = 1; j <= m; j++)
    {
      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]);
    }
  }
  string r;
  int i=n;
  int j=m;
  while(i && j){
    if(s[i-1]==t[j-1]){
      r+=s[i-1];
      i--;
      j--;
    }
    else if(dp[i-1][j]<dp[i][j-1]) j--;
    else i--;
  }
  reverse(r.begin(),r.end());
  cout << r << endl;
  return 0;
}

// この問題DPで解けるん？？！？！？！
int main()
{
    input();
    solve();
    return 0;
}


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

using namespace std;

int main()
{
    int x;
    cin >> x;
    if(400<=x && x<=599){
       cout<<8<<endl;
    }else if(600<=x && x<=799){
        cout<<7<<endl;
    }else if(800<=x && x<=999){
        cout<<6<<endl;
    }else if(1000<=x && x<=1199){
        cout<<5<<endl;
    }else if(1200<=x && x<=1399){
        cout<<4<<endl;
    }else if(1400<=x && x<=1599){
        cout<<3<<endl;
    }else if(1600<=x && x<=1799){
        cout<<2<<endl;
    }else if(1800<=x && x<=1999){
        cout<<1<<endl;
    }
}


Measured memory_bytes: 3620
/* Dsingh_24 */

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

#define N  100005
ll vis[1002][1002];
int main()
{
	ios
	ll n,m,i,j;
	cin>>n>>m;
	string s[n+1];
	queue<pii>q;
	for(i=1;i<=n;i++){
		cin>>s[i];
		s[i]=' '+s[i];
		for(j=1;j<=m;j++){
			if(s[i][j]=='#')q.push(mp(i,j)),vis[i][j]=1;
		}
	}
	ll ans=0;
	//cout<<q.size()<<"\n";
	while(1){
		queue<pii>p;
		ll flag=0;
		while(!q.empty()){
			auto f=q.front();
			q.pop();
			i=f.F,j=f.S;
			if(i-1>0&&vis[i-1][j]==0)p.push(mp(i-1,j)),vis[i-1][j]=1,flag=1;
			if(j+1<=m&&vis[i][j+1]==0)p.push(mp(i,j+1)),vis[i][j+1]=1,flag=1;
			if(i+1<=n&&vis[i+1][j]==0)p.push(mp(i+1,j)),vis[i+1][j]=1,flag=1;
			if(j-1>0&&vis[i][j-1]==0)p.push(mp(i,j-1)),vis[i][j-1]=1,flag=1;
		}
		q=p;
		//cout<<q.size()<<"\n";
		if(flag)ans++;
		if(q.size()==0){cout<<ans;return 0;}
	}
	return 0;
}


Measured memory_bytes: 26052
//  @ /\/\ BESH //

#include <bits/stdc++.h>
#define inp_out_work ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define testCase    int T; cin>>T; while(T--)
#define fr(i,n) for(int i=0;i<n;i++)
#define fro(i,s,e) for(int i=s;i<=e;i++)
#define endl '\n'
#define debug(P) cout<<#P<<" = "<<P<<endl;
#define pb push_back


using namespace std;

typedef long long ll;
typedef long double ld;

const int MAXN = 100001;
const int mod = 1000000007;

vector<int> adj[MAXN];
int col[MAXN];
map< pair<int,int> , int > edge;

void setEdge(int u, int v, int x){
    if(u>v)swap(u,v);
    edge[make_pair(u,v)] = x;
}

int getEdge(int u, int v){
    if(u>v)swap(u,v);
    return edge[make_pair(u,v)];
}

void dfs(int x, int p, int last_col){
    int curr_col = 1;
    for(int c : adj[x]){
        if(c != p){
            if(curr_col == last_col)++curr_col;
            col[getEdge(x,c)] = curr_col;
            dfs(c, x, curr_col);
            ++curr_col;
        }
    }
}

int main(){
        int n;
        cin>>n;
        fr(i,n-1){
            int u, v;
            cin>>u>>v;
            adj[u].pb(v);
            adj[v].pb(u);
            setEdge(u,v,i+1);
        }
        dfs(1, 0, 0);
        int ans = 0;
        for(int i = 1; i < n; i++)ans = max(ans, col[i]);
        cout<< ans << endl;
        for(int i = 1; i < n; i++)cout<< col[i] << endl;
}


Measured memory_bytes: 15744