akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;
int main(void){
  int N, M, X;
  int A[110];
  int left_cost, right_cost; // 左へ進むコスト，右へ(ry
  left_cost = 0;
  right_cost = 0;
  
  cin >> N >> M >> X;
  for(int i = 0; i < M; ++i) {
    cin >> A[i];
    if( A[i] < X ) ++left_cost;
    else ++right_cost;
  }
  
  if( left_cost < right_cost ) cout << left_cost << endl;
  else cout << right_cost << endl;
    
  return 0;
}


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


int main() {
    ll n, k;
    cin >> n >> k;

    ll f;
    for(int i = 0; i < n; ++i)
        cin >> f;

    if((n-1)%(k-1) == 0)
        cout << (n-1)/(k-1) << endl;
    else
        cout << ((n-1)/(k-1))+1 << endl; 

    return 0;
}

Measured memory_bytes: 256
def main():
    n,a,b=map(int,input().split())

    if n == 0:
        ans=0
        print(ans)
        return
    elif n==1:
        if a==b:
            ans=1
            print(ans)
            return
        else:
            ans=0
            print(ans)
            return

    elif n>=2:
        ans=1
        if a>b:
            ans=0
            print(ans)
            return
# ありうる数字の種類
        dif=b-a
        #数
        num=n-2
        ans=dif*num+1
        print(ans)




if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#!/usr/bin/env ruby
h , w = STDIN.readline().split(' ').map(&:to_i)
ss = []
ss << ('#' * (w + 2)).split('')
h.times.each {|i| ss << ('#' + STDIN.readline().strip + '#').split('') }
ss << ('#' * (w + 2)).split('')
def sum(a)
  a.inject(0){|sum, i| sum += i }
end
def check_paint(ss, h, w)
  for y in (1..h) do
    for x in (1..w) do
      next if ss[y][x] == '.'
      return false if not paintable?(x, y, ss)
    end
  end
  true
end
def print_bomb_nums(ns)
  ns.each{|n| puts "#{n.join}"}
end
def p?(x, y, ss)
  ss[y][x] == '#'
end
def paintable?(x, y, ss)
  [[x, y-1, ss],
   [x-1, y, ss], [x+1, y, ss],
   [x, y+1, ss]].any?{|x, y, ss|p?(x, y, ss)}
end
puts "#{check_paint(ss, h, w) ? 'Yes' : 'No'}"

Measured memory_bytes: 2172
#include <stdio.h>
int main()
{
   int k, x;
   int sum = 0;
   scanf("%d", &k);
   x = k;
   
   while (k != 0){
       if(k != 10){
           sum = sum + k%10;
           k = k/10;
       }
       else {
           sum = sum + 1;
           k = 0;
       }
   }

   if (x%sum == 0){
       printf("%s\n", "Yes");
   }
   else {
       printf("%s\n", "No");
   }
   return 0;
}


Measured memory_bytes: 128
import sys
input=sys.stdin.buffer.readline
from math import*

n=int(input())
arr=list(map(int,input().split()))
brr=list(map(int,input().split()))
crr=list(map(int,input().split()))

ans=0
for i in range(n):
	if i!=0 and arr[i]==arr[i-1]+1:
			ans+=brr[arr[i]-1]+crr[arr[i-1]-1]
	else:
		ans+=brr[arr[i]-1]
print(ans)

Measured memory_bytes: 62236
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
using namespace std; using ll = long long; using pll = pair<ll, ll>;
using vl = vector<ll>; using vll = vector<vl>; using vpll = vector<pll>;
int ctoi(char c) {
	switch (c) {
	case '0': return 0; case '1': return 1; case '2': return 2;
	case '3': return 3; case '4': return 4; case '5': return 5;
	case '6': return 6; case '7': return 7; case '8': return 8;
	case '9': return 9;  default: return 0;
	}
}
bool pairCompare(const pll firstElof, pll secondElof)
{
	return firstElof.first > secondElof.first;
}
//**Snippetリスト**//
//rep, vin, all, iteLoop//
//gcdlcm, isPrime, eratos, divisor, modinv, bitSearch, bitList, dfs, bfs//
//dijkstra, UnionFind, COM, digitDP//
ll i, j, k, l; ll N, M, K, H, W, L;
ll MOD = 1000000007; ll INF = 9999999999999; ll ans = INF;
vl flag, color, D; vll path;
//***********//
int main() {
	string S;
	cin >> S;
	N = S.length();
	for (i = 0; i < N-2; i++) {
		ll P = abs(753 - (ctoi(S[i]) * 100 + ctoi(S[i + 1]) * 10 + ctoi(S[i + 2])));
		ans = min(ans, P);
	}
	cout << ans;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
static const int MAX = 200000;

int main() {
    int R[MAX], n;

    cin >> n;
    for (int i = 0; i < n; i++) cin >> R[i];

    int maxv = -2000000000;
    int minv = R[0];

    for (int i = 1; i < n; i++) {
        maxv = max(maxv, R[i] - minv);
        minv = min(minv, R[i]);        
    }

    cout << maxv << endl;

    return 0;
}


Measured memory_bytes: 3880
N = int(input())
first = input()
shiritori = [first]
t = 0
for i in range(N-1):
  lastword = shiritori[-1]
  nextword = input()
  lastchara = list(lastword)[-1]
  nextchara = list(nextword)[0]
  if lastchara == nextchara:
    shiritori.append(nextword)
    if shiritori.count(nextword) > 1:
      t += 1
  else:
    t += 1
if t == 0:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pii> pip;
typedef pair<pll, pll> P;
const ll INF = 1ll<<30;
const ll MOD = 1000000007;
const double EPS = 1e-9;
const bool debug = 0;
//---------------------------------//

int N;
ll A[112345];

ll calc(vector<ll> &v) {
	ll res = 0;
	FOR(i, 1, v.size()) res += abs(v[i] - v[i - 1]);
	return res;
}

int main() {
	cin >> N;
	REP(i, N) scanf("%lld", A + i);
	sort(A, A + N);
	
	vector<ll> v[2];
	v[0].push_back(A[N / 2]);
	v[1].push_back(A[(N - 1) / 2]);

	REP(i, N / 2) {
		v[0].push_back(A[i]);
		if (!(i == N / 2 - 1 && N % 2 == 0)) v[0].push_back(A[N - i - 1]);
		
		v[1].push_back(A[N - i - 1]);
		if (!(i == N / 2 - 1 && N % 2 == 0)) v[1].push_back(A[i]);
	}
	
	ll ans = max(calc(v[0]), calc(v[1]));
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 2924
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v).begin(), (v).end()
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define DEBUG
#define int long long
#define INF 1e18
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; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }
template<class T>void show(vector<T>v){for (int i = 0; i < v.size(); i++){cerr<<v[i]<<" ";}cerr<<"\n";}
typedef long long ll;

