akhauriyash/Code-Regression huggingface dataset:
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author anand.oza
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        BAlgae solver = new BAlgae();
        solver.solve(1, in, out);
        out.close();
    }

    static class BAlgae {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            long r = in.nextInt();
            long D = in.nextInt();
            long x = in.nextLong();

            for (int i = 0; i < 10; i++) {
                x = r * x - D;
                out.println(x);
            }
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

    }
}



Measured memory_bytes: 21460
/*  -*- coding: utf-8 -*-
 *
 * b.cc: D: Coloring Dominoes
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 52;

typedef long long ll;
const ll MOD = 1000000007;

/* typedef */

/* global variables */

ll dp[MAX_N][3][3];

/* subroutines */

inline bool match(char c0, char c1, int i, int j) {
  return (c0 == c1 && i == j) || (c0 != c1 && i != j);
}

/* main */

int main() {
  int n;
  string s0, s1;
  cin >> n >> s0 >> s1;

  for (int j0 = 0; j0 < 3; j0++)
    for (int j1 = 0; j1 < 3; j1++)
      dp[0][j0][j1] = match(s0[0], s1[0], j0, j1) ? 1 : 0;

  for (int i = 0; i < n - 1; i++)
    for (int j0 = 0; j0 < 3; j0++)
      for (int j1 = 0; j1 < 3; j1++)
	if (dp[i][j0][j1] > 0)
	  for (int k0 = 0; k0 < 3; k0++)
	    for (int k1 = 0; k1 < 3; k1++)
	      if (match(s0[i], s0[i + 1], j0, k0) &&
		  match(s1[i], s1[i + 1], j1, k1) &&
		  match(s0[i + 1], s1[i + 1], k0, k1))
		dp[i + 1][k0][k1] = (dp[i + 1][k0][k1] + dp[i][j0][j1]) % MOD;

  ll sum = 0;
  for (int j0 = 0; j0 < 3; j0++)
    for (int j1 = 0; j1 < 3; j1++)
      sum = (sum + dp[n - 1][j0][j1]) % MOD;

  printf("%lld\n", sum);
  return 0;
}


Measured memory_bytes: 256
/*g++ main.cpp -o main.out*/
/*./main.out*/

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

#define LL long long
#define LD long double
#define Mod 1000000007
#define L_Mod 17100000013

const double eps = 1e-9;
const int INF = 0x3f3f3f3f;
const double PI = 3.1415926535;

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

#define ree(a,n) memset(a,n,sizeof(a));

#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 red(i,l,u) for(int (i)=(int)(l);(i)>=(int)(u);--(i))

LL Pow(LL a, LL n, LL m)
{
    LL t = 1;
    for (; n; n >>= 1, a = (a * a % m))
        if (n & 1)
            t = (t * a % m);
    return t;
}
const LL p=1000000007;
vector<LL> v;
LL dp[1101];
LL Cal(LL l, LL r, LL k, LL dis)
{
    LL res = 1;
    for (LL i = l; i <= r; i++)
    {
        LL t = i;
        for (LL j = 0; j < v.size(); j++)
        {
            LL y = v[j];
            while (t % y == 0) dp[j] += dis, t /= y;
        }
        res = res * (LL)t % k;
    }
    return res;
}
//扩展欧几里得exgcd
LL exgcd(LL a,LL b,LL &x,LL &y)
{
    long long d=a;
    if(b)
        d=exgcd(b,a%b,y,x),y-=x*(a/b);
    else
        x=1,y=0;
    return d;
}

// 利用exgcd求a在模m下的逆元，需要保证gcd(a, m) == 1.
LL inv(LL a, LL m)
{
    LL x, y;
    LL d = exgcd(a, m, x, y);
    return d == 1 ? (x + m) % m : -1;
}
LL Comb(LL n, LL m, LL k)
{
    memset(dp, 0, sizeof(dp));
    v.clear();
    LL tmp = k;
    for (LL i = 2; i * i <= tmp; i++)
        if (tmp % i == 0)
        {
            LL num = 0;
            while (tmp % i == 0) tmp /= i, num++;
            v.push_back(i);
        }
    if (tmp != 1) v.push_back(tmp);
    LL ans = Cal(n - m + 1, n, k, 1);
    for (LL j = 0; j < v.size(); j++) ans = ans * Pow(v[j], dp[j], k) % k;
    ans = ans * inv(Cal(2, m, k, -1), k) % k;
    return ans;
}


int main()
{
    LL n,a,b;
    cin>>n>>a>>b;
    LL ans=(Pow(2,n,Mod)-1+Mod)%Mod;
    ans=((ans-Comb(n,a,p)+Mod)%Mod-Comb(n,b,p)+Mod)%Mod;
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
def main():
    S = input()
    T = input()

    ans = 10 ** 6
    for i in range(len(S) - len(T) + 1):
        cnt = 0
        for j in range(len(T)):
            if S[i + j] != T[j]:
                cnt += 1
        ans = min(ans, cnt)
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 9044
#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
ll N,A[200010];
ll ma = 0,mi= 1e9+1;
int main(){
	cin >> N;
	vector<ll> v;;
	for(int i=1;i<=N;i++){
		cin >> A[i];
		A[i] -= i;
		v.push_back(A[i]);
	}
	ll ans1 = 0,ans2 = 0;
	sort(v.begin(),v.end());
	for(int i=1;i<=N;i++){
		ans1 += abs(A[i]-v[N/2]);
		ans2 += abs(A[i]-v[N/2+1]);
	}
	cout << min(ans1,ans2) << endl;
}

Measured memory_bytes: 3444
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef tuple<ll, ll, ll> tll;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S;
    cin >> S;
    int K;
    cin >> K;
    set<string> subStrings;
    for (int i = 0; i < 26; i++)
    {
        ll checkChar = 'a' + i;
        for (int i = 0; i < S.size(); i++)
        {
            if (S.at(i) == checkChar)
            {
                string str = "";
                for (int j = 0; j <= K; j++)
                {
                    if(i + j == S.size())
                    {
                        break;
                    }
                    str += S.at(i + j);
                    subStrings.insert(str);
                }
            }
        }
        if (subStrings.size() >= K)
        {
            break;
        }
    }
    auto ite = subStrings.begin();
    advance(ite, K - 1);
    cout << *ite << endl;
    return 0;
}


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

