akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

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

    int n, r, p, c;
    while (true) {
        cin >> n >> r;
        if (n == 0 && r == 0) {
            break;
        }
        vector<int> deck;
        for (int i = 0; i < n; i++) {
            deck.push_back(i + 1);
            // cout << deck[i] << endl;
        }
        for (int i = 0; i < r; i++) {
            cin >> p >> c;
            stack<int> s;
            for (int j = 0; j < c; j++) {
                // cout << "要素番号" << deck.size() - p - j << endl;
                s.push(deck[deck.size() - p - j]);
                // cout << "取り除いたもの" << s.top() << endl;
            }
            // cout << s.top() << endl;
            deck.erase(deck.begin() + (deck.size() - p - c + 1), deck.begin() + (deck.size() - p + 1));

            for (int j = 0; j < c; j++) {
                deck.push_back(s.top());
                s.pop();
            }
            // for (int afa = 0; afa < deck.size(); afa++) {
            //     cout << deck[afa] << endl;
            // }
        }
        cout << deck[deck.size() - 1] << endl;
    }
}


Measured memory_bytes: 3112
#include <bits/stdc++.h>
#define intt long long
using namespace std;
int i ,j ;
int main()
{
    int n,m,x,y;
    cin >> n >> m >> x >> y;
    int maxx = -200,minn = 200;
    for ( i = 1 ; i <= n; i++ )
    {
        int a;
        cin >> a;
        maxx = max(maxx,a);
    }
    for ( i = 1 ; i <= m ; i++ )
    {
        int a;
        cin >> a;
        minn = min(minn,a);
    }
    for ( i = maxx+1 ; i <= minn ; i++ )
    {
        if ( i <= y && i > x )
        {
            cout << "No War" << endl;
            return 0;
        }
    }
    cout << "War" << endl;
}


Measured memory_bytes: 256
N,M=map(int,input().split())
box=[[] for i in range(N)]
for i in range(M):
    a,b=map(int,input().split())
    box[a-1].append(b-1)
    box[b-1].append(a-1)
ans=[None]*(N)
ans[0]=0
que=[0]
while len(que)>0:
    index=que.pop(0)
    for x in box[index]:
        if ans[x]==None:
            ans[x]=index+1
            que.append(x)
print("Yes")
for i in range(1,N):
    print(ans[i])


Measured memory_bytes: 36448
#include<stdio.h>
main(){
  int n,i,j,temp;
  while(1){

    int taro[201]={0};
    int hana[201]={0};
    int tc=0;
    int hc=0;

    scanf("%d",&n);

    if(n==0) break;

    for(i=0;i<n;i++){
      scanf("%d",&temp);
      taro[temp]=temp;
    }

    for(i=1;i<=2*n;i++){
      if(taro[i]==0)
	hana[i]=i;
    }

    int fl=0;//taroツづ個づつォ0ツ嘉板子ツづ個づつォ1

    while(1){
      for(i=1;i<=2*n;i++){
	if(taro[i]!=0 && fl==0){
	  //printf("t...%d %d\n",i,taro[i]);
	  taro[i]=0;
	  fl=1;
	  tc++;
	}
	else if(hana[i]!=0 && fl==1){
	  //printf("h...%d %d\n",i,hana[i]);
	  hana[i]=0;
	  fl=0;
	  hc++;
	}
	if(tc==n || hc==n) break;
      }
      if(tc==n || hc==n) break;
      if(fl) fl=0;
      else fl=1;
      //printf("f..%d\n",fl);
    }
    printf("%d\n%d\n",n-hc,n-tc);
  }
  return 0;
}


    

Measured memory_bytes: 0
#include <iostream>
#include <iomanip> 
#include <cstdlib>
#include <cmath>
#include<map>
#include<string.h>
#include <algorithm>
#include <bits/stdc++.h> 
#include<vector>

using namespace std;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repb(i,a,b) for(int i=a;i>=b;i--)
#define replb(i,a,b) for(ll i=a;i>=b;i--)
#define repl(i,a,b) for(ll i=a;i<b;i++)
#define repv(arr)  for(auto it=arr[i].begin();it!=arr[i].end();it++)  
#define vi vector<int>
#define vb vector<bool>
#define vs vector<string>
#define vl vector<long long int>
#define sortA(arr)   sort(arr.begin(),arr.end())
#define search(arr,c)  binary_search(arr.begin(),arr.end(),c)
#define pb   push_back
#define ll long long
#define LCM(a,b) boost::math::lcm(a,b)
#define cl_bf cin.ignore(numeric_limits<streamsize>::max(), '\n');
#define castl static_cast<ll>
vector<vector<ll>> st;
vl a;
void subseq(int i,vl s,ll n)
{
    int z=a.size();
    if(i==z)
    {if(!s.empty())
    st.pb(s);
    return;}
    subseq(i+1,s,n);
    s.push_back(a[i]);
    subseq(i+1,s,n);
}
void set0(ll arr[],ll m){
    rep(i,0,m)arr[i]=0;
}
void print0(ll arr[],ll m){
    rep(i,0,m)cout<<arr[i]<<" ";
}
bool check0(ll arr[],ll m,ll x){
    rep(i,0,m){if(arr[i]<x)return false;}
    return true;
}

int main(){
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    ll n,m,x,min,ans;ans=1LL<<40;
    cin>>n>>m>>x;vl s;
    ll C[n],A[n][m],D[m];
    rep(i,0,n){
        cin>>C[i];
        rep(j,0,m){
            cin>>A[i][j];
        }
    }
    rep(i,0,n){
        a.pb(i);
    }
    subseq(0,s,n);
    min=0;
    set0(D,m);
    //print0(D,n);
    
    for(int k=0;k<st.size();k++){
        min=0;
        set0(D,m);
        for(int i=0;i<st[k].size();i++){
            rep(l,0,m){D[l]+=A[st[k][i]][l];}
                min+=C[st[k][i]];
        }//print0(D,n);cout<<"\n";cout<<min<<"\n";
            if(check0(D,m,x)){
                if(min<=ans)ans=min;
            }
    }
    if(ans==1LL<<40)cout<<-1;
    else cout<<ans;
    return 0;
}

