akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    bool first = true;

    for(;;){
        int n;
        if(!(cin >> n))
            return 0;

        vector<string> s(8, string(5, '*'));
        s[2] = string(5, '=');
        for(int i=4; i>=0; --i){
            int a = n % 10;
            n /= 10;

            if(a >= 5)
                s[0][i] = ' ';
            else
                s[1][i] = ' ';
            s[a%5+3][i] = ' ';
        }

        if(first)
            first = false;
        else
            cout << endl;
        for(int i=0; i<8; ++i)
            cout << s[i] << endl;
    }
}

Measured memory_bytes: 0
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<string>
#include<vector>
#include<map>
using namespace std;
typedef pair<int, int> P;
int main(void){
	int W, Q;
	while (cin >> W){
		
		vector<int> hei(1000, -1);
		cin >> Q;
		if (W == 0 && Q == 0)return 0;
		for (int i = 0; i < Q; i++)
		{
			char c;
			int id;
			int w;
			cin >> c;
			if (c == 's'){
				cin >> id >> w;
				int b = -1;
				for (int j = 0; j <= W - w; j++){
					bool flag = true;
					for (int k = 0; k < w; k++)
					{
						if (hei[j + k] != -1)flag = false;
					}
					if (flag){
						for (int k = 0; k < w; k++)
						{
							hei[j + k] = id;
						}
						b = j;
						break;
					}
				}
				if (b == -1)cout << "impossible" << endl;
				else cout << b << endl;

			}
			else{
				cin >> id;
				for (int j = 0; j < W; j++)
				{
					if (hei[j] == id)hei[j] = -1;
				}


			}






		}

		cout << "END" << endl;

	}

	return 0;
}

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

using namespace std;

#define int long long
#define pb push_back
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define REP(i, n) FOR(i, 0, n)

signed main () {
  int h, w;
  cin >> h >> w;
  vector<vector<bool> > a(h);
  char tmp;
  REP(i, h) {
    REP(j, w) {
      cin >> tmp;
      if(tmp == '.') a[i].pb(true);
      else a[i].pb(false);
    }
  }

  bool success = true;

  REP(i, h) {
    REP(j, w) {
      if(!a[i][j]) {
        if(i == 0 && j == 0 && a[i+1][j] && a[i][j+1]) {
          success = false;
          break;
        } else if(i == 0 && j == w-1 && a[i+1][j] && a[i][j-1]) {
          success = false;
          break;
        } else if(i == 0 && 0 < j && j < w-1 && a[i+1][j] && a[i][j-1] && a[i][j+1]) {
          success = false;
          break;        
        } else if(i == h-1 && j == 0 && a[i-1][j] && a[i][j+1]) {
          success = false;
          break;
        } else if(i == h-1 && j == w-1 && a[i-1][j] && a[i][j-1]) {
          success = false;
          break;
        } else if(i == h-1 && 0 < j && j < w-1 && a[i-1][j] && a[i][j-1] && a[i][j+1]) {
          success = false;
          break;
        } else if(i != 0 && i != h-1 && j != 0 && j != w-1 && a[i-1][j] && a[i+1][j] && a[i][j-1] && a[i][j+1]) {
          success = false;
          break;
        }
      }
    }
  }
  if(success) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//make_tuple emplace_back next_permutation push_back make_pair second first setprecision

#if MYDEBUG
#include "lib/cp_debug.h"
#else
#define DBG(...) ;
#endif

using LL = long long;
constexpr LL LINF=334ll<<53;
constexpr int INF=15<<26;
constexpr LL  MOD=1E9+7;

struct UnionFind{
    vector<int> par; //par: -1*elements(root) number of par(not root)
    UnionFind(int n){par = vector<int>(n,-1);}
    int root(int x){return par[x]<0?x:(par[x]=root(par[x]));}
    void unite(int x,int y){
        x=root(x);
        y=root(y);
        if(x!=y){
            if(par[x]<par[y]) swap(x,y);
            par[y] += par[x];
            par[x] = y;
        }
    }
    bool is_par(int x){return root(x)==x;}
    bool same(int x,int y){return root(x) == root(y);}
    int size(int x){return -par[root(x)];}
};

struct Problem{
    int n;
    vector<pair<int,int>> x,y;
    vector<tuple<int,int,int>> e;
    UnionFind uf;
    Problem(LL n):n(n),uf(n){};

    void solve(){
        for(int i=0; i<n; ++i){
            int a,b;
            cin >> a >>b;
            x.emplace_back(a,i);
            y.emplace_back(b,i);
        }
        sort(x.begin(),x.end());
        sort(y.begin(),y.end());
        for(int i=0; i<n-1; ++i){
            if(x[i].first==x[i+1].first){
                uf.unite(x[i].second,x[i+1].second);
            }else{
                e.emplace_back(x[i+1].first-x[i].first,x[i].second,x[i+1].second);
            }
            if(y[i].first==y[i+1].first){
                uf.unite(y[i].second,y[i+1].second);
            }else{
                e.emplace_back(y[i+1].first-y[i].first,y[i].second,y[i+1].second);
            }
        }
        sort(e.begin(),e.end());
        LL ans=0;
        for(int i=0;uf.size(0)<n;++i){
            int a,b,c;
            tie(a,b,c)=e[i];
            if(!uf.same(b,c)){
                uf.unite(b,c);
                ans+=a;
            }
        }
        cout << ans<<"\n";
    }
};

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    long long n=0;
    cin >> n;
    Problem p(n);
    p.solve();
    return 0;
}



Measured memory_bytes: 7528
#include <stdio.h>
#include <algorithm>
#include <functional>
#define mod 1000000007
using namespace std;
typedef long long ll;

ll mpow(ll a, ll b) {
  ll ans = 1;
  while(b) {
    if(b & 1) ans *= a, ans %= mod;
    a *= a, a %= mod, b >>= 1;
  }
  return ans;
}

int main(void) {
  ll i, j, k, n, ans = 0;
  scanf("%lld", &n);
  ll c[n];
  for(i = 0; i < n; ++i) scanf("%lld", &c[i]);
  sort(c, c + n, greater<ll>());
  for(i = 0; i < n; ++i) {
    k = i * (i ? mpow(2, i - 1) : 0) + mpow(2, i), k %= mod;
    k *= c[i], k %= mod;
    k *= mpow(2, 2 * n - i - 1), k %= mod;
    ans += k, ans %= mod;
  }
  printf("%lld", ans);
  return 0;
}

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

long long computeXOR(long long n) 
{ 
    switch(n & 3)  
    { 
    case 0: return n; 
    case 1: return 1;  
    case 2: return n + 1;     
    case 3: return 0;
    } 
} 

