akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef  long long ll;
using vll=vector<ll>;
using vvll=vector<vll>;
using vi=vector<int>;
using vvi=vector<vector<int>>;
using vb=vector<bool>;
using pii=pair<int,int>;
using vpii=vector<pair<int,int>>;
using plli=pair<ll,int>;
using vplli=vector<pair<ll,int>>;
using pllll=pair<ll,ll>;
using vpllll=vector<pair<ll,ll>>;

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

//pow(llpow,modpow)
template<class T> ll llpow(ll x,T n){ll ans=1;if(x==0)ans=0;while(n){if(n&1)ans*=x;x*=x;n>>=1;}return ans;}
long long modpow(long long a, long long n, long long mod) {long long res = 1;while (n > 0) {if (n & 1) res = res * a % mod;a = a * a % mod;n >>= 1;}return res;}
//最大公約数
template<class T> inline T gcd(T x,T y){if(y==0)return x; else {return gcd(y,x%y);}}
//最小公倍数
template<class T> inline T lcm(T x,T y){return x/gcd(x,y)*y;}
//逆元
long long modinv(long long a, long long m) {long long b = m, u = 1, v = 0;while (b) {long long t = a / b;a -= t * b; swap(a, b);u -= t * v; swap(u, v);}u %= m;if (u < 0) u += m;return u;}

#define rep(i, begin_i, end_i) for (ll i = (ll)begin_i; i < (ll)end_i; i++)
//試験導入
#define irep(i, end_i, begin_i) for (ll i = (ll)begin_i-1; i >= (ll)end_i; i--)

long long INF = 1LL<<60;
ll dp[55][5001];
int main( ){
    int n,a;
    cin>>n>>a;
    vi x(n);
    rep(i,0,n)cin>>x[i],x[i]-=a;
    dp[0][n*a]=1;
    rep(i,0,n){
        rep(j,0,5001){
            dp[i+1][j+x[i]]+=dp[i][j];
            dp[i+1][j]+=dp[i][j];
        }
    }
    cout<<dp[n][n*a]-1<<endl;
    return 0;
}




Measured memory_bytes: 5584
from itertools import combinations
N = int(input())
m = [0] * 5
for _ in range(N):
    S = input()
    cand = ("M", "A", "R", "C", "H")
    if S[0] in cand:
        m[cand.index(S[0])] += 1
ans = 0
for i, j, k in combinations(range(5), 3):
    ans += m[i] * m[j] * m[k]
print(ans)


Measured memory_bytes: 3060
#include<iostream>
#include<vector>
#include <cmath>
#include <map>
#include <algorithm>
using namespace std;
int main(void){
    double a,b,c,d;
    cin >> a >> b >> c >>d;
    if(abs(a-c)<=d){
        cout << "Yes" <<endl;
    }else if(abs(a-b)<=d&&abs(b-c)<=d){
        cout <<"Yes"<<endl;
    }else{
        cout <<"No"<<endl;
    }

    
    return 0;
}

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

using namespace std;


int main(){
    
    vector<bool> prime(100001, true);
    prime[0] = false;
    prime[1] = false;
    
    vector<int> prime_num(100001, 0);
    prime_num[0] = prime_num[1] = 0;
    
    for (int i = 2; i <= 100000; i++) {
        prime_num[i] = prime_num[i-1];
        if (prime[i]) {
            if (prime[(i+1)/2] && i%2 == 1) {
                prime_num[i] += 1;
            }
            for (int j = i*2; j <= 100000; j += i) {
                prime[j] = false;
            }
        }
    }
    
    int Q;
    cin >> Q;
    vector<int> l(Q);
    vector<int> r(Q);
    vector<int> ans(Q);
    
    
    for (int i = 0; i < Q; i++) {
        cin >> l[i] >> r[i];
        ans[i] = prime_num[r[i]] - prime_num[l[i]-1];
    }
    
    for (int i = 0; i < Q; i++) {
        
        cout << ans[i] << endl;
        
    }
    
    
}

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

L = sorted(list(map(int, input().split())))

ans = 0
for i in range(N-2):
    for j in range(i+1, N-1):
        for k in range(j+1, N):
            if L[i] < L[j] < L[k] and L[i] + L[j] > L[k]:
                ans += 1
print(ans)


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

class Main{
    public static void main(String[] args){
        FastScanner fs = new FastScanner();
        char[] s = fs.next().toCharArray();
        int res = 0;
        int left = 0;
        int right = s.length-1;
        while(left<=right){
            if(s[left]!=s[right])res++;
            left++;
            right--;
        }
        System.out.println(res);
    }
    static class FastScanner{
        private final InputStream in = System.in;
        private final byte[] buffer = new byte[1024];
        private int ptr = 0;
        private int buflen = 0;

        private boolean hasNextByte(){
            if(ptr < buflen){
                return true;
            }else{
                ptr = 0;
                try{
                    buflen = in.read(buffer);
                }catch(IOException e){
                    e.printStackTrace();
                }
                if(buflen <= 0){
                    return false;
                }
            }
            return true;
        }

        private int readByte(){
            if(hasNextByte())return buffer[ptr++];
            else return -1;
        }

        private boolean isPrintableChar(int c){
            return 33<=c && c<=126;
        }

        public boolean hasNext(){
            while(hasNextByte() && !isPrintableChar(buffer[ptr]))ptr++;
            return hasNextByte();
        }

        public String next(){
            if(!hasNext()) throw new NoSuchElementException();
            StringBuilder sb = new StringBuilder();
            int b = readByte();
            while(isPrintableChar(b)){
                sb.appendCodePoint(b);
                b = readByte();
            }
            return sb.toString();
        }

        public long nextLong(){
            if(!hasNext()) throw new NoSuchElementException();
            long n = 0;
            boolean minus = false;
            int b = readByte();
            if(b == '-'){
                minus = true;
                b = readByte();
            }
            if(b < '0' || '9' < b){
                throw new NumberFormatException();
            }
            while(true){
                if('0' <= b && b<='9'){
                    n*=10;
                    n+=b-'0';
                }else if(b==-1 || !isPrintableChar(b)){
                    return minus ? -n : n;
                }else{
                    throw new NumberFormatException();
                }
                b = readByte();
            }
        }
        public int nextInt(){
            long nl = nextLong();
            if(nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)throw new NumberFormatException();
            return (int)nl;
        }
        public double nextDouble(){return Double.parseDouble(next());}
    }
}

