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

using namespace std;

typedef long long ll;

const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = (ll)1e9 + 7;

ll cal(int len, int H, int W)
{
  ll ret = LLINF;
  ll a1 = 1LL * len * H;
  ll a2 = 1LL * (W - len) * (H / 2), a3 = 1LL * (W - len) * (H - (H / 2));
  ret = min(ret, max({ a1, a2, a3 }) - min({ a1, a2, a3 }));

  a2 = 1LL * H * ((W - len) / 2);
  a3 = 1LL * H * (W - len - (W - len) / 2);
  return min(ret, max({ a1, a2, a3 }) - min({ a1, a2, a3 }));
}

int main()
{
  int H, W; scanf("%d %d", &H, &W);
  ll ans = LLINF;
  for (int i = 1; i * 2 <= W; ++i) {
    ans = min(ans, cal(i, H, W));
  }

  for (int i = 1; i * 2 <= H; ++i) {
    ans = min(ans, cal(i, W, H));
  }
  printf("%lld\n", ans);
  return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) throws Exception{
        BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter output = new PrintWriter(System.out);
        int N = Integer.parseInt(input.readLine());
        int[][] dp = new int[N][3];
        int[] A = new int[N];
        int[] B = new int[N];
        int[] C = new int[N];
        for(int n = 0; n<N; n++){
            StringTokenizer st = new StringTokenizer(input.readLine());
            A[n] = Integer.parseInt(st.nextToken());
            B[n] = Integer.parseInt(st.nextToken());
            C[n] = Integer.parseInt(st.nextToken());
        }
       
        dp[0][0] = A[0];
        dp[0][1] = B[0];
        dp[0][2] = C[0];

        for(int i = 1; i<N; i++){
            for(int j = 0; j<3; j++){
                for(int k = 0; k<3; k++){
                    if(j!=k){
                        if(j == 0) dp[i][j] = Math.max(dp[i][j], dp[i-1][k] + A[i]);
                        else if(j == 1) dp[i][j] = Math.max(dp[i][j], dp[i-1][k] + B[i]);
                        else dp[i][j] = Math.max(dp[i][j], dp[i-1][k] + C[i]);
                    }
                }
            }
        }

        /*for(int i = 0; i<N; i++){
            for(int j = 0; j<3; j++){
                output.print(dp[i][j] + " ");
            }
            output.println();
        }*/

        output.println(Math.max(dp[N-1][0], Math.max(dp[N-1][1], dp[N-1][2])));
        output.close();
    }
}

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

int main(){
    int n;
    cin >> n;
    int a[n];
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    int count = 10000;
    for(int i = 0; i < n; i++){
        int asd = 0;
        while(a[i] % 2 == 0){
            a[i] = a[i] / 2;
            asd += 1;
        }
        if(asd < count){
            count = asd;
        }
    }
    cout << count << endl;
    return 0;
}


Measured memory_bytes: 256
// Date: 2020-06-21

#include <bits/stdc++.h>
using namespace std;

typedef long long LL;
typedef long double LD;
typedef vector<int> VI;
typedef pair<LL, LL> pll;
typedef pair<int, int> pii;
#define IO freopen("in.txt", "r", stdin);freopen("out.txt", "w", stdout)
#define FIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define rep(i, a, b) for(int i = int(a); i <= int(b); ++i)
#define per(i, b, a) for(int i = int(b); i >= int(a); --i)
#define D(x) cout << #x << " = " << x << endl;
#define mem(x, y) memset(x, y, sizeof(x))
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)x.size())
#define mk make_pair
#define pb push_back
#define fi first
#define se second
const LL INF = 1e18;
const LL mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const int N = 2e5 + 10;
template <typename T> void chkmax(T &x, T y) { x = max(x, y); }
template <typename T> void chkmin(T &x, T y) { x = min(x, y); }
LL qpow(LL x, LL y, LL MOD) {LL a=1; while(y){ if(y&1) a=a*x%MOD; x=x*x%MOD; y>>=1; } return a;}

int main() {
	char c;
	cin >> c;
	if(c >= 'a' && c <= 'z') cout << "a";
	else cout << "A";

	return 0;
}

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

using namespace std;

const int maxn = 310;

int n;
double dp[maxn][maxn][maxn];

int main(){
	cin >> n;
	int s1 = 0, s2 = 0, s3 = 0;
	for (int i = 0; i < n; i++){
		int a;
		cin >> a;
		if (a == 1)
			s1++;
		if (a == 2)
			s2++;
		if (a == 3)
			s3++;
	}
	dp[0][0][0] = 0;
	for (int k = 0; k <= n; k++){
		for (int j = 0; j <= n; j++){
			for (int i = 0; i <= n; i++){
				if (i == 0 && j == 0 && k == 0)
					continue;
				if (i > 0)
					dp[i][j][k] += (dp[i-1][j][k]+1) * i/n;
				if (j > 0)
					dp[i][j][k] += (dp[i+1][j-1][k]+1) * j/n;
				if (k > 0)
					dp[i][j][k] += (dp[i][j+1][k-1]+1) * k/n;
				double p0 = (double)(n - i - j - k)/n;
				dp[i][j][k] = (dp[i][j][k] + p0)/(1-p0);
			}
		}
	}
	printf("%.9f", dp[s1][s2][s3]);
	return 0;
}


Measured memory_bytes: 227584
#include<stdio.h>
int main(void){
  int i;
  int a=0;
  char s[100];
  scanf("%s",s);
  for(i=0;s[i]!='\0';i++){
    a+=1;
  }
  for(i=0;i<a;i++){
    s[i]='x';
  }
  printf("%s",s);
  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define X first
#define Y second
#define pb emplace_back
#define FOR(i,a,b) for(int (i)=(a);i<(b);++(i))
#define EFOR(i,a,b) for(int (i)=(a);i<=(b);++(i))
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define REP rep
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define all(X) (X).begin(),(X).end()
#define eb emplace_back

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef ll LL;
typedef pii PII;
typedef pll PLL;
const ll MOD=1e9+7;

#define rall(X) (X).rbegin(),(X).rend()
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())
#define reps(X,S,Y) for (int (X) = S;(X) < (Y);++(X))
#define rreps(X,S,Y) for (int (X) = (Y)-1;(X) >= (S);--(X))
template<class T> inline bool MX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool MN(T &l,const T &r){return l>r?l=r,1:0;}

