akhauriyash/Code-Regression huggingface dataset:
while true
	count=0
	args = gets.split(" ").map{|e|e.to_i}
	break if args[0] == 0 && args[1] == 0
	(args[0]-2).times{|t1|
		t1+=1
		(args[0]-t1).times{|t2|
			t2+=t1+1
			(args[0]-t2).times{|t3|
				t3+=t2+1
				count+=1 if args[1]==t1+t2+t3
			}
		}
	}
	p count
end

Measured memory_bytes: 6116
#include <iostream>
#include <algorithm>
#include <vector>
#define rep(i,n) for(int i = 0; i<(n); ++i)
using namespace std;

int main(){
    int n; cin >> n;
    vector<int> a(n);

    rep(i,n) cin >> a[i];

    sort(a.begin(), a.end());

    cout << a[n-1] - a[0] << endl;

    return 0;
}

Measured memory_bytes: 3592
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b)  for(int i=(a),i##formax=(b);i< i##formax;i++)
#define FORR(i,a,b) for(int i=(a),i##formin=(b);i>=i##formin;i--)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define pcnt __builtin_popcount
#define sz(x) (int)(x).size()
#define maxs(x,y) x=max((x),(y))
#define mins(x,y) x=min((x),(y))
#define show(x) cout<<#x<<" = "<<(x)<<endl;
#define all(a) ((a).begin()),((a).end())
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define bit(n) (1LL<<(n))
typedef long long ll;
typedef __int128_t lll;
template<class T>using V=vector<T>;
template<class T>using VV=V<V<T>>;
template<class T,class Y>using P=pair<T,Y>;
template<class T,class Y>ostream& operator<<(ostream&o,P<T,Y>&p){return o<<"("<<p.fi<<","<<p.se<<")";}
template<class T>ostream& operator<<(ostream&o,V<T>&v){for(T&t:v)o<<t<<",";return o;}
template<class T>void uniq(V<T>&v){sort(all(v));v.erase(unique(all(v)), v.end());}
template<class A,size_t N,class T>void Fill(A(&a)[N],const T&v){fill((T*)a,(T*)(a+N),v);}

const int MOD = 1e9+7; //998244353;

lll gcd(lll a,lll b,lll&x,lll&y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll modInv(ll a,ll m=MOD){lll x,y;gcd(a,m,x,y);return(x%m+m)%m;}
ll modPow(lll a,lll n,ll m=MOD){lll p=1;for(;n;n>>=1,a=a*a%m)if(n&1)p=p*a%m;return p;}
//V<ll>Fac,Rac;void setF(int n,int m=MOD){Fac=Rac=V<ll>(++n);Fac[0]=1;FOR(i,1,n)Fac[i]=Fac[i-1]*i%m;Rac[n-1]=modInv(Fac[n-1],m);FORR(i,n-1,1)Rac[i-1]=Rac[i]*i%m;}
//ll comb(int a,int b,int m=MOD){return a<b||b<0?0:Fac[a]*Rac[b]%m*Rac[a-b]%m;}

const int IINF = 1e9+6;
const ll LINF = 1e18;
int n, q;
string s;
struct Seg{
  typedef int T;
  const T e = 0;
  void merge(const T &a, const T &b, T &c){
    c = a|b;
  }

  int n;
  vector<T> d;

  void init(int m){
    n = 1<<(32-__builtin_clz(m-1));
    d = vector<T>(2*n, e);
  }
  void init(vector<T> &v){
    init(v.size());
    FOR(j, 0, v.size()) d[j+n] = v[j];
    for(int k=n-1;k>0;k--) merge(d[k*2], d[k*2+1], d[k]);
  }
  void update(int k, T a){
    k+=n;
    d[k]=a;
    while(k){
      k >>= 1;
      merge(d[k*2], d[k*2+1], d[k]);
    }
  }
  T query(int L, int R) {
    L += n; R += n;
    T l=e, r=e;
    while (L < R) {
      if (L & 1) merge(l, d[L++], l);
      if (R & 1) merge(d[--R], r, r);
      L >>= 1; R >>= 1;
    }
    merge(l, r, l);
    return l;
  }
  T get(int a){
    return d[n+a];
  }
} seg;

main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n >> s >> q;
  {
    V<int> v;
    FOR(i, 0, n) v.pb(bit(s[i]-'a'));
    seg.init(v);
  }
  FOR(_, 0, q){
    int t, a, b;
    char c;
    cin >> t;
    if(t==1){
      cin >> a >> c;
      seg.update(a-1, bit(c-'a'));
    }else{
      cin >> a >> b;
      cout << pcnt(seg.query(a-1, b)) << endl;
    }
  }
}

Measured memory_bytes: 10140
N, M = map(int, raw_input().split())
a = [0]*N
b = [0]*N
for i in range(N):
  a[i], b[i] = map(int, raw_input().split())
c = [0]*M
d = [0]*M
for i in range(M):
  c[i], d[i] = map(int, raw_input().split())

for i in range(N):
  ans = -1
  for j in range(M):
    if ans==-1 or abs(a[i]-c[j])+abs(b[i]-d[j]) < abs(a[i]-c[ans])+abs(b[i]-d[ans]):
      ans = j
  print ans+1


Measured memory_bytes: 2692
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<vector>
#include<list>
#include<algorithm>
#include<math.h>
#include<map>
#include<iomanip>
#include<functional>
#include<limits>
#include <unordered_map>
#include <numeric>
#include <array>
#include <queue>
#include <chrono>
#include <random>
#include <fstream>


using namespace std;
using  ull = unsigned long long int;

#define rep(i,n,m) for(long long int i=n;i<(long long int)(m);i++)
#define INF (1<<29)
#define MD 1000000007

int main() {
	
	int n, m, x,tmp;
	cin >> n >> m >> x;
	vector<int>root(n+1,0);
	rep(i, 0, m) {
		cin >> tmp;
		root[tmp] = 1;
	}

	int begin = std::accumulate(root.begin(), root.begin()+x, 0);
	int end = std::accumulate(root.begin()+x, root.end(), 0);
	cout << min(begin, end) << endl;

	return 0;
}


Measured memory_bytes: 256
# import math
# import itertools
# from collections import deque
# from collections import defaultdict
# import heapq
import sys
# import numpy as np
# from scipy.special import comb

sys.setrecursionlimit(100000)
INF = 100100100

N = int(input())
memo = [-1] * (N + 1)
memo[0] = 0


def f(n):

    # 0なら終了
    if n == 0:
        return 0

    # メモされてたら終了
    if not memo[n] == -1:
        return memo[n]

    ans = INF

    # 9
    for i in range(1, n):
        if 9 ** i > n:
            break
        ans = min(ans, f(n - 9**i) + 1)

    # 6
    for i in range(1, n):
        if 6 ** i > n:
            break
        ans = min(ans, f(n - 6**i) + 1)

    # 1
    ans = min(ans, f(n - 1) + 1)

    # メモ
    memo[n] = ans
    return ans


def main():

    print(f(N))


if __name__ == '__main__':
    main()


Measured memory_bytes: 13812
/**
    C   -   Five Transportations	C++14 (Clang 3.8.0)
	Accepted
5
3
2
4
3
5
**/
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
using namespace std;

int main(){
    vector<long long> num(5);
    long long N;
    long long time = 0;
    cin >> N;
    for(int i = 0 ; i < 5 ; i++){
        cin >> num[i];
    }
    long long min = *std::min_element(num.begin(), num.end());
    if (min >= N){cout << 5 << endl; return 0;}
    time += N / min;
    if (N % min > 0) time++;
    time += 4;
    cout << time << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int n,i,d[200010];
  long long s=0;
  scanf("%d",&n);
  for(i=0;i<n;i++)scanf("%d",&d[i]);
  d[n]=0;
  if(d[0])goto END;
  for(i=n;i--;){
    if(d[i]&&d[i-1]+1<d[i])goto END;
    if(d[i]>=d[i+1])s+=d[i];
  }
  printf("%lld\n",s);
  return 0;
 END:;
  printf("-1\n");
  return 0;
}


Measured memory_bytes: 896
import java.util.Scanner;

class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int H = sc.nextInt(), W = sc.nextInt(), N = sc.nextInt();
		int[] A = new int[N];
		for(int i = 0; i < N; i++) A[i] = sc.nextInt();
		int[][] ans = new int[H][W];
		int i = 0, j = 0;
		for(int c = 0; c < N; c++) {
			// いろ c をぬる
			while(A[c] > 0) {
				ans[i][j] = c + 1;
				A[c]--;
				j += (i % 2 == 0) ? 1 : -1;
				if(j < 0) {
					i++; j = 0;
				}else if(j >= W){
					i++; j = W - 1;
				}
			}
		}
		for(i = 0; i < H; i++) {
			System.out.print(ans[i][0]);
			for(j = 1; j < W; j++) {
				System.out.print(" "+ans[i][j]);
			}
			System.out.println();
		}
	}
}