Measured memory_bytes: 3996
s=list(map(int,input()))
a=10*s[0]+s[1]
b=10*s[2]+s[3]
counta=0
countb=0
'''month'''
if 0<a<=12:
    counta+=1
if 0<b<=12:
    countb+=1
'''year'''
if a==0 or a>=13:
    counta+=5
if b==0 or b>=13:
    countb+=5
j=counta+countb
if j==2:
    print('AMBIGUOUS')
elif j==6 and counta==5:
    print('YYMM')
elif j==6 and countb==5:
    print('MMYY')
else:
    print('NA')


Measured memory_bytes: 3064
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    int n, l;
    cin >> n >> l;

    vector<int> icicle(n+2, 0);
    for(int i=1; i<=n; ++i)
        cin >> icicle[i];

    multimap<int, int> mm;
    for(int i=1; i<=n; ++i){
        if(icicle[i] > icicle[i-1] && icicle[i] > icicle[i+1])
            mm.insert(make_pair(l-icicle[i], i));
    }

    for(;;){
        multimap<int, int>::iterator it = mm.begin();
        int time = it->first;
        int i = it->second;
        mm.erase(it);
        icicle[i] = 0;
        if(i-1 >= 1 && icicle[i-1] > icicle[i-2])
            mm.insert(make_pair(time + l-icicle[i-1], i-1));
        if(i+1 <= n && icicle[i+1] > icicle[i+2])
            mm.insert(make_pair(time + l-icicle[i+1], i+1));
        if(mm.empty()){
            cout << time << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 0
#!/usr/bin/env python

if __name__ == '__main__':
    n = int(raw_input())
    X = map(int, raw_input().split())
    Y = map(int, raw_input().split())

    dist = []
    for i in range(n):
        dist += [abs(X[i]-Y[i])]

    print sum(dist)
    print sum(map(lambda x : x**2, dist))**(1.0/2)
    print sum(map(lambda x : x**3, dist))**(1.0/3)
    print max(dist)



Measured memory_bytes: 4740
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cctype>
#include<cstdlib>
#include<algorithm>
#include<bitset>
#include<vector>
#include<list>
#include<deque>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cmath>
#include<sstream>
#include<fstream>
#include<iomanip>
#include<ctime>
#include<complex>
#include<functional>
#include<climits>
#include<cassert>
#include<iterator>
#include<random>
#include<unordered_set>
#include<unordered_map>

using namespace std;

#define MAX 100002

int n;
int d;

int cnt[1002][1002];

inline int rng(int a, int b, int c) {   //count [a,b] x%d==c
	int below = (a / d)*d + c;
	while (below < a) {
		below += d;
	}
	int up = (b / d)*d + c;
	while (up > b) {
		up -= d;
	}
	if (below > up)return 0;
	return (up - below) / d + 1;
}

vector<pair<int, pair<int, int> > > vv;

bool valid(int x, int y, int len) {
	long long int guarantee = len / d;
	guarantee *= guarantee;
	for (int i1 = 0; i1 < vv.size(); i1++) {
		int i = vv[i1].second.first;
		int j = vv[i1].second.second;
		long long int validx = rng(x, x + len, i);
		long long int validy = rng(y, y + len, j);
		validx *= validy;
		if (validx < cnt[i][j]) {
			return false;
		}
		if (cnt[i][j] == 0)break;
		if (cnt[i][j] <= guarantee)break;
	}
	return true;
}

int main() {
	cin >> n >> d;
	for (int i = 0; i < n; i++) {
		int x, y;
		scanf("%d%d", &x, &y);
		cnt[x%d][y%d]++;
	}
	for (int i = 0; i < d; i++) {
		for (int j = 0; j < d; j++) {
			vv.push_back(make_pair(cnt[i][j], make_pair(i, j)));
		}
	}
	sort(vv.begin(), vv.end());
	reverse(vv.begin(), vv.end());
	int ans = 1000000;
	for (int ii = 0; ii < vv.size(); ii++) {
		int i = vv[ii].second.first;
		int j = vv[ii].second.second;
		int mint = 0;
		int maxt = ans;
		if (valid(i, j, ans - 1) == false) {

		}
		else {
			maxt = ans - 1;
			if (mint > maxt)continue;
			while (mint + 1 < maxt) {
				int mid = (mint + maxt) / 2;
				if (valid(i, j, mid)) {
					maxt = mid;
				}
				else {
					mint = mid + 1;
				}
			}
			if (valid(i, j, mint)) {
				maxt = mint;
			}
			else {
				mint = maxt;
			}
			ans = min(ans, mint);
		}
		if (ii % 40 == 0 && d > 30 && clock() / (double)(CLOCKS_PER_SEC) > 2.2)break;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 17004
#include <iostream>
#include <cstdio>
using namespace std;
int main() {
	long N;
	long *A;
	long result=0;
	bool isMin=true;
	cin >> N;
	A = new long[N*N];

	for (size_t i = 0; i < N; i++) {
		for (size_t j = 0; j < N; j++) {
			cin >> A[i*N+j];
		}
	}

	for (size_t i = 0; i < N-1; i++) {
		for (size_t j = i+1; j < N; j++) {
			for (size_t k = 0; k < N; k++) {
				if (k==i || k==j) {
					continue;
				}
				if (A[i*N+j]>A[i*N+k]+A[k*N+j]) {
					result=-1;
					i=N-1;
					j=i;
					k=N;
					continue;
				}else if(A[i*N+j]==A[i*N+k]+A[k*N+j]){
					// 最小値が大体できるか
					isMin=false;
				}
			}
			if (isMin) {
				result+=A[i*N+j];
			}else{
				isMin=true;
			}

		}
	}

	cout << result << endl;
	return 0;
}


Measured memory_bytes: 1024
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <cctype>
#include <cassert>
#include <limits>
#include <functional>
#include <complex>
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
#if defined(_MSC_VER) || __cplusplus > 199711L
#define aut(r,v) auto r = (v)
#else
#define aut(r,v) __typeof(v) r = (v)
#endif
#define each(it,o) for(aut(it, (o).begin()); it != (o).end(); ++ it)
#define all(o) (o).begin(), (o).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset(m,v,sizeof(m))
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL-1
double EPS=1e-9;
using namespace std;
typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
typedef complex<double> P;
template<typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }

/*
cin >> n;
vi a(n);
rep(i,n)cin>>a[i];
*/

int main(){
	string str;
	cin>>str;
	int n=str.size();
	if(str[0]!=str[n-1]){
		if(n%2==1)cout<<"First"<<endl;
		else cout<<"Second"<<endl;
	}else{
		if(n%2!=1)cout<<"First"<<endl;
		else cout<<"Second"<<endl;
	}
}

Measured memory_bytes: 640
import itertools

N = int(input())
P = tuple(map(int,input().split()))
Q = tuple(map(int,input().split()))

A = list(itertools.permutations(range(1,N+1)))
cnt_a = 0
cnt_b = 0
for i in range(len(A)):
  if P == A[i]:
    cnt_a += i
  if Q == A[i]:
    cnt_b += i

print(abs(cnt_a - cnt_b))

Measured memory_bytes: 8052
import java.util.*;
public class Main{   
    public static void main(String[] args){
      Scanner sc = new Scanner(System.in);
      int n = sc.nextInt();
      long g  = 1;
      for(int i = 0;i < n;i++){
      	g = lcm(g,sc.nextLong());
      }
      System.out.println(g);
    }
    public static long lcm(long x, long y){
      return (x/gcd(x,y))*y;
    }
    public static long gcd(long x, long y){
      if(x < y)return gcd(y,x);
      if(y==0)return x;
      return gcd(y,x%y);
    }
}


Measured memory_bytes: 24148
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<functional>
#include<algorithm>
#include<cstdio>
#include<math.h>
#include<unordered_map>
using namespace std;
typedef long long ll;
typedef long double ld;
const long double pi = 3.14159265358979323846264338327950288;
ll n, a[4][101], w, o, k;
int b[4] = { 1,0,0,0 };
int main() {
	cin >> n >> w;
	cin >> o >> k;
	a[0][0] = k;
	for (ll i = 1; i < n; i++) {
		ll w, v;
		cin >> w >> v;
		a[w - o][b[w - o]] = v;
		b[w - o]++;
	}
	for (int i = 0; i < 4; i++) {
		sort(a[i], a[i] + b[i]);
		reverse(a[i], a[i] + b[i]);
	}
	ll ans = 0, sum1 = 0;
	for (int i = 0; i <= b[0]; i++) {
		ll sum2 = 0;
		for (int j = 0; j <= b[1]; j++) {
			ll sum3 = 0;
			for (int x = 0; x <= b[2]; x++) {
				ll sum4 = 0;
				for (int y = 0; y <= b[3]; y++) {
					if (o*i + (o + 1)*j + (o + 2)*x + (o + 3)*y <= w) {
						ans = max(ans, sum1 + sum2 + sum3 + sum4);
					}
					sum4 += a[3][y];
				}
				sum3 += a[2][x];
			}
			sum2 += a[1][j];
		}
		sum1 += a[0][i];
	}
	cout << ans << endl;
	cin >> n;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,m,sum=0,tmp;
int main(int argc, char const *argv[])
{
    cin>>n>>m;
    for (int i = 0; i < m; i++)
    {
        cin>>tmp;
        sum+=tmp;
    }
    if(n>=sum)cout<<n-sum;
    else cout<<"-1\n";
   return 0;
}


Measured memory_bytes: 3576
#include <iostream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <utility>
#include <map>
#include <list>
#include <climits>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <bitset>

// #define cerr if(false)cerr
#define watch(x) cerr << "> " << #x << ": " << x << "\n";

using namespace std;

template <typename T>
std::ostream &operator <<(std::ostream &out, vector<T> &v) {
	for (typename vector<T>::size_type i = 0; i < v.size(); ++i)
		out << v[i] << " ";
	out << "\n";
    return out;
}
template <typename T, typename N>
std::ostream &operator <<(std::ostream &out, vector<pair<T, N> > &v) {
	for (size_t i = 0; i < v.size(); ++i)
		out << "(" << v[i].first << ", " << v[i].second << ") ";
	out << "\n";
    return out;
}
template <typename T>
std::ostream &operator <<(std::ostream &out, vector<vector<T> > &v) {
	for (size_t i = 0; i < v.size(); ++i) {
		for (size_t j = 0; j < v[i].size(); ++j) {
			out << v[i][j] << " ";
		}
		out << "\n";
	}
   	return out;
}

int main() {

	std::ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	int n;
	cin >> n;

	vector<pair<int, int> > balls(n);
	int x, y;
	for (int i = 0; i < n; ++i) {
		cin >> x >> y;
		balls[i] = {x, y};
	}

	map<pair<int, int>, int> distances;
	for (int i = 0; i < n; ++i) {
		for (int j = i + 1; j < n; ++j) {
			++distances[make_pair(balls[j].first - balls[i].first, balls[j].second - balls[i].second)];
			++distances[make_pair(balls[i].first - balls[j].first, balls[i].second - balls[j].second)];
		}
	}

	int p, q;
	int most = 0;
	for (auto it = distances.begin(); it != distances.end(); ++it) {
		if (it->second > most) {
			most = it->second;
			p = (it->first).first;
			q = (it->first).second;
		}
	}

	cout << n - most << "\n";

	return 0;

}

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

int main()
{
    int n, k; cin >> n >> k;
    vector<int> v(n+1, 0);

    for(int i=0; i<n; i++)
    {
        int x; cin >> x;
        v[x]++;
    }

    vector<int> c;
    for(int i=1; i<=n; i++)
    {
        if(v[i]) c.push_back(v[i]);
    }

    sort(c.rbegin(), c.rend());

    int res = 0;
    while(c.size() > k)
    {
        res += c.back();
        c.pop_back();
    }

    cout << res << endl;

    return 0;
}


Measured memory_bytes: 2168
#include<stdio.h>

int main()
{
	int  N,n,sn=0,i;
	scanf("%d",&N);
	n=N;
	
	for(i=0; n>0; i++){
		sn+=n%10;
		n=n/10;
	}
	
	if(N%sn == 0)
		printf("Yes\n");
	if(N%sn != 0)
		printf("No\n");
	
	return 0;
}


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

#define REP(i, n) for(int i = 0; i < (int) (n); i++)
#define ALL(v) (v).begin(), (v).end()
#define INF 1e9

using namespace std;

struct node{
  int id, fr, to;
  node(int i, int f, int t) : id(i), fr(f), to(t) {}
};

int main(){
  int n, m, k;
  while(cin >> n >> k >> m and n + m + k){
    vector<node> left;
    REP(i, n) left.emplace_back(i, (i+n-1)%n, (i+1)%n);
    left[left[m-1].fr].to = left[m-1].to;
    left[left[m-1].to].fr = left[m-1].fr;
    int size = n - 1;
    int target = m % n;
    int counter = 0;
    if(size == 1){
      cout << left[m-1].to + 1 << endl;
      continue;
    }
    while(size > 1){
      counter++;
      if(counter == k){
        size--;
        if(size == 1) {
          cout << left[target].to + 1 << endl;
          break;
        }
        left[left[target].fr].to = left[target].to;
        left[left[target].to].fr = left[target].fr;
        counter = 0;
      }
      target = left[target].to;
    }
  }
  return 0;
}

Measured memory_bytes: 3292
import math

K = int(input())
ans = int(math.log10(K)) + 1
X = (10 ** ans - 1) // 9 * 7

while True:
  Y = X % K
  if Y==0:
    print(ans)
    break
  elif K%2==0 or K%5==0:
    print('-1')
    break
  else:
    X = Y * 10 + 7
    ans += 1


Measured memory_bytes: 63452
#include<stdio.h>
#include<string.h>
int main(){
    char ch[105][105];
    int n,m;
    scanf("%d%d",&n,&m);
    getchar();
    for(int i=0;i<n;i++) gets(ch[i]);
    for(int i=0;i<strlen(ch[0])+2;i++) printf("#");
    putchar('\n');
    for(int i=0;i<n;i++){
        putchar('#');
        for(int j=0;j<strlen(ch[i]);j++) printf("%c",ch[i][j]);
        putchar('#');
        putchar('\n');
    }
    for(int i=0;i<strlen(ch[0])+2;i++) printf("#");
    return 0;
}

Measured memory_bytes: 128
n, y = list(map(int, input().split()))
#a, b, c = -1, -1, -1
flag = False
for i in range(n + 1):
    for j in range((n + 1) - i):
        k = n - i - j
        if i * 10000 + j * 5000 + k * 1000 == y:
            print(i, j, k)
            flag = True
            break
    if flag:break
if not flag:print(-1, -1, -1)

Measured memory_bytes: 3060
#include <iostream>
#include <cstring>
#include <map>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <set>
#include <vector>
#include <queue>
#include <list>
#include <numeric>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <math.h>
#include <stack>
#include <climits>
#include <bitset>

using namespace std;
typedef long long ll;

int gcd(int x, int y) {
  if (x < y) swap(x, y);
  while (y > 0) {
    int r = x % y;
    x = y;
    y = r;
  }
  return x;
}

//for(int i = ; i < ; i++){}

int main(){
    int a[3];
    int d;
    cin>>a[0]>>a[1]>>a[2]>>d;
    if((abs(a[1]-a[0])<=d&&abs(a[2]-a[1])<=d)||abs(a[2]-a[0])<=d) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}



Measured memory_bytes: 256
#134
import math
n,d = map(int, input().split())
x = [list(map(int, input().split())) for i in range(0,n)]

res = 0;
rowres = 0
for i in range(0, n):
    for j in range(i+1,n):
        rowres = 0
        for k in range(0, d):
            rowres += (x[i][k] - x[j][k]) ** 2
        if math.sqrt(rowres) - int(math.sqrt(rowres)) == 0:
            res += 1
print(res)

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

int main(){
	int w,h,c,g;
	cin>>w>>h>>c;
	if(w>=h){
		for(int i=h;i>0;i--){
			if(w%i==0&&h%i==0){
				g=i;
				break;
			}
		}
	}
	else{
		for(int i=w;i>0;i--){
			if(h%i==0&&w%i==0){
				g=i;
				break;
			}
		}
	}
	cout<<c*((w/g)*(h/g))<<endl;
	return 0;
}


Measured memory_bytes: 3096
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;
 
int main() {
    ll n;
    cin >> n;

    map<string, ll> mp1;
    rep(i, n) {
        string s;
        cin >> s;
        mp1[s]++;
    }

    ll m;
    cin >> m;

    map<string, ll> mp2;
    rep(i, m) {
        string t;
        cin >> t;
        mp2[t]++;
    }

    ll ans = 0;
    for(auto p : mp1) {
        chmax(ans, p.second - mp2[p.first]);
    }
    
    out(ans);
    re0;
}

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

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define watch(a) { std::cout << #a << " = " << a << "\n"; }
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }
template<class T, class V> istream& operator>> (istream& ist, pair<T, V>& p) { return ist >> p.first >> p.second; }
template<class T> ostream& operator<< (ostream& ost, pair<T, T>& p) { return ost << p.first << ", " << p.second; }
template<class T> istream& operator>> (istream& ist, vector<T>& vs) { for(auto& e: vs) ist >> e; return ist; }

typedef long long ll;
int const inf = INT_MAX / 2;

int main() {
  ll H, W; cin >> H >> W;
  if (H == 1) {
    cout << 1 << "\n";
  }
  else if (W == 1) {
    cout << 1 << "\n";
  }
  else {
    cout << (H * W + 1) / 2 << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll int64_t
const ll mod = 1000000007;

const ll LINF = 1e13;
const ll LLINF = 1e18;
const ll ALPHABET = 26;

template <class T>
void Swap(T& r, T& l) {
  T tmp = r;
  r = l;
  l = tmp;
}

template<typename T>
istream& operator >> (istream& is, vector<T>& vec) {
  for (T& x : vec) is >> x; //for(int i=0; i<vec.size(); i++) is >> x[i]; とかでもいい
  return is;
}



// check
// 問題文を復唱する


int main() {
  // ll r,d,x;
  ll n;
  string s;
  cin >> s;

  ll num = s.size();


  char m = 'o';
  char b = 'x';

  ll count = 0;

  for (int i = 0; i < num; i++) {
      if (s[i] == m){
        count++;
      }
  }





  bool ans = false;

  if (15-num +count >=8)ans =true;

  if (ans){
    cout << "YES" << endl;
  }else{
    cout << "NO" << endl;
  }

  


}




















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

int bubbleSort(int A[], int N)
{
    int sw = 0;
    bool flag = 1;
    for (int i = 0; flag; i++)
    {
        flag = 0;
        for (int j = N - 1; j >= i + 1; j--)
        {
            if (A[j] < A[j - 1])
            {
                swap(A[j], A[j - 1]);
                flag = 1;
                sw++;
            }
        }
    }
    return sw;
}
int main()
{
    int A[100], N, sw;
    cin >> N;
    for (int i = 0; i < N; i++)
    {
        cin >> A[i];
    }
    sw = bubbleSort(A, N);
    for (int i = 0; i < N; i++)
    {
        if (i)
            cout << " ";
        cout << A[i];
    }
    cout << endl;
    cout << sw << endl;
    return 0;
}


Measured memory_bytes: 3100
# https://atcoder.jp/contests/agc043/tasks/agc043_a

import sys
# sys.setrecursionlimit(100000)


def input():
    return sys.stdin.readline().strip()


def input_int():
    return int(input())


def input_int_list():
    return [int(i) for i in input().split()]


ans = (100 * 100) + 1


def main():
    global ans
    h, w = input_int_list()
    grid = []
    grid.append(["#"] * (w + 2))
    for _ in range(h):
        grid.append(["#"] + list(input()) + ["#"])
    grid.append(["#"] * (w + 2))

    dp = [[101 for _ in range(w + 2)] for _ in range(h + 2)]
    if grid[1][1] == "#":
        dp[1][1] = 1
    else:
        dp[1][1] = 0
    for i in range(1, h + 1):
        for j in range(1, w + 1):
            # 上のマスからくる場合を評価
            if i > 1:
                if grid[i - 1][j] == "." and grid[i][j] == "#":
                    dp[i][j] = min(dp[i - 1][j] + 1, dp[i][j])
                else:
                    dp[i][j] = min(dp[i][j], dp[i - 1][j])

            # 左のマスからくる場合を評価
            if j > 1:
                if grid[i][j - 1] == "." and grid[i][j] == "#":
                    dp[i][j] = min(dp[i][j - 1] + 1, dp[i][j])
                else:
                    dp[i][j] = min(dp[i][j - 1], dp[i][j])

    print(dp[h][w])
    return


if __name__ == "__main__":
    main()


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

int main() {
    int a,b;
    cin >> a >> b;
    int ans = a - b * 2;

    if (ans < 0) cout << "0" << endl;
    else cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import sys
N=int(input())
a=[list(map(int,input().split())) for i in range(N)]
a.sort(key=lambda x: x[2],reverse=True)
ans=[]

if a[0][2]==100:
    print(a[0][0],a[0][1],a[0][2])
    sys.exit()



for i in range(0,101):
    for j in range(0,101):
        p=a[0][2]+abs(i-a[0][0])+abs(j-a[0][1])
#       q=a[1][2]+abs(i-a[1][0])+abs(j-a[1][1])
        for k in range(1,N):
            if a[k][2]>0 and a[k][2]+abs(i-a[k][0])+abs(j-a[k][1])!=p : break
            elif a[k][2]==0 and a[k][2]+abs(i-a[k][0])+abs(j-a[k][1])<p : break
            if k==N-1:
                print(i,j,p)
                sys.exit()

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

int main(){
  int N, x;
  cin >> N >> x;
  vector<int> a(N);
  for (int i=0; i<N; i++) cin >> a[i];
  long long count = 0;
  long long score = a[0];
  if (score > x){
    count += score - x;
    a[0] = x;
    score = x;
  }
  for (int i=1; i<N; i++){
    score += a[i];
    if (score > x){
      count += score - x;
      a[i] = x - a[i-1];
      score = x;
    }
    score -= a[i-1];
  }
  cout << count << endl;
}


Measured memory_bytes: 640
//#define _GLIBCXX_DEBUG

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

#define endl '\n'
#define lfs cout<<fixed<<setprecision(10)
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define fi first
#define se second
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define EB emplace_back
#define rep(i,n,m) for(ll i = (n); i < (ll)(m); i++)
#define rrep(i,n,m) for(ll i = (ll)(m) - 1; i >= (ll)(n); i--)
using ll = long long;
using ld = long double;
const ll MOD1 = 1e9+7;
const ll MOD9 = 998244353;
const ll INF = 1e18;
using P = pair<ll, ll>;
template<typename T1, typename T2>
bool chmin(T1 &a,T2 b){if(a>b){a=b;return true;}else return false;}
template<typename T1, typename T2>
bool chmax(T1 &a,T2 b){if(a<b){a=b;return true;}else return false;}
ll median(ll a,ll b, ll c){return a+b+c-max({a,b,c})-min({a,b,c});}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
template<typename T1,typename T2>
void ans(bool x,T1 y,T2 z){if(x)cout<<y<<endl;else cout<<z<<endl;}  
template<typename T>
void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++)
{cout<<v[i][0];for(ll j=1;j<w;j++)cout spa v[i][j];cout<<endl;}};
void debug(vector<string>&v,ll h,ll w){for(ll i=0;i<h;i++)
{for(ll j=0;j<w;j++)cout<<v[i][j];cout<<endl;}};
template<typename T>
void debug(vector<T>&v,ll n){if(n!=0)cout<<v[0];
for(ll i=1;i<n;i++)cout spa v[i];cout<<endl;};
template<typename T>
vector<vector<T>>vec(ll x, ll y, T w){
  vector<vector<T>>v(x,vector<T>(y,w));return v;}
ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;}
vector<ll>dx={1,-1,0,0,1,1,-1,-1};
vector<ll>dy={0,0,1,-1,1,-1,1,-1};
template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2>&p){
  return os << p.first << " " << p.second;
}
//mt19937 mt(chrono::steady_clock::now().time_since_epoch().count());
map<ll,ll> factoring(ll n){ 
  ll buf=n;
  map<ll,ll>ret;
  ll i,j;
  for(i=2;buf!=1&&i*i<=n;i++){
    for(j=0;buf%i==0;j++){
      buf/=i;
    }
    if(j>0)ret.emplace(i,j);
  }
  if(buf!=1)ret.emplace(buf,1);
  return ret;
}
int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  ll res=0,buf=0;
  bool judge = true;
  ll n;cin>>n;
  auto mp=factoring(n);
  for(auto z:mp){
    ll num=0;
    rep(i,0,1000){
      num+=i+1;
      if(z.se<num)break;
      res++;
    }
  }
  cout<<res<<endl;
  return 0;
}

Measured memory_bytes: 3656
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }

int main(){
    ll A, B;
    cin >> A >> B;
    
    cout << (A * B)/GCD(A, B);
    return 0;
}


Measured memory_bytes: 256
from math import ceil, log2

n, k = map(int,input().split())

ans = 0
d = {}
d[0] = 1
for i in range(n, 0, -1):
    c = ceil(log2(k / i))
    if c < 0:
        c = 0
    if c not in d:
        d[c] = pow(1/2, c)
    ans += d[c] / n

print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define pi acos(-1.0)

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) c.begin(), c.end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int main(){
    int a, b, c;
    cin >> a >> b >> c;
    REP(i,100000){
        if ((a % 2) + (b % 2) + (c % 2) > 0){
            cout << i << endl;
            return 0;
        }
        int ao = a, bo = b, co = c;
        a = bo/2 + co/2;
        b = ao/2 + co/2;
        c = ao/2 + bo/2;
    }

    cout << -1 << endl;
    return 0;
}

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

