akhauriyash/Code-Regression huggingface dataset:
module.exports=function(e){var r={};function t(n){if(r[n])return r[n].exports;var o=r[n]={i:n,l:!1,exports:{}};return e[n].call(o.exports,o,o.exports,t),o.l=!0,o.exports}return t.m=e,t.c=r,t.d=function(e,r,n){t.o(e,r)||Object.defineProperty(e,r,{enumerable:!0,get:n})},t.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},t.t=function(e,r){if(1&r&&(e=t(e)),8&r)return e;if(4&r&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(t.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&r&&"string"!=typeof e)for(var o in e)t.d(n,o,function(r){return e[r]}.bind(null,o));return n},t.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(r,"a",r),r},t.o=function(e,r){return Object.prototype.hasOwnProperty.call(e,r)},t.p="",t(t.s=0)}([function(e,r,t){t(1)(t(2).readFileSync("/dev/stdin","UTF-8"))},function(e,r){e.exports=function(e){for(var r=e.split("\n"),t=r[0].split(" "),n=(Number(t[0]),Number(t[1])),o=0,u=999999,i=0;i<n;i++){var f=r[i+1].split(" "),l=Number(f[0]),c=Number(f[1]);l>o&&(o=l),c<u&&(u=c)}var a=u-o+1,p=a>=0?a:0;console.log(p)}},function(e,r){e.exports=require("fs")}]);

Measured memory_bytes: 28988
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
ll mod=998244353;
ll mul(ll a, ll b)
{
	return ((a%mod)*(b%mod))%mod;
}
ll add(ll a, ll b)
{
	return ((a%mod)+(b%mod))%mod;
}
ll sub(ll a, ll b)
{
	return ((a%mod)-(b%mod)+mod)%mod;
}
ll n,m,kk;
ll a[20][20];
ll c[20];
ll out=1e18;
int main() 
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>n>>m>>kk;
	vector<ll> v;
	ll arr[m];
	for(ll i=0;i<n;i++)
	{
		
		cin>>c[i];
		for(ll j=0;j<m;j++)
		{
			cin>>a[i][j];
		}
	}
	ll u=pow(2,n);

	for(ll i=1;i<u;i++)
	{
		ll x=i;
		ll j=0;
		vector<ll> v;
		while(x)
		{
			if(x%2)
			{
				v.push_back(j);
			}
			x=x/2;
			j++;
		}
		ll b[m];
		for(ll j=0;j<m;j++)
		{
			b[j]=0;
		}
		ll co=0;
		for(ll j=0;j<v.size();j++)
		{
			
			co+=c[v[j]];
			for(ll k=0;k<m;k++)
			{
				b[k]+=a[v[j]][k];
			}
		}
		
		ll tr=1;
		for(ll j=0;j<m;j++)
		{
			
			if(b[j]<kk)
			{
				tr=0;
			}
		}
		
		if(tr==1)
		{
			out=min(out,co);
		}
	}
	if(out==1e18)
	{
		cout<<"-1";
	}
	else
	{
		cout<<out;
	}
}

Measured memory_bytes: 4096
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
#include <array>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <queue>
#include <bitset>
#include <tuple>
#include <cmath>
#include <complex>
#include <algorithm>
#include <utility>
#include <regex>
#include <cstdint>
#include <numeric>
#include <functional>
#include <cassert>

using namespace std;
using ll = int64_t;
using ull = uint64_t;

constexpr ll INF = 1000000000;/* 1e+9a */

void solve(istream &cin) {
    string s;
    cin >> s;
    if(!cin) return;
    bool N, W, S, E;
    N = W = S = E = false;
    for (auto &&c : s) {
        if(c == 'N'){
            N = true;
        }
        else if(c == 'W'){
            W = true;
        }
        else if(c == 'S'){
            S = true;
        }
        else {
            E = true;
        }
    } // end c
    cout << (N == S and W == E ? "Yes\n" : "No\n") ;
    
}

int main(int argc, char *argv[]) {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << setprecision(16) << scientific;
#ifdef DEBUG
    cerr << "DEBUG MODE" << endl;
    string test_cases = "test.txt";
    auto fs = fstream(test_cases, fstream::in);
    while(fs) {
        solve(fs);
    }
#else
    solve(cin);
#endif
    return 0;
}


Measured memory_bytes: 256
ans = 0
for x in range(30):    
    a, op, b = input().split()
    if op == "+":
      ans = int(a) + int(b)
      print(str(ans))
    elif op == "-":
      ans = int(a) - int(b)
      print(str(ans))
    elif op == "*":
      ans = int(a) * int(b)
      print(str(ans))
    elif op == "/":
      ans = int(a) / int(b)
      print(str(int(ans)))
    else:
      break


Measured memory_bytes: 5600
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <string>
#include <numeric>
#include <cmath>
using namespace std;

