akhauriyash/Code-Regression huggingface dataset:
import { ifError } from "assert";

const input=require('fs').readFileSync('/dev/stdin','utf8').split(/[\s]/);const tn=():number=>{const a=input[0];input.shift();return Number(a)};const tnn=(n:number):number[]=>{const a=[];for(let i=0;i<n;i++){a.push(tn())}return a};const ts=():string=>{const a=input[0];input.shift();return String(a)};const tss=(n:number):string[]=>{const a=[];for(let i=0;i<n;i++){a.push(ts())}return a};const tc=():string=>{let a=input[0].split('');const b=a[0];a.shift();if(a.length>0){input[0]=a.join('')}else{input.shift()}return String(b)};const tcc=(n:number):string[]=>{const a=[];for(let i=0;i<n;i++){a.push(tc())}return a};const to=(...arg)=>{console.log(...arg)};const abs=(a)=>{return Math.abs(a)};const min=(...a)=>{return Math.min(...a)};const max=(...a)=>{return Math.max(...a)};const floor=(a)=>{return Math.floor(a)};const asc=(ar:number[])=>{return ar.sort((a,b)=>{return a-b})};const desc=(ar:number[])=>{return ar.sort((a,b)=>{return b-a})};const sw=(a,arr:any[],op:'=='|'>='|'>'|'<='|'<'='==')=>{for(let i=0;i<arr.length-1;i+=2){if(eval(a+op+arr[i])){return arr[i+1];}}return arr[arr.length-1]};const near=(n:number,arr:number[]):number=>{let ne=arr[0],ni=0;for(let i=1;i<arr.length;i++){if(Math.abs(n-ne)>Math.abs(n-arr[i])){ne=arr[i];ni=i}}return ni};const objvs =(a)=>{const b=[];for(const v in a){b.push(a[v])}return b};
const main=()=>{
  let [d,n]=tnn(2)
  if(d==0&&n==100)to(101)
  else if(d==1&&n==100)to(10100)
  else if(d==2&&n==100)to(1010000)
  else to(d==0?n:d==1?100*n:10000*n)
}
main()


Measured memory_bytes: 7372
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<cstring>
#include<vector>
#include<cmath>
#include<queue>
#include<stack>
using namespace std;
#define INT(x) int x; scanf("%d",&x)
#define INPUT(x) scanf("%d",&x)
#define REP1(x,n) for(int x = 0; x < n; x++)
#define REP2(x,s,e) for(int x = s; x <= e; x++)
#define RREP1(x,n) for(int x = n-1; x >= 0; x--)
#define RREP2(x,s,e) for(int x = s; x >= e; x--)
#define BR printf("\n")
#define INF 2000000000

typedef long long ll;

int dp[301][301][300];
int cost_list[301][301][300] = {};//左残i段,右残j段,k番目
char obj[300][302] = {};

int saiki(int i,int j,int c,int H){
    if (dp[i][j][c] != -1) return dp[i][j][c];
    
    int l,r;
    if (i + 1 > H) l = INF;
    else l = saiki(i+1,j,c,H) + cost_list[i+1][j][c];
    
    if (j + 1 > H) r = INF;
    else r = saiki(i,j+1,c,H) + cost_list[i][j+1][c];
    
    dp[i][j][c] = min(l,r);

    return dp[i][j][c];
}

void cost_decide(int H, int W){
    REP1(c,W-1){
        REP2(i,1,H){ //i(1 -> H) , j = H
            int si = i - 1;
            int sj = H - 1;
            
            int org_cost = 0;
            
            REP1(t,i){//沈めていない状況の計算
                if (obj[si - t][c] == obj[sj - t][c + 1]) {
                    org_cost++;
                }
            }
            
            REP1(t,i){//沈めていく
                cost_list[i-t][H-t][c] = org_cost;
                if (obj[si - t][c] == obj[sj - t][c + 1]){
                    org_cost--;
                }
            }
        }
        RREP2(j,H-1,1){ //i = H , j(H -> 1)
            int si = H - 1;
            int sj = j - 1;
            
            int org_cost = 0;
            
            REP1(t,j){//沈めていない状況の計算
                if (obj[si - t][c] == obj[sj - t][c + 1]) {
                    org_cost++;
                }
            }
            
            REP1(t,j){//沈めていく
                cost_list[H-t][j-t][c] = org_cost;
                if (obj[si - t][c] == obj[sj - t][c + 1]){
                    org_cost--;
                }
            }
        }
    }
}

void rec(int H, int W){
    cost_decide(H,W);
    
    int sum = 0;
    
    REP1(c,W-1){
        RREP2(i,H-1,1){
           int s = saiki(0,0,c,H);
        }
        sum += saiki(0,0,c,H);
    }
    cout << sum << endl;
}

int main(){
    INT(H);INT(W);
    REP1(i,H) cin >> obj[i];

    REP1(i,H+1){
        REP1(j,H+1){
            REP1(c,W-1){
                dp[i][j][c] = -1;
            }
        }
    }
    REP1(c,W-1){
        dp[H][H][c] = 0;
    }
    rec(H,W);

    return 0;
}

Measured memory_bytes: 212352
#include <cstdio>
typedef long long lld;
int A, B;

template <typename T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
lld lcm(int a, int b) { return 1LL * a / gcd(a, b) * b; }

int main() {
  scanf(" %d%d", &A, &B);
  printf("%lld\n", lcm(A, B));
  return 0;
}

Measured memory_bytes: 256
import collections

N, K = map(int, input().split())
arr = list(map(int, input().split()))
ans = 0
cnt = collections.defaultdict(int)
for num in arr:
    cnt[num] += 1

vals = sorted(cnt.values())

if len(cnt) > K:
    for i in range(len(cnt) - K):
        ans += vals[i]

print(ans)


