akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
int main() {
    set<int> a{1};
    for (int b = 2; b * b <= 1000; ++b) {
        for (int p = 2; pow(b, p) <= 1000; ++p) { a.insert((int)(pow(b, p))); }
    }

    int x;
    scanf("%d", &x);

    int ans;
    for (int i : a) {
        if (i == x) {
            ans = i;
            break;
        } else if (i > x)
            break;
        else {
            ans = i;
        }
    }
    printf("%d\n", ans);
}

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

int main(){
    int num;
    cin>>num;
    vector<int> st;
    int strong;
    for(int i=0; i<num*3; i++){
        cin>>strong;
        st.push_back(strong);
    }
    sort(st.begin(),st.end());
    long long ans=0;
    for(int i=num;i<num*2;i++){
        ans+=st[i];
    }
    long long ans2=0;
    for(int i=3*num-2;i>=num; i-=2){
        ans2+=st[i];
    }
    cout<<max(ans,ans2)<<endl;
}





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

int main() {
  int64_t n;
  cin>>n;
 int64_t count=1;
  for(int i=1;i<=n;i++){
    count=(i*count)%1000000007;
  }
  int64_t ans=count;
  cout<<ans;
}


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

using namespace std;

void dfs(vector< vector<int> >& cs, vector<int>& add, int add_sum, vector<int>& ans, int current, int p) {
    ans[current] += add_sum;
    for (auto i : cs[current]) {
        if (i != p)
            dfs(cs, add, add_sum+add[i], ans, i, current);
    }
}

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

    vector< vector<int> > cs(n+1);
    for (int i=0; i<n-1; i++) {
        int a, b;
        cin >> a >> b;
        cs[a].push_back(b);
        cs[b].push_back(a);
    }
    
    vector<int> add(n+1, 0);
    for (int i=0; i<q; i++) {
        int p, x;
        cin >> p >> x;
        add[p] += x;
    }

    vector<int> ans(n+1);
    dfs(cs, add, add[1], ans, 1, 0);

    for (int i=1; i<=n; i++)
        printf("%d%c", ans[i], i==n?'\n':' ');
}


Measured memory_bytes: 30464
#include <iostream>
#include <string>
#include <deque>

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

    std::string initial;
    std::cin >> initial;

    int queryCount = 0;
    std::cin >> queryCount;

    std::deque<std::string::value_type> work(initial.begin(), initial.end());
    auto inverted = false;
    for (auto count = 0; count < queryCount; ++count)
    {
        int instruction = 0;
        std::cin >> instruction;
        if (instruction == 1)
        {
            inverted = !inverted;
        }
        else
        {
            int option = 0;
            std::cin >> option;
            auto optionInvert = inverted;
            if (option == 1)
            {
                optionInvert = !optionInvert;
            }

            auto append = '\0';
            std::cin >> append;

            if (optionInvert)
            {
                work.push_front(append);
            }
            else
            {
                work.push_back(append);
            }
        }
    }

    if (inverted)
    {
        std::cout << std::string(work.rbegin(), work.rend());
    }
    else
    {
        std::cout << std::string(work.begin(), work.end());
    }
    
    return 0;
}

Measured memory_bytes: 1232
L = int(input())
L -= 1
n = 1
x = 0
ans = []
now = 1
while x + x+1 <= L:
    x += x+1
    n += 1
    ans.append((n-1,n,0))
    ans.append((n-1,n,now))
    now *= 2

now = now // 2
i = n-1
while now >= 1:
    if x + now<= L:
        ans.append((i,n,x+1))
        x += now
        if now == 0:now -= 1
    else:
        now = now // 2
        i -= 1
if x < L:
    ans.append((1,n,L))
print(n,len(ans))
for a in ans:
    print(' '.join(str(i) for i in a))


Measured memory_bytes: 38384
#include<bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
#define REP2(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(v) (v).begin(),(v).end()
#define INF 2e9
typedef long long ll;

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

  vector<int> num(n);
  REP(i,n) num[i]=i+1;
  int v=1,a,b;
  do{
    if(num==p) a=v;
    if(num==q) b=v;
    v++;
  }while(next_permutation(num.begin(),num.end()));

  cout<<abs(a-b)<<endl;

  return 0;
}


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

int main() {
   long long N, A, B;
   cin >> N >> A >> B;
   long long a = (N / (A + B));

   if(a <= 0) {
      cout << min(N, A) << endl;
      return 0;
   }
   else if(a > 0) {
      long long ans = a * A;
      N = (N % (A + B));
      ans += min(A, N);
      cout << ans << endl;
   }
}

Measured memory_bytes: 3672
#include<bits/stdc++.h>
using namespace std;
int n,a[201],l,sum,sumn[201]; 
int main(){
	cin>>n>>l; 
	for(int i=1;i<=n;i++){
		a[i]=l+i-1;
		sum+=a[i];
	}
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)
			if(j!=i)
				sumn[i]+=a[j];
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n-1;j++)
			if(abs(sum-sumn[j])>abs(sum-sumn[j+1]))
				swap(sumn[j],sumn[j+1]);
	cout<<sumn[1];
	return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python
# coding: utf-8

# In[8]:


import math


# In[68]:


N, K = map(int, input().split())


# In[73]:


ans = 0
if K > 1:
    for i in range(1,N+1):
        ans += (1/2)**(max(math.floor(math.log((K-1)/i, 2)) + 1, 0))/N
else:
    ans = 1


# In[74]:


print(ans)


# In[ ]:






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

#define ll long long
#define vi vector<int>
#define vl vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
// pll pp; -> (pp.first,pp.second)
// vector<vl> pp(n,vl(2)); sort(pp.begin(),pp.end(),[](vl a,vl b){return a[0]<b[0];});

#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define RREP(i,n) for(ll (i)=(n)-1;(i)>=0;(i)--)
#define FOR(i,a,b) for(ll (i)=(a);(i)<(b);(i)++)
#define FORR(i,a,b) for(ll (i)=(b)-1;(i)>=(a);(i)--)
#define DEBUG(x) cout << #x << ": " << x << endl
#define CHMAX(a,b) a=max((a),(b))
#define CHMIN(a,b) a=min((a),(b))
/*}}}*/
int main() {
  ll n;
  cin >> n;
  vl d(n);
  REP(i,n) cin >> d[i];
  sort(d.begin(),d.end());
  ll up = d[n/2];
  ll low = d[n/2-1];
  ll ans = up - low;
  cout << ans<< endl;
  return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n,a) for(int i=a;i<n;i++)
