akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include<vector>
using namespace std;
int main(void){
    // Your code here!
    
    int MAX = 101010;
    vector<int> is_prime(MAX,1);
    is_prime[0] = 0, is_prime[1] = 0;
    for(int i = 2; i < MAX; i++){
        if(!is_prime[i]) continue;
        for(int j = i * 2; j < MAX; j += i) is_prime[j] = 0;
    }
    
    
    vector<int> a(MAX,0);
    for(int i = 0; i < MAX; i++){
        if(i % 2 == 0) continue;
        if(is_prime[i] && is_prime[(i+1)/ 2]) a[i] = 1;
    }
    
    vector<int> s(MAX+1,0);
    for(int i = 0; i < MAX; i++) s[i+1] = s[i] + a[i];
    
    int Q;
    cin >> Q;
    for(int q = 0; q < Q; q++){
        int l, r;
        cin >> l >> r;
        r++; //累積和を考えるときは区間の右側を含まない形式で考えると明快だから、r に 1を足しておく
        
        cout << s[r] - s[l] << endl;
        
    }
}


Measured memory_bytes: 1792
#!/usr/bin/env python3
import sys

MOD = 1000000007  # type: int


def solve(N: int):
    p = 1
    for i in range(1,N+1):
        p = p * i % MOD
    print(p)

    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    solve(N)

if __name__ == '__main__':
    main()


Measured memory_bytes: 62876
#include <iostream>
#include <string>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
const long long INF = 1LL<<60;

string s, t;

int dp[3100][3100] = {0};

int main() {
    cin >> s >> t;
    for (int i = 0; i < s.size(); ++i) {
        for (int j = 0; j < t.size(); ++j) {
            if (s[i] == t[j]) chmax(dp[i+1][j+1], dp[i][j] + 1);
            chmax(dp[i+1][j+1], dp[i+1][j]);
            chmax(dp[i+1][j+1], dp[i][j+1]);
        }
    }
    string res = "";
    int i = (int)s.size(), j = (int)t.size();
    while (i > 0 && j > 0)
    {
        if (dp[i][j] == dp[i-1][j]) {
            --i;
        }
        else if (dp[i][j] == dp[i][j-1]) {
            --j; 
        }
        else {
            res = s[i-1] + res; 
            --i, --j; 
        }
    }
    cout << res << endl;
}


Measured memory_bytes: 37120
n=int(input())
dp=[1000]*(10**7)
dp[0]=0
for i in range(n):
    for j in range(1,8):
        dp[i+6**j]=min(dp[i+6**j],dp[i]+1)
    for k in range(1,7):
        dp[i+9**k]=min(dp[i+9**k],dp[i]+1)
    dp[i+1]=min(dp[i+1],dp[i]+1)
print(dp[n])

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


int main(){
	int check;
	do{
		check = 1;
		int m,f,r;
		cin >> m >> f >> r;
		
		if(m == -1 && f == -1 && r == -1)	check = 0;
		else if(m == -1 || f == -1)	cout << "F\n";
		else if(m + f >= 80)	cout << "A\n";
		else if(m + f >= 65)	cout << "B\n";
		else if(m + f >= 50)	cout << "C\n";
		else if(m + f >= 30 && r >= 50)	cout << "C\n";
		else if(m + f >= 30)	cout << "D\n";
		else	cout << "F\n";
		
	}while(check);
	
	return 0;
}

Measured memory_bytes: 3064
/*#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>

#include <boost/rational.hpp>
*/
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
using ll = long long;
using ld = long double;
using pll = pair<ll,ll>;
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define rep3(i, n) for (ll i = 1; i < (ll)(n+1); i++)
#define rep4(i, s, n) for (ll i = (s); i < (ll)(n+1); i++)
#define repr(i,n) for (ll i = (n-1); i>=0;i--)
#define repr3(i,n) for(ll i = (n);i>0;i--)
#define repr4(i,s,n) for(ll i = (n);i>=(s);i--)
#define stlen(s) ll s.size()-1
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define cout(n) cout<<std::fixed<<std::setprecision(n)
using Graph = vector<vector<int>>;
using Graphw = vector<vector<pair<ll,ll>>>;
using mat = vector<vector<ll>>;
using vec = vector<ll>;
#define INF1  INT_MAX;
#define INF2  LLONG_MAX;
#define PI  3.14159265358979323846;
#define MOD 1000000007;
/*
namespace mp = boost::multiprecision;
// 任意長整数型
using Bint = mp::cpp_int;
// 仮数部長が32の浮動小数点数型
using Real32 = mp::number<mp::cpp_dec_float<32>>;
// 仮数部長が1024の浮動小数点数型
using Real1024 = mp::number<mp::cpp_dec_float<1024>>;
// 有理数型
using Rat = boost::rational<Bint>;
*/
const int mod = 1000000007;

vector<vector<long long>> comb(ll n, ll r) {
  vector<vector<long long>> v(n + 1,vector<long long>(n + 1, 0));
  for (int i = 0; i < v.size(); i++) {
    v[i][0] = 1;
    v[i][i] = 1;
  }
  for (int j = 1; j < v.size(); j++) {
    for (int k = 1; k < j; k++) {
      v[j][k] = (v[j - 1][k - 1] + v[j - 1][k]);
    }
  }
  return v;
}

int main(){
int N,P;
cin>>N>>P;
int A;
map<int,int>count;
auto com=comb(50,1);
rep(i,N){
    cin>>A;
    count[A%2]++;
}
ll ans1=0,ans2=0;
if(P==0){
rep(i,count[0]+1)ans1+=com[count[0]][i];
rep(i,count[1]+1)if(i%2==0)ans2+=com[count[1]][i];
}
else{
rep(i,count[0]+1)ans1+=com[count[0]][i];
rep(i,count[1]+1)if(i%2==1)ans2+=com[count[1]][i];
}
cout<<ans1*ans2<<endl;


return 0;
}

Measured memory_bytes: 3612
/*
    STARK_BOY
*/
#include <bits/stdc++.h>
#include <fstream>
using namespace std;
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define repe(i,a,b) for(ll i=a;i<=b;i++)
#define bac(i,a,b) for(ll i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define F first
#define S second
typedef long long ll;
typedef vector< ll > vi;
typedef vector<pair<ll,ll> > vpii;
typedef pair<ll,ll> pii;
#define all(c) c.begin(),c.end()
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define PI           3.14159265358979323846  /* pi */
mt19937 rng32(chrono::steady_clock::now().time_since_epoch().count());
#define N 1000005
//Variables Start
ll inf=1e18,MOD=1e9+7;
//Variables End


