akhauriyash/Code-Regression huggingface dataset:
// 2012/12/16 Tazoe

#include <iostream>
#include <string>
using namespace std;

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

	int k = 0;
	int s = 0;

	int k_J = 0;
	int k_O = 0;
	int k_I = 0;

	for(int i=0; i<S.size(); i++){
		switch(s){
			case 0:
				if(S[i]=='J'){
					s = 1;
					k_J = 1;
					k_O = 0;
					k_I = 0;
				}
				else if(S[i]=='O'){
					s = 0;
					k_J = 0;
					k_O = 0;
					k_I = 0;
				}
				else if(S[i]=='I'){
					s = 0;
					k_J = 0;
					k_O = 0;
					k_I = 0;
				}
				break;
			case 1:
				if(S[i]=='J'){
					s = 1;
					k_J++;
					k_O = 0;
					k_I = 0;
				}
				else if(S[i]=='O'){
					s = 2;
					k_O = 1;
					k_I = 0;
				}
				else if(S[i]=='I'){
					s = 0;
					k_J = 0;
					k_O = 0;
					k_I = 0;
				}
				break;
			case 2:
				if(S[i]=='J'){
					s = 1;
					k_J = 1;
					k_O = 0;
					k_I = 0;
				}
				else if(S[i]=='O'){
					s = 2;
					k_O++;
					k_I = 0;
				}
				else if(S[i]=='I'){
					s = 3;
					k_I = 1;
				}
				break;
			case 3:
				if(S[i]=='J'){
					if(k_O<=k_J&&k_O<=k_I&&k_O>k){
						k = k_O;
					}
					s = 1;
					k_J = 1;
					k_O = 0;
					k_I = 0;
				}
				else if(S[i]=='O'){
					if(k_O<=k_J&&k_O<=k_I&&k_O>k){
						k = k_O;
					}
					s = 0;
					k_J = 0;
					k_O = 0;
					k_I = 0;
				}
				else if(S[i]=='I'){
					s = 3;
					k_I++;
				}
				break;
		}
	}

	if(s==3){
		if(k_O<=k_J&&k_O<=k_I&&k_O>k){
			k = k_O;
		}
	}

	cout << k << endl;

	return 0;
}

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

rr,cc,kk=map(int,input().split())
goods=np.array([list(map(int,input().split())) for _ in range(kk)])
gg=np.zeros((rr,cc))
for cr,ccc,ck in goods:
    gg[cr-1][ccc-1]=ck

@njit
def calc(r,c,g):
    dp=-1*np.ones((r+1,c+1,4))
    maxlst=np.zeros((r+1,c+1))

    dp[:,0,0]=0
    dp[0,:,0]=0
    
    for i in range(r):
        for j in range(c):
            tmp=0
            for k in range(3):
                if g[i][j]>0 and dp[i+1][j][k]>=0:
                    dp[i+1][j+1][k+1]=max(dp[i+1][j][k+1],dp[i+1][j][k]+g[i][j])
                else:
                    dp[i+1][j+1][k+1]=dp[i+1][j][k+1]
                tmp=max(tmp,dp[i+1][j+1][k+1])
            
            dp[i+1][j+1][0]=max(maxlst[i][j+1],dp[i+1][j][0])
            tmp=max(tmp,dp[i+1][j+1][0])
            
            if g[i][j]>0 and dp[i+1][j+1][0]>=0:
                dp[i+1][j+1][1]=max(dp[i+1][j+1][1],dp[i+1][j+1][0]+g[i][j])
                tmp=max(tmp,dp[i+1][j+1][1])
            
            maxlst[i+1][j+1]=tmp
    
    return maxlst[r][c]
            
print(int(calc(rr,cc,gg)))

Measured memory_bytes: 761612
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
//大小比較(大)
long long int big(long long int a, long long int b) {
	if (a >= b) {
		return a;
	}
	else {
		return b;
	}
}

//大小比較(小)
long long int small(long long int a, long long int b) {
	if (a >= b) {
		return b;
	}
	else {
		return a;
	}
}

