akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <iostream>
#include <queue>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;

const int MAX = 1e6 + 10;

int main() {
  int n;
  cin >> n;
  vector<int> div(MAX, 0);
  rep(i, n) {
    int x;
    cin >> x;
    div[x]++;
  }

  for (int i = 1; i < MAX; i++) {
    if (div[i] == 0) continue;
    for (int j = i + i; j < MAX; j += i) div[j] = 0;
  }

  int ans = 0;
  for (int i = 1; i < MAX; i++) {
    if (div[i] == 1) ans++;
  }

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


Measured memory_bytes: 7212
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <limits>
#include <climits>
#include <utility>
#include <algorithm>
#include <numeric>

using namespace std;

using ll = long long;
using ull = unsigned long long;

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

    if (S.size() == T.size()-1 && S == T.substr(0, T.size()-1)) {
        cout << "Yes"<< endl;
    } else {
        cout << "No"<< endl;
    }

    return 0;
}


Measured memory_bytes: 3160
h, w = gets.split.map(&:to_i)
grid = []
h.times { grid << gets.chomp.split("") }
# 終点のみ、横に照らせるマス目の数をメモする
horizontal_sums = Array.new(h) { Array.new(w) }
# 終点のみ、縦に照らせるマス目の数をメモする
vertical_sums = Array.new(h) { Array.new(w) }

current_vertical = Array.new(w, 0)
(0...h).each do |r|
  current_row = grid[r]
  current_horizontal_sum = horizontal_sums[r]
  current_horizontal = 0
  previous_vertical_sum = vertical_sums[r - 1]
  current_vertical_sum = vertical_sums[r]
  (0...w).each do |c|
    if current_row[c] == "."
      current_horizontal += 1
      current_vertical[c] += 1
    else
      current_horizontal_sum[c - 1] = current_horizontal
      current_horizontal_sum[c] = 0
      current_horizontal= 0
      previous_vertical_sum[c] = current_vertical[c]
      current_vertical_sum[c] = 0
      current_vertical[c] = 0
    end
  end
  current_horizontal_sum[w - 1] = current_horizontal
end
vertical_sums[h - 1] = current_vertical

max = 0
current_vertical = vertical_sums[h - 1]
(h - 1).downto(0) do |r|
  current_horizontal_sum = horizontal_sums[r]
  current_horizontal = current_horizontal_sum.last
  current_vertical_sum = vertical_sums[r]
  (w - 1).downto(0) do |c|
    tmp = -1
    current_horizontal = current_horizontal_sum[c] || current_horizontal
    current_vertical[c] = current_vertical_sum[c] || current_vertical[c]
    tmp += current_horizontal
    tmp += current_vertical[c]
    max = tmp if max < tmp
  end
end
puts max


Measured memory_bytes: 362720
import itertools

N = int(input())
L = []

for i in range(N):
    x,y = map(int,input().split())
    L.append([x,y])

cnt = 0
total = 0
for v in itertools.permutations(L):
    for i in range(N-1):
        x_1 = v[i][0]
        y_1 = v[i][1]
        x_2 = v[i+1][0]
        y_2 = v[i+1][1]
        total += ((x_2 - x_1) ** 2 + (y_2 - y_1) ** 2) ** 0.5
    cnt += 1

print(total/cnt)

Measured memory_bytes: 9384
k, n = map(int, input().split())
a = list(map(int, input().split()))
ans = k
b = a[0] + (k-a[-1])

prev = a[0]

for i, v in enumerate(a):
    if i == 0:
        ans = min(ans, k-b)
    ans = min(ans, k-abs(v-prev))
    prev = v
    
print(ans)

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

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;
typedef unordered_set<int> si;
typedef pair<int, int> pp;
typedef vector<pp> vpp;
typedef unsigned int i64;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#define all(e) (e).begin(), (e).end()
#define pb push_back

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

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


template <typename T>
void printV(vector<T> A) {
  if (A.empty()) cerr << "EMTPY\n";
  else { 
    cerr << "[";
    for (int i = 0; i < A.size() -1 ; ++i) {
      cerr << A[i] << ", ";
    }
    if (A.size()) cerr << A.back() << "]\n";
  }
}


template <typename T>
void printVV(vector<vector<T>> A) {
  cerr << "[";
  for (auto v : A) {
    printV<T>(v);
  }
  cerr << "]";
}

template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cerr << name << ": " << arg1 << endl;
}

template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&& ...args) {
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

int main(int argc, char **argv) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int t; cin >> t;
  queue<ll> q;
  for (ll i = 1; i <= 9; ++i) q.push(i);
  while (!q.empty()) {
    t--;
    ll val = q.front(); q.pop();
    if (t == 0) {
      cout << val << endl;
      return 0;
    }
    int d = val % 10;
    if (d-1 >= 0) q.push(val * 10 + d-1);
    q.push(val * 10 + d);
    if (d+1 <= 9) q.push(val * 10 + d+1);
  }
  return 0;
}



Measured memory_bytes: 4756
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

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

    vl a(n);
    rep(i, n) {
        cin >> a[i];
    }

    vvl dp(n+1, vl(n+1));  // dp[i][j] : 区間a[i]～a[j-1]から始めて二人が最適に行動したときのx-yの値
    exrep(len, 1, n) {
        for(ll i = 0; i + len <= n; i++) {
            ll j = i + len;
            // 先手
            if((n - len)%2 == 0) {
                dp[i][j] = max(dp[i+1][j] + a[i], dp[i][j-1] + a[j-1]);
            }
            // 後手
            else {
                dp[i][j] = min(dp[i+1][j] - a[i], dp[i][j-1] - a[j-1]);
            }
        }
    }
    
    out(dp[0][n]);
    re0;
}

