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

class UnionFind {
	vector<int> data;
	int root(int a) {
		return data[a] < 0 ? a : data[a] = root(data[a]);
	}
public:
	UnionFind(int n) : data(n, -1) {}
	bool Find(int a, int b) {
		return root(a) == root(b);
	}
	void Union(int a, int b) {
		a = root(a);
		b = root(b);
		if (a == b) return;
		if (data[a] < data[b]) {
			data[a] += data[b];
			data[b] = a;
		}
		else {
			data[b] += data[a];
			data[a] = b;
		}
	}
	int Size(int a) {
		return -data[root(a)];
	}
};

int main()
{
	UnionFind uf(13);
	uf.Union(1, 3);
	uf.Union(3, 5);
	uf.Union(5, 7);
	uf.Union(7, 8);
	uf.Union(8, 10);
	uf.Union(10, 12);
	uf.Union(4, 6);
	uf.Union(6, 9);
	uf.Union(9, 11);
	int x, y;
	cin >> x >> y;
	cout << (uf.Find(x, y) ? "Yes" : "No") << endl;
	return 0;
}


Measured memory_bytes: 256
def solve(n, k, ts, ds, dt):
    firsts = set()
    seconds = []

    dt.sort(reverse=True)

    count = 0
    t_sum = 0
    d_sum = 0
    score_max = 0
    for d, t in dt:

        if count == k:
            # かぶり一切なし
            if not seconds:
                break

            # 今までにいれたことある種類はパス
            if t in firsts:
                continue

            d_sum -= seconds[-1]
            seconds.pop()
            count -= 1

        if t not in firsts:
            firsts.add(t)
            t_sum += 1
        else:
            seconds.append(d)

        d_sum += d
        score = d_sum + (t_sum * t_sum)
        # print(d_sum, ',', t_sum, '=', score)

        if score_max < score:
            score_max = score

        count += 1

    return score_max


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

ts = [0] * n
ds = [0] * n
td = [(0, 0)] * n
for i in range(n):
    t, d = map(int, input().split())
    ts[i] = t
    ds[i] = d
    td[i] = (d, t)

print(solve(n, k, ts, ds, td))


Measured memory_bytes: 20792
#include <bits/stdc++.h>
#define LOCAL
using namespace std;
template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
out << "(" << a.first << "," << a.second << ")";
return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << ": " << arg1 << " |";
__f(comma + 1, args...);
}
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
#define int long long
using P = pair<int,int>;
//#########################################
const int INF = 1e18;
void chmin(int &a,int b){
    if( a > b) a = b;
}
signed main(){
    int n,k;cin >> n >> k;
    vector<int> a(n);
    rep(i,n)cin >> a[i];
    vector<int> dp(n+1,INF);
    dp[1] = 0;
    for(int i = 1;i <= n;i++){
        for(int j = i+1;j <= i+k;j++){
            if(j < n+1)chmin(dp[j],dp[i] + abs(a[j-1] - a[i-1]));
        }
    }
    cout << dp[n] << endl;

    return 0;
}

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