main() {
	long long int a=0,b=0,c=0,n, m, k = 0;
	char str[5],str2[5];
	
	scanf("%lld%lld", &a,&b);
	
	printf("%lld", 2 * b - a);
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <algorithm>
#include <utility>
#include <iomanip>
#include <functional>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cctype>
#include <cstdio>
#include <bitset>
#define ll long long
#define INF 1000000000000000001
#define MOD 1000000007
using namespace std;



int main(){
    int N;
    cin >> N;
    cout << N*N*N << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdio>
#define rep(i,n) Rep(i,0,n)
#define Rep(i,k,n) for(int i=k ; i<n ; i++)

const int INF = 1 << 30;
long long cnt = 0;

using namespace std;

void Merge(int x[],int left, int mid, int right){
    //define range
    int n1 = mid - left;
    int n2 = right - mid;

    //working array
    int l[n1+10],r[n2+10];

    //init
    rep(i,n1) l[i] = x[left + i]; 
    rep(i,n2) r[i] = x[mid + i];

    //番兵
    l[n1] = r[n2] = INF;

    int il = 0;
    int ir = 0;
    
    //転倒数の増加分
    int t = 0;

    for(int i = left; i < right ; i++){
        if(l[il] <= r[ir]){
            x[i] = l[il];
            il++;
            cnt += t;

        }else{
            x[i] = r[ir];
            ir++;
            t += 1;
        }
        
    }
}

void MergeSort(int x[],int left,int right){
    if(left+1 < right){
        int mid = (left + right)/2;

        MergeSort(x,left,mid);
        MergeSort(x,mid,right);
        Merge(x,left,mid,right);
    }
}

int main(){
    int n; cin >> n;
    int t[n];
    rep(i,n) cin >> t[i];

    
    MergeSort(t,0,n);
    
    //rep(i,n) cout << t[i] << (i == n-1 ? '\n':' ');
    cout << cnt << endl;
    
}


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

char s[52][52];
int num(int a,int b) {
	int c = 0;
	for (int i = -1; i < 2; i++){
		for (int j = -1; j < 2; j++) {
			if (s[a + i][b + j] == '#') {
				c++;
			}
		}
	}
	return c;
}

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

	int H, W;
	cin >> H >> W;
	for (int i = 0; i < H + 2; i++)for (int j = 0; j < W + 2; j++) {
		s[i][j] = '.';
	}
	for (int i = 1; i < H + 1; i++)for (int j = 1; j < W + 1; j++) {
		cin >> s[i][j];
	}
	for (int i = 1; i < H + 1; i++) {
		for (int j = 1; j < W + 1; j++) {
			if (s[i][j] == '#')cout << "#";
			else {
				cout << num(i, j);
			}
		}
		cout << endl;
	}
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fs first
#define sc second
using namespace std;
typedef long long ll;

const int INF = 1e9;
const int  kx[] = {0,1,1,-1}, ky[] = {1,0,1,1};

inline pair<int,int> line_cp(int d1, int x1, int y1, int d2, int x2, int y2){
  int X=INF, Y=INF;
  if(d1==d2)return make_pair(X,Y);

  if(kx[d1] == 0){
    if(kx[d2] != 0){
      Y = y1;
      X = ky[d2]*(Y-y2)/kx[d2] + x2;
    }
    return make_pair(X,Y);
  }
  if(ky[d1] == 0){
    if(ky[d2] != 0){
      X = x1;
      Y = kx[d2]*(X-x2)/ky[d2] + y2;
    }
    return make_pair(X,Y);
  }
  if(kx[d2] == 0){
    Y = y2;
    X = ky[d1]*(Y-y1)/kx[d1] + x1;
    return make_pair(X,Y);
  }
  if(ky[d2] == 0){
    X = x2;
    Y = kx[d1]*(X-x1)/ky[d1] + y1;
    return make_pair(X,Y);
  }

  int dy1 = ky[d1]*kx[d2], dy2 = ky[d2]*kx[d1];
  Y = (dy1*y1 - dy2*y2 - kx[d1]*kx[d2]*(x1-x2) );
  if(dy1-dy2==0 || abs(Y) % abs(dy1-dy2) != 0)return make_pair(INF,INF);
  Y /= dy1-dy2;
  X = ky[d1]*(Y-y1)/kx[d1] + x1;
  return make_pair(X,Y);
}

inline int check(int x1,int y1,int x2,int y2){
  int difx = abs(x1-x2), dify = abs(y1-y2);
  if( difx == dify || difx==0 || dify==0 )return 1;
  return 0;
}

inline int solve(int k){
  int x1,y1,x2,y2,X,Y;
  cin >> x1 >> y1 >> x2 >> y2 >> X >> Y;
  if( (x1==X && y1==Y) || (x2==X && y2==Y) )return 0;
  int cnt = check(x1,y1,X,Y) + check(x2,y2,X,Y);
  if(cnt)return 3-cnt;

  if(check(x1,y1,x2,y2))return 3;
  for(int d1=0;d1<4;d1++){
    for(int d2=0;d2<4;d2++){
      pair<int,int> p = line_cp(d1,x1,y1,d2,x2,y2);
      if(p.fs!=INF && check(p.fs, p.sc, X,Y))return 3;
    }
  }
  return 4;
}

int main(){
  int n; cin >> n;
  for(int i=1;i<=n;i++){
    cout << solve(i) << endl;
  }
}

Measured memory_bytes: 1160
n,m,s,t=map(int,input().split())
edge=[[] for i in range(n+1)]
edge2=[[] for i in range(n+1)]
for i in range(m):
    a,b,c,d=map(int,input().split())
    edge[a].append((b,c))
    edge[b].append((a,c))
    edge2[a].append((b,d))
    edge2[b].append((a,d))
from heapq import *
def dijkstra(s,n):
    d = [float('inf') for i in range(n+1)]
    pq = []
    d[s]=0
    heappush(pq,(0,s))
    while pq:
        dist,u = heappop(pq)
        for v,cost in edge[u]:
            if d[v]<=dist+cost:
                continue
            d[v]=dist+cost
            heappush(pq,(d[v],v))
    return d
ds=dijkstra(s,n)
edge=edge2
dt=dijkstra(t,n)
ans=[10**15 for i in range(n+1)]
for i in range(n):
    ans[i]=ds[i+1]+dt[i+1]
for i in range(n-1,-1,-1):
    ans[i]=min(ans[i],ans[i+1])
for i in range(n):
    print(10**15-ans[i])

Measured memory_bytes: 73644
import java.util.List;
import java.util.Scanner;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Set;
import java.util.Map;
import java.util.HashMap;
import javax.swing.text.DefaultStyledDocument.ElementSpec;

import java.util.HashSet;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long sum = 0;
        for (int i = 0; i < n; i++) {

            sum += i + 1;
        }

        sum -= n;
        System.out.println(sum);
    }
}

Measured memory_bytes: 23252
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp88 {
    class Program {
        static void Main(string[] args) {
            var st = Console.ReadLine().Split().Select(long.Parse).ToArray();
            long N = st[0];
            long M = st[1];

            var A = new long[N];
            var B = new long[N];

            var tupleList = new List<Tuple<long, long>>();

            for (int i = 0; i < N; i++) {
                var x = Console.ReadLine().Split().Select(long.Parse).ToArray();

                A[i] = x[0];
                B[i] = x[1];

                tupleList.Add(new Tuple<long, long>(A[i], B[i]));
            }

            tupleList.Sort((a, b) => a.Item1.CompareTo(b.Item1));

            //これまでに買った本数
            long num = 0;
            //あと何本？
            long remain = M;

            //今何番目に安いやつを買っているか
            int buyIndex = 0;

            //これまでに買った金額
            long ans = 0;

            while (num < M) {
                remain = M - num;
                if (tupleList[buyIndex].Item2 >= remain) {
                    ans += tupleList[buyIndex].Item1 * remain;
                    num += remain;
                } else {
                    ans += tupleList[buyIndex].Item1 * tupleList[buyIndex].Item2;
                    num += tupleList[buyIndex].Item2;
                }
                buyIndex++;
            }

            Console.WriteLine(ans);
        }
    }
}

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

using namespace std;

#define YES cout << "YES" << endl;
#define NO  cout << "NO"  << endl;
#define Yes cout << "Yes" << endl;
#define No  cout << "No"  << endl;
 
#define INF INT_MAX
#define MOD 1000000007
#define PI  acos(-1)

using ll  = long long;
using ull = unsigned long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rrep(i, n) for (ll i = (n)-1; i >= 0; i--)

