akhauriyash/Code-Regression huggingface dataset:
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def bisect(l,r,f,discrete=True,left=True):
    """
    l,r: l<r int if discrete else float
    f: function defined on [l,...,r] to {False,True}
    if discrete: f defined on Z; else: R
    if left: f satisfies that there uniquely exists d such that iff i<=d then f(i)
    else: iff i>=d then f(i) is True
    return d such as those above
    """
    assert r>l
    if discrete: assert isinstance(l,int) and isinstance(r,int)
    eps=1 if discrete else 10**-12
    if (not left)^f(r): return r if left else r+1
    elif left^f(l): return l-1 if left else l
    while(r-l>eps):
        h=(l+r)//2 if discrete else (l+r)/2
        if (not left)^f(h): l=h
        else: r=h
    return h if not discrete else l if left else r
    
class RollingHash(object):
    """
    construct: O(N)
    query:
        hash: O(1)
        lcp: O(logN)
    """
    __base1=1007; __mod1=10**9
    __base2=1009; __mod2=10**7

    def __init__(self,S):
        """
        S: str
        """
        n=len(S)
        self.__n=n
        b1=self.__base1; m1=self.__mod1
        b2=self.__base2; m2=self.__mod2
        H1,H2=[0]*(n+1),[0]*(n+1)
        P1,P2=[1]*(n+1),[1]*(n+1)
        for i,s in enumerate(S):
            H1[i+1]=(H1[i]*b1+ord(s))%m1
            H2[i+1]=(H2[i]*b2+ord(s))%m2
            P1[i+1]=P1[i]*b1%m1
            P2[i+1]=P2[i]*b2%m2
        self.__H1=H1; self.__H2=H2
        self.__P1=P1; self.__P2=P2

    @property
    def len(self):
        return self.__n

    def hash(self,l,r=None):
        """
        l,r: int (0<=l<=r<=n)
        return (hash1,hash2) of S[l:r]
        """
        m1=self.__mod1; m2=self.__mod2
        if r is None: r=self.__n
        assert 0<=l<=r<=self.__n
        return ((self.__H1[r]-self.__P1[r-l]*self.__H1[l]%m1)%m1,
                (self.__H2[r]-self.__P2[r-l]*self.__H2[l]%m2)%m2)

    @classmethod
    def lcp(cls,rh1,rh2,l1,l2,r1=None,r2=None):
        """
        rh1,rh2: RollingHash object
        l1,l2,r1,r2: int 0<=l1<=r1<=r1.len,0<=l2<=r2<=rh2.len
        return lcp length between rh1[l1:r1] and rh2[l2:r2]
        """
        if r1 is None: r1=rh1.__n
        if r2 is None: r2=rh2.__n
        assert 0<=l1<=r1<=rh1.__n and 0<=l2<=r2<=rh2.__n
        L=0
        R=min(r1-l1,r2-l2)
        if rh1.hash(l1,l1+R)==rh2.hash(l2,l2+R): return R
        while(R-L>1):
            H=(L+R)//2
            if rh1.hash(l1,l1+H)==rh2.hash(l2,l2+H): L=H
            else: R=H
        return L

def resolve():
    n=int(input())
    S=input()
    # d=0ではtrue,d=nではfalseなので、そこでbisectする
    rh=RollingHash(S)
    def judge(d):
        # initialize
        J={rh.hash(i,i+d):-1 for i in range(n-d+1)}
        for i in range(n-d+1):
            h=rh.hash(i,i+d)
            if J[h]!=-1:
                if i-J[h]>=d: return True
            else: J[h]=i
        return False
    print(bisect(0,n,judge))
resolve()

Measured memory_bytes: 43376
#include <stdio.h>
#define N 500000
 
int data[N+1], n;
 
void swap(int* a, int* b){
  int tmp = *a;
  *a = *b;
  *b = tmp;
}
 
void maxHeapify(i){
  int l = 2*i;
  int r = 2*i+1;
  int valM;
  if(l <= n && data[l] > data[i]) valM = l;
  else valM = i;
  if(r<=n && data[r] > data[valM]) valM = r;
  if(valM != i){
    swap(&data[i], &data[valM]);
    maxHeapify(valM);
  }
}
 
void buildMaxHeap(){
  int i;
  for(i=n/2;i>0;i--) maxHeapify(i);
}
 
main(){
  int i;
  scanf("%d", &n);
  for(i=1;i<=n;i++) scanf("%d", &data[i]);
  buildMaxHeap();
  for(i=1;i<=n;i++) printf(" %d", data[i]);
  printf("\n");
  return 0;
}


Measured memory_bytes: 3628
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define END {}
#endif
typedef long long ll;
#define int ll
#define uset unordered_set
#define umap unordered_map
typedef std::pair<int,int> P;
struct edge{int to,cost;};
const int INF=100000000000000000;
const int INF2=9223372036854775807;
const int MOD=1000000007;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define min(X,Y) (((int)(X)<(int)(Y))?(X):(Y))
#define max(X,Y) (((int)(X)>(int)(Y))?(X):(Y))
#define MAX(X,Y) (*max_element(X,Y))
#define MIN(X,Y) (*min_element(X,Y))
#define NP(X,Y) next_permutation(X,Y)

int N;
string S;

signed main(){
	cin>>N>>S;
	int sum=0,sum2=0;
	REP(i,S.size()){
		if(S[i]=='#'){
			sum++;
		}
		else{
			sum2++;
		}
	}
	int cnt=0,cnt2=0;
	int ans=INF;
	REP(i,S.size()){
		if(S[i]=='#'){
			cnt++;
		}
		else if(S[i]=='.'){
			cnt2++;
		}
		DEB(cnt+sum2-cnt2)END
		ans=min(cnt+sum2-cnt2,ans);
	}
	ans=min(sum2,ans);
	ans=min(sum,ans);
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 640
""" Atcorder practice 20200719 """
# test programm for practice


def __main__():
    """ def for calc """
    num_input = int(input())
    if num_input < 1 or num_input > 10:
        raise ValueError
    #elif num_input % 1 != 0:
        #raise ValueError
    else:
        print(num_input + num_input**2 + num_input**3)


if __name__ == "__main__":
    __main__()


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

const long double PI = acos(-1);
 
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }

int main(){
    string s, t;
    cin >> s >> t;
    cout << t << s << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define bug1(x) cout<<#x<<" = "<<x<<endl
#define bug2(x,y) cout<<#x<<" = "<<x<<" "<<#y<<" = "<<y<<endl
#define bug3(x,y,z) cout<<#x<<" = "<<x<<" "<<#y<<" = "<<y<<" "<<#z<<" = "<<z<<endl
#define bug4(x,y,z,m) cout<<#x<<" = "<<x<<" "<<#y<<" = "<<y<<" "<<#z<<" = "<<z<<" "<<#m<<" = "<<m<<endl

using namespace std;

class Debugger {
public:
	template<typename T>
	void printVector(vector<T> const &vec, bool printSize=true){
		if(printSize){
			cout << vec.size() << endl;
		}
		for(auto &elem : vec){
			cout << elem << " ";
		}
		cout << endl;
	}

	template<typename T>
	void printMatrix(vector<vector<T>> const &matrix){
		cout << matrix.size()<< " ";
		if(!matrix.empty()){
			cout << matrix[0].size();
		}
		cout << endl; 
		for(auto &vec : matrix){
			printVector(vec, false);
		}
		cout << endl;
	}
};

#define ll long long
const int MAXN = 1000005;
const int MOD = 1000000007;

class TaskE {
private:
	Debugger debugger;
	vector<int> lp;
	void prepare() {
		lp.assign(MAXN, -1);
		for(int i = 2; i < MAXN; i++) {
			if(lp[i] == -1) {
				for(int j = i; j < MAXN; j+=i) {
					if(lp[j] == -1) {
						lp[j] = i;
					}
				}
			}
		}
	}

	unordered_set<int> get(int x) {
		unordered_set<int> ans;
		while(x > 1) {
			ans.insert(lp[x]);
			x /= lp[x];
		}
		return ans;
	}

public:
	void solveOne(int it){	
		prepare();

		int n;
		cin >> n;
		vector<int> nums(n);
		int t = 0;
		for(int i = 0; i < n; i++) {
			cin >> nums[i];
			t = __gcd(t, nums[i]);
		}
		bool ok = true;
		unordered_set<int> all;
		for(int i = n-1; i >= 0; i--) {
			unordered_set<int> factors = get(nums[i]);
			for(int p : factors) {
				if(all.count(p)) {
					ok = false;
				}
			}
			for(int p : factors) {
				all.insert(p);
			}
		}
		if(ok) {
			cout << "pairwise coprime\n";
			return;
		}
		if(t == 1) {
			cout << "setwise coprime\n";
		} else {
			cout << "not coprime\n";
		}



	}

	void solve(){
		int tc = 1;
		for(int it = 1; it <= tc; it++){
			solveOne(it);
		}
	}
};


int main(){
	ios_base::sync_with_stdio(false);
	TaskE solver;
	solver.solve();
	return 0;
}



Measured memory_bytes: 14536
H,N = map(int, input().split())
magic = [list(map(int,input().split())) for _ in range(N)]

max_damage = max(damage for damage, cost in magic)
dp = [0] * (H + max_damage)

for x in range(1, H + max_damage):
    dp[x] = min(dp[x - damage] + cost for damage, cost in magic)
    
ans = min(dp[H:])

print(ans)

Measured memory_bytes: 3660
#include<iostream>
#include<algorithm>
#include<vector>

typedef long long ll;

#define debug(x) cout << #x << "=" << x << endl;
#define debug_arr(a, n) for(ll i = 0; i < n; i++)cout << a[i] << " "
#define inf 100000000000
#define loop(i,n) for(ll i = 0; i < n; i++)

using namespace std;

ll conbination(ll n){
    return n * (n-1) / 2;
}

int main(){
    ll n;
    ll totalNum = 0;
    cin >> n;
    vector<ll> a(n), num(n+1, 0) ;
    loop(i,n){
        cin >> a[i];
        num[a[i]]++;
    }

    loop(i,n+1){
        totalNum += conbination(num[i]);
    }

    loop(i,n){
        if(num[a[i]] == 0 || num[a[i]] == 1)cout << totalNum << endl;
        else cout << totalNum - num[a[i]] + 1 << endl;
    }

    return 0;
}

Measured memory_bytes: 5760
/**************************
*                         *
*  Nothing Is Impossible  *
*                         *
**************************/
#include <algorithm>
#include <iostream>
#include <fstream>
#include <ctype.h>
#include <string>
#include <vector>
#include <thread>
#include <math.h>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <set>
#include <map>
#define GetRand(Min, Max) ((rand()%(int)(((Max) + 1)-(Min))) + (Min))
#define Rep(i, min, max) for(int i = min; i < max; ++i)
#define PB push_back
#define MP make_pair
typedef long long ll;
typedef long double ld;
using namespace std;

void Solve(){
	int X,Y;	cin >> X >> Y;
	if(4*X < Y){
		cout << "No" << endl;
	}else{
		int x = X, y = Y;
		while(y >= 2 && x > 0){
			if(2*x == y){
				cout << "Yes" << endl;
				return;
			}else if(4*x == y){
				cout << "Yes" << endl;
				return;
			}else{
				y -= 2;
				x--;
			}
		}
		x = X; y = Y;
		while(y >= 4 && x > 0){
			if(2*x == y){
				cout << "Yes" << endl;
				return;
			}else if(4*x == y){
				cout << "Yes" << endl;
				return;
			}else{
				y -= 4;
				x--;
			}
		}
		cout << "No" << endl;
	}
}

int main(){
	ios::sync_with_stdio(NULL);
	cin.tie(NULL); cout.tie(NULL);
	int t = 1;
	//int t;	cin >> t;
	while(t--) Solve();
	//system("pause");
	return 0;
}

Measured memory_bytes: 3608
def valid(s, r, c):
    if s[r][c] != '#': return True
    if r > 0 and s[r-1][c] == '#': return True
    if r < H-1 and s[r+1][c] == '#': return True
    if c > 0 and s[r][c-1] == '#': return True
    if c < W-1 and s[r][c+1] == '#': return True
    return False

def solve():
    for i in range(H):
        for j in range(W):
            if not valid(s, i, j): return False
    return True

H, W = map(int, input().split())
s = []
for i in range(H):
    s.append(input())

if solve():
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3064
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#define rep(i,n) for (int i = 0; i < n; ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
  int N;
  cin >> N;
  if (N%2 == 0) cout << fixed << setprecision(7) <<  0.5 << endl;
  else cout << fixed << setprecision(7) <<  (N+1)/(2.0*N) << endl;
  return 0;
}

Measured memory_bytes: 3216
#include <bits/stdc++.h>
using namespace std;
vector<long long> la(51,1),pa(51,1);
long long ans = 0;

