akhauriyash/Code-Regression huggingface dataset:
#include <cctype>
#include <cfloat>
#include <climits>
#include <cmath>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <ios>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <forward_list>
#include <random>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <unordered_map>
#include <unordered_set>
#endif

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define lcm( a, b ) (a)/__gcd((a),(b))*(b)
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair< int, int > P;
typedef pair< LL, LL > LP;
typedef pair< int, P > iP;
typedef pair< P, P > PP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;
static const int SIZE = 100005;

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

vector< int > Div( int n ) {
    vector< int > ret;
    for( int i = 1; i * i <= n; ++i ) {
        if( n % i == 0 ) {
            ret.pb( i );

            if( i * i != n ) ret.pb( n / i );
        }
    }
    sort( all( ret ) );
    return ret;
}

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

    int k, x;
    cin >> k >> x;
    for( int i = x - k + 1; i < x + k; ++i ) {
        cout << i << " ";
        
    }
    cout << endl;
    return 0;
}



Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner scan=new Scanner(System.in);
		int a=scan.nextInt();
		int b=scan.nextInt();
		if(a>=13) {
			System.out.println(b);
		}
		else if(a<13&&a>=6) {
			System.out.println(b/2);
		}
		else if(a<6) {
			System.out.println(0);
		}
	}
}


Measured memory_bytes: 23764
n, k = list(map(int, input().split()))
a = list( map(int, input().split())) 

MOD = 10**9 + 7

ansR = 0
ansL = 0

for i in range(n):
    for j in range(n):
        if a[i] > a[j]:
            if i > j:
                ansL += 1
            if i < j:
                ansR += 1


ansR %= MOD
ansL %= MOD
Rn = (k+1)*k//2%MOD
Ln = (k-1)*k//2%MOD

ans = int(ansR*Rn)%MOD + int(ansL*Ln)%MOD

print(int(ans%MOD))

Measured memory_bytes: 3188
from heapq import heappush,heappop,heapify
from collections import deque,defaultdict,Counter
import itertools
from functools import *
from itertools import permutations,combinations,groupby
import sys
import bisect
import string
import math
import time
import random
def Golf():
    *a,=map(int,open(0))
def S_():
    return input()
def IS():
    return input().split()
def LS():
    return [i for i in input().split()]
def I():
    return int(input())
def MI():
    return map(int,input().split())
def LI():
    return [int(i) for i in input().split()]
def LI_():
    return [int(i)-1 for i in input().split()]
def NI(n):
    return [int(input()) for i in range(n)]
def NI_(n):
    return [int(input())-1 for i in range(n)]
def StoI():
    return [ord(i)-97 for i in input()]
def ItoS(nn):
    return chr(nn+97)
def LtoS(ls):
    return ''.join([chr(i+97) for i in ls])
def GI(V,E,Directed=False,index=0):
    org_inp=[]
    g=[[] for i in range(n)]
    for i in range(E):
        inp=LI()
        org_inp.append(inp)
        if index==0:
            inp[0]-=1
            inp[1]-=1
        if len(inp)==2:
            a,b=inp
            g[a].append(b)
            if not Directed:
                g[b].append(a)
        elif len(inp)==3:
            a,b,c=inp
            aa=(inp[0],inp[2])
            bb=(inp[1],inp[2])
            g[a].append(bb)
            if not Directed:
                g[b].append(aa)
    return g,org_inp
def GGI(h,w,search=None,replacement_of_found='.',mp_def={'#':1,'.':0}):
#h,w,g,sg=GGI(h,w,search=['S','G'],replacement_of_found='.',mp_def={'#':1,'.':0}) # sample usage
    mp=[1]*(w+2)
    found={}
    for i in range(h):
        s=input()
        for char in search:
            if char in s:
                found[char]=((i+1)*(w+2)+s.index(char)+1)
                mp_def[char]=mp_def[replacement_of_found]
        mp+=[1]+[mp_def[j] for j in s]+[1]
    mp+=[1]*(w+2)
    return h+2,w+2,mp,found
