akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>

using namespace std;

int main()
{
    int H, W;

    scanf("%d %d", &H, &W);

    char table[H][W];

    int i, j;

    for (i = 0; i < H; i++) {
        scanf("%s", &table[i]);
    }

    for (i = 0; i < H; i++) {
        for (j = 0; j < W; j++) printf("%c", table[i][j]);
        printf("\n");
        for (j = 0; j < W; j++) printf("%c", table[i][j]);
        printf("\n");
    }

    return 0;
}


Measured memory_bytes: 128
local mmi, mma = math.min, math.max
local r, c, k = io.read("*n", "*n", "*n")
local item_row = {}
for i = 1, r do
  item_row[i] = {}
end
for i = 1, k do
  local ra, ca, v = io.read("*n", "*n", "*n")
  table.insert(item_row[ra], {ca, v})
end
for i = 1, r do
  table.sort(item_row[i], function(a, b) return a[1] < b[1] end)
end

local v1, v2, v3 = 0, 0, 0
local function box_reset(val)
  v1, v2, v3 = val, 0, 0
end
local function box_update(val)
  if val <= v3 then return end
  v3 = val
  if val <= v2 then return end
  v2, v3 = val, v2
  if v1 < val then
    v1, v2 = val, v1
  end
end
local function getboxval()
  return v1 + v2 + v3
end

local dp1, dp2 = {}, {}
for i = 1, r do
  local tbl = dp1
  local tbl2 = dp2
  -- local tbl = i % 2 == 1 and dp1 or dp2
  -- local tbl2 = i % 2 == 1 and dp2 or dp1
  if i == 1 then
    for j = 1, c do
      tbl[j] = 0
    end
  else
    for j = 1, c do
      tbl[j] = tbl2[j]
    end
  end
  for j = 1, c - 1 do
    tbl[j + 1] = mma(tbl[j + 1], tbl[j])
  end
  for j = 1, c do
    tbl2[j] = 0
  end
  local item = item_row[i]
  for j = 1, #item do
    local col, val = item[j][1], item[j][2]
    box_reset(val)
    local baseval = tbl[col]
    tbl2[col] = mma(tbl2[col], baseval + getboxval())
    for k = j + 1, #item do
      local c2, v2 = item[k][1], item[k][2]
      box_update(v2)
      tbl2[c2] = mma(tbl2[c2], baseval + getboxval())
    end
  end
  tbl2[1] = mma(tbl2[1], tbl[1])
  for j = 2, c do
    tbl2[j] = mma(tbl2[j], tbl2[j - 1], tbl[j])
  end
end
-- print(dp1[1], dp1[2])
-- print(dp2[1], dp2[2])
print(dp2[c])