int main(){
int n,d1,x; scanf("%d%d%d",&n,&d1,&x);
double d=d1+(2.0*n-1.0)/2.0*x,val[201000];
val[1]=1;
rep(i,2,n+1)val[i]=val[i-1]*(i+1.0)/i+1.0;
d*=val[n]; printf("%.12f",d);
return 0;
}

Measured memory_bytes: 1792
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <cctype>
#include <cassert>
#include <limits>
#include <functional>
#include <iomanip>
#include <complex>
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
#if defined(_MSC_VER) || __cplusplus > 199711L
#define aut(r,v) auto r = (v)
#else
#define aut(r,v) __typeof(v) r = (v)
#endif
#define each(it,o) for(aut(it, (o).begin()); it != (o).end(); ++ it)
#define all(o) (o).begin(), (o).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset(m,v,sizeof(m))
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
using namespace std;
typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
template<typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }
typedef complex<double> P;
long long int MOD=1000000007;
#define SIZE 200005
bool used[15];

bool judge(int n){
	bool flag=true;
	while(n>0){
		int x=n%10;
		if(!used[x])flag=false;
		n/=10;
	}
	return flag;
}

int main(){
	int n,k,x;
	cin>>n>>k;
	rep(i,10)used[i]=true;
	for(int i=0;i<k;i++){
		cin>>x;
		used[x]=false;
	}
	while(1){
		if(!judge(n))n++;
		else break;
	}
	cout<<n<<endl;
	
}



