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

unordered_set<int> x_dp[8000],y_dp[8000];
vector<int> x_move,y_move;

int main() {

    string s;

    cin >> s;

    bool is_x = true;

    int count = 0;

    s.push_back('T');

    for(int i=0; i<s.size(); i++){
        if(s[i] == 'T'){
            if (is_x) {
                x_move.push_back(count);
            } else {//!is_x
                y_move.push_back(count);
            }
            count = 0;
            is_x = !is_x;
        }
        else{//s[i] == 'F'
            count++;
        }
    }

    if (is_x) {
        x_move.push_back(count);
    } else {//!is_x
        y_move.push_back(count);
    }

    if(s[0] == 'F' && x_move.size() != 0){
        x_dp[0].insert(x_move[0]);
    }
    else if(x_move.size() != 0){
        x_dp[0].insert(x_move[0]);
        x_dp[0].insert(-x_move[0]);
    }

    if(y_move.size() != 0){
        y_dp[0].insert(y_move[0]);
        y_dp[0].insert(-y_move[0]);
    }

    for(int i=1; i<x_move.size(); i++){
        for(auto itr_num : x_dp[i-1]){
            x_dp[i].insert(itr_num + x_move[i]);
            x_dp[i].insert(itr_num - x_move[i]);
        }
    }

    for(int i=1; i<y_move.size(); i++){
        for(auto itr_num : y_dp[i-1]){
            y_dp[i].insert(itr_num + y_move[i]);
            y_dp[i].insert(itr_num - y_move[i]);
        }
    }

    int goal_x,goal_y;

    cin >> goal_x >> goal_y;

    string ans = "No";

    if(x_dp[x_move.size()-1].find(goal_x) != x_dp[x_move.size()-1].end() && y_dp[y_move.size()-1].find(goal_y) != y_dp[y_move.size()-1].end()){
        ans = "Yes";
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 205312
#include<bits/stdc++.h>
#define ll long long 
#define pb push_back
#define mod 1000000007
#define all(v) v.begin(),v.end()
#define MP make_pair
#define F first
#define S second
#define inf 10000000000000
#define vll vector<ll>
using namespace std;
const int N=200005;
ll par[N],xx,u[N],v[N];
ll root(ll x)
{
	return (par[x]<0)?x:(par[x]=root(par[x]));
}
void join(ll x,ll y)
{
	x=root(x);
	y=root(y);
	if(x==y)
		return;
	xx-=par[x]*par[y];
	par[x]+=par[y];
	par[y]=x;

}
void solve()
{
	ll n,m,i,ans[N];
	cin>>n>>m;
	memset(par,-1,sizeof par);
	for(i=1;i<=m;i++)
	{
		cin>>u[i]>>v[i];
	}
	ans[m]=n*(n-1)/2;
	xx=ans[m];
	for(i=m;i>=1;i--)
	{
		ans[i]=xx;
		join(u[i],v[i]);
	}
	for(i=1;i<=m;i++)
		cout<<ans[i]<<"\n";

	
}
 
int main() {
    
    ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	
    ll t=1;
    //cin>>t;
    while(t--)
        solve();
 
    
    return 0;
}

Measured memory_bytes: 6016
package main

import (
	"fmt"
	"math"
)

func main() {
	var n int
	fmt.Scan(&n)
	np := sliceInt(n)
	if np[0] == 7 || np[1] == 7 || np[2] == 7 {
		fmt.Println("Yes")
		return
	}
	fmt.Println("No")
}

//-------------------------------------------
// util tools

// abs 絶対値を返す
func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

// sliceInt []intをスライスする
func sliceInt(k int) []int {
	s := make([]int, getDigit(k))
	count := 0
	for k > 0 {
		i := k % 10
		s[len(s)-1-count] = i
		count++
		k = k / 10
	}
	return s
}

// sliceIntSum []intの合計を出す
func sliceIntSum(v []int) int {
	sum := 0
	for _, x := range v {
		sum += x
	}
	return sum
}

// reverse []intを反転
func reverse(s []int) []int {
	for i, j := 0, len(s)-1; i < j; i, j = i+1, j-1 {
		s[i], s[j] = s[j], s[i]
	}
	return s
}

// getDigit intの桁数を取得
func getDigit(num int) int {
	digit := 0
	for num != 0 {
		num /= 10
		digit++
	}
	return digit
}

// getSumDigit intの各位の和を返す
func getSumDigit(num int) int {
	sum := 0
	for num != 0 {
		t := num % 10
		num /= 10
		sum += t
	}
	return sum
}

// lastPrime 素数 エラトステネスの篩
func lastPrime(max int64) int64 {
	if max <= 1 {
		return 2
	}
	primes := make([]int64, 1, max)
	primesF := make([]float64, 1, max)
	primes[0] = 2
	primesF[0] = 2.0

	count := int64(1)
	for n := int64(3); ; n += 2 {
		flag := true
		f := float64(n)
		rf := math.Sqrt(f)
		for i := 1; i < len(primes); i++ {
			if primesF[i] > rf {
				break
			} else if (n % primes[i]) == 0 {
				flag = false
				break
			}
		}
		if flag {
			count++
			if count >= max {
				return n
			}
			primes = append(primes, n)
			primesF = append(primesF, f)
		}
	}
}


Measured memory_bytes: 1756
N=int(input())
A = [int(a) for a in input().split()]

d = {}
for a in A:
  d[a] = d.get(a,0) + 1
B = [0,0]
for k in d:
  if d[k] >= 4:
    B.append(k)
    B.append(k)
  elif d[k] >=2:
    B.append(k)
B.sort()
print(B[-1]*B[-2])

Measured memory_bytes: 17960
#include <iostream>

using namespace std;

void solve()
{
	int n;
	while(cin >> n, n)
	{
		int count = 0;
		while(true)
		{
			if(n == 1)
			{
				break;
			}
			if(n % 2)
			{
				n = 3 * n + 1;
			}
			else
			{
				n /= 2;
			}
			++count;
		}
		cout << count << endl;
	}
}

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

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

int main() {
	int N;
	cin >> N;
	vector<ll> A(N);
	rep(i, N) cin >> A[i];

	ll ans = 0;
	sort(A.begin(), A.end(), greater<ll>());
	rep(i, (N - 1)) {
		ans += A[i / 2 + i % 2];
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 4824
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define ll long long
int main(){
  int H,W;
  cin>>H>>W;
  string S[H];
  rep(i,H) cin>>S[i];
  int X[H][W]={},Y[H][W]={};
  rep(i,H) rep(j,W){
    int A;
    if(j==0) A=0;
    if(S[i][j]=='.') A++;
    else{
      if(j-1>=0) X[i][j-1]=A;
      A=0;
    }
    if(j==W-1) X[i][j]+=A;
  }
  rep(i,H) rep(j,W){
    int A;
    if(j==0) A=0;
    if(S[i][W-1-j]=='.'&&X[i][W-1-j]!=0) A=X[i][W-1-j];
    else if(S[i][W-1-j]=='.') X[i][W-1-j]=A;
  }
  rep(j,W) rep(i,H){
    int A;
    if(i==0) A=0;
    if(S[i][j]=='.') A++;
    else{
      if(i-1>=0) Y[i-1][j]=A;
      A=0;
    }
    if(i==H-1) Y[i][j]+=A;
  }
  rep(j,W) rep(i,H){
    int A;
    if(i==0) A=0;
    if(S[H-1-i][j]=='.'&&Y[H-1-i][j]!=0) A=Y[H-1-i][j];
    else if(S[H-1-i][j]=='.') Y[H-1-i][j]=A;
  }
  rep(i,H) rep(j,W) X[i][j]+=Y[i][j];
  rep(i,H) sort(X[i],X[i]+W);
  int Z[H];
  rep(i,H) Z[i]=X[i][W-1];
  sort(Z,Z+H);
  cout<<Z[H-1]-1<<endl;
}

Measured memory_bytes: 35584
#include <bits/stdc++.h>
//#define DEBUG

using namespace std;
int n, a[200010];
struct node {
    int id, point;
} node[1<<21];

void add(int id, int x)
{
    id=n-1+id;
    node[id].point+=x;

    while (id>0) {
        id=(id-1)/2;
        int c1=2*id+1, c2=2*id+2;
        if (node[c1].point>=node[c2].point)
            node[id]=node[c1];
        else
            node[id]=node[c2];
    }
}

void print()
{
#ifdef DEBUG
    int k=1;
    int x=0;
    while (true) {
        for(int i=0;i<k;++i) printf("(%d %d)", node[x+i].id, node[x+i].point);
        puts("");
        x+=k;
        k<<=1;
        if (x>=n) break;
    }
    puts("");
#endif
}

int main()
{
    int m, r, l;
    scanf("%d%d%d", &m, &r, &l);
    n=1;
    while (n<m) n<<=1;
    for(int i=0;i<m;++i) node[n-1+i].id=i;

    int pt=0;
    for(int i=0;i<r;++i) {
        int d, t, x;
        scanf("%d%d%d", &d, &t, &x);

        if (pt<t) {
            int id=node[0].id;
            a[id]+=t-pt;
        }
        add(d-1, x);
        print();
        pt=t;
    }
    print();
    a[node[0].id]+=l-pt;
#ifdef DEBUG
    for(int i=0;i<n;++i) printf("%d ", a[i]); puts("");
#endif
    printf("%d\n", 1+(max_element(a, a+n)-a));
}

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

P v1[200], v2[200];
bool used1[200], used2[200];
int main() {
	int n;
	while (scanf("%d", &n), n) {
		memset(used1, 0, sizeof(used1));
		memset(used2, 0, sizeof(used2));
		rep(i, n) {
			int h, r; scanf("%d%d", &h, &r);
			v1[i] = P(h, r);
		}
		int m; scanf("%d", &m);
		rep(i, m) {
			int h, r; scanf("%d%d", &h, &r);
			v2[i] = P(h, r);
		}
		sort(v1, v1 + n);
		sort(v2, v2 + m);
		v1[n] = v2[m] = P(2000, 2000);
		int cnt1 = 0;
		rep(i, n + 1) {
			rep(j, m) {
				if ((!i || (v1[i - 1].first < v2[j].first&&v1[i - 1].second < v2[j].second)) &&
					v2[j].first < v1[i].first&&v2[j].second < v1[i].second && !used1[j]) {
					used1[j] = true;
					cnt1++;
				}
			}
		}
		int cnt2 = 0;
		rep(i, m + 1) {
			rep(j, n) {
				if ((!i || (v2[i - 1].first < v1[j].first&&v2[i - 1].second < v1[j].second)) &&
					v1[j].first < v2[i].first&&v1[j].second < v2[i].second && !used2[j]) {
					used2[j] = true;
					cnt2++;
				}
			}
		}
		printf("%d\n", max(cnt1 + n, cnt2 + m));
	}
}

Measured memory_bytes: 3160
def main():
    n, k = map(int, input().split(" "))
    monster = [int(s) for s in input().split(" ")]
    monster.sort(reverse=True)
    attack = 0
    for i in range(k, n):
        attack += monster[i]
    print(attack)


if __name__ == '__main__':
    main()


Measured memory_bytes: 26764
#include <iostream>

int main(){
    while(true){
        int n;
        std::cin >> n;
        
        if(n == 0) {
            break;
        }
        
        n = 1000 - n;
        
        int count = 0;
        
        count += n / 500;
        n %= 500;
        count += n / 100;
        n %= 100;
        count += n / 50;
        n %= 50;
        count += n / 10;
        n %= 10;
        count += n / 5;
        n %= 5;
        count += n / 1;
        n %= 1;
    
        std::cout << count << std::endl;
    }
}

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

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author dyominov
 */
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);
        ALibra solver = new ALibra();
        solver.solve(1, in, out);
        out.close();
    }

    static class ALibra {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int a = in.nextInt() + in.nextInt();
            int b = in.nextInt() + in.nextInt();
            out.print(a == b ? "Balanced" : a > b ? "Left" : "Right");
        }

    }

    static class InputReader implements AutoCloseable {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

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

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

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

        public void close() {
        }

    }
}