Measured memory_bytes: 70784
H, W = map(int, input().split())
S = [input() for i in range(H)]
def minesweeper(Map, px, py):
  cnt = 0
  for i in range(9):
    if i != 4:
      dx, dy = i % 3 - 1, (i // 3) % 3 - 1
      if px + dx >= 0 and py + dy >= 0 and px + dx < len(Map) and py + dy < len(Map[0]):
        if Map[px+dx][py+dy] == '#':
          cnt += 1
  return cnt
for i in range(H):
  for j in range(W):
    if S[i][j] == '.':
      S[i] = S[i][:j] + str(minesweeper(S, i, j)) + S[i][j+1:]
for i in range(H):
  print(S[i])

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

using namespace std;

int main(void) {
    int t;
    while (cin>>t && t) {
        vector<int> s(t);
        for (int i = 0; i < t; i++) cin >> s[i];
        int n;
        cin >> n;
        vector<int> d(101, 24);
        for (int i = 0; i < n; i++) {
            int a, b;
            cin >> a >> b;
            a--;
            d[a] = min(d[a], b);
        }
        
        vector<vector<int> > dp(101, vector<int>(t, 101));
        dp[0][0] = 0;
        for (int i = 0; i < 100; i++) {
            for (int j = 0; j < t; j++) {
                if (s[j] <= d[i]) {
                    dp[i+1][(j+1)%t] = min(dp[i+1][(j+1)%t], dp[i][j]);
                    dp[i+1][1] = min(dp[i+1][1], dp[i][j]+1);
                }
                else dp[i+1][1] = min(dp[i+1][1], dp[i][j]+1);
            }
        }
        cout << *min_element(dp[100].begin(), dp[100].end()) << endl;
    }
}

Measured memory_bytes: 3152
#include<bits/stdc++.h>
#define rep(i,a) for(int (i)=0; (i)<(a); (i)++)
#define rrep(i,a) for(int (i)=a-1; (i)>=(0); (i)--)
#define rep2(i,a,b) for(int (i)=(a); (i)<(b); (i)++)
#define MOD 1000000007
#define all(v) v.begin(), v.end()
#define m0(x) memset(x,0,sizeof(x))
typedef long long ll;
using namespace std;

int dp[3050][3050];

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  string s="X",t="Y",a,b; cin >> a >> b;
  s += a; t += b;
  auto n = s.size(), m = t.size();
  m0(dp);
  rep2(i,1,n)rep2(j,1,m){
    if(s[i] == t[j]) 
      dp[i][j] = dp[i-1][j-1] + 1;
    else 
      dp[i][j] = max(dp[i-1][j],dp[i][j-1]);
  }
  string ans = "";
  int snow = n-1, tnow = m-1, l = dp[n-1][m-1];
  while(1){
     if(s[snow] == t[tnow]){
       ans += s[snow];
       snow--; tnow--; l--;
     }else if(dp[snow][tnow] == dp[snow-1][tnow] && snow > 0) snow--;
     else if(tnow > 0) tnow--;
     if(l == 0) break;
  }
  reverse(all(ans));
  cout << ans;
      
  return 0;
}

Measured memory_bytes: 36608
import sys
def input(): return sys.stdin.readline().rstrip()
import numpy as np
def main():
    n,k=map(int,input().split())
    P=np.array([int(_) for _ in input().split()])
    PP=(P+1)/2
    PP_cum=np.cumsum(PP)
    PP_cum=np.insert(PP_cum,0,0)
    print(np.max(PP_cum[k:]-PP_cum[:n-k+1]))

if __name__=='__main__':
    main()

Measured memory_bytes: 34212
alp = [0 for i in range(26)]
while(True):
    try:
        s = input()
        for i in range(len(s)):
            if s[i].isalpha():
                alp[ord(s[i].lower())-97] = alp[ord(s[i].lower())-97] + 1
    except EOFError:
        break
for i in range(97,97+26):
    print(chr(i),":",alp[i-97])


Measured memory_bytes: 5568
#include <iostream>
#include <algorithm>
#include <queue>
#include <iomanip>

using namespace std;

const int N = 2e5 + 5;
long long freq[N];
long long a[N];

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  long long total = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    freq[a[i]]++;
  }
  for (int i = 1; i <= n; i++) {
    total += freq[i] * (freq[i] - 1) / 2;
  }
  long long org = total;
  for (int i = 0; i < n; i++) {
    long long kolo = freq[a[i]] * (freq[a[i]] - 1) / 2;
    total -= kolo;
    freq[a[i]]--;
    total += freq[a[i]] * (freq[a[i]] - 1) / 2;

    cout << total << '\n';
    total = org;
    freq[a[i]]++;
  }

  return 0;
}


Measured memory_bytes: 4736
import sys
sys.setrecursionlimit(10**7) #再帰関数の上限,10**5以上の場合python
import math
from copy import copy, deepcopy
from copy import deepcopy as dcp
from operator import itemgetter
from bisect import bisect_left, bisect, bisect_right#2分探索
#bisect_left(l,x), bisect(l,x)#aはソート済みである必要あり。aの中からx未満の要素数を返す。rightだと以下
from collections import deque, defaultdict
#deque(l), pop(), append(x), popleft(), appendleft(x)
#q.rotate(n)で → にn回ローテート
from collections import Counter#文字列を個数カウント辞書に、
#S=Counter(l),S.most_common(x),S.keys(),S.values(),S.items()
from itertools import accumulate,combinations,permutations,product#累積和
#list(accumulate(l))
from heapq import heapify,heappop,heappush
#heapify(q),heappush(q,a),heappop(q) #q=heapify(q)としないこと、返り値はNone
from functools import reduce,lru_cache#pypyでもうごく
#@lru_cache(maxsize = None)#maxsizeは保存するデータ数の最大値、2**nが最も高効率
from decimal import Decimal

def input(): 
    x=sys.stdin.readline()
    return x[:-1] if x[-1]=="\n" else x
def printe(*x):print("## ",*x,file=sys.stderr)
def printl(li): _=print(*li, sep="\n") if li else None
def argsort(s, return_sorted=False): 
    inds=sorted(range(len(s)), key=lambda k: s[k])
    if return_sorted: return inds, [s[i] for i in inds]
    return inds
def alp2num(c,cap=False): return ord(c)-97 if not cap else ord(c)-65
def num2alp(i,cap=False): return chr(i+97) if not cap else chr(i+65)
def matmat(A,B):
    K,N,M=len(B),len(A),len(B[0])
    return [[sum([(A[i][k]*B[k][j]) for k in range(K)]) for j in range(M)] for i in range(N)]
