akhauriyash/Code-Regression huggingface dataset:
/*

結果:
*/
#define _USE_MATH_DEFINES
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <limits.h>  
#include <stdbool.h>   
#define inf (INT_MAX-1)
#define INF 9223372036854775807
#define PI 3.14159265358979323846;
#define EPS 1e-10
#define sq(n) ((n)*(n))
#define rep(i,n) for(i=0;i<n;i++)
#define rev(i,n) for(i=n-1;i>=0;i--)
/*
#define sort(a,n) qsort(a,n,sizeof(TYPE),cmp)
#define sort_r(a,n) qsort(a,n,sizeof(TYPE),cmp_r)
*/
#define chsort(s,n) qsort(s,n,sizeof(char),cmp)
#define chsort_r(s,n) qsort(s,n,sizeof(char),char_cmp_r)
#define TYPE long long
#define ll long long
#define MEMSET(a) memset(a,0,sizeof(a))
#define MEMSET_U(a) memset(a,-1,sizeof(a))
const int mod = (int)1e09 + 7;

//#define DEBUG1
//#define DEBUG2
//#define DEBUGF
#define DUMMY

int in(void) { int i; scanf("%d", &i); return i; }
long long llin(void) { long long i; scanf("%lld", &i); return i; }
double din(void) { double i; scanf("%lf", &i); return i; }
void chin(char s[]) { scanf("%s", s); }

void print(int a) { printf("%d\n", a); }
void llprint(long long a) { printf("%lld\n", a); }
void dprint(double a) { printf("%.10f\n", a); }
void print2(int a, int b) { printf("%d %d\n", a, b); }
int Max(int a, int b) { if (a > b) { return a; }return b; }
int Min(int a, int b) { if (a < b) { return a; }return b; }
long long llmax(long long a, long long b) { return a > b ? a : b; }
long long llmin(long long a, long long b) { return a < b ? a : b; }
double dmax(double a, double b) { return a > b ? a : b; }
double dmin(double a, double b) { return a < b ? a : b; }
//long long llmax(long long a, long long b) { return a > b ? a : b; }
//long long llmin(long long a, long long b) { return a < b ? a : b; }
//double dmax(double a, double b) { return a > b ? a : b; }
int cmp(const void *a, const void *b) { return *(TYPE *)a - *(TYPE *)b; }
int cmp_r(const void *a, const void *b) { return *(TYPE *)b - *(TYPE *)a; }
int char_cmp(const void *a, const void *b) { return strcmp((char *)a, (char *)b); }
int char_cmp_r(const void *a, const void *b) { return strcmp((char *)b, (char *)a); }
void swap(int *a, int *b) { int t = *a; *a = *b; *b = t; }




int main() {
	int A, B, C;
	scanf("%d%d%d", &A, &B, &C);
	int jadge = 0;

	for (int i = 1; i <= B; i++) {
		if ((A*i)%B==C) {
			jadge++;
			break;
		}
	}

	if (jadge) {
		puts("YES");
}
	else {
		puts("NO");
	}

#ifdef DEBUGF
	getch();
#endif
	return 0;
	}

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

const ll MOD = 1000000007;

ll fac(int n) {
    ll ans = 1;
    for (int i = 1; i <= n; i++){
        ans *= i;
        ans %= MOD;
    }
    return ans;
}



int main() {
    int N, M; cin >> N >> M;
    if (max(N, M) - min(N, M) == 1) {
        cout << (fac(N) * fac(M)) % MOD << endl;
    }
    else if (N == M) {
        cout << (2 * fac(N) * fac(M)) % MOD << endl;
    }
    else {
        cout << 0 << endl;
    }
}


Measured memory_bytes: 256
open System

let Puts = Console.WriteLine : 'a -> unit
let Reads () = Console.ReadLine().Split()
let ReadDouble () = Reads() |> (fun x -> x.[0], x.[1])
let ReadTriple () = Reads() |> (fun x -> x.[0], x.[1], x.[2])
let ReadQuadruple () = Reads() |> (fun x -> x.[0], x.[1], x.[2], x.[3])

let FuncDouble f1 f2 (t1, t2) = (f1 t1, f2 t2)
let FuncTriple f1 f2 f3 (t1, t2, t3) = (f1 t1, f2 t2, f3 t3)
let FuncQuadruple f1 f2 f3 f4 (t1, t2, t3, t4) = (f1 t1, f2 t2, f3 t3, f4 t4)

let ensmallen l = l % 1000000007L

// main code

let w, a, b = ReadTriple() |> FuncTriple int int int

let d =
    if a + w < b then b - (a + w)
    else if b + w < a then a - (b + w)
    else 0
d |> Puts


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

int main(){
    int n,m;
    int total = 0;
    cin >> n;
    vector<int> t(n);
    rep(i,n){
        cin >> t[i];
        total += t[i];
    }
    cin >> m;
    vector<int> p(m),x(m);
    rep(i,m)cin >> p[i] >> x[i];
    rep(i,m){
        cout << total - (t[p[i]-1] -x[i]) << endl;
    }
    return 0;
}

Measured memory_bytes: 256
import itertools

l, r = (int(i) for i in input().split())
if r-l>=2019:
  print(0)
else:
  ls = list(range(l, r+1))
  hoge = [i[0]*i[1]%2019 for i in itertools.combinations(ls, 2)]
  print(min(hoge))

Measured memory_bytes: 75460
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<(n);i++)
#define loop(i,a,n) for(i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;

int main(void) {
  int i,j;
  int n;
  cin>>n;
  int m;
  cin>>m;
  vector<vi> g(n);
  vi in(n,0),out(n,0);

  rep(i,m){
    int a,b;
    cin>>a>>b;
    a--,b--;
    in[b]++;
    out[b]++;
    out[a]++;
    g[a].push_back(b);
  }

  queue<int> q;
  rep(i,n)if(in[i]==0)q.push(i);

  bool c=true;
  while(q.size()){
    if(q.size()>=2)c=false;
    int x=q.front();
    cout<<x+1<<endl;
    q.pop();
    rep(i,g[x].size()){
      int y=g[x][i];
      in[y]--;
      if(in[y]==0){
	q.push(y);
      }
    }
  }

  if(c)cout<<0<<endl;
  else cout<<1<<endl;

}



Measured memory_bytes: 3816
N,A,B,C,D=map(int, input().split())
S=input()
result = ""

for i in range(A,max(C,D)):
    if S[i:i+2]=="##":
        result = "No"
        break

