akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<algorithm>
using namespace std;
int K;
long long po[301000];
void Calc2(int L, long long c) {
	if (!L)return;
	int i;
	long long tp = (po[L] - 1) / (K - 1);
	for (i = 1; i <= K; i++) {
		if (c > tp) c -= tp;
		else {
			printf("%d ", i);
			if (c == 1)return;
			Calc2(L - 1, c - 1);
			return;
		}
	}
}
void Calc(int L, int c) {
	if (po[L] < 7e11){
		long long ss = 0;
		int i;
		for (i = 1; i <= L; i++)ss += po[i];
		Calc2(L, (ss + c) / 2);
		return;
	}
	printf("%d ", (K + 1) / 2);
	Calc(L - 1, c - 1);
}
int main() {
	int i, n;
	scanf("%d%d", &K, &n);
	if (K % 2 == 0) {
		printf("%d ", K / 2);
		for (i = 1; i < n; i++)printf("%d ", K);
		printf("\n");
		return 0;
	}
	if (K == 1) {
		for (i = 1; i <= (n+1) / 2; i++)printf("%d ", 1);
		printf("\n");
		return 0;
	}
	po[0] = 1;
	for (i = 1; i <= n+1; i++) {
		po[i] = min(po[i - 1] * K, (long long)1e12);
	}
	Calc(n, n%2);
	printf("\n");
}

Measured memory_bytes: 4608
parseInt(s)=parse(Int,s)
MOD=10^9+7
N,a,b=parseInt.(split(readline()))

function CmbMod(a,b,M)
    A=B=1
    for i in 1:b
        A*=(a-i+1)%M
        B*=invmod(i,M)
        A%=M
        B%=M
    end
    A*B%M
end

print((powermod(2,N,MOD)-1-CmbMod(N,a,MOD)-CmbMod(N,b,MOD)+3MOD)%MOD)

Measured memory_bytes: 170652
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <assert.h>
#include <fstream>
#include <time.h>
#include <map>

using namespace std;

const int MAXN = 100005;

int n,ans,id;
int a[MAXN];
int b[MAXN];
int fa[MAXN];

map<int,int> cnt;
map<int,int> match;

int getroot(int p)
{
	return p == fa[p] ? p : fa[p] = getroot(fa[p]);
}
int main()
{
	std::ios::sync_with_stdio(0);
	cin >> n;
	for (int i = 1;i <= n;i++)
	{
		cin >> a[i];
		a[n + 1] ^= a[i];
	}
	for (int i = 1;i <= n;i++)
	{
		cin >> b[i];
		b[n + 1] ^= b[i];
	}
	for (int i = 1;i <= n + 1;i++)
		if (a[i] != b[i] || i == n + 1)
		{
			cnt[a[i]]++;
			cnt[b[i]]--;
			ans += (i <= n);
		}
	for (map<int,int>::iterator i = cnt.begin();i != cnt.end();i++)
	{
		match[i->first] = ++id;
		if (i->second)
		{
			cout << -1 << endl;
			return 0;
		}
		ans++;
	}
	for (int i = 1;i <= n;i++)
	{
		fa[i] = i;
		a[i] = match[a[i]];
		b[i] = match[b[i]];
	}
	for (int i = 1;i <= n;i++)
		if (a[i] != b[i] && getroot(a[i]) != getroot(b[i]))
		{
			ans--;
			fa[getroot(a[i])] = getroot(b[i]);
		}
	cout << ans - 1 << endl;
	return 0;
}

Measured memory_bytes: 12416
#include<stdio.h>
int main(){
  char s[100];
  int j=0,stack[200],top=0,status;
  
  while(1){
    status=scanf("%s",s);
    if(status==EOF) break;
    if(s[0]=='+'){
      stack[top-2]=stack[top-2]+stack[top-1];
      top--;
    }
      
    else if(s[0]=='-'){
      stack[top-2]=stack[top-2]-stack[top-1];
    top--;
    }
    else if(s[0]=='*'){
      stack[top-2]=stack[top-2]*stack[top-1];
      top--;
    }
    else {
      stack[top]=atoi(&s[0]);
      top++;
    }
    
    
  }
  printf("%d\n",stack[0]);
  return 0;
}
      



Measured memory_bytes: 2104
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task solver = new Task();
        solver.solve(in, out);
        out.close();
    }
    
    static class Task {

        void solve(InputReader in, PrintWriter out) {
            int minB = Integer.MAX_VALUE;
            
            int H = in.nextInt();
            int N = in.nextInt();
            
            int[] A = new int[N];
            int[] B = new int[N];
            for (int i = 0; i < N; ++i) {
                A[i] = in.nextInt();
                B[i] = in.nextInt();
            }
            
            int[] dp = new int[H + 1];
            for (int i = 0; i <= H; ++i) {
                dp[i] = -1;
            }
            dp[0] = 0;
            
            for (int i = 0; i < N; ++i) {
                for (int j = 0; j <= H; ++j) {
                    if (dp[j] >= 0) {
                        if (j + A[i] >= H) {
                            minB = Math.min(minB, dp[j] + B[i]);
                        } else {
                            dp[j + A[i]] = dp[j + A[i]] >= 0 ? Math.min(dp[j + A[i]], dp[j] + B[i]) : dp[j] + B[i];
                        }
                    }
                }
            }
            
            out.println(minB);
        }
    }

    static class InputReader {
        BufferedReader reader;
        StringTokenizer tokenizer;

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

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

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

        int[] nextIntArray(int size) {
            int[] arr = new int[size];
            for (int i = 0; i < size; i++) {
                arr[i] = nextInt();
            }
            return arr;
        }

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

        long[] nextLongArray(int size) {
            long[] arr = new long[size];
            for (int i = 0; i < size; i++) {
                arr[i] = nextLong();
            }
            return arr;
        }
    }
}
    

Measured memory_bytes: 21716
#include<bits/stdc++.h>
using namespace std;
int main()
{
  long long n,k,sum=0;
  cin>>n>>k;
  long long a[n];
  for(int i=0;i<n;i++)
  cin>>a[i];
  sort(a,a+n);
  if(k>n)
    cout<<0;
  else
  {
    for(int i=0;i<n-k;i++)
      sum+=a[i];
    cout<<sum;
  }
  
  
}

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