def matvec(M,v):
    N,size=len(v),len(M)
    return [sum([M[i][j]*v[j] for j in range(N)]) for i in range(size)]
def T(M):
    n,m=len(M),len(M[0])
    return [[M[j][i] for j in range(n)] for i in range(m)]
def binr(x): return bin(x)[2:]
def bitcount(x): #xは64bit整数
    x= x - ((x >> 1) & 0x5555555555555555)
    x= (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)
    x= (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f 
    x+= (x >> 8); x+= (x >> 16); x+= (x >> 32) 
    return x & 0x7f

def main():
    mod = 1000000007
    #w.sort(key=itemgetter(1),reverse=True)  #二個目の要素で降順並び替え

    N = int(input())
    #N, K = map(int, input().split())
    #A = tuple(map(int, input().split())) #1行ベクトル
    #L = tuple(int(input()) for i in range(N)) #改行ベクトル
    #S = tuple(tuple(map(int, input().split())) for i in range(N)) #改行行列


    if N>=30:
        print('Yes')
    else:
        print('No')



if __name__ == "__main__":
    main()


Measured memory_bytes: 77488
#include<stdio.h>
#define N 100001
int main(){
  int i,j,q,l,r,p[N]={},n[N];
  for(i=2;i<N;i++)p[i]=1;
  for(i=2;i<N;i++)if(p[i])for(j=2;i*j<N;j++)p[i*j]=0;
  n[0]=0;for(i=1;i<N;i++)n[i]=n[i-1]+p[i]*p[(i+1)/2];
  scanf("%d",&q);
  for(i=0;i<q;i++){scanf("%d%d",&l,&r);printf("%d\n",n[r]-n[l-1]);}
}


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

int main(){
  int flag;
  cin>>flag;
  vector<char> forin(flag);
  bool check=false;
  
  for(int i=0;i<flag;i++){
  	cin>>forin.at(i);
  }
  
  for(int f=0;f<flag;f++){
    	if(forin.at(f)=='Y'){
          check=true;
  		}
    }
  if(check==true){
    cout<<"Four"<<endl;
  }else{
    cout<<"Three"<<endl;
  }

}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
const int INF = 1 << 28;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}

