akhauriyash/Code-Regression huggingface dataset:
N,M=map(int,input().split())
AB=[list(map(int,input().split())) for _ in range(N)]
CD=[list(map(int,input().split())) for _ in range(M)]

ans=[]
for ab in AB:
  min_m=10**10
  for i,cd in enumerate(CD):
    #print(ab[0],ab[1],cd[0],cd[1],abs(ab[0]-cd[0])+abs(ab[1]-cd[1]))
    m=abs(ab[0]-cd[0])+abs(ab[1]-cd[1])
    if min_m>m:
      min_m=m
      min_i=i+1
  ans.append(min_i)
#print(ans)

for a in ans:
  print(a)

Measured memory_bytes: 3064
import           Control.Monad
import           Data.Array
import qualified Data.ByteString.Char8 as BS
import           Data.List
import           Data.Maybe
import           Data.Ord

readInts :: IO [Int]
readInts = map (fst . fromJust . BS.readInt) . BS.words <$> BS.getLine

main = do
  n <- read <$> getLine
  nums <- readInts
  print $ solve n 0 nums

solve :: Int -> Int -> [Int] -> Int
solve n acc []
  | acc == 0 = -1
  | otherwise = n - acc
solve n acc (x:xs)
  | acc + 1 == x = solve n x xs
  | otherwise = solve n acc xs


Measured memory_bytes: 4348
import std.algorithm, std.conv, std.range, std.stdio, std.string;

void main()
{
  auto n = readln.chomp.to!size_t;
  auto root = new RootNode!int;

  foreach (_; n.iota) {
    auto rd = readln.chomp.splitter(' '), cmd = rd.front;
    switch (cmd) {
    case "insert":
      rd.popFront;
      root.insert(rd.front.to!int);
      break;
    case "print":
      root.inorderWalk;
      root.preorderWalk;
      break;
    default:
      assert(0);
    }
  }
}

class Node(T)
{
  T key;
  Node l, r;

  this(T key)
  {
    this.key = key;
  }

  void insert(T val)
  {
    if (val < key) {
      if (l is null) l = new Node(val);
      else l.insert(val);
    } else {
      if (r is null) r = new Node(val);
      else r.insert(val);
    }
  }

  void inorderWalk()
  {
    if (l !is null) l.inorderWalk;
    write(" ", key);
    if (r !is null) r.inorderWalk;
  }

  void preorderWalk()
  {
    write(" ", key);
    if (l !is null) l.preorderWalk;
    if (r !is null) r.preorderWalk;
  }
}

class RootNode(T)
{
  Node!T n;

  void insert(T val)
  {
    if (n is null) n = new Node!T(val);
    else n.insert(val);
  }

  void inorderWalk()
  {
    if (n !is null) n.inorderWalk;
    writeln;
  }

  void preorderWalk()
  {
    if (n !is null) n.preorderWalk;
    writeln;
  }
}

Measured memory_bytes: 37408
#include <bits/stdc++.h>
#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 namespace std;
int main() {
  long n;
  cin>>n;
  
  long ans=1;
  long m=1;
  vector<long>a(n);
  rep(i,n){
    cin>>a.at(i);
    ans*=3;
    if(a.at(i)%2==0){
      m*=2;
    }
  }
  ans-=m;
  cout<<ans<<endl;
}



Measured memory_bytes: 256
import java.util.Arrays;
import java.util.*;
public class Main{
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
      int h = sc.nextInt();
      int n = sc.nextInt();
      int[] a = new int[n];
      for(int i=0;i<n;i++){
        a[i] = sc.nextInt();
      }
      int total = 0;
      for(int i=0;i<n;i++){
        total += a[i];
      }
      if(h<=total){
        System.out.println("Yes");
      }else{
        System.out.println("No");
      }

    }
}


Measured memory_bytes: 49748
#include <bits/stdc++.h>
#define ALL(v) v.begin(), v.end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
using namespace std;
typedef long long ll;
 
int main(){
 int h,w;
  cin>>h>>w;
  char masu[h][w];
  queue<pair<ll, ll>> que;
  
  rep(i, h){
    rep(j, w){
      cin>>masu[i][j];
    }
  }
  
  int dx[4]={1,0,-1,0};
  int dy[4]={0,1,0,-1};
  int dis[1010][1010];
  
  
  rep(i, h){
    rep(j, w){
      dis[i][j]=100000000;
      if(masu[i][j]=='#'){
        dis[i][j]=0;
        que.push(pair<ll, ll>(i, j));
      }
    }
  }
  
  while(que.size()){
    int x=que.front().first, y=que.front().second;
    que.pop();
    rep(i, 4){
      int nx=x+dx[i];
      int ny=y+dy[i];
    if(nx>=0 && nx<h && ny>=0 && ny<w && dis[nx][ny]>dis[x][y]+1){
      que.push(pair<ll, ll>(nx, ny));
      dis[nx][ny]=dis[x][y]+1;
    }
    }
  }
  
  int ans=-1;
  rep(i, h){
    rep(j, w){
      ans=max(ans,dis[i][j]);
    }
  }
  
  
  cout<<ans<<endl;
  
 
}

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

using namespace std;



int main(){
	char c[6];
	for(int i = 0; i < 6; i++)
		cin >> c[i];
	
	if(c[0] == c[5] && c[1] == c[4] && c[2] == c[3])
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
	
	return 0;
}

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

int main() {
	int n,l;
	cin >> n >> l;
	vector<string> s(n);
	for(int i = 0;i < n;i++)
	{
		cin >> s.at(i);
	}
	sort(s.begin(),s.end());
	for(int i = 0;i < n;i++)
	{
		cout << s.at(i);
	}
}


Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <iostream>
#include <string>
#include <utility>
#include <vector>

using namespace std;
using ll = long long int;

template <class T> ostream &operator<<(ostream &os, vector<T> &v) {
  for (auto i = v.begin(); i != v.end(); i++) {
    os << *i << " ";
  }
  return os;
}

ll gcd(ll a, ll b) {
  ll tmp;
  if ( b > a) {
    tmp = a;
    a = b;
    b = tmp;
  }
  while (a % b !=0) {
    tmp = b;
    b = a % b;
    a = tmp;
  }
  return b;
}

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

