akhauriyash/Code-Regression huggingface dataset:
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author Gosu_Hiroo
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
#define tr(container, it) \
        for (auto it = container.begin(); it != container.end(); it++)
#define scontains(c, x) ((c).find(x) != (c).end())   //O(log n)
#define contains(c, x) (find((c).begin(),(c).end(),x) != (c).end()) //O(n)
#define pll pair<ll,ll>
#define pii pair<int,int>
#define mll map<ll,ll>
#define intv(x, a, b)((x)>=a && (x)<=b)
#define  rep(i, _begin, _end) for (__typeof(_end) end = _end, begin = _begin,  i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define  _for(i, end) for (__typeof(end) i = 0, _len = (end); i < (_len); i += 1)
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define F first
#define S second
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define what_is(x) cerr << #x << " is " << x << endl;
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args,cerr); }
#define mod(x, m) ((((x) % (m)) + (m)) % (m))
#define bit(n) (1LL<<(n))
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define readint ({int t;cin >> t;t;})
#define fcout cout << fixed << setprecision(12)
#define fcerr cerr << fixed << setprecision(12)

const double PI = 2 * acos(.0);
const int INF = 0x3f3f3f3f;
const ll LLINF = 1000000000000000005LL;;
const ll MOD = (ll) (1e9) + 7;
void _mod(ll &x){x = mod(x, MOD);}
//const ll MOD = (ll) 998244353 ;
const double EPS = 1e-10;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

void err(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 A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
    std::fill((T *) array, (T *) (array + N), val);
}

template <typename T>
ostream& operator << (ostream& os, const vector<T> V) {
    for(auto v : V)os << v << " ";
    return os;
}

template <typename T>
ostream& operator << (ostream& os, const set<T> V) {
    for(auto v : V)os << v << " ";
    return os;
}

template <typename T>
ostream& operator << (ostream& os, const deque<T> V) {
    for(auto v : V)os << v << " ";
    return os;
}

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; }

//#define int ll

class AHarmony {
public:

void solve(std::istream& cin, std::ostream& cout, std::ostream& cerr) {
    int A, B;
    cin >> A >> B;
    if((A-B) & 1)cout << "IMPOSSIBLE\n";
    else cout << (A+B)/2 << endl;
}


};


#undef int
int main() {

	AHarmony solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
    std::ostringstream err;
	in.tie(0); ios::sync_with_stdio(0);
//	solver.solve(in, out);
    solver.solve(in, out,err);
	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <algorithm>
#include <cmath>
#include <string>

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

using namespace std;

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

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

void trace(int A[], int N) {
    for (int i = 0; i < N; ++i) {
        if (i > 0) cout << " ";
        cout << A[i];
    }
    cout << endl;
}

using ll = long long;
using P = pair<int, int>;

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

////////////////////////////////////////////////////////////

int main() {
    int N, K;
    cin >> N >> K;

    int ans = K * (int) pow((K - 1), N - 1);
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cassert>
#include <climits>
#include <bitset>
#include <stack>
#include <queue>
#include <iomanip>
#include <limits>
#include <string>
#include <cmath>
#include <set>
#include <map>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string.h>

using namespace std;

typedef long long ll;
typedef pair<ll,ll> P;

long long int INF = 1e18;
long long int mod = 998244353;
double Pi = 3.1415926535897932384626;

vector<ll> G[500005];
vector<P> tree[500010];
priority_queue <ll> pql;
priority_queue <P> pqp;
//big priority queue
priority_queue <ll,vector<ll>,greater<ll> > pqls;
priority_queue <P,vector<P>,greater<P> > pqps;
priority_queue <P,vector<P>,greater<P> > pqps2;
//small priority queue
//top pop

int dx[8]={1,0,-1,0,1,1,-1,-1};
int dy[8]={0,1,0,-1,1,-1,-1,1};
char dir[] = "RULD";
ll bit[500005];
//↓,→,↑,←

#define p(x) cout<<x<<endl;
#define el cout<<endl;
#define pe(x) cout<<x<<" ";
#define ps(x) cout<<fixed<<setprecision(15)<<x<<endl;
#define pu(x) cout<<x;
#define re(i,n) for(i=0;i<n;i++);
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define deba(x) cout<< #x << " = " << x <<endl

ll rui(ll abc,ll bed){
    //abcのbed乗を計算する
    if(bed==0){return 1;}
    else{
        ll ced = rui(abc,bed/2);
        ced *= ced;
        ced %= mod;
        if(bed%2==1){ced*=abc; ced%=mod;}
        return ced;
    }
}
ll gcd(ll number1,ll number2){
	if(number1 > number2){
		swap(number1,number2);
	}
	if(number1 == 0 || number1 == number2){
		return number2;
	}else{
		return gcd(number2 % number1,number1);
	}
}

ll i,j,k,ii,jj,r,l;
ll n,m,num,ans;
ll a,b,c,d,e,g,h,w;
ll x[500005],y[500005],z[500005];
char s[5005];

ll bitsum(ll i){
	ll s = 0;
	while(i>0){
		//p("hoi");
		s += bit[i];
		i -= i & -i;
	}
	return s;
}
void bitadd(ll b,ll x){
	while(b <= n){
		//p("hoi");
		bit[b] += x;
		b += b & -b;
	}
}

int main(){
	
    cin>>x[0] >> x[1] >> a;
	while(k < a){		
		x[(k+1)%2] += (x[k%2])/2;
		x[k%2] /= 2;
		k++;
	}
	pe(x[0]);
	p(x[1]);


	//p(ans);
	

    return 0;
}

Measured memory_bytes: 29056
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    long[] n=new long[3];
    for(int i=0;i<3;i++){
      n[i]=sc.nextInt();
    }
    if(n[0]%2==0||n[1]%2==0||n[2]%2==0){
      System.out.println(0);
    }else{
      Arrays.sort(n);
      System.out.println(n[0]*n[1]);
    }
  }
}


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

int n,m,p,ans,a[100002];

