akhauriyash/Code-Regression huggingface dataset:
s = input()


ans = 0
i = 0
while True:
    # print(i, len(s), s)
    if i > len(s) - 2:
        print(ans)
        exit()
    if s[i] != s[i + 1]:
        ans += 2
        if i == len(s) - 2:
            s = s[:i]
        else:
            s = s[:i] + s[i + 2:]
        if i >= 1:
            i -= 1
        continue

    i += 1


Measured memory_bytes: 3420
#include<bits/stdc++.h>
using namespace std;
#define max(a,b) (a<b?b:a)
#define abs(x) (x<0?(-x):x)
#define F(i,L,R) for (int i = L; i < R; i++)
#define FE(i,L,R) for (int i = L; i <= R; i++)
#define RF(i,L,R) for (int i = L; i > R; i--)
#define RFE(i,L,R) for (int i = L; i >= R; i--)
#define getI(a) scanf("%d", &a)
#define getII(a,b) scanf("%d%d", &a, &b)
#define getIII(a,b,c) scanf("%d%d%d", &a, &b, &c)
#define VgetI(n) int (n); scanf("%d",&(n))
#define VgetII(n,m) int (n),(m); scanf("%d %d",&(n),&(m))
#define VgetIII(n,m,k) int (n),(m),(k); scanf("%d %d %d",&(n),&(m),&(k))
#define ll long long
#define INF 2000000000
#define nINF -2000000000
#define MOD 1e9+7
#define PI 3.1415926535897932384626
int main(){
	int n;
	while(~getI(n)){
		ll m=0,a=0,r=0,c=0,h=0,ans=0;
		while(n--){
			char in[50];
			scanf("%s",in);
			if(in[0]=='M') m++;
			if(in[0]=='A') a++;
			if(in[0]=='R') r++;
			if(in[0]=='C') c++;
			if(in[0]=='H') h++;
		}
		ans+=(m*a*r);
		ans+=(m*a*c);
		ans+=(m*a*h);
		ans+=(m*r*c);
		ans+=(m*r*h);
		ans+=(m*c*h);
		ans+=(a*r*c);
		ans+=(a*r*h);
		ans+=(a*c*h);
		ans+=(r*c*h);
		printf("%lld\n",ans);
	}
}


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