Measured memory_bytes: 256
#ifdef _WIN32
#include "stdc++.h"
#else
#include <bits/stdc++.h>
#endif

// 継承可能な型
template <class Type>
struct IN : Type
{
	IN()
	{
		std::cin >> *this;
	}
};

// 継承不可能な型
template <class Type>
struct IN_
{
	Type val;

	IN_()
	{
		std::cin >> val;
	}

	operator Type&()
	{
		return val;
	}

	IN_<Type>& operator=(const Type& _value)
	{
		val = _value;
		return *this;
	}
};

template <class Char, class Type>
std::basic_ostream<Char>& operator <<(std::basic_ostream<Char>& os, const IN_<Type>& value)
{
	return os << value.val;
}

template <class Char, class Type>
std::basic_istream<Char>& operator >>(std::basic_istream<Char>& is, IN_<Type>& value)
{
	return is >> value.val;
}

template <class Type>
void OUT(const Type& value)
{
	std::cout << value << std::endl;
}

template <class Type, class ... Args>
void OUT(const Type& value, const Args& ... args)
{
	std::cout << value << ' ';
	OUT(args...);
}

void Yes()
{
	OUT("Yes");
}
void No()
{
	OUT("No");
}

using ll = long long;
using inll = IN_<ll>;
using vll = std::vector<ll>;
using setll = std::set<ll>;
using msetll = std::multiset<ll>;
using instr = IN<std::string>;