if result == "":
    if C < D:
        result ="Yes"
    else: # D < C
        if S[B-2] == "." and S[B] == ".":
            result = "Yes"
        else:
            for i in range(B-2,D-2):
                if S[i:i+4] == "#...":
                    result = "Yes"

if result == "":
    result = "No"

print(result)


Measured memory_bytes: 3572
n=int(input())
ans=0
c=0
while not n%2:
    n=n//2
    c+=1
ans+=int((pow(1+8*c,0.5)-1)/2)
for i in range(3,int(pow(n,0.5))+1,2):
    
    c=0
    while not n%i:
        n=n//i
        c+=1
    ans+=int((pow(1+8*c,0.5)-1)/2)
if n>2:
    ans+=1
print(ans)


Measured memory_bytes: 65228
#include <bits/stdc++.h>
#define SZ(v) (int((v).size()))
#define ALL(vec) (vec).begin(),(vec).end()
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
using namespace std;
 
using i64 = long long int;
template <typename T> inline bool uax(T &x, T y) {return (y > x) ? x = y, true : false;}
template <typename T> inline bool uin(T &x, T y) {return (y < x) ? x = y, true : false;}
 
void err(__attribute__((unused)) istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " =: " << a << endl;
  err(++it, args...);
}
template <typename T1, typename T2>
inline ostream& operator << (ostream& os, const pair<T1, T2>& buf) {
  return os << "(" << buf.first << ": " << buf.second << ")";
}
template<typename T>
inline ostream &operator << (ostream & os,const vector<T>& v) {
  bool first = true;
  os << "[";
  for (const auto &e: v) {
    if(!first) os << ", ";
    os << e;
    first = false;
  }
  return os << "]";
}
template<typename T>
inline ostream &operator << (ostream & os, multiset<T>& v) {
  bool first = true;
  os << "{";
  for (auto ii = v.begin(); ii != v.end(); ++ii) {
    if(!first) os << ", ";
    os << *ii;
    first = false;
  }
  return os << "}";
}
template<typename T>
inline ostream &operator << (ostream & os,const unordered_set<T>& v) {
  bool first = true;
  os << "{";
  for (const auto &x : v) {
    if(!first) os << ", ";
    os << x;
    first = false;
  }
  return os << "}";
}
template<typename T1, typename T2>
inline ostream &operator << (ostream & os,const map<T1, T2>& v) {
  bool first = true;
  os << "{";
  for (const auto &e : v) {
    if(!first) os << ", ";
    os << e;
    first = false;
  }
  return os << "}";
}
template<typename T>
ostream &operator << (ostream & os,const vector<vector<T>>& v) {
  for (auto &u: v) os << '\n' << u;
  return os;
}
template<typename T>
void finish(T ans) {cout << ans << '\n'; exit(0);}
int const MOD = 1e9 + 7;
long long const INF = 1e18;
#define PI 3.14159265358979323846
/***********************************************************************/
signed main() {

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

  int ans = 0, n;
  cin >> n;
  int a = 0, b = 0, ab = 0;
  for (int i = 0; i < n; ++i) {
    string s;
    cin >> s;
    for (int j = 1; j < SZ(s); ++j) {
      if (s[j] == 'B' && s[j - 1] == 'A') ++ans;
    }
    b += s[0] == 'B';
    a += s.back() == 'A';
    ab += (s[0] == 'B' && s.back() == 'A');
  }
  b -= ab;
  a -= ab;
  if (ab > 1) {
    ans += ab - 1;
    ab = 1;
  }
  if (ab > 0) {
    if (a > 0) --a, ++ans;
    if (b > 0) --b, ++ans; 
  }
  int m = min(a, b);
  ans += m;
  cout << ans << '\n';
  
  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
char s[5];
bool vis[5];
int main() {
	scanf("%s",s);
	for(int i=0;i<=2;i++)
		vis[s[i]%3]=true;
	for(int i=0;i<=2;i++)
		if(vis[i]==false) {
			printf("No\n");
			return 0;
		}
	printf("Yes\n");
	return 0;
}

Measured memory_bytes: 128
//参考：https://qiita.com/DaikiSuyama/items/9dba963ba74396b9b7fd
//インクルード(アルファベット順)
#include <algorithm>     //sort,二分探索,など
#include <bitset>        //固定長bit集合
#include <cmath>         //pow,logなど
#include <complex>       //複素数
#include <deque>         //両端アクセスのキュー
#include <functional>    //sortのgreater
#include <iomanip>       //setprecision(浮動小数点の出力の誤差)
#include <iostream>      //入出力
#include <iterator>      //集合演算(積集合,和集合,差集合など)
#include <map>           //map(辞書)
#include <numeric>       //iota(整数列の生成),gcdとlcm(c++17)
#include <queue>         //キュー
#include <set>           //集合
#include <stack>         //スタック
#include <string>        //文字列
#include <unordered_map> //イテレータあるけど順序保持しないmap
#include <unordered_set> //イテレータあるけど順序保持しないset
#include <utility>       //pair
#include <vector>        //可変長配列

using namespace std;
typedef long long ll;

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= (ll)(b); i++)
#define FORD(i, a, b) for (ll i = a; i >= (ll)(b); i--)
//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(), (x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size())      //sizeをsize_tからllに直しておく
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007    //10^9+7:合同式の法
#define MAXR 100000       //10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define FIR first    //pairの一つ目の要素
#define SEC second   //pairの二つ目の要素

