akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
int main(){
    long long N,X;
    cin >> N >> X;
    long long ans =0;
    long long S[55], P[55]; //レベルiバーガーの長さ,パティの数
    S[0]=1; P[0]=1;
    for(int i=0; i<50; i++){
        S[i+1] = 2* S[i] + 3;
        P[i+1] = 2* P[i] + 1;
    }


    for(int i=N; i>0; i--){
        if(X > S[i-1]+1) {
            ans += P[i-1]+1;
            X -= S[i-1]+2;
            continue;
        }
        if(X <= S[i-1]+1) {
            X--;
            continue;
        }
    }
    if(X>=1) ans++;
    cout << ans << endl;
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, l, r) for (int i = (l); i < (r); i++)
#include <bits/stdc++.h>
//~ #include <atcoder/all>
using namespace std;
using ll = long long;
//~ using P = pair<int, int>;

template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}
//~ int A = (1<<2) | (1<<3) | (1<<5) | (1<<7);
//~ for (int bit=A; ; bit=(bit-1)&A){
//~ if (!bit) break;
//~ }
int next_combination(int sub)
{
    int x = sub & -sub, y = sub + x;
    return (((sub & ~y) / x) >> 1) | y;
}
//~ int n=5;
//~ int k=3; // nCkの組み合わせ、ただしk=0には対応してない
//~ int bit=(1<<k)-1; // 1000 -> 0111
//~ for(; bit < (1<<n); bit=nex_combination(bit){
//~ }
bool isPrime(int a)
{
    if (a == 2)
        return true;
    if (a <= 1 || a % 2 == 0)
        return false;

    for (int i = 3; i * i <= a; i += 2)
    {
        if (a % i == 0)
            return false;
    }
    return true;
}
//~ vector<int> a = {1, 14, 32, 51, 51, 51, 243, 419, 750, 910};
vector<int> a;
// index が条件を満たすかどうか
bool isOK(int index, int key)
{
    if (a[index] >= key)
        return true;
    else
        return false;
}
// 汎用的な二分探索のテンプレ
int binary_search(int key)
{
    int ng = -1;            //「index = 0」が条件を満たすこともあるので、初期値は -1
    int ok = (int)a.size(); // 「index = a.size()-1」が条件を満たさないこともあるので、初期値は a.size()

    /* ok と ng のどちらが大きいかわからないことを考慮 */
    while (abs(ok - ng) > 1)
    {
        int mid = (ok + ng) / 2;

        if (isOK(mid, key))
            ok = mid;
        else
            ng = mid;
    }
    return ok;
}