int main(){
	cin>>n;
	for(int i=1;i<=n;i++){
		int dis;
		cin>>dis;
		a[dis]++;
	}
	for(int i=1;i<=100000;i++){
		ans=max(ans,a[i-1]+a[i]+a[i+1]);
	}
	cout<<ans<<endl;
	//cin>>p;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii; 
const int N = 2e5+10;

void solve() {
    int a, b; cin >> a >> b;
    cout << a * b << endl;
}

int main(void) {
    int t; t = 1;
    while (t--) solve();
    return 0;
}

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

vector<vector<int>> v(200010);
vector<vector<ll>> cnt(200010);
int use[200010];


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

    int n;
    cin>>n;
    for(int i=1;i<n;i++){
        int a,b;
        cin>>a>>b;
        a--,b--;
        use[a]++, use[b]++;
        v[a].push_back(b);
        v[b].push_back(a);
    }
    int root = 0;
    queue<pair<int,int>> q;
    for(int i=0;i<n;i++){
        if(v[i].size()==1){
            use[i]--;
            q.push({i,0});
            cnt[i].push_back(n-1);
        }
    }
    bool used[n]={};
    int sum[n]={};
    while(q.size()){
        pair<int,int> p = q.front(); q.pop();
        // cerr << p.first << endl;
        for(auto i:v[p.first]){
            use[i]--;
            if(use[i]<=0) continue;
            sum[i] += p.second+1;
            cnt[i].push_back(p.second+1);
            if(use[i]==1){
                q.push({i,sum[i]});
                if(n-sum[i]-1 > 0) cnt[i].push_back(n - sum[i] -1);
            }
        }
    }

    ll ans = 0, mod = 1e9+7;
    ll inv[n+1]={};
    inv[0] = 1;
    inv[1] = 500000004;
    for(int i=2;i<=n;i++){
        inv[i] = inv[i-1] * inv[1];
        inv[i] %= mod;
    }
    for(int i=0;i<n;i++){
        if(cnt[i].size()==1) continue;
        ll ret = inv[n];
        for(auto j:cnt[i]){
            // cerr << "d "<< i << " " << j << endl;
            ll e = (mod+1 - inv[j]) % mod;
            e *= inv[n-j];
            e %= mod;
            ret += e;
            ret %= mod;
        }
        ans += inv[1] - ret;
        if(ans<0) ans+=mod;
        ans %= mod;
    }
    cout << ans << endl;
    
}

Measured memory_bytes: 27392
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

using pi = pair<int,int>;

const int dx[4]={1,-1,0,0}, dy[4]={0,0,1,-1};

string ans(int r, int nr)
{
    if(r>0 && nr>0) return "Unknown";
    if(r==0 && nr>0) return "No";
    if(r>0 && nr==0) return "Yes";
    return "Broken";
}

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

    vector<string> t(h);
    rep(i,h) cin >>t[i];

    vector<int> r(d+1);
    rep(i,d) cin >>r[i];

    vector<int> x(n),y(n),s(n);
    rep(i,n) cin >>x[i] >>y[i] >>s[i];

    int px,py;
    rep(i,h)rep(j,w)if(t[i][j]=='D')
    {
        px = j;
        py = i;
    }

    #define IN(x,y) (0<=x && x<w && 0<=y && y<h)

    vector<vector<bool>> vis(h,vector<bool>(w,false));
    vis[py][px]=true;
    queue<pi> que;
    que.push({py,px});
    while(!que.empty())
    {
        pi p = que.front();
        que.pop();
        rep(i,4)
        {
            int nx = p.se+dx[i], ny = p.fi+dy[i];
            if(IN(nx,ny) && t[ny][nx]!='#' && !vis[ny][nx])
            {
                vis[ny][nx] = true;
                que.push({ny,nx});
            }
        }
    }

    vector<vector<int>> f(h,vector<int>(w));
    rep(i,n)
    {
        if(s[i]==0)
        {
            for(int Y=y[i]-r[0]; Y<=y[i]+r[0]; ++Y)for(int X=x[i]-r[0]; X<=x[i]+r[0]; ++X)
            {
                if(IN(X,Y)) ++f[Y][X];
            }
        }
        else if(s[i]==d)
        {
            rep(Y,h)rep(X,w) ++f[Y][X];
            for(int Y=y[i]-r[d-1]; Y<=y[i]+r[d-1]; ++Y)for(int X=x[i]-r[d-1]; X<=x[i]+r[d-1]; ++X)
            {
                if(IN(X,Y)) --f[Y][X];
            }
        }
        else
        {
            for(int Y=y[i]-r[s[i]]; Y<=y[i]+r[s[i]]; ++Y)for(int X=x[i]-r[s[i]]; X<=x[i]+r[s[i]]; ++X)
            {
                if(IN(X,Y)) ++f[Y][X];
            }
            for(int Y=y[i]-r[s[i]-1]; Y<=y[i]+r[s[i]-1]; ++Y)for(int X=x[i]-r[s[i]-1]; X<=x[i]+r[s[i]-1]; ++X)
            {
                if(IN(X,Y)) --f[Y][X];
            }
        }
    }

    // printf("------\n");
    // rep(i,h)
    // {
    //     rep(j,w) printf("%d", f[i][j]);
    //     printf("\n");
    // }

    int R=0, NR=0;
    rep(i,h)rep(j,w)
    {
        if(t[i][j]!='#' && f[i][j]==n)
        {
            if(vis[i][j]) ++R;
            else ++NR;
        }
    }

    cout << ans(R,NR) << endl;
    return 0;
}

Measured memory_bytes: 3208
#include <iostream>
using namespace std;
int main() {
	int n, d, x, ans = 0, l;
	cin >> n >> d >> x;
	for (int i = 0; i < n; i++) {
		cin >> l;
		ans += d / l + 1;
		if (d % l == 0) ans--;
	}
	cout << ans + x << endl;
}

Measured memory_bytes: 256
use std::io;


