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

vector< vector<int> > snext( 100005, vector<int>(26,0) );

int main() {
  string s,t;
  cin >> s >> t;

  int slen = s.length();
  int tlen = t.length();

  // インデックス作成
  for(int i=slen-1;i>=0; i--) {
    for (int j=0; j<26; ++j ){
      snext[i][j] = snext[i+1][j];
    }
    char c = s[i] - 'a';
    snext[i][c] = i+1;
  }

//  for(int i=0;i<slen+1;++i) {
//    cout << i << " : ";
//    for(int j=0;j<26;++j) {
//      cout << snext[i][j] << " ";
//    }
//    cout << endl;
//  }

  // t の各文字を検索
  int64_t ans = 0;
  int64_t spos = 0;
  for (int i=0; i<tlen; ++i ){
    char c = t[i] - 'a';
    int next = snext[spos][c];
    if ( next == 0 ) {
      ans += slen;
      next = snext[0][c];
      if ( next == 0 ) {
        cout << "-1" << endl;
        return 0;
      }
    }
    spos = next;
//    cout << spos << endl;
  }

  cout << ans+spos << endl;

}


Measured memory_bytes: 13824
#include <bits/stdc++.h>
#define rep(i, n) for (rint i = 1; i <= int(n); i ++)
#define re0(i, n) for (rint i = 0; i < (int) n; i ++)
#define travel(i, u) for (rint i = head[u]; i; i = e[i].nxt)
#define rint register int
using namespace std;

typedef long long lo;

template<typename tp> inline void read(tp &x) {
    x = 0; char c = getchar(); int f = 0;
    for (; c < '0' || c > '9'; f |= c == '-', c = getchar());
    for (; c >= '0' && c <= '9'; x = (x << 3) + (x << 1) + c - '0', c = getchar());
    if (f) x = -x;
}

namespace {
    int mo;
    inline int add(int x, int y) { x += y; return x >= mo ? x - mo : x; }
    inline int sub(int x, int y) { x -= y; return x < 0 ? x + mo : x; }
    inline int mul(int x, int y) { return (lo) x * y % mo; }
    inline int power(int a, int k = mo - 2) {
		int ans = 1;
		for (; k; k >>= 1, a = mul(a, a))
			if (k & 1) ans = mul(ans, a);
		return ans;
    }
	inline void U(int &x, int y) { x = add(x, y); } 
}

const int N = 666;
int n;

struct P {
	int l, r;
} p[N];

inline int doit(int K) {
	vector <int> dp(n + 1, 0);
	int large = 0, small = 0;
	dp[0] = 1;
	re0 (i, 2 * n) {
		vector <int> new_dp(n + 1, 0);
		P &u = p[i];
		re0 (pre, n + 1) if (dp[pre]) {
			if (u.r == 0) {
				U(new_dp[pre], mul(dp[pre], u.l + 1 - (pre + large)));
			} else {
				U(new_dp[pre], mul(dp[pre], u.r + 1 - (K + n + (small - pre))));
				U(new_dp[pre + 1], mul(dp[pre], u.l + 1 - (pre + large)));
			}
		}
		swap(dp, new_dp);
		// cout << u.l << " " << u.r << "\n";
		// for (int i : dp) cout << i << " " ; cout << "\n";
		u.r == 0 ? ++large : ++small;
	}
	// cout << K << " " << dp[K] << "\n";
	// exit(0);
	return dp[K];
}

int main(void) {
	read(n); read(mo);
	re0 (i, 2 * n) {
		if (i >= n) {
			re0 (j, 2 * n) if (i * i + j * j <= 4 * n * n) {
				p[i].l = j;
			}
			p[i].r = 0;
		} else {
			re0 (j, 2 * n) if (i * i + j * j >= n * n) {
				p[i].l = j - 1;
				break;
			}
			re0 (j, 2 * n) if (i * i + j * j <= 4 * n * n) {
				p[i].r = j;
			}
		}
		// cout << p[i].l << " " << p[i].r << "\n";
	}
	sort(p, p + 2 * n, [&](P x, P y) {
			return make_pair(x.l, x.r) < make_pair(y.l, y.r);
		});
	int ans = 0;
	re0 (pre, n + 1) U(ans, mul(pre & 1 ? mo - 1 : 1, doit(pre)));
	cout << ans << "\n";
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod=1e9+7;

int main(){
    string s;
    cin >> s;
    for(int i=0; i<s.size()-1; i++){
        if(s[i] == s[i+1]){
            cout << "Bad";
            return 0;
        }
    }
    cout << "Good";
}

Measured memory_bytes: 256
#include"bits/stdc++.h"
using namespace std;
#define ll long long
#define LL long long
#define MOD 1000000007
#define INF 2000000000000
int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };
ll N, M, K, H, W, L, R, l, r, u, d, sum, Q;
LL ans;
LL no;
bool b, bb[1000001];
string s, t;

int main() {
	cin >> H;
	for (int i = 2; i <= 1000000; i++) {
		bb[i] = true;
	}
	for (int i = 2; i <= pow(H,0.5); i++) {
		for (int j = 1; j*i < 1000000; j++) {
			bb[j*i] = false;
		}
	}
	N = H;
	while (1) {
		if (bb[N]) {
			break;
		}
		N++;
	}

	cout << N << endl;
	return 0;
}



Measured memory_bytes: 1280
#include <bits/stdc++.h>
#define REP(i, n) for (long long i = 0; i < (long long)n; i++)
//#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using Vl = vector<ll>;
using vi = vector<int>;
using Graph = vector<vi>;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  // std::cout << std::fixed << std::setprecision(15); //"for float-base
  // problem"
  ll A, B, N;
  cin >> A >> B >> N;
  ll tmp = min(B - 1, N);
  cout << (A * tmp) / B << endl;
}

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

bool che(int x,int y,char c){
	switch(c){
	case 'J':if((x>>0&1)!=1)return false;break;
	case 'O':if((x>>1&1)!=1)return false;break;
	case 'I':if((x>>2&1)!=1)return false;break;
	}
	
	for(int i=0;i<3;i++){
		if(x>>i&1==1&&y>>i&1==1)return true;
	}
	return false;
}

int dp[1500][10]={0};
int main(){
	int n;
	string str;
	cin>>n>>str;
	dp[0][1]=1;
	for(int i=1;i<=n;i++){
		for(int x=0;x<8;x++){
			for(int y=0;y<8;y++){
				if(che(x,y,str[i-1])){
					dp[i][x]+=dp[i-1][y];
					dp[i][x]%=10007;
					
				}
			}
		}
	}
	int ans=0;
	for(int i=0;i<8;i++){
		ans+=dp[n][i];
		ans%=10007;
	}
	
	cout<<ans<<endl;

}

Measured memory_bytes: 1244
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <array>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <cmath>
#include <climits>
#include <cstdio>
#include <iomanip>
#include <utility>

using namespace std;
typedef long long int ll;

