akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define ls rt<<1
#define rs rt<<1|1
#define lson rt<<1,l,M
#define rson rt<<1|1,M+1,r
#define PI acos(-1)
#define MM int M=(l+r)>>1;
#define fu(i,r,t) for(int i=r;i<=t;i++)
#define fd(i,r,t) for(int i=r;i>=t;i--)
#define fh(i,be,e) for(int i=head[be];~i;i=e[i].next)
#define fa(i,V) for(auto i:V)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long
#define endl '\n'
#define lcm(a,b) (a*b)/__gcd(a,b)
#define cp(i,ans) printf("%.if",ans);
#define cpp(i,ans) cout<<setprecision(i)<<fixed<<ans<<endl;
#define ppb pop_back
#define ppf pop_front
#define pb push_back
#define pf push_front
#define pq priority_queue
#define lowbit(x) (x)&(-x)
#define all(V) V.begin(),V.end()
#define ms multiset
#define mod(x) ((x+mo_num)%mo_num)
#define vc vector
#define vct vector<int>
#define out(i) cout<<(i)<<endl;
#define fi first
#define se second
#define fun(i) fu(i,1,n)
#define fut(i) fu(i,1,t)
#define fum(i) fu(i,1,m)
#define ld long double
#define umap unordered_map
#define P pair<int,int>
#define SET set<int>
#define mp map<int,int>
#define mk make_tuple
#define low lower_bound
#define upp upper_bound
#define yn(key) out(key?"YES":"NO")
#define in(i) i+1,i+1+n
#define im(i) i+1,i+1+m
#define bffs(i) __builtin_ffs(i)
#define bcount(i) __builtin_popcount(i)
#define bone(i) ((1<<i)-1)
using namespace std;
const int INF=LLONG_MAX/2;
const int dx[]={0,0,-1,1},dy[]={-1,1,0,0};//up down left right
const int maxn=1e6+1e5;
const int mo_num=1e9+7;
int n,m,t,a[maxn],b[maxn],ans;

main()
{
    IOS
    cin>>n;
    m=n%10;
    if(m==2 or m==4 or m==5 or m==7 or m==9){out("hon")return 0;}
    if(m==0 or m==1 or m==6 or m==8){out("pon")return 0;}
    if(m==3){out("bon")return 0;}
    return 0;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef long long ll;
const int MOD = (int)1e9 + 7;
const int INF = 1e18;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define ALL(obj) (obj).begin(), (obj).end() //コンテナじゃないと使えない!!
#define debug(x) cerr << #x << ": " << x << "\n";
//cin,coutより遅いので注意
template <class T = int>
void in() //in<string>();とか書く intのときはそのままin();
{
    T x;
    cin >> x;
    return (x);
}
template <class T>
void print(T &x) { cout << x << "\n"; }

signed main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<int> A(N);
    REP(i, N)
    {
        cin >> A[i];
    }
    vector<int> cumsum(N);
    cumsum[0] = A[0];
    for (int i = 1; i < N; i++)
    {
        cumsum[i] = cumsum[i - 1] + A[i];
    }
    int ans = INF;
    for (int i = 0; i < N - 1; i++)
    {
        ans = min(ans, abs(2 * cumsum[i] - cumsum.back()));
    }
    cout << ans << "\n";
}

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

bool sum_formula(string s, int x){

  //cout << "sum_formula(" << s << "," << x << ")" << endl;

  int s0 = s.at(0) - '0';
  
  if(s.size() == 1){
    if(s0 == x){
      cout << s0;
      return true;
    }
    else{
	return false;
      }
  }

  int t = s.at(s.size()-1) - '0';

  if(sum_formula(s.substr(0,s.size()-1), x-t)){
    cout << "+" << t;
    return true;
  }else if(sum_formula(s.substr(0,s.size()-1), x+t)){
    cout << "-" << t;
    return true;
  }else{
    return false;
  }
}
    
  
int main(){
  string s;
  cin >> s;

  sum_formula(s,7);
  cout << "=7" << endl;
}


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

using namespace std;

int main()
{
    long long MOD=1e9+7;
    string s;
    cin>>s;
    int maxn=s.size();
    long long dp[maxn+1][13];
    for(int i=0;i<=maxn;i++)
    {
        for(int j=0;j<=12;j++)
        {
            dp[i][j]=0;
        }
    }
    dp[0][0]=1;

    for(int i=0;i<maxn;i++)
    {
        for(int j=0;j<=9;j++)
        {
            int res;
            if(s[i]=='?'){
                res=j;
            }
            else{
                res=s[i]-'0';
            }
            for(int k=0;k<=12;k++)
            {
                int rem=(10*k+res)%13;
                dp[i+1][rem]+=dp[i][k];
                dp[i+1][rem]%=MOD;
            }
            if(s[i]!='?')
                break;
        }
    }
    cout<<dp[maxn][5]<<endl;
}


Measured memory_bytes: 10624
#include <iostream>
using namespace std ;
int main(){
	int x , y , number[101] , i , j , k , cn= 0 ;
	while ( 1 ){
		cn = 0 ;
	cin >> x >> y ;
	if ( x + y == 0 ) break ;
	for ( i = 1 ; i<=x ; i ++ ){
		number[i] = i ;
	}
	for ( i = 1 ; i <= x ; i ++ ){
		for ( j = i + 1 ; j <= x ; j ++ ){
			for ( k = j + 1 ; k <= x ; k ++ ){
				if ( number[i] + number[j] + number[k] == y ){
					cn ++ ;
				}
			}
		}
	}
	cout << cn << endl ;
}
}

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

int N, K, a[1000000];
int main()
{
  while(true)
  {
    cin >> N >> K;
    if(!N)
      break;
    int v = 0;
    for(int i = 0; i < N; i++)
    {
      cin >> a[i];
      if(i < K)
        v += a[i];
    }
    int ans = v;
    for(int i = K; i < N; i++)
      ans = max(ans, v = v + a[i] - a[i - K]);
    cout << ans << endl;
  }
}