/// https://beta.atcoder.jp/contests/abc068/tasks/abc068_b
fn main() {
    let n = read_one::<usize>();
    let mut cnt = 0;
    let mut ans = 0;
    for i in 0..n {
        let zeros = (i + 1).trailing_zeros();
        if cnt <= zeros { ans = i + 1; cnt = zeros; }
    }
    println!("{}", ans);
}


#[allow(dead_code)]
fn read<T>() -> Vec<T>
where T:
    std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.split_whitespace()
        .map(|s| s.trim().parse().unwrap())
        .collect()
}

#[allow(dead_code)]
fn read_one<T>() -> T
where T:
    std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.trim().parse().unwrap()
}

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

struct UnionFind {
    vector<int> d;
    UnionFind(int n=0): d(n, -1) {}
    int find(int x) {
        if (d[x]<0) return x;
        return d[x] = find(d[x]);
    }
    bool unite(int x, int y) {
        x = find(x);
        y = find(y);
        if (x==y) return false;
        if (d[x] > d[y]) swap(x, y);
        d[x] += d[y];
        d[y] = x;
        return true;
    }
    bool same(int x, int y) {
        return find(x) == find(y);
    }
    int size(int x) {
        return -d[find(x)];
    }
};



int main(){
    int n, m;
    cin >> n >> m;
    vector<P> e;
    rep(i, m) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        e.emplace_back(a, b);
    }
    
    int ans = 0;
    rep(i, m) {
        UnionFind u(n);
        rep(j, m) {
            if (j==i) continue;
            u.unite(e[j].first, e[j].second);
        }
        int x = -1;
        rep(j, n) {
            chmax(x, u.size(j));
        }
        if (x!=n) ans++;
    }
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3612
from math import ceil
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

def main():
    A,B = map(int, readline().split())

    x1 = ceil(A / 0.08)
    x2 = ceil(B / 0.1)

    if int(x1 * 0.1) == B:
        print(x1)
    elif int(x2 * 0.08) == A:
        print(x2)
    else:
        print(-1)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
const double eps = 1e-8;
const int NINF = 0xc0c0c0c0;
const int INF  = 0x3f3f3f3f;
const ll  mod  = 1e9 + 7;
const ll  maxn = 1e6 + 5;
const int N = 1e5 + 5;

int n,m,v[N];
vector<int> G[N];

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>n>>m;
	for(int i=1;i<=m;i++){
		int u,v;
		cin>>u>>v;
		G[u].push_back(v);
		G[v].push_back(u);
	}
	queue<int> q; q.push(1);
	while(!q.empty()){
		int x=q.front();q.pop();
		for(auto c:G[x]){
			if(v[c]==0) q.push(c),v[c]=x;
		}
	}
	for(int i=2;i<=n;i++){
		if(v[i]==0) {cout<<"No\n";return 0;}
	}
	cout<<"Yes\n";
	for(int i=2;i<=n;i++) cout<<v[i]<<'\n';
	return 0;
}

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

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

typedef long long ll; 
typedef long double ld; 
#define prarr(a,n) cout<<#a<<" : ";for(ll i=0;i<n;i++) cout<<a[i]<<" "; cout<<endl;
#define prmat(mat,row,col) cout<<#mat<<" :\n";for(ll i=0;i<row;i++) {for(ll j=0;j<col;j++) cout<<mat[i][j]<<"\t";cout<<endl;}
#define pr(...) dbs(#__VA_ARGS__, __VA_ARGS__)
#define all(a) a.begin(),a.end()
#define sz(x) ((int)x.size())
#define endl '\n'
#define F first
#define S second
#define pb push_back
#define vi vector<int>
#define pii pair<int,int>
#define fast_io ios_base::sync_with_stdio(NULL); cin.tie(NULL)
template <class T> void dbs(string str, T t) {cout << str << " : " << t << "\n";}
template <class T, class... S> void dbs(string str, T t, S... s) {ll idx = str.find(','); cout << str.substr(0, idx) << " : " << t << ", "; dbs(str.substr(idx + 1), s...);}
template <class T> void prc(T a, T b) {cout << "["; for (T i = a; i != b; ++i) {if (i != a) cout << ", "; cout << *i;} cout << "]\n";}
template <class T> void prall(T a) { prc(all(a)); }
const int inf=1000*1000*1000+9; 
const ll infl=1ll*inf*inf; 
const int mod=1000*1000*1000+7;

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

const int nax=1e5+5;


void solve(){
    string s[7] = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};
    string ss;cin>>ss;
    for(int i=0;i<7;i++){
        if(s[i]==ss){
            cout<<7-i;
            return;
        }
    }
}


