akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef unsigned long long int ulli;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define YN(x) cout<<(bool x?"Yes":"No")<<endl;
#define out(s) cout<<s<<endl;
#define pb push_back;
#define sp " ";
void vout(vector<int> v){
    for(int i=0;i<v.size();i++)
    cout<<v.at(i)<<endl;
}
int main(){
    int n;
    long long int ans=0;
    vector<long long int> a,b;
    cin>>n;
    rep(i,n+1){
        int s;
        cin>>s;
        a.push_back(s);
    }
    rep(i,n){
        int s;
        cin>>s;
        b.push_back(s);
    }
    rep(i,n){
        if(a.at(i)>b.at(i)){
            ans+=b.at(i);
            a.at(i)-=b.at(i);
        }
        else if(a.at(i)+a.at(i+1)<b.at(i)){
            ans=ans+a.at(i)+a.at(i+1);
            a.at(i)=0;
            a.at(i+1)=0;
        }
        else
        {
            ans+=b.at(i);
            b.at(i)-=a.at(i);
            a.at(i)=0;
            a.at(i+1)-=b.at(i);
        }
    }
    cout<<ans;
}

Measured memory_bytes: 2548
#include<iostream>
using namespace std;
int main(){
	int n;
	cin>>n;
	int f=n%10;
	if(f==9)
		f=1;
	else if(f==1)
		f=9;
	int a=(n/10)%10;
	if(a==9)
		a=1;
	else if(a==1)
		a=9;
	int b=n/100;
	if(b==9)
		b=1;
	else if(b==1)
		b=9;
	cout<<b<<a<<f<<endl;	
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,x,y) for (int i=(x);i<=(y);i++)

using namespace std;

const int N=2e5+10;
int n,a[N],b[N];

bool check(int x){
	rep (i,1,2*n-1) b[i]=a[i]>x;
	int m=n,l=m,r=m;
	while (l>1&&b[l-1]!=b[l]) l--;
	while (r<2*n-1&&b[r+1]!=b[r]) r++;
	if (l==m||r==m) return b[m];
	if (b[l]==b[r]) return b[l];
	return l>2*n-r?b[l]:b[r];
}

int main(){
	scanf("%d",&n);
	rep (i,1,2*n-1) scanf("%d",&a[i]);
	int l=1,r=2*n-1;
	while (l<=r){
		int mid=l+r>>1;
		if (!check(mid)) r=mid-1; else l=mid+1;
	}
	printf("%d\n",r+1);
	return 0;
}

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

int main(){
  	long int N;
  	cin >> N;
  	int res = 100000, res_a = 0, res_b = 0, res2 = 0;;
  	long int a, b;
  	for (int i = 1; i <= (int)sqrt(N) + 1; i++){
      	a = i;
      	if (N % a == 0){
          	b = N / a;
          	while(a > 0){
              	res_a++;
              	a /= 10;
            }
          	while(b > 0){
              	res_b++;
              	b /= 10;
            }
          	if (res_a >= res_b) res2 = res_a;
          	else res2 = res_b;
          	if (res2 < res) res = res2;
          	res2 = 0;
          	res_a = 0;
          	res_b = 0;
        }
    }
  	cout << res << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <numeric>
#include <cstdio>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
using namespace std;
#define MOD 1000000007
#define endl "\n" 
#define rep(i,n) for(int i = 0; i < (n); ++i)
typedef long long ll;

const ll INF = 1001001001001001;

int main(void) {
    cin.tie(0);
    ios::sync_with_stdio(false);
  
    int n; cin >> n;
    vector<int> x(n+1);
    int ma = 0;
    for(int i = 1; i <= n; ++i) {
        cin >> x[i];
        ma = max(ma, x[i]);
    }
    ll ans = INF;
    for(int i = 1; i <= ma; ++i) {
       ll s = 0;
       for(int j = 1; j <= n; ++j) {
           s += (x[j] - i) * (x[j] - i);
       }
       ans = min(ans, s);
    }

    cout << ans << endl;


    return 0;
}


Measured memory_bytes: 256
n = int(input())
a = [int(input()) for i in range(n)]
b = sorted(a, reverse=True)
for i in range(n):
    if b[0] == b[1]:
        print(b[0])
    else:
        if a[i] == b[0]:
            print(b[1])
        else:
            print(b[0])


Measured memory_bytes: 14112
#include<bits/stdc++.h>
using namespace std;
typedef long long  ll;
ll power(ll a,ll b,ll mod){return b?power(a*a%mod,b/2,mod)*(b%2?a:1)%mod:1;}
ll cal(ll n){
    ll cnt=1;
    while(n){
        n=n%__builtin_popcount(n);
        cnt++;
    }
    return cnt;
}
int main(){
    ll n,cnt=0,ans1=0,ans2=0,ans;
    string s;
    cin>>n>>s;
    for(int i=0;i<n;i++){
        if(s[i]=='1') cnt++;
    }
    if(cnt>1){
        for(ll i=0;i<n;i++){
            if(s[i]=='1') ans1=(ans1+power(2,n-i-1,cnt-1))%(cnt-1),ans2=(ans2+power(2,n-i-1,cnt+1))%(cnt+1);
        }
        for(ll i=0;i<n;i++){
            if(s[i]=='0'){
                ans=(ans2+power(2,n-i-1,cnt+1))%(cnt+1);
                cout<<cal(ans)<<endl;
            }else{
                ans=(ans1+((cnt-1)-power(2,n-i-1,cnt-1)%(cnt-1))%(cnt-1))%(cnt-1);
                cout<<cal(ans)<<endl;
            }
        }
    }else if(cnt==1){
        for(int i=0;i<n;i++){
            if(s[i]=='1') ans2=(ans2+power(2,n-i-1,cnt+1))%(cnt+1);
        }
        for(ll i=0;i<n;i++){
            if(s[i]=='0'){
                ans=(ans2+power(2,n-i-1,cnt+1))%(cnt+1);
                cout<<cal(ans)<<endl;
            }else{
                cout<<0<<endl;
            }
        }
    }else{
        for(int i=0;i<n;i++) cout<<1<<endl;
    }
	return 0;
}


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

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) std::cout << x << '\n'
#define all(a) a.begin(), a.end()
#define pb push_back
#define sz(x) ((int)(x).size())
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { ll g = gcd(a, b); return a / g * b; }
const int dx[4] = { 1, 0, -1,  0 };
const int dy[4] = { 0, 1,  0, -1 };
const int INF = (int)1e9;
const ll  inf = (ll)1e18;
const int mod = 1000000007;
const int MAX_N = 100010;

