akhauriyash/Code-Regression huggingface dataset:
def s()
  gets().chomp
end
def i()
  gets.to_i
end
def ls()
  gets.split
end
def li()
  gets.split.map(&:to_i)
end
def ili()
  n = gets.to_i
  as = gets.split.map(&:to_i)
  [n, as]
end
def inli()
  n = gets.to_i
  as = []
  n.times {
    as << gets.split.map(&:to_i)
  }
  [n, as]
end
class Array
  def sum
    total = 0
    self.each do |item|
      total += item
    end
    total
  end
end

def eratosthenes(size)
  prime_list = []
  is_prime = Array.new(size, true)
  is_prime[0] = false
  is_prime[1] = false

  2.upto(size-1){|i|
    if is_prime[i]
      prime_list << i
      (2).upto((size.to_f/i).ceil-1){|j|
        is_prime[j*i] = false
      }
    end
  }
  [prime_list, is_prime]
end

def dijkstra(s, e, cost)
  size = cost.length
  if s==e
    return 0
  end
  dp = {}
  dp[s] = 0
  undefined_node = {}
  size.times{|i|
    if i != s
      undefined_node[i] = cost[s][i]
    end
  }
  while undefined_node.length != 0
    min = undefined_node.min_by{|_, v| v}
    stock = {}
    temp = undefined_node.clone
    temp.each{|k, v|
      if min[1] == v
        undefined_node.delete(k)
        if k == e
          return v
        end
        dp[k] = v
        stock[k] = v
      end
    }

    stock.each{|k, v|
      undefined_node.each{|k2, v2|
        undefined_node[k2] = v + cost[k][k2] < v2 ?  v + cost[k][k2] : v2
      }
    }
  end
end

def get_bits(len)
  res =  []
  (2**len).times{|i|
    res << i.to_s(2).rjust(len, '0')
  }
  res
end

def get_GCD(m, n)
  tmp = [n, m].max
  n = [n, m].min
  m = tmp
  while n != 0
    tmp = m % n
    m = n
    n = tmp
  end
  m
end
def fact(n, m=0)
  (m+1..n).inject(1,:*)
end
def perm(n, r)
  fact(n, n-r)
end
def comb(n, m)
  fact(n, n-m)/fact(m)
end

def matrix(n, m=n, init=0)
  Array.new(n).map{Array.new(m,init)}
end

def solve(n, ss)
  map = {}
  ss.each do |s,c|
    if map.has_key?(s) && map[s] != c
      return -1
    end
    map[s] = c
  end
  if map[1] == 0 && n > 1
    return -1
  end
  res = Array.new(n, 0)
  if n > 1
    res[0] = 1
  end
  map.each do |k, v|
    res[k-1] = v
  end
  res.join("")
end

N, M = li()
ss = []
M.times do
  ss << li()
end
puts solve(N, ss)