int main() {
    string s;
    cin >> s;
    if (s.size() != 26) {
        set<char> chars;
        for (int i = 0; i < s.size(); ++i) {
            chars.insert(s[i]);
        }
        for (int i = 0; i < 26; ++i) {
            if (chars.count('a' + i) == 0) {
                s += char('a' + i);
                break;
            }
        }
        cout << s << "\n";
    } else {
        int idx = -1;
        for (int i = s.size() - 2; i >= 0; --i) {
            if (s[i] < s[i + 1] + 1) {
                idx = i;
                break;
            }
        }
        if (idx == -1) {
            cout << -1 << "\n";
        } else {
            string t = s.substr(0, idx);
            int idx2 = idx + 1;
            for (int i = idx + 1; i < s.size(); ++i) {
                if (s[idx] < s[i] && s[i] < s[idx2]) {
                    idx2 = i;
                }
            }
            t += s[idx2];
            cout << t << "\n";
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int a[4];
    int min;
    
    for(int i = 0; i < 5; i += 1){
        int n;
        cin >> n;
        a[i] = n;
    }
    
    for(int i = 0; i < 4; i += 1){
        int n = a[i] % 10;
        n = n == 0 ? 10: n;
        int m = a[i + 1] % 10;
        m = m == 0 ? 10: m;
        if(n < m){
            int temp= a[i];
            a[i] = a[i+1];
            a[i+1] = temp;
        }
    }
    int i = 0;
    int total = 0;
    while(i < 4){
        int n = a[i] % 10;
        n = n == 0 ? 0 : 10 - n; 
        total += n + a[i];
        i += 1;
    }
    total += a[4];
    cout << total << "\n";
}


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

using namespace std;

const int inf = 0x3f3f3f3f;


char str[2000001], s[2000001];
pair<int, int> d[2000001][4];
priority_queue<pair<pair<int, int>, pair<pair<int, int>, int> > > q;

int D[4][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};
int n, m, K;
int sx, sy, tx, ty;

int _(int x, int y) {
	return (x - 1) * m + y;
}
int main( ) {
	scanf("%d %d %d", &n, &m, &K);
	scanf("%d %d %d %d", &sx, &sy, &tx, &ty);
	for (int i = 1; i <= n; i ++) {
		scanf("%s", str + 1);
		for (int j = 1; j <= m; j ++) {
			s[_(i, j)] = str[j];
			for (int r = 0; r < 4; ++ r) {
				d[_(i, j)][r] = make_pair(inf, inf);
			}
		}
	}
	for (int i = 0; i < 4; i ++) {
		d[_(sx, sy)][i] = make_pair(0, 0);
		q.push(make_pair(make_pair(0, 0), make_pair(make_pair(sx, sy), i)));
	}
	while (!q.empty()) {
		pair<pair<int, int>, pair<pair<int, int>, int> > k;
		int x, y, dir;
		while (!q.empty()) {
			k = q.top(); 
			x = k.second.first.first;
			y = k.second.first.second;
			dir = k.second.second;
			k.first.first = -k.first.first;
			k.first.second = -k.first.second;
			if (d[_(x, y)][dir] != k.first) q.pop();
			else break;
		}
		if (q.empty()) break;
		q.pop();
		for (int i = 0; i < 4; i ++) {
			int nx = x + D[i][0];
			int ny = y + D[i][1];
			//if (vis[nx][ny]) continue;
			int cost;
			if (i != dir) {
				int tmpx = k.first.first + (k.first.second == 0 ? 0 : 1);
				int tmpy = 0;

				if (make_pair(tmpx, tmpy) < d[_(x, y)][i]) {
					d[_(x, y)][i] = make_pair(tmpx, tmpy);
					q.push(make_pair(make_pair(-tmpx, -tmpy), make_pair(make_pair(x, y), i)));
				}
			}
			else {
				if (nx < 1 || ny < 1 || nx > n || ny > m) continue;
				if (s[_(nx, ny)] == '@') continue;
				int tmpx = k.first.first;
				int tmpy = k.first.second;
				tmpy ++;
				if (tmpy == K) tmpy = 0, tmpx ++;
				if (make_pair(tmpx, tmpy) < d[_(nx, ny)][i]) {
					d[_(nx, ny)][i] = make_pair(tmpx, tmpy);
					q.push(make_pair(make_pair(-tmpx, -tmpy), make_pair(make_pair(nx, ny), i)));
				}
			}
		}
	}
	int ans = inf;
	for (int i = 0; i < 4; i ++) {
		int xx = d[_(tx, ty)][i].first;
		int yy = d[_(tx, ty)][i].second;
		xx = xx + (yy == 0 ? 0 : 1);
		ans = min(ans, xx);
	}
	if (ans == inf) printf("-1\n");
	else printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 45840
#include <stdio.h>

int main(void){
    int a, b, c;
    int sum = 0;

    scanf("%d%d%d", &a,&b,&c);
    sum = a+b+c;

    if(sum >= 22){
        printf("bust");
    }else{
        printf("win");
    }
    return 0;
}

Measured memory_bytes: 128
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;

int main() {
	int N;
	cin >> N;
	vector<ll> L(N);
	for (int i = 0; i < N; i++) cin >> L[i];
	sort(L.begin(), L.end());
	int ans = 0;
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < i; j++) {
			int cnt = (L.begin() + j) - upper_bound(L.begin(), L.begin() + j, L[i] - L[j]);
			ans += cnt;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for (ll i = 0; i < (n); i++)
typedef pair<int, int> 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(){

  ll s, w;
  cin >> s >> w;
  if(w >= s){
    cout << "unsafe" << endl;
  }else{
    cout << "safe" << endl;
  }


  return 0;
}



Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,n) for(int i=(a); i<(n); i++)
#define all(v) v.begin(), v.end()
#define fi first
#define se second
using namespace std;
using ll = long long;
using P = pair<int ,int>;
const int INF = 1e9;
const int MOD = 1e9+7;


const int MAX = 10000000; // nの最大値を入れておくこと

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

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

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

int main() {

    // 0, 0 => X, Y まで移動
    // nCk mod p

    ll x, y; cin >> x >> y;
    ll n = (x+y) / 3ll;
    if ((x+y) != n * 3ll) cout << 0 << endl;
    else {
        COMinit();
        ll a = ((2ll*x)-y) / 3ll;
        cout << COM(n, a) << endl;
    }
}

Measured memory_bytes: 234624
#include <iostream>
#include <cmath>

int main()
{
	int x;
	std::cin >> x;
	int ans = 1;
	for (int i = 2; i <= x; i++)
	{
		int b = 1, cnt = 0;
		while (b * i <= x)
		{
			b = b * i;
			cnt++;
		}
		if (b > ans && cnt > 1)
			ans = b;
	}
	std::cout << ans << std::endl;
	std::cin >> x;
	return 0;
}


Measured memory_bytes: 256
typedef long unsigned int size_t;
extern int printf (const char *__restrict __format, ...);
extern int scanf (const char *__restrict __format, ...) ;
extern int getchar (void);
extern int putchar (int __c);
int nextInt(){int f=0;char s=0;char c=getchar();while((c<48)||(57<c)){if(c==45){s=1;c=getchar();break;}c=getchar();}while((48<=c)&&(c<=57)){f=f*10+(c-48);c=getchar();}return s?-f:f;}
char nextChar(){char f=0;char s=0;char c=getchar();while((c<48)||(57<c)){if(c==45){s=1;c=getchar();break;}c=getchar();}while((48<=c)&&(c<=57)){f=f*10+(c-48);c=getchar();}return s?-f:f;}
short int nextShort(){short f=0;char s=0;char c=getchar();while((c<48)||(57<c)){if(c==45){s=1;c=getchar();break;}c=getchar();}while((48<=c)&&(c<=57)){f=f*10+(c-48);c=getchar();}return s?-f:f;}
long long int nextLong(){long long int f=0;char s=0;char c=getchar();while((c<48)||(57<c)){if(c==45){s=1;c=getchar();break;}c=getchar();}while((48<=c)&&(c<=57)){f=f*10+(c-48);c=getchar();}return s?-f:f;}
void println(){putchar(10);}
void print(char *f){while(*f){putchar(*f);f++;}}
void printInt(int f){char c[10];if(!f){putchar(48);return;}if(f<0){f=-f;putchar(45);}char i=0;while(f){c[++i]=(f%10)+48;f/=10;}while(i){putchar(c[i--]);}}
void printLong(long long int f){char c[19];if(!f){putchar(48);return;}if(f<0){f=-f;putchar(45);}char i=0;while(f){c[++i]=(f%10)+48;f/=10;}while(i){putchar(c[i--]);}}
int n, q, i;
int l, r;
char s[100001], c;
int a[100001];
int main(void){
 n=nextInt();
 q=nextInt();
 s[0]=getchar();
 for(i=1; i<n; i++){
  s[i]=getchar();
  if(s[i-1]=='A' && s[i]=='C'){a[i]=1;}
  a[i] += a[i-1];
 }
 for(i=0; i<q; i++){
  l=nextInt()-1;
  r=nextInt()-1;
  printInt(a[r]-a[l]); println();
 }
}


Measured memory_bytes: 1280
// C - Coloring Colorfully

#include <bits/stdc++.h>
using namespace std;
#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 _GLIBCXX_DEBUG
const lli INF = 2147483647;
const lli MINF = -2147483648;
const lli LINF = 9223372036854775807;
const lli MOD = 1000000007; //10^9+7
const long double PI = acos(-1);
#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
#define pb push_back
#define ppb pop_back
#define eb emplace_back
#pragma GCC optimize("Ofast")
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vlli = vector<lli>;
using P = pair<lli, lli>;
// vector<P> vp;
// vp.emplace_back(a[i], b[i]);
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;
}
// aよりもbが大きいならばaをbで更新する(更新されたならばtrueを返す)
template <typename T>
bool chmax(T &a, const T &b)
{
  if (a < b)
  {
    a = b; // aをbで更新
    return true;
  }
  return false;
}
// aよりもbが小さいならばaをbで更新する(更新されたならばtrueを返す)
template <typename T>
bool chmin(T &a, const T &b)
{
  if (a > b)
  {
    a = b; // aをbで更新
    return true;
  }
  return false;
}

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  lli a, b, c, h, k, n, w, ans = 0, count = 0;
  string s, t;
  cin >> s;
  vlli d(n);
  rep(i, 0, s.size() - 1)
  {
    if (s[i] == s[i + 1])
    {
      count++;
      if (s[i] == '0')
      {
        s[i + 1] = '1';
      }
      else
      {
        s[i + 1] = '0';
      }
      // cout << s[i] << endl;
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 512
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
	Scanner sc = new Scanner(System.in);
	int x =sc.nextInt();
	int y =sc.nextInt();
	int area =x*y;
	int length =2*(x+y);
	System.out.println(area + " " + length);
	}
}

Measured memory_bytes: 25828
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
  ll n,sum=0;
  cin>>n;
  for(ll i =1;i<=n;i++)
  {
    sum=sum+(i*(n/i)*(n/i+1))/2;
  }
  cout<<sum<<endl;
}

Measured memory_bytes: 3644
#include<bits/stdc++.h>
#define int long long
#define mod 1000000007
#define trace(x) cerr<<#x<<": "<<x<<" "<<endl
#define trace2(x, y) cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z) cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define sa(a,n) for(int i =0 ; i<n ; i++) cin>>a[i]
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define pb push_back
#define inf 2e18
#define scan() int n; cin>>n ; int a[n]; for(int i = 0 ; i<n ; i++) cin>>a[i]
#define print(a,n) for(int i = 0 ; i < n ; i++) cout<<a[i]<<' '
#define mem(a,v) memset(a,v,sizeof(a))
#define pii pair<int,int>
#define mkp make_pair
using namespace std;
#define N 2e5+5


int32_t main(){
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        cout.tie(NULL);
        int n,i;
        cin >> n;
        int b[n+1],a[n+1];
        int ans=0;
        for(i=1; i<n; i++) cin >> b[i];

       a[1]=b[1];
       a[n]=b[n-1];
       for(i=2; i<n; i++){
           a[i]=min(b[i],b[i-1]);
       }
       for(i=1; i<=n; i++){
           ans+=a[i];
       }
       cout << ans << '\n';
}

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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define eb emplace_back

using ll = long long;
using vll = vector<ll>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using P = pair<int, int>;

void Main(){
    int a; cin >> a;
  	cout << a + a*a + a*a*a << endl;
	return;
}

int main(){
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
	return 0;
}

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

int main() {
  int a,b,x;
  cin >> a >> b >> x;
  double pi=3.1415926535;
  double arg;
  if(x<(b*pow(a,2))/2){
    arg=atan((a*pow(b,2))/(2*x))*180/pi;
  }
  else{
    arg=atan((2*(pow(a,2)*b-x))/pow(a,3))*180/pi;
  }
  cout << fixed << setprecision(10) << arg << endl;
}




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

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

    int n, k;
    cin >> n >> k;

    vector<int> v;

    int count = 0;

    for(int i = 0; i < n; i++){
        int h;
        cin >> h;
        v.push_back(h);
    }

    for(int i = 0; i < v.size(); i++){
        if(v[i] >= k){
            count = count + 1;
        }
    }

    cout << count;

}

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

