akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long N,K;
  cin>>N>>K;
  long long x=(K*((N+K-1)/K))-N;
  long long y=N-K*(N/K);
  if(N>=K){
    if(x>=y){
      cout<<y<<endl;
    }
    else{
      cout<<x<<endl;
    }
  }
  else{
    long long z=K-N;
    if(z>=N){
      cout<<N<<endl;
    }
    else{
      cout<<z<<endl;
    }
  }
  return 0;
}


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

using namespace std;

int main()
{
    int N,K;
    int counter = 1;
    cin >> N >> K;
    while(true){
        N /=K;
        if(N > 0) counter++;
        else break;
    }
    cout << counter << "\n";

    return 0;
}

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

int left(int i){return i*2;}
int right(int i){return i*2+1;}
void maxHeapify(std::vector<int>& A, int i)
{
    int H = A.size();
    int l = left(i);
    int r = right(i);
    int largest;
    if(l <= H && A[l] > A[i]){
        largest = l;
    }else{
        largest = i;
    }
    if(r <= H && A[r] > A[largest]){
        largest = r;
    }
    if(largest != i){
        std::swap(A[i], A[largest]);
        maxHeapify(A, largest);
    }
}

void buildMaxHeap(std::vector<int>& A)
{
    int H = A.size() + 1;
    for(std::size_t i = H/2; i; --i){
        maxHeapify(A, i);
    }
}

int main()
{
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    int H;
    std::cin >> H;
    std::vector<int> A(H+1);
    for(std::size_t i = 1; i <= H; ++i){
        int Value;
        std::cin >> Value;
        A[i] = Value;
    }
    buildMaxHeap(A);
    for(std::size_t i = 1; i <= H; ++i){
        std::cout << " " << A[i];
    }
    std::cout << std::endl;
    return 0;
}

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

int p[1010];

int main() {
	int n, k;
	int sum = 0;

    ios::sync_with_stdio(false);
    cin.tie(0);

	cin >> n >> k;

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

	int len = sizeof(p) / sizeof(int);
//	cout << "len" << len << endl;
	sort(p, p+n);


	for(int i = 0; i < k; i++) {
//		cout << p[i] << endl;
		sum += p[i];
	}

	cout << sum << endl;

	return 0;
}


Measured memory_bytes: 3532
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <deque>
#include <cassert>
#include <complex>
#include <iomanip>
#include <random>

using namespace std;

typedef long long ll;
#define int long long

int M = (int)1e9 + 7;
#define msum(a, b) ((a) + (b) >= M ? (a) + (b) - M : (a) + (b))
#define msub(a, b) ((a) - (b) < 0 ? (a) - (b) + M : (a) - (b))
#define mmult(a, b) (((a) * (b)) % M)

typedef long double ld;
typedef vector<char> vc;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vlll;
typedef vector<double> vd;
typedef vector<vd> vdd;
typedef vector<bool> vb;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vpi;
#define inmin(a, b) a = min(a, (b))
#define inmax(a, b) a = max(a, (b))
#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
#define SZ(a) ((int)(a).size())
#define watch(x) cout << (#x) << " = " << (x) << endl;

const double PI = 2 * acos(0.0);
const int oo = 1e18 + 100;
const string DIGITS = "0123456789", alph = "abcdefghijklmnopqrstuvwxyz", ALPH = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

//THE END OF TEMPLATE////////////////////////////////////////////////////////////////////////////////

#define N 3100



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

	int n, w, sm = 0;
	cin >> n >> w;
	vi a(n + 1), b(n + 1);
	for (int i = 1; i <= n; i++) {
		cin >> a[i] >> b[i];
		sm += b[i];
	}
	vvi dp(n + 1, vi(sm + 1, oo));

	for (int i = 0; i <= n; i++)
		dp[i][0] = 0;


	for (int i = 1; i <= n; i++)
	{
		for (int j = 0; j <= sm; j++)
		{
			dp[i][j] = dp[i - 1][j];
			if (j - b[i] >= 0)
				inmin(dp[i][j], dp[i - 1][j - b[i]] + a[i]);
		}
	}

	int mx = 0;
	for (int i = 0; i <= sm; i++)
		if (dp[n][i] <= w)
			mx = i;


	
	cout << mx;




}

//m1.codeforces.com, m2.codeforces.com или m3.codeforces.com

Measured memory_bytes: 80256
//package com.zhangyong.algorithm;

import java.io.*;
import java.util.StringTokenizer;

public class Main {

    FastScanner in;
    PrintWriter out;

    class FastScanner {

        BufferedReader br;
        StringTokenizer st;