int main(){
	int X,Y;
	int mp[23][23];
	int obj[22][22];
	int sum = 0;
	while(cin >> X >> Y && X && Y){
		rep(i,22)rep(j,22)mp[i][j]=0;
		rep(i,22)rep(j,22)obj[i][j]=1;
		REP(i,X+1,1)mp[1][i]=1;
		
		rep(i,Y)rep(j,X){
			cin >> obj[1+i][1+j];
		}
		
		REP(i,Y+1,1	)REP(j,X+1,1){
			if(obj[i][j]==1){
				mp[i][j]=0;
			}else if(obj[i][j]==2){
				if(obj[i-1][ j ]==0)mp[i][j] =mp[i-1][ j ];
				if(obj[i-2][ j ]==2)mp[i][j]+=mp[i-2][ j ];
			}else{
				if(obj[i-1][j-1]==0)mp[i][j]+=mp[i-1][j-1];
				if(obj[i-1][ j ]==0)mp[i][j]+=mp[i-1][ j ];
				if(obj[i-1][j+1]==0)mp[i][j]+=mp[i-1][j+1];
				if(obj[i-2][ j ]==2)mp[i][j]+=mp[i-2][ j ];
			}
		}
		
		sum = 0;
		for(int i=1;i<=X;i++){
			sum += mp[Y][i];
			if(obj[Y-1][i]==2)sum+=mp[Y-1][i];
		}
		cout << sum << endl;
	}
}

Measured memory_bytes: 0
// Amsal Shoma Ro Gaedan Ye Amal Pasandidas !

#include <bits/stdc++.h>

#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define debug(x) cerr << #x << " : " << x << '\n'

using namespace std;

typedef long long ll;
typedef long double ld;
typedef string str;
typedef pair<ll, ll> pll;

const ll Mod = 1000000007LL;
const int N = 2e5 + 10;
const ll Inf = 2242545357980376863LL;
const ll Log = 30;

int a[N], b[N];
int n, k;
void Move(){
	memset(b, 0, sizeof b);
	for(int i = 1; i <= n; i++){
		b[max(i - a[i], 1)] ++;
		b[min(a[i] + i + 1, n + 1)] --;
	}
	for(int i = 1; i <= n; i++){
		b[i] = b[i - 1] + b[i];
		a[i] = b[i];
	}
}

int main(){
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	
	cin >> n >> k; k = min(100, k);
	for(int i = 1; i <= n; i++) cin >> a[i];
	for(int i = 0; i < k; i++) Move();
	for(int i = 1; i <= n; i++) cout << a[i] << ' ';
	cout << '\n';
	return 0;
}


Measured memory_bytes: 5204
import java.util.*; import java.io.*; import java.math.*;
public class Main{
	//Don't have to see. start------------------------------------------
	static class InputIterator{
		ArrayList<String> inputLine = new ArrayList<String>(1024);
		int index = 0; int max; String read;
		InputIterator(){
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
			try{
				while((read = br.readLine()) != null){
					inputLine.add(read);
				}
			}catch(IOException e){}
			max = inputLine.size();
		}
		boolean hasNext(){return (index < max);}
		String next(){
			if(hasNext()){
				return inputLine.get(index++);
			}else{
				throw new IndexOutOfBoundsException("There is no more input");
			}
		}
	}
	static HashMap<Integer, String> CONVSTR = new HashMap<Integer, String>();
	static InputIterator ii = new InputIterator();//This class cannot be used in reactive problem.
	static PrintWriter out = new PrintWriter(System.out);
	static void flush(){out.flush();}
	static void myout(Object t){out.println(t);}
	static void myerr(Object t){System.err.print("debug:");System.err.println(t);}
	static String next(){return ii.next();}
	static boolean hasNext(){return ii.hasNext();}
	static int nextInt(){return Integer.parseInt(next());}
	static long nextLong(){return Long.parseLong(next());}
	static double nextDouble(){return Double.parseDouble(next());}
	static ArrayList<String> nextStrArray(){return myconv(next(), 8);}
	static ArrayList<String> nextCharArray(){return myconv(next(), 0);}
	static ArrayList<Integer> nextIntArray(){
		ArrayList<String> input = nextStrArray(); ArrayList<Integer> ret = new ArrayList<Integer>(input.size());
		for(int i = 0; i < input.size(); i++){
			ret.add(Integer.parseInt(input.get(i)));
		}
		return ret;
	}
	static ArrayList<Long> nextLongArray(){
		ArrayList<String> input = nextStrArray(); ArrayList<Long> ret = new ArrayList<Long>(input.size());
		for(int i = 0; i < input.size(); i++){
			ret.add(Long.parseLong(input.get(i)));
		}
		return ret;
	}
	static String myconv(Object list, int no){//only join
		String joinString = CONVSTR.get(no);
		if(list instanceof String[]){
			return String.join(joinString, (String[])list);
		}else if(list instanceof ArrayList){
			return String.join(joinString, (ArrayList)list);
		}else{
			throw new ClassCastException("Don't join");
		}
	}
	static ArrayList<String> myconv(String str, int no){//only split
		String splitString = CONVSTR.get(no);
		return new ArrayList<String>(Arrays.asList(str.split(splitString)));
	}
	public static void main(String[] args){
		CONVSTR.put(8, " "); CONVSTR.put(9, "\n"); CONVSTR.put(0, "");
		solve();flush();
	}
	//Don't have to see. end------------------------------------------
	static void solve(){//Here is the main function
      ArrayList<String> one = nextCharArray();
      if(one.get(0).equals(one.get(1)) || one.get(1).equals(one.get(2)) || one.get(2).equals(one.get(3))){
        myout("Bad");
      }else{
        myout("Good");
      }
	}
	//Method addition frame start



	//Method addition frame end
}


Measured memory_bytes: 33260
N = int(input())
S = []
for i in range(N):
    S.append(input())
# print(N, S)

for i in range(len(S)):
    s = S[i]
    t = list(s)
    t.sort()
    S[i] = ''.join(t)

S.sort()
# print(S)

ans = 0
count = 0
for i in range(N - 1):
    si = S[i]
    sj = S[i + 1]
    if si != sj:
        ans += count * (count + 1) // 2
        count = 0
    else:
        count += 1
        if i == N - 2:
            # 最後の足し忘れ防止
            ans += count * (count + 1) // 2

print(ans)


Measured memory_bytes: 63320
#include <iostream>

using namespace std;

const long MOD = 1000000007;

long fact[200001];
long fact_inv[200001];

long binomial(long n, long k) {
	if (n < k) return 0;
	return (((fact[n] * fact_inv[k]) % MOD) * fact_inv[n - k]) % MOD;
}

long power(long n, long p) {
	if (p == 0) return 1;
	if (p % 2 == 0) return power((n * n) % MOD, p / 2);
	else return (n * power(n, p - 1)) % MOD;
}