Measured memory_bytes: 1788
a,b,c = map(int, input().split())
l = [int(input()) for _ in range(a)]
flag = True
l = sorted(l)
max_T = 10**18
def ok(k):
    s = k
    for i in l:
        hp = i - c * k
        if hp > 0:
            s -= -(-hp // (b - c))
        if s < 0:
            return False
    return True
def binary_search(l,r):
    mid = (l + r) // 2
    if l == r:
        return l
    elif ok(mid):
        return binary_search(l,mid)
    else:
        if mid == l:
            mid += 1
            
        return binary_search(mid,r)
ans = binary_search(0,max_T)
print(ans) 

Measured memory_bytes: 8280
N = int(input())
li = list(map(int,input().split()))
li.sort(reverse=True)
c = 0
for i in range(N-2):
    for j in range(i+1,N-1):
        for k in range(j+1, N):
            if li[i] == li[j] or li[j] == li[k] or li[i] == li[k]:
                continue

            if li[i] < li[j] + li[k]:
#                print(i,j,k)
                c += 1
print(c)




Measured memory_bytes: 9184
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<unordered_map>
#include<array>
#include<map>
#include<bitset>
#include<iomanip>
#include<list>
using namespace std;
typedef unsigned long long int ulint;
typedef long long int llint;
typedef long double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
#define RE return 0
//ios::sync_with_stdio(false);
//std::cin.tie(0);
//<< setprecision(20)
const int mod=1e7+7;
const llint big=1e15+100;
const long double pai=3.141592653589793238462643383279502884197;
const long double ena=2.71828182845904523536;
const long double eps=1e-7;
template <class T,class U>void mineq(T& a,U b){if(a>b){a=b;}}
template <class T,class U>void maxeq(T& a,U b){if(a<b){a=b;}}
template <class T> void soun(T& ar)
{sort(ar.begin(),ar.end());ar.erase(unique(ar.begin(),ar.end()),ar.end());}
llint gcd(llint a,llint b){if(a%b==0){return b;}else{return gcd(b,a%b);}}
llint lcm(llint a,llint b){return a/gcd(a,b) *b;}
template<class T,class U> auto LB(T& ve,U in){return lower_bound(ve.begin(),ve.end(),in);}
template<class T,class U> auto UB(T& ve,U in){return upper_bound(ve.begin(),ve.end(),in);}
template<class T,class U> auto LBI(T& ve,U in){return LB(ve,in)-ve.begin();}
template<class T,class U> auto UBI(T& ve,U in){return UB(ve,in)-ve.begin();}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
int main(void){
	int n,b;cin>>n>>b;b/=1000;
	if(n>b){cout<<"-1 -1 -1"<<endl;RE;}
	int x=0,y=0,z=b,nok=b-n;
	while(nok>0){
		if(z>=5&&nok>=4){z-=5;y++;nok-=4;}
		else if(y>=2){y-=2;x++;nok--;}
		else{cout<<"-1 -1 -1"<<endl;RE;}
	}
	cout<<x<<" "<<y<<" "<<z<<endl;
	RE;
}

Measured memory_bytes: 256
from math import gcd
K=int(input())

result=[]
count=0
cnt=0
# def gcd(a,b):
#   while b!=0:
#     a,b=b,a%b
#   return a

 
for i in range(1,K+1):
  for j in range(1,K+1):
    for k in range(1,K+1):
      cnt+=gcd(gcd(i,j),k)


print(cnt)



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

int main(){
	int n, k;
  	cin >> n >> k;
  
  	int ans = 0;
  	rep(i, n){
    	int h;
      	cin >> h;
      
      	if(h >= k) ans++;
    }
  
  	cout << ans << endl;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
#define rep(i,m,n) for(int i=m; i<n; i++)
#define co(n) cout << n << endl
using namespace std;
int main(){
  long a, b, c=0, d=0, e, f, g, h, n;
  cin >> a >> b;
  if(500*a>=b) co("Yes");
  else co("No");
  
  
  return 0;
}

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

int main(){
  int N,K;
  cin>>N>>K;
  vector<int> A(N);
  for(int i=0;i<N;i++){
    cin>>A.at(i);
  }

  if(K>100){
    for(int i=0;i<N;i++){
      cout<<N<<" ";
    }
    cout<<endl;
  }else{
    for(int k=0;k<K;k++){
      vector<int> sum(N+1,0);
      for(int i=0;i<N;i++){
        int left=i-A.at(i);
        int right=i+A.at(i);
        sum.at(max(left,0))++;
        sum.at(min(right+1,N))--;
      }
      for(int i=1;i<=N;i++){
        sum.at(i)+=sum.at(i-1);
      }
      for(int i=0;i<N;i++){
        A.at(i)=sum.at(i);
      }
    }

    for(int i=0;i<N;i++){
      cout<<A.at(i)<<" ";
    }
    cout<<endl;
  }
}


Measured memory_bytes: 4792
#include <iostream>
#include <iomanip>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>
#include <numeric>
#include <set>

using namespace std;
struct aaa{aaa(){cin.tie(nullptr); ios::sync_with_stdio(false); cout<<fixed<<setprecision(20);};}aaa;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v){o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
#define debug(v) {cerr<<"\033[1;36m[debug]\033[m "<<#v<<" : "<<v<<endl;}

using int64 = long long;

int64 calc(const vector<int64>& a, const vector<int64>& s) {
    int64 res = 0;
    int64 pre = 0;
    int n = a.size();
    auto si = s.begin();
    for (int i=0; i<n; i++) {
        int ad = 0;
        if (i == *si) {
            ad = max(0LL, pre - a[i] + 1);
            res += ad;
            if (++si == s.end()) break;
        }
        pre = max(pre, a[i] + ad);
    }
    return res;
}

int64 dfs(const int& i, const int& k, const vector<int64>&a, vector<int64> s) {
    if (s.size() == k) return calc(a,s);
    if (i >= a.size()) return LONG_MAX;
    int64 res = LONG_MAX;

    res = min(res, dfs(i+1, k, a, s));
    s.push_back(i);
    res = min(res, dfs(i+1, k, a, s));
    return res;
}


int main() {
    int n,k;
    cin >> n >> k;
    vector<int64> a(n);
    for (int i=0; i<n; i++) cin >> a[i];

    vector<int64> s;
    int64 ans = dfs(0, k, a, s);

    cout << ans << endl;
}


Measured memory_bytes: 888
#define _USE_MATH_DEFINES //M_PI, M_E
#include<bits/stdc++.h>
#define mod 1000000007
#define ll long long int
#define ar array
#define pb push_back
ll power(ll a,ll b){ll r=1;for(;b;b>>=1){if(b&1)r=r*a%mod;a=a*a%mod;}return r;}
using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	int h,w;
	cin>>h>>w;
	char ch[h][w];
	int white = 0;
	for(int i = 0; i<h; i++) for(int j = 0; j<w; j++){cin>>ch[i][j] ; white += ch[i][j]=='.';}
	queue<ar<int,3>> q;
	q.push({0,0,1});
	bool vis[h][w];
	memset(vis,0,sizeof(vis));
	vis[0][0] = 1;
	vector<ar<int,2>> v = {{-1,0},{1,0},{0,1},{0,-1}};
	int ans = 0;
	while(!q.empty())
	{
		auto y = q.front();
		q.pop();
		if(y[0]==h-1 && y[1]==w-1){ ans = y[2]; break;}
		for(auto it:v)
		{
			int y2 = it[0]+y[0], x = it[1]+y[1];
			if(y2>=0 && y2<h && x>=0 && x<w && ch[y2][x] =='.' && !vis[y2][x])
			{
				vis[y2][x] = 1;
				q.push({y2,x,y[2]+1});
			}
		}
	}
	if(!vis[h-1][w-1]) cout<<-1<<endl;
	else 
	cout<<(white-ans)<<endl;
	return 0;
}

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

int main() {
  string s;
  cin>>s;
  int a=-1;
  int b=-1;
  int c=-1;
  int d=-1;
  for(int i=0;i<s.size();i++){
    if(s[i]=='N')a+=2;
    if(s[i]=='S')b+=2;
    if(s[i]=='E')c+=2;
    if(s[i]=='W')d+=2;
  }
  if(a*b>0&&c*d>0)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}


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

struct edge { int to, id; };
vector<vector<edge>> graph;

vector<int> path;
bool DFS(int v, int terminal, int parent_v = -1){// reachablility to terminal from v
    if(v == terminal) return true;

    for(edge e : graph[v]){
        if(e.to == parent_v) continue;

        if(DFS(e.to, terminal, v) == true){
            path.push_back(e.id);
            return true;
        }
    }
    return false;
}

int main(){
    int n;
    cin >> n;
    graph.resize(n);

    for(int i=0; i<n-1; i++){
        int a, b;
        cin >> a >> b;
        a -= 1;
        b -= 1;
        graph[a].push_back({b,i});
        graph[b].push_back({a,i});            
    }

    int m;
    cin >> m;
    vector<long long int> uvpath(m);
    for(int i=0; i<m; i++){
        int u, v;
        cin >> u >> v;
        u -= 1;
        v -= 1;
        path = {};
        DFS(u, v);
        for(int edge_id : path){
            uvpath[i] |= 1LL<<(edge_id);
        }
    }

    vector<long long int> pow2(60, 1);// pow2[i] = 2^i
    for(int i=0; i<60; i++){
        pow2[i+1] = pow2[i] * 2;
    }

    long long int ans = 0;
    for(int bit=0; bit<(1<<m); bit++){
        int phase = 1;
        if(__builtin_popcount(bit) % 2 == 1) phase *= -1;

        long long int total = 0;
        for(int i=0; i<m; i++){
            if(bit >> i & 1) total |= uvpath[i];
        }
        ans += phase * pow2[(n-1) - __builtin_popcountll(total)];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3600
using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;


class C
{
   public static void Main() {
        int n = int.Parse(Console.ReadLine());
        int[,] G = new int[n+1, n+1];
        for(int i = 0; i < n; i++) {
            int[] input = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
            for(int j = 0; j < input[1]; j++) {
                if (G[input[0], input[j + 2]] == 0) {
                    G[input[0], input[j + 2]] = 1;
                }
            }
        }
        for(int i = 1; i <= n; i++) {
            for(int j = 1; j <=n; j++) {
                if (j > 1) {
                    Console.Write(" ");
                }
                Console.Write(G[i, j]);
            }
                Console.WriteLine();
        }
    }
}


Measured memory_bytes: 17900
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7

def LI(): return list(map(int,input().split()))
def I(): return int(input())
def LS(): return input().split()
def S(): return input()

def main():
  a,p=LI()
  p+=a*3
  print(p//2)

main()
# print(main())


Measured memory_bytes: 7836
N = int(input())
A = list(map(int, input().split()))
c2 = sum([a % 2 == 0 and a % 4 != 0 for a in A])
c4 = sum([a % 4 == 0 for a in A])
cp = sum([a % 2 != 0 for a in A])
print('Yes' if cp+c4 == N and cp - c4 ==
      1 or cp <= c4 and c4+cp+c2 == N else 'No')


Measured memory_bytes: 65944
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#include<stack>
#include<vector>
#include<map>
#define int long long
using namespace std;
const int maxn = 3e5+10;
const int mod = 1e9+7;

int read(){
	int x=0,f=1;
	char c=getchar();
	while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}
	while(isdigit(c)){x=(x<<3)+(x<<1)+c-48;c=getchar();}
	return x*f;
}

int k,m,n;
int a[maxn],max_=0;
signed main(){
	n=read();
	for(register int i=1;i<=n;i++){a[i]=read();max_=max(max_,a[i]);}
	int ans=0;
	for(register int i=1;i<=max_;i<<=1){
		int num=0;
		for(register int j=1;j<=n;j++){
			if(i&a[j])num++;
		}
		(ans+=i%mod*num%mod*(n-num)%mod)%=mod;
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 2560
#include <iostream>
#include <algorithm>
#include <map>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#define rep(i, N) for (int i = 0; i < N; i++)
#define rep1(i, N) for (int i = 1; i <= N; i++)

typedef long long ll;
const ll MOD = 1e9 + 7;

int main() {
    int H, W, h, w;
    cin >> H >> W >> h >> w;
    
    cout << (H - h)*(W - w) << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/range/adaptors.hpp>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;
using namespace boost::adaptors;

int64_t pow10(int64_t n) {
    if (n == 0) {
        return 1;
    }

    auto p = pow10(n / 2);
    return p * p * ((n % 2) ? n : 1);
}

int64_t solve(string n, int64_t pos, int64_t k, bool f) {
    static vector<vector<vector<int64_t>>> cache(
            101, vector<vector<int64_t>>(4, vector<int64_t>(2, -1L)));

    if (cache[pos][k][f ? 1 : 0] >= 0) {
        return cache[pos][k][f ? 1 : 0];
    }

    if (pos == n.size()) {
        return (k > 0) ? 0 : 1;
    }

    int64_t ret = 0;
    if (f) {
        if (n[pos] == '0') {
            ret += solve(n, pos + 1, k, true);
        } else {
            if (k > 0) {
                ret += solve(n, pos + 1, k - 1, true);
                ret += ((n[pos] - '0') - 1) * solve(n, pos + 1, k - 1, false);
            }
            ret += solve(n, pos + 1, k, false);
        }
    } else {
        if (k == 0) {
            ret = 1;
        } else {
            ret += 9 * solve(n, pos + 1, k - 1, false);
            ret += solve(n, pos + 1, k, false);
        }
    }

    cache[pos][k][f ? 1 : 0] = ret;
    return ret;
}

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

    int64_t k;
    cin >> k;

    cout << solve(n, 0, k, true) << endl;
}

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

int main()
{
	string s;
	cin >> s;
	vector<char> v;
	for (int i = 0; i < s.size(); i++) {
		v.push_back(s[i]);
	}
	sort(v.begin(), v.end());
	int c = 1;
	bool f = true;
	if (v.size() == 1) f = false;
	for (int i = 0; i < v.size() - 1; i++) {
		if (v[i] == v[i + 1]) {
			c++;
		}
		else {
			if (c % 2 != 0) {
				f = false;
				break;
			}
			c = 1;
		}
	}
	if (c % 2 != 0) f = false;
	if (f) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
N, M = map(int, input().split())

mod = 1000000007;

# dpテーブル, 壊れた階段を記録するテーブル用意
dp = [0]*(N+1)
broken = [0]*(N+1)

# 初期化
dp[0] = 1
dp[1] = 1

# 壊れている階段は-1で定義
for _ in range(M) :
    broken[int(input())] = -1

# 漸化式から求めていく
for i in range(2, N+1):
        
    if (broken[i-1] != -1):
        dp[i] += dp[i-1]
    
    if (broken[i-2] != -1):
        dp[i] += dp[i-2]
    
    dp[i] %= mod

print(dp[-1])

Measured memory_bytes: 7772
//******* It's LEVI_17 ***************

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

#define ff first
#define ss second
#define MP make_pair
#define mset(x,a) memset(x,a,sizeof(x))
#define max3(x,y,z) max(x,max(y,z))
#define min3(x,y,z) min(x,min(y,z))
#define sqr(a) (a)*(a)
#define all(x) (x).begin(), (x).end()
#define f(i, n) for (int i = 0; i < n; i++)
#define f1(i, n) for (int i = 1; i <= n; i++)
#define loop(i,a,b) for (int i = a; i < b; i++)
#define bloop(i,a,b) for (int i = a ; i>=b;i--)
#define vvll vector<vector<ll>>  
#define vll vector<ll> 
#define pll pair<ll,ll>
#define vpll vector<pll>
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define cases ll t;cin >> t;while(t--)
#define rr return 0
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

#define deb(a)			std::cerr<<#a<<"="<<(a)<<"\n"
#define deb2(a,b)		std::cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<"\n"
#define deb3(a,b,c)		std::cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<"\n"
const int MOD = 1000 * 1000 * 1000 + 7;

//syntax for priority queue
// max queue -> priority_queue<ll>
// min queue -> priority_queue<ll,vector<ll>,greater<ll>>

//##############################################################################################

ll getRes(ll arr[], ll n,ll k)
{
    ll dp[n + 1] = { 0 };
    dp[0] = 0;
    dp[1] = 0;
    dp[2] = abs(arr[1] - arr[0]);
    for (ll i = 3; i <= n; i++)
    {
        ll ans = INT_MAX;
        for (ll j = 1; j <= k && j<i; j++)
        {
            ans = min(ans, dp[i - j] + abs(arr[i - 1] - arr[i - j - 1]));
        }
        dp[i] = ans;
        
    }

    return dp[n];
}

void solve()
{
    ll n,k;
    cin >> n >> k;
    ll arr[100001];
    f(i, n)
        cin >> arr[i];
    if (n < 2)
    {
        cout << 0 << "\n";
        return;
    }
    //cout << n << " ";
    ll res = getRes(arr, n,k);
    cout << res << "\n";
}

//###############################################################################################

int main()
{
    fast;
    ll t = 1;
    //cin >> t;
    while (t--)
    {
        solve();
    }
    rr;
}


//Watashi wa tsuyoku modotte kimasu

Measured memory_bytes: 5184
#include<iostream>
#include<math.h>
#include<vector>

using namespace std;

int n,w;
vector< pair<int, int> > item;
long long dp[101][100001];
long long m = -1;

int dfs(int k){
  if(k == n){
    for(int i = 0; i <= w; i++){
      m = max(m, dp[n][i]);
    }
    return 0;
  }
  for(int i = 0; i <= w; i++){
//    if(dp[k][i] == -1) continue;
    dp[k+1][i] = max(dp[k+1][i], dp[k][i]);
    if(i + item[k].first <= w)dp[k+1][i + item[k].first] = max(dp[k+1][i + item[k].first], dp[k][i] + item[k].second);
  }
  return dfs(k+1);
}

int main(){
  cin >> n >> w;
  for(int i = 0; i < n ; i++){
    int a,b;
    cin >> a >> b;
    item.push_back(make_pair(a,b));
  }
  for(int i = 0; i <= n; i++){
    for(int j = 0; j <= w; j++){
      dp[i][j] = -1;
    }
  }
  dp[0][0] = 0;
  dfs(0);
  cout << m << endl;
}


Measured memory_bytes: 79104
#include<bits/stdc++.h>
using namespace std;
const int mod=1e9+7;
int n,ans,f[2][310][310],a[610];
bool b[610],vis[610];
void add(int&x,int y){x=(x+y)%mod;}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n*2;i++)scanf("%d",&a[i]);
	for(int i=1;i<=n*2;i++)if(a[i]!=-1)b[a[i]]=1;
	for(int i=1;i<=n;i++)if(a[i*2-1]!=-1&&a[i*2]!=-1)vis[a[i*2-1]]=vis[a[i*2]]=1;
	int p=0;
	f[0][0][0]=1;
	for(int i=n*2;i;i--)
	if(!vis[i])
	{
		p^=1;
		memset(f[p],0,sizeof f[p]);
		for(int j=0;j<=n;j++)
		for(int k=0;k<=n;k++)
		if(f[p^1][j][k])
		{
			if(b[i])add(f[p][j+1][k],f[p^1][j][k]);
			else add(f[p][j][k+1],f[p^1][j][k]);
			if(b[i]&&k)add(f[p][j][k-1],f[p^1][j][k]);
			if(!b[i])
			{
				if(k)add(f[p][j][k-1],f[p^1][j][k]);
				if(j)add(f[p][j-1][k],1ll*f[p^1][j][k]*j%mod);
			}
		}
	}
	ans=f[p][0][0];
	for(int i=1,s=0;i<=n;i++)if(a[i*2-1]==-1&&a[i*2]==-1)ans=1ll*ans*(++s)%mod;
	printf("%d",ans);
}

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

typedef struct{
	int x;
	int y;
}point;

int main(){
	while(1){
		int n;
		int dx[4]={-1,0,1,0}, dy[4]={0,-1,0,1};
		point plot[201];
		
		scanf(" %d", &n);
		if(n==0) break;
		plot[0].x=0;
		plot[0].y=0;
		
		int right=0, left=0, top=0, bottom=0;
		
		for(int i=1; i<n; ++i){
			int s, d;
			scanf(" %d %d", &s, &d);
			
			plot[i].x = plot[s].x+dx[d];
			plot[i].y = plot[s].y+dy[d];
			
			if(plot[i].x>top) top=plot[i].x;
			else if(plot[i].x<bottom) bottom=plot[i].x;
			
			if(plot[i].y>right) right=plot[i].y;
			else if(plot[i].y<left) left=plot[i].y;	
		}
		
	printf("%d %d\n", top-bottom+1, right-left+1);
	}
	return 0;
}

Measured memory_bytes: 1188
//  ROAD TO GREEN
#include <iostream>
#include <algorithm>
#include <vector>
#include <deque>

using namespace std;
typedef long long ll;
const ll MAXN = 45;

int main(){
    int n; cin >> n;
    double a[n];
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    sort(a,a+n);
    double cur = (a[0]+a[1])/2;
    for(int i = 2; i < n; i++){
        cur = (cur+a[i])/2;
    }
    cout << cur << endl;
    return 0;
}

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

signed main() {
  lint n, m, x;
  cin >> n >> m >> x;
  vector<lint> prises(12);
  vector<vector<lint>*> skills(12);
  for(lint i = 0; i < n; i++){
    cin >> prises.at(i);
    skills.at(i) = new vector<lint>(12);
    for(lint j = 0; j < m; j++){
      cin >> skills.at(i)->at(j);
    }
  }

  lint minPrise = 10000000;
  for(int bit = 0; bit < (1 << n); bit++){
    vector<lint> set;
    for(int i = 0; i < n; i++){
      if(bit & (1 << i)){
        set.push_back(i);
      }
    }
    if(set.size() <= 0)
      continue;

    lint prise = 0;
    vector<lint> understanding(12, 0);
    for(lint i = 0; i < set.size(); i++){
      prise += prises[set[i]];
      for(lint j = 0; j < m; j++){
        understanding.at(j) += skills[set[i]]->at(j);
      }
    }

    bool isUnderstood = true;
    for(lint i = 0; i < m; i++){
      if(understanding[i] < x){
        isUnderstood = false;
        break;
      }
    }

    if(!isUnderstood)
      continue;

    if(minPrise > prise){
      minPrise = prise;
    }   
  }

  if(minPrise == 10000000){
    cout << -1 << endl;
  }else{
    cout << minPrise << endl;
  }
}


Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<ll,ll>;
const ll mod = 1e9+7;
#define ALL(x) (x).begin(),(x).end()
#define pow(x,y) modpow(x,y)
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define REPS(i,n) for(ll (i)=1;(i)<=(n);(i)++)
#define RREP(i,n) for(ll (i)=(n-1);(i)>=0;(i)--)
#define RREPS(i,n) for(ll (i)=(n);(i)>0;(i)--)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());

template <class T = int>T in(){
    T x;
    cin >> x;
    return (x);
}

template<class T> inline void chmin(T& a, T b){
    if (a > b){
        a = b;
    }
}

template<class T> inline void chmax(T& a, T b){
    if (a < b){
        a = b;
    }
}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(10);
    vector<vector<int>> to(10,vector<int>(10));
    int H = in(),W = in();
    REP(i,10){
        REP(l,10){
            to[i][l] = in();
        }
    }
    for (int k = 0; k < 10; k++){
        for (int i = 0; i < 10; i++) {
            for (int j = 0; j < 10; j++) {
            to[i][j] = min(to[i][j], to[i][k] + to[k][j]);
            }
        }
    }
    int answer = 0;
    REP(i,H){
        REP(l,W){
            int tmp = in();
            if(tmp >= 0)answer += to[tmp][1];
        }
    }
    cout << answer << "\n";
}

Measured memory_bytes: 256
#include <map>
#include <set>
#include <list>
#include <array>
#include <cmath>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <cstdio>
#include <string>
#include <vector>
#include <random>
#include <chrono>
#include <utility>
#include <numeric>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <sstream>
#include <assert.h>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <unordered_map>
using namespace std;

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(bool x) {cerr << (x ? "true" : "false");}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}

template<typename T, typename V> void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i : x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";} void _print() {cerr << "]\n";}
template <typename T, typename... V>void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifdef HOME
#warning CHECK int:ll::INT_MAX:LLONG_MAX
#define maxn 20
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define maxn 2000006
#define gcd __gcd
#define debug(x...)
#endif

#define ff first
#define endl '\n'
#define ss second
#define inf 0x3f3f3f3f
#define MOD 1000000007
#define PI 3.14159265358979323846264338327950L
#define f(i,x,n) for(int i=x;i<=n;i++)
#define fr(i,x,n) for(int i=x;i>=n;i--)
struct _ { ios_base::Init i; _() { ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); } } _;

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