int main() {
    string a, b;
    cin >> a >> b;
    int s = stoi(a+b);
    for (int i=0; i<400; i++) {
        if (i*i==s) {
            cout << "Yes\n";
            return 0;
        }
        if (i*i>=s) {
            cout << "No\n";
            return 0;
        }
    }
}

Measured memory_bytes: 256
n,m = [int(i) for i in input().split()]
like = {i:True for i in range(1,m+1)}
for i in range(n):
  a = [int(i) for i in input().split()[1:]]
  s = list(like.keys())
  for i in s:
    if i not in a:
      like.pop(i)

print(len(like.keys()))


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main(){
	int N; cin>>N;
	vector<int> A(N);
	for (int i=0; i<N; i++)
		cin>>A[i];
	sort(A.begin(),A.end());
	int M=A.back()-A.front();
	for (int i=1; i<N-1; i++)
		M+=abs(A[i]);
	cout<<M<<endl;
	int x=A.front(), y=A.back();
	for (int i=1; i<N-1; i++) {
		if (A[i]<0) cout<<y<<" "<<A[i], y-=A[i];
		else cout<<x<<" "<<A[i], x-=A[i];
		cout<<"\n";
	}
	cout<<y<<" "<<x<<"\n";
	return 0;
}

Measured memory_bytes: 2304
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e16;
const ll mod = 1000000007;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
int ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}
ll factorial(ll n) {
  if (n == 1) {
    return 1;
  }
  ll ans = factorial(n-1);
  return ans*n;
}
ll gcd(ll a, ll b) {
  if (a < b) {
    ll tmp = a;
    a = b;
    b = tmp;
  }
  ll r = a%b;
  while(r != 0) {
    a = b;
    b = r;
    r = a%b;
  }
  return b;
}
ll lcm(ll a, ll b) {
  return (a/gcd(a, b))*b;
}
bool prime(ll n) {
  if (n == 1) {
    return false;
  } else {
    for (ll i = 2; i <= (ll)pow(n, 0.5); i++) {
      if (n%i == 0) return false;
    }
  }
  return true;
}
ll RepeatSquaring(ll n, ll p, ll m) {
  if (p == 0) return 1;
  if (p%2 == 0) {
    ll t = RepeatSquaring(n, p/2, m);
    return (t*t)%m;
  }
  return (n*RepeatSquaring(n, p-1, m))%m;
}

int main() {
  string s, t;
  cin >> s >> t;
  reverse(s.begin(), s.end());
  reverse(t.begin(), t.end());
  bool tmp = false;
  rep(i, s.size()-(t.size()-1)) {
    bool flag = true;
    rep(j, t.size()) {
      if (s.at(i+j)=='?' || s.at(i+j)==t.at(j)) {
        continue;
      } else {
        flag = false;
      }
    }
    if (flag) {
      rep(j, t.size()) {
        s.at(i+j) = t.at(j);
      }
      tmp = true;
      break;
    }
  }
  if (tmp) {
    reverse(s.begin(), s.end());
    rep(i, s.size()) {
      if (s.at(i) == '?') {
        cout << 'a';
      } else {
        cout << s.at(i);
      }
    }
    cout << endl;
  } else {
    cout << "UNRESTORABLE" << endl;
  }
}

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

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int m = scan.nextInt();

		int[] x = new int[m];

		for(int i = 0; i < m; i++) {
			x[i] = scan.nextInt();
		}
		scan.close();

		Arrays.sort(x);

		int[] d = new int[m]; //座標間の距離のリスト
		for(int i = 1; i < m; i++) {
			d[i] = x[i] - x[i-1];
		}

		Arrays.sort(d);

		int ans = 0;

		for(int i = 0; i < m-n; i++) {
			ans+=d[i+1];
		}

		System.out.println(ans);


	}

}

Measured memory_bytes: 50904
// B.

#include <sstream>
#include <iostream>
#include <vector>

using namespace std;

