akhauriyash/Code-Regression huggingface dataset:
# include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn = 1e5+30;
int n, id=0, cnt=0, Next[maxn], in[maxn], out[maxn], son[maxn]={0}, zhong[maxn];
int msize = 0x3f3f3f3f, mid;
LL ans = 0;
struct node{int e, w, next;}edge[maxn<<1];
void add_edge(int u, int v, int w)
{
    edge[cnt] = {v, w, Next[u]};
    Next[u] = cnt++;
    edge[cnt] = {u, w, Next[v]};
    Next[v] = cnt++;
}
void dfs(int cur, int pre, int w)
{
    in[cur] = ++id;
    int imax = 0;
    for(int i=Next[cur]; i!=-1; i=edge[i].next)
    {
        int v = edge[i].e;
        if(v == pre) continue;
        dfs(v, cur, edge[i].w);
        son[cur] += son[v] + 1;
        imax = max(imax, son[v]+1);
    }
    out[cur] = id;
    int imin = min(out[cur]-in[cur]+1, n-out[cur]+in[cur]-1);
    ans = ans + (LL)imin*w*2;
    imax = max(imax, n-1-son[cur]);
    zhong[cur] = imax;
    if(imax < msize)
    {
        msize = imax;
        mid = cur;
    }
}
int main()
{
    memset(Next, -1, sizeof(Next));
    int a, b, c;
    scanf("%d",&n);
    for(int i=1; i<n; ++i)
    {
        scanf("%d%d%d",&a,&b,&c);
        add_edge(a, b, c);
    }
    dfs(1, 0, 0);
    int com = 0x3f3f3f3f;
    for(int i=Next[mid]; i!=-1; i=edge[i].next)
    {
        int v = edge[i].e;
        com = min(com, edge[i].w);
        if(zhong[v] == zhong[mid])
        {
            ans -= edge[i].w;
            return 0*printf("%lld\n",ans);
        }
    }
    printf("%lld\n",ans-com);
    return 0;
}


Measured memory_bytes: 11264
#include "bits/stdc++.h"

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
const ll INF = numeric_limits<ll>::max()/2;

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

    int N,C;cin>>N>>C;
    vector<vector<int>> d(C,vector<int>(C)),c(N,vector<int>(N)),cnt(3,vector<int>(C,0));
    for(int i=0;i<C;i++){
        for(int j=0;j<C;j++){
            cin>>d[i][j];
        }
    }
    for(int i=0;i<N;i++){
        for(int j=0;j<N;j++){
            cin>>c[i][j]; c[i][j]--;
            cnt[(i+j)%3][c[i][j]]++;
        }
    }
    ll res=INF;
    for(int c1=0;c1<C;c1++){
        for(int c2=0;c2<C;c2++){
            if(c1==c2) continue;
            for(int c3=0;c3<C;c3++){
                if(c1==c3 || c2==c3) continue;
                ll tmp=0;
                for(int i=0;i<C;i++){
                    tmp += cnt[0][i]*d[i][c1];
                }
                for(int i=0;i<C;i++){
                    tmp += cnt[1][i]*d[i][c2];
                }
                for(int i=0;i<C;i++){
                    tmp += cnt[2][i]*d[i][c3];
                }
                res=min(res,tmp);
            }
        }
    }
    cout<<res<<endl;

}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string s;
  cin >> s;
  vector<int>v(4);
  for(int i = 0; i < 4; i++)v[i] = s[i] - '0';
  int wa;
  for(int i=0; i<(1 << 3); i++){
    wa=v[0];
  	for(int k=0; k<3; k++){
      if(i & 1<<k){wa+=v[k+1];}
      else {wa-=v[k+1];}
    }
    if(wa==7){
      cout << v[0];
      for(int m=0; m<3;m++){
        if(i & 1<<m){cout << '+';}
        else {cout << '-';}
        cout << v[m+1];
      }
      cout << "=7" << endl;
      break;
    }
  }
}

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


using namespace std;



int gcd2(int a,int b){
    int buff;
    if(b>a){
        buff=a;
        a=b;
        b=buff;
    }
    if(a%b==0) return b;
    else return gcd2(b,a%b);
}

int gcd(int a,int b,int c){
    int buff;
    if(b>a){
        buff=a;
        a=b;
        b=buff;
    }
    if(c>b){
        buff=b;
        b=c;
        c=buff;
    }
     if(b>a){
        buff=a;
        a=b;
        b=buff;
    }
    a=a%c;
    b=b%c;
    if(a==0 && b==0) return c;
    else if(a==0) return gcd2(c,b);
    else if(b==0) return gcd2(c,a);
    else return gcd(a,b,c);
}


int main(){
    int K,sum=0,add;
    cin >> K;
    for (int i=1;i<K+1;i++){
        for(int j=i;j<K+1;j++){
            for(int k=j;k<K+1;k++){
                if(i==j && j==k) add=gcd(i,j,k);
                else if (i==j || j==k || i==k) add=gcd(i,j,k)*3;
                else add=gcd(i,j,k)*6;
                sum=sum+add;
            }
        }
    }
    cout << sum <<endl;
    return 0;
}


Measured memory_bytes: 3632
using System;
using System.Text;
using System.Collections.Generic;
using System.Collections;
using static System.Math;
using System.Linq;
using static System.Array;

namespace ConsoleApp2
{
    class Program
    {
        static void Main(string[] args)
        {
            var S = Console.ReadLine();
            var dic = new Dictionary<char, int>();
            for (int i = 0; i < 4; i++)
            {
                if (dic.ContainsKey(S[i]))
                {
                    dic[S[i]]++;
                }
                else
                {
                    dic.Add(S[i], 1);
                }
            }

            if (dic.Count() == 2 && dic.Values.Max() == 2)
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
            
            
        }
    }

}


Measured memory_bytes: 13268
package main

import "fmt"

func main() {
	var input string
	fmt.Scanf("%s", &input)
	maxlen := 0
	for i := 0; i < len(input); i++ {
		sublen := 0
		for j := i; j < len(input); j++ {
			if input[j] == 'A' || input[j] == 'T' || input[j] == 'G' || input[j] == 'C' {
				sublen++
			} else {
					break
			}
		}
		if sublen > maxlen {
			maxlen = sublen
		}
	}
	fmt.Println(maxlen)
}

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

#define ll int64_t
#define Rep(i, n) for (ll i = 0; i < n; i++)