int main (){
    int a, b, c, d, e, f;

    cin >> a >> b;

    c = a+b;
    d = a-b;
    e = a*b;


   cout << max({c, d, e}) << endl;
  
  return 0;
}

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

int main(){
    int n,m,c;
    std::cin>>n>>m>>c;
    std::vector<int> b(m);
    for (int i = 0; i < m; ++i) {
        std::cin>>b[i];
    }
    int ans=0;
    for (int i = 0; i < n; ++i) {
        int score=0;
        for (int j = 0; j < m; ++j) {
            int t;
            std::cin>>t;
            score+=t*b[j];
        }
        if(score+c>0)++ans;
    }
    std::cout<<ans<<std::endl;
    return 0;
}

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

int main() {
  int a, b, c; cin >> a >> b >> c;
  int res = -1;
  for (int iter = 0; iter < 100; ++iter) {
	int q = c % (a + b);
	if (q <= a) {
	  res = c; break;
	}
	c += 60;
  }
  cout << res << endl;
}



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

using namespace std;

int main()
{
  int n;
  cin >> n;
  //part_aとpart_bは後々の処理の簡略化のためにn+1個の要素
  //part_a[0]とpart_b[0]は0とする
  vector<int> a(n), b(n), part_a(n + 1), part_b(n + 1);
  for (auto&& i : a) {
    cin >> i;
  }
  partial_sum(begin(a), end(a), begin(part_a) + 1);
  for (auto&& i : b) {
    cin >> i;
  }
  partial_sum(begin(b), end(b), begin(part_b) + 1);
  
  int ans = 0;
  for (int i = 0; i < n; i++) {
    ans = max(ans, part_a[i + 1] + part_b[n] - part_b[i]);
  }
  cout << ans << "\n";
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <bitset>
#include <string>
#include <numeric>
#include <algorithm>
#include <functional>
#include <iterator>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <complex>
#include <ctime>
typedef long long LL;

const double pi = acos(-1.0);
const long long mod = 1e9 + 7;

using namespace std;


int main() 
{
    int w, d;
    while (scanf("%d %d", &w, &d) && (w || d) ) 
    {
        int h, F[25] = {0}, S[25] = {0};
        for (int i = 0; i < w; i++) 
        {
            scanf("%d", &h);
            F[h]++;
        }
        for (int i = 0; i < d; i++) 
        {
            scanf("%d", &h);
            S[h]++;
        }
        int ans = 0;
        for (int i = 1; i <= 20; i++)
            ans += max(F[i], S[i]) * i;
        printf("%d\n", ans);
    }
    return 0;
}

Measured memory_bytes: 1172
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <cstdint>
#include <sstream>
#include <map>
#include <vector>
#include <queue>
#include <iomanip>

using namespace std;
typedef long long ll;

ll mx,sum,mn=1e8,cnt;
double ans;
int main(){
	ll n,m;
	cin>>n>>m;
	priority_queue <ll> q;
	for(ll i=0; i<n; i++){
		ll a;
		cin>>a;
		q.push(a);
	}
	while(m>0){
		ll b=q.top();
		q.pop();
		q.push(b/2);
		m--;
	}
	while(!q.empty()){
		sum+=q.top();
		q.pop();
	}
	cout<<sum<<endl;
	 
}

Measured memory_bytes: 1400
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ull unsigned long long
#define ff first
#define ss second

template <class T>
void print(vector<T>& v){
    for(T x:v) cout<<x<<" ";
    cout<<"\n";
}
void inp(vector<int>& v, int n){
    for (int i=0; i<n; ++i) scanf("%d", &v[i]);
}


void sol(){
    ll n, x, t;
    cin>>n>>x>>t;
    printf("%lld\n", t*(n/x+(n%x!=0)));
}

int main() {
    // int t;
    // cin>>t;
    // t++;
    // for (int i=1; i<t; ++i){
        // cout<<"Case #"<<i<<": ";
        sol();
    // }
    return 0;
}

Measured memory_bytes: 3764
#include <cmath>
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<set>
#include<tuple>
#include<bitset>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
ll inf = 1000000007;

int main(void) {
	ll n;
	cin >> n;
	ll count = 0;
	for (int i = 1; i <= n; i++) {
		count = 0;
		for (int x = 1; x <= sqrt(2*i)+1; x++) {
			for (int y = 1; y <= sqrt(2*i)+1; y++) {
				if (i - (x * x + x * y + y * y) <2) {
					continue;
				}
				for (int z = 1; z*z+x*z+y*z<=i-(x*x+y*y+x*y); z++) {
					if ((x + y) * (x + y) + (x + z) * (x + z) + (y + z) * (y + z) == 2 * i) {
						count++;
					}
				}
			}
		}
		cout << count << endl;
	}
}

Measured memory_bytes: 3656
#include <bits/stdc++.h>
#include <cstdlib>
#include <cmath>
#include <algorithm>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using Graph= vector<vector<ll>>;
struct edge{ll to ; ll cost ;} ;
using graph =vector<vector<edge>> ;
#define rep(i,n) for (ll i=0; i < (n); ++i)
#define rep2(i,n,m) for(ll i=n;i<=m;i++)
#define rep3(i,n,m) for(ll i=n;i>=m;i--)
#define pb push_back
#define eb emplace_back
#define ppb pop_back
#define mpa make_pair
#define fi first
#define se second 
#define set20 cout<<fixed<<setprecision(20) ;
const ll INF=1e18 ;
inline void chmax(ll& a,ll b){a=max(a,b);}
inline void chmin(ll& a,ll b){a=min(a,b);}
double pi=acos(-1) ;
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(){
  ll h,w,k ; cin>>h>>w>>k ;
  int d[h][w] ;
  rep(i,h){
    rep(j,w){
      char q ;cin>>q ;
      d[i][j]= q- '0' ;
    }
  }

ll bns=INF ;
  for( ll tmp = 0 ; tmp <( 1<<h-1) ; tmp++ ){
     bitset<9> s(tmp) ;
     int sum =0 ;
     rep(i,9) sum+= s[i] ;
     vector<ll> A(sum+1) ;
     ll ans=0 ;
     int ii=0 ;
     rep(xx,3*w){
      
       
       bool ok = 0;
       
       A[0] += d[0][ii] ;
       int j=0 ;
       rep(a,h-1){
        
        if(s[a]==1){
          j++ ;
        }

        A[j] += d[a+1][ii] ;
       } 

       rep(c,sum+1){
         if(A[c]>k) ok=1 ;
       }

       if(ok){
         ans++ ;
         rep(b,sum+1) A[b]=0 ;
         ii-- ;
       }
     
     ii++ ;

     if(ii==w) break ;
     
     if(xx==3*w-1){
       ans =INF-10 ;
     }
     
     }
  
  chmin(bns,ans+sum) ;
  }
  cout<<bns<<endl ;
 return 0 ; 
}



Measured memory_bytes: 3652
import java.util.*;

// ABC 54-D
// https://beta.atcoder.jp/contests/abc054/tasks/abc054_d

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		
		int N = in.nextInt();
		int[] nums = new int[N];
		for (int i = 0; i < N; i++) {
			nums[i] = in.nextInt();
		}
		
		Arrays.sort(nums);
		int answer = 1;
		int pre = nums[0];
		for (int i = 1; i < N; i++) {
			if (pre < nums[i]) {
				answer++;
				pre = nums[i];
			}
			
		}
		System.out.println(answer);
	}
}