int main() {

	int n, k; cin >> n >> k;
	if (k > (((n - 1) * (n - 2)) / 2)) {
		cout << -1;
		return 0;
	}

	vector<array<int, 2>> edge;

	for (int j = 2; j <= n; j++) {
		edge.push_back({1, j});
	}
	int ans = (((n - 1) * (n - 2)) / 2);

	for (int i = 2; i <= n; i++) {
		for (int j = i + 1; j <= n; j++) {
			if (ans == k) break;
			edge.push_back({i, j});
			ans--;
		}
		if (ans == k) break;
	}

	cout << edge.size() << "\n";
	for (auto i : edge) cout << i[0] << " " << i[1] << "\n";

	return 0;
}

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

using namespace std;

int main(){
    string S;

    cin >> S;
    int cnt = 0;
    int tmp = 0;
    bool flg = false;

    for(size_t i = 0; i < (int)S.size(); i++)
    {
        if (S[i] == 'A' || S[i] == 'T' || S[i] == 'C' || S[i] == 'G'){
            tmp++;
            flg = true;
        }else{
            false;
            tmp = 0;
        }
        if(cnt < tmp){
            cnt = tmp;
        }
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define itn int
#define REP(i, n) for (int i = 0; i < n; i++)
#define IREP(i, n) for (int i = n - 1; i >= 0; i--)
#define REPEACH(i,k) for(auto&& i:k)
#define all(a) a.begin(),a.end()
#define MOD 1000000007
#define int long long
using namespace std;
typedef long long ll;

const ll INF = 1LL << 60;

signed main() {
	int n,t;
	cin >> n >> t;
	vector<int> h(n);
	int now=0;
	int ans=0;
	REP(i,n){
		cin >> h[i];
		if(i==0){
			now=h[i]+t;
			ans+=t;
		}
		else if(now>h[i]){
			ans+=h[i]+t-now;
			now=h[i]+t;
		}
		else{
			now=h[i]+t;
			ans+=t;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    vector<int> v(n);
    vector<int> c(n);

    for(int i=0;i<n;i++){
        cin >> v[i];
    }
    for(int i=0;i<n;i++){
        cin >> c[i];
    }

    int ans = 0;
    for(int i=0;i<n;i++){
        if(v[i]-c[i] >= 0){
            ans += v[i]-c[i];
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=5e18;

int main() {
  ll d;
  cin >> d;
  cout << "Christmas";
  while(d<25) {
    cout << " " << "Eve";
    d++;
  }
  cout << endl;
}

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

using namespace std;


#ifdef zxc

#include "debug.h"

#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif
using ll = int64_t;
const ll MOD = 1e9 + 7;
const int maxn = 600001;
using ld = long double;
const ld EPS = 1e-9;
const ld PI = 3.141592653589793;

void fast_io() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
}

int a[maxn];

signed main() {
#ifdef zxc
    mt19937 mt(228);
    freopen("../kolya_input.txt", "r", stdin);
//    freopen("../kolya_output.txt", "w", stdout);
#else
    //    mt19937 mt(std::chrono::high_resolution_clock::now().time_since_epoch().count());
    //            freopen("", "r", stdin);
    //        freopen("hack.out", "w", stdout);
#endif
    fast_io();
    cout.precision(4);
    cout << fixed;
    auto start = chrono::steady_clock::now();
    int n;
    cin >> n;
    for (int i = 1; i <= n; ++i) {
        cin >> a[i];
    }
    sort(a + 1, a + 1 + n);
    reverse(a + 1, a + 1 + n);
    vector<pair<int, int>> angles;
    for (int i = 1; i <= n;) {
        angles.emplace_back(a[i], i - 1);
        int j = i;
        while (j <= n && a[j] == a[i]) { ++j; }
        angles.emplace_back(a[i], j - 1);
        i = j;
    }
    angles.emplace_back(0, n);
    debug(angles);
    pair<int, int> pos;
    int ind;
    for (int i = 0; i + 1 < angles.size(); ++i) {
        if (angles[i].first == angles[i + 1].first) {
            if (angles[i].second <= angles[i].first && angles[i].first <= angles[i + 1].second) {
                pos = {angles[i].first, angles[i].first};
                ind = i;
                break;
            }
        } else {
            if (angles[i + 1].first <= angles[i].second && angles[i].second <= angles[i].first) {
                pos = {angles[i].second, angles[i].second};
                ind = i;
                break;
            }
        }
    }
    if (pos == angles[ind + 1]) {
        int y = (angles[ind].second == angles[ind + 1].second) ? angles[ind + 2].second : pos.second;
        int x = (angles[ind].second == angles[ind + 1].second) ? angles[ind].first : pos.first;
        --pos.first;
        --pos.second;
        if ((y - pos.second) % 2 && (x - pos.first) % 2) {
            cout << "Second";
        } else {
            cout << "First";
        }
        return 0;
    } else if (angles[ind + 1].second == angles[ind].second) {
        int x = angles[ind].first;
        --pos.first;
        --pos.second;
        if ((x - pos.first) % 2) {
            cout << "Second";
        } else {
            cout << "First";
        }
        return 0;
    } else {
        int y = angles[ind + 1].second;
        --pos.first;
        --pos.second;
        if ((y - pos.second) % 2) {
            cout << "Second";
        } else {
            cout << "First";
        }
    }
    auto end = chrono::steady_clock::now();
    debug("time", chrono::duration_cast<chrono::milliseconds>(end - start).count() / 1000.0);

}



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

#define froop1(a,n) for(int i = a;i < n;i++)
#define froop2(a,n) for(int i = a;i > n;i--)
int main(){
	long long a;
  cin >> a;
  vector<char> d;
  vector<int> d1;
  long long b = 26;
  
  while(a > 0){
    a--;
    long long mod = a % b;
    char c = 'a' + mod;
    d.push_back(c);
   d1.push_back(mod);
    a /= b;
  }

  for(int i = d.size() - 1;i >= 0;i--){
	cout << d.at(i);
  }
  cout << endl;
}


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

using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#define FOR(k,m,n) for(ll (k)=(m);(k)<(n);(k)++)
#define REP(i,n) FOR((i),0,(n))
#define WAITING(str) int str;std::cin>>str;
#define DEBUGING(str) cout<< #str << " " str<<endl

constexpr int INF = (1 << 30);
constexpr ll INFL = (1ll << 60);
constexpr ll MOD = 1000000007;// 10^9+7


struct COMB {
	static constexpr ll LIM = 200'000;
	COMB() { make_contents(); }

	//繰り返し累乗法
	//in:  x,n,mod
	//out: x^n(Mod mod)
	template<typename T>
	T mod_pow(T x, T n, T mod) {
		T res = 1;
		while (n > 0) {
			if (n & 1)res = (res * x) % mod;
			x = (x * x) % mod;
			n >>= 1;
		}
		return res;
	}

	void make_contents()
	{
		ll tmp = 1;
		fact.push_back(0);
		FOR(i, 1, LIM) {
			tmp *= i;
			tmp %= MOD;
			fact.push_back(tmp);
		}

		tmp = mod_pow(tmp, MOD - 2, MOD);
		//inv.push_back(tmp);
		for (ll i = LIM - 1; i > 0; i--) {
			tmp *= i;
			tmp %= MOD;
			inv.push_back(tmp);
		}
		reverse(inv.begin(), inv.end());
		fact[0] = inv[0] = 1;
		/*正当性確認
		REP(i, LIM) {
			cerr << (fact[i] * inv[i]) % MOD << endl;
		}
		*/
	}

	ll comb(ll n, ll k) {
		if (n < 0 || k < 0)return 0;
		if (n < k)return 0;
		ll res = fact[n];
		res *= inv[k]; res %= MOD;
		res *= inv[n - k]; res %= MOD;
		return res;
	}

private:
	vector<ll> fact, inv;
};



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

	COMB comb;
	cout << N - K + 1 << endl;
	FOR(i, 2, K + 1) {
		ll res = 0;
		(res += comb.comb(N - K - 1, i)) %= MOD;
		(res += 2 * comb.comb(N - K - 1, i - 1)) %= MOD;
		(res += comb.comb(N - K - 1, i - 2)) %= MOD;
		(res *= comb.comb(K - 1, i - 1)) %= MOD;
		cout << res << endl;
	}
	return 0;
}


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

//g++ -g -o yourexe yourfile.cpp
//./yourexe < yourinput.in > youroutput.out

#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

#define M 1000000007

#define ll long long
//#define ld long double
#define vi vector<ll>
#define pi pair<ll, ll>
#define vii vector<pi>
#define vvi vector<vi>
#define pb push_back
#define endl "\n"
#define fi first
#define se second

#define REP(i, s, e) for (ll i = s; i < e; i++)
#define RREP(i, s, e) for (ll i = s; i > e; i--)

#define all(v) v.begin(), v.end()
#define part(v, s, e) v.begin() + s, v.begin() + e
#define print(v) for (auto i: v) cout << i << " ";

int main() {
    ll n;
    cin >> n;
    vi a(n), b(n), c(n-1);
    REP(i, 0, n)
        cin >> a[i];
    REP(i, 0, n)
        cin >> b[i];
    REP(i, 0, n-1)
        cin >> c[i];
    ll s = 0;
    s += b[a[0] - 1];
    REP(i, 1, n) {
        s += b[a[i] - 1];
        if (a[i] == a[i-1] + 1)
            s += c[a[i]-2];
    }
    cout << s << endl;
    return 0;
}


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

long long n, m, a[100009], b[100009], e[100009], col[100009], cnts; bool used[100009]; vector<long long>x[100009], G[100009];

void dfs(int pos) {
	if (col[pos] >= 1) return;
	col[pos] = cnts; G[cnts].push_back(pos);
	for (int i = 0; i < x[pos].size(); i++) dfs(x[pos][i]);
}

int main() {
	cin >> n >> m;
	for (int i = 0; i < n; i++) cin >> e[i];
	for (int i = 1; i <= m; i++) {
		cin >> a[i] >> b[i];
		x[a[i]].push_back(b[i]);
		x[b[i]].push_back(a[i]);
	}
	for (int i = 0; i < n; i++) {
		if (col[i] >= 1) continue;
		cnts++; dfs(i);
	}
	if (cnts == 1) { cout << "0" << endl; return 0; }
	long long sum = 0;
	for (int i = 1; i <= cnts; i++) {
		long long minx = (1LL << 60), minid = 0;
		for (int j = 0; j < G[i].size(); j++) {
			if (e[G[i][j]] < minx) { minx = e[G[i][j]]; minid = G[i][j]; }
		}
		sum += minx; used[minid] = true;
	}
	vector<long long>F;
	for (int i = 0; i < n; i++) {
		if (used[i] == false) F.push_back(e[i]);
	}
	if (F.size() < cnts - 2) {
		cout << "Impossible" << endl;
		return 0;
	}
	sort(F.begin(), F.end());
	for (int i = 0; i < cnts - 2; i++) sum += F[i];
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 15476
import sys 
sys.setrecursionlimit(10**6)
input = lambda: sys.stdin.readline().rstrip()

def dfs(v, pv):
    global P

    for nv in G[v]:
        if nv != pv:
            P[nv] += P[v]
            dfs(nv, v)

n,q = map(int, input().split())
G = [[] for _ in range(n)]              # adjacent list
for i in range(n-1):
    a,b = map(int, input().split())
    G[a-1].append(b-1)
    G[b-1].append(a-1)

P = [0]*n                               # add list
for i in range(q):
    p,x = map(int, input().split())
    P[p-1] += x


dfs(0, 0)
print(*P)



Measured memory_bytes: 230932
#include<iostream>
#include<stdio.h>
#include<math.h>
using namespace std;
int main(){
    double a,b,C;
    scanf("%lf %lf %lf",&a,&b,&C);
    double s = (0.5)*a*b*sin(M_PI*C/180);
    double c = sqrt(a*a+b*b-2*a*b*cos(M_PI*C/180));
    double L = a+b+c;
    double h = 2*s/a;
    printf("%.8lf\n",s);
    printf("%.8lf\n",L);
    printf("%.8lf\n",h);
    return 0;
}


Measured memory_bytes: 3456
#include<bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
typedef long long ll;
int main(){
  ll N,i,ans = 0;cin >> N;
  for(i=1;i<N;i++) ans += (N-1)/i;
  cout << ans << "\n";
}

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

using namespace std;
typedef long long ll;
typedef long double ld;
using graph = vector<vector<int>>;

#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define repd(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
//xにはvectorなどのコンテナ
#define all(x) (x).begin(),(x).end()
#define size(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))

#define INF 1000000000000
#define MOD 10000007
#define MAXR 100000

#define pb push_back
#define mp make_pair
#define f first
#define s second

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

vector<int> ans(100100,-1);

void dfs(int v,vector<vector<pair<int,int>>>&g){
	for(auto&nv:g[v]){
		if(ans[nv.f]!=-1)continue;
		if(nv.s%2==0)ans[nv.f]=ans[v];
		else ans[nv.f]=1-ans[v];
		dfs(nv.f,g);
	}
}

int main(){
	int n; cin>>n;
	vector<vector<pair<int,int>>> g(100100);
	rep(i,n-1){
		int a,b,c;cin>>a>>b>>c;
		a--;
		b--;
		g[a].pb(mp(b,c));
		g[b].pb(mp(a,c));
	}
	ans[0]=1;
	dfs(0,g);
	rep(i,n)cout<<ans[i]<<endl;
}




Measured memory_bytes: 8448
#include <stdio.h>
#include <stdlib.h>

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treeMinimum(Node x){


}

Node treeMaximum(Node x){


}

Node treeSearch(Node u, int k){


}

Node treeSuccessor(Node x){


}

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y



}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x!=NIL){
    y = x;
    if(z->key < x->key){
      x = x->left;
    }
    else{
      x = x->right;
    }
  }

  z->parent = y;

  if(y==NIL){
    root =z;
  }
  else if(z->key < y->key){
    y->left = z;
  }
  else{
    y->right = z;
  }

}

void inorder(Node u){

  if(u->left!=NIL){
    inorder(u->left);
  }

  printf(" %d", u->key);

  if(u->right!=NIL){
    inorder(u->right);
  }

}
void preorder(Node u){

  printf(" %d", u->key);

  if(u->left!=NIL){
    preorder(u->left);
  }

  if(u->right!=NIL){
    preorder(u->right);
  }

}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }

  return 0;
}


Measured memory_bytes: 25132
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        long num, x, sum=0;
        Scanner scanner = new Scanner(System.in);
        num = scanner.nextLong();
        x = scanner.nextLong();
        //scanner.nextLine();
        for(int i=0; i<x; i++) sum += scanner.nextLong();
        if(sum > num){
            System.out.println(-1);
        }
        else System.out.println(num - sum);
    }
}

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

