akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
#include <climits>
#include <set>

using namespace std;

template<typename T>
void show(T a){
  for(auto i = a.begin(); i != a.end(); i++)
    cout << *i << " ";
  cout << endl;
}

int main(void){
  int m, n, tmpvalue, tmpweight;
  cin >> n >> m;
  vector<int> dplist(m+1, 0);
  vector<int> values = vector<int>(n, 0);
  vector<int> weights = vector<int>(n, 0);
  for(auto i = 0; i < n; ++i){
    cin >> tmpvalue >> tmpweight;
    values[i] = tmpvalue;
    weights[i] = tmpweight;
  }

  for(auto i = 0; i < n; ++i){
    for(auto j = m; j >= 1; --j){
      if(weights[i] <= j){
        dplist[j] = max(dplist[j], dplist[j-weights[i]] + values[i]);
      }
      else{
        dplist[j] = dplist[j];
      }
    }
    //show(dplist);
  }

  cout << dplist[m] << endl;
  return 0;
}


Measured memory_bytes: 3140
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for (ll i = 0; i < (n); i++)
typedef pair<ll,ll> P;

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


int main(){

  int x;
  cin >> x;
  if(x>=30){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }


  return 0;
}

Measured memory_bytes: 3512
def rotate(li, b, m, e):
    """Rotate li[b:e] by (m-b).

    >>> rotate([0, 1, 2], 1, 2, 3)
    [0, 2, 1]
    >>> rotate([0], 0, 0, 1)
    [0]
    """
    m = m - b
    return li[:b] + li[b+m:e] + li[b:b+m] + li[e:]


def run():
    n = int(input())
    li = input().split()
    assert(n == len(li))

    q = int(input())
    for _ in range(q):
        b, m, e = [int(x) for x in input().split()]
        li = rotate(li, b, m, e)

    print(" ".join(li))


if __name__ == '__main__':
    run()



Measured memory_bytes: 5648
N,M,X=map(int,input().split())
CA=[list(map(int,input().split())) for i in range(N)]
min_cost=float("inf")
for bit in range(1<<N):
    cost=0
    understand=[0]*M
    for digit in range(N):
        if (bit>>digit)&1:
            cost+=CA[digit][0]
            for m in range(M):
                understand[m]+=CA[digit][m+1]
    if all(understand[m]>=X for m in range(M)):
        min_cost=min(min_cost,cost)
print(min_cost if min_cost!=float("inf") else -1)

Measured memory_bytes: 9212
#include <bits/stdc++.h>
#define endl '\n'
#define fast ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define zy -2147382637
#define bql 2147483647
#define ll long long
#define ull unsigned long long
#define ld long double
#define maxn 100010
#define rp(i, l, r) for (int i = l; i <= r; i++)
#define rb(i, r, l) for (int i = r; i >= l; i--)
#define fi first
#define se second
#define pb push_back

using namespace std;
ll prime(ll x){
   if(x<=1)return false;
   for(int i=2;i<=int(sqrt(x));i++){
	   if(x%i==0)return false;
   }return true;
}
ll gcd(ll a,ll b){ll r;while(b>0){r=a%b;a=b;b=r;}return a;}
ll powmod(ll a,ll b,ll mod) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
template <typename T>
inline void read(T &x) {
	char c = getchar(); int w = 1; x = 0;
	while (!isdigit(c))
		(c == '-') && (w = -w), c = getchar();
	while (isdigit(c))
		x = (x << 1) + (x << 3) + (c ^ '0'), c = getchar();
	x *= w;
}
const int dx[8] = {-1, 1, 0, 0, -1, 1, -1, 1},
		  dy[8] = {0, 0, -1, 1, -1, -1, 1, 1};
map <string,int> mp;
string s;
ll ans=0;
int main(){
	int n;
	cin>>n;
	while (cin>>s,sort(s.begin(),s.end()), n--){ ans+=mp[s]++; }
	cout<<ans<<endl;return 0;
	//with no copyright,QwQ
}

Measured memory_bytes: 11136
#include <stdio.h>
 
int main()
{
  int n, a, i, j;
  int x = 0;
  int y[8] = {0,0,0,0,0,0,0,0};
  int z = 0;
  int min = 0;
  int max = 0;
 
  scanf("%d", &n);
  for(i = 0; i < n; i++)
  {
    scanf("%d", &a);
    x = a / 400;
    if(x < 8)
    {
      y[x] += 1;
    }
    else if(x >= 8)
    {
      z += 1;
    }
  }
  for(j = 0; j < 8; j++)
  {
    if(y[j] > 0)
    {
      min += 1;
    }
  }
  max = min + z;
  if(min == 0)
  {
    min = 1;
  }
  printf("%d %d", min, max);
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    int n;
    cin>>n;
    map<int,bool> m;
    for(int i=0;i<n;i++){
        int a;
        cin>>a;
        if(m.count(a)){
            m[a]=!m[a];
        }else{
            m[a]=true;
        }
    }
    int ans=0;
    for(auto kv:m){
        if(kv.second)ans++;
    }
    cout<<ans<<endl;
    return 0;
}


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

//411872707
long long power[10], lev[10];
bool possi_digit[10], has_no;
char c;
int main() {
    power[0] = 1;
    for(int i = 1; i < 10; i++) power[i] = power[i-1]*10, lev[i] = power[i]-1;
    for(int i = 0; i < 10; i++) {
        //printf("? %d", power[i]);
        cout << "? " << power[i] << '\n';
        cout.flush();
        //scanf(" %c", &c);
        cin >> c;
        possi_digit[i] = (c == 'Y');
        has_no |= (c == 'N');
    }
    if(has_no) {
        long long len = 9, ans = 0;
        for(len = 0; len < 10; len++) {
            if(not possi_digit[len]) break;
        }
        for(int i = len; i >= 1; i--) {
            int d = -1;
            for(int j = 3; j >= 0; j--) {
                if(d + (1<<j) > 9) continue;
                long long num = ans*10 + lev[i] + (d + (1<<j)) * power[i];
                //printf("? %lld", num);
                cout << "? " << num << '\n';
                cout.flush();
                //scanf(" %c", &c);
                cin >> c;
                if(c == 'N') d += (1<<j);
            }
            if(d == -1) {
                long long num = ans*10 + power[i];
                //printf("? %lld", num);
                cout << "? " << num << '\n';
                cout.flush();
                //scanf(" %c", &c);
                cin >> c;
                d = (c == 'N') - 1;
            }
            ans += (d+1)*power[i-1];
        }
        //printf("! %lld\n", ans);
        cout << "! " << ans << '\n';
        cout.flush();
    }
    else {
        bool answer = false;
        for(int i = 9; i > 0; i--) {
            //printf("? %lld", lev[i]);
            cout << "? " << lev[i] << '\n';
            cout.flush();
            //scanf(" %c", &c);
            cin >> c;
            if(c == 'N') {
                //printf("! %lld", power[i]);
                cout << "! " << power[i] << '\n';
                cout.flush();
                answer = true;
                break;
            }
        }
        if(not answer) {
            cout << "! " << 1 << '\n';
            cout.flush();
        }
    }
}


