akhauriyash/Code-Regression huggingface dataset:
#include <cmath>
#include <cstring>
#include <iostream>
#include <stack>
#include <stdio.h>
#include <string>
#include <vector>

using namespace std;

int binary_search(int A[], int right, int key) {
    int left = 0;
    while(left < right) {
        int mid = (right + left) / 2;
        if(A[mid] == key) {
            return 1;
        } else if(A[mid] > key) {
            right = mid;
        } else if(A[mid] < key) {
            left = mid+1;
        }
    }
    return 0;
}

int main() {
    int n, q, count = 0;
    cin >> n;
    int s[n];
    for(int i = 0; i < n; i++) {
        scanf("%d", &s[i]);
    }
    cin >> q;
    int t[q];
    for(int i = 0; i < q; i++) {
        scanf("%d", &t[i]);
    }

    for(int i = 0; i < q; i++) {
        count += binary_search(s, n, t[i]);
    }
    cout << count <<endl;
}


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

using namespace std;

#define int long long
#define all(v) (v).begin(), (v).end()
#define reps(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep(i, n) reps(i, 0, n)

template<class T1, class T2> void chmin(T1 &a, T2 b){if(a>b)a=b;}
template<class T1, class T2> void chmax(T1 &a, T2 b){if(a<b)a=b;}

typedef pair<int, int> Pi;
typedef tuple<int, int, int> Ti;
typedef vector<int> vint;

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

struct BIT {
  vector<int> data;
  BIT(int n):data(n+1, 0){}
  int sum(int k) {
    int res = 0;
    while(k > 0) {
      res += data[k];
      k -= k & -k;
    }
    return res;
  }
  void add(int k, int x) {
    while(k < (int)data.size()) {
      data[k] += x;
      k += k & -k;
    }
  }
};

signed main()
{
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  int n;
  cin >> n;
  BIT bit(n*2);
  bool deeper = false;
  rep(i, n) {
    int x;
    cin >> x;
    bool izryt = false;
    if(bit.sum(1) == 1) {
      izryt = false; //,cout<<1<<endl; // root medal ari
    } else if(x > n*2) {
      izryt = true, deeper = true; //,cout<<2<<endl;
    } else if(bit.sum(x+1) == x && (bit.sum(n*2)-bit.sum(x+1) > 0 || deeper)) { // root medal nasi [1,x] naname haichi
      izryt = false;//,cout<<3<<endl;;
    } else { // bit.sum(x+1) < x || hoge
      //cout<<4<<endl;
      izryt = true;
      int j = x;
      while(bit.sum(j+1)-bit.sum(j) > 0) bit.add(j+1, -1), j--;
      //cout<<j<<endl;
      bit.add(j+1, 1);
    }
    cout << (izryt ? "Yes" : "No") << endl;
  }

  return 0;
}

Measured memory_bytes: 10728
import java.util.Scanner;

class Main {

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

		int n = sc.nextInt();
    int m = sc.nextInt();

    if(n-m!=1&&n-m!=-1&&n-m!=0){
      System.out.print("0");
      return;
    }

    long ans = 1;
    for(int i=2; i<=n; i++){
      ans *= (long)i;
      ans = ans % 1000000007;
    }
    for(int i=2; i<=m; i++){
      ans *= (long)i;
      ans = ans % 1000000007;
    }
    if(n==m){
      ans *= 2;
      ans = ans % 1000000007;
    }
    System.out.print(ans);

	}

}


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

using namespace std;