Measured memory_bytes: 21204
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll x, y;
ll a[1010];
ll gcd(ll x, ll y){
	if (y == 0) return x;
	return gcd(y, x%y);
}
int main() {
	scanf("%lld%lld", &x, &y);
	x = gcd(x, y);
	int lena = 1;
	for (ll i = 2; i <= sqrt(x); i++){
		if (x%i == 0){
			a[lena++] = i;
			while (x%i == 0) x = x/i;
		}
	}
	if(x > 1) lena++;
	printf("%d\n", lena);
	return 0;
}

Measured memory_bytes: 256
import itertools
import math
import statistics

N = int(input())
x = []
y = []
for i in range(N):
    e1,e2 = map(int,input().split())
    x.append(e1)
    y.append(e2)

lengths = []
for pattern in itertools.permutations(range(N)):
    length = 0
    for path in [(pattern[i],pattern[i+1]) for i in range(N-1)]:
        length += math.sqrt((x[path[0]]-x[path[1]])**2 + (y[path[0]]-y[path[1]])**2)
    lengths.append(length)

# 平均
print(statistics.mean(lengths))

Measured memory_bytes: 6540
using System;

namespace B___1_21
{
    class Program
    {
        static void Main(string[] args)
        {
            var input=Console.ReadLine().Split(' ');
            var c = int.Parse(input[0] + input[1]);
            for (var i = 1; i <= 1000; i++)
            {
                if (i * i == c)
                {
                    Console.WriteLine("Yes");
                    return;
                }
            }
            Console.WriteLine("No");
        }
    }
}

Measured memory_bytes: 11092
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc =new Scanner(System.in);
    int N =sc.nextInt();
    long A[] =new long[N];
    double e =Math.pow(10,18);
    long f =(long) e;long l =1;
    for(int j=0;j<N;j++){
      A[j]=sc.nextLong();if(A[j]==0){System.out.println(0);System.exit(0);}}
    for(int i=0;i<N;i++){
      l=l*A[i];
      if(l>f||l<=0){System.out.println(-1);System.exit(0);}}
    System.out.println(l);
  }
}

Measured memory_bytes: 61476
/* Note:
Check constants at the beginning of the code.
    N is set to 4e5 but be careful in problems with large constant factor.
    Setting N in every problem is more effective.
Check corner cases.
    N = 1
No def int long long for now.
Add something here.

*/
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define MAX 10000

using namespace std;
typedef long long ll;

int mod = 1000000007;
ll dp[100005];;

ll gcd(long long a,long long b){

  if(b == 0)
    return a;
  else return gcd(b,a%b);
}

bool compare(pair<int,int>p1, pair<int,int>p2){

  return p1.second > p2.second;
 }

 // sorting the map when the first is string ans second is the integer
 bool sortbyval(pair<string,int>a, pair<string,int>b){
   return a.second < b.second;
 }

int main(){

  long long h,w,lens;
  cin>>h>>w;
 vector<string>v;

 for(int i=0;i<h;i++){
    string x;
    cin>>x;
    v.push_back(x); }

  lens =w+2;

 for(int i=0;i<lens;i++)
    cout<<"#";

 cout<<endl;

 for(int i=0;i<h;i++){

    cout<<"#"<<v[i]<<"#"<<endl;
 }


 for(int i=0;i<lens;i++)
    cout<<"#";


 return 0;
}


Measured memory_bytes: 3636
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<functional>
#include<map>
#include<cstdlib>
#include<complex>
#include<numeric>
#include<set>
#include<deque>
#include<queue>

using namespace std;
using Int = long long;
Int INF = 1LL << 60;
const Int MOD = 1000000000 + 7;

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	Int N;
	cin >> N;

	string S;
	cin >> S;

	Int ans = 1;
	char temp=S[0];

	for (Int i = 0; i < N-1; i++) {
		if (S[i + 1] == temp)continue;
		else {
			temp = S[i + 1];
			ans++;
		}
	}

	cout << ans << "\n";

}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define F first
#define S second
#define PB push_back
#define REP(i,a,b) for (int i = a ; i <= b ; i++)
#define REPI(i,a,b) for (int i = a ; i >= b ; i--)
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;

const int OO = 1e9+7;
const int MOD = 1e9+7;
const int N = 1e5+7;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    //freopen("teleport.in","r",stdin);
    //freopen("teleport.out","w",stdout);
	ll k,a,b;
	cin >> k >> a >> b;
	ll ans = k+1;
	k -= a+1;
	if (b-a > 0 && k >= 0) ans = max(b+(b-a)*(k/2) + (k%2),ans);
	cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<string>
#include<utility>
#include<queue>
#include<tuple>
#include<stdio.h>
#define rep(i, n) for(int i=0;i<n;i++)
using namespace std;
int main(){
	string s;
	cin>>s;
	int a=s.size(), b=s.size();
	a=(a-1)/2;
	b=(b+3)/2-1;
	bool f=0;
	rep(i, s.size()){
		if(s[i]!=s[s.size()-1-i])
			f=1;
	}
	rep(i, a){
		if(s[i]!=s[a-1-i])
			f=1;
	}
	for(int i=b;i<s.size();i++){
		if(s[i]!=s[s.size()-1-i])
			f=1;
	}
	if(f==0)
		cout<<"Yes"<<endl;
	else
		cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
        int a,b,c,s;
        scanf("%d%d%d",&a,&b,&c);

        if(a==5){
                if(b==5 && c==7 || b==7 && c==5)printf("YES\n");
                else printf("NO\n");
        }
        else if(a==7){
                if(b==5 && c==5)printf("YES\n");
                else printf("NO\n");
        }
        return 0;
}


Measured memory_bytes: 1624
#include <iostream>
#include <limits>
#include <vector>

using namespace std;

int N, A, B, C;
vector<int> L;