        private FastScanner(File f) {
            try {
                br = new BufferedReader(new FileReader(f));
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
        }

        private FastScanner(InputStream f) {
            br = new BufferedReader(new InputStreamReader(f));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

    }


    private void solve() {
        int num, l = 0, r = 0;
        for (int i = 0; i < 3; i++) {
            num = in.nextInt();
            if (num == 5) {
                l += 1;
            } else if (num == 7) {
                r += 1;
            }
        }
        if (l == 2 && r == 1) {
            out.print("YES");
        } else {
            out.print("NO");
        }
    }

    private void run() {
        in = new FastScanner(System.in);
        out = new PrintWriter(System.out);
        solve();
        out.close();
    }

    public static void main(String[] args) {
        new Main().run();
    }
}


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

#define int long long
#define double long double
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, n) for (int i = 1; i <= (n); i++)
#define all(x) (x).begin(), (x).end()
#define uniq(x) (x).erase(unique(all(x)), (x).end())
#define bit(n) (1LL << (n))
#define dump(x) cerr << #x " = " << (x) << endl
using vint=vector<int>;
using vvint=vector<vint>;
using pint=pair<int, int>;
using vpint=vector<pint>;
template<typename T> using priority_queue_rev=priority_queue<T, vector<T>, greater<T>>;
constexpr double pi = 3.1415926535897932384626433832795028;
constexpr int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int gcd(int a, int b) {
    while (b) { swap(a %= b, b); }
    return a;
}
int lcm(int a, int b) { return a / gcd(a, b) * b; }
template<typename T1, typename T2> bool chmax(T1 &a, const T2 &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T1, typename T2> bool chmin(T1 &a, const T2 &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &rhs) {
    os << "(" << rhs.first << ", " << rhs.second << ")";
    return os;
}
template<typename T> ostream &operator<<(ostream &os, const vector<T> &rhs) {
    os << "{";
    for (auto itr = rhs.begin(); itr != rhs.end(); itr++) {
        os << *itr << (next(itr) != rhs.end() ? ", " : "");
    }
    os << "}";
    return os;
}
struct setup {
    static constexpr int PREC = 20;
    setup() {
        cout << fixed << setprecision(PREC);
        cerr << fixed << setprecision(PREC);
    };
} setup;

int n;
int a[110000];
signed main() {
    cin >> n;
    rep(i, n) { cin >> a[i]; }

    int ans0 = 0, cur0 = 0;
    rep(i, n) {
        cur0 += a[i];
        if (i & 1) {
            if (cur0 >= -1) { ans0 += cur0 + 1, cur0 = -1; }
        } else {
            if (cur0 <= 1) { ans0 += -cur0 + 1, cur0 = 1; }
        }
    }

    int ans1 = 0, cur1 = 0;
    rep(i, n) {
        cur1 += a[i];
        if (!(i & 1)) {
            if (cur1 >= -1) { ans1 += cur1 + 1, cur1 = -1; }
        } else {
            if (cur1 <= 1) { ans1 += -cur1 + 1, cur1 = 1; }
        }
    }
    cout << min(ans0, ans1) << endl;
}


Measured memory_bytes: 1024
#include <iostream>

using namespace std;

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

    if (a%2==0 && a==b && b==c) {
        cout << -1 << endl;
        return 0;
    }

    int ans = 0;
    while(!(a%2 || b%2 || c%2)) {
        int at = b/2 + c/2;
        int bt = a/2 + c/2;
        int ct = a/2 + b/2;
        a = at;
        b = bt;
        c = ct;
        ans++;
    }

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,n1,n2) for(int i=n1;i<n2;i++)
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
typedef pair<int,int> Pi;
typedef long long int ll;
const int INF=(ll)(1<<30)-1;
const ll INFl=(ll)9223372036854775807;
const int MAX=10000;
const ll MOD=(ll)1e9+7;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a, b)*b;}
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

ll n;
int a[100100];
int b[100100];
int c[100100];

int main(){
	cin>>n;
	REP(i,n)
		cin>>a[i];
	sort(a,a+n);
		
	REP(i,n)
		cin>>b[i];
	sort(b,b+n);
		
	REP(i,n)
		cin>>c[i];
	sort(c,c+n);
	ll ans=0;
	for(int i=0;i<n;i++){
		int s=0;
		int t=0;
		auto it=lower_bound(a,a+n,b[i]);
		if(it!=a+n||*it<b[i]){
			s=distance(a,it);
		}
		it=upper_bound(c,c+n,b[i]);
		if(it!=c+n){
			t=distance(it,c+n);
		}
		ans+=(ll)s*t;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 1408
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 2e5 + 10;
#define fi first
#define se second
#define pb push_back
#define wzh(x) cerr<<#x<<'='<<x<<endl;
int n,k,l[N],r[N];
const LL mod=998244353;
LL dp[N],s[N];
int main() {
  ios::sync_with_stdio(false);
  cin>>n>>k;
  for(int i=1;i<=k;i++)cin>>l[i]>>r[i];dp[1]=1;s[1]=1;
  for(int i=2;i<=n;i++){
    for(int j=1;j<=k;j++){
      int L=max(1,l[j]);
      int R=min(i-1,r[j]);
      if(L>R)continue;
      (dp[i]+=(0ll+s[i-(L)]-s[i-R-1]+mod)%mod)%=mod;
    }
    (s[i]=s[i-1]+dp[i])%=mod;
  }
  cout<<dp[n]<<endl;
  return 0;
}

Measured memory_bytes: 6712
#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);
  }
  sort(a.begin(), a.end());
  double p = a.at(n-1)/2.0, q;
  int x;
  for (int i = 0; i < n-1; i++) {
    double r = fabs(a.at(i)-p);
    if (i == 0) {
      q = r;
      x = 0;
    }
    else  {
      if (r < q) {
        q = r;
        x = i;
      }
    }
  }
  cout << a.at(n-1) << ' ' << a.at(x) << endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <functional>
#include <iterator>
#include <limits>
#include <numeric>
#include <utility>
#include <cmath>
#include <cassert>
#include <cstdio>

// #include <unordered_set>
// #include <unordered_map>

#define rep(i, a, n) for(int i = a; i < n; i++)
#define REP(i, n) rep(i, 0, n)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())

#define pb push_back
#define mp make_pair

int gcd(int a,int b){int c;while(b!=0){c=a%b;a=b;b=c;}return a;}
int lcm(int a,int b){int c=gcd(a,b);a/=c;return a*b;}

typedef std::pair<int, int> P;
typedef long long ll;
typedef long double ld;

const int MOD = 1000000007;
const int INF = 1e9;
const ll LINF = INF * 1ll * INF;
const ld DINF = 1e200;
const double EPS = 1e-10;
const double PI  = acos(-1.0);

using namespace std;

// #define int long long



signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    //cin高速化

    string s;
    cin>>s;

    for(int i=0;i<s.size()-1;i++){
        if(s[i]=='A'&&s[i+1]=='C'){
            cout<<"Yes"<<endl;
            return 0;
        }
    }

    cout<<"No"<<endl;

    return 0;

}

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

int main(){
  int h,w,ig[100],icnt=0;
  char sp[100][100];
  cin>>h>>w;
  for(int i=0; i<h; i++){
    bool alldot=true;
    for(int j=0; j<w; j++){
      cin>>sp[i][j];
      if(sp[i][j]!='.') alldot=false; 
    }
    if(alldot){
      h--;
      i--;
      continue;
    }
  }
  for(int j=0; j<w; j++){
    bool alldot=true;
    for(int i=0; i<h; i++){
      if(sp[i][j]!='.'){ alldot=false;}
    }
    if(alldot){
      ig[icnt]=j;
      icnt++;
      // continue;
    }
  }
  for(int i=0; i<h; i++){
    for(int j=0; j<w; j++){
      bool isok=true;
      for(int k=0; k<icnt; k++){
	if(ig[k]==j)isok=false;
      }
      if(isok)cout<<sp[i][j];
    }
    cout<<endl;
  }
}