int main(){
    string board[50];
    int h, w;
    cin >> h >> w;
    for(int i = 0; i < h; ++i){
        cin >> board[i];
    }
    const int dj[4] = {0, 1, 0, -1};
    const int di[4] = {1, 0, -1, 0};
    bool can = true;
    for(int i = 0; i < h; ++i){
        for(int j = 0; j < w; ++j){
            if(board[i][j] == '.') continue;
            bool exist = false;
            for(int d = 0; d < 4; ++d){
                int nj = j + dj[d];
                int ni = i + di[d];
                if(nj < 0 || w <= nj) continue;
                if(ni < 0 || h <= ni) continue;
                if(board[ni][nj] == '#') exist = true;
            }
            if(!exist) can = false;
        }
    }
    if(can){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define repa(i, s, n) for(int i = s; i < (int)n; i++)
using namespace std;
using ll = long long;
typedef vector<int> vi;

int main(){
    vi cnt(26);
    string s;
    cin >> s;
    rep(i, s.size()){
        cnt[s[i] - 'a']++ ;
    }

    rep(i, 26){
        if(cnt[i] % 2 != 0){
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;
    return 0;
}

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

template<typename T>
void fin(T a){
  cout<<a<<endl;
  exit(0);
}

signed main(){
  int n;cin>>n;
  while(n--){
    int a;cin>>a;
    if(!(a&1)&&a%3&&a%5)fin("DENIED");
  }
  fin("APPROVED");
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <math.h>
#include <algorithm>
#include <functional>

using namespace std;

int main()
{
	long A, B, C, D;

	cin >> A >> B >> C >> D;

	int ac;
	ac = C / B;

	if (C % B != 0)
		ac++;

	if (D * (ac - 1) < A)
		cout << "Yes";
	else
		cout << "No";
	

	return 0;
}

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

/*vector<long long int>::iterator position;
position=lower_bound(a.begin(),a.end(),b[i]);
key=distance(a.begin(),position);*/

/**/

int main(){
    int x,y,z;
    cin>>x>>y>>z;

    cout<<z<<" "<<x<<" "<<y<<endl;
    return 0;
}

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


int main(){
	int k,n;
	while(cin>>k>>n){
		int arr[n];
		for (int i = 0; i < n; ++i){
			scanf("%d", arr+i);
		}
		int maxN = arr[1]-arr[0];

		for (int i = 1; i < n; ++i){
			maxN = max(maxN, arr[i]-arr[i-1]);
		}
		maxN = max(maxN, arr[0] - (arr[n-1]-k));
		cout << k-maxN << endl;
	}
}


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

int main() {
  int s;

  cin >> s;
  
  int s1 = s / 100;
  int s2 = (s - 100 * s1) / 10;
  int s3 = s - 100 * s1 - 10 * s2;

  cout << s1 + s2 + s3 << endl;
}


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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repr(i,n) for(int (i)=(n);(i)>0;(i)--)
#define rrep(i,n,m) for(int (i)=(n);(i)<(m);(i)++)
#define rrepr(i,n,m) for(int (i)=(n);(i)>(m);(i)--)
#define esort(s) sort((s).begin(),(s).end())

typedef long long ll;
typedef pair<int,int> ipair;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vector<int>> vvi;

const int INF = 1000000000;
const ll LINF = 1000000000000000000;
const double PI = acos(-1.0);
const double EPS = 1e-10;

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

ll A,B;

ll gcd(ll a,ll b){
    if(a<b) {
        ll tmp=a; a=b; b=tmp;
    }
    ll c=a%b;
    if(c==0) return b;
    return gcd(b,c);
}

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

void solve(){
    cin>>A>>B;
    ll ans=lcm(A,B);
    cout<<ans<<endl;
    return;
}

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

    solve();
    return 0;
}

Measured memory_bytes: 256
/*|In The Name Of Allah|*/

#include <bits/stdc++.h>

using namespace std;

const int N = 1e2+5;
const int M = 1e5+5;

const int mod = 1e9+7;

int n;
int k;
int w[N];
int v[N];
int mem[N][M];

int go(int idx , int val){
    if(idx == n + 1){
        if(val == 0)
            return 0;
        return 1e9;
    }
    if(~mem[idx][val])
        return mem[idx][val];
    int best = go(idx + 1 , val);
    if(val >= v[idx])
        best = min(best , go(idx + 1 , val - v[idx]) + w[idx]);
    return mem[idx][val] = best;
}

int main(){
    scanf("%d%d" , &n , &k);
    int sm = 0;
    for(int i = 1; i <= n; i++){
        scanf("%d%d" , &w[i] , &v[i]);
        sm += v[i];
    }
    memset(mem , -1 , sizeof mem);
    for(int i = sm; i >= 1; i--){
        if(go(1 , i) <= k){
            printf("%d\n" , i);
            break;
        }
    }
}


Measured memory_bytes: 41344
def cordtest(AAA):
  jisyo ={'H':0,'C':0,'G':0,'M':0,'B':0,'Y':0,'O':0,'R':0,'A':0}
  for i in AAA:
    
    if i <= 399:
      jisyo['H'] +=1
    elif 400 <= i <=799:
      jisyo['C'] +=1
    elif 800 <= i <=1199:
      jisyo['G'] +=1
    elif 1200 <= i <=1599:
      jisyo['M'] +=1
    elif 1600 <= i <=1999:
      jisyo['B'] +=1
    elif 2000 <= i <=2399:
      jisyo['Y'] +=1
    elif 2400 <= i <= 2799:
      jisyo['O'] +=1
    elif 2800 <= i <= 3199:
      jisyo['R'] +=1
    else:
      jisyo['A'] +=1
  maxi = 0
  mini = 0
  for i,j in jisyo.items():
    
    if i != 'A':
      if j >0:
        mini +=	1
    else:
      maxi += j
  ans = maxi + mini
  if mini ==0:
    mini =1
  
  return print(mini,ans)
N = int(input())
AA = list(map(int,input().split()))
cordtest(AA)
      
      
  

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

using namespace std;

int main() {
	double a, b, n;
	cin >> a >> b >> n;
	if (n >= b - 1) {
		cout << a - ceil(a / b) << endl;
	}
	else {
		cout << floor(a * n / b) - a * floor(n / b) << endl;
	}
}


Measured memory_bytes: 3292
#include<iostream>
#include<algorithm>
#include<string>
#include<sstream>
#define ll long long
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define RREP(i,n) for(ll (i)=(n)-1;(i)>=0;(i)--)
using namespace std;
int main() {
  ll n,m,c;
  cin >> n >> m >> c;
  ll a[20],b[20];
  ll count = 0;
  REP(i,m) cin >> b[i];
  REP(i,n){
    ll ans = c;
    REP(j,m){
      cin >> a[j];
      ans += a[j] * b[j];
    }
    if(ans>0) count ++;
  }
  cout << count << endl;
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <cstring>
using namespace std;
int main()
{
    char s[4];
    while(~scanf("%s",s)){
        int n=strlen(s);
        bool flag=0;
        for(int i=0;i<n;i++)
            if(s[i]!=s[n-i-1]){
                flag=1;
                break;
            }
        if(flag) printf("No\n");
        else printf("Yes\n");
    }

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set>

using namespace std;

typedef long long ll;

int main()
{
    ios_base::sync_with_stdio(0);
    int n;
    cin >> n;
    vector<ll> a(3 * n);
    for (int i = 0; i < 3 * n; ++i)
        cin >> a[i];
    multiset<ll> L, P;
    ll sL = 0, sP = 0;
    vector<ll> x(3 * n);
    vector<ll> y(3 * n);
    for (int i = 0; i < 3 * n; ++i)
    {
        if (i + 1 <= n)
        {
            L.insert(a[i]);
            sL += a[i];
            x[i] = sL;
        }
        else
        {
            ll t = *L.begin();
            if (a[i] > t)
            {
                L.erase(L.begin());
                L.insert(a[i]);
                sL -= t;
                sL += a[i];
                x[i] = sL;
            }
            else
                x[i] = sL;
        }
    }
    for (int i = 3 * n - 1; i >= 0; --i)
    {
        if (3 * n - i <= n)
        {
            P.insert(-a[i]);
            sP += a[i];
            y[i] = sP;
        }
        else
        {
            ll t = -(*P.begin());
            if (a[i] < t)
            {
                P.erase(P.begin());
                P.insert(-a[i]);
                sP -= t;
                sP += a[i];
                y[i] = sP;
            }
            else
                y[i] = sP;
        }
    }
    ll odp = -1000000000000000000;
    for (int i = 0; i < 3 * n; ++i)
    {
        if (i + 1 >= n && 3 * n - (i + 1) >= n)
            if (x[i] - y[i + 1] > odp)
                odp = x[i] - y[i + 1];
    }
    cout << odp;
    return 0;
}


Measured memory_bytes: 16640
from collections import Counter

N = int(input())
A = list(map(int, input().split()))
cntA = Counter(A)

cmbA = {}
for key, value in cntA.items():
    cmbA[key] = value * (value - 1) // 2

sum_cmbA = sum(cmbA.values())

for n in range(N):
    if cntA[A[n]] == 1:
        print(sum_cmbA)
    else:
        print(sum_cmbA - (cntA[A[n]] - 1))


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

int main(){
  int M,D;
  cin>>M>>D;
  int count=0;
  if(D<22){
    cout<<"0"<<endl;
  }else{
    for(int i=1;i<=M;i++){
      for(int j=22;j<=D;j++){
        if((j/10)*(j%10)==i&&j%10!=1){count++;
        //cout<<"M:"<<i<<" D:"<<j<<endl;
      }
      }
    }
    cout<<count<<endl;
  }

return 0;


}


Measured memory_bytes: 256
// A.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//

#include <iostream>
using namespace std;
int main()
{
   
    int r;
    cin >> r;

    const double pi = 3.1415926535;

    cout << 2 * pi * r << endl;
}



Measured memory_bytes: 3780
def main():
    from collections import deque
    import sys
    input = sys.stdin.readline

    inf = 1 << 60

    N, M, P = map(int, input().split())

    to = tuple(set() for _ in range(N))
    ot = tuple(set() for _ in range(N))
    for _ in range(M):
        a, b, c = map(int, input().split())
        a -= 1
        b -= 1
        to[a].add((b, -(c - P)))  # to,coin(負辺)
        ot[b].add((a, -(c - P)))  # to,coin(負辺)

    def reach(s, g, result):
        dq = deque()
        dq.append(s)
        while dq:
            v = dq.popleft()
            for u, _ in g[v]:
                if result[u]: continue
                result[u] = 1
                dq.append(u)

    reachable_from_N = [0] * N
    reachable_from_N[N - 1] = 1
    reach(N - 1, ot, reachable_from_N)

    reachable_from_1 = [0] * N
    reachable_from_1[0] = 1
    reach(0, to, reachable_from_1)

    unreachable = tuple(1 ^ (rn & r1) for rn, r1 in zip(reachable_from_N, reachable_from_1))

    def bellman_ford(dist):
        for _ in range(N):
            not_updated = True
            for v in range(N):
                for u, c in to[v]:
                    if unreachable[u]: continue
                    if (dist[v] == inf) or (dist[v] + c >= dist[u]): continue
                    dist[u] = dist[v] + c
                    not_updated = False
            if not_updated: return False

        for v in range(N):  # 負閉路検知
            for u, c in to[v]:
                if unreachable[u]: continue
                if (dist[v] == inf) or (dist[v] + c >= dist[u]): continue
                return True
        return False

    dist = [inf] * N
    dist[0] = 0
    cond = bellman_ford(dist=dist)

    if cond:
        print(-1)
    else:
        print(max(0, -dist[N - 1]))


if __name__ == '__main__':
    main()


Measured memory_bytes: 49628
import java.util.Scanner;


public class Main {
	public static void main(String[] args) {
		new Main().solve(new Scanner(System.in));
	}

	public void solve(Scanner sc) {
		String s = sc.next();
		
		int red = 0, blue = 0;
		for(int i=0; i<s.length(); i++) {
			char chr = s.charAt(i);
			if(chr =='0') {
				red++;
			} else {
				blue++;
			}
		}
		
		
		System.out.println(Math.min(red, blue) * 2);
		
	}
}


Measured memory_bytes: 25960
#include<bits/stdc++.h>
using namespace std;
int main(){
	int a,b,k;
	cin>>a>>b>>k;
	for(int i=0;i<k;i++){
		if(i%2==0){
			b+=a/2;
			a/=2;
		}else{
			a+=b/2;
			b/=2;
		}
	}
	cout<<a<<' '<<b<<endl;
}


Measured memory_bytes: 256
#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif
#include<bits/stdc++.h>
using namespace std;
#define rep(i,s,t) for(ll i = (ll)(s); i < (ll)(t); i++)
#define rrep(i,s,t) for(ll i = (ll)(s-1);(ll)(t) <= i; i--)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
constexpr ll INF = numeric_limits<ll>::max()/4;
constexpr ll n_max = 2e5+10;
#define int ll

template <typename A, typename B>
string to_string(pair<A, B> p);
string to_string(const string &s) {return '"' + s + '"';}
string to_string(const char *c) {return to_string((string) c);}
string to_string(bool b) {return (b ? "true" : "false");}
template <size_t N>
string to_string(bitset<N> v){
    string res = "";
    for(size_t i = 0; i < N; i++) res += static_cast<char>('0' + v[i]);
    return res;
}
template <typename A>
string to_string(A v) {
    bool first = true;
    string res = "{";
    for(const auto &x : v) {
        if(!first) res += ", ";
        first = false;
        res += to_string(x);
    }
    res += "}";
    return res;
}
template <typename A, typename B>
string to_string(pair<A, B> p){return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";}

void debug_out() {cerr << endl;}
template<typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << to_string(H);
    debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

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

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    string s;cin >> s;
    ll tmp = 0;
    ll ans = 0;
    s += 'S';
    rep(i,0,4){
        if(s[i] == 'R')tmp++;
        else{
            chmax(ans, tmp);
            tmp = 0;
        }
    }

    cout << ans << "\n";
}

Measured memory_bytes: 3616
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define y1 ___y1
const int N=200005;
map<int ,int > Map[N];
int n,m,Q,opt,x,y,f1[N],X[N],Y[N],tot,f2[N],size[N];
int find1(int x){
	if (x==f1[x])return x;
	return f1[x]=find1(f1[x]);
}
int find2(int x){
	if (x==f2[x])return x;
	return f2[x]=find2(f2[x]);
}
signed main(){
	scanf("%lld%lld%lld",&n,&m,&Q);
	int flag=0,cnt=0;
	for (int i=1;i<=n;i++)f1[i]=f2[i]=i,size[i]=1;
	while (Q--){
		scanf("%lld%lld%lld",&x,&y,&opt);
		x++;y++;
		if (opt==0){
			int x1=find1(x),y1=find1(y);
			if (x1!=y1){
				f1[x1]=y1;
				size[y1]+=size[x1];
				cnt++;
			}
		}
		else {
			X[++tot]=x;
			Y[tot]=y;
			flag=1;
		}
	}
	for (int i=1;i<=tot;i++)
		if (find1(X[i])==find1(Y[i])){
			puts("No");
			return 0;
		}
	if (m==n-1&&flag){
		puts("No");
		return 0;
	}
	if (m>(n-cnt)*(n-cnt-1)/2+cnt){
		puts("No");
		return 0;
	}
	puts("Yes");
}

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

const int dir[2][2] = {0,1,1,0};
int dis[103][103] , H , W; char str[103][103];
struct node{int x , y; friend bool operator <(node p , node q){return p.x < q.x;}};

int main(){
	scanf("%d %d" , &H , &W);
	memset(dis , 0x3f , sizeof(dis));
	for(int i = 1 ; i <= H ; ++i) scanf("%s" , str[i] + 1);
	priority_queue < pair < int , node > > q; dis[1][1] = str[1][1] == '#';
	q.push(make_pair(dis[1][1] , (node){1 , 1}));
	while(!q.empty()){
		node t = q.top().second; q.pop();
		for(int i = 0 ; i < 2 ; ++i){
			int x = t.x + dir[i][0] , y = t.y + dir[i][1];
			if(dis[t.x][t.y] + (str[x][y] != str[t.x][t.y]) < dis[x][y] && x > 0 && y > 0 && x <= H && y <= W){
				dis[x][y] = dis[t.x][t.y] + (str[x][y] != str[t.x][t.y]);
				q.push(make_pair(-dis[x][y] , (node){x , y}));
			}
		}
	}
	cout << (dis[H][W] + 1) / 2;
	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <algorithm>
#include <string>
#include <list>
#include <numeric>
#include <cstdlib>

bool valid(const std::string &s, int k) {
  if (k % 15 == 0) {
    if (s != "FizzBuzz") return false;
  } else if (k % 3 == 0) {
    if (s != "Fizz") return false;
  } else if (k % 5 == 0) {
    if (s != "Buzz") return false;
  } else {
    if (s != std::to_string(k)) return false;
  }
  return true;
}

int testcase_ends() {
  size_t m;
  int n;
  scanf("%zu %d", &m, &n);
  if (m == 0 && n == 0)
    return 1;

  std::list<int> pp(m);  // players
  std::iota(pp.begin(), pp.end(), 1);
  auto it=pp.begin();
  for (int i=1; i<=n; ++i) {
    char buf[32];
    scanf("%s", buf);
    std::string s=buf;
    if (pp.size() <= 1) continue;

    if (!valid(s, i)) {
      auto tmp=it++;
      pp.erase(tmp);
    } else {
      ++it;
    }
    if (it == pp.end())
      it = pp.begin();
  }
  
  it = pp.begin();
  while (it != pp.end()) {
    printf("%d%c", *it, std::next(it)!=pp.end()? ' ':'\n');
    ++it;
  }
  return 0;
}

int main() {
  while (!testcase_ends()) {}
}



Measured memory_bytes: 2820
#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;
inline ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
inline ll lcm(ll a, ll b) { return a / gcd(a, b)*b; }
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T>& V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> >& Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T>& mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }
template<typename T>vector<T> make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>auto make_v(size_t a,Ts... ts){return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type fill_v(T &t,const V &v){t=v;}
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type fill_v(T &t,const V &v){for(auto &e:t) fill_v(e,v);}
/*
 <url:https://atcoder.jp/contests/abc143/tasks/abc143_a>
 問題文============================================================
 =================================================================
 解説=============================================================
 max(0,A-B*2)
 ================================================================
 */

template<class Type>
Type solve(Type res = Type()){
    int A,B; cin >> A >> B;
    res = max(0,A-B*2);
    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    // solve(0);
    cout << fixed << setprecision(15) << solve<ll>() << endl;
    return 0;
}


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

#include <iostream>
#include <vector>
#include <math.h>

std::unordered_map<long, int> mp;
std::vector<int> v;

int main(void) {
  int k, n;
  int p[1000] = {0};
  int sum = 0;

  scanf("%d %d", &n, &k);

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

  std::sort(p, p + n);

  for(int i = 0; i < k; i++){
    sum += p[i];
  }

  printf("%d", sum);

  return 0;
}

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

int main() {
  int n;
  cin >> n;
  string s;
  do {
    if (n % 2 != 0) {
      --n;
      s = "1" + s;
    } else {
      s = "0" + s;
    }
    n /= -2;
  } while (n != 0);
  cout << s << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
///Welcome to Nasif's Code
#define bug printf("bug\n");
#define bug2(var) cout<<#var<<" "<<var<<endl;
#define co(q) cout<<q<<endl;
#define all(q) (q).begin(),(q).end()
typedef long long int ll;
typedef unsigned long long int ull;
const int MOD = (int)1e9+7;
const int MAX = 1e6;
#define pi acos(-1)
#define inf 1000000000000000LL
#define FastRead    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int main()
{
    FastRead
    //freopen("output.txt", "w", stdout);
    map<int,int>mp;
    int n;
    cin>>n;
    vector<int>v;
    mp[n]=1;
    int cnt=1;
    while(1)
    {
        cnt++;
        if(n%2==0)
            n/=2;
        else
            n=3*n+1;

        if(mp[n])
        {
            cout<<cnt<<endl;
            return 0;
        }
        mp[n]=1;

    }

    return 0;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
#include <atcoder/all>
#define rep(i, n) for(int i = 0; i < n; i++)
#define vv(T) vector<vector<T>>
#define coa cout << ans << endl; return 0;
using namespace std;
using namespace atcoder;
using ll = long long;
template<typename T>
using vec = vector<T>;
template<typename T>
using vvec = vector<vector<T>>;
using qint = queue<int>;
using sint = stack<int>;
using pii = pair<int, int>;

using mint = modint998244353;
// const long long MOD = 998244353;

struct S{
    mint x, w;
    S(mint x = 0, mint w = 1) : x(x), w(w){}
};

S op(S a, S b){
    return S(a.x * b.w + b.x, a.w * b.w);
}

S e(){
    return S();
}

S mapping(int f, S a){
    if(f == 0) return a;
    return S((a.w - 1) / 9 * f, a.w); 
}

int composition(int f, int g){
    if(f == 0) return g;
    return f;
}

int id(){
    return 0;
}

int main(){
    int n, q;
    cin >> n >> q;
    lazy_segtree<S, op, e, int, mapping, composition, id> lt(n);
    rep(i, n) lt.set(i, S(1, 10));
    rep(i, q){
        int l, r, d;
        cin >> l >> r >> d;
        l--;
        lt.apply(l, r, d);
        S ans = lt.prod(0, n);
        cout << ans.x.val() << endl;
    }
    return 0;
}


Measured memory_bytes: 9896
use proconio::input;

fn main() {
    input! {
        n: usize,
        k: usize,
    }

    let mut count_1 = 0_usize;
    let mut count_2 = 0_usize;

    if k % 2 == 0 {
        for i in 1..=n {
            if i % k == k / 2 {
                count_2 += 1;
            } else if i % k == 0 {
                count_1 += 1;
            }
        }
    } else {
        count_1 = n / k;
    }

    let ans = count_1.pow(3) + count_2.pow(3);

    println!("{}", ans);
}


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

int num = 1;
vector<long long> A;

void update(int i, char c) {
  i += num - 1;
  A.at(i) = 1LL << (c - 'a');
  while (i > 0) {
    i = (i - 1) / 2;
    A.at(i) = A.at(i*2 + 1) | A.at(i*2 + 2);
  }
}

long long query(int a, int b, int k, int l, int r) {
  if (r <= a || b <= l) return 0;
  if (a <= l && r <= b) return A.at(k);
  else {
    long long c1 = query(a, b, 2*k+1, l, (l+r)/2);
    long long c2 = query(a, b, 2*k+2, (l+r)/2, r);
    return c1 | c2;
  }
}

int main() {
  int N; cin >> N;
  string S; cin >> S;
  num = 1;
  while (num < N) num *= 2;
  A = vector<long long>(2*num - 1, 0);
  for (int i = 0; i < N; i++) update(i, S.at(i));

  int Q; cin >> Q;
  for (int i = 0; i < Q; i++) {
    int com; cin >> com;
    if (com == 1) {
      int idx; cin >> idx; idx--;
      char c; cin >> c;
      update(idx, c);
    }
    if (com == 2) {
      int left, right; cin >> left >> right;
      left--;
      long long bit = query(left, right, 0, 0, num);
      int cnt = 0;
      for (int i = 0; i < 26; i++) {
        if ((bit >> i) & 1) cnt++;
      }
      cout << cnt << endl;
    }
  }
}

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

using namespace std;

#define MAX 110
#define INF 1e9
typedef pair<int,int> pii;
typedef pair<pii,int> State;

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

int V,E;
vector<Edge> G[MAX];

int dijkstra(){
  priority_queue<State,vector<State>,greater<State> > Q;
  Q.push(State(pii(0,0),0));
  int dp[MAX][2];
  for(int i = 0 ; i < V ; i++){
    for(int j = 0 ; j < 2 ; j++){
      dp[i][j] = INF;
    }
  }
  dp[0][0] = 0;

  while(!Q.empty()){
    State p = Q.top(); Q.pop();
    int v = p.first.second;

    if(dp[v][p.second] < p.first.first) continue;

    for(int i = 0 ; i < (int)G[v].size() ; i++){
      if(dp[v][p.second] + G[v][i].cost < dp[G[v][i].to][p.second]){
        dp[G[v][i].to][p.second] = dp[v][p.second] + G[v][i].cost;
        Q.push(State(pii(dp[G[v][i].to][p.second],G[v][i].to),p.second));
      }
      if(p.second) continue;
      int d = G[v][i].to;
      for(int j = 0 ; j < (int)G[d].size() ; j++){
        if(dp[v][0] < dp[G[d][j].to][1]){
          dp[G[d][j].to][1] = dp[v][0];
          Q.push(State(pii(dp[G[d][j].to][1],G[d][j].to),1));
        }
      }
    }
  }
  return min(dp[V-1][0],dp[V-1][1]);
}

int main(){
  int a,b,c;
  while(cin >> V >> E, V){
    for(int i = 0 ; i < V ; i++){
      G[i].clear();
    }
    for(int i = 0 ; i < E ; i++){
      cin >> a >> b >> c;
      a--, b--;
      G[a].push_back(Edge(b,c));
      G[b].push_back(Edge(a,c));
    }
    cout << dijkstra() << endl;
  }
  return 0;
}

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

int main(void){
  int n,m,i;
  cin >> n >> m;
  vector<int> a(n,-1),s(m),c(m);
  for(i=0;i<m;i++){
    cin >> s.at(i) >> c.at(i);
  }
  
  for(i=0;i<m;i++){
    if(a.at(s.at(i)-1)!=-1&&a.at(s.at(i)-1)!=c.at(i)){
      cout << -1 << endl;
      return 0;
    }
    if(n!=1&&s.at(i)==1&&c.at(i)==0){
      cout << -1 << endl;
      return 0;
    }
    a.at(s.at(i)-1)=c.at(i);
  }
  
  for(i=0;i<n;i++){
    if(i==0&&a.at(i)==-1&&n!=1){
      cout << 1;
    }else if(a.at(i)==-1){
      cout << 0;
    }else{
      cout << a.at(i);
    }
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long
#define pb push_back
#define fi first
#define se second 
#define mp make_pair
#define int long long
signed main()
{
    IOS
    string s1,s2; cin>>s1>>s2;
    int ans = 0;
    for(int i=0;i<=2;i++)
    {
        if(s1[i] == s2[i]) ans++;
    }
    cout<<ans<<endl;
    return 0;
}

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

const int limit = 50;

int N,M,ans = 0;

int a[limit],b[limit];
bool graph[limit][limit];
bool visited[limit];

void dfs(int v){
  visited[v] = true;

  //全頂点に対して、グラフが連結かつ未訪問なら、探索を続ける
  for(int v2 = 0; v2 < N; v2++){
    if(graph[v][v2] == false) continue;
    if(visited[v2] == true) continue;
    dfs(v2);
  }
}

int main(){
  cin >> N >> M;
  for(int i = 0; i < M; i++){
    cin >> a[i] >> b[i];
    a[i]--; b[i]--;
    graph[a[i]][b[i]] = graph[b[i]][a[i]] = true;
  }

  for(int i = 0; i < M; i++){
    graph[a[i]][b[i]] = graph[b[i]][a[i]] = false;
    for(int j = 0; j < N; j++) visited[j] = false;

    dfs(0);

    bool bridge = false;
    for(int j = 0; j < N; j++) if(visited[j] == false) bridge = true;
    if(bridge) ans++;

    graph[a[i]][b[i]] = graph[b[i]][a[i]] = true;
  }

  cout << ans << endl;
  return 0;

}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v; ll w; };

ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

int main() {
	int N, W; cin >> N >> W;
	vector<int> w(N);
	for (int i = 0; i < N; i++) cin >> w[i];
	sort(w.begin(), w.end());
	w.push_back(10001);
	ll ans = 0;
	for (int i = 0; i <= N; i++) {
		int sum = 0;
		for (int j = 0; j < i; j++) sum += w[j];
		if (sum > W) continue;
		vector<ll> dp(W + 1);
		dp[sum] = 1;
		for (int j = i + 1; j <= N; j++)
			for (int k = W; k >= w[j]; k--)
				dp[k] = (dp[k] + dp[k - w[j]]) % MOD;
		for (int k = max(0, W - w[i] + 1); k <= W; k++)
			ans = (ans + dp[k]) % MOD;
	}
	cout << ans << endl;
}

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

int main() {
    int N, M;
    cin >> N >> M;
    
    int sum = 0;
    for (int i = 0; i < M; i++) {
        int a;
        cin >> a;
        sum += a;
        if (sum > N)
            break;
    }
    
    if (sum > N)
        cout << -1 << endl;
    else
        cout << N - sum << endl;
    
    return 0;
}

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

const int INF = 1<<28;
const int MAXN = 10001;
const int MAXK = 15;
int n, m, W, K;
int B[MAXN], weight[MAXN], sum[1<<MAXK], dp[1<<MAXK];

int main() {
  while(cin >> n >> m >> W) {
    --m;
    K = 0;
    int top = 0;
    for(int i = 0; i < n; ++i) {
      int k; cin >> k;
      if(k) top = i;
      for(int j = 0; j < k; ++j) {
        int w; cin >> w;
        if(i) {
          B[i] |= 1 << K;
          weight[K++] = w;
        }
      }
    }

    if(K == 0) {
      cout << 0 << endl;
      continue;
    }

    for(int i = 0; i < (1<<K); ++i) {
      sum[i] = 0;
      for(int j = 0; j < K; ++j) {
        if(i >> j & 1) sum[i] += weight[j];
      }
    }

    fill(dp, dp+(1<<MAXK), INF);
    dp[0] = 0;
    for(int i = 1; i < (1<<K); ++i) {
      for(int j = i; j > 0; j = j - 1 & i) {
        if(sum[j] <= W) dp[i] = min(dp[i], dp[i-j] + 1);
      }
    }

    int res = abs(m - top);
    for(int i = top, j = 0; i > 0; --i) {
      j |= B[i];
      res += dp[j] * 2 - 1;
    }
    cout << res << endl;
  }
  return 0;
}

Measured memory_bytes: 1424
#include <bits/stdc++.h>
using namespace std;
int main(void){
    char x,y;
    cin >> x >> y;
    if(x<y){
        cout << "<" << endl;
    }
    else if(x>y){
        cout << ">" << endl;
    }
    else{
        cout << "=" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
 
int main(){ 
  int a,b;
  cin >> a >> b;
  if(a==1) a= 14;
  if(b==1) b= 14;
 
  if(a>b)      cout << "Alice"<< endl;
  else if(a<b) cout << "Bob"  << endl;
  else         cout << "Draw" << endl;
  return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <numeric>
#include <math.h>
#include <algorithm>
#include <functional>
#include <string>
#include <array>
#include <vector>
#include <list>
#include <stack>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <deque>
#include <queue>
#include <complex>
#include <bitset>
#define full(c) c.begin(), c.end()
#define vector2d(name,type,h,w,init) vector<vector<type>> name(h,vector<type>(w,init)) 
const int PRIME = 1000000007;
const int INT_INF = 2147483647;
const long long int LL_INF = 9223372036854775807;
const double PI = acos(-1);
const double EPS = 0.000000001;
typedef unsigned long long int ull;
typedef long long int ll;
using namespace std;

int main() {
	//cin.tie(0);
	//ios::sync_with_stdio(false);
	int k, s, cnt = 0;
	cin >> k >> s;
	for (int x = 0; x <= k; x++) {
		for (int y = 0; y <= k; y++) {
			int z = s - x - y;
			if (0 <= z && z <= k) cnt++;
		}
	}
	cout << cnt << endl;
	return 0;
}


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

#define ll long long

ll n;
ll a[200000];

void solve(){
    ll sum=0LL;
    cin>>n;
    for(int i=0; i<n; i++){
        cin>>a[i];
        sum+=a[i];
    }
    
    ll mid=sum/(2LL);
    ll sum1=0LL;
    ll sum2=0LL;
    ll ans;
    bool flag=false;
    bool flag1=false;
    for(int i=0; i<n; i++){
        sum2=sum1;
        sum1+=a[i];
        if(sum1>=mid){
            ans=min(abs(sum1-mid), abs(sum2-mid));
            if(abs(sum1-mid)>abs(sum2-mid)){
                flag1=true;
            }
            flag=true;
            break;
        }
    }
    ans=ans*2LL;
    if(sum%(2LL)==1){
        if(flag1){
            ans+=1LL;
        }else{
            ans-=1LL;
        }
    }
    cout<<ans<<endl;
}

signed main(){
    //while(1)
    solve();
}

Measured memory_bytes: 1792
while True:
    h,w = map(int, input().split())
    if w==0 and h==0:
        break
    
    s = '#'
    d = '.'

    for i in range(h):
        if i==0 or i==h-1:
            print(s*w)
        else:
            print(s+(d*(w-2))+s)
    
    print()

    



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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
//#pragma GCC optimize ("-O3") 
#ifdef YANG33
#include "mydebug.hpp"
#else
#define DD(x) 
#endif
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2019/03/12  Problem: ABC 082 A / Link: http://abc082.contest.atcoder.jp/tasks/abc082_a  ----- */


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


	LL A, B; cin >> A >> B;

	LL ans = (A+B+1)/2;


	cout << (ans) << "\n";

	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    int a, x;
    
    x = 1;
    a = 1;
    
    while(x <= 10000){
        scanf("%d", &x);
        
        if(x >= 1 && 10000 >= x){
            printf("Case %d: %d\n", a, x);
            a++;
        }
        else{
            break;
        }
    }
    return 0;
}



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

#define REP(i, n) for (int i = 0; i < (n); ++i)

string a[50], b[50];

bool isMatch(int n, int m, int y, int x) {
    if (m + y > n || m + x > n) {
        return false;
    }

    REP(i, m) {
        REP(j, m) {
            if (a[y + i][x + j] != b[i][j]) {
                return false;
            }
        }
    }

    return true;
}

int main(void) {
    int m, n;
    bool flg = false;

    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n >> m;
    REP(i, n) {
        cin >> a[i];
    }
    REP(i, m) {
        cin >> b[i];
    }

    REP(i, n - m + 1) {
        REP(j, n - m + 1) {
            if (isMatch(n, m, i, j)) {
                flg = true;
                break;
            }
        }

        if (flg) {
            break;
        }
    }

    cout << (flg? "Yes" : "No") << "\n";
    return 0;
}

Measured memory_bytes: 256
import sys
 
n, k = map(int, input().split())
a = [int(x) for x in input().split()]
mod = pow(10, 9)+7
zero = 0
plus = []
minus = []
for i in range(n):
  if a[i] == 0:
    zero += 1
  elif a[i] > 0:
    plus.append(a[i])
  else:
    minus.append(a[i])
 
P, M = len(plus), len(minus)
plus.sort(reverse=True)
minus.sort()
ans = 1
if n == k:
  for i in range(n):
    ans *= a[i]
    ans %= mod
elif P+M < k:
  ans = 0
elif P == 0 and k%2 ==1 :
  if zero >= 1:
    ans = 0
  else:
    minus.sort(reverse=True)
    for i in range(k):
      ans *= minus[i]
      ans %= mod
else:
  q = 0
  if k%2 == 1:
    ans *= plus[0]
    ans %= mod
    q = 1
  judge = []
  for i in range((P-q)//2):
    judge.append(plus[2*i+q]*plus[2*i+q+1])
  for i in range(M//2):
    judge.append(minus[2*i]*minus[2*i+1])
  judge.sort(reverse=True)
  for i in range(k//2):
    ans *= (judge[i]%mod)
    ans %= mod
 
print(ans)

Measured memory_bytes: 31752
#include<iostream>
#include<string>
#include<algorithm>
#include<iomanip>
#include<cmath>
#include<cstdio>
#include<map>
#include<fstream>
using namespace std;
int n;
int main()
{
	cin >> n;
	int s;
	s = n;
	while (s > 10)
	{
		s = s % 10;
	}
	if (s == 3)
	{
		cout << "bon" << endl;
	}
	else if (s == 0 || s == 1 || s == 6 || s == 8)
	{
		cout << "pon" << endl;
	}
	else
	{
		cout << "hon" << endl;
	}
	return 0;
}


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

using namespace std;
mt19937_64 rng(58);

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    string n;
    cin >> n;
    for (char x : n) {
        if (x == '7') {
            cout << "Yes\n";
            return 0;
        }
    }
    cout << "No\n";
}

Measured memory_bytes: 3648
#include <cstdio>
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <ctype.h>
#include <cmath>
#include <stdlib.h>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
using namespace std;
#define inf 0x3f3f3f3f
#define PI acos(-1.0)
#define me(x) memset(x,0,sizeof(x))
#define scan(x) scanf("%d",&x)
#define scan2(x,y) scanf("%d%d",&x,&y)
#define STR(s) strlen(s)
#define FOR(i,sta,n) for(i=sta;i<n;i++)
#define FOR1(i,sta,n) for(i=sta;i<=n;i++)

typedef long long ll;
int vis[20]={0,1,3,1,2,1,2,1,1,2,1,2,1};

int main()
{
    int x,y;
    scanf("%d%d",&x,&y);
    if(vis[x]==vis[y])
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 384
s=int(input())
SUM=[s]
for i in range(10**7):
  if SUM[i]%2==1:
    SUM.append(SUM[i]*3+1)
  else:
    SUM.append(int(SUM[i]/2))
  if SUM.count(SUM[i])==2:
    print(i+1)
    break

Measured memory_bytes: 3060
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<string>
#include<cstring>
using namespace std;
int main()
{
	double l,a,b,c;
	cin>>l;
	a=b=l/3;
	c=l-a-b;
	printf("%.10lf",a*b*c);
	return 0;
}

Measured memory_bytes: 256
//#pragma warning disable
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System;
using System.Numerics;
using System.Threading.Tasks;
using static System.Math;
using static System.Console;
class Z { static void Main() => new K(); }
class K
{
	int F() => int.Parse(ReadLine());
	long FL() => long.Parse(ReadLine());
	int[] G() => ReadLine().Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToArray();
	long[] GL() => ReadLine().Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries).Select(long.Parse).ToArray();
	public const int MOD = 1000000007;
	public K()
	{
		SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
		Solve();
		Out.Flush();
	}
	int N;
	int[] P, X, Y;
	List<int>[] child;
	void Solve()
	{
		N = F();
		P = new int[N];
		P[0] = -1;
		X = G();
		child = new List<int>[N];
		for (var i = 0; i < N; i++) child[i] = new List<int>();
		for (var i = 0; i < N - 1; i++)
		{
			P[i + 1] = X[i] - 1;
			child[i + 1].Add(P[i + 1]);
			child[P[i + 1]].Add(i + 1);
		}
		X = G();
		Y = new int[N];
		WriteLine(DFS(0, -1) >= 0 ? "POSSIBLE" : "IMPOSSIBLE");
	}
	int DFS(int v, int p)
	{
		var x = new List<int>();
		var y = new List<int>();
		foreach (var c in child[v])
			if (c != p)
			{
				x.Add(X[c]);
				var t = DFS(c, v);
				if (t < 0) return Y[v] = -1;
				y.Add(t);
			}
		var d = x.Count;
		if (d == 0) return Y[v] = 0;
		var s = 0;
		for (var i = 0; i < d; i++) s += Min(x[i], y[i]);
		if (s > X[v]) return Y[v] = -1;
		var m = new int[X[v] + 1];
		for (var i = 1; i <= X[v]; i++) m[i] = MOD;
		for (var i = 0; i < d; i++)
		{
			var n = new int[X[v] + 1];
			for (var k = X[v]; k >= 0; k--)
			{
				n[k] = MOD;
				if (k >= x[i]) n[k] = Min(n[k], m[k - x[i]] + y[i]);
				if (k >= y[i]) n[k] = Min(n[k], m[k - y[i]] + x[i]);
			}
			m = n;
		}
		return Y[v] = m.Min();
	}
}


Measured memory_bytes: 20320
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define Sort(Array) sort(Array.begin(), Array.end())
#define Reverse(a) reverse(a.begin(), a.end())
#define out(ans) cout << ans << endl;
const int MOD = 1000000007;
const int INF = 2147483647;
const ld PI = 3.14159265358979323846;

//------------↓------------- M -------------- E ---------------- M --------------- O ---------------↓--------------//
// コンパイル 
// g++ -std=c++1z
//
// -------型変換--------
// int を string に変換
// string s = to_string(n);
// string を int に変換
// int n = stoi(s);
//
// -------二分探索---------
// k以上の値が最初に現れる時のイテレータ
// lower_bound(data.begin(), data.end(), k)
// kより大きい値が最初の現れる時のイテレータ O(logN)
// upper_bound(data.begin(), data.end(), k)
// kがdataに存在するかをtrue or falseで返す O(logN)
// binary_search(data.begin(), data.end(), k)
// 
//
//
//
//
//
// 
//------------↑------------- M -------------- E ---------------- M --------------- O ---------------↑--------------//






int main(void) {

    string s; cin >> s;
    char ans[100];
    int idx = 0;
    rep(i,s.size()) {
        if (s[i] == '0' || s[i] == '1') {
            ans[idx] = s[i];
            ++idx;
        }
        else {
            if (idx > 0) --idx;
        }
    }
    rep(i,idx) cout << ans[i];
    cout << endl;


    return 0;
}









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

using namespace std;

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

  if ((a == b && a != c) || (a == c && a != b) || (b == c && a != b))
  {
    cout << "Yes" << endl;
  } else
  {
    cout << "No" << endl;
  }

}

Measured memory_bytes: 256
n = int(input())

sum = 0.5 * n * (n + 1)

sum3 = 0
sum5 = 0
sum15 = 0
i = 1
flag3 = 1
flag5 = 1
flag15 = 1

while 1:
    if 3 * i <= n:
        sum3 += 3 * i
    else : 
        break
    if 5 * i <= n:
        sum5 += 5 * i
    if 15 * i <= n:
        sum15 += 15 * i
    i += 1

print(int(sum - sum3 - sum5 + sum15))

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

#define _GLIBCXX_DEBUG
#define all(v) (v).begin(),(v).end()

using namespace std;

using ll=long long;
using pii=pair<int, int>;
using vi=vector<int>;
using vii=vector<vector<int>>;

const ll LINF=1LL<<60;
const int INF=1<<29;
const ll MOD=1e9+7;

vii G, g;
vi check, deg;

struct Edge{
    int from;
    int to;
};

int main(){
    int N, M; cin >> N >> M;
    G.resize(N), g.resize(N), deg.resize(N);
    vector<Edge> e(M); 
    for(int i=0; i<M; i++){
        int s, t; 
        cin >> s >> t;
        s--, t--;
        e[i].from=s;
        e[i].to=t;
        G[t].emplace_back(s);
        g[s].emplace_back(t);
        deg[s]++;
    }
    vector<double> dp(N, 0);
    for(int v=N-1; v>=1; v--){
        for(auto &nv : G[v]){
            dp[nv]+=(dp[v]+1)/deg[nv];
        }
    }
    double res=dp[0];
    for(int i=0; i<=N-2; i++){
        int id;
        double maximum=-1;
        for(int j=0; j<M; j++){
            if(e[j].from == i && dp[e[j].to] > maximum){
                id=j;
                maximum=dp[e[j].to];
            }
        }
        vector<double> dp1(N, 0);
        vi ndeg=deg;
        ndeg[i]--;
        for(int j=N-1; j>=1; j--){
            for(auto &k : G[j]){
                if(e[id].from == k && e[id].to == j) continue;
                dp1[k]+=(dp1[j]+1)/ndeg[k];
            }
        }
        bool ok=true;
        queue<int> que;
        que.push(0);
        check.assign(N, 0);
        check[0]=1;
        while(!que.empty()){
            int v=que.front();
            que.pop();
            bool ng=true;
            for(auto &nv : g[v]){
                if(v == e[id].from && nv == e[id].to){
                    if(g[v].size() == 1) ok=false;
                    continue;
                }
                if(check[nv]) continue;
                check[nv]=1;
                que.push(nv);
            }
        }
        if(ok) res=min(res, dp1[0]);
    }
    cout << fixed << setprecision(7);
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 7220
#include<stdio.h>
#define MAX 2000000

int A[MAX];
int H;
void maxheapify( int i);

int main(){
    int i;
    scanf("%d",&H);
    
    for(i=1;i<=H;i++) scanf("%d",&A[i]);
    
    for(int i=H/2; i>=1; i--) maxheapify(i);
    
    for(i=1;i<=H;i++) printf(" %d",A[i]);
    printf("\n");
    return 0;
}

void maxheapify(int i){
    int l = 2 * i;
    int r = 2 * i  +1;
    int largest,t;
    
    // 左の子、自分、右の子で値が最大のノードを選ぶ
    if(l<=H && A[l]>A[i]) largest=l;
    else largest=i;
    if(r<=H && A[r]>A[largest]) largest=r;
    
    if(largest != i){
        t=A[i];
        A[i]=A[largest];
        A[largest]=t;
        maxheapify(largest);
    }
}


Measured memory_bytes: 3696
#include <bits/stdc++.h>
 
using namespace std;
 
#define int long long
 
bool used[101010];
priority_queue<int, vector<int>, greater<int>> dup;
 
signed main() {
 
  int N, K;
  cin >> N >> K;
 
  vector<pair<int, int>> sushi;
  for (int i = 0; i < N; ++i) {
    int t, d;
    cin >> t >> d;
    sushi.emplace_back(make_pair(d, t));
  }
 
  sort(sushi.rbegin(), sushi.rend());
 
  int var = K;
  long long delic = 0;
  for (int i = 0; i < K; ++i) {
    int d, t;
    tie(d, t) = sushi[i];
    if (used[t]) {
      dup.push(d);
      --var;
    }
    used[t] = true;
    delic += d;
  }
 
  long long res = delic + var * var;
  for (int i = K; i < N; ++i) {
    int d, t;
    tie(d, t) = sushi[i];
    if (used[t]) continue;
    var++;
    used[t] = true;
    if(dup.empty()) continue;
    delic -= dup.top(); dup.pop();
    delic += d;
    res = max(res, delic + var * var);
  }
 
  cout << res << endl;
 
}

Measured memory_bytes: 2672
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int MOD = pow(10, 9) + 7;
//const int MOD = 998244353;
//const int MOD = ;
int mod(int A, int M) {return (A % M + M) % M;}
const int INF = 1LL << 60;
template <class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template <class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
int divCeil(int A, int B) {return (A + (B - 1)) / B;}
int myctoi(char C) {return C - '0';}
char myitoc(int N) {return '0' + N;}

signed main()
{
  int H, W;
  cin >> H >> W;
  vector<vector<char>> S(H + 2, vector<char>(W + 2, '.'));
  for (int i = 1; i < H + 1; i++)
  {
    for (int j = 1; j < W + 1; j++)
    {
      cin >> S.at(i).at(j);
    }
  }

  string ans = "Yes";
  vector<vector<int>> d = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};
  for (int i = 1; i < H + 1; i++)
  {
    for (int j = 1; j < W + 1; j++)
    {
      if (S.at(i).at(j) == '.') continue;

      bool ok = false;
      for (int k = 0; k < 4; k++)
      {
        if (S.at(i + d.at(k).at(0)).at(j + d.at(k).at(1)) == '#')
        {
          ok = true;
          break;
        }
      }
      if (!ok)
      {
        cerr << i << " " << j << endl;
        ans = "No";
        break;
      }
    }
    if (ans == "No")
      break;
  }

  cout << ans << endl;
}

Measured memory_bytes: 256