akhauriyash/Code-Regression huggingface dataset:
mod = 10**9 + 7
N = int(input())
T = list(map(int, input().split()))
A = list(map(int, input().split()))

Min = [1] * N
Max = [float("inf")] * N
tp = 0
for i, t in enumerate(T):
    if t != tp:
        Min[i] = max(Min[i], t)
    Max[i] = min(Max[i], t)
    tp = t
ap = 0
for i, a in zip(range(N-1, -1, -1), A[::-1]):
    if a != ap:
        Min[i] = max(Min[i], a)
    Max[i] = min(Max[i], a)
    ap = a
ans = 1
for mi, ma in zip(Min, Max):
    ans = ans * max(ma-mi+1, 0) % mod
print(ans)


Measured memory_bytes: 18532
N, K = map(int, input().split())
As = list(map(int, input().split()))

lastVisit = [None] * N
now = 0
n = 0
while lastVisit[now] is None:
    lastVisit[now] = n
    now = As[now]-1
    n += 1
    if n == K:
        print(now+1)
        exit()

for _ in range((K-lastVisit[now]) % (n-lastVisit[now])):
    now = As[now]-1
print(now+1)


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

#define ll long long

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

  if(a == b && b == c)
  {cout << 1 << endl;}

  else if(a == b)
  {cout << 2 << endl;}

  else if(b == c)
  {cout << 2 << endl;}

  else if(a == c)
  {cout << 2 << endl;}

  else{cout << 3 << endl;}
}

Measured memory_bytes: 3564
#include <stdio.h>
int main(){
    int e,y;
    scanf("%d%d",&e,&y);
    if(e==0){
        if(y>1988)printf("H%d",y-1988);
        else if(y>1925)printf("S%d",y-1925);
        else if(y>1911)printf("T%d",y-1911);
        else printf("M%d",y-1867);
        printf("\n");
        return 0;
    }
    else if(e==1)y+=1867;
    else if(e==2)y+=1911;
    else if(e==3)y+=1925;
    else y+=1988;
    printf("%d\n",y);
}


Measured memory_bytes: 2724
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i < (int)(n); i++)
typedef long long ll;
 
 
int main() {
    int n; cin >> n;
    vector<int> A(n);
    vector<vector<int>> x(n);
    vector<vector<int>> y(n);
    rep(i,n){
        cin >> A[i];
        for(int j = 0; j < A[i]; j++){
        int a;
        int b;
        cin >> a >> b;
        x[i].emplace_back(a);
        y[i].emplace_back(b);
        }
    }
    
    bool judge;
    int ans = 0;
    for(int bit = 0; bit < (1 << n); bit++){
        judge = true;
        rep(i,n){
            if(!(bit & (1 << i))) continue;
            for(int j = 0; j < A[i]; j++){
                if(y[i][j] == 1 && !(bit & (1 << (x[i][j]-1)))) judge = false;
                if(y[i][j] == 0 && (bit & (1 << (x[i][j]-1)))) judge = false;
            }
        }
 
        if(judge){
            int cnt = 0;
            rep(i,n){
                if(bit & (1 << i)) cnt++;
            }
            ans = max(ans,cnt);
        }
    }
 
    cout << ans << endl;
}

Measured memory_bytes: 256
x, y = [int(s) for s in input().split()]
temp_list = [{1, 3, 5, 7, 8, 10, 12}, {4, 6, 9, 1}, {2}]
ans = "No"
for temp in temp_list:
    if x in temp and y in temp:
        ans = "Yes"
print(ans)

Measured memory_bytes: 9088
a = int(input())
b = int(input())
c = int(input())
x = int(input())
ans = 0

for i in range(0, a+1):
    for j in range(0, b+1):
        for k in range(0, c+1):
            if i * 500 + j * 100 + k * 50 == x:
                ans += 1

print(ans)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
 
#define INF 1000000007
#define LINF 1000000000000000007
 
using namespace std;
 
typedef long long ll;
typedef pair<ll, ll> P;


int n;

int main(){
	cin >> n;
	
	cout << n*800 - 200*(n/15) << endl;
	
	return 0;
}

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

using namespace std;

int main(){
    int n, a[10000], temp, k = 0;

    cin >> n;

    for(int i = 0; i < n; i++)cin >> a[i];

    for(int i = 0; i < n; i++)
        for(int j = n - 1; j > i; j--)
        if(a[j] < a[j -1]){
            temp = a[j  - 1];
            a[j - 1] = a[j];
            a[j] = temp;
            k++;
        }
    for(int i = 0; i < n; i++){
            cout << a[i];
            if(i == n - 1)break;
            cout << " ";
    }

    cout << endl;
    cout << k <<endl;
    return 0;
}

Measured memory_bytes: 1168
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define rep(i, n) FOR(i, 0, n - 1)
using namespace std;
typedef long long ll;
template <class T> inline bool dpmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool dpmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}

void solve(long long N, vector<long long> a) {
    ll alice = 0;
    ll bob = 0;

    if (N%2!=0) { a.push_back(0); }
    sort(a.rbegin(), a.rend());

    for (int i=0; i<a.size(); i+=2) {
        alice += a[i];
        bob += a[i+1];
    }

    cout << alice - bob << endl;
}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips:
// You use the default template now. You can remove this line by using your
// custom template)
int main() {
  long long N;
  cin >> N;
  vector<long long> a(N);
  for (int i = 0; i < N; i++) {
    cin >> a[i];
  }
  solve(N, move(a));
  return 0;
}


Measured memory_bytes: 3632
def solver():
	N,K = map(int, input().split())
	h = list(map(int, input().split()))
	dp = [0 for _ in range(N)]
	for i in range(1,N):
		min_cost = 10**10
		for j in range(max(0, i-K),i):
			cost = dp[j] + abs(h[i]-h[j])
			if cost < min_cost : min_cost = cost
		dp[i] = min_cost
	print(dp[N-1])

solver()

Measured memory_bytes: 13976
Day=input()
if Day == "SUN":
    print("7")
elif Day == "MON":
    print("6")
elif Day == "TUE":
    print("5")
elif Day == "WED":
    print("4")
elif Day == "THU":
    print("3")
elif Day == "FRI":
    print("2")
elif Day == "SAT":
    print("1")
else:
    print("無効な入力です")


Measured memory_bytes: 2940
n=int(input())
s=[list(input()) for i in range(n)]
ans=0
for i in range(n):
  ct=0
  for j in range(n):
    for k in range(n):
      if s[(j+i)%n][k]==s[(k+i)%n][j]:
        ct+=1
  if ct==n**2:
    ans+=1