Measured memory_bytes: 684
import copy

n,m=map(int,input().split())
h=list(map(int,input().split()))
l=[]
for i in range(m):
    a,b=map(int,input().split())
    l.append([a,b])
    
ll=[0]*n

for j in l:
    if h[j[0]-1]>h[j[1]-1]:
        ll[j[1]-1]+=1
    elif h[j[0]-1]==h[j[1]-1]:
        ll[j[1]-1]+=1
        ll[j[0]-1]+=1
    else:
        ll[j[0]-1]+=1

ans=0

for k in ll:
    if k==0:
        ans+=1
print(ans)

Measured memory_bytes: 29252
n=int(input())
a=list(map(int, input().split()))
q=int(input())
for i in range(q):
    com,b,e=map(int,(input()).split())
    if com==0:
        if b==e-1:
            print(a[e-1])
        else:
            print(min(a[b:e]))
    if com==1:
        if b==e-1:
            print(a[e-1])
        else:
            print(max(a[b:e]))


Measured memory_bytes: 5628
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define INF (1<<29)
#define LINF (1LL<<60)
#define EPS (1e-10)
#define PI 3.1415926535897932384626433832795028
#define all(a) (a).begin(),(a).end()
#define sz(x) (int)x.size()
#define max_heap priority_queue<int>
#define min_heap priority_queue<int,vector<int>,greater<int>>
using ll = long long;
#define int long long
#define endl "\n"
#define vi vector<int>
#define pb push_back
#define inp_arr(a,n) for(ll i=0;i<n;i++)cin>>a[i];
#define out_arr(a) for(ll i=0;i<a.size();i++)cout<<a[i]<<" ";
#define deb(n) cerr << #n << " = " << n << "\n";
int gcd(int a, int b) { if (a == 0) return b; return gcd(b % a, a);}
ll mypower(ll x,ll n,ll c){
    if(n == 0)
        return 1;
    ll temp = mypower(x,n/2,c)%c;
    if(n%2)
        return (n<0)? (1/x)*temp*temp%c: ((x*temp)%c)*temp%c;
    else
        return temp*temp%c;
}
bool codejam = 0;

int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
	#ifndef ONLINE_JUDGE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif

	ll n;
	double d;
	cin>>n>>d;
	ll ans = 0;
	for(int i=0;i<n;i++){
		ll x,y;
		cin>>x>>y;
		if(x*x + y*y <= d*d)
			ans++;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 3740
#include<iostream>
#include<list>
#include<algorithm>

// string は遅い！！！！！！

using namespace std;

int main() {
    int n;
    cin >> n;
    list<int> L;
    for (int i = 0; i < n; i++) {
        char cmd[20];
        cin >> cmd;

        if (cmd[0] == 'i') {
            int operand;
            cin >> operand;
            L.push_front(operand);
        } else if (cmd[6] == 'F') {
            L.pop_front();
        } else if (cmd[6] == 'L') {
            L.pop_back();
        } else{
            int operand;
            cin >> operand;
            for(auto itr = L.begin(); itr != L.end(); itr++) {
                if (*itr == operand) {
                    L.erase(itr);
                    break;
                }
            }
        } 
    }
    bool first = true;
    for (auto itr = L.begin(); itr != L.end(); itr++) {
        if(first) {
            cout << *itr;
            first = false;
            continue;
        }
            cout << " " << *itr;
    }
    cout << endl;
}


Measured memory_bytes: 34348
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#define _USE_MATH_DEFINES
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007; // 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
/*-------------------------------------------------*/
int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  // freopen("input.txt", "r", stdin);

  int n; cin >> n;
  string s; cin >> s;
  int r = 0, b = 0;
  for (char c : s) {
    if (c == 'R') ++r;
    else ++b;
  }
  cout << (r > b ? "Yes" : "No") << '\n';
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    char c;
    cin>>c;
    if('a'<=c&&c<='z')  cout<<'a';
    if('A'<=c&&c<='Z')  cout<<'A';
    return 0;
}


Measured memory_bytes: 3672
#include<iostream>
#include<stdio.h>
//#include <bits/stdc++.h>
#include<vector>
#include<float.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cstring>
#include<math.h>
#include<cmath>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include <cassert>
#include <cmath>
#include<cstdint>

#define INF 1e9
#define rep(i,n)for(int i=0;(i)<(int)(n);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
#define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define vec(type,n) vector<type>(n)
#define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
#define ALL(a)  (a).begin(),(a).end()

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<int,int>;

vector<int>bitSearch(int bit,int n){
    vector<int>S;
    rep(i,n)if(bit&(1<<i))S.push_back(i);
    return S;
}

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

int main(){
    int n,k;cin>>n>>k;
    VEC(int,a,n);
    int gcd = a[0];
    rep(i,n){
        if(i==0)continue;
        gcd = GCD(gcd,a[i]);
    }
    sort(ALL(a));
    cout<<(k%gcd==0 && a[n-1]>=k?"POSSIBLE":"IMPOSSIBLE")<<endl;
}



Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int n;
long long cnt = 0LL;
int main() {
    // #ifndef ONLINE_JUDGE
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "a", stdout);
    // #endif
    cin >> n;
    for(int i = 1; i < n; i++) {
        for(int j = 1; j * j <= i; j++) {
            if(i % j == 0) {
                if(j == i / j)  cnt += 1;
                else    cnt += 2;
            }
        }
    }
    cout << cnt << "\n";
    return 0;
}

Measured memory_bytes: 3544
#include <bits/stdc++.h>
using namespace std;
#define MD 1000000007
typedef long long int ll;