def bit_combination(k,n=2):
    rt=[]
    for tb in range(n**k):
        s=[tb//(n**bt)%n for bt in range(k)]
        rt+=[s]
    return rt
def show(*inp,end='\n'):
    if show_flg:
        print(*inp,end=end)
YN=['YES','NO']

mo=10**9+7
inf=float('inf')
l_alp=string.ascii_lowercase
u_alp=string.ascii_uppercase
ts=time.time()
#sys.setrecursionlimit(10**7)
input=lambda: sys.stdin.readline().rstrip()
 
def ran_input():
    import random
    n=random.randint(4,16)
    rmin,rmax=1,10
    a=[random.randint(rmin,rmax) for _ in range(n)]
    return n,a

show_flg=False
show_flg=True

n,k=LI()
if n%k==0:
    ans=0
else:
    ans=1
print(ans)




Measured memory_bytes: 39276
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define all(v) v.begin(), v.end()
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define Rep(n) for (ll _ = 0; _ < (ll)(n); _++)
#define P pair<ll,ll>
#define fs first
#define sc second

template<class S>S sum(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
ll min(int a,ll b){return min((ll)a,b);} ll min(ll a,int b){return min(a,(ll)b);}
template <class S> void print(vector<S> &v){for(ll i=0; i<(ll)v.size(); i++){cerr << v[i] << ' ';}cerr << endl;}
template <class S> void print(vector<vector<S>> &v) {for (ll i = 0; i < (ll)v.size(); i++) {for (ll j = 0; j < (ll)v[i].size(); j++) {cerr << v[i][j] << ' ';}cerr << endl;}}

int main(){
	int n; cin >> n;
	string s; cin >> s;
	int ans = 0;
	for(int i=1; i<n; i++){
		if(s[i] == 'E') ans++;
	}
	int tmp = ans;
	for(int i=1; i<n; i++){
		tmp = tmp + (s[i-1] == 'W') - (s[i] == 'E');
		ans = min(ans, tmp);
		//cerr << ans << i << endl;
	}
	cout << ans << endl;
}


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

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

Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
int main() {
    int ans = 0;
    
    int N, H;
    cin >> N >> H;
    vector<int> a(N), b(N);
    for(int i = 0; i < N; i++) cin >> a.at(i) >> b.at(i);
    sort(a.begin(), a.end());
    reverse(a.begin(), a.end());
    sort(b.begin(), b.end());
    reverse(b.begin(), b.end());
    
    int i = 0;
    while(i<N && H>0 && b.at(i)>a.at(0)) {
        H -= b.at(i);
        i++;
        ans++;
    }
    cout << ans + max(0, (H + a.at(0) - 1)/a.at(0)) << endl;
}


Measured memory_bytes: 1024
#include <iostream>
using namespace std;
int main(void){
    int a[100]={0};
    int n;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    cout<<a[n-1];
    for(int i=1;i<n;i++){
        int j=n-i-1;
        cout<<" "<<a[j];
    }   
    cout<<endl;
}



Measured memory_bytes: 3092
n,m = map(int,input().split())
s=[]
c=[]
for i in range(m):
    si,ci = map(int,input().split())
    s.append(si)
    c.append(ci)


keta = 0
start = 0
if n == 1:
    keta = 10
    start = 0
elif n == 2:
    keta = 100
    start = 10
elif n == 3:
    keta = 1000
    start = 100
    
def chk_num(num):
    num = str(num)
    flg = 0
    for i,v in enumerate(s):
        if num[v-1] != str(c[i]):
            flg = 1
            break
    return flg
    

for i in range(start,keta):
    if chk_num(i) == 0:
        print(i)
        exit()

print(-1)

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

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;A++)
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

/////////////////////////////////////////////////////

ll N,A[1010][1010],NN;
vector<pll> g[1010][1010];
ll mk[1010][1010];
ll mk2[1010];
ll i, j, k, ans;
int main(){
    scanf("%lld",&N);
    NN = (N - 1) * N;
    fornum(i,0,N){
        fornum(j,1,N){
            scanf("%lld", &A[i+1][j-1]);
        }
    }
    fornum(i,0,N){
        fornum(j,1,N){
            ll a = A[i + 1][N - j];
            ll b = i + 1;
            if(a>b)
                swap(a, b);
            g[i + 1][A[i + 1][N - j - 1]].push_back({a, b});
            g[A[i + 1][N - j - 1]][i+1].push_back({a, b});
            mk[a][b]++;
        }
    }
    /*
    fornum(i,0,N){
        fornum(j,0,N){
            printf("%lld ", mk[i + 1][j + 1]);
        }
        printf("\n");
    }*/
    queue<pll> q;
    fornum(i,0,N){
        fornum(j,i+1,N){
            if(mk[i+1][j+1]==0){
                q.push({i + 1, j + 1});
            }
        }
    }
    ll nm =(N-1)*N/2;
    while(q.size()){
        auto qa=q.front();
        q.pop();
        ll a = qa.first;
        ll b = qa.second;
        //printf("%lld %lld\n", a, b);
        if(a==0||b==0)
            continue;
        nm--;
        ll c = max(mk2[a], mk2[b]) + 1;
        if(ans<c)
            ans = c;
        mk2[a] = c;
        mk2[b] = c;
        
        fornum(i,0,g[a][b].size()){
            pll nx = g[a][b][i];
            if(--mk[nx.first][nx.second]==0){
                q.push({nx.first, nx.second});
            }
        }
    }
    if(nm==0){
        printf("%lld",ans);
    }else{
        printf("-1");
    }
    return 0;
}

Measured memory_bytes: 89728
import java.util.Scanner;

class Main{
	static int G;
	static int D;
	static int[] p;
	static int[] c;
	static boolean[] used;
	static long ans = 1000000000;


	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);			//文字の入力
		String ss = sc.next();
		long[][] dp = new long[ss.length()+1][3];
		dp[0][0] = 0l;
		long mod = 1000000007;
		long moziretusum = 1l;
		
		for(int i = 0;i < ss.length();i++){
			if(ss.charAt(i) == 'A' ){
				dp[i+1][0] = dp[i][0] % mod;			//Aが入っている
				dp[i+1][1] = dp[i][1] % mod;			//Aが入っている
				dp[i+1][2] = dp[i][2] % mod;			//Aが入っている
				dp[i+1][0] += moziretusum % mod;

			}else if(ss.charAt(i) == 'B'){
				dp[i+1][0] = dp[i][0] % mod;			//Aが入っている
				dp[i+1][1] = dp[i][1] % mod;			//Aが入っている
				dp[i+1][2] = dp[i][2] % mod;			//Aが入っている
				dp[i+1][1] += dp[i][0] % mod;
			}else if(ss.charAt(i) == 'C'){
				dp[i+1][0] = dp[i][0] % mod;			//Aが入っている
				dp[i+1][1] = dp[i][1] % mod;			//Aが入っている
				dp[i+1][2] = dp[i][2] % mod;			//Aが入っている
				dp[i+1][2] += dp[i][1] % mod;
			}
			if( ss.charAt(i) == '?'){
				dp[i+1][0] =3*dp[i][0] % mod;			//Aが入っている
				dp[i+1][1] =3*dp[i][1] % mod;			//Aが入っている
				dp[i+1][2] =3*dp[i][2] % mod;			//Aが入っている

				
				dp[i+1][0] += moziretusum % mod;			
				dp[i+1][1]  += dp[i][0] % mod;
				dp[i+1][2] += dp[i][1] % mod;

				moziretusum *= 3l;
				moziretusum %= mod;


			}
			//System.out.println(dp[i+1][0] + " "+dp[i+1][1] + " "+dp[i+1][2]  );
		}

		System.out.println(dp[ss.length()][2] % mod);


	}


}

class Pair implements Comparable{
	int from;		//p
	int end;		//y
	int num;
	int bango;
	@Override
	public int compareTo(Object other) {
		Pair otherpair = (Pair)other;

		return from - otherpair.from;
	}
}



Measured memory_bytes: 30164
#include<deque>
#include<cstdio>

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