int main(int argc, char *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    ll N;
    cin >> N;

    vector<ll> H(N);
    rep (i, N) {
        cin >> H[i];
    }

    ll ans = 0;
    ll tmp = 0;
    rep (i, N-1) {
        if (H[i] < H[i+1]) {
            tmp = 0;
        } else {
            tmp++;
        }
        ans = max(tmp, ans);
    }

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

Measured memory_bytes: 1024
N = int(input())


for a in range(1,3501):
    for b in range(1,3501):
        if (4*a*b - a*N - b*N) > 0:
            c = (a*b*N) // (4*a*b - a*N - b*N)
        else:
            continue
        if c != 0 and 4/N == (1/a + 1/b + 1/c):
            print(a,b,c)
            exit()

Measured memory_bytes: 3064
#include<cstdio>
#include<algorithm>
#include<vector>
#include<string>
#include<iostream>

using namespace std;

#define rep(i,n) for(int i=0;i<int(n);i++)
#define reps(i,n) for(int i=1;i<=int(n);i++)

int main(){
	int mini[2]={3333,3333};
	for(int i=0;i<5;i++){
		int a;
		cin>>a;
		mini[i/3]=min(mini[i/3],a);
	}
	
	printf("%d\n",mini[0]+mini[1]-50);
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
#define rep(i, n) for(int i=0;i<(n);++i)
#define per(i, n) for(int i=(n)-1;i>=0;--i)
#define repa(i, n) for(int i=1;i<(n);++i)
#define foreach(i, n) for(auto &i:(n))
#define pii pair<int, int>
#define pll pair<long long, long long>
#define all(x) (x).begin(), (x).end()
#define bit(x) (1ll << (x))
using ll = long long;
//const ll MOD = (ll)1e9+7;
const ll MOD = 998244353;
const int INF = (ll)1e9+7;
const ll INFLL = (ll)1e18;
using namespace std;
template<class t>
using vvector = vector<vector<t>>;
template<class t>
using vvvector = vector<vector<vector<t>>>;
template<class t>
using priority_queuer = priority_queue<t, vector<t>, greater<t>>;
template<class t, class u> bool chmax(t &a, u b){if(a<b){a=b;return true;}return false;}
template<class t, class u> bool chmin(t &a, u b){if(a>b){a=b;return true;}return false;}
#ifdef DEBUG
#define OUTPUT(x) (output(x), output("\n"))
#else
#define OUTPUT(x) (void)0
#endif

ll modpow(ll x, ll b){
    ll res = 1;
    while(b){
        if(b&1)res = res * x % MOD;
        x = x * x % MOD;
        b>>=1;
    }
    return res;
}

ll modinv(ll x){
    return modpow(x, MOD-2);
}

bool was_output = false;
template<class t>
void output(t a){
    if(was_output)cout << " ";
    cout << a;
    was_output = true;
}
void outendl(){
    was_output = false;
    cout << endl;
}
ll in(){
    ll res;
    scanf("%lld", &res);
    return res;
}

template<class t>
istream& operator>>(istream& is, vector<t> &x){
    for(auto &i:x)is >> i;
    return is;
}

template<class t, class u>
istream& operator>>(istream& is, pair<t, u> x){
    is >> x.first >> x.second;
    return is;
}


int main(){
    vector<int> nums(9);
    cin >> nums;
    int n;
    cin >> n;
    set<int> s;
    rep(i,n){
        s.insert(in());
    }
    int checker[8][3]=
    {{0,1,2},
        {3,4,5},
        {6,7,8},
        {0,3,6},
        {1,4,7},
        {2,5,8},
        {0,4,8},
        {2,4,6}};
    rep(i,8){
        bool flag = true;
        rep(j,3){
            if(!s.count(nums[checker[i][j]])){
                flag = false;
                break;
            }
        }
        if(flag){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
import kotlin.math.max

fun main(args: Array<String>) {
    val (n, t) = readLine()!!.split(" ").map { it.toInt() }.let { Pair(it[0], it[1]) }
    val ab = (1 .. n).map {
        readLine()!!.split(" ").map { it.toInt() }.let { Pair(it[0], it[1]) }
    }.sortedBy {
        it.first
    }
    var dp = IntArray(t) { if (it == t - 1) 0 else -1 }
    var ret = 0
    for ((a, b) in ab) {
        val newdp = dp.toMutableList()
        for (j in 0 .. t - 1) {
            if (dp[j] >= 0) {
                ret = max(ret, dp[j] + b)
                if (j - a >= 0) {
                    newdp[j - a] = max(newdp[j - a], dp[j] + b)
                }
            }
        }
        dp = newdp.toIntArray()
    }
    println(ret)
}


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

//累積和で→Eの数をカウント
int main() {
   int n;
   string s;
   cin>>n>>s;
   vector<int> rui(n);
   if(s[0]=='E')rui[0]=1;
   rep(i,n-1){
       if(s[i+1]=='E')rui[i+1]=rui[i]+1;
       else rui[i+1]=rui[i];
   }
   
   int ans=n+1;
   rep(i,n){
       if(s[i]=='E'){
           ans=min(ans,i-(rui[i]-1)+(rui[n-1]-rui[i]));
       }
       else{
           ans=min(ans,i-rui[i]+(rui[n-1]-rui[i]));
       }
   }
   cout<<ans<<endl;
}

Measured memory_bytes: 1796
#include<stdio.h>
int main()
{
    int a, b, c;
    int tmp;
 
    scanf("%d%d%d", &a, &b, &c);
    if (a > b) tmp = a, a = b, b = tmp;
    if (b > c) tmp = b, b = c, c = tmp;
    if (a > b) tmp = a, a = b, b = tmp;
    printf("%d %d %d\n", a, b, c);
    return 0;
}


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

int dp[3005][3005];

int main() {
    int N, T; cin >> N >> T;
    vector<P> sushi(N);
    rep(i, N){
        cin >> sushi[i].first >> sushi[i].second;
    }
    sort(sushi.begin(), sushi.end());

    rep(i, N){
        rep(j, T){
            dp[i+1][j] = dp[i][j];
            if(j-sushi[i].first >= 0 && j-sushi[i].first < T){
                dp[i+1][j] = max(dp[i+1][j], dp[i][j-sushi[i].first] + sushi[i].second);
            }
        }
    }

    int ans = 0;
    rep(i, N){
        ans = max(ans, dp[i][T-1] + sushi[i].second);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 38824
import java.io.*;
import java.util.*;


public class Main{
    public static void main(String[] args) {
        MyScanner sc = new MyScanner();
        out = new PrintWriter(new BufferedOutputStream(System.out));

        // Start writing your solution here. -------------------------------------
      /*
      int n      = sc.nextInt();        // read input as integer
      long k     = sc.nextLong();       // read input as long
      double d   = sc.nextDouble();     // read input as double
      String str = sc.next();           // read input as String
      String s   = sc.nextLine();       // read whole line as String

      int result = 3*n;
      out.println(result);                    // print via PrintWriter
      */
        // Stop writing your solution here. -------------------------------------
        int n = sc.nextInt();
        if (n % 1000 == 0) {
            out.println(0);
        } else {
            out.println((((n / 1000) + 1) * 1000) - n);
        }
        out.close();
    }



    //-----------PrintWriter for faster output---------------------------------
    public static PrintWriter out;

    //-----------MyScanner class for faster input----------
    public static class MyScanner {
        BufferedReader br;
        StringTokenizer st;

        public MyScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

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

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

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

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

        String nextLine(){
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }

    }
    //--------------------------------------------------------
}

Measured memory_bytes: 32780
using System;
using System.Linq;

namespace abc089_d
{
	class Program
	{
		static void Main(string[] args)
		{
			int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray();
			Tuple<int, int>[] where = new Tuple<int, int>[x[0] * x[1] + 1];
			for (int i = 0; i < x[0]; i++)
			{
				int[] a = Console.ReadLine().Split().Select(int.Parse).ToArray();
				for (int j = 0; j < x[1]; j++)
				{
					where[a[j]] = new Tuple<int, int>(i, j);
				}
			}
			int[] sum = new int[x[0] * x[1] + 1];
			for (int i = x[2] + 1; i <= x[0] * x[1]; i++)//search num
			{
				sum[i] = sum[i - x[2]] +
					Math.Abs(where[i].Item1 - where[i - x[2]].Item1) +
					Math.Abs(where[i].Item2 - where[i - x[2]].Item2);
			}
			int n = int.Parse(Console.ReadLine());
			for (int i = 0; i < n; i++)
			{
				int[] a = Console.ReadLine().Split().Select(int.Parse).ToArray();
				Console.WriteLine(sum[a[1]] - sum[a[0]]);
			}
		}
	}
}

Measured memory_bytes: 23348
def judge(S):
    cursor = 0
    len_S = len(S)
    
    while cursor < len_S:
        next_str = S[cursor:cursor+8]
        if next_str[:] == "dreamera":
            cursor += 5
        elif next_str[:7] == "dreamer":
            cursor += 7
        elif next_str[:6] == "eraser":
            cursor += 6
        elif (next_str[:5] == "dream") or (next_str[:5] == "erase"):
            cursor += 5
        else:
            return False
        
    if cursor != len_S:
        return False
    
    return True

S = input()

if judge(S):
    print("YES")
else:
    print("NO")

Measured memory_bytes: 3316
#include <iostream>
using namespace std;
int main(void)
{
	int n, m;
	int a[1001];
	while (cin >> n >> m) {
		if (n == 0 && m == 0)	break;
		for (int i = 0; i < n; i++) {
			cin >> a[i];
		}
		int max = 0;
		int x;
		for (int i = 0; i < n; i++) {
			for (int j = i + 1; j < n; j++) {
				x = a[i] + a[j];
				if (x > max && x <= m)	max = x;
			}
		}
		if (max == 0) {
			cout << "NONE" << endl;
		}
		else {
			cout << max << endl;
		}
	}


	return 0;
}


Measured memory_bytes: 3072
import java.util.*; import java.io.*; import java.math.*;
public class Main{
	//Don't have to see. start------------------------------------------
	static class InputIterator{
		ArrayList<String> inputLine = new ArrayList<String>(1024);
		int index = 0; int max; String read;
		InputIterator(){
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
			try{
				while((read = br.readLine()) != null){
					inputLine.add(read);
				}
			}catch(IOException e){}
			max = inputLine.size();
		}
		boolean hasNext(){return (index < max);}
		String next(){
			if(hasNext()){
				return inputLine.get(index++);
			}else{
				throw new IndexOutOfBoundsException("There is no more input");
			}
		}
	}
	static HashMap<Integer, String> CONVSTR = new HashMap<Integer, String>();
	static InputIterator ii = new InputIterator();//This class cannot be used in reactive problem.
	static PrintWriter out = new PrintWriter(System.out);
	static void flush(){out.flush();}
	static void myout(Object t){out.println(t);}
	static void myerr(Object t){System.err.print("debug:");System.err.println(t);}
	static String next(){return ii.next();}
	static boolean hasNext(){return ii.hasNext();}
	static int nextInt(){return Integer.parseInt(next());}
	static long nextLong(){return Long.parseLong(next());}
	static double nextDouble(){return Double.parseDouble(next());}
	static ArrayList<String> nextStrArray(){return myconv(next(), 8);}
	static ArrayList<String> nextCharArray(){return myconv(next(), 0);}
	static ArrayList<Integer> nextIntArray(){
		ArrayList<String> input = nextStrArray(); ArrayList<Integer> ret = new ArrayList<Integer>(input.size());
		for(int i = 0; i < input.size(); i++){
			ret.add(Integer.parseInt(input.get(i)));
		}
		return ret;
	}
	static ArrayList<Long> nextLongArray(){
		ArrayList<String> input = nextStrArray(); ArrayList<Long> ret = new ArrayList<Long>(input.size());
		for(int i = 0; i < input.size(); i++){
			ret.add(Long.parseLong(input.get(i)));
		}
		return ret;
	}
	static String myconv(Object list, int no){//only join
		String joinString = CONVSTR.get(no);
		if(list instanceof String[]){
			return String.join(joinString, (String[])list);
		}else if(list instanceof ArrayList){
			return String.join(joinString, (ArrayList)list);
		}else{
			throw new ClassCastException("Don't join");
		}
	}
	static ArrayList<String> myconv(String str, int no){//only split
		String splitString = CONVSTR.get(no);
		return new ArrayList<String>(Arrays.asList(str.split(splitString)));
	}
	public static void main(String[] args){
		CONVSTR.put(8, " "); CONVSTR.put(9, "\n"); CONVSTR.put(0, "");
		solve();flush();
	}
	//Don't have to see. end------------------------------------------
	static void solve(){//Here is the main function
		ArrayList<String> one = nextStrArray();
		ArrayList<String> A = myconv(one.get(0), 0);
		ArrayList<String> B = myconv(one.get(1), 0);
		ArrayList<String> C = myconv(one.get(2), 0);
		if(A.get(A.size() - 1).equals(B.get(0)) && B.get(B.size() - 1).equals(C.get(0))){
			myout("YES");
		}else{
			myout("NO");
		}
	}
	//Method addition frame start



	//Method addition frame end
}


Measured memory_bytes: 25356
import math
from functools import reduce

def main():
    k = int(input())
    ans = 0
    ary = []
    for i in range(1,k+1):
        for j in range(1,k+1):
            ary.append(math.gcd(i,j))
    for i, aa in enumerate(ary):
        for j in range(1,k+1):
            ans += math.gcd(aa,j)
    print(ans)


def gcd(*numbers):
    return reduce(math.gcd, numbers)

def gcd_list(numbers):
    return reduce(math.gcd, numbers)

if __name__=='__main__':
    main()


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

using namespace std;

const int MAX = 2 * 1000 * 100 + 11;
int parent[MAX];
int sizeOfSet[MAX];
int n, m;

void make_set(int node) {
	parent[node] = node;
	sizeOfSet[node] = 1;
}

int find_set(int node) {
	if(node == parent[node]) {
		return node;
	}
	
	return parent[node] = find_set(parent[node]);
}

void union_sets(int firstNode, int secondNode) {
	int parentOfFirstNode = find_set(firstNode);
	int parentOfSecondNode = find_set(secondNode);
	
	if(parentOfFirstNode != parentOfSecondNode) {
		if(sizeOfSet[parentOfFirstNode] < sizeOfSet[parentOfSecondNode])
			swap(parentOfFirstNode, parentOfSecondNode);
			
		parent[parentOfSecondNode] = parentOfFirstNode;
		
		sizeOfSet[parentOfFirstNode] += sizeOfSet[parentOfSecondNode];
	}
}


int main()
{
	int n; cin >> n;
	for(int i = 1; i <= n; i++)
	{
		make_set(i);
	}
	
	int t; cin >> t;
	while(t--)
	{
		int a, b, c;
		cin >> a >> b >> c;
		if(a == 0)
		{
			union_sets(b + 1, c + 1);
		}
		else
		{
			if(find_set(b+1) == find_set(c+1))
			{
				cout << '1' << endl;
			}
			else
			{
				cout << '0' << endl;
			}
		}
	}
	return 0;
}


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

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

    string s,t;
    // sliding window
    cin >> s >> t;
    int n = s.size(), m=t.size();
    int mCur=1e9+7;
    for (int i = 0; i < n-m+1; i++) {
        int cur = 0;
        for (int j = 0; j < m; j++) {
            if (s[i+j]!=t[j]) cur++;
        }
        mCur = min(mCur, cur);
    }
    cout << mCur << endl;

    return 0;
}


Measured memory_bytes: 3656
use std::io::{stdin, Read, StdinLock};
use std::str::FromStr;
use std::cmp;

struct Scanner<'a> {
    cin : StdinLock<'a>,
}

impl<'a> Scanner<'a> {
    fn new(cin : StdinLock<'a>) -> Scanner<'a> {
        Scanner { cin: cin }
    }

    fn read1<T: FromStr>(&mut self) -> Option<T> {
        let token = self.cin.by_ref().bytes().map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        token.parse::<T>().ok()
    }

    fn read<T: FromStr>(&mut self) -> T {
        self.read1().unwrap()
    }
}

fn main(){
    loop{
        let cin = stdin();
        let cin = cin.lock();
        let mut sc = Scanner::new(cin);
        let d : i32 = sc.read();
        let e : i32 = sc.read();
        if d == 0 { break; }
        let mut ans : f64 = 1e9;
        for i in 0..d+1 {
            let j = d - i;
            ans = ans.min((((i*i + j*j) as f64).sqrt() - (e as f64)).abs());
        }
        println!("{}", ans);
    }
}




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

using namespace std;
typedef long long int ll;
typedef pair<ll, ll > pi;  
typedef pair<pair<ll, ll >, ll > pii;  
vector<ll > vec;
vector<vector<ll > > vec2;
ll MOD = 1000000007;

ll dx[4] = {-1, 1, 0, 0};
ll dy[4] = { 0, 0,-1, 1};

int main(){

    ll H, W;
    cin >> H >> W;
    
    //map<pair<ll, ll >, ll> mp;
    queue<pair<ll, ll > > que;
    //距離格納
    vector<vector<ll > > ans(H, vector<ll >(W, -114514));

    for(ll y = 0; y < H; y++){
        string s; cin >> s;
        for(ll x = 0; x < W; x++){
            if(s[x] == '#'){
                que.push(make_pair(y, x));
                ans[y][x] = 0;
                //mp[make_pair(i, j)] = 1;
            }    
        }
    }

    //黒点から広げて距離を出していく(これはもうBFS)
    while(!que.empty()){
        ll x = que.front().second;
        ll y = que.front().first;
        que.pop();
        for(ll d = 0; d < 4; d++){
            if(x+dx[d] < W && x+dx[d] >= 0 && y+dy[d] < H && y+dy[d] >= 0){
                //何も更新されていないマスだったら
                if(ans[y+dy[d]][x+dx[d]] == -114514){
                    que.push(make_pair(y+dy[d], x+dx[d]));
                    ans[y+dy[d]][x+dx[d]] = ans[y][x] + 1;
                }
            }

        }
    }

    ll mx_dist = 0;
    for(ll y = 0; y < H; y++){
        for(ll x = 0; x < W; x++){
            //cout << ans[y][x] << endl;
            mx_dist = max(mx_dist, ans[y][x]);
        }
    }    

    cout << mx_dist << endl;

}

Measured memory_bytes: 24500
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int m, f, r;

        while (true) {
            m = sc.nextInt();
            f = sc.nextInt();
            r = sc.nextInt();

            if (m == -1 && f == -1 && r == -1) break;

            if (m == -1 || f == -1) {
                System.out.println("F");
            } else if (m + f >= 80) {
                System.out.println("A");
            } else if (m + f >= 65) {
                System.out.println("B");
            } else if (m + f >= 50) {
                System.out.println("C");
            } else if (m + f >= 30) {
                if (r >= 50) {
                    System.out.println("C");
                } else {
                    System.out.println("D");
                }
            } else {
                System.out.println("F");
            }
        }
    }
}


Measured memory_bytes: 26324
#include<stdio.h>

int main(void){
  int A,B,C,D,E,F;
  int ans_w=0,ans_s=0;
  
  scanf("%d %d %d %d %d %d",&A,&B,&C,&D,&E,&F);

  for(int i=0;100*A*i<=F;i++){
    for(int j=0;100*A*i+100*B*j<=F;j++){
      int x = 100*A*i+100*B*j;

      for(int k=0;x+C*k<=F;k++){
        for(int l=0;x+C*k+D*l<=F;l++){
          int y = C*k+D*l;

          if(x*E >= 100*y && F >= x+y){
            if(ans_w*y >= ans_s*(x+y)){
              ans_w = x+y;
              ans_s = y;
            }
          }
        }
      }
    }
  }
  printf("%d %d\n",ans_w,ans_s);
  
  return 0;
}

Measured memory_bytes: 128
h,w=map(int,raw_input().split())
n=input()
s=raw_input().split()
a=[0 for i in range(n)]
ans=[]
for i in range(n):
    a[i]=int(s[i])
    for j in range(a[i]):
        ans.append(i+1)

p=0
for i in range(h):
    if i%2==0:
        for j in range(i*w,i*w+w):
            print ans[j],
    else:
        for j in range(i*w+w-1,i*w-1,-1):
            print ans[j],
    print


Measured memory_bytes: 33768
#include <cstdio>
#include <iostream>
#include <string>
#include <stack>
#include <cmath>

#define loop(i,a,b) for(int i = a; i < b; i++)
#define rep(i,a) loop(i,0,a)
using namespace std;


int main(void){
  int N;cin>>N;

  int M = 0;
  int ans = 0;
  rep(i,N){
      int tmp;cin>>tmp;
      ans += tmp;
      if(tmp > M){
          M = tmp;
      }
  }
  cout<<(ans-M/2)<<endl;
    
  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<iostream>
using namespace std;
int p[30],ans;
void change(int x){
    if(p[0]==p[1]&&p[1]==p[2]&&p[2]==p[3]&&p[3]==p[4]&&p[4]==p[5]&&p[5]==p[6]&&p[6]==p[7]&&p[7]==p[8]&&p[18]==p[19]&&p[19]==p[20]&&p[15]==p[16]&&p[16]==p[17])ans=min(ans,x);
    if(x==8)return;
    swap(p[0],p[23]),swap(p[3],p[26]),swap(p[6],p[29]),swap(p[9],p[20]),swap(p[15],p[17]);
    change(x+1);
    swap(p[0],p[23]),swap(p[3],p[26]),swap(p[6],p[29]),swap(p[9],p[20]),swap(p[15],p[17]);
    swap(p[2],p[21]),swap(p[5],p[24]),swap(p[8],p[27]),swap(p[11],p[18]),swap(p[12],p[14]);
    change(x+1);
    swap(p[2],p[21]),swap(p[5],p[24]),swap(p[8],p[27]),swap(p[11],p[18]),swap(p[12],p[14]);
    swap(p[0],p[27]),swap(p[1],p[28]),swap(p[2],p[29]),swap(p[14],p[15]),swap(p[18],p[20]);
    change(x+1);
    swap(p[0],p[27]),swap(p[1],p[28]),swap(p[2],p[29]),swap(p[14],p[15]),swap(p[18],p[20]);
    swap(p[6],p[21]),swap(p[7],p[22]),swap(p[8],p[23]),swap(p[12],p[17]),swap(p[9],p[11]);
    change(x+1);
    swap(p[6],p[21]),swap(p[7],p[22]),swap(p[8],p[23]),swap(p[12],p[17]),swap(p[9],p[11]);
}
int main(){
    int N;
    cin>>N;
    for(int i=0;i<N;i++){
        for(int j=0;j<30;j++)cin>>p[j];
        ans=8;
        change(0);
        cout<<ans<<endl;
    }
    return 0;
}

Measured memory_bytes: 1164
#include <stdio.h>
#include <math.h>

typedef struct {
  double x;
  double y;
} Point;

double calcTriangelArea(Point p1, Point p2, Point p3) {
  return fabs(p1.x * (p2.y - p3.y) + p2.x * (p3.y - p1.y) + p3.x * (p1.y - p2.y)) / 2;
}

int main(void) {
  Point p1, p2, p3, p;
  double tri, tri1, tri2, tri3;

  while (scanf("%lf %lf %lf %lf %lf %lf %lf %lf", &p1.x, &p1.y, &p2.x, &p2.y, &p3.x, &p3.y, &p.x, &p.y) != EOF) {
    tri = calcTriangelArea(p1, p2, p3);
    tri1 = calcTriangelArea(p, p1, p2);
    tri2 = calcTriangelArea(p, p2, p3);
    tri3 = calcTriangelArea(p, p3, p1);

    if (tri == tri1 + tri2 + tri3)
      printf("YES\n");
    else
      printf("NO\n");
  }

  return 0;
}

Measured memory_bytes: 612
import java.io.*;
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
//        sc.useDelimiter(",");
//        DecimalFormat df = new DecimalFormat("0.00000000");
        int a = Integer.parseInt(sc.next());
        int b = Integer.parseInt(sc.next());
        int c = Integer.parseInt(sc.next());
        boolean isPoor = false;
        if ((a == b && a != c)
                || (a == c && a != b)
                || (b == c && a != b)) {
            isPoor = true;
        }
        out.println(isPoor ? "Yes" : "No");
        out.flush();
    }
}

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

#define ll long long
#define vi vector<int>
#define vl vector<long long>
#define pb push_back
#define si set<int>
#define sl set<long long>
#define pq prioirty_queue
#define all(v) v.begin(),v.end()
#define left (2*idx)+1
#define right (2*idx)+2
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);

const ll N = (ll)(1e5 + 7);
const ll MOD = (ll)(1e9 + 7);

int main()
{
    FIO;

    int n;
    cin >> n;

    map<string, ll> m;
    ll ans = 0;

    for(int i=0; i<n; i++)
    {	
    	string s;
    	cin >> s;
    	sort(all(s));
    	ans += m[s];
    	m[s]+=1;
    }

    cout << ans << "\n";
}


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


int main (void){
  int i;
  int n,m;
  int *arr;
  int all=0;
  
  if( scanf("%d %d",&n,&m) == 2){
    arr = (int*)calloc(m,sizeof(int));
    for(i=0; i<m; i++){
      scanf("%d",&arr[i]);
    }
    for(i=0; i<m; i++) all += arr[i];
    if (n >= all) printf("%d\n",n-all);
    else printf("-1\n"); 
    free(arr);
  }
  return 0;
}


Measured memory_bytes: 1744
n, m, q = map(int, input().split())
conditions = [list(map(int, input().split())) for _ in range(q)]

max_points = 0
def dfs(ary):
    global max_points

    if len(ary) == n:
        points = 0
        for c in conditions:
            if ary[c[1] - 1] - ary[c[0] - 1] == c[2]:
                points += c[3]
        max_points = max(max_points, points)
        return
    
    if len(ary) == 0:
        minimum = 1
    else:
        minimum = ary[-1]

    for i in range(minimum, m+1):
        ary.append(i)
        dfs(ary)
        ary.pop(-1)

dfs([])
print(max_points)

Measured memory_bytes: 73140
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<ll,ll>;
const ll mod = 1e9+7;
#define ALL(x) (x).begin(),(x).end()
#define pow(x,y) modpow(x,y)
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define REPS(i,n) for(ll (i)=1;(i)<=(n);(i)++)
#define RREP(i,n) for(ll (i)=(n-1);(i)>=0;(i)--)
#define RREPS(i,n) for(ll (i)=(n);(i)>0;(i)--)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());

template<class T> inline void chmin(T& a, T b){
    if (a > b){
        a = b;
    }
}

template<class T> inline void chmax(T& a, T b){
    if (a < b){
        a = b;
    }
}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(10);
    int ha,hi;
    int ma,mi,K;
    cin >> ha >> ma >> hi >> mi >> K;
    cout << hi*60 + mi - ha*60 - ma - K << "\n";
}

Measured memory_bytes: 3652
import java.util.*;

public class Main {

    public static void main(String[] args) {
        // write your code here
        Scanner scanner = new Scanner(System.in);
        int h = scanner.nextInt();
        int w = scanner.nextInt();

        char[][] array = new char[h][];
        Arrays.setAll(array, i -> scanner.next().toCharArray());

        int[][] l = new int[h][w];
        int[][] r = new int[h][w];
        int[][] u = new int[h][w];
        int[][] d = new int[h][w];

        // 左メモ
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                if (array[i][j] == '#') {
                    l[i][j] = 0;
                } else if (j == 0) {
                    l[i][j] = 1;
                } else {
                    l[i][j] = l[i][j - 1] + 1;
                }
            }
        }

        // 右メモ
        for (int i = 0; i < h; i++) {
            for (int j = w - 1; j >= 0; j--) {
                if (array[i][j] == '#') {
                    r[i][j] = 0;
                } else if (j == w - 1) {
                    r[i][j] = 1;
                } else {
                    r[i][j] = r[i][j + 1] + 1;
                }
            }
        }

        // 上メモ
        for (int i = 0; i < w; i++) {
            for (int j = 0; j < h; j++) {
                if (array[j][i] == '#') {
                    u[j][i] = 0;
                } else if (j == 0) {
                    u[j][i] = 1;
                } else {
                    u[j][i] = u[j - 1][i] + 1;
                }
            }
        }

        // 下メモ
        for (int i = 0; i < w; i++) {
            for (int j = h - 1; j >= 0; j--) {
                if (array[j][i] == '#') {
                    d[j][i] = 0;
                } else if (j == h - 1) {
                    d[j][i] = 1;
                } else {
                    d[j][i] = d[j + 1][i] + 1;
                }
            }
        }

        int ans = 0;

        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                ans = Math.max(ans, u[i][j] + d[i][j] + l[i][j] + r[i][j] - 3);
            }
        }

        System.out.println(ans);
    }
}

