akhauriyash/Code-Regression huggingface dataset:
//#pragma GCC optimize ("O3")
//#pragma GCC target ("tune=native")
//#pragma GCC target ("avx")
//#include <bits/stdc++.h>
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <sstream>
#include <functional>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <list>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<P,ll> PPI;
typedef pair<ll,P> PIP;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<P> vp;
#define PQ(T) priority_queue<T,vector<T>,greater<T>>
#define PQ2(T) priority_queue<T>
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1LL<<29;
const ll mod = 1e9+7;
#define REP(i,a,b) for(ll (i)=a;(i)<(ll)(b);++(i))
#define rep(i,n) REP(i,0,n)
#define rep1(i,n) REP(i,1,n+1)
#define repd(i,n,d) for(ll (i)=0;(i)<(ll)(n);(i)+=(d))
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset((m),(v),sizeof(m))
#define chmin(x,y) ((x)=min((x),(y)))
#define chmax(x,y) ((x)=max((x),(y)))
#define fst first
#define snd second
#define UNIQUE(x) (x).erase(unique(all(x)),(x).end())
#define DEBUG(x) cerr<<"line ("<<__LINE__<<")  "<<#x<<": "<<x<<endl;
template<class T> ostream &operator<<(ostream &os, const vector<T> &v){int n=v.size();rep(i,n)os<<v[i]<<(i==n-1?"":" ");return os;}
#define INIT std::ios::sync_with_stdio(false);std::cin.tie(0);


int main(){
	INIT;
	ll n;
	cin>>n;
	vector<ll> a(n), b(n);
	rep(i, n) cin>>a[i];
	rep(i, n) cin>>b[i];
	ll x = 0;
	for(ll i = 30; i >= 0; i--){
		ll mask = (1LL<<(i+1))-1;
		rep(j, n){
			a[j] &= mask;
			b[j] &= mask;
		}
		sort(all(a));
		sort(all(b));
		//cerr<<i<<endl;
		rep(j, a.size()){
			ll lb = (1LL<<i)-a[j];
			if(lb<0) lb += (1LL<<(i+1));
			ll ub = lb^(1<<i), t = 1;
			if(lb>ub){
				swap(lb, ub);
				t ^= n%2;
			}
			ll cnt = lower_bound(all(b), ub)-lower_bound(all(b), lb);
			if(cnt%2==t) x ^= 1<<i;
			if(i<=2){
				//cerr<<j<<" "<<a[j]<<" "<<lb<<" "<<ub<<" "<<t<<" "<<cnt<<endl;
			}
		}
	}
	cout<<x<<endl;
	return 0;
}


Measured memory_bytes: 3456
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define mod 1000000007
#define lim 1000000000000000007
#define lim1 18446744073709551615  //Unsigned
#define sq(a) ((a)*(a))
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define mms(v,i) memset(v,i,sizeof(v))
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define REP(i,a,b) for (int i = a; i <= b; i++)
#define REPN(i,a,b) for (int i = a; i >= b; i--)
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<int,int> pi;
typedef pair<ll,ll> PL;
typedef pair<ll,int> PLI;
typedef pair<int,ll> PIL;
typedef pair<int,pair<int,int> > pii;
typedef pair<double,double> pdd;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
ll power(ll a,ll b) {
    if (b==0) return 1;
    ll c = power(a,b>>1);
    c = (c*c)%mod;
    if (b&1) return (c*a)%mod;
    return c;
}
ll gcdll(ll a,ll b) {
    if (b==0) return a;
    return gcdll(b,a%b);
}
int gcd(int a,int b) {
    if (b==0) return a;
    return gcd(b,a%b);
}

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

const int N = (int)3e5+5;
const int Q = 301;

int cnt[10][10];
pi get(int n) {
    pi ret = {0,n%10};
    while (n>0) {
        ret.first = n%10;
        n /= 10;
    }
    return ret;
}
void solve() {
	int n,p;
	cin>>n;
	ll ans = 0;
	REP(i,1,n) {
        pi f = get(i);
        cnt[f.first][f.second]++;
	}
	REP(i,1,n) {
        pi f = get(i);
        ans += cnt[f.second][f.first];
	}
	cout<<ans;
}
int main() {
    //freopen("output.txt","r",stdin);
    //freopen("output.txt","w",stdout);

    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int T=1;
    //cin>>T;
    REP(TC,1,T) {
        //cout<<"Case #"<<TC<<": ";
        solve();
        //cout<<"\n";
    }
}


Measured memory_bytes: 256
n,w = map(int, input().split())
wvList = [list(map(int, input().split())) for i in range(n)]
dp = [[0]*(w+1) for i in range(n+1)]
for i in range(n):
    for j in range(w+1):
        if j - wvList[i][0] >= 0:
            dp[i+1][j] = max(dp[i][j], dp[i+1][j], dp[i][j-wvList[i][0]]+wvList[i][1])
        else:
            dp[i+1][j] = max(dp[i+1][j], dp[i][j])
print(dp[n][w])


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

using namespace std;

#define all(x) (x).begin(), (x).end()
typedef long double ld;
typedef long long ll;


int main() {
#ifdef LOCAL
  assert(freopen("a.in", "r", stdin));
#endif

  ios_base::sync_with_stdio(false);

  string s;
  cin >> s;
  ll ans = 0;
  reverse(all(s));

  int x = 0;
  for (char c : s) {
    if (c == 'W')
      ++x;
    else
      ans += x;
  }

  cout << ans << "\n";

}



Measured memory_bytes: 720
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;

int main(){
    ios::sync_with_stdio(false);
    string t;
    cin>>t;
    reverse(t.begin(),t.end());
    ll n=t.length(),c=0;
    if(n==1){
        cout<<t[0]-'0';
        return 0;
    }
    for(int i=0;i<(1<<n-1);i++){
        ll tmp=1;
        c+=t[0]-'0';
        for(int j=0;j<n-1;j++){
            if(i&(1<<j)) tmp=1;
            else tmp*=10;
            c+=tmp*(t[j+1]-'0');
        }
        tmp=1;
    }
    cout<<c<<endl;
    return 0;
}

Measured memory_bytes: 256
def main():
    H, W, K = map(int, input().split(" "))
    c = [[c for c in input()] for _ in range(H)]
    cnt = 0
    ans = 0
    for i in range(1 << H):
        for j in range(1 << W):
            cnt = 0
            for ii in range(H):
                for jj in range(W):
                    if(i >> ii & 1):
                        continue
                    if(j >> jj & 1):
                        continue
                    if(c[ii][jj] == '#'):
                        cnt += 1
            if cnt == K :
                ans += 1
    print(ans)
    
    

if __name__ == "__main__":
    main()

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