bool cmp(P a, P b) { return a.second < b.second; }

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(10);
	/*------------------------------*/

	ll x, y;
	cin >> x >> y;

	ll cnt = 0;
	for (ll i = x; i <= y; i *= 2) {
		cnt++;
	}

	out(cnt);

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
void sort(int& a, int& b) {
    if (a <= b) return;
    int t = a; a = b; b = t;
}
int main() {
    int a, b, i = 0;
    while (true) {
        cin >> a >> b;
        if (a == 0 && b == 0) break;
        sort(a, b);
        cout << a << " " << b << endl;
    }
    return 0;
}


Measured memory_bytes: 3000
#include <stdio.h>

int main()
{
    int t[4][14];
    int n,i,j,c;
    char m,d;
    
    for(i=0; i<4;i++){
        for(j=0; j<14; j++){
            t[i][j]= 0;
        }
    }    
scanf("%d",&c);
    for(i=0; i<c; i++){
        scanf("%c",&d);
        scanf("%c %d",&m,&n);
        if(m == 'S'){
            t[0][n]=1;
        }
        else if(m == 'H'){
            t[1][n] = 1;
        }
        else if(m == 'C'){
            t[2][n] = 1;
        }
        else if(m == 'D'){
            t[3][n] = 1;
         }
    }
    for(j=1; j<14; j++){
        if(t[0][j] != 1){
            printf("S %d\n", j);
        }
    }
      for(j=1; j<14; j++){
        if(t[1][j] != 1){
            printf("H %d\n", j);
        }
    }
     for(j=1; j<14; j++){
        if(t[2][j] != 1){
            printf("C %d\n", j);
        }
    }
     for(j=1; j<14; j++){
        if(t[3][j] != 1){
            printf("D %d\n", j);
        }
    }
    return 0;
}



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

// statics
using namespace std;
using int64 = int_fast64_t;
using PAIR = pair<int64, int64>;
constexpr int INF = 1 << 30;
constexpr int64 LINF = 1LL << 60;
constexpr int MOD = 1e9 + 7;
constexpr int MAX_N = 3e5 + 1;

// init/input
#define int int64
#define INIT ios::sync_with_stdio(false);cin.tie(0);
#define VAR(type, ...) type __VA_ARGS__;MACRO_VAR_Scan(__VA_ARGS__);
template<typename T> void MACRO_VAR_Scan(T &t) {cin>>t;}
template<typename First, typename...Rest> void MACRO_VAR_Scan(First &first, Rest&...rest) {cin>>first;MACRO_VAR_Scan(rest...);}
#define VEC(type, c, n) vector<type> c(n);for(auto &&i:c)cin>>i;

// out
#define OUT(dist) cout<<(dist);
#define FOUT(n, dist) cout<<fixed<<setprecision(n)<<(dist);
#define SP cout<<" ";
#define BR cout<<endl;
#define zero(n) cout<<setfill('0')<<right<<setw(n)
#define debug(x) cerr<<#x<<":"<< (x);BR;

// utility
#define ALL(a) (a).begin(), (a).end()
#define EACH(i, a) for(auto &&i:(a))
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define RFOR(i, a, b) for(int i=(b)-1;i>=0;--i)
#define REP(i, n) for(int i=0;i<(n);++i)
#define RREP(i, n) for(int i=(n)-1;i>=0;--i)

// b:1枚
// k会行う
// - 1枚増やす
// - A枚を1円に変換
// - 1円をb枚に変換

signed main() {
  INIT;
	VAR(int, k, a,b);
	int ans1 = k+1;
	
	// a < b
	int ans = a + (b-a) * ((k-(a-1))/2);
	//debug(ans);
	if ((k-(a-1)) % 2 == 1) ++ans;
	ans = max(ans, ans1);
	cout << ans << endl;
  
  return 0;
}


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

public class Main {
	public static final long MOD = 1000000007;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(true) {
			char[] aa = sc.next().toCharArray();
			if (aa[0] == '0') {
				break;
			}
			char[] bb = sc.next().toCharArray();
			char[] cc = sc.next().toCharArray();
			int n = aa.length;
			long[][] dp = new long[n+1][2];
			dp[0][0] = 1;
			for(int i=1;i<=n;i++) {
				int da = aa[n-i] == '?' ? -1 : aa[n-i] - '0';
				int db = bb[n-i] == '?' ? -1 : bb[n-i] - '0';
				int dc = cc[n-i] == '?' ? -1 : cc[n-i] - '0';
				for(int j=0;j<2;j++) {
					for(int carry=0;carry<2;carry++) {
						int patterns = 0;
						for(int a=0;a<10;a++) {
							if (da != -1 && da != a) {
								continue;
							}
							for(int b=0;b<10;b++) {
								if (db != -1 && db != b) {
									continue;
								}
								int c = a + b + carry;
								if ((j == 0 && c >= 10) || (j == 1 && c < 10)) {
									continue;
								}
								if (i == n) {
									if (a * b * c == 0) {
										continue;
									}
								}
								if (dc == -1 || dc == c%10) {
									patterns++;
								}
							}
						}
						dp[i][j] += dp[i-1][carry] * patterns % MOD;
						dp[i][j] %= MOD;
					}
				}
			}
			//System.out.println(Arrays.deepToString(dp));
			System.out.println(dp[n][0]);
		}
	}

}

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

using namespace std;

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

using ll = long long;

const int Inf = 1e9;
const double EPS = 1e-9;
const int N = 1e7;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(0);
    int n, m;
    cin >> n >> m;
    vector<int> work[m];
    rep (i, n) {
        int a, b;
        cin >> a >> b;
        if (a > m) continue;
        work[a - 1].push_back(b);
    }
    int res = 0;
    priority_queue<int> pq;
    rep (i, m) {
        for (auto w: work[i]) pq.push(w);
        if (pq.empty()) continue;
        res += pq.top();
        pq.pop();
    }
    cout << res << endl;

    return 0;
}


Measured memory_bytes: 5632
import java.util.Scanner;

public class Main{
	
	static int mod = 1000000007;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = Integer.parseInt(sc.next());
		int []a = new int [n];
		
