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

int main(){
	int n;
	cin >> n;
    string ans="No";
    for(int i=1; i<=9; i++){
        for(int j=i; j<=9; j++){
            if(i*j==n){
                ans="Yes";
                goto OUT;
            }
        }
    }
OUT:    cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
	// 入力 h:体力　n:必殺技の数
	int h,n;

	cin >> h >> n;

	int attack[100000];
	for (int i = 0; i < n; ++i) {
		cin >> attack[i];
	}

	bool enable = false;
	for (int i = 0; i < n; ++i) {
		h -= attack[i];
		if (h <= 0) {
			enable = true;
			break;
		}
	}
	cout << (enable ? "Yes":"No") << endl;
	return 0;
}

Measured memory_bytes: 640
import sys
from collections import Counter
input = sys.stdin.readline

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

count = Counter(A)
sm = {}
sm2 = {}
for key, value in count.items():
    sm[key] = value*(value-1)//2
    sm2[key] = (value-1)*(value-2)//2
total = sum(sm.values())

for num in A:
    print(total - sm[num] + sm2[num])


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

#define TRACE(x) x
#define WATCH(x) TRACE(cout << #x" = " << x << endl)
#define WATCHR(a, b) TRACE(for (auto it=a; it!=b;) cout << *(it++) << " "; cout << endl)
#define WATCHC(V) TRACE({cout << #V" = "; WATCHR(V.begin(), V.end());})

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

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vs = vector<string>;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);

    int N, Z, W;
    cin >> N >> Z >> W;

    vi deck(N);
    for (int i = 0; i < N; i++) {
        cin >> deck[i];
    }
    reverse(all(deck));

    deck.push_back(W);
    deck.push_back(Z);
    N += 2;

    vvi play(N, vi(N, INT_MAX));
    vi prefX(N); // prefX[c] = min over play[c][oc < c]
    vi prefY(N); // prefY[c] = max over play[oc < c][c]

    for (int oc = 1; oc < N; oc++) {
        prefX[oc] = prefY[oc] =
        play[0][oc] = play[oc][0] = abs(deck[0] - deck[oc]);
    }

    for (int lc = 1; lc < N; lc++) {
        for (int hc = lc + 1; hc < N; hc++) {
            play[lc][hc] = prefX[lc];
            prefY[hc] = max(prefY[hc], play[lc][hc]);
            play[hc][lc] = prefY[lc];
            prefX[hc] = min(prefX[hc], play[hc][lc]);
        }
    }

    cout << play[N-1][N-2] << endl;

    return 0;
}



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

ll func(int N, int b, int K){
    ll count = 0;
    ll countRem = max(N % b + 1 - K, 0);
    ll countCycle = b - K;
    ll numCycle = std::floor(N / b);
    return numCycle * countCycle + countRem;
}

int main(){
    int N, K;
    cin >> N >> K;
    ll count = 0;
    if (K == 0){
        count = N;
        count *= N;
    } else {
        for (int b=K+1; b<=N; b++){
            //cout << b << ":" << func(N, b, K) << endl;
            count += func(N, b, K);
        }
    }
    cout << count << endl;
}

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

using namespace std;

const int INF = (1 << 30);
int n, m, viz[100002], dist[100002];
vector<int>g[100002];
stack<int>st;

void dfs (int x) {
  for (int i = 0; i < g[x].size(); i++) {
    if (viz[g[x][i]] == 0) {
      viz[g[x][i]] = 1;
      dfs(g[x][i]);
    }
  }
  st.push(x);
}

int main()
{
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    int x, y;
    cin >> x >> y;
    g[x].push_back(y);
  }
  for (int i = 1; i <= n; i++) {
    if (viz[i] == 0) {
      viz[i] = 1;
      dfs(i);
    }
  }
  for (int i = 1; i <= n; i++)
    dist[i] = -INF;
  while (st.empty() == false) {
    int u = st.top();
    st.pop();
    if (dist[u] == -INF)
      dist[u] = 0;
    for (int i = 0; i < g[u].size(); i++) {
      int v = g[u][i];
      if (dist[v] < dist[u] + 1)
        dist[v] = dist[u] + 1;
    }
  }
  int ans = 0;
  for (int i = 1; i <= n; i++)
    ans = max(ans, dist[i]);
    cout << ans;
  return 0;
}


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

int main(void){
    int N, M;
    cin >> N >> M;
    
    vector<int> X(M);

    for (int i = 0; i < M; i++)
    {
        cin >> X[i];
    }
    
    sort(X.begin(), X.end());

    priority_queue<int> dist;
    
    for(int i = 0; i < M - 1; i++){
        dist.push(X[i+1]- X[i]);
    }

    for(int i = 0; i < N-1; i++){
        if(dist.empty()) break;
        int d = dist.top();
        dist.pop();
    }

    int sum = 0;
    while (!dist.empty())
    {
        sum+=dist.top();
        dist.pop();
    }

    cout << sum << endl;

    return 0;
}


Measured memory_bytes: 4144
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <set>
#include <cmath>

using namespace std;

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

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

    sort(v.begin(), v.end(), greater<int>());

    int count = 0;
    for (int i = 0; i < n - 2; ++i) {
        for (int j = i + 1; j < n - 1; ++j) {
            for (int k = j + 1; k < n; ++k) {
                if (v[i] < v[j] + v[k] && v[i] != v[j] && v[j] != v[k]) {
                    count++;
                }
            }
        }
    }

    cout << count;
}

Measured memory_bytes: 3604
<?php
/*
    http://code-festival-2016-quala.contest.atcoder.jp/tasks/codefestival_2016_qualA_b

    Score  :
    Result :
    Time   : ms
    Memory : KB
 */

fscanf(STDIN, "%d", $N);
$a = explode(" ", trim(fgets(STDIN)));

$ans = 0;

for ($i = 0; $i < $N; $i++) {
	$suki = $a[$i] - 1;
	$aite = $a[$suki] - 1;
	// echo "{$i} {$suki} {$aite}\n";
	if ($aite === $i) { 
		$ans++;
		$a[$suki] = "X";
	}
}

echo $ans . PHP_EOL;

