akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
using vec = vector<ll>;
using vect = vector<double>;
using Graph = vector<vector<ll>>;
#define loop(i, n) for (ll i = 0; i < n; i++)
#define Loop(i, m, n) for (ll i = m; i < n; i++)
#define pool(i, n) for (ll i = n; i >= 0; i--)
#define Pool(i, m, n) for (ll i = n; i >= m; i--)
#define mod 1000000007ll
//#define mod 998244353ll
#define flagcount __builtin_popcount
#define flag(x) (1ll << x)
#define flagadd(bit, x) bit |= flag(x)
#define flagpop(bit, x) bit &= ~flag(x)
#define flagon(bit, i) bit &flag(i)
#define flagoff(bit, i) !(bit & (1ll << i))
#define all(v) v.begin(), v.end()
#define low2way(v, x) lower_bound(all(v), x)
#define high2way(v, x) upper_bound(all(v), x)
#define idx_lower(v, x) (distance(v.begin(), low2way(v, x)))  //配列vでx未満の要素数を返す
#define idx_upper(v, x) (distance(v.begin(), high2way(v, x))) //配列vでx以下の要素数を返す
#define idx_lower2(v, x) (v.size() - idx_lower(v, x))         //配列vでx以上の要素数を返す
#define idx_upper2(v, x) (v.size() - idx_upper(v, x))         //配列vでxより大きい要素の数を返す
#define putout(a) cout << a << endl
#define Sum(v) accumulate(all(v), 0ll)
#define gcd(x, y) __gcd(x, y)
ll ctoi(char c)
{
    if (c >= '0' && c <= '9')
    {
        return c - '0';
    }
    return -1;
}
template <typename T>
T lcm(T x, T y)
{
    T z = gcd(x, y);
    return x * y / z;
}
template <typename T>
bool primejudge(T n)
{
    if (n < 2)
        return false;
    else if (n == 2)
        return true;
    else if (n % 2 == 0)
        return false;
    double sqrtn = sqrt(n);
    for (T i = 3; i < sqrtn + 1; i++)
    {
        if (n % i == 0)
        {
            return false;
        }
        i++;
    }
    return true;
}
template <typename T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b; // aをbで更新
        return true;
    }
    return false;
}
template <typename T>
bool chmin(T &a, const T &b)
{
    if (a > b)
    {
        a = b; // aをbで更新
        return true;
    }
    return false;
}
//場合によって使い分ける
//const ll dx[4]={1,0,-1,0};
//const ll dy[4]={0,1,0,-1};
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
//2次元配列の宣言
//vector<vector<ll>> field(h, vector<ll>(w));

int main()
{
    cout << fixed << setprecision(30);
    ll N;
    cin >> N;
    vector<ll> A(N);
    loop(i, N) cin >> A[i];
    ll ans = 0;
    loop(i, N - 1)
    {
        if (A[i] > A[i + 1])
        {
            ans -= (A[i + 1] - A[i]);
            A[i + 1] = A[i];
        }
    }
    putout(ans);
    return 0;
}


Measured memory_bytes: 4832
//
// Created by Danny Mittal on 6/13/20.
//

#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

int values[1 << 18];
int weights[1 << 18];
int depth[1 << 18];
int knapsack[512][100001];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    for (int a = 1; a <= n; a++) {
        cin >> values[a] >> weights[a];
    }
    depth[0] = -1;
    for (int j = 0; j <= 100000; j++) {
        knapsack[0][j] = 0;
    }
    for (int a = 1; a <= n; a++) {
        depth[a] = depth[a >> 1] + 1;
        if (depth[a] < 9) {
            for (int j = 0; j <= 100000; j++) {
                knapsack[a][j] = knapsack[a >> 1][j];
                if (j >= weights[a]) {
                    knapsack[a][j] = max(knapsack[a][j], knapsack[a >> 1][j - weights[a]] + values[a]);
                }
            }
        }
    }
    int q;
    cin >> q;
    for (; q; q--) {
        int a, limit;
        cin >> a >> limit;
        int b = a;
        while (depth[b] >= 9) {
            b >>= 1;
        }
        int res = knapsack[b][limit];
        if (a != b) {
            int d = depth[a] - depth[b];
            vector<int> dpW;
            vector<int> dpV;
            dpW.push_back(0);
            dpV.push_back(0);
            for (int mask = 1; mask < (1 << d); mask++) {
                int bit = mask & -mask;
                int w = dpW[mask ^ bit] + weights[a / bit];
                int v = dpV[mask ^ bit] + values[a / bit];
                dpW.push_back(w);
                dpV.push_back(v);
                if (w <= limit) {
                    res = max(res, knapsack[b][limit - w] + v);
                }
            }
        }
        cout << res << '\n';
    }
    cout << flush;
}

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

using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod =(1e9)+7;
using P = pair<ll,ll>;

int main(){
    ll ans=1;
    ll n;cin >>n;
    string s[2];
    cin >>s[0];
    cin >>s[1];
    ll c=0;//縦おｒ横
    for(int i=0;i<n;) {
       // cout <<ans<<endl;
        if(s[0][i]==s[1][i]){
           if(c==0){
               ans*=3;
               c=1;
           }
           else if(c==1){
               ans*=2;
               c=1;
           }
           else if(c==2){
               c=1;
           }
        }
        if(s[0][i]!=s[1][i]){
            if(c==0){
                ans*=6;
                c=2;
            }
            else if(c==1){
                ans*=2;
                c=2;
            }
            else if(c==2){
                ans*=3;
            }
        }
        ans%=mod;
        i+=c;
    }
    cout << ans <<endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
 
using namespace std;
int main()
{
	
	while(true)
	{
		int x;
		int y;
		cin>>x>>y;
		if (x == 0 && y == 0)
			break;
		else
		{
			if (x > y)
			{
				int temp = x;
				x = y;
				y = temp;
				cout<<x<<" "<<y<<endl;
			}
			else
			{
				cout<<x<<" "<<y<<endl;
			}
		}
	}
    return 0;
}

Measured memory_bytes: 3072
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>
#include <map>
#include <queue>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (a); i > (b); i--)
#define ALL(a) (a).begin(), (a).end()

int main() {
    int N;
    cin >> N;
    cout << N * N * N << endl;
    return 0;
}

Measured memory_bytes: 256
// -----------------------------------
// author   : MatsuTaku
// country  : Japan
// created  : 09/26/20 20:43:51
// -----------------------------------

#include <bits/stdc++.h>
#include <atcoder/all>

using namespace std;
using ll = long long;

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

  int n,m; cin>>n>>m;
  atcoder::dsu g(n);
  for (int i = 0; i < m; i++) {
    int a,b; cin>>a>>b; a--; b--;
    g.merge(a,b);
  }
  cout << g.groups().size()-1 << endl;

  return 0;
}