def dfs(s, mx):
  if len(s) == N:
    print(s)
  else:
    for i in range(ord('a'), ord(mx)+1):
      dfs(s+chr(i), chr(ord(mx)+1) if chr(i) == mx else mx)
      
dfs('', 'a')

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

const int MAX_N = 40, MAX_AB = 10, INF = (1<<20);

int a[MAX_N], b[MAX_N], c[MAX_N];
int dp[MAX_N + 1][MAX_N*MAX_AB + 1][MAX_N*MAX_AB + 1];

int main() {
	cin.tie(0); ios::sync_with_stdio(false);
	int N, Ma, Mb;
	cin >> N >> Ma >> Mb;
	for (int i = 0; i < N;i++) cin >> a[i] >> b[i] >> c[i];

	for (int i = 0; i <= N;i++) {
		for (int ca = 0; ca <= MAX_N*MAX_AB;ca++) {
			for (int cb = 0; cb <= MAX_N*MAX_AB;cb++) {
				dp[i][ca][cb] = INF;
			}
		}
	}
	dp[0][0][0] = 0;

	for (int i = 0; i < N;i++) {
		for (int j = 0; j <= MAX_N*MAX_AB;j++) {
			for (int k = 0; k <= MAX_N*MAX_AB;k++) {
				if (dp[i][j][k] == INF)continue;
				dp[i + 1][j + a[i]][k + b[i]] = min(dp[i + 1][j + a[i]][k + b[i]], dp[i][j][k] + c[i]);
				dp[i + 1][j][k] = min(dp[i + 1][j][k], dp[i][j][k]);
			}
		}
	}
	int ans = INF;
	for (int i = 1; i <= MAX_N*MAX_AB;i++) {
		for (int j = 1; j <= MAX_N*MAX_AB;j++) {
			if (i*Mb == j*Ma) {
				ans = min(ans, dp[N][i][j]);
			}
		}
	}
	if (ans == INF) ans = -1;
	cout << ans << endl;
}