Measured memory_bytes: 256
//#include <bits/stdc++.h>
//#include <stdio.h>
#include<iostream>
#include<cstdio>
#include<bitset>
#include<algorithm>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<string>
#include<string.h>
#include<cmath>
#include<utility>
#include<functional>
#include<map>
#include<set>
#include<cctype>
#include<fstream>
 
 
#define FOR(i, a, b) for( int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for( int i=(a);i>=(b);i--)
#define LFOR(i, a, b) for( long long int i=(a);i<=(b);i++)
#define LRFOR(i, a, b) for(long long int i=(a);i>=(b);i--)
#define MOD 1000000007
#define INF 1000000000 //2000000000
#define LINF 1000000000000000000 //9000000000000000000
#define PI 3.14159265358979
#define MAXI 7500000
 
using namespace std;
typedef long long int ll;
typedef pair< long long int, long long  int> P;
 
int dy[5] = { 0,0,1,-1,0 };
int dx[5] = { 1,-1,0,0,0 };
 
 
int main(void) {
    int a,b,c;
	bool flag=false;

	cin>>a>>b>>c;

	FOR(i,1,b){
		if((a*i)%b==c){
			flag=true;
			break;
		}
	}

	if(flag){
		cout<<"YES"<<endl;
	}else{
		cout<<"NO"<<endl;
	}

	return 0;
}

Measured memory_bytes: 256
I=lambda:map(int,input().split());F=1e21;r=range;n,m=I();f=[-F,F];X=[0]+f;Y=X[:];R=[(f,F),(f,-F)];H=[(F,f),(-F,f)]
for i in r(n):*a,c=I();R+=[(a,c)];Y+=c,;X+=a
for i in r(m):a,*b=I();H+=[(a,b)];X+=a,;Y+=b
def g(X):s=dict(enumerate(sorted(set(X))));return{s[i]:i for i in s},s,len(s)+1
h,s,K=g(X);w,t,L=g(Y);j=lambda:[[0]*-~K for i in r(L+1)];V=j();U=j();v=j()
for(a,b),c in R:U[w[c]][h[a]]+=1;U[w[c]][h[b]]+=-1
for d,(e,f)in H:V[w[e]][h[d]]+=1;V[w[f]][h[d]]+=-1
for i in r(L):
 for j in r(K):U[i][j+1]+=U[i][j];V[i+1][j]+=V[i][j]
q=[(h[0],w[0])];v[w[0]][h[0]]=1;a=0
while q:
 x,y=q.pop();a+=(s[x]-s[x+1])*(t[y]-t[y+1])
 for e,f in[(-1,0),(1,0),(0,1),(0,-1)]:
  c=x+e;d=y+f
  if 1-v[d][c]and(U[(f>0)+y][x]|e==0)|(V[y][(e>0)+x]|f==0):q+=[(c,d)];v[d][c]=1
print([a,'INF'][a>F])

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

using namespace std;

typedef long long ll;
typedef long double ld;

const int M = 100100;

int n, m, q;
int a[M];
bool used[M];
int cnt[M];
int ord[M];
vector<int> seq;

void read() {
  cin >> n >> m >> q;
  for (int i = 0; i < q; ++i) {
    cin >> a[i];
    --a[i];
  }
  reverse(a, a + q);
}

void nx(int i) {
  assert(i < m);
  if (cnt[i] > 0) {
    --cnt[i];
    ++cnt[i + 1];
  }
}

void add(int x) {
  if (!used[x]) {
    int f = seq.size();

    used[x] = true;
    ord[x] = f;

    nx(f);
    seq.push_back(x);
  } else {
    int k = ord[x];
    nx(k);
  }
}

void kill() {
  cnt[0] = n;

  for (int i = 0; i < q; ++i)
    add(a[i]);

  for (int i = 0; i < m; ++i)
    if (!used[i])
      seq.push_back(i);

  int sh = 0;
  while (!cnt[sh])
    ++sh;
  
  auto alt = seq;
  sort(alt.begin() + sh, alt.end());

  if (alt == seq) {
    cout << "Yes\n";
  } else {
    cout << "No\n";
  }
}

int main() {
  cout.precision(20);
  cout << fixed;
  ios_base::sync_with_stdio(false);
  read();
  kill();
}


Measured memory_bytes: 2424
#include<bits/stdc++.h>
using namespace std;
#define pb  push_back
#define mod 1000000007
#define INF 1e18
typedef  long long ll;

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int n;
	cin>>n;
	ll arr[n];
	ll pre[n];
	for (int i = 0; i < n; ++i)
	{
		cin>>arr[i];
	}
	pre[0]=arr[0];
	for (int i = 1; i <n; ++i)
	{
		pre[i]=(pre[i-1]+arr[i])%mod;
		// cout<<pre[i]<<" ";
	}
	// cout<<endl;
	ll ans=0;
	for (int i = 1; i <= n-1; ++i)
	{
		ll temp=(pre[i]+mod-arr[i])%mod;
		ans=((temp*arr[i])+ans)%mod;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 6764
// AtCoder Beginner Contest 054
// C - One-stroke Path
// https://atcoder.jp/contests/abc054/tasks/abc054_c
// https://book.mynavi.jp/manatee/detail/id=65960
#include <bits/stdc++.h>
using namespace std;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef vvi graph;
#define rep(i, n) for(int i = 0; i < (n); i++)
template<class T> istream& operator >> (istream& s, vector<T>& v)
{ for (T& x: v) { s >> x; } return s;}

int dfs(graph& g, vb& f, int v, int depth)
{
    if (f[v]) return 0;
    if (depth == g.size()) return 1;

    int res = 0;
    f[v] = true;
    for (int i = 0; i < g[v].size(); i++) {
        if (!f[g[v][i]]) res += dfs(g, f, g[v][i], depth+1);
    }
    f[v] = false;
    return res;
}

int main()
{
    int N, M; cin >>N>>M;
    graph g(N);
    rep(i, M) {
        int a, b; cin >> a >> b; a--; b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }

    vb f(N, false);
    cout << dfs(g, f, 0, 1) << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

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

        int n = scan.nextInt();
        int m = scan.nextInt();
        int l = scan.nextInt();
        long [][]A;
        A = new long[n][m];
        long [][]B;
        B = new long[m][l];
        long [][]C;
        C = new long[n][l];
        int i,j,k;

        for(i = 0; i < n; i++){
            for(j = 0; j < m; j++){
            A[i][j] = scan.nextLong();
            }
        }
        for(j = 0; j < m; j++){
            for(k = 0; k < l; k++){
            B[j][k] = scan.nextLong();
            }
        }
        for(k = 0; k < l; k++){
            for(j = 0; j < m; j++){
                for(i = 0; i < n; i++){
                C[i][k] += A[i][j]*B[j][k];
                }
            }
        }
        for(i = 0; i< n; i++){
        	for(k = 0; k< l; k++){
        		if(k != l-1){
        			System.out.print(C[i][k]+" ");
        		}
        		else{
        			System.out.println(C[i][k]);
        		}
        	}
        }      
    }
}     