Measured memory_bytes: 21684
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = ll(A); I < ll(B); ++I)
#define FORR(I,A,B) for(ll I = ll((B)-1); I >= ll(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a%b==0)return b;return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=ll(1e16)+ll(7);
const ll MOD=1000000007LL;
#define out(a) cout<<fixed<<setprecision((a))


int main(){
	ll n;
	cin >> n;
	vector<int> t(n);
	vector<string> s(n);
	FOR(i,0,n){
		cin >> s[i] >> t[i];
	}
	ll ans = 0;
	bool ok = false;
	string x;
	cin >> x;
	FOR(i,0,n){
		if(ok) ans += t[i];
		if(s[i]==x) ok = true;
	}
	cout << ans << endl;
}



Measured memory_bytes: 256
x=input()
x=int(x)
a=x%10
b=x//10%10
c=x//100%10
d=x//1000%10
e=x//1000%10
d='Good'
if a==b:
  d='Bad'
if b==c:
  d='Bad'
if c==e:
  d='Bad'
print(d)

Measured memory_bytes: 2940
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <tuple>
#include <numeric>
#define rep(i, s, g) for ((i) = (s); (i) < (g); ++(i))
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll MOD = 1e9 + 7;
const ll INF = (1ll << 60);

int main(void)
{
    int h, w;
    cin >> h >> w;

    vector<bool> x(w, false), y(h, false);

    vector<vector<char>> v(h, vector<char>(w));

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

            if (v[i][j] == '#')
            {
                x[j] = true;
            }
        }
    }

    for (int i = 0; i < w; i++)
    {
        for (int j = 0; j < h; j++)
        {
            if (v[j][i] == '#')
            {
                y[j] = true;
            }
        }
    }

    for (int i = 0; i < h; i++)
    {
        for (int j = 0; j < w; j++)
        {
            if (y[i] && x[j])
            {
                cout << v[i][j];
            }
        }
        if (y[i])
        {
            cout << endl;
        }
    }
}


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

int W, H;
bool Buildings[102][102] = {0};
bool visible[102][102] = { false };

void visibilityDiffusion(int w, int h){
	if (w == 0 || h == 0 || w == W + 1 || h == H + 1) return;
	if (visible[w][h]) return;

	visible[w][h] = true;
	if (!Buildings[w - 1][h]) visibilityDiffusion(w - 1, h);
	if (!Buildings[w + 1][h]) visibilityDiffusion(w + 1, h);

	if (!Buildings[w][h - 1]) visibilityDiffusion(w, h - 1);
	if (!Buildings[w][h + 1]) visibilityDiffusion(w, h + 1);
	if (h % 2 == 1){
		// odd
		if (!Buildings[w + 1][h - 1]) visibilityDiffusion(w + 1, h - 1);
		if (!Buildings[w + 1][h + 1]) visibilityDiffusion(w + 1, h + 1);
	}
	else{
		// even
		if (!Buildings[w - 1][h - 1]) visibilityDiffusion(w - 1, h - 1);
		if (!Buildings[w - 1][h + 1]) visibilityDiffusion(w - 1, h + 1);
	}
}

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

	// 建物がない場所のうち、外から見える部分を探索する
	for (int i = 1; i <= W; i++){
		if (!Buildings[i][1]) visibilityDiffusion(i, 1);
		if (!Buildings[i][H]) visibilityDiffusion(i, H);
	}
	for (int i = 1; i <= H; i++){
		if (!Buildings[1][i]) visibilityDiffusion(1, i);
		if (!Buildings[W][i]) visibilityDiffusion(W, i);
	}

	int ans = 0;
	int hole = 0;
	for (int i = 1; i <= H; i++){
		for (int j = 1; j <= W; j++){
			if (Buildings[j][i]){
				ans += 6;
				if (Buildings[j+1][i]) ans -= 2;
				if (i % 2 == 1){
					// odd
					if (Buildings[j][i+1]) ans -= 2;
					if (Buildings[j+1][i+1]) ans -= 2;
				}
				else{
					// even
					if (Buildings[j][i+1]) ans -= 2;
					if (Buildings[j-1][i+1]) ans -= 2;
				}
			}
			else if (!visible[j][i]){
				hole += 6;
				if (!Buildings[j+1][i]) hole -= 2;
				if (i % 2 == 1){
					// odd
					if (!Buildings[j][i+1]) hole -= 2;
					if (!Buildings[j+1][i+1]) hole -= 2;
				}
				else{
					// even
					if (!Buildings[j][i+1]) hole -= 2;
					if (!Buildings[j-1][i+1]) hole -= 2;
				}
			}
		}
	}

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

Measured memory_bytes: 1708
#include <stdio.h>