int main(){
    ll n,m;
    cin>>n>>m;
    vector<ll> p(m);//各市の，所属する県のIDを格納
    vector<ll> rank(m);//各市の，所属する県でのランキングを格納
    vector<pair<ll,ll>> pa[n];//i県に所属する市の情報を格納
    for(ll i=0;i<m;i++){
        ll a;
        cin>>p[i]>>a;
        pa[p[i]-1].push_back(make_pair(a,i));//firstにID，secondに何番目の市かどうかを格納
    }
    for(ll i=0;i<n;i++){
        sort(pa[i].begin(),pa[i].end());//各県に属する市をIDでソート
    }
    for(ll i=0;i<n;i++){//各県を全探索．各市の情報をrankに格納
        for(ll j=0;j<pa[i].size();j++){
            rank[pa[i][j].second]=j+1;//県iではj+1番目の市
        }
    }
    for(ll i=0;i<m;i++){
        printf("%06d",p[i]);
        printf("%06d",rank[i]);
        cout<<endl;
    }
    return 0;
}
    

Measured memory_bytes: 8576
#include <iostream>
#include <queue>

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

int h = 0, w = 0;
char maze[51][51];
int visited[51][51] = { 0 };
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int cnt = 0;

// 最短経路をbfsで決める
// ゴールした後に訪れていおらず、かつ黒のマスをカウントする
bool bfs(int x, int y)
{
    bool goal = false;
    queue<P> que;

    que.push(P(x, y));

    while (que.size()) {
        P p = que.front(); que.pop();

        /*

        cout << "x: " << p.first << endl;
        cout << "y: " << p.second << endl;

        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                if (j == w - 1) cout << maze[i][j] << endl;
                else            cout << maze[i][j];
            }
        }
        cout << endl;

        */

        if (p.first == h - 1 && p.second == w - 1) {
            goal = true;
            break;
        }

        for (int i = 0; i < 4; i++) {
            int nx = p.first + dx[i], ny = p.second + dy[i];

            if (nx >= 0 && nx < h && ny >= 0 && ny < w) {
                if (visited[nx][ny] == 1) continue;
                if (visited[nx][ny] == 0 && maze[nx][ny] == '.') {
                    que.push(P(nx, ny));
                    visited[nx][ny] = visited[p.first][p.second] + 1;
                }
            }
        }
    }

    if (goal) {
        cnt = cnt - visited[h - 1][w - 1];
    } else {
        cnt = -1;
    }

    // cout << "result: " << goal << endl;
    // cout << "cnt: " << cnt << endl;
    // cout << "visited[goal]: " << visited[h - 1][w - 1] << endl;

    return goal;
}

int main()
{
    cin >> h >> w;

    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            cin >> maze[i][j];
            if (maze[i][j] == '.') {
                cnt++;
            } 
        }
    }

    // cout << "before bfs cnt: " << cnt << endl;

    cout << (bfs(0, 0) ? cnt - 1 : -1) << endl;

    return 0;
}

Measured memory_bytes: 256
#!/usr/bin/python3
# -*- coding: utf-8 -*-
def euclid(a, b):
    if b == 0:
        return a
    else:
        return euclid(b, a % b)

def list_euclid(int_list):
    ans = int_list[0]
    if len(int_list) == 1:
        return ans
    kako_hash = {}
    kako_hash[ans] = ans
    for i in range(1,len(int_list)):
        if int_list[i] in kako_hash:
            continue
        else:
            kako_hash[int_list[i]] = int_list[i]
            ans = euclid(ans, int_list[i])
        if ans == 1:
            return ans
    return ans

n = int(input())
a = list(map(int, input().split()))
max_gcd = 0
b_int = {}
min = min(a)
if n == 2:
    max_gcd = max(a)
elif n < 5:
    for i in range(0, n):
        if a[0] in b_int:
            p = a.pop(0)
            # a.append(p)
        else:
            p = a.pop(0)
            b_int[p] = p
            x = list_euclid(a)
            if max_gcd < x:
                max_gcd = x
            a.append(p)
else:
    for i in range(0, n):
        if a[0] in b_int:
            p = a.pop(0)
            # a.append(p)
        else:
            if max_gcd == 0:
                p = a.pop(0)
                b_int[p] = p
                k = len(a) // 2
                x = 0
                y = list_euclid(a[0:k])
                if y == 1:
                    x = 1
                else:
                    z = list_euclid(a[k:len(a)])
                    x = euclid(y, z)
                if max_gcd < x:
                    max_gcd = x
                a.append(p)
            elif min <= max_gcd:
                break
            else:
                p = a.pop(0)
                b_int[p] = p
                k = len(a) // 2
                x = 0
                if k < 1:
                    x = list_euclid(a)
                else:
                    y = list_euclid(a[0:k])
                    if y == 1:
                        x = 1
                    else:
                        z = list_euclid(a[k:len(a)])
                        x = euclid(y, z)
                if max_gcd < x:
                    max_gcd = x
                a.append(p)
print(max_gcd)


Measured memory_bytes: 14088
n,m,q = map(int,input().split())
trains = [[0]*(n+1) for _ in range(n+1)]
ans = [[0]*(n+1) for _ in range(n+1)]
for i in range(m):
    l,r = map(int,input().split())
    trains[l][r] += 1
for i in range(1,n+1):
    cur = 0
    for j in range(i,n+1):
        cur += trains[i][j]
        ans[i][j] = cur
for i in range(q):
    p,q = map(int,input().split())
    ansi = 0
    for j in range(p,q+1):
        ansi += ans[j][q]
    print(ansi)

Measured memory_bytes: 55256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int w,ans;
  while(1){
    cin >> w;if(w==-1)break;
    ans = 1150;
    if(w>30){
      ans+=160*(w-30);
      w = 30;
    }
    if(w>20){
      ans+=140*(w-20);
      w = 20;
    }
    if(w>10){
      ans+=125*(w-10);
    }
    cout << 4280-ans << endl;
  }
}

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

#define INFTY 1000000001

int merge(int A[], int left, int mid, int right)
{
  int n1 = mid - left, n2 = right - mid;
  int L[n1 + 1], R[n2 + 1];
  for (int i = 0; i < n1; i++) {
    L[i] = A[left + i];
  }
  for (int i = 0; i < n2; i++) {
    R[i] = A[mid + i];
  }
  L[n1] = INFTY;
  R[n2] = INFTY;
  int i = 0, j = 0, count = 0;
  for (int k = left; k < right; k++) {
    if (L[i] <= R[j]) {
      A[k] = L[i];
      i++;
    } else {
      A[k] = R[j];
      j = j + 1;
    }
    count++;
  }
  return count;
}

