akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
typedef long long ll;
typedef vector<vector<ll>> vvl;
typedef vector<ll> vl;
typedef vector<vector<char>> vvc;
typedef vector<char> vc;
typedef pair<ll,ll> pll;
typedef priority_queue<string> priquest;
typedef priority_queue<string,vector<string>,greater<string>> rpriquest;
ll max(ll x,ll y){
if(x>y)return x;
else return y;
}
ll min(ll x,ll y){
  return x+y-max(x,y);
}

const ll big=1000000007;
int exp(int x,int y){
    if(y==0)return 1;//0^0=1
    if(x==1||x==0)return x;
    if(y%2==1)return (exp(x,y-1)*x);
    int t=exp(x,y/2);
    return (t*t);
}
void chmin(ll a,ll b){
    if(a>b)a=b;
    return;
}

int main(){
    string s;int k;cin >> k >> s;
    if((int)s.size()<=k)cout << s << endl;
    else {rep(i,k)cout << s[i];cout << "...";}
    cout << endl;
}
//言語選択！！！！！！！！

Measured memory_bytes: 3632
//18
#include<iostream>
#include<sstream>
#include<string>
#include<algorithm>
#include<cstdlib>
#include<iomanip>

using namespace std;

int main(){
  for(int n,l;cin>>n>>l,n|l;){
    stringstream ss;
    ss<<setw(l)<<setfill('0')<<n;
    string a[21];
    a[0]=ss.str();
    for(int i=1;;i++){
      string h=a[i-1],lo=a[i-1];
      sort(h.begin(),h.end());
      sort(lo.rbegin(),lo.rend());
      stringstream st;
      st<<setw(l)<<setfill('0')<<atoi(lo.c_str())-atoi(h.c_str());
      a[i]=st.str();
      string *p=find(a,a+i,a[i]);
      if(p!=a+i){
	cout<<p-a<<' '<<atoi(p->c_str())<<' '<<a+i-p<<endl;
	break;
      }
    }
  }
  return 0;
}

Measured memory_bytes: 1260
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<iostream>
#include<queue>
using namespace std;
const int maxn=1e5+10;
typedef long long ll;
char ch[maxn];
int a[maxn];
int main()
{
     int i,j,k;
     scanf("%d",&k);
     printf("%d\n",3*k*k);

    return 0;
}


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

int main() {
  int N;
  cin >> N;
  vector<int> a(N);
  int count = 0;
  
  for (int i = 0; i < N; i++) cin >> a.at(i);
  sort(a.begin(), a.end());
  for (int i = 0; i < N - 1; i++) { 
    if (a.at(i) != a.at(i + 1)) count++;
  }
  
  cout << count + 1 << endl;
 
}


Measured memory_bytes: 3520
/* bimillahir rahmanir rahim...
 * AUTHOR
 * mubin_akib */
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair <int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<ld, ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;

#define FOR(i, a, b) for (int i = a; i < (b); i++)
#define F0R(i, a) for (int i = 0; i < (a); i++)
#define FORd(i,a,b) for (int i = (b) - 1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a) - 1; i >= 0; i--)
#define REP(i, a, b) for(int i = a; i <= (b); ++i)
#define trav(a,x) for (auto& a : x)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int mod = 1e9 + 7;
const char nl = '\n';

int a[1234567];

void solve() {
    int n, c1(0), c2(0), c3(0), c4(0);
    cin >> n;
    while(n--){
        string s;
        cin >> s;
        if(s == "AC") c1++;
        if(s == "TLE") c2++;
        if(s == "WA") c3++;
        if(s == "RE") c4++;
    }
    printf("AC x %d\n", c1);
    printf("WA x %d\n", c3);
    printf("TLE x %d\n", c2);
    printf("RE x %d\n", c4);
}

int main() {
#ifndef ONLINE_JUDGE
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    solve();
    return 0;
}


Measured memory_bytes: 3732
#include <iostream>
#include <string>
int main() {
    std::string s;
    std::cin >> s;
    long long ans = 0;
    int cnt = 0;
    for (const auto c : s) {
        if (c == 'B')
            ++cnt;
        else
            ans += cnt;
    }
    std::cout << ans << '\n';
}

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

using namespace std;
typedef long long ll;
typedef long int li;
typedef long double lb;
#define rep(i,j,n) for (ll i = j; i < (n); i++)
#define repr(i,j,n) for(ll i = j; i >= (n); i--)
#define all(x) (x).begin(),(x).end()
#define CLR(mat,f) memset(mat, f, sizeof(mat))
#define IN(a, b, x) (a<=x&&x<b)
#define out(ans) cout << ans << endl
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 pair<ll,ll>P;
const ll mod=1e9+7;
const ll INF = 1LL<<60;

int main(){

  multiset<ll>se;
  rep(i,0,3){
    ll num;cin>>num;
    se.insert(num);
  }

  for(multiset<ll>::iterator itr=se.begin();itr!=se.end();itr++){
    if(++itr==se.end())out(*--itr);
    else cout<<*--itr<<" ";
  }


  return 0;
}



Measured memory_bytes: 3056
#include <bits/stdc++.h>
using namespace std;
using ll = long long; using ull = unsigned long long;
//#define int ll
using vb = vector<bool>; using vvb = vector<vb>;
using vi = vector<int>; using vvi = vector<vi>;
using vl = vector<ll>; using vvl = vector<vl>;
template<class T> using V = vector<T>;
template<class T> using VV = vector<V<T>>;
#define fi first
#define se second
#define maxs(x,y) (x=max(x,y))
#define mins(x,y) (x=min(x,y))
using pii = pair<int,int>; using pll = pair<ll,ll>;
#define FOR(i,a,b) for(ll i = (a); i < (ll)(b); ++i)
#define REP(i,n) FOR(i,0,n)
#define RFOR(i,a,b) for(ll i = (ll)(b)-1;i >= a;--i)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define eb(val) emplace_back(val)
const double PI = acos(-1), EPS = 1e-10;
const ll MOD = 1e9+7;
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  string l;
  cin >> l;
  int n = l.size();
  vvl dp(n+1,vl(2,0));
  dp[0][1] = 1;
  REP(i,n){
    dp[i+1][0] = 3*dp[i][0];
    dp[i+1][1] = dp[i][1];
    if(l[i]=='1'){
      dp[i+1][0] += dp[i][1];
      dp[i+1][1] += dp[i][1];
    }
    dp[i+1][0] %= MOD;
    dp[i+1][1] %= MOD;
  }
  cout << (dp[n][0] + dp[n][1])%MOD << endl;
}