// 階乗を計算 O(N) (N=10^7 で O(10^7))
int Factorial(ll n)
{
	for (ll i = n - 1; i > 1; i--)
		n *= i;
	return n;
}

// nCrを計算 O(N) (N=10^7 で O(10^7))
ll Combination(const ll n, const ll r)
{
	return Factorial(n) / (Factorial(r) * Factorial(n - r));
}

// 素数判定 O(sqrt(N)) (N=10^7 で O(10^3))
bool IsPrime(const ll num)
{
    if (num < 2) return false;
    if (num == 2) return true;
    if (num % 2 == 0) return false;

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return false;
        }
    }

    return true;
}

// 各桁の和を計算 O(logN) (N=10^7 で O(7))
ll DigitSum(ll n)
{
	ll sum = 0;
	while(n != 0){
		sum += n % 10;
		n /= 10;
	}
	return sum;
}

#define FOR(i, m, n) for (ll (i) = (m); (i) < (n); ++(i))
#define REP(i, n) for (ll (i) = 0; (i) < (n); ++(i))
#define REPR(i, n) for (ll (i) = (n); (i) >= 0; --(i))
#define ITRREP(it, v) for (auto (it) = (v).begin(); (it) != (v).end(); ++(it))
#define ITRREPR(it, v) for (auto (it) = (v).rbegin(); (it) != (v).rend(); ++(it))
#define DIVUP(a, b) (((a) + (b) - 1) / (b))