#define SP(x) setprecision((int)x)
#define ALL(v) v.begin(),v.end()

ll gcd(ll x, ll y)
{
    while (y > 0)
    {
        ll tmp = y;
        y = x % y;
        x = tmp;
    }
    return x;
}

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

ll facctorialMethod(ll k)
{
    ll sum = 1;
    for (ll i = 1; i <= k; ++i)
    {
        sum *= i;
        sum %= 1000000007;
    }
    return sum;
}

int main(int argc, char const *argv[])
{
    ll n;
    cin >> n;
    vector<ll> a(n), b;
    for (ll i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    b = a;
    sort(b.begin(), b.end());
    ll m1 = b[n / 2 - 1], m2 = b[n / 2];
    for (ll i = 0; i < n; i++)
    {
        cout << (a[i] <= m1 ? m2 : m1) << endl;
    }
}

Measured memory_bytes: 5376
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
static const int MAX = 10000;
static const int INFTY = (1 << 21);
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;

int n;
vector<pair<int, int> > adj[MAX]; 

void dijkstra() {
    priority_queue<pair<int, int> > PQ;
	int d[MAX], color[MAX];
	
	for(int i = 0; i < n; i++) {
		d[i] = INFTY;
		color[i] = WHITE;
	}
	
	d[0] = 0;
	PQ.push(make_pair(0,0));
	color[0] =GRAY;	
    while(!PQ.empty()) {
    	pair<int, int> f = PQ.top();
    	PQ.pop();
		int u = f.second;
		
		color[u] = BLACK;
		
		if(d[u] < f.first * (-1)) continue;
		
		for(int j = 0; j < adj[u].size(); j++) {
			int v = adj[u][j].first;
			if(color[v] == BLACK) continue;
			if(d[v] > d[u] + adj[u][j].second) {
				d[v] = d[u] + adj[u][j].second;
				PQ.push(make_pair(d[v] * (-1), v));
				color[v] = GRAY;
			}
		}
    }
    
    for(int i = 0; i < n; i++) {
    	cout << i << " " << (d[i] == INFTY ? -1 : d[i]) << endl;
    }
}

int main() {
	int k, c, u, v;
	
	cin >> n;
	for(int i = 0; i < n; i++) {
		cin >> u >> k;
		for(int j = 0; j < k; j++) {
			cin >> v >> c;
		    adj[u].push_back(make_pair(v, c));
		}
	} 
	
	dijkstra();

	return 0;
} 

Measured memory_bytes: 8060
S=input()
N=len(S)
if N!=26:
    for i in range(26):
        c=chr(97+i)
        if not c in S:
            print(S+c)
            exit()
li=[]
for i in reversed(range(26)):
    li.append(S[i])
    if i==0:
        print(-1)
        exit()
    if S[i-1]<S[i]:
        e=i-1
        break
li.sort()
for x in li:
    if S[e]<x:
        print(S[:e]+x)
        exit()

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


    using namespace std;
    typedef long long ll;
    # define M_PI  3.14159265358979323846


    void solve(){
        int n,m;
        cin>>n>>m;
        if(n==m)
            cout<<"Yes";
        else
            cout<<"No";
        return;
    }


    int main(){
        ios::sync_with_stdio(0);
        cin.tie(0);
        cout.tie(0);
        cout<<fixed;
        cout<<setprecision(10);
        int t=1;
//        cin>>t;
        for(int i=1;i<=t;i++){
            solve();
        }
        return 0;
    }


Measured memory_bytes: 256
S = list(input())
# min(全部０１０１０、全部１０１０１)
cnt0 = 0
cnt1 = 0
for e in S[::2]:
    if e == '1':
        cnt0 += 1
    else:
        cnt1 += 1
for e in S[1::2]:
    if e == '0':
        cnt0 += 1
    else:
        cnt1 += 1
print(min(cnt0, cnt1))


Measured memory_bytes: 4396
import java.util.*;

class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int w = sc.nextInt();
    int sum = 0;
    
    int wt[] = new int[n];
    int v[] = new int[n];
    for (int i=0; i<n; i++) {
      wt[i] = sc.nextInt();
      v[i] = sc.nextInt();
      sum += v[i];
    }
    long dp[] = new long[sum+1];
    long inf = 1234567890987L;
    for (int i=1; i<=sum; i++) dp[i] = inf;
    dp[0] = 0;
    long ans = 0;
    for (int i=0; i<n; i++) {
      for (int W=sum; W-v[i]>=0; W--) {
        dp[W] = Math.min(dp[W], dp[W-v[i]] + wt[i]);
      }
    }
    for (int i=0; i<=sum; i++) {
      if (dp[i] <= w) {
        ans = Math.max(ans, i);
      }
    }
    System.out.println(ans);
  }
}

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

using namespace std;

#define FOR(i, N) for (int i = 0; i < (int)N; i++)
#define FORIN(i, a, b) for (int i = a; i < (int)b; i++)
#define ALL(x) (x).begin(), (x).end()
#define MOD 1000000007
#define INF (1 << 29)
#define LLINF (1LL << 60)
#define DEBUG(...) debug(__LINE__, ":" __VA_ARGS__)

using Pi = pair<int, int>;
using ll = long long;

string to_string(string s) { return s; }
template <class S>
string to_string(unordered_set<S> s);
template <class S>
string to_string(set<S> s);
template <class S, class T>
string to_string(map<S, T> m);
template <class T>
string to_string(vector<T> v);

template <class S, class T>
string to_string(pair<S, T> p) {
  return "{" + to_string(p.first) + "," + to_string(p.second) + "}";
}

template <class S>
string to_string(unordered_set<S> s) {
  string ret = "{";
  for (S x : s) ret += to_string(x) + ",";
  return ret + "}";
}

template <class S>
string to_string(set<S> s) {
  string ret = "{";
  for (S x : s) ret += to_string(x) + ",";
  return ret + "}";
}

template <class S, class T>
string to_string(map<S, T> m) {
  string ret = "{";
  for (pair<S, T> x : m) ret += to_string(x) + ",";
  return ret + "}";
}

template <class T>
string to_string(vector<T> v) {
  string ret = "{";
  for (int i = 0; i < (int)v.size() - 1; ++i) {
    ret += to_string(v[i]) + ",";
  }
  if (v.size() > 0) {
    ret += to_string(v.back());
  }
  ret += "}";
  return ret;
}

void debug() { cerr << endl; }

template <class Head, class... Tail>
void debug(Head head, Tail... tail) {
  cerr << to_string(head) << " ";
  debug(tail...);
}

void print() { cout << endl; }

template <class Head, class... Tail>
void print(Head head, Tail... tail) {
  cout << to_string(head);
  print(tail...);
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  int N;
  cin >> N;
  vector<int> P(N), Q(N);
  FOR(i, N) cin >> P[i];
  FOR(i, N) cin >> Q[i];
  vector<int> order(N);
  iota(ALL(order), 1);
  int a = 0;
  while (order != P) {
    a++;
    next_permutation(ALL(order));
  }
  iota(ALL(order), 1);
  int b = 0;
  while (order != Q) {
    b++;
    next_permutation(ALL(order));
  }
  print(abs(a - b));
  return 0;
}

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