// genzai no level, a, b, c de saishouno
int mp(int level, int a, int b, int c)
{
  if (level == N) {
    if (a == 0 || b == 0 || c == 0) {
      return 1000000;
    } else {
      return abs(a-A)+abs(b-B)+abs(c-C);
    }
  }

  int ret_a = mp(level+1, a+L[level], b, c) + ((a == 0) ? 0 : 10);
  int ret_b = mp(level+1, a, b+L[level], c) + ((b == 0) ? 0 : 10);
  int ret_c = mp(level+1, a, b, c+L[level]) + ((c == 0) ? 0 : 10);
  int ret_null = mp(level+1, a, b, c);
  
  return min(min(min(ret_a, ret_b), ret_c), ret_null);
}


int main(int argc, char* argv[])
{
  cin >> N >> A >> B >> C;

  for (int i = 0; i < N; i++) {
    int l; cin >> l;
    L.push_back(l);
  }

  cout << mp(0, 0, 0, 0) << endl;
  
  return 0;
}


Measured memory_bytes: 256
/*
　　こんにちは。あたしはｶｳｶﾞｰﾙ。
　　RedcoderになるためAtCoderを巡る旅をしてます。

　　　 　＿_
　　　 ヽ|＿_|ノ　　　　ﾓｫ
　　　　||‘‐‘||ﾚ　　_)_, ―‐ 、
　　　　/(Ｙ (ヽ＿ /・ ヽ　　   ￣ヽ
　　　　∠ ＿ ゝ　 ｀^ヽ ﾉ.::::_(ノヽ
　　　　 _/ヽ　 　　  /ヽ￣￣￣/ヽ
*/

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define dump(x) cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl

#define rep(i, n) REP(i, 0, n)                  // 0, 1, ..., n-1
#define REP(i, x, n) for(int i = x; i < n; i++) // x, x + 1, ..., n-1
#define FOREACH(x, a) for(auto &(x) : (a))

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()

#define COUT(x) cout << (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;
}

const ll INF = 1LL << 60;
ll dp[100010];

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

    int N;
    cin >> N;
    vector<int> h(N);
    rep(i, N) cin >> h[i];
    rep(i, 100010) dp[i] = INF;

    dp[0] = 0;

    REP(i, 1, N) {
        chmin(dp[i], dp[i - 1] + abs(h[i] - h[i - 1]));
        if(i > 1) chmin(dp[i], dp[i - 2] + abs(h[i] - h[i - 2]));
    }

    COUT(dp[N - 1]);
}


Measured memory_bytes: 1408
n = input()
if 1 <= int(n[2:]) <= 12 and 1 <= int(n[:2]) <= 12:
    print('AMBIGUOUS')
elif 1 <= int(n[:2]) <= 12:
    print('MMYY')
elif 1 <= int(n[2:]) <= 12:
    print('YYMM')
else:
    print('NA')

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

using namespace std;
using ll =long long;
#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
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 coY() {cout <<"Yes"<<endl;}
void coN(){cout <<"No"<<endl;}
const ll INF = 1LL << 60;
const int mod = 1e9+7;
//Write From this Line

int main()
{
	int n , q ;
	cin >> n >> q ;
	string s;
	cin >> s;
	//累積和
	vector<int> b(n+1);
	int l[q],r[q];
	rep(i,q) cin >> l[i] >> r[i];
	b[0] = 0 ;
	b[1] = 0 ;
	for(int i = 2 ; i <= n ; i ++){
		if(s[i-2] == 'A' && s[i-1] == 'C'){
			b[i] = b[i-1] + 1;
		} else {
			b[i] = b[i-1];
		}
	}
	rep(i,q){
		int L = l[i] , R = r[i] ;
		cout << b[R] - b[L]  << endl;
	}

}


Measured memory_bytes: 2176
#include <bits/stdc++.h>
using namespace std;
#define modd 1000000000000000000
int main()
{
    long long x,y;
    while(~scanf("%lld%lld",&x,&y))
    {
        long long sum;
        long long ans=0;
        while(x<=y)
        {
            ans++;
            x*=2;
        }
        cout<<ans<<endl;
    }
}


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

int main() {
    int n, a, b;
    int sum_nb;
    int total = 0;

    cin >> n >> a >> b;
    for (int i = 1; i <= n; i++) {
        sum_nb = i/10000 + (i%10000)/1000 + (i%1000)/100 + (i%100)/10 + i%10;
        if (a <= sum_nb && sum_nb <= b) {
            total += i;
        }
    }
    cout << total << endl;
    return 0;
}

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

#define d(x) cerr << #x ":" << x << endl;
#define dd(x, y) cerr << "(" #x "," #y "):(" << x << "," << y << ")" << endl
#define rep(i, n) for (int i = (int)(0); i < (int)(n); i++)
#define repp(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define all(v) v.begin(), v.end()
#define dump(v)                  \
    cerr << #v ":[ ";            \
    for (auto macro_vi : v) {    \
        cerr << macro_vi << " "; \
    }                            \
    cerr << "]" << endl;
#define ddump(v)                           \
    cerr << #v ":" << endl;                \
    for (auto macro_row : v) {             \
        cerr << "[";                       \
        for (auto macro__vi : macro_row) { \
            cerr << macro__vi << " ";      \
        }                                  \
        cerr << "]" << endl;               \
    }
using lint       = long long;
const int INF    = 1e9;
const lint LINF  = 1e18;
const lint MOD   = 1e9 + 7;
const double EPS = 1e-10;

int main() {
    int N;
    cin >> N;
    vector<lint> A(N, 0);
    lint ans = 0;
    rep(i, N) { cin >> A[i]; }

    for (int i = 0; i < N - 1; i++) {
        if (A[i] == 0) continue;
        ans += A[i] / 2;
        A[i] = A[i] % 2;
        if (A[i] == 1) {
            if (A[i + 1] != 0) {
                ans++;
                A[i]--;
                A[i + 1]--;
            }
        } else {
            continue;
        }
    }
    ans += A[N - 1] / 2;
    dump(A);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
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; }
#define rep(i,n) for(int i=0;i<(int)(n);i++)
const int mod = 1e9+7;
const long long INF = 1LL << 60;
typedef long long ll;
int main(){
    string s,t;
    cin >> s >> t;
    vector<int> start(26, -1);
    vector<int> goal(26, -1);
    for(int i = 0; i < s.size(); i++){
        int a = s[i] - 'a';
        int b = t[i] - 'a';
        if(start[a] != -1 || goal[b] != -1){
            if(start[a] != b || goal[b] != a){
                cout << "No" << endl;
                return 0;
            }
        }
        //swapする
        start[a] = b;
        goal[b] = a;
    }
    cout << "Yes" << endl;
}