int main() {
    int t;
    cin >> t;
    vector<long long> a(t);
    for (int i = 0; i < t; i++) {
        cin >> a[i];
    }
    int s = 0;

    /*int k = a[0];
    for (int i = 1; i < t; i++) {
        if (a[i] > k) {
            k = a[i];
            //cout << k << endl;
        }
        
        if (a[i] < k) {
            s += k - a[i];
            //cout << s << " " << a[i] << " " << k << endl;
        }
    }*/

    /*for (int i = 1; i < t; i++) {
        if (a[i] < a[i - 1]) {
            int d = a[i - 1] - a[i];
            s += d;
            //cout << s << " " << a[i] << " " << a[i - 1] << endl;
            a[i] += d;
        }
    }*/
    
    /*int mx = a[0];
    for (int i = 0; i < t; i++) {
        mx = max(mx, a[i]);
        //cout << mx - a[i] << endl;
        //cout << i << endl;
        s += mx - a[i];
    }*/

    /*int worst = 0;
    for (int i = 0; i < t; i++) {
        if (a[i] < worst) {
            s += worst - a[i];
            a[i] = worst;
        }
        worst = max(worst, a[i]);
    }
    cout << s << endl;*/

    long long m = a[0];
    long long ans = 0;
    for (int i = 0; i < t; ++i) {
        if (m < a[i]) {
            m = a[i];
        } else {
            ans += m - a[i];
        }
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 4756
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
// #include "prettyprint.hpp"

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

  long count[10][10];
  for (int i = 0; i < 10; i++) {
    for (int j = 0; j < 10; j++) {
      count[i][j] = 0;
    }
  }

  for (int i = 1; i <= N; i++) {
    string temp = to_string(i);
    int first = temp[0] - '0';
    int last = temp[temp.length() - 1] - '0';
    count[first][last] += 1;
  }

  long ans = 0;

  for (int i = 0; i < 10; i++) {
    for (int j = 0; j < 10; j++) {
      ans += count[i][j] * count[j][i];
    }
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cstdlib>

#define COMMAND_MAX_SIZE 8

struct Node {
  Node *left_child_ptr;
  Node *right_child_ptr;
  int key;
};

struct Tree {
  Node *root_ptr;
};


void insert(Tree *tree, int key) {
  Node *new_node_ptr = (Node *)malloc(sizeof(Node));
  new_node_ptr->key = key;
  new_node_ptr->left_child_ptr = NULL;
  new_node_ptr->right_child_ptr = NULL;

  if(tree->root_ptr == NULL) {
    tree->root_ptr= new_node_ptr;
    return;
  }

  Node *previous_node_ptr;
  Node *current_node_ptr = tree->root_ptr;
  while(true) {
    previous_node_ptr = current_node_ptr;
    if(key <= current_node_ptr->key) {
      current_node_ptr = current_node_ptr->left_child_ptr;
    } else {
      current_node_ptr = current_node_ptr->right_child_ptr;
    }

    if(current_node_ptr == NULL) {
      break;
    }
  }

  if(key <= previous_node_ptr->key) {
    previous_node_ptr->left_child_ptr = new_node_ptr;
  } else {
    previous_node_ptr->right_child_ptr = new_node_ptr;
  }
}

void print_as_inorder_walk(Tree tree, Node *current_node_ptr) {
  if(current_node_ptr == NULL) {
    return;
  }

  print_as_inorder_walk(tree, current_node_ptr->left_child_ptr);
  printf(" %d", current_node_ptr->key);
  print_as_inorder_walk(tree, current_node_ptr->right_child_ptr);
}

void print_as_preorder_walk(Tree tree, Node *current_node_ptr) {
  if(current_node_ptr == NULL) {
    return;
  }

  printf(" %d", current_node_ptr->key);
  print_as_preorder_walk(tree, current_node_ptr->left_child_ptr);
  print_as_preorder_walk(tree, current_node_ptr->right_child_ptr);;
}

void print(Tree tree, Node* current_node_ptr) {
  print_as_inorder_walk(tree, current_node_ptr);
  printf("\n");
  print_as_preorder_walk(tree, current_node_ptr);
  printf("\n");
}

bool find(Tree tree, int target_key) {
  if(tree.root_ptr == NULL) {
    return false;
  }

  Node *current_node_ptr = tree.root_ptr;
  while(true) {
    if(current_node_ptr->key == target_key) {
      return true;
    }

    if(target_key <= current_node_ptr->key ) {
      current_node_ptr = current_node_ptr->left_child_ptr;
    } else {
      current_node_ptr = current_node_ptr->right_child_ptr;
    }

    if(current_node_ptr == NULL) {
      break;
    }
  }

  return false;
}

int main() {
  int commpand_size;
  Tree tree = {NULL};

  scanf("%d", &commpand_size);

  for(int i = 0; i < commpand_size; i++) {
    char command[COMMAND_MAX_SIZE];

    scanf("%s", command);

    if(0 == strncmp(command, "insert", 7)) {
      int key;
      scanf("%d", &key);
      insert(&tree, key);
    } else if(0 == strncmp(command, "find", 4)) {
      int key;
      scanf("%d", &key);

      bool is_found = find(tree, key);

      if(is_found) {
        puts("yes");
      } else {
        puts("no");
      }

    } else if(0 == strncmp(command, "print", 5)) {
      print(tree, tree.root_ptr);
    }
  }
}



Measured memory_bytes: 15120
import numpy as np
from sys import argv
import time


def input_from_file():
    with open(argv[1], "r") as f:
        D = int(f.readline())
        C = np.array(f.readline().split(), dtype=int)
        S = tuple(tuple(map(int, f.readline().split())) for _ in range(D))
    return D, C, S


def input_from_console():
    D = int(input())
    C = np.array(input().split(), dtype=int)
    #S = tuple(tuple(map(int, input().split())) for _ in range(D))
    S = np.array([input().split() for _ in range(D)], dtype=int)
    cand = np.argsort(C * S)[:, 10:] + 1
    return D, C, S, cand.tolist()


def greed(D, C, S):
    last = np.ones(26, dtype=int)
    ans = []
    for s in S:
        s = np.array(s)
        tmp = s + C * last
        i = np.argmax(tmp)
        last[i] = 0
        last += 1
        ans.append(i + 1)
    return ans


def calc_score(D, C, S, T):
    res = 0
    last = np.ones(26, dtype=int)
    for d, t in enumerate(T):
        t -= 1
        last[t] = 0
        score = S[d][t]
        score -= (C * last).sum()
        res += score
        last += 1
    return res


def output_to_file(ans):
    with open("output.txt", "w", newline="") as f:
        for a in ans:
            f.write("{}\n".format(a))


def main():
    start = time.time()
    lim = 1.800
    D, C, S, cand = input_from_console()
    #D, C, S = input_from_file()
    #初期解, 貪欲法
    sol = greed(D, C, S)
    score = calc_score(D, C, S, sol)
    while True:
        d = np.random.randint(0, D)
        q = np.random.choice(cand[d])
        old = sol[d]
        sol[d] = q
        new_score = calc_score(D, C, S, sol)
        if new_score > score:
            score = new_score
        else:
            sol[d] = old
        if time.time() - start >= lim:
            break
    print(*sol, sep="\n")
    # output_to_file(sol)


if __name__ == "__main__":
    main()

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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define R(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

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

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

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
  for(auto &e:u) fill_v<T>(e,v...);
}

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

    int64 T;
    cin >> T;
    REP(_, T) {
        int64 m, n, cnt = 0;
        cin >> m >> n;
        REP(i, 500) {
            REP(j, 500) {
                if (i == j && i == 0) continue;
                int64 a = i*i+j*j;
                if ((m*i+n*j) % a == 0 && (i*n-m*j) % a == 0) {
                    cnt += 2 * (i != 0 && j != 0 ? 2 : 1);
                }
            }
        }
        cout << "CP"[cnt == 8] << endl;
    }
}



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

using namespace std;

int main() {
	ios_base::sync_with_stdio(false);
	int n, m, c;
	cin >> n >> m >> c;
	vector<int> b(m);
	for (int i = 0; i < m; ++i) {
		cin >> b[i];
	}
	int cnt = 0;
	while (n--) {
		vector<int> a(m);
		int nw = c;
		for (int i = 0; i < m; ++i) {
			cin >> a[i];
			nw += a[i] * b[i];
		}
		if (nw > 0) {
			++cnt;
		}
	}
	
	cout << cnt << '\n';
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cassert>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define PI 3.14159265358979
using namespace std;
using ll = long long;
using P = pair<int, int>;
struct Edge
{
  int to;
  int weight;
  Edge(int t, int w) : to(t), weight(w) {}
};
// using Graph = vector<vector<Edge>>;
using Graph = vector<vector<int>>;

const long long INF = 1LL << 60;
const int INT_INF = 1000000000;

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

int count(vector<int> &vis)
{
  int mi = INT_INF;
  for (int i = 0; i < 24; i++)
  {
    for (int j = 0; j < 24; j++)
    {
      if (vis[i] && vis[j] && i != j)
      {
        int d1 = abs(i - j);
        int d2 = 24 - d1;
        int d = min(d1, d2);
        mi = min(mi, d);
      }
    }
  }
  return mi;
}

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N;
  cin >> N;
  vector<int> D(N);
  for (auto &it : D)
    cin >> it;

  vector<int> cnt(13);
  vector<int> vis(24);
  for (int i = 0; i < N; i++)
    cnt[D[i]]++;
  if (cnt[0])
  {
    cout << 0 << endl;
    return 0;
  }
  vis[0] = 1;
  vector<int> v;
  for (int i = 1; i < 12; i++)
  {
    if (cnt[i] == 1)
      v.push_back(i);
    else if (cnt[i] == 2)
      vis[i] = vis[24 - i] = 1;
    else if (2 < cnt[i])
    {
      cout << 0 << endl;
      return 0;
    }
  }
  if (cnt[12] == 1)
    vis[12] = 1;
  else if (2 <= cnt[12])
  {
    cout << 0 << endl;
    return 0;
  }

  int M = v.size();
  if (M == 0)
  {
    cout << count(vis) << endl;
    return 0;
  }

  int ans = 0;
  for (int bit = 0; bit < (1 << M); bit++)
  {
    for (int i = 0; i < M; i++)
    {
      if (bit & (1 << i))
      {
        vis[v[i]] = 1, vis[24 - v[i]] = 0;
      }
      else
      {
        vis[v[i]] = 0, vis[24 - v[i]] = 1;
      }
    }
    ans = max(ans, count(vis));
  }
  cout << ans << endl;
  return 0;
}

//  公式解説の図を基に考える．cnt[i]:=時間iの人の人数とする．まず，例外から考える．1 <= cnt[0]のとき，高橋君と被るので答えは0.cnt[12] == 0　その時間に人がいるのは間違いない．1 < cnt[12]そのなかの二人の答えが被るので答えは0.ほかのある時間t([1, 11])を考える．cnt[t] == 0なら人はいない．cnt[t] == 1ならば時間tか時間24-tに人がいる．これは分からないので全探索．cnt[t] == 2ならば時間tと時間24 - tのどちらにも人がいる．ここは確定．2 <= cnt[t]ならばどうやっても2人がいる時間ができてしまうため答えは0 あとはcnt[t] == 1である部分のみを全探索して距離の最小をチェックする．


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <cstring>
#include <utility>
#include <algorithm>
#include <functional>
#include <deque>
#include <cctype>
#include <ctime>
#include <cstdlib>
#include <iomanip>
using namespace std;

int main(){
   int a, b, c, d;
   cin >> a >> b >> c >> d;
   if (a+b < c+d) cout << "Right" << endl;
   else if (a+b == c+d) cout << "Balanced" << endl;
   else cout << "Left" << endl;
}


Measured memory_bytes: 888
#include <utility>
#include <vector>
#include <iostream>
#include <algorithm>
#include <set>
#include <climits>
#define REP(i,n) for(int i=0;i<n;i++)
typedef unsigned long ul;
typedef unsigned long long ull;
typedef long long ll;
using namespace std;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int inf = 10000000;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a[3], b[3];
  int count[4] = {0};
  string ans;
  for(int i = 0; i < 3; i++){
    cin >> a[i] >> b[i];
    a[i]--;
    b[i]--;
    count[a[i]]++;
    count[b[i]]++;
  }
  int numOnes= 0;
  for(int i = 0; i < 4; i++){
    if(count[i] == 1){
      numOnes++;
    }
  }
  if(numOnes==2){
    ans = "YES";
  }else{
    ans = "NO";
  }
  cout << ans <<endl;
  
}

Measured memory_bytes: 256
#include<stdio.h>
#define N 100
#define WHITE 0
#define GRAY 1
#define BLACK 2

int n,M[N][N];
int color[N],d[N],f[N],tt;
 
void dfs_visit(int);
void dfs();

int main(){
  int i,j,u,k,v;
 
  scanf("%d",&n);
 
  for(i=0;i<n;i++){ 
    for(j=0;j<n;j++){
      M[i][j]=0;
    }
  }

  for(i=0;i<n;i++){ 
    scanf("%d %d",&u,&k);
    u--;
    for(j=0;j<k;j++){
      scanf("%d",&v);
      v--;
      M[u][v]=1;
    }
  }

  dfs();
 
  return 0;
}
 
void dfs_visit(int u){
  int v;
  color[u]=GRAY;
  d[u]=++tt;
  for(v=0;v<n;v++){
    if(M[u][v]==0){ 
      continue;
    }
    if(color[v]==WHITE){
      dfs_visit(v);
    }
  }
  color[u]=BLACK;
  f[u]=++tt;
}

void dfs(){
  int u;

  for(u=0;u<n;u++){
    color[u]==WHITE;
    tt=0;
  }

  for(u=0;u<n;u++){
    if(color[u]==WHITE){
      dfs_visit(u);
    }
  }

  for(u=0;u<n;u++){
    printf("%d %d %d\n",u+1,d[u],f[u]);   
  }
}

Measured memory_bytes: 632
import Control.Monad(forM_)
import qualified Data.Vector as V

main = do
  ns <- fmap (fmap (read :: String -> Int) . words) . lines <$> getContents
  let n = head $ head ns
  let ls = V.fromList $ tail $ concat $ ns
  putStrLn $ show $ solve n ls

solve :: Int -> V.Vector Int -> Int
solve n ls = f n 1
  where
    f 0 _ = -1
    f m i
      | i == 2 = n - m
      | otherwise = f (subtract 1 m) $ ls V.! (subtract 1 i)     


Measured memory_bytes: 33148
n = int(input())
h = tuple(map(int, input().split()))

INF = float('inf')
dp = [INF] * n
dp[0] = 0
# dp[i] = (足場iにたどり着いた時点でのコストの最小値)

for i in range(n):
    if i + 1 < n:
        dp[i + 1] = min(dp[i + 1], dp[i] + abs(h[i + 1] - h[i]))
    if i + 2 < n:
        dp[i + 2] = min(dp[i + 2], dp[i] + abs(h[i + 2] - h[i]))

print(dp[n - 1])


Measured memory_bytes: 14056
from collections import defaultdict
n, x, y = map(int, input().split())
x -= 1
y -= 1
dd = defaultdict(int)
for i in range(n-1):
    for j in range(i+1, n):
        sp = min(j-i, abs(i-x)+abs(j-y)+1)
        dd[sp] += 1
for i in range(1, n):
    print(dd[i])


Measured memory_bytes: 3956
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define EPS (1e-10)
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

signed main(){
	cerr<<"Hello"<<endl;
	string s;int k;cin>>s>>k;
	vector<string>v;
	rep(i,s.size()){
		for(int j=1;j<=5;j++){
			v.push_back(s.substr(i,j));
		}
	}
	sort(v.begin(),v.end());
	v.erase(unique(v.begin(),v.end()),v.end());
	k--;
	cerr<<v[k]<<endl;
	cout<<v[k]<<endl;
}

Measured memory_bytes: 1660
#include <vector>
#include <algorithm>
#include <cstdio>
using namespace std;

bool chk(const vector<int> &v){
	int s=0;
	for(int i=0;i<v.size();i++){
		if(s<i)return false;
		s=max(s,i+v[i]/10);
	}
	return true;
}

int main(){
	int n;
	scanf("%d",&n);
	vector<int>v(n);
	for(int i=0;i<n;i++)scanf("%d",&v[i]);
	if(chk(v)){
		reverse(v.begin(),v.end());
		if(chk(v)){
			puts("yes");
			return 0;
		}
	}
	puts("no");
}

Measured memory_bytes: 3432
fun main(args: Array<String>) {
    val sc = java.util.Scanner(System.`in`)
    val n = sc.nextInt()
    val a = sc.asSequence().take(n + 1).map { it.toInt() }.toMutableList()
    val b = sc.asSequence().take(n).map { it.toInt() }.toMutableList()

    var r = 0L
    for (i in 0 until n) {
        val score = Math.min(a[i], b[i])
        b[i] -= score
        val scoreNext = Math.min(a[i + 1], b[i])
        a[i + 1] -= scoreNext
        r += score + scoreNext
    }
    println(r)
}


Measured memory_bytes: 59624
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))
def ism():return map(str,input().split())
def isl():return list(map(str,input().split()))