long long modpow(long long a, long long n, long long mod)
{
    long long res = 1;
    while (n > 0)
    {
        if (n & 1)
            res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

//~ int v[100100];
//~ int INF = 1 << 30;
//~ vector<vector<int>> dp(310, vector<int>(310));
//~ ll dp[110][100100];
//~ vector<int> dp(100100, 0));

//~ int seen[110];
//~ int ans[110][2];
//~ ll MOD = 1e9 + 7;

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

    int ans = 0;
    rep(i, n)
    {
        int x;
        cin >> x;
        ans += min(2 * x, 2 * abs(k - x));
    }

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


Measured memory_bytes: 3644
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
using ll=long long;
using vec=vector<ll>;
using vect=vector<double>;
using Graph = vector<vector<ll>>;
#define loop(i,n) for(ll i=0;i<n;i++)
#define Loop(i, m, n) for(ll i = m;i < n;i++)
#define pool(i,n) for(ll i=n;i>=0;i--)
#define Pool(i, m, n) for(ll i=n;i>=m;i--)
#define setbit bitset<8>
#define flagcount __builtin_popcount
#define flag(x) (1<<x)
#define flagadd(bit,x) bit|=flag(x)
#define flagpop(bit,x) bit&=~flag(x) 
#define flagon(bit,i) bit&flag(i)
#define flagoff(bit,i) !(bit & (1<<i))
#define all(v) v.begin(),v.end()
#define low2way(v,x) lower_bound(all(v),x)
#define high2way(v,x) upper_bound(all(v),x)
#define count2way(v,x) high2way(v,x)-low2way(v,x)
#define lower(v,x) low2way(v,x)-v.begin() //1番左が0、もし見つから無いならｎを出力
#define higher(v,x) high2way(v,x)-v.begin()-1 //1番左が0、もし見つからないならn-1を出力（注意）
#define putout(a) cout<<a<<endl
#define putout2(a,b) putout(a);putout(b)
#define putout3(a,b,c) putout(a);putout(b);putout(c)
#define putout4(a,b,c,d) putout(a);putout(b);putout(c);putout(d)
#define putout5(a,b,c,d,e) putout(a);putout(b);putout(c);putout(d);putout(e)
#define Gput(a,b) G[a].push_back(b)
#define cin1(a) cin>>a
#define cin2(a,b) cin>>a>>b
#define cin3(a,b,c) cin>>a>>b>>c
#define cin4(a,b,c,d) cin>>a>>b>>c>>d
#define cin5(a,b,c,d,e) cin>>a>>b>>c>>d>>e
#define sum(v) accumulate(all(v), 0ll)
#define gcd(x,y) __gcd(x,y)
#define erase(s) s.erase(s.end()-1) //文字列sの末尾削除
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m; 
    if (u < 0) u += m;
    return u;
}
ll ctoi(char c){
	if(c>='0'&&c<='9'){
		return c-'0';
	}
	return 0;
}
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
ll lcm(ll x,ll y){
  ll z=gcd(x,y);
  return x*y/z;
}
ll primejudge(ll n){
  if(n<2)return 0;
  else if(n==2)return 1;
  else if(n%2==0)return 0;
  double sqrtn=sqrt(n);
  Loop(i,3,sqrtn+1){
     if(n%i==0){
        return 0;
     }
     i++;
  }
  return 1;
}
string RLE(string s){
  ll n=s.size();
  char now='.';
  ll count=1;
  string press;
  loop(i,n){
    if(s[i]!=now){
      if(i){
        press+=now;
        press+=to_string(count);
      }
      now=s[i];
      count=1;
      continue;
    }
    else count++;
  }
  press+=now;
  press+=to_string(count);
  return press;
}
int main() {
  cout << fixed << setprecision(30);
  ll a,b;
  cin>>a>>b;
  ll ans=-1;
  for(double i=1;i<100000;i++){
    double t=i;
    double o=t*0.08;
    double p=t*0.10;
    ll a1=floor(o),a2=floor(p);
    if(a1==a&&a2==b){
      ans=t;
      break;
    }
  }
  putout(ans);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define uint ungigned
#define db double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pli pair<ll,int>
#define vi vector<int>
#define vpi vector<pii >
#define IT iterator
 
#define PB push_back
#define MK make_pair
#define LB lower_bound
#define UB upper_bound
#define y1 wzpakking 
#define fi first
#define se second
#define BG begin
#define ED end
 
#define For(i,j,k) for (int i=(int)(j);i<=(int)(k);i++)
#define Rep(i,j,k) for (int i=(int)(j);i>=(int)(k);i--)
#define UPD(x,y) (((x)+=(y))>=mo?(x)-=mo:233)
#define CLR(a,v) memset(a,v,sizeof(a))
#define CPY(a,b) memcpy(a,b,sizeof(a))
#define sqr(x) (1ll*x*x)
 
#define LS3 k*2,l,mid
#define RS3 k*2+1,mid+1,r
#define LS5 k*2,l,mid,x,y
#define RS5 k*2+1,mid+1,r,x,y
#define GET pushdown(k);int mid=(l+r)/2
#define INF (1<<29)
using namespace std;
const int N=100005;
int a[N],b[N],n,tot;
int sum[N],val[N];
ll ans1,ans2,ans3;
pii q[N*2];
int main(){
	scanf("%d",&n);
	for (int i=1;i<=n;i++) scanf("%d%d",&a[i],&b[i]);
	ans1=0,ans2=0,ans3=0;
	for (int i=1;i<=n;i++) ans1+=a[i],ans2+=b[i];
	for (int i=1;i<=n;i++) q[++tot]=pii(a[i],i),q[++tot]=pii(b[i],-i);
	sort(q+1,q+tot+1); int ok=0;
	for (int i=1;i<=n;i++){
		ok+=(sum[abs(q[i].se)]!=0);
		ans3+=q[i].fi;
		sum[abs(q[i].se)]+=q[i].se;
		val[abs(q[i].se)]=q[i].fi;
	}
	if (!ok){
		int del=1<<30;
		for (int i=n+1;i<=tot;i++)
			del=min(del,q[i].fi-(val[abs(q[i].se)]==q[n].fi?q[n-1].fi:q[n].fi));
		ans3+=del;
	}
	printf("%lld\n",min(min(ans1,ans2),ans3));
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
#define printArr(harry, tam) range(tam) cout << harry[i] << " \n"[i == tam -1];
#define range(n) for(int i = 0; i < n; i++)
#define forn(x, n) for(int x = 0; x < n; x++)
#define maxn "100000"
#define mod "1000000007"
#define md(x) ((((x) % mod) + mod) % mod)
#define sc scanf
#define pr printf
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define prt(x) cout << (#x) << " is " << (x) << endl
#define EPS 1e-9
#define INF INT_MAX
#define INFd 1e9

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef vector<int> vi;

//Trace dinamico
template<typename T>
void trace(T a) { cout << a << "\n"; }
template<typename T, typename... Args>
void trace(T a, Args... args) { cout << a << " "; trace(args...); }

//DP debug
int recNum = 0;
void prTabs() { range(recNum) cout << "    "; }
template<typename... Args>
void recInit(Args... args) { prTabs(); trace("rec(", args..., ")"); recNum++; }
template<typename T>
void recEnd(T a) { prTabs(); trace("->", a); recNum--;}
int r, g, b, n;
//vector<int> g[maxn]; 
char ch = '0', ant = '0';

int main(){
    sc("%d\n", &n);
    int initb = 0, fima = 0, ab = 0;
    int ba = 0, ca = 0, bc = 0, cc = 0;
    for(int i = 0; i < n; i++) {
        ant = ch;
        ch = getchar();
        char init = ch;
        if (ch == 'B') initb++;
        while(ch != '\n') {
            if (ch == 'B' && ant == 'A') ab++;
            ant = ch;
            ch = getchar();
        }
        if (ant == 'A') fima++;
        if (init == 'B' && ant == 'A') {
            ba++;
        } else if (init == 'B') {
            bc++;
        } else if (ant == 'A') {
            ca++;
        }
    }
    int r = 0;
    //trace(ba, ca, bc, cc);
    if (ca == 0) {
        r += max(ba-1, 0);
        if (r && bc) r++; 
    } else if (bc == 0) {
        r += ba;
    } else {
        r += min(ca, bc);
        r += ba;
    }
    //trace("r:",r);
    
    r += ab;
    
    pr("%d\n", r);
	
 	return 0;
}


Measured memory_bytes: 256
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', function (second) {
    var hour = Math.floor(second / 3600);
    var minute = Math.floor((second - 3600 * hour) / 60);
    second = second - (hour * 3600 + minute * 60);
    var output = hour + ":" + minute + ":" + second;
    console.log(output);
});

Measured memory_bytes: 7648
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import sys
import math

input = sys.stdin.readline

def main():
    n = int(input())
    a, b, c, d, e = [int(input()) for _ in range(5)]
    print(math.ceil(n / min(a, b, c, d, e)) + 4)

main()


Measured memory_bytes: 2940
#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 INF 1e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
#define downque(que)  priority_queue<ll> que;
#define upque(que) priority_queue<ll, vector<int>, greater<int>> que;


int main(){
   ll n,a,b; cin>>n>>a>>b;
   ll x[n];
   ll sum=0;

   REP(i,n)cin>>x[i];
   REP(i,n-1){ 
     sum+=min((x[i+1]-x[i])*a,b);
      
   }
  cout<<sum<<endl;
} 

Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws Exception {

//    	File file = new File("test.txt");
//    	Scanner sc = new Scanner(file);
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        long k = sc.nextLong();
        sc.close();
        boolean flg = true;
        if(k == 1){
        	System.out.println(0);
        	return;
        }
        n = n % k;
        while(flg){
        	n = Math.abs(n - k);
        	if(n < Math.abs(n - k)) flg = false;
        }
        System.out.println(n);
    }
}

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

int main(){
    int A,B,C,X,total,n=0;
    cin >>A>>B>>C>>X;
    for(int i=0;i<=A;i++){
        for(int j=0;j<=B;j++){
            for(int k=0;k<=C;k++){
                total =500*i+100*j+50*k;
                if(total == X) n+=1;
            }
        }
    }

    cout <<n<<endl;
}

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

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

    string alpha = "abcdefghijklmnopqrstuvwxyz";
    int ret = -1;
    for (int i = 0; i < alpha.length(); i++) {
        if (s.find(alpha[i]) == string::npos) {
            ret = i;
            break;
        }
    }

    if (ret > -1) {
        cout << alpha[ret] << endl;
    } else {
        cout << "None" << endl;
    }
}


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