Measured memory_bytes: 99152
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int a[n+1],b[n+1],c[n+1];
    for(int i=0;i<n;i++)cin>>a[i];
    for(int i=0;i<n;i++)cin>>b[i];
    for(int i=0;i<n-1;i++)cin>>c[i];
    int last=-1,ans=0;
    for(int i=0;i<n;i++)
    {
        ans+=b[a[i]-1];
        if(last==a[i]-1)
        {
            ans+=c[last-1];
        }
        last=a[i];
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
import sys
readline = sys.stdin.readline
N, K = map(int, readline().split())
H = list(map(int, readline().split()))
H = [0] + H
N += 1
inf = 10**18
dp = [[[inf]*(K+1) for j in range(N)] for i in range(N)]
dp[0][0][0] = 0
for i in range(1, N):
    hi = H[i]
    for j in range(i):
        hj = H[j]
        for k in range(1, 1 + min(K, i)):
            dp[i][j][k] = dp[i-1][j][k-1]
    for k in range(min(K+1, i)):
        dp[i][i][k] = min(dp[i-1][j][k] + max(0, hi - H[j]) for j in range(i))

print(min(min(dp[N-1][j]) for j in range(N)))

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

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

typedef unsigned long long ull;
typedef long long ll;

const int INF = 1001001001;

int main() {
    string s;
    cin >> s;

    string ans = (s[2] == s[3] && s[4] == s[5]) ? "Yes" : "No";
    cout << ans << endl;
}

Measured memory_bytes: 256
<?php

fscanf(STDIN, "%d", $n);
$A = explode(' ', trim(fgets(STDIN)));

$A = array_flip($A);
ksort($A);
$str = '';
for ($i = 1; $i <= $n; ++$i) {
    $str .= ($A[$i] + 1) . ' ';
}
echo substr($str, 0, -1);


Measured memory_bytes: 20980
//package abc136;
import java.io.*;
import java.util.*;

public class Main {
	// ------------------------
	
	public static void main(String[] args) {
		MyScanner sc = new MyScanner();
		out = new PrintWriter(new BufferedOutputStream(System.out));
		// ------------------------
		int n = sc.nextInt(), ans = 0;
		for(int i = 1; i <= n; i++)
			if(dig(i) % 2 == 1)
				ans++;
		out.println(ans);
		// ------------------------
		out.close();
	}
	//------------------------
	static int dig(int n) {
		if(n == 0)
			return 0;
		return 1 + dig(n / 10);
	}
	public static PrintWriter out;
	public static class MyScanner {
		BufferedReader br;
		StringTokenizer st;
		public MyScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}
		String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}
		int nextInt() {
			return Integer.parseInt(next());
		}
		long nextLong() {
			return Long.parseLong(next());
		}
		double nextDouble() {
			return Double.parseDouble(next());
		}
		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}
	}
}


Measured memory_bytes: 21204
#include<stdio.h>
#include<algorithm>
#include<queue>
#include<string.h>
using namespace std;
#define NIL -2000000001
#define INFTY 2000000001
#define MAX 101
#define WHITE 0
#define GRAY 1
#define BLACK 2

int n = 0;
int adm[MAX][MAX];
int color[MAX];
int d[MAX], p[MAX];
queue<int> queueBfs;


int mst() {
  int sum = 0;
  for ( int i = 0; i < n; i++ ) {
    color[i] = WHITE;
    d[i] = INFTY;
    p[i] = -1;
  }
  d[0] = 0;

  while (true) {
    int mincost = INFTY;
    int u; //訪問する頂点

    for (int i = 0; i < n; i++) {
      if (color[i] != BLACK && d[i] < mincost) {
        mincost = d[i];
        u = i;
      }
    }
    if (mincost == INFTY) break;
    sum += mincost;
    color[u] = BLACK;

    // u周りの頂点vの情報を入れる
    for (int v = 0; v < n; v++) {
      if (color[v] != BLACK && adm[u][v] != -1 && adm[u][v] < d[v]) {
        d[v] = adm[u][v];
        p[v] = u;
        color[v] = GRAY;
      }
    }
  }

  return sum;
}

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

  printf("%d\n", mst());
  
  return 0;
}



Measured memory_bytes: 2764
import java.io.IOException;
import java.lang.*;
public class Main {
	
		
		public static void main(String[] args) throws IOException {
			java.util.Scanner scan = new java.util.Scanner(System.in);
		int x = scan.nextInt();
			
//			BufferedReader br = new BufferedReader (new InputStreamReader(System.in));
//			String str = br.readLine();
//			int x = Integer.parseInt(str);
//			
		if(1<=x && x<=100){;
		System.out.println(x*x*x);// TODO ?????????????????????????????????????????????
		}
		}	
			
		
	
	}
	

Measured memory_bytes: 26132
N = int(input())

flag = True
t, x, y = 0, 0, 0

for _ in range(N):
    t_nxt, x_nxt, y_nxt = map(int, input().split())
    dist = abs(x_nxt - x) + abs(y_nxt - y)
    if dist == 0 or not (dist <= t_nxt and (t_nxt - dist) % 2 == 0):
        flag = False

print('Yes' if flag else 'No')

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
int a[200001];
vector<int> v;
main()
{
    ios_base::sync_with_stdio(false);
    int n;
    scanf("%d",&n);
    for(int i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
        v.push_back(a[i]);
    }
    sort(v.begin(),v.end());
    int mid1,mid2;
    mid1 = v[n/2-1];
    mid2 = v[n/2];
    for(int i=0;i<n;i++)
    {
        if(a[i]<=mid1)cout<<mid2<<endl;
        else cout<<mid1<<endl;
    }
}


Measured memory_bytes: 3956
import sys
def input():
    return sys.stdin.readline()[:-1]
n,m=map(int,input().split())
xyz=[list(map(int,input().split())) for i in range(m)]
# print(xyz)
class WeightedUnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n+1)]
        self.rank = [0] * (n+1)
        self.weight = [0] * (n+1)


    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            y = self.find(self.par[x])
            self.weight[x] += self.weight[self.par[x]]
            self.par[x] = y
            return y

    def union(self, x, y, w):
        rx = self.find(x)
        ry = self.find(y)
        if self.rank[rx] < self.rank[ry]:
            self.par[rx] = ry
            self.weight[rx] = w - self.weight[x] + self.weight[y]
        else:
            self.par[ry] = rx
            self.weight[ry] = -w - self.weight[y] + self.weight[x]
            if self.rank[rx] == self.rank[ry]:
                self.rank[rx] += 1

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def diff(self, x, y):
        return self.weight[x] - self.weight[y]