Measured memory_bytes: 25984
from collections import defaultdict as dd
n, m = map(int, input().split())
P = list(map(lambda x: int(x) - 1, input().split()))

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

uf = UnionFind(n)
#print(P)
for i in range(m):
    x, y = map(lambda x: int(x) - 1, input().split())
    uf.union(x, y)

#dic[root] -> [i1, i2, ...]
dic_idx = dd(set)
#dic[root] -> [p1, p2, ...]
dic_p = dd(set)
visited_root = set()

for i, p in enumerate(P):
    root = uf.find(i)
    visited_root.add(root)
    dic_idx[root].add(i)
    dic_p[root].add(p)

#print(dic_idx)
#print(dic_p)
#print(visited_root)

ans = 0
for root in list(visited_root):
    #print(root, dic_idx[root] & dic_p[root])
    ans += len(dic_idx[root] & dic_p[root])
print(ans)

Measured memory_bytes: 159956
import java.util.*;

public class Main {
    public static void main(String [] args) {
        Scanner sc = new Scanner(System.in);
        String S = sc.next();
        sc.close();
        int length = S.length();
        if(length == 3) {
            char [] array = S.toCharArray();
            for (int i = 2; i >=0; i --) {
                 System.out.print(array[i]);
            }
        } else {
                System.out.println(S);
        }
    }
}