Measured memory_bytes: 33296
#include <iostream>
#include <bitset>
#include <fstream>
#include <string>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <functional>
#include <cctype>
#include <list>
#include <limits>
//#include <boost/multiprecision/cpp_int.hpp>

const double EPS = (1e-10);


using namespace std;
using Int = long long;
//using namespace boost::multiprecision;

const Int MOD = 1000000007;

Int mod_pow(Int x, Int n) {
    Int res = 1;
    while(n > 0) {
        if(n & 1) res = (res * x) % MOD; //ビット演算(最下位ビットが1のとき)
        x = (x * x) % MOD;
        n >>= 1; //右シフト(n = n >> 1)
    }
    return res;
}

template<typename T>
T gcd(T a, T b) {
    return b != 0 ? gcd(b, a % b) : a;
}

template<typename T>
T lcm(T a, T b) {
    return a * b / gcd(a, b);
}


int N;
int A[5];
int l[10];

int calc(int s){
    int take[4] = {0};
    int ans = 0;
    for (int i = 0; i < N; i++){
        if (s%4 != 0 && take[s%4] > 0) ans += 10;
        take[s%4] += l[i];
        s /= 4;
    }
    for (int i = 1; i <= 3; i++){
        if (take[i] == 0) return 1000000000;
        ans += abs(take[i] - A[i]);
    }
    return ans;
}


int main(){
    cin.tie(0);
    cin >> N >> A[1] >> A[2] >> A[3];
    for (int i = 0; i < N; i++){
        cin >> l[i];
    }
    int ans = 1000000000;
    for (int i = 0; i < mod_pow(4, N); i++){
        ans = min(ans, calc(i));
    }
    cout << ans << endl;
}


Measured memory_bytes: 888
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10**9)
INF = 10**9
mod = 10**9+7

def cmb(n,k,p):
    x,y = 1,1
    for i in range(k):
        x=x*(n-i)%p
        y=y*(i+1)%p
    return x*pow(y,p-2,p)%p

s = i()
s -= 3
ans = 0
if s >= 0:
    ans += 1
for i in range(1,10000):
    s -= 3
    if s < 0:
        break
    ans += cmb(s+i,i,mod)
print(ans%mod)

Measured memory_bytes: 72748
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using data = pair<int, pair<int, int>>;
template<class T, class U> inline bool chmax(T& a,U b) { if (a < b) { a = b; return 1; } return 0; }
template<class T, class U> inline bool chmin(T& a,U b) { if (a > b) { a = b; return 1; } return 0; }


