akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <numeric>

int main()
{
    long long h{};
    std::cin >> h;

    if (h == 1) {
        std::cout << 1 << std::endl;
        return 0;
    }

    long long count = 0;
    long long tmp = 1;
    while (h > 0) {
        h /= 2;
        count += tmp;
        tmp *= 2;
    }

    std::cout << count << std::endl;

    return 0;
}


Measured memory_bytes: 256
a = list(map(int, input().split()))
b = list(input())
c = b[a[1]-1]

if c == "A":
    b[a[1]-1] = "a"
if c == "B":
    b[a[1]-1] = "b"
if c == "C":
    b[a[1]-1] = "c"

print("".join(b))


Measured memory_bytes: 3060
from statistics import mean, median,variance,stdev
import sys
import math

x = input().split()
#y = input().split()
a = []
for i in range(len(x)):
   a.append(int(x[i]))

a.sort()
if a[0]*a[1] == 25 and a[2]==7:print("YES")
else: print("NO")

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

using namespace std;

typedef long long int ll;
typedef pair<ll, ll> pll;

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    cout << 0 << endl;
    string b;
    cin >> b;
    if (b == "Vacant") {
        return 0;
    }
    ll bi = 0;
    ll ng = N;
    while (true) {
        ll mid = (bi + ng) / 2;
        cout << mid << endl;
        string s;
        cin >> s;
        if (s == "Vacant")
            break;

        ll n = mid - bi + 1;
        if (n % 2 == 0) {
            if (b == s)
                ng = mid;
            else {
                bi = mid;
                b = s;
            }
        }
        else {
            if (b != s)
                ng = mid;
            else {
                bi = mid;
                b = s;
            }
        }
    }
    return 0;
}

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

int main() {
  ll a;
  string sb;
  cin >> a >> sb;
  
  string ans;
  if (sb.size() > 3){
      ans = sb.substr(0,1) + sb.substr(2,3);
  } else {
      ans = sb.substr(0,1) + sb.substr(2,2) + "0";
  }
  int b = std::atoi(ans.c_str());
  cout << a * b / 100 << endl;
}


Measured memory_bytes: 3632
#pragma warning(disable: 4996)
#define _USE_MATH_DEFINES
#include <iostream>
#include <unordered_map>
#include <functional>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <bitset>
#include <set>
using namespace std;

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

	int N;
	string S;
	cin >> N >> S;
	if (S.size() % 2 == 1) cout << "No";
	else {
		int a = S.size() / 2;
		if (S.substr(0, a) == S.substr(a)) cout << "Yes";
		else cout << "No";
	}
	return 0;
}


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

using namespace std;

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

	int red = 0, blue = 0;
	for (int i = 0; i < S.size(); i++){
		if (S[i] == '0'){
			red++;
		} else {
			blue++;
		}
	}

	cout << min(red, blue) * 2 << endl;
	return 0;
}


Measured memory_bytes: 512
import math
from functools import reduce
from collections import deque
import sys
sys.setrecursionlimit(10**7)
import heapq

# スペース区切りの入力を読み込んで数値リストにして返します。
def get_nums_l():
    return [ int(s) for s in input().split(" ")]

# 改行区切りの入力をn行読み込んで数値リストにして返します。
def get_nums_n(n):
    return [ int(input()) for _ in range(n)]

# 改行またはスペース区切りの入力をすべて読み込んでイテレータを返します。
def get_all_int():
    return map(int, open(0).read().split())

def log(*args):
    print("DEBUG:", *args, file=sys.stderr)

n,m = get_nums_l()
aaa = get_nums_l()
h = []

for a in aaa:
    heapq.heappush(h, -1 * a)

for _ in range(m):
    a = heapq.heappop(h)
    heapq.heappush(h, math.ceil(a/2))

print(-1 * sum(h))

Measured memory_bytes: 92628
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
#define rep(i,n) for (ll i = 0; i < (n); i++)
#define repd(i,a,b) for (ll i = (a); i < (b); i++)
#define INF LLONG_MAX
#define mod 1000000007
typedef long long ll;
int main(void)
{
	string S;
	cin >> S;
	rep(i, S.size()) cout << "x";
	cout << endl;
	return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const int INF = 1e9;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, k, s;
    cin >> n >> k >> s;
    rep(i,k) cout << s << " ";
    if(s == INF){
        rep(i,n-k) cout << INF - 1 << " ";
    }
    else{
        rep(i,n-k) cout << s+1 << " ";
    }
    cout << endl;
    return 0;
}

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

int main(){
  string S; cin >> S;
  string T; cin >> T;
  
  vector<int> R(150,-1) , U(150,-1);
  bool OK = true;
  for(int i = 0; i < S.size(); i++){
      int Si = (int)S.at(i);
      int Ti = (int)T.at(i);
      if(R.at(Si) == -1){
          R.at(Si) = Ti;
      }else if(R.at(Si) != Ti){
          OK = false;
      }
      if(U.at(Ti) == -1){
          U.at(Ti) = Si;
      }else if(U.at(Ti) != Si){
          OK = false;
      }
  }
  if(OK) cout << "Yes" << endl;
  else cout << "No" << endl;
}



Measured memory_bytes: 776
import java.util.*;
import java.math.BigInteger;

public class Main{

	public static void main(String[] args){

		Scanner sc = new Scanner(System.in);
        long H = sc.nextLong();
        long W = sc.nextLong();
        long ans;
       
        if(H == 1 || W == 1){
          System.out.println(1);
        }else if(H*W % 2 == 0){
          ans = H*W/2;
          System.out.println(ans);
        }else{
          ans = (H*W/2)+1;
          System.out.println(ans);
        }  
	}

}

Measured memory_bytes: 35700
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

var in = bufio.NewScanner(os.Stdin)