Measured memory_bytes: 23764
#include <iostream>
#include<string>
#include<algorithm>
#include<iomanip>
using namespace std;
int main()
{
	int a[5], k;
	for (int i = 0; i < 5; i++)
	{
		cin >> a[i];
	}
	cin >> k;
	int length, ji = 0;
	int flag = 0;
	for (int i = 0; i < 5; i++)
	{
		if (flag == 1)
			break;
		for (int j = i+1; j < 5; j++)
		{
			length = a[j] - a[i];
			if (length > k)
			{
				cout << ":(";
				flag = 1; break;
			}
			else
			{
				ji++;
			}
		}
	}
	if (ji == 10)
	{
		cout << "Yay!" ;
	}
}

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

const long long mod = 1e9 + 7;

struct BinomialCoefficient {
  vector<long long> fac, finv, inv;

  BinomialCoefficient(int N) : fac(N), finv(N), inv(N) {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for ( int i = 2; i < N; i++ ) {
        fac[i] = fac[i-1] * i % mod;
        inv[i] = mod - inv[mod%i] * (mod / i) % mod;
        finv[i] = finv[i-1] * inv[i] % mod;
    }
  }

  long long combination(int n, int k) {
    if ( n < k ) { return 0; }
    if ( n < 0 || k < 0 ) { return 0; }
    return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
  }
};