void Main();

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

	Main();

#ifdef _DEBUG
	system("pause");
#endif

	return 0;
}

using namespace std;

//////////////////////////////

void Main()
{
	inll n;
	vll a;
	REP(i, n)
	{
		inll a_;
		a.push_back(a_);
	}

	ll res = 0;

	REP(i, n)
	{
		while(a[i] % 2 == 0)
		{
			a[i] /= 2;
			res++;
		}
	}

	return OUT(res);
}


Measured memory_bytes: 512
from collections import defaultdict

N, K, Q = map(int, input().split(' '))
a = [int(input()) for _ in range(Q)]

num_ans = defaultdict(int)
for i in a:
    num_ans[i-1] += 1

for i in range(N):
    win = K - (Q - num_ans[i]) > 0
    print('Yes' if win else 'No')




Measured memory_bytes: 20088
import java.util.*;
import javax.lang.model.util.ElementScanner6;

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

        // 入力
        int a = sc.nextInt();
        int b = sc.nextInt();

        long out = a;
        long a1 = a;
        long b1 = b;
        while (!(out % a == 0 && out % b == 0)) {
            out = a1 > b1 ? a1 : b1;
            if (a1 < out) {
                a1 += a;
            }
            if (b1 < out) {
                b1 += b;
            }
        }

        // 出力
        System.out.println(out);
    }
}

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