Measured memory_bytes: 1552
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T> V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> > Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T> mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }


/*
 update : [s,t) に xを加算
 query  : [s,t) の　最大(小)値を出力する
 */

/* [0..N-1] */
const ll INIT = 0; // 問題に合わせる
struct SegTree {
    int N;
    ll init_v;
    vector<ll> node, lazy;
    
    SegTree(int _N):init_v(INIT) {
        N = 1;
        while (N < _N) N *= 2;
        node.resize(2 * N - 1, init_v);
        lazy.resize(2 * N - 1, init_v);
    }
    
    ll merge(ll l,ll r){
        return min(l,r);
    }
    
    void lazy_evaluate(int l, int r,int k){
        node[k] += lazy[k];
        if(r - l > 1){
            lazy[2 * k + 1] += lazy[k];
            lazy[2 * k + 2] += lazy[k];
        }
        lazy[k] = 0;
    }
    
    /* [a,b) 引数の範囲に注意!! s~tまでを更新→update(s,t+1,~) */
    void update(int a, int b, ll x) { update(a, b, 0, 0, N, x); }
    void update(int a, int b, int k, int l, int r, ll x) {
        lazy_evaluate(l,r,k);
        if (r <= a || b <= l) return;
        if (a <= l && r <= b) {
            lazy[k] += x;
            lazy_evaluate(l,r,k);
        }
        else {
            update(a, b, 2 * k + 1, l, (l + r) / 2, x);
            update(a, b, 2 * k + 2, (l + r) / 2, r, x);
            node[k] = merge(node[2 * k + 1],node[2 * k + 2]);
        }
    }
    
    /* [a,b) 引数の範囲に注意!! */
    ll query(int a, int b) { return query(a, b, 0, 0, N); }
    ll query(int a, int b, int k, int l, int r) {
        lazy_evaluate(l, r, k);
        if (r <= a || b <= l) return LLONG_MAX; // min : LLONG_MAX , max : LLONG_MIN
        if (a <= l && r <= b) {
            return node[k];
        }
        else {
            ll vl = query(a, b, 2 * k + 1, l, (l + r) / 2);
            ll vr = query(a, b, 2 * k + 2, (l + r) / 2, r);
            return merge(vl, vr);
        }
    }
};

int main(){
    cin.tie(0); ios_base::sync_with_stdio(false);
    int n; cin >> n;
    SegTree ST(n);
    int q; cin >> q;
    while(q--){
        int com; cin >> com;
        if(com == 0){
            int s,t,x; cin >> s >> t >> x;
            ST.update(s-1,t,x);
        }else{
            int i; cin >> i;
            cout << ST.query(i-1,i) << endl;
        }
    }
}



Measured memory_bytes: 7068
#include <iostream>
#include <string>

const int MAX = 36;

struct CARD {
    char suit;
    int value;
};

void BubbleSort(CARD *C, int n)
{
    for (int i = 0; i < n; ++i) {
        for (int j = n-1; j > i; --j) {
            if (C[j].value < C[j-1].value) {
                CARD save = C[j];
                C[j] = C[j-1];
                C[j-1] = save;
            }
        }
    }
}

void SelectionSort(CARD *C, int n)
{
    for (int i = 0; i < n; ++i) {
        int min = i;
        for (int j = i; j < n; ++j) {
            if (C[j].value < C[min].value) {
                min = j;
            }
        }
        if (i != min) {
            CARD save = C[i];
            C[i] = C[min];
            C[min] = save;
        }
    }
}

bool isStable(CARD *C1, CARD *C2, int n)
{
    for (int i = 0; i < n; ++i) {
        if (C1[i].suit != C2[i].suit && C1[i].value == C2[i].value)
            return false;
    }
    return true;
}

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

    int N;
    CARD C1[MAX], C2[MAX];
    std::cin >> N;
    for (int i = 0; i < N; ++i) {
        char in[3];
        std::cin >> in;
        C1[i].suit = in[0];
        C1[i].value = in[1] - '0';
        C2[i].suit = in[0];
        C2[i].value = in[1] - '0';
    }
    BubbleSort(C1, N);
    SelectionSort(C2, N);
    for (int i = 0; i < N; ++i) {
        std::cout << C1[i].suit << C1[i].value;
        if (i != N-1) std::cout << " ";
        else std::cout << std::endl;
    }
    std::cout << "Stable" << std::endl;
    for (int i = 0; i < N; ++i) {
        std::cout << C2[i].suit << C2[i].value;
        if (i != N-1) std::cout << " ";
        else std::cout << std::endl;
    }
    if (isStable(C1, C2, N))
        std::cout << "Stable" << std::endl;
    else
        std::cout << "Not stable" << std::endl;

    return 0;
}



Measured memory_bytes: 3208
#include <bits/stdc++.h>
#define fto(i,a,b) for(int i=a; i<=b;++i)
#define fdto(i,a,b) for(int i=a; i>=b;--i)
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pii pair<ll,ll>
#define ll long long
#define maxn 300009
#define gb(i,j) ((i>>j)&1)
#define name "a"
#define endl '\n'

using namespace std;

const int mod=1e9+7;

string S;
int s1[maxn],s2[maxn];

main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> S;
    int n=0;
    for(char c:S){
        ++n;
        s1[n]=s1[n-1];
        if(c=='A')s1[n]+=1;
        else s1[n]+=2;
    }
    cin >> S;
    int m=0;
    for(char c:S){
        ++m;
        s2[m]=s2[m-1];
        if(c=='A')s2[m]+=1;
        else s2[m]+=2;
    }
    int q;
    cin >> q;
    while(q--){
        int x,y,u,v;
        cin >> x >> y >> u >> v;
        if((s1[y]-s1[x-1]-s2[v]+s2[u-1])%3==0)cout <<"YES\n";
        else cout << "NO\n";
    }
    return 0;
}


Measured memory_bytes: 1616
from collections import deque

class Node():
    def __init__(self, val):
        self.val = val
        self.sign = None
        self.adj = []

n, m = map(int, input().split())
a, b = [], []
nodes = []