int main(void) {
  int n;

  cin>>n;
  vector<int> v(n);
  for(int i=0; i<n; i++) {
    cin>>v[i];
  }
  int m = -1;
  int one;
  int sec;
  for(int i=0; i<n; i++) {
    if (m < v[i]) {
      m = v[i];
      one = i;
    }
  }
  m = -1;
  for(int i=0; i<n; i++) {
    if (i == one)
      continue;
    if (m < v[i]) {
      m = v[i];
      sec = i;
    }
  }
  for(int i=0; i<n; i++) {
    if (i==one)
      std::cout << v[sec] << std::endl;
    else
      std::cout << v[one] << std::endl;
  }
  return 0;
}



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

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

  int ans = 0;
  while (ans * (ans + 1) / 2 < X) ans++;
  cout << ans << endl;
  return 0;
}

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

int a,b,c,d;
int main(){
  cin >> a >> b >> c >> d;
  int push = max(a,c);
  int release = min(b,d);
  if(release - push > 0) cout << release - push << endl;
  else cout << 0 << endl;
}


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

using ll = long long;

const int INF = 1001001001;
const ll INF_LL = 1001001001001001001LL;

int main(void){
  int n; cin >> n;
  if(n==1) cout << "Hello World" << endl;
  else{
    int a,b; cin >> a >> b;
    cout << a+b << endl;
  }
  
  return 0;
}


Measured memory_bytes: 3572
# 2019/08/15

n=int(input())
x=list(map(int,input().split()))

res=float('inf')
for y in range(min(x),max(x)+1):
    cnt=0
    for i in range(n):
        cnt+=(x[i]-y)**2
    res=min(res,cnt)
print(res)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;

void Main() {
  ll n;
  R n;
  for(int i=111; i<1000; i+=111) {
    if(n<=i) {
      pr(i);
      return;
    }
  }
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
a.sort()

def gozyo():
    global a
    for i in range(1,len(a)):
        a[i]%=a[0]
    a.sort()
    while a[0]==0:
        a.pop(0)

while len(a)>1:
    gozyo()
print(a[0])

Measured memory_bytes: 14252
# Zalgo
# https://drken1215.hatenablog.com/entry/2019/09/16/014600


def z_algo(s: str) -> list:
    """LCP(0,i)のlist"""
    N = len(s)
    ret = [-1] * N
    ret[0] = N
    i, j = 1, 0
    while i < N:
        while i + j < N and s[j] == s[i + j]:
            j += 1
        ret[i] = j
        if j == 0:
            i += 1
            continue
        k = 1
        while i + k < N and k + ret[k] < j:
            ret[i + k] = ret[k]
            k += 1
        i += k
        j -= k
    return ret


def main():
    N = int(input())
    s = input()

    ans = 0

    t = ''
    for c in reversed(s):
        t = c + t
        lcp = z_algo(t)
        for d, x in enumerate(lcp):
            ans = max(ans, min(x, d))

    print(ans)


if __name__ == '__main__':
    main()


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

stack<char> sa;
stack<char> sb;
stack<char> sc;

int main(){
	string a,b,c;
  cin>>a>>b>>c;
  for(int i=a.size()-1;i>=0;i--){
  	sa.push(a[i]);
  }
  for(int i=b.size()-1;i>=0;i--){
  	sb.push(b[i]);
  }
  for(int i=c.size()-1;i>=0;i--){
  	sc.push(c[i]);
  }
  char val='a';
  while(true){
  	if(val=='a'){
    	val=sa.top();
      sa.pop();
    }
    else if(val=='b'){
    	val=sb.top();
      sb.pop();
    }
    else{
      val=sc.top();
      sc.pop();
    }
    if(sa.size()==0 &&val=='a'){
      cout<<"A";
      return 0;
    }
    if(sb.size()==0 && val=='b'){
      cout<<"B";
      return 0;
    }
    if(sc.size()==0 && val=='c'){
      cout<<"C";
      return 0;
    }
  }
}

Measured memory_bytes: 256
x1, y1, x2, y2 = map(int, input().split())

yoko = x2 - x1
tate = y2 - y1

x3 = x2 - tate
y3 = y2 + yoko 

x4 = x3 - yoko
y4 = y3 - tate

print(x3,y3,x4,y4)

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

struct card{
  char mark;
  int val;
};


void bubble(struct card A[],int N){
  int i,j;

  for(i=0;i<N-1;i++){
    for(j=N-1;j>=i;j--){
      if(A[j].val < A[j-1].val){
	swap(A[j],A[j-1]);
      }
    }
  }
}

void selection(struct card A[],int N){
  int i,j,min;

  for(i=0;i<N-1;i++){
    min=i;
    for(j=i;j<N;j++){
      if(A[j].val < A[min].val){
	min=j;
      }
    }
    swap(A[i],A[min]);
  }
}

void print(struct card A[],int N){
  int i;

  for(i=0;i<N;i++){
    if(i)cout << " ";
    cout << A[i].mark << A[i].val;
  }
  cout << endl;
}

bool isStable(struct card A1[],struct card A2[],int N){
  for(int i=0;i<N;i++){
    if(A1[i].mark != A2[i].mark)return false;
  }
  return true;
}

int main(){

  card C1[100],C2[100];
  int N,i;

  cin >> N;
  for(i=0;i<N;i++){
    cin >> C1[i].mark >> C1[i].val;
  }
  for(i=0;i<N;i++){
    C2[i]=C1[i];
  }

  bubble(C1,N);
  selection(C2,N);

  print(C1,N);
  cout << "Stable" <<endl;
  print(C2,N);
  if(isStable(C1,C2,N)){
    cout << "Stable" <<endl;
  }else{
    cout << "Not stable" << endl;
  }
}

Measured memory_bytes: 1164
#include <bits/stdc++.h>
#define FOR(i, a, n) for(ll i = (ll)a; i < (ll)n; i++)
#define rep(i, n) FOR(i, 0, n)
#define ALL(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;

constexpr ll mod = 1e9 + 7;

template <typename T> inline bool chmax(T &a, const T b) {
    if(a >= b) return false;
    a = b;
    return true;
}
template <typename T> inline bool chmin(T &a, const T b) {
    if(a <= b) return false;
    a = b;
    return true;
}

/*-------------------------------------------*/

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

    int h, w;
    cin >> h >> w;
    int a[h][w];
    bitset<40000> dp[w];
    rep(i, h) rep(j, w) cin >> a[i][j];
    rep(i, h) rep(j, w) {
        int b;
        cin >> b;
        a[i][j] -= b;
        a[i][j] = abs(a[i][j]);
    }
    dp[0].set(20000 + a[0][0]);
    dp[0].set(20000 - a[0][0]);
    rep(i, h) rep(j, w) {
        if(i) dp[j] = (dp[j] << a[i][j]) | (dp[j] >> a[i][j]);
        if(j) dp[j] |= (dp[j - 1] << a[i][j]) | (dp[j - 1] >> a[i][j]);
    }
    int ans = 1e9;
    rep(i, 40000) if(dp[w - 1][i]) chmin<int>(ans, abs(20000 - i));
    cout << ans << endl;
}

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

