akhauriyash/Code-Regression huggingface dataset:
N, x = map(int, input().split())
A = list(map(int, input().split()))
ans = 0
for i in range(N - 1):
  s = A[i] + A[i + 1] - x
  ans += max(0, s)
  if s > 0:
    if s <= A[i + 1]:
      A[i + 1] -= s
    else:
      A[i + 1] = 0
print(ans)


Measured memory_bytes: 14540
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define RREP(i,m,n) for(int i=int(n)-1;i>=int(m);--i)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long int;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;

struct edge {
    int to, cost;
    edge(int to, int cost): to(to), cost(cost) {}
};

constexpr double EPS = 1e-10;
//constexpr double PI  = acos(-1.0);
//constexpr int INF = INT_MAX;
constexpr int MOD = 1'000'000'007;
//inline void modAdd(LL &l, LL &r) {l = (l + r) % MOD;}

template<class T> inline T sqr(T x) {return x*x;}

void solve() {
    int n,m;
    cin >> n >> m;
    vector<vector<edge>> es(n), res(n);
    VI c(n);
    int a,b;
    REP(i,0,n-1+m) {
        cin >> a >> b;
        a--; b--;
        es[a].pb(b, 1);
        res[b].pb(a, 1);
        c[b]++;
    }
    int r;
    REP(i,0,n) if (c[i] == 0) r = i;
    deque<int> q;
    VI l;
    q.push_back(r);
    while (!q.empty()) {
        int v = q.front();
        q.pop_front();
        l.push_back(v);
        for (auto &e: es[v]) {
            c[e.to]--;
            if (c[e.to] == 0) q.push_back(e.to);
        } 
    }
    //REP(i,0,n) cout << l[i] << endl;
    //cout << "---" << endl;
    VI ri(n);
    REP(i,0,n) ri[l[i]] = i;
    VI par(n, -1);
    RREP(i,0,n) {
        //dump(l[i]);
        int pos = 0;
        for (auto &e: res[l[i]]) {
            //dump(e.to);
            //dump(ri[e.to]);
            pos = max(pos, ri[e.to]);
        }
        for (auto &e: res[l[i]]) {
            if (ri[e.to] == pos) {
                par[l[i]] = e.to;
                break;
            }
        }
    }
    REP(i,0,n) cout << par[i] + 1 << endl;
}

int main() {
    solve();
    
    return 0;
}

Measured memory_bytes: 13436
n,m,c=map(int,input().split())
b=[int(_) for _ in input().split()]
l=[]
for i in range(n):
    a=[int(_) for _ in input().split()]
    x=c
    for j in range(m):
        x+=a[j]*b[j]
    if x>0:
        l.append(x)
print(len(l))

Measured memory_bytes: 9184
#include "bits/stdc++.h"
using namespace std;


long long f(int N, long long X) {
    vector<long long> sum = {1};
    vector<long long> pat = {1};
    for (int i = 0; i < N; i++) {
        sum.push_back(sum[i] * 2 + 3);
        pat.push_back(pat[i] * 2 + 1);
    }
    if (N == 0) {
        if (X <= 0) {
            return 0;
        }
        else {
            return 1;
        }
    }
    else if (X <= 1 + sum[N - 1]) {
        return f(N - 1, X - 1);
    }
    else {
        return pat[N - 1] + 1 + f(N - 1, X - 2 - sum[N - 1]);
    }
}

int main() {
    int N;
    cin >> N;
    long long X;
    cin >> X;
    cout << f(N, X) << endl;
}

Measured memory_bytes: 256
import sys
N, M = map(int, input().split())

dp_f = [None] * (10**5 + 2)
dp_f[1] = 1
dp_f[2] = 1
for i in range(3, 10**5 + 1):
    dp_f[i] = dp_f[i-1] + dp_f[i-2]
def f(n):
    if n == 1:
        return 1
    elif n == 2:
        return 1
    elif dp_f[n] is not None:
        return dp_f[n]
    v = f(n-1) + f(n-2)
    dp_f[n] = v
    return dp_f[n]

if M == 0:
    m = f(N+1)
    m %= 1000000007
    print(m)
    sys.exit(0)

A = [int(input()) for i in range(M)]

S = []
S.append(A[0])
for i in range(1, M):
    if A[i] == A[i-1] + 1:
        print(0)
        sys.exit(0)
    S.append(A[i] - A[i-1] - 1)
S.append(N - A[-1])

m = 1
for s in S:
    m *= f(s)
    m %= 1000000007

print(m)


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

using namespace std;


//repetition
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define euc_dis(x, y) sqrt(x*x + y*y)
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)

#define pb push_back
#define INF 999999999
#define MOD 1000000007
#define sp ' '


//typedef
typedef long long ll;
typedef pair<int, int> pint;
typedef pair<long, long> pll;
typedef map<int, int> mint;
typedef set<int> sint;
typedef vector<int> vint;
typedef vector<char> vchr;
typedef vector<long long> vll;
typedef vector<string> vstr;


ll mod(ll a, ll b){return (a%b+b)%b;}
ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b){return a*b/gcd(a,b);}
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void Judge(bool b){b?Yes():No();}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void JUDGE(bool b){b?YES():NO();}
ll powMod(ll a, ll b, ll c){ll ans=1; rep(i, b){ans=ans*a%c;} return ans;}
double distance(ll x1, ll y1, ll x2, ll y2){return sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));}

template<typename T>
void ppp(T n){cout << n << endl;}
template<typename T>
void dpp(T n){cerr << n << endl;}
template<typename T>
void vpp(T a){rep(i,a.size()){cout << a[i] << endl;}}
template<typename T>
void vdp(T a){rep(i,a.size()){cerr << a[i];}cerr << endl;}

const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int ddx[8] = {1,0,-1,0,1,-1,-1,1};
const int ddy[8] = {0,1,0,-1,1,1,-1,-1};

