akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<algorithm>
#include<vector>
#include<cstring>
#include<utility>
#include<queue>
#include<cmath>
#define mod 1000000007
#define INF 1000000000000000
using namespace std;

int main(){
    int n,w,sum[101]={},ans=10000000;
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%d",&w);
        sum[i+1]=sum[i]+w;
    }
    for(int i=1;i<n;i++){
        ans=min(ans,abs(sum[n]-2*sum[i]));
    }
    printf("%d\n",ans);
}

Measured memory_bytes: 128
n,m = map(int,input().split())
a = [0] *m
b = [0] *m
for i in range(m):
    a[i], b[i] = map(int, input().split())

ans = [a[0],b[0]]

for i in range(m-1):
    if ans[0] < a[i+1]:
        ans[0] = a[i+1]
    if ans[1] > b[i+1]:
        ans[1] = b[i+1]

if (ans[1]-ans[0] +1)<= 0:
    print(0)
    exit()

print(ans[1]-ans[0]+1)


Measured memory_bytes: 10868
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;
const ll MOD = 1000000007LL;

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

    int antenna[5], k;
    for (int i = 0; i < 5; i++) cin >> antenna[i];
    cin >> k;

    for (int i = 0; i < 5; i++) {
        for (int j = i + 1; j < 5; j++) {
            if (antenna[j] - antenna[i] > k) {
                cout << ":(\n";
                return 0;
            }
        }
    }

    cout << "Yay!\n";
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
#define rep2(x,from,to) for(int x=(from);x<(to);++(x))
#define rep(x,to) rep2(x,0,to)
const int MX = 1000000;
int main(){
	bool h[MX+1] = {};
	h[1] = h[2] = h[3] = h[5] = 1;
	rep2(i,2,MX+1) {
		if(h[i]) {
			if(i*2 <= MX) h[i*2] = 1;
			if(i*3 <= MX) h[i*3] = 1;
			if(i*5 <= MX) h[i*5] = 1;
		}
	}
    int m, n;
	while(cin >> m, m) {
		cin >> n;
		int cnt = 0;
		rep2(i,m,n+1) {
			if(h[i]) cnt++;
		}
		cout << cnt << endl;
	}
    return 0;
}

Measured memory_bytes: 2140
import numpy as np

N = int(input())

Cs = []
Ss = []
Fs = []
ans = [0] * N
ans_fix = [False] * N
for i in range(N-1):
    C,S,F = list(map(int, input().split()))
    Cs.append(C)
    Ss.append(S)
    Fs.append(F)

ans_fix[-1] = True

for i in range(N):
    for j in range(i, N-1):
        if i == 0:
            ans[j] = Ss[j] + Cs[j]
        elif not ans_fix[j-i]:
            if ans[j-i] <= Ss[j]:
                ans[j-i] = Ss[j]
            wait_time = Fs[j] - (ans[j-i] % Fs[j]) if ans[j-i] % Fs[j] != 0 else 0
            ans[j-i] += wait_time + Cs[j]

    ans_fix[N-2-i] = True

for a in ans:
    print(a)

Measured memory_bytes: 21780
#include<iostream>

int main(){
    long a, b, k;

    std::cin >> a >> b >> k;
    if(a - k <= 0){
        k -= a;
        a = 0;
        b -= k;
        if(b <= 0){
            b = 0;
        }
    }else{
        a -= k;
    }

    std::cout << a << " " << b << std::endl;

    return 0;
}


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