using ll = long long;
using P = pair<ll, ll>;

const ll MOD = 1e9+7;
// const ll MOD = 998244353;
const ll INF = 1ll<<60;

#define FOR(i,a,b) for (ll i=(a);i<(ll)(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define DEBUG(x) std::cerr << #x << " : " << (x) << std::endl;

void no()
{
	std::cout << "No" << std::endl;
	exit(0);
}

int main(int argc, char **argv)
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll X, Y; cin >> X >> Y;

	ll tmp = Y - 2*X;
	if (tmp < 0) no();
	if (tmp & 1) no();

	ll y = tmp/2;
	ll x = X - y;
	if (x < 0) no();
	
	std::cout << "Yes" << std::endl;
	return 0;
}


Measured memory_bytes: 3648
#include<iostream>
#include<iomanip>
using namespace std;
#include<vector>
#include<algorithm>
int main(){
  int n,k,i;
  cin>>n;
  vector<pair<int,int>>a(n);
  for(i=0;i<n;i++){
    cin>>a[i].first;
    a[i].second=i+1;
  }
  sort(a.begin(),a.end());
  for(i=0;i<n;i++){
    cout<<a[i].second<<" ";
  }
  return 0;
}

Measured memory_bytes: 1536
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main() {
	int D, E; int F, G;
	int a, b, c;
	int d, e, f;
	int g, h, i;
	scanf("%d%d%d%d%d%d%d%d%d", &a, &b, &c, &d, &e, &f, &g, &h, &i);
	D = b - a; E = c - b; F = d - a; G = g - d;
	if (D == e - d && D == h - g && E == f - e && E == i - h && F == e - b && F == f - c && G == h - e && G == i - f)printf("Yes");
	else printf("No");
	return 0;
}



Measured memory_bytes: 128
#pragma gcc optimize("Ofast")
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort(ALL(V)) //小さい方からソート
#define REV(V) reverse(ALL(V)) //リバース
#define RSORT(V) SORT(V);REV(V) //大きい方からソート
#define NPN(V) next_permutation(ALL(V)) //順列
#define pb(n) push_back(n)
#define endl '\n'
#define Endl '\n'
#define DUMP(x)  cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define Yay(n) cout << ((n) ? "Yay!": ":(") << endl
#define RAPID cin.tie(0);ios::sync_with_stdio(false)
#define VSUM(V) accumulate(ALL(V), 0)
#define MID(a,b,c) (a) < (b) && (b) < (c)
#define MIDe(a,b,c) (a) <= (b) && (b) <= (c)
#define IN(n) cin >> n
#define IN2(a,b) cin >> a >> b
#define IN3(a,b,c) cin >> a >> b >> c 
#define IN4(a,b,c,d) cin >> a >> b >> c >> d
#define VIN(V) for(int i = 0; i < (V).size(); i++) {cin >> (V).at(i);}
#define OUT(n) cout << n << endl
#define VOUT(V) REP(i, (V).size()) {cout << (V)[i] << endl;}
#define VOUT2(V) REP(i, (V).size()) {cout << (V)[i] << " ";} cout<<endl;

// 型マクロ定義
#define int long long
#define P pair<ll,ll>
#define Vi vector<ll>
#define Vd vector<double>
#define Vs vector<string>
#define Vc vector<char>
#define M map<ll,ll>
#define S set<ll>
#define PQ priority_queue<ll>
#define PQG priority_queue<ll,V,greater<ll>
//

const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI  = acos(-1.0);

int gcd(int a,int b){return b != 0 ? gcd(b, a % b) : a;} //最大公約数
int lcm(int a, int b){return a * b / gcd(a, b);}
string toStrUp(string str){char diff = 'A'-'a';REP(i,str.size()) str[i] += diff;return str;}
string gCh(string str, int key){return str.substr(key,1);}

signed main() {
  RAPID;
  // デフォルト変数定義
  int n=0,m=0,a=0,b=0,c=0,d=0,x=0,y=0,z=0;
  string s="",t="";
  //

  // ここから
  IN(n);
  Vi p(n);
  VIN(p)
  SORT(p);
  p[n-1] /= 2;
  OUT(VSUM(p));
}

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

int main()
{
	std::vector<int> input;
	std::copy(
		std::istream_iterator<int>(std::cin),
		std::istream_iterator<int>(),
		std::back_inserter(input));

	std::partial_sort(input.begin(), input.begin() + 3, input.end(), std::greater<int>());

	for (std::vector<int>::const_iterator i = input.begin(); i != input.begin() + 3; ++i) {
		std::cout << *i << "\n";
	}
	return 0;
}

Measured memory_bytes: 1220
#include <bits/stdc++.h>
using namespace std;
int n, m, p = 1000000007;
long long z = 1;
int main() {
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= n; i++) {
		z = z * i % p;
	}
	for (int i = 1; i <= m; i++) {
		z = z * i % p;
	}
	if (abs(n - m) > 1) {
		z = 0;
	} else if (n == m) {
		z = z * 2 % p;
	}
	printf("%lld\n", z);
	return 0;
}

Measured memory_bytes: 256
import java.util.*

val sc = Scanner(System.`in`)
val S: String = sc.next()

fun main(args: Array<String>) {
    var ans = 0
    for (i in 0 until S.length / 2 - 1) {
        if (S.slice(0..i) == S.slice(i + 1..i * 2 + 1)) {
            ans = (i + 1) * 2
        }
    }
    println(ans)
}


Measured memory_bytes: 31260
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<ll> vi;
typedef long double ld;

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define INF ll(1e18)
#define MOD (ll)1e9+7
#define print(a); for(auto x:a)cout<<x<<" "; cout<<"\n";
#define mset(a); memset(a,0,sizeof(a));

int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);
	int n;cin>>n;
	string s;cin>>s;
    map<char,ll>a;
    for(int i=0;i<n;i++){
        a[s[i]]++;
    }
    ll cnt=0;
    for(int i=0;i<n;i++){
        if(s[i]=='R'){
            cnt+=a['G']*a['B'];
            for(int j=1;j<(n-i+1)/2;j++){
                if(s[i+j]!='R'&&s[i+2*j]!='R'&&s[i+j]!=s[i+2*j]){
                    cnt--;
                }
            }
        }
        if(s[i]=='G'){
            cnt+=a['R']*a['B'];
            for(int j=1;j<(n-i+1)/2;j++){
                if(s[i+j]!='G'&&s[i+2*j]!='G'&&s[i+j]!=s[i+2*j]){
                    cnt--;
                }
            }
        }
        if(s[i]=='B'){
            cnt+=a['G']*a['R'];
            for(int j=1;j<(n-i+1)/2;j++){
                if(s[i+j]!='B'&&s[i+2*j]!='B'&&s[i+j]!=s[i+2*j]){
                    cnt--;
                }
            }
        }
        a[s[i]]--;
    }
    cout<<cnt<<"\n";
}



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