int main()
{
	long long A,B;
	cin>>A>>B;
	if(A)
		cout<<(computeXOR(B)^computeXOR(A-1))<<endl;
	else
		cout<<(computeXOR(B))<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

//-------------------------------------------------------------
void hairetu_zero(int card[][13]);   //??????????????????
void card_check(int card[][13], char egara, int rank);   //?????????????????´????????????????¢????????????¢??°
void output(int card[][13]);           //?¶???±????????????????????????????????¢??°

//--------------------------------------------------------------
int main(void)
{
	int n;      //??????????????£???????????????????????°
	int taro_card[4][13]; //taro_card/??????/?????????
	char taro_egara;    //????????????????????????
	int taro_rank;      //???????????????????????????
	char dummy;        //???????????§???????????????
	
	hairetu_zero(taro_card);  //??????????????????
	
	scanf("%d",&n);
	
	for(int i = 0; i < n; i++){
		scanf("%c", &dummy);
		scanf("%c %d", &taro_egara, &taro_rank);
		card_check(taro_card, taro_egara, taro_rank);   //?????£???????????????????????????
	}

	output(taro_card);    //?¶???±????????????????????????
	
	return 0;
}

//--------------------------------------------------------//??????????????????
void hairetu_zero(int card[][13])
{
	for(int i = 0; i < 4; i++){
		for(int j = 0; j < 13; j++){
			card[i][j] = 0;
		}
	}
}
//--------------------------------------------------------//?????????????????´????????????????¢????????????¢??°(?¶???±????????????0)
void card_check(int card[][13], char egara, int rank)
{
	if(egara == 'S'){
		card[0][rank-1] = 1;     //????????????????????°1?????????????????????
	}
	if(egara == 'H'){
		card[1][rank-1] = 1;     //????????????????????°1?????????????????????
	}
	if(egara == 'C'){
		card[2][rank-1] = 1;     //????????????????????°1?????????????????????
	}
	if(egara == 'D'){
		card[3][rank-1] = 1;     //????????????????????°1?????????????????????
	}
}

//----------------------------------------------------------//?¶???±????????????????????????????????¢??°
void output(int card[][13])
{
	for(int i = 0; i < 4; i++){
		for(int j = 0; j < 13; j++){
			if(card[i][j] == 0){
				if(i == 0){
					printf("S %d\n", j+1);
				}
				else if(i == 1){
					printf("H %d\n", j+1);
				}
				else if(i == 2){
					printf("C %d\n", j+1);
				}
				else if(i == 3){
					printf("D %d\n", j+1);
				}
			}
		}
	}
}

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

#define int long long


signed main(){

  int H, W, S, T;
  int ans = 0;
  
  cin>>H>>W>>S>>T;

  if((S-1)%2 && (H-S)%2 && (T-1)%2 == 0&& (W-T)%2 == 0) cout<<"No"<<endl;
  else if((S-1)%2 == 0&& (H-S)%2 == 0&& (T-1)%2 && (W-T)%2) cout<<"No"<<endl;
  else cout<<"Yes"<<endl;
  return 0;
}



Measured memory_bytes: 3104
eval'N,X,M='+`tr ' ' ,`
v={}
s=t=0
(v[X]=t
t+=1
$*[X]=s
s+=X
v[X=X*X%M]&&(b=t-v[X]
s+=N/b*(s-$*[X])
N%=b))until 0>N-=1
p s

Measured memory_bytes: 36100
import java.io.IOException;
class Main {
	static final int[] C = {
		0,1,2,0,2,4,0,3,1,0,4,3,1,0,3,1,2,0,1,3,5,1,5,2,
		2,0,1,2,1,5,2,4,0,2,5,4,3,0,4,3,1,0,3,4,5,3,5,1,
		4,0,2,4,2,5,4,3,0,4,5,3,5,1,3,5,2,1,5,3,4,5,4,2
	};
	byte[] b = new byte[4096];
	int p;
	int r() {
		for (; b[p] < 0x30 || b[p] > 0x39; p++);
		int v = 0;
		for (; b[p] >= 0x30; ) v = 10 * v + b[p++] - 0x30;
		return v;
	}
	public static void main(String[] args) throws IOException {
		Main r = new Main();
		System.in.read(r.b, 0, r.b.length);
		int[] d = new int[6 + r.r() * 6];
		for (int i = 6; i < d.length; i++) {
			d[i] = r.r();
		}
		for (int p = 6; p < d.length; p += 6) {
			for (int c = 0; c < C.length; c += 3) {
				d[0]=d[p+C[c+0]];d[3]=d[p+5-C[c+2]];
				d[1]=d[p+C[c+1]];d[4]=d[p+5-C[c+1]];
				d[2]=d[p+C[c+2]];d[5]=d[p+5-C[c+0]];
				for (int q = p + 6; q < d.length; q += 6) {
					if (d[0]==d[q+0]&&d[1]==d[q+1]&&d[2]==d[q+2]&&
						d[3]==d[q+3]&&d[4]==d[q+4]&&d[5]==d[q+5]) {
						System.out.println("No");
						return;
					}
				}
			}
		}
		System.out.println("Yes");
	}
}



Measured memory_bytes: 24288
a, b = map(int, input().split())
c = [int(input()) for _ in range(a)]
c.sort()
d = -1
for i in range(b-1, a):
    if d == -1:
        d = abs(c[i] - c[i-b+1])
    else:
        if abs(c[i] - c[i-b+1]) < d:
            d = abs(c[i] - c[i-b+1])
print(d)


Measured memory_bytes: 7384
#include<bits/stdc++.h>
using namespace std;
long long a,b,c;
int main()
{
	cin>>a>>b>>c;
	if(b-a==c-b)
	{
		cout<<"YES"<<endl;
	}
	else
	cout<<"NO"<<endl;
	
	
	 return 0;
}

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

template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
signed main(){
  Int n;
  cin>>n;
  Int s=1<<n;
  vector<Int> a(s);
  for(Int i=0;i<s;i++) cin>>a[i];

  Int ans=0;
  for(Int b=1;b<s;b++){
    Int p=-1,q=-1;
    for(Int x=b;;x=(x-1)&b){
      if(a[x]>=p){
	chmax(q,p);
	p=a[x];
      }else chmax(q,a[x]);
      if(x==0) break;
    }
    //cout<<p<<" "<<q<<endl;
    chmax(ans,p+q);
    cout<<ans<<endl;
  }
  
  return 0;
}


Measured memory_bytes: 5120
N=input()
H=[int(i) for i in input().split()]

#len(H)==1は別でOK
for i in range(len(H)-1):
    if H[i] > H[i+1]+1:
        print("No")
        break
    elif H[i] == H[i+1]+1:
        H[i]-=1
    elif i==0:
        H[i]-=1
    elif H[i-1] < H[i]:
        H[i]-=1
else:
    for i in range(len(H)-1):
        if H[i] > H[i+1]:
            print("No")
            break
    else:
        print("Yes")


Measured memory_bytes: 14396
#include<stdio.h>
int main()
{
	int n;
	scanf("%d", &n);
	int i;
	int a[100005];
	for (i = 0; i < n; i++)
		scanf("%d", &a[i]);
	int min, max;
	min = max = a[0];
	for (i = 0; i < n; i++)
		if (min > a[i])
			min = a[i];
	for (i = 0; i < n; i++)
		if (max < a[i])
			max = a[i];
	int c1, c2;
	if (max - min > 1)
	{
		printf("No\n");
		return 0;
	}
	if (min == max)
	{
		if (max == n - 1)
			printf("Yes\n");
		else if (max * 2 <= n)
			printf("Yes\n");
		else
			printf("No\n");
	}
	else
	{
		c1 = 0;
		for (i = 0; i < n; i++)
			if (a[i] == min)
				c1++;
		c2 = n - c1;
		if (c2 > 1 && (max - c1) > 0 && (max - c1) * 2 <= c2)
			printf("Yes\n");
		else
			printf("No\n");
	}
	return 0;
}

Measured memory_bytes: 512
N = int(input())
h = list(map(int, input().split()))

dp = [0] * N

dp[1] = abs(h[0] - h[1])
for i in range(2, N):
    dp[i] = min(dp[i - 1] + abs(h[i - 1] - h[i]), dp[i - 2] + abs(h[i - 2] - h[i]))

print(dp[N - 1])


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

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    int n, x, y;
    cin >> n >> x >> y;
    x--; y--;
    vector<int> ans(n);
    for(int i = 0; i < n; i++){
        for(int j = i + 1; j < n; j++){
            int len;
            if(j <= x){
                len = j - i;
            }else if(i <= x && j <= y){
                len = x - i + min(j - x, 1 + y - j);
            }else if(i <= x && y < j){
                len = x - i + 1 + j - y;
            }else if(x < i && i < y && j <= y){
                len = min(j - i, i - x + 1 + y - j);
            }else if(x < i && i < y && y < j){
                len = min(y - i, i - x + 1) + j - y;
            }else if(y <= i){
                len = j - i;
            }else{
                return 1;
            }
            printde(i, j, len);
            ans[len]++;
        }
    }
    for(int i = 1; i < n; i++){
        cout << ans[i] << '\n';
    }
}