Measured memory_bytes: 21460
#include <iostream>
#include <queue>
#include <vector>
#include<algorithm>
#include <string.h>
using namespace std;

int maxn;
int kv,tv;
int kc;
vector<int> tc;

int dp[101][101];

int main(void)
{
	cin >> maxn;
	cin >> kv >> tv;
	cin >> kc;
	for(int i=0;i<maxn;++i){
		int a; cin >> a;
		tc.push_back(a);
	}
	memset(dp,-1,sizeof(dp));
	dp[0][0] = 0;
	for(int t=0;t<tc.size();++t)//なにをトッピングする?
	{
		for(int i=0;i<101;++i){
			int now = t;
			if(dp[now][i] == -1) continue;
			if(dp[now+1][i] < dp[now][i])
				dp[now+1][i] = dp[now][i];
			if(dp[now+1][i+1] < dp[now][i]+tc[t])
				dp[now+1][i+1] = dp[now][i]+tc[t];
		}
	}
	double max=-1;
	int d = tc.size();
	for(int i=0;i<101;++i){
		if(max < (double)(kc+dp[d][i])/(double)(i*tv+kv))
			max = (double)(kc+dp[d][i])/(double)(i*tv+kv);
	}
	cout << (int)max << endl;
	return 0;
}

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

using namespace std;