Measured memory_bytes: 110564
#include<bits/stdc++.h>
using namespace std;
double n,ans;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> n;
	ans=(n/3.0)*(n/3.0)*(n/3.0);
	printf("%.12lf",ans);
	return 0;
}

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

int main(){
    ll x,y;
    cin>>x>>y;
    ll ans=0;
    while(x<=y){
        x*=2;
        ans++;
    }
    cout<<ans<<endl;
}


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

int main()
{
    int n, a;
    cin >> n;
    cin >> a;
    if (n % 500 > a)
    {
        std::cout << "No" << std::endl;
    }
    else
    {
        std::cout << "Yes" << std::endl;
    }
}

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

using ll = long long;

template<typename T>
T gcd(T a, T b)
{
	if (a < b)	return gcd(b, a);
	T r;
	while ((r = a % b))
	{
		a = b;
		b = r;
	}
	return b;
}

template<typename T>
T lcm(T a, T b)
{
	return a * b / gcd(a, b);
}

template<typename T>
T ext_gcd(T a, T b, T& x, T& y)
{
	x = 1;
	y = 0;
	T x0 = 0, y0 = 1;
	while (b != 0)
	{
		T q = a / b;
		a -= q * b;
		swap(a, b);
		x -= q * x0;
		swap(x, x0);
		y -= q * y0;
		swap(y, y0);
	}
	return a;
}

