akhauriyash/Code-Regression huggingface dataset:
def bfs():
    while q!=[]:
        color[q[0]-1]="grey"
        for i in m[q[0]-1]:
            if i==0:continue
            if color[i-1]=="white":
                color[i-1]="grey"
                q.append(i)
                d[i-1]=d[q[0]-1]+1
        del q[0]

n=input()
d=[0]*n
m=[[0]*n for _ in xrange(n)]
info=[0]*n
color=["white"]*n
for i in xrange(n):
    info[i]=map(int,raw_input().split())
    if info[i][1]==0:
        pass
    else:
       for j in info[i][2:]:
           m[info[i][0]-1][j-1]=j
q=[1]
bfs()
for i in xrange(n):
    if i!=0 and d[i]==0:
        print i+1,-1
    else:
        print i+1,d[i]

Measured memory_bytes: 6544
#include<cstdio>
#include<cmath>
#include<string>
#include<vector>
#include<algorithm>

using namespace std;

int main()
{
	int n;
	vector<long long> a, b;
	int i;
	long long input;
	long long sol = 0;

	scanf("%d", &n);

	for (i = 0; i < n - 1; i++)
	{
		scanf("%lld", &input);

		b.push_back(input);
	}

	sol += b[0];

	for (i = 1; i < n - 1; i++)
	{
		sol += b[i - 1] < b[i] ? b[i - 1] : b[i];
	}

	sol += b[n - 2];

	printf("%lld\n", sol);

	return 0;
}

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


int main() {
    string s;
    cin >> s;
    int n=s.size();
    s = s + 'R';
    int ans[100010]={0};
    int m=-1;
    for (int i=0;i<n;i++) {
        if (s[i]=='R' && s[i+1]=='L') {
            ans[i]+=(i-m)-(i-m)/2;
            ans[i+1]+=(i-m)/2;
            m=i;
        }
        else if (s[i]=='L' && s[i+1]=='R') {
            ans[m]+=(i-m)/2;
            ans[m+1]+=(i-m)-(i-m)/2;
            m=i;
        }
    }
    for (int i=0;i<n;i++) {
        cout << ans[i];
        if (i!=n-1) cout << ' ';
        else cout << endl;
    }
}

Measured memory_bytes: 1020
using System;
class Program
{
    public static void Main()
    {
        string[] str = Console.ReadLine().Split(' ');
        int a = int.Parse(str[0]);
        int b = int.Parse(str[1]);
        int c = int.Parse(str[2]);
        
        if(a < b)
        {   
            if(b < c)
                Console.WriteLine(a + " " + b + " " + c);
            else if(c > a)
                Console.WriteLine(a + " " + c + " " + b);
            else
                Console.WriteLine(c + " " + a + " " + b);
        }
        
        if(b < a)
        {
            if(a < c)
                Console.WriteLine(b + " " + a + " " + c);
            else if(b < c)
                Console.WriteLine(b + " " + c + " " + a);
            else
                Console.WriteLine(c + " " + b + " " + a);
        }
    }
    
}


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


int main(){
  ll n,k;
  cin >> n >> k;
  vector<int> a(n);
  for(int i=0;i<n;++i){
    cin >> a[i];
  }
  vector<int> s; //訪れた頂点
  vector<int> ord(n+1,-1); //s index
  int c=1; //周期
  int l=0;
  {
    int v=1;
    while(ord[v]==-1){
      ord[v]=s.size();
      s.push_back(v);
      v=a[v-1];

    }
    c=s.size()-ord[v];
    l=ord[v]; //例外部分の長さ
  }
  if(k<l) cout << s[k] << endl;
  else{
    k-=l;
    k%=c;
    cout << s[l+k] << endl;
  }
  return 0;

}


Measured memory_bytes: 5812
#include<bits/stdc++.h>
using namespace std;
#define sz(x) (int)x.size()
#define pb push_back
#define mp make_pair
#define ll long long 
#define mod 1000000007 
#define mod2 998244353
void fast(){
  ios_base::sync_with_stdio(false);cin.tie(NULL);
}



int main() {
   fast();
   int n;
   cin>>n;
   int a[n+1];
   int pre[n+1];
   int suf[n+1];
   for(int i=1;i<=n;i++){
    cin>>a[i];
   }
   if(n==1){
       cout<<mod-7<<"\n";
       return 0;
   }
   pre[1]=a[1];
   suf[n]=a[n];
   for(int i=2;i<=n;i++){
    pre[i]=__gcd(pre[i-1],a[i]);
   }
   for(int i=n-1;i>=1;i--){
      suf[i]=__gcd(a[i],suf[i+1]);
   }
   int ans=0;
   for(int i=1;i<=n;i++){
     if(i>1 && i<=n-1){
       ans=max(__gcd(pre[i-1],suf[i+1]),ans);
     }
     if(i==1){
      ans=max(suf[i+1],ans);
     }
     if(i==n){
      ans=max(pre[i-1],ans);
     }
   }
   cout<<ans<<"\n";


}