int main() {
    int n;
    cin >> n;
    vector<data> a;
    for (int i = 0; i < n; i++) {
        int x, b, c;
        cin >> x >> b >> c;
        a.emplace_back(x, make_pair(b, c));
    }
    
    bool ans = true;
    int h = 0, w = 0, time = 0;
    for (int i = 0; i < n; i++) {
        int dt = abs(time - a[i].first);
        int dist = abs(h - a[i].second.first) + abs(w - a[i].second.second);
        if (dt < dist || dist % 2 != dt % 2) ans = false;
        tie(h, w) = a[i].second; time = a[i].first;
    }
    
    cout << ((ans) ? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 1912
#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;
template<typename T> using gpp_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T, typename L> using gpp_map = tree<T, L, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T> using gpp_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;*/
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define all(v) v.begin(),v.end()
#define SZ(v) ((int)v.size())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)
#define bit(n) (1LL<<(n))
#define bit_exist(x, n) ((x >> n) & 1)
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) cout << #v << "=" << endl; REP(i_debug, v.size()){ cout << v[i_debug] << ","; } cout << endl;
#define mdebug(m) cout << #m << "=" << endl; REP(i_debug, m.size()){ REP(j_debug, m[i_debug].size()){ cout << m[i_debug][j_debug] << ","; } cout << endl;}
#define pb push_back
#define f first
#define s second
#define int long long
#define INF 1000000000000000000
template<typename T> istream &operator>>(istream &is, vector<T> &v){ for (auto &x : v) is >> x; return is; }
template<typename T> ostream &operator<<(ostream &os, vector<T> &v){ for(int i = 0; i < v.size(); i++) { cout << v[i]; if(i != v.size() - 1) cout << endl; }; return os; }
template<typename T> void Out(T x) { cout << x << endl; }
template<typename T1, typename T2> void Ans(bool f, T1 y, T2 n) { if(f) Out(y); else Out(n); }

using vec = vector<int>;
using mat = vector<vec>;
using Pii = pair<int, int>;
using PiP = pair<int, Pii>;
using PPi = pair<Pii, int>;
using bools = vector<bool>;
using pairs = vector<Pii>;

//int dx[4] = {1,0,-1,0};
//int dy[4] = {0,1,0,-1};
//char d[4] = {'D','R','U','L'};

const int mod = 1000000007;
//const int mod = 998244353;
//#define Add(x, y) x = (x + (y)) % mod
//#define Mult(x, y) x = (x * (y)) % mod



signed main(){

    int N, K, M; cin >> N >> K >> M;

    mat POW(N + 2, vec(N + 1, 0));
    REP(i, N + 2){
        POW[i][0] = 1;
        FOR(j, 1, N + 1) POW[i][j] = (POW[i][j - 1] * i) % M;
    }

    mat dp1(N + 1, vec(N + 1, 0));
    REP(j, N + 1) dp1[0][j] = 1;
    REP(i, N) REP(j, N + 1) FOR(j2, j, N + 1){
        (dp1[i + 1][j2] += dp1[i][j] * POW[i + 2][j2 - j]) %= M;
    }

    mat dp2(K + 1, vec(N + 1, 0));
    dp2[0][0] = 1;
    REP(i, K) REP(j, N + 1) FOR(j2, j, N + 1){
        (dp2[i + 1][j2] += dp2[i][j] * dp1[j][j2 - j]) %= M;
    }
    Out(dp2[K][N]);

    return 0;
}


Measured memory_bytes: 2432
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(k,i,n) for(ll i=k;i<n;++i)
int main(void){
    // Your code here!
    ll n,a,b;
    cin>>n>>a>>b;
    string s;
    cin>>s;
    bool t[n];
    rep(0,i,n)t[i]=false;
    ll c0=0,c1=0;
    rep(0,i,n){
        string s0=s.substr(i,1);
        if(s0=="a"&& c0<a+b){
            ++c0;
            t[i]=true;
        }else if(s0=="b" && c0<a+b && c1<b){
            ++c1,++c0;
            t[i]=true;
        }
    }
    rep(0,i,n){
        if(t[i])cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }
}

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

using namespace std;

int main()
{
  int N, M, P;
  while(cin >> N >> M >> P, N || M || P){
    int x = 0, y;
    for(int i = 0; i < N; i++){
      int X;
      cin >> X;
      x += X;
      if(i+1 == M) y = X;
    }
    if(y == 0) cout << 0 << endl;
    else cout << x  * (100 - P) / y << endl;
  }
  return 0;
}

Measured memory_bytes: 1160
import java.util.*;

public class Main {

  public static void main (String[] args) {

    Scanner sc = new Scanner(System.in);

    int A = sc.nextInt();
    int B = sc.nextInt();
    int C = sc.nextInt();
    int D = sc.nextInt();
    int E = sc.nextInt();

    sc.close();

    int[][] array = new int[5][3];

    array[0][0] = A;
    array[1][0] = B;
    array[2][0] = C;
    array[3][0] = D;
    array[4][0] = E;
    if (A % 10 != 0) {
      array[0][1] = A % 10;
      array[0][2] = A + (10 - A % 10);
    } else {
      array[0][1] = 10;
      array[0][2] = A;
    }
    if (B % 10 != 0) {
      array[1][1] = B % 10;
      array[1][2] = B + (10 - B % 10);
    } else {
      array[1][1] = 10;
      array[1][2] = B;
    }
    if (C % 10 != 0) {
      array[2][1] = C % 10;
      array[2][2] = C + (10 - C % 10);
    } else {
      array[2][1] = 10;
      array[2][2] = C;
    }
    if (D % 10 != 0) {
      array[3][1] = D % 10;
      array[3][2] = D + (10 - D % 10);
    } else {
      array[3][1] = 10;
      array[3][2] = D;
    }
    if (E % 10 != 0) {
      array[4][1] = E % 10;
      array[4][2] = E + (10 - E % 10);
    } else {
      array[4][1] = 10;
      array[4][2] = E;
    }

    Arrays.sort(array, (a,b) -> Integer.compare(b[1],a[1]));

    int sum = 0;

    for (int i = 0; i < 5; i++) {
      if (i == 4) {
        sum += array[i][0];
      } else {
        sum += array[i][2];
      }
    }

    System.out.println(sum);

  }

}

Measured memory_bytes: 26704
# -*- coding: utf-8 -*-

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

N, a, b, c = MAP()
C = {0: a, 1: b, 2: c}
S = []
for i in range(N):
    s = input()
    c1, c2 = s
    S.append((ord(c1)-65, ord(c2)-65))

ans = []
for i in range(N-1):
    cur1, cur2 = S[i]
    if C[cur1] == C[cur2] == 0:
        No()
        exit()
    elif C[cur1] == 0:
        ans.append(cur1)
        C[cur1] += 1
        C[cur2] -= 1
    elif C[cur2] == 0:
        ans.append(cur2)
        C[cur2] += 1
        C[cur1] -= 1
    elif C[cur1] == C[cur2] == 1 and C[3-cur1-cur2] == 0:
        if cur1 in S[i+1] and 3-cur1-cur2 in S[i+1]:
            ans.append(cur1)
            C[cur1] += 1
            C[cur2] -= 1
        else:
            ans.append(cur2)
            C[cur2] += 1
            C[cur1] -= 1
    elif C[cur1] <= C[cur2]:
        ans.append(cur1)
        C[cur1] += 1
        C[cur2] -= 1
    else:
        ans.append(cur2)
        C[cur2] += 1
        C[cur1] -= 1
cur1, cur2 = S[-1]
if C[cur1] == C[cur2] == 0:
    No()
    exit()
elif C[cur1] == 0:
    ans.append(cur1)
    C[cur1] += 1
    C[cur2] -= 1
else:
    ans.append(cur2)
    C[cur2] += 1
    C[cur1] -= 1
Yes()
for i in range(N):
    print(chr(ans[i]+65))


Measured memory_bytes: 16872
#include <bits/stdc++.h>
using namespace std;  
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
 
 
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define ll long long
#define ull unsigned long long
#define F first
#define S second
 
const int MOD = 1e9 + 7; 
const int N = 1e5; 
const int INF = 1e9 + 5; 


int main(void) 
{

	#ifndef ONLINE_JUDGE
//	freopen("input.txt", "r", stdin);
	#endif

	int a, b, c; 
	scanf("%d %d %d", &a, &b, &c); 
	swap(a, b); 
	swap(a, c); 
	printf("%d %d %d\n", a,b,c); 



	return false; 
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
int n;
ll a[100005];
vector<int>edge[100005];
bool flag = true;
ll dfs(int v,int u,int d){
	if(edge[v].size() == 1) return a[v];
	ll cnt = 0,mx = 0;
	rep(i,edge[v].size()){
		if(edge[v][i]==u) continue;
		ll A = dfs(edge[v][i],v,d+1);
		cnt += A;
		mx = max(mx,A);
	}
	ll pr = 0;
	if(mx*2 > cnt){
		pr = cnt-mx;
	}
	else{
		pr = cnt/2;
	}
	if(d == 0){
	    if(pr*2 != cnt || a[v] != pr) flag = false;
	}
	else{
	    if(cnt-pr<=a[v] && a[v]<=cnt);
	    else flag = false;
	}
	return cnt-(cnt-a[v])*2LL;
}
int main(){
	cin>>n;
	repn(i,n)cin>>a[i];
	rep(i,n-1){
		int a,b; cin>>a>>b;
		edge[a].pb(b);
		edge[b].pb(a);
	}
	if(n == 2){
	    puts(a[1]!=a[2]?"NO":"YES");
	    return 0;
	}
	int v = -1;
	repn(i,n){
		if(edge[i].size()>=2){
			v = i;
			break;
		}
	}
	dfs(v,-1,0);
	puts(!flag?"NO":"YES");
}

Measured memory_bytes: 14464
#include <bits/stdc++.h>
#define INF 1e9
using namespace std;

#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(a)  (a).begin(),(a).end()

template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}
typedef long long ll;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b) {
    return a/gcd(a,b)*b;
}