int main(void)
{
	int a, b, c;
	scanf("%d %d %d", &a, &b, &c);
	int m1, m2, m3;
	m1 = a + b;
	m2 = b + c;
	m3 = c + a;
	if (m1 <= m2)
	{
		if (m1 <= m3)
			printf("%d", m1);
		else 
			printf("%d", m3);
	}
	else 
	{
		if (m3 <= m2)
			printf("%d", m3);
		else
			printf("%d", m2);
	}
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define EPS 1e-9
#define MOD 1000000007
#define int long long
using namespace __gnu_pbds;
using namespace std;
typedef pair<int, int> pii;
typedef tree<int, null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update> ost;
#define INF 10000000000


int dp[100005];
int32_t main(){
	int n;
	cin >> n;
	int a[n];
	for(int i = 0; i < n; i++)
		cin >> a[i];
	for(int i = 1; i < n; i++){
		dp[i] = min(dp[i-1]+abs(a[i]-a[i-1]), (i > 1 ? dp[i-2] + abs(a[i]- a[i-2]) : INF ));
	}

	cout << dp[n-1];

	return 0;
}

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

int compare_int(const void *a, const void *b)
{
    return *(int*)a - *(int*)b;
}

int main(){
  int N,X;
  scanf("%d%d",&N,&X);
  int i;
  int m[N];
  for(i=0;i<N;i++){
    scanf("%d",&m[i]);
  }
  for(i=0;i<N;i++){
    X=X-m[i];
  }
  qsort(m, N, sizeof(int), compare_int);
  printf("%d",N+(int)(X/m[0]));
  return 0;
}


Measured memory_bytes: 128
import sys
from fractions import gcd

input = sys.stdin.readline


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


def main():
    N, M = map(int, input().split())
    S = input().rstrip()
    T = input().rstrip()

    L = lcm(N, M)
    n = L // N
    m = L // M

    ans = L
    i = 0
    while i < L // (n * m):
        if S[m * i] != T[n * i]:
            ans = -1
            break
        i += 1

    print(ans)


if __name__ == "__main__":
    main()


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

int n = 8;
int row[8] = {}, col[8] = {}, dpos[16] = {}, dneg[16] = {}; //0->free
int queen[8][8] = {}; //0->free

void printBoard(){

  for(int i = 0;i < n;i++){
    for(int j = 0;j < n;j++){
      if(queen[i][j] && row[i] != j) return ;
    }
  }

  for(int i = 0;i < n;i++){
    for(int j = 0;j < n;j++){
      if(row[i] == j) cout << 'Q';
      else cout << '.';
    }
    cout << endl;
  }
}

void putQueen(int i){

  //print
  if(i == n){
    printBoard();
    return ;
  }

  for(int j = 0;j < n;j++){
    if(col[j] || dpos[i + j] || dneg[i - j + n - 1]) continue;

    //put queen
    row[i] = j;
    col[j] = dpos[i + j] = dneg[i - j + n - 1] = 1; //not free

    //next row
    putQueen(i + 1);

    //backtracking
    col[j] = dpos[i + j] = dneg[i - j + n - 1] = 0; //free
  }
}

int main(){

  int k, r, c;

  //input
  cin >> k;
  for(int i = 0;i < k;i++){
    cin >> r >> c;
    queen[r][c] = 1;
  }

  //solve and output
  putQueen(0);

  return 0;
}


Measured memory_bytes: 3112
#include <bits/stdc++.h>
#include <vector> 
# include <cstdint>
#define FOR(i,l,r) for(int i=(l);i<(r);++i)
#define RFOR(i,l,r) for(int i=(l);i>=(int)(r);i--)
#define rep(i,n)  FOR(i,0,n)
#define rrep(i,n)  RFOR(i,n-1,0)

#define int long long
using namespace std;
const int MX = 1e6;
const int inf = 1e9;
const int mod = 998244353;
using ll = long long;
using P = pair<ll, ll>;
double PI = acos(-1);
map<ll, ll> prime_factors(ll n) {
    map<ll, ll> res;
    if(n == 1) { // n=1 の素因数分解は n^1
        res[n] = 1;
        return res;
    }
    for(ll i = 2, _n = n; i*i <= _n; ++i) {
        while(n % i == 0) {
            ++res[i]; // 素数i^{res[i]}
            n /= i;
        }
    }
    if(n != 1) res[n] = 1;
    return res;
}

signed main(){
    int n,m,k;
    cin >> n >> m>>k;
    int ans=0;
    vector<int> a(n);
    vector<int> b(m);
    rep(i,n) cin>>a[i];
    rep(i,m) cin>>b[i];
    vector<int> as(n+1);
    vector<int> bs(m+1);
    as[0]=0;
    bs[0]=0;
    rep(i,n) as[i+1]+=a[i]+as[i];
    rep(i,m) bs[i+1]+=b[i]+bs[i];
    //sort(bs.begin(),bs.end(),)
    if(as[0]>k) {
        rep(i,m) {
            if(bs[i]<=k) {
                ans++;
            }
        }
    }
    rep(i,n+1) {
        if(as[i]>k) break;
        int md = k-as[i];
        int p = upper_bound(bs.begin(),bs.end(),md)-bs.begin();
        //if(p+1as[p]==)
        //cout << i<<" "<<as[i]<<" "<< md <<" "<< p-1 << endl;
        ans = max(ans, i+p-1);
    }

    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 9512
/* Dsingh_24 */

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

#define N  100005
ll cal(ll x){
	return (x*x*x*x*x);
}
int main()
{
	ios
	int TESTS=1;
//	cin>>TESTS;
	while(TESTS--)
	{
		ll x,i,j;
		cin>>x;
		for(i=0;i<1000;i++){
			ll p=cal(i);
			ll dif=p-x;
			for(j=-i+1;j<i;j++){
				ll pp=cal(j);
				if(dif==pp){
					cout<<i<<" "<<j<<"\n";return 0;
				}
			}
		}
	}
	return 0;
}

Measured memory_bytes: 3640
import java.util.Scanner;
class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int K = sc.nextInt();
        int count = 1;

        while (N >= K) {
            N /= K;
            count++;
        }
        System.out.println(count);
    }
}

Measured memory_bytes: 22612
N = int(input())
G = [[] for i in range(N)]
for i in range(N-1):
    a, b = map(int, input().split())
    G[a-1].append(b-1)
    G[b-1].append(a-1)

from collections import deque
def bfs(v):
    que = deque([v])
    dist = {v: 0}
    prev = {v: v}
    while que:
        u = que.popleft()
        d = dist[u]
        for w in G[u]:
            if w in dist:
                continue
            dist[w] = d + 1
            prev[w] = u
            que.append(w)
    w = u
    D = []
    while w != v:
        D.append(w)
        w = prev[w]
    D.append(v)
    return u, D

from collections import deque
def solve(u, v = -1):
    que = deque([u])
    if v != -1:
        que.append(v)
    used = set([u, v])
    D = {v: 0, u: 0}
    E = {}
    if v != -1:
        E[0] = max(len(G[v]), len(G[u]))-1
    else:
        E[0] = len(G[u])
    x = v
    while que:
        v = que.popleft()
        d = D[v]
        for w in G[v]:
            if w in used:
                continue
            D[w] = d + 1
            que.append(w)
            used.add(w)
            E[d+1] = max(E.get(d+1, 0), len(G[w])-1)
    res = 2 if x != -1 else 1
    for v in E.values():
        if v: res *= v
    return res

D = bfs(bfs(0)[0])[1]
L = len(D)

col = (L + 1) // 2