Measured memory_bytes: 54052
import java.util.Scanner;

public class Main {

    public static void main(String[] args){
        Scanner in = new Scanner(System.in);
        int a = in.nextInt();
        int b = in.nextInt();
        int c = in.nextInt();
        if (a != b && a != c){
            System.out.println(a);
        }
        else if (b != a && b != c){
            System.out.println(b);
        }
        else{
            System.out.println(c);
        }
        
    }
}

Measured memory_bytes: 25556
import java.io.BufferedReader
import java.io.InputStreamReader

fun isPrime(n: Int): Boolean {
    when (n) {
        0 -> return false
        1 -> return false
        else -> return (2..Math.sqrt(n.toDouble()).toInt()).all { n % it != 0 }
    }
}

fun main(args: Array<String>) {
    BufferedReader(InputStreamReader(System.`in`))
            .readText()
            .trim()
            .split(regex = """\s+""".toRegex())
            .map { it.toInt() }
            .drop(n = 1)
            .filter { isPrime(it) }
            .count()
            .let { println(it) }
}



Measured memory_bytes: 36832
#include <iostream>
#include <cstring>
#include <stdlib.h>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <math.h>
#include <string>
#include <map>
#include <iomanip>
using namespace std;

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

void print_vector(vector<ll> vt){
    for(auto v: vt){
        cout << v;
    }
    cout << endl;
}

ll N;
vector<ll> A;

int main()
{
    cin >> N;
    ll sum=0;
    A.push_back(0);
    for(int i=1; i<=N; i++){
        int tmp;
        cin >> tmp;
        A.push_back(tmp);
        sum+=abs(A[i]-A[i-1]);
    }
    A.push_back(0);
    sum+=abs(A[N]);
    for(int i=1; i<=N; i++){
        cout << sum - (abs(A[i]-A[i-1])+abs(A[i]-A[i+1])-abs(A[i+1]-A[i-1])) << endl;
    }
    

    return 0;
}


Measured memory_bytes: 2164
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=5e15;

int main() {
  ll n;
  cin >> n;
  ll l=0,r=n-1;
  cout << l << endl;
  string s0,sn;
  cin >> s0;
  if(s0=="Vacant") return 0;
  cout << r << endl;
  cin >> sn;
  if(sn=="Vacant") return 0;
  while(1) {
    ll m=(l+r)/2;
    cout << m << endl;
    string s;
    cin >> s;
    if(s=="Vacant") return 0;
    if(m%2==l%2) {
      if(s==s0) l=m;
      else {
        r=m;
        sn=s;
      }
    }
    else {
      if(s==s0) {
        r=m;
        sn=s;
      }
      else {
        l=m;
        s0=s;
      }
    }
  }
}

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

#define int long long

using namespace std;
#define rep(i,s,n) for(int i = s;i<n;i++)
#define repe(i,s,n) for(int i = s;i<=n;i++)
#define rrep(i,s,n) for(int i = (n)-1;i>=(s);i--)
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
typedef pair<pint,int> P1;
typedef pair<int,pint> P2;
static const ll maxLL = (ll)1 << 62;
const ll MOD=1000000007,INF=1e18;
int dy[]={-1,0,1,0};
int dx[]={0,1,0,-1};




string s;
 
signed main(){
	cin>>s;
	int cnt,ans;
	bool can=false;
	if(s[s.size()-1]=='B'){
	    cnt=0;
	    rep(i,0,s.size()-1){
	        if(s[i]=='W'&&s[i+1]=='B')cnt++;
	    }
	    if(s[0]=='B')can=true;
	    ans=cnt;
	}else{
	    cnt=0;
	    rep(i,0,s.size()-1){
	        if(s[i]=='B'&&s[i+1]=='W')cnt++;
	    }
	    if(s[0]=='W')can=true;
	    ans=cnt;
	}
	if(can)cout<<ans*2<<endl;
	else cout<<ans*2-1<<endl;
	
	
	
	
	
	
	
	return 0;
}

Measured memory_bytes: 512
#include<cstdint>
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include <sstream>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<deque>
#include<stack>
#include<iterator>
#include<stack>
#include<cctype>
#include<climits>
#include<string>
#include<bitset>
#include<cfloat>
#include<iomanip>
#include<numeric>
#include<utility>
#include<initializer_list>


#define repi(i,start,end)for(int64_t (i)=(start);(i)<(end);++(i))
#define rep(i,end) repi((i),0,(end))
#define rfor(x, v) for(auto& (x) : (v))
#define iterate(itr, v) for(auto (itr)=(v).begin();(itr)!=(v).end();++(itr))
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define vin(v) rep(i,(v).size()) cin >> (v)[i];
#define vpin(v) rep(i,(v).size()) cin >> (v)[i].first >> (v)[i].second

using namespace std;
using Int = int64_t;
using pint = pair<Int, Int>;
using vint = vector<Int>;
using vvint = vector<vint>;
using vpint = vector<pint>;
using vstr = vector<string>;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1;  } return 0;  }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1;  } return 0;  }
template<class T>void put_double(T a){cout<<setprecision(12);cout<<a<<"\n";}
template<class T>void println(T a){cout << a << "\n";}
template<class T>void put_line(T &v){iterate(itr,v){cout<<*itr<<((itr==--v.end())?"\n":" ");}}
// auto [x, y] = make_tuple(3, 4); => let (x, y) = (3, 4);

int main(void) {
    string s, t; cin >> s >> t;
    rep(i, s.size()) {
        if(s[i] != t[i]) {
            println("No");
            return 0;
        }
    }
    println("Yes");

    return 0;
}