signed main()
{
    //入力の高速化用のコード
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int N;
    cin >> N;

    vector<vector<vector<int>>> A(N);
    int a;
    REP(i, N)
    {
        cin >> a;
        A[i] = vector<vector<int>>(a, vector<int>(2));
        REP(j, a)
        {
            cin >> A[i][j][0] >> A[i][j][1];
        }
    }

    ll ans = 0;
    //正直者と不親切な人の組み合わせを表す
    REP(i, 1 << N)
    {
        bool is_conflict = false;
        //各人の証言を精査する
        REP(j, N)
        {
            //人jを正直者と仮定していない場合、証言の精査を行わない
            if (!(i >> j & 1))
                continue;

            REP(k, SIZE(A[j]))
            {
                //仮定と証言を比べて矛盾が無いか確かめる
                if ((i >> (A[j][k][0] - 1) & 1) != A[j][k][1])
                {
                    is_conflict = true;
                    break;
                }
            }

            if (is_conflict)
                break;
        }
        //矛盾がない場合、正直者の最大値を更新しているか確かめる
        if (!is_conflict)
        {
            bitset<15> bs(i);
            if (bs.count() > ans)
                ans = bs.count();
        }
    }

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


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

using namespace std;
#define ll long long

ll INF = 1e9 + 7;
const int N = 1e5 + 7;

int main(){

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

    int n;
    cin>>n;
    vector<ll> arr(n);

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

    ll sum = 0;
    ll prod = 0;

    for(int i=0;i<n;i++)
    {
        prod = (prod + sum * arr[i]) %INF;
        sum = (sum + arr[i]) %INF;
    }

    cout<<(prod + INF)%INF<<endl;
}


Measured memory_bytes: 4776
import java.util.*;
public class Main {
	static int[] a = new int [50];
	static int[] b = new int [50];
	static int[] c = new int [50];
	static int[] d = new int [50];
	static int n,m,q;
	static int ans = 0;
	public static void main(String[] args)  {
		Scanner scan = new Scanner(System.in);
		n = Integer.parseInt(scan.next());
		m = Integer.parseInt(scan.next());
		q = Integer.parseInt(scan.next());

		for (int i = 0;i < q; ++i){
			a[i] = Integer.parseInt(scan.next());
			b[i] = Integer.parseInt(scan.next());
			c[i] = Integer.parseInt(scan.next());
			d[i] = Integer.parseInt(scan.next());
		}
		Vector<Integer> vec = new Vector<>();
		vec.add(1);
		dfs(vec);
		System.out.print(ans);
	}

	static void dfs(Vector<Integer> A){
		A = new Vector<Integer>(A);
		if (A.size() == n+1){
			int score = 0;
			for (int i = 0;i < q; ++i){
				if (A.get(b[i]) - A.get(a[i]) == c[i] )score += d[i];
				ans = Math.max(ans, score);
			}
		}else{
			int tmp;
			A.add(A.lastElement());
			while(A.lastElement() <= m){
				dfs(A);
				tmp = A.lastElement()+1;
				A.remove(A.size()-1);
				A.add(tmp);
			}
		}
	}
}

//end

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

int main(int argc, char const *argv[])
{
	int n,k,ans=0;
	cin>>n>>k;
	while (n>0)
	{
		n/=k;
		++ans;
	}
	cout<<ans<<endl;
	return 0;
}


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

using namespace std;

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

int main()
{
  int N, M, K, S;
  int P, Q;
  vector< vector<int> > G(100011);
  cin >> N >> M >> K >> S;
  cin >> P >> Q;
  queue<int> que;
  ll dist[100011] = {0};
  for(int i = 0; i < K; i++){
    int C;
    cin >> C;
    --C;
    que.push(C);
    dist[C] = S + 1;
  }
  G.resize(N + 1);
  for(int i = 0; i < M; i++){
    int A, B;
    cin >> A >> B;
    --A, --B;
    G[A].push_back(B);
    G[B].push_back(A);    
  }
  while(!que.empty()){
    int now = que.front(); que.pop();
    for(int i = 0; i < G[now].size(); i++){
      int to = G[now][i];
      if(dist[to] >= dist[now] - 1) continue;
      dist[to] = dist[now] - 1;
      que.push(to);      
    }
  }
  priority_queue<PA, vector<PA>, greater<PA> > pq;
  ll cost[100011];
  const ll inf = (1LL << 60);
  fill(cost, cost + 100011, inf);
  pq.push(PA(0, 0));
  cost[0] = 0;
  while(!pq.empty()){
    PA p = pq.top(); pq.pop();
    ll now = p.second, c = p.first;
    if(now == N-1){
      if(dist[N-1] > 0) cout << c - Q << endl;
      else cout << c - P << endl;
      break;
    }
    if(cost[now] < c) continue;
    for(int i = 0; i < G[now].size(); i++){
      int to = G[now][i];
      ll ex = (dist[to] > 0 ? Q : P);
      if(dist[to] >= S+1 || cost[to] <= cost[now] + ex) continue;
      cost[to] = cost[now] + ex;
      pq.push(PA(c + ex, to));
    }
  }
  return 0;
}

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

int main(){
 int n;
  cin>>n;
  int *arr=new int[n];
   long *dp=new long[n];
  for(int i=0;i<n;i++) {
    cin>>arr[i];
   dp[i]=0;
  }
  dp[0]=0;
  dp[1]=abs(arr[1]-arr[0]);
  for(int i=2;i<n;i++){
   dp[i]=min(dp[i-1]+abs(arr[i]-arr[i-1]),dp[i-2]+abs(arr[i]-arr[i-2])); 
  // cout<<dp[i]<<" ";
    }
  long ans=dp[n-1];
  delete [] arr;
  delete [] dp;
  cout<<endl<<ans;
 }

Measured memory_bytes: 1408
import java.math.BigDecimal;
import java.util.Scanner;

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

        double L=sc.nextDouble();

        BigDecimal r=new BigDecimal(Math.pow((L/3), 3));
        System.out.println(r.toPlainString());
    }
}

Measured memory_bytes: 22612
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#define INF 1000000009
#define LINF 1000000000000000009
#define EPS 1e-10
#define PI 3.141592653589793238
#define all(a) a.begin(),a.end()
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;
template<class T> bool chmax(T &a, const T&b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T&b) { if (a > b) { a = b; return 1; } return 0; }
ll gcd(ll n, ll m) { return (m ? gcd(m, n%m) : n); }
ll lcm(ll n, ll m) { return n / gcd(n, m)*m; }

ll mod = 1000000007;

vector<ll> fac(1000010);