if L % 2 == 1:
    ans = 10**18
    v = D[L//2]
    for w in G[v]:
        ans = min(ans, solve(v, w))
    ans = min(ans, solve(v))
else:
    v = D[L//2-1]; w = D[L//2]
    ans = solve(v, w)
print(col, ans)


Measured memory_bytes: 3444
A = int(input())
B = int(input())
C = int(input())
D = int(input())
E = int(input())
K = int(input())

lists=[]
lists.append(A)

lists.append(B)
lists.append(C)
lists.append(D)
lists.append(E)
import itertools 
T=list(itertools.combinations(lists,2))
ans =0
for i in T:
    if abs(i[0]-i[1]) > ans:
        ans = abs(i[0]-i[1])
if ans > K:
    print(':(')

else:
    print('Yay!')

Measured memory_bytes: 3064
/* be name khoda */

// #define stream_enable
#define long_enable
#include <iostream>
#include <algorithm>
#include <cstring>
#include <numeric>
#include <iomanip>
#include <sstream>
#include <vector>
#include <queue>
#include <set>
#include <map>
using namespace std;

#ifdef stream_enable
#define cin sss
#endif
#ifdef long_enable
typedef long long int ll;
#else
typedef int ll;
#endif

typedef pair<ll, ll> pii;
typedef pair<pii, ll> ppi;
typedef pair<ll, pii> pip;
typedef vector<ll> vi;
typedef vector<pii> vpii;

const ll MOD = 1000000007;
const long long BIG = 1446803456761533460;
const int Big = 336860180;

#define F first
#define S second
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(), (x).end()

#define debug(x) cout << #x << " -> " << (x) << endl
#define debug2(x, y) cout << #x << ' ' << #y << " -> " << (x) << ' ' << (y) << endl
#define debug3(x, y, z) cout << #x << ' ' << #y << ' ' << #z << " -> " << (x) << ' ' << (y) << ' ' << (z) << endl
#define debug4(x, y, z, t) cout << #x << ' ' << #y << ' ' << #z << ' ' << #t << " -> " << (x) << ' ' << (y) << ' ' << (z) << ' ' << (t) << endl
#define debugp(x) cout << #x << " -> " << "(" << (x).F << ", " << (x).S << ")" << endl
#define debuga(x, n) cout << #x << " -> "; fori (i1_da, n) { cout << (x)[i1_da] << ' '; } cout << endl
#define debugap(x, n) cout << #x << " ->\n"; fori (i1_dap, n) { cout << "(" << (x)[i1_dap].F << ", " << (x)[i1_dap].S << ")\n"; } cout << endl
#define debugaa(x, n, m) cout << #x << " ->\n"; fori (i1_daa, n) { fori (i2_daa, m) { cout << (x)[i1_daa][i2_daa] << ' '; } cout << '\n'; } cout << endl
#define debugav(x, n) cout << #x << " ->\n"; fori (i1_dav, n) { fori (i2_dav, (x)[i1_dav].size()) { cout << (x)[i1_dav][i2_dav] << ' '; } cout << '\n'; } cout << endl
#define debugia(x, n) cout << #x << " ->\n"; fori (i1_dia, n) { cout << i1_dia << " : " << (x)[i1_dia] << '\n'; } cout << endl

#define forifrom(i, s, n) for(ll i = (s); i < (n); ++i)
#define forirto(i, n, e) for(ll i = (n) - 1; i >= (e); --i)
#define fori(i, n) forifrom (i, 0, n)
#define forir(i, n) forirto (i, n, 0)

#define smin(a, b) a = min(a, (b))
#define smax(a, b) a = max(a, (b))

#define Add(a, b) a = (a + (b)) % MOD
#define Mul(a, b) a = (a * (b)) % MOD

stringstream sss;

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

const ll maxn = 100010;

ll n;
ll A[maxn];
ll dp[maxn][2];

void MAIN() {

    cin >> n;
    fori (i, n) cin >> A[i];
    memset(dp, 128, sizeof dp);
    dp[0][0] = 0;
    fori (i, n) {
        dp[i + 1][0] = A[i] / 2 + dp[i][0];
        if (A[i] >= 1) {
            smax(dp[i + 1][0], (A[i] - 1) / 2 + 1 + dp[i][1]);
            dp[i + 1][1] = (A[i] - 1) / 2 + dp[i][0];
        }
        if (A[i] >= 2) {
            smax(dp[i + 1][1], A[i] / 2 + dp[i][1]);
        }
    }
    cout << dp[n][0] << '\n';

}

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

int main() {
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    cout << fixed << setprecision(10);
    sss << R"(
4
4
0
3
2

8
2
0
1
6
0
8
2
1
    )";
    MAIN();
    return 0;
}


Measured memory_bytes: 2560
#include <stdio.h>
#include <string.h>

int main()
{
    char s[80];
    int i = 0, j, length = 0;
    
    while(gets(s)){
    	char t[80] = {};
        for (i = 0; i < 26; i++){
            for (j = 0; j < strlen(s); j++){
            	if (s[j] >= 'a' && s[j] <= 'z') t[j] = s[j] + i  > 'z' ? s[j] + i - 26 : s[j] + i;
            	else t[j] = s[j];
            	
            }
            if (strstr(t, "the") != NULL || strstr(t, "this") != NULL || strstr(t, "that") != NULL) break;
        }
        printf("%s\n", t);
    }
    return 0;
}

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


int main()
{
    int a,b,c,x;cin>>a>>b>>c>>x;
    int ans = 0;
    for(int i = 0; i <= a; i++){
        for(int j = 0; j <= b; j++){
            for(int k = 0; k <= c; k++){
                int sum = i*500+j*100+k*50;
                if(sum == x) ans++;
            }
        
        }
    
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
  
  int x,y;
  
  do{
    cin >> x >> y;
    if(x==0&&y==0)
      break;
    else if(x<y)
      cout << x << ' ' << y << '\n';
    else if(y<x)
      cout << y << ' ' << x << '\n';
    else if(x==y)
      cout << x << ' ' << y << '\n';
  }while(x>=0||y>=0);
  return 0;
}

Measured memory_bytes: 2992
#include <stdio.h>
#include <algorithm>
using namespace std;

int a[111];

int main(void)
{
	int m, n, i, sum = 0, cnt = 0;

	scanf("%d %d", &n, &m);
	for (i = 1; i <= n; i++)
	{
		scanf("%d", &a[i]);
		sum += a[i];
	}

	sort(a + 1, a + n + 1);

	for (i = n; i >= 1; i--)
		if ((double)a[i] >= (double)sum / 4.0 / (double)m)
			++cnt;

	if (cnt >= m)
		puts("Yes");
	else
		puts("No");
	return 0;
}

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

const int MAX = 50+1;

int main() {
        int n, m;
        cin >> n >> m;
        string a[MAX], b[MAX];
        for (int i=0; i<n; ++i) {
                cin >> a[i];
        }
        for (int j=0; j<m; ++j) {
                cin >> b[j];
        }

        for (int j=0; j<=n-m; ++j) {

                for (int i=0; i<=n-m; ++i) {
                        string tmp;
                        tmp = a[j].substr(i, m);
                        if (tmp.compare(b[0])==0) {
                                bool find = true;
                                for (int ii=j; ii<m+j; ++ii) {
                                        string t = a[ii].substr(i, m);
                                        if (t.compare(b[ii-j])!=0) {
                                                find = false;
                                                break;
                                        }
                                }
                                if (find) {
                                        cout << "Yes" << endl;
                                        return 0;
                                }
                        }
                }
        }
        cout << "No" << endl;
        return 0;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define fore(i,a) for(auto &i:a)
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧  
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     
　　　　／　　　＼　 　  |　|     
　　　 /　　 /￣￣￣￣/　　|  
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿  
　 　　　＼/＿＿＿＿/　（u　⊃  
---------------------------------------------------------------------------------------------------*/
 
 
typedef long long ll;
ll hint = 10;
int get(ll n) {
    if (n == 0) return 0;
 
    printf("? %lld\n", n);

    fflush(stdout);
    string s; cin >> s;
    if (s == "Y") return 1;
    else return 0;
}
//---------------------------------------------------------------------------------------------------
ll str2int(string s) {
    ll res = 0;
    fore(i, s) res = res * 10 + i - '0';
    return res;
}
//---------------------------------------------------------------------------------------------------
int findDigit() {
    int ng = 1, ok = 19;
    while (ng + 1 != ok) {
        int x = (ng + ok) / 2;
        string s = "1";
        rep(i, 0, x - 1) s += "0";
        if (!get(str2int(s))) ok = x;
        else ng = x;
    }
    int dig = ok - 1;

    if (dig == 18) {
        ng = 0, ok = 11;
        while (ng + 1 != ok) {
            int x = (ng + ok) / 2;
            string s = "9";
            rep(i, 0, x - 1) s += "9";
            if (get(str2int(s))) ok = x;
            else ng = x;
        }
        dig = ok;
    }

    return dig;
}
//---------------------------------------------------------------------------------------------------
ll solve() {
    int dig = findDigit();
 
    string ans = "";
    rep(i, 0, dig - 1) {
        int ok = 0, ng = 10;
        while (ok + 1 != ng) {
            int x = (ok + ng) / 2;
            string a = ans + char('0' + x);
            if (get(str2int(a))) ok = x;
            else ng = x;
        }
        ans += char('0' + ok);
    }
 
    int ng = -1, ok = 10;
    while (ng + 1 != ok) {
        int x = (ok + ng) / 2;
        string a = ans + char('0' + x) + "0";
        if (get(str2int(a))) ok = x;
        else ng = x;
    }
    ans += char('0' + ok);
 
    return str2int(ans);
}
//---------------------------------------------------------------------------------------------------
void _main() {
    ll a = solve();
    printf("! %lld\n", a);
}

Measured memory_bytes: 596
#include<stdio.h>
int main()
{
  int m, f, r, ans;

  while(1){
    scanf("%d%d%d", &m, &f, &r);
    if(m == -1 && f == -1 && r == -1) break;
    
    ans = m + f;

    if(m == -1 || f == -1 || ans < 30){
      printf("F\n");
      continue;
    }

    else{
      if(80 <= ans){
	printf("A\n");
	continue;
      }
      
      if(65 <= ans && ans < 80){
	printf("B\n");
	continue;
      }
      
      if(50 <= ans && ans < 65){
	printf("C\n");
	continue;
      }
      
      if(30 <= ans && ans < 50){
	if(50 <= r) printf("C\n");
	
	else printf("D\n");
	continue;
      }

    }

  }
  
  return 0;

}

Measured memory_bytes: 584
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        ABC_108_C solver = new ABC_108_C();
        solver.solve(1, in, out);
        out.close();
    }

    static class ABC_108_C {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            int k = in.nextInt();
            int cnt = 0;
            long ans = 0;
            for (int i = 1; i <= n; i++) {
                if (i % k == 0) {
                    cnt++;
                }
            }

            if (k % 2 == 0) {
                int cnthalf = 0;
                for (int i = 1; i <= n; i++) {
                    if (i % k == (k / 2)) {
                        cnthalf++;
                    }
                }
                ans += (long) Math.pow(cnthalf, 3);
            }
            ans += (long) Math.pow(cnt, 3);

            out.print(ans);
        }

    }
}