		for(int i = 0 ; i < n ;i++) {
			a[i] = Integer.parseInt(sc.next());
		}
		
		int []cnt = new int [n+1];
		
		cnt[0] = 3;
		long ans = 1;
		
		for(int i = 0 ; i < n ;i++) {
			int num = a[i];
			ans = (ans * (cnt[num] - cnt[num+1])% mod); 
			cnt[num+1]++;
		}
		
		System.out.println(ans);
		

	}

}


Measured memory_bytes: 49428
from sys import stdin
input = stdin.readline
lmi = lambda: list(map(int, input().split()))
mi = lambda: map(int, input().split())

n = int(input())
s = input().strip('\n')
ans = 0
for i in range(1, n):
    if s[i] != s[i-1]:
        ans += 1
print(ans+1)

Measured memory_bytes: 29676
#include <iostream>
#include <string>
#define ADD 0
#define SUB 1
#define MUL 2
using namespace std;

int calc(int a, int b, int op){
	switch(op){
		case ADD:
			return a + b;
		case SUB:
			return a - b;
		case MUL:
			return a * b;
	}
}

string parseStr(int op){
	switch(op){
		case ADD:
			return " + ";
		case SUB:
			return " - ";
		case MUL:
			return " * ";
	}
}

bool calc(int a, int b, int c, int d, int op0, int op1, int op2){
	int sum, tmp;
	sum = calc(a, b, op0);
	sum = calc(sum, c, op1);
	sum = calc(sum, d, op2);
	if(sum == 10){
		cout << "(((";
		cout << a << parseStr(op0) << b << ")";
		cout << parseStr(op1) << c << ")" << parseStr(op2) << d << ")" << endl;
		return true;
	}
	sum = calc(a, b, op0);
	tmp = calc(c, d, op2);
	sum = calc(sum, tmp, op1);
	if(sum == 10){
		cout << "((";
		cout << a << parseStr(op0) << b << ")";
		cout << parseStr(op1) << "(" << c << parseStr(op2) << d << "))" <<	 endl;
		return true;
	}
	sum = calc(b, c, op1);
	sum = calc(a, sum, op0);
	sum = calc(sum, d, op2);
	if(sum == 10){
		cout << "((";
		cout << a << parseStr(op0) << "(" << b ;
		cout << parseStr(op1) << c << "))" << parseStr(op2) << d << ")" <<	 endl;
		return true;
	}
	sum = calc(b, c, op1);
	sum = calc(sum, d, op2);
	sum = calc(a, sum, op0);
	if(sum == 10){
		cout << "(";
		cout << a << parseStr(op0) << "((" << b ;
		cout << parseStr(op1) << c << ")" << parseStr(op2) << d << "))" <<	 endl;
		return true;
	}
	sum = calc(c, d, op2);
	sum = calc(b, sum, op1);
	sum = calc(a, sum, op1);
	if(sum == 10){
		cout << "(";
		cout << a << parseStr(op0) << "(" << b ;
		cout << parseStr(op1) << "(" << c << parseStr(op2) << d << ")))" <<	 endl;
		return true;
	}
	return false;
}

int main(){
	int n[4];
	int p[4];
	int a,b,c,d;
	int op[3];
	while(cin >> n[0] >> n[1] >> n[2] >> n[3]){
		if(n[0] == 0 && n[0] == n[1] && n[1] == n[2] && n[2] == n[3]) break;
		for (int i = 0; i < 3*3*3; i++) {
			for (int j = 0; j < 4*4*4*4; j++) {
				p[0] = j%4;
				p[1] = (j%16)/4;
				p[2] = (j%64)/16;
				p[3] = (j%256)/64;
				// ツ重ツ閉。ツチツェツッツク
				bool flag = false;
				for (int k = 0; k < 4; k++) 
					for (int l = 0; l < 4; l++) 
						if(k != l && p[k] == p[l])
							flag = true;
				if(flag){
					continue;
				}
				a = n[p[0]];
				b = n[p[1]];
				c = n[p[2]];
				d = n[p[3]];
				op[0] = i%3;
				op[1] = (i%9)/3;
				op[2] = (i%27)/9;
				if(calc(a, b, c, d, op[0], op[1], op[2])){
					goto z;
				}
			}
		}
		cout << 0 << endl;
z:;
	}
	return 0;
}

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

int main() {
  ll a,b,c,k;  cin>>a>>b>>c>>k;
  if(a>k)cout<<k;
  else if(a+b>=k){cout<<a;}
  else {cout<<2*a-k+b;}
}



Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
int main()
{
  long long int n,a,b,t;
  cin>>n>>a>>b;
  t=a+b;
  t=n/t;
  n-=t*(a+b);
  t=t*a;
  t+=min(a,n);
  cout<<t<<endl;
  return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
#define mp make_pair

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

const double PI=3.1415926535;

int main() {
	double a,b,c,d;
	while(cin>>a>>b>>c>>d){
		if(a==-1&&b==-1&&c==-1&&d==-1)break;
		a=a/180*PI;
		b=b/180*PI;
		c=c/180*PI;
		d=d/180*PI;
		cout<<int(acos(cos(PI/2-a)*cos(PI/2-c)+sin(PI/2-a)*sin(PI/2-c)*cos(b-d))*6378.1+0.5)<<endl;;
	}
	return 0;
}

Measured memory_bytes: 0
import java.util.*;

public class Main {
    static final int MOD = 1000000007;
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int h = sc.nextInt();
		int w = sc.nextInt();
		UnionFindTree uft = new UnionFindTree(h, w);
		char[][] field = new char[h][];
		for (int i = 0; i < h; i++) {
		    field[i] = sc.next().toCharArray();
		    for (int j = 0; j < w; j++) {
		        if (field[i][j] == '#') {
		            uft.setBlack(i, j);
		        } else {
		            uft.setWhite(i, j);
		        }
		    }
		}
		
		for (int i = 0; i < h; i++) {
		    for (int j = 0; j < w; j++) {
		        if (field[i][j] == '.') {
		            continue;
		        }
		        if (i != 0 && field[i - 1][j] == '.') {
		            uft.unite(i, j, i - 1, j);
		        }
		        if (i != h - 1 && field[i + 1][j] == '.') {
		            uft.unite(i, j, i + 1, j);
		        }
		        if (j != 0 && field[i][j - 1] == '.') {
		            uft.unite(i, j, i, j - 1);
		        }
		        if (j != w - 1 && field[i][j + 1] == '.') {
		            uft.unite(i, j, i, j + 1);
		        }
		        
		    }
		}
	    System.out.println(uft.getCount());
	}
	
	static class UnionFindTree {
	    int h;
	    int w;
	    int[] parents;
	    int[] blacks;
	    int[] whites;
	    
	    public UnionFindTree(int h, int w) {
	        this.h = h;
	        this.w = w;
	        int size = h * w;
	        parents = new int[size];
	        blacks = new int[size];
	        whites = new int[size];
	        for (int i = 0; i < size; i++) {
	            parents[i] = i;
	        }
	    }
	    
	    public int find (int x) {
	        if (parents[x] == x) {
	            return x;
	        } else {
	            return parents[x] = find(parents[x]);
	        }
	    }
	    
	    public void unite(int h1, int w1, int h2, int w2) {
	        unite(h1 * w + w1, h2 * w + w2);
	    }
	    
	    public void unite(int x, int y) {
	        int xx = find(x);
	        int yy = find(y);
	        if (xx == yy) {
	            return;
	        }
	        parents[xx] = yy;
	        blacks[yy] += blacks[xx];
	        whites[yy] += whites[xx];
	    }
	    
	    public void setBlack(int h1, int w1) {
	        blacks[h1 * w + w1]++;
	    }
	    
	    public void setWhite(int h1, int w1) {
	        whites[h1 * w + w1]++;
	    }
	    
	    public long getCount() {
	        long total = 0;
	        for (int i = 0; i < parents.length; i++) {
	            if (parents[i] == i) {
	                total += (long)blacks[i] * whites[i];
	            }
	        }
	        return total;
	    }
	}
}
	


