akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#define max(X, Y) ((X) > (Y) ? (X) : (Y))
#define min(X, Y) ((X) < (Y) ? (X) : (Y))

int64_t n;
int64_t a[100005];
int64_t minv = 100000000;
int64_t maxv = -1;

int main()
{
    scanf("%lld", &n);
    for (int64_t i = 0; i < n; i++) {
        scanf("%lld", &a[i]);

        minv = min(minv, a[i]);
        maxv = max(maxv, a[i]);
    }

    if (maxv - minv >= 2) {
        puts("No");
    }
    else if (maxv - minv == 1) {
        int64_t alone, dlone;
        alone = dlone = 0;

        for (int64_t i = 0; i < n; i++) {
            if (maxv == a[i]) {
                dlone++;
            }
            else {
                alone++;
            }
        }

        if (alone < maxv && 2 * maxv - 2 * alone <= dlone) {
            puts("Yes");
        }
        else {
            puts("No");
        }
    }
    else {
        int64_t i = 0;
        while (i < n && 2 * a[i] <= n) {
            i++;
        }

        if (i == n || maxv == n - 1) {
            puts("Yes");
        }
        else {
            puts("No");
        }
    }

    return 0;
}


Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define UNIQUE(v) v.erase(unique(all(v)), v.end());
#define ZIP(v) sort(all(v)),UNIQUE(v)
#define ADD(a, b) a = (a + b) % mod
#define SUB(a, b) a = (a+mod-b)%mod
#define MUL(a, b) a = (a * b) % mod
#define repi(i,m,n) for(int i = m;i < n;i++)
#define drep(i,n,m) for(int i = n;i >= m;i--)
#define rep(i,n) repi(i,0,n)
#define rrep(i,n) repi(i,1,n+1)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define dmp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define fi first
#define se second
typedef pair<int,int> P;
typedef pair<int, P> PP;
typedef pair<P, int> Pi;
typedef vector<int> vi;
typedef deque<int> dq;
const int inf = 1e9+7;
const int INF = 1e18+7;

char str[100][100];
signed main(){
	int h, w;
	char c;
	rep(i,100)rep(j,100)str[i][j] = '.';
	scanf("%lld%lld %c", &w, &h, &c);
	rep(i,w)str[0][i] = str[h-1][i] = '-';
	rep(i,h)str[i][0] = str[i][w-1] = '|';
	str[0][0] = str[h-1][0] = str[0][w-1] = str[h-1][w-1] = '+';
	str[h/2][w/2] = c;
	rep(i,h){
		rep(j,w)printf("%c", str[i][j]);
		printf("\n");
	}
	return 0;
}







Measured memory_bytes: 3176
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mod 1e9+7
#define mininf -922337203685477
#define pi acos(-1)
#define inf 0x3f3f3f3f
#define fast ios_base::sync_with_stdio(0); cin.tie(); cout.tie();
typedef long long ll;
typedef unsigned long long ull;

int main(){
	fast
	int x, y;
	cin >> x >> y;
	if(x*2>y or x*4<y){
		cout << "No" << '\n';
	}
	else{
		if(y&1){
			cout << "No" << '\n';
		}
		else{
			cout << "Yes" << '\n';
		}
	}
}

Measured memory_bytes: 3656
#include<cstdio>
#include<iostream>
using namespace std;
int t,x,y,px,py,pt,n;
int main()
{
	scanf("%d",&n);
	for (int i=1;i<=n;i++)
	{
		scanf("%d%d%d",&t,&x,&y);
		if (x-px+y-py>t-pt) {printf("No");return 0;}
		if ((x-px+y-py-t+pt)&1) {printf("No");return 0;}
		pt=t,px=x,py=y;
	}
	printf("Yes");
}

Measured memory_bytes: 256
MOD = pow(10, 9) + 7
waru2 = pow(2, MOD-2, MOD)

def main():
    N = int(input())
    A = list(map(int, input().split()))
    taikaku = 0
    for i in range(N):
        taikaku += pow(A[i], 2)
        taikaku %= MOD
    zennbu = 0
    sumA = sum(A)
    for i in range(N):
        zennbu += A[i]*sumA
        zennbu %= MOD
    
    ans = ((zennbu - taikaku) * waru2) % MOD
    print(ans)

if __name__ == "__main__":
    main()


Measured memory_bytes: 31428
#include <bits/stdc++.h>
#include<iostream>
#include<cmath>
#define rep(i,n) for(int i=0;i<(n);++i)
using namespace std;
using ll=long long;
using P=pair<int,int>;
const int INF=1001001001;

int main(){
   int n,m; cin>>n>>m;
   vector<pair<int,int>> p(m);
   rep(i,m) cin>>p[i].first>>p[i].second;
   rep(x,1000){
      int nx=x/10;
      vector<int> d(1,x%10); //一つの要素をx%10で初期化する
      while(nx){
         d.push_back(nx%10);
         nx/=10;
      }
      reverse(d.begin(),d.end());
      //n桁か
      if(d.size()!=n) continue;
      bool ok=true;
      rep(i,m){
         if(d[p[i].first-1]!=p[i].second) ok=false;
      }
      if(ok){
         cout<<x<<endl;
         return 0;
      }
   }
   cout<<-1<<endl;
   return 0;
}


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

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)

using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PI;
const ll mod = 1e9 + 7;