for i in range(n):
    node = Node(i+1)
    nodes.append(node)

for i in range(m):
    A, B = map(int, input().split())
    nodeA, nodeB = nodes[A-1], nodes[B-1]
    nodeA.adj.append(nodeB)
    nodeB.adj.append(nodeA)
    # a.append(A)
    # b.append(B)

q = deque()
q.append(nodes[0])
done = set()

while q:
    node = q.popleft()
    parent = node.val

    for adj in node.adj:
        if adj not in done:
            done.add(adj)
            adj.sign = parent
            q.append(adj)
            
print('Yes')            

for i in range(1, len(nodes)):
    print(nodes[i].sign)

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

float ab(float x) {
    if (x > 0) return x;
    else return -x;
}

int main() {
    int N;
    float T, A;
    cin >> N >> T >> A;
    float H[N];
    for (int i = 0; i < N; i++) cin >> H[i];
    int ans;
    float temp_diff = 10000;
    for (int i = 1; i <= N; i++) {
        float d = ab(A - (T - H[i-1] * 0.006));
        if (d < temp_diff) {
            ans = i;
            temp_diff = d;
        }
    }
    cout << ans << endl;
}


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

using namespace std;

using ll = long long;
using ld = long double;

using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vs = vector<string>;
using vld = vector<ld>;
using vvld = vector<vld>;

typedef pair<ll, ll> P;

#define bit(n) (1LL << (n))

//#define int long long

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

#define rep(i, n) for (ll i = 0; i < n; i++)
#define REP(i, n) for (ll i = 1; i < n; i++)

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORm(i, m) for (auto i = m.begin(); i != m.end(); i++)

template <class T>
inline void chmax(T& a, T b) {
  a = std::max(a, b);
}
template <class T>
inline void chmin(T& a, T b) {
  a = std::min(a, b);
}

#define mod (ll)(1e9 + 7)
// #define mod (998244353ll)

const long long INF = 1LL << 60;

// const long long INF = 1LL << 60;

template <typename T>
struct Edge {
  int to;
  T cost;
};

// Dijkstra
template <typename T>
class Dijkstra {
 private:
  vector<vector<Edge<T>>> G;
  int num_v;

 public:
  Dijkstra(int num_v) : G(num_v), num_v(num_v) {
  }

  void add_edge(int from, int to, T cost) {
    G[from].push_back((Edge<T>){to, cost});
  }

  // start: Start point
  // result: result
  void solve(int start, vector<T>& result) {
    vector<int> tmp;
    solve(start, result, tmp);
  }

  void solve(int start, vector<T>& result, vector<int>& prev) {
    result.resize(num_v, INF);
    prev.resize(num_v, -1);

    // get<0>(T): cost
    // get<1>(T): index
    // get<2>(T): ... ( for extent)
    using Tup = tuple<T, int>;
    priority_queue<Tup, vector<Tup>, greater<Tup>> que;

    que.emplace(0, start);
    result[start] = 0;

    while (!que.empty()) {
      Tup p = que.top();
      que.pop();

      T t = get<0>(p);
      int v = get<1>(p);

      // queueに入れてから別の最短経路が見つかった場合、探索処理は不要
      if (result[v] != t) {
        continue;
      }

      // vの各辺に対しよりコストの低い経路があるかを確認
      for (auto& e : G[v]) {
        if (result[e.to] > result[v] + e.cost) {
          prev[e.to] = v;
          result[e.to] = result[v] + e.cost;
          que.emplace(result[v] + e.cost, e.to);
        }
      }
    }
  }

  // t: 目的地
  vector<int> get_path(const vector<int>& prev, int t) {
    vector<int> path;

    for (int v = t; v != -1; v = prev[v]) {
      path.push_back(v);
    }

    reverse(path.begin(), path.end());
    return path;
  }
};

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);

  ll n;
  cin >> n;

  Dijkstra<ll> g(n);
  rep(i, n) {
    ll a;
    cin >> a;
    a--;
    g.add_edge(i, a, 1);
  }
  vll res;
  g.solve(0, res);
  if (res[1] == INF) {
    res[1] = -1;
  }
  cout << res[1] << endl;

  return 0;
}


Measured memory_bytes: 6912
// https://ynucpc.github.io/blog/2018/04/15/cp_vscode/
// http://www.atmarkit.co.jp/ait/articles/1509/08/news019.html

#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define rep1(i,n) for(ll i=1;i<=(ll)(n);i++)
#define rep3(i,n,m) for(ll i=(n);i<(ll)(m);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << (x) << endl
// #define max(a, b) ((a) > (b) ? (a) : (b))
// #define min(a, b) ((a) < (b) ? (a) : (b)) 
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
	return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
	o<<"{";
	for(const T& v:vc) o<<v<<",";
	o<<"}";
	return o;
}
using ll = long long;
template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T>>;
int stoi (string s, int tmp=10){
	istringstream stm(s);
	int res;
	stm >> res;
	return res;
}
double stod(string s, int tmp=10){
	istringstream stm(s);
	double res;
	stm >> res;
	return res;
}


// 降順ソート: sort(A, A+N, greater<>());
// min: *min_element(A, A+N)
// argmin: min_element(A, A+N)-A

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


ll A[101010];

int main(){	
	// ll A;
    // cin >> A;
	// cout << "hello" << endl;
	// cout << stoi("14") << endl;
	// cout << max({1,3}) << endl;
	ll N;
	cin >> N;
	rep(i, N)cin >> A[i];
	ll ans = A[0];
	rep1(i, N-1)ans = gcd(ans, A[i]);
	cout << ans << endl;

}