#define X first
#define Y second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define rep(i, a, b) for (long i = (a); i <= (b); ++i)
#define per(i, a, b) for (long i = (a); i >= (b); --i)

using namespace std;

using I = int;
using L = long;
using F = float;
using S = string;
using SS = stringstream;
using C = char;
using LL = long long;
using VI = vector<int>;
using VL = vector<long>;
using VF = vector<float>;
using VS = vector<string>;
using VVI = vector<vector<int>>;
using VVL = vector<vector<long>>;
using PLL = pair<long, long>;
using PLF = pair<long, float>;
using PLS = pair<long, string>;
using PSL = pair<string, long>;
using PSF = pair<string, float>;
using PSS = pair<string, string>;
using MLL = map<long, long>;
using MLF = map<long, float>;
using MLS = map<long, string>;
using MSL = map<string, long>;
using MSF = map<string, float>;
using MSS = map<string, string>;

const long kMax2 = 109;
const long kMax3 = 1009;
const long kMax4 = 10009;
const long kMax5 = 100009;
const long kMax6 = 1000009;
const long kInfI = 0x3F3F3F3F;
const float kInfF = 1e15;

template <class T>
void PrintVector(const vector<T> & v) {
  for (const auto & e: v) {
    cout << e << endl;
  }
}

template <class T>
void PrintVector(const vector<T> & v, unsigned n) {
  rep(i, 0, n - 1) {
    cout << v[i] << endl;
  }
}

int main(int argc, char const *argv[]) {
  int n;
  int t0 = 0, x0 = 0, y0 = 0, t1, x1, y1;
  cin >> n;
  rep(i, 1, n) {
    scanf("%d %d %d", &t1, &x1, &y1);
    auto dif_t = int(fabs(t1 - t0));
    auto dif_s = int(fabs(x1 - x0) + (y1 - y0));
    if (dif_t < dif_s || ((dif_t - dif_s) % 2 != 0)) {
      printf("No\n");
      return 0;
    }
    t0 = t1;
    x0 = x1;
    y0 = y1;
  }
  printf("Yes\n");

  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define repi(i,a,b) for(int i = (a);i < (b); i++)
#define rep(i,a) repi(i,0,a)
#define repd(i,a,b) for(int i = (a); i >= (b); i--)
#define repit(i,a) for(__typeof((a).begin()) i = (a).begin(); i != (a).end(); i++)

#define all(u) (u).begin(),(u).end()
#define rall(u) (u).rbegin(),(u).rend()
#define UNIQUE(u) (u).erase(unique(all(u)),(u).end())

#define pb push_back
#define mp make_pair
#define INF 1e9
#define EPS 1e-9
#define PI acos(-1.0)

using namespace std;

typedef long long ll;
typedef vector<int> vi;

ll champer(ll n)
{
  ll ret = 0;
  for (ll d = 1; d <= n; d *= 10)
    ret += n - d + 1;
  return ret;
}

string solve(ll n, ll k)
{
  ll l = 0, r = (int) 1e9;
  while (l + 1 < r) {
    ll m = (l + r) / 2;
    if (champer(m) < n)
      l = m;
    else
      r = m;
  }
  int offset = n - champer(r - 1) - 1;
  ostringstream ret;
  for (ll i = r; ret.str().length() < k + offset; ++i)
    ret << i;
  return ret.str().substr(offset, k);
}

int main()
{
  ll n, k;
  while (cin >> n >> k && n)
    cout << solve(n, k) << endl;

  return 0;
}

Measured memory_bytes: 1220
#include <algorithm>
#include <climits>
#include <cmath>
#include <iostream>
#include <set>
#include <string>
#include <utility>
#include <vector>
#define ll long long int
int main(void) {
  int n;
  std::cin >> n;
  std::vector<int> v(n + 1, 0);
  std::vector<int> vv;
  for (int i = 1; std::pow(6, i) <= n; i++) {
    vv.push_back(std::pow(6, i));
  }
  for (int i = 1; std::pow(9, i) <= n; i++) {
    vv.push_back(std::pow(9, i));
  }
  vv.push_back(1);
  for (int i = 1; i <= n; i++) {
    int x = 100000;
    for (auto it = vv.begin(); it != vv.end(); it++) {
      if (i - *it >= 0) {
        x = std::min(x, v[i - *it] + 1);
      }
    }
    v[i] = x;
  }
  std::cout << v[n] << std::endl;
  return 0;
}


Measured memory_bytes: 1016
#include <bits/stdc++.h>
int main()
{
    using namespace std;
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int spot_num;
    cin >> spot_num;
    vector<int> spot(spot_num);
    istream_iterator<int> read_int(cin);
    std::copy_n(read_int, spot_num, spot.begin());

    spot.insert(spot.cbegin(), 0);
    spot.push_back(0);

    int sum = 0;
    for (int i = 1; i <= spot_num + 1; ++i)
    {
        sum += abs(spot.at(i - 1) - spot.at(i));
    }

    for (int i = 1; i <= spot_num; ++i)
    {
        int a = spot.at(i - 1);
        int b = spot.at(i);
        int c = spot.at(i + 1);

        if (!((a <= b && b <= c) || (a >= b && b >= c)))
        {
            if (abs(b - c) > abs(b - a))
                swap(a, c);
            cout << sum - (abs(b - c) << 1) << "\n";
        }
        else
            cout << sum << "\n";
    }
    return 0;
}


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

typedef long long int LL;
typedef long long int LLint;
typedef pair<int,int> intpair;
typedef pair<bool,bool> boolpair;
typedef pair<string,string> strpair;
typedef pair<LL,LL> LLpair;
typedef pair<double,double> doublepair;
typedef pair<float,float> floatpair;
typedef vector<int> intvector;
typedef vector<bool> boolvector;
typedef vector<string> strvector;
typedef vector<LL> LLvector;
typedef vector<double> doublevector;
typedef vector<float> floatvector;
#define wait(sec) usleep((sec) * 1000000)
#define ED return 0;
#define TEST cout << "OK" << endl;
#define UP(a,b) ((a+(b-1))/b)
#define SORT(vec) sort(vec.begin(),vec.end());
#define DOUBLECHANGE(count) cout << setprecision(count);
#define REV(vec) reverse(vec.begin(),vec.end());
#define ipow(x,y) LL(pow(x,y))
#define INF 999999999
const long long mod = 1000000007;

int main(){
//    random_device rnd;
//    mt19937 mt(rnd());
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    if(N > 999){
        cout << "ABD" << endl;
    }
    else{
        cout << "ABC" << endl;
    }
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        String s = sc.nextLine();

        char[] chars = s.toCharArray();

        int sum = 0;
        for (int i = 0; i <chars.length; i++) {
            sum += Character.getNumericValue(chars[i]);
        }

        if (sum % 9 == 0) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }



    }
}