Measured memory_bytes: 26808
using System;
using System.Numerics;
using System.Linq;
using System.Collections.Generic;
using System.Text;

namespace debug
{

    class ProgramB
    {
        static void Main(string[] args)
        {
            //入力
            string a = Console.ReadLine();
          
            if(a == "ABC")
                Console.WriteLine("ARC");
            else
                Console.WriteLine("ABC");

        }
    }
}


Measured memory_bytes: 25796
#include <algorithm>
#include <array>
#include <assert.h>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;
typedef long long ll;
typedef long double ld;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define sz(x) ((int)(x).size())
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ld> vld;
typedef vector<vector<int>> vvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<ld>> vvd;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

const ll MOD = (ll)1e9 + 7;
ll binpow(ll a, ll n) {
    ll res = 1;
    while (n) {
        if (n & 1) { res *= a; res %= MOD; }
        a *= a;
        a %= MOD;
        n >>= 1;
    }
    return res % MOD;
}

ll inv(ll x) { return binpow(x, MOD - 2); }

void add(ll& x, ll y) { x += y; if (x >= MOD) x -= MOD; }
void take(ll& x, ll y) { x -= y; if (x < 0) x += MOD; }

ll sum(ll a, ll b) { add(a, b); return a; }
ll sub(ll a, ll b) { take(a, b); return a; }
ll mul(ll x, ll y) { return (x * y) % MOD; }
ll rat(ll x, ll y) { assert(y); return mul(x, inv(y)); }

int main() {
    cout << setprecision(30);
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);

    string s;
    cin >> s;
    ll n = sz(s);
    vvl dp(2, vl(13));
    dp[0][0] = 1;
    ll ten = 1;
    for (ll i = n - 1; i >= 0; --i) {
        char ch = s[i];
        for (ll d = 0; d < 10; ++d) {
            if (ch == '?' || (ch - '0') == d) {
                for (ll r = 0; r < 13; ++r) {
                    ll rr = (r + (d * ten)) % 13;
                    add(dp[1][rr], dp[0][r]);
                }
            }
        }
        dp[0].assign(13, 0);
        swap(dp[0], dp[1]);
        ten = (ten * 10) % 13;
    }
    cout << dp[0][5] << endl;

    return 0;
}


Measured memory_bytes: 512
import math
 
N,K = (int(x) for x in input().split())
S = input()
 
list1 = []
now = 1
count = 0
 
for i in range(N):
    if now == int(S[i]):
        count += 1
    else:
        list1.append(count)
        now = 1-now
        count = 1
else:
    list1.append(count)

if len(list1) % 2 == 0:
    list1.append(0)
 
tmp=0
left=0
right=0
ans=0
for i in range(0,len(list1),2):
    nextleft = i
    while left<nextleft:
        tmp = tmp - list1[left]
        left = left + 1
 
    nextright = min(i+2*K+1,len(list1))
    while right<nextright:
        tmp = tmp + list1[right]
        right = right + 1

    ans=max(ans,tmp)

print(ans)