Measured memory_bytes: 9004
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.nextLine();
		String[] split = s.split(" ");
		int H = Integer.parseInt(split[0]);
		int W = Integer.parseInt(split[1]);
		s = sc.nextLine();
		split = s.split(" ");
		int h = Integer.parseInt(split[0]);
		int w = Integer.parseInt(split[1]);

		System.out.println((H - h) * (W - w));

		sc.close();
	}
}


Measured memory_bytes: 22740
using System;
using System.Linq;

public class Test
{
	public static void Main()
	{
		// my code goes here
		var a = Console.ReadLine().Split().Select(b => int.Parse(b)).ToArray();
		Console.WriteLine(a[2] + " " + a[0] + " " + a[1]);
		
	}
}

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

using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  string a, b, c;
  cin >> a >> b >> c;
  cout << (a.back() == b.front() && b.back() == c.front() ? "YES" : "NO") << '\n';
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define Rep(i,N) for(int i = 0;i < N;i++)
int main()
{
  int N;
  int data[105];
  int sum = 0;
  int M;
  int p,x;
  cin >> N;
  Rep(i,N){
    cin >> data[i];
    sum += data[i];
  }
  cin >> M;
  Rep(i,M){
    cin >> p >> x;
    p--;
    cout << sum + x - data[p] << endl;
  }
  return 0;
}


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

int main(void){
    
    string str;
    
    map<char, int> alpha_Count;
    for(char i = 'a'; i <= 'z'; i++){
        alpha_Count[i] = 0;
    }
    
    while(getline(cin, str)){
        
        // 各文字列を全て小文字に変換してmapに代入する
        for(int i = 0; i < str.size(); i++){
            if(isalpha(str[i])){
                if(isupper(str[i])){
                    char alphabet = tolower(str[i]);    
                    alpha_Count[alphabet]++;
                } 
                else{
                    alpha_Count[str[i]]++;
                }
            }
        }
    }
    
    for(char i = 'a'; i <= 'z'; i++){
        cout << i << " : " << alpha_Count[i] << endl;
    }

}



Measured memory_bytes: 3192
N,A,B=map(int,input().split())
S=str(input())
M=A+B
K=0
Foreign=0
for j in S:
  if j=="c":
    print("No")
  else:
    if j=="a":
      K+=1
      if K<=M:
        print("Yes")
      else:
        print("No")
    else:
      Foreign+=1
      if Foreign<=B:
        K+=1
        if K<=M:
          print("Yes")
        else:
          print("No")
      else:
        print("No")
   
    


Measured memory_bytes: 4016
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef tuple<int,int,int> tii;
#define rep(i,s,n) for(int i=(int)(s);i<(int)(n);i++)


int main(){
  ll A,B,N;
  cin >> A >> B >> N;
  ll x = min(B-1,N);
  ll ans = (A*x)/B - A*(x/B);
  cout << ans << endl;
}


Measured memory_bytes: 3600
leap = []
(4...3000).step(4) do |n|
  case
    when n % 400 == 0;
    when n % 100 == 0; next
    #when n % 4 != 0; next
  end
  leap << n
end

while gets
  a, b = $_.split.map(&:to_i)
  break if a == 0 && b == 0
  puts if $<.lineno > 1

  ret = [*a..b] & leap
  puts (ret.empty? ? "NA" : ret)
end

Measured memory_bytes: 6236
#include <cstdio>
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <set>

#define ll long long
#define pll pair<ll, ll>

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

const int INF = 1111111111;
const double EPS = 1e-9;

using namespace std;

const int N = 11111;
int ans[N];

void init()
{
}

void solve()
{
	int n;
	cin >> n;

	reps(i, 1, N)
	{
		reps(j, i, N)
		{
			reps(k, j, N)
			{
				ll x = i;
				ll y = j;
				ll z = k;

				ll now = x * x + y * y + z * z + x * y + y * z + z * x;

				if (now < N)
				{
					if (x == y && y == z)
					{
						ans[now]++;
						continue;
					}
					if (x == y || y == z || z == x)
					{
						ans[now] += 3;
						continue;
					}
					ans[now] += 6;
				}
				else
				{
					break;
				}
			}
		}
	}

	rep(i, n)
	{
		cout << ans[i + 1] << endl;
	}
}

int main()
{
	init();
	solve();
}


Measured memory_bytes: 3220
while True:
    mid,final,re = map(int,input().split())
    if mid==final==re==-1: break
    elif mid==-1 or final==-1:
        print("F")
    elif mid+final>=80:
        print("A")
    elif 65<= mid+final <80:
        print("B")
    elif 50<= mid+final <65:
        print("C")
    elif 30<= mid+final <50:
        if re>=50:
            print("C")
        else:
             print("D")
    elif mid+final <30:
        print("F")

Measured memory_bytes: 7636
#include <iostream>
#include <vector>
#include <set>
#include <queue>
#include <array>
#include <tuple>
#include <string>
#include <algorithm>
#include <functional> // greater など
#include <cmath>      // abs など
#include <numeric>    // accumulate など
#include <stdexcept>
#include <cassert> // assert
using namespace std;

#include <boost/multiprecision/cpp_int.hpp>
namespace mp = boost::multiprecision;

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;

// #define NDEBUG 1
// debug用出力 https://trap.jp/post/998/
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T)
{
  cerr << H << " ";
  debug_out(T...);
}
#ifdef NDEBUG
#define debug(...)
#else
#define debug(...) debug_out(__VA_ARGS__)
#endif

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

// constexpr inline ll MOD = 1'000'000'007;

mp::cpp_int a, res;
int x,y;

int main()
{
  // 入出力
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);

  char c;
  cin >> a >> x >> c >> y;
  res = a * (x * 100 + y) / 100;
  cout << res << endl;
  return 0;
}



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

const int MOD = 1000000007;

//long long
using ll = long long;

//出力系
#define print(x) cout << x << endl
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
 
// begin() end()
#define all(x) (x).begin(),(x).end()

//for
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)