int main() {
  int n, k;
  cin >> n >> k;
  BinomialCoefficient BC(n+1);

  if ( k > n ) { k = n; }

  long long ans = 0;
  for ( int i = 0; i <= k; i++ ) {
    ans += (BC.combination(n, i) * BC.combination(n-1, i)) % mod;
    ans %= mod;
  }

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


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

template<typename T> struct BIT {
    int max_n;
    vector<T> data;
    const T unit;
    BIT<T>(int n, T u = T(0)) : max_n(n), unit(u) {
        data.assign(max_n + 1, u);
    }
    void add(int i, T x) {
        while ( i <= max_n ) {
            data[i] += x;
            i += i & -i;
        }
    }
    T sum(int i) {
        T s = unit;
        while ( i > 0 ) {
            s += data[i];
            i -= i & -i;
        }
        return s;
    }
};

ll solve() {
    ll N, K, a;
    cin >> N >> K;
    vector<ll> cum(N+1);
    for ( int i = 0; i < N; i++ ) {
        cin >> a;
        cum[i+1] = cum[i] + a - K;
    }

    vector<ll> cp(N+1);
    for ( int i = 0; i <= N; i++ ) cp[i] = cum[i];
    sort(cp.begin(), cp.end());
    cp.erase(unique(cp.begin(), cp.end()), cp.end());
    for ( int i = 0; i <= N; i++ ) {
        cum[i] = lower_bound(cp.begin(), cp.end(), cum[i]) - cp.begin() + 1;
    }

    ll ans = 0;
    BIT<ll> b(N+1);
    for ( int i = 0; i <= N; i++ ) {
        ans += b.sum(cum[i]);
        b.add(cum[i], 1);
    }
    return ans;
}

int main() {
    auto ans = solve();
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 4992
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(v) v.begin(),v.end()
#define zeros(arr) memset(arr,0,sizeof(arr))
#define precise(num)  cout<<fixed; cout << std::setprecision(num)
int32_t main(){
    
    ios_base::sync_with_stdio(cin.tie(NULL));
    cout.tie(NULL);
    
    int tc = 1;
    // cin>>tc;
    while(tc -- ){
        
        vector< string >v;
        
        string p = "a";
        v.pb(p);
        int n;
        cin>>n;
        
        int curr = 'a';
        
        // vector< char >pos;
        // pos.pb(curr);
        vector< string>final;
        for(int i = 1 ;i < n ; i++ ){
            
            int sz =v.size(); 
            curr++;
            // pos.pb(curr);
            for(int j = 0; j < sz; j++ )
            {
                    vector< char > pos;
                    map<char,int>cn;
                    char p = 'a';
                    for(int k = 0; k < v[j].size() ; k ++ )
                        {
                            cn[v[j][k]]++;
                            p = max(p , v[j][k]);
                            if(cn[v[j][k]]==1)
                            pos.pb(v[j][k]);
                        }
                        pos.pb(p+1);
                    
                    for(int k = 0 ; k <pos.size() ; k++)
                        {
                            string  res = v[j] + pos[k];
                            
                            
                            v.pb(res);
                        
                            // if(i == n-1)
                            //     final.pb(res);
                        }
                        
            }
            
        }
        unordered_map<string , int > cn;
        for(int i = 0; i < v.size() ; i++ )
        {
            cn[v[i]]++;
            if(v[i].size() == n && cn[v[i]] == 1)
                final.pb(v[i]);
        }
        
        
        sort(all(final));
        
        for(int i =0 ; i< final.size() ; i ++ ){
            cout<<final[i]<<endl;
        }
        // if( n == 1)cout<<'a'<<endl;
        
        
    }
    
}

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

int main()
{
    long long n;
    cin >> n;
    vector<int> a(n);
    vector<long long> suma(n + 1, 0);
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    
    sort(a.begin(), a.end());

    for (int i = 0; i < n; i++)
    {
        suma[i + 1] = suma[i] + a[i];
    }

    long long ans = 0;
    for (int i = 1; i < n; i++)
    {
        if(2 * suma[i] < a[i])ans = i;
    }
    
    cout << n - ans << endl;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h> // Replace needed headers for speed up

// -------------8<------- start of library -------8<------------------------
template<typename T>
struct RangeMinimumQuery {
    const T INF;
    int n;
    std::vector<T> val;

    RangeMinimumQuery(int size, T inf = std::numeric_limits<T>::max()) : INF(inf) {
        for (n = 1; n < size; ) n <<= 1;
        val.assign(2 * n + 1, INF);
    }
    void update(int idx, T v) {
        idx += n - 1;
        val[idx] = v;
        while (idx > 0) {
            idx = (idx - 1) >> 1;
            val[idx] = std::min(val[idx * 2 + 1], val[idx * 2 + 2]);
        }
    }
    T find(int l, int r) {
        T res = INF;
        l += n - 1; r += n - 1;
        while (l < r) {
            if ((l & 1) == 0) res = std::min(res, val[l]);
            if ((r & 1) == 0) res = std::min(res, val[r - 1]);
            l >>= 1;
            r = (r - 1) >> 1;
        }
        return res;
    }
};

// -------------8<------- end of library ---------8-------------------------
int main() {
    int n, q;
    std::cin >> n >> q;

    RangeMinimumQuery<int> rmq(n);
    for (int i = 0, com, x, y; i < q; ++i) {
        std::cin >> com >> x >> y;
        if (com == 0) rmq.update(x, y);
        else std::cout << rmq.find(x, y + 1) << '\n';
    }

    return 0;
}



Measured memory_bytes: 3844
#include <iostream>
#include <vector>
#include <deque>
using namespace std;

int main(){
    int K;
    cin >> K;
    vector<bool> vis(K, false);
    deque<pair<int, int>> dq;
    dq.push_back(make_pair(1, 1));
    while(!dq.empty()){
        auto p = dq.front();
        dq.pop_front();
        int x = p.first;
        int d = p.second;
        if(vis[x]) continue;
        vis[x] = true;
        if(x == 0){
            cout << d << endl;
            return 0;
        }
        if(x % 10 != 9)
            dq.push_back(make_pair((x+1)%K, d+1));
        dq.push_front(make_pair((10*x)%K, d));
    }
    return 0;
}


Measured memory_bytes: 1024
import math

A, B, C, X, Y = map(int, input().split())

min_sum = A*X+B*Y
for c in range(0, (max(X, Y)*2)+1, 2):
    s = (max(X-math.floor(c/2), 0))*A + (max(Y-math.floor(c/2), 0))*B + c*C
    if s < min_sum:
        min_sum = s
print(min_sum)


Measured memory_bytes: 9068
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;


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

	int a, b;
	cin >> a >> b;
	cout << 6 - a - b << "\n";

	return 0;
}



Measured memory_bytes: 384
#include <algorithm>
#include <bitset>
#include <iomanip>
#include <iostream>
#include <queue>
#include <vector>
#define int long long
using namespace std;

struct Edge {
  int dst, id;
  Edge(const int dst = 0, const int id = 0) : dst(dst), id(id) {}
};

using Edges = vector<Edge>;
using Graph = vector<Edges>;

string itos(int i) {
  ostringstream os;
  os << setfill('0') << setw(3) << i;
  return os.str();
}

int compose(int p, int q) { // 置換の合成
  string s = itos(p), t = itos(q), r = "   ";
  for (int i = 0; i < 3; i++) r[i] = t[s[i] - '0'];
  return stoi(r);
}

int prms[] = {12, 21, 102, 120, 201, 210};

signed main() {
  int n;
  cin >> n;
  vector<int> prm(n);
  for (int i = 0; i < n; i++) { // 各あみだくじを置換に変換
    int w;
    cin >> w;
    vector<int> q(w);
    for (int j = 0; j < w; j++) cin >> q[j];
    string v = "012";
    for (int j = w - 1; j >= 0; j--) swap(v[q[j]], v[q[j] + 1]);
    prm[i] = stoi(v);
  }

  Graph g(211); // 頂点を置換, 辺を置換とするグラフ
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 6; j++) {
      int u = prms[j], v = compose(prms[j], prm[i]);
      g[u].emplace_back(v, i);
    }
  }

  // ここから恒等置換から恒等置換への閉路を検出
  vector<bool> used(211, false);
  queue<pair<int, int>> q; // 頂点, 使用した置換(あみだくじ)をbitで持つ
  q.emplace(12, 0);
  bool cycle = false;
  while (q.size()) {
    int v, b;
    tie(v, b) = q.front();
    q.pop();
    if (used[v]) continue;
    used[v] = true;
    for (auto &e : g[v]) {
      if ((b >> e.id) & 1LL) continue;
      if (e.dst == 12) cycle = true;
      q.emplace(e.dst, b | (1LL << e.id));
    }
  }

  cout << (cycle ? "yes" : "no") << endl;
}