void check(int n, long long x) {
	if (n > 0) {
		if (x == la[n] || x == la[n] - 1) {
			ans += pa[n];
			x = 0;
		}
		else if (la[n] / 2 + 1 < x&&x < la[n] - 1) {
			ans += pa[n - 1]+1;
			x -= la[n] / 2 + 1;
		}
		else if (x == la[n]/2 + 1) {
			ans += 1;
			x -= 2;
		}
		else if (x == 0 || x == 1)
			x = 0;
		else
			x--;
		check(n - 1, x);
	}
	else
		ans += x;
}

int main() {
	long long n, x;
	cin >> n >> x;
	for (int i = 1;i < n+1;i++) {
		pa[i] = pa[i - 1] * 2 + 1;
		la[i] = la[i - 1] * 2 + 3;
	}
	check(n, x);
	cout << ans << endl;
	//for (int i = 0;i < 50;i++)
		//cout << la[i] << " " << pa[i] << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;cin >> n;long long a[n+5],b[n+5],c[n+5];
    for(int i = 1;i<=n;i++) cin >> a[i];
    for(int i = 1;i<=n;i++) cin >> b[i];
    for(int i = 1;i<=n;i++) cin >> c[i];
    sort(a+1,a+n+1);
    sort(b+1,b+n+1);
    sort(c+1,c+n+1);long long i,k;long long ans;ans = 0;i = k = 1;
    for(long long j = 1;j<=n;j++){
        for(;i<=n;i++) if(a[i] >= b[j]) break;
        for(;k<=n;k++) if(c[k] > b[j]) break;
        ans += (i-1)*(n-k+1)*1LL;
    }
    cout << ans;
}

Measured memory_bytes: 2560
def gcd(a, b):
  if b == 0:
    return a
  else:
    return gcd(b, a % b)
 
N=int(input())
A = [ int(input()) for _ in range(N) ]
ans = A[0]
for x in A[1:]:
  ans = ans * x // gcd(ans, x)
print(ans)

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <cmath>
#include <iomanip>
#include <algorithm>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)

int main() {
	int ans=0,mx=0;
	string s;
	cin>>s;
	int n=s.size();
	rep(i,n){
	    if(s[i]-'0'==i%2)ans++;
	}
	cout<<min(ans,n-ans);
	return 0;
}


Measured memory_bytes: 512
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		try {
			int n = sc.nextInt();
			int m = sc.nextInt();
			sc.nextLine();

			int[] ab = new int[n];
			Arrays.fill(ab, 0);
			int ai = 0;
			int bi = 0;
			for (int i = 0; i < m; i++) {
				ai = sc.nextInt();
				ab[ai - 1]++;
				bi = sc.nextInt();
				ab[bi - 1]++;
				sc.nextLine();
			}

			Arrays.stream(ab).forEach(i -> System.out.println(i));

		} finally {
			sc.close();
		}
	}
}

Measured memory_bytes: 26320
N = int(input())
T, X, Y = 0, 0, 0
for i in range(N):
    t, x, y = map(int, input().split())
    dt = abs(T-t)
    dist = abs(X-x) + abs(Y-y)
    if dt < dist or dist % 2 != dt % 2:
        print("No")
        exit()
print("Yes")

Measured memory_bytes: 3064
# -*- coding: utf-8 -*-

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

if not len(h_list) == n :
    raise RuntimeError("Mismatch Length.")

count = 0
while True:
    h_max = max(h_list)

    if h_max == 0:
        break

    isMax_list = [h == h_max for h in h_list]

    for i, isMax in enumerate(isMax_list):
        if isMax:
            h_list[i] -= 1
            if i == 0 or not isMax_list[i-1]:
                count += 1

print(count)


Measured memory_bytes: 3060
#include<stdio.h>
#include<stdlib.h>
#define MAX 100005
#define NIL -1

struct Node {
  int parent,left,right;
};

struct Node T[MAX];
int n,D[MAX],H[MAX];

void setDepth(int u,int d){
  if(u==NIL)return;
  D[u]=d;
  setDepth(T[u].left,d+1);
  setDepth(T[u].right,d+1);
}

int setHeight(int u){
  int h1=0,h2=0;
  if(T[u].left!=NIL) h1=setHeight(T[u].left)+1;
  if(T[u].right!=NIL) h2=setHeight(T[u].right)+1;
  return H[u]=(h1>h2?h1:h2);
}

int getSibling(int u){
  if(T[u].parent==NIL)return NIL;
  if(T[T[u].parent].left!=u&&T[T[u].parent].left!=NIL)return T[T[u].parent].left;
  if(T[T[u].parent].right!=u&&T[T[u].parent].right!=NIL)return T[T[u].parent].right;
 return NIL;
}


void print(int u){
  int i,c;
  printf("node %d: ",u);
  printf("parent = %d, ",T[u].parent);
  printf("sibling = %d, ",getSibling(u));
  int deg=0;
  if(T[u].left!=NIL)deg++;
  if(T[u].right!=NIL)deg++;
  printf("degree = %d, ",deg);
  printf("depth = %d, ",D[u]);
  printf("height = %d, ",H[u]);
  
  if(T[u].parent==NIL)printf("root\n");
  else if(T[u].left==NIL&&T[u].right==NIL) printf("leaf\n");
  else  printf("internal node\n");
}

int main(){

  int v,l,r,root=0,i;

  scanf("%d",&n);
  for(i=0;i<n;i++){
    T[i].parent=NIL;
  }

  for(i=0;i<n;i++){
     scanf("%d",&v);
     scanf("%d",&l);
     scanf("%d",&r);
     T[v].left=l;
     T[v].right=r;
     if(l!=NIL)T[l].parent=v;
     if(r!=NIL)T[r].parent=v;
  }
  for(i=0;i<n;i++){
    if(T[i].parent==NIL)root=i;
  }
  
  setDepth(root,0);
  setHeight(root);
  for(i=0;i<n;i++)print(i);

  return 0;
}



Measured memory_bytes: 2108
# A = [list(map(int, input().split())) for _ in range(3)]
H = int(input())
# B = [int(input()) for _ in range(n)]
# A = list(map(int, input().split()))
# a, b = map(int, input().split())
# S = input()