//最大公約数 
unsigned gcd(unsigned a, unsigned b) {
  if(a < b) return gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

int main(){
string S;
cin >> S;
bool flag = true;
REP(i, S.size()){
    if(i % 2 == 0){
        if(S.at(i) == 'L') flag = false;
    }else if(i % 2 == 1){
        if(S.at(i) == 'R') flag = false;
    }
}

if(flag) yes;
else no;


}

Measured memory_bytes: 256
s = input()
n = len(s)
t = ('A','G','C','T')
ans = 0
flag = 0
for i in range(n):
	for j in range(i+1,n+1):
		#print(i,j,s[i:j])
		flag = 0
		for c in s[i:j]:
			if c not in t:
				flag = 1
				break
		if flag == 0:
			ans = max(ans,j-i)
print(ans)	


Measured memory_bytes: 3060
def xor_0_n(n):
    if n % 2 == 1 and (n//2) % 2 == 1:
        n = 0
    elif n % 2 == 1 and (n//2) % 2 == 0:
        n = 1
    elif n % 2 == 0 and (n//2) % 2 == 1:
        n ^= 1
    return n
  
a, b = map(int,input().split())

print(xor_0_n(a-1)^xor_0_n(b))


Measured memory_bytes: 61680
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include <boost/multiprecision/cpp_ll.hpp>
//typedef boost::multiprecision::cpp_ll ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E18;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
//#define endl "\n"
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);

ll mo=998244353;
int main(){fastio
    ll n;cin>>n;
    ll s;cin>>s;
    ll a[n];rep(i,0,n-1)cin>>a[i];
    ll dp[n+1][s+1];
    rep(i,0,n)rep(j,0,s)dp[i][j]=0;
    dp[0][0]=1;
    rep(i,0,n-1){
        rep(j,0,s){
            dp[i+1][j]=(dp[i+1][j]+dp[i][j]*2)%mo;
            if(j+a[i]<=s){
                dp[i+1][j+a[i]]=(dp[i+1][j+a[i]]+dp[i][j])%mo;
            }
        }
    }
    /*
    rep(i,0,n){
        rep(j,0,s){
            cout<<dp[i][j];
        }
        cout<<endl;
    }*/
    cout<<dp[n][s]%mo<<endl;
    
    return 0;
}





Measured memory_bytes: 74036
using System;
//using System.Collections;
//using System.Collections.Generic;
using System.Linq;

namespace problem
{
  class Test
  {
    static void Main()
    {
        var a = Console.ReadLine().Split().Select(int.Parse).ToArray();
        Console.WriteLine("{0} {1} {2}", a[0]/a[1], a[0]%a[1], (decimal)a[0]/a[1]);
    }
  }
}


Measured memory_bytes: 9680
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const ll dx[4] = { 0, -1, 1, 0 };
const ll dy[4] = { -1, 0, 0, 1 };
const int INF = 1e9 + 7;
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}
void mul(ll a, ll b) {
	a = a * b % INF;
}
///////////////////////////////////////
struct UnionFind {
	vector<int>par;

	UnionFind(int N) :par(N) {
		for (int i = 0; i < N; ++i) {
			par[i] = i;
		}
	}

	int root(int x) {
		if (par[x] == x)return x;
		return par[x] = root(par[x]);
	}

	void unite(int x, int y) {
		int rx = root(x);
		int ry = root(y);
		if (rx == ry)return;
		par[rx] = ry;
	}

	bool same(int x, int y) {
		int rx = root(x);
		int ry = root(y);
		return rx == ry;
	}
};
//.......クラスカル法......//

int main() {
	int N;
	cin >> N;
	vector<pair<ll,int>>x, y;
	for (int i = 0; i < N; ++i) {
		ll a, b;
		cin >> a >> b;
		x.push_back({ a,i });
		y.push_back({ b,i });
	}
	sort(x.begin(), x.end());
	sort(y.begin(), y.end());
	using edge = pair<ll, pii>;
	vector<edge>edges;
	for (int i = 0; i < N-1; ++i) {
		int v1 = x[i].second;
		int v2 = x[i + 1].second;
		ll cost = x[i + 1].first - x[i].first;
		edges.push_back(edge(cost,pii(v1,v2)));
	}
	for (int i = 0; i < N-1; ++i) {
		int v1 = y[i].second;
		int v2 = y[i + 1].second;
		ll cost = y[i + 1].first - y[i].first;
		edges.push_back(edge(cost,pii(v1,v2)));
	}
	sort(edges.begin(), edges.end());
	UnionFind uf(N);
	ll ans = 0;
	for (auto e : edges) {
		int u = e.second.first, v = e.second.second;
		ll cost = e.first;
		if (!uf.same(u,v)) {
			uf.unite(u,v);
			ans += cost;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 9444
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>

using namespace std;

int h,w,n;
char initField[51][51];
char field[51][51];
int cnt=0;
bool del[51][51];

bool search(){
	int sum=0;
	for(int i=0;i<h;i++)for(int j=0;j<w;j++)if(field[i][j]!='.')sum++;
	//cout<<"start"<<endl;
	while(sum){
		// º
		for(int j=0;j<w;j++){
			for(int i=h-2;i>=0;i--){
				if(field[i][j]!='.'){
					char ch=field[i][j];
					field[i][j]='.';
					for(int k=i;k<h;k++){
						if(k+1==h||field[k+1][j]!='.'){
							field[k][j]=ch;
							break;
						}
					}
				}
			}
		}
//		for(int i=0;i<h;i++){
//			for(int j=0;j<w;j++)cout<<field[i][j];
//			cout<<endl;
//		}
//		cout<<endl;
		memset(del,0,sizeof(del));
		int dec=0;
		for(int i=0;i<h;i++){
			for(int j=0;j<w;j++){
				if(field[i][j]=='.')continue;
				// tate
				int cnt=0;
				for(int k=i;k<h;k++){
					if(field[i][j]==field[k][j])cnt++;
					else break;
				}
				if(cnt>=n){
					for(int k=i;k<h;k++){
						if(field[i][j]==field[k][j])del[k][j]=true;
						else break;
					}
				}
				// yoko
				cnt=0;
				for(int k=j;k<w;k++){
					if(field[i][j]==field[i][k])cnt++;
					else break;
				}
				if(cnt>=n){
					for(int k=j;k<w;k++){
						if(field[i][j]==field[i][k])del[i][k]=true;
						else break;
					}
				}
			}
		}
		// í
		for(int i=0;i<h;i++)for(int j=0;j<w;j++)if(del[i][j])field[i][j]='.',dec++;

		if(dec==0)return false;
		sum-=dec;
	}
	return true;
}

int main(){

	cin>>h>>w>>n;
	bool ok=false;
	for(int i=0;i<h;i++)for(int j=0;j<w;j++)cin>>initField[i][j];
	for(int i=0;i<h;i++){
		for(int j=0;j<w-1;j++){
			for(int k=0;k<h;k++)for(int l=0;l<w;l++)field[k][l]=initField[k][l];
			cnt++;
			swap(field[i][j],field[i][j+1]);
			ok|=search();
			if(ok)break;
		}
		if(ok)break;
	}
	if(ok)cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
	return 0;
}

Measured memory_bytes: 0
#!/usr/bin/env python3
import sys

def check(k=10):
    li = {'0':("0","1"), "1":("0","1","2"), "2":("1","2","3"),"3":("2","3","4"),
    "4":("3","4","5"),"5":("4","5","6"),"6":("5","6","7"),"7":("6","7","8"),"8":("7","8","9"),"9":("8","9")}
    if k == 1:
        res = set(['1','2','3','4','5','6','7','8','9'])
    else:
        s = check(k-1)
        res = s.copy()
        for i in s:
            for j in li[i[-1]]:
                res.add(i+j)
    return res

def solve(K: int):
    k = K
    s = list(map(int, check()))
    s = sorted(s)
    print(s[k-1])



# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    K = int(input())  # type: int
    solve(K)

if __name__ == '__main__':
    main()


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

typedef long long LL;
typedef pair<int, int> PII;
typedef vector<int> VI;
#define MP make_pair
#define PB push_back
#define X first
#define Y second

#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define RFOR(i, b, a) for(int i = (b) - 1; i >= (a); --i)
#define ALL(a) a.begin(), a.end()
#define SZ(a) (int)((a).size())
#define FILL(a, value) memset(a, value, sizeof(a))
#define debug(a) cerr << #a << " = " << a << endl;

template<typename T> void setmax(T& x, T y) {x = max(x, y);}
template<typename T> void setmin(T& x, T y) {x = min(x, y);}

const double PI = acos(-1.0);
const LL INF = 1e9 + 47;
const LL LINF = INF * INF;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int N = 1 << 17;
int n;
vector<PII> g[N];
int color[N];

void dfs(int v, int c, int p = -1)
{
	color[v] = c;
	for(auto i: g[v]) if (i.X != p)
	{
		if (i.Y & 1) dfs(i.X, c ^ 1, v);
		else dfs(i.X, c, v);
	}
}

int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	
	cin >> n;
	FOR(i, 0, n - 1)
	{
		int u, v, w;
		cin >> u >> v >> w;
		g[u].PB({v, w});
		g[v].PB({u, w});
	}
	
	dfs(1, 0);
	FOR(i, 1, n + 1) cout << color[i] << endl;
	
	cerr << "Time elapsed: " << clock() / (double)CLOCKS_PER_SEC << endl;
	return 0;
}



Measured memory_bytes: 9856
#include        "algorithm"
#include        "iostream"
#include        "numeric"
#include        "iomanip"
#include        "cstring"
#include        "math.h"
#include        "bitset"
#include        "string"
#include        "vector"
#include        "random"
#include        "chrono"
#include        "ctime"
#include        "queue"
#include        "stack"
#include        "map"
#include        "set"

#include        "ext/pb_ds/assoc_container.hpp" // Common file
#include        "ext/pb_ds/tree_policy.hpp" // Including tree_order_statistics_node_update
#include        "ext/pb_ds/detail/standard_policies.hpp"

using namespace std;
using namespace __gnu_pbds;


#define          f first
#define          lgn 25
#define          endl '\n'
#define          sc second
#define          pb push_back
#define          N (int)2e5+5
#define          PI acos(-1.0)
#define          int long long 
#define          vi vector<int>
#define          mod 1000000007
#define          ld long double
#define          eb emplace_back
#define          mii map<int,int>
#define          vpii vector<pii>
#define          pii pair<int,int>
#define          pq priority_queue
#define          BLOCK (int)sqrt(N)
#define          test(x) while(x--)
#define          all(x) begin(x),end(x)
#define          allr(x) x.rbegin(),x.rend()
#define          fo(i,a,n) for(int i=a;i<n;i++)
#define          rfo(i,n,a) for(int i=n;i>=a;i--)
#define          FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define          time() cerr << "Time : " << (double)clock() / (double)CLOCKS_PER_SEC << "s\n"
#define 		 bug(...)       __f (#__VA_ARGS__, __VA_ARGS__)

typedef tree< int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update > 
OS ;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

template <typename Arg1>
void __f (const char* name, Arg1&& arg1) { cout << name << " : " << arg1 << endl; }
template <typename Arg1, typename... Args>
void __f (const char* names, Arg1&& arg1, Args&&... args)
{
     const char* comma = strchr (names + 1, ',');
     cout.write (names, comma - names) << " : " << arg1 << " | "; __f (comma + 1, args...);
}

const int inf = 0x3f3f3f3f;
const int INF = 0x3f3f3f3f3f3f3f3f;

int n,m,k,q;
string s;
vi adj[N];
int vis[N],par[N],a[N];

void go()
{
	cin >> k >> s;

	n = s.size();

	if( n > k )
	{
		string now = s.substr(0,k);
		cout << now + "..." << endl;
	}
	else
	{
		cout << s << endl;
	}
}

int32_t main()
{
	FAST;     
	int t=1; 
	// cin>>t;
	test(t) go();
}



Measured memory_bytes: 8352
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int (i)=0;(i)<(n);i++)
#define INF 1001001001
#define LLINF 1001001001001001001
#define MOD 1000000007
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define ALL(v) v.begin(), v.end()
typedef long long ll;

int main(){
    int a[3][3];
    for(int i=0;i<3;i++){
        for(int j=0;j<3;j++){
            cin >> a[i][j];
        }
    }

    int n;cin >> n;
    int b[n];
    rep(i,n)cin >> b[i];

    bool ans[3][3];
    rep(i,3)rep(j,3)ans[i][j]=false;

    for(int i=0;i<n;i++){
        for(int j=0;j<3;j++){
            for(int k=0;k<3;k++){
                if(a[j][k]==b[i])ans[j][k]=true;
            }
        }
    }

    if(ans[0][0] and ans[1][0] and ans[2][0])cout << "Yes" << endl;
    else if((ans[0][1] and ans[1][1] and ans[2][1]))cout << "Yes" << endl;
    else if((ans[0][2] and ans[1][2] and ans[2][2]))cout << "Yes" << endl;
    else if((ans[0][0] and ans[0][1] and ans[0][2]))cout << "Yes" << endl;
    else if((ans[1][0] and ans[1][1] and ans[1][2]))cout << "Yes" << endl;
    else if((ans[2][0] and ans[2][1] and ans[2][2]))cout << "Yes" << endl;
    else if((ans[0][0] and ans[1][1] and ans[2][2]))cout << "Yes" << endl;
    else if((ans[2][0] and ans[1][1] and ans[0][2]))cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}





Measured memory_bytes: 3632
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long ll;

int main(){
    ios::sync_with_stdio(false);
	int n;
	string s;
	cin>>n>>s;
	int a=count(s.begin(),s.end(),'R');
	int b=count(s.begin(),s.end(),'B');
	if(a>b) cout<<"Yes";
	else cout<<"No";
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
 
#define all(x) (x).begin() , (x).end();
#define rall(x) (x).rbegin() , (x).rend();
#define fi first
#define se second
#define pb push_back
 
 
 
void deb(){
    cerr<<endl;
}
template<typename T , typename... t>
void deb(T a , t...b){
    cerr<<a<<" ";
    deb(b...);
}
template<typename T>
void dev(vector<T>v){
    int c = 0;
    for(auto i : v){
        cerr<<i<<" ";
        c++;
    }
    cerr<<endl;
}
 
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    string s ; cin>>s;
    bool coffee = false;
    if(s[2] == s[3] && s[5]==s[4])coffee = true;
    cout<<(coffee?"Yes": "No")<<"\n";
    //int t; cin>>t;for(;t--;)done();
}

Measured memory_bytes: 256
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

void main()
{
    auto N = readln.chomp.to!int;
    auto AS = new int[](2^^N);
    foreach (i; 0..2^^N) {
        AS[i] = readln.chomp.to!int;
    }

    while (AS.length > 1) {
        int[] NAS;
        for (int i; i < AS.length; i += 2) {
            if (AS[i] == AS[i+1]) {
                NAS ~= AS[i];
            } else {
                NAS ~= abs(AS[i] - AS[i+1]);
            }
        }
        AS = NAS;
    }
    writeln(AS[0]);
}

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

if x <= 3:
  print(x)
  exit()

ans = 0
for i in range(2, int(x**0.5)+1):
  s = 0
  t = 1
  while i**t <= x:
    s = i**t
    t += 1
  ans = max(ans, s)
print(ans)

Measured memory_bytes: 9400
while 1:
	li=[]
	w = list(2**i for i in range(10))
	try: a = int(input())
	except: break
	for i in range(9,-1,-1):
		if w[i] <= a:
			a = a - w[i]
			li.append(w[i])
	li.reverse()
	for i in li: 
		if i == li[len(li)-1]:
			print(i)
		else:
			print(i, end=' ')


Measured memory_bytes: 5604
using System;
using System.Linq;

public class Hello
{
    public static void Main()
    {
        var K = int.Parse(Console.ReadLine().Trim());
        var S = Console.ReadLine().Trim();

        var ans  = S.Length <= K ? S : S.Substring(0, K) + "...";
        Console.WriteLine(ans);
   }
}

Measured memory_bytes: 27528
package main

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

func main() {
	a := getInt()
	if a == 1 {
		a = 14
	}
	b := getInt()
	if b == 1 {
		b = 14
	}

	ans := "Draw"
	if a > b {
		ans = "Alice"
	} else if a < b {
		ans = "Bob"
	}

	fmt.Println(ans)
}

// -----------------------------------------

var scanner = wordScanner()

func wordScanner() *bufio.Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	return sc
}

func getInt() int {
	scanner.Scan()
	i, err := strconv.Atoi(scanner.Text())
	if err != nil {
		panic(err)
	}
	return i
}

func getString() string {
	scanner.Scan()
	s := scanner.Text()
	return s
}


Measured memory_bytes: 640
#include <bits/stdc++.h> //Stack size ~2'000'000(x4)
#define pb push_back
#define mp make_pair
#define ll long long
#define ull unsigned long long
#define all(a) begin(a),end(a)
#define FOR(x,val,to) for(int x=(val);x<int((to));++x)
#define FORE(x,val,to) for(auto x=(val);x<=(to);++x)
#define FORR(x,arr) for(auto &x: arr)
#define FORS(x,plus,arr) for(auto x = begin(arr)+(plus); x != end(arr); ++x)
#define FORREV(x,plus,arr) for(auto x = rbegin(arr)+(plus); x != rend(arr); ++x)
#define PRINT(arr) {copy(begin((arr)), end((arr)), ostream_iterator<int>(cout, " "));cout<<'\n';}
#define REE(s_) {cout<<s_<<'\n';exit(0);} //print s_ and terminate program
#define CONT(s_) {cout<<s_<<'\n';continue;} //print s_ and continue;
#define GETCIN(arr) for(auto &i: (arr)) cin>>i
#define GET(arr) for(auto &i: (arr)) sc(i)
#define GETSTR(arr) for(auto &i: (arr)) getstr(i)
#define INF 2139062143 //127 in memset -> memset(arr,127,size)
#define SINF 1061109567 //Safe INF, for graphs or 2d arrays 63 in memset(arr,63,size)
#define LL_INF 7234017283807667300 //100 in memset(arr,100,size) !!!must be LL
#define whatis(x) cerr << #x << " is " << x << endl;
#define e1 first
#define e2 second
typedef std::pair<int,int> pi;
typedef std::vector<int> vi;
typedef std::vector<std::string> vs;
#define umap unordered_map
#define uset unordered_set
using namespace std;

#ifdef _WIN32
#define getchar_unlocked() _getchar_nolock()
#define _CRT_DISABLE_PERFCRIT_LOCKS
#endif
template<class T> ostream& operator<<(ostream &os, vector<T> V) { os<<"[";for(auto const &vv:V)os<<vv<<","; os<<"]"; return os; }//prnt vec
template<class L, class R> ostream& operator<<(ostream &os, pair<L, R> P) { os<<"("<<P.first<<","<<P.second<<")"; return os; }//prnt pair
template<typename T> inline void print_128(T num){ if(!num) return; print_128(num / 10); cout.put((num % 10) + '0'); }
inline int fstoi(const string &str){auto it=str.begin();bool neg=0;int num=0;if(*it=='-')neg=1;else num=*it-'0';++it;while(it<str.end()) num=num*10+(*it++-'0');if(neg)num*=-1;return num;}
inline void getch(char &x){while(x = getchar_unlocked(), x < 33){;}}
inline void getstr(string &str){str.clear(); char cur;while(cur=getchar_unlocked(),cur<33){;}while(cur>32){str+=cur;cur=getchar_unlocked();}}template<typename ...Args> inline void getstr(string &str, Args &...arg){str.clear();char cur;while(cur=getchar_unlocked(),cur<33){;}while(cur>32){str+=cur;cur=getchar_unlocked();}getstr(arg...);}
template<typename T> inline bool sc(T &num){ bool neg=0; int c; num=0; while(c=getchar_unlocked(),c<33){if(c == EOF) return false;} if(c=='-'){ neg=1; c=getchar_unlocked(); } for(;c>47;c=getchar_unlocked()) num=num*10+c-48; if(neg) num*=-1; return true;}template<typename T, typename ...Args> inline void sc(T &num, Args &...args){ bool neg=0; int c; num=0; while(c=getchar_unlocked(),c<33){;} if(c=='-'){ neg=1; c=getchar_unlocked(); } for(;c>47;c=getchar_unlocked()) num=num*10+c-48; if(neg) num*=-1; sc(args...); }

int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);
    string s;
    cin >> s;
    cout << s.front() << s.size()-2 << s.back();
}