using Weight = long long;
using Vertex = int;
struct Edge {Vertex from, to; Weight weight;};
using Graph = std::vector<std::vector<Edge>>;

std::vector<Vertex> Kahn(const Graph& G) {
  std::vector<Vertex> order;
  std::vector<int> indeg(G.size());
  for(const auto& E: G) for(const auto& e: E) ++indeg[e.to];
  std::queue<Vertex> q;
  for(Vertex v = 0; v < G.size(); ++v) if(indeg[v] == 0) q.emplace(v);
  while(!q.empty()) {
    for(const auto& e: G[q.front()]) if(--indeg[e.to] == 0) q.emplace(e.to);
    order.emplace_back(q.front());
    q.pop();
  }
  for(Vertex v = 0; v < G.size(); ++v) if(indeg[v] != 0) return {};
  return order;
}

int main() {
  int V, E;
  cin >> V >> E;
  Graph G(V);
  for(int i = 0; i < E; ++i) {
    int s, t;
    cin >> s >> t;
    G[s].push_back({s, t, 0});
  }
  for(auto v: Kahn(G)) cout << v << endl;
}



Measured memory_bytes: 4416
IDENTIFICATION DIVISION.
PROGRAM-ID. 129B.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 INP   PIC X(400).
01 N     PIC 9(3).
01 W     PIC 9(3).
01 WA    PIC 9(5).
01 HF    PIC 9(4)V9.
01 TBL.
   03 TW PIC 9(5) OCCURS 100.
01 I     PIC 9(3).
01 S1    PIC 9(5).
01 S2    PIC 9(5).
01 P1    PIC 9(3).
01 P2    PIC 9(3). 
01 OUT   PIC ZZZ9.
*>
PROCEDURE DIVISION.
  ACCEPT N.
*>
  ACCEPT INP.
  MOVE 0 TO WA.
  MOVE 1 TO P1.
  PERFORM VARYING I FROM 1 BY 1 UNTIL I > N
    PERFORM VARYING P2 FROM P1 BY 1 UNTIL INP(P2:1) = ' '
    END-PERFORM
*>
    MOVE INP(P1:P2 - P1) TO W
    COMPUTE WA = WA + W
    MOVE WA TO TW(I)
*> 
    COMPUTE P1 = P2 + 1
  END-PERFORM.  
*>
  COMPUTE HF = WA / 2.
  PERFORM VARYING I FROM 1 BY 1 
     UNTIL (I > N) OR (TW(I) >= HF)
  END-PERFORM. 
*>
  IF (TW(I) = HF)
    DISPLAY '0'
  ELSE
    COMPUTE S1 = WA - TW(I) * 2
    IF (I > 1)
      COMPUTE S2 = WA - TW(I - 1) * 2
    ELSE
      COMPUTE S2 = S1
    END-IF
*>
    IF (S1 < S2)
      MOVE S1 TO OUT
    ELSE
      MOVE S2 TO OUT
    END-IF
    DISPLAY FUNCTION TRIM(OUT)
  END-IF.  
*>
  STOP RUN.


Measured memory_bytes: 384
//Digit Sum 2

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a/__gcd(a, b)*b)
#define range(a) (a).begin(),(a).end() 
#define pb push_back
#define mp make_pair
#define nnn "\n"
template<class T>inline bool chmin(T& a,T b,bool f){
if(f==1){if(a>b){a=b;return true;}return false;}
else if(f==0){if(a<b){a=b;return true;}return false;}return false;}
typedef pair<int,string> p;
const int inf = 2147483647;//2*10^9
const ll INF = 9223372036854775807;//9*10^18

int main (){
    string s;cin>>s;
    int n = s.size();
    s = to_string(stoll(s)+1);
    int ans = 0;
    ans += (s[0]-'1');
    ans += 9*(s.size()-1);
    cout<<ans<<nnn;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
#define int long long 
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define vi vector<int>
#define mod 1000000007
#define tc(t) 			int t;cin >> t;while(t--)
#define for0(i , n)		for(int i=0;i<n;i++)
#define loop(i , a, b)	for(int i=a;i<=b;i++)
#define endl '\n'

char a[1001][1001];
int h,w;

vector<vector<int>> dp(1001,vector<int>(1001,-1));

int countpaths(int i, int j){
	if(i >= h || j >= w || a[i][j] == '#'){
		return 0;
	}

	if(i == h-1 && j == w-1){
		return 1;
	}

	if(dp[i][j] != -1){
		return dp[i][j];
	}

	return dp[i][j] = (countpaths(i,j+1) + countpaths(i+1,j)) % mod;
}

signed main() {

	ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    
#ifndef ONLINE_JUDGE
	freopen("input.txt" , "r" , stdin);
	freopen("output.txt" , "w" , stdout);
#endif


	cin >> h >> w;

	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			cin >> a[i][j];
		}
	}

	cout << countpaths(0,0) << endl;

	return 0;
}

Measured memory_bytes: 12600
#include <bits/stdc++.h>
typedef long long LL;
#define SORT(c) sort((c).begin(),(c).end())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

using namespace std;
int main(void)
{
  int n;
  cin >> n;
  string nsign;
  cin >> nsign;
  int answer=0;
  REP(i,n){
    string osign;
    cin >> osign;
    bool flag=false;
    REP(beg,osign.size()){
      FOR(gap,1,osign.size()){
	if(osign.size()<=beg+(nsign.size()-1)*gap) break;
	bool tmpflag=true;
	REP(j,nsign.size())
	  if(osign[beg+gap*j] != nsign[j]) tmpflag=false;
	flag=flag||tmpflag;
      }
    }
    if(flag) ++answer;
  }
  cout << answer << endl;
  return 0;  
}

Measured memory_bytes: 1212
/*
　　　  ∧＿∧　やあ
　　 （´・ω・｀)　　　　　/　　　　　ようこそ、バーボンハウスへ。
　　 ／∇y:::::＼　　　 [￣]　　　　　このテキーラはサービスだから、まず飲んで落ち着いて欲しい。
　　 |:⊃:|:::::|　　　|──|
￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣|　うん、「また」なんだ。済まない。
￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣|￣　  仏の顔もって言うしね、謝って許してもらおうとも思っていない。
￣￣￣￣￣￣￣￣￣￣￣￣￣￣／|
　　　　∇　∇　∇　∇　　　／.／|　　　でも、この提出を見たとき、君は、きっと言葉では言い表せない
　　　　┴　┴　┴　┴　／ ／　  |　　　「ときめき」みたいなものを感じてくれたと思う。
￣￣￣￣￣￣￣￣￣￣|／　　  |　　　殺伐としたコンテストの中で、そういう気持ちを忘れないで欲しい
￣￣￣￣￣￣￣￣￣￣　　　　 |　　　そう思って、この提出を投げたんだ。
　　　(⊆⊇)　(⊆⊇)　(⊆⊇)　　|
　    ||　　 ||　　||　　|　　　 じゃあ、判定を聞こうか。
　　.／|＼　／|＼ ／|＼
*/