Measured memory_bytes: 5840
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
using vi = vector<int64_t>;
using vvi = vector<vi>;
int64_t INF = 1000000007;
// int64_t INF = 9223372036854775807;

int main() {
    // fasten cin
    cin.tie(0);
    ios::sync_with_stdio(false);
    // implement
    int64_t n,m,x;
    cin >> n >> m >> x;
    vi c(n);
    vvi a(n, vector<int64_t>(m));
    rep(i,n){
        cin >> c.at(i);
        rep(j,m) cin >> a.at(i).at(j);
    }
    // 2^12で求めることが可能
    // bit全探索なんだけど…。
    vi clear;
    rep(i,1<<n){
        vi score(m,0);
        int64_t amount = 0;
        rep(j,n){
            if (i & (1<<j)) { // 列挙に i が含まれるか
                // cout << "i:" << i << " j:" << j << endl;
                rep(k,m) score.at(k) += a.at(j).at(k);
                amount += c.at(j);
            }
        }
        rep(l,m){
            if(score.at(l)<x) break;
            if(l==m-1) clear.push_back(amount);
        }
    }
    // sortしてemptyじゃなければget(0);
    sort(clear.begin(), clear.end());
    if(!clear.empty()){
        cout << clear.at(0) << endl;
    }else{
        cout << -1 << endl;
    }
}

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

int main() {
  int n;
  cin >> n;
  if (n / 100000 >= 1) {
    cout << 90909;
  }
  else if (n / 10000 >= 1) {
    cout << 909 + n - 9999;
  }
  else if (n / 1000 >= 1) {
    cout << 909;
  }
  else if (n / 100 >= 1) {
    cout << 9 + n - 99;
  }
  else if (n / 10 >= 1) {
    cout << 9;
  }
  else if (n / 10 == 0) {
    cout << n;
  } 
}

Measured memory_bytes: 384
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
//stl
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <list>
#include <bitset>
#include <iomanip>

#define ll long long
#define ioio ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define F first
#define S second
const ll mod = 1000000007;
const double eps = 1e-9;
const double pi = acos(-1.0);

using namespace std;

int module(int a, int b)
{
	return (a % b + b) % b;
}

vector<vector<int>>g;
vector<int>used;

bool dfs(int v, int pcol)
{
	if (pcol == 1)
		used[v] = 2;
	else
		used[v] = 1;
	int call = used[v];
	bool f = 1;
	for (auto i : g[v])
	{
		if (used[i] == 0)
		{
			f &= dfs(i, call);
		}
		else
		{
			if (used[v] == used[i])
			{
				return false;
			}
		}
	}
	return f;
}


void solve()
{
	int n, k;
	cin >> n >> k;
	vector<int>v(n + 1);
	for (int i = 1 ; i <= n; ++i)
		cin >> v[i];
	vector<double>p(n + 1);
	for (int i = 1; i <= n; ++i)
	{
		if (v[i] % 2 == 0)
			p[i] += 0.5;
		p[i] += v[i] / 2 + (v[i] % 2 > 0);
		p[i] += p[i - 1];
	}
	double ans = p[k];
	double temp_ans = p[k];
	for (int i = k + 1; i <= n; ++i)
	{
		temp_ans = p[i] - p[i - k];
		ans = max(temp_ans, ans);
	}
	cout << fixed << setprecision(15) << ans;
}


int main()
{
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	ioio;
	/*int n;
	cin >> n;
	for (int i = 0; i < n; ++i)*/
	{
		solve();
	}
}

Measured memory_bytes: 2560
N, W = map(int, input().split())
v = [0]*(N+1); w = [0]*(N+1)
for i in range(1, N+1):
    a, b = map(int, input().split())
    w[i], v[i] = a, b

dp = [[0]*(W+1) for _ in range(N+1)]
for i in range(1, N+1):
    row = dp[i]; row_before = dp[i-1]
    v_i = v[i]; w_i = w[i]
    for sum_w in range(1, W+1):
        if sum_w - w_i >= 0:
            row[sum_w] = max(row_before[sum_w - w_i] + v_i, row_before[sum_w])
        else:
            row[sum_w] = row_before[sum_w]
print(dp[N][W])

Measured memory_bytes: 147572
#include <iostream>
#include <algorithm>

int main()
{
    int ab, bc, ca, max;

    std::cin >> ab >> bc >> ca;

    max = std::max(std::max(ab, bc), ca);
    if(max == ab){
        std::cout << bc * ca / 2;
        return 0;
    }
    else if(max == bc){
        std::cout << ab * ca / 2 ;
        return 0;
    }
    else {
        std::cout << ab * bc / 2;
        return 0; 
    }

}

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

#define rep(i, N) for(int i = 0;i < (N);++i)
// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
using ll = long long;
const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  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 argc, char** argv) {
  int H, W;
  std::cin >> H >> W;
  std::vector<std::vector<char>> map(H, std::vector<char>(W));
  rep(i, H) rep(j, W) std::cin >> map[i][j];
  std::vector<std::vector<mint>> dp(H, std::vector<mint>(W, 0));
  rep(i, W) {
    if (map[0][i]=='#') {
      break;
    }
    mint tmp {1};
    dp[0][i] = tmp;
  }
  rep(i, H) {
    if (i == 0) continue;
    rep(j, W) {
      if (map[i][j] == '#') continue;
      else if (j == 0) {
        dp[i][j] = dp[i-1][j];
      } else {
        dp[i][j] = dp[i-1][j] + dp[i][j-1];
      }
    }
  }
  std::cout << dp[H-1][W-1].x << '\n';
}


Measured memory_bytes: 9088
/*
by.YXH_XianYu
 */
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#define MXN 100003

int n,
	a[MXN];
bool naive;

bool comp(int a, int b){
	return a>b;
}

int main(){

	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	std::sort(a+1,a+n+1,comp);
	
	int i,j;
	for(i=1;i<=n;i++)
		if(a[i]<i)
			break;
	i--;
	for(j=i;j<=n;j++)
		if(i>a[j])
			break;
	j--;
	//printf("i=%d a[i]=%d j=%d\n",i,a[i],j);
	if(((j-i)&1) || ((a[i]-i)&1))
		printf("First\n");
	else
		printf("Second\n");

	//system("pause");
	return 0;
}


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

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