Measured memory_bytes: 888
#include <iostream>

using namespace std;

int main()
{
	int a[55556];
	fill(a, a + 55556, 1);
	a[0] = a[1] = 0;
	for (int i = 4; i < 55556; i += 2) {
		a[i] = 0;
	}
	for (int i = 3; i * i < 55556; i += 2) {
		if (a[i] == 1) {
			for (int j = i + i; j < 55556; j += i) {
				a[j] = 0;
			}
		}
	}

	int n;
	cin >> n;
	for (int i = 11, j = 0; j < n; i += 5) {
		if (a[i] == 1) {
			cout << i << (j == n - 1 ? "\n" : " ");
			j++;
		}
	}

	return 0;
}

Measured memory_bytes: 3812
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define debug(x)      cerr << "L" << __LINE__ << ": " << #x << " = " << (x) << endl
#define debugvec(v)   rep(i, v.size()) cerr << "L" << __LINE__ << ": " << #v << "[" << i << "] = " << v[i] << endl;
#define debugvec2(v)  cerr << "L" << __LINE__ << ": " << #v << " = { "; rep(i, v.size()) cerr << v[i] << (i + 1 == v.size() ? "" : ", "); cerr << " }" << endl;
typedef long long ll;  /* 10^18 くらいまでいける */

int main(){
  int h, a;
  cin >> h >> a;
  
  int ans = h / a;
  if (h%a!=0)
    ans += 1;

  cout << ans << endl;

  return 0;
}

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

using namespace std;

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

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

ll A[100005];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    REP(i, N) {
        cin >> A[i];
    }

    ll s = 1;
    ll p = 0;
    REP(i, N - 1) {
        ll a = A[i + 1] - A[i];
        if (a * p < 0) {
            s++;
            p = 0;
        }
        else if (a != 0) {
            p = a;
        }
    }
    cout << s << endl;
    return 0;
}

Measured memory_bytes: 1024
a = None
p = None


def f(N, X):
    if N == 0:
        return 0 if X <= 0 else 1
    elif X <= 1 + a[N-1]:
        return f(N-1, X-1)
    else:
        return p[N-1] + 1 + f(N-1, X-2-a[N-1])


def main():
    N, X = list(map(int, input().split()))
    global a
    global p
    a = [1]
    p = [1]

    for i in range(N):
        a.append(a[i] * 2 + 3)
        p.append(p[i] * 2 + 1)

    print(f(N, X))


if __name__ == '__main__':
    main()


Measured memory_bytes: 38384
#include<bits/stdc++.h>
using namespace std;
typedef long long int  ll;
const ll mod = 1e9+7;
#define rep(i,a,b) for(ll i=a;i<b;i++)

void swap(ll &a , ll &b){
    ll t = a;
    a = b;
    b = t;
}

ll min(ll a, ll b){
    if(a<b)return a;
    return b;
}

ll max(ll a, ll b){
    if(a>b)return a;
    return b;
}

 ll pow(ll a, ll b) {
    a %= mod;
    ll ans = 1;
    while (b > 0) {
        if (b & 1)
            ans = ans * a % mod;
        a = a * a % mod;
        b /= 2;
    }
    return ans;
}


int main(){

 
   ios_base :: sync_with_stdio(0);
   cin.tie(0);
   /// 1 2 3 4  ....
    ll n;
    cin>>n;
    ll a[n][3];
    for(int i = 0; i < n;i++){
        cin>>a[i][0]>>a[i][1]>>a[i][2];
    }
    ll dp[n][3];
    dp[0][0] = a[0][0];
    dp[0][1] = a[0][1];
    dp[0][2] = a[0][2];


    for(int i = 1;i<n;i++){
        dp[i][0] = max(dp[i-1][1]+a[i][0] , dp[i-1][2]+a[i][0]);
        dp[i][1] = max(dp[i-1][0]+a[i][1] , dp[i-1][2]+a[i][1]);
        dp[i][2] = max(dp[i-1][0]+a[i][2] , dp[i-1][1]+a[i][2]);
    }
    cout<<max(dp[n-1][0] , max(dp[n-1][1] , dp[n-1][2]) );







}


