akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

using int64 = long long;
const int mod = 998244353;

const int64 infll = (1LL << 62) - 1;
const int inf = (1 << 30) - 1;

struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    cerr << fixed << setprecision(10);
  }
} iosetup;


template< typename T1, typename T2 >
ostream &operator<<(ostream &os, const pair< T1, T2 > &p) {
  os << p.first << " " << p.second;
  return os;
}

template< typename T1, typename T2 >
istream &operator>>(istream &is, pair< T1, T2 > &p) {
  is >> p.first >> p.second;
  return is;
}

template< typename T >
ostream &operator<<(ostream &os, const vector< T > &v) {
  for(int i = 0; i < (int) v.size(); i++) {
    os << v[i] << (i + 1 != v.size() ? " " : "");
  }
  return os;
}

template< typename T >
istream &operator>>(istream &is, vector< T > &v) {
  for(T &in : v) is >> in;
  return is;
}

template< typename T1, typename T2 >
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

template< typename T1, typename T2 >
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

template< typename T = int64 >
vector< T > make_v(size_t a) {
  return vector< T >(a);
}

template< typename T, typename... Ts >
auto make_v(size_t a, Ts... ts) {
  return vector< decltype(make_v< T >(ts...)) >(a, make_v< T >(ts...));
}

template< typename T, typename V >
typename enable_if< is_class< T >::value == 0 >::type fill_v(T &t, const V &v) {
  t = v;
}

template< typename T, typename V >
typename enable_if< is_class< T >::value != 0 >::type fill_v(T &t, const V &v) {
  for(auto &e : t) fill_v(e, v);
}

template< typename F >
struct FixPoint : F {
  FixPoint(F &&f) : F(forward< F >(f)) {}

  template< typename... Args >
  decltype(auto) operator()(Args &&... args) const {
    return F::operator()(*this, forward< Args >(args)...);
  }
};

template< typename F >
inline decltype(auto) MFP(F &&f) {
  return FixPoint< F >{forward< F >(f)};
}


// 競技プログラミングを引退します
// いままでありがとうございました

int main() {
  vector< string > v = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};
  string S;
  cin >> S;
  auto pos = find(begin(v), end(v), S) - begin(v);
  cout << 7 - pos << endl;
}



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

int main(){
  int n,k; cin >> n >> k;
  int r,s,p; cin >> r >> s >> p;
  string t; cin >>t;
  string dasu;
  int ans = 0;
  for(int i = 0; i < n; i++){
    char janken = t.at(i);
    if(i  - k >= 0){
      if(janken == 'r' and dasu.at(i - k) != 'r'){
        ans += p;
        dasu.push_back('r');
      }
      else if(janken == 's' and dasu.at(i - k) != 's'){
        ans += r;
        dasu.push_back('s');
      }
      else if(janken == 'p' and dasu.at(i - k) != 'p'){
        ans += s;
        dasu.push_back('p');
      }
      else 
        dasu.push_back('a');
    }
    
    else{
      if(janken == 'r') 		ans += p;
      else if(janken == 's')	ans += r;
      else 						ans += s;
      dasu.push_back(janken);
    }
  }
  cout << ans;
}

Measured memory_bytes: 3740
#
# abc087 c
#
import sys
from io import StringIO
import unittest


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """5
3 2 2 4 1
1 2 2 2 1"""
        output = """14"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """4
1 1 1 1
1 1 1 1"""
        output = """5"""
        self.assertIO(input, output)

    def test_入力例_3(self):
        input = """7
3 3 4 5 4 5 3
5 3 4 4 2 3 2"""
        output = """29"""
        self.assertIO(input, output)

    def test_入力例_4(self):
        input = """1
