akhauriyash/Code-Regression huggingface dataset:
#include <cstddef>
#include <cstdint>
#include <vector>

namespace null_null {

using i32 = std::int_fast32_t;
using i64 = std::int_fast64_t;
using u32 = std::uint_fast32_t;
using u64 = std::uint_fast64_t;
using usize = std::size_t;

constexpr usize operator"" _z(unsigned long long x) noexcept {
  return static_cast<usize>(x);
}

template <typename T>
std::vector<T> make_v(usize a) { return std::vector<T>(a); }
template <typename T, typename... Ts>
auto make_v(usize a, Ts... ts) {
  return std::vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}

template <typename T, typename V>
typename std::enable_if<std::is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }
template <typename T, typename V>
typename std ::enable_if<std::is_class<T>::value != 0>::type
fill_v(T &t, const V &v) {
  for (auto &e : t) fill_v(e, v);
}

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

} // namespace null_null

#include <algorithm>
#include <iomanip>
#include <iostream>
#include <utility>

namespace null_null {

void main_() {
  usize N;
  std::cin >> N;
  std::vector<double> A(N);
  for (usize i = 0; i < N; i++) std::cin >> A[i];
  double sum = 0;
  for (usize i = 0; i < N; i++) sum += 1 / A[i];
  std::cout << 1 / sum << std::endl;
}

} // namespace null_null

int main() {
  null_null::main_();
  return 0;
}


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

if (400 <= x <= 599):
    print(8)
elif (600 <= x <= 799):
    print(7)
elif (800 <= x <= 999):
    print(6)
elif (1000 <= x <= 1199):
    print(5)
elif (1200 <= x <= 1399):
    print(4)
elif (1400 <= x <= 1599):
    print(3)
elif (1600 <= x <= 1799):
    print(2)
elif (1800 <= x <= 1999):
    print(1)


Measured memory_bytes: 9188
// E - Yutori
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)

int main(){
	int N,K,C; string S;
	cin>>N>>K>>C>>S;

	vector<int> L(N,-1), R(N,-1);

	int l_c, r_c, l_pos, r_pos;
	l_c = r_c = l_pos = r_pos = 0;

	rep(l, N){
		if(l_c > 0) l_c--;
		else{
			l_c = 0;
			if(S[l] == 'o'){ L[l_pos++] = l; l_c = C; }
		}

		if(r_c > 0) r_c--;
		else{
			int r = N - l - 1;
			if(S[r] == 'o'){ R[r_pos++] = r; r_c = C; }
		}
	}

	reverse(R.begin(), R.begin() + r_pos);

	if(l_pos > K) return 0; // 働ける日に余裕があると、その日に必ず働く必要がない
	rep(i, l_pos) if(L[i] == R[i]) cout<< L[i] + 1 <<endl;
}

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

int main() {
  int w, h, n;
  cin>>w>>h>>n;
  bool white[h][w];
  for (int i=0; i<h; i++) {
    for (int j=0; j<w; j++) {
      white[i][j] = true;
    }
  }
  for (int k=0; k<n; k++) {
    int x, y, a;
    cin>>x>>y>>a;
    int sx, sy, ex, ey;
    if (a == 1) {
      sx = 0;
      ex = x;
      sy = 0;
      ey = h;
    } else if (a == 2) {
      sx = x;
      ex = w;
      sy = 0;
      ey = h;
    } else if (a == 3) {
      sx = 0;
      ex = w;
      sy = 0;
      ey = y;
    } else {
      sx = 0;
      ex = w;
      sy = y;
      ey = h;
    }
    for (int i=sy; i<ey; i++) {
      for (int j=sx; j<ex; j++) {
        white[i][j] = false;
      }
    }
  }
  int cnt = 0;
  for (int i=0; i<h; i++) {
    for (int j=0; j<w; j++) {
      if (white[i][j]) {
        ++cnt;
      }
    }
  }
  cout<<cnt<<endl;
}

Measured memory_bytes: 256
import sys
import bisect
input = sys.stdin.readline

a,b,q = map(int,input().split())

ans = 10**100

s = [-ans] + [int(input()) for i in range(a)] + [ans]
t = [-ans] + [int(input()) for i in range(b)] + [ans]
x = [int(input()) for i in range(q)]


ans = 10**100

for i in range(q):
    ans = 10**100
    s_idx = bisect.bisect_left(s,x[i])
    t_idx = bisect.bisect_left(t,x[i])
    s_idx -= 1
    t_idx -= 1
    #print(x[i],s_idx,t_idx)
    for j in s[s_idx+0],s[s_idx+1]:
        for k in t[t_idx+0],t[t_idx+1]:
            ans = min(ans,abs(x[i] - j) + abs(j - k),abs(x[i] - k) + abs(j - k))
            
    print(ans)  

Measured memory_bytes: 17664
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;

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

    int c[10][10];
    for (int i = 0; i < 10; i++) {
        for (int j = 0; j < 10; j++) {
            cin >> c[i][j];
        }
    }

    for (int k = 0; k < 10; k++)
        for (int i = 0; i < 10; i++)
            for (int j = 0; j < 10; j++)
                c[i][j] = min(c[i][j], c[i][k] + c[k][j]);

    int r = 0;
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            int a;
            cin >> a;

            if (a >= 0) r += c[a][1];
        }
    }

    cout << r << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
using namespace std;
int main(){
	int a,b;
	int d,r;
	double f;
	cin >> a >> b;
	d=(int)a/b;
	r=a%b;
	f=((double)a)/b;
	printf("%d %d %.5f\n",a/b,a%b,(double)a/b);
	return 0;
}

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

using namespace std;


#define MAXN 52
int dx[8] = {1,  1,  0, -1, -1, -1,  0,  1};
int dy[8] = {0, -1, -1, -1,  0,  1,  1,  1};
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int h, w, a[MAXN][MAXN];
  cin >> h >> w;
  for (int i = 1; i <= h; ++i) {
    string s;
    cin >> s;
    for (int j = 0; j < w; ++j) {
      a[i][j+1] = s[j]=='#' ? -1 : 0;
    }
  }
  for (int i = 1; i <= h; ++i) {
    for (int j = 1; j <= w; ++j) {
      if (a[i][j]==-1) {
        for (int di = 0; di < 8; ++di) {
          int I = i+dy[di];
          int J = j+dx[di];
          if (a[I][J]==-1) continue;
          a[I][J]++;
        }
      }
    }
  }
  for (int i = 1; i <= h; ++i) {
    for (int j = 1; j <= w; ++j) {
      if (a[i][j]==-1) cout << "#";
      else cout << a[i][j];
    }
    cout << endl;
  }
  return 0;
}