#ifdef DEBUG_MODE
	#define DBG(n) n;
#else
	#define DBG(n) ;
#endif
#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define rep(i,s,g) for(ll (i) = (s);(i) < (g);++i)
#define rrep(i,s,g) for(ll (i) = (s);i >= (g);--(i))
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int W = 0;W < (n);W++)cerr << v[W] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define MOD 1000000007

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

struct UF
{
	vector<int> par; // 親のインデックスを記憶する配列
	vector<int> sz; // サイズを記憶する。
	vector<int> rank;
	// 初期化
	UF(int n):par(n),sz(n),rank(n){
		for(int i = 0; i < n; i++){
			par[i] = i;sz[i] = 1;rank[i] = 0;
		}
	}
	// 親を求める
	int find(int x) {
		if (par[x] == x) return x;
		else return par[x] = find(par[x]);
	}
	// xとyの属する集合を併合
	void unite(int x, int y) {
		x = find(x); y = find(y);
		if (x == y) return;
		if(rank[x] < rank[y]){
			par[x] = y;
			sz[y] += sz[x];
		}
		else{
			par[y] = x;
			sz[x] += sz[y];
			if(rank[x] == rank[y])rank[x]++;
		}
	}
	// xとyが同じ集合ならtrue
	bool same(int x, int y) { return find(x) == find(y); }
	// 素の集合のサイズを求める
	int size(int n){return sz[find(n)];}
};


int main(){
	int n,m;
	cin >> n >> m;
	vector<int> v(n);
	for(int i = 0;i < n;i++){
		cin >> v[i];v[i]--;
	}
	
	UF uf(n);
	
	for(int i = 0;i < m;i++){
		int x,y;cin >> x >> y;
		x--;y--;
		uf.unite(x,y);
	}
	
	int ans = 0;
	
	for(int i = 0;i < n;i++){
		if(uf.same(i,v[i]))ans++;
	}
	
	cout << ans << endl;
		
	return 0;
}

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

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
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 { return mint(*this) += a; }
	mint operator-(const mint a) const { return mint(*this) -= a; }
	mint operator*(const mint a) const { return mint(*this) *= 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 { return mint(*this) /= a; }
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x; }
ostream& operator<<(ostream& os, const mint& a) { return os << a.x; }


int main() {
	int N;
	string S1, S2;
	cin >> N >> S1 >> S2;
	mint ans = 0;
	vector<int>X;
	for (int k = 0; k < S1.size(); ++k) {
		if (S1[k] ==S2[k]) {
			X.push_back(1);
		}
		else {
			X.push_back(0);
			++k;
		}
	}
	for (int i = 0;i<X.size();++i) {
		if (0 ==i) {
			if (1 == X[i]) {
				ans = 3;
			}
			else {
				ans = 6;
			}
		}
		else {
			if (1 == X[i]) {
				if (1== X[i-1]) {
					ans *= 2;
				}
				else {
					ans *= 1;
				}
			}
			else {
				if (1 == X[i - 1]) {
					ans *= 2;
				}
				else {
					ans *= 3;
				}
			}
		}
	}
	cout << ans <<endl;
	return 0;
}


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

using namespace std;

int main()
{
  int n,a,cnt=0;
  cin>>n;
  vector<int>v;
  for(int i=0;i<n;i++)
  {
      cin>>a;
      v.push_back(a);
  }
  sort(v.begin(),v.end(),greater<int>());
  for(int i=0;i<n;i++)
  {
      for(int j=i+1;j<n;j++)
      {
          for(int k=j+1;k<n;k++)
          {
              if(v[i]<v[j]+v[k] && v[j]<v[k]+v[i] && v[k]<v[i]+v[j])cnt++;
              else continue;
          }
      }
  }
  cout<<cnt<<endl;

    return 0;
}


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

using namespace std;

#define REP(i,n) for(ll (i) = (0); (i) < (n); ++i)
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define ALL(v) v.begin(),v.end()
#define INF 1100000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007
#define Decimal fixed << setpresicion(20)
#define SHOWP(x) cerr<<"("<<(x).FI<<", "<<(x).SE<<") ";
#define SHOWX(x) cerr<<#x<<": "<<x<<endl;
#define SHOWVEC(v, e) REP(i, e) cerr << (v[i]) << ' '; cerr << endl;
#define SHOW2D(a, h, w) REP(i, h){REP(j, w)cerr<<setw(3)<<(a[i][j])<<' ';cerr<<endl;}

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

ll N, A, B, C;
bool check(vector<ll>& h, ll n)
{
  vector<ll> tv;
  REP(i, N) {
    ll tmp = h[i] - B*n;
    if (tmp > 0) tv.PB(tmp);
  }
  ll cnt = 0;
  REP(i, tv.size()) {
    cnt += (tv[i] + C - 1) / C;
  }
  return cnt <= n;
}

int main()
{
  cin >> N >> A >> B;
  C = A - B;
  vector<ll> h(N);
  REP(i, N) cin >> h[i];

  ll lb = -1, ub = INF;
  while (ub - lb > 1) {
    ll mid = (lb + ub) / 2LL;
    if (check(h, mid)) ub = mid;
    else lb = mid;
  }
  cout << ub << endl;

  return 0;
}

Measured memory_bytes: 2896
import sys
input = sys.stdin.readline
import copy