Measured memory_bytes: 42248
#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;
using P = pair<int, int>;
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() {

    ll n, a[5];
    cin >> n >> a[0] >> a[1] >> a[2] >> a[3] >> a[4];

    ll m = 1e16;
    rep(i, 5){
        chmin(m, a[i]);
    }

    ll time = n / m + 4;
    if(n % m != 0){
        time++;
    }
    
    cout << time << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
#define dbg(x) cerr << #x << " = " << x << endl
#define _ << ' ' <<
using namespace std;
using ll = long long;
using vi = vector<int>;


int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s;
    cin >> s;
    sort(all(s));
    if (s[0] != s[1] || s[2] != s[3] || s[1] == s[2])
        cout << "No";
    else
        cout << "Yes";
}


Measured memory_bytes: 764
#include <vector>
#include <cstdio>
#include <climits>

class Node{
public:
	Node *parent;
	std::vector<Node*> child;
	int prenum, low;
	bool art;
	Node():parent(this), child(), prenum(-1), low(), art(false){};
	int dfs(int &num){
		prenum = low = num;
		int suspect = INT_MAX;
		for(auto c : child){
			if (c->prenum >= 0){
				suspect = c->prenum;
			}else{
				c->parent = this;
				suspect = c->dfs(++num);
				if (prenum <= suspect){
					art = true;
				}
			}
			if (low > suspect){
				low = suspect;
			}
		}
		return low;
	}
	void search(){
		prenum = 0;
		low = 0;
		int num = 0;
		for(auto c : child){
			if (c->prenum < 0){
				++low;
				c->parent = this;
				c->dfs(++num);
			}
		}
		if (low > 1){
			art = true;
		}
	}
	bool is_art(){
		return (art);
	}
};
int main(){
	int v, e;
	std::scanf("%d %d", &v, &e);
	std::vector<Node> node(v);
	for(auto i = 0; i < e; ++i){
		int s, t;
		std::scanf("%d %d", &s, &t);
		node.at(s).child.push_back(&node.at(t));
		node.at(t).child.push_back(&node.at(s));
	}
	node.at(0).search();
	for(auto i = 0; i < v; ++i){
		if (node.at(i).is_art()){
			std::printf("%d\n", i);
		}
	}
}

Measured memory_bytes: 3008
#include <iostream>
#include <vector>

using namespace std;

#define debug(x) cout << #x << "==" << x << endl;

const int inf = 100000000;

typedef long long ll;

int main() {
  ios::sync_with_stdio(false);

  int A, B, C, D;
  cin >> A >> B >> C >> D;

  int s1 = A * B;
  int s2 = C * D;
  if( s1 <= s2 ) {
    cout << s2 << "\n";
  } else {
    cout << s1 << "\n";
  }

  return 0;
}


Measured memory_bytes: 764
n,m = map(int, input().split())
a = list(map(int, input().split()))
a.sort()

cb = []
for i in range(m):
    b, c = map(int, input().split())
    cb.append([c, b])
cb = list(reversed(sorted(cb)))

c, b = 0, 0
for i in range(n):
    if b <= 0:
        if len(cb) == 0:
            break
        c, b = cb.pop(0)
    if c <= a[i]:
        break
    a[i] = c
    b -= 1
print(sum(a))


Measured memory_bytes: 25548
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		 Scanner sc = new Scanner(System.in);
		 int N=sc.nextInt();
		 int K=sc.nextInt();
		 int d[]=new int[K];
		 int A[][]=new int[K][N];
		 for(int i=0;i<K;i++) {
			 d[i]=sc.nextInt();
			 for(int count=0;count<d[i];count++) {
				 A[i][count]=sc.nextInt();
			 }
		 }
		 boolean student[]=new boolean[N];
		 for(int i=0;i<N;i++)
			 student[i]=false;
		 for(int i=0;i<K;i++) {
			 for(int count=0;count<N;count++) {
				 if(A[i][count]==0) {}
				 else if(student[A[i][count]-1]==false) 
						student[A[i][count]-1]=true;
			 }
		 }
		 int num=0;
		 for(int i=0;i<N;i++) {
			 if(student[i]==false)
				 num++;
		 }
	     System.out.println(num);
	     sc.close();
	 }
}

Measured memory_bytes: 46040
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String s = sc.next();
    int cnt = 0;
    for(int i = 0;i < 6;i++)if(s.charAt(i)=='1')cnt++;
    System.out.println(cnt);
  }
}

Measured memory_bytes: 23764
s = list(input())
a,b = "",""
f1,f2 = False,False
for i in range(2):
    a += s[i]
    b += s[i+2]
if 0<int(a)<13:
    f1 = True
if 0<int(b)<13:
    f2 = True
if f1 and f2:
    print("AMBIGUOUS")
elif f1:
    print("MMYY")
elif f2:
    print("YYMM")
else:
    print("NA")

Measured memory_bytes: 3064
#include<cstdio>
#include<algorithm>
using namespace std;

const int INF = 1000000000;

int main(){
	int ans[1000000];
	int bns[1000000];
	for(int i=0;i<1000000;i++){
		if(i==0){
			ans[i] = 0;
			bns[i] = 0;
			continue;
		}
		ans[i] = INF;
		bns[i] = INF;
		for(int j=0;i-j*(j+1)*(j+2)/6>=0&&j<200;j++){
			ans[i] = min(ans[i],ans[i-j*(j+1)*(j+2)/6]+1);
			if(j*(j+1)*(j+2)/6%2==1) bns[i] = min(bns[i],bns[i-j*(j+1)*(j+2)/6]+1);
		}
	}
	while(true){
		int n;
		scanf("%d",&n);
		if(n==0) break;
		else printf("%d %d\n",ans[n],bns[n]);
	}
	return 0;
}

Measured memory_bytes: 10436
#include<bits/stdc++.h>
using namespace std; 
typedef long long ll;
#define pb push_back
#define fi first
#define se second
const ll mod = 1e9+7;
const int N = 1e5+6;
void solve(){
	string s; 
	cin>>s; 
	int ans = 0;
	int n= s.size();
	for(int i=1;i<n;i++){
		if(s[i]!=s[i-1])ans++;
	}
	cout<<ans<<endl;
}
int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int t=1; 
//	cin>>t; 
	while(t--){
		solve();
	}
	return 0;
}