#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <array>
#include <bitset>
#include <climits>
#include <cmath>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
#define fst first
#define snd second
#define ALL(obj) (obj).begin(),(obj).end()
#define debug(x) cerr << #x << " -> " << x << " (line:" << __LINE__ << ")" << '\n';
#define debugpair(x, y) cerr << "(" << #x << ", " << #y << ") -> (" << x << ", " << y << ") (line:" << __LINE__ << ")" << '\n';
typedef long long lint;
typedef priority_queue<int> p_que;
typedef priority_queue<int, vector<int>, greater<int>()> p_que_rev;
const int INF = INT_MAX;
const lint LINF = LLONG_MAX;
const int MOD = 1000000000 + 7;
const double EPS = 1e-9;
const double PI = acos(-1);
const int di[]{0, -1, 0, 1, -1, -1, 1, 1};
const int dj[]{1, 0, -1, 0, 1, -1, -1, 1};

int main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    int a, b, c;
    cin >> a >> b >> c;
    if(b / a >= c){
        cout << c << endl;
    }
    else {
        cout << b / a << endl;
    }
    return 0;
}

Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
#define per(i,n) for(int i = n-1; i >= 0; i--)
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<ll> vll;
const long long mod = 1000000007LL;

ll check[110000];

int main() {
  ll n, x, m;
  cin >> n >> x >> m;
  if(x==0) {
    cout << 0 << endl;
    return 0;
  }
  vll v;
  ll cnt = 0LL;
  ll a = x;
  rep(i,m*2) {
    v.push_back(a);
    cnt += a;
    check[a] = true;
    a *= a;
    a %= m;
    if(check[a]) break;
    if(a==0) {
      cout << cnt << endl;
      return 0;
    }
  }
  if(a==x) {
    ll s = v.size();
    ll ans = 0LL;
    ll b = n/s;
    ans += cnt*b;
    rep(i,n%s) ans += v[i];
    cout << ans << endl;
  }
  else {
    ll ans = 0LL;
    bool swi = true;
    vll vv;
    ll vs = v.size();
    rep(i,vs) {
      if(v[i]==a) swi = false;
      if(swi) {
        ans += v[i];
        n--;
      }
      else vv.push_back(v[i]);
    }
    ll s = vv.size();
    ll sum = 0LL;
    rep(i,s) sum += vv[i];
    ll b = n/s;
    ans += sum*b;
    rep(i,n%s) ans += vv[i];
    cout << ans << endl;
  }
  return 0;
}


Measured memory_bytes: 5000
#include <iostream>
using namespace std;
int main(){
  int house[4][3][10]={{{}}},n,b,f,r,v;
  cin >>n;
  for(int i=0;i<n;i++){
    cin >> b >> f >> r >> v;
    house[b-1][f-1][r-1] += v;
  }
  for(int i=0;i<4;i++){
    for(int j=0;j<3;j++){
      for(int k=0;k<10;k++){
    cout << " " << house[i][j][k];
      }
      cout << endl;
    }
    if(i!=3)
    cout << "####################" << endl;
  }
}


Measured memory_bytes: 3136
(princ (loop :for k :from 1 :upto (read) :with a := (read) :with b := (read)
             :for x := (loop :for l :from (1+ (floor (log k 10))) :downto 1
                             :for j := k :then (mod j (expt 10 l))
                             :sum (floor j (expt 10 (1- l))))
             :if (<= a x b) :sum k))

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

long extgcd(long a,long b,long &x,long &y){
    long g = a;
    x = 1; y = 0;
    if(b != 0) {
        g = extgcd(b, a%b, y, x);
        y -= (a / b) * x;
    }
    return g;
}

int main() {
    long a, b; cin >> a >> b;
    long x, y;
    extgcd(a, b , x, y);
    cout << x << " " << y << endl;
    return 0;
}


Measured memory_bytes: 3108
/*
数据不清空，爆零两行泪。
多测不读完，爆零两行泪。
边界不特判，爆零两行泪。
贪心不证明，爆零两行泪。
D P 顺序错，爆零两行泪。
大小少等号，爆零两行泪。
变量不统一，爆零两行泪。
越界不判断，爆零两行泪。
调试不注释，爆零两行泪。
溢出不 l l，爆零两行泪。
*/
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=3000;
int n;
int a[N+1];
int dp[N+1][N+1];
signed main(){
	cin>>n;
	for(int i=1;i<=n;i++)cin>>a[i];
	for(int i=n;i;i--)for(int j=i;j<=n;j++)
		dp[i][j]=n+i+j&1?max(dp[i+1][j]+a[i],dp[i][j-1]+a[j]):min(dp[i+1][j]-a[i],dp[i][j-1]-a[j]);
	cout<<dp[1][n];
	return 0;
}
/*1
4
10 80 90 30
*/
/*2
3
10 100 10
*/
/*3
1
10
*/
/*4
10
1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000 1
*/
/*5
6
4 2 9 7 1 5
*/

Measured memory_bytes: 70016
N=int(input())
a=list(map(int,input().split()))

MAX=max(a)
MIN=min(a)
m=0
operation=[]
if abs(MAX)>=abs(MIN):
    n=a.index(MAX)
    for i in range(N):
        a[i]+=MAX
        m+=1
        operation.append([n+1,i+1])
    for i in range(N-1):
        a[i+1]+=a[i]
        m+=1
        operation.append([i+1,i+2])
else:
    n=a.index(MIN)
    for i in range(N):
        a[i]+=MIN
        m+=1
        operation.append([n+1,i+1])
    for i in range(N-1,0,-1):
        a[i-1]+=a[i]
        m+=1
        operation.append([i+1,i])

print(m)
for i in range(m):
    print(*operation[i])

Measured memory_bytes: 3064
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <functional>
#include <stack>
#include <iomanip>
#include <limits>
using namespace std;
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
using Graph=vector<vector<int>>;
using edge= struct{int to;ll cost;};