int main()
{
    long long n;

    while (cin >> n, n) {
        int cnt = 0;
        while (n / 5) {
            cnt += n / 5;
            n /= 5;
        }
        cout << cnt << endl;
    }

    return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;


int main() {
  ios_base::sync_with_stdio(false);
  int r;
  cin >> r;
  cout << 3 * r * r << endl;
}


Measured memory_bytes: 256
#include<stdio.h>

int dp[50];

int fib(int n) {
	if ( n == 0 || n == 1 ) return dp[n] = 1;
	if( dp[n] != -1 ) return dp[n];
	return dp[n] = fib(n - 1) + fib(n - 2);
}


int main() {
	int n, i;
	for ( i = 0; i < 50; i++ ) dp[i] = -1;
	
	scanf("%d", &n);
	printf("%d\n", fib(n));
	
	return 0;
}


Measured memory_bytes: 2084
#![allow(non_snake_case)]
use proconio::input;
// use std::collections::HashMap;

fn main() {
    input! {
        X: i64,
    }

    let mut money: i64 = 100;
    let mut year = 0;
    while money < X {
        money += money / 100;
        year += 1;
    }

    println!("{}", year);
}


Measured memory_bytes: 2152
fun main(args:Array<String>) {
    val dateString = readLine()!!
    val num1 = dateString.substring(0,2).toInt()
    val num2 = dateString.substring(2).toInt()
    var ans = "NA"
    if (num1 in 1..12) {
        if(num2 in 1..12) {
            ans = "AMBIGUOUS"
        } else {
            ans = "MMYY"
        }
    } else {
        if(num2 in 1..12) {
            ans = "YYMM"
        } else {

        }
    }
    println(ans)

}


Measured memory_bytes: 29856
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<set>
#include<iomanip>
#define pi 3.14159265358979323846
#define ill long long int
#define rep(i, a, n) for(int i = a; i < n; i++)
using namespace std;
int main(){
  ill n, a;
  cin >> n >> a;
  if(n >= 500){
    n = n % 500;
    if(n <= a){
      cout << "Yes\n";
      return 0;
    }
    cout << "No\n";
    return 0;
  }
  if(n <= a){
    cout << "Yes\n";
    return 0;
  }
  cout << "No\n";
  return 0;
}
  

Measured memory_bytes: 3604
n = int(input())
s = [input() for _ in range(n)]
m = int(input())
t = [input() for _ in range(m)]

s_set = set(s)

points = []
for s_set_i in s_set:
    points.append(max(0, s.count(s_set_i) - t.count(s_set_i)))

print(max(points))

Measured memory_bytes: 3060
K =  int(input())
def gcd(a,b):
    r = divmod(a,b)[1]
    if r == 0:
        return int(b)
    else:
        return gcd(b,r)
    
def gcd3(a,b,c):
    return gcd(gcd(a,b),c)

s = 0
for a in range(1,K+1):
    for b in range(1,K+1):
        for c in range(1,K+1):
            s += gcd3(a,b,c)
            
print(s)

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

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    int n;
    static vector<int> edges[200000];
    cin >> n;
    for(int i=1;i<n;++i){
        int a, b;
        cin >> a >> b;
        --a; --b;
        edges[a].emplace_back(b);
        edges[b].emplace_back(a);
    }
    if(n == 2){ cout << "1 2\n"; return 0; }
    static int val[200000];
    int count[3] = {0, 0, 0};
    for(int i=0;i<n;++i) val[i] = -1;
    queue<pair<int, int>> q;
    q.emplace(0, 1);
    while(!q.empty()){
        auto p = q.front();
        q.pop();
        val[p.first] = p.second;
        count[p.second]++;
        for(auto to: edges[p.first]){
            if(val[to] >= 0) continue;
            q.emplace(to, (p.second - 1 ^ 1) + 1);
        }
    }
    if(count[1] == 1 || count[2] == 1){
        for(int i=1;i<=n;++i) cout << i << " \n"[i==n];
        return 0;
    }
    if(min(count[1], count[2]) >= (n+1)/3){
        int nx[3] = { 3, 1, 2 };
        int mx[3] = { 3, 1, 2 };
        for(int i=n-2;i<=n;++i) mx[i%3] = i;

        for(int i=0;i<n;++i){
            if(nx[val[i]] > mx[val[i]]) val[i] = 0;
            cout << nx[val[i]] << " \n"[i == n-1];
            nx[val[i]] += 3;
        }
    }else if(count[1] < count[2]){
        int nx[3] = { 3, 1, 2 };
        int mx[3] = { 3, 1, 2 };
        for(int i=n-2;i<=n;++i) mx[i%3] = i;
        for(int i=0;i<n;++i){
            if(val[i] == 1){
                cout << nx[0] << " \n"[i == n-1];
                nx[0] += 3;
            }else{
                int v = 1;
                if(nx[v] > mx[v]) v = 2;
                if(nx[v] > mx[v]) v = 0;
                cout << nx[v] << " \n"[i == n-1];
                nx[v] += 3;
            }
        }
    }else{
        int nx[3] = { 3, 1, 2 };
        int mx[3] = { 3, 1, 2 };
        for(int i=n-2;i<=n;++i) mx[i%3] = i;
        for(int i=0;i<n;++i){
            if(val[i] == 2){
                cout << nx[0] << " \n"[i == n-1];
                nx[0] += 3;
            }else{
                int v = 1;
                if(nx[v] > mx[v]) v = 2;
                if(nx[v] > mx[v]) v = 0;
                cout << nx[v] << " \n"[i == n-1];
                nx[v] += 3;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 15216
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <unordered_map>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
#include <assert.h>
#include <unordered_map>
#include <fstream>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 510000;
ll dy[8] = {1,-1,0,0,1,-1,1,-1};
ll dx[8] = {0,0,1,-1,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T> inline void print(T &a){
    rep(i,a.size()) cout << a[i] << " ";
    cout << "\n";
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << "\n";}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << "\n";
}
const int mod = 1e9 + 7;
//const int mod = 998244353;

bool v[1010101];
bool visit[1010101];

int main(){
    ll n; cin >> n;
    vl a(n); rep(i,n) cin >> a[i];
    ll ans = 0;
    sort(all(a));
    rep(i,n){
        if(visit[a[i]]) continue;
        if(!v[a[i]]){
            if(upper_bound(all(a),a[i]) - lower_bound(all(a),a[i]) == 1){
                ans++;
            }
        }
        visit[a[i]] = true;
        for(ll j=a[i]+a[i]; j<=1000000; j+=a[i]) v[j] = true;
    }
    cout << ans << endl;
}

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

typedef struct{
    int x, y, c;
}point;

int acsx(const void *p, const void *q){
    return ((point*)p)->x - ((point*)q)->x;
}
int acsy(const void *p, const void *q){
    return ((point*)p)->y - ((point*)q)->y;
}

int main(){
    int i, j, k;
    int N;
    point red[110],blue[110];
    int maxx, maxy, maxpoint;
    int ans=0;

    scanf("%d", &N);
    for(i=0; i<N; i++){
        scanf("%d %d", &red[i].x, &red[i].y);
        red[i].c = 0;
    }
    for(i=0; i<N; i++){
        scanf("%d %d", &blue[i].x, &blue[i].y);
        blue[i].c = 0;
    }

    qsort(red, N, sizeof(point), acsx);
    qsort(blue, N, sizeof(point), acsx);

    for(i=0; i<N; i++){
        maxy=-1;
        maxpoint = -1;
        for(j=0; j<N; j++){
            if(red[j].x < blue[i].x && red[j].c == 0){
                if(red[j].y<blue[i].y && maxy<red[j].y){
                    maxy = red[j].y;
                    maxpoint = j;
                }
            }
        }
        if(maxpoint != -1){
            //printf("%d %d %d %d\n", red[maxpoint].x, red[maxpoint].y, blue[i].x, blue[i].y);
            red[maxpoint].c = 1;
            ans++;
        }
    }

    printf("%d", ans);

    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();    
    int K = sc.nextInt();
    int sum = 0;
    
    for(int i=0; i<N; i++) {
      int x = sc.nextInt();
      if(x <= Math.abs(K-x)) {
        sum = sum + x;
      } else {
        sum = sum + Math.abs(K-x);
      }
    }
    System.out.println(sum * 2);
  }
}


Measured memory_bytes: 21844
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))

using namespace std;

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

const ll INF=1e9+7;


int main() {
    ll l,r,d;
    cin >> l >> r >> d;
    ll ans=0;
    for(ll i=l;i<=r;i++){
        if(i%d==0) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3628
import java.util.*;
public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int L = sc.nextInt();
        int M = sc.nextInt();
        if(N - L*M > 0){
            System.out.println("No");
        }else{
            System.out.println("Yes");
        }
        
        
        
        //System.out.println(anc);
    }
}


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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit32(x) (1 << (x))
#define bit64(x) (1ll << (x))

using namespace std;

using i32 = int;
using i64 = long long;
using f80 = long double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << '\n'; exit(0); }
inline void no() { cout << "No" << '\n'; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); return a / gcd(a, b) * b; }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { if (x < y) x = y; }
template <typename T> inline void amin(T &x, T y) { if (x > y) x = y; }
template <typename T> inline T exp(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { each(x, v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }

struct UnionFind {
  vector<int> data;
  UnionFind(int n) {
    data.assign(n, -1);
  }
  int root(int k) {
    if (data[k] < 0) return k;
    return data[k] = root(data[k]);
  }
  bool unite(int x, int y) {
    x = root(x), y = root(y);
    if (x == y) return false;
    if (data[x] > data[y]) swap(x, y);
    data[x] += data[y];
    data[y] = x;
    return true;
  }
  int size(int k) {
    return -data[root(k)];
  }
};

void solve() {
  int n, m, k;
  cin >> n >> m >> k;
  UnionFind uf(n);
  vector<pair<int, int>> par;
  rep(i, m) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    par.emplace_back(a, b);
    uf.unite(a, b);
  }
  rep(i, k) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    par.emplace_back(a, b);
  }
  vi32 ans(n);
  rep(i, n) {
    ans[i] = uf.size(i) - 1;
  }
  rep(i, m + k) {
    int a, b;
    tie(a, b) = par[i];
    if (uf.root(a) == uf.root(b)) {
      ans[a]--;
      ans[b]--;
    }
  }
  cout << ans << endl;
}


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