using namespace std;

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

    string S;
    cin >> S;

    if (S.size() == 3) {
        reverse(S.begin(), S.end());
    }

    cout << S << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main() {
  int N, K;
  scanf("%d %d", &N, &K);

  char S[N + 1];
  scanf("%s", S);

  for(int i = 0; i < N; i++) {
    if(i == K - 1) {
      printf("%c", S[i] + 'a' - 'A');
    }
    else {
      printf("%c", S[i]);
    }
  }
  return 0;
}

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

using namespace std;


int main(){
	int n, m;
	int in;
	int a[1000];
	cin >> n >> m;
	fill_n(a, 1000, n);
	int ans = 0;
	for(int i = 0; i < m; i++){
		cin >> in;
		a[i] -= in;
		ans += max(0, a[i]);
		cin >> in;
	}
	sort(a, a+m);
	cout << ans - a[m-1] << endl;
	return 0;
}


Measured memory_bytes: 3132
#include <iostream>
#include <set>

using namespace std;

int main() {
    long long n;
    cin >> n;

    set<long long> s;
    for (long long i = 2; i * i <= n - 1; i++) {
        if ((n - 1) % i == 0) {
            s.insert(i);
            s.insert((n - 1) / i);
        }
    }

    for (long long i = 2; i * i <= n; i++) {
        if (n % i == 0) {
            long long j = n;
            while (j % i == 0) {
                j /= i;
            }
            if (j % i == 1) {
                s.insert(i);
            }

            long long k = n;
            while (k % (n / i) == 0) {
                k /= (n / i);
            }
            if (k % (n / i) == 1) {
                s.insert(n / i);
            }
        }
    }

    if (n > 2) {
        s.insert(n - 1);
    }

    s.insert(n);

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 2000000000
using namespace std;
typedef long long ll;
int read(){
    int f = 1, x = 0;
    char c = getchar();
    while(c < '0' || c > '9'){if(c == '-') f = -f; c = getchar();}
    while(c >= '0' && c <= '9')x = x * 10 + c - '0', c = getchar();
    return f * x; 
}
int n, r;
void init(){
    n = read(), r = read();
}
void solve(){
    int cnt = 0;
    while (n > 0)
        n /= r, ++cnt;
    printf("%d\n", cnt);
}
int main(){
    init();
    solve();
    return 0;
}

Measured memory_bytes: 256
[<AutoOpen>]
module Program

open System

let read f = stdin.ReadLine() |> f
let reada f = stdin.ReadLine().Split() |> Array.map f
let reads f = stdin.ReadLine().Split() |> Array.toList |> List.map f

[<EntryPoint>]
let main _ =
    let N = read int
    let S = (read string).ToCharArray()

    if N % 2 <> 0 then
        printfn "No"
    else
        let n = N / 2
        let a, b = Array.splitAt n S
        if a = b then
            printfn "Yes"
        else
            printfn "No"
    0

Measured memory_bytes: 18236
from collections import deque

n, q = map(int, input().split())
pro = [list(map(str, input().split())) for i in range(n)]

for i in range(n):
    pro[i][1] = int(pro[i][1])

que = deque(pro)
done = False
time = 0

order = []

while not done:
    if len(que) == 0:
        done = True
        break
    now = que.popleft()
    t = now[1]
    name = now[0]
    if 0 < t <= q:
        time += t
        order.append(name + ' ' + str(time))
    if t > q:
        time += q
        t -= q
        que.append([name] + [t])

for i in order:
    print(i)







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

#define ll long long int
#define inv(name,Type,size) vector<Type> name(size);for(int index=0;index<n;index++) cin>>name[index];
#define F(a,n,i) for(int i=a;i<n;i++)
#define pb push_back
#define endl "\n"
#define mod 10000000007
#define modpro 99824435

const int d4i[4]={-1,0,1,0},d4j[4]={0,1,0,-1};
const int d8i[8]={-1,-1,0,1,1,1,0,-1},d8j[8]={0,1,1,1,0,-1,-1,-1};


void solve(){
	int n;
	cin>>n;
	inv(v,int,n);
	vector<int> dp(n);
	F(0,n,i) dp[i] = INT_MAX;
	dp[0] = 0;
	dp[1] = abs(v[0]-v[1]);
	F(2,n,i){
		dp[i] = min(dp[i-2]+abs(v[i-2]-v[i]),dp[i-1]+abs(v[i-1]-v[i]));
	}
	cout<<dp[n-1];
}

int main()
{
  ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  
  //int t;cin>>t;while(t--) solve(),cout<<endl;
  solve();
}



Measured memory_bytes: 3988
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
  double a1,a2;
  cin>>a1>>a2;
  if(a1>a2) swap(a1,a2);
  if(a1+360.0-a2<a2-a1){
    if(a1-(a1+360.0-a2)/2>0)
      printf("%.12f\n",a1-(a1+360.0-a2)/2);
    else
      printf("%.12f\n",a2+(a1+360.0-a2)/2);
  }else printf("%.12f\n",(a1+a2)/2);
  return 0;
}

Measured memory_bytes: 3188
n=int(input())
mini = (10** 12)+1
X=0
Y=0
t=0
K=0
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    return divisors
ans = make_divisors(n)
ans.sort()
K+=len(ans)
if K%2:
  for i in range(int((K+1)/2)):
    t=-(i+1)
    if mini>ans[t]-ans[i] and n==ans[t]*ans[i] and ans[t]>=ans[i]:
      mini =ans[t]-ans[i]
      X=ans[t]
      Y=ans[i]
else:
  for i in range(int(K/2)):
    t=-(i+1)
    if mini>ans[t]-ans[i] and n==ans[t]*ans[i] and ans[t]>=ans[i]:
      mini =ans[t]-ans[i]
      X=ans[t]
      Y=ans[i]
print(X-1+Y-1)



Measured memory_bytes: 3284
using System;
using System.Collections.Generic;

namespace diverta2019_D
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = long.Parse(Console.ReadLine());
            var L = new Dictionary<long, int>();

            var sqrt = (int)Math.Ceiling(Math.Sqrt(N));
            long ans = 0;
            for (long i = 1; i <= sqrt; i++)
            {
                if (N % i == 0)
                {
                    var t = N / i;
                    var n = t - 1;
                    if (n > 0 && N % n == N / n)
                        ans += n;
                }
            }

            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 13152