int N;
int sz[5145];
LL fact[5145];
LL rev[5145];
vector<int> cent;
vector<int> es[5145];
vector<LL> dp[5145];

void Dfs(int v, int p) {
  sz[v] = 1;

  bool fail = false;
  for (int u : es[v]) {
    if (u == p) continue;
    Dfs(u, v);
    sz[v] += sz[u];
    if (N/2 < sz[u]) fail = true;
  }
  if (N/2 < N-sz[v]) fail = true;

  if (!fail) cent.eb(v);
}

LL mypow(LL base, LL exp) {
  if (!exp) return 1;
  LL res = mypow(base*base%MOD, exp/2);
  if (exp%2) res = res*base%MOD;
  return res;
}

LL Comb(LL n, LL k) {
  return fact[n] * rev[k] % MOD * rev[n-k] % MOD;
}

LL Solve(vector<int> &S) {
  int m = S.size();
  int sum = 0;
  for (int s : S) sum += s;

  dp[0].assign(1, 1);
  
  int lim = 0;
  rep(i, m) {
    dp[i+1].assign(dp[i].size() + S[i], 0);
    rep(j, dp[i].size()) {
      rep(t, S[i]+1) {
        LL c = Comb(S[i], t);
        c = c*c % MOD * fact[t] % MOD;
        dp[i+1][j+t] += c * dp[i][j];
        dp[i+1][j+t] %= MOD;
      }
    }
  }

  LL ans = fact[sum];
  reps(t, 1, dp[m].size()) {
    LL v = dp[m][t] * fact[sum - t] % MOD;
    if (t%2) {
      ans += MOD - v;
    } else {
      ans += v;
    }
    if (ans >= MOD) ans -= MOD;
  }
  //cout << "ret: " << ans << endl;
  return ans;
}

signed main(){
  ios_base::sync_with_stdio(false);
  cout<<fixed<<setprecision(0);

  cin >> N;
  fact[0] = rev[0] = 1;
  reps(i, 1, N+1) {
    fact[i] = fact[i-1] * i % MOD;
    rev[i] = rev[i-1] * mypow(i, MOD-2) % MOD;
  }

  rep(i, N-1) {
    int x, y;
    cin >> x >> y;
    --x;
    --y;
    es[x].eb(y);
    es[y].eb(x);
  }

  Dfs(0, 0);
  assert(!cent.empty() && cent.size() <= 2);
  vector<int> ss;
  LL ans;
  if (cent.size() == 2) {
    assert(N%2 == 0);
    ss.eb(N/2);
    ss.eb(N/2);
    ans = Solve(ss);
  } else {
    int r = cent[0];
    //cout << "cent: " << r << endl;
    fill(sz, sz+N, 0);
    Dfs(r, r);

    for (int v : es[r]) {
      ss.eb(sz[v]);
    }
    ss.eb(1);
    ans = Solve(ss);
    ss.pop_back();
    ans += Solve(ss);
    if (ans >= MOD) ans -= MOD;
  }
  cout << ans << endl;
}


Measured memory_bytes: 98560
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 10000000000000000

#define Edge pair<long long,int>


		