constexpr char NL = '\n';
constexpr int MOD = 1e9 + 7;

struct safe_hash {
    static uint64_t splitmix64(uint64_t x) {
        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);
    }
};

void solve()
{
    int n; cin >> n;
    cout << n * (n + 1) / 2 << "\n";
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    solve();
    return 0;
}

Measured memory_bytes: 3540
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;

int main(void) {
	int num, i = 0, a, b;
	long long k;
	cin >> num >> k;
	vector<int> d;
	map<int, long long> mp;
	for (; i < num; i++) {
		scanf("%d%d", &a, &b);
		if (mp.find(a) == mp.end())
			d.push_back(a);
		mp[a] += b;
	}
	sort(d.begin(), d.end());
	i = -1;
	while (k > 0)
		k -= mp[d[++i]];
	cout << d[i] << "\n";
	return 0;
}

Measured memory_bytes: 4476
N,K = map(int,input().split())
A = [1]*N
import collections
for i in range(K):
  d = int(input())
  check = input().split()
  for j in range(d):
    if A[int(check[j])-1] == 1:
      A[int(check[j])-1] = 0
c = collections.Counter(A)
print(c[1])

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

int main() {
    int A, B;
    int X, Y;

    cin >> A >> B;
    if (A == B) {
        X = A + B;
    } else {
        X = max(A, B) * 2 - 1;
    }
    cout << X << endl;
    return 0;
}


Measured memory_bytes: 256
A= [list(map(int, input().split())) for i in range(3)]
N = int(input())
B = [int(input()) for i in range(N)]
#print(A)
for b in B:
    for i in range(len(A)):
        for u in range(len(A[i])):
            if b==A[i][u]:
                A[i][u]=0
                
s=False
if A[0][0]==A[0][1]==A[0][2]==0:
    s=True
if A[1][0]==A[1][1]==A[1][2]==0:
    s=True
if A[2][0]==A[2][1]==A[2][2]==0:
    s=True
if A[0][0]==A[1][0]==A[2][0]==0:
    s=True
if A[0][1]==A[1][1]==A[2][1]==0:
    s=True
if A[0][2]==A[1][2]==A[2][2]==0:
    s=True
if A[0][0]==A[1][1]==A[2][2]==0:
    s=True
if A[0][2]==A[1][1]==A[2][0]==0:
    s=True
#print(A)
if s:
    print('Yes')
else:
    print('No')

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

int main(){
    int N,K,Q;cin>>N>>K>>Q;
    vector<int>A(Q);
    for(int i=0;i<Q;i++)cin>>A[i];
    vector<int>B(N,0);
    for(int i=0;i<Q;i++){
        //cout<<A[i]-1<<endl;
        B[A[i]-1]+=1;
    }
    int L=K-Q;
    //cout<<L<<endl;
    for(int i=0;i<N;i++){
        //cout<<B[i]+L<<endl;
        if(B[i]+L>0)cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }


}

Measured memory_bytes: 1408
#include<iostream>
#include<string>
#include<typeinfo>
#include<vector>
#include<algorithm>
#include<map>
#include<iomanip>
typedef long long int ll;
using namespace std;
int limit = 100000;
int main()
{
	ll n, k;
	cin >> n >> k;
	
	ll a[limit+1];
	for(ll i=0; i<limit+1; i++){
		a[i]=0;
	}
	ll A, B;
	for(ll i=0; i<n; i++){
		cin >> A >> B;
		a[A] += B;
	}
	
	for(ll i=1; i<limit+1; i++){
		if(k<=a[i]){
			cout << i << endl;
			break;
		}
		k -= a[i];
	}

	return 0;
}