Measured memory_bytes: 1024
#include<iostream>
#include<string>
#include<vector>
#include<math.h>
#include<map>
#include<algorithm>
#include<set>
#include <stdexcept>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int dx[]={1,0,-1,0,1,-1,-1,1};
const int dy[]={0,1,0,-1,1,1,-1,-1};
int ceil(int a,int b){
    return (a+b-1)/b;
}
int main(void){
    int a,b;
    cin>>a>>b;
    if(a<=9 && b<=9) cout<<a*b<<endl;
    else cout<<"-1"<<endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scn = new Scanner(System.in);
		int a = scn.nextInt();
		int b = scn.nextInt();
		
		int d = a/b;
		int r = a%b;
		double f = (double) a/b ;
		
		System.out.print(d +" ");
		System.out.print(r +" ");
		System.out.printf("%5.5f",f);
		scn.close();
	}

}

Measured memory_bytes: 26340
#include <bits/stdc++.h>
#define ADD(a, b) a = (a + ll(b)) % mod
#define MUL(a, b) a = (a * ll(b)) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define all(a) (a).begin(), (a).end()
#define sz(v) (int)(v).size()
#define pb push_back
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<int, pi> ppi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> mat;
typedef complex<double> comp;
void Debug() {cout << '\n'; }
template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){
	cout<<arg<<" ";Debug(rest...);}
template<class T>ostream& operator<<(ostream& out,const vector<T>& v) {
	out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<<", ";out<<v.back();}out<<"]";return out;}
template<class S, class T>ostream& operator<<(ostream& out,const pair<S, T>& v){
	out<<"("<<v.first<<", "<<v.second<<")";return out;}
const int MAX_N = 200010;
const int MAX_V = 100010;
const double eps = 1e-6;
const ll mod = 1000000007;
const int inf = 1 << 29;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;
///////////////////////////////////////////////////////////////////////////////////////////////////

int N, K;

ll dp[110][2000];
ll S[110];


ll mod_pow(ll a, ll n) {
	if(n == 0) return 1;
	ll res = mod_pow(a, n / 2);
	if(n % 2 == 0) return res * res % mod;
	else return a * res % mod * res % mod;
}


ll f(int i, int k, int s) {
	if(k <= i) return s % i;
	else return s;
}

void solve() {
	cin >> N >> K;
	dp[N][0] = 1;
	rer(i, N + 1, 2) {
		rep(j, 0, 2000) {
			if(!dp[i][j]) continue;
			rep(k, 0, K + 1) {
				if(k <= i) {
					ADD(dp[i - 1][j + (j + k) / i], dp[i][j]);
				}
				else ADD(dp[i - 1][j], dp[i][j]);
			}
		}
	}
	rep(i, 1, N + 1) {
		rep(j, 0, 2000) {
			if(!dp[i][j]) continue;
			rep(k, 0, K + 1) {
				ADD(S[i], dp[i][j] * f(i, k, j + k) % mod);
			}
		}
	}
	ll ans = 0;
	rep(i, 1, N + 1) ADD(ans, S[i] * mod_pow(K + 1, i - 1) % mod);
	cout << ans << "\n";
}

int main() {
#ifndef LOCAL
	ios::sync_with_stdio(false);
    cin.tie(0);
#endif
    cout << fixed;
	cout.precision(20);
	srand((unsigned int)time(NULL));
#ifdef LOCAL
	//freopen("in.txt", "wt", stdout); //for tester
    freopen("in.txt", "rt", stdin);
#endif	
	solve();
#ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}



Measured memory_bytes: 768
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>
#include <random>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define RREP(i,m,n) for(int i=int(n)-1;i>=int(m);--i)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
//#define int long long

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;
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 (b<a) { a=b; return 1; } return 0; }

constexpr double EPS = 1e-10;
//constexpr double PI  = acos(-1.0);
//constexpr int INF = INT_MAX;
constexpr int MOD = 1'000'000'007;
//inline void modAdd(LL &l, LL &r) {l = (l + r) % MOD;}

template<class T> inline T sqr(T x) {return x*x;}

void solve() {
    int n;
    cin >> n;
    VI a(n);
    REP(i,0,n) cin >> a[i];
    VI m(n);
    m[0] = a[0] == 1 ? 1 : 0;
    REP(i,1,n) {
        m[i] = m[i-1];
        if (a[i] == m[i] + 1) ++m[i];
    }
    if (m[n-1] == 0) cout << -1 << endl;
    else cout << n - m[n-1] << endl;
}

signed main() {
    solve();
    
    return 0;
}

Measured memory_bytes: 1792
import java.util.ArrayList;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		ArrayList<Integer> x = new ArrayList<>();
		for (int i = 1; i <= 10000; i++) {
			x.add(in.nextInt());
			if (x.get(x.size() - 1) == 0) {
				break;
			}
		}
		
		for (int i = 1; i <= 10000; i++) {
			if (x.get(i - 1) == 0) {
				break;
			}
			System.out.println("Case " + i + ": " + x.get(i - 1) );
		}
	}
}	


Measured memory_bytes: 43432
#include <stdio.h>
#include <stdlib.h>
int h, w, d;
int xs[90001];
int ys[90001];
int ds[90001];
int s[90001];

int main() {
  int q;
  scanf("%d%d%d", &h, &w, &d);
  for (int y = 0; y < h; y++) {
    for (int x = 0; x < w; x++) {
      int v;
      scanf("%d", &v);
      xs[v] = x;
      ys[v] = y;
    }
  }
  for (int l0 = h * w - d, r0 = h * w; l0; l0--, r0--) {
    ds[l0] = abs(xs[r0] - xs[l0]) + abs(ys[r0] - ys[l0]);
  }
  for (int l = 0; l < d; l++) {
    s[l] = 0;
    for (int r = l + d; r <= h * w; r += d) {
      s[r] = s[r - d] + ds[r - d];
    }
  }
  scanf("%d", &q);
  for (int _ = 0; _ < q; _++) {
    int l, r;
    scanf("%d%d", &l, &r);
    int ans = s[r] - s[l];
    printf("%d\n", ans);
  }
  return 0;
}

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

int main() {
    int a, b;
    cin >> a >> b;
    string ans;
    if (a <= 0 && 0 <= b) ans = "Zero";
    else if (a > 0 && b > 0) ans = "Positive";
    else {
        if ((-b-a+1)%2 == 1) ans = "Negative";
        else ans = "Positive";
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <cstdio>

using namespace std;

const int MAXN = 100000;
#define ll long long
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))