template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}
using Graph =vector<vector<int>>;
//xor ^
int main(){
  int N;cin>>N;
  ll data[200000];
  ll final=0;
  REP(i,200000){
    data[i]=0;
  }
  vector<ll> colum(N);
  REP(i,N){
    ll tmp;cin>>tmp;
    colum[i]=tmp;
    data[tmp]++;
  }
  REP(i,200000){
    if(data[i]!=0){
      final+=data[i]*(data[i]-1)/2;
    }
  }
  for(int i=0;i<N;i++){
    cout<<final-data[colum[i]]*(data[colum[i]]-1)/2+(data[colum[i]]-1)*(data[colum[i]]-2)/2<<endl;
  }
}

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

using namespace std;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
//#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) ll(x.size())
typedef long long ll;
//typedef pair<int, int> P;
//typedef pair<ll, ll> P;
//const double INF = 1e10;
//const ll INF = 10e15;
const ll MINF = -10e10;
const int INF = INT_MAX;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)


//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);

//typedef priority_queue<P, vector<P>, greater<P>> PQ_ASK;
const int mod = 1000000007;
typedef pair<int, int> P;

int main() {
    int n, a, b;
    cin >> n >> a >> b;
    cout << min(n * a, b) << endl;


}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<string>
#include<array>
#include<cmath>
#include<vector>
#include<utility>
#include<algorithm>
using namespace std;


int main() {
	int k;
	cin >> k;
	if (k%2==0) {
		cout << pow(k/2,2) << endl;
	}
	else {
		cout << (k / 2) * (k / 2 + 1) << endl;
	}
}

Measured memory_bytes: 256
n, k = map(int, raw_input().split())
W = [input() for _ in xrange(n)]

MAX = 100000
T = [0] * MAX

def check(p):
    i = 0
    for j in xrange(k):
        s = 0
        while s + W[i] <= p:
            s += W[i]
            i += 1
            if (i == n):
                return n
    return i

def solve():
    left = 0
    right = 100000 * 10000
    while right - left > 1:
        mid = int((right + left) / 2)
        v = check(mid)
        if v >= n:
            right = mid
        else:
            left = mid

    return right

def main():
    ans = solve()
    print ans
    return 0

main()

Measured memory_bytes: 10180
#include <bits/stdc++.h>
using namespace std;
#define  rep(i, n) for(int i = 0; i < n; i++) 
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  INF 1LL << 60
typedef long long int LL;
typedef long long int ll;
#define pll pair<ll, ll>
#define F first
#define S second
const int MOD = 1000000007;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }
//sort(all(x))とするとソートできるよ
// 10^x は pow(10,(x)) 
// 任意のlogは　対数の底の変換を使う    log(N) / log(任意の底)

int main(){
    int X;cin >> X;
    int x = X % 100;
    int y = X / 100;



    if(ceil((float)x/5.0)  > y)cout << 0 << endl;
    else cout << 1 << endl;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <utility>
#include <queue>
#include <set>
#include <map>
#include <deque>
#include <iomanip>
#include <cstdio>
#include <stack>

using namespace std;
typedef  long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
#define  MP make_pair
#define  PB push_back
#define inf  1000000007
#define mod 1000000007
#define rep(i,n) for(int i=0;i<(int)(n);++i)
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}
int n;

vector<vector<int> > g;
vector<int>p(n),q(n);

pair<ll,ll> dfs(int k,int pre){
    pair<ll,ll> res = {1,1};
    for(auto x:g[k]){
        if(x!=pre){
            auto z = dfs(x,k);
            res.first *= z.second;
            res.first %= mod;
            res.second *= (z.first+z.second)%mod;
            res.second %= mod;
        }
    }
    return res;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    g.resize(n);
    p.resize(n);
    q.resize(n);
    rep(i,n-1){
        int a,b;
        cin >> a >> b;
        a--;
        b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    auto x = dfs(0,-1);
    cout << (x.first+x.second)%mod << endl;
    return 0;
}

Measured memory_bytes: 12032
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.util.Arrays;
class Main {
    
    public static void main(String[] args) throws IOException {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        int n=Integer.parseInt(br.readLine());
        for(int i=0;i<n;i++){
            StringTokenizer st=new StringTokenizer(br.readLine()," ");
            int array[] =new int[3];
            for(int j=0;j<array.length;j++) array[j]=Integer.parseInt(st.nextToken());
            Arrays.sort(array);
            if(Math.pow(array[0],2)+Math.pow(array[1],2)==Math.pow(array[2], 2))
                System.out.println("YES");
            else System.out.println("NO");
        }
    }
    
}

Measured memory_bytes: 25596
using System;
using System.Linq;
class c
{
    static void Main()
    {
        var nk = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
        var h = Array.ConvertAll(Console.ReadLine().Split(), int.Parse).ToList();
        var ans = new int[nk[0]];
        for (int i = 1; i < nk[0]; i++)
        {
            int temp = int.MaxValue;
            for (int j = 1; j <= nk[1]; j++)
            {
                if (i - j >= 0) temp = Math.Min(temp, ans[i - j] + Math.Abs(h[i] - h[i - j]));
            }
            ans[i] = temp;
        }
        Console.WriteLine(ans[nk[0] - 1]);
    }
}

Measured memory_bytes: 19296
#include <bits/stdc++.h>
typedef long long i64;
using std::cout;
using std::endl;
using std::cin;

int main() {
	int n; cin >> n;
	int q; cin >> q;
	if(n == 1) {
		while(q--) {
			int a, b; cin >> a >> b;
			
			cout << std::min(a, b) << endl;
		}
		return 0;
	}
	
	while(q--) {
		int a, b; cin >> a >> b; a--; b--;
		
		std::map<int, bool> used; used[a] = true;
		while(a) {
			a = (a - 1) / n;
			
			used[a] = true;
		}
		
		if(used[b]) {
			cout << b + 1 << endl;
			continue;
		}
		
		while(b) {
			b = (b - 1) / n;
			
			if(used[b]) {
				cout << b + 1 << endl;
				break;
			}
		}
	}
	return 0;
}


Measured memory_bytes: 1280
def check(arr):
	if len(arr)!=0:
		return arr.pop(0)
	else:
		return False



stringa = list(input())
stringb = list(input())
stringc = list(input())
# print(len(stringa))
temp = stringa.pop()
# print(len(stringa))

last_temp = 'a'
while temp:
	if temp=='a':
		last_temp = temp
		temp = check(stringa)
	elif temp=='b':
		last_temp = temp
		temp = check(stringb)
	elif temp=='c':
		last_temp = temp
		temp = check(stringc)
print(last_temp.capitalize())


Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <iomanip>
#include <map>
using namespace std;

#define INF 1e9
#define LLINF 1e18
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;

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


int main() {
    int n;
    int ans = INF;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a.at(i);
    sort(a.begin(), a.end());
    for(int i = a.at(0); i <= a.at(n - 1); i++) {
        int b = 0;
        rep(j, n) {
            b += (i - a.at(j)) * (i - a.at(j));
        }
        ans = min(ans, b);
    }
    cout << ans << endl;
}

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

using namespace std;

int w,h;
bool grid[50][50];

void rec(int x,int y){
  grid[y][x]=false;
  for(int i=-1;i<2;i++){
    for(int j=-1;j<2;j++){
      int ny=y+i,nx=x+j;
      if(0<=nx && nx<w && 0<=ny && ny<h)
	if(grid[ny][nx])rec(nx,ny);
    }
  }
}

int main(void){

  while(cin >> w >> h,w|h){
    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
	cin >> grid[i][j];
      }
    }
    
    int ans=0;
    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
	if(grid[i][j])rec(j,i),ans++;
      }
    }
    cout << ans << endl;
  }

  return 0;
}