ll modinv(ll a) {
	ll b = mod, u = 1, v = 0;
	while (b) {
		ll t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= mod;
	if (u < 0) u += mod;
	return u;
}

void modfac() {
	fac[0] = 1;
	for (ll i = 1; i < 1000010; i++) {
		fac[i] = (fac[i - 1] * i) % mod;
	}
}

ll modperm(ll n, ll k) {
	if (n < 0 || k < 0 || n < k) return 0;
	else return (fac[n] * modinv(fac[n - k])) % mod;
}

ll modcomb(ll n, ll k) {
	if (n < 0 || k < 0 || n < k) return 0;
	else return ((fac[n] * modinv(fac[k])) % mod*modinv(fac[n - k])) % mod;
}

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


int main(){
	ll n, a, b, c;
	cin >> n >> a >> b >> c;
	modfac();
	ll base = modinv(a + b);
	ll ans = 0;
	for (ll i = 0; i < n; i++) {
		ll p = modpow(a, n - 1)*modpow(b, i) % mod*modpow(base, n - 1 + i) % mod;
		p *= modcomb(n - 1 + i, i); p %= mod;
		p *= a; p %= mod;
		p *= base; p %= mod;
		ans += p * (n + i) % mod;
		ans %= mod;
	}
	for (ll i = 0; i < n; i++) {
		ll p = modpow(b, n - 1)*modpow(a, i) % mod*modpow(base, n - 1 + i) % mod;
		p *= modcomb(n - 1 + i, i); p %= mod;
		p *= b; p %= mod;
		p *= base; p %= mod;
		ans += p * (n + i) % mod;
		ans %= mod;
	}
	ans *= 100; ans %= mod;
	ans *= modinv(100 - c); ans %= mod;
	cout << ans << endl;
}

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


/********************************************************************/
#define M1 1000000007
#define M2 998244353
#define ll long long
#define pll pair<ll,ll>
#define REP(i,a,b) for(ll i=a;i<b;i++)
#define REPR(i,a,b) for(ll i=b-1;i>=a;i--)
#define forr(i,n) for(ll i=0;i<n;i++)
#define F first
#define S second
#define pb push_back
#define DB pop_back
#define mp make_pair
#define MT make_tuple
#define V(a) vector<a>
#define vi vector<ll>
#define endl '\n'
#define ce(ele) cout<<ele<<' '
#define cs(ele) cout<<ele<<'\n'
#define CASE(t) ll t; cin>>t; while(t--)
/********************************************************************/
// const int mx = 1e7 + 5;
const double pi = 3.1415926535;
/********************************************************************/
//FAST IO//
void FAST() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
}


/********************************************************************/
int main() {
	FAST();
	ll x,y;
	cin>>x>>y;
	cout<<x*y;
	return 0;
}

Measured memory_bytes: 3608
#include <stdio.h>
#include <stdint.h>
#include <iostream>
#include <fstream>
#include <cassert>
using namespace std;

#define DEBUG (1)

#ifdef DEBUG
#define DPRINT(...)  printf("D(L%d)%s: ", __LINE__, __func__); printf(__VA_ARGS__)
#else
#define DPRINT(...)
#endif

void printArray(int ary[], int size);

int main() {
  int size;
  cin >> size; cin.ignore();
  assert(size > 0);

  int input[size];
  for (int i = 0; i < size; i++) {
    cin >> input[i];
  }
  printArray(input, size);

  for (int i = 1; i < size; i++) {
    int v = input[i];
    int j = i - 1;
    while (j >= 0 && (input[j] > v)) {
      input[j+1] = input[j];
      j--;
    }
    input[j+1] = v;
    printArray(input, size);
  }

  return 0;
}

void printArray(int ary[], int size) {
  for (int i = 0; i < size-1; i++)
    cout << ary[i] << " ";
  cout << ary[size-1] << endl;;
}

Measured memory_bytes: 3072
#include <bits/stdc++.h>
#define pb          emplace_back
#define ll          long long
#define fi          first
#define se          second
#define mp          make_pair
#define int         int64_t

using namespace std;

typedef pair<int, int> pii;
const int N = int(2e5 + 7);
const int inf = int(1e18);

struct TEdge {
    int u, v, w;
    TEdge() {}
    TEdge(int u, int v, int w): u(u), v(v), w(w) {}
    bool operator < (const TEdge& o) const& {
        return w < o.w;
    }
};
int n, m, res, cnte[N], lab[N], w[N];
vector<TEdge> e;

int Find(int x) {return lab[x] < 0? x: lab[x] = Find(lab[x]);}
void Union(int r, int s, int W) {
    if(r != s) {
        if(lab[r] > lab[s]) swap(r, s);
        cnte[r] += cnte[s], w[r] += w[s], lab[r] += lab[s], lab[s] = r;
    }
    if(w[r] >= W) {
        res += cnte[r] + 1;
        cnte[r] = 0;
    } else ++cnte[r];
}

int32_t main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    #define Task        "test"
    if(fopen(Task".inp", "r")) {
        freopen(Task".inp", "r", stdin);
        freopen(Task".out", "w", stdout);
    }
    cin >> n >> m; memset(&lab, -1, sizeof lab);
    for(int i = 1; i <= n; ++i) cin >> w[i];
    e.resize(m); for(TEdge& ed: e) cin >> ed.u >> ed.v >> ed.w;
    sort(e.begin(), e.end());
    for(TEdge& ed: e) Union(Find(ed.u), Find(ed.v), ed.w);
    cout << m - res;
}


Measured memory_bytes: 5888
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def Z(s):
    """
    s: str
    return list of int with length len(s)
    """
    # initialization
    n=len(s)
    z=[0]*n
    z[0]=n
    # construct
    L,R=0,0
    for i in range(1,n):
        if i>=R: # 過去の結果が全く使えない
            L=R=i
            while(R<n and s[R-L]==s[R]): R+=1
            z[i]=R-L
        elif z[i-L]<R-i: # 過去の結果が全て使える
            z[i]=z[i-L]
        else: # 過去の結果が一部使える
            L=i
            while(R<n and s[R-L]==s[R]): R+=1
            z[i]=R-L
    return z
def resolve():
    n=int(input())
    s=input()
    ans=0
    for i in range(n):
        z=Z(s[i:])
        k=len(z) # k=n-i
        for j in range(k):
            ans=max(ans,min(j,z[j]))
    print(ans)
resolve()


Measured memory_bytes: 34716
#include<stdio.h>
int main(void)
{
  int A,B,C;
  int sum;
  
  scanf("%d",&A);
  scanf("%d",&B);
  scanf("%d",&C);
  
  sum=C-(A-B);
  
  if(sum>0)
    printf("%d",sum);
  else
    printf("%d",0);
  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <numeric>
#include <utility>
#include <string>

using namespace std;

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

	long long ans = 0;
	for (int a = 1; a < n; a++) {
		int b_max = (n - 1) / a;
		ans += b_max;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3196
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  int N, D;
  cin>>N>>D;
  if(N%(2*D+1)==0) cout<<N/(2*D+1)<<endl;
  else cout<<N/(2*D+1)+1<<endl;
}



Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for(int i = a; i < b; i++)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
using P = pair<int,int>;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    vector<int> ans(n);
    rep(i,n){
        ans[a[i]-1] = i+1;
    }
    rep(i,n) cout << ans[i] << endl;
    return 0;
}

Measured memory_bytes: 3968
def num(i,j):
    if i==j:
        return -1
    S=bin(i)[2:][::-1]+"0"*20
    T=bin(j)[2:][::-1]+"0"*20
    for index in range(min(len(S),len(T))):
        if S[index]!=T[index]:
            return index+1
    return -1