typedef long long int lli;
#define FOR(i, l, r) for(size_t i=(l); i<=(r); i++)
#define REP(i, n) FOR(i, 1, n);

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

int main(){
    lli K;
    lli sum = 0;

    cin >> K;

    lli i, j, s;

    //cout << gcd(31, 18) << endl;

    /*REP(i, K){
        REP(j, K){
            //int ij = gcd(i, j);
            REP(s, K){
                sum += gcd(gcd(i, j), s);
            }
        }
    }*/
    for(i=1; i<=K; i++){
        //cout << "i: " << i << endl;
        for(j=1; j<=K; j++){
            //cout << "j: " << j << endl;

            for(s=1; s<=K; s++){
                //cout << "s: " << s << endl;

                sum += gcd(gcd(i, j), s);
                //cout << sum << endl;
            }
        }
    }

    cout << sum << endl;
}

Measured memory_bytes: 3640
import java.util.*;

public class Main{
	static Scanner s=new Scanner(System.in);
	static int gInt(){
		return Integer.parseInt(s.next());
	}

	public static void main(String[]$){
		int n=gInt(),m=gInt(),x=gInt();
		int l=0,r=0;
		for(int i=0;i<m;++i)
			if(gInt()<x)
				++l;
			else
				++r;
		System.out.println(Math.min(l,r));
	}
}

Measured memory_bytes: 23636
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;
using static System.Array;
using static Read;

class Program
{
    public static void Main()
    {
        var a = Int();
        var b = Int();
        var h = Int();
        WriteLine($"{(a + b) * h / 2}");
    }
}

static class Read
{
    static Queue<string> queue = new Queue<string>();
    static void Enqueue()
    {
        ReadLine().Split(' ').ToList().ForEach(a => queue.Enqueue(a));
    }
    public static int Int()
    {
        if(queue.Count == 0)
            Enqueue();
        return int.Parse(queue.Dequeue());
    }
    public static long Long()
    {
        if(queue.Count == 0)
            Enqueue();
        return long.Parse(queue.Dequeue());
    }
    public static double Double()
    {
        if(queue.Count == 0)
            Enqueue();
        return double.Parse(queue.Dequeue());
    }
    public static string String()
    {
        if(queue.Count == 0)
            Enqueue();
        return queue.Dequeue();
    }
    public static int[] IntArray()
    {
        return ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray();
    }
    public static long[] LongArray()
    {
        return ReadLine().Split(' ').Select(a => long.Parse(a)).ToArray();
    }
    public static double[] DoubleArray()
    {
        return ReadLine().Split(' ').Select(a => double.Parse(a)).ToArray();
    }
    public static string[] StringArray()
    {
        return ReadLine().Split(' ');
    }
}


Measured memory_bytes: 13396
class UnionFind():
    def __init__(self, n):
        self.n=n
        self.parents=[-1]*n # 親(uf.find()で経路圧縮して根)の番号。根の場合は-(そのグループの要素数)
    def find(self,x):
        #グループの根を返す
        if self.parents[x]<0:return x
        else:
            self.parents[x]=self.find(self.parents[x])
            return self.parents[x]
    #def members(self, x):
    #    root = self.find(x)
    #    return [i for i in range(self.n) if self.find(i) == root]
    def unite(self,x,y):
        #要素x,yのグループを併合
        x,y=self.find(x),self.find(y)
        if x==y:return
        if self.parents[x]>self.parents[y]:#要素数の大きい方をxに
            x,y=y,x
        self.parents[x]+=self.parents[y]
        self.parents[y]=x #要素数が大きい方に併合
    def roots(self):
        #全ての根の要素のリスト
        return [i for i, x in enumerate(self.parents) if x<0]
    def group_count(self):
        #グループの数
        return len(self.roots())
    #def __str__(self):
    #   return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
import sys
from functools import lru_cache
 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

def read():
  return int(readline())
def reads():
  return map(int, readline().split())
n,m=reads()
uf=UnionFind(n)
for i in range(m):
  x,y,z=reads()
  uf.unite(x-1,y-1)
print(uf.group_count())
  


Measured memory_bytes: 8392
#include <cstdio>
#include <algorithm>
using namespace std;

int l,a,b,c,d;
int m;

int calc(int x, int y) {
    return x%y==0?x/y:x/y+1;
}

int main() {
    scanf("%d%d%d%d%d",&l,&a,&b,&c,&d);
    m = max(calc(a,c),calc(b,d));
    printf("%d\n",l-m);
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
struct hhh
{
    int a,x;
}h[100005];
bool cmp(hhh x,hhh y)
{
    return x.a<y.a;
}

int main()
{
    int n,k,ans=0;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>h[i].a;
        h[i].x=i+1;
    }
    sort(h,h+n,cmp);
        for(int i=0;i<n;i++)
    {
        cout<<h[i].x<<" ";
    }
    return 0;
}


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

int charToInt(char c){
    char zero_num = '0';
    return (int)c - (int)zero_num;
}

int find_root(vector<int> &parent, int i){
    vector<int> path_nodes;
    int temp=i;
    while(true){
        if(parent[temp] == temp){
            for(int k=0;k<path_nodes.size();k++){
                parent.at(path_nodes.at(k))=temp;
            }
            return temp;
        }else{
            path_nodes.push_back(temp);
            temp=parent[temp];
        }
    }
}

signed merge_trees(vector<int> &parent,int i, int j, vector<int> &tree_size){
    int i_root = find_root(parent, i);
    int j_root = find_root(parent, j);
    if(i_root==j_root){
        return 0; // do nothing
    }else{
        int i_size = tree_size.at(i_root);
        int j_size = tree_size.at(j_root);
        if((i+j)%2==0){
            parent.at(i_root) = j_root;
            tree_size.at(j_root) = tree_size.at(j_root) + tree_size.at(i_root);
        }else{
            parent.at(j_root) = i_root;
            tree_size.at(i_root) = tree_size.at(j_root) + tree_size.at(i_root);
        }
        return j_size*i_size;
    }
}


