akhauriyash/Code-Regression huggingface dataset:
//#define _GLIBCXX_DEBUG

#include<bits/stdc++.h>
using namespace std;

#define endl '\n'
#define lfs cout<<fixed<<setprecision(10)
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define fi first
#define se second
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define EB emplace_back
#define rep(i,n,m) for(ll i = (n); i < (ll)(m); i++)
#define rrep(i,n,m) for(ll i = (ll)(m) - 1; i >= (ll)(n); i--)
using ll = long long;
using ld = long double;
const ll MOD1 = 1e9+7;
const ll MOD9 = 998244353;
const ll INF = 1e18;
using P = pair<ll, ll>;
template<typename T1, typename T2>
bool chmin(T1 &a,T2 b){if(a>b){a=b;return true;}else return false;}
template<typename T1, typename T2>
bool chmax(T1 &a,T2 b){if(a<b){a=b;return true;}else return false;}
ll median(ll a,ll b, ll c){return a+b+c-max({a,b,c})-min({a,b,c});}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
template<typename T1,typename T2>
void ans(bool x,T1 y,T2 z){if(x)cout<<y<<endl;else cout<<z<<endl;}  
template<typename T>
void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++)
{cout<<v[i][0];for(ll j=1;j<w;j++)cout spa v[i][j];cout<<endl;}};
void debug(vector<string>&v,ll h,ll w){for(ll i=0;i<h;i++)
{for(ll j=0;j<w;j++)cout<<v[i][j];cout<<endl;}};
template<typename T>
void debug(vector<T>&v,ll n){if(n!=0)cout<<v[0];
for(ll i=1;i<n;i++)cout spa v[i];cout<<endl;};
template<typename T>
vector<vector<T>>vec(ll x, ll y, T w){
  vector<vector<T>>v(x,vector<T>(y,w));return v;}
ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;}
vector<ll>dx={1,0,-1,0,1,1,-1,-1};
vector<ll>dy={0,1,0,-1,1,-1,1,-1};
template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2>&p){
  return os << p.first << " " << p.second;
}
//mt19937 mt(chrono::steady_clock::now().time_since_epoch().count());

int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  ll res=0,buf=0;
  bool judge = true;
  ll k;cin>>k;
  string s;cin>>s;
  if(s.size()<=k)cout<<s<<endl;
  else cout<<s.substr(0,k)+"..."<<endl;
  return 0;
}

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

typedef long long ll;
typedef pair <int, int> ii;
typedef pair <int, ii> iii;
typedef pair<ll, ll> pll;
typedef pair<double, int> pdi;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
#ifdef VC
#define scanf scanf_s
#endif
#define iINF (1<<30)
#define INF (1LL<<59)
#define forn(i) for(int i = 0;i < n; ++i)
#define form(i,n) for(int i = 0 ;i < n; ++i)
#define NIL -1

const ll mod = 998244353;
int n;
int m;
int ans = 0;

int main(){
	cin >> n;
	bool flg = false;
	for (int i = 1; i*(i + 1) <= 2 * n; i++) {
		if (i*(i + 1) == 2 * n) {
			flg = true;
			m = i;
			break;
		}
	}
	if (!flg) {
		cout << "No"<<endl;
		return 0;
	}
	cout<<"Yes"<<endl;
	cout << m + 1 << endl;
	for (int i = 0; i < m+1; i++) {
		cout << m;
		int pr=i;
		for (int j = 0; j < i; j++) {
			cout << " "<<pr ;
			pr += m - j - 1;
		}
		pr += 1;
		for (int j = 0; j < m - i; j++) {
			cout << " "<< pr;
			pr++;
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define ll long long
#define ALL(x) x.begin(), x.end()
#define fir first
#define sec second
using namespace std;

int main()
{
    string s;
    cin >> s;
    int y = 0, m = 0, d = 0;
    //y += (int)(s[0] - '0') * 1000 + (int)(s[1] - '0') * 100 + (int)(s[2] - '0') * 10 + (int)(s[3] - '0');
    m += (int)(s[5] - '0') * 10 + (int)(s[6] - '0');
    d += (int)(s[8] - '0') * 10 + (int)(s[9] - '0');
    if (m > 4)
    {
        cout << "TBD" << endl;
        return 0;
    }
    else if (m < 4)
    {
        cout << "Heisei" << endl;
        return 0;
    }
    if (d > 30)
    {
        cout << "TBD" << endl;
        return 0;
    }
    else
    {
        cout << "Heisei" << endl;
    }
    return 0;
}

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

template<typename T>
void fin (T a){
    cout<<a<<endl;
    exit(0);
}

template<typename S>
void print(S a){
    cout<<a<<endl;
}


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

    ll a=0;
    ll w=0;
    ll t=0;
    ll r=0;
    int n;cin>>n;
    string  s;
    rep(i,n){
        cin>>s;
        if(s=="AC"){
            a++;
        } else if (s == "WA") {
            w++;
        }else if(s=="TLE"){
            t++;
        }else{
            r++;
        }
    }
    cout<<"AC x "<< a<<endl;
    cout<<"WA x "<< w<<endl;
    cout<<"TLE x "<< t<<endl;
    cout<<"RE x "<< r<<endl;


}




Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,i,j,c=0;
    cin>>n;
    int a[n+3];
    for(i=0;i<n;i++)
    {
        cin>>a[i];
    }
    int x=a[0];
     for(i=0;i<n;i++)
     {
        if(x>=a[i])
        {
            c++;
            x=a[i];
        }

     }
     cout<<c<<endl;
}

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

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)

#define INF 1000000000000000000LL
#define MOD 1000000007
#define writeln(n) cout<<n<<endl
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
//vector<tuple<long long, long long, long long>>vec;

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

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

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



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

    llong n, m;
    cin >> n >> m;
    vector<pair<pair<llong,llong>,llong>> t(m);
    REP(i,m) cin >> t[i].first.second >> t[i].first.first;
    REP(i,m) t[i].second = i;
    sort(t.begin(),t.end());
    vector<vector<llong>> cit(n);
    REP(i,m) {
        cit[t[i].first.second - 1].pb(t[i].second);
    }
    vector<string> ans(m);
    REP(i,n) REP(j,cit[i].size()) {
            string zen = to_string(i + 1);
            while(zen.size() < 6) zen = "0" + zen;
            string kou = to_string(j + 1);
            while(kou.size() < 6) kou = "0" + kou;
            ans[cit[i][j]] = zen + kou;
        }
    REP(i,m) cout << ans[i] << endl;
    return 0;
}

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