int main(void){
  string S;
  cin >> S;
  while (true)
    {
      int len = S.size();
      if (len == 0)
	break;
      //cout << S << endl;
      if (len >= 5 && (S.substr(len-5) == "dream"||S.substr(len-5) == "erase"))
	S = S.substr(0,len-5);
      else if (len >=6 &&S.substr(len-6)=="eraser")
	S = S.substr(0,len-6);
      else if (len>=7 &&S.substr(len-7)=="dreamer")
	S = S.substr(0,len-7);
      else 
	{
	  cout << "NO" << endl;
	  return 0;
	}
      //cout << S << endl;
    }
  cout << "YES" << endl;
  return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <vector>
#include <cstdio>
#include <bits/stdc++.h>
#include <set>
using namespace std;
using ll =long long;

int main (void) {
  int N;
  cin >> N;
  int a[2*N];
  int b=0;
  int sum=0;
  for (int i=0; i<2*N; i++) {
    cin >> b;
    a[i]=b;
  }
  sort(a,a+2*N);
  for (int i=0; i<2*N; i=i+2) {
    sum=a[i]+sum;
  }
  cout << sum;
}

Measured memory_bytes: 256
#define REP(i, n) for(int i = 0; i < (int)(n); i++)

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

int main() {
	int N, K;
	cin >> N >> K;
	int max_K = (N - 1) * (N - 2) / 2;

	if (K > max_K) {
		cout << -1 << endl;
	}
	else {
		vector<pair<int, int>> fri(N * (N - 1) / 2);
		int M = N - 1 + max_K - K;

		cout << M << endl;

		int cnt = 0;
		for (int i = 0; i < N; i++) {
			for (int j = i + 1; j < N; j++) {
				fri[cnt].first = i + 1;
				fri[cnt].second = j + 1;
				cnt++;
			}
		}

		REP(i, M) {
			cout << fri[i].first << " " << fri[i].second << endl;
		}

	}

	return 0;
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Map;
import java.util.Scanner;
import java.util.TreeMap;

public class Main {
	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		int n = scan.nextInt();
		int count = 0;
		TreeMap<String, ArrayList<Integer>> map = new TreeMap<>();

		for(int i = 0; i < n; i++) {
			int query = scan.nextInt();
			String key = scan.next();

			switch(query) {

			case 0:	//insert
				int value = scan.nextInt();
				if(!map.containsKey(key)) map.put(key, new ArrayList<Integer>());	//WARNING
				map.get(key).add(value);
				break;

			case 1:	//find
				if(map.get(key) != null) 
					for(Integer x : map.get(key)) {
						System.out.println(x);
					}
					break;

			case 2:	//delete
				if(map.get(key) != null) {
					map.remove(key);
				}
				break;

			case 3:	//dump
				String tilKey = scan.next();
				Map<String, ArrayList<Integer>> subM = map.subMap(key,true, tilKey,true);
				for(String x : subM.keySet()){
					for(Integer x2 : subM.get(x)) {
						System.out.println(x + " " + x2);
					}
				}
				break;
			}
		}
	}
}


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

int main(){
  int N;
  cin >> N;
  vector<int64_t> a(N);
  cin >> a.at(0);
  int64_t ans=a.at(0);
  for(int i=1;i<N;i++){
    cin >> a.at(i);
    ans^=a.at(i);
  }
  if(ans==0){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 1024
def main():
    s = input()
    sukima = len(s)-1
    res = 0
    for i in range(2**sukima):
        op = ['']*sukima
        for j in range(sukima):
            if ((i>>j)&1): # bit check
                op[sukima-1-j] = '+'
        s1 = [s[i//2] if i%2 == 0 else op[i//2] for i in range(len(s)*2-1)]
        res += eval(''.join(s1))
    print(res)
    
if __name__ == '__main__':
    main()



Measured memory_bytes: 39636
N, M = map(int, input().split())
goal = list(map(int, input().split()))

goal = sorted(goal)
sabun = [goal[_+1]-goal[_] for _ in range(M-1)]
sabun = sorted(sabun)

if M-N <= 0:
  print(0)
else:
  k = M-N
  print(sum(sabun[:k]))

Measured memory_bytes: 13968
#include <bits/stdc++.h>
using namespace std;
#define rep0(i,n) for(ll (i) = 0; (i) < (n); ++(i))
#define rrep0(i,n) for(ll (i) = (n) - 1; (i) >= 0; --(i))
#define rep1(i,n) for(ll (i) = 1; (i) <= (n); ++(i))
#define rrep1(i,n) for(ll (i) = (n); (i) >= 1; --(i))
#define nfor(i,a,b) for(ll (i) = (a); (i) < (b); ++(i))
#define rnfor(i,a,b) for(ll (i) = (a) - 1; (i) >= (b); --(i))
#define ll long long
#define mod (1000000007)
#define pf(x) cout << (x) << endl
#define all(x) (x).begin(),(x).end()

ll gcd(ll a,ll b){
    if(a < b)swap(a, b);
    if(b == 0) return a;
    return gcd(b,a%b);
}

ll lcm(ll a,ll b){
    ll g = gcd(a,b);
    return a / g * b;
}

ll factorial(ll n){
    ll t = 1;
    rep1(i, n)t *= i;
    return t;
}

ll combinations(ll n, ll k) {
    ll r = 1;
    rep1(i, k)r = r * n-- / i;
    return r;
}

int main(){
    ll n,m;
    cin >> n >> m;
    vector<bool> c(n + 1,false);
    vector<ll> cnt(n + 1,1);
    cnt[0] = 0;
    c[1] = true;
    rep0(i, m){
        ll x,y;
        cin >> x >> y;
        --cnt[x];
        ++cnt[y];
        if(c[x])c[y] = true;
        if(cnt[x] == 0)c[x] = false;
    }
    ll ans = 0;
    rep0(i, n + 1)if(c[i])++ans;
    pf(ans);
    return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>

#define INFTY 1000000000

void merge(int *,int ,int ,int);
void mergeSort(int *,int,int);

int S[500000],L[500000],R[500000];
int count;

int main(){
  
  int n,i;

  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&S[i]);
  }

  mergeSort(S,0,n);

  for(i=0;i<n;i++){
    printf("%d",S[i]);
    if(i<n-1) printf(" ");
  }
  printf("\n");
  printf("%d\n",count);
    
  
  return 0;

}

void merge(int A[],int left,int mid,int right){

  int n1,n2,i,k,j;
  
  n1 = mid - left;
  n2 = right - mid;
  for(i = 0 ;i<= n1-1;i++){
    L[i] = A[left + i];
  }
  for(i = 0; i<= n2-1;i++){
    R[i] = A[mid + i];
  }
  L[n1] = INFTY;
  R[n2] = INFTY;
  i = 0;
  j = 0;
  for (k = left; k< right;k++){
    if (L[i] <= R[j]){
      A[k] = L[i];
      i = i + 1;
    }
    else{ 
      A[k] = R[j];
      j = j + 1;
    }
    count++;
  }
}

void mergeSort(int A[],int left,int right){
  if(left+1<right){
    int mid;
    mid=(left+right)/2;
    mergeSort(A, left, mid);
    mergeSort(A, mid, right);
    merge(A, left, mid, right);
  }
}

Measured memory_bytes: 5488
class SegmentTree:
    def __init__(self, size, f=lambda x,y : x+y, default=0):
        self.size = 2**(size-1).bit_length()
        self.default = default
        self.dat = [default]*(self.size*2)
        self.f = f

    def update(self, i, x):
        i += self.size
        self.dat[i] = x
        while i > 0:
            i >>= 1
            self.dat[i] = self.f(self.dat[i*2], self.dat[i*2+1])

    def query(self, l, r):
        l += self.size
        r += self.size
        lres, rres = self.default, self.default
        while l < r:
            if l & 1:
                lres = self.f(lres, self.dat[l])
                l += 1

            if r & 1:
                r -= 1
                rres = self.f(self.dat[r], rres)
            l >>= 1
            r >>= 1
        res = self.f(lres, rres)
        return res

n, q = map(int, input().split())
s = SegmentTree(n, min, 2**31-1)
for i in range(q):
    com, x, y = map(int, input().split())
    if com == 0:
        s.update(x, y)
    else:
        print(s.query(x, y+1))



Measured memory_bytes: 8692
#include <cstdio>
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <algorithm>
#include <cmath>
#include <string>

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

using namespace std;

template<class T>
inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

void trace(int A[], int N) {
    for (int i = 0; i < N; ++i) {
        if (i > 0) cout << " ";
        cout << A[i];
    }
    cout << endl;
}

using ll = long long;
using P = pair<int, int>;

const unsigned long long INF = 1LL << 60;

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

int m, f, r;

int main() {
    while (true) {
        cin >> m >> f >> r;
        if (m == -1 && f == -1 && r == -1) break;

        if (m == -1 || f == -1) {
            cout << "F" << endl;
        } else if (m + f >= 80) {
            cout << "A" << endl;
        } else if (m + f >= 65) {
            cout << "B" << endl;
        } else if (m + f >= 50) {
            cout << "C" << endl;
        } else if (m + f >= 30) {
            if (r >= 50) {
                cout << "C" << endl;
            } else {
                cout << "D" << endl;
            }
        } else {
            cout << "F" << endl;
        }
    }
}



Measured memory_bytes: 3092
#!/usr/bin/env python
# coding: utf-8

# In[10]:


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


# In[11]:


a_s = sorted(a, reverse=True)
alice = sum(a_s[::2])
bob = sum(a_s[1::2])
print(alice-bob)


# In[ ]:






Measured memory_bytes: 2940
#include<bits/stdc++.h>
#define pb push_back
using namespace std;
int main()
{
int n,m,h[100005],i,a,b;
cin>>n>>m;
vector<int>g[100001];
for(i=1; i<=n; i++)
{
cin>>h[i];
}
for(i=1; i<=m; i++)
{
cin>>a>>b;
g[a].pb(b);
g[b].pb(a);
}
int cnt,ans=0;
for(i=1; i<=n; i++)
{
cnt=0;
for(int j=0;j<g[i].size();j++)
{
int k=g[i][j];
if(h[k]<h[i])
{
cnt++;
}
}
if(cnt==g[i].size())
{
ans++;
}
}
cout<<ans<<'\n';
return 0;
}


Measured memory_bytes: 9156
import string
import numpy as np

alist=np.asarray(list(string.ascii_uppercase)) # アルファベットのリスト
N=int(input()) # 何個ずらすか
S=input() # 入力の文字列
O="" # 出力の文字列

# 各文字について
for s in S:
    aconv=alist[(np.where(alist==s)[0][0]+N)%26] # 変換した後の文字
    O+=aconv # 連結

print(O)

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

cnt = 0
b_start = 0
a_end = 0
b_start_and_a_end = 0

for i in range(N):
    s = input()
    cnt += s.count('AB')
    if s[0] == 'B' and s[-1] == 'A':
        b_start_and_a_end += 1
    elif s[0] == 'B':
        b_start += 1
    elif s[-1] == 'A':
        a_end += 1

cnt += min(a_end,b_start)

if b_start == a_end == 0:
    cnt += max(0,b_start_and_a_end-1)
else:
    cnt += b_start_and_a_end

print(cnt)

Measured memory_bytes: 3064
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    for(int i=1; i<=9; ++i)
        for(int j=1; j<=9; ++j)
            cout << i << 'x' << j << '=' << (i*j) << endl;
}

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

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = std::int64_t;
using P = std::tuple<int,int>;

ll A, B, C;

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

  std::cin >> A >> B >> C;

  bool ok = false;

  if(C >= A + B){
      ok = 4ll * A * B < (C - A - B) * (C - A - B);
  }
  
  if(ok){
      std::cout << "Yes" << std::endl;
  }else{
      std::cout << "No" << std::endl;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <iomanip>
using namespace std;

void solve(){
  int n, k; cin >> n >> k;
  vector<int> p(n);
  vector<double> t(n);
  for(int i = 0; i < n; i++){
    cin >> p[i];
    t[i] = (1 + p[i]) / 2.0;
  }
  double tmp = 0, ans;
  for(int i = 0; i < k; i++){
    tmp += t[i];
  }
  ans = tmp;
  for(int i = 1; i <= n - k; i++){
    tmp = tmp - t[i - 1] + t[i + k - 1];
    ans = max(ans, tmp);
  }
  cout << fixed << setprecision(6) << ans << endl;
  return;
}

int main(){
  solve();
  return 0;
}


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


int main(){
    string s;
    cin>>s;
    int c=0;
    for(int i=0;i<4;i++){
        for(int j=i+1;j<4;j++){
            if(s[i]==s[j])
            c++;
        }
    }
    if(c==2)
    cout<<"Yes";
    else
    cout<<"No";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long lint;
using namespace std;
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)

const int INF = 1000000000;

void setUnion(set<char> &s1, set<char> &s2) {
    for (char i: s2) {
        s1.insert(i);
    }
}

struct SegTree{
    private:
        int n;
        vector<set<char>> node;
public:
    SegTree(string &v) {
        int sz = v.size();
        n = 1;
        while (n < sz) {
            n <<= 1;
        }
        node.resize(2 * n - 1, set<char>());
        rep(i,sz) {
            set<char> s;
            s.insert(v[i]);
            node[i + n - 1] = s;
        }
        for(int i=sz; i < n; i++) {
            set<char> s;
            node[i + n - 1] = s;
        }
        for (int i = n-2; i >= 0; i--) {
            set<char> s;
            setUnion(s, node[2*i+1]);
            setUnion(s, node[2*i+2]);
            node[i] = s;
        }
    }

    void update(int i, char c) {
        i += (n-1);
        {
            set<char> s;
            s.insert(c);
            node[i] = s;
        }
        while (i > 0) {
            i = (i - 1) / 2;
            set<char> s;
            setUnion(s, node[2*i+1]);
            setUnion(s, node[2*i+2]);
            node[i] = s;
        }
    }

    set<char> find(int a, int b) {
        set<char> val_left;
        set<char> val_right;
        for (a += (n-1), b += (n-1); a < b; a >>= 1, b >>= 1){
            if ((a & 1) == 0) {
                setUnion(val_left, node[a]); 
            }
            if ((b & 1) == 0) {
                setUnion(val_right, node[--b]);
            }
        }
        setUnion(val_left, val_right);
        return val_left;
    }
};

int main() {
    int n; cin >> n;
    string s; cin >> s;
    int q; cin >> q;
    SegTree seg(s);
    rep(loop,q) {
        int query; cin >> query;
        if (query == 1) {
            int i; cin >> i;
            char c; cin >> c;
            seg.update(i-1,c);
        }
        else {
            int l,r; cin >> l >> r;
            set<char> res = seg.find(l-1,r);
            cout << res.size() << endl;
        }
    }
}

Measured memory_bytes: 191656
#pragma GCC optimize ("Ofast","unroll-loops")
#include <bits/stdc++.h>
#define pb push_back
#define eb emplace_back
#define MP make_pair
#define F first
#define S second
#define MEM(a,b) memset(a,b,sizeof a)
#define Tie ios::sync_with_stdio(0),cin.tie(0);
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

ll n,x,y,dp[2][100001];
const ll MOD=1e9+7;
vector<int> v[100001];
bitset<100001> u;

void dfs(int a)
{
	dp[0][a]=dp[1][a]=1;
	u[a]=1;
	for(int i:v[a])
		if(!u[i])
			dfs(i),dp[1][a]=dp[1][a]*dp[0][i]%MOD,dp[0][a]=dp[0][a]*(dp[0][i]+dp[1][i])%MOD;
}

int main()
{Tie
	cin>>n;
	for(int i=1;i<n;i++)
		cin>>x>>y,v[x].pb(y),v[y].pb(x);
	dfs(1);
	cout << (dp[1][1]+dp[0][1])%MOD<<'\n';
}

Measured memory_bytes: 9984
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
const int INF = 1001001001;

int a[12][12];

int main() {
  int n, m, x;
  cin >> n >> m >> x;
  vector<int> c(n);
  rep(i,n) {
    cin >> c[i];
    rep(j,m) cin >> a[i][j];
  }

  int ans = INF;
  rep(s,1<<n) {
    int cost = 0;
    vector<int> d(m);
    rep(i,n) {
      if(s>>i&1) {//  >>2進数を右に移動、i bit目が1か
        cost += c[i];
        rep(j,m) d[j] += a[i][j];
      }
    }
    bool ok = true;
    rep(j,m) if(d[j] < x) ok = false;
    if(ok) ans = min(ans,cost);
  }
  if(ans == INF) cout << -1 << endl;
  else cout << ans << endl;
  return 0;
}


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

char o[3] = {'+','-','*'};
bool flag;

int calc(int a,int b,int op){
	if( op == 0 )
		return a + b;
	if( op == 1 )
		return a - b;
	
	return a * b;
}

void solve(vector<int> v, int op1, int op2, int op3){
	if( flag == false ) return ;
	int a = v[0];
	int b = v[1];
	int c = v[2];
	int d = v[3];
	
	if( calc( calc( calc(a,b,op1) , c , op2 ) , d , op3 ) == 10 ){
		cout << "(((" << a << " " << o[op1] << " " << b << ") " << o[op2] << " " << c << ") " << o[op3] << " " << d << ")" << endl;
		flag = false;
		return;
	}
	if( calc( calc(a,b,op1) , calc(c,d,op3) , op2 ) == 10 ){
		cout << "((" << a << " " << o[op1] << " " << b << ") " << o[op2] << " (" << c << " " << o[op3] << " " << d << "))" << endl;
		flag = false;
		return;
	}
	if( calc( calc( a , calc(b,c,op2) , op1 ) , d , op3 ) == 10 ){
		cout << "((" << a << " " << o[op1] << " (" << b << " " << o[op2] << " " << c << ") " << o[op3] << " " << d << "))" << endl;
		flag = false;
		return;
	}
}

int main(){
	int a,b,c,d;
	
	while( cin >> a >> b >> c >> d , a || b || c || d ){
		vector<int> v(4);
		flag = true;
		v[0] = a;
		v[1] = b;
		v[2] = c;
		v[3] = d;
		
		sort( v.begin() , v.end() );
		do{
			for(int i=0 ; i < 3 && flag ; i++ ){
				for(int j=0 ; j < 3 && flag ; j++ ){
					for(int k=0 ; k < 3 && flag ; k++ ){
						solve( v , i , j , k );
					}
				}
			}
		}while( next_permutation(v.begin(),v.end()) && flag );
		if( flag ){
			cout << 0 << endl;
		}
	}
}

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

int main(){
  int a,b,c = 0;
  string s;
  bool f = false;
  cin >> a >> b >> s;
  rep(i,s.size()){
    if(s[i] == '-'){
      if(i == a){
        f = true;
      }
      c++;
    }
  }
  if(f && c == 1)cout << "Yes";
  else cout << "No";
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
#define double long double
#define pdi pair<double, int>
#define mp make_pair
#define F first
#define S second

using namespace std;

const int N = 1e3+3;
const double INF = 1e18;
int n;
bool vis[N];
double costs[N];

struct circle
{
	int x, y, r;
} barr[N];
double adjmat[N][N];

struct disrt
{
	bool operator()(const pdi &a, const pdi &b)
	{
		return a.F - b.F > (double) 0.0;
	}
};

priority_queue< pdi, vector < pdi >, disrt > pq;

double dist(circle a, circle b)
{
	double dx = (a.x - b.x) * (a.x - b.x);
	double dy = (a.y - b.y) * (a.y - b.y);
	double dd = sqrt(dx + dy);
	dd = max(dd - a.r - b.r, (double) 0.0);
	return dd;
}
signed main()
{
	cout << setprecision(35);
	cin >> barr[0].x >> barr[0].y;
	barr[0].r=0;
	cin >> barr[1].x >> barr[1].y;
	barr[1].r=0;
	cin >> n;
	for(int i = 2; i < n+2; i++)
	{
		cin >> barr[i].x >> barr[i].y >> barr[i].r;
	}	
	n+=2;
	for(int i = 0; i < n; i++)
	{
		costs[i]=INF;
		for(int j = 0; j < n; j++)
		{
			adjmat[i][j] = dist(barr[i], barr[j]);
		}
	}
	costs[0]=0;
	pq.push(mp(0.0, 0));
	while(pq.size())
	{
		while(pq.size() && vis[pq.top().S]) pq.pop();
		if(!pq.size()) break;
		pdi curr = pq.top();
		if(curr.S==1)
		{
			cout << curr.F;
			return 0;
		}
		pq.pop();
		vis[curr.S]=true;
		for(int i = 0; i < n; i++)
		{
			if(!vis[i])
			{
				if(curr.F + adjmat[curr.S][i] - costs[i] < (double) 0.0)
				{
					pq.push(mp(curr.F + adjmat[curr.S][i], i));
					costs[i] = curr.F + adjmat[curr.S][i];
				}
			}
		}
	}
}

Measured memory_bytes: 26092
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws NumberFormatException, IOException {
        BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
        String s = stdin.readLine();
        
        int a = Integer.parseInt(s.substring(0, 2));
        int b = Integer.parseInt(s.substring(2));
        boolean yymm = 01 <= b && b <= 12;
        boolean mmyy = 01 <= a && a <= 12;
        
        String ans = (yymm && mmyy) ? "AMBIGUOUS" :
                      yymm          ? "YYMM"      :
                      mmyy          ? "MMYY"      : "NA";
        System.out.println(ans);
    }
}


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

using namespace std;

typedef long long ll;
const int mod = 1e9 + 7;

ll binPow(ll x, ll y, ll md = mod){
    ll res = 1;
    x %= mod;
    while(y){
        if(y & 1){
            res = (res * x) % mod;
        }
        y >>= 1;
        x = (x * x) % mod;
    }
    return res;
}

void solve(){
    ll n, s;
    cin >> n >> s;
    ll base = 1e18;
    bool flag = false;
    for(ll b = 2; b <= sqrt(n); b++){
        ll sum = 0, temp = n;
        while(temp){
            sum += (temp % b);
            temp /= b;
        }
        if(sum == s){
            flag = true;
            base = b;
            break;
        }
    }
    if(!flag){
        ll res = n - s;
        if(res > 0){
            for(ll i = 1; i <= sqrt(res); ++i){
                if(res % i == 0){
                    ll f1 = i, f2 = res / i;
                    if(f1 <= f2){
                        ll x = f1, bb = f2 + 1, y = s - x;
                        if(y >= 0 and y < bb and (bb * x + y == n))
                            base = min(base, bb), flag = true;
                    }
                }
            }
        }
        else{
            if(n == s){
                base = n + 1;
                flag = true;
            }
        }
    }
    if(flag){
        cout << base << "\n";
    }
    else{
        cout << "-1\n";
    }
 }

int main() {
#ifndef ONLINE_JUDGE
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    solve();
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <algorithm>
#include <bitset>
#include <cstdlib>
#include <cmath>
#define INF 100000000000
#define MOD 1000000007
 
#define ll long long int
using namespace std;

struct Node{
  set <ll> to;
  ll point = 0;
  bool or_root = false;

};

vector < Node > gragh(200009);

void rec(ll now);

int main(){
  ll N,Q;
 cin>>N>>Q;

gragh[1].or_root = true;

for(int i=1;i<=N-1;i++){
  ll a,b; cin>>a>>b;
 gragh[a].to.insert(b);
  gragh[b].to.insert(a);
}

for(int i=0;i<Q;i++){
  int p,x; cin>>p>>x;
  gragh[p].point += x;
}

rec(1);

for(int i=1;i<=N;i++){
  cout<<gragh[i].point<<" ";
}




return 0;

}

void rec(ll now){

  Node here = gragh[now]; 

  for(auto itr = here.to.begin();itr != here.to.end();itr++){
    if( gragh[(*itr)].or_root == true ) continue;
    gragh[*itr].point += here.point;
    gragh[*itr].or_root = true;
    rec(*itr);
  }
}

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

int main() {
    string s;
    cin >> s;
    unordered_map<char, int> mp;
    for (char c: s) {
        mp[c]++;
    }
    if (mp.size() != 2) {
        cout << "No" << endl;
    } else {
        for (auto p: mp) {
            if (p.second != 2) {
                cout << "No" << endl;
                return 0;
            }
        }
        cout << "Yes" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
def main():
	n , l = map(int,input().split())
	arr= []
	for i in range(n):
		arr.append(l+i)
	arr.sort()
	add = sum(arr)
	mn = 10000000000000
	# print(arr)
	# print(abs(0))
	for i in range(len(arr)):
		if abs(arr[i])<abs(mn):
			mn = arr[i]
	print(add-mn)
main()


Measured memory_bytes: 3060
import itertools
N = int(input().strip())
S = input().strip()

X = set()
Y = set()
Z = set()

# X, Y, Zの位置を挿入
for index in range(len(S)):
    if S[index] == 'R':
        X.add(index)
    elif S[index] == 'G':
        Y.add(index)
    elif S[index] == 'B':
        Z.add(index)

all_combination_num = len(X) * len(Y) * len(Z)
exclude_num = 0

rgbcombination = list(itertools.permutations('RGB', 3))
for i in range(1, N):
    for j in range(N - i * 2):
        if (S[j], S[i + j], S[j + i * 2]) in rgbcombination:
            exclude_num += 1

print(all_combination_num - exclude_num)

Measured memory_bytes: 9588
fn main() {
    // unimplemented!();
    let input: Vec<i32> = read_vec();
    let result = if input[0] >= 30 { "Yes" } else { "No" };
    println!("{}", result);
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}

Measured memory_bytes: 2140
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ins insert
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
ll modfac(ll a){
    ll ans=1;
    while(a>1){
        ans*=a;
        ans%=1000000007;
        a--;
    }
    return ans;
}
ll modinv(ll a,ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m; 
    if (u < 0) u += m;
    return u;
}
struct UnionFind {
    vector<int> par;
    
    UnionFind(int n) : par(n, -1) {}

    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }
    
    bool same(int x, int y) {
        return root(x) == root(y);
    }
    
    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y);
        par[x] += par[y];
        par[y] = x;
        return true;
    }
    
    int size(int x) {
        return -par[root(x)];
    }
};
ll modpow(ll a, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
int main(){
    ll n,k;cin >> n >>k;
    vl v(n);
    rep(i,n)cin >> v[i];
    vl dp(n,inf);
    dp[0]=0;
    rep(i,n){
        rep(j,k+1){
            if((i-j)<0)continue;
            dp[i]=min(dp[i],dp[i-j]+abs(v[i]-v[i-j]));
        }
    }
    cout << dp[n-1] <<endl;
}

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

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

    int ans = 0;
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        while (a % 2 == 0) {
            ans++;
            a /= 2;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<n+1;i++)
#define sort(A) sort(A.begin(),A.end())
#define reverse(A) reverse(A.begin(),A.end())
typedef long long ll;
typedef pair<int,int> P;

int main(){
  int n,m,x,y;
  cin >> n >> m >> x >> y;
  int A_max = x;
  rep(i,n){
    int p;
    cin >>p;
    A_max = max(A_max,p);
  }
  int B_min = y;
  rep(i,m){
    int p;
    cin >>p;
    B_min = min(B_min,p);
  }
  if(A_max < B_min) cout << "No ";
  cout << "War";
}

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

void sort(int n, int *a)
{
    bool f=true;
    int temp;

    while(f==true)
    {
        f=false;
        for(int i=0;i<n-1;i++)
        {
            if (a[i]>a[i+1])
            {
                f=true;
                temp = a[i];
                a[i] = a[i+1];
                a[i+1] = temp;
            }
        }
    }
}

int main()
{
    int n;
    int ans=0;
    int *l;

    cin >> n;
    n*=2;
    l = new int [n];

    for (int i=0;i<n;i++)
        cin >> l[i];

    sort(n,l);

    for (int i=0;i<n;i=i+2)
        ans += l[i];

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


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

using namespace std;

vector<int> func(vector<int> s){
  vector<int>t;
  for(int i=0;i<s.size();i++){
    int cnt=0;
    for(int j=0;j<s.size();j++){
      if(s[i]==s[j])cnt++;
    }
    t.push_back(cnt);
  }
  return t;
}

int main(void){
  vector<int>p;
  int n,x;
  
  while(cin >> n,n){
    p.clear();
    for(int i=0;i<n;i++){
      cin >> x;
      p.push_back(x);
    }
    
    int cnt=0;
    while(true){
      vector<int>res=func(p);
      if(res==p){
	cout << cnt << endl;
	for(int i=0;i<res.size();i++){
	  cout << res[i];
	  if(i==res.size()-1)cout << endl;
	  else cout <<" ";
	}
	break;
      }
      p=res;
      cnt++;
    }
  }
  return 0;
}

Measured memory_bytes: 0
//header{{{
#include<bits/stdc++.h>
  
using namespace std;
 
#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define setout(n,x) setw(n) << setfill(x)
#define Fixed fixed << setprecision(10)
#define int long long
using pii = pair<int,int>;
constexpr int INF  = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod = 1e9+7; 
 
int gcd(int a,int b){ return b ? gcd(b,a % b) : a;}
int lcm(int a,int b){ return a / gcd(a,b) * b;}
//}}}

bool IsPrime(int n){
	if(n == 2) return true;
	if(n < 2 || n % 2 == 0) return false;
	for(int i = 3;i * i <= n;i += 2){
		if(n % i == 0) return false;
	}
	return true;
}

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int q;
	cin >> q;
	vector<int> dp(100050);
	reps(i,100000){
		if(IsPrime(i) && IsPrime((i+1)/2)) ++dp[i];
		dp[i] += dp[i-1];
	}
	rep(i,q){
		int l,r;
		cin >> l >> r;
		cout << dp[r] - dp[l-1] << '\n';
	}
	return 0;
}



Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
int main() {
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		string str,one=".,!? ",ans;
		cin>>str;
		for(int j=0,co=0,num=0;j<=str.size();j++){
			if(num==str[j]-'0')co++;
			else{
				if(num==1)ans+=one[co%5];
				else if(num==7)ans+=co%4+'p';
				else if(num==8)ans+=co%3+'t';
				else if(num==9)ans+=co%4+'w';
				else if(num>1)ans+=co%3+'a'+3*(num-2);
				co=0;
				num=str[j]-'0';
			}
		}
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 1216
#include <bits/stdc++.h>
using namespace std;
string s;
int tot=0;
int main()
{
	cin>>s;
	for(int i=0;i<s.size();i++)
	{
		tot+=s[i]-'0';
	}
	if(tot%9==0)
	{
		printf("Yes");
	}
	else
	{
		printf("No");
	}
}

Measured memory_bytes: 3896
N = int(input())
A = [int(input()) for i in range(N)]
Q =[0]*(N)
for i in range(N):
    Q[A[i]-1] = i+1
num = 1
ans = 1
for i in range(N-1):
    if Q[i]<Q[i+1]:
        num += 1
    else:
        num = 1
    ans =max(ans,num)
print(N-ans)

Measured memory_bytes: 20932
/**
 *    author:  otera    
**/
#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<deque>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

//#define int long long
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const int inf=1e9+7;
const ll INF=1LL<<60 ;
const ll mod=1e9+7 ;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
#define debug(x)  cerr << #x << " = " << (x) << 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; }

void solve() {
	int n; cin >> n;
    if(n == 1) {
        cout << "Hello World" << endl;
    } else {
        int a, b; cin >> a >> b;
        cout << a + b << endl;
    }
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//int t; cin >> t; rep(i, t)solve();
	solve();
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}

int main() {
  int n, k, s;
  cin >> n >> k >> s;
  rep(i,k) cout << s << " ";
  int num;
  if(s<500000) num = 500000;
  else num = 1;
  rep(i,n-k) cout << num << " ";
  cout << endl;
  return 0;
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
using ll =long long;
#define all(v) v.begin(),v.end()
 
int main() {
ll A,B;
  cin>>A>>B;
  if(A<9&&B<9) {
cout<<"Yay!"<<endl;
  }
  else {
    cout<<":("<<endl;
  }
}

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



int main(){
	long long x, sum=0, n, m;
	cin>>n>>m;
	while(m--) {
		cin>>x;
		sum += x;
	}
	if(sum>n) cout<<-1<<endl;
	else cout<<n-sum<<endl;
}

Measured memory_bytes: 3636
import math
n, q = map(int, input().split())

s = input()

t = [0]

tmp = 0
for i in range(len(s)-1):
    if s[i] == "A" and s[i+1] == "C":
        tmp += 1

    t.append(tmp)

for _ in range(q):
    l,r = map(int, input().split())
    print(t[r-1]-t[l-1])

Measured memory_bytes: 6104
import java.io.*;
import java.util.ArrayList;
class Main{
	public static void main(String[] args) throws IOException {
		int i,j,m;
		ArrayList<String> str = new ArrayList<>();
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		m = Integer.parseInt(in.readLine());
        for(i=0;i<m;i++){
            str.add(in.readLine());
        }
        for (i = 1; i < 14; i++) {
            if (str.contains("S " + i) == false) {
                System.out.println("S " + i);
            }
        }
        for (i = 1; i < 14; i++) {
            if (str.contains("H " + i) == false) {
                System.out.println("H " + i);
            }
        }
        for (i = 1; i < 14; i++) {
            if (str.contains("C " + i) == false) {
                System.out.println("C " + i);
            }
        }
        for (i = 1; i < 14; i++) {
            if (str.contains("D " + i) == false) {
                System.out.println("D " + i);
            }
       }
		System.out.flush();
	}
}

Measured memory_bytes: 24456
import sys
import numpy as np
import random
from decimal import Decimal
import itertools
import re
import bisect
from collections import deque, Counter
from functools import lru_cache

sys.setrecursionlimit(10**9)
INF = 10**13
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
def SERIES(n): return np.fromstring(sys.stdin.buffer.read(), dtype=np.int32, sep=' ')
def GRID(h,w): return np.fromstring(sys.stdin.buffer.read(), dtype=np.int32, sep=' ').reshape(h,-1)[:,:w]
def GRIDfromString(h,w): return np.frombuffer(sys.stdin.buffer.read(), 'S1').reshape(h,-1)[:,:w]
MOD = 1000000007

def main():
	x = LI()
	for i, xi in enumerate(x):
		if xi == 0:
			print(i+1)



if __name__ == '__main__':
    main()

Measured memory_bytes: 27144
a,b,c,d=[int(i) for i in input()]

if a+b+c+d==7:
    print("{}+{}+{}+{}=7".format(a,b,c,d))
elif a+b+c-d==7:
    print("{}+{}+{}-{}=7".format(a,b,c,d))
elif a+b-c+d==7:
    print("{}+{}-{}+{}=7".format(a,b,c,d))
elif a-b+c+d==7:
    print("{}-{}+{}+{}=7".format(a,b,c,d))
elif a+b-c-d==7:
    print("{}+{}-{}-{}=7".format(a,b,c,d))
elif a-b+c-d==7:
    print("{}-{}+{}-{}=7".format(a,b,c,d))
elif a-b-c+d==7:
    print("{}-{}-{}+{}=7".format(a,b,c,d))
else:
    print("{}-{}-{}-{}=7".format(a,b,c,d))


Measured memory_bytes: 3064
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

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

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*);
    }
}

#[allow(unused_imports)]
use std::cmp::{min, max};

#[allow(unused_imports)]
use std::io::Write;
const MOD: usize = 1e9 as usize + 7;

use std::cell::RefCell;

#[derive(Debug)]
struct Solver {
  edges: Vec<Vec<usize>>,
  dp: RefCell<Vec<Vec<usize>>>
}

impl Solver {
    fn dfs(&self, cur: usize, par: usize) -> usize {
        let mut white = 1;
        let mut black = 1;

        for &next in self.edges[cur].iter() {
            if par != next {
                self.dfs(next, cur);

                let dp = self.dp.borrow();
                white *= (dp[next][0] + dp[next][1]) % MOD;
                white %= MOD;

                black *= dp[next][0];
                black %= MOD;
            }
        }

        let mut dp = self.dp.borrow_mut();
        dp[cur][0] = white;
        dp[cur][1] = black;

        return (white + black) % MOD;
    }
}

fn main() {
    input!{
      n: usize,
      xys: [(usize,usize); n-1],
    }

    let mut edges = vec![vec![]; n];
    for &(x, y) in xys.iter() {
        edges[x-1].push(y-1);
        edges[y-1].push(x-1);
    }
    let dp = vec![vec![0; 2]; n];
    let solver = Solver { edges: edges, dp: RefCell::new(dp) };
    let ans = solver.dfs(0, n);
    println!("{}", ans);
}


Measured memory_bytes: 27004
def main():


   N = int(input())
   buffeList = list(map(int,input().split()))
   gainList =  list(map(int,input().split()))
   addionList =  list(map(int,input().split()))
   ans = 0
   
   for i in range(N):
      wEat = gainList[buffeList[i]-1]
      ans += wEat
      if buffeList[i]-buffeList[i-1] == 1 and i>=1 :
         ans += addionList[buffeList[i-1]-1]
   print(ans)








if __name__== "__main__":
    main() 



Measured memory_bytes: 3064
#include <iostream>
#include <sstream>
#include <stack>
#include <iomanip>
#include <numeric>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <cassert>
#include <map>
#include <set>
#include <vector>
#include <utility>
#include <queue>
#include <cmath>

#define BEGIN(x) x.begin()
#define END(x) x.end()
#define ALL(x) BEGIN(x), END(x)
#define PAIR make_pair
#define VEC(type) vector<type >
#define endl '\n'
#define FIR first
#define SEC second
#define PB push_back
#define SZ(x) ((int)x.size())

#define FOR(i, A, B) for(auto i = (A);i != (B); i++)
#define FORD(i, A, B) for(auto i = (A);i != (B); i--)

#define READRANGE(begin, end) FOR(it, begin, end) cin >> *it
#define READVEC(V) READRANGE(BEGIN(V), END(V))

using namespace std;

typedef long long lint;
typedef pair<int, int> Pii;
typedef pair<int, lint> Pil;
typedef pair<lint, lint> Pll;
typedef pair<lint, int> Pli;

template<class U, class V>
istream& operator >>(istream& in, pair<U, V>& pr) {
    return in >> pr.first >> pr.second;
}

template<class U, class V>
ostream& operator <<(ostream& out, pair<U, V>& p) {
    return out << p.first << " " << p.second;
}

template<class T>
ostream& operator <<(ostream& out, vector<T> vec) {
    for (T& e : vec)
        out << e << " ";
    return out << endl;
}

// ---- BEGIN LIBRARY CODE ----
// ---- END LIBRARY CODE ----
void io_init()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
};

void solveSingleCase(int caseNo)
{
    int X;
    cin >> X;
    lint t = 0;
    while (t * (t + 1) / 2 < X)
        t++;
    cout << t << endl;
};

int main(int argc, char **argv)
{
    io_init();

    // Actual program code starts here.
    int T = 1;
    // cin >> T;
    FOR(tcase, 1, T + 1) {
        solveSingleCase(tcase);
    }
    return 0;
};


Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<iomanip>
#include<math.h>
#include<algorithm>
#include<utility>
#include<queue>
#include<string.h>
#include<string>
#include<set>
#include<functional>
using namespace std;
typedef long long LL;

int N;
LL t[101];
LL gcd(LL x,LL y){
    if(y==0){
        return x;
    }
    return gcd(y,x%y);
}
LL LCM(LL x, LL y){
    return x/gcd(x,y)*y;
}
int main(){
    cin>>N;
    LL nowLCM=1;
    
    for(int i=0;i<N;i++){
        cin >> t[i];
        nowLCM=LCM(nowLCM,t[i]);
    }

    cout << nowLCM << endl;
    return 0;
}

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

int main(){
    double a,b,c,s,l,h;
    double pi = 3.1415926535;
    cin >> a >> b >> c;
    c = c*pi/180;
    s = a*b*sin(c)/2;
    l = a + b + pow(pow(a,2) + pow(b,2) - 2*a*b*cos(c),0.5);
    h = s/a*2;
    cout << fixed << setprecision(8) << s << endl;
    cout << fixed << setprecision(8) <<  l << endl;
    cout << fixed << setprecision(8) << h << endl;
    return 0;
}


Measured memory_bytes: 3544