using namespace std;

int main(){

    int N, K;
    string S;

    cin >> N >> S >> K;

    char ch = S[K-1];

    for(int i=0; i<N; i++){
        if (S[i] != ch) S[i] = '*';
    }

    cout << S;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define fi first
#define se second
#define pb push_back
#define pob pop_back
#define mp make_pair
#define pque priority_queue
#define endl '\n'
typedef vector <int> 	vi;
typedef pair <int, int> ii;
typedef vector <vi > 	vvi;
typedef vector <ii > 	vii;

const int N = 100, mod = 1e9 + 7, inf = 1e18 + 7;

bool a[N + 1][N + 1];

signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int n, idx = -1, t;
    cin >> n;
    int x[n], y[n], h[n];
    for (int i = 0; i < n; i++){
        cin >> x[i] >> y[i] >> h[i];
        a[x[i]][y[i]] = 1;
        if (h[i]){
            idx = i;
        }
    }
    if (idx == -1){
        for (int i = 0; i <= N; i++){
            for (int j = 0; j <= N; j++){
                if (!a[i][j]){
                    cout << i << ' ' << j << " 1";
                    return 0;
                }
            }
        }
    }
    int cx, cy, ch;
    for (int i = 0; i <= N; i++){
        for (int j = 0; j <= N; j++){
            ch = h[idx] + abs(i - x[idx]) + abs(j - y[idx]);
            bool ck = 1;
            for (int k = 0; k < n; k++){
                t = max(ch - abs(x[k] - i) - abs(y[k] - j), 0ll);
                if (t != h[k]){
                    ck = 0;
                    break;
                }
            }
            if (ck){
                cout << i << ' ' << j << ' ' << ch;
                return 0;
            }
        }
    }
}

/*
INPUT:


OUTPUT:


*/

Measured memory_bytes: 256
def main():
    N, K = map(int, input().split())
    R, S, P = map(int, input().split())
    T = list(input())

    score = 0
    for i in range(K, N):
        if T[i] == T[i-K]:
            T[i] = 'x'
    
    for t in T:
        if t == 'r':
            score += P
        elif t == 's':
            score += R
        elif t == 'p':
            score += S
    
    print(score)


if __name__ == "__main__":
    main()

Measured memory_bytes: 4084
// B - Counting of Trees
#include <bits/stdc++.h>
using namespace std;
#define rp(i,s,e) for(int i=(s);i<(e);++i)
#define MOD 998244353

int main(){
	int N; cin>>N;
	vector<int> C(N);
	int ans = 1;
	rp(i, 0, N){
		int d; scanf("%d",&d);
		if(i==0 ^ d==0){ans = 0; break;}
		C[d]++;
	}
	if(ans) rp(d, 2, N) rp(i, 0, C[d]) ans  = 1L*ans * C[d-1] % MOD;
	cout<< ans <<endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define For(i,a,b) for(int i=a;i<=b;i++)
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define sz(x) ((int)x.size())
#define int ll
#define MOD (ll)(998244353)
using namespace std;
using ll=long long;
using pii=pair<int,int>;

int gcd(int a,int b) { return b==0?a:gcd(b,a%b); }
int lcm(int a,int b) { return a/gcd(a,b)*b; }

int fpow(int b,int p)
{
	if(p==0) return 1;
	int h=fpow(b,p/2);
	if(p%2) return h*b%MOD*h%MOD;
	return h*h%MOD;
}

int32_t main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int n; cin>>n;
	vector<int> v(n),s;
	for(auto &i:v){
		cin>>i;
		s.emplace_back(i);
	}
	sort(all(s));
	for(auto &i:v){
		if(i==s.back()) cout<<s[n-2];
		else cout<<s[n-1];
		cout<<"\n";
	}
	return 0;
}

















Measured memory_bytes: 4848
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args)  {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int c = in.nextInt();
		int k = in.nextInt();
		
		List<Integer> list = new ArrayList<>();
		
		for (int i = 0; i < n; i++) {
			list.add(in.nextInt());
		}
		in.close();
		
		Collections.sort(list);
		
		int ans = 0;
		int t = list.get(0);
		
		int count = 0;
		
		for (int i = 0; i < n; i++) {
			count++;
			if(list.get(i) > t + k) {
				ans++;
				t = list.get(i);
				count = 1;
			}else if(count == c) {
				ans++;
				count = 0;
				if(i + 1 < n) {
					t = list.get(i + 1);
				}
			}
//			System.out.println(ans + " " + list.get(i));
		}
		if(count > 0) {
			ans++;
		}
		System.out.println(ans);
	}

}


Measured memory_bytes: 62744
import numpy as np
x, n = map(int, input().split())
pn = np.array([int(p) for p in input().split()])


sub = pn - x