Measured memory_bytes: 3596
#include<bits/stdc++.h>
using namespace std;
int main(){
  	long long int n,sum=0;
    double m;
  	int c = 0;
    cin >> n >> m;
    vector<long long int> a(n);
    for(long long int i = 0; i < n ; i++){
        cin >> a[i];
        sum += a[i];
    }
    sort(a.begin(), a.end(), greater<long long int>());
 
   
    while(a[c]>=sum/(4*m)){
        c++;
    }
 
    if(c >= m){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
 
 
 
    return 0;
}  


Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

#[test]
fn test() {
    assert_eq!(tenki("CSS".to_string(),"CSR".to_string()), 2);
    assert_eq!(tenki("SSR".to_string(),"SSR".to_string()), 3);
    assert_eq!(tenki("RRR".to_string(),"SSS".to_string()), 0);

}

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
            .bytes()
            .map(|c| c.expect("failed to read char") as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect();
    token.parse().ok().expect("failed to parse token")
}

fn tenki(s: String, t: String) -> u8 {
    let mut ans = 0;
    let sv :Vec<char> = s.chars().collect();
    let tv :Vec<char> = t.chars().collect();
    for i in 0..3 {
        if sv[i] == tv[i] {
            ans += 1;
        }
    }
    ans
}

fn main() {
    let s: String = read();
    let t: String = read();
    println!("{}", tenki(s, t));

}



Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1145141919810893364
typedef pair<int,int> PP;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
#define int ll
#define setdouble setprecision
#define REP(i,n) for(int i=0;i<(n);++i)
#define OREP(i,n) for(int i=1;i<=(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define GOODBYE cout << -1 << endl;return 0
#define MM <<" "<<
#define Endl endl
 
signed main(void){
    int N;
    int A[57];
    cin >> N;
    REP(i,N){
        cin >> A[i];
    }
    int Ans=0;
    while(1){
        bool ch=true;
        REP(i,N){
            if(A[i]>=N){
                ch=false;
            }
        }
        if(ch==true){
            break;
        }
        REP(i,N){
            if(A[i]>=N){
                int E=A[i]/N;
                A[i]-=E*N;
                REP(j,N){
                    if(i==j)continue;
                    A[j]+=E;
                }
                Ans+=E;
            }
        }
    }
    cout << Ans << endl;
 
    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);
		Dice dc = new Dice();

		for (int i = 0; i < 6; i++) {
			dc.n[i] = sc.nextInt();
		}
		int q = sc.nextInt();
		int top, front;
		int[] r = new int[q];
		for (int i = 0; i < q; i++) {
			top = sc.nextInt();
			front = sc.nextInt();
			r[i] = dc.getRight(top, front);
		}

		for (int i = 0; i < q; i++) {
			System.out.println(r[i]);
		}
	}

}

class Dice {
	public int[] n = new int[6];
	private int temp = 0;

	void north() {
		temp = n[0];
		n[0] = n[1];
		n[1] = n[5];
		n[5] = n[4];
		n[4] = temp;
	}

	void south() {
		temp = n[0];
		n[0] = n[4];
		n[4] = n[5];
		n[5] = n[1];
		n[1] = temp;
	}

	void west() {
		temp = n[0];
		n[0] = n[2];
		n[2] = n[5];
		n[5] = n[3];
		n[3] = temp;
	}

	void east() {
		temp = n[0];
		n[0] = n[3];
		n[3] = n[5];
		n[5] = n[2];
		n[2] = temp;
	}
	void right() {
        temp = n[1];
        n[1] = n[2];
        n[2] = n[4];
        n[4] = n[3];
        n[3] = temp;
    }

	int getRight(int t, int f) {
		for (int i = 0; i < 3; i++) {
			if (t == n[0]) {
				break;
			}
			north();
			if (t == n[0]) {
				break;
			}
			west();
		}
		for (int i = 0; i < 3; i++) {
			if (f == n[1]) {
				break;
			}
			right();
		}
		return n[2];
	}

}


Measured memory_bytes: 26088
#include <iostream>

using namespace std;

void solve()
{
	int n;
	while(cin >> n, n)
	{
		int price = 0;
		while(n--)
		{
			int x, y, h, w;
			cin >> x >> y >> h >> w;
			int size = x + y + h;
			if(size <= 60 && w <= 2)
			{
				price += 600;
			}
			else if(size <= 80 && w <= 5)
			{
				price += 800;
			}
			else if(size <= 100 && w <= 10)
			{
				price += 1000;
			}
			else if(size <= 120 && w <= 15)
			{
				price += 1200;
			}
			else if(size <= 140 && w <= 20)
			{
				price += 1400;
			}
			else if(size <= 160 && w <= 25)
			{
				price += 1600;
			}
			else
			{
				continue;
			}
		}
		cout << price << endl;
	}
}

int main()
{
	solve();
	return(0);
}

Measured memory_bytes: 1160
#include <stdio.h>
int main(void)
{
    int a[20000], b[20000] ,c ,i ,count;
    char op[20000];
    
    for(i=0;i<20000;i++){
    	scanf("%d %c %d",&a[i] ,&op[i] ,&b[i]);
    	if(op[i] == '?'){
    		break;
    	}
    }
   
   count = i;
   
   for(i=0;i<count;i++){
   		if(op[i] == '+'){
    		c = a[i] + b[i];
    	}
    	if(op[i] == '-'){
    		c = a[i] - b[i];
    	}
    	if(op[i] == '*'){
    		c = a[i] * b[i];
    	}if(op[i] == '/'){
    		c = a[i] / b[i];
    	}
    	printf("%d\n",c);
   }
    
    return 0;
}

Measured memory_bytes: 616
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc=new Scanner(System.in);
		int A=sc.nextInt();
		int B=sc.nextInt();
		int C=sc.nextInt();
		int L=0;
		while(L<C) {
			B=B-A;
			if(B>=0) {
				L++;
			}
			else {
				break;
			}
		}
		System.out.println(L);
	}
}

Measured memory_bytes: 22868
import sys
from collections import defaultdict
int1 = lambda x: int(x) - 1
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

H, W = map(int, readline().split())
A = [readline().decode().rstrip() for _ in range(H)]

dicts = defaultdict(int)
for a in A:
    for c in a:
        dicts[c] += 1