Measured memory_bytes: 22612
#include <stdio.h>

using namespace std;

int main(){
	int n;
	scanf("%d",&n);
	int A[n];

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

	for(int i = n-1; i > 0; i--) printf("%d ",A[i]);
	printf("%d\n",A[0]);
}


Measured memory_bytes: 2760
# -*- coding: utf-8 -*-
import collections
n = int(input())
a = [int(i) for i in input().split()]

ans = 0
c = collections.Counter(a)
#print(c)
#print(set(a))
b = list(set(a))
for i in range(len(b)):
    tmp = c[b[i] - 1] + c[b[i]] + c[b[i] + 1]
    #print(tmp)
    if ans < tmp:
        ans = tmp
print(ans)


Measured memory_bytes: 15064
#include <iostream>
#include <string>
#include <vector>
#include <numeric>
#include <queue>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <sstream>
#include <stack>
#include <map>
#include <set>

#define STARTUP {(cin.tie(0));\
 (ios::sync_with_stdio(false));}

#define REP(i,a) for(int i = 0;i < (a);++i)
#define FOR(i,a,b) for(int i = (a);i < (b); ++i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SIZE(obj) (int)(obj).size()
#define MAX(list) std::max(list)
#define MIN(list) std::min(list)
#define YESNO(cond,yes,no){cout <<((cond)?(yes):(no))<<endl; }
#define SORT(list) sort(ALL((list)));
#define RSORT(list) sort((list).rbegin(),(list).rend())
#define CINVEC(vec) REP(i,(vec).size()) cin>>(vec)[i];