signed main()
{
    int n, m;
    cin >> n >> m;
    vector<int> a(n);
    REP(i,n){
        cin >> a[i];
    }
    sort(ALL(a));
    vector<int> rui(n + 1, 0);
    for (int i = 1; i <=n; i++)
    {
        rui[i] = rui[i - 1] + a[i - 1];
    }
    show(rui);
    int r = 1e6,l=0;
    int ans = 0;
    while (l + 1 < r)
    {
        int mid = (l + r) / 2;
        bool ok;
        int cnt = 0;
        int c = 0;
        for (int i = 0; i < n; i++)
        {
            int x = lower_bound(ALL(a), mid - a[i]) - a.begin();
            cnt += a[i]*(n-x)+(rui[n] - rui[x]);
            c += n - x;
            
        }
       // cerr << l << " " << r << endl;
        cerr << c << " " << cnt <<" "<<mid<< endl;
        ok = (c >= m ? 1 : 0);
      
        if (ok)
        {
            l = mid;
            ans =cnt - (c - m) * mid;
        }
        else{
            r = mid;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 2560
/*
    Life Before Death, Strength Before Weakness, Journey Before Destination
    ------------------------------------------------------------------------
    You don't become great by trying to be great.
    You become great by wanting to do something,
    and then doing it so hard that you become great in the process.
    */
 
    //#pragma comment(linker, ack:200000000")
    #pragma GCC optimize ("Ofast")
    #pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
    #include <bits/stdc++.h>
    using namespace std;
    
    #define TRACE
    
    #ifdef TRACE
    #define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
      cerr << name << " : " << arg1 << std::endl;
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
      const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
    #else
    #define trace(...)
    #endif
    
    #define rep(i, n)    for(ll i = 0; i < (n); ++i)
    #define repA(i, a, n)  for(ll i = a; i <= (n); ++i)
    #define repD(i, a, n)  for(ll i = a; i >= (n); --i)
    #define trav(a, x) for(auto& a : x)
    #define all(x) x.begin(), x.end()
    #define sz(x) (int)(x).size()
    #define fill(a)  memset(a, 0, sizeof (a))
    #define fst first
    #define snd second
    //#define mp make_pair
    #define pb push_back
    #define PI           3.141592653589793238462643383279502884197169399  /* pi */
    // #define te    
    typedef long double ld;
    typedef long long ll;
    typedef pair<ll, ll> pii;
    typedef vector<ll> vi;
    const int maxN = 100100;

    void solve() {
        ll n, cnt = 0;
        cin >> n;
        ll a[n];
        rep(i, n) cin >> a[i];
        //cout << "hola" << endl;
        if(a[0]!=0){
            cout << -1 << endl;
            return;
        } 
        repD(i, n-1, 1){
            if(a[i] > i) {
                cout << -1 << endl;
                return;
            }
            if(a[i-1] < a[i]){
                if(abs(a[i] - a[i-1]) > 1){
                    cout << -1 << endl;
                    return;       
                }
            } else cnt+=a[i-1];
        }   cnt+=a[n-1];
        cout << cnt << endl;
    }
 
    int main() {
      cin.sync_with_stdio(0); cin.tie(0);
      cin.exceptions(cin.failbit);
      // ll ti;   cin >> ti;  while(ti--)
      solve();
      return 0;
    } 

Measured memory_bytes: 1792
import java.util.Scanner;
public class Main {
    public static void main (String[] args) {
      
      Scanner scanner = new Scanner(System.in);
      int n = scanner.nextInt();
      int a1_1;
      int a1_2;
      int[][] a2 = new int[n][2];
      double pow1 = 0;
      double sqrt1 = 0;
      double all_qty = 0;

      for (int i = 0;  i < n  ; i ++ ) {
          a1_1 = scanner.nextInt();
          a1_2 = scanner.nextInt();
          a2[i][0] = a1_1;
          a2[i][1] = a1_2;
      }

      for (int i = 0;  i < n ; i ++ ) {
          for (int j = i + 1;  j < n ; j ++ ) {
             pow1 = (Math.pow((a2[i][0] - a2[j][0]), 2) + Math.pow((a2[i][1] - a2[j][1]), 2));
             sqrt1 = Math.sqrt(pow1);

             all_qty = all_qty + sqrt1;

          }
      }

      System.out.println(all_qty / ((double)n/2));
      
      return;
    }

 }


Measured memory_bytes: 22740
import sys
import math
import collections
import itertools
import array
import inspect

# Set max recursion limit
sys.setrecursionlimit(10000)


# Debug output
def chkprint(*args):
    names = {
        id(v): k
        for k, v in inspect.currentframe().f_back.f_locals.items()
    }
    print(', '.join(
        names.get(id(arg), '???') + ' = ' + repr(arg) for arg in args))


# Binary converter
def to_bin(x):
    return bin(x)[2:]


def li_input():
    return [int(_) for _ in input().split()]


# --------------------------------------------

dp = None


def main():
    A, B = li_input()
    print((A - 1) * (B - 1))


main()


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

using namespace std;

const int N = 10000 + 4;;

int n  , r;

int main()
{
    cin>>n>>r;
    int sol = 0;
    while(n)
    {
        n/=r;
        sol++;
    }
    cout<<sol;
    return 0;
}



Measured memory_bytes: 256
#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;
}
#define DEBUG
#ifdef DEBUG
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    os << '(' << p.first << ',' << p.second << ')';
    return os;
}
template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
    os << '{';
    for(int i = 0; i < (int)v.size(); i++) {
        if(i) {
            os << ',';
        }
        os << v[i];
    }
    os << '}';
    return os;
}
void debugg() { cerr << endl; }
template <class T, class... Args>
void debugg(const T &x, const Args &... args) {
    cerr << " " << x;
    debugg(args...);
}
#define debug(...)                                                             \
    cerr << __LINE__ << " [" << #__VA_ARGS__ << "]:", debugg(__VA_ARGS__)