int main(int argc, char *argv[])
{
	int n;
	cin >> n;
	vector<string> s(n);
	for (int i = 0; i < n; ++i) {
		cin >> s[i];
	}
	int ans = 0;
	for (int i = 0; i < n; ++i) {
		int cnt = 0;
		for (int j = 0; j < n; ++j) {
			for (int k = j + 1; k < n; ++k) {
				cnt += s[j][(k + i) % n] == s[k][(i + j) % n];
			}
		}
		if (cnt == ((n - 1) * n) / 2) {
			ans += n;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep2(i, m, n) for(int i=int(m); i<int(n); i++)
#define rep(i, n) rep2(i, 0, n)
#define all(a) a.begin(), a.end()
using ll = long long;
using ld = long double;
using V = vector<int>;
using Vll = vector<ll>;
using Vld = vector<ld>;
using VV = vector<V>;
using VVll = vector<Vll>;
using VVld = vector<Vld>;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
using Pld = pair<ld, ld>;
const int INF = 1<<30;
const ll INFll = 1ll<<62;
const ld EPS = 1e-10;
const int MOD = int(1e9)+7;
template<typename T> inline bool chmin(T& a, T b) {if(a>b) {a=b; return true;} return false;}
template<typename T> inline bool chmax(T& a, T b) {if(a<b) {a=b; return true;} return false;}


struct UnionFind {
  vector<int> d;
  UnionFind(int n=0): d(n, -1) {}
  int find(int x) {
    if (d[x] < 0) return x;
    return d[x] = find(d[x]);
  }
  bool unite(int x, int y) {
    x = find(x); y = find(y);
    if (x == y) return false;
    if (d[x] > d[y]) swap(x, y);
    d[x] += d[y];
    d[y] = x;
    return true;
  }
  bool same(int x, int y) { return find(x) == find(y);}
  int size(int x) { return -d[find(x)];}
};


int main() {
  ll N, M; cin >> N >> M;
  V a(M), b(M);
  rep(i, M) {
    int x, y; cin >> x >> y;
    x--; y--;
    a[i] = x; b[i] = y;
  }

  UnionFind uf(N);
  Vll ans(M+1);
  ans[M] = N*(N-1)/2;

  for (int i = M-1; i >= 0; i--) {
    if (uf.same(a[i], b[i])) {
      ans[i] = ans[i+1];
      continue;
    }
    ll x = uf.size(a[i]);
    ll y = uf.size(b[i]);
    ans[i] = ans[i+1] - x * y;
    uf.unite(a[i], b[i]);
  }

  rep(i, M) cout << ans[i+1] << endl;
  return 0;
}


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

using namespace std;

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

#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back
#define INF 999999999

int n,m;
int pass[200][200];

int d[200][3];
bool used[200][3];

int dijk(int s){
    rep(i,200)rep(j,3)d[i][j]=INF;
    rep(i,200)rep(j,3)used[i][j]=false;
    
    d[0][2]=0;
    while(1){
        int v=-1;
        int w=-1;
        rep(u,n){
            rep(i,3){
                if(!used[u][i]&&(v==-1||d[u][i]<d[v][w])){v=u,w=i;}
            }
        }
        if(v==-1)break;
        
        used[v][w]=true;
        rep(u,n){
//            cout<<u<<" "<<v<<" "<<w<<endl;
            if(w==2){
                d[u][2] = min( d[u][2] , d[v][w]+pass[v][u] );
//                cout<<"d["<<u<<"][2]="<<d[u][2]<<endl;
                if(v!=u && pass[u][v]!=INF){
                    d[u][1] = min( d[u][1] , d[v][w] );
//                    cout<<"d["<<u<<"][1]="<<d[u][1]<<endl;
                }
            }
            else if(w==1 && v!=u && pass[u][v]!=INF){
                d[u][0] = min( d[u][0] , d[v][w] );
//                cout<<"d["<<u<<"][0]="<<d[u][0]<<endl;
            }
            else if(w==0){
                d[u][0] = min( d[u][0] , d[v][w]+pass[v][u] );
//                cout<<"d["<<u<<"][0]="<<d[u][0]<<endl;

            }
        }
    }
//    cout<<"d["<<n-1<<"]["<<0<<"]="<<d[n-1][0]<<endl;
//    cout<<"d["<<n-1<<"]["<<2<<"]="<<d[n-1][2]<<endl;
    return min( d[n-1][0] , d[n-1][2] );
}


int main(){
    while(cin>>n>>m){
        if(n==0&&m==0)break;
        
        n;
        rep(i,200)rep(j,200)pass[i][j]=INF;
        rep(i,200)pass[i][i]=0;
        rep(i,m){
            int a,b,c;
            cin>>a>>b>>c;
            a--,b--;
            pass[a][b]=c;
            pass[b][a]=c;
//            cout<<"pass["<<a<<"]["<<b<<"]="<<pass[a][b]<<endl;
        }
        
        cout<<dijk(0)<<endl;
    }
}

Measured memory_bytes: 1320
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;

lint N, K;
vector<lint> s;

// 0-indexed interface BIT
template<typename T>
class BIT
{
    vector<T> val;
public:
    BIT(int num)
    {
        val = vector<T>(num+1, 0);
    }
    BIT(vector<T> &init)
    {
        val = vector<T>(init.size()+1, 0);
        for (int i=0; i<init.size(); i++) q_add(i, init[i]);
    }
    void q_add(int pos, T v)
    {
        pos++;
        while (pos < val.size())
        {
            val[pos] += v;
            pos += pos & -pos;
        }
    }
    T q_sum(int pos)
    {
        pos++;
        T res = 0;
        while (pos > 0)
        {
            res += val[pos];
            pos -= pos & -pos;
        }
        return res;
    }
};

int main()
{
    scanf("%lld", &N);
    scanf("%lld\n", &K);
    lint sum = 0;
    s = vector<lint>(N+1, 0LL);

    vector<pair<lint, int> > p;

    for (int i = 0; i <= N; i++)
    {
        lint tmp = K;
        if (i > 0) scanf("%lld", &tmp);
        sum += tmp - K;
        s[i] = sum;
        p.push_back(make_pair(s[i], i));
    }
    sort(p.begin(), p.end());
    for (int i=0; i<=N; i++)
    {
        s[p[i].second] = i; 
    }

    BIT<int> bit(N+1);
    lint res = 0;
    for (int i = 0; i <= N; i++)
    {
        res += bit.q_sum((int)s[i]);
        bit.q_add(s[i], 1);
    }

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


Measured memory_bytes: 7792
fun main(args: Array<String>) {
    val s = readLine()!!
    val t = readLine()!!

    (0..(s.length - 1))
            .map { (s + s).substring(it, it + s.length) }
            .any { it == t }
            .let { println(if (it) "Yes" else "No") }
}

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

int main(void){
    int n,m,i,s,cnt;
    double inf;
    s = 0;
    cnt = 0;
    cin >> n >> m;
    vector<int> a(n);

    for(i=0; i<n; i++){
        cin >> a.at(i);
        s += a.at(i);
    }
    inf = s / (4.0 * m);

    for(i=0; i<n; i++){
        if(a.at(i) >= inf) cnt++;
    }

    if(cnt >= m){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 3608
import sys
from heapq import heapify, heappop, heappush

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N, M = lr()
jobs = [[] for _ in range(M+1)]
for _ in range(N):
    a, b = lr()
    if a > M:
        continue
    jobs[a].append(b)

answer = 0
candidate = []
for i in range(1, M+1):
    for job in jobs[i]:
        heappush(candidate, -job)
    if candidate:
        answer += heappop(candidate)

answer *= -1
print(answer)
# 31

Measured memory_bytes: 63836
from collections import Counter
N=int(input())
L=list(map(int,input().split()))
ke=list(Counter(L).values())
val=list(Counter(L).keys())
ans=0
for i in range(len(val)):
  if val[i]>ke[i]:
    ans+=ke[i]
  else:
    ans+=ke[i]-val[i]
print(ans)

Measured memory_bytes: 23992
package main

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

var sc = bufio.NewScanner(os.Stdin)
var out = bufio.NewWriter(os.Stdout)

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

func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}

func main() {
	buf := make([]byte, 1024*1024)
	sc.Buffer(buf, bufio.MaxScanTokenSize)
	sc.Split(bufio.ScanWords)
	defer out.Flush()

	a, b, c, d := nextInt(), nextInt(), nextInt(), nextInt()

	max := a * c
	if a*d > max {
		max = a * d
	}
	if b*c > max {
		max = b * c
	}
	if b*d > max {
		max = b * d
	}
	fmt.Fprintf(out, "%d\n", max)
}


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

#define REP(i, n) for(int i = 0; i < n; i++)
using namespace std;

int main()
{   
    string n;
    while (cin >> n && (int) (n[0] - '0') != 0) {
        int len = n.size();

        vector<vector<int>> dp(len, vector<int> (11, 0));
        dp[0][(int) (n[0] - '0')] = 1;

        int ans = 0;

        for (int i = 1; i < len; i++) {
            int xi = (int) (n[i] - '0');

            for (int j = 0; j <= 10; j++) {
                dp[i][(10*j+xi)%11] = dp[i-1][j];
            }
            if (xi != 0) dp[i][xi]++;
            ans += dp[i][0];
        }

        cout << ans << endl;
        
    }
}


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

using namespace std;

int main(){
  int n, k, q;
  cin >> n >> k >> q;
  vector<int> p(n, k - q);
  for(int i = 0; i < q; i++){
    int a;
    cin >> a;
    p[a - 1]++;
  }
  
  for(int i = 0; i < n; i++){
    if(p[i] > 0) cout << "Yes" << endl;
    else cout << "No" << endl;
  }
  
  return 0;
}

Measured memory_bytes: 1024
/**
 *    DP
 *    24.04.2020 15:55
**/

#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n, weight, value, total_val = 0;
  long long wmax;
  vector<long long> w, v;
  cin >> n >> wmax;
  for (int i = 0; i < n; i++) {
    cin >> weight >> value;
    w.push_back(weight);
    v.push_back(value);
    total_val += value;
  }
  vector<long long> dp (total_val + 1, 1e18L);
  // dp[j] = minimum weight to obtain value exactly j
  
  dp[0] = 0;
  for (int i = 0; i < n; i++) {
    for (int val = 0; val <= total_val - v[i]; val++) {
      dp[total_val - val] = min(dp[total_val - val], 
                                dp[total_val - val - v[i]] + w[i]);
    }
  }
  int ans = 0;
  for (int i = 0; i <= total_val; i++) {
    if (dp[i] <= wmax) {
      ans = i;
    }
  }
  cout << ans << "\n";
  return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
void solve(){
    ll n,hi=0;
    cin>>n;
    map<string,ll> m;
    for(ll i=0;i<n;i++){
        string s;
        cin>>s;
        if(m.find(s)==m.end())
        m.insert({s,0});
        m[s]++;
        hi=max(hi,m[s]);
    }
    set<string> st;
    for(auto it=m.begin();it!=m.end();it++)
    if(it->second==hi)
    st.insert(it->first);
    for(auto it=st.begin();it!=st.end();it++)
    cout<<(*it)<<endl;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll t;
    t=1;
    for(ll i=0;i<t;i++)
    solve();
}

Measured memory_bytes: 33280
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

const ll MOD = 1e9 + 7;
const ll INF = 1e14;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)

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; }

void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}
//--------------------------------------------------------------------------------//

int main() {
    init();
    ll M, K;
    cin >> M >> K;
    ll N = 1 << M;
    if(K>=N){
        cout << -1 << endl;
        return 0;
    }
    vl ans(2 * N);
    if(M==0){
        rep(i, N)
            ans[i] = ans[2 * N - i - 1] = i;
    }
    else if(M==1){
        if(K==0){
            rep(i, N) ans[i] = ans[2 * N - i - 1] = i;
        }
        else{
            cout << -1 << endl;
            return 0;
        }
    }
    else{
        vl a;
        rep(i, N) if (i != K) a.eb(i);
        ans[0] = K;
        rep(i, N - 1) ans[i+1] = a[i];
        ans[N] = K;
        rep(i, N - 1) ans[2 * N - i - 1] = a[i];
    }
    rep(i, 2 * N) cout << ans[i] << " ";
    cout << endl;
}

Measured memory_bytes: 4080
#include <stdio.h>
int main()
{
  int x,y;
  int hozon;

  scanf("%d%d",&x,&y);

  if(x>y){
    while(x%y!=0){
      hozon = x%y;
      x = y;
      y = hozon;
    }
    printf("%d\n",y);
  }
  if(x== y){
    printf("%d\n",x);
  }

  if(y>x){
    while(y%x!=0){
      hozon = y%x;
      y = x;
      x = hozon;  
    }
    printf("%d\n",x);
  }
  return 0;
}



Measured memory_bytes: 2140
#include <algorithm>
#include <iostream>
//#include <numeric>

using namespace std;
using large = long long;

static large gcd(large x, large y) {
    if (x == y)
        return x;
    else if (x > y)
        return gcd(y, x - y);
    else // x < y
        return gcd(x, y - x);
}

static large lcm(large x, large y) { return y * (x / gcd(x, y)); }

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

    large c_divisible = (b / c) - ((a - 1) / c);
    large d_divisible = (b / d) - ((a - 1) / d);
    large cd = lcm(c, d);
    large cd_divisible = (b / cd) - ((a - 1) / cd);

    large num = (b - a + 1) - (c_divisible + d_divisible - cd_divisible);

    cout << num;
    return 0;
}


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


void solve(long long N, std::string S){
    vector<vector<long long>> dp(N+1, vector<long long>(N+1,0));
    for(int i = N-1;i>-1;--i){
        for(int k = i-1;k>-1;--k){
            if(S[i]==S[k]){
                dp[i][k] = 1 + dp[i+1][k+1];
                // cout<<i<<" "<<k<<" "<<dp[i][k]<<endl;
            }
        }
    }
    long long res = 0;
    for(int i = N-1;i>-1;--i){
        for(int k = i-1;k>-1;--k){
            if(dp[i][k]>res&&i-k>=dp[i][k]){
                res = dp[i][k];
            }
        }
    }
    cout<<res<<endl;
}

// Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    std::string S;
    std::cin >> S;
    solve(N, S);
    return 0;
}