template<typename T>
T inv_mod(T a, T mod)
{
	T t1, t2;
	ext_gcd(a, mod, t1, t2);
	t1 %= mod;
	if (t1 < 0)		t1 += mod;
	return t1;
}

template<typename T>
T combination_large(T n, T k, T mod)
{
	if (n < k || n < 0 || k < 0)	return 0;
	vector<T> inv(n + 1, 1), fact(n + 1, 1), fact_inv(n + 1, 1);
	for (T i = 2; i <= n; ++i)
	{
		inv[i] = mod - inv[mod % i] * (mod / i) % mod;
		fact[i] = (fact[i - 1] * i) % mod;
		fact_inv[i] = fact_inv[i - 1] * inv[i] % mod;
	}
	return fact[n] * (fact_inv[k] * fact_inv[n - k] % mod) % mod;
}

template<typename T>
T combination(T n, T k, T mod = 1)
{
	vector<vector<T>> table(n + 1, vector<T>(k + 1, 1));
	for (T i = 1; i <= n; ++i)
	{
		table[i][0] = 1;
		for (T j = 1; j <= n; ++j)
		{
			table[i][j] = (table[i - 1][j - 1] + table[i - 1][j]) % mod;
		}
	}
}

int main(int, char**)
{
	int a, b, c;
	cin >> a >> b >> c;
	cout << (a + b + c >= 22 ? "bust" : "win") << endl;
	return 0;
}


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