#define dump(x) cerr << __LINE__ << " " << #x << " = " << (x) << endl
#else
#define debug(...) (void(0))
#define dump(x) (void(0))
#endif

struct Setup {
    Setup() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(15);
    }
} __Setup;

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

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

#include <atcoder/segtree>
using namespace atcoder;

int e() { return -INF; }

int op(int a, int b) { return max(a, b); }

int target;

bool f(int x) { return x < target; }

int main() {
    int N, Q;
    cin >> N >> Q;
    vector<int> a(N);
    for(int i = 0; i < N; i++) {
        cin >> a[i];
    }
    segtree<int, op, e> seg(a);

    while(Q--) {
        int t;
        cin >> t;
        if(t == 1) {
            int x, v;
            cin >> x >> v;
            x--;
            seg.set(x, v);
        } else if(t == 2) {
            int l, r;
            cin >> l >> r;
            l--;
            cout << seg.prod(l, r) << "\n";
        } else {
            int x;
            cin >> x >> target;
            x--;
            cout << seg.max_right<f>(x) + 1 << "\n";
        }
    }
}

Measured memory_bytes: 6088
#include "bits/stdc++.h"
using namespace std;

typedef long long int ll;
const int N=1e6+6;

ll arr[3][N],dp[3][N];

int main()
{
    ll n;cin>>n;
    for(int i=1;i<=2;i++)
    {
        for(int j=1;j<=n;j++)
            cin>>arr[i][j];
    }
    //dp[1][1]=arr[1][1];
    for(int i=1;i<=2;i++)
    {
        for(int j=1;j<=n+1;j++)
            {
                if(i==1)
                {
                    dp[i][j]=max(dp[i][j-1]+arr[i][j],dp[i][j]);
                    //cout<< dp[i][j]<< " ";
                }
                else
                {
                    dp[i][j]=max(dp[i-1][j]+arr[i][j],dp[i][j]);
                    dp[i][j]=max(dp[i][j-1]+arr[i][j],dp[i][j]);
                }
                //cout<<dp[i][j]<< " ";
            }
         //   cout<< "\n";
    }
    cout<< dp[2][n]<< "\n";


    return 0;
}


Measured memory_bytes: 8448
X, Y = [int(_) for _ in input().split()]

a_div = ((4*X-Y)/2)
a_mod = ((4*X-Y)%2)
b_div = ((Y-2*X)/2)
b_mod = ((Y-2*X)%2)

"""
print(a_div)
print(b_div)
print(a_mod)
print(b_mod)
"""

if( (a_div >= 0 and a_mod == 0) and (b_div >= 0 and b_mod == 0)):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 61696
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧  
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     
　　　　／　　　＼　 　  |　|     
　　　 /　　 /￣￣￣￣/　　|  
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿  
　 　　　＼/＿＿＿＿/　（u　⊃  
---------------------------------------------------------------------------------------------------*/





int N, A;
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> N >> A;
    int ans = N * N - A;
    cout << ans << endl;
}


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

typedef long long ll;

ll mod=1e9+7;