int main(){
	
	long long N,X;
	cin>>N>>X;
	
	long long a = X,b = N-X;
	
	long long ans = a+b;
	
	while(true){
		if(a>b){
			if(a%b==0){
				ans += 2*a-b;
				break;
			}
			
			
			long long k = a-b;
			long long n = (k+b-1)/b;
			ans += n*2*b;
			a -= n*b;
		}
		else{
			if(b%a==0){
				ans += 2*b-a;
				break;
			}
			
			
			long long k = b-a;
			long long n = (k+a-1)/a;
			ans += n*2*a;
			
			b -= n*a;
		}
	}
	
	cout<<ans<<endl;
	
	
	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <vector>

#define FOR(i,k,n) for (int (i)=(k); (i)<(n); ++(i))
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define all(v) begin(v), end(v)
#define debug(x) cerr<< #x <<": "<<x<<endl
#define debug2(x,y) cerr<< #x <<": "<< x <<", "<< #y <<": "<< y <<endl

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<ll> vll;
typedef vector<vector<ll> > vvll;
template<class T> using vv=vector<vector< T > >;

int n, m;
vvi g;
int main() {
  scanf("%d %d", &n, &m);
  g.assign(n, vi(n, 0));
  rep (i, m) {
    int a, b;
    scanf("%d %d", &a, &b);
    a -= 1; b -= 1;
    g[a][b] = 1;
    g[b][a] = 1;
  }
  vi data(n);
  rep (i, n) {
    data[i] = i;
  }
  int ans = 0;
  int cnt = 0;
  do {
    assert (data[0] == 0);
    cnt += 1;
    bool flag = true;
    rep (i, n-1) {
      if (g[data[i]][data[i+1]] == 0) {
        flag = false;
        break;
      }
    }
    if (flag) {
      ans += 1;
    }
  } while (next_permutation(begin(data) + 1, end(data)));
  printf("%d\n", ans);

  return 0;
}


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

int main()
{
  //int A, B, C, X, Y;
//  int m[101]={};
  int A, B, C, D;
  //int ans=1;
  char comp[6]={};
//  int sosu[20000]={};
  char s[5001]={};
  char x[5001]={};
  char y[5001]={};
  char abc[27]={};
  int cnt=0;
  int len;
  int ans[2]={};
  int i,j,k,l;
  int flag=0;  
//    int k=0;

  scanf("%d", &A);
  scanf("%s", &s);

  for(i=1;i<A;i++){
    strncpy(x,s,i);
    strncpy(y,&s[i],A-i);  
    x[i+1] = '\0';
    y[A-i] = '\0';

    for(j=0;j<26;j++){
      for(k=0;k<i;k++){
         if(x[k] == (0x61 + j)){
           abc[j]=1;
         }
      }
      for(k=0;k<A-i;k++){
         if(y[k] == (0x61 + j)){
           if(abc[j]==1){
             abc[j]=2;
             cnt++;
           }
         }
      }
    }
    if(ans[0]<cnt) ans[0]=cnt;
    cnt=0;
  }
  
  printf("%d\n", ans[0]);
  
//  printf("%d\n", &ans[0]);
  
return 0;
}


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

bool compare_by_b(pair<int, int> a, pair<int, int> b) {
    return a.second < b.second;
}

int main(){
    int N,K;
    string t;
    cin >> N >>K;
    vector<pair<int,int>> p;
    int R,S,P;
    cin >> R >> S >> P;
    cin >>t;
    

    rep(n,N){
        if(t[n] == 'r'){
        t[n] = 'p';
        }
        else if(t[n] == 'p'){
        t[n] = 's';
        }
        else if(t[n] == 's'){
        t[n] = 'r';
        }
    }
    
    int ans = 0;
    rep(n,N){
        if(n>=K){
            if(t[n-K] == t[n]){
                t[n] = 'x';
            }
        }
        if(t[n] == 'r'){
        ans+=R;
        }
        else if(t[n] == 'p'){
        ans+=P;
        }
        else if(t[n] == 's'){
        ans+=S;
        }
    }
    //cout<<t<<endl;
    cout<<ans<<endl;

}

Measured memory_bytes: 512
def double(i, k):
    cnt = 0
    while True:
        if i >= k:
            break
        i *= 2
        cnt += 1
    return cnt


def main():
    N, K = map(int, input().split())
    ans = 0
    for i in range(1, N+1):
        ans += 1/N * (0.5**double(i, K))
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const int INF=1e9;

int main(){
    string s;
    cin>>s;
    int ans=0,d=0;
    for(char c:s){
        if(d>0){
            if(c=='g')ans+=1;
            d--;
        }
        else{
            if(c=='p')ans-=1;
            d++;
        }
    }
    cout<<ans<<endl;
}


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

#define lint long long

lint MOD = 1000000007;

using namespace std;

int main(){
    int N;
    cin >> N;
    string S1, S2;
    cin >> S1 >> S2;
    
    lint ans = 1;
    int state;
    int pos = 0;
    
    if(S1[0] == S2[0]){
        ans *= 3;
        pos = 1;
    } else {
        ans *= 6;
        pos = 2;
    }
    
    while(pos < N){
        if(S1[pos-1] == S2[pos-1]){
            if(S1[pos] == S2[pos]){
                ans *= 2;
                pos++;
            } else {
                ans *= 2;
                pos += 2;
            }
        } else {
            if(S1[pos] == S2[pos]){
                ans *= 1;
                pos++;
            } else {
                ans *= 3;
                pos += 2;
            }
        }
        ans %= MOD;
    }
    cout << ans << endl;
    
}






Measured memory_bytes: 256
N,M = map(int,input().split())
H = list(map(int,input().split()))
AB = [list(map(int,input().split())) for i in range(M)] #[道iが繋げる展望台は][a,b]

nearheight = [[] for i in range(N)] #[展望台Nに][隣接する展望台の高さ]
for i in range(M): #道の数だけループ
    nearheight[AB[i][0]-1].append(H[AB[i][1]-1])
    nearheight[AB[i][1]-1].append(H[AB[i][0]-1])

count = 0
for i in range(N):
    if nearheight[i] == []:
        count += 1
    elif all(k < H[i] for k in nearheight[i]):
        count += 1

print(count)

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

int main() {
    string S; cin >> S;
    int N = S.size();
    if(N%2) {
        cout << "No" << '\n';
        return 0;
    }
    for(int i = 0; i < N - 1; i += 2) {
        if(S[i] == 'h' && S[i + 1] == 'i') continue;
        else {
            cout << "No" << '\n';
            return 0;
        }
    }
    cout << "Yes" << '\n';
    return 0;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(1000000000)
input = sys.stdin.readline
n = int(input())
es=[[] for i in range(n)]
for i in range(n - 1):
   a, b = map(int, input().split())
   es[a - 1].append(b - 1)
   es[b - 1].append(a - 1)
def dfs0(v, d, p):
    if v == n - 1:
        return d
    for e in es[v]:
        if e != p:
            k = dfs0(e, d + 1, v)
            if k:
                if isinstance(k, int) and k // 2 == d:
                    return v, e
                return k
    return 0

def dfs1(v, p):
    if v == E:
        return 0
    cnt = 1
    for e in es[v]:
        if e != p:
            cnt += dfs1(e, v)
    return cnt

def dfs2(v, p):
    if v == 0:
        return 0
    cnt = 1
    for e in es[v]:
        if e != p:
            cnt += dfs2(e, v)
    return cnt
V, E = dfs0(0, 0, -1)
if  2*dfs1(0, -1) > n:
    print("Fennec")
else:
    print("Snuke")


Measured memory_bytes: 118008
#include<bits/stdc++.h>
#define N (200009)
#define LL long long
using namespace std;
int n;
char s[N];
int main()
{
	scanf("%s",s+1);
	n=strlen(s+1);
	LL ans=0;
	for(int i=1,L=1;i<=n;++i)
		if(s[n-i+1]=='B') ans+=i-L, ++L;
	printf("%lld",ans);
}


Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <cmath>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ROF(i,a,b) for(int i=b-1;i>=a;i--)
#define FI first
#define SE second
#define MA(i,j) make_pair(i,j)
#define PA pair<int,int>
#define PB push_back
#define PQ priority_queue<int>
#define PGQ priority_queue<int,vector<int>,greater<int> >
#define VE vector<int>
#define VP vector<PA>
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define Yes(i) cout<<(i?"Yes":"No")<<endl
#define MOD 1000000007
#define INF 1000000007
using namespace std;
//
int main(){
  int N;
  int A[100000];
  VE V;
  set<int> S;
  cin>>N;
  FOR(i,0,N){
    cin>>A[i];
    if(S.find(A[i])==S.end()){
      S.insert(A[i]);
    }else{
      V.PB(A[i]);
    }
  }
  int num=S.size();
  sort(V.begin(),V.end());
  if(V.size()%2==0){
    cout<<num<<endl;
  }else{
    cout<<num-1<<endl;
  }
  return 0;
}


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

const int N = 1e5;

ll dist[2][N];
ll dp[2][N];
int n, m;
using P = tuple<ll, int>;
vector<P> treeone[N]; // not tree, graph
constexpr int mod = 1e9 + 7;

void dijkstra(int s, int x) {
  for(int i = 0; i < n; i++) dist[x][i] = 1e18;
  priority_queue<P, vector<P>, greater<P> > pq;
  pq.emplace(0, s);
  dist[x][s] = 0;
  dp[x][s] = 1;
  while(pq.size()) {
    ll d = get<0>(pq.top()); int i = get<1>(pq.top());
    pq.pop();
    if(dist[x][i] < d) continue;
    for(auto to : treeone[i]) {
      int j = get<0>(to), co = get<1>(to);
      if(dist[x][j] > d + co) {
        dp[x][j] = dp[x][i];
        dist[x][j] = d + co;
        pq.emplace(d + co, j);
      } else if(dist[x][j] == d + co) {
        (dp[x][j] += dp[x][i]) %= mod;
      }
    }
  }
}

int main() {
  ios::sync_with_stdio(false), cin.tie(0);
  cin >> n >> m;
  int s, t; cin >> s >> t; s--; t--;
  for(int i = 0; i < m; i++) {
    int a, b, c; cin >> a >> b >> c;
    a--; b--;
    treeone[a].emplace_back(b, c);
    treeone[b].emplace_back(a, c);
  }
  dijkstra(s, 0);
  dijkstra(t, 1);
  ll ans = dp[0][t] * dp[1][s] % mod;
  for(int i = 0; i < n; i++) {
    if(2 * dist[0][i] == dist[0][t]) {
      ans -= dp[0][i] * dp[1][i] % mod * dp[0][i] % mod * dp[1][i] % mod;
    }
    for(auto to : treeone[i]) {
      int j = get<0>(to), w = get<1>(to);
      if(dist[0][i] + dist[1][j] + w == dist[0][t] &&
          2 * dist[0][i] < dist[0][t] && dist[0][t] < 2 * dist[0][i] + 2ll * w) {
        ans -= dp[0][i] * dp[1][j] % mod * dp[0][i] % mod * dp[1][j] % mod;
      }
    }
  }
  ans = (ans % mod + mod) % mod;
  cout << ans << endl;
}



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

int main()
{
    size_t K;
    string S;
    cin >> K >> S;

    if (S.size() <= K)
    {
        cout << S << endl;
    }
    else
    {
        for (size_t i = 0; i < K; i++)
        {
            cout << S[i];
        }
        cout << "..." << endl;
    }
}


Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> pii;
const ll INF = 1e9+100;
const ll INFL = 1e18+100;
const ll MOD = 1e9+7;
const bool debug = 0;
//-----------------------------------------------//

int N;
string S;

int main() {
	cin >> N >> S;
	
	int ans = INF;
	int l = 0, r = 0;
	REP(i, S.size()) if (S[i] == 'E') r++;
	
	REP(i, S.size()) {
		if (S[i] == 'E') r--;
		chmin(ans, l + r);
		if (S[i] == 'W') l++;
	}
	
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 900
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template < typename T > string tost( const T& n ) { ostringstream stm; stm << n; return stm.str();}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1;} return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1;} return 0;}
int const INF = 1001001001;


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