n,m,x = iim()
before = 0
after = 0
A = iil()
for i in A:
    if i < x:
        before += 1
    else:
        after += 1

print(min(before,after))

Measured memory_bytes: 3064
#if !defined(__clang__) && defined(__GNUC__)
#include <bits/stdc++.h>
#else
#include <cstdlib>
#include <climits>
#include <iostream>
#include <cstdint>
#include <vector>
#include <string>
#include <complex>
#include <bitset>
#include <queue>
#include <deque>
#include <stack>
#include <utility>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <regex>
#endif //  !defined(__clang__) && defined(__GNUG__)
#include <boost/lexical_cast.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/multi_array.hpp>
#include <boost/optional.hpp>
#include <boost/math/common_factor_rt.hpp>

using namespace std;

int main()
{
    int64_t N, x;
    std::cin >> N >> x;

    std::vector<int64_t> A;
    for (size_t i = 0; i < N; ++i) {
        int64_t t;
        std::cin >> t;
        A.push_back(t);
    }

    uint64_t count = 0;

    for (int64_t i = 0; i < N-1; ++i) {
        auto s = A[i] + A[i+1];
        if (s > x) {
            auto e = s - x;
            count += e;
            if (A[i+1] >= e) {
                A[i+1] -= e;
            }
            else {
                A[i+1] = 0;
            }
        }
    }

    std::cout << count << std::endl;

    return 0;
}