print(ans*n)

Measured memory_bytes: 46716
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v).begin(), (v).end()
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define DEBUG
#define int long long
#define INF 1e18
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }
template<class T>void show(vector<T>v){for (int i = 0; i < v.size(); i++){cerr<<v[i]<<" ";}cerr<<"\n";}
typedef long long ll;

int dp[200010];
ll MOD=1e9+7;
signed main()
{
    int n;
    cin>>n;
    vector<int>c(n),d;
    REP(i,n) cin>>c[i];
    d.push_back(c[0]);
    for (int i = 1; i < n; i++)
    {
        if(c[i]==c[i-1]) continue;
        d.push_back(c[i]);
    }
  //  show(d);
    vector<vector<int>>cnt(2*1e5,vector<int>());
    dp[0]=1;
    cnt[d[0]].push_back(0);
    for (int i = 1; i < d.size(); i++)
    {
        if(cnt[d[i]].size()==0) {
            dp[i]=dp[i-1];
            cnt[d[i]].push_back(i);
        }
        else{
            dp[i]=dp[i-1] + dp[cnt[d[i]].back()];
            cnt[d[i]].push_back(i);
        }
        dp[i]%=MOD;
       // cerr<<dp[i]<<endl;
    }
    cout<<dp[d.size()-1]<<endl;    
    return 0;
}

Measured memory_bytes: 15856
class Dice():
    def __init__(self, arr):
        self.top = arr[0]
        self.front = arr[1]
        self.right = arr[2]
        self.left = arr[3]
        self.back = arr[4]
        self.bottom = arr[5]
        
    def rotate(self, direction):
        if direction == "N":
            self.back, self.top, self.front, self.bottom = \
            self.top, self.front, self.bottom, self.back
        elif direction == "S":
            self.front, self.bottom, self.back, self.top = \
            self.top, self.front, self.bottom, self.back
        elif direction == "E":
            self.right, self.bottom, self.left, self.top = \
            self.top, self.right, self.bottom, self.left
        elif direction == "W":
            self.left, self.bottom, self.right, self.top = \
            self.top, self.left, self.bottom, self.right
        
            
dice = Dice(input().split())

direction_list = list(input())

for direction in direction_list:
    dice.rotate(direction)

print(dice.top)


Measured memory_bytes: 5564
#include<bits/stdc++.h>
using namespace std;
bool a[100];
vector<int> b[100];
int memo[100000];
string str[100000];
int n,m;
void dfs(int num,int dig){
    if(num >= n)return;
    for(int i = 2;i <= 7;i++){
        if(b[i].size() == 0)continue;
        if(memo[num + i] < dig + 1){
            memo[num + i] = dig + 1;
            dfs(num + i, dig + 1);
        }
    }
}
int main(){
    cin >> n >> m;
    for(int i = 0;i < m;i++){
        int x;
        cin >> x;
        a[x] = true;
    }
    if(a[9])b[6].push_back(9);
    if(a[8])b[7].push_back(8);
    if(a[7])b[3].push_back(7);
    if(a[6])b[6].push_back(6);
    if(a[5])b[5].push_back(5);
    if(a[4])b[4].push_back(4);
    if(a[3])b[5].push_back(3);
    if(a[2])b[5].push_back(2);
    if(a[1])b[2].push_back(1);
    dfs(0,0);
    int dig = memo[n];
    int w[] = {0,2,5,5,4,5,6,3,7,6};
    //for(int i = 0;i <= n;i++)cout << i << ", " << memo[i] << endl;
    for(int i = 0;i < dig;i++){
        int d = 0;
        for(int j = 9;j >= 1;j--){
            //cout << i << ": "<< n << endl;
            if(a[j] && memo[n-w[j]] == memo[n] - 1){
                if(i == dig-1 && n != w[j])continue;
                cout << j;
                n -= w[j];
                break;
            }
        }
    }
    cout << endl;

}

Measured memory_bytes: 1280
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <limits.h>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>

typedef unsigned long long ULLONG;
typedef long long LLONG;

template <class _T> static _T tp_abs(const _T& a) {
	return ((a < 0) ? (a * -1) : a);
}
template <class _T> static _T tp_min(_T a, _T b) {
	return a < b ? a : b;
}
template <class _T> static _T tp_max(_T a, _T b) {
	return a > b ? a : b;
}
template<class _T> static void get1int(_T& a) {
	const char* fmt = " %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld";
	}

	if (scanf(fmt, &a) < 0) {
		printf("g1int Error\n");
	}
}
template<class _T> static void get2int(_T& a, _T& b) {
	const char* fmt = " %d %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld %lld";
	}

	if (scanf(fmt, &a, &b) < 0) {
		printf("g2int Error\n");
	}
}
template<class _T> static void get3int(_T& a, _T& b, _T& c) {
	const char* fmt = " %d %d %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld %lld %lld";
	}

	if (scanf(fmt, &a, &b, &c) < 0) {
		printf("g3int Error\n");
	}
}
static void getstring(char* buff) {
	if (scanf(" %s", buff) < 0) {
		printf("getstr error!\n");
	}
}
static const long long MOD_NUM = 1000000007LL;

static void C_task();

int main()
{
	C_task();
	fflush(stdout);
	return 0;
}

class C_data {
public:
	int wa = 0;
	int ac = 0;
};
static void C_task()
{
	int N, M;
	get2int(N, M);

	std::vector<C_data> point(N);

	for (int i = 0; i < M; i++) {
		int num;
		char ret[3] = { 0 };
		get1int(num); num--;
		getstring(ret);

		if (strcmp(ret, "AC") == 0) {
			point[num].ac = 1;
		}
		else if(point[num].ac == 0) {
			point[num].wa++;
		}
	}

	int ac = 0, wa = 0;
	for (int i = 0; i < N; i++) {
		ac += point[i].ac;
		if (point[i].ac) {
			wa += point[i].wa;
		}
	}

	printf("%d %d\n", ac, wa);
}



Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <algorithm>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#define N 110
#define pb push_back
#define fi first
#define se second
#define si size()
#define ll long long
#define mp make_pair
#define iter ::iterator
#define all(v) v.begin(), v.end()
#define READ(f) freopen (f, "r", stdin)
#define WRITE(f) freopen (f, "w", stdout)
#define pp pop_back
#define mapiter map<int, int>::iterator
#define pii pair<int, int>
#define forn(i, n) for(ll i = 0; i < n; ++i)
#define forn1(i, n) for(int i = 1; i <= n; ++i)
#define forr(i, n) for(int i = n - 1; i >= 0; --i)
#define forr1(i, n)	for(int i = n; i >= 1; --i)
#define barnarnar ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define elif else if
#define lld long double
#define r0 return 0
#define EPS 1e-7
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
 