Measured memory_bytes: 4752
#include<stdio.h>
int main()
{
	int n;
	scanf("%d", &n);
	int i;
	double a[102];
	for (i = 0; i < n; i++)
		scanf("%lf", &a[i]);
	double ans = 0;
	for (i = 0; i < n; i++)
		ans += 1.0 / a[i];
	printf("%.20lf\n", 1.0 / ans);
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e6+10;
ll a[maxn]={0};
int main(){
    ll n;
    scanf("%lld",&n);
    ll n1=n;
    for(ll i=2;i*i<=n;i++){
        if(n1%i==0){
            ll cnt=0;
            while(n1%i==0) n1/=i,cnt++;
            a[i]=cnt;
        }
    }

    ll ans=0;
    if(n1>1) ans++;
    for(ll i=2;i*i<=n;i++){
        if(a[i]!=0){
            for(ll j=1;j<=n;j++){
                if(j*(j+1)/2>a[i]) break;
                ans++;
            }
        }
    }
    printf("%lld",ans);
  	return 0;
}

Measured memory_bytes: 3760
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
#define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define ll long long int
#define pb push_back
#define mod 1000000007
#define mp make_pair
#define fi first
#define se second
int main()
{
  fastIO
  ll n;
  cin>>n;
  ll dp[2][3],flag=0,a,b,c;
  memset(dp,0,sizeof(dp));
  cin>>a>>b>>c;
  dp[flag][0]=a;
  dp[flag][1]=b;
  dp[flag][2]=c;
  flag=(flag+1)%2;
  for(ll i=1;i<n;i++)
  {
    cin>>a>>b>>c;
    dp[flag][0]=max(dp[(flag+1)%2][1]+a,dp[(flag+1)%2][2]+a);
    dp[flag][1]=max(dp[(flag+1)%2][0]+b,dp[(flag+1)%2][2]+b);
    dp[flag][2]=max(dp[(flag+1)%2][0]+c,dp[(flag+1)%2][1]+c);
    //cout<<dp[flag][0]<<" "<<dp[flag][1]<<" "<<dp[flag][2]<<endl;
    flag=(flag+1)%2;
  }
  cout<<max(dp[(flag+1)%2][0],max(dp[(flag+1)%2][1],dp[(flag+1)%2][2]))<<"\n";
  return 0;
}


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

#define ll long long int
#define mp make_pair
#define pb push_back
using namespace std;

int main() {
    int n,m;
    cin >> n >> m;
    vector<ll> v(n);
    for (int i = 0; i < n; ++i) {
        cin >>v[i];
    }
    if(n == 1){
        printf("%lld",abs(m - v[0]));
        return 0;
    }
    v.push_back(m);
    sort(v.begin(), v.end());
    vector<ll> ans;
    for (int j = 0; j < v.size() - 1; ++j) {
        ans.push_back(v[j+1] - v[j]);
    }
    ll x = 0;
    for (int i = 0; i < ans.size(); ++i) {
        x = __gcd(ans[i] , x);
    }
    printf("%lld",x);
    return 0;
}

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

int main()
{
 
  int ind;
  int a[5];
  for(int i=0;i<5;i++)
  {
    cin>>a[i];
    if(a[i]==0)
      ind=i+1;
  }
  cout<<ind<<endl;
  return 0;
}

Measured memory_bytes: 3676
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>

using namespace std;

typedef pair <char, long> P;

int main() {
	long long ans = 0;
	long N;
	cin >> N;
	string st;
	vector<P> input(5);
	(input[0].first,input[0].second) = ('M',0); input[1].first,input[2].second = ("A", 0); 
	input[2].first,input[2].second = ("R", 0); input[3].first,input[3].second = ("C", 0); input[4].first,input[4].second = ("H", 0);
	for (int i = 0; i < N; i++){
		cin >> st;
		if (st[0] == 'M') input[0].second++;
		if (st[0] == 'A') input[1].second++;
		if (st[0] == 'R') input[2].second++;
		if (st[0] == 'C') input[3].second++;
		if (st[0] == 'H') input[4].second++;
	}
	for (int i = 0; i <= 2; i++) {
		for (int j = i+1; j <=3; j++) {
			for (int k = j+1; k <= 4; k++) {
				ans += input[i].second * input[j].second * input[k].second;
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <cstring>
#include <iostream>
using namespace std;
const int MAX_W = 15;
const int MAX_H = 15;

int w, h;
int field[MAX_H + 1][MAX_W + 2];
int dp[MAX_H + 1][MAX_W + 2];

void printfield() {
	for (int i = 0; i < h + 1; i++) {
		for (int j = 0; j <= w + 1; j++) {
			cout << '\t' << dp[i][j] << '(' << field[i][j] << ')';
		}
		cout << endl;
	}
}

int main () {
	while (cin >> w >> h, w || h) {
		memset(field, 0, sizeof(field));
		memset(dp, 0, sizeof(dp));
		for (int i = 0; i < h + 1; i++) {
			field[i][0] = 1;
			dp[i][0] = 0;
			field[i][w + 1] = 1;
			dp[i][w + 1] = 0;
		}
		for (int i = 0; i < h; i++) {
			for (int j = 1; j <= w; j++) {
				cin >> field[i][j];
			}
		}
		for (int i = 1; i <= w; i++) {
			if (field[0][i] == 0) dp[0][i] = 1;
		}
		for (int i = 0; i < h - 1; i++) {
			for (int j = 1; j <= w; j++) {
				if (field[i][j] == 0) {
					dp[i + 1][j] += dp[i][j];
					if (field[i + 1][j + 1] != 2) dp[i + 1][j + 1] += dp[i][j];
					if (field[i + 1][j - 1] != 2) dp[i + 1][j - 1] += dp[i][j];
				}
				else if (field[i][j] == 2) {
					dp[i + 2][j] += dp[i][j];
				}
			}
		}
//		printfield();
		int sum = 0;
		for (int i = h - 1; i < h + 1; i++) {
			for (int j = 1; j <= w; j++) {
				if (field[i][j] != 1) {
					sum += dp[i][j];
				}
			}
		}
		cout << sum << endl;
	}
	return 0;
}

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

#define ll long long int
#define str string
#define sec .second

ll MOD = 1000000007, INFL = 1ll << 60, INF = 1 << 30;
ll A[1000000] = {}, B[1000000] = {}, weight[1000] = {}, value[1000] = {};
ll dp[10][100002] = {};
int dy[] = { 0, 0, 1, -1 }, dx[] = { 1, -1, 0, 0 };
vector <ll> v;
ll a = 0, b = 0, c = 0, d = 0, e = 0, f = 0, n = 0, su = 0, ma = INF, mi = -1;
double ans;
str S;

bool an = true, bn = false;
long long mod = 1e9 + 7;

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

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	//Code Line
	cin >> n;
	for (int i = 0; i < n; i++)cin >> A[i];
	sort(A, A + n);
	if (n % 2 == 1)cout << 0 << endl;
	else cout << A[n / 2] - A[n / 2-1] << endl;
	
	return 0;
}


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

typedef vector<int> vi;

// Union-Find Disjoint Sets Library written in OOP manner, using both path compression and union by rank heuristics
class UnionFind {                                              // OOP style
private:
  vi p, rank, setSize;                       // remember: vi is vector<int>
  int numSets;
public:
  UnionFind(int N) {
    setSize.assign(N, 1); numSets = N; rank.assign(N, 0);
    p.assign(N, 0); for (int i = 0; i < N; i++) p[i] = i; }
  int findSet(int i) { return (p[i] == i) ? i : (p[i] = findSet(p[i])); }
  bool isSameSet(int i, int j) { return findSet(i) == findSet(j); }
  void unionSet(int i, int j) { 
    if (!isSameSet(i, j)) { numSets--; 
    int x = findSet(i), y = findSet(j);
    // rank is used to keep the tree short
    if (rank[x] > rank[y]) { p[y] = x; setSize[x] += setSize[y]; }
    else                   { p[x] = y; setSize[y] += setSize[x];
                             if (rank[x] == rank[y]) rank[y]++; } } }
  int numDisjointSets() { return numSets; }
  int sizeOfSet(int i) { return setSize[findSet(i)]; }
};

int main() {
	int N,M; cin>>N>>M;
	vector<int> p(N);
	for (int i=0; i<N; i++)
		cin>>p[i], p[i]--;
	UnionFind uf(N);
	for (int i=0; i<M; i++) {
		int x,y; cin>>x>>y; x--; y--;
		uf.unionSet(x,y);
	}
	int ret=0;
	map<int,vector<int>> gp;
	for (int i=0; i<N; i++)
		gp[uf.findSet(i)].push_back(i);
	for (auto it : gp) {
		set<int> cur;
		for (auto it2 : it.second)
			cur.insert(p[it2]);
		for (auto it2 : it.second)
			if(cur.count(it2))
				ret++;
	}
	cout<<ret<<"\n";
  return 0;
}

Measured memory_bytes: 12800
//Arayi
//#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <math.h>
#include <vector>
#include <cstring>
#include <ctime>
#include <set>
#include <bitset>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <ctime>
#include <climits>
#include <cassert>
#include <chrono>
#include <random>
#include <complex>

#define fr first
#define sc second
#define MP make_pair
#define ad push_back
#define PB push_back
#define fastio ios_base::sync_with_stdio(false); cin.tie(0);
#define lli long long int
#define y1 arayikhalatyan
#define j1 jigglypuff
#define ld long double
#define itn int
#define pir pair<int, int> 
#define all(x) (x).begin(), (x).end()
#define str string
#define enl endl
#define en endl
#define cd complex<long double>
#define vcd vector<cd>
#define vii vector<int>
#define vlli vector<lli>
using namespace std;

lli gcd(lli a, lli b) { return (b == 0LL ? a : gcd(b, a % b)); }
ld dist(ld x, ld y1, ld x2, ld y2)
{
    return sqrt((x - x2) * (x - x2) + (y1 - y2) * (y1 - y2));
}
lli S(lli a)
{
    return (a * (a + 1LL)) / 2;
}
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
char vow[] = { 'a', 'e', 'i', 'o', 'u' };
int dx[] = { 1, -1, 0, 0, -1, -1, 1, 1, 0 };
int dy[] = { 0, 0, 1, -1, -1, 1, -1, 1, 0 };


const int N = 1e5 + 230;
const lli mod = 998244353;
const ld pi = acos(-1);
const int T = 238;
const ld e = 1e-13;

lli bp(lli a, lli b = mod - 2LL)
{
    lli ret = 1;
    while (b)
    {
        if (b & 1) ret *= a, ret %= mod;
        a *= a;
        a %= mod;
        b >>= 1;
    }
    return ret;
}
ostream& operator<<(ostream& c, pir a)
{
    c << a.fr << " " << a.sc;
    return c;
}
struct pt
{
    lli x, y;
    int ind;
    int bl;
    bool operator==(const pt& a)
    {
        return ind == a.ind;
    }
    bool operator<(const pt& b)
    {
        if (x == b.x) return y < b.y;
        return x < b.x;
    }
};


lli k, d, x;
int main()
{
    fastio;
    cin >> x >> k >> d;
    x = abs(x);
    if (k < x / d) cout << abs(x - k * d) << endl;
    else
    {
        k -= x / d;
        x %= d;
        if (k & 1) cout << abs(x - d) << endl;
        else cout << x << endl;
    }
    return 0;
}

/*

  __
*(><)*
  \/ /
  ||/
--||
  ||
  /\
 /  \
/    \
*/

Measured memory_bytes: 3696
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;

int n;
int a[100005],b[100005];
ll cnt[100005];
ll fac[345678],rfac[345678];

ll mod_pow(ll x,ll y){
    ll a=1LL;
    while(y){
        if(y%2) a=1LL*a*x%MOD;
        x=x*x%MOD;
        y/=2;
    }
    return a;
}
 
ll mod_reverse(ll x,ll mod){
    return mod_pow(x,mod-2LL);
}

ll comb(int n,int r){
    if(n<r) return 0LL;
    return 1LL*fac[n]*rfac[n-r]%MOD*rfac[r]%MOD;
}

int main(){

cin>>n; 

for(int i=0; i<=n; i++){
    scanf("%lld",&a[i]); 
    cnt[a[i]]++; b[a[i]]=i;
}
int s,t;
for(int i=0; i<=n; i++){
    if(cnt[a[i]]==2){
        s=i; break;
    }
}
for(int i=1; i<=n; i++){
    if(cnt[i]==2) t=b[i];
}
int p=n-t+s; 

fac[0]=1LL; rfac[0]=1LL;
for(int i=0; i<300000; i++){
    fac[i+1]=(fac[i]*(i+1LL))%MOD;
    rfac[i+1]=mod_reverse(fac[i+1],MOD);
}

for(int i=1; i<=n+1; i++){
    ll ans=comb(n+1,i)-comb(p,i-1);
    if(ans<0) ans+=MOD;
    //cout<<comb(n+1,i)<<" "<<comb(p,i-1)<<endl;
    cout<<ans<<endl;
}

}

Measured memory_bytes: 8192
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

# 2点の直径または3点の外心をテスト

import itertools
import numpy as np

N = int(readline())
m = map(int,read().split())
Z = [x + y * 1j for x,y in zip(m,m)]

def find_O(z0,z1,z2):
    z1 -= z0; z2 -= z0
    if abs((z1 * z2.conjugate()).imag) < 0.5:
        # 同一直線上
        return None
    num = z1 * z2 * (z1-z2).conjugate()
    den = z1.conjugate() * z2
    den -= den.conjugate()
    return (num / den) + z0

A = []
for comb in itertools.combinations(Z,3):
    O = find_O(*comb)
    if O is None:
        continue
    A.append(O)
    
for z1,z2 in itertools.combinations(Z,2):
    O = (z1 + z2) / 2
    A.append(O)

Z = np.array(Z); A = np.array(A)

answer = np.abs((Z[:,None] - A[None,:])).max(axis = 0).min()
print(answer)

Measured memory_bytes: 37612
def isPrime(x):
    if x == 2:
        return True

    if (x < 2 or x%2 == 0):
        return False

    i = 3
    while i <= x**0.5:
        if x%i == 0:
            return False
        i = i + 2

    return True

n = int(input())
count = 0
for i in range(n):
    x = int(input())
    if isPrime(x) == True:
        count += 1
print(count)



Measured memory_bytes: 5668
#include <bits/stdc++.h>
#define ALL(a)  (a).begin(),(a).end()
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
template <typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template <typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
const int INT_INF = 1 << 30;
const double PI = acos(-1.0);
#define MOD 1000000007LL
#define endl "\n"

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll N;
  cin >> N;
  vll D(N+1);
  D.at(0) = 0;
  for(int i = 1; i <= N; i++){
    cin >> D.at(i);
  }
  sort(ALL(D));

  if(D.at(1) == 0){
    cout << 0 << endl;
    return 0;
  }

  ll ok = 0, ng = 24;
  
  ll ans = 0;
  while(ng - ok > 1){
    ll mid = (ok + ng) / 2;
    ll mini = 0, maxi = 24;
    vll A(N+1);
    A.at(0) = 0;
    bool flag = true;
    for(int i = 1; i <= N; i++){
      ll x = D.at(i), y = 24 - D.at(i);
      if(x - mini >= mid && maxi - y >= mid){
        if(x - mini > maxi - y){
          A.at(i) = y;
          maxi = y;
        }
        else{
          A.at(i) = x;
          mini = x;
        }
      }
      else if(x - mini >= mid){
        A.at(i) = x;
        mini = x;
      }
      else if(maxi - y >= mid){
        A.at(i) = y;
        maxi = y;
      }
      else{
        flag = false;
        break;
      }
    }
    if(flag){
      ok = mid;
      ll res = INF;
      sort(ALL(A));
      for(int i = 1; i <= N; i++){
        chmin(res, A.at(i) - A.at(i-1));
      }
      chmax(ans, res);
    }
    else ng = mid;
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (ll i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using ull = long long unsigned;
using P = pair<int,int>;
const int INF=1001001001;
const int NMAX=8;
const int MOD=1000000007;
const int dbase=80*160;

int cnt(int x){
	int ans=0;
	for (int i=1;i<=x;i++){
		if (x%i==0) ans++;
	}
	return ans;
}

int main(){
	int n;
	cin>>n;
	int ans=0;
//	cout<<cnt(105)<<endl;
	rep(i,n+1){
		if (i%2==0) continue;
		int now=cnt(i);
		if (now==8) {
			ans++;
		   //cout<<i<<'i'<<endl;
		 }
	}
	cout<<ans;

}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC068AABCxxx
{
    class Program
    {
        static void Main(string[] args)
        {
            string input = Console.ReadLine();

            string header = "ABC";

            Console.WriteLine(header + input);

        }
    }
}


Measured memory_bytes: 13140
package main

import "fmt"

func main() {
	// Code for B - Counting Roads
	var N, M int
	fmt.Scanf("%d %d", &N, &M)
	var a, b int
	city := make(map[int]int, N)
	for i := 0; i < M; i++ {
		fmt.Scanf("%d %d", &a, &b)
		city[a]++
		city[b]++
	}

	for i := 1; i <= N; i++ {
		fmt.Println(city[i])
	}
}


Measured memory_bytes: 1836
n = int(input())
count = 0
base = [[0],[],[],[],[],[],[],[],[],[],[]]
for digit in range(10):
  for i in base[digit]:
    num_3 = i+3*10**digit
    num_5 = i+5*10**digit
    num_7 = i+7*10**digit
    next_digit = digit + 1
    if num_3 <= n:
      if set(str(num_3)) == {'3','5','7'}:
        count += 1
      base[next_digit].append(num_3)
    if num_5 <= n:
      if set(str(num_5)) == {'3','5','7'}:
        count += 1
      base[next_digit].append(num_5)
    if num_7 <= n:
      if set(str(num_7)) == {'3','5','7'}:
        count += 1
      base[next_digit].append(num_7)
print(count)

Measured memory_bytes: 4304
/**
 * File              : c.cpp
 * Author            : recurze
 * Date              : 23:13 18.01.2019
 * Last Modified Date: 23:22 18.01.2019
 */

#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

void readInput();
void solve();
void printAns();

int main() {
    int t = 1;
    //scanf("%d", &t);

    for (int tc = 1; tc <= t; ++tc) {
        readInput();
        solve();
        printAns();
    }
}

const int N = 1010101;

int n = 0, m = 0;
std::vector< std::pair< std::pair<int, int>, int> > v;
void readInput() {
    scanf("%d%d", &n, &m);

    int p, y;
    for (int i = 0; i < m; ++i) {
        scanf("%d%d", &p, &y);
        v.push_back({{p, y}, i});
    }
}

std::string makeID(int x, int p) {
    fprintf(stderr, "%d %d\n", x, p);
    std::string s;
    for (int i = 0; i < 6; ++i) {
        if (x) s += std::to_string(x%10);
        else s += '0';
        x /= 10;
    }
    std::string s1;
    for (int i = 0; i < 6; ++i) {
        if (p) s1 += std::to_string(p%10);
        else s1 += '0';
        p /= 10;
    }
    std::reverse(s.begin(), s.end());
    std::reverse(s1.begin(), s1.end());
    return s1 + s;
}

std::string ans[N];
void solve() {
    std::sort(v.begin(), v.end(),
            [] (const auto& i, const auto& j) {
            if (i.first.first == j.first.first) {
                return i.first.second < j.first.second;
            }
            return i.first.first < j.first.first;
            });

    int j = 1, last = 0;
    for (auto& i: v) {
        if (last != i.first.first) {
            j = 1;
        }
        fprintf(stderr, "s%d\n", i.second);
        ans[i.second] = makeID(j++, i.first.first);
        last = i.first.first;
    }
}

void printAns() {
    for (int i = 0; i < m; ++i) {
        std::cout<<ans[i]<<"\n";
    }
}


Measured memory_bytes: 15220
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <cstring>
#include <string>
#include <set>
using namespace std;
#define maxn 100000+5
typedef long long int ll;
const double INF = 1e20;
const double pi = acos (-1.0);
int vis[5];
int main () {
    for(int i=0;i<3;i++){
        int a,b;
        scanf("%d%d",&a,&b);
        vis[a]++,vis[b]++;
    }
    int coun=0;
    for(int i=1;i<=4;i++){
        if(vis[i]%2==1)coun++;
        if(vis[i]==0){
            printf("NO\n");
            return 0;
        }
    }
    //cout<<coun<<endl;
    if(coun!=2&&coun!=0){
        printf("NO\n");
        return 0;
    }
    printf("YES\n");
   // while(1)getchar();
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N = 1e5+5;
long long dp[105][N];
int main(){
    long long n,W;
    scanf("%lld %lld",&n,&W);
    for(int i=1;i<=n;i++){
        long long v,w;
        scanf("%lld %lld",&w,&v);
        for(int j=0;j<w;j++)    dp[i][j] = dp[i-1][j];
        for(int j=w;j<=W;j++)   dp[i][j] = max(dp[i-1][j],v+dp[i-1][j-w]);
    }
    printf("%lld\n",dp[n][W]);
    return 0;
}


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

int main() {
    vector<string> a = {"#","."};
    int h, w, n;
    while (true){
        cin >> h >> w;
        if(h==0)break;
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                n = (i+j)%2;
                cout << a[n];
            }
            cout << endl;
        }
        cout << endl;
    }
    
    
   
    return 0;
}



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

using namespace std;
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))
#define endl "\n"
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {os << "["; for (const auto &v : vec) {os << v << ","; } os << "]"; return os;}
template <typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &p) {os << "(" << p.first << ", " << p.second << ")"; return os;}

void solve() {
    string s;
    cin >> s;
    sort(all(s));
    if (s[0] == s[1] && s[1] != s[2] && s[2] == s[3]) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

int main() {
    #ifdef LOCAL_ENV
    cin.exceptions(ios::failbit);
    #endif
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    
    solve();
}

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

#define ll long long
#define ar array
#define vi vector<int>
#define vvi vector<vector<int>>
#define vll vector<long long>
#define forn(i,n) for(ll i=0; i<(n); i++)
#define fori(i,k,n) for(ll i=k; i<(n); i++) 
#define all(x) (x).begin(),(x).end()
#define en '\n'
#define FILL(x,v) memset(x,v,sizeof(x))
#define pb push_back

const ll MOD = 1e9+7;

void solve(){
	ll n, k;
	cin >> n >> k;
	ll pw = n*(n+1)/2;
	ll ans = 0;
	for(ll i = k; i<n+1; i++){
		ll mn = (i-1)*i/2;
		ll mx = pw - (n-i)*(n-i+1)/2;
		ans += mx - mn + 1;
		ans %= MOD;
	}
	ans += 1;
	ans %= MOD;
	cout << ans << en;
}

int main(){
    ios::sync_with_stdio(0);
	cin.tie(0);
    cout.tie(0);
 
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
    int t = 1;
	// cin >> t;
    while(t--)
        solve();
    return 0;
}

Measured memory_bytes: 3656
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <queue>
#include <stack>
#include <list>
#include <functional>
#include <numeric>
#include <iostream>

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

char S[12];

int main() {

	scanf("%s", S);

	int l = strlen(S);

	if (S[0] == 'A') {
		int c = 0;
		rep(i, l) {
			if (S[i] == 'C') c++;
		}
		if (c == 1) {
			if (S[l - 1] == 'C' || S[1] == 'C') {
				printf("WA\n");
				return 0;
			}
			rep(i, l) {
				if (S[i] == 'B' || (S[i] > 'C' && S[i] <= 'Z')) {
					printf("WA\n");
					return 0;
				}
			}

			printf("AC\n");
			return 0;
		}
	}

	printf("WA\n");
	return 0;
}

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

int main(void) {
  ll N;
  cin >> N;

  ll ans = 1LL << 60;
  REP(A, 1, N) {
    ll B = N - A;

    ll a = A, b = B;
    ll sa = 0, sb = 0;
    while(a > 0) {
      sa += a % 10;
      a /= 10;
    }
    while(b > 0) {
      sb += b % 10;
      b /= 10;
    }
    ans = min(ans, sa + sb);
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
from operator import itemgetter
from collections import deque

n, m = map(int, input().split())

bridge = [0 for i in range(n-1)]

query = [list(map(int, input().split())) for i in range(m)]
query = sorted(query, key = itemgetter(1))

cut_cnt = 1
cut_bridge = deque()
cut_bridge.append(query[0][1] - 2)

for i in range(1, m):
    a, b = query[i]
    if a - 1 > cut_bridge[-1]:
        cut_bridge.append(b - 2)
        cut_cnt += 1


print(cut_cnt)



Measured memory_bytes: 30964
Module Program

    Sub Main(args As String())

        Dim arrStr As String() = Split(Console.ReadLine())
        Dim Taka_HP As Integer = CInt(arrStr(0))
        Dim Taka_AP As Integer = CInt(arrStr(1))
        Dim Ao_HP As Integer = CInt(arrStr(2))
        Dim Ao_AP As Integer = CInt(arrStr(3))

        Dim taka_turn As Boolean = True
        While Taka_HP > 0I And Ao_HP > 0I
            If taka_turn = True Then
                Ao_HP = Ao_HP - Taka_AP
                taka_turn = False
            Else
                Taka_HP = Taka_HP - Ao_AP
                taka_turn = True
            End If
        End While

        If Taka_HP <= 0I Then
            Console.WriteLine("No")
        Else
            Console.WriteLine("Yes")
        End If

    End Sub

End Module

Measured memory_bytes: 28384
#include<cstdio>
//2k+1回の移動でゴールにたどり着くとする（0<=k, 2k+1<=N-1）。
//A,Bを決めたとき、0,A,A-B,2A-B,...,(k+1)A-kBに対してs_yの和を求める
//A-B=Cとおくと、A+kC=N-1なので、0,C,...,kC,N-1,N-1-C,...,N-1-kCの和を求める
//dp[k][C]をこの和とすると、累積和をとって1個あたりO(1)で求められる
//// dp[0][C]=0, dp[k][C]=dp[k-1][C]+s_{kC}+s_{N-1-kC}
using ll = long long;
ll s[100000];
int main(){
    int n;
    scanf("%d",&n);
    for(int i=0;i<n;i++)scanf("%lld",&s[i]);
    //k=0のとき得点はs_0+s_{N-1}=0
    ll max_score=0;
    for(int c=1;c<n;c++){
        ll dp=0;
        for(int k=1;k*c<n;k++){
            //同じ場所を踏んでいないかチェック
            //N-1がCの倍数なら、kC<N-1-kCならOK
            //N-1がCの倍数でないなら、C<N-1-kC(=A)ならOK
            if((n-1)%c==0 && 2*k*c>=n-1 || (n-1)%c!=0 && c*(k+1)>=n-1)break;
            dp+=s[k*c]+s[n-1-k*c];
            if(dp>max_score)max_score=dp;
        }
    }
    printf("%lld\n",max_score);
    return 0;
}

Measured memory_bytes: 896
<?php
$n = fgets(STDIN);
$arr = str_split($n);
$arr0 = $arr[0];
$arr1 = $arr[1];
$arr2 = $arr[2];

if($arr0 == 7){
  echo 'Yes';
  }
  elseif($arr1 == 7){
  echo 'Yes';
  }
  elseif($arr2 == 7){
  echo 'Yes';
  }
  else{
  echo 'No';
  }

?>

Measured memory_bytes: 16124
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
template<class T> inline bool chmin (T& a, T b) {if (a > b) {a = b; return true;} return false;}

long long INF = 1LL << 60;
long long dp[110000];
int p[] = {6,9};
int N;

int main() {
	cin >> N;
	
	rep(i, 110000) dp[i] = INF;
	dp[0] = 0;

	int d;
	rep(i, N+1) {
		if (i != 0) chmin(dp[i], dp[i-1]+1);
		rep(j, 2) {
			d = p[j];
			while (i - d >= 0) {
				chmin(dp[i], dp[i-d]+1);
				d *= p[j];
			}
		}
		// cout << i << ": " << dp[i] << endl;
	}
	cout << dp[N] << endl;
}

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

int main() {
  	int K, S;
  	cin >> K >> S;
  	int count = 0;;
  	for (int x = 0; x <= K; x++){
      	for (int y = 0; y <= K; y++){
          	int z = S - (x + y);
			if ((z >= 0) && (z <= K)) count++;
        }
    }
  	cout << count << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <iostream>
#include <string>
#include <utility>
#include<vector>
#include<iomanip>
#include<map>
#include <queue>
#include<cmath>
#include<cstdio>
#include<iomanip>
#include<set>
#include <bits/stdc++.h>
 
using namespace std;
using ll = long long int;
 
#define REP(i,n) for(ll i=0;i<(ll)(n);i++) //REP(i, 5) cout<<i;
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define MOD 1000000007 //10^9+7
//#define MOD 1
 
ll gcd(ll a, ll b) {
  ll tmp;
  if ( b > a) {
    tmp = a;
    a = b;
    b = tmp;
  }
  while (a % b !=0) {
    tmp = b;
    b = a % b;
    a = tmp;
  }
  return b;
}
 
const int MAX = 2000;

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

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}


void sosuu(ll n, vector<ll> &v){

  vector<ll> num(n, 0);

  FOR(i, 1, sqrt(n)){
    if(num[i]==0){
      FOR(j, 0, n/i){
        num[i+(j*i)] = 1;
      }
    }
  }
  REP(i, n){
    if(num[i]==0) v.push_back(i+1);
  }
}

ll GetDigit(ll num){
    ll digit=0;
    while(num!=0){
        num /= 10;
        digit++;
    }
    return digit;
}


int main(void){
 
  ll x;
  cin>>x;

  ll ans = x/11;
 
  //cout<<x/11<<" "<<x%11<<endl;
  if(x%11==0) cout<<2*ans<<endl;
  else if((x%11) <= 6)cout<<2*ans + 1<<endl;
  else cout<<2*ans+2<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <cmath>
#include <cstdlib>
#include <cstdio>
#include <climits>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstring>
#include <string>
#include <algorithm>
#include <vector>
#include <list>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <bitset>
using namespace std;

int main() {
    string s;
    cin>>s;
    s[5]=' ';
    s[13]=' ';
    cout<<s<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <vector>
#include <iostream>
#include <set>
#include <cstdio>
#include <queue>
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <ctime>
#include <algorithm>
#include <tuple>
#include <algorithm>
#include <limits>
#include <map>

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
const ll INF = 1LL<<50;
ll dp[2][10010][2] = {};
int t[10010];
int main() {
    int n;
    int f = 0;
    cin >> n;
    t[0] = 0;
    for (int i = 1; i < n; i++) {
        cin >> t[i];
    }
    dp[0][0][1] = INF;
    for (int i = 1; i < n; i++) {
        dp[0][i][0] = dp[0][i][1] = INF;
    }
    for (int i = 0; i < n; i++) {
        f = 1-f;
        dp[f][0][0] = INF;
        for (int j = 1; j < n; j++) {
            dp[f][j][0] = min(dp[1-f][j-1][0], dp[1-f][j-1][1]+t[i]);
        }
        for (int j = 0; j < n; j++) {
            dp[f][j][1] = min(dp[1-f][j][0]+t[i], dp[1-f][j][1]);
        }
    }
    printf("%lld\n", min(dp[f][n/2][0], dp[f][n/2][1]));
    return 0;
}

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

int main() {
  int first[3][10];
  int second[3][10];
  int thired[3][10];
  int force[3][10];
  for(int tk = 0; tk < 3; ++tk) {
    for(int num = 0;num < 10; ++num) {
      first[tk][num] = 0;
      second[tk][num] = 0;
      thired[tk][num] = 0;
      force[tk][num] = 0;
    }
  }
  int n;
  std::cin >> n;
  //??\???
  for(int a = 0; a < n; ++a) {
    int b,f,r,v;
    std::cin >> b >> f >> r >> v;
    switch(b) {
      case 1:
      first[f-1][r-1] = first[f-1][r-1] +v;
      break;
      case 2:
      second[f-1][r-1] = second[f-1][r-1] +v;
      break;
      case 3:
      thired[f-1][r-1] = thired[f-1][r-1] +v;
      break;
      case 4:
      force[f-1][r-1] = force[f-1][r-1] +v;
      break;
    }
  }
  //??????
  int kai = 0;
  for(int c = 0; c < 10; ++c) {
    std::cout<< " " << first[kai][c];
    if(c == 9) {
      if(kai == 2) {
        std::cout<< std::endl << "####################" << std::endl;
        break;
      }else if(kai != 2) {
        std::cout<< std::endl;
        c = -1;
        ++kai;
      }
    }
  }
  int kai2 = 0;
  for(int d = 0; d < 10; ++d) {
    std::cout<< " " << second[kai2][d];
    if(d == 9) {
      if(kai2 == 2) {
        std::cout<< std::endl << "####################" << std::endl;
        break;
      }else if(kai2 != 2) {
        std::cout<< std::endl;
        d = -1;
        ++kai2;
      }
    }
  }
  int kai3 = 0;
  for(int e = 0; e < 10; ++e) {
    std::cout<< " " << thired[kai3][e];
    if(e == 9) {
      if(kai3 == 2) {
        std::cout<< std::endl << "####################" << std::endl;
        break;
      }else if(kai3 != 2) {
        std::cout<< std::endl;
        e = -1;
        ++kai3;
      }
    }
  }
  int kai4 = 0;
  for(int f = 0; f < 10; ++f) {
    std::cout<< " " << force[kai4][f];
    if(f == 9) {
      if(kai4 == 2) {
        std::cout<< std::endl;
        break;
      }else if(kai4 != 2) {
        std::cout<< std::endl;
        f = -1;
        ++kai4;
      }
    }
  }
}

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

int main(){
    int n, y;
    cin >> n >> y;
    bool exit_flag = false;
    for(int i=0; i<=n; i++){
        for(int j=0; j<=n-i; j++){
            int k=n-i-j;
            if(i*10000 + j*5000 + k*1000 == y){
                cout << i << " " << j << " " << k << endl;
                exit_flag = true;
                break;
            }
        }
        if(exit_flag) break;
    }
    if(!exit_flag) cout << -1 << " " << -1 << " " << -1 << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second

const int mx=100010;
const ll mod=1e9+7;

struct UnionFind {  
  vector<int> par,sizes;                     // par[i]:iの親の番号(ex)par[3]=2 : 3の親が2
  UnionFind(int n) : par(n),sizes(n,1)  {    //最初は全てが根であるとして初期化
    for(int i=0; i<n; i++){ par[i]=i; }  
  }
  int root(int x) {                       //xが属する木の根を再帰で得る:root(x)={xの木の根}
    if(par[x]==x){ return x; }
    return par[x] = root(par[x]);
  }
  void unite(int x, int y) {                 // xとyの木を併合
    int rx = root(x);                        //xの根をrx
    int ry = root(y);                        //yの根をry
    if(rx == ry){ return; }                  //xとyの根が同じ(=同じ木にある)時はそのまま
    if(sizes[rx]<sizes[ry]){ swap(rx, ry); } //xの木をおおきくする
    par[ry] = rx; 
    sizes[rx] += sizes[ry];                  //sizes[ry]はもう使わない
  }
 
  bool check(int x, int y) {                 // x,yが属する木が同じならtrueを返す
    return root(x) == root(y);
  }
  
  int size(int x){                           //xが含まれる木の大きさを返す
    return sizes[root(x)];
  }
};

int main(){
  int n,m;
  cin >> n >> m;
  UnionFind com(mx+m+10);
  
  rep(i,n){
    int k; cin >> k;
    rep(j,k){
      int l; cin>>l; l+=mx;
      if(com.check(i,l)){continue;}
      com.unite(i,l);
    }
  }

  int ne=com.root(0);
  rep(i,n){
    int tmp=com.root(i);
    if(ne!=tmp){cout<<"NO"<<endl; return 0;}
  }
  cout << "YES" << endl;
  return 0;
}


Measured memory_bytes: 1792
n, y = [int(i) for i in input().split()]

min_1sen = (y%5000)//1000
n = n - min_1sen
y = y - 1000*min_1sen
max_1sen = min(n, y//1000)
max_5sen = min(n, y//5000)
max_1man = min(n, y//10000)

ans = [-1, -1, -1]

for i in range(max_1man+1):
    for j in range(n-i+1):
        if y == 10000*i+5000*j+1000*(n-i-j):
            ans = [i, j, n-i-j+min_1sen]

print(*ans)



Measured memory_bytes: 3064
#include<iostream>
#include<vector>
#include<cmath>
#include<string>
#include<algorithm>
#include<map>
#include<utility>
#include<cstdio>
#include<bits/stdc++.h>

using namespace std;
using ll = long long;
const long long INF = 1LL<<60;

typedef pair<ll,ll> Pair;
int main(){


ll N;

cin >> N;

ll D[100][2];
ll count = 0;

for (ll i = 0; i < N;++i){

    cin >> D[i][0] >> D[i][1];
    
}

bool flg = false;

for (ll i = 0; i < N-2;++i){

    if((D[i][0] == D[i][1]) && (D[i+1][0] == D[i+1][1]) && (D[i+2][0] == D[i+2][1]))
        flg = true;
}

if(flg)
    cout << "Yes" << endl;
else
    cout << "No" << endl;

return 0;

}


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

int main() {
  ll a, b, c, x, y;
  cin >> a >> b >> c >> x >> y;
  ll ans = 0;
  rep(i, 100000) {
    if (i >= x && i >= y) break;
    if (i >= x) {
      ans += min(c * 2, b);
    } else if (i >= y) {
      ans += min(c * 2, a);
    } else {
      ans += min(c * 2, a + b);
    }
  }
  cout << ans << endl;
  return 0;
}

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

//var 
long long dp[101][100001],ans=0; 
long long v[101], w[101], W,N;

int main(){
	cin >> N >> W;
	for(int i = 1; i<=N; i++)cin >> w[i] >> v[i];
	for(int i = 1; i<=N; i++){
		for(int j = 0; j<=W; j++){
			dp[i][j] = dp[i-1][j];
			if(j-w[i]<0)continue;
			dp[i][j] = max(dp[i][j],dp[i-1][j-w[i]]+v[i]);
			//cout << i << " " << j << " " << dp[i][j] << endl;
		}
	}
	cout << dp[N][W] << endl;
}

Measured memory_bytes: 78336
/*
#include <boost/multiprecision/cpp_int.hpp>
namespace mp = boost::multiprecision;
typedef mp::cpp_int mint; //*/
#include <bits/stdc++.h>
#define  re(i,j,n) for(li i=(j);i<(n);i++)
#define  rep(i,n) re(i,0,(n))
#define  red(i,n) for(li i=n-1;i>=0;i--)
#define  all(a) begin(a),end(a)
#define  pb(a) push_back(a)
using namespace std;
typedef long int li;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<li> vli;
typedef vector<string> vs;


int main()
{
    int ans;
    string s;
    cin>>s;
    ans=s.size();
    rep(i,s.size()) {
        if(s[i]=='A') break;
        ans--;
    }
    red(i,s.size()) {
        if(s[i]=='Z') break;
        ans--;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 640
#include <stdio.h>

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

    int i;
    for(i = 0; i < 3; ++i){
        if(n % 10 == 7){
            printf("Yes");
            return 0;
        }else{
            n = n/10;
        }
    }
    printf("No");
    return 0;
}


Measured memory_bytes: 1660
S=input()

for i in range(100000):
  if S[-7:]=="dreamer":
    S=S[:-7]
  elif S[-6:]=="eraser":
    S=S[:-6]
  elif S[-5:]=="dream" or S[-5:]=="erase":
    S=S[:-5]
  else:
    pass
  if S=="":
    print("YES")
    break
else:
  print("NO")

Measured memory_bytes: 3244
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <tuple>

using ll = unsigned long long;
using namespace std;

int main(void)
{
    ll a;
    float b;

    cin >> a >> b;

    ll b_int = (ll)(b * 100 + 0.001);
    cout << ((a * b_int) / 100) << endl;

    return 0;
}


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

int main(){
  string n;
  cin >> n;
  int ans = 0;
  for(auto x : n) ans += (x - '0');
  if(ans%9 == 0) cout << "Yes" << endl;
  else           cout << "No"  << endl;
  return 0;
}

Measured memory_bytes: 3696
#include<iostream>
using namespace std;
int p,i,j,a,b,d;string s,u="[<++++++++++>-]>",c=">+++++[<++++++>-]>+++++[<++++++++>-]>+++++"+u+"++++++"+u+"+++++++"+u+"++++++++"+u+"+++++++++"+u+"++++++++++"+u+"+++++++++++"+u+"++++++++++++"+u+"<<<<<<<<<<<";main(){for(cin>>s;i<s.length();++i){a=s[i]/10-3,b=a-p,p=a,d=s[i]-a*10-30;for(j=b>0?b:-b;j--;)c+=b>0?62:60;for(j=d;j--;)c+=43;c+=46;for(j=d;j--;)c+=45;}cout<<c<<endl;}

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

struct Node{
    int left;
    int right;
};

class Tree{
    vector<Node> node;
public:
    Tree(int n){
        node.resize(n);
    }
    int make_tree(vector<int>& pre, vector<int>& in){
        if (pre.empty()) return -1;
        int obj = pre[0];
        vector<int> in_left;
        vector<int> in_right;
        vector<int>::iterator it = in.begin();
        while (*it != obj) {
            in_left.push_back(*it);
            it++;
        }
        it++;
        while (it < in.end()) {
            in_right.push_back(*it);
            it++;
        }
        vector<int> pre_left;
        vector<int> pre_right;
        it = pre.begin() + 1;
        for (int i = 0; i < in_left.size(); i++) {
            pre_left.push_back(*it);
            it++;
        }
        while (it < pre.end()) {
            pre_right.push_back(*it);
            it++;
        }
        node[obj].left  = make_tree(pre_left , in_left );
        node[obj].right = make_tree(pre_right, in_right);
        return obj;
    }
    void post_order(int p, vector<int>& post){
        if (p == -1) return;
        post_order(node[p].left , post);
        post_order(node[p].right, post);
        post.push_back(p);
    }
};

int main(){
    int n;
    cin >> n;
    vector<int> pre(n);
    vector<int> in(n);
    for (int i = 0; i < n; i++) {
        cin >> pre[i];
    }
    for (int i = 0; i < n; i++) {
        cin >> in[i];
    }
    Tree T(n + 1);
    T.make_tree(pre, in);
    vector<int> post;
    T.post_order(pre[0], post);
    for (int i = 0; i < post.size(); i++) {
        cout << post[i] << (i == post.size() - 1 ? '\n' : ' ');
    }
    return 0;
}

Measured memory_bytes: 3164
n = int(input())
InputNum = input().split()
a = []
for x in range(n):
    a.append(int(InputNum[x]))
a.sort()
min = a[0]
a.reverse()
max = a[0]
sum = 0
for y in range(n):
    sum += int(a[y])

print(min,max,sum)

Measured memory_bytes: 8640
N, M = map(int, input().split())
a=set()
b=set()
for i in range(M):
    k,l=map(int, input().split())
    if k==1:
        a.add(l)
    if l==N:
        b.add(k)
if a&b:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")


Measured memory_bytes: 19024
/*
ID: anonymo14
TASK: wormhole
LANG: C++                 
*/
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pair<int,int>> vpii;

#define F first
#define S second
#define PU push
#define PUF push_front
#define PUB push_back
#define PO pop
#define POF pop_front
#define POB pop_back

#define REP(i,a,b) for(int i=a; i<=b; i++)

#define MOD 1000000007

void solve(int test_case) {
	int a,b;
	cin>>a>>b;
	if(a==b){
		cout<<0;
		return;
	}
	if(a==-b) {
		cout<<1;
		return;
	}
	if(a==0) {
		if(b<0)cout<<abs(b)+1;
		else cout<<b;
		return;
	}
	if(b==0) {
		if(a>0)cout<<a+1;
		else cout<<abs(a);
		return;
	}
	if(a<0&&b<0) {
		if(b<a){cout<<abs(b)-abs(a)+2;}
		else if(b>a){cout<<abs(a)-abs(b);}
	} else if(a>0&&b<0) {
		cout<<abs(a-abs(b))+1;
	} else if(a<0&&b>0) {
		cout<<abs(abs(a)-b)+1;
	} else {
		if(b>a)cout<<b-a;
		else cout<<a-b+2;
	}
			
}

int main() {
	
	////// FILE BASED IO////
	//freopen("wormhole.in", "r", stdin);
	//freopen("wormhole.out", "w", stdout);
	///////////////
	
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t=1;
	//cin>>t;
	REP(i,1,t) {
		solve(i);
	}
	return 0;
}	


Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
void solve()
{
	
}
int main()
{
	long long n,m,sum=0;
	cin>>n>>m;
	long long x;
	for(int i = 0;i<m;i++)
	{
		cin>>x;
		sum+=x;
	}
	if(sum>n)
		cout<<"-1\n";
	else
		cout<<n-sum<<'\n';
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
using namespace std; 
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)
inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }
const int INF = 1<<29;
typedef long long int ll;
inline int two(int n) { return 1 << n; }
inline int test(int n, int b) { return (n>>b)&1; }
inline void set_bit(int & n, int b) { n |= two(b); }
inline void unset_bit(int & n, int b) { n &= ~two(b); }
inline int last_bit(int n) { return n & (-n); }
inline int ones(int n) { int res = 0; while(n && ++res) n-=n&(-n); return res; }
template<class T> void chmax(T & a, const T & b) { a = max(a, b); }
template<class T> void chmin(T & a, const T & b) { a = min(a, b); }
const int MOD=1000000007;

bool isPowerOfTwo (ll x)  
{  
    return x && (!(x&(x-1)));  
}
bool isPrime(int n) 
{ 
    if (n <= 1)  return false; 
    if (n <= 3)  return true; 
    if (n%2 == 0 || n%3 == 0) return false; 
  
    for (int i=5; i*i<=n; i=i+6) 
        if (n%i == 0 || n%(i+2) == 0) 
           return false; 
  
    return true; 
}
int highestPowerof2(unsigned int n) 
{ 
    // Invalid input 
    if (n < 1) 
        return 0; 
  
    int res = 1;
    for (int i=0; i<8*sizeof(unsigned int); i++) 
    { 
        int curr = 1 << i; 
        if (curr > n) 
           break; 
  
        res = curr; 
    } 
  
    return res; 
} 
long long binpow(long long a, long long b) {
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}       
////////////////////////////////////////////////////////////////////

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);  
  cout.tie(NULL);
  int t=1;
  while(t--)
  {
    string s;
    cin>>s;
    ll q;
    cin>>q;
    deque<char> deq;
    bool flag=false;
    for(auto i:s)
    deq.push_back(i);
    while(q--)
    {
        int x;
        cin>>x;
        if(x==1)flag=!flag;
        else
        {
            int y;
            char c;
            cin>>y>>c;
            if(flag^(y==1))deq.push_front(c);
            else deq.push_back(c);
        }
    }
    string ans;
    for(auto i:deq)
    {
        ans.push_back(i);
    }
    if(flag)reverse(ans.begin(),ans.end());
    cout<<ans<<"\n";
  }  
  return 0;
}

Measured memory_bytes: 1368
#include <bits/stdc++.h>
using namespace std;
main(){
  int n;cin >> n;
  int t[100010],x[100010],y[100010];
  t[0]=x[0]=y[0]=0;
  for(int i=0;i<n;i++) cin >> t[i+1] >> x[i+1] >> y[i+1];
  string ans="Yes";
  for(int i=0;i<n;i++){
    int dt = t[i+1]-t[i];
    int dist = abs(x[i+1]-x[i])+abs(y[i+1]-y[i]);
    if(dt>=dist){
      if(dt%2!=dist%2) ans="No";
    } else {
      ans = "No";
    }
  }
  cout << ans <<endl;
  return 0;
}

Measured memory_bytes: 4720