akhauriyash/Code-Regression huggingface dataset:
import sys
sys.setrecursionlimit(10000000)
input=sys.stdin.readline

N,Q=map(int,input().split())

T=[[] for i in range(N)]

for i in range(N-1):
    a,b=map(int,input().split())
    T[a-1].append(b-1)
    T[b-1].append(a-1)

O=[0 for i in range(N)]

for i in range(Q):
    p,x=map(int,input().split())
    O[p-1]+=x

def dfs(n,r):
    for i in T[n]:
        if i!=r:
            O[i]+=O[n]

            dfs(i,n)

dfs(0,-1)

print(*O)

Measured memory_bytes: 230920
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>
#include <cfloat>
#include <map>
#include <set>
#include <array>
#include <stdio.h>
#include <string.h>
using ll = long long;
using ull = unsigned long long;
using namespace std;
#define int long long
#define CONTAINS(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define REMOVE(v,a) (v.erase(remove((v).begin(), (v).end(), (a)), (v).end()))
#define REVERSE(v) (reverse((v).begin(), (v).end()))
#define ARY_REVERSE(v,a) (reverse((v), (v)+(a)))
#define REP(i, n) for (int (i)=0; (i) < (n); (i)++)
#define CONTAINS_MAP(m, a) (m).find((a)) != m.end()
void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; }
void YESNO(bool b) { cout << (b ? "YES" : "NO") << endl; }
//max_element



//---------- 1000000007 ----------
const int MOD = 1000000007;
int m_add(int a, int b)
{
	return (a + b) % MOD;
}
int m_sub(int a, int b)
{
	return (a + MOD - b) % MOD;
}
int m_mul(int a, int b)
{
	return (a * b) % MOD;
}
int m_pow(int x, int n)
{
	if (n == 0) return 1;
	ll res = m_pow((x * x) % MOD, n / 2);
	if (n & 1) res = (res * x) % MOD;
	return res;
}
int m_divide(int a, int b)
{
	return m_mul(a, m_pow(b, MOD - 2));
}
int m_comb(int n, int r)
{
	int i;
	int p = 1;
	for (i = 1; i <= r; i++)
	{
		p = m_mul(p, (n - i + 1));
		p = m_divide(p, i);
	}
	return p;
}
int m_comb_with_rep(int n, int r)
{
	return m_comb(n + r - 1, r);
}



int N, M;
int dp[100010];
bool flg[100010];

signed main()
{
	char c;
	cin >> c;
	switch (c)
	{
		case 'A': cout << 'T' << endl; break;
		case 'C': cout << 'G' << endl; break;
		case 'T': cout << 'A' << endl; break;
		case 'G': cout << 'C' << endl; break;
	}
}



Measured memory_bytes: 3600
#include <algorithm>
#include <array>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
using namespace std;

int main(int argc, char** argv) {
	string s;
	bool odd, even;
	odd = true;
	even = true;

	cin >> s;

	for (int i = 0; i < s.size(); i++) {
		switch (i % 2) {
		case 0:
			if (s.at(i) == 'L')
				odd = false;
			break;
		case 1:
			if (s.at(i) == 'R')
				even = false;
			break;
		}
	}

	cout << ((odd && even) ? "Yes" : "No") << endl;

	return 0;
}


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

int main() {
  int n; cin>>n;
  int a,b; cin>>a>>b;
  ll count=0;
  for(ll i=1;i<=n;i++){
    ll value=i;
    int sum=0;
    while(value>=1){sum+=value%10;
      value/=10;}
    if(sum>=a&&sum<=b) count+=i;
  }
  cout<<count<<endl;
}

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

struct edge {
    int to, cost;
};
class dijkstra {
    int V;
    int d[100002];
    priority_queue<P, vector<P>, greater<P>> que;
    void update(int s, vector<edge> G[]) {
        fill(d, d + V + 1, 100000000000ll);
        d[s] = 0;
        que.push(make_pair(0, s));
        while (!que.empty()) {
            P p = que.top();
            que.pop();
            int v = p.second;
            if (d[v] < p.first) continue;
            rep(i, G[v].size()) {
                edge e = G[v][i];
                if (d[e.to] > d[v] + e.cost) {
                    d[e.to] = d[v] + e.cost;
                    que.push(make_pair(d[e.to], e.to));
                }
            }
        }
    }

public:
    dijkstra(int v, int s, vector<edge> G[]) {
        V = v;
        update(s, G);
    }
    int find(int e) {
        return d[e];
    }
};
int gcd(int a, int b) {
    if (a % b == 0)
        return b;
    else
        return gcd(b, a % b);
}
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}
bool prime(int a) {
    if (a == 1) return false;
    for (int i = 2; i * i <= a; i++) {
        if (a % i == 0) return false;
    }
    return true;
}
class Union_Find {
private:
    vector<int> t, s;

public:
    Union_Find(int max_length) {
        rep(i, max_length + 1) {
            t.push_back(i);
            s.push_back(1);
        }
    }
    void Union(int x, int y) {
        if (same(x, y)) return;
        int tx = Find(x), ty = Find(y);
        if (s[tx] < s[ty]) {
            s[ty] += s[tx];
            t[tx] = ty;
        }
        else if (s[tx] > s[ty]) {
            s[tx] += s[ty];
            t[ty] = tx;
        }
        else if (tx > ty) {
            t[tx] = ty;
            s[ty] += s[tx];
        }
        else {
            t[ty] = tx;
            s[tx] += s[ty];
        }
    }
    int Find(int n) {
        if (t[n] == n)
            return n;
        else
            return t[n] = Find(t[n]);
    }
    bool same(int x, int y) {
        return Find(x) == Find(y);
    }
    int get_Size(int a) {
        return s[a];
    }
};
signed main() {
    string s;
    cin>>s;
    int cnt=0;
    rep(i,s.size()){
        if(s[i]=='o')cnt++;
    }
    if(cnt+15-s.size()>=8)cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
}


Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;
int main(){
    int a,b;
    cin >> a >> b;
    cout << max(a+b,max(a-b,a*b)) << endl;
}

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

using namespace std;

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

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

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