const int inf = 1e9 + 1;
const ll modw = 1e9 + 7;
 
const ll mods[2] = {1000000009ll, 1000000007ll};
const ll p[2] = {31, 53};
 
using namespace std;
using namespace __gnu_pbds;

int a[N];

bool check(int a1, int b, int c)
{
	if(a1 + b <= c)	return 0;
	if(a1 + c <= b)	return 0;
	if(b + c <= a1)	return 0;
	return 1;
}

int main()
{
	barnarnar
	int n;
	cin >> n;
	forn(i, n)	cin >> a[i];
	int ans = 0;
	forn(i, n)
	{
		for(int j = i + 1; j < n; j++)
		{
			for(int k = j + 1; k < n; k++)
			{
				if(check(a[i], a[j], a[k]) && a[i] != a[j] && a[i] != a[k] && a[j] != a[k])
				{
					ans++;
				}
			}
		}
	}
	cout << ans;
}	
// # pog-unlimitation

/*
Merami isn't so great?
Are you kidding me?
When was the last time you saw a player with such aim ability and movement with a tablet?
Merami puts the game in another level, and we will be blessed if we ever see a player with his skill and passion for the game again.
Whitecat breaks records.
Vaxei breaks records.
Merami breaks the rules.
You can keep your statistics.
I prefer the magic.
*/

Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define REP(i, d, n) for(int i=(d); i<(n); ++i)
#define all(v) v.begin(), v.end()
using ll = long long;
int main() {

ll n; cin>>n; int ans=0;
  char c[n]; ll cr=0;
  rep(i,n){cin>>c[i];if(c[i]=='R'){cr++;}}
  
  
    
   rep(i,cr){if(c[i]=='W'){ans++;}} 
    cout<<ans<<endl;
  
  
  

  
}


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

using namespace std;

typedef long long int ll;

const int M = (int) 1e2 + 10;
const int N = (int) 1e5 + 10;
const int mod = (int) 1e9 + 7;

int n, k;
int a[M];
int memo[M][N];

int dp(int at, int rem) {
    if(at == n) return rem == 0 ? 1 : 0;
    int &ans = memo[at][rem];
    if(ans != -1) return ans;
    ans = 0;
    for(int i = 0; i <= a[at] && i <= rem; ++i) {
        ans += dp(at + 1, rem - i);
        ans %= mod;
    }
    return ans;
}

int sum(int l, int r, vector<int> &prefix) {
    int ans = prefix[r];
    if(l > 0) ans -= prefix[l - 1];
    if(ans < 0) ans += mod;
    return ans;
}