int main(){
    // clock_t beg=clock(); 
    fast_io; 
    cout << fixed << setprecision(13); 
    int t=1;
    // cin>>t;
    while(t--){
        solve();
    } 
    // clock_t end=clock(); 
    // fprintf(stderr, "%lf\n", (double)(end-beg)/(CLOCKS_PER_SEC));
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
/*{{{*/  //template
#define rep(i,n) for(int i=0;i<(int)(n);i++)
constexpr int INF = numeric_limits<int>::max()/2;
constexpr long long LINF = numeric_limits<long long>::max()/3;
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define sz(x) (int)(x).size()
#define debug(x) cerr<<#x<<":"<<x<<endl
#define debug2(x,y) cerr<<#x<<","<<#y":"<<x<<","<<y<<endl
//struct fin{ fin(){ cin.tie(0); ios::sync_with_stdio(false); } } fin_;
struct Double{ double d; explicit Double(double x) : d(x){} };
ostream& operator<<(ostream& os,const Double x){ os << fixed << setprecision(20) << x.d; return os; }
template<typename T> ostream& operator<<(ostream& os,const vector<T>& vec){ os << "["; for(const auto& v : vec){ os << v << ","; } os << "]"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os,const pair<T,U>& p){ os << "(" << p.first << ","<< p.second <<")"; return os; }
template<typename T> ostream& operator<<(ostream& os,const set<T>& st){ os<<"{"; for(T v:st) os<<v<<","; os <<"}"; return os; }
template<typename T,typename U> inline void chmax(T &x,U y){ if(y>x) x = y; }
template<typename T,typename U> inline void chmin(T &x,U y){ if(y<x) x = y; }
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
ll gcd(ll a,ll b){ if(b==0) return a; else return gcd(b,a%b); }
//constexpr double eps = 1e-14; 
constexpr double eps = 1e-10; 
constexpr ll mod = 1e9+7;
const int dx[]={1,0,-1,0} ,dy[] = {0,1,0,-1};
/*}}}*/

int main(){
    ll N; scanf("%lld",&N);
    if(N==0){
        cout << 0 << endl;
        return 0;
    }
    string ans;

    while(N){
        if(N%(-2)){
            ans.push_back('1');
            N-=1;
            N /= (-2);
        }else{
            ans.push_back('0');
            N /= (-2);
        }
    }

    reverse(all(ans));
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i <= (n); i++)
#define show(a, n) rep(i,n) {cout<<a[i]<<' ';} cout<<endl;

using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<long long, long long> pll;

const int INF = 1 << 30;
const long long INFL = 1LL << 62;
const int MOD = 1000000007;
const int MAX = 100000;
const int N = 100010;

struct mint {
    ll x;
    mint(ll x=0):x((x%MOD+MOD)%MOD){}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {if ((x+=a.x)>=MOD) x-=MOD; return *this;}
    mint& operator-=(const mint a) {if ((x+=MOD-a.x)>=MOD) x-=MOD; return *this;}
    mint& operator*=(const mint a) {(x*=a.x)%=MOD; return *this;}
    mint operator+(const mint a) const {mint res(*this); return res+=a;}
    mint operator-(const mint a) const {mint res(*this); return res-=a;}
    mint operator*(const mint a) const {mint res(*this); return res*=a;}
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const { return pow(MOD-2);}
    mint& operator/=(const mint a) { return (*this) *= a.inv();}
    mint operator/(const mint a) const {mint res(*this); return res/=a;}
};

int main() {
	int n;
	cin >> n;
	int a[N];
	rep(i, n) cin >> a[i];
	sort(a, a + n);
	bool valid = true;
	int i, cur_a;
	if(n % 2 == 1) {
		if(a[0] != 0) valid = false;
		i = 1;
		cur_a = 2;
	}
	else {
		i = 0;
		cur_a = 1;
	}
	while(i < n) {
		if(a[i] != cur_a || a[i + 1] != cur_a) valid = false;
		i += 2;
		cur_a += 2;
	}
	mint ans = 2;
	cout << (valid ? ans.pow(n / 2).x : 0) << endl;
}


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

using namespace std;

const int MOD = 1e9 + 7, MAX = 2e5 + 2;
int sumDp[MAX];
int main() {
    //ifstream cin("gard6.in");
    int n;
    cin >> n;
    vector<int>c;
    for(int i = 0; i < n; ++i) {
        int x;
        cin >> x;
        if(c.empty() || c.back() != x)
            c.push_back(x);
    }

    n = c.size();
    vector<int>dp(n);
    dp[0] = 1;
    sumDp[c[0]] = 1;
    for(int i = 1; i < n; i++) {
        dp[i] = (dp[i - 1] + sumDp[c[i]]) % MOD;
        sumDp[c[i]] = (sumDp[c[i]] + dp[i - 1]) % MOD;
    }
    cout << dp[n - 1];
}


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

using namespace std;
using ll =long long;
using db = double;
using vll = vector<long long>;

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
#define che(a,string) cout<<"//"<<string <<"=="<<(a)<<"//" <<endl;
#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define leftunique(a) {SORT(a);(a).erase(unique((a).begin(),(a).end()),(a).end());}
//leftuniqueは配列から同じ要素のものを取り除く 例 4 6 2 1 3 4 1 2 なら 1 2 3 4 6 になる
#define debug(x)  cout << #x << " = " << (x) << endl;
bool IsInt(double a){int b = a/1;if(a==b){return true;}else {return false;}}
bool coY() {cout <<"Yes"<<endl;}
bool coN(){cout <<"No"<<endl;}
const int mod = 1e9 + 7;
const ll INF = 1LL << 60;
// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
//グラフ用
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};	
//ここから書き始める

ll combination(ll n, ll i){
	ll count = 0;
	ll multi = 1;
	ll div =1;
	int limit = i;
	while(count < limit){
		multi *= n;
		n--;
		multi/= count+1;
		count ++ ;
	}
	return multi / div;
}

int main()
{
	cout <<setprecision(10);
	ll n; cin >> n;
	vector<ll> v(n);
	rep(i,n) cin >> v[i];

	vector<ll> Left(n+1);
	vector<ll> Right(n+1);
	Left[0] = Right[0] = 0;
	rep(i,n){
		Left[i+1] = Left[i] + v[i];
	}
	rep(i,n){
		Right[i+1] = Right[i] + v[n-1-i];
	}
	reverse(Right.begin(),Right.end());

//	for(auto x:Left){
//		cout << x <<" " ;
//	}
//	cout << endl;
//	for(auto x:Right){
//		cout << x <<" " ;
//	}
//	cout << endl;

	ll minlen = INF;
	rep(i,n+1){
		ll thi = abs(Left[i] - Right[i]);
		chmin(minlen,thi);
	}
	cout << minlen << endl;



}


Measured memory_bytes: 4992
using System;
using System.Collections.Generic;
using System.Text;

class TEST{
	static void Main(){
		
		while(true){
			var s=Console.ReadLine();
			if(s==null)break;
			var arr=Array.ConvertAll(s.Split(' '),elem=>int.Parse(elem));
			Console.WriteLine(cal_gcd(arr[0],arr[1]));
		}
	}

	static int cal_gcd(int a,int b){
		int c;
		
		if(a<b){
			c=b;
			b=a;
			a=c;
		}
		
		
		while((a%b)!=0){
			c=a;
			a=b;
			b=c%b;
		}
		return b;
	}
}

Measured memory_bytes: 5632
#include <bits/stdc++.h>
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;
}
typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define LLINF (1e18)
#define PI (acos(-1))
#define MOD (1000000007)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

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