const double PI = acos(-1);
const int inf = 2e9;
const ll INF = 2e18;
const ll MOD = 1e9+7;

#define sz(s) (s).size()
#define pb push_back
#define fi first
#define se second
#define REP(i,n) for (int i = 0; i<n; i++)
#define ALL(a) begin(a), end(a)

int N,Q;
string s;
vector<pair<char,char>> order;

int disap(int n) {
    //左に落ちたら1,右に落ちたら2,落ちなかったら0;
    REP(i,Q) {
        if (s[n] == order[i].fi) {
            if (order[i].se == 'R') n++;
            else n--;
        }
        if (n<0) return 1;
        if (n>=N) return 2;
    }
    return 0;
}

int main (void) {
    cin>>N>>Q;
    cin>>s;
    REP(i,Q){
        char a,b;
        cin>>a>>b;
        order.pb(make_pair(a,b));
    }

    int l = -1;
    int r = N;
    while(abs(l-r)>1) {
        int m = (l+r)/2;
        if (disap(m)==1) {
            l = m;
        }
        else {
            r = m;
        }
    }
    int lside = r;

    l = -1;
    r = N;
    while(abs(l-r)>1) {
        int m = (l+r)/2;
        if (disap(m)==2) {
            r = m;
        }
        else {
            l = m;
        }
    }
    int rside = l;

    int ans = rside - lside + 1;
    ans = max(ans,0);
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1024
# 競プロ幼稚園には N 人の子供がいます。
# えび先生は、子供たちを一列に並べ、一人目にはキャンディーを 1 個,
# 二人目には 2 個,..., N 人目には N 個あげることにしました。
# 必要なキャンディーの個数の合計は何個でしょう。

# 子供の人数を取得
n = gets.chomp.to_i

# 必要なキャンディーの個数の合計を格納する変数を宣言
sum = 0

# 必要なキャンディーの個数を計算
n.times do |i|
  sum += i + 1
end

# 結果を出力
puts sum

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

int main(){

    int n, d;
    cin >> n >> d;

    vector<vector<int>> x(n, vector<int>(d));
    for (int i=0; i<n; i++){
        for (int j=0; j<d; j++){
            cin >> x.at(i).at(j);
        }
    }

    int cnt = 0;
    double distance = 0, distance_0 = 0, distance_1 = 0;
    for (int i=0; i<n; i++){
        for (int j=i+1; j<n; j++){
            for (int k=0; k<d; k++){
                distance_0 += (x.at(i).at(k) - x.at(j).at(k))*(x.at(i).at(k) - x.at(j).at(k));
            }
            distance = sqrt(distance_0);
            if (floor(distance) == distance){
                cnt++;
            }
            distance_0 = 0;
            distance = 0;
        }
    }

    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 3728
N, M, K = map(int, input().split())

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

a, b = [0], [0]
for i in range(N):
    a.append(a[i] + A[i])
for i in range(M):
    b.append(b[i] + B[i])

res = 0
j = M
for i in range(N+1):
    if a[i] > K:
        break
    while b[j] > K - a[i]:
        j -= 1
    res = max(res, i+j)
print(res)

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

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vl2;
const bool multiple_queries = false;
#define rep(i, n) for(ll i = 0; i < (n) ; ++i)
#define For(i, a, b) for(ll i = (a); i < (b) ; ++i)
#define revrep(i, n) for(ll i = (n) - 1; i >= 0 ; --i)
#define revFor(i, b, a) for(ll i = (b) - 1; i >= (a) ; --i)
#define all(v) v.begin(), v.end()
#define rall(v) (v).rbegin(), (v).rend()
#define popcount(i) __builtin_popcountl((i))
#define substring(s, start, end) s.substr((start), (end) - (start) + 1)

void print(){cout;}
void println(){cout << endl;}

template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
    cout << head;
    if (sizeof...(tail) != 0) cout << " ";
    print(forward<Tail>(tail)...);
}

template <class Head, class... Tail>
void println(Head&& head, Tail&&... tail) {
    cout << head;
    if (sizeof...(tail) != 0) cout << " ";
    println(forward<Tail>(tail)...);
}

void solve(){
    ll a, b, c, d;
    cin >> a>>b>>c>>d;
    ll v1, v2, v3, v4;
    v1 = a * d;
    v2 = a * c;
    v3 = b * c;
    v4 = b * d;
    print(max({v1, v2, v3, v4}));
}

void test(ll num = 0, bool verbose = false){
    rep(i, max(1LL, num)){
        ll t = clock();
        if (verbose) cout << "\n#####" << " " << i + 1 << " " << "#####" << " " << "\n## Answer ##\n";
        solve();
        if (verbose) {cout << "\nElapsed Time:" << " " << 1000.0 * (clock() - t) / CLOCKS_PER_SEC << " " << "[ms]" << endl;}
    }
}

int main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    #ifdef _LOCAL
        test(6, true);
    #else
        ll t = 0;
        if (multiple_queries) cin >> t;
        test(t, false);
    #endif
    return 0;
}

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

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

  vector<vector<int>> dice(n, vector<int>(2));

  for(int i = 0; i < n; i++) {
    for(int j = 0; j < 2; j++) {
      cin >> dice.at(i).at(j);
    }
  }

  int count = 0;

  for(int i = 0; i < n; i++) {
    if(dice.at(i).at(0) == dice.at(i).at(1)) {
      count++;
    }
    else{
      if(count != 0 && count < 3) {
        count = 0;
      }
    }
  }

  if(count >= 3) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define show(x) cout << #x << " = " << (x) << endl;
#define show2(x,y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl;
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
const int mod = 1000000007;
const double EPS = 1e-9;
const int INF = 1<<30;
const ll INFLL = 1LL<<60;
//cout << fixed << setprecision(10);

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