signed main(){
    int N, M; cin>>N>>M;
    vec_int A(M),B(M);
    rep(i,M){
        cin>>A.at(i)>>B.at(i);
    }

    vec_int unionfind(N+1);
    rep(i,N+1){
        unionfind.at(i) = i;
    }

    vec_int tree_size(N+1);
    rep(i,N+1){
        tree_size.at(i) = 1;
    }

    vec_int ans(M+1);
    ans[M] = (N-1)*N/2;
    for(int i=M-1;i>=0;i--){
        int a = A.at(i);
        int b = B.at(i);
        int temp = merge_trees(unionfind, a,b, tree_size);
        ans.at(i)= ans.at(i+1)-temp;
    }

    for(int i=1;i<M+1;i++){
        cout<<ans.at(i)<<endl;
    }
        


    



    return 0;
}

Measured memory_bytes: 7176
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
 
#include<bits/stdc++.h>
 
using namespace std;
#define ll long long
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define ins insert
#define ull unsigned long long
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define ff first
#define ss second
#define fast ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0); 
#define nl "\n"
#define sz(a) (int)(a).size() 
#define all(a) (a).begin(),(a).end()
#define fl(a,x) memset(a,x,sizeof(a));
#define pt(a,x) cout << get<x>(a) << " " ;  
#define mt make_tuple 
#define vec vector
 
#define int long long 
 
const int mod = (int) 1e9 + 7 ;
const int MOD = (int) 998244353 ;
const int INF = (int) 1e18 ;
 
typedef vector<int> vii;
typedef pair<int,int> pii;
typedef vector<pii> vpi;
typedef vector<vector<int> > vv;
 
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
 
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}

void solve(int test) {
	char ch; cin >> ch ;
	if(ch <= 'Z') cout << 'A';
	else cout << 'a' ;
}
 
int32_t main() {

 
    fast;
	int t=1;
	// cin>>t;
	rep(i,0,t) {
		solve(i) ;
	}
 
	// cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
	return 0;
}

Measured memory_bytes: 3608
#include <iostream>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <algorithm>
#include <bitset>
#include <cstdlib>
#include <cmath>
#define INF 100000000000
#define MOD 1000000007
#define ll long long int
using namespace std;

/*
int main(){
   int a,b;cin>>a>>b;
   if(a>=13) cout<<b<<endl;
   else if(a>=6 and a<=12) cout<<b/2<<endl;
   else cout<<0<<endl;
 //  //return 0;
    return 0;
}*/

int main(){
 int N,M;cin>>N>>M;
 vector <int> imos(max(M+10,N+10),0);
 for(int i=0;i<M;i++){
     ll l,r;cin>>l>>r;
     imos[l]++;
     imos[r+1]--;
 }
 for(int i=1;i<imos.size();i++){
     imos[i] += imos[i-1];
 }

 ll ans = 0;
 for(int i=0;i<imos.size();i++){
     if(imos[i] == M) ans++;
 }
cout<<ans<<endl;
    return 0;
}

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

using namespace std;

const int MAXM=2020; 

int main()
{
	bitset<MAXM> bs;
	bs.set(0);
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	{
		int t;
		scanf("%d",&t);
		bs=bs|(bs<<t);
	}
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	{
		int t;
		scanf("%d",&t);
		if(bs[t])
			printf("yes\n");
		else
			printf("no\n");
	}
	return 0;
}

Measured memory_bytes: 3104
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>
#include <cmath>
#include <stack>
#include <map>
#include <functional>
#include <queue>
using namespace std;

int64_t min(int64_t a,int64_t b) {
    if (a > b)
    {
        return b ;
    }else
    {
        return a ;
    }
}


int main(){
    int h,w,m ;
    cin >> h >> w >> m ;
    vector<pair<int,int> > htable(h,pair<int,int>()) ;
    vector<pair<int,int> > wtable(w,pair<int,int>()) ;
    for (size_t i = 0; i < h; i++)
    {
        htable.at(i).first = 0 ;
        htable.at(i).second = i ;
    }
    for (size_t i = 0; i < w; i++)
    {
        wtable.at(i).first = 0 ;
        wtable.at(i).second = i ;
    }
    vector<pair<int,int> > b ;
    for (int i = 0; i < m; i++)
    {
        int hi,wi ;
        cin >> hi >> wi ;
        htable.at(hi-1).first ++ ;
        wtable.at(wi-1).first ++ ;
        b.push_back(make_pair(hi-1,wi-1)) ;
    }
    sort(b.begin(),b.end()) ;
    sort(htable.begin(),htable.end(),greater<pair<int,int> >()) ;
    sort(wtable.begin(),wtable.end(),greater<pair<int,int> >()) ;
    int limit = 1000000 ;
    int lookh = 1 ;
    int lookw = 1 ;
    while(lookh < limit && h > 1)
    {
        if (htable.at(lookh).first == htable.at(lookh-1).first)
        {
            lookh ++ ;
        }else
        {
            break ;
        }
        if (lookh >= h)
        {
            break ;
        }
        
    }
    int ans = 0 ;
    int temp = 0 ;
    for (int i = 0; i < min(h,lookh); i++)
    {
        for (int j = 0; j < min(w,limit/lookh+1) ; j++)
        {
            temp = htable.at(i).first + wtable.at(j).first ;
            temp -= binary_search(b.begin(),b.end(),make_pair(htable.at(i).second,wtable.at(j).second)) ;
            ans = max(temp,ans) ;
        }
        
    }
    cout << ans << endl ;
    
}

Measured memory_bytes: 12124
n,x,m=map(int,input().split())
# -1はまだ来てない
order=[-1 for i in range(m)]
index=0
#0,1,2,...　番目の数字を配列で記憶高々mこ
a=[]
while(order[x]==-1):
    order[x]=index
    a.append(x)
    x=(x**2)%m
    index+=1
#1周期の和
tmp=sum(a[order[x]:index])
T=index-order[x]
if(n-1<order[x]):
    print(sum(a[:n]))
else:
    #ループ前の和
    sum1=sum(a[:order[x]])
    #ループ前を全体から引いた数
    x1=n-order[x]
    #ループ回数
    n1=x1//T
    n2=x1%T
    print(sum1+n1*tmp+sum(a[order[x]:order[x]+n2]))

Measured memory_bytes: 13840
#include <stdio.h>