Measured memory_bytes: 1024
import java.util.*;

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

        int N = sc.nextInt();
        Double T = sc.nextDouble();
        Double A = sc.nextDouble();

        List<Point> Ps = new ArrayList<>();
        
        for (int i=0; i<N; i++) {
            Ps.add(new Point(i + 1, Math.abs(A - (T - sc.nextDouble()*0.006))));
        }

        Ps.sort((Point a, Point b) -> a.temp <= b.temp ? -1 : 1);

        System.out.println(Ps.get(0).index);

    }
}

class Point {

    public int index;

    public Double temp;

    public Point(int index, Double temp) {
        this.index = index;
        this.temp = temp;
    }

}



Measured memory_bytes: 34596
#include <stdio.h>
const int N=1e4+10;
int max(int a,int b){return a>b?a:b;}
int main(){
	int ans=0,h,n,x,y,a[N][4],dp[N][5];
	bool flag;
	scanf("%d%d",&h,&n);
	for(int i=0;i<4;i++)for(int j=1;j<=h;j++)a[j][i]=0;
	for(int i=0;i<5;i++)for(int j=1;j<=h;j++)dp[j][i]=0;
	for(int i=0;i<5;i++)dp[0][i]=0;
	for(int i=1;i<=n;i++){
		scanf("%d%d",&x,&y);
		y++;
		a[y][x]=1;
	}
	//0=xxxx
	//1=ooxx
	//2=xoox
	//3=xxoo
	//4=oooo
	for(int i=2;i<=h;i++){
		for(int j=0;j<5;j++)dp[i][0]=max(dp[i][0],max(dp[i-2][j],dp[i-1][j]));
		flag=true;
		for(int j=0;j<2;j++)if(a[i][j]|a[i-1][j])flag=false;
		if(flag){
			for(int j=0;j<5;j++)dp[i][1]=max(dp[i][1],dp[i-2][j]+1);
			dp[i][1]=max(dp[i][1],dp[i-1][3]+1);
		}
		flag=true;
		for(int j=1;j<3;j++)if(a[i][j]|a[i-1][j])flag=false;
		if(flag)for(int j=0;j<5;j++)dp[i][2]=max(dp[i][2],dp[i-2][j]+1);
		flag=true;
		for(int j=2;j<4;j++)if(a[i][j]|a[i-1][j])flag=false;
		if(flag){
			for(int j=0;j<5;j++)dp[i][3]=max(dp[i][3],dp[i-2][j]+1);
			dp[i][3]=max(dp[i][3],dp[i-1][1]+1);
		}
		flag=true;
		for(int j=0;j<4;j++)if(a[i][j]|a[i-1][j])flag=false;
		if(flag)for(int j=0;j<5;j++)dp[i][4]=max(dp[i][4],dp[i-2][j]+2);
	}
	for(int i=0;i<5;i++)ans=max(ans,dp[h][i]);
	printf("%d\n",ans);
}




Measured memory_bytes: 3060
N, Q = map(int, input().split())
S = input()
t = [0] * (N + 1)
for i in range(N):
  t[i + 1] = t[i] + (1 if S[i : i + 2] == 'AC' else 0)
for i in range(Q):
  l, r = map(int, input().split())
  print(t[r-1] - t[l-1])

Measured memory_bytes: 9668
#include<bits/stdc++.h>
using namespace std;using ll=long long;using vi=vector<int>;using vvi=vector<vi>;using vl=vector<ll>;using vvl=vector<vl>;using P=pair<int,int>;using PL=pair<ll,ll>;using vp=vector<P>;using vpl=vector<PL>;
template<typename T>constexpr auto inf=numeric_limits<T>::max()/2;constexpr int INF=inf<int>,MOD=1000000007;constexpr ll LINF=inf<ll>;
#define _ol3(_1,_2,_3,name,...)name
#define _rep(i,n)_repi(i,0,n)
#define _repi(i,a,b)for(int i=a,i##_l=(b);i<i##_l;++i)
#define REP(...)_ol3(__VA_ARGS__,_repi,_rep,)(__VA_ARGS__)
#define REPR(i,n)for(int i=n-1;i>=0;--i)
#define REPA(i,v)REP(i,v.size())
#define all(v)(v).begin(),(v).end()
#define bit(n)(1ll<<(n))
#define uniq(v)sort(all(v));v.erase(unique(all(v)),v.end())
#define F first
#define S second
#define endl '\n'
#define cho(n,a,b)cout<<((n)?a:b)<<endl
void YES(int n){cho(n,"YES","NO");}void Yes(int n){cho(n,"Yes","No");}void Poss(int n){cho(n,"Possible","Impossible");}
void _print(ostream&s){}template<class T,class...U>void _print(ostream&s,T&&t,U&&...u){s<<t<<(sizeof...(u)?' ':'\n');_print(s,u...);}
template<class...T>void print(T&&...t){_print(cout,t...);}
#ifndef LOCAL
struct osd{template<class T>osd&operator<<(const T&t){return*this;}};osd cer_;
#define dprint(...)
#define cerr cer_
#else
template<class...T>void dprint(T&&...t){_print(cerr,t...);}
#endif
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>ostream&operator<<(ostream&o,const vector<T>&v){for(auto&&i:v)o<<i<<' ';return o;}
template<class T>istream&operator>>(istream&i,vector<T>&v){for(T&j:v)i>>j;return i;}
template<class T,class U>ostream&operator<<(ostream&o,const pair<T,U>&p){return o<<p.F<<' '<<p.S;}
template<class T,class U>istream&operator>>(istream&i,pair<T,U>&p){return i>>p.F>>p.S;}
template<class T>ostream&operator<<(ostream&o,const set<T>&v){for(auto&&i:v)o<<i<<' ';return o;}
template<class T>ostream&operator<<(ostream&o,const multiset<T>&v){for(auto&&i:v)o<<i<<' ';return o;}
template<class T>vector<T>&operator<<(vector<T>&v,const T&t){v.push_back(t);return v;}
template<class T>set<T>&operator<<(set<T>&v,const T&t){v.insert(t);return v;}
template<class T>multiset<T>&operator<<(multiset<T>&v,const T&t){v.insert(t);return v;}