Measured memory_bytes: 3240
N = int(input())
L = list(map(int, input().split()))

ans = 0
for i in range(len(L) - 1):
    if L[i] - L[i + 1] >= 0:
        ans = ans + L[i] - L[i + 1]
        L[i + 1] = L[i]

print(ans)

Measured memory_bytes: 32420
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
using namespace std;

int N, Q;
string s;

int main() {
    cin >> N >> Q >> s;
    vector<char> t(Q), d(Q);
    for (int i = 1; i < Q + 1; i++) {
        cin >> t[Q - i] >> d[Q - i];
    }
    int left = 0, right = N - 1;
    for (int i = 0; i < Q; i++) {
        if (t[i] == s[left] && d[i] == 'L') {
            left++;
            if (left > N - 1) break;
        } else if (left > 0 && t[i] == s[left - 1] && d[i] == 'R') {
            left--;
        }
        
        if (t[i] == s[right] && d[i] == 'R') {
            right--;
            if (right < 0) break;
        } else if (right < N - 1 && t[i] == s[right + 1] && d[i] == 'L') {
            right++;
        }
    }
    cout << max(right - left + 1, 0) << endl;
}


Measured memory_bytes: 900
// clang-format off
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define main signed main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979;
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
bool odd(const int &n) { return n & 1; }
bool even(const int &n) { return ~n & 1; }
template<typename T = int> T in() { T x; cin >> x; return x; }
template<typename T = int> T in(T &&x) { T z(forward<T>(x)); cin >> z; return z; }
template<typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &x : v) is >> x; return is; }
template<typename A, typename B> istream &operator>>(istream &is, pair<A, B> &p) { return is >> p.first >> p.second; }
template<typename T> ostream &operator<<(ostream &os, const vector<vector<T>> &v) { int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "" : "\n"); return os; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &v) { int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "" : " "); return os; }
template<typename A, typename B> ostream &operator<<(ostream &os, const pair<A, B> &p) { return os << p.first << ' ' << p.second; }
template<typename Head, typename Value> auto vectors(const Head &head, const Value &v) { return vector<Value>(head, v); }
template<typename Head, typename... Tail> auto vectors(Head x, Tail... tail) { auto inner = vectors(tail...); return vector<decltype(inner)>(x, inner); }
// clang-format on

main {
  while (true) {
    string s;
    cin >> s;
    if (s == ".") break;
    vector<int> v(3);
    function<int(int &)> dfs = [&](int &i) -> int {
      if (s[i] == '(') {
        i++;
        int e = dfs(i);
        if (s[i] == '+') {
          i++;
          cmax(e, dfs(i));
        }
        if (s[i] == '*') {
          i++;
          cmin(e, dfs(i));
        }
        i++; // ')'
        return e;
      }
      if (s[i] == '-') {
        i++;
        return 2 - dfs(i);
      }
      if (isdigit(s[i])) return s[i++] - '0';
      return v[s[i++] - 'P'];
    };
    int cnt = 0;
    for (v[0] = 0; v[0] < 3; v[0]++) {
      for (v[1] = 0; v[1] < 3; v[1]++) {
        for (v[2] = 0; v[2] < 3; v[2]++) {
          int i = 0;
          cnt += dfs(i) == 2;
        }
      }
    }
    cout << cnt << endl;
  }
}



Measured memory_bytes: 3140
#include <bits/stdc++.h>
using namespace std;
int n, d; string s;
int main() {
	cin >> n;
	bool ok = true;
	while(n--) {
		cin >> s;
		if(s == "A") d++;
		else d--;
		if(d < 0) ok = false;
	}
	if(d != 0) ok = false;
	cout << (ok ? "YES" : "NO") << endl;
	return 0;
}

Measured memory_bytes: 3136