Measured memory_bytes: 197888
#include <cassert>
#include <algorithm>
#include <array>
#include <bitset>
#include <cctype>
#include <cstdint>
#include <cmath>
#include <complex>
#include <chrono>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
#include <random>
#include <memory>
#include <utility>
#include <limits>
 
#define rep(i, a, b) for (long long i = (a); (i) < (b); (i)++)
#define all(i) i.begin(), i.end()
#define debug(...) std::cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

void debug_out(){std::cerr<<std::endl;}

template<typename Head,typename... Tail>
void debug_out(Head h,Tail... t){
  std::cerr<<" "<<h;
  debug_out(t...);
}
 
template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, std::pair<T1, T2> pa) {
  return os << pa.first << " " << pa.second;
}
 
template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (std::size_t  i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}
 
template<typename T1,typename T2>
inline bool chmax(T1& a,T2 b){return a<b && (a=b,true);}
 
template<typename T1,typename T2>
inline bool chmin(T1& a,T2 b){return a>b && (a=b,true);}
 
long long pow_mod(long long a, long long b, long long mod=-1) {
  if(b==0)return 1;
  if ((a == 0)||(mod!=-1&&(a+mod)%mod==0))return 0;
  long long x = 1;
  while (b > 0) {
    if (b & 1)x = (mod!=-1)?(x * a) % mod:x*a;
    a = (mod!=-1)?(a * a) % mod:a*a;
    b >>= 1;
  }
  return x;
}