int main() {
    ll A,B;
    cin >> A >> B;
    cout << lcm(A,B) << endl;

    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

constexpr int MOD = 1000000007;

typedef long long LL;
typedef pair<int, int> P;
typedef pair<LL, LL> PLL;

int N;
int a[201010];

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

    cin >> N;
    for (int j = 0; j < 2*N-1; ++j) {
        cin >> a[j];
    }

    int low = 1, high = 2*N-1;

    while (low + 1 < high) {
        int mid = (low + high) / 2;

        int b[201010];
        for (int j = 0; j < 2*N-1; ++j) {
            b[j] = a[j] < mid ? 0 : 1;
        }

        int result;

        int l = N-1;
        while (l > 0) {
            if (b[l-1] == b[l]) { break; }
            --l;
        }

        int r = N-1;
        while (r < 2*N-2) {
            if (b[r] == b[r+1]) { break; }
            ++r;
        }

        if (b[l] == b[r]) {
            result = b[l];
        } else {
            if (N-1-l < r-N+1) {
                result = b[l];
            } else {
                result = b[r];
            }
        }

        if (result == 1) {
            low = mid;
        } else {
            high = mid;
        }
    }

    cout << low << endl;

    return 0;
}


Measured memory_bytes: 1920
#include<iostream>
using namespace std;
int main(){
int t;
cin>>t;
int ar1[t],ar2[t];

for(int i=0;i<t;i++)
        cin>>ar1[i]>>ar2[i];
        int c=0;
   for(int i=2;i<t;i++){
    if(ar1[i]==ar2[i]&&ar1[i-1]==ar2[i-1]&&ar1[i-2]==ar2[i-2]){
       {c++;
        break;}
   }
}
if(c==1)
    cout<<"Yes";
    else
        cout<<"No";


}


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

using namespace std;
using ll = long long;
#define rep(i, n) for(ll i = 0; i < (ll)(n); ++i)
#define REP(i, n) for(ll i = n-1; i >= 0; i--)
#define all(x) (x).begin(),(x).end()
#define debug(x) cerr << #x << " = " << x << endl
#define mp make_pair
#define pb push_back

const long long MOD = 1000000007;
const long long INF = 1LL<<60;


int main(){
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    cout << fixed << setprecision(12);

    ll n, m;
    cin >> n >> m;
    vector<ll> h(n);
    vector<ll> mask(n, 0);
    rep(i, n){
        cin >> h[i];
    }
    ll a, b;
    vector<vector<ll>> ma(n, vector<ll>());
    rep(i, m){
        cin >> a >> b;
        a--;
        b--;
        ma[a].pb(b);
        ma[b].pb(a);
        if(h[a]==h[b]){
            mask[a]++;
            mask[b]++;
        }
    }
//    for(auto mm: ma){
//        for(auto l : mm){
//            cerr << l << " ";
//        }
//        cerr << endl;
//    }

    vector<pair<ll,ll>> hs;
    rep(i, n){
        hs.pb(mp(h[i], i));
    }
    sort(all(hs));

    ll count = 0;
    for(ll i = n-1; i >= 0; i--){
//        debug(hs[i].first);
//        debug(hs[i].second);
        if(mask[hs[i].second]==0){
//            cerr << hs[i].second << endl;
            count++;
        }
        for(auto e: ma[hs[i].second]){
            mask[e]++;
        }
//        for(auto c: mask){
//            cerr << c << " ";
//        }
//        cerr << endl;
    }

    cout << count << endl;

    return 0;
}