Measured memory_bytes: 3756
#include <stdio.h>
#include<stdio.h>
#include<iostream> 
#include<string>
#include<vector>
using namespace std;
int main()
{
	int n,m,t=0,y=0;
	cin>>n;
	cin>>m;
int a[n][m]={0},x[m]={0};
	for(int i=0;i<n;i++){
		int k;
		cin>>k;
		for(int j=0;j<k;j++){
			cin>>a[i][j];
			y=a[i][j]-1;
			x[y]=x[y]+1;
		}
	}
	
	for(int i=0;i<m;i++){

	if(x[i] == n){t++;}
    }
    printf("%d",t);
	
	
	return 0;
}


Measured memory_bytes: 256
public class Main {
  private static void solve() {
    char[] a = ns();
    int n = a.length;

    int[][] sum = new int[26][n + 1];

    for (int i = 1; i <= n; i++) {
      int c = a[i - 1] - 'a';
      for (int j = 0; j < 26; j++) {
        if (c == j) {
          sum[j][i] = sum[j][i - 1] + 1;
        } else {
          sum[j][i] = sum[j][i - 1];
        }
      }
    }

    long count = 0;
    for (int i = 0; i < n; i++) {
      int c = a[i] - 'a';
      count += (n - i) - (sum[c][n] - sum[c][i]);
    }
    out.println(count + 1);
  }

  public static void main(String[] args) {
    new Thread(null, new Runnable() {
      @Override
      public void run() {
        long start = System.currentTimeMillis();
        String debug = System.getProperty("debug");
        if (debug != null) {
          try {
            is = java.nio.file.Files.newInputStream(java.nio.file.Paths.get(debug));
          } catch (Exception e) {
            throw new RuntimeException(e);
          }
        }
        reader = new java.io.BufferedReader(new java.io.InputStreamReader(is), 32768);
        solve();
        out.flush();
        tr((System.currentTimeMillis() - start) + "ms");
      }
    }, "", 64000000).start();
  }

  private static java.io.InputStream is = System.in;
  private static java.io.PrintWriter out = new java.io.PrintWriter(System.out);
  private static java.util.StringTokenizer tokenizer = null;
  private static java.io.BufferedReader reader;

  public static String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }

  private static double nd() {
    return Double.parseDouble(next());
  }

  private static long nl() {
    return Long.parseLong(next());
  }

  private static int[] na(int n) {
    int[] a = new int[n];
    for (int i = 0; i < n; i++)
      a[i] = ni();
    return a;
  }

  private static char[] ns() {
    return next().toCharArray();
  }

  private static long[] nal(int n) {
    long[] a = new long[n];
    for (int i = 0; i < n; i++)
      a[i] = ni();
    return a;
  }

  private static int[][] ntable(int n, int m) {
    int[][] table = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[i][j] = ni();
      }
    }
    return table;
  }

  private static int[][] nlist(int n, int m) {
    int[][] table = new int[m][n];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[j][i] = ni();
      }
    }
    return table;
  }

  private static int ni() {
    return Integer.parseInt(next());
  }

  private static void tr(Object... o) {
    if (is != System.in)
      System.out.println(java.util.Arrays.deepToString(o));
  }
}




Measured memory_bytes: 52052
#include<bits/stdc++.h>
#define forinc(i,a,b) for(int i=a;i<=b;i++)
#define fordec(i,a,b) for(int i=a;i>=b;i--)
#define in ({int x=0;int c=getchar(),n=0;for(;!isdigit(c);c=getchar()) n=(c=='-');for(;isdigit(c);c=getchar()) x=x*10+c-'0';n?-x:x;})
#define mod 1000000007
#define st first
#define nd second
#define mid (l+r)/2
#define int long long
#define bit(x,i) ((x>>(i))&1)
#define batbit(x,i) (x|(1<<(i)))
#define tatbit(x,i) (x&~(1<<(i)))
#define pii pair<int,int>
#define pb push_back
using namespace std;
int const N=3e5+29;
int n;
int id[N];
struct bts
{
    int u,v,c;
};
struct bts1
{
     int st,nd,idd;
};
bts e[N];
bts1 a[N];
bool cmp1(bts u,bts v)
{
    return (u.c<v.c);
}
bool ss1(bts1 u,bts1 v)
{
    return (u.nd<v.nd);
}
bool ss2(bts1 u,bts1 v)
{
    return (u.st<v.st);
}
int goc(int u)
{
     return (id[u]<0 ? u: id[u]=goc(id[u]) );
}
void noi(int u,int v)
{
     if((u=goc(u))==(v=goc(v))) return;
     if(id[u]>id[v]) swap(u,v);
     id[u]+=id[v];
     id[v]=u;
}
main()
{
    ios_base::sync_with_stdio(false);
   // freopen("cpp.inp","r",stdin);
    cin >> n;
    memset(id,-1,sizeof id);
    forinc(i,1,n) cin >> a[i].st >> a[i].nd,a[i].idd=i;
    sort(a+1,a+n+1,ss1);
    int cnt=0;
    forinc(i,1,n-1)
    {
        e[++cnt]={a[i].idd,a[i+1].idd,min(abs(a[i].st-a[i+1].st),abs(a[i].nd-a[i+1].nd))};
    }
    sort(a+1,a+n+1,ss2);
    forinc(i,1,n-1)
    {
        e[++cnt]={a[i].idd,a[i+1].idd,min(abs(a[i].st-a[i+1].st),abs(a[i].nd-a[i+1].nd))};

    }
    int res=0;
    sort(e+1,e+cnt+1,cmp1);
    forinc(i,1,cnt)
    {
         int u=e[i].u;
         int v=e[i].v;
         int c=e[i].c;
         if(goc(u)!=goc(v))
         {
             noi(u,v);
             res+=c;
         }
    }
    cout<<res;
}


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

using namespace std;

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

    int a, b;
    cin >> a >> b;
    string s;
    cin >> s;
    bool ok = true;
    for(int i = 0; i < a + b + 1; i++)
    {
        if(i == a)
        {
            if(s[i] != '-')
            {
                ok = false;
                break;
            }
        }
        else if(!(s[i] - '0' >= 0 && s[i] - '0' <= 9))
        {
            ok = false;
            break;
        }
    }
    cout << (ok ? "Yes" : "No");

    return 0;
}


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

using namespace std;
using ll=long long;

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

int main(){
  cin.tie(nullptr);ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  int n,k,x,y;
  cin>>n>>k>>x>>y;
  n<=k ? cout<<n*x<<endl : cout<<k*x+(n-k)*y<<endl;
}

Measured memory_bytes: 256
import sys

#sys.stdin = open('b_2.txt', 'r')
in_str = list(raw_input())
out_str = ['X' for _ in range(10)]
cur_pos = 0

for x in in_str:
	if x != 'B':
		out_str[cur_pos] = x
		cur_pos = cur_pos + 1
	else:
		if cur_pos > 0:
			cur_pos = cur_pos - 1
		else:
			pass