int main(void)
{
    ll N, K;
    cin >> N >> K;
    vector<int> A(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }

    ll c1 = 0;
    ll c2 = 0;
    ll count = 0;
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            if (A[i] > A[j]) {
                if (i < j) {
                        c1++;
                }
                c2++;
            }
        }
        c1 %= mod;
        c2 %= mod;
    }
    count += c1*K % mod;
    count %= mod;
    count += c2*(((K*K-K)/2)%mod) % mod;
    count %= mod;
    cout << count << endl;

    return 0;
}



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

using namespace std;



int main(){
	string ss;
	list<char> s;
	int q,t,f;
	char c;
	bool re=false;


	cin >> ss >> q;

	for (auto x : ss) s.push_back(x);

	for (int i=0; i < q ; i++) {
		cin >> t;
		if (t == 2){
			cin >> f >> c;
			if ((f == 1 && !re) || (f == 2 && re)) {
				s.push_front(c);
			}
			else{
				s.push_back(c);
			}
		}
		else{
//			cout << (re?"o":"x") << endl;
			if (re) re=false;
			else re = true;
		}
	}

	if (re) {
		while(!s.empty()){
			cout << s.back() ;
			s.pop_back();
		}
	}
	else{
		while(!s.empty()){
			cout << s.front() ;
			s.pop_front();
		}	
	}
	
	cout << endl;
	cin >> q;
	return 0;

	
}