def f(h):
    if h == 1:
        return 1
    return 2*f(h//2)+1


print(f(H))


Measured memory_bytes: 2940
#include <iostream>
#include <vector>
#include <cstdlib>
#include <string>
#include <map>
#include <cmath>
using namespace std;


int main (int argc, char const *argv[])
{
    string s; cin>>s;
    map<char,string> ans;
    ans['S']="Cloudy";
    ans['C']="Rainy";
    ans['R']="Sunny";
    cout<<ans[s[0]]<<endl;
    return 0;
}

Measured memory_bytes: 256
n = int(input())
ans_list = list()

for i in range(1,n+1):
    if i % 3 == 0:
        ans_list.append(str(i))
    elif i % 10 == 3:
        ans_list.append(str(i))
    elif '3' in str(i):
        ans_list.append(str(i))

print('', ' '.join(ans_list))



Measured memory_bytes: 5996
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
using namespace std;
constexpr int kMod = 1000000007;
typedef long long LL;

int main() {
  string S; cin >> S;
  LL K; cin >> K;
  int N = S.size();

  LL cnt = 0;
  for (int i = 1; i < N; ++i) {
    if (S[i-1] == S[i]) {
      ++cnt; ++i;
    }
  }

  LL a = 0, b = 0;
  while (S[0] == S[a] && a < N) ++a;
  while (S[N-1] == S[N-b-1] && b < N) ++b;

  if (a == N) {
    cout << N * K / 2  << endl;
  } else if (S[0] != S.back()) {
    cout << cnt * K  << endl;
  } else {
    cout << cnt * K - (a/2 + b/2 - (a + b)/2) * (K-1) << endl;
  }
}


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

int main() {
	ll N;
	cin >> N;
	ll mn = 1e12 + 5;
	for (int i = 1; i <= sqrt(N); i++) {
		if (N % i == 0) {
			ll a = i + (N / i) - 2;
			mn = min(a, mn);
		}
	}

	cout << mn << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <limits.h>
#include <algorithm>
#include <math.h>
using namespace std;
typedef long long ll;

int main(void){
    int n, m, a, b;
    bool brg[8][8];
    cin >> n >> m;
    for (int i = 0; i < n*n; i++) brg[i/n][i%n] = false;
    for (int i = 0; i < m; i++) {
        cin >> a >> b;
        brg[a-1][b-1] = true;
        brg[b-1][a-1] = true;
    }
    
    int ans = 0;
    for (int i = 0; i < pow(n - 1, n - 1); i++) {
        int il[8], ic = i;
        il[0] = 0;
        for (int j = 0; j < n - 1; j++) {
            il[j + 1] = ic % (n - 1) + 1;
            ic /= n - 1;
        }
        bool check = true;
        for (int j = 0; j < n; j++) {
            for (int k = j + 1; k < n; k++) {
                if (il[j] == il[k]) check = false;
            }
        }
        if (check) {
            for (int j = 0; j < n - 1; j++) {
                if (!brg[il[j]][il[j + 1]]) break;
                if (j == n - 2) {
                    ans++;
                }
            }
        }
    }
    
    cout << ans << endl;
}


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

struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);}} fast;

/* cpp template {{{ */

/* short */
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define X real()
#define Y imag()

/* REPmacro */
#define REPS(i, a, n) for (ll i = (a); i < (ll)(n); ++i)
#define rep(i, n) REPS(i, 0, n)
#define REP0(i,n) for (ll i = 0; i <= (ll)(n); ++i)
#define REP1(i,n) for (ll i = 1; i <= (ll)(n); ++i)
#define RREP(i, n) REPS(i, 1, n + 1)
#define DEPS(i, a, n) for (ll i = (a); i >= (ll)(n); --i)
#define DEP(i, n) DEPS(i, n, 0)
#define EACH(i, n) for (auto&& i : n)

/* debug */
#define debug(x) cerr << x << " " << "(L:" << __LINE__ << ")" << '\n';

/* alias */
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using pii = pair<int, int>;
using D = double;
using P = complex<D>;
using vs = vector<string>;
template <typename T> using PQ = priority_queue<T>;
template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

/* const */
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7;
const D EPS = 1e-9;
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

/* func */
inline bool inside(int y, int x, int H, int W) {return y >= 0 && x >= 0 && y < H && x < W;}
inline int in() {int x; cin >> x; return x;}
inline ll IN() {ll x; cin >> x; return x;}
inline vs split(const string& t, char c) {vs v; stringstream s(t); string b; while(getline(s, b, c)) v.eb(b); return v;}
template <typename T> inline bool chmin(T& a, const T& b) {if (a > b) a = b; return a > b;}
template <typename T> inline bool chmax(T& a, const T& b) {if (a < b) a = b; return a < b;}
template <typename T, typename S> inline void print(const pair<T, S>& p) {cout << p.first << " " << p.second << endl;}
template <typename T> inline void print(const T& x) {cout << x << '\n';}
template <typename T, typename S> inline void print(const vector<pair<T, S>>& v) {for (auto&& p : v) print(p);}
template <typename T> inline void print(const vector<T>& v, string s = " ") {rep(i, v.size()) cout << v[i] << (i != (ll)v.size() - 1 ? s : "\n");}