Measured memory_bytes: 12736
import itertools
import math
N = int(input())
x = [[int(x) for x in input().split()] for _ in range(N)]
p = itertools.permutations([x for x in range(N)])
d = 0
cnt = 0
for seq in p:
    cnt+=1
    for i in range(1,N):
        d += math.sqrt((x[seq[i-1]][0] - x[seq[i]][0])**2 + (x[seq[i-1]][1] - x[seq[i]][1])**2) 
print(d/cnt)

Measured memory_bytes: 40556
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long ll;

const int N=510;
int n,prm[N*2];
ll a[N][N];

struct node
{
	int dat,prm;
}b[N*2];

bool cmp(node x,node y)
{
	return x.dat<y.dat;
}

void findprm(int k)
{
	for (int i=2,m=0;m<k;i++)
	{
		bool flag=1;
		for (int j=2;j*j<=i;j++)
			if (i%j==0) flag=0;
		if (flag) prm[++m]=i;
	}
}

ll query(int x,int y,int opt)
{
	if (opt==1) return b[(x+y)/2].prm;
		else return b[(n+x-y+1)/2+n].prm;
}

int main()
{
	scanf("%d",&n);
	if (n==2) return !printf("4 7\n23 10");
	findprm(2*n);
	for (int i=1;i<=2*n;i++)
	{
		if (i<=n) b[i].dat=i*2-1;
			else b[i].dat=(2*n-i)*2;
		b[i].prm=prm[i];
	}
	sort(b+1,b+1+2*n,cmp);
	for (int i=1;i<=n;i++,putchar(10))
		for (int j=1;j<=n;j++)
			if ((i+j)&1)
				printf("%lld ",query(i,j,1)*query(i,j,2));
			else 	
			{
				if (1<i && i<n)
					printf("%lld ",query(i-1,j,1)*query(i-1,j,2)*query(i+1,j,1)*query(i+1,j,2)+1);
				else if (1<j && j<n)
					printf("%lld ",query(i,j-1,1)*query(i,j-1,2)*query(i,j+1,1)*query(i,j+1,2)+1);
				else if (i==1 && j==1)
					printf("%lld ",query(i,j+1,1)*query(i,j+1,2)*query(i+1,j,2)+1);
				else if (i==1 && j==n)
					printf("%lld ",query(i,j-1,1)*query(i,j-1,2)*query(i+1,j,1)+1);
				else if (i==n && j==1)
					printf("%lld ",query(i,j+1,1)*query(i,j+1,2)*query(i-1,j,1)+1);
				else if (i==n && j==n)
					printf("%lld ",query(i,j-1,1)*query(i,j-1,2)*query(i-1,j,2)+1);
				else puts("WYC AK IOI!!!!!");
			}
	return 0;
}

Measured memory_bytes: 3072
//

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const ll MOD = 1e9 + 7;

int main() {
	ll N;
	cin >> N;
	N;
	string ans = "";
	bool carry = false;
	while(1) {
		int k = N % 26;
		char c;
		if (k == 0) {
			carry = true;
			c = 'z';
		} else {
			c = 'a' + k - 1;
		}

		ans = c + ans;
		N /= 26;

		if (carry) {
			N--;
			carry = false;
		}

		if (N == 0) break;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3628
N, K, S = map(int, input().split())

ans = []
if S != 10**9:
  for i in range(K):
    ans.append(S)
  for i in range(N-K):
    ans.append(S+1)
else:
  for i in range(K):
    ans.append(S)
  for i in range(N-K):
    ans.append(1)
print(*ans)

Measured memory_bytes: 13792
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

template<class T>
vector<vector<T>> ScanVectors(size_t all_size, size_t vec_size) {
  vector<vector<T>> vectors(all_size);
  for (size_t i = 0; i < all_size; i++) {
    for (size_t j = 0; j < vec_size; j++) {
      T in; cin >> in; vectors[j].emplace_back(in);
    }
  }
  return vectors;
}

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

int main() {
  size_t H, N;
  cin >> H >> N;

  auto A = ScanVectors<size_t>(N, 1)[0];
  size_t sum = 0;
  for (const auto a : A) {
    sum += a;
  }

  if (H > sum) {
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
  }

}


Measured memory_bytes: 4340
// OURL: https://atcoder.jp/contests/abc123/tasks/abc123_a
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i,n) for(int i=0,i##_len=(n);i<i##_len;++i)
#define RREP(i,a,n) for(int i=(a),i##_len=(n);i<i##_len;++i)
#define MAT1D(V,T,a) vector<T> V (a)
#define MAT2D(V,T,a,b) vector<vector<T>> V (a, vector<T>(b))
#define MAT3D(V,T,a,b,c) vector<vector<vector<T>>> V (a, vector<vector<T>>(b, vector<T>(c)))

// http://beet-aizu.hatenablog.com/entry/2018/04/08/145516
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); }

string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string) s); }
string to_string(bool b) { return (b ? "true" : "false"); }
string to_string(vector<bool>::reference b) { return to_string(bool(b)); }
template <typename A, typename B>
string to_string(pair<A, B> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; }
template <typename A>
string to_string(A v) { bool first = true; string res = "{"; for (const auto &x : v) { if (!first) { res += ", "; } first = false; res += to_string(x); } res += "}"; return res; }
template <typename A>
string to_string(vector<vector<A>> v) { string res; for(const auto &x : v) {res+="\n ";res += to_string(x);} return res;}

void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) { cerr << " " << to_string(H); debug_out(T...); }