2
3"""
        output = """5"""
        self.assertIO(input, output)


def resolve():
    N = int(input())
    A = [list(map(int, input().split())) for _ in range(2)]

    ans = 0
    if N == 1:
        ans = A[0][0]+A[1][0]
    else:
        #        for i in range(N):
        #            ans = max(ans, sum(A[0])+A[1][N-1],
        #                      sum(A[0][:N-1-i])+sum(A[1][N-1-i-1:]))

        for i in range(N):
            ans = max(ans, sum(A[0])+A[1][-1],
                      sum(A[0][:-2-i+1])+sum(A[1][-2-i:]))

    print(ans)


if __name__ == "__main__":
    # unittest.main()
    resolve()


Measured memory_bytes: 16268
import sys
input = sys.stdin.buffer.readline
from collections import deque

def main():
    N = int(input())
    edge = [[] for _ in range(N)]
    for _ in range(N-1):
        a,b = map(int,input().split())
        edge[a-1].append(b-1)
        edge[b-1].append(a-1)

    
    use = [-1 for _ in range(N)]
    d = [[0],[]]
    use[0] = 0
    q = deque([0])
    while q:
        now = q.popleft()
        for fol in edge[now]:
            if use[fol] == -1:
                use[fol] = (use[now]+1)%2
                q.append(fol)
                d[use[fol]].append(fol)

    ans = [0 for _ in range(N)]
    b = [False for _ in range(N)]
    if len(d[0]) <= N//3:
        l = len(d[0])
        for i in range(l):
            ans[d[0][i]] = 3*i+3
            b[3*i+2] = True
        t = 0
        for num in d[1]:
            while b[t]:
                t += 1
            ans[num] = t+1
            b[t] = True
    elif len(d[1]) <= N//3:
        l = len(d[1])
        for i in range(l):
            ans[d[1][i]] = 3*i+3
            b[3*i+2] = True
        t = 0
        for num in d[0]:
            while b[t]:
                t += 1
            ans[num] = t+1
            b[t] = True
    else:
        l = len(d[0])
        t = 0
        for i in range(l):
            if i < (N-1)//3+1:
                ans[d[0][i]] = 3*i+1
                b[3*i] = True
            else:
                ans[d[0][i]] = 3*t+3
                b[3*t+2] = True
                t += 1
        l = len(d[1])
        for i in range(l):
            if i < (N-2)//3+1:
                ans[d[1][i]] = 3*i+2
                b[3*i+1] = True
            else:
                ans[d[1][i]] = 3*t+3
                b[3*t+2] = True
                t += 1
    
    print(*ans)

if __name__ == "__main__":
    main()


Measured memory_bytes: 58868
rooms = [[[0] * 10 for b in range(3)] for a in range(4)]
n = int(input())
for _ in range(n):
    b, f, r, v = map(int, input().split())
    rooms[b - 1][f - 1][r - 1] += v

for i in range(4):
    for j in range(3):
        print(' ' + ' '.join(map(str, rooms[i][j])))
    if i < 3:
        print('#' * 20)

Measured memory_bytes: 6724
#include<bits/stdc++.h>
using namespace std;
#include<map>
#define MEM(var,val) memset(var,(val),sizeof(var))
#define MAX(a,b) ((a) > (b) ? (a) : (b))
#define MIN(a,b) ((a) < (b) ? (a) : (b))
#define nitro   ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
#define vll vector<ll>
#define pll pair<ll,ll>
#define mp make_pair
#define pb push_back
#define F first
#define S second

ll dp[100][100001];
ll wajan[100],val[100];
ll n;

ll rec(ll i,ll w)
{
    if(i>n-1)
        return 0;
    if(w<=0)
        return 0;
    if(dp[i][w]!=-1)
        return dp[i][w];
        dp[i][w]=rec(i+1,w);
    if(wajan[i]<=w)
        dp[i][w]=MAX(dp[i][w],val[i]+rec(i+1,w-wajan[i]));
    return dp[i][w];
}
int main()
{
    ll w;
    cin>>n>>w;
    MEM(dp,-1);
    for(int i=0;i<n;i++)
        cin>>wajan[i]>>val[i];
        cout<<rec(0,w);

}


Measured memory_bytes: 78336
#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, cnt = 0; cin >> n;
    string a, b, c;
    cin >> a >> b >> c;

    for (int i = 0; i < n; i++)
    {
        if (a[i] != b[i] && b[i] != c[i] && a[i] != c[i]) cnt+=2;
        else if(a[i] == b[i] && b[i] == c[i]) cnt += 0;
        else cnt++;
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 3604
#include <stdio.h>
 
int main(){
    int i, j, prm[1000000];
     
    for(i = 0; i < 1000000; i++) prm[i] = 1;
     
    for(i = 4; i < 1000000; i += 2) prm[i] = 0;
     
    prm[0] = prm[1] = 0;
     
    for(i = 3; i * i < 1000000; i += 2)
        if(prm[i])
            for(j = i + i; j < 1000000; j += i) prm[j] = 0;
                 
    for(i = j = 0; i < 1000000; i++){
        if(prm[i]) j++;
         
        prm[i] = j;
    }
     
    while(scanf("%d", &i) != EOF) printf("%d\n", prm[i]);
     
    return 0;
}

Measured memory_bytes: 5604
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep_s(i, s, n) for (int i = (int)(s); i < (int)(n); i++)
using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;

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

  string ans = "APPROVED";
  rep(i, n) {
    int a;
    cin >> a;
    if (a % 2 == 0) {
      if (a % 3 != 0 && a % 5 != 0) {
        ans = "DENIED";
      }
    }
  }

  cout << ans << endl;
}


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

int main()
{
	int n;
	cin>>n;
	int h;
	cin>>h;
	int a[n];
	int ans=0;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
		if(a[i]>=h)
		{
			ans++; 
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 640
#include <string.h>

#include <algorithm>
#include <iostream>

using namespace std;

int ctoi(char c);

int main(void) {

	string str;
	cin >> str;
	long long sum = 0;
	long long i = 0;

	while (str[i] != '\0') {
		int l = ctoi(str[i]);
		sum += l;
		i++;
	}

	if (sum % 9 == 0) {
		cout << "Yes" << endl;
	}

	else {
		cout << "No" << endl;
	}

	return 0;
}


int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

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

int main(){
	int D;
	cin >> D;
	switch(D){
		case 25:cout << "Christmas" << endl; break;
		case 24:cout << "Christmas Eve" << endl; break;
		case 23:cout << "Christmas Eve Eve" << endl; break;
		case 22:cout << "Christmas Eve Eve Eve" << endl; break;
		default:break;
	}

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void)
{
  int n[3];
  int N;
  int t;
  int i,j;

  scanf("%d",&N);

  while(N--){
    for(i=0;i<3;i++)
      scanf("%d",&n[i]);

    for(i=0;i<2;i++){
      for(j=2;j>i;j--){
        if(n[j]<n[j-1]){
  	  t=n[j];
 	  n[j]=n[j-1];
	  n[j-1]=t;
        }
      }
    }
    if((n[0]*n[0]+n[1]*n[1])==(n[2]*n[2]))
      printf("YES\n");
    else
      printf("NO\n");
   }

  return 0;
}

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

// types
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;

// macros
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

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

  ll n,a,b;
  cin >> n >> a >> b;

  vll x(n);
  REP(i, n)
    cin >> x[i];

  ll ans = 0;
  REP1(i, n)
    ans += min(a*(x[i]-x[i-1]), b);

  cout << ans << endl;
}


Measured memory_bytes: 1024
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}
 
#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};
 
    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
 
    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}
 
#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };
 
    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };
 
    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };
 
    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };
 
    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };
 
    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}



fn main() {
    input! {
        n: usize,
        mut d: [i32; n],
    }
    d.sort();
    println!("{}", d[n/2] - d[n/2-1]);
}


Measured memory_bytes: 4352
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        int N;
        String S;
        String T;
        StringBuilder ans = new StringBuilder();

        Scanner sc = new Scanner(System.in);
        N = sc.nextInt();
        S = sc.next();
        T = sc.next();

        for(int i=0; i<N; i++) {
            ans.append(S.charAt(i)).append(T.charAt(i));
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 21844
#include<iostream>
#include<vector>
#include<map>
#include<string>
#include<cstring>
#include<bitset>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<cstdio>
#include<numeric>
#include<set>
#include<math.h>
using namespace std;

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

#define rep(i,x) for(int i=0;i<x;i++)
#define re(i,x,y) for(int i=x;i<y;i++)

long long INF=1e9;
const int mod=10007;
#define ll long long

int main(){
    ll n;
    cin>>n;
    ll a=sqrt(n);
    ll b=1e12,c=-1,tmp1,tmp2;
    for(int i=1;i<=a;i++){
        if(n%i==0){
            tmp1=n/i;
            tmp2=i;   
        }
        b=min(b,tmp1);
        c=max(c,tmp2);
    }
    cout<<b+c-2<<endl;
    return 0;
}


Measured memory_bytes: 256
import bisect
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))

a.sort()
c.sort()

res = 0

for sb in b:
    resa = bisect.bisect_left(a,sb)
    resc = n - bisect.bisect_right(c,sb)
    res += resa*resc

print(res)

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

signed main() {
    int n;cin>>n;
    int ans[n+1];
    memset(ans,0,sizeof(ans));
    
    for(int x=1;x<=100;x++){
        for(int y=1;y<=100;y++){
            for(int z=1;z<=100;z++){
                int t = x*x+y*y+z*z+x*y+y*z+z*x;
                if(t<=n){
                    ans[t]++;
                }
            }
        }
    }

    for(int i=1;i<=n;i++){
        cout<<ans[i]<<endl;
    }

    return 0;
}

Measured memory_bytes: 3592
#include<stdio.h>

int main(){
  int i,j,k;
  int x,y;
  int N,Y;
  
  scanf("%d %d",&N,&Y);
  
  for(y=0;y<=N;y++){
    for(x=0;x<=(N-y);x++){
      if(Y == ((N-x-y)*1000 + x*5000 + y*10000)){
        printf("%d %d %d\n",y,x,N-x-y);
        return 0;
      }
    }
  }
  puts("-1 -1 -1");
  return 0;
}



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

int main()
{
    int W, H, x, y, r;
    cin >> W >> H >> x >> y >> r;

    if (x-r >= 0 && y-r >=0 && x+r <= W && y+r <= H) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 3080
import heapq

def f(x):
    return -int(x)

N, M = map(int, input().split())
A = list(map(f, input().split()))

A.sort()

for _ in range(M):
    a = A[0]
    heapq.heappop(A)
    heapq.heappush(A, -((-a)//2))
    
print(-sum(A))

Measured memory_bytes: 14180
#dp[i][j] denotes number of ways to distribute j candies among first i
l=input().split()
n=int(l[0])
k=int(l[1])
l=input().split()
li=[int(i) for i in l]
dp=[[0 for i in range(k+1)]for i in range(n+1)]
for i in range(n+1):
    dp[i][0]=1
for i in range(1,k+1):
    dp[0][i]=0
pref=[0 for i in range(k+1)]
sumi=0
for i in range(k+1):
    sumi+=dp[0][i]
    pref[i]=sumi
    pref[i]%=1000000007
for i in range(1,n+1):
    for j in range(1,k+1):
        howmany=li[i-1]
        left=max(0,j-howmany)
        right=j
        if(left==0):
            dp[i][j]=pref[j]
        else:
            dp[i][j]=pref[j]-pref[left-1]
        dp[i][j]%=1000000007
    sumi=0
    for j in range(k+1):
        sumi+=dp[i][j]
        pref[j]=sumi
        pref[j]%=1000000007
print(dp[n][k])


Measured memory_bytes: 173832
#include <iostream>

using namespace std;


int main(int argc, char* argv[]) {
  int X, Y;
  cin >> X >> Y;

  for (int i = 0; i <= X; ++i) {
    if (2 * i + 4 * (X - i) == Y) {
      cout << "Yes" << endl;
      return 0;
    }
  }

  cout << "No" << endl;

  return 0;
}

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

int N, K;
const int MOD = 1.0e9 + 7;

ll modpow(ll a, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

ll modinv(ll a, ll mod) {
    return modpow(a, mod - 2, mod);
}

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

    ll comb[K];
    comb[0] = N - K + 1;
    for (int i = 1; i < K; i++) {
        comb[i] = 1;
        for (int j = 0; j <= i; j++) {
            comb[i] *= (comb[0]-j);
            comb[i] = comb[i] % MOD;
        }
        for (int j = 0; j <= i; j++) {
            ll inv = modinv(j+1, MOD);
            comb[i] *= inv;
            comb[i] = comb[i] % MOD;
        }
        comb[i] = comb[i] % MOD;
    }

    for (int i = 1; i < K; i++) {
        for (int j = 1; j <= i; j++) {
            comb[i] *= (K-j);
            comb[i] = comb[i] % MOD;
        }
        for (int j = 1; j <= i; j++) {
            ll inv = modinv(j, MOD);
            comb[i] *= inv;
            comb[i] = comb[i] % MOD;
        }
        comb[i] = comb[i] % MOD;
    }

    for (int i = 0; i < K; i++) {
        cout << comb[i] << endl;
    }

    return 0;
}


Measured memory_bytes: 256
import collections
N=int(input())
c=collections.Counter()
for i in range(N):
    t=input()
    c[t]+=1
print('AC x {}'.format(c['AC']))
print('WA x {}'.format(c['WA']))
print('TLE x {}'.format(c['TLE']))
print('RE x {}'.format(c['RE']))

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

int main(){
	string S;
	string Ans="CODEFESTIVAL2016";
	cin>>S;
	int ret=0;
	for(int i=0;i<S.size();i++){
		if(S[i]!=Ans[i]){
			ret++;
		}
	}
	cout<<ret<<endl;
	return 0;
}

Measured memory_bytes: 256
N = int(input())
X = list(map(int, input().split()))
ans = 10**18
m = min(X)
M = max(X)

for i in range(m, M+1):
    ans_cand = 0
    
    for Xi in X:
        ans_cand += (i-Xi)**2
    
    ans = min(ans, ans_cand)

print(ans)

Measured memory_bytes: 38896
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<bitset>
#include<vector>
#include<deque>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cmath>
#include<iomanip>
#include <functional>
using namespace std;
typedef long long ll;
const int mod = 1000000007;
const int INF = 1 << 28;
const double EPS = 1e-10;
//cout << fixed << std::setprecision(9)
//memset(a, 0, sizeof(a));
//--------------------------

int a, b, h;

int main()
{
	cin >> a >> b >> h;
	cout << h * (a + b) / 2 << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(v) v.begin(), v.end()

using namespace std;
typedef long long LL;
const LL MOD = 1e9 + 7;
const double PI = 2 * acos(0);

int main() {
	int K;
	scanf("%d", &K);
	vector<string> data;
	queue<string> q;
	for (int i = 1; i <= 9; i++) {
		char tmp = '0' + i;
		string x; x.pb(tmp);
		q.push(x);
	}
	int cnt = 0;
	while (1) {
		if (cnt == 1e5) break;
		string now = q.front();
		q.pop();
		data.pb(now);
		cnt++;
		char tmp = now.back();
		string tmp2;
		if (tmp > '0') {
			tmp2 = now; tmp2.pb(tmp - 1);
			q.push(tmp2);			
		}
		tmp2 = now; tmp2.pb(tmp);
		q.push(tmp2);
		if (tmp < '9') {
			tmp2 = now; tmp2.pb(tmp + 1);
			q.push(tmp2);
		}
	}
	cout << data[K - 1] << "\n";
}

Measured memory_bytes: 20468
<?php
fscanf(STDIN, "%d", $n);
$res = '';
for ($i = 3; $i <= $n; ++$i) {
  if ($i % 3 === 0) {
    $res .= " $i";
  } else {
    for ($x = $i; $x; $x = (int)($x/10)) {
      if ($x % 10 === 3) {
        $res .= " $i";
        break;
      }
    }
  }
}
echo $res,PHP_EOL;

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

int main() {
    int n,x; cin >> n;
    set<int> s;
    rep(i,1,n+1){
        cin >> x;
        if(s.count(x)){
            s.erase(x);
        }else{
            s.insert(x);
        }
    }
    cout << s.size() << endl;
}

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

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

#define rep(i, n) for (ll i = 0, xxx_rep_end = (n); i < xxx_rep_end; ++i)
#define all(x) (x).begin(), (x).end()

template <class T1, class T2>
inline bool chmax(T1 &a, const T2 &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T1, class T2>
inline bool chmin(T1 &a, const T2 &b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

constexpr ll INF = 0x3f3f3f3f3f3f3f3fLL;
constexpr ll mod = 1000000007;

int main() {
    ll X;
    cin >> X;
    ll ans = 0;
    ans += X / 500 * 1000;
    X -= X / 500 * 500;
    ans += X / 5 * 5;
    cout << ans << endl;
}

Measured memory_bytes: 3564
#include<bits/stdc++.h>
using namespace std;
inline void rd(int &x){
  int k, m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(int x){
  char f[10];
  int m=0, s=0;
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
template<class S, class T> inline S chmax(S &a, T b){
  if(a<b){
    a=b;
  }
  return a;
}
int N;
int H[20];
int main(){
  int i, mx=0, res=0;
  rd(N);
  {
    int Lj4PdHRW;
    for(Lj4PdHRW=0;Lj4PdHRW<N;Lj4PdHRW++){
      rd(H[Lj4PdHRW]);
    }
  }
  for(i=0;i<N;i++){
    chmax(mx, H[i]);
    if(mx==H[i]){
      res++;
    }
  }
  wt_L(res);
  wt_L('\n');
  return 0;
}
// cLay varsion 20190608-2

// --- original code ---
// int N, H[20];
// {
//   int i, mx = 0, res = 0;
//   rd(N,H(N));
//   rep(i,N){
//     mx >?= H[i];
//     if(mx==H[i]) res++;
//   }
//   wt(res);
// }


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std ;
const double pi = acos(-1) ;
int main () {
  int N ;
  cin >> N ;
  vector<long long> line(N) ;
  long long ans = 0 ;
  for(int i = 0; i < N ;i++) {
    cin >> line[i] ;
    ans += line[i] ;
  }
  sort(line.begin(),line.end()) ;
  cout << line[0] << ' '<<line[N-1] <<' '<< ans << endl ;
}


Measured memory_bytes: 3220
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vi>;
using vb = vector<bool>;
using pii = pair<int, int>;
using mii = map<int, int>;


void solve() {
	int n, a, q, b, c; cin >> n;
	ll sum = 0;
	vi num(100001, 0);
	
	for (int i = 0; i < n; i++) {
		cin >> a;
		num[a]++;
		sum += a;
	}
	
	cin >> q;
	while (q--) {
		cin >> b >> c;
		sum += (c - b) * num[b];
		num[c] += num[b];
		num[b] = 0;
		cout << sum << '\n';
	}
}

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

Measured memory_bytes: 3700
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        String input = new Scanner(System.in).nextLine();
        String[] inputs = input.split("\\s+");
        int a = Integer.parseInt(inputs[0]);
        int b = Integer.parseInt(inputs[1]);
        System.out.println((a * b) + " " + (a * 2 + b * 2));
    }
}


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

int main() {
  vector<int> A(5);

  for (int i = 0; i < 5; i++) {
    cin >> A[i];
    if (A[i] == 0) {
      cout << (i+1) << endl;
      break;
    }
  }
  return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
int main() {
    int N, K;
    cin >> N >> K;
    int num = 1;
    for(int i = 0; i < N; i++){
        if(num * 2 <= num + K){
            num *= 2;
        }
        else{
            num += K;
        }
    }
    cout << num << endl;
    return 0;
}

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

using namespace std;

using ll = long long;

const ll MOD = 998244353;

ll modpow(ll x, ll n, ll mod = MOD) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * x % mod;
        x = x * x % mod;
        n >>= 1;
    }
    return res;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> d(n);
    for (int i = 0; i < n; i++) {
        cin >> d[i];
    }

    if (d[0] != 0) {
        cout << 0 << "\n";
        return 0;
    }

    for (int i = 1; i < n; i++) {
        if (d[i] == 0) {
            cout << 0 << "\n";
            return 0;
        }
    }

    vector<int> cnt(n, 0);
    int max_num = 0;
    for (int i = 0; i < n; i++) {
        max_num = max(max_num, d[i]);
        cnt[d[i]]++;
    }

    ll ans = 1;
    for (int i = 1; i <= max_num; i++) {
        (ans *= (cnt[i - 1] == 0 ? 0 : modpow(cnt[i - 1], cnt[i]))) %= MOD;
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 1024
/*
***************************************************************************
 name  : ITP1_01_B.cpp
 title : X Cubic
 make  : 2018/08/01 tanabe
***************************************************************************
*/

// Library
#include <iostream> // standard input output object
#include <cmath>    // mathematical functions

main(void){
  int x; // integer

  std::cin >> x;                   // input "x"
  std::cout << x*x*x << std::endl; // output "x"

}



Measured memory_bytes: 3108
ri = lambda: int(input())
rl = lambda: list(map(int,input().split()))
rr = lambda N: [ri() for _ in range(N)]
YN = lambda b: print('YES') if b else print('NO')
yn = lambda b: print('Yes') if b else print('No')
OE = lambda x: print('Odd') if x%2 else print('Even')
INF = 10**18

R,G,B,N=rl()
ans = [0]*(N+1)
ans[0] = 1
for color in [R,G,B]:
    for i in range(N+1):
        temp = i + color
        if temp <= N:
            ans[temp] += ans[i]
print(ans[N])

Measured memory_bytes: 3064
/*
これを入れて実行
g++ code.cpp
./a.out
 */
 
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <cmath>
#include <math.h>
#include <tuple>
#include <iomanip>
#include <bitset>
 
using namespace std;
typedef long long ll;
typedef long double ld;
 
int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};
 
const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;
 
bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}
 
ll gcd(ll a, ll b){
	if (b == 0)return a;
	return gcd(b, a % b);
}
 
ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}
 
ll nCr(ll n, ll r){
    if(r == 0 || r == n){
        return 1;
    } else if(r == 1){
        return n;
    }
    return (nCr(n - 1, r) + nCr(n - 1, r - 1));
}
 
ll nPr(ll n, ll r){
    r = n - r;
    ll ret = 1;
    for (ll i = n; i >= r + 1; i--) ret *= i;
    return ret;
}
 
//-----------------------ここから-----------

int main(void){
    int n, k;
    cin >> n >> k;
    int r, s, p;
    cin >> r >> s >> p;

    string t;
    cin >> t;

    ll ans = 0;

    for(int i = 0; i < k; i++){
        if(t[i] == 'r'){
            ans += p;
        } else if(t[i] == 's'){
            ans += r;
        } else if(t[i] == 'p'){
            ans += s;
        }
        char past = t[i];
        bool f = true;
        for(int j = i + k; j < n; j += k){
            if(!f || t[j] != past){
                if(t[j] == 'r'){
                    ans += p;
                } else if(t[j] == 's'){
                    ans += r;
                } else if(t[j] == 'p'){
                    ans += s;
                }
                f = true;
            } else {
                f = false;
            }
            past = t[j];
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 512
n=int(input())

lfb=[]
l=[]

for i in range(1,n+1):
    if i%3==0:
        lfb.append(i)
    elif i%5==0:
        lfb.append(i)
    elif i%15==0:
        lfb.append(i)
    else:
        l.append(i)
print(sum(l))




Measured memory_bytes: 48356
from collections import deque

n = int(input())
A = list(input().split())
a = [int(A[i]) for i in range(n)]

b = deque([])
b_rev = deque([])

for i in range(n):
    if i % 2 == 0:
        b.append(str(A[i]))
        b_rev.appendleft(str(A[i]))
    else:
        b.appendleft(str(A[i]))
        b_rev.append(str(A[i]))
    
if n % 2 == 0:
    print(' '.join(b))
else:
    print(' '.join(b_rev))

Measured memory_bytes: 40036
<?php
list($n, $k) = ints();
$a = ints();
// 全ての丸太をx未満の長さにするのに必要な回数がk以下となる時のxの最小値を求める
$ok = max($a);
$ng = 0;
while (abs($ok - $ng) > 1) {
    $mid = intdiv($ok + $ng, 2);
    $cnt = 0;
    for ($i = 0; $i < $n; ++$i)
        $cnt += intdiv($a[$i], $mid) + min(1, $a[$i] % $mid) - 1;
    if ($cnt <= $k) $ok = $mid;
    else $ng = $mid;
}
echo $ok;
function ints()
{
    return array_map('intval', explode(' ', trim(fgets(STDIN))));
}


Measured memory_bytes: 37956
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(long long i=0; i<(n); i++)
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

bool ifokay(ll x, ll w){
    rep(i,w-1){
        if(((x>>i)&1) && ((x>>(i+1))&1)) return false;
    }
    return true;
}

int main(){
    ll h,w,K; cin>>h>>w>>K;
    vector<vector<ll>> dp(h+1, vector<ll>(w+1, 0));
    ll mod=1e9+7;
    dp[0][1]=1;
    for(ll i=1; i<=h; i++){
        rep(j, 1<<(w-1)){
            if(!ifokay(j, w)) continue;
            for(ll k=1; k<=w; k++){
                if(k==1){
                    if(j & 1) dp[i][1]+=dp[i-1][2];
                    else dp[i][1]+=dp[i-1][1];
                }else if(k==w){
                    if((j>>(w-2)) & 1) dp[i][w]+=dp[i-1][w-1];
                    else dp[i][w]+=dp[i-1][w];
                }else{
                    if((j>>(k-2)) & 1) dp[i][k]+=dp[i-1][k-1];
                    else if((j>>(k-1)) & 1) dp[i][k]+=dp[i-1][k+1];
                    else dp[i][k]+=dp[i-1][k];
                }
            }
        }
        rep(j,w) dp[i][j+1]%=mod;
    }
    cout<<dp[h][K]<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>

using namespace std;

bool isPrime(int x) {
	for (int i = 2; i*i <= x; i++) {
		if (x % i == 0) return false;
	}
	return true;
}

int main() {

	int N;
	cin >> N;
	vector<int> data(N);

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

	int ans = 0;
	for (int i = 0; i < N; i++) {
		if (isPrime(data[i])) ans++;
	}
	cout << ans << endl;

	return 0;
}




Measured memory_bytes: 3124
import sys
N, M = map(int, input().split())
H = tuple(map(int, input().split()))
G = [set() for _ in range(N)]
for _ in range(M):
    a, b = map(int, sys.stdin.readline().split())
    G[a-1].add(b-1)
    G[b-1].add(a-1)

ans = 0
for i in range(N):
    h = H[i]
    for j in G[i]:
        if h <= H[j]:
            break
    else:
        ans += 1
print(ans)

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

int main()
{



        long long A, B, K;
        cin >> A >> B >> K;

        if (K >= A) {
                K -= A;
                A = 0;
        }
        else {
                A -= K;
                K = 0;
        }

        if (K >= B) {
                K -= B;
                B = 0;
        }
        else {
                B -= K;
                K = 0;
        }

        cout << A << " " << B << endl;







}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <array>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <cmath>
#include <climits>
#include <cstdio>
#include <iomanip>
#include <utility>

using namespace std;
typedef long long int ll;

#define SP(x) setprecision((int)x)
#define ALL(v) v.begin(),v.end()

int main(int argc, char const *argv[])
{
    string s;
    cin >> s;
    for (ll i = 0; i < s.size(); i++)
    {
        if (s[i] == ',')
            s[i] = ' ';
    }
    cout << s << endl;
}

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

typedef long long int64;

const int MAXN = 5000 + 10;

int n, k;
int col[MAXN], colcnt;
int size[MAXN];
int64 sum[MAXN];
int a[MAXN], nxt[MAXN];

int64 f(int u, int k) {
    int64 ans = 0, nowans = -5e18;

    k = std::min(k, n);

    for(; k; u=nxt[u], k--) {
        ans += a[u];
        nowans = std::max(nowans, ans);
    }
    return nowans;
}

int main() {
    // #ifndef ONLINE_JUDGE
    // freopen("d.in", "r", stdin);
    // freopen("d.out", "w", stdout);
    // #endif

    int64 ans = -5e18;
    int i, u, x, y;

    scanf("%d %d", &n, &k);
    for (i = 1; i <= n; i++)
        scanf("%d", &nxt[i]);
    for (i = 1; i <= n; i++)
        scanf("%d", &a[i]);

    for (u = 1; u <= n; u++) {
        if (col[u])
            continue;
        colcnt++;
        size[colcnt] = 1;
        sum[colcnt] = a[u];
        col[u] = colcnt;
        for (x = nxt[u]; x ^ u; x = nxt[x]) {
            size[colcnt]++;
            sum[colcnt] += a[x];
            col[x] = colcnt;
        }
    }

    for (u = 1; u <= n; u++) {
        ans = std::max(ans, f(u, k));
        if (k > n) {
            ans = std::max(ans, (k / size[col[u]] - 1) * sum[col[u]] + std::max(0LL, f(u, size[col[u]] + k % size[col[u]])));
            ans = std::max(ans, k / size[col[u]] * sum[col[u]] + std::max(0LL, f(u, k % size[col[u]])));
        }
    }
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 1808
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(a) (a).begin(), (a).end()
typedef vector<int> vi;
const int INF = 1LL << 60; //10e18+10e17ちょっとくらい
const int MOD = 1000000007;
const int MAX_N = 200100;

signed main()
{
    //  以降 cin の入力元が 'input.txt' になる
    //std::ifstream in("input.txt");
    //std::cin.rdbuf(in.rdbuf());
    string s, t;
    cin >> s >> t;
    map<string, int> mp;
    int a, b;
    cin >> a >> b;
    mp[s] = a;
    mp[t] = b;
    string u;
    cin >> u;
    mp[u]--;
    cout << mp[s] << " " << mp[t] << endl;

    return 0;
}

Measured memory_bytes: 256
#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 INF 1e9
#define ALL(v) v.begin(), v.end()

using namespace std;

typedef long long ll;

typedef pair<string, int> proc;
queue<proc> q;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n, max, et;
    cin >> n;
    cin >> max;
    et = 0;

    REP(i, n) {
        string name;
        int time;
        cin >> name;
        cin >> time;
        proc p = proc(name, time);
        q.push(p);
    }

    while(!q.empty()) {
        proc p;
        p = q.front();
        q.pop();
        int t = p.second;

        if (t > max) {
            p.second = t - max;
            q.push(p);
            et += max;
        } else {
            et += t;
            cout << p.first << ' ' << et << "\n";
        }
    }
}


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

#define      pb    push_back
#define      ff    first
#define      ss    second
#define      ll    long long int
#define      endl  "\n"
#define      FASTIO        ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

const ll big = 10e10 + 11 ;

int  main (  ) {

    FASTIO ;

    int x , a ;
    cin >> x >> a ;

    if( x < a ) cout << 0 ;
    else   cout <<  10  ;


    return  0 ;
}



Measured memory_bytes: 256
import copy
n = int(input())
a = list(map(int, input().split()))

def judge_pm(a,b):
    if a*b<0:
        return True
    else:
        return False

a1 = copy.deepcopy(a)
operate_num1 = 0
if a1[0]==0:
    a1[0] = 1
    operate_num1 += 1
tmp_sum = a1[0]
for i in range(1, n):
    if judge_pm(tmp_sum, tmp_sum+a1[i]):
        pass 
    elif tmp_sum<0:
        tmp_operate_num =  - tmp_sum + 1 - a1[i]
        operate_num1 += tmp_operate_num
        a1[i] += tmp_operate_num
    else:
        tmp_operate_num = tmp_sum + 1 + a1[i]
        operate_num1 += tmp_operate_num
        a1[i] -= tmp_operate_num
    tmp_sum += a1[i]
        
a2 = copy.deepcopy(a)
operate_num2 = 0
if a2[0]<0:
    operate_num2 += 1 - a2[0]
    a2[0] += operate_num2
else:
    operate_num2 += a2[0] + 1
    a2[0] -= operate_num2

tmp_sum = a2[0]

for i in range(1, n):
    if judge_pm(tmp_sum, tmp_sum+a2[i]):
        pass 
    elif tmp_sum<0:
        tmp_operate_num =  - tmp_sum + 1 - a2[i]
        operate_num2 += tmp_operate_num
        a2[i] += tmp_operate_num
    else:
        tmp_operate_num = tmp_sum + 1 + a2[i]
        operate_num2 += tmp_operate_num
        a2[i] -= tmp_operate_num
    tmp_sum += a2[i]

print(min(operate_num1, operate_num2))        


Measured memory_bytes: 15164
#include <bits/stdc++.h>
using namespace std;
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;
}
typedef long long int ll;

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define endl "\n"
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
const double PI = acos(-1);
const int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//-------------------------------------

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int x, a, b;
    cin >> x >> a >> b;
    int n;
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        string s;
        cin >> s;
        if (s == "nobiro")
        {
            x = max(x + a, 0);
        }
        else if (s == "tidime")
        {
            x = max(x + b, 0);
        }
        else
        {
            x = 0;
        }
    }
    cout << x << endl;
}


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

using namespace std;

int32_t main() {

    ios_base::sync_with_stdio(false);

    cin.tie(0);

    vector<string> days= {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};

    long long res=0;

    string s;

    cin >> s;

    long long idx=0;

    for(long long i = 0 ; i < days.size() ; i++) {

        if(days[i]==s) {

            idx=i;

            break;

        }

    }

    res=1;

    idx+=1;

    idx%=7;

    while(days[idx]!="SUN") {

        idx++;

        idx%=7;

        res++;

    }

    cout << res << '\n';

    return 0;

}



Measured memory_bytes: 3628
#include<iostream>
#include<cstring>
#include<string>
#include<vector>
#include<utility>
#include<stdlib.h>
#include<limits.h>
#include<cmath>
#include<set>
#include<initializer_list>
#include<unordered_set>
#include<unordered_map>
#include<map>
#include<iomanip>
#include<algorithm>

#define sze 1000005
#define ld long double
#define ull unsigned long long
#define ll long long
#define endl "\n"
#define pb push_back
#define mkp make_pair
#define mod 1000000007
#define ff first
#define ss second
#define F(i,a,b) for(int i = (int)(a); i <= (int)(b); i++)
#define RF(i,a,b) for(int i = (int)(a); i >= (int)(b); i--)

using namespace std;

int main(int argc, const char *argv[])
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s,t; cin>>s>>t;
    ll n1 = s.length(); ll n2=t.length();
    ll dp[n1+1][n2+1];
    memset(dp,0,sizeof dp);
    F(i,1,n1)
    {
        F(j,1,n2)
        {
            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]);
            }
        }
    }
    ll i=n1,j=n2;
    string str;
        F(k,0,n1)
        {
            if(dp[i][j]==dp[i-1][j])
            {
                i--;
            }
            else if(dp[i][j]==dp[i][j-1])
            {
                k--;
                j--;
            }
            else if(dp[i][j]==dp[i-1][j-1]+1)
            {
                str = str+ s[i-1];
                i--;  j--;
            }
        }
    //cout<<str<<endl;
    //string str1;
    reverse(str.begin(),str.end());
    cout<<str<<endl;
}


Measured memory_bytes: 70656
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MAX_H 1005
#define MAX_W 1005
ll INF=(1LL<<50);
int H,W;
ll t[MAX_H][MAX_W];
ll u[MAX_H][MAX_W];
ll dp[MAX_H][MAX_W];

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

int main(){
  cin>>W>>H;
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      cin>>t[i][j];
      u[i][j+1]=t[i][j]+u[i][j];
    }
  }

  dp[H][W]=0;
  for(int i=H;i>=0;i--){
    for(int j=W;j>=0;j--){
      if(i==H&&j==W)continue;
      
      if((i+j)&1){
        dp[i][j]=INF;
        if(j+1<=W)dp[i][j]=min(dp[i][j],dp[i][j+1]);
        if(i+1<=H)dp[i][j]=min(dp[i][j],u[i][W]-u[i][j]-u[i][j]+dp[i+1][j]);
      }else{
        dp[i][j]=-INF;
        if(j+1<=W)dp[i][j]=max(dp[i][j],dp[i][j+1]);
        if(i+1<=H)dp[i][j]=max(dp[i][j],u[i][W]-u[i][j]-u[i][j]+dp[i+1][j]);
      }
    }
  }

  cout<< abs(dp[0][0]) <<endl;
  return 0;
}

Measured memory_bytes: 26636
#include"bits/stdc++.h"
#include<boost/multi_array.hpp>
#include<boost/optional.hpp>
#include<boost/range/irange.hpp>
#include<boost/range/algorithm.hpp>
#include<boost/range/adaptors.hpp>
#include<boost/operators.hpp>
#include<boost/dynamic_bitset.hpp>

namespace adaptor = boost::adaptors;
using index_t = std::size_t;

int run(int N, std::vector<std::queue<int>> opponents)
{
	int day = 0;
	std::size_t rest = N * (N - 1) / 2;
	std::set<int> set;
	for (auto i : boost::irange(0, N))
	{
		auto op = opponents[i].front();
		if (opponents[op].front() == i)
		{
			set.emplace(std::min(i, op));
		}
	}
	for (; rest != 0; ++day)
	{
		if (set.size() == 0)
		{
			return -1;
		}
		rest -= set.size();
		std::set<int> next;
		for (auto i : set)
		{
			auto op = opponents[i].front();
			opponents[i].pop();
			opponents[op].pop();
			for (auto j : { i,op })
			{
				if (opponents[j].size() != 0)
				{
					auto op2 = opponents[j].front();
					if (opponents[op2].front() == j)
					{
						next.emplace(std::min(j, op2));
					}
				}
			}
		}
		std::swap(set, next);
	}
	return day;
}

void Main()
{
	int N;
	std::cin >> N;
	std::vector<std::queue<int>> opponents(N);
	for (auto& queue : opponents)
	{
		for (auto i : boost::irange(0, N - 1))
		{
			int a;
			std::cin >> a;
			--a;
			queue.emplace(a);
		}
	}
	std::cout << run(N, std::move(opponents)) << std::endl;
}

int main()
{
	std::cin.tie(nullptr);
	std::ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	Main();
}

Measured memory_bytes: 4736
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;

int main(void)
{
	int i,j,n,m,a[51],b[51],c[51],d[51],mn,mm,x,y;
	scanf("%d %d",&n,&m);
	for(i=1;i<=n;i++)	scanf("%d %d",&a[i],&b[i]);
	for(i=1;i<=m;i++)	scanf("%d %d",&c[i],&d[i]);	
	for(i=1;i<=n;i++)	{
		mn=2000000000;
		for(j=1;j<=m;j++)	{
			x=a[i]-c[j];	x=max(x,-x);
			y=b[i]-d[j];	y=max(y,-y);
			if(mn>x+y)	{
				mn=x+y;
				mm=j;
			}
		}
		printf("%d\n",mm);
	}
	return 0;
}

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

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; }

#define ld long double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

/* Some Libraries */

//-------------------------------------------------

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,m; cin>>n>>m;
    vector<vector<char> > f(n, vector<char>(n)), g(m, vector<char>(m));
    rep(i,n)rep(j,n){
        cin>>f[i][j];
    }
    rep(i,m)rep(j,m){
        cin>>g[i][j];
    }
    rep(i,n-m+1)rep(j,n-m+1){
        bool ok = true;
        rep(k,m)rep(l,m){
            if (f[i+k][j+l]!=g[k][l]){
                ok = false;
                break;
            }
        }
        if (ok){
            cout<<"Yes\n";
            return 0;
        }
    }
    cout<<"No\n";
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=200005;
const int V=1100001;
const int MOD=998244353;
int t[V];
int ADD(int x,int y){return x+y>=MOD ? x+y-MOD : x+y;}
int MUL(int x,int y){return 1ll*x*y%MOD;}
int f[V],g[V];
int n,m;

int prime[V],bl[V],mu[V],tot=0;
void getmu()
{
    for(int i=1;i<V;i++) bl[i]=1;
    bl[1]=0; mu[1]=1;
    for(int i=2;i<V;i++)
    {
        if(bl[i]) mu[i]=(MOD-1),prime[++tot]=i;
        for(int j=1;j<=tot;j++)
        {
            if(prime[j]*i>V-1) break;
            if(i%prime[j]==0)
            {
                bl[i*prime[j]]=0;
                mu[i*prime[j]]=0;
                break;
            }
            bl[i*prime[j]]=0; mu[i*prime[j]]=MOD-mu[i];
        }
    }
} 

int inv[V],mx=0;
void init()
{
    inv[1]=1;
    for (int i=2;i<=mx;++i) inv[i]=MUL(MOD-MOD/i,inv[MOD%i]);
    for(int i=1;i<=mx;i++)
    {
        for(int j=i;j<=mx;j+=i)
        {
            f[i]=ADD(f[i],MUL(t[j],j));
            g[j]=ADD(g[j],MUL(mu[j/i],inv[i]));
        }
    }
}

int main()
{
    getmu();
    scanf("%d",&n);
    int sum=0;
    for(int i=1;i<=n;i++)
    {
        int x; scanf("%d",&x);
        t[x]++;
        mx=max(mx,x);
        sum=ADD(sum,x);
    }
    init();
    int ans=0;
    for(int i=1;i<=mx;i++) ans=ADD(ans,MUL(MUL(f[i],f[i]),g[i]));
    ans=MUL(ans-sum+MOD,inv[2]);
    printf("%d\n",ans);
    return 0;
}


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

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

int main(){
  cin.tie(nullptr);ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  int p,q,r;cin>>p>>q>>r;
  cout<<min(p+q,min(q+r,p+r))<<endl;
}


Measured memory_bytes: 256