Measured memory_bytes: 4212
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
ll ans = 0;
const ll mo = 998244353;
ll mypow(ll a, ll b)
{
  ll res = 1;
  a %= mo;
  while (b)
  {
    if (b & 1)
      res = res * a % mo;
    a = a * a % mo;
    b >>= 1;
  }
  return res;
}
int main()
{
  ll n;
  cin >> n;
  vector<ll> a(n);
  ll maxv = 1;
  rep(i, n)
  {
    cin >> a[i];
    if (maxv < a[i])
      maxv = a[i];
  }
  vector<ll> r(maxv + 1);
  rep(i, n) r[a[i]]++;

  auto mod = [](ll modx) {modx%=mo;modx+=mo;modx%=mo;return modx; };
  vector<ll> v(maxv + 1);
  rep(i, maxv) v[i + 1] = mypow(i + 1, mo - 2);
  for (ll i = 1; i <= maxv; i++)
  {
    for (ll j = i * 2; j <= maxv; j += i)
    {
      v[j] = mod(v[j] - v[i]);
    }
  }

  vector<ll> sum(maxv + 1);
  vector<ll> sum2(maxv + 1);
  for (ll i = 1; i <= maxv; i++)
  {
    for (ll j = i; j <= maxv; j += i)
    {
      sum[i] = mod(sum[i] + r[j] * j);
      sum2[i] = mod(sum2[i] + r[j] * mod(j * j));
    }
  }
  rep(i, maxv) ans = mod(ans + mod(v[i + 1] * (mod(sum[i + 1] * sum[i + 1]) - sum2[i + 1])) * mypow(2, mo - 2));
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 33024
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <bitset>
#include <set>
#include <queue>

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

const float PI = 3.1415926;
static const int INFTY = (1<<30);

using namespace std;

typedef long long ll;
typedef long double ld;

const int V[6][2] = {{1,2}, {-1,3}, {1,-1}, {4,5}, {5,2}, {2,1}};

int main() {
  string t;
  int now;
  bool flag;
  while(cin >> t, t!="#") {
    flag = true;
    now = 0;
    rep(i, t.size()) {
      int tmp= t[i] - '0';
      now = V[now][tmp];
      if(now < 0) {
        flag = false;
        break;
      }
    }
    if(now == 5 && flag)
      cout << "Yes" << endl;
    else
      cout << "No" << endl;
  }
    
  
  return 0;
}

Measured memory_bytes: 1180
import collections
q = int(input())
A = collections.deque()
ans = list()
for i in range(q):
    query = list(map(int, input().split()))
    if query[0] == 0:
        A.append(query[1])
    elif query[0] == 1:
        ans.append(A[query[1]])
    elif query[0] == 2:
        A.pop()
for a in ans:
    print(a)


Measured memory_bytes: 13808
#include <iostream>
using namespace std;
int main(void){
    long int n, ai;
    long int a_min, a_max, a_sum;
    cin >> n;
    cin >> ai;
    a_min = a_max = a_sum = ai;
    for (int i = 1 ; i < n ; ++i) {
        cin >> ai;
        a_min = min(a_min, ai);
        a_max = max(a_max, ai);
        a_sum += ai;
    }
    cout << a_min << " " << a_max << " " << a_sum << endl;
    return 0;
}


Measured memory_bytes: 3072
#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f
#include <cstdio>
#include <iostream>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>

using namespace std;

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

int tx[] = {0,1,0,-1};
int ty[] = {-1,0,1,0};

static const double EPS = 1e-8;


static const string kang[] = {"a", "b", "c","d", "e", "f", "g", "h", "i","j", "k", "l","m","n", "o","p","q","r", "s","t", "u", "v", "w", "x", "y","z",
	"ld", "mb", "mp", "nc", "nd", "ng", "nt", "nw", "ps", "qu", "cw","ts"};

int main(){
	string str;
	map<string,vector<string> > dubStr;
	dubStr["m"].push_back("mb");
	dubStr["m"].push_back("mp");

	dubStr["l"].push_back("ld");

	dubStr["n"].push_back("nc");
	dubStr["n"].push_back("nd");
	dubStr["n"].push_back("ng");
	dubStr["n"].push_back("nt");
	dubStr["n"].push_back("nw");

	dubStr["p"].push_back("ps");

	dubStr["q"].push_back("qu");

	dubStr["c"].push_back("cw");

	dubStr["t"].push_back("ts");

	int n;
	while(getline(cin,str)){

		n = atoi(str.c_str());

		map<P,int> kangPair;
		for(int line=0;line<n;line++){
			getline(cin,str);
			stringstream ss(str);
			while(ss >> str){
				map<string,int> freq;

				string prev = "";
				for(int s = 0; s<str.size();){

					string key = str.substr(s,1);
					string key2="";
					if(s<str.size()-1) key2 = str.substr(s,2);


					if(dubStr.find(key) != dubStr.end()){
						for(int i=0;i<dubStr[key].size();i++){
							if(key2 == dubStr[key][i]){

								if(prev != ""){
									kangPair[P(prev,key2)]++;
								}

								prev = key2;
								s+=2;
								goto next;
							}
						}

						if(prev != ""){
							kangPair[P(prev,key)]++;
						}
						prev = key;
						s+=1;
					}
					else{
						if(prev != ""){
							kangPair[P(prev,key)]++;
						}
						prev = key;
						s+=1;
					}
next:;
				}
			}
		}

		for(int i=0;i<38;i++){
			int maxv = 0;
			int to=0;
			for(int j=0;j<38;j++){
				map<P,int>::iterator it;
				if((it = kangPair.find(P(kang[i],kang[j]))) == kangPair.end()) continue;
				if(maxv < it->second){
					maxv = it->second;
					to = j;
				}
			}
			//cout << kang[i] << endl;
			if(maxv == 0) printf("%s %s %d\n",kang[i].c_str(),"a",0);
			else printf("%s %s %d\n",kang[i].c_str(),kang[to].c_str(),maxv);
		}
	}
}

Measured memory_bytes: 968
#x=int(input())
a,b,k=map(int,input().split())
#xl=list(map(int,input().split()))
#l=[list(map(int,input().split())) for i in range(n)]

ansl=[]

for i in range(1,min(a,b)+1):
    if a%i==0 and b%i==0:
        ansl.append(i)

ansl.sort(reverse=True)

print(ansl[k-1])



Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999

using namespace std;

string rotate(string a){
	return a.substr(1) + a[0];
}

int main(){
	cin.tie(0);					//cinとcoutの結び付きを解除
	ios::sync_with_stdio(false);//stdioとの同期を解除
	
	string S,T;	cin >> S >> T;
	int ss = S.size();
	bool ans = false;
	
	REP(i, ss){
		S = rotate(S);
		if(S == T){
			ans = true;
			break;
		}
	}
	
	if(ans == true){
		cout << "Yes";
	}else{
		cout << "No";
	}
	
	
	return 0;
	
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); 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 FORS(i, m, n) for (int i = m; i <= n; i++)
#define bit(n) (1LL << (n))
#define INF 2e9
#define MOD (1000000007)
#define EPS 1e-9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long long int lli;
int gcd(int m, int n) { return (m % n == 0) ? n : gcd(n, m % n); }
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int A, B, K, count = 1;
  cin >> A >> B >> K;
  int gcdAB = gcd(A, B);
  int i = gcdAB;
  while (i > 0) {
    if (gcdAB % i == 0) {
      if (count == K) {
        cout << i << "\n";
        break;
      } else {
        count++;
      }
    }
    i--;
  }
}

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

long long n,W,dp[110][100010],v[110],w[110];

long long solve(long long pos,long long weight)
{
    if(pos==n || weight>=W)
        return 0;
    if(dp[pos][weight]!=-1)
        return dp[pos][weight];
    long long a,b;
    a=solve(pos+1,weight);
    if(w[pos]+weight<=W)
        b=v[pos]+solve(pos+1,weight+w[pos]);
    else
        b=0;
    dp[pos][weight]=max(a,b);
    return dp[pos][weight];
}