print str(''.join(out_str[:cur_pos]))


Measured memory_bytes: 2568
N,x = gets.split.map(&:to_i)
A = gets.split.map(&:to_i)
A.sort!
num = 0
A.each do |a|
    if a <= x then
        x -= a
        num += 1
    else
        x -= a
        break
    end
end
num -=1 if x > 0
puts num

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

/**
 * vector<int>ar(3);
 * for(auto&e:ar){
 *     scanf("%d",&e);
 * }
 * sort(ar.begin(),ar.end())
 * int sum=accumulate(ar.begin(),ar.end(),0);
 ***/

int main(){
    double pai=3.141592653589;
    char chk[10], t[1000];
    int ans=0;
    string ask,tmp;
    scanf("%s",&chk);
    ask=chk;
    transform(ask.begin(),ask.end(),ask.begin(),::toupper);
    for(;;){
        scanf("%s",&t);
        tmp=t;
        if(tmp=="END_OF_TEXT") break;
        transform(tmp.begin(),tmp.end(),tmp.begin(),::toupper);
        if(tmp==ask){
            ans++;
        }
    }
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 1196
# n, m, l = map(int, input().split())

# list_n = list(map(int, input().split()))

# n = input()
# list = [input() for i in range(N)

# list = [[i for i in range(N)] for _ in range(M)]

import sys
input = sys.stdin.readline

N, M, X = map(int, input().split())
list_A = list(map(int, input().split()))
l = 0
r = 0

for A in list_A:
    if A < X:
        l += 1
    else:
        r += 1

print(min(l, r))


Measured memory_bytes: 9012
#include<stdio.h>
#include<stdlib.h>
 
int main(void)
{
  int a, b, c, d, ab, bc, ca;
 
  scanf("%d",&a);
  scanf("%d",&b);
  scanf("%d",&c);
  scanf("%d",&d);
 
  ab = abs(a - b);
  bc = abs(b - c);
  ca = abs(c - a);
 
  if((ab <= d && bc <= d) || ca <= d){
    printf("Yes");
  }
  else{
    printf("No");
  }
 
  return 0;
 
}

Measured memory_bytes: 128
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<vector>
#include<queue>
#include<cmath>
#include<cctype>
#include<cstdlib>
#include<climits>
using namespace std;
const int oo=0x3f3f3f3f,maxn=200010,maxlog=19;
int f[2][maxlog][maxn],val[maxn],n;
struct Pair{
	int a,b;
	Pair(){}
	Pair(int x,int y):a(x),b(y){}
};
vector<Pair>p;
vector<int>to[maxn];
struct cmp{inline bool operator () (int x,int y) {return val[p[x].a]>val[p[y].a];}};
priority_queue<int,vector<int>,cmp>q;
inline int getmin(int x,int y){return val[x]<val[y]?x:y;}
inline int query(int o,int l,int r) {
	int k=log2(r-l+1);
	return getmin(f[o][k][l],f[o][k][r-(1<<k)+1]);
}
inline int dfs(int o,int l,int r) {
//	cout<<"Begin DFS :"<<o<<" "<<l<<" "<<r<<endl;
	if(l>=r)
		return 0;
	int le=query(o,l,r),ri=query(o^1,le+1,r),sz=p.size(),nxt;
//	cout<<"GetMinIndex :"<<le<<" "<<ri<<" "<<sz<<endl;
	p.push_back(Pair(le,ri));
	nxt=dfs(o,l,le-1);
	if(nxt)
		to[sz].push_back(nxt);
	nxt=dfs(o^1,le+1,ri-1);
	if(nxt)
		to[sz].push_back(nxt);
	nxt=dfs(o,ri+1,r);
	if(nxt)
		to[sz].push_back(nxt);
	return sz;
}
int main() {
//	freopen("B.in","r",stdin);
//	freopen("B.out","w",stdout);
	scanf("%d",&n);
	for(int i=1;i<=n;i++) {
		scanf("%d",&val[i]);
		f[0][0][i]=i&1?0:i;
		f[1][0][i]=i&1?i:0;
	}
	val[0]=oo;
	for(int k=0;k<2;k++)
		for(int j=1;(1<<j)<=n;j++)
			for(int i=1;i+(1<<j)-1<=n;i++)
				f[k][j][i]=getmin(f[k][j-1][i],f[k][j-1][i+(1<<(j-1))]);
//	for(int i=0;(1<<i)<=n;i++,putchar('\n'))
//		for(int j=1;j<=n;j++,putchar(' '))
//			cout<<val[f[1][i][j]];
//	cout<<"==============================="<<endl;
//	for(int i=0;(1<<i)<=n;i++,putchar('\n'))
//		for(int j=1;j<=n;j++,putchar(' '))
//			cout<<val[f[0][i][j]];
//	cout<<"==============================="<<endl;
	int res=dfs(1,1,n);
	q.push(res);
	while(!q.empty()) {
		int now=q.top();
		q.pop();
		printf("%d %d ",val[p[now].a],val[p[now].b]);
		for(unsigned i=0;i<to[now].size();i++)
			q.push(to[now][i]);
	}
	return 0;
}

Measured memory_bytes: 48116
#include<stdio.h>

int main(){
    int W,H,x,y,r;
    
    scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);
    if(W < x + r || x - r < 0){
        printf("No\n");
    }else if(H < y + r || y - r < 0){
        printf("No\n");
    }else
    printf("Yes\n");
    return 0;
}


Measured memory_bytes: 2108
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
 
int main(){
  int i,j,cnt;
  int n,m;
  cin>>n>>m;
  int L[m],R[m];
  for(i=0;i<m;i++)cin>>L[i]>>R[i];
  int maL=0,miR=1000000;
  for(i=0;i<m;i++){
    maL=max(maL,L[i]);
    miR=min(miR,R[i]);
  }
  cout<<max(0,miR-maL+1);
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, a, b;
  cin >> n >> a >> b;
  int c = min(abs(a - n), abs(b - n));
  if (c == abs(a - n)) cout << "A" << endl;
  else cout << "B" << endl;
}

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

int gcd(int l,int m,int n)
{
    int tmp;
    int r;
    if(l<m){
        tmp = l;
        l = m;
        m = tmp;
    }
 
    /* ユークリッドの互除法 */
    r = l % m;
    while(r!=0){
        l = m;
        m = r;
        r = l % m;
    }
    

    if(m<n){
        tmp=m;
        m=n;
        n=tmp;
    }

        /* ユークリッドの互除法 */
    r = m % n;
    while(r!=0){
        m = n;
        n = r;
        r = m % n;
    }
    return n;




}