void fnInput(vector<int>& rvnNum)
{
  int nNumSiz;
  cin >> nNumSiz;
  rvnNum.resize(nNumSiz);

  for (int& rnNum : rvnNum)
    cin >> rnNum;
}

llong fnSumOfMultpl(const vector<int>& cnrvnNum)
{
  const int cnnMod = 1e9 + 7;
  llong nCumlSum = 0;

  for (int i = 0; i < cnrvnNum.size(); ++i)
    nCumlSum += cnrvnNum[i];

  llong nSumOfMultpl = 0;

  for (int i = 0; i < cnrvnNum.size() - 1; ++i)
  {
    nCumlSum -= cnrvnNum[i];

    nSumOfMultpl += cnrvnNum[i] * ( nCumlSum % cnnMod );
    nSumOfMultpl %= cnnMod;
  }

  return nSumOfMultpl;
}
  
int main()
{
  vector<int> vnNum;
  
  fnInput(vnNum);
  cout << fnSumOfMultpl(vnNum) << endl;

  return 0;
}

Measured memory_bytes: 4004
#include <iostream>
#include <cmath>
#include <queue>
#include <string>
#include <algorithm>

using namespace std;

#define INF 1e9
#define MAXN 100005
#define MAXM 100005
#define ll long long
#define vi vector<int>
#define vll vector<long long>
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define psi pair<string, int>

ll ans;
int N;

void recurr_enum(string st, int k){
    if(st.size() == N){
        cout << st << endl;
        return;
    }

    rep(i, k+1){
        char tmp = 'a' + i;
        string buff = st + tmp;
        if(i==k)
            recurr_enum(buff, k+1);
        else
            recurr_enum(buff, k);
        }
    }

void solve(){
    recurr_enum("a", 1);
}

int main(){
    cin >> N;

    solve();
}


Measured memory_bytes: 1536
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        
        int t = 0, h = 0;
        
        int x = sc.nextInt();
        
        for(int i = 0; i < x; i++){
            String str1 = sc.next();
            String str2 = sc.next();
            if(str1.compareTo(str2)<0){
                h+=3;
            }else if(str1.compareTo(str2)==0){
                t++;
                h++;
            }else{
                t+=3;
            }
        }
        System.out.println(t + " " + h);
    }
}


Measured memory_bytes: 29180
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A, B, C, D, L, R;
  cin >> A >> B >> C >>D;
  L = A + B;
  R = C + D;
  if (L > R) {
    cout << "Left" << endl;
  }
  else if (L < R) {
    cout << "Right" << endl;
  }
  else if (L == R) {
    cout << "Balanced" << endl;
  }
    
}

Measured memory_bytes: 3616
/*
  Reference:-
*/
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define F first
#define S second
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define forn1(i, n) for (int i = 1; i < int(n); i++)
#define PI pair<int,int>
#define all(vec) vec.begin(),vec.end()
ll mod=1000000007;
int n,m;
int dp[3001][3001];
string s1,s2,ans;
void sol(int i,int j){
    //cout<<ans<<" "<<ans.size()<<" 1"<<endl;
    if(i==0||j==0)return;
    if(s1[i-1]==s2[j-1]){
        ans=ans+s1[i-1];
        i--;j--;
    }
    else {
        if(dp[i-1][j]>dp[i][j-1])i--;
        else j--;
    }
    //cout<<ans<<" "<<ans.size()<<endl;
    sol(i,j);
}
int main(){
    std::ios::sync_with_stdio(false);
    //string s1,s2;
    cin>>s1>>s2;
    n=s1.size();m=s2.size();
    memset(dp,0,sizeof(dp));
    forn1(i,n+1){
        forn1(j,m+1){
            if(s1[i-1]==s2[j-1])dp[i][j]=dp[i-1][j-1]+1;
            else dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
        }
    }
    ans="";
    //cout<<ans<<" "<<ans.size()<<endl;
    sol(n,m);
    reverse(ans.begin(),ans.end());
    //reverse()
    cout<<ans;

    return 0;
}


Measured memory_bytes: 35968
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr int N = 1e5+5;
int n, p[N];
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> n;
    for(int i = 0; i < n; i++) {
        int x;
        cin >> x;
        x--;
        p[x] = i;
    }
    vector<int> a(n), b(n);
    b[0] = n * n + 5;
    for(int i = 1; i < n; i++) b[i] = b[i - 1] - n;
    a[0] = 1;
    for(int i = 1; i < n; i++) {
        int d = p[i] - p[i - 1];
        a[i] = a[i-1] + n + d;
    }
    for(int i = 0; i < n; i++) cout << a[i] << " ";
    cout << "\n";
    for(int i = 0; i < n; i++) cout << b[i] << " ";
    return 0;
}

Measured memory_bytes: 3844
package main

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

var sc = bufio.NewScanner(os.Stdin)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	sc.Split(bufio.ScanWords)

	a, b := nextInt(), nextInt()
	switch {
	case a > 8 || b > 8:
		fmt.Println(":(")
	default:
		fmt.Println("Yay!")
	}
}


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

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

    ll s, w; cin >> s >> w;

    if (w>=s) cout << "unsafe" << "\n";
    else cout << "safe" << "\n";

    return 0;
}

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

typedef long long ll;
typedef pair<int, int> P;
#define MOD 1000000007
#define INF (1 << 30)
#define REP(i, m, n) for(int i = (int)m; i < (int)n; ++i)
#define rep(i, n) REP(i, 0, n)


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

    int a, b; cin >> a >> b;
    cout << (0 < a && a < 10 && 0 < b && b < 10 ? a*b : -1) << '\n';
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    string str;cin >> str;
    bool result = false;
    for(int a = 0;a < str.size()-1;a++){
        string b;
        b.clear();
        b += str.at(a);
        b+= str.at(a+1);
        //cout<<b<<endl;
        if(b == "AC"){
            result = true;
            break;
        }
    }
    cout<<(result?"Yes":"No")<<endl;
    return 0;
}