bool is10pown(ll x){
    rep(i, to_string(x).size()){
        if(x%10) return false;
        x /= 10;
    }
    return true;
}
int main(){

    cin.tie(0);
    ios::sync_with_stdio(false);

    int n;
    cin >> n;

    if(is10pown(n)){
        ppp(10);
    }
    else{
        ll sum = 0;
        for(auto c : to_string(n)){
            sum += c - '0';
        }
        ppp(sum);
    }

    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for (int i = (int)(s); i < (int)(n); i++)
const ll mod = ll(1e9) + 7;
const int INF = int(1e9);
ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
int main()
{
    ll A, B, C, D;
    cin >> A >> B >> C >> D;
    ll ans = 0;
    ll ans1 = (A - 1) / C + (A - 1) / D - (A - 1) / (C * D / gcd(C, D));
    ans1 = A - 1 - ans1;
    ll ans2 = B / D + B / C - B / (C * D / gcd(C, D));
    ans2 = B - ans2;
    //cout << ans1 << " " << ans2 << endl;
    cout << ans2 - ans1 << endl;
    return 0;
}


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

typedef long long LL;

int n,k;
LL li[1005];

LL nli[1000005];

int main()
{
   scanf("%d%d",&n,&k);
   for(int i=1;i<=n;i++){
      scanf("%lld",&li[i]);
   }
   int idd = 0;
   for(int i=1;i<=n;i++){
      LL tmp = 0LL;
      for(int j=i;j<=n;j++){
         tmp+=li[j];
         idd++;
         nli[idd] = tmp;
      }
   }
   LL ans = 0LL;
   int l = 1;
   int r = idd;
   int tmp = 50;
   while(tmp>=0){
      sort(nli+l,nli+r+1);
//      for(int i=l;i<=r;i++) cout << nli[i] << " ";
//      cout << endl;
      bool dpt = 1;
      for(int i=r;i>=l;i--){
         if(!((1LL<<tmp)&nli[i])){
//            cout << r-i << " <<< << \n";
            if((r-i)>=k){
               l = i+1;
               ans+=(1LL<<tmp);
//               cout << ">>> " << ans << endl;
            }
            dpt = 0;
            break;
         }
      }
      if(dpt) ans+=(1LL<<tmp);
      for(int i=l;i<=r;i++) if((1LL<<tmp)&nli[i])nli[i]^=(1LL<<tmp);
      tmp--;
   }
   printf("%lld\n",ans);
 	return 0;
}


Measured memory_bytes: 4352
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
   
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
   
const int MAX_N=1<<17;
const ll INF=1e9;
    
ll sum[2*MAX_N-1], part[2*MAX_N-1];
int m;
   
void init(int n){
    m=1;
    while(m<n) m*=2;
}
  
void eval(int k, int l, int r){
    if(part[k]<INF){
        sum[k]=part[k]*((ll)(r-l));
        if(k<m-1){
            part[2*k+1]=part[k];
            part[2*k+2]=part[k];
        }
        part[k]=INF;
    }
}
    
void update(int a, int b, ll x, int k, int l, int r){
	eval(k, l, r);
	if(r<=a || b<=l) return;
    if(a<=l && r<=b){
        part[k]=x;
        eval(k, l, r);
    }else{
        update(a, b, x, k*2+1, l, (l+r)/2);
        update(a, b, x, k*2+2, (l+r)/2, r);
        sum[k]=sum[2*k+1]+sum[2*k+2];
    }
}
    
ll getsum(int a, int b, int k, int l, int r){
	eval(k, l, r);
    if(b<=l || r<=a){
        return 0;
    }
    if(a<=l && r<=b){
        return sum[k];
    }else{
        return getsum(a, b, 2*k+1, l, (l+r)/2)+getsum(a, b, 2*k+2, (l+r)/2, r);
    }
}
   
int main()
{
    int n, q;
    cin>>n>>q;
    init(n);
    for(int i=0; i<q; i++){
        int tp;
        cin>>tp;
        if(tp==0){
            int s, t; ll x;
            cin>>s>>t>>x;
            update(s, t+1, x, 0, 0, m);
        }else{
            int s, t;
            cin>>s>>t;
            cout<<getsum(s, t+1, 0, 0, m)<<endl;
        }
    }
    return 0;
}


Measured memory_bytes: 6240
#include<stdio.h>
#include<stdlib.h>

int main(){
	int N,min,max;
	int A[100];
	scanf("%d",&N);
	for(int i=0;i<N;i++){
		scanf("%d",&A[i]);
	}
	min=A[0];
	max=A[0];
	for(int i=1;i<N;i++){
		if(A[i]<min)min=A[i];
		if(A[i]>max)max=A[i];
	}
	printf("%d",abs(max-min));
}

Measured memory_bytes: 128
n,m = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n)]
cd = [list(map(int, input().split())) for _ in range(m)]

for a,b in ab:
    ans = []
    for c,d in cd:
        ans.append(abs(a-c)+abs(b-d))
    print(ans.index(min(ans))+1)

Measured memory_bytes: 3060
N = int(input())
S = input()
T = input()
MOD = 10**9 + 7

isPrevI = S[0] == T[0]

ans = 3 if isPrevI else 6
now = 1 if isPrevI else 2

while now < N:
    isI = S[now] == T[now]

    if isPrevI:
        ans *= 2
    elif not isI:
        ans *= 3
    ans %= MOD
    now += 1 if isI else 2
    isPrevI = isI

print(ans)


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

#define fio ios_base::sync_with_stdio(false);cin.tie(NULL)
#define int long long 

using namespace std;

int32_t main()
{
	fio;
	int n,k;
	cin>>n>>k;
	int num=n%k;
	num=abs(num-k);
	num=min(num,abs(num-k));
	cout<<num<<endl;
	return 0;
}

Measured memory_bytes: 3672
import sys
from itertools import permutations
import math


def distance(x1, y1, x2, y2):
    return math.sqrt((x1 - x2) ** 2 + (y1 - y2) ** 2)


def main():
    input = sys.stdin.buffer.readline
    n = int(input())
    c = [0] * n
    for i in range(n):
        x, y = map(int, input().split())
        c[i] = (x, y)
    ans = 0
    for p in permutations(range(n)):
        for i in range(1, n):
            ans += distance(*c[p[i]], *c[p[i - 1]])
    ans /= math.factorial(n)
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 8892
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 7;
int n, a[maxn], p[maxn], d[maxn];