N=int(input())
a=[[0 for j in range(N-1-i)] for i in range(N-1)]
for i in range(N-1):
    for j in range(i+1,N):
        a[i][j-i-1]=num(i,j)
for i in range(N-1):
    print(*a[i])


Measured memory_bytes: 48088
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <cassert>
#include <cmath>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

typedef long long LL;
typedef pair<int, int> P;
typedef pair<LL, LL> PLL;

const int INF = 1 << 29;

int main() {
    int n;
    vector<P> a;

    cin >> n;
    a.resize(n);
    for (int j = 0; j < n; ++j) {
        cin >> a[j].first >> a[j].second;
    }

    int m[105][105];
    for (int j = 0; j < n; ++j) {
        fill(m[j], m[j] + 105, INF);
        m[j][j] = m[j][j+1] = 0;
    }

    for (int j = 2; j <= n; ++j) {
        for (int k = 0; k + j <= n; ++k) {
            for (int l = 1; l < j; ++l) {
                m[k][k+j] = min(m[k][k+j],
                        m[k][k+l] + m[k+l][k+j] + a[k].first * a[k+l-1].second * a[k+l].first * a[k+j-1].second);
            }
        }
    }

    cout << m[0][n] << endl;

    return 0;
}

Measured memory_bytes: 3016
NAME = [0]*5

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

for _ in range(N):
    s = input()
    if s[0]=="M":
        NAME[0] = NAME[0] + 1
    if s[0]=="A":
        NAME[1] = NAME[1] + 1
    if s[0]=="R":
        NAME[2] = NAME[2] + 1
    if s[0]=="C":
        NAME[3] = NAME[3] + 1
    if s[0]=="H":
        NAME[4] = NAME[4] + 1
ans = 0

for i in range(5-3+1):
    for j in range(i+1, 5-2+1):
        for k in range(j+1, 5):
            ans = ans + NAME[i]*NAME[j]*NAME[k]

print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define all(v) v.begin(),v.end()
using namespace std;
long long h[300005],w[300005],ansh[300005]={},answ[300005]={};
int main(){
    long long H,W,m,h2,w2,ansh2=0,ans=0,answ2=0;
    cin>>H>>W>>m;
    for(int i=0;i<m;i++){
        cin>>h[i]>>w[i];
        ansh[h[i]]++;
        answ[w[i]]++;
    }
    for(int i=1;i<=H;i++){
        if(ansh[i]>ansh2){
            ansh2=ansh[i];
            h2=i;
        }
    }
    bool h3[300005]={false};
    bool w3[300005]={false};
    for(int i=0;i<m;i++){
        if(h2==h[i]){
            h3[w[i]]=true;
        }
    }
    for(int i=1;i<=W;i++){
        long long sum=ansh2;
        if(h3[i]){
            sum+=answ[i]-1;
        }
        else{
            sum+=answ[i];
        }
        if(ans<sum){
            ans=sum;
        }
    }



    for(int i=1;i<=W;i++){
        if(answ[i]>answ2){
            answ2=answ[i];
            w2=i;
        }
    }
    for(int i=0;i<m;i++){
        if(w2==w[i]){
            w3[h[i]]=true;
        }
    }
    for(int i=1;i<=H;i++){
        long long sum=answ2;
        if(w3[i]){
            sum+=ansh[i]-1;
        }
        else{
            sum+=ansh[i];
        }
        if(ans<sum){
            ans=sum;
        }
    }
    cout<<ans<<endl;
    return(0);
}

Measured memory_bytes: 13556
package main

import (
	"fmt"
)

func main() {
	var R int
	fmt.Scan(&R)

	if R < 1200 {
		fmt.Println("ABC")
	} else if R < 2800 {
		fmt.Println("ARC")
	} else {
		fmt.Println("AGC")
	}
}


Measured memory_bytes: 512
def approve(A: list) -> bool:
    is_even = lambda number: number % 2 is 0
    is_odd = lambda number: not is_even(number)
    is_dividable_by_3 = lambda number: number % 3 is 0
    is_dividable_by_5 = lambda number: number % 5 is 0
    is_dividable_by_3_or_5 = lambda number: is_dividable_by_3(number) or is_dividable_by_5(number)
    is_approved = lambda number: (
        is_odd(number) or
        (is_even(number) and is_dividable_by_3_or_5(number)))

    approved = all(map(is_approved, A))

    return approved


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

answer = 'APPROVED' if approve(A) else 'DENIED'

print(answer)


Measured memory_bytes: 3064
#include <iostream>
typedef long long ll;

#include <cstdio>
inline int getInt(){ int s; scanf("%d", &s); return s; }

#include <set>

using namespace std;

const int MAX = 200000 + 10;
const ll mod = 1000000007;
ll f[MAX];

ll mpow(ll b, ll e){
  ll ret = 1;
  while(e){
    if(e & 1) ret = (ret * b) % mod;
    b = (b * b) % mod;
    e /= 2;
  }
  return ret;
}

ll cmb(ll n, ll k){
  return f[n] * mpow(f[k], mod - 2) % mod * mpow(f[n - k], mod - 2) % mod;
}

int main(){
  const int h = getInt();
  const int w = getInt();
  const int a = getInt();
  const int b = getInt();

  f[0] = f[1] = 1;
  for(int i = 2; i < MAX; i++)
    f[i] = (f[i - 1] * i) % mod;


  ll ans = 0;
  for(int i = 0; i < h - a; i++){
    if(i == h - a - 1) {
      const ll left = cmb(i + b, i);
      const ll right = cmb((h - 1 - i) + (w - 1 - b), h - 1 - i) % mod;
      ans = (ans + (left * right) % mod) % mod;
    } else if (b + 1 != w) {
      const ll left = cmb(i + b, i);
      const ll right = cmb((h - 1 - i) + (w - 2 - b), h - 1 - i) % mod;
      ans = (ans + (left * right) % mod) % mod;
    }
  }

  printf("%lld\n", ans);

  return 0;
}


Measured memory_bytes: 1792
import math

def main():
    N, D = list(map(int, input().split()))
    ans = 0
    for i in range(0,N):
        A, B = list(map(int, input().split()))
        dist = math.sqrt(A**2 + B**2)
        if dist <= D:
            ans +=1
    print(ans)


if __name__ == '__main__':
    main()