ll L[100];

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

    L[0] = 2;
    L[1] = 1;

    int N;
    std::cin >> N;
    
    for(int i=2;i<=N;++i){
        L[i] = L[i-1] + L[i-2];
    }

    std::cout << L[N] << std::endl;
}


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

const int MAX = 1010000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

int main() {
    // 前処理
    COMinit();
    
    int x, y; cin >> x >> y;
    int a, b, ans;
    
    if (2*y - x >= 0 && 2*x - y >= 0 && (2*y - x) % 3 == 0 && (2*x - y) % 3 == 0) {
        a = (2*y - x)/3;
        b = (2*x - y)/3;
        ans = fac[a + b] * (finv[a] * finv[b] % MOD) % MOD;
    }else{
        ans = 0;
    }
    // 計算例
    cout << ans << endl;
    return 0;
}


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

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;

ll N;
vector<ll> v;

int main(){
    cin >> N;
    for(ll i=1;i*i<=N;i++){
        if(N%i==0){
            v.push_back(i);
            if(i*i != N) v.push_back(N/i);
        }
    }
    ll ans = 0;
    for(auto &e : v){
        if(e==1) continue;
        if(N % (e-1) == 0) continue;
        if(N / (e-1) == N % (e-1)) ans += (e-1);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3688
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
using P = pair<string,int>;
int n;
vector<P> v[10];
int main(){
	cin >> n;
	rep(i,n){
		if(i == 0) v[i].push_back(P{"a",1});
		else{
			for(P p: v[i-1]) rep(j, p.second+1){
				v[i].push_back(P{p.first + (char)('a'+j), p.second + (j==p.second)});
			}
		}
	}
	for(P p: v[n-1]) cout << p.first << '\n';
}

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

using namespace std;


signed main(){
    int N;cin >> N;
    vector<int> a, b;
    set<int> se;
    for(int i = 0;i < N;i++){
        int c;cin >> c;
        a.push_back(c-1);
    }
    for(int i = 0;i < N;i++){
        int c;cin >> c;
        b.push_back(c-1);
        se.insert(c-1);
    }
    if(se.size() == N){
        cout<<"Yes"<<endl;
        return 0;
    }
    cout<<"No"<<endl;
    vector<int> g(N, 1),h(N, 1);
    for(int i = 0;i < N;i++){
        if(se.find(a.at(i)) == se.end()){
            g.at(i) = 1;
            h.at(i) = 2;
        }
    }
    for(int i = 0;i < N;i++){
        cout<<g.at(i)<<(i != N-1 ? " " : "");
    }
    cout<<endl;
    for(int i = 0;i < N;i++){
        cout<<h.at(i)<<(i != N-1 ? " ": "");
    }
    cout<<endl;
}



Measured memory_bytes: 8360
#include <iostream>
#include <utility>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stack>
#include <set>
#include <deque>
#include <cmath>
#include <cassert>

using namespace std;
typedef long long ll;
ll mod = 1e9+7;
#define rep(i,n) for(int i = 0; i < (n); ++i)

int main() {
    int n;
    cin >> n;
    ll ans = 0;
    vector<int> d(n+1);
    for (int i = 1; i <= n; ++i) {
        for (int j = i; j <= n; j += i) ++d[j];
    } 
    for (int i = 1; i <= n; ++i) ans += ll(i) * d[i];
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 42304
#include <cstdio>

typedef long long LL;
const int Mod = 1000000007;
const int MN = 10000005, MA = 5005;

inline int qPow(int b, int e) {
	int a = 1;
	for (; e; e >>= 1, b = (LL)b * b % Mod)
		if (e & 1) a = (LL)a * b % Mod;
	return a;
}

int Fac[MN], iFac[MN], Inv[MN];
inline void Init(int N) {
	Fac[0] = 1;
	for (int i = 1; i <= N; ++i) Fac[i] = (LL)Fac[i - 1] * i % Mod;
	iFac[N] = qPow(Fac[N], Mod - 2);
	for (int i = N; i >= 1; --i) iFac[i - 1] = (LL)iFac[i] * i % Mod; 
	for (int i = 1; i <= N; ++i) Inv[i] = (LL)iFac[i] * Fac[i - 1] % Mod;
}
inline int Binom(int N, int M) {
	return (LL)Fac[N] * iFac[M] % Mod * iFac[N - M] % Mod;
}

int N, A;

int main() {
	scanf("%d%d", &N, &A);
	Init(N);
	int Ans = 0;
	for (int t = 2; t <= A + 1; ++t) {
		int a = t - 1, b = N - A, c = t <= A ? A - t : 0;
		for (int d = 0; d <= a; ++d)
			Ans = (Ans + (d & 1 ? -1ll : 1ll) * Binom(a, d) * Fac[a - d + b + c] % Mod * (a - d) % Mod * Inv[a - d + b]) % Mod;
	}
	printf("%d\n", (Ans + Mod) % Mod);
	return 0;
}

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

int main(){
  int N1,N2,X1,X2,buf;
  cin >> N1 >> N2 >> X1 >> X2;

  int edge1= X1;
  int edge2= X2;

  for(int i=0; i<N1; i++){
    cin >> buf;
    edge1= max(edge1,buf);
  }
  for(int i=0; i<N2; i++){
    cin >> buf;
    edge2= min(edge2,buf);
  }

  if(edge1 < edge2){
    cout << "No War" << endl;
  }
  else{
    cout << "War" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define x first
#define y second
#define pb push_back
#define mp make_pair
typedef pair<int, int> pii;
typedef long long ll;
const int MOD = 1e9+7;
const int BASE = 27;
const int N = 500003;
const ll oo = 1e18;
const double EPS = 1e-9;

ll adl(ll a , ll b){
	return (a+b)%MOD;
}
ll mul(ll a , ll b){
	return (a*b)%MOD;
}
ll fast(ll a , ll b){
	if(!b)return 1ll;
	ll res = fast(a,b/2);
	res = mul(res,res);
	if(b&1)return mul(res,a);
	return res;
}
int pre[N],num[N],pst[1<<20+1],last[1<<20+1],dp[N],n,a[N],sumZero[1<<20+1];

ll ans = 0;

int main() {
	cin >> n;
	for (int i = 1; i <= n; ++i){
		scanf("%d",a+i);
		pre[i] = a[i]^pre[i-1];
		num[i] = (pre[i]==0) + num[i-1];
	}

	if(pre[n] == 0){
		for(int i = 1 ; i <= (1<<20);++i)last[i] = n,sumZero[i] = 1;
		for(int i = n-1; i >= 1;--i){
			if(pre[i]==0)continue;
			int cur = pre[i];
			int numOfZero = num[last[cur]]-num[i];
			sumZero[cur] = adl(sumZero[cur],mul(numOfZero,pst[cur]));
			
			dp[i] = sumZero[cur];
			pst[cur] = adl(pst[cur],dp[i]);
			last[cur] = i;
		}
		ans = adl(ans,fast(2,num[n]-1));
	}else{
		dp[n] = 1;
		int smZ = 0, smO = 1;
		for(int i = n-1;i >= 1 ; --i){
			if(pre[i]==pre[n]){
				dp[i] = smZ;
				smO = adl(smO,dp[i]);
			}
			if(pre[i]==0){
				dp[i] = smO;
				smZ = adl(smZ,dp[i]);
			}
		}

	}
	for(int i = 1; i <= n;++i)if(pre[i])ans = adl(ans,dp[i]);
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 26496
N=int(input())
def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i:
        divisors.append(n//i)
  return divisors
A=make_divisors(N)
ans=0
for i in A:
  if i==1:
    continue
  a=N//(i-1)
  b=N%(i-1)
  if a==b:
    ans+=(i-1)
print(ans)

Measured memory_bytes: 3356
#include<iostream>

using namespace std;

#define long long long

long n, s, m;
long w[101], v[101], dp[101][100000];

long cal(int idx, long val) { 
    if (val == 0) return 0;
    if (idx > n) return 1e18;
    if (dp[idx][val] != -1) return dp[idx][val];
    dp[idx][val] = 0;

    if (val - v[idx] >= 0) dp[idx][val] = min (cal(idx + 1, val), cal(idx + 1, val - v[idx]) + w[idx]);
    else dp[idx][val] = cal(idx + 1, val);
    return dp[idx][val];
}

void FastInput() {
    ios_base::sync_with_stdio(NULL);
    cin.tie(NULL);
    cout.tie(NULL);
    //freopen(".inp", "r", stdin);
    //freopen(".out", "w", stdout);
}

void Input() {
    cin >> n >> m;
    for (int i = 1; i <= n; i ++) cin >> w[i] >> v[i], s += v[i];
    for (int i = 0; i <= n; i ++)
        for (int j = 0; j <= s; j ++) dp[i][j] = -1;
}

void Solve() {
    for (int i = s; i >= 1; i --) {
        long res = cal(1, i);
        if (res <= m) {
            cout << i;
            return;
        }
    }
}

int main() {
    FastInput();
    Input();
    Solve();
}

Measured memory_bytes: 82436
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int> a(N);
  for (int i=0; i<N; i++) cin >> a[i];
  int ans = 0;
  for (int i=0; i<N; i++) {
    ans += a[i]-1;
  }
  cout << ans << endl;
}
  

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

using namespace std;

typedef unsigned long long ull;
#define loop(i,a,b) for(int i=(a);i<ull(b);++i)
#define rep(i,n) loop(i,0,n)
#define all(a) (a).begin(), (a).end()

const double eps = 1e-10;
const double pi  = acos(-1.0);
const double inf = (int)1e8;

int main(){
	string s;
	getline(cin, s);
	rep(i, s.size()){
		if(s.substr(i, 5) == "apple") s.replace(i, 5, "peach");
		else if(s.substr(i, 5) == "peach") s.replace(i, 5, "apple");
	}
	cout << s << endl;
}

Measured memory_bytes: 1184
#include<bits/stdc++.h>
using namespace std;
#define int ll
#define ll long long

#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
// #define MOD 998244353 
#define MEM_SIZE 100010
#define DEBUG_OUT true
#define ALL(x) (x).begin(), (x).end()

template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return; std::cout << e <<" ";}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){std::cout<< e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T,class... Ts> void DEBUG(T d, Ts... e){if(DEBUG_OUT == false)return;DEBUG(d);DEBUG(e...);}
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; abort();}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

void chmaxs(string &s,string ref)
{
  int flg = 0;
  
  if(s == ref)return;

  if(ref.size() != s.size())
  {
    if(ref.size() > s.size())
    {
      s = ref;
      return;
    }
    else
    {
      return;
    }
  }
    

  if(ref.size() == s.size());
  {
    for (int i = 0; i < s.size(); i++)
    {
      if(ref[i] != s[i])
      {
        if(ref[i] > s[i])
        {
          s = ref;
          return;
        }
        else
        {
          return;
        }
        
      }
    }
    
  }
  return;
}


void solve(void)
{
  vector<int> data = {0,2,5,5,4,5,6,3,7,6};
  int N,M; cin>>N; cin>>M;
  vector<int> vec (M,0);
  for (int i = 0; i < M; i++)
  {
     cin>>vec[i];
  }
  vector<string> DP (N+1,"");//i本のマッチを用いて作ることが可能な整数のうち最大のものを格納する。
  for (int i = 1; i <= N; i++)
  {
    for (int j = 0; j < M; j++)
    {
      int fi = i - data[vec[j]];
      if(fi < 0 )continue;
      if(fi != 0 && DP[fi] == "")continue;
      chmaxs(DP[i],DP[fi] + to_string(vec[j]));
    }
    
  }
  cout<<DP[N]<<endl;

  
  return;
}
int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(11);
  solve();

  return 0;
}


Measured memory_bytes: 51232
l, r = gets.strip.split(' ').map(&:to_i)

if (r-l+1 >= 2019)
  p 0
  exit
end




result = 2019

arr = (l..r).to_a
arr.each_with_index do |num, i|
  
  arr.each_with_index do |num, j|

    next if  i>=j
    tmp = (arr[i] * arr[j])%2019
#    p [arr[i], arr[j]] if tmp < result
    result = [tmp, result].min

  end
end

p result





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

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;

#define INF (1LL << 60)
#define MOD 1000000007
#define PI 3.14159265358979323846

#define REP(i,m,n) for(ll (i)=(m),(i_len)=(n);(i)<(i_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define ASC(x) sort(ALL((x)))
#define DESC(x) sort(ALL((x)),greater<ll>())
#define REV(x) reverse(ALL((x)))
#define pb push_back

int main()
{
    string S;
    cin >> S;
    ll K;
    cin >> K;

    ll N = SZ(S);
    ll M = MAX(K,N);
    ll dp[N+1][2][M+1]; // dp[桁][未満フラグ][0でない個数]
    REP(i,0,N+1) {
        REP(smaller,0,2) {
            REP(k,0,M+1) {
                dp[i][smaller][k] = 0;
            }
        }
    }
    dp[0][0][0] = 1;

    REP(i,0,N) {
        REP(smaller,0,2) {
            REP(k,0,K+1) {
                REP(n,0,smaller?10:(S[i]-'0')+1) {
                    dp[i + 1][smaller || n < (S[i]-'0')][k + (n > 0)] += dp[i][smaller][k];
                }
            }
        }
    }

    PR(dp[N][0][K]+dp[N][1][K]);

    return 0;
}

/*



*/

Measured memory_bytes: 3708
#include<iostream>
#include<algorithm>
using namespace std;
int main(void)
{
    int masu,N,ba[1001],sai,now=1,crear=1005;
    while(1){
    cin>>masu>>N;
    if(masu==0&&N==0)break;
    for(int i=1;i<=masu;i++)cin>>ba[i];
    for(int i=1;i<=N;i++){
        cin>>sai;
        if(crear==1005){
            now+=sai;
            now+=ba[now];
            if(crear>i&&now>=masu)crear=i;
        }
    }
    cout<<crear<<endl;
    crear=1005;now=1;
    }
}

Measured memory_bytes: 1164
#include<stdio.h>

int main(void){
	
	int n;
	
	scanf("%d", &n);
	
	int r[n], t;
	
	for(t=0; t<n; t++){
		scanf("%d", &r[t]);
	}
	
	int i, j, maxv=-999999999, minv=r[0];
	
	for(j=1; j<n; j++){
		
		if(maxv < r[j]-minv){
			maxv = r[j]-minv;
		}
		
		if(r[j] < minv){
			minv = r[j];
		}
	}
	
	
	/*for(i=0; i<n; i++){	
		
		if(max < max+r[i]){
			max=max+r[i];
		}
		
		if(max < r[i+1]-r[i]){
			max=r[i+1]-r[i];
		}	
	}*/
	
	
	printf("%d\n", maxv);
	return 0;
	
}



Measured memory_bytes: 2508
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define FORR(i,a,b) for (int i=(a);i>=(b);i--)
#define pb push_back
#define pcnt __builtin_popcount
#define show(x) cout<<#x<<" = "<<x<<endl;
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define fi first
#define se second
#define rng(a) (a.begin()),(a.end())
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define sz(x) (int)(x).size()
#define mp make_pair

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef set<int> si;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pll> vpll;
typedef set<ll> sl;
typedef __int128_t lll;
typedef pair<lll,lll> plll;
typedef vector<lll> vlll;
template<typename T>string join(vector<T>&v)
{stringstream s;FOR(i,0,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename A, size_t N, typename T>void Fill(A (&array)[N], const T&v)
{fill((T*)array,(T*)(array+N),v);}
ll gcd(ll a,ll b){if(a>b)swap(a,b);for(;a>0;b%=a,swap(a,b));return b;}
int modpow(ll a,ll n,int m){if(a==0)return a;ll p=1;for(;n>0;n/=2,a=a*a%m)if(n&1)p=p*a%m;return(int)p;}
void dout(double d){printf("%.12f\n",d);}

const int iinf = 1e9;
const ll linf = 1e18;
const int mod = 1e9+7;
const double pi = acos(-1);
const double eps = 1e-10;
int n, h;
vpii v;
vi vv;
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n >> h;
  FOR(i, 0, n){
    int a, b;
    cin >> a >> b;
    v.pb(mp(a, b));
  }
  sort(rng(v));
  int l = sz(v), m = v[l-1].fi;
  FOR(i, 0, l) if(v[i].se >= m) vv.pb(v[i].se);
  sort(rng(vv));
  reverse(rng(vv));
  ll ans = 0;
  FOR(i, 0, sz(vv)){
    ans++;
    h -= vv[i];
    if(h <= 0) break;
  }
  if(h > 0) ans += (h-1)/m + 1;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1908
#include <cstdio>
#include <cmath>
#include <iostream>
#include <set>
#include <algorithm>
#include <vector>
#include <map>
#include <cassert>
#include <string>
#include <cstring>
#include <queue>

using namespace std;

#define rep(i,a,b) for(int i = a; i < b; i++)
#define S(x) scanf("%d",&x)
#define S2(x,y) scanf("%d%d",&x,&y)
#define P(x) printf("%d\n",x)
#define all(v) v.begin(),v.end()
#define FF first
#define SS second
#define pb push_back
#define mp make_pair

typedef long long int LL;
typedef pair<int, int > pii;
typedef vector<int > vi;

const int N = 11;

int P[N], C[N];

int main() {
  int d,g;
  S2(d,g);
  g /= 100;
  rep(i,0,d) {
    S2(P[i], C[i]);
    C[i] /= 100;
  }
  int ans = 100 * d;
  rep(i,0,1<<d) {
    int cnt = 0;
    int val = 0;
    rep(j,0,d) if((i >> j) & 1) {
      cnt += P[j];
      val += (j + 1) * P[j] + C[j];
    }
    int rem = g - val;
    int mn = 100000;
    if(rem < 0) {
      mn = 0;
    } else {
      rep(j,0,d) if(!((i >> j) & 1)) {
        int tmp = (rem + j) / (j + 1);
        if(tmp <= P[j]) {
          mn = min(mn, tmp);
        }
      }
    }
    ans = min(ans, cnt + mn);
  }
  P(ans);
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
 
class Main{
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String inputValue = scanner.next();
        int height = Integer.valueOf(inputValue);
        inputValue = scanner.next();
        int width = Integer.valueOf(inputValue);
        if(height < 1 || width > 100){
            System.out.println("input value error: " + inputValue);
            return;
        }
        int area = height * width;
        int circumference = (height * 2) + (width * 2);
        System.out.println(area + " " + circumference);
        return;
    }
}


Measured memory_bytes: 25928
s = { i:input() for i in ["a", "b", "c"]}

next = s["a"][0]
s["a"] = s["a"][1:]

while True:

    if s[next] == "":
        break
    else:
        tmp = next
        next = s[tmp][0]
        s[tmp] = s[tmp][1:]

print(next.upper())


Measured memory_bytes: 3188
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
using namespace std;
const int INF = 1e9;

int main(){
    int N, M;  cin >> N >> M;
    vector<int> a(M, 0), k(M, 0);
    for(int m=0; m<M; m++){
        int b;  cin >> a[m] >> b;
        for(int i=0; i<b; i++){
            int c;  cin >> c;  c--;
            k[m] += pow(2, c);
        }
    }

    int P = pow(2, N);
    vector<vector<int>> dp(M, vector<int>(P, INF));
    dp[0][0] = 0;  dp[0][k[0]] = a[0];
    for(int m=1; m<M; m++){
        for(int p=0; p<P; p++){
            if(dp[m-1][p] == INF)
                continue;

            // 鍵 m を用いない場合
            dp[m][p] = min(dp[m][p], dp[m-1][p]);

            // 鍵 m を用いる場合
            int result = (p | k[m]);
            if(result == p){
                dp[m][p] = min(dp[m][p], dp[m-1][p]);
                continue;
            }
            dp[m][result] = min(dp[m][result], dp[m-1][p] + a[m]);
        }
    }

    if(dp[M-1][P-1] == INF){
        cout << -1 << endl;
    }else{
        cout << dp[M-1][P-1] << endl;
    }
}

Measured memory_bytes: 16256
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define all(x) x.begin(),x.end()
#define dbg(x) cout<<#x<<":"<<x<<endl
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,P> PP;

int main(){
  ll k,a,b;
  cin>>k>>a>>b;

  if(b<a||a>=k){
    cout<<k+1<<endl;
    return 0;
  }

  ll t=k-(a-1);
  cout<<max(k+1,t/2*(b-a)+a+t%2)<<endl;
  
  return 0;
}


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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(a)     (a).begin(),(a).end()
#define RALL(a)     (a).rbegin(),(a).rend()
#define PRINT(a)   cout << (a) << endl

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define Fi first
#define Se second

#define debug(x) cerr << x << " " << "(L:" << __LINE__ << ")" << '\n';

using ll = long long int;
using P = pair<int,int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using pii = pair<int, int>;

template <typename T> using PQ = priority_queue<T>;
template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7;

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

  if(k==1 || k==7){
    cout << 1 << endl;
    return 0;
  }

  int t = 7;
  int ans = 0;
  map<int,int> mp;
  while(t!=0 ){
    t *= (10%k);
    t += (7%k);
    t %= k;
    ans++;
    mp[t]++;
    if(mp[t]>=2){
      ans = -2;
      break;
    }
  }
  cout << ans+1 << endl;
}



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

int main() {
	int n;
	float x[4],y[4];
	float slope1,slope2;
	
	cin >> n;
	for ( int i = 0; i < n; i++ ) {
		for ( int j = 0; j < 4; j++ )
			cin >> x[j] >> y[j];
		slope1 = (y[1] - y[0]) / (x[1] - x[0]);
		slope2 = (y[3] - y[2]) / (x[3] - x[2]);
		if ( slope1 == slope2 )
			cout << "YES" << endl;
		else
			cout << "NO" << endl;
	}
}

Measured memory_bytes: 1224
n=int(input())

def yakusu(num):
    list_a=[]
    for i in range(1,num//2+1):
        if num % i == 0:
            list_a.append(i)
    list_a.append(num)
    return list_a

ans=0
for i in range(1,n+1):
    if len(yakusu(i)) == 8 and i % 2 == 1:
        ans += 1
print(ans)


Measured memory_bytes: 2940
n = input()
N = []
N.append(int(n[0]))
N.append(int(n[1]))
N.append(int(n[2]))

if N[0] * 100 + N[0] * 10 + N[0] >= N[0] * 100 + N[1] * 10 + N[2]:
    print(N[0] * 100 + N[0] * 10 + N[0])
else:
    print((N[0] + 1) * 100 + (N[0] + 1) * 10 + (N[0] + 1))


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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

// 最大公約数
ll gcd(ll a,ll b){
   if (a%b == 0) return(b);
   else return(gcd(b, a%b));
}

// 最小公倍数
ll lcm(ll a, ll b){
    return a*b/gcd(a, b);
}

int main()
{
    cout << fixed << setprecision(15);
    ll N, Z, W;
    cin >> N >> Z >> W;

    vector<ll> A(N);

    REP(i, N){
        cin >> A[i];
    }

    if(N >= 2){
        cout << max(abs(A[N-1]-W), abs(A[N-2]-A[N-1])) << endl;
    }
    else{
        cout << abs(A[N-1]-W) << endl;
    }
    
    return 0;
}

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


using namespace std;

typedef long long ll;

#define pi 2*acos(0.0)


int main(void)
{
    //ios_base::sync_with_stdio(false);
    //cin.tie(0);
    // cout.tie(0);
  set<ll>s;

  int n;
  cin>>n;
  bool flag = true;
  while(n--)
  {
      ll x;
      cin>>x;
      if(s.count(x)>0)
      {
          flag = false;
      }
      s.insert(x);
  }
  if(flag)
  {
      cout<<"YES"<<endl;
  }
  else
  {
      cout<<"NO"<<endl;
  }
}


Measured memory_bytes: 12912
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, x, n) for (int i = x; i < (n); i++)
#define all(n) begin(n), end(n)
struct cww
{
    cww()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
} star;
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<char> vchar;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;
#define vcin(a)                          \
    for (int i = 0; i < (a).size(); i++) \
        cin >> (a)[i];

int main()
{
    string s;
    cin >> s;
    int n = s.size();
    if (n == 2)
    {
        if (s[0] == s[1])
            cout << 1 << " " << 2;
        else
        {
            cout << -1 << " " << -1;
        }
        return 0;
    }
    rep(i, n - 2)
    {
        if ((s[i] == s[i + 1] and s[i] != s[i + 2]) or (s[i] == s[i + 2] and s[i] != s[i + 1]) or (s[i] != s[i + 2] and s[i + 1] == s[i + 2]))
        {
            cout << i + 1 << " " << i + 3;
            return 0;
        }
    }
    cout << -1 << " " << -1;
    return 0;
}

Measured memory_bytes: 512
A,B,C,D=gets.chomp.split(" ").map(&:to_i)
LCM=C.lcm(D)
####1から(A-1)まででCでもDでも割り切れないもの
x=(A-1)-((A-1)/C)-((A-1)/D)+((A-1)/LCM)
####1からBまででCでもDでも割り切れないもの
y=B-(B/C)-(B/D)+(B/LCM)
####引き算
print y-x

Measured memory_bytes: 1788
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
      	//入力値
      	int n = sc.nextInt();
      	//配列
      	int a[] =new int[n];
     	
     	//入力値を配列に格納
      	for(int i=0;i<n;++i){
          a[i] = sc.nextInt();
        }
      	//カウントする
      	int count = 0;
      	for(int i=0;i<n;i++){
        	 if(i + 1 == a[a[i]-1]) {
               ++count;
           }
        }
      
      System.out.print(count/2);
      
    }
}

Measured memory_bytes: 59244
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

struct node{
  int num;
  struct node *prev;
  struct node *next;
};
  
typedef struct node *NodePointer;


NodePointer make1node(NodePointer,int);
void showlist();
void insert(int);
void delete(int);
void deletefirst();
void deletelast();

NodePointer head;

int main(){
  int i, cou, num;
  char str[10];
  

  head = make1node(NULL, 0);
  head->next = head;
  head->prev = head;
  scanf("%d", &cou);

  
  for (i = 0; i < cou; i ++){
    scanf("%s", str);
    
    if(strcmp(str, "insert") == 0){
      scanf("%d", &num);
      insert(num);
    }
    if(strcmp(str, "delete") == 0){
      scanf("%d", &num);
      delete(num);
    }
    if(strcmp(str, "deleteFirst") == 0){
      deletefirst();
    }
    if(strcmp(str, "deleteLast") == 0){
      deletelast();
    }
  }
  showlist();
  return 0;
}

NodePointer make1node(NodePointer p, int num){
  NodePointer n;
  
  n = (NodePointer)malloc(sizeof(struct node));
  n->next = p;
  n->num = num;

  return n;
}

void showlist(){
  NodePointer n;

  n = head->next;
  while(n->next != head){
    printf("%d ",n->num);
    n = n->next;
  }
  printf("%d\n",n->num);
}

void insert(int num){
  NodePointer new;
  new = make1node(NULL, num);
  new->next = head->next;
  head->next->prev = new;
  head->next = new;
  new->prev = head;
}

void delete(int num){
  NodePointer n;
  /*
  for (n = head; n->next != NULL; n = n->next) {
    if (n->next->num == num){
      del = n->next;
      n->next = del->next;
      free(del);
      return n;
    }
  }
  return NULL;
  */

  n = head->next;
  while(n != head && n->num != num){
    n = n->next;
  }
  if(n != head){
    n->prev->next = n->next;
    n->next->prev = n->prev;
    free(n);
  }
}

void deletefirst(){
  NodePointer n;

  n = head->next;
  n->prev->next = n->next;
  n->next->prev = n->prev;
  free(n);
}

void deletelast(){
  NodePointer n, del;

  n = head->prev;
  n->prev->next = n->next;
  n->next->prev = n->prev;
  free(n);
}



Measured memory_bytes: 32956
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <cmath>
#include <complex>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cassert>
#include <iomanip>
using namespace std;

#define Rep(b, e, i) for(int i = b; i <= e; i++)
#define Repr(e, b, i) for(int i = e; i >= b; i--)
#define rep(n, i) Rep(0, n-1, i)
#define repr(n, i) Repr(n-1, 0, i)
#define all(v) (v).begin(), (v).end()
#define pb(v) push_back(v)
#define uniq(v) (v).erase(unique(all(v)),(v).end())
#define bitcnt(x) __builtin_popcount(x)
#define fst first
#define snd second
#define Pqaz(T) priority_queue<T,vector<T>,greater<T>>
#define Pqza(T) priority_queue<T>
#define put(x) cout << x;
#define putsp(x) cout << x << ' ';
#define putbd cout << "---------------------------------------------" << endl;
#define putln(x) cout << x << endl;
#define debug(x) cerr << #x << "=" << x << endl;
#define ENJYU std::ios::sync_with_stdio(false);std::cin.tie(0);

typedef long long ll;
typedef pair<ll, ll> llP;
typedef pair<int, int> intP;
typedef complex<double> comp;
typedef vector <int> vec;
typedef vector <ll> vecll;
typedef vector <double> vecd;
typedef vector <vec> mat;
typedef vector <vecll> matll;
typedef vector <vecd> matd;

//vector の中身を出力
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;}

const int MAX = 200020;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const ll INFL = 1e18;
const int MOD = 1000000007;

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

//********************************template END****************************************//

void solve(void){

	string S;
	cin >> S;

	if (S.length() >= 4 && S.substr(0,4) == "YAKI")
	{
		cout << "Yes" << endl;
	}
	else
	{
		cout << "No" << endl;
	}

}

int main(void){
	solve();
	//cout << "yui(*-v・)yui" << endl;
	return 0;
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    static Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        int num = sc.nextInt();
        double x[] = new double[num];
        double y[] = new double[num];
        for (int i = 0; i < num; i++)
            x[i] = sc.nextDouble();
        for (int j = 0; j < num; j++)
            y[j] = sc.nextDouble();
        double sum1 = 0;
        double sum2 = 0;
        double sum3 = 0;
        double maxInf[] = new double[num];
        for (int k = 0; k < num; k++){
            sum1 += Math.abs(x[k] - y[k]);
            sum2 += Math.pow(Math.abs(x[k] - y[k]), 2);
            sum3 += Math.pow(Math.abs(x[k] - y[k]), 3);
            maxInf[k] = Math.abs(x[k] - y[k]);
        }
        double p2 = Math.sqrt(sum2);
        double p3 = Math.cbrt(sum3);
        Arrays.sort(maxInf);
        System.out.println(sum1);
        System.out.println(p2);
        System.out.println(p3);
        System.out.println(maxInf[num - 1]);

    }
}