int main(int argc, char *argv[]) {
	long H, W, A, B;
	cin >> H >> W >> A >> B;

	fact[0] = 1;
	for (int i = 1; i <= 200000; i++)
		fact[i] = (fact[i - 1] * i) % MOD;

	fact_inv[0] = 1;
	for (int i = 1; i <= 200000; i++)
		fact_inv[i] = power(fact[i], MOD - 2);

	long ans = 0;
	for (long x = B; x < W; x++) {
		long y = H - A - 1;
		long x2 = W - 1 - x;
		long y2 = A - 1;

		ans = (ans + (binomial(x + y, y) * binomial(x2 + y2, y2)) % MOD) % MOD;
	}

	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3328
#include<stdio.h>

int month(int x){
	if(1<=x && x<=12)
		return 1;
	else
		return 0;
}

int main(){
	int s;
	scanf("%d",&s);
	/*aは上二桁、bは下二桁*/
	int a,b;
	a = s/100;
	b = s%100;
	if(month(a) && month(b))
		printf("AMBIGUOUS");
	else if(month(a) && month(b)==0)
		printf("MMYY");
	else if(month(a)==0 && month(b))
		printf("YYMM");
	else
		printf("NA");
	printf("\n");
	return 0;
}

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

using namespace std;
int main(void){
    string s;
    cin >> s;
    
    int n = (int)s.size();
    
    int number_of_p = 0;
    int number_of_g = 0;
    
    int win = 0, lose = 0;
    
    if (s[0] == 'g') number_of_g++;
    else{
        number_of_g++;
        lose++;
    }
    
    for (int i = 1; i < n; i++){
        
        if (s[i] == 'g'){
            
            if (number_of_p < number_of_g){
                number_of_p++;
                win++;
            }
            else{
                number_of_g++;
            }
            
        }
        else{
            
            if (number_of_p < number_of_g) number_of_p++;
            else{
                number_of_g++;
                lose++;
            }
        }
    }
    
    cout << (win - lose) << endl;
}


Measured memory_bytes: 3728
#include <bits/stdc++.h>
#define debug(x) cerr << #x << ": " << x << endl
#define debugArray(x, n)                           \
  for (long long hoge = 0; (hoge) < (n); ++(hoge)) \
  cerr << #x << "[" << hoge << "]: " << x[hoge] << endl
using namespace std;

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a[3];
  cin >> a[0] >> a[1] >> a[2];
  if (a[0] == a[1]) {
    cout << (a[2] != a[0] ? "Yes" : "No") << endl;
  } else {
    cout << (a[2] == a[0] || a[2] == a[1] ? "Yes" : "No") << endl;
  }
  return 0;
}


Measured memory_bytes: 3664
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import (division, absolute_import, print_function,
                        unicode_literals)
from sys import stdin


def solve(n):
    square = [[0]*n for _ in range(n)]
    x = n // 2
    y = x + 1

    square[y][x] = 1
    for i in range(1, n*n):
        x = (x+1) % n
        y = (y+1) % n
        if square[y][x]:
            x = (x-1) % n
            y = (y+1) % n
        square[y][x] = i + 1

    fmt = ('{:4d}' * n).format
    print('\n'.join(fmt(*row) for row in square))

for line in stdin:
    n = int(line)
    if not n:
        break
    solve(n)

Measured memory_bytes: 4300
str=input()
rts=str[int(len(str)/2):]
str=str[:int(len(str)/2)]
if(len(str)!=len(rts)):
  rts=rts[1:]
rts=rts[::-1]
cnt=0
i=0
for e in str:
  if(rts[i]!=e):
    cnt+=1
  i+=1
print(cnt)

Measured memory_bytes: 3064
#include <stdio.h>
#include <stdlib.h>

int main(){
	int n, i;
	scanf("%d", &n);
	int *a = (int *)malloc(sizeof(int) * n);
	int *b = (int *)malloc(sizeof(int) * n);
	for(i = 0; i < n; i++){
		scanf("%d", &a[i]);
	}
	for(i = 0; i < n; i++){
		if(i % 2 == 0){
			b[i / 2] = a[n - i - 1];
		}
		else{
			b[n - i / 2 - 1] = a[n - i - 1];
		}
	}
	for(i = 0; i < n; i++){
		printf("%d ", b[i]);
	}
	return 0;
}

Measured memory_bytes: 3712
//インクルード(アルファベット順)
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
//#include<unordered_map>//イテレータあるけど順序保持しないmap
//#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列
#include<valarray>//なんとなく追加
//メモ：表示桁数を大きくする　　cout << fixed << setprecision(20) << cm << endl;
using namespace std;
typedef long long ll;

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素
#define PI acos(-1.0)
#define answer(ans) cout<<ans<<endl;
#define input(N) cin >> N ;