int main(){
    long long a,b,c;
    cin >> a >> b >> c;
    long long A = c - a - b;
    if(A > 0 && 4 * a * b < A * A){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    return 0;
}

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


int main(){
    int N;
    cin >> N;
    double v[N];
    for (int i = 0; i < N; i++)
    {
        cin >> v[i];
    }
    sort(v,v+N);
    double ans = v[0];
    for (int i = 1; i < N; i++)
    {
        ans = (ans + v[i]) / 2;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        int a = Integer.parseInt(sc.next());
        int b = Integer.parseInt(sc.next());
        sc.close();

        // 主処理
        int result = (int) Math.ceil((a + b) / 2.0);

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


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

using namespace std;
typedef long long ll;
typedef pair<ll, ll> p_ll;

#define rep(i, N) for (int i = 0; i < (int)N; i++)
const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;


int main() {
  int N; cin >> N;
  int a[N]; rep(i,N) cin >> a[i];
  string result = "No";
  map<ll, ll> num; rep(i,N) num[a[i]]++;
  if (num.size()==1&&num.begin()->first==0) result = "Yes";
  else if (N%3==0) {
    if (num.size()==2) {
       p_ll z = *(num.begin());
      if (z.first==0) {
        if (z.second==N/3||z.second==2*N/3) result = "Yes";
      }
    }
    else if (num.size()==3) {
      result = "Yes";
      ll xsum = 0;
      auto itr = num.begin();
      while (itr!=num.end()) {
        if (itr->second!=N/3) result = "No";
        xsum ^= itr->first;
        itr++;
      } 
      if (xsum) result = "No";
    }
  }
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 5376
<?php
//error_reporting(0);
//$N = (int)trim(fgets(STDIN));
$R = trim(fgets(STDIN));
//list($a,$b,$c) = array_map('intval',explode(" ",trim(fgets(STDIN))));
//$s = trim(fgets(STDIN));
//$a = array_map('intval',explode(" ",trim(fgets(STDIN))));


printf("%f\n",($R*2)*M_PI);


Measured memory_bytes: 16060
#include <iostream>
using namespace std;
int main() {
 int a, b, x;
 char op;
 while(1){
 cin >> a >> op >> b;
 switch(op){
  case '+':
    x = a+b;
    break;
  case '-':
    x = a-b;
    break;
  case '*':
    x = a*b;
    break;
  case '/':
    x = a/b;
    break;
  case '?':
    return 0;
  }
 cout << x << endl;
 }
    return 0;
  }

Measured memory_bytes: 3068
#include <bits/stdc++.h>
#include <array>
using namespace std;
using ULL = unsigned long long;
using UL = unsigned;
using LL = long long;
#define rep(i, n) for(UL i = 0; i < (n); i++)

struct Problem {

	void Solve() {
		UL a, b, c; cin >> a >> b >> c;
		UL ans = 0;
		UL buf = min(b, c); b -= buf; c -= buf; ans += buf * 2;
		buf = min(a, c); a -= buf; c -= buf; ans += buf;
		ans += b;
		if (c) ans += 1;
		cout << ans << endl;
	}


	Problem();
};
int main() {
	unique_ptr<Problem> p(new Problem());
	p->Solve();
	return 0;
}
Problem::Problem() {
	cout << fixed << setprecision(10);
}

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

#define bc __builtin_popcount

vector <int> construct(int n, int st, int en) {
	if (!n)
		return {0};
		
	int pos = -1;
	for (int i = 0; i < n; i++)
		if ((st ^ en) >> i & 1)
			pos = i;
	
	bool sw = false;
	if (st >> pos & 1) {
		swap(st, en);
		sw = true;
	}
	
	int st1 = 0, en1 = 0;
	int ptr = 0;
	for (int i = 0; i < n; i++)
		if (i != pos) {
			if (st >> i & 1)
				st1 |= 1 << ptr;
			if (en >> i & 1)
				en1 |= 1 << ptr;
			ptr++;
		}
	
	vector <int> lft = construct(n - 1, st1, bc(en) % 2);
	vector <int> rig = construct(n - 1, bc(en) % 2, en1);
	
	vector <int> res;
	for (auto it : lft) {
		int ptr = 0, curr = 0;
		for (int i = 0; i < n; i++)
			if (i != pos) {
				if (it >> ptr & 1)
					curr |= 1 << i;
				ptr++;
			}
		res.push_back(curr);
	}
	
	for (auto it : rig) {
		int ptr = 0, curr = 1 << pos;
		for (int i = 0; i < n; i++)
			if (i != pos) {
				if (it >> ptr & 1)
					curr |= 1 << i;
				ptr++;
			}
		res.push_back(curr);
	}
	
	if (sw) 
		reverse(res.begin(), res.end());
		
	return res;
}

int main() {
	int N, A, B;
	scanf("%d%d%d", &N, &A, &B);
	
	if (bc(A) % 2 == bc(B) % 2) {
		puts("NO");
		return 0;
	}
	
	vector <int> ans = construct(N, A, B);
	
	puts("YES");
	for (auto it : ans)
		printf("%d ", it);
	puts("");
	
	return 0;
}

Measured memory_bytes: 1628
#include <iostream>
#include <string>

using namespace std;

int main(void) {
	double a, b, double_ave;
	int int_ave, distance;
	cin >> a >> b ;
	double_ave = (a + b) / 2;
	int_ave = double_ave;

	distance = (double_ave - int_ave)*10;
	if (5 <= distance) {
		int_ave++;
	}
	cout << int_ave << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define show(x) cout << #x << " = " << (x) << endl;
#define show2(x,y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl;
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
const int mod = 1000000007;
const double EPS = 1e-9;
const int INF = 1<<30;
const ll INFLL = 1LL<<60;
//cout << fixed << setprecision(10);

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

int main () {
  int n;
  cin >> n;
  vi a(n);
  rep(i,n) cin >> a[i];
  
  deque<int> dq;
  rep(i,n) {
    if (i%2 == (n-1)%2) dq.push_front(a[i]);
    else dq.push_back(a[i]);
  }

  rep(i,dq.size()) printf("%d%c", dq[i], i==dq.size()-1?'\n':' ');
  return 0;
}

Measured memory_bytes: 3840
s=input()
end_flag=0

if ((s[0]!="A")or(s.count("C")!=1)):
  end_flag=1
elif (s[1]=="C")or(s[-1]=="C"):
  end_flag=1

if (s.count("B")!=0)or(s.count("D")!=0)or(s.count("E")!=0):
  end_flag=1
if (s.count("F")!=0)or(s.count("G")!=0)or(s.count("H")!=0):
  end_flag=1
if (s.count("I")!=0)or(s.count("J")!=0)or(s.count("K")!=0):
  end_flag=1
if (s.count("L")!=0)or(s.count("M")!=0)or(s.count("N")!=0):
  end_flag=1
if (s.count("O")!=0)or(s.count("P")!=0)or(s.count("Q")!=0):
  end_flag=1
if (s.count("R")!=0)or(s.count("S")!=0)or(s.count("T")!=0):
  end_flag=1
if (s.count("U")!=0)or(s.count("V")!=0)or(s.count("W")!=0):
  end_flag=1
if (s.count("X")!=0)or(s.count("Y")!=0)or(s.count("Z")!=0):
  end_flag=1

if end_flag==1:
    print("WA")
else:
    print("AC")



Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
static const int MAX=100000;
static const int INF=(1<<29);
vector<int> G[MAX];
list<int> out;
bool V[MAX]; int N,indeg[MAX];

void bfs(int s){
  queue<int> q;
  q.push(s); V[s]=true;
  while(!q.empty()){
    int u=q.front(); q.pop();
    out.push_back(u);
    for(int i=0;i<G[u].size();i++){
      int v=G[u][i];
      indeg[v]--;
      if(indeg[v]==0 && !V[v]){V[v]=true; q.push(v);}
    }
  }
}
void tsort(){
  for(int i=0;i<N;i++)indeg[i]=0;
  for(int u=0;u<N;u++){
    for(int i=0;i<G[u].size();i++){int v=G[u][i]; indeg[v]++;}
  }
  for(int u=0;u<N;u++){if(indeg[u]==0 && !V[u])bfs(u);}
  for(list<int>::iterator it=out.begin();it!=out.end();it++){cout << *it << endl;}
}

int main(){
  int s,t,M;
  cin >> N >> M;
  for(int i=0;i<N;i++)V[i]=false;
  for(int i=0;i<M;i++){
    cin >> s >> t;
    G[s].push_back(t);
  }
  tsort();
}


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

int main () {
    int N; cin >> N;
    vector<int> p(N);
    for (int i = 0; i < N; ++i) {
        cin >> p[i];
    }

    int max = *max_element(p.begin(), p.end());
    vector<int>::iterator maxIt = max_element(p.begin(), p.end());
    int maxIndex = distance(p.begin(), maxIt);

    ll sum = 0;
    for (int i = 0; i < N; ++i) {
        if (i == maxIndex) {
            sum += p[maxIndex] / 2;
        } else {
            sum += p[i];
        }
    }

    cout << sum << endl;
}



Measured memory_bytes: 256
//Sasayego! Sasayego! Shinzou wo Sasageyo!

#include <iostream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <ctime>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <numeric>
#include <bitset>
#include <ctime>
#define debug(x)  cerr << #x << " = " << x << endl
#define lid (id << 1)
#define rid (lid ^ 1)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair <ll, ll> pll;
typedef pair <int, int> pii;

const int maxN = 1e5 + 5;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;

int a[maxN], cnt[2];

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

int main(){
	time_t START = clock();
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int n; scanf("%d", &n);
	for (int i = 0; i < n; i++){
		scanf("%d", a + i);
		if (a[i] != 1)
			cnt[a[i] & 1]++;
	}
	for (int x = 0; ; x++){
		if ((cnt[0] & 1) == 1)
			return printf(x & 1 ? "Second\n" : "First\n"), 0;
		if (cnt[1] != 1)
			return printf(x & 1 ? "First\n" : "Second\n"), 0;
		int g = 0;
		for (int i = 0; i < n; i++){
			if (a[i] != 1 && (a[i] & 1))
				a[i]--;
			g = gcd(g, a[i]);
		}
		cnt[0] = cnt[1] = 0;
		for (int i = 0; i < n; i++){
			a[i] /= g;
			if (a[i] != 1)
				cnt[a[i] & 1]++;
		}
	}
	time_t FINISH = clock();
	cerr << "Execution time: " << (ld)(FINISH - START) / CLOCKS_PER_SEC * 1000.0 << " milliseconds.\n";
	return 0;
}
 


Measured memory_bytes: 4140
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,s,k,l,p,q,x;
    string a[10005];
    cin>>n;
    s=k=p=q=0;
    for(int i=0; i<n; i++)
    {
        cin>>a[i];
        l=a[i].length();
        for(int j=1; j<l; j++)
        {
            if(a[i][j]=='B'&&a[i][j-1]=='A')
                s++;
        }
        if(a[i][0]=='B'&&a[i][l-1]=='A')
            q++;
        else
        {
            if(a[i][0]=='B')
                k++;
            if(a[i][l-1]=='A')
                p++;
        }
    }
    if(k>=1&&p>=1)
        x=s+q+1+min(k-1,p-1);
    else
    {
        if(k+p>=1)
            x=s+q;
        else
        {
            if(q>0)
                x=s+q-1;
            else
                x=s;
        }

    }
    cout<<x;
    return 0;
}


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

#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, m, n) for(int (i) = (m); (i) < (n); (i)++)
#define RFOR(i, a, b) for (int (i) = (b) - 1; (i) >= (a); (i)--)

#define SORT(v, n) sort(v, v + n)
#define VSORT(v) sort(v.begin(), v.end())
#define REVERSE(v, n) reverse(v, v + n)
#define SIZE(v) (sizeof(v) / sizeof(v[0]))
#define ALLCOUNT(v, n, x) count(v, v + n, x)

#define PUT(x)  cout << #x << ": " << x << endl
#define ll long long

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

using namespace std;

int main(){
    string s; cin >> s;
    ll gc = count(s.begin(), s.end(), 'g'), pc = count(s.begin(), s.end(), 'p');
    ll ans = (gc - pc) / 2;
    cout << ans << endl;
}

Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <algorithm>

int main() {
    std::string w, t;
    int count = 0;
    std::cin >> w;
    std::transform(w.begin(), w.end(), w.begin(), ::tolower);
    while (std::cin >> t) {
        if (t == "END_OF_TEXT") break;
        else {
            std::transform(t.begin(), t.end(), t.begin(), ::tolower);
            if (t == w)
                ++count;
        }
    }
    std::cout << count << std::endl;
    
    return 0;
}


Measured memory_bytes: 3160
#include <stdio.h>

int lng(int x){
  int cnt=0;
  while(x>0){
    cnt++;
    x=x/10;
  }
  return cnt;
}

int main(void){
  int a, b, ans;
  int a_lng, b_lng;

  while((scanf("%d %d", &a, &b))!=EOF){
    a_lng=lng(a);
    b_lng=lng(b);

    if(0>a || b>1000000 || a_lng>200 || b_lng>200){
      printf("error\n");
      return 0;
    }

    ans=a+b;
    printf("%d\n",  lng(ans));
  }
  return 0;
}

Measured memory_bytes: 596
n, total = map(int, input().split())
# n, total = 2000, 20000000
min = n * 1000
max = n * 10000
if (total > max) or (total < min):
    print('-1 -1 -1')
else:
    min_man = (total - (5000 * n)) // 10000 if total - (5000 * n) > 0 else 0
    n -= min_man
    total -= min_man*10000
    min_sen = (total % 5000) // 1000
    total -= min_sen*1000
    n -= min_sen
    success = False
    if total == 0:
        print(str(min_man) + ' 0 ' + str(min_sen))
    else:
        for i in range(int(total // 10000)+1):
            if success:
                break
            ii = total - i*10000
            for j in range(int(ii // 5000)+1):
                jj = ii - j*5000
                k = jj//1000
                if i + j + k == n:
                    print(str(i+min_man) + ' ' + str(j) + ' ' + str(k+min_sen))
                    success = True
                    break

        if not success:
            print('-1 -1 -1')


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
int id[N], num[N];
bool cmp(int a, int b) {
	return num[a] < num[b];
}
int main() {
	int n; cin >> n;
	for (int i = 1; i <= n; i++) cin >> num[i], id[i] = i;
	sort(id + 1, id + n + 1, cmp);
	for (int i = 1; i <= n; i++) cout << id[i] << ' ';
}

Measured memory_bytes: 1536
#include <bits/stdc++.h>
#define CFS           \
    cin.tie(nullptr); \
    ios::sync_with_stdio(false);
#define CST(x) cout << fixed << setprecision(x);
using namespace std;
const int IINF = 1 << 30;
const long LINF = 1LL << 60;
const int MOD = (int)1e9 + 7;
#define MM " "
// const int MOD = 998244353;

int main()
{
    int x, y, z;
    cin >> x >> y >> z;
    cout << z << MM << x << MM << y << "\n";
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <cassert>
#include <cstdarg>
#include <sys/time.h>
#include <fstream>
//#include "cout.h"

using namespace std;

#define SZ(x) ((int)x.size())
#define MSET(x,a) memset(x, a, (int)sizeof(x))
#define PB push_back
#define VI vector < int >
#define PII pair < int, int >
#define 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 FIT(it,v) for (__typeof((v).begin()) it = (v).begin(); it != (v).end(); it++)
#define OUT(A) cout << #A << " = "<< (A) << endl
#define OUT2(A, B) cout << "(" << #A << ", " << #B << ") = (" << (A) << ", "<< (B) << ")" << endl
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }

#define present(c, e) ((c).find((e)) != (c).end())
#define cpresent(c, e) (find(ALL(c), (e)) != (c).end())

int n, a, b, c;
int l[10];

void init() {

}

void input() {
  cin >> n >> a >> b >> c;
  REP(i, n) cin >>l[i];
}

int go(int A, int B, int C, int m, int i) {
  if (i == n) {
    if (A == 0 || B == 0 || C == 0) {
      return 99999999;
    }
    else return abs(a-A) + abs(b-B) + abs(c-C) + m;
  }
  int res = 88888888;
  chmin(res, go(A+l[i], B, C, (A==0 ? m : m+10), i+1));
  chmin(res, go(A, B+l[i], C, (B==0 ? m : m+10), i+1));
  chmin(res, go(A, B, C+l[i], (C==0 ? m : m+10), i+1));
  chmin(res, go(A, B, C, m, i+1));
  return res;
}

void solve() {
  cout << go(0, 0, 0, 0, 0) << endl;
}

int main() {
	init();
	input();
	solve();
	return 0;
}


Measured memory_bytes: 256
function Main(input) {
    input = input.split(" ");
    var N = input[0];
    var A = input[1];
    var B = input[2];
    var c = N * A;
    if(c > B){
        console.log(B);
    }else{
        console.log(c)
    }
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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


def main():
  N = int(input())
  U = list(map(int, input().split()))
  L = list(map(int, input().split()))

  SU = [0]
  for u in U:
    SU.append(u + SU[-1])

  SL = [0]
  for l in L:
    SL.append(l + SL[-1])

  max_ = 0
  for i in range(N):
    max_ = max(max_, SU[i+1]+SL[N]-SL[i])
  print(max_)


if(__name__ == '__main__'):
  main()

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

int main() {
	long long n,a;

	bool check = true;
	
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a;
		if (a % 2 == 1) {
			check = false;
		}
	}

	if (check) {
		cout << "second" << endl;
	}
	else {
		cout << "first" << endl;
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <array>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>
#include <iomanip>

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

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;

using namespace std;

int main()
{
	int n;
	cin >> n;
	vector<int> a(n);
	for (auto& i : a)
		cin >> i;
	vector<int> b(n);
	for (auto& i : b)
		cin >> i;
		
	vector<vector<set<ll>>> s;
	for (auto i : a)
		s.push_back(vector<set<ll>>(i + 1));
	REP(i, n)
		if (a[i] >= b[i])
			s[i][b[i]].insert(0);
	
	FOR(i, 1, 51)
		REP(j, n)
			FOR(k, i, s[j].size())
				for (auto x : s[j][k % i])
					s[j][k].insert(x | (1ll << i));

	vector<set<ll>> cand;
	REP(i, n)
		cand.push_back(s[i][a[i]]);

	ll res = 0;
	while (cand.size())
	{
		ll cm = -1;
		auto de = cand.end();
		for (auto it = cand.begin(); it != cand.end(); ++it)
		{
			if (!it->size())
				continue;
			ll cur = 1ll << 60;
			for (auto x : *it)
				cur = min(cur, res | x);
			if (cur > cm)
			{
				cm = cur;
				de = it;
			}
		}
		if (cm == -1)
		{
			cout << -1 << endl;
			return 0;
		}
		res = cm;
		cand.erase(de);
	}

	cout << res << endl;

	return 0;
}


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

#define endl '\n'

int n, k;
string s;
long long dp[102][102][2];

long long solve(int i, int cnt, bool limiar){
    long long * ref = &dp[i][cnt][limiar];
    
    if (*ref != -1) return *ref;
    if (i == n){
        if (cnt == k) return *ref = 1;
        else return *ref = 0;
    }
    if (cnt > k) return *ref = 0;

    long long lim = (limiar ? s[i] - '0' : 9);

    if (limiar){
        if (lim == 0) *ref = solve(i+1, cnt, 1);
        else *ref = solve(i+1, cnt, 0) + (lim-1) * solve(i+1, cnt+1, 0) + solve(i+1, cnt+1, 1);
    } else{
        *ref = solve(i+1, cnt, 0) + 9LL * solve(i+1, cnt+1, 0);
    }
    //cout << "dp[" << i << "][" << _k << "][" << limiar << "] = " << ans << endl;
    return *ref;
}

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

    cin >> s >> k;
    n = s.size();
    memset(dp, -1, sizeof dp);
    cout << solve(0, 0, 1);
}

Measured memory_bytes: 384
#include <stdio.h>
int main ()

{
   int n,x1,x2,a,b,c,d,e,i,k,x;
   k=0;
   scanf("%d %d %d",&n,&x1,&x2);
   for(i=0;i<=n;i++)
   {
         a=i/10000;
         b=(i-a*10000)/1000;
         c=(i-a*10000-b*1000)/100;
         d=(i-a*10000-b*1000-c*100)/10;
         e=(i-a*10000-b*1000-c*100)-d*10;
         x=a+b+c+d+e;
         if(x>=x1 && x<=x2)
         {
          k=k+i;
         }

       }

       printf("%d",k);
       return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <sstream>
#include <unordered_map>
#include <vector>


#define INF 4000000000000000000LL
#define MOD 1000000007
#define ALL(x) std::begin(x), std::end(x)


int N, A[111111], a[111111], b[111111];

int doit(int x)
{
  memcpy(a, A, sizeof(int) * N);

  memset(b, 0, sizeof(b));

  int l = 0, r = N - 1, xl = x, xr = x;

  b[N - 1] = x + x;
  
  for ( ; l < r; l ++, r --) {
    xl = a[l] -= xl;
    xr = a[r] -= xr;

    b[l    ] = xl + xl;
    b[r - 1] = xr + xr;
  }

  assert(l == r);

  a[l] -= xl;
  a[r] -= xr;

  return a[l];
}


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

  std::cout << std::fixed << std::setprecision(6);
  std::cerr << std::fixed << std::setprecision(6);

  std::cin >> N;

  for (int i = 0; i < N; i ++)
    std::cin >> A[i];

  long long l = -1, u = std::min(A[0], A[N - 1]) + 1;

  while (u - l > 1) {
    long long m = (l + u) / 2;

    int x = doit(m);

    if (x == 0) {
      for (int i = 0; i < N; i ++)
        std::cout << b[(i - 1 + N) % N] << ' ';
      std::cout << std::endl;
      
      break;
    }
    
    (x < 0 ? l : u) = m;
  }

  return 0;
}


Measured memory_bytes: 2560
#include<bits/stdc++.h>
#include <map>
#include <set>
#include <cmath>
#include <queue>
#include <cstdio>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
using namespace std;
const int N=1e5+5;
#define ll long long
#define inf 0x3f3f3f3f
#define mem(x) memset(x,0,sizeof(x))
#define sca(x) scanf("%d",&x)
#define scall(x) scanf("%lld",&x)
#define eps 1e-6
ll num[10000006];
int main()
{
	int n;sca(n);
	mem(num);
    for(int i=1;i<=n;i++)
    {
    	for(int j=i;j<=n;j+=i)
    	num[j]++;
	}
	ll ans=0;
	for(int i=1;i<=n;i++)
	{
		ans+=num[i]*i;
	}
	printf("%lld\n",ans);
}


Measured memory_bytes: 81960
#include <iostream>
#include <string>
#include <cmath>
#include <vector>
#include <algorithm>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <cctype>

using namespace std;
// for loop
#define F(i, L, R) for(int i = L; i < R; i++)
#define FE(i, L, R) for(int i = L; i <= R; i++)
// for (reversed)
#define FR(i, L, R) for(int i = L; i > R; i--)
#define FRE(i, L, R) for(int i = L; i >= R; i--)

// data types
#define ul unsigned long
#define ll long long
#define ull unsigned long long
#define ui unsigned int
#define us unsigned shoft

// vectors
typedef vector<int> vi;
typedef vector<long> vl;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
#define ALL(c) (c).begin(),(c).end()
#define last(vec) vec.size()-1
#define lastEle(vec) vec[last(vec)]
#define pb push_back

// debug
#define DBG(vari) cerr<<#vari<<" = "<<(vari)<<endl;
#define printA(a, L, R) FE(i, L, R) cout << a[i] << (i==R?'\n':' ')
#define printAF(a, L) printA(a, 0, L-1)
#define printV(a) printA(a, 0, a.size()-1)

// utils
#define char2int(c) (c-'0')
#define bit(x, i) (x&(1<<i))
#define space ' '
#define PI 3.14159265358979323

int main() {
    vi data(26);
    char input;
    while((input = getchar()) != EOF){
        if(65 <= input && input <= 90){
            input = tolower(input);
        }
        if('a' <= input && input <= 'z'){
            data[input-'a'] ++;
        }
    }

    char target = 'a';
    F(i, 0, data.size()){
        cout << target << space << ":" << space << data[i] << endl;
        target ++;
    }
}



Measured memory_bytes: 3116
#include <iostream>
#include <vector>
#include <string>
#include <stdio.h>
#include<math.h>
#include<algorithm>
#include<limits.h>


using namespace std;


int gcd(int a, int b) {

	int tmp;
	int r;
	if (a < b) {
		tmp = a;
		a = b;
		b = tmp;
	}

	r = a % b;

	while (r != 0) {
		a = b;
		b = r;
		r = a % b;
	}

	return b;
}

int main()
{
	int n;
	vector<int> a;

	cin >> n;

	int wk;
	for (int i = 0; i < n; i++) {
		cin >> wk;
		a.push_back(wk);
	}

	int ans = a[0];

	for (int i = 1; i < n; i++) {
		ans = gcd(ans, a[i]);
	}

	cout << ans << endl;


	return 0;
}



Measured memory_bytes: 892
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define rep(i,n) for (int i=0;i<(int)(n);i++)
#define codefor int test;scanf("%d",&test);while(test--)
#define yn(ans) if(ans)printf("Yes\n");else printf("No\n")
#define YN(ans) if(ans)printf("YES\n");else printf("NO\n")
#define vector2d(type,name,h,...) vector<vector<type>>name(h,vector<type>(__VA_ARGS__))
#define umap unordered_map
#define uset unordered_set
using namespace std;
using ll = long long;
//入力系
void scan(int& a){scanf("%d",&a);}
void scan(long long& a){scanf("%lld",&a);}
template<class T> void scan(T& a){cin>>a;}
template<class T> void scan(vector<T>& vec){for(auto&& it:vec)scan(it);}
void in(){}
template <class Head, class... Tail> void in(Head& head, Tail&... tail){scan(head);in(tail...);}
//出力系
void print(const int& a){printf("%d",a);}
void print(const long long& a){printf("%lld",a);}
void print(const double& a){printf("%.15lf",a);}
template<class T> void print(const T& a){cout<<a;}
template<class T> void print(const vector<T>& vec){if(vec.empty())return;print(vec[0]);for(auto it=vec.begin();++it!= vec.end();){putchar(' ');print(*it);}}
void out(){putchar('\n');}
template<class T> void out(const T& t){print(t);putchar('\n');}
template <class Head, class... Tail> void out(const Head& head,const Tail&... tail){print(head);putchar(' ');out(tail...);}
//デバッグ系
template<class T> void dprint(const T& a){cerr<<a;}
template<class T> void dprint(const vector<T>& vec){if(vec.empty())return;cerr<<vec[0];for(auto it=vec.begin();++it!= vec.end();){cerr<<" "<<*it;}}
void debug(){cerr<<endl;}
template<class T> void debug(const T& t){dprint(t);cerr<<endl;}
template <class Head, class... Tail> void debug(const Head& head, const Tail&... tail){dprint(head);cerr<<" ";debug(tail...);}

int left(int i){
    return 2*i+1;
}

int right(int i){
    return 2*i+2;
}

void maxHeapify(vector<int> &vec,int i){
    int size=vec.size();
    int l= left(i);
    int r= right(i);
    int largest;
    //左の子，自分，右の子で最大のノードを選ぶ
    if(l<size&&vec[l]>vec[i])largest=l;
    else largest=i;
    if(r<size&&vec[r]>vec[largest])largest=r;
    //largestとiが異なる場合交換
    if(largest!=i){
        swap(vec[i],vec[largest]);
        maxHeapify(vec,largest);
    }
}

void buildMaxHeap(vector<int> &vec){
    //vec.size()/2は子を持つ最大の節点
    for(int i=vec.size()/2-1;i>=0;i--){
        maxHeapify(vec,i);
    }
}

int main(){
    int h;
    in(h);
    vector<int> vec(h);
    in(vec);
    printf(" ");
    buildMaxHeap(vec);
    out(vec);
}


Measured memory_bytes: 4636
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n, l, sum;
	cin>>n>>l;
	sum = 0;
	int res = 1e9;
	int t = 0;
	int ans = 0;
	for(int i = 1; i <= n; ++i)t += l + i - 1;
	for(int i = 1; i <= n; ++i){
		int sum = 0;
		for(int j = 1; j <= n; ++j){
			if(j != i){
				sum += l + j - 1;
			}
		}
		if(abs(t - sum) <= res){
			res = abs(t - sum);
			ans = sum;
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
    #include <ext/pb_ds/assoc_container.hpp>
    #include <ext/pb_ds/tree_policy.hpp>
    #include <ext/pb_ds/detail/standard_policies.hpp>
    using namespace std;
    using namespace __gnu_pbds;
    #define ll long long
    #define int long long
    #define pb push_back
    #define For(i,n) for(ll  i=0;i<n;i++)
    #define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) ;clock_t clk = clock();
    #define f(a,b,c) for(ll a=b;a<c;a++)
    #define mod 998244353
    #define ld long double
    #define read(t) ll t;cin>>t;
    #define all(x) x.begin(),x.end()
    #define fi first
    #define se second
    #define endl "\n"
    #define pii pair<ll,ll>
    #define what_is(x) cerr << #x << " is " << x << endl;
    #define time cerr << "Time (in ms): " << double(clock() - clk) * 1000.0 / CLOCKS_PER_SEC << '\n';
    const double pi=3.14159265358979323846264;
    typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
    typedef tree<long long,null_type,greater<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set1;

/**********************************************************************************************************************/

signed main()/*Check flow...question galat mat padhna */
{
    fast;   
    ld n;
    cin>>n;
    cout<<fixed<<setprecision(10)<<(n/3)*(n/3)*(n/3)<<endl;
}      

Measured memory_bytes: 256
n=int(input());p=eval('list(map(int,input().split())),'*n);x,y,h=[x for x in p if x[2]][0]
for I in range(10201):j,i=I//101,I%101;H=h+abs(x-j)+abs(y-i);print(*(j,i,H)*all(u==max(H-abs(s-j)-abs(t-i),0)for s,t,u in p))

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

int main() {
  int n;
  cin >> n;
  vector<int> v(n);
  for (int i = 1; i < n; i++) {
    int a;
    cin >> a;
    v.at(a - 1)++;
  }
  for (int i = 0; i < n; i++) {
    cout << v.at(i) << endl;
  }
}


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

Measured memory_bytes: 256
N,M = map(int,input().split())
if N==1 and M==1:
    print(1)
elif (N>=1 and M==2) or (N==2 and M>=1):
    print(0)
elif (N==1 and M>=3) or (N>=3 and M==1):
    print(max(N,M)-2)
elif N>=3 and M>=3:
    print((N-2)*(M-2))

Measured memory_bytes: 61792
#include <iostream>

#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = 1; i <= (n); i++)
using ll = long long;

using namespace std;



int main() {
    string s;
    cin >> s;
    rep(i,s.size()) {
        if(i%2==0 && s[i]=='L') {
            cout << "No" << endl;
            return 0;
        } else if(i%2 && s[i]=='R') {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;

    return 0;
}


Measured memory_bytes: 3636
(eval-when (:compile-toplevel :load-toplevel :execute)
  (defparameter OPT
    #+swank '(optimize (speed 3) (safety 2))
    #-swank '(optimize (speed 3) (safety 0) (debug 0)))
  #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))
                 (shadow :run)
                 (use-package :fiveam)))
#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)

;; BEGIN_INSERTED_CONTENTS
(defmacro define-int-types (&rest bits)
  `(progn
     ,@(mapcar (lambda (b) `(deftype ,(intern (format nil "UINT~A" b)) () '(unsigned-byte ,b))) bits)
     ,@(mapcar (lambda (b) `(deftype ,(intern (format nil "INT~A" b)) () '(signed-byte ,b))) bits)))
(define-int-types 2 4 7 8 15 16 31 32 62 63 64)

(defmacro println (obj &optional (stream '*standard-output*))
  `(let ((*read-default-float-format* 'double-float))
     (prog1 (princ ,obj ,stream) (terpri ,stream))))

(defconstant +mod+ 1000000007)

;; Hauptteil

(defun main ()
  (let* ((h (read))
         (w (read))
         (plan (make-array (list h w) :element-type 'bit)))
    (dotimes (i h)
      (let ((line (read-line)))
        (dotimes (j w)
          (setf (aref plan i j) (if (char= #\# (aref line j)) 1 0)))))
    (dotimes (i h)
      (dotimes (j w)
        (when (and (= 1 (aref plan i j))
                   (zerop (aref plan (max 0 (- i 1)) j))
                   (zerop (aref plan i (max 0 (- j 1))))
                   (zerop (aref plan (min (- h 1) (+ i 1)) j))
                   (zerop (aref plan i (min (- w 1) (+ j 1)))))
          (println "No")
          (return-from main))))
    (println "Yes")))

#-swank(main)


Measured memory_bytes: 17000
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define all(v) v.begin(),v.end()
#define P pair<int,int>
#define len(s) (int)s.size()
#define pb push_back

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;
}
constexpr int mod = 1e9+7;
constexpr int inf = 3e18;

int mod_pow(int x,int y,int m=mod){
	int res=1;
	while(y>0){
		if(y&1)(res*=x)%=m;
		(x*=x)%=m;
		y>>=1;
	}
	return res;
}
vector<int>perm,inv;
void init_perm(){
	int x=1e6+1;perm.resize(x);inv.resize(x);
	perm[0]=1;
	REP(i,x+1)perm[i]=perm[i-1]*i%mod;
	inv[x]=mod_pow(perm[x],mod-2);
	for(int i=x-1;i>=0;i--){
		inv[i]=inv[i+1]*(i+1)%mod;
	}
}
int nCk(int x,int y){
	if(x<y)return 0;
	return perm[x]*inv[x-y]%mod*inv[y]%mod;
}
int N,M,K;
int f(){
	int res=0;
	REP(i,M){
		res+=nCk(N*M-2,K-2)*N%mod*N%mod*(M-i)%mod*i%mod;
		res%=mod;
	}
	return res;
}
signed main(){
	init_perm();
	cin>>N>>M>>K;
	int ans=0;
	ans+=f();
	swap(N,M);
	ans+=f();
	cout<<ans%mod<<endl;
}


Measured memory_bytes: 15872
n = int(input())
a = list(map(int, input().split()))
a.sort()
l = a[n - 1]
c, d = 0, 0
for i in a:
    if i < l / 2:
        c = i
    else:
        d = i
        break
if (l / 2) - c <= d - (l / 2):
    r = c
else:
    r = d
print(l, r)

Measured memory_bytes: 14052
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <cmath>
#include <iomanip>

using namespace std;
using ll = long long;
using vi = vector<int>;

#define in(v) v; cin >> v;
void ins() {}
template<class T,class... Rest>void ins(T& v,Rest&... rest){cin>>v;ins(rest...);}

#define rep(i,n) for(int i=0,_i=(n);i<_i;++i)
#define rrep(i,n) for(long long i=(n);i>=0;--i)
#define all(f,c,...) (([&](decltype((c)) cccc) { return (f)(begin(cccc), end(cccc), ## __VA_ARGS__); })(c))

// ========== debug ==========
template<class T>ostream& operator<<(ostream& os,const vector<T>& vec){os<<"{";for(size_t i=0;i<vec.size();++i)os<<(i?", ":"")<<vec[i];os<<"}";return os;}
ostream& operator<<(ostream& os,const vector<char>&v){for(size_t i=0;i<v.size();++i)os<<v[i];return os;}
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>& rhs){os<<"("<<rhs.first<<", "<<rhs.second<<")";return os;}

#ifdef LOCAL
void debug() {cerr << "\n";}
template<class First> void debug(const First& first) {cerr<<first<<"\n";}
template<class First, class... Rest> void debug(const First& first, const Rest&... rest) {cerr<<first<<",";debug(rest...);}
void debug2() {cerr << "\n";}
template<class First> void debug2(const First& first) {cerr<<first<<" ";}
template<class First, class... Rest> void debug2(const First& first, const Rest&... rest) {cerr<<first<<" ";debug2(rest...);}
#else
#define debug(...) 42
#define debug2(...) 42
#endif
// ===========================

int main() {
  int N;
  ins(N);

  map<string, int> m;
  rep(i, N) {
    string s; cin >> s;
    ++m[s];
  }
  printf("AC x %d\n", m["AC"]);
  printf("WA x %d\n", m["WA"]);
  printf("TLE x %d\n", m["TLE"]);
  printf("RE x %d\n", m["RE"]);

  return 0;
}


Measured memory_bytes: 3724
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC098_A
{
    class Program
    {
        static void Main(string[] args)
        {
            var AB = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var A = AB[0];
            var B = AB[1];

            var check = A + B > A * B && A + B > A - B;
            Console.WriteLine(check ? A + B : (A * B > A - B ? A * B : A - B));
        }
    }
}


Measured memory_bytes: 13268
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
using ll = long long;
using P = pair<int,int>;
using PP = pair<int,pair<int,int>>;
using T = tuple<string,int,int>;
const ll INF = 1LL<<60;

int main(){
  int m,k; cin >> m >> k;
  int ul = pow(2,m);
  if(k >= ul){
    cout << -1 << endl;
  }else if(m == 0){
    if(k != 0) cout << -1 << endl;
    else cout << "0 0" << endl;
  }else if(m == 1){
    if(k != 0) cout << -1 << endl;
    else cout << "0 0 1 1" << endl;
  }else{
    vector<int> arr;
    for(int i = 0; i < ul; i++){
      if(i == k) continue;
      cout << i << " ";
      arr.push_back(i);
    }
    reverse(arr.begin(), arr.end());
    cout << k;
    for(int v: arr){
      cout << " " << v;
    }
    cout << " " << k << endl;
  }
  return 0;
}


Measured memory_bytes: 2424
import Control.Arrow
import Control.Monad
import Data.List
import qualified Data.ByteString.Char8 as B

main :: IO ()
main = readLine >>= print . solve

solve :: [Int] -> Int
solve [a, b] 
    | a > 12 = b 
    | a > 5 = b `div` 2 
    | otherwise = 0 

readLine :: IO [Int]
readLine = unfoldr (fmap (second (maybe B.empty snd . B.uncons)) . B.readInt) <$> B.getLine

readContents :: Int -> IO [[Int]]
readContents = flip replicateM readLine

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

int main()
{ 
  int n, p, flag = 0;

  cin >> n;
  for (int i = 0; i < n; i++)
  {
    cin >> p;
    if (i + 1 != p)
      flag++;
  }
  cout << (flag > 2 ? "NO" : "YES") << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;

//typedef
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

//conversion
inline LL toLong(string s) {LL v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) LL((a).size())
#define EACH(i,c) for(auto i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define UNTIL(p) while(!(p))

//constant
const double EPS = 1e-5;
const double PI  = acos(-1.0);

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

#define PUTS(x) cout << (x) << endl;

const LL MOD = 1e9 + 7;

vector<vector<LL>> link;

// first: white, second: black
PLL f(LL x, LL pre){
    LL w = 1;
    LL b = 1;
    for(LL y : link[x]){
        if(y == pre)continue;
        PLL p = f(y, x);
        LL k = (p.first + p.second) % MOD;
        w = (w * k) % MOD;
        b = (b * p.first) % MOD;
    }
    return MP(w, b);
}

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

    LL n;
    cin>>n;
    link.resize(n);
    REP(i,n-1){
        LL x,y;
        cin>>x>>y;
        x--;
        y--;
        link[x].PB(y);
        link[y].PB(x);
    }

    PLL ans = f(0, -1);
    PUTS((ans.first + ans.second)%MOD);
}

Measured memory_bytes: 12672
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
 
ll N, K;
vector<P> ab;
 
int main(void){
	
	scanf("%lld %lld", &N, &K);
	for(int i = 0; i < N; ++i){
	    ll a, b; scanf("%lld %lld", &a, &b);
	    ab.push_back(make_pair(a, b));
	}
	sort(ab.begin(), ab.end());

	ll sum = 0;
	for(int i = 0; i < N; ++i){
	    sum += ab[i].second;
	    if(sum >= K){ printf("%lld\n", ab[i].first); break; }
	}
	
    return 0;
}


Measured memory_bytes: 2420
import math
a, b = map(int, input().split())

beforeA = range(math.ceil(a * (100 / 8)), math.ceil((a+1) * (100 / 8)))
beforeB = range(b * 10, (b+1) * 10)
ans = 990990990
flag = False
for i in beforeA :
    for j in beforeB :
        #print(i, j)
        if i == j :
            flag = True
            ans = min(ans, i)
if flag :
    print(ans)
else :
    print(-1)


#print(beforeA, beforeB)


Measured memory_bytes: 3064
n,k=map(int,input().split())
a=[-1]+list(map(int,input().split()))
dp=[-1]*(n+1)
now=1
cnt=0
while True:
    nex=a[now]
    cnt+=1
    if dp[nex]!=-1:
        break
    dp[nex]=cnt
    now=nex

loop_start=nex
loop=[loop_start]
loop_now=loop_start
loop_next=-1
while loop_start!=loop_next:
    loop_next=a[loop_now]
    loop.append(loop_next)
    loop_now=loop_next
del loop[-1]
if dp[loop_start]>=k:
    print(dp.index(k))
else:
    d=k-dp[loop_start]
    print(loop[d%len(loop)])


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

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

    int flag = 0;
    int cnt = 0;

    for(int i = 0; i < n; i++){
        if(s.at(i) == 'R'){
            cnt++;
        }
    }


    int num_r = cnt;
    for(int i = 0; i < num_r; i++){
        if(s.at(i) == 'R'){
            cnt--;
        }
    }

    cout << cnt << endl;

}

Measured memory_bytes: 3664
N,M = map(int, input().split())
li = [list(map(int, input().split())) for i in range(M)]

mi = 0
ma = 10**9

for index, n in enumerate(li):
  if mi < n[0]:
    mi = n[0]

  if ma > n[1]:
    ma = n[1]

ans = N - (mi - 1) - (N - ma)

if mi > ma:
  print(0)
else:
  print(ans)

Measured memory_bytes: 27328
# -*- coding: utf-8 -*-
n = int(input())
x = list(map(int, input().split()))

result=100000000
p = 0

for i in range(1,101):
    tmp_r = 0
    for xj in x:
        tmp_r += (i-xj)*(i-xj)
    if tmp_r < result:
        result = tmp_r
        p = i

print(result)


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

#define ll long long
using namespace std;


void lcs(string a ,string b)
{

    int n = a.length();
    int m = b.length();
     

    int max_len = 0;
    

    vector<vector<int>>dp(n + 1 ,vector<int>(m+1 ,0));
    for(int i = 0 ;i <= n ; i++)
    {
        for(int j = 0 ; j<= m ;j++)
        {
            if(i == 0 || j == 0)
            {
                dp[i][j] = 0;
                continue;
            }
            
            if(a[i-1] == b[j-1])
            {
                dp[i][j] = 1+ dp[i-1][j-1];
            }
            else
            {
                dp[i][j] = max(dp[i-1][j] , dp[i][j-1]);
            }

            if(dp[i][j] > max_len)
            max_len = dp[i][j];
        }

    }

    //cout<<max_len<<endl;
    
    string s;
   int i = n, j =m;
    while(i > 0 && j > 0)
    {
        if(a[i-1] == b[j-1])
        {
            s = s + a[i-1];
            i--;
            j--;
        }
        else if(dp[i-1][j] > dp[i][j-1])
        {
            i--;
        }
        else
        {
            j--;
        }
    }
    reverse(s.begin() , s.end());
    cout<<s<<endl;
}
int main()
{
    string s,t;

    cin>>s>>t;

     lcs(s,t);
}

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

using namespace std;

int main(void){
  int a, b, c;
  cin >> a >> b >> c;
  cin.ignore();

  if(a + b >= c) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long long n,i,x;
vector<long long> a,p;
void com(long long x)
{
	if(a[n-1]==p[i])
	{
		cout<<a[n-2]<<endl;
	}
	else
	{
		cout<<a[n-1]<<endl;
	}
}
int main(){
	cin>>n;
	for(i=0;i<n;i++)
	{
		cin>>x;
		a.push_back(x);
		p.push_back(x);
	}
	sort(a.begin(),a.end());
	for(i=0;i<n;i++)
	{
		com(i);
	}
	return 0;
}

Measured memory_bytes: 4964
#include <iostream>
#include <algorithm>
typedef long long ll; 

using namespace std; 

int main() {
	int num, n, i, ans = 0, a = 0, b = 0, control = 1, original, bdin = 0, a1 = 0, b1 = 0;
	cin >> num >> n;
	original = num;
	int li[n];
	for(i = 0; i < n; i++) {
		cin >> li[i];
		if(li[i] == original) {
			bdin++;
		}
	}
	sort(li, li + n);
	while(true) {
		for(i = 0; i < n; i++) {
			if(bdin == 0) {
				ans = num;
				break;
			}
			a = num - control;
			b = num + control;
			for(int j = 0; j < n; j++) {
				if(li[j] == a) {
					a1++;
				}
				if(li[j] == b) {
					b1++;
				}
			}
			if(a1 == 0 && b1 > 0) {
				ans = a;
				break;
			}
			if(b1 == 0 && a1 > 0) {
				ans = b;
				break;
			}
			if(a1 == 0 && b1 == 0) {
				ans = min(a, b);
				break;
			}
			control++;
			a1 = 0;
			b1 = 0;
		}
		if(ans == num || ans == a || ans == b) {
			break;
		}
	}
	if(n == 0) {
		ans = num;
	}
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 3636