Measured memory_bytes: 4992
#include <bits/stdc++.h>
    #include <ext/pb_ds/assoc_container.hpp>
    #include <ext/pb_ds/tree_policy.hpp>
    #ifdef ONLINE_JUDGE
    #define LLD "%I64d"
    #else
    #define LLD "%lld"
    #endif
    #define fu(a,b,c) for(int a=b;a<=(int)c;++a)
    #define fd(a,b,c) for(int a=b;a>=(int)c;--a)
    #define cu(a,b,c) for(int a=b;a<(int)c;++a)
    #define cd(a,b,c) for(int a=(b)-1;a>=(int)c;--a)
    #define gcd(a,b) __gcd(a,b) 
    #define pii pair<int,int>
    #define pll pair<long long,long long>
    #define all(a) a.begin(),a.end()
    #define F first
    #define S second
    #define pb push_back
    #define pf push_front
    #define MOD 1000000007 
    #define MAXN 52
    #define MAXH 20
    #define MAXM 52
    #define INF 100000000
    #define ll long long
    #define ull unsigned long long
    #define RNG rng mt19937(time(NULL))
    #define udist(a,b) uniform_int_distribution<uint32_t> distribution(a,b)
    #define max3(a,b,c) max(a, max(b, c))
    #define min3(a,b,c) min(a, min(b, c))
    #define gmax(a,b) a = max(a, b)
    #define gmin(a,b) a = min(a, b)
    #define whatis(x) cerr << #x << " is " << x << endl;
    #define fast_io() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    #define PI 3.1415926535897932384626433
    using namespace std;
    using namespace __gnu_pbds;
    typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
     
    	int n,m,cnt[35];
    int main(){
    	cin >> n >> m;
    	ll ans = 0;
    	cu(i,0,n){
    		int k;
    		cin >> k;
    		cu(j,0,k){
    			int x;
    			cin >> x;	
    			++cnt[x];
    			if(cnt[x] == n)++ans;
    		}
    	}
    	cout << ans << endl;
    }

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define int long long
#define mp make_pair
#define inf 1000000007
#define ll long long
using namespace std;
int par[1145];
int a[1145];
bool dp[1000][5001];
pair<int,int> dame = mp(-1,-1);
vector<int> ch[1145];
pair<int,int> dfs(int id){
	int mi = 0, sum = 0;
	vector< pair<int,int> > ps;
	for(int i=0;i<ch[id].size();i++){
		int ko = ch[id][i];
		pair<int,int> P = dfs(ko);
		if( P == dame )return dame;
		mi += P.first;
		sum += P.first + P.second;
		ps.pb(P);
	}
	if( mi > a[id]){
		return dame;
	}
	else{
		for(int i=0;i<=ps.size();i++){
			for(int j=0;j<=a[id];j++){
				dp[i][j]=false;
			}
		}
		dp[0][0]=true;
		for(int i=1;i<=ps.size();i++){
			for(int j=0;j<=a[id];j++){
				int xx = ps[i-1].first;
				int yy = ps[i-1].second;
				if( j+xx <= a[id]) dp[i][j+xx] |= dp[i-1][j];
				if( j+yy <= a[id]) dp[i][j+yy] |= dp[i-1][j];
			}
		}
		int best = a[id];
		while( dp[ ps.size()][ best] == false){
			best--;
		}
		//cout<<id<<" "<<min(sum-best,a[id])<<" "<<max(sum-best,a[id])<<endl;
		return( mp( min(sum-best,a[id]), max(sum-best,a[id])) );
	}
}
signed main(){
	int n;
	cin>>n;
	for(int i=2;i<=n;i++){
		int x;
		cin>>x;
		par[i] = x;
		ch[x].pb(i);
	}
	for(int i=1;i<=n;i++){
		int x;
		cin>>x;
		a[i]=x;
	}
	pair<int,int> P = dfs(1);
	if( P == dame){
		cout<<"IMPOSSIBLE"<<endl;
	}
	else{
		cout<<"POSSIBLE"<<endl;
	}
	return 0;
}

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

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

    long long takahashi, aoki;
    cin >> takahashi >> aoki;

    for (auto i = 1; i < N; i++)
    {
        int t, a; cin >> t >> a;
        auto k = max((takahashi+t-1)/t, (aoki+a-1)/a);
        takahashi = t*k, aoki = a*k;
    }

    cout << takahashi + aoki << endl;
}



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

using namespace std;

main() {
#ifdef HOME
    freopen("input.txt", "r", stdin);
#endif // HOME
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    char a;
    cin >> a;
    if ('A' <= a && a <= 'Z') cout << 'A';
    else cout << 'a';
    return 0;
}