int main(){
    cin.tie(0);ios::sync_with_stdio(0);
    int n;
    cin>>n;
    n++;
    int ans=0;
    ans+=max(0,min(10,n)-1);
    ans+=max(0,min(1000,n)-min(100,n));
    ans+=max(0,min(100000,n)-min(10000,n));
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#float型を許すな
#numpyはpythonで
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi,factorial
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

lis=LI()
for i in range(5):
    if lis[i]==0:
        print(i+1)

Measured memory_bytes: 9356
#include<stdio.h>
#include<string.h>
int main(){
  char a[10],s[10][10]={"SUN","MON","TUE","WED","THU","FRI","SAT","SUN"};
  int i;
  scanf("%s",a);
  for(i=0;strcmp(s[i],a);i++);
  printf("%d\n",7-i);
  return 0;
}


Measured memory_bytes: 128
#include <stdio.h>
int main()
{
    int n,  d1, d2;
    scanf("%d", &n);
    d1 = n/10;
    d2 = n%10;
    if(d1==9)
    {
        printf("Yes");
    }
    else if(d2==9)
    {
        printf("Yes");
    }
    else
    {
        printf("No");
    }
    return 0;
}

Measured memory_bytes: 2096
package main

import (
	"fmt"
)

func main() {
	var N, Y int
	ax, ay, az := -1, -1, -1
	fmt.Scan(&N, &Y)
	for ix := 0; ix <= N; ix++ {
		for iy := 0; iy <= N; iy++ {
			iz := N - ix - iy
			if iz < 0 {
				continue
			}
			if Y == 10000*ix+5000*iy+1000*iz {
				ax = ix
				ay = iy
				az = iz
			}
		}
	}
	fmt.Println(ax, ay, az)
}


Measured memory_bytes: 512
#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>;

int main() {

    int n, k;
    string s;
    cin >> n >> k >> s;

    int cnt = 0;
    rep(i, n-1){
        if(s[i] == s[i+1]){
            cnt++;
        }
    }
    int ans = min(cnt+2*k, n-1);

    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 512
def S(a,i,x,y):
	if 2*x >= A: return 2*x-A
	if 2*y >= A: return 2*y-A
	return min(S(a,i+1,x+a[i],y),S(a,i+1,x,y+a[i]))
while 1:
	n = input()
	if n == 0: break
	a = sorted(map(int,raw_input().split()))[::-1]
	A = sum(a)
	print S(a,1,a[0],0)

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

int main()
{
    int n;
    int cnt = 0;
    cin >> n;
    for (int a = 1; a <= n; a++){
        for (int b = 1; b <= (n/a); b++){
            if (n-a*b > 0) {
                cnt++;
            }
        }
    }
    cout << cnt;
}


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

#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define repp(i, n, m) for(int (i) = (n); (i) < (m); (i)++)
#define repn(i, n) for(int (i) = 1; (i) <= (n); (i)++)
#define repr(i, n) for(int (i) = (n-1); (i) >= 0; (i)--)
#define all(x) (x).begin(), (x).end()
#define lint long long
#define ulint unsigned long long
#define ldou long double
#define fi first
#define se second
#define setpre(x) std::cout << fixed << setprecision(x)
#define ii(x) int x; cin >> (x)
#define ii2(x, y) int x, y; cin >> (x) >> (y)
#define ii3(x, y, z) int x, y, z; cin >> (x) >> (y) >> (z)
#define out(x) cout << (x) << endl
#define outs(x) cout << (x) << " "
#define yn(x) cout << ((x)?("Yes"):("No")) << endl
#define YN(x) cout << ((x)?("YES"):("NO")) << endl
#define bit_c(x) __builtin_popcountll(x)

inline void logger(){ std::cout << " [LOGGER] " << endl; }
template<typename A, typename... B>
void logger(const A& a, const B&... b){
    cout << a << " , ";
    logger(b...);
}

typedef pair<lint, lint> P;
const lint MOD = 1000000007;
const lint MOD9 = 998244353;
const lint INF = MOD * MOD;
const int MAX = 200005*4;

/* ...o(^-^)o... */

lint dp[MAX];
struct segtree{
    int n; lint arr[MAX];
    segtree(int n_){
        n = 2;
        while(n < n_) n *= 2;
        rep(i, n*2) arr[i] = 0;
    }
    void update(int k, lint a){
        k += n - 1;
        arr[k] = a;
        while(k > 0){
            k = (k - 1) / 2;
            arr[k] = max(arr[k * 2 + 1], arr[k * 2 + 2]);
        }
    }
    lint query_(int a, int b, int k, int l, int r){
        if(r <= a || b <= l) return 0;
        if(a <= l && r <= b) return arr[k];
        else{
            lint vl = query_(a, b, k * 2 + 1, l, (l + r) / 2);
            lint vr = query_(a, b, k * 2 + 2, (l + r) / 2, r);
            return max(vl, vr);
        }
    }
    lint query(int a, int b){
        return query_(a, b, 0, 0, n);
    }
};

int main(){
    int n; cin >> n;
    vector<lint> h(n), a(n);
    rep(i, n){
        cin >> h[i]; h[i]--;
    }
    rep(i, n) cin >> a[i];

    segtree st(n);
    rep(i, n){
        dp[h[i]] = st.query(0, h[i]);
        dp[h[i]] += a[i];
        st.update(h[i], dp[h[i]]);
    }
    lint ans = 0;
    rep(i, n) ans = max(ans, dp[i]);
    out(ans);
}

Measured memory_bytes: 10880
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        ABC_107 solver = new ABC_107();
        solver.solve(1, in, out);
        out.close();
    }

    static class ABC_107 {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            int i = in.nextInt();

            out.print(n - i + 1);
        }

    }
}