int main()
{
  int i, j;
  int h, w;

  while (1) {
    scanf("%d %d", &h, &w);
    if (h == 0 && w == 0) break;

    for(i = 0; i < h; i++) {
      for (j = 0; j < w; j++) {
        if (i == 0 || i == h - 1) {
          putchar('#');
        } else {
          if (j == 0 || j == w - 1) {
            putchar('#');
          } else {
            putchar('.');
          }
        }
      }
      putchar('\n');
    }
    putchar('\n');
  }
  return 0;
}



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

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

const int maxn=307;

int n,k,m,f[maxn][maxn],g[maxn][maxn],C[maxn][maxn];

int main(){
	scanf("%d%d%d",&n,&k,&m);
	C[0][0]=1;
	for(int i=1;i<maxn;++i){
		for(int j=1;j<maxn;++j)
			C[i][j]=(C[i-1][j-1]+C[i-1][j])%m;
		C[i][0]=1;
	}
	for(int i=0;i<=k;++i)f[1][i]=1,g[1][i]=k-i+1;
	for(int i=2;i<=n+1;++i){
		for(int j=0;j<=k;++j){
			for(int t=1;t<i;++t)
				f[i][j]=(f[i][j]+1ll*f[t][j]*g[i-t][j+1]%m*C[i-2][t-1])%m;
//			printf("f[%d][%d]=%d\n",i,j,f[i][j]);
		}
		for(int j=k;j>=0;--j)g[i][j]=(g[i][j+1]+f[i][j])%m; 
	}
	printf("%d\n",f[n+1][0]);
	return 0;
}
/*
4 3 999999999

150 150 998244353
*/


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

int main(){
    long N;
    cin >> N;
    deque<long> A(N);
    for(auto& i : A)cin >> i;
    auto i = N - 1;
    for(; i >= 0; i -= 2)cout << A[i] << " ";
    for(i = -1 - i; i < N; i += 2)cout << A[i] << " ";
    return 0;
}

Measured memory_bytes: 3840
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    x = int(input())

    year = 0
    money = 100
    
    from math import floor
    
    while money < x:
        money *= 1.01
        money = floor(money)
        year += 1

    print(year)


if __name__ == '__main__':
    main()


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


int main(){
    long long int N;
    long long int A,B;
    double L;
    double l;
    string s;
    bool flag=true;
    cin>>L;
    l=L/3;
    cout << fixed << setprecision(7);
    cout<<l*l*l<<endl;
}


Measured memory_bytes: 256
// Problem : D - Banned K
// Contest : AtCoder Beginner Contest 159
// URL : https://atcoder.jp/contests/abc159/tasks/abc159_d
// Memory Limit : 1024 MB
// Time Limit : 2000 ms

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

#define int         long long int
#define all(a)      (a).begin(),(a).end()
#define f           first
#define s           second
#define endl        '\n'
#define MOD         1000000007

int get(int n)
{
	if(n < 2)
		return 0 ;
	return (n * (n - 1) / 2) ;
}

void solve()
{
	int n ;
	cin >> n ;
	map<int, int> mp ;
	int sum = 0 ;
	int a[n] ;
	for(int i = 0 ; i < n ; i++)
	{
		cin >> a[i] ;
		mp[a[i]]++ ;
	}
	for(auto i : mp)
	{
		sum += get(i.s) ;
	}
	int ans[n] ;
	for(int i = 0 ; i < n ; i++)
		ans[i] = 0 ;
	for(int i = 0 ; i < n ; i++)
	{
		ans[i] = sum - get(mp[a[i]]) + get(mp[a[i]] - 1) ;
	}
	for(int i = 0 ; i < n ; i++)
		cout << ans[i] << "\n" ;
}

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

    int t = 1 ;
    //cin >> t ;
    while(t--)
    {
        solve() ;
    }
    return 0 ;
}

Measured memory_bytes: 12672
#define _USE_MATH_DEFINES
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <clocale>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

const int MOD = 1000000007; 
const int INF = 1000000000; //1e9
const int NIL = -1;
const long long LINF = 1000000000000000000; // 1e18
const long double EPS = 1E-10;

template<class T, class S> inline bool chmax(T &a, const S &b){
    if(a < b){
        a = b; return true;
    }
    return false;
}
template<class T, class S> inline bool chmin(T &a, const S &b){
    if(b < a){
        a = b; return true;
    }
    return false;
}



int main(){
    int N; std::cin >> N;
    std::vector<int> A(3), a(N), b(N), c(N);
    for(int i(0); i < 3; ++i) std::cin >> A[i];
    std::string s;
    std::vector<char> ans(N);
    for(int i(0); i < N; ++i){
        std::cin >> s;
        if(s == "AB"){a[i] = 0; b[i] = 1; c[i] = 2;}
        if(s == "BC"){a[i] = 1; b[i] = 2; c[i] = 0;}
        if(s == "AC"){a[i] = 2; b[i] = 0; c[i] = 1;}
    }
    for(int i(0); i < N; ++i){
        if(!A[a[i]] && !A[b[i]]){
            std::cout << "No" << std::endl;
            return 0;
        }
        if(i < N-1 && a[i+1] == b[i] && A[a[i]]){
            ans[i] = b[i] + 'A';
            ++A[b[i]]; --A[a[i]];
        }
        else if(i < N-1 && a[i+1] == c[i] && A[b[i]]){
            ans[i] = a[i] + 'A';
            ++A[a[i]]; --A[b[i]];
        }
        else if(A[a[i]] < A[b[i]]){
            ans[i] = a[i] + 'A';
            ++A[a[i]]; --A[b[i]];
        }else{
            ans[i] = b[i] + 'A';
            ++A[b[i]]; --A[a[i]];
        }

    }
    std::cout << "Yes\n";
    for(char cr: ans){
        std::cout << cr << "\n";
    }
    return 0;
}


Measured memory_bytes: 4564
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <cfloat>

using std::cerr;
using std::cin;
using std::cout;
using std::endl;