g1 = H * W % 2
g2 = (H // 2) * (W % 2) + (W // 2) * (H % 2)
g4 = (H // 2) * (W // 2)

for _ in range(g1):
    for k, v in dicts.items():
        if (v % 4 == 1) | (v % 4 == 3):
            dicts[k] -= 1
            break

for _ in range(g2):
    for k, v in dicts.items():
        if v % 4 == 2:
            dicts[k] -= 2
            break
"""for _ in range(g4):
    for k, v in dicts.items():
        if (v % 4 == 0) & (v != 0):
            dicts[k] -= 4
            break
"""
for k, v in dicts.items():
    if v % 4 != 0:
        print('No')
        sys.exit()

print("Yes")


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

int main() {
	int n;
	cin >> n;
	int a[n + 1];
	for (int i = 1; i <= n; i++) {
		int temp;
		scanf("%d",&temp);
		a[temp] = i;
	}
	int ans = 0, temp = 1;
	for (int i = 2; i <= n; i++) {
		if (a[i] > a[i - 1]) {
			temp++;
		} else {
			ans = max(ans, temp);
			temp = 1;
		}
	}
	ans = max(ans, temp);
	cout << n - ans << endl;
	return 0;
}

Measured memory_bytes: 1024
import java.util.ArrayList;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
	    ArrayList<Integer> input = getInput();

	    String a = "";
	    String b = "";
	    for (int i = 0; i < input.get(0); i++) a += input.get(1);
        for (int i = 0; i < input.get(1); i++) b += input.get(0);

        if (a.compareTo(b) < 0) {
            Print(a);
        } else {
            Print(b);
        }
    }

    private static Scanner scanner = new Scanner(System.in);
    private static ArrayList<Integer> getInput() {
        String in = scanner.nextLine();

        ArrayList<Integer> result = new ArrayList<>();
        for (String t : in.split(" ")) {
            result.add(Integer.parseInt(t));
        }

        return result;
    }

    private static void Print(Object o) {
        System.out.println(o);
    }
}


Measured memory_bytes: 21972
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
#define deb(x) cout<< #x << " " << x << "\n";
#define MAX 9223372036854775807
#define MIN -9223372036854775807
#define PI 3.141592653589
#define setbits(n) __builtin_popcountll(n)
const ll mod=1e9+7;

const int N=1e5+1;
ll dp[N][101][2],d,n;
string s;

ll go(ll pos, ll k, ll mx){
    if(pos==n){
        if(k==0) return 1;
        else return 0;
    }
    if(dp[pos][k][mx]!=-1)
        return dp[pos][k][mx];
    ll ans=0,lim=s[pos]-'0';
    if(mx==0) lim=9;
    for(int i=0;i<lim;i++)
        ans=(ans+go(pos+1,(k+i)%d,0))%mod;
    if(mx==1) ans=(ans+go(pos+1,(k+lim)%d,1))%mod;
    else ans=(ans+go(pos+1,(k+lim)%d,0))%mod;
    return dp[pos][k][mx]=ans;
}

int main() {
    
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll T=clock();
    
    cin>>s;
    cin>>d;
    n=s.size();
    memset(dp,-1,sizeof(dp));
    cout<<(go(0,0,1)-1+mod)%mod;

    cerr<<"\n\nTIME: "<<(double)(clock()-T)/CLOCKS_PER_SEC<<" sec\n";
    T = clock();
    return 0;
}

Measured memory_bytes: 162420
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>

using namespace std;

const int MOD = 1000000007;
typedef pair<int, int> P;
typedef long long ll;
#define rep(i, m, n) for(int i=m;i<n;i++)
#define rrep(i, n, m) for(int i=n;i>=m;i--)

int main() {
    string S;
    cin >> S;
    int ans = 0;
    for (int i = 0; i < S.length(); ++i) {
        if (S[i] == '+') {
            ans ++;
        }else{
            ans --;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define el "\n"
#define ll long long
#define ull unsigned long long int
#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define M 1000000007
#define all(v) v.begin(), v.end()

bool cmp(pair<ll,ll> x ,pair<ll,ll> y){
    if(x.Y==y.Y)return (x.X > y.X);
    return (x.Y<y.Y);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll n;
  cin>>n;
  ll x,y;
  vector<pair<ll,ll>> v;
  for(int i=0;i<n;i++){
      cin>>x>>y;
      v.pb(mp(x,y));
  }
  sort(all(v), cmp);
  /*for(auto x:v){
     cout<<x.X<<" "<<x.Y<<el;
  }*/
  ll cnt=0;
  for(int i=0;i<n;i++){
      cnt+=v[i].X;
      if(cnt>v[i].Y){
          cout<<"No"<<el;
          return 0;
      }
  }
  cout<<"Yes"<<el;
  return 0;
}


Measured memory_bytes: 6256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        
        Scanner scan = new Scanner(System.in);
        String N = scan.next();
        String M = scan.next();
        
        if( N.equals(M)  ) {
            System.out.println("Yes");
        } else {
            System.out.println("No");    
        }
        
    }
}


Measured memory_bytes: 21972
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a, b, c, d;
  cin >> a >> b >> c >>d;

  int left = a + b;
  int right = c + d;
  if (left > right) {
  	cout << "Left" << endl;
  } 
  if (left < right) {
  	cout << "Right" << endl;
  }
  if (left == right) {
  	cout << "Balanced" << endl;
  }

}

Measured memory_bytes: 256
import sys
readline = sys.stdin.readline
write = sys.stdout.write
N, M = map(int, readline().split())
*p, = range(N)
def root(x):
    if x == p[x]:
        return x
    p[x] = x = root(p[x])
    return x
def unite(x, y):
    px = root(x); py = root(y)
    if px < py:
        p[py] = px
    else:
        p[px] = py


for i in range(M):
    s, t = map(int, readline().split())
    unite(s, t)
*_, = map(root, range(N))
Q = int(readline())
ans = []
for q in range(Q):
    s, t = map(int, readline().split())
    ans.append('yes' if p[s] == p[t] else 'no')
write("\n".join(ans))
write("\n")



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