string S;
cin >> S;
int N = S.size();
if(N == 1) {
    cout << 0 << endl;
    return 0;
}

int cnt = 0;
rep(i,N-1) {
    if(S[i] != S[i+1]) cnt++;
}
cout << cnt << endl;
return 0;
}

Measured memory_bytes: 512
#include <cstdio>
#include <algorithm>
using namespace std;

int a, b, c, N, i[1000], j[1000], k[1000], r[1000], h[301];

int main(){
    while(scanf("%d%d%d", &a, &b, &c), a+b+c){
        scanf("%d", &N);
        for(int x = 0; x < N; x++){
            scanf("%d%d%d%d", i+x, j+x, k+x, r+x);
        }
        fill(h, h+301, 2);
        for(int x = 0; x < N; x++){
            if(r[x] == 1){
                h[i[x]] = h[j[x]] = h[k[x]] = 1;
            }
        }
        for(int x = 0; x < N; x++){
            if(r[x]) continue;
            if(h[i[x]]%2 + h[j[x]]%2 + h[k[x]]%2 == 2){
                if(h[i[x]]/2){
                    h[i[x]] = 0;
                }
                if(h[j[x]]/2){
                    h[j[x]] = 0;
                }
                if(h[k[x]]/2){
                    h[k[x]] = 0;
                }
            }
        }
        for(int x = 1; x <= a+b+c; x++){
            printf("%d\n", h[x]);
        }
    }
    return 0;
}

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

ll po(ll i,ll p){
    if(p==0)return 1;
    else{
        i=mod(i);
        if(p==1)return i;
        if(p%2==0)return po(mod(i*i),p/2);
        return mod(i*po(i,p-1));
    }
}
ll bunbo(ll n){
    return po(n,i_5);
}
ll p1=1009;

int main(){fastio
    ll n;cin>>n;
    ll a[n+1],b[2*n];
    rep(i,0,n-1)cin>>a[i];
    a[n]=a[0];
    rep(i,0,n-1)cin>>b[i];
    rep(i,n,2*n-1)b[i]=b[i%n];
    ll c[n],d[2*n-1];
    rep(i,0,n-1)c[i]=a[i+1]^a[i];
    rep(i,0,2*n-2)d[i]=b[i+1]^b[i];
    ll sc[n+1],sd[2*n];
    sc[0]=0;sd[0]=0;
    rep(i,0,n-1){
        sc[i+1]=c[i]*po(p1,i);
        Add(sc[i+1],sc[i]);
    }
    vector<l_l>ans;
    rep(i,0,2*n-2){
        sd[i+1]=d[i]*po(p1,i);
        Add(sd[i+1],sd[i]);
    }
  //  rep(i,0,n)cout<<sc[i]<<" ";cout<<endl;
  //  rep(i,0,2*n-1)cout<<sd[i]<<" ";cout<<endl;
    rep(i,n,2*n-1){
        ll sum=mod(sd[i]-sd[i-n])*bunbo(po(p1,i-n));
        ll y=b[i]^a[0];
        if(mod(sum-sc[n])==0){
            if(i==n)ans.pb(l_l(0,y));
            else ans.pb(l_l(2*n-i,y));
        }
    }
    sort(ans.begin(),ans.end());
    for(auto x:ans){
        cout<<x.fi<<" "<<x.se<<endl;
    }
    
    return 0;
}


Measured memory_bytes: 20844
#include <bits/stdc++.h>
using namespace std;
const int con=8;
  int N;
  int ans;
  bool flag[8];