int main() {
	scanf("%d", &n); a[0] = -1;
	for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
	sort(a + 1, a + n + 1);
	if(a[n] == 0) printf("Yes\n");
	else {
		if(n % 3) printf("No\n");
		else {
			int cnt = 0;
			for (int i = 1; i <= n && cnt <= 3; ++i) {
				if(a[i] != a[i - 1]) {
					d[cnt] = i - 1;
					p[++cnt] = a[i];
				}
			}
			d[cnt] = n;
			for (int i = cnt; i; --i) d[i] -= d[i - 1];
			if(cnt == 1 || cnt > 3) printf("No\n");
			else {
				if(cnt == 2 && d[2] == d[1] * 2 && p[1] == 0) printf("Yes\n");
				else if(cnt == 3 && d[1] == d[2] && d[2] == d[3] && ((p[1] ^ p[2]) == p[3])) printf("Yes\n");
				else printf("No\n");
			}
		}
	}
	return 0;
}

Measured memory_bytes: 3992
#include <bits/stdc++.h>
#define REP(i,s,e) for(int i=(s); i<(e);i++)
#define rep(i,n) REP(i,0,n)
#define repe(i,n) for(auto &&i:n)
#define all(v) (v).begin(),(v).end()
#define decimal fixed<<setprecision(20)
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)
using namespace std;
using LL = long long;
const int INF = 1e9;
const LL LLINF = 1e16;
const int mod = 1e9+7;

int main(){
    int n;
    cin >> n;
    vector<string> s(n);
    LL ans = 0;
    rep(i, n) cin >> s[i];

    int a=0, b=0, ba=0;
    repe(i, s){
        rep(j, i.size()-1) if(i.substr(j, 2) == "AB") ans++;
        if(i[0] == 'B'){
            if(i[i.size()-1] == 'A'){
                ba++;
            }else b++;
        }else if(i[i.size()-1] == 'A') a++;
    }
    if(ba > 0){
        ans += ba - 1;
        ba = 1;
    }
    if(ba == 1){
        if(a > 0){
            a--;
            ans++;
        }
        if(b > 0){
            b--;
            ans++;
        }
        ba--;
    }
    ans += min(a, b);
    cout << ans << endl;


}


Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    ll n, m, z = mod * 328ll;
    cin >> n >> m;
    for (int i = 1; i < n; i++) {
        ll a[3] = {m * i};
        if (m % 2 && (n - i) % 2) a[1] = max((n - i) / 2 * m, m / 2 * (n - i)), a[2] = n * m - a[0] - a[1];
        else a[1] = a[2] = (n - i) * m / 2;
        sort(a, a + 3);
        z = min(z, a[2] - a[0]);
    }
    for (int i = 1; i < m; i++) {
        ll a[3] = {n * i};
        if (n % 2 && (m - i) % 2) a[1] = max((m - i) / 2 * n, n / 2 * (m - i)), a[2] = n * m - a[0] - a[1];
        else a[1] = a[2] = (m - i) * n / 2;
        sort(a, a + 3);
        z = min(z, a[2] - a[0]);
    }
    cout << z << '\n';
}


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

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

	vector<long long> a(n), num(n + 1, 0);

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

	long long sum = 0;
	for (int j = 1; j <= n; j++) {
		if (2 <= num[j]) {
			sum += num[j] * (num[j] - 1) / 2;
		}	
	}

	for (int i = 0; i < n; i++) {

		long long tmp_ans;
		long long tmp = num[a[i]];

		tmp_ans = sum;
		tmp_ans -= tmp*(tmp - 1) / 2;
		tmp_ans += (tmp - 1)*(tmp - 2) / 2;
		
		cout << tmp_ans << endl;
	}

	return 0;
}

Measured memory_bytes: 5760
#include<iostream>

using namespace std;

int main(){
  unsigned long long a, b, c, k;
  cin >> a >> b >> c >> k;

  int mod = k%2;
  long long ans = ((mod==0)? a-b : -a+b);
  if(-1000000000000000000 <= ans && ans <= 1000000000000000000) cout << ans << endl;
  else cout << "Unfair" << endl;
}


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

using namespace std;
#define ll long long
#define pb push_back
#define vi vector<int>
#define inf 1000000100

int main()
{
   string s1, s2, s3;
   cin >> s1 >> s2 >> s3;
   cout << "A" << s2[0] << "C" << endl;

}


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

#define all(a) a.begin(), a.end()
#define allr(a) a.rbegin(), a.rend()
#define rev(v) reverse(v.begin(), v.end());
#define make_unique(x) sort(all((x))); (x).resize(unique(all((x))) - (x).begin());
#define io() ios_base::sync_with_stdio(0);cout.tie(0);cin.tie(0);srand(time(NULL));
using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

signed main(){
	io();
	string s, t; cin >> s >> t;
	int a, b;  cin >> a >> b;
	string u; cin >> u;
	if(u == s){
		--a;
	}else{
		--b;
	}
	cout << a << ' ' << b << '\n';
	return 0;
}

Measured memory_bytes: 3596
#include <cstdio>

int N, M;
int p[100010];
int x[100010], y[100010];
int fa[100010];
int res;

int getFa(int u)
{
	int u2 = u;
	while(fa[u] != -1)
		u = fa[u];
	int u3;
	while(fa[u2] != -1){
		u3 = fa[u2];
		fa[u2] = u;
		u2 = u3;
	}
	return u;
}

void join(int u, int v)
{
	fa[u] = v;
}

void solve()
{
	int i;
	int u, v;
	for(i=0; i<N; i++)
		fa[i] = -1;
	for(i=0; i<M; i++){
		u = getFa(x[i]);
		v = getFa(y[i]);
		if(u != v){
			join(u, v);
		}
	}
	for(i=0; i<N; i++){
		u = getFa(i);
		v = getFa(p[i]);
		if(u==v)
			res ++;
	}
	printf("%d\n", res);
}

int main()
{
	//freopen("in.txt", "r", stdin);
	int i;
	scanf("%d%d", &N, &M);
	for(i=0; i<N; i++){
		scanf("%d", &p[i]);
		p[i] --;
	}
	for(i=0; i<M; i++){
		scanf("%d%d", &x[i], &y[i]);
		x[i]--, y[i]--;
	}
	solve();
	return 0;
}

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