using namespace std;
using ll=long long;
using pi=pair<int, ll>;
const int inf = 0x3f3f3f3f;

const int V = 2048;
const int E = (V*5)<<2;
int sson[V], pre[V], trk[V]; ll dis[V];
int cnt;

struct node{
    int to, bro, cap, flow; ll cost;
} edge[E];

void init(){
    cnt = 0;
    memset(sson, -1, sizeof sson);
}

void add_edge(int u, int v, int cap, ll cost){
    edge[cnt] = {v, sson[u], cap, 0, cost};
    sson[u] = cnt++;
    edge[cnt] = {u, sson[v], 0, 0, -cost};
    sson[v] = cnt++;
}

bool spfa(int s, int t){
    queue<int> q;
    memset(pre, -1, sizeof pre);
    memset(dis, inf, sizeof dis);
    memset(trk, 0, sizeof trk);
    dis[s] = 0; trk[s] = 1; q.push(s);
    while(!q.empty()){
        int u = q.front(); q.pop(); trk[u] = 0;
        for (int e=sson[u]; ~e; e=edge[e].bro){
            int v = edge[e].to;
            if (edge[e].cap > edge[e].flow && dis[v] > dis[u] + edge[e].cost){
                dis[v] = dis[u] + edge[e].cost;
                pre[v] = e;
                if (!trk[v]){
                    trk[v] = 1;
                    q.push(v);
                }
            }
        }
    }
    return pre[t] != -1;
}

pi mcmf(int s, int t){
    int flow = 0; ll cost = 0;
    while (spfa(s, t)){
        int f = inf;
        for (int e=pre[t]; ~e; e=pre[edge[e^1].to])
            f = min(f, edge[e].cap - edge[e].flow);
        for (int e=pre[t]; ~e; e=pre[edge[e^1].to]){
            edge[e].flow += f;
            edge[e^1].flow -= f;
            cost += edge[e].cost * f;
        }
        flow += f;
    }
    return {flow, cost};
}
int dx[4] = {1, -1, 1, -1};
int dy[4] = {1, -1, -1, 1};
void solve() {
    int n; cin >> n;
    init();
    int S = 4, T = 5;
    int v = 6;
    for (int _ = 0; _ < n; _++) {
        int x,y,z;
        cin >> x >> y >> z;
        add_edge(S, v, z, 0);
        for (int i = 0; i < 4; i++) {
            ll cost = x*dx[i] + y*dy[i];
            add_edge(v, i, z, cost);
        }
        v++;
    }
    for (int _ = 0; _ < n; _++) {
        int x,y,z;
        cin >> x >> y >> z;
        add_edge(v, T, z, 0);
        for (int i = 0; i < 4; i++) {
            ll cost = x*dx[i^1] + y*dy[i^1];
            add_edge(i, v, z, cost);
        }
        v++;
    }

    ll res = -mcmf(S,T).second;
    cout << res;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    cout << endl;
}


Measured memory_bytes: 768
import java.util.*;

class Main{

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

		int N = sc.nextInt();
		String W = sc.next();
		 Set<String> list = new HashSet<String>();
		 list.add(W);
		 String ans = "Yes";

		for(int i = 1; i < N; i++){
			String W1 = W;
			String W2 = sc.next();
			if(W1.charAt(W.length() - 1) == W2.charAt(0)){
				W = W2;
				list.add(W);
			}else{
				ans = "No";
				break;
			}
		}

		if(list.size() != N){
			ans = "No";
		}

		System.out.println(ans);


	}
}

Measured memory_bytes: 23764
#include <bits/stdc++.h>
#include <array>
using namespace std;
using ULL = unsigned long long;
using UL = unsigned;
using LL = long long;
#define rep(i, n) for(UL i = 0; i < (n); i++)

struct Problem {

	void Solve() {
		UL N, M; cin >> N >> M;
		vector<vector<UL>> E(N);
		rep(i, M) {
			UL a, b; cin >> a >> b; a--; b--;
			E[a].push_back(b);
			E[b].push_back(a);
		}
		rep(i, N) { if (E[i].size() % 2 == 1) { cout << "No" << endl; return; } }
		rep(i, N) { if (E[i].size() >= 6) { cout << "Yes" << endl; return; } }
		vector<UL> S;
		rep(i, N) { if (E[i].size() == 4) { S.push_back(i); } }
		//cout << "S.size() = " << S.size() << endl;
		if (S.size() >= 3) { cout << "Yes" << endl; return; }
		if (S.size() <= 1) { cout << "No" << endl; return; }
		queue<UL> Q; Q.push(S[0]);
		vector<UL> F(N);
		UL q = 0;
		while (Q.size()) {
			UL p = Q.front(); Q.pop();
			if (p == S[1]) { q++; continue; }
			if (F[p]) continue;
			F[p] = true;
			for (UL e : E[p]) { Q.push(e); }
		}
		//cout << "q = " << q << endl;
		if (q == 4) { cout << "No" << endl; }
		else cout << "Yes" << endl;
	}


	Problem();
};
int main() {
	unique_ptr<Problem> p(new Problem());
	p->Solve();
	return 0;
}
Problem::Problem() {
	cout << fixed << setprecision(10);
}


Measured memory_bytes: 6144
def warshall_floyd(edge):
  e=edge
  for k in range(len(e)):
    for i in range(len(e)):
      for j in range(len(e)):
        e[i][j]=min(e[i][j],e[i][k]+e[k][j])
  return e

n,m,l=map(int,input().split())

edge=[n*[10**18]for _ in range(n)]
for i in range(n):
  edge[i][i]=0
for i in range(m):
  a,b,c=map(int,input().split())
  a-=1
  b-=1
  edge[a][b]=edge[b][a]=c
edge=warshall_floyd(edge)

edge2=[n*[10**18]for _ in range(n)]
for i in range(n):
  edge2[i][i]=0
  for j in range(n):
    if edge[i][j]<=l:
      edge2[i][j]=1

edge2=warshall_floyd(edge2)
q=int(input())
for i in range(q):
  s,t=map(int,input().split())
  s-=1
  t-=1
  ans=edge2[s][t]
  if ans==10**18:
    print(-1)
  else:
    print(ans-1)


Measured memory_bytes: 58968
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayDeque;
import java.util.Deque;

public class Main {