N,K = map(int, input().split())
A = list(map(int, input().split()))

# 累積和
AS = [0] * (N+1)
for i in range(N):
  AS[i+1] = AS[i] + A[i]
  
# 全要素をリスト化する
B = []
for i in range(N+1):
  for j in range(i+1,N+1):
    wk = AS[j] - AS[i]
    if wk > 0:
      B.append(wk)

ans = 0
for m in range(38,-1,-1):
  cnt = 0
  p = pow(2,m)
  nxt = []
  for b in B:
    if p & b == p:
      nxt.append(b)
  if len(nxt) >= K:
    ans += p
    B = nxt
    # Bの候補が減っていくところがポイント！
  else:
    pass
    # Bは変わらないところがポイント！

print(ans)
#print(B)

Measured memory_bytes: 110676
#include <iostream>

using namespace std;

typedef long long ll;

string Conv(int d, ll x)
{
    string w = "";
    while (x != 0)
    {
        w = (char) (x % 26 + 'a') + w;
        x /= 26;
    }
    while (w.size() < d)
        w = "a" + w;
    return w;
}

int main()
{
    ios_base::sync_with_stdio(0);
    ll n;
    cin >> n;
    ll d = 1, sp = 26;
    while (n > sp)
    {
        n -= sp;
        sp *= 26;
        ++d;
    }
    cout << Conv(d, n - 1);
    return 0;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define ss second
#define ff first
#define all(x) x.begin(), x.end()
 
using namespace std;
using ll = long long;
using pii = pair<int, int>;
 
const int oo = 1e9 + 7;
const int mod = 1e9 + 7, maxn = 100100;
const long double PI = acos(-1);
 
int main (){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    ll n, mx = -1,mn = oo, p;
    ll ans = oo;
    cin >> n;

    vector<ll> v(n);

    for (int i=0; i<n; i++) cin >> v[i], mx = max(v[i], mx), mn = min(v[i], mn);

    for (int i=mn; i<=mx; i++){
        p = 0;
        for (int j=0;j<n; j++){
            p += (v[j] - i)*(v[j] - i);
        }
        ans = min(p, ans);
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
n,m = gets.split(" ").map(&:to_i)
as = gets.split(" ").map(&:to_i)
as1 = as[1..-1]

(n-1).times do
    asn = gets.split(" ").map(&:to_i)
    as1 = as1 & asn[1..-1]
end
puts as1.count

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

int main() {
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  for (int i = 0; i < 100000 ; i++) {
    c = c - b;
    if (a <= 0) {
      cout << "No";
      break;
    };
    if (c <= 0) {
      cout << "Yes";
      break;
    };
    a = a - d;
    if (a <= 0) {
      cout << "No";
      break;
    };
    if (c <= 0) {
      cout << "Yes";
      break;
    };
  }
}


Measured memory_bytes: 3600
package main

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

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

func scanString() string   { sc.Scan(); return sc.Text() }
func scanRunes() []rune    { return []rune(scanString()) }
func scanInt() int         { a, _ := strconv.Atoi(scanString()); return a }
func scanInt64() int64     { a, _ := strconv.ParseInt(scanString(), 10, 64); return a }
func scanFloat64() float64 { a, _ := strconv.ParseFloat(scanString(), 64); return a }

func scanInts(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = scanInt()
	} 
	return res
}

func debug(a ...interface{}) { fmt.Fprintln(os.Stderr, a...) }

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

//•*¨*•.¸¸♪main•*¨*•.¸¸♪(　-ω-)ノ　(　・ω・)
func main() {
	defer wr.Flush()
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 10000), 1001001)

	n := scanInt()
	m := scanInt()
	s := scanInts(n)
	t := scanInts(m)

	s = append(s)
	t = append(t)

	dp := make([][]int, n+1)
	for i := 0; i < n+1; i++ {
		dp[i] = make([]int, m+1)
	}
	for i := 0; i < m+1; i++ {
		dp[0][i] = 1
	}

	for i := 0; i < n; i++ {
		add := 0
		dp[i+1][m] = 1
		for j := 0; j < m; j++ {
			dp[i+1][m-1-j] = dp[i][m-1-j]
			if s[n-1-i] == t[m-1-j] {
				add+=dp[i][m-j]
				add %= MOD
			}

			dp[i+1][m-1-j] += add
			dp[i+1][m-1-j] %= MOD
		}
		// debug(dp[i+1])
	}

	fmt.Fprintln(wr, dp[n][0])
}

// MOD constant
const MOD = 1000000007


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

using namespace std;

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

typedef long long ll;

void solve1()
{
    int n, k; cin >> n >> k;
    long double ans = 0;

    for(int i = 1; i <= n; i++) {
        
            int cnt = 0; 
            ll p = i;
            while (p < k)
            {
                p *= 2;
                cnt++;
            }
        
        double d = pow(0.5, cnt);
        ans += (1.0/ n)*(d);
        /*cout << i << endl;*/
    }

    

    cout << fixed << setprecision(12) << ans << endl;
}

int main()
{
    solve1();
}

Measured memory_bytes: 4056
#include<bits/stdc++.h>
using namespace std;
     
     
typedef long long ll;
typedef vector <int> vi;
typedef pair <int,int> pi;
typedef tuple <int,int,int> ti;

#define forn(i,a,n) for(int i = a; i < n ; i++)
#define mem(str,a) memset(str, a, sizeof(str));
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(nullptr)
const int MOD = 1e9+7, N = 1e7 + 10, E = 1e-9;
/*
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
//vector <int> show;
//for (auto x : show)
//   cout << x << " ";
getline(cin,s);


*/

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

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

int main() {
double a, circ, area;
cin >> a;
circ = M_PI * a * 2;
area = M_PI * (a * a);
cout << fixed << setprecision(10);
cout << area << " " << circ;
return 0;
}



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

using namespace std;
using ll=long long;
using ull=unsigned long long;
using pii=pair<int,int>;

#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()

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

  string s;
  cin>>s;
  map<char,int>m;
  for(auto it:s)m[it]++;
  bool ok=true;
  for(auto it:m)if(it.second>1)ok=false;
  if(ok)cout<<"yes"<<endl;
  else cout<<"no"<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <math.h>