int main(){
	int n; scanf("%d",&n);
	int a[100000];
	rep(x,n) scanf("%d",a+x);

	int dp[100000];
	rep(x,n) dp[x]=-1;

	deque< pair<int,int> > Q;
	Q.push_back(make_pair(0,0));
	while(!Q.empty()){
		int d=Q.front().first;
		int x=Q.front().second; Q.pop_front();

		if(dp[x]!=-1) continue;
		dp[x]=d;

		if(a[x]==0){
			for(int i=1;i<=6&&x+i<n;i++){
				Q.push_back(make_pair(d+1,x+i));
			}
		}
		else{
			Q.push_front(make_pair(d,x+a[x]));
		}
	}

	printf("%d\n",dp[n-1]);

	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <cmath>
// #include <string>
// #include <vector>
// #include <algorithm> // to use min_element

using namespace std;


int main(){
	int i=0, n;
	cin >>n;
	while (pow(2,  i)<=n){
		i++;
	}
	cout << pow(2, i-1);
return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <functional>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <cmath>
#include <cstdio>

using namespace std;

typedef long long ll;

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

int main(int argc, char **argv)
{
    int N;
    cin >> N;
    int p[N];
    REP(i, N) cin >> p[i];

    ll count = 0;

    REP(i, N - 1) {
        if (p[i] == i + 1) {
            count++;
            int t = p[i];
            p[i] = p[i + 1];
            p[i + 1] = t;
        }
    }
    if (p[N - 1] == N) {
        count++;
        int t = p[N - 2];
        p[N - 2] = p[N - 1];
        p[N - 1] = t;
    }

    cout << count << endl;
    return 0;
}


Measured memory_bytes: 640
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;
using static System.Array;

class Program
{
    public static void Main()
    {
        var n = long.Parse(ReadLine());
        long count = 0;
        count += (n / 11) * 2;
        n %= 11;
        count += n / 6;
        n %= 6;
        if(n != 0)
            count++;

        WriteLine(count);
        ReadLine();
    }
}


Measured memory_bytes: 17604
class Town:
  def __init__(self,x,y):
    self.x = x
    self.y = y

from itertools import permutations

N = int(input())
towns = []
for n in range(N):
  d = input().split()
  x, y = map(int, d)
  towns.append(Town(x,y))

roots = list(permutations(towns))

distances = 0
for root in roots:
  distance = 0
  for i in range(len(root) - 1 ):
    start = root[i]
    end = root[i + 1]
    distance += ((start.x - end.x) ** 2 + (start.y - end.y) ** 2) ** (1 / 2)
  distances += distance

average = distances / len(roots)
print(average)

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

main(){
	int n;
	while(cin >> n && n){
	
		int f[n][n];
		bool chk[2][n][n];
		memset(chk, false, sizeof(chk));
		
		for(int i=0;i<n;i++){
			for(int j=0;j<n;j++){
				cin >> f[i][j];
			}
		}
		
		//horizontal
		for(int i=0;i<n;i++){
			int tmp = 1 << 28;
			for(int j=0;j<n;j++){
				tmp = min(tmp, f[i][j]);
			}
			for(int j=0;j<n;j++){
				if(f[i][j] == tmp){
					chk[0][i][j] = true;
				}
			}
		}
		
		//vertical
		for(int i=0;i<n;i++){
			int tmp = -1;
			for(int j=0;j<n;j++){
				tmp = max(tmp, f[j][i]);
			}
			for(int j=0;j<n;j++){
				if(f[j][i] == tmp){
					chk[1][j][i] = true;
				}
			}
		}
		
		bool isok=false;
		
		for(int i=0;i<n&&!isok;i++)
		for(int j=0;j<n&&!isok;j++){
			if(chk[0][i][j] && chk[1][i][j]){
				cout << f[i][j] << endl;
				isok = true;
			}
		}
		if(!isok) cout << 0 << endl;
	}
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
#define con continue
#define pb push_back
#define fi first
#define se second
#define fr front()
#define one 1.0
#define inf 1000000000000000000
#define ret return
#define all(vl) vl.begin(),vl.end()
#define sor sort 
#define cl clear()
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef map<ll,ll>::iterator itll;
typedef long double ld;
typedef map<ll,ll> mapll;
typedef double dou;
#define int ll
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);
}
ll getlcm(vector<ll> vl)
{
	ll ch = 1;
	if(vl.size() == 1)
	{
		return vl[0];
	}
	if(vl.size() == 2)
	{
		return lcm(vl[0],vl[1]);
	}
	ch = lcm(vl[0],vl[1]);
	for(int i=2;i<vl.size();i++)
	{
		ch = lcm(ch,vl[i]);
	}
	return ch;
}
signed main()
{
	ll n,m;
	cin>>n>>m;
	vector<ll> vl(n);
	for(int i=0;i<n;i++)
	{
		cin>>vl[i];
		vl[i]/=2;
	} 
	ll ch = getlcm(vl); 
	ll pl = ch*2;
	ll he = ch;
	for(int i=0;i<n;i++)
	{
		if((ch/vl[i])%2 == 0)
		{
			cout<<"0\n";ret 0;
		}
	}
	ll cnt = 1;
	if(m<ch)
	{
		cout<<"0\n";ret 0;
	}
	cnt+=((m-ch)/pl);
	cout<<cnt<<endl;
	return 0;
}

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

// #undef DEBUG  // Uncomment this line to forcefully disable debug print.
#if DEBUG
template <typename T>
void debug(T value) {
  std::cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  std::cerr << value << ", ";
  debug(args...);
}
#define dbg(...)                              \
  do {                                        \
    cerr << #__VA_ARGS__ << ": ";             \
    debug(__VA_ARGS__);                       \
    cerr << " (L" << __LINE__ << ")" << endl; \
  } while (0)
#else
#define dbg(...)
#endif

void read_from_cin() {}
template <typename T, typename... Ts>
void read_from_cin(T& value, Ts&... args) {
  std::cin >> value;
  read_from_cin(args...);
}
#define in(type, ...) \
  type __VA_ARGS__;   \
  read_from_cin(__VA_ARGS__);

template <typename T>
void write_to_cout(const T& value) {
  std::cout << value << std::endl;
}
template <typename T, typename... Ts>
void write_to_cout(const T& value, const Ts&... args) {
  std::cout << value << ' ';
  write_to_cout(args...);
}
#define out(...) write_to_cout(__VA_ARGS__);

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

using ll = long long;

using namespace std;

int main() {
  in(string, s);
  vector<int> v(2);
  rep(i, s.size())++ v[s[i] - '0'];
  out(min(v[0], v[1]) * 2);
}


Measured memory_bytes: 3724
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        s: chars
    }
    let mut s = s;
    s.sort();
    let s = s.into_iter().collect::<String>();
    println!("{}", if "abc" == s {"Yes"} else {"No"});
}