int main(){
  cout << std::fixed << std::setprecision(16);
  cin.tie(nullptr);
  std::ios::sync_with_stdio(false);

  int n,m;
  cin>>n>>m;
  std::vector<int> x(n);
  for(int i=0;i<n;++i){
    cin>>x[i];
  }

  std::unordered_multiset<int> x_mod[100000];
  std::vector<int> samenumber_card(m);

  for(auto v:x){
    x_mod[v%m].insert(v);
    if(x_mod[v%m].count(v)==2){
      x_mod[v%m].erase(v);
      x_mod[v%m].erase(v);
      samenumber_card[v%m]+=2;
    }
  }

  int result=0;

  result+=x_mod[0].size()/2;
  if(m%2==0){
    result+=x_mod[m/2].size()/2;
  }

  for(int l=1;l<m;l++){
    if(l>=m-l){
      break;
    }

    int not_pair_l=x_mod[l].size();
    int not_pair_r=x_mod[m-l].size();
    int pair=std::min(not_pair_l,not_pair_r);
    not_pair_l-=pair;
    not_pair_r-=pair;
    result+=pair;

    int repair_r=samenumber_card[m-l];
    int repair_num=std::min(not_pair_l,repair_r);
    result+=repair_num;
    not_pair_l-=repair_num;
    samenumber_card[m-l]-=repair_num;

    int repair_l=samenumber_card[l];
    repair_num=std::min(not_pair_r,repair_l);
    result+=repair_num;
    not_pair_r-=repair_num;
    samenumber_card[l]-=repair_num;
  }

  for(auto v:samenumber_card){
    result+=v/2;
  }

  cout<<result<<endl;



  return 0;
}

Measured memory_bytes: 12800
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=200010;
int n,m,a[N];
ll k;
bool st[N];
int main()
{
	cin>>n>>k;
	k++;
	for(int i=1;i<=n;i++) cin>>a[i];
	vector<int> ve;
	int pos=1;
	while(!st[pos])
	{
		ve.push_back(pos);
		st[pos]=1;
		pos=a[pos];
	}
	int l,len;
	for(int i=0;i<ve.size();i++)
		if(ve[i]==pos)
		{
			l=i;
			break;
		}
	len=ve.size()-l;
	if(k>ve.size())
	{
		k-=ve.size();
		k%=len;
		if(k==0) cout<<ve[ve.size()-1];
		else
			cout<<ve[k+l-1];
	}
	else cout<<ve[k-1];
	return 0;
}

Measured memory_bytes: 5292
# -*- coding: utf-8 -*-
import sys 
from collections import Counter,deque,defaultdict
from itertools import combinations,permutations,accumulate
from bisect import bisect_left,bisect
sys.setrecursionlimit(10**6)
INF = 10**9+7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

S = readline().decode().rstrip()
N = len(S)
cnt = 0
for i in range(N):
    cnt += int(S[i])

if cnt % 9 == 0:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 68340
#include<iostream>
#include <cstdio>
#include<cstring>
#include<string>
#include <cstdlib>  
#include<cmath>   
#include <cctype>
#include<string>
#include<set>
#include <iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include<list>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility>
#define LEN 100005
using namespace std;
using ll = long long;
double pi() { return 3.14; }
int sum(int a, int b) { return a + b; }
int mul(int a, int b) { return a * b; }
ll LGCD(ll x, ll y) {if (x % y == 0) return y;else return LGCD(y, x % y);}
ll LLCM(ll x, ll y) {return x * y / LGCD(x, y);}

int GCD(int x, int y) {if (x % y == 0) return y;else return GCD(y, x % y);}
int LCM(int x, int y) {return x * y / GCD(x, y);}
ll dpc[10000][10000];
ll combination(ll n, ll r) {
	if (n == r) { return dpc[n][n] = 1; }
	else if (r == 0) { return dpc[n][0] = 1; }
	else if (r == 1) { return dpc[n][1] = n; }
	else if (dpc[n][r]) { return dpc[n][r]; }
	else {return dpc[n][r]=combination(n - 1, r - 1)  + combination(n - 1, r);}}


ll nCr(ll n, ll r) {
	ll ans = 1;
	for (int i = n; i > n - r; --i) {
		ans = ans * i;
	}
	for (int i = 1; i < r + 1; ++i) {
		ans = ans / i;
	}
	return ans;
}

bool chsK(string s) {
	int n = s.length();
	if (n % 2 == 0) {
		for (int i = 0;i <= n / 2;i++) {
			if (s[i] != s[n - i-1])return false;
		}
	}
	else {
		for (int i = 0;i <= n / 2;i++) {
			if (s[i] != s[n - i-1])return false;
		}
	}
	return true;
}

int main() {
	string s;
	cin >> s;
	if (s[2] == s[3] && s[4] == s[5])cout << "Yes" << endl;
	else cout << "No" << endl;

	
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		String dir;
		int move,N;
		while(true){
			N = sc.nextInt();
			if(N==0) break;
			int x=10,y=10;
			int count=0;

			int[][] jewel = new int[N][2];
			for(int i=0; i<N; i++){
				for(int j=0; j<2; j++){
					jewel[i][j] = sc.nextInt();
				}
			}

			int M = sc.nextInt();
			count = N;
			for(int k=0;k<N;k++){
					if(x==jewel[k][0]&&y==jewel[k][1]){
					count--;
				}
			}

			for(int i=0; i<M; i++){
				dir = sc.next();
				move = sc.nextInt();


				if(dir.equals("N")){
					for(int j=0;j<move;j++){
						y++;
						if(y>20) y = 20;
						for(int k=0;k<N;k++){
							if(x==jewel[k][0]&&y==jewel[k][1]){
								jewel[k][0] = -1;
								jewel[k][1] = -1;							
								count--;
							}
						}
					}
				}
				else if(dir.equals("E")){
					for(int j=0;j<move;j++){
						x++;
						if(x>20) x = 20;
						for(int k=0;k<N;k++){
							if(x==jewel[k][0]&&y==jewel[k][1]){
								jewel[k][0] = -1;
								jewel[k][1] = -1;
								count--;
							}
						}
					}
				}
				else if(dir.equals("S")){
					for(int j=0;j<move;j++){
						y--;
						if(y<0) y = 0;
						for(int k=0;k<N;k++){
							if(x==jewel[k][0]&&y==jewel[k][1]){
								jewel[k][0] = -1;
								jewel[k][1] = -1;								
								count--;
							}
						}
					}
				}
				else if(dir.equals("W")){		
					for(int j=0;j<move;j++){
						x--;
						if(x<0) x = 0;
						for(int k=0;k<N;k++){
							if(x==jewel[k][0]&&y==jewel[k][1]){
								jewel[k][0] = -1;
								jewel[k][1] = -1;								
								count--;
							}
						}
					}
				}
			}	
			if(count==0) System.out.println("Yes");
			else if(count>0) System.out.println("No");
		}
	}
}

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

/** Application main entry point. */
int main (
  int argc,
  char *argv[ ]
  )
{
  double x = 0.;
  double y = 0.;
  int angle = 90;
  int r, t;

  while ( scanf ( " %d,%d", &r, &t ) == 2 )
  {
    x += r * cos ( angle / 180. * M_PI );
    y += r * sin ( angle / 180. * M_PI );
    angle -= t;
  }
  printf ( "%d\n", (int)x );
  printf ( "%d\n", (int)y );

  return ( 0 );
}