int main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);
    long long i,j,k,temp,ans;
    cin>>n>>W;
    for(i=0;i<n;i++)
        cin>>w[i]>>v[i];
    memset(dp,-1,sizeof(dp));
    ans=solve(0,0);
    cout<<ans;
}


Measured memory_bytes: 86272
#include<stdio.h>
#include<math.h>
int main(){
  
  double a,b,c,d,e,f;
  int i;
  scanf("%d",&i);
  for(;i!=0;i--){
    scanf("%lf %lf %lf %lf %lf %lf",&a,&b,&c,&d,&e,&f);
    double x=0,y=0,r=0;
    x=((b-d)*(a*a+b*b-e*e-f*f)-(b-f)*(a*a+b*b-c*c-d*d))
      /(2*(a-e)*(b-d)-2*(b-f)*(a-c));
    y=((a-e)*(a*a+b*b-c*c-d*d)-(a-c)*(a*a+b*b-e*e-f*f))
      /(2*(a-e)*(b-d)-2*(b-f)*(a-c));
    r=sqrt((x-a)*(x-a)+(y-b)*(y-b));
    // printf("%f,%f,%f,%f,%f,%f\n",a,b,c,d,e,f);
    printf("%.3f %.3f %.3f\n",x,y,r);
  }
}

Measured memory_bytes: 660
import java.util.*;

class Main {
    class Cache {
        private long size;
        private long pati;

        public Cache(long size, long pati) {
            this.size = size;
            this.pati = pati;
        }

        public long size() {
            return this.size;
        }

        public long pati() {
            return this.pati;
        }
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String[] line = scanner.nextLine().split(" ", 2);
        long n = Long.parseLong(line[0]);
        long x = Long.parseLong(line[1]);
        new Main(x, 0).main(n);
    }

    private long toEat;
    private long pati;
    private HashMap<Long, Cache> cacheMap;

    public Main(long toEat, long pati) {
        this.toEat = toEat;
        this.pati = pati;
        this.cacheMap = new HashMap<>();
    }

    public void main(long level) {
        this.eat(level);
        System.out.println(this.pati);
    }

    public void eat(long level) {
        if (toEat == 0) {
            return;
        }

        if (level == 0) {
            this.toEat--;
            this.pati++;
        } else {
            Cache cache = this.cacheMap.get(level - 1);

            long initToEat = this.toEat;
            long initPati = this.pati;

            this.toEat--; // ban

            // level - 1 burger
            if (cache != null && this.toEat >= cache.size) {
                this.toEat -= cache.size;
                this.pati += cache.pati;
            } else if (this.toEat > 0) {
                this.eat(level - 1);
            }

            if (this.toEat > 0) { // pati
                this.toEat--;
                this.pati++;
            }

            // level - 1 burger
            if (cache != null && this.toEat >= cache.size) {
                this.toEat -= cache.size;
                this.pati += cache.pati;
            } else if (this.toEat > 0) {
                this.eat(level - 1);
            }

            if (this.toEat > 0) { // ban
                this.toEat--;

                this.cacheMap.put(level, new Cache(initToEat - toEat, pati - initPati));
            }
        }
    }
}


Measured memory_bytes: 22868
import java.io.PrintWriter
import java.util.StringTokenizer
import kotlin.math.sqrt

fun main() {

    fun PrintWriter.solve() {
        var n = nextLong()

        var ans = 0L

        for (x in 2..sqrt(n.toDouble()).toInt()+1){
            var cnt = 0
            while (n%x == 0L){
                n/=x
                cnt++
            }
            val D = sqrt((1 + 8*cnt).toDouble())

            val meg = maxOf((-1+D)/2 , (-1-D)/2).toInt()

            ans+=meg
        }

        if (n > 1){
            ans++
        }

        println(ans)


    }

    writer.solve()
    writer.flush()


}


private val reader = System.`in`.bufferedReader()
private val writer = PrintWriter(System.out, false)

private var tokenizer: StringTokenizer = StringTokenizer("")

private fun next(): String {
    while (tokenizer.hasMoreTokens().not()) tokenizer = StringTokenizer(reader.readLine())
    return tokenizer.nextToken()
}

private fun nextInt() = next().toInt()
private fun nextLong() = next().toLong()
private fun nextDouble() = next().toDouble()
private fun nextLine() = reader.readLine()



Measured memory_bytes: 34580
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <unordered_map>

using namespace std;

#ifdef DEBUG
int __cnt = 0;
#define msg(x) cout << ++__cnt << '\t' << __FUNCTION__ << "(" << __LINE__ << "): " << x << endl
#else
#define msg(x)
#endif

typedef long long ll;
typedef unsigned long long ull;

template<typename T>
T _scan() {
  T ch; bool seg = false;
  while (!isdigit(ch = getchar())) {
    seg |= (ch == '-');
  }
  T x = ch - '0';
  while (isdigit(ch = getchar())) {
    x = x * 10 + ch - '0';
  }
  if (seg) {
    x = -x;
  }

  return x;
}

auto const scan = &_scan<int>;
auto const scan_ll = &_scan<ll>;

template<typename T>
T maximize(T& a, const T b) {
  if (b > a) {
    a = b;
  }
  return a;
}

template<typename T>
T minimize(T& a, const T b) {
  if (b < a) {
    a = b;
  }
  return a;
}

#define MAXN 100007

int w, h;
ll p[MAXN], psum[MAXN], q[MAXN], qsum[MAXN];

void init() {
  w = scan(); h = scan();
  for (int i = 0; i < w; ++i) {
    p[i] = scan_ll();
  }
  for (int i = 0; i < h; ++i) {
    q[i] = scan_ll();
  }
}

ll work() {
  sort(p, p + w, greater<int>());
  sort(q, q + h, greater<int>());
  psum[0] = p[0];
  qsum[0] = q[0];

  for (int i = 1; i < w; ++i) {
    psum[i] = psum[i-1] + p[i];
  }
  for (int i = 1; i < h; ++i) {
    qsum[i] = qsum[i-1] + q[i];
  }

  ll ans = 0;
  while (w > 0 && h > 0) {
    ll val0 = p[w-1] * (h+1);
    ll val1 = q[h-1] * (w+1);
    if (p[w-1] < q[h-1]) {
      msg(val0<<" w "<<p[w-1]<<' '<<h);
      ans += val0;
      --w;
    } else {
      msg(val1<<" h "<<q[h-1]<<' '<<w);
      ans += val1;
      --h;
    }
  }
  while (w > 0) {
    ans += p[w-1];
    --w;
  }
  while (h > 0) {
    ans += q[h-1];
    --h;
  }

  return ans;
}