Measured memory_bytes: 776
# 2019-11-24 20:59:47(JST)
import sys
from string import ascii_uppercase as alphabet

# alpha_num = dict((alpha, num) for num, alpha in enumerate(alphabet, 0))
alpha_ind = dict((alphabet[i], i) for i in range(26))

def main():
    n, s = sys.stdin.read().split()
    n = int(n)

    t = ''
    for char in s:
        t += alphabet[(alpha_ind[char] + n) % 26]
    
    print(t)

if __name__ == '__main__':
    main()


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

#define DEBUG(x) cout<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cout<<#v<<":";for(int i=0;i<v.size();i++) cout<<" "<<v[i]; cout<<endl

typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
const int inf = 1000000001;
const ll INF = 1e18 * 4;
#define MOD 1000000007
#define mod 1000000009
#define pi 3.14159265358979323846
#define Sp(p) cout<<setprecision(15)<<fixed<<p<<endl;
int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };

int main() {
	int n, i;
	cin >> n;
	string s, t;
	cin >> s >> t;
	for (i = n; i >= 0; i--) {
		if (s.substr(n - i, i) == t.substr(0, i)) {
			cout << 2 * n - i << endl;
			return 0;
		}
	}
	cout << 2 * n << endl;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 7)

N = int(input())
edge = [[] for _ in range(N + 1)]
for _ in range(N - 1):
    x, y = map(int, input().split())
    x -= 1
    y -= 1
    edge[x].append(y)
    edge[y].append(x)

topo = []
parent = [-1] * N
node = [0]
while node:
    s = node.pop()
    topo.append(s)
    for t in edge[s]:
        if t == parent[s]:
            continue
        parent[t] = s
        node.append(t)

memo = [0] * N  # ノードiより下の情報をマージしたもの
res = [0] * N  # 求めたいやつ、ノードiの上に出ていく情報
for s in reversed(topo):
    for t in edge[s]:
        if t == parent[s]:
            continue
        memo[s] = max(memo[s], res[t])
    res[s] = memo[s] + 1


TD = [0] * N  # 上からノードiへ向かう辺の情報
for s in topo:
    acc = TD[s]
    for t in edge[s]:
        if t == parent[s]:
            continue
        TD[t] = max(TD[t], acc)
        acc = max(acc, res[t])
    acc = 0
    for t in reversed(edge[s]):
        if t == parent[s]:
            continue
        TD[t] = max(TD[t], acc) + 1
        acc = max(acc, res[t])
        res[t] = max(memo[t], TD[t]) + 1


ans = [2 * (N - 1) - res[i] + 1 for i in range(N)]
print(*ans, sep="\n")



Measured memory_bytes: 40636
#include <iostream>
#include <cmath>
#include <vector>
using namespace std;
bool check1(long long n){
	long long x=sqrtl(n);
    return (x*x==n? true: false); 
}
bool check2(vector<long long> a, vector<long long> b){
    long long res=0;
    for(int i=0; i<a.size(); i++){
        res+=(a[i]-b[i])*(a[i]-b[i]);
    }
    return (check1(res)==true? true: false);
}
int main() {
	int n, d;
	cin >> n >> d;
	vector<vector<long long>> a;
	for(int i=0; i<n; i++){
		vector<long long> b;
	    for(int j=0; j<d; j++){
	    	long long x;
	    	cin >> x;
	    	b.push_back(x);
	    }
	    a.push_back(b);
	}
	int res=0;
	for(int i=0; i<n; i++){
	    for(int j=i+1; j<n; j++){
	        if(check2(a[i], a[j])==true) res++;
	    }
	}
	cout << res;
}

Measured memory_bytes: 256
/* ****mittal**** */
#include<bits/stdc++.h>
#define ll          long long int 
#define pb          push_back
#define endl        '\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define jell        998244353
#define rep(i,a,b)    for(ll int i=a;i<b;i++)
#define repr(i,a,b)   for(ll int i=a;i>=b;i--)
#define lbnd    lower_bound
#define ubnd        upper_bound
#define mp          make_pair
#define DEC(N)  cout << std::fixed; cout << setprecision(N);
using namespace std;
ll add(ll x,ll y)
{
return (x%hell+y%hell)%hell;
}
ll mul(ll x,ll y)
{
return ((x%hell)*(y%hell))%hell;
}
ll sub(ll x,ll y)
{
return (x-y+hell)%hell;
}
#define N  100005
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll t=1;
   //cin>>t;
    for(int ok=1;ok<=t;ok++)
    {
      ll n;
      cin>>n;
      ll ans=0;
      for(int i=1;i<=n;i++)
      {
        for(int j=1;j<=n;j++)
        {
            for(int k=1;k<=n;k++)
            {
                ans+=__gcd(i,__gcd(j,k));
            }
        }
      }  
      cout<<ans;
     
    }
    return 0;
}

Measured memory_bytes: 3612
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int bs(vector<int> &v, int x){
  int l = 0, r = v.size()-1;
  int n = v.size();
  while(l<=r){
    int md = (l+r)/2;
    if(v[md]>x) r = md-1;
    else l = md+1;
  }
  if(v[r]!=x) return x;
  else {
    int i= 1;
    for(; (r-i)>=0&&(r+i)<n; i++) {
      if((r-i)>=0){
        if(v[r-i] != x-i) return x-i;
      } 
      if((r+i)<n){
        if(v[r+i] != x+i) return x+i;
      }     
    }
    if((r-i)<0) return x-i;
    else if((r+i)==n) {
          if(v[r-i]==x-i) return x+i;
          else return x-i;
        }
  }
}
int main()
{ 
  int x, n; cin >> x>> n;
  vector<int> v(n);
  for(int i=0; i<n ;i++) cin >> v[i];
  if(n == 0) { cout<<x; return 0; }
  sort(v.begin(), v.end());
  cout<<bs(v,x);
  return 0;
}

Measured memory_bytes: 3660
#include <stdio.h>
#include <math.h>