Measured memory_bytes: 256
<?php
	$output = array();
	while( true ) {
		list( $a, $op, $b ) = explode( ' ', trim( fgets( STDIN ) ) );
		if( '?' == $op ) { break; }
		
		$res = 0;
		switch( $op ) {
			case '+':
				$res = $a+$b;
				break;
			case '-':
				$res = $a-$b;
				break;
			case '*':
				$res = $a*$b;
				break;				
			case '/':
				$res = floor( $a/$b );
				break;
		}
		array_push( $output, $res );
	}
	print implode( "\n", $output );
?>

Measured memory_bytes: 6604
#include<stdio.h>
int main(void){

    int train[10000],i=0,j,latte[10000],x,k;

    while(scanf("%d",&x)!=EOF){
        train[i]=x;
        i++;
    }

    for(j=0;j<=i;j++){
        if(train[j]==0){
            for(k=j-1;k>=0;k--){
                if(train[k]!=0){
                    printf("%d\n",train[k]);
                    train[k]=0;
                    break;

                }
            }
        }
    }





    return 0;
}

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

vector<int> to[100005];

int main(){
    int n, m;
    cin >> n >> m;
    rep(i,m){
        int a,b;
        cin >> a >> b;
        a--;b--;
        to[a].push_back(b);
        to[b].push_back(a);
    }
    
    queue<int> q;
    vector<int> dist(n,inf);
    vector<int> pre(n,-1);
    dist.at(0) = 0;
    q.push(0);
        while(!q.empty()){
            int v = q.front();q.pop();
            for(int u : to[v]){
                if(dist.at(u) != inf) continue;
                dist.at(u) = dist.at(v)+1;
                pre.at(u) = v;
                q.push(u);
            }
        }
        cout << "Yes" << endl;
        rep(i,n){
            if(i==0) continue;
            int ans = pre.at(i);
            ans++;
            cout << ans << endl;
        }
}