void solve() {
    cin >> n >> k;
    for(int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    vector<int> cur(N), nxt(N);
    for(int at = n; at >= 0; --at) {
        for(int rem = 0; rem <= k; ++rem) {
            int ans;
            if(at == n) ans = rem == 0;
            else {
                int l = max(0, rem - a[at]);
                int r = rem;
                ans = sum(l, r, nxt);
            }
            cur[rem] = ans;
        }
        for(int i = 0; i <= k; ++i) {
            if(i > 0) cur[i] = (cur[i] + cur[i - 1]) % mod;
        }
        swap(cur, nxt);
    }
    cout << sum(k, k, nxt) << endl;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(20);
    cout << fixed;
    solve();
    return 0;
}

Measured memory_bytes: 1024
n,m,x,y = map(int,input().split())
xlist = list(int(i) for i in input().split())
ylist = list(int(i) for i in input().split())
z = max(xlist)+1
if z <= min(ylist) and x < z and z <= y:
  print("No War")
else:
  print("War")

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

int main(){
    string s;
    cin >> s;
    string year = s.substr(0, 4);
    string month = s.substr(5, 2);
    if(year <= "2018"){
        cout << "Heisei";
    }else if(year >= "2020"){
        cout << "TBD";
    }else{
        if(month <= "04"){
            cout << "Heisei";
        }else{
            cout << "TBD";
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define rep(i,a,n) for(int i=a;i<(int)(n);i++)
using namespace std;
int main(){
    int a,b,N;
    int time[1000];
    rep(i,0,1000)time[i]=0;
    cin>>a>>b>>N;
    int s,f;
    rep(i,0,N){
        cin>>s>>f;
        rep(j,s,f){
            time[j+1]=1;
        }
    }
    rep(i,a,b){
        if(time[i+1]!=0){
            cout<<1<<endl;
            return 0;
        }
    }
    cout<<0<<endl;
    return 0;
}


Measured memory_bytes: 3140
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repd(i,a,b) for (int i = (a); i < (b); i++)
typedef long long ll;
int main(void)
{
	int n, a, q, b, e, t;
	vector<int> A;
	cin >> n;
	rep(i, n)
	{
		cin >> a;
		A.push_back(a);
	}
	
	cin >> q;
	rep(i, q)
	{
	    cin >> b >> e >> t;
	    swap_ranges(A.begin() + b, A.begin() + e,  A.begin() + t);
	}
	
	rep(i, n)
	{
	    if (i)
	    {
	        cout << " ";
	    }
	    cout << A[i];
	}
	cout << endl;
}



Measured memory_bytes: 3168
#include <cstdio>
#include <iostream>
#include <algorithm>

using namespace std;

int bubbleSort(int *a, int n);

int main()
{
	int n;
	int a[100];
	int cnt;

	scanf("%d", &n);

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

	cnt = bubbleSort(a, n);

	for (int i = 0; i < n; i++){
		if (i == n - 1){
			cout << a[i] << endl;
		}
		else {
			cout << a[i] << " ";
		}
	}
	cout << cnt << endl;

	return (0);
}

int bubbleSort(int *a, int n)
{
	int cnt = 0;

	for (int i = 0; i < n - 1; i++){
		for (int j = n - 1; j > 0; j--){
			if (a[j] < a[j - 1]){
				swap(a[j], a[j - 1]);
				cnt++;
			}
		}
	}
	return (cnt);
}

Measured memory_bytes: 1208
import java.util.*;
public class Main {
    public static long five(long x){
    return x*x*x*x*x;
    }
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		long x = sc.nextLong();
        long a = 0;
		long b = 0;
        for(long i=-1000;i<=1000;i++){
        for(long j=-1000;j<=1000;j++){if(five(i)-five(j)==x){a=i;b=j;break;}}}
		System.out.println(a + " " + b);
	}
}


Measured memory_bytes: 38892
n, m = map(int, input().split())
matrix1 = [[0]*m]*n
matrix2 = [0]*m
answer = [0]*n
for i in range(n):
  matrix1[i] = list(map(int, input().split()))
for i in range(m):
  matrix2[i] = int(input())

for i in range(n):
  for j in range(m):
    answer[i] += matrix1[i][j] * matrix2[j]
  print(answer[i])


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

#define REP(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x.size())
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define uniq(x) x.erase(unique(x.begin(), x.end()), x.end())
#define F first
#define S second
#define mp make_pair
#define eb emplace_back
#define pii pair<int, int>
#define pll pair<ll, ll>

using namespace std;

typedef long long ll;

/* --- INFやMODの値が適切か確認する --- */
// const int INF = 1 << 30;
// const ll INF = 1LL << 60;
// const ll MOD = 1000000007;

int main() {
  int n;
  cin >> n;
  vector<vector<pii>> edge(n, vector<pii>());
  rep(i, n - 1) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    edge[a].eb(mp(b, i));
    edge[b].eb(mp(a, i));
  }

  int ans = 0;
  rep(i, n) ans = max(ans, (int)edge[i].size());
  vector<int> color(n - 1, -1);

  queue<int> Q;
  Q.push(0);

  while (!Q.empty()) {
    int cur = Q.front();
    Q.pop();
    vector<bool> used(ans, 0);
    rep(i, edge[cur].size()) {
      int next = edge[cur][i].F;
      int idx = edge[cur][i].S;
      if (color[idx] != -1) used[color[idx]] = 1;
    }
    int idx2 = 0;
    rep(i, edge[cur].size()) {
      int next = edge[cur][i].F;
      int idx = edge[cur][i].S;
      if (color[idx] != -1) continue;
      while (used[idx2]) idx2++;
      color[idx] = idx2++;
      Q.push(next);
    }
  }

  cout << ans << endl;
  rep(i, n - 1) cout << color[i] + 1 << endl;
}


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

using namespace std ;

using singlebit = uint32_t;
using doublebit = uint64_t;
static constexpr int digit_level = 8 * sizeof(singlebit);

static constexpr singlebit find_inv(singlebit n, int d = 6, singlebit x = 1) {
	return d == 0 ? x : find_inv(n, d - 1, x * (2 - x * n));
}
template <singlebit mod> class fast_modint {
	// Fast Modulo Integer, Assertion: mod < 2^(bits of singlebit - 1) and mod is prime
private:
	singlebit n;
	static constexpr singlebit r2 = (((doublebit(1) << digit_level) % mod) << digit_level) % mod;
	static constexpr singlebit ninv = singlebit(-1) * find_inv(mod);
	singlebit reduce(doublebit x) const {
		singlebit res = (x + doublebit(singlebit(x) * ninv) * mod) >> digit_level;
		return res < mod ? res : res - mod;
	}
public:
	fast_modint() : n(0) {};
	fast_modint(singlebit n_) { n = reduce(doublebit(n_) * r2); };
	static constexpr singlebit get_mod() { return mod; }
	singlebit get() const { return reduce(n); }
	bool operator==(const fast_modint& x) const { return n == x.n; }
	bool operator!=(const fast_modint& x) const { return n != x.n; }
	fast_modint& operator+=(const fast_modint& x) { n += x.n; n -= (n < mod ? 0 : mod); return *this; }
	fast_modint& operator-=(const fast_modint& x) { n += mod - x.n; n -= (n < mod ? 0 : mod); return *this; }
	fast_modint& operator*=(const fast_modint& x) { n = reduce(doublebit(n) * x.n); return *this; }
	fast_modint operator+(const fast_modint& x) const { return fast_modint(*this) += x; }
	fast_modint operator-(const fast_modint& x) const { return fast_modint(*this) -= x; }
	fast_modint operator*(const fast_modint& x) const { return fast_modint(*this) *= x; }
	fast_modint inv() const { return binpow(mod - 2); }
	fast_modint binpow(singlebit b) const {
		fast_modint ans(1), cur(*this);
		while (b > 0) {
			if (b & 1) ans *= cur;
			cur *= cur;
			b >>= 1;
		}
		return ans;
	}
};

using modint = fast_modint<1000000007>;

struct combination
{
    vector<modint>fact , inv ;
    combination(int sz) : fact(sz + 1) , inv(sz + 1)
    {
        fact[0] = 1ll ;
        inv[0] = 1ll ;
        for(long long i = 1 ; i <= sz ; ++i)
        {
            fact[i] = (fact[i-1] * i) ;
            inv[i] = fact[i].inv() ;
        }
    }
    long long choose(int n , int k) const
    {
        if(k < 0 || n < k)
            return 0 ;
        return (fact[n] * inv[k] * inv[n - k]).get() ;
    }
};

const int MAX = 4e5 + 5 ;

combination table(MAX) ;

int NoofSequences(int N, int M) 
{ 
	map<int, int> prime; 
	for (int i = 2; i * i <= M; ++i) 
	{ 
		while (M % i == 0) 
		{ 
			prime[i]++; 
			M /= i; 
		} 
	} 
	if (M > 1) 
		prime[M] += 1; 
	modint ans = 1ll ;
	for (auto it : prime) 
		ans = ans * table.choose(N + it.second - 1, N - 1) ; 
	return ans.get(); 
} 

int main() 
{
	ios_base::sync_with_stdio(0) ;
	cin.tie(0) ;
	int n , m ;
	cin>>n>>m ;
	return cout<<NoofSequences(n, m)<<"\n" , 0; 
} 

Measured memory_bytes: 3328
import math

A,B = map(int,input().split())


ARangemin = math.ceil(A * (100/8))
BRangemin = math.ceil(B * (100/10))

ARangemax = ARangemin
BRangemax = BRangemin
while int(ARangemax * 0.08) == A:
    ARangemax = ARangemax + 1
while int(BRangemax* 0.10) == B:
    BRangemax = BRangemax + 1
ARangemax = ARangemax -1
BRangemax = BRangemax -1

if ARangemax >= BRangemin or ARangemin >= BRangemax:
    if ARangemin >= BRangemax:
        print(-1)
    else:
        if ARangemin > BRangemin:
            print(ARangemin)
        else:
            print(BRangemin)
else:
    print(-1)



Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define mk make_pair
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
string s[500];
int h,w,sum=0;
vector<int>x,y;
void del(int t1,int t2){
  vector<pair<char,pair<int,int> > >p;
  for(int i=t1;i<h;i++)if(s[i][t2]!='.'){
    p.push_back(mk(s[i][t2],mk(i,t2)));
    break;
  }
  for(int i=t1;i>=0;i--)if(s[i][t2]!='.'){
    p.push_back(mk(s[i][t2],mk(i,t2)));
    break;
  }
  for(int i=t2;i<w;i++)if(s[t1][i]!='.'){
    p.push_back(mk(s[t1][i],mk(t1,i)));
    break;
  }
  for(int i=t2;i>=0;i--)if(s[t1][i]!='.'){
    p.push_back(mk(s[t1][i],mk(t1,i)));
    break;
  }
  sort(p.begin(),p.end());
  if(p.size()>=2){
    r(i,p.size()-1){
      if(p[i].first==p[i+1].first){
        sum++;
        s[p[i].second.first][p[i].second.second]='.';
        s[p[i+1].second.first][p[i+1].second.second]='.';
      }
    }
  }
}
int main(){
  cin>>h>>w;
  r(i,h)cin>>s[i];
  r(i,h)r(j,w)if(s[i][j]!='.'){
      y.push_back(i),x.push_back(j);
      if(i+1<h)y.push_back(i+1);
      if(j+1<w)x.push_back(j+1);
    }
  r(k,4)r(i,y.size())r(j,x.size())
    if(s[y[i]][x[j]]=='.')del(y[i],x[j]);
  cout<<sum*2<<endl;
}

Measured memory_bytes: 3328
#B - Ruined Square
x1,y1,x2,y2 = map(int,input().split())

y3 = y2 + (x2-x1)
x3 = x2 - (y2-y1)
y4 = y1 + (x2-x1)
x4 = x1 - (y2-y1)
A = [x3,y3,x4,y4]
print(*A)

Measured memory_bytes: 9100
#include <iostream>
#include <vector>
#include <cassert>
#include <cmath>

using ll = long long;
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
#define MAX(a, b) (((a) < (b)) ? (b) : (a))

int const nmax = 300;
int const modulo = 998244353;
int dp[5 + nmax][5 + nmax][5 + nmax];
int pref[5 + nmax][5 + nmax][5 + nmax];

int main() {
  std::string s;
  std::cin >> s;
  int n = s.size();
  s = "0" + s + "0";
  dp[n + 1][0][0] = 1;
  for(int i = n + 1; 1 <= i; i--)
    for(int j = 0; j <= n; j++)
      for(int h = 0; h <= n; h++) {
        if(s[i - 1] == '0') {
          dp[i - 1][j][h] += dp[i][j][h];
          if(modulo <= dp[i - 1][j][h])
            dp[i - 1][j][h] -= modulo;
          dp[i][j][h + 1] += dp[i][j][h];
          if(modulo <= dp[i][j][h + 1])
            dp[i][j][h + 1] -= modulo;
        } else {
          dp[i - 1][j][h] += dp[i][j][h];
          if(modulo <= dp[i - 1][j][h])
            dp[i - 1][j][h] -= modulo;
          dp[i][j + 1][h] += dp[i][j][h];
          if(modulo <= dp[i][j + 1][h])
            dp[i][j + 1][h] -= modulo;
        }
      }
  pref[0][0][0] = 1;
  for(int i = 0;i < n; i++)
    for(int j = 0;j <= n; j++)
      for(int h = 0;h <= n; h++)
        if(0 < pref[i][j][h]) {
          if(s[i + 1] == '0' || s[i + 2] == '0')
            pref[i + 2][j + 1][h] = 1;
          if(s[i + 1] == '1' || s[i + 2] == '1')
            pref[i + 2][j][h + 1] = 1;
          pref[i + 1][j][h] = 1;
          if(s[i + 1] == '0' && 0 < h) 
            pref[i + 1][j + 1][h - 1] = 1;
          if(s[i + 1] == '1' && 0 < j)
            pref[i + 1][j - 1][h + 1] = 1;
        }
  int result = modulo - 1;
  for(int i = 1;i <= n + 1; i++)
    for(int j = 0; j <= n; j++)
      for(int h = 0; h <= n; h++) {
        result += dp[i][j][h] * pref[i - 1][j][h];
        if(modulo <= result)
          result -= modulo;
      }
  std::cout << result ;
  return 0;
}


Measured memory_bytes: 141380
n = int(input())
a = list(map(int,input().split()))
q = int(input())

import collections
ans = sum(a)
a = collections.Counter(a)

for i in range(q):
    b,c = list(map(int,input().split()))
    d = a[b]
    ans -= d*b
    a[b] = 0
    ans += d*c
    a[c] += d
    print(ans)

Measured memory_bytes: 22952
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> pii;
const double EPS = 1e-10;
const int INF = 1e9;
const ll LINF = 1e15;
const int MOD = 1000000007;
const double PI = acos(-1);
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};

int main() {
	int n;
	cin >> n;
	vector<ll> a(n), b(n);
	rep(i,n) cin >> a[i];
	rep(i,n) cin >> b[i];
	ll x = 0;
	rep(i,n) {
		if (a[i] == b[i]) continue;
		if (a[i] < b[i]) {
			ll t = (b[i] - a[i]) / 2;
			x += t;
		} else {
			ll t = a[i] - b[i];
			x -= t;
		}
	}
	if (x < 0) cout << "No" << endl;
	else cout << "Yes" << endl;
}

Measured memory_bytes: 3796
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <utility>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define _GLIBCXX_DEBUG
using namespace std;
typedef long long ll;
typedef pair<int, int> pair;
const int inf = 1000000000; //10^9

ll mon(ll h) {
    if (h == 1) return 1;

    return 2 * mon(h / 2) + 1;
}

int main(){
    ll h;
    cin >> h;

    cout << mon(h) << endl;

    return 0;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
double dp[3001][3001];
double solve(vector<double>& v, double dp[][3001], int n, int x){
    if(x==0)
        return 1;
    if(n==0)
        return 0;
    if(dp[n][x] > -1){
        return dp[n][x];
    }
    dp[n][x] = v[n]*solve(v, dp, n-1, x-1) + (1 - v[n])*solve(v, dp, n-1, x);

    return dp[n][x];
}
int main(){
    cout<<fixed<<setprecision(13);
    int n;
    cin>>n;
    vector<double> v(n+1);
    for(int i=1; i<=n; i++)
        cin>>v[i];
    memset(dp, -1, sizeof(dp));
    double ans = solve(v, dp, n, (n/2)+1);
   
    
    cout<<ans<<endl;
    
    return 0;

}

Measured memory_bytes: 74408
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <deque>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <tuple>
#include <numeric>
#include <string>
#include <bitset>
#include <functional>

using ld = long double;
using vld = std::vector<ld>;
using vvld = std::vector<vld>;
using vvvld = std::vector<vvld>;
using ll = long long;
using vll = std::vector<ll>;
using vvll = std::vector<vll>;
using vvvll = std::vector<vvll>;
using pll = std::pair<ll, ll>;
using vpll = std::vector<pll>;
using str = std::string;
using vstr = std::vector<str>;

template<typename T> bool chmin(T a, T &b) { return a < b ? b = a, true : false; }
template<typename T> bool chmax(T a, T &b) { return a > b ? b = a, true : false; }

constexpr ld PI = 3.141592653589793L;
constexpr ld EPS = std::numeric_limits<ld>::epsilon();

ll gcd(ll n, ll m) { return m ? gcd(m, n % m) : n; }
ll lcm(ll n, ll m) { return n / gcd(n, m) * m; }
bool is_prime(ll n) {
    if (n == 1) return false;
    for (ll i = 2; i * i <= n; i++)
        if (n % i == 0) return false;
    return true;
}

/*------------------------------------------------------------------------*/

void solve();

int main() {
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    std::cout << std::setprecision(15);

    solve();
}

void solve() {
    ll n, p;
    std::cin >> n >> p;

    vll a(n);
    for (ll i = 0; i < n; i++)
        std::cin >> a[i];

    ll even = 0, odd = 0;
    for (ll i = 0; i < n; i++)
        ~a[i] & 1 ? even++ : odd++;

    std::cout << (odd ? 1LL << n - 1 : !p * (1LL << n)) << '\n';
}


Measured memory_bytes: 3656
N, W = map(int, raw_input().split())
v = [0] * N
d = [0] * N
dp = [[0 for i in range(W + 1)] for j in range(N + 1)]
for i in range(N):
  v[i], d[i] = map(int, raw_input().split())
  for j in range(W + 1):
    if j < d[i]:
      dp[i + 1][j] = dp[i][j];
    else:
      dp[i + 1][j] = max(dp[i][j], dp[i][j - d[i]] + v[i])
print dp[N][W];

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

int main(int argc , char* argv[]){
	int n; cin >> n;
	vector<int> p(n+2);
	p[0]=0;p[n+1]=0;
	for(int i=0;i<n;++i) cin >> p[i];
	int counter=0;
	for(int i=1;i<n-1;++i){
		if((p[i]>p[i-1]&&p[i]<p[i+1])|| (p[i]>p[i+1]&& p[i]<p[i-1])) ++counter;
	}
	cout << counter << endl;
}
	

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

#define rep(i, n) for(int i = 0; i < n;i++)

int main()
{
    string S, T;
    cin >> S >> T;
    int ans = 0;
    rep(i, 3){
        if(S[i] == T[i]){
            ans++;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<map>
#include<cstdio>
#include<stack>
#include<queue>
#include<fstream>
#include<cstdio>
#include<deque>
#include<iomanip>
#include <numeric>
#include<tuple>
//#include<bits/stdc++.h>

using namespace std;
#define ok1 printf("ok1\n");
#define ok2 printf("ok2\n");
#define M 1000000000000000000LL
#define rep(i,n) for(int i=0;i<n;++i)
#define REP(i,s,n) for(int i=(s);i<(n);++i)
#define repr(i,n) for(int i=n-1;i>=0;--i)
#define REPR(i,s,n) for(int i=(s);i>=(n);--(i))
#define all(a) (a).begin(),(a).end()
#define reall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define pf push_front
#define MIN(a,b) a=min((a),(b))
#define MAX(a,b) a=max((a),(b))
#define SIZE(v) (int)v.size()
#define fi first
#define se second
const double pi = acos(-1.0);

typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<char> vc;
typedef vector<double> vd;
typedef vector<bool> vb;
typedef deque<ll> dll;
typedef pair<ll, ll> P;
typedef vector<P> vP;
using Edge = pair<int, ll>;
using Graph = vector<vector<Edge> >;
const ll mod = 1e9 + 7;
ll dx[4] = { 1,0,-1,0 };
ll dy[4] = { 0,1,0,-1 };

void printvll(vll v) {
	cout << "------------------------------------------------\n";
	rep(i, v.size()) cout << v[i] << " ";
	cout << endl;
	cout << "------------------------------------------------\n";
}
void printvvll(vvll v) {
	cout << "------------------------------------------------\n";
	rep(i, v.size()) {
		rep(j, v[i].size()) {
			cout << v[i][j] << " ";
		}
		cout << endl;
	}
	cout << "------------------------------------------------\n";
}

void prints(string s) {
	cout << "------------------------------------------------\n";
	rep(i, s.size()) cout << s[i] << " ";
	cout << endl;
	cout << "------------------------------------------------\n";
}

void printvs(vs s) {
	cout << "------------------------------------------------\n";
	rep(i, s.size()) {
		rep(j, s[i].size()) {
			cout << s[i][j] << " ";
		}
		cout << endl;
	}
	cout << "------------------------------------------------\n";
}

void Yes(bool x) {
	if (x) cout << "Yes\n";
	else cout << "No\n";
}

void YES(bool x) {
	if (x) cout << "YES\n";
	else cout << "NO\n";
}

void yes(bool x) {
	if (x) cout << "yes\n";
	else cout << "no\n";
}

void Yay(bool x) {
	if (x) cout << "Yay!\n";
	else cout << ":(\n";
}
ll gcd(ll x, ll y)
{
	ll r;
	while ((r = x % y) != 0)
	{
		x = y;
		y = r;
	}
	return y;
}
ll lcm(ll x, ll y)
{
	x /= gcd(x, y);
	y /= gcd(x, y);
	return (x * y);
}



ll  d, n, r, l, k, ans = 0, ret = M;
bool flag = false, flag2 = false, flag3 = false;
string s,t;
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	/*
	cin >> n >> k;
	cout << n - k + 1 << endl;*/
	ll g, b;
	cin >> r >> g >> b >> n;
	rep(i, n+1) {
		rep(j, n+1) {
			if ((n - (r*i + g * j)) < 0) break;
			//cout << i << " " << j << endl;
			//cout << (n - (r*i + g * j)) << " " ;
			if ((n - (r*i + g * j)) % b == 0) ans++;
			
			//cout << ans << endl << endl;
		}
	}
	cout << ans << endl;
	return 0;
}

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

using namespace std;

#define MOD 1000000009

int main () {
    string s; cin >> s;
    int l = s.size();


    for(int i = 0; i < l ; i++) {
        char c = s[i];

        if (c == '?') {
            if (i > 0) {
                if (s[i - 1] == 'P') {
                    cout << 'D';
                    continue;
                }
            }
            if (i != l - 1) {
                if (s[i + 1] == '?') {
                    cout << "PD";
                    i++;
                } else {
                    cout << 'D';
                }
            } else {
                cout << 'D';
            }
        } else {
            cout << c;
        }

    }

    cout << endl;
}

Measured memory_bytes: 3712
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int price = scanner.nextInt();
        int numberOf1Yen = scanner.nextInt();

        if(numberOf1Yen == 0) {
            if(price % 500 == 0) {
                System.out.println("Yes");
            } else {
                System.out.println("No");
            }
        } else if (price % numberOf1Yen == 0) {
            System.out.println("Yes");
        } else if (price % 500 > 0) {
            int left = price % 500;
            if(numberOf1Yen - left >= 0) {
                System.out.println("Yes");
            } else {
                System.out.println("No");
            }
        } else {
            System.out.println("No");
        }
    }
}


Measured memory_bytes: 23380
#include <bits/stdc++.h>
using namespace std;
#define maxn 55
#define maxm 125005
#define int long long
#define INF 1e9 + 10
int n, X, D, ans, cnt, dp[maxn][maxm];
int w[maxn], val[maxn], pos[maxn];
     
int read()
{
    int x = 0, k = 1;
    char c; c = getchar();
    while(c < '0' || c > '9') { if(c == '-') k = -1; c = getchar(); }
    while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
    return x * k;
}
     
struct edge
{
    int cnp, to[maxn], last[maxn], head[maxn];
    edge() { cnp = 1; }
    void add(int u, int v) 
    { to[cnp] = v, last[cnp] = head[u], head[u] = cnp ++; }
}E1;
     
void dfs(int u)
{
    val[u] = 1;
    for(int i = E1.head[u]; i; i = E1.last[i])
    {
    	int v = E1.to[i];
    	dfs(v);
    	w[u] += w[v]; val[u] += val[v];
    }
    cnt += val[u] * n; pos[u] = u;
}
     
bool cmp(int x, int y) { return val[x] * w[y] > val[y] * w[x]; }
void Get_min(int &x, int y) { x = x < y ? x : y; }
     
signed main()
{
    n = read(), X = read(), D = read();
    w[1] = read();
    for(int i = 2; i <= n; i ++)
    {
    	w[i] = read(); int x = read();
    	E1.add(x, i);
    }
    dfs(1);
    sort(pos + 1, pos + n + 1, cmp);
    int tmp = min(n, D);
    for(int i = 1; i <= cnt; i ++) dp[0][i] = INF;
    for(int i = 1; i <= n; i ++)
    {
    	memcpy(dp[i], dp[i - 1], sizeof(dp[i - 1]));
    	for(int j = 0; j <= cnt; j ++)
    		for(int k = 1; k <= tmp && j - k * val[i] >= 0; k ++)
    			Get_min(dp[i][j], dp[i - 1][j - k * val[i]] + k * w[i]);
    }
    int ans = 0;
    for(int i = 0; i <= cnt; i ++)
   	{
    	if(dp[n][i] > X) continue;
    	int ret = i, left = X - dp[n][i];
    	for(int j = 1; j <= n; j ++)
    	{
    		int tem = pos[j], used = min(max(D - n, 0LL), left / w[tem]);
    		if(tem == 1) used = left / w[tem];
    		left -= w[tem] * used;
    		ret += val[tem] * used;
    	}
    	ans = max(ans, ret);
    }
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 50944
#include <bits/stdc++.h>
using namespace std;
#define long long long
const int MAXN = 1e6 + 7;
const long MOD = 1e9 + 7;
const long INF = 1e15 + 7;


main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int i, j, k;

    int N; cin >> N;
    long A[N + 1], B[N];
    for (i = 0; i <= N; ++i) cin >> A[i];
    for (i = 0; i < N; ++i) cin >> B[i];

    long count = 0;
    for (i = 0; i < N; ++i) {
        int temp = min(A[i], B[i]);
        A[i] -= temp; B[i] -= temp; count += temp;

        temp = min(A[i + 1], B[i]);
        A[i + 1] -= temp; B[i] -= temp; count += temp;
    }
    cout << count;
}

Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

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

    int k = S.size();
    int lose = count(S.begin(), S.end(), 'x');
    if(lose >= 8){
        cout << "NO" << endl;
    }else{
        cout << "YES" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
from itertools import product
target = ['3','5','7']

n=int(input())
tmp=n
keta=0
while tmp!=0:
  tmp//=10
  keta+=1
check_list = []
for i in range(1,keta+1):
  tmp=[]
  for _ in range(i):
    tmp.append(target.copy())
    tmp_product = list(product(*tmp))
  check_list+=[int(''.join(nums)) for nums in tmp_product]
check_list = sorted(check_list)

cnt=0
for i in check_list:
  if i <= n:
    tmp = set([w for w in str(i)])
    if len(tmp)==3:
      cnt+=1
  else:
    break
print(cnt)


Measured memory_bytes: 13592
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int a,b;
    int i;
    int ans=0;
    cin>>a>>b;
    if(b==1){
        cout<<0;
        return 0;
    }
    for(i=0; ans<b;i++){
     ans=a+(a-1)*i;   
    }
    cout<<i;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
typedef long long ll;

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    string s,t; cin >> s >> t;
    bool ok=1;
    for(int i=0;i<s.size();i++){
        if(s[i]!=t[i]){
            ok=0;
        }
    }
    if(ok){
        printf("Yes\n");
    }else{
        printf("No\n");
    }
}

Measured memory_bytes: 3648
n,x,y = list(map(int,input().split()))
x,y = x-1,y-1
d=[0]*(n)
for i in range(n-1):
  for j in range(i+1,n):
    m = min(j-i,abs(i-x)+1+abs(j-y)) 
    d[m]+=1

print(*d[1:],sep="\n")

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

using namespace std;
using ll = long long;

template< typename flow_t, typename cost_t >
struct PrimalDual {
  const cost_t INF;

  struct edge {
    int to;
    flow_t cap;
    cost_t cost;
    int rev;
    bool isrev;
  };
  vector< vector< edge > > graph;
  vector< cost_t > potential, min_cost;
  vector< int > prevv, preve;

  PrimalDual(int V) : graph(V), INF(numeric_limits< cost_t >::max()) {}

  void add_edge(int from, int to, flow_t cap, cost_t cost) {
    graph[from].emplace_back((edge) {to, cap, cost, (int) graph[to].size(), false});
    graph[to].emplace_back((edge) {from, 0, -cost, (int) graph[from].size() - 1, true});
  }

  cost_t min_cost_flow(int s, int t, flow_t f) {
    int V = (int) graph.size();
    cost_t ret = 0;
    using Pi = pair< cost_t, int >;
    priority_queue< Pi, vector< Pi >, greater< Pi > > que;
    potential.assign(V, 0);
    preve.assign(V, -1);
    prevv.assign(V, -1);

    while(f > 0) {
      min_cost.assign(V, INF);
      que.emplace(0, s);
      min_cost[s] = 0;
      while(!que.empty()) {
        Pi p = que.top();
        que.pop();
        if(min_cost[p.second] < p.first) continue;
        for(int i = 0; i < graph[p.second].size(); i++) {
          edge &e = graph[p.second][i];
          cost_t nextCost = min_cost[p.second] + e.cost + potential[p.second] - potential[e.to];
          if(e.cap > 0 && min_cost[e.to] > nextCost) {
            min_cost[e.to] = nextCost;
            prevv[e.to] = p.second, preve[e.to] = i;
            que.emplace(min_cost[e.to], e.to);
          }
        }
      }
      if(min_cost[t] == INF) return -1;
      for(int v = 0; v < V; v++) potential[v] += min_cost[v];
      flow_t addflow = f;
      for(int v = t; v != s; v = prevv[v]) {
        addflow = min(addflow, graph[prevv[v]][preve[v]].cap);
      }
      f -= addflow;
      ret += addflow * potential[t];
      for(int v = t; v != s; v = prevv[v]) {
        edge &e = graph[prevv[v]][preve[v]];
        e.cap -= addflow;
        graph[v][e.rev].cap += addflow;
      }
    }
    return ret;
  }

  void output() {
    for(int i = 0; i < graph.size(); i++) {
      for(auto &e : graph[i]) {
        if(e.isrev) continue;
        auto &rev_e = graph[e.to][e.rev];
        cout << i << "->" << e.to << " (flow: " << rev_e.cap << "/" << rev_e.cap + e.cap << ")" << endl;
      }
    }
  }
};

const vector<vector<int>> dir4 = {{0, 1}, {1, 0}};
int h, w, k = 0;
int id(int i, int j) {return i * w + j;}


int main()
{
	cin >> h >> w;
	vector<string> g(h);
	for(int i = 0; i < h; i++)cin >> g[i];
	int S = h * w, T = h * w + 1;
	PrimalDual<int,int> flow(h * w + 2);
	for(auto i : g)k += count(i.begin(), i.end(), 'o');

	for(int i = 0; i < h; i++) {
		for(int j = 0; j < w; j++) {
			if(g[i][j] == '#')continue;
			int u = id(i, j), v;
			for(auto d: dir4) {
				int ny = i + d[0], nx = j + d[1];
				if(ny < 0 || ny >= h || nx < 0 || nx >= w || g[ny][nx] == '#')continue;
				v = id(ny, nx);
				flow.add_edge(u, v, k, -1);
			}
			flow.add_edge(u, T, 1, 0);
			if(g[i][j] == 'o')flow.add_edge(S, u, 1, 0);
		}
	}

	cout << -flow.min_cost_flow(S, T, k) << endl;

}

Measured memory_bytes: 4164
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

typedef enum { top, south, east, west, north, bottom, NUM_SIDES } sides;

int checkDice(const int dice0[], const int dice1[])
{
    int i, flag = 1;

    for( i = 0; i < NUM_SIDES && flag; ++i )
        if( dice0[i] != dice1[i] )
            flag = 0;

    return flag;
}

sides getOperator()
{
    return rand() % north + 1;
}

void roll(int *dice, const sides operator)
{
    int anti_op;
    switch( operator ){
    case south: anti_op = north; break;
    case east: anti_op = west; break;
    case west: anti_op = east; break;
    case north: anti_op = south; break;
    default: break;
    }

    int tmp = dice[operator];
    dice[operator] = dice[top];
    dice[top] = dice[anti_op];
    dice[anti_op] = dice[bottom];
    dice[bottom] = tmp;
}

int main()
{
    int i;

    srand(time(0));

    int dice0[NUM_SIDES], dice1[NUM_SIDES];
    for( i = 0; i < NUM_SIDES; ++i )
        scanf("%d", &dice0[i]);
    for( i = 0; i < NUM_SIDES; ++i )
        scanf("%d", &dice1[i]);

    sides operator = getOperator();
    while( dice0[top] != dice1[top] || dice0[south] != dice1[south] ){
        roll(dice1, operator);
        operator = getOperator();
    }

    if( checkDice(dice0, dice1) ) printf("Yes\n");
    else printf("No\n");

    return 0;
}

Measured memory_bytes: 580
N, M = map(int, input().split())
iPYx = []
for i in range(M):
  P, Y = map(int, input().split())
  iPYx.append([i, P, Y])

iPYx.sort(key = lambda x: (x[1], x[2]))
cnt = 0
for i in range(M):
  if i == 0 or iPYx[i][1] != iPYx[i - 1][1]:
    cnt = 1
  else:
    cnt += 1
  iPYx[i].append(cnt)
iPYx.sort(key = lambda x: x[0])
for i in range(M):
  print("{:06}{:06}".format(iPYx[i][1], iPYx[i][3]))

Measured memory_bytes: 35504
#include <iostream>
#include <cstdlib>

using namespace std;

int n;

void solve()
{
	int N = n;
	int t = 0;
	while (n) {
		t += n % 10;
		n /= 10;
	}
	if (N % t) cout << "No\n";
	else cout << "Yes\n";
}


int main()
{
	cin >> n;
	solve();
	return 0;
}

Measured memory_bytes: 256
h, w = map(int, input().split())
x = [0]*h
for i in range(h):
  x[i] = input()

for i in range(w+1):
  print('#', end='')
print('#')
for i in range(h):
  print('#' + x[i] + '#')

for i in range(w+2):
  print('#', end='')

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
int in(){int x; scanf("%d",&x); return x;}
static const int MAX = 100;


int main(){
  int N = in(), count = 0, ans = 1;
  string S; cin >> S;


  rep(i, N-1){
    if(S[i] == S[i+1]) continue;
    ans++;
  }
  
  cout << ans << endl;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define o(a) cout << a << endl
#define int long long
#define fi first
#define se second
using namespace std;
typedef pair<int, int> P;

signed main(){
    int n;
    cin >> n;
    vector<int> a(n);
    int ans = 0;
    rep(i, 0, n){
        cin >> a[i];
    }
    a. push_back(0);
    int now = 0;
    rep(i, 0, n + 1){
        if(a[i] == 0){
            ans += now / 2;
            now = 0;
        }else{
            now += a[i];
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 1792