typedef long long int LL;
int n;

LL solve() {
	string str;
	set<string> s;
	for (int i = 0; i < n; i++) {
		cin >> str;
		s.insert(str);
	}
	return s.size();
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	while (cin >> n) {
		cout << solve() << endl;
	}
}

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

int main(){
  int N;
  int a,b;
  cin >> N;
  
  for(int i=1;i<=9;i++){
    if(N%i == 0){//a
      if(N/i <=9){//b
        cout << "Yes";
        return 0;
      }
    }
  }
  cout << "No";
  
  return 0;
}





Measured memory_bytes: 256
#include<stdio.h>
int main(){
	int n,x;
	int l[105];
	int d[105];
	while(~scanf("%d %d",&n,&x)){
		int t=0;
		for(int i=0;i<n;i++)
		scanf("%d",&l[i]);
		d[0]=0;
		for(int i=1;i<=n;i++)
		d[i]=d[i-1]+l[i-1];
		for(int j=0;j<=n;j++)
		if(d[j]<=x)
		t++;
		printf("%d\n",t);
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

using namespace std;
#define ll long long
#define rep(i,n) for (int i = 0; i < n; i++)
#define rrep(i,n) for (int i = n-1; i >= 0; i--)
#define MOD (1000000007)
#define vi vector<int>
#define vl vector<ll>
#define vb vector<bool>
#define vvi vector<vi>
#define vvl vector<vl>
#define pii pair<int, int>
#define pli pair<ll, int>a
#define pb push_back
#define sz(x) int(x.size())

#define mp make_pair
#define all(a) (a).begin(),(a).end()

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

ll gcd(ll a, ll b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}

ll keta(ll n){
  string s = to_string(n);
  ll num = s.size();
  return num;
}

const ll INF = 1LL << 60;

const int dh[4] = {1,0,-1,0};
const int dw[4] = {0,1,0,-1};

struct Edge{
  int to;
  int weight;
  Edge(int t, int w) : to(t), weight(w){}
};
using Graph = vector<vector<Edge>>;
using P = pair<ll, int>;

class UnionFind{
  public:
  vi Parent;
  UnionFind(int n){
    Parent = vi(n,-1);
  }

  int root(int a){
    if(Parent[a] < 0) return a;
    else return Parent[a] = root(Parent[a]);
  }

  int size(int a){
    return -Parent[root(a)];
  }

  bool merge(int a, int b){
    a = root(a);
    b = root(b);
    if(a == b) return false;

    if(size(a) < size(b)) swap(a,b);
    Parent[a] += Parent[b];
    Parent[b] = a;

    return true;
  }
};

class Factrial{
  public:
  vl Fac;
  Factrial(int MAX){
    Fac = vl(MAX+1);
    rep(i,MAX) {
      if(i == 0) Fac[i+1] = 1;
      else Fac[i+1] = ((i+1)*Fac[i])%MOD;
    }
  }
};


int main(){
  string l; cin >> l;
  int n = sz(l);
  vl a(n+1),b(n+1);
  
  a[0] = 1;
  rep(i,n) {
    if(l[i] == '1'){
      a[i+1] = 2*a[i];
      b[i+1] = a[i] + 3*b[i];
    }
    else{
      a[i+1] = a[i];
      b[i+1] = 3*b[i];
    }
    a[i+1] %= MOD;
    b[i+1] %= MOD;
  }
  cout << (a[n]+b[n])%MOD << endl;
}

Measured memory_bytes: 2048
#include<bits/stdc++.h>
using namespace std;
#define int long long
//BEGIN CUT HERE
struct Fordfulkerson{
  const int INF = 1 << 28;
  struct edge{
    int to,cap,rev;
    edge(){}
    edge(int to,int cap,int rev):to(to),cap(cap),rev(rev){}
  };
  
  vector<vector<edge> > G;
  vector<int> used;
  
  Fordfulkerson(){}
  Fordfulkerson(int V){init(V);}
  
  void init(int V){
    for(int i=0;i<(int)G.size();i++) G[i].clear();
    G.clear();
    used.clear();
    G.resize(V);
    used.resize(V);
  }
  
  void add_edge(int from,int to,int cap){
    G[from].push_back(edge(to,cap,G[to].size()));
    // undirected
    //G[to].push_back(edge(from,cap,G[from].size()-1));
    // directed
    G[to].push_back(edge(from,0,G[from].size()-1));
  }
 
  int dfs(int v,int t,int f){
    if(v==t) return f;
    used[v]=true;
    for(int i=0;i<(int)G[v].size();i++){
      edge &e = G[v][i];
      if(!used[e.to] && e.cap > 0 ){
	int d=dfs(e.to,t,min(f,e.cap));
	if(d>0){
	  e.cap-=d;
	  G[e.to][e.rev].cap+=d;
	  return d;
	}
      } 
    }
    return 0;
  }
 
  int max_flow(int s,int t){
    int flow=0;
    for(;;){
      fill(used.begin(),used.end(),0);
      int f=dfs(s,t,INF);
      if(f==0) return flow;
      flow+=f;
    }
  }
};
//END CUT HERE

signed main(){
  int V,E;
  cin>>V>>E;
  Fordfulkerson ford(V);
  for(int i=0;i<E;i++){
    int u,v,c;
    cin>>u>>v>>c;
    ford.add_edge(u,v,c);
  }
  cout<<ford.max_flow(0,V-1)<<endl;
  return 0;
}

/*
verified on 2017/06/29
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=GRL_6_A&lang=jp
*/

Measured memory_bytes: 3180
n=int(input())
A=list(map(int,input().split()))
ans=1
for i in range(n):
  if A[i]==0:
    print(0)
    exit()
for i in range(n):
  if len(str(A[i]))>19:
    print(-1)
    exit()
  ans*=A[i]
  if ans>10**18:
    print(-1)
    exit()
print(ans)

Measured memory_bytes: 84500
#include <iostream>
#include <string>
#include <algorithm>
#include <utility>
#include <iomanip>
#include <functional>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cctype>
#include <cstdio>
#include <bitset>
#include <complex>
#define ll long long
#define INF 1000000000000000001
#define MOD 1000000007
using namespace std;


int main(){
    int N;
    cin >> N;
    string s[50];
    int t[50];
    for(int i=0; i<N; i++){
        cin >> s[i] >> t[i];
    }
    string X;
    cin >> X;

    int flag=0;
    int ans=0;
    for(int i=0; i<N; i++){
        if(flag==1){
            ans+=t[i];
        }

        if(X==s[i]){
            flag=1;
        }
    }

    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
	int n, k;
	scanf("%d %d", &n, &k);
	int arr[n];
	for(int i = 0; i < n; i++){
		scanf("%d", & arr[i]);
	}
	for(int j = 0; j < n - k; j++){
		if(arr[j] < arr[j + k]){
			printf("Yes\n");
		}
		else{
			printf("No\n");
		}
	}
	return 0;
}

Measured memory_bytes: 2400
#インポート
import sys

#入力用
def ILI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def ISI(): return map(int, sys.stdin.readline().rstrip().split())
def II(): return int(sys.stdin.readline().rstrip())
def ISS(): return sys.stdin.readline().rstrip().split()
def IS(): return sys.stdin.readline().rstrip()

N, M, X = ISI()
A = ILI()
cost_a = 0
cost_b = 0

for x in A:
    if x < X:
        cost_a += 1
    else:
        cost_b += 1
print(min(cost_a, cost_b))

Measured memory_bytes: 3064
n = int(input())
p = list(map(int, input().split()))
cnt = 0
for i in range(1,n-1):
    if p[i-1] <= p[i] and p[i] <= p[i+1]:
        cnt += 1
    elif p[i+1] <= p[i] and p[i] <= p[i-1]:
        cnt += 1
print(cnt)

Measured memory_bytes: 3060
#include<stdio.h>
#include<string.h>
int main(void){
    int lens,lenp,i,j,hante=0;
    char s[101],p[101],buf[201];
 
    scanf("%s",s);
    scanf("%s",p);
    lens=strlen(s);
    lenp=strlen(p);
    strcpy(buf,s);
    strcat(buf,s);
    for(i=0;i<lens;i++){
        for(j=0;j<lenp;j++){
            if(buf[i+j]!=p[j]) break;
        }
	if(lenp==j){hante=1;break;}
    }
    printf("%s\n",hante?"Yes":"No");
    return 0;
}

Measured memory_bytes: 532
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;

class Program
{
    static void Main(string[] args)
    {
        var S = ReadLine();
        var N = S.Length;

        var rle = RunLengthEncoding.Encode(S).ToArray();
        var ans = new int[N];
        var cursor = 0;

        for (int i = 0; i < rle.Length; i += 2)
        {
            var (r, l) = (rle[i], rle[i + 1]);
            var length = r.length + l.length;
            var (rVal, lVal) = (length / 2, length / 2);

            if (length % 2 == 1)
            {
                if (r.length % 2 == 1)
                    rVal++;
                else
                    lVal++;
            }

            ans[cursor += r.length - 1] = rVal;
            ans[cursor += 1] = lVal;
            cursor += l.length;
        }

        for (int i = 0; i < N; i++)
            Write($"{ans[i]}{((i < N - 1) ? ' ' : '\n')}");
    }
}

static class RunLengthEncoding
{
    public static IEnumerable<(T element, int length)> Encode<T>(IEnumerable<T> collection)
    {
        var isFirst = true;
        var prevElement = default(T);
        var length = 0;

        foreach (var element in collection)
        {
            if (!isFirst && !EqualityComparer<T>.Default.Equals(prevElement, element))
            {
                yield return (prevElement, length);
                length = 0;
            }
            else
                isFirst = false;

            length++;
            prevElement = element;
        }
        if (!isFirst)
            yield return (prevElement, length);
    }

    public static IEnumerable<T> Decode<T>(IEnumerable<(T element, int length)> rle) => rle.SelectMany(t => Enumerable.Repeat(t.element, t.length));
}


Measured memory_bytes: 39232
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int N;
	cin >>N;
	vector<int> A(N);
	for(int i=0; i<N; i++){
		cin >>A.at(i);
	}
	bool flag = 0;

	for(int i=0; i<N; i++){
		if(!(A.at(i)%2)){
			if(A.at(i)%3&&A.at(i)%5){
				flag = 1;
			}
		}
	}

	if(flag){
		cout <<"DENIED" <<endl;
	}
	else{
		cout <<"APPROVED" <<endl;
	}
}

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

using namespace std;
typedef long long ll;
#define int ll

#define REP(i,n) for(ll i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const double DINF = std::numeric_limits<double>::infinity();
const int MOD = 1000000007;
#define MAX_N 30

vector<string> S;

signed main()
{
    int N, L;
    cin >> N >> L;
    REP(i, N) {
        string s;
        cin >> s;
        S.push_back(s);
    }
    SORT(S);
    REP(i, N) {
        printf("%s", S[i].c_str());
    }
    printf("\n");

    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

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

        int M1 = sc.nextInt();
        int D1 = sc.nextInt();
        int M2 = sc.nextInt();
        int D2 = sc.nextInt();

        System.out.println(M1 != M2 ? 1 : 0);


    }
}