Measured memory_bytes: 4352
package main
import (
  "fmt"
)

func abs(a int) int {
  if 0 < a {
    return a
  }
  return -a
}
func main() {
  var n int
  fmt.Scan(&n)
  as := make([]int, n)
  for i := 0; i < n; i++ {
    fmt.Scan(&as[i])
  }
  absMin := 1000000000
  minusCnt := 0
  total := 0
  for _, a := range as {
    absA := abs(a)
    total += absA
    if absA < absMin {
      absMin = absA
    }
    if a < 0 {
      minusCnt++
    }
  }
  var result int
  if minusCnt%2 == 0 {
    result = total
  } else {
    result = total - absMin*2
  }
  fmt.Println(result)
}

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

using namespace std;

int main()
{string N ;

    cin >> N ;

        if (N[0] ==N[1] and N[1]==N[2]) cout << "Yes";

   else if (N[1] ==N[2] and N[2]==N[3]) cout << "Yes";
   
   else cout << "No";


    return 0;
}
// king of the falafel

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#include <math.h>
#include <cmath>

using namespace std;
using ll =long long;
using vi = vector<int>; 
using vvi = vector<vi>; 
using vl = vector<ll>; 
using vvl = vector<vl>; 
using vs = vector<string>;
using vvs = vector<vs>; 
using vc = vector<char>;
using vvc = vector<vc>; 
using vb = vector<bool>;
using vvb = vector<vb>; 

#define rep(i,n) ;for( int i =0; i < n ; i ++)
#define all(a) a.begin(),a.end()
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define f(i,a,b) for(int i=a;i<b;i++)
#define pri(a)  printf("%.14lf\n",a);
#define sz(a) ((int)a.size())
#define MOD 1000000007
bool is_int_lround(double x){
  return std::lround(x)==x;
}

ll keta(ll x){
  ll n=0;
  while(x>0){
    x /=10 ;
    n ++;
  }
  return n;
}

ll conbi(int n,int m){
  
  cin>>n>>m;
  vector<ll> a(100);
  a[0] =1;
  for(int i=0;i<14;i++){
    a[i+1]=a[i]*(i+1);
  }
  return a[n] /(a[m] *a[n-m]);
}

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;//繰り返し二乗法
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
ll kaijoMOD(ll x){
  ll z=1;
  if(x==0){
    return 1;
  }
  while(x>0){
    z *=x;
    z %=MOD;
    x--;
  }
  return z;
}
ll div_num(ll n){
  vl div(n+1,1);
  for(ll i=2;i*i<=n;i++){ 
    while(n%i==0){
      n /=i;
      div[i]++;
    }
  }
  if(n!=1)div[n]++;
  ll num=1;
  for(ll i=0;i<=n;i++){
    num*=div[i];
  }
  return num;
}
vector<ll> divisor(ll n) {
  vector<ll> ret;
  for(ll i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}

int keta_wa(int x){
  int tot=0;
  while(x>0){
    tot +=x%10;
    x/=10;
  }
  return tot;
}
long long lopow(ll a, long long n) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a ;
        a = a * a ;
        n >>= 1;
    }
    return res;
}

        
//vc alp ={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
//vc Alp ={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
//cout<<""<<endl;
void dfs(int d, ll v, vl &A ){
  if(d>10)return;
  ll add=v%10;
  A.pb(v);
  for(ll i=-1; i<=1;i++){
    
    if(add+i>=0&&add+i<=9){
      dfs(d+1,v*10+add+i, A);
    }
  }

}
int main(){
  ll K;cin>>K;
  vl ans;
  for(ll i=1;i<=9;i++){
    dfs(1,i,ans);
  }
  sort(all(ans));
  cout<<ans[K-1]<<endl;
}

Measured memory_bytes: 5436
#include<iostream>
#include<queue>
#include<map>
using namespace std;

#define abs(x) (x>0 ? x : -(x))

typedef pair<int, int> P;
typedef pair<int, P> IP;

#define N 10
#define W 12

int main() {
  int x0, y0;
  int X[W] = {-2,-2,-2,-1, 0, 1, 2, 2, 2, 1, 0,-1};
  int Y[W] = { 1, 0,-1,-2,-2,-2,-1, 0, 1, 2, 2, 2};
  while(cin >> x0 >> y0 && x0+y0) {
    queue<IP> que;
    int n, x, y;
    cin >> n;
    que.push(IP(0, P(x0, y0)));
    for(int i=0; i<n; ++i) {
      cin >> x >> y;
      while(!que.empty() && que.front().first == i) {
        int xa = que.front().second.first, ya = que.front().second.second; que.pop();
        for(int j=0; j<W; ++j) {
          int nx = xa + X[j], ny = ya + Y[j];
          if(nx < 0 || 9 < nx || ny < 0 || 9 < ny) continue;
          if(abs(nx - x)<=1 && abs(ny - y)<=1) {
            que.push(IP(i+1, P(nx, ny)));
          }
        }
      }
    }
    cout << (que.empty() ? "NA" : "OK") << endl;
  }
  return 0;
}

Measured memory_bytes: 1212
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pint = pair<int,  int>;
using pll = pair<ll, ll>;
using edge = pair<int, ll>;
using Graph = vector<vector<int>>; 
using WeightedGraph = vector<vector<edge>>;
const ll INF = 1LL << 60;
const int INF32 = 1 << 29;
const ll MOD = 1000000007;
 
ll dp[51][51][2510] {};