int main()
{
    int K;
    int p,q,r;
    cin >> K;
    int sum=0;
    for(p=1;p<=K;p++){
        for(q=1;q<=K;q++){
            for(r=1;r<=K;r++){
                sum+=gcd(p,q,r);
            }
        }
    }
    cout << sum;

}



Measured memory_bytes: 3636
#include<bits/stdc++.h>
// __builtin_ctz : no of trailing zeros
#define int long long
#define ll long long
#define pp pair<int,int>
#define mod 1000000007
#define trace(x) cerr<<#x<<": "<<x<<" "<<endl
#define trace2(x, y) cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z) cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define sa(a,n) for(int i =0 ; i<n ; i++) cin>>a[i]
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define scan() int n; cin>>n ; int a[n]; for(int i = 0 ; i<n ; i++) cin>>a[i]
#define print(a,n) for(int i = 0 ; i < n ; i++) cout<<a[i]<<' '
using namespace std;
int max(int x, int y)
{
    return x>y ? x : y;
}
int min(int x, int y)
{
    return x<y ? x : y;
}
void _(int&a , int b)
{
    a=(a%mod+b%mod)%mod;
    a=(a+mod)%mod;
}
ll cl(ll a,ll b)
{
    return (a/b)+(!(!(a%b)));
}
int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll d;d=0;
    for (int i = 0; i < 5; ++i)
    {
    	ll c;cin >> c;d+=c;
    }
    cout << 5*3-d;
    }

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

int main() {
  string a;
  a = "abcdefghijklmnopqrstuvwxyz";
  char b;
  cin >>b;
  int c = 0;
  while(b!=a.at(c)){
    c++;
  }
  cout <<a.at(c+1) <<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
struct SegTree {
    int N;
    vector<int> A;
    SegTree(int n) {
        N = 1;
        while (N < n) N *= 2;
        A.resize(2 * N);
    }
    void set(int idx, int val) {
        idx += N;
        A[idx] = val;
        idx /= 2;
        while (idx > 0) {
            A[idx] = max(A[2*idx+0], A[2*idx+1]);
            idx /= 2;
        }
    }
    int greater_index(int L, int R, int val, int dir) {
        L += N, R += N;
        deque<int> D1, D2;
        while (L < R) {
            if (R & 1) D2.push_front(--R);
            if (L & 1) D1.push_back(L++);
            L /= 2, R /= 2;
        }
        vector<int> D;
        for (auto d : D1) D.push_back(d);
        for (auto d : D2) D.push_back(d);
        if (dir == 1) reverse(begin(D), end(D));
        for (auto d : D) {
            if (A[d] <= val) continue;
            while (d < N) {
                if (A[2*d+dir] > val) d = 2*d+dir;
                else d = 2*d+!dir;
            }
            return d - N;
        }
        return -1;
    }
};
const int INF = 1e9;
int main() {
    int N; cin >> N;
    vector<Int> P(N); for (auto &p : P) cin >> p;
    SegTree st(N);
    for (int i = 0; i < N; i++) {
        st.set(i, P[i]);
    }
    Int ans = 0;
    for (int i = 0; i < N; i++) {
        Int L1 = -1, L2 = -1;
        Int R1 = -1, R2 = -1;
        L1 = st.greater_index(0, i, P[i], 1);
        if (L1 != -1) L2 = st.greater_index(0, L1, P[i], 1);
        R1 = st.greater_index(i, N, P[i], 0);
        if (R1 != N) R2 = st.greater_index(R1+1, N, P[i], 0);
        if (L1 != -1) {
            Int l2 = L2 == -1 ? -1 : L2;
            Int r1 = R1 == -1 ? N : R1;
            ans += (L1 - l2) * (r1 - i) * P[i];
        }
        if (R1 != -1) {
            Int l1 = L1 == -1 ? -1 : L1;
            Int r2 = R2 == -1 ? N : R2;
            ans += (i - l1) * (r2 - R1) * P[i];
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 2048
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll;
int k;
const int maxN = 1e5 + 10;
int dist[maxN];
const int INF = (int)1e9;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
//    freopen("input.txt", "r", stdin);
    cin >> k;
    for (int i = 0; i < k; i++) {
        dist[i] = INF;
    }
    set < pair < int, int > > s;
    for (int i = 1; i <= 9; i++) {
        dist[i % k] = min(dist[i % k], i);
    }
    for (int i = 1; i <= 9; i++) {
        if (dist[i % k] != i) continue;
        s.insert(make_pair(dist[i % k], i % k));
    }
    while (!s.empty()) {
        auto it = *s.begin();
        s.erase(s.begin());
        int v = it.second;
        int d = it.first;
        if (dist[v] != d) continue;
//        cout << v << " " << dist[v] << endl;
        for (int j = 0; j < 10; j++) {
            int nv = (10 * v + j) % k;
            if (dist[nv] > dist[v] + j) {
                if (dist[nv] != INF) {
                    s.erase(s.find(make_pair(dist[nv], nv)));
                }
                dist[nv] = dist[v] + j;
                s.insert(make_pair(dist[nv], nv));
            }
        }
    }
    cout << dist[0];
    return 0;
}

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

const int inf=0x3f3f3f3f, N=100010;
int c[N], w[N];
long long dp[N];
int main(){
  int n, p;scanf("%d%d", &n, &p);

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

  for(int i=0;i<n;i++)
    for(int j=p;j>=w[i];j--){
      dp[j]=max(dp[j], c[i]+dp[j-w[i]]);
    }
  printf("%lld\n", dp[p]);
}


Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cmath>
using namespace std;
typedef long long ll;
ll mod = 1e9+7;
#define rep(i,n) for(int i = 0; i < (n); ++i)
int main() {
    int r, g, b;
    cin >> r >> g >> b;
    int num = r * 100 + g * 10 + b;
    if ( num % 4 == 0 ) cout << "YES" << endl;
    else                cout << "NO" << endl;
    return 0;
}


Measured memory_bytes: 256
// 手を動かせばわかる Sの文字の登場する場所を保存してTを頭からみてどれだけ動けばいいかをアレする
// 一周する場合もなんかできた

package main
import (
	"fmt"
	"sort"
)

func main(){
	var S, T string
	fmt.Scan(&S, &T)
	SM := make(map[string][]int)
	for i, c := range []rune(S){
		SM[string(c)] = append(SM[string(c)], i+1)
	}
	ans := 0
	cur := 0
	for _, c := range []rune(T){
		x := string(c)
		if _, ok := SM[x]; !ok{
			fmt.Println(-1)
			return
		}
		idx := sort.Search(len(SM[x]), func(j int)bool{
			return cur <SM[x][j]
		})
		if idx == len(SM[x]){
			// 一周して一番最初に登場するところ
			ans += (len(S) - cur) + SM[x][0]
			cur = SM[x][0]
		}else{
			// 今いるところより先にいるのでそこまでの距離
			ans += SM[x][idx]-cur
			cur = SM[x][idx]
		}
	}
	fmt.Println(ans)
}

Measured memory_bytes: 7296
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	sc.Split(bufio.ScanWords)
	n, k, s := nextInt(), nextInt(), nextInt()
	a := make([]int, n)
	for i := 0; i < k; i++ {
		a[i] = s
	}
	for i := k; i < n; i++ {
		if s > 1 {
			a[i] = s - 1
		} else {
			a[i] = s + 1
		}
	}
	for i := 0; i < n; i++ {
		if i < n-1 {
			putf("%d ", a[i])
		} else {
			putf("%d\n", a[i])
		}
	}
	wt.Flush()
}

var (
	sc  = bufio.NewScanner(os.Stdin)
	rdr = bufio.NewReaderSize(os.Stdin, 1000000)
	wt  = bufio.NewWriter(os.Stdout)
)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	i, _ := strconv.Atoi(next())
	return i
}

func nextFloat64() float64 {
	f, _ := strconv.ParseFloat(next(), 64)
	return f
}

func nextInts(n int) []int {
	slice := make([]int, n)
	for i := 0; i < n; i++ {
		slice[i] = nextInt()
	}
	return slice
}

func nextFloat64s(n int) []float64 {
	slice := make([]float64, n)
	for i := 0; i < n; i++ {
		slice[i] = nextFloat64()
	}
	return slice
}

func nextMega() string {
	buf := make([]byte, 0, 1000000)
	for {
		l, p, _ := rdr.ReadLine()
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}

func putf(format string, a ...interface{}) {
	fmt.Fprintf(wt, format, a...)
}

func puts(a ...interface{}) {
	fmt.Fprintln(wt, a...)
}


Measured memory_bytes: 3328
import java.util.Scanner;

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

		int n=sc.nextInt();
		int a=sc.nextInt();
		int b=sc.nextInt();
		if(a*n>b){
			System.out.println(b);
		}else{
			System.out.println(a*n);
		}



	}
}