int main(void)
{
  int CountA;
  int Count;
  CountA=0;
  Count=0;
  cin>>N;
  for(int i=0;i<N;i++){
    cin >> ans;
    ans=ans/400;
    
    if(ans>=con){
      CountA++;
    }else{
      flag[ans]=true;
    }
    
  }
  for(int i=0;i<con;i++){
    if(flag[i])Count++;
  }
  if(Count==0){
    Count=1;
  }else{
    CountA+=Count;
  }
  cout <<Count<<" "<<CountA<< endl;
  return 0;
}

Measured memory_bytes: 256
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    from itertools import product
    s = input()
    c = ["KIH", "B", "R", ""]
    p = []

    for bit in product(range(2), repeat=4):
        cur = ""
        for i in range(4):
            if bit[i]:
                cur += "A"
            cur += c[i]
        p.append(cur)

    if s in p:
        print("YES")
    else:
        print("NO")


if __name__ == '__main__':
    main()


Measured memory_bytes: 61972
/*
    Author:zeke

    pass System Test!
    GET AC!!
*/
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using ll = long long;
using ld = long double;
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define rep3(var, min, max) for (ll(var) = (min); (var) < (max); ++(var))
#define repi3(var, min, max) for (ll(var) = (max)-1; (var) + 1 > (min); --(var))
#define Mp(a, b) make_pair((a), (b))
#define F first
#define S second
#define Icin(s) \
    ll(s);      \
    cin >> (s);
#define Scin(s) \
    ll(s);      \
    cin >> (s);
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;
}
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef vector<V> VV;
typedef vector<P> VP;
ll mod = 1e9 + 7;
ll MOD = 1e9 + 7;
ll INF = 1e18;
// cout << "Case #" << index << " :IMPOSSIBLE";
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    ll k;
    cin>>k;
    rep(i,k){
        cout<<"ACL";
    }
    cout<<endl;
}


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

using namespace std;

int main(){
	int n;
	cin >> n;
	
	vector<int> a(n);
	
	
	for (int i=0; i<n; ++i) {
		cin >> a.at(i);
	}
	
	double res = 0;
	for (int i=0; i<n; ++i) {
		res += 1.0 / a.at(i);
	}
	
	cout << 1.0 / res << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
string lcs(string s,string t){
    int n=s.length();
    int m=t.length();
    int dp[n+1][m+1];
    for(int i=0;i<=m;i++)
        dp[0][i]=0;
    for(int i=0;i<=n;i++)
        dp[i][0]=0;

    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
                if(s[i-1]==t[j-1])
                   dp[i][j]=dp[i-1][j-1]+1;
                else
                   dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
            }
    }
    
   string ans="";
   while(n>0 && m>0){
       if(s[n-1]==t[m-1]) {ans=s[n-1]+ans; n--;m--;}
       else if(dp[n-1][m]>dp[n][m-1]){n--;}
       else {m--;}
   }
   return ans;
}




int main(){
    string s,t;
    cin>>s>>t;
    cout<<lcs(s,t)<<endl;
    return 0;
}

Measured memory_bytes: 38804
#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
#define dbg(x) cerr << #x << " = " << x << endl
#define _ << ' ' <<
using namespace std;
using ll = long long;
using vi = vector<int>;


int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, T;
    cin >> n >> T;
    int sol = 1e9;
    for (int i = 0; i < n; ++i)
    {
        int c, t;
        cin >> c >> t;
        if (t <= T)
            sol = min(sol, c);
    }
    if (sol == 1e9)
        cout << "TLE";
    else
        cout << sol;
}


Measured memory_bytes: 256
N, M= map(int, input().split())
L_list=list()
R_list=list()
for i in range(M):
	L, R = map(int, input().split())
	L_list.append(L)
	R_list.append(R)
	
result=min(R_list)-max(L_list)+1

if result < 0:
	print(0)
else:
	print(result)

Measured memory_bytes: 11108
import java.text.ParseException;
import java.util.Scanner;

class Main {
	public static void main(String[] args) throws ParseException {
		Scanner sc = new Scanner(System.in);

		String s = sc.nextLine();

		int zero = 0;
		int one = 0;

		char[] array = s.toCharArray();

		for (char c : array) {

			if (c == '0') {
				zero++;
			} else if (c == '1') {
				one++;
			}

		}

		System.out.println(Math.min(one, zero) * 2);

		sc.close();
	}

}


Measured memory_bytes: 26292
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
)

func main() {
	N := ReadInt()
	d := ReadInts(N)
	sort.Ints(d)
	ans := d[N/2] - d[N/2-1]
	if ans > 0 {
		fmt.Println(ans)
	} else {
		fmt.Println(0)
	}
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int)       { Scan(&i); return }
func ReadString() (s string) { Scan(&s); return }
func ReadInts(n int) []int {
	v := make([]int, n)
	for i := 0; i < n; i++ {
		Scan(&v[i])
	}
	return v
}


Measured memory_bytes: 3304
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		new Main().solve();
	}

	void solve(){
		Scanner sc=new Scanner(System.in);
		String s=sc.next();
		char[]ans=new char[100001];
		int len=0;
		for(int i=0;i<s.length();i++) {
			if(i%2==0) {
				ans[len]=s.charAt(i);
				len++;
			}
		}
		for(int i=0;i<len;i++) {
			System.out.print(ans[i]);
		}
		System.out.println();
	}
}


Measured memory_bytes: 28824
#include<iostream>
#include<stdio.h>
//#include <bits/stdc++.h>
#include<vector>
#include<float.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cstring>
#include<math.h>
#include<cmath>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include <cassert>
#include <cmath>
#include<cstdint>

#define INF 1e9
#define rep(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 VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define vec(type,n) vector<type>(n)
#define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
#define ALL(a)  (a).begin(),(a).end()

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<int,int>;

vector<int>bitSearch(int bit,int n){
    vector<int>S;
    rep(i,n)if(bit&(1<<i))S.push_back(i);
    return S;
}



int main(){
    int n;cin>>n;
    map<string,int>mp;
    rep(i,n){
        string s;cin>>s;
        mp[s]++;
    }
    int k;cin>>k;
    rep(i,k){
        string t;cin>>t;
        mp[t]--;
    }
    int res = 0;
    for(auto m:mp){
        res = max(res,m.second);
    }
    cout<<res;
}



Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>
#include <deque>
#include <complex>