Measured memory_bytes: 9228
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public  class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        List<Integer> lst = new ArrayList<>();
        for(int i = 0;i < N;i++){
            lst.add(sc.nextInt());
        }
        PrintList(lst);
        for(int i = 1;i < N;i +=1){
            int v = lst.get(i);
            int j = i-1;
            while(0 <= j && lst.get(j) > v){
                lst.set(j+1,lst.get(j));
                j -=1;
            }
            lst.set(j+1,v);
            PrintList(lst);
        }
        
    }

    public static void PrintList(List lst){
        System.out.printf("%d",lst.get(0));
            for(int k = 1;k < lst.size();k +=1){
                System.out.printf(" %d",lst.get(k));
            }
            System.out.println("");
    }
}


Measured memory_bytes: 42504
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <chrono>
#include <random>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <iomanip>
#include<string>
#include <complex>
using namespace std;

#define ll long long
#define f first
#define s second
typedef pair<int , int > pii;
const ll MOD = 1e9+7;
const int N = 1e6+10;


void min_self(ll &a , ll b){
    a=min(a,b);
}

void max_self(ll &a, ll b){
    a=max(a,b);
}

ll add(ll x, ll y)
{
    return (x + y) % MOD;
}

ll sub(ll x, ll y)
{
    return add(x, MOD - y);
}

ll mul(ll x, ll y)
{
    return (x * 1ll * y) % MOD;
}

ll binpow(ll x, ll y)
{
    ll z = 1;
    while(y > 0)
    {
        if(y % 2 == 1)
            z = mul(z, x);
        x = mul(x, x);
        y /= 2;
    }
    return z;
}

ll inv(ll x)
{
    return binpow(x, MOD - 2);
}

ll fact[N];

void fac_pre()
{
    fact[0]=1;
    for(ll i=1; i<N; i++){
        fact[i]=mul(fact[i-1],i);
    }
}
ll C(ll n, ll k)
{
    return mul(fact[n], inv(mul(fact[k], fact[n - k])));
}

ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);

}
// BIT //
const int MAXN=2*1e5+10;
vector<int> bit(MAXN,0);
int sump(int idx) {
    int ret = 0;
    for (++idx; idx > 0; idx -= idx & -idx)
        ret += bit[idx];
    return ret;
}

int sum(int l, int r) {
    return sump(r) - sump(l - 1);
}

void upd(int idx, int delta) {
    for (++idx; idx < MAXN; idx += idx & -idx)
        bit[idx] += delta;
}

/////-----//////

int  main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //freopen("input.txt", "r", stdin);
    /* KEEP IN MIND
     * take care when sorting a 1 based indexed vector
     * const int N is defined way above in the starting
    */
    int MAX=2*1e5+5;
    int n,k; cin>>n>>k;
    vector<int> v(n+1);
    for(int i=1; i<=n; i++){
        cin>>v[i];
    }
    for(int i=1; i<=n; i++){
        int a=v[i];
        int l=max(1,i-a);
        int r=min(i+a,MAX);
        upd(l,1);
        upd(r+1,-1);
    }
    int itr=0;
    while(k--){
        ++itr;
        for(int i=1; i<=n; i++){
            v[i]=sump(i);
        }
        bit.clear();
        bit.resize(MAXN,0);
        for(int i=1; i<=n; i++){
            int a=v[i];
            int l=max(1,i-a);
            int r=min(i+a,MAX);
            upd(l,1);
            upd(r+1,-1);
        }
        bool f=true;
        for(int i=1; i<=n; i++){
            if(v[i] != n) f=false;
        }
        if( f ) break;
    }
    for(int i=1; i<=n; i++){
        cout<<v[i]<<" ";
    }



}

Measured memory_bytes: 4784
#include<algorithm>
#include<cmath>
#include<deque>
#include<fstream>
#include<iomanip>
#include<iostream>
#include<list>
#include<map>
#include<numeric> //xとyの最大公約数は__gcd(x,y),xとyの最小公倍数は(x*y)/__gcd
#include<set>
#include<string>
#include<vector>

#include<stack>
#include<queue>
#include<utility>
#include<tuple>
#include<cstdio>
#include<cstdlib>
#define rep(i,n) for(int i=0; i<n; i++)
typedef long long ll;
using namespace std;

int main(){
  int n;
  cin >> n;
  vector<int> w(n);
  rep(i,n){
    cin >> w[i];
  }
  int front = 0, rear = 0, i = 0, j = n-1;
  while (i <= j) {
    if(front <= rear){
      front += w[i];
      i++;
    }else{
      rear += w[j];
      j--;
    }
  }
  cout << abs(front-rear);
  return 0;
}


Measured memory_bytes: 256
import bisect
N = int(input())
S = set([7,5,3])
for i in range(8):
    for j in S.copy():
        for k in [7,5,3]:
            S.add(int(str(j)+str(k)))
S = list(sorted(S))
T = []
for i in S:
    if str(i).count('3') and str(i).count('5') and str(i).count('7'):
        T.append(i)
print(bisect.bisect_right(T,N))

Measured memory_bytes: 6936
l=[0]*5
n=int(input())
for i in range(n):
  s=input()
  a=s[0]
  if a=='M':
    l[0]+=1
  elif a=='A':
    l[1]+=1
  elif a=='R':
    l[2]+=1
  elif a=='C':
    l[3]+=1
  elif a=='H':
    l[4]+=1
print(l[0]*l[1]*l[2]
  +l[0]*l[1]*l[3]
  +l[0]*l[1]*l[4]
  +l[0]*l[2]*l[3]
  +l[0]*l[2]*l[4]
  +l[0]*l[3]*l[4]
  +l[1]*l[2]*l[3]
  +l[1]*l[2]*l[4]
  +l[1]*l[3]*l[4]
  +l[2]*l[3]*l[4])

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <list>
#include<utility>
#include <new>
#include <string>
#include<cmath>
#include<unordered_set>
#include<iomanip>
#include<algorithm>
#include<bits/stdc++.h>
using namespace std;
#define forloop(i,x,z) for (int i=x;i<z;i++)
using ll = unsigned long long int;
/*bool cmp(pair<ll,ll>a,pair<ll,ll>b){
return a.second<b.second;
}*/
int main()
{ll n,k=0;
	cin >> n;
        ll A[n];
        forloop(i,0,n){
                cin>>A[i];
        }
ll p=1000;
        for(int i=0;i<n-1;i++){
            if(A[i]<A[i+1]){
            k=p%A[i];
              p=p/A[i];
              p=p*A[i+1]+k;
            }
        }
        cout<<p;
	return 0;
}


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