#ifdef LOCAL
#define debug(...) cerr << "[L" << to_string(__LINE__) << ":" <<#__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int k;
  auto as = make_v<int>(5);
  REP(i,5) {
    cin >> as[i];
  }
  cin >> k;
  sort(as.begin(), as.end());
  if (as.back() - as.front() > k) {
    cout << ":(" << endl;
  } else {
    cout << "Yay!" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-

r, c = list(map(int, input().split()))
a = []
line_sum = 0

for i in range(r):
    a.append(list(map(int, input().split())))

for i in range(r):
    for j in range(c + 1):
        if j == c:
            print('{0}'.format(sum(a[i])))
            line_sum += sum(a[i])
        else:
            print('{0} '.format(a[i][j]), end='')

for i in range(c):
    column_sum = 0
    for j in range(r):
        column_sum += a[j][i]

    print('{0} '.format(column_sum), end='')

print(line_sum)


Measured memory_bytes: 6264
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <memory.h>
#include <iomanip>
#include <bitset>
#include <list>
#include <stack>
#include <deque>
#include <numeric>

using namespace std;

#define mod 1000000007

int main()
{
	long long int l, r;
	cin >> l >> r;
	if(r - l >= 2500) cout << 0 << endl;
	else {
		long long int ans = mod;
		for(long long int i = l; i <= r; i++){
			for(long long int j = i + 1; j <= r; j++){
				ans = min(ans, (i * j) % 2019);
			}
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
// iostream is too mainstream
#include <cstdio>
// bitch please
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <cmath>
#include <iomanip>
#include <time.h>
#define dibs reserve
#define OVER9000 1234567890
#define ALL_THE(CAKE,LIE) for(auto LIE =CAKE.begin(); LIE != CAKE.end(); LIE++)
#define tisic 47
#define soclose 1e-8
#define chocolate win
// so much chocolate
#define patkan 9
#define ff first
#define ss second
#define abs(x) (((x) < 0)?-(x):(x))
#define uint unsigned int
#define dbl long double
#define pi 3.14159265358979323846
using namespace std;
// mylittledoge

using cat = long long;

#ifdef DONLINE_JUDGE
	// palindromic tree is better than splay tree!
	#define lld I64d
#endif

cat W[10][10];

void upd(int a, int b, cat hint = 1) {
	int P[10];
	for(int i = 0; i < 10; i++) P[i] = i;
	vector<cat> sum_c, sum_l;
	while(true) {
		if(P[0] < P[9]) {
			cat s = 0;
			int l = 0;
			for(int i = 0; i < 9; i++) {
				if(P[i] == a && P[i+1] == b) l++;
				else if(P[i] == b && P[i+1] == a) l++;
				else s += W[P[i]][P[i+1]];
			}
			if(l == 0) sum_c.push_back(s);
			else sum_l.push_back(s);
		}
		if(!next_permutation(P, P+10)) break;
	}
	sort(begin(sum_c), end(sum_c));
	sort(begin(sum_l), end(sum_l));
	vector<int> pos_c(sum_l.size(), 0);
	priority_queue< pair<cat, int>, vector< pair<cat, int> >, greater< pair<cat, int> > > q;
	for(int i = 0; i < (int)sum_l.size(); i++) {
		if(i > 0) pos_c[i] = pos_c[i-1];
		while(pos_c[i] < (int)sum_c.size() && sum_c[pos_c[i]] < sum_l[i]+hint) pos_c[i]++;
		if(pos_c[i] < (int)sum_c.size()) q.push({sum_c[pos_c[i]]-sum_l[i], i});
	}
	cat x = hint;
	while(!q.empty()) {
		pair<cat, int> p = q.top();
		if(x < p.ff) break;
		q.pop();
		while(true) {
			pos_c[p.ss]++;
			q.push({sum_c[pos_c[p.ss]]-sum_l[p.ss], p.ss});
			p = q.top();
			if(p.ff > x) break;
			q.pop();
		}
		x++;
	}
	if(q.empty()) return;
	cerr << x << " " << max(sum_c.back(), sum_l.back()+x)*1e-11 << endl;
	W[a][b] = W[b][a] = x;
}

int main() {
	cin.sync_with_stdio(0);
	cin.tie(0);
	cout << fixed << setprecision(10);
	int N;
	cin >> N;
	memset(W, 0, sizeof(cat)*100);
	int seq[11] = {1, 2};
	for(int i = 2; i <= 10; i++) seq[i] = seq[i-1]+seq[i-2]+1;
	cat prod = 1;
	int n = N-1;
	while(n > 0) {
		for(int i = 0; i < n; i++) W[i][n] = W[n][i] = prod * seq[i];
		prod *= seq[n];
		n--;
	}
	if(N == 10) {
		W[1][2] = W[2][1] = 3;         //upd(1, 2);
		W[0][1] = W[1][0] = 214;       //upd(0, 1);
		W[0][2] = W[2][0] = 95963;     //upd(0, 2, 50000);
		W[2][3] = W[3][2] = 1002019965;//upd(2, 3, 1002000000);
		W[1][3] = W[3][1] = 2004429048;//upd(1, 3, 2004000000);
		W[0][3] = W[3][0] = 4008331713;//upd(0, 3, 4008000000);
	}
	for(int i = 0; i < N; i++)
		for(int j = 0; j < N; j++) cout << W[i][j] << ((j+1 == N) ? "\n" : " ");
	return 0;
}

// look at my code
// my code is amazing


Measured memory_bytes: 256
import * as fs from 'fs';

const readString = (() => {
  const input = fs.readFileSync(0).toString();
  const words = input.split(/[ \n]/);
  let i = 0;
  return () => words[i++] || '';
})();
const readInt = () => parseInt(readString(), 10);
const readBigInt = () => BigInt(readString());

const gcd = (a: bigint, b: bigint) => {
  const _gcd = (a: bigint, b: bigint): bigint => {
    const q = a % b;
    return q === 0n ? b : _gcd(b, q);
  };
  return a > b ? _gcd(a, b) : _gcd(b, a);
};

const MOD = 1000000007;
const MOD_BIGINT = BigInt(MOD);
class ModBigInt {
  constructor(public v: bigint) {}

  static of(n: number | bigint) {
    return new ModBigInt(ModBigInt.toBigInt(n));
  }

  static toBigInt(other: number | bigint | ModBigInt) {
    if (typeof other === 'bigint') return other;
    if (typeof other === 'number') return BigInt(other);
    return other.v;
  }

  clone = () => new ModBigInt(this.v);
  plus = (other: number | bigint | ModBigInt) => {
    this.v = (this.v + ModBigInt.toBigInt(other)) % MOD_BIGINT;
    return this;
  };
  minus = (other: number | bigint | ModBigInt) => {
    this.v = (this.v + MOD_BIGINT - ModBigInt.toBigInt(other)) % MOD_BIGINT;
    return this;
  };
  multiply = (other: number | bigint | ModBigInt) => {
    this.v = (this.v * ModBigInt.toBigInt(other)) % MOD_BIGINT;
    return this;
  };
  pow = (other: number) => {
    const v = mod(1);
    for (let i = 0; i < other; i++) v.multiply(this.v);
    return v;
  };
}

const mod = ModBigInt.of;

const abs = (a: bigint) => (a > 0n ? a : -a);

(function main() {
  const N = readInt();
  const A = Array(N).fill(0).map(readBigInt);
  for (let i = 0; i < N; i++) {
    if (A[i] === 0n) {
      console.log(0);
      process.exit(0);
    }
  }

  const max = 10n ** 18n;
  let result = 1n;
  for (let i = 0; i < N; i++) {
    result *= A[i];
    if (result > max) {
      console.log(-1);
      process.exit(0);
    }
  }
  console.log(result.toString());
})();


Measured memory_bytes: 48556
#!/usr/bin/env python
from collections import defaultdict, deque
import math
from math import factorial
import fractions
import re

BIGNUM = 10 ** 9 + 7

def main():
    #A, B, C = map(int, input().split())
    N = int(input())
    Hs = list(map(int, input().split()))

    is_possible = True
    max_sofar = 0
    for H in Hs:
        if max_sofar > H:
            is_possible = False
            break
        max_sofar = max([H-1, max_sofar])

    if is_possible:
        print("Yes")
    else:
        print("No")


if __name__ == '__main__':
    main()


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

using namespace std;

int main(void){
    const long long MOD = 1E9+7;
    string L;
    cin >> L;
    long long dangerous = 2, safe = 1;
    for(int i = 1; i < L.length(); i++){
        if(L[i] == '0'){
            safe *= 3;
            safe %= MOD;
        }else{
            safe *= 3;
            safe += dangerous;
            safe %= MOD;
            dangerous *= 2;
            dangerous %= MOD;
        }
    }
    cout << (safe + dangerous) % MOD << endl;
    return 0;
}


Measured memory_bytes: 512
import java.util.*;
import java.io.*;

public class Main {
    
    static int n;
    static int[] a;
    static int[] dp;
    static Node[] node;
    public static void main(String[] args) throws IOException {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        n=Integer.parseInt(br.readLine());
        a=new int[n-1];
        dp=new int[n+1];
        node=new Node[n+1];
        for(int i=0;i<n+1;i++){ node[i]=new Node(); }
        Arrays.fill(dp,-1);
        for(int i=0;i<n-1;i++){
            a[i]=Integer.parseInt(br.readLine());
            node[a[i]].next_list.add(i+2);
        }System.out.println(dfs(1));
    }
    
    static int dfs(int target){
        //System.out.println("target="+" "+target+" "+Arrays.toString(node[target].next_list.toArray()));
        if(dp[target]!=-1){ return dp[target]; }
        if(node[target].next_list.isEmpty()){ return 0; }
        int[] temp=new int[node[target].next_list.size()];
        int max=0;
        for(int i=0;i<node[target].next_list.size();i++){
            temp[i]=dfs(node[target].next_list.get(i));
        }
        Arrays.parallelSort(temp);
        for(int i:temp){
            if(max<i){ max=i+1; }
            else{ max++; }
        }
        //System.out.println("target="+target+" "+max);
        dp[target]=max;
        return dp[target];
    }
}

class Node{
    ArrayList<Integer> next_list=new ArrayList<>();
}

Measured memory_bytes: 53724
#include <stdio.h>

struct ITEM{
  char name[101];
  int cost;
};

int main(){
  struct ITEM item[100];
  int n, i, j, l, m, k, cost;
  char o[101], q[101];
  while(scanf("%d", &n) && n){
    for(i = 0; i < n; ++i) scanf("%s %d", item[i].name, &item[i].cost);

    scanf("%d", &m);
    for(i = 0; i < m; ++i){
      scanf("%s %d", o, &k);
      cost = 0;
      for(j = 0; j < k; ++j){
	scanf("%s", q);
	for(l = 0; l < n; ++l) if(strcmp(item[l].name, q) == 0) break;
	cost += item[l].cost;
      }
      for(j = 0; j < n; ++j) if(strcmp(item[j].name, o) == 0) break;
      if(cost < item[j].cost) item[j].cost = cost;
    }

    scanf("%s", o);
    for(i = 0; i < n; ++i) if(strcmp(item[i].name, o) == 0) break;
    printf("%d\n", item[i].cost);
  }
  return 0;
}

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

char s[204800];
int main() {
	int r = 0, c = 0;
	scanf("%s", s);
	for(char* p = s; *p; ++p)
	if(*p=='S') {
		++c;
	} else {
		if(c) --c; else ++r;
	}
	printf("%d\n", c + r);
}

Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
using namespace std;
#define INF 1010101010

int N, M;
int A[1000], B[1000];
int C[100][100];
int mincost[100][100];
bool done[100];

void solve() {
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            done[j] = false;
            mincost[i][j] = INF;
        }
        mincost[i][i] = 0;
        while (true) {
            int mj = 0;
            int mc = INF;
            for (int j = 0; j < N; j++) {
                if (!done[j] && mc > mincost[i][j]) {
                    mj = j;
                    mc = mincost[i][j];
                }
            }
            if (mc == INF) break;
            done[mj] = true;
            for (int j = 0; j < N; j++) {
                if (mincost[i][mj]+C[mj][j] < mincost[i][j]) mincost[i][j] = mincost[i][mj]+C[mj][j];
            }
        }
    }
    int ans = M;
    for (int i = 0; i < M; i++) {
        for (int j = 0; j < N; j++) {
            if (mincost[j][A[i]] + C[A[i]][B[i]] == mincost[j][B[i]]) {
                ans--;
                break;
            }
        }
    }
    cout << ans << endl;
}

int main() {
    cin >> N >> M;
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            C[i][j] = C[i][j] = INF;
        }
    }
    for (int i = 0; i < M; i++) {
        int a, b, c;
        cin >> A[i] >> B[i] >> c;
        A[i]--; B[i]--;
        C[A[i]][B[i]] = C[B[i]][A[i]] = c;
    }
    solve();
}