using namespace std;

/*
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
*/

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<long long, long long> pll;
typedef vector<pll> vpll;

typedef long double ld;
typedef vector<ld> vld;

typedef vector<bool> vb;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define reps(i, n) for (ll i = 1; i <= (n); i++)
#define rrep(i, n) for (ll i = (n) - 1; i >= 0; i--)
#define rreps(i, n) for (ll i = (n); i >= 1; i--)
#define all(v) (v).begin(), (v).end()

template <class T> void chmin(T& a, T b) { a = min(a, b);}
template <class T> void chmax(T& a, T b) { a = max(a, b);}

constexpr int INF = 1 << 30;
constexpr ll INFL = 1LL << 60;
constexpr ll MOD = 1000000007;
constexpr ld EPS = 1e-12;
ld PI = acos(-1.0);

void solve() {
    ll x;
    cin >> x;
    string ans;
    if(x == 3 || x == 5 || x == 7) ans = "YES";
    else ans = "NO";
    cout << ans << endl;
    return;
}

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

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

//typedef
//------------------------------------------
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int MOD = 1000000007;

//MOD
//--------------------------------------------
#define MUL(a,b) (((a) % MOD) * ((b) % MOD)) % MOD

// grid
//--------------------------------------------
VL dx = {0, 1, 0, -1};
VL dy = {1, 0, -1, 0};
VL dx2 = {-1, 0, 1, -1, 1, -1, 0, 1};
VL dy2 = {-1, -1, -1, 0, 0, 1, 1, 1};

//debug
//--------------------------------------------
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

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

//main code
int main(int argc, char const* argv[])
{
	int a,b;
	cin >> a >> b;
	string s;
	cin >> s;
	int sa = 'a' - 'A';
	s[b-1] = s[b-1] + sa;
	cout << s << endl;
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <unistd.h>
#define ll long long
#define inf 1000000007
#define inf16 0x3f3f3f3f
#define INF 1000000000000000007LL
#define VI vector<int>
#define VPII vector<pair<int, int> >
#define VLL vector<ll>
#define PII pair<int, int>
#define st first
#define nd second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define endl '\n'
#define ALL(c) (c).begin(), (c).end()
using namespace std;

const int N = 57;

int n, max_abs = -1, ind;

bool m, p;

int a[N];

VPII ans;

void dodatnie()
{
	ans.eb(ind, 1);

	for(int i = 2; i <= n; ++i)
	{
		ans.eb(i-1, i);
	}
}

void ujemne()
{
	ans.eb(ind, n);

	for(int i = n-1; i >= 1; --i)
	{
		ans.eb(i+1, i);
	}
}

int Abs(int a)
{
	return max(a, -a);
}

int32_t main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(NULL);

	cin >> n;

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

		if(a[i]<0)
			m = 1;

		if(a[i]>0)
			p = 1;

		if(max_abs<Abs(a[i]))
		{
			max_abs = Abs(a[i]);
			ind = i;
		}
	}

	if(m && !p)
		ujemne();
	else if(!m && p)
		dodatnie();
	else if(m && p)
	{
		for(int i = 1; i <= n; ++i)
		{
			ans.eb(ind, i);
		}

		if(a[ind]<0)
			ujemne();
		else
			dodatnie();
	}

	cout << ans.size() << endl;

	for(auto it:ans)
		cout << it.st << " " << it.nd << endl;
}

Measured memory_bytes: 256
//{{{
#include<algorithm>
#include<cmath>
#include<fstream>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<random>
#include<set>
#include<sstream>
#include<sys/time.h>
#include<unordered_map>
#include<unordered_set>
#include<vector>
using ll = long long;
enum : int { M = (int)1e9 + 7 };
enum : ll { MLL = (ll)1e18L + 9 };
using namespace std;
#ifdef LOCAL
#include"rprint2.hpp"
#else
#define FUNC(name) template <ostream& out = cout, class... T> void name(T&&...){ }
FUNC(prints) FUNC(printw) FUNC(printwe) FUNC(printb) FUNC(printbe) FUNC(printd) FUNC(printde) FUNC(printdu);
#endif
template <class S, class T>
istream& operator >> (istream& in, pair<S, T>& p){ return in >> p.first >> p.second; }
template <class T>
istream& operator >> (istream& in, vector<T>& v){ for(auto& e : v){ in >> e; } return in; }
//}}}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int h, w, n;
    cin >> h >> w >> n;
    int sr, sc;
    cin >> sr >> sc;
    string s; cin >> s;
    string t; cin >> t;
    auto f = [&](char a, char b, int pos, int llim0, int rlim0){ 
        int llim = llim0, rlim = rlim0;
        for(int i = n - 1; i >= 0; i--){
            if(s[i] == a){
                llim++;
            }else if(s[i] == b){
                rlim--;
            }
            // printde(l, llim, r, rlim);
            if(rlim < llim){
                return true;
            }
            if(!i){
                return pos < llim || rlim < pos;
                // return false;
            }
            if(t[i - 1] == a){
                rlim = min(rlim0, rlim + 1);
                // r = min(l, r - 1);
            }else if(t[i - 1] == b){
                llim = max(llim0, llim - 1);
                // l = max(r, l + 1);
            }
        }
        return false;
        // int maxi = 0, pos = 0;
        // for(int i = 0; i < n; i++){
        //     if(s[i] == a){
        //         pos++;
        //     }
        //     maxi = max(maxi, pos);
        //     if(t[i] == b){
        //         pos--;
        //     }
        // }
        // printde(a, b, maxi);
        // return maxi;
    };
    if(f('L', 'R', sc, 1, w) ||
       f('U', 'D', sr, 1, h)){
    // if(f('L', 'R', sc, 1, w) ||
    //    f('U', 'D', sr, 1, h)){
        cout << "NO" << '\n';
    }else{
        cout << "YES" << '\n';
    }
    // if(sr <= f('U', 'D') || h - sr + 1 <= f('D', 'U') ||
    //    sc <= f('L', 'R') || w - sc + 1 <= f('R', 'L')){
    //     cout << "NO" << '\n';
    // }else{
    //     cout << "YES" << '\n';
    // }
}


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