Measured memory_bytes: 0
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<math.h>
#include<limits>
#include<list>
#include <stdio.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i = 0;i < (n); ++i)
#pragma GCC optimize("Ofast")



int main() {
	int a, b;
	cin >> a >> b;
	int c;
	if (b ==100) {
		c = a * 1000 + b;
	}
	else if (b / 10 > 0) {
		c = a * 100 + b;
	}
	else {
		c = a * 10 + b;
	}

	for (int i = 4; i <= 316;i++) {
		if (pow(i,2) == c) {
			cout << "Yes" << endl;
			return 0;
		}
		if (pow(i,2) > c)break;
	}
	cout << "No" << endl;
	
	

	return 0;
}


Measured memory_bytes: 3688
require 'prime'

N = ARGF.gets.chomp.to_i

pp = Prime.prime_division(N)

#p pp

ans = 0
pp.each do |nn, ee|
  ii = 1
  while ii <= ee
#    p ii
    ee -= ii
    ii += 1
    ans += 1
  end
end

puts ans


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

#define FAST ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define ll long long
#define int long long
#define double long double

#define all(a)      (a).begin(),(a).end()
#define sz(x)       (int)x.size()

#define ff first
#define ss second
#define mp make_pair

#define pb push_back
#define endl "\n"

#define f(i,l,r) for(int i=l;i<=r;i++)
#define rf(i,r,l) for(int i=r;i>=l;i--)

#define bp __builtin_popcountll
#define inf 1e18

const int N=1e5+5;
const int M=1e9+7;
void solve()
{
	 string s;
	 cin>>s;
	 int n=s.size();
	 n--;
	 if(s[n]=='s')
	 	s+="es";
	 else
	 	s+="s";
	 cout<<s<<endl;
}

signed main()
{
	FAST
	
	#ifndef ONLINE_JUDGE
	freopen("input_sublime.txt", "r", stdin);
	freopen("output_sublime.txt", "w", stdout);
	#endif
	
    int t=1;
    // cin>>t;
    for(int tc=1;tc<=t;tc++)
    {
    	// cout<<"Case #"<<tc<<": ";
    	solve();
    }
    
    #ifndef ONLINE_JUDGE
    cout<<"\nTime Elapsed: " << 1.0*clock() / CLOCKS_PER_SEC << " sec\n";
	#endif
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
typedef bool boolean;

const int N = 5005;

int n, K;
int mxR[N];
char s[N << 1], t[N], ans[N];

void check(char* s, int k, char min_c) {
	int L = 0, p = n;
	while (s[n - L] == min_c)
		L++, p--;
	L <<= k;
	if (L >= n) {
		for (int i = 1; i <= n; i++)
			putchar(min_c);
		putchar('\n');
		exit(0);
	}
	for (int i = 1; i <= L; i++) {
		t[i] = min_c;
	}
	for (int i = L + 1; i <= n; i++)
		t[i] = s[p--];
	for (int i = 1; i <= n; i++)
		if (t[i] ^ ans[i]) {
			if (t[i] > ans[i]) {
				return;
			}
			break;
		}
	for (int i = 1; i <= n; i++)
		ans[i] = t[i];
}

int main() {
	scanf("%d%d", &n, &K);
	scanf("%s", s + 1);
	for (int i = 1; i <= n; i++)
		s[2 * n - i + 1] = s[i];
	char x = 'z', y = 'a';
	for (int i = 1; i <= n; i++) {
		x = min(x, s[i]);
		y = max(y, s[i]);
	}
	if (K >= 20 || x == y) {
		for (int i = 1; i <= n; i++)
			putchar(x);
		putchar('\n');
		return 0;
	}
	ans[1] = 'z' + 1;
	if (s[n] == x)
		check(s, K, x);
	int mxL = 0;
	for (int i = 1, j = 1; i <= n; i = j) {
		if (s[i] != x) {
			j++;
			continue;
		}
		while (s[j] == s[i])
			j++;
		mxR[i] = j - i;
		mxL = max(mxL, mxR[i]);
	}
	for (int i = 1; i <= n; i++) {
		if (mxR[i] == mxL) {
			check(s + (n - i + 1), K - 1, x);
		}
	}
	puts(ans + 1);
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n - 1); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
#define get_unique(x) x.erase(unique(all(x)), x.end());
typedef long long ll;
typedef complex<double> Complex;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
const ll LINF = 1e18;
template <class T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T& a, const T& b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
int main() {
    int q;
    cin >> q;
    while (q--) {
        string s, t;
        cin >> s >> t;
        int n = sz(s);
        int m = sz(t);
        auto dp = make_vec<int>(1010, 1010);
        int ans = 0;
        rep(i, n) rep(j, m) {
            chmax(dp[i + 1][j + 1], dp[i][j] + (s[i] == t[j]));
            chmax(dp[i + 1][j], dp[i][j]);
            chmax(dp[i][j + 1], dp[i][j]);
            chmax(ans, dp[i + 1][j + 1]);
        }
        cout << ans << endl;
    }
}


Measured memory_bytes: 6800
var
  s:ansistring;
  t,len,ans,wei:int64;

function get1(x,y:int64):int64;
begin
  exit((x-1)*9+y);
end;

function get2_1(x:int64):int64;
begin
  exit((x-2)*(x-1) div 2*81);
end;

function get2_2(x,y:int64):int64;
begin
  exit((x-1)*y*9);
end;

function get3(x:int64):int64;
begin
  exit((x-3)*(x-2)*(x-1) div 6*729);
end;

function get2(len:int64;s:string):int64;
var
  anss:int64;
begin
    anss:=get2_1(len)+get2_2(len,ord(s[1])-49);
    wei:=2;
    while (s[wei]='0') and (wei<len) do inc(wei);
    anss:=anss+get1(len-wei+1,ord(s[wei])-48);
    exit(anss);
end;

begin
  readln(s);
  len:=length(s);
  readln(t);
  if (len<t) then begin
  writeln(0);
  exit;
  end;
  if (t=1) then
  begin
    writeln(get1(len,ord(s[1])-48));
  end else if (t=2) then begin
    writeln(get2(len,s));
  end else begin
    wei:=2;
     while (s[wei]='0') and (wei<len) do inc(wei);
    ans:=get2(len-wei+1,copy(s,wei,len));
    ans:=ans+(len-1)*(len-2) div 2*81*(ord(s[1])-49)+get3(len);
    writeln(ans);
  end;
end.

Measured memory_bytes: 128
// doot diddly donger cuckerino Hahahahahah

#include<bits/stdc++.h>

using namespace std;

typedef long long int LL;
typedef unsigned int UINT;
typedef unsigned long long ULL;
typedef pair<int, int> PII;
typedef pair<string, int> PSI;
typedef pair<LL, LL> PLL;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<PII> VPII;
typedef vector<PLL> VPLL;
typedef vector<LL> VLL;
typedef tuple<int,int,int> TPL;
typedef priority_queue<int> pqueue;
typedef priority_queue<int,VI,greater<int>> pdqueue;

const int dx[] = {-1, 0, 1, 0, -1, -1, 1, 1};
const int dy[] = {0, 1, 0, -1, -1, 1, -1, 1};
const int dxhorse[] = {-2, -2, -1, -1, 1, 1, 2, 2};
const int dyhorse[] = {1, -1, 2, -2, 2, -2, 1, -1};

#define MP make_pair
#define MT make_tuple
#define PB push_back
#define EB emplace_back
#define endl "\n"
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())
#define F first
#define S second
#define SZ(x)           (x).size()
#define MAX(a, b)      ((a)>(b)?(a):(b))
#define MIN(a, b)      ((a)<(b)?(a):(b))
#define ALL(a)         std::begin(a), std::end(a)
#define Fill(n, x)      memset(n,x,sizeof n);
#define IN_REP         int _t; cin >> _t ; while(_t--)
#define IOS            ios::sync_with_stdio(false);cin.tie(NULL)
#define FOR(i, a, b)    for(int i=(a);i<(b);i++)
#define REP(i, n)       FOR(i,0,n)
#define FORR(i, n)      for(int i=(n);i>=0;i--)
#define EPS (double) 1e-9
#define MOD (1000*1000*1000 + 7)
#define INF 1011111111
#define LLINF 1000111000111000111LL
#define MAXN 5000007