Measured memory_bytes: 23124
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <climits>
#include <cstring>
#include <string>
#include <set>
#include <bitset>
#include <map>
#include <queue>
#include <stack>
#include <vector>
#define rep(i,m,n) for(i=m;i<=n;i++)
#define mod 1000000007
#define inf 0x3f3f3f3f
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ll long long
#define pi acos(-1.0)
#define pii pair<int,int>
#define sys system("pause")
const int maxn=1e5+10;
const int N=1e3+10;
using namespace std;
ll gcd(ll p,ll q){return q==0?p:gcd(q,p%q);}
ll qpow(ll p,ll q){ll f=1;while(q){if(q&1)f=f*p;p=p*p;q>>=1;}return f;}
int n,m,k,t;
int main()
{
    int i,j;
    scanf("%d",&n);
    int now=1;
    while((ll)now*(now+1)/2<n)now++;
    printf("%d\n",now);
    return 0;
}


Measured memory_bytes: 256
import sys
from collections import Counter

# sys.stdin = open('c1.in')


def read_int_list():
    return list(map(int, input().split()))


def read_str_list():
    return input().split()


def read_int():
    return int(input())


def read_str():
    return input()


def solve():
    n = read_int()
    a = read_int_list()
    c = Counter()

    for x in a:
        if x % 2 == 1:
            c[0] += 1
        elif x % 4 == 2:
            c[1] += 1
        else:
            c[2] += 1

    if c[0] > c[2] + 1:
        return False
    if c[0] == c[2] + 1:
        return c[1] == 0
        # if c[1] == 0:
        #     return True
        # else:
        #     return False
    if c[0] <= c[2]:
        return True


