akhauriyash/Code-Regression huggingface dataset:
#最初に置いておくもの
import sys
sys.setrecursionlimit(500000) 
input=sys.stdin.readline

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

inf=float('inf')
dp=[[0]*3 for j in range(N+1)]

def chmax(a,b):
    return max(a,b)

def rec(n,m):
    if n==0:
        return 0
    if dp[n][m]>0:
        return dp[n][m]

    for i in range(3):
            if (i == m):
                continue
            dp[n][m]=chmax(dp[n][m], rec(n-1,i) + A[n-1][m])
    
    return dp[n][m]

re=max(rec(N,0),rec(N,1),rec(N,2))
print(re)

Measured memory_bytes: 129696
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<map>
#include<set>
#include<cstring>
using namespace std;

#define fi(a,b) for(int i=a;i<b;++i)
#define fj(a,b) for(int j=a;j<b;++j)
#define fo(a,b) for(int o=a;o<b;++o)
#define fdi(a,b) for(int i=a-1;i>=b;--i)
#define fdj(a,b) for(int j=a-1;j>=b;--j)
#define fdo(a,b) for(int o=a-1;o>=b;--o)
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
///////////////////////////



int main(){
#ifdef _DEBUG
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
#endif

	int n;
	cin >> n;
	vi a;
	fi(0, n){
		int x;
		cin >> x;
		a.pb(x);
	}
	sort(a.begin(), a.end());
	int ans = 1;
	int w = a[0];
	fi(1, n){
		if(a[i] > w){
			++ans;
			w = a[i];
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
typedef long long ll;

int main(){
    int a,b,t;
    cin >> a >> b >> t;
    cout << b*(t/a) << endl; return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define debug(x) cerr << #x << " " << x << '\n'
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using pli = pair<ll,int>;
const int INF = 0x3f3f3f3f, N = 1e5 + 5;
const ll LINF = 1e18 + 5;
int n, m, cnt[N];
int main()
{
 	ios::sync_with_stdio(false);
 	cin.tie(0);
 	cin >> n >> m;
 	for(int i=1; i<=m; i++)
 	{
 		int l, r;
 		cin >> l >> r;
 		cnt[l]++; cnt[r+1]--;
 	}
 	for(int i=1; i<=n; i++) cnt[i] += cnt[i-1];
 	int ans = 0;
 	for(int i=1; i<=n; i++) ans += cnt[i]==m;
 	cout << ans;
	return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
#define Rint register int
using namespace std;
const int N = 21;
int n, m, f[1 << N][N];
int main(){
    scanf("%d%d", &n, &m);
    for(Rint i = 0;i <= n;++ i)
        for(Rint j = 0, x;j < (1 << i);++ j){
            for(x = getchar();x != '0' && x != '1';x = getchar());
            f[(1 << i) | j][i] = (x == '1');
        }
    for(Rint i = n;~i;-- i)
        for(Rint j = 0;j < (1 << i);++ j)
            for(Rint k = i;~k;-- k) if(f[(1 << i) | j][k]){
                int t = f[(1 << i) | j][k], S = j >> k, T = j & ((1 << k) - 1);
                if(k) f[(1 << i - k) | S][0] += t;
                if(T){
                    int u = k - 1;
                    while(!((T >> u) & 1)) -- u;
                    f[(1 << i - k + u + 1) | (S << u + 1) | (1 << u) | (T & ((1 << u) - 1))][u] += t;
                }
                if((~T) & ((1 << k) - 1)){
                    int u = k - 1;
                    while((T >> u) & 1) -- u;
                    f[(1 << i - k + 1 + u) | (S << u + 1) | (T & ((1 << u) - 1))][u] += t;
                }
            }
    for(Rint i = n;~i;-- i)
        for(Rint j = 0;j < (1 << i);++ j) if(f[(1 << i) | j][0] >= m){
            for(Rint k = i - 1;~k;-- k) putchar('0' + ((j >> k) & 1));
            return 0;
        }
}

Measured memory_bytes: 172416
import sys


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    a, b, c = list(map(int, readline().split()))
    if a == b != c or a != b == c or a == c != b:
        print("Yes")
    else:
        print("No")


if __name__ == '__main__':
    solve()


Measured memory_bytes: 38512
#include <iostream>

using namespace std;

long long INF = 1ll << 60;
long long dp[100][100001] {};
long long w[100] {};
long long v[100] {};

long long rec(int i, int j) {
    if(dp[i][j] > -INF) return dp[i][j];
    else {
        long long tmp;
        if(j-w[i] >= 0) {
            tmp = max(
                rec(i-1, j),
                rec(i-1, j-w[i]) + v[i]
            );
        } else {
            tmp = rec(i-1, j);
        }

        return dp[i][j] = tmp;
    }
}

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

    for(int i = 0; i < N; ++i) {
        cin >> w[i] >> v[i];
        for(int j = 0; j <= W; ++j) dp[i][j] = -INF;
    }

    for(long long i = 0; i <= W; ++i) {
        if(i >= w[0]) dp[0][i] = v[0];
        else dp[0][i] = 0;
    }

    cout << rec(N-1, W) << endl;
}


Measured memory_bytes: 78336
#include <iostream>
#include <string>
#include <algorithm>
#include <ctime>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cassert>
#include <bitset>
#include <list>
#include <cstdio>
#include <stdio.h>

typedef long long ll;

using namespace std;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    string s;
    cin >> n;
    cin >> s;
    int cnt = 0;
    for(int i=0; i<n-2; i++)
    {
        if(s.substr(i, 3) == "ABC") cnt++;
    }
    cout << cnt;
}


Measured memory_bytes: 256
nl = lambda: list(map(int, input().split()))
sl = lambda: input().split()
n = lambda: int(input())
s = lambda: input()

N = n()

def divisors(n):
    res = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            res.append(i)
            if i != n // i:
                res.append(n//i)
    return res

total = 0
for i in range(1, N+1):
    if i % 2 == 0:
        continue
    nums = divisors(i)
    if len(nums) == 8:
        total += 1

print(total)





Measured memory_bytes: 3316
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <math.h>
#include <cmath>
#include<cctype>
#include<string>
#include<set>
#include<iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include<bitset>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
using namespace std;
using ll = long long;
using R = double;
using Data = pair < ll, vector <ll>>;
template<typename T>using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const ll MOD = 1e9 + 7;
const ll inf = 1LL << 60;
struct edge { ll from; ll to; ll cost; };
typedef pair<ll, ll>pll;
#define all(x) (x).begin(),(x).end()
#define rep(i,m,n) for(ll i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(ll i = m;i >= n;--i)
#define INF INT_MAX/2

string S;
string slice(int i, int j, string a) {
	string ret = "";
	for (int k = i; k <= j; k++) {
		ret += a[k];
	}
	return ret;
}
ll tonum(string s) {
	reverse(all(s));
	ll dgt = 1;
	ll ret = 0;
	rep(i, 0, s.size()) {
		ret += dgt * (s[i] - '0');
		dgt *= 10;
	}
	return ret;
}

ll sum(vector<int>v) {
	v.pb(0);
	v.pb(S.size());
	sort(all(v));
	ll ret = 0;
	rep(i, 1, v.size()) {
		ret += tonum(slice(v[i - 1], v[i] - 1, S));
	}
	return ret;
}

int main() {
	cin >> S;

	ll ans = 0;
	rep(msk, 0, (1 << S.size() - 1)) {
		vector<int>v;
		rep(i, 0, S.size() - 1) {
			if ((1 << i) & msk)v.pb(i + 1);
		}
		ans += sum(v);
	}

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


Measured memory_bytes: 256
K = int(input())
A, B = list(map(int,input().split(" ")))
tri = 0
if A%K == 0 or B%K == 0:
  print("OK")
else:
  for i in range(A,B):
    if i%K == 0:
      print("OK")
      tri = 1
      break
  if tri == 0:
    print("NG")

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

int main() {
  int N;
  long long a[1000000];
  cin >> N;
  for(int i=0; i<3*N; i++) cin >> a[i];
  sort(a, a+3*N, greater<long long>());
  
  long long ans=0;
  for(int i=0; i<N; i++){
    ans+=a[2*i+1];
  }
  
  cout << ans << endl;
}


Measured memory_bytes: 4352
class UnionFind:
    def __init__(self, n):
        self.par = list(range(n))
        self.rank = [0] * n
        self.size = [1] * n

    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.rank[x] == self.rank[y]:
            self.rank[x] += 1
        elif self.rank[x] < self.rank[y]:
            x, y = y, x

        self.par[y] = x
        self.size[x] += self.size[y]

    def is_same(self, x, y):
        return self.find(x) == self.find(y)

    def get_size(self, x):
        return self.size[self.find(x)]


N, M = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(M)]

tree = UnionFind(N)
for x, y, z in X:
    tree.unite(x - 1, y - 1)

# Update
for x in range(N):
    tree.find(x)

print(len(set(tree.par)))


Measured memory_bytes: 107524
// D - Lucky PIN
#include <bits/stdc++.h>
using namespace std;
#define rp(i,s,e) for(int i=(s);i<(e);++i)
#define all(x) (x).begin(),(x).end()
#define ubound(x,c) upper_bound(all(x),(c))-(x).begin()

int main(){
	int N; char S[30001]; scanf("%d%s",&N,S);
	vector<int> ix[10];
	rp(i, 0, N) ix[S[i]-'0'].push_back(i);
	int ans = 0;
	rp(a, 0, 10){
		int p = ubound(ix[a], -1); if(p >= ix[a].size()) continue;
		rp(b, 0, 10){
			int q = ubound(ix[b], ix[a][p]); if(q >= ix[b].size()) continue;
			rp(c, 0, 10) if(ubound(ix[c], ix[b][q]) < ix[c].size()) ans++;
		}
	}
	printf("%d\n",ans);
}

Measured memory_bytes: 512
s = input()

i = len(s)
index = 0

while(1):
    i = i-1
    s = s[:i]
    if len(s) % 2 == 0:
        if s[:i//2] == s[i//2:]:
            index = i
            break
    if i == 0:
        break


print(index)

Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
	int h,a;
	cin >>h >>a;
	if (h<=a)
		cout <<"1"<<endl;
	else
	{
		if (h%a==0)
			cout <<h/a<<endl;
		else 
			cout <<h/a+1<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ran 100010
vector<int> E[ran];
int main()
{
    int n,m;
    while(cin>>n>>m)
    {
        for(int i=1;i<=m;i++)
        {
            int a,b;
            cin>>a>>b;
            E[b-1].push_back(a);
        }
        int sum=0;
        int pre=-1;
        for(int i=1;i<=n;i++)
        {
            for(auto j:E[i])
            {
                if(j>pre)
                {
                    pre=i;
                    sum++;
                }
            }
        }
        cout<<sum<<endl;
    }
}


Measured memory_bytes: 4864
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;

#define REP(i, n) for (int i = 0; i < n; ++i)
#define FOR(i, a, b) for (int i = a; i <= b; ++i)
#define FORR(i, a, b) for (int i = a; i >= b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int c[3][3];
    REP(i, 3)REP(j, 3) cin >> c[i][j];
    REP(i, 3) {
        if(!(c[0][i] - c[0][(i + 1) % 3] == c[1][i] - c[1][(i + 1) % 3] 
        and c[1][i] - c[1][(i + 1) % 3] == c[2][i] - c[2][(i + 1) % 3])) {
            cout << "No" << endl;
            return 0;    
        }
    }
    REP(i, 3) {
        if(!(c[i][0] - c[(i + 1) % 3][0] == c[i][1] - c[(i + 1) % 3][1] 
        and c[i][1] - c[(i + 1) % 3][1] == c[i][2] - c[(i + 1) % 3][2])) {
            cout << "No" << endl;
            return 0;    
        }
    }

    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <set>
int main()
{
    std::multiset<int> s;

    int a;
    std::cin >> a;
    s.insert(a);
    std::cin >> a;
    s.insert(a);
    std::cin >> a;
    s.insert(a);
    
    for(auto it = s.begin();it != s.end();)
    {
        
        std::cout << *it;
        ++it;
        if(it != s.end())
        {
            std::cout <<" ";
        }
    }
    std::cout <<"\n";
    return 0;
}


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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define ALL(a) (a).begin(), (a).end()
#define rALL(a) (a).rbegin(), (a).rend()
#define SZ(x) ((int)(x).size())
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 28;
const ll INF64 = 1ll << 55;
const int mod = 1000000007;
//const int mod = 998244353;

template <class T>inline bool chmin(T &a, const T b)
{
  if (a > b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline bool chmax(T &a, const T b)
{
  if (a < b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline void line_out(const vector<T> vec) {
  int n = SZ(vec);
  rep(i, n) {
    cout << vec[i];
    if(i < n-1) cout << " ";
  }
  cout << endl;
  return;
}

struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint &operator++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};

int main()
{
  int n, m;
  cin >> n >> m;
  ll min_t = 1900*m + (n-m)*100;
  cout << min_t*pow(2, m) << endl;
}

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

int main() {
  int H, W;
  cin >> H >> W;
  
  vector<string> str(H);
  for (int i = 0; i < H; i++){
    cin >> str[i];
  }
  
  string s;
  int count;
  
  for (int i = 0; i < H; i++){
    
    for (int j = 0; j < W; j++){
      if (str[i][j] == '#'){
        continue;
      }
      
      count = 0;
      
      if (i > 0 && j > 0){
        if (str[i-1][j-1] == '#'){
          count++;
        }
      }
      
      if (i > 0){
        if (str[i-1][j] == '#'){
          count++;
        }
      }
      
      if (i > 0 && j < (W-1)){
        if (str[i-1][j+1] == '#'){
          count++;
        }
      }
      
      if (j > 0){
        if (str[i][j-1] == '#'){
          count++;
        }
      }
      
      if (j < (W-1)){
        if (str[i][j+1] == '#'){
          count++;
        }
      }
      
      if (i < (H-1) && j > 0){
        if (str[i+1][j-1] == '#'){
          count++;
        }
      }
      
      if (i < (H-1)){
        if (str[i+1][j] == '#'){
          count++;
        }
      }
      
      if (i < (H-1) && j < (W-1)){
        if (str[i+1][j+1] == '#'){
          count++;
        }
      }
      
      str[i][j] = char(count + '0');
    }
  }
  
  for (int i = 0; i < H; i++){
    cout << str[i] << endl;
  }
  
}


Measured memory_bytes: 3640
# import bisect
# from collections import Counter, defaultdict, deque
# import copy
# from heapq import heappush, heappop, heapify
# from fractions import gcd
# import itertools
# from operator import attrgetter, itemgetter
# import math

import sys

# import numpy as np

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

def main():
    d = int(input())
    ev = 25 - d

    print("Christmas"+" Eve"*ev)

if __name__ == '__main__':
    main()

Measured memory_bytes: 38256
import sys

read = sys.stdin.buffer.read


def main():
    N, D, A, *XH = map(int, read().split())
    monster = [0] * N
    for i, (x, h) in enumerate(zip(*[iter(XH)] * 2)):
        monster[i] = (x, (h + A - 1) // A)

    monster.sort()

    X = [x for x, h in monster]
    S = [0] * (N + 1)
    idx = 0
    ans = 0

    for i, (x, h) in enumerate(monster):
        d = h - S[i]
        if d > 0:
            right = x + 2 * D
            while idx < N and X[idx] <= right:
                idx += 1

            S[i] += d
            S[idx] -= d
            ans += d

        S[i + 1] += S[i]

    print(ans)
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 139568
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=(ll)1e9+7;

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

    deque<char> dq;

    for(char c:s) dq.push_back(c);
    int ans=0;

    while(!dq.empty()){
        char l=dq.front(),r=dq.back();
        if(l==r){
            dq.pop_back();
            if(!dq.empty()) dq.pop_front();
        } else if(l=='x'){
            ans++; dq.pop_front();
        }else if(r=='x'){
            ans++; dq.pop_back();
        }else{
            cout<<-1<<endl;
            return 0;
        }
    }

    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
    int N,ans=INT32_MAX;
    cin>>N;
    vector<int> ma(N,0);
    REP(i,N)cin>>ma[i];
    for(int i=1;i<=N;i++){
        int l=0,u=0;
        REP(y,N){
            if(y<=i)l+=ma[y];
            else u+=ma[y];
        }
        ans=min(ans,abs(u-l));
    }
    cout<<ans<<endl;
}

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

#define pb push_back
#define all(v) v.begin(), v.end()
#define sz(v) int(v.size())
#define pii pair<int, int>
#define mp make_pair
#define f first
#define ll long long
#define ld long double
#define s second
#define vec vector<int>

using namespace std;

const int N = (int) 300 + 10;
const int M = (int) 2018 * 2018;
const int K = (int) 15;
const int INF = (int) 1e9 + 7;
const int mod = (int) 998244353;
const ld EPS = (ld) 1e-9;
const ll LINF = (ll) 1e18;

int n, k;
string s;
int dp[N][N][N];

void upd_max(int &x, int y) {
	x = max(x, y);
}

int main() {
	#ifdef sony
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif
	srand(time(0));
	cin >> s >> k;
	n = sz(s);
	for (int i = 0; i < n; i++) {
		dp[i][i][0] = 1;
	}
	for (int len = 2; len <= n; len++) {
		for (int i = 0; i + len - 1 < n; i++) {
			int j = i + len - 1;
			for (int sum = 0; sum <= k; sum++) {
				if (s[i] == s[j]) {
					upd_max(dp[i][j][sum], dp[i + 1][j - 1][sum] + 2);
				} else {
					if (sum)
						upd_max(dp[i][j][sum], dp[i + 1][j - 1][sum - 1] + 2);
					upd_max(dp[i][j][sum], dp[i + 1][j][sum]);
					upd_max(dp[i][j][sum], dp[i][j - 1][sum]);
				}
			}
		}
	}
	int ans = 0;
	for (int sum = 0; sum <= k; sum++) {
		ans = max(ans, dp[0][n - 1][sum]);
	}
	cout << ans;
	return 0;	
}

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

using namespace std;

int main() {
  int A, B;
  cin >> A >> B;
  for (int m = 1; m <= 1000; m++) {
    int a = m * 0.08;
    int b = m * 0.1;

    if (A == a && B == b) {
      cout << m << endl;
      return 0;
    }
  }

  cout << -1 << endl;

  return 0;
}


Measured memory_bytes: 256
package main

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

func newScanner() *bufio.Scanner {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	return scanner
}

var sc = newScanner()

func scanInt() int {
	sc.Scan()
	v, _ := strconv.Atoi(sc.Text())
	return v
}

func scanInts(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = scanInt()
	}
	return a
}

func scanString() string {
	if sc.Scan() {
		return sc.Text()
	}
	panic(sc.Err())
}

func main() {
	v, e, r := scanInt(), scanInt(), scanInt()
	edgeMap := make(map[int][]edge)
	for i := 0; i < e; i++ {
		ed := edge{scanInt(), scanInt(), scanInt()}
		if _, exists := edgeMap[ed.from]; !exists {
			edgeMap[ed.from] = []edge{}
		}
		edgeMap[ed.from] = append(edgeMap[ed.from], ed)
	}

	printSingleSourceShortestPath(v, r, edgeMap)
}

type edge struct {
	from, to, cost int
}

func debug(a ...interface{}) {
	// fmt.Println(a...)
}

const inf = 10000000000000

func printSingleSourceShortestPath(v, r int, edgeMap map[int][]edge) {
	d := make([]int, v)
	for i := 0; i < v; i++ {
		if i != r {
			d[i] = inf
		}
	}
	queue := []int{r}
	for len(queue) != 0 {
		nextQueue := []int{}
		for _, node := range queue {
			for _, e := range edgeMap[node] {
				debug(node, d[e.to], d[node], e.cost)
				if d[e.to] > d[node]+e.cost {
					d[e.to] = d[node] + e.cost
					nextQueue = append(nextQueue, e.to)
				}
			}
		}
		debug("nextQueue", nextQueue)
		queue = nextQueue
	}
	for i := 0; i < v; i++ {
		if d[i] != inf {
			fmt.Println(d[i])
		} else {
			fmt.Println("INF")
		}

	}
}



Measured memory_bytes: 44724
n = int(input())
a1 = [int(i) for i in input().split()]
a2 = [int(i) for i in input().split()]

max = 0

for i in range(n):
    tmp = sum(a1[:i+1]) + sum(a2[i:])
    if max < tmp:
        max = tmp

print(max)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll arr[200005];

ll solve(ll m,ll n){
  ll cnt=0;
  for(ll i=0;i<n;i++){
     cnt += (arr[i]-1)/m;
  }
  return cnt;
}

int main() {
  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
  
  ll  i, n ,k;
  cin>>n>>k;
  for(i=0;i<n;i++) cin>>arr[i];  
  
  ll l = 1 , r = 1000000000;
  ll ans =r;
  while(l<=r){
    ll mid =(l+r)>>1;
    if(solve(mid ,n)<=k){
       ans = min(ans,mid); r=mid-1;
    }
    else l = mid+1;
  }

  cout<< ans ;
}   

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

#define INF 1e18
#define PI 3.141592653589793238
typedef long long ll;

int main() {
    string s;
    cin>>s;
    int n=s.length();
    string ss[(n+1)/2];
    for(int i=0; i<(n-1)/2; i++) ss[i] = s[i];
    int flag=1;
    for(int i=0; i<(n-1)/2; i++){
        if(s[i]!=s[n-i-1]) flag=0;
    }
    n = (n-1)/2;
    if(n%2==1){
        for(int i=0; i<(n-1)/2; i++){
            if(ss[i]!=ss[n-i-1]) flag=0;
        }
    }
    else{
        for(int i=0; i<n/2; i++){
            if(ss[i]!=ss[n-i-1]) flag=0;
        }
    }
    
    if(flag==1) cout<<"Yes"<<endl;
    else cout<<"No"<<endl; 



    return 0;
}

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

#define F first
#define S second
#define prev azaza
#define MP make_pair
#define PB push_back

using namespace std;
typedef long long ll;
typedef long double ld;

const int max_n = 100111, inf = 1000111222;

int v[max_n];
vector<pair<int, pair<int, int>>> e;

int sz[max_n];
int pr[max_n];
ll sumv[max_n];
ll cnte[max_n];
ll sete[max_n];
int n, m;


int get_set(int a) {
    if (pr[a] == a) {
        return a;
    } else {
        return get_set(pr[a]);
    }
}

int ans = 0;

void unite_set(int a, int b, int w) {
    int pra = get_set(a);
    int prb = get_set(b);
    if (pra == prb) {
        int pr = pra;
        if (w <= sumv[pr]) {
            ans++;
            cnte[pr]++;
            sete[pr]++;
            if (cnte[pr] != sete[pr]) {
                exit(228);
            }
        } else {
            cnte[pr]++;
        }
        return;
    }
    ll n_sumv = sumv[pra] + sumv[prb];
    ll n_cnte;
    ll n_sete;
    if (w <= n_sumv) {
        ans -= sete[pra];
        ans -= sete[prb];
        n_cnte = cnte[pra] + cnte[prb] + 1;
        n_sete = n_cnte;
        ans += n_cnte;
    } else {
        n_cnte = cnte[pra] + cnte[prb] + 1;
        n_sete = sete[pra] + sete[prb];
    }
    if (sz[pra] > sz[prb]) {
        sz[pra] += sz[prb];
        pr[prb] = pra;
        sumv[pra] = n_sumv;
        cnte[pra] = n_cnte;
        sete[pra] = n_sete;
    } else {
        sz[prb] += sz[pra];
        pr[pra] = prb;
        sumv[prb] = n_sumv;
        cnte[prb] = n_cnte;
        sete[prb] = n_sete;
    }
}

int main()
{
    //freopen("input.txt", "r", stdin);
    cin >> n >> m;
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
    for (int i = 0; i < m; ++i) {
        int a, b, c;
        cin >> a >> b >> c;
        --a, --b;
        e.push_back(MP(c, make_pair(a, b)));
    }
    for (int i = 0; i < n; ++i) {
        sz[i] = 1;
        pr[i] = i;
        sumv[i] = v[i];
        cnte[i] = sete[i] = 0;
    }
    sort(e.begin(), e.end());
    for (int i = 0; i < e.size(); ++i) {
        int a = e[i].S.F, b = e[i].S.S;
        int c = e[i].F;
        unite_set(a, b, c);
    }
    cout << (m - ans) << endl;
    return 0;
}




Measured memory_bytes: 5108
s = list(input())
b = 0
if len(s)%2==1:
    for a in range(int((len(s)-1)/2)):
        if s[a]!=s[len(s)-a-1] and b==0:
            b = 1
else:
    b = 1
if b == 0:
    for c in range(int((len(s)-1)/4+1)):
        if s[c]==s[int((len(s)-1)/2-c-1)]==s[int((len(s)+1)/2+c)]==s[len(s)-c-1] and b==0:
            b = 0
        else:
            b = 1
if b == 0:
    print("Yes")
elif b == 1:
    print("No")

Measured memory_bytes: 9096
N,X,Y=map(int,input().split())
A=[0]*(N)
for i in range(X-1):
  for j in range(i+1,X):
    A[j-i]+=1
    
for i in range(Y-1,N):
  for j in range(i+1,N):
    A[j-i]+=1    

for i in range(1,X+1):
  for j in range(Y,N+1):
    A[j-i-(Y-X-1)]+=1

for i in range(X+1,Y-1):
  for j in range(i+1,Y):
    a=(j-i)
    b=(Y-j)+(i-X)+1
    c=min(a,b)
    A[c]+=1

for i in range(1,X+1):
  for j in range(X+1,Y):
    d=j-i
    e=(X-i)+1+(Y-j)
    f=min(d,e)
    A[f]+=1

for i in range(X+1,Y):
  for j in range(Y,N+1):
    g=j-i
    h=(i-X)+1+(j-Y)
    k=min(g,h)
    A[k]+=1

for i in range(1,N):
  print(A[i])

Measured memory_bytes: 47452
import math

def trial(k):
    factor = []
    m = int(math.sqrt(k)) + 1
    for i in range(2,m):
        while k % i == 0:
            k = k // i
            factor.append(i)
    if not factor:
        return [1,k]
    else:
        factor.append(k)
        factor.append(1)
        return factor

def isPrime(x):
    return (len(trial(x)) == 2)

x = int(input())

while not isPrime(x):
    x += 1

print(x)


Measured memory_bytes: 3060
#!/usr/bin/env python
n = int(input())
A = sorted(list(map(int, input().split())), reverse=True)
cnt = {}
tmp = None
for a in A:
    cnt[a] = cnt.get(a, 0) + 1 
    if cnt[a]>=4:
        print(a*a)
        break
    if cnt[a]==2:
        if tmp:
            print(tmp*a)
            break
        tmp=a
else:
    print(0)

Measured memory_bytes: 14224
/*
Author : Chandan Agrawal
College : Poornima College of Engg. jaipur, Raj
Mail : chandanagrawal23@gmail.com


" when you are not practicing someone else is ,
 and the day u meet them u will lose "

*/
#include<bits/stdc++.h>
#include<stdio.h>
using namespace std;

#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define MAX 200050

#define ll long long
#define ld long double
#define lli long long int

#define pb push_back
#define INF 1000000000000
#define mod 1000000007

// trignometric function always give value in Radians only
#define PI acos(-1) //3.1415926535897932384626433832795028
#define dsin(degree) sin(degree*(PI/180.0))
#define dcos(degree) cos(degree*(PI/180.0))
#define dtan(degree) tan(degree*(PI/180.0))

#define rsin(radian) sin(radian)
#define rcos(radian) cos(radian)
#define rtan(radian) tan(radian)

#define mem0(a) memset(a,0,sizeof(a))
#define mem1(a) memset(a,-1,sizeof(a))
#define memf(a) memset(a,false,sizeof(a))

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

#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define makeuniq(v) v.resize(unique(all(v)) - v.begin()); //only uniq element in vector after this
#define sz(x) int(x.size())
#define F first
#define S second

#define mii map<lli,lli>

#define pii pair<lli,lli>

#define vi vector<lli>
#define vvi vector<vi>
#define vpi vector<pii>
#define vbool vector<bool>

#define seti set<lli>

#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) (a/gcd(a,b))*b
#define abs(x) ((x < 0)?-(x):x)

#define endl '\n'

template <typename T>
void print(T x){cout<<x<<endl;}
template <typename T1, typename T2>
void print2(T1 x,T2 y){cout<<x<<" "<<y<<endl;}
template <typename T1, typename T2,typename T3>
void print3(T1 x, T2 y,T3 z){cout<<x<<" "<<y<<" "<<z<<endl;}

#define scanarr(a,n) for(lli i=0;i<n;i++)    cin>>a[i];
#define scanvec(a,n) for(lli i=0;i<n;i++){ lli x ; cin>>x; a.pb(x);}

#define printarr(a,n) for(lli i=0;i<n;i++)   cout<<a[i]<<" "; cout<<endl;
#define printvec(vec) for(auto xt : vec) cout<<xt<<" ";    cout<<"\n";

#define FD(N) fixed<<setprecision(N)

#define deb(x) cout<<#x<<" "<<x<<endl;

/*
1D vector -  vi dp(n,value);
2D vector -  vvi dp(n,vi(n,value));
*/

// chandan1,2
void chandan1(){int y=1;return;}
void chandan2(){
        loop(i,10){
        lli x=1;
    }
    return(chandan1());
}


int main(){
fastio
lli tt=1;
//cin>>t;
chandan2();
while(tt--) {
    lli n,x,t;
    cin>>n>>x>>t;
    if(n%x==0){
        cout<<(n/x)*t;
    }
    else{
        cout<<(1+n/x)*t;
  }
}
return 0;
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
#define inf INT_MAX
#define INF LLONG_MAX
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define int ll
#define vi vector<int>
#define IP pair<int,P>
#define PI pair<P,int>
#define PP pair<P,P>
#define Yes(f){cout<<(f?"Yes":"No")<<endl;}
#define YES(f){cout<<(f?"YES":"NO")<<endl;}
int Madd(int x,int y) {return (x+y)%M;}
int Msub(int x,int y) {return (x-y+M)%M;}
int Mmul(int x,int y) {return (x*y)%M;}


signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(20);

  int n;
  cin>>n;
  vi a(n);
  rep(i,n){
    cin>>a[i];
  }

  int ans=0;
  rep(i,n){
    P p=P(i,a[i]);
    FOR(j,i,n){
      if(p.S>a[j]){
        p=P(j,a[j]);
      }
    }
    ans+=(p.F!=i);
    swap(a[i],a[p.F]);
  }

  rep(i,n){
    if(i) cout<<' ';
    cout<<a[i];
  }
  cout<<endl;
  cout<<ans<<endl;



}


Measured memory_bytes: 3208
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
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; }
// Welcome to my source code!

ll euclidean_gcd(int a, int b) {
    if (a < b) return euclidean_gcd(b, a);
    ll r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

int main() {
    ll a, b;
    cin >> a >> b;
    ll ab_gcd = euclidean_gcd(a, b);
    ll ans = a * b / ab_gcd;
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
#include <sstream>
#include <functional>
#include <unordered_map>
#include <set>

#include <cassert>
using namespace std;

int main(void){

	string s;
	cin >> s;
	vector<short> nx(1,0),ny(1,0);

	int dx,dy;
	cin >> dx >> dy;

	int ofx=0;
	int i;
	for(i=0;i<s.size();++i){
		if(s[i]=='T'){
			dx = abs(dx);
			dy = abs(dy);
			i+=1;
			break;
		}else{
			dx-=1;
		}
	}
	
	int d = 1; //0=x,1=y,最初は1回方向転換済みなのでy
	int cnt=0;
	for(;i<s.size();++i){
		auto &n = (d==0)?nx:ny;
		if (s[i]=='T'){
			if(cnt>0){
				for(int k=0;k<n.size();++k){ n[k] += cnt; }
				cnt=0;
			}

			d = 1 - d;
			continue;
		}

		// 'F'
		auto dd = (d==0)?dx:dy;
		if(s[i-1]=='T'){
			set<short> nnext;
			for(int k=0;k<n.size();++k){
				const auto &v = n[k];
				auto in1=v+1,in2=v-1;
				nnext.insert(in1);
				nnext.insert(in2*-1);
			}
			n.resize(0);
			n.reserve(nnext.size());
			for(auto it=nnext.begin();it!=nnext.end();++it){ n.push_back(*it); }
		}else{
			cnt+=1;
		}
	}

	if(cnt>0){
		auto &n = (d==0)?nx:ny;
		for(int k=0;k<n.size();++k){ n[k] += cnt; }
	}

	if(binary_search(nx.begin(),nx.end(),dx) && binary_search(ny.begin(),ny.end(),dy)){
		std::cout << "Yes" << endl;
	}else{
		std::cout << "No" << endl;
	}

	return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MS(a) memset(a,0,sizeof(a))
#define MP make_pair
#define PB push_back
const int INF = 0x3f3f3f3f;
const ll INFLL = 0x3f3f3f3f3f3f3f3fLL;
inline ll read(){
    ll x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
//////////////////////////////////////////////////////////////////////////
const int maxn = 1e5+10;

int a[105];

int main(){
	int n;
	cin >> n;
	for(int i=1; i<=n; i++)
		cin >> a[i];
	sort(a+1,a+1+n);
	int t = 0, p;
	for(int i=1; i<=n; i++){
		if(a[i]%10 != 0) {
			t = a[i];
			p = i;
			break;
		}
	}
	if(t == 0) {
		puts("0");
		return 0;
	}

	int sum = 0;
	for(int i=1; i<=n; i++){
		if(i == p) continue;
		sum += a[i];
	}
	if(sum%10 == 0) {
		cout << sum+t << endl;
	}else{
		if((sum+t)%10 != 0){
			cout << sum+t << endl;
		}else{
			cout << sum << endl;
		}
	}


    return 0;
}

Measured memory_bytes: 256
#pragma once
#include <stdio.h>
#include <sstream>
#include <string>
#include <string.h>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <deque>
#include <limits>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define bit(x,v) ((ll)x << v)

const ll INF = 1000000007;
const int MAX = 210000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
int pr[100010];
void uini(int n) {
	for (size_t i = 0; i <= n; i++)
	{
		pr[i] = i;
	}
}

int parent(int x) {
	if (x == pr[x]) return x;
	return pr[x] = parent(pr[x]);
}

bool unit(int x, int y) {
	int px = parent(x);
	int py = parent(y);

	if (px == py) return false;
	if (px < py) {
		pr[py] = px;
	}
	else {
		pr[px] = py;
	}
	return true;
}

// res[i][c] := i 文字目以降で最初に文字 c が登場する index (存在しないときは n)
vector<vector<int> > calcNext(const string& S) {
	int n = (int)S.size();
	vector<vector<int> > res(n + 1, vector<int>(26, n));
	for (int i = n - 1; i >= 0; --i) {
		for (int j = 0; j < 26; ++j) res[i][j] = res[i + 1][j];
		res[i][S[i] - 'a'] = i;
	}
	return res;
}
// mod 1000000007 の世界で a += b する関数
void add(long long& a, long long b) {
	a += b;
	if (a >= MOD) a -= MOD;
}
ll slide(vector<ll>& v, ll a, ll b) {
	ll azv = abs(v[0] - a);
	ll bzv = abs(v[0] - b);
	ll aov = abs(v[1] - a);
	ll bov = abs(v[1] - b);
	v[0] = a;
	v[1] = b;
	return max((azv + bov), (bzv + aov));
}


void solv() {

	int q;
	cin >> q;
	ll left[100010],right[100010];
	for (size_t i = 0; i < q; i++)
	{
		cin >> left[i] >> right[i];
	}

	bool pri[100010];
	fill(pri, pri + 100010, true);
	pri[0] = false;
	pri[1] = false;
	for (size_t i = 2; i < 100000; i++)
	{
		if (!pri[i]) continue;
		int pnum = i;
		while (pnum < 100000)
		{
			pnum += i;
			if(pnum <= 100000)
				pri[pnum] = false;
		}
	}

	ll ct[100010];
	fill(ct, ct + 100010, 0);
	int sum = 0;
	for (size_t i = 2; i < 100000; i++)
	{
		ct[i] += sum;
		sum = ct[i];
		if (!pri[i]) continue;
		ll ne = (i * 2) - 1;
		if (ne > 100000) continue;
		if (!pri[ne]) continue;
		ct[ne] = 1;
	}

	for (size_t i = 0; i < q; i++)
	{
		ll val = ct[right[i]] - ct[left[i] - 1];
		cout << val << endl;
	}

}


int main() {
	//COMinit();
	solv();

	return 0;
}


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

#define ll          long long
#define pb          push_back
#define endl        '\n'
#define mii         map<ll,ll>
#define pii         pair<ll,ll>
#define vi          vector<ll>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll)x.size()
#define hell        1000000007
#define INF         (1ll<<60)
#define rep(i,a,b)  for(ll i=a;i<=b;i++)
#define rrep(i,a,b)  for(ll i=a;i>=b;i--)
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define time        cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return a * (b / gcd(a, b)); }
const int N=100005;
void solve(){
    ll x,y,z;
    cin>>x>>y>>z;
    cout<<z<<" "<<x<<" "<<y<<endl; 
}
signed main()
{
    ios
    int TESTS=1;
    //cin>>TESTS;
    while(TESTS--){
        solve();
    }
    time
    return 0;
}

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

int main(){
    int A,B,C;
    scanf("%d %d %d",&A,&B,&C);
    int max=0;
    max = max>10*A+B+C? max:10*A+B+C;
    max = max>10*B+C+A? max:10*B+C+A;
    max = max>10*C+A+B? max:10*C+A+B;
    printf("%d",max);
    return 0;
}

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

// 総数を1000000007（素数）で割った余り
const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e17)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

struct Rank {
    int x, y, z;
    Rank(int x, int y, int z) : x(x), y(y), z(z) {}
    bool operator<(const Rank& a) const {
        return (x < a.x);
    }
};

int main(){
    int x, y, z, k;
    cin >> x >> y >> z >> k;
    vll a(x), b(y), c(z);
    rep(i, x) cin >> a[i];
    rep(i, y) cin >> b[i];
    rep(i, z) cin >> c[i];
    RSORT(a); RSORT(b); RSORT(c);
    a.pb(-INF); b.pb(-INF); c.pb(-INF);
    priority_queue<pair<ll, Rank>> q;
    set<int> s;
    auto ps = [&] (ll abc, Rank r) {
        int hash = (r.x<<20) + (r.y<<10) + r.z;
        if (s.find(hash)!=s.end()) return;
        q.push({abc, r});
        s.insert(hash);
    };
    vll ans;
    ps(a[0]+b[0]+c[0], {0, 0, 0});
    rep(i, k) {
        auto p = q.top(); q.pop();
        ans.pb(p.first);
        rep(j, 3) {
            int tx = p.second.x;
            int ty = p.second.y;
            int tz = p.second.z;
            if (j==0) ++tx;
            if (j==1) ++ty;
            if (j==2) ++tz;
            ps(a[tx]+b[ty]+c[tz], {tx, ty, tz});
        }
    }
    rep(i, k) cout << ans[i] << endl;
    return 0;
}


Measured memory_bytes: 896
#include "bits/stdc++.h"
#define rep(i,a,n) for(int i = a;i < n;i++)
typedef unsigned long long ull;
typedef long long ll;
using namespace std;

int main(){
    ll n,ans = 0;
    cin >> n;
    ll a[n-1],dp[21][n-1] = {0};
    
    rep(i,0,21){
        rep(j,0,n-1){
            dp[i][j] = 0;
        }
    }
  
    rep(i,0,n-1){
        cin >> a[i];
    }
    
    cin >> ans;
    
    dp[a[0]][0] = 1;
    
    rep(j,0,n-2){
        rep(i,0,21){
            if(i - a[j+1] >= 0){
                dp[i-a[j+1]][j+1] += dp[i][j];
            }
            if(i + a[j+1] <= 20){
                dp[i+a[j+1]][j+1] += dp[i][j]; 
            }
        }
    }
    
    
    
    cout << dp[ans][n-2] << endl;
    
    return 0;
}


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

int main()
{
	char num[1010];
	scanf("%s",num);
	
	int i,j,flag=1;
	
	for(i=0,j=strlen(num)-1;i<strlen(num)/2;i++,j--)
	{
		if(num[i] == num[j] && i<=j){
		//	cout << num [i] << num[j] << endl;
			flag = 1;
		}  
		else{
			flag = 0;
			break;
		}
	}
//	cout << "Flag:  " << flag << endl;
	if(flag == 1) cout << "Yes\n";
	else cout << "No\n";
}

Measured memory_bytes: 3688
#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <set>
#include <algorithm>
#include <unordered_map>
#include <queue>
#include <iomanip>
#include <map>
#include <utility>
#include <numeric>
#include <chrono>
#include <ctime>
#include <bitset>

#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define P pair<int, int>
#define debug(x) cerr << #x << ": " << x << ", "
#define debugln(x) cerr << #x << ": " << x << '\n'

using namespace std;
using ll = long long;
const ll mod = 1e9+7;

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

  int n; cin >> n;
  vector<int> a(n);
  rep(i, n) {
    cin >> a.at(i);
  }
  int ans = 0;
  int now = 0;
  while (now != 1) {
    ans++;
    now = a.at(now) - 1;
    if (ans > n) {
      cout << -1 << endl;
      return 0;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 640
#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>;
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)

const int mod = 998244353;
struct mint {
ll x; 
mint(ll x=0):x((x%mod+mod)%mod){}
mint operator-() const { return mint(-x);}
mint& operator+=(const mint a) {
if ((x += a.x) >= mod) x -= mod;
return *this;
 }
mint& operator-=(const mint a) {
if ((x += mod-a.x) >= mod) x -= mod;
return *this;
 }
 mint& operator*=(const mint a) {
(x *= a.x) %= mod;
return *this;
}
mint operator+(const mint a) const {
mint res(*this);
return res+=a;
}
mint operator-(const mint a) const {
mint res(*this);
return res-=a;
}
 mint operator*(const mint a) const {
mint res(*this);
return res*=a;
}
mint pow(ll t) const {
if (!t) return 1;
mint a = pow(t>>1);
a *= a;
if (t&1) a *= *this;
return a;
}
 mint inv() const {
return pow(mod-2);
 }
  mint& operator/=(const mint a) {
return (*this) *= a.inv();
 }
mint operator/(const mint a) const {
mint res(*this);
return res/=a;
 }
};
struct combination {
vector<mint> fact, ifact;
combination(int n):fact(n+1),ifact(n+1) {
  assert(n < mod);
 fact[0] = 1;
 for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
 ifact[n] = fact[n].inv();
  for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
}
mint operator()(int n, int k) {
if (k < 0 || k > n) return 0;
return fact[n]*ifact[k]*ifact[n-k];
}
  };
int main() {
ios::sync_with_stdio(false);
cin.tie(0);

int n;
cin>>n;
vector<int>d(n);
rep(i,n)cin>>d[i];

map<int,int>mp;
mint ans=1;
rep(i,n){
    mp[d[i]]++;
}
if(d[0]!=0||mp[0]!=1){
    cout<<0<<endl;
    return 0;
}
rep(i,mp.size()){
    if(mp[i]==0){
    cout<<0<<endl;
    return 0;
}
    if(i==0)continue;
    ans*=mint(mp[i-1]).pow(mp[i]);
}
cout<<ans.x<<endl;

return 0;
}


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

using namespace std;

typedef long long ll;
typedef long double ld;

int niz[1000005];

int main(){
    ios_base::sync_with_stdio(false);
	cout.precision(10);
	cout << fixed;

	int n;
	cin >> n;
    for(int i=1; i<=n; i++){
        cin >> niz[i];
    }
    int cnt = 0;
    for(int i=1; i<n; i++){
        if(niz[i] == i){
            swap(niz[i], niz[i+1]);
            cnt++;
        }
    }
    if(niz[n] == n) cnt++;
    cout << cnt;
    return 0;
}


Measured memory_bytes: 640
H, N = map(int, input().split())
A, B = [], []
for i in range(N):
	a, b = map(int, input().split())
	A.append(a)
	B.append(b)

# dp
INF = 1 << 30
dp = [INF] * (H + 1) # dp[i]: モンスターの体力を i 減らすため消耗する魔力の最小値
dp[0] = 0
for h in range(H + 1):
	for n in range(N):
		dp[h] = min(dp[h], B[n] + dp[max(h - A[n], 0)])

print(dp[H])

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

int main()
{
	string S;
	string T_elements[4] = { "dream", "dreamer", "erase", "eraser" };
	string answer;
	bool tmpCanDivideFlag;
	bool canDivideFlag;

	cin >> S;

	// 左右反転
	reverse(S.begin(), S.end());
	for (int i = 0; i < 4; i++) {
		reverse(T_elements[i].begin(), T_elements[i].end());
	}

	canDivideFlag = true;

	// Sを調べる
	for (int i = 0; i < S.size();) {

		tmpCanDivideFlag = false;

		// T_elementsのどれかでdivideできるか
		for (int j = 0; j < 4; j++) {
			
			string tmpS = S.substr(i, T_elements[j].size());

			// divideできる
			if (tmpS == T_elements[j]) {
				
				tmpCanDivideFlag = true;

				// 次に進む
				i += T_elements[j].size();
			}

		}

		if (!tmpCanDivideFlag) {
			canDivideFlag = false;
			break;
		}

	}
	
	if (canDivideFlag) {
		answer = "YES";
	}
	else {
		answer = "NO";
	}
	
	cout << answer <<  endl;

	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define GET_REP(_1, _2, _3, NAME, ...) NAME
#define rep(...) GET_REP(__VA_ARGS__, irep, _rep)(__VA_ARGS__)
#define rep1(...) GET_REP(__VA_ARGS__, irep1, _rep1)(__VA_ARGS__)
#define _rep(i, n) irep (i, 0, n)
#define _rep1(i, n) irep1(i, 1, n)
#define irep(i, a, n) for (int i = a; i < (int)(n); ++i)
#define irep1(i, a, n) for (int i = a; i <= (int)(n); ++i)
#define rrep(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define rrep1(i, n) for (int i = (int)(n); i >= 1; --i)
#define allrep(X, x) for (auto &&X : x)
#define all(x) begin(x), end(x)
#define debug(x) cout << #x " => " << (x) << endl
#ifdef LOCAL
  #include "../../Lib/cout_container.hpp"
#endif
using lint = long long;
constexpr int MOD = (int)1e9 + 7;
constexpr double EPS = 1e-9;
using namespace std;
namespace { struct INIT { INIT() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(15); } } INIT; }

int main(void) {
  int m1, m2, d1, d2;
  cin >> m1 >> d1 >> m2 >> d2;
  cout << (d2 == 1 ? 1 : 0) << endl;
  return 0;
}

Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var a, b int
	fmt.Scanf("%d %d", &a, &b)
	if a != 1 && b != 1 {
		if a > b {
			fmt.Println("Alice")
		} else if  a < b {
			fmt.Println("Bob")
		} else {
			fmt.Println("Draw")
		}
	} else if a == 1 {
		if b == 1 {
			fmt.Println("Draw")
		} else {
			fmt.Println("Alice")
		}
	} else if b == 1 {
		if a == 1 {
			fmt.Println("Draw")
		} else {
			fmt.Println("Bob")
		}
	}
}

Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
using namespace std;

int main(){
  int N;
  char ch[4] = {'S', 'H', 'C', 'D'};
  cin >> N;
  vector<pair<char,int> >v(N);
  for(int i=0;i<N;i++){
    cin >> v[i].first;
    cin >> v[i].second;
  }

  for(int i=0;i<4;i++){
    for(int j=1;j<=13;j++){
      for(int k=0;k<N;k++){
        if(ch[i] == v[k].first && j == v[k].second){
          break;
        }
        if(k == N-1){
          cout << ch[i] << " " << j << endl;
        }
      }
    }
  }
  return 0;
}

Measured memory_bytes: 1196