//x=100/8*a
//x=10b

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

typedef long long ll;

ll f(ll x){
	if(x == 1) return 1;
	return 2ll * f(x/2) + 1;
}

ll n;

int main(){
	cin >> n;
	cout << f(n) << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

int main(){
  string s;
  cin >> s;
  s.at(5) = s.at(13) = ' ';
  cout << s << endl;
  return 0;
}

Measured memory_bytes: 3540
#include <bits/stdc++.h>
using namespace std;
#define PII pair<int, int>
#define VI vector<int>
#define VPII vector<PII>
#define LL long long
#define LD long double
#define f first
#define s second
#define MP make_pair
#define PB push_back
#define endl '\n'
#define ALL(c) (c).begin(), (c).end()
#define SIZ(c) (int)(c).size()
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, b, e) for(int i = (b); i <= (int)(e); ++i)
#define FORD(i, b, e) for(int i = (b); i >= (int)(e); --i)

#define sim template<class n
sim, class s> ostream & operator << (ostream &p, pair<n, s> x)
{return p << "<" << x.f << ", " << x.s << ">";}
sim> auto operator << (ostream &p, n y) ->
typename enable_if<!is_same<n, string>::value, decltype(y.begin(), p)>::type 
{int o = 0; p << "{"; for(auto c: y) {if(o++) p << ", "; p << c;} return p << "}";}
void dor() {cerr << endl;}
sim, class...s> void dor(n p, s...y) {cerr << p << " "; dor(y...);}
sim, class s> void mini(n &p, s y) {if(p>y) p = y;}
sim, class s> void maxi(n &p, s y) {if(p<y) p = y;}
#ifdef DEB
#define debug(...) dor(__FUNCTION__, ":", __LINE__, ": ", __VA_ARGS__)
#else
#define debug(...)
#endif 