int main(){
  int n;
  string s,t;
  cin >> n >> s >> t;
  ll ans=1;
  ll count=0;
  ll now=0;
  for(int i=0;i<n;i++){
    if(s[i]==t[i]){
      if(now==0) ans=(ans*3)%mod;
      else if(now==1) ans=(ans*2)%mod;
      now=1;
    }
    else{
      count++;
      if(count==1){
        if(now==0) ans=(ans*6)%mod;
        else if(now==1) ans=(ans*2)%mod;
        else if(now==-1) ans=(ans*3)%mod;
      }
      else{
        count=0;
      }
      now=-1;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <bitset>
#include <utility>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
 
using namespace std;
typedef long long ll;
 
int main(){
  int N; cin >> N;
  int a,b,c;

  cin >> a >> b >> c;
  for(int i=1;i<N;i++){
    int ai,bi,ci,an,bn,cn;
    cin >> ai >> bi >> ci;
    an=max(b,c)+ai;
    bn=max(c,a)+bi;
    cn=max(a,b)+ci;

    a=an; b=bn; c=cn;
  }
  
  cout << max({a,b,c}) << endl;

  return 0;
}


Measured memory_bytes: 256
H, W = map(int, input().split())
C = [list(map(int, input().split())) for i in range(10)]
A = [list(map(int, input().split())) for i in range(H)]

def warshall_floyd(d):
    #d[i][j]: iからjへの最短距離
    for k in range(10):
        for i in range(10):
            for j in range(10):
                d[i][j] = min(d[i][j],d[i][k] + d[k][j])
    return d

##############################

d = [[float("inf") for i in range(10)] for i in range(10)] 
#d[u][v] : 辺uvのコスト(存在しないときはinf)
for i in range(10):
  for j in range(10):
    d[i][j] = C[i][j]

#print(warshall_floyd(d))

cost = warshall_floyd(d)

num = [0] * 10
for i in range(H):
  for j in range(W):
    if A[i][j] != -1:
      kazu = A[i][j]
      num[kazu] += 1
#print(num)
ans = 0
for i in range(10):
  ans += num[i] * cost[i][1]

print(ans)

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

int main() {
    int x1, y1, x2, y2, x3, y3, x4, y4;
    cin >> x1 >> y1 >> x2 >> y2;

    int vec23x = -1 * (y2 - y1), vec23y = x2 - x1, vec34x = -1 * (x2 - x1), vec34y = -1 * (y2 - y1);
    x3 = x2 + vec23x;
    y3 = y2 + vec23y;
    x4 = x3 + vec34x;
    y4 = y3 + vec34y;

    cout << x3 << " " << y3 << " " << x4 << " " << y4 << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin >> s;
    map<char,int>mp;
    mp[s[0]]++;
    mp[s[1]]++;
    mp[s[2]]++;
    if(mp['a']==1 && mp['b']==1 && mp['c']==1 )
        cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 3612
#include <iostream>
#include <cstdlib>
#include <time.h>
#include <algorithm>
#include <map>
#include <queue>
#include <stack>
#include <vector>
#include <array>
#include <string>
#include <iomanip>
#include <cstring>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define mp make_pair
#define eb emplace_back
#define F first
#define S second
using namespace std;
using namespace __gnu_pbds;

typedef long long int ll;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ost;

const ll maxN = 1e7;
const ll INF = 1e17;
const ll MOD = 1e9 + 7;

ll xs[] = {-1, 1, 0, 0, -1, 1, 1, -1};
ll ys[] = {0, 0, -1, 1, -1, 1, -1, 1};

ll segtree[maxN << 2];
ll lazy[maxN << 2];
ll A[maxN];

inline ll left(ll x){
	return x << 1;
}

inline ll right(ll x){
	return (x<<1) + 1;
}

void build(ll node, ll start, ll end){
	if(start == end)
		segtree[node] = A[start];
	else{
		ll mid = (start + end)/2;
		build(left(node), start, mid);
		build(right(node), mid+1, end);
		segtree[node] = segtree[left(node)] + segtree[right(node)];
	}
}

void update(ll node, ll start, ll end, ll l, ll r, ll val){
	if(lazy[node] != 0){
		segtree[node] += (end-start+1)*lazy[node];
		if(start != end){
			lazy[left(node)] += lazy[node];
			lazy[right(node)] += lazy[node];
		}
		lazy[node] = 0;
	}
	if(start > end or l > start or r < end)
		return ;
	else if(start >= l and r >= end){
		segtree[node] += val;
		if(start != end){
			lazy[left(node)] += val;
			lazy[right(node)] += val;
		}
	}
	else{
		ll mid=(start + end)/2;
		update(left(node), start, mid, l, r, val);
		update(right(node), mid+1, end, l, r, val);
		segtree[node] = segtree[left(node)] + segtree[right(node)];
	}
}

ll sums(ll node, ll start, ll end, ll l, ll r){
	if(lazy[node] != 0){
		segtree[node] += (end-start+1)*lazy[node];
		if(start != end){
			lazy[left(node)] += lazy[node];
			lazy[right(node)] += lazy[node];
		}
		lazy[node] = 0;
	}
	if(l > end or r < start or start > end)
		return 0;
	if(l <= start and r >= end)
		return segtree[node];
	ll mid = (start+end)/2;
	return sums(left(node), start, mid, l , r) + sums(left(node), mid + 1, end, l , r);
}

int main(){
	cin.sync_with_stdio(false);
	cin.tie(0);
	ll n;
	cin >> n;
	map<ll, pair<ll, ll> > ind;
	map<ll, ll> aind;
	ll a[n];
	ll b[n];
	for(ll i=0; i<n; i++){
		cin >> a[i];
		b[i] = a[i];
	}
	sort(b, b+n);
	for(ll i=0; i<n; i++){
		if(a[i] <= b[(n-1)/2])
			cout << b[(n)/2] << "\n";
		else
			cout << b[((n-1)/2)] << "\n";
	}
	return 0;
}

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

using namespace std;
typedef long long ll;
typedef pair<int, int> pint;
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define IREP(i, n) for(int i = (int)(n) - 1; i >= 0; i--)
#define ALL(x) (x).begin(), (x).end()
#define MOD 1000000007
#define IMAX INT_MAX
#define IMIN INT_MIN
#define LMAX LLONG_MAX
#define LMIN LLONG_MIN
template<typename T> inline void chmin(T &a, T b){ if(a > b) a = b; }
template<typename T> inline void chmax(T &a, T b){ if(a < b) a = b; }
template<typename T> inline void xch(T &a, T &b){ T w = a; a = b; b = w; }


int main() {
    bool b = false;
    int n;
    cin >> n;
    int p[n];
    REP(i, n) cin >> p[i];
    b = true;
    REP(k, n - 1){
        if(p[k] <= p[k + 1]) continue;
        b = false;
        break;
    }
    if(b){
        cout << "YES" << endl;
        return 0;
    }
    REP(i, n){
        REP(j, n){
            if(i < j){
                xch(p[i], p[j]);
                b = true;
                REP(k, n - 1){
                    if(p[k] <= p[k + 1]) continue;
                    b = false;
                    break;
                }
                if(b){
                   cout << "YES" << endl;
                    return 0;
                }
                xch(p[i], p[j]);
            }
        }
    }
    cout << "NO" << endl;
    return 0;
}








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

int main(){
  int h,w;
  while(cin>>h>>w, h+w){
    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
	cout<<"#";
      }
      cout<<endl;
    }
    cout<<endl;
  }
  return 0;
}

Measured memory_bytes: 1152
#include<iostream>

using namespace std;

int main(void){

    int n; cin >> n;
    int ans = 0;

    for(int i = 1;i <= n;i += 2){
        for(int j = 2;j <= n; j += 2){
            ans++;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main(){
    int flag=0;
    char S[4];
    scanf("%s",S);
    for(int i=0;i<4;i++){
        if(S[i]==S[i+1]){
            flag++;
        }
    }
    if(flag==0){
        puts("Good");
    }else{
        puts("Bad");
    }

    return 0;
}


Measured memory_bytes: 128
#include <stdio.h>
int main(void){
    int a,b,c;
    scanf("%d%d%d",&a,&b,&c);
    if(a==b&&a==c) printf("1");
    else if(a==b||a==c||b==c) printf("2");
    else printf("3");
    return 0;
}

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

int main(){
    int x,a,b;
    cin >> x >> a >> b;

    if(-a + b <= 0){
        cout << "delicious" << endl;
    }
    else if(-a + b <= x){
        cout << "safe" << endl;
    }
    else if(-a + b > x){
        cout << "dangerous" << endl;
    }
}

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

#define ll long long int
void fast()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
}
const ll maxk = 3e3 + 2;
ll n;
ll dp[maxk][maxk];
bool vis[maxk][maxk];
ll v[maxk];
ll go(ll st=0,ll end=n-1)
{	
	if(vis[st][end])
	return dp[st][end];
	vis[st][end]=1;
	if(st==end)
	{
		return dp[st][end]=v[st];
	}
	return dp[st][end]=max(v[st]-go(st+1,end),v[end]-go(st,end-1));

}
int main()
{
	fast();
	cin>>n;
	
	for(ll i=0;i<n;i++)
	{
		cin>>v[i];
		
	}
	
	cout<<go()<<endl;
}

Measured memory_bytes: 78464
#include <iostream>

using namespace std;

int main()
{
    int D ,T, S;

    cin>>D>>T>>S;
   if(1<=D && D<=10000 && 1<=T && T<=10000 && 1<=S && S<=10000 )
    
    {
    float d=(float)D/S;
     
    if(d<=T)
    {
    cout<<"Yes";
    }
    else
    cout<<"No";
    
    return 0;
    }
}

Measured memory_bytes: 3628
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
#include <time.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


#define NUM 1000001

struct Node{
	int parent_id,children[128],suffix_link;
	bool finish_FLG;
};

struct Info{
    Info(int arg_node_id,int arg_ch){
        node_id = arg_node_id;
        ch = arg_ch;
    }

    int node_id,ch;
};

int T_length,P_length;
int index = 1;
char T[NUM],P[10001];
Node nodes[10005];

int main(){

	scanf("%s",T);
	for(T_length = 0; T[T_length] != '\0'; T_length++);

	scanf("%s",P);
	for(P_length = 0; P[P_length] != '\0'; P_length++);

	int root = 0;
	nodes[root].suffix_link = -1;

	for(int i = 0; i <= P_length+1; i++){
		nodes[i].parent_id = -1;
		nodes[i].finish_FLG = false;
		for(int k = 0; k < 128; k++){
			nodes[i].children[k] = -1;
		}
	}

	int tmp_ch,tmp_loc,parent_id,tmp_index;

	tmp_index = 0;
	tmp_ch = P[tmp_index];

	tmp_loc = root;

	while(true){

		parent_id = tmp_loc;

		nodes[tmp_loc].children[tmp_ch] = index++;

		tmp_loc = nodes[tmp_loc].children[tmp_ch];
		nodes[tmp_loc].parent_id = parent_id;

		tmp_index++;

		if(P[tmp_index] == '\0'){
			nodes[tmp_loc].finish_FLG = true;
			break;
		}
		tmp_ch = P[tmp_index];
	}

	int node_id;
	queue<Info> MAKE_SL;
	for(int i = 0; i < 128; i++){
		if(nodes[root].children[i] != -1){
			node_id = nodes[root].children[i];
			nodes[node_id].suffix_link = root;
			for(int k = 0; k < 128; k++){
				if(nodes[node_id].children[k] != -1){
					MAKE_SL.push(Info(nodes[node_id].children[k],k));
				}
			}
		}
	}

	while(!MAKE_SL.empty()){
		node_id = MAKE_SL.front().node_id;
		tmp_ch = MAKE_SL.front().ch;
		MAKE_SL.pop();

		for(int i = 0; i < 128; i++){
			if(nodes[node_id].children[i] != -1){
				MAKE_SL.push(Info(nodes[node_id].children[i],i));
			}
		}

		for(tmp_loc = nodes[nodes[node_id].parent_id].suffix_link; tmp_loc != root; tmp_loc = nodes[tmp_loc].suffix_link){
			if(nodes[tmp_loc].children[tmp_ch] != -1){
				break;
			}
		}

		if(tmp_loc == root){
			if(nodes[root].children[tmp_ch] != -1){
				nodes[node_id].suffix_link = nodes[root].children[tmp_ch];
			}else{
				nodes[node_id].suffix_link = root;
			}
		}else{
			nodes[node_id].suffix_link = nodes[tmp_loc].children[tmp_ch];
		}
	}

	tmp_loc = root;
	for(int i = 0; i < T_length; i++){
		tmp_ch = T[i];

		if(nodes[tmp_loc].children[tmp_ch] != -1){
			tmp_loc = nodes[tmp_loc].children[tmp_ch];

			if(nodes[tmp_loc].finish_FLG){
				printf("%d\n",i-P_length+1);
				tmp_loc = nodes[tmp_loc].suffix_link;
			}
		}else{

			if(tmp_loc == root)continue;

			for(tmp_loc = nodes[tmp_loc].suffix_link; tmp_loc != root; tmp_loc = nodes[tmp_loc].suffix_link){
				if(nodes[tmp_loc].children[tmp_ch] != -1){
					break;
				}
			}
			if(nodes[tmp_loc].children[tmp_ch] != -1){
				tmp_loc = nodes[tmp_loc].children[tmp_ch];
			}else{
				//Do nothing
			}
		}
	}

	return 0;
}



Measured memory_bytes: 9348
#include <iostream>
#include <algorithm>

using namespace std;

int main() {
    int N, X;
    cin >> N >> X;

    int sum = 0;
    int min = 1'000'000'000;
    for (int i = 0; i < N; ++i) {
        int m;
        cin >> m;
        sum += m;
        if (min > m) min = m;
    }

    cout << N + (X - sum) / min << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define F first
#define S second

using namespace std;
typedef pair<int,int> P;

const int MOD=1000000007;
int INF=100100100100100;
int keta(int n){
  if(n==0)return 0;
  return keta(n/10)+1;
}
signed main(){
  int n;int ans=0;
  cin>>n;
  rep(i,n+1){
    if(i==0)continue;
    if(keta(i)%2==1)ans++;
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 3596
input_nums = []
input_count = 5

for i in range(0,input_count):
  input_nums.append(int(input()))

allowed_distance = int(input())

for i in range(0,input_count):
  for j in range(i+1,input_count):
    #print('i:',i,'j:',j)
    if (input_nums[j] - input_nums[i]) > allowed_distance:
      print(':(')
      exit()

print('Yay!')

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define inf (ll)1e9
#define d(x) cerr<<#x<<"="<<x<<endl;
#define p(x) cout<<x<<endl
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define minel(v) *min_element(all(v))
#define minind(v) distance((v).begin(), min_element(all(v)))
#define maxel(v) *max_element(all(v))
#define maxind(v) distance((v).begin(), max_element(all(v)))
typedef vector<int> vi;

string a;
int n,q,l,r;
int cum[100002];
int prevf;

int main(void){
    //01122233
    //左が変化点3-(3-3)-1
    //左が変化点でない3-(3-1)-1
    cin>>n>>q>>a;
    rep(i,n){
        if(i>0)cum[i]+=cum[i-1];
        if(i>0 && a[i-1]=='A' && a[i]=='C')cum[i]++;
    }
    rep(i,q){
        cin>>l>>r;
        l--;r--;
        //d(cum[l]);d(cum[r]);d(cum[n-1]);
        p(cum[r]-cum[l]);
    }
    //rep(i,n)p(cum[i]);
    return 0;
}



Measured memory_bytes: 1408
#include <iostream>
#include <cstdio>
#include <vector>
using namespace std;
string s;
int main(){
    short n,mod=26,u;
    cin>>n>>s;
    for (int i=0,ii=s.size();i<ii;++i){
        u=s[i]-'A';
        u=(u+n)%mod;
        s[i]=u+'A';
    }
    cout<<s;
}


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


class Program
{


    static void Main(string[] args)
    {
        Solve();
    }

    static void Solve()
    {
        Scan sc = new Scan();
        write wr = new write();

        var s = sc.intarr;

        int a = s[0];
        int b = s[1];
        int c = s[2];

        long target = Math.Max(Math.Max(a, b), c);

        if ((3 * target - (a + b + c) )% 2 == 1) target++;

        wr.wri((3 * target - (a + b + c)) / 2);

    }


}
    class Scan
    {
        public string str => Console.ReadLine();

        public string[] strarr => str.Split(' ');

        public long[] longarr => strarr.Select(long.Parse).ToArray();
        public int[] intarr => strarr.Select(int.Parse).ToArray();
        public char[] chararr => str.ToArray();


}



class write
{
    public void wri<Type>(Type x)
    {
        Console.WriteLine(x);
    }
}


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

int main(){
    int n, r;
    cin >> n >> r;
    if(n >= 10) cout << r << endl;
    else cout << (r + 100*(10-n)) << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<algorithm>
#define LL long long
#define INF 0x3f3f3f3f
//#define io ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
const int MAXN = 405;
const LL mod = 1e9+7;
LL sum[MAXN];
LL A[MAXN],B[MAXN];
LL dp[MAXN][MAXN];
LL N,C;
using namespace std;
 
LL calc(int a, int b)
{
    memset(sum,0,sizeof(sum));
    for(int i = a; i <= b; ++i)
    {
        LL t = 1;
        for(int j = 0; j <= C; ++j)
        {
            sum[j] = sum[j]+t;
            sum[j] %= mod;
            t = t*i%mod;
        }
    }
}
 
int main()
{
    //io;
    cin >> N >> C;
    for(int i = 1; i <= N; ++i)
        cin >> A[i];
    for(int i = 1; i <= N; ++i)
        cin >> B[i];
    dp[0][0] = 1;
    for(int i = 1; i <= N; ++i)
    {
        calc(A[i],B[i]);//计算A[i]^m + (A[i]+1)^m + ... + B[i]^m
        for(int j = 0; j <= C; ++j)
            for(int k = 0; k <= j; ++k)
                dp[i][j] = (dp[i][j] + dp[i-1][j-k]*sum[k])%mod;
    }
    cout << dp[N][C] << endl;
    return 0;
}


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

int main(){
	int e;
	int x,y,z;
	int y2,z3;
	while(cin>>e,e){
		int ans=1<<30;
		for(z=0;(z3=z*z*z)<=e;z++){
			for(y=0;(y2=y*y)+z3<=e;y++){
				ans = min(ans,e-z3-y2+y+z);
			}
		}
		cout<<ans<<endl;
	}
	return 0;
}

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

int main(){
  int n,temp,c=0;
  cin>>n;
  int d[n];
  for(int i=0;i<n;i++){
    cin>>d[i];
  }

  for(int i=0;i<n-1;i++){
    for(int j=i+1;j<n;j++){
      if(d[i] < d[j]){
        temp=d[i];
        d[i]=d[j];
        d[j]=temp;
      }
    }
  }

  for(int i=0;i<n-1;i++){
    for(int j=i+1;j<n;j++){
      if(d[i] == d[j]){
        d[j]=0;
      }
    }
  }

  for(int i=0;i<n;i++){
    if(d[i]!=0){
      c++;
    }
  }

  cout<<c<<endl;

  return 0;
}

Measured memory_bytes: 256
package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	for scanner.Scan() {
		lineArgs := strings.Fields(scanner.Text())
		x, _ := strconv.Atoi(lineArgs[0])
		y, _ := strconv.Atoi(lineArgs[1])
		if x == 0 && y == 0 {
			break
		} else {
			chkPrint(x, y)
		}
	}
}

func chkPrint(x int, y int) {
	if x > y {
		fmt.Printf("%d %d\n", y, x)
	} else {
		fmt.Printf("%d %d\n", x, y)
	}
}


Measured memory_bytes: 1184
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        try(Scanner sc = new Scanner(System.in)){
            String line = sc.nextLine();
            int length = line.length();
            char result[] = new char[length];
            for(int i=0; i<length; i++){
                char ch = line.charAt(i);
                if(Character.isLowerCase(ch) == true) result[i] = Character.toUpperCase(ch);
                else if(Character.isUpperCase(ch) == true) result[i] = Character.toLowerCase(ch);
                else result[i] = ch; 
            }
            System.out.println(result);
        }
    }
}


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

int main(){
  long n, k;
  cin >> n >> k;
  long p, m;
  p = n % k;
  m = -(p - k);
  if(p >= m){
  	n = m;
  }
  else{
  	n = p;
  }
  cout << n << endl;
  return 0;
}

Measured memory_bytes: 3644
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int num = in.nextInt();
        int[] value = new int[num];
        int a = 0;
        int b = 0;
        for (int i = 0; i < num; i++){
            value[i] = in.nextInt();
            if (a < value[i]) {
                b = a;
                a = value[i];
            } else if (b < value[i]) {
                b = value[i];
            }
        }
        in.close();
        for (int i = 0; i < num; i++) {
            if (a == value[i]) {
                System.out.println(b);
            } else {
                System.out.println(a);
            }
        }
    }
}


Measured memory_bytes: 87220
#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 ll long long int
const int INF = 2147483647;

using namespace std;

int main()
{
  int n, k;
  cin >> n >> k;
  int ans = 1;
  REP(i, n)
  {
    if (ans + k < ans * 2)
    {
      ans += k;
    }
    else
    {
      ans *= 2;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();

		//個数を求めるだけだから、全探索不要。
		//基本的に、a,b,cすべてがkの倍数のとき、条件を満たす。
		//例外として、nが偶数、a,b,cすべてが (sk - k / 2) (sは任意の正の整数)で
		//表されるとき、条件を満たす。

		//n以下のkの倍数の個数を求める。
		int multNum = n / k;
		long count = multNum;
		count *= multNum;
		count *= multNum;

		//n以下の(sk - k / 2) (sは任意の正の整数)の個数を求める。
		long exCount = 0;
		if (k % 2 == 0) {
			int exNum = (multNum * k + k / 2 <= n) ? multNum + 1: multNum;
			exCount = exNum;
			exCount *= exNum;
			exCount *= exNum;
		}

		//出力する
		System.out.println(count + exCount);

	}

}


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

using namespace std;
using ll = long long;

int main(){
  ll n;
  cin >> n;
  vector<ll> a(n);
  vector<ll> cnt(n, 0);
  ll sum = 0;
  map<ll, ll> ma;
  for(int i=0; i<n; i++) cin >> a[i];
  
  for(int i=0; i<n; i++){
    ma[a[i]]++;
  }
  
  for(auto it:ma) sum += it.second*(it.second-1)/2;
  
  for(int i=0; i<n; i++){
    sum += cnt[i]*(cnt[i]-1)/2;
  }
  
  for(int i=0; i<n; i++){
    ll val = ma[a[i]];
    ll before = val*(val-1)/2;
    ll after =  (val-1)*(val-2)/2;
    cout << sum - before + after << endl;
  }

  return 0;
}

Measured memory_bytes: 14240
n=int(input())
numbers=list(map(int,input().split()))
count=1
c=0
for i in range(n-1):
  if numbers[i] is numbers[i+1]:
    count+=1
  else:
  	c+=count//2
  	count=1
if count-1:
	c+=count//2
print(c)


Measured memory_bytes: 3060
import heapq

N = int(input())
cities = [0 for _ in range(N)]

for i in range(N):
    x, y = map(int, input().split())
    cities[i] = (i, x, y)

edges = [[] for _ in range(N)]

cities.sort(key=lambda A : A[1])
for i in range(N - 1):
    a, xFrom, yFrom = cities[i]
    b, xTo, yTo = cities[i + 1]
    cost = min(abs(xFrom - xTo), abs(yFrom - yTo))

    edges[a].append((cost, b))
    edges[b].append((cost, a))

cities.sort(key=lambda A : A[2])
for i in range(N - 1):
    a, xFrom, yFrom = cities[i]
    b, xTo, yTo = cities[i + 1]
    cost = min(abs(xFrom - xTo), abs(yFrom - yTo))

    edges[a].append((cost, b))
    edges[b].append((cost, a))

vertex = set([0])
newEdge = []
que = []

for cost, to in edges[0]:
    heapq.heappush(que, (cost, to))

ans = 0
while len(vertex) < N:
    cost, now = heapq.heappop(que)
    if now in vertex:
        continue
    ans += cost
    vertex.add(now)
    for c, to in edges[now]:
        if not to in vertex:
            heapq.heappush(que, (c, to))

print(ans)

Measured memory_bytes: 77300
#include <iostream>
#include <string>
#include <algorithm> 
#include <cstdlib>
#include <map>
#include <queue>
#include <vector>
#include <utility>
#include <climits>
#include <numeric>
#define ll long long
#define INF INT_MAX 
using namespace std;
int main(){
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    int x,y;
    x=c-a;
    y=d-b;
    int e,f,g,h;
    e = c-y;
    f = d+x;
    g = e-x;
    h = f-y;
    printf("%d %d %d %d\n",e,f,g,h);
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <utility>
#include <iomanip>
#include <functional>
#include <queue>
#include <stack>
#include <cmath>
#define INF 10000000000000000
#define MOD 1000000007
using namespace std;




int main(){
    int beki[1000]={};
    beki[0]=1;
    beki[1]=1;
    
    for(int i=2; i<40; i++){
        int temp=i*i;
        while(temp<=1000){
            beki[temp]=1;
            temp*=i;
        }
    }
    
    int X;
    cin >> X;
    for(int i=X; ; i--){
        if(beki[i]==1){
            cout<<i<<endl;
            break;
        }
    }
    
    return 0;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
	#define PI 			acos(-1)
	#define mp			make_pair
	#define pb			push_back
	#define all(a)		(a).begin(), (a).end()
	#define srt(a)			sort(all(a))
	#define mem(a, h)	memset(a, (h), sizeof(a))
	#define f 			first
	#define s 			second
	#define MOD			1000000007
	int in(){int r=0,c;for(c=getchar();c<=32;c=getchar());if(c=='-') return -in();for(;c>32;r=(r<<1)+(r<<3)+c-'0',c=getchar());return r;}

	using namespace std;

	typedef long long 		ll;
	typedef unsigned long long 		ull;
	typedef pair<int, int>  ii;
	typedef vector<int>     vi;
	typedef vector<ii>      vii;
	typedef vector<ll>      vll;
	int main()
	{
		//ios::sync_with_stdio(false); cin.tie(0);
		//freopen("", "r", stdin);
		//freopen("", "w", stdout);
		int n,pa;
		cin>>n;
		queue<pair<int,int> > que;
		int nu=1,se=1;
			while(nu*9<=n)
				nu*=9;
			while(se*6<=n)
				se*=6;
		que.push(mp(n-nu,1));
		que.push(mp(n-se,1));
		while(true)
		{
			n = que.front().f;
			pa = que.front().s;
			if(n==0)
			{
				cout<<pa<<endl;
				return 0;
			}
			nu=se=1;
			while(nu*9<=n)
				nu*=9;
			while(se*6<=n)
				se*=6;
			que.push(mp(n-nu,pa+1));
			que.push(mp(n-se,pa+1));
			que.pop();
		}
		return 0;
	}

Measured memory_bytes: 768
#include<stdio.h>

int main(void){
    int N;
    scanf("%d",&N);
    if(N==1){
        printf("Hello World");
        return 0;
    }
    else{
        int A,B;
        scanf("%d",&A);
        scanf("%d",&B);
        printf("%d",A+B);
        return 0;
    }
    return 0;
}

Measured memory_bytes: 128
package main

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

func newScanner() *bufio.Scanner {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	return scanner
}

func scanInt() int {
	sc.Scan()
	v, _ := strconv.Atoi(sc.Text())
	return v
}

func scanString() string {
	if sc.Scan() {
		return sc.Text()
	}
	panic(sc.Err())
}

var sc = newScanner()

type node struct {
	key        int
	prev, next *node
}

func delete(n *node) {
	n.prev.next, n.next.prev = n.next, n.prev
}

func main() {
	n := scanInt()
	f, l := &node{-1, nil, nil}, &node{-1, nil, nil}
	f.next = l
	l.prev = f

	for i := 0; i < n; i++ {
		op := scanString()
		switch op {
		case "insert":
			x := scanInt()
			t := &node{x, f, f.next}
			f.next, f.next.prev = t, t
		case "delete":
			x := scanInt()
			a := f.next
			for a != nil {
				if a.key == x {
					delete(a)
					break
				}
				a = a.next
			}
		case "deleteFirst":
			delete(f.next)
		case "deleteLast":
			delete(l.prev)
		}
	}

	w := bufio.NewWriter(os.Stdout)
	a := f.next
	for a != nil && a.key != -1 {
		fmt.Fprint(w, a.key)
		a = a.next
		if a != nil && a.key != -1 {
			fmt.Fprint(w, " ")
		}
	}
	fmt.Fprintln(w)
	w.Flush()
}



Measured memory_bytes: 49680
using System;
using System.Collections.Generic;
using System.Linq;
using static Library.Input;

namespace AtCoderTemplate {
    class ProgramF {
        static int[][] dp;
        static int[] weight;
        static int n;

        static void Main () {
            while (true)
            {
                n = NextInt;
                if (n == 0) return;
                weight = IntList.ToArray();
                dp = Enumerable.Range(0, n).Select(_ => Enumerable.Repeat(-1, n).ToArray()).ToArray();

                System.Console.WriteLine(Memo(0, n - 1));
            }
        }

        static int Memo(int left, int right) {
            if (dp[left][right] != -1) return dp[left][right];
            if (left == right) return dp[left][right] = 0;
            if (right - left == 1) return dp[left][right] = Math.Abs(weight[right] - weight[left]) <= 1 ? 2 : 0;

            // 中と外で区切る
            if (Math.Abs(weight[left] - weight[right]) <= 1 && Memo(left + 1, right - 1) == right - left - 1)
                return dp[left][right] = Memo(left + 1, right - 1) + 2;

            // 左と右で区切る
            return dp[left][right] = Enumerable.Range(left, right - left).Max(i => Memo(left, i) + Memo(i + 1, right));
        }
    }

}

namespace Library {
    class Input {
        static IEnumerator<string> enumerator = new string[] { }.AsEnumerable ().GetEnumerator ();

        public static string Line => Console.ReadLine ();

        public static string[] StrArr => Line.Split (' ');

        public static int NextInt => int.Parse (NextWord ());

        public static long NextLong => long.Parse (NextWord ());

        public static List<int> IntList => StrArr.Select (int.Parse).ToList ();

        public static List<long> LongList => StrArr.Select (long.Parse).ToList ();

        public static IEnumerable<long[]> TakeLine (int N) {
            return Enumerable.Repeat (0, N).Select (_ => Console.ReadLine ().Split (' ').Select (long.Parse).ToArray ());
        }

        public static string NextWord () {
            while (!enumerator.MoveNext ()) {
                enumerator = StrArr.AsEnumerable ().GetEnumerator ();
            }
            return enumerator.Current;
        }
    }
}


Measured memory_bytes: 38524
#include <iostream>
#include <fstream>
#include <vector>
#include <queue>
#include <string>
#include <limits>
#include <algorithm>
#include <map>

using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;

using namespace std;

int main()
{
  ll N;
  cin >> N;
  vector<string> ws(N);
  vector<string> ws2(N);
  for (auto i = 0; i < N; i++) {
    cin >> ws[i];
    ws2[i] = ws[i];
  }
  sort(ws2.begin(), ws2.end());
  for (auto i = 1; i < N; i++) {
    if (ws2[i-1] == ws2[i]) {
      cout << "No" << endl;
      return 0;
    }
  }

  for (auto i = 1; i < N; i++) {
    if (ws[i][0] != ws[i-1][ws[i-1].size()-1]) {
      cout << "No" << endl;
      return 0;
    }
  }


  cout << "Yes" << endl;


  return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main
{
  public static void main(String args[])
  {
    Scanner sc = new Scanner(System.in);
    String s = sc.next();
    int fla =0;
    for(int i=0;i<s.length()-1;i++)
    {
        if(s.charAt(i) == s.charAt(i+1) )
            fla =1;
    }
    if(fla == 1)
    System.out.println("Bad");
    else
    System.out.println("Good");
    
    
  }
}

Measured memory_bytes: 21844