def main():
    res = solve()
    if res:
        print('Yes')
    else:
        print('No')


main()


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

#define rep(i, a, b) for(int i = (a); i <= (b); ++i)
#define per(i, b, a) for(int i = (b); i >= (a); --i)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
#define boost ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)

#define M (ll)(1e9+7)
#define inf (ll)(2e9+9)
#define infl (ll)(2e18+9)
#define debug1(a) cout<<#a<<" = " <<a<<endl; 
#define debug2(a,b) cout<<#a<<" = " <<a<<" , "<<#b<<" = "<<b<<endl; 
#define debug3(a,b,c) cout<<#a<<" = " <<a<<" , "<<#b<<" = "<<b<<" , "<<#c<<" = "<<c<<endl; 
#define debug4(a,b,c,d) cout<<#a<<" = " <<a<<" , "<<#b<<" = "<<b<<" , "<<#c<<" = "<<c<<" , "<<#d<<" = " <<d<<endl; 
  
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<char> vc; 
typedef vector<ll> vll; 
typedef vector< pair<int,int> > vpii;

/* -------------------------------------------------------------------------*/
/* -------------------------------------------------------------------------*/



void solve(){
  string s,t; cin>>s>>t; 
  int n=sz(s),m=sz(t); 
  vector<vector<int>> dp(n,vector<int>(m)); 
  rep(i,0,n-1){
    rep(j,0,m-1){
      if(i==0 && j==0){
        dp[i][j]=(s[i]==t[j]); 
      } 
      else if(i==0){
        dp[i][j]=(s[i]==t[j])|dp[i][j-1]; 
      }
      else if(j==0){
        dp[i][j]=(s[i]==t[j])|dp[i-1][j];  
      }
      else{
        if(s[i]==t[j]) dp[i][j]=1+dp[i-1][j-1];   
        else dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
      }
    }
  }
  vector<char> ans; 
  int i=n-1,j=m-1; 
  while(i>0 && j>0){
    if(dp[i][j]==dp[i-1][j]) i--; 
    else if(dp[i][j]==dp[i][j-1]) j--; 
    else{
      ans.push_back(s[i]);  
      i--; j--; 
    } 
  }
  if(dp[i][j]==1) {
    while(s[i]!=t[j]){
      if(i>0) i--; 
      else j--;  
    }
    ans.push_back(s[i]); 
  }
  reverse(all(ans)); 
  for(char c:ans) cout<<c; 
}

int main() {
  clock_t beg=clock(); 
  boost;
  int t=1; 
  // cin>>t; 
  while(t--){
    solve(); 
  }
  clock_t end=clock(); 
  fprintf(stderr, "%lf\n", (double)(end-beg)/CLOCKS_PER_SEC);
}


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

int main() {
  int n, a, min;
  std::cin >> n;
  min = 100;
  for (int i = 0; i < n; i++) {
    int count = 0;
    std::cin >> a;
    while (a % 2 == 0) {
      a = a / 2;
      count++;
    }
    if (count < min) {
      min = count;
    }
  }
  std::cout << min << std::endl;
}


Measured memory_bytes: 256
A = int(input())
B = int(input())
C = int(input())
X = int(input())

X //= 50
ans = 0
for a in range(A+1):
    for b in range(B+1):
        if 0 <= X - 10*a - 2*b <= C:
            ans += 1
print(ans)

Measured memory_bytes: 3060
l, r = (int(_) for _ in input().split())

if r-l>=2019:
    kotae=0
else:
    a=l%2019
    b=r%2019
    if a>b:
        kotae=0
    else:
        kotae=2019
        for i in range(b-a):
            sho=a+i
            for j in range(b-a-i):
                dai=a+j+i+1
                #print(sho,dai)
                koho=(sho*dai)%2019
                if koho<kotae:
                    kotae=koho

print(kotae)

Measured memory_bytes: 3064
S = input()
start_flag = False
z_count = S.count("Z")
start = 200001
end = 200001
for i in range(len(S)):
    if S[i] == "A" and start_flag == False:
        start_flag = True
        start = i
    elif S[i] == "Z":
        if z_count == 1 and start_flag == True:
            end = i
            break
        else:
            z_count -= 1
print(end-start+1)

Measured memory_bytes: 3516
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

#include "bits/stdc++.h"

#define REP(i,x,y) for(int i=(x);i<(y);i++)
#define RREP(i,x,y) for(int i=(y)-1;i>=(x);i--)
#define all(x) (x).begin(),(x).end()
//#define int long long

using namespace std;

// conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

#define dump(x)  cerr << #x << " = " << (x) << endl
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl

typedef long long ll;

const ll MOD = 1e9 + 7;

class BStringsWithTheSameLength {
public:
	void solve(std::istream& in, std::ostream& out) {
	    int N;
	    string S, T;
	    in >> N >> S >> T;
	    stringstream ss;
	    REP(i,0,N) {
	        ss << S[i] << T[i];
	    }
	    out << ss.str() << "\n";
	}
};