int mergeSort(int A[], int left, int right)
{
  int count = 0;
  if ((left + 1) < right) {
    int mid = (left + right)/2;
    count += mergeSort(A, left, mid);
    count += mergeSort(A, mid, right);
    count += merge(A, left, mid, right);
  }
  return count;
}

int main() {
  int n;
  cin >> n;
  int S[n], count;
  for (int i = 0; i < n; i++) cin >> S[i];
  count = mergeSort(S, 0, n);
  for (int i = 0; i < n; i++) {
    if (i) cout << " ";
    cout << S[i];
  }
  cout << endl << count << endl;
  return 0;
}

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

using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

bool check(vector<pair<int, int>> a) {
    int h = 0;
    for (auto p : a) {
        int d = h + p.first;
        if (d < 0) return false;
        h += p.second;
    }
    return true;
}

int main() {

    int n; cin >> n;

    vector<pair<int, int>> l;
    vector<pair<int, int>> r;

    int total = 0;
    vector<string> s(n);
    for (int i = 0; i < n; ++i) {
        cin >> s[i];

        int h = 0;
        int d = 0;
        for (char c : s[i]) {
            if (c == '(') {
                ++h;
            } else {
                --h;
            }
            d = min(d, h);
        }

        if (h >= 0) {
            l.push_back(make_pair(d, h));
        } else {
            r.push_back(make_pair(d - h , -h));
        }

        total += h;
    }

    sort(l.rbegin(), l.rend());
    sort(r.rbegin(), r.rend());

    if (check(l) && check(r) && total == 0) {
        puts("Yes");
    } else {
        puts("No");
    }
}

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

//Code Short
#define REP(i,n) for(int i = 0;i < n;++i)
#define PB(s) push_back(s)
#define DSORT(n) sort(n.begin(),n.end())
#define QECHO(n) cout << n
#define QECHOS(n) cout << n << " "

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

using namespace std;
typedef long long ll;
/* prototype */
int EDSum(ll);//各桁の和
vector<int> SOE(int,int);//素数 (Min,Max)
int MinCM(int,int);//最小公倍数(num1,num2)
int MaxCD(int,int);//最大公約数(num1,num2)
vector<int> igets(int);//cin * N
ll nPr(ll,ll); //(n,r)
ll nE(ll); //(n)
ll nCr(ll,ll); //(n,r)

void solve(){
    //START
    int a,b;
    cin >> a >> b;
    if((a+b)%3==0 || a%3==0 || b%3==0 )QECHO("Possible");else QECHO("Impossible");
    QECHO("\n");
}

int main(void){cin.tie(0);ios::sync_with_stdio(false);solve();}
int EDSum(ll number) {
  int ans = 0;
  while (1) {
    ans += number % 10;
    number /= 10;
    if (number == 0) break;
  }
  return ans;
}

vector < int > SOE(int min, int max) {
  if (min < 2) min = 2;
  vector < int > int_array;
  for (int i = min; i <= max; i++) int_array.push_back(i);
  vector < int > sosu;
  double stop = sqrt(max);
  while (true) {
    sosu.push_back(int_array.front());
    int_array.erase(int_array.begin());
    if (stop < (double)(sosu.back())) break;
    for (int i = 0; i < (int) int_array.size(); i++) {
      if (int_array[i] % sosu.back() == 0)
        int_array.erase(int_array.begin() + i);
    }
  }
  sosu.insert(sosu.end(), int_array.begin(), int_array.end());
  return sosu;
}

int MinCM(int a, int b) {
  int c = a * b;
  if (a < b)
    swap(a, b);
  int r = a % b;
  while (r != 0) {
    a = b;
    b = r;
    r = a % b;
  }
  return c / b;
}

int MaxCD(int a, int b) {
  if (a < b)
    swap(a, b);
  int r = a % b;
  while (r != 0) {
    a = b;
    b = r;
    r = a % b;
  }
  return b;
}
vector < int > igets(int N) {
  vector < int > A;
  int temp;
  for (int i = 0; i < N; ++i) {
    cin >> temp;
    A.push_back(temp);
  }
  return A;
}

ll nPr(ll n, ll r) {
  ll ans = 1;
  r = n - r;
  while (n != r) {
    ans *= n;
    --n;
  }
  return ans;
}

ll nE(ll n) {
  return nPr(n, n);
}