const int N = 1e5 + 10;

int a[N];
long long pre[N], suf[N], sum[N];
 
int main(){
	int n, k;
	long long ans;
	scanf("%d %d",&n,&k);
	for (int i = 1; i <= n; i++) scanf("%d",&a[i]);
	sum[0] = 0;
	for (int i = 1; i <= n; i++) sum[i] = sum[i - 1] + a[i];
	pre[0] = 0;
	for (int i = 1; i <= n; i++) pre[i] = pre[i - 1] + max(a[i], 0);
	suf[n + 1] = 0;
	for (int i = n; i >= 1; i--) suf[i] = suf[i + 1] + max(a[i], 0);
	ans = 0;
	for (int i = 0; i <= n - k; i++)
		ans = max(ans, pre[i] + suf[i + k + 1] + max(sum[i + k] - sum[i], 0LL));
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 2944
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define FORL(i,x) for(int i=head[x];i;i=nxt[i])
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define PB push_back
#define MP make_pair
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() {
  string s;
  cin >> s;
  map<char,int> m;

  FOR(i,0,s.size()-1) ++m[s[i]];

  FOR(i,0,25){
    if(m['a'+i]==0){
      cout << s << char('a'+i) << endl;
      return 0;
    }
  }

  FORD(i,25,1){
    if(s[i-1]>s[i]) --m[s[i]];
    else{
      --m[s[i]];
      if(i!=1){
        FOR(j,0,i-2) cout << s[j];
      }
      FOR(j,(s[i-1]-'a'+1),25){
        if(m[char('a'+j)]==0){
          cout << char('a'+j) << endl;
          return 0;
        }
      }
    }
  }

  cout << -1 << endl;

}

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

typedef struct {
  int row;
  int col;
} Coord;

typedef struct _stack {
  struct _stack *next;
  Coord point;
} *stack, stackelem;


int solve (int W, int H);

stack  new_stack (void);
int is_empty (stack);
int push (stack, Coord);
Coord top (stack);
Coord pop (stack);


int main () {
  int W, H;

  while(scanf("%d %d", &W, &H))
    {
      if(W==0&&H==0)
	break;
      else
	printf("%d\n", solve(W,H));
    }

  return 0;
}


int solve (int W, int H) {
  stack S = new_stack ();  
  int M[H+2][W+2]; 
  Coord start;   
  int i, j, tile=1;
  int isl_num=2;
 
  for (i=0; i<=W+1; i++) { M[0][i] = '#'; M[H+1][i] = '#'; }
  for (i=1; i<=H; i++) { M[i][0] = '#'; M[i][W+1] = '#'; }

  for (i=1; i<=H; i++) {
    for (j=1; j<=W; j++) {
      scanf(" %d", &M[i][j]);
      /*if (M[i][j]=='@') {
	start.row = i;
	start.col = j;
	}*/
    }
  }
  
  for (i=1; i<=H; i++) {
    for (j=1; j<=W; j++) {
      //scanf(" %d", &M[i][j]);
      if (M[i][j]==1) {
	start.row = i;
	start.col = j;
	push(S,start);	
	while (!is_empty(S)) {
	  Coord current = pop(S);                  
	  int d;                                 
	  int D1[]={1,1,0,-1,-1,-1,0,1}; int D2[]={0,-1,-1,-1,0,1,1,1};
	  
	  for (d=0; d<8; d++) {
	    Coord nc = current;
	    
	    if(M[nc.row + D1[d]][nc.col + D2[d]] == 1)
	      {
		nc.row += D1[d];
		nc.col += D2[d];
		push(S,nc);
		M[nc.row][nc.col] = isl_num;
		tile++;
	      }
	  }
	}
	isl_num++;
      }
    }
  }

  /*
  push(S,start);
  

  while (!is_empty(S)) {
    Coord current = pop(S);                  
    int d;                                 
    int D1[]={1,0,-1,0}; int D2[]={0,-1,0,1};
    
    for (d=0; d<4; d++) {
      Coord nc = current;
      
      if(M[nc.row + D1[d]][nc.col + D2[d]] == 1)
	{
	  nc.row += D1[d];
	  nc.col += D2[d];
	  push(S,nc);
	  M[nc.row][nc.col] = i;
	  tile++;
	}
    }
    }*/
  isl_num = isl_num - 2;
  return isl_num;
}

stack new_stack (void) {
  stack s;
  s = (stack) malloc (sizeof (stackelem));
  if (s == NULL) return NULL;
  s->next = NULL;
  return s;
}

int is_empty (stack s) {
  return (s && s->next == NULL);
}

int push (stack s, Coord v) {
  stack p;
  if (s == NULL) return 0;
  p = (stack) malloc (sizeof (stackelem));
  if (p == NULL) return 0;
  p->point = v;
  p->next = s->next;
  s->next =  p;
  return 1;
}

Coord top (stack s) {
  if (s && s->next) 
    return s->next->point;
  exit (1);
}

Coord pop (stack s) {
  stack p;
  Coord v = top (s);
  p = s->next;
  s->next = p->next;
  free (p);
  return v;
}

Measured memory_bytes: 632
#include<stdio.h>
int main(void){
int a[10000],c;
int b=0;
while(1){
scanf("%d",&a[b]);
if(a[b]==0){
break;
}
b++;
}
for(c=1;c<=b;c++){
printf("Case %d: %d\n",c,a[c-1]);
}
return 0;
}


Measured memory_bytes: 1976
import math


def inputIntList():
    return [int(s) for s in input().split()]


def inputInt():
    return int(input())


def main():
    N = inputInt()
    A = inputIntList()

    pattern = [0 for _ in range(N + 1)]
    pattern[0] = 3

    ret = 1
    for a in A:
        ret *= pattern[a]
        pattern[a] -= 1
        pattern[a + 1] += 1
        # print(pattern)
    return ret % 1000000007


if __name__ == "__main__":
    print(main())


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

#define rep(var, start, end)  for(int var = start; var <= end; ++var)
#define drep(var, start, end) for(int var = start; var >= end; --var)

typedef long long ll;

using namespace std;

int main() {

    ll N, K;
    vector<ll> di(101);
    vector<vector<ll>> A(101, vector<ll>(101));
    set<ll> s;

    cin >> N >> K;

    rep(i, 1, K) {
        cin >> di[i];
        rep(j, 1, di[i]) {
            cin >> A[i][j];
        }
    }

    rep(i, 1, K) {
        rep(j, 1, di[i]) {
            s.insert(A[i][j]);
        }
    }

    cout << N - s.size() << endl;
    
    return 0;
}

Measured memory_bytes: 3716
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int X = sc.nextInt();
		int N = sc.nextInt();
		Integer[] p = new Integer[N];
		for (int i = 0; i < N; i++) {
			p[i] = sc.nextInt();
		}
		sc.close();

		// -1, +2, -3, +4という順番で調べていく
		int num = X;
		for (int i = 0; i <= 200; i++) {
			if (i % 2 == 1) {
				num = num - i;
			} else {
				num = num + i;
			}

			if (Arrays.asList(p).indexOf(num) == -1) {
				System.out.println(num);
				return;
			}
		}
	}
}