Measured memory_bytes: 17984
#include<bits/stdc++.h>
#pragma warning(disable:4996)
using namespace std;
int main() {
	int n, m, sum;
	scanf("%d%d%d", &n, &m, &sum);
	for (int i = 0; i < m; i++) {
		printf("%d ", sum);
	}
	if (sum > 1e5 + 5) {
		for (int i = m; i < n; i++) {
			printf("1 ");
		}
		printf("\n");
	}
	else {
		for (int i = m; i < n; i++) {
			printf("1000000 ");
		}
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 3820
#include <iostream>
#include <vector>
#include <stack>
#include <algorithm>

using std::cin;
using std::cout;
using std::endl;

struct data_t {
	int hh;
	int mm;
	int ss;

	bool operator<(const data_t& right) const {
		if ( hh ==  right.hh ) {
			if ( mm == right.mm ) {
				return ( ss == right.ss ) || ( ss < right.ss );
			}
			else {
				return ( mm < right.mm );
			}
		}
		else {
			return ( hh < right.hh );
		}
	}
};

bool is_early(data_t d1, data_t d2) {
	if (d1.hh == d2.hh) {
		if (d1.mm == d2.mm) {
			return (d1.ss < d2.ss);
		}
		else {
			return (d1.mm < d2.mm);
		}
	}
	else {
		return (d1.hh < d2.hh);
	}
}

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

	char c;
	while ( n != 0 ) {
		std::vector<data_t> start(n+1); 
		std::vector<data_t> stop(n+1); 
		for (int i = 0; i < n; i++) {
			cin >> start[i].hh;
			cin >> c;
			cin >> start[i].mm;
			cin >> c;
			cin >> start[i].ss;

			cin >> stop[i].hh;
			cin >> c;
			cin >> stop[i].mm;
			cin >> c;
			cin >> stop[i].ss;
		}

		start[n].hh = 100;
		start[n].mm = 100;
		start[n].ss = 100;
		stop[n].hh = 100;
		stop[n].mm = 100;
		stop[n].ss = 100;
		std::sort(start.begin(), start.end());
		std::sort(stop.begin(), stop.end());

		std::stack<bool> train;
		int count_t = 0;
		int r1 = 0;
		int r2 = 0;
		for (int i = 0; i < (n*2); i++) {
			if (is_early(start[r1],stop[r2])) {
				if (train.empty()) {
					count_t++;
				}
				else {
					train.pop();
				}
				r1++;
			}
			else {
				train.push(true);
				r2++;
			}
		}

		cout << count_t << endl;
		cin >> n;
	}

	return 0;
}

Measured memory_bytes: 3200
#include <cstdio>
#include <vector>
using namespace std;

int main()
{
  int N, A, B, C, X;
  while (scanf("%d %d %d %d %d", &N, &A, &B, &C, &X) != EOF) {
    if (N == 0 && A == 0 && B == 0 && C == 0 && X == 0)
      break;

    vector<int> Y(N);
    for (int i = 0; i < N; ++i)
      scanf("%d", &Y[i]);

    int f = 0, cnt = 0;
    for (; f <= 10000 && cnt < N; ++f) {
      if (X == Y[cnt])
	++cnt;
      X = (A * X + B) % C;
    }

    if (cnt < N)
      printf("-1\n");
    else
      printf("%d\n", --f);
  }
  return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<vector>
#include<cstdlib>
using namespace std;

struct Card{
	int value;
	char type;
	void swapCard(Card &c){Card tmp; tmp=*this; *this=c; c=tmp;}
};

void printCards(vector<Card> &C,int N){
	cout << C[0].type << C[0].value;
	for(int i=1;i<N;i++){
		cout << " " << C[i].type << C[i].value;
	}
	cout << endl;
	return;
}

bool BubbleSort(vector<Card> &C,int N){
	bool stable;
	int i, j;
	for(i=0;i<N;i++){
		for(j=N-1;j>i;j--){
			if(C[j].value < C[j-1].value)
				C[j].swapCard(C[j-1]);
		}
	}
	stable = true;
	return stable;
}

bool SelectionSort(vector<Card> &C,int N){
	bool stable = true;
	int i, j, k, minj;
	for(i=0;i<N-1;i++){
		minj = i;
		for(j=i;j<N;j++){
			if(C[j].value < C[minj].value){
				minj = j;
				
			}
		}
		C[i].swapCard(C[minj]);
		for(k=minj-1;k>=0;k--){
			if(C[minj].value == C[k].value)
				stable = false;
		}
	}
	return stable;
}

int main(){
	int n, i;
	bool stable;
	char str[3];
	cin >> n;
	vector<Card> v(n), vcpy(n);
	for(i=0;i<n;i++){
		cin >> str;
		v[i].value = atoi(str+1);
		v[i].type = str[0];
	}
	vcpy = v;
	stable = BubbleSort(vcpy, n);
	printCards(vcpy, n);
	if(stable)
		cout << "Stable\n";
	else
		cout << "Not stable\n";
	vcpy = v;
	stable = SelectionSort(vcpy, n);
	printCards(vcpy, n);
	if(stable)
		cout << "Stable\n";
	else
		cout << "Not stable\n";
	return 0;
}

Measured memory_bytes: 1232
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <bitset>
#include <deque>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <iterator>
#include <string>
#include <chrono>
#include <random>
#include <tuple>
#include <utility>
#include <fstream>
 
const long INF = (1l << 30);
const long LINF = (1l << 60);

long n, m;
long l, r;

int main(){
	scanf("%ld%ld", &n, &m);
	for(int i = 0; i < m; i++){
		long a, b;
		scanf("%ld%ld", &a, &b);
		if(i == 0){
			l = a;
			r = b;
		}else{
			l = std::max(a, l);
			r = std::min(b, r);
		}
	}
	printf("%ld\n", std::max(0l, r - l + 1));
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main
{
	public static void main(String[] args)
	{
		Scanner sc=new Scanner(System.in);
		int L=sc.nextInt();
		int A=sc.nextInt();
		int B=sc.nextInt();
		int C=sc.nextInt();
		int D=sc.nextInt();
		
		int ans=0;
		int ma, ja;
		ma=A/C;
		if(A%C != 0)ma++;
		
		ja=B/D;
		if(B%D != 0)ja++;
		
		ans = Math.max(ma, ja);
		System.out.println(L-ans);
	}
}

Measured memory_bytes: 17360
#include<iostream>
#include<algorithm>
using namespace std;
int N_MAX=200000;
int main()
{
  int n,s=0,i;
  int a[N_MAX];
  cin >> n;
  for(i=0;i<n;i++){
    cin >> a[i];
    s^=a[i];
  }
  for(i=0;i<n;i++)
    cout << (s^a[i]) << " ";
  cout << endl;
  return 0;
}

Measured memory_bytes: 4332
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = (int)1e9 + 7;
const ll INF = (int)100100100100100100;

int main() {
    //ll N; cin >> N;
    ll N,W; cin >> N >> W;
    //string S; cin >> S;
    //ll H,W; cin >> H >> W;
    ll dp[N+1][W+1]={};
    ll w[N];
    ll v[N];
    for(int i=0;i<N;i++){
        cin >> w[i] >> v[i];
    }
    for(int i=0;i<N;i++){
        for(int j=0;j<=W;j++){
            if(j-w[i]>=0){
                dp[i+1][j]=max(dp[i][j],dp[i][j-w[i]]+v[i]);
            }
            dp[i+1][j]=max(dp[i+1][j],dp[i][j]);
        }
    }
    cout << dp[N][W];
}

/*



 */



Measured memory_bytes: 79104
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
using namespace std;
int main(){
  int n;
  char room[11];

  while(cin >> n, n){
    //printf("%o\n", n);
    sprintf(room, "%o", n);
    for(int i = 0 ; i <= 10 ; i++){
      if(room[i] < '4') continue;
      else if(room[i] == '4') room[i] = '5';
      else if(room[i] > '4') room[i] += 2;
    }
    cout << room << endl;
  }
  return 0;
}

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

using namespace std;

typedef long long ll;

int main() {
	ll s = 10000000000, e = 99999999999;
	while(s<=e) {
		ll m = (s+e)>>1;
		printf("? %lld\n",m);
		fflush(stdout);
		char buf[5];
		scanf("%s",buf);
		if (buf[0]=='Y') {
			e = m-1;
		}
		else s = m+1;
	}
	if (s==10000000000) {
		ll cnt = 10, dig = 2;
		for (;cnt<=10000000000;cnt*=10,dig++) {
			printf("? %lld\n",cnt-1);
			fflush(stdout);
			char buf[5];
			scanf("%s",buf);
			if (buf[0]=='Y') break;
		}
		printf("! %lld\n",cnt/10);
	}
	else {
		ll cnt = 1, dig = 1;
		for (;cnt<=10000000000;cnt*=10,dig++) {
			printf("? %lld\n",cnt);
			fflush(stdout);
			char buf[5];
			scanf("%s",buf);
			if (buf[0]=='N') break;
		}
		while(s>=cnt) s/=10;
		printf("! %lld\n",s);
	}

    return 0;
}


Measured memory_bytes: 596
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=1;i<=n;i++)
using namespace std;
using ll=long long;
using P = pair<int,int>;
int main(){
    int N;
    cin >> N;
    int d1[N],d2[N];
    for(int i=0;i<N;i++){
        cin >> d1[i] >> d2[i];
    }
    int ans = 0;
    for(int i=0;i<N-2;i++){
        if(d1[i]==d2[i]&&d1[i+1]==d2[i+1]&&d1[i+2]==d2[i+2])ans++;
    }
    if(ans==0)cout << "No" << endl;
    else cout << "Yes" << endl;
}

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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    int H, W;
    cin >> H >> W;
    int board[H][W];
    rep(i, H){rep(j, W){
        char x;
        cin >> x;
        if (x == '.'){board[i][j] = 1;} else {board[i][j] = 0;}
    }}

    ll total_ans = 0;

    // BFS(幅優先探索)
    rep(i, H){rep(j, W){
        if (!board[i][j]){continue;}
        ll dist[H][W];
        int cnt = 0;
        rep(k, H){rep(l, W){dist[k][l]=INF;}}

        queue<tuple<int, int, int>> fifo;
        fifo.push(make_tuple(i, j, 0));

        while (fifo.size() > 0){
            tuple<int, int, int> tmp = fifo.front();
            int& cur_y = get<0>(tmp);
            int& cur_x = get<1>(tmp);
            int& cur_cost = get<2>(tmp);
            fifo.pop();
            cnt += 1;
            if (dist[cur_y][cur_x] != INF){continue;}
            dist[cur_y][cur_x] = cur_cost;

            rep(k, 4){
                int next_y = cur_y + dy[k];
                int next_x = cur_x + dx[k];
                if (0 <= next_y && next_y < H && 0 <= next_x && next_x < W && dist[next_y][next_x] == INF && board[next_y][next_x]){
                    // cout << next_y << " " << next_x << " " << dist[next_y][next_x] << " " << board[next_y][next_x] << endl;
                    fifo.push(make_tuple(next_y, next_x, cur_cost + 1));
                }
            }
        }
        ll ans = 0;
        rep(k, H){rep(l, W){
            if (dist[k][l] != INF and dist[k][l] > ans){ans = dist[k][l];}
        }}
        if (ans != INF and ans > total_ans){total_ans = ans;}
        // cout << i << " " << j << " count: " << cnt << endl;
    }}
    cout << total_ans << endl;
}

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


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

int sum;

void cmp(int a, int b, int c){
    if ((a < b && b < c) || (a > b && b > c)) sum++;
}

int main(){
    sum = 0;
    int p[20];
    int n;

    cin >> n;
    for (int i = 0; i < n; i++){
        cin >> p[i];
    }
    
    for(int i = 0; i < n-2 ; i++){
        cmp(p[i], p[i+1], p[i+2]);
    }

    cout << sum << "\n";

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <string>
#include <cstring>

using namespace std;

int N;
map<string,int> m;
int idx=0;
vector<int> G[101];
vector<string> CS[101];
string names[101];
int strong[101];
bool used[101];
int optNum;

// 現在選べるものから選ぶ
void dfs(int idx,int sum,int leftSum){
  if(idx==N){
    optNum=max(optNum,sum);
    return;
  }
  if(used[idx]){
    dfs(idx+1,sum,leftSum);
    return;
  }
  if(leftSum+sum<=optNum)return;
  bool ok=true;
  // これから選ぶ頂点のどれかと隣接しているかチェック
  for(int i=idx+1;i<N;i++){
    if(used[i])continue;
    for(int j=0;j<(int)G[i].size();j++){
      if(G[i][j]==idx){
	ok=false;
	break;
      }
    }
    if(!ok)break;
  }
  // 隣接している頂点が存在する場合
  if(idx!=0&&!ok){
    // 取らない
    dfs(idx+1,sum,leftSum);
  }
  if(!used[idx]){
    bool cur[50];
    for(int i=0;i<N;i++)cur[i]=used[i];
    int nLeftSum=leftSum;
    nLeftSum-=strong[idx];
    used[idx]=true;
    for(int j=0;j<(int)G[idx].size();j++){
      int to=G[idx][j];
      if(!used[to])nLeftSum-=strong[to];
      used[to]=true;
    }
    dfs(idx+1,sum+strong[idx],nLeftSum);
    for(int j=0;j<N;j++)used[j]=cur[j];
  }
}

int main(){
  while(cin>>N&&N){
    idx=0;
    optNum=-1;
    for(int i=0;i<101;i++){
      G[i].clear();
      CS[i].clear();
    }
    m.clear();
    int sum=0;
    for(int i=0;i<N;i++){
      cin>>names[i]>>strong[i];
      sum+=strong[i];
      int C;
      cin>>C;
      for(int j=0;j<C;j++){
	string s;
	cin>>s;
	if(m.count(s)==0)m[s]=idx++;
	CS[i].push_back(s);
      }
    }
    for(int i=0;i<N;i++)
      m[names[i]]=i;
    for(int i=0;i<N;i++){
      for(int j=0;j<(int)CS[i].size();j++){
	G[m[names[i]]].push_back(m[CS[i][j]]);
	G[m[CS[i][j]]].push_back(m[names[i]]);
      }
    }
    memset(used,0,sizeof(used));
    dfs(0,0,sum);
    cout<<optNum<<endl;
  }

  return 0;
}

Measured memory_bytes: 1032
#include <iostream>
#include <complex>
using namespace std;
 
typedef complex<double> Point;
 
double cross(Point a, Point b){
    return (conj(a)*b).imag();
}
 
int main(){
    Point V[3], P;
    while(true){
        double x, y;
        for(int i=0; i<3; i++){
            cin >> x >> y;
            V[i] = {x, y};
        }
        cin >> x >> y;
        P = {x, y};
         
        if(!cin)break;
         
        int sum = 0;
        for(int i=0; i<3; i++){
            sum += cross(V[(i+1)%3]-V[i], (P-V[i])) > 0;
        }
        cout << (sum==0 || sum==3? "YES": "NO") << endl;
    }
    return 0;
}


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


int main() {
  
  int a, p, ans;
  cin >> a >> p;
  
 ans = (a * 3 +  p ) / 2;
  
  //ans = ((a * 3 + p) + 2 - 1) / 2;
    
    cout << ans << endl;
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ALL(V) (V).begin(), (V).end()
#define ALLR(V) (V).rbegin(), (V).rend()
// #define DEBUGGING

template <typename T> using V = vector<T>;
template <typename T> using VV = V<V<T>>;
template <typename T, typename U> using P = pair<T, U>;
using ll = int64_t;
using PLL = P<ll, ll>;

template <typename T> const T& var_min(const T &t) { return t; }
template <typename T> const T& var_max(const T &t) { return t; }
template <typename T, typename... Tail> const T& var_min(const T &t, const Tail&... tail) { return min(t, var_min(tail...)); }
template <typename T, typename... Tail> const T& var_max(const T &t, const Tail&... tail) { return max(t, var_max(tail...)); }
template <typename T, typename... Tail> void chmin(T &t, const Tail&... tail) { t = var_min(t, tail...); }
template <typename T, typename... Tail> void chmax(T &t, const Tail&... tail) { t = var_max(t, tail...); }
template <typename T> const T& clamp(const T &t, const T &low, const T &high) { return max(low, min(high, t)); }
template <typename T> void chclamp(T &t, const T &low, const T &high) { t = clamp(t, low, high); }

namespace __init {

struct InitIO {
    InitIO() {
        cin.tie(nullptr);
        ios_base::sync_with_stdio(false);
        cout << fixed << setprecision(30);
    }
} init_io;

}

#ifdef DEBUGGING
#include "../debug.cpp"
#else
#define DEBUG(...) 0
#define DEBUG_SEPARATOR_LINE 0
#endif

template <typename T>
T make_v(T init) { return init; }

template <typename T, typename... Tail>
auto make_v(T init, size_t s, Tail... tail) {
#define rec make_v(init, tail...)
    return V<decltype(rec)>(s, rec);
#undef rec
}

struct UnionFind {
    V<ll> rank;
    V<ll> parent;

    UnionFind(ll N) : rank(N, 0), parent(N) {
        iota(parent.begin(), parent.end(), 0ll);
    }

    ll find(ll child) {
        return (child == parent[child] ? child : parent[child] = find(parent[child]));
    }

    void unit(ll x, ll y) {
        ll px = find(x);
        ll py = find(y);
        if(px == py) {
            return;
        }
        if(rank[px] < rank[py]) {
            swap(px, py);
        }
        parent[py] = px;
        rank[px] += (rank[px] == rank[py]);
    }

    bool same(ll x, ll y) {
        return (find(x) == find(y));
    }
};

int main() {
    ll N, M;
    cin >> N >> M;
    UnionFind uf(N + M + 10);
    for(ll i = 0; i < N; i++) {
        ll k;
        cin >> k;
        while(k--) {
            ll l;
            cin >> l;
            l--;
            uf.unit(i, N + l);
        }
    }

    ll par = uf.find(0);
    for(ll i = 1; i < N; i++) {
        if(uf.find(i) == par) continue;
        cout << "NO\n";
        return 0;
    }
    cout << "YES\n";
    return 0;
}


Measured memory_bytes: 3328
#
# abc070 a
#
import sys
from io import StringIO
import unittest


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """575"""
        output = """Yes"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """123"""
        output = """No"""
        self.assertIO(input, output)

    def test_入力例_3(self):
        input = """812"""
        output = """No"""
        self.assertIO(input, output)


def resolve():
    N = input()
    if N[0] == N[-1]:
        print("Yes")
    else:
        print("No")


if __name__ == "__main__":
    # unittest.main()
    resolve()


Measured memory_bytes: 16240
#include <bits/stdc++.h>
using namespace std;
#ifdef __DEBUG__
    void debug_out() { cerr << endl; } 
    template <typename Head, typename... Tail>
    void debug_out(Head H, Tail... T) {cerr << " " << H; debug_out(T...);}
    #define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
    #define debug(...) 
#endif

using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

int dx[]={1, 0, -1, 0, 1,-1, 1,-1};
int dy[]={0, 1, 0, -1, 1, 1,-1,-1};
const int INT_INF = (int)(2e9);
const ll  LL_INF = (ll)(2e18);

inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const map<T, S> p) { for (auto el : p) cout << "[" << el.first << ";" << el.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const deque<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const set<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; }

int N, M;
inline void input(){
    fast_io();
    cin >> N >> M;
}
#include <atcoder/dsu>
inline int solve(){
    atcoder::dsu dsu(N);
    for (int i = 0; i < M; i++)
    {
        int a,b;cin >>a >> b;
        a--,b--;
        dsu.merge(a,b);
    }
    int ans = dsu.groups().size()-1;
    cout << ans << endl;
    
    
    return 0;
}   

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


Measured memory_bytes: 8792
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define sz(x) (int)x.size()
#define int long long
typedef pair<int,int>pii;
const int mxN=1e5+5,M=1e9+7;
//did u check when n=1?
//is mxN correct?
int n,k,q;
int tot,v[mxN];
int32_t main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin>>n>>k>>q;
    for(int i=0;i<q;i++){
        int x;cin>>x;
        v[x]++;
    }
    for(int i=1;i<=n;i++){
        //cout<<k<<" "<<(q-v[i])<<"\n";
        if(k-(q-v[i])<=0)cout<<"No\n";
        else cout<<"Yes\n";
    }

}


Measured memory_bytes: 1408
import bisect
a,b,q=map(int,input().split())
s=[int(input()) for i in range(a)]
t=[int(input()) for i in range(b)]
for i in range(q):
  x=int(input())
  idxS=bisect.bisect_left(s,x)
  idxT=bisect.bisect_left(t,x)
  d=[]
  if idxS<a and idxT<b:
    d.append(max(s[idxS]-x,t[idxT]-x))
  if 1<=idxS and 1<=idxT:
    d.append(max(x-s[idxS-1],x-t[idxT-1]))
  if 1<=idxS and idxT<b:
    d.append((t[idxT]-x)*2+x-s[idxS-1])
  if 1<=idxT and idxS<a:
    d.append((s[idxS]-x)*2+x-t[idxT-1])
  if idxT<b and 1<=idxS:
    d.append((x-s[idxS-1])*2+t[idxT]-x)
  if idxS<a and 1<=idxT:
    d.append((x-t[idxT-1])*2+s[idxS]-x)
  print(min(d))

Measured memory_bytes: 12080
import sys
input = sys.stdin.readline

A = list(list(map(int, input().split())) for i in range(3))
N = int(input())
B = list(int(input()) for i in range(N))

for b in B:
    A = [["hit" if i==b else i for i in a] for a in A]

for w in range(3):
    if all(a=="hit" for a in A[w]):
        print("Yes")
        quit()

for h in range(3):
    if all(A[i][h]=="hit" for i in range(3)):
        print("Yes")
        quit()

if A[0][0]=="hit" and A[1][1]=="hit" and A[2][2]=="hit":
    print("Yes")
    quit()

if A[0][-1]=="hit" and A[1][-2]=="hit" and A[2][-3]=="hit":
    print("Yes")
    quit()

print("No")

Measured memory_bytes: 3064
#include<iostream>
#include<algorithm>
#include<math.h>
using namespace std;
int main(){
	int n;
	cin>>n;
	bool down=false;
	bool p=true;
	int before=0;
	for(int i=0;i<n;i++){
		int j;cin>>j;
		if(j<before){
			if(before-j>=2){p=false;}
			if(down==true){p=false;}
			else{down=true;}
		}
		if(j>before){
			down=false;
		}
		before=j;
	}
	if(p==true){cout<<"Yes"<<endl;}
	else{cout<<"No"<<endl;}
}

Measured memory_bytes: 384
#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() {
    int n;cin>>n;
    int count=0;
    int cnt[n+1];
    rep(i,n+1){
        cnt[i]=0;
    }
    for (int i = 1; i <= n; i++)
    {
        /* code */
        for (int j = 1; j <= n; j++)
        {
            /* code */
            if (i%j==0&&i%2!=0)
            {
                /* code */
                cnt[i]++;
            }
            
        }
        
    }
    rep(i,n+1){
        if (cnt[i]==8)
        {
            /* code */
            count++;
        }
        
    }
    cout<<count<<endl;

}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <math.h>
#include <stdio.h>
#include <ctype.h>
#include <ios> 
#include <iomanip>
using namespace std;

#define N_MAX   (100000)
#define LL_MAX_NUM (1LL<<60)
#define INF 1e7

typedef long long ll;
typedef long long int lli;

int main() {
	string N; cin >> N;
	cout << (N[0]==N[1]||N[1]==N[2]||N[2]==N[3]?"Bad":"Good") << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define SORT(x) sort((x).begin(),(x).end())
#define ALL(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < n; i++)
#define reps(i, m, n) for(ll i = m; i < n; i++)
#define repr(i, m, n) for(int i = m; i >= n; i--)
template<class T>bool maxi(T &a,const T &b){if(a<b){ a=b; return 1;} return 0;}
template<class T>bool mini(T &a,const T &b){if(b<a){ a=b; return 1;} return 0;}
#define y0 y3487465 //j0
#define j1 j1347829 //j1
#define INF2 4000000000000000037
#define INF 1000000007
#define PI (acos(-1))
#define MOD 1000000007
using namespace std;
typedef long long ll;


void Main(){

  int Q; cin>>Q;

  ll sumb=0;
  ll fx=0;
  ll ct1=0;
  priority_queue<ll> st1; //xが小さい方、大きい方から出る
  priority_queue<ll,vector<ll>, greater<ll>> st2; //xが大きい方、小さい方から出る
  ll center;
  ll center1=INF2;
  ll center2=INF2;
  rep(i,Q){
    int qu; cin>>qu;
    if(qu==1){
      ll a,b; cin>>a>>b;
      sumb+=b;

      if(ct1==0){
        center=a;
        ct1++;
        continue;
      }
      if(ct1%2==0){
        if(a<center1){
          fx+=center1-a;
          center=center1;
          st1.push(a);
          st2.push(center2);
        }
        else if(a>center2){
          fx+=a-center2;
          center=center2;
          st1.push(center1);
          st2.push(a);
        }
        else{
          center=a;
          st1.push(center1);
          st2.push(center2);
        }
      }
      if(ct1%2==1){
        fx+= abs(center-a);
        if(a>=center){
          st2.push(a);
          center1=center;
          center2=st2.top();
          st2.pop();
        }
        else{
          st1.push(a);
          center2=center;
          center1=st1.top();
          st1.pop();
        }
      }
      ct1++;
    }
    else{
      if(ct1%2==0){
        cout<< center1<<" "<< fx+sumb <<"\n";
      }
      else{
        cout<< center<<" "<< fx+sumb <<"\n";
      }
    }
  }

}

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


Measured memory_bytes: 3828
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long unsigned int ll;
 
int main() {
 
  string a;
  int b=0;
  cin >> a;
  
  
  if(a[0]=='o')b+=1;
  if(a[1]=='o')b+=1;
  if(a[2]=='o')b+=1;
  
  cout << (7+b)*100 <<endl;  
   return 0;
}


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

int main(){

    while(true){

    string str;
    cin >> str;
    if(str[0] == '0') break;
    int sum = 0;

    for(int i=0; i<str.size(); i++){
        sum += (str[i] - '0');
    }

    cout << sum << endl;

    }
    return 0;
}


Measured memory_bytes: 3180
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for(int i=0;i<(int)n;i++)
#define PI acos(-1)
#define fast_io ios_base::sync_with_stdio(false) ; cin.tie(0); cout.tie(0);
ll mod=1e9+7;

ll rep_pow(ll a, ll b){//繰り返し2乗法
    if(b==0) return 1;
    else if(b%2==0){
        ll memo = rep_pow(a, b/2);
        return memo*memo%mod;
    }else{
        return rep_pow(a, b-1)*a%mod;
    }
}
ll nCr(ll n, ll r){//mod逆元使ったnCr
    ll ret=1;
    rep(i,r){
        ret *= n-i;//分子
        ret %= mod;
        ret *=rep_pow(r-i, mod-2);//mod逆元によりr!で割ると同値
        ret %= mod;
    }
    return ret;
}
ll gcd(ll a, ll b){if(b==0) return a; return gcd(b, a%b);}
bool isPrime(int x){
    if(x==1) return false;
    else if(x==2) return true;
    else if(x%2==0) return false;
    for(int i=3;i<=sqrt(x);i+=2){
        if(x%i==0){
            return false;
        }
    }
    return true;
}


int main(){
    fast_io
    
    int n;
    cin>>n;
    int A[2][n];
    rep(i,2){
        rep(j,n){
            cin>>A[i][j];
        }
    }

    int ans=0;
    rep(i, n){
        int k=0;
        int sum=0;
        rep(j,n){
            sum+=A[k][j];
            if(i==j) {
                k++;
                sum+=A[k][j];
            }
        }
        ans=max(ans, sum);
    }
    cout<<ans<<endl;
    
    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

template <typename T>
void print(T x) {
    cout << x << endl;
}

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;

struct mint {
    ll x; // typedef long long ll;
    mint(ll x=0):x((x%MOD+MOD)%MOD){}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += MOD-a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= MOD;
        return *this;
    }
    mint operator+(const mint a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res*=a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    // for prime MOD
    mint inv() const {
        return pow(MOD-2);
    }
    mint& operator/=(const mint a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint a) const {
        mint res(*this);
        return res/=a;
    }
};

ostream& operator << (ostream& os, const mint a) {
    os << a.x;

    return os;
}

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    
    int N;
    cin >> N;

    vll C(N);
    REP(i, N) cin >> C[i];

    sort(ALL(C), greater<>());

    mint ans = 0;
    mint s = 1, b1 = 1, p = mint(4).pow(N), b2 = 2;
    REP(i, N) {
        p /= 4;
        mint tmp = p * C[i] * s * b2;
        ans += tmp;


        if (i > 0) {
            b1 *= 2;
        }
        s = s * 2 + b1;
        b2 *= 2;

    }

    print(ans);
    
}


Measured memory_bytes: 4788
use std::io::*;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
  let stdin = stdin();
  let stdin = stdin.lock();
  let token: String = stdin
    .bytes()
    .map(|c| c.expect("failed to read char") as char)
    .skip_while(|c| c.is_whitespace())
    .take_while(|c| !c.is_whitespace())
    .collect();
  token.parse().ok().expect("failed to parse token")
}

use std::cmp::{max, min};
use std::collections::HashMap;

fn main() {
  let x = read::<i64>();

  let mut sum = 0;
  let mut ans = 1;

  while sum < x {
    sum += ans;
    ans += 1;
  }

  println!("{}", ans - 1);
}



Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0; i<(n); i++)
#define all(n) begin(n),end(n)
using ll = long long;
using P = pair<int,int>;

int main() {
    int n, k;
    cin >> n >> k;
    double ans = 0;
    for(int i = 1; i <= n; ++i) {
        double tmp = 1.0/n;
        int score = i;
        while(score<k) {
            tmp*=0.5;
            score *=2;
        }
        ans += tmp;

    }
    printf("%.10f", ans);
    return 0;
}

Measured memory_bytes: 256
# include <bits/stdc++.h>
  using namespace std;
# define res(a,b,c) for (int64 a=b ; a<c ; a++)
# define ress(a,b)  for (auto a = b.begin() ; a!=b.end() ; a++) 
# define all(con) con.begin() , con.end()
# define INF (int)1e9  
# define MOD 1000000007
# define pb push_back   
# define mp make_pair
# define f first
# define s second   
# define MAX numeric_limits<int>::max() 
# define MIN numeric_limits<int64>::min()
# define mymin -1000000000000000001
# define mymax 1000000000000000001
# define watch(x) cout<<(#x)<<" is "<<(x)<<endl
# define in(x) cin>>(x)
# define inn(x,y) cin>>(x)>>(y)  
# define out(x) cout<<(x)<<"\n"  
# define outt(x,y) cout<<(x)<<" "<<(y)<<"\n"  
typedef long long int int64;
typedef unsigned long long int uint64;
typedef vector<int64> vi;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef pair<int64,int64> pi; 
bool doubleSame(double a, double b)
{ const double eps = 1e-15; return ( abs(a-b)<= eps*abs(a) ); }

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

	vector<vector<int64>> inp(n+1,vector<int64>(4));
	for(int64 i = 1 ; i<=n ; i++)
	{
		for(int64 j = 1 ; j<=3 ; j++)
			cin>>inp[i][j];
	}

	vector<vector<int64>> lev(n+1,vector<int64>(4));
	lev[1][1] = inp[1][1];
	lev[1][2] = inp[1][2];
	lev[1][3] = inp[1][3];

	for(int64 i = 2 ; i<=n ; i++)
	{
		for(int64 j = 1 ; j<=3 ; j++)
		{
			if(j==1)
				lev[i][j] = inp[i][j] + max(lev[i-1][j+1],lev[i-1][j+2]);
			else if(j==2)
				lev[i][j] = inp[i][j] + max(lev[i-1][j-1],lev[i-1][j+1]);
			else
				lev[i][j] = inp[i][j] + max(lev[i-1][j-1],lev[i-1][j-2]);
		}
	}
	cout<<max(lev[n][1],max(lev[n][2],lev[n][3]));
}

Measured memory_bytes: 14336
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
//#include<bits/stdc++.h>
#include<cstdio>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread_unlocked(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	int A = 0;
	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}

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


	int N = getint();
	int k = 1;
	rep(i, N >> 1) {
		k += getint() == k;
		k += getint() == k;
	}
	if (N & 1) k += getint() == k;

	if (k != 1) printf("%d", N - k + 1);
	else printf("-1");

	Would you please return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<functional>
#include<algorithm>
#include<iostream>
#include<cstring>
#include<string>
#include<cstdlib>
#include<cctype>
#define rep(i,a) for(int i=0;i<a;i++)
#define rep2(i,a) for(int i=1;i<a;i++)
using namespace std;
long long c[100][100];
int main(void)
{
	int m,l,n;
	int a[100][100],b[100][100];
	cin>>n>>m>>l;
	rep(i,n)rep(j,m)cin>>a[i][j];
	rep(i,m)rep(j,l)cin>>b[i][j];
	rep(i,n)rep(j,l)rep(k,m) c[i][j]+=a[i][k]*b[k][j];
	rep(i,n){
		cout<<c[i][0];
		rep2(j,l) {
			if(j==l) cout<<c[i][j];
			else cout<<" "<<c[i][j];
		}
		cout<<endl;
	}
	return 0;
}

Measured memory_bytes: 3188
#include<stdio.h>

int main(void){

 int a,b,d,r;

 double f;

 scanf("%d",&a);

 scanf("%d",&b);

 d=a/b;

 r=a-(d*b);

 f=(double)a/b;

 printf("%d %d ",d,r);

 printf("%lf",f);

 return 0;

}

Measured memory_bytes: 636
#include <bits/stdc++.h>
#define REP(i,n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i,a,b) for (ll i=(a);i<(ll)b; i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define INF 1000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<ll,ll> p;
const int MOD = 1000000007;

// vector<p> cut(M);
// cut[i].second
// cut[i].first;
// REP(i,M){
//     int a,b;cin>>a>>b;
//     cut[i] = make_pair(b,a);//last first の順番
// }
// for(int i=0; i<N;i++){
// }
// sort(cut.begin(),cut.end()); //sort
// char '' str ""
int main(void)
{
    int A,B;cin>>A>>B;

    if(A==B){
      cout<<"Draw"<<endl;
      return 0;
    }
    if(A==1){
      cout<<"Alice"<<endl;
        return 0;
    }
    if(B==1){
      cout<<"Bob"<<endl;
        return 0;
    }
    if(A>B){
      cout<<"Alice"<<endl;
        return 0;
    }else{
      cout<<"Bob"<<endl;
        return 0;
    }

    return 0;
}


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

using namespace std;

int main()
{
	int n, lim, i, remain;
	int trr[100002];
	int falltime[100002];
	
		memset( trr, 0, sizeof(trr));
		memset( falltime, -1, sizeof(falltime));
		cin >> n >> lim;
		
		for( i = 1; i <= n; i++)
		{
			cin >> trr[i];
		}
		
		remain = n;
		
		for( i = 1; i <= n; i++)
			if( trr[i] > trr[i-1] && trr[i] > trr[i+1] )
			{
				falltime[i] = lim - trr[i];
				remain--;
			}
		
		while( remain != 0 )
		{
			for( i = 1; i <= n; i++)
			{
				int left = 0, right = 0;
				if( falltime[i] == -1 )
				{
					if( trr[i-1] > trr[i] )
						if( falltime[i-1] != -1 )
							left = falltime[i-1];
						else
							continue;

					if( trr[i+1] > trr[i] )
						if( falltime[i+1] != -1 )
							right = falltime[i+1];
						else
							continue;
					
					if( left || right )
					{
						falltime[i] = lim - trr[i] + max( left, right );
						remain--;
					}
				}
			}
		}
		
		int out = 0;
		for( i = 1; i <= n; i++)
		{
			out = max(out, falltime[i]);
		}
		
		cout << out << endl;
	
	return 0;
}

Measured memory_bytes: 0
import sys
from bisect import bisect_left
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

A, B, Q = map(int, readline().split())
stx = list(map(int, read().split()))
s = stx[:A]; t = stx[A:-Q]; x = stx[-Q:]
s = [-10 ** 10] + s + [10 ** 11]
t = [-10 ** 10] + t + [10 ** 11]

for i in x:
    ax = bisect_left(s, i)
    bx = bisect_left(t, i)
    pp = max(s[ax], t[bx]) - i
    mm = i - min(s[ax - 1], t[bx - 1])
    pm = min(s[ax] * 2 - i - t[bx - 1], t[bx] * 2 - i - s[ax - 1])
    mp = min(i - s[ax - 1] * 2 + t[bx], i - t[bx - 1] * 2 + s[ax])
    print(min(pp, mm, pm, mp))

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

using namespace std;

int main() {
	string s;
	cin >> s;
	if (s[0] == '0' || s.back() != '0') {
		cout << -1 << endl;
		return 0;
	}
	for (int i = 0; i < s.length() / 2; i++)
		if (s[i] != s[s.length() - i - 2]) {
			cout << -1 << endl;
			return 0;
		}
	s.back()++;
	for (int a = 0, b = 0; b < s.length();) {
		if (a == b || s[b] == '0') {
			b++;
			continue;
		}
		cout << a + 1 << ' ' << b + 1 << '\n';
		a++;
	}
	cout << flush;
	return 0;
}


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

#define froop1(a,n) for(int i = a;i < n;i++)
#define froop2(a,n) for(int i = a;i > n;i--)

#define ll long long

#define pq(name,type) priority_queue<type> name
#define vec(name,type,length,value) vector<type> name(length,value)
#define vec2(name,type,length,width,value) vector<vector<type>> name(length,vector<type>(width,value));

int main(){
	string N1,N2;
  cin >> N1 >> N2;
 int n1 = N1.length();
 int n2 = N2.length();
  vector<int> c1(26,0);
  vector<int> c2(26,0);
  froop1(0,n1){
   int a = N1[i] - 'a';
    c1.at(a)++;
  }
  froop1(0,n2){
    int a = N2[i] - 'a';
    c2.at(a)++;
  }
  string s = "",t = "";
  froop1(0,26){
    for(int j = 0;j < c1.at(i);j++){
     s += 'a' + i; 
    }
  }
  froop2(25,-1){
    for(int j = 0;j < c2.at(i);j++){
     t += 'a' + i; 
    }
  }

	froop1(0,min(n1,n2)){
     if(s[i] - t[i] < 0){
       cout << "Yes" << endl;
       return 0;
     }else if(s[i] - t[i] > 0){
       cout << "No" << endl;
       return 0;
     }
    }
  if(n1 < n2){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
return 0;
}

Measured memory_bytes: 3628
n,k = map(int,input().split())
a = list(map(int,input().split()))
ans = 1

po_a = 1
po_b = 1
flag = 0

while flag != 2:
    if flag == 0:
        po_a = a[po_a-1]
        po_b = a[po_b-1]
        po_b = a[po_b-1]
        if po_a == po_b:
            flag += 1
            po_b = 1
    else:
        po_a = a[po_a-1]
        po_b = a[po_b-1]
        if po_a == po_b:
            flag += 1

flag = 0
po = po_a
cont_po = 0

while flag != 1:
    po = a[po-1]
    cont_po += 1
    if po == po_a:
        flag = 1

flag = 0
cont_topo = 0
po_temp = 1

if k <= 2*(10**5):
    for i in range(k):
        ans = a[ans-1]
else:
    if po_a != 1:
        while flag != 1:
            ans = a[ans-1]
            cont_topo += 1
            if ans == po_a:
                flag = 1

    k_cont = k-cont_topo
    k_cont = k_cont%cont_po

    for i in range(k_cont):
        ans = a[ans-1]


print(ans)


Measured memory_bytes: 32192
#include<stdio.h>

int main( void ){
	int i, j, k, n, v;
	
	scanf("%d", &n );
	
	int a[n];
	
	for( i = 0; i < n; i++ ){
		scanf("%d", &a[i] );
	}
	
	for( k = 0; k < n; k++ ){
		printf("%d", a[k] );
		if( k != n-1 ){
			printf(" ");
		}
		else{
			printf("\n");
		}
	}
	
	for( i = 1; i <= n-1; i++ ){
		v = a[i];
		j = i - 1;
		
		while( j >= 0 && a[j] > v ){
			a[j+1] = a[j];
			j--;
		}
		
		a[j+1] = v;
		for( k = 0; k < n; k++ ){
			printf("%d", a[k] );
			if( k != n-1 ){
				printf(" ");
			}
			else{
				printf("\n");
			}
		}
	}
	
	return 0;
}


Measured memory_bytes: 2024
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    S_ = SS()
    T = SS()

    len_S = len(S_)
    len_T = len(T)

    # TはS'のなるべく右側にあるべき
    idx = -1
    for i in range(len_S - len_T, -1, -1):
        exists = True
        for j in range(len_T):
            if S_[i+j] != '?' and S_[i+j] != T[j]:
                exists = False
                break
        if exists:
            idx = i
            break

    if idx == -1:
        print('UNRESTORABLE')
    else:
        ans = list(S_)
        for i in range(len_S):
            if S_[i] == '?':
                if idx <= i < idx + len_T:
                    ans[i] = T[i-idx]
                else:
                    ans[i] = 'a'

        print(''.join(ans))

if __name__ == '__main__':
    resolve()


Measured memory_bytes: 9976
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <list>
#include <numeric>
#include <map>
#include <cmath>
#include <string>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
//================================================

int a = 0, b = 0, c, d, n, k = 0;
string s, t;



int main()
{
	cin >> s; int cnt = 0;
	rep(i, 4)
		if (s[i] == '2')cnt++;
	cout << cnt << endl;

	return 0;
}

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

using ll    = long long;
using ull   = unsigned long long;
using veci  = vector<int>;
using vecll = vector<ll>;
#define EPS (1e-7)
#define INF (1e9)
#define PI  (acos(-1))
#define FOR(i,a,b) for(int i = (a);i < (b); ++i)
#define REP(i,n) for(int i= 0;i<(int)(n);++i)
#define pb push_back

veci enum_div(int n){
	veci ret;
	ret.pb(1);
	for(int i=1;i*i<n;i++){
		if(n%i==0){
			ret.pb(i);
			if(i != n/i){ret.pb(n/i);}
		}
	}
	ret.pb(n);
	return ret;
}
int gcb(int a,int b){return ((b == 0)? a : gcb(b,a%b));}
int gcd(int a,int b){return (a*b) / gcb(a,b);}

int main(){
    int a,b,c;
    cin >> a >> b >> c;
    if(a==b){
        cout << c << endl;
        return 0;
    }else if(a==c){
        cout << b << endl;
        return 0;
    }else{
        cout << a << endl;
        return 0;
    }
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <functional>
using namespace std;

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
    int n, k;
    cin >> n >> k;
    long long int sum = k;
    for (int i = 1; i < n; i++) {
        sum *= k-1;
    }
    cout << sum << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#define _v first
#define _t second
using namespace std;
typedef long long ll;
pair<ll,double> q[500010];
int n,L,t,v;
int l=1,r=0;
ll pour,all_water=0;double degree=0;
int main()
{
    scanf("%d%d",&n,&L);
    for (int i=1;i<=n;i++)
    {
        scanf("%d%d",&t,&v);
        while (all_water+v>L)
        {
            pour=min(q[l]._v,all_water+v-L);
            q[l]._v-=pour;
            all_water-=pour;    
            degree-=q[l]._t*pour;
            if (!q[l]._v) l++;
        }
        all_water+=v;degree+=1ll*t*v;
        q[++r]=make_pair(v,t);
        while (l<r&&q[r]._t<q[r-1]._t)
        {
            q[r-1]._t=(q[r]._t*q[r]._v+q[r-1]._t*q[r-1]._v)/(q[r]._v+q[r-1]._v);
            q[r-1]._v+=q[r]._v;r--;
        }
        printf("%.7f\n",degree/L);
    }
}

Measured memory_bytes: 16896
// بِسمِ اللہِ  الرَّحم?نِ  الرَّ حِیم
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define MOD 1000000007
#define ll long long
#define pb push_back
#define all(v) v.begin(),v.end()
#define INF 1e18
#define N 100100
#define PI 3.141592653589793238
typedef pair<ll,ll> pll;
ll power(ll a,ll b)
{
    if(b==1)return a;
    if(b==0)return 1;
    ll temp=power(a,b/2);
    ll ans=temp*temp;
    if(b&1)
        ans*=a;
    return ans;
}
ll power(ll a,ll b,ll p)
{
    a=a%p;
    if(b==1)return a;
    if(b==0)return 1;

    ll temp=power(a,b/2,p);
    ll ans=(temp*temp)%p;
    if(b&1)
        ans=(a*ans)%p;
    return ans%p;
}
ll inv(ll a,ll m)
{
    return power(a,m-2,m);
}
//code begins
void solve(){
    ll a,b,c;cin>>a>>b>>c;
    ll k;cin>>k;
    while(b<=a and k>0)
    {
        b=b*2;
        k--;
    }
    while(c<=b and k>0)
    {
        c=c*2;
        k--;
    }
    if(k>=0 and c>b and b>a)
        cout<<"Yes\n";
    else
        cout<<"No\n";
}
signed main()
{
//    freopen("input.txt","r",stdin);
//    freopen("output.txt","w",stdout);

    ios_base::sync_with_stdio(false);
//    cin.tie(NULL);cout.tie(NULL);

//    ll t;cin>>t;while(t--)
    solve();
    return 0;
}


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

if N<10:
  print(N)
elif 10<=N and N<100:
  print(9)
elif 100<=N and N<1000:
  print(9 + (N-100+1))
elif 1000<=N and N<10000:
  print(909)
elif 10000<=N and N<100000:
  print(909 + (N-10000+1))
else:
  print(90909)

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

#define lp(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) lp(i, 0, n)
#define fi first
#define se second

const int INF = 1 << 28;

typedef pair<int, int> pr;
typedef tuple<int, int, int> tp;

int a_, b_, C_ = ~(1<<31), M_ = (1<<16)-1;
int r_() {
  a_ = 36969 * (a_ & M_) + (a_ >> 16);
  b_ = 18000 * (b_ & M_) + (b_ >> 16);
  return (C_ & ((a_ << 16) + b_)) % 1000000;
}

vector<tp> ps;

int solve()
{
	rep(i, ps.size()) get<1>(ps[i]) *= -1;
	sort(begin(ps), end(ps));
	rep(i, ps.size()) get<1>(ps[i]) *= -1;
	
	vector<set<pr>> sts(ps.size() + 10);
	for (auto &st : sts){
		st.insert(pr(-INF, INF));
		st.insert(pr(INF, -INF));
	}
	
	int res = 0;
	rep(i, ps.size()){
		int x, y, z;
		tie(x, y, z) = ps[i];
		int l = 0, r = ps.size();
		while (l + 1 < r){
			int m = (l + r) / 2;
			auto it = --sts[m].lower_bound(pr(y, -INF));
			if (it->se < z) l = m;
			else r = m;
		}
		if (z <= (--sts[r].lower_bound(pr(y, z)))->se){
			while (true){
				auto it = sts[r].lower_bound(pr(y, z));
				if (it->se < z) break;
				sts[r].erase(it);
			}
			sts[r].insert(pr(y, z));
		}
		res = max(res, r);
	}

	return res;
}

int main()
{
	int m, n;
	while (cin >> m >> n >> a_ >> b_, m + n){
		ps.clear();
		rep(i, m){
			int x, y, z;
			cin >> x >> y >> z;
			ps.emplace_back(x, y, z);
		}
		rep(i, n){
			int x = r_();
			int y = r_();
			int z = r_();
			ps.emplace_back(x, y, z);
		}
		cout << solve() << endl;
	}
}

Measured memory_bytes: 52348