#define I(x) #x " =", (x), " "
#define A(a, i) #a "[" #i " =", i, "] =", a[i], " "

int in[11][1004];

int group[11];

int g_sum[11];
int main()
{
  int n, m, k;
  scanf("%d%d%d", &n, &m, &k);
  FOR(i, 1, n)
    FOR(j, 1, m)
      {
      char ch;
      scanf(" %c", &ch);
      in[i][j] = ch - '0';
      }

  int result = 1e9;
  REP(mask, 1 << (n-1))
    {
    int gid = 1;
    REP(i, n)
      {
      group[i+1] = gid;
      if(mask & (1<<i))gid++;
      }

    int res = gid-1;
    FOR(j, 1, m)
      {
      FOR(i, 1, n)
        {
        g_sum[group[i]] += in[i][j];
        }

      bool ok = 1;
      FOR(i, 1, n)
        {
        if(g_sum[i] > k)ok = 0;
        }
      if(ok == 0)
        { 
        res++;
        FOR(i, 1, n)g_sum[i] = 0;
        FOR(i, 1, n)g_sum[group[i]] += in[i][j];

        FOR(i, 1, n)if(g_sum[i] > k)res = 1e9;
        }
      }


    FOR(i, 1, n)g_sum[i] = 0;
    mini(result, res);
    }
  printf("%d\n", result);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int N,K,T,U,V,L;
bool mp[10010];
 
int main(){
  cin>>N>>K>>T>>U>>V>>L;
  int cnt=0;
  for(int i=0,a,A;i<N;i++){
    cin>>a;
    A=a;
    while(mp[a])a++;
    while((1.0*a-A)/V/T>K)a--;
    for(int j=a;j<L&&j<a+T*V;j++)cnt+=!mp[j],mp[j]=1;
  }
 
  printf("%.8f\n",(1.0*cnt/V)+(1.0*(L-cnt)/U));
  return 0;
}

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

using i64=int64_t;

#define rep(i,x,y) for(i64 i=i64(x),i##_max_for_repmacro=i64(y); i<i##_max_for_repmacro; ++i)
#define debug(x) #x << "=" << (x)
 
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif
 
const int inf=1.01e9;
const i64 inf64=4.01e18;
const double eps=1e-9;
 
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
        os << v << ",";
    }
    os << "]";
    return os;
}

void solve(){
    int N,M;
    cin >> N >> M;
    
    vector<vector<pair<int,i64>>> graph(N);
    rep(i,0,M){
        int L,R;
        i64 D;
        cin >> L >> R >> D;
        --L;
        --R;
        graph[L].push_back(make_pair(R,D));
        graph[R].push_back(make_pair(L,-D));
    }

    vector<i64> x(N);
    vector<bool> done(N);
    bool ans=true;
    function<void(int)> rec=[&](int u){
        done[u]=true;
        for(auto& edge:graph[u]){
            int v=edge.first;
            i64 d=edge.second;
            if(done[v] and x[u]+d!=x[v]){
                ans=false;
                return;
            }
            if(!done[v]){
                x[v]=x[u]+d;
                rec(v);
            }
        }
    };

    rep(i,0,N) if(!done[i]){
        x[i]=0;
        rec(i);
    }

    if(ans) cout << "Yes" << endl;
    else cout << "No" << endl;
}

int main(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    solve();
    return 0;
}


Measured memory_bytes: 17408
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
int a[114514];
signed main(){
	int n;
	cin>>n;
	rep(i,n)cin>>a[i];
	sort(a,a+n);
	map<int,int>mp;
	rep(i,n)mp[a[i]]++;
	int ans=0;
	for(auto p:mp){
		if(p.second%2==1)ans++;
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 7296
<?php
error_reporting(0);
$stdin = file_get_contents('php://stdin');
$line = explode("\n",$stdin);
$fi = 0;
$cnt = 0;
$list = array();
$key = new stdclass();
foreach($line as $l) {
  if (strlen($l)==0) continue;
  if ($fi == 0) {
    $a = explode(" ",$l);
    $key->A = $a;
    $fi++;
    continue;
  }
  if ($fi > 0) {
    $a = explode(" ",$l);
    $key->X[] = $a;
  }
}
$A = $key->A[0];
$x = array();
foreach($key->X[0] as $k=>$a) {
  $x[]=$a;
}
if ($A==1) {
  printf("%s\n",$A);
  exit;
}
$n=2;
while(1) {
  if (($n  >= $A)||($n * 2 > $A)) break;
  $n = $n * 2;
}
printf("%s\n",$n);


Measured memory_bytes: 3828
#include <bits/stdc++.h>
using namespace std;
#define rep(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(v) v.begin(), v.end()
using ll = long long;
const ll MOD = 1e9+7; ll LLINF = 1LL << 60; int INF = INT_MAX;

//

int main(){
    int n,k; cin>>n>>k;
    vector<int> a(n);
    int one=0;
    rep(i,0,n){
        cin>>a[i];
    }
    cout<<ceil((double)(n-1)/(k-1))<<endl;
}

Measured memory_bytes: 640