int main(){
  int n,t;cin >> n >> t;
  vector<int> a(n);
  int A = 0;
  for(int i = 0; i < n; ++i){
    cin >> a[i];
    A=max(A,a[i]);
  }
  int M = n * A;
  
  dp[0][0][0]= 1;
  for(int i = 0; i < n; ++i){
    for(int j = 0; j <= i; ++j){
      for(int k = 0; k <= M; ++k){
        dp[i+1][j+1][k+a[i]] += dp[i][j][k];
        dp[i+1][j][k] += dp[i][j][k];
      }
    }
  }
  ll ans = 0;
  for(int i = 1; i <=  n; ++i){
    ans += dp[n][i][i*t];
  }
  cout << ans << endl;
}


Measured memory_bytes: 49280
#include<algorithm>
#include<iostream>
#define N 100100
using namespace std;
typedef pair<string,int> P;
P queue[N];
int n,q,b,h,t,cnt;
string a;

void push(P x){
  if(t+1==N)queue[t]=x,t=0;
  else queue[t++]=x;
}

void pop(){h+1==N?h=0:h++;}

bool empty(){return h==t;}

P front(){
  return queue[h];
}

int main(){
  cnt=h=0,t=0;
  cin>>n>>q;
  for(int i=0;i<n;i++)cin>>a>>b,push(P(a,b));
  while(!empty()){
    P t=front(); pop();
    int tim=min(q,t.second);
    t.second-=tim;
    cnt+=tim;
    if(!t.second)cout<<t.first<<' '<<cnt<<endl;
    else push(t);
  }
  return 0;
}

Measured memory_bytes: 5116
import sys
input = sys.stdin.readline

n = int(input())
adj = [[] for _ in range(n)]  # adjacence(隣接)の略

for (a,b,c) in (map(int, input().split()) for _ in range(n-1)):
    adj[a-1].append((b-1, c))
    adj[b-1].append((a-1, c))

q, k = map(int, input().split())
k -= 1
dist = [-1]*n  # 経由地から各頂点までのコスト
dist[k] = 0  # 経由地kをスタート地点とするため、コスト0に設定

stack = [k]  # 探索候補。経由地kをスタート地点にするため、先に積んでおく

while stack: # 探索候補がなくなるまで続ける
    now = stack.pop()
    for dest, cost in adj[now]:
        if dist[dest] != -1: # dest(目的地)までのコストがすでに設定されていればスルー
            continue
        dist[dest] = dist[now] + cost # コストを現地点までのコストと合算して算出
        stack.append(dest)

for _ in range(q):
    x, y = map(int, input().split())
    print(dist[x-1] + dist[y-1])

Measured memory_bytes: 43440
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int,int> pint;
typedef vector<pint> vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
const int MOD = 1e9 + 7;
const int INF = 1e9;