Measured memory_bytes: 36020
N = int(input())
H = list(map(lambda h: int(h), input().split(" ")))
 
lower = [0]
movable = 0
for i in range(len(H) - 1):
  if H[i] >= H[i + 1]:
    movable += 1
  else:
    lower.append(movable)
    movable = 0
else:
  lower.append(movable)

print(max(lower))

Measured memory_bytes: 20340
#n = gets.to_s.to_i
n,l = gets.to_s.split.map{|i|i.to_i}
cts = Array.new(n){ gets.to_s.split.map{|i|i.to_i} }

ans = 10 ** 18
cts.each_with_index do |ct,i|
  c = ct[0]
  t = ct[1]
  
  # p ct
  
  next if t > l
  
  ans = c if ans > c
end

puts ans != 10 ** 18 ? ans : "TLE"


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

long lcd(long a, long b) {
  if (a < b) {
    b = a + b;
    a = b - a;
    b = b - a;
  }
  if (a % b == 0)
    return b;
  else
    return lcd(b, a % b);
}

int main() {
  long A, B;
  cin >> A;
  cin >> B;
  long l = lcd(A, B);
  cout << l * (A / l) * (B / l);
  return 0;
}

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

namespace Header_Template {
  typedef long long li;
  template<class T>inline void read(T &x) {
    x = 0;
    T tmp = 1;
    char c = getchar();
    while ((c < '0' || c > '9') && c != '-') c = getchar();
    if (c == '-') tmp = -1, c = getchar();
    while (c >= '0' && c <= '9')
      x = (x << 1) + (x << 3) + c - '0', c = getchar();
    x *= tmp;
  }
  template<class T>inline void Max(T &x, T y) {
    if (y > x) x = y;
  }
  template<class T>inline void Min(T &x, T y) {
    if (y < x) x = y;
  }
}
using namespace Header_Template;

const int N = 1e5 + 10;
int n, k, a[N];