const int MAX = 200000;

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

void COMinit() // 二項係数を求める時は前処理としてCOMinit()をする
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++)
    {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

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

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

    ll h, w, a, b;
    cin >> h >> w >> a >> b;
    ll ans = 0;
    for (ll i = b; i < w; i++)
    {
        (ans += COM(h - a - 1 + i, i) * COM(a + w - i - 2, a - 1) % MOD) %= MOD;
    }
    cout << ans << endl;
}

Measured memory_bytes: 4992
a,b=input().split()
a=int(a)
b=int(b)
c=list(map(int,input().split()))
d=0
e=0
for i in range(a):
  if d+c[i]<=b:
    d=d+c[i]
    e=e+1
  else:
    break
print(e+1)

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

int main() {
  int n,a[100000],ans=0;
  cin >> n;
  for(int i=0; i<n; i++) {
    cin >> a[i];
  }
  for(int i=0; i<n; i++) {
    if(a[a[i]-1]==i+1) {
      ans++;
    }
  }
  cout << ans/2 << endl;
}

Measured memory_bytes: 640
import java.util.*;

class Main{

  public static void main(String args[]){

    Scanner s=new Scanner(System.in);
    int N=s.nextInt();
    long ans=0;
    long max=0;
    for(int i=0;i<N;i++){
      long height=s.nextInt();
      if(height<=max) ans+=max-height;
      else max=height;
    }
    System.out.println(ans);
    
  }  
}

Measured memory_bytes: 60080
#include<iostream>
#include<algorithm>
#define DUMMY 'X'
#define INF 1000000001
using namespace std;

int partition(pair<char, int> array[], int p, int r) {
  pair<char, int> x = array[r];
  int i = p - 1;
  for(int j = p; j < r; j++) {
    if(array[j].second <= x.second) {
      i++;
      swap(array[i], array[j]);
    }
  }
  swap(array[i + 1], array[r]);
  
  return i + 1;
}


void quickSort(pair<char, int> deck[], int begin, int end) {
  if(begin < end) {
    int index = partition(deck, begin, end);
    quickSort(deck, begin, index - 1);
    quickSort(deck, index + 1, end);
  }
}

pair<char, int> L[50001];
pair<char, int> R[50001];

void merge(pair<char, int> array[], int left, int mid, int right) {
  int n1 = mid - left;
  int n2 = right - mid;

  for(int i = 0; i < n1; i++) {
    L[i] = array[left + i];
  }
  for(int i = 0; i < n2; i++) {
    R[i] = array[mid + i];
  }
  L[n1] = make_pair(DUMMY, INF);
  R[n2] = make_pair(DUMMY, INF);

  int i = 0;
  int j = 0;

  for(int k = left; k < right; k++) {
    if(L[i].second <= R[j].second) {
      array[k] = L[i];
      i++;
    }
    else {
      array[k] = R[j];
      j++;
    }
  }
}

void mergeSort(pair<char, int> array[], int left, int right) {
  if(left + 1 < right) {
    int mid = (left + right) / 2;
    mergeSort(array, left, mid);
    mergeSort(array, mid, right);
    merge(array, left, mid, right);
  }
}


int main(void) {
  int n;
  char c;
  int cardNum;

  cin >> n;
  pair<char, int> deck[100000];
  pair<char, int> copy[100000];

  for(int i = 0; i < n; i++) {
    cin >> c;
    cin >> cardNum;

    pair<char, int> d = make_pair(c, cardNum);
    deck[i] = d;
    copy[i] = d;
  }

  mergeSort(copy, 0, n);
  quickSort(deck, 0, n - 1);

  bool isStable = true;
  for(int i = 0; i < n; i++) {
    if(copy[i].first != deck[i].first) {
      cout << "Not stable" << endl;
      isStable = false;
      break;
    }
  }
  if(isStable) {
    cout << "Stable" << endl;
  }

  for(int i = 0; i < n; i++) {
    cout << deck[i].first << " " << deck[i].second << endl;
  }
  return 0;
}

Measured memory_bytes: 3508
import java.util.*

fun main(args: Array<String>) {
    val pw = java.io.PrintWriter(System.out)
    Problem.solve(Scanner(System.`in`), pw)
    pw.flush()
}

object Problem {
    fun solve(sc: Scanner, pw: java.io.PrintWriter) {
        val N = sc.next().toInt()
        val S = sc.next().map { it - 'a' }.toIntArray()
        val Q = sc.next().toInt()

        val alphaIndexes = Array(26) { sortedSetOf<Int>() }
        for (i in 0 until N) {
            alphaIndexes[S[i]].add(i)
        }

        repeat(Q) {
            when (sc.next()) {
                "1" -> {
                    val i = sc.next().toInt() - 1
                    val c = sc.next().toCharArray().first() - 'a'
                    alphaIndexes[S[i]].remove(i)
                    S[i] = c
                    alphaIndexes[c].add(i)
                }
                "2" -> {
                    val l = sc.next().toInt() - 1
                    val r = sc.next().toInt() - 1
                    var ans = 0
                    alphaIndexes.forEach { indexes ->
                        if (indexes.higher(l - 1) ?: Int.MAX_VALUE <= r) {
                            ans++
                        }
                    }
                    pw.println(ans)
                }
            }
        }
    }
}


Measured memory_bytes: 99672
n = int(input())
a = list(map(int, input().split()))

for i in range(n):
    if a[i] % 2 == 0:
        if a[i] % 3 == 0 or a[i] % 5 == 0:
            continue
        else:
            print('DENIED')
            exit()
print('APPROVED')

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

//typedef
//------------------------------------------
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

//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 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())

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int MOD = 1000000007;

//MOD
//--------------------------------------------
#define MUL(a,b) (((a) % MOD) * ((b) % MOD)) % MOD

// grid
//--------------------------------------------
VL dx = {0, 1, 0, -1};
VL dy = {1, 0, -1, 0};
VL dx2 = {-1, 0, 1, -1, 1, -1, 0, 1};
VL dy2 = {-1, -1, -1, 0, 0, 1, 1, 1};