using namespace std;
using ll = long long;

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

  int sx, sy, tx, ty;
  cin >> sx >> sy >> tx >> ty;

  for (int i = 0; i < tx - sx; i++)
    cout << 'R';
  for (int i = 0; i < ty - sy; i++)
    cout << 'U';

  for (int i = 0; i < tx - sx; i++)
    cout << 'L';
  for (int i = 0; i < ty - sy; i++)
    cout << 'D';

  cout << 'D';
  for (int i = 0; i < tx - sx + 1; i++)
    cout << 'R';
  for (int i = 0; i < ty - sy + 1; i++)
    cout << 'U';
  cout << 'L';

  cout << 'U';
  for (int i = 0; i < tx - sx + 1; i++)
    cout << 'L';
  for (int i = 0; i < ty - sy + 1; i++)
    cout << 'D';
  cout << 'R';

  cout << endl;

  return 0;
}


Measured memory_bytes: 3660
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define rep(i,n) for (int i=0;i<(int)(n);i++)
#define codefor int test;scanf("%d",&test);while(test--)
#define INT(...) int __VA_ARGS__;in(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__;in(__VA_ARGS__)
#define yn(ans) if(ans)printf("Yes\n");else printf("No\n")
#define YN(ans) if(ans)printf("YES\n");else printf("NO\n")
#define vector1d(type,name,...) vector<type>name(__VA_ARGS__)
#define vector2d(type,name,h,...) vector<vector<type>>name(h,vector<type>(__VA_ARGS__))
#define umap unordered_map
#define uset unordered_set
using namespace std;
using ll = long long;
const int MOD=1000000007;
//入力系
void scan(int& a){scanf("%d",&a);}
void scan(long long& a){scanf("%lld",&a);}
template<class T> void scan(T& a){cin>>a;}
template<class T> void scan(vector<T>& vec){for(auto&& it:vec)scan(it);}
void in(){}
template <class Head, class... Tail> void in(Head& head, Tail&... tail){scan(head);in(tail...);}
//出力系
void print(const int& a){printf("%d",a);}
void print(const long long& a){printf("%lld",a);}
void print(const double& a){printf("%.15lf",a);}
template<class T> void print(const T& a){cout<<a;}
template<class T> void print(const vector<T>& vec){if(vec.empty())return;print(vec[0]);for(auto it=vec.begin();++it!= vec.end();){putchar(' ');print(*it);}}
void out(){putchar('\n');}
template<class T> void out(const T& t){print(t);putchar('\n');}
template <class Head, class... Tail> void out(const Head& head,const Tail&... tail){print(head);putchar(' ');out(tail...);}
//デバッグ系
template<class T> void dprint(const T& a){cerr<<a;}
template<class T> void dprint(const vector<T>& vec){if(vec.empty())return;cerr<<vec[0];for(auto it=vec.begin();++it!= vec.end();){cerr<<" "<<*it;}}
void debug(){cerr<<endl;}
template<class T> void debug(const T& t){dprint(t);cerr<<endl;}
template <class Head, class... Tail> void debug(const Head& head, const Tail&... tail){dprint(head);cerr<<" ";debug(tail...);}
ll intpow(ll a, ll b){ ll ans = 1; while(b){ if(b & 1) ans *= a; a *= a; b /= 2; } return ans; }
ll modpow(ll a, ll b, ll p){ ll ans = 1; while(b){ if(b & 1) (ans *= a) %= p; (a *= a) %= p; b /= 2; } return ans; }
ll updivide(ll a,ll b){if(b==1) return a;else if(a%b==0) return a/b;else return (a/b)+1;}

int main(){
    vector<bool> prime(100001,true);
    vector<int> ans(100001,0);
    for(int i=2;i<=100000;i++){
        for(int j=i*2;j<=100000;j+=i){
            prime[j]=false;
        }
    }
    for(int i=3;i<=100000;i+=2){
        ans[i]=ans[i-2]+(prime[i]&&prime[(i+1)/2]);
    }
    INT(q);
    int l,r;
    while(q--){
        in(l,r);
        out(ans[r]-ans[l]+(ans[l]>ans[l-2]));
    }
}

Measured memory_bytes: 3756
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    static int[] createPrimes(int n) {
        int[] ans = new int[n+1];
        Arrays.fill(ans, 1);
        ans[0] = ans[1] = 0;

        int max = (int)Math.sqrt(n) + 1;

        for (int i = 2; i < n/2 + 1; i++) {
            ans[i*2] = 0;
        }

        for (int i = 3; i <= max; i += 2) {
            for (int j = 2; j < n / i; j++) {
                ans[i*j] = 0;
            }
        }

        return ans;
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a, d, n;
        int m = (int)Math.pow(10, 6);
        int[] primes = createPrimes(m);

//        int[] subarray = new int[50]; // to debug


//        System.arraycopy(primes, 0, subarray, 0, 50);
//        System.out.println(Arrays.toString(subarray));

        while (true) {
            a = Integer.parseInt(sc.next());
            d = Integer.parseInt(sc.next());
            n = Integer.parseInt(sc.next());
            int c = 0;

            if (a == 0) break;

            int i = 0;
            while (true) {
                if (primes[a + i * d] == 1)
                    c++;
                if (c == n) {
                    System.out.println(a + i * d);
                    break;
                }
                i++;
            }







        }
    }
}

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