using namespace std;
using ll = unsigned long long;
constexpr int mod = 1e9+7;
constexpr int md = mod;
int main(){
    int n,m;
    cin>>n>>m;
    vector<ll> a(n);
    map<ll,int> bc;
    ll sum = 0ll;
    for(auto & b : a ){ cin>>b;sum+= b;}
    for(int i=0;i<m;++i) {
        int b;
        ll c;
        cin>>b>>c;
        bc[c] += b;
    }
    sort(a.begin(),a.end());
    bool last = false;
    int cur = 0;
    for(auto i = bc.rbegin();i != bc.rend(); ++i){
        for(int j=0;j<min(n,i->second);++j){
            if((a[cur] >= i->first) || cur == n){ last = true;break;}
            sum += i->first - a[cur];
            cur++;
        }
        if(last)break;
    }
    cout << sum << endl;
    return 0;
}



Measured memory_bytes: 7296
#![allow(non_snake_case, unused_macros, unused_imports)]

// Input
macro_rules! input { (source = $s:expr, $($r:tt)*) => { let mut iter = $s.split_whitespace(); let mut next = || { iter.next().unwrap() }; input_inner!{next, $($r)*} }; ($($r:tt)*) => { let stdin = std::io::stdin(); let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock())); let mut next = move || -> String{ bytes.by_ref().map(|r|r.unwrap() as char).skip_while(|c|c.is_whitespace()).take_while(|c|!c.is_whitespace()).collect() }; input_inner!{next, $($r)*} }; }
macro_rules! input_inner { ($next:expr) => {}; ($next:expr, ) => {}; ($next:expr, $var:ident : $t:tt $($r:tt)*) => { let $var = read_value!($next, $t); input_inner!{$next $($r)*} };}
macro_rules! read_value { ($next:expr, ( $($t:tt),* )) => { ( $(read_value!($next, $t)),* ) }; ($next:expr, [ $t:tt ; $len:expr ]) => { (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>() }; ($next:expr, chars) => { read_value!($next, String).chars().collect::<Vec<char>>() }; ($next:expr, bytes) => { read_value!($next, String).into_bytes() }; ($next:expr, usize1) => { read_value!($next, usize) - 1 }; ($next:expr, $t:ty) => { $next().parse::<$t>().expect("Parse error") }; }

// Module
use std::cmp::{min,max};
use std::collections::{HashSet,BTreeMap,VecDeque};

// Fn 
fn dfs(i:u64, b3:bool, b5:bool, b7:bool, N:u64) -> u64{
    // オーバーしてたら終了
    if i > N{
        return 0;
    }
    // オーバーしていなければカウントしていく
    let mut k = 0;
    // 3,5,7全て含んでいれば +1
    if b3 && b5 && b7{
        k += 1;
    }
    // 桁を繰り上げて調べる
    k += dfs(i*10+3, true, b5, b7, N);
    k += dfs(i*10+5, b3, true, b7, N);
    k += dfs(i*10+7, b3, b5, true, N);
    // 数え上げた数字を返す
    return k;
}

// Main
fn main(){
    input!{
        N: u64
    }
    let ans = dfs(0, false, false, false, N);
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
#define endl '\n';
using namespace std;
using ll = long long;
using P = pair<int,int>;
constexpr ll INF = 9e18;
constexpr int inf = 1e9;
constexpr double INFD = 1e100;
constexpr ll mod = 1000000007;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// ---------------------------------------------------------------------------

int main(){
  int N,K;
  cin >> N >> K;
  if((N-1)*(N-2)/2 < K){
    cout << -1 << endl;
    return 0;
  }
  vector<P> ans;
  for(int i=2; i<=N; i++){
    ans.emplace_back(1,i);
  }
  int vi=2,vj=3;
  for(int i=0; i<(N-1)*(N-2)/2-K; i++){
    ans.emplace_back(vi,vj);
    if(vj == N){
      vi++;
      vj = vi;
    }
    vj++;
  }
  cout << ans.size() << endl;
  for(int i=0; i<ans.size(); i++){
    cout << ans[i].first << " " << ans[i].second << endl;
  }
  return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main(){
  ios::sync_with_stdio(false);
  long long n,a,b,c,i;cin >> n >> a >> b >> c;
  string s[n];char ans[n];
  for(i=0;i<n;i++) cin >> s[i];
  for(i=0;i<n;i++){
    if(s[i]=="AB"){
      if(a==0 && b==0){
        cout << "No" << "\n";return 0;
      } else if(a>b || (a==b && a>=2)){
        ans[i] = 'B';a--;b++;
      } else if(a<b){
        ans[i] = 'A';a++;b--;
      } else {
        if(i+1==n) ans[i]='A';
        else if(s[i+1]=="BC"){
          ans[i] = 'B';b++;a--;
        } else {
          ans[i] = 'A';a++;b--;
        }
      }
    } else if(s[i]=="AC"){
      if(a==0 && c==0){
        cout << "No" << "\n";return 0;
      } else if(a>c || (a==c && a>=2)){
        ans[i] = 'C';a--;c++;
      } else if(a<c){
        ans[i] = 'A';a++;c--;
      } else {
        if(i+1==n) ans[i]='A';
        else if(s[i+1]=="BC"){
          ans[i] = 'C';c++;a--;
        } else {
          ans[i] = 'A';a++;c--;
        }
      }
    } else if(s[i]=="BC"){
      if(b==0 && c==0){
        cout << "No" << "\n";return 0;
      } else if(b>c || (b==c && b>=2)){
        ans[i] = 'C';b--;c++;
      } else if(b<c){
        ans[i] = 'B';b++;c--;
      } else {
        if(i+1==n) ans[i]='B';
        else if(s[i+1]=="AC"){
          ans[i] = 'C';c++;b--;
        } else {
          ans[i] = 'B';b++;c--;
        }
      }
    }
  }
  cout << "Yes" << "\n";
  for(i=0;i<n;i++) cout << ans[i] << "\n";
  return 0;
}
    
  

Measured memory_bytes: 6888
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

n = ni()
a = list(li())

a.sort()
print(sum(a[n::2]))

Measured memory_bytes: 37084
#pragma GCC optimize("Ofast","inline","-ffast-math")
#pragma GCC target("avx,sse2,sse3,sse4,mmx")
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/hash_policy.hpp>
//#define int long long
using namespace __gnu_pbds;
using namespace std;

int n;
char s[20];
vector<string> v;

inline void dfs(int lvl,int maxv)
{
	if(lvl==n+1){
		string x;
		for(int i=1;i<=n;i++) x+=s[i];
		v.push_back(x);
		return;
	}
	for(int i=1;i<=maxv+1;i++){
		s[lvl]=char('a'+i-1);
		dfs(lvl+1,max(maxv,i));
	}
}

signed main()
{
	ios::sync_with_stdio(false);
	cin>>n;	
	dfs(1,0);
	sort(v.begin(),v.end());
	for(int i=0;i<v.size();i++){
		cout<<v[i]<<endl;
	}
	return 0;
}

Measured memory_bytes: 9716
#include<bits/stdc++.h>
#include<cmath>
#include<string>
using namespace std;
#define f first
//#define s second
#define MOD 1000000007
#define fast ios::sync_with_stdio(0),cout.tie(0),cin.tie(0)
#define pb push_back
#define fo(i,a,b) for(i=a;i<b;i++)
#define foe(i,a,b) for(i=a;i<=b;i++)
#define mp make_pair
#define mkt make_tuple
#define nax (ll)1e6+2
typedef long long ll;
typedef unsigned long long ull;
class solution{
public: 
	void solve(){
		int a1,a2,a3;
		cin>>a1>>a2>>a3;
		int ans = a1+a2+a3;
		if(ans>=22){
			cout<<"bust";
		}
		else{
			cout<<"win";
		}
	}
};

int main()
{
    fast;
	ll i=0;
	solution s;
	s.solve();

 return 0;
}



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

#ifdef DBG
    #define D(y) y
#else
    #define D(y)
#endif

using namespace std;

const long long inf = 1023456789;
const long long INF = inf * inf;

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

    int N;
    long long K;
    cin >> N >> K;

    vector<long long> positives, negatives;
    for (int i = 0; i < N; ++i) {
        int x;
        cin >> x;
        if (x < 0) {
            negatives.push_back(-x);
        } else {
            positives.push_back(x);
        }
    }
    sort(negatives.begin(), negatives.end());
    sort(positives.begin(), positives.end());

    long long non_positive_products = positives.size() * (long long) negatives.size();

    auto count_less_or_eq_helper = [](long long threshold, const vector<long long> v1, const vector<long long> v2, bool subtract_dups) {
        long long count = 0;
        D(cout << "less or eq" << endl;);

        int v2_idx = v2.size() - 1;
        for (int v1_idx = 0; v1_idx < v1.size(); ++v1_idx) {
            while (v2_idx >= 0 && v1[v1_idx] * v2[v2_idx] > threshold) {
                v2_idx--;
            }

            count += v2_idx + 1;

            D(cout << v1_idx << " " << v2_idx << endl;);
        }

        if (subtract_dups) {
            for (int v1_idx = 0; v1_idx < v1.size(); ++v1_idx) {
                if (subtract_dups && v1[v1_idx] * v1[v1_idx] <= threshold) {
                    count--;
                }
            }

            count /= 2;
        }

        return count;
    };

    auto count_greater_or_eq_helper = [&](long long threshold, const vector<long long> v1, const vector<long long> v2) {
        long long less_or_eq_count = count_less_or_eq_helper(threshold - 1, v1, v2, false);
        long long overall_count = v1.size() * (long long) v2.size() - less_or_eq_count;
        return overall_count;
    };

    auto count_less_or_eq = [&](long long threshold) {
        D(cout << "threshold = " << threshold << endl;);
        if (threshold >= 0) {
            long long count = 0;
            count += non_positive_products;
            count += count_less_or_eq_helper(threshold, negatives, negatives, true);
            count += count_less_or_eq_helper(threshold, positives, positives, true);
            D(cout << "count = " << count << endl;);
            return count;
        } else {
            long long count = count_greater_or_eq_helper(-threshold, positives, negatives);
            D(cout << "count = " << count << endl;);
            return count;
        }
    };

    // find first number such that # products <= is >= K
    long long low = -INF, high = INF;
    while (low < high) {
        long long mid = low + (high - low) / 2;

        if (count_less_or_eq(mid) < K) {
            low = mid + 1;
        } else {
            high = mid;
        }
    }

    cout << high << endl;

    return 0;
}


Measured memory_bytes: 5104
'use strict'
function main(input) {
  input = input.trim().split('\n')
  let ABC = input.shift().split(' ').map(v => Number(v))
  const N = ABC.shift()
  input = input.map(v => Number(v)).sort((a, b) => b - a)
  const INF = Math.pow(10, 9)

  const dfs = (cur, a, b, c) => {
    if (cur === N) {
      if (Math.min(a, b, c) > 0) {
        return Math.abs(a - ABC[0]) + Math.abs(b - ABC[1]) + Math.abs(c - ABC[2]) - 30
      }
      return INF
    }
    return Math.min(
      dfs(cur+1, a, b, c),
      dfs(cur+1, a + input[cur], b, c) + 10,
      dfs(cur+1, a, b + input[cur], c) + 10,
      dfs(cur+1, a, b, c + input[cur]) + 10
    )
  }
  console.log(dfs(0,0,0,0))
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


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

using namespace std;

struct Says
{
	int x, y;
};

int a[20];
Says x[20][20];
int honest[20];
int n;

bool check(int s)
{
	int i, j;
	for (i=0; i<n; i++) if (s&(1<<i)) honest[i] = 1; else honest[i] = 0;
	for (i=0; i<n; i++)
		if (honest[i])
		{
			for (j=0; j<a[i]; j++) if (x[i][j].y != honest[x[i][j].x]) return false; 
		}
	return true;	
}

int main()
{
	int res, i, j;
	cin>>n;
	for (i=0; i<n; i++)
	{
		cin>>a[i];
		for (j=0; j<a[i]; j++) 
		{
			cin>>x[i][j].x>>x[i][j].y;
			x[i][j].x --;
		}
	}
	res = 0;
	for (i=0; i<(1<<n); i++) if (check(i)) res = max(res, __builtin_popcount(i));
	cout<<res<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <utility>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
     int N;
     cin >> N;
     vector<pair<int, int>> A(N);
     for (int i {}, t; i < N; i++) {
          cin >> t;
          A[i] = make_pair(i + 1, t);
     }
     sort(A.begin(), A.end(), [](const auto& p, const auto& q) { return p.second < q.second; });
     for (const auto& p : A) cout << p.first << " ";
     cout << endl;
}

Measured memory_bytes: 1536
#include <stdio.h>

int main(void){
	int a[100],i=0;
	while(scanf("%d",&a[i]) != EOF)
	{
		if(a[i] == 0){
			while(1){
				i--;
				if(a[i] != 0){
					printf("%d\n",a[i]);
					a[i]=0;
					break;
				}
			}
		}
		i++;
	}

	return 0;
}

Measured memory_bytes: 600