akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<string>
#include<set>
#include<climits>
#include<map>
#define ll long long
using namespace std;
int main() {
	ll w, a, b;
	cin >> w >> a >> b;
	if (b > a + w) {
		cout << b - (a + w) << endl;
	}
	else if (b + w < a) {
		cout << a-(b + w)  << endl;
	}
	else {
		cout << "0" << endl;
	}
}



Measured memory_bytes: 256
#include"bits/stdc++.h"
using namespace std;
#define LL long long
#define PB push_back
#define MP make_pair

int main(){
	int H, W;
	cin >> H >> W;
	string S[2000];
	for(int i=0; i<H; i++) cin >> S[i];

	vector<int> tate[2000],yoko[2000];
	for(int i=0; i<H; i++) yoko[i].PB(-1);
	for(int i=0; i<W; i++) tate[i].PB(-1);
	for(int i=0; i<H; i++){
		for(int j=0; j<W; j++){
			if(S[i][j] == '#'){
				tate[j].PB(i);
				yoko[i].PB(j);
			}
		}
	}
	for(int i=0; i<H; i++) yoko[i].PB(W);
	for(int i=0; i<W; i++) tate[i].PB(H);

	int ans = 0;
	for(int i=0; i<H; i++){
		for(int j=0; j<W; j++){
			if(S[i][j] == '#') continue;
			int u = *(lower_bound(tate[j].begin(), tate[j].end(), i)-1);
			int d = *lower_bound(tate[j].begin(), tate[j].end(), i);
			int l = *(lower_bound(yoko[i].begin(), yoko[i].end(), j)-1);
			int r = *lower_bound(yoko[i].begin(), yoko[i].end(), j);
			ans = max(ans, d-u+r-l-3);
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 38400
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define F(i,s,e) for(ll i=s;i<e;++i)

int main()
{
    int k;
    string s;
    cin >> k >> s;
    if(k<s.size()){
        for(int i=0;i<k;++i){
            cout << s[i];
        }
        cout << "...";
    }
    else{
        cout << s;
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 3592
n=int(input())
march=[]
for i in range(n):
    x=input()
    march.append(x[0])

m=march.count('M')
a=march.count('A')
r=march.count('R')
c=march.count('C')
h=march.count('H')
ways=m*a*r+m*a*c+m*a*h+m*r*c+m*c*h+a*r*c+a*r*h+a*c*h+r*c*h+m*r*h
print(ways)


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

#define ll long long
#define ar array
#define vi vector<int>
#define INF 1000000000

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	ll a, b, c, k;				
	cin >> a >> b >> c >> k;
	if(k <= a) cout << k << endl;
	else if(k <= a + b) cout << a << endl;
	else cout << a - (k - a - b) << endl;		

	return 0;
}


Measured memory_bytes: 3636
N, P = gets.split(" ").map(&:to_i)
A = gets.split(" ").map(&:to_i)

odd, even = 0, 1
A.each do |a|
	if a % 2 == 0
		odd, even = odd * 2, even * 2
	else
		odd, even = odd + even, odd + even
	end
end

puts P.zero? ? even : odd


Measured memory_bytes: 1788
#include <iostream>
#include <vector>

using namespace std;

typedef pair< int, int > P;
const int N_MAX = 1e5 + 1;

vector< P > g[N_MAX];
bool is_checked[N_MAX] = {false};
int color[N_MAX] = {0};

void dfs(int p, int c) {
    color[p] = c;
    is_checked[p] = true;
    for (auto x : g[p]) {
        if (is_checked[x.first]) continue;
        if (x.second % 2 == 0)
            dfs(x.first, c);
        else
            dfs(x.first, c ^ 1);
    }
}

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

    for (int i = 0; i < N - 1; i++) {
        int u, v, w;
        cin >> u >> v >> w;
        u--, v--;

        g[u].push_back(P(v, w));
        g[v].push_back(P(u, w));
    }

    dfs(0, 0);
    for (int i = 0; i < N; i++) {
        cout << color[i] << endl;
    }
}

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

int main(){
  int n; cin >> n;
  int p[25];
  for (int i = 0; i < n; i++){
    cin >> p[i];
  }
  int ans = 0;
  for (int i = 1; i < n - 1; i++){
    if (p[i - 1] < p[i] && p[i] < p[i + 1]
    || p[i - 1] > p[i] && p[i] > p[i + 1]){
      ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
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; }

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ for(auto it : P) { s << "<" << it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ for(auto it : P) { s << "<" << it.first << "->" << it.second << "> "; } return s << endl; }




template <class Abel> struct BIT {
    vector<Abel> dat[2];
    Abel UNITY_SUM = 0;                     // to be set
    
    /* [1, n] */
    BIT(int n) { init(n); }
    void init(int n) { for (int iter = 0; iter < 2; ++iter) dat[iter].assign(n + 1, UNITY_SUM); }
    
    /* a, b are 1-indexed, [a, b) */
    inline void sub_add(int p, int a, Abel x) {
        for (int i = a; i < (int)dat[p].size(); i += i & -i)
            dat[p][i] = dat[p][i] + x;
    }
    inline void add(int a, int b, Abel x) {
        sub_add(0, a, x * -(a - 1)); sub_add(1, a, x); sub_add(0, b, x * (b - 1)); sub_add(1, b, x * (-1));
    }
    
    /* a is 1-indexed, [a, b) */
    inline Abel sub_sum(int p, int a) {
        Abel res = UNITY_SUM;
        for (int i = a; i > 0; i -= i & -i) res = res + dat[p][i];
        return res;
    }
    inline Abel sum(int a, int b) {
        return sub_sum(0, b - 1) + sub_sum(1, b - 1) * (b - 1) - sub_sum(0, a - 1) - sub_sum(1, a - 1) * (a - 1);
    }
    
    /* debug */
    void print() {
        for (int i = 1; i < (int)dat[0].size(); ++i) cout << sum(i, i + 1) << ",";
        cout << endl;
    }
};

int main() {
    int N, Q; cin >> N >> Q;
    vector<int> a(N);
    for (int i = 0; i < N; ++i) cin >> a[i];

    vector<int> lefts(Q), rights(Q), ids(Q);
    for (int i = 0; i < Q; ++i) {
        cin >> lefts[i] >> rights[i];
        --lefts[i];
        ids[i] = i;
    }
    sort(ids.begin(), ids.end(), [&](int i, int j) {
            return rights[i] < rights[j];});

    BIT<int> bit(N+5);
    vector<int> prev(1100000, -1);
    vector<int> res(Q, 0);
    int r = 0;
    for (auto i : ids) {
        for (; r < rights[i]; ++r) {
            bit.add(prev[a[r]]+2, r+2, 1);
            prev[a[r]] = r;
        }
        int tmp = bit.sum(lefts[i]+1, lefts[i]+2);
        res[i] = max(res[i], tmp);
    }
    for (int i = 0; i < Q; ++i) cout << res[i] << endl;
}













Measured memory_bytes: 21724
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <cfloat>

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

enum Status{
  win=1,lose,unknown
};

struct Matrix{
  Status status[9][9]={};
  int win_count[9]={};
  int lose_count[9]={};
  void SetStatus(Status s, int team,int against){
    if(s==unknown){
      status[team][against]=unknown;
      status[against][team]=unknown;
    }else if(s==win){
      status[team][against]=win;
      win_count[team]++;
      status[against][team]=lose;
      lose_count[against]++;
    }else{
      status[team][against]=lose;
      lose_count[team]++;
      status[against][team]=win;
      win_count[against]++;
    }
  }
  bool IsValid(int team, int n){
    return win_count[team]<=(n-1)/2&&lose_count[team]<=(n-1)/2;
  }
};

int Solve(int n){
  int m;
  cin>>m;
  Matrix initial_matrix;
  for(int i=0;i<m;i++){
    int x,y;
    cin>>x>>y;
    initial_matrix.SetStatus(win,x-1,y-1);
  }
  for(int r=0;r<n;r++){
    for(int c=0;c<n;c++){
      if(initial_matrix.status[r][c]==0){
        initial_matrix.status[r][c]=unknown;
      }
    }
  }
  for(int i=0;i<n;i++){
    if(!initial_matrix.IsValid(i,n)){
      return 0;
    }
  }
  std::stack<Matrix> q;
  int result=0;
  q.push(initial_matrix);
  while(!q.empty()){
    Matrix curr=q.top();
    q.pop();
    bool found_unknown=false;
    for(int r=0;r<n;r++){
      for(int c=0;c<n;c++){
        if(r==c) continue;
        if(curr.status[r][c]==unknown){
          Matrix next_win=curr;
          next_win.SetStatus(win,r,c);
          if(next_win.IsValid(r,n)&&next_win.IsValid(c,n)){
            q.push(next_win);
          }
          Matrix next_lose=curr;
          next_lose.SetStatus(lose,r,c);
          if(next_lose.IsValid(r,n)&&next_lose.IsValid(c,n)){
            q.push(next_lose);
          }
          found_unknown=true;
          break;
        }
      }
      if(found_unknown) break;
    }
    if(!found_unknown){
      result++;
    }
  }
  return result;
}

int main(){
  cout << std::fixed << std::setprecision(16);
  cin.tie(nullptr);
  std::ios::sync_with_stdio(false);

  while(true){
    int n;
    cin>>n;
    if(n==0) break;
    cout<<Solve(n)<<endl;
  }



  return 0;
}


Measured memory_bytes: 3080
fn main() {
    let (a, b) = read();
    let ans = solve(a, b);
    write(ans);
}

fn read() -> (i32, i32) {
    let mut l1 = String::new();
    std::io::stdin().read_line(&mut l1).ok();
    let mut iter1 = l1.trim().split_whitespace();
    let a = iter1.next().unwrap().parse::<i32>().unwrap();
    let b = iter1.next().unwrap().parse::<i32>().unwrap();

    (a, b)
}

fn write(ans: i32) {
    println!("{}", ans);
}

fn solve(a: i32, b: i32) -> i32 {
    a * b
}


Measured memory_bytes: 2108
#include <iostream>
#include <algorithm>
#include <cmath>
#include <list>

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

int main() {
    int n, k;
    cin >> n >> k;

    int d = 0;
    int a;

    list<int> oks;
    for(int i=0; i<k; i++) {
        cin >> d;
        for(int j=0; j<d; j++) {
            cin >> a;
            oks.push_back(a);
        }
    }

    oks.sort();
    oks.unique();

    int count = 0;
    for(int x=1; x<=n; x++) {
        if(oks.front() == x) {
            oks.pop_front();
        } else {
            count++;
        }
    }

    cout << count << endl;
}

Measured memory_bytes: 3340
#include<stdio.h>
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
string a;
string b;
int main() {
	cin >> a;
	cin >> b;
	int count = 0;
	int as = a.size();
	int bs = b.size();
	if (as > bs) {
		printf("GREATER\n");
	}
	else if (as < bs) {
		printf("LESS\n");
	}
	else {
		int i = 0;
		while (1) {
			if (i == as) {
				break;
			}
			if (a[i] > b[i]) {
				count++;
				printf("GREATER\n");
				break;
			}
			else if (a[i] < b[i]) {
				count++;
				printf("LESS\n");
				break;
			}
			i++;
		}
		if (count == 0) {
			printf("EQUAL\n");
		}
	}
}

Measured memory_bytes: 256
def d():
    from collections import deque
    n = int(input())
    p = [int(pi) for pi in input().split()]
    continuous = deque()
    tmp = 0
    for i, k in enumerate(p):
        if i+1 == k:
            tmp += 1
        else:
            if tmp > 0:
                continuous.append(tmp)
            tmp = 0
    else:
        if tmp > 0:
            continuous.append(tmp)
        tmp = 0
    res = 0
    while len(continuous):
        k = continuous.popleft()
        res += k//2 + k%2
    print(res)

d()


Measured memory_bytes: 14324
a, b, k = map(int, input().split())

if k < (b - a + 1) / 2:
    for i in range(a, a + k): 
        print(i)
    for i in range(b - k + 1, b + 1): 
        print(i)
else:
    for i in range(a, b+1):
        print(i)

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

#define forn(i,n) for(int i=0;i<(int)(n);i++)
#define si(c) ((int)(c).size())
#define forsn(i,s,n) for(int i = (int)(s); i<((int)n); i++)
#define dforsn(i,s,n) for(int i = (int)(n)-1; i>=((int)s); i--)
#define all(c) (c).begin(), (c).end()
#define D(a) cerr << #a << "=" << a << endl;
#define pb push_back
#define eb emplace_back
#define mp make_pair

#ifdef LOCAL
#define i64 "%lld"
#else
#define i64 "%I64d"
#endif

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

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

    int n; scanf("%d", &n);
    ll ans = 0;
    vi x(n);
    forn(i,n) scanf("%d", &x[i]);

    forn(i,n-1) {
        ans += x[i]/2;
        x[i] %= 2;
        if (x[i] && x[i+1]) {
            x[i]--; x[i+1]--;
            ans++;
        }
    }
    ans += x[n-1]/2;
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
#define ll long long int
#define ul unsigned long long int
#define mp make_pair
#define endl "\n"
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define lb lower_bound
#define forn(i,n) for(ll i=0 ; i<n ; i++)
#define arr(a,n) for(ll i=0;i<n;i++){ cin>>a[i]; }
#define ub upper_bound
#define pb push_back
#define pi pair<int,int>
#define mod 1000000007
#define vectormax *max_element
#define vectormin *min_element
#define arraysize 1000000
#define setbit _builtin_popcountll
using namespace std;

ll ipow(ll x, ll n)
{
    ll result = 1;
    while (n) {
        if (n & 1)
            result = result * x % mod;
        n = n / 2;
        x = x * x % mod;
    }
    return result;
}

int main(){
   fio
ll n;
cin>>n;
unordered_map<ll,ll>m;
ll a[n];
for(ll i=0;i<n;i++)
{
    cin>>a[i];
    m[a[i]]++;
}
ll s=0;
for(ll i=0;i<n;i++)
    s+=a[i];

ll t;
cin>>t;
while(t--){
    ll x,y;
    cin>>x>>y;
    s=s-x*m[x]+y*m[x];
    ll t=m[x];
    m[x]-=t;
    m[y]+=t;
cout<<s<<endl;
}
  return 0;
}


Measured memory_bytes: 7744
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static final int MAX = 100; 
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
	
		String[] in;
		int[] a = new int[MAX + 1];
		for(int i = 0; i < n; ++i){
			in = br.readLine().split(" ");
			a[i] = Integer.parseInt(in[0]);
			
			if(i == n-1){
				a[i+1] = Integer.parseInt(in[1]);
			}
		}
		
		long[][] cost = new long[MAX][MAX];
		calcCost(a, cost);
		
		System.out.println(cost[0][n-1]);
	}
	public static void calcCost(int[] a, long[][] cost){
		int n = cost.length;
		for(int k = 0; k < n; k++){
			for(int i = 0; i + k < n; i++){
				if(k == 0){
					cost[i][k] = 0;
					continue;
				}
				cost[i][k] = Long.MAX_VALUE;
				for(int j = 0; j < k; j++){
					long c = cost[i][j] + cost[i+j+1][k-j-1] + a[i]*a[i+j+1]*a[i+k+1]; 
					if(c < cost[i][k]){
						cost[i][k] = c;
					}
				}
			}
		}

	}

}

Measured memory_bytes: 24748
n, k = map(int, input().split())
a = list(map(int, input().split()))
f = list(map(int, input().split()))
a.sort()
f.sort(reverse=True)
costs = [(ai * fi, fi) for ai, fi in zip(a, f)]
costs.sort(reverse=True)
# l impossible, r ok
l, r = -1, costs[0][0]
while(r - l > 1):
    c = (l + r) // 2
    train = 0
    for cost, step in costs:
        if cost > c:
            train += (cost - c + step - 1) // step
    if train <= k:
        r = c
    else:
        l = c
print(r)


Measured memory_bytes: 126028
#include <cstdio>
using ll = long long;

ll ds(ll x) {
    ll ret = 0;
    while(x) {
        ret += x % 10;
        x /= 10;
    }
    return ret;
}

int main() {
    ll K; scanf("%lld", &K);

    ll num = 1, add = 1;
    for(ll i=0; i < K; ++i) {
        printf("%lld\n", num);
        while(double(num + add) / ds(num + add) > double(num + 2 * add) / ds(num + 2 * add)) add *= 10;
        num += add;
    }
    return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#include <string.h>

int main(){
    char str[1000];
    long len;
    int i;
    gets(str);
    len = strlen(str);
    for (i = 0; i < len - 4; i++) {
        if (str[i]=='a' && str[i+1]=='p' && str[i+2]=='p' && str[i+3]=='l' &&str[i+4]=='e') {
            str[i]='p';
            str[i+1]='e';
            str[i+2]='a';
            str[i+3]='c';
            str[i+4]='h';
        }
        else if (str[i]=='p' && str[i+1]=='e' && str[i+2]=='a' && str[i+3]=='c' &&str[i+4]=='h') {
            str[i]='a';
            str[i+1]='p';
            str[i+2]='p';
            str[i+3]='l';
            str[i+4]='e';
        }
    }
    puts(str);
    return 0;
}

Measured memory_bytes: 524
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include <sstream>
#include <iomanip>


using namespace std;
typedef long long ll;
const int INF=1000000000;
const int MOD=1000000007;

int main()
{
 int n;
 ll ans=1;
 cin >> n;
 int a[n],b[3]={};
 for(int i=0;i<n;i++) cin >> a[i];
 for(int i=0;i<n;i++){
   int c=0;
   for(int j=0;j<3;j++){
     if(b[j]==a[i]){
       if(c==0) b[j]++;    
       c++;
     }
   }
   ans=(ans*c)%MOD;
 }
  cout << ans;
  return 0;
}

Measured memory_bytes: 640
#include<stdio.h>
#include<stdlib.h>
int main(){
	int x,y,k=0,temp;
	scanf("%d %d",&x,&y);

	if(x < y){
		temp = x;
		x = y;
		y = temp;
	}
	//ユークリッドの互除法
	k = x%y;
	while(k != 0){
		x = y;
		y = k;
		k = x%y;
	}
	printf("%d\n",y);
	return 0;
}


Measured memory_bytes: 2128
/* ITP1_10_C: Standard Deviation */

#include <iostream>
#include <cstdio>
#include <cmath>
#include <numeric>
using namespace std;

double calc_stdv(int n_students, int scores[]) {
    double sum = accumulate(scores, scores + n_students, 0);
    double average = sum / n_students;
    double var = 0;

    for (int i = 0; i < n_students; i++)
        var += pow(average - scores[i], 2);
    
    return sqrt(var / n_students);
}

int main() {
    int n_students;
    while (true) {
        scanf("%d", &n_students);
        if (n_students == 0) break;

        int scores[n_students];
        for (int i = 0; i < n_students; i++)
            scanf("%d", &scores[i]);

        double stdv = calc_stdv(n_students, scores);
        printf("%.6f\n", stdv);
    }
    return 0;
}

Measured memory_bytes: 1220
#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(int i=0;i<N;++i)
typedef long long int LL;

int main()
{
	LL N, K;
	in >> N >> K;
	std::vector<LL>x(N), y(N);
	std::vector<char>c(N);
	rep(i, N) in >> x[i] >> y[i] >> c[i];

	std::vector<std::vector<LL>>imos(4 * (K + 1), std::vector<LL>(4 * (K + 1), 0));
	rep(i, N)
	{
		if (c[i] == 'W')
		{
			x[i] += K;
			c[i] = 'B';
		}
		x[i] %= 2 * K;
		y[i] %= 2 * K;
		++imos[x[i] + 1][y[i] + 1];
		++imos[x[i] + 2 * K + 1][y[i] + 1];
		++imos[x[i] + 1][y[i] + 2 * K + 1];
	}
	rep(i, imos.size() - 1) rep(j, imos[i].size()) imos[i + 1][j] += imos[i][j];
	rep(i, imos.size()) rep(j, imos[i].size() - 1) imos[i][j + 1] += imos[i][j];
	LL ans = 0;
	for (int i = 1; i <= K; ++i)
	{
		for (int j = 1; j <= K; ++j)
		{
			LL t1x1 = i + K, t1y1 = j, t1x2 = i + 2 * K - 1, t1y2 = j + K - 1;
			LL t2x1 = i, t2y1 = j + K, t2x2 = i + K - 1, t2y2 = j + 2 * K - 1;
			LL res1 = imos[t1x2][t1y2] - imos[t1x1 - 1][t1y2] - imos[t1x2][t1y1 - 1] + imos[t1x1 - 1][t1y1 - 1];
			LL res2 = imos[t2x2][t2y2] - imos[t2x1 - 1][t2y2] - imos[t2x2][t2y1 - 1] + imos[t2x1 - 1][t2y1 - 1];
			ans = std::max(ans, std::max(res1 + res2, N - res1 - res2));
		}
	}
	out << ans << std::endl;
	return 0;
}


Measured memory_bytes: 127360
fn main() {
    let n: usize = {
        let mut buf = String::new();
        std::io::stdin().read_line(&mut buf).unwrap();
        buf.trim_end().parse().unwrap()
    };

    let mut s: Vec<Vec<char>> = Vec::with_capacity(n);
    for _ in 0..n {
        let mut buf = String::new();
        std::io::stdin().read_line(&mut buf).unwrap();
        s.push(buf.trim_end().chars().rev().collect());
    }

    let mut g = vec![vec![0; 26]];
    let mut v = vec![vec![]; n];
    let mut leaves = std::collections::HashSet::new();
    for i in 0..n {
        let mut now = 0;
        for &c in &s[i] {
            v[i].push(now);
            let k = c as usize - 'a' as usize;
            if g[now][k] == 0 {
                g[now][k] = g.len();
                g.push(vec![0; 26]);
            }
            now = g[now][k];
        }
        leaves.insert(now);
    }

    let mut ans = 0;
    for i in 0..n {
        let mut check = vec![false; 26];
        for j in (0..s[i].len()).rev() {
            check[s[i][j] as usize - 'a' as usize] = true;
            let now = v[i][j];
            for k in 0..26 {
                if check[k] && leaves.contains(&g[now][k]) {
                    ans += 1;
                }
            }
        }
    }
    println!("{}", ans - n);
}

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    char ss[500050];
    string s;
    cin>>s;
    rep(i,s.size())ss[200005+i]=s[i];
    int l=200004, r=200005+s.size();
    int q;cin>>q;
    int nn=0;

    rep(i,q){
      int t;cin>>t;
      if(t==1){
        nn++;
        swap(l,r);
      }
      else if(t==2){
        int f;
        char c;
        cin>>f>>c;
        if(f==1){
          ss[l]=c;
          if(nn%2==0)l--;
          else l++;
        }
        else{
          ss[r]=c;
          if(nn%2==0)r++;
          else r--;
        }
      }
    }
    if(nn%2==0){
      for(int i=l+1;i<r;i++)cout<<ss[i];
    }
    else{
      for(int i=l-1;i>r;i--)cout<<ss[i];
    }
    cout<<endl;
    return 0;
}


Measured memory_bytes: 1104
from collections import Counter

N = int(input())
V = list(map(int, input().split()))

a1 = list(Counter(V[::2]).items())
a2 = list(Counter(V[1::2]).items())

a1.sort(key=lambda a: a[1], reverse=True)
a2.sort(key=lambda a: a[1], reverse=True)

if a1[0][0] != a2[0][0]:
    print(N - a1[0][1] - a2[0][1])
else:
    if len(a1) == 1 and len(a2) == 1:
        print(N // 2)
    elif len(a1) == 1:
        print(N - a2[1][1])
    elif len(a2) == 1:
        print(N - a1[1][1])
    else:
        print(min(N - a1[1][1] - a2[0][1], N - a1[0][1] - a2[1][1]))


Measured memory_bytes: 61804
S = list(input())
i = 0
cnt = 0
while i < len(S):
    #print(S)
    if "".join(S[i:i+2]) == "01" or "".join(S[i : i + 2]) == "10":
        if i + 1< len(S):
            S.pop(i + 1)
        S.pop(i)
        cnt += 2
        i = max(0 , i - 1)
    else:
        i += 1
print(cnt)


Measured memory_bytes: 3956
#include <bits/stdc++.h>
#define FI first
#define SE second
#define EPS 1e-9
#define ALL(a) a.begin(),a.end()
#define SZ(a) int((a).size())
#define MS(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define WHATIS(x) cout << #x << " is " << x << endl;
#define ERROR(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
//__builtin_ffs(x) return 1 + index of least significant 1-bit of x
//__builtin_clz(x) return number of leading zeros of x
//__builtin_ctz(x) return number of trailing zeros of x

using namespace std;
using ll = long long;
using ld = double;
typedef pair<int, int> II;
typedef pair<II, ll> III;
typedef complex<ld> cd;
typedef vector<cd> vcd;

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cout << *it << " = " << a << endl;
    err(++it, args...);
}

const ll MODBASE = 1000000007LL;
const int MAXN = 100010;
const int MAXM = 100010;
const int MAXK = 510;
const int MAXQ = 200010;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
  int n;
  cin >> n;
  if (n % 10 == 9 || n / 10 == 9) cout << "Yes";
  else cout << "No";
    return 0;
}

Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;

int main(){
    bool p=false;
    int A,B,ans,x,y,z;
    cin>>A>>B;
    x=A*12;
    y=B*10;
    z=min(x,y);
while(z<=(A*15)&&z<=(B*15)){
        int a=z*0.08;
        int b=z*0.1;
        if(a==A&&b==B){ans=z;p=true; break;}
        z+=1;
    }
if(p)cout<<ans;
else cout<<"-1";
    return 0;
}

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

using namespace std;

#define ll long long
#define X first
#define Y second
#define all(x) x.begin(), x.end()

const int MX = (int)1e5 + 10;
const int mod = (int)1e9 + 7;

int main(){

    cin.tie(0); cout.tie(0);
    ios_base::sync_with_stdio(0);

    int n;
    cin >> n;

    for(int i = 1; i <= 9; ++i){
        for(int j = 1; j <= 9; ++j){
            if(i * j == n){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }

    cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<queue>
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define ROF(i,a,b) for(int i=a;i>=b;i--)
using namespace std;
const int N=100100;
int n,m,T,u,v,ans,du[N],d[N],t[N],g[N],b[N],c[N],fa[N];
struct lin{int x,y;}p[N],f[N];
vector<int>ad[N],ve;
queue<int>q;
void add(int u,int v){ad[u].push_back(v);du[v]++;}
void dfs(int u){for(int v:ad[u])if(v!=fa[u]) fa[v]=u,d[v]=d[u]+1,dfs(v);}
void gtp(int x,int y){
	if(d[x]<d[y]) swap(x,y);
	for(;d[x]>d[y];x=fa[x]) c[x]++;
	for(;x!=y;x=fa[x],y=fa[y]) c[x]++,c[y]++; 
}
int main(){
	//freopen("1.in","r",stdin);
	scanf("%d%d",&n,&m);T=m;
	FOR(i,2,n) scanf("%d%d",&u,&v),add(u,v),add(v,u);
	FOR(i,1,m) scanf("%d%d",&p[i].x,&p[i].y),f[i]=p[i];
	dfs(1);
	FOR(i,1,m) gtp(p[i].x,p[i].y);
	FOR(i,1,n) ans+=min(2,c[i]),d[i]=0;
	FOR(i,1,n)if(du[i]==1) q.push(i);
	while(q.size()){
		int u=q.front(),p0=0,p1=0,w;
		q.pop();ve.clear();
		for(int v:ad[u])if(du[v]){
			w=v;du[u]--;
			if(--du[w]==1) q.push(w);
		}
		FOR(i,1,T)if(!b[i]){
			b[i]=f[i].x==u&&f[i].y==u; 
			if(!(f[i].x==u^f[i].y==u)) continue;
			ve.push_back(i);
		}
		//cout<<u<<'\n';
		//FOR(i,1,T)if(!b[i]) cout<<i<<':'<<f[i].x<<' '<<f[i].y<<'\n'; 
		while(ve.size()>1){
			int v0=ve.back(),r0=f[v0].y==u;ve.pop_back();
			int v1=ve.back(),r1=f[v1].y==u;ve.pop_back();
			b[v0]=b[v1]=1;
			f[++T]=(lin){r0?f[v0].x:f[v0].y,r1?f[v1].x:f[v1].y};
			g[v0]=g[v1]=T;d[v0]=!r0,d[v1]=r1;
		}
		if(ve.size()==1){
			int v=ve[0];
			if(f[v].x==u) f[v].x=w;
			if(f[v].y==u) f[v].y=w;
		}
	}
	ROF(i,T,1) t[i]=d[i]^t[g[i]];
	cout<<ans<<'\n';
	FOR(i,1,m){
		if(t[i]) swap(p[i].x,p[i].y);
		cout<<p[i].x<<' '<<p[i].y<<'\n';
	}
}

Measured memory_bytes: 6528
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<utility>
#include <functional>
#include <set>
#include <map>
#include <queue>
#include <cmath>
#include <stack>

using namespace std;


int main() {
	char a[3];
	cin >> a;
	char b[10] = "aiueo";
	for (int i = 0; i < 5; i++) {
		if (a[0] == b[i]) {
			cout << "vowel";
			return 0;
		}
	}
	cout << "consonant";
}

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

int main() {
    int64_t n, dvs = 1;
    cin >> n;
    for (int64_t i = 1; i <= sqrt(n); i++) {
        if (n % i == 0) {
            dvs = i;
        }
    }
    cout << dvs + (n / dvs) - 2 << endl;
}


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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define MAXN 1000010
#define rep(i,n) for (int i = 0; i < (n); ++i)
const ll mod = 1e9+7;

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

bool pairCompare(const P& firstElof, const P& secondElof)
{
    return firstElof.second < secondElof.second;
}

ll h;
int main() {
    cin >> h;
    ll ans = 1;
    ll tmp = 1;


    while (h > 1) {
        h /= 2;
        ans *= 2;
        tmp += ans;
    }

    cout << tmp << endl;


}



Measured memory_bytes: 256
N=int(input())
p=[]
r=0

if N%2==0:
  c=0
  while N%2==0:
    c+=1
    N/=2
  p.append([c])
  
i=3
while i<N**0.5+1:
  if N%i==0:
    c=0
    while N%i==0:
      c+=1
      N/=i
    p.append([c])
  i+=2
  
if N!=1:
  p.append([1])
  
for i in range(len(p)):
  j=1
  while p[i][0]>=j:
    p[i][0]-=j
    j+=1
    r+=1
    
print(r)

Measured memory_bytes: 9276
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <numeric>
using namespace std;

#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<((x))<<endl
#define fi first
#define se second

#define INF 2147483600
#define long long long

typedef pair<int, int> P;

struct edge{
  int to, w, i;
};

int main(){
  int n,m;
  cin>>n>>m;
  vector<vector<edge> > vec(n);
  vector<bool> check(m, false);
  rep(i,m){
    int a,b,c;
    cin>>a>>b>>c;
    a--;b--;
    vec[a].pb((edge{b,c,i}));
    vec[b].pb((edge{a,c,i}));
  }

  rep(i,n){
    // iからはじめる
    vector<int> d(n,INF);
    vector<vector<int> > use(n);
    priority_queue<P, vector<P>, greater<P>> pq;
    pq.push(mp(0,i)); // weight, to
    d[i]=0;
    while(!pq.empty()){
      P p = pq.top(); pq.pop();
      int v=p.se; int w=p.fi;
      if(d[v]<w) continue;
      for(edge e : vec[v]){
        int to=e.to;
        int ww=w+e.w;
        if(d[to]>=ww){
          if(d[to]>ww) use[to].clear();
          use[to].pb(e.i);
          pq.push(mp(ww, to));
          d[to] = ww;
        }
      }
    }
    for(auto v : use) for(int u : v) check[u]=true;
  }

  int ret=0;
  rep(i,m) if(!check[i]) ret++;

  cout<<ret<<endl;

  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i, m, n) for(int i = m; i < (n); i++)
#define print(x) cout << (x) << endl;
#define printv(x) for(int i = 0; i < x.size(); i++){ cout << (x[i]) << " "; } cout << endl; 
#define printa(x,n) for(int i = 0; i < n; i++){ cout << (x[i]) << " ";} cout << endl;
#define printaa(x) for(int i = 0; i < (sizeof(x)/sizeof(x[0])); i++){ for(int j = 0; j < (sizeof(x[0])/sizeof(x[0][0])); j++){ cout << x[i][j] << " ";} cout << endl;}
#define INF (1e9)
typedef long long ll;
typedef struct{
    int x;
    int y;
} P;

using namespace std;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    rep(i,0,26){
        rep(j,0,15){
            if(4 * i + 7 * j == N){
                print("Yes");
                return 0;
            }
        }
    }
    print("No");
}


Measured memory_bytes: 256
N = int(input())
A = [0] * N
for i in range(N):
    A[i] = int(input())

MAX = max(A)
cnt = 0
for i in range(N):
    if MAX == A[i]:
        cnt += 1

if cnt >= 2:
    for i in range(N):
        print(MAX)
    exit()
    
B = sorted(A)
nMAX = B[-2]
for i in range(N):
    if A[i] == MAX:
        print(nMAX)
    else:
        print(MAX)

Measured memory_bytes: 58584
n = int(input())
l = list(map(int, input().split()))
min = float('inf') 
sum = 0
for i in range(1, 100):
    for j in range(n):
        sum += (l[j] - i) * (l[j] - i)
    if min > sum:
        min = sum
    sum = 0
print(min)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;

int main() {
  int n, k;
  cin >> n >> k;
  vector<bool> snuke(n);
  for (int i = 0; i < k; i++) {
    int d;
    cin >> d;
    for (int j = 0; j < d; j++) {
      int a;
      cin >> a;
      snuke[a - 1] = true;
    }
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    if (snuke[i] == false) ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3632
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> v(n);
  for(int i=0; i<n; i++) cin >> v[i];
  sort(v.rbegin(), v.rend());
  
  int ans = 0;
  for(int i=0; i<k; i++) ans += v[i];
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3680
arr=input().split()
k=int(arr[0])
n=int(arr[1])
arr=input().split()
x_i=[int(arr[i]) for i in range(n)]
sa=0
for i in range(1,n,1):
  sa=x_i[i]-x_i[i-1] if sa<x_i[i]-x_i[i-1] else sa
sa=x_i[0]+k-x_i[n-1] if sa<x_i[0]+k-x_i[n-1] else sa
print(k-sa)

Measured memory_bytes: 27184
use std::io::prelude::*;

fn input<T>() -> T
where
    T: std::str::FromStr,
{
    let stdin = std::io::stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}

fn main() {
    let h: i64 = input();
    let w: i64 = input();
    let n: usize = input();
    let ab: Vec<(i64, i64)> = (0..n)
        .map(|_| {
            let a = input();
            let b = input();
            (a, b)
        })
        .collect();

    let mut m = std::collections::HashMap::new();
    for (a, b) in ab {
        for i in 0..3 {
            for j in 0..3 {
                let (p, q) = (a - i, b - j);
                if p > 0 && q > 0 && p + 2 <= h && q + 2 <= w {
                    let e = m.entry((p, q)).or_insert(0);
                    *e += 1;
                }
            }
        }
    }

    let mut u = vec![0; 10];
    for (_, v) in m {
        u[v] += 1;
    }
    let sum: i64 = u.iter().sum();
    u[0] = (h - 2) * (w - 2) - sum;

    for i in u {
        println!("{}", i);
    }
}


Measured memory_bytes: 55588
use whiteread::parse_line;

fn main() {
    let (h, w): (usize, usize) = parse_line().unwrap();
    let mut s: Vec<Vec<char>> = Vec::new();
    let dx = [-1, 0, 1, 0];
    let dy = [0, -1, 0, 1];
    let mut ans = true;

    for _ in 0..h {
        s.push(parse_line::<String>().unwrap().chars().collect());
    }

    'outer: for i in 0..h {
        for k in 0..w {
            if s[i][k] == '#' {
                let mut res = false;
                for d in 0..4 {
                    let ni = i as isize + dx[d];
                    let nk = k as isize + dy[d];
                    if ni < 0 || ni as usize >= h {
                        continue;
                    }
                    if nk < 0 || nk as usize >= w {
                        continue;
                    }
                    if s[ni as usize][nk as usize] == '#' {
                        res = true;
                    }
                }
                ans &= res;
                if !ans {
                    break 'outer;
                }
            }
        }
    }
    println!("{}", if ans { "Yes" } else { "No" });
}


Measured memory_bytes: 2168
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
using namespace std;
int main()
{
	int n,d;
	cin>>d>>n;
	if(d==0)
	{
		if(n==100)cout<<n+1;
		else cout<<n;
	}
	else if(d==1)
	{
		if(n==100)cout<<(n+1)*100;
		else cout<<n*100;
	}
	else 
	{
		if(n==100)cout<<(n+1)*10000;
		else cout<<n*10000;
	}
	return 0;
}

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

vector<vector<int>> graph;
vector<int> parent;
vector<int> visited;
vector<pair<int,int>> depth;

void DFS(int v, int parent_v, int d){
    parent[v] = parent_v;
    depth[v] = {d, v};

    for(int child_v : graph[v]){
        DFS(child_v, v, d+1);
    }
}

int main(){
    int s = 0;// starting point
    int n, k;
    cin >> n >> k;

    graph.resize(n);
    parent.resize(n);
    visited.resize(n);
    depth.resize(n);

    int ans = 0;
    int a0;
    cin >> a0;
    if(a0 != 1) ans = 1;

    for(int i=1; i<n; i++){
        int a;
        cin >> a;
        a -= 1;

        graph[a].push_back(i);
    }

    DFS(0,-1,0);
    sort(depth.begin(),depth.end());
    reverse(depth.begin(),depth.end());

    for(int i=0; i<n; i++){
        if(depth[i].first <= k) break;

        int current = depth[i].second;
        for(int j=0; j<k; j++){
            if(visited[current] == true) break;
            visited[current] = true;
            current = parent[current];
            if(j == k-1) ans += 1;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 14756
#include<stdio.h>

int main(){
    int a,b,tmp,n;
    scanf("%d%d",&a,&b);
    
    if(a<b){
        tmp=a;
        a=b;
        b=tmp;
    }
    while((n=a%b)!=0){
        a=b;
        b=n;
        n=a%b;
    }
    printf("%d\n",b);
    return 0;
}



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

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl << endl;}
#define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 998244353
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)

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

bool mp[111][111];

void kisuu(int n){
	REP(i, n){
		mp[i][i] = true;
		if(i != n-1)mp[i][n - 2 - i] = true;
	}
}

void guusuu(int n){
	REP(i, n){
		mp[i][i] = true;
		mp[i][n - 1 - i] = true;
	}
}

int main(){

	int n;cin >> n;

	if(n % 2)kisuu(n);
	else guusuu(n);

	vector<P> v;
	REP(i, n){
		REP(j, i){
			if(!mp[i][j])v.EB(i + 1, j + 1);
		}
	}

	cout << v.size() << endl;
	REP(i, v.size()){
		cout << v[i].FI << " " << v[i].SE << endl;
	}

	return 0;
}


Measured memory_bytes: 512
#include<stdio.h>
#include<string.h>
#define MAX 1000005
 typedef struct  d{
  char name[11];
  int time;
  char sname[11];
  int stime;
  char Ansname[11];
  int Anstime;
}date;

 
int main(){
  int n,q,i,str,tmp,tmp2,j,k=0;
  date tn[MAX];

  scanf("%d%d",&n,&q);

  for(i=1;i<n+1;i++){
    scanf("%s ",tn[i].name);
     scanf("%d",&tn[i].time);
  }
  tmp2=n+1;
  i=1;
  while(1){
   
    tn[i].stime=(tn[i].time-q);
    if(tn[i].stime>0){
       
     
      tn[tmp2].time=tn[i].stime;
      strcpy(tn[i].sname,tn[i].name);
      strcpy(tn[tmp2].name,tn[i].sname);
      str+=q;
      if(tmp2==n+1){
	tmp2=1;
      }
      else{
	tmp2++;
      }
      if(i==n+1){
	i=1;
      }
      else{
	i++;
      }
      
    }
    else{
     
      str+=tn[i].time;
      tn[k].Anstime=str;
      tn[i].time=0;
      strcpy(tn[k].Ansname,tn[i].name);
      k++;
      strcpy ( tn[i].name," ");
      if(i==n+1){
	i=1;
      }
      else{
	i++;
      }
    }
    if(k==n){
      break;
    }

  }
  for(j=0;j<n;j++){
    printf("%s %d\n",tn[j].Ansname,tn[j].Anstime);
  }
  return 0;
}



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

using namespace std;

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

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

int main(){
  string s;
  cin>>s;
  if(s.size() < 26){
    char c = 'a';
    while(true){
      bool ok = true;
      REP(i,s.size())if(s[i]==c){
        ok = false;
      }
      if(ok){
        s += string(1,c);
        cout<<s<<endl;
        return 0;
      }else{
        c++;
      }
    }
  }else{
    if(s=="zyxwvutsrqponmlkjihgfedcba"){
      cout<<-1<<endl;
    }else{
      vector<bool> ava(26,false);
      FORR(i,0,s.size()){
        char c = s[i];
        for(char d=c+1;d<='z';d++){
          if(ava[d-'a']){
            string t = s.substr(0,i) + string(1,d);
            cout<<t<<endl;
            return 0;
          }
        }
        ava[c-'a'] = true;
      }
    }
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <cmath>
using namespace std;
int a[100010];
vector<pair<int,int>> v;
int main(){
	int i,n,cnt = 0;
	cin >> n;
	for(i=0;i<n;i++){
		cin >> a[i];
		if(a[i]>=0) cnt++;
	}
	sort(a,a + n);
	int ans;
	if(cnt==0){
		int x = a[n-1];
		for(i=0;i<n-1;i++){
			v.push_back({x,a[i]});
			x -= a[i];
		}
		ans = x;
	}else if(cnt==n){
		int x = a[0];
		for(i=1;i<n-1;i++){
			v.push_back({x,a[i]});
			x -= a[i];
		}
		v.push_back({a[n-1],x});
		ans = a[n-1] - x;
	}else{
		int x = a[0];
		for(i=0;i<n-1;i++){
			if(a[i]<0) continue;
			v.push_back({x,a[i]});
			x -= a[i];
		}
		v.push_back({a[n-1],x});
		x = a[n-1] - x;
		for(i=1;i<n;i++){
			if(a[i]>=0) break;
			v.push_back({x,a[i]});
			x -= a[i];
		}
		ans = x;
	}
	cout << ans << endl;
	for(i=0;i<n-1;i++){
		cout << v[i].first << " " << v[i].second << endl;
	}
}
		
		

Measured memory_bytes: 3188
import sys
input = lambda: sys.stdin.readline().rstrip()

def main():
    n = int(input())
    v = sorted(list(map(int, input().split())))
    for _ in range(n-1):
        v.append((v.pop(0) + v.pop(0)) / 2)
        v.sort()
    print(*v)

if __name__ == '__main__':
    main()

Measured memory_bytes: 9192
#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 10;
char lx[N];

int main() {
  int n;
  scanf("%d%s", &n, lx + 1);
  int pos = 0;
  for(int i = 1; i <= n; ++i) {
    if(lx[i] == 'E') pos++;
  }
  int ans = n, tmp = 0;
  for(int i = 1; i <= n; ++i) {
    if(lx[i] == 'E') pos--;
    ans = min(ans, pos + tmp);
    if(lx[i] == 'W') tmp++;
  }
  printf("%d\n", ans);
  return 0;  
}

Measured memory_bytes: 512
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<math.h>

using namespace std;

typedef long long ll;

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


bool sosu(ll n) {
	if (n == 2)return true;
	if (n % 2 == 0)return false;
	for (int i = 3; i <= sqrt(n); i++) {
		if (n % i == 0) {
			return false;
		}
	}
	return true;
}


signed main() {
	
	int n;
	string s;
	cin >> n >> s;
	int a[10000];
	rep(i, s.length()) {
		a[i] = (int)s[i] - 64 + n;
	}
	for (int i = 0; i < s.length(); i++) {
		switch (a[i] % 26) {
		case 1:
			cout << "A";
			break;
		case 2:
			cout << "B";
			break;
		case 3:
			cout << "C";
			break;
		case 4:
			cout << "D";
			break;
		case 5:
			cout << "E";
			break;
		case 6:
			cout << "F";
			break;
		case 7:
			cout << "G";
			break;
		case 8:
			cout << "H";
			break;
		case 9:
			cout << "I";
			break;
		case 10:
			cout << "J";
			break;
		case 11:
			cout << "K";
			break;
		case 12:
			cout << "L";
			break;
		case 13:
			cout << "M";
			break;
		case 14:
			cout << "N";
			break;
		case 15:
			cout << "O";
			break;
		case 16:
			cout << "P";
			break;
		case 17:
			cout << "Q";
			break;
		case 18:
			cout << "R";
			break;
		case 19:
			cout << "S";
			break;
		case 20:
			cout << "T";
			break;
		case 21:
			cout << "U";
			break;
		case 22:
			cout << "V";
			break;
		case 23:
			cout << "W";
			break;
		case 24:
			cout << "X";
			break;
		case 25:
			cout << "Y";
			break;
		case 0:
			cout << "Z";
			break;
		}
	}

	return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <numeric>
#include <regex>
#include <tuple>
#include<iomanip>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
#define MOD 1000000007 // 10^9 + 7
#define INF 1000000000 // 10^9
#define LLINF 1LL<<60

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

	int N; cin >> N;
	ll ans = 1;
	int g[3]; for (int i = 0; i < 3; i++) g[i] = 0;
	for (int i = 0; i < N; i++) {
		int a; cin >> a;
		int pos = -1;
		ll cnt = 0;
		for (int i = 0; i < 3; i++) {
			if (g[i] == a) {
				cnt++;
				pos = i;
			}
		}
		g[pos]++;
		ans *= cnt; ans %= MOD;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORq(i, m, n) for(int i = (m);i <= (n);++i)
#define SCD(n) scanf("%d",&n)
#define SCD2(m,n) scanf("%d%d",&m,&n)
#define SCD3(m,n,k) scanf("%d%d%d",&m,&n,&k)
#define PB push_back
#define MP make_pair
#define ARSCD(A,N) REP(i,N){SCD(A[i]);}
#define ARSCD1(A,N) FORq(i,1,N){SCD(A[i]);}
#define PRINTD(n) printf("%d\n",n)
#define PRINTLLD(n) printf("%lld\n",n)
#define DEBUG printf("%s\n","debug")
#define fst first
#define snd second
#define IN(x,S) (S.count(x) != 0)
using namespace std;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef long long ll;
//////////////////////////////////////////////////////
int main(){
	int a,b; SCD2(a,b);
	int s[1001];
	s[0] = 0;
	FORq(i,1,999){
		s[i] = s[i-1] + i;
	}
	
	int k = b - a;
	PRINTD(s[k-1] - a);
	
	
	
	
	return 0;
}



Measured memory_bytes: 256
/*
これを入れて実行
g++ code.cpp
./a.out
 */

#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <cmath>
#include <tuple>
#include <iomanip>

using namespace std;
typedef long long ll;
typedef long double ld;

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

const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;

bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}

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

//-----------------------ここから-----------


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

    vector<ll> h(n);

    for(ll i = 0; i < n; i++){
        cin >> h[i];
    }

   for(int i = n - 1; i >= 1; i--){
       if(i == n - 1){
           if(h[i] < h[i - 1]){
               h[i - 1]--;
               if(h[i] < h[i - 1]){
                   break;
                }
            }
           continue;
        }

        
        if(h[i] < h[i - 1]){
            h[i - 1]--;
            if(h[i] < h[i - 1]){
                break;
            }
        }
    }
    
    bool ok = true;
    for(int i = 0; i < n - 1; i++){
        if(h[i] > h[i + 1]){
            ok = false;
            break;
        }
    }

    if(ok){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}



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

using namespace std;

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

#define F first
#define S second
#define PB push_back
#define MK make_pair
#define REP(i, a, b) for (int i=a; i < b; i++)


bool sort_by(vi c, vi d){
	return c.S < d.S;
}

bool check(int j, string s1){
	if(s1[j] == '-') return true;
	else return false;
}


int main() {
	int a, b;
	string s, ans="Yes";
	cin >> a >> b >> s;
	
	REP(i, 0, a+b+1){
		if((s[i] == '-' && i != a) || (s[i] != '-' && i == a)) ans = "No";
	}
	cout << ans;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fastIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
using namespace std;   
int a[100003];
int dp[100003];
int main(){
	fastIO;       
	int inf = (int)1e9+7;  
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i];	
		dp[a[i]]++;
	}
	int cnt=1;
	if(n%2){
		if(dp[0] == 1){
			for(int i=2;i<=n;i+=2){
				if(dp[i] == 2){
					cnt=(cnt*2) % inf;
					//cout<<cnt<<endl;
				}
				else{
					cnt=0;
					break;
				}
			}
		}
		else cnt=0;
	}
	else{
		for(int i=1;i<=n;i+=2){
			if(dp[i] == 2)cnt=(cnt*2) % inf;
			else{
				cnt=0;
				break;
			}
		}
	}
	cout<<cnt%inf<<'\n';
	return 0;
}

Measured memory_bytes: 1024