void solve(){
	int n;ll k;cin>>n>>k;
	vector<int> next(n+1,0);
	for(int i=0;i<n;i++ )cin>>next[i+1];
	
	int cyc = 0,cur=1;
	vector<int> vis(n+1,0);
	vector<int> ord;
	while(!vis[cur]){
		ord.pb(cur);
		vis[cur]=1;
		cyc++;
		cur = next[cur];
	}
	
	if(k<ord.size()){
		cout<<ord[k]<<endl;
		return;
	}
	
	int pos=0;
	for(int i=0;i<ord.size();i++)if(ord[i]==cur){pos = i;break;}
	k-=pos;
	cyc = ord.size() - pos;
	k%=cyc;
	
	cout<<ord[pos+k]<<endl;
	 
}
int main()
{
    ios
    int ti=1;
    //cin>>ti;
    for(int i=1;i<=ti;i++)
    {
		solve();        
    }
    return 0;
        
}


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

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n; long long d, a; cin >> n >> d >> a;
    vector<pair<long long, long long>> v;
    for (int i = 0; i < n; i++) {
        long long x, h; cin >> x >> h;
        v.emplace_back(x, h);
    }
    sort(v.begin(), v.end());
    queue<pair<long long, long long>> q;
    long long qsum = 0; long long ans = 0;
    for (int i = 0; i < n; i++) {
        while (!q.empty() && q.front().first < v[i].first) {
            qsum -= q.front().second; q.pop();
        }
        long long remain = v[i].second - qsum;
        if (remain <= 0) continue;
        long long req = (remain + a - 1) / a;
        ans += req;
        q.emplace(v[i].first+2*d, req * a);
        qsum += req * a;
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 6512
#include <stdio.h>
#include <string.h>
#define MAXLEN 1000

/* Prototype Declaration */
int LCSLength(char [], char []);

int main() {
  char X[MAXLEN], Y[MAXLEN];
  int i, n, q;

  scanf("%d", &q);
  for ( i = 0; i < q; i++ ) {
    scanf("%s", X);
    scanf("%s", Y);
    printf("%d\n", LCSLength(X,Y));
  }


  return 0;
}

int LCSLength(char X[], char Y[]) {
  int c[MAXLEN+1][MAXLEN+1];
  int m, n;
  int i, j;

  m = strlen(X);
  n = strlen(Y);

  for ( i = 1; i <= m; i++ ) c[i][0] = 0;
  for ( j = 1; j <= n; j++ ) c[0][j] = 0;
  
  for ( i = 1; i <= m; i++ ) {
    for ( j = 1; j <= n; j++ ) {
      if ( X[i-1] == Y[j-1] )
        c[i][j] = c[i - 1][j - 1] + 1;
      else if ( c[i - 1][j] >= c[i][j - 1] )
        c[i][j] = c[i - 1][j];
      else
        c[i][j] = c[i][j - 1];
    }
  }

  return c[m][n];
}

Measured memory_bytes: 4524
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
	int ans = 0;
	int N, K;
	string  S;
	cin >> N >> K;
	cin >> S;

	char state = S[0];
	vector<int> v;
	int val = 0;


	for (int i = 0; i < N; i++) {
		if (S[i] != state)
			v.push_back(val),val = 0;
		val++;
		state = S[i];
	}
	v.push_back(val);
	v.push_back(0);

	if (S[0] == '0') 
		v.insert(v.begin()+0, 0);
	
	if (v.size() < 2 * K + 1)
		 ans = N;
	else{
		for (int i = 0; 2 * (K + i) < v.size(); i++) {
			int sum = 0;
			for (int j = 0; j <= 2 * K; j++)
				sum += v[2*i + j];
			if (ans < sum) ans = sum;
		}
	}
	cout << ans;
}

Measured memory_bytes: 1020
from itertools import permutations
n=int(input())
p=list(map(int,input().split()))
q=list(map(int,input().split()))
p_permu=sorted(list(permutations(p)))
q_permu=sorted(list(permutations(q)))
print(abs(p_permu.index(tuple(p))-q_permu.index(tuple(q))))

Measured memory_bytes: 18724
#include "bits/stdc++.h"
#include <cassert>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define vi vector<int>
#define pb push_back
#define INF 999999999
#define int ll

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

ll lcm(ll a,ll b){
	return a/gcd(a,b)*b;
}

struct stick{
	int ld,rd,left,right;
};


vector<stick> data;

int solve(int num){
	
	int lweight = 1,rweight = 1;
	if(data[num].left !=0) lweight = solve(data[num].left );
	if(data[num].right!=0) rweight = solve(data[num].right);
	
	int ledge = data[num].ld/gcd(data[num].ld,data[num].rd);
	int redge = data[num].rd/gcd(data[num].ld,data[num].rd);
	
	if(lweight==1 && rweight==1){
		return ledge+redge;
	}
	else{
		int res = lcm(lweight*ledge,rweight*redge);
		return res/ledge + res/redge;
	}
}


int getParent(int n){
	int par[200];
	rep(i,200)par[i]=-1;
	
	for(int i=1;i<=n;i++){
		if(data[i].left !=0) par[data[i].left ] = i;
		if(data[i].right!=0) par[data[i].right] = i;
	}
	
	for(int i=1;i<=n;i++){
		if(par[i]==-1)return i;
	}
	return -1;
}


signed main(){
	int n;
	while(cin>>n&&n){
		data.clear();
		data.pb(stick{-1,-1,-1,-1});
		rep(i,n){
			int a,b,c,d;
			cin>>a>>b>>c>>d;
			data.pb(stick{a,b,c,d});
		}
		int root = getParent(n);
		
		cout<<solve(root)<<endl;
	}
}

Measured memory_bytes: 3032
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <queue>
#include <iostream>
#include <string.h>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <cstdint>
#include <climits>
#include <unordered_set>
#include <sstream>

using namespace std;

#define ll long long int
#define pii pair<ll,ll>
#define ti3 tuple<ll,ll,ll>

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

struct UnionFind {
    vector<int> data;
    
    UnionFind(int size) : data(size, -1) { }
    