Measured memory_bytes: 21972
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
#include<math.h>
using namespace std;
#define INF 10000000
#define MOD 1000000007
typedef long long ll;
typedef pair<ll,int> P;



int main(){
   int count=0,num; 
   ll N,P,ans=1;
   cin>>N>>P;
   if(N==1){
       cout<<P<<endl;
       return 0;
   }
   for(ll i=2;i<=1000000;i++,count=0){
       if(P%i==0){
           while(P%i==0){
               P/=i;
               count++;
           }
           num=count/N;
           //cout<<i<<" "<<count<<endl;
           while(num--){
               ans*=i;
           }
       }
   }
   
   cout<<ans<<endl;
}


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

long long n, cnt, first, last;

void check( int d, int i ){
	if( last == 0 ) return;
	if( d == -1 ){
		if( first == last ) cnt ++;
		return;
	}
	if( d == 0 ){
		if( last * 10 + first <= n ) cnt ++;
		return;
	}
	int ll = 1, rr = 9, p = 100;
	while( d > 1 ){
		ll *= 10;
		rr *= 10;
		rr += 9;
		p *= 10;
		d--;
	}
	for( int j = 0; j <= rr; j ++ ){
		int a = last * p + j*10 + first;
		if( a <= n ){
			cnt ++; 
		}
		else{
			break;
		}
	}
}

int main(){

	# ifdef FILEs
		freopen( "input.txt", "r", stdin );
		freopen( "output.txt", "w", stdout );
	# endif
	ios_base::sync_with_stdio( false );
	cin >> n;
	for( int i = 1; i <= n; i ++ ){
		first = i; last = i % 10;
		while( first > 9 ) first /= 10;
		check( -1, i );
		check( 0, i );
		check( 1, i );
		check( 2, i );
		check( 3, i );
		check( 4, i );
	}
	cout << cnt;
}

Measured memory_bytes: 256
def resolve():
    D = int(input())
    cost = list(map(int, input().split()))
    sat = [list((map(int, input().split()))) for _ in range(D)]
    last = [0]*26

    sumsat = 0

    for i in range(D):
        pro = int(input())
        pro -= 1
        last[pro] = i + 1
        plussat = sat[i][pro]
        minussat = 0
        for j in range(26):
            minussat += (i+1-last[j])*(cost[j])
        sumsat += (plussat-minussat)

        print(sumsat)
resolve()

Measured memory_bytes: 69848
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

#define inf 1013161010
#define ninf -1013161010
#define mod 1000000007
#define ll long long
#define lf long double
#define in(x) scanf("%d",&x);
#define sz(x) ((int)x.size())
#define lld l64d
#define rep(i,n) for(i=0;i<n;i++)
#define rrep(i,n) for(i=n-1;i>=0;i--)
#define rep1(i,a,b) for(i=a;i<=b;i++)
#define rrep1(i,a,b) for(i=a;i>=b;i--)
#define stlfor(i,t) for(auto i =t.begin();i!=t.end();i++)
#define fr freopen("x.txt","r",stdin)
#define frc freopen("y.txt","w",stdout)
#define all(x) x.begin(),x.end()
#define set0(x) memset(x,0,sizeof(x))
#define dbg cout<<"yo "<<endl;
#define pset(n) fixed<<showpoint<<setprecision(n)

#define pii pair<int,int>
#define pll pair<ll,ll>
#define vpii vector<pair<int,int> >
#define si set<int>
#define mii map<int,int>
#define umii unordered_map<int,int>
#define vi vector<int>
#define pb push_back
#define ff first
#define ss second
#define mp make_pair

typedef tree<pii,null_type,less<pii>,rb_tree_tag,tree_order_statistics_node_update> OST;

ll toint(const string &s) { stringstream ss; ss << s; ll x; ss >> x; return x; }
string tostring ( ll number ){  stringstream ss; ss<< number; return ss.str();}

const lf pi = 2*acos(0);
const int nn = 2000006;

ll gcd(ll a,ll b){return (b==0)? a:gcd(b,a%b); }
void nope(int num = 0){ if(num==0) cout<<"NO"; else cout<<"-1"; exit(0); }

ll a[nn],f[nn];
ll lr[nn],nr[nn];
ll pr[nn];

ll fast_pow(ll a,ll m)
{
    if(m==0)
        return 1;
    else if(m==1)
        return a;
    ll h=fast_pow(a,m/2);
    if(m%2==0)
        return ((h*h)%mod);
    else
        return ((((h*h)%mod)*a)%mod);
}