Measured memory_bytes: 384
import java.util.Scanner;
import java.util.Arrays;
class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N=sc.nextInt();
    int M=sc.nextInt();
    int As[]=new int[M];
    int Sum=0;
    for (int i=0;i<M ;i++ ) {
      As[i]=sc.nextInt();
    }
    for (int i=0;i<M ;i++ ) {
      Sum+=As[i];
    }
    if(N-Sum>0|N-Sum==0){
      System.out.println(N-Sum);
    }else{
      System.out.println(-1);      
    }

  }
}


Measured memory_bytes: 46596
##### 解けた #####

A,B,C=input().split(" ")

if A==B: # Cが仲間外れの場合
    print(C)
elif A==C: # Bが仲間外れの場合
    print(B)
elif B==C: # Aが仲間外れの場合
    print(A)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < b; i++)
#define Rep(i, a, b) for(int i = a; i <= b; i++)
#define _GLIBCXX_DEBUG
#define V vector<ll>
#define ll long long
#define ALL(v) (v).begin(),(v).end()
using namespace std;

int main() {
    int n; cin >> n;
    V a(n);
    rep(i, 0, n) cin >> a[i];

    ll ans = 0;
    rep(i, 0, n){
        while(a[i]%2 == 0){
            ans++;
            a[i] /= 2;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 384
#!/usr/bin/env python3
import sys
import itertools
import collections
import functools
import math
from queue import Queue
INF = float("inf")


def solve(R: int):
    if R < 1200:
        print("ABC")
    elif R < 2800:
        print("ARC")
    else:
        print("AGC")
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    R = int(next(tokens))  # type: int
    solve(R)


if __name__ == '__main__':
    main()


Measured memory_bytes: 4192
#include<cstring>
#include<cstdio>
int main(){
  char key[10];
  char s[10];
  int x = 0;
  scanf("%s", key);
  
  for(int i=0; i<strlen(key); i++){
    if(key[i] == 'B'){
      if(x != 0)
        x--;
    }
    else{
        s[x] = key[i];
        x++;
    }
  }
  s[x] = '\0';
  printf("%s", s);
  
  return 0;
}

Measured memory_bytes: 128
n=int(input())
A=list(map(int,input().split()))
 
a=max(A)
 
B=[]
 
for i in range(n):
    if A[i]==a:
        B.append(a)
    else:
    	B.append(abs(A[i]-a/2))
 
ind=B.index(min(B))
 
b=A[ind]
 
print(a,b)

Measured memory_bytes: 14432
#include "bits/stdc++.h"
using namespace std;

/* macro */
#define rep(i,a,b) for(int i=a;i<b;i++)
#define revrep(i,a,b) for(int i = a; i > b; i--)
#define int long long
#define exist(s,e) ((s).find(e)!=(s).end())
#define all(v) (v).begin(), (v).end()
#define each(s,itr) for(auto (itr) = s.begin(); (itr) != s.end(); (itr)++)
#define sum(v) accumulate(all(v), (0LL))
#define isin(a, b, c) (b <= a && a <= c)
#define println cout << "\n";
#define sz(v) (int)v.size()
#define bin(x) static_cast<bitset<16> >(x)


/* alias */
template<class T> using vec = vector<T>;
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef tuple<int, int, int> ti;
typedef map<int, int> mi;
typedef set<int> si;


/* constant */
const int inf = 1LL << 62;
const int mod = 1e9 + 7;
const int dx[8]={1,0,-1,0,-1,1,-1,1};
const int dy[8]={0,1,0,-1,-1,-1,1,1};
const string alphabet = "abcdefghijklmnopqrstuvwxyz";

/* io_method */
int input(){int tmp;cin >> tmp;return tmp;}
string raw_input(){string tmp;cin >> tmp;return tmp;}
template<class T> void printx(T n){cout << n;}
template<class T, class U> void printx(pair<T, U> p){cout << "(" << p.first << "," << p.second << ")";}
template<class T, class U, class V> void printx(tuple<T, U, V> t){cout << "{" << get<0>(t) << "," << get<1>(t) <<"," << get<2>(t) << "}" << endl;}
template<class T> void printx(vector<T> v){cout << "{";rep(i,0,v.size()){printx(v[i]);if(i != v.size()-1)printx(",");}cout << "}";}
template<class T> void print(T n){printx(n);cout << endl;}
template<class T> void print(set<T> s){cout << "{";each(s, e){if(e != s.begin()) printx(",");printx(*e);}cout << "}" << endl;}
template<class T, class U> void print(map<T, U> mp){cout << "{";each(mp, e){cout << "(" << e -> first << "," << e -> second << ")";}cout << "}" << endl;}
template<class T> void printans(vec<T> v){rep(i,0,sz(v)){cout << v[i] << (i == sz(v) - 1 ? "" : " ");}cout << endl;}


/* general_method */
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 (b<a) { a=b; return 1; } return 0; }
template<class T>T cut(T &a, int l, int r){return T(a.begin()+l, a.begin()+r);}


/* math_method */
int ceil(int a, int b){return a / b + (a % b > 0);}


/* main */

int a, b;
void in(){
    cin >> a >> b;
}

void solve(){

    int ans = max(a, b);

    if(a == ans){
        ans += max(a - 1, b);
    }else{
        ans += max(a, b - 1);
    }
    print(ans);

}

signed main(){

    cin.tie(0);
    ios::sync_with_stdio(false);
    in();
    solve();
    
}

Measured memory_bytes: 256