Measured memory_bytes: 10616
// 2013/11/09 Tazoe

#include <iostream>
using namespace std;

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

	int DP[100][3];
	for(int i=0; i<N; i++){
		for(int j=0; j<3; j++){
			DP[i][j] = 0;
		}
	}

	for(int i=0; i<K; i++){
		int A, B;
		cin >> A >> B;

		if(B==1){
			DP[A-1][1] = DP[A-1][2] = -1;
		}
		else if(B==2){
			DP[A-1][0] = DP[A-1][2] = -1;
		}
		else if(B==3){
			DP[A-1][0] = DP[A-1][1] = -1;
		}
	}

	for(int j=0; j<3; j++){
		if(DP[0][j]==-1)
			continue;

		DP[0][j] = 1;
	}

	for(int j=0; j<3; j++){
		if(DP[1][j]==-1)
			continue;

		int s = 0;
		for(int k=0; k<3; k++){
			if(DP[0][k]==-1)
				continue;

			s += DP[0][k];
		}

		DP[1][j] = s;
	}

	for(int i=2; i<N; i++){
		for(int j=0; j<3; j++){
			if(DP[i][j]==-1)
				continue;

			int s = 0;
			for(int k=0; k<3; k++){
				if(DP[i-1][k]==-1)
					continue;

				s += DP[i-1][k];
			}

			DP[i][j] = s%10000;

			if(DP[i-1][j]!=-1){
				int t = 0;
				for(int k=0; k<3; k++){
					if(DP[i-2][k]==-1)
						continue;

					if(j==k)
						continue;

					t += DP[i-2][k];
				}

				DP[i][j] = (DP[i][j]-(DP[i-1][j]-t+20000)+30000)%10000;
			}
		}
	}