double pi(double ang){
    double rag;
    rag=acos(-1)*ang/180;
    return rag;
}
int main(void){
    double a, b, c, ang_C, rag_C, S, L, h, PI;
    scanf("%lf %lf %lf", &a, &b, &ang_C);
    
    rag_C=pi(ang_C);
    c=sqrt(a*a+b*b-2*a*b*cos(rag_C));
    L=a+b+c;
    
    S=a*b*sin(rag_C)/2;
    
    h=2*S/a;
    printf("%lf\n%lf\n%lf\n", S, L, h);
    return 0;
}



Measured memory_bytes: 2104
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long a = Long.parseLong(sc.next()) - 1;
        long b = Long.parseLong(sc.next());
        long c = Long.parseLong(sc.next());
        long d = Long.parseLong(sc.next());
        long gcd = (c * d) / getGcd(c, d);
        long bb = b - (b / c) - (b / d) + (b / gcd);
        long aa = a - (a / c) - (a / d) + (a / gcd);
        System.out.println(bb - aa);
    }

    public static long getGcd(long a, long b) {
        long tmp;
        long x = 0;
        long y = 0;
        if (x >= y) {
            x = a;
            y = b;
        } else {
            x = b;
            y = a;
        }
        while ((tmp = x % y) != 0) {
            x = y;
            y = tmp;
        }
        return y;
    }
}

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


int dh[]={0,-1,0,1};
int dw[]={1,0,-1,0};

struct State{
    int h,w;
    int dir;
};

int main(){
    int n,m;
    cin>>n>>m;
    n+=2;
    m+=2;
    vector<string> s(n,"");
    for(int i=0;i<m;i++){
        s[0]+="#";
        s[n-1]+="#";
    }
    for(int i=1;i<n-1;i++){
        cin>>s[i];
        s[i]="#"+s[i]+"#";
    }

    vector<vector<int>> flag(n,vector<int>(m,0));

    State ini;
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            if(s[i][j]=='>') ini=State{i,j,0};
            if(s[i][j]=='^') ini=State{i,j,1};
            if(s[i][j]=='<') ini=State{i,j,2};
            if(s[i][j]=='v') ini=State{i,j,3};
        }
    }
    auto forward=[&](State st){
        int dr=(st.dir+3)%4;
        if(s[st.h+dh[dr]][st.w+dw[dr]]!='#'){
            return State({st.h+dh[dr],st.w+dw[dr],dr});
        }
        if(s[st.h+dh[st.dir]][st.w+dw[st.dir]]=='#'){
            return State{st.h,st.w,(st.dir+1)%4};
        }
        return State({st.h+dh[st.dir],st.w+dw[st.dir],st.dir});
    };
    State st=ini;
    while(true){
        int ch=1<<st.dir;
        //cerr<<st.h<<" "<<st.w<<" "<<st.dir<<endl;
        if(flag[st.h][st.w]&ch){
            cout<<-1<<endl;
            return 0;
        }
        flag[st.h][st.w]|=ch;
        if(s[st.h][st.w]=='G') break;
        st=forward(st);
    }
    int res=0;
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            res+=(int)(flag[i][j]>0);
        }
    }
    cout<<res<<endl;
    return 0;        
}


Measured memory_bytes: 3244
#include <iostream>

using namespace std;

int a[100000], b[100000], mi, ma = 0, n, t, c;

int main() {
	cin >> n >> t;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	mi = a[0];
	for (int i = 0; i < n; i++) {
		b[i] = a[i] - mi;
		if (b[i] < 0)mi = a[i];
		if (b[i] > ma)ma = b[i];
	}

	for (int i = 0; i < n; i++) {
		if (b[i] == ma)c++;
	}

	cout << c << endl;
}

Measured memory_bytes: 1024
#include<iostream>
    using namespace std;
    int main(){
     int A,N,j,k;
     cin>>N;
     cin>>A;
     k=N/500;
      for(j=0;j<=A;j++){
        if(N==500*k+j) {
        cout<<"Yes"<<endl;
        return 0;
       }
     }
     cout<<"No"<<endl;
     return 0;
    }

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