int main()
{
    ll n,d,ans=0,x,y,temp,m;
    cin>>n>>d;

    m=d*d;
    while(n--)
    {
        cin>>x>>y;
        if(x<0)
          x=-x;
        if(y<0)
          y=-y;

       temp=(x*x)+(y*y);

    //  cout<<"temp:  m:  "<<temp<<" "<<m<<endl;
      if(temp<=m)
        ans++;
      //cout<<"ans:  "<<ans<<endl;
    }
    cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 3604
n,m = map(int,input().split())
cnt = 0
pena = 0
problem = [0]*n
ac = 0
penalty = 0
for i in range(m):
    p,s = input().split()
    if problem[int(p)-1] == -1:
        continue
    if s == "WA":
        problem[int(p)-1]+=1
    else:
        ac += 1
        penalty += problem[int(p)-1]
        problem[int(p)-1] = -1
print(ac,penalty)

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

typedef long long ll;
typedef long double ld;
typedef vector<vector<int>> Graph;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
#define pi 3.14159265359
#define inf 2147483647
#define INF 9223372036854775807
#define mod 1000000007
#define mod2 998244353

int main() {
	ll x; cin >> x;
	ll n = x / 11;
	ll ans = 2 * n + ((x - 11 * n) + 5) / 6;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3580
import sys
input = sys.stdin.readline

N = int(input())
A = [0] * N
B = [0] * N
for i in range(N):
    A[i], B[i] = map(int, input().split())
    if N % 2 == 0:
        A[i] *= 2
        B[i] *= 2
A.sort()
B.sort()
if N % 2 == 1:
    print(B[N//2] - A[N//2] + 1)
else:
    print((B[N//2-1] + B[N//2] - A[N//2-1] - A[N//2]) // 2 + 1)

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

vector<pair<long long, long long> > prime_factorize(long long N) {
	vector<pair<long long, long long> > res;
	for (long long a = 2; a * a <= N; ++a) {
		if (N % a != 0) continue;
		long long ex = 0; // 指数

		// 割れる限り割り続ける
		while (N % a == 0) {
			++ex;
			N /= a;
		}

		// その結果を push
		res.push_back({a, ex});
	}

	// 最後に残った数について
	if (N != 1) res.push_back({N, 1});
	return res;
}

int main() {
	long long N;
	cin >> N;
	const auto &res = prime_factorize(N);

	if(N == 1){
		cout << 0 << endl;
		return 0;
	}

	int ans = 0;
	for(auto p : res){
		if(p.second < 3){
			ans += 1;
		}else if(p.second < 6){
			ans += 2;
		}else if(p.second < 10){
			ans += 3;
		}else if(p.second < 15){
			ans += 4;
		}else if(p.second < 21){
			ans += 5;
		}else if(p.second < 28){
			ans += 6;
		}else if(p.second < 36){
			ans += 7;
		}else if(p.second < 45){
			ans += 8;
		}else if(p.second < 55){
			ans += 9;
		}
	}

	cout << ans << endl;

}


Measured memory_bytes: 3628
// Maximum Difference

#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
#include <unordered_map>
#include <ios>
#include <iomanip>
#include <string>
#include <numeric>

using namespace std;

int n;

int main() {
    cin >> n;

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

    sort(a.begin(), a.end());

    cout << abs(*a.begin() - *(a.end() - 1)) << endl;

    return 0;
}


Measured memory_bytes: 256
from itertools import*
n=int(input())
a=[input().split()for _ in[0]*n]
for b in a:
 b[3:5]=b[4],b[3]
def f():
 for d,e in combinations(a,2):
  for p in([0,1,2,3,4,5],[1,5,2,0,4,3],[2,1,5,3,0,4],[3,0,2,5,4,1],[4,1,0,3,5,2],[5,1,4,3,2,0]):
   f=[d[i]for i in p]
   if f[0]==e[0]and f[5]==e[5]:
    f=f[1:5]*2
    for k in range(4):
     if f[k:k+4]==e[1:5]:return'No'
 return'Yes'
print(f())


Measured memory_bytes: 5656
h,w = map(int, raw_input().split())
if h%3 == 0 or w % 3 == 0:
  print 0
  exit()

def calc(x,y):
  ans = float('inf')
  for x1 in [x/3, x/3+1]:
    x2 = x-x1
    xy1 = x1*y
    xy2 = x2 * (y/2 + y%2)
    xy3 = x2 * (y/2)
    ans1 = max(xy1, xy2, xy3) - min(xy1, xy2, xy3)

    xy2 = (x2/2 + x2%2) * y
    xy3 = (x2/2) * y
    ans2 = max(xy1, xy2, xy3) - min(xy1, xy2, xy3)

    ans = min(ans, ans1, ans2)
  return ans

print min(calc(h,w), calc(w,h))



Measured memory_bytes: 2692
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(i=0;i<n;i++)
#define foreach(c,itr) for(__typeof(c)::iterator itr=c.begin();itr!=c.end();itr++)
typedef long long ll;
int i,j;

int main(){
	ios::sync_with_stdio(false);
    cin.tie();
    
    string s,t;
    cin>>s>>t;
    ll ans=10000;
    if(s==t){
    	cout<<0<<endl;
    	return 0;
	}
    for(i=0;i<=s.size()-t.size();i++){
    	string qs=s.substr(i,t.size());
    	ll sum=0;
    	for(j=0;j<t.size();j++){
    		if(t[j]!=qs[j])sum++;
		}
		if(sum<ans) ans=sum;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 3644
n = gets.to_i

a = Hash.new(0)
gets.split.each {|e| a[e.to_i] += 1}

sum = a.inject(0) {|r, (k,v)| r + k * v}

gets.to_i.times do
    b, c = gets.split.map(&:to_i)
    v = a[b]
    sum += (c - b) * v
    a[b] = 0
    a[c] += v
    p sum
end

Measured memory_bytes: 26124
s = input()
count = 0
ans = [0]*len(s)
flag = 0
for i in range(len(s)):
    if flag == 0:
        if s[i] == "R":
            count += 1
        elif s[i] == "L":
            index = i
            ans[index-1] += count - count//2
            ans[index] += count//2 + 1
            count = 0
            flag = 1
            continue
    elif flag == 1:
        if s[i] == "L":
            count += 1
        if i == len(s)-1:
            ans[index-1] += count - count//2
            ans[index] += count//2
            
        elif s[i] == "R":
            ans[index-1] += count - count//2
            ans[index] += count//2
            count = 1
            flag = 0
print(*ans)
        

Measured memory_bytes: 6400
//For higher stack size use g++ -O2 -std=c++11 -Wall -Wl,--stack=268435456 a.cpp -o a.exe in cmd
    #include <bits/stdc++.h>
    #include <cstdio>
    #include <cstring>
    #include <cmath>
    #include <cstring>
    #include <chrono>
    #include <complex>
    #define ll long long
    #define ld long double
    #define vi vector<int>
    #define vll vector<ll>
    #define vvi vector < vi >
    #define pii pair<int,int>
    #define pll pair<long long, long long>
    #define mod 1000000007
    #define inf 1000000000000000001;
    #define all(c) c.begin(),c.end()
    #define mp(x,y) make_pair(x,y)
    #define mem(a,val) memset(a,val,sizeof(a))
    #define eb emplace_back
    #define pb push_back
    #define f first
    #define s second
    
    using namespace std;

    ld pi = 3.14159265359;

    ld retval(ld x)
    {
        return pi*x/180.0;
    }

    int main()
    {
        std::ios::sync_with_stdio(false);
        int T;
        T=1;
        // cin.ignore(); must be there when using getline(cin, s)
        while(T--)
        {
            ll a,b,h,m;
            cin>>a>>b>>h>>m;
            ld ha = 0.5 * (h * 60 + m);  
            ld ma = 6 * m;
            ld x1 = a*cos(retval(ha)),y1 = a*sin(retval(ha));
            ld x2 = b*cos(retval(ma)),y2 = b*sin(retval(ma));
            ld ans = ((x2-x1)*(x2-x1) + (y2-y1)*(y2-y1));
            ans=sqrt(ans);
            printf("%.12Lf\n",ans);
        }
        return 0;
    }


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

using namespace std;

  int main() {
    int N,A,B;
    cin >> N;

    cin >> A;

    B = N % 500;

    if (B <= A) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
  }

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

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)n; ++i)
#define FOR(i, a, b) for(int i = a; i < (int)b; ++i)

typedef long long ll;

const int Inf = 1e9;
const double EPS = 1e-9;

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

int lcm(int a, int b) {
    return a * b / gcd(a, b);
}

int bitCount(long bits) {
    bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
    bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
    bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
    bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
    return (bits & 0x0000ffff) + (bits >>16 & 0x0000ffff);
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    int cnt = 0;
    rep (i, s.size()) {
        if (s[i] == 'S') cnt++;
        else {
            if (cnt > 0) cnt--;
        }
    }
    cout << cnt * 2 << endl;
    
    return 0;
}



Measured memory_bytes: 720
import java.util.Scanner;
public class Main {
    public static void main(String[] args){
    
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
     
    int ans = 1;
    while(ans*2 <= n) {
			ans *= 2;

		}
        	System.out.println(ans);
}
}

Measured memory_bytes: 35776
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>

using namespace std;

#define int long long
#define endl '\n'
#define maxn 100010
const int MOD = 1000000007;

void solve() {
    int n;
    cin >> n;

    if(n & 1)cout << 0;
    else{
        int ans = 0, p = 10;
        while(n >= p){
            ans += n/p;
            p *= 5;
        }
        cout << ans << endl;
    }
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int t = 1;
//    cin >> t;

    while (t--)
        solve();
    return 0;
}


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

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

const int INF=1e9;
const int MOD=1e9+7;

int main(){
    ll N,X,M; cin >> N >> X >> M;
    vector<ll> tmp;
    tmp.push_back(X);
    bool used[M+10]={};
    used[X]=true;
    ll res=X;
    ll next;
    while(true){
        next=(res*res)%M;
        if(used[next]) break;
        tmp.push_back(next);
        res=next;
        used[next]=true;
    }
    vector<ll> cur;
    bool flag=false;
    ll ans=0;
    int ind;
    for(int i=0;i<tmp.size();i++){
        if(tmp[i]==next){
            ind=i;
        }
    }
    for(int i=0;i<tmp.size();i++){
        if(i<ind) ans+=tmp[i];
        else cur.push_back(tmp[i]);
    }
    for(int i=1;i<cur.size();i++){
        cur[i]+=cur[i-1];
    }
    ans+=((N-ind)/cur.size())*cur[cur.size()-1];
    ll m=(N-ind)%cur.size();
    if(m!=0) ans+=cur[m-1];
    cout << ans << endl;
}

Measured memory_bytes: 4284
#include<iostream>
#include<vector>
#include<algorithm>
#include<numeric>
#include<map>
#define rep(i, n) for(ll i=0;i<n;i++)
using namespace std;
using ll = long long int;

ll n;

vector<ll> enum_div(ll n)
{
	std::vector<ll> ret;
	for (ll i = 1; i * i <= n; ++i) {
		if (n % i == 0) {
			ret.push_back(i);
			ret.push_back(n / i);
		}
	}
	sort(ret.rbegin(), ret.rend());
	return ret;
}

ll test(vector<ll> vec, vector<ll> a) {
	ll ret;
	ll size = vec.size();
	rep(i, size) {
		ll cnt = 0;
		ll tmp = vec[i];
		bool flag = true;
		rep(j, n) {
			if (a[j] % tmp != 0) {
				if (flag) {
					flag = false;
				}
				else {
					break;
				}
			}
			else {
				cnt++;
			}
		}
		if (cnt >= n - 1) {
			ret = tmp;
			break;
		}
	}
	return ret;
}

int main(void) {
	cin >> n;
	vector<ll> a(n);
	ll ret = 0;
	rep(i, n) {
		cin >> a[i];
	}
	sort(a.begin(), a.end());
	ll amax = a[n - 1];
	ll amax2 = a[n - 2];
	vector<ll> amax_cd = enum_div(amax);
	vector<ll> amax2_cd = enum_div(amax2);

	ret = test(amax_cd, a);
	ret = max(ret, test(amax2_cd, a));

	cout << ret << endl;
	return 0;
}

Measured memory_bytes: 1792
def warshall_floyd(n, dists):
    prev = [t.copy() for t in dists]

    for k in range(n):
        current = [t.copy() for t in prev]
        prev_k = prev[k]
        for i in range(n):
            prev_i, current_i = prev[i], current[i]
            prev_i_k = prev_i[k]
            for j in range(n):
                current_i[j] = min(prev_i[j], prev_i_k + prev_k[j])
        prev = current

    return prev


def solve(n, links, total_d, odd_vertices):
    if not odd_vertices:
        return total_d

    d_table = warshall_floyd(n, links)
    d_table = [[d for oj, d in enumerate(d_table[oi]) if oj in odd_vertices] for ni, oi in enumerate(odd_vertices)] ## odd_verticesのみ抽出したwarshall_floydテーブルになおす
    ndt = len(d_table)
    bit_dict = {1 << i: i for i in range(ndt)}

    def minimum_pair(remains):
        if not remains:
            return 0
        b = remains & -remains ## 1であるbitのうち一番下のbit 1桁をとってくる
        remains ^= b ## bで選んだbitを反転 こいつは1確定なので、それが0になるってこと
        i = bit_dict[b] ## i=2**b
        return min(minimum_pair(remains ^ (1 << j)) + d_table[i][j] for j in range(ndt) if remains & (1 << j)) ## remainsは訪れてないとこのbit管理、iが現在地点、jが次の奇点、これで末尾の1から各odd_verticesに再帰で訪れていく odd_vertices個分の辺を足す

    return total_d + minimum_pair((1 << ndt) - 1)


v, e = map(int, input().split())

dists = [[float('inf')] * v for _ in range(v)]
for i in range(v):
    dists[i][i] = 0
odd_vertices = [0] * v
total_d = 0

for _ in range(e):
    s, t, d = map(int, input().split())
    dists[s][t] = min(dists[s][t], d)
    dists[t][s] = min(dists[t][s], d)
    odd_vertices[s] ^= 1
    odd_vertices[t] ^= 1
    total_d += d

print(solve(v, dists, total_d, [i for i, v in enumerate(odd_vertices) if v]))


Measured memory_bytes: 5632
fn main() {
    let s = read_line();
    if s == "ABC" {
        println!("ARC");
    } else {
        println!("ABC");
    }
}

fn read_line() -> String {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim_end().to_owned()
}


Measured memory_bytes: 2108
#include <stdio.h>
int main()
{
    int n,i,j;
    scanf("%d", &n);
    long int a[n];
    for(i=0; i<n; i++)
    {
     scanf("%ld",&a[i]);
    }
    long int t=a[0];
    long int sum=0;
    for(i=1;i<n;i++){
        if(t>a[i]){
            sum=sum+t-a[i];
            t=t;
        }
        else{
            t=a[i];
        }

    }
    printf("%ld\n",sum);
    return 0;
}


Measured memory_bytes: 3264
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)

int dx[] = {-1,0,1,0};
int dy[] = {0,1,0,-1};
struct NODE{
	int x1,y1,x2,y2,d;
	NODE(int a,int b,int c,int D,int e){
		x1 = a , y1 = b , x2 = c , y2 = D , d = e;
	}
};
bool done[52][52][52][52] = {0};
bool data[52][52];
int main(){
	int W,H;
	while(cin >> W >> H , W){
		int a,b,c,d;
		cin >> a >> b >> c >> d;
		rep(i,52)rep(j,52)data[i][j] = true;
		rep(i,H)rep(j,W)cin >> data[i+1][j+1];
		queue<NODE> Q;
		Q.push(NODE(a,b,c,d,0));
		int ans = -1;
		rep(i,52)rep(j,52)rep(k,52)rep(l,52)
			done[i][j][k][l] = 0;
		
		while(Q.size()){
			NODE q = Q.front(); Q.pop();
			if(q.d >= 100) break;
			if(done[q.y1][q.x1][q.y2][q.x2])continue;
			else done[q.y1][q.x1][q.y2][q.x2] = true;
			
			if(q.x1 == q.x2 && q.y1 == q.y2){
				ans = q.d;
				break;
			}
			rep(i,4){
				int A = q.x1 + dx[i] , B = q.y1 + dy[i];
				int C = q.x2 - dx[i] , D = q.y2 - dy[i];
				if(data[B][A])A = q.x1 , B = q.y1;
				if(data[D][C])C = q.x2 , D = q.y2;
				Q.push(NODE(A,B,C,D,q.d+1));
			}
		}
		if(~ans){
			cout << ans << endl;
		}else{
			cout << "NA" << endl;
		}
	}
}

Measured memory_bytes: 8752
#include <iostream>
using namespace std;
 
int main(){
  int n; cin >> n;
  int a[n]; for(int j = 0; j < n; j++) a[j] = 0;
  int b[n-1]; for(int i = 0; i < n-1; i++) cin >> b[i];
  int sum = 0;
  
  for(int k = 0; k < n; k++){
    if(k == 0){
      a[k] = b[k];
    }
    else if(k == (n-1))
    {
      if(a[k-1] == b[k-1]) a[k] = a[k-1];
      else a[k] = b[k-1];
    }
    else
    {
      if(b[k-1] < b[k]) a[k] = b[k-1];
      else a[k] = b[k];
    }
    
    sum += a[k];
  }
  
  cout << sum << endl;
}

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

int main(int argc, const char * argv[]) {
    // insert code here...
    string N;
    cin >> N;
    
    if (N.at(0) == N.at(1) && N.at(1) == N.at(2)) cout << "Yes" << endl;
    else if (N.at(1) == N.at(2) && N.at(2) == N.at(3)) cout << "Yes" << endl;
    else cout << "No" << endl;
    
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main
{
    public static void main(String[] args)
    {
        Scanner sc=new Scanner(System.in);
        int ans=0;
        //String ans="even";

        int n=sc.nextInt();
        ++n;
        int c=sc.nextInt();
        int sum=0;
        for (int i=0;i<c;++i) { sum+=sc.nextInt();}

        if (sum%n==0){ ans=sum/n;}
        else {ans=sum/n+1;}

        System.out.println(ans);
    }
}


Measured memory_bytes: 26332
import java.util.*;
public class Main { 
	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		MyComp comp = new MyComp();
		while(true) {
			int n = stdIn.nextInt();
			int m = stdIn.nextInt();
			if(n == 0 && m == 0) break;
			ArrayList<Data> list = new ArrayList<Data>();
			boolean[] infected = new boolean[n+1];
			infected[1] = true;
			for(int i = 0; i < m; i++) {
				int t = stdIn.nextInt();
				int s = stdIn.nextInt();
				int d = stdIn.nextInt();
				list.add(new Data(t,s,d));
			}
			Collections.sort(list,comp);
			for(int i = 0; i < m; i++) {
				Data tmp = list.get(i);
				if(infected[tmp.s]) {
					infected[tmp.d] = true;
				}
			}
			int ans = 0;
			for(int i = 1; i <= n; i++) {
				if(infected[i]) {
					ans++;
				}
			}
			System.out.println(ans);
		}
	}
}

class Data {
	int time;
	int s;
	int d;
	Data(int t, int a, int b) {
		time = t;
		s = a;
		d = b;
	}
}

class MyComp implements Comparator<Data> {
	public int compare(Data o1, Data o2) {
		if(o1.time < o2.time)
			return -1;
		if(o1.time > o2.time)
			return 1;
		return 0;
	}
	
}

	

Measured memory_bytes: 168680
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
	    int A = sc.nextInt();
	    int B = sc.nextInt();
	    
	    int X = A - B * 2;
	    
	    if (X > 0) {
	    	System.out.println(X);
	    } else {
	    	System.out.println(0);
	    }
	}	
}	

Measured memory_bytes: 22612
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define eb emplace_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
#define fi first
#define se second
#define pi M_PI
#define PQ(T) priority_queue<T>
#define SPQ(T) priority_queue<T,vector<T>,greater<T>>
using ll=long long;
using P=pair<ll,ll>;
using PP=tuple<ll,ll,ll>;
using S=multiset<ll>;
using vi=vector<ll>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;
const ll inf=1001001001001001;
const int INF=1001001001;
const int mod=1000000007;
const double eps=1e-10;
template<class T> bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<'\n';}
template<class T> void outvp(T v){rep(i,v.size())cout<<'('<<v[i].fi<<','<<v[i].se<<')';cout<<'\n';}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<'\n';}
template<class T> void outvv(T v){rep(i,v.size())outv(v[i]);}
template<class T> bool isin(T x,T l,T r){return (l)<=(x)&&(x)<=(r);}
template<class T> void YesNo(T b){if(b)out("Yes");else out("No");}
void decimal(int x){cout<<fixed<<setprecision(x);}
ll GCD(ll a,ll b){if(b==0) return a; return GCD(b,a%b);}
ll LCM(ll a,ll b){return(a/GCD(a,b))*(b/GCD(a,b))*GCD(a,b);}
ll POW(ll a,ll b){a%=mod;if(b==0)return 1;if(b&1)return a*POW(a,b-1)%mod;ll k=POW(a,b/2);return k*k%mod;}
vi calc(ll x){vi res;while(x>0){res.eb(x%10);x/=10;}reverse(all(res));return res;}

void solve() {
  int n; cin>>n;
  string s; cin>>s;
  string t;
  rep(i,n/2){
    t+=s[i];
  }
  t+=t;
  bool f=false;
  if(s==t) f=true;
  YesNo(f);
}

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  solve();
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
const int maxn=1e5+7;
vi G[maxn];
int val[maxn];
int vis[maxn];
int ti;
typedef pair<int,int> pi;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int n;
	cin>>n;
	for(int i=1,u,v;i<n;i++){
		cin>>u>>v;
		G[u].push_back(v);
		G[v].push_back(u);
	}
	int k;
	cin>>k;
	priority_queue<pi> q;
	for(int i=0,v,p;i<k;i++){
		cin>>v>>p;
		val[v]=p;
		vis[v]=1;
		q.push(make_pair(p,v));
	}
	bool ok=1;
	while(!q.empty())
	{
		auto u=q.top();q.pop();
		for(auto v:G[u.second]){
			if(!vis[v]){
				vis[v]=1;
				val[v]=u.first-1;
				q.push(make_pair(val[v],v));
			}
			else{
				if(abs(val[v]-u.first)!=1)
				{
					ok=0;
					break;
				}
			}
		}
		if(!ok) break;
	}
	if(ok) 
	{
		cout<<"Yes\n";
		for(int i=1;i<=n;i++) cout<<val[i]<<'\n';
	}
	else cout<<"No\n";

	

}

Measured memory_bytes: 8308
#include<iostream>
#include<cstdio>
#include<string>
using namespace std;
string s;
int l;
int main()
{
    cin>>s;
    l=s.size();
    for(long i=0;i<l;i++)
    {
        if(s[i]=='C')
        {
            for(long j=i+1;j<l;j++)
            {
                if(s[j]=='F')
                {
                    cout<<"Yes";
                    return 0;
                }
            }
        }
    }
    cout<<"No";
    return 0;
}

Measured memory_bytes: 256
(let* ((n (read))
       (q (read))
       (c (loop :for p :from 1 :upto n collect(cons (read) (read))))
       (d nil))
  (mapcar (lambda (k) (if (<= (cdr k) q)
                          (push (car k) d)
                          nil)) c)
  (if (equal d nil)
      (princ "TLE")
      (format t "~A" (first (sort d #'<)))))


Measured memory_bytes: 4456
#include <iostream>
#include <cmath>
#include <stdio.h>
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
const int MAX = 510000;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit()
{
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++)
  {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}

// 二項係数計算
long long COM(int n, int k)
{
  if (n < k)
    return 0;
  if (n < 0 || k < 0)
    return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
bool is_integer(double x)
{
  return floor(x) == ceil(x);
}

int main()
{
  int n;
  int d1[100];
  int d2[100];
  int cnt = 0;

  cin >> n;
  for (int i = 0; i < n; i++)
  {
    cin >> d1[i] >> d2[i];
  }

  for (int i = 0; i < n; i++)
  {
    if (d1[i] == d2[i])
    {
      cnt++;
    }
    else
    {
      cnt = 0;
    }
    if (cnt == 3)
    {
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
}


Measured memory_bytes: 3624
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_set>
#include <vector>

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 DEBUG(...) debug(__LINE__, ":" __VA_ARGS__)

using Pi = pair<int, int>;
using ll = long long;
const int INF = 1 << 28;

string to_string(string s) {
  return s;
}

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

template <class T>
string to_string(vector<T> v) {
  string ret = "{";
  for (int i = 0; i < 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...);
}

void get() {}

template <class Head, class... Tail>
void get(Head& head, Tail&... tail) {
  cin >> head;
  get(tail...);
}

template <class T>
void getv(vector<T>& vec) {
  for (int i = 0; i < vec.size(); ++i)
    cin >> vec[i];
}

int main() {
	string S,T;
	cin>>S>>T;
	int ans=0;
	FOR(i,3)if(S[i]==T[i])ans++;
	print(ans);
  return 0;
}


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

using namespace std;

inline void read() {}
template <class S>
inline void read(S &arg) {
  cin >> arg;
}
template <class S>
inline void readA(S Lptr, S Rptr) {
  while (Lptr != Rptr) {
    read(*Lptr);
    Lptr++;
  }
}
template <class S, class... T>
inline void read(S &arg, T &... rest) {
  read(arg);
  read(rest...);
}

inline void write() {}
template <class S>
inline void write(S arg) {
  cout << arg;
}
template <class S>
inline void writeA(S Lptr, S Rptr) {
  if (Lptr != Rptr) {
    write(*Lptr);
    Lptr++;
  }
  while (Lptr != Rptr) {
    write(' ');
    write(*Lptr);
    Lptr++;
  }
}
template <class S, class... T>
inline void write(S arg, T... rest) {
  write(arg);
  write(' ');
  write(rest...);
}

#define rep(i, j, k) for (int i = j; i < (int)k; i++)
#define pb push_back
#define mt make_tuple
#define all(x) x.begin(), x.end()

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

template <class T, class S>
inline bool smin(T &a, S b) {
  return (T)b < a ? a = b, 1 : 0;
}
template <class T, class S>
inline bool smax(T &a, S b) {
  return a < (T)b ? a = b, 1 : 0;
}

constexpr int MOD = 1e9 + 7;
constexpr int N = 1e6 + 10;

template <typename T>
inline T mod(T &v) {
  return v = (v % MOD + MOD) % MOD;
}
template <typename S, typename T>
inline S add(S &l, T r) {
  return mod(l += r);
}

ll po(ll v, ll u) {
  return u ? po(v * v % MOD, u >> 1) * (u & 1 ? v : 1) % MOD : 1;
}

int n, m, a[N];
pair<ll, pii> edge[N];

ll par[N], sz[N], S[N];
pii act[N];
int getPar(int v) { return par[v] ? getPar(par[v]) : v; }

int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);

  read(n, m);
  fill(sz + 1, sz + 1 + n, 1);
  readA(S + 1, S + n + 1);
  rep(i, 0, m) {
    int y, u, v;
    read(u, v, y);
    edge[i] = {-y, {u, v}};
  }

  sort(edge, edge + m);

  for (int i = m - 1; ~i; i--) {
    int u = edge[i].second.first;
    int v = edge[i].second.second;
    v = getPar(v);
    u = getPar(u);
    if (v == u) continue;
    if (sz[v] > sz[u]) swap(v, u);
    par[v] = u;
    S[u] += S[v];
    sz[u] += sz[v];
    act[i] = {v, u};
  }

  int res = 0;
  rep(i, 0, m) {
    int v = edge[i].second.second;
    if (-edge[i].first > S[getPar(v)]) {
      res++;
      if (act[i].first) {
        par[act[i].first] = 0;
        sz[act[i].second] -= sz[act[i].first];
        S[act[i].second] -= S[act[i].first];
      }
    }
  }

  write(res);

  return 0;
}


Measured memory_bytes: 15360
import sys
import heapq
import math
import fractions
import bisect
import itertools
from collections import Counter
from collections import deque
from operator import itemgetter
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))

s=input()
if len(s)<4:
    print("No")
    exit()
if s[:4]=="YAKI":
    print("Yes")
else:
    print("No")

Measured memory_bytes: 77464
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i <= (n); i++)
#define zep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define printa(x,m,n) for(ll i = (m); i <= n; i++){cout << (x[i]) << " ";} cout<<endl;

ll powmod(ll a, ll x){
	if(x == 1){return a;}
	ll r = powmod(a, x/2);
	return (x%2)? (r*r%MOD)*a%MOD : r*r%MOD;
}

int main(){
	cin.tie(0); ios::sync_with_stdio(false);
	
	ll n, k; cin >> n >> k;
	
	ll ans[k+1]; memset(ans, 0, sizeof(ans));
	rrep(i, k, 1){
		//print(powmod(k/i, n))
		ans[i] += powmod(k/i, n); ans[i] %= MOD;
		//print(ans[i])
		for(ll j = 1; j*j <= i; j++){
			if(i%j == 0){
				if(j != i){
					ans[j] += MOD-ans[i]; ans[j] %= MOD;
				}
				if(j*j != i && i/j != i){
					ans[i/j] += MOD-ans[i]; ans[i/j] %= MOD;
				}
			}
		}
		//printa(ans, 1, k)
	}
	
	
	ll res = 0;
	rep(i, 1, k){
		res += ans[i]*i%MOD; res %= MOD;
	}
	print(res)
	return 0;
}

Measured memory_bytes: 4428
#include<bits/stdc++.h>
#include <atcoder/all>
#define rep(i,n) for(int i = 0;i<n;i++)
using namespace std;
using namespace atcoder;
typedef pair<int,int> P;
typedef long long ll;
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 main() {
    int n,m;
    cin >> n >> m;
    dsu uf(n);
    rep(i,m) {
        int a,b;
        cin >> a >> b;
        a--;b--;
        uf.merge(a,b);
    }
    set<int>se;
    rep(i,n) se.insert(uf.leader(i));
    int ans = se.size()-1;
    cout << ans << endl;
}

Measured memory_bytes: 7452
#include<stdio.h>
int a[1000000];
int main(void)
{
	int n,i,j,wk,x;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d",&a[i]);
	}
	for(i=0;i<n-1;i++){
		for(j=i+1;j<n;j++){
			if(a[i]<a[j]){
				wk=a[i];
				a[i]=a[j];
				a[j]=wk;
			}
		}
	}
	x=a[0]-a[n-1];
	if(x<0){
		x=x*(-1);
	}
	printf("%d\n",x);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>

using namespace std;

int main(void){
    int i10000,i5000,i1000,N,y;
    int n10000=-1,n5000=-1,n1000=-1;

    cin >> N >> y;

    for (i10000=0;i10000<=N;i10000++){
        for (i5000=0;i5000<=N-i10000;i5000++){
            // for (i1000=0;i1000<=N;i1000++){
                i1000 = N - i10000 - i5000;
                int x = 10000*i10000 + 5000*i5000 + 1000*i1000;
                bool isEqual = (x == y);
                //bool isCount = (N == (i10000+i5000+i1000));
                //if (isEqual && isCount) {
                if (isEqual) {
                    n10000 = i10000;
                    n5000 = i5000;
                    n1000 = i1000;
                    continue;
                }
            // }

        }
    }
    cout << n10000 << " " << n5000 << " " << n1000;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace std;
using namespace __gnu_pbds;   
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
#define ll long long int
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define pll pair<ll,ll>
#define all(x) x.begin(),x.end()
#define sz(x) (ll)x.size() 

ll power(ll x,ll y,ll p) 
{ 
    ll res = 1;      
    x = x % p;  
    while (y > 0) 
    { 
        if (y & 1) 
            res = (res*x) % p; 
        y = y>>1; 
        x = (x*x) % p;   
    } 
    return res; 
} 

int main()
{
    ios_base::sync_with_stdio(false);
	ll n,i,j,k,x,y,t,m;

	string s;
	cin >> s;
	if(s=="ABC")
		cout<<"ARC"<<endl;
	else
	cout<<"ABC"<<endl;

}

Measured memory_bytes: 3656
#include <stdio.h>
#include <string.h>
int main(){
        int N,i,j;
        scanf("%d",&N);
        int len[N];
        char W[N][11];
        char flg[] = "Yes";
        
        for(i=0;i<N;i++){
             scanf("%s",W[i]);
             len[i] = strlen(W[i]);
        }
        
        for(i = 0; i < N - 1; i++){
            for(j = i + 1; j < N; j++){
                if(strcmp(W[i], W[j])==0){
                    strcpy(flg,"No");
                    break;
                }
            }
            if(strcmp(W[i], W[j])==0){
                break;
            }
            if(!(W[i][len[i] - 1] == W[i + 1][0])){
                strcpy(flg,"No");
                break;
            }
        }
	    printf("\n%s",flg);
        return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using std::cout;
using std::endl;
using std::cin;

int main(){
	std::string s, w; cin >> s >> w;
	
	if(s.size() < w.size()) cout << "LESS" << endl;
	else if(w.size() < s.size()) cout << "GREATER" << endl;
	else{
		if(w == s) cout << "EQUAL" << endl;
		else if(s < w) cout << "LESS" << endl;
		else cout << "GREATER" << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using P = pair<int, int>;
const int mod = 1e9 + 7;

int main() {
  int H, W;
  cin >> H >> W;

  vector<vector<char>> G(H, vector<char>(W));
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cin >> G.at(i).at(j);
    }
  }

  vector<vector<int>> dp(H, vector<int>(W, 0));
  vector<vector<bool>> reached(H, vector<bool>(W, false));

  queue<P> q;
  q.push(P(0, 0));
  while (!q.empty()) {
    P p = q.front();
    q.pop();

    int u = p.first;
    int v = p.second;

    if (u >= H || v >= W) continue;

    if (reached.at(u).at(v)) continue;
    reached.at(u).at(v) = true;

    if (G.at(u).at(v) == '#') continue;

    if (u == 0 && v == 0) {
      dp.at(u).at(v) = 1;
    } else if (u == 0) {
      dp.at(u).at(v) = dp.at(u).at(v - 1) % mod;
    } else if (v == 0) {
      dp.at(u).at(v) = dp.at(u - 1).at(v) % mod;
    } else {
      dp.at(u).at(v) = (dp.at(u - 1).at(v) + dp.at(u).at(v - 1)) % mod;
    }

    q.push(P(u + 1, v));
    q.push(P(u, v + 1));
  }

  cout << dp.at(H - 1).at(W - 1) << endl;
  return 0;
}

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

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

#define p_ary(ary,a,b) do { cout << "["; for (int count = (a);count < (b);++count) cout << ary[count] << ((b)-1 == count ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)

int main() {
    int n;
    unordered_set<int> st;
    cin >> n;
    for (int i = 0;i < n;++i) {
        int a;
        cin >> a;
        st.insert(a);
    }
    cout << (n == st.size() ? "YES" : "NO") << endl;
}

Measured memory_bytes: 8520
n = int(input())
x=[]
u=[]
for _ in range(n):
    xx,uu = map(str,input().split())
    x.append(float(xx))
    u.append(uu)
ans = 0
for i in range(n):
    if u[i]=="JPY":
        ans += x[i]
    else:
        ans += x[i]*380000
print(ans)


Measured memory_bytes: 3060
h,w = map(int,input().split())

a=[]
a.append(["_"]*(w+2))
for i in range(1,h+1):
  a.append(["_"] + list(input()) + ["_"])
a.append(["_"]*(w+2))

b=a
for i in range(1,h+1):
  for j in range(1,w+1):
    if a[i][j] != "#":
      b[i][j] = str((a[i-1][j-1]=="#")+(a[i-1][j]=="#")+(a[i-1][j+1]=="#")+(a[i][j-1]=="#")+(a[i][j+1]=="#")+(a[i+1][j-1]=="#")+(a[i+1][j]=="#")+(a[i+1][j+1]=="#"))

for i in range(1,h+1):
  print("".join(b[i][1:w+1]))

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

public class Main {

	public static void main(String[] args) {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		try {
			String str;
			String[] arr;
			int i;
			int j;
			while((str = br.readLine()) !=  null){
				arr = str.split(" ");
				i = Integer.parseInt(arr[0]);
				j = Integer.parseInt(arr[1]);
				if(i == 0 && j == 0) {
					break;
				}
				
				if(i <= j) System.out.println(str);
				else {
					System.out.println(arr[1] + " " + arr[0]);
				}
			}
			br.close();
		} catch (IOException e) {
			// TODO 自動生成された catch ブロック
			e.printStackTrace();
		}

	}
}

Measured memory_bytes: 24296
n,m=map(int,input().split())
x = [list(map(int, input().split())) for _ in range(n)]
from itertools import *
res = 0
for a in product([-1, 1], [-1, 1], [-1, 1]):
    ts = [sum(i*j for i,j in zip(a,t)) for t in x]
    s = sum(sorted(ts,reverse=True)[:m])
    res = max(res, s)
print(res)


Measured memory_bytes: 3316
import java.util.*;
class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int M = sc.nextInt();
    for(int i=0; i<M; i++){
      N -= sc.nextInt();
      if(N<0){
        System.out.print("-1");
        return;
      }
    }
    System.out.print(N);
  }
}


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

#define int long long

typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
template<class T,class U>void chmin(T &t,U f){if(t>f)t=f;}
template<class T,class U>void chmax(T &t,U f){if(t<f)t=f;}

int N;
string S;

bool C(int x){
    int cnt,idx;
    for(idx=0,cnt=0;cnt<x&&idx<N;idx++){
        if(S[idx]=='I')cnt++;
    }
    if(cnt<x)return false;

    int J=0,O=0,I=0;
    rep(t,x){
        while(I<N&&S[I]!='I')I++;
        if(I==N)return false;
        I++;
        chmax(O,I);
        while(O<N&&S[O]!='O')O++;
        if(O==N)return false;
        O++;
        chmax(J,O);
        while(J<N&&S[J]=='O'||(S[J]=='I'&&J<idx))J++;
        if(J==N)return false;
        J++;
    }
    return true;
}

signed main(){
    cin>>N>>S;
    reverse(all(S));
    int lb=0,ub=N;
    while(ub-lb>1){
        int mid=(ub+lb)/2;
        if(C(mid))lb=mid;
        else ub=mid;
    }
    cout<<lb<<endl;
    return 0;
}

Measured memory_bytes: 2072
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define YES cout<<"YES"<<endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define all(a) a.begin(),a.end()
#define SORT(a) sort(all(a))
#define int long long
#define FOR(i, m, n) for(int i = m;i < n;i++)
typedef vector<int> VI;
typedef vector<VI> VVI;
const int MOD=1000000007;
const long long INF = 1LL << 60;
//----------------------------------------------
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int n,max_w; cin >> n >> max_w;
    int w[n],v[n];
    rep(i,n) cin >> w[i] >> v[i];
    int dp[n+1][max_w+1] = {};
    for(int i = 1; i <= n; i++){
        for(int j = 0; j <= max_w; j++){
            dp[i][j] = max(dp[i][j], dp[i-1][j]);
			if(j - w[i-1] >= 0) dp[i][j] = max(dp[i][j], dp[i-1][j-w[i-1]] + v[i-1]);
        }
    }
	cout << dp[n][max_w] << endl;


    return 0;
}

Measured memory_bytes: 79232
"use strict";

const main = input => {
  input = input.split("\n")[0];
  
  var arr = [];
  for (var i = 0; i < input.length; i++) {
    var s = input[i];
    
    if( s == '0') arr.push('0');
    else if( s == '1') arr.push('1');
    else if( s == 'B') {
      if( arr.length != 0 ){
        arr.pop();
      }
    }
  }
  console.log(arr.join(''));
  
}

main(require("fs").readFileSync("/dev/stdin", "utf8"));


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

#define rep(i, s, n) for(int i = s; i < n; ++i)
#define rrep(i, n) for(int i = n - 1; i > -1; --i)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
using namespace std;
const long long INF = 1000000000;
const int MOD = 1000000007;
typedef long long ll;
typedef pair<int, int> P;

int main() {
    int n;
    cin >> n;
    vector<pair<ll, ll>> xl(n);
    ll x, l;
    rep(i, 0, n){
        cin >> x >> l;
        xl[i] = make_pair(x + l, x - l);
    }
    int ans = 0;
    int t = -INF;
    sort(all(xl));
    rep(i, 0, n){
        if (t <= xl[i].second){
            ans++;
            t = xl[i].first;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 1792
#include <climits>
#include <cstring>
#include <cmath>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <functional>
#define fi first
#define se second
#define FO(x, n) for (int x = 0; x < n; ++x)
#define FOR(x, a, b) for (int x = a; x < b; ++x)
#define RFO(x, n) for (int x = n - 1; x >= 0; --x)
#define RFOR(x, a, b) for (int x = b - 1; x >= a; --x)
using namespace std;
typedef unsigned char byte;
typedef long long llong;
typedef unsigned long long ullong;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef pair<string, string> pss;
typedef pair<llong, llong> pll;
inline bool feq(const double& a, const double& b) { return fabs(a - b) < 1e-10; }

int N;
int nums[1010];

int main()
{
    cin >> N;
    FO (i, N)
        cin >> nums[i];
    sort(nums, nums + N);
    cout << (nums[N - 1] - nums[0]) << endl;
    return 0;
}

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

using namespace std;

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define F first
#define S second
#define forn(i, n) for (int i = 0; i < (int)n; i++)
#define pb push_back
#define fastIO ios::sync_with_stdio(0), cin.tie(0)
#define endl '\n'
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
void debug_out() {cerr << endl;}
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {cerr << " " << to_string(H), debug_out(T...);}

int main() {
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
    freopen("in.txt", "r", stdin);
    // freopen("out.txt", "w", stdout);
#else
#define debug(...) 3
    fastIO;
#endif
    int n,m;
    cin>>n>>m;
    n--,m--;
    cout<<n*(n+1)/2+m*(m+1)/2<<endl;
    return 0;
}


Measured memory_bytes: 3644
N = int(input())
a_list = []
b_list = []
for i in range(N):
    A, B = map(int, input().split())
    a_list.append(A)
    b_list.append(B)

a_list.sort()
b_list.sort()

a_m = a_list[N // 2 - 1] + a_list[N // 2] if N % 2 == 0 else a_list[(N + 1) // 2 - 1]
b_m = b_list[N // 2 - 1] + b_list[N // 2] if N % 2 == 0 else b_list[(N + 1) // 2 - 1]
a_m /= 2
b_m /= 2

print(int((b_m - a_m) / 0.5) + 1)

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

int main() {
    string S;
    cin >> S;
    int N = (int)S.size();
    for (int i = N - 2; i >= 0; i -= 2) {
        bool flag = true;
        for (int j = 0; j < i / 2; j++) {
            if (S[j] != S[i / 2 + j]) {
                flag = false;
                break;
            }
        }
        if (flag) {
            cout << i << endl;
            return 0;
        }
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std;

int main() {
  
  int a,b,c,d,x;
  double da,db;
  string s,ss,sss;
  
  int ans = 0;
  string anss = "";
  
  cin >> x >> a;
  
  int ab [] = {0 , 1 , 3 , 1 , 2 , 1 , 2 , 1 , 1 , 2 , 1 , 2 , 1};
  int result3 = std::max({a, b, c});
//--------------------------------------------------------------------------------
  x = x%500; 
  if(x <= a) anss = "Yes";
  else anss = "No";

  cout << anss << endl;

}

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

int main() {
    int h, w;

    while(1) {
        cin >> h >> w;
        if(h + w == 0) break;

        int temp = 150*150+150*150;
        int ans_h, ans_w;
        for(int i = 1; i <= 150; i++) {
            for(int j = i+1; j <= 150; j++) {
                if(temp > i*i+j*j && h*h+w*w < i*i+j*j) {
                    ans_h = i;
                    ans_w = j;
                    temp = i*i+j*j;
                    //cout << i << ' ' << j << endl;
                }
                else if(temp == i*i+j*j && temp == h*h+w*w) {
                    if(h < i && ans_h > i) {
                        ans_h = i;
                        ans_w = j;
                        temp = i*i+j*j;
                        //cout << i << ' ' << j << endl;
                    }
                }
                else if(temp == i*i+j*j && ans_h > i) {
                    ans_h = i;
                    ans_w = j;
                    temp = i*i+j*j;
                    //cout << i << ' ' << j << endl;
                }
                else if(i*i+j*j == h*h+w*w && h < i) {
                    ans_h = i;
                    ans_w = j;
                    temp = i*i+j*j;
                    //cout << i << ' ' << j << endl;
                }
            }
        }
        cout << ans_h << ' ' << ans_w << endl;
    }
    return 0;
}


Measured memory_bytes: 3104
#include <iostream>

#define VARIABLE(x) cerr << #x << "=" << x << endl
#define BINARY(x) cerr << #x << "=" << static_cast<bitset<16> >(x) << endl;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for (int i=m;i<(int)(n);i++)

const int INF = 10000000;
int dx[4]={1, 0, -1, 0}, dy[4]={0, 1, 0, -1};
using namespace std;
typedef long long  ll;
typedef pair<int, int> P;
const int MAX = 2*123500;

/** Problem1172 : Chebyshev's Thorem **/
int main()
{
	bool prime[MAX];
	int num[MAX]={0};
	
	for (int i=0; i<MAX; i++)
		prime[i] = true;
	
	prime[0] = false; prime[1] = false;
	
	for (int i=2; i<MAX; i++) {
		if (prime[i]) {
			for (int j=2; i*j<MAX; j++) {
				prime[i*j] = false;
			}
		}
	}
	
	for (int i=2; i<MAX; i++) {
		if (prime[i])
			num[i]=num[i-1]+1;
		else
			num[i] = num[i-1];
	}
	
	int N;
	while (cin>>N, N) {
		cout << num[2*N] - num[N] << endl;
	}
	return 0;
}

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

int main(){
    int a, b;
    cin >> a >> b;
    
    for(int i=0; i<100000; i++){
        int n1 = i*0.08;
        int n2 = i*0.1;
        if(n1==a && n2==b){
            cout << i << endl;
            // cout << n1 << " " << n2 << endl;
            return 0;
        }
    }
    cout << "-1" << endl;
    return 0;
}

Measured memory_bytes: 256