akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<LL,LL> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const LL mod=1000000007;
const LL LINF=1LL<<60;
const int INF=1<<30;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};




int main(){
    int n;cin >> n;
    vector<string> s(n+1),t(n+1);
    string p;
    for (int i = 0; i < n+1; i++) {
        cin >> s[i];
        t[i] = s[i];
        if(i==n) p = s[i];
        for (int j = 0; j < s[i].size(); j++) {
            if(s[i][j] == '?'){
                s[i][j] = 'z';
                t[i][j] = 'a';
            }
        }
    }
    sort(ALL(s));
    sort(ALL(t));
    int l = 0, r = 0;
    for (int i = 0; i < n+1; i++) {
        if(s[i] == p){
            l = i;
            break;
        }
    }
    for (int i = n; i >= 0; i--) {
        if(t[i] == p){
            r = i;
            break;
        }
    }
    for (int i = l; i <= r; i++) {
        cout << i + 1 << (i==r?"\n":" ");
    }
    return 0;
}


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

int main() {
    ll N, X;
    cin >> N >> X;
    ll a = X, b = N-X;
    if (a < b) swap(a, b);
    ll ans = N;
    while (b) {
        ll k = a/b;
        ans += (2*k)*b;
        ll c = a%b;
        a = b, b = c;
    }
    ans -= a;
    cout << ans << endl;
    return 0;
}

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

using namespace std;