Measured memory_bytes: 256
N=int(input())
P_=list(map(int, input().split()))
Q_=list(map(int, input().split()))
import numpy as np

def stair(N):
  ans=1
  for i in range(1,N+1):
    ans*=i
  return ans

def calc_dict(Q):
  re=list(range(1,len(Q)+1))
  ans=1
  for j in range(len(Q)-1):
    
    if Q[j]!=re[0]:
      a=np.where(np.array(re)<Q[j], 1, 0).sum()
      #print(a)
      ans+=a*stair(len(Q[(j+1):]))
      #print((Q[j]-1)*stair(len(Q[(j+1):])))
      re.remove(Q[j])
    else:
      re.remove(Q[j])
  if ans==0:
    ans+=1
  return ans


print(abs(calc_dict(P_)-calc_dict(Q_)))

      
  





Measured memory_bytes: 12516
#include <bits/stdc++.h>
#define rep(i, N) for (int i = 0; i < (N); i++)
#define swap(a, b) (a += b, b = a - b, a -= b)
using namespace std;
int main()
{
    int N;
    cin >> N;
    vector<int> A(N);
    rep(i, N)
    {
        cin >> A[i];
    }
    int max_1 = 0, max_2 = 0, key;
    rep(i, N)
    {
        if (max_1 < A[i])
        {
            max_1 = A[i];
            key = i;
        }
        else if (max_2 < A[i])
        {
            max_2 = A[i];
        }
    }
    rep(i, N)
    {
        if (i == key)
        {
            cout << max_2 << endl;
        }
        else
        {
            cout << max_1 << endl;
        }
    }
}


Measured memory_bytes: 2432
from collections import deque

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

if n % 2 == 0:
    flg = True
else:
    flg = False

na = deque()
for i in range(n):
    if i % 2 == 0:
        na.append(a[i])
    else:
        na.appendleft(a[i])

na = list(na)
if flg:
    for el in na:
        print(el, end=" ")
else:
    for el in reversed(na):
        print(el, end=" ")


Measured memory_bytes: 99796
from sys import stdin
input = stdin.readline

k,a,b=map(int,input().split())

if a+2>=b:
    print(k+1)