Measured memory_bytes: 23764
#include<bits/stdc++.h>
using namespace std;
#define LL long long
int N, M;
char maps[2222][2222];
int sum[2222][2222][4];
bool check(int x, int y){
	return (x > 0 && x <= N && y <= M && y > 0);
}
int main(){
	cin>>N>>M;
	for(int i = 1;i <= N; i++){
		scanf("%s", maps[i] + 1);
	}
	memset(sum, -1, sizeof(sum));
	int ans = 0;
	for(int i = 1;i <= N; i++){
		for(int j = 1;j <= M; j++){
			if(maps[i][j] == '#')continue;
			sum[i][j][0] = sum[i][j-1][0] + 1;
		}
		for(int j = M;j >= 1; j--){
			if(maps[i][j] == '#')continue;
			sum[i][j][1] = sum[i][j+1][1] + 1;			
		}
	}
	for(int j = 1; j <= M; j++){
		for(int i = 1;i <= N; i++){
			if(maps[i][j] == '#')continue;
			sum[i][j][2] = sum[i-1][j][2] + 1;
		}
		for(int i = N;i >= 1; i--){
			if(maps[i][j] == '#')continue;
			sum[i][j][3] = sum[i+1][j][3] + 1;
		}	
	}
	for(int i = 1;i <= N; i++){
		for(int j = 1;j <= M; j++){
			ans = max(ans, sum[i][j][0] + sum[i][j][1] + sum[i][j][2] + sum[i][j][3] + 1);
		}
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 82176
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;


int dp[22222];
int main(){
    int c,n,m;
    cin>>c>>n>>m;
    int a[n],b[n];
    rep(i,n)cin>>a[i]>>b[i];
    rep(i,20000)dp[i+1]=-inf;
    rep(i,n){
        for(int j=c-a[i]+1;j>=0;--j){
            dp[j+a[i]]=max(dp[j+a[i]],dp[j]+b[i]);
        }
    }
    rep(i,20000)dp[i+1]=max(dp[i+1],dp[i]);
    rep(i,m){
        cout<<dp[c/(i+1)]*(i+1)<<endl;
    }
    return 0;
}


Measured memory_bytes: 3256
import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;

void readV(T...)(ref T t){auto r=readln.splitter;foreach(ref v;t){v=r.front.to!(typeof(v));r.popFront;}}

void main()
{
  int k; readV(k);

  auto g = GraphW!()(k);
  foreach (i; 0..k) {
    g.addEdge(i, (i+1)%k, 1);
    g.addEdge(i, (i*10)%k, 0);
  }

  auto d = Dijkstra!(typeof(g)).dijkstra(g, 1);
  writeln(d[0]+1);
}

struct GraphW(N = int, W = int, W i = 10^^9)
{
  alias Node = N, Wt = W, inf = i;
  struct Edge { Node src, dst; Wt wt; alias cap = wt; }
  Node n;
  Edge[][] g;
  alias g this;
  this(Node n) { this.n = n; g = new Edge[][](n); }
  void addEdge(Node u, Node v, Wt w) { g[u] ~= Edge(u, v, w); }
  void addEdgeB(Node u, Node v, Wt w) { g[u] ~= Edge(u, v, w); g[v] ~= Edge(v, u, w); }
}

template Dijkstra(Graph)
{
  import std.array, std.container, std.traits;
  alias Node = TemplateArgsOf!Graph[0], Wt = TemplateArgsOf!Graph[1];
  alias Edge = Graph.Edge;

  void dijkstra(ref Graph g, Node s, out Wt[] dist, out Node[] prev)
  {
    auto n = g.n, sent = n;

    dist = new Wt[](n);
    dist[] = g.inf;
    dist[s] = 0;

    prev = new Node[](n);
    prev[] = sent;

    auto q = heapify!("a.wt > b.wt")(Array!Edge(Edge(sent, s, 0)));
    while (!q.empty) {
      auto e = q.front; q.removeFront();
      if (prev[e.dst] != sent) continue;
      prev[e.dst] = e.src;
      foreach (f; g[e.dst]) {
        auto w = e.wt + f.wt;
        if (dist[f.dst] > w) {
          dist[f.dst] = w;
          q.insert(Edge(f.src, f.dst, w));
        }
      }
    }
  }

  auto dijkstra(ref Graph g, Node s)
  {
    Wt[] dist;
    Node[] prev;
    dijkstra(g, s, dist, prev);
    return dist;
  }
}


Measured memory_bytes: 10620
#include <stdio.h>

int main(void) {

	int W , H , x , y , r ;
	
	scanf("%d",&W);
	scanf("%d",&H);
	scanf("%d",&x);
	scanf("%d",&y);
	scanf("%d",&r);
	
/*
	x+r <= W
	x-r >= 0
	y+r <= H
	y-r >= 0
*/

	if((x+r)<= W && (x-r) >= 0 && (y+r) <= H && (y-r) >= 0){
		printf("Yes\n");		
	}else{
		printf("No\n");
	}


	return 0;
}

Measured memory_bytes: 580
package main

import "fmt"

func main() {
        var n, a, b int
        fmt.Scan(&n, &a, &b)
        var length int
        if diff := a - b; diff > 0 {
                length = diff
        } else {
                length = -diff
        }
        if length%2 == 0 {
                fmt.Println("Alice")
        } else {
                fmt.Println("Borys")
        }
}

Measured memory_bytes: 512
import java.util.*;
 
public class Main {
	Scanner sc = new Scanner(System.in);
 
	public static void main(String[] args) {
		new Main();	
	}
 
	public Main() {
		new A().doIt();
	}
	class A{
		void swap(int a,int b,int c,int d,int dice[]){
			int result = dice[a];
			dice[a] = dice[b];
			dice[b] = dice[c];
			dice[c] = dice[d];
			dice[d] = result;
		}
		int top(String str,int dice[]){
			if(str.equals("North"))swap(0,1,2,3,dice);
			else if(str.equals("South"))swap(0,3,2,1,dice);
			else if(str.equals("East"))swap(1,4,3,5,dice);
			else if(str.equals("West"))swap(1,5,3,4,dice);
			else if(str.equals("Right"))swap(2,5,0,4,dice);
			else swap(2,4,0,5,dice);
			return dice[1];
		}
		void doIt(){
			while(true){
				int dice[] = {5,1,2,6,4,3};
				int n = sc.nextInt();
				if(n == 0)break;
				int ans = 1;
				for(int i = 0;i < n;i++){
					String str = sc.next();
					ans = ans + top(str,dice);
				}
				System.out.println(ans);
			}
		}
	}
}

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

using namespace std;


 
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int a;
    cin>>a;
    if(a%2==0){
        cout<<a/2<<endl;
    }else{
        cout<<a/2+1<<endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include<algorithm>
#include<string>
#include <map>
#include <queue>
#include <stack>
#include<set>

#define DIV 1000000007

using namespace std;
using ll = long long;
using ldb = long double;

int main() {
	ldb A, B, H, M; cin >> A >> B >> H >> M;
	ldb ang = abs((ldb)30.0 * H - M * (ldb)6.0+(ldb)0.500*M);
	ldb pi = 3.14159265358979323846;
	ldb ez = 180.00, two = 2.00;
	ldb ans = sqrt(A * A + B * B - two * A * B * cos(ang * pi / ez));
		
	printf("%.15Lf\n", ans);
	
}


Measured memory_bytes: 4124
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <sstream>
#include <map>
#include <set>

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1<<30
#define pb push_back
#define mp make_pair

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

ll dp[505][10005];

int main() {
	int m, n;
	cin >> m >> n;

	vector<int> v(m);
	rep(i, m) cin >> v[i];

	vector<P> p(n);
	rep(i, n) {
		cin >> p[i].first >> p[i].second;
	}

	sort(v.begin(), v.end(), greater<int>());

	int d[10005];
	memset(d, 0, sizeof(d));
	REP(i, 1, m + 1) {
		d[i] += d[i-1] + v[i-1];
	}

	memset(dp, 0, sizeof(dp));
	rep(i, 505) {
		rep(j, 10005) dp[i][j]  = -1;
	}

	dp[0][0] = 0;

	rep(i, n) {
		rep(j, m + 1) {
			dp[i+1][j] = max(dp[i+1][j], dp[i][j]);
		}

		rep(j, m) {
			if(dp[i][j] == -1) continue;

			int id = j + p[i].first;
			id = min(id, m);
			dp[i+1][id] = max(dp[i+1][id], max(dp[i][id], dp[i][j] + (d[id] - d[j]) - p[i].second));
		}
	}


	ll ans = 0;
	rep(i, n + 1) {
		rep(j, m + 1) {
			ans = max(ans, dp[i][j]);
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 40768
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define all(x) x.begin(), x.end()
#define MOD 1000000007
#define vi vector < int >
#define pii pair < int, int >
#define INF (int)1e9
#define pb push_back
#define fastIO ios::sync_with_stdio(0); cin.tie(0);

int n;
double cache[3005][3005];
bool visited[3005][3005];
vector < double > prob;

double dpSol(int i, int j)
{
    int mid = (n / 2);
    if(i == n)
    {
        if(j > mid)
            return 1;
        return 0;
    }
    
    double &res = cache[i][j];
    if(visited[i][j])
        return res;
    
    visited[i][j] = 1;
    return res = dpSol(i + 1, j) * (1.0 - prob[i]) + dpSol(i + 1, j + 1) * prob[i];
}

int main()
{
    fastIO
    
    cin >> n;
    
    prob = vector < double >(n);
    for(int i = 0; i < n; ++i)
        cin >> prob[i];
    
    for(int i = 0; i < 3005; ++i)
        for(int j = 0; j < 3005; ++j)
            visited[i][j] = 0;
    cout << setprecision(10) << dpSol(0, 0);

    return 0;
}

Measured memory_bytes: 79744
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main(){
	 ll n;
	 cin>>n;
	 float c;
	 c=sqrt(n);
	  	for(ll i=c;i>=0;i--){
	  		if(n%i==0){
	  			ll div=n/i;
	  			cout<<div+i-2;
	  			break;
			  }
		  }
		  return 0;
	  }

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define INF_LL 1LL << 40
#define INF 2000000000
#define MOD 1000000007
#define ll long long
#define all(x) x.begin(), x.end()
#define REP(i, a, b) for(int i = a; i < b; i++)
#define rep(i, n) REP(i, 0, n)
// typedef float double;
// typedef priority_queue prique;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<P> vp;
typedef vector<ll> vl;
typedef vector<vi> matrix;
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};
int sign[2] = {1, -1};
template <class T> bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return 1;
    }
    return 0;
}
struct edge {
    int to, cap, rev;
};

vector<edge> g[202];
bool used[202];

void add_edge(int from, int to, int cap) {
    g[from].push_back({to, cap, (int)g[to].size()});
    g[to].push_back({from, 0, (int)g[from].size() - 1});
}

int dfs(int v, int t, int f) {
    if(v == t)
        return f;
    used[v] = true;
    rep(i, g[v].size()) {
        edge &e = g[v][i];
        if(!used[e.to] && e.cap > 0) {
            int d = dfs(e.to, t, min(f, e.cap));
            if(d > 0) {
                e.cap -= d;
                g[e.to][e.rev].cap += d;
                return d;
            }
        }
    }
    return 0;
}

signed main() {
    int n;
    vector<vector<edge>> g(2 * n + 2);
    cin >> n;
    rep(i, n) {
        add_edge(0, i + 1, 1);
        add_edge(n + i + 1, 2 * n + 1, 1);
    }
    vector<P> r(n), b(n);
    rep(i, n) cin >> r[i].first >> r[i].second;
    rep(i, n) cin >> b[i].first >> b[i].second;
    // cout << b[0].first << b[0].second << endl;
    rep(i, n) rep(j, n) {
        if(r[i].first < b[j].first && r[i].second < b[j].second) {
            add_edge(i + 1, n + j + 1, 1);
        }
    }
    int ans = 0;
    while(1) {
        memset(used, false, sizeof(used));
        int f = dfs(0, 2 * n + 1, INF);
        // cout << f << endl;
        if(f == 0)
            break;
        ans += f;
    }
    cout << ans << endl;
}


Measured memory_bytes: 1920
// AOJ 2250 Operator
// 2018.2.1 bal4u

#include <stdio.h>
#include <string.h>

int N, T;
int M[1001], L[1001], K[1001];
int avai[1001];
char done[1001];

//#define getchar_unlocked()  getchar()
int in()
{
	int n = 0;
	int c = getchar_unlocked();
	do n = (n<<3)+(n<<1) + (c & 0xf), c = getchar_unlocked();
	while (c >= '0');
	return n;
}

int check(int p)
{
	int i, t, left;

	if (p >= N) return 1;

	memset(avai, 0, sizeof(avai));
	memset(done, 0, sizeof(done));

    for (i = 0; i < p; i++) avai[M[i]]++;
    left = N-p;

	for (t = 1; ; t++) {
		if (t > T) return 0;
		if (left <= 0) break;
		if (!avai[t]) continue;
		for (i = p; i < N; i++) {
			if (done[i]) continue;
			if (t % (L[i]+K[i]) <= L[i]) {
				if (t + M[i] > T) return 0;
				left--, done[i] = 1;
				avai[t]--, avai[t+M[i]]++;
				if (!avai[t]) break;
			}
		}
		avai[t+1] += avai[t];
	}
    return 1;
}

int main()
{
	int i;

	while (N = in()) {
		T = in();
		for (i = 0; i < N; i++) M[i] = in(), L[i] = in(), K[i] = in();
		for (i = 1; !check(i); i++);
		printf("%d\n", i);
	}
	return 0;
}


Measured memory_bytes: 2024
k, a, b = map(int, input().split())

if b<=a+2:
    print(1+k)
    exit()

#if b>a+2:
if (k-(a-1))%2 == 0:
    print(((k+1-a)//2)*(b-a)+a)
else:
    print(((k+1-a)//2)*(b-a)+a+1)


Measured memory_bytes: 2940
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0;i < n;i++)
#define mrep(p,mp) for(auto p : mp)
using namespace std;
using ll = long long;
using P = pair<int,int>;
 
int main(){
int n,m;
  cin >> n >> m;
  if(n <= m)
    cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
l = list(map(int, input().split()))
N, M, X = l[0], l[1], l[2]

fee = list(map(int, input().split()))

import numpy as np
fee = np.array(fee)
left = np.sum(fee < X)
right = np.sum(fee > X)

if left > right:
    print(right)
else:
    print(left)

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

int main()
{
	const int mod = 1000000007;
	int H, W, K;
	cin >> H >> W >> K;

	long long n[101][10];

	int a[] = { 1,1,2,3,5,8,13,21,34 };

	for (int i = 0; i < 100; i++){
		for (int j = 0; j < 10; j++) {
			n[i][j] = 0;
		}
	}
	n[0][K] = 1;

	for (int i = 1; i <= H; i++) {
		for (int j = 1; j <= W; j++) {
			n[i][j] = 0;
			n[i][j] += a[j - 1] * a[W - j] * n[i - 1][j];
			if (j > 1) n[i][j] += a[j - 2] * a[W - j] * n[i - 1][j - 1];
			if (j < W) n[i][j] += a[j - 1] * a[W - j - 1] * n[i - 1][j + 1];
			n[i][j] %= mod;
		}
	}

	cout << n[H][1] << endl;

}

Measured memory_bytes: 256
#!/usr/bin/env python


def knapsack(N,W,values,weights):
    dp = [[0 for j in range(W+1)] for i in range(N+1)]

    for i in range(N):
        for w in range(W+1):
            if w >= weights[i]:
                dp[i+1][w] = max(dp[i][w-weights[i]]+values[i], dp[i][w])
            else:
                dp[i+1][w] = dp[i][w]

    return dp[N][W]


tmp = [int(x) for x in input().split()]
N = tmp[0]
W = tmp[1]

values = []
weights = []
for i in range(N):
    tmp = [int(x) for x in input().split()]
    values.append(tmp[0])
    weights.append(tmp[1])

print(knapsack(N,W,values,weights))



Measured memory_bytes: 42264
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}
fn main() {
    input!(
    k: u64
    );
    let mut ans = 0;
    for a in 1..=k{
        for b in 1..=k{
            let t = gcd(a,b);
            for c in 1..=k{
                ans += gcd(t, c);
            }

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

fn gcd(a: u64, b: u64) -> u64 {
    if b == 0 {
        a
    } else {
        gcd(b, a % b)
    }
}


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


int main(){
	int a[16] = {};
	string s;
	cin >> s;
	int p = 0;
	for(int i = 0; i < s.size(); ++i){
		int t = (s[i] - 33) / 9;
		cout << string(abs(p - t), p < t ? '>' : '<') << string(abs(a[t] - s[i]), a[t] < s[i] ? '+' : '-') << '.';
		p = t;
		a[t] = s[i];
	}
	cout << '\n';
}

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

using namespace std;

inline int read(){
	int x(0);char ch('@');bool flag(false);
	for(;!isdigit(ch);ch=getchar())	flag|=(ch=='-');
	for(;isdigit(ch);ch=getchar())	x=(x<<3)+(x<<1)+(ch^48);
	return flag?-x:x;
}

int L,R;

int main(){
	L=read(),R=read();
	if(R-L+1>=2019)	puts("0");
	else {
		int ans=2019;
		for(register long long i(L);i<=R;++i)
			for(register long long j(i+1);j<=R;++j)
				if((i*j%2019)<ans)
					ans=i*j%2019;
		printf("%d\n",ans);
	}
	return 0;
}

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

using namespace std;

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

	int a, b, c;
	cin >> a >> b >> c;

	if(a < b and b < c) cout << "Yes\n";
	else cout << "No\n";

	return 0;
} // br1



Measured memory_bytes: 3160
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(x),end(x)
#define show(obj) {for(auto x:obj)cout<<x<<' ';cout<<endl;}
#define line "----------"
typedef long long ll;
typedef pair<int,int> ip;
typedef pair<ll,ll> lp;
const int inf = 1001001000;
const ll INF = 1LL<<60;
const ll MOD = 1e9 + 7;

int main(){
	string s; cin>>s;
	int t_cnt = 0;
	int minus = 0;
	for(int i = s.size()-1; i>=0; --i){
		if(s[i] == 'S' && t_cnt>0){
			--t_cnt;
			minus += 2;
		}
		if(s[i] == 'T'){
			t_cnt++;
		}
	}
	cout<<s.size()-minus<<endl;
	return 0;
}

Measured memory_bytes: 3724
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>
using namespace std;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) long long((x).size())
#define OUT(x) cout << (x) << endl
typedef long long ll;

int main() {
    int n;
    cin >> n;
    vector<int> l(n);
    for (int i = 0; i < n; i++) cin >> l[i];
    sort(ALL(l));
    int cnt = 0;
    for (int upp = n - 1; upp > 1; upp--) {
        for (int mid = upp - 1; mid > 0; mid--) {
            auto itr = upper_bound(l.begin(), l.begin() + mid, l[upp] - l[mid]);
            cnt += mid - (itr - l.begin());
        }
    }
    OUT(cnt);
}


Measured memory_bytes: 256
from collections import deque
H,W=map(int,input().split())
M=[input() for _ in range(H)]
D=[[10**5]*W for _ in range(H)]

cnt=0
for i in range(H):
    cnt+=M[i].count('#')

visited=[[0]*W for _ in range(H)]
q=deque([[0,0,0]])

while q:
    x,y,dist=q.popleft()
    if visited[x][y]==1:
        continue
    visited[x][y]=1
    D[x][y]=dist
    
    for i,j in [(1,0),(-1,0),(0,1),(0,-1)]:
        if x+i>=H or y+j>=W or x+i<0 or y+j<0:
            continue
        if M[x+i][y+j]=='#':
            continue
        q.append([x+i,y+j,dist+1])
if D[H-1][W-1]==10**5:
    print(-1)
else:
    print((H*W-1-D[H-1][W-1])-cnt)

Measured memory_bytes: 3316
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define EACH(i, c) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort((c).begin(), (c).end())
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
                      << " " << __FILE__ << endl;
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())

using namespace std;

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

    string n;
    cin >> n;

    if (n.length() == 2){
      cout << n;
    } else {
      cout << n[2] << n[1] << n[0];
    }
}


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

    cin >> n >> m;

    cout << (n-1) * (m-1) << endl;


}

    


Measured memory_bytes: 256
//
//  main.cpp
//  Problem Code
//
//  Created by Algo张伯威 on 2020/4/24.
//  Copyright © 2020 Algo张伯威. All rights reserved.
//

#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <map>
#include <cstdlib>
#include <vector>
#include <iostream>
using namespace std;


int main() {
    int a, b, k;
    scanf("%d%d%d", &k, &a, &b);
    if(a % k == 0 || b % k == 0) {
        printf("OK\n");
        return 0;
    }
    if(a / k - b / k != 0) {
       printf("OK\n");
       return 0;
    }
    printf("NG\n");
    
    return 0;
}






















Measured memory_bytes: 3760
#include <iostream>
#include <stdio.h>

using namespace std;

int main() {
 int mh[200],mr[200],mc[200],c,n,m,i,j,k;
 while(true) {
 c=0;
 for (i=0;i<2;i++) {
	 cin >> n;
	 if (n==0) return 0;
	 for (j=0;j<n;j++) { cin >> mh[c] >> mr[c]; mc[c]=0; c++;}
	 }
 for (i=0;i<c;i++) for (j=0;j<c;j++) if (mc[j]==i) for (k=0;k<c;k++) if (mh[j]>mh[k] && mr[j]>mr[k]) mc[k]=i+1;
 for (i=0,m=0;i<c;i++) if (m<mc[i]) m=mc[i];
 cout << m+1 << endl;
 }
 return 0;
 }

Measured memory_bytes: 1160
n = int(input())
s = int(input())
if s == 1 and n == 1:
    print(2)
    exit()
if s > n:
    print(-1)
    exit()
if n%2 == 0 and n > s > n//2:
    print(-1)
    exit()
if n%2 == 1 and n > s > n//2+1:
    print(-1)
    exit()

ans = float("INF")
for i in range(2,int(n**0.5)+1):
    x = n
    count = 0
    while x >= i:
        count += x%i
        x //= i
    if count + x == s:
        print(i)
        exit()
now = 2
li = int(n**0.5)+1
while True:

    x = n//now
    if x < li:
        break
    count = 0
    y = n
    while y >= x:
        count += y%x
        y //= x
    count += y
    if count <= s and (s-count)%now == 0:
        z = x-n//(now+1)
        if (s-count)//now < z:
            ans = x-(s-count)//now
    now += 1

if s == n:
    print(min(ans,n+1))
else:
    print(min(ans,n-s+1))


Measured memory_bytes: 3064
class Main{

	public static void main (String[] args) {

		Main main = new Main();

		java.util.Scanner sc = new java.util.Scanner(System.in);

		int N = sc.nextInt();
		int D = sc.nextInt();

		int count = 0;

		for (int index=0; index<N; index++) {
			int x = sc.nextInt();
			int y = sc.nextInt();
			if (Math.pow(x, 2)+Math.pow(y, 2)<=Math.pow(D, 2)) {
				count++;
			}
		}

		System.out.println(count);

		sc.close();;

	}

}


Measured memory_bytes: 59136
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double

const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;
const int mod=1000000007;

int main(){
	LL n,a[101010]={};
	cin>>n;
	FOR(i,0,n)cin>>a[i];
	sort(a,a+n);
	LL w=0,h=0,t=-1,idx=n;
	FORD(i,n,0){
		if(t==a[i]){
			w=t;
			idx=i;
			break;
		}else{
			t=a[i];
		}
	}
	t=-1;
	FORD(i,idx,0){
		if(t==a[i]){
			h=t;
			break;
		}else{
			t=a[i];
		}
	}
	cout<<w*h<<endl;
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
//#define s second
#define f first
long long const mod = 1000000007; 
#define inf 1000000000000000000
inline ll add(ll a, ll b){ return ((a%mod)+(b%mod)+mod)%mod;}
inline ll mul(ll a, ll b){ return (((a%mod)*(b%mod))%mod+mod)%mod;}
inline ll sub(ll a, ll b){ return ((a%mod)-(b%mod)+mod)%mod;}

ll gcd(ll a, ll b) 
{ 
    if (b == 0) 
        return a; 
    return gcd(b, a % b);  
      
}

ll power(ll x,ll y,ll m) 
{ 
    if (y == 0) 
        return 1; 
    ll p = power(x, y/2, m) % m;
    p = (p * p) % m; 
    return (y%2 == 0)? p : (x * p) % m; 
}

ll modInv(ll x)
{
    return power(x,mod-2,mod)%mod;
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
   
    ll n;
    cin>>n;
    set<string>st;
    for(ll i=0;i<n;i++)
    {
        string s;
        cin>>s;
        st.insert(s);
    }
    cout<<st.size()<<endl;
    
    

    return 0;
}



Measured memory_bytes: 19140
#include <bits/stdc++.h>
#define dmin(i, j) ((i) < (j) ? (i) : (j))
#define dmax(i, j) ((i) > (j) ? (i) : (j))
#define cmin(i, j) ((i) > (j) ? (i) = (j) : (i))
#define dabs(i) ((i) < 0 ? -(i) : (i))
using namespace std;
int n, ST[10000010 << 1], *st = ST + 10000010;
long long ans, sum;
char s[10000010], t[10000010];
int main() {
	cin >> n; scanf("%s%s", s, t); ans = 1e18; int _p = 0, _c = (s[0] != t[0]);
	for(register int i = 0; i < n; ++i) {
    	++st[_p - _c]; sum += _p - _c + n + 2;
    	if(s[i] != s[i + 1]) ++_p;
    	if(t[i] != t[i + 1]) ++_c;
    }
    _p = -n;
	for(register int i = -n - 2; i <= n + 2; ++i) {
		if(~i & 1) cmin(ans, sum);
//        cout << sum << endl;
    	_p += st[i] << 1, sum += _p;
    }
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 6528
#include <bits/stdc++.h>
#define REP(i, n) for (long long i = 0; i < (long long)n; i++)
//#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using Vl = vector<ll>;
using vi = vector<int>;
using Graph = vector<vi>;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  // std::cout << std::fixed << std::setprecision(15); //"for float-base
  // problem"
  ll A, B, K;
  string S;
  cin >> K >> A >> B;
  for (ll i = A; i <= B; i++) {
    if (i % K == 0) {
      cout << "OK" << endl;
      return 0;
    }
  }
  cout << "NG" << endl;
  return 0;
}

Measured memory_bytes: 3640
//
//AtCoder Beginner Contest 132
//A - Fifty-Fifty
//

#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <ctime>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <functional>
#include <cassert>

using namespace std;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define SIZE(x) (int)(x).size()
#define SIZEL(x) (ll)(x).size()
#define MSG(a) cout << #a << " " << a << endl;

using ll = long long;
using ld = long double;

const double PI = 3.14159265358979323846;

ll gcd(ll x, ll y) { return (x % y)? gcd(y, x % y): y; }    //最大公約数
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }            //最小公倍数

int main()
{
    string s;

    cin >> s;

    string ans = "No";

    sort(ALL(s));
    if (s[0]==s[1] && s[2]==s[3] && s[0]!=s[2]) ans = "Yes";

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


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
    int N, Y;
    cin >> N >> Y;

    int itimanen = -1,gosenen = -1,senen = -1;
    for(int i = 0; i <= N; i++){
        for(int j = 0; j <= N; j++){
            int tmp_value = Y - i * 10000 - j * 5000; 
            int tmp_number = N - i - j;
            if(tmp_value == 0 && tmp_number == 0){
                itimanen = i;
                gosenen = j;
                senen = 0;
                break;
            }
            else if(tmp_value/1000 == tmp_number && tmp_value >= 0){
                itimanen = i;
                gosenen = j;
                senen = tmp_number;
                break;
            }
        }
    }

    cout << itimanen << " " << gosenen << " " << senen << endl;
    return 0;
}


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

int main(){
  int n, a;
  int b[3] = {};
  cin >> n;
  for(int i = 0; i < n; i++){
    cin >> a;
    int cnt = 0;
    while(1){
      if(a % 2 != 0) break;
      a /= 2;
      cnt++;
    }
    if(cnt >= 2) b[2]++;
    else if(cnt == 1) b[1]++;
    else b[0]++;
  }
  if(b[1] == 0){
    if(b[0] <= b[2] + 1) cout << "Yes" << endl;
    else cout << "No" << endl;
  }else{
    if(b[0] <= b[2]) cout << "Yes" << endl;
    else cout << "No" << endl;
  }
  return 0;
}


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

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	
	int n,m; cin>>n>>m;
	int coin[m];
	int dp[n+1]; //dp[i] = min number of coins to reach i
	for(int i=0;i<n+1;i++)
		dp[i]=INT_MAX;
	for(int i=0;i<m;i++)
		cin>>coin[i];		
	
	dp[0]=0; dp[1]=1;
	for(int i=2;i<n+1;i++)
		for(int j=0;j<m;j++){
			if(i-coin[j]<0)	continue;
			else if(coin[j]==i)	dp[i]=1;
			else{
				dp[i]=min(dp[i],dp[i-coin[j]]+1);
			}
		}
	
	cout<<dp[n]<<"\n";
	return 0;
}



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

int main()
{
  int n;
  cin >> n;
  vector<int> s(n);
  for (auto &e : s)
    cin >> e;

  int q;
  cin >> q;
  int cnt = 0;
  for (int i = 0; i < q; ++i)
  {
    int t;
    cin >> t;
    int ng = -1, ok = n;
    while (abs(ok - ng) > 1)
    {
      int mid = (ok + ng) / 2;
      if (s[mid] >= t)
        ok = mid;
      else
        ng = mid;
    }
    if (s[ok] == t)
      cnt++;
  }
  cout << cnt << endl;

  return 0;
}



Measured memory_bytes: 3104
import sys
A, B = list(map(int, input().split()))
S = str(input())
flag = 0

if S[A] != "-":
  print("No")
  sys.exit()
else:
  for i in range(0,A):
    if 48 <= ord(S[i]) <= 57:
      flag = flag + 0
    else:
      flag = flag + 1
  for i in range(A+1,A+B+1):
    if 48 <= ord(S[i]) <= 57:
      flag = flag + 0
    else:
      flag = flag + 1
if flag != 0:
  print("No")
else:
  print("Yes")

Measured memory_bytes: 3064