Measured memory_bytes: 29112
require 'prime'

class Integer
  def my_divisor_list
    divisors = [1]
    primes = []
    Prime.prime_division(self).each do |prime|
      prime[1].times {primes << prime[0]}
    end

    1.upto(primes.size) do |i|
      primes.combination(i) do |prime|
        divisors << prime.inject{|a,b| a *= b}
      end
    end

    divisors.uniq!
    divisors.sort!
    return divisors
  rescue ZeroDivisionError
    return
  end
end

N = gets.to_i
divisiors = N.my_divisor_list.select {|x| x <= Math.sqrt(N)}

ans = Float::INFINITY
f = 0

divisiors.each do |a|
	f = [a.to_s.length, (N/a).to_s.length].max
	ans = f if f < ans
end

p f

Measured memory_bytes: 12792
from itertools import combinations_with_replacement
from math import factorial
n,m,q=map(int,input().split())
lst=[list(map(int,input().split())) for i in range(q)]
total=[]
for a in combinations_with_replacement(range(1,m+1),n):
  ans=0
  for j in range(q):
    if int(a[lst[j][1]-1])-int(a[lst[j][0]-1])==lst[j][2]:
      ans+=lst[j][3]
  total.append(ans)

print(max(total))


Measured memory_bytes: 72300
/*
これを入れて実行
g++ code.cpp
./a.out
 */

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