else:
    if k<=a:
        print(k+1)
    elif k==a+1:
        print(b)
    elif (k-(a+1))%2==0:
        print((k-(a+1))//2*(b-a)+b)
    elif (k-(a+1))%2==1:
        print((k-(a+1))//2*(b-a)+b+1)



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

using ll = long long;
using P = pair<ll, ll>;

const ll MOD = 1e9+7;
// const ll MOD = 998244353;
const ll INF = 1ll<<60;

#define FOR(i,a,b) for (ll i=(a);i<(ll)(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define DEBUG(x) std::cerr << #x << " : " << (x) << std::endl;

vector<long long> toDivisor(ll num)
{
	vector<long long> d;
	for (ll i = 1; i*i <= num; ++i)
	{
		if (i*i == num)
		{
			d.push_back(i);
		}
		else if (num % i == 0)
		{
			d.push_back(i);
			d.push_back(num/i);
		}
	}
	return d;
}

vector<pair<long long , long long>> toDivisorP(ll num)
{
	vector<pair<long long, long long>> d;
	for (ll i = 1; i * i <= num; ++i)
	{
		if (i*i == num) d.push_back(pair<ll, ll>(i, i));
		else if (num % i == 0)
		{
			d.push_back(pair<ll, ll>(i, num/i));
		}
	}
	return d;
}


int main(int argc, char **argv)
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	vector<bool> seen(1000010, false);
	ll N; cin >> N;
	vector<ll> V(N);
	REP(i, N)
		cin >> V[i];
	sort(ALL(V));
	ll res{0};
	vector<ll> tmp;
	for (ll i = 0; i < N-1; ++i)
	{
		if (V[i] == V[i+1])
			seen[V[i]] = true;
			
	}

	REP(i, N)
	{
		ll t = V[i];

		vector<ll> di = toDivisor(t);
		ll ok{true};
		for (auto &d : di)
		{
			if (seen[d])
				ok = false;
		}
		seen[t] = true;
		res += ok;
	}

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


Measured memory_bytes: 4952
#include <iostream>
#include <cstdio>

using namespace std;

const int max_n=100;

int a[max_n];

int bubble_sort(int a[],int n)
{
    int cnt=0;
    bool flag=true;
    for(int i=0;i<n-1 && flag;++i)
    {
        flag=false;
        for(int j=1;j<n-i;++j)
        {
            if(a[j-1]>a[j])
            {
                a[j-1]^=a[j];
                a[j]^=a[j-1];
                a[j-1]^=a[j];
                cnt++;
                //cout<<">";
                flag=true;
            }
        }
    }
    return cnt;
}


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

    int cnt=bubble_sort(a,n);

    for(int i=0;i<n-1;++i)
    {
        cout<<a[i]<<' ';
    }
    cout<<a[n-1]<<endl;

    cout<<cnt<<endl;
    return  0;
}



Measured memory_bytes: 3164
#include<bits/stdc++.h> 
//#define <- プログラムの文字列を置換する
//typedef <- 新しい型に名前を付けるためのキーワード

using namespace std;

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

const long long MOD = 1e9 + 7;
const long long INF = 1e15;
const int INF_INT = 1e9;

template<class TYPE>
struct edge{
    TYPE to,cost; 
    edge(TYPE t,TYPE c){
        to = t;
        cost = c;
    }
};

int main(){
    int N,M,K;
    cin >> N >> M >> K;
    ll timeA[N];
    ll timeB[M];
    for(int i = 0; i < N; i++) timeA[i] = 0;
    for(int i = 0; i < M; i++) timeB[i] = 0;
    cin >> timeA[0];
    for(int i = 1; i < N; i++){
        int a;
        cin >> a;
        timeA[i] = timeA[i-1] + a;
    }
    cin >> timeB[0];
    for(int i = 1; i < M; i++){
        int a;
        cin >> a;
        timeB[i] = timeB[i-1] + a;
    }
    int ans = 0;
    for(int i = 0; i <= N; i++){
        ll temp = K;
        int anstemp = 0;
        if(i != 0){
            temp -= timeA[i-1];
            anstemp += i;
        }
        if(temp < 0) break;
        int left = -1;
        int right = M;
        while(right - left > 1){
            int mid = (left + right) / 2;
            if(timeB[mid] <= temp) left = mid;
            else right = mid;
        }
        if(left != -1) anstemp += left + 1;
        ans = max(ans,anstemp);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 6716
'''
N  個の県があり、これらの県には合計で 
M 個の市が属しています。
市i が誕生したのは Yi 年であり、県 Pi に属しています。
それぞれの市に12 桁の認識番号を割り振ることとなりました。
市 i が 県 Pi に属する市の中で x 番目に誕生した市のとき、
市i の認識番号の上 6 桁は Pi、下 6 桁は x となります。

出力するのは県の番号とその県の中で何番目に誕生したかを
組み合わせたものになります。
したがって、まずは市を県ごとに分ける必要があります。
また、最終的にはもともとinputで受け取った順番で出力する
必要があるので、市ごとに配列に分けてそれぞれの配列に
誕生した年と初めのinputで受け取った順番を組にしたものをいれます。
このもとでそれぞれの県ごとの配列
'''
n,m=map(int,input().split())
pyi=[[] for i in range(n)]
for i in range(m):
    p,y=map(int,input().split())
    pyi[p-1].append([y,i])#県の下に、市をぶら下げる（出来た年とi）
ans=[]
for i in range(n):#県ごとに処理
    #print(pyi[i])
    pyi[i].sort()#県内で出来た年でソート
    #print(pyi[i])
    for j in range(len(pyi[i])):
        ans.append([(6-len(str(i+1)))*"0"+str(i+1)+\
                    (6-len(str(j+1)))*"0"+str(j+1),pyi[i][j][1]])
        #pyi[i][j][1]は初めのinputで受け取った順番
#print(ans)
ans.sort(key=lambda x:x[1])#入力順に並び変える
#print(ans)
for i in range(m):
    print(ans[i][0])#0は識別番号

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

#define MaxN 200005
#define INF 2140000000000

using namespace std;

int N,v[55],Min=INF,Max=-INF;
queue<pair<int,int> >Q;
int main()
{
    cin>>N;
    for(int i=1;i<=N;i++)
    {
        cin>>v[i];
        Max=max(Max,v[i]);
        Min=min(Min,v[i]);
    }
    if(Min<0&&Max>0)
    {
        int Maxpos,Minpos;
        for(int i=1;i<=N;i++)
            if(Max==v[i])
                Maxpos=i;
        for(int i=1;i<=N;i++)
            if(Min==v[i])
                Minpos=i;
        if(abs(Max)>=abs(Min))
        {
            for(int i=1;i<=N;i++)
                if(v[i]<=0)
                {
                    v[i]+=v[Maxpos];
                    Q.push({Maxpos,i});
                }
        }
        else
        {
            for(int i=1;i<=N;i++)
                if(v[i]>0)
                {
                    v[i]+=v[Minpos];
                    Q.push({Minpos,i});
                }
        }
    }
    Max=-INF,Min=INF;
    for(int i=1;i<=N;i++)
    {
        Max=max(Max,v[i]);
        Min=min(Min,v[i]);
    }
    if(Max<=0)
    {
        for(int i=N;i>1;i--)
            if(v[i]<v[i-1])
            {
                v[i-1]+=v[i];
                Q.push({i,i-1});
            }
    }
    else if(Min>=0)
    {
        for(int i=1;i<N;i++)
            if(v[i]>v[i+1])
            {
                v[i+1]+=v[i];
                Q.push({i,i+1});
            }
    }
    if(Q.empty())
    {
        cout<<0;
        return 0;
    }
    cout<<Q.size()<<'\n';
    while(!Q.empty())
    {
        cout<<Q.front().first<<' '<<Q.front().second<<'\n';
        Q.pop();
    }
    return 0;
}


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

S=list(str(input()))
S1=int("".join(S[0:2]))
S2=int("".join(S[2:4]))

if 1 <= S1 <= 12:
    s1="MM"
else:
    s1="YY"
    
if 1 <= S2 <= 12:
    s2="MM"
else:
    s2="YY"


if s1 != s2:
    print(s1+s2)
else:
    if s1 == "MM" and s2 == "MM":
        print("AMBIGUOUS")
    elif S1 == 0 and s2 =="MM":
        print("YYMM")
    elif s1 == "MM" and S1 == 0:
        print("MMYY")
    else:
        print("NA")


Measured memory_bytes: 3064
#include <bits/stdc++.h>
// #include <boost/multiprecision/cpp_dec_float.hpp>
// #include <boost/multiprecision/cpp_int.hpp>
using namespace std;
// namespace mp = boost::multiprecision;
// using Bint = mp::cpp_int;
// using Real = mp::number<mp::cpp_dec_float<128>>;
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = int(a); i < int(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()
#define debug(x) cerr << #x << ": " << (x) << '\n'
typedef long long lint;
const int INF = 2e9;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
const lint LINF = 1e18;
typedef vector<int> vint;
typedef pair<int, int> pint;
template <class T = int> T in() {
    T x;
    cin >> x;
    return (x);
}
void print() { cout << endl; }
template <class T, class... A> void print(const T &first, const A &... rest) {
    cout << first;
    print(rest...);
}
template <class... A> void print(const A &... rest) { print(rest...); }
template <class T> bool chmax(T &a, const T &b) {
    if(a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> bool chmin(T &a, const T &b) {
    if(a > b) {
        a = b;
        return 1;
    }
    return 0;
}
int modulo(int a, int b, int n) {
    long long x = 1, y = a;
    while(b > 0) {
        if(b % 2 == 1) {
            x = (x * y) % n; // multiplying with base
        }
        y = (y * y) % n; // squaring the base
        b /= 2;
    }
    return x % n;
}
/* templates */ /* templates */ /* templates */ /* templates */ /* templates */

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

    int N, K;
    cin >> N >> K;
    vector<int> a(N + 1, 0);
    rep(i, 1, N + 1) { cin >> a[i]; }
    vector<bool> dp(K + 1);
    dp[0] = false;

    rep(i, 1, K + 1) {
        rep(j, 1, N + 1) {
            if(i - a[j] >= 0 && !dp[i - a[j]]) {
                dp[i] = true;
            }
        }
    }

    if(dp[K]) {
        cout << "First" << endl;
    } else {
        cout << "Second" << endl;
    }
}

Measured memory_bytes: 256
n=int(input())
dp=list(range(n+1))
C=[]
i=1
while n>=6**i:
    C.append(6**i)
    C.append(9**i)
    i+=1
i=1
while n>=9**i:
    C.append(9**i)
    i+=1
C.sort()


for c in C:
    for i in range(n+1):
        if i-c<0:continue
        dp[i]=min(dp[i],dp[i-c]+1)
print(dp[-1])


Measured memory_bytes: 41836
//
// Created on 2020/08/02.
//


#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <ios>
#include <iomanip>
#include <numeric>

#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
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; }
typedef long long ll;
using namespace std;
const long long LINF =1e18;
const int INF = 1e9;



int main() {
    int n;
    cin>>n;
    ll d;
    cin>>d;
    int ans = 0;
    for (int i = 0; i < n; ++i) {
        ll x,y;
        cin>>x>>y;
        if(d * d >= (x * x) + (y * y)){
            ans ++;
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3512
#include <iostream>
#include <algorithm>
#include <vector>
#include <deque>
#include <queue>
#include <list>
#include <stack>
#include <string>
#include <tuple>
#include <functional>
#include <numeric>
#include <cmath>
#include <iomanip>
#include <map>
#include <random>
#include <cstdlib>
#define INT_MAX 2147483647
#define Loop(i, n) for(int i = 0; i < (int)n; i++)
#define Loop1(i, n) for(int i = 1; i < (int)n; i++)
#define Loopr(i, n) for(int i= (int)n - 1; i >= 0; i--)

using namespace std;
typedef long long int ll;

int n, q;
vector<int> a(20);

bool func(int k, int m) {
	if (m == 0) return true;
	else if (k < n) {
		return func(k + 1, m) || func(k + 1, m - a[k]);
	}
	else return false;
}


int main() {
	cin >> n;
	Loop(i, n) cin >> a[i];
	cin >> q;
	Loop(i, q) {
		int m;
		cin >> m;
		if (func(0, m)) cout << "yes" << endl;
		else cout << "no" << endl;
	}
}

Measured memory_bytes: 3084
#include<bits/stdc++.h>
using namespace std;
/**
********************************************************************
******************* Author:Bisnu sarkar ****************************
********************************************************************
**/
#define ull            unsigned long long
#define ll             long long
#define pii            pair<int,int>
#define sit            set<int> :: iterator
#define vrit           vector<int> :: reverse iterator
#define ff             first
#define ss             second
#define endl           '\n';

int set_1(int n,int pos){return n = (n | (1<<pos));}
int reset_0(int n,int pos){return n= n & ~(1<<pos);}
bool check_bit(int n,int pos){return n = n & (1<<pos);}

int dx[8]= {1,0,-1,0,-1,-1,1,1};
int dy[8]= {0,1,0,-1,-1,1,-1,1};
const int N = (int) 1e6 + 5;
const int M = (int) 1e9 + 7;
const double pi=2* acos(0.0);
const double eps=1e-9;

pii p[N];

int main()
{
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL); 

    int t=1,te=0;
    // cin>>t;
    while(t--){
        int n,x;
        cin>>n;

        for(int i=1;i<=n;++i){
            cin>>x;
            p[i]={x,i};
        }

        sort(p+1,p+n+1);

        for(int i=1;i<=n;++i)printf("%d ",p[i].ss );


        //printf("Case %d: ",++te);
    }
    return 0;
}

Measured memory_bytes: 1664
import math
import functools
import itertools
import numpy as np
import sys
MAX_INT = int(10e10)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

def tami(node,cost):
  if visited[node] == True:
    return
  else:
    visited[node] = True
    if cost%2 == 0:
      ans[node-1] = 0
    else:
      ans[node-1] = 1
    for x,c in root[node]:
      tami(x, cost+c)

N = I()
uvw = [IL() for i in range(N-1)]

root = [[] for _ in range(N+1)]
visited = [False]*(N+1)
ans = [0]*N

for u,v,w in uvw:
  root[u].append([v, w])
  root[v].append([u, w])

tami(1, 0)
for i in ans:
  print(i)

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

using namespace std;
typedef long long ll;
typedef pair<int, int> i_i;
typedef pair<ll, ll> l_l;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define int ll
//const ll mod = 1000000007;

int a, b;

signed main() {
    cin >> a >> b;
    int ans[3];
    ans[0] = a + b;
    ans[1] = a * b;
    ans[2] = a - b;
    int res = max(ans[0], max(ans[1], ans[2]));

    cout << res << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
public class Hello{
    public static void Main(){
        int N = int.Parse(Console.ReadLine());
        int[] array = Console.ReadLine().Split(' ').Select(x=>int.Parse(x)).ToArray();
        List<int> list = new List<int>();
        list.Add(0);//番兵
        list.AddRange(array);
        list.Add(0);//番兵
        var sum = list.Zip(list.Skip(1), (prev, next) => Math.Abs(prev - next)).Sum();
        int dif;
        for(var i=0;i<N;i++){
            //経路i~i+2において、点iを経由する時の距離と経由しない時の距離の差を求める
            dif = Math.Abs(list[i+1] - list[i]) + Math.Abs(list[i+2] - list[i+1]) - Math.Abs(list[i+2] - list[i]);
            Console.WriteLine(sum - dif);
        }
    }
}


Measured memory_bytes: 27740
#include<iostream>
#include<cstring>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cstdio>
#include<sstream>
#include<vector>
#include<algorithm>

using namespace std;
#define read(x) scanf("%d",&x)
#define Read(x,y) scanf("%d%d",&x,&y)
#define gc(x)  scanf(" %c",&x);
#define mmt(x,y)  memset(x,y,sizeof x)
#define write(x) printf("%d\n",x)
#define pii pair<int,int>
#define INF 0x3f3f3f3f
#define ll long long
#define mod  998244353
const int N = 1e5 + 10;
const int M = 2e6 + 1005;
int main()
{
    int n;
    cin>>n;
    ll Sum = 0,num = 0;
    for(int i = 1;i <= n;++i){
        ll a,b;
        cin>>a>>b;
        Sum += a*b;
        num += b;

    }
    num = num - 1 + (Sum - 1) /9;
    cout<<num<<endl;
}


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

int main()
{
  string s; cin>>s;
  for (int i = 0; i < 3; i++)
  {
    if (s[i] == s[i+1]) 
    {
      cout<<"Bad"<<endl;
      return 0;
    }
  }
  cout<<"Good"<<endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pll pair<long long,long long>
#define ii pair<int,int>
#define mod 1000000007
#define endl '\n'
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);

ll power(ll a,ll b){
	ll ans=1;
	while(b>0){
		if(b%2!=0){
			ans=(ans*a)%mod;
		}
		a=((a%mod)*(a%mod))%mod;
		b>>=1;
	}
	return ans;
}

void sieve(int n){
	bool prime[n+1];
	memset(prime,true,sizeof(prime));
	for(int p=2;p*p<=n;p++){
		if(prime[p]){
			for(int i=p*p;i<=n;i+=p)
				prime[i]=false;
		}
	}
	for(int p=2;p<=n;p++){
		if(prime[p])
			cout<<p<<" ";
	}
}

int main() {
	IOS;
	int t=1;
	//cin>>t;
	while(t--){
		int x,y;
		cin>>x>>y;
		if(4*x<y||2*x>y){
			cout<<"No";
			return 0;
		}
		if((y-2*x)%2==0){
			cout<<"Yes";
			return 0;
		}
		cout<<"No";
	}
	return 0;
}

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

int f(int n){
  int count = 0;
  for(int i = 0; i <= n; i++)
    count += i;
  return count;
}

int main(){
  int a, b;
  cin >> a >> b;
  int sub = b - a;
  int n = f(sub);
  cout << n - b << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, j, n) for (ll i = j; i < n; i++)
#define all(x) (x).begin(),(x).end()
#define INF (1000000000)
#define MOD (1000000007)

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

void Main(){
  ll N, K; cin >> N >> K;
  vector<ll> D(K);
  rep(i, 0, K) cin >> D[i];
  while(true){
    bool ok = true;
    rep(i, 0, K){
      ll tmp = N;
      while(tmp > 0){
        if(tmp % 10 == D[i]) ok = false;
        tmp /= 10;
      }
    }
    if(ok) break;
    N++;
  }
  cout << N << endl;
}

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

int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  //cout << std::fixed << std::setprecision(15);

  Main();
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cmath>
#include <string>
#include <vector>
#include <cstdlib>
#include <map>
#include <queue>
#include <deque>
#include <algorithm>
#include <stack>
#include <functional>
#include <sstream>
#define rep(i,j,n) for(i=j;i<(n);i++)
#define rrep(i,j,n) for(i=j;i>(n);i--)
typedef long long int lli;
#define N 1000000007
#define M 998244353

using namespace std;

struct unionfind{
    lli i;
    vector<lli> vec;
    unionfind(lli n){
        rep(i,0,n){
            vec.push_back(i);
        }
    }
    
    lli root(lli n){
        if(vec[n]==n){
            return n;
        }
        else{
            return root(vec[n]);
        }
    }
    
    void unite(lli a,lli b){
        lli ra=root(a);
        lli rb=root(b);
        if(ra!=rb){
            vec[ra]=rb;
        }
    }
    
    void reset(lli n){
        rep(i,0,n){
            vec[i]=i;
        }
    }
    
};

int main() {
    lli n,m,a,b,cnt=0;
    pair<lli,lli> dat;
    vector<pair<lli,lli>> data;
    lli i,j;
    cin>>n>>m;
    unionfind tree(n);
    rep(i,0,m){
        cin>>a>>b;
        data.push_back({a,b});
    }
    rep(i,0,m){
        tree.reset(n);
        map<lli,lli> mp;
//        cout<<data[i].first<<"ー"<<data[i].second<<"間の橋がない場合"<<endl;
        rep(j,0,m){
            if(i!=j){
                tree.unite(data[j].first-1,data[j].second-1);
            }
        }
        rep(j,0,n){
//            cout<<j+1<<"の根は、"<<tree.root(tree.vec[j])+1<<endl;
            mp[tree.root(tree.vec[j])]++;
        }
        if(mp.size()!=1){
            cnt++;
        }
    }
    cout<<cnt<<endl;
}


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

using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, a, b) for(ll i = ll(a); i <= ll(b); i++)


int main(){

 long long n;
 long double x,sum = 0.0;
  cin>>n;
 vector<long long>das;

 rep(i,0,n-1){
   cin>>x;
  das.push_back(x);
 }

  sort(das.begin(),das.end());

   x = (das[0] + das[1])/2.0;

 rep(i,2,n-1){
   x = (x + das[i])/2.0;
 }

  cout<<x<<endl;


return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using V = vector<ll>;
#define _GLIBCXX_DEBUG
#define rep(i, a) for(int i = 0; i < a; i++)
#define ALL(v) v.begin(), v.end()

int main(){
    int a,b,c; cin>>a>>b>>c;
    cout<<max(a,max(b,c))-min(a,min(b,c))<<endl;
}


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

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define itn int

typedef long long ll;
typedef pair<ll,ll> p;


int main()
{
  int k;
  cin >> k;
  int a = k / 2;
  int b = k / 2;
  if(k % 2 == 1) a++;
  cout << a * b << endl;

}

Measured memory_bytes: 768
#include <bits/stdc++.h>
#define S second 
#define F first 
#define pb push_back 
#define mp make_pair 
#define ll long long 
using namespace std;

bool flag = 0 ; 
vector < vector < int > > G ; 
vector < bool > vis ; 
int dp[100002] ; 
int n , m , from , to , ans = 0 ; 

int DFS ( int node ){
    flag = 0 ; 
    if ( dp[node] != -1 ){
        return dp[node] ; 
    }
    for ( int E : G[node] ){
        dp[node] = max ( dp[node] , DFS(E) + 1 )  ; 
        flag = 1 ; 
    }
    
    if ( flag )
        return dp[node] ; 
    return dp[node] = 0 ; 
}

int main() {
 
    cin >> n >> m ;
    G.resize(n+1) ; 
    vis.resize(n+1) ; 
    
    memset ( dp , -1 , sizeof dp ) ;
    
    for ( int i = 0 ; i < m ; ++i ){
        cin >> from >> to ; 
        G[from].pb(to) ; 
    }
    
    for ( int i = 1 ; i <= n ; ++i ){
        ans = max ( ans , DFS(i) ) ; 
    }
    cout << ans ; 
    
  return 0 ; 
}

Measured memory_bytes: 7552
# 22:12
n = int(input())
w = list(map(int,input().split()))
ans = abs(sum(w[:1]) - sum(w[1:]))
for i in range(2,n):
    if ans > abs(sum(w[:i]) - sum(w[i:])):
        ans = abs(sum(w[:i]) - sum(w[i:]))
print(ans)


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

typedef long long ll;
const int MOD = 1000000007;

int main(){
  int N;
  cin >> N;
  vector<int> a(N);
  vector<bool> color(8, false);
  int red = 0;
  for(int i = 0; i < N; i++){
    cin >> a[i];
    if(a[i] < 400){
      color[0] = true;
    }else if(a[i] < 800){
      color[1] = true;
    }else if(a[i] < 1200){
      color[2] = true;
    }else if(a[i] < 1600){
      color[3] = true;
    }else if(a[i] < 2000){
      color[4] = true;
    }else if(a[i] < 2400){
      color[5] = true;
    }else if(a[i] < 2800){
      color[6] = true;
    }else if(a[i] < 3200){
      color[7] = true;
    }else{
      red++;
    }
  }
  int cnt = 0;
  for(int i = 0; i < 8; i++){
    if(color[i]) cnt++;
  }
  cout << max(cnt, 1) << " " << cnt + red << endl;
}


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

using namespace std;

int main() {
	string alph = "abcdefghijklmnopqrstuvwxyz";
	string A;
	cin >> A;
	int first[26];
	for (int i = 0; i < 26; i++) {
		first[i] = - 1;
	}
	int nx[A.length()][26];
	int lens[A.length()][26];
	int cur[26];
	int mins[A.length()];
	for (int i = 0; i < 26; i++) {
		cur[i] = -1;
	}
	for (int i = A.length()-1; i >= 0; i--) {
		mins[i] = 300000;
		for (int j = 0; j < 26; j++) {
			nx[i][j] = cur[j];
			if (cur[j] == -1) {
				lens[i][j] = 1;
			}
			else {
				lens[i][j] = mins[cur[j]]+1;
			}
			mins[i] = min(mins[i], lens[i][j]);
		}
		cur[A[i]-'a'] = i;
		first[A[i]-'a'] = i;
	}
	bool done = false;
	for (int i = 0; i < 26; i++) {
		if (first[i] == -1) {
			done = true;
			cout << alph[i];
			break;
		}
	}
	if (!done) {
		int minval = 300000;
		int minnum = 0;
		for (int i = 0; i < 26; i++) {
			if (mins[first[i]] < minval) {
				minval = mins[first[i]];
				minnum = first[i];
			}
		}
		cout << A[minnum];
		int prev = minnum;
		while (mins[minnum] != 1) {
			for (int i = 0; i < 26; i++) {
				if (mins[nx[prev][i]] < minval) {
					minval = mins[nx[prev][i]];
					minnum = nx[prev][i];
				}
			}
			cout << A[minnum];
			prev = minnum;
		}
		for (int i = 0; i < 26; i++) {
			if (nx[prev][i] == -1) {
				cout << alph[i];
				break;
			}
		}
	}
	cout << endl;
	// cin >> first[0];
}

Measured memory_bytes: 41988
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
    int m,k;
    cin >> m >> k;
    int lim = pow(2, m);
    if(k >= lim) cout << -1 << endl;
    else if(k == 0){
        for(int i=0;i<lim; i++){
           cout << i << " " << i << " ";
        }
        cout << endl;
    }else if(m == 1){
        cout << -1 << endl;
    }else{
        cout << 0 << " " << k;
        for(int i=0;i<lim;i++){
            if(i == k) continue;
            cout << " " << i;
        }
        cout << " " << k;
        for(int i=lim-1;i>0;i--){
            if(i == k) continue;
            cout << " " << i;
        }
        cout << endl;
    }
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define debug(x)      cerr << "L" << __LINE__ << ": " << #x << " = " << (x) << endl
#define debugvec(v)   rep(i, v.size()) cerr << "L" << __LINE__ << ": " << #v << "[" << i << "] = " << v[i] << endl;
#define debugvec2(v)  cerr << "L" << __LINE__ << ": " << #v << " = { "; rep(i, v.size()) cerr << v[i] << (i + 1 == v.size() ? "" : ", "); cerr << " }" << endl;
typedef long long ll;  /* 10^18 くらいまでいける */

int main(){
  int n, a, b;
  cin >> n >> a >> b;
  cout << min(n*a, b) << endl;

  return 0;
}

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

//a^n (mod m)
const long long mod = 1e9+7;
long long modpow(long long a, long long n) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

//mod mでの a の逆元を求める
long long modinv(long long a) {
    long long b = mod, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= mod; 
    if (u < 0) u += mod;
    return u;
}

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

    ll n;
    cin>>n;
    ll a[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    ll p[n]={};
    p[0] = modinv(1);
    for(int i=1;i<n;i++){
        p[i] = p[i-1] + modinv(i+1);
        p[i] %= mod;
    }

    ll ans = 0;
    for(int i=0;i<n;i++){
        ans += (a[i] * ((p[i-0] + p[n-1 - i]+mod - 1)%mod))%mod;
        ans %= mod;
    }
    for(int i=1;i<=n;i++){
        ans *= i;
        ans %= mod;
    }
    cout<<ans<<endl;
    
}


Measured memory_bytes: 1792
#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <bitset>
#include <algorithm>
#include <functional>
#include <utility>
#include <iomanip>

#define int long long int
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )

using namespace std;

typedef pair<int, int> P;

const int INF = 1e15;
const int MOD = 1e9+7;

template <typename T>
using vector2 = vector<vector<T>>;
template <typename T>
vector2<T> initVec2(size_t n0, size_t n1, T e = T()){
    return vector2<T>(n0, vector<T>(n1, e));
}

template <typename T>
using vector3 = vector<vector<vector<T>>>;
template <typename T>
vector3<T> initVec3(size_t n0, size_t n1, size_t n2, T e = T()){
    return vector3<T>(n0, vector2<T>(n1, vector<T>(n2, e)));
}

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

    int a, b, c, d, e, k;
    cin >> a >> b >> c >> d >> e >> k;

    cout << (e - a > k ? ":(" : "Yay!") << endl;

    return 0;
}


Measured memory_bytes: 256