uf=WeightedUnionFind(n)
for i in range(m):
    uf.union(xyz[i][0] ,xyz[i][1],1)

dic={}
for i in range(n):
    tmp=uf.find(i+1)
    if tmp in dic:
        continue
    else:
        dic[tmp]=1

print(len(dic.values()))

Measured memory_bytes: 89052
h, w = map(int, input().split())
a = [list(input()) for _ in range(h)] # #.のグリッドの場合
#print(a)

from collections import deque
step = [(0,1), (0,-1), (1,0), (-1,0)]
que = deque()

seen = [[-1] * w for _ in range(h)]
for i in range(h):
    for j in range(w):
        if a[i][j] == '#':
            que.append((i, j))
            seen[i][j] = 0
ans = 0
#import numpy as np
#print(np.array(seen))
while len(que) > 0:
    x, y = que.popleft()
    for tx, ty in step:
        xi, yi = x + tx, y + ty
        if xi < 0 or yi < 0 or xi >= h or yi >= w:
            continue
        if a[xi][yi] == '#':
            continue
        if a[xi][yi] == '.':
            seen[xi][yi] = seen[x][y] + 1
            ans = max(ans, seen[xi][yi])
            a[xi][yi] = '#'
            que.append((xi, yi))
    #print(np.array(seen))
print(ans)




Measured memory_bytes: 121564
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <tuple>
#include <vector>

using namespace std;
typedef long long int ll;
typedef vector<int> vi;
typedef vector<vi> vvi;

#define INF (1e9)

int N, K;
string S;