// #define int long long
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) int(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;

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

const ll INF = 1e15;
const int MOD = 1e9+7;
const ll LINF = 1e18;



signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  string s; cin>>s;
  ll n=s.size();
  
  string r=regex_replace(s,regex("BC"), "X");
  // cout<<r<<endl;
  ll ans=0;
  ll cnt=0;
  rep(i,n){
    if(r[i]=='A') cnt++;
    else if(r[i]=='X') ans+=cnt;
    else cnt=0;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 916
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize ("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace __gnu_pbds;
using namespace std;
#define gcd(a,b) __gcd(a,b)
#define ll long long int
#define ld double
#define pi pair<ll,ll>
#define pb push_back
#define pf push_front
#define pu push
#define po pop
#define fi first
#define se second
#define mk make_pair
#define ve vector
#define lr(n) for(ll i=0;i<n;i++)
#define all(x) x.begin(),x.end()
#define be begin
#define sz(a) (ll)a.size()
#define INF 1e18
 
typedef tree <ll, null_type, less <ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
// order_of_key(val): returns the number of values less than val
// find_by_order(k): returns an iterator to the kth largest element (0-based)
 
ll mod=1e9+7;
// ll gcd(ll a, ll b){
//     if(a<b) swap(a,b);
//     if(b==0) return a;
//     return gcd(b,a%b);
// }
 
ll fun(ll x, ll y){
    ll rem=1;
    while(y!=0){
        if(y%2==1){
            rem=(rem*x)%mod;
        }
        x=(x*x)%mod;
        y/=2;
    }
    return rem;
}

ll fact[200001];
ll ifact[200001];
ll dp[3001]={0};

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll h,w,n;
	cin>>h>>w>>n;
	fact[0]=1; ifact[0]=1;
	for(ll i=1;i<=(h+w);i++) fact[i]=(fact[i-1]*i)%mod;
	for(ll i=1;i<=(h+w);i++) ifact[i]=fun(fact[i],mod-2);
	ve<pi>ar(n+1);
	lr(n){
		cin>>ar[i].fi>>ar[i].se;
		ar[i].fi--; ar[i].se--;
	}
	ar[n]=mk(h-1,w-1);
	sort(all(ar));
	for(ll i=0,y,a,b;i<=n;i++){
		dp[i]=fact[ar[i].fi+ar[i].se]*ifact[ar[i].fi]%mod*ifact[ar[i].se]%mod;
		for(ll j=i-1;j>=0;j--){
			if(ar[j].se>ar[i].se) continue;
			a=ar[i].fi-ar[j].fi;b=ar[i].se-ar[j].se;
			y=fact[a+b]*ifact[a]%mod*ifact[b]%mod;
			dp[i]=(dp[i]+mod-dp[j]*y%mod)%mod;
		}
	}
	cout << dp[n] << "\n";
	return 0;
}

Measured memory_bytes: 3456
import java.util.Scanner;

public class Main {
	public static void main (String args[]){
		Scanner sc = new Scanner(System.in);
		int score[]=new int[100];
		while(true){
		int n= sc.nextInt();
		if(n==0){ 
			break;
		}else{
		score[0]=sc.nextInt();
		int Sum=score[0];
		int Max= score[0];
		int min = score[0];
	for(int i=1;i<n;i++){
		score[i]=sc.nextInt();
		Sum = Sum+score[i];
		if(Max<score[i]){
			Max=score[i];
		}
		if(min>score[i]){
			min=score[i];
		}
	}
	System.out.println((Sum-Max-min)/(n-2));
	}
		}
	}
}

Measured memory_bytes: 29108
#include "bits/stdc++.h"
using namespace std;
#define fst first
#define scd second
int main()
{
	int n, ans = 0;	
	scanf("%d", &n);
	for(int i = 0, mi = 1e9, p; i < n; ++i)
	{
		scanf("%d", &p);
		ans += p <= mi;
		mi = min(mi, p);
	}
	printf("%d\n", ans);
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<numeric>
#include<algorithm>
typedef long long ll;
using namespace std;
int main()
{
    int M, N, sum, idx;   cin >> N >> M;
    std::vector<int> a(N);
    for(int i=0; i<N; i++){
        cin >> a[i];
    }
    sum = std::accumulate(a.begin(), a.end(), 0);
    if(sum % (4*M) == 0)    idx = sum/(4*M) - 1;
    else    idx = sum/(4*M);
    std::sort(a.begin(),a.end());
    for(int i=N-1; i>=N-M; i--){
        if(a[i] <= idx){
            cout << "No";
            return 0;
        }
    }
    cout << "Yes";
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define rep(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define o(a) cout<<a<<endl
#define int long long
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

int d[110],w,q;

int check(int wide){
	int cnt=0;
	rep(i,0,w-wide+1){
		bool can=true;
		rep(j,0,wide){
			if(d[i+j]) can=false;
		}
		if(can) return i;
	}
	return -1;
}

signed main(){
	while(1){
		cin>>w>>q;
		if(w+q==0) break;
		char c;
		int id,wide;
		rep(i,0,w) d[i]=0;
		d[w]=1;

		map<int,pii> mp;
		rep(i,0,q){
			cin>>c;
			if(c=='s'){
				cin>>id>>wide;
				mp[id].first=wide;
				int ind=check(wide);
				if(ind==-1) o("impossible");
				else{
					o(ind);
					mp[id].second=ind;
					rep(j,0,wide){
						d[ind+j]=1;
					}
				}
			}else{
				cin>>id;
				rep(j,0,mp[id].first){
					d[mp[id].second+j]=0;
				}
			}
		}
		o("END");
	}
}

Measured memory_bytes: 1196
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define x first
#define y second
#define ndl '\n'
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define up_b upper_bound
#define low_b lower_bound
#define sz(x) (int)x.size()
#define bit __builtin_popcount
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()

using namespace std;
using namespace __gnu_pbds;

template<typename T> using indexed_set = tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<int, ull> piu;
typedef vector<vector<int>> matrix;

const ll INF = 1e18 + 123;
const ld EPS = 1e-9;
const int inf = 1e9 + 123;
const int MOD = 1e9 + 7;
const int N = 5e5 + 13;
const int M = 1e6 + 123;
const double pi = acos(-1.0);
const int dx[] = {0, 0, 1, -1};
const int dy[] = {1, -1, 0, 0};

vector<int> g[N];

int col[N], mx = 0, id[N], ans[N];

int main(){
    #ifdef KAZAKH
        freopen("input.txt", "r", stdin);
    #endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    for (int i = 1; i < n; i++){
        int u, v;
        cin >> u >> v;
        g[u].pb(v);
        id[v] = i;
    }
    for (int i = 1; i <= n; i++){
        int cnt = 1;
        for (int to : g[i]){
            if (col[i] == cnt) cnt++;
            col[to] = cnt++;
            ans[id[to]] = col[to];
        }
        mx = max(mx, cnt-1);
    }
    cout << mx << ndl;
    for (int i = 1; i < n; i++){
        cout << ans[i] << ndl;
    }
    return 0;
}


Measured memory_bytes: 18048
N,L = list(map(int,input().split()))
a = list(map(int,input().split()))
a.append(0)
b = []
res = "Impossible"

for i in range(N):
    if L <= (a[i]+a[i+1]):
        count = i
        res = "Possible"
        break

if res =="Possible":
    for j in range(count):
        b.append(j+1)
    for k in range(count+1,N)[::-1]:
        b.append(k)
    
    print(res)
    for l in range(len(b)):
        print(b[l])
else:
    print(res)



Measured memory_bytes: 14060
#include <iostream>
#include <algorithm>
#include <string>
#include <queue>
#include <vector>
using namespace std;

typedef long long ll;

/*
const ll M = 1000000007;
vector<ll> fac(3001);
vector<ll> ifac(3001);
ll mpow(ll x, ll n){
    ll ans = 1;
    while(n != 0){
        if(n&1) ans = ans*x % M;
        x = x*x % M;
        n = n >> 1;
    }
    return ans;
}
 
ll comb(ll a, ll b){
    if(a == 0 && b == 0)return 1;
    if(a < b || a < 0 || b < 0)return 0;
    ll tmp = ifac[a-b]* ifac[b] % M;
    return tmp * fac[a] % M;
}
*/


ll lcm(ll a,ll b){
 
  ll r, x, tmp;
  x = a * b;
  if(a<b){
    tmp = a;
    a = b;
    b = tmp;
  }
 
  r = a % b;
  while(r!=0){
    a = b;
    b = r;
    r = a % b;
  }
  return x/b;
}

ll gcd(ll a ,ll b){
    if(a==0){return b;}
    else if(b==0){return a;}
    else{
    ll tmp,r;
    if(a<b){
        tmp = a;
        a = b;
        b = tmp;
    }
    
    r = a % b;
    while(r!=0){
        a = b;
        b = r;
        r = a % b;
    }
    return b;
    }
}




int main(void){
    const ll M = 1000000007;
    ll n,x,y;
    x=0;
    y=0;
    string ans;
    cin >> n;
    ll a[n];
    for(ll i=0;i<n;i++)cin >> a[i];
    for(ll i=0;i<n;i++){
        if(a[i]<=x-2)y=-1;
        x = max(a[i],x);
    }
    if(y==0)ans = "Yes";
    else ans = "No";
    
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+5;
const int inf=0x3f3f3f3f;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //freopen(".in","r",stdin);
    //freopen(".out","w",stdout);
    int x;
    cin>>x;
    if(x==0)
    	cout<<1<<endl;
    else if(x==1)
    	cout<<0<<endl;
	return 0;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;

int n;
ll a[123456],b[123456];
ll ans1,ans2;

int main(){

cin>>n;

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

b[0]=a[0];

//先頭が正
if(b[0]>0) ans1=0LL;
else if(b[0]==0){
    ans1=1LL; b[0]=1LL;
}
else if(b[0]<0){
    ans1=1LL-b[0]; b[0]=1LL;
}
for(int i=1; i<n; i++){
    if(b[i-1]>0){
        if(b[i-1]+a[i]>=0){
            ans1+=b[i-1]+a[i]+1LL;
            b[i]=-1LL;
        }
        else b[i]=b[i-1]+a[i];
    }
    else{
        if(b[i-1]+a[i]<=0){
            ans1+=1LL-(b[i-1]+a[i]);
            b[i]=1LL;
        }
        else b[i]=b[i-1]+a[i];
    }
  }

b[0]=a[0];

//先頭が負
if(b[0]<0) ans2=0LL;
else if(b[0]==0){
    ans2=1LL; b[0]=-1;
}
else if(b[0]>0){
    ans2=1+b[0]; b[0]=-1;
}
for(int i=1; i<n; i++){
    if(b[i-1]>0){
        if(b[i-1]+a[i]>=0){
            ans2+=b[i-1]+a[i]+1LL;
            b[i]=-1LL;
        }
        else b[i]=b[i-1]+a[i];
    }
    else{
        if(b[i-1]+a[i]<=0){
            ans2+=1LL-(b[i-1]+a[i]);
            b[i]=1LL;
        }
        else b[i]=b[i-1]+a[i];
    }
  }

cout<<min(ans1,ans2)<<endl;

return 0;
 
}

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

int main() {
	int N,K;
	cin >> N >> K;
	vector<int>vec(N,100);
	for(int i=0;i<K;i++){
		int d;
		cin >> d;
		for(int j=0;j<d;j++){
			int a;
			cin >> a;
			vec.at(a-1)=0;
		}
	}
	int count =0;
	for(int i=0;i<N;i++){
		if(vec.at(i)!=0){
			count++;
		}


	}
	cout << count << endl;
}



Measured memory_bytes: 3596
//#pragma GCC optimize("O-fast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
//#pragma comment(linker, "/STACK:367077216")

#include <iostream>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef long double ld;

#define pii pair<int, int>
#define F first
#define S second
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define pop pop_back

vector <int> c;
vector <vector <int>> a;
int n, m, x;

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	cin >> n >> m >> x;
	c.resize(n);
	a.resize(n);
	for (int i = 0; i < n; ++i) {
		cin >> c[i];
		for (int j = 0; j < m; ++j) {
			int x; cin >> x;
			a[i].push_back(x);
		}
	}
	int ans = 1000000000;
	vector <int> check(m, 0);
	for (int mask = 0; mask < (1 << n); ++mask) {
		int cost = 0;
		for (int i = 0; i < n; ++i) {
			if (mask & (1 << i)) {
				cost += c[i];
				for (int j = 0; j < m; ++j) {
					check[j] += a[i][j];
				}
			}
		}
		bool ok = true;
		for (int i = 0; i < m; ++i) {
			if (check[i] < x) {
				ok = false;
				break;
			}
		}
		if (ok) {
			ans = min(ans, cost);
		}
		fill(all(check), 0);
	}
	cout << ((ans == 1000000000) ? -1 : ans);
	return 0;
}


Measured memory_bytes: 3672
#include <bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL); 

#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define in insert
#define ld long double


#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...) 1
#endif
template<class T> ostream& operator<<(ostream &os, vector<T> V) {os << "[ "; for(auto v : V) os << v << " "; return os << "]";}
template<class L, class R> ostream& operator<<(ostream &os, pair<L,R> P) {return os << "(" << P.first << "," << P.second << ")";}
template <typename T,typename U>pair<T,U> operator+(const pair<T,U> & l,const std::pair<T,U> & r) { return {l.first+r.first,l.second+r.second};}
typedef long long int ll;
#define int ll
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
const ll mod =1e18;
const ll MAX_NODES =200001;
const ll MAX_LOG =50;
const ll maxn = 100000+1;

int32_t main()
{ 

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


  

  




}


Measured memory_bytes: 3616
// ===================================
//   author: M_sea
//   website: http://m-sea-blog.com/
// ===================================
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int read() {
    int X=0,w=1; char c=getchar();
    while (c<'0'||c>'9') { if (c=='-') w=-1; c=getchar(); }
    while (c>='0'&&c<='9') X=X*10+c-'0',c=getchar();
    return X*w;
}

const int mod=1e9+7;
const int inv2=(mod+1)/2;
int qpow(int a,int b) { int c=1;
    for (;b;b>>=1,a=1ll*a*a%mod) if (b&1) c=1ll*c*a%mod;
    return c;
}

const int N=3000+10;

int n,q,a[N],x[N],y[N],dp[N][N];

int main() {
    n=read(),q=read();
    for (int i=1;i<=n;++i) a[i]=read();
    for (int i=1;i<=q;++i) x[i]=read(),y[i]=read();
    for (int i=1;i<=n;++i)
        for (int j=1;j<=n;++j)
            dp[i][j]=a[i]>a[j];
    for (int i=1;i<=q;++i) {
        int u=x[i],v=y[i];
        dp[u][v]=dp[v][u]=1ll*(dp[u][v]+dp[v][u])*inv2%mod;
        for (int j=1;j<=n;++j) {
            if (j==u||j==v) continue;
            dp[u][j]=dp[v][j]=1ll*(dp[u][j]+dp[v][j])*inv2%mod;
            dp[j][u]=dp[j][v]=1ll*(dp[j][u]+dp[j][v])*inv2%mod;
        }
    }
    int ans=0;
    for (int i=1;i<=n;++i)
        for (int j=i+1;j<=n;++j)
            ans=(ans+dp[i][j])%mod;
    printf("%lld\n",1ll*ans*qpow(2,q)%mod);
    return 0;
}

Measured memory_bytes: 35712
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using Map = map<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
ll INF=1LL<<60;
ll MOD=1000000007;



int main(){
    string s;
    cin >> s;
    ll K;
    cin >> K;
    ll N=s.size();

    vector<ll> num(N,0);
    for(ll i=0;i<N;i++){
        num[i]=s[i]-'0'
    ;}                 

    //未満フラグ、
    vector<vector<ll>> dp(2, vector<ll>(4, 0));
    dp[1][0]=1;
    dp[1][1]=num[0]-1;
    dp[0][1]=1;

    for(ll j=1;j<N;j++){
        vector<vector<ll>> dp2(2, vector<ll>(4, 0));
        if(num[j]!=0){
            //0の追加
            for(ll i=0;i<4;i++){
                dp2[1][i]+=dp[0][i]
            ;}
            for(ll i=0;i<4;i++){
                dp2[1][i]+=dp[1][i]
            ;}
            //numの追加
            for(ll i=1;i<4;i++){
                dp2[0][i]+=dp[0][i-1]
            ;}
            for(ll i=1;i<4;i++){
                dp2[1][i]+=dp[1][i-1]
            ;}
            //1からnum-1の追加
            for(ll i=1;i<4;i++){
                dp2[1][i]+=dp[0][i-1]*(num[j]-1)+dp[1][i-1]*(num[j]-1)
            ;}
            //num+1から9の追加
            for(ll i=1;i<4;i++){
                dp2[1][i]+=dp[1][i-1]*(9-num[j])
            ;}

        }
        else if(num[j]==0){
            //0の追加
            for(ll i=0;i<4;i++){
                dp2[1][i]+=dp[1][i];
                dp2[0][i]+=dp[0][i];
            ;}
            //1から9の追加
            for(ll i=1;i<4;i++){
                dp2[1][i]+=dp[1][i-1]*9
            ;}
        }
        for(ll i=0;i<4;i++){
            dp[1][i]=dp2[1][i];
            dp[0][i]=dp2[0][i]
        ;}

    ;}

    cout<<dp[0][K]+dp[1][K]<<endl;
    

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define S second
#define F first
using namespace std;
typedef pair<int,int> P;
typedef pair<int, P > PP;
main(){
  PP team[1000];
  int n;
  int a,b,c,d;
  cin>>n;
  int kekka=0;
  for(int i=0;i<n-1;i++){
    team[i].S.F=i;
    team[i].F=0;
    kekka+=(i+1);
  }
  team[n-1].F=0;
  team[n-1].S.F=n;
  for(int i=0;i<kekka;i++){
    cin>>a>>b>>c>>d;
    a--;
    b--;
    if(c>d){
      team[a].F+=3;
    }
    else if(c<d){
      team[b].F+=3;
    }
    else{
      team[a].F++;
      team[b].F++;
    }
  }
  sort(team,team+n,greater<PP>());
  int rank=1;
  int up=1;
  team[0].S.S=1;
  swap(team[0].S.F,team[0].F);
  for(int i=1;i<n;i++){
    if(team[i-1].S.F>team[i].F){
      rank+=up;
      up=1;
    }
    else{
      up++;
    }
    team[i].S.S=rank;
    swap(team[i].F,team[i].S.F);
  }
  sort(team,team+n);
  for(int i=0;i<n;i++){
    cout<<team[i].S.S<<endl;
  }
}

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


int str2int(string str){
  stringstream s;
  int a;
  s << str;
  s >> a;
  return a;
}

int main(void){
  string n;
  while(true){
    getline(cin, n);
    int nn = str2int(n);
    if(nn == 0) break;
    vector<string> tmpv;
    while(nn--){
      string tmps;
      getline(cin, tmps);
      int index = 0;
      for(int i=0; i < tmps.length(); i++){
        if(tmps[i] == ' '){
          tmpv.push_back(tmps.substr(index, i-index));
          index = i+1;
        }
      }
      tmpv.push_back(tmps.substr(index, tmps.length()-index));
    }

    char head;
    string tmpss;
    map<string,int> words;
    getline(cin, tmpss);
    head = tmpss[0];
    vector<string> ans;
    for(int i=0; i < tmpv.size(); i++){
      if(tmpv[i][0] != head)  continue;
      if(words.find(tmpv[i]) == words.end()){
        words[tmpv[i]] = 1;
      }else{
        words[tmpv[i]]++;
      }
    }
    int maxcnt = 0;
    for(map<string, int>::iterator it = words.begin(); it != words.end(); it++){
      maxcnt = max(maxcnt, (*it).second);
    }
    for(int i=maxcnt; i >= 0; i--){
      for(map<string, int>::iterator it = words.begin(); it != words.end(); it++){
        if((*it).second == i) ans.push_back((*it).first);
      }
    }
    int count = 5;
    if(count > ans.size()) count = ans.size();
    if(count == 0) cout << "NA" << endl;
    else{
      for(int i=0; i < count-1; i++){
        cout << ans[i] << " ";
      }
      cout << ans[count-1] << endl;
    }

  }
  return 0;
}

Measured memory_bytes: 1264
n,a,b = [int(x) for x in input().split()]

ans = 0
mod = 10**9+7
ans = (pow(2,n,mod)-1)%mod

com1 = 1
for i in range(n-a+1,n+1):
    com1 = com1*i%mod
for i in range(1,a+1):
    com1 = com1 * pow(i,mod-2,mod)%mod
com2 = 1
for i in range(n-b+1,n+1):
    com2 = com2*i%mod
for i in range(1,b+1):
    com2 = com2*pow(i,mod-2,mod)%mod
ans = (ans - com1 - com2)%mod
print(ans)

Measured memory_bytes: 3064