int main () {
  int n;
  cin >> n;
  vll a(n);
  rep(i,n) cin >> a[i];
  
  ll ans = INFLL;

  ll sum = 0;
  ll cnt = 0;
  rep(i,n) {
    // i%2 == 0 -> +, i%2 != 0 -> -
    sum += a[i];
    if (i%2 == 0 && sum <= 0) {
      cnt += -sum + 1;
      sum += -sum + 1;
    }
    else if (i%2 != 0 && sum >= 0) {
      cnt += -(-sum - 1);
      sum += -sum - 1;
    }
  }
  ans = min(ans, cnt);

  sum = 0;
  cnt = 0;
  rep(i,n) {
    // i%2 == 0 -> -, i%2 != 0 -> +
    sum += a[i];
    if (i%2 != 0 && sum <= 0) {
      cnt += -sum + 1;
      sum += -sum + 1;
    }
    else if (i%2 == 0 && sum >= 0) {
      cnt += -(-sum - 1);
      sum += -sum - 1;
    }
  }
  ans = min(ans, cnt);
  
  cout << ans << endl;
  return 0;
}

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

int main() {
    string S;cin >> S;
    int N = S.size();
    int A[N] = {};int B[N] = {};
    for (int i = 0;i < N;i++){
        if ((i + 1) % 2 == 0){
            A[i] = 1;B[i] = 0;
        }
        else{
            A[i] = 0;B[i] = 1;
        }
    }
    int sumA = 0;int sumB = 0;
    for (int i = 0;i < N;i++){
        if (A[i] != (S[i] - '0')) sumA++;
        if (B[i] != (S[i] - '0')) sumB++;
    }
    cout << min(sumA,sumB) << endl;
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
 
using namespace std;
 
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define fileio freopen("in.in", "r", stdin),freopen("out.out", "w", stdout);
#define ll long long int
#define FF first
#define SS second
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define pll pair<long long int,long long int>
#define sd(x) scanf("%d",&x)
#define slld(x) scanf("%lld",&x)
#define pd(x) printf("%d\n",x)
#define plld(x) printf("%lld\n",x)
#define pss printf
#define MOD 1000000007
#define INF 1e18
#define eps 0.00001
#define endl '\n'
#define debug(n1) cout<<n1<<endl
string s;
ll a[27];
int main() {
cin>>s;
for(int i=0;i<s.length();i++)
a[s[i]-'a']++;

ll n=s.length();
ll ans=n*(n+1);
ans>>=1;
ans-=n;
ans++;
for(int i=0;i<26;i++)
ans-=(a[i]*(a[i]-1))/2;
plld(ans);
	return 0;
           } 	

Measured memory_bytes: 640
#include<stdio.h>

#define N 100001
 
int Partition(int A[],int p,int r);
 
int main(){
  int i,n,A[N],q;

  scanf("%d",&n);

  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }

  q=Partition(A,0,n-1);

  for(i=0;i<n;i++){
    if(i==q){
      printf("[%d] ",A[i]);
    } else if(i!=n-1) {
      printf("%d ",A[i]);
    }
    else printf("%d",A[i]);
  }
  printf("\n");

  return 0;
}

int Partition(int A[],int p,int r){
  int i,j,s,t,u;
  s=A[r];
  i=p-1;
  for(j=p;j<=r-1;j++){
    if(A[j]<=s){
      i++;
      t=A[i];
      A[i]=A[j];
      A[j]=t;
    }
  }
  u=A[i+1];
  A[i+1]=A[r];
  A[r]=u;
  return i+1;
}