int main(void) {
  read(n), read(k);
  for (int i = 1; i <= n; ++i) read(a[i]);
  bool flag = 1;
  for (int i = 1; i <= n; ++i)
    if (a[i] > 0) flag = 0;
  if (flag) {
    for (int i = 1; i <= n; ++i) a[i] = -a[i];
    sort(a + 1, a + 1 + n);
  }

  int mid = 1;
  for (int i = 1; i <= n; ++i)
    if (a[i] >= 0) {
      mid = i;
      break;
    }
  int ans = 1e9;
  if (mid + k - 1 <= n) ans = a[mid + k - 1];
  for (int cnt = (a[mid] == 0) + 1, l = mid - 1; l && cnt <= k; --l, ++cnt) {
    int r = l + k - 1;
    if (r > n) continue;
    int cur = min(-a[l] * 2 + a[r], -a[l] + a[r] * 2);
    //printf("l = %d cur = %d\n", l, cur);
    Min(ans, cur);
  }
  printf("%d\n", ans);

  return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <cmath>
#include <climits>


// 1になっている2進数の桁の個数を返す
int cnt1Digit(int num){
	int cnt = 0;
	while(num > 0){
		cnt += num % 2;
		num /= 2;
	}
	return cnt;
}


int main(void){

	int n;
	std::cin >> n;

	std::vector<int> f;
	f.resize(n);
	for(int i = 0; i < n; i++){
		f[i] = 0;
		for(int j = 0, digit = 0; j < 10; j++, digit++){
			int tmp;
			std::cin >> tmp;
			f[i] += tmp * (int)(std::pow(2, digit));
		}
	}

	std::vector<std::vector<long long>> p;
	p.resize(n);
	for(int i = 0; i < n; i++){
		p[i].resize(11);
		for(int j = 0; j < 11; j++){
			std::cin >> p[i][j];
		}
	}

	long long max = LLONG_MIN;
	for(int i = 1; i < 1024; i++){

		long long sum = 0;
		for(int j = 0; j < n; j++){
			int c = cnt1Digit(i & f[j]);
			sum += p[j][c];
		}

		if(sum > max){
			max = sum;
		}
	}

	std::cout << max << std::endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int                     long long   
#define double                  long double
#define endl                    "\n"
#define pb                      push_back
#define PI                      3.1415926535897932384626433832795l
#define F                       first
#define S                       second
#define mp                      make_pair
#define f(i,n)                  for(int i=0;i<n;i++)
#define fastio                  ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define all(v)                  (v).begin(),(v).end()
#define rall(v)                 (v).rbegin(),(v).rend()
#define gcd(a,b)                __gcd((a),(b))
#define fill(a,value)           memset(a,value,sizeof(a));
#define minn(v)                 *min_element(v.begin(), v.end());
#define maxx(v)                 *max_element(v.begin(), v.end());
#define print(x)                cout<<(x)<<endl;
#define sum(v)+x                accumulate(v.begin(), v.end(),x);
#define debug(x)                cout<<#x<<'='<<(x)<<endl;
typedef pair<int,int>           pii;
typedef vector<int>             vi;
 
signed main() 
{
    fastio;
    cout << fixed << setprecision(12);
    int a,b,c;
    cin>>a>>b>>c;
    cout<<max(0ll,c-(a-b))<<endl;
    
    
    
    return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define debug(var) do{cout << #var << " : "; view(var);}while(0)
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
template<class T> void view(T e) {cout << e << endl;}
template<class T> void view(const vector<T> &v) {for(const auto &e : v){cout << e << " ";} cout << endl;}
template<class T> void view(const vector<vector<T>> &vv) {for(const auto &v : vv){view(v);}}
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const int inf = 1e9;
const ll inf_l = 1e18;
const int MAX = 1e5;

int main() {
    string s; cin >> s;
    int x; cin >> x;
    string ans;
    rep(i,s.size()) {
        if (i % x == 0) ans += s[i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
using P = pair<ll,ll>;
const ll mod = 1e9+7;
#define ALL(x) (x).begin(),(x).end()
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define REPS(i,n) for(ll (i)=1;(i)<=(n);(i)++)
#define RREP(i,n) for(ll (i)=(n-1);(i)>=0;(i)--)
#define RREPS(i,n) for(ll (i)=(n);(i)>0;(i)--)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());

template<class T> inline void chmin(T& a, T b){
    if (a > b){
        a = b;
    }
}

template<class T> inline void chmax(T& a, T b){
    if (a < b){
        a = b;
    }
}

/* modとる */
inline ll modu(ll a){
    return(a % mod + mod) % mod;
}

/* modつき二項係数 前処理必要*/
const ll binomialmax = 510000;
ll fac[binomialmax], finv[binomialmax], inv[binomialmax];

void cominit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < binomialmax; i++){
        fac[i] = modu(fac[i - 1] * i);
        inv[i] = modu(-inv[mod % i] * (mod / i));
        finv[i] = modu(finv[i - 1] * inv[i]);
    }
}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(12);
    cominit();
    ll ans = 0;
    ll N,M;
    cin >> N >> M;
    REP(i,N+1){
        ans = modu(ans + (i % 2 == 0 ? 1 : -1) *modu( modu(fac[M-i] * fac[N]) * modu(modu(finv[M-N] * finv[N-i]) * finv[i])));
    }
    cout << modu(ans*modu(fac[M]*finv[M-N])) << "\n";
}

Measured memory_bytes: 15540
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <queue>

using namespace std;

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

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

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

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

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

  int n; cin >> n;
  int ans;
  if(n > 2) ans = 0;
  else if(n == 2) ans = 1;
  else if(n == 1) ans = 2;
  else ans = 1;

  cout << ans << endl;
  return 0;
}

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

n=int(input())
l=deque([])
for i in range(n):
    a=int(input())
    ind=bisect.bisect_right(l,a-1)
    if ind==0:
        l.appendleft(a)
    else:
        l[ind-1]=a
print(len(l))

Measured memory_bytes: 69944
#include "bits/stdc++.h"
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
 
using namespace std;
 
#ifndef _DEBUG
#define main_ main
#endif
#define FOR(i,s,e) for (int i = int(s); i != int(e); i++)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LONG_MAX/2)
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
 
template <typename T>
using keyVal = pair<string, T>;
template<typename T>
bool val_greater(const keyVal<T>& left, const keyVal<T>& right) {
	return left.second > right.second;
}
 
void init_global() {}
 
int main_() {
	int N;
	cin >> N;
 
	const int D = 1000000007;
	ll pw = 1;
	FOR(i, 1, N+1) {
		pw *= i;
		pw %= D;
	}
 
	ll ans = pw%D;
	cout << ans << endl;
	return 0;
}


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


using namespace std;
typedef long long ll;

#define REP(i,n) for(int i=0; i<int(n); i++)
#define FOR(i,m,n) for(int i=int(m); i<int(n); i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define VI vector<int>
#define VP vector<pair<int,int>>
#define VPP vector<pair<int,pair<int,int>>>
#define VLL vector<long long>
#define VVI vector<vector<int>>
#define VVLL vector<vector<long long>>
#define VC vector<char>
#define VS vector<string>
#define VVC vector<vector<char>>
#define VB vector<bool>
#define VVB vector<vector<bool>>
#define fore(i,a) for(auto &i:a)
typedef pair <int, int> P;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;

const int  INF = 1 << 29;
const ll INFL = 1LL << 60;
const ll mod = 998244353;




int main() {
	
	
	int a, b, m;
	cin >> a >> b >> m;

	int aa = INF;
	int bb = INF;

	VI c(a), d(b);
	REP(i, a) {
		cin >> c[i];
		aa = min(aa, c[i]);
	}
	REP(i, b) {
		cin >> d[i];
		bb = min(bb, d[i]);
	}

	int ans = aa + bb;

	REP(i, m) {


		int e, f, g;
		cin >> e >> f >> g;

		e--; f--;
		ans = min(ans, c[e] + d[f] - g);
	}

	cout << ans << endl;





}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //GCC5.4.1で配列の範囲外アクセスをエラーにする

//cmdで g++ test.cpp とするとコンパイルできる
//制限1秒なら10^6は余裕 10^7は多分間に合う 10^8はよほど単純でないと厳しい

#define ALL(x) x.begin(),x.end()
typedef long long ll; //long long
typedef pair<int,int> pii; //pair<int,int>
typedef vector<int> vi; //vector<int>
typedef vector<vector<int>> vvi; //vector<vector<int>>
typedef vector<ll> vll; //vector<long long>
typedef vector<vector<ll>> vvll; //vector<vector<long long>>
typedef priority_queue<int, vector<int>, greater<int> > gpq; //逆順priority_queue
typedef priority_queue<int> pq;

//const int MOD=998244353;
const int MOD=1000000007; //10^9+7
const long double PI=3.14159265358979323846264338327950288;

int main(){
    int A,B;
    cin>>A>>B;
    cout<<A*B<<endl;
}


Measured memory_bytes: 3624
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Map;
import java.util.Scanner;

public class Main {
	
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		
		LinkedList<String> input = new LinkedList<String>();
		while(sc.hasNext()){
			input.addLast(sc.next());
		}
		
		LinkedList<Integer> stack = new LinkedList<Integer>();
		while(!input.isEmpty()){
			String ops = input.poll();
			
			if("+".equals(ops)){
				final int a = stack.poll();
				final int b = stack.poll();
				stack.addFirst(b + a);				
			}else if("-".equals(ops)){
				final int a = stack.poll();
				final int b = stack.poll();
				stack.addFirst(b - a);
			}else if("*".equals(ops)){
				final int a = stack.poll();
				final int b = stack.poll();
				stack.addFirst(b * a);
			}else if("/".equals(ops)){
				final int a = stack.poll();
				final int b = stack.poll();
				stack.addFirst(b / a);
			}else{
				stack.addFirst(Integer.parseInt(ops));
			}
		}
		
		System.out.println(stack.poll());
		
	}
}

Measured memory_bytes: 19400
const lines=readlines()
input()=shift!(lines)
int(x)=parse(Int,x)
function intLine()
    s=input()|>split
    int(s[1]),int(s[2])
end
function main()
    n,m=intLine()
    e=Array{Int,1}[[]for i=1:n]
    for i=1:m
        u,v=intLine()
        push!(e[u],v)
    end
    s,t=intLine()
    f=Array{Int,1}[[-3,-3,-3]for i=1:n]
    f[s][1]=0
    q=Array{Pair{Int,Int}}([s=>1])
    while !isempty(q)
        v,m=shift!(q)
        if v==t&&m==1;break;end
        u=m>2?1:m+1
        for w=e[v]
            if f[w][u]<0
                f[w][u]=f[v][m]+1
                push!(q,w=>u)
            end
        end
    end
    show(f[t][1]÷3)
end
main()

Measured memory_bytes: 167048
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;

/*
<url:https://agc019.contest.atcoder.jp/tasks/agc019_a>
問題文============================================================
 あなたは行きつけの店、インフバリューにアイスティーを買いに来ています。
 
 この店では、様々なサイズのボトル入りアイスティーが様々な価格で売られています。
 具体的な価格は、0.25 リットルサイズが一つ Q 円、0.5 リットルサイズが一つ H 円、
 1 リットルサイズが一つ S 円、2 リットルサイズが一つ D 円です。各サイズの在庫は無限にあります。
 
 あなたはちょうど N リットルのアイスティーを買いたいです。これに必要な金額は何円でしょうか？
 
 ちょうど N リットルのアイスティーを買うのに必要な最小の金額を出力せよ。
=================================================================

解説=============================================================

================================================================
*/
int main(void) {
	cin.tie(0); ios::sync_with_stdio(false);
    ll Q,H,S,D; cin >> Q >> H >> S >> D;
    ll N; cin >> N; N*= 4; // Q 1l, H 2l, S 4l, D 8l
    ll Ans = 0;
    if(N >= 8){
        ll M = min({8*Q,4*H,2*S,D});
        Ans += N/8*M;
        N -= N/8*8;
    }
    if(N >= 4){
        ll M = min({4*Q,2*H,S});
        Ans += N/4*M;
        N -= N/4*4;
    }
    if(N >= 2){
        ll M = min({2*Q,H});
        Ans += N/2*M;
        N -= N/2*2;
    }
    Ans += N*Q;
    cout << Ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())
#define ll long long
#define pb(a) push_back(a)
#define INF 1LL<<50
#define MOD 1e9+7
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

typedef vector<unsigned int>vec;
typedef vector<vec> mat;
typedef tuple<ll, ll, ll> T;

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N,M;
    cin>>N>>M;
    const int NMAX=1000;
    const int MMAX=2000;
    vector<int> a(MMAX),b(MMAX);
    vector<ll> c(MMAX);

    REP(i,M){
        cin>>a[i]>>b[i]>>c[i];
        c[i] = -c[i];
    }

    vector<ll> dist(NMAX);

    REP(i,N) dist[i]=INF;

    dist[0]=0;

    for(int loop=0;loop<N;++loop){
        for(int i=0;i<M;++i){
            if(dist[a[i]-1]==INF) continue;

            if(dist[b[i]-1] > dist[a[i]-1]+c[i]) dist[b[i]-1] = dist[a[i]-1] + c[i];
        }
    }

    ll ans = dist[N-1];

    vector<bool> negative(NMAX,0);

    for(int loop=0;loop<N;++loop){
        for(int i=0;i<M;++i){
            if(dist[a[i]-1]==INF) continue;

            if(dist[b[i]-1] > dist[a[i]-1]+c[i]){
                dist[b[i]-1] = dist[a[i]-1] + c[i];
                negative[b[i]-1] = true;
            }

            if(negative[a[i]-1]==true) negative[b[i]-1]=true;
        }
    }

    if(negative[N-1]) cout<<"inf"<<endl;
    else cout<<-ans<<endl;
    return 0;
}


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

int main()
{
     int a,b,c;
     scanf("%d%d%d",&a,&b,&c);
     int sum=a*100+b*10+c;
     if(sum%4==0)
        cout<<"YES"<<endl;
     else
        cout<<"NO"<<endl;
     return 0;


}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define xx first
#define yy second
#define mp make_pair
#define pb push_back
#define mset(x, y) memset(x, y, sizeof x)
#define mcpy(x, y) memcpy(x, y, sizeof x)
using namespace std;

typedef long long LL;
typedef pair <int, int> pii;

inline int Read()
{
	int x = 0, f = 1, c = getchar();
	for (; !isdigit(c); c = getchar())
		if (c == '-')
			f = -1;
	for (;  isdigit(c); c = getchar())
		x = x * 10 + c - '0';
	return x * f;
}

const int MAXN = 100005;

int n, p;
LL cur;

struct Node
{
	int w, b;
	bool operator < (const Node &c) const
	{
		return 1LL * w * (100 - p) + 1LL * b * p > 1LL * c.w * (100 - p) + 1LL * c.b * p;
	}
} a[MAXN];

int main()
{
#ifdef wxh010910
	freopen("data.in", "r", stdin);
#endif
	n = Read(), p = Read();
	for (int i = 1; i <= n; i ++)
		a[i].w = Read(), a[i].b = Read(), cur -= a[i].b;
	sort(a + 1, a + n + 1);
	cur *= p;
	for (int i = 1; i <= n; i ++)
		if ((cur += 1LL * a[i].w * (100 - p) + 1LL * a[i].b * p) >= 0)
			return printf("%d\n", i), 0;
}


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

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

  string tmp = S.substr(0, 1);
  int cnt = 1;
  for (int i = 1; i < S.size(); i++) {
    if (tmp == S.substr(i, 1)) {
      if (tmp != S.substr(i, 2)) {
        tmp = S.substr(i, 2);
        cnt++, i++;
      } else {
        break;
      }
    } else {
      tmp = S.substr(i, 1);
      cnt++;
    }
  }

  cout << cnt << "\n";
}

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