// const long long MOD = 998244353;
const long long MOD = 1e9 + 7;

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

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

std::vector<std::vector<int>> solve(int n,int max){
  if(n==1){
    std::vector<std::vector<int>> ret;
    rep(i,0,max+1){
      ret.emplace_back(1,i);
    }
    return ret;
  }
  std::vector<std::vector<int>> ret;
  rep(i,0,max+1){
    for(auto&& e:solve(n-1,std::max(max,(int)i+1))){
      e.insert(e.begin(),i);
      ret.emplace_back(e);
    }
  }
  return ret;
}

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

  ll n;
  std::cin>>n;

  for(auto&& e:solve(n,0)){
    rep(i,0,n){
      std::cout<<(char)('a'+e[i]);
    }
    std::cout<<"\n";
  }

  return 0;
}



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

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

    int n;
    cin >> n;

    vector<int> G[n];
    for(int i = 0; i < n; i++){
        int p, k;
        cin >> p >> k;
        for(int j = 0; j < k; j++){
            int a;
            cin >> a;
            G[p - 1].push_back(a - 1);
        }
    }

    vector<int> D(n, 1e9);
    D[0] = 0;
    queue<int> q;
    q.push(0);

    while(!q.empty()){
        int now = q.front();
        q.pop();

        for(int i = 0; i < G[now].size(); i++){
            int to = G[now][i];
            if(D[now] + 1 < D[to]){
                D[to] = D[now] + 1;
                q.push(to);
            }
        }
    }

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

    return 0;
}