template<typename T>
T round_up(const T& a, const T& b) {
    return (a + (b - 1)) / b;
}

template <typename T1, typename T2>
std::istream& operator>>(std::istream& is, std::pair<T1, T2>& p) {
    is >> p.first >> p.second;
    return is;
}

template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, std::pair<T1, T2>& p) {
    os << p.first << p.second;
    return os;
}

using ll = long long;
using namespace std;
ll mod = 1'000'000'007;

const int INF = 1'050'000'000;

int main() {
    STARTUP;

    char c;
    cin >> c;
    YESNO(c == 'a' || c == 'i' || c == 'u' || c == 'e' || c == 'o', "vowel", "consonant");
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		@SuppressWarnings("resource")
		Scanner scan = new Scanner(System.in);
		int a = scan.nextInt();
		int b = scan.nextInt();
		int h = scan.nextInt();

		System.out.println(((a + b) * h) / 2);

	}

}


Measured memory_bytes: 23124
#include <bits/stdc++.h>
using namespace std;
 
#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 FOR(e, c) for (auto &e : c)
#define SORT(v, n) sort(v, v + n);
#define vsort(v) sort(v.begin(), v.end());
#define rvisort(v) sort(v.begin(), v.end(), greater<int>());
#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 int long long
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
 
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 ul = unsigned long;
 
const int MOD = 1e9+7;
const int INF = 1e9;
const ll LINF = 1e18;
 
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
 
int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { return a * b / GCD(a, b); }
 
 
signed main()
{
  int a,b;cin>>a>>b;
  if(a>9||b>9) cout<<-1<<endl;
  else cout<<a*b<<endl;
}

Measured memory_bytes: 256