int kan(int n){
  int sum=1,i=2;
  double s=sqrt(n);
  if(n<6)return -1;
  for(;i<s;i++){
    if(n%i==0)sum += i+n/i;
  }
  if(floor(s)==s&&n%(int)s==0)sum+=s;
  return sum-n;
}
 
int main(){
  int n,r;
  while(1){
    scanf("%d",&n);
    if(n==0)return 0;
    r=kan(n);
    if(r<0)printf("deficient number\n");
    if(r==0)printf("perfect number\n");
    if(r>0)printf("abundant number\n");
  }
}

Measured memory_bytes: 584
#include<iostream>
#include<cstdio>
using namespace std;
typedef long long ll;
typedef long double ld;
#define res register
const int INF=0x3f3f3f3f;
template<typename T> inline T read(){
	char ch=getchar();T s=0;int f=1;
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){s=(s<<1)+(s<<3)+(ch^48);ch=getchar();}
	return s*f;
}
ll f1(ll x){
	ll ans=1;
	for(res ll i=2;i*i<=x;++i){
		if(x%i==0){
			if(x/i==i)ans++;
			else ans+=2;
		}
	}
	return ans;
}
ll f2(ll x){
	ll ans=1;
	for(res ll i=2;i*i<=x;++i){
		if(x%i==0){
			ll tmp=x;
			while(tmp%i==0)tmp/=i;
			if(tmp>i)tmp%=i;
			ans+=(tmp==1);
			if(x/i!=i){
				tmp=x;
				int j=x/i;
				while(tmp%j==0)tmp/=j;
				if(tmp>j)tmp%=j;
				ans+=(tmp==1);
			}
		}
	}
	return ans;
}
int main(){
	ll n=read<ll>();
	if(n==2){cout<<1<<endl;return 0;}
	cout<<f1(n-1)+f2(n)<<endl;
	return 0;
}


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

template<typename T>
T gcd(T a, T b) {
  if (a == 0) return b;
  return gcd(b%a, a);
}

template<typename T>
T lcm(T a, T b) {
  return (a*b)/gcd(b%a, a);
}

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << setprecision(20);
  ll a, b, c, d;
  cin >> a >> b >> c >> d;
  ll l = lcm(c, d);
  ll div_by_c = b/c - (a-1)/c;
  ll div_by_d = b/d - (a-1)/d;
  ll div_by_l = b/l - (a-1)/l;
  cout << (b - a + 1) - div_by_c - div_by_d + div_by_l << endl;
  return 0;
}


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


int main(){
    ll N,A,B,C,D,E;
    cin >> N >> A >> B >> C >> D >> E;
    ll min_dist;
    min_dist = min(A,min(B,min(C,min(D,E))));
    //cout << min_dist << endl;
    
    ll total_time;
    //人の数が少ない
    if(N <= min_dist){
        cout << 5 << endl;
    }else{
        //詰まるところでかかる時間
        ll move_time;
        if(N%min_dist !=0){
            move_time = N/min_dist + 1;
        }else{
            move_time = N/min_dist;
        }
        
        total_time = move_time + 4;
        cout << total_time << endl;
    }
}


Measured memory_bytes: 256
#ifndef LOCAL
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#else
#include <iostream>
#include <iomanip> 
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <memory>
#include <cctype>
#include <cstring>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#endif
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; }; sim > rge<c> range(c i, c j) { return rge<c>{i, j}; } sim > auto dud(c* x) -> decltype(cerr << *x, 0); sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; } eni(!=) cerr << boolalpha << i; ris; } eni(==) ris << range(begin(i), end(i)); } sim, class b dor(pair < b, c > d) { ris << "(" << d.first << ", " << d.second << ")"; } sim dor(rge<c> d) { *this << "["; for (auto it = d.b; it != d.e; ++it) *this << ", " + 2 * (it == d.b) << *it; ris << "]"; }
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

// #include <ext/pb_ds/assoc_container.hpp> 
// #include <ext/pb_ds/tree_policy.hpp> 
// using namespace __gnu_pbds; 
// #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 

template<typename T> void setmax(T& x, T y) {x = max(x, y);}
template<typename T> void setmin(T& x, T y) {x = min(x, y);}
#define fix(a) fixed << setprecision(a)
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define rep(i, a, b) for (int i = int(a); i < int(b); i++)
#define all(V) V.begin(), V.end()
#define rall(V) V.rbegin(), V.rend()
#define len(V) (int)V.size()
#define ll long long
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define endl '\n'


void solve(){
  ll x, k;
  cin >> x >> k;
  x = x % k;
  cout << min(x, k-x);
}

int main() {
  ios::sync_with_stdio(false);
  int t = 1;
  // cin >> t;
  forn(i, t){
    solve();
  }
}

/* 

1
322123


n - 1
0 ... (n-1) [res ... res] S - (n-1) ... S


 */

Measured memory_bytes: 3660
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <time.h>
#define ll long long
#define double long double
#define itn int
#define endl '\n'
#define co(ans) cout<<ans<<endl;
#define COYE cout<<"YES"<<endl;
#define COYe cout<<"Yes"<<endl;
#define COye cout<<"yes"<<endl;
#define CONO cout<<"NO"<<endl;
#define CONo cout<<"No"<<endl;
#define COno cout<<"no"<<endl;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,1,n)
#define ALL(V) ((V).begin(),(V).end())
#define SORT(V) sort((V).begin(),(V).end())
#define REVERSE(V) reverse((V).begin(),(V).end())
#define INF ((1LaL<<62)-(1LL<<31))
#define EPS 1e-10
#define PI 3.141592653589793238
#define MOD 1000000007
#define MAX 5100000
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;}
using namespace std;