Measured memory_bytes: 3224
#include <bits/stdc++.h>
using namespace std;
int main () {
    int n;
    cin >> n;
    vector<string> v(n);
    bool f = 1;
    for (int i = 0; i < n; i++) {
        cin >> v[i];
        if (i) {
            if (v[i-1].back() != v[i].front()) {
                f = 0;
            }
        }
        for (int j = 0; j < i; j++) {
            if (v[j] == v[i]) {
                f = 0;
            }
        }
    }
    if (f) puts("Yes");
    else puts("No");
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
// std::cout << std::setprecision(2) << 3.141; // "3.1"
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <map>
 
using namespace std;
 
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef pair<double, ll> pdlg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef tuple<double, double, double> tddd;
 
static const int giga = pow(10,9);
// double pi = 3.141592653589793238463;
 
int main(void){
  int n;
  cin >> n;
 
  int red = 0, blue = 0;
  for(int i = 0; i < n; i++){
    char temp;
    cin >> temp;
    if(temp == 'R'){
      red++;
    } else {
      blue++;
    }
  }
  if(red > blue){
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
 
  return 0;
}

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

#define MAX_N 100
int L[MAX_N];
int N;

void solve(){
  int sum = 0;
  for(int i = 0; i < 2 * N; i+=2){
    sum += L[i];
  }
  cout << sum << endl;
  return ;
}

int main(){
  cin >> N;
  for (int i = 0; i < 2 * N; ++i){
    cin >> L[i];
  }
  sort(L, L + 2 * N);
  solve();
  return 0;
}


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

int main(int argc, char const *argv[]){
	int a,b;
	int n,cnt = 0;
	std::vector<int> keta(5);
	cin >> a >> b;
	for (int i = a; i <= b ; ++i)
	{
		n = i;
		for (int j = 0; j < 5; ++j)
		{
			keta.at(j) = n % 10;
			n /= 10;
		}
		if(keta.at(0) == keta.at(4) and keta.at(1) == keta.at(3))	++cnt;
	}
	cout << cnt << endl;
	return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#pragma GCC optimize "03"
using namespace std;

#define int long long int
#define pb push_back
#define pii pair<int,int>
#define fi first
#define se second
#define rep(i,a,b) for (int i = a; i < b; ++i)
#define dbg(x) { cerr<<"> "<<#x<<": "<<x<< endl; }
#define dbg2(x,y) { cerr<<"> "<<#x<<": "<<x<<" , "<<#y<<": "<<y<<endl; }
#define dbg3(x,y,z) { cerr<<"> "<<#x<<": "<<x<<" , "<<#y<<": "<<y<<" , "<<#z<<": "<<z<<endl; }
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#ifndef LOCAL
#define endl '\n'
#endif
const int inf = INT_MAX;
const double eps = 0.0000001;
const double PI = acos(-1.0);
const int MOD = 1e9+7;
const int N  = 1e5+5;

int a[N], dp[N];

signed main(){
    #ifdef LOCAL
        freopen("input.txt", "r", stdin);
        //freopen("output.txt", "w", stdout);
    #endif  
    IOS;

    int n;
    cin >> n;
    for (int i = 1; i <= n; i++)
    	cin >> a[i];
    dp[n-1] = abs(a[n] - a[n-1]);
    for (int i = n-2; i >= 1; i--) {
    	dp[i] = min(dp[i+1] + abs(a[i+1] - a[i]), dp[i+2] + abs(a[i+2]-a[i]));
    }
    cout << dp[1];
    return 0;
}

Measured memory_bytes: 1792
#include <iostream>
using namespace std;
int main()
{
	string s,t;
	cin>>s>>t;
	
	int l1=s.size();
	int l2=t.size();
	
	if(l1>l2)
	{
		cout<<"GREATER"<<endl;
	}
	else if(l1<l2)
	{
		cout<<"LESS"<<endl;
	}
	else if(l1==l2)
	{
		if(s[0]>t[0])
		cout<<"GREATER";
		else if(s[0]<t[0])
		cout<<"LESS";
		else if(s[0]==t[0])
		{
			int i=0,cnt=0;
			while(s[i]==t[i])
			{
				i++;
				if(i==l1)
				break;
			}
			if((s[i]-'0')>(t[i]-'0'))
			cout<<"GREATER"<<endl;
			else if((s[i]-'0')<(t[i]-'0'))
			cout<<"LESS"<<endl;
			else if(i==l1)
			cout<<"EQUAL"<<endl;
		}
	}
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
)

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	var N, X int
	scanner.Scan()
	fmt.Sscanf(scanner.Text(), "%d %d", &N, &X)

	ms := make([]int, N)
	for i := 0; i < N; i++ {
		scanner.Scan()
		fmt.Sscanf(scanner.Text(), "%d", &ms[i])
	}

	ans := 0
	for _, m := range ms {
		X = X - m
		ans++
	}

	t := min(ms...)
	ans = ans + X/t
	fmt.Println(ans)
}

func min(ns ...int) int {
	ret := math.MaxInt64
	for _, n := range ns {
		if n < ret {
			ret = n
		}
	}
	return ret
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int main(){
  string s,t="";
  cin >> s;
  for(int i=0; i<s.size(); i++){
    if(s.at(i)=='0') t+="0";
    else if(s.at(i)=='1') t+="1";
    else if(t!="") t.pop_back(); 
  }
  cout << t << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, n) for (ll i = 0; i < n; i++)
#define REPR(i, n) for (ll i = n; i >= 0; i--)
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define FORR(i, m, n) for (ll i = m; i >= n; i--)
#define REPO(i, n) for (ll i = 1; i <= n; i++)
#define ll long long
#define INF (ll)1 << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(), n.end()
#define MOD 1000000007
#define P pair<ll, ll>

ll n, k;
vector<double> s;

bool solve(double index, double key) { //条件判定
    ll cnt = 0;
    REP(i, n){
        cnt += ceil(s[i] / index) - 1;
    }
    if (cnt <= k) return true; //ここに条件を入れる
    else return false;
}

double nibutan(ll key = 0) { //ちゃろー！

    double ng = 0; //最大値ならs.size()
    double ok = 1e11; // 最大値なら0

    REP(i, 300) {
        double mid = (ok + ng) / 2;

        if (solve(mid, key)) ok = mid;
        else ng = mid;
    }
    return ok; //満たさない最大ならng
}
int main() {
    cin >> n >> k;
    s.resize(n);
    REP(i, n){
        cin >> s[i];
    }
    //cout << nibutan() << endl;
    cout << (ll)ceil(nibutan()) << endl;
}

Measured memory_bytes: 4804
char s[9999],t[1001];
main(i,j,m,r){
	scanf("%s",&s);
	for(i=j=0;i<strlen(s);){
		if(s[i]=='e')t[j++]='e',i+=3;
		else t[j++]='c',i+=7;
	}
	t[j]=0;
	for(m=i=0;i<strlen(t);){
		for(j=i+1;j<strlen(t);j++)if(t[j]==t[j-1])break;
		if(m<j-i)m=j-i,r=t[j-1];
		i=j;
	}
	puts(r=='c'?"chicken":"egg");
	exit(0);
}

Measured memory_bytes: 524
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> P;

int main() {
    int i, j, k;
    int n;
    cin >> n;
    vector<int> p(n);
    int cnt = 0;
    for (i = 0; i < n; i++)
        cin >> p[i];
    for (i = 1; i < n - 1; i++) {
        int a = p[i - 1];
        int b = p[i];
        int c = p[i + 1];
        if (a == b && b > c || b == c && b > a) cnt++;
        if (a < b && b < c || c < b && b < a) cnt++;
        if (a == c && b > a) cnt++;
    }
    cout << cnt << endl;
}


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

#define Online 1
// #define multitest 1
#define Debug 1
typedef long long ll;
typedef long double ld;
#define f first
#define s second
#define pb push_back
#define mp make_pair
const long long mod = 1000000007;
void ControlIO();
void TimerStart();
void TimerStop();
#ifdef Debug
#define db(...) ZZ(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void ZZ(const char *name, Arg1 &&arg1)
{
	std::cerr << name << " = " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void ZZ(const char *names, Arg1 &&arg1, Args &&... args)
{
	const char *comma = strchr(names + 1, ',');
	std::cerr.write(names, comma - names) << " = " << arg1;
	ZZ(comma, args...);
}
#else
#define db(...)
#endif

void solve()
{
	int n,m;
	cin >> n >> m;
	vector<int> A(n);
	for(auto &x:A)
		cin >> x;
	sort(A.begin(),A.end());
	vector<pair<int,int>> V(m);
	for(auto &x:V)
		cin >> x.s >> x.f;
	sort(V.begin(),V.end());
	reverse(V.begin(),V.end());
	ll sum = 0;
	int j = 0,jcnt = 0;
	for(int i=0;i<n;++i)
	{
		if(j!=m)
		{
			if(A[i]<V[j].f)
			{
				A[i] = V[j].f;
				V[j].s--;
				if(V[j].s==0) ++j;
			}
		}
		sum += A[i]; 
	}
	cout << sum;
}

int main()
{
	ControlIO();
	int t = 1;
#ifdef multitest
	cin >> t;
#endif
	TimerStart();
	while (t--)
		solve();
	TimerStop();
	return 0;
}

void ControlIO()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
#ifndef Online
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}

auto TimeStart = chrono::steady_clock::now();
auto TimeEnd = chrono::steady_clock::now();

void TimerStart()
{
#ifndef Online
	TimeStart = chrono::steady_clock::now();
#endif
}

void TimerStop()
{
#ifndef Online
	TimeEnd = chrono::steady_clock::now();
	auto ElapsedTime = TimeEnd - TimeStart;
	cout << "\n\nTime elapsed: " << chrono::duration<double>(ElapsedTime).count() << " seconds.\n";
#endif
}

Measured memory_bytes: 1408
n = int(input())
x = input()

# n = 3
# x = "100"

l = 2*10**5 + 5
A = [0] * l
for i in range(1,l):
    ab = format(i, "b")
    abo = ab.count("1")
    A[i] = i % abo

B = [-1] * l
B[0] = 0
# print(A[:10])

def dd(y):
    # print(y)
    if B[y] == -1:
        return dd(A[y])+1
    else:
        return B[y]

for i in range(1, l):
    # print(dd(i))
    B[i] = dd(i)

# print(B[:100])

m = x.count("1")
m0 = m-1
m00 = m0
if m0 == 0:
    m0 = 1

m1 = m+1
M0 = [1]
M1 = [1]
for i in range(l):
    M0.append((M0[-1]*2) % m0)
    M1.append((M1[-1]*2) % m1)

n0 = 0
n1 = 0
for i in range(n):
    if x[n-1-i] == "1":
        n0 = (n0 + M0[i]) % m0
        n1 = (n1 + M1[i]) % m1

for i in range(n):
    nn = 0
    if x[i] == "1":
        nn = (n0 - M0[n-i-1]) % m0
    else:
        nn = (n1 + M1[n-i-1]) % m1
    print(B[nn]+1 if (m00!=0 or x[i]!="1") else 0)



Measured memory_bytes: 100364
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

#素数判定
def is_prime(num):
	if num < 2:
		return False
	if num in [2, 3, 5]:
		return True
	if num%2 == 0 or num%3 == 0 or num%5 == 0:
		return False
	prime = 7
	step = 4
	num_sqrt = sqrt(num)
	while prime <= num_sqrt:
		if num%prime == 0:
			return False
		prime += step
		step = 6 - step
	return True

X = INT()

while 1:
	if is_prime(X):
		print(X)
		break
	else:
		X += 1


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

// template {{{
#define  range(i, l, r) for (int i = (int)(l); i < (int)(r); (i) += 1)
#define rrange(i, l, r) for (int i = (int)(r) - 1; i >= (int)(l); (i) -= 1)

#define  whole(f, x, ...) ([&](decltype((x)) container) { return (f)(  begin(container),  end(container), ## __VA_ARGS__); })(x)
#define rwhole(f, x, ...) ([&](decltype((x)) container) { return (f)( rbegin(container), rend(container), ## __VA_ARGS__); })(x)

#define debug(x) cerr << "(" << __LINE__ << ")" << #x << ": " << (x) << endl

using i32 = int;
using u32 = unsigned int;
using i64 = long long;
using u64 = unsigned long long;

// constexpr i32 mod   = 998244353;
constexpr i32 mod   = 1e9 + 7;
constexpr i32 inf   = 1001001001;
constexpr i64 infll = 1001001001001001001ll;

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

struct IoSetup { IoSetup(int x = 15){ cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(x); cerr << fixed << setprecision(x); } } iosetup;

template <typename T = i64> T input() { T x; cin >> x; return x; }

template <typename T> ostream &operator<<(ostream &os, vector<T> &v) { range(i, 0, v.size()) { os << v[i] << (i + 1 != v.size() ? " " : ""); } return os; }
template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &in : v) is >> in; return is; }

template <typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
template <typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; }