import java.util.*;
import java.io.*;
public class Main
{
    public static void main(String []args) throws IOException {
    	FastScanner in  = new FastScanner(System.in);
    	PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)), false); 
    	solve(in, out);
    	in.close();
    	out.close();
    }
    static long gcd(long a, long b){ return (b==0) ? a : gcd(b, a%b); }
    static int gcd(int a, int b){ return (b==0) ? a : gcd(b, a%b); }
    
    public static int[] generatePrimes(int n) {
		boolean[] prime = new boolean[n + 1];
		Arrays.fill(prime, 2, n + 1, true);
		for (int i = 2; i * i <= n; i++)
			if (prime[i])
				for (int j = i * i; j <= n; j += i)
					prime[j] = false;
		int[] primes = new int[n + 1];
		int cnt = 0;
		for (int i = 0; i < prime.length; i++)
			if (prime[i])
				primes[cnt++] = i;
		return Arrays.copyOf(primes, cnt);
	}
    static class FastScanner{
	BufferedReader reader;
	StringTokenizer st;
	FastScanner(InputStream stream){reader=new BufferedReader(new InputStreamReader(stream));st=null;}	
	String next(){while(st == null || !st.hasMoreTokens()){try{String line = reader.readLine();if(line == null){return null;}		    
	     st = new StringTokenizer(line);}catch (Exception e){throw new RuntimeException();}}return st.nextToken();}
	String nextLine()  {String s=null;try{s=reader.readLine();}catch(IOException e){e.printStackTrace();}return s;}	    	  	
	int    nextInt()   {return Integer.parseInt(next());}
	long   nextLong()  {return Long.parseLong(next());}		
	double nextDouble(){return Double.parseDouble(next());}
	char   nextChar()  {return next().charAt(0);}
	int[]  nextIntArray(int n)         {int[] arr= new int[n];   int i=0;while(i<n){arr[i++]=nextInt();}  return arr;}
	long[] nextLongArray(int n)        {long[]arr= new long[n];  int i=0;while(i<n){arr[i++]=nextLong();} return arr;}	
	int[]  nextIntArrayOneBased(int n) {int[] arr= new int[n+1]; int i=1;while(i<=n){arr[i++]=nextInt();} return arr;}	    	
	long[] nextLongArrayOneBased(int n){long[]arr= new long[n+1];int i=1;while(i<=n){arr[i++]=nextLong();}return arr;}	    	
	void   close(){try{reader.close();}catch(IOException e){e.printStackTrace();}}				
    }
    
    /********* SOLUTION STARTS HERE ************/
    
    private static void solve(FastScanner in, PrintWriter out){
        int n = in.nextInt();
        int sum=1;
        String s = in.nextLine();
        for(int i=0;i<n-1;i++)
        {
            if(s.charAt(i)!=s.charAt(i+1)) sum++;
        }
        
        out.println(sum);
    }
    /************* SOLUTION ENDS HERE **********/
}

Measured memory_bytes: 22612
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define prtd(var, i) cout << fixed << setprecision(i) << var << endl;
#define ll long long
#define P pair<int, int>
using namespace std;

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


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


#define TRACE

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

#define rep(i, n)    for(int i = 0; i < (n); ++i)
#define repA(i, a, n)  for(int i = a; i <= (n); ++i)
#define repD(i, a, n)  for(int i = a; i >= (n); --i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
typedef long double ld;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

void pre(){


}

void solve(){


}
int a[109][109];
pii b[100009];
bool dfs(int a, int layer, const vector<vi>& g, vi& btoa,
			vi& A, vi& B) {
	if (A[a] != layer) return 0;
	A[a] = -1;
	trav(b, g[a]) if (B[b] == layer + 1) {
		B[b] = -1;
		if (btoa[b] == -1 || dfs(btoa[b], layer+2, g, btoa, A, B))
			return btoa[b] = a, 1;
	}
	return 0;
}

int hopcroftKarp(const vector<vi>& g, vi& btoa) {
	int res = 0;
	vi A(g.size()), B(btoa.size()), cur, next;
	for (;;) {
		fill(all(A), 0);
		fill(all(B), -1);
		/// Find the starting nodes for BFS (i.e. layer 0).
		cur.clear();
		trav(a, btoa) if(a != -1) A[a] = -1;
		rep(a,sz(g)) if(A[a] == 0) cur.push_back(a);
		/// Find all layers using bfs.
		for (int lay = 1;; lay += 2) {
			bool islast = 0;
			next.clear();
			trav(a, cur) trav(b, g[a]) {
				if (btoa[b] == -1) {
					B[b] = lay;
					islast = 1;
				}
				else if (btoa[b] != a && B[b] == -1) {
					B[b] = lay;
					next.push_back(btoa[b]);
				}
			}
			if (islast) break;
			if (next.empty()) return res;
			trav(a, next) A[a] = lay+1;
			cur.swap(next);
		}
		/// Use DFS to scan for augmenting paths.
		rep(a,sz(g)) {
			if(dfs(a, 0, g, btoa, A, B))
				++res;
		}
	}
}
vi c[109][109];
int main() {
	cin.sync_with_stdio(0); cin.tie(0);
	cin.exceptions(cin.failbit);
	pre();
	int n,m;cin>>n>>m;
	rep(i,n){
		rep(j,m){
			cin>>a[i][j];
			c[i][(a[i][j]-1)/m].pb(a[i][j]);
			b[a[i][j]] = mp(i,j);
		}
	}
	repA(i,1,m){
		vector<vi> g(2*n);
		vi btoa(2*n,-1);
		rep(j,n){
			repA(k,0,n-1){
				if(sz(c[k][j])) {
					g[j].pb(k+n);
					g[k+n].pb(j);
				}
			}
		}
		hopcroftKarp(g,btoa);
		rep(j,n){
			int k = btoa[j]-n;
			b[c[k][j].back()].snd = i-1;
			c[k][j].pop_back();
		}
	}
	repA(i,1,n*m) a[b[i].fst][b[i].snd] = i;
	rep(i,n) {
		rep(j,m) cout<<a[i][j]<<' ';
		cout<<'\n';
	}
	repA(i,1,n*m) a[(i-1)/m][b[i].snd] = i;
	rep(i,n) {
		rep(j,m) cout<<a[i][j]<<' ';
		cout<<'\n';
	}
	return 0;
}



Measured memory_bytes: 1152
#include <vector>
#include <iostream>
#include <math.h>

using namespace std;

typedef long long int ll;
long long int MOD = pow(10,9) + 7;