ll func(ll t, ll x){
	if(t < 0) return 0ll;
	else return t / x + 1;
}
int main(void){
	ll a, b; cin >> a >> b;
	ll x; cin >> x;
	ll ans = func(b, x) - func(a - 1, x);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <map>
#include <algorithm>
#include <numeric>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

using namespace std;

int main(void){
  int n;
  cin >> n;
  int h[n];
  rep(i,n) {
    cin >> h[i];
  }
  int ans=0;
  while(*max_element(h, h+n) >0) {
    int i = 0;
    while(i < n && h[i] == 0)i++;
    if (i == n) {
      ans += h[i-1];
      cout << ans;
      return 0;
    }
    int j = i;
    while(j < n && h[j] > 0)j++;
    j--;
    for (int k=i;k<=j;k++) {
      h[k]--;
    }
    ans++;
  }
  cout << ans;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define rep(i,n) for (int i=0;i<(int)(n);i++)
#define codefor int test;scanf("%d",&test);while(test--)
#define yn(ans) if(ans)printf("Yes\n");else printf("No\n")
#define YN(ans) if(ans)printf("YES\n");else printf("NO\n")
#define vector2d(type,name,h,...) vector<vector<type>>name(h,vector<type>(__VA_ARGS__))
#define umap unordered_map
#define uset unordered_set
using namespace std;
using ll = long long;
const int MOD=1000000007;
//入力系
void scan(int& a){scanf("%d",&a);}
void scan(long long& a){scanf("%lld",&a);}
template<class T> void scan(T& a){cin>>a;}
template<class T> void scan(vector<T>& vec){for(auto&& it:vec)scan(it);}
void in(){}
template <class Head, class... Tail> void in(Head& head, Tail&... tail){scan(head);in(tail...);}
//出力系
void print(const int& a){printf("%d",a);}
void print(const long long& a){printf("%lld",a);}
void print(const double& a){printf("%.15lf",a);}
template<class T> void print(const T& a){cout<<a;}
template<class T> void print(const vector<T>& vec){if(vec.empty())return;print(vec[0]);for(auto it=vec.begin();++it!= vec.end();){putchar(' ');print(*it);}}
void out(){putchar('\n');}
template<class T> void out(const T& t){print(t);putchar('\n');}
template <class Head, class... Tail> void out(const Head& head,const Tail&... tail){print(head);putchar(' ');out(tail...);}
//デバッグ系
template<class T> void dprint(const T& a){cerr<<a;}
template<class T> void dprint(const vector<T>& vec){if(vec.empty())return;cerr<<vec[0];for(auto it=vec.begin();++it!= vec.end();){cerr<<" "<<*it;}}
void debug(){cerr<<endl;}
template<class T> void debug(const T& t){dprint(t);cerr<<endl;}
template <class Head, class... Tail> void debug(const Head& head, const Tail&... tail){dprint(head);cerr<<" ";debug(tail...);}

int main(){
    string s,t;
    int a=0,b=0;
    codefor{
        cin>>s>>t;
        if(s>t)a+=3;
        else if(s<t)b+=3;
        else{a++;b++;}
    }
    out(a,b);
}


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

int main(void)
{
	long int i, j;
	long int h, n;
	long int work;
	long int count = 0;
	
	scanf("%ld%ld", &h, &n);
	
	
	for(i = 0; i < n; i++) {
		scanf("%ld", &work);
		count += work;
		if(count >= h) {
			printf("Yes\n");
			return 0;
		}
	}
	
	printf("No\n");
	
	return 0;
}


Measured memory_bytes: 128
N = int(input())

def make_divisors(n):
    from collections import deque
    divisors = deque([])
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    lst_divisors = list(divisors)
    lst_divisors.sort()
    return lst_divisors

ans = 0
for i in range(1,-(-N//2)+1):
    now = 2*i-1
    if len(make_divisors(now)) == 8:
        ans += 1

print(ans)

Measured memory_bytes: 38384
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc =new Scanner(System.in);
    String s =sc.next();
    String S[] =s.split("",0);
    Arrays.sort(S);
    if((S[0].equals(S[1])&&!(S[1].equals(S[2])))&&S[2].equals(S[3])){System.out.println("Yes");}
    else{System.out.println("No");}
  }
}

Measured memory_bytes: 23892
array = input().split(' ')

n = int(array[0])
ll = int(array[1])

sum_n = 0
have_zero = False
for i in range(n):
    sum_n += ll + i
    if sum_n == 0:
        have_zero = True

if have_zero:
    print(sum_n)
else:
    if ll >= 0:
        print(sum_n - ll)
    else:
        print(sum_n - (n + ll - 1))







Measured memory_bytes: 3060
// g++ -std=c++11 temp.cpp
#include <bits/stdc++.h>
using namespace std;

#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) FOR(i,0,n)
#define EACH(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define mp(a,b) make_pair(a,b)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl

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

#define INF INT_MAX/3

#define MAX_N 1000

int n;

ll euler_phi(ll n){
	ll res=n;
	for(ll i=2;i*i<=n;i++){
		if(n%i==0){
			res=res/i*(i-1);
			for(;n%i==0;n/=i);
		}
	}
	if(n!=1) res=res/n*(n-1);
	return res;
}

int main(){
	cin>>n;
	cout<<euler_phi(n)<<endl;
	return 0;
}

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

const long Day_num = 365;
const long type_num = 26;

class Scoring {
public:
    Scoring(const long arg_days, const std::vector<long>& arg_costs, const std::vector<std::vector<long>>& arg_incentives);
    std::vector<long> score(const std::vector<long>& arg_types);
private:
    long days;
    std::vector<long> costs;
    std::vector<std::vector<long>> incentives;
};

std::vector<long> Scoring::score(const std::vector<long>& arg_types) {
    std::vector<long> result(days);
    long satisfy = 0;
    std::vector<long> last_days(type_num, 0);


    for (long day = 1; day <= days; ++day) {
        const auto exe_type = arg_types[day-1];
        satisfy += incentives[day-1][exe_type-1];
        last_days[exe_type-1] = day;
        for (long type = 1; type <= type_num; ++type) {
            satisfy -= costs[type-1] * (day - last_days[type-1]);
        }
        result[day-1] = satisfy;
    }
    return result;
}

Scoring::Scoring(const long arg_days, const std::vector<long>& arg_costs, const std::vector<std::vector<long>>& arg_incentives) {
    days = arg_days;
    costs = arg_costs;
    incentives = arg_incentives;
}

int main() {
    clock_t start_clock = clock();
    std::mt19937 engine(10123123);
    std::uniform_int_distribution<> type_random(1, type_num);
    std::uniform_int_distribution<> day_random(1, Day_num);
    long D;
    std::cin >> D;
    std::vector<long> costs(type_num);
    for (long type = 1; type <= type_num; ++type) {
        std::cin >> costs[type-1];
    }
    std::vector<std::vector<long>> incentives(D, std::vector<long>(type_num));
    for (long day = 1; day <= D; ++day) {
        for (long type = 1; type <= type_num; ++type) {
            std::cin >> incentives[day-1][type-1];
        }
    }

    Scoring scoring(D, costs, incentives);

    std::vector<long> types(D);
    for (long day = 1; day <= D; ++day) {
        types[day-1] = type_random(engine);
    }

    while (static_cast<double>(clock() - start_clock)/CLOCKS_PER_SEC*1000.0 < 2000.0-20.0) {
        const auto old_types = types;
        types[day_random(engine)-1] = type_random(engine);
        if (scoring.score(old_types).back() > scoring.score(types).back()) {
            types = old_types;
        }
    }

    for (long day = 1; day <= D; ++day) {
        std::cout << types[day-1] << std::endl;
    }
    return 0;
}

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

int main(){
  vector<int> A(5);
  int a=10;
  int sum=0;
  for(int i=0;i<5;++i){
    
    cin>>A.at(i);
    if(0<A.at(i)%10 && A.at(i)%10<a){
      a=A.at(i)%10;
    }
    
    sum=sum+10*((A.at(i)+9)/10);
  }

  cout<<sum+(a-10)<<endl;
}

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

using namespace std;

int main()
{
    int n,k;
    cin >> n >> k;
    int cont=0;
    double prob = 0.0;
    for(int i=1;i<=n;i++){
        cont =i;
        int j=0;
        while(cont<k){
            cont*=2;
            j++;
        }
        //cout << "j " <<j << "cont " << cont << endl;
        double p = (1.0 / n) * pow(0.5, j);
        //cout << "p " << p << endl;
        prob += p;
    }
    cout.precision(12);
    cout <<fixed<< prob << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
using ll = long long;
int main(void){
   int A,B,C;
   cin>>A>>B>>C;
   vector<int> data{A,B,C};
   sort(data.begin(),data.end());
   int ans=data[2]*10+data[1]+data[0];
   cout<<ans<<endl;
   
}

Measured memory_bytes: 3624
// A - Ball Distribution
#include <bits/stdc++.h>

using namespace std;

int main(int argc, char *argv[])
{
	int n, k;
	cin >> n >> k;
	if (k <= 1) {
		cout << 0 << endl;
	} else {
		cout << (n - k) << endl;
	}

	return 0;
}


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

int comp(char a, char b){
    if(a==b){
        return 1;
    }else{
        return 0;
    }
}

int main(){
    char a[5], b[5];
    int c1, c2, i , j;
    while(1){
        c1 = c2 = 0;
        scanf("%s %s", a, b);
        if(strcmp(a, "0")==0 && strcmp(b, "0")==0){
            break;
        }
        for(i=0; i<4; i++){
            for(j=0; j<4; j++){
                if(j==i){
                    c1 += comp(a[i], b[j]);
                }else{
                    c2 += comp(a[i], b[j]);
                }
            }
        }
        printf("%d %d\n", c1, c2);
    }
    return 0;
}

Measured memory_bytes: 540
#include <iostream>
using namespace std;
int main() {
    int x1,x2,x3,x4,x5;
    cin>>x1>>x2>>x3>>x4>>x5;

    if(x1==0){
        cout<< 1;
    }
    else if(x2==0){
        cout<< 2;
    }
    else if(x3==0){
        cout<< 3;
    }
    else if(x4==0){
        cout<< 4;
    }
    else if(x5==0){
        cout<<5;
    }
    return 0;

}


Measured memory_bytes: 3564
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        n: usize
    }
    let ans: f64 = if n == 1 {
        1.0
    } else if n % 2 == 0 {
        0.5
    } else {
        ((n/2+1) as f64) / (n as f64)
    };
    println!("{}", ans);
}

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

void Main()
{
    int n;
    cin >> n;
    unsigned long a[n], x = 1;
    for (int i = 0; i < n; i++)
    {
            cin >> a[i];
    }
    sort(a, a+n);

    for (int i = 0; i < n; i++)
    {
            if((a[i] != 0 && x > a[i]*x) || x*a[i] > 1000000000000000000){
                cout << -1 << endl;
                return;
            }
            x = x*a[i];
    }
    
    cout << x << endl;
}

int main(int argc, char **argv)
{
    Main();
    return 0;
}


Measured memory_bytes: 4408
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
    int N, M;
    cin >> N >> M;
    int A[M], B[M];
    set<int> adj[N];
    for (int i = 0; i < M; i++) {
        cin >> A[i] >> B[i];
        A[i]--;
        B[i]--;
        adj[A[i]].insert(B[i]);
        adj[B[i]].insert(A[i]);
    }
    int d = 0;
    bool flag[N]{};
    for (int i = 0; i < N; i++) {
        if (flag[i]) continue;
        int k = 1;
        flag[i] = true;
        deque<int> q;
        q.push_back(i);
        while (!q.empty()) {
            int u = q.front();
            q.pop_front();
            for (int j : adj[u]) {
                if (!flag[j]) {
                    q.push_back(j);
                    k++;
                    flag[j] = true;
                }
            }
        }
        d = max(d, k);
    }
    cout << d << "\n";
    return 0;
}

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

