akhauriyash/Code-Regression huggingface dataset:
//
// Created by yamunaku on 2019/10/22.
//

#include <bits/stdc++.h>

using namespace std;

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repl(i, l, r) for(int i = (l); i < (r); i++)
#define per(i, n) for(int i = ((n)-1); i >= 0; i--)
#define perl(i, l, r) for(int i = ((r)-1); i >= (l); i--)
#define all(x) (x).begin(),(x).end()
#define MOD9 998244353
#define MOD1 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000
#define SP <<" "<<
#define CYES cout<<"Yes"<<endl
#define CNO cout<<"No"<<endl
#define CFS cin.tie(0);ios::sync_with_stdio(false)
#define CST(x) cout<<fixed<<setprecision(x)

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int>> mti;
typedef vector<ll> vl;
typedef vector<vector<ll>> mtl;


mti e;
vi ec, ed;

struct UnionFind{
private:
    struct d{
        int num;
        int flag;
    };
    map<int, d> node;
    int ans = 0;

public:
    int root(int x){
        auto itr = node.find(x);
        if(itr == node.end()){
            node[x] = {-1, 0};
            return x;
        }else if(itr->second.num < 0){
            return x;
        }else{
            return itr->second.num = root(itr->second.num);
        }
    }

    void uni(int x, int y){
        x = root(x);
        y = root(y);
        if(x == y){
            if(node[x].flag == 0){
                ans++;
                node[x].flag = 1;
            }
            return;
        }
        ans++;
        if(node[x].flag == 1 && node[y].flag == 1) ans--;
        if(-node[x].num < -node[y].num) swap(x, y);
        node[x].num += node[y].num;
        if(node[y].flag == 1) node[x].flag = 1;
        node[y].num = x;
    }

    int solve(){
        return ans;
    }
};

struct data{
    vector<pair<int, int>> color;
    UnionFind uf;
};

vector<data *> dt;

int merge(int l, int r){
    if(dt[l]->color.size() < dt[r]->color.size()) swap(l, r);
    for(auto &p: dt[r]->color){
        dt[l]->uf.uni(p.first, p.second);
        dt[l]->color.push_back(p);
    }
    delete dt[r];
    return l;
}

vi ans;

int dfs(int x, int p){
    int nd = dt.size();
    dt.push_back(new data());
    for(auto ch:e[x]){
        if(ch == p) continue;
        nd = merge(nd, dfs(ch, x));
    }
    dt[nd]->color.emplace_back(ec[x], ed[x]);
    dt[nd]->uf.uni(ec[x], ed[x]);
    ans[x] = dt[nd]->uf.solve();
    return nd;
}


int main(){
    int n, k;
    cin >> n >> k;
    e = mti(n);
    ans = vi(n, -1);
    ec = vi(n), ed = vi(n);
    int u, v;
    rep(i, n - 1){
        cin >> u >> v;
        u--, v--;
        e[u].push_back(v);
        e[v].push_back(u);
    }
    rep(i, n){
        cin >> ec[i] >> ed[i];
    }
    dfs(0, -1);
    rep(i, n){
        cout << ans[i] << endl;
    }
    return 0;
}



Measured memory_bytes: 28856
#include <iostream>
#include <string>
#include <queue>
#include <math.h>
using namespace std;

#define ll long long

int main(){

    ll a, b;
    string op;
    queue<int> que;

    while(1){
        cin >> a >> op >> b;
        if(op == "+"){  que.push(a+b);}
        if(op == "-"){  que.push(a-b);}
        if(op == "*"){  que.push(a*b);}
        if(op == "/"){  que.push(a/b);}
        if(op == "?"){  break;}
    }

    int length = que.size();
    for(int i=0; i < length; i++){
        cout << que.front() << endl;
        que.pop();
    } 

    return 0;
}

Measured memory_bytes: 3120
#include<iostream>
#include<string>
#include<vector>
#include<iomanip>
#include<algorithm>
#include<queue>
#include<stack>
#include<map>
using namespace std;
#define ll long long
int main(){
    int n,k,x,i,ans=0;
    cin >> n>>k;
    for(i=0;i<n;i++){
      cin >>x;
      ans+=min(x,k-x);
    }
    cout << ans*2;
    return 0;
}


Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

//https://qiita.com/tubo28/items/e6076e9040da57368845
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main(){
    let s: Vec<char> = read::<String>().chars().collect();
    let mut count = 0;
    let mut ans = 0;
    for c in s.into_iter(){
        if c == 'A' || c == 'C' || c == 'G' || c == 'T'{
            count += 1;
        }else{
            ans = std::cmp::max(ans,count);
            count = 0;
        }
    }
    ans = std::cmp::max(ans,count);
    println!("{}",ans);
}

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

int main()
{
    string s,t,p;
    cin>>s;
    cin>>t;
    ll m = s.length();
    ll n = t.length();
    ll dp[m+1][n+1];
    for(ll i=0; i<=m; i++)
    {
        dp[i][0] = 0;
    }
    for(ll i=0; i<=n; i++)
    {
        dp[0][i] = 0;
    }
    
    for(ll i=1; i<=m; i++)
    {
        for(ll j=1; j<=n; j++)
        {
            if(s[i-1] == t[j-1])
            {
                dp[i][j] = 1+dp[i-1][j-1];
            }
            else
            {
                dp[i][j] = max(dp[i-1][j],dp[i][j-1]);
            }
        }
    }
    while(m>0 && n>0)
    {
        if(s[m-1] == t[n-1])
        {
            p.push_back(s[m-1]);
            m--;
            n--;
        }
        else if(dp[m-1][n] > dp[m][n-1])
        {
            m--;
        }
        else
        {
            n--;
        }
    }
    if(p.length()>0)
    {
       reverse(p.begin(),p.end());
        cout<<p; 
    }
    else
    {
        cout<<" ";
    }
    return 0;
}

Measured memory_bytes: 73976
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

int main(void) {
	int num = 0;
	int a, b;
	int ans = 0;
	cin >> num;

	for (int i = 0; i < num; i++) {
		cin >> a >> b;
		ans += (b - a + 1);
	}

	cout << ans << endl;

	return 0;

}

Measured memory_bytes: 256
#include <stdio.h>
int A[10000000],n;
int binarySearch(int key){
  int left=0;
  int right=n;
  int mid;
  while(left<right){
    mid=(left+right)/2;
    if(key==A[mid]) return 1;
    if(key>A[mid]) left=mid+1;
    else if(key<A[mid]) right=mid;
  }
  return 0;
}
int main(){
  int i,q,k,sum=0;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }
  scanf("%d",&q);
  for(i=0;i<q;i++){
    scanf("%d",&k);
    if(binarySearch(k))sum++;
  }
  printf("%d\n",sum);
  return 0;
}

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