//debug
//--------------------------------------------
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

//main code

int main(int argc, char const* argv[])
{
	
	int a,b,c,d;
	cin >> a >> b >> c >> d;
	VL t(101,0);
	int ans = 0;
	for (int i = a; i <= b; i++) {
		t[i] = 1;
	}
	for (int i = c; i <= d; i++) {
		if (t[i] == 1) {
			ans++;
		}
	}
	cout << max(ans-1, 0) << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 100000000

using namespace std;

int main()
{
    //COMinit();
    ios::sync_with_stdio(false);
    cin.tie(0);
    llong a,b; cin>>a>>b;
    if((a+b)%2==0) cout<<(a+b)/2<<endl;
    else cout<<"IMPOSSIBLE"<<endl;
    return  0;
}

Measured memory_bytes: 256
from collections import Counter
n = int(input())
a = list(map(int, input().split()))
cnt = Counter(a)
s = sum(a)

q = int(input())
for _ in range(q):
    b, c = map(int, input().split())
    memo = cnt[b]
    cnt[c] += cnt[b]
    cnt[b] = 0

    s += memo * (c - b)
    print(s)

Measured memory_bytes: 24136
while True:
	n = int(input())
	if n == 0: 
            break
	s, vmin, vmax = 0, 1001, -1
	for i in range(n):
		a = int(input())
		vmin = min(vmin, a)
		vmax = max(vmax, a)
		s += a
	print((s-vmin-vmax)//(n-2))



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

int main(){
  string s,p;
  cin >> s;
  int n=0;
  for(int i=0;i<s.size();i++) {
    if('A'<=s[i]&&s[i]<='Z') s[i]+='a'-'A';
  }
  cin >> p;
  while(p!="END_OF_TEXT"){
        for(int i=0;i<p.size();i++) {
            if('A'<=p[i]&&p[i]<='Z') p[i]+='a'-'A';
        }
        if(s==p) n++;
        cin >> p;
  }
  cout << n << endl;
  return 0;
}
  


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

#define pb push_back
#define pf push_front
#define pp pop_back
#define sz(a) (int)(a.size())
#define mp make_pair
#define F first
#define S second
#define next _next
#define prev _prev
#define left _left
#define right _right
#define y1 _y1
#define all(x) x.begin(), x.end()
#define int ll

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int N = (int)1e6 + 123;
const ll INF = (ll)1e18 + 123;
const int inf = (int)1e9 + 123;
const int MOD = (int)1e9 + 7;

int q, h, s, d, n, res;

main() {
	cin >> q >> h >> s >> d >> n;	
	int cost = min({d, 2 * s, 4 * h, 8 * q});
	res += (n / 2) * cost;
	if(n % 2 == 1) {
		res += min({s, 2 * h, 4 * q});		
	} 	
	cout << res;
	return 0;         
}


Measured memory_bytes: 384
import sys
input = lambda: sys.stdin.readline().rstrip()
from math import floor,ceil,sqrt,factorial,log
from heapq import heapify, heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from decimal import Decimal
inf = float('inf')
mod = 1000000007

n = int(input())
a = list(map(int, input().split()))

ans = 1
flag = True
for i in range(len(a)):
    if a[i] == 0:
        print(0)
        exit()

for i in range(n):
    ans *= a[i]
    if ans > 1e+18:
        flag = False
        break;

if(flag):
    print(ans)
else:
    print(-1)

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

int main(){
    int n;
    cin >> n;
    vector<int>d1(n), d2(n);
    for(int i=0;i<n;i++) cin >> d1[i] >> d2[i];

    bool exist = false;
    for(int i=0;i<n-2;i++){
        if(d1[i]==d2[i] && d1[i+1]==d2[i+1] && d1[i+2]==d2[i+2]) exist = true;

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

Measured memory_bytes: 3640
_n,k = gets.chomp.split.map(&:to_i)
ary = gets.chomp.split.map(&:to_i)

num_ary = []
ruisekiwa = [ary[0]]
for i in 1..(ary.length-1)
  ruisekiwa[i] = ruisekiwa[i-1]+ary[i]
end
for i in 0..(ary.length-1)
  for j in (i+1)..(ary.length-1)
    if i == 0
      num_ary << ruisekiwa[j]
    else
      num_ary << ruisekiwa[j]-ruisekiwa[i-1]
    end
  end
end
num_ary.sort!{|a, b| b <=> a}
tmp_keta = (Math.log2(num_ary[0])).to_i
# 14→3
# tmp_keta目でK個1が取れるか確認
ans = 0
while tmp_keta >= 0
  tmp_ary = []
  # flag = true
  count = 0
  num_ary.each do |item|
    if (item >> tmp_keta) & 1 == 1
      count += 1
      tmp_ary << item
    end
  end
  if count >= k
    ans += 2**tmp_keta
    num_ary = tmp_ary
  end
  # p num_ary
  tmp_keta -= 1
end
puts ans






  # for i in 0..(k-1)
  #   if (num_ary[i]>>tmp_keta)&1 == 1
  #     tmp_ary << num_ary[i]-2**tmp_keta
  #   else
  #     flag = false
  #     break
  #   end
  # end
  # if flag
  #   ans += 2**tmp_keta
  #   num_ary = tmp_ary.sort!{|a, b| b <=> a}
  # else
  #   for i in 0..(num_ary.length-1)
  #     num_ary[i] -= 2**tmp_keta
  #   end
  #   num_ary.sort!{|a, b| b <=> a}
  # end
  # tmp_keta-=1
# end
# puts ans


Measured memory_bytes: 14196
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <array>
#include <initializer_list>
#include <random>
#include <regex>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
using namespace std;

char col[4] = {'R', 'G', 'B', 'Y'};
char ans[1005][1005];
int h, w, d;

void fill_triangle(int cx, int cy, int dr, char cr)
{
    for (int i = cx - d / 2 + 1; i < cx + d / 2; i++)
    {
        int R = d / 2 - abs(cx - i);
        for (int j = 0; j < R; j++)
        {
            if (i >= 0 && i < h && cy + dr * j >= 0 && cy + dr * j < w)
                ans[i][cy + dr * j] = cr;
        }
    }
}

int main()
{
    scanf("%d%d%d",&h,&w,&d);

    if (d & 1)
    {
        for (int i = 0; i < h; i++)
        {
            for (int j = 0; j < w; j++)
            {
                printf("%c", col[(i + j) & 1]);
            }
            printf("\n");
        }

        return 0;
    }
    else if (d % 4 == 2)
    {
        for (int i = 0; i < h; i++)
        {
            for (int j = 0; j < w; j++)
            {
                printf("%c", col[(j + i / 2 * 2) % 4]);
            }
            printf("\n");
        }
        return 0;
    }
    else
    {
        for (int i = d / 2 - 1; i < h + 2 * d; i += d)
        {
            for (int j = 0; j < w + 2 * d; j += d)
            {
                fill_triangle(i, j, 1, col[((i + j + d) / d) & 1]);
                fill_triangle(i, j - 1, -1, col[((i + j + d) / d) & 1]);
            }
        }

        for (int i = -1; i < h + 2 * d; i += d)
        {
            for (int j = d / 2; j < w + 2 * d; j += d)
            {
                fill_triangle(i, j, 1, col[(((i + j + d) / d) & 1) + 2]);
                fill_triangle(i, j - 1, -1, col[(((i + j + d) / d) & 1) + 2]);
            }
        }

        for (int i = 0; i < h; i++) printf("%s\n", ans[i]);
    }
}


Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repp(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define rrep(i, n, m) for (int i = n; i >= m; i--)
#define p(s) cout << s << endl;
typedef long long LL;
template <class T>
bool contain(const std::string &s, const T &v)
{
    return s.find(v) != std::string::npos;
}

int main()
{
   char c; int ans=0;
   rep(i,4){
       cin>>c;
       if(c=='+') ans++;
       else ans--;
   }
   cout<<ans<<endl;
}


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

int main(){
	int X,T,total,i;
  	T = 0;
  	total = 0;
  	cin>>X;
  	int array[X]={};
  		for(i=0;i<X;i++){
  			cin>>array[i];
    		if(array[i] > T){
            	T = array[i];
            }
          total += array[i];
        }
  	
  	if(total - T > T){
      cout<<"Yes"<<endl;
    }
  	else{
    	cout<<"No"<<endl;
    }


}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/range/irange.hpp>
#include <boost/range/algorithm.hpp>
using namespace std;
using namespace boost::range;
using boost::irange;

using ll = int64_t;
constexpr char LN = '\n';
template<class T> bool chmax(T& a, const T& b) {if(a<b){a=b;return true;}else{return false;}}
template<class T> bool chmin(T& a, const T& b) {if(b<a){a=b;return true;}else{return false;}}

#ifdef LOCAL
template<class H> void dump_(const char* s, H h) {cout<<s<<"="<<h<<LN; }
template<class H, class... T> void dump_(const char* s, H h, T... t) {for(;*s!=',';++s){cout<<*s;}cout<<"="<<h<<",";dump_(++s,t...);}
#define dump(...) dump_(#__VA_ARGS__, __VA_ARGS__)
#else
#define dump(...)
#endif

struct init_ {init_(){ 
    cin.tie(nullptr); ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
}} init_;

template<class C> C scan(size_t n) {C c(n);for(auto& v:c){cin>>v;}return c;}
template<class C> C scan(size_t n, size_t m) {C vss(n);for(auto& vs:vss){vs.resize(m);for(auto& v:vs){cin>>v;}}return vss;}

template<class R> struct Joined { const R& r; const char* s; };
template<class R> Joined<R> joined(const R& r, const char* s = " ") {return{r,s};}
template<class R> ostream& operator<<(ostream& out, Joined<R> j) {bool f=true;for(const auto& v:j.r){if(f){f=false;}else{out<<j.s;}out<<v;}return out;}

template<class T> using matrix = vector<vector<T>>;
template<class T> matrix<T> make_matrix(size_t n, size_t m, const T& init = T()) {matrix<T> vss(n);for(auto& vs:vss){vs.resize(m,init);}return vss;}
template<class T> ostream& operator<<(ostream& out, Joined<matrix<T>> j) {bool a=true;for(const auto& vs:j.r){if(a){a=false;}else{out<<LN;}bool f=true;for(const auto& v:vs){if(f){f=false;}else{out<<j.s;}out << v;}}return out;}

int main() {
    int N;
    string S;
    cin >> N >> S;
    int c = 0;
    auto i = 0ul;
    while (i != string::npos) {
        i = S.find("ABC", i);
        if (i != string::npos) {
            c++;
            i++;
        }
    }
    cout << c << LN;
}


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

//.define
// #define FILE_IN_OUT
#define RET(_x)                       return cout << (_x) << '\n', 0;
#define all(_obj)                     (_obj).begin(), (_obj).end()
#define loop(_n)                      for (int i = 0; i < (_n); ++i)
#define CeilDiv(_dividend, _divider)  (((_dividend) - 1LL + (_divider)) / (_divider))
#define sz(_obj)                      static_cast<int>((_obj).size())
#ifdef SHJ_LOCAL
#define debug(_x)                     std::cerr << (#_x) << " = " << (_x) << '\n' << std::flush;
#else
#define debug(_x)                     {}
#endif
#define endl "\n"
template<typename Tp>
inline void outarr(Tp _begin, Tp _end, const char* _delim = " ") {
    for (Tp current = _begin; current != _end; ++current) {
        std::cout << *current << _delim;
    }
    std::cout << '\n';
}

//.constant
using ll  = long long;
using pii = std::pair<int, int>;
constexpr int INF = 0x3f3f3f3f;
constexpr int MOD = static_cast<const int>(1e9 + 7);

//.data

//.code
int main() {
#ifdef FILE_IN_OUT
    std::ifstream cin ("input.txt",  std::ios::in);
    std::ofstream cout("output.txt", std::ios::out);
#else
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);
#endif

    int a, b, c, d;
    cin >> a >> b >> c >> d;
    const int mod = 998244353;
    vector<vector<ll>> dp(c + 1, vector<ll>(d + 1, 0));
    dp[a][b] = 1;
    for (int i = a + 1; i <= c; ++i) {
        dp[i][b] = dp[i - 1][b] * b % mod;
    }
    for (int i = b + 1; i <= d; ++i) {
        dp[a][i] = dp[a][i - 1] * a % mod;
    }
    auto Add = [mod](ll x, ll y) {
        x += y;
        return x < mod ? x : x - mod;
    };
    auto Sub = [mod](ll x, ll y) {
        x -= y;
        return x >= 0 ? x : x + mod;
    };
    for (int i = a + 1; i <= c; ++i) {
        for (int j = b + 1; j <= d; ++j) {
            dp[i][j] = Sub(Add(dp[i - 1][j] * j % mod, dp[i][j - 1] * i % mod), dp[i - 1][j - 1] * (i - 1) * (j - 1) % mod);
        }
    }
    cout << dp[c][d] << endl;

#ifdef FILE_IN_OUT
    cin.close();
    cout.close();
#endif
    return 0;
}

Measured memory_bytes: 73532
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<memory.h>

using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
  int n;
  cin >> n;
  string s;
  cin >> s;
  int lcnt=0;
  int rcnt=0;
  int l=0,r=0;
  rep(i,n){
    if(s[i]=='(')lcnt++;
    else lcnt--;
    l=min(l,lcnt);
  }
  for(int i=n-1;i>=0;i--){
    if(s[i]==')')rcnt++;
    else rcnt--;
    r=min(r,rcnt);
  }
  rep(i,-l)cout << '(' ;
  cout << s ;
  rep(i,-r)cout << ')' ;
  cout << endl;
return 0;}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define INF 1<<30
#define LINF 1LL<<60

int main(void) {
    cin.tie(0); ios::sync_with_stdio(false);
    ll N,T; cin >> N >> T;
    vector<ll> t(N,0);
    for(auto& in:t)cin >> in;
    ll res = 0;
    ll pre_t = t[0];
    for(int i = 1; i < N;i++){
        res += min(t[i] - pre_t,T);
        pre_t = t[i];
    }
    res += T;
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 1792
import sys
input = sys.stdin.readline

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

alist = list(map(int, input().split()))
blist = list(map(int, input().split()))

ans = min(alist) + min(blist)

for i in range(m):
    x, y, c = map(int, input().split())
    x -= 1  # リストは0番目から始まるため、合わせる
    y -= 1  # リストは0番目から始まるため、合わせる
    if alist[x] + blist[y] - c < ans:
        ans = alist[x] + blist[y] - c
    else:
        continue

print(ans)

Measured memory_bytes: 18616
#include <iostream>

using namespace std;

#define MAX(a,b) ((a)>(b)?(a):(b))

int main()
{
    int total=0;
    int p;

    for(int i=0; i<5; ++i) {
        cin >> p;
        total+=MAX(p,40);
    }
    cout << total/5 << endl;
    return 0;
}

Measured memory_bytes: 3076
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace AtCoder
{
	public class ABC
	{
		static public void Main(string[] args)
		{
			Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
			Solve(args);
			Console.Out.Flush();
		}

		private const int mod = 1000000007;  // 10^9+7

		static public void Solve(string[] args)
		{
			//string s = Console.ReadLine();
			//int n = int.Parse(Console.ReadLine());
			//long x = long.Parse(Console.ReadLine());
			int[] vs = Console.ReadLine().Split().Select(int.Parse).ToArray();
			//long[] vs = Console.ReadLine().Split().Select(long.Parse).ToArray();
			int n = vs[0];
			int m = vs[1];
			int x = vs[2];
			long[][] book = new long[n][];
			for (int i = 0; i < n; i++) {
				book[i] = Console.ReadLine().Split().Select(long.Parse).ToArray();
			}

			long ans = -1;
			for (int i = 1; i < Math.Pow(2, n); i++) {
				//string s = $"000000000000{Convert.ToString(i, 2)}";
				//System.Diagnostics.Debug.WriteLine($"{s.Substring(s.Length - n)}");
				int bit = 1;
				long sum = 0;
				long[] skill = new long[m];
				bool f = false;
				for (int j = 0; j < n; j++) {
					if ((i & bit) > 0) {
						sum += book[j][0];
						f = true;
						for (int k = 0; k < m; k++) {
							skill[k] += book[j][k + 1];
							if (skill[k] < x) {
								f = false;
							}
						}
						//System.Diagnostics.Debug.WriteLine($"  {sum} {f} {string.Join(",", skill)}");
					}
					if (f && (ans == -1 || ans > sum)) {
						ans = sum;
					}
					bit = bit << 1;
				}
			}
			Console.WriteLine(ans);
		}

	}
}


Measured memory_bytes: 28876
n,k = map(int,input().split())
p = list(map(int,input().split()))

kitai = []
for i in range(n):
    kitai.append((1+p[i])/2)
ans = 0
sum_kitai = 0
for i in range(k):
    sum_kitai += kitai[i]
ans = sum_kitai
for i in range(1,n-k+1):
    sum_kitai -= kitai[i-1]
    sum_kitai += kitai[i+k-1]
    ans = max(ans,sum_kitai)
print(ans)

Measured memory_bytes: 25060
#include<bits/stdc++.h>
using namespace std;
#define nl cout<<'\n';
int main()
{
    /*string s;
    cin>>s;
    if((s[0]==s[1]&&s[1]==s[2])||(s[1]==s[2]&&s[2]==s[3]))
      cout<<"Yes";
    else
      cout<<"No";*/
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    cout<<((a+b)>(c+d)?"Left":((a+b)==(c+d)?"Balanced":"Right"));
    nl;
    return 0;
}


Measured memory_bytes: 256