int main(){

    double x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;

    double x = pow(x1 - x2, 2);
    double y = pow(y1 - y2, 2);

    cout << fixed << setprecision(7) << sqrt(x + y) << endl;

    return 0;
}


Measured memory_bytes: 3284
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <string>
#include <math.h>
#include <map>
#include <numeric>
#include <stack>
#include <queue>
#include <functional>
#include <stdio.h>
#define ll long long
#define pl pair<ll,ll>
#define vl vector<ll>
#define vvl vector<vector<ll> >
#define vvvl vector<vector<vector<ll> > >
#define vd vector<double>
#define vvd vector<vector<double> >
#define vvvd vector<vector<vector<double> > >
#define vb vector<bool>
#define vvb vector<vector<bool> >
#define vvvb vector<vector<vector<bool> > >
#define rep(i,a) for(ll i = 0;i<a;++i)
#define rep1(i,a) for(ll i = 1;i<a;++i)
#define rrep(i,a) for(ll i = a;i>=0;--i)
#define mod 1000000007
#define inf 10010010010
using namespace std;

int main(){
	ll a, b, m; cin >> a >> b >> m;
	vl as(a), bs(b);
	rep(i, a) cin >> as[i];
	rep(i, b) cin >> bs[i];
	ll ans = *min_element(as.begin(), as.end()) + *min_element(bs.begin(), bs.end());
	rep(i, m){
		ll x, y, c; cin >> x >> y >> c;
		x--; y--;
		ans = min(ans, as[x] + bs[y] - c);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define GET_MACRO(_1,_2,_3,_4,_5,NAME,...) NAME
#define pr(...) GET_MACRO(__VA_ARGS__,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__)
#define pr1(a) (#a)<<"="<<(a)
#define pr2(a,b) pr1(a)<<", "<<pr1(b)
#define pr3(a,b,c) pr2(a,b)<<", "<<pr1(c)
#define pr4(a,b,c,d) pr3(a,b,c)<<", "<<pr1(d)
#define pr5(a,b,c,d,e) pr4(a,b,c,d)<<", "<<pr1(e)
#define int long long
#define double long double
using namespace std;
const int N = 100010;
const int INF = 1LL<<55;
const int mod = (1e9)+7;
const double EPS = 1e-8;
const double PI = 6.0 * asin(0.5);
typedef pair<int,int> P;
typedef long long ll;
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
ostream& operator<<(ostream& o,P p){return o<<"("<<p.first<<","<<p.second<<")";}
istream& operator>>(istream& i,P &p){return i>>p.first>>p.second;}
ostream& operator<<(ostream& o,vector<auto> &a){int i=0;for(auto t:a)o<<(i++?" ":"")<<t;return o;}
istream& operator>>(istream& i,vector<auto> &a){for(auto &t:a)i>>t;return i;}
void prArr(auto a,string s=" "){int i=0;for(auto t:a)cout<<(i++?s:"")<<t;cout<<endl;}

int n;
string str;
string num="51?3";

int mem[20][2][10][10][10];
int used[20][2][10][10][10];


int pow10(int x){
  if(x == 0) return 1;
  return 10 * pow10(x-1);
}

int cnt(int x,int less){
  if(x == n) return 1;
  if(less) return pow10(n - x);
  int a =  cnt(x+1,0);
  int b = (str[x] - '0') * cnt(x+1,1);
  return a + b;
}

int dfs(int idx=0,int less=0,int a=0,int b=0,int c=0){

  if(idx == n) return 0;
  if(used[idx][less][a][b][c]++) return mem[idx][less][a][b][c];
  
  int u = less? 9:str[idx]-'0';
  int res = 0;
  for(int i=0;i<=u;i++){
    int nidx = idx+1;
    int nless = less || (i != u);
    if(a == 5 && b == 1 && i == 3) res += cnt(nidx,nless);
    else res += dfs(nidx,nless,b ,c ,i);
    
  }
  return mem[idx][less][a][b][c] = res;
}

signed main(){
  cin>>str;
  n = str.size();

  int ans = dfs();
  cout<<ans<<endl;
  return 0;
}



Measured memory_bytes: 3656
N = int(input())
A = list(map(int, input().split()))
B = []

for i in range(N):
    if i==0:
        B.append(0)
    else:
        if A[i-1]>A[i]:
            temp = A[i-1]-A[i]
            B.append(temp)
            A[i] += temp

ans = sum(B)
print(ans)

Measured memory_bytes: 32072
"""
author : halo2halo
date : 24, Jan, 2020
"""

import sys

# import numpy as np

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

a, b = map(int, readline().split())
print(':(' if a > 8 or b > 8 else 'Yay!')


Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin >> s;
  int size = s.size();
  if(size==2){
    cout << s << endl;
  }else{
    cout << s.at(2) << s.at(1) <<s.at(0) << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
	REP(i, v.size()) { if (i)os << " "; os << v[i]; }return os;
}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
	REP(i, v.size()) { if (i)os << endl; os << v[i]; }return os;
}

int main() {
	// メインプログラムここから
	double r1, r2, r3;

	cin >> r1 >> r2;

	r3 = r1*r2 / (r1 + r2);

	cout << setprecision(10) << r3 << setprecision(12) << endl;
	// ここまで
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
// XOR[0, 2^M)= (M==1) ? 1
//                     : 0;
int main(){
  int M,K;
  cin >> M >> K;

  int ub= 1<<M;
  if(K>=ub){
    cout << -1 << endl;
  }
  else if(M==1){
    if(K==0){
      cout << 0 <<" "<< 0 <<" "<< 1 <<" "<< 1 << endl;
    }
    else{
      cout << -1 << endl;
    }
  }
  else{
    for(int i=0; i<ub; i++){
      if(i != K){
        cout << i <<" ";
      }
    }
    cout << K <<" ";
    for(int i=ub-1; i>=0; i--){
      if(i != K){
        cout << i <<" ";
      }
    }
    cout << K << endl;
  }
}

Measured memory_bytes: 1792
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
using namespace std;
typedef long long ll;
const int MAXN=2000;
ll a[MAXN+5],b[MAXN+5][MAXN+5];
ll n,x,ans,sum=1LL<<60LL;
int main()
{
	scanf("%lld%lld",&n,&x);
	for(int i=1;i<=n;i++)
		scanf("%lld",&a[i]);
	for(int i=1;i<=n;i++)
	{
		b[i][0]=a[i];
		for(int j=1;j<=n-1;j++)
		{
			int pos=i-j;
			if(pos<=0)
				pos=n-abs(pos);
			b[i][j]=min(b[i][j-1],a[pos]);
		}
	}
	for(int j=0;j<=n-1;j++)
	{
		ans=0;
		for(int i=1;i<=n;i++)
			ans+=b[i][j];
		sum=min(sum,ans+x*j);
	}
	printf("%lld\n",sum);
	return 0;
}


Measured memory_bytes: 31616
import java.util.Scanner;

class Main{
	public static void main(String[] args) {
		try(Scanner sc = new Scanner(System.in)){
			for(;;) {
				int h = sc.nextInt();
				int w = sc.nextInt();
				if(h==0&&w==0) break;
				for(int i=0; i<h; i++) {
					for(int j=0; j<w; j++) {
						System.out.print("#");
					}
					System.out.println();
				}
				System.out.println();
			}
		}
	}
}


Measured memory_bytes: 34648
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <set>
#include <iomanip>
#include <map>
#include <queue>
#include <ctime>
#include <stack>
#include <bitset>
#include <list>

#define X first
#define Y second
#define pb push_back
#define mp make_pair
#define sqr(x) ((x)*(x))
#define bitcnt(x) __builtin_popcountll(x)
#define rt return


typedef unsigned long long ull;
typedef unsigned int uint;
typedef long long ll;
typedef long double ld;

using namespace std;


const int INF = (int)1e9 + 37;
const ld PI = acos(-1.0);
const int MAXN = (int)100000 + 222;
const ll MOD = (ll)1e6 + 3;
const int MAXQ = (int)1e5 + 222;
const int dx[4] = { 0, 0, 1, -1 };
const int dy[4] = { -1, 1, 0, 0 };

vector <int> g[MAXN];
int a[MAXN];
int ans = 0;
int n, x;

int dfs(int v) {
	int cur = 0;
	for (auto u : g[v]) {
		cur = max(cur, dfs(u) + 1);
	}
	if (cur == x - 1 && a[v] != 0) {
		a[v] = 0;
		cur = -1;
		ans++;
	}
	return cur;
}

int main() {
	//freopen("input.txt", "rt", stdin);
	//freopen("output.txt", "wt", stdout);

	
	cin >> n >> x;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		a[i]--;
		if (i == 0) {
			ans += (a[0] != 0);
			a[0] = 0;
		}
		else {
			g[a[i]].pb(i);
		}
	}
	
	dfs(0);

	cout << ans << endl;
    
	rt 0;
}

Measured memory_bytes: 10752
program main
implicit None
	character*10,allocatable::w(:)
	integer::n,i,j,c,k
	
	read *,n
	
	c = 0
	allocate(w(n))
	
	read *,w
	
	do i = 1,n-1
		do j = i+1,n
			if(w(i) == w(j))then
				c = 1
			endif
		enddo
	enddo
	
	do i = 2,n
		k = len_trim(w(i-1))
		if(w(i-1)(k:k) /= w(i)(1:1))then
			c = 1
		endif
	enddo
	
	if(c == 0)then
		print 101,"Yes"
		else
			print 101,"No"
	endif
	
101 format(a)
end program main

Measured memory_bytes: 512