Measured memory_bytes: 1400
#include <iostream>
#include <cstdlib>
#include <string>
#include <algorithm>
using namespace std;

int main(){
  int n;
  cin >> n;
  int a[n];
  int count_hu=0;
  int count_sei=0;
  int max=0,min=1000000001;
  int max2=0,min2=-1000000001;
  for(int i=0;i<n;i++){
    cin >> a[i];
    if(a[i]>=0)
      count_sei++;
    if(a[i]<=0)
      count_hu++;
    if(max<a[i])
      max=a[i];
    if(min>a[i] && a[i]>0)
      min=a[i];
    if(max2>a[i])
      max2=a[i];
    if(min2<a[i] && a[i]<0)
      min2=a[i];
  }
  if(count_sei==n){
    cout << max-min << endl;
    return 0;
  }
  if(count_hu==n){
    cout << -1*(max2-min2) << endl;
    return 0;
  }
  cout << max-min2 << endl;
  return 0;
}


Measured memory_bytes: 256
from fractions import gcd
# from math import gcd
from functools import reduce
N, M = map(int, input().split())
nums = set([num // 2 for num in list(map(int, input().split()))])
# 1<=X<=Mの範囲で、半公倍数の数を求める。
# 但し、Xは、num*(p+0.5)でなければならない
# Mが10**9なので、全部やるのは無理。
# n.5倍なので、numsのあたいは全て偶数になっている。

# nums一つ一つ、答えになりうるXの配列を作って、重複したものを残せばそれが答えになる。
# Nが10**5なので、どうだろう


def half_multiple(x, y):
    # 最大公約数は無駄なのではぶく
    # x=6,y=10なら=>2が無駄なもの
    return (x * y) // gcd(x, y)


def run():
    half_multiple_num = reduce(half_multiple, nums, 1)

    # print(half_multiple_num)
    for num in nums:
        # n.5倍の値でなければならないので、ここでチェックする
        if (half_multiple_num // num) % 2 == 0:
            print(0)
            return

    ans = M // half_multiple_num
    ans = ans - 1 if ans % 2 == 0 else ans

    print((ans + 1) // 2)


run()


Measured memory_bytes: 89580
from itertools import accumulate
import bisect


n = int(input())
a = list(map(int, input().split()))

arev = list(reversed(a))

front = list(accumulate(a))
back = list(accumulate(arev))

ans = float('inf')
for i in range(1,n-2):
    b = bisect.bisect_left(front,front[i]//2,0,i-1)
    c = bisect.bisect_left(back,back[n-i-2]//2,0,n-i-3)

    p = front[b]
    q = front[i]-front[b]
    s = back[c]
    r = back[n-i-2]-back[c]
    ans = min(max(p,q,r,s)-min(p,q,r,s),ans)

    if b!=0:
        p = front[b-1]
        q = front[i] - front[b-1]
        s = back[c]
        r = back[n-i-2] - back[c]
        ans = min(max(p, q, r, s) - min(p, q, r, s), ans)
    if c!=0:
        p = front[b]
        q = front[i] - front[b]
        s = back[c-1]
        r = back[n-i-2] - back[c-1]
        ans = min(max(p, q, r, s) - min(p, q, r, s), ans)
    if b!=0 and c!=0:
        p = front[b-1]
        q = front[i] - front[b-1]
        s = back[c-1]
        r = back[n-i-2] - back[c-1]
        ans = min(max(p, q, r, s) - min(p, q, r, s), ans)

print(ans)











Measured memory_bytes: 126044
N=int(input())
dp=[float("INF")]*(N+1)
dp[0]=0
six,nine=1,1
for i in range(1,N+1):
  if i==six*6:
    six*=6
  if i==nine*9:
    nine*=9
  dp[i]=min(dp[i-1],dp[i-six],dp[i-nine])+1
print(dp[N])

Measured memory_bytes: 3828
#include <stdio.h>
#include <vector>
#include <iostream>
#include <queue>
#include <bits/stdc++.h>
 
#define rep(i,n) for (int i=0;i<(n);++i)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<double> vd;
typedef pair<int, int> pi;


int main() {
  string s, t;
  cin >> s >> t;
  if (s == t.substr(0, s.size())){
    cout << "Yes" << endl;
  }else {
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
int l[300010],r[300010],col[300010];
vector<int> des[300010];
void dfs1(int s,int pre)
{
	for (int k=0;k<des[s].size();k++) if (des[s][k]!=pre)
	{
		dfs1(des[s][k],s);
		l[s]=max(l[s],l[des[s][k]]-1);
		r[s]=min(r[s],r[des[s][k]]+1);
		if (l[s]>r[s]) {puts("No");exit(0);}
	}
}
void dfs2(int s,int pre)
{
	for (int k=0;k<des[s].size();k++) if (des[s][k]!=pre)
	{
		if ((l[des[s][k]]<=col[s]+1)&&(r[des[s][k]]>=col[s]+1)) col[des[s][k]]=col[s]+1;
		else if ((l[des[s][k]]<=col[s]-1)&&(r[des[s][k]]>=col[s]-1)) col[des[s][k]]=col[s]-1;
		else {puts("No");exit(0);}
		dfs2(des[s][k],s);
	}
}
int main()
{
	int n;scanf("%d",&n);
	for (int i=1;i<=n;i++) {l[i]=-1e9;r[i]=1e9;}
	for (int i=1;i<n;i++)
	{
		int u,v;scanf("%d%d",&u,&v);
		des[u].push_back(v);des[v].push_back(u);
	}
	int d;scanf("%d",&d);
	while (d--)
	{
		int u,x;scanf("%d%d",&u,&x);
		l[u]=r[u]=x;
	}
	dfs1(1,0);col[1]=l[1];dfs2(1,0);puts("Yes");
	for (int i=1;i<=n;i++) printf("%d\n",col[i]);
}
	

Measured memory_bytes: 22144
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <algorithm>
#define rep(i, a, b) for (int i = (a), _ = (b); i <= _; ++ i)
#define per(i, a, b) for (int i = (a), _ = (b); i >= _; -- i)
#define For(i, a, b) for (int i = (a), _ = (b); i < _; ++ i)
#define ri rd<int>
using namespace std;
const int maxN = 307;

template<class T> inline T rd() {
	bool f = 1; char c = getchar(); for (; !isdigit(c); c = getchar()) if (c == '-') f = 0;
	T x = 0; for (; isdigit(c); c = getchar()) x = x * 10 + c - 48; return f ? x : -x;
}

int n, m;
int vis[maxN];
int mx[maxN], cnt[maxN];
int b[maxN][maxN];

int main() {

	n = ri(), m = ri();
	int res = n;
	rep (i, 1, n) rep (j, 1, m) b[i][j] = ri(), vis[j] = 0, mx[i] = 1;

	for (int t = m; t > 0; -- t) {
		rep (i, 1, m) cnt[i] = 0;
		rep (i, 1, n) {
			while (vis[b[i][mx[i]]] == 1) ++mx[i];
			++cnt[b[i][mx[i]]];
		}
		int id = 1;
		rep (i, 1, m) if (cnt[i] > cnt[id]) id = i;
		res = min(res, cnt[id]);
		vis[id] = 1;
	}
	printf("%d\n", res);

	return 0;
}


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

int n, arr[26];
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    cin >> n;
    for(int i =0; i < n; i++) {
      string s;
      cin >> s;
      arr[s[0]-'A']++;
    }
    cout << "AC x " << arr['A'-'A'] << " \n";
    cout << "WA x " << arr['W'-'A'] << " \n";
    cout << "TLE x " << arr['T'-'A'] << " \n";
    cout << "RE x " << arr['R'-'A'] << " \n";
}


Measured memory_bytes: 3676
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

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

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

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

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

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


int main(){
    int N = 10;
    int M = 100;

    cin >> N  >> M;

    double a = pow(2,M);
    int ans = a  * ( M*1900 + (N-M)*100 )  + EPS;
    cout << ans << endl;
    
    /* 
      vector<int> vec(10,5);
      for(auto itr = vec.begin(); itr != vec.end(); ++itr){
          std::cout << *itr << "\n";        
          
      }
      
      int aiueo = 1000;
      a = aiueo;
     */
   
}





Measured memory_bytes: 888
/*
    飲んだ魔剤で家が建つ。
    created at: 2020-03-14 21:19:01
*/

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

#define all(x) (x).begin(),(x).end()
#define rep(x, y) for (int x = 0; x < y; x++)
#define MOD 1000000007

typedef long long LL;
typedef long double LD;

bool compare_by_b(pair<int, int> a, pair<int, int> b)
{
    if (a.second != b.second) {
        return a.second < b.second;
    } else {
        return a.first < b.first;
    }
}

LL modpower(LL n, LL m, LL mod) {
    if (m == 0) {
        return 1;
    } else if (m % 2 == 0) {
        LL p = modpower(n, m/2, mod);
        return p*p % mod;
    } else {
        return n*modpower(n, m-1, mod) % mod;
    }
}

LL modinv(LL n, LL mod) {
    return modpower(n, mod-2, mod);
}

LL modcombination(LL n, LL r, LL mod) {
    LL ret = 1;

    for (int i = 0; i < r; i++) {
        ret *= (n-i);
        ret %= mod;
        ret *= modinv(i+1, mod);
        ret % mod;
    }

    return ret % mod;
}

ostringstream oss_global;
string s_global = oss_global.str();

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

    int ok = 1;
    for (int i = n-1; i >= 1; i--) {
        int diff = h[i] - h[i-1];
    
        if (diff < -1) {
            ok = 0;
        } else if (diff == -1) {
            h[i-1]--;
        }
    }

    for (int i = 0; i < n-1; i++) {
        if (h[i] > h[i+1]) ok = 0;
    }

    if (ok) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define rep(i,s, n) for(int i = s; i < (int)(n); i++)
#define co(x) cout<<x<<endl
#define SQvec(i,j) vector<vector<int>> data(i, vector<int>(j))
#define mod 1000000007
typedef long long int lint;

int main (){
  int N,M;
  cin >> N;
  M = N%10;
  if(M == 2 || M == 4 || M == 5 || M == 7 || M == 9){
    co("hon");
  }
  if(M == 0 || M == 1 || M == 6 || M == 8){
    co("pon");
  } 
  if(M == 3){
    co("bon");
  }
}

Measured memory_bytes: 3624
#include "bits/stdc++.h"

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

using namespace std;
const int INF = 1 << 30;
const long long MOD = 1000000000 + 7;

int main() {
	int N; cin >> N;
	if (N % 10 == 3)cout << "bon";
	else if (N % 10 == 0 || N % 10 == 1 || N % 10 == 6 || N % 10 == 8)cout << "pon";
	else cout << "hon";
}

Measured memory_bytes: 3636
from heapq import heappush, heappop

x, y, a, b, c = map(int, input().split())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))

hp = []
for e in p:
    heappush(hp, [-e, 0])
for e in q:
    heappush(hp, [-e, 1])
for e in r:
    heappush(hp, [-e, 2])

ans = 0
cnt = [0] * 3
sm = 0
mx = [x, y, c]
while hp:
    yum, col = heappop(hp)
    yum = -yum

    if cnt[col] >= mx[col]:
        continue

    ans += yum
    cnt[col] += 1
    sm += 1

    if sm == x + y:
        break

print(ans)


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

const int MOD = (int)1e9+7;

string s;
int n;
int dp[100100][13];

int dfs ( int pos, int mod ) {
    if ( pos == n ) {
        if ( mod == 5 ) return 1;
        else return 0;
    }
    if ( ~dp[pos][mod] ) return dp[pos][mod];
    if ( s[pos] == '?' ) {
        int rec = 0;
        for ( int i = 0; i <= 9; i++ ) {
            rec += dfs ( pos+1, (10*mod+i)%13 );
            rec %= MOD;
        }
        return dp[pos][mod] = rec;
    }
    else {
        int newMod = 10*mod + s[pos]-'0';
        return dp[pos][mod] = dfs ( pos+1, newMod%13 ) % MOD;
    }
}

signed main ( ) {

    memset(dp, -1, sizeof(dp));

    cin >> s;
    n = s.size();
    cout << dfs(0, 0) << endl;

    return 0;
}

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

#define rep(i,n) for(ll i=0;i<(n);++i)
using ll = int_fast64_t;
using pll = pair<ll,ll>;
constexpr ll INF = 1LL<<60;
constexpr ll MOD = 1e9+7;
template<class T> bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a,const T &b){if(a>b){a=b;return 1;}return 0;}
#if loc||local
template<class T>void dump(T&& t){cerr<<t<<endl;}
template<class T,class... Ts> void dump(T&& h, Ts&&... t){cerr<<h<<", ";dump(forward<Ts>(t)...);}
#else
void dump(){}
template<class T,class... Ts> void dump(T&& h, Ts&&... t){}
#endif
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T> ostream &operator<<(ostream& os,vector<T>const& v){for(auto const& vi:v)os<<vi<<" ";return os;}
template<class T,class U> ostream &operator<<(ostream& os,pair<T,U>const& p){os<<p.first<<","<<p.second;return os;}
template<class T>vector<T> vec(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto vec(size_t a, Ts... ts){return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...));}

signed main(){

  int x,n;
  cin>>x>>n;
  vector<ll> a(n);
  cin>>a;

  ll ans = -INF;
  for(int i=-1000;i<=1000;++i){
    bool ok = true;
    rep(j,n)if(a[j]==i)ok=false;
    if(ok){
      if(abs(ans-x)>abs(x-i)){
        ans=i;
      }
    }
  }
  cout<<(ans)<<endl;

}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
using vll = vector<vl>;
using Pll = pair<ll, ll>;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(v) v.begin(), v.end()
#define sz(x) ((int) x.size())
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
const int MOD = 1e9+7;
const int INF = 2e9;
template<class T> void print(const T& t){ cout << t << endl; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}

int main(){
  ll x, y;
  cin >> x >> y;
  ll ans = 0;
  if(x==1){
    ans += 300000;
  }
  else if(x==2){
    ans += 200000;
  }
  else if(x==3){
    ans += 100000;
  }
  if(y==1){
    ans += 300000;
  }
  else if(y==2){
    ans += 200000;
  }
  else if(y==3){
    ans += 100000;
  }
  if(x==y&&x==1){
    ans += 400000;
  }
  print(ans);
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i < (int)(n); i++)
#define rep1c(i, n) for (int i = 1; i <= (int)(n); i++)
#define repc0(n, i) for (int i = (int)(n); i >= 0; i--)

using namespace std;
typedef long long ll;

ll A, B;

void solve() {
  if(A==B) {
    cout << A << endl;
    return;
  }
  ll res = 0;
  rep(i, 40) {
    ll period = (ll)pow(2, i+1);
    ll a_m1_ones = A==0 ? 0ll : ((A-1)/period)*(period/2)+max(((A-1)%period)-(period/2-1), 0ll);
    ll a_ones = (A/period)*(period/2)+max((A%period)-(period/2-1), 0ll);
    ll b_ones = (B/period)*(period/2)+max((B%period)-(period/2-1), 0ll);
    ll ones = b_ones - a_ones + (a_ones - a_m1_ones);
    res |= (ones%2)<<i;
  }
  cout << res << endl;
  return;
}

int main() {
  cin >> A >> B;
  solve();
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
int main() {
    int n;
    std::cin >> n;
    if (n % 10 == 3) {
        std::cout << "bon\n";
        return 0;
    }
    if (n % 10 == 0 || n % 10 == 1 || n % 10 == 6 || n % 10 == 8) {
        std::cout << "pon\n";
        return 0;
    }
    std::cout << "hon\n";
    return 0;
}

Measured memory_bytes: 3524
using System;

class Program
{
    static int N;
    static int M;
    static int Q;
    static int[] A = new int[10];
    static int[] a = new int[50];
    static int[] b = new int[50];
    static int[] c = new int[50];
    static long[] d = new long[50];

    static void Main(string[] args)
    {
        var nmq = Console.ReadLine().Split(' ');
        N = int.Parse(nmq[0]);
        M = int.Parse(nmq[1]);
        Q = int.Parse(nmq[2]);

        for (var i = 0; i < Q; i++)
        {
            var abcd = Console.ReadLine().Split(' ');
            a[i] = int.Parse(abcd[0]) - 1;
            b[i] = int.Parse(abcd[1]) - 1;
            c[i] = int.Parse(abcd[2]);
            d[i] = long.Parse(abcd[3]);
        }

        var pos = 0;
        var min = 1;
        Console.WriteLine(Sub1(min, pos));
    }

    static long Sub1(int min, int pos)
    {
        long score = 0;

        if (pos == N)
        {
            for(var i = 0; i < Q; i++)
            {
                if (A[b[i]] - A[a[i]] == c[i]) score += d[i];
            }

            return score;
        }

        for (var i = min; i <= M; i++)
        {
            A[pos] = i;
            score = Math.Max(Sub1(i, pos + 1), score);
        }

        return score;
    }
}


Measured memory_bytes: 17768
#pragma GCC optimize("Ofast")
#pragma GCC target("avx2,tune=native")
#include <bits/stdc++.h>
#include <bits/extc++.h>
#define all(x) x.begin(), x.end()
#define pb push_back
using namespace std;
using namespace __gnu_pbds;
using ll = long long;
using vi = vector<ll>;
using vvi = vector<vi>;

int main() {
	 ios::sync_with_stdio(0);
	 cin.tie(0);
	 cout.tie(0);
	 ll n;
	 cin >> n;
	 vi a;
	 a.resize(n);
	 for(auto &i :a) cin >> i;
	 sort(all(a));
	 reverse(all(a));
	 gp_hash_table<ll, int> cnt;
	 ll ans = 0;
	 ll x;
	 for(auto i : a) {
		 cnt[i]++;
	 }
	 for(auto i : a) {
		 if(!cnt[i]) continue;
		 cnt[i]--;
		 ll x = 1;
		 while(x <= i) x<<=1;
		 if(cnt[x-i]) cnt[x-i]--, ans++;
	 }
	 cout << ans;
	 return 0;
}


Measured memory_bytes: 38888
A,B,M=map(int,input().split())
Ai=list(map(int,input().split()))
Bi=list(map(int,input().split()))

res=min(Ai)+min(Bi)
for j in range(M):
  s=list(map(int,input().split()))
  if Ai[s[0]-1]+Bi[s[1]-1]-s[2]<res:
    res=Ai[s[0]-1]+Bi[s[1]-1]-s[2]
print(res)

Measured memory_bytes: 18736
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
     
#define fast { ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0); }
#define pb push_back
#define ll long long
#define ld long double
     
#define vi vector<int>
#define vl vector<long>
#define vll vector<long long>
     
#define infi INT_MAX
#define infl LONG_LONG_MAX
#define infd LDBL_MAX
#define f(i,a,b) for(ll i=a;i<b;i++)
#define fi(i,a,b) for(ll i=(b-1);i>=a;i--)
#define F first
#define S second
#define G(a,b) get<a>(b)
#define MP make_pair
#define MT make_tuple
#define pll pair<ll,ll> 
#define endl "\n"
#define ALL(v) v.begin(),v.end()
#define nl cout<<"\n";
#define pr(x) cout<<x;
#define pr1(x) cout<<x<<" ";
#define pr2(x,y) cout<<x<<" "<<y;
#define deb printf("***************************************************************************************\n");
#define moshi printf("moshi moshi ! \n");
#define hi printf("hi ! \n");
#define bye printf("bye bye ! \n");
#define o_set(ll) tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
#define number_of_set_bits  __builtin_popcountll  
const ld PI=3.1415926535897932384626433; 

inline ll ceil(ll a,ll b)
{
   return (a+b-1)/b;
}

const ll N=2e5+5;
ll n,k,arr[N],inc[N],decr[N];

void func()
{ 
  cin>>n>>k;
  f(i,1,n+1) cin>>arr[i];


  f(i,1,k+1)
  {
    bool flag=1;
    f(j,1,n+1) if(arr[j]!=n) flag=0;
    if(flag) break;

    f(j,1,n+1)
    {
      ll l=max(1LL,j-arr[j]),r=min(n,j+arr[j]);
      inc[l]+=1;
      decr[r]+=1;
    }

    ll curr=0;
    f(j,1,n+1)
    {
      curr+=inc[j];
      arr[j]=curr;
      curr-=decr[j];
    }
    f(j,1,n+1) inc[j]=decr[j]=0;
  }

  f(i,1,n+1) pr1(arr[i])
  nl
}   

     
     
int main() 
{
    fast

    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif // ONLINE_JUDGE
        
     
    ll ntc=1;
    //cin>>ntc;
     
    f(i,1,ntc+1)
    {
      //cout<<"Case #"<<i<<": ";
      func();
    }     
    return 0;
}

Measured memory_bytes: 8336
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<set>
#include<climits>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)

using namespace std;

typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;


template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
	return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T& t, const V& v) { t = v; }
template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T& t, const V& v) {
	for (auto& e : t) fill_v(e, v);
}


#define ARRAY_MAX 100005
const int INF = INT32_MAX / 3;
const ll MOD = 1e9 + 7;

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


/******************************************************************************************/


vector<int> G[30];
int st = 0;
int check[30];
int cnt[30];

void dfs(int now) {

	
	check[now] = 1;
	
	for (auto itr : G[now]) {

		if (check[itr] == 1)continue;
		dfs(itr);
	}
}



int main() {

	int n;
	while (cin >> n, n) {

		bool ok = true;
		for (int i = 0; i < n; i++)
		{
			string s;
			cin >> s;
			G[s[0] - 'a'].push_back(s.back() - 'a');
			cnt[s[0] - 'a']++;
			cnt[s.back() - 'a']--;
		}

		//入次数，出次数のチェック
		for (int i = 0; i < 26; i++)
		{
			if (cnt[i] != 0) {
				ok = false;
				break;
			}
		}
		
		for (int i = 0; i < 26; i++) {
			if (G[i].size() > 0) {
				dfs(i);
				break;
			}
		}
		

		for (int i = 0; i < 26; i++) {
			if (G[i].size() > 0 && !check[i]) {
				ok = false;
			}
		}

		if (ok) {
			cout << "OK" << endl;
		}
		else
		{
			cout << "NG" << endl;
		}

		
		for (int i = 0; i < 30; i++)
		{
			cnt[i] = 0;
			check[i] = 0;
			G[i].clear();
		}
	}

	


	return 0;
}



Measured memory_bytes: 3180
#include <iostream>
#include <vector>
#define ll long long
using namespace std;

bool work[1010], lp[1010], pos_lp[1010];
void dfs(int now, vector<vector<int>> &G, vector<vector<ll>> &C, vector<ll> &X){
    work[now]=1;
    for(int i=0; i<G[now].size(); ++i){
        if(work[G[now][i]]){
            lp[now]=1;
            if(X[G[now][i]]<X[now]+C[now][i]) pos_lp[now]=1;
        }
        X[G[now][i]]=max(X[G[now][i]], X[now]+C[now][i]);
    }
    for(int i=0; i<G[now].size(); ++i){
        if(!lp[G[now][i]]){
            lp[G[now][i]] |= lp[now];
            pos_lp[G[now][i]] |= pos_lp[now];
            dfs(G[now][i], G, C, X);
        }
    }
    work[now]=0;
}

int main() {
	int N, M;
	cin >> N >> M;
	vector<vector<int>> g(N+1);
	vector<vector<ll>> cost(N+1);
	for(int i=0; i<M; ++i){
	    int a, b;
	    ll c;
	    cin >> a >> b >> c;
	    g[a].push_back(b);
	    cost[a].push_back(c);
	}
	vector<ll> mx(N+1, -1e14);
	mx[1]=0;
	dfs(1, g, cost, mx);
	if(pos_lp[N]) cout << "inf" << endl;
	else cout << mx[N] << endl;
	return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define pi acos(-1.0)


int main()
{

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    double t,m1,d1,m2,d2;
    cin>>t;

   m1=ceil(t/1.08);
   if(floor(m1*1.08)==t)
      cout<<m1<<endl;
   else
      cout<<":("<<endl;



    return 0;
}



Measured memory_bytes: 764
#include<stdio.h>
int main(){
  int H,W,h,w,i=1,j;
  scanf("%d%d%d%d",&H,&W,&h,&w);
  if(H%h||W%w) for(puts("Yes");i<=H;++i,puts("")) for(j=0;j<W;++j,printf("%d ",(i%h||j%w)?999:-999*(h*w-1)-1));
  else puts("No");
  return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i <(n); ++i)
#define REP2(i,x,n) for (int i = x; i <(n); ++i)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using P = pair<int,int>;
static const double PI = acos(-1);
static const int INF = 1e9+7;
#define REP(i,n) for (int i = 0; i <(n); ++i)
//debug 
#ifdef _DEBUG
#define debug(var)  do{cout << #var << " :";view(var);}while(0)
#else
#define debug(...)
#endif
template<typename T> void view(T e){cout << e << endl;}
template<typename T> void view(const vector<T>& v){for(const auto& e : v){ cout << e << " "; } cout << endl;}
template<typename T> void view(const vector<vector<T> >& vv){ for(const auto& v : vv){ view(v); } }


int main(){
  int n;
  cin >> n;
  vector<int> l(n);
  REP(i,n) cin >> l[i];
  debug(l);
  sort(ALL(l));
  ll cnt = 0;
  REP(i,n-2){
    REP2(j,i+1,n-1){
      REP2(k,j+1,n){
        if(l[i]==l[j] || l[j] == l[k] || l[k] == l[i]) continue;
        ll sum = (ll)l[i]+l[j]+l[k];
        int maxl = max({l[i],l[j],l[k]});
        if(maxl < (ll)sum - maxl) cnt++;
      }
    }    
  }
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
using namespace std;

inline int toInt(string s) {
	int v;
	istringstream sin(s);
	sin >> v;
	return v;
}

vector<int> split(const string &str, char delim) {
	vector<int> res;
	string::size_type current = 0, found;
	while((found = str.find_first_of(delim, current)) != string::npos){
		res.push_back(toInt(string(str, current, found - current)));
		current = found + 1;
	}
	res.push_back(toInt(string(str, current, str.size() - current)));
	return res;
}

int main () {
	vector<int> pre;
	for (int i = 0; ; i++) {
		string line;
		getline(cin, line);
		vector<int> nums = split(line, ',');
		if (i != 0) {
			for (unsigned i = 0; i < nums.size(); i++) {
				if (pre.size() < nums.size()) {
					if (i == 0) nums[i] += pre[0];
					else if (i == pre.size()) nums[i] += pre[pre.size() - 1];
					else nums[i] += max(pre[i - 1], pre[i]);
				}
				else {
					nums[i] += max(pre[i], pre[i + 1]);
				}
			}
			if (nums.size() == 1) {
				cout << nums[0] << endl;
				break;
			}
		}
		pre = nums;
	}
	return 0;
}

Measured memory_bytes: 1244