int main() {
	int n;
	vector<int> target(3);
	cin >> n >> target[0] >> target[1] >> target[2];
	vector<int> l(n);
	rep(i,n) cin >> l[i];
	
	int num_rep = pow(4,n);
	int ans = 1e9;
	vector<int> kind(n);
	vector<int> length(3);
	rep(i,num_rep) {
		int tmp = i;
		int mp = 0;
		rep(j,4) length[j] = 0;
		rep(j,n) {
			int r = tmp%4;
			if (r!=3) {
				if (length[r]!=0) mp += 10;
				length[r] += l[j];
			}
			tmp /= 4;
		}
		bool fl = true;
		rep(j,3) if (length[j]==0) fl = false;
		if (fl) {
			rep(j,3) mp += abs(length[j] - target[j]);
			ans = min(mp, ans);
		}
	}
	cout << ans << endl;

	return 0;
}


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



int main(){
    int N;
    cin >> N;
    bool flag = false;
    for(int a = 0; a <= N / 4; a++){
        for(int b = 0; b <= N / 7; b++){
             if(N == a * 4 + b * 7) flag = true;
        }
    }
    if(flag == false) cout << "No" << endl; 
    else cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main(){
  int N;
  cin>>N;
  vector<pair<int,int>> A(N);
  for(int i=0;i<N;i++)
    cin>>A[i].second>>A[i].first;
  sort(A.begin(),A.end());
  int t=0;
  for(int i=0;i<N;i++){
    t+=A[i].second;
    if(t>A[i].first){
      puts("No");
      return 0;
    }
  }
  puts("Yes");
}

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

const int MAXN = ( int ) 1e5;
const int MAXM = ( int ) 1e5;
const int MAXQ = ( int ) 1e5;

int N, M;
vector< int > G[ MAXN ];
int col[ MAXN ];
int vis[ MAXN ];

int V[ MAXQ ], D[ MAXQ ], C[ MAXQ ];

signed main(){
  ios::sync_with_stdio( 0 );
  cin >> N >> M;
  for( int i = 0; i < M; ++i ){
    int u, v; cin >> u >> v;
    G[ u - 1 ].emplace_back( v - 1 );
    G[ v - 1 ].emplace_back( u - 1 );
  }
  int Q;
  cin >> Q;
  for( int qi = 0; qi < Q; ++qi ){
    cin >> V[ qi ] >> D[ qi ] >> C[ qi ];
  }
  memset( vis, -1, sizeof( vis ) );
  for( int qi = Q - 1; qi >= 0; --qi ){
    int v, d, c;
    v = V[ qi ] - 1, d = D[ qi ], c = C[ qi ];
    if( d <= vis[ v ] ) continue;
    queue< tuple< int, int > > que;
    que.emplace( v, d );
    if( col[ v ] == 0 ){
      col[ v ] = c;
    }
    vis[ v ] = d;
    while( not que.empty() ){
      int u, s;
      tie( u, s ) = que.front();
      que.pop();
      if( s == 0 ) continue;
      for( int nu : G[ u ] ){
        if( vis[ nu ] >= s - 1 ) continue;
        vis[ nu ] = s - 1;
        if( col[ nu ] == 0 ){
          col[ nu ] = c;
        }
        que.emplace( nu, s - 1 );
      }
    }
  }
  for( int i = 0; i < N; ++i ){
    cout << col[ i ] << "\n";
  }
  return 0;
}


Measured memory_bytes: 8952
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
#define rng(a) a.begin(),a.end()
using namespace std;
using ll = long long;
const int INF = 1001001001;


int main() {
  int n;
  cin >> n;
  vector<ll> a(n+2), b(n+2), c(n+2);
  rep(i,n) cin >> a[i];
  rep(i,n) cin >> b[i];
  rep(i,n) cin >> c[i];
  a[n] = 0; b[n] = 0; c[n] = 0;
  a[n+1] = INF; b[n+1] = INF; c[n+1] = INF;
  sort(rng(a));
  sort(rng(b));
  sort(rng(c));
  ll ans = 0;
  vector<ll> pos(n+1);
  for(int i = 1; i <= n; i++) {
    auto iter = lower_bound(a.begin(),a.end(),b[i]);
    pos[i] = distance(a.begin(),iter)-1;
  }
  for(int i = 1; i <= n; i++) pos[i] += pos[i-1];
  for(int i = 1; i <= n; i++) {
    auto iter = lower_bound(b.begin(),b.end(),c[i]);
    auto p = distance(b.begin(),iter)-1;
    ans += pos[p];
  }
  cout << ans << endl;
  return 0;
}

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

int main(){
    ll n,m;
    cin>>n>>m;
    ll a[m];
    ll sum = 0;
    for(int i=0;i<m;i++){
        cin>>a[i];
        sum+=a[i];
    }
    if(n-sum>=0){
        cout<<n-sum<<"\n";
    }else{
        cout<<"-1\n";
    }
    return 0;
}


Measured memory_bytes: 3712
#![allow(unused_macros)]
#![allow(dead_code)]
#![allow(unused_imports)]

use text_io::*;

const U_INF: usize = 1 << 60;
const I_INF: isize = 1 << 60;

fn main() {
    let s: String = read!();
    let len = s.chars().count();
    let s = s.chars().filter(|&c| c == 'o').count() + 15 - len;
    let ans = if s >= 8 { "YES" } else { "NO" };
    println!("{}", ans);
}


Measured memory_bytes: 2068
#include <stdio.h>
#define N 100
#define NIL -1
#define INF 10000000

int G[N][N];
int d[N];
int n;

void dijkstra(int r) {
	int i,u;
	int mincost;
	char color[N];

	for(i=0;i<n;i++){
		d[i] = INF;
		color[i] = 'W';
	}

	d[r] = 0;

	while(1) {
		mincost = INF;
		for (i=0;i<n;i++) {
			if (color[i] != 'B' && d[i] < mincost) {
				mincost = d[i];
				u = i;
			}
		}

		if (mincost == INF) break;

		color[u] = 'B';

		for (i=0;i<n;i++) {
			if(color[i] != 'B' && d[u] + G[u][i] < d[i] && G[u][i] != INF) {
				d[i] = G[u][i] + d[u];
			}
		}
	}
}

int main() {
	int i,j;
	int u,k,v,c;

	scanf("%d", &n);
	for(i=0;i<n;i++) {
		for(j=0;j<n;j++) {
			G[i][j] = INF;
		}
	}

	for(i=0;i<n;i++) {
		scanf("%d%d",&u,&k);
		for(j=0;j<k;j++) {
			scanf("%d%d",&v,&c);
			G[u][v] = c;
		}
	}

	dijkstra(0);

	for(i=0;i<n;i++) {
		printf("%d %d\n",i,d[i]);
	}

	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);++i)