int main(){
    ios_base::sync_with_stdio (false);
    long long a,p,sum=0;
    cin>>a;
    p=a;
    while(a!=0){
        sum+=a%10;
        a/=10;
    }
    if(p%sum==0) cout<<"Yes";
    else cout<<"No";
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
using namespace std;
int main(void)
{
    bool flag=false;
    string s,t;
    int j;
    int end;
    cin >> s >> t;
    for(int i=0;i<s.length();i++)
    {
        j=s.length()-1;
        end=s[j];
        for (j=s.length()-1;j>0;--j)
        {
            s[j]=s[j-1];
        }
        s[0]=end;
        if(s==t)
        {
            cout << "Yes" << endl;
            flag=true;
            return 0;
        }
    }
    if(flag==false)
    {
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int N,K,R,S,P;
string T;
int win(char C){
  if (C=='r') return P;
  if (C=='s') return R;
  if (C=='p') return S;
  else return 0;
}

int main(){
  cin >> N >> K >> R >> S >> P;
  cin >> T;
  int T_len = T.length();
  for(int i=0;i<K;i++)T+="X";
  bool renzoku[K];
  for(int i=0;i<K;i++) renzoku[i]=1;
  long long int score=0;
  for(int i=T_len-1;i>=0;i--){
    if(T[i]==T[i+K]){
      if (renzoku[i%K]==1){
        renzoku[i%K] =0;
      }else {
        renzoku[i%K]=1;
        score += win(T[i]);
      }
    }else {
      score+=win(T[i]);
      renzoku[i%K]=1;
    }
  }
  cout << score;
}


Measured memory_bytes: 644
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
#define rep(i,n) for (ll i=0;i<(n);++i)
#define rep2(i,a,b) for (ll i=(a);i<(b);++i)
#define debug(x) cout << #x << '=' << x << endl
#define all(v) (v).begin(),(v).end()
const ll MOD=1e9+7;
//const ll MOD=998244353;
const ll INF=1e9;
const ll IINF=1e18;
const double EPS=1e-8;
const double pi=acos(-1);

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);
    int N; cin >> N;
    vector<ll> A(N),B(N);
    rep(i,N) cin >> A[i] >> B[i];
    vector<ll> C(2*N);
    rep(i,N) C[i]=A[i],C[i+N]=B[i];
    sort(all(C));
    vector<int> a(N),b(N);
    ll ans=0,border,ok=0,smaller=0;
    rep(i,N){
        a[i]=lower_bound(all(C),A[i])-C.begin();
        b[i]=lower_bound(all(C),B[i])-C.begin();
        if (a[i]==N-1||b[i]==N-1) border=i;
        if (a[i]<N&&b[i]<N) ok=1;
        ans+=C[i];
    }
    if (a[border]==N-1) smaller=1;
    int ca=0,cb=0;
    rep(i,N){
        if (a[i]<N&&!(b[i]<N)) ++ca;
        if (b[i]<N&&!(a[i]<N)) ++cb;
    }
    if (ca==N||cb==N) ok=1;
    if (!ok){
        if (a[border]+b[border]!=2*N-1) ans+=C[N]-C[N-1];
        else if (smaller&&ca==1) ans+=C[N]-C[N-1];
        else if (!smaller&&cb==1) ans+=C[N]-C[N-1];
        else ans+=min(C[N]-C[N-2],C[N+1]-C[N-1]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 4224
n, p = map(int, input().split())
num = int(p ** (1 / n))
for i in range(num + 1, 0, -1):
    p0 = p
    count = 0
    if i == 1:
        print(i)
        break
    for j in range(n):
        if p0 % i == 0:
            p0 //= i
            count += 1
        else:
            break
    else:
        print(i)
        break

Measured memory_bytes: 9372
#!/usr/bin/env python
import numpy as np
N, C = map(int, input().split())
x = [0]*N
v = [0]*N
for i in range(N):
    x[i], v[i] = map(int, input().split())

x = np.array(x)
v = np.array(v)

gain_f = np.cumsum(v)-x
for i in range(1, N):
    gain_f[i] = max(gain_f[i-1], gain_f[i])

gain_b = np.cumsum(v[::-1])-(C-x[::-1])
for i in range(1, N):
    gain_b[i] = max(gain_b[i-1], gain_b[i])
    
turn_f = np.cumsum(v)-x*2
for i in range(1, N):
    turn_f[i] = max(turn_f[i-1], turn_f[i])

turn_b = np.cumsum(v[::-1])-(C-x[::-1])*2
for i in range(1, N):
    turn_b[i] = max(turn_b[i-1], turn_b[i])

turn_f = np.concatenate(([0], turn_f))
turn_b = np.concatenate(([0], turn_b))

ans = 0
for i in range(N):
    ans = max([ans, gain_f[i]+turn_b[N-1-i], gain_b[i]+turn_f[N-1-i]])

print(ans)

Measured memory_bytes: 20680
#include<bits/stdc++.h>
using namespace std;
#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> p2;
#define sz(a) ll(a.size())
ll a[200005],b[200005];
ll f(ll l,ll r,vector<ll> &v){
	auto it=lower_bound(v.begin(),v.end(),l);
	auto ut=lower_bound(v.begin(),v.end(),r);
	return (ut-it);
}
void solve(){
	ll n,res=0;
	cin>>n;
	for(ll i=1;i<=n;i++)
		cin>>a[i];
	for(ll i=1;i<=n;i++)
		cin>>b[i];
	for(ll bit=0;bit<30;bit++){
		ll val=pow(2,bit+1),cnt=0;
		vector<ll> v;
		for(ll i=1;i<=n;i++)
			v.push_back(b[i]%val);
		sort(v.begin(),v.end());
		val/=2;
		for(ll i=1;i<=n;i++){
			ll x=a[i]%(2*val);
			cnt+=f(val-x,2*val-x,v)+f(3*val-x,4*val-x,v);
		}
		if(cnt&1)
			res+=val;
	}
	cout<<res;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r" , stdin);
    freopen("output.txt", "w", stdout);
    #endif
    clock_t z=clock();
    ll qc=1;
    //cin>>qc;
    for(ll i=1;i<=qc;i++){
        solve();
    }
    debug("Total Time:%.4Lf\n",(ld)(clock()-z)/CLOCKS_PER_SEC);
}

Measured memory_bytes: 10500
import copy

s = list(input())
t = list(input())
if len(s) < len(t):
    print("UNRESTORABLE")
    exit()

ans_list = []
for i in range(len(s) - len(t) + 1):
    tmps = s[i:i + len(t)]
    ok = True
    for j in range(len(tmps)):
        if t[j] == tmps[j] or tmps[j] == '?':
            pass
        else:
            ok = False
            break
    if ok == True:
        cp_s = copy.deepcopy(s)
        for k in range(len(t)):
            cp_s[k+i] = t[k]
        ans_list.append(cp_s)

if len(ans_list) == 0:
    print("UNRESTORABLE")
else:
    # ?をaに書き換え
    for i in range(len(ans_list)):
        for j in range(len(s)):
            if ans_list[i][j] == '?':
                ans_list[i][j] = 'a'
    ans_list.sort()
    for c in ans_list[0]:
        print(c, end="")
    print()


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

#define REPU(i, a, b) for (int i = (a); i < (b); ++i)
#define REPD(i, a, b) for (int i = (a); i > (b); --i)
#define MEM(a, x) memset(a, x, sizeof(a))
#define ALL(a) a.begin(), a.end()
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end())
#define DEBUG(x) cerr << #x << " = " << x << endl

typedef long long ll;
const int MOD = 1000000007;

template<class T, class U> inline T tmin(T a, U b) { return (a < b) ? a : b; }
template<class T, class U> inline T tmax(T a, U b) { return (a > b) ? a : b; }
template<class T, class U> inline void amax(T &a, U b) { if (b > a) a = b; }
template<class T, class U> inline void amin(T &a, U b) { if (b < a) a = b; }
template<class T> inline T tabs(T a) { return (a > 0) ? a : -a; }
template<class T> T gcd(T a, T b) { while (b != 0) { T c = a; a = b; b = c % b; } return a; }

const int N = 10;
bool vis[N];
int ans = INT_MAX;

void dfs(int x, int n) {
	if (x >= n) {
		amin(ans, x); return;
	}
	REPU(i, 0, 10) if (!vis[i]) {
		if (x == 0 && i == 0) continue;
		dfs(x * 10 + i, n);
	}
}

int main(int argc, char *argv[]) {
	ios_base::sync_with_stdio(false);
	
	int n, k;

	MEM(vis, 0);
	cin >> n >> k;
	REPU(i, 0, k) {
		int d; cin >> d;
		vis[d] = 1;
	}

	dfs(0, n);
	cout << ans << endl;
	
	return 0;
}

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

int main() {
  int a,b,i,ans=0;
  cin>>a>>b;
  
  for(i=0;i<=b-a;i++){
    int c=a+i;
    if( c/10000==c%10 && (c/1000)%10==(c%100)/10 )
      ans++;
  }
  cout<<ans;
  
}


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

#define int long long
#define ll long long
#define pb push_back
#define mp make_pair
#define f(i,a,n) for(int i=a ; i<(int)n ; i++)
#define rf(i,n,a) for(int i=n ; i>=a ; i--)
#define F first
#define S second
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()
#define fill(a,v) memset(a,v,sizeof(a))
#define d1(a) cout << a << "\n"
#define d2(a,b) cout << a << " " << b << "\n"
#define d3(a,b,c) cout << a << " " << b << " " << c << "\n"
#define d4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << "\n"
#define fast ios:: sync_with_stdio(false),cin.tie(nullptr);

typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<pii,int> ppi;
typedef vector<pii> vpi;

const int inf = 1e9;
const int inf64 = 1e18;
const int MOD = inf + 7;
struct BIT
{
	int N;
	vector<int> bit;

	void inti(int n)
	{
		N = n;
		bit.assign(n+1 , 0);
	}

	void update(int pos , int val)
	{
		while(pos <= N)
		{
			bit[pos] += val;
			pos += pos & -pos;
		}
	}

	int pref(int pos)
	{
		int ans = 0;
		while(pos > 0)
		{
			ans += bit[pos];
			pos -= pos & -pos;
		}
		return ans;
	}

	int query(int l , int r)
	{
		return pref(r) - pref(l-1);
	}
};
const int N = 500005;
BIT a[26];
int32_t main(){
	fast;
	
	for(int i=0 ; i<26 ; i++)
		a[i].inti(N);

	int n;
	cin >> n;
	string s;
	cin >> s;
	
	for(int i=1 ; i<=n ; i++)
	{
		a[s[i-1]-'a'].update(i,1);
	}

	int q;
	cin >> q;
	while(q--)
	{
		int t;
		cin >> t;
		if(t == 1)
		{
			int pos;
			char aa;
			cin >> pos >> aa;
			a[s[pos-1]-'a'].update(pos,-1);
			s[pos-1] = aa;
			a[s[pos-1]-'a'].update(pos,1);
		}
		else
		{
			int l,r;
			cin >> l >> r;
			int ans = 0;
			for(int i=0 ; i<26 ; i++)
			{
				if(a[i].query(l,r) > 0 )
					ans++;
			}
			cout << ans << "\n";
		}
	}
}

Measured memory_bytes: 102804
n,W=map(int,input().split())
t = [[-1 for i in range(W + 1)] for j in range(n + 1)] 
  
def dp(n,W,w,p):
  
  if n==0 or W==0:
    return 0
  elif t[n][W]!=-1:
    return t[n][W]
  else:
    if w[n-1]<=W:
      t[n][W]=max(p[n-1]+dp(n-1,W-w[n-1],w,p),dp(n-1,W,w,p))
      return t[n][W]
    else:
      t[n][W]=dp(n-1,W,w,p)
      return t[n][W]

weight,profit=[],[]
for _ in range(n):
  w,p=map(int,input().split())
  weight.append(w)
  profit.append(p)
print(dp(n,W,weight,profit))

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

#define REP(i, m, n) for (int i = (m); i < (int)(n); i++)
#define REPS(i, m, n) for (int i = (m); i <= (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define reps(i, n) for (int i = 0; i <= (int)(n); i++)
#define rrep(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define rreps(i, x) for (int i = (int)(x); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef pair<int, int> P;
const int inf = INT_MAX;
const ll INF = 1LL << 60;
const ll mod = 1e9 + 7;
const double EPS = 1e-10;
const double PI = acos(-1.0);
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val) { fill( (T*)array, (T*)(array+N), val ); }
template <class T1, class T2, class Pred = std::less<T2> >
struct sort_pair_second {
    bool operator()(const std::pair<T1,T2>&left, const std::pair<T1,T2>&right) {
        Pred p;
        return p(left.second, right.second);
    }
};

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

    int N; cin >> N;
    vector<ll> A(N), X(N), Y(N);
    rep(i, N) cin >> A[i];
    rep(i, N) X[i] = A[i] + i;
    rep(i, N) Y[i] = i - A[i];
    map<ll, ll> mpx, mpy;
    rep(i, N) {
      mpx[X[i]]++;
      mpy[Y[i]]++;
    }
    ll ans = 0;
    for (auto x : mpx) {
      ll ind = x.fi;
      ans += x.se * mpy[ind];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 42108
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>
#include <numeric>
#include <queue>
#include <stack>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9) + 7;

int main(void) {
	int n, m;
	cin >> n >> m;
	
	vector< vector<int> > s(m);
	for(int i = 0; i < m; ++i) {
		int k;
		cin >> k;
		
		for(int j = 0; j < k; ++j) {
			int v;
			cin >> v;
			s[i].push_back(v - 1);
		}
	}
	
	vector<int> p(m);
	for(int i = 0; i < m; ++i) {
		cin >> p[i];
	}
	
	int ans = 0;
	for(int bit = 0; bit < (1 << n); ++bit) {
		bool f = true;
		
		for(int j = 0; j < m; ++j) {
			int x = 0;
			
			for(int k = 0; k < s[j].size(); ++k) {
				int a = s[j][k];
				
				if( bit & (1 << a) ) x ^= 1;
			}
			
			if( x != p[j] ) f = false;
		}
		
		ans += f;
	}
	
	cout << ans << endl;
	
	return 0;
}


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

int main()
{
    ll n,i,j,ans = LONG_MAX;
    cin>>n;
    for(i=1;i*i<=n;i++)
    {
        if(n%i==0)
        {
            ans = max(to_string(i).length(),to_string(n/i).length());
        }
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);

    int n = sc.nextInt();
    String ans = "hon";

    if(n % 10 == 3){
      ans = "bon";
    } else if(n % 10 == 0 || n % 10 == 1 || n % 10 == 6 || n % 10 == 8){
      ans = "pon";
    }

    System.out.println(ans);
  }
}


Measured memory_bytes: 35732
import sys
import itertools
MAX_INT = int(10e10)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

N = I()
d = IL()

ans = 0
for i in itertools.combinations(d, 2):
  ans += i[0] * i[1]
print(ans)

Measured memory_bytes: 39024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i <= (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define printa(x,m,n) for(ll i = (m); i <= n; i++){cout << (x[i]) << " ";} cout<<endl;

ll n, m, dp[1008][(1 << 12)], a, b, c;

int main(){
	cin.tie(0); ios::sync_with_stdio(false);
	
	cin >> n >> m;
	dp[0][0] = 0;
	rep(bit, 1, (1 << n)-1){dp[0][bit] = INF;}

	rep(i, 1, m){
		rep(bit, 0, (1 << n)-1){
			dp[i][bit] = dp[i-1][bit];
		}
		
		cin >> a >> b;
		ll key = 0;
		rep(j, 1, b){
			cin >> c;
			key |= (1 << c-1);
		}
		
		rep(bit, 0, (1 << n)-1){
			dp[i][bit | key] = min(dp[i-1][bit]+a, dp[i][bit | key]);
		}
	}
	
	if(dp[m][(1 << n)-1] == INF){
		print(-1)
	}
	else{
		print(dp[m][(1 << n)-1])
	}
	
	return 0;
}

Measured memory_bytes: 32256
import sys
# sys.stdin = open('input.txt')

# i < j
# j - i == Ai + Aj
# j - Aj == i + Ai

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

ans = 0
# key: i + Ai, value: count
d = {}

for j in range(n):
    a1 = j - a[j]
    try:
        ans += d[a1]
    except KeyError:
        d[a1] = 0

    a2 = j + a[j]
    try:
        d[a2] += 1
    except KeyError:
        d[a2] = 1

print(ans)

Measured memory_bytes: 61636
A=list()

while True:
    m,f,r=map(int,input().split())
    if m==-1 and f==-1 and r==-1:
        for i in range(len(A)):
            print(A[i])
        break
    else:
        if m==-1 or f==-1:
            A.append("F")
        elif m+f>=80:
            A.append("A")
        elif 65<=m+f<80:
            A.append("B")
        elif 50<=m+f<65:
            A.append("C")
        elif 30<=m+f<50:
            if r>=50:
                A.append("C")
            else:
                A.append("D")
        else:
            A.append("F")



Measured memory_bytes: 5596
from math import factorial as fact
import math
import sys
import itertools
import numpy as np
from collections import Counter
import datetime
from collections import deque


#入力:N(int:整数)
def input1():
	return int(input())

#入力:N,M(int:整数)
def input2():
	return map(int,input().split())

#入力:[n1,n2,...nk](int:整数配列)
def input_array():
	return list(map(int,input().split()))

def keta(N):
	return len(str(N))


def input_daytime(input_time):
	time,distance=input_time.split()
	t=time.split(":")
	se=str(t[-1]).split(".")
	dt1 = datetime.timedelta(hours=int(t[0]),minutes=int(t[1]),seconds=int(se[0]),milliseconds=int(se[1]))
	return dt1

def combinations(n,r):
	return list(itertools.combinations(range(n),r))



def all_sets(num_list):
	subsets=[]
	for i in range(2,len(num_list) + 1):
		for c in combinations(num_list, i):
			subsets.append(c) 
	return subsets

#公約数の列挙
def ch(x1):
	cf=[]
	for i in range(2,math.sqrt(x1)+1):
		if x1 % i==0:
			cf.append(i)
	return cf

def CountOneRoots(x,y):
	#x:縦，y:横
	return fact(x+y)/fact(x)/fact(y)

# 素因数分解
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a
	
def count_str(m):
	tmp={}
	for i in range(10):
		if i in tmp:
			tmp[i]=1
		else:
			tmp[i]+=1
	return tmp

def is_prime(n):
	if n==1: return True

	for i in range(2,int(math.sqrt(n))+1):
		if n%i==0:
			return False
	return True

n=input1()
p=input_array()
count=0
for i in range(n):
	if i+1!=p[i]:
		count+=1
	if count>2:
		print("NO")
		break
if count==2 or count==0:
	print("YES")






Measured memory_bytes: 12292
#include <iostream>
using namespace std;
int hit(int a[],int b[]);
int blow(int a[], int b[]);
int main(){
    int a[4];
    int b[4];
    while (cin >> a[0] >> a[1] >> a[2] >> a[3]){
        cin >> b[0] >> b[1] >> b[2] >> b[3];
        int hi = hit(a,b);
        int bl = blow(a,b);
        cout << hi << " " << bl << endl;
    }
}

int hit(int a[],int b[]){
    int n=0;
    for (int i=0; i<4;i++){
        if (a[i]==b[i])
            n++;
    }
    return n;
}

int blow(int a[], int b[]){
    int n=0;
    for (int i=0; i<4; i++){
        for (int j=0; j<4; j++){
            if (a[i]==b[j] && i!=j)
                n++;
        }
    }
    return n;
}

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

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

#define pi pair<int,int>
#define pl pair<lld,lld>

#define dump(x) cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define SANKOU(n,a,b) cout << ((n) ? (#a) : (#b) ) << endl

#define mem0(x) memset(x,0,sizeof(x))
#define fillnum(x,n) fill(begin(x),end(x),n)
#define asort(x) sort(x.begin(),x.end())
#define dsort(x,t) sort(x.begin(),x.end(),greater<t>())
#define vuniq(x) x.erase(unique(x.begin(), x.end()), x.end())

#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)

int main() {
    string S;
    ll w;
    cin >> S;
    cin >> w;
    for (int i = 0; i < S.size(); i+=w) {
        cout << S[i];
    }
    cout << endl;
}

Measured memory_bytes: 3656
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <string>
using namespace std;

int main() {
  string s;
  cin >> s;
  int N = s.size();
  int ans = 0;
  bool flag = false;
  int dp[2][s.size() + 1];

  dp[0][0] = 0;
  dp[1][0] = 2;
  for (int i = 0; i < s.size(); ++i) {
    int num = s[i] - '0';

    dp[0][i + 1] = min(dp[0][i], dp[1][i]) + num;
    dp[1][i + 1] = dp[0][i] + 11 - num;
    dp[1][i + 1] = min(dp[1][i + 1], dp[1][i] + 9 - num);
  }

  cout << min(dp[0][s.size()], dp[1][s.size()]) << endl;
  return 0;
}


Measured memory_bytes: 9220
#include <bits/stdc++.h>
using namespace std;
int main(){
    int a,k;
    string s;
    cin>>a>>s>>k;
    char m=s.at(k-1);
    for(char c:s){
        if(c!=m) cout<<"*";
        else cout<<c;
    }
    cout<<"\n";
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#define N 502
using namespace std;
int n,m,i,j,a[N][N],b[N][N];
char c[N][N];
int main()
{
	scanf("%d%d",&n,&m);
	for(i=1;i<=n;i++) scanf("%s",c[i]+1);
	for(i=1;i<=n;i++) a[i][1]=b[i][m]=1;
	for(i=1;i<=n;i+=2){
		for(j=1;j<m;j++) a[i][j]=1;
	}
	for(i=2;i<=n;i+=2){
		for(j=2;j<=m;j++) b[i][j]=1;
	}
	for(i=1;i<=n;i++){
		for(j=1;j<=m;j++){
			if(c[i][j]=='#') a[i][j]=b[i][j]=1;
		}
	}
	for(i=1;i<=n;i++){
		for(j=1;j<=m;j++){
			if(a[i][j]==0) printf(".");
			else printf("#");
		}
		puts("");
	}
	puts("");
	for(i=1;i<=n;i++){
		for(j=1;j<=m;j++){
			if(b[i][j]==0) printf(".");
			else printf("#");
		}
		puts("");
	}
	return 0;
}


Measured memory_bytes: 5972
#include <iostream>
#include <algorithm>
#include <queue>
#include <vector>
#include <set>
#include <cmath>
#include <string>
#include <map>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ROF(i,a,b) for(int i=b-1;i>=a;i--)
#define FI first
#define SE second
#define MA(i,j) make_pair(i,j)
#define PA pair<int,int>
#define PB push_back
#define PQ priority_queue<int>
#define PGQ priority_queue<int,vector<int>,greater<int> >
#define VE vector<long long>
#define VP vector<PA>
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define Yes(i) cout<<(i?"Yes":"No")<<endl
using namespace std;
//
int MOD=1e9+7;
int INF=1e9+7;
//
int main(){
  int N;
  int L[200];
  cin>>N;
  FOR(i,0,2*N){
    cin>>L[i];
  }
  sort(L,L+2*N);
  int ans=0;
  for(int i=0;i<2*N;i+=2){
    ans+=L[i];
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <limits>
#include <cfenv>
#include <cmath>
#include <algorithm>
#include <array>
#include <bitset>
#include <cstring>
#include <map>
#include <stack>
#include <set>
#include <tuple>
#include <queue>
#include <vector>
#include <cmath>
#include <random>
#include <math.h>
#include <list>
#include <random>
#include <functional>


#define FOR(i, a, b) for(int (i) = (a); (i) < (b); ++(i))
#define REP(i, n) FOR(i, 0, n)
#define rREP(i, n) for(int (i) = (n) - 1; (i) >= 0; --(i))
#define ALL(TheArray) TheArray.begin(), TheArray.end()

using lli = long long int;
using pii = std::pair<int, int>;

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


// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


constexpr int mod = 1000000007
  ;
std::vector<int> A, Waiting;

int main(void){
    int n; scanf("%d", &n);
    A.resize(n); REP(i, n) scanf("%d", &A[i]);
    Waiting.assign(n, 0);
    Waiting[0] = 3;
    lli res = 1;
    REP(i, n){
        if(Waiting[A[i]] == 0){
            puts("0");
            return 0;
        }
        (res *= Waiting[A[i]])%= mod;
        Waiting[A[i]]--;
        Waiting[A[i]+1]++;
    }
    printf("%lld\n", res);

    
    
    

    
    return 0;
}

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

int main(void){
	ll a,b,c,d;
	cin>>a>>b>>c>>d;
	ll ans = 0;
	ans = abs(b-a)+1;
	ll tmp = 0;
	tmp += (b/c)-((a-1)/c);
	tmp += (b/d)-((a-1)/d);

	 ll x = c * d;

	  if(c<d){
	    ll tmp2 = c;
	    c = d;
	    d = tmp2;
	  }

	  ll r = c % d;
	  while(r!=0){
	    c = d;
	    d = r;
	    r = c % d;
	  }
	  ll lcm = x/d;
	 // cout<<lcm<<endl;
	  tmp -= ((b/lcm)-((a-1)/lcm));
	  //cout<<tmp<<endl;
	  cout<<ans-tmp<<endl;
}


Measured memory_bytes: 256
//#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"

#define rep(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
typedef long long ll;

using namespace std;


int main() {
	ll x; cin >> x;
	ll ans = 0;
	ll k = 0;
	while (k < x) {
		ans += 1;
		k += ans;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#define _LIBCPP_DEBUG 0
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll MOD = 1e9 + 7;
int INF = 1 << 30;

int main(void){

    int N; cin>>N;

    if(N%10==3){
        cout<<"bon"<<endl;
    }else if(N%10==0 ||N%10==1 ||N%10==6 ||N%10==8){
        cout<<"pon"<<endl;
    }else {
        cout<<"hon"<<endl;
    }

}


Measured memory_bytes: 3636
#include <iostream>
#include <climits>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <vector>

#define ll long long
#define REP(i, n) for (int i=0;i<n;++i)
#define REP_1(i, n) for (int i=1;i<=n;++i)
#define REP_2(i, j, n, m) REP(i, n) REP(j, m)
#define REP_2_1(i, j, n, m) REP_1(i, n) REP_1(j, m)

#define JU_RAN(a,x,b) a<=x&&x<=b



using namespace std;

char v[105][105];
int m,n;

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

void dfs(int x,int y, char z){
    v[x][y]='0';

    REP(i,4){
        int nx=x+dx[i];
        int ny=y+dy[i];

        if(JU_RAN(1,nx,m)&&JU_RAN(1,ny,n)&&v[nx][ny]==z){
            dfs(nx,ny,z);
        }
    }
}

void solve(){

    while (cin>>m>>n){
        if(m==0&&n==0)break;

        REP_2_1(i,j,m,n)cin>>v[i][j];

        int ans=0;
        REP_2_1(i,j,m,n){
                if(v[i][j]!='0'){
                    dfs(i,j,v[i][j]);
                    ans++;
                }
            }

        cout<<ans<<endl;
    }




}



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

#ifdef LOCAL_DEFINE
    freopen("input.txt", "rt", stdin);
#endif

    solve();



#ifdef LOCAL_DEFINE
    cerr << "\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
    return 0;
}


Measured memory_bytes: 3624
N = int(input())
a = list(map(int, input().split()))
a_comb = []
mod = 10 ** 9 + 7

for i in range(N):
    a_comb.append(abs(i - (N - 1 - i)))

if sorted(a_comb) == sorted(a):
    print(2 ** (N // 2) % mod)
else:
    print(0)

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


int main(){
  int N;
  int i,j;
  int a;
  int count=0;
  scanf("%d",&N);
  
  for(i=1;i<=N;i++){
    scanf("%d",&a);
    if(a==2) count+=1;//a==2は、約数として奇数のみを調べていくため、事前にチェック
    if(a%2!=0){
      j=3;
      while(1){
        if( a < j*j){
          count+=1;
          break;
        }//この条件を満たすまで奇数の約数がなかったら素数
        
        if(a%j==0) break;//割り切れたら素数じゃない
        j+=2;
      }
    }
  }
  printf("%d\n",count);
  return 0;
}


Measured memory_bytes: 2080
#include<iostream>
using namespace std;
int main()
{
	int x, y,z;
	while (cin>>x>>y){
    if (x == 0 && y == 0) { break; }
	if (x > y) { z = x; x = y; y = z; }
	cout << x << " " << y<<endl;
	}

return 0;
}	

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

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 (a>b) { a=b; return 1; } return 0; }

#define ld long double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

//-------------------------------------------------
//--Segment tree
//-------------------------------------------------
template<typename T>
class SegmentTree
{
private:
    using F = function<T(T,T)>;
    ::std::vector<T> btree;
    F f, _update;
    T e;
    int n;
public:
    SegmentTree(){}
    SegmentTree(int _n, F f, T e, F g=[](T a,T b){return b;})
         : f(f),e(e),_update(g)
    {
        init(_n);
    }
    SegmentTree(const ::std::vector<T> &v, F f, T e, F g=[](T a,T b){return b;})
         : f(f),e(e),_update(g)
    {
        int _n = v.size();
        init(_n);
        for(int i=0; i<_n; i++) btree[i+n-1] = v[i];
        build();
    }
    void init(int _n){
        n = 1;
        while(_n>n) n<<=1;
        btree.resize(2*n-1, e);
    }
    void build(){
        for(int i=n-2; i>=0; i--) btree[i] = f(btree[2*i+1], btree[2*i+2]);
    }
    void update(int k, T a){
        k += n-1;
        btree[k] = _update(btree[k], a);
        while(k>0){
            --k>>=1;
            btree[k] = f(btree[2*k+1], btree[2*k+2]);
        }
    }
    T query(int a, int b){
        T L=e, R=e;
        a+=n-1; b+=n-1;
        while(a<b){
            if (!(a & 1)) L=f(L, btree[a++]);
            if (!(b & 1)) R=f(btree[--b], R);
            a>>=1; b>>=1;
        }
        return f(L, R);
    }
    T operator[](int k){return btree[k+n-1];}
};

//-------------------------------------------------

int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);
    int n; cin>>n;
	ll c; cin>>c;
	vll x(n),v(n);
	rep(i,n) cin>>x[i]>>v[i];
	vll rsum(n+1),lsum(n+1);
	rep(i,n) rsum[i+1]=rsum[i]+v[i];
	rep(i,n) rsum[i+1]-=x[i];
	rep(i,n) lsum[i+1]=lsum[i]+v[n-1-i];
	rep(i,n) lsum[i+1]-=c-x[n-1-i];
	SegmentTree<ll> segR(rsum, [](ll x,ll y){return max(x,y);}, 0ll);
	SegmentTree<ll> segL(lsum, [](ll x,ll y){return max(x,y);}, 0ll);
	ll ans=0;
	//L -> R
	FOR(i,0,n){
		ll sum=0;
		sum += lsum[i];
		if (i>0) sum -= c-x[n-i];
		sum += segR.query(0,n-i+1);
		chmax(ans,sum);
	}
	//R -> L
	FOR(i,0,n){
		ll sum=0;
		sum += rsum[i];
		if (i>0) sum -= x[i-1];
		sum += segL.query(0,n-i+1);
		chmax(ans,sum);
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 7552
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long int lli;
 
vector< vector<int> > vec(100001, vector<int>());
vector<bool> ans(100001, true);
vector<bool> used(100001, false);
 
void func (int idx) {
    used[idx] = true;
    //cout << "idx : " << idx << endl;
 
    for (int i=0; i<vec[idx].size(); i+=2) {
        if (used[vec[idx][i]]) {
            continue;
        }
 
        if (vec[idx][i+1] % 2) {
            ans[vec[idx][i]] = !ans[idx];
        }
        else {
            ans[vec[idx][i]] = ans[idx];
        }
        func(vec[idx][i]);
    }
}
 
int main() {
    int n, u, v, w;
 
    cin >> n;
    for (int i = 0; i < n-1; i++)
    {
        cin >> u >> v >> w;
        vec[u].push_back(v);
        vec[u].push_back(w);
        vec[v].push_back(u);
        vec[v].push_back(w);
    }

    func(1);

    for (int i = 0; i < n; i++)
    {
        cout << ((ans[i+1]) ? 1 : 0) << endl;
    }
    
    return 0;
}

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

int main(){
  int n; cin>>n;
  int num=n/2;
  int ans;
  vector<int>d(n);
  for(int i=0; i<n; ++i){
    cin>>d[i];
  }
  
  sort(d.begin(), d.end());
  ans = d[num]-d[num-1];
  
  cout << ans << endl;
}

Measured memory_bytes: 640
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  string S;
  cin>>S;
  string ans;
  for(int i=0;i<S.size();++i) {
    if(S[i]=='B') {
      if(ans.size()>0) ans.pop_back();
    }
    else {
      ans.push_back(S[i]);
    }
  }
  cout<<ans<<endl;
}



Measured memory_bytes: 3612
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORS(i, m, n) for (int i = m; i <= n; i++)
#define bit(n) (1LL << (n))
#define INF 2e9
#define MOD (1000000007)
#define EPS 1e-9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long long int lli;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    lli Q;
    cin >> Q;
    vector<vector<lli>> v(Q, vector<lli>(3, 0));
    REP(i, Q)
    {
        cin >> v[i][0];
        if (v[i][0] == 1)
        {
            cin >> v[i][1] >> v[i][2];
        }
    }
    //find medium
    lli sum = 0;
    multiset<lli> l, r;
    l.insert(-INF);
    r.insert(INF);
    lli lsum = 0;
    lli rsum = 0;
    // 5 012 34  l>r
    // 6 012 345 l>=r
    //6 6 -> 76,67*
    //7 6 -> 77,86*
    bool isEven = true;
    REP(i, Q)
    {
        if (v[i][0] == 1) //add section
        {
            isEven = !isEven;
            lli val = v[i][1];
            sum += v[i][2];
            //cout << val << " " << v[i][2] << "\n";
            if (*r.begin() <= val)
            {
                r.insert(val);
                rsum += val;
            }
            else
            {
                //cout << val << "!\n";
                l.insert(val);
                lsum += val;
            }
            if (l.size() < r.size() && !isEven)
            {
                auto p = r.begin();
                lli rmin = *p;
                r.erase(p);
                rsum -= rmin;
                l.insert(rmin);
                lsum += rmin;
            }
            else if (l.size() > r.size() && isEven)
            {
                auto p = l.end();
                --p;
                lli lmax = *p;
                //イテレータ pos は有効かつ逆参照可能でなければなりません。 そのため end() イテレータは (有効であるが逆参照可能でないため) pos の値として使用することはできません。
                //  cout << "lmax = " << lmax << "\n";
                l.erase(p);
                lsum -= lmax;
                r.insert(lmax);
                rsum += lmax;
            }
        }
        else
        {
            lli val = *(--l.end());
            lli lrsize = l.size() - r.size();
            // cout << val << " " << lsum << " " << rsum << " " << lrsize << " " << val << " " << sum << "\n"; // v4 l4 r0 lr1 v4 s2,-4+0+4+2=2.
            //cout << l.size() - 1 << " lr " << r.size() - 1 << "sum= " << sum << "\n";
            cout << val << " " << -lsum + rsum + lrsize * val + sum << "\n";
        }
    }
}

Measured memory_bytes: 20608
#include <bits/stdc++.h>
using namespace std;
long long dp[2020][2020];
int main() {
    int n; cin >> n;
    int a[n]; for (int &i : a) cin >> i;
    int p[n]; iota(p, p + n, 0);
    sort(p, p + n, [&] (int x, int y) {
        return a[x] > a[y];
    });
    for (int i = 0; i < n; i++) {
        for (int j = 0; i + j < n; j++) {
            int k = i + j;
            dp[i + 1][j] = max(dp[i + 1][j], dp[i][j] + 1LL * a[p[k]] * abs(p[k] - i));
            dp[i][j + 1] = max(dp[i][j + 1], dp[i][j] + 1LL * a[p[k]] * abs(p[k] - (n - 1 - j)));
        }
    }
    long long ans = 0;
    for (int i = 0; i <= n; i++) 
        ans = max(ans, dp[i][n - i]);
    cout << ans;
}

Measured memory_bytes: 26312
import java.awt.geom.Line2D;
import java.awt.geom.Point2D;
import java.util.*;

public class Main {
	Scanner in = new Scanner(System.in);
	public static void main(String[] args) {
		new Main();
	}

	public Main(){
		new AOJ0068().doIt();
	}
	
	
	class AOJ0068{
		int n;
		Point2D p[];
		
		void solve(){
			Point2D[] a = convexHull(p);
//			System.out.println(Arrays.toString(a));
			System.out.println(p.length-a.length);
		}
		
		void doIt(){
			while(in.hasNext()){
				n = in.nextInt();
				if(n==0)break;
				p = new Point2D[n];
				for(int i=0;i<n;i++){
					String[] a = in.next().split(",");
					p[i] = new Point2D.Double(Double.parseDouble(a[0]),Double.parseDouble(a[1]));
				}
//				System.out.println(Arrays.toString(p));
				solve();
			}
		}
		//凸包 返上は含めない
		Comparator< Point2D > com = new Comparator< Point2D >() {
			public int compare(Point2D p1,Point2D p2) {
				if(p1.getX() < p2.getX()) return -1;
				else if(p1.getX() > p2.getX()) return 1; 
				else if(p1.getY() < p2.getY()) return -1;
				else if(p1.getY() > p2.getY()) return 1; 
				else return 0;
			}
		};
		Point2D[] convexHull(Point2D []plist) { 
			int n = plist.length; Arrays.sort(plist, com);
			int k = 0;
			Point2D [] qs = new Point2D[n * 2]; 
			for(int i = 0; i < n; i++){
				while(k > 1 && new Line2D.Double(qs[k-2] , qs[k-1]).relativeCCW(plist[i]) > 0){
					k--;
				}
				qs[k++] = plist[i]; 
			}
			for(int i = n - 2, t = k; i >= 0; i--){
				while(k > t && new Line2D.Double(qs[k-2] , qs[k-1]).relativeCCW(plist[i]) > 0){
					k--;
				}
				qs[k++] = plist[i]; 
			}
			Point2D [] res = Arrays.copyOf(qs, k-1);
			return res; 
		}
	}
	
}

Measured memory_bytes: 17324
/*
Original problem: https://atcoder.jp/contests/dp/tasks/dp_s
Author: sammochen
*/

#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"

using namespace std;

#define REP(x,l,u) for(ll x = l;x<u;x++)
#define RREP(x,l,u) for(ll x = l;x>=u;x--)

#define PII pair<int,int>
#define PLL pair<ll,ll>
#define MP make_pair

typedef  long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ld;
typedef vector<ll> VLL;
typedef vector<int> VI;

const ll mod = 1e9+7;

namespace SOLVE {
	void addmod(ll & a, ll b) {
		a += b;
		if (a >= mod) {
			a -= mod;
		}
	}

	void main() {
		ll n, r;
		string s;

		cin >> s >> r;
		n = s.length();

		vector < VLL > dp(r, VLL(2)); // dp[rem][tight]

		// base case
		dp[0][0] = 1;
		dp[0][1] = 1;

		RREP(index, n - 1, 0) {
			vector < VLL > temp(r, VLL(2));
			int digit = (s[index] - '0');

			REP(rem, 0, r) {
				// the tight version is the sum of all prev ones loose, plus the same number tight
				REP(num, 0, digit) {
					addmod(temp[rem][1], dp[(rem - num + 10 * r) % r][0]);
				}
				addmod(temp[rem][1], dp[(rem - digit + 10 * r) % r][1]);

				// the loose version is sum of 0-9
				REP(num, 0, 10) {
					addmod(temp[rem][0], dp[(rem - num + 10 * r) % r][0]);
				}
			}
			dp = temp;
		}


		// ans is dp[0][1] - 1 (the 0 was counted as a 0modr solution)
		ll ans = dp[0][1] == 0 ? mod - 1 : dp[0][1] - 1;
		cout << ans << endl;
	}
}


signed main() {
	int t;
	t = 1;
	// cin >> t;
	while (t--) {
		SOLVE::main();
	}

	return 0;
}

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

int main() {
  int h,w;
  cin >> h >> w;
  string s,x;
  for (int i = 0; i < w+2; i++) {
    s += "#";
  }
  cout << s << endl;
  for (int i = 0; i< h; i++) {
    cin >> x;
    cout << "#" << x << "#" << endl;
  }
  cout << s << endl;
}


Measured memory_bytes: 3592
integer(16) :: stone(-1000000:1000000)
      integer(16) :: k,x,i,up,bottom
      
      read*,k,x
      
      stone(-1000000) = -1000000
      do i = -1000000+1,1000000
        stone(i) = stone(i-1) + 1
      end do
      
      
      up = x - k + 1
      bottom = x + k -1
      
      print'(*(I0,x))',stone(up:bottom)
      end

Measured memory_bytes: 34148
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while (true) {
			int n = sc.nextInt();
			if (n == 0) {
				sc.close();
				break;
			}

			String[][] conv = new String[n][2];
			for (int i = 0; i < conv.length; i++) {
				conv[i][0] = sc.next();
				conv[i][1] = sc.next();
			}

			String before = sc.next();
			String after = sc.next();

			Deque<String> deque = new ArrayDeque<String>();
			deque.addLast(before);
			int depth = 0;
			boolean convertable = false;
			bfs: while (!deque.isEmpty()) {
				depth++;
				int size = deque.size();
				for (int q = 0; q < size; q++) {
					String poll = deque.pollFirst();
					for (int i = 0; i < conv.length; i++) {
						String test = poll.replaceAll(conv[i][0], conv[i][1]);
						if (test.equals(poll)) {
							continue;
						} else if (test.equals(after)) {
							convertable = true;
							break bfs;
						} else if (test.length() <= after.length()) {
							deque.addLast(test);
						}
					}
				}
			}
			if (convertable) {
				System.out.println(depth);
			} else {
				System.out.println(-1);
			}
		}
	}
}

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

int main() {
  int H, W;
  cin >> H >> W;
  string area[H];
  for(int i = 0; i < H; i++) {
    cin >> area[i];
  }
  int dir[][2] = {{-1, -1}, {-1, 0}, {-1, 1}, {0, 1}, {1, 1}, {1, 0}, {1, -1}, {0, -1}};
  for(int i = 0; i < H; i++) {
    for(int j = 0; j < W; j++) {
      if(area[i][j] == '.') {
        int count = 0;
        int h, w;
        for(int k = 0; k < 8; k++) {
          h = i + dir[k][0];
          w = j + dir[k][1];
          if(h >= 0 && h < H && w >= 0 && w < W) {
            if(area[h][w] == '#') {
              count++;
            }
          }
        }
        area[i][j] = char(count + '0');
      }
    }
  }
  for(int i = 0; i < H; i++) {
    cout << area[i] << endl;
  }
}


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

int64_t I=167167167167167;

int main(){
  int N,M,S,T;
  cin>>N>>M>>S>>T;
  S--,T--;
  vector<vector<tuple<int,int64_t,int64_t>>> G(N);
  for(int i=0;i<M;i++){
    int a,b;
    int64_t c,d;
    cin>>a>>b>>c>>d;
    a--,b--;
    G[a].push_back(make_tuple(b,c,d));
    G[b].push_back(make_tuple(a,c,d));
  }
  vector<int64_t> yen(N,I);
  vector<int64_t> snuke(N,I);
  priority_queue<pair<int64_t,int>> pq;
  pq.push(make_pair(0,S));
  yen[S]=0;
  while(!pq.empty()){
    int64_t a;
    int b;
    tie(a,b)=pq.top();
    pq.pop();
    a*=-1;
    if(yen[b]<a){
      continue;
    }
    for(auto x:G[b]){
      int c;
      int64_t d,e;
      tie(c,d,e)=x;
      if(yen[c]>d+a){
        yen[c]=d+a;
        pq.push(make_pair((d+a)*-1,c));
      }
    }
  }
  pq.push(make_pair(0,T));
  snuke[T]=0;
  while(!pq.empty()){
    int64_t a;
    int b;
    tie(a,b)=pq.top();
    pq.pop();
    a*=-1;
    if(snuke[b]<a){
      continue;
    }
    for(auto x:G[b]){
      int c;
      int64_t d,e;
      tie(c,d,e)=x;
      if(snuke[c]>e+a){
        snuke[c]=e+a;
        pq.push(make_pair((e+a)*-1,c));
      }
    }
  }
  vector<int64_t> p(N,1167167167167167);
  for(int i=0;i<N;i++){
    p[i]-=I;
    p[i]-=yen[i];
    p[i]-=snuke[i];
  }
  for(int i=N-1;i>0;i--){
    p[i-1]=max(p[i],p[i-1]);
  }
  for(int i=0;i<N;i++){
    cout<<p[i]<<endl;
  }
  
}

Measured memory_bytes: 15000
using System;

namespace Sample101
{
    class Program
    {
        static void Main(string[] args)
        {
            while (true)
            {
                var line = Console.ReadLine().Split(' ');
                var n = int.Parse(line[0]);
                var x = int.Parse(line[1]);
                if (n == 0 && x == 0)
                {
                    return;
                }

                int result = 0;
                for (int i = 1; i < n - 1; i++)
                {
                    for (int j = i + 1; j < n; j++)
                    {
                        for (int k = j + 1; k <= n; k++)
                        {
                            if (i + j + k == x)
                            {
                                result++;
                            }
                        }
                    }
                }
                Console.WriteLine(result);
            }
        }
    }
}


Measured memory_bytes: 15980
#include<bits/stdc++.h>
using namespace std;
#define REP(i,st,ed) for(register int i=st,i##end=ed;i<=i##end;++i)
#define DREP(i,st,ed) for(register int i=st,i##end=ed;i>=i##end;--i)
typedef long long ll;
template<typename T>inline bool chkmin(T &x,T y){return (y<x)?(x=y,1):0;}
template<typename T>inline bool chkmax(T &x,T y){return (y>x)?(x=y,1):0;}
inline int read(){
	int x;
	char c;
	int f=1;
	while((c=getchar())!='-' && (c>'9' || c<'0'));
	if(c=='-') f=-1,c=getchar();
	x=c^'0';
	while((c=getchar())>='0' && c<='9') x=(x<<1)+(x<<3)+(c^'0');
	return x*f;
}
inline ll readll(){
	ll x;
	char c;
	int f=1;
	while((c=getchar())!='-' && (c>'9' || c<'0'));
	if(c=='-') f=-1,c=getchar();
	x=c^'0';
	while((c=getchar())>='0' && c<='9') x=(x<<1ll)+(x<<3ll)+(c^'0');
	return x*f;
}
int l[100],r[100],w[100];
int main(){
	int n=read();
	int N=20,M=0;
	REP(i,1,19){
		l[++M]=i,r[M]=i+1,w[M]=0;
		if(n>=(1<<i)) l[++M]=i,r[M]=i+1,w[M]=(1<<(i-1));
	}
	int num;
	for(num=0;(1<<num)<n;++num);
	if((1<<num)!=n){
		n&=(1<<num)-1;
		int res=0;
		--num;
		DREP(i,num,0) if(n&(1<<i)){
			if(res) l[++M]=i+1,r[M]=20,w[M]=res;
			res|=(1<<i);
		}
	}
	printf("%d %d\n",N,M);
	REP(i,1,M) printf("%d %d %d\n",l[i],r[i],w[i]);
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<bitset>
#include<vector>
#include<deque>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cmath>
#include<iomanip>
#include <functional>
using namespace std;
typedef long long ll;
const int mod = 1000000007;
const int INF = 1 << 28;
const double EPS = 1e-10;
//cout << fixed << std::setprecision(9)
//memset(a, 0, sizeof(a));
//--------------------------


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

	if (a + b >= c) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

	return 0;
}



Measured memory_bytes: 764
X,Y = map(int,input().split())

money = [3*10**5,2*10**5,10**5]

ans = 0
if X == 1 and Y == 1:
    ans = 2*money[0] + 4*10**5
    print(ans)
else:
    if X <= 3:
        ans += money[X-1]
    if Y <= 3:
        ans += money[Y-1]
    print(ans)


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

int main()
{
  int n;
  int t[100001],x[100001],y[100001];
  int i;
  scanf("%d",&n);
  t[0]=0;
  x[0]=0;
  y[0]=0;
  for(i=1;i<=n;i++){
    scanf("%d%d%d",&t[i],&x[i],&y[i]);
  }
  for(i=0;i<n;i++){
    if(abs(x[i+1]-x[i])+abs(y[i+1]-y[i])>t[i+1]-t[i]){
      printf("No");
      return 0;
    }
    else if((abs(x[i+1]-x[i])+abs(y[i+1]-y[i]))%2!=(t[i+1]-t[i])%2){
      printf("No");
      return 0;
    }
  }
  printf("Yes");
  return 0;
}



Measured memory_bytes: 2856
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef pair<ll, ll> P;

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

    vector<bool> fi(10, false), se(100, false), th(1000, false);
        for(char c: s){
            int x = c-'0';
            for(int i=0; i<100; i++)
                if(se[i]) th[i*10+x] = true;
            for(int i=0; i<10; i++){
                if(fi[i]) se[i*10+x]=true;
            }
            fi[x] = true;
        }
    int ans=0;
        for(auto a: th) 
            if(a) ans += 1;
    cout << ans << endl;

    
}

Measured memory_bytes: 256
from sys import stdin
def main():
    #入力
    readline=stdin.readline
    n=int(readline())
    a=list(map(int,readline().split()))

    flags=[False]*8
    free=0
    for i in range(n):
        if a[i]//400<=7:
            flags[a[i]//400]=1
        else:
            free+=1

    color_max=flags.count(1)+free
    color_min=max(1,flags.count(1))
    print(color_min,color_max)

if __name__=="__main__":
    main()

Measured memory_bytes: 3064