using namespace std;
typedef long long ll;
typedef long double ld;

int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};

const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;

bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}

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

//-----------------------ここから-----------


int main(void){
	int a, b, c, d;
	cin >> a >> b >> c >> d;

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

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

using namespace std;
#define DBG(x)                         \
    (void)(cout << "L" << __LINE__     \
                << ": " << #x << " = " \
                << (x) << '\n')
typedef long long ll;
const int INF = 0x3f3f3f3f;
const int maxn = 20;
ll a[maxn][maxn];
ll c[maxn];
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setiosflags(ios::fixed) << setprecision(12);
    ll n, m, x;
    cin >> n >> m >> x;
    for (int i = 0; i < n; i++)
    {
        cin >> c[i];
        for (int j = 0; j < m; j++)
        {
            cin >> a[i][j];
        }
    }
    ll inf = 1LL << 63 - 1;
    ll ans = inf;
    ll num = 1LL << n;
    for (int i = 0; i < num; i++)
    {
        ll cur = i;
        vector<ll> b(m);
        ll cnt = 0;
        for (int j = 0; j < n; j++)
        {
            int id = cur >> j;
            if (id & 1)
            {
                cnt += c[j];
                //DBG(cnt);
                for (int k = 0; k < m; k++)
                {
                    b[k] += a[j][k];
                }
            }
        }
        int flag = 0;
        for (int t = 0; t < m; t++)
        {
            if (b[t] < x)
            {
                flag = 1;
                break;
            }
        }
        if (!flag)
        {
            ans = min(ans, cnt);
            //DBG(ans);
        }
    }
    if (ans == inf)
        cout << -1 << "\n";
    else
        cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 3536
class AtCoder {
  // 入力系
  input=require('fs').readFileSync('/dev/stdin','utf8').split(/[\s]/);
  input_i=-1;

  n(){
    this.input_i++;
    return Number(this.input[this.input_i]);
  }
  nn(n:number):number[]{
    const a=[];
    for(let i=0;i<n;i++){
      a.push(this.n());
    }
    return a;
  }
  s(){
    this.input_i++;
    return String(this.input[this.input_i]);
  }
  ss(n:number):string[]{
    const a=[];
    for(let i=0;i<n;i++){
      a.push(this.s());
    }
    return a;
  }

  // コンソール
  o(...a:any){
    console.log(...a);
  }

  // Math
  abs(a:number){
    return Math.abs(a);
  }
  min(...a:number[]){
    return Math.min(...a);
  }
  max(...a:number[]){
    return Math.max(...a);
  }
  floor(a:number){
    return Math.floor(a);
  }
  ceil(a:number){
    return Math.ceil(a);
  }
  round(a:number){
    return Math.round(a);
  }

  // ソート
  asc(ar:number[]){
    const t=[...ar];
    ar.sort((a,b)=>{return a-b});
  }
  desc(ar:number[]){
    const t=[...ar];
    ar.sort((a,b)=>{return b-a});
  }

  // 自作
  gcd(...arr:number[]):number{
    for(let i=0;i<arr.length-1;i++){
      let [x,y]=[arr[i],arr[i+1]];
      while(y){
        [x,y]=[y,x%y];
      }
      arr[i+1]=x;
    }
    return arr[arr.length-1];
  };
  lcm(...arr:number[]):number{
    for(let i=0;i<arr.length-1;i++){
      let [x,y]=[arr[i],arr[i+1]];
      while(y){
        [x,y]=[y,x%y];
      }
      arr[i+1]=arr[i]*arr[i+1]/x;
    }
    return arr[arr.length-1];
  };
  isPrime(n:number):boolean{
    if(n < 2) return false;
    const suq=Math.sqrt(n);
    for(let i=2;i<=suq;i++){
      if(n%i==0){
        return false;
      }
    }return true;
  };
  deduplicate(a:any[]):any[]{
    return Array.from(new Set(a));
  };
  f(roop:number, callback:any){
    for(let i=0;i<roop;i++){
      callback(i);
    }
  };
  Yes(){
    console.log('Yes');
  }
  No(){
    console.log('No');
  }
  YES(){
    console.log('YES');
  }
  NO(){
    console.log('NO');
  }
}
const m = () => {
  const o = new AtCoder();
  let [n, r] = o.nn(2);
  if(n>=10){
    o.o(r);
  }else{
    o.o(r+100*(10-n));
  }
}
m();

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

#define lli long long int
#define REP(i,s,l) for(lli i=s;i<l;i++)
#define DEBUG 0
#define INF (1LL<<50)
#define MOD 1000000007

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

    cout << pow(n, 3) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>

int main() {
    int n;
    std::string str, res = "No";
    std::cin >> n >> str;

    if(n % 2 == 0) {
        int h = n/2;

        if(str.substr(0, h) == str.substr(h)) {
            res = "Yes";
        }
    }

    std::cout << res << "\n";
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
#define map map1
bool map[100][100];
int main(){
    ios::sync_with_stdio(false);
    int a,b;
    cin>>a>>b;
    cout<<"100 100"<<endl;
    a--,b--;
    for (int i=0;i<50;i++)
        for (int j=0;j<100;j++)map[i][j]=1;
    int x=0,y=0;
    while (a--){
        map[x][y]=0;
        y+=2;
        if (y==100){
            x+=2;
            y=0;
        }
    }
    x=51,y=0;
    while (b--){
        map[x][y]=1;
        y+=2;
        if (y==100){
            x+=2;
            y=0;
        }
    }
    for (int i=0;i<100;i++){
        for (int j=0;j<100;j++)
            if (map[i][j])cout<<'#';
            else
                cout<<'.';
        cout<<endl;
    }
    return 0;
}

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

int main()
{
  ll n; cin >> n;
  ll a[n];
  rep(i,n) cin >> a[i];
  
  ll ans = 0;
  bool flag = false;
  while(1)
  {
    rep(i,n)
    {
      if(a[i] % 2 == 0)
      {
        a[i] /= 2;
        flag = true;
        ans++;
        break;
      }
    }
    
    if(flag == false)
    { 
      break;
    }
    flag = false;
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 3660
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner((System.in));
		int n = sc.nextInt();
		int m = sc.nextInt();
		int x = sc.nextInt();
		int ans = 0, l = 0, r = 0;

		for (int i = 0; i < m; i++) {
			int b = sc.nextInt();
			if (x < b) {
				r++;
			} else {
				l++;
			}
		}

		if (r < l) {
			ans = r;
		} else {
			ans = l;
		}

		System.out.println(ans);

		sc.close();
	}
}


Measured memory_bytes: 21844
// Traveling Salesman around Lake
#include <iostream>
#include <vector>
using namespace std;

int main(){
    int k,n;
    cin >> k >> n;
    int a[n];
    vector <int> b(n);
    for(int i=0; i<n; i++){
        cin >> a[i];
    }
    b[0]=a[0]+k-a[n-1];
    int y=a[0]+k-a[n-1];
 //   cout << y << endl;
    for (int i=1; i<n; i++){
        b[i]=a[i]-a[i-1];
 //       cout << a[i] << "-" << a[i-1] << " " <<  b[i] << endl;
        if(b[i]>y){
            y=b[i];
        }
    }

//        cout << y << endl;
        cout << k-y << endl;
        return 0;
    

}


Measured memory_bytes: 1792
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Math;

//https://beta.atcoder.jp/contests/abc112/tasks/abc112_c
public class Program_ABC112_C // ←Class名変更！！
{
    public static void Main(string[] args)
    {
        var n = int.Parse(ReadLine());

        var points = new int[n][];
        for (int i = 0; i < n; i++)
        {
            points[i] = Array.ConvertAll(ReadLine().Split(' '), int.Parse);
        }

        Array.Sort(points, (a, b) => b[2].CompareTo(a[2])); //高い順にソート  先頭が高さゼロだとh1が正しい値にならないのでソートする。

        var crest = new int[3] { -1, -1, -1 };
        for (var x = 0; x < 101; x++)
        {
            var xConst = points[0][2] + Abs(x - points[0][0]);
            for (var y = 0; y < 101; y++)
            {
                var h1 = xConst + Abs(y - points[0][1]);
                var isCrest = true;
                for (int i = 1; i < n; i++)
                {
                    var h2 = points[i][2] + Abs(x - points[i][0]) + Abs(y - points[i][1]);
                    if (0 < points[i][2])
                    {
                        //座標に高さがあるということは、ピラミッドの一部なので、h1=h2が成り立つ
                        if (h1 != h2)
                        {
                            isCrest = false;
                            break;

                        }
                    }
                    else
                    {
                        //座標の高さが0の場合、ピラミッドの底辺もしくは、ピラミッドの高さとは関係ない座標の2つが考えられる。
                        //ピラミッドの底辺の場合h1=h2となり、無関係な座標で頂点を計算すると、h2<h1となる。
                        //頂点を求めるのに十分な調査が行われたことは書いてあるが、余計な調査が行われていないとは書いてない
                        //if (h1 < h2)
                        if (h2 < h1)
                        {
                            isCrest = false;
                            break;
                        }
                    }
                }

                if (isCrest)
                {
                    crest = new[] { x, y, h1 };
                    Console.WriteLine($"{x} {y} {h1}");
                    return;
                    //break;
                }
            }

        }



        //Console.WriteLine($"{crest[0]} {crest[1]} {crest[2]}");

    } // Main
}     // Class





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

using ll = long long;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = (n); i > 0; i--)
#define all(n) n.begin(), n.end()
#define print(n) cout << n << endl

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

    int n,k,d,temp;
    cin >> n >> k;
    
    vector<int> a(n);
    rep(i,k){
        cin >> d;
        rep(j,d){
            cin >> temp;
            a[temp-1]++;
        }
    }
    int ans=0;
    rep(i,n){
        if(a[i]==0) ans++;
    }
    print(ans);
    return 0;    
}

Measured memory_bytes: 3664