Measured memory_bytes: 256
use std::io::stdin;

fn main() {
    let mut s = String::new();
    stdin().read_line(&mut s).unwrap();
    
    let xy = s.trim().split(" ").map(|s| s.parse().unwrap()).collect::<Vec<u64>>();
    println!("{}", xy[0] + xy[1] / 2);
}

Measured memory_bytes: 4352
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <math.h>
using namespace std;
bool m[51][51];
bool c[51];
int n,M;

void dfs(int a){
  c[a]=1;
  for(int i=1;i<=n;i++){
    if(m[a][i]==0) continue;
    if(c[i]==0) dfs(i);
  }
}

int main(){
  cin>>n>>M;
  int a[M],b[M],ans=0;
  for(int i=0;i<M;i++){
    cin>>a[i]>>b[i];
    m[a[i]][b[i]]=1;
    m[b[i]][a[i]]=1;
  }
  for(int i=0;i<M;i++){
    for(int j=1;j<=n;j++) c[j]=0;
    m[a[i]][b[i]]=0;
    m[b[i]][a[i]]=0;
    dfs(1);
    int tmp=0;

    for(int i=1;i<=n;i++){
      if(c[i]==1) tmp++;
    }
    if(tmp!=n) ans++;
    m[a[i]][b[i]]=1;
    m[b[i]][a[i]]=1;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
import sys

def main():
    #inputs = [5, 3, 2, 4, 1]
    #inputslen = len(inputs) - 1

    inputslen = int(sys.stdin.readline().rstrip())
    inputs= sys.stdin.readline()

    sortvalue = [int(i) for i in inputs.split()]
    flag = 1
    count = 0
    while flag:
        flag = 0
        for i in range(1, inputslen):
            j = inputslen - i
            compvalue = sortvalue[j]
            if compvalue < sortvalue[j-1]:
                sortvalue[j] = sortvalue[j-1]
                sortvalue[j-1] = compvalue
                flag = 1
                count += 1

    printvalue = map(str, sortvalue)
    print(' '.join(printvalue))
    print(count)

if __name__ == '__main__':
    main()


Measured memory_bytes: 5608
# sys.stdin.readline
import sys

input = sys.stdin.readline


class AtCoder:
    def main(self):
        N, C, K = map(int, input().split())
        T = [int(input()) for _ in range(N)]

        T.sort()
        bus = 1
        p = 1
        start = T[0]
        for i in range(1, N):
            p += 1
            if T[i] > K + start or p > C:
                bus += 1
                p = 1
                start = T[i]

        print(bus)


# Run main
if __name__ == '__main__':
    AtCoder().main()

Measured memory_bytes: 43996
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(n) begin(n), end(n)
using ll = long long;
using namespace std;

int main(){
	string s;
	cin >> s;
	int fr = 0, re = s.size()-1;
	int ans = 0;
	while(1){
		if(fr >= re) break;
		char f = s[fr], r = s[re];
		if(f != r){
			ans++;
			if(f != 'x' && r != 'x'){
				ans = -1;
				break;
			}else if(f != 'x'){
				re--;
			}else{
				fr++;
			}
		}else{
			fr++;
			re--;
		}
	}
	cout << ans << endl;
	return 0;
}

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

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

    int need_l = 0;
    int p = 0;
    for (int i = 0; i < N; i++) {
        if (S.at(i) == '(') p++;
        else {
            if (p == 0) need_l++;
            else p--;
        }
    }
    int need_r = p;

    string res = "";
    for (int i = 0; i < need_l; i++) res += '(';
    res += S;
    for (int i = 0; i < need_r; ++i) res += ')';
    cout << res << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
int main()
{
  int x,y,a;
  scanf("%d%d",&x,&y);
  while(x != 0 || y != 0){
    if(x>y){a=y,y=x,x=a;}
    printf("%d %d\n",x,y);
    scanf("%d%d",&x,&y);
  }
  return 0;
}

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

int main() {
  string d;
  cin>>d;
  
  if (d=="A")
    cout<<"T"<<endl;
  
  if (d=="T")
    cout<<"A"<<endl;
  
  if(d=="C")
    cout<<"G"<<endl;
  
  if (d=="G")
    cout<<"C"<<endl;
}


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

bitset<16010> bx, by;
char s[100100];
int sx, sy;
vector<int> x, y;

int main(void) {
	scanf("%s%d%d", s, &sx, &sy);
	int n = strlen(s);
	int cnt = 0, p = 1;
	for(int i = 0; i < n; i++) {
		if(s[i] == 'F') cnt++;
		else {
			(p ? x : y).push_back(cnt);
			p ^= 1;
			cnt = 0;
		}
	}
	(p ? x : y).push_back(cnt);	
	sx -= x[0];	
	if(sx < -8000) return puts("No") * 0;
	bx[8001] = 1;
	for(int i = 1; i < x.size(); i++) 
		bx = (bx << x[i]) | (bx >> x[i]);
	if(!bx[sx + 8001]) return puts("No") * 0;

	by[8001] = 1;
	for(int i = 0; i < y.size(); i++)
		by = (by << y[i]) | (by >> y[i]);
	if(!by[sy + 8001]) return puts("No") * 0;
	puts("Yes");
	return 0;
	
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
const int MOD=1000000007;
const int INF=1000000000;
using namespace std;
typedef long long ll;
typedef tuple<ll,int,int> tup;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int,int> pii;
typedef vector<pair<int,int> > vp;
bool visited[100005];
vp g[100005];
int colors[100005];

void dfs(int s)
{
  visited[s]=true;
  for(int i=0;i<int(g[s].size());i++)
    {
      int to=g[s][i].first;
      int len=g[s][i].second;
      if(visited[to]) continue;
      else
	{
	  if(len%2==0)
	    {
	      colors[to]=colors[s];
	      dfs(to);
	    }
	  else
	    {
	      colors[to]=(colors[s]+1)%2;
	      dfs(to);
	    }
	}
    }
}

int main(int argc,char const* argv[])
{
  int N;
  memset(visited,false,sizeof(visited));
  colors[1]=0;
  cin >> N;
  for(int i=0;i<N-1;i++)
    {
      int u,v,w;
      cin >> u >> v >> w;
      g[u].push_back(pii(v,w));
      g[v].push_back(pii(u,w));
    }
  dfs(1);
  for(int i=1;i<=N;i++)
    {
      cout << colors[i] << endl;
    }
  return 0;
}


Measured memory_bytes: 8448
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using P = pair<int, int>;
#define debug(var) cerr << "[" << #var << "] " << var << endl
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
const ll mod = 1000000007;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,-1,0,1};


int main(){
    int n;
    cin >> n;
    string ans = "No";
    rep(i, 25) rep(j, 25) {
        if (4*i+7*j==n) ans = "Yes";
    }
    
    cout << ans << endl;
    return 0;
}


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


using namespace std;
struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

template<class T> inline bool chmin(T& a, T b) {
  //aの方が大きければbに値を更新、そうでなければ何もしない
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
bool compare_a_big(pair<int,int> l,pair<int,int> r){
  //firstが大きい方からソート、firstが同じならbが小さい方から
  if(l.first != r.first){
    return l.first>r.first;
  }
  else{
    return l.second < r.second;
  }
}
bool compare_a_b_big(pair<int,int> l,pair<int,int> r){
  //firstが大きい方からソート、firstが同じならbが大きい方から
  if(l.first != r.first){
    return l.first>r.first;
  }
  else{
    return l.second > r.second;
  }
}
bool compare_b_small(pair<int,int> l,pair<int,int> r){
  //secondが小さい方からソート、firstが同じならfirstが小さい方から
  if(l.second != r.second){
    return l.second<r.second;
  }
  else{
    return l.first < r.first;
  }
}
const int INF = 1e9;
const int M = 1000000007;


typedef long long int ll;
vector<ll> fac(3001); //n!(mod M)
vector<ll> ifac(3001); //k!^{M-2} (mod M)
//a,bの範囲的にこれだけ配列を用意していけば十分

ll mpow(ll x, ll n){ //x^n(mod M) ←普通にpow(x,n)では溢れてしまうため，随時mod計算
    ll ans = 1;
    while(n != 0){
        if(n&1) ans = ans*x % M;
        x = x*x % M;
        n = n >> 1;
    }
    return ans;
}

ll comb(ll a, ll b){ //aCbをmod計算、a,b<=300000でないと使えない
    fac[0] = 1;
    ifac[0] = 1;
    for(ll i = 0; i<3000; i++){
        fac[i+1] = fac[i]*(i+1) % M; // n!(mod M)
        ifac[i+1] = ifac[i]*mpow(i+1, M-2) % M; // k!^{M-2} (mod M) ←累乗にmpowを採用
    }
    if(a == 0 && b == 0)return 1;
    if(a < b || a < 0)return 0;
    ll tmp = ifac[a-b]* ifac[b] % M;
    return tmp * fac[a] % M;
}

typedef long long int ll;

int pow(int a,int b){
  if(b==0) return 1;
  else{
    return a*pow(a,b-1);

  }
}

typedef struct ListNode {
    int data;
    struct ListNode *next;
} ListNode;



int main(){
  long long int a,b,c,d;
  cin >> a >> b >> c >> d;
  long long int array[4] = {a*c,b*c,a*d,b*d};
  long long int max = a*c;
  for(int i=0;i<4;i++){
  if(array[i] >= max){
    max = array[i];
  }
  }


  cout << max << endl;






}


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

int main(){
  int n;
  cin >> n;
  
  int ans = 0;
  int color[n+5];
  for(int i=0; i<n; i++) cin >> color[i];

  int l = 0, r = 0;
  while(l < n){
    while(r+1 < n && color[l] == color[r+1]) r++;
    ans += (r-l+1)/2;
    l = r+1;
    r = l;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main() {
    int a, b;
    scanf("%d %d", &a, &b);

    if(a > b){
        if (b != 1)
            printf("Alice\n");
        else
            printf("Bob\n");
    }

    if(b > a){
        if(a != 1)
            printf("Bob\n");
        else
            printf("Alice\n");
    }
    if (a == b)
        printf("Draw\n");

    return 0;
}


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

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = Integer.parseInt(sc.next());
		int B = Integer.parseInt(sc.next());
		int C = Integer.parseInt(sc.next());
		sc.close();
		int[] array = {A,B,C};
		Arrays.sort(array);
		int min = array[0];
		int mid = array[1];
		int max = array[2];
		int cnt = 0;
		cnt += max - mid;
		if((max-(min+cnt))%2==0) {
			cnt += (max-(min+cnt))/2;
		}else {
			cnt += ((max+1)-(min+cnt))/2+1;
		}
		System.out.println(cnt);
	}
}

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

int n, w;
int num[20];

int main(){
  while(cin>>n>>w, !(n==0&&w==0)){
    int num_d=0, max_h=0;
    memset(num, 0, sizeof(num));
    while(n--){
      int tmp;
      cin>>tmp;
      num[tmp/w]++;
      if(max_h<num[tmp/w])max_h=num[tmp/w];
      if(num_d<tmp/w+1)num_d=tmp/w+1;
    }
    double ans=0.0;
    for(int i=0; i<num_d; i++){
      ans+=((double)num[i]/(double)max_h)*((double)(num_d-1-i)/(double)(num_d-1));
    }
    ans+=0.01;
    printf("%.10f\n", ans);
  }
  return 0;
}

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

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef pair<ll, ll> P;


#define rep(a,n) for(int a = 0;a < n;a++)


int main(void)
{
	ll n, k;
	cin >> n >> k;
	vector<ll> vs(n);
	rep(i, n) cin >> vs[i];
	ll u = min(n, k);
	ll c = 0;
	for (int i = 0; i <= u; i++) {
		for (int j = 0; j <= u - i; j++) {
			vector<ll> buffer;
			if (i + j > n) continue;
			rep(t, i) buffer.push_back(vs[t]);
			rep(t, j) buffer.push_back(vs[n-1-t]);
			sort(buffer.begin(), buffer.end());
			ll remove = k - i - j;
			ll sum = 0;
			for (int t = 0; t < buffer.size(); t++) {
				sum += buffer[t];
			}
			for (int t = 0; t < min((ll)buffer.size(), remove); t++) {
				if (buffer[t] < 0) {
					sum -= buffer[t];
				}
			}
			c = max(c, sum);
		}
	}
	cout << c << endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
	int n;
	scanf("%d",&n);
	int v[n],c[n];
	for(int i=0;i<n;i++)scanf("%d",&v[i]);
	for(int i=0;i<n;i++)scanf("%d",&c[i]);
	int ans=0;
	for(int i=0;i<n;i++){
		if(v[i]>c[i])ans+=v[i]-c[i];
	}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<queue>
#include<string>
#include<cstring>
#include<algorithm>
#include<set>
#include<map>

#define REP(i,n) for(int i=0;i<(n);i++)
#define EPS (1e-7)
#define INF (3e9)

using namespace std;
typedef long long int ll;

ll N, K, Q;
ll A;
ll B[100000];
int main(void){
    cin >> N >> K >> Q;
    REP(i,Q){
        scanf("%lld", &A);
        B[A-1]++;
    }
    ll count = 0;
    REP(i,N){
        if(K-(Q-B[i]) <= 0) cout << "No" << endl;
        else cout << "Yes" << endl;
    }

    return 0;
}



Measured memory_bytes: 1408
#include"bits/stdc++.h"

using namespace std;

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define PN 6700417 

/*long check(long* a,long n){
    long m=0;
    for(long i=0;i<n;i++){
      if(i+1>=a[i]&&!(a[i]==a[i+1])){
        a[m]=a[i];
        m++;
      }
    }
    return m;
}*/

int main(){
    int i;
    //入力
    /*long n,l;
    cin>>n;
    l=n;
    long a[n]={};
    for(i=0;i<n;i++){
        long y;
        cin>>y;
        if(i+1>=y){
            a[j]=y;
            j++;
        }
    }
    //処理
    if(a[0]==0){
        cout<<-1<<endl;
        exit;
    }
    long m=j;
    do{
        n=m;
        m=check(a,n);
    }while(!(m==n));

    //出力
    cout<<(l-m)<<endl;*/
    long n,j=1,k;
    cin>>n;
    for(i=0;i<n;i++){
        cin>>k;
        if(k==j){
            j++;
        }
    }
    if(j==1){
        cout<<-1<<endl;
    }else{
        cout<<n-(j-1)<<endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define SZ(x) ((int)(x).size())
#define rep(i,n) for(int i=0;i<(n);++i)
#define fore(i,a) for(auto &i:a)
#define min(...) min({__VA_ARGS__})
#define max(...) max({__VA_ARGS__})
#define Yes cout << "Yes" << endl;
#define No cout << "No" << endl;
#define ALL(x) (x).begin(),(x).end()
signed _main(); signed main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> using v = vector<T>;
template<class T> using vv = vector<v<T>>;
const int MOD=1e9+7;
const long long INF = 1LL << 60;
using P=pair<int,int>;

signed _main(){
  int N; cin >> N;
  v<int> a(N);
  rep(i,N){
    cin >> a[i];
    if(a[i]==0){
      cout << 0 << endl;
      return 0;
    }
  }
  int ans=1;
  rep(i,N){
    //cout << ans << endl;
    if(a[i]<=1000000000000000000/ans){
      ans*=a[i];
    }
    else{
      cout << -1 << endl;
      return 0;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3952
#include "bits/stdc++.h"
#define rep(i,a,n) for(int i = (a);i < (n);i++)
typedef unsigned long long ull;
typedef long long ll;
using namespace std;

int main(){
    
    int h1,m1,s1,h2,m2,s2,h,m,s;
    
    rep(i,0,3){
        cin >> h1 >> m1 >> s1;
        cin >> h2 >> m2 >> s2;
        h = h2 - h1;
        
        if(m2 < m1){
            h--;
            m = m2+60-m1;
        }
      	else{
          	m = m2-m1;
        }
        
        if(s2 < s1){
          	if(m == 0){
              h--;
              m = 59;
            }
          	else{
              m--;
            }
            s = s2+60-s1;
        }
      	else{
          	s = s2-s1;
        }
        
        cout << h << " " << m << " " << s << endl;
        
    }
}


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

typedef double du ;
typedef string st ;
typedef long long ll ;
typedef long double ld ;
typedef long long int lli ;

int main ()
{
    int p , q , r , dd ;
    cin >> p >> q >> r ;

    dd = max(p , max(q , r)) ;

    cout << (p+q+r) - dd << endl ;


    return 0;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10 ** 6)
# input = sys.stdin.readline    ####
int1 = lambda x: int(x) - 1
def II(): return int(input())

def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())

def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

def printlist(lst, k='\n'): print(k.join(list(map(str, lst))))
INF = float('inf')

def solve():
    n, m = MI()
    A = LI()
    L = []
    for a in A:
        L.append((a, 1))
    for i in range(m):
        b, c = MI()
        L.append((c, b))
    L = sorted(L, key=lambda x:x[0], reverse=True)

    cnt = 0
    ans = 0
    for i in range(n):
        val, c = L[i]
        # print(val, c)
        if cnt + c >= n:
            c = n - cnt
        ans += val * c
        cnt += c
    print(ans)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 33508
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include <numeric>
#include<cstring>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999
#define m0(x) memset(x,0,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))

using namespace std;



int dy[4] = { 0,0,1,-1 };
int dx[4] = { 1,-1,0,0 };
int dxx[8] = { 0,0,1,1,1,-1,-1,-1 };
int dyy[8] = { 1,-1,0,1,-1,0,1,-1 };


ll m = 1000000007;

const int MOD = 1000000007;

ll gcd(ll x, ll y) {
	ll m = max(x, y), n = min(x, y);
	if (m%n == 0)return n;
	else return gcd(m%n, n);
}
ll lcm(ll x, ll y) {
	return x / gcd(x, y)*y;
}

ll myPow(ll x, ll n, ll m) {
	if (n == 0)
		return 1;
	if (n % 2 == 0)
		return myPow(x * x % m, n / 2, m);
	else
		return x * myPow(x, n - 1, m) % m;
}

long long nCr(int n, int r) {
	if (r > n / 2) r = n - r; // because C(n, r) == C(n, n - r)
	long long ans = 1;
	int i;

	for (i = 1; i <= r; i++) {
		ans *= n - r + i;
		ans /= i;
	}

	return ans;
}



int main() {
	string s; cin >> s;
	set<char>st;
	int n = s.length();
	REP(i, n) {
		st.insert(s[i]);
	}
	if (st.size() == n) {
		cout << "yes" << endl;
	}
	else cout << "no" << endl;
}


Measured memory_bytes: 256
while True:
    a, op, b = input().split()
    if op == '?':
        break
    elif op == '+':
        print(int(a) + int(b))
    elif op == '-':
        print(int(a) - int(b))
    elif op == '*':
        print(int(a) * int(b))
    elif op == '/':
        print(int(a) // int(b))


Measured memory_bytes: 5592
#include <stdio.h>

int main(){
    int i, n;
    int a[100];
    
    scanf("%d", &n);
    
    for(i = 0; i < n; ++i){
        scanf("%d", &a[i]);
    }
    
    for(i = n - 1; i >= 0; --i){
        printf("%d", a[i]);
        
        if(i > 0){
            putchar(' ');
        }
    }
    
    putchar('\n');
    
    return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
#define int long long
#define bp __builtin_popcountll
#define pb push_back
#define in(s) freopen(s, "r", stdin);
#define out(s) freopen(s, "w", stdout);
#define inout(s, end1, end2) freopen((string(s) + "." + end1).c_str(), "r", stdin),\
		freopen((string(s) + "." + end2).c_str(), "w", stdout);
#define fi first
#define se second
#define bw(i, r, l) for (int i = r - 1; i >= l; i--)
#define fw(i, l, r) for (int i = l; i < r; i++)
#define fa(i, x) for (auto i: x)
using namespace std;
const int mod = 1e9 + 7, inf = 1061109567;
const long long infll = 4557430888798830399;
const int N = 105;
int n, a[N];
struct Dinic {
   int n, s, t;
   struct Edge {
      int to, cap, flow, rev;
      Edge(int to = 0, int cap = 0, int flow = 0, int rev = 0) :
         to(to), cap(cap), flow(flow), rev(rev) {}
   };
   vector<int> d;
   vector<int> ptr;
   vector<vector<Edge>> g;
   Dinic(int n = 0, int s = 0, int t = 0) :
      n(n), s(s), t(t), d(n), ptr(n), g(n) {}
   void addEdge(int u, int v, int cap) {
      g[u].emplace_back(v, cap, 0, g[v].size());
      g[v].emplace_back(u, 0, 0, g[u].size() - 1);
   }
   bool bfs() {
      fill(d.begin(), d.end(), -1);
      fill(ptr.begin(), ptr.end(), 0);
      queue<int> q;
      d[s] = 0;
      q.push(s);
      while (!q.empty()) {
         int u = q.front();
         q.pop();
         for (auto e : g[u]) {
            if (d[e.to] == -1 && e.cap > e.flow) {
               d[e.to] = d[u] + 1;
               q.push(e.to);
            }
         }
      }
      return d[t] != -1;
   }
   int dfs(int u, int flow) {
      if (u == t) {
         return flow;
      }
      for (int &i = ptr[u]; i < g[u].size(); ++i) {
         auto &e = g[u][i];
         if (e.cap <= e.flow || d[e.to] != d[u] + 1) continue;
         int nxt = dfs(e.to, min(flow, e.cap - e.flow));
         if (nxt) {
            e.flow += nxt;
            g[e.to][e.rev].flow -= nxt;
            return nxt;
         }
      }
      return 0;
   }
   	int maxFlow() {
      	int ans = 0;
      	while (bfs()) {
       	  while (true) {
            int now = dfs(s, inf);
            if (now) ans += now;
            else break;
         }
      }
      return ans;
   }
} mf;
signed main() {
	#ifdef BLU
	in("blu.inp");
	#endif
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> n;
	fw (i, 0, n) cin >> a[i];
	fw (i, 0, n) a[i] = -a[i];
	mf = Dinic(n + 2, 0, n + 1);
	//Get rid of gemstones so that the sum of the destroyed gems is maximum.
	fw (i, 0, n) {
		if (a[i] <= 0) mf.addEdge(i + 1, n + 1, -a[i]);
		else mf.addEdge(0, i + 1, a[i]); 
	}
	fw (i, 1, n + 1) {
		fw (j, i, n + 1) if (j % i == 0) mf.addEdge(i, j, inf);
	}
	//Min cut of graph now represents the selected gems.
	int sumA = 0;
	fw (i, 0, n) sumA += a[i];
	int destroyed = 0;
	fw (i, 0, n) if (a[i] >= 0) destroyed += a[i];
	destroyed -= mf.maxFlow();
	sumA -= destroyed;
//	cout << "max flow = " << mf.maxFlow() << "\n";
	cout << max(-sumA, 0ll);
	return 0;
}

Measured memory_bytes: 384
#date: 2020-03-15 21:24
import sys
stdin = sys.stdin

def ns(): return stdin.readline().rstrip()
def ni(): return int(ns())
def na(): return list(map(int, stdin.readline().split()))

def main():
    s = ns()
    for i, si in enumerate(s):
        if i % 2 == 0:
            if si in ("R", "U", "D"):
                continue
            else:
                print("No")
                quit()
        else:
            if si in ("L", "U", "D"):
                continue
            else:
                print("No")
                quit()
    print("Yes")

if __name__ == "__main__":
    main()

Measured memory_bytes: 3064
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main{
    public static void main(String[] args)throws IOException {
    	InputStreamReader is = new InputStreamReader(System.in);
        BufferedReader br = new BufferedReader(is);
int n=Integer.parseInt(br.readLine()); int []p=new int[n];
int m=Integer.parseInt(br.readLine()); int []t=new int[m];
String[] ts = br.readLine().split(" ");
for(int i=0;i<m;i++)t[i]=Integer.parseInt(ts[i]);
for(int i=0;i<m;i++){
	String[] ps = br.readLine().split(" ");
	for(int j=0;j<n;j++){
		if(Integer.parseInt(ps[j])==t[i]){p[j]++;}else  p[t[i]-1]++;
	}
}
for(int i=0;i<n;i++)System.out.println(p[i]);
br.close();
    }
}

Measured memory_bytes: 26816
#include<stdio.h>

int main()
{
     int a,b,c,con=0;
     scanf("%d %d %d",&a,&b,&c);
     for(int i = a; i <= b;i++){
          if(c%i==0)
               con +=1;
     }
     printf("%d\n",con);
     return 0;
}


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

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> VI;
typedef vector<VI> VVI;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = numeric_limits<int>::max() / 2;
const int NEG_INF = numeric_limits<int>::min() / 2;

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

  string s;
  cin >> s;
  int len=s.length();
  int res=0;
  for(int i=1;i<len;i++){
    if(s[i]!=s[i-1]) res++;
  }
  cout << res << endl;
}

Measured memory_bytes: 512
n, m = map(int, input().split())
a = [-1] * n
for i in range(m):
    p, d = map(int, input().split())
    if a[p - 1] != -1 and a[p - 1] != d:
        print(-1)
        exit()
    else:
        a[p - 1] = d
if a[0] == 0 and n != 1:
    print( -1 )
    exit()
for i in range(n):
    if a[i] == -1:
        a[i] = 0
if a[0] == 0 and n != 1:
    a[0] = 1

for i in range(n):
    print(a[i], end = "")

Measured memory_bytes: 38384
#include<bits/stdc++.h>
#include <math.h>
#include <map>
#include <unordered_map>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define pb(s) push_back(s)
#define CST(x) cout<<fixed<<setprecision(x)
#define ci(x) cin >>x
#define co(x) cout<<x<<endl
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
long long fac(ll a) {
 long long ans=1;
 while(a>1){
 ans*=a;
 ans%=1000000007;
     a--;
    }
    return ans;
     }

ll powmod(ll n, ll k, ll m) {
ll r=1;
 for(; k>0; k >>=1) {
   if(k&1) r=(r*n)%m;
   n=(n*n)%m;
 }
  return r;
}

struct UF{
    vl par;
    UF(ll N):par(N){
        rep(i,N)par[i]=i;
    }
    ll root(ll x){
        if(par[x]==x)return x;
        return par[x]=root(par[x]);
    }
    bool same(ll x,ll y){
        return root(x)==root(y);
    }
    void unite(ll x,ll y){
        x=root(x),y=root(y);
        if(x==y)return;
        par[x]=y;
        return;
    }
};
ll ps(ll b) {
  ll c=(b*(b-1))/2;
  return c;
}
  
int main() {
ll N;
  cin >>N;
  vl a(N);
  rep(i,N) {
cin >>a.at(i);
  }
  
  map<ll,ll>mp;
  rep(i,N) {
mp[a.at(i)]++;
  }
ll x=mp.size();
 
  ll ma=0;
  rep(i,N) {
    
    ma=max(ma,a.at(i));
  }
  
  
  vl vec(ma);
  rep(i,ma) {
    vec.at(i)=0;
  }

  rep(i,N) {
vec.at(a.at(i)-1)++;
  }
  ll sum=0;
  rep(i,ma) {
    sum +=ps(vec.at(i));
  }
  
  
  vl fin(N);
  rep(i,N) {
fin.at(i)=0;
  }

  rep(i,N) {
    vec.at(a.at(i)-1)--;
    
    ll bb=0;
    bb=sum-ps(vec.at(a.at(i)-1)+1)+ps(vec.at(a.at(i)-1));
    fin.at(i)=bb;
    vec.at(a.at(i)-1)++;
  }
  
  
  
  rep(i,N) {
cout<<fin.at(i)<<endl;
  }
  
}
  
  
 

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

#define sz(s) (int)(s).size()
#define re(i, n) for (int i = 1; i <= n; i ++)
#define pb push_back
#define finish(x) return cout << x << endl, 0
#define MP make_mair
#define trav(x, a) for(auto& x: a)
#define all(x) (x).begin,(x).end()
#define Sor(x) sort(all(x))
#define REV(x) reverse(all(x))
#define F first
#define S second
#define I insert
#define N 222222
#define MOD 100000007

using namespace std;

typedef long long ll;
vector <ll> vll;
template <class T> bool umin(T& a, T b) {if(a>b){a = b; return 1;}return 0;}
template <class T> bool umax(T& a, T b) {if(a<b){a=b; return 1;}return 0;}
template <class T, class TT> bool pal(T a, TT n){int k = 0; for(int i =0; i <= n / 2; i ++){if(a[i]!=a[n-i-1]){k=1;break;}}return k?0:1;}

ll powmod(ll a, ll b, ll m = MOD){ll r = 1;while(b>0){if(b&1)r=r*a%m;a=a*a%m;b>>=1;}return r;}


int main()
{
	string s;
	cin >> s;
            for(int i = 0; i < s.size(); i++)
              if(!(i & 1) && s[i] == 'L')
                return cout << "No", 0;
              else if((i & 1) && s[i] == 'R')
                return cout << "No", 0;
            cout << "Yes";







	getchar();
	getchar();
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s;
  int m, h;
  while (getline(cin, s)) {
    if (!s.compare("-")) break;
    cin >> m;
    for (int i{0}; i < m; ++i) {
      cin >> h;
      auto cards = s.substr(0, h);
      s.erase(0, h);
      s += cards;
    }
    cout << s << '\n';
    cin.ignore(1, '\n');
  }
}



Measured memory_bytes: 3200
N,A,B=map(int,input().split())
num=0
for n in range(0,N+1):
    def degitSum(n):
        s=str(n)
        lists=list(map(int,s))
        return sum(lists)
    if degitSum(n)>A-1 and degitSum(n)<B+1:
        num=num+n
print(num)

Measured memory_bytes: 3060
sx, sy, tx, ty = list(map(int, input().split()))

# 上右下左
S = [[sx, sy+1], [sx+1, sy], [sx, sy-1], [sx-1, sy]]
T = [[tx, ty+1], [tx+1, ty], [tx, ty-1], [tx-1, ty]]

diff_x = abs(sx - tx) #差分計算
diff_y = abs(sy - ty)

re = ''
# 1回目の行き
re += 'U' * diff_y + 'R' * diff_x

# 1回目の帰り
re += 'D' * diff_y + 'L' * diff_x

# 2回目の行き
re += 'L' + 'U' * (diff_y + 1) + 'R' * (diff_x + 1) + 'D'


# 2回目の帰り
re += 'R' + 'D' * (diff_y + 1) + 'L' * (diff_x + 1) + 'U'

print(re)

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

char F[102][102];

void fruit(int H,int W,char n){
  if(F[H][W]!=n){
    return;
  }

  F[H][W] = '.';

  fruit(H-1,W  ,n);
  fruit(H  ,W+1,n);
  fruit(H+1,W  ,n);
  fruit(H  ,W-1,n);
}

int main(){
  while(1){
    int N,M;
    cin >> N >> M;
    if(N==0 && M==0){
      break;
    }

    for(int y=1;y<=N;y++){
      for(int x=1;x<=M;x++){
        cin >> F[y][x];
      }
    }

    int cnt = 0;
    for(int y=1;y<=N;y++){
      for(int x=1;x<=M;x++){
        if(F[y][x]=='@'){
          cnt++;
          fruit(y,x,'@');
        }else if(F[y][x]=='#'){
          cnt++;
          fruit(y,x,'#');
        }else if(F[y][x]=='*'){
          cnt++;
          fruit(y,x,'*');
        }
      }
    }
    cout << cnt << endl;
  }

  return 0;
}



Measured memory_bytes: 3416
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <string>
#include <cmath>
using namespace std;
#define MOD 1000000007
#define INF 1<<30
#define LINF (ll)1<<62
#define MAX 510000
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> P;
typedef vector<pair<ll, ll>> vpl;



int main(){
    ll x; cin >> x;
    ll n = 1;
    ll sum = 1;
    while(sum < x){
        n++;
        sum += n;
    }
    cout << n << endl;
}


Measured memory_bytes: 256
/*
	Author: Luis Manuel D�az Bar�n (LUISMO)
	Problem:
	Online Judge:
	Idea:
*/
#include<bits/stdc++.h>
// Types
#define ll long long
#define ull unsigned long long
// IO
#define sf scanf
#define pf printf
#define mkp make_pair
#define fi first
#define se second
#define endl "\n"

using namespace std;

typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const ll inf = 1e16 + 3;
const int mod = 1e9 + 7;
const int lim = 2e5 + 2;

int N, K;
ll hi[lim];

ll dp[lim];
int mark[lim];

ll DynamicProgramming(int idx)
{
    if(idx <= 0)
        return 0;

    if(mark[idx])
        return dp[idx];

    mark[idx] = true;

    DynamicProgramming(idx - 1);
    
    int kidx =max(0,idx - K);
    ll aux = inf;
    for(int i = kidx; i < idx; i++)
    {
        ll curr = dp[i] + abs(hi[i] - hi[idx]);
        aux = min(aux, curr);
    }

    dp[idx] = aux;
    return dp[idx];
}


void solve()
{
    cin >> N >> K;
    for(int i = 0; i < N; i++) 
        cin >> hi[i];   

    ll answ = DynamicProgramming(N - 1);
    cout << answ;
}

void fastIO()
{
	cin.sync_with_stdio(false);
	cin.tie(0);
}

void IO()
{
	if(fopen("d:\\lmo.in","r") != NULL)
	{
		freopen("d:\\lmo.in","r",stdin);
	}
	else if(fopen("/media/Beijing/lmo.in","r") != NULL)
	{
		freopen("/media/Beijing/lmo.in", "r", stdin);
	}
}

int main()
{
	IO();

	fastIO();

	solve();
}


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

int n, a, b, c;
vector<string> s;
vector<string> ans;
bool stop;

void ab(string nx)
{
  if (a + b == 0) {
    stop = true;
    return;
  }
  if (a * b == 0) {
    if (a == 0) {
      ans.push_back("A");
      a++;
      b--;
    } else {
      ans.push_back("B");
      a--;
      b++;
    }
    return;
  }
  if (nx == "AC") {
    ans.push_back("A");
    a++;
    b--;
  } else {
    ans.push_back("B");
    a--;
    b++;
  }
}

void ac(string nx)
{
  if (a + c == 0) {
    stop = true;
    return;
  }
  if (a * c == 0) {
    if (a == 0) {
      ans.push_back("A");
      a++;
      c--;
    } else {
      ans.push_back("C");
      a--;
      c++;
    }
    return;
  }
  if (nx == "AB") {
    ans.push_back("A");
    a++;
    c--;
  } else {
    ans.push_back("C");
    a--;
    c++;
  }
}

void bc(string nx)
{
  if (b + c == 0) {
    stop = true;
    return;
  }
  if (b * c == 0) {
    if (b == 0) {
      ans.push_back("B");
      b++;
      c--;
    } else {
      ans.push_back("C");
      b--;
      c++;
    }
    return;
  }
  if (nx == "AB") {
    ans.push_back("B");
    b++;
    c--;
  } else {
    ans.push_back("C");
    b--;
    c++;
  }
}

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

  for (int i = 0; i < n; i++) {
    string t;
    cin >> t;
    s.push_back(t);
  }
  s.push_back("XX");

  for (int i = 0; i < n; i++) {
    if (s[i] == "AB") {
      ab(s[i + 1]);
    } else if (s[i] == "AC") {
      ac(s[i + 1]);
    } else {
      bc(s[i + 1]);
    }
    if (stop) break;
  }

  if (stop) {
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
    for (auto&& e : ans) {
      cout << e << endl;
    }
  }
}


Measured memory_bytes: 12448
def soin(num):
    re = []
    div = 2
    while 1:
        lim = int(num ** 0.5) + 1
        while num % div:
            div += 1
            if div > lim:
                re += [1]
                return re
        sisu = 0
        while num % div == 0:
            num //= div
            sisu += 1
        re += [sisu]
        if num == 1:
            return re


def com(a, b):
    if a == b:
        return 1
    t = (a, b)
    if (a, b) in com_memo:
        return com_memo[t]
    re = com(a - 1, b) * a // (a - b)
    com_memo[t] = re
    return re


def f(n, m):
    if m == 1:
        print(1)
        return
    sisus = soin(m)
    ans = 1
    for s in sisus:
        ans = ans * com(s + n - 1, n - 1) % md
    print(ans)


md = 10 ** 9 + 7
n, m = map(int, input().split())
com_memo = {}
f(n, m)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define range(i, l, r) for(long long int (i) = (l); (i) < (r); (i)++)
#define reversed_range(i, l, r) for (long long int (i) = (r) - 1; (i) >= l; (i)--)
using namespace std;
template <typename T>
using vec = vector<T>;
using lint = long long;
using ulint = unsigned long long;
using pint = pair<int, int>;
using plint = pair<lint, lint>;

template <typename S, typename T>
ostream& operator <<(ostream& os, pair<S, T> p) {
    os << "(";
    os << p.first << ", " << p.second;
    return os << ")";
}

template <typename T>
ostream& operator <<(ostream& os, vec<T> v) {
    os << "[";
    if (v.size() == 0) return os << "]";
    for (int i = 0; i < v.size() - 1; i++) {
        os << v.at(i) << ", ";
    }
    return os << v.at(v.size() - 1) << "]";
}

template <typename T>
ostream& operator <<(ostream& os, set<T>& s) {
    os << "{";
    if (s.begin() == s.end()) return os << "}";
    auto it_first_item = s.begin();
    cout << *it_first_item;
    for (auto it = ++it_first_item; it != s.end(); it++) {
        cout << ", " << *it;
    }
    return cout << "}";
}

template <typename T>
ostream& operator <<(ostream& os, unordered_set<T>& s) {
    os << "{";
    if (s.begin() == s.end()) return os << "}";
    auto it_first_item = s.begin();
    cout << *it_first_item;
    for (auto it = ++it_first_item; it != s.end(); it++) {
        cout << ", " << *it;
    }
    return cout << "}";
}

template <typename K, typename V>
ostream& operator <<(ostream& os, map<K, V> m) {
    os << "{";
    if (m.begin() == m.end()) return os << "}";
    auto it_first_item = m.begin();
    cout << it_first_item->first << ": " << it_first_item->second;
    for (auto it = ++it_first_item; it != m.end(); it++) {
        cout << ", " << it->first << ": " << it->second;
    }
    return os << "}";
}

template <typename K, typename V>
ostream& operator <<(ostream& os, unordered_map<K, V> m) {
    os << "{";
    if (m.begin() == m.end()) return os << "}";
    auto it_first_item = m.begin();
    cout << it_first_item->first << ": " << it_first_item->second;
    for (auto it = ++it_first_item; it != m.end(); it++) {
        cout << ", " << it->first << ": " << it->second;
    }
    return os << "}";
}

lint pow(lint num, lint e, lint MOD) {
    lint res = 1;
    lint cur_num = num;
    while (e) {
        if (e & 1) {
            res *= cur_num;
            res %= MOD;
        }
        cur_num *= cur_num;
        cur_num %= MOD;
        e >>= 1;
    }
    return res;
}

int main() {
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    lint N; cin >> N;
    lint ans = 1LL << 58;
    range(i, 1, (lint)1e6 + 1) {
        if (N % i > 0) continue;
        lint j = N / i;
        lint dist = i - 1 + j - 1;
        ans = min(ans, dist);
    }
    cout << ans << "\n";
}

Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
using namespace std;
#include<vector>
#include<stack>
#include<algorithm>

stack<int> S1;
stack<pair< int, int> > S2;

int main()
{
    int i = 0;
    int j = 0;
    int sum = 0;
    char ch;
    while(scanf("%c",&ch) != EOF)
    {
        i++;
        if( ch == '\\')
           S1.push(i);
        else if( ch == '/')
        {
            if(!S1.empty())
            {
                j = S1.top();
                S1.pop();
                sum = sum + i - j;
                int a = i - j;
                while(!S2.empty() && S2.top().first > j)
                {
                    a += S2.top().second;
                    S2.pop();
                }
                S2.push(make_pair(j,a));
            }
        }
    }
        vector<int> ans;
        while( S2.size() > 0) {ans.push_back(S2.top().second);   S2.pop();}
        reverse(ans.begin(), ans.end());
        cout<< sum << endl;
        cout<< ans.size();
        for( i = 0; i < ans.size(); i++ ) {
            cout << " ";
            cout << ans[i];
        }
        cout << endl;

        return 0;

}



Measured memory_bytes: 3304
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <numeric>
#include <map>
#include <cmath>
#include <iostream>
#include <deque>
#include <math.h>
#include <cstdio>
#include <functional>
#include <set>
#include <iomanip>
#include <tuple>
typedef  long long ll;
using namespace std;

int main(void) {
	ll n;
	cin >> n;
	vector<ll> a(n);
	for (int i = 0; i < n; i++) cin >> a[i];
	ll num = 1, ans = 0;
	for (int i = 0; i < n; i++)
	{
		if(a[i] == num) num++;
		else ans++;
	}
	
	if (num == 1) cout << "-1" << endl;
	else cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    ios_base:: sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    ll n,k;cin>>n>>k;
    ll a[n];for(ll i=0;i<n;i++)cin>>a[i];
    cout<<(n-1 + k-1 - 1)/(k-1);
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main(){
  int64_t n,m;
  cin >> n>>m;
  vector<pair<int64_t,int64_t>> a(n);
  int64_t i;
  for(i=0;i<n;i++){
    int64_t c,d;
    cin >>c>>d;
    a.at(i)=make_pair(c,d);
  }
  sort(a.begin(),a.end());
  int64_t sum=0;
  for(i=0;i<n;i++){
    if(m-a.at(i).second>=0){
      m-=a.at(i).second;
      sum+=a.at(i).first*a.at(i).second;
    }else{
      sum+=a.at(i).first*m;
      break;
    }
  }
  cout << sum;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; i++)
#define repo(i, n) for(int i=1; i<=n; i++)
#define ssort(a) sort(a.begin(), a.end())
#define INF 1001001001
#define INFll 100100100100100
// debug用
#define PrintVec(x) for (auto elementPrintVec: x) { cout << elementPrintVec << " "; } cout << endl;

using namespace std;
using ull = unsigned long long;
using ll = long long;
using P = pair<int, int>;
const int mod = 1000000007;


#define MAX_V 100

struct edge {
    int to;
    int cost;
};

// <最短距離, 頂点の番号>
using P = pair<int, int>;

int V;
vector<edge> G[MAX_V];
int d[MAX_V];
set<P> S;
vector<P> vec(MAX_V, P(0, 0));

void dijkstra(int s) {
    priority_queue<P, vector<P>, greater<P> > que;
    fill(d, d+MAX_V, INF);
    d[s] = 0;
    que.push(P(0, s));

    while (!que.empty()) {
        P p = que.top();
        que.pop();
        int v = p.second;
        if (d[v] < p.first) continue;

        for (int i=0; i<G[v].size(); ++i) {
            edge e = G[v][i];
            if (d[e.to] > d[v] + e.cost) {
                d[e.to] = d[v] + e.cost;
                if(e.to<=v){
                  vec[e.to]=P(e.to, v);
                } else {
                  vec[e.to]=P(v, e.to);
                }
                que.push(P(d[e.to], e.to));
            }
        }
    }
    rep(i, MAX_V){
      if(vec[i]!=P(0, 0)){
        S.insert(vec[i]);
      }
    }
}

int main() {
    cin >> V;
    int E;
    cin >> E;
    for (int i=0; i<E; ++i) {
        int a, b, c;
        cin >> a >> b >> c;
        //有向グラフ
        a--;b--;
        edge e = {b, c};
        G[a].push_back(e);
        edge e2 = {a, c};
        G[b].push_back(e2);
    }
    rep(i, V){
      dijkstra(i);
    }
    cout << (int)(E-S.size()) << endl;
    return 0;
}


Measured memory_bytes: 3604
#include <iostream>

using namespace std;

int n;
int hall[4][3][10];

int main() {
    cin >> n;
    int b, f, r, v;
    for(int i = 0; i < n; i++) {
        cin >> b >> f >> r >> v;
        b--; f--; r--;
        hall[b][f][r] += v;
    }
    for(int i = 0; i < 4; i++) {
        for(int j = 0; j < 3; j++) {
            for(int k = 0; k < 10; k++) {
                cout << " " << hall[i][j][k];
            }
            cout << endl;
        }
        if(i != 3)cout << "####################" << endl;
    }
}


Measured memory_bytes: 3060