template <typename T> vector<T> make_vector(size_t a, T b) { return vector<T>(a, b); }
template <typename... Ts> auto make_vector(size_t a, Ts... ts) { return vector<decltype(make_vector(ts...))>(a, make_vector(ts...)); }

template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
// }}}

void solver() {
    int n = input();
    vector< int > x(n);
    cin >> x;

    int ans = inf;
    range(p, 0, 101) {
        int sum = 0;
        for (auto a: x) sum += (a - p) * (a - p);
        chmin(ans, sum);
    }

    cout << ans << endl;
}

signed main(int argc, char *argv[]) {
    solver();
}


Measured memory_bytes: 3628
#include<iostream>
#include<cstdio>
#include<stack>

using namespace std;

int n,a[300000],s[300000];

int main(void){
	scanf("%d",&n);
	for(int i=0;i<n;i++)scanf("%d",&a[i]);
	int cnt=0,sn=0;
	for(int i=0;i<n;i++){
		if(sn==0 || s[sn-1]<a[i]){
			s[sn++]=a[i];
			cnt++;
		}else if(s[sn-1]==a[i])continue;
		else{
			while(sn>0 && s[sn-1]>a[i])sn--;
			if(sn==0 || s[sn-1]<a[i]){
				s[sn++]=a[i];
				cnt++;
			}
		}
	}
	printf("%d\n",cnt);
	return 0;
}


Measured memory_bytes: 4712
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
typedef long long LL;
int N;

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

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using Pld = pair<ld, ld>;
using Vec = vector<ll>;
using VecP = vector<P>;
using VecB = vector<bool>;
using VecC = vector<char>;
using VecD = vector<ld>;
using VecS = vector<string>;
using Graph = vector<VecP>;
template <typename T>
using Vec1 = vector<T>;
template <typename T>
using Vec2 = vector<Vec1<T> >;
#define REP(i, m, n) for(ll i = (m); i < (n); ++i)
#define REPN(i, m, n) for(ll i = (m); i <= (n); ++i)
#define REPR(i, m, n) for(ll i = (m)-1; i >= (n); --i)
#define REPNR(i, m, n) for(ll i = (m); i >= (n); --i)
#define rep(i, n) REP(i, 0, n)
#define repn(i, n) REPN(i, 1, n)
#define repr(i, n) REPR(i, n, 0)
#define repnr(i, n) REPNR(i, n, 1)
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define fs first
#define sc second
template <typename T>
bool chmax(T &a, const T b){if(a < b){a = b; return true;} return false;}
template <typename T>
bool chmin(T &a, const T b){if(a > b){a = b; return true;} return false;}
template <typename T>
ll pow2(const T n){return (1LL << n);}
template <typename T>
void cosp(const T n){cout << n << ' ';}
void co(void){cout << '\n';}
template <typename T>
void co(const T n){cout << n << '\n';}
template <typename T1, typename T2>
void co(pair<T1, T2> p){cout << p.fs << ' ' << p.sc << '\n';}
template <typename T>
void co(const Vec1<T> &v){for(T i : v) cosp(i); co();}
template <typename T>
void co(initializer_list<T> v){for(T i : v) cosp(i); co();}
template <typename T>
void ce(const T n){cerr << n << endl;}
void sonic(){ios::sync_with_stdio(false); cin.tie(0);}
void setp(const ll n){cout << fixed << setprecision(n);}
constexpr int INF = 1e9+1;
constexpr ll LINF = 1e18+1;
constexpr ll MOD = 1e9+7;
// constexpr ll MOD = 998244353;
constexpr ld EPS = 1e-11;
const ld PI = acos(-1);