using namespace std;

int N;

set<vector<long long int>>ans;
void saiki(vector<long long int>town, vector<long long int>nowInput, long long int maxlen);
void saiki2(vector<long long int>nextTown, vector<long long int>nextInput, long long int maxlen, long long int townPoint){
	bool f = true;
	if(nextInput[townPoint] <= 0)return;
	for(auto x: nextTown){
		if(nextInput[abs(x-townPoint)] > 0){
			nextInput[abs(x-townPoint)] --;
		} else {
			f = false;
			break;
		}
	}
	nextTown.push_back(townPoint);
	if(f){
		saiki(nextTown, nextInput, maxlen);
	}
}

void saiki(vector<long long int>town, vector<long long int>nowInput, long long int maxlen){
	while(maxlen > 0 && !nowInput[maxlen])maxlen--;
	if(maxlen == 0){
		if(town.size() == N){
			sort(town.begin(), town.end());
			ans.insert(town);	
		}
		return;
	}
	long long int townPoint = maxlen;
	saiki2(town, nowInput, maxlen, townPoint);
	townPoint = town[1] - maxlen;
	saiki2(town, nowInput, maxlen, townPoint);
}

int main(){
	while(cin >> N, N){
		ans = set<vector<long long int>>();
		vector<long long int>town(1), input(401);
		for(int i = 0; i < N * (N-1) / 2; i++){
			long long int x;
			cin >> x;
			if(i == 0){
				town.push_back(x);
			} else {
				input[x]++;
			}
		}
		saiki(town, input, 400);
		for(auto now: ans){
			for(int i = 0; i < N - 1; i++){
				cout << now[i + 1] - now[i];
				if(i == N-2){
					cout << endl;
				} else {
					cout << " ";
				}
			}
		}
		cout << "-----" << endl;
	}
}

Measured memory_bytes: 3248
#include <bits/stdc++.h>
using namespace std;
const int maxn = 10;
int arr[maxn],N;
bool vis[maxn];
struct S{
	int arr[3];
};
S tag;
int ans = 0x3f3f3f3f;
void dfs(S sta,int cos,int be){
	{
		bool flag = 1;
		for(int i = 0 ; i < 3 ; ++i){
			if(sta.arr[i] <= 0){
				flag = 0;
				break;
			}
		}
		if(flag){
			int res = cos;
			for(int i = 0 ; i < 3 ; ++i)
				res += abs(tag.arr[i] - sta.arr[i]);
			ans = min(ans,res);
		}
		
	}
	for(int i = be ; i < N; ++i){
		if(vis[i])continue;
		vis[i] = 1;
		for(int j = 0 ; j < 3 ; ++j){
			S buf = sta;
			if(buf.arr[j] == 0){
				buf.arr[j] += arr[i];
				dfs(buf,cos,i+1);
			}else{
				buf.arr[j] += arr[i];
				dfs(buf,cos+10,i+1);
			}
			
		}
		vis[i] = 0;
	}
}
int main(){
	scanf("%d",&N);
	for(int i = 0 ; i < 3 ; ++i){
		scanf("%d",&(tag.arr[i]));
	}
	for(int i = 0 ; i < N ; ++i) scanf("%d",arr+i);
	dfs({0,0,0},0,0);
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
K=input()
S=list(input())
answer_str=S[0]
if len(S) <= int(K) :

  for i in range(len(S)-1):
    answer_str += S[i+1] 
  
else :
  for i in range(int(K)-1):
    answer_str += S[i+1] 
  answer_str += "..."
print(str(answer_str))

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

int main() {
    ll N, Y;
    cin >> N >> Y;
    vector<ll> ans(3, -1);
    for (int i = 0; i <= N; i++) {
        for (int j = 0; j <= N-i; j++) {
            int k = N-i-j;
            ll val = 0;
            val += 10000*i;
            val += 5000*j;
            val += 1000*k;
            if (val == Y) {
                ans[0] = i; ans[1] = j; ans[2] = k;
                break;
            }
        }
    }

    for (int i = 0; i < 3; i++) {
        cout << ans[i] << " ";
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**7)

# first line
N, K = list(map(int, input().rstrip().split()))

ans = []
for k in range(K):
    d = input().rstrip()
    for i in input().rstrip().split():
        ans.append(i)

print(N - len(set(ans)))


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

#define pb push_back
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define REP(i,n) for(int _n=n, i=0;i<_n;++i)
#define FOR(i,a,b) for(int i=(a),_b=(b);i<=_b;++i)
#define FORD(i,a,b) for(int i=(a),_b=(b);i>=_b;--i)
#define trav(a, x) for (auto& a : x)
using ull = uint64_t;
using ll = int64_t;
using PII = pair<int, int>;
using VI = vector<int>;
#define INF (1ll<<60)

string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string) s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B> string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; }
template <typename A> string to_string(A v) {
bool first = true; string res = "{";
for (const auto &x : v) { if (!first) { res += ", "; } first = false; res += to_string(x); }
res += "}"; return res; }
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H); debug_out(T...); }
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

int main() {
    ios::sync_with_stdio(false), cin.tie(0);
    ll N, T;
    cin >> N >> T;
    vector<ll> V(N);
    REP(i, N) {
        cin >> V[i];
    }
    ll mx = -1, minPrice = LLONG_MAX, cnt = 0;
    REP(i, N) {
        if (V[i] < minPrice) {
            minPrice = V[i];
        }
        ll maxProfit = V[i] - minPrice;
        if (maxProfit <= 0) continue;
        if (maxProfit > mx) {
            mx = maxProfit;
            cnt = 1;
        } else if (maxProfit == mx) {
            cnt++;
        }
    }
    // cout << min(T / 2, cnt) << endl;
    cout << cnt << endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long lli;
const int maxn = 5e5 + 50;
typedef pair<int, int> P;

void solve();
int main()
{
	int t = 1;
//	cin >> t;
	for(int i=0; i<t; i++)
	{
		solve();
		cout << '\n';
	}
	return 0;
}

// type below

void solve()
{
	int a; cin >> a;
	int arr[a + 50], tmp[a + 50];
	for(int i=0; i<a; i++)
	{
		cin >> arr[i]; 
		tmp[i] = arr[i];
	}
	sort(tmp, tmp + a);
	for(int i=0; i<a; i++)
	{
		if(arr[i] >= tmp[a / 2]) cout << tmp[a / 2 - 1];
		else					 cout << tmp[a / 2];
		cout << '\n';
	}
}

Measured memory_bytes: 3712
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

#define rep(i,n) for(int i = 0; i < (n); ++i)
 
typedef long long ll;
typedef char str255[256];

#define BIG_PRIME 1'000'000'007
#define BP_remainder(x) ((x) % BIG_PRIME)

const int INF = 1 << 30;
const int INF_NEG = INF * -1;
const ll INF_LONG = 1LL << 62;
const ll INF_LONG_NEG = INF_LONG * -1;

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

    ll p1; rep(i, N) { if (A[i] == 1){ p1 = i; break; }}

    ll left = p1 / (K - 1);
    if (p1 % (K - 1)){
        ++left;
        if (p1 == 0 || p1 == N - 1){
            cout << left << endl;
            return 0;
        }
        p1 = left * (K - 1);
    }

    ll right = (N - p1 - 1) / (K - 1);
    if ((N - p1 - 1) % (K - 1)){
        ++right;
    }
    cout << left + right << endl;

    return 0;
}