/*
	for(int i=0; i<N; i++){
		for(int j=0; j<3; j++){
			cout << DP[i][j] << ' ';
		}
		cout << endl;
	}
*/

	int s = 0;
	for(int j=0; j<3; j++){
		if(DP[N-1][j]==-1)
			continue;

		s += DP[N-1][j];
	}

	cout << s%10000 << endl;

	return 0;
}

Measured memory_bytes: 1160
#include<iostream>
using namespace std;
int main(){
int a,b,c,d,p,x,y;
cin>>a>>b>>c>>d>>p;
x=p*a;
if(p<=c){
y=b;
}else{
y=b+((p-c)*d);
}
if(x<=y)cout<<x<<endl;else cout<<y<<endl;
return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <iomanip>
#include <cstdio>
#include <set>
#include <map>
#include <list>
#include <cstdlib>

using namespace std;

#define mod (1e9 + 7)
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(x) x.begin(), x.end()

typedef long long ll;

void solve1()
{
    int n; cin >> n;
    vector<int> a(n);
    rep(i, n) {
        cin >> a[i];
    }

    sort(all(a));

    int nn = a[n-1];

    double hl = nn/2.0;

    int r = a[0];
    int diff = abs(hl - a[0]);
    for(int i= 1;i < n; i++) {
    
        if(diff > abs(hl - a[i])) {
            r = a[i];
            diff = abs(hl - a[i]);
        }
     }

    cout << nn << " " << r << endl;


}

int main()
{
    solve1();
}

Measured memory_bytes: 3744
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <cstdio>
#include <ctime>
#include <assert.h>
#include <chrono>
#include <random>
#include <numeric>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
using namespace std;
typedef long long int ll;
typedef unsigned long long ull;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) {
	return (ull)rng() % B;
}