int main() {
  init();
  cout << work() << endl;
}



Measured memory_bytes: 3328
var lines = [];
var readline = require('readline');

var rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout,
});

rl.on('line', function (x) {
    lines.push(x);
});

rl.on('close', function () {
    var ABC = lines[0].split(" ");
    var A = Number(lines[0].split(" ")[0]);
    var B = Number(lines[0].split(" ")[1]);
    var C = Number(lines[0].split(" ")[2]);

    var even = 0, odd = 0; ans = 0;
    for (var value of ABC) { Number(value) % 2 === 0 ? even++ : odd++; }

    switch (even) {
        case 1: // even = 1; odd = 2; =>全て偶数に合わせる
            if (A % 2 !== 0) { A += 1 }
            if (B % 2 !== 0) { B += 1 }
            if (C % 2 !== 0) { C += 1 }
            ans++; break;

        case 2: // even = 2; odd = 1; =>全て奇数に合わせる
            if (A % 2 === 0) { A += 1 }
            if (B % 2 === 0) { B += 1 }
            if (C % 2 === 0) { C += 1 }
            ans++; break;
    }

    ans += (Math.max(A, B, C) - A) / 2
    ans += (Math.max(A, B, C) - B) / 2
    ans += (Math.max(A, B, C) - C) / 2

    console.log(ans);
});

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

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

    static class AizuKnapsackWithRepetitions {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            int w = in.nextInt();
            int[] vs = new int[n];
            int[] ws = new int[n];

            for (int i = 0; i < n; i++) {
                vs[i] = in.nextInt();
                ws[i] = in.nextInt();
            }

            out.printf("%d\n", knapsack(w, vs, ws, n));
        }

        private int knapsack(int w, int[] vs, int[] ws, int n) {
            int[] dp = new int[w + 1];

            for (int i = 1; i < w + 1; i++) {
                for (int j = 0; j < n; j++) {
                    if (i >= ws[j]) {
                        dp[i] = Math.max(dp[i], vs[j] + dp[i - ws[j]]);
                    }
                }
            }

            return dp[w];
        }

    }
}




Measured memory_bytes: 27268
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007;
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin>>n;
    ll a,ans=1,num=0;
    ll m[n+1];
    memset(m,0,sizeof(m));
    for(int i=0;i<n;i++){
    	cin>>a;
    	if(a==0){
    		num++;
    	}
    	m[a]++;
    	if(a){
    		ans*=m[a-1];
    		ans%=mod;
    		if(m[a-1])m[a-1]--;
    	}
    }
    if(num==0||num>3)ans=0;
    else if(num==1)ans*=3;
    else ans*=6;
    cout << ((ans%mod)+mod)%mod<<endl;
    return 0;
}


Measured memory_bytes: 1024
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
//        Scanner scanner = new Scanner(System.in);
//        int n = Integer.parseInt(scanner.nextLine());

        int[] array = scanIntArray(br, n);
        //int[] array = scanIntArray(scanner, n);

        int count = shellSort(array);
        System.out.println(count);
        Arrays.stream(array).forEach(System.out::println);
    }

    private static int[] scanIntArray(Scanner scanner, int size) {
        return IntStream.range(0, size)
                .map(n -> Integer.parseInt(scanner.nextLine()))
                .toArray();
    }

    private static int[] scanIntArray(BufferedReader br, int size) throws IOException {
//        int[] array = new int[size];
//        for (int i = 0; i < size; i++) {
//            array[i] = Integer.parseInt(br.readLine());
//        }
//        return array;
        return IntStream.range(0, size)
                .map(n -> {
                    try {
                        return Integer.parseInt(br.readLine());
                    } catch (IOException e) {
                        return -1;
                    }
                })
                .toArray();
    }

    private static int shellSort(int[] array) {
        // make intervals
        int[] intervals = new int[array.length];
        int index = 0;
        for (int h = 1; h <= array.length; h = 3 * h + 1) {
            intervals[index] = h;
            index++;
        }

        // print of intervals
        System.out.println(index);
        for (int i = index - 1; i >= 0; i--) {
            System.out.print(intervals[i]);
            if (i != 0) System.out.print(" ");
            else System.out.println();
        }

        int sumOfCount = 0;
        for (int i = index - 1; i >= 0; i--) {
            sumOfCount += insertionSort(array, intervals[i]);
        }
        return sumOfCount;
    }

    private static int insertionSort(int[] array, int interval) {
        int length = array.length;
        int count = 0;
        for (int i = interval; i < length; i++) {
            int v = array[i];
            int j = i - interval;
            while (j >= 0 && array[j] > v) {
                swap(array, j + interval, j);
                j -= interval;
                count++;
            }
            array[j + interval] = v;
        }
        return count;
    }

    private static void swap(int[] array, int index1, int index2) {
        int tmp = array[index1];
        array[index1] = array[index2];
        array[index2] = tmp;
    }
}



Measured memory_bytes: 111588
x = int(input())

primes = [True]*(2*x)

for i in range(2, x):
    if primes[i]:
        for j in range(i, 2*x, i):
            primes[j] = False
for i in range(x, 2*x):
    if primes[i]:
        print(i)
        exit()