Measured memory_bytes: 3548
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <stack>
#include <queue>
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main()
{
    int n;
    scanf("%d", &n);
    vector<int> a(n);
    for (int i = 0; i < n; ++i) scanf("%d", &a[i]);
    map<int, int> dic;
    int num = 0;
    for (int i = 0; i < n; ++i)
    {
        if (a[i] >= 1 && a[i] < 400)
        {
            ++dic[0];
        }
        else if (a[i] >= 400 && a[i] < 800)
        {
            ++dic[1];
        }
                else if (a[i] >= 800 && a[i] < 1200)
        {
            ++dic[2];
        }
        else if (a[i] >= 1200 && a[i] < 1600)
        {
            ++dic[3];
        }
        else if (a[i] >= 1600 && a[i] < 2000)
        {
            ++dic[4];
        }
        else if (a[i] >= 2000 && a[i] < 2400)
        {
            ++dic[5];
        }
        else if (a[i] >= 2400 && a[i] < 2800)
        {
            ++dic[6];
        }
        else if (a[i] >= 2800 && a[i] < 3200)
        {
            ++dic[7];
        }
        else
        {
            ++num;
        }
    }
    int minval = dic.size() > 0 ? dic.size() : 1;
    int maxval = dic.size() + num;
    printf("%d %d\n", minval, maxval);
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(){
  int N,K,X,Y,i=0;
  int total = 0;
  scanf("%d",&N);
  scanf("%d",&K);
  scanf("%d",&X);
  scanf("%d",&Y);

  for(i=1;i<=N;i++){
    if(i>=K+1){
      total += Y;
    }else{
      total += X;
    }
  }
  printf("%d\n",total);
}

Measured memory_bytes: 128
#include <iostream>

using namespace std;


int main (){
  int N;
  int A[200000];
  cin >> N;
  for (int i=0; i<N; i++) A[i] = 0;
  for (int i=1; i<N; i++) {
    int a;
    cin >> a;
    if (a) A[a-1]++;
  }
  for (int i=0; i<N; i++) {
    cout << A[i] << endl;
  }
  return 0;
}

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

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
ll gcd(ll a, ll b){return (b==0)?a:gcd(b,a%b);}

int factorial(int n){
	if(n == 0) return 1;
	else return n*factorial(n-1);
}


int main(){

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

	int n; cin >> n;
	vector<pair<int,int> > points(n);
	for(int i = 0; i < n; ++i) cin >> points[i].first >> points[i].second;
	vector<int> arr(n);
	for(int i = 0; i < n; ++i) arr[i] = i;
	long double ans = 0;
	do {
		long double tmp = 0;
		for(int i = 0; i < n-1; ++i){
			//cout << points[arr[i]].first << " " << points[arr[i+1]].first << " " << points[arr[i]].second << " " << points[arr[i+1]].second << "\n";
			tmp += sqrt((points[arr[i]].first - points[arr[i+1]].first)*(points[arr[i]].first - points[arr[i+1]].first)
			 			+ (points[arr[i]].second - points[arr[i+1]].second)*(points[arr[i]].second - points[arr[i+1]].second));
			//cout << tmp << endl;
		}
		ans += tmp;
		
  	}while ( next_permutation(arr.begin(),arr.begin()+n) );

	cout << setprecision(10) << ans/factorial(n) << "\n";
    return 0;
}

Measured memory_bytes: 256
// c++ cpp.cpp -o cpp.exe -std=c++14
// ./cpp.exe

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

void print(int A[], int N) {
	for (int i = 0; i < N; i++) {
		if (i > 0) cout << " ";
		cout << A[i];
	}
	cout << endl;
}

int insertionSort(int A[], int n, int g) {
	int cnt = 0;
	for (int i = g; i < n; i++) {
		int v = A[i];
		int j = i - g;
		while (j >= 0 && A[j] > v) {
			A[j + g] = A[j];
			j -= g;
			cnt += 1;
		}
		A[j + g] = v;
	}
	return cnt;
}

int shellSort(int A[], int n) {
	int R[10100];
	R[0] = 1;

	int i = 0;
	while (R[i] <= n) {
		R[i + 1] = 3 * R[i] + 1;
		i++;
	}
	int m = i;

	int *G;
	G = new int[m];
	int j = 0;
	for (int i = m - 1; i >= 0; i--) {
		G[j] = R[i];
		j++;
	}

	cout << m << endl;
	print(G, m);

	int cnt = 0;
	for (i = 0; i < m; i++) {
		cnt += insertionSort(A, n, G[i]);
	}
	return cnt;
}

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

	int *A;
	A = new int[n];
	for (int i = 0; i < n; i++) {
		cin >> A[i];
	}

	int cnt = shellSort(A, n);
	cout << cnt << endl;

	for (int i = 0; i < n; i++) {
		cout << A[i] << endl;
	}
	return 0;
}



Measured memory_bytes: 6996
#include <iostream>
#include <cstdio>

using namespace std;

int main(void)
{
	int N;
	string S;

	cin >> N >> S;

	for(int i = 0, i_end = S.length(); i < i_end; ++i){
		int t = (S[i] - 65 + N) % 26 + 65;
		printf("%c", (char)t);
	}
	cout << endl;

	return 0;
}


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

int main()
{

    while(true){
        int m, f, r;
        cin >> m >> f >> r;
        if( m==-1 and f==-1 and r==-1){
            break;
        }

        if( m==-1 or f==-1){
            cout << "F\n";
        }else if( m+f >= 80 ){
            cout << "A\n";
        }else if( 65<= m+f and m+f < 80 ){
            cout << "B\n";
        }else if( 50<= m+f and m+f < 65 ){
            cout << "C\n";
        }else if( 30<= m+f and m+f < 50){
            if( 50 <= r ){
                cout << "C\n";
            } else {
                cout << "D\n";
            }
        }else if ( m+f < 30 ){
            cout << "F\n";
        }
    }
    return 0;
}



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

typedef long long ll;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); ++itr)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second

typedef vector<int> vi;
typedef pair<int,int> pi;
typedef pair<int,pi> edge;

struct UF{
    int n;
    //??£?????£????????????????????????,????????£???????????§??£?????????????????°
    vector<int> d;
    UF() {}
    UF(int N):n(N), d(N,-1){}
    int root(int v){
        if(d[v]<0) return v;
        return d[v]=root(d[v]);
    }
    bool unite(int X,int Y){
        X=root(X); Y=root(Y);
        if(X==Y) return false;
        if(size(X) < size(Y)) swap(X,Y);
        d[X]+=d[Y];
        d[Y]=X;
        return true;
    }
    int size(int v){ return -d[root(v)]; }
    bool same(int X,int Y){ return root(X)==root(Y); }
};

const int INF=123456789;
const int N=250000;
int dp[2][N+1];

int main()
{
    int R;
    while(scanf(" %d", &R),R)
    {
        fill(dp[0],dp[2],INF);

        rep(room,2)
        {
            int W,H,X,Y;
            scanf(" %d %d %d %d", &W, &H, &X, &Y);
            --X;
            --Y;

            vector<vi> f(H,vi(W));
            rep(i,H)rep(j,W) scanf(" %d", &f[i][j]);

            #define NUM(x,y) (y*W+x)
            #define IN(x,y) (0<=x && x<W && 0<=y && y<H)
            int dx[4]={1,-1,0,0}, dy[4]={0,0,1,-1};
            vector<edge> e;
            rep(i,H)rep(j,W)
            {
                int u = NUM(j,i);
                rep(k,4)
                {
                    int nx=j+dx[k], ny=i+dy[k];
                    if(IN(nx,ny))
                    {
                        int v = NUM(nx,ny);
                        int cost = max(f[i][j], f[ny][nx]);
                        e.pb(edge(cost,pi(u,v)));
                    }
                }
            }
            sort(all(e));

            dp[room][0] = 0;
            dp[room][1] = 1;
            UF uf(H*W);
            rep(i,e.size())
            {
                int cost = e[i].fi;
                int u = e[i].se.fi, v = e[i].se.se;
                uf.unite(u,v);

                int SZ = uf.size(NUM(X,Y));
                dp[room][SZ] = min(dp[room][SZ],cost);
            }

            for(int i=N; i>0; --i) dp[room][i-1] = min(dp[room][i-1], dp[room][i]);
        }

        int ans = 2*INF;
        rep(i,R+1) ans = min(ans, dp[0][i]+dp[1][R-i]);
        printf("%d\n", ans);
    }
    return 0;
}

Measured memory_bytes: 29784
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>
#include <functional>