signed main() {
	BStringsWithTheSameLength solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std; 
int main(){
string s;
cin>>s;
int n  = (int)s.size();
vector<int> a(n+1);
for(int i=0;i<n;i++){
if(s[i]=='<'){
a[i+1] = max(a[i+1],a[i]+1);
}
}
for(int i=n-1;i>=0;--i){
if(s[i]=='>'){
a[i] = max(a[i],a[i+1]+1);
}
}
long long ans=0;
for(int i=0;i<=n;i++){
ans+=a[i];
}
cout<<ans<<endl;


}

Measured memory_bytes: 2820
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  ll n,W;
  cin >> n >> W;
  vector<ll> w(n),v(n);
  vector<vector<int>> c(4);
  for(int i=0;i<n;i++){
    cin >> w[i] >> v[i];
    c[w[i]-w[0]].push_back(v[i]);
  }
  for(int i=0;i<4;i++){
    sort(c[i].begin(),c[i].end(),greater<int>());
  }
  int ans=0;
  int I=0;
  for(ll i=0;i<=c[0].size();i++){
    if(i!=0){
      I+=c[0][i-1];
    }
    int J=0;
    for(ll j=0;j<=c[1].size();j++){
      if(j!=0){
        J+=c[1][j-1];
      }
      int K=0;
      for(ll k=0;k<=c[2].size();k++){
        if(k!=0){
          K+=c[2][k-1];
        }
        int L=0;
        for(ll l=0;l<=c[3].size();l++){
          if(l!=0){
            L+=c[3][l-1];
          }
          if(w[0]*i+(w[0]+1)*j+(w[0]+2)*k+(w[0]+3)*l<=W){
            ans=max(ans,I+J+K+L);
          }
        }
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>
#include <limits>
#define ALL(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define int_INF 2147483647
#define pint_INF 2000000000
#define ll_INF 	9223372036854775807
#define MOD 1000000007
#define vi vector<int>
#define vvi vector<vector<int>>
#define vvll vector<vector<long long>>
#define vvc vector<vector<char>>
#define vll vector<long long>
#define pii pair<int,int>
#define vpii vector<pair<int,int>>
#define sysp system("PAUSE")
#define pno cout << "no" << endl
#define pyes cout << "yes" << endl
#define pYes cout << "Yes" << endl
#define pNo cout << "No" << endl
#define pNO cout << "NO" << endl
#define pYES cout << "YES" << endl
#define endl "\n"
#define pi 3.14159265358979
using namespace std;
using ll = long long;

class MyCombination{
private:
	vector<long long> fac, ifac;
public:
	ll mpow(ll x, ll n) { //x^n(mod M) ←普通にpow(x,n)では溢れてしまうため，随時mod計算
		ll ans = 1;
		while (n != 0) {
			if (n & 1) ans = ans * x % MOD;
			x = x * x % MOD;
			n = n >> 1;
		}
		return ans;
	}

	ll comb(ll a, ll b) { //aCbをmod計算
		if (a == 0 && b == 0)return 1;
		if (a < b || a < 0)return 0;

		ll tmp = ifac[a - b] * ifac[b] % MOD;

		return tmp * fac[a] % MOD;
	}

	MyCombination(long long SIZE = 200001) {
		fac.resize(SIZE);
		ifac.resize(SIZE);
		fac[0] = 1;
		ifac[0] = 1;
		for (ll i = 0; i < SIZE - 1; i++) {
			fac[i + 1] = fac[i] * (i + 1) % MOD; // n!(mod M)
			ifac[i + 1] = ifac[i] * mpow(i + 1, MOD - 2) % MOD; // k!^{M-2} (mod M) ←累乗にmpowを採用
		}
	}
};

int main(){
    ll N,K; cin >> N >> K;
    MyCombination myc;
    for(int i = 1; i <= K; i++){
        ll ans = myc.comb(K-1,i-1);
        ll G = N-K-i+1;
        if(G < 0){
            ans *= 0;
        }else{
            ans *= myc.comb(G+i,i);
        }
        cout << ans%MOD << endl;
    }
    sysp;
}

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

 int main(){

 int x,y;
 while(1){
 cin>>x>>y;
  if(x==0 && y==0) break;
  if(x>y) swap(x,y);
  cout<<x<<" "<<y<<endl;

  }
  return 0;
  }



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

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()

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

    vector<int> ck(26, 0);
    rep(i, s.size())
    {
        ck[s[i] - 'a']++;
    }
    bool flag = true;
    rep(i, 26)
    {
        if(ck[i]>1){
            flag = false;
        }
    }

    cout << (flag ? "yes" : "no") << '\n';
    return 0;
}


Measured memory_bytes: 3588
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int64_t> A(N);
  
//  bool thereIsZero = false;
  
  for(int i =0; i<N; i++){
    cin >> A.at(i);
    if(A.at(i) == 0){
      cout << 0 << endl;
      return 0;
    }
  }
  
  double b =0;
  int64_t ans = 1LL;
  
  for(int i =0; i<N; i++){
    b += log10(A.at(i));
  }
  if( b > 18.){
   ans = -1 ;
  }
  else{
    for(int i =0; i<N; i++){
      ans *= A.at(i);
    }
  }
  if (ans > 1000000000000000000){
    ans = -1;
  }
  
  cout << ans << endl;
 
  return 0;
}

Measured memory_bytes: 4004
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
#define all(x) (x).begin(), (x).end()
#define endl '\n'
ll inf = LLONG_MAX;
long double pi = M_PI;
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}

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

  vll aa(a), bb(b), x(m), y(m), c(m);
  for (ll i = 0; i < a; i++) cin >> aa[i];
  for (ll i = 0; i < b; i++) cin >> bb[i];
  for (ll i = 0; i < m; i++) cin >> x[i] >> y[i] >> c[i];

  vll sa = aa, sb = bb;
  sort(all(sa));
  sort(all(sb));

  priority_queue<ll, vll, greater<ll>> ans;
  ans.push(sa[0] + sb[0]);
  for (ll i = 0; i < m; i++) {
    ans.push(aa[x[i] - 1] + bb[y[i] - 1] - c[i]);
  }
  cout << ans.top() << endl;
}

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

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

void insert(int);
void print(void);
Node treeMaximum(Node);
Node treeMinimum(Node);
Node treeSearch(Node, int);
Node treeSuccessor(Node);
void delete(Node);
void inorder(Node);
void preorder(Node);
Node find(Node, int);