ll f[MAXN + 5], v[105];
int w[105];
int main() {
	int n, W;
	scanf("%d%d", &n, &W);
	for (int i = 1; i <= n; ++ i) {
		scanf("%d%d", &w[i], &v[i]);
	}
	for (int i = 1; i <= n; ++ i) {
		for (int j = w[i]; j <= W; ++ j) {
			f[j - w[i]] = max(f[j - w[i]], f[j] + v[i]);
		}
	}
	printf("%lld\n", f[0]);
	return 0;
}

Measured memory_bytes: 896
#include<bits/stdc++.h>
using namespace std;
int main(){
    int h,w;
    cin >> h >> w;
    vector<vector<char>> a (h ,vector<char>(w));
    for(int i=0;i<h;i++)for(int j=0;j<w;j++) cin >> a[i][j];
    vector<bool> height (h ,true);
    vector<bool> width (w ,true);

    for(int i=0;i<h;i++){
        bool check=true;
        for(int j=0;j<w;j++){
            if(a[i][j] == '#'){
                check = false;
                break;
            }
        }
        if(check)height[i] = false;
    }
    for(int j=0;j<w;j++){
        bool check=true;
        for(int i=0;i<h;i++){
            if(a[i][j] == '#'){
                check = false;
                break;
            }
        }
        if(check) width[j] = false;
    }

    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            if(height[i] && width[j]) cout << a[i][j];
        }
        if(height[i]) cout << endl;
    }
}

Measured memory_bytes: 256
n = int(input())
x = [int(i) for i in input().split()]

cnt = 0
min = 10000000000
for i in range(n):
    if x[i] < 0:
        cnt += 1
    if abs(x[i]) < min:
        min = abs(x[i])

if 0 in x:
    cnt = 0

ans = 0
for i in range(n):
    ans += abs(x[i])

#print(cnt)
#print(ans)

if cnt % 2 == 0:
    print(ans)

else:
    print(ans - min*2)

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

int main(){
	int n;
	
	while((scanf("%d", &n)) != EOF){
		for(int i = 0; i < 10; i++){
			if(n >> i & 1){
				n -= 1 << i;
				printf("%d%c", 1 << i, (n > 0)? ' ' : '\n');
			}
		}
	}
	
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define int long long
#define rng(i, l, r) for (size_t i = (l); i < (r); ++i)
#define rep(i, n) rng(i, 0, n)
#define gnr(i, l, r) for (size_t i = (r)-1; i >= (l); i--)
#define per(i, b) gnr(i, 0, b)
#define ALL(obj) (obj).begin(), (obj).end()    //1,2,3,...
#define rALL(obj) (obj).rbegin(), (obj).rend() //...,3,2,1

using namespace std;
const int INF = 1e18;

void solve()
{

    // remove the bottom 3 lines when you submit this code.
    std::ifstream in("sample.txt");
    std::cin.rdbuf(in.rdbuf());

    cin.tie(0);
    ios::sync_with_stdio(false);

    int n, k;
    cin >> n >> k;
    int a[n], b[n];
    rep(i, n) cin >> a[i] >> b[i];

    map<int, int> mp;
    rep(i, n) mp[a[i]] += b[i];

    vector<pair<int, int>> vec;
    for (auto now : mp)
        vec.push_back(make_pair(now.first, now.second));

    sort(ALL(vec));

    int tmp = 0;
    for (int i = 0; i < vec.size(); i++)
    {
        if (tmp <= k && k <= tmp + vec[i].second)
        {
            cout << vec[i].first << endl;
            break;
        }
        else
        {
            tmp += vec[i].second;
        }
    }
}

signed main()
{
    solve();
    return 0;
}


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

using namespace std;

int64_t N;
int64_t K;

vector<int64_t> costs;
vector<int64_t> foods;

int64_t solve() {
  int64_t total_cost = 0;
  int64_t max_score = 0;
  for (int64_t i = 0; i < N; ++i) {
    auto cost = costs[N - i - 1];
    auto food = foods[i];
    total_cost += cost;
    max_score = max(cost * food, max_score);
  }
  if (K == 0) {
    return max_score;
  }
  if (total_cost <= K) {
    return 0;
  }

  int64_t left = 0;
  auto right = max_score;

  while (1 < right - left) {
    auto mid = (left + right) / 2;
    // cout << " left " << left << endl;
    // cout << " right " << right << endl;
    // cout << " mid " << mid << endl;
    auto remain = K;
    for (int64_t i = 0; 0 <= remain && i < N; ++i) {
      auto cost = costs[N - i - 1];
      auto food = foods[i];
      auto score = cost * food;
      if (mid < score) {
        remain -= (score - mid - 1) / food + 1;
        // cout << " mid " << mid << endl;
        if (remain < 0) {
          break;
        }
      }
    }
    if (remain < 0) {
      left = mid;
    } else {
      right = mid;
    }
  }

  return right;
}

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

  cin >> N >> K;

  costs.resize(N);
  for (int64_t i = 0; i < N; ++i) {
    cin >> costs[i];
  }

  foods.resize(N);
  for (int64_t i = 0; i < N; ++i) {
    cin >> foods[i];
  }

  sort(costs.begin(), costs.end());
  sort(foods.begin(), foods.end());

  auto score = solve();
  cout << score << endl;
}


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

using namespace std;

int main(){
    int w, a, b;
    cin >> w >> a >> b;
    if(a + w < b) cout << b - (a + w);
    else if(b + w < a)cout << a - (b + w);
    else cout << 0;
    return 0;

}


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

using namespace std;

int main(){
  int N, h[100]={0};
  int max=0, ans=0;
  cin >> N;
  for(int i=0; i < N; i++){
    cin >> h[i];
    if(h[i]>=max){
      ans++;
      max=h[i];
    }
  }
  cout << ans << endl;
  return 0;
}


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

