akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int main(){
    int n,k;cin>>n>>k;
    int x[n]={};
    for(int i=0;i<n;i++){
        cin>>x[i];
    }
    sort(x,x+n);
    long long sum=0;
    for(int i=0;i<n-k;i++){
        sum+=x[i];
    }
    cout <<sum;

}


Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <queue>
using namespace std;

struct st{
	int p, q;
} t, t2;

int k;
bool v[100005];
deque<st> qu;
int main()
{
	cin >> k;
	qu.push_back({1, 1});
	while (1) {
		t = qu.front(); qu.pop_front();
		if (v[t.q]) continue;
		v[t.q] = 1;
		if (t.p > 45) continue;
		if (t.q == 0) {
			cout << t.p; return 0;
		}
		qu.push_front({t.p, t.q * 10 % k});
		qu.push_back({t.p + 1, (t.q + 1) % k});
	}
    return 0;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
#define REP(i,n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i,a,b) for (ll i=(a);i<(ll)b; i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define INF 1000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<ll,ll> p;
const int MOD = 1000000007;

// vector<p> cut(M);
// cut[i].second
// cut[i].first;
// REP(i,M){
//     int a,b;cin>>a>>b;
//     cut[i] = make_pair(b,a);//last first の順番
// }
//     for(int i=0; i<N;i++){
//     }
// sort(cut.begin(),cut.end()); //sort

int main ()
{
    double x[11];
    double xx;
    str u[11];
    str uu;
    int N;cin>>N;
    double sum=0;
    for(int i=0; i<N;i++){
      cin>>xx>>uu;
      if(uu == "JPY"){
        sum += xx;
      }else{
        sum += xx*380000.0;
      }
    }

    cout<<sum<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define boost_io ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define debug(x) cout<<#x<<":"<<x<<" "
#define all(a) (a).begin(), (a).end()
#define cast static_cast
#define vi vector<int>
#define v vector
#define p pair
#define push_back pb
#define mkae_pair mk
typedef long long int ll;
using namespace std;
ll modF=1e9+7;
ll INF=1e11;

void solve(){
	int h,w,k;
	cin>>h>>w>>k;
	v<v<char>> ma(h,v<char>(w));
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			cin>>ma[i][j];
		}
	}
	set<int> sh;
	set<int> sw;
	int ans;
	int hv=0;
	for(int bit1=0;bit1 < 1<<h;bit1++){
		for(int bit2=0;bit2 < 1<<w;bit2++){
			ans=0;
			for(int i=0;i<h;i++){
				if(bit1 & 1<<i){
					sh.insert(i);
				}
			}
			for(int i=0;i<w;i++){
				if(bit2 & 1<<i){
					sw.insert(i);
				}
			}
			for(int i=0;i<h;i++){
				for(int j=0;j<w;j++){
					if(ma[i][j]=='#'){
						if(sh.find(i)==sh.end()){
							if(sw.find(j)==sw.end()){
								ans++;
							}
						}
					}
				}
			}
			if(ans==k){
				hv++;
			}
			sh.clear();
			sw.clear();
		}
	}
	if(k==0){
		cout<<hv-2<<"\n";
		return;
	}
	cout<<hv<<"\n";
}	

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


Measured memory_bytes: 3616
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr



n=int(input())
if n==1:
    print(0)
    exit()
f = factorization(n)
ans=0
for g,m in f:
    for i in range(10000):
        if i*(i+1)//2>m:
            ans+=i-1
            break
print(ans)




Measured memory_bytes: 9480
import itertools

n = int(input())

p_list = [int(i) for i in input().split()]
q_list = [int(i) for i in input().split()]

num_list = [i+1 for i in range(n)]

a = 0
b = 0

for i, v in enumerate(itertools.permutations(num_list, n)): 
    if(list(v) == p_list):
        a = i
    if(list(v) == q_list):
        b = i
print(abs(a - b))

Measured memory_bytes: 3064
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <queue>
#include <iomanip>
#include <cmath>

using namespace std;