using namespace std;
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define RREP(i, a) for(int (i) = (a) - 1; (i) >= 0; (i)--)
#define FORR(i, a, b) for(int (i) = (a) - 1; (i) >= (b); (i)--)
#define DEBUG(C) cerr << #C << " = " << C << endl;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<LL>;
using VVL = vector<VL>;
using VD = vector<double>;
using VVD = vector<VD>;
using PII = pair<int, int>;
using PDD = pair<double, double>;
using PLL = pair<LL, LL>;
using VPII = vector<PII>;
template<typename T> using VT = vector<T>;
#define ALL(a) begin((a)), end((a))
#define RALL(a) rbegin((a)), rend((a))
#define SORT(a) sort(ALL((a)))
#define RSORT(a) sort(RALL((a)))
#define REVERSE(a) reverse(ALL((a)))
#define MP make_pair
#define FORE(a, b) for (auto &&a : (b))
#define EB emplace_back
#define GREATER(T) T, VT<T> greater<T>
template<typename T> inline bool chmax(T &a, T b){if (a < b){a = b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if (a > b){a = b;return true;}return false;}

const int INF = 1e9;
const int MOD = INF + 7;
const LL LLINF = 1e18;

// エラトステネスの篩,素数列挙
// O(N log log N)
std::vector<int> sieve_of_eratosthenes(const int n) {
    std::vector<bool> is(n + 1, true);
    std::vector<int> res;
    is[0] = false;
    is[1] = false;
    for (int i = 2; i <= n; i++) {
        if (is[i]) {
            res.emplace_back(i);
            for (int j = i * 2; j <= n; j += i) {
                is[j] = false;
            }
        }
    }
    return res;
}

const int MAX = 1e7 + 10;
int memo[MAX];
VI p;
unordered_set<int> ps;

LL calc(int cur) {
    const auto a = cur;
    if (ps.count(cur)) return memo[cur] = 2;
    VI tmp;
    FORE(e, p) {
        int cnt = 0;
        while (cur % e == 0) {
            cnt++;
            cur /= e;
        }
        if (cnt == 0) continue;
        return memo[a] =  memo[cur] * (cnt + 1);
    }
    return -1;
}

int main(void) {
    LL N;
    cin >> N;
    p = sieve_of_eratosthenes(N);
    ps = unordered_set<int>(ALL(p));
    memo[1] = 1;

    LL ans = 1;
    FOR(i, 2, N + 1) {
        const auto cur = calc(i);
        ans += cur * i;
    }

    cout << ans << endl;
}


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

int main()
{
	int n, d, x;
	cin >> n >> d >> x;
	vector<int> as(n);
	for (auto &&a : as)
	{
		cin >> a;
	}

	int ans = x;
	for (auto &&a : as)
	{
		ans += (d + a - 1) / a;
	}

	cout << ans << endl;

	return 0;
}

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

int	main(void)
{
  int N, K;
  int total_dist = 0;
  
  //ボールの個数とロボットBの位置x座標を読み込む
  cin >> N >> K;
  
  while (N > 0)
  { 
    int distA, distB, ball_pos = 0;
    
    //ボールのx座標を読み込む
    cin >> ball_pos;
    
    //ロボットAとボールとの距離をx座標を元に計算
    distA = ball_pos - 0;
    //ロボットBとボールとの距離をx座標を元に計算
    distB = K - ball_pos;
    
    if (distA >= distB)
      total_dist += distB * 2;
    else
      total_dist += distA * 2;
    N--;
  }
  cout << total_dist << endl;
}

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

using namespace std;

typedef long long ll;

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

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

const ll MOD = 1000000007;

vector<ll> C;
vector<ll> two;

ll solve(const ll N) {
    ll acc = 0;
    for (int i = 1; i <= N; i++) {
        ll l = i - 1;
        ll r = N - i;
        ll k = i;

        ll x = two[r];
        if (r != 0) x = (x + two[r - 1] * r) % MOD; // ???
        x = x * two[l] % MOD;
        x = x * C[k] % MOD;
        acc = (acc + x) % MOD;
        // printf("x: %lld, acc: %lld\n", x, acc);
    }
    return acc * two[N] % MOD;
}

int main(void) {
    ll N;
    cin >> N;

    C.resize(N + 1);
    for (int i = 1; i <= N; i++) {
        cin >> C[i];
    }
    sort(C.begin() + 1, C.end());

    two.resize(N + 1);
    two[0] = 1LL;
    for (int i = 1; i <= N; i++) {
        two[i] = two[i - 1] * 2 % MOD;
    }

    cout << solve(N) << endl;

    return 0;
}


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

int main(){

    string a, b;
    cin >> a >> b;

    int size_a, size_b;
    size_a = a.size();
    size_b = b.size();

    if (size_a > size_b){
        cout << "GREATER" << endl;
    }
    else if (size_a < size_b){
        cout << "LESS" << endl;
    }
    else{
        for (int i=0; i<size_a; i++){
            if (a.at(i) > b.at(i)){
                cout << "GREATER" << endl;
                return 0;
            }
            if (a.at(i) < b.at(i)){
                cout << "LESS" << endl;
                return 0;
            }
        }
        cout << "EQUAL" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#-*-coding:utf-8-*-

def main():
    w, h, n = map(int, input().split())
    arry = [list(map(int, input().split())) for _ in range(n)]

    x1 = 0
    x2 = w
    y1 = 0
    y2 = h
    for i in arry:
        if i[2] == 1:
            x1 = max(x1, i[0])
        elif i[2] == 2:
            x2 = min(x2, i[0])
        elif i[2] == 3:
            y1 = max(y1, i[1])
        elif i[2] == 4:
            y2 = min(y2, i[1])
    if x2 <= x1 or y2 <= y1:
        ans = 0
    else:
        ans = (x2 - x1) * (y2 - y1)
    
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
#pragma region Header
#define _CRT_SECURE_NO_WARNINGS
#define FOR(i,s, e) for(int i = s; i<e; ++i)
#define rFOR(i,s, e) for(int i=s-1; i>=e; --i)
#define loop(len) for(int i=0; i<len; ++i)
#define rloop(len) for(int i=len-1; i>=0; --i)
#define iPair pair<int,int>
#define LPair pair<ll,ll>
#define vecP(t,t2) vector<pair<t,t2>>
#define uoMP(t, t2) unordered_map<t, t2>
#define pb push_back
#define pp pop_back
#define beg_end(v) v.begin(), v.end()
#define Sort(v) sort(v.begin(), v.end())
#define rSort(v) sort(v.rbegin(), v.rend())
#define rev(v) reverse(v.begin(), v.end())
#define MrN ios::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
typedef long long  ll;
typedef long double  ld;
#include<bits/stdc++.h>
using namespace std;
#pragma endregion

string s, t;
int ans;

int main() {
	MrN;
	// freopen("input.txt", "r", stdin);
	cin >> s >> t;
	loop(s.size()){
		if(s[i] != t[i])
			ans++;
	}

	cout << ans << '\n';
	return 0;
}

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

int main() {
    int n;
    cin >> n;
    vector<int> a(n), b(n);
    rep(i, n) {
        int x, y;
        cin >> x >> y;
        a[i] = x + y;
        b[i] = x - y;
    }
    sort(all(a));
    sort(all(b));
    cout << max(a[n-1] - a[0], b[n-1] - b[0]) << endl;
    return 0;
}

Measured memory_bytes: 4740
def isMatch( a, b, num)
  amount = num.to_s.split("").map(&:to_i).inject(&:+)
  a <= amount && amount <= b
end

n, a, b = gets.chomp.split(" ").map(&:to_i)
total = 0
(1..n).each do |num|
  total += num if isMatch( a, b, num)
end
print("#{total}")


Measured memory_bytes: 1916
import java.io.*;
        import java.util.Scanner;

public class Main{
    public static void main(String []args) throws IOException
    {
        Scanner sc = new Scanner(System.in);
        int  a = sc.nextInt();
        switch(a)
        {
            case 7:
            case 5:
            case 3:
                System.out.println("YES");
                break;
            default:
                System.out.println("NO");
                break;
        }

    }
}

Measured memory_bytes: 22868
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String s = sc.next();
    int a = 0;
    int b = 0;
    for(int i = 0; i < s.length(); i++) {
      if(i % 2 == 0) {
        if(s.charAt(i) != '0') a++;
      } else {
        if(s.charAt(i) != '1') a++;
      }
    }
    for(int i = 0; i < s.length(); i++) {
      if(i % 2 == 0) {
        if(s.charAt(i) != '1') b++;
      } else {
        if(s.charAt(i) != '0') b++;
      }
    }
    int ans = Math.min(a, b);
    System.out.println(ans);
  }
}

Measured memory_bytes: 25044
#include <iostream>
#include <iomanip>
#include <cstring>
#include <algorithm> 
#include <math.h>
#include <queue>
#include <functional>
#include <map>
#include <vector>
#include <string>
#include <set> 
using namespace std;

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

const ll INF = 1e15;
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };

const int MAX = 510000;
const int MOD = 1000000007;

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

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

// 二項係数計算
ll COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main(void) {
	ll N, M, K; cin >> N >> M >> K;
	ll X = 0, Y = 0;
	for (int d = 1; d < M; d++) {
		X += d*(M - d);
		X %= MOD;
	}
	for (int d = 1; d < N; d++) {
		Y += d * (N - d);
		Y %= MOD;
	}
	COMinit();
	X *= N * N; X %= MOD; X *= COM(N*M - 2, K - 2);X %= MOD;
	Y *= M * M; Y %= MOD; Y *= COM(N*M - 2, K - 2); Y %= MOD;
	cout << (X + Y) % MOD << endl;
	
}


Measured memory_bytes: 12160
#include <utility>
#include <algorithm>
#include <iostream>
using namespace std;


int N,M;
pair<int,int> a[100000];
int main(){
  while(cin >> N >> M){
    if(N==0 && M==0){
      return 0;
    }
    else{
      for(int i=0; i<N; i++){
	int d,p;
	cin >> d >> p;
	a[i] = make_pair(p,d);
      }
      
      sort(a, a+N);
      reverse(a, a+N);
      
      int S = 0;
      for(int k=0; k<N; k++){
	S += a[k].first*a[k].second;
      }
      for(int l=0; l<N; l++){
	if(M<=0)break;
	int guarded = min(M, a[l].second);
	S -= a[l].first*guarded;
	M -= guarded;
      }
      cout << S << endl;
    }
  }
}

#if 0


#endif

Measured memory_bytes: 1944
#include<iostream>
#include<algorithm>

using namespace std;