signed main() 
{
  string w; cin>>w;
  int c[26]={};
  rep(i,w.size())
  {
    c[w[i]-'a']++; 
  }
  rep(i,26)
  {
    if(c[i]%2==1) 
    {
      print("No");
      return 0;
    }
  }
  print("Yes");

  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
ll w;
int n;
ll x[50010];
ll s[50010];
ll s2[50010];
int ok[50010];
int oks[50010];
int main()
{
    while(1){
        cin>>w>>n;
        if(w==0) return 0;
        for(int i=0; i<n; i++){
            cin>>x[i];
        }
        s[n]=0;
        for(int i=n-1; i>=0; i--){
            s[i]=s[i+1]+x[i]+1;
        }
        ll d1=0, d2=w-1;
        while(d2-d1>1){
            ll d=(d1+d2)/2;
            fill(ok, ok+n, 0);
            s2[n]=0;
            for(int i=n-1; i>=0; i--){
                if(s[i]<=w+1) ok[i]=1;
                s2[i]=s2[i+1]+x[i]+d;
            }
            oks[n]=oks[n+1]=0;
            for(int i=n-1; i>=0; i--){
                if(ok[i]){
                    oks[i]=oks[i+1]+1;
                    continue;
                }
                int l=lower_bound(s2, s2+n+1, s2[i]-w-d, greater<ll>())-s2;
                int r=lower_bound(s, s+n+1, s[i]-w-2, greater<ll>())-s;
                if(oks[l]-oks[r]>0) ok[i]=1;
                oks[i]=oks[i+1]+ok[i];
            }
            if(ok[0]) d2=d;
            else d1=d;
        }
        cout<<d2<<endl;
    }
    return 0;
}


Measured memory_bytes: 4668
fn main() {
    use std::io::Read;
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    let mut iter = buf.split_whitespace();
    
    let n: usize = iter.next().unwrap().parse().unwrap();
    let a: Vec<u64> = (&mut iter).take(n).map(|x| x.parse().unwrap()).collect();
    
    let mut left: Vec<Option<u64>> = vec![None;n+1];
    let mut right: Vec<Option<u64>> = vec![None;n+1];
    for i in 0..n {
        left[i+1] = Some(gcd(a[i], left[i].unwrap_or(a[i])));
        right[n-1-i] = Some(gcd(a[n-1-i], right[n-i].unwrap_or(a[n-1-i])));
    }

    let mut max = 1;
    for i in 0..n {
        max = std::cmp::max(max, match (left[i], right[i+1]) {
            (Some(l), Some(r)) => gcd(l,r),
            (None,Some(r)) => r,
            (Some(l),None) => l,
            _ => 1
        });
    }
    println!("{}", max);
}

#[allow(dead_code)]
pub fn gcd(a: u64, b: u64) -> u64 {
    if b == 0 {
        a
    } else {
        gcd(b, a % b)
    }
}
#[allow(dead_code)]
pub fn lcm(a: u64, b: u64) -> u64 {
    a / gcd(a, b) * b
}
#[allow(dead_code)]
#[doc = " ax + by = gcd"]
#[doc = " (gcd, x, y)"]
pub fn extgcd(a: i64, b: i64) -> (i64, i64, i64) {
    if b == 0 {
        (a, 1, 0)
    } else {
        let (gcd, x, y) = extgcd(b, a % b);
        (gcd, y, x - (a / b) * y)
    }
}

Measured memory_bytes: 12540
n = gets.to_i
bit = 1
cnt = 0
while n.to_s.length >= bit
  [3,5,7].repeated_permutation(bit).each do |x|
    if x.include?(3) && x.include?(5) && x.include?(7)
      num = 0
      bit.times do |i|
        num = num * 10 + x[i]
      end
      if num <= n
        cnt += 1
      end
    end
  end
  bit += 1
end
puts cnt

Measured memory_bytes: 14644
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

e = A.copy()
for n in range(N):
	if e[n] < B[n]:
		e[n + 1] = max(e[n + 1] - (B[n] - e[n]), 0)
		e[n] = 0
	else:
		e[n] -= B[n]
#print(A)
#print(e)
print(sum(A) - sum(e))


Measured memory_bytes: 18476
N = int(input())
B = [int(x) - 1 for x in input().split()]
ans = []
while B:
    popped = -1
    for i in reversed(range(len(B))):
        x = B[i]
        if B[i] == i:
            ans.append(i + 1)
            popped = B.pop(i)
            break
    if popped == -1:
        print(-1)
        quit()
print(*ans[::-1], sep="\n")


Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
  ll x;
  cin>>x;
  ll t =0;
  ll am=100;
  while(1)
  {   
	  if(am>=x)
	  {
		  break;
	  }
	  am+=floor(am/100);
	  t++;
  }
  cout<<t;
}


Measured memory_bytes: 3620
import sys
import math
from fractions import gcd
# import queue
# from collections import Counter
# from itertools import accumulate
# from functools import reduce

def lcm(a, b):
    return a * b // gcd(a, b)

def combination_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def permutations_count(n, r):
    return math.factorial(n) // math.factorial(n - r)

big_prime = 1000000007

"""
# 標準入力取得
## 文字列
 =  sys.stdin.readline().rstrip()
 =  list(sys.stdin.readline().rstrip())

## 数値
 =  int(sys.stdin.readline()))
 =  map(int, sys.stdin.readline().split())
 =  list(map(int, sys.stdin.readline().split()))
 =  [list(map(int,list(sys.stdin.readline().split()))) for i in range(N)]
"""

s =  sys.stdin.readline().rstrip()
K =  int(sys.stdin.readline())


current = s[0]
cnt = 0
L = []
for stride in range(1, K + 1):
    for i in range(len(s) - stride + 1):
        L.append(s[i:i + stride])

print(sorted(list(set(L)))[K - 1])

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