Measured memory_bytes: 996
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

 
public class Main {
    public static void main(String[] args) {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        try {
	    String str=reader.readLine();
	    String s1[]=str.split(" ");

	    int a=Integer.parseInt(s1[0]);
	    String s=reader.readLine();
	    char c[]=s.toCharArray();

	    int count=0;
	    int max=0;

	    for(int i=0;i<a;i++){
		if(c[i]=='I'){
		    count++;
		    max=Math.max(max,count);
		}else{
		    count--;
		}
	    }

	    System.out.println(max);

	    
	    
	    reader.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    static int gcd (int a, int b){
	return b>0?gcd(b,a%b):a;
    }
    static int lcm (int a, int b) {
	return a*b/gcd(a,b);
    }
}


Measured memory_bytes: 21460
#include <bits/stdc++.h>
using namespace std;
int main(){
    string s;
    cin >> s;
    vector<int> a(26);
    for(int i = 0; i < s.size(); i++){
        a[s.at(i) - 'a']++;
    }
    for(int i = 0; i < 26; i++){
        if(a[i] == 0){
            cout << (char)('a' + i) << endl;
            return 0;
        }
    }
    cout << "None" << endl;
}


Measured memory_bytes: 512
S = input()
T = input()
N = len(S)
SD = {}
TD = {}
SN = [0]*N
TN = [0]*N
count = 1
for i in range(N):
  s = S[i]
  if s not in SD:
    SD[s] = count
    count+=1
  SN[i] = SD[s]
count = 1
for i in range(N):
  t = T[i]
  if t not in TD:
    TD[t] = count
    count+=1
  TN[i] = TD[t]
ans = "Yes"
for i in range(N):
  if SN[i]!=TN[i]:
    ans = "No"
    break
print(ans)

Measured memory_bytes: 76608
A=[list(map(int,input().split())) for _ in range(3)]
N=int(input())
b=[int(input()) for _ in range(N)]
flag=0
for i in range(3):
  if (A[0][i] in b)and(A[1][i] in b)and(A[2][i] in b):
    flag=1
  elif (A[i][0] in b)and(A[i][1] in b)and(A[i][2] in b):
    flag=1
if (A[0][0] in b)and(A[1][1] in b)and(A[2][2] in b):
  flag=1
elif (A[0][2] in b)and(A[1][1] in b)and(A[2][0] in b):
  flag=1
print("Yes" if flag==1 else "No")

Measured memory_bytes: 3064
#include<bits/stdc++.h>
 
#define ll          long long
#define pb          push_back
#define ppb         pop_back
#define int         ll int
#define float       double
#define	endl		'\n'
#define maxpq       priority_queue<ll>
#define minpq       priority_queue<ll, vector<ll>, greater<ll> >
#define mii         map<int,int>
#define msi         map<string,int>
#define mis         map< int, string>
#define mpi         map<pair< int, int>, int>
#define pii         pair< int, int>
#define vi          vector< int>
#define vs          vector<string>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define EPS         1e-9
#define INF         1e18
#define PI          3.14159265358979323846
#define MAXI        1000000
#define what_is(x)  cerr << #x << " is " << x << endl;
#define fast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
using namespace std;
#define N 100005
int dp[102][100005];
int rec(int val[],int wt[],int n,int capacity)
{
	if(n==0||capacity==0) return 0;
	if(dp[n][capacity]!=-1) return dp[n][capacity];
	if(wt[n-1]>capacity)
	{
		return dp[n][capacity]=rec(val,wt,n-1,capacity);
	}
	else
	{
		return dp[n][capacity]=max(val[n-1]+rec(val,wt,n-1,capacity-wt[n-1]),rec(val,wt,n-1,capacity));
	}
}
signed main()
{
	fast;
	int t=1;
	//cin>>t;
	while(t--)
	{
		int n,c;
		cin>>n>>c;
		int wt[n],val[n];
		int i,j,k;
		memset(dp,-1,sizeof(dp));
		for(i=0;i<=n-1;i++)
		{
			cin>>wt[i]>>val[i];
		}
		cout<<rec(val,wt,n,c)<<endl;
		
	}
}

Measured memory_bytes: 83348
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cctype>
#include <climits>
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <list>
#include <queue>
#include <deque>
#include <algorithm>
#include <numeric>
#include <utility>
#include <complex>
#include <memory>
#include <functional>
#include <set>
#include <iomanip>
 
using namespace std;
 
#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < (int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define F(i,j,k) fill(i[0],i[0]+j*j,k)
#define P(p) cout<<(p)<<endl;
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define INF 1<<25
#define pb push_back
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<double> vd;
typedef pair<int, int> pii;
typedef pair<long, long> pll;
typedef long long ll;
 
int dx[4] = {-1,0,1,0};
int dy[4] = {0,-1,0,1};
 
int main()
{
    int a, b, c;
    cin >> a >> b >> c;

    if(a + b == c || b + c == a || a + c == b) {
        cout << "Yes" << endl;
    }else {
        cout << "No" << endl;
    }

    return 0;
}

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

using namespace std;

bool _can_make(vector<int>& v, int key, int idx, int sum) {
    if (sum == key)
        return true;
    if (idx >= v.size())
        return false;

    bool r1 = _can_make(v, key, idx + 1, sum);
    bool r2 = _can_make(v, key, idx + 1, sum + v[idx]);
    return r1 || r2;
}

bool can_make(vector<int>& v, int key) { return _can_make(v, key, 0, 0); }

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

    int q;
    cin >> q;
    for (int i = 0; i < q; ++i) {
        int m;
        cin >> m;
        if (can_make(a, m))
            cout << "yes\n";
        else
            cout << "no\n";
    }
}



Measured memory_bytes: 3104
#include <bits/stdc++.h>
#include<string.h>
using namespace std;
#define li long long int
#define mod 1000000000+7
li n;

double dp[305][305][305];

double f(li x,li y,li z)
{
    if(x==0 && y==0 && z==0)
        return 0;

    if(x<0 || y<0 || z<0)
    {
        return 0;
    }
    if(dp[x][y][z]>-0.9)
    {
        return dp[x][y][z];
    }
    double exp=(n + x*f(x-1,y,z)+ y*f(x+1,y-1,z) + z*f(x,y+1,z-1));
    return dp[x][y][z]=exp/(x+y+z);
}
int main()
{
    cin>>n;
    li t;
    li x1=0,y1=0,z1=0;
    memset(dp,-1.0,sizeof(dp));
    li i;
    for(i=1;i<=n;i++)
    {
        cin>>t;
        if(t==1)x1++;
        if(t==2)y1++;
        if(t==3)z1++;
    }
    cout<<fixed<<setprecision(10)<<f(x1,y1,z1);
    return 0;
}


Measured memory_bytes: 221952
# 問題文
# アライグマはモンスターと戦っています。モンスターの体力は Hです。
# アライグマはN種類の必殺技を使うことができ、i番目の必殺技を使うとモンスターの体力を Ai減らすことができます。
# 必殺技を使う以外の方法でモンスターの体力を減らすことはできません。
# モンスターの体力を0以下にすればアライグマの勝ちです。
# アライグマが同じ必殺技を 2度以上使うことなくモンスターに勝つことができるなら Yes を、できないなら No を出力してください。

# H（体力）,N（種類）：標準入力
# リストの中のA(体力を減らす：攻撃力)：リストを作成し、標準入力
h, n = map(int, input().split())
A = list(map(int, input(). split()))


# 攻撃力Aが0からNの間で増えていくとき、
# H が 0 以下のとき Yes、そうでないとき No となる。

def hp(h: int, n: int, A: list) -> str:
    damage = 0                   # ダメージは最初0なので、0と定義
    for i in range(0, n):        # 0からn番目まで繰り返す時
        damage += int(A[i])      # リスト[i]（インデックスi番目）をintに変更
        i += 1                   # 0番目からi番目まで1ずつ足されていく

    if (h - damage) <= 0:     # forの中で、残った体力が0以下であれば倒せる→Yes
        return 'Yes'
    else:              # 残った体力が0以上の時は倒せる→No
        return 'No'


print(hp(h, n, A))

# TypeError: list expected at most 1 argument, got 2

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

#define int long long
const int _ = 1e5 + 7;
struct Edge{int end , upEd;}Ed[_ << 1];
int head[_] , cntEd , N , A[_] , du[_]; bool flag = 1;
void addEd(int a , int b){Ed[++cntEd] = (Edge){b , head[a]}; head[a] = cntEd; ++du[a];}

int dfs(int x , int p){
	int sum = 0; vector < int > pot;
	for(int i = head[x] ; i ; i = Ed[i].upEd)
		if(Ed[i].end != p){
			int t = dfs(Ed[i].end , x);
			sum += t; pot.push_back(t);
		}
	if(pot.empty()) return A[x];
	sort(pot.begin() , pot.end()); int lft = max(0ll , 2 * (int)pot.back() - sum);
	if(A[x] <= sum && A[x] >= lft + (sum - lft) / 2) return sum - (sum - A[x]) * 2;
	flag = 0; return sum;
}

signed main(){
	cin >> N; for(int i = 1 ; i <= N ; ++i) cin >> A[i];
	for(int i = 1 ; i < N ; ++i){int a , b; cin >> a >> b; addEd(a , b); addEd(b , a);}
	if(N == 2) puts(A[1] == A[2] ? "YES" : "NO");
	else{
		int p = 1; while(du[p] == 1) ++p;
		puts(!dfs(p , 0) && flag ? "YES" : "NO");
	}
	return 0;
}


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

int dp[1002][1002];

int main() {
    int n;
    while (cin >> n, n) {
        for (int i=0; i<n+2; ++i) {
            for (int j=0; j<n+2; ++j) {
                dp[i][j] = 0;
            }
        }
        int ret = 0;
        char sign;
        for (int i=1; i<=n; ++i) {
            for (int j=1; j<=n; ++j) {
                cin >> sign;
                if (sign == '.') {
                    dp[i][j] = min(dp[i-1][j-1], min(dp[i-1][j], dp[i][j-1])) + 1;
                    ret = max(ret, dp[i][j]);
                }
            }
        }
        cout << ret << endl;
    }
    return 0;
}

Measured memory_bytes: 5080
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 550;

int a[N][N], b[N][N], n, m, Q;

int main() {
	scanf("%d%d%d", &n, &m, &Q);
	for (int i = 1; i <= m; ++ i) {
		int x, y; scanf("%d%d", &x, &y); ++ a[x][y];
	}
	for (int i = n; i >= 1; -- i) {
		for (int j = 1; j <= n; ++ j) {
			b[i][j] = a[i][j] + b[i + 1][j] + b[i][j - 1] - b[i + 1][j - 1];
		}
	}
	
	while (Q --) {
		int x, y; scanf("%d%d", &x, &y);
		cout << b[x][y] << endl;
	}
	return 0;
}


Measured memory_bytes: 3072
n,m=map(int,input().split())
ball=[1]*n
p=set()
p.add(1)
for i in range(m):
	x,y=map(int,input().split())
	ball[x-1]-=1
	ball[y-1]+=1
	if x in p:
		p.add(y)
	if x in p:
		if ball[x-1]==0:
			p.remove(x)
print(len(p))

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

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

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