int main() {
  int n;
  cin >> n;
  string d(n, '\0');
  REP(i, n) cin >> d[i];
  map<string, bool> mp;
  REP(i, n) {
    FOR(j, i + 1, n + 1) {
      auto s = d.substr(i, j - i);
      mp[s] = true;
    }
  }
  REP(i, 1e7) {
    if (mp[to_string(i)]) continue;
    cout << i << endl;
    return 0;
  }
}



Measured memory_bytes: 217384
#include <iostream>
#include <stack>
#include <algorithm>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <functional>
#include <string>
#include <cstdlib>
#include <numeric>
#include <cstdbool>
#include <cstring>
#include <map> 
#include<set>
#include<queue>
#include <iomanip>

typedef long long ll;

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

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

const long long INF = 1000000000000000;
const ll inf = -1e18;
typedef pair<ll, ll> P;
ll ma = 1000000000 + 7;
ll mx = 1000003;
ll h,n, w,m,t; string s;
ll R, C;
ll sy, sx, gy, gx;
char maze[20][20];
ll dis[20][20];
int dx[4] = { 1, 0, -1, 0 };
int dy[4] = { 0, 1, 0, -1 };
ll gcd(ll x, ll y) {
	if (x % y == 0) return y;
	return gcd(y, x % y);
}
ll lcm(ll a,ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
void comb(vector<vector <ll> >& v) {
	for (ll i = 0; i < v.size(); i++) {
		v[i][0] = 1;
		v[i][i] = 1;
	}
	for (ll k = 1; k < v.size(); k++) {
		for (int j = 1; j < k; j++) {
			v[k][j] = (v[k - 1][j - 1] + v[k - 1][j])%ma;
		}
	}
}

ll GetDigit(ll num) {
	return log10(num) + 1;
}
ll Combination(int n, int r)
{
	if (n - r < r) r = n - r;
	if (r == 0) return 1;
	if (r == 1) return n;

	vector<ll> numerator(r);
	vector<ll> denominator(r);

	for (int k = 0; k < r; k++)
	{
		numerator[k] = n - r + k + 1;
		denominator[k] = k + 1;
	}

	for (int p = 2; p <= r; p++)
	{
		int pivot = denominator[p - 1];
		if (pivot > 1)
		{
			int offset = (n - r) % p;
			for (int k = p - 1; k < r; k += p)
			{
				numerator[k - offset] /= pivot;
				denominator[k] /= pivot;
			}
		}
	}

	ll result = 1;
	for (int k = 0; k < r; k++)
	{
		if (numerator[k] > 1) result *= numerator[k];
		result %= ma;
	}

	return result;
}

ll bfs() {
	queue<P> que;
	for (int i = 0; i < R; i++) {
		for (int j = 0; j < C; j++) dis[i][j] = INF;
	}
	que.push(P(sy - 1, sx - 1));
	dis[sy - 1][sx - 1] = 0;

	while (que.size() > 0) {
		P p = que.front();
		que.pop();
		if (p.first == gy - 1 && p.second == gx - 1) break;
		for (ll i = 0; i < 4; i++) {
			ll ny = p.first + dy[i];
			ll nx = p.second + dx[i];
			if (0 <= ny && ny < R && 0 <= nx && nx < C && maze[ny][nx] == '.' && dis[ny][nx] == INF) {
				que.push(P(ny, nx));
				dis[ny][nx] = dis[p.first][p.second] + 1;
			}
		}
	}
	return dis[gy - 1][gx - 1];
}
ll dp[20500];
int main() {
	ll a, b;
	cin >> a >> b;
	ll q = GetDigit(b);
	rep(i, q) {
		a *= 10;
	}
	n = a + b;
	double p = sqrt(n);
	if (p == floor(p)) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}


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

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

const long long INF = 1LL << 60;

int main()
{
    while (true) {
        int N;
        cin >> N;
        long long dp[N+1];
        if (N == 0) {
            break;
        }
        rep(i, N+1) dp[i] = 0;
        dp[0] = 1;
        repd(i, 1, N + 1) {
            dp[i] += dp[i-1];
            if (i > 1) dp[i] += dp[i-2];
            if (i > 2) dp[i] += dp[i-3];
        }
        int ans = dp[N] / 3650;
        if (dp[N] % 3650) ans++;

        cout << ans << endl;
    }

    return 0;
}


Measured memory_bytes: 3008
#include<stdio.h>
int main()
{
    int n[32]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    int k;
scanf("%d", &k);
printf("%d", n[k-1]);
}






Measured memory_bytes: 128
//
// Created by moono on 2018/10/27.
//

#include <iostream>
#include <string>
#include <unordered_set>
using namespace std;

int main(){
    int N;
    unordered_set<string> words;

    //
    cin >> N;

    //
    bool is_Yes = true;
    string current_word, previous_word;
    for (int i = 0; i < N; ++i) {
        cin >> current_word;
        if(is_Yes){
            if(words.find(current_word) != words.end()){
                is_Yes = false;

            }else if(previous_word.size() > 0){
                int i = previous_word.size() - 1;
                if(previous_word[i] != current_word[0]){
                    is_Yes = false;
                }
            }

            previous_word = current_word;
            words.insert(current_word);
        }
    }

    if(is_Yes) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}



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

// 総数を1000000007（素数）で割った余り
const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>
#define Graph vector<vector<int>>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }


void func(long long A, long long B, long long H, long long M){

}

int main(){

    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    long long H;
    scanf("%lld",&H);
    long long M;
    scanf("%lld",&M);

    
    cout <<fixed<<setprecision(15)<< sqrt(abs(A*A+B*B-2*A*B*cosl(5.5*(60.0*H+M)*PI/180.0))) << endl;
    return 0;
}

Measured memory_bytes: 4228