Measured memory_bytes: 22356
#include "bits/stdc++.h"
 
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
#define int ll
#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
#define rep(i,n) for(int i = 0;i < (n) ; i++) 
#define REP(i,n) for(int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define INF LLONG_MAX/2
#define all(x) (x).begin(),(x).end()
#define debug(x) cerr<<#x<<": "<<x<<endl
#define debug_vec(v) cerr<<#v<<":";rep(i,v.size())cerr<<" "<<v[i];cerr<<endl
/*----------------------------------------------------------------*/

// int MOD = 998244353;
int MOD = 1000000007;


/*----------------------------------------------------------------*/
signed main(){

	int n;
	cin >> n;
	vll a(n);
	vll b(n);
	vll c(n);
	rep(i,n)cin >> a[i];
	rep(i,n)cin >> b[i];
	rep(i,n)c[i] = i+1;

	int x,y;
	int z = 0;
	do{
		z++;
		if(c == a)x = z;
		if(c == b)y = z;
	}while(next_permutation(all(c)));

	cout << abs(x-y) << endl;



	return 0;
}
/*----------------------------------------------------------------*/

// g++ -std=c++14 code1.cpp
// sudo pip3 install --upgrade online-judge-tools
// rm -r -f test;oj dl https://code-festival-2018-quala.contest.atcoder.jp/tasks/code_festival_2018_quala_c
// rm -r -f test;oj dl https://ddcc2020-qual.contest.atcoder.jp/tasks/ddcc2020_qual_b
// rm -r -f test;oj dl https://abc150.contest.atcoder.jp/tasks/abc150_b

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
inline ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
inline ll lcm(ll a, ll b) { return a / gcd(a, b)*b; }
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T>& V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> >& Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T>& mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }
template<typename T>vector<T> make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>auto make_v(size_t a,Ts... ts){return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type fill_v(T &t,const V &v){t=v;}
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type fill_v(T &t,const V &v){for(auto &e:t) fill_v(e,v);}
/*
 <url:>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */

template<class Type>
Type solve(Type res = Type()){
    ll N,M; cin >> N >> M;
    vector<ll> a(N); for(auto& in:a) cin >> in;

    sort(a.begin(),a.end());
    ll _lcm = 1;
    for(auto x:a){
        _lcm = lcm(_lcm,x/2);
        if(_lcm > M) return 0;
    }
    for(auto x:a){
        ll n = _lcm/(x/2);
        if(n%2 == 0) return 0;
    }
    res = (M/_lcm + 1)/2;
    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    // solve(0);
    cout << fixed << setprecision(15) << solve<ll>() << endl;
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define xx first
#define yy second
#define mp make_pair
#define pb push_back
#define mset(x, y) memset(x, y, sizeof x)
#define mcpy(x, y) memcpy(x, y, sizeof x)
using namespace std;

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

inline int Read()
{
	int x = 0, f = 1, c = getchar();
	for (; !isdigit(c); c = getchar())
		if (c == '-')
			f = -1;
	for (;  isdigit(c); c = getchar())
		x = x * 10 + c - '0';
	return x * f;
}

LL l, r, mid, ret;

inline bool Ask(LL x)
{
	string s;
	cout << "? " << x << endl;
	cin >> s;
	return s == "Y";
}

int main()
{
	if (Ask(10000000000))
		for (ret = 2; ; ret *= 10)
			if (Ask(ret))
				return cout << "! " << ret / 2 << endl, 0;
	for (r = 10; ; r *= 10)
		if (!Ask(r))
			break;
	for (l = r / 10, r --; l < r; )
		if (Ask((mid = l + r >> 1) * 10))
			r = mid;
		else
			l = mid + 1;
	return cout << "! " << r << endl, 0;
}


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

int main()
{
    int N;
    cin >> N;
    int A[N];
    rep(i, N) cin >> A[i];
    int counter = 0;
    for (int i = 1; i < N; i++)
    {
        if (A[i - 1] == A[i])
        {
            counter++;
            A[i] = -1;
        }
    }
    cout << counter << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#define mod (1e9 + 7)
#define pb push_back
#define ll long long int
using namespace std;
typedef pair<int,int> pii;

int main(){
  int hako[33]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  int k;
  cin>>k;
  cout<<hako[k-1]<<endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<functional>
#include<queue>
#include<algorithm>
#include<math.h>

typedef long long int ll;

using namespace std;

int main(void){

    int n; cin >> n;
    vector<int> a(n);

    ll total = 0;
    ll min = 20000000000000000;
    ll start = 0, end = 0;

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

    for(int i = 0;i < n-1;i++){
        end = total;
        start += a[i];
        end -= start;
        if(min > abs(start - end)) min = abs(start - end);
    }

    cout << min << endl;

    return 0;
}

Measured memory_bytes: 1024
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;
typedef pair<int,int> PP;

/*
    freopen("input","r",stdin);
    freopen("output","w",stdout);
*/

ll A[200], K[200];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int N;
    cin >> N;
    for (int i = 0;i < N;i++) cin >> A[i] >> K[i];
    ll sol = 0;
    for (int i = 0;i < N;i++) {
    	if (A[i] >= K[i]) {
    		ll crt = A[i];
    		while (crt % K[i] != 0) {
    			ll r = crt / K[i];
    			ll d = (crt % K[i]) / (r + 1);
    			crt -= (r + 1) * max(1LL, d);
    		}
    		sol = sol ^ (crt / K[i]);
    	}
    }
    if (sol != 0) cout << "Takahashi" << endl;
    else cout << "Aoki" << endl;
    return 0;
}

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

int main()
{
  int n;

  cin >> n;

  vector<int> v(n);
  vector<int> c(n);
  vector<int> sa(n);

  int total = 0;

  rep(i, n)
  {
    cin >> v.at(i);
  }

  rep(i, n)
  {
    cin >> c.at(i);
  }

  rep(i, n)
  {
    sa.at(i) = v.at(i) - c.at(i);
    if(sa.at(i)  >0)
      total += sa.at(i);
  }

  cout << total;
}


Measured memory_bytes: 3584
#k = int(input())
#s = input()
#a, b = map(int, input().split())
#s, t = map(str, input().split())
#l = list(map(int, input().split()))
#l = [list(map(int,input().split())) for i in range(n)]
#a = [input() for _ in range(n)]

l = [int(input()) for _ in range(5)]
k = int(input())

for i in range(5):
    for j in range(i+1,5):
        #print(l[i],l[j])
        if l[j] - l[i] > k:
            print(":(")
            exit()
print("Yay!")




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

main(){

  ll n,m;
  cin>>n>>m;
  vector<ll> a(n);
  rep(i,n)cin>>a[i];
  vector<ll> b(m),c(m);
  rep(i,m)cin>>b[i]>>c[i];

  priority_queue<pair<ll,ll>,vector<pair<ll,ll>>,less<>> que;
  rep(i,n)que.emplace(a[i],1);
  rep(i,m)que.emplace(c[i],b[i]);

  ll sum=0,card=0;
  while(card<n){
    ll val,num;
    tie(val,num)=que.top();
    que.pop();
    if(card+num<n){
      sum+=val*num;
      card+=num;
    }
    else{
      while(card<n){
        sum+=val;
        card++;
      }
    }
  }
  cout<<(sum)<<endl;


}


Measured memory_bytes: 8816
from collections import deque

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

bc = [list(map(int, input().split())) for _ in range(m)]

a.sort(reverse = False)
bc.sort(key = lambda x: x[1], reverse = True)

q = deque(bc)

s = 0

b, c = q.popleft()

for x in a:
    #print(x, b, c)
    if b == 0:
        if len(q) > 0:
            b, c = q.popleft()
        else:
            b, c = n, 0
    
    if x < c:
        s += c
        b -= 1
    else:
        s += x

print(s)

Measured memory_bytes: 101768
// #pragma GCC target ("avx2")
// #pragma GCC optimization ("O3")
// #pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>
using namespace std;
#define FastRead ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int
#define ll int
#define bits_count __builtin_popcountll
#define endl '\n'
#define double long double
#define ld double
#define FOR(i,a,n) for (ll i=(a);i<=(n);++i)
#define RFOR(i,a,n) for (ll i=(n);i>=(a);--i)
#define FI(i,n) for (ll i=0; i<(n); ++i)
#define ZERO(a) memset((a),0,sizeof((a)))
#define MINUS(a) memset((a),-1,sizeof((a)))
#define f first
#define s second
#define pb push_back
#define mk make_pair
#define all(g) g.begin(),g.end()
#define sz(x) (ll)x.size()
#define pr pair<int,int>
int fastMax(int x, int y) { return (((y-x)>>(32-1))&(x^y))^y; }
int fastMin(int x, int y) { return (((y-x)>>(32-1))&(x^y))^x; }

// #include <ext/pb_ds/assoc_container.hpp> // Common file
// #include <ext/pb_ds/tree_policy.hpp>     // Including tree_order_statistics_node_updat
// using namespace __gnu_pbds;
// typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

const int MAXN = 1e5 + 10;
bool visit[MAXN][180];
int n;

void dfs(int val,int sum){
    if(sum >= 100) return;
    if(visit[val][sum]) return;
    visit[val][sum] = 1;
    FOR(i,0,9) dfs((10*val + i)%n, sum + i);
}

void solve(){
    cin>>n; 
    FOR(i,0,9) dfs(i%n,i);

    int ans = 1e9;
    FOR(i,1,99) if(visit[0][i]) ans = min(ans,i);
    cout<<ans<<endl;
}

signed main(){

   FastRead;    

    int t = 1; 
    // cin>>t; 
    FOR(i,1,t){
        // cout<<"Case #"<<i<<": ";
        solve();
    }
}

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

using namespace std;

int main() {

char s[15];
scanf("%s", s);
for (int i = 0; i < 4; i++) { printf("%c", s[i]); }
printf(" ");
for (int i = 4; i < 12; i++) { printf("%c", s[i]); }
printf("\n");

return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main{
	public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int a = sc.nextInt();
        if(n % 500 <= a){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
    }
}


Measured memory_bytes: 22484
import java.io.*;
import java.util.List;
import java.util.StringTokenizer;

public class Main {

    int[] arr;

    int size;

    int swaps;

    public static void main(String[] args)
    {

        Main g = new Main();

        g.readArray();

        g.selectionSort();

        g.printArray();

        System.out.println("\n" + g.swaps);
    }

    private void readArray() {

        InputReader reader = new InputReader(System.in);

        size = reader.nextInt();

        arr = new int[size];

        for(int i=0; i<size; ++i)
            arr[i] = reader.nextInt();
    }

    private void printArray() {

        PrintWriter writer = new PrintWriter(System.out);

        for(int i=0; i<size; ++i) {

            writer.write("" + arr[i]);

            if(i<size-1) writer.write(" ");
        }

        writer.flush();
    }


    private void selectionSort() {

        for(int i=0; i<size-1; ++i) {

            int min=i+1;

            for(int j=i+1; j<size; ++j) {
                if(arr[j] < arr[min])
                    min=j;
            }

            if(arr[min] < arr[i]) {

                ++swaps;

                int tmp = arr[min];
                arr[min] = arr[i];
                arr[i] = tmp;
            }
        }
    }


    private void bubbleSort() {

        boolean flag=false;

        for(int i=0; i<size-1; ++i) {

            flag=false;

            for(int j=0; j<size-1-i; ++j) {

                if(arr[j]>arr[j+1]) {

                    flag=true;

                    ++swaps;

                    int tmp = arr[j];
                    arr[j] = arr[j+1];
                    arr[j+1] = tmp;
                }
            }

            // no swap has taken place so array is already sorted at this point
            if(!flag) break;
        }

    }


    class InputReader {

        private BufferedReader reader;

        private StringTokenizer tokenizer;

        InputReader(InputStream ip) {

            reader = new BufferedReader(new InputStreamReader(ip));
        }

        String next() {

            if(tokenizer==null || !tokenizer.hasMoreTokens()) {

                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }

            return tokenizer.nextToken();
        }

        int nextInt() {

            return Integer.parseInt(next());
        }
    }
}



Measured memory_bytes: 24496
import java.io.*;
public class Main{
    public static void main(String[] args) throws IOException{
        Reader r = new Reader();
        int N, K;
        {int[] a = r.ii(); N = a[0]; K = a[1];}
        double ans = 0;
        if(K <= N)
            ans += N-K+1;
        for(int i = 1; i <= Math.min(K-1, N); i++){
            int n = 0;
            int score = i;
            while(score < K){
                n++;
                score *= 2;
            }            
            ans += Math.pow(0.5, n);
        }
        ans /= N;
        print(ans);        
    }
    static void print(Object o){
        System.out.println(o.toString());
    }
    static class Reader extends BufferedReader{
        Reader(){
            super(new InputStreamReader(System.in));
        }
        String s() throws IOException{
            return readLine();
        }
        String[] ss() throws IOException{
            return s().split(" ");
        }
        int Int(String s){
            return Integer.parseInt(s);
        }
        int i() throws IOException{
        return Int(s());
        }
        int[] ii() throws IOException{
            String[] ss = ss();
            int size = ss.length;
            int[] ii = new int[size];
            for(int j = 0; j < size; j++) ii[j] = Int(ss[j]);
            return ii;
        }
    }
}


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

int main() {
    int N;
    cin >> N;
    vi A(N);
    rep(i, N) {
        cin >> A[i];
    }

    deque<int> deq;
    if (N % 2 == 0) {
        // 偶数を先頭に、奇数を末尾に追加していく
        for (int i = 0; i < N; i++) {
            // 奇数
            if (i % 2 == 0) {
                deq.push_back(A[i]);
            } 
            // 偶数
            else {
                deq.push_front(A[i]);
            }
        }
    } else {
        // 偶数を末尾に、奇数を先頭に追加していく
        for (int i = 0; i < N; i++) {
            // 奇数
            if (i % 2 == 0) {
                deq.push_front(A[i]);
            }
            // 偶数
            else {
                deq.push_back(A[i]);
            }
        }
    }

    rep(i, deq.size()) {
        cout << deq[i];
        if (i != deq.size() - 1) {
            cout << " ";
        }
    }
    cout << endl;
}

Measured memory_bytes: 4740
#include<iostream>
#include<cstdlib>
#include<cmath>
#include<string>
using namespace std;

#define ll long long
#define int ll

int ans;

string S;
int a[300000];
int len;
int Count;

signed main()
{
	cin >> S;

	len = S.size();

	for (int i = 0; i < len; i++) {
		if (S[i] == 'B') {
			a[i + 1] = 1;
		}
	}


	for (int i = len; i != 0; i--) {
		if (a[i] == 1) {
			ans += Count;
		}
		else {
			Count++;
		}
	}


	cout << ans << endl;

//	system("pause");
	return 0;
}



Measured memory_bytes: 2180
#include <cstdio>
#include <cstring>
#include <algorithm>
void Unused(...) {}
#ifndef DEBUG
  #define echo(...) Unused(__VA_ARGS__)
#else
  #define echo(...) fprintf(stderr, __VA_ARGS__)
#endif

const int MaxN = 500 + 7;
const int MaxM = int(3e5) + 7;

struct Inv
{
    int l, r;
    int idx;
    friend bool operator<(const Inv &a, const Inv &b)
    {
        return a.l == b.l ? a.idx < b.idx : a.l > b.l;
    }
};
Inv rd[MaxM];

int n, m, q;
int ans[MaxM];

int vol[MaxN];
int lowbit(int x) { return x & (-x); }

int query(int v)
{
    int res = 0;
    for (; v > 0; v -= lowbit(v))
        res += vol[v];
    return res;
}
void update(int v)
{
    for (; v < MaxN; v += lowbit(v))
        ++vol[v];
}

int main()
{
    scanf("%d %d %d", &n, &m, &q);
    for (int i = 1; i <= m; ++i)
        scanf("%d %d", &rd[i].l, &rd[i].r);
    for (int i = 1; i <= q; ++i)
    {
        scanf("%d %d", &rd[i + m].l, &rd[i + m].r);
        rd[i + m].idx = i;
    }
    std::sort(rd + 1, rd + m + q + 1);

    for (int i = 1; i <= m + q; ++i)
    {
        // query
        if (rd[i].idx > 0)
            ans[rd[i].idx] = query(rd[i].r);
        else
            update(rd[i].r);
    }
    for (int i = 1; i <= q; ++i)
        printf("%d\n", ans[i]);

    return 0;
}



Measured memory_bytes: 4736