vector<int> g[10010];

int res[101][101];

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    for(int i=0;i<2*n*n-2*n;i++){
        int a,b; cin >> a >> b;
        a--; b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    for(int i=0;i<2*n*n-2*n;i++){
        if(g[i].size()==2){
            res[0][0]=i;
            res[0][1]=g[i][0];
            res[1][0]=g[i][1];
            break;
        }
    }
    for(int i=2;i<n;i++){
        int pp=res[0][i-2];
        int p=res[0][i-1];
        for(int t:g[p]){
            if(g[t].size()<=3&&t!=pp){
                res[0][i]=t;
            }
        }
    }
    for(int i=2;i<n;i++){
        int pp=res[i-2][0];
        int p=res[i-1][0];
        for(int t:g[p]){
            if(g[t].size()<=3&&pp!=t){
                res[i][0]=t;
            }
        }
    }
    for(int i=1;i<n;i++){
        for(int j=1;j<n;j++){
            int r=res[i-1][j-1];
            for(int s:g[res[i-1][j]]){
                for(int t:g[res[i][j-1]]){
                    if(s==t&&s!=r){
                        res[i][j]=s;
                    }
                }
            }
        }
    }
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            if(j)printf(" ");
            printf("%d",res[i][j]+1);
        }
        printf("\n");
    }
}



Measured memory_bytes: 3840
n = int(input())
l = list(map(int,input().split()))

def gcd(x,y):
    if x<y:
        x,y=y,x
    #x>y
    if y==0:
        return x
    if x%y==0:
        return y
    else:
        return gcd(y,x%y)
      
x = l[0]
for i in range(1,n):
  x = gcd(x,l[i])
  
print(x)

Measured memory_bytes: 14252
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define INF 1000000000000 //10^12

int main(){
    double l;
    cin >>l;
    double ans =l/3.0*l/3.0*l/3.0;
    printf("%.10f",ans);
}

Measured memory_bytes: 256
import Control.Applicative
import Control.Monad
import Control.Monad.ST
-- import qualified Data.ByteString as BS
import Data.Functor
import Data.Function
import Data.Monoid
import Data.Maybe
import Data.List
import qualified Data.Foldable as Foldable
--import qualified Data.Set as Set
--import qualified Data.Sequence as Sequence
import Data.List.Split
import Data.Bits
import Data.Char
import Data.Ix
import Data.Ratio
import Data.Ord
import Data.Fixed
import Data.Tuple
import Data.Array
--import Data.Array.Unboxed
--import Data.Array.IArray
import Data.Array.MArray
import Data.Array.IO
import Data.Array.ST
import Data.IORef
import Data.STRef
import Text.Printf
import System.IO
-- import System.IO.Unsafe
 
-- templete
readInt = read :: String -> Int
readInteger = read :: String -> Integer
readDouble = read :: String -> Double
getInt = readLn :: IO Int
getInts = map readInt . words <$> getLine
getInteger = readLn :: IO Integer
getIntegers = map readInteger . words <$> getLine
getDouble = readLn :: IO Double
getDoubles = map readDouble . words <$> getLine
sjoin :: (Show a) => [a] -> String
sjoin = unwords . map show
tjoin :: (Show a, Show b) => (a, b) -> String
tjoin (x, y) = show x ++ (' ' : show y)
cond :: a -> a -> Bool -> a
cond t f c = if c then t else f
apply2 :: (a -> a -> b) -> [a] -> b
apply2 f [x,y] = f x y
apply3 :: (a -> a -> a -> b) -> [a] -> b
apply3 f [x,y,z] = f x y z
apply4 :: (a -> a -> a -> a -> b) -> [a] -> b
apply4 f [x,y,z,w] = f x y z w
fnTuple :: (a -> b, a -> c) -> a -> (b, c)
fnTuple (f,g) a = (f a, g a)
replace :: (Eq a) => a -> a -> [a] -> [a]
replace x y = map (\z -> if z==x then y else z)
binMap :: (a -> a -> b) -> [a] -> [b]
binMap f (x:xs@(y:_)) = f x y : binMap f xs
binMap _ _ = []
splitRec :: Int -> [a] -> [[a]]
splitRec _ [] = []
splitRec n xs = let (y,ys) = splitAt n xs in y : splitRec n ys
infixl 7 `divCeil`
divCeil :: Integral a => a -> a -> a
x `divCeil` y = (x+y-1) `div` y
coverC :: Ord a => (a, a) -> a -> Bool
coverC (l,r) x = l<=x && x<=r
coverH :: Ord a => (a, a) -> a -> Bool
coverH (l,r) x = l<=x && x<r
ibsearch :: (Int -> Bool) -> (Int,Int) -> Int
ibsearch f (ok,ng) = if abs (ok-ng) <= 1 then ok else let mid = (ok + ng) `div` 2 in ibsearch f (if f mid then (mid,ng) else (ok,mid))
whenM :: Monad m => m Bool -> m () -> m ()
whenM c a = c >>= flip when a
unconsU :: [a] -> (a, [a])
unconsU (x:xs) = (x, xs)
-- templete

isSquare n = let sq = ibsearch (\x -> x^2 <= n) (1,n) in sq^2 == n


main = getLine >>= putStrLn . cond "Yes" "No" . isSquare . readInt . concat . words

Measured memory_bytes: 508
n =int(input())
A = list(map(int,input().split()))
q = int(input())

from collections import defaultdict
dic = defaultdict(int)
for a in A:
  dic[a] += 1 
  
ans = sum(A)
for i in range(q):  
  b,c = map(int,input().split())
  
  diff = dic[b]*c-dic[b]*b
  dic[c] += dic[b]
  ans += diff
  print(ans)  
  dic[b] = 0    

Measured memory_bytes: 23844
import math

N = int(input())