Measured memory_bytes: 4596
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define ll long long
#define midl (l+r)>>1 
const int maxn=1e6+7;
using namespace std;
int n,l,r,mid,arc[maxn];
bool check(int pp)
{
	if (arc[n]<=pp&&arc[n+1]<=pp) return 1;
	if (arc[n]<=pp&&arc[n-1]<=pp) return 1;
	if (arc[n]>pp&&arc[n+1]>pp) return 0;
	if (arc[n]>pp&&arc[n-1]>pp) return 0;
	rep(i,1,n-2) 
	 {
	 	if (arc[n+i]<=pp&&arc[n+i+1]<=pp) return 1;
	    if (arc[n-i]<=pp&&arc[n-i-1]<=pp) return 1;
     	if (arc[n+i]>pp&&arc[n+i+1]>pp) return 0;
    	if (arc[n-i]>pp&&arc[n-i-1]>pp) return 0;
	 }
	return (arc[1]<=pp && arc[1]<=pp);
}
int main(){
	scanf("%d",&n);
	rep(i,1,(n<<1)-1) 
	 scanf("%d",&arc[i]);
	for (r=(n<<1)-1,mid=l+r>>1;l<r;mid=l+r>>1)//while(l<r) 
	 if (check(mid)==1) r=mid;
	 else l=mid+1;
	cout<<l;
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

const int mod = 100000007;

long long modpow(long long a, long long p){
	if(p==0) return 1;
	long long res = modpow(a, p/2);
	res = (res*res)%mod;
	if(p%2==1) res = (res*a)%mod;
	return res;
}

int main(){
	int n;
	double p[100], w[100];
	int nxt[100];
	double exp[100];
	bool visit[100];
	while(cin >> n, n){
		for(int i=0;i<n;i++) cin >> p[i] >> nxt[i] >> w[i];
		for(int i=0;i<n;i++){
			visit[i] = false;
			exp[i] = 1 + (1-p[i])/p[i];
			for(int j=nxt[i];j!=i;j=nxt[j])
				exp[i] += 1 + (1-w[j])/w[j];
		}
		double res = 0.0;
		long long pat = 1;
		int lest = n;
		for(int i=0;i<n;i++){
			int cnt = 0;
			int mul = 1;
			double mx = 1e12;
			if(visit[i]) continue;
			for(int j=i;!visit[j];j=nxt[j]){
				cnt++;
				visit[j] = true;
				if(mx > exp[j]) mul = 0, mx = exp[j];
				if(abs(mx-exp[j]) < 1e-9) mul++;
			}
			res += mx;
			long long add = mul;
			for(int j=0;j<cnt;j++) add = (add*(lest-j))%mod;
			for(int j=0;j<cnt;j++) add = (add*modpow(j+1, mod-2))%mod;
			pat = (pat*add)%mod;
			lest -= cnt;
		}
		printf("%.10lf %d\n", res, pat);
	}
	return 0;
}

Measured memory_bytes: 984
#include <bits/stdc++.h>
using namespace std;
vector<long long> box;
int main(void){
    long long N;
    cin >> N;
    for(int i = 1; i <= sqrt(N); i++){
        if (N % i ==0){
            long long j = N / i;
            long long plus = i + j;
            box.push_back(plus);
        }
    }
    sort(box.begin(), box.end());
    long long min = box.front();
    cout << min - 2;
}


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

using namespace std;

int main()
{
    int N;
    cin>>N;
    double n=0;
    for(int i = 0;i < N;i++){
      double x;
      cin>>x;
      string u;
      cin>>u;
      if(u=="BTC"){
        x*=380000.0;
      }
      n+=x;
 }
    cout<<n<<endl;
    return 0;



}


Measured memory_bytes: 256
#include <stdio.h>

int main(int argc, char** argv)
{
    int n=0,i,cnt=3;
    char s;
    
    do{
        scanf("%d",&n);
    }while((1>n)||(n>100));

    for(i=0;i<n;i++)
    {
        scanf("%c",&s);
        if(s=='Y')
        {
            cnt=4;
        }
    }
    if(cnt==3)
    {
        printf("Three\n");
    }
    else
    {
        printf("Four\n");
    }
    return 0;
}

Measured memory_bytes: 128
N=int(input())
A=[int(input()) for i in range(N)]
max_val=max(A)

def f(A):
  for i in range(N):
    if A[i]==max_val:
      n=i
    else:
      pass
   
  return n
n=f(A)
l=[max_val]*N
A.pop(n)
second_max=max(A)
l[n]=second_max

for i in range(N):
  print(l[i])
   

Measured memory_bytes: 70488
#include<iostream>
using namespace std;
int main(){
    int N,M;
    cin >> N;
    cin >> M;
    int i,j;
    int K;
    int A;
    int array[N][M+1];
    for(i = 0;i<N;i++){
        for(j = 0;j<M+1;j++){
            array[i][j] = 0;
        }
    }
    for(i = 0;i<N;i++){
        cin >> K;
        for(j=0;j<K;j++){
            cin >> A;
            array[i][A] = 1;
        }
    }
    int count = 0;
    int flug = 0;
    for(i = 1;i<M+1;i++){
        flug = 0;
        for(j = 0;j<N;j++){
            if(array[j][i] != 1){
                flug = 1;
                break;
            }
        }
        if(flug == 0){
            count++;
        }
    }
    
    cout << count << "\n";
    return 0;
}



Measured memory_bytes: 256
n,m = gets.chomp.split.map &:to_i
a = gets.chomp.split.map &:to_i
a.sort!
bc = []
m.times do
  b,c = gets.chomp.split.map(&:to_i)
  bc << { :b => b, :c => c }
end
bc.sort_by!{|a| a[:c] }.reverse!

bc_0n = []
size = 0
bc.each do |hash|
  hash[:b].times { bc_0n << hash[:c] }
  size += hash[:b]
  break if size >= n
end

a.each_with_index do |v, i|
  break if bc_0n.size.zero?
  new = bc_0n.shift
  break if v >= new
  a[i] = new
end

puts a.sum


Measured memory_bytes: 40260
import sys

if sys.platform =='ios':
    sys.stdin=open('input_file.txt')
    
    
x=int(input())

c=1
for b in range(1,x):
	 for p in range(2,x):
	 	if b**p<=x:
	 		c=max(c,b**p)
	 	else:
	 		break
print(c)
	 	

Measured memory_bytes: 2940
import sys

N, M = map(int, sys.stdin.readline().split())

shops = []
for _ in range(N):
    a, b = map(int, sys.stdin.readline().split())
    shops.append((a, b))

ans = 0
num = 0
for a, b in sorted(shops):
    if num < M:
        if num + b < M:
            num += b
            ans += a * b
        else:
            ans += a * (M - num)
            break

print(ans)

Measured memory_bytes: 23372
#include<iostream>
#include<string>
#include<cmath>
#include<algorithm>/*toupperとかが入っている*/
#include<vector>/*可変長配列vectorのインクルード*/
 
const int MOD=1000000007;/* 1,000,000,007 で割った余りを出力する　のとき使う*/
using namespace std;/*標準名前空間を利用する。cinやcoutはこれによって利用可能になる*/

int D, T, S;

int main(void) {
  cin >> D >> T >> S;
  if(D <= T * S){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 3628