int main()
{
	int n;

	cin >> n;

	vector<int> b;
	b.resize(n);

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

	int total = b[0] + b[n-2];

	for (int i = 1; i < n-1; ++i)
	{
		total += min(b[i - 1], b[i]);
	}

	cout << total << endl;

	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>

#define rep(i, n) for(int i = 0; i < (n); i++)
using ll = long long;

int main(){
	ll N, X, T;
	std::cin >> N >> X >> T;
	std::cout << ((N+X-1) / X) * T << std::endl;
	return 0;
}

Measured memory_bytes: 3620
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
#include<iomanip>
#include<list>
#include<deque>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define END {}
#endif
typedef long long ll;
#define int ll
#define uset unordered_set
#define umap unordered_map
typedef std::pair<int,int> P;
struct edge{int to,cost;};
const int INF=100000000000000000;
const int INF2=9223372036854775807;
const int MOD=1000000007;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define min(X,Y) (((int)(X)<(int)(Y))?(X):(Y))
#define max(X,Y) (((int)(X)>(int)(Y))?(X):(Y))
#define MAX(X,Y) (*max_element(X,Y))
#define MIN(X,Y) (*min_element(X,Y))
#define NP(X,Y) next_permutation(X,Y)
#define setp(X,Y) cout<<fixed<<setprecision(Y)<<X;
int ceil2(int a,int b){if(a%b==0){return a/b;}else{return a/b+1;}}
int pow2(int a,int b){int r=1;for(int i=1;i<=b;i++){r*=a;}return r;}
int Log2(int a){int t=0;while(1){if(a==0||a==1){break;}a/=2;t++;}return t;}

int N,Q;
int A[200010],B[200010];
int C[200010],X[200010];
int num[200010];
int num2[200010];
bool F[200010];
vector<int> G[200010];

void dfs(int s,int s2){
	F[s]=true;
	s2+=num[s];
	num2[s]=s2;
	REP(i,G[s].size()){
		int e=G[s][i];
		if(F[e]==false){
			dfs(e,s2);
		}
	}
}

signed main(){
	cin>>N>>Q;
	REP(i,N-1){
		cin>>A[i]>>B[i];
	}
	REP(i,Q){
		cin>>C[i]>>X[i];
	}
	REP(i,N-1){
		G[A[i]-1].push_back(B[i]-1);
		G[B[i]-1].push_back(A[i]-1);
	}
	REP(i,Q){
		num[C[i]-1]+=X[i];
	}
	dfs(0,0);
	REP(i,N){
		cout<<num2[i];
		if(i<N-1){
			cout<<" ";
		}
	}
	cout<<endl;
	return 0;
}


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

int main(){
    int n;
    while(cin >> n, n){
        vector<int> depth[1002];
        string s[n];
        for(int i = 0; i < n; i++){
            cin >> s[i];
            int j;
            for(j = s[i].length()-1; j >= 0; j--){
                if(s[i][j] == '.'){
                    s[i][j] = '+';
                    break;
                }
            }
            depth[j+1].push_back(i);
        }
        for(int i = 1; i < 1002; i++){
            for(int j = 1; j < depth[i].size(); j++){
                bool check = true;
                for(int k = depth[i][j-1]+1; k < depth[i][j]; k++){
                    check &= (s[k][i-1] == '.');
                }
                if(!check)  continue;
                for(int k = depth[i][j-1]+1; k < depth[i][j]; k++){
                    s[k][i-1] = '|';
                }
            }
        }
        for(int i = 0; i < n; i++){
            for(char x : s[i]){
                cout << (x == '.' ? ' ' : x);
            }
            cout << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3808
import numpy as np
from numba import njit

@njit #処理の並列化_これがない場合は'TLE'
def imos(n, a):
    
    l=np.zeros((n+1), dtype = np.int64)

    for i in range(n):
        ai = a[i] # 光の強さ_これにより照らせる範囲が決まる
        start = max(0, i - ai) #StartIndex_照らせる範囲
        end = min(n, i + ai + 1) #EndIndex + 1_照らせる範囲
        l[start] += 1 # 各々を'+1'と'-1'で表し...
        l[end] -= 1
    return np.cumsum(l)[:n] # 累積和をとる_cumulative sum

n, k = map(int, input().split())
a = list(map(int, input().split()))

for _ in range(k):
    a = imos(n, a)
    if a.min() == n: # すべての要素が最大値'n'になるとbreak
        break

print(*a)


Measured memory_bytes: 125060
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<cmath>
#include<math.h>
#include<algorithm>
#include<string.h>
#include <iomanip>
#include <sstream>
using namespace std;

int main() {
  string s;
  string t;
  int ans = 0;

  cin >> s;
  cin >> t;

  for(int i = 0; i < 3; i++){
    if(s[i] == t[i])ans++;
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
n=int(input())
A=list(map(int,input().split()))
def chk(A,t):
  ans=0
  s=0
  for i in A:
    s+=i
    if t==True and s<1:
      ans+=1-s
      s=1
    elif t==False and s>-1:
      ans+=1+s
      s=-1
    t=not t
  return ans
print(min(chk(A,True),chk(A,False)))

Measured memory_bytes: 14332
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double lb;
typedef vector<int,vector<int>> vec;
typedef pair<int,int> P;
#define REP(i,j,n) for (int i=j;i<(n);i++)
#define RREP(i,n,j) for (int i = n; j<i;i--)
#define print(out) cout<< out  << "\n";
#define all(vec) vec.begin(),vec.end()
#define mod 1000000007
const int INF = 1e9;

ll N,M;
string S;

int main(){
  cin>>S;
  N=S.size();
  REP(i,0,N/2){
    if(S.at(i)!=S.at(N-1-i)){
      print("No")
      return 0;
    }
  }
  REP(i,0,(N-1)/2){
    if(S.at(i)!=S.at((N-1)/2-i-1)){
      print("No")
      return 0;
    }
  }
  REP(i,((N+3)/2),N){
    if(S.at(i)!=S.at(N-i-1)){
      print("No")
      return 0;
    }
  }
  print("Yes")

  
}


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

#define rep(i, n) for (ll i = 0; i < n; i++)
#define Rep(i, r, n) for (ll i = r; i < n; i++)
#define pb push_back
#define MOD 1000000007
typedef long long ll;

int main() {
  ll n;
  cin >> n;
  ll max = (ll) sqrt(n);
  for(ll i = max; i > 0; i--) {
    if(n % i == 0) {
      cout << i+(n/i)-2 << "\n";
      return 0;
    }
  }
  cout << n-1 << "\n";
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define rrep(i,n) for(int i=(int)n-1;i>=0;--i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template<typename T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T> inline bool chmin(T& a,T b){if(b<a){a=b;return 1;}return 0;}
template<typename T> vector<T> make_vec(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_vec(size_t a,Ts... ts){return vector<decltype(make_vec<T>(ts...))>(a,make_vec<T>(ts...));}
template<typename T,typename U,typename... V>
typename enable_if<is_same<T,U>::value>::type fill_v(U& u,const V... v){u=U(v...);}
template<typename T,typename U,typename... V>
typename enable_if<!is_same<T,U>::value>::type fill_v(U& u,const V... v){for(auto& e:u)fill_v<T>(e,v...);}

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

    int n;
    cin >> n;
    vector<int> ans(n+1);
    auto f = [](ll a, ll b, ll c) { return a*a + b*b + c*c + a*b + b*c + c*a;};
    for (ll x = 1; x*x < n; ++x) {
        for (ll y = 1; y*y < n; ++y) {
            for (ll z = 1; z*z < n ; ++z) {
                ll now = f(x, y, z);
                if (now <= n) {
                    ans[now]++;
                }
            }
        }
    }
    for (int i = 1; i <= n; ++i) cout << ans[i] << endl;
}


Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define rep(i, n) ;for (int i = 0;i < (int)(n);i++)
#define rep2(i, s, n) ;for (int i = s; i < (int)(n);i++)
#define ALL(vec)  (vec).begin(),(vec).end()
#define pi 3.1415926535897932384626433832795
#define MAX_INF 9223372036854775807
#define MIN_INF (922337203685477587+1)
#define sosuu 1000000007

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

Measured memory_bytes: 3568
import java.util.*;
import java.util.stream.Collectors;
import java.io.*;
import java.math.BigDecimal;
import java.nio.charset.StandardCharsets;

public class Main {
	public static void main(String[] args) throws IOException {
		InputStreamReader reader = new InputStreamReader(System.in, StandardCharsets.UTF_8);
		BufferedReader in = new BufferedReader(reader);
		Main ins = new Main(in);
		ins.calc();
		ins.showResult();
	}

	Main(BufferedReader in) throws IOException {
		String S = in.readLine();
		if((S.charAt(2) == S.charAt(3)) && (S.charAt(4)== S.charAt(5))) {
			System.out.println("Yes");
		}else {
			System.out.println("No");			
		}
	}

	void calc() {
	}

	void showResult() {
	}

}


Measured memory_bytes: 23380
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AtCoder
{
    class Program
    {

        static void Main(string[] args)
        {
            var chars = new[] { 'A', 'C', 'G', 'T' };
            var str = Console.ReadLine();

            var ans = 0;
            for (int i = 0; i < str.Length; i++)
            {
                int a = 0;
                for (int j = i; j < str.Length; j++)
                {
                    if (!chars.Contains(str[j]))
                    {
                        i = j;
                        break;
                    }
                    a++;
                }
                if (ans < a) ans = a;
            }
            Console.WriteLine(ans);
            return;
        }
    }
}

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

public class Main {

	static int min;
	static int MAX=1000000;
	static int dp[]=new int[MAX];
	static int dp2[]=new int[MAX];
	
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int n,i;
		Arrays.fill(dp, -1);
		Arrays.fill(dp2, -1);
		for(i=0;i<MAX;i++){
			min=1<<29;
			serch(i);
			min=1<<29;
			serch2(i);
		}
		while(true){
		n=sc.nextInt();
		if(n==0) break;
		System.out.println(dp[n]+" "+dp2[n]);
		}
	}
	static int serch(int N){
		int k;
		if(dp[N]!=-1) return dp[N];
		if(N==0){
			return 0;
		}
		for(int i=1;;i++){
			k=i*(i+1)*(i+2)/6;
			if(N<k) break;
			min=Math.min(min, serch(N-k)+1);
		}
		dp[N]=min;
		return min;
	}
	static int serch2(int N){
		int k;
		if(dp2[N]!=-1) return dp2[N];
		if(N==0){
			return 0;
		}
		for(int i=1;;i++){
			k=i*(i+1)*(i+2)/6;
			if(k%2==0) continue;
			if(N<k) break;
			min=Math.min(min, serch2(N-k)+1);
		}
		dp2[N]=min;
		return min;
	}

}

Measured memory_bytes: 19000
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <iomanip>
#define ll long long

using namespace std;

long long MOD = 1000000007;

template<typename T>
void cout_vec(vector<T> &vec){
    for(int i=0; i<vec.size(); i++){
        if (i!=0){
            cout << ' ';
        }
        cout << vec[i];
    }
    cout << endl;
}

int main(){
    ll N, K;
    cin >> N >> K;
    vector<int> A(N,0);
    map<int, vector<int> > mp;

    for(int i=0; i<N; i++){
        cin >> A[i];
        mp[A[i]].push_back(i);
    }
    /*
    for(auto x:mp){
        cout << x.first << endl;
        cout_vec(x.second);
    }
    */
    

    vector<int> top(N+2,-1);
    ll period=N+1;
    for(int i=1; i<=N; i++){
        int tmp=-1;
        int tmpA;
        if(top[i]==-1){
            tmpA=A[0];
            tmp=0;
        }else{
            tmpA=A[top[i]];
        }
        while(true){
            auto it = upper_bound(mp[tmpA].begin(), mp[tmpA].end(), tmp);
            if(it==mp[A[tmp]].end()){
                top[i+1]=tmp;
                break;
            }else{
                tmp=(*it)+1;
            }
            //cout << i << ' ' << tmp << endl;
            if(tmp==N){
                break;
            }
            tmpA=A[tmp];
        }
        if(tmp==N){
            period=i;
            break;
        }
    }
    //cout << period << endl;
    //cout_vec(top);

    int H = K%period;
    vector<int> ans(0);
    int tmp = -1;
    int tmpA;
    if(H==0){
        cout << endl;
        return 0;
    }else if(H==1){
        tmp=0;
        tmpA=A[0];
    }else{
        tmpA=A[top[H]];
    }
    while(true){
        auto it = upper_bound(mp[tmpA].begin(), mp[tmpA].end(), tmp);
        if(it==mp[tmpA].end()){
            ans.push_back(tmpA);
            tmp++;
        }else{
            tmp=(*it)+1;
        }
        if(tmp==N)break;
        tmpA=A[tmp];
    }

    cout_vec(ans);
}

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

int main(){ 
    int n,x;
    cin>>n>>x;
    int b=0;
    int c=10000;
    vector<int> a(n);
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    for(int i=0;i<n;i++){
        b+=a[i];
    }
    b=x-b;
    for(int i=0;i<n;i++){
        c=min(c,a[i]);
    }
    cout<<n+b/c;

    return 0;
}


Measured memory_bytes: 256
h,w=map(int,input().split())
s=[input() for _ in range(h)]
 
for i in range(h):
    ans=""
    for j in range(w):
        if(s[i][j]=="#"):
            ans+="#"
        else:
            tmp=0
            for k in s[max(0, i-1):min(h, i+2)]:
                tmp+=k[max(0, j-1):min(w, j+2)].count("#")
                
            ans+=str(tmp)
    print(ans)

Measured memory_bytes: 3064
n, k = map(int, input().split())
a = list(map(int, input().split()))

MOD = 10 ** 9 + 7

fact = [1, 1]  # fact[n] = (n! mod p)
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1]  # factinv 計算用
 
for i in range(2, n + 1):
    fact.append((fact[-1] * i) % MOD)
    inv.append((-inv[MOD % i] * (MOD // i)) % MOD)
    factinv.append((factinv[-1] * inv[-1]) % MOD)

def nCr(n, r, MOD):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % MOD

a.sort()
smin = 0
for i in range(n - k + 1):
    smin = (smin + a[i] * nCr(n-i-1, k-1, MOD)) % MOD

a = a[::-1]
smax = 0
for i in range(n - k + 1):
    smax = (smax + a[i] * nCr(n-i-1, k-1, MOD)) % MOD

print((smax - smin) % MOD)

Measured memory_bytes: 20816
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long n,m,p,q,ans;
    while(cin>>n)
    {
        m = n/11;
        p = n%11;
        if(p!=0)
        {
            if(p>6) q=2;
            else q=1;
        }
        else q=0;
        ans = m*2+q;
        cout<<ans<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,l[45],L[45],a,d[5]={5,7,5,7,7};
string s;
 
int main(){
  while(1){
    cin>>n;
    if(!n)break;
    for(int i=1;i<=n;i++){
      cin>>s,l[i]=s.size();
      L[i]=L[i-1]+l[i];
    }
    a=0;
    for(int i=1;i<=n;i++){
      int x=0,s=i;
      for(int j=i;j<=n;j++){
    if(L[j]-L[s-1]==d[x])x++,s=j+1;
    if(!a&&x==5)a=i,cout<<a<<endl;
      }
    }
  }
  return 0;
}

Measured memory_bytes: 1200
def input_int():
    return map(int, input().split())

def one_int():
    return int(input())

def one_str():
    return input()

def many_int():
    return list(map(int, input().split()))

N,M = input_int()
A = many_int()

sumA=sum(A)
if sumA<=N:
    print(N-sumA)
else:
    print(-1)

Measured memory_bytes: 9984
#include <sstream>
#include <string>
using namespace std;

int main(){
  string s;
  int i,x,r=0;
  for(;cin>>s;){
    stringstream ss;
    for(i=0;i<s.length();i++)
      if(!isdigit(s[i]))s[i]=' ';
    for(ss<<s;ss>>x;r+=x);
  }
  cout<<r<<endl;
}

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

void trace(vector<string> a, int n) {
  int i;
  for (i = 0; i < n; i++) {
    if (i != 0) cout << " ";
    cout << a[i];
  }
  cout << endl;
}

void arcopy(vector<string> in, vector<string> *out, int n) {
  int i;
  string s;
  for (i = 0; i < n; i++){
    s = in[i];
    out->at(i) = s;
  }
}

bool isStable(vector<string> in, vector<string> out, int n) {
  int i, j, a, b;
  for (i = 0; i < n - 1; i++) {
    for (j = i + 1; j < n; j++) {
      for (a = 0; a < n - 1; a++) {
        for (b = a + 1; b < n; b++) {
          if (in[i][1] == in[j][1] && in[i] == out[b] && in[j] == out[a]) {
            return false;
          }
        }
      }
    }
  }
  return true;
}

void bubbleSort(vector<string> *c, int n) {
  int i, j;
  string tmp;
  for (i = 0; i < n; i++) {
    for (j = n - 1; j > i; j--) {
      if (c->at(j)[1] < c->at(j-1)[1]) {
        tmp = c->at(j);
        c->at(j) = c->at(j-1);
        c->at(j-1) = tmp;
      }
    }
  }
}

void selectionSort(vector<string> *c, int n) {
  int i, j, minj;
  string tmp;
  for (i = 0; i < n; i++) {
    minj = i;
    for (j = i; j < n; j++) {
      if (c->at(j)[1] < c->at(minj)[1]) minj = j;
    }
    tmp = c->at(i);
    c->at(i) = c->at(minj);
    c->at(minj) = tmp;
  }
}

int main(void) {
  int i, n;
  string tmp;
  cin >> n;
  vector<string> a(n), bubarr(n), selarr(n);
  for (i = 0; i < n; i++) {
    cin >> tmp;
    a.at(i) = tmp;
  }
  arcopy(a, &bubarr, n);
  arcopy(a, &selarr, n);
  bubbleSort(&bubarr, n);
  trace(bubarr, n);
  if (isStable(a, bubarr, n)) cout << "Stable" << endl;
  else cout << "Not stable" << endl;
  selectionSort(&selarr, n);
  trace(selarr, n);
  if (isStable(a, selarr, n)) cout << "Stable" << endl;
  else cout << "Not stable" << endl;
  return 0;
}

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

int main(){
    #define rep(i,n) for (int i=0;i < (int)(n);i++)

    int N;
    cin >> N;

    vector<int> a(N);
    rep(i,N){
        cin >> a.at(i);
    }

    sort(a.begin(),a.end());
    reverse(a.begin(),a.end());

    int AP=0;
    int BP=0;

    rep(i,N){
        if(i%2==0){
            AP += a.at(i);
        }
        else{
            BP += a.at(i);
        }
    }

    cout << AP - BP;
    cout << endl;
    

}

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

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

  ll N; cin >> N;
  ll K; cin >> K;
  vector<ll> L(K), R(K);
  for (ll i = 0; i < K; i++) {
    ll l, r;
    cin >> l >> r;
    L[i] = l;
    R[i] = r + 1;
  }

  ll MOD = 998244353;
  vector<ll> ans(2 * N + 5, 0);
  vector<ll> hosei(2 * N + 5, 0);
  vector<ll> A(2 * N + 5, 0);

  ll ruikei = 0;
  ans[1] = 1;
  for (ll i = 1; i <= N; i++) {
    for (ll j = 0; j < K; j++) {
      if (i + L[j] <= N) {
        hosei[i + L[j]] += ans[i];
        hosei[i + L[j]] %= MOD;
      }
      if (i + R[j] <= N) {
        hosei[i + R[j]] += MOD - ans[i];
        hosei[i + R[j]] %= MOD;
      }
    }
    ruikei = (ruikei + hosei[i]) % MOD;
    ans[i + 1] = (ruikei + hosei[i + 1]) % MOD;
  }

  cout << ans[N] << '\n';
  return 0;
}

Measured memory_bytes: 12696
#include <stdio.h>
int main() {
    int W, H, x, y, r;
    scanf("%d%d%d%d%d", &W, &H, &x, &y, &r);
    
    if (x + r <= W && x - r >= 0) {
        
        if (y + r <= H && y - r >= 0) {
            printf("Yes\n");
        }
        
        else printf("No\n");
    }
    
    else printf("No\n");
    
    return 0;
}


Measured memory_bytes: 2148
#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(false), cin.tie(0)
#define debug(a) cout << #a ": " << a << endl
using namespace std;
typedef long long ll;

int main(void){
    IOS;
    int n; cin >> n;
    while (n){
        if (n%10 == 7){
            cout << "Yes" << endl; return 0;
        }
        n /= 10;
    }
    cout << "No" << endl;
    return 0;
}

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

int main(){
	int a, b, c, m;
	cin>> a >> b >> c;
	
	if(a > b){
		m = b;
		b = a;
		a = m;
	}
	
	if(b > c){
		m = c;
		c = b;
		b = m;
	}
	if(a > b){
		m = b;
		b = a;
		a = m;
	}
	
	cout << a << " " << b << " " << c << endl;
	
	return 0;
}


Measured memory_bytes: 3108
#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define fi first
#define se second

const int N = 3e5 + 7;

int n, a[N];

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0);
	cin >> n;
	for(int i = 1; i <= 3 * n; i++){
		cin >> a[i];
	}
	sort(a + 1, a + 1 + 3 * n);
	long long ans = 0;
	for(int i = 1; i <= n; i++){
		ans += a[3 * n - 1 - (i - 1) * 2];
	}
	cout << ans;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define SORT(a) sort(a.begin(), a.end())
#define REVERSE(a) reverse(a.begin(), a.end())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define ll long long
#define INF 1000000000000000000
using namespace std;

typedef vector<int> vec;
typedef vector<vec> mat;
typedef pair<int, int> Pii;

template<typename T>
void readvec(vector<T> &a);
void readindex(vector<int> &a);

int fastpow(int x, int n, int m){
    ll a = 1;
    IREP(i, 32){
        a = (a * a) % m;
        if(((n >> i) & 1) == 1) a = (a * x) % m;
    }
    return (int)a;
}

signed main(){

    int N; cin >> N;
    string s; cin >> s;
    int mod = 1000000007;

    //n回後に空文字となる場合の数 0,1区別
    mat dp(N + 1, vec(N + 2, 0));
    dp[0][0] = 1;
    FOR(n, 1, N + 1){
        ll tmp = ((ll)dp[n - 1][0] + (ll)dp[n - 1][1]) % mod;
        dp[n][0] = (int)tmp;
        FOR(k, 1, n + 1){
            ll tmp = (2 * (ll)dp[n - 1][k - 1] + (ll)dp[n - 1][k + 1]) % mod;
            dp[n][k] = (int)tmp;
        }
    }

    //0から1へ　1から|S|へ
    mat dp2(N + 1, vec(N + 2, 0));
    dp2[1][1] = 1;
    FOR(n, 2, N + 1){
        FOR(k, 1, n + 1){
            ll tmp = ((ll)dp2[n - 1][k - 1] + (ll)dp2[n - 1][k + 1]) % mod;
            dp2[n][k] = (int)tmp;
        }
    }

    ll ans = 0;
    int n = s.size();
    REP(i, N + 1){
        if(N - i - n < 0 || (N - i - n) % 2 != 0) continue;
        int del = (N - i - n) / 2;
        //cout << dp[i][0] << "," << dp2[N - i][n] << endl;
        ans += (ll)dp[i][0] * (((ll)dp2[N - i][n] * (ll)fastpow(2, del, mod)) % mod);
        ans %= mod;
    }
    cout << ans;
    
    return 0;
}


template<typename T>
void readvec(vector<T> &a){
    REP(i, a.size()){
        cin >> a[i];
    }
}
void readindex(vector<int> &a){
    REP(i, a.size()){
        cin >> a[i];
        a[i]--;
    }
}

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

int main() {
	int n;
	while (scanf("%d", &n), ~n) {
		double x = 1, y = 0;
		rep(i, n - 1) {
			double X = ((x - y) - (x + y)) / 2, Y = ((x - y) + (x + y)) / 2;
			double d = sqrt(i + 1);
			x += X / d; y += Y / d;
		}
		printf("%.7lf\n%.7lf\n", x, y);
	}
}

Measured memory_bytes: 3208
/*
------------------------------------------------------
 
    Dilon Mein Tum Apni Betaabiyan Leke Chal Rahe Ho,
    Toh Zinda Ho Tum.
       
    Nazar Mein Khwabon Ki Bijliyan Leke Chal Rahe Ho,
    Toh Zinda Ho Tum.
	
    Hawa Ke Jhokon Ke Jaise Aazad Rehno Sikho,
    Tum Ek Dariya Ke Jaise Lehron Mein Behna Sikho,
    Har Ek lamhe Se Tum Milo Khole Apni Bhaayein,
    Har Ek Pal Ek Naya Samha Dekhen Yeh Nigahaein,
    
    Jo Apni Aankhon Mein Hairaniyan Leke Chal Rahe Ho,
    Toh Zinda Ho Tum.
    
    Dilon Mein Tum Apni Betaabiyan Leke Chal Rahe Ho,
    Toh Zinda Ho Tum.   
 
    - Imran ( Zindagi Na Milegi Dobara )
 
-------------------------------------------------------	                                                                                                
 
	Author :- Gaurang_Kothiya
	Nirma University
 
*/ 
 
 
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>  
#include <ext/pb_ds/tree_policy.hpp> 
#include <functional>
#include <bitset>
#include <cstdint>
#include <initializer_list>
 
using namespace std;
using namespace __gnu_pbds;  
 
typedef tree<int, null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update> data_set; 
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long int
#define ld long double
#define f(i,x,n) for(auto i=x;i<=n;i++)
#define fe(x,v)   for(auto &x :v)
#define nf(i,x,n) for(auto i=n;i>=x;i--)
#define all(a)   a.begin(),a.end()
#define rall(a)  a.rbegin(),a.rend()
#define b_s(a,b)   binary_search( all(a),b)
#define lb(v,n)  lower_bound(all(v) ,n )
#define ub(v,n)  upper_bound( all(v) , n)
#define gcd(a,b) __gcd(a,b)
#define pub push_back
#define pob pop_back
#define puf push_front
#define pof pop_front
#define RE rend()
#define RB rbegin()
#define B begin()
#define E end()
#define acc(v, x) accumulate(all(v), x)
#define p(a,b) pair<a,b>
#define F first
#define S second
#define sz size()
#define v(x) vector<x>
#define m(a,b) map<a,b>
#define u_m(a,b) unordered_map<a,b>
#define mm(a,b) multimap<a,b>
#define s(a) set<a>
#define us(a) unordered_set<a>
#define ms(a) multiset<a>
#define maxy __LONG_LONG_MAX__
#define miny INT_MIN
#define PI 3.14159265358979323846
#define MOD 1000000007
 
 
 

void Solve()
{	
	ll n;
	cin>>n;
	ll tr=sqrt(n);
	v(ll) vr;
	
	f(i,2,tr)
	{
		if(n%i ==0)
		{
			while(n%i ==0)
			{
				vr.pub(i);
				n/=i;
			}
		}
	}
	if(n!=1) vr.pub(n);
	
	m(ll,ll) mp;
	fe(x,vr) mp[x]++;
	
	ll ans=0;
	
	fe(x,mp)
	{
		int tx= x.S;
		int id=1;
		while(tx>0)
		{
			if(tx>=id)
			{
				tx -=id;
				ans++;
				id++;
			}
			else break;
		}
	}
	if(ans==0)
	{
		if(tr==1)cout<<0;
		else cout<<1;
	}
	else cout<<ans;
}
 
 
 
 
signed main() 
{
	speed	
	
	int q=1;
	//cin>>q;
	
	while(q--)
	Solve();
	
	//cout << "\n\n"<<"Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " seconds.\n";
	return 0;
} 

Measured memory_bytes: 3640
//@author yash2040
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define ll long long
#define int long long
#define pb push_back
#define mod 1000000007
#define fast() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
main()
{
	fast();
	int t=1;
//	cin>>t;
	while(t--)
	{
		int n;
		cin>>n;
		int arr[n];
		for(int i=0;i<n;i++)
		cin>>arr[i];
		int ans=0;
		sort(arr,arr+n,greater<int>());
		ans+=arr[0];
		int prev=arr[1];
		int cnt=0;
		queue<int> q;
		q.push(prev);
		for(int i=2;i<n;i++)
		{
			int x=q.front();
			int prev1=arr[i];
			q.pop();
			ans+=x;
			i++;
			if(i==n)
			break;
			int prev2=arr[i];
			ans+=x;
			q.push(prev1);
			q.push(prev2);
			
		}
		cout<<ans<<endl;
	}
	
}




Measured memory_bytes: 5604
N=int(input())
A=list(map(int,input().split()))
m=int(input())
q=list(map(int,input().split()))
num_list=set()
for i in range(2**N):
    ans=0
    for j in range(N):
        if i>>j&1:
            ans+=A[j]
    num_list.add(ans)
for i in q:
    if i in num_list:
        print("yes")
    else:print("no")



Measured memory_bytes: 5644
#include <bits/stdc++.h>
#define ll long long
#define V vector<long long>
#define VV vector<vector<long long>>
#define VVV vector<vector<vector<long long>>>
#define rep(i,n) for(ll (i)=0;(i)<(n);++(i))
using namespace std;

int main() {
    ll n;
    cin>>n;
    cout<<fixed<<setprecision(10);
    vector<double> p(n);
    rep(i,n)cin>>p[i];
    vector<vector<double>> dp(n+1,vector<double>(n+1,0));
    dp[0][0]=1;
    rep(i,n){
        rep(j,i+2){
            if(j)dp[i+1][j]+=dp[i][j-1]*p[i];
            dp[i+1][j]+=dp[i][j]*(1-p[i]);
        }
    }
    double ans=0;
    for(ll i=(n+1)/2;i<=n;i++)ans+=dp[n][i];
    cout<<ans<<endl;
}


Measured memory_bytes: 70784
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>
#include <set>
#include <functional>
#include <iomanip>

using namespace std;

#define DEBUG_ //!!$BDs=P;~$K%3%a%s%H%"%&%H(B!!
#ifdef DEBUG_
#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
#define dump(x)  ;
#endif

#define equals(a,b) (fabs((a)-(b)) < EPS)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back

//#define int long long

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

    template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

template <typename T>
void print_array(const T &ary, int size){
    REP(i,size){
        cout << ary[i] << " ";
    }
    cout << endl;
}

const int mod = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;
const double EPS = (1e-10);
const long double PI = 3.14159265358979323846264338327950288419716939937510582097494459230781640628620899;
int dx[] = {0,0,-1,1};
int dy[] = {-1,1,0,0};


int main(){
    int n;
    cin >> n;
    vector<int> a_list(n);
    vector<int> kaburi(1e6+10),seen(1e6+10);
    for (int i = 0; i < n; i++ ) {
        cin >> a_list.at(i);
        kaburi.at(a_list.at(i))++;
    }
    sort(a_list.begin(),a_list.end());
    bool dp[int(1e6+10)] = {};
    for (int i = 0; i < int(1e6+10); i++) {
        dp[i] = 1;
    }
 
    
    int ans = 0;
    for (int i = 0; i < n; i++) {
        if (kaburi.at(a_list.at(i)) >= 2) {
            if (seen.at(a_list.at(i)) == 1) continue;
            else {
                seen.at(a_list.at(i)) = 1;
            }
        }
        else {
            if (dp[a_list.at(i)] == 1){
                ans++;
 
            }
                
        } 
        for (int j = a_list.at(i); j < int(1e6+10); j += a_list.at(i)) {
            dp[j] = 0;   
 
        }
         
        
    }
cout << ans << endl;
}

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

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

int ggcd(int a, int b, int c){
  int cc = gcd(a, b);
  return gcd(c, cc);
}

int main(){
  int kk;
  cin >> kk;

  ll sum=0;
  rep(i,kk)rep(j,kk)rep(k,kk) sum+=ggcd(i+1,j+1,k+1);
  
  cout << sum << endl;
  return 0;
}

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

int main(){
    int n=0;
    cin >> n;
    int l=0;
    cin >> l;
    string arr[n]={};
    for(int i=0;i<n;i++){
    	cin >> arr[i];
    }
    sort(arr,arr+n);
    string ans;
    for(int i=0;i<n;i++){
    	ans+=arr[i];
    }
    cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3608
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
using ll = long long;
using u64 = uint_fast64_t;
using pii = pair<int, int>;
using pll = pair<long long, long long>;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007;
//constexpr long long MOD = 998244353;
template<class T1, class T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return true;} return false; }
template<class T1, class T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return true;} return false; }
inline int popcount(int x) {return __builtin_popcount(x);}
inline int popcount(long long x) {return __builtin_popcountll(x);}
void print() { cout << "\n"; }
template<class T, class... Args>
void print(const T &x, const Args &... args) {
    cout << x << " ";
    print(args...);
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////

struct color {
    int b1,w1,b2,w2;
    color(){};
    color(int b1, int w1, int b2, int w2) : b1(b1), w1(w1), b2(b2), w2(w2) {}
};

const int MAX = 5000;
int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int N; cin >> N;
    vector<vector<int>> G(N);
    rep(i,N-1) {
        int p; cin >> p;
        --p;
        G[p].emplace_back(i+1);
    }
    vector<int> X(N);
    rep(i,N) cin >> X[i];

    auto dfs=[&](auto&& self, int v)->color {
        vector<vector<int>> dp(2, vector<int>(MAX+2,1e9));
        dp[0][0] = 0;
        int cur = 0, nex = 1;
        for (auto nv : G[v]) {
            fill(all(dp[nex]),1e9);
            color c = self(self,nv);
            for (int i = 0; i <= MAX+1; i++) {
                if (dp[cur][i]==1e9) continue;
                if (c.b1 != 1e9 and c.w1 != 1e9) {
                    chmin(dp[nex][min(i+c.b1,MAX+1)],min(dp[cur][i]+c.w1,MAX+1));
                }
                if (c.b2 != 1e9 and c.w2 != 1e9) {
                    chmin(dp[nex][min(i+c.b2,MAX+1)],min(dp[cur][i]+c.w2,MAX+1));
                }
            }
            swap(cur,nex);
        }
        color ret = color(1e9,1e9,1e9,1e9);
        int wval = *min_element(dp[cur].begin(),dp[cur].begin()+X[v]+1);
        if (wval != 1e9) {
            ret.b1 = X[v];
            ret.w1 = wval;
        }
        for (int i = 0; i <= MAX+1; i++) {
            if (dp[cur][i] <= X[v]) {
                ret.b2 = i;
                ret.w2 = X[v];
                break;
            }
        }
        return ret;
    };

    color ans = dfs(dfs,0);
    if ((ans.b1 != 1e9 and ans.w1 != 1e9) or (ans.b2 != 1e9 and ans.w2 != 1e9)) {
        cout << "POSSIBLE" << ln;
    } else cout << "IMPOSSIBLE" << ln;
}

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

int main() {
    int N;
    string S;
    cin>>N;
    for(int i=0;i<N;i++){
        cin>>S;
        if(S=="Y"){
            cout<<"Four"<<endl;
            break;
        }
    if(i==N-1)cout<<"Three"<<endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define endl '\n'
#define PI acos(-1)
#define sz 100010
#define RUN_FAST ios::sync_with_stdio(false);
using namespace std;

int main()
{
    RUN_FAST; cin.tie(nullptr);
    string s1, s2, s3;
    int a, b;
    cin >> s1 >> s2 >> a >> b >> s3;
    if (s3==s1) a--;
    else b--;
    cout << a << ' ' << b << endl;
    return 0;
}


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



int main(){
  
  int A,B,C;
  cin>>A>>B>>C;
  
  bool can=false;
  for(int i=1;i<=100;i++){
    if(i*A%B==C) can=true;
  }
  
  if(can) cout<<"YES"<<endl;
  else cout<<"NO"<<endl;

}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<vector>
#define maxn 20005
#define mod 1000000007
using namespace std;
long long n, k;
long long f[maxn];

long long pow(long long x, long long k) {
	if(k < 0) return 1;
	long long res = 1ll;
	while(k) {
		if(k & 1) res = (long long)(res * x) % mod;
		x = (long long)(x * x) % mod;
		k >>= 1;
	}
	return res;
}

int main() {
	f[0] = 1ll;
	scanf("%lld%lld", &n, &k);
	for(int i = 1; i < n; i ++) {
		for(int j = i; j; j --)
			f[j] = (long long)(f[j + 1] + f[j - 1]) % mod;
		f[0] = f[1];
	}
	printf("%lld\n", (long long)f[n - k] * pow(2ll, n - k - 1) % mod);
}

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

using namespace std;

const int N = int(2e5) + 5;
const int MOD = int(1e9) + 7;
const int inf = int(2e9);

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

    string s,d,c;
    int q;
    cin >> s >> q;
    int r = 0;
    while (q--) {
        int t;
        cin >> t;
        if (t == 1) r = abs(r-1);
        else {
            int f;
            char cc;
            cin >> f >> cc;
            int h = f == 1;
            if (r) h = abs(h-1);
            if (h) d = cc + d;
            else c = c + cc;
        }
    }
    if (r) {
        reverse(s.begin(),s.end());
        reverse(d.begin(),d.end());
        reverse(c.begin(),c.end());
        s = c + s + d;
    }
    else s = d + s + c;
    cout << s;
    return 0;
}


Measured memory_bytes: 1320
#include<stdio.h>
 
int D[107][7],i,j,N;
int G[55][6]={
    {1,2,3},{1,3,5},{1,5,4},{1,4,2},
    {2,1,4},{2,4,6},{2,6,3},{2,3,1},
    {3,1,2},{3,2,6},{3,6,5},{3,5,1},
    {4,1,5},{4,2,1},{4,6,2},{4,5,6},
    {5,1,3},{5,3,6},{5,4,1},{5,6,4},
    {6,2,4},{6,4,5},{6,5,3},{6,3,2}};
 
int ch(int a,int b)
{
    int i;
    for(i=0;i<24;i++)
    {
        if(D[a][1]==D[b][G[i][0]]&&
           D[a][2]==D[b][G[i][1]]&&
           D[a][3]==D[b][G[i][2]]&&
           D[a][6]==D[b][7-G[i][0]]&&
           D[a][5]==D[b][7-G[i][1]]&&
           D[a][4]==D[b][7-G[i][2]])
        return 1;
    }
    return 0;
}
 
int main()
{
    scanf("%d",&N);
    for(i=0;i<N;i++)
        for(j=1;j<=6;j++)
            scanf("%d",&D[i][j]);
    for(i=0;i<N;i++)
        for(j=i+1;j<N;j++)
        {
            if(ch(i,j))
            {
                puts("No");
                return 0;
            }
        }
    puts("Yes");
    return 0;
}


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

int main(){
  int N,m,count;
  count = 0;
  m = 0;
  cin >> N;
  vector<int> H(N);
  for(int i=0;i<N;i++){
    cin >> H.at(i);
    }
  for(int i=0;i<N;i++){
    if(m<=H.at(i)){
      count++;
    m = H.at(i);
    }
  }
  cout << count << endl;
}


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

using namespace std;

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


    int l, bounce = 1, sum = 0;
    for(int i=0; i<n; i++)
    {
        cin>>l;
        sum+=l;
        if(sum<=x)  bounce++;
        else break;
    }

    cout<<bounce;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
    int a,b,c,d,e,f,g,h,i;
    cin>>a>>b>>c;
    d=((10*a)+b)+c;
    e=((10*b)+c)+a;
    f=((10*c)+a)+b;
    g=((10*a)+c)+b;
    h=((10*b)+a)+c;
    i=((10*c)+b)+a;
    cout<<max({d,e,f,g,h,i})<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define pb push_back
#define x first
#define y second
#define pii pair<int, int>
#define p3i pair<pii, int>
#define pll pair<ll, ll>
#define p3l pair<pll, ll>
#define vi vector<int>
#define vpii vector<pii>
#define vp3i vector<p3i>
#define vpll vector<pll>
#define vp3l vector<p3l>
#define lseg L, (L+R)/2, N*2+1
#define rseg (L+R)/2+1, R, N*2+2
#define ub upper_bound
#define lb lower_bound
#define pq priority_queue
#define MN 1000000007
#define fox(k, x) for (int k=0; k<x; ++k)
#define fox1(k, x) for (int k=1; k<=x; ++k)
#define foxr(k, x) for (int k=x-1; k>=0; --k)
#define fox1r(k, x) for (int k=x; k>0; --k)
#define ms multiset
#define flood(x) memset(x, 0x3f3f3f3f, sizeof x)
#define drain(x) memset(x, 0, sizeof x)
#define rng() ((rand() << 14)+rand())
#define scan(X) do{while((X=getchar())<'0'); for(X-='0'; '0'<=(_=getchar()); X=(X<<3)+(X<<1)+_-'0');}while(0)
char _;
#define pi 3.14159265358979323846

int a[3], c;
int main(){
    cin >> a[0] >> a[1] >> a[2];
    sort(a, a+3);
    c+=a[2]-a[1];
    a[0]+=a[2]-a[1];
    if (a[0]%2!=a[2]%2){
        c++;
        a[2]++;
    }
    c+=(a[2]-a[0])/2;
    cout << c;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int a, b;
char op[2];

int operate(int a, char op, int b) {
    switch (op) {
    case '+': return a + b;
    case '-': return a - b;
    case '*': return a * b;
    case '/': return a / b;
    }
}

int main(void) {
    while (1) {
        scanf("%d%s%d", &a, op, &b);
        if (op[0] == '?') break;
        printf("%d\n", operate(a, op[0], b));
    }
    
    return 0;
}

Measured memory_bytes: 600
N = int(input())
a = [int(input()) for i in range(N)]
visited = [0]*N
now = 1
visited[0] = 1
flag = -1
for i in range(N):
    if visited[a[now-1]-1]:
        flag = -1
        break
    now = a[now-1]
    if now==2:
        flag = i+1
        break
print(flag)

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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long a, b, n;
  cin >> a >> b >> n;
  long long x = min(b - 1, n);
  cout << (a * x) / b - a * (x / b) << '\n';
  return 0;
}

Measured memory_bytes: 3552
import java.util.Scanner;
class Main {
    public static void main(String args[]) {
      Scanner sc = new Scanner(System.in);
      int d = sc.nextInt();
      int t = sc.nextInt();
      int s = sc.nextInt();
      
      if((double)d / s <= t){
        System.out.println("Yes");
      } else {
        System.out.println("No");   
      }
    }
}

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

int main() {
	int n;
	cin >> n;
	int x[n], y[n];
	for (int i = 0; i < n; i++) {
		cin >> x[i] >> y[i];
	}
	for (int i = 0; i < n; i++) {
		double l1 = 0, r1 = PI, l2 = - PI, r2 = 0;
		for (int j = 0; j < n; j++) {
			if (i != j) {
				double th = atan2(y[j] - y[i], x[j] - x[i]);
				//cout << th << " ";
				if (th < -0.5 * PI && x[i] != x[j]) {
					l2 = max(l2, th + PI * 0.5);
					r1 = min(r1, th + PI * 1.5);
				} else if (th < 0.5 * PI || x[i] == x[j]) {
					l1 = max(l1, th + PI * 0.5);
					r2 = min(r2, th - PI * 0.5);
				} else {
					l2 = max(l2, th - PI * 1.5);
					r1 = min(r1, th - PI * 0.5);
				}
				//cout << l1 << " " << r1 << " " << l2 << " " << r2 << endl;
			}
		}
		printf("%.10lf\n", max(0., (r1 - l1) / 2 / PI) + max(0., (r2 - l2) / 2 / PI));
	}
    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <bits/stdc++.h>
#include <string>
#include <ctype.h>
#include <algorithm>
#include <cmath>
#include <vector>

#define REP(i, n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(),(x).end()
#define square(x) (x) * (x)

const int INF = 1e9;

using namespace std;

int main() {
    string str;
    getline(cin, str);

    REP(i, str.size()){
        if(0x40 < str[i]  && str[i] < 0x5B)
            str[i] += 0x20;
        else if(0x60 < str[i] && str[i] < 0x7B)
            str[i] -= 0x20;
    }

    cout << str << endl;
    return 0;
}

Measured memory_bytes: 1184
#include <bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define lli long long int
#define tc int t;cin>>t;while(t--)
#define all(x) x.begin(),x.end()
#define f first
#define s second
#define pb push_back
#define vi vector<int>
#define vll vector<lli>
#define vpi vector<pair<int,int> > 
#define vpll vector<pair<lli,lli> > 
#define vvi vector<vector<int> >
#define vvll vector<vector<lli> >
#define maxn 100005
#define inf 1000000000
lli mod=1000000007;


int main(){
    fastio;
    int n,x,t;
    cin>>n>>x>>t;
    int mul=n/x;
    if(n%x) mul++;
    cout<<mul*t<<"\n";
    return 0;
}


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

int main() {
  int n, l;
  cin >> n >> l;
  if (l*(l+n-1) <= 0){
    cout << (2*l+n-1)*n/2 << endl;
    //cout << 1 <<endl;
  }
  else if ( l*l < (l+n-1)*(l+n-1)){
    cout << (2*l+n-1)*n/2-l << endl;
    //cout << 2 <<endl;
  }
  else {
    cout << (2*l+n-1)*n/2-(l+n-1) << endl;
    //cout << 3 <<endl;
  }
}


Measured memory_bytes: 256