int main() {
    cin >> N >> K;
    cin >> S;

    S[K - 1] = S[K - 1] - 'A' + 'a';
    cout << S << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define IFOR(i, m, n) for (ll i = n - 1; i >= m; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define FOREACH(x, a) for (auto&(x) : (a))
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ll(x.size())

int main() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  string t = "RGB";
  long long ans = 0;
  for (int j = 1; j < n - 1; j++) {
    int idx;
    for (int l = 0; l < t.size(); l++) {
      if (s[j] == t[l]) {
        idx = l;
      }
    }
    // idx = s[j]がtの何番目に一致しているか？
    char c1 = t[(idx + 1) % 3], c2 = t[(idx + 2) % 3];
    // cnt1L = (s[j] = 'R'のときなら)s[j]の左にあるGの数，cnt2R =
    // s[j]の右にあるBの数
    int cnt1L = 0, cnt2L = 0, cnt1R = 0, cnt2R = 0;
    for (int i = 0; i < j; i++) {
      if (s[i] == c1) {
        cnt1L++;
      } else if (s[i] == c2) {
        cnt2L++;
      }
    }
    for (int k = j + 1; k < n; k++) {
      if (s[k] == c1) {
        cnt1R++;
      } else if (s[k] == c2) {
        cnt2R++;
      }
    }
    ans += cnt1L * cnt2R + cnt2L * cnt1R;
    for (int d = 1; d <= n; d++) {
      int l = j - d, r = j + d;
      if (l < 0 || r >= n) {
        break;
      }
      if (s[l] != s[r] && s[l] != s[j] && s[j] != s[r]) {
        ans--;
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9 + 7;
const int MOD = 1e9 + 7;

int main()
{
  int n, m;
  cin >> n >> m;
  int sum = 0;
  vector<int> list(n);
  for (int i = 0; i < n; i++) {
    cin >> list[i];
    sum += list[i];
  }

  int cnt = 0;
  double b = (double) 1 / (4 * m);
  for (int i = 0; i < n; i++) {
    double a = (double) list[i] / sum;
    if (a >= b) {
      cnt++;
    }
  }
  if (cnt >= m) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

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

	sc.Scan()
	s := sc.Text()
	h, err := strconv.Atoi(s)
	if err != nil {
		panic("error")
	}

	sc.Scan()
	s = sc.Text()
	w, err := strconv.Atoi(s)
	if err != nil {
		panic("error")
	}

	fmt.Printf("%d %d\n", h*w, 2*(h+w))
}



Measured memory_bytes: 1060
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e16;
const ll mod = 1000000007;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

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;
}
int ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}
ll factorial(ll n) {
  if (n == 1) {
    return 1;
  }
  ll ans = factorial(n-1);
  return ans*n;
}
ll gcd(ll a, ll b) {
  if (b == 0) return a;
  return gcd(b, a%b);
}
ll lcm(ll a, ll b) {
  return (a/gcd(a, b))*b;
}
bool is_prime(ll n) {
  for (ll i = 2; i*i <= n; i++) {
    if (n%i == 0) return false;
  }
  return n != 1;
}
ll mod_pow(ll x, ll n, ll mod) {
  if (n == 0) return 1;
  ll res = mod_pow(x*x%mod, n/2, mod);
  if (n & 1) res = res * x % mod;
  return res;
}

int main() {
  ll a, b, c;
  cin >> a >> b >> c;
  cout << c <<  ' ' << a << ' ' << b << endl;
}

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

int main() {
  int n, a, b, c;
  cin >> n >> a >> b >> c;

  vector<int> d(n);

  for (int &topping : d) {
    cin >> topping;
  }

  sort(d.begin(), d.end());
  reverse(d.begin(), d.end());

  int answer = 0;
  for (int use = 0; use <= n; use++) {
    int sum = c;
    if (use > 0) {
      for (int i = 0; i < use; i++) {
        sum += d[i];
      }
    }

    answer = max(answer, sum / (a + b * use));
  }
  cout << answer << endl;
}

Measured memory_bytes: 1216
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>
typedef long long LL;
constexpr int kMod = 1000000007;
constexpr int kMax = 21;

std::string bin(int v, int n) {
  std::string ret;
  for (int i = 0; i < n; ++i) {
    if (v & (1 << i)) ret += "1";
    else              ret += "0";
  }
  return ret;
}

int main() {
  static LL dp[kMax+1][1 << kMax];
  int a[kMax+1][kMax+1];

  int N; std::cin >> N;
  for (int i = 1; i <= N; ++i) {
    for (int j = 1; j <= N; ++j) {
      std::cin >> a[i][j];
    }
  }

  dp[0][0] = 1;
  for (int k = 1; k < (1 << N); ++k) {
    dp[0][k] = 0;
  }

  for (int i = 1; i <= N; ++i) {
    for (int j = 1; j <= N; ++j) {
      if (a[i][j]) {
#if DEBUG
        std::cout << i << ", " << j << ":" << std::endl;;
#endif
        for (int k = 0; k < (1 << N); ++k) {
          int mask = (1 << (j-1));
          if (k & mask) continue;
#if DEBUG
          std::cout << "  " << bin(k, N) << "->" << bin(k|mask, N);
#endif
          dp[i][k|mask] += dp[i-1][k];
          dp[i][k|mask] %= kMod;
#if DEBUG
          std::cout << "-->" << dp[i][k|mask] << std::endl;
#endif
        }
      }
    }
  }

  std::cout << dp[N][(1 << N)-1] << std::endl;
}


Measured memory_bytes: 360704
#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()

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

const int mod =  1000000007;  //出力は (ans % mod + mod) % mod  (負の剰余を正にする)
const int inf = 1e9;
const long long INF = 1LL << 60;   // INF = 11


int main()
{
    int n,l; cin >> n >> l;
    vector<string> vec;
    rep(i,n){
        string s;cin >> s;
        vec.push_back(s);
    }
    sort(all(vec));
    for(int i = 0; i < n; i++) cout << vec[i];
}

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

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

		for (int i = 0; i < n; i++){
			s[i] = sc.next();
			sc.nextLine();
		}

		Arrays.sort(s);

		for (int i = 0; i < n; i++) {
			System.out.print(s[i]);
		}
		System.out.println();
	}
}

Measured memory_bytes: 21716
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <time.h>
signed main(void){

    char str[3000];
    char *tok;
    int m,n;
    int i1,i2,i3,i4,i44;
    int flag=0;
    int a;
    int b;
    int c;

    
    fgets(str, sizeof(str), stdin);
    tok=strtok(str," ");
    a=strtol(tok,NULL,10);
    tok=strtok(NULL," ");
    b=strtol(tok,NULL,10);
    tok=strtok(NULL," ");
    c=strtol(tok,NULL,10);
    
    if(a*c<=b) printf("%d",c);
    else printf("%d",b/a);

    
    
}


Measured memory_bytes: 128
#Solve this by Rerooting
import sys
from itertools import accumulate
input = sys.stdin.buffer.readline

N = int(input())
adj = [[] for _ in range(N)]
for _ in range(N-1):
    a, b = map(int, input().split())
    adj[a-1].append(b-1)
    adj[b-1].append(a-1)


dfs_order = []
parent = [-1] * N
root = 0
stack = [root]
while stack:
    node = stack.pop()
    dfs_order.append(node)
    for next_node in adj[node]:
        if next_node != parent[node]:
            parent[next_node] = node
            stack.append(next_node)

dp1 = [1] * N
for node in reversed(dfs_order):
    for next_node in adj[node]:
        if next_node != parent[node]:
            dp1[node] = max(dp1[node], dp1[next_node] + 1)

dp2 = [1] * N
for node in dfs_order:
    around = [dp1[next_node]+1 if next_node != parent[node] else dp2[node] for next_node in adj[node]]
    from_left = [1] + list(accumulate(around, max))[:-1]
    from_right = list(accumulate(reversed(around), max))[-2::-1] + [1]
    without = [max(l, r) + 1 for l, r in zip(from_left, from_right)]
    for next_node, value in zip(adj[node], without):
        if next_node != parent[node]:
            dp2[next_node] = value

dp = [v1 + v2 - 1 for v1, v2 in zip(dp1, dp2)]

length = max(dp)

if length % 3 == 2:
    print("Second")
else:
    print("First")

Measured memory_bytes: 69296
#include <cstdio>
#include <iostream>
#include <algorithm>
#define rep2(x,from,to) for(int x=(from);(x)<(to);(x)++)
#define rep(x,to) rep2(x,0,to)

using namespace std;

int main() {
	int a[3];
	rep(i,3) {
		cin >> a[i];
	}
	sort(a, a+3);
	rep(i,2) {
		cout << a[i] << " ";
	}
	cout << a[2] << endl;
	return 0;
}

Measured memory_bytes: 1176
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n
    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.parents[x] > self.parents[y]:
            x, y = y, x
        self.parents[x] += self.parents[y]
        self.parents[y] = x
    def size(self, x):
        return -self.parents[self.find(x)]
    def same(self, x, y):
        return self.find(x) == self.find(y)
    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]
    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]
    def group_count(self):
        return len(self.roots())
    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}
    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


N, M = map(int, input().split())
uf = UnionFind(N)
ans = 0
for i in range(M):
    A, B = map(int, input().split())
    uf.union(A-1,B-1)
print(uf.group_count()-1)

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

#define N 100
#define M 4950
#define INT(X) \
  ( *( (const int *)(X) ) )
#define MIN(A,B) \
  ( (A) < (B) ? (A) : (B) )
#define MAX(A,B) \
  ( (A) > (B) ? (A) : (B) )

int compare (
  const void  * a,
  const void  * b
  )
{
  return ( INT( a ) - INT( b ) );
}

/** Application main entry point. */
int main (
  int     argc,
  char  * argv[ ]
  )
{
  int i, j;

  for ( ; ; )
  {
    int r[ N ], res = 0;
    struct
    {
      int d;
      int a;
      int b;
    } d[ M ];
    int n, m;

    scanf ( " %d", &n );
    if ( !( n ) ) break ;

    scanf ( " %d", &m );
    for ( i = 0; i < n; ++i )
    {
      r[ i ] = i;
    }
    for ( i = 0; i < m; ++i )
    {
      scanf ( " %d,%d,%d", &d[ i ].a, &d[ i ].b, &d[ i ].d );
      d[ i ].d = ( d[ i ].d / 100 ) - 1;
    }
    qsort ( d, m, sizeof ( d[ 0 ] ), compare );

    for ( j = 0; j < m; ++j )
    {
      if ( r[ d[ j ].a ] != r[ d[ j ].b ] )
      {
        int t = MIN( r[ d[ j ].a ], r[ d[ j ].b ] );
        int u = MAX( r[ d[ j ].a ], r[ d[ j ].b ] );

        for ( i = 0; i < n; ++i )
        {
          if ( r[ i ] == u )
          {
            r[ i ] = t;
          }
        }

        res += d[ j ].d;
      }
    }

    printf ( "%d\n", res );
  }

  return ( 0 );
}