ll mmi(ll b)
{
    return fast_pow(b,mod-2);
}

void solve()
{
    ll len;
    nr[0]=1;
    lr[0]=1;
    pr[0]=1;
    ll i,j,n;
    cin>>n;
    memset(f,-1,sizeof(f));
    int prev;
    rep(i,n+1)
    {
        cin>>a[i];
        if(f[a[i]]!=-1)
        {
            len=n-i;
            prev=f[a[i]];
        }
        f[a[i]]=i;
    }

    for(i=1;i<=n;i++)
    {
        nr[i]=(nr[i-1]*(n-i))%mod;
        nr[i]=(nr[i]*mmi(i))%mod;
    }

    for(i=1;i<=len+prev;i++)
    {
        lr[i]=(lr[i-1]*(len+prev-i+1))%mod;
        lr[i]=(lr[i]*mmi(i))%mod;
    }


    ll k;

    for(k=1;k<=n+1;k++)
    {
        if(k==1)
        {
            cout<<n<<endl;
            continue;
        }
        ll ans =0;
        if(n-1>=k)
            ans+=nr[k];

        if(n-1>=k-2)
            ans+=nr[k-2];
        ans%=mod;

        if(n-1>=k-1)
            ans+=(2*nr[k-1]);
        ans%=mod;


        if((prev+len)>0 and (prev+len)>=k-1)
            ans=(ans-lr[k-1]+mod)%mod;

        cout<<ans<<endl;

    }

}

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(0);
    ll i,j,n,tt;
    tt=1;
    //cin>>tt;
    while(tt--)
    {
        solve();
    }
    return 0;
}



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

using namespace std;

int main()
{
    int N;
    int t[110000], x[110000], y[110000];
    cin >> N;
    t[0] = x[0] = y[0] = 0;
    for (int i = 0; i < N; ++i) cin >> t[i+1] >> x[i+1] >> y[i+1];

    bool can = true;
    for (int i = 0; i < N; ++i) {
        int dt = t[i+1] - t[i];
        int dist = abs(x[i+1] - x[i]) + abs(y[i+1] - y[i]);
        if (dt < dist) can = false;
        if (dist % 2 != dt % 2) can = false;
    }    

    if (can) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 1408
#include<iostream>
#include<vector>
#include<algorithm>

signed main(){

  int n,m;
  int64_t k;
  std::cin>>n>>m>>k;
  std::vector<int64_t> a(n),b(m);
  for(auto& ai:a)std::cin>>ai;
  for(auto& bi:b)std::cin>>bi;

  std::vector<int64_t> as(n+1),bs(m+1);
  for(int i=0;i<n;++i)as[i+1]=as[i]+a[i];
  for(int i=0;i<m;++i)bs[i+1]=bs[i]+b[i];

  int ans = 0;
  for(int i=0;i<=n;++i){
    if(as[i]>k)break;
    ans = std::max<int>(ans,i+(std::upper_bound(std::begin(bs),std::end(bs),k-as[i])-std::begin(bs)-1));
  }

  std::cout<< ans <<std::endl;

}



Measured memory_bytes: 9508
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N,K;
  cin>>N>>K;
  int sum=1;
  for(int i=0;i<N;i++){
    if(sum<K){
      sum=sum*2;
    }
    else{
      sum=sum+K;
    }
  }
  cout<<sum<<endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <cassert>
#include <numeric>
#include <functional>
#pragma warning(disable:4996) 

typedef long long ll;
typedef unsigned long long ull;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF  9223300000000000000
#define LINF2 1223300000000000000
#define LINF3 1000000000000
#define INF 2140000000
const long long MOD = 1000000007;
//const long long MOD = 998244353;

using namespace std;

char str[200005];
pair<int,pair<int,int> > dp[200005];    // dp0[i],dp1[i]: i文字目までについて、部分列に現れないベストの文字列の長さ、prev, 最後の文字
int dp0[200005];

void solve()
{
    scanf("%s", str);
    int n = strlen(str);
    int save[26] = { 0 };
    int i, k;
    for (i = 0; i <= n; i++) {
        pair<int,pair<int,int> > z = make_pair(INF, make_pair(INF, INF));
        for (k = 0; k < 26; k++) {
            int id=save[k] - 1;
            if (id >= 0) {
                int nextlen = dp[id].first + 1;
                pair<int,pair<int,int> > ztmp = make_pair(nextlen, make_pair(id, k));
                if (ztmp.first < z.first) {
                    z = ztmp;
                }
                else if (ztmp.first == z.first) {
                    int prev = z.second.first;
                    int prevtmp=ztmp.second.first;
                    if (dp0[prev] > dp0[prevtmp]) {
                        z = ztmp;
                    }
                }
            }
            else {
                int nextlen = 1;
                pair<int,pair<int,int> > ztmp = make_pair(nextlen, make_pair(id, k));
                z = MIN(z, ztmp);
            }
        }
        dp[i] = z;
        if (i > 0) {
            if (dp[i] != dp[i - 1]) {
                dp0[i] = dp0[i - 1] + 1;
            }
            else {
                dp0[i] = dp0[i - 1];
            }
        }
        if (i < n) {
            save[str[i] - 'a'] = i + 1;
        }
    }

    vector<char> s;
    int curr = n;
    while (dp[curr].first > 0) {
        s.push_back('a' + dp[curr].second.second);
        curr = dp[curr].second.first;
    }
    reverse(s.begin(), s.end());
    s.push_back('\0');
    printf("%s\n", &s[0]);

    return;
}


int main(int argc, char* argv[])
{
#if 1
    solve();
#else
    int T;
    scanf("%d", &T);
    int t;
    for(t=0; t<T; t++) {
        //printf("Case #%d: ", t+1);
        solve();
    }
#endif
    return 0;
}


Measured memory_bytes: 3584
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <bitset>
#include <map>
#include <string>

#define repd(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;

using namespace std;

int inputValue(){
	int a;
	cin >> a;
	return a;
}

void inputArray(int *p,int a){
	rep(i,a){
		cin >> p[i];
	}
}

void inputVector(vector<int> *p,int a){
	rep(i,a){
		int input;
		cin >> input;
		p -> push_back(input);
	}
}

template <typename T>
void output(T a,int precision){
	if(precision > 0){
		cout << setprecision(precision) << a << "\n";
	}else{
		cout << a << "\n";
	}
}

int main(){
	//source
	int n,sum;
	cin >> n >> sum;
	int q=sum/n;
	for(int i=q;q>0;q--){
		if(sum%q==0){
			cout << q << endl;
			return 0;
		}
	}
	return 0;
}


Measured memory_bytes: 256