    bool unionSet(int x, int y) {
        x = root(x); y = root(y);
        if (x != y)
        {
            if (data[y] < data[x]) swap(x, y);
            data[x] += data[y]; data[y] = x;
        }
        return x != y;
    }
    bool findSet(int x, int y) {
        return root(x) == root(y);
    }
    int root(int x) {
        return data[x] < 0 ? x : data[x] = root(data[x]);
    }
    int size(int x) {
        return -data[root(x)];
    }
};

vector<ll> g;

int main(void)
{
    int n,m;
    cin >> n >> m;
    g.assign(n, 0);
    vector<pii> p;
    for(int i = 0;i < m;i++)
    {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        g[a]++;
        g[b]++;
    }
    for(auto e : g)
    {
        if(e % 2 != 0)
        {
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
    return 0;
}

Measured memory_bytes: 1024
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;

/*
<url:https://cf17-final-open.contest.atcoder.jp/tasks/cf17_final_a>
問題文============================================================
 文字列 S が与えられます。
 
 高橋君はこの文字列の好きな位置に好きなだけ文字 A を挿入することができます。
 
 S を AKIHABARA に変えることはできるでしょうか？
=================================================================

解説=============================================================

================================================================
*/
set<string> s;

void init(string akiba){
    s.insert(akiba);
    for(int i = 0; i < (int)akiba.size();i++){
        if(akiba[i] == 'A'){
            init(akiba.substr(0,i) + akiba.substr(i+1));
        }
    }
}
int main(void) {
	cin.tie(0); ios::sync_with_stdio(false);
    string S; cin >> S;
    init("AKIHABARA");
    if(s.find(S) != s.end()){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,m,f[100005],cnt[100005],vis[100005];
int head,tail,que[100005],ans;
vector<int> v[100005];
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		v[x].push_back(y);
		cnt[y]++;
	}
	for(int i=1;i<=n;i++) if(!cnt[i]) que[tail++]=i,vis[i]=1;
	while(head<tail)
	{
		int x=que[head];
		for(int i=0;i<v[x].size();i++)
		{
			int y=v[x][i];
			f[y]=max(f[y],f[x]+1);
			cnt[y]--;
			if(!cnt[y]&&!vis[y]) que[tail++]=y,vis[y]=1;
		}
		head++;
	}
	for(int i=1;i<=n;i++) ans=max(ans,f[i]);
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 7296
H,W = map(int,input().split())
Mini = 999999999999999

for i in range(1,H+1):
  A = i * W
  B1 = (H-i)//2 * W
  C1 = (H-i-(H-i)//2) * W
  M = max(A,B1,C1) - min(A,B1,C1)
  Mini = min(Mini,M)
  
  B2 = W//2 * (H-i)
  C2 = (W - W//2) * (H-i)
  M = max(A,B2,C2) - min(A,B2,C2)
  Mini = min(Mini,M)
  
for i in range(1,W+1):
  A = i * H
  B1 = (W-i)//2 * H
  C1 = (W-i-(W-i)//2) * H
  M = max(A,B1,C1) - min(A,B1,C1)
  Mini = min(Mini,M)
  
  B2 = H//2 * (W-i)
  C2 = (H - H//2) * (W-i)
  M = max(A,B2,C2) - min(A,B2,C2)
  Mini = min(Mini,M)
  
print(Mini)

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

using namespace std;

using ll = long long;

ll calc1(ll n) {
	vector<ll> p;
	{
		vector<bool> e(n+1, true);
		e[0] = e[1] = false;
		for (ll i = 0; i < n+1; i++) {
			if (e[i]) {
				p.push_back(i);
				for (ll j = i+i; j < n+1; j += i) {
					e[j] = false;
				}
			}
		}
	}
	ll res = 1;
	for (auto x: p) {
		ll t = 0;
		for (ll a = n / x; a; a /= x) t += a;
		res *= t + 1;
		res %= 1000000007;
	}
	return res;
}

int main() {
	ll n;
	cin >> n;
	cout << calc1(n) << endl;
}

Measured memory_bytes: 256
S=input()
A=int(S[:2])
B=int(S[2:])
if 1<=A<=12:
    if 1<=B<=12:
        print("AMBIGUOUS")
    else:
        print("MMYY")
else:
    if 1<=B<=12:
        print("YYMM")
    else:
        print("NA")


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

#define STACK 1000
#define MAX 10

void push(int x);
int pop(void);

int stack[STACK];
int sp;

int main(void) {
  int x, y;
  char s[MAX];

  while(scanf("%s", s) != EOF) {
    if(s[0] == '+') {
      x = pop(); y = pop();
      push(y + x);
    }else if(s[0] == '-') {
      x = pop(); y = pop();
      push(y - x);
    }else if(s[0] == '*') {
      x = pop(); y = pop();
      push(y * x);
    }else {
      x = atoi(s);
      push(x);
    }
  }

  printf("%d\n", pop());

  return 0;
}

void push(int x) {
  if(sp >= STACK-1) {
    printf("スタックの容量が満タンです\n");
  }
  else {
    ++sp;
    stack[sp] = x;
  }
}

int pop(void) {
  if(sp == 0) {
    printf("スタックには何も入ってしません\n");
  }
  else {
    --sp;
    return stack[sp+1];
  }
}



Measured memory_bytes: 2112
from sys import stdin
def main():
    #入力
    readline=stdin.readline
    n,k=map(int,readline().split())
    a=list(map(lambda x:int(x)-1,readline().split()))

    flags=[False]*n

    now=0
    cnt=0
    while True:
        flags[now]=True
        cnt+=1
        nex=a[now]
        if flags[nex]:
            last=now
            break
        else:
            now=nex

    f_cnt=cnt
    cnt=0
    while True:
        nex=a[now]
        if nex==last:
            cnt+=1
            break
        else:
            now=nex
            cnt+=1

    l=k-(f_cnt-cnt)
    if l<0:
        now=0
        for _ in range(k):
            now=a[now]
        print(now+1)
    else:
        l%=cnt
        now=a[last]
        for _ in range(l):
            nex=a[now]
            now=nex

        print(now+1)
if __name__=="__main__":
    main()

Measured memory_bytes: 31452
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
const int inf = 1e9;

int main(){
	while(1){
		int n;
		cin >> n;
		if(n==0) break;
		
		vector<int> a(n);
		for(int i=0; i<n; i++){
			cin >> a[i];
		}
		
		int ans=-inf;
		for(int i=0; i<n; i++){
			int sum=0;
			for(int j=0; i+j<n; j++){
				sum += a[i+j];
				ans = max(ans, sum);
			}
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 3088
N,K=map(int,input().split())
L=[]
for i in range(1,N+1):
  l=0
  while i*2**l<K:
    l+=1
  else:
    L.append(l)
ans=0
for m in range(N):
  ans+=1/N*((1/2)**L[m])
print(float(ans))

Measured memory_bytes: 3864
#include <iostream>
#include <vector>

int main() {
    int N;
    std::cin >> N;
    int S = (N % 2 == 0 ? N + 1 : N);

    std::vector<int> u, v;
    for (int i = 1; i <= N; ++i) {
        for (int j = i + 1; j <= N; ++j) {
            if (i + j != S) {
                u.push_back(i);
                v.push_back(j);
            }
        }
    }

    std::cout << u.size() << std::endl;
    for (int i = 0; i < u.size(); ++i) {
        std::cout << u[i] << " " << v[i] << std::endl;
    }
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
const ll INF = 1LL<<60;
/////////////////////////////////
int main(){
    ll N;
    cin >> N;
    if(N%2==1)
        cout << 0 << endl;
    else{
        ll p5=10,ans=0;
        while(N/p5){
            ans += N / p5;
            p5 *= 5;
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 3636
-- | Main entry point to the application.
module Main where

import Control.Applicative
import Control.Monad
import Data.List
import Debug.Trace
import Text.Printf

rInt :: String -> Int
rInt str = read str :: Int

condd :: Int -> Int -> Int -> String
condd a b c
    | a < b && b < c = "Yes"
    | otherwise = "No"

-- | The main entry point.
main :: IO ()
main = do
    lst <- (map rInt . words) <$> getLine
    let sorted = sort lst
    printf "%d %d %d\n" (sorted !! 0) (sorted !! 1) (sorted !! 2)

Measured memory_bytes: 3676
#include<bits/stdc++.h>
using namespace std;
#define itn int
#define endl '\n'

int main(void){
    string s;
    int q;
    cin >> s >> q;
    
    deque<char> str(s.size());
    for(int i = 0;i < s.size();i++)str[i] = s[i];
    
    int back = 0;
    for(int i = 0;i < q;i++){
        int t;
        cin >> t;
        if(t == 1)back++,back %= 2;
        else {
            int f;
            char c;
            cin >> f >> c;
            f--;
            if((back + f) % 2 == 0)str.push_front(c);
            else str.push_back(c);
        }
    }
    
    if(back == 1)reverse(str.begin(),str.end());
    
    for(auto i : str)cout << i;
    cout << endl;
}

Measured memory_bytes: 896
N = int(input())
P = list(map(int, input().split()))
Q = list(map(int, input().split()))

import itertools
p = list(itertools.permutations(range(1,N+1)))

for i in range(len(p)):
    p[i] = list(p[i])
    if p[i] == P:
        a = i + 1
    if p[i] == Q:
        b = i + 1
        
print(abs(a-b))




Measured memory_bytes: 49648
import java.util.*;
public class Main
{
    public static Scanner sc = new Scanner(System.in);
	public static void main(String[]args)
    {
      String str = sc.next();
      int len = str.length();
      if(str.charAt(len-1)!='s')
      	System.out.println(str + 's');
      else
        System.out.println(str + "es");
    }
}


Measured memory_bytes: 38524
#include <bits/stdc++.h>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define pb push_back
#define all(r) (r).begin(),(r).end()
#define rall(r) (r).rbegin(),(r).rend()
#define fi first
#define se second
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll LINF = 1e18;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

#define MAX_V 1000010

struct Edge
{
	int to, cap, rev;
	Edge(){};
	Edge(int to, int cap, int rev) : to(to), cap(cap), rev(rev){};
};

vector<Edge> G[MAX_V];
bool used[MAX_V];

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

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

int max_flow(int s, int t){//O(FE);
	int flow = 0;
	while(1){
		memset(used, 0, sizeof(used));
		int f = dfs(s, t, INF);
		if(f == 0) return flow;
		flow += f;
	}
}

int main(){
	int n, m;
	while(cin >> n >> m && n && m) {
		for(int i = 0; i < MAX_V; i++) G[i].clear(), used[i] = false;
		vector<int> b(n), r(m);
		rep(i, n) cin >> b[i];
		rep(i, m) cin >> r[i];
		set<int> bst[510], rst[510];
		rep(i, n) {
			for(int j = 2; (ll)(j*j) <= b[i]; j++){
				if(b[i]%j == 0) bst[i].insert(j);
				while(b[i]%j == 0) b[i] /= j;
			}
			if(b[i] != 1) bst[i].insert(b[i]);
		}
		rep(i, m) {
			for(int j = 2; (ll)(j*j) <= r[i]; j++){
				if(r[i]%j == 0) rst[i].insert(j);
				while(r[i]%j == 0) r[i] /= j;
			}
			if(r[i] != 1) rst[i].insert(r[i]);
		}
		int s = n + m, t = n + m + 1;
		rep(i, n) add_edge(s, i, 1);
		rep(i, m) add_edge(n + i, t, 1); 
		rep(i, n) rep(j, m) {
			for(auto& p : bst[i]) {
				if(rst[j].count(p)) {
					add_edge(i, n + j, 1);
					break;
				}
			}
		}
		cout << max_flow(s, t) << endl;
	}
}

Measured memory_bytes: 33844
#include <stdio.h>

int main (void) {
    int n;
    scanf("%d", &n);
    int i, p, sum = 0, max = 0;
    for ( i = 0; i < n; i++ ) {
        scanf("%d", &p);
        sum += p;
        if ( p > max ) {
            max = p;
        }
    }
    sum -= max/2;

    printf("%d\n", sum);
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define ll long long int
#define yorn(f) cout<<((f)?"Yes":"No")<<endl
#define YORN(f) cout<<((f)?"YES":"NO")<<endl
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define println(x) cout << x << endl
using namespace std;
int main()
{
    int x, t;
    cin >> x >> t;
    cout << max(0, x - t) << endl;
    return 0;
}

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

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

		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		int[] l = new int[n];
		for (int i = 0; i < n; i++) {
			l[i] = sc.nextInt();
		}
		Arrays.sort(l);

		int ans = 0;
		for (int i = 0; i < k; i++) {
			ans += l[n - 1 - i];
		}

		System.out.println(ans);
		sc.close();
	}
}

Measured memory_bytes: 23764
#include<iostream>
#include<vector>
#include<algorithm>

const static int INF = 1001001001;

int main(void){
    int n;
    std::cin >> n;
    std::vector<int> a(n);
    for(int i = 0; i < n; i++){
	std::cin >> a[i];	
    }
    std::sort(a.begin(), a.end());

    int MAX = a[n-1];
    std::vector<int> acnt(MAX+1);
    acnt[0] = INF;

    for(int i = 0; i < n; i++){
	if(i != 0 && a[i] == a[i-1]){
	    acnt[a[i]]++;
	}
	for(int j = a[i] * 2; j <= MAX; j = j + a[i]){
	    acnt[j]++;
	}
    }


    int cnt = 0;
    for(int i = 0; i < n; i++){
	if(acnt[a[i]] == 0) cnt++;
    }

    std::cout << cnt << std::endl;

    return 0;
}


Measured memory_bytes: 8012
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <math.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <stack>
#include <queue>

typedef unsigned long long ULLONG;
typedef long long LLONG;
static const LLONG MOD_NUM = 1000000007;

template<class _T> static void getval(_T& a) {
	std::cin >> a;
}
template<class _T> static void getval(_T& a, _T& b) {
	std::cin >> a >> b;
}
template<class _T> static void getval(_T& a, _T& b, _T& c) {
	std::cin >> a >> b >> c;
}
template <class _T> static _T tp_abs(_T a) {
	if (a < (_T)0) {
		a *= (_T)-1;
	}
	return a;
}
template <class _T> static void tp_swap(_T& right, _T& left) {
	//	usage:  tp_swap<type name>(a, b);
	_T tmp = right;
	right = left;
	left = tmp;
}

static void exec();

int main()
{
	exec();
	fflush(stdout);
	return 0;
}

static void exec()
{
	int N;
	getval(N);

	if (N == 1) {
		printf("0\n");
		return;
	}

	LLONG ai;
	std::map<LLONG, int> index;
	std::vector<LLONG> odd(N / 2), even(N / 2 + N % 2);
	for (int i = 0; i < N; i++) {
		getval(ai);
		if (i % 2) {
			odd[i / 2] = ai;
		}
		else {
			even[i / 2] = ai;
		}
		index[ai] = 1;
	}

	int idx = 0;
	for (auto it = index.begin(); it != index.end(); it++) {
		it->second = idx;
		idx++;
	}

	int ans = 0;
	for (auto it = even.begin(); it != even.end(); it++) {
		if (index[*it] % 2) {
			ans++;
		}
	}

	printf("%d\n", ans);
}


Measured memory_bytes: 10392
#include<cstdio>
#include<cmath>
#include<vector>
#include<string>
#include<algorithm>

using namespace std;

int main()
{
	int lb[] = { 1, 100,10000};
	int arr[] = { 9,999,99999 };
	int ub[] = { 99,9999,999999 };
	int tar[] = { 9,900,90000};
	int n;
	int i;
	int sum = 0;

	scanf("%d", &n);

	if (n == 100000)
	{
		printf("90909\n");

		return 0;
	}


	for (i = 0; i < 3; i++)
	{
		if (n >= lb[i] && n <= ub[i])
		{
			sum += arr[i] <= n ? tar[i] : n - lb[i] + 1;

			break;
		}

		sum += tar[i];
	}
	
	printf("%d\n", sum);

		return 0;
}

Measured memory_bytes: 128
n = int(input())
li = list(map(int, input().split()))
li_a = list(reversed(li))
from collections import deque
a = 0
b = sum(li)
while a < b//2:
  s = li.pop()
  a += s
c = sum(li)

d = 0
e = sum(li_a)
while d < e//2:
  t = li_a.pop()
  d += t
f = sum(li_a)
print(min(a-c, d-f))


  

Measured memory_bytes: 26060
using System;
using System.Linq;
using System.Collections.Generic;
public class P{
    public static void Main(){
        var s = Console.ReadLine();
        long N = long.Parse(s);
        var s1 =Console.ReadLine().Split(' ');
        double T=double.Parse(s1[0]), A = double.Parse(s1[1]);
        s1= Console.ReadLine().Split(' ');
        List<int> a = new List<int>();
        for (int i = 0;i<N;i++){
            a.Add(int.Parse(s1[i]));
        }
        var b = a.OrderBy(x => Math.Abs(T-0.006*x-A)).ToArray();
        for (int i = 0;i<N;i++){
            if (a[i]==b[0]) Console.WriteLine(i+1);
        }
    }
}

Measured memory_bytes: 13340
#include <bits/stdc++.h>
#define rep(i, n) REP(i, 0, n)
#define REP(i, l, r) for (int i = l; i < r; ++i)
#define int long long
#ifdef DEBUG
#define dout cout
#else
std::stringstream dout;
#endif
using namespace std;
typedef pair<int, int> P;
// other libs

signed main(int argc, char* argv[]) {
	int ans=0,n;
	cin>>n;
	rep(i,n)ans+=i;
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
// const bool debug=true;
const bool debug=false;
#define DEBUG if(debug==true)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1000000007;

int main(void) {
    int n,q;cin>>n>>q;
    vector<int> a(n),b(n);
    vector<int> parent(n,0);
    vector<vector<int> >  children(n,vector<int>());
    vector<int> res(n,0);
    rep(i,n-1){
        cin>>a.at(i)>>b.at(i);
        a.at(i)--;
        b.at(i)--;
        children.at(a.at(i)).push_back(b.at(i));
        parent.at(b.at(i))=a.at(i);
    }
    rep(i,q){
        int tmp,x;
        cin>>tmp>>x;
        res.at(tmp-1)+=x;
    }
    queue<int> que;
    que.push(0);
    while(!que.empty()){
        int cur = que.front();
        que.pop();
        if(cur!=0){
            res.at(cur) += res.at(parent.at(cur));
        } 
        for(auto x:children.at(cur)){
            que.push(x);
        }
    }
    rep(i,n){
        cout << res.at(i);
        cout << (i==n-1 ? "\n" : " ");
    }
    return 0;
}


Measured memory_bytes: 16512
#include <iostream>
#include <algorithm>
#include <queue>
#include <vector>
#include <set>
#include <cmath>
#include <string>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ROF(i,a,b) for(int i=b-1;i>=a;i--)
#define FI first
#define SE second
#define SI size()
#define VE vector<int>
#define MA(i,j) make_pair(i,j)
#define PA pair<int,int>
#define PB push_back
#define LL long long
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define Yes(i) cout<<(i?"Yes":"No")<<endl
using namespace std;
//
const int INF=1e8+7;
const int MOD=1e9+7;
//
int main(){
  LL N,M;
  cin>>N;
  M=N;
  LL S=0;
  LL C=0;
  LL A;
  while(N){
    if(N<10){
      A=N;
    }
    S+=N%10;
    N/=10;
    C++;
  }
  if(S==N){
    cout<<S<<endl;
  }else if((S-A)==9*(C-1)){
    cout<<S<<endl;
  }else if(S==1){
    cout<<(C-1)*9<<endl;
  }else if(S==C*9){
    cout<<S<<endl;
  }else{
    cout<<(C-1)*9+A-1<<endl;
  }
  return 0;
}


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

using namespace std;

typedef long long LL;
typedef pair<int , int> P2;
typedef pair<pair<int , int> , int> P3;
typedef pair<pair<int , int> , pair<int , int> > P4;
#define PB(a) push_back(a)
#define MP(a , b) make_pair((a) , (b))
#define M3P(a , b , c) make_pair(make_pair((a) , (b)) , (c))
#define M4P(a , b , c , d) make_pair(make_pair((a) , (b)) , make_pair((c) , (d)))
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)

int main(){
	int N,K; cin >> N >> K;
	cout << (N%K?1:0) << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn = 1e5+100;
int prime[maxn];
bool num[maxn];
int pos;
void init()
{
    pos = 1;
    memset(num,false,sizeof(num));
    for(int i = 2;i<=maxn;++i)
    {
        if(!num[i])
        {
            prime[pos++] = i;
        }
        for(int j = 1;j<pos&&prime[j]*i<=maxn;++j)
        {
            num[i*prime[j]] = 1;
            if(i%prime[j]==0)
                break;
        }
    }
}
int main()
{
    init();
    int x;
    cin >> x;
    for(int  i = 1;i<pos;++i)
    {
        if(prime[i]>=x)
        {
            cout << prime[i] << "\n";
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<math.h>
#include<algorithm>
#include<stdlib.h>
#include<stack>
#include<set>
#include<string.h>
#include<map>
#include<vector>
#define pb push_back
#define eb emplace_back
#define ins insert 
#define mp make_pair
#define ll long long 
#define max3(a,b,c) max(c,max(a,b))
#define min3(a,b,c) min(c,min(a,b))
#define M 10000007
#define inf 1000000000000000000
using namespace std;
vector<vector<ll> > v;
bool vis[100005];
ll dp[100005];
void dfs(int node){
	if(v[node].size()==0 || vis[node])
		return;
	vis[node]=true;
	for (int i = 0; i < v[node].size(); ++i)
	{
		if(!vis[v[node][i]])
			dfs(v[node][i]);
		dp[node]=max(dp[node],1+dp[v[node][i]]);
	}
}
void solve(){
	ll vertex,e,ans=0;
	cin>>vertex>>e;
	//cout<<0<<endl;
	v.resize(vertex+1);
	memset(vis,false,sizeof(vis));
	ll x,y;
	for (int i = 0; i <=vertex; ++i)
	{
		dp[i]=0;
	}
	//cout<<"1";
	for (int i = 0; i < e; ++i)
	{
		cin>>x>>y;
		v[x].pb(y);
	}
	//cout<<"2";
	for (int i = 1; i <=vertex; ++i)
	{
		if(!vis[i])
			dfs(i);
	}
	//cout<<"3";
	for (int i = 1; i <=vertex; ++i)
	{
		ans=max(ans,dp[i]);
	}
	cout<<ans;

}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll t=1;
    //cin>>t;
    while(t--){
        solve();
    }
    return 0 ;
}


Measured memory_bytes: 8704
#include <bits/stdc++.h>
using namespace std;
#define __ <<" "<<
#define ___ <<" "
#define bash push_back
#define ALL(x) x.begin(),x.end()

struct IoSetup {
    IoSetup() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(10);
        cerr << fixed << setprecision(10);
    }
}IoSetup;

typedef long long ll;
typedef pair < int , int >  pii;
static const signed int INF = 0x3f3f3f3f;
static const signed long long LINF = 0x3f3f3f3f3f3f3f3fLL;
static const signed int SMOD = 1000000007;
static const signed int NMOD = 998244353;
static const signed int dx[]={1,0,-1,0,1,1,-1,-1};
static const signed int dy[]={0,-1,0,1,-1,1,-1,1};

bool inside(int x,int y,int w,int h){return (x>=0 && y>=0 && x<w && y<h);}
template<class T>T abs(T &x){return x<0 ? -x : x;}
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; }

int x;

int dp[100005];

signed main() {

	cin >> x;

	vector<int> d;
	
	for(int i = 0; i < 6; i++){
		d.bash(100+i);
		dp[100+i] = 1;
	}
	
	for(int i = 0; i <= x; i++) {
		for(int j = 0; j < 6; j++) {
			if(i - d[j] >= 0)
				chmax(dp[i],dp[i-d[j]]);
		}
	}
			
	
	cout << dp[x] << endl;
			

    return 0;
}



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

int main(){
	for (long i = 0; i < 9; i++){
		for (long j = 0; j < 9; j++){
			cout << (i + 1) << "x" << (j + 1) << "=" << (i + 1) * (j + 1) << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1116
#include <stdio.h>

int main()
{
  int n, i;
  long a[10005], min, max;
  long long sum;
  scanf("%d", &n);
  scanf("%ld", &a[0]);
  sum = max = min = a[0];
  for (i = 1; i < n; i++) {
    scanf("%ld", &a[i]);
    if (a[i] < min) {
      min = a[i];
    }
    else if (a[i] > max) {
      max = a[i];
    }
    sum += a[i];
  }

  printf("%ld %ld %lld\n", min, max, sum);

  return 0;
}

Measured memory_bytes: 676
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main(void){
    int n, r = 0;
    string c;
    cin >> n >> c;
    for(char s: c){
        if(s == 'R') r ++;
    }
    int x = 0, y = 0;
    for(int i=0;i<n;i++){
        if(i < r && c[i] == 'W'){
            x++;
        }
        if(i >= r && c[i] == 'R'){
            y++;
        }
    }
    cout << max(x, y ) << endl;
}


Measured memory_bytes: 3488
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define all(v) v.begin(), v.end()
#define sz(v) v.size()
#define INF 100000000000000 //10^14
template <typename T>
bool chmax(T &a, const T& b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
bool chmin(T &a, const T& b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
  if ((x += a.x) >= mod) x -= mod;
  return *this;
  }
  mint& operator-=(const mint a) {
  if ((x += mod-a.x) >= mod) x -= mod;
  return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
  if (!t) return 1;
  mint a = pow(t>>1);
  a *= a;
  if (t&1) a *= *this;
  return a;
  }
  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

int main()
{
    string S;
    cin >> S;
    vector<ll> rem(100003, 1); //10^iを13で割った余り
    rep(i, 99999){
        rem.at(i+1) = (rem.at(i) * 10) % 13;
    }
    vector<vector<mint>> dp(100003, vector<mint>(13, 0)); //下i+1桁を13で割った余りがjになる場合の数
    reverse(all(S));
    if(S.at(0) == '?'){
        rep(i, 10){
            dp.at(0).at(i) = 1;
        }
    }
    else{
        dp.at(0).at(S.at(0) - '0') = 1;
    }
    rep(i, sz(S)-1){
        if(S.at(i+1) == '?'){
            rep(j, 10){
                rep(k, 13){
                    dp.at(i+1).at((k+j*rem.at(i+1))%13) += dp.at(i).at(k);
                }
            }
        }
        else{
            rep(j, 13){
                dp.at(i+1).at((j+(S.at(i+1)-'0')*rem.at(i+1))%13) += dp.at(i).at(j);
            }
        }
    }
    cout << dp.at(sz(S)-1).at(5) << endl;
}

Measured memory_bytes: 17464
#include<bits/stdc++.h>
#include<math.h>
using namespace std;
typedef long long ll;
const int INF = 1<<30;
int main(){
  int n;cin>>n;int m=INF, M=-1;
  for(int i=0;i<n;i++){
    int x;cin>>x;
    m=min(m, x);M=max(M, x);
  }
  cout << M-m << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define sz(x) (int)(x).size()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define EPS (1e-10)
#define equals(a, b) (fabs((a)-(b)) < EPS)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
  
int main() {
  vvi G(4);
  rep(i,3) {
    int a,b;
    cin >> a >> b;
    a--;b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  vi cnt(3,0);
  rep(i,4) {
    cnt[sz(G[i])]++;
  }
  if(cnt[2]==2&&cnt[1]==2) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
  return 0;
}

Measured memory_bytes: 3596
#include <iostream>
#include <vector>
#include <cmath>
#include <iomanip>

using namespace std;

struct point { double x, y; };
int n, k, EPS = 100;
double l = 0, ri = 1E10;
vector<point> p;
vector<double> c;

double len(point a, point b) { return hypot((a.x - b.x), (a.y - b.y)); }

bool yet_ok(double t)
{
    if (n == 1)
        return true;

     vector<double> r(n);

    for (int i = 0; i < n; i++)
        r[i] = t / c[i];

    for (int i = 0; i < n; i++)
        for (int j = i + 1; j < n; j++)
        {
            if (len(p[i], p[j]) > r[i] + r[j])
                continue;

            if (len(p[i], p[j]) < fabs(r[i] - r[j]))
                continue;

            double a1 = -2 * (p[i].x - p[j].x);
            double b1 = -2 * (p[i].y - p[j].y);
            double c1 = p[i].x * p[i].x - p[j].x * p[j].x + p[i].y * p[i].y -
                    p[j].y * p[j].y - r[i] * r[i] + r[j] * r[j];

            point o;
            int cnt = 0;

            double d1 = len({ 0, 0 }, { a1, b1 });
            a1 /= d1;
            b1 /= d1;
            c1 /= d1;

            d1 = a1 * p[i].x + b1 * p[i].y + c1;

            o = { p[i].x - a1 * d1, p[i].y - b1 * d1};
            double move = sqrt(r[i] * r[i] - d1 * d1);

            vector<point> all_dots = {
                    {o.x + b1 * move, o.y - a1 * move},
                    {o.x - b1 * move, o.y + a1 * move}
            };

            for (auto v : all_dots)
            {
                cnt = 0;
                o = v;
                for (int q = 0; q < n; q++)
                    if (len(p[q], o) <= r[q] || q == i || q == j)
                        cnt++;

                if (cnt >= k)
                    return true;
            }
        }

    for (auto o : p)
    {
        int cnt = 0;
        for (int q = 0; q < n; q++)
            if (len(p[q], o) <= r[q])
                cnt++;

        if (cnt >= k)
            return true;
    }

    return false;
}

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

    cin >> n >> k;

    p.resize(n);
    c.resize(n);

    for (int i = 0; i < n; i++)
        cin >> p[i].x >> p[i].y >> c[i];

    for (int it = 0; it < EPS; it++)
    {
        double m = (l + ri) / 2;

        if (yet_ok(m))
            ri = m;
        else
            l = m;
    }

    cout << fixed << setprecision(20);
    cout << ri << "\n";

    return 0;
}


Measured memory_bytes: 384
inp = list(map(int, list(input())))
if inp[0] < inp[1] or (inp[0] == inp[1] and inp[1] < inp[2]):
    for i in range(3):
        print(inp[0] + 1, end="")
    print()
else:
    for i in range(3):
        print(inp[0], end="")
    print()


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

int main() {
  int n;
  cin >> n;
  vector<string> s(n);
  int ans = 0;
  rep(i, n) cin >> s[i];

  sort(s.begin(), s.end());
  s.erase(unique(s.begin(), s.end()), s.end());

  cout << s.size() << endl;

  return 0;
}


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

int main() {
    // #ifndef ONLINE_JUDGE
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    // #endif

    int n;
    cin>>n;
    int a[n];
    for(int i = 0;i < n;i++) cin>>a[i];
    sort(a,a+n);
    int lhs = a[n-1], rhs = 0;
    for(int i = 0;i < n-1;i++) rhs += a[i];
    if(lhs < rhs) cout<<"Yes";
    else cout<<"No";
    
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <iomanip> // cout<<setprecision(n)
#include <functional> // std::function<void(int)>
using namespace std;
#define All(v) (v).begin(),(v).end()
const long long mod = 1000000007;
const long long inf = mod*mod;
const int MAXS = 114514;
const double EPS=1e-10;
const double INF=1e+10;
const double PI=acos(-1.0);
signed main(){
    int n;
    cin>>n;
    vector<int> s(n);
    for(int i=0;i<n;i++){
        cin>>s[i];
    }
    s.push_back(0);
    sort(All(s));
    int dp[111][111];
    for(int i=0;i<110;i++){
        for(int j=0;j<110;j++){
            dp[i][j]=0;
        }
    }
    for(int i=0;i<n+1;i++){
        for(int j=1;j<n+1;j++){
            if(i==j){
                dp[i][j]=dp[i][j-1];
            }
            else{
                dp[i][j]=dp[i][j-1]+s[j];
            }
        }
    }
    int res = 0;
    for(int i=0;i<n+1;i++){
        for(int j=0;j<n+1;j++){
            if(dp[i][j]%10!=0){
                res=max(res,dp[i][j]);
            }
        }
    }
    cout<<res<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long long ld;
ll read(){ll x;scanf("%lld",&x);return x;}
ll F(ll x,ll y){
	if(x%y==0){return 2*x-y;}
	return F(y,x%y)+2*(x/y)*y;
}
int main(){
	ll N=read(),X=read();
	printf("%lld\n",F(N-X,X)+N);
	return 0;	
} 

Measured memory_bytes: 256
var line = require('fs').readFileSync('/dev/stdin', 'utf8').split(/ |\n/);
var n = Number(line[0]);
var q = Number(line[1]);
var i;
var time = 0;
var queue = [];

var name_start = 2;
var name_end = 2 + 2 * n;
var rest_start = 3;
var rest_end = 3 + 2 * n;

for (i = rest_start; i < rest_end; i += 2) line[i] = Number(line[i]);

// run all processes once
for (i = name_start; i < name_end; i += 2) {
    if (line[i+1] <= q) {
        time += line[i+1];
        console.log(line[i], time);
    } else {
        time += q;
        line[i+1] -= q;
        queue.push(i);
    }
}

// run processes on queue
while (queue.length != 0) {
    i = queue.shift();
    if (line[i+1] <= q) {
        time += line[i+1];
        console.log(line[i], time);
    } else {
        time += q;
        line[i+1] -= q;
        queue.push(i);
    }
}

Measured memory_bytes: 37072
#include <iostream>
#include <algorithm>
#include <string>
#include  <queue>
#include <vector>
#include  <cstdio>
#include <cstring>
#include<map>
#include<cmath>
#include<set>
//#include<bits/stdc++.h>
#define ll long long int
#define ull unsigned long long int
#define I(a) scanf("%d",&a)
#define I2(a,b) scanf("%d%d",&a,&b)
#define I3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define L(a) scanf("%lld",&a)
#define L2(a,b) scanf("%lld%lld",&a,&b)
#define L3(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define PI(a) printf("%d",a)
#define PL(a) printf("%lld",a)
#define PT(t) printf("Case %d: ",t)
#define PB push_back
#define x first
#define y second
#define xx first.first
#define xy first.second
#define yx second.first
#define yy second.second
#define SC scanf
#define PC printf
#define NL printf("\n")
#define SET(a) memset(a,0,sizeof a)
#define SETR(a) memset(a,-1,sizeof a)
#define SZ(a) ((int)a.size())-1
#define f(i,a,b) for(int i=a;i<=b; i++)
#define fr(i,a,b) for(int i=a;i<=b; i++)
#define frr(i,a,b) for(int i=a;i>=b; i--)
#define frv(i,a)  for(int i=0;i<a.size();i++)
#define pi 2.0*acos(0.0)
#define R(a) freopen(a, "r", stdin);
#define W(a) freopen(a, "w", stdout);
#define CB(x) __builtin_popcount(x)
#define STN(a) stringtonumber<ll>(a)
#define lol printf("BUG\n")
#define Endl "\n"
#define mk make_pair
using namespace std;
template <class T> inline T BM(T p, T e, T M)
{
    ll ret = 1;
    for(; e > 0; e >>= 1)
    {
        if(e & 1) ret = (ret * p) % M;
        p = (p * p) % M;
    }
    return (T)ret;
}
template <class T> inline T mul(T p, T e, T M)
{
    ll ret = 0;
    for(; e > 0; e >>= 1)
    {
        if(e & 1) ret = (ret + p) ;
        p = (p + p) ;
        if(ret>=M)ret-=M;
        if(p>=M)p-=M;
    }
    return (T)ret;
}
template <class T> inline T gcd(T a, T b)
{
    if(b == 0)return a;
    return gcd(b, a % b);
}
template <class T> inline T mdINV(T a, T M)
{
    return BM(a, M - 2, M);
}
template <class T> inline T PW(T p, T e)
{
    ll ret = 1;
    for(; e > 0; e >>= 1)
    {
        if(e & 1) ret = (ret * p);
        p = (p * p);
    }
    return (T)ret;
}
 
 
template <class T>bool ISLEFT(T a, T b, T c)
{
    if(((a.xx - b.xx) * (b.yy - c.yy) - (b.xx - c.xx) * (a.yy - b.yy)) < 0.0)return 1;  //Uporer dike //A,b,c, x okkher ordera sorted
    else return 0;
}
 

#define  mx 200004
#define base 193ll
 
typedef pair<int,int >P;
//////////////////////////
////////////////////////
#define F(i,a,b) for(int i=a;i<b; i++)
#define LL long long
#define MX  200007
#define md 1000000007ll
///////////////////////////
///////////////////////////
int main() {

   int n;
   I(n);
   ll res = 0;
   ll cum = 0;
   for(int i = 1; i<= n;i++){
       ll x;
       L(x);
       res = (res + cum * x) % md;
       cum = (cum + x) % md;
   }
   cout<<res<<endl;

    return 0;
}

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

public class Main {
	private static Scanner scan;

	public static void main(String a[]){
		scan = new Scanner(System.in);
		int[] list = new int[10];
		for(int i=0;i<10;i++){
			list[i]=scan.nextInt();
		}
		Arrays.sort(list);

		for(int i=9;i>6;i--){
			System.out.println(list[i]);
		}

	}
}



Measured memory_bytes: 26168
#include <bits/stdc++.h>
#define rep3(i, s, n, a) for (int i = (s); i < (int)(n); i += a)
#define rep2(i, s, n) rep3(i, s, n, 1)
#define rep(i, n) rep2(i, 0, n)

using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;

int main(){
    int x;
    cin >> x;
    if(x>=30){
        cout << "Yes";
    }else{
        cout << "No";
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 3620