    public static void main(String[] args) throws IOException {

        Deque<Integer> numero = new ArrayDeque<>();
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] opcion;
        int n = Integer.parseInt(br.readLine());
        for (int t = 0; t < n; t++) {
            opcion = br.readLine().split(" ");
            switch (opcion[0]) {
                case "insert":
                    numero.addFirst(Integer.parseInt(opcion[1]));
                    break;
                case "delete":
                    numero.remove(Integer.parseInt(opcion[1]));
                    break;
                case "deleteFirst":
                    numero.removeFirst();
                    break;
                default:
                    numero.removeLast();
            }
        }
        if (numero.size() == 1) {
            System.out.println(numero.getFirst());
        } else {
            StringBuilder resul = new StringBuilder();
            int longitud = numero.size() - 1;
            for (int i = 0; i < longitud; i++) {
                resul.append(numero.getFirst()).append(" ");
                numero.removeFirst();
            }
            resul.append(numero.getFirst());
            System.out.println(resul.toString());
        }
    }
}



Measured memory_bytes: 189184
n = int(input())
x = input()
k = x.count("1")
s = int(x, 2)

def ev(n):
	cnt = 0
	while n != 0:
		m = bin(n).count("1")
		n = n % m
		cnt += 1
	return cnt

if k != 1:
	k1 = s%(k-1)
	k2 = s%(k+1)
	for i in range(n):
		if x[i] == "0":
			print(ev((k2+pow(2, n-i-1, k+1)) % (k+1))+1)
		else:
			print(ev((k1-pow(2, n-i-1, k-1)) % (k-1))+1)
else:
	k2 = s%(k+1)
	for i in range(n):
		if x[i] == "0":
			print(ev((k2+pow(2, n-i-1, k+1)) % (k+1))+1)
		else:
			print(0)

Measured memory_bytes: 81396
#include <iostream>
using namespace std;
   
int main() {
  int w, h, x, y, r;
  cin >> w >> h >> x >> y >> r;
   
  if ( w >= x + r && h >= y + r && 0 <= x + r && 0 <= y + r && x >= 0 && y >= 0 ) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
   
  return 0;
}

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

using namespace std;

using ll = long long;
using ull = unsigned long long;

int main(int argc, char const *argv[]) {
	int a,b,c;
	std::cin >> a >> b >> c;
	if (a + b >= c) {
		std::cout << "Yes" << '\n';
	}
	else {
		std::cout << "No" << '\n';
	}
	return 0;
}


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