int main(void){
	ll n;
	cin >> n;
	Vec cnt(4);
	VecS s = {"AC", "WA", "TLE", "RE"};
	rep(i, n){
		string in;
		cin >> in;
		rep(j, 4) if (s[j] == in) cnt[j]++;
	}

	rep(i, 4) cout << s[i] << " x " << cnt[i] << endl;

	return 0;
}


Measured memory_bytes: 3596
from sys import stdin

def binarySearch(target:list, value):
    left = 0
    right = len(target)
    while left < right:
        mid = int((left + right) / 2)
        if target[mid] == value:
            return True
        elif target[mid] > value:
            right = mid
        else:
            left = mid + 1
    return False

def main():
    n = stdin.readline()
    s = list(map(int, stdin.readline().split()))
    q = stdin.readline()
    t = list(map(int, stdin.readline().split()))
    print(sum([1 for v in t if binarySearch(s, v)]))
        
main()


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

int main()
{
	int N, M;
	cin >> N >> M;
	vector<vector<int>> V(3 * N);
	for (int i = 0; i < M; i++) {
		int s, e;
		cin >> s >> e;
		s--, e--;
		V[s].push_back(e + N);
		V[s + N].push_back(e + 2*N);
		V[s + 2 * N].push_back(e);

	}
	int s, t;
	cin >> s >> t;
	s--, t--;
	queue<int> Q;
	vector<int>dist(3 * N,-1);
	dist[s] = 0;
	Q.push(s);
	while (!Q.empty()) {
		int here = Q.front();
		Q.pop();
		for (int i = 0; i < V[here].size(); i++) {
			int next = V[here][i];
			if (dist[next] == -1) {
				dist[next] = dist[here] + 1;
				Q.push(next);
			}
		}
	}
	if (dist[t] == -1)cout << -1;
	else
		cout << dist[t] / 3;
	
	
}

Measured memory_bytes: 17792
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def TUPLE(): return tuple(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7 
#mod = 998244353
from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10

N, K = MAP()
A = LIST()

def is_OK(X):
	cnt = 0
	for a in A:
		cnt += (a-0.1)//X
		if K < cnt:
			return False
	else:
		return True

l = 0
r = max(A)

while l != r-1:
	m = (r+l)//2
	if is_OK(m):
		r = m
	else:
		l = m

print(r)


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

int mycal(int ty,int tm,int td){
	int y=1,m=1,d=1;
	int ret = 0;
	while(1){
		bool isBigMonth = y%3==0 || m%2;
		if(d > 20 - !isBigMonth){
			m++;
			d=1;
		}
		if(m > 10){
			y++;
			m=1;
		}
		if(y == ty && m == tm && d == td){
			return ret;
		}
		d++;
		ret++;
	}
}

int main() {
	int n;
	cin >> n;
	for(int i=0;i<n;i++){
		int y,m,d;
		cin >> y >> m >> d;
		cout << mycal(1000,1,1) - mycal(y,m,d) << endl;
	}
	return 0;
}

Measured memory_bytes: 3092
import math
import sys
readline = sys.stdin.readline


def main():
    n = int(input())
    A = list(map(int, input().split()))
    cnt = 0
    for i in range(n - 1):
        if A[i + 1] == A[i]:
            cnt += 1
            A[i + 1] = "s" + str(i + 1)
    print(cnt)


if __name__ == '__main__':
    main()


Measured memory_bytes: 9052
io = STDIN
n=io.gets.to_i
ar=io.gets.split.map(&:to_i).sort_by{|i|-i}
pool=[]
cnt=0
ar.each_with_index do |a,i|
  if i==0
    pool << a
  else
    item = pool.shift
    cnt += item
    pool << a
    pool << a
  end
end
puts cnt


Measured memory_bytes: 34164
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <numeric>
#include <cassert>
#include <cmath>
#include <unordered_map>
#include <unordered_set>

//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//typedef tree<int, null_type, std::less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
// Там еще некоторые особенности есть. Подробнее https://codeforces.com/blog/entry/11080?locale=ru

using namespace std;
using ld = long double;
using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vi>;
using vvll = vector<vll>;

#define endl '\n'
#define all(x) (x).begin(),(x).end()
#define len(x) (int)(x).size()
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

const ll mod = (ll) 1e9 + 7;

ll binpowmod(ll a, ll n) {
    ll res = 1;

    while (n > 0) {
        if (n & 1) {
            res *= a;
            res %= mod;
        }
        n >>= 1ll;
        a *= a;
        a %= mod;
    }

    return res % mod;
}

ll inv(ll a) {
    return binpowmod(a, mod - 2);
}

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

    ll fact = 1;
    for (ll i = 2; i <= n - 1; i++) {
        fact *= i;
        fact %= mod;
    }

    vll a(n + 1);
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }

    vll inversed(n + 1, 1);
    for (ll i = 2; i <= n; i++) {
        inversed[i] = inv(i);
    }
    for (int i = 2; i <= n; i++) {
        inversed[i] += inversed[i - 1];
        inversed[i] %= mod;
    }

    ll ans = 0;

    for (ll i = 1; i <= n - 1; i++) {
        ll d = (a[i + 1] - a[i]) % mod;
        ans += d * inversed[i];
        ans %= mod;
    }

    cout << (ans * fact) % mod;

    return 0;
}

Measured memory_bytes: 1792