int main()
{
  int m,i,x;
  char com[10];
  Node t;

  scanf("%d",&m);
  
  for(i = 0; i < m; i++){
    scanf("%s",com);
    if(com[0] == 'p'){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
    else if(com[0] == 'd'){
      scanf("%d",&x);
      delete(treeSearch(root, x));
    }
    else if(com[0] == 'i'){
      scanf("%d",&x);
      insert(x);
    }
    else if(com[0] == 'f'){
      scanf("%d",&x);
      t = treeSearch(root, x);
      if(t != NIL)printf("yes\n");
      else printf("no\n");
    }
  }

  return 0;
}

void insert(int k)
{
  Node y;
  Node x;
  Node z;
  
  y = NIL; //xの親
  x = root;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x != NIL){
    y = x;
    if(z->key < x->key)
      x = x->left;
    else
      x = x->right;
  }
  z->parent = y;

  if(y == NIL)
    root = z;
  else if(z->key < y->key)
    y->left = z;
  else
    y->right = z;
}

Node treeMaximum(Node x)
{
  while(x->left != NIL){
    x = x->right;
  }
  return x;
}

Node treeMinimum(Node x)
{
  while(x->left != NIL){
    x = x->left;
  }
  return x;
}

Node treeSearch(Node x, int k)
{
  while(x != NIL && k != x->key){
    if(k < x->key)x = x->left;
    else x = x->right;
  }
  
    return x;
}

Node treeSuccessor(Node x)
{
  Node y;
  
  if(x->right != NIL)return treeMinimum(x->right);

  y = x->parent;
  while(y != NIL && x == y->right){
    x = y;
    y = y->parent;
  }

  return y;
}

void delete(Node z)
{
  Node y; //消去候補
  Node x; //yの子

  if(z->left == NIL || z->right == NIL)
    y = z;
  else
    y = treeSuccessor(z);

  if(y->left != NIL)
    x = y->left;
  else
    x = y->right;

  if(x != NIL)x->parent = y->parent;
  
  if(y->parent == NIL)root = x;
  else if(y == y->parent->left)y->parent->left = x;
  else y->parent->right = x;

  if(y != z)z->key = y->key;
}

void inorder(Node x)
{
  if(x != NIL){
    inorder(x->left);
    printf(" %d",x->key);
    inorder(x->right);
  }
}

void preorder(Node x)
{
  if(x == NIL)return;
  printf(" %d",x->key);
  preorder(x->left);
  preorder(x->right);
}

Node find(Node x, int k)
{
  while(x != NIL && k != x->key){
    if(k < x->key)x = x->left;
    else x = x->right;
  }

    return x;
}



Measured memory_bytes: 20484
#include <bits/stdc++.h>
	
using namespace std;
    
#define endl "\n"
#define ll unsigned long long
//#define int long long int
#define vi vector <int >
#define vvi vector < vector < int >  >
#define vii vector < pii >
#define vll vector <ll >
#define pii pair <int, int>
#define pdd pair< double, double>
#define piii pair < pii, int > 
#define pll pair<ll, ll >
#define umap unordered_map
#define pb push_back
#define pq priority_queue
#define forn(i, n) for(int i = 0; i < (int)n; i++)
#define rep(i,b,c) for(int i = (int)b; i < (int)c; i++)
//#define double long double
#define a first
#define b second


int main(){
    ios::sync_with_stdio(0),cin.tie(0);
    
    string s;
    cin >> s;
    forn(i, s.length())
        cout << "x";
    cout << endl;
    
    
    return 0;
}

Measured memory_bytes: 256
#pragma comment(linker, "/stack:640000000")

#include<bits/stdc++.h>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<stdio.h>
using namespace std;
#define ll long long int
#define scanl(a) scanf("%lld",&a)
#define scanii(a,b) scanf("%d%d",&a,&b)
#define scaniii(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define scanll(a,b) scanf("%lld%lld",&a,&b)
#define scanlll(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define scani(a) scanf("%d",&a)
#define clr(a) memset(a,0,sizeof(a))
#define clr_(a) memset(a,-1,sizeof(a))
#define pb(a) push_back(a)
#define pii pair<int,int>
#define sqr(a) a*a
#define eps 1e-9
#define inf INT_MAX
#define pi acos(-1.0)
#define ff first
#define ss second
#define INF (ll)1e18
#define m_p make_pair
#define vsort(v) sort(v.begin(),v.end())
#define all(v) v.begin(),v.end()
#define UNIQUE(X) sort(all(X)) X.resize( unique( all(X)) - X.begin() )
int fx[]={0,0,-1,1,-1,1,1,-1};
int fy[]={1,-1,0,0,1,1,-1,-1};
ll lcm(ll a,ll b){return (a/__gcd(a,b))*b;}
ll bigmod(ll a,ll p,ll mod){ll ans=1;while(p){if(p&1)ans=ans*a%mod;a=a*a%mod;p>>=1;}return ans;}
ll power(ll x,ll n){if(n==0)return 1;else if(n%2==0){ll y=power(x,n/2);return y*y;}else return x*power(x,n-1);}
struct point{double x,y;point(){}point(double xx,double yy){x=xx;y=yy;}};
inline double Distance(point  a,point b){return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));}
#ifdef shaft
     #define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template < typename Arg1 >
    void __f(const char* name, Arg1&& arg1){
        cerr << name << " is " << arg1 << std::endl;
    }
    template < typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names+1, ',');
        cerr.write(names, comma - names) << " is " << arg1 <<endl;
        __f(comma+1, args...);
    }
#else
    #define debug(...)
#endif
const int N=(int)1e6;
const ll mod=(ll)1e9+7;
int k,dis[N];
void bfs01(int u){
    for(int i=0;i<N;i++)dis[i]=inf;
 //   for(int i=0;i<=5;i++)debug(dis[i]);
    deque<int>dq;
    dq.push_front(u);
    dis[u] = 1;
    while(!dq.empty()){
        int v = dq.front();
        dq.pop_front();
        int x = (v*10)%k;
        if(dis[x] > dis[v]){
            dis[x]=dis[v];
            dq.push_front(x);
        }
        x = (v+1)%k;
        if(dis[x] > dis[v]+1){
            dis[x] = dis[v] + 1;
            dq.push_back(x);
        }
    }
}
int main()
{
    //ios_base::sync_with_stdio(0);cin.tie(0);
    #ifdef shaft
        //freopen("in.txt","r",stdin);
        ///freopen("out.txt","w",stdout);
    #endif ///shaft
    scani(k);
    bfs01(1);
    printf("%d\n",dis[0]);
    return 0;
}



Measured memory_bytes: 4352