vector<ll> divisor(ll n) {
  vector<ll> ret;
  for(ll i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}

int main() {
	ll n;
	cin >> n;
	auto p = divisor(n);
	auto q = divisor(n-1);
	set<ll> s;
	rep(i, p.size()) s.insert(p[i]);
	rep(i, q.size()) s.insert(q[i]);
	ll cnt = 0;
	for(ll t: s) {
		if(t==1) continue;
		ll tmp = n;
		while(tmp > 0) {
			if(tmp==1) {
				cnt++;
				break;
			}
			if(tmp % t == 0) tmp /= t;
			else {
				tmp %= t;
				if(tmp == 1) cnt++;
				break;
			}
		}
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ll long long
using namespace std;

const ll P = 1000000007;
int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

int main()
{
  cout << fixed << setprecision(10);
  int a,b,c;
  cin >> a >> b >> c;
  vector<int> vec(3);
  vec = {a,b,c};
  sort(ALL(vec));
  cout << vec[0]+vec[1] << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <numeric>
#include <set>
#include <cstdlib>
#include <queue>

using namespace std;

typedef long long llint;
typedef long double ld;
#define inf 1e18

priority_queue<int,vector<int>,greater<int>> que;


llint n,y;


void solve(){
	cin >> n >> y;
	bool f=false;
	for(int i=0;i<=n;i++){
		int s=y-10000*i;
		if(s<0)break;
		for(int j=0;j<=n-i;j++){
			int t=s-5000*j;
			if(t<0)break;
			int k=t/1000;
			if(i+j+k==n){
				printf("%d %d %d\n",i,j,k);
				f=true;
				break;
			}
		}
		if(f)break;
	}
	if(!f)printf("-1 -1 -1\n");
}

int main(int argc, char *argv[]) {
  solve();
  return 0;
}


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

const int maxn = (int)(2e5) + 5;
map<int,int> now;
int f[maxn];
char s[maxn];

int main() {
	scanf("%s", s + 1);
	int n = strlen(s + 1), w = 0;
	memset(f, 0x3f, sizeof(f));
	now[0] = 0; f[0] = 0;
	for (int i = 1; i <= n; ++i) {
		w ^= (1 << (s[i] - 'a'));
		f[i] = min(f[i], f[i - 1] + 1);
		if (now.count(w)) f[i] = now[w] + 1;
		for (int j = 0; j < 26; ++j) {
			if (now.count(w ^ (1 << j))) f[i] = min(f[i], now[w ^ (1 << j)] + 1);
		}
		if (!now.count(w)) now[w] = f[i]; else now[w] = min(now[w], f[i]);
	}
	return printf("%d\n", f[n]), 0;
}

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

int main()
{
    vector<bool> ans(3, true);
    rep (i, 2)
    {
        int x;
        cin >> x;
        ans[x - 1] = false;
    }

    rep (i, 3)
        if (ans[i] == true)
            cout << i + 1 << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>

using namespace std;

int main(){
	int n,a,b,c;
	int m=0;
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		int a[3];
		for(int j=0;j<3;j++)scanf("%d",&a[j]);
		std::sort(a,a+3);
		
		m=max(m,a[2]);
		
		if(a[0]*a[0]+a[1]*a[1] == a[2]*a[2])puts("YES");
		else{
			if(m<30)puts("NO");
			else puts("YES");
		}
	}
}

Measured memory_bytes: 0
#include<stdio.h>
int main()
{
    int i,j,n,m,a,b;
    int A[100][100]={0};
    int B[100]={0};
    int C[100]={0};
    scanf("%d %d",&n,&m);
    for(j=0;j<n;j++){
        for(i=0;i<m;i++){
            scanf("%d",&a);
            A[j][i]=a;
        }
    }
    for(j=0;j<m;j++){
        scanf("%d",&b);
        B[j]=b;
    }
    for(j=0;j<n;j++){
        for(i=0;i<m;i++){
            C[j]=C[j]+A[j][i]*B[i];
        }
    }
    for(i=0;i<n;i++){
        printf("%d\n",C[i]);
    }

    return 0;
}



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


using namespace std;
#define rep(i,n) for (int i = 0; i < (int)(n); ++i)
#define reps(i,n) for (int i = 1; i <= (int)(n); ++i)
#define repd(i,n) for (int i = (int)(n - 1); i >= 0; --i)
#define repds(i,n) for (int i = (int)(n); i > 0; --i)
#define loop(i,x,n) for (int i = (int)(x); i < (n); ++i)
#define loops(i,x,n) for (int i = (int)(x); i <= (n); ++i)
#define loopd(i,x,n) for (int i = (int)(x); i > (n); --i)
#define loopds(i,x,n) for (int i = (int)(x); i >= (n); --i)
#define itrep(i,s) for (auto i = begin(s); i != end(s); ++i)
#define itrepd(i,s) for (auto i = --end(s); i != begin(s); --i)
#define all(f,x,...) [&](decltype(x)& whole) { return (f)(begin(whole), end(whole), ##__VA_ARGS__); }(x)
#define rall(f,x,...) [&](decltype(x)& whole) { return (f)(rbegin(whole), rend(whole), ##__VA_ARGS__); }(x)
using ll = long long;
using ld = long double;
constexpr ll inf = static_cast<ll>(1e17);
constexpr int iinf = static_cast<int>(1e9);
constexpr double dinf = 1e10;
constexpr ld ldinf = 1e17;
ll mod = static_cast<ll>(1e9 + 7);
std::ostream& endn(std::ostream& os) { return os.put(os.widen('\n')); }
template<class T> constexpr int sz(const T& a) { return (int)a.size(); }
template<class T> constexpr T pow2(const T a) { return a * a; }
template<class T, class ... Args> constexpr T mins(T& a, Args... args) { return a = min<T>({ a, args... }); }
template<class T, class... Args> constexpr T maxs(T& a, Args... args) { return a = max<T>({ a,args... }); }

char c;
void solve() {
    cin >> c;
    cout << (char)(c + 1) << endn;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
    cout << flush;
    return 0;
}


Measured memory_bytes: 256
N = int(input())
A = list(map(int,input().split()))
A += [0]
m = 1000
k = 0
for i in range(N):
    if A[i] == A[i+1]:
        continue
    elif A[i] < A[i+1]:
        k += m // A[i]
        m -= (m//A[i])*A[i]
    else:
        m += k*A[i]
        k = 0
print(m)

Measured memory_bytes: 61644
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
typedef long long ll;

using namespace std;

int main()
{
	ll a, b, k;

	cin>>a>>b>>k;
	ll ans_a;
		if (a < k) {
			ans_a = 0;
			if (b > k - a) {
				b = b - k + a;
			} else {
				b = 0;
			}
		} else if (a == k) {
			ans_a = 0;
		} else {
			ans_a = a - k;
		}




	cout << ans_a << " " << b;
	return 0;
}


Measured memory_bytes: 256
# D - Sum of Divisors

N = int(input())

ans = 0
#D = [0] * (N+1)
for i in range(1, N+1):
    for j in range(i, N+1, i):
        #D[j] += 1
        ans += j
    #ans += i*D[i]
print(ans)

Measured memory_bytes: 73480
#include<iostream>
using namespace std;
int main()
{
	int a,b;
	cin>>a>>b;
	int x=max(a,b);
	int ans=0;
	ans+=x;
	if(x==a)
	{
		a--;
	}
	else b--;
	x=max(a,b);
	ans+=x;
	cout<<ans<<endl;
}

Measured memory_bytes: 256