ll path_count(vector<vector<char>>& G)
{

    vector<vector<ll>> dp(G.size(),vector<ll>(G[0].size()));

    dp[G.size()-1][G[0].size()-1] = 1;

    for (int i=G.size()-1;i>=0;--i)
    {
        for (int j=G[0].size()-1;j>=0;--j)
        {

            if (i==G.size()-1 && j==G[0].size()-1) continue;

            if (G[i][j] == '#') continue;

            ll right = (j+1<G[0].size())?dp[i][j+1]:0;
            ll down = (i+1<G.size())?dp[i+1][j]:0;

            dp[i][j] = (right + down)%MOD;

        }
    }

    return dp[0][0];

}



int main()
{
    int H,W;
    cin>>H>>W;

    vector<vector<char>> G(H,vector<char>(W));

    for (int i=0;i<H;++i)
    {
        for (int j=0;j<W;++j)
        {
            char cur;
            cin>>cur;
            G[i][j] = cur;
        }
    }

    cout<<path_count(G)<<endl;

    return 0;
}


Measured memory_bytes: 12004
#include <iostream>
#include <string>

using namespace std;

string exchange(string c, int i, int j){
    string temp;
    temp = c[i];
    c[i] = c[j];
    c[j] = temp[0];

    return c;
}

string change(string c, int i){

    if(c[i] == 'W'){c[i] = 'R';}
    else{c[i] = 'W';}

    return c;
}

int judge(string c, int N){
    int t = 0;
    int has_R = 0;
    int area_R = 0;
    
    for(int i = 0; i < N; i++){ //count a number of 'R'
        if(c[i] == 'R'){
            has_R++;
        }
    }


    for (int i = has_R; i < N; i++){

        if(c[i] == 'R'){
            for(int j = area_R; j < has_R; j++){
                if(c[j] == 'W'){
                    c = exchange(c, j, i);
                    t++;
                    area_R = j;

                    break;
                }
            }
        }
        has_R = i;
    }


    return t;
}



int main(void){
    int N;
    string c;

    cin >> N;
    cin >> c;

    int ans;

    ans = judge(c, N);
    cout << ans;
    return 0;
}

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