  sort(x.begin(), x.end());

  int a = 0, b = 0;
  int cnt = 1;
  for(int i = n-1; i >= 0; i--){
    if(cnt % 2 == 1){
      a += x[i];
    }else{
      b += x[i];
    }
    cnt++;
  }

  cout << a - b << endl;

  return 0;
}

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

int main() {
    int64_t N;
    cin >> N;
    int64_t A[N];
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }

    int64_t sum = 0;
    int64_t X = 0;
    for (int i = 0; i < N; i++) {
        X = X + A[i];
        X = X % 1000000007;
    }

    for (int i = 0; i < N - 1; i++) {
        int64_t Y;
        if (X - A[i] % 1000000007 < 0) {
            X = X + 1000000007;
        }
        X = X - A[i] % 1000000007;
        Y = A[i] * X;
        Y = Y % 1000000007;
        sum = sum + Y;
        sum = sum % 1000000007;
    }
    cout << sum << endl;

}

Measured memory_bytes: 5144
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
signed main(){
  Int n,k;
  cin>>n>>k;

  Int ans=0;
  for(Int i=0;i<n;i++){
    Int h;
    cin>>h;
    ans+=h>=k;
  }

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


Measured memory_bytes: 256
import java.util.*;

/**
 * C Main
 *
 * @date 2020.09.19
 * @author 焼き鮭 <yaki-shake@up-tri.me>
 */

public class Main {
  Scanner sc;
  int[] memo;

  public static void main(String[] args) {
    new Main().execute();
  }

  public void execute() {
    this.sc = new Scanner(System.in);
    int n = sc.nextInt();
    int cnt = 0;
    this.memo = new int[n + 1];
    for (int i = 1; i < n; i++) {
      cnt += countPair(n - i);
    }

    System.out.println(cnt);
  }

  public int countPair(int n) {
    if (this.memo[n] != 0) {
      return this.memo[n];
    }
    int cnt = 0;
    int max = (int) (Math.sqrt(n));
    for (int i = 1; i <= max; i++) {
      if (n % i == 0) {
        cnt += (i == n / i ? 1 : 2);
      }
    }
    this.memo[n] = cnt;
    return cnt;
  }
}


Measured memory_bytes: 31320
#include <iostream>
#include <string>
using namespace std;
typedef long long ll;
const int MOD = 1000 * 1000 * 1000 + 7;

int dp[2][100][2]; string S;
inline int s(int i) { return S[i] - '0'; }

int main() {
	int d; cin >> S >> d; int n = (int)S.size();
	fill(dp[0][0], dp[0][0] + 400, 0); dp[0][0][1] = 1;
	for (int i = 0; i < n; i++) {
		int I = (i ^ 1) & 1;
		fill(dp[I][0], dp[I][0] + 200, 0);
		for (int k = 0; k < d; k++) {
			for (int j = 0; j < 10; j++) {
				int K = (k + j) % d;
				dp[I][K][0] = (dp[I][K][0] + dp[i & 1][k][0]) % MOD;
				if (s(i) > j) {	dp[I][K][0] = (dp[I][K][0] + dp[i & 1][k][1]) % MOD; }
				if (s(i) == j) { dp[I][K][1] = (dp[I][K][1] + dp[i & 1][k][1]) % MOD; }
			}
		}
	}
	cout << (dp[n & 1][0][1] + dp[n & 1][0][0] - 1 + MOD) % MOD << '\n';
	cin.ignore(2); return 0;
}

Measured memory_bytes: 3616
#pragma region _head

#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<map>
#include<set>
#include<iomanip>
#include<queue>
#include<stack>
#include<numeric>
#include<utility>
#include<regex>

#pragma region _define

#define f(i,a,b) for(int i=a;i<b;i++)
#define f_vI(v,n) f(i,0,n)cin>>v[i]
#define f_v2I(v1,v2,n) f(i,0,n)cin>>v1[i]>>v2[i]
#define f_v3I(v1,v2,v3,n) f(i,0,n)cin>>v1[i]>>v2[i]>>v3[i]
#define f_vO(v,n) f(i,0,n)cout<<v[i]<<endl
#define all(a) a.begin(),a.end()
#define size(s) s.size()
#define check() cout<<"! ! !"
#define endl "\n"
#define _y() cout<<"Yes"<<endl
#define _Y() cout<<"YES"<<endl
#define _n() cout<<"No"<<endl
#define _N() cout<<"NO"<<endl

#pragma endregion

#pragma region _using

using namespace std;

using LL = long long;
using st = string;
using vi = vector<LL>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vc = vector<char>;
using vs = vector<st>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvvb = vector<vvb>;
using si = stack<LL>;
using ss = stack<st>;
using pi = pair<LL, LL>;
using v_pi = vector<pi>;

#pragma endregion

#pragma region _graph

#define node 50  //グラフの最大位数　適宜変更
//bool graph[node][node]; bool visited[node] = { false };
#define link(a,b,m) f(i,0,m){cin>>a[i]>>b[i]; a[i]--; b[i]--; graph[a[i]][b[i]]=graph[b[i]][a[i]]=true;}

#pragma endregion

LL gcd(LL a, LL b) {
	LL r;
	while ((r = a % b) != 0) {
		a = b;
		b = r;
	}
	return b;
}
LL lcm(LL a, LL b) {
	return (a / gcd(a, b) * b);
}

#pragma endregion 

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

	st s;
	cin >> s;
	LL ans = 0;
	f(i, 0, size(s)) {
		if ((s[i] == 'W'&&s[i + 1] == 'B') || (s[i] == 'B'&&s[i + 1] == 'W')) {
			ans++;
		}
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 512
//
//  main.cpp
//  atcoder
//
//  Created by zer0 on 2020/03/22.
//  Copyright © 2020 zer0. All rights reserved.
//

#include <iostream>

int main(int argc, const char * argv[]) {
    
    int m, n;
    
    std::cin >> m >> n;
    
    int a = m * (m - 1) / 2;
    int b = n * (n - 1) / 2;
    
    std::cout << a + b;
    return 0;
}


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

int main(){
  string S,T;
  cin>>S>>T;
  int N=S.size();
  map<char,char> m,n;
  bool flag=true;
  for(int i=0;i<N;i++){
    char c=S.at(i);
    char d=T.at(i);
    if(m.count(c)==0){
      m[c]=d;
    }
    if(n.count(d)==0){
      n[d]=c;
    }
    if(m[c]!=d||n[d]!=c){
      flag=false;
      break;
    }
  }

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


Measured memory_bytes: 776
#include <iostream> 
    #include <algorithm> 
    #include <cstring> 
   
    using namespace std; 
    
    #define mem(a) (memset(a,0,sizeof(a)))
    typedef long long ll;
    ll n,front,last;
    ll gcd(ll x,ll y)
    {
        return y==0?x:gcd(y,x%y);
    }
    ll lcm(ll x,ll y)
    {
        return x/gcd(x,y)*y;
    }
    int main()
    {
        while(scanf("%lld",&n)!=EOF)
        {
            scanf("%lld",&front);
            for(int i=1;i<n;i++)
            {
                scanf("%lld",&last);
                front=lcm(front,last);
            }
            printf("%lld\n",front);
        }
        return 0;
    }

Measured memory_bytes: 256
import java.util.*;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		
		
		for (int i=0; i<1100; i++) {
			if(i*8/100==A && i*10/100==B){
				System.out.println(i);
				return;
			}
		}
		System.out.println(-1);
	}
}


Measured memory_bytes: 25300
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()

typedef long long lint;

using namespace std;

struct UnionFind{
  vector<int> par;
  UnionFind(int N):par(N){
    REP(i,N)par[i]=i;
  }
  int root(int x){
    if(par[x]==x)return x;
    return par[x]=root(par[x]);
  }
  void unite(int x,int y){
    int rx=root(x);
    int ry=root(y);
    if(rx==ry)return;
    par[rx]=ry;
  }
};

int main(){
  int N,M;
  cin>>N>>M;
  int place[N];
  REP(i,N){
    int p;
    cin>>p;
    place[p-1]=i;
  }
  UnionFind t(N);
  REP(i,M){
    int x,y;
    cin>>x>>y;
    x--;y--;
    t.unite(x,y);
  }
  int ans=0;
  REP(i,N){
    if(t.root(i)==t.root(place[i]))ans++;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 1024
#include <iostream>
//#include <fstream>
#include <cmath>
#include <vector>
#include <stdio.h>

using namespace std;

int culcPowerExponent(int n, int K)
{
    int i = 0;
    while (K>n)
    {
        i++;
        n = n << 1;
    }
    return i;
}


int main(int argc, const char * argv[]) {
//    ifstream in("input.txt");
//    cin.rdbuf(in.rdbuf());
    
    int N, K;
    cin >> N >> K;
    
    int n;
    double P = 0;
    for (int i=0; i<N; i++)
    {
        n = i+1;
        P += 1/static_cast<double>(N) * pow(1.0f/2.0f, culcPowerExponent(n, K));
    }
    
    printf("%.12f\n", P);
    
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
		public static void main(String[] args) {
		
	   Scanner sc = new Scanner(System.in);
	   
	   int A = sc.nextInt();
	   int B = sc.nextInt();
	   
	   if(!(A < 10)) {
		   System.out.println(-1);
	   }else if(!(B < 10)) {
		   System.out.println(-1);
	   }else{
          System.out.println(A * B);
       }       
	   
	  
		}
}


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


ll f(ll x , ll C , ll D){
  ll res = x ; 
  res -= x/C ; 
  res -= x/D ; 
  res += x/lcm(C,D) ; 
  return res ; 
}


int main(){
  ll A , B  ; 
  ll C , D ; 
  cin >> A >> B >> C >> D ; 
  
  ll ans = f(B, C ,D) - f(A-1,C,D) ; 
  cout << ans << endl ; 
  return 0 ; 
  
}

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

int main(){
  ll H, W;
  cin >> H >> W;
  if(H==1||W==1) cout << 1 << endl;
  else if(H%2==0) cout << (H/2)*W << endl;
  else if(W%2==0) cout << (W/2)*H << endl;
  else cout << H*(W/2)+((H+1)/2) << endl;
  return 0;
}

Measured memory_bytes: 256
import Text.Printf

ans :: (Int,Int) -> [String] -> (Int,Int)
ans (n,m) (a:b:_) =
  if a == b
  then (n+1,m+1)
  else
    if a > b
    then (n+3,m)
    else (n,m+3)

main = do
  c <- getContents
  let i = map words $ drop 1 $ lines c
      o = foldl ans (0,0) i
  printf "%d %d\n" (fst o) (snd o)

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

using namespace std;

int n, bit = 3;
int can[3] = {3, 5, 7};
int which[10];
vector<int> v;
void dfs(int now) { // library
    if (now == n) {
        // 処理
        string t;
        int a = 0, b = 0, c = 0;
        for (int i = 0; i < n; ++i) {
            t += to_string(which[i]);
            if (which[i] == 3) a++;
            else if (which[i] == 5) b++;
            else c++;
        }
        if (!a || !b || !c) return;
        v.push_back(stoi(t));
        //
        return;
    }
    for (int i = 0; i < bit; ++i) {
        which[now] = can[i];
        dfs(now + 1);
    }
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int x; cin >> x;
    for (int i = 3; i <= (int)to_string(x).size(); ++i) {
        n = i;
        dfs(0);
    }
    int c = 0;
    for (int i = 0; i < (int)v.size(); ++i) {
        if (v[i] <= x) c++;
    }
    cout << c << endl;
}


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

ll fac5( ll n, ll t ){
  if( t == 0 ) return 1;
  ll tmp = fac5(n,t/2);
  if( t%2 == 0 ){
    return tmp*tmp;
  }else{
    return tmp*tmp*n;
  }
}

int main(){
  ll x;cin >> x;
  for(ll i=-1000;i<=1000;++i){
    for(ll j=-1000;j<=1000;++j){
      if( fac5(i,5) - fac5(j,5) == x ){
        cout << i << " " << j << endl;
        return 0;
      }
    }
  }
  return 0;
}

Measured memory_bytes: 3636
#include <iostream>


void swap(int & a, int & b) {
	int tmp = a;
	a = b;
	b = tmp;
}

int main()
{
	int x[3];
	std::cin >> x[0] >> x[1] >> x[2];

	if (x[0] > x[1]) swap(x[0], x[1]);
	if (x[0] > x[2]) swap(x[0], x[2]);
	if (x[1] > x[2]) swap(x[1], x[2]);

	printf("%d %d %d\n", x[0], x[1], x[2]);
	return 0;
}


Measured memory_bytes: 3172
n = int(input())
import math
divisors = []
for i in range(1, math.ceil(math.sqrt(n))+1):
  if n%i==0:
    divisors.append([i, n//i])

ans = 2*10**12
for divisor in divisors:
  ans = min(ans, divisor[0]+divisor[1]-2)
print(ans)

Measured memory_bytes: 3472
#include <bits/stdc++.h>
using namespace std;  
#define rep(i, a, b) for(ll i = a; i < b; i++)
#define Rep(i, a, b) for(ll i = a; i <= b; i++)
#define repr(i, a, b) for(ll i = b-1; i >= a; i--)
// #define _GLIBCXX_DEBUG
#define Vl vector<ll>
#define Vs vector<string>
#define Vp vector<pair<ll, ll>>
using ll = long long;
#define ALL(v) (v).begin(),(v).end()
#define endl "\n"
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define co(x) cout << x << endl
#define pb push_back
#define sz(v) ((ll)(v).size())
const double pi = acos(-1.0);
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
#define pp pair<ll, pair<ll, ll>> 
// #define fi first
// #define se second
// ios::sync_with_stdio(false);
// cin.tie(nullptr);
const int dy[] = {1, 0, -1, 0};
const int dx[] = {0, 1, 0, -1};

/*--------------------------------------------------------------------------------

--------------------------------------------------------------------------------*/

int main() {
    ll n;
    cin >> n;
    Vl a, b;
    rep(i, 0, n){
        ll x, y;
        cin >> x >> y;
        a.push_back(x+y);
        b.push_back(x-y);
    }
    sort(ALL(a));
    sort(ALL(b));
    cout << max(a[n-1]-a[0], b[n-1]-b[0]) << endl;

    return 0;
}

Measured memory_bytes: 6652
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<tuple>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-15
#define mp(a1,a2) make_pair(a1,a2)
typedef long long ll;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
const int MAX = 200000;
const int MOD = 1e+9+7;
ll fac[MAX], finv[MAX], inv[MAX];
void COMinit(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i = 2; i < MAX; i++){
        fac[i] = fac[i-1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD;
        finv[i] = finv[i-1] * inv[i] % MOD;
    }
}
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(){
	COMinit();
	ll H,W,A,B;
	scan(H);scan(W);scan(A);scan(B);
	ll all,sub=0;
	all=COM(H+W-2,H-1);
	rep1(k,A){
		sub+=COM(H-k+B-1,H-k)*COM(k-1+W-B-1,k-1)%MOD;
		sub%=MOD;
	}
	all-=sub;
	if(all<0) all+=MOD;
	prin(all);
	return 0;
}


Measured memory_bytes: 4992
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

kill=0
for i in range(N):
    x1 = min(B[i], A[i])
    x2 = min(B[i]-x1, A[i+1])
    A[i+1] -= x2

    kill += x1 + x2

print(kill)

Measured memory_bytes: 19116
#pragma GCC optimize(2)
#pragma G++ optimize(2)
#include<bits/stdc++.h>
#define si(a) scanf("%d",&a)
#define sl(a) scanf("%lld",&a)
#define sd(a) scanf("%lf",&a)
#define ss(a) scanf("%s",a)
#define ms(a) memset(a,0,sizeof(a))
#define repi(i,a,b) for(register int i=a;i<=b;++i)
#define repd(i,a,b) for(register int i=a;i>=b;--i)
#define reps(s) for(int i=head[s];i;i=e[i].nxt)
#define ce(i,r) i==r?'\n':' '
#define pb push_back 
#define all(x) x.begin(),x.end()
#define fi first
#define se second
#define pr(x) cout<<#x<<": "<<x<<endl
using namespace std;
typedef long long ll;
const int MAX_N=2e3+5;
struct node{
	ll val;
	int id;
}a[MAX_N];
bool cmp(node a,node b)
{
	return a.val>b.val;
}
ll dp[MAX_N][MAX_N];
int main()
{
	ms(dp);
	int n; si(n);
	repi(i,1,n) sl(a[i].val),a[i].id=i;
	sort(a+1,a+1+n,cmp);
	ll ans=0;
	repi(l,0,n-1)repi(r,0,n-1)if(l+r+1<=n){
		int now=l+r+1;
		dp[l+1][r]=max(dp[l+1][r],dp[l][r]+a[now].val*abs(l+1-a[now].id));
		dp[l][r+1]=max(dp[l][r+1],dp[l][r]+a[now].val*abs((n-r)-a[now].id));
		ans=max(ans,max(dp[l+1][r],dp[l][r+1]));
	}
	printf("%lld\n",ans);
	return 0;
} 

Measured memory_bytes: 35244