signed main() {
int N;
cin >> N;
string S,T,ans;
cin >> S >> T;
REP(i,N){
    ans += S.at(i);
    ans += T.at(i);
}
answer(ans);
return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
// type alias
typedef long long LL;
typedef pair<int,int> II;
typedef tuple<int,int,int> III;
typedef vector<int> VI;
typedef vector<string> VS;
typedef unordered_map<int,int> MAPII;
typedef unordered_set<int> SETI;
template<class T> using VV=vector<vector<T>>;
// minmax
template<class T> inline T SMIN(T& a, const T b) { return a=(a>b)?b:a; }
template<class T> inline T SMAX(T& a, const T b) { return a=(a<b)?b:a; }
// repetition
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define REPE(i,n)  for(int i=0;i<=(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORR(x,arr) for(auto& x:arr)
#define SZ(a) int((a).size())
// collection
#define ALL(c) (c).begin(),(c).end()
// DP
#define MINUS(dp) memset(dp, -1, sizeof(dp))
#define ZERO(dp) memset(dp, 0, sizeof(dp))
// stdout
#define println(args...) fprintf(stdout, ##args),putchar('\n');
// debug cerr
template<class Iter> void __kumaerrc(Iter begin, Iter end) { for(; begin!=end; ++begin) { cerr<<*begin<<','; } cerr<<endl; }
void __kumaerr(istream_iterator<string> it) { (void)it; cerr<<endl; }
template<typename T, typename... Args> void __kumaerr(istream_iterator<string> it, T a, Args... args) { cerr<<*it<<"="<<a<<", ",__kumaerr(++it, args...); }
template<typename S, typename T> std::ostream& operator<<(std::ostream& _os, const std::pair<S,T>& _p) { return _os<<"{"<<_p.first<<','<<_p.second<<"}"; }
#define __KUMATRACE__ true
#ifdef __KUMATRACE__
#define dump(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); __kumaerr(_it, args); }
#define dumpc(ar) { cerr<<#ar<<": "; FORR(x,(ar)) { cerr << x << ','; } cerr << endl; }
#define dumpC(beg,end) { cerr<<"~"<<#end<<": "; __kumaerrc(beg,end); }
#else
#define dump(args...)
#define dumpc(ar)
#define dumpC(beg,end)
#endif

// $ cp-batch ExceptionHandling | diff ExceptionHandling.out -
// $ g++ -std=c++14 -Wall -O2 -D_GLIBCXX_DEBUG -fsanitize=address ExceptionHandling.cpp && ./a.out

/*
 
 7/20/2019
 
 5:04-
 
 */

const int MAX_N=1e6+1;
LL A[MAX_N];
int N;

void solve() {
  VI B(A,A+N);
  sort(ALL(B)),reverse(ALL(B));
  int maxa=B[0];
  int suba=B[1];
  
//  dump(suba,maxa);
  REP(i,N) {
    int res=(A[i]!=maxa)?maxa:suba;
    println("%d",res);
  }
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout<<setprecision(12)<<fixed;
  
  cin>>N;
  REP(i,N) cin>>A[i];
  solve();
  
  return 0;
}


Measured memory_bytes: 3968
#include <bits/stdc++.h>
using namespace std;
#define ll long long int 
int main()
{
    ll n;
    cin >> n;
    priority_queue <ll> q;
    for(ll i=0;i<n;i++)
    {
        ll temp;
        cin >> temp;
        q.push(temp);
    }
    ll sum=0;
    ll t=q.top();
    sum+=t;
    q.pop();
    ll carry=0;
    for(ll i=1;i<n-1;i++)
    {
        carry++;
        if(carry%2==0)
        {
            ll z=q.top();
            sum+=z;
            q.pop();
        }
        else
        {
            ll z=q.top();
            sum+=z;

        }
        

    }
    cout << sum;
}


Measured memory_bytes: 5360
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<stack>
#include<bitset>
#include<cstdlib>
#include<cmath>
#include<set>
#include<list>
#include<deque>
#include<map>
#include<queue>
using namespace std;
typedef long long ll;
const double PI = acos(-1.0);
const double eps = 1e-6;
const int INF = 1000000000;
const int mod = 1e9+7;
const int maxn = 2e5+5;
ll a[maxn];
ll b[maxn];
struct node{
	int x,y;
	int dir;
}p[maxn]; 
bool cm1(node x1,node x2){
	if((x1.x-x1.y)==(x2.x-x2.y)) return x1.x<x2.x;
	else return (x1.x-x1.y)<(x2.x-x2.y);
}
bool cm2(node x1,node x2){
	if((x1.x+x1.y)==(x2.x+x2.y)) return x1.x<x2.x;
	else return (x1.x+x1.y)<(x2.x+x2.y);
}
bool cmp1(node x1,node x2){
	if(x1.x!=x2.x){
		return x1.x<x2.x;
	}else {
		return x1.y>x2.y;
	}
}
bool cmp2(node x1,node x2){
	if(x1.y!=x2.y){
		return x1.y>x2.y;
	}else {
		return x1.x<x2.x;
	}
}
int main() {
	int n;
	cin>>n;
	map<char,int> mp;
	mp['U'] = 1;
	mp['R'] = 2;
	mp['D'] = 3;
	mp['L'] = 4; 
	map<pair<int,int> ,int> mpp1;
	map<pair<int,int> ,int> mpp2;
	map<pair<int,int> ,int> mpp3;
	map<pair<int,int> ,int> mpp4;
	for(int i=1;i<=n;i++){
		char c;
		cin>>p[i].x>>p[i].y>>c;
		p[i].dir = mp[c];
	}
	sort(p+1,p+1+n,cm1);
	int flag = 0;
	int ans = INF;
	for(int i=1;i<=n;i++){
		int dxy = p[i].x-p[i].y;
		if(p[i].dir==4&&mpp1[{dxy,1}]){
			flag = 1;
			ans = min(ans,abs(p[mpp1[{dxy,1}]].x-p[i].x)*10);
		//	break;
		}
		if(p[i].dir==3&&mpp1[{dxy,2}]){
			flag = 1;
			ans = min(ans,abs(p[mpp1[{dxy,2}]].x-p[i].x)*10);
		//	break;
		}
		mpp1[{p[i].x-p[i].y,p[i].dir}] = i;
	}
	
	sort(p+1,p+1+n,cm2); 
	for(int i=1;i<=n;i++){
		int dxy = p[i].x+p[i].y;
		if(p[i].dir==4&&mpp2[{dxy,3}]){
			flag = 1;
			ans = min(ans,abs(p[mpp2[{dxy,3}]].y-p[i].y)*10); 
		//	break;
		}
		if(p[i].dir==1&&mpp2[{dxy,2}]){
			flag = 1;
			ans = min(ans,abs(p[mpp2[{dxy,2}]].y-p[i].y)*10);
		//	break;
		}
		mpp2[{dxy,p[i].dir}] = i;
	}
//	if(flag){
//		cout<<abs(ans)*10<<endl;
//		return 0;
//	}
	sort(p+1,p+1+n,cmp1);
	for(int i=1;i<=n;i++){
		if(p[i].dir==1&&mpp3[{p[i].x,3}]){
			flag = 1;
			ans = min(ans,abs(p[mpp3[{p[i].x,3}]].y-p[i].y)*5);
		//	break;
		}
		mpp3[{p[i].x,p[i].dir}] = i;
	}
//	if(flag){
//		cout<<abs(ans)*5<<endl;
//		return 0;
//	}
	sort(p+1,p+1+n,cmp2);
	for(int i=1;i<=n;i++){
		if(p[i].dir==4&&mpp4[{p[i].y,2}]){
			flag = 1;
			ans = min(ans,abs(p[mpp4[{p[i].y,2}]].x-p[i].x)*5);
		//	break;
			
		}
		mpp4[{p[i].y,p[i].dir}] = i;
	}
	if(flag){
		cout<<ans<<endl;
		return 0;
	}
	cout<<"SAFE\n";
    return 0;
}



Measured memory_bytes: 65064
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std;
const int N=610;
int w[N][N],c[N][N];
char s[N][N];
inline int gi() {
    int x=0,o=1;
    char ch=getchar();
    while(ch!='-'&&(ch<'0'||ch>'9')) ch=getchar();
    if(ch=='-') o=-1,ch=getchar();
    while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    return x*o;
}
int main() {
    int n,ans=0;
    cin>>n;
    for(int i=1;i<=n;i++) {
	scanf("%s",s[i]+1);
	for(int j=n+1;j<=n+n;j++) s[i][j]=s[i][j-n];
	for(int j=1;j<=n+n;j++) s[i+n][j]=s[i][j];
    }
    for(int i=1;i<=n+n;i++)
	for(int j=1;j<=n+n;j++) {
	    int x=i,y=j,a=i,b=j;
	    w[i][j]=0;
	    while(x<=n+n&&s[x][y]==s[a][b]) ++w[i][j],++x,++b;
	}
    for(int i=1;i<=n;i++)
	for(int j=1;j<=n;j++)
	    for(int k=0;k<n;k++) {
		if(w[i+k][j+k]<=n-k) break;
		if(k==n-1) ++ans;
	    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 2048
#include<bits/stdc++.h>
#define rep(i,x,y) for (int i=(x);i<=(y);i++)
#define ll long long

using namespace std;

const int N=5e5+10;
int n,v[N]; char s[N]; ll ans;

int main(){
	scanf("%s",s+1); n=strlen(s+1)+1;
	s[0]='>'; s[n]='<';
	rep (i,1,n) if (s[i-1]=='>'&&s[i]=='<'){
		v[i]=0;
		for (int j=i-1;j>=1&&s[j]=='>';j--) v[j]=max(v[j],v[j+1]+1);
		for (int j=i+1;j<=n&&s[j-1]=='<';j++) v[j]=max(v[j],v[j-1]+1);
	}
	rep (i,1,n) ans+=v[i];
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 2688
#include<bits/stdc++.h>
#define sz(x) ((int)x.size())
#define pb push_back
#define ii pair<int,int>
#define ppb pop_back
#define orta ((bas+son)>>1)
#define st first
#define nd second
#define ll long long
#define N 200005
#define inf 1000000000
#define MOD 1000000007
#define LOG 20
#define EPS 0.000000001
#define M 305
using namespace std;

map<string,int> mp;
int n;
int mx;

int main() {

	ios_base::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);

	cin>>n;
	for(int i=1;i<=n;i++) {
		string s;
		cin>>s;
		mp[s]++;
		mx=max(mx,mp[s]);
	}
	vector<string> a;
	for(auto x:mp) {
		if(x.nd==mx) a.pb(x.st);
	}
	sort(a.begin(),a.end());
	for(auto x:a) 
		cout<<x<<"\n";

}

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

int a, s[4];
char ans[4];

bool dfs(int i, int sum) {
    if (i == 4) return sum == 7;
    
    if (dfs(i + 1, sum + s[i])) {
        ans[i - 1] = '+';
        return true;
    }
    if (dfs(i + 1, sum - s[i])) {
        ans[i - 1] = '-';
        return true;
    }
    return false;
}

int main(void){
    // Your code here!
    scanf("%d", &a);
    s[0] = a / 1000;
    s[1] = a % 1000 / 100;
    s[2] = a % 1000 % 100 / 10;
    s[3] = a % 1000 % 100 % 10;
    ans[3] = '\0';
    
    dfs(1, s[0]);
    printf("%d", s[0]);
    for (int i = 0; i < 3; i++)
        printf("%c%d", ans[i], s[i + 1]);
    printf("=7");
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main() {
	int N;
	cin >> N;
	bool buy = false;
	int donut=N/7;
	for (int i = 0; i <= donut; i++) {
		if ((N - 7 * i) % 4 == 0) {
			buy = true;
			break;
		}

	}
	if (buy) cout << "Yes" << endl;
	else {
		cout << "No" << endl;
	}

}

Measured memory_bytes: 256
def inpl(): return [int(i) for i in input().split()]
mod = 10**9 +7
n = int(input())

fac = [1 for _ in range(n+1)]
for i in range(n):
    fac[i+1] = (i+1)*fac[i]%mod

inv = [1 for _ in range(n+1)]
for i in range(2,n):
    inv[i] = (-(mod//i) * inv[mod%i]) %mod    

facinv = [1 for _ in range(n+1)]
for i in range(n):
    facinv[i+1] = inv[i+1]*facinv[i]%mod

def comb(a, b):
    if a < b or b < 0:
        return 0
    return fac[a]*facinv[b]*facinv[a-b]
    
a = inpl()
x = sum(a) - n*(n+1)//2
Y = [i for i, v in enumerate(a) if v == x]
y = n-Y[1]+Y[0]

for k in range(1,n+2):
    ans = (comb(n-1, k) + 2*comb(n-1, k-1) + comb(n-1, k-2) - comb(y, k-1))%mod
    print(ans)

Measured memory_bytes: 61596
N, K = map(int, input().split())
MOD = 10**9 + 7

cnt = [0] * (K + 1)

def calc(x):
    M = K // x
    c = pow(M, N, MOD)
    for i in range(x + x, K + 1, x):
        c -= cnt[i]
    cnt[x] = c
    return c * x

ans = 0
for x in range(1, K + 1)[::-1]:
    ans = (ans + calc(x)) % MOD
print(ans)


Measured memory_bytes: 11220
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
 
typedef pair<ll,ll> pairs;
vector<pairs> p;
bool pairCompare(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.first < secondElof.first;
}
#define MAX_N 1000100
bool x[MAX_N];
ll num[MAX_N];
ll fibl[MAX_N]={0};
 
ll fib(ll a){
    if (fibl[a]!=0)return fibl[a];
    if (a==0){
        return 0;
    }else if (a==1){
        return 1;
    }
    return fibl[a]=fib(a-1)+fib(a-2);
}
 
ll eratosthenes(ll n) {
    int p = 0;
    for (ll i=0; i<=n; ++i) x[i] = true;
    x[0] = x[1] = false;
    for(int i=2; i<=n; ++i) {
        if(x[i]) {
            p++;
            for(int j=2*i; j<=n; j+=i) x[j] = false;
        }
        
        num[i] = p;
    }
    return p;
}
 
ll gcd(ll a,ll b){
    if (a%b==0)return(b);
    else return(gcd(b,a%b));
}
 
ll keta(ll N){
    int tmp{};
    while( N > 0 ){
        tmp += ( N % 10 );
        N /= 10;
    }
    N = tmp;
    return N;
}

int main(){
    ll n,k;
    cin >> n >> k;
    
    if (n%k == 0)cout << 0 << endl;
    else cout << 1 << endl;
    
    
    return 0;
    
}



Measured memory_bytes: 256
/* ICPC2008 国内予選問題 Problem A */
// http://sparth.u-aizu.ac.jp/icpc2008/d_problem.php?lang=jp#section_A
// filename = a.c
// アルゴリズム：
//  ts = 太郎が最初に持っているカードの合計点、
//  hs = 花子が最初に持っているカードの合計点、
//  t = 太郎が花子に渡すカード、 h = 花子が太郎の渡すカード とすると
//  題意より ts - t + h = hs + t - h が成立しなければならない。
//  これを整理すると、ts - hs = 2 (t - h) なので
//  ts - hs が奇数の時は題意を満たす交換は存在しない。
//  ts - hs が偶数の時は t - h = (ts - hs)/2 を満たす最小の t, h を探す。
//  このためには、太郎と花子が持っているカードをソートし、小さい方から探す。

#include <stdio.h>

int n;		// 太郎が最初に持っているカードの枚数,  1 <= n <= 100
int m;		// 花子が最初に持っているカードの枚数,  1 <= m <= 100
int tc[100];	// 太郎が持っているカードを記憶する配列,  0 <= tc[i] <= 100
int hc[100];	// 花子が持っているカードを記憶する配列,  0 <= hc[i] <= 100

// 配列 c に入っている nc 個の整数を昇順にソート（バブルソート）
void sort(int c[], int nc)
{
  int i, j;
  for(i=nc-1; i>0; i--){
    for(j=0; j<i; j++){
      if(c[j] > c[j+1]){	// c[j] > c[j+1] なら c[j] と c[j+1] を交換
	int tmp;
	tmp = c[j];
	c[j] = c[j+1];
	c[j+1] = tmp;
      }
    }
  }
}

void solve()
{
  int i, j, t, h, ts=0, hs=0;	// ts, hs は各々太郎と花子が持っているカードの合計点
  int df, found;
  for(i=0; i<n; i++) ts += tc[i];
  for(i=0; i<m; i++) hs += hc[i];
  df = ts - hs;
  if(df & 1){		// df = ts - hs が奇数
    printf("-1\n");	// 交換方法無し
    return;
  }
  sort(tc,n);	// 太郎の持っているカードを昇順にソート
  sort(hc,m);	// 花子の持っているカードを昇順にソート
  found = 0;
  for(i=0; i<m; i++){
    h = hc[i];		// h = 花子が持っているカード
    t = h + df/2;	// t = 太郎が持っているべきカード
    if(t < 0 || t > 100)	// 太郎は負や100を超える値のカードを持っていない
      continue;
    for(j=0; j<n; j++){
      if(t == tc[j]){	// 太郎はその値のカードを持っていた
	found = 1;
	break;
      }
      if(t < tc[j])	// 太郎のカードはソートされているのでこれ以上探しても無駄
	break;
    }
    if(found) break;
  }
  if(found)
    printf("%d %d\n", t, h);
  else
    printf("-1\n");
}

int main()
{
  int i;
  while(1){
    scanf("%d %d", &n, &m);		// n, m を入力
    if(n == 0 && m == 0) break;		// 両方とも0なら終了
    for(i=0; i<n; i++) scanf("%d", &tc[i]);	// 太郎のカードを読み込む
    for(i=0; i<m; i++) scanf("%d", &hc[i]);	// 花子のカードを読み込む
    solve();		// この問題を解く
  }
}



Measured memory_bytes: 2624
#include<bits/stdc++.h>
using namespace std;
#define all(vec) vec.begin(),vec.end()
typedef long long int ll;
typedef pair<ll,ll> P;
const ll MOD=1234567;
const ll INF=1000000010;
const ll LINF=1000000000000000010LL;
const int MAX=500010;
const double EPS=1e-3;
int dx[4]={0,1,0,1};
int dy[4]={0,0,1,1};
int main(){
	int n;cin>>n;
	int m=100000;
	for(int i=0;i<n;i++){
		m=m*105/100;
		if(m%1000){
			m-=m%1000;
			m+=1000;
		}
	}
	cout<<m<<endl;
	return 0;
}



Measured memory_bytes: 2996
#include<bits/stdc++.h>
#define pii pair<int,int>
#define fi first
#define se second
#define int long long
#define pb push_back
#define mod 1000000007
#define pll pair<long long,long long>
using namespace std;
long long power(long long a,long long b){
    long long ans=1;
    while(b>0){
        if(b&1){ans=(ans*a)%mod;}
                a=(a*a)%mod;
                b>>=1;
        }
    return ans;
        
}
bool prime(int n){
    for(int i=2;i*i<=n;i++){
        if(n%i==0)return false;
    }
    return true;
}
int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n;
    cin>>n;
    int k=n;
    for(int i=1;i<=n;i++){
        k=((k*10)+7)%n;
        if(k==0){
            cout<<i;
            return 0;
        }
    }
    cout<<-1;
    return 0;
}

Measured memory_bytes: 3620
#include <iostream>
#include <bits/stdc++.h>
#include <time.h>
#include <sys/timeb.h>
#include <cstdio>
#include <sys/time.h>

using namespace std;
#define ll long long
#define uint unsigned int
#define ulong unsigned long long int

int main(){
	
	string s;
	cin >> s;
	if(s.length() == 3){
		reverse(s.begin(), s.end());
	}
	
	cout << s << endl;
	
	
	
    return 0;
}

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

#define fir first
#define sec second
using namespace std;
typedef long long LL;
typedef unsigned long long u64;

template <typename T> inline bool cmin(T & a, const T & b) { return a > b ? a = b, 1 : 0;}
template <typename T> inline bool cmax(T & a, const T & b) { return a < b ? a = b, 1 : 0;}
int inp() {
	int x = 0, f = 1;char ch;
	for(ch = getchar(); !isdigit(ch); ch = getchar())
		if(ch == '-') f = -1;
	for(; isdigit(ch); x = x * 10 + ch - '0', ch = getchar());
	return x * f;
}

const int MaxN = 233;

int h, w, a[MaxN]; string s[MaxN];
int main() {
	int i, j;
	cin >> h >> w;
	for(i = 0; i < h; i++) cin >> s[i];
	for(i = 0; i < h; i++) {
		for(j = 0; j < w; j++) a[s[i][j] - 'a'] ++;
	}
	
	int cnt = 0, cnt1 = 0;
	for(i = 0; i < 26; i++) {
		if(a[i] % 4 == 2) cnt++;
		else {
			if(a[i] % 4 == 0) continue;
			if(h % 2 == 0 || w % 2 == 0) {
				if(a[i] % 2 != 0)
					return puts("No"), 0;
			} 
				else
					if(a[i] % 2 != 0) 
						if(++cnt1 > 1) return puts("No"), 0;	
		}
	}
	
	int t = 0;
	if(h % 2 == 1) t += w; if(w % 2 == 1) t += h;
	if(h % 2 == 1 && w % 2 == 1) t --;
	t /= 2;
	if(h % 2 == 0 && w % 2 == 0 && cnt) puts("No");
	else if(cnt > t) puts("No");
	else puts("Yes");
	return 0;
}




Measured memory_bytes: 256
/* ****GT_18**** */

#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define    endl        '\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define rep(i,a,b)    for(ll int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
using namespace std;

#define N  100005

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int TESTS=1;
//    cin>>TESTS;
    while(TESTS--)
    {
        string s;
        ll i,j,k,l,m,n;
        cin>>s;
        n=s.size();
        k=0;
        l=1;
        k=1;
        for(i=1;i<n;i++)
        {
            if(s[i]==s[i-1]&&l==1)
            {
                if(i==n-1)
                    continue;
                i++;
                k++;
                l=2;
            }
            else
            {
                k++;
                l=1;
            }
        }
        cout<<k<<endl;
    }
    return 0;
}   

Measured memory_bytes: 720
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<set>
#include<queue>
#include<cmath>
#define R(i, n) for(int i = 0;i < n;i++)
#define S(a) scanf("%d", &a)
#define S2(a, b) scanf("%d%d", &a, &b)
#define S3(a, b, c) scanf("%d%d%d", &a, &b, &c)
#define P(a) printf("%d", a)
#define INF 1000000000
using namespace std;
using ll = long long;
using IR = pair<int, int>;

string ST;
char C;
int Q, T, F;

int main() {
	cin >> ST;
	deque<char> s(ST.begin(), ST.end());
	S(Q);
	bool front = true;
	R(i, Q) {
		S(T);
		if (T == 1) front = !front;
		else {
			S(F);
			cin >> C;
			if (F == 1) {
				if (front) s.push_front(C);
				else s.push_back(C);
			}
			else {
				if (front) s.push_back(C);
				else s.push_front(C);
			}
		}
	}
	if (front) {
		R(i, s.size()) printf("%c", s[i]);
	}
	else {
		for(int i = s.size() - 1; i >= 0; i--) printf("%c", s[i]);
	}
}

Measured memory_bytes: 896
import java.io.PrintWriter
val pw = PrintWriter(System.out)

fun main(args : Array<String>) {
    func()
    pw.flush()
}

fun func() {
    val n = nextInt()

    if (n == 1) {
        println(1)
        return
    }

    val ll = mutableListOf<Long>()

    ll.add(2L)
    ll.add(1L)

    for (i in 2..n) {
        ll.add(ll[i-1] + ll[i-2])
    }

    println(ll.last())
}

fun next() = readLine()!!
fun nextInt() = next().toInt()

fun println(value : Any) {
    pw.println(value)
}

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

int main() {
  int a,b;
  int c=0;
  int d=10000000000;
  cin>>a;
  for(int i=0;i<a;i++){
    cin>>b;
    c=max(c,b);
    d=min(d,b);
  }
  cout<<c-d<<endl;
}

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

struct Edge {
	int row, column, weight;
};

void divide_graph(bool[], int);

int n;
Edge edges[99]{};

int main()
{
	int in_tmp, min{}, matrix[100][100]{};

	std::cin >> n;
	for (int i = 0; i < n; ++i)
		for (int j = 0; j < n; ++j)
		{
			std::cin >> in_tmp;
			matrix[i][j] = in_tmp;
		}

	int rest = n - 1, pre_size = 0;
	std::vector<int> queue{ 0 };
	bool visited[100]{ true };
	for (int i = 1; rest; ++i)
	{
		int now_size = queue.size();
		for (int j = pre_size; j < now_size; ++j)
			for (int k = 0; k < n; ++k)
			{
				int tmp = matrix[queue[j]][k];
				if (tmp != -1 && !visited[k])
				{
					visited[k] = true;
					rest--;
					edges[queue.size() - 1] = { queue[j], k , tmp};
					queue.push_back(k);
				}
			}
		pre_size = now_size;
	}
	bool flag = 1;
	while (flag)
	{
		flag = 0;
		for (int i = 0; i < n - 1; ++i)
		{
			bool conne_row[100]{};
			divide_graph(conne_row, i);

			for (int j = 0; j < n; ++j)
			{
				if (!conne_row[j]) continue;
				for (int k = 0; k < n; ++k)
				{
					if (conne_row[k]) continue;
					if (matrix[j][k] == -1 || matrix[j][k] >= edges[i].weight) continue;

					edges[i] = { j, k, matrix[j][k] };
					flag = true;
				}
			}
		}
	}

	for (int i = 0; i < n - 1; ++i)
		min += edges[i].weight;

	std::cout << min << std::endl;
	
	return 0;
}

void divide_graph(bool conne_row[], int max_edge)
{
	conne_row[edges[max_edge].row] = true;

	std::vector<int> queue = { edges[max_edge].row };
	int pre_size = 0;

	bool visit_edge[100]{};
	visit_edge[max_edge] = true;

	while (pre_size != queue.size())
	{
		int now_size = queue.size();
		for (int j = pre_size; j < now_size; ++j)
		{
			for (int k = 0; k < n - 1; ++k)
			{
				if (visit_edge[k]) continue;
				if (edges[k].row == queue[j])
				{
					visit_edge[k] = true;
					conne_row[edges[k].column] = true;
					queue.push_back(edges[k].column);
				}
				else if (edges[k].column == queue[j])
				{
					visit_edge[k] = true;
					conne_row[edges[k].row] = true;
					queue.push_back(edges[k].row);
				}
			}
		}
		pre_size = now_size;
	}
	return;
}


Measured memory_bytes: 3168
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;
template<class T> void chmin(T &a,const T &b){if(a>b) a=b;}
template<class T> void chmax(T &a,const T &b){if(a<b) a=b;}

int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};

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

  int N,M;
  cin>>N>>M;
  vector<ll> A(N),B(N),C(N);
  rep(i,N) cin>>A[i]>>B[i]>>C[i];
  vector<ll> D(M),E(M),F(M);
  rep(i,M) cin>>D[i]>>E[i]>>F[i];

  vector<ll> xs,ys;
  xs.push_back(0);
  ys.push_back(0);
  rep(i,N){
    xs.push_back(A[i]);
    xs.push_back(B[i]);
    ys.push_back(C[i]);
  }
  rep(i,M){
    xs.push_back(D[i]);
    ys.push_back(E[i]);
    ys.push_back(F[i]);
  }
  sort(xs.begin(),xs.end());
  xs.erase(unique(xs.begin(),xs.end()),xs.end());
  sort(ys.begin(),ys.end());
  ys.erase(unique(ys.begin(),ys.end()),ys.end());
  map<ll,int> xmp,ymp;
  int H=xs.size(),W=ys.size();
  rep(i,H) xmp[xs[i]]=i;
  rep(i,W) ymp[ys[i]]=i;

  vector<vector<int>> dp(2*H,vector<int> (2*W,0));
  rep(i,N){
    int u=xmp[A[i]]*2;
    int d=xmp[B[i]]*2;
    int a=ymp[C[i]]*2;
    for(int x=u;x<=d;x++) dp[x][a]=-1;
  }
  rep(i,M){
    int a=xmp[D[i]]*2;
    int l=ymp[E[i]]*2;
    int r=ymp[F[i]]*2;
    for(int y=l;y<=r;y++) dp[a][y]=-1;
  }

  queue<pair<int,int>> Q;
  int stx=xmp[0]*2+1,sty=ymp[0]*2+1;
  dp[stx][sty]=1;
  Q.push(mkp(stx,sty));
  while(!Q.empty()){
    auto f=Q.front();Q.pop();
    int x=f.first;
    int y=f.second;

    rep(k,4){
      int nx=x+dx[k];
      int ny=y+dy[k];
      if(nx<0||nx>=2*H|ny<0||ny>=2*W) continue;
      if(dp[nx][ny]!=0) continue;
      dp[nx][ny]=1;
      Q.push(mkp(nx,ny));
    }
  }

  ll ans=0;
  for(int i=0;i<2*H;i++) for(int j=0;j<2*W;j++){
    if(dp[i][j]!=1) continue;
    if(i==0||i==2*H-1||j==0||j==2*W-1){
      cout<<"INF"<<endl;
      return 0;
    }
    if(i%2==0||j%2==0) continue;
    
    ll ex=xs[i/2+1]-xs[i/2];
    ll ey=ys[j/2+1]-ys[j/2];
    ans+=ex*ey;
  }

  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 144712
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n)     for (ll i = 0; i < (b); ++i)
#define rep2(i, a, b) for (ll i = (a); i < (b); ++i)
#define repin(a, n)  \
    vector<ll> a(n); \
    rep(i, n) { cin >> a[i]; }
#define repins(a, n)     \
    vector<string> a(n); \
    rep(i, n) { cin >> a[i]; }
#define repind(a, n)     \
    vector<double> a(n); \
    rep(i, n) { cin >> a[i]; }
#define in(a) \
    ll a;     \
    cin >> a;
#define ins(a) \
    string a;  \
    cin >> a;
#define ind(a) \
    double a;  \
    cin >> a;
template <class T>
inline void out(T a) {
    cout << a << endl;
}
inline void out(double a) { printf("%.10f\n", a); }
#define all(x)  (x).begin(), (x).end()    //昇順
#define rall(x) (x).rbegin(), (x).rend()  //降順
#define yes     out("Yes");
#define no      out("No");

int main() {
    in(d);
    in(t);
    in(s);

    if ((double)d / (double)s > t) {
        no;
    } else {
        yes;
    }
}

Measured memory_bytes: 3648
#include<bits/stdc++.h>
int main()
{
    int len;
    scanf("%d",&len);
    char s[len];
    scanf("%s",s);
    int i,c;
    i=c=0;
    while(s[i]!='\0')
    {
        if(s[i]=='A'&&s[i+1]=='B'&&s[i+2]=='C')
        {
            c++;
            i=i+3;
        }
        else
        {
            i++;
        }
    }
    printf("%d\n",c);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
typedef pair<ll,ll> P;
using VP = vector<P>; using VVP = vector<VP>;
using VI = vector<ll>; using VVI = vector<VI>; using VVVI = vector<VVI>;
const int inf=1e9+7;
const ll INF=1LL<<61;
const ll mod=1e9+7;

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

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


int n;
vector<int> E[202020];
vector<ll> v(202020,INF);
VI a(202020);
VI ans(202020);

void dfs(int cu, int pa = -1) {
  // v[cu]=0;
  ans[cu]=lower_bound(v.begin(),v.end(),INF)-v.begin();
  for(int to:E[cu]) {
    if (to != pa) {
        auto it = lower_bound(v.begin(),v.end(),a[to]);
        ll pre = *it;
        *it = a[to];
        dfs(to,cu);
        *it = pre;
      //
    }
  }
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int i,j;
    cin>>n;
    for(i=0;i<n;i++) cin>>a[i];
    for(i=0;i<n-1;i++){
        int u,v;
        cin>>u>>v;
        u--; v--;
        E[u].pb(v);
        E[v].pb(u);
    }
    v[0] = a[0];
    dfs(0);
    for(i=0;i<n;i++){
        cout<<ans[i]<<endl;
    }
}

Measured memory_bytes: 30368
#include <cmath>
#include <vector>
#include <iostream>
#include <algorithm>

#pragma warning(disable : 4996)

#define PI 3.1415926535897932384626433832795L

using namespace std;

int N, X, Y;

vector<long double> x;
vector<long double> y;

int main()
{
	scanf("%d", &N);

	for (int i = 0; i < N; i++)
	{
		scanf("%d", &X);
		scanf("%d", &Y);

		x.push_back(X);
		y.push_back(Y);
	}

	bool ok = true;

	for (int i = 0; i < N - 1; i++)
	{
		// Translation.

		for (int j = 0; j < N; j++)
		{
			if (i != j)
			{
				x[j] -= x[i];
				y[j] -= y[i];
			}
		}

		x[i] = 0;
		y[i] = 0;

		// Rotate.

		long double ang = -atan2l(y[i + 1], x[i + 1]);

		for (int j = 0; j < N; j++)
		{
			if (i != j)
			{
				long double ang2 = atan2l(y[j], x[j]) + ang;
				long double radi = sqrtl(x[j] * x[j] + y[j] * y[j]);

				x[j] = radi * cosl(ang2);
				y[j] = radi * sinl(ang2);
			}
		}

		long double maxc = -999.0L, minc = 999.0;

		for (int j = i + 1; j < N; j++)
		{
			long double ang2 = atan2l(y[j], x[j]);

			maxc = max(maxc, ang2);
			minc = min(minc, ang2);
		}

		ang = PI - atan2l(y[i + 1], x[i + 1]);

		for (int j = 0; j < N; j++)
		{
			if (i != j)
			{
				long double ang2 = atan2l(y[j], x[j]) + ang;
				long double radi = sqrtl(x[j] * x[j] + y[j] * y[j]);

				x[j] = radi * cosl(ang2);
				y[j] = radi * sinl(ang2);
			}
		}

		long double maxd = -999.0L, mind = 999.0;

		for (int j = 0; j < i; j++)
		{
			long double ang2 = atan2l(y[j], x[j]);

			maxd = max(maxd, ang2);
			mind = min(mind, ang2);
		}

		if (maxc - minc > PI || (maxd - mind > PI && i != 0)) ok = false;
	}

	printf("%s\n", ok ? "Possible" : "Impossible");

	return 0;
}

Measured memory_bytes: 3540
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

#define MOD 1000000007
#define MOD2 998244353
#define int long long
#define double long double
#define EPS 1e-9
//#define PI 3.14159265358979

#define rep(i, n) for (int i = 0; i < (int)(n); i++)

using namespace std;

template < typename T >
ostream &operator<<(ostream &os, const vector< T > &A) {
	for (int i = 0; i < A.size(); i++)
		os << A[i] << " ";
	os << endl;
	return os;
}
template <>
ostream &operator<<(ostream &os, const vector< vector< int > > &A) {
	int N = A.size();
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < A[i].size(); j++)
			os << A[i][j] << " ";
		os << endl;
	}
	return os;
}

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

struct edge {
	int from, to, d, c;
	edge(int _from = 0, int _to = 0, int _d = 0, int _c = 0) {
		from = _from;
		to = _to;
		d = _d;
		c = _c;
	}
	bool operator<(const edge &rhs) const {
		return (d == rhs.d) ? (c < rhs.c) : (d < rhs.d);
	}
};
struct aabb {
	int x1, y1, x2, y2;
	aabb(int x1, int y1, int x2, int y2) : x1(x1), y1(y1), x2(x2), y2(y2) {}
};

typedef vector< edge > edges;
typedef vector< edges > graph;
struct flow {
	int to, cap, rev, cost;
	flow(int to = 0, int cap = 0, int rev = 0, int cost = 0) : to(to), cap(cap), rev(rev), cost(cost) {}
};
typedef vector< vector< flow > > flows;

const int di[4] = {0, -1, 0, 1};
const int dj[4] = {-1, 0, 1, 0};
const int ci[5] = {0, 0, -1, 0, 1};
const int cj[5] = {0, -1, 0, 1, 0};
const ll LINF = LLONG_MAX / 2;
const int INF = INT_MAX / 2;
const double PI = acos(-1);

int pow2(int n) { return 1LL << n; }
template < typename T, typename U >
bool chmin(T &x, const U &y) {
	if (x > y) {
		x = y;
		return true;
	}
	return false;
}
template < typename T, typename U >
bool chmax(T &x, const U &y) {
	if (x < y) {
		x = y;
		return true;
	}
	return false;
}

struct initializer {
	initializer() {
		cout << fixed << setprecision(20);
	}
};
initializer _____;

int N, M, K, T, Q, H, W;
signed main() {
	cin >> N >> K;
	vector< int > A(N);
	rep(i, N) cin >> A[i];
	vector< int > now = A, next(N + 1, 0);
	rep(_, K) {
		int tmp = 0;
		rep(i, N) {
			int l = max(0LL, i - now[i]);
			int r = min(N, i + now[i] + 1);
			next[l]++;
			next[r]--;
		}
		rep(i, N) next[i + 1] += next[i];
		//cout << next;
		rep(i, N) if (next[i] == N) tmp++;
		rep(i, N) now[i] = next[i];
		if (tmp == N)
			break;
		next.assign(N + 1, 0);
		//cout << tmp << endl;
	}
	rep(i, N) cout << now[i] << " ";
	cout << endl;
	return 0;
}

Measured memory_bytes: 7960
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
    int a[3];
    for(int i=0;i<3;i++) cin>>a[i];
    sort(a,a+3);
    if(a[0]==a[1]&&a[0]==5&&a[2]==7) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
}

Measured memory_bytes: 3556