int main()
{
	long long N,i;
	long long(*A) = (long long(*))
	malloc(100010 * sizeof(long long));
	long long(*B) = (long long(*))
	malloc(100010 * sizeof(long long));
	long long ans=0;
	scanf("%lld", &N);
	for (i = 1;i <= N+1;i++)scanf("%lld", &A[i]);
	for (i = 1;i <= N;i++)scanf("%lld", &B[i]);
	for (i = 1;i <= N;i++)
	{
		if (B[i] >= A[i])
		{
			ans += A[i];
			B[i] -= A[i];
			A[i] = 0;
		}
		else
		{
			ans += B[i];
			A[i] -= B[i];
			B[i] = 0;
		}

		if (B[i] >= A[i+1])
		{
			ans += A[i+1];
			B[i] -= A[i + 1];
			A[i+1] = 0;
			
		}else
		{
			ans += B[i];
			A[i+1] -= B[i];
			B[i] = 0;
		}
	
	}
	printf("%lld\n", ans);
	free(A);
	free(B);
	return 0;
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define debug(x) cout << #x << " = " << x << endl
#define pb push_back
#define F first
#define S second

const int MAX = 100005;
int dif[MAX];


struct dsu {
    vector<int> par, sz, sum;
    int size;

    dsu(int n) {
        size = n;
    	par = sz = sum = vector<int>(n);
        for (int i = 0; i < n; i++) {
            par[i] = i;
            sz[i] = 1;
            sum[i] = dif[i];
        }
    }

    int find(int u) {
        return par[u] == u ? u : (par[u] = find(par[u]));
    }

    void unite(int u, int v) {
        if ((u = find(u)) == (v = find(v))) return;
        if (sz[u] > sz[v]) swap(u,v);
        par[u] = v;
        sz[v] += sz[u];
        sum[v] = (sum[v]+sum[u])%26;
        size--;
    }

    int count(int u) {
        return sz[find(u)];
    }

    int getSum(int u){
        return sum[find(u)];
    }
};


int main() {
    #ifdef LOCAL
        freopen("in.txt", "r", stdin);
        //freopen("out.txt", "w", stdout);
    #endif
    ios::sync_with_stdio(0);
    cin.tie(0);

    string s;
    int n, sz, a, b;

    cin >> s >> n;
    sz = s.size();

    for (int i = 0; i < sz; i++){
        dif[i+1] = s[i]-'a';
    }
    for (int i = 0; i < sz+1; i++) {
        dif[i] = (dif[i+1]+26-dif[i])%26;
    }

    dsu ds = dsu(sz+1);

    for (int i = 0; i < sz; i++) {
        ds.unite(i, sz-i);
    }

    for (int i = 0; i < n; i++) {
            cin >> a >> b;
            a--;
            ds.unite(a, b);
    }
    bool f = true;
    for (int i = 0; i < sz; i++) {
        if(ds.getSum(i) != 0){
            f = false;
            break;
        }
    }

    if(f)cout << "YES\n";
    else cout << "NO\n";



}


Measured memory_bytes: 2000
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
long long a[200005],b[200005];
long long cnta=0,cntb=0;
long long n,k,t,ans=2345241124;
int main() {
	scanf("%lld%lld",&n,&k);
	for(int i=1; i<=n; i++) {
		scanf("%lld",&t);
		if(t>=0)a[++cnta]=t;
		else b[++cntb]=-t;
		}
	a[0]=b[0]=0;
	sort(a,a+cnta+1);
	sort(b,b+cntb+1);
	for(int i=0; i<=k&&i<=cnta; i++) {
		if((k-i)<=cntb)ans=min(ans,2*min(a[i],b[k-i])+max(a[i],b[k-i]));
		}
	cout<<ans;
	}




Measured memory_bytes: 1024
#include <iostream>
//#include <numeric>
//#include <vector>
//#include<math.h>
//#include <algorithm>
//#include <functional>
//#include <numeric>
//#include<cmath>
//#include <stdio.h> 
//#include <cstdint>
//#include <string>
//#include <cstdlib>
//#define pi 3.14159265359
using namespace std;

int main() {

	
	int n;
	cin >> n; 
	int d;
	d =  n * 100 / 108;
	int m = d * 1.08;

	if (d * 1.08 == n) {
		cout << d;
	}
	else if (int((d - 1) * 1.08) == n) {
		cout << d - 1;
	}
	else if (int((d + 1) * 1.08) == n) {
		cout << d + 1;
	}
	else {
		cout << ":(";
	}

	return 0;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define re register int
#define F(x,y,z) for(re x=y;x<=z;x++)
#define FOR(x,y,z) for(re x=y;x>=z;x--)
typedef long long ll;
#define I inline void
#define IN inline int
#define STS system("pause")
template<class D>I read(D &res){
	res=0;register D g=1;register char ch=getchar();
	while(!isdigit(ch)){
		if(ch=='-')g=-1;
		ch=getchar();
	}
	while(isdigit(ch)){
		res=(res<<3)+(res<<1)+(ch^48);
		ch=getchar();
	}
	res*=g;
}
const int Mod=924844033;
struct E{
	int to,nt;
}e[404000];
#define T e[k].to
int r[606000];
I Add(int &x,int y){(x+=y)>=Mod?x-=Mod:0;}
IN Plus(int x,int y){(x+=y)>=Mod?x-=Mod:0;return x;}
IN Pow(int x,int y=Mod-2){
	re res=1;
	while(y){
		if(y&1)res=(ll)res*x%Mod;
		x=(ll)x*x%Mod;
		y>>=1;
	}
	return res;
}
I ntt(int *f,int S,int sn){
	F(i,0,S-1)if(i<r[i])swap(f[i],f[r[i]]);
	for(re i=1;i<S;i<<=1){
		re gn=Pow(5,(Mod-1)/(i<<1));if(sn==-1)gn=Pow(gn);
		for(re p=i<<1,j=0;j<S;j+=p){
			re g0=1;
			for(re k=0;k<i;k++,g0=(ll)g0*gn%Mod){
				re X=f[j+k],Y=(ll)g0*f[i+j+k]%Mod;
				f[j+k]=Plus(X,Y);f[i+j+k]=Plus(X,Mod-Y);
			}
		}
	}
	if(sn==-1){
		re invn=Pow(S);
		F(i,0,S-1)f[i]=(ll)f[i]*invn%Mod;
	}
}
I mul(int lena,int *a,int lenb,int *b,int lenc,int *c){
	static int f[606000],g[606000];
	re lim=1,len=0;while(lim<lena+lenb)lim<<=1,len++;
	F(i,0,lim-1)r[i]=(r[i>>1]>>1)|((i&1)<<(len-1));
	F(i,0,lim-1)f[i]=g[i]=0;F(i,0,lena-1)f[i]=a[i];F(i,0,lenb-1)g[i]=b[i];
	ntt(f,lim,1);ntt(g,lim,1);F(i,0,lim-1)f[i]=(ll)f[i]*g[i]%Mod;
	ntt(f,lim,-1);F(i,0,lenc-1)c[i]=f[i];F(i,lenc,lim-1)c[i]=0;
}
int n,m,X,Y,tot,ans[202000],fac[202000],inv[202000],head[202000],siz[202000],cnt[202000],a[606000],b[606000],c[606000];
I add(int x,int y){e[++tot].to=y;e[tot].nt=head[x];head[x]=tot;}
IN C(int x,int y){return (ll)fac[x]*inv[y]%Mod*inv[x-y]%Mod;}
I D_1(int x,int fa){
	siz[x]=1;
	for(re k=head[x];k!=-1;k=e[k].nt){
		if(T==fa)continue;
		D_1(T,x);siz[x]+=siz[T];cnt[siz[T]]++;
	}
	//cnt[siz[x]]++;
	cnt[n-siz[x]]++;
}
int main(){
	read(n);memset(head,-1,sizeof(head));tot=-1;
	F(i,1,n-1){read(X);read(Y);add(X,Y);add(Y,X);}
	D_1(1,0);
	fac[0]=1;F(i,1,n)fac[i]=(ll)fac[i-1]*i%Mod;
	inv[n]=Pow(fac[n]);FOR(i,n-1,0)inv[i]=(ll)inv[i+1]*(i+1)%Mod;
	F(i,1,n)a[i]=(ll)fac[i]*cnt[i]%Mod,b[i]=inv[n-i];
	mul(n+1,a,n+1,b,(n+1)<<1,c);
	F(i,1,n)ans[i]=Plus((ll)C(n,i)*n%Mod,Mod-(ll)inv[i]*c[n+i]%Mod),printf("%d\n",ans[i]);
	return 0;
}



Measured memory_bytes: 34520
#include <iostream>
#include <vector>
//#define int long long
using namespace std;
const int INF = 1e18 + 10;
int minCost(vector<int> & dp,vector<int> v, int n){
    if(dp[n]!=INF)
        return dp[n];
    else{
        dp[n]=min(minCost(dp,v,n-1)+abs(v[n]-v[n-1]),minCost(dp,v,n-2)+abs(v[n]-v[n-2]));
    }
    return dp[n];
}
signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    vector<int> v(n,0);
    for (int i = 0; i <n ; i++) {
        cin>>v[i];
    }
    vector<int> dp(n,INF);
    dp[0]=0;
    dp[1]=abs(v[1]-v[0]);
//    int ans=minCost(dp,v,n-1);
    for (int i = 2; i <n ; i++) {
        dp[i]=min(dp[i-1]+abs(v[i]-v[i-1]),dp[i-2]+abs(v[i]-v[i-2]));
    }
    cout<<dp[n-1];
    return 0;
}

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

int main(){
  int n;	cin >> n;
  vector<long long>	A(n);
  rep(i,n)	cin >> A[i];
  
  long long m=A[0];
  long long ans=0;
  rep(i,n){
    if(A[i]<m){
      ans+=m-A[i];
      A[i]=m;
    }
    m=A[i];
  }
  cout << ans;
}


Measured memory_bytes: 4812
N,K=map(int,input().split())
A=[list(map(int,input().split())) for i in range(N-1)]
m=10**9+7
c=[[] for i in range(N)]
for i,j in A:
    c[i-1].append(j-1)
    c[j-1].append(i-1)
import sys
sys.setrecursionlimit(10**6)
def bfs(p):
    r=K
    d=1
    n=[1]*N
    while len(p)>0:
        q=[]
        for e in p:
            n[e]=0
            x=max(K-min(2,d),0)
            for f in c[e]:
                if n[f]:
                    q.append(f)
                    r=(r*x)%m
                    x-=1
        p=q
        d+=1
    return r
print(bfs([A[0][0]-1]) if N>1 else K)

Measured memory_bytes: 43352
#include<iostream>
using namespace std;
int main()
{
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	if(a+b==c+d)
		cout<<"Balanced"<<endl;
	else if(a+b>c+d)
		cout<<"Left"<<endl;
	else
		cout<<"Right"<<endl;
	return 0;	
}

Measured memory_bytes: 256
import math
N,X  = (int(T) for T in input().split())
Cor  = sorted([abs(int(T)-X) for T in input().split()])
GCDC = Cor[0]
for T in range(1,N):
    GCDC = math.gcd(GCDC,Cor[T])
    if GCDC==1: break
print(GCDC)

Measured memory_bytes: 20120
#include<bits/stdc++.h>
using namespace std;
#define RI register int
int read() {
	int q=0;char ch=' ';
	while(ch<'0'||ch>'9') ch=getchar();
	while(ch>='0'&&ch<='9') q=q*10+ch-'0',ch=getchar();
	return q;
}
typedef long long LL;
const int N=100005,inf=0x3f3f3f3f;
int n,js,a[N],s[N],b[N],c[N];LL res,num;
void msort(int l,int r) {
	int mid=(l+r)>>1;
	for(RI k=l,i=l,j=mid+1;k<=r;++k)
		if(j>r||(i<=mid&&s[i]<=s[j])) c[k]=s[i++];
		else c[k]=s[j++];
	for(RI k=l;k<=r;++k) s[k]=c[k];
}
void work(int l,int r) {
	if(l==r) return;
	int mid=(l+r)>>1;
	work(l,mid),work(mid+1,r);
	for(RI i=l,j=mid+1;j<=r;++j) {
		while(i<=mid&&s[i]<=s[j]) ++i;
		res+=i-l;
	}
	msort(l,r);
}
int check(int x) {
	for(RI i=1;i<=n;++i)
		s[i]=s[i-1]+(a[i]>=x?1:-1),b[i]=s[i];
	b[n+1]=0,sort(b+1,b+2+n);
	js=1;for(RI i=2;i<=n+1;++i) if(b[i]!=b[js]) b[++js]=b[i];
	for(RI i=0;i<=n;++i) s[i]=lower_bound(b+1,b+1+js,s[i])-b;
	res=0,work(0,n);
	return res>=(num+1)/2;
}
int main()
{
	int l=inf,r=0,ans;
	n=read();num=1LL*n*(n-1)/2+n;
	for(RI i=1;i<=n;++i)
		a[i]=read(),l=min(a[i],l),r=max(a[i],r);
	while(l<=r) {
		int mid=(l+r)>>1;
		if(check(mid)) ans=mid,l=mid+1;
		else r=mid-1;
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
typedef long long ll;
using namespace std;

int main() {

	int n, k;
	cin >> n >> k;
	int * a = new int[n];
	for (int i = 0; i < n; ++i)
	{
		cin >> a[i];
	}
	sort(a, a + n,greater<int>());
	ll sum = 0;
	for (int i = 0; i < n; ++i)
	{
		if (k > 0)
		{
			k--;
		}
		else
		{
			sum += a[i];
		}
	}
	cout << sum;


	//ll t, n, m;
	//cin >> t;
	//while (t--)
	//{
	//	int c = 0;
	//	cin >> n >> m;
	//	int e = max(n, m);
	//	ll *a = new ll[n];
	//	ll *b = new ll[m];
	//	map<ll, ll>ax, bx;
	//	set<int>as,bs;
	//	for (int i = 0; i < n; ++i)
	//	{
	//		cin >> a[i];
	//		ax[a[i]]++;
	//		/*as.insert(a[i]);*/
	//	}
	//	for (int i = 0; i < m; ++i)
	//	{
	//		cin >> b[i];
	//		if (ax[b[i]] > 0)
	//		{
	//			ax[b[i]]--;
	//			e--;
	//		}
	//		else
	//		{
	//			c++;
	//		}
	//		/*bx[b[i]]++;
	//		bs.insert(a[i]);*/
	//	}
	//	cout << e+c << endl;
	//}



	system("pause");
	return 0;
}
/*

#include <iostream>
#include <algorithm>

using namespace std;

int main() {

	int n, m, k;
	cin >> n >> k >> m;
	int * arr = new int[n];
	int sum = 0;
	for (int i = 0; i < n - 1; ++i)
	{
		cin >> arr[i];
		sum += arr[i];
	}
	int ans = -555;

	ans = m * n - sum;
	for (int i = 0; i <= k; ++i)
	{
		if ((sum + i) / n >= m)
		{
			cout << i;
			system("pause");
			return 0;
		}
	}
	cout << -1;

	system("pause");
	return 0;
}


*/

Measured memory_bytes: 1272
#X*0.08=A
#X*0.10=B

A,B=input().split()
A=int(A);B=int(B);

#X*0.08=A.0~A.9999...

X1=A/0.08
X2=(A+0.999)/0.08

Y1=B/0.10
Y2=(B+0.999)/0.10

#print(X1,X2)
#print(Y1,Y2)

#お互いが満たす数値の中で、最小のものを出力する
#X1~X2 Y1~Y2

import math

# 切り上げ
X1=math.ceil(X1)
Y1=math.ceil(Y1)

# 切り捨て
X2=math.floor(X2)
Y2=math.floor(Y2)

#片方を下から上まで見て、領域が一致するところがあればそれが答え
for i in range(X1,X2+1):
    if Y1<=i and i<=Y2:
        print(i)
        exit()
#重なる領域がなかったら-1出力
print("-1")

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

typedef long long ll;
typedef long double ld;
#define pi 3.14159265359
#define inf 2147483647
#define INF 9223372036854775807
#define mod 1000000007
#define mod2 998244353
#define Graph vector<vector<int>>

int main() {
    int a, b; cin >> a >> b;
    if (a <= b) cout << a << endl;
    else cout << a - 1 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <deque>
using namespace std;

int main() {
    //input
    int r,g,b,n; cin >> r >> g >> b >> n;
    int counter = 0;

    //compute
    for(int i = 0;i < n / r + 1; i++) {
        for(int j = 0; j < n / g + 1 ; j++){
            bool p = ((n - r * i - g * j) >= 0 && (n - r * i - g * j) % b == 0);
            if(p) counter++;
        } 
    }

    //output
    cout << counter << endl;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long int
#define rep(i, n) for(int i = 0; i < n; i++)
#define repp(i, n) for(int i = 1; i <= n; i++)
#define sort(v) sort((v).begin(), (v).end())
#define pb push_back
#define mp make_pair
#define riverse(v) reverse((v).begin(), (v).end())
using vi = vector<int>;
using vs = vector<string>;
using vvi = vector<vi>;
using vll = vector<ll>;
const int MOD = 1e9+7;
vi alphabet = {'a','b','c','d','e','f','g','h','i','j','k','l','m',
               'n','o','p','q','r','s','t','u','v','w','x','y','z'};
int main() {
	int n;
  	cin >> n;
  	vll a(n);
  	rep(i,n){
    	int x;
      	cin >> x;
      	a[i] = x+1;
    }
	vi ans(10000000,0);
  	rep(i,n){
    	ans[a[i]]++;
      	ans[a[i]-1]++;
      	ans[a[i]+1]++;
    }
  	sort(ans);
  	riverse(ans);
  	cout << ans[0] << endl;
}

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

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    long n = Long.parseLong(in.readLine());
    in.close();
    
    long k = (int)Math.sqrt(n);
    while(n%k!=0){
      k--;
    }
    
    System.out.println(Math.max(String.valueOf(k).length(),
                                String.valueOf(n/k).length()));
  }
}

Measured memory_bytes: 21588
$/=get.words;$_=sort -*,get.words;
say .[^$1].sum/$1;
$!=+.grep: *==.[$1-1];
say (combinations($!,+.[^$1].grep(*==.[$1-1])).elems,sum map {combinations($!,$_).elems},+$1..(+$2 min$!))[.[$1-1]==.[0]]

Measured memory_bytes: 75140
def d(u):
 global t
 C[u]=0;D[u]=t;t+=1
 for v in M[u]:v=int(v)-1;C[v]and d(v)
 F[u]=t;t+=1
N=int(input());R=range(N)
M=[input().split()[2:]for _ in R]
C,D,F=[1]*N,[0]*N,[0]*N
t=1
for i in R:C[i]and d(i)
for i in R:print(i+1,D[i],F[i])


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

int main() {
  int N;
  cin >> N;
  
  string S;
  cin >> S;
  
  int F = 0;
  for (int i=0; i<N-1; i++) {
    if (S.at(i) == S.at(i+1)) {
      F++;
    }
  }
  cout << N - F << endl;
}

Measured memory_bytes: 512
[H1,M1,H2,M2,K]=input().split();
H1=int(H1);
H2=int(H2);
M1=int(M1);
M2=int(M2);
K=int(K);
d1=60*H1+M1;
d2=60*H2+M2-K;
print(d2-d1);

Measured memory_bytes: 9172
#include <iostream>
#include <string>
#include <sstream>
#include <utility>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <cmath>
#include <functional>
#include <chrono>
#include <cstring>
#include <limits.h>

using namespace std;
typedef long long lint;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<lint> vl;
typedef pair<lint,lint> pll;

lint mod = 1e9 + 7;
lint mypow(lint a, lint n){
    lint res = 1;
    lint base = a;
    while(n > 0){
        if (n%2) res = res*base%mod;
        base = base*base%mod;
        n = n/2;
    }
    return res;
}

lint rev(lint a){
    return mypow(a, mod-2);
}
vl la, rela;
lint comb(lint n, lint m, vl &la, vl &rela){
    return (la[n] * rela[m] % mod) * rela[n-m] % mod;
}

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

    int k; cin>>k;
    string s; cin>>s;
    int n = s.size();

    {
        int n = 2e6 + 5;
        la.assign(n+1, 1);
        for (int i=1; i<=n; ++i) la[i] = la[i-1]*i%mod;

        rela.assign(n+1, 0);
        rela[n] = rev(la[n]);
        for (int i=n; i>=1; --i) rela[i-1] = rela[i] * i % mod;
    }

    lint ans = 0;
    for (int l = n-1; l<= n + k-1; ++l){
        lint base =  comb(l, n-1, la, rela) * mypow(25, l - n +1) % mod;
        base = base * mypow(26, n + k - l-1) % mod;
        ans = (ans + base)%mod;
    }
    cout<<ans;


}


Measured memory_bytes: 35676
#include<stdio.h>
#include<math.h>
#include <stdlib.h>
int compare_int(const void *a, const void *b)
{
    return *(int*)b - *(int*)a;
}
int main(){
	char year[20];
	int ans=0;
	scanf("%s\n",year);
	if(year[5]=='0'){
		if(year[6]=='4'||year[6]=='2'||year[6]=='1'||year[6]=='3'){
			ans=1;
		}
	}
	if(ans==1){
		printf("Heisei\n");
	}else{
		printf("TBD\n");
	}
}

Measured memory_bytes: 128
n,m,i,p[1000],P;
//M(int*a){return*1[&a]-*a;}
M(int*a,int*b){return*b-*a;}
main(){
	for(;scanf("%d%d",&n,&m),n;){
		for(i=0;i<n;i++){
			scanf("%d",p+i);
		}
		qsort(p,n,4,M);
		P=0;
		for(i=0;i<n;i++){
			if(i%m!=m-1)
				P+=p[i];
		}
		printf("%d\n",P);
	}
	exit(0);
}

Measured memory_bytes: 0
#include <iostream>
#include <cstdio>
using namespace std;
int n, a[100005],i,k;string s;
int main() {
	cin>>s;n = s.size();
	for(i=0; i<n; i++) {
		if(s[i]=='R') k = i;
		else a[k + (i-k)%2]++;
	}
	for(i=n-1; i>=0; i--) {
		if(s[i]=='L') k = i;
		else a[k - (k-i)%2]++;
	}
	for(i=0; i<n; i++) printf("%d ", a[i]);
}

Measured memory_bytes: 1024
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <climits>
#include <cmath>
#include <complex>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <iomanip>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <cstdint>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
#define MP make_pair
#define PB push_back
#define inf 1000000007
#define rep(i,n) for(int i = 0; i < (int)(n); ++i)
#define all(x) (x).begin(),(x).end()

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}
 
template<class T> inline bool chmax(T &a, T b){
    if(a<b){
        a = b;
        return true;
    }
    return false;
}

template<class T> inline bool chmin(T &a, T b){
    if(a>b){
        a = b;
        return true;
    }
    return false;
}

int main(){
    int n;
    cin >> n;
    vector<string> s(n);
    rep(i,n)cin >> s[i];
    vector<pair<int,int> > p,q;
    int sm = 0;
    bool flag = 1;
    rep(i,n){
        int c = 0;
        int mi = 0;
        rep(j,s[i].size()){
            if(s[i][j]=='('){
                c++;
                sm++;
            }else{
                c--;
                sm--;
            }
            chmin(mi,c);
            if(mi!=0)flag = 0;
        }
        if(c>0){
            p.push_back(MP(mi,c));
        }else{
            q.push_back(MP(mi,c));
        }
    }
    if(sm!=0){
        cout << "No\n";
        return 0;
    }
    if(flag){
        cout << "Yes\n";
        return 0;
    }
    int d = 0;
    vector<pair<int,int> > r;
    for(auto x:p){
        if(x.first==0){
            d += x.second;
        }else{
            r.push_back(x);
        }
    }
    if(d==0){
        cout << "No\n";
        return 0;
    }
    sort(r.rbegin(),r.rend());
    for(auto x:r){
        if(d+x.first<0){
            cout << "No\n";
            return 0;
        }else{
            d += x.second;
        }
    }
    int m = q.size();
    vector<pair<int,pair<int,int> > > qq;
    rep(i,m){
        qq.push_back(MP(+q[i].first-q[i].second,MP(q[i].first,q[i].second)));
    }
    sort(qq.begin(),qq.end());
    rep(i,m){
        if(d+qq[i].second.first<0){
            cout << "No\n";
            return 0;
        }else{
            d += qq[i].second.second;
        }
    }
    cout << "Yes\n";
    return 0;
}

Measured memory_bytes: 43192
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>
#include<stack>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
typedef vector<string> vstring;
typedef vector<pint> vpint;
typedef stringstream SS;

template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }

#define rep(i,n) for(int i=0;i<(n);++i)
#define repn(i,m,n) for(int i=(m);i<(n);++i)
#define repd(i,n) for(int i=(n)-1;i>=0;--i)
#define repnd(i,m,n) for(int i=(n)-1;i>=(m);--i)
#define rep0(i,n) for(i=0;i<(n);++i)
#define repn0(i,m,n) for(i=(m);i<(n);++i)
#define repd0(i,n) for(i=(n)-1;i>=0;--i)
#define repnd0(i,m,n) for(i=(n)-1;i>=(m);--i)
#define repc(i,n) for(int i=0;i<=(n);++i)
#define repcn(i,m,n) for(int i=(m);i<=(n);++i)
#define repcd(i,n) for(int i=(n);i>=0;--i)
#define repcnd(i,m,n) for(int i=(n);i>=(m);--i)
#define repc0(i,n) for(i=0;i<=(n);++i)
#define repcn0(i,m,n) for(i=(m);i<=(n);++i)
#define repcd0(i,n) for(i=(n);i>=0;--i)
#define repcnd0(i,m,n) for(i=(n);i>=(m);--i)
#define all(n) n.begin(),n.end()
#define sz(n) ((int)(n).size())
#define IL for(;;)
#define MP make_pair
#define PB push_back
#define X second
#define Y first
#define p_queue(n) priority_queue<n,vector<n>,greater<n> >
#define PUTLINE cout<<"LINE:"<<__LINE__<<endl;