int main(){
  ll X;
  cin>>X;
  ll P[1010];
  for(ll i=0; i<1001; ++i){
    P[i]=i*i*i*i*i;
  }
  
  for(ll i=0; i<1001; ++i){
    for(ll j=0; j<=i; ++j){
      if(P[i]-P[j]==X){
        cout<<i<<" "<<j<<endl;
        return 0;
      }
      else if(P[i]+P[j]==X){
        j*=-1ll;
        cout<<i<<" "<<j<<endl;
        return 0;
      }
    }
  }
  return 0;
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
    using namespace std;
     
    int main() {
      int n;
      cin >> n;
      int arr[n];
      for (int i = 0; i < n; ++i) {
      	cin >> arr[i]; 
      }
      long long ans = 0;
      for (int i = 0; i < n; ++i) {
        for (int j = i + 1; j < n; ++j) {
        	ans += arr[i] * arr[j]; 
        }
      }
      cout << ans;
    }

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

int main(){
    int A, B, C;
    int X, Y;
    cin >> A >> B >> C >> X >> Y;

    if( A+B <= 2*C ){
        cout << A*X + B*Y << endl;
        return 0;
    }

    int min_c = min({X, Y}) * 2;
    int max_c = max({X, Y}) * 2;

    long long ans = A*X + B*Y;
    for(int c_count=min_c; c_count<max_c+1; c_count++){
        long long price = A*max({X-c_count/2,0}) + B*max({Y-c_count/2,0}) + c_count*C;
        if(ans > price){
            ans = price;
        }
    }

    cout << ans << endl;
    return 0;

}

Measured memory_bytes: 3552
def read_int():
    return int(input().strip())


def read_ints():
    return list(map(int, input().strip().split(' ')))

def g(X):
    """
    000
    001
    010
    011
    100
    101
    110
    111
    """
    p = 1
    i = 39
    digits = [0]*40
    N = X+1
    while i > -1:
        digits[i] = N//(2*p)*p
        if N%(2*p)-p > 0:
            digits[i] += N%(2*p)-p
        p *= 2
        i -= 1
    answer = 0
    p = 1
    for d in digits[::-1]:
        if d%2 == 1:
            answer += p
        p *= 2
    return answer


def solve():
    """
    f(A, B) = A^...^B
    g(A) = 0^...^A
    g(B) = 0^...^B

    f(A, B) = g(A-1)^g(B)
    f(0, B) = g(B)
    """
    A, B = read_ints()
    if A == 0:
        return g(B)
    return g(A-1)^g(B)


if __name__ == '__main__':
    print(solve())


Measured memory_bytes: 62044
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

typedef struct dou
{
	int key;
	struct dou  *next, *prev;
}list;

list *y;

void insert(int key)
{
	list *x = (list *)malloc(sizeof(list));
	
	x->key = key;
	x->next = y->next;
	y->next->prev = x;
	y->next = x;
	x->prev = y;
}

void deleteKey(int key)
{
	list *x = y->next;
	
	while(x != y && x->key != key)
	{
		x = x->next;
	}
	
	if(x != y)
	{
		x->prev->next = x->next;
		x->next->prev = x->prev;
		free(x);
	}
	
	
}

void deleteFirst()
{
	list *x = y->next;
	
	if(x != y)
	{
		x->prev->next = x->next;
		x->next->prev = x->prev;
		free(x);
	}
}

void deleteLast()
{
	list *x = y->prev;
	
	if(x != y)
	{
		x->prev->next = x->next;
		x->next->prev = x->prev;
		free(x);
	}
}

int main(void)
{
	list a;
	int n, i, key, np, nd, size;
	char command[20];
	
	np=0;
	nd=0;
	size=0;
	
	scanf("%d", &n);
	
	y=(list *)malloc(sizeof(list));
	y->next = y;
	y->prev = y;
	
	for(i =0; i< n; i++)
	{
		scanf("%s %d", command, &key);
		
		if(strcmp("insert", command)==0)
		{
			insert(key);
			np++;
			size++;
		}
		else if(strcmp("delete", command)==0)
		{
			deleteKey(key);
			nd++;
			size--;
		}
		else if(strcmp("deleteFirst", command)==0)
		{
			deleteFirst();
			size--;
		}
		else if(strcmp("deleteLast", command)==0)
		{
			deleteLast();
			size--;
		}
		
	}
	
	list *x = y->next;
	int j = 0;
	
	for(;;)
	{
		if(x==y)
		{
			break;
		}
		
		if(j > 0)
		{
			printf(" ");
		}
		
		j++;
	
		printf("%d", x->key);
		x=x->next;
		
	}
	
	printf("\n");
	
	return 0;
	
}





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

int main(){
    int n;
    cin >> n;
    vector<pair<int, int>> ab;
    vector<pair<int, int>> cd;
    for(int i = 0; i < n; i++){
        int a,b;
        cin >> a >> b;
        ab.push_back({a,b});
    }
    for(int i = 0; i < n; i++){
        int c,d;
        cin >> c >> d;
        cd.push_back({c,d});
    }
    sort(ab.begin(),ab.end()); //赤
    sort(cd.begin(),cd.end()); //青

    int x,y;
    pair<int, int> temp;
    int ans = 0;
    for(int i = 0; i < n; i++){
        int tx = 10000,ty = 10000;
        temp = {-1,-1};
        for(int j = 0; j < n; j++){
            x = 0, y = 0;
            if(ab[j].first < cd[i].first) x = cd[i].first - ab[j].first;
            if(ab[j].second < cd[i].second) y = cd[i].second - ab[j].second;
            if(x > 0 and y > 0){
                ty = min(ty,y);
                if(ty == y) temp = {i,j};
            }
        }
        if(temp.first != -1){
            ans++;
            ab[temp.second].first = 10000000;
            ab[temp.second].second = 10000000;
        }
    }

    cout << ans << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef int ll;
typedef long double ld;
const ll N = 100005;
char en = '\n';
ll inf = 1e16;
ll mod = 1e9 + 7;
ll power(ll x, ll n, ll mod) {
  ll res = 1;
  x %= mod;
  while (n) {
    if (n & 1)
      res = (res * x) % mod;
    x = (x * x) % mod;
    n >>= 1;
  }
  return res;
}

struct node {
  ll a, b, c;
  node() {}
  node(ll a, ll b, ll c) : a(a), b(b), c(c) {}
};
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  ll n, m, p;
  cin >> n >> m >> p;

  ll cost[n + 5];

  for (ll i = 1; i <= n; i++)
    cost[i] = -inf;

  cost[1] = 0;
  node edges[m + 5];
  for (ll i = 1; i <= m; i++) {
    cin >> edges[i].a >> edges[i].b >> edges[i].c;
    edges[i].c -= p;
  }

  for (ll i = 1; i <= n; i++) {
    for (ll j = 1; j <= m; j++) {
      ll a = edges[j].a, b = edges[j].b, c = edges[j].c;
      cost[b] = max(cost[b], cost[a] + c);
    }
  }

  ll tmp[n + 5];
  for (ll i = 1; i <= n; i++)
    tmp[i] = cost[i];
  for (ll i = 1; i <= n; i++) {
    for (ll j = 1; j <= m; j++) {
      ll a = edges[j].a, b = edges[j].b, c = edges[j].c;
      cost[b] = max(cost[b], cost[a] + c);
    }
  }

  ll flag = 0;
  if (cost[n] != tmp[n])
    flag = 1;

  if (flag)
    cout << -1 << en;
  else {
    cout << max(0ll, cost[n]) << en;
  }
  return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int K,S;
  cin >> K >> S;
  int res=0;
  for (int i=0;i<=K;++i){
    for (int j=0;j<=K;++j){
      int k=S-i-j;
        if(0<=k && k<=K) res++;
    }
  }
  cout << res << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdlib.h>

using namespace std;

int main(){
  int m1,m2,d1,d2;
  cin >> m1 >> d1 >> m2 >> d2;
  if(m1 == m2){
    cout << 0 << endl;
    return 0;
  }
  cout << 1 << endl;
  return 0;
}

Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
d=dict()
for i in a:
    if i in d:
        d[i]+=1
    else:
        d[i]=1
p=0
k=0
for i in d.values():
    p+=i//2
    k-=i%2-1
print(n-(p-k//2)*2)


Measured memory_bytes: 17400
#include <chrono>

#include <iostream>
#include <iomanip>
#include <algorithm>
#include <bitset>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <time.h>
#include <random>
#include <string>
#include <cassert>
#include <vector>
#include <ostream>
#include <istream>
#include <stack>
#include <deque>
#include <queue>
#include <functional>

using namespace std;

#define int long long
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define pii pair<int, int>
#define ld long double

ostream& operator << (ostream &a, const vector<int> &b) {
    for (auto k : b) cout << k << " ";
    return a;
}

#ifdef LOCAL
    #define dbg(x) cout << #x << " : " << (x) << "\n";
    const int INF = 1e18;
//    const int mod = 2600000069;
//    const int p = 10;
//    const ld PI = 3.1415926535;
#else
    #define dbg(x)
    const int INF = 1e18;
//    const int mod = 2600000069;
//    const int p = 179;
//    const ld PI = 3.1415926535;
#endif

//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,sse3,sse4")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("fast-math")
//#pragma GCC target("avx2")
//#pragma GCC optimize("section-anchors")
//#pragma GCC optimize("profile-values,profile-reorder-functions,tracer")
//#pragma GCC optimize("vpt")
//#pragma GCC optimize("rename-registers")
//#pragma GCC optimize("move-loop-invariants")
//#pragma GCC optimize("unswitch-loops")
//#pragma GCC optimize("function-sections")
//#pragma GCC optimize("data-sections")

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    #ifdef LOCAL
    #else
//        freopen("capitals.in", "r", stdin);
//        freopen("capitals.out", "w", stdout);
    #endif
    string s;
    cin >> s;
    int n = s.size();
    int q;
    cin >> q;
    int t, f;
    char c;
    bool rev = 0;
    vector<pair<bool, char>> a;
    for (int i = 0; i < q; i++) {
        cin >> t;
        if (t == 1) rev ^= 1;
        else {
            cin >> f >> c;
            if (f == 1) {
                if (rev) a.pb({1, c});
                else a.pb({0, c});
            } else {
                if (rev) a.pb({0, c});
                else a.pb({1, c});
            }
        }
    }
    q = a.size();
    if (rev) {
        reverse(all(s));
        for (int i = 0; i < q; i++) a[i].first ^= 1;
    }
    for (int i = q - 1; i >= 0; i--) if (!a[i].first) cout << a[i].second;
//    cout << "\n";
    cout << s;
//    cout << "\n";
    for (int i = 0; i < q; i++) if (a[i].first) cout << a[i].second;
}
/*

*/


Measured memory_bytes: 1224
#include <iostream>

using namespace std;
long long N;

int main(void) {
	long long k[88];
	k[0] = 2;
	k[1] = 1;

	for (int i = 2; i < 87; ++i) {
		k[i] = k[i - 1] + k[i - 2];
	}

	cin >> N;
	cout << k[N] << endl;

	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);
		String S = sc.next();
		String T = sc.next();
		if (T.matches(S+".")) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}

Measured memory_bytes: 38600
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,b) for(int i=a; i<=b; i++)
#define all(v) v.begin(), v.end()
#define F first
#define S second
#define INF 1000000000000
#define MOD 10000007
typedef long long ll;
//

int main(){
   ll n,k,d;cin>>n>>k>>d;
   int ans=0;
   FOR(i,n,k){
      if(i%d==0)ans++;
   }
   cout<<ans<<endl;
}

Measured memory_bytes: 3588
N=int(input())
a=list(map(int,input().split()))
a.append(10**10)
a.sort()
n=0
c=0
ans=0
for i in range(N+1):
    if n!=a[i]:
        if n<c:ans+=c-n
        elif c<n:ans+=c
        n=a[i]
        c=1
    else:c+=1
print(ans)

Measured memory_bytes: 20640
#include <iostream>
#include <string>
#include <unordered_map>
#include <stdio.h>
#include <list>
#include <vector>
#include <algorithm>
#include <stack>
#include <climits>
#include <queue>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; ++i)
typedef long long ll;



struct shi
{
	int y,smallnum,innum,k;
};


bool cmp(shi &a,shi &b)
{
	return a.innum < b.innum;
}

bool cmp2(shi &a,shi &b)
{
	return a.y < b.y;
}

int main()
{
	int n,m;
	cin >> n >> m;
	vector<vector<shi>> v(n);
	rep(i,m)
	{
		int k;cin >> k;
		int l;cin >> l;
		shi foo = {l,0,i,k};
		v[k-1].push_back( foo );
	}
	
	//年順にソート
	rep(i,n)
	{
		sort(v[i].begin(),v[i].end(), cmp2);
	}
	
	vector<shi> w(m);

	int k=0;
	rep(i,n)
		rep(j,v[i].size())
		{
			v[i][j].smallnum=j;
			w[k]=v[i][j];
			k++;
		}

sort(w.begin(),w.end(),cmp);

rep(i,m)printf("%06d%06d\n",w[i].k,w[i].smallnum+1);


		
	
	return 0;
}

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

using namespace std;

int main() {
    int h, w;
    cin >> h >> w;
    string s[h];
    for (int i = 0; i < h; i++) {
        cin >> s[i];
    }

    bool bh[h];
    for (int i = 0; i < h; i++) {
        bh[i] = true;
        for (int j = 0; j < w; j++) {
            if (s[i][j] == '#') {
                bh[i] = false;
                break;
            }
        }
    }

    bool bw[w];
    for (int i = 0; i < w; i++) {
        bw[i] = true;
        for (int j = 0; j < h; j++) {
            if (s[j][i] == '#') {
                bw[i] = false;
                break;
            }
        }
    }

    for (int i = 0; i < h; i++) {
        if (bh[i]) {
            continue;
        }
        for (int j = 0; j < w; j++) {
            if (!bw[j]) {
                cout << s[i][j];
            }
        }
        cout << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
    int x[50][3];
    int j, q, k;
    
    for(j = 0; j < 50; j++){
        for(q = 0; q < 3; q++){
            scanf(" %d", &x[j][q]);
        }
        if(x[j][0] == -1 && x[j][1] == -1 && x[j][2] == -1)
            break;
    }
    
    for(k = 0; k < j; k++){
        if(x[k][0] == -1 && x[k][1] == -1 && x[k][2] == -1)
            break;
        if(x[k][0] == -1 || x[k][1] == -1)
            printf("F\n");
        else if(x[k][0] + x[k][1] >= 80)
            printf("A\n");
        else if(x[k][0] + x[k][1] >= 65)
            printf("B\n");
        else if(x[k][0] + x[k][1] >= 50)
            printf("C\n");
        else if(x[k][0] + x[k][1] >= 30){
            if(x[k][2] >= 50)
                printf("C\n");
            else
                printf("D\n");
        }else if(x[k][0] + x[k][1] < 30)
            printf("F\n");
    }
    
    
    return 0;
}


Measured memory_bytes: 2080
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define double long double
using datas=pair<ll,ll>;
using ddatas=pair<double,double>;
using tdata=pair<ll,datas>;
using vec=vector<ll>;
using mat=vector<vec>;
using pvec=vector<datas>;
using pmat=vector<pvec>;
#define For(i,a,b) for(i=a;i<(ll)b;i++)
#define bFor(i,a,b) for(i=a;i>=(ll)b;i--)
#define rep(i,N) For(i,0,N)
#define rep1(i,N) For(i,1,N)
#define brep(i,N) bFor(i,N-1,0)
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define vsort(v) sort(all(v))
#define vrsort(v) sort(allr(v))
#define endl "\n"
#define pb push_back
#define print(v) cout<<v<<endl
#define printyes cout<<"Yes"<<endl
#define printno cout<<"No"<<endl
#define printYES cout<<"YES"<<endl
#define printNO cout<<"NO"<<endl
#define output(v) do{bool f=0;for(auto outi:v){cout<<(f?" ":"")<<outi;f=1;}cout<<endl;}while(0)
const ll mod=1000000007;
const ll inf=1LL<<60;
const double PI = acos(-1);
const double eps = 1e-9;
template<class T> inline bool chmax(T& a,T b){bool x=a<b;if(x)a=b;return x;} 
template<class T> inline bool chmin(T& a,T b){bool x=a>b;if(x)a=b;return x;} 

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

double distance(ddatas x,ddatas y){
  double a=x.first-y.first,b=x.second-y.second;
  return sqrt(a*a+b*b);
}

ll modinv(ll a) {
  ll b=mod,u=1,v=0,t;
  while(b){
    t=a/b;
    a-=t*b; swap(a,b);
    u-=t*v; swap(u,v);
  }
  return (u+mod)%mod;
}

ll moddevide(ll a,ll b){return (a*modinv(b))%mod;}

vec modncrlistp,modncrlistm;

ll modncr(ll n,ll r){
  ll i,size=modncrlistp.size();
  if(size<=n){
    modncrlistp.resize(n+1);
    modncrlistm.resize(n+1);
    if(!size){
      modncrlistp[0]=modncrlistm[0]=1;
      size++;
    }
    For(i,size,n+1){
      modncrlistp[i]=modncrlistp[i-1]*i%mod;
      modncrlistm[i]=modinv(modncrlistp[i]);
    }
  }
  return modncrlistp[n]*modncrlistm[r]%mod*modncrlistm[n-r]%mod;
}

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

ll gcd(ll a,ll b){if(!b)return a;return (a%b==0)?b:gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

ll countdigits(ll n){
  ll ans=0;
  while(n){n/=10;ans++;}
  return ans;
}

ll sumdigits(ll n){
  ll ans=0;
  while(n){ans+=n%10;n/=10;}
  return ans;
}

int main(){
  // startupcpp();
  // ll test;cin>>test;while(test--){
  ll i,j,N,H,W,ans=0;
  cin>>N;
  mat v(11,vec(11,0));
  rep1(i,N+1){
    H=countdigits(i);
    W=modpow(10,H-1);
    v[i%10][i/W]++;
  }
  //rep(i,11)output(v[i]);
  rep1(i,11)rep1(j,11){
    ans+=v[i][j]*v[j][i];
  }
  print(ans);
  return 0;
}

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

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

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

// GCC, 配列のアクセスなど
#define _GLIBCXX_DEBUG
// Clang, 配列のアクセスなど
#define _LIBCPP_DEBUG 0

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

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

int n;
vector<int> as;
int dp;
multiset<int> dp2;

int main()
{
    // 高速な入出力
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << setprecision(15); // 浮動小数の表示の精度

    cin>>n;
    rep(i,n) {
        int a; cin>>a; as.push_back(a);
    }

    // これも嘘かも
    rep(i, n) {
        int a = as[i];
        if (dp2.empty()) { dp++; dp2.insert(a); continue; }
        auto it = dp2.lower_bound(a);
        if (it == dp2.begin()) { dp++; dp2.insert(a); }
        else { it--; dp2.erase(it); dp2.insert(a); }
    }

    cout << dp << '\n';

    return 0;
}


Measured memory_bytes: 8312