ll nCr(ll n, ll r) {
  if (r == 0) return -1;
  else {
    if (0 != n - r && n - r < r) r = n - r;
    return nPr(n, r) / nE(r);
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define EM 100000000
using namespace std;
using LL = long long;
using P = pair<LL, LL>;
LL LINF = 1e18;
int INF = 1e9;
LL mod = 1e9+7;
using vint = vector<int>;
using vLL = vector<LL>;
using vvint = vector<vector<int>>;
using vvLL = vector<vector<LL>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
	int N;
	cin >> N;
	int subk = sqrt(2*N*4+1);
	if(subk*subk != 2*N*4+1){cout << "No" << endl; return 0;}
	int K = (subk+1)/2;
	vvint s(K);
	int cur = 1;
	for(int i = 0;i < K;i++){
		for(int j = i+1;j < K;j++){
			s[i].push_back(cur);
			s[j].push_back(cur++);
		}
	}
	cout << "Yes" << endl;
	cout << K << endl;
	for(int i = 0;i < K;i++){
		cout << (K-1) << " ";
		for(int j = 0;j < K-1;j++){cout << s[i][j] << " ";}
		cout << endl;
	}
}

Measured memory_bytes: 2304
fun main(args: Array<String>) {
    val (a, b) = readLine()!!.split(' ').map { it.toInt() }

    val x = (a * 100 + 7) / 8
    if (x / 10 == b) {
        println(x)
        return
    }

    val y = b * 10
    if (y * 8 / 100 == a) {
        println(y)
        return
    }

    println(-1)
}


Measured memory_bytes: 38264
N,x = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
cnt = 0
for ind in range(len(a)-1):
    if(ind==0):
        if(a[1]+a[0]>x):
            cnt += a[1]+a[0]-x
            a[1]-=min(a[1]+a[0]-x,a[1])
            a[0]-=max((a[1]+a[0])-x,0)
    if(a[ind+1]+a[ind]>x):
        cnt += a[ind+1]+a[ind]-x
        a[ind+1] -= a[ind+1]+a[ind]-x
print(cnt)


Measured memory_bytes: 14400
#include<stdio.h>
#include<string.h>
struct Node{
  int key;
  struct Node *right,*left,*parent;
};
  
struct Node *root,*NIL;
  
void insert(int k){
  struct Node *x=root;
  struct Node *y=NIL;
  struct Node *z;
  
  z=(struct Node *)malloc(sizeof(struct Node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;
  
  while( x!=NIL){
    y=x;
    if(z->key < x->key){
      x=x->left;
    }else{
      x=x->right;
    }
  }
  z->parent=y;
  if(y==NIL){
    root=z;
  }else{
    if(z->key < y->key){
      y->left=z;
    }else{
      y->right=z;
    }
  }
}
  
void inorder(struct Node *u){
  if(u==NIL)return;
  inorder(u->left);
  printf(" %d",u->key);
  inorder(u->right);
}
  
void preorder(struct Node *u){
  if(u==NIL)return;
  printf(" %d",u->key);
  preorder(u->left);
  preorder(u->right);
}
  
int main(){
  int n,i,x;
  int a=0,b=0;
  char com[10];
  
  scanf("%d",&n);
  
  for(i=0;i<n;i++){
    scanf("%s",com);
      
    a = strcmp(com,"insert");
    if(a==0){
      scanf("%d",&x);
      insert(x);
    }
  
    b = strcmp(com,"print");
    if(b==0){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
  }
  
  return 0;
}

Measured memory_bytes: 24040
n = int(input())
cc = list(input())

l = 0
r = n - 1
count = 0
while l < r:
    while l < n and cc[l] != "W":
        l += 1
    while 0 <= r and cc[r] != "R":
        r -= 1
    if 0 <= l < r < n:
        cc[l], cc[r] = cc[r], cc[l]
        count += 1
    else:
        break
print(count)

Measured memory_bytes: 10680
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	static Scanner scanner;

	public static void main(String[] args) {
	    scanner = new Scanner(System.in);

        int a=gi();
        int b=gi();

        int c=0;
        for (int i=a; i<=b; i++) {
            String s=String.valueOf(i);
            StringBuffer sb = new StringBuffer(s);
            if(s.equals(sb.reverse().toString())) {
            	c++;
            }
        }
        

	    System.out.println(c);

//	    if (isNumber(s1) && isNumber(s2) && s.charAt(a) == '-') {
//	    	System.out.print("Yes");
//	    }else {
//	    	System.out.print("No");
//	    }



	}

	public static long d(long n) {
		String a=String.valueOf(n);
		return (long)a.length();
	}

	// 文字列として入力を取得
	public static String gs() {
		return scanner.next();
	}

	// intとして入力を取得
	public static int gi() {
		return Integer.parseInt(scanner.next());
	}

	// longとして入力を取得
	public static long gl() {
		return Long.parseLong(scanner.next());
	}

	// doubleとして入力を取得
	public static double gd() {
		return Double.parseDouble(scanner.next());
	}
}

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


int main(){
    int N;
    int x[200005];
    cin >>N;
    
    for(int i =0 ; i < N; i++){
        cin >>x[i];
    }
    
   
    if (x[0] >0){
        cout << -1 << endl;
            return 0;
    }
    long long ans=0;

    for(int i =1 ; i < N; i++){
        if(x[i] - x[i-1] > 1){
            cout << -1 << endl;
            return 0;
        }
        else if(x[i] - x[i-1] == 1){
            ans++;
        }
        else if(x[i] - x[i-1] <= 0){
            ans += x[i];
        }
       
    }
    
    cout << ans << endl;
    return 0;
}
    

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
typedef long long ll;
typedef pair<int,int> pint;

ll a,b,c;
int main(){
    int ans=0;
    cin>>a>>b;
    c=__gcd(a,b);
    for(ll i=2;i*i<=c;++i){
        if(c%i==0){
            ++ans;
            while(c%i==0){
                c/=i;
            }
        }
    }
    if(c!=1) ++ans;
    cout<<ans+1<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define int long long
using namespace std;
typedef vector<int>   vint;
typedef pair<int,int> pint;

signed main()
{
    int x1,y1,x2,y2;
    cin>>x1>>y1>>x2>>y2;

    int dx=x2-x1,dy=y2-y1;
    cout<<x2-dy<<' '<<y2+dx<<' '<<x2-dy-dx<<' '<<y2+dx-dy<<endl;

}


Measured memory_bytes: 256
# include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pii pair<int,int>
typedef long long ll;
ll n,m;
string s,t;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cin>>n>>m;
    cin>>s>>t;
    int fpb=__gcd(n,m);
    int x=n/fpb;
    int y=m/fpb;
    for(int i=0,j=0;i<n && j<m;i+=x,j+=y){
        if(s[i]!=t[j]){
            cout<<-1<<endl;
            return 0;
        }
    }
    cout<<(n*m)/fpb<<endl;
}

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

int main(){
  int A,B,C,D;
  cin >> A >> B >> C >> D;

  int time = 0;
  if(A <= C){
    if(C <= B){
      if(D <= B){
	time = D-C;
      }
      else{
	time = B-C;
      }
    }
  }
  else{
    if(A <= D){
      if(B <= D){
	time = B-A;
      }
      else{
	time = D -A;
      }
    }
  }

  cout << time << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
template<class T> void ckmin(T &a, T b) { a = min(a, b); }
template<class T> void ckmax(T &a, T b) { a = max(a, b); }
#define pb push_back
#define mp make_pair
#define Red ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define F first
#define S second
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int i = 0; i < n; ++i)
#define repr(i,n) for(int i = n - 1; i >= 0; --i)
#define Rep(i, a, n) for(int i = (a); i <=(n); ++i)
#define repst(i, n) for(auto it = n.begin(); it != n.end(); ++it)
#define Repr(i, a, n) for(int i = (n); i >= (a); --i)
typedef long long ll;
 
const int inf = int(1e9);
const int mod = 1e9 + 7;
const int N = 1e6 + 555;
const long double PI = acos(-1.0);
map<ll, ll> cnt;
ll binpow (ll a, ll n) {
	ll res = 1;
	while (n) {
		if (n & 1){
			res *= a;
			res %= mod;
		}
		a *= a;
		a %= mod;
		n >>= 1;
	}
	return res % mod;
}
// 4 3 1 2 4 3 1 2 4 3 1 2
// 15 + 9 + 6 + 3
void solve()
{	
	ll n, k;
	cin >> n >> k;
	int a[n];
	for(int i = 0; i < n; ++i){
		cin >> a[i];	
		cnt[a[i]]++;
	}
	ll res = 0;
	vector<pair<ll, ll> > temp;
	for(int i = 0; i < n; ++i){
		for(int j = 0; j < i; ++j){
			if(a[j] > a[i]) res++;
		}
	}
	for(auto it : cnt){
		temp.pb(mp(it.F, it.S));
	}
	sort(all(temp));
	int r = sz(temp);
	ll pref[r], add = 0, pw = ((k) * (k - 1) / 2) % mod; 
	pref[0] = 0;
	for(int i = 1; i < sz(temp); ++i){
		pref[i] = (temp[i - 1].S) * temp[i].S;
		pref[i] %= mod;
		// cout << pref[i] << endl;
		add += pref[i] * pw;
		add %= mod;
		temp[i].S += temp[i - 1].S;
		temp[i].S %= mod;
	}	
	// cout << add << endl;
	ll sum = (res * k)% mod + add;
	sum %= mod;
	cout << sum;

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

Measured memory_bytes: 384
a,b,x = gets.chomp.split.map(&:to_f)

if (a**2)*b/2== x
  puts 45
elsif (a**2)*b/2 < x
  tan_t = 2 * (b/a) - 2 * x/(a**3)
  p 180 * Math.atan(tan_t)/Math::PI
else
  tan_t = (a * b*b)/(2 * x)
  p 180 * Math.atan(tan_t)/Math::PI
end




Measured memory_bytes: 1916
#include <bits/stdc++.h>
#define Inf 1000000007
using namespace std;
int dp[1001][1001];
int makegrid(int h,int w,char grid[][1001])
{     
    dp[0][0]=1;
       for(int j=1;j<w;j++)
       {
           if(grid[0][j]=='#')
           dp[0][j]=0;
           else
           dp[0][j]=dp[0][j-1];
       }
        for(int i=1;i<h;i++)
       {
           if(grid[i][0]=='#')
           dp[i][0]=0;
           else
           dp[i][0]=dp[i-1][0];
       }
       ////////////////
    for(int i=1;i<h;i++)
    {
        for(int j=1;j<w;j++)
        {    
            if(grid[i][j]=='#')
            dp[i][j]=0;
            else
            dp[i][j]=(dp[i-1][j]+dp[i][j-1])%Inf;
        }
    }
    return dp[h-1][w-1];
}
int main() {
    
    char grid[1001][1001];
    int h,w;
    cin>>h>>w;
    for(int i=0;i<h;i++)
    {
        for(int j=0;j<w;j++)
        {
            cin>>grid[i][j];
        }
    }
    cout<<makegrid(h,w,grid)<<endl;
    
    
    return 0;
}


Measured memory_bytes: 8480
// A - Candy Distribution Again
// https://atcoder.jp/contests/agc027/tasks/agc027_a
#include <bits/stdc++.h>
#define lli long long int
#define uli unsigned long long int
#define rep(i, m, n) for (lli i = m; i < (n); i++)
#define repe(i, m, n) for (lli i = m; i <= (n); i++)
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((lli)(x).size())
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000 //10^12
#define MOD 10000007      //10^9+7
#define SORT(n) sort(n.begin(), n.end())
#define SORTR(n) sort(n.begin(), n.end(), greater<int>())
#define REV(n) reverse(n.begin(), n.end())
#define Vec(K, L, N, S) vector<L> K(N, S)
#define rt sqrt
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vlli = vector<lli>;
using vs = vector<string>;
using ll = long long;
// vector入力
template <typename T>
istream &operator>>(istream &is, vector<T> &vec)
{
  for (T &x : vec)
    is >> x;
  return is;
}
// vector出力
template <typename T>
ostream &operator<<(ostream &os, vector<T> &vec)
{
  // os << '{';
  for (int i = 0; i < vec.size(); i++)
  {
    os << vec[i] << (i + 1 == vec.size() ? "" : "");
  }
  // os << '}';
  return os;
}

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  lli b, c, h, k, n, w, x, ans = 0, count = 0, tmp = 0;
  string s, t;
  cin >> n >> x;
  vlli a(n);

  rep(i, 0, n)
  {
    cin >> a[i];
    ans += a[i];
  }
  SORT(a);
  tmp = ans;
  if (x == ans)
  {
    cout << n << endl;
    return 0;
  }
  else if (x < a[0])
  {
    cout << 0 << endl;
    return 0;
  }
  else
  {
    rep(i, 0, n)
    {
      if (x >= a[i])
      {
        x -= a[i];
        count++;
      }
    }
    if (x != tmp && count == n)
      count--;
  }
  cout << count << endl;
}

Measured memory_bytes: 256
import sys

stdin = sys.stdin
def ns(): return stdin.readline().rstrip()
def ni(): return int(stdin.readline().rstrip())
def nm(): return map(int, stdin.readline().split())
def nl(): return list(map(int, stdin.readline().split()))


a, b, t = nm()
print(int(((t + 0.5) // a) * b))


Measured memory_bytes: 9188
// 標準入力
var fs = require('fs'),
length = fs.fstatSync(process.stdin.fd).size,
buffer = new Buffer(length),
bytesRead = fs.readSync(process.stdin.fd, buffer, 0, length, 0),
input = buffer.toString('utf8', 0, bytesRead).trim().split('\n');
main();

function main(){
  var x=y=0;
  var d='R';
  var route='';

  while(true){
    var dy = y*2+1;
    var uy = y*2-1;
    var ny = y*2;
    var lx = x-1;
    var rx = x+1;
    var nx = x;

    switch(d){
    case 'L':
      if(dy < input.length && +input[dy][nx]){//↓に行ける
        d='D';y++;
      }else if(+input[ny][lx]){// ←に行ける
        d='L';x--;
      }else if(uy > 0 && +input[uy][nx]){//↑に行ける
        d='U';y--;
      }else{
        d='R';x++;
      }
      break;
    case 'R':
      if(uy > 0 && +input[uy][nx]){//↑に行ける
        d='U';y--;
      }else if(+input[ny][nx]){// →に行ける
        d='R';x++;
      }else if(dy < input.length && +input[dy][nx]){//↓に行ける
        d='D';y++;
      }else{
        d='L';x--;
      }
      break;
    case 'D':
      if(+input[ny][nx]){// →に行ける
        d='R';x++;
      }else if(dy < input.length && +input[dy][nx]){// ↓に行ける
        d='D';y++;
      }else if(+input[ny][lx]){// ←に行ける
        d='L';x--;
      }else{
        d='U';y--;
      }
      break;
    case 'U':
      if(+input[ny][lx]){// ←に行ける
        d='L';x--;
      }else if(uy > 0 && +input[uy][nx]){// ↑に行ける
        d='U';y--;
      }else if(+input[ny][nx]){// →に行ける
        d='R';x++;
      }else{
        d='D';y++;
      }
      break;
    default:
      return;
    }
    route+=d;
    if(!x && !y)
      break;
  }
  console.log(route);
}

Measured memory_bytes: 7628
#include <iostream>
#include <queue>
#include <vector>

using namespace std;

struct node {
  int i;
  int v;
};

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

  int persons[1000001] = {};
  auto c = [](node &l, node &r) {
    return ((l.v < r.v) || ((l.v == r.v) && (l.i > r.i)));
  };
  priority_queue<node, vector<node>, decltype(c)> que(c);

  for (int i = 1; i <= n; ++i)
    que.push({i, 0});

  for (int i = 0; i < q; ++i) {
    int a, v;
    cin >> a >> v;

    persons[a] += v;
    que.push({a, persons[a]});

    while (true) {
      const node& t = que.top();
      if (persons[t.i] == t.v)
        break;
      que.pop();
    }

    cout << que.top().i << " " << que.top().v << endl;
  }
}


Measured memory_bytes: 23232
#include<bits/stdc++.h> 
#define Pair pair<int, int>
#define MP(x, y) make_pair(x, y)
#define fi first
#define se second
//#define int long long 
#define LL long long 
#define rg register 
#define pt(x) printf("%d ", x);
#define Fin(x) {freopen(#x".in","r",stdin);}
#define Fout(x) {freopen(#x".out","w",stdout);}
using namespace std;
const int MAXN = 1e6 + 10, INF = 1e9 + 10, mod = 1e9 + 7;
const double eps = 1e-9;
inline int read() {
    char c = getchar(); int x = 0, f = 1;
    while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();}
    while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
    return x * f;
}
int N, a[MAXN], ans, po[MAXN];
char s[MAXN]; 
map<int, int> mp;
signed main() {
	N = read();

	for(int i = 1; i <= N; i++) a[i] = read(), mp[a[i]]++;
	sort(a + 1, a + N + 1, greater<int>());
	for(int i = 1; i <= N; i++) {
		if(mp[a[i]] == 0) continue;
		for(int j = 31; j >= 0; j--) {
			LL cur = 1ll << j;
			if(a[i] == cur - a[i] ) {
				if(mp[cur - a[i]] > 1) {
					mp[cur - a[i]] -= 2; ans++;
					break;					
				}
			}
			else if(cur > a[i] && mp[cur - a[i]] > 0) {
				ans++, mp[cur - a[i]]--; mp[a[i]]--; break;
			}
		}
	}
	cout << ans;
    return 0;
}
/*
4
1 3 7 9

4
3 5 11 13

5
3 11 14 5 13
*/

Measured memory_bytes: 40448
#include <iostream>
#include <algorithm>
#include <vector>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
class Tree{
private:
  int n;
  vector<vector<int>> edge;
  vector<int> d;
  vector<int> res;
public:
  Tree(int _n,vector<int> a,vector<int> b){
    n = _n;
    edge.resize(n);
    d.resize(n,0);
    res.resize(n,0);    
    rep(i,n-1){
      edge[a[i]].push_back(b[i]);
      edge[b[i]].push_back(a[i]);      
    }
  }

  void init(vector<int> p,vector<int> x){
    rep(i,p.size()) d[p[i]] += x[i];
  }

  void dfs(int v,int p,int point){
    for(auto w:edge[v]){
      if(w==p) continue;
      dfs(w,v,point+d[w]);
    }
    res[v] = point;
  }

  void solve(){
    dfs(0,-1,d[0]);
    rep(i,n) cout << res[i] << " ";
    cout  << "\n";
  }

};


int main()
{
  int n,q;
  cin >> n >> q;
  vector<int> a(n-1),b(n-1);
  rep(i,n-1){
    cin >> a[i] >> b[i];a[i]--;b[i]--;
  }
  Tree tr(n,a,b);

  vector<int> p(q),x(q);
  rep(i,q){
    cin >> p[i] >> x[i];p[i]--;
  }
  tr.init(p,x);
  tr.solve();

  
  return 0;
}


Measured memory_bytes: 25412
let n = Scanf.sscanf (read_line ()) "%d" @@ fun n -> n
let s = Array.init n @@ fun _ -> read_line ()

let tbl = Hashtbl.create 4

let () =
  Array.iter (fun s -> Hashtbl.add tbl s 1 ) s;
  Printf.printf "AC x %d\n" @@ List.length @@ Hashtbl.find_all tbl "AC";
  Printf.printf "WA x %d\n" @@ List.length @@ Hashtbl.find_all tbl "WA";
  Printf.printf "TLE x %d\n" @@ List.length @@ Hashtbl.find_all tbl "TLE";
  Printf.printf "RE x %d\n" @@ List.length @@ Hashtbl.find_all tbl "RE";


Measured memory_bytes: 18960
N, K = map(int, input().split())
D = [_ for _ in input().split()]

t = N
while 1:
    s = str(t)
    flg = True
    for i in range(len(s)):
        if s[i] in D:
            flg = False
    if flg:
        res = t
        break
    t += 1
print(res)

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

// GNU C Compiler
//template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

// type
using ll = int_fast64_t;
using ull = uint_fast64_t;
using LL = long long;
using ULL = unsigned long long;
using PII = pair<int, int>;
//using pair<T1, T2> = p12;

//container
#define PB emplace_back
#define MP make_pair 
#define SZ(a) int((a).size())
#define ALL(v) v.begin(),v.end()

//repetition
#define REP(n) for(int i=0; i<(n); i++)
#define REPj(n) for(int j=0; j<(n); j++)
#define REPinit(i,a,n) for(int i=(a); i<(n); i++)
#define REPinitj(j,a,n) for(int j=(a); j<(n); j++)

//algorithm
//#define SORT(c) sort((c).begin(),(c).end())

//constant

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//Optimizer
// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

/* 
	add utility Algorithm
*/

int main(int argc, char const *argv[])
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int A, B;
    cin >> A >> B;

    cout << (max(0, A - 2 * B)) << endl;

    return 0;
}


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

/*#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")*/
#define mp make_pair
#define pb push_back
#define pll pair<LL,LL>
#define pii pair<int,int>
#define y second
#define x first
#define LL long long 
#define sqr(x) ((x)*(x))
#define pi acosl(-1)
#define MEM(x) memset(x,0,sizeof(x))
#define MEMS(x) memset(x,-1,sizeof(x))
using namespace std;
struct node{
    node *l,*r;
    int a,b;
    int tag;
    node(int _a,int _b):l(NULL),r(NULL),a(_a),b(_b),tag(1e9){

    }
}*root[2];
void build(node *n,int k){
    if(n->a==n->b){
        n->tag=k;
        return ;
    }
    int mid=(n->a+n->b)/2;
    n->l=new node(n->a,mid);
    n->r=new node(mid+1,n->b);
    build(n->l,k);
    build(n->r,k);
}
void add(node *n,int l,int r,int k){
    if(n->a>=l&&n->b<=r){
        n->tag=min(n->tag,k);
        return ;
    }
    if(n->b<l||n->a>r)return ;
    add(n->l,l,r,k);
    add(n->r,l,r,k);
}
int query(node *n,int x){
    if(n->a==n->b)return n->tag;
    int mid=(n->a+n->b)/2;
    if(x<=mid)return min(query(n->l,x),n->tag);
    else return min(query(n->r,x),n->tag);
}
void solve(){
    int n,q;
    scanf("%d %d",&n,&q);
    root[0]=new node(1,n);
    root[1]=new node(1,n);
    LL ans=(n-2)*1ll*(n-2);
    build(root[0],n-1);
    build(root[1],n-1);
    while(q--){
        int op,x;
        scanf("%d %d",&op,&x);
        op%=2;
        int val=query(root[op],x);
        ans-=val-1;
       // printf("%d\n",val);
        add(root[1-op],1,val,x-1);
    }
    printf("%lld\n",ans);
}
int main(){
    int t=1;
    int T=1;
    while(t--){
        solve();
    }
}
/*
100
5
5 4
4 2
4 2 3
5 4 2 3 1
*/


Measured memory_bytes: 41220
def no():
    print("No")
    exit()

n, a, b, c = map(int, input().split())
ans = []
s = [input() for _ in range(n)]
for i in range(n):
    if s[i] == "AB":
        if a == b == 1 and not i == n - 1:
            if (not c == 0) or (s[i + 1] == "AB"):
                a += 1
                b -= 1
                ans.append("A")
            else:
                if s[i + 1] == "AC":
                    a += 1
                    b -= 1
                    ans.append("A")
                else:
                    b += 1
                    a -= 1
                    ans.append("B")
        elif a + b > 0:
            if a <= b:
                a += 1
                b -= 1
                ans.append("A")
            else:
                b += 1
                a -= 1
                ans.append("B")
        else:
            no()
    elif s[i] == "BC":
        if b == c == 1 and not i == n - 1:
            if (not a == 0) or (s[i + 1] == "BC"):
                b += 1
                c -= 1
                ans.append("B")
            else:
                if s[i + 1] == "AB":
                    b += 1
                    c -= 1
                    ans.append("B")
                else:
                    c += 1
                    b -= 1
                    ans.append("C")
        elif b + c > 0:
            if b <= c:
                b += 1
                c -= 1
                ans.append("B")
            else:
                c += 1
                b -= 1
                ans.append("C")
        else:
            no()
    elif s[i] == "AC":
        if c == a == 1 and not i == n - 1:
            if (not b == 0) or (s[i + 1] == "AC"):
                c += 1
                a -= 1
                ans.append("C")
            else:
                if s[i + 1] == "BC":
                    c += 1
                    a -= 1
                    ans.append("C")
                else:
                    a += 1
                    c -= 1
                    ans.append("A")
        elif c + a > 0:
            if c <= a:
                c += 1
                a -= 1
                ans.append("C")
            else:
                a += 1
                c -= 1
                ans.append("A")
        else:
            no()
print("Yes")
for i in ans:
    print(i)

Measured memory_bytes: 17108
using System;
using System.IO;
using System.Linq;

class Program{
    static void Main(string[] args){
        var arr = Console.ReadLine().Split();
        var H = long.Parse(arr[0]);
        var W = long.Parse(arr[1]);
        long answer;
        if (H == 1 || W == 1) answer = 1;
        else answer = H * W % 2 == 0 ? H * W / 2 : H * W / 2 + 1;
        var writer = new StreamWriter(Console.OpenStandardOutput()) {AutoFlush = false};
        Console.SetOut(writer);
        Console.WriteLine(answer);
        Console.Out.Flush();}}

Measured memory_bytes: 27436
#include <iostream>
using namespace std;
#define MAX_N 100010
const int INF = 1e9;
int n;
int dp[MAX_N][3];
int h[MAX_N][3];

int main() {
    cin >> n;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < 3; j++) cin >> h[i][j];
    }
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < 3; j++) {
            for (int k = 0; k < 3; k++) {
                if (j == k) continue;
                dp[i+1][j] = max(dp[i+1][j], dp[i][k] + h[i][j]);
            }
        }
    }
    int ans = 0;
    for (int i = 0; i < 3; i++) ans = max(ans, dp[n][i]);
    cout << ans << endl;
}  

Measured memory_bytes: 2560
#include "bits/stdc++.h"
using namespace std;
using ll = long long;

const ll M = 1e9 + 7;

ll power(ll a, ll b) {
  ll x = 1, y = a;
  while (b > 0) {
    if (b % 2) x = (x * y) % M;
    y = (y * y) % M;
    b /= 2;
  }
  return x % M;
}

ll inv(ll a) {
  return power(a, M - 2);
}

ll comb(ll n, ll r) {
  ll ans = 1;
  for (ll i = 0; i < r; i++) {
    ans = (ans * (n - i)) % M;
  }
  for (ll i = 1; i <= r; i++) {
    ans = (ans * inv(i)) % M;
  }
  return ans;
}

int main() {
  ll n, a, b; cin >> n >> a >> b;
  ll ans = (power(2, n) - 1 + M) % M;
  ans = (ans - comb(n, a) + M) % M;
  ans = (ans - comb(n, b) + M) % M;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
int main(){
  string s, t;
  cin >> s >> t;
  bool ans = false;

  for(int i = 0; i < s.size(); i++){
    if(s == t){
      ans = true;
      break;
    }
    else{
      s = s.back() + s.substr(0, s.size() - 1);
    }
  }

  if(ans){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256