#define ALL(v)   (v).begin(),(v).end()
#define debug(x) cerr<<#x<<": "<<(x)<<endl
using namespace std;
using llong = long long;
using vi    = vector<int>;
using vvi   = vector<vi >;
using vvvi  = vector<vvi >;
using pii   = pair<int,int>;
constexpr int    INF=1e9;
constexpr double EPS=1e-9;
constexpr int    MOD=1e9+7;
template<class Type>
void line(const Type &a){int cnt=0;for(const auto &elem:a){cerr<<(cnt++?' ':'>');cerr<<elem;}cerr<<endl;}

using vl   = vector<long long>;
using vvl  = vector<vl >;
using vvvl = vector<vvl >;

int main(){
	llong n;
	int x,m;
	cin>>n>>x>>m;
	
	vi next(m);
	REP(i,m) next[i]=(llong)i*i%m;
	line(next);
	
	int p=x;
	vl v;
	vi seen(m,-1);
	for(int i=0;;++i){
		v.push_back(p);
		seen[p]=i;
		
		p=next[p];
		if(seen[p]>=0) break;
	}
	for(int i=1;i<v.size();++i) v[i]+=v[i-1];
	line(v);
	
	llong ans=0LL;
	if(n<=v.size()) ans+=v[n-1];
	else{
		if(seen[p]==0){
			int range=v.size();
			ans+=v[v.size()-1]*(n/range);
			if(n%range) ans+=v[n%range-1];
		}else{
			ans+=v[seen[p]-1];
			n-=seen[p];
			int range=v.size()-seen[p];
			ans+=(v[v.size()-1]-v[seen[p]-1])*(n/range);
			if(n%range) ans+=v[seen[p]-1+(n%range)]-v[seen[p]-1];
		}
	}
	
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 4680
#include<bits/stdc++.h>
#define ll          long long int
#define ld          long double
#define pb          push_back
#define mp          make_pair
#define ff          first
#define se          second
#define endl        '\n'
#define fd(n)       fixed<<setprecision(n)
#define MAX         100000000000001
#define MAXN        400005
#define mod         1000000007
using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll a,b;
    cin>>a>>b;
    if(a>=13){
        cout<<b;
    }
    else if(a>=6 && a<=12){
        cout<<b/2;
    }
    else{
        cout<<0;
    }
}

Measured memory_bytes: 256
A, B = map(int, input().strip().split())

if A!=1 and B!=1:
	if A > B:
		print('Alice')
	elif A < B:
		print('Bob')
	else:
		print('Draw')
else:
	if A==1 and B!=1:
		print('Alice')
	elif B==1 and A!=1:
		print('Bob')
	elif A==1 and B==1:
		print('Draw')

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define x first
#define y second
using namespace std;
const int sz=2e5+9;
int n;
pair<int,int> p[sz];

bool cmp(pair<int,int> a,pair<int,int> b){
    //if(a.x!=b.x) return a.x<b.x;
    return a.y<b.y;
}

int main()
{
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    scanf("%d",&n);
    for(int i=0;i<n;i++) scanf("%d %d",&p[i].x,&p[i].y);
    sort(p,p+n,cmp);
    int curr=0;
    for(int i=0;i<n;i++){
        curr+=p[i].x;
        if(curr>p[i].y){
            printf("No");
            return 0;
        }
    }
    printf("Yes");
    return 0;
}


Measured memory_bytes: 1792
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define all(v) v.begin(), v.end()
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define Rep(n) for (ll _ = 0; _ < (ll)(n); _++)
#define P pair<ll,ll>
#define fs first
#define sc second

template<class S>S sum(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
ll min(int a,ll b){return min((ll)a,b);} ll min(ll a,int b){return min(a,(ll)b);}
template <class S> void print(vector<S> &v){for(ll i=0; i<(ll)v.size(); i++){cerr << v[i] << ' ';}cerr << endl;}
template <class S> void print(vector<vector<S>> &v) {for (ll i = 0; i < (ll)v.size(); i++) {for (ll j = 0; j < (ll)v[i].size(); j++) {cerr << v[i][j] << ' ';}cerr << endl;}}

int main(){
	string s;
	cin >> s;
	s[3] = '8';
	cout << s << endl;
}

Measured memory_bytes: 256
import math
A=[]
B=[]
n=int(input())
for i in range(n):
    A.append(i+1)
    B.append(i+1)
SA=set(A)
SB=set(B)
F=[1,1]
f=1
for i in range(n-2):
    f*=i+2
    F.append(f)
P=list(map(int,input().split()))
Q=list(map(int,input().split()))
p=0
for i in range(n-1):
    p+=(list(SA).index(P[i]))*F[n-i-1]
    s=[]
    s.append(P[i])
    SA^=set(s)
q=0
for i in range(n-1):
    q+=(list(SB).index(Q[i]))*F[n-i-1]
    s=[]
    s.append(Q[i])
    SB^=set(s)
print(abs(p-q))

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;


int main() {
	int n;
	cin >> n;
	vector<int> v(n);
	for (int i = 0; i < n; ++i) {
		cin >> v[i];
	}

	int mx = v[0];
	int mn = v[0];
	for (auto x : v) {
		mx = max(mx, x);
		mn = min(mn, x);
	}

	cout << mx - mn << endl;
}

Measured memory_bytes: 256
def main():
    s = input()
    t = input()
    n, m = len(s), len(t)
    dp = [[j if i == 0 else 10 ** 10 for i in range(m + 1)] for j in range(n + 1)]
    dp[0] = [i for i in range(m + 1)]
    for i in range(n):
        for j in range(m):
            dp[i + 1][j + 1] = min(dp[i][j + 1] + 1,
                                   dp[i + 1][j] + 1,
                                   dp[i][j] + 1 - (s[i] == t[j]))
    ans = dp[n][m]
    print(ans)


main()



Measured memory_bytes: 43808