F = len(str(N))
for i in range(1, int(math.sqrt(N))+1):
    if N % i == 0:
        j = int(N / i)

        tmp = max(len(str(i)), len(str(j)))
        if tmp < F:
            F = tmp

print(F)

Measured memory_bytes: 3060
S = input()
T = input()

def solve(S,T):
    ls = len(S)
    lt = len(T)
    S = S[::-1]
    T = T[::-1]
    ans = [S[i] for i in range(ls)]
    # print(ans)
    # 既に含んでいる場合は全てaに変えていい
    if T not in S:    
        for i in range(ls-lt+1):
            for j in range(lt):
                if S[i+j]!=T[j] and S[i+j]!='?':
                    break
            else:
                ans[i:i+lt] = [T[i] for i in range(lt)]
                # print(ans)
                break
        else:
            return 'UNRESTORABLE'
    # print(ans)
    for i in range(ls):
        if ans[i]=='?':
            ans[i] = 'a'
    ans = ''.join(ans)
    return ans[::-1]
print(solve(S,T))

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

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

int main() {
    string S; cin >> S;
    string ans;
    rep(i,S.size()){
        if(S[i] == 'B'){
            if(ans != "") ans.pop_back();
        }else{
            ans += S[i];
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
D=int(input())
c=list(map(int,input().split()))
s=[]
for _ in range(D):
    ss=list(map(int,input().split()))
    s.append(ss)

for i in range(D):
    sss=s[i]
    a=sss.index(max(sss))
    print(a+1)
    i+=1

Measured memory_bytes: 9328
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = (A); I < (B); ++I)
#define FORR(I,A,B) for(ll I = (B-1); I >= (A); --I)
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(a%b==0)return b;else return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}//saisyo kobaisu
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=1e18+7;
const ll MOD=1e9+7;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll N;
	cin >> N;
	ll a2=0,a4=0,ao=0;
	FOR(i,0,N){
		ll k;
		cin >> k;
		if(k%4==0){
			a4++;
		}else if(k%2==0){
			a2++;
		}else{
			ao++;
		}
	}
	if(a2>0)ao++;
	if(a4>=(ao-1)){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}
}

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

using namespace std;

long long x;

int main (int argc, char const *argv[]) {
	cin >> x;
	long long l = 0, r = 3e9 + 10;
	while (l < r) {
		long long z = l + r + 1 >> 1;
		if (z * (z + 1) > x + x) r = z - 1;
		else l = z;
	}
	if (l * (l + 1) == x + x) {
		printf("%lld\n", l);
		return 0;
	}
	printf("%lld\n", l + 1);
  return 0;
}


Measured memory_bytes: 256
#include<algorithm>     //sort,二分探索,など
#include<bitset>        //固定長bit集合
#include<cmath>         //pow,logなど
#include<complex>       //複素数
#include<deque>         //両端アクセスのキュー
#include<functional>    //sortのgreater
#include<iomanip>       //setprecision(浮動小数点の出力の誤差)
#include<iostream>      //入出力
#include<iterator>      //集合演算(積集合,和集合,差集合など)
#include<map>           //map(辞書)
#include<numeric>       //iota(整数列の生成),gcdとlcm(c++17)
#include<queue>         //キュー
#include<set>           //集合
#include<stack>         //スタック
#include<string>        //文字列
#include<unordered_map> //イテレータあるけど順序保持しないmap
#include<unordered_set> //イテレータあるけど順序保持しないset
#include<utility>       //pair
#include<vector>        //可変長配列

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvll;
typedef vector<vector<string>> vvs;
typedef vector<vector<bool>> vvb;
const ll MOD = 1000000007;
const ll INF = 1000000000000000000;
#define rep(i,n) for(int i=0;i<n;i++)
#define repl(i,s,e) for(int i=s;i<e;i++)
#define reple(i,s,e) for(int i=s;i<=e;i++)
#define revrep(i,n) for(int i=n-1;i>=0;i--)
#define all(x) (x).begin(),(x).end()

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()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int N, K;
    cin >> N >> K;

    vll A(N);
    rep(i, N) cin >> A[i];

    repl(i, K, N)
    {
        if (A[i] > A[i - K])
        {
            cout << "Yes" << endl;
        }
        else
        {
            cout << "No" << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 4776
#include <iostream>
using namespace std;
int main(){
	int n,m,dp[50001]={0};
	while(cin>>n>>m){
	for(int i=0;i<=n;i++){
		dp[i]=i;
	}
	for(int i=0;i<m;i++){
		int c;
		cin>>c;
		for(int j=0;j<=n;j++){
			if(j>=c){
				dp[j]=min(dp[j],dp[j-c]+1);
			}
		}
	}
	cout<<dp[n]<<endl;
	/*
	for(int i=0;i<50;i++){
		cout<<dp[i]<<" ";
	}
	*/
	}
	return 0;
}

Measured memory_bytes: 3260
#include<stdio.h>
int main(void)
{
	int n,z[1000],c,i,m,b,y,j;
	double t,w,x,max,o,s[1000];
	while(1){
		scanf("%d",&n);
		if(n==0) break;
		scanf("%d",&y);
		for(i=0;i<n;i++){
			scanf("%d %lf %d",&z[i],&x,&c);
			if(c==1) s[i]=10000.0+(double)y*x*100;
			else {
				o=x/100.0;
				t=o+1.0;
				w=t;
				for(j=0;j<y-1;j++){
					t=t*w;
				}
				s[i]=t*10000.0;
			}
			
		}
		max=-1;
		for(i=0;i<n;i++){
			if(max<s[i])	{
				max=s[i];
				b=z[i];
			}
		}
		printf("%d\n",b);
	}
	return 0;
}

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

const int N = 200000;
const int M = 20;

int n, a[N], cnt[M];

bool check()
{
    for (int i = 0; i < M; ++ i) {
        if (cnt[i] > 1) {
            return false;
        }
    }
    return true;
}

int main()
{
    scanf("%d", &n);
    long long result = 0;
    for (int i = 0, j = 0; i < n; ++ i) {
        scanf("%d", a + i);
        for (int k = 0; k < M; ++ k) {
            cnt[k] += a[i] >> k & 1;
        }
        while (!check()) {
            for (int k = 0; k < M; ++ k) {
                cnt[k] -= a[j] >> k & 1;
            }
            j ++;
        }
        result += i - j + 1;
    }
    printf("%lld\n", result);
}

Measured memory_bytes: 1024