res = 0
i = 0
while True:
    if sub[sub == -i].size == 0:
        res = x - i
        break

    if sub[sub == i].size == 0:
        res = x+i
        break
    i += 1

print(res)

Measured memory_bytes: 27288
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout<<(x)<<endl
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,vector<ll>,greater<ll>>
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define mp make_pair
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define sz(x) (int)(x).size()
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pll = pair<ll, ll>;
int main(){
  ll n;
  cin>>n;
  vll aa(100001,0);
  vll bb(100001,0);
  for (int i = 0, a, b; i < n / 2; i++){
    
    cin>>a>>b;
    aa[a]++;
    bb[b]++;
  }
  int am=0;
  int bm=0;
  int ao=0;
  int bo=0;
  for(int i=0;i<100001;i++){
    if(am<aa[i]){
      am=aa[i];
      ao=i;
    }
    if(bm<bb[i]){
      bm=bb[i];
      bo=i;
    }
  }
  sort(rall(aa));
  sort(rall(bb));
  if(ao!=bo) COUT(n-aa[0]-bb[0]);
  else{
    COUT(min(n-am-bb[1],n-aa[1]-bm));
  }
}


Measured memory_bytes: 1920
#include<bits/stdc++.h>
using namespace std;
multiset<int> s;
bool proc(){
	int n,x;
	for(scanf("%d",&n); n--;){
		scanf("%d",&x);
		s.insert(x);
	}
	for(scanf("%d",&n); n--;){
		scanf("%d",&x);
		if(s.find(x)!=s.end()){
			s.erase(s.find(x));
		}else
			return false;
	}
	return true;
}
int main(){
	puts(proc()?"YES":"NO");
	return 0;
}


Measured memory_bytes: 9600
#include<bits/stdc++.h>
#define Imposter ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define ll long long int
using namespace std;
#define f(n) for(ll i=0;i<n;i++)
#define rep(i,a,b) for(i=a;i<b;i++)
#define vll vector<ll>
#define vlll vector<vll>
#define all(x) x.begin(),x.end()

int main()
{
  int n; cin >>n;
  
  vector<ll>l(n);
  
  ll ans =0;
  for(ll i=0; i<n; i++) {
    cin >> l[i];
  }
  sort(l.begin(), l.end());
  for (ll i=0; i<n;i++) {
    for(ll j=i+1; j<n; j++) {
      for (ll k=j+1; k<n; k++) {
        if((l[i]+l[j] >l[k]) &&
           (l[i] != l[j]) &&
           (l[i] != l[k]) &&
           (l[j] != l[k])) ans++;
      }
    }
  }
  cout << ans << endl;
}


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

int main() {
  string s;
  cin >> s;
  
  int len = s.length();
  bool odd = len % 2;
  int checklen;
  
  if (odd){
    checklen = (len-1)/2;
  }else{
    checklen = len / 2;
  }
  
  int count = 0;
  
  for (int i = 0; i < checklen; i++){
    if ( s.at(i) != s.at( len -	1 - i) ){
      count++;
    }
  }
  
  cout << count << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
using Graph = vector<vector<int>>;
#define MOD 1000000007
#define MOD2 998244353
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long ll;
typedef pair<ll, ll> P;

vector<ll> s;
vector<ll> t;
vector<ll> x;

int main(){
    int a, b, q;
    cin >> a >> b >> q;
    ll tmp;

    s.push_back(-LINF);
    t.push_back(-LINF);

    rep(i, a) {
        cin >> tmp;
        s.push_back(tmp);
    }
    rep(i, b) {
        cin >> tmp;
        t.push_back(tmp);
    }
    rep(i, q) {
        cin >> tmp;
        x.push_back(tmp);
    }
    s.push_back(LINF);
    t.push_back(LINF);


    rep(i, q){
        auto itr_s = upper_bound(s.begin(), s.end(), x[i]);
        auto itr_t = upper_bound(t.begin(), t.end(), x[i]);
        int ind_s = itr_s - s.begin();
        int ind_t = itr_t - t.begin();
        ll tmp_1 = max(s[ind_s] - x[i], t[ind_t] - x[i]);
        ll tmp_2 = max(x[i] - s[ind_s - 1], x[i] - t[ind_t - 1]);
        ll tmp_3 = s[ind_s] - t[ind_t - 1] + min(s[ind_s] - x[i], x[i] - t[ind_t - 1]);
        ll tmp_4 = t[ind_t] - s[ind_s - 1] + min(t[ind_t] - x[i], x[i] - s[ind_s - 1]);
        // cout << tmp_1 << " " << tmp_2 << " " << tmp_3 << " " << tmp_4 << endl;
        cout << min({tmp_1, tmp_2, tmp_3, tmp_4}) << endl;
    }

    return 0;
}

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


typedef long long ll;
typedef vector<long long> VLL;
typedef vector<pair<int,int>> VP;
#define INF (int)(1e9)
#define MAXX 1.1529215e+18
#define inf 999999
#define EPS (1e-7)
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define REP(i,n) for(int i=1;i<=(int)(n);i++)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define ALL(a)  a.begin(),a.end()
#define RALL(a) a.begin(),a.end(),greater<int>()
#define ROT(a) a.begin(),a.begin()+1,a.end()
#define RROT(a) a.begin(),a.end()-1,a.end()
#define PB push_back
#define MP make_pair
#define PI acos(-1.0)
#define sz(a) a.size()
const ll MOD = 1e9+7;
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }
//cout << 'H' << endl;
/*--------------------------------------------*/

int main(){
  //cout.precision(10);
  cin.tie(0);
  ios::sync_with_stdio(false);

  int N;
  cin >> N;
  vector<ll> a(N);
  rep(i,N)cin >> a[i];

  sort(ALL(a));
  
  vector<ll> sum(N);
  
  sum[0] = a[0];
  
  rep(i,N-1) sum[i+1] = sum[i] + a[i+1];
  
  int tmp = 0;
    
  rep(i,N-1){  //i = 1 ~ N-2
    if(2 * sum[i] < a[i+1]){
      tmp = i+1;
    }
  }
  
  cout << N - tmp << endl;  
  
}


Measured memory_bytes: 1792