int main() {
    IOS;
    int n,T;
    cin >> n >>T;
    int ans = INF;
    REP(i,n){
      int x,y;
      cin >> x >>y;
      if(y <= T && x < ans){ans = x;}
    }
    if(ans == INF){cout << "TLE";}
    else cout << ans;
    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>

#define for0(i,n) for(ll i = 0;i < (n);i++)
#define for1(i,n) for(ll i = 1;i<=(n);i++)
#define for2(i,n) for(ll i = 2;i<=(n);i++)
#define fastio cin.tie(0);cout.tie(0);ios::sync_with_stdio(0)
#define rep(i,st,en,cnt) for(ll i = st;i <= en;i+=cnt)
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define bit(x,n) (x & (1<<(n)))
#define EPS 1e-8
#define all(x) (x).begin(),(x).end()
#define INF 0x3f3f3f3f3f3f3f
#define NEGINF -INF
#define TYPEMAX(type)   std::numeric_limits<type>::max()
#define inp_arr(a,n) for0(i,n) {cin>>a[i];}
#define out_arr(a,n) for0(i,n) {cout<<a[i]<<" ";}cout<<endl;
#define deb1(a) cout<<(a)<<endl;
#define deb2(a,b) cout<<(a)<<" "<<(b)<<endl;
#define deb3(a,b,c) cout<<(a)<<" "<<(b)<<" "<<(c)<<endl;

using namespace std;

typedef pair<int,int> ii;
typedef pair<long long,long long> pll;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef long long ll;
typedef vector<long long> vl;
typedef vector<vector<ll> > vvl;
typedef vector<pair<long long, long long> > vll;

ii DR8[] = {{-1,0},{0,1},{1,0},{0,-1},{-1,1},{-1,-1},{1,1},{1,-1}};
ii DR4[] = {{-1,0},{0,-1},{0,1},{1,0}};

const ll mod = 998244353;

ll nop = 2;
vi primes(nop+1,1);

void sieve(){
    primes[1] = primes[0] = 0;
    for(ll i = 2;i * i <= nop;i++){
        if(primes[i]){
            for(ll j = i*i; j <= nop;j+=i){
                primes[j] = 0;
            }
        }
    }
}

ll gcd(ll a,ll b){
    if(b>a) swap(b,a);
    if(b==0) return a;
    return gcd(b,a%b);
}

void extgcd(ll a,ll b,ll& x,ll& y){  //a smaller b larger
    if(a==0) {
        x = a;y = b;
        return;
    }
    extgcd(b%a,a,x,y);
    ll y1 = y,x1 = x;
    x = y1 - (b/a)*x1;
    y = x1;
}

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

ll bexp(ll num,ll e){
    ll ans = 1;
    while(e>0){
        if(e&1){
            ans *= num;
        }
        num *= num;
        e>>= 1;
    }
    return ans;
}

ll mexp(ll num,ll e){
    ll ans = 1;
    while(e>0){
        if(e&1){
            ans = (ans *num)%mod;
        }
        num *= num;
        num %= mod;
        e>>=1;
    }
    return ans%mod;
}

ll modinv(ll a){
    a %= mod;
    return mexp(a,mod-2);
}

void solve() {
    ll n;
    cin>>n;
    vl a(n);
    inp_arr(a,n);
    sort(all(a),greater<ll>());
    queue<ll> q;
    q.push(a[0]);
    ll ans = 0;
    for1(i,n-1) {
        ans += q.front();
        q.pop();
        q.push(a[i]);
        q.push(a[i]);
    }
    deb1(ans)
}

int main() {
    fastio;
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
    int t = 1;
    //cin>>t;
    while(t--) {
        solve();
    }
    /* #ifndef ONLINE_JUDGE
    cout<<"\nTime Elapsed: " << 1.0*clock() / CLOCKS_PER_SEC << " sec\n";
    #endif */
    return 0;
}


Measured memory_bytes: 6380
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
typedef long double ld;
const ll MOD=1e9+7;
const ll N=2e5+5;
const ld pi=3.14159265359;
#define REP(i,n) for(ll i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define setp setprecision
#define lwb lower_bound
#define SZ(a) (ll)a.size()

ll k,x;

int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);
	cin>>k>>x;
	for(ll i=max(x-k+1,-1000000LL);i<min(x+k,1000000LL);i++){
		cout<<i<<" ";
	}
	return 0;
}




Measured memory_bytes: 256