int main(){
  int N,i,count;
  int A[111111];
  cin >> N;
  for(i=0;i<=N-1;i++)
    cin >> A[i];
  sort(A,A+N);
  count = 1;
  for(i=0;i<=N-2;i++)
  	if(A[i] != A[i+1])count++;
  if(count%2) cout << count << endl;
    else cout << count - 1 << endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <stdio.h>
#include <string>
#include <string.h>
#include <algorithm>
#include <cmath>
#include <vector>
#include <functional>
#include <cstdlib>
#include <map>
using namespace std;
#define REP(i,n); for(int i = 0;i < (int)(n);i++)

int main() {
	int n, k, a;
	double e, emax=0.0;
	vector<int> p;
	cin >> n >> k;
	REP(i,n){
		cin >> a;
		p.push_back(a);
	}
	
	vector<double> E;
	E.push_back(0.0);
	REP(i, n){
		e = (p[i]+1)/2.0;
		
		E.push_back(e + E[i]);
	}

	emax = 0.0;
	REP(i, n-k+1){
		emax = max(emax, E[i+k]-E[i]);
	}

	printf("%.10f\n", emax);

	return(0);
}


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

bool uruu[3000] = {};

void is_uruu(){
	for(int i = 0;i < 3000;i++){
		if(i % 4 == 0){
			if(i % 100 == 0){
				if(i % 400 == 0) uruu[i] = true;
				else uruu[i] = false;
			}
			else uruu[i] = true;
		}
	}
}

int main(){
	int a,b;
	is_uruu();
	bool start = false;
	while(cin >> a >> b,a){
		if(!start) start = true;
		else cout << endl;
		bool flag = false;
		for(int i = a;i <= b;i++){
			if(uruu[i]){
				flag = true;
				cout << i << endl;
			}
		}
		if(!flag) cout << "NA" << endl;
	}
	return 0;
}

Measured memory_bytes: 3060
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<cctype>
#include<complex>
#include<iostream>
#include<sstream>
#include<algorithm>
#include<functional>
#include<utility>
#include<vector>
#include<string>
#include<stack>
#include<queue>
#include<map>
#include<set>
 
using namespace std;
const int dx[] = {1,0,-1,0},dy[] = {0,1,0,-1};
#define INF 1e+9
#define EPS 1e-9
#define P pair<int,int>
#define rep(i,j) for(int i = 0; i < (j); i++)
#define reps(i,j,k) for(int i = j; i < (k); i++)
typedef long long ll;
priority_queue<P, vector<P> > PQ;
int main(){
    int icicle[100010]={0};
    int N,L;
    scanf("%d%d",&N,&L);
    int x;
    rep(i,N){
        scanf("%d",&x);
        PQ.push(P(x,i+1));
    }
    while( !PQ.empty() ){
        int l = PQ.top().first;
        int m = PQ.top().second;
        PQ.pop();
        int t = icicle[m] + L - l;
        icicle[m-1] = max(t,icicle[m-1]);
        icicle[m+1] = max(t,icicle[m+1]);
    }
    int res = 0;
    rep(i,N){
        res = max(res,icicle[i+1]);
    }
    printf("%d\n",res);
    return 0;
}

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

const int MAX_N = 100;
const int MAX_W = 1e9;
const int MAX_V = 1000;

const ll INF = 1e11;

int main() {
    int N, W; cin >> N >> W;
    vector<pair<int, int>> wv(N);
    for (int i = 0; i < N; i++) {
        cin >> wv[i].first;
        cin >> wv[i].second;
    }
    vector<vector<ll>> memo(N, vector<ll>(N*1000+1, INF));
    for (int i = 0; i < N; i++) memo[i][0] = 0;
    memo[0][wv[0].second] = wv[0].first;
    for (int i = 1; i < N; i++) {
        for (int j = 1; j <= N * 1000; j++) {
            memo[i][j] = min(memo[i-1][j], memo[i-1][max(0, j-wv[i].second)] + wv[i].first);
        }
    }
    int ans = 0;
    for (int i = 0; i <= N*1000; i++) {
        if (memo[N-1][i] <= W) ans = i;
    }
    cout << ans << endl;
}


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

int main(){
  int N; cin>>N;
  vector<long long> L(3*N);
  for (int i=0;i<3*N;++i){
    cin>>L[i];
  }
  sort(L.begin(),L.end());
  long long ans=0;
  for (int i=N;i<3*N;i+=2){
    ans+=L[i];
  }
  cout<<ans<<endl;
}
  

Measured memory_bytes: 2560
def main(n,a,b):
    res = 0
    for i in range(1, n+1):
        val = sub(i)
        if a <= val and val <= b:
            res += i
    return res

def sub(val):
    res = 0
    x = val
    while x > 0:
        x, j = divmod(x,10)
        res += j
    return res

n,a,b = map(int, input().split())
print(main(n,a,b))

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

int main() {
	std::size_t N, X, tmp;
	std::cin >> N >> X;

	std::size_t rem = X;
	std::size_t low_ = 1000000;

	for (std::size_t i = 0; i < N; i++) {
		std::cin >> tmp;
		rem -= tmp;
		low_ = std::min(tmp, low_);
	}

	std::cout << N + (rem / low_) << "\n";
	//std::cin >> tmp;
	return 0;
}


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

#define ll long long

signed main()
{
  int n,d; cin >> n >> d;
  ll x,y,cnt=0; double p;

  for(int i=0; i<n; ++i)
  {
    cin >> x >> y;
    p = sqrt(x*x + y*y);
    if(p<=d) ++cnt;
  }
  cout << cnt << endl;
}

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

int main(){
  int N;
  cin >> N;
  
  vector<int> A(N),B(N);
  vector<int> sum_n(N,0);
  for(int i=0;i<N;i++){
    cin >> A.at(i);
  }
  for(int i=0;i<N;i++){
    cin >> B.at(i);
  }
  
  for(int i=0;i<N;i++){
    sum_n.at(i) += A.at(0);
    for(int j=1;j<=i;j++){
      sum_n.at(i) += A.at(j);
    }
    for(int j=i;j<N;j++){
      sum_n.at(i) += B.at(j);
    }    
  }
  sort(sum_n.begin(),sum_n.end());
  cout << sum_n.at(N-1) << endl;
}

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

using namespace std;

const int N=105;
int n,d[N];

int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        int a,b;
        cin>>a>>b;
        if(a==b) d[i]=1;
    }
    for(int i=1;i<=n-2;i++) if(d[i]+d[i+1]+d[i+2]==3) return cout<<"Yes",0;
    cout<<"No";
}


Measured memory_bytes: 3620
#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <set>
#include <string.h>
#include <math.h>
#include <map>
using namespace std;

int gcd(int a, int b){
  int mi = std::min(a, b);
  int ma = std::max(a, b);
  if(mi == 0){
    return ma;
  }else{
    return gcd(ma % mi, mi);
  }
}

std::set<int> get_prime_factors(int n){
  std::set<int> result;
  while(n%2==0){
    n = n / 2;
    result.insert(2);
  }
  for(int i=3; i<=sqrt(n)+1; i=i+2){
    while( n % i == 0){
      n = n / i;
      result.insert(i);
    }
  }
  if (n > 2){
    result.insert(n);
  }
  return result;
}

int main()
{
  int n = 0;
  long long base = 1e9+7;
  scanf("%d", &n);
  vector<int> a(n, 0);
  for(int i=0; i<n; i++){
    scanf("%d", &a[i]);
  }
  std::map<int, int> primes;
  for(int i=0; i<n; i++){
      std::set<int> current_factors = get_prime_factors(a[i]);
    for (std::set<int>::iterator it = current_factors.begin(); it != current_factors.end(); ++it) {
      if(primes.find(*it) != primes.end()){
        primes[*it] += 1;
      }else{
        primes[*it] = 1;
      }
    }
  }
  int max_number = 1;
  for(std::map<int, int>::iterator it = primes.begin(); it != primes.end(); ++it){
    max_number = std::max(it->second, max_number);
  }
  if(max_number == 1){
    printf("pairwise coprime\n");
  }else{
    if(max_number < n){
      printf("setwise coprime\n");
    }else{
      printf("not coprime\n");
    }
  }


  


//  printf("%d\n", gcd(150, 155));


//  for(int i=0; i<n; i++){
//    for(int j=0; j<k+1; j++){
//      printf("%lld ", arr[i][j]);
//    }
//    printf("\n");
//  }
//  printf("%lld\n", (arr[n-1][k] - arr[n-1][k-1] + base) % base);
}


Measured memory_bytes: 10672
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<string>
#define inf 1e18
using namespace std;
const int maxn = 2e5+10;
long long a[maxn];
long long sum[maxn];
int main()
{
  int n;
   scanf("%d",&n);

        memset(sum,0,sizeof(sum));
        for(int i=1;i<=n;i++)
        {
            scanf("%lld",&a[i]);
            sum[i]=a[i]+sum[i-1];
        }


        long long x = 0;
        long long y=0;
        long long minn = inf;
        int mi=0;
        for(int i=1;i<n;i++)
        {

           minn = min(minn,abs(sum[n]-2*sum[i]));

        }

        cout<<minn<<endl;

    return 0;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int a, b;
    cin >> a >> b;

    int ans = -1;
    int ma, mb;
    for (int i = 1000; i > -1; i--) {
        ma = i*0.08;
        mb = i*0.1;
        // cout << ma << " " << mb << endl;
        if (( ma == a) && ( mb == b)) ans = i;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256