int main() {
  int N;
  cin >> N;
  int v=0;
  int a,b,h;
  cin >> h;
  v++;
  for (int i=0; i<N-1; i++) {
    cin >> a;
    if (a>=h) {
      v++;
      h=a;
    }
  }
  cout << v << endl;
}


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

int main() {
  int a,b,c,tmp;
  cin >> a >> b >> c;
  tmp = a;
  a = b;
  b=tmp;
  tmp=a;
  a=c;
  c = tmp;
  cout <<a<< ' '<< b<< ' ' << c; 
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
///Welcome to Nasif's Code
#define bug printf("bug\n");
#define bug2(var) cout<<#var<<" "<<var<<endl;
#define co(q) cout<<q<<endl;
#define all(q) (q).begin(),(q).end()
typedef long long int ll;
typedef unsigned long long int ull;
const int MOD = (int)1e9+7;
const int MAX = 1e6;
#define pi acos(-1)
#define inf 1000000000000000LL
#define FastRead    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int parent1[MAX];
int connected1[MAX];
int parent2[MAX];
int connected2[MAX];
int root1(int a)
{
    if(parent1[a]==a)
        return parent1[a];
    return root1(parent1[a]);
}
void Merge1(int a,int b)
{
    int x=root1(a),y=root1(b);
    if(x!=y)
    {
        if(x>y)
            swap(x,y);
        parent1[x]=y;
        connected1[y]+=connected1[x];
    }
}
int root2(int a)
{
    if(parent2[a]==a)
        return parent2[a];
    return root2(parent2[a]);
}
void Merge2(int a,int b)
{
    int x=root2(a),y=root2(b);
    if(x!=y)
    {
        if(x>y)
            swap(x,y);
        parent2[x]=y;
        connected2[y]+=connected2[x];
    }
}
int main()
{
    FastRead
    //freopen("output.txt", "w", stdout);
    for(int i=1;i<=MAX;i++)
        parent1[i]=parent2[i]=i;
    int n,a,b;
    cin>>n>>a>>b;
    while(a--)
    {
        int u,v;
        cin>>u>>v;
        Merge1(u,v);
    }
    while(b--)
    {
        int u,v;
        cin>>u>>v;
        Merge2(u,v);
    }
    map<pair<int,int>,int>ans;
    for(int i=1; i<=n; i++)
        ans[ {root1(i),root2(i)}]++;
    for(int i=1; i<=n; i++)
        cout<<ans[{root1(i),root2(i)}]<<" ";
    cout<<endl;
    return 0;
}


Measured memory_bytes: 23024
#include<stdio.h>
#include<stdlib.h>
#include<math.h>

typedef long long int int64;

#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))

int64 comb(int n,int k){
  if(k<0 || n<k) return 0;
  int64 res=1;
  int i;
  for(i=1;i<=k;i++) res=res*(n+1-i)/i;
  return res;
}

int cmp(const void *a,const void *b){
  int64 p=*(int64 *)a;
  int64 q=*(int64 *)b;
  return p==q?0:p<q?-1:1;
}

void run(void){
  int n,a,b;
  scanf("%d%d%d",&n,&a,&b);
  int64 v[50];
  int i;
  for(i=0;i<n;i++) scanf("%lld",v+i);
  qsort(v,n,sizeof(int64),cmp);
  double sum=0;
  for(i=n-1;i>=n-a;i--) sum+=v[i];
  printf("%.10lf\n",sum/a);
  for(i=n-1;i>=0 && v[i]==v[n-1];i--);
  i++;
  if(n-i>=a){
    int64 ans=0;
    int j;
    for(j=a;j<=b;j++) ans+=comb(n-i,j);
    printf("%lld\n",ans);
  } else {
    int l,r;
    for(l=n-a;l>=0 && v[l]==v[n-a];l--);
    l++;
    for(r=n-a;r<n  && v[r]==v[n-a];r++);
    r--;
    printf("%lld\n",comb(r-l+1,a-(n-1-r)));
  }
}

int main(void){
  run();
  return 0;
}


Measured memory_bytes: 128
n,m=map(int, input().split())  #複数数値入力
A=list(map(int, input().split()))  #リスト入力（数値)
num = [-1, 2, 5, 5, 4, 5, 6, 3, 7, 6]

A.sort(reverse=True)    # 大きい順に並べる

dp = [-1*float("inf")]*(n+1)    # その本数で作れる最大の桁数
# dp初期化 (0本では0桁, 各数字を1つ作る場合は1桁)
dp[0] = 0
for a in A:
    if num[a] <= n:
        dp[num[a]] = 1

for i in range(1,n+1):
    for a in A:
        if i - num[a] >= 0:
            dp[i] = max(dp[i], dp[i-num[a]] + 1)

ans = ""
for i in range(dp[n]):  # 1桁ずつ考える
    for a in A: # 使える数1つずつ大きい方から考える
        if n-num[a] >= 0 and dp[n-num[a]] == dp[n]-1:
            ans += str(a)
            n -= num[a]
            break
 
print(ans)


Measured memory_bytes: 3308
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <map>
typedef long long LL;

int main() {

	char c[100][100];
	int h, w;
	bool hoge = true;
	std::cin >> h >> w;

	for (int i = 0; i < h; ++i) {
		for (int j = 0; j < w; ++j) {
			std::cin >> c[i][j];
		}
	}

	for (int i = 0; i < h; ++i) {
		for (int j = 0; j < w; ++j) {
			if (c[i][j] != '.') {
				hoge = false;
			}
		}
		if (hoge) {
			for (int j = 0; j < w; ++j) {
				c[i][j] = '0';
			}
		}
		hoge = true;
	}

	hoge = true;

	for (int i = 0; i < w; ++i) {
		for (int j = 0; j < h; ++j) {
			if (c[j][i] != '.' && c[j][i] != '0') {
				hoge = false;
			}
		}
		if (hoge) {
			for (int j = 0; j < h; ++j) {
				c[j][i] = '0';
			}
		}
		hoge = true;
	}

	for (int i = 0; i < h; ++i) {
		int temp = 0;
		for (int j = 0; j < w; ++j) {
			if (c[i][j] != '0') {
				std::cout << c[i][j];
			}
			else {
				temp += 1;
			}
		}
		if (temp != w) {
			std::cout << "" << std::endl;
		}
	}

	return 0;
}

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

int main(int argc, char const *argv[])
{
	int n, k; cin >> n >> k;
	vector<int> p(n); rep(i, n) cin >> p[i];
	vector<double> e(n + 1); rep(i, n) e[i + 1] = (1. + p[i]) / 2.;
	rep(i, n) e[i + 1] += e[i];
	double ans = 0.;
	rep(i, n - k + 1) {
		ans = max(ans, e[i + k] - e[i]);
	}
	printf("%.12f\n", ans);
	return 0;
}


Measured memory_bytes: 2560
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
#include <functional>
using namespace std;

int main()
{
    for(;;){
        int n;
        if(!(cin >> n))
            return 0;

        vector<vector<long long> > a(5, vector<long long>(n+1, 0));
        a[0][0] = 1;
        for(int i=0; i<4; ++i){
            for(int j=0; j<=n; ++j){
                for(int k=0; k<=1000; ++k){
                    int x = j + k;
                    if(x <= n)
                        a[i+1][x] += a[i][j];
                }
            }
        }

        cout << a[4][n] << endl;
    }
}

Measured memory_bytes: 1364
$<.map{|e|n,*a,d=e.split.map &:to_i
h={0=>0,1=>d}
f=->x{h[x]||=a.zip([2,3,5]).map{|a,b|[x%b*d+f[x/b]+a,-x%b*d+f[0--x/b]+a,x*d].min}.min}
d&&p(f[n])}

Measured memory_bytes: 17676
import sys
from fractions import gcd
from functools import reduce

INPUT = lambda: sys.stdin.readline().strip()
INT = lambda: int(INPUT())
LIST = lambda: list(map(int, INPUT().split()))

sys.setrecursionlimit(10 ** 9)


def lcm(*numbers):
    return reduce(lambda x, y: (x * y)//gcd(x, y), numbers, 1)


def main():
    N = INT()
    A = LIST()
    f_max = 0
    f_limit = sum(A) - N

    for m in range(lcm(*A)-1, -1, -1):
        f = sum(list(map(lambda a: m % a, A)))

        if f > f_max: f_max = f
        if f_max == f_limit: break

    print(f_max)


if __name__ == '__main__':
    main()


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

int main(){
string c;
cin>>c;
int n;
//cout<<c<<endl;


for (int i=0;i<=3;i++){
 if(c[i]==c[i+1]){
 n=1;
 // cout<<"Bad"<<endl;
  break;
 }
else{
 n=0;
   //cout<<"Good"<<endl;
   
  }
 }
if(n==1){
cout<<"Bad"<<endl;
}
if(n==0){
cout<<"Good"<<endl;
}
return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        for(int i = 0; i < s.length();i=i+2){
            System.out.print(s.charAt(i));
        }
        System.out.println();
    }
}

Measured memory_bytes: 29316
#pragma GCC optimize ("O2")
#pragma GCC target ("avx2")
//#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
#include<cstring>

using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

//みなさん天才的ですよね

const int CM = 1 << 17, CL = 12;
char cn[CM + CL], * ci = cn + CM + CL, * owa = cn + CM, ct;
const ll ma0 = 1157442765409226768;
const ll ma1 = 1085102592571150095;
const ll ma2 = 71777214294589695;
const ll ma3 = 281470681808895;
const ll ma4 = 4294967295;
inline int getint() {
	if (ci - owa > 0) {
		memcpy(cn, owa, CL);
		ci -= CM;
		fread(cn + CL, 1, CM, stdin);
	}
	ll tmp = *(ll*)ci;
	int dig = 68 - __builtin_ctzll((tmp & ma0) ^ ma0);
	tmp = tmp << dig & ma1;
	tmp = tmp * 10 + (tmp >> 8) & ma2;
	tmp = tmp * 100 + (tmp >> 16) & ma3;
	tmp = tmp * 10000 + (tmp >> 32) & ma4;
	ci += 72 - dig >> 3;
	return tmp;

}
int KH[300001], KW[300001];
int h[300001], w[300001];
int main() {
	//cin.tie(0);
	//ios::sync_with_stdio(false);


	int H = getint(), W = getint(), M = getint();

	rep(i, M) {
		KH[h[i] = getint()]++;
		KW[w[i] = getint()]++;
	}

	int saidaih = -1, hh = 0;
	rep1(i, H) {
		if (saidaih < KH[i]) {
			saidaih = KH[i];
			hh = 1;
		}
		else if (saidaih == KH[i]) hh++;
	}
	int saidaiw = -1, ww = 0;
	rep1(i, W) {
		if (saidaiw < KW[i]) {
			saidaiw = KW[i];
			ww = 1;
		}
		else if (saidaiw == KW[i]) ww++;
	}

	ll are = ll(hh) * ww;

	int kazu = 0;
	rep(i, M) {
		kazu += (KH[h[i]] == saidaih && KW[w[i]] == saidaiw);
	}

	printf("%d\n", saidaih + saidaiw - (kazu == are));

	Would you please return 0;
}

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

int main(){
  int n; cin >> n;
  int alp[26];
  for(int i=0; i<26; i++){
    alp[i]=100;
  }
  
  string s;
  for(int i=0; i<n; i++){
    cin >> s;
    
    int cur[26]={};
    for(int j=0; j<s.size(); j++){
      cur[s[j]-'a']++;
    }
    
    for(int j=0; j<26; j++){
      alp[j]=min(alp[j],cur[j]);
    }
  }
  
  for(int i=0; i<26; i++){
    if(alp[i]!=0){
      for(int j=0; j<alp[i]; j++){
        cout << (char)(i+'a');
      }
    }
  }
  cout << endl;
}

Measured memory_bytes: 256
mod = 10**9 + 7
t = input()
n = len(t)

l_a = [0] * (n + 1)
l_q = [0] * (n + 1)
r_c = [0] * (n + 1)
r_q = [0] * (n + 1)
total = 0

for i in range(1, n):
    l_a[i] = l_a[i - 1] + (1 if t[i - 1] == 'A' else 0)
    l_q[i] = l_q[i - 1] + (1 if t[i - 1] == '?' else 0)
for i in range(n - 1, 0, -1):
    r_c[i - 1] = r_c[i] + (1 if t[i] == 'C' else 0)
    r_q[i - 1] = r_q[i] + (1 if t[i] == '?' else 0)


pow3mod = [1] * (n+1)
for i in range(n):
    pow3mod[i+1] = pow3mod[i] * 3 % mod

for i in range(n):
    if t[i] in 'B?':
        total += l_a[i] * r_c[i] * pow3mod[l_q[i] + r_q[i]] + \
            l_a[i] * r_q[i] * pow3mod[l_q[i] + r_q[i] - 1] +\
            l_q[i] * r_c[i] * pow3mod[l_q[i] + r_q[i] - 1] +\
            l_q[i] * r_q[i] * pow3mod[l_q[i] + r_q[i] - 2]
        total %= mod
print(int(total))


Measured memory_bytes: 22984
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  double N, i, sum = 0, b=0;
  cin >> N;
  
  vector<double> A(N);
  for(i=0 ; i<N; i++){
    cin >> A[i];
  }
  while(1){
    for(i=0; i<N; i++){
      if(ceil(A[i]/2)==floor(A[i]/2) && A[i] != 0)
        A[i] /= 2;
      else{
        b++;
        break;
      }
    }
    if(b != 0)
      break;
    else
      sum++;
  }
  cout << sum << endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;

using ll = long long;

int main() {
    int N;
    cin >> N;
    vector<vector<int>> F(N, vector<int>(10)), P(N, vector<int>(11));
    rep(i, N) {
        rep(j, 10) {
            cin >> F[i][j];
        }
    }
    rep(i, N) {
        rep(j, 11) {
            cin >> P[i][j];
        }
    }
    int ans = -1e9;
    rep(i, 1023) {
        int b = 0;
        rep(j, N) {
            int c = 0;
            rep(k, 10) {
                if ((((i + 1) >> k) % 2) && F[j][k]) c++;
            }
            b += P[j][c];
            //cout << b << " " << j << " " << c << " " << i << endl;
        }
        ans = max(ans, b);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include <cstdlib>
#define INF 0x3f3f3f3f
using namespace std;
typedef long long LL;
const int MAXN = 2*1e5+10;
int a[MAXN],n,L[MAXN/2],R[MAXN/2];
LL merge(int left,int mid,int right){
    int i,j,k;
    LL cnt = 0;
    int n1 = mid - left;
    int n2 = right - mid;
    for(i = 0; i < n1; ++i)	L[i] = a[left+i];
    for(i = 0; i < n2; ++i)	R[i] = a[mid+i];
    L[n1] = R[n2] = INF;
    i = j = 0;
    for(k = left; k < right; ++k){
        if(L[i] <= R[j]) a[k] = L[i++];
        else{
            a[k] = R[j++];
            cnt += n1-i;
        }
    }
    return cnt;
}
LL mergesort(int left,int right){
    int mid;
    LL v1,v2,v3;
    if(left + 1 < right){
        mid = (left+right)/2;
        v1 = mergesort(left,mid);
        v2 = mergesort(mid,right);
        v3 = merge(left,mid,right);
        return v1+v2+v3;
    }
    return 0;
}
int main(){
    ios::sync_with_stdio(false);
    cin>>n;
    for(int i = 0; i < n; ++i) cin>>a[i];
    LL ans = mergesort(0,n);
    cout<<ans<<'\n';
    return 0;
}


Measured memory_bytes: 4732
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <queue>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <stdio.h>
#include <complex>
#include <cstdint>
#include <tuple>

#define M_PI       3.14159265358979323846

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }
inline int readInt() { int x; scanf("%d", &x); return x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<int, PII> TIII;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;

//container util

//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SQ(a) (a*a)
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,s,n) for(int i=s;i<(int)n;++i)
#define REP(i,n) FOR(i,0,n)
#define MOD 1000000007

int x[100000];

int query(int k) {
	cout << k << endl;
	fflush(stdout);
	string str;
	cin >> str;
	if (str[0] == 'V') {
		exit(0);
	}
	if (str[0] == 'M')return x[k] = 0;
	return x[k] = 1;
}

int main() {
	int n;
	scanf("%d", &n);
	query(0);
	int l = 1, r = n-1;
	while (r - l > 1) {
		int mid = (l + r) / 2;
		int d = mid - l;
		int f = query(mid) ^ x[l-1];
		if ((d ^ f) % 2)l = mid+1;
		else r = mid-1;
	}
	query(l);
	query(r);
	return 0;
}

Measured memory_bytes: 852
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define FOR(i,start,end) for(int i=start;i<=end;i++)
const int INF = 1001001001;
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
typedef long long ll;
const ll MOD=1000000007;
using namespace std;
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; }
template<class T>auto MAX(const T& a) { return *max_element(a.begin(),a.end()); }
template<class T>auto MIN(const T& a) { return *min_element(a.begin(),a.end()); }
template<class T, class U>U SUM(const T& a, const U& v) { return accumulate(a.begin(),a.end(), v); }
template<class T, class U>U COUNT(const T& a, const U& v) { return count(a.begin(),a.end(), v); }
template<class T, class U>int LOWER(const T& a, const U& v) { return lower_bound(a.begin(),a.end(), v) - a.begin(); }
template<class T, class U>int UPPER(const T& a, const U& v) { return upper_bound(a.begin(),a.end(), v) - a.begin(); }
int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { int g = GCD(a, b); return a / g * b; }
//---------------------------------------------------------------------------------------------------
typedef pair<int,int> P;

int main(void){
    // Your code here!
    ll n,a,b; cin >> n >> a >> b;
    ll ans = n /(a+b) * a + min(n % (a+b),a); 
    cout << ans << endl;
}


Measured memory_bytes: 3632