int main (){
    int N;
    cin >> N;
    vector<int> A(N);
    for(int i = 0; i < N; i++){
        cin >> A[i];
    }
    sort(A.begin(), A.end());
    string ans = "YES";
    for(int i = 0; i < N - 1; i++){
        if(A[i] == A[i + 1]){
            ans = "NO";
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,m,a,b;
	cin>>n>>m;
	vector<set<int>>G(n);
	while(cin>>a>>b)
		G[--a].insert(--b),G[b].insert(a);
	for(int i=1;i<n-1;i++){
		if(G[0].find(i)!=G[0].end()&&G[n-1].find(i)!=G[n-1].end()){
			cout<<"POSSIBLE"<<endl;
			return 0;
		}
	}
	cout<<"IMPOSSIBLE"<<endl;
}


Measured memory_bytes: 28416
n = int(input())
al = list(map(int, input().split()))

res = 0

al.append(0)
al.insert(0,0)

for i in range(n+1):
    res += abs(al[i+1]-al[i])

for j in range(1,n+1):
    if (al[j+1]-al[j]) * (al[j]-al[j-1]) >= 0:
        print(res)
    else:
        print(res - min(abs(al[j+1]-al[j]),abs(al[j]-al[j-1]))*2)

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

int main() {
    int N, M;
    cin >> N >> M;
    vector<int> A(N);
    double vote = 0;
    rep(i, N) {
        cin >> A[i];
        vote += A[i];
    }
    int cnt = 0;
    rep(i, N) {
        if (vote/(4*M) <= A[i]) cnt += 1;
    }
    cout << (cnt >= M ? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <math.h>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
 
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// using namespace __gnu_pbds;
using namespace std;
// typedef pair<int,int> pii;
// tree <pii,null_type,greater<pii>,rb_tree_tag,tree_order_statistics_node_update> tr;
// cin.tie(0);
// std::ios::sync_with_stdio(false);
typedef long long LL;
const int N = 400005;
const int M = 205;
const int INF = 0x3f3f3f3f;
const double Pi = acos(-1);
const int MOD = 1e9+7;
const double eps = 1e-8;
int n,m;
int dp[N];
int s[N],pre[N];
std::vector<int> G[N];
class SegmentTree {
  public:
    SegmentTree(int size, int value):
        m_size(size),
        m_data(size * 2, value) {}
 
    void update(int position, int value) {
        for (position += m_size; position; position /= 2)
            m_data[position] = min(m_data[position], value);
    }
 
    int query(int from, int to) {
        int answer = numeric_limits<int>::max();
        for (from += m_size, to += m_size; from < to; from /= 2, to /= 2) {
            if (from & 1)
                answer = min(answer, m_data[from++]);
            if (to & 1)
                answer = min(answer, m_data[--to]);
        }
        return answer;
    }
 
  private:
    int m_size;
    vector<int> m_data;
};
void ini()
{
    fill(pre,pre+n+1,0);
    fill(dp,dp+n+1,n);
    for (int i=0;i<=n;i++)    
        G[i].clear();
}
int main()
{
    while (~scanf("%d",&n))
    {
        ini();
        for (int i=1;i<=n;i++)
        {
            scanf("%d",&s[i]);
            pre[i] = pre[i-1]+(1-s[i]);
        }
        scanf("%d",&m);
        for (int i=0;i<m;i++)
        {
            int a,b;
            scanf("%d%d",&a,&b);
            G[a].push_back(b);
        }
        int ans = 0;
        dp[0] = 0;
        SegmentTree S(n+1,n);
        for (int i=1;i<=n;i++)
        {
            dp[i] = min(dp[i],dp[i-1]+s[i]);
            S.update(i-1,dp[i-1]-pre[i-1]);
            for (int j=0;j<G[i].size();j++)
            {
                int l = i;
                int r = G[i][j];
                int tmp = S.query(l-1,r);
                dp[r] = min(dp[r],tmp+pre[r]);
                S.update(r,tmp);
            }
            // cout<<"bug "<<endl;
            // for (int i=1;i<=n;i++)
            //     cout<<dp[i]<<" ";
            // cout<<endl;
            // for (int i=1;i<=n;i++)
            //     cout<<S.query(i-1,i)<<" ";
            // cout<<endl;
        }
        ans = dp[n];
        printf("%d\n", ans);
    }
    return 0;
}
 
/*
 
3
1 0 1
1
1 3

3
1 0 1
2
1 1
3 3

3
1 0 1
2
1 1
2 3
 
5
0 1 0 1 0
1
1 5
 
9
0 1 0 1 1 1 0 1 0
3
1 4
5 8
6 7
 
15
1 1 0 0 0 0 0 0 1 0 1 1 1 0 0
9
4 10
13 14
1 7
4 14
9 11
2 6
7 8
3 12
7 13
 
10
0 0 0 1 0 0 1 1 1 0
7
1 4
2 5
1 3
6 7
9 9
1 5
7 9
 
*/

Measured memory_bytes: 18816
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define int long long
signed main(void){
    int n; cin>>n;
    vector <pair<int,int>> work(n);
    for(int i=0;i<n;i++){
        int a,b; cin>>a>>b;
        work[i] = make_pair(b,a); //締め切り, 作業時間
    }
    sort(work.begin(),work.end());
    int sum = 0;
    for(int i=0;i<n;i++){
        sum+= work[i].S;
        if(sum>work[i].F) {cout<<"No"<<endl; return 0;}
    }
    cout<<"Yes"<<endl;
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
     
int main() {
  string S;
  cin >> S;
  
  if((S.at(0) == S.at(1) && S.at(1) == S.at(2))){
    cout << "No" << endl;
  }
  else{
    cout << "Yes" << endl;
  }
  
}

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

int main(){
    int k, s; cin >> k >> s;
    int cnt=0;
    rep(i,k+1){
        rep(j,k+1){
                if(0 <= s-i-j && k >= s-i-j) cnt++;
        }
    }
    cout << cnt << endl;
    return 0;
}


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

using namespace std;

using ll = long long;

using ull = unsigned long long;

int main(void){

  ll x;

  cin >> x;

  cin.ignore();

  ll sum = 0;

  for (ll m = x; m > 0; m /= 10){
    sum += m % 10;
  }

  if(x % sum == 0){
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <regex>
#include <cstdio>
#include <cmath>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
#include <iomanip>

using namespace std;
using ll = long long int;
#define rep(i,n) for(int i = 0; i < n; i++)
#define FOR(i, a, b)  for(int i = (a); i < (b) ; i++)
#define pb push_back
#define SORT(v,n) sort(v, v+n)
#define ALL(x) (x).begin(),(x).end()
#define debug(x) cerr << #x << ": " << x << '\n'
#define elif else if
#define int ll
//const int INF = 100100100;
const int INF = (1LL << 32);
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
int dx[8] = { 1, 0, -1, 0, 1, -1, -1, 1 };
int dy[8] = { 0, 1, 0, -1, 1, 1, -1, -1 };
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;

signed main() {
	ios::sync_with_stdio(false);
	int a, b, c;
	cin >> a >> b >> c;
	int x = max(a,max(b,c));
	int m = 0;
	if ((a + b + c) % 2 != 3 * x % 2) {
		m = x + 1;
	}
	else {
		m = x;
	}
	cout << ((3 * m) - (a + b + c)) / 2 << endl;
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(vec) vec.begin(),vec.end()
#define mp make_pair
using namespace std;
using ll=long long;
using P=pair<int,int>;
const ll INF=1LL<<30;
const ll LINF=1LL<<61;
const double eps=1e-9;
const ll MOD=1e9+7;
int main(){
    int n;cin>>n;
    vector<ll> a(n);
    for(int i=0;i<n;i++)cin>>a[i];
    ll mi=2,ma=2;
    for(int i=n-1;i>=0;i--){
        if(mi/a[i]==ma/a[i]&&mi%a[i]){
            cout<<-1<<endl;
            return 0;
        }
        mi=(mi/a[i]+(mi%a[i]>0))*a[i];
        ma=(ma/a[i])*a[i];
        ma+=a[i]-1;
    }
    cout<<mi<<" "<<ma<<endl;
}


Measured memory_bytes: 1024
#include<stdio.h>

int main(){
		int n,i,j;
		scanf("%d",&n);
		for(i=1;i<=n;i++){
				if(i*(i+1)/2>=n){
						long long tmp=i*(i+1)/2;
						for(j=1;j<=i;j++){
								if(tmp-n!=j)printf("%d\n",j);
						}
						return 0;
				}
		}
		return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string S,ans="yes";cin>>S;
  vector<bool> a(26,false);
  for(int i=0; i<S.size(); i++){
    if(a[S[i]-'a']){
      
      ans="no";
      break;
    }
    a[S[i]-'a']=true;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;
const long long MOD=1e09+7;



#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,m,n) for(int i=m;i<n;i++)
#define vi vector<int>

int main(){


  int a,b;
  cin>>a>>b;
  
  int answer=-1;
  
  for (int i=1;i<1010;i++){
    if (floor(0.08*i)==a and floor(0.1*i)==b){
      answer=i;
      break;
    }
  }
  
  cout<<answer<<endl;
  
  
  
  
}





Measured memory_bytes: 384
#include <bits/stdc++.h>
typedef long long int ll;
using namespace std;
ll N = 100005;
int main(){
	ios_base::sync_with_stdio(false);  
	cin.tie(NULL);
	int n;cin>>n;
	map<ll,ll> mp;
	for(int i=0;i<n;i++){
		ll a;cin>>a;
		mp[a]++;
	}
	map<ll,ll>::iterator itr;
	ll ans=0;
	for(itr=mp.begin();itr!=mp.end();itr++){
		if(itr->second>=itr->first){
			ans += itr->second - itr->first;
		}
		else{
			ans += itr->second;
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 6272
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;


public class C
{
	public static void Main()
	{			
		string[] args = Console.ReadLine().Split(' ');
		int H = Int32.Parse(args[0]);
		int W = Int32.Parse(args[1]);

		char[,] s = new char[H,W];
		for(int i = 0; i < H; i++)
		{
			string str = Console.ReadLine();
			for(int j = 0; j < W; j++)
				s[i,j] = str[j];
		}

		bool ans = true;
		for(int i = 0; i < H; i++)
		{
			for(int j = 0; j < W; j++)
			{
				if((s[i,j] == '.') ||
					((i > 0) && (s[i-1,j] == '#')) || 
					((i < H-1) && (s[i+1,j] == '#')) ||
					((j > 0) && (s[i,j-1] == '#')) || 
					((j < W-1) && (s[i,j+1] == '#')))
					continue;
				
				ans = false;
				break;
			}
			if(!ans)
				break;
		}

		Console.WriteLine(ans ? "Yes" : "No");
	}	
}





Measured memory_bytes: 13140
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
#define lli long long
#define all(i) i.begin(),i.end()
#define rall(i) i.rbegin(),i.rend()
#define rep0(i,j) for(int i=0;i<j;i++)
#define MAX 1000000007

using namespace std;


int main() {
	char s[100002];
	int ans,n,m;
	cin >> n >> m;
	cin >> s;
	int l[100001], r[100001];
	int j[100001];
	rep0(i, n+1)j[i] = 0;

	for (int i = 1; i <= n; i++) {
	    j[i] = j[i - 1];
		if (s[i-1] == 'A') if (s[i] == 'C') j[i]++;
	}
	
	for (int i = 1; i <= m; i++) {
		cin >> l[i] >> r[i];
	}

	for (int i = 1; i <= m; i++) {
		ans = 0;
		cout << j[r[i]-1] - j[l[i]-1] << endl;
	}
}




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

using namespace std;

int main() {
  int n;
  cin >> n;
  int p = n / 1.08;
  bool flag = true;
  for (int i = p - 1; i <= p + 1; i++) {
    if (int(floor(i * 1.08)) == n) {
      cout << i << '\n';
      flag = false;
      break;
    }
  }
  if (flag) {
    cout << ":(\n";
  }
  return 0;
}

Measured memory_bytes: 256
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,copy,time
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())


N = inp()
AA = inpl()
BB = inpl()

# In[]:
# N = 3
# AA = [3, 4, 3]
# BB = [3, 2, 3]

cards = []
for i,(a,b) in enumerate(zip(AA,BB)):
    if i%2 == 0:
        cards.append((a, b, i))
    else:
        cards.append((b, a, i))


n = (N+1)//2

# In[]:
def solve(ii):
    tmp = 0
    # print(ii)
    for _ in range(N):
        next = []
        for k, i in enumerate(ii):
            if i == 0:
                tmp += k
            else:
                next.append(i-1)
        ii = next[:]
    # print(tmp)
    return tmp



# In[]:
ans = INF
for Acards in itertools.combinations(cards, n):
    Ais = sorted([(Acard[0], Acard[2]) for Acard in Acards])

    ii = set([i for A,i in Ais])
    Bis = []
    for a,b,i in cards:
        if i not in ii:
            Bis.append((b,i))
    Bis.sort()

    nums = []
    ii = []
    for i in range(N):
        if i%2 == 0:
            n,i = Ais[i//2]
        else:
            n,i = Bis[i//2]
        nums.append(n)
        ii.append(i)

    # print(nums,ii)
    if nums != sorted(nums):
        continue
    else:
        ans = min(ans,solve(ii))
        if ans == 0:
          print(0)
          sys.exit()


if ans == INF:
    print(-1)
else:
    print(ans)


Measured memory_bytes: 4084
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<iomanip>
using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,b) for(int i=(a); i<(b); i++)
const long long INF = 1LL << 60;

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    REP(i,n){
        cin >> a[i];
    }

    int max1 = 0, max2 = 0;
    int maxn;
    REP(i,n){
        if(max1<a[i]){
            max1 = a[i];
            maxn = i;
        }
    }

    REP(i,n){
        if(i==maxn){
            continue;
        }
        if(max2<a[i]){
            max2 = a[i];
        }
    }

    REP(i,n){
        if(i==maxn){
            cout << max2 << endl;
        }
        else{
            cout << max1 << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 2432
# Streamline
N, M = map(int, input().split())
X = list(map(int, input().split()))
X.sort()

if N < M:
	dist = []
	for i in range(M-1):
		dist.append(abs(X[i+1] - X[i]))
	dist.sort()
	ans = sum(dist[:M-N])
else:
	ans = 0

print(ans)

Measured memory_bytes: 13960
#include<bits/stdc++.h>
using namespace std;
string to_string(const string& s) {
	return '"' + s + '"';
}
string to_string(const bool b) {
	return (b ? "true" : "false");
}
string to_string(const char* s) {
	return to_string((string)s);
}
string to_string(const char c) {
	string s = "'";
	s += c;
	s += "'";
	return s;
}
template<class T, class U>
string to_string(const pair<T, U>& p) {
	string s = "(";
	s += to_string(p.first);
	s += ", ";
	s += to_string(p.second);
	s += ")";
	return s;
}
template<class T>
string to_string(const T& a) {
	bool first = true;
	string s = "{";
	for (const auto& x : a) {
		if(!first){
			s += ", ";
		}
		first = false;
		s += to_string(x);
	}
	s += "}";
	return s;
}
void debug_out() {cerr << '\n';}
template<class Head, class... Tail>
void debug_out(Head head, Tail... tail) {
	cerr << ' ' << to_string(head);
	debug_out(tail...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "] = ", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif
using ll = long long;
using ld = long double;
const int mod = 1e9 + 7;
const int inf = 1e9 + 100;
const ll inf64 = 7e18l;
vector<vector<int>> perm;
int n, m;
void construct(const vector<int>& cur) {
	if ((int) cur.size() == n) {
		perm.push_back(cur);
		return;
	}
	int last = cur.empty() ? 1 : cur.back();
	for (int i = last; i <= m; ++i) {
		vector<int> p = cur;
		p.push_back(i);
		construct(p);
	}
}
struct S {
	int a, b, c, d;
};
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(20);
	int q;
	cin >> n >> m >> q;
	construct({});
	vector<S> vec(q);
	for (int i = 0; i < q; ++i) {
		cin >> vec[i].a >> vec[i].b >> vec[i].c >> vec[i].d;
		--vec[i].a;
		--vec[i].b;
	}
	int answer = 0;
	for (const vector<int>& p : perm) {
		int cur_ans = 0;
		for (int i = 0; i < q; ++i) {
			if (p[vec[i].b] - p[vec[i].a] == vec[i].c) {
				cur_ans += vec[i].d;
			}
		}
		answer = max(answer, cur_ans);
	}
	cout << answer << '\n';
 	return 0;
}


Measured memory_bytes: 9784
#include "bits/stdc++.h"
#define PRECISION(x) cout << fixed << setprecision(x)
#define FAST_IO ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define ALLR(X) (X).rbegin(), (X).rend()
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define F first
#define S second

using namespace std;
 
template<class T> bool max_self(T & a, const T & b){ 
  return b > a ? a = b, true : false; 
}
template<class T> bool min_self(T & a, const T & b){ 
  return b < a ? a = b, true : false;    
}
typedef long long LL;
const int INF = 1e9 + 7;
const double PI = acos(-1.0);
const double EPS = (1e-9);


int main(){
  FAST_IO
  int x; cin >> x;
  cout << 1 - x;
  return 0;
}



Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
 
template <typename A, typename B>
string to_string(pair<A, B> p);
 
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);
 
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);
 
string to_string(const string& s) {
  return '"' + s + '"';
}
 
string to_string(const char& ch) {
	string s = "";
	s += ch;
	return "'" + s + "', ";
}
 
string to_string(const char* s) {
  return to_string((string) s);
}
 
string to_string(bool b) {
  return (b ? "true" : "false");
}
 
string to_string(vector<bool> v) {
  bool first = true;
  string res = "{";
  for (int i = 0; i < static_cast<int>(v.size()); i++) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(v[i]);
  }
  res += "}";
  return res;
}
 
template <size_t N>
string to_string(bitset<N> v) {
  string res = "";
  for (size_t i = 0; i < N; i++) {
    res += static_cast<char>('0' + v[i]);
  }
  return res;
}
 
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
 
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
 
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}
 
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}
 
void debug_out() { cout << endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cout << " " << to_string(H);
  debug_out(T...);
}
 
#ifdef LOCAL_DEFINE
#define debug(...) cout << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif
   
#define int long long
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(),(v).end()
typedef pair<int, int> pii;
const int mod = (int) 1000000007; // 998244353;
const int inf = (int) 2e18;

 
int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout << fixed << setprecision(9);
	#ifdef LOCAL_DEFINE
		freopen("in.txt", "rt", stdin);
	#endif
	
	string n;
	cin >> n;
	int su = 0;
	for(int i = 0; i < sz(n); ++ i)
		su += (n[i] - '0');
	cout << (su % 9 == 0 ? "Yes" : "No") << '\n';
	
	return 0;
}
 
 
 
 

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

using namespace std;

int a[100000];

int main(){
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
    cin>>a[i];
    sort(a+1,a+n+1);
    cout<<a[n]-a[1];
    return 0;
} 

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
static const int MAX_N = 500;
static const int INF = 1000000;
int N, M;
vector<int> G[MAX_N];
int dist[MAX_N];

int main(){
	for(;;){
		cin >> N >> M;
		if(N == 0 && M == 0) break;
		fill(dist, dist + N, INF);
		dist[0] = 0;
		for(int i = 0; i < M; i++){
			int a, b;
			cin >> a >> b;
			a--; b--;
			G[a].push_back(b);
			G[b].push_back(a);
		}
		int res = 0;
		for(int j = 0; j < G[0].size(); j++){
			dist[G[0][j]] = 1;
		}
		for(int i = 0; i < N; i++){
			if(dist[i] == 1){
				for(int j = 0; j < G[i].size(); j++){
					if(dist[G[i][j]] == INF) dist[G[i][j]] = 2;
				}
			}
		}
		for(int i = 0; i < N; i++){
			if(dist[i] == 1 || dist[i] == 2) res++;
		}
		cout << res << endl;
		for(int i = 0; i < N; i++) G[i].clear();
	}
	return 0;
}


Measured memory_bytes: 3212
n = int(input())

d = {}
for i in range(n):
    a = int(input())
    if a not in d:
        d[a] = 1
    else:
        if d[a]:
            d[a] = 0
        else:
            d[a] = 1

ans = 0
for v in d.values():
    ans += v
    
print(ans)

Measured memory_bytes: 86108
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String line; 
        while(true){
            line = sc.next();
            if(line.equals("-")){
                break;
            }
            else{
                char[] c = line.toCharArray();
                int m = sc.nextInt();
                int[] h;
                h = new int[m];
                int Sum = 0;
                for(int j = 0; j < m; j++){
                    h[j] = sc.nextInt();
                    Sum += h[j];
                }
                int rem = Sum % line.length();
                for(int j = rem; j < line.length(); j++){
                    System.out.print(c[j]);
                }
                for(int j = 0; j < rem; j++){
                    System.out.print(c[j]);
                }
                System.out.println("");
            }
        } 
    }    
}


Measured memory_bytes: 26248
#include <bits/stdc++.h>
#include <algorithm>
#include <string>
using namespace std;
int main(){
	int N; 
	cin >> N; 
	int T[110] = {}; 
	int sum = 0; 
	for(int i = 1; i <= N; i++){
		cin >> T[i]; 
		sum += T[i]; 
	}
	int M; 
	cin >> M; 
	for(int i = 0; i < M; i++){
		int P, X;
		cin >> P >> X; 
		cout << sum - T[P] + X << endl;  
	}
}

Measured memory_bytes: 256