const int INF = 2147483647/3;
const double EPS = 1e-10;
const double PI = acos(-1.0);

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

int sig(double r) { return r < -EPS ? -1 : r > EPS ? 1 : 0; }

int main() {
	int m, n;
	int v1[400], v2[400];
	double m1, m2;
	IL {
		cin >> m;
		if (m == 0) break;
		rep (i, m - 1) cin >> v1[i];
		cin >> n;
		rep (i, n - 1) cin >> v2[i];
		m1 = m2 = 0;
		rep (i, m - 1) m1 += sin(v1[i] * PI / 180);
		rep (i, n - 1) m2 += sin(v2[i] * PI / 180);
		int th1, th2;
		th1 = th2 = 360;
		rep (i, m - 1) th1 -= v1[i];
		m1 += sin(th1 * PI / 180);
		rep (i, n - 1) th2 -= v2[i];
		m2 += sin(th2 * PI / 180);
		//cout << m1 << " " << m2 << endl;
		if (sig(m1 - m2) > 0) cout << 1 << endl;
		if (sig(m1 - m2) < 0) cout << 2 << endl;
		if (sig(m1 - m2) == 0) cout << 0 << endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include<stdio.h>

int main(void){
  char s[13];
  scanf("%s",s);

  int i;
  for(i=11;i>3;i--){
    s[i+1] = s[i];
  }
  s[4] = ' ';

  printf("%.13s\n",s);

  return 0;
}


Measured memory_bytes: 128
/*{{{*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<iostream>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include<bitset>
#include<vector>
#include<limits.h>
#include<assert.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORS(I, S) for (int I = 0; S[I]; ++I)
#define RS(X) scanf("%s", (X))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII> VPII;
typedef pair<LL,LL> PLL;
typedef vector<PLL> VPLL;
template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(LL &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const LL &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
#ifdef HOME
 #define DEBUG(...) {printf("# ");printf(__VA_ARGS__);puts("");}
#else
 #define DEBUG(...)
#endif
int MOD = 1e9+7;
void ADD(LL& x,LL v){x=(x+v)%MOD;if(x<0)x+=MOD;}
/*}}}*/
const int SIZE = 1e6+10;
int main(){
    LL a,b,c;
    R(a,b,c);
    if(a+b>=c)W("No");
    else {
        W((4*a*b<(c-a-b)*(c-a-b))?"Yes":"No");
    }
    return 0;
}


Measured memory_bytes: 256
import Data.List

main = do
  s <- getLine

  print $ minimum [length s - length (solve s c) | c <- s]

  where
    solve xs c = if eqAll xs then xs else solve (aux xs) c
      where
        aux (_:[]) = []
        aux (x:y:xs) = (if x == c || y == c then c else x) : aux (y:xs)

    eqAll :: Eq a => [a] -> Bool
    eqAll = (==1) . length . nub


Measured memory_bytes: 1020
#include <bits/stdc++.h>
#include <cmath>
using namespace std;
#define fast                                                                   \
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define int long long
#define ll long long
#define f(i, n) for (int i = 0; i < n; i++)
#define fo(i,a,n) for (i = a; i <= n; i++)
#define F first
#define S second
#define pii pair<int,int>
#define sz size()
#define all(v) v.begin(),v.end()
#define pb push_back
#define pf push_front    
#define PB pop_back
#define pll pair<long long, long long>
#define vi vector<int>
#define vl vector<int>
#define mp make_pair
#define mod 1000000007
typedef unsigned long long ull;
const int N = 200005;
const int MOD = 998244353 ;



void solve(){
    int n, ans = 0;
    string s;
    cin>>n>>s;
    f(i,n){
        if(s[i] == 'C' && i >= 2){
            if(s[i-1] == 'B' && s[i-2] == 'A')ans++;
        }
    }
    cout<<ans;
}


int32_t main() {
    fast
    int t;
    t = 1;
    //cin >> t;
    while(t--)solve();
    return 0;
}


Measured memory_bytes: 256
def create_fact_mod(num_max)
    $fmod = Array.new(num_max + 1)
    $fmod[0] = 1
    $fmod[1] = 1
    (2..num_max).each do |i|
        $fmod[i] = ($fmod[i - 1] * i) % MOD
    end
end

def create_seq_inv_mod(num_max)
    $simod = Array.new(num_max + 1)
    $simod[0] = 1
    $simod[1] = 1
    (2..num_max).each do |i|
        $simod[i] = (MOD - MOD / i) * $simod[MOD % i] % MOD
    end
end

def create_fact_inv_mod(num_max)
    $fimod = Array.new(num_max + 1)
    $fimod[0] = 1
    $fimod[1] = 1
    (2..num_max).each do |i|
        $fimod[i] = ($fimod[i - 1] * $simod[i]) % MOD
    end
end

def create_mod_tables(n)
    create_fact_mod(n)
    create_seq_inv_mod(n)
    create_fact_inv_mod(n)
end

def comb_mod(n, k)
    return $fmod[n] * $fimod[n - k] * $fimod[k] % MOD
end

def perm_mod(n, k)
    return $fmod[n] * $fimod[n - k] % MOD
end


H, W, A, B = gets.split.map(&:to_i)

M = [H-A, W-B].min
MOD = 10**9+7
ans = 0

create_mod_tables(H+W)

M.times do |i|
    h1 = H-A-i-1
    w1 = B+i
    ans += comb_mod(h1+w1, h1) * comb_mod(H-h1+W-w1-2, H-h1-1)
    ans %= MOD
end
puts ans


Measured memory_bytes: 6524
"""
author : halo2halo
date : 8, Jan, 2020
problem : ABC149
"""

import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

A, B, K = map(int, read().decode('utf-8').split())

TA = max(A - K, 0)
AO = min(B, B + A - K)
AO = max(AO, 0)
print(TA, AO)


Measured memory_bytes: 3064