int main(){
  int A,B,C,D;
  int ans = 0;
  cin >> A >> B >> C >> D;
  if(A<=C && C<=B){
    if(B<=D){
      ans = B-C;
    }else{
      ans = D-C;
    }
  }else if(C<A){
    if(A<=D && D<=B){
      ans = D-A;
    }else if(B<D){
      ans = B-A;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstring>
using namespace std;
int o;
char s;
int main()
{
	ios::sync_with_stdio(false);
    while(cin>>s)
    {
    	if(s=='9') o=1;
	}
    if(o)cout<<"Yes"<<endl;
	else  cout<<"No"<<endl; 
    return 0;
}

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

int main() {
  ll x;
  cin >> x;
  ll sum=0;
  for(int i=0;i<100000;i++){
    sum+=i;
    if(sum>=x){
      cout << i << endl;
      return 0;
    }
  }
}



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

using namespace std;

int main() {
    
    int num;
    cin >> num;
    vector<int> arr;
    for(int i = 0; i < num; ++i)
    {
        int ab;
        cin >> ab; 
        arr.push_back(ab);
    }
    sort(arr.begin(), arr.end());
    long long ans = 0;
    for(int i = 1; i < arr.size(); ++i)
    {
        ans += arr[(num-1) - i/2];
    }
    cout << ans;
}


Measured memory_bytes: 4240
#include <stdio.h>

int main() {
    int x, yenes10, yenes5, soma;
    scanf("%d", &x);
    yenes10 = 1000*(x/500);
    yenes5 = 5*((x%500)/5);
    soma = yenes10 + yenes5;
    printf("%d\n", soma);
    

    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
	string s[100];
	int h, w;
	cin >> h >> w;
	for (int i = 0; i < h; ++i)
	{
		cin >> s[i];
	}
	for (int i = -1; i < h + 1; ++i)
	{
		for (int j = -1; j < w+1; ++j)
		{
			if (i == -1 || i == h || j == -1 || j == w)
			{
				cout << "#";
			}
			else
			{
				cout << s[i][j];
			}
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int gcd(int x,int y){
    int result=0;
   
    while(true){
        x=x%y;
       // cout<<"x:"<<x<<"y:"<<y<<endl;
        if(x==0){result=y;break;}
         y=y%x;
        //cout<<"x:"<<x<<"y:"<<y<<endl;
        if(y==0){result=x;break;}
    }
    return result;
}

int main(){
    int x,y;
    cin>>x>>y;
   
    cout<<gcd(x,y)<<endl;
}




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

typedef long long ll;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); ++itr)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second

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

    stack<char> st;
    rep(i,s.size())
    {
        if(!st.empty() && st.top()=='S' && s[i]=='T') st.pop();
        else st.push(s[i]);
    }

    cout << st.size() << endl;
    return 0;
}


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

bool is_prime(const unsigned n){
    switch(n){
        case 0: // fall-through
        case 1: return false;
        case 2: // fall-through
        case 3: return true;
    } // n > 3 が保証された

    if(n%2 == 0) return false;
    if(n%3 == 0) return false;
    // 2と3の倍数でないので6の倍数ではないことが保証された

    if(n%6 != 1 && n%6 != 5) return false;
    // 6の倍数前後の数(素数かもしれない数)であることが保証された

    // 6の倍数前後の数を使って試し割りをする
    for(unsigned i=5;i*i<=n;i+=6){
        if(n%i     == 0) return false; // 6n-1
        if(n%(i+2) == 0) return false; // 6n+1
    }

    return true;
}

int main(){
    ll X; cin >> X;
    vector<int> prime;
    rep(i, 2, 100100){
        if(is_prime(i)) prime.push_back(i);        
    }
    cout << *lower_bound(prime.begin(), prime.end(), X) << endl;

}

Measured memory_bytes: 384
H,W = list(map(int,input().split()))

rows = []
for i in range(1,H+1):
    row = input()
    if row.count("#") > 0:
        rows.append(list(row))

cols = []
for j in range(W):
    col = ""
    for k in range(len(rows)):
        col += rows[k][j]

    if col.count("#") > 0:
        cols.append(col)
        
ans = []
for l in range(len(cols[0])):
    row = ""
    for m in range(len(cols)):
        row += cols[m][l]

    ans.append(row)
    
print("\n".join(ans))

Measured memory_bytes: 3188
ans = []

n, k = gets.chomp.split(" ").map(&:to_i);
h = readlines.map{|l| l.to_i}
h1 = h.sort

(n - k + 1).times do |i|
  ans << (h1[i + k -1] - h1[i]).abs
end
puts ans.min

Measured memory_bytes: 10600
#include <bits/stdc++.h>
using namespace std;
int data[100],n,tot;
int vis[1000000];
int divide(int x){
	for (register int i=2;i<=x;++i){
		if (x%i) continue;
		while(x%i==0) data[i]++,x/=i;
	}	
}
int sum(int x){
	int res=0;
	for (;res<=tot;++res)
		if (data[res+1]<x-1) return res;
}
bool cmp(int a,int b){
	return a>b;
}
int main(){
	cin>>n;
	for (int i=2;i<=n;++i)
		divide(i);
	sort(data+1,data+101,cmp);
	for (tot=1;tot<=101;++tot)
		if (!data[tot]) {tot--;break;}
	int a=sum(75),b=sum(25),c=sum(15),d=sum(5),e=sum(3);
	int ans=a+b*(e-1)+c*(d-1)+d*(d-1)*(e-2)/2;
	printf("%d\n",ans);
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
	int test[6];
	int min4 = 100, min2 = 100, sum = 0;
	int i;
	
	for (i = 0; i < 6; i++){
		scanf("%d", &test[i]);
		sum += test[i];
	}
	
	for (i = 0; i < 4; i++){
		if (min4 > test[i]) min4 = test[i];
	}
	
	for (i = 4; i < 6; i++){
		if (min2 > test[i]) min2 = test[i];
	}
	sum = sum - min4 - min2;
	
	printf("%d\n", sum);
	
	return 0;
}

Measured memory_bytes: 600
/*
	Failure is not the reason for you to stop trying 
	   it is actually a remainder that you should 
			KEEP GOING 
*/
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back 
#define eb emplace_back
#define fn for(int i =0 ;i <n;i++)
#define fn1 for( int i =1;i<=n;i++)
#define fm for(int j =0 ;j <m;j++)
#define fm1 for(int j =1;j<=m;j++)
#define fi first
#define se second
#define E endl
#define MOD 1000000007
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
const int N = 1e6+5;
const int INF = 1e18L;
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}
double ar[N];
int dp[N];
signed main(){
	// #ifndef ONLINE_JUDGE
	// freopen("input.txt","r",stdin);
	// freopen("output.txt","w",stdout);
	// #endif
	IOS;
	int T=1;
	// cin >> T;
	while(T--){
		double h , w , x  ,y;
		cin >> h >> w >> x >> y;
		double tot = h*w;
		cout << setprecision(10) << fixed;
		cout << tot/2<<" ";
		if(2*x == h && 2*y==w)cout<<1;
		else
			cout<<0;
	
	}
	
	cerr << "Time elapsed : " << 1.0 * clock() / CLOCKS_PER_SEC << " sec \n";
	return 0;
}

Measured memory_bytes: 256
from itertools import count, combinations, product

H,W = map(int,input().split())

H += 2
W += 2

visited = [2**31]*(W*H)

for i in range(1,H-1):
    S = input()
    for j,v in zip(range(1,W-1),S):
        if v == '.':
            visited[i*W + j] = 0

res = 1
D = (W,-W,1,-1)

for i in range(W*H):
    if visited[i] == 2**31:
        continue
    q = [i]
    visited[i] = i
    for dist in count():
        if not q:
            break
        nq = []
        for j in q:
            for d in D:
                if visited[j+d] < i:
                    visited[j+d] = i
                    nq.append(j+d)
        q = nq
    res = max(dist, res)

print(res-1)

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

#define rep2(x,fr,to) for(int x=(fr);x<(to);x++)
#define rep(x,to) for(int x=0;x<(to);x++)
#define repr(x,fr,to) for(int x=(fr);x>=(to);x--)
#define all(c) c.begin(),c.end()
#define sz(v) (int)v.size()

using namespace std;
typedef long long  ll; typedef vector<int> VI; typedef pair<int,int> pii; typedef vector<ll> VL; const int MD = 1e9 + 7;
void dbg(){cerr<<"\n";} template <class F,class ...S> void dbg(const F& f, const S&...s){cerr <<f <<": "; dbg(s...);}


int main()
{
	cin.tie(0); ios_base::sync_with_stdio(false);
	int n, m;
	cin >>n >>m;
	vector<VI> r(n+1);
	rep(i, m){
		int a, b; cin >>a >>b;
		r[a].push_back(b);
		r[b].push_back(a);
	}
	
	const int INF= 1<<28;
	VI dd(n+1, INF), bf(n+1, -1);
	queue< int > que;
	que.emplace(1); dd[1]=0;
	while(!que.empty()){
		int cy = que.front();
		que.pop();
		for(auto v: r[cy]){
			if(dd[v] == INF){
				que.emplace(v);
				dd[v] = dd[cy] + 1;
				bf[v] = cy;
			}
		}
	}
	cout <<"Yes\n";
	rep2(i,2, n+1) cout <<bf[i] <<"\n";
	
	return 0;
}


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

using namespace std;

int n, k;
vector<int> a(200000);

bool good(int x) {
  int cut = 0;
  for (int i = 0; i < n; i++) {
    cut += a[i] / x;
    if (a[i] % x == 0) cut--;
    if (cut > k) return false;
  }
  return true;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  int upper = *max_element(a.begin(), a.end());
  int lower = 0;
  int mid = 1;
  while (upper - lower > 1) {
    mid = (upper + lower) / 2;
    if (good(mid)) {
      upper = mid;
    } else {
      lower = mid;
    }
  }
  cout << upper << '\n';
  return 0;
}

Measured memory_bytes: 3912
#include <iostream>
#include <iomanip>
#include <climits>
#include <algorithm>
#include <vector>
#include <deque>
#include <queue>
#include <list>
#include <stack>
#include <string>
#include <functional>
#include <numeric>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <unordered_map>
#include <random>
#define _USE_MATH_DEFINES
#include <math.h>
#include <complex>

using namespace std;

#define INF (int)1e8
#define _INF (int)-1e8
#define INFLL (long long)1e15
#define _INFLL (long long)-1e15
#define Loop(i, n) for(int i = 0; i < (int)n; i++)
#define Loop1(i, n) for(int i = 1; i <= (int)n; i++)
#define Loopr(i, n) for(int i = (int)n - 1; i >= 0; i--)
#define Loopr1(i, n) for(int i = (int)n; i >= 1; i--)
#define bitmanip(m,val) static_cast<bitset<(int)m>>(val)
typedef long long int ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef pair<int, int> P;

/*******************************************************/

int main() {
  ll n, a, b; cin >> n >> a >> b;
  ll ans = 0;
  if (a <= b) {
    if (a < b && n == 1) ans = 0;
    else {
      ll x = a * (n - 1) + b;
      ll y = b * (n - 1) + a;
      ans = y - x + 1;
    }
  }
  cout << ans << endl;
}

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

typedef long long ll;

ll gcd(ll a, ll b)
{
	if(!b) return a;
	return gcd(b, a % b);
}

int n, m, ans;
ll cnt[100010], is[100010];

int main()
{
	ll a, b, c;
	scanf("%lld %lld", &a, &b);
	c = gcd(a, b);
	for(ll i = 1; i * i <= c; ++i)
		if(c % i == 0)
		{
			cnt[++m] = i;
			if(i * i != c) cnt[++m] = c / i;
		}
	sort(cnt + 1, cnt + 1 + m);
	for(int i = 1; i <= m; ++i)
	{
		bool flag = 1;
		for(int j = 1; j <= n; ++j)
			if(is[j] != 1 && cnt[i] % is[j] == 0) flag = 0;
		if(flag) ++ans, is[++n] = cnt[i];
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <vector>
#define rep(i,n) for(int i=0;i<n;i++)
#define ll long long int
#define ii pair<int,int>
#define MAX 1000000007
using namespace std;

int main(void){
	int n;
	cin>>n;
	int p[n];
	rep(i,n)cin>>p[i];
	int cnt=0;
	rep(i,n-2)if(p[i]<p[i+1] && p[i+1]<p[i+2] || p[i+2]<p[i+1] && p[i+1]<p[i])cnt++;

	cout<<cnt<<endl;
	return 0;
}


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

using namespace std;
typedef long long ll;
const int MAXN = 2000 + 5;
int n, m, q;
bool s[MAXN][MAXN];
int e[MAXN][MAXN], v[MAXN][MAXN], dp[MAXN][MAXN][2] ;
// |( 0) // -- (1)

char x;

int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin >> n >> m >> q;
	for(int i = 0; i < n; i ++){
		for(int j = 0; j < m; j ++){
			cin >> x;
			s[i][j] = x - '0';
			if( i == 0 && j == 0) v[i][j] = s[i][j];
			else if(i == 0){
				v[i][j] = v[i][j - 1] + s[i][j];
				e[i][j] = e[i][j - 1] + (s[i][j] && s[i][j - 1]);
			}
			else if(j == 0){
				v[i][j] = v[i - 1][j] + s[i][j];
				e[i][j] = e[i - 1][j] + (s[i][j] && s[i - 1][j]);
			}
			else{
				v[i][j] = v[i][j - 1] + v[i - 1][j] - v[i - 1][j - 1] + s[i][j];
				e[i][j] = e[i - 1][j] + e[i][j - 1] - e[i - 1][j - 1] + (s[i - 1][j] && s[i][j]) + (s[i][j - 1] && s[i][j]);
			}
		}
	}
	for(int i = 1; i < n; i ++){
		dp[i][0][0] = (s[i][0] && s[i - 1][0]);
		for(int j = 1; j < m; j ++)
			dp[i][j][0] = dp[i][j - 1][0] + (s[i][j] && s[i - 1][j]);
		// |
	}
	for(int i = 1; i < m; i ++){
		dp[0][i][1] = (s[0][i] && s[0][i - 1]);
		for(int j = 1; j < n; j ++)
			dp[j][i][1] = dp[j - 1][i][1] + (s[j][i] && s[j][i - 1]);
		// --
	}
	while( q ){
		q --;
		int x1, x2, y1, y2;
		cin >> x1 >> y1 >> x2 >> y2, x1 --, x2 --, y1 --, y2 --;
		if( x1 == 0 && y1 == 0)
			cout <<  v[x2][y2] - (e[x2][y2]) << '\n';
		else if( x1 == 0) 
			cout << v[x2][y2] - v[x2][y1 - 1] - (e[x2][y2] - e[x2][y1 - 1] - dp[x2][y1][1]) << '\n';
		else if( y1 == 0)
			cout <<  v[x2][y2] - v[x1 - 1][y2] - (e[x2][y2] - e[x1 - 1][y2] - dp[x1][y2][0]) << '\n';
		else{
			int ver = v[x2][y2] - v[x1 - 1][y2] - v[x2][y1 - 1] + v[x1 - 1][y1 - 1];
			int edge= e[x2][y2] - e[x1 - 1][y2] - e[x2][y1 - 1] + e[x1 - 1][y1 - 1];
			edge += dp[x1 - 1][y1][1] + dp[x1][y1 - 1][0];
			edge -= dp[x2][y1][1] + dp[x1][y2][0];
			cout  << ver - edge << endl;
			
		}
	}
	return 0;
}


Measured memory_bytes: 70236
#include <bits/stdc++.h>
#define pb push_back
typedef long long int ll;
#define loop(a,b) for(int i=a;i<b;i++)
#define say(a) cout<<a<<endl
#define say2(a,b) cout<<a<<" "<<b<<endl;
ll mod =1e9+7;
using namespace std;

int main()
{
    int n;
    scanf("%d",&n);
    double s=0,f;
    loop(0,n) {scanf("%lf",&f);
    s+=(double)(1/f);
    }
    s=(double)1/s;
    say(s);
}


Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
#include <vector>
using namespace std;

int N; vector<pair<int, int> > w[16];

int main()
{
	scanf ("%d", &N);
	for (int i = 0; i < N; i++){
		int k; scanf ("%d", &k); while (k--){
			int x, y; scanf ("%d %d", &x, &y); x--;
			w[i].push_back({ x,y });
		}
	}

	int a = 0;
	for (int b = 0; b < (1 << N); b++){
		bool gg = 1;
		int c = 0;
		for (int j = 0; j < N; j++) if (b & (1 << j)){
			bool g = 1;
			for (auto &p : w[j]){
				if (((b & (1 << p.first)) > 0) != p.second) g = 0;
			}
			if (!g) gg = 0;
			c++;
		}
		if (gg){
			a = max(a, c);
		}
	}
	printf ("%d\n", a);
	return 0;
}

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

using namespace std;
using ll = long long;
using pii = pair<int, int>;
using db = long double;
using vi = vector<int>;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define debug(x) cout << #x <<"\t" << x <<endl
const int inf = 0x3f3f3f3f;
const db eps = 1e-8;
const int mod = 1e9+7;
ll qpow(ll a, ll b){
	ll ret = 1;
	while(b){
		if(b&1)ret = ret*a%mod;
		a = a*a%mod;
		b>>=1;
	}
	return ret;
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	db a, b, c;
	cin >> a >> b >> c;
	if(2*sqrt(a*b)<(c-a-b)){
		cout <<"Yes\n";
	}else{
		cout <<"No\n";
	}
}





Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
using namespace std;
constexpr int mod=1e9+7;
signed main(){
    string s;
    int q,t,f;
    char c;
    cin>>s>>q;
    bool turn=0;
    deque<char>deq;
    for(int i=0;i<s.size();i++)
        deq.push_back(s[i]);
    for(int i=0;i<q;i++){
        cin>>t;
        if(t==1)
            turn=!turn;
        else{
            cin>>f>>c;
            if(turn&&f==1||!turn&&f==2)
                deq.push_back(c);
            else
                deq.push_front(c);
        }
    }
    string ans;
    for(auto x:deq)
        ans.push_back(x);
    if(turn)
        reverse(ans.begin(),ans.end());
    cout<<ans<<endl;
}


Measured memory_bytes: 1412
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<utility>
#include<tuple>
#include<algorithm>
using namespace std;
#define INF 1e9
#define ll long long

int main(){
    int N;cin>>N;
    ll X;cin>>X;
    vector<int> A(N);
    for(int i=0;i<N;i++){
        cin>>A[i];
        A[i]--;
    } 
    vector<bool> v(N,false);
    int now=0;
    int cf=0;
    while(true){
        if(v[now]) break;
      if(cf==X){
        cout<<now+1<<endl;
        return 0;
      }
        v[now]=true;
        now=A[now];
        cf++;
    }
    int cnt=1;
    int s=A[now];
    while(s!=now){
        s=A[s];
        cnt++;
    }
    X-=cf;
    X%=cnt;
    for(int i=0;i<X;i++){
        now=A[now];
    }
    cout<<now+1<<endl;
}


Measured memory_bytes: 3664
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(obj) (obj).begin(), (obj).end()

using namespace std;
typedef long long unsigned int ll;

double dist(int x1, int x2, int y1, int y2) {
	double d;
	d = sqrt((x1 - x2)*(x1 - x2) + (y1 - y2)*(y1 - y2));
	return d;
}

int main() {
	int n;
	cin >> n;
	vector<int>x, y;
	REP(i, n) {
		int _x, _y;
		cin >> _x >> _y;
		x.emplace_back(_x);
		y.emplace_back(_y);
	}

	vector<int>v;
	double sum = 0.0;
	double cnt = 0.0;
	REP(i, n)v.emplace_back(i);
	do {
		REP(i, n - 1) {
			sum += dist(x[v[i]], x[v[i + 1]], y[v[i]], y[v[i + 1]]);
		}
		cnt++;
	} while (next_permutation(ALL(v)));
	sum /= cnt;

	cout << fixed << setprecision(10) << sum;
}

Measured memory_bytes: 256
import Control.Monad
import Data.List
import Data.Maybe

main=do
    n<-readLn::IO Int
    putStrLn $ f2 n

f2 :: Int -> String
f2 n
    | n==0 = "0"
    | n>0  = f1 n
    | True = tail $ f1 n

f1 n
    | n==0 = "0"
    | even n = f (n`div`2) "0"
    | True   = f (n`div`2) "1"

f n r
    | n==0 = r
    | n`mod`4 == 0 = f ((n+1)`div`4) ('0':'0':r)
    | n`mod`4 == 1 = f ((n+1)`div`4) ('1':'1':r)
    | n`mod`4 == 2 = f ((n+1)`div`4) ('1':'0':r)
    | n`mod`4 == 3 = f ((n+1)`div`4) ('0':'1':r)


Measured memory_bytes: 508
// SeeAlso: 

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define MAX 100000
#define NIL -1
#define MOD 1000000007

typedef int _loop_int;
#define rep(i,n) for(int i = 0; i < n; i++)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define debug(x) cout<<#x<<": "<<x<<endl
#define debig_vec(v) cout<<#v<<":";rep(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

// 最大公約数
inline constexpr ll gcd(ll a,ll b){if(!a||!b)return 0;while(b){ll c=b;b=a%b;a=c;}return a;}
// 最小公倍数
inline constexpr ll lcm(ll a,ll b){if(!a||!b)return 0;return a*b/gcd(a,b);}

#define print2D(h, w, arr) rep(i, h) { rep(j, w) cout << arr[i][j] << " "; cout << endl; }
template<class T> void print(const T& x){cout << setprecision(12) << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }

int main() {
    string s;
    cin >> s;
    vector<char> ans;
    rep(i, s.size()) {
        ans.push_back(s[i]);
    }
    
    ll q;
    cin >> q;
    bool hanten = false;
    rep(i, q) {
        int t;
        cin >> t;

        if(t==1) {
            hanten = !hanten;
        } else {
            int f;
            char c;
            cin >> f;
            cin >> c;

            bool isFront;

            if(f==1) {
                isFront = !hanten;
            } else {
                isFront = hanten;
            }
            
            if(isFront) {
                ans.insert(ans.begin(),c);
            } else {
                ans.push_back(c);
            }
        }
    }

    if(hanten) {
        reverse(ans.begin(), ans.end());
    }

    for(auto it=ans.begin();it!=ans.end();it++){
        cout << *it;
    }

    cout << endl;
    return 0;
}


Measured memory_bytes: 1144
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long A = sc.nextLong();
		long B = sc.nextLong();
		long C = sc.nextLong();
		long X = sc.nextLong();
		long Y = sc.nextLong();
		
		long sum = 0;
		
		if(A + B >= 2 * C) {
			if(X >= Y) {
				sum = 2 * C * Y;
				if(A >= 2 * C) {
					sum += (X - Y) * 2 * C;
				} else {
					sum += (X - Y) * A;
				}
			} else {
				sum = 2 * C * X;
				if(B >= 2 * C) {
					sum += (Y - X) * 2 * C;
				} else {
					sum += (Y - X) * B;
				}
			}
		} else if(A + B < 2 * C) {
			sum = A * X + B * Y;
		}
		System.out.println(sum);
	}
}


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

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

Measured memory_bytes: 3544
while s=gets
	n=s.to_i
	break if n==0
	r=0
	(2..1/0.0).each{|i|
		x=n/i*i+i*(i-1)/2
		break if x>2*n
		if (x-n)%i==0
			d=x-n
			k=n/i-d/i
			break if k<=0
			r+=1
		end
	}
	p r
end

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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int INF = 1e9;

bool s[200050];
bool t[200050];

int main() {
  int n, m, a, b;
  cin >> n >> m;

  rep(i, m) {
    cin >> a >> b;
    if (a == 1) s[b] = true;
    if (b == n) t[a] = true;
  }
  for (int i = 0; i < 200050; ++i) {
    if (s[i] && t[i]) {
      cout << "POSSIBLE" << endl;
      return 0;
    }
  }
  cout << "IMPOSSIBLE" << endl;
  return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<map>
#define int long long
#define endl '\n'
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define line cout<<"here - "<<__LINE__<<"\n";
#define dbg(a) cout<<#a<<" --> "<<(a)<<"\n";
#define infi INT_MAX
#define rinfi INT_MIN
#define inf LLONG_MAX
#define rinf LLONG_MIN
#define ff first
#define ss second
using namespace std;
main()
{
    //fast
    int tc=1,i,j,k;
//    cin>>tc;
    while(tc--)
    {
       string aa;
       cin>>aa;
       map<char,int>mp;
       for(i=0;i<aa.size();i++)
        mp[aa[i]]++;
       int ok=1;
       for(char s='a';s<='z';s++)
       {
           if(mp[s]%2==1)
            ok=0;
       }
       if(ok) cout<<"Yes"<<endl;
       else cout<<"No"<<endl;

    }
}




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

typedef long long LL;

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(x) (x).begin(),(x).end()
const int IINF = 1e9;
const LL LINF = 1e18;
const LL MOD = 1e9+7;

LL power(LL x, LL y) {
    LL r = 1;
    for(;0 < y;) {
        if(y%2 == 0) {
            y /= 2;
            x = (x*x)%MOD;
        }else{
            y--;
            r = (r*x)%MOD;
        }
    }
    return r;
}

LL inverse(LL n) {
    return power(n, MOD - 2);
}

int main() {
    LL N;
    cin >> N;
    LL res = 0;
    vector<LL> fact(N + 1);
    vector<LL> fact_inv(N + 1);
    fact[0] = 1;
    fact_inv[0] = 1;
    FOR(i, 1, N + 1) {
        fact[i] = (fact[i - 1]*i)%MOD;
        fact_inv[i] = inverse(fact[i]);
    }

    FOR(i_zero, 1, N) {
        LL c;
        c = (fact[N]*fact_inv[i_zero])%MOD;
        c = (c*fact_inv[N - i_zero])%MOD;

        LL all = power(9, N - i_zero);
        LL reject = power(8, N - i_zero);

        LL x = (c*(all - reject))%MOD;
        res = (res + x)%MOD;
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 18780
line1 = input()
line1 = line1.rstrip().split(" ")
A = int(line1[0])
B = int(line1[1])
C = int(line1[2])
D = int(line1[3])

if -D<= A-C <=D:
    print("Yes")
else:
    if -D<= A-B <=D and -D<= B-C <=D:
        print("Yes")
    else:
        print("No")

Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <vector>
#include <list>
#include <algorithm>
#include <cmath>
#include <stack>
#include <set>
using namespace std;

#define REP(i,n) for(int (i)=0; (i)<(n); (i)++)
#define FOR(i,a,b) for(int (i)=(a); (i)<(b); (i)++)
#define PUSH(n,v) for(int i=0; i<(n); i++) {int j; cin >> j; v.push_back(j);}
#define ALL(v) v.begin(), v.end()

int getint(char c) {
    if (c == 'A') return 1;
    else if (c == 'C') return 2;
    else if (c == 'G') return 3;
    else return 4;
}

int getint(string s) {
    int j = 1;
    int a = 0;
    REP(i, s.size()) {
        a += j * getint(s[i]);
        j *= 5;
    }
    return a;
}

int main() {
    int n;
    cin >> n;
    set<int> st;
    REP(i,n) {
        string s, t;
        cin >> s >> t;
        int h = getint(t);
        if (s[0] == 'i') st.insert(h);
        else {
            if (st.find(h) != st.end()) cout << "yes" << endl;
            else cout << "no" << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 14124
#include "bits/stdc++.h"
using namespace std;
int main()
{
    char c;
    scanf("%c",&c);
    switch(c)
    {
        case 'A':
             printf("T\n");
             break;
        case 'T':
             printf("A\n");
             break;
        case 'C':
             printf("G\n");
             break;
        case 'G':
             printf("C\n");
             break;
    }
    return 0;
}

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

int main(){
    int r,g,b;
    cin>>r>>g>>b;
    int ans = 100*r+10*g+b;
    puts(ans%4==0 ? "YES":"NO");
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <string>
#include <climits>
#include <iomanip>
#include <algorithm>
#include <queue>
#include <map>
#include <tuple>
#include <iostream>
#include <deque>
#include <array>
#include <set>
#include <functional>
#include <memory>

int main() {
	int n; std::cin >> n;
	std::vector<long long int> dum(n);
	for (auto& m : dum) std::cin >> m;
	long long int all_sum = 0;
	for (const auto m : dum) all_sum += m;
	long long int odd_sum = 0;
	for (auto i = 1; i < n; i += 2){
		odd_sum += dum[i] * 2;
	}
	auto prev = all_sum - odd_sum;
	std::cout << prev;
	for (auto i = 0; i < n - 1; ++i) {
		dum[i] -= prev / 2;
		prev = dum[i] * 2;
		std::cout << " " << prev;
	}
	std::cout << std::endl;
}


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

int main() {

	std::string s;
	std::cin >> s;

	std::vector<char> stack_;

	stack_.reserve(s.size());

	auto count = 0;
	for (const auto&e : s) {

		if (stack_.empty()) {
			stack_.push_back(e);
			continue;
		}
			
		if (stack_.back() != e) {
			stack_.pop_back();
			count += 2;
//			continue;
		}
		else {
			stack_.push_back(e);
		}
	}

	std::cout << count << "\n";

	return 0;
}

Measured memory_bytes: 640
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int n = scanner.nextInt();
			String prev = null;
			boolean shiritori = true;
			Set<String> set = new HashSet<>();
			for (int i = 0; i < n; i++) {
				String w = scanner.next();
				if (shiritori) {
					if (null != prev) {
						if (prev.charAt(prev.length() - 1) != w.charAt(0)) {
							shiritori = false;
						}
					}
				}
				set.add(w);
				prev = w;
			}
			System.out.println((shiritori && (set.size() == n)) ? "Yes" : "No");
		}
	}
}


Measured memory_bytes: 35928