Measured memory_bytes: 640
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**15
mod = 10**9+7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    n = I()
    a = LI()
    s = sorted(a)
    r = []
    if n % 2 == 0:
        b = s[n//2-1]
        c = s[n//2]
        for t in a:
            if t <= b:
                r.append(c)
            else:
                r.append(b)
    else:
        b = s[n//2]
        c = s[n//2-1]
        for t in a:
            if t >= b:
                r.append(c)
            else:
                r.append(b)


    return '\n'.join(map(str,r))


print(main())




Measured memory_bytes: 32608
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 

typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
using namespace std;

int main(int argc, char* argv[])
{
    while( 1 ) {
        int h,w;
        scanf("%d%d", &h, &w);
        if(h==0 && w==0) break;
        int i,j;
        for(i=0; i<h; i++) {
            for(j=0; j<w; j++) {
                if(i==0 || i==h-1 || j==0 || j==w-1) printf("#");
                else printf(".");
            }
            printf("\n");
        }
        printf("\n");
    }
    return 0;
}



Measured memory_bytes: 2696
let () = Scanf.scanf "%d\n" @@ fun n ->
  let list = List.init n (fun _ -> Scanf.scanf " %d" Fun.id) in
  Printf.printf "%s\n" @@
  if List.for_all (fun elm -> elm mod 2 = 1 || elm mod 3 = 0 || elm mod 5 = 0) list
  then "APPROVED"
  else "DENIED"

Measured memory_bytes: 3736
s = list(input())
n = len(s)

head_1 = s[:(n - 1) // 2]
tail_1 = s[n:n // 2:-1]

m = len(head_1)

if str(head_1) != str(tail_1):
    print('No')
else:
    head_2 = head_1[:m // 2]
    tail_2 = head_1[m:(m - 1) // 2:-1]

    if str(head_2) == str(tail_2):
        print('Yes')
    else:
        print('No')


Measured memory_bytes: 3060
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
const int N = 2e5+7;
const ll mod = 1e9+7;
int a[N];
int n;
ll ans;
ll cal(int b)
{
    ll ret=0;
    for(int i=1;i<=n;i++)
        ret+=abs(a[i]-(b+i));
    return ret;
}
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%d",&a[i]);
    }
    int l=-1e9,r=1e9;
    int lm,rm;
    while(l+1<r){
        lm=(l+r)>>1;rm=(lm+r)>>1;
        if(cal(lm)>cal(rm)){
            l=lm;
        }
        else{
            r=rm;
        }
    }
    ans=min(cal(l),cal(r));
    ans=min(ans,cal((l+r)>>1));
    printf("%lld\n",ans);
}

Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cassert>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <algorithm>
#include <utility>
#define llint long long
#define inf 1e18
#define rep(x, s, t) for(llint (x) = (s); (x) < (t); (x)++)
#define Rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))

using namespace std;
typedef pair<llint, llint> P;

llint n;

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n;
	cout << (n+999)/1000*1000-n << endl;
	
	return 0;
}

Measured memory_bytes: 3656
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std; 

int main(){
    int N,K;
    cin>>N>>K;
    vector<int> H(N);
    for(int i=0;i<N;i++){
        cin>>H[i];
    }
    sort(H.begin(),H.end());

    long long sum=0;
    for(int i;i<N-K;i++){
        sum+=H[i];
    }

    cout<<sum;
}

Measured memory_bytes: 1024
N = int(input())
s = []
for i in range(N):
    s.append(int(input()))

s.sort()
x = sum(s)

if str(x)[-1] != '0':
    print(x)
    exit()

ans = x
for i in range(N):
    ans = max(x-s[i], ans-s[i])
    if str(ans)[-1] != '0':
        print(ans)
        exit()
print(0)


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

using namespace std;

int p[20000];
int a[20000];
int b[20000];

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

    for (int i = 0; i < n; i++)
        a[i] = i + 1, b[i] = n - i;

    int val = 2 * n;
    for (int i = n - 1; i > 0; i--){
        for (int j = p[i]; j < n; j++)
            a[j] += val;
        for (int j = p[i]; j >= 0; j--)
            b[j] += val;
        val--;
    }

    for (int i = 0; i < n; i++)
        cout << a[i] << ' ';
    cout << '\n';
    for (int i = 0; i < n; i++)
        cout << b[i] << ' ';
    cout << '\n';
    return 0;
}


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

//g++ -g -o yourexe yourfile.cpp
//./yourexe < yourinput.in > youroutput.out

#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

#define M 998244353

#define ll long long
#define ld long double
#define vi vector<ll>
#define pi pair<ll, ll>
#define vii vector<pi>
#define vvi vector<vi>
#define pb push_back
#define endl "\n"

#define REP(i, s, e) for (ll i = s; i < e; i++)
#define RREP(i, s, e) for (ll i = s; i > e; i--)

#define all(v) v.begin(), v.end()
#define part(v, s, e) v.begin() + s, v.begin() + e
#define prll(v) for (auto i: v) cout << i << " ";

int main() {
    fast
	string s;
	ll k;
	cin >> s >> k;
	vi tmp;
	REP(i, 0, s.size()) {
		ll j = i, c = 0;
		while (j < s.size() && s[j] == s[i]) {
			c++;
			j++;
		}
		i = j-1;
		tmp.pb(c);
	}
	ll ans = 0;
	if (tmp.size() == 1)
		ans = (tmp[0]*k)/2;
	else {
		REP(i, 1, tmp.size() - 1)
			ans += (tmp[i]/2) * k;
		if (s[0] == s[s.size() - 1]) {
			ans += ((tmp[0] + tmp[tmp.size() - 1])/2) * (k-1);
			ans += tmp[0]/2 + tmp.back()/2;
		}
		else {
			ans += (tmp[0]/2) * k;
			ans += (tmp[tmp.size() - 1]/2) * k;
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
// #define USE_LLONG_AS_INT
#ifdef USE_LLONG_AS_INT
#define int long long
#define inf (1ll<<60)
#else
#define inf (1<<30)
#endif
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define Yes(f) cout<<(f?"Yes":"No")<<endl
#define yes(f) cout<<(f?"yes":"no")<<endl
#define YES(f) cout<<(f?"YES":"NO")<<endl
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())

using namespace std;

const int mod=1e9+7;
const string sp=" ";

void run();

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

signed main(){
    init();
    run();
    return 0;
}

#define N (1001*1001)
bool p[N+1];

void eratosthenes(void){
    for(int i=2;i<N;i++)
        p[i]=1;
    for(int i=2;i*i<N;i++){
        if(p[i]){
            for(int j=2*i;j<=N;j=j+i){
                p[j]=0;
            }
        }
    }
}

int d[1001][1001];
int n,m;
pi rec[1001][1001];
bool visited[1001][1001];

pi dfs(int y,int x){
    if(d[y][x]>m)return mp(0,0);
    if(visited[y][x])return rec[y][x];
    visited[y][x]=true;
    pi ret=dfs(y+1,x);
    if(x>0)ret=max(ret,dfs(y+1,x-1));
    if(x<1000)ret=max(ret,dfs(y+1,x+1));
    int prime=(ret.se?:p[d[y][x]]?d[y][x]:0);
    return rec[y][x]=mp(ret.fi+p[d[y][x]],prime);
}

void run(){
    eratosthenes();
    int x=500,y=500;
    int dx[]={1,0,-1,0},dy[]={0,-1,0,1};
    int dir=0;
    int cnt=1;
    int num=1;
    int cc=0;
    while(0<=x&&x<1001&&0<=y&&y<1001){
        d[y][x]=num++;
        y+=dy[dir],x+=dx[dir];
        cc++;
        if(cc%cnt==0)dir=(dir+1)%4;
        if(cc==cnt*2)cc=0,cnt++;
    }
    while(cin>>m>>n,m){
        memset(rec,-1,sizeof(rec));
        MEMSET(visited);
        int sy,sx;
        rep(i,1001)rep(j,1001){
            if(d[i][j]==n){
                sy=i,sx=j;
                break;
            }
        }
        pi ans=dfs(sy,sx);
        cout<<ans.fi<<sp<<ans.se<<endl;
    }
}


Measured memory_bytes: 16988
#include <bits/stdc++.h>
using namespace std;
const int maxn=100000+5;
int s[4][maxn],n,a[maxn];
int sum[maxn];
inline int lowbit(int x){return x&(-x);}
void add(int pos,int ad)
{
    while(pos<=n){
        sum[pos]+=ad;
        pos+=lowbit(pos);
    }
}
int getsum(int pos)
{
    int ret=0;
    while(pos>0){
        ret+=sum[pos];
        pos-=lowbit(pos);
    }
    return ret;
}
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=3;i++)
        for(int j=1;j<=n;j++) scanf("%d",&s[i][j]);
    for(int i=1;i<=n;i++){
        a[i]=(s[2][i]+1)/3;
    }
    bool can=true;
    for(int i=1;i<=n;i++){
        if(s[1][i]-s[2][i]!=s[2][i]-s[3][i] || abs(s[1][i]-s[2][i])!=1) {can=false;break;}
        if(i%2 != a[i]%2) {can=false;break;}
    }
    if(!can) {printf("No\n");exit(0);}
    memset(sum,0,sizeof(sum));
    int od=0,ev=0,odv=0,eve=0;
    for(int i=1;i<=n;i++){
        if(s[1][i]-s[2][i]==1) odv+=(a[i]&1),eve+=(a[i]%2==0);
    }
    for(int i=1;i<=n;i+=2){
        od+=((i+1)/2-1)-getsum(a[i]);
        add(a[i],1);
    }
    memset(sum,0,sizeof(sum));
    for(int i=2;i<=n;i+=2){
        ev+=(i/2-1)-getsum(a[i]);
        add(a[i],1);
    }
    if(od%2!=eve%2 || ev%2!=odv%2) can=false;
    if(!can) printf("No\n");
    else printf("Yes\n");
    return 0;
}


Measured memory_bytes: 2176
#include <iostream>
#include <string>
#include <list>
#include <stdio.h>
#include <ctype.h>
#include <string.h>

#define APPTXT_BUFSZ	128

using namespace std;

static void deleteX(list<int> &list, int x) {
    for(auto itr=list.begin(); itr!=list.end(); itr++ ) {
        if(*itr==x) {
            list.erase(itr);
            break;
        }
    }
}

int main(void) {
    list<int> list;
    int n;
    int x;
    string str;

	getline(cin,str);
	n = atoi(&(str[0]));

	while( n-- > 0 && getline(cin, str) ) {
		if (str[0] == 'i') {		// ("insert"?¢????)
			x = atoi(&(str[sizeof("insert") - 1]));
            list.push_front(x);
        } else {
			int c = str[sizeof("delete") - 1];
			if (isalpha(c)) {
				if (c == 'F') {		// ("deleteFirst"?¢????)
		            list.pop_front();
				} else {			// ("deleteLast"?¢????)
		            list.pop_back();
				}
			} else {				// ("delete"?¢????)
				x = atoi(&(str[sizeof("delete") - 1]));
				deleteX(list, x);
			}
		}
    }

	//display list
    for(auto itr=list.begin(); itr!=list.end(); itr++ ) {
        if(itr==list.begin()) {
			printf("%d", *itr);
        } else {
			printf(" %d", *itr);
        }
    }
	fputc('\n', stdout);

	return 0;
}

Measured memory_bytes: 34520
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define SORT(a) sort(a.begin(), a.end())
#define REVERSE(a) reverse(a.begin(), a.end())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define int long long
#define INF 1000000000000000000
using namespace std;

#define ANS(f) if(f) cout << "YES" << endl; else cout << "NO" << endl;

typedef vector<int> vec;
typedef vector<vec> mat;
typedef pair<int, int> Pii;

template<typename T>
void readv(vector<T> &a){ REP(i, a.size()) cin >> a[i]; }
void readi(vector<int> &a){ REP(i, a.size()){cin >> a[i]; a[i]--;} }
void debug(mat m){REP(i, m.size()){ REP(j, m[i].size()){ cout << m[i][j] << ","; } cout << endl; }}


signed main(){

    int N, P; cin >> N >> P;
    map<int, int> m;
    FOR(i, 2, 1000001){
        while(P % i == 0){
            P /= i;
            m[i] += 1;
        }
    }
    if(P > 1) m[P] += 1;
    int ans = 1;
    for(auto p: m){
        int k = p.second / N;
        REP(j, k) ans *= p.first;
    }
    cout << ans;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < (int)n; i++)
#define all(x) x.begin(), x.end()
#define MOD 1000000007//1e9+7
typedef long long ll;
using namespace std;
int main()
{
  int a;
  cin >> a;
  int Max, Min;
  Max = 0;
  Min = 1e9 + 1;
  int tmp;
  REP(i, a){
    cin >> tmp;
    Max = max(tmp, Max);
    Min = min(tmp, Min);
  }
  cout << Max - Min << endl;
}


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

int main() {
  string S;
  int n = 0;
  cin >> S;
  
  if ( S.size() % 2 == 0){
    for(int i = 0; i <= (S.size())/2 ; i++){
      if(S[i] != S[S.size() - i-1]){
        S[i] = S[S.size() - i-1];
          n++;
      }
    }
      cout << n << endl;
    }
  if ( S.size() % 2 == 1){
    for(int i = 0; i < (S.size()-1)/2 ; i++){
      if(S[i] != S[S.size() - i-1]){
        S[i] = S[S.size() - i-1];
          n++;
      }
    }
      cout << n << endl;
  }
}
      

Measured memory_bytes: 256
#include<iostream>
int main()
{
	int a[300], b[300];
	int i = 1;
	int j = 1;
	int v = 0, t = 0;
	for ( int i = 1; i <= 300; i++ )
	{
		std::cin >> a[i] >> b[i];
		if ( a[i] == 0 && b[i] == 0 )
		{
			break;
		}
		else
			{
				j++;
		    }
	}
		for ( int i = 1; i <= j; i++ )
	{
		for ( int v = 0; v < a[i]; v++ )
	{
		for ( int t = 0; t <= b[i]; t++ )
	{
		if (  v < a[i] && t < b[i] )
	    {
			std::cout << '#';
		}
		else
		{
			std::cout << '\n';
		}
	}
	}
	if (i != j-1)
	{
		std::cout << '\n';
	}
		}
	return 0;
}


Measured memory_bytes: 3080
from collections import deque

# 入力
N, M = map(int, input().split())
A, B = zip(*(map(int, input().split()) for _ in range(N - 1 + M)))

# 各頂点の深さを求め、深さを利用して元の木を復元する
G = [set() for _ in range(N + 1)]
G_inv = [set() for _ in range(N + 1)]
for a, b in zip(A, B):
    G[a].add(b)
    G_inv[b].add(a)
deg = [len(G_inv[i]) for i in range(N + 1)]
V = [i for i in range(1, N + 1) if not G_inv[i]]
deq = deque(V)
while deq:
    i = deq.popleft()
    for j in G[i]:
        deg[j] -= 1
        if deg[j] == 0:
            deq.append(j)
            V.append(j)

R = {i: r for r, i in enumerate(V)}
ans = '\n'.join(
    str(max(G_inv[i], key=lambda j: R[j], default=0))
    for i in range(1, N + 1)
)

# 出力
print(ans)


Measured memory_bytes: 82364
#include <bits/stdc++.h>
using namespace std;
#define Hello ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl '\n'
#define ll long long
const int N = 2e3 + 5, M = 2e5;
ll costs[M], ans[M];
vector<vector<pair<int, int>>> v;
int n, x, y;
void dijkestra(int src){
    priority_queue<pair <ll, ll>> pq;
    for(int i = 0; i < N; i++)
        costs[i] = 1e12;
    pq.push({0, src});
    costs[src] = 0;
    while(!pq.empty()){
        ll cost = -pq.top().first;
        ll node = pq.top().second;
        pq.pop();
        if (cost > costs[node]) continue;
        for(ll i = 0; i < v[node].size(); i++){
            if(cost + v[node][i].second < costs[v[node][i].first]){
                costs[v[node][i].first] = cost + v[node][i].second;
                pq.push({-(costs[v[node][i].first]), v[node][i].first});
            }
        }
    }
    for(int i = 1; i <= n; i++) ans[costs[i]]++;
}
int main()
{
    Hello
    cin >> n >> x >> y;
    v.resize(n + 5);
    v[x].push_back({y, 1});
    v[y].push_back({x, 1});
    for(int i = 1; i <= n; i++){
        v[i].push_back({i + 1, 1});
        v[i + 1].push_back({i, 1});
    }
    for(int i = 1; i <= n; i++) dijkestra(i);
    for(int i = 1; i <= n - 1; i++)
        cout << ans[i]/2 << endl;
    return 0;
}

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

const int MAX_N = 1e5 + 5;
int n, ans;
int Arr[MAX_N];
unordered_map <int, int> cnt[2][2], Mark;
unordered_map <int, int>::iterator it;

void calc(int x) {
	for (int i = 0; i < n; i++)
		cnt[x][i & 1][Arr[i]]++;
}

int main() {
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d", &Arr[i]);
		Mark[Arr[i]]++;
	}

	calc(0);
	sort(Arr, Arr + n);
	calc(1);

	for (it = Mark.begin(); it != Mark.end(); it++)
		ans += abs(cnt[0][0][it->first] - cnt[1][0][it->first]);

	printf("%d", ans >> 1);
	return 0;
}

Measured memory_bytes: 17316
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll n,k,a[100105];
ll dp[100105];
ll mini(ll arr[]);
ll rec(int i=0)
{
    if(i>=n)
        return 1e16;
    if(i==n-1)
        return 0;
    if(dp[i]+1)
        return dp[i];
    ll ch[101];
    for(int j=1;j<=k;j++)
    {
        ch[j-1] = abs(a[i]-a[i+j])+rec(i+j);
    }
    return dp[i] = mini(ch);
}

int main()
{
    memset(dp,-1,sizeof(dp));
    cin >> n >> k;
    for(int i=0;i<n;i++)
        cin >> a[i];
    for(int i=n;i<n+k;i++)
        a[i] = 1e16;
    cout << rec();
    return 0;
}

ll mini(ll arr[])
{
    ll res = arr[0];
    for(int i=1;i<k;i++)
        if(res>arr[i])
            res = arr[i];
    return res;
}


Measured memory_bytes: 86144
from sys import stdin,stdout
def INPUT():return list(int(i) for i in stdin.readline().split())
def inp():return stdin.readline()
def out(x):return stdout.write(x)
import math
#=================================================
l,r,d=INPUT()
count=0
i=d*int(math.ceil(l/d))
while(i<=r):
    if i%d==0:
        count+=1
    i+=d
print(count)


Measured memory_bytes: 61872
//Longest Common Subsequence

#include<stdio.h>
#include<string.h>
#define N 1001

int main()
{
  int i,n,k,j;
  int arr[N][N];
  char X[N],Y[N];
  
  scanf("%d",&n);
  for(i = 0; i < n; i++)
    {
      scanf("%s %s",X,Y);
      for(j = 1; j <= (int)strlen(X); j++)
	{
	  for(k = 1; k <=(int)strlen(Y); k++)
	    {
	      if(X[j-1] == Y[k-1])
		{
		  arr[j][k] = arr[j-1][k-1]+1;
		}
	      else{
		arr[j][k] = arr[j-1][k] > arr[j][k-1] ? arr[j-1][k] : arr[j][k-1];
	      }
	    }
	}
      printf("%d\n",arr[strlen(X)][strlen(Y)]);
    }
  return 0;
}



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

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

    if(A<=X && X<=A+B){
        cout << "YES" << endl;
    }
    else{
        cout << "NO" << endl;
    }

}

Measured memory_bytes: 3632
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val l = readLine()!!.split(" ").map { it.toInt() }
    var lsum = l.sum()
    var diff = Int.MAX_VALUE
    for(i in 1 until n){
        diff = Math.min(diff, Math.abs(l.take(i).sum() - (lsum - l.take(i).sum())))
    }
    println(diff)
}

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

int main(int argc, const char * argv[]) {
    int d[6], temp=0;
    int i;
    char c[101];
    
    for(i=0; i<6; i++){
        scanf("%d", &d[i]);
    }
    scanf("%s", c);
    for(i=0; i<strlen(c); i++){
        if(c[i] == 'E'){
            temp = d[2];
            d[2] = d[0];
            d[0] = d[3];
            d[3] = d[5];
            d[5] = temp;
        }
        if(c[i] == 'N'){
            temp = d[4];
            d[4] = d[0];
            d[0] = d[1];
            d[1] = d[5];
            d[5] = temp;
        }
        if(c[i] == 'S'){
            temp = d[1];
            d[1] = d[0];
            d[0] = d[4];
            d[4] = d[5];
            d[5] = temp;
        }
        if(c[i] == 'W'){
            temp = d[3];
            d[3] = d[0];
            d[0] = d[2];
            d[2] = d[5];
            d[5] = temp;
        }
    }
    
    printf("%d\n", d[0]);
    return 0;
}


Measured memory_bytes: 2104
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define per(i,j,n) for(int i=(int)(j);(int)(n)<=i;i--)
#define int long long
#define ll long long
#define ALL(a) (a).begin(),(a).end()
#define pb push_back
#define mp make_pair
#define endl "\n"
#define vi vector<ll>
#define pii pair<ll,ll>
#define vii vector<vi>
const int MOD=1e9+7;
//const int MOD=998244353;
const int INF=(1ll<<62)-1;
signed main(){
  double A,B,H,M; cin>>A>>B>>H>>M;
  double X=abs(30.0*H+0.5*M-M*6.0);
  X=std::min(X,360.0-X);
  double ans=sqrt(A*A+B*B-2*cos(X*M_PI/180.0)*A*B);
  printf("%.10lf\n",ans);
}

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

using namespace std ;

int dp[5005][5005] ;

int main()
{
	int N ; string S ; cin >> N >> S ;
	
	int ans = 0 ;
	int i , j ;
	int max = 0 ;
	
	for ( i = 0 ; i < 5005 ; i++ )
		for ( j = 0 ; j < 5005 ; j++)
			dp[i][j] = 0 ;
			
	for ( i = N-1 ; i >= 0 ; i--){
		for ( j = N-1 ; j > i ; j--){
			if ( S[j] == S[i] )
			{
				dp[i][j] = dp[i+1][j+1] + 1 ;
			}
			if ( max < min(dp[i][j],j-i) )
				max = min(dp[i][j],j-i) ;
		}
	}
	cout << max ;
	return 0 ;
}

Measured memory_bytes: 98176
//============================================================================
// Name        : u
// Date        : Wed Mar  6 16:50:29 CST 2019
// Author      : landcold7
// Description : Actions speak louder more than words
//============================================================================
#include "bits/stdc++.h"
using namespace std;

#define pb push_back
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define mst(x, y) memset(x, y, sizeof(x))
#define pvar(x) cout << #x << ": "
#define fora(e, c) for (auto &e : c)
#define fori(i, a, b) for (int i = a; i < b; ++i)
#define ford(i, a, b) for (int i = a; i > b; --i)
#define output(v) cout << (v) << '\n'
#define jam(x, n) cout << "Case #" << x << ": " << n << "\n"
#define prt(x, a, n) { cout << x[a]; if (a < n - 1) cout << " "; }
#define par(x, s, n, v) if(v) pvar(x); fori(y, s, n) prt(x, y, n) cout << "\n"

#ifndef __has_trace
#define trace(...)
#endif
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef vector<pii> vpii;

const ll inf = (ll) 1e18 + 7;

vl pre, dp;

void rec(int i, vi& not_taken, ll score_so_far, int mask, int group) {
    // If we already have a group denoted by mask, what should we do
    // for the rest of rabbits?
    // For each rabbit, there are two choice here:
    //      1> do not include this into new group,
    //      2> include this into new group
    if (i == sz(not_taken)) {
        dp[mask] = max(dp[mask], score_so_far + pre[group]);
        return;
    }

    rec(i + 1, not_taken, score_so_far, mask, group);
    rec(i + 1, not_taken, score_so_far, mask ^ (1 << not_taken[i]),
        group ^ (1 << not_taken[i]));
}

void solve() {
    int n; cin >> n;
    vector<vl> a(n, vl(n));
    fori (i, 0, n) fori (j, 0, n) {
        cin >> a[i][j];
    }

    pre.resize(1 << n);
    fori (mask, 0, (1 << n)) {
        fori (i, 0, n) {
            if (mask & (1 << i)) {
                fori (j, i + 1, n) {
                    if (mask & (1 << j)) {
                        pre[mask] += a[i][j];
                    }
                }
            }
        }
    }

    dp.resize(1 << n, -inf);
    dp[0] = 0;
    fori (mask, 0, (1 << n)) {
        vi not_taken;
        fori (i, 0, n) {
            if (!(mask & (1 << i))) {
                not_taken.pb(i);
            }
        }
        rec(0, not_taken, dp[mask], mask, 0);
    }
    output(dp[(1 << n) - 1]);
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    solve();
    return 0;
}



Measured memory_bytes: 1280
#include <stdio.h>
int main(void){
    // Your code here!
    int n,l,i,tmp,flag;
    int d[10],cnt[10]={0};
    scanf("%d %d",&n,&l);
    for(i=0;i<l;i++){
        scanf("%d",&d[i]);
        cnt[d[i]]++;
    }
    for(i=n;;i++){
        flag = 1;
        tmp = i;
        for(;;){
            if(tmp==0) break;
            if(cnt[tmp%10]==1){
                flag = 0;
                break;
            }
            tmp/=10;
        }
        if(flag==1){
            printf("%d\n",i);
            break;
        }
    }
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <string>

static bool Input(std::string &W, std::string &T)
{
	if (0x00 == &W || 0x00 == &T) {
		return false;
	}

	std::getline(std::cin, W);
	if (0 >= W.size() || 10 < W.size()) {
		return false;
	}

	std::string tmp;
	while (true) {
		std::getline(std::cin, tmp);
		if (0 >= tmp.size() || 1000 < T.size()) {
			return false;
		}
		if (0 == tmp.compare("END_OF_TEXT")) {
			break;
		}
		T.append(tmp + "\n");
	}

	transform(W.begin(), W.end(), W.begin(), tolower);
	transform(T.begin(), T.end(), T.begin(), tolower);

	return true;


}

static bool countSameWord(const std::string W, const std::string T, int &num)
{
	std::string new_str(T);
	std::string keyWord;
	int spos = 0;
	int epos = 0;

	num = 0;

	if (0x00 == &num) {
		return false;
	}

	while (true) {
		if (0 > epos) {
			break;
		}
		epos = new_str.find_first_of(" \n", spos);
		keyWord = new_str.substr(spos, epos - spos);
		if (0 == keyWord.compare(W)) {
			num++;
		}
		spos = epos + 1;
	}

	if (0 < num) {
		return true;
	}

	return false;

}
int main()
{
	std::string W, T;
	int num = 0;

	if (true == Input(W, T)) {
		if (true == countSameWord(W, T, num)) {
			std::cout << num << std::endl;
		}
	}

	return (0);
}

Measured memory_bytes: 3220
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main(void){
   int n,ans=0;
   string s;
   cin >> n >> s;
   rep(i,10)rep(j,10)rep(k,10){
                int x=30001,y=30001,flag=0;
                rep(a,n){
                    if(s[a]==i+48){
                     x = a;
                    break;
                     }
                }
                rep(b,n){
                    if(s[b]==j+48&&x<b){
                        y = b;
                        break;
                    }
                }
                rep(c,n){
                    if(s[c]==k+48&&y<c) flag++;
                }
                if(flag) ans++; 
   }
   cout << ans << endl;
}

Measured memory_bytes: 3684
let a=Int(readLine()!)!
let arr=readLine()!.characters.split{$0==" "}.map{Int(String($0))!}

var i = 0
var diff = 0

for i in 0..<a {
  if( arr[i] != i + 1 ) {
    diff += 1
  }

}

if ( diff <= 2 ) {
  print( "YES" )
} else {
  print( "NO" )
}

Measured memory_bytes: 4080
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Math;
using static System.Console;
using System.Text;

class Program
{
    static void Main(string[] args)
    {
        solve();
    }
    static Scanner cin;

    static int D;
    static int G;
    static int[] p;
    static int[] c;
    static void input()
    {
        cin = new Scanner();
        D = cin.nextInt();
        G = cin.nextInt();
        p = new int[D + 1];
        c = new int[D + 1];
        for(int i = 1; i <= D; i++)
        {
            p[i] = cin.nextInt();
            c[i] = cin.nextInt();
        }
    }
    static void solve()
    {
        input();
        int[,] dp = new int[D + 1,D * 100 + 1];
        int sumP = 0;
        for(int d = 1; d <= D; d++)
        {
            sumP += p[d];
            
            for(int i = 1; i <= sumP; i++)
            {
                for(int j = 0; j <= p[d] && i - j >= 0; j++)
                {
                    dp[d, i] = Max(dp[d - 1, i], dp[d - 1, i - j] + d * 100 * j +
                       (j == p[d] ? c[d] : 0));
                }
            }
        }
        for(int i = 1; ; i++)
        {
            if(dp[D, i] >= G)
            {
                WriteLine(i);
                return;
            }
        }
    }
    class Scanner
    {
        string[] s;
        int i;

        char[] cs = new char[] { ' ' };

        public Scanner()
        {
            s = new string[0];
            i = 0;
        }
        
        public string next()
        {
            if (i < s.Length) return s[i++];
            string st = Console.ReadLine();
            while (st == "") st = Console.ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            if (s.Length == 0) return next();
            i = 0;
            return s[i++];
        }

        public int nextInt()
        {
            return int.Parse(next());
        }

        public int[] ArrayInt(int N, int add = 0)
        {
            int[] Array = new int[N];
            for(int i = 0; i < N; i++)
            {
                Array[i] = nextInt() + add;
            }
            return Array;
        }

        public long nextLong()
        {
            return long.Parse(next());
        }

        public long[] ArrayLong(int N, long add = 0)
        {
            long[] Array = new long[N];
            for(int i = 0; i < N; i++)
            {
                Array[i] = nextLong() + add;
            }
            return Array;
        }

        public double nextDouble()
        {
            return double.Parse(next());
        }

        public double[] ArrayDounble(int N, int add = 0)
        {
            double[] Array = new double[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextDouble() + add;
            }
            return Array;
        }
    }
}

Measured memory_bytes: 13140
#include<bits/stdc++.h>
#define ll long long int
#define ld long double
#define sync ios_base::sync_with_stdio(false); cin.tie(NULL) 
#define input(arr,n) for(ll i1=0;i1<n;i1++ )cin>>arr[i1]
#define rep(n) for(ll i2=0;i2<n;i2++)
#define vmp(v,a,b) v.push_back(make_pair(a,b))
#define si(a) scanf("%lld",&a)
#define pi(a) printf("%lld",a)
#define aset(a,n,k) for(ll i3=0;i3<n;i3++)a[i3]=k; 	
#define mod 1000000007
#define mp(a,b) make_pair(a,b)
#define f first
#define s second 
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<ll, null_type,greater_equal<ll>, rb_tree_tag,tree_order_statistics_node_update>//s.order_of_key(val) *s.find_by_orde(ind)
using namespace std;
int main()
{
	sync;
	ll n,k;
	cin>>n>>k;
	if(k==1)
	cout<<0;
	else
	cout<<max(n-k,(ll)0)<<endl;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))

# 絶対値が最も大きいものを取得
M, M_index = 0, -1
for i, a in enumerate(A):
    if abs(M) <= abs(a):
        M = a
        M_index = i

# 全体に対してMを加算
for i in range(N):
    A[i] += A[M_index]
ans = [(M_index, i) for i in range(N)]

# 隣り合う数を見ていく
if M >= 0:
    for i in range(N - 1):
        if A[i] > A[i + 1]:
            A[i + 1] += A[i]
            ans.append((i, i + 1))
else:
    for i in range(N - 1, 0, -1):
        if A[i - 1] > A[i]:
            A[i - 1] += A[i]
            ans.append((i, i - 1))

print(len(ans))
for x, y in ans:
    print(x + 1, y + 1)


Measured memory_bytes: 3064
#include<stdio.h>
#include<string.h>
int main()
{
    char s[15],t[15],u[15];
    int a,b;
    scanf("%s %s",s,t);
    scanf("%d %d\n",&a,&b);
    scanf("%s",u);
    if(strcmp(u,s)==0) a--;
    else b--;
    printf("%d %d",a,b);
    return 0;
}


Measured memory_bytes: 128
S = raw_input()
T = raw_input()
a = []
for i in range (len(S)):
  A = S[len(S)-1]
  B = S[:len(S)-1]
  C = A+B
  a.append(C)
  S = C
if T in a:
  print "Yes"
else:
  print "No"

Measured memory_bytes: 2568
// xの3乗
// 1つの整数xを読み込んで、xの3乗を計算し結果を出力するプログラムを作成せよ。
// 【入力】
// 入力として1つの整数が与えられる。
// 【出力】
// xの３乗の計算結果を１行に出力する。最後に改行を付ける。
// 【制約】
// 1 ≦ x ≦ 100
// 【例】
// 入力：2、出力：8
// 入力：3、出力：27
#include<iostream>

int main(void) {
  int x, cubeX;

  std::cin >> x;

  cubeX = x * x * x;

  std::cout << cubeX << "\n";

  return 0;
}



Measured memory_bytes: 3072
#include <stdio.h>

int main(){
	int a,b,c,x=0,i;
	scanf("%d%d%d",&a,&b,&c);
	for(i=a;i<=b;i++){
		if(c%i==0){
			x++;
		}
	}
	printf("%d\n",x);
	return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

constexpr ld PI = acos(ld(-1));

int n, x[105], y[105];
ld ans[105], cur[105];

int main()
{
    ios_base::sync_with_stdio(false);

    cin >> n;
    for (int i = 0; i < n; ++i)
        cin >> x[i] >> y[i];
    if (n == 1) { cout << 1 << endl; return 0; }
    if (n == 2) { cout << 0.5 << endl << 0.5 << endl; return 0; }
    ld sum = 0;
    for (int i = 0; i < n; ++i) {
        vector<ld> v;
        for (int j = 0; j < n; ++j)
            if (i != j)
                v.push_back(atan2(ld(y[j] - y[i]), x[i] - x[j]));
        sort(v.begin(), v.end());
        v.push_back(v[0] + 2 * PI);
        ld mx = 0;
        for (int i = 0; i + 1 < v.size(); ++i)
            mx = max(mx, v[i + 1] - v[i]);
        cur[i] = max(mx - PI, (ld)0);
        sum += cur[i];
    }
    for (int i = 0; i < n; ++i)
        cout << setprecision(17) << fixed << cur[i] / sum << endl;

    return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>

int main(void) {

	int r, g, b;

	scanf("%d%d%d", &r, &g, &b);

	if ((10 * g + b) % 4 == 0) {
		printf("YES");
	}
	else {
		printf("NO");
	}
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
/*#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
/*template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
*/typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll,ll> pl;
typedef pair<int,int> pii;

#define int ll
#define LOCAL 0
#define dbg(x) cout << #x << " is " << x << "\n"
#define gll(x) scanf("%d",&x)
#define gll2(x,y) scanf("%d%d",&x,&y)
#define gll3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define gllarr(arr,n) f(i,n) gll(arr[i]);
#define sz(x) ((int)x.size())
#define s(x) sort(x.begin(),x.end())
#define all(v) v.begin(),v.end()
#define rs(v) { s(v) ; r(v) ; }
#define r(v) {reverse(all(v));}
#define pb push_back
#define f(i,n) for(int i=0;i<n;i++)
#define fr(i,n) for(int i=n-1;i>=0;i--)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,a,b) for(int i=a;i>=b;i--)

const ll mod = (ll)1e9 + 7;
const ll inf = (ll)1e16;
const ld eps = 1e-12;
const ll N = (int)1e5 + 5;
const ll LOGN = 19;
const ld PI = 3.14159265358979323846;
inline ll mul(ll a, ll b, ll m = mod) { return (ll)(a * b) % m;}
inline ll add(ll a, ll b, ll m = mod) { a += b; if(a >= m) a -= m; if(a < 0) a += m; return a;}
inline ll power(ll a, ll b, ll m = mod) { if(b == 0) return 1; if(b == 1) return (a % m); ll x = power(a, b / 2, m); x = mul(x, x, m); if(b % 2) x = mul(x, a, m); return x;}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    if (LOCAL) {
        freopen("C:\\Users\\Dishant\\Desktop\\Collection-DEV c++\\input.txt", "r", stdin);
        freopen("C:\\Users\\Dishant\\Desktop\\Collection-DEV c++\\output.txt", "w", stdout);
    }
    int n, h;
    cin>>h>>n;
    f(i, n) {
        int u;
        cin>>u;
        h -= u;
    }
    if(h <= 0) cout<<"Yes";
    else cout<<"No";
    return 0;
}


Measured memory_bytes: 256