func NextSlices(n int) (a, b []int) {
	for i := 0; i < n; i++ {
		in.Scan()
		temp := strings.Split(in.Text(), " ")
		li1, _ := strconv.Atoi(temp[0])
		li2, _ := strconv.Atoi(temp[1])
		a = append(a, li1)
		b = append(b, li2)
	}
	return a, b
}
func main() {

	a, b := NextSlices(3)

	count1 := 0
	count2 := 0
	count3 := 0
	count4 := 0
	for i := 0; i < 3; i++ {
		if a[i] == 1 {
			count1++
		} else if a[i] == 2 {
			count2++
		} else if a[i] == 3 {
			count3++
		} else if a[i] == 4 {
			count4++
		}
		if b[i] == 1 {
			count1++
		} else if b[i] == 2 {
			count2++
		} else if b[i] == 3 {
			count3++
		} else if b[i] == 4 {
			count4++
		}
	}
	if count1 <= 2 && count2 <= 2 && count3 <= 2 && count4 <= 2 {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}

Measured memory_bytes: 640
n = int(input())
s = str(input())

s_r = s.count("R")
s_g = s.count("G")
s_b = s.count("B")

def noteq(a, b, c):
  if a != b and b != c and c != a:
    return True
  else:
    return False

ans = s_r * s_g * s_b

for i in range(n):
  for d in range(n):
    j = i + d
    k = j + d
    if k >= n:
      break;
    else:
      a = s[i]
      b = s[j]
      c = s[k]
      if noteq(a, b, c):
        ans -= 1
    
print(ans)

Measured memory_bytes: 9220
package main

import (
        "bufio"
        "fmt"
        "math"
        "os"
        "strconv"
        "strings"
)

////////////////////////////////////////
///        templates                 ///
////////////////////////////////////////

var sc = bufio.NewScanner(os.Stdin)

func nextLine() string {
        sc.Scan()
        return sc.Text()
}

var rdr = bufio.NewReaderSize(os.Stdin, 1000000)

func readBigLine() string {
        buf := make([]byte, 0, 1000000)
        for {
                l, p, e := rdr.ReadLine()
                if e != nil {
                        panic(e)
                }
                buf = append(buf, l...)
                if !p {
                        break
                }
        }
        return string(buf)
}

func strSprit(str string) []string {
        cols := strings.Split(str, " ")
        return cols
}

func parseInt(str string) int {
        n, _ := strconv.Atoi(str)
        return n
}

func intSprit(str string) []int {
        strs := strSprit(str)
        cols := make([]int, len(strs))
        for i, v := range strs {
                cols[i] = parseInt(v)
        }
        return cols
}

type SortSlice []int

func (s SortSlice) Len() int {
        return len(s)
}

func (s SortSlice) Swap(i, j int) {
        s[i], s[j] = s[j], s[i]
}

func (s SortSlice) Less(i, j int) bool {
        return s[i] < s[j]
}

func reverseString(str string) string {
        buf := []rune(str)
        for i, j := 0, len(buf)-1; i < j; i, j = i+1, j-1 {
                buf[i], buf[j] = buf[j], buf[i]
        }
        return string(buf)
}

////////////////////////////////////////
///        end templates             ///
////////////////////////////////////////

func main() {
        line := nextLine()
        a := parseInt(line)

        line = nextLine()
        b := parseInt(line)

        line = nextLine()
        c := parseInt(line)

        line = nextLine()
        d := parseInt(line)

        tmin := float64(math.Min(float64(a), float64(b)))
        bmin := float64(math.Min(float64(c), float64(d)))

        fmt.Println(tmin + bmin)

}


Measured memory_bytes: 640
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()

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

#include <bits/stdc++.h>
using namespace std;

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

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


int main() {
  long long a,b,c,d;
  cin >>a>>b>>c>>d;
  
  long long cdiv=b/c-(a-1)/c;
  long long ddiv=b/d-(a-1)/d;
  
  long long e=lcm(c,d);
  long long ediv=b/e-(a-1)/e;
  
  cout << b-a+1-cdiv-ddiv+ediv << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include<iostream>

#include<string>

#define ll long long 

using namespace std;

int main(){

ll n;

cin>>n;

ll sum=0;

for(int i=1;i<=n;i++){

		 if(i%3==0||i%5==0) continue;

	 

	  else sum+=i;

}

cout<<sum<<endl;

return 0;

}

Measured memory_bytes: 3636
/*
  AOJ #3002
  title:Factrization
  @kankichi573
  2017/12/14 WA 35/37
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define max(x,y) (((x)>(y))?(x):(y))
char S[1000];
int  k[6];
int  jisuu;
int  insuu[6];

char delim[3]="+-";

int find_sign(char s[])
{
  char *p;
  int ret;

  for(p=s;*p;p++)
    if(*p=='+')
      {
        ret=1;
        goto END;
      }
    else
      {
        ret=-1;
        goto END;
      }
  ret=0;
 END:
  printf("f_s %s [%d]\n",s,ret);
}


int parse_monomial(char s[])
{ 
  char *p1,*p2;
  int a,b,ji;

  //printf("Mono=%s\n",s);
  
  
  p1=strchr(s,'x');
  p2=strchr(s,'^');

  
  if(p1 && p2 && p1!=s)
    {
      sscanf(s,"%dx^%d",&a,&b);
      ji=b;
      k[b]=a;
    }
  
  else if(p2 && p1==s)
    {
      sscanf(s,"x^%d",&b);
      ji=b;
      k[b]=1;
    }
    
  else if(p1 && !p2 && p1!=s)
    {
      if( 0==strcmp("+x",s))
        {
          ji=1;
          k[1]=1;
        }
      else if(0==strcmp("-x",s))
        {
          ji=1;
          k[1]=-1;
        }
      else
        {
          sscanf(s,"%dx",&a);
          ji=1;
          k[1]=a;
        }
    }

  else if(!p1 && !p2)
    {
      sscanf(s,"%d",&a);
      ji=0;
      k[0]=a;
    }
  return(ji);
}




int parse(char s[],int k[])
{
  char *p,*q,buf[100];
  int jisuu,ji,t;
  //printf("%s:\n",s);
  ji=0;
  t=0;
  p=q=s;
  while(1)
    {
      if(t==1)
        p++;
      while(*p!='+' && *p!='-' && *p)
        p++;
      memset(buf,0,sizeof(buf));
      strncpy(buf,q,p-q);
      jisuu=parse_monomial(buf);
      ji=max(ji,jisuu);
      q=p;
      t=1;
      if(!*p)
        return(ji);
    }
}
void dump()
{
  int i;
  for(i=5;i>=0;i--)
    printf("[%d],%d\n",i,k[i]);
}

long long calc_poly(int k[],int n)
{
  long long ret;
  ret =  k[5]*n*n*n*n*n;
  ret += k[4]*n*n*n*n;
  ret += k[3]*n*n*n;
  ret += k[2]*n*n;
  ret += k[1]*n;
  ret += k[0];
  return(ret);
}

int comp( const void * a , const void * b ) {

  if( *( int * )a < *( int * )b ) {
    return 1;
  }
  else
    if( *( int * )a == *( int * )b ) {
      return 0;
    }
  return -1;
}

void dump2()
{
  int i;
  for(i=0;i<jisuu;i++)
    printf("|%d\n",insuu[i]);
}

int main()
{
  int i,p;
  long long llret,llret2;

  scanf("%s",S);
  jisuu=parse(S,k);
  //dump();
  for(i=1,p=0;i<=200000;i++)
    if((k[0] % i)==0)
      {
        llret=calc_poly(k,i);
        llret2=calc_poly(k,-i);
        if(0==llret)
          insuu[p++]=i;
        if(0==llret2)
          insuu[p++]=-i;
      }

  qsort(insuu,jisuu,sizeof(int),comp);
  for(i=0;i<jisuu;i++)
    if(insuu[i]>0)
      printf("(x-%d)",insuu[i]);
    else
      printf("(x+%d)",-insuu[i]);
  printf("\n");
  
  return(0);
}

Measured memory_bytes: 1864
#include <stdio.h>

int main(){
	int n,x,count;
	while(true){
		scanf("%d %d",&n,&x);
		if(n == 0 && x == 0) break;
		count = 0;
		for(int min = 1; min < x/3 && min <= n-2;min++){
			for(int middle = min+1;middle < x - (min+middle) && middle <= n-1; middle++){
				if(x-(min+middle) <= n) count++;
			}
		}
		printf("%d\n",count);
	}

}


Measured memory_bytes: 2712
#include <stdio.h>
#define N 100

int A[N],d[N],f[N],tt,i;
int n,G[N][N];

void dfs_visit(int u){
  int t;
  A[u] = 1;
  d[u] = tt++;
  for(t=0;t<n;t++){
    if(G[u][t] == 1 && A[t] == 0) {
      dfs_visit(t);
    }
  }
  A[u] = 2;
  f[u] = tt++;
}

void dfs(void){

  for(i=0;i<n;i++) A[i] = 0;
  tt = 1;

  for(i=0;i<n;i++){
    if(A[i] == 0) dfs_visit(i);
  }
  for(i=0;i<n;i++){
    printf("%d %d %d\n",i+1,d[i],f[i]);
  }
}


int main(){
  int j,u,k,v;

  scanf("%d",&n);

  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      G[i][j] = 0;
    }
  }

  for(i=0;i<n;i++){
    scanf("%d%d",&u,&k);
    u--;
    for(j = 0; j < k;j++){
      scanf("%d",&v);
      v--;
      G[u][v] = 1;
    }
  }
  dfs();

  return 0;
}



Measured memory_bytes: 2036
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;
int main(int, char**)
{
       string s;
	int ans = 1000;
	std::cin >> s;

       for(int i = 0; i < s.length() - 2; i++) {
                int t = (s[i] - '0') * 100 + (s[i+1] - '0') *10 + (s[i+2]-'0');
               if (abs(t -753) < ans)
                    ans = abs(t - 753);
       }
       cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
      #include <string>
      #include <vector>
      #include <algorithm>
      #include <utility>
      #include <map>
      using namespace std;
      typedef long long ll;
      #define rep(i, n) for (int i=0;i < (int)(n);i++)

      int main(){
         int n;
         map<ll,int> m;
         cin >> n;
         vector<int> v(n);
         rep(i,n) {
            cin >> v[i];
            m[v[i]]++;
         }
         //sort(v.begin(),v.end());
         ll f = 0LL,s = 0LL;
         for (auto w :m){
            if (w.second >= 4){
               s = w.first;
               f = w.first;
            }
            else if (w.second >= 2) {
               s = f;
               f = w.first;
            }    
         }
         cout << s*f << endl;

         return 0;
         
      }



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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	string s="ACGT"s,v="TGCA"s;
	char b; cin>>b;
	int i=0;
	while(s.at(i)!=b)++i;
	cout<<v.at(i)<<"\n"s;
}

Measured memory_bytes: 256
#! /usr/bin/env ruby
# coding: utf-8
Thread.new do
  while n = gets.to_i
    break if n == 0
    v = gets.split.map{|e| e.to_i }
    raise "assert" unless v.length == n
    count = {}
    count.default = 0
    v.each do |e|
      count[e] += 1
    end
    ans = "NO COLOR"
    count.each do |k, v|
      ans = k if v > n / 2
    end
    puts ans
  end
end

sleep 10
    

Measured memory_bytes: 109712
#include<bits/stdc++.h>
#include <iostream>
#include <numeric>
#include <math.h>
#define ll long long 
#define ull long
#define mpa make_pair
#define pb push_back
#define ff first
#define pii pair<ll,ll>
#define dd long long
#define trace(x) cerr << #x << " : " << x << endl
#define ss second
#define boost ios_base::sync_with_stdio(0)
#define forp(i,a,b) for(ll i=a;i<=b;i++)
#define rep(i,n)    for(ll i=0;i<n;++i)
#define ren(i,n)    for(ll i=n-1;i>=0;i--)
#define forn(i,a,b) for(ll i=a;i>=b;i--)
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(typeof((c).begin()) i = (c).begin(); i != (c).end();
#define sc(x) scanf("%lld",&x)
#define clr(x,val) memset(x,val,sizeof(x))
#define pr(x) printf("%lld\n",x) 
#define gc getchar
#define pdd pair<dd,dd>
#define prec(x) cout<<fixed<<setprecision(x)
#define fre freopen("input.txt","r",stdin),freopen("output.txt","w",stdout)
using namespace std;
ll h,w;
char s[1005][1005];
vector<pii> adj[1000005];
ll dis[1000005];
ll chk(ll x,ll y){
	if(x>=1 && x<=h && y>=1 && y<=w)return 1;
	return 0;
}
ll conv(ll x,ll y){
	return (x-1)*w+y;
}
int main(){
   //boost;
  cin>>h>>w;
  ll x1,y1;
  cin>>x1>>y1;
  ll st=conv(x1,y1);
  ll x2,y2;
  cin>>x2>>y2;
  ll en=conv(x2,y2);
  
  for(ll i=1;i<=h;i++){
  	for(ll j=1;j<=w;j++){
  		
  		cin>>s[i][j];
	  }
    }

  for(ll i=1;i<=h;i++){
  	for(ll j=1;j<=w;j++){
  		ll curr=conv(i,j);
  		map<ll,ll> help;
  		if(chk(i+1,j) && s[i+1][j]=='.')adj[curr].pb(mpa(conv(i+1,j),0)),help[conv(i+1,j)]=1;
  		if(chk(i-1,j) && s[i-1][j]=='.')adj[curr].pb(mpa(conv(i-1,j),0)),help[conv(i-1,j)]=1;
  		if(chk(i,j+1) && s[i][j+1]=='.')adj[curr].pb(mpa(conv(i,j+1),0)),help[conv(i,j+1)]=1;
  		if(chk(i,j-1) && s[i][j-1]=='.')adj[curr].pb(mpa(conv(i,j-1),0)),help[conv(i,j-1)]=1;
  		
  		ll tx1=i-2;
  		ll ty1=j-2;
  		ll tx2=i+2;
  		ll ty2=j+2;
  		
  		for(ll p=tx1;p<=tx2;p++){
  			for(ll q=ty1;q<=ty2;q++){
  				if(chk(p,q)==0)continue;
  				if(conv(p,q)==curr)continue;
  				if(help[conv(p,q)])continue;
  				if(chk(p,q)==1 && s[p][q]=='.')adj[curr].pb(mpa(conv(p,q),1));
  				
			 }
		}
  		
	  }
  }
  for(ll i=1;i<=h*w;i++)dis[i]=1e10;
  deque<ll> q;
  q.push_front(st);
  dis[st]=0;
  
  while(!q.empty()){
  	 
	 ll v=q.front();
  	 q.pop_front();
  	 
  	 for(ll i=0;i<adj[v].size();i++){
  	 	ll u=adj[v][i].ff;
  	 	ll w=adj[v][i].ss;
  	 	
  	 	if(dis[u]>dis[v]+w){
  	 		dis[u]=dis[v]+w;
  	 		if(w==1)q.push_back(u);
  	 		else q.push_front(u);
  	 	}
	 }
	}
	if(dis[en]==1e10)cout<<-1;
	else cout<<dis[en];
  	 
  	 
  	 
  	 
  }
  
  
  
   


    


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

int main(){
	int N;
	cin >> N;
	int x[N], y[N];
	rep(i,N) cin >> x[i] >> y[i];
	double d[N][N];
	double ans = 0;
	for (int i = 0; i < N; i++) {
		for (int j = i; j < N; j++) {
			d[i][j] = (x[i]-x[j])*(x[i]-x[j]) + (y[i]-y[j])*(y[i]-y[j]);
			d[i][j] = sqrt(d[i][j]);
			d[j][i] = d[i][j];
		}
	}
	rep(i,N)rep(j,N) ans += d[i][j]/N;
	printf("%.7f\n", ans);

	return 0;
}


Measured memory_bytes: 3772
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
char ch[111];
int a[111],n,ans=2e9;
int main()
{
	scanf("%s",ch+1);n=strlen(ch+1);
	for(int i=1;i<=n;++i)a[i]=ch[i]-97;
	for(int i=0;i<26;++i)
	{
		int mx=0,d=0;
		for(int j=n;j;--j)
			if(a[j]==i)d=0;
			else mx=max(mx,++d);
		ans=min(ans,mx);
	}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 256
-- day-of-takahashi.hs --- Day of Takahashi

-- author: Seong Yong-ju <sei40kr@gmail.com>

solve :: Int -> Int -> Int
solve a b = a - 1 + (if a <= b then 1 else 0)

main :: IO ()
main = do
  [a, b] <- map (read :: String -> Int) . words <$> getLine
  print $ solve a b


Measured memory_bytes: 508
#include <bits/stdc++.h>
using namespace std;
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return 1;
    }
    return 0;
}
typedef long long int ll;

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define endl "\n"
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
const double PI = acos(-1);
const int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//-------------------------------------

struct edge {
    int to, cost;
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N = 0, M = 0, L;
    cin >> L;
    int tmp = 1;
    while(tmp <= L) {
        tmp *= 2;
        N++;
    }
    vector<vector<edge>> g(N);
    for(int i = 0; i < N - 1; i++) {
        g[i].emplace_back(edge{i + 1, (1 << i)});
        g[i].emplace_back(edge{i + 1, 0});
        M += 2;
    }
    int now = L - 1;
    for(int i = N - 2; i >= 0; i--) {
        if(now - ((1 << i) - 1) >= (1 << (N - 1))) {
            g[i].emplace_back(edge{N - 1, now - ((1 << i) - 1)});
            M++;
            now = (now - ((1 << i) - 1)) - 1;
        }
    }
    cout << N << ' ' << M << endl;
    for(int i = 0; i < N; i++) {
        for(auto e : g[i]) {
            cout << i + 1 << ' ' << e.to + 1 << ' ' << e.cost << endl;
        }
    }
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<queue>
#define MAXN 500000
using namespace std;
priority_queue<int,vector<int>,greater<int> > que;
int N,K;
int p[MAXN+5],q[MAXN+5];
int tree[MAXN*4],d[MAXN+5];
vector<int> G[MAXN+5],ans;
void Build(int i,int l,int r)
{
	tree[i]=0;
	if(l==r)
		return;
	int mid=(l+r)/2;
	Build(i*2,l,mid);
	Build(i*2+1,mid+1,r);
}
void PushUp(int i)
{
	tree[i]=max(tree[i*2],tree[i*2+1]);
}
void Insert(int i,int l,int r,int p,int val)
{
	if(l==r)
	{
		tree[i]=val;
		return;
	}
	int mid=(l+r)/2;
	if(p<=mid)
		Insert(i*2,l,mid,p,val);
	else
		Insert(i*2+1,mid+1,r,p,val);
	PushUp(i);
}
int Query(int i,int l,int r,int ql,int qr)
{
	if(qr<l||ql>r)
		return 0;
	if(ql<=l&&r<=qr)
		return tree[i];
	int mid=(l+r)/2;
	return max(Query(i*2,l,mid,ql,qr),Query(i*2+1,mid+1,r,ql,qr));
}
void BFS()
{
	for(int i=1;i<=N;i++)
		if(d[i]==0)
			que.push(i);
	while(que.empty()==false)
	{
		int u=que.top();
		que.pop();
		ans.push_back(u);
		for(int i=0;i<(int)G[u].size();i++)
		{
			int v=G[u][i];
			d[v]--;
			if(d[v]==0)
				que.push(v);
		}
	}
}
int main()
{
//	freopen("swap.in","r",stdin);
//	freopen("swap.out","w",stdout);
	scanf("%d %d",&N,&K);
	for(int i=1;i<=N;i++)
	{
		scanf("%d",&p[i]);
		q[p[i]]=i;
	}
	Build(1,1,N);
	for(int i=1;i<=N;i++)
	{
		int pos=Query(1,1,N,max(q[i]-K+1,1),q[i]);
		if(pos!=0)
		{
			G[q[pos]].push_back(q[i]);
			d[q[i]]++;
		}
		pos=Query(1,1,N,q[i],min(N,q[i]+K-1));
		if(pos!=0)
		{
			G[q[pos]].push_back(q[i]);
			d[q[i]]++;
		}
		Insert(1,1,N,q[i],i);
	}
	for(int i=1;i<=N;i++)
		sort(G[i].begin(),G[i].end());
	BFS();
	for(int i=0;i<(int)ans.size();i++)
		p[ans[i]]=i+1;
	for(int i=1;i<=N;i++)
		printf("%d\n",p[i]);
	return 0;
}

Measured memory_bytes: 45168
#include "bits/stdc++.h"
using namespace std;
typedef long long lint;
typedef vector<lint> LIV;
#define rep(i,n) for(int i=0;i<n;++i)
#define MAXN 100010
#define MAXM 1100000
#define all(v) v.begin(),v.end()
#define inf 2147483647
#define linf 1152921504606846976

#include "bits/stdc++.h"
using namespace std;
typedef long long lint;
typedef vector<lint> LIV;
#define rep(i,n) for(int i=0;i<n;++i)
#define MAXN 100010
#define MAXM 1100000
#define all(v) v.begin(),v.end()
#define inf 2147483647
#define linf 1152921504606846976
#define MAX_N 100010

int main(){
	lint n;cin>>n;
	string s;cin>>s;
	lint ans=-linf;
	rep(i,n-1){
		lint c=0;
		string t=s.substr(0,i+1),u=s.substr(i+1);
		rep(j,26)c+=(count(all(t),j+'a')&&count(all(u),j+'a'));
		ans=max(ans,c);
	}cout<<ans<<endl;
}

//sub-EOF


Measured memory_bytes: 256
#include<stdio.h>

int main(){
  int i,j,k,t,q;
  int n,cnt;
  int A_size[10000];

  cnt = 0;

  //linearsearch function is here
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",A_size+i);
  }
  
  scanf("%d",&q);
  for(j=0;j < q;j++){
    scanf("%d",&t);
    for(k=0;k < n;k++){
      if(A_size[k] == t){
	cnt++;
	break;
      }
    }
  }
  printf("%d\n",cnt);
  return 0;

}



Measured memory_bytes: 2108
#define _USE_MATH_DEFINES
#include <iostream>
#include <stdio.h>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <math.h>
#include <complex>
#include <cassert>
#define rep(i,a,b) for (int i = (a); i < (b); i++)
#define case(i) printf("Case #%d: ",i);
using namespace std;
typedef long long int ll;
typedef complex<double> com;
typedef pair<int, int> P;
const int mod = 1e9 + 7;
const int MOD = 998244353;
const ll INF = 4e18;



int main(){
	int n; cin >> n;
	vector<int> a(n),ans;
	rep(i, 0, n) cin >> a[i];
	sort(a.begin(), a.end());
	rep(i, 0, n - 1) {
		if (a[i] == a[i + 1]) {
			ans.push_back(a[i]);
			i++;
		}
	}
	if (ans.size() < 2) {
		cout << 0 << endl;
		return 0;
	}
	sort(ans.begin(), ans.end(), greater<int>());
	printf("%lld", 1LL*ans[0] * ans[1]);
	return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <string.h>

int main(void)
{
    char s[2000000], t[2000000];
    int l, i, count = 0;

    scanf("%s %s", &s, &t);

    l = strlen(s);
    
    for (i = 0; i < l; i++)
    {
        if (s[i] != t[i]) count++;
    }

    printf("%d", count);
    
    return 0;
}

Measured memory_bytes: 2136
#include <iostream>
#include <string.h>
using namespace std;

struct edge {
	int s, t, d;
};

int v, e, r, ct = 0;
bool nc = 0;
edge es[2000];
long d[1000];
const long Mx = 0xFFFFFFF;

int main()
{
	cin >> v >> e >> r;

	for (int i = 0; i < e; i++)
		cin >> es[i].s >> es[i].t >> es[i].d;

		for (int i = 0; i < v; i++)
			d[i] = Mx;

		d[r] = 0;

	while (true) {
		bool f = true;
		for (int i = 0; i < v; i++) {
			for (int j = 0; j < e; j++) {
				edge e = es[j];
				if (d[e.s] != Mx && d[e.t] > d[e.s] + e.d) {
					d[e.t] = d[e.s] + e.d;
					f = false;
				}
			}
		}
		ct++;
		if (ct > v || f)
			break;
	}

	if (ct > v)
		cout << "NEGATIVE CYCLE" << endl;
	else {
		for (int i = 0; i < v; i++) {
			if (d[i] == Mx)
				cout << "INF" << endl;
			else
				cout << d[i] << endl;
		}
	}

	return 0;
}


Measured memory_bytes: 3108
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) (v).begin(), (v).end()
#define coutd(n) cout << fixed << setprecision(n)
#define ll long long int
#define vl vector<ll>
#define vi vector<int>
const int INF = 2147483647;
const ll MOD = 1000000007;

using namespace std;

void dfs(const int i, const int j, const int h, const int w, const vector<vi> &grid, vector<vector<bool>> &visited) {
  if (not(0 <= i and i < h and 0 <= j and j < w))
    return;
  if (visited[i][j] or grid[i][j] == 0)
    return;
  visited[i][j] = true;
  int dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
  int dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
  REP(k, 8) { dfs(i + dx[k], j + dy[k], h, w, grid, visited); }
}

int main() {
  while (true) {
    int w, h;
    cin >> w >> h;
    if (w == 0 and h == 0)
      return 0;
    vector<vi> grid(h, vi(w, 0));
    vector<vector<bool>> visited(h, vector<bool>(w, false));
    REP(i, h) {
      REP(j, w) { cin >> grid[i][j]; }
    }

    int ans = 0;
    REP(i, h) {
      REP(j, w) {
        if (not visited[i][j] and grid[i][j] == 1) {
          ans++;
          dfs(i, j, h, w, grid, visited);
        }
      }
    }
    cout << ans << endl;
  }
  return 0;
}



Measured memory_bytes: 3500
N, K = map(int, input().split())
A = [int(a) - 1 for a in input().split()]

if K <= N:
    p = 0
    for i in range(K):
        p = A[p]
    print(p + 1)
    exit()

p = 0
t = [-1] * N
t[0] = 0
for i in range(1, N):
    p = A[p]
    if t[p] != -1:
        break
    t[p] = i

d = i - t[p]
K -= i
K %= d

for i in range(K):
    p = A[p]
print(p + 1)


Measured memory_bytes: 32364
import heapq
import sys

readline = sys.stdin.buffer.readline


def main():
    N = int(readline())
    A = list(map(int, readline().split()))
    rA = list(map(lambda x: -1 * x, A[::-1]))

    MM = A[:N]
    mm = rA[:N]
    heapq.heapify(MM)
    heapq.heapify(mm)
    M = [sum(MM)]
    m = [sum(mm)]

    for i in range(N, 2*N):
        pM = heapq.heappushpop(MM, A[i])
        pm = heapq.heappushpop(mm, rA[i])
        M.append(M[-1] - pM + A[i])
        m.append(m[-1] - pm + rA[i])

    Dm = -10**14
    for i, j in zip(M, m[::-1]):
        if i + j > Dm:
            Dm = i + j

    print(Dm)


main()


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

int n, f[30][55];
string s;

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

    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> s;
        for (int j = 0; j < s.size(); j++) {
            f[s[j] - 'a'][i]++;
        }
    }

    for (int i = 0; i < 26; i++) {
        int mn = 1e9;
        for (int j = 0; j < n; j++) {
            mn = min(mn, f[i][j]);
        }

        for (int j = 0; j < mn; j++) {
            cout << (char) ('a' + i);
        }
    }
    cout << '\n';

    return 0;
}

Measured memory_bytes: 3652
# -*- coding: utf-8 -*-
from itertools import permutations, product
from heapq import heappush, heappop
def inpl(): return tuple(map(int, input().split()))
N, M, R = inpl()
inf = float("inf")
G = {n: {} for n in range(N+1)}
Des = inpl() 

for _ in range(M):
    a, b, c = inpl()
    G[a][b] = c
    G[b][a] = c

def dijkstra(s):
    D = [inf for _ in range(N+1)]
    D[s] = 0
    HQ = [(0, s)]
    checked = [False for _ in range(N+1)]
    while HQ:
        pc, a = heappop(HQ)
        if D[a] < pc or checked[a]:
            continue
        for b, c in G[a].items():
            if pc + c < D[b]:
                D[b] = pc + c
                heappush(HQ, (D[b], b))

        checked[a] = True
    return [D[des] for des in Des]

C = []
for s in Des:
    C.append(dijkstra(s))

res = inf
for E in permutations(range(len(Des)), len(Des)):
    res = min(res, sum([C[E[i]][E[i+1]] for i in range(len(Des)-1)]))            
        
print(res)

Measured memory_bytes: 6644
#![allow(unused_imports)]
#![allow(unused_macros)]
use std::cmp::{max, min};
use std::collections::*;
use std::io::{stdin, Read};

trait ChMinMax {
    fn chmin(&mut self, other: Self);
    fn chmax(&mut self, other: Self);
}
impl<T> ChMinMax for T
where
    T: PartialOrd,
{
    fn chmin(&mut self, other: Self) {
        if *self > other {
            *self = other
        }
    }
    fn chmax(&mut self, other: Self) {
        if *self < other {
            *self = other
        }
    }
}

#[allow(unused_macros)]
macro_rules! parse {
    ($it: ident ) => {};
    ($it: ident, ) => {};
    ($it: ident, $var:ident : $t:tt $($r:tt)*) => {
        let $var = parse_val!($it, $t);
        parse!($it $($r)*);
    };
    ($it: ident, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = parse_val!($it, $t);
        parse!($it $($r)*);
    };
    ($it: ident, $var:ident $($r:tt)*) => {
        let $var = parse_val!($it, usize);
        parse!($it $($r)*);
    };
}

#[allow(unused_macros)]
macro_rules! parse_val {
    ($it: ident, [$t:tt; $len:expr]) => {
        (0..$len).map(|_| parse_val!($it, $t)).collect::<Vec<_>>();
    };
    ($it: ident, ($($t: tt),*)) => {
        ($(parse_val!($it, $t)),*)
    };
    ($it: ident, u1) => {
        $it.next().unwrap().parse::<usize>().unwrap() -1
    };
    ($it: ident, $t: ty) => {
        $it.next().unwrap().parse::<$t>().unwrap()
    };
}

#[cfg(debug_assertions)]
macro_rules! debug {
    ($( $args:expr ),*) => { eprintln!( $( $args ),* ); }
}

#[cfg(not(debug_assertions))]
macro_rules! debug {
    ($( $args:expr ),*) => {
        ()
    };
}

fn solve(s: &str) {
    let mut it = s.split_whitespace();
    parse!(it, n: usize, a: [usize; n]);
    let mut cur = 0;
    let mut ret = 0;
    for &ai in &a {
        if cur > ai {
            ret += cur - ai;
        } else {
            cur = ai
        }
    }
    println!("{}", ret);
}

fn main() {
    let mut s = String::new();
    stdin().read_to_string(&mut s).unwrap();
    solve(&s);
}

#[cfg(test)]
mod tests {
    use super::*;
    #[test]
    fn test_input() {
        let s = "
        ";
        solve(s);
    }
}


Measured memory_bytes: 5780
N, W = map(int, input().split())
cf=sorted( [ [int(x) for x in input().split()] for _ in range(N) ] )
dp = [0]*(W+1)
cnt=0
for w, c in cf:
    cnt=cnt+w
    for i in range(min(cnt, W), w-1, -1):
        if dp[i]<dp[i-w]+c:
            dp[i]=dp[i-w]+c
print(max(dp))

Measured memory_bytes: 7736
#include <iostream>
#include <sstream>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <numeric>
#include <algorithm>
#include <string>
#include <complex>
 
#include <cassert>
#include <cstdlib>
#include <cmath>
#include <cstdio>
#include <cstring>
 
#define REP(i,e) for(int i=0;i<(int)(e);i++)
#define FOR(i,b,e) for(int i=(int)(b);i<(int)(e);i++)
#define ALL(c) (c).begin(), (c).end()
#define EACH(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();++it)
#define RALL(c) (c).rbegin(), (c).rend()
#define ALLA(a,n) ((a)+0), ((a)+n)
 
using namespace std;
 
typedef long long ll;
typedef vector<int> vint;
typedef vector<long long> vll;
typedef vector<string> vstring;
typedef vector<double> vdouble;
 
template<class T>void pp(T v,int n){ REP(i,n)cout<<v[i]<< ' ' ; cout << endl; }
template<class T>void pp(T v){ EACH(it,v) cout << *it << ' ' ; cout << endl;  }
template<class T>T& ls(T& a,T b){ if(b<a) a=b; return a; }
template<class T>T& gs(T& a,T b){ if(b>a) a=b; return a; }
inline ll to_i(const string& s){ll n;sscanf(s.c_str(),"%lld",&n);return n;}
inline string to_s(ll n){char buf[32];sprintf(buf,"%lld",n);return string(buf);}

inline string bool_to_string(bool b, const string &tval, const string fval) { return b ? tval : fval; } 
string YESNO(bool b) { return bool_to_string(b, "YES", "NO"); }
string YesNo(bool b) { return bool_to_string(b, "Yes", "No"); }
string yesno(bool b) { return bool_to_string(b, "yes", "no"); }

int main() {
  string a, b, c;
  while (cin >> a >> b >> c) {
    cout << YESNO(to_i(a + b + c) % 4 == 0) << endl;
  }
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr long long INFL = numeric_limits<long long>::max() / 2;
constexpr int MOD = 1000000007;
using Graph = vector<vector<int>>;



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

    int N;
    cin >> N;
    int p[N];
    rep(i,N){
        cin >> p[i];
    }
    int count=0;
    rep(i,N){
        if(i+1 != p[i]) count++;
    }
    if(count<=2) cout << "YES" << endl;
    else cout << "NO" << endl;


}


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

class UnionFind {
public:
    // parent node index if not root index
    // minus size of the tree if root index
    std::vector<int> data;

    UnionFind( int n ) {
        data.resize( n, -1 );
    }

    int find( int x ) {
        if ( data[x] < 0 ) {
            return x;
        } else {
            int r = find( data[x] );
            data[x] = r;
            return r;
        }
    }

    void unite( int x, int y ) {
        int r = find( x );
        int s = find( y );
        if ( r != s ) {
            data[r] += data[s];
            data[s] = r;
        }
    }

    int count( int x ) {
        return -data[find(x)];
    }
};

int main() {
    int NMAX = 1e5;
    int N;
    cin >> N;
    vector<int> X(N), Y(N);
    for ( int i = 0; i < N; i++ ) {
        cin >> X[i] >> Y[i];
        X[i]--;
        Y[i]--;
    }
    map<int, set<int>> px, py;
    for ( int i = 0; i < N; i++ ) {
        px[X[i]].insert(Y[i]);
        py[Y[i]].insert(X[i]);
    }

    UnionFind ux(NMAX), uy(NMAX);

    for ( auto p : px ) {
        int y0 = *p.second.begin();
        for ( auto y : p.second) {
            uy.unite(y0, y);
        }
    }
    for ( auto p : py ) {
        int x0 = *p.second.begin();
        for ( auto x : p.second) {
            ux.unite(x0, x);
        }
    }

    set<pair<int, int>> used;
    ll dots = 0;

    for ( int i = 0; i < N; i++ ) {
        auto pp = make_pair(ux.find(X[i]), uy.find(Y[i]));
        if ( used.find(pp) == used.end() ) {
            used.insert(pp);
            dots += (ll)ux.count(pp.first) * uy.count(pp.second);
        }
    }
    
    ll ans = dots - N;
    cout << ans << '\n';
    return 0;
}

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

// #define int long long
#define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i)
#define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i)
#define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--)
#define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i)
#define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) long long(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

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

const ll INF = 1e9;
const ll MOD = 1e9+7;
const ll LINF = 1e18;

ll dp[2005][2005]; // [l,r)における回文の最大長
string s;

void solve(){
  ll n=s.size();
  
  memset(dp,0,sizeof(dp));
  rep(i,n) dp[i][i+1]=1;
  
  for(ll len=2; len<=n; len++){
    for(ll i=0; i+len<=n; i++){
      ll j=i+len;
      if(s[i]==s[j-1]) chmax(dp[i][j],dp[i+1][j-1]+2);
      else chmax(dp[i][j],max(dp[i+1][j],dp[i][j-1]));
    }
  }
  
  ll ma=0, l,r;
  rep(i,n) irep(j,i,n+1){
    if(chmax(ma,dp[i][j])) l=i, r=j;
  }
  
  // cout<<dp[0][n]<<' '<<ma<<endl;
  
  if(ma==1){
    cout<<s[0]<<endl;
    return;
  }
  
  string left="", right="";
  while(ma>0){
    while(dp[l+1][r]==ma) l++;
    while(dp[l][r-1]==ma) r--;
    left+=s[l], right+=s[l];
    // cout<<l<<' '<<r<<' '<<ma<<endl;
    ma-=2;
    if(ma==1){
      left+=s[l+1];
      ma--;
    }
    l++, r--;
  }

  reverse(all(right));
  string ans=left+right;
  cout<<ans<<endl;
  
  return;
}


signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  
  for(int t = 0; cin >> s; t++) {
    solve();
  }
  
}


Measured memory_bytes: 34620
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rep1(i,n) for(int i=1; i<=(n); ++i)
#define repi(i,a,b) for(int i=a; i<=(b); ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define pb push_back
#define mp make_pair
#define sz(v) (int)v.size()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
using ll = long long;
using namespace std;
typedef pair<int,int> P;
struct aaa{aaa(){ cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);};}aaaaaaa;
int MOD = 1e9 + 7;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return (a*b)/gcd(a,b);}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int a,b;
int main(){
    cin >> a >> b;
    cout << ((b>=a)? a : (a-1)) << '\n';
}

Measured memory_bytes: 256
#include <cstdio>
using namespace std;
typedef long long int ll;
const ll MOD = 1000000007;

int N, C, A[410], B[410];
ll sum[410][410], dp[410][410];

ll mod_pow(ll n, ll k) {
    ll ret = 1, pw = n%MOD;
    while(k) {
        if(k & 1) (ret *= pw) %= MOD;
        (pw *= pw) %= MOD;
        k >>= 1;
    }
    return ret;
}

int main() {
    scanf("%d%d", &N, &C);
    for(int i=0; i<N; i++) scanf("%d", &A[i]);
    for(int i=0; i<N; i++) scanf("%d", &B[i]);

    for(int i=0; i<=C; i++) {
        for(int j=1; j<=400; j++) {
            sum[i][j] = (sum[i][j-1] + mod_pow(j, i)) % MOD;
        }
    }

    dp[0][0] = 1;
    for(int i=0; i<N; i++) {
        for(int j=0; j<=C; j++) {
            for(int k=0; k<=j; k++) {
                // dp[i+1][j] = dp[i][j-k] * (A^k + (A+1)^k + ... + B^k)
                ll mul = (sum[k][B[i]] - sum[k][A[i] - 1] + MOD) % MOD;
                (dp[i+1][j] += (dp[i][j-k] * mul) % MOD) %= MOD;
            }
        }
    }
    printf("%lld\n", dp[N][C]);
    return 0;
}

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

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;

const int N = 200010;

int n, idx1, idx2;
int a[8] = {1, 2, 3, 4, 5, 6, 7, 8};
int b[8];
int c[8];

int check1()
{
    for(int i = 0; i < n; i++)
        if(a[i] != b[i]) return false;
    return true;
}

bool check2()
{
    for(int i = 0; i < n; i++)
        if(a[i] != c[i]) return false;
    return true;
}

int main()
{
    cin >> n;
    for(int i = 0; i < n; i++) cin >> b[i];
    for(int i = 0; i < n; i++) cin >> c[i];

    int cnt = 0;
    do
    {
        cnt++;
        if(check1()) idx1 = cnt;
        if(check2()) idx2 = cnt;
    }while(next_permutation(a, a + n));

    cout << abs(idx1 - idx2) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>

int main(int argc,char *argv[])
{
	int N;
	std::cin >> N;

	if(!(N%2)) std::cout << static_cast<double>(1.0/2.0) << std::endl;
	else std::cout << (N-N/2)/static_cast<double>(N) << std::endl;

	return 0;
}


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

int main()
{
  int a, b, c, d;
  cin >> a >> b >> c >> d;

  int ans = 0;

  if(a <= c && c <= b){
    if(b <= d) ans = b - c;
    if(d <= b) ans = d - c;
  }

  else if(c <= a && a <= d){
    if(d <= b) ans = d - a;
    if(b <= d) ans = b - a;
  }

  cout << ans << endl;

  return 0;

}


Measured memory_bytes: 256
#![allow(non_snake_case, unused)]
use std::cmp::*;
use std::collections::*;
use std::f64::consts::*;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        d: u32,
        mut n: i32,
    }
    if n == 100 {
        n += 1;
    }
    println!("{}", 100i32.pow(d) * n);
}


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

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);
    
    ll h,w;
    cin>>h>>w;
    ll a[h][w]={};
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            int b;
            cin>>b;
            a[i][j] += b;
        }
    }
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            int b;
            cin>>b;
            a[i][j] -= b;
        }
    }
    bool dp[h][w][30000]={};
    dp[0][0][a[0][0]+12800]=1;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            for(int k=0;k<30000;k++){
                if(k+a[i][j] >=0 && k+a[i][j]<30000){
                    if(i) dp[i][j][k+a[i][j]] |= dp[i-1][j][k];
                    if(j) dp[i][j][k+a[i][j]] |= dp[i][j-1][k];
                }
                if(k-a[i][j]>=0 && k-a[i][j]<30000){
                    if(i) dp[i][j][k-a[i][j]] |= dp[i-1][j][k];
                    if(j) dp[i][j][k-a[i][j]] |= dp[i][j-1][k];
                }
            }
        }
    }
    int ans = 1e9;
    int t = 12800;
    for(int i=0;i<30000;i++){
        if(dp[h-1][w-1][i]){
            ans = min(ans,abs(i-t));
            //cerr << i-t << endl;
        }
    }
    cout << ans << endl;
}

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

// calc divisors of n
set<ll> divisor(ll n){
    set<ll> ret;
    for(ll i = 1; i*i <= n; ++i){
        if(n%i == 0){
            ret.insert(i);
            ret.insert(n/i);
        }
    }
    return ret;
}

int main() {
    ll n, m;
    cin >> n >> m;
    
    set<ll> s = divisor(m);
    ll ans = 0;
    for(ll i : s){
        if(i <= m/n){
            ans = i;
        }
    }
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a, b, c;
	cin>>a>>b>>c;
	map<int, int> cnt;
	cnt[a]++;
	cnt[b]++;
	cnt[c]++;
	if(cnt[5]==2 && cnt[7]==1)
		cout<<"YES";
	else
		cout<<"NO";
	return 0;
}

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

class Main {

	public static void main(String[] args) {
        FastScanner in = new FastScanner();
        PrintWriter out = new PrintWriter(System.out);
        char ch[] = in.next().toCharArray();
        long sum = 0;
        for(int i=0;i<ch.length;i++)
        	sum = sum + Integer.parseInt(""+ch[i]);
        if(sum%9==0) out.println("Yes");
        else out.println("No");
        out.flush();
	}
	
	static class FastScanner {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer("");
		
		String next() {
			while(!st.hasMoreTokens())
				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());
		}
		
		int[] readArray(int n) {
			int a[] = new int[n];
			for(int i=0;i<n;i++) a[i] = nextInt();
			return a;
		}
		
		long[] readArray(int n,long x) {
			long a[] = new long[n];
			for(int i=0;i<n;i++) a[i] = nextLong();
			return a;
		}
		
	}
}











Measured memory_bytes: 44528