Measured memory_bytes: 0
is_prime = [False,False]

for i in range(2,1000000):
    is_prime.append(True)

for i in range(2,1000000):
    if is_prime[i]:
        for j in range(i*i,1000000,i):
            is_prime[j] = False


n_prime = [0,0]
cnt = int(0)

for i in range(2,1000000):
    if is_prime[i]:
        cnt += 1
    n_prime.append(cnt)

while True:
    try:
        n = int(input())
        print(n_prime[n])
        
    except:
        break

        




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

using namespace std;

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define MOD 1000000007
#define NUM 2520
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)

signed main(){

    lli a,b,c,d;
    cin>>a>>b>>c>>d;

    if(abs(a-c)<=d || ((abs(a-b)<=d) && (abs(b-c)<=d)))
    {
        cout<<"Yes"<<endl;
    }
    else cout<<"No"<<endl;

	return 0;
}

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

int main() {
	int a,b,k;cin >>a>>b>>k;
	for(int i=0;i<k/2;++i){
		if(a%2!=0)--a;
		a/=2;
		b += a;
		if(b%2!=0)--b;
		b/=2;
		a += b;
	}
	if(k%2!=0){
		if(a%2!=0)--a;
		a/=2;
		b += a;
	}
	cout << a << " " << b << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	Scanner sc;
	int w,h;
	int[][] map;
	int[][] route;
	
	void printMap(){
		for(int i=0;i<h+2;i++) {
			for(int j =0;j<w+2;j++) {
				System.out.print(route[i][j] + " ");
			}
			System.out.print(" ");
			for(int j =0;j<w+2;j++) {
				System.out.print(map[i][j] + " ");
			}
			System.out.println();
		}
		System.out.println();
	}
	
	void run() {
		sc = new Scanner(System.in);
		while (true) {
			w = sc.nextInt();
			h = sc.nextInt();
			if(w==0&&h==0) break;
			map = new int[h+2][w+2];
			route = new int[h+2][w+2];
			for(int i=0;i<h;i++) for(int j=0;j<w+2;j++) { map[i][j] = 1; route[i][j] = 0; }
			for(int i=h;i<h+2;i++)for(int j=0;j<w+2;j++) { map[i][j] = 0; route[i][j] = 0; }
			for(int i=0;i<h;i++) for(int j=1;j<w+1;j++) map[i][j] = sc.nextInt();
			for(int j=1;j<w+1;j++) if(map[0][j] != 1) route[0][j] = 1;
			for(int i=0;i<h-1;i++) for(int j=1;j<w+1;j++){
//				if(j==1)printMap();
				if(map[i][j] == 0){
					if(map[i+1][j-1] == 0) route[i+1][j-1] += route[i][j];
					if(map[i+1][j] != 1) route[i+1][ j ] += route[i][j];
					if(map[i+1][j+1] == 0) route[i+1][j+1] += route[i][j];
				}
				else if(map[i][j] == 2) {
					if(map[i+2][j] != 1) route[i+2][ j ] += route[i][j];
				}
			}
			int ans = 0;
			for(int i=h-1;i<h+1;i++) for(int j=1;j<w+1;j++) {
				ans += route[i][j];
			}
			System.out.println(ans);
		}
	}
	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 12000
import numpy as np
n, k = map(int, input().split())
a = np.array(sorted(list(map(int, input().split()))))
f = np.array(sorted(list(map(int, input().split())), reverse=True))

def check(x):
    cost = np.maximum(0, a-x//f).sum()
    return cost <= k

left = -1
right = 10 ** 12
while left+1 < right:
    mid = (left+right)//2
    if check(mid):
        right = mid
    else:
        left = mid
    
print(right)

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

#define ll long long 

int main() {
    ios::sync_with_stdio(0); 

    int n, m; cin >> n >> m;
    ll ans = 0; 
    ans += n * (n-1) / 2;
    ans += m * (m-1) / 2;
    cout << ans << endl;



    return 0; 
}



Measured memory_bytes: 3596
#pragma GCC target ("avx2")
#pragma GCC optimize ("unroll-loops")
#pragma GCC optimize ("O3")
#include "bits/stdc++.h"
#include <unordered_set>
#include <unordered_map>
#include <random>
using namespace std;
typedef long long ll;
const ll MOD = 1'000'000'007LL; /*998'244'353LL;*/
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int (i)=0; (i)<(n); (i)++)
const int dx[4]={ 1,0,-1,0 };
const int dy[4]={ 0,1,0,-1 };

ll K;

signed main(){
	cin >> K;
	cout << 50 << endl;
	rep(i, 50){
		if(i != 0) cout << " ";
		if(K%50 > i){
			cout << 100 + K/50 - K%50;
		}
		else{
			cout << 50 + K/50 - K%50 - 1;
		}
	}
	cout << endl;
}

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

using namespace std;
typedef pair<double, string> pds;

int main(){
	while(true){
		int n;
		cin >> n;
		if(n == 0){ break; }
		vector<string> name(n);
		vector<int> time(n), benefit(n);
		vector<pds> pairs(n);
		for(int i = 0; i < n; ++i){
			int p, a, b, c, d, e, f, s, m;
			cin >> name[i] >> p >> a >> b >> c >> d >> e >> f >> s >> m;
			time[i] = (a + b + c + (d + e) * m);
			benefit[i] = f * m * s - p;
			pairs[i] = pds(
				static_cast<double>(-benefit[i]) / time[i], name[i]);
		}
		sort(pairs.begin(), pairs.end());
		for(int i = 0; i < n; ++i){
			cout << pairs[i].second << endl;
		}
		cout << "#" << endl;
	}
	return 0;
}

Measured memory_bytes: 1220
#include <bits/stdc++.h>
#define int long long
using namespace std;
using PII = pair<int, int>;
const int INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

struct Edge {
    int to;
    int cost;
};

signed main() {
    int n, m;
    cin >> n >> m;
    vector<vector<Edge>> g(n);
    for (int i = 0; i < m; i++) {
        int l, r, c;
        cin >> l >> r >> c;
        g[l - 1].push_back(Edge{r - 1, c});
    }
    for (int i = 1; i < n; i++) {
        g[i].push_back(Edge{i - 1, 0});
    }

    priority_queue<PII, vector<PII>, greater<PII>> q;
    vector<int> d(n, INF);
    d[0] = 0;
    q.push({0, 0});
    while(!q.empty()) {
        PII p = q.top();
        q.pop();
        if (d[p.second] < p.first) continue;
        for (auto&& e : g[p.second]) {
            if (d[e.to] > d[p.second] + e.cost) {
                d[e.to] = d[p.second] + e.cost;
                q.push({d[e.to], e.to});
            }
        }
    }

    cout << (d[n - 1] == INF ? -1 : d[n - 1]) << "\n";
}

Measured memory_bytes: 9340
#include<bits/stdc++.h>
using namespace std;
int main () {
    ios_base::sync_with_stdio(false);
    string s;
    cin>>s;
    bool flag = false;
    for(int i=0;i<s.length();i++) {
        if(s[i] == '7') flag = true;
    }
    if(flag) {
        cout<<"Yes"<<"\n";
    }
    else {
        cout<<"No"<<"\n";
    }
    return 0;
}

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

#define ll long long
#define pb push_back
#define vi vector<int>
#define FOR(i, a, b) for(int i = a; i < b; i++)
#define sizeOf(A) (sizeof(A))/(sizeof(A[0]))
#define odd(x) ((x) % (2))

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

    int a, b, c;
    cin >> a >> b >> c;

    bool yes = false;
    FOR(i, 1, b) {
        if (a*i % b == c % b) {
            cout << "YES\n";
            yes = true;
            break;
        }
    }
    if (!yes) {cout << "NO\n";}


    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
const long long mod=1e9+7;
#define ll long long
using namespace std;
int lim=0;

/*ll power(ll n)
{
    if(n==0) return 0%mod;
    if(n==1) return 1%mod;
    return ((power(n-1)%mod) + (power(n-2)%mod ))%mod;
}
int main()
{
    ll n;cin>>n;
    cout<<power(n%mod)%mod;
}*/
ll pw(ll x,ll n)
{
    ll res=1;
    while(n)
    {
        if(n&1) res=res*x*1ll%mod;
        x=x*x*1ll%mod;
        n/=2;
    }return res;
}
int main()
{
    int i;double t=0,n;
    cin>>n;
    for(i=1;i<=n;i++) if(i%2==1) t++;
    double ans=t/n;
    cout<<ans<<endl;
}
// C++ program to find sum of two large numbers.
/*#include<bits/stdc++.h>
using namespace std;

// Function for finding sum of larger numbers
string findSum(string str1, string str2)
{
    // Before proceeding further, make sure length
    // of str2 is larger.
    if (str1.length() > str2.length())
        swap(str1, str2);

    // Take an empty string for storing result
    string str = "";

    // Calculate length of both string
    int n1 = str1.length(), n2 = str2.length();

    // Reverse both of strings
    reverse(str1.begin(), str1.end());
    reverse(str2.begin(), str2.end());

    int carry = 0;
    for (int i=0; i<n1; i++)
    {
        // Do school mathematics, compute sum of
        // current digits and carry
        int sum = ((str1[i]-'0')+(str2[i]-'0')+carry);
        str.push_back(sum%10 + '0');

        // Calculate carry for next step
        carry = sum/10;
    }

    // Add remaining digits of larger number
    for (int i=n1; i<n2; i++)
    {
        int sum = ((str2[i]-'0')+carry);
        str.push_back(sum%10 + '0');
        carry = sum/10;
    }

    // Add remaining carry
    if (carry)
        str.push_back(carry+'0');

    // reverse resultant string
    reverse(str.begin(), str.end());

    return str;
}

// Driver code
int main()
{
    string str1 ,str2 ;
    cin>>str1>>str2;
    cout << findSum(str1, str2);
    return 0;
}
*/
// CPP program to find (a^b) % MOD where a and
// b may be very large and represented as strings.




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long long n,k,h[100002],ok[100002];
int main (){
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
     cin>>n>>k;
     for(int i=1;i<n+1;i++)
         cin>>h[i];
         ok[1]=0;
         ok[2]=abs(h[2]-h[1]);
     for(int i=3;i<n+1;i++){
     	ok[i]=ok[i-1] + abs(h[i]-h[i-1]);
     	for(int j=2;j<k+1;j++){
     		if(j<i){
	             ok[i] = min(ok[i], ok[i-j] + abs(h[i]-h[i-j]));
	        }
        }
	}
	 cout<<ok[n];
return 0;
}

Measured memory_bytes: 1792
x=int(input())

if((x>=400)and(x<=599)):
  print(8)
elif((x>=600)and(x<=799)):
  print(7)
elif((x>=800)and(x<=999)):
  print(6)
elif((x>=1000)and(x<=1199)):
  print(5)
elif((x>=1200)and(x<=1399)):
  print(4)
elif((x>=1400)and(x<=1599)):
  print(3)
elif((x>=1600)and(x<=1799)):
  print(2)
elif((x>=1800)and(x<=1999)):
  print(1)

Measured memory_bytes: 9092
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 998244353;
const ll MAX = 1000001;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

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

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

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

struct edge {
	ll ind;
	ll fr;
	ll to;
	ll d;
};


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



int main() {
	
	ll N, A, B, C, D;
	cin >> N >> A >> B >> C >> D;
	string ans = "NO";

	rep(i, N + 1) {
		if (A + C * i - D * (N-1 - i) <= B && B <= A + D * i - C * (N-1 - i)) { ans = "YES"; }
	}

	cout << ans;


	system("PAUSE");
}


Measured memory_bytes: 504
import sys
import numpy as np
def input(): return sys.stdin.readline().rstrip()
def ii(): return int(input())
def mi(): return map(int, input().split())
def li(): return list(mi())


def main():
    n, k = mi()
    ans = 0
    for i in range(k+1, n+1):
        ans += (n//i)*(i-k)
        if k == 0:
            ans -= 1
        ans += max(n%i-k+1, 0)
    print(ans)



    
        
if __name__ == '__main__':
    main()

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

int main()
{
	int N;
	cin >> N;
	L[0] = 2;
	L[1] = 1;
	rep(i,N-1)
	{
		L[i+2] = L[i] + L[i+1];
	}
	cout << L[N] << endl;
	return 0;
}

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

using ll = long long;
using ld = long double;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define FORR(i, m, n) for (int i = (m); i >= (n); i--)
#define REP(i, n) FOR(i, 0, (n))
#define REPR(i, n) FORR(i, (n) - 1, 0)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define REPS(c, s) for (char c : s)
#define ALL(c) (c).begin(), (c).end()
#define sz(v) (int)v.size()
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
const int MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000001000000001LL;
const char EOL = '\n';

void solve();

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(numeric_limits<double>::max_digits10);
    solve();
    return 0;
}

void solve() {
    string s;
    string t;
    cin >> s >> t;
    cout << t << s << EOL;
}
 

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


int main(){
    ll x;   cin >> x;
    ll ans=1;
    for(int i=2;i<x;i++){
        ll  tmp=i;
        while(tmp*i<=x){
            tmp *= i;
            ans = max(ans, tmp);
        }
        
    }
    cout << ans << endl;
    
}

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

using namespace std; 

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
typedef long long LL;
typedef priority_queue<int> PQ_DESC;
typedef priority_queue<int, vector<int>, greater<int>> PQ_ASC;
typedef priority_queue<PII> PQ_DESC_PII;
typedef priority_queue<PII, vector<PII>, greater<PII>> PQ_ASC_PII;

#define ALL(c) (c).begin(),(c).end()
#define PB push_back
#define MP make_pair
#define SORT_ASC(c) sort(ALL(c))
#define SORT_DESC(c) sort(ALL(c), greater<typeof(*((c).begin()))>())
#define SIZE(a) int((a).size())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ROF(i,a,b) for(int i=(b-1);i>=(a);--i)
#define REP(i,n) FOR(i,0,n)
#define REP(i,n) FOR(i,0,n)
#define PER(i,n) ROF(i,0,n)

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int LARGE_INT = 1e9+100;
const int INF = 2e9+100;
const LL INF_LL = (LL)INF * 300 * 300;
const int MOD = 1e9+7;

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

LL modpow(LL a, LL n) {
    LL res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}

LL modinv(LL a) {
    LL b = MOD, u = 1, v = 0;
    while (b) {
        LL t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= MOD;
    if (u < 0) u += MOD;
    return u;
}

LL moddev(LL a, LL b){
	return a * modinv(b) % MOD;
}

void Main()
{
    int n;cin>>n;
    int r;cin>>r;

    if(n > 10){
        cout << r << endl;
    }
    else{
        cout << r + 100*(10-n) << endl;
    }

	return;
}

int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
    return 0;
}

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

void dfs(vector<unordered_set<int>> &friendship,
  unordered_set<int> &nets, int i, vector<int> &marked) {
  if (marked[i] == 1) {
    return;
  } else {
    nets.insert(i);
    marked[i] = 1;
    for (int next : friendship[i]) {
      dfs(friendship, nets, next, marked);
    }
  }
}


int main() {
  int N, M, K;
  cin >> N >> M >> K;
  vector<unordered_set<int>> friendship(N), blockship(N);
  for (int i = 0; i < M; i++) {
    int a, b;
    cin >> a >> b;
    friendship[a - 1].insert(b - 1);
    friendship[b - 1].insert(a - 1);
  }
  for (int i = 0; i < K; i++) {
    int a, b;
    cin >> a >> b;
    blockship[a - 1].insert(b - 1);
    blockship[b - 1].insert(a - 1);
  }
  vector<int> res(N, -1);
  vector<int> marked(N, 0);
  for (int i = 0; i < N; i++) {
    if (marked[i] != 0) continue;
    unordered_set<int> nets;
    dfs(friendship, nets, i, marked);
    int friends = nets.size();
    for (int j : nets) {
      res[j] = friends - friendship[j].size() - 1;
      for (int block : blockship[j]) {
        if (nets.find(block) != nets.end()) {
          res[j]--;
        }
      }
    }
  }
  for (int i = 0; i < N - 1; i++) {
    cout << res[i] << " ";
  }
  cout << res.back() << endl;
  return 0;
}

Measured memory_bytes: 37796
import sys
def input(): return sys.stdin.readline().rstrip()


def main():
    n, k = map(int, input().split())
    full = (n-1)*(n-2)//2
    if k > full:
        print(-1)
    else:
        num = full-k
        print(num+n-1)
        for i in range(2, n+1):
            print(1, i)
        for i in range(2, n):
            for j in range(i+1, n+1):
                if num == 0:
                    exit()
                print(i, j)
                num -= 1


if __name__ == '__main__':
    main()

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

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

    vector<int> a(n), b(n);
    rep(i,n) cin >> a[i];
    rep(i,n) cin >> b[n- 1 - i];

    int save = 0;
    vector<int> ch1, ch2;
    rep(i,n) if (a[i] == b[i]) { save = a[i]; ch1.push_back(i); }
    rep(i,n) if (a[i] != save && b[i] != save) ch2.push_back(i);
    
    if ((int)ch1.size() > (int)ch2.size()) {
        cout << "No" << endl;
    }
    else {
        cout << "Yes" << endl;
        rep(i,(int)ch1.size()) swap(b[ch1[i]], b[ch2[i]]);
        rep(i,n) cout << b[i] << " ";
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 6128
#include<bits/stdc++.h>
#define ll long long
#define MOD 1000000007
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL)
using namespace std;
int main(){
    speed;
    ll X,N,p,mini=10000,ans=10000;
    cin>>X>>N;
    unordered_map<ll,ll>exist;
    for(ll i=0;i<N;i++){
        cin>>p;
        exist[p]=1;
    }
    for(ll i=-200;i<=200;i++){
        if(mini>=abs(X-i) && exist[i]!=1){
            if(mini>abs(X-i)) ans=i,mini=abs(X-i);
            else if(mini==abs(X-i) && ans>i) ans=i;
        }
    }
    printf("%lld",(ans!=10000)?ans:X);
}


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

int main() {
  int N;
  cin >> N;
  vector<tuple<string, int, int>> data(N);
  rep(i, N) {
    string s;
    int p;
    cin >> s >> p;
    get<0>(data[i]) = s;
    get<1>(data[i]) = 100 - p;
    get<2>(data[i]) = i+1;
  }
  sort(data.begin(), data.end());
  rep(i, N) {
    cout << get<2>(data[i]) << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fo(i,a,b) for((i)=(a);i<=(b);i++)
#define rfo(i,a,b) for((i)=(a);i>=(b);i--)
#define inrange(x,y,z) (((x)>=(y))&&((x)<=(z)))
#define ALL(vec) ((vec).begin(),(vec).end())
#define SOR(vec) sort(ALL(vec))
#define UNI(vec) (vec).erase(unique(ALL(vec)),(vec).end())
using namespace std;
string s;
int k;
int main(){
	#ifdef FILIN
		#ifndef DavidDesktop
			freopen(FILIN,"r",stdin);
			freopen(FILOUT,"w",stdout);
		#endif
	#endif
	ios::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>k>>s;
	if(s.size()>k){
		for(int i=0;i<k;i++) cout<<s[i];
		cout<<"...";
		cout<<endl;
	}
	else
		cout<<s<<endl;
	return 0;
}


Measured memory_bytes: 3636
import sys
#import numpy as np
import math
#from fractions import Fraction
#import itertools
from collections import deque
#import heapq
from fractions  import gcd

#input=sys.stdin.readline
n=int(input())
dic={}
for i in range(n):
    s=input()
    if s not in dic:
        dic[s]=1
    else:
        dic[s]+=1
m=max(dic.values())
dic=sorted(dic.items(),key=lambda x: x[0])
for i in range(len(dic)):
    if dic[i][1]==m:
        print(dic[i][0])
   

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

#define REP(i, n) for(int (i) = 0; (i) < (n); ++(i))
#define REPR(i, n) for(int (i) = (n); (i) >= 0; --(i))
#define FOR(i, n, m) for(int (i) = (n); (i) < (m); ++(i))

// constexpr int INF = 1e9;
constexpr ll INF = 1LL<<61;
constexpr ll mod = 1e9+7;


int main(){
  int N;
  cin >> N;
  vector<pair<ll, ll>> xy(N);
  REP(i, N){
    ll x, y;
    cin >> x >> y;
    xy[i].first = x + y;
    xy[i].second = x-y;    
  }
  ll xmax = xy[0].first, xmin = xy[0].first, ymax = xy[0].second, ymin = xy[0].second;
  REP(i, N){
    xmax = max(xmax, xy[i].first);
    xmin = min(xmin, xy[i].first);
    ymax = max(ymax, xy[i].second);
    ymin = min(ymin, xy[i].second);
  }
  ll ans = max(abs(xmax-xmin), abs(ymax-ymin));
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 6332
def main():
    import bisect
    n = int(input())
    l = list(map(int, input().split()))
    l.sort()
    ans = 0
    # a < b < c とすると、2式は必ず成立し、c < a + b のみ考慮すれば良い
    # つまり　b < c < a + b
    # c < a + b の境界部の発見に2分探索を利用する
    for i in range(n - 1):
        for j in range(i + 1, n):
            k = bisect.bisect_left(l, l[i] + l[j])
            ans += k - (j + 1)
    print(ans)


if __name__ == '__main__':
    main()

Measured memory_bytes: 3316
#include <iostream>
#include <functional>
#include <vector>
using namespace std;

const long long MOD = 1000000007;

int main() {
    int n, k;
    cin >> n >> k;
    vector<int> graph[n + 1];
    for (int a, b; cin >> a >> b; graph[b].emplace_back(a)) {
        graph[a].emplace_back(b);
    }
    long long result = k;
    function<void(int, int, int)> dfs = [&](int node, int parent, int depth) {
        int used = 1;
        for (int i : graph[node]) {
            if (i != parent) {
                int next = k - used;
                if (depth > 0) {
                    next--;
                }
                result = result * max(next, 0) % MOD;
                dfs(i, node, depth + 1);
                used++;
            }
        }
    };
    dfs(1, -1, 0);
    cout << result;
    return 0;
}


Measured memory_bytes: 12800
#include "bits/stdc++.h"

#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,m,n) for(ll i=m;i<n;++i)
#define RFOR(i,m,n) for(ll i=n-1;i>=m;--i)
#define ALL(v) (v).begin(),(v).end()
#define PB(a) push_back(a)
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define DUMP(v) REP(i, (v).size()) { cout << v[i]; if (i != v.size() - 1)cout << " "; else cout << endl; }
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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


using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll max(ll a, int b) { return max(a, ll(b)); }
ll max(int a, ll b) { return max(ll(a), b); }
ll min(ll a, int b) { return min(a, ll(b)); }
ll min(int a, ll b) { return min(ll(a), b); }
///(?´????????`)(?´????????`)(?´????????`)(?´????????`)(?´????????`)(?´????????`)///
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s, t;
	cin >> s >> t;
	string tmp;
	REP(i, s.size()) {
		if (i % 2)tmp += s[i];
	}
	int k = 0;
	REP(j, t.size()) {
		if (k<tmp.size()&&t[j] == tmp[k]) {
			k++;
			
		}
	}
	if (k >= tmp.size()) {
		cout << "Yes" << endl;
		return 0;
	}
	tmp = "";
	REP(i, s.size()) {
		if (!(i % 2))tmp += s[i];
	}

	 k = 0;
	REP(j, t.size()) {
		if (k<tmp.size()&&t[j] == tmp[k]) {
			k++;
			
		}
	}
	if (k == tmp.size()) {
		cout << "Yes" << endl;
		return 0;
	}
	cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 3248