Measured memory_bytes: 1340
#include <iostream>

using namespace std;
const int N = 2e5 + 1;
const int mod = 1e9 + 7;
long long a[N];
int n;
int main(){
    cin >> n;
    for (int i = 1; i <= n; i++) cin >> a[i];
    for (int i = 1; i <= n; i++) a[i] = a[i - 1] + a[i];
    long long ans = 0;
    for (int i = 1; i < n; i++){
        long long p = (a[i] - a[i - 1] + mod) % mod;
        ans = (ans + (p % mod * ((a[n] - a[i] + mod) % mod))) % mod;
    }
    cout << ans;
    return 0;
}   

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

int main()
{
    int A, B;
    cin >> A >> B;

    for (int i = 1; i < 1010; i++) {
        if ((A == (int)(i * 0.08)) && (B == (int)(i * 0.1))) {
            cout << i << endl;
            return 0;
        }
    }
    cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<ll,ll> P;
typedef pair<ll,P> PP;

void Main() {
  ll n,m,t,T;
  cin >> n >> m >> t;
  vector<P> v[n];
  rep(i,m) {
    ll x,y,z;
    cin >> x >> y >> z;
    x--,y--;
    v[x].pb(P(y,z));
    v[y].pb(P(x,z));
  }
  ll d[n][n][n],c[n][n];
  rep(i,n)rep(j,n)rep(k,n) d[i][j][k]=MAX;
  rep(i,n)rep(j,n) c[i][j]=MAX;
  rep(k,n) {
    d[k][k][0]=-t;
    priority_queue<PP,vector<PP>,greater<PP> > que;
    que.push(PP(0,P(-t,k)));
    while(!que.empty()) {
      PP p=que.top();que.pop();
      ll x=p.S.S,e=p.F,r=p.S.F;
      c[k][x]=min(c[k][x],e);
      rep(i,v[x].size()) {
        ll y=v[x][i].F,w=v[x][i].S;
        if(w>t) continue;
        ll ee=e,cc=r+w;
        if(cc>0) {
          ee++;
          cc=-t+w;
        }
        if(ee>=n) continue;
        if(c[k][y]<=ee) continue;
        if(d[k][y][ee]>cc) {
          d[k][y][ee]=cc;
          que.push(PP(ee,P(cc,y)));
        }
        ee++;
        cc=-t+w;
        if(ee>=n) continue;
        if(d[k][y][ee]>cc) {
          d[k][y][ee]=cc;
          que.push(PP(ee,P(cc,y)));
        }
      }
    }
  }
  R T;
  while(T--) {
    ll x,y;
    cin >> x >> y;
    x--,y--;
    if(c[x][y]==MAX) pr(-1);
    else pr(c[x][y]);
  }
}

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


Measured memory_bytes: 214656
#include <bits/stdc++.h>
using intl = long long;
using itnl = long long;//typo用
using itn = int;//typo用
using ld = long double;
using namespace std;
#define rep(i, n) for(intl i = 0; i < (intl)(n); i++)
#define rrep(i, n) for(intl i = (intl)(n) - 1; i >= 0; i--)
#define repi(i, a, b) for(intl i = (intl)(a); i < (intl)(b); i++)
#define rrepi(i, a, b) for(intl i = (intl)(a) - 1; i >= (intl)(b); i--)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,1,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define alength(a) (sizeof(a) / sizeof(a[0]))
#define debug(x) cout << #x << ":" << x << endl
#define rdebug(i,x) rep(i, alength(x))cout << #x << "[" << i << "]:" << x[i] << endl//1次元配列の出力
#define rrdebug(i, j, x) rep(i, alength(x))rep(j, alength(x[i]))cout << #x << "[" << i << "][" << j << "]:" << x[i][j] << endl//二次元配列の出力
#define pb push_back
#define mp make_pair
#define pii pair<intl,intl>
const intl INF = 1e9;
const intl MOD = 1e9+7;
const ld EPS = 1.0e-14;//-9
const ld PI = acos(-1);
void fp(bool f){cout << (f ? "Yes" : "No") << endl;}
void fp(bool f, string s, string t){cout << (f ? s : t) << endl;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) {a = b; return true;} return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) {a = b; return true;} return false; }
intl gcd(intl a, intl b){ if(!b)return a; return gcd(b, a % b); }
intl lcm(intl a,intl b){ return a / gcd(a, b) * b; }
intl kai(intl k){//k!を求める関数,
    intl a = 1;
    for(int i = 2; i <= k; i++){
        a *= i;
    }
    return a;
}
intl digit10(intl a){//aを10進数で表したときの桁数を求める関数
    intl b = 0;
    do{
        a /= 10;
        b++;
    }while(a);
    return b;
}

signed main(){
    cout << fixed << setprecision(10);
    intl n,m;
    cin >> n >> m;
    vector<tuple<intl,intl,intl> > t(m);
    rep(i,m){
        intl a,b;
        cin >> a >> b;
        t[i] = make_tuple(a,b,i);
    }
    sort(all(t));
    vector<pair<intl, string> > v(m);
    intl num = 0;
    intl idx = 0;
    rep(i,m){
        if(idx != get<0>(t[i])){
            idx = get<0>(t[i]);
            num = 1;
        }
        intl a = get<0>(t[i]);
        intl d = digit10(a);
        intl e = digit10(num);
        string s = "";
        rep(j,6 - d)s += '0';
        s += to_string(a);
        rep(j, 6 - e)s += '0';
        s += to_string(num);
        v[i] = mp(get<2>(t[i]),s);
        //debug(s);
        num++;
    }
    sort(all(v));
    for(auto i : v){
        cout << i.second << endl;
    }
    return 0;
}

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

int main(){
  int a; long long b,n; cin >>a >>b >>n;
  int x=floor(a*(b-1)*1.0/b);
  int y=floor(a*n*1.0/b);
  if(n>=b-1) cout <<x;
  else cout <<y;
return 0;}

Measured memory_bytes: 3716
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  vector<pair<int,int>> ab(N),cd(N);
  for (int i=0;i<N;i++){
    int a,b;
    cin >> a >> b;
    ab[i]=make_pair(a,b);
  }
  for (int i=0;i<N;i++){
    int c,d;
    cin >> c >> d;
    cd[i]=make_pair(d,c);
  }
  sort(ab.begin(),ab.end());
  sort(cd.begin(),cd.end());
  int ans=0;
  for (int i=0;i<N;i++){
    int rec=101;
    for (int j=0;j<N;j++){
      if (ab[j].first<cd[i].second&&ab[j].second<cd[i].first){
        rec=j;
      }
    }
    if (rec>N-1){
      continue;
    }
    else {
      ans++;
      ab[rec]=make_pair(201,201);
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
L,R = map(int, input().split())
'''
if L <= 2019 <= R:
    print(0)
    exit()
'''
ans = 2020
for i in range(L,R):
    x = i % 2019
    for j in range(L+1,R+1):
        y = j % 2019
        tmp = (x * y) % 2019 
        if tmp < ans:
            ans = tmp
        if ans == 0:
            print(ans)
            exit()

print(ans)

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

using namespace std;
using LL = long long;
const LL INF=1LL<<60;

class SegmentTree {
private:
    int st_siz;
    vector<LL> ST_min, ST_max;

public:
    SegmentTree(int siz) {
        st_siz = 1;
        while(st_siz < siz) st_siz *= 2;
        ST_min = vector<LL>(2 * st_siz - 1, INF);
        ST_max = vector<LL>(2 * st_siz - 1, -INF);
    }

    int get_size() {
    	return st_siz;
    }

    void min_init(LL x) {
    	for(int i = 0; i < 2 * st_siz - 1; i++) ST_min[i] = x;
    }

	void max_init(LL x) {
		for(int i = 0; i < 2 * st_siz - 1; i++) ST_max[i] = x;
	}

    void min_update(int i, LL x) {
        i += st_siz - 1;
        ST_min[i] = x;
        while(i > 0) {
            i = (i - 1) / 2;
            ST_min[i] = min(ST_min[i * 2 + 1], ST_min[i * 2 + 2]);
        }
    }

    void max_update(int i, LL x) {
        i += st_siz - 1;
        ST_max[i] = x;
        while(i > 0) {
            i = (i - 1) / 2;
            ST_max[i] = max(ST_max[i * 2 + 1], ST_max[i * 2 + 2]);
        }
    }

    LL RmQ(int a, int b, int k, int l, int r, LL M = INF) {
        if (r <= a || b <= l) return M;
        if (a <= l && r <= b) return ST_min[k];
        else {
            LL m1 = RmQ(a, b, 2 * k + 1, l, (l + r) / 2, M);
            LL m2 = RmQ(a, b, 2 * k + 2, (l + r) / 2, r, M);
            return min(m1, m2);
        }
    }

    LL RMQ(int a, int b, int k, int l, int r, LL M = 0) {
        if (r <= a || b <= l) return M;
        if (a <= l && r <= b) return ST_max[k];
        else {
            LL M1 = RMQ(a, b, 2 * k + 1, l, (l + r) / 2, M);
            LL M2 = RMQ(a, b, 2 * k + 2, (l + r) / 2, r, M);
            return max(M1, M2);
        }
    }
};

int main(){
	int N;
	cin >> N;
	vector<int> h(N);
	rep(i,N) cin >> h[i];
	vector<LL> a(N);
	rep(i,N) cin >> a[i];
	vector<LL> dp(N);
	SegmentTree st(N);
	st.max_init(0);
	rep(i,N){
		int height=h[i]-1;
		dp[height]=st.RMQ(0,height,0,0,st.get_size())+a[i];
		st.max_update(height,dp[height]);
	}
	LL ans=0;
	rep(i,N) ans=max(ans,dp[i]);
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 12416
#include <bits/stdc++.h>
using namespace std;
#define REP(asd, fgh) for(int asd = 0; asd < fgh; asd++)
int n;
int cnt;
long long ans;
vector<int> S;

void merge(vector<int> &A, int left, int mid, int right){
  int n1 = mid - left;
  int n2 = right - mid;
  vector<int> L(n1+1), R(n2+1);
  REP(i, n1){
    L[i] = A[left + i];
  }
  REP(i, n2){
    R[i] = A[mid + i];
  }
  L[n1] = INT_MAX/2;
  R[n2] = INT_MAX/2;
  int i = 0, j = 0;
  for(int k = left; k < right; k++){
    cnt++;
    if(L[i] <= R[j]){
      A[k] = L[i];
      i++;
    }else{
      A[k] = R[j];
      j++;

      ans += n1 - i;
    }
  }

}

void mergeSort(vector<int> &A, int left, int right){
  if(left + 1 < right){
    int mid = (left + right) / 2;
    mergeSort(A, left, mid);
    mergeSort(A, mid, right);
    merge(A, left, mid, right);
  }
}

int main(void){
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  S.resize(n);
  REP(i, n) cin >> S[i];
  mergeSort(S, 0, n);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 2588
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    ios::sync_with_stdio(false); 
    string s1,s2;
    int i,cnt=0;
    cin>>s1>>s2;
    for(i=0;i<s1.length();i++)if(s1[i]!=s2[i])cnt++;
    cout<<cnt;
	return 0; 
}

Measured memory_bytes: 3948
#include<stdio.h>
int main(){
    int w,h,c;
    int i;
    int big=0,small=0;
    int squar;
    scanf("%d %d %d",&w,&h,&c);
    if(w==h){
        squar=1;
    }else{
        if(w>h){
            big=w;
            small=h;
        }else{
            big=h;
            small=w;
        }
        for(i=small;i>0;i--){
            if(small%i==0&&big%i==0){
                squar=(small/i)*(big/i);
                break;
            }
        }
    }
    printf("%d\n",squar*c);
    return 0;
}


Measured memory_bytes: 2708
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <cstring>
#include <cstdlib>
using namespace std;

#define REP(i,n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<int, int> pint;
template <class T> inline void chmax(T &a, const T b) { a = max(a, b); }
template <class T> inline void chmin(T &a, const T b) { a = min(a, b); }
template <class T> void pp(T v, int n) { REP(i,n) cout<<v[i]<< ' '; cout << endl; }

const ll MOD = 1000 * 1000 *1000 + 7 ;
inline void chadd(ll &a, const ll b) { a = (a + b) % MOD;}
inline ll add(const ll a, const ll b){ return (a + b) %  MOD;}
inline void chsub(ll &a, const ll b) { a = (a - b + MOD) % MOD;}
inline ll sub(const ll a, const ll b){ return (a - b + MOD) % MOD; }
inline void chmul(ll &a, const ll b) { a = (a * b) %  MOD;}
inline ll mul(const ll a, const ll b){ return (a * b) %  MOD;}

const int MOD_TABLE_SIZE = 1000000 + 10;
ll inv[MOD_TABLE_SIZE];
ll fac[MOD_TABLE_SIZE];
ll facinv[MOD_TABLE_SIZE];

void mod_table_init() {
  inv[1] = 1;
  for(int i = 2; i < MOD_TABLE_SIZE; i++) {
    inv[i] = MOD - (MOD / i) * inv[(int)MOD % i] % MOD;
  }
  fac[0] = facinv[0] = 1;
  for(int i = 1; i < MOD_TABLE_SIZE; i++) {
    fac[i] = (fac[i-1] * (ll)i) % MOD;
    facinv[i] = (facinv[i-1] * inv[i]) % MOD;
  }
}

inline ll P(int a, int b) {
#ifdef DEBUG
  cout << "P(" << a << "," << b << ")" << endl;
#endif
  if(a<b) return 0LL;
  return fac[a] *  facinv[a-b] % MOD;
}

inline ll C(int a, int b) {
  if(a<b) return 0LL;
  return (fac[a] * facinv[b] % MOD) * facinv[a-b] % MOD;
}

inline ll H(int a, int b) {
  return C(a+b-1,b);
}

void inline TorF(bool tf, const string &trueMessage, const string &falseMessage) { 
  cout << (tf ? trueMessage : falseMessage) << endl;
}
void inline YESNO(bool tf) { TorF(tf, "YES", "NO"); }
void inline YesNo(bool tf) { TorF(tf, "Yes", "No"); }

ll ans = 1;
int N, K;
vector<vector<int> > G;
vector<bool> visited;
void init() {
  ans = 1;
  mod_table_init();
}
void dfs(const int cur, const int old) {
  visited[cur] = false;
  int m = G[cur].size() -1;
  chmul(ans, P(K-2, m));
  REP(i,G[cur].size()) {
    if(G[cur][i]==old) continue;
    dfs(G[cur][i], cur);
  }
  
}

int main() {
  init();
  cin>>N>>K;
  G = vector<vector<int> >(N);
  visited = vector<bool>(N, false);
  REP(i,N-1) {
    int a, b; cin>>a>>b; a--; b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  visited[0] = true;
  int m = G[0].size();
  chmul(ans, P(K, m+1));
  REP(i, m) {
    dfs(G[0][i], 0);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 32640
#include <bits/stdc++.h>
using namespace std;
 
int main () {
  string S;
  cin >> S;
  bool ok = true;
  int size = S.size();
  for (int i = 0; i < size; i++) { 
    if (S.at(i) != S.at(size - i - 1)) {
      ok = false;
    }
  }
  for (int i = 0; i < (size - 1) / 2; i++) { 
    if (S.at(i) != S.at((size - 1) / 2 - i - 1)) {
      ok = false;
    }
  }
  int j = 0;
  for (int i = (size + 3) / 2; i <= size; i++) { 
    if (S.at(i - 1) != S.at(size - j - 1)) {
      ok = false;
    }
    j++;
  } 
  if (ok) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 3640
using System;

namespace abca093
{
    class Program
    {
        static void Main(string[] args)
        {
            string s = Console.ReadLine();
           
            bool a = false;
            bool b = false;
            bool c = false;
            char[] chr = s.ToCharArray();
            if (chr[0] == 'a' || chr[1] == 'a' || chr[2] == 'a')
                a= true;
            if (chr[0] == 'b' || chr[1] == 'b' || chr[2] == 'b')
                b = true;
            if (chr[0] == 'c' || chr[1] == 'c' || chr[2] == 'c')
                c = true;
            if (a == true && b == true && c == true)
                Console.WriteLine("Yes");
            else
                Console.Write("No");








        }
    }
}


Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;
int INF = 1000000007;
 
int main(){
  int D, N;
  cin >> D >> N;
  if(D == 0){
    if(N != 100) cout << N << endl;
    else cout << 101 << endl;
  }
  else if(D == 1){
    if(N != 100) cout << N * 100 << endl;
    else cout << 10100 << endl;
  }
  else{
    if(N != 100) cout << N * 10000 << endl;
    else cout << 101 * 10000 << endl;
  }
}

Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <complex>
#include <vector>
#include<limits>
#include<iomanip>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;

const long double pi = 3.141592653589793;

#define debug(x) cout << #x << " = " << (x) << endl;
#define rep(i, n) for(int i = 0;i < n;i++)
#define repi(i, j, n) for(int i = j;i < n;i++)
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define F first
#define S second

// #define COMMENT

/*

const int NN = 200090;
ll fact[NN];
ll finv[NN];
ll inv[NN];

void inverse_modulao() {
  fact[0] = fact[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;

  for(int i = 2;i < NN;i++) {
    fact[i] = fact[i-1]*i%mod;
    inv[i] = mod-mod/i*inv[mod%i]%mod;
    finv[i] = finv[i-1]*inv[i]%mod;
  }
}

ll nCr(int n, int r) {
  return fact[n]*finv[r]%mod*finv[n-r]%mod;
}

*/

int MXM = 1000000;
int A[1<<20], B[1<<20], n, num;

int main() {

//  freopen("input.in","r",stdin);
 // freopen("output.out","w",stdout);
  cin>>n;
  rep(i,n) {cin>>num;A[num]++;}
  for(int i = 1;i <= MXM;i++) {
    if(A[i]) {
      int j = 2*i;
      while(j <= MXM) {
        B[j]++;
        j += i;
      }
    }
  }
  int ans=0;
  for(int i = 1;i <= MXM;i++) {
    if(A[i] == 1 && B[i] == 0) {
      ans++;
    }
  }
  cout<<ans;


  return 0;
}


Measured memory_bytes: 11440