akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>

int main (void)
{
    int i,comi;
    int K,N;
    int min,minval;
    int p[1000];
    int flag[1000];
    int first=0;
    int sum=0;
    char c;

    scanf("%d %d",&N,&K);
    scanf("%c",&c);

    for(i=0;i<N;i++){
        scanf("%d",&p[i]);
        scanf("%c",&c);
        flag[i]=1;
    }

    for(i=0;i<K;i++){
        first=0;
        for(comi=0;comi<N;comi++){
            if(flag[comi]==0){
                continue;
            }else if(first==0){
                minval=p[comi];
                min=comi;
                first=1;
            }else if( p[comi]<minval ){
                minval=p[comi];
                min=comi;
            }
        }
        sum+=minval;
        flag[min]=0;


    }

    printf("%d",sum);

    return 0;
}

Measured memory_bytes: 1740
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define stoi stoll
using ll=long long;
using vi=vector<int>;
using pii=pair<int,int>;
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)
#define ITR(i,b,e) for(auto i=(b);i!=(e);++i)
#define FORE(x,c) for(auto &x:c)
#define REPF(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define REP(i,n) REPF(i,0,n)
#define REPR(i,n) for(int i=(int)(n);i>=0;--i)
#define SZ(c) ((int)c.size())
#define CONTAIN(c,x) (c.find(x)!=end(c))
#define OUTOFRANGE(y,x,h,w) ((y)<0||(x)<0||(y)>=(h)||(x)>=(w))
#define dump(...)
const signed INF_=1001001001; const long long INF=1001001001001001001LL;
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) {
    ITR(i,begin(v),end(v))os<<*i<<(i==end(v)-1?"":" ");return os;}
template<class T> istream& operator>>(istream &is,vector<T> &v) {
    ITR(i,begin(v),end(v)) is>>*i;return is;}
template<class T,class U> istream& operator>>(istream &is, pair<T,U> &p) {
    is>>p.first>>p.second;return is;}
template<class T> bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a,const T &b){if(a>b){a=b;return 1;}return 0;}
template<class T> using heap=priority_queue<T,vector<T>,greater<T>>;
struct{template<class T> operator T(){T x;cin>>x;return x;}} IN;
struct before_main_function {
    before_main_function() {
        cin.tie(0);ios::sync_with_stdio(false);
        cout<<setprecision(15)<<fixed;
        #define endl "\n"
    }
} before_main_function;
//------------------8<------------------------------------8<--------------------

signed main() {
    int A,B;
    cin>>A>>B;
    char bl='#',wh='.';
    if(A>B) {
        swap(bl,wh);
        swap(A,B);
    }
    vector<vector<char>> ans(100,vector<char>(100,wh));
    REP(i,B) {
        int y=(i/25)*4+1;
        int x=(i%25)*4+1;
        REP(dir,8) {
            int yy=y+DY[dir];
            int xx=x+DX[dir];
            ans[yy][xx]=bl;
        }
    }
    A--;
    REP(i,B-A) {
        int y=(i/25)*4+1;
        int x=(i%25)*4+1;
        ans[y][x]=bl;
    }
    cout<<"100 100"<<endl;
    REP(i,100) {
        REP(j,100) {
            cout<<ans[i][j];
        }
        cout<<endl;
    }
    return 0;
}



Measured memory_bytes: 256
// Problem : B - 123 Triangle
// Contest : AtCoder - AtCoder Grand Contest 043
// URL : https://atcoder.jp/contests/agc043/tasks/agc043_b
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define db long double
#define pb push_back
#define pii pair<int,int>
#define vi vector<int>
#define vl vector<ll>
#define vii vector<pii>
#define mi map<int,int>
#define ml map<ll,ll>
#define mii map<pii,int>
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()
#define sz(x) (int)x.size()
#define mod 1000000007
#define MAX 4294967295
#define EPS 1e-9
#define io ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define MAXN 15000005
#define inf 1e10
#define PI acos(-1.0)
#define int long long

int n;
string s;
vi a(1000005);

bool check(int n, int k){ return (n&k) == k; }

int getXor(){
    int ret = 0;
    for(int i=0;i<n;i++){
        if(a[i]%2) ret ^= check(n-1,i);
    }
    return ret;
}

signed main(){
    io;
    //freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
    cin>>n>>s;
    for(int i=0;i<n;i++) a[i] = s[i]-'1';
    if(getXor()) return cout<<1, 0;
    bool exist = false;
    for(int i=0;i<n;i++) exist |= a[i]==1;
    if(exist) return cout<<0, 0;
    for(int i=0;i<n;i++) a[i] /= 2;
    if(getXor()) cout<<2;
    else cout<<0;
    return 0;
}


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

using namespace std;

#define ll long long

void solve() {
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	int e = a+b;
	int f = c+d;
	if (e == f) {
		cout << "Balanced\n";
	} else if (e > f) {
		cout << "Left\n";
	} else {
		cout << "Right\n";
	}
}

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

	int t = 1, i = 1;
	//cin >> t;
	while(t--) {
		//cout << "Case #" << i << ": ";
		solve();
		//i++;
	}
	return 0;
}



Measured memory_bytes: 3632
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <cstdint>

#include <map>
 
using namespace std;
typedef long long ll;

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


ll ans,mx,sum,mn=1e8;
int main(){
	ll n,x;
	cin>>n>>x;
	ll a[n];
	for(ll i=0; i<n; i++){
		cin>>a[i];
	}
	sort(a,a+n);
	ans = a[1]-a[0];
	for(ll i=2; i<n; i++){
		ans = gcd(ans,a[i]-a[0]);
	}
	if(n==2) {
		cout<<gcd(a[0],a[1]);
	}
	else if(n==1) cout<<abs(x-a[0]);
	else cout<<ans<<endl;
}



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

int main() {
   int n;
   cin>>n;
  vector<long long> a(n);
  for(int i=0;i<n;i++) cin>>a[i];
  sort(a.begin(),a.end());
  
  int de=0;
  while(de<n-1){
    int d=de;
  	for(int i=d+1;i<n;i++){
    	a[i]=a[i]%a[d];
        if(a[i]==0) de++; 
    }
    sort(a.begin(),a.end());
  }
  cout<<a[n-1];
}


Measured memory_bytes: 3988
#include<bits/stdc++.h>
//ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
//clock_t start=clock();clock_t end=clock();cout<<(double)(end-start)/CLOCKS_PER_SEC<<endl;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<pll,ll> ppll;
typedef pair<ll,pll> plpl;
typedef pair<pii,pii> pippi;
typedef tuple<ll,ll,ll> tl;
typedef pair<double,double> pdd;
typedef vector<vector<ll>> mat;
ll mod=1000000007;
ll mod2=998244353;
ll mod3=1000003;
ll mod4=998244853;
ll mod5=1000000009;
ll inf=1LL<<62;
int iinf=1<<30;
double pi=3.141592653589793238462643383279L;
double eps=1e-8;
#define rep(i,m,n) for(ll i=m;i<n;i++)
#define rrep(i,n,m) for(ll i=n;i>=m;i--)
#define srep(itr,st) for(auto itr=st.begin();itr!=st.end();itr++)
#define mrep(itr,mp) for(auto& itr:mp)
#define Max(a,b) a=max(a,b)
#define Min(a,b) a=min(a,b)
//#define endl "\n"
int dh[4]={1,-1,0,0};
int dw[4]={0,0,1,-1};
int ddh[8]={-1,-1,-1,0,0,1,1,1};
int ddw[8]={-1,0,1,-1,1,-1,0,1};
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
#define umh unordered_map<int,int,custom_hash>
ll gcd(ll a,ll b){
    if(a<b)swap(a,b);
    if(b==0)return a;
    if(a%b==0)return b;
    return gcd(b,a%b);
}
ll lcm(ll a,ll b){
    ll c=gcd(a,b);
    return a*b/c;
}
ll Pow(ll n,ll k){
    if(k<0)return 0;
    ll ret=1;
    ll now=n;
    while(k>0){
        if(k&1)ret*=now;
        now*=now;
        k/=2;
    }
    return ret;
}
ll beki(ll n,ll k,ll md){
  ll ret=1;
  ll now=n;
    now%=md;
  while(k>0){
    if(k%2==1){
      ret*=now;
      ret%=md;
    }
    now*=now;
    now%=md;
    k/=2;
  }
  return ret;
}
ll gyaku(ll n,ll md){
  return beki(n,md-2,md);
}
ll popcount(ll n){
    ll ret=0;
    ll u=n;
    while(u>0){
        ret+=u%2;
        u/=2;
        
    }
    return ret;
}
ll n;
vector<ll> v[200010];
int main(){
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    cin>>n;
    rep(i,0,n-1){
        ll a,b;cin>>a>>b;
        a--;
        b--;
        v[a].push_back(b);
        v[b].push_back(a);
    }
    ll ans=0;
    ll now=0;
    rep(i,1,n+1){
        now+=i;
        ans+=now;
    }
    vector<pll> w;
    vector<ll> h[n];
    rep(i,0,n){
        rep(j,0,v[i].size()){
            ll ne=v[i][j];
            if(ne<i){
                w.push_back({i,ne});
                h[ne].push_back(i);
            }
        }
    }
    ll gen=0;
    rep(i,0,w.size()){
        ll y=w[i].first;
        gen+=n-y;
    }
    rep(i,0,n){
        ans-=gen;
        rep(j,0,h[i].size()){
            ll y=h[i][j];
            gen-=n-y;
        }
    }
    cout<<ans<<endl;
}



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

int main()
{
    int a, b, c;
    cin >> a >> b >> c;
    int count = 0;
    for (int i = a; i <= b; i++)
    {
        if (c % i == 0)
            count++;
    }
    cout << count << endl;
    return 0;
}


Measured memory_bytes: 3092
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys

err = 1e-10

def cross(v1,v2):
  return v1[0]*v2[1]-v1[1]*v2[0]

num = input()

for i in range(num):
  d = map(float,sys.stdin.readline().split())
  x1,y1,x2,y2,x3,y3,x4,y4 = d[0],d[1],d[2],d[3],d[4],d[5],d[6],d[7]
  ab = [ x2-x1, y2-y1 ]
  cd = [ x4-x3, y4-y3 ]
  if abs(cross(ab,cd)) < err:
    print "YES"
  else:
    print "NO"

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

template <typename T> class tRMQ {
  vector<T> data;
  T unit;

public:
  int n;
  function<T(const T &, const T &)> f;

  tRMQ(int _, T u, function<T(T, T)> bi) {
    unit = u;
    f = bi;
    n = 1;
    while (n < _) {
      n <<= 1;
    }
    data.resize(n * 4);
    for (int i = 0; i < 4 * n; i++)
      data[i] = unit;
  }

  tRMQ(vector<T> &v, T u, function<T(T, T)> bi) {
    unit = u;
    f = bi;
    n = 1;
    while (n < v.size())
      n <<= 1;
    data.resize(n * 2 + 10);
    for (int i = 0; i < n + 10; i++) {
      if (i < v.size())
        data[i + n] = v[i];
      else
        data[i + n] = u;
    }
    for (int i = n - 1; i >= 0; i--) {
      data[i] = f(data[i * 2 + 1], data[i * 2 + 2]);
    }
  }

  void update(int index, T val) {
    int i = index + n - 1;
    data[i] = val;
    while (i > 0) {
      i = (i - 1) / 2;
      data[i] = f(data[i * 2 + 1], data[i * 2 + 2]);
    }
  }

  // [a, b)
  T query(int a, int b, int k, int l, int r) {
    if (a < 0 || r <= a || b <= l) {
      return unit;
    }
    if (a <= l && r <= b) {
      return data[k];
    } else {
      return f(query(a, b, k * 2 + 1, l, (l + r) / 2),
               query(a, b, k * 2 + 2, (r + l) / 2, r));
    };
  }

  T query(int a, int b) { return query(a, b, 0, 0, n); }
};

int DAY = 86400;
int MOR = 10800;

int main() {
  int n;
  cin >> n;
  int base = 0;
  vector<ll> d(DAY);
  for (int i = 0; i < n; i++) {
    int a, b;
    cin >> a >> b;
    d[(base + a) % DAY] += 1;
    base += a + b;
    base %= DAY;
  }
  tRMQ<ll> q(d, 0ll, [](const ll &l, const ll &r) { return l + r; });
  ll ans = 0;
  for (int i = 0; i < DAY; i++) {
    ll b = q.query(max(-DAY + i, 0), max(-DAY + i + MOR + 1, 0)) +
           q.query(min(i, DAY), min(i + MOR + 1, DAY));
    ans = max(ans, b);
  }
  cout << ans << endl;
  return 0;
}

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

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

using namespace std;
typedef long long int ll;

const int MOD = 1000000007;
struct mint { int n; mint(int n_ = 0) : n(n_) {} };
mint operator-(mint a) { return -a.n + MOD * (a.n != 0); }
mint operator+(mint a, mint b) { int x = a.n + b.n; return x - (x >= MOD) * MOD; }
mint operator-(mint a, mint b) { int x = a.n - b.n; return x + (x < 0) * MOD; }
mint operator*(mint a, mint b) { return (long long)a.n * b.n % MOD; }
mint &operator+=(mint &a, mint b) { return a = a + b; }
mint &operator-=(mint &a, mint b) { return a = a - b; }
mint &operator*=(mint &a, mint b) { return a = a * b; }
istream &operator>>(istream &i, mint &a) { return i >> a.n; }
ostream &operator<<(ostream &o, mint a) { return o << a.n; }

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 N;
ll a[3000];
ll dp[3001][3001];

int main(void){
    cin >> N;
    rep(i,N) cin >> a[i];

    for(int len=1;len <= N;len++)
        for(int i = 0;i+len<=N;i++){
        int j = i + len;
        if((N-len)%2 == 0) dp[i][j] = max(dp[i + 1][j] + a[i], dp[i][j - 1] + a[j - 1]);
        else dp[i][j] = min(dp[i + 1][j] - a[i], dp[i][j - 1] - a[j - 1]);
    }

    cout << dp[0][N] << endl;
    return 0;
}



Measured memory_bytes: 70016
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)

const ll MOD = 1000000007;
const ll HIGHINF = (ll)1e18;

int main() {
  ll n, m; cin >> n >> m;
  ll total = m * 1900 + (n-m) * 100;
  cout << total * (ll)pow(2, m) << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue>
#include <climits>
int main(void){
    long N,Q;
    std::cin >> N >> Q;
    std::string S;
    std::cin >> S;
    long Alist[100000+1]={};
    long Clist[100000+1]={};

    long ACsum=0;
    Alist[0]=0;
    Clist[0]=0;
    Clist[1]=0;
    for(long i=0; i<S.length()-1;i++){
        if(S[i]=='A' && S[i+1]=='C'){
            ACsum++;
        }
        Alist[i+1]=ACsum;
        Clist[(i+1)+1]=ACsum;
    }
    Alist[S.length()]=ACsum;

    for(long i=0; i<Q; i++){
        long l,r;
        std::cin >> l >> r;
        std::cout << std::min(Alist[r]-Alist[l-1],Clist[r]-Clist[l]) << std::endl;;
    }
    return 0;
}

Measured memory_bytes: 5312
# coding:utf-8
n = int(input())
h = list(map(int, input().split()))

ans = 0
tmp = 0

for i in range(0, n - 1):
    if h[i] >= h[i + 1]:
        tmp += 1
    else:
        ans = max(tmp, ans)
        tmp = 0

ans = max(tmp, ans)
print(ans)


Measured memory_bytes: 14252
#include<bits/stdc++.h>
using namespace std;
#define FasterIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)

typedef unsigned long long ull;
typedef long long ll;
typedef double db;

#define mem(a,x) memset(a,x,sizeof(a))
#define pb push_back
#define ff first
#define ss second
#define mk make_pair
#define pi pair<int,int>
#define vi vector<int>
#define pL pair<ll,ll>
#define vL vector<ll>
#define vp vector<pi>
#define vpL vector<pL>

const int MX=2000000;
const ll mod=998244353;
const int LG=26;


ll L[MX];

int main()
{
    FasterIO;

    int n;

    cin>>n;

    for(int i=1; i<=n; i++) cin>>L[i];


    int cn=0;

    for(int i=1; i<=n; i++)
    {
        for(int j=i+1; j<=n; j++)
        {
            for(int k=j+1; k<=n; k++)
            {
                if(L[i]==L[j] || L[i]==L[k] || L[j]==L[k]) continue;
                int x=min({L[i], L[j], L[k]}), z=max({L[i], L[j], L[k]}), y=(L[i]+L[j]+L[k]-x-z);
                if(x+y>z) cn++;
            }
        }
    }

    cout<<cn<<endl;

    return 0;
}


Measured memory_bytes: 3640
#include <algorithm>
#include <bitset>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stdio.h>
#include <string>
#include <vector>

#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using LP = pair<ll, ll>;
const double PI = 3.1415926535897932;

/* a と b の最大公約数を返す関数 */
long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}

int main()
{
	int S, W;
	cin >> S >> W;

	int TW = W * 2;
	if (S <= W) {
		cout << "unsafe" << endl;
	}
	else {
		cout << "safe" << endl;
	}

	return 0;
}


Measured memory_bytes: 3636
#include <iostream>
#include <string>
using namespace std;
 
int main(){
string in;
int a[300] = {};
cin >> in;
for(int i = 0;i<in.size();i++){
a[in[i]]++;
if(a[in[i]] > 1){
cout << "no" << endl;
return 0;
}
}
cout << "yes" << endl;
return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() {
	long long K, A, B; cin >> K >> A >> B;
	if (B <= A + 1) {//硬貨にしないほうがよい
		cout << 1 + K << endl;
		return 0;
	}
	//硬貨にしたほうがよい場合
		if (K <= A) {//どんなに頑張っても硬貨からビスケットにできない
			cout << 1 + K << endl;
			return 0;
		}
		else {//少なくとも一回はビスケットに変換できる
			if ((K - A) % 2 == 0) {//残りの操作が偶数回
				long long ans = 0;
				long long nokori = K - A;
				long long ret =nokori/ 2;//残されたセット数
				ret--;//最後の一回は特別
				ans += ret * (B - A);//セットの操作数を足す
				ans += B + 1;//最後は返還のBと叩くA
				cout << ans << endl;
				return 0;
			}
			else {//最後が返還で終わる
				long long ans = 0;
				long long nokori = K - A-1;
				long long ret =nokori/ 2;//残されたセット数
				//最後の一回はすでに除いた
				ans += ret * (B - A);
				ans += B;
				cout << ans << endl;
				return 0;
			}
		}
}

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

int main() {
  int N;
  ll x;
  cin >> N >> x;
  vector<ll> a(N);
  for (int i = 0; i < N; ++i) {
    cin >> a[i];
  }
  vector<ll> dp(N, 0);
  dp[0] = max((ll)0, a[0] - x);
  a[0] = min(a[0], x);
  for (int i = 1; i < N; ++i) {
    dp[i] = dp[i - 1] + max((ll)0, a[i] - x);
    a[i] = min(a[i], x);
    dp[i] += max((ll)0, a[i - 1] + a[i] - x);
    a[i] -= max((ll)0, a[i - 1] + a[i] - x);
  }
  cout << dp[N - 1] << endl;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
#define ll                  long long int
#define ull                 unsigned long long int
#define ld                  long double
#define fi                  first
#define se                  second
#define pb                  push_back
#define pbb                 pop_back
#define mp                  make_pair
#define popcount            __builtin_popcountll
#define pii     	        pair<int,int>
#define all(x)              x.begin(), x.end()
#define uniq(x)             x.erase(unique(x.begin(),x.end()),x.end())
#define mem(array, value)   memset(array, value, sizeof(array))
#define lcm(a,b)            (abs(a)/gcd(a,b))*abs(b)
#define random(a, b)        ((((rand() << 15) ^ rand()) % ((b) - (a) + 1)) + (a))
#define PI      	        2*acos(0.0)
#define INF     	        1e9
#define EPS     	        1e-8
#define line                cout << "\n==========\n"
#define fastRead 	        ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;
//using namespace __gnu_pbds;
//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> orderedSet;

//int dx[] = {1, -1, 0, 0},                  dy[] = {0, 0, 1, -1};                  // 4 Direction
//int dx[] = {1, -1, 0, 0, 1, 1, -1, -1},    dy[] = {0, 0, 1, -1, 1, -1, 1, -1};    // 8 Direction
//int dx[] = {1, -1, 1, -1, 2, 2, -2, -2},   dy[] = {2, 2, -2, -2, 1, -1, 1, -1};   // Knight Direction

inline ll gcd(ll a, ll b){
    a = abs(a);
    b = abs(b);
    while (b){
        a = a % b;
        swap (a, b);
    }
    return a;
}
inline ll power(ll a, ll p){
    ll res = 1, x = a;
    while (p){
        if (p & 1){
            res = (res * x);
        }
        x = (x * x);
        p >>= 1;
    }
    return res;
}
inline ll bigmod(ll a, ll p, ll m){
    ll res = 1 % m, x = a % m;
    while (p){
        if (p & 1){
            res = (res * x) % m;
        }
        x = (x * x) % m;
        p >>= 1;
    }
    return res;
}

int main ()
{
    #ifdef Lollipop
    //freopen ("input.txt", "r", stdin);
    //freopen ("output.txt", "w", stdout);
    #endif
    int n;
    cin >> n;
    int ans = 0;
    int x;
    for (int i = 0; i<n; i++){
        cin >> x;
        ans = gcd(ans, x);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
from collections import Counter
N = int(input())
c = Counter([int(s) for s in input().split()])
a = [(k, v) for k, v in c.items() if v > 1]
a.sort(reverse=True)
if len(a) < 1:
    print(0)
elif a[0][1] >= 4:
    print(a[0][0] ** 2)
elif len(a) < 2:
    print(0)
else:
    print(a[0][0] * a[1][0])


Measured memory_bytes: 18600
#include <iostream>
#include <sstream>
#include <iomanip>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <vector>
#include <cmath>
#include <math.h>
#include <stdexcept>
#include <algorithm>
#include <set>
#include <map>
#include <stdlib.h>
#include <cctype>
using namespace std;
int main(){
    long int A,B,AB,X,Y,p,i,a,b,answer;
    answer = 1000000010;
    cin >> A >> B >> AB >> X >> Y;
    AB *= 2;
    if(X < Y){
        p = A;
        A = B;
        B = p;
        p = X;
        X = Y;
        Y = p;
    }
    //必要数A > B
    for(i = 0;i <= X;i++){
        //iはABセットの購入数
        a = X - i;
        if(Y - i <= 0) b = 0;
        else b = Y - i;
        if(answer > a * A + b * B + i * AB){
            answer = a * A + b * B + i * AB;
        }
    }
    cout << answer << endl;
}

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

using namespace std;
// void fill(std::vector<int> &v,std::vector<int> &fill1,vector<int> &fill2,int p,int k){
// 	int x=v.size();
// 	if (p==1){
// 		int pb=0;
// 		for(int i=0;i<x;i++){
// 			if(v[i]<=k){
// 				if(fill2[k-v[i]]==0)fill(v,fill1,fill2,2,k-v[i]);
// 				if(fill2[k-v[i]]==1){
// 					fill1[k]=1;

// 					pb=1;
// 					break;					
// 				}
// 				else if(fill2[k-v[i]]==2)continue;
// 			}
// 		}
// 		if(!pb){
// 			fill1[k]=2;
// 			// fill2[k]=2;
// 		}

// 		return;
// 	}
// 	else {
// 		int pb=0;
// 		for(int i=0;i<x;i++){
// 			if(v[i]<=k){
// 				if(fill1[k-v[i]]==0)fill(v,fill1,fill2,1,k-v[i]);
// 				if(fill1[k-v[i]]==2){
// 					fill2[k]=2;
// 					pb=1;
// 					break;					
// 				}
// 				else if(fill1[k-v[i]]==1)continue;
// 			}
// 		}
// 		if(!pb){
// 			fill2[k]=1;
// 			// fill1[k]=1;
// 		}
// 		return ;

// 	}

// } 
// void fill(std::vector<long> &a,vector<std::vector<long> > &v,int n,long k){
// 	long sum=0;
// 	long m=v[0].size()-1;
// 	for(long i=k;i<=min(m,k+a[n]);i++){
// 		if(v[n-1][i]==-1){
// 			fill(a,v,n-1,i);
// 		}
// 		sum=(sum+v[n-1][i])%1000000007;
// 	}
// 	v[n][k]=sum;
// 	return;

// }
void fill(std::vector<long> &v,std::vector<long> &sum,std::vector<std::vector<long> > &cost){
	int n=v.size();
	for(int l=2;l<=n;l++){
		for (int i = 0; i < n-l+1; ++i)
		{
			int j=i+l-1;
			long mini=LONG_MAX;
			for(int k=i;k<j;k++){
				if(i)mini=min(mini,cost[i][k]+cost[k+1][j]+sum[j]-sum[i-1]);
				else mini=min(mini,cost[i][k]+cost[k+1][j]+sum[j]);

			}
			cost[i][j]=mini;
		}
	}
	return ;
}
int main(int argc, char const *argv[])
{
	int n;
	cin>>n;
	std::vector<long> v(n);
	for (int i = 0; i < n; ++i)
	{
		/* code */
		cin>>v[i];
	}
	std::vector<long> sum(n);
	sum[0]=v[0];
	for (int i = 1; i < n; ++i)
	{
		/* code */
		sum[i]=sum[i-1]+v[i];
	}
	std::vector<vector<long> > cost(n,std::vector<long>(n,0));
	fill(v,sum,cost);
	cout<<cost[0][n-1]<<"\n";


	return 0;
}

Measured memory_bytes: 1536
def main():
    A,B,C,D=map(int,input().split())
    t=True
    while A>0 and C>0:
        if t: C-=B
        else: A-=D
        t=not t
    if A<=0: print('No')
    elif C<=0: print('Yes')

if __name__=='__main__':
    main()

Measured memory_bytes: 9180
N, M = map(int, input().split())
A = [list(input()) for i in range(N)]
B = [list(input()) for i in range(M)]
flag = False

for x1 in range(N - M + 1):
    for x2 in range(N - M + 1):
        check = True
        for y in range(M):
            for z in range(M):
                if A[z + x1][y + x2] != B[z][y]:
                    check = False

                # print(A[z][y])
                # print(B[z][y])
        if check:
            flag = True
            break

if flag:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 71504
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<functional>
#include<math.h>
using namespace std;
#define N (1000000000+7)
#define M (998244353)
#define INF 1e16
typedef long long ll;
typedef pair<ll,ll> P;

int dp[5005][5005];

int main(void){
    int n;
    string s;
    cin>>n>>s;
    int res=0;
    for(int r=n-1;r>0;r--){
        for(int l=r-1;l>=0;l--){
            if(s[r]==s[l])dp[l][r]=max(dp[l][r],dp[l+1][r+1]+1);
            res=max(res,min(dp[l][r],r-l));
        }
    }
    cout<<res<<endl;
    return 0;
}

Measured memory_bytes: 96768
//Ruthless Coding 
#include <bits/stdc++.h>

#define uni(x)      (x).resize(unique(all(x)) - (x).begin())
#define fprint(v)   for(auto x : v) cout << x << ' '
#define ALL(x)      (x).begin(), (x).end()
#define MP(x, y)    make_pair(x, y)
#define PII         pair<int, int>
#define SZ(x)       int((x).size())
#define PB(x)       push_back(x)
#define ll          long long
#define S           second 
#define F           first
#define nl          '\n'

using namespace std;

mt19937_64 rnd;

const int N = 2e5 + 5;

int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);
    int n;
    cin >> n;
    int ans = -1;
    int num = 0;
    for(int i = 1; i <= n; i++){
        int cnt = 0;
        int yo = i;
        while(yo > 0){
            cnt += (yo % 2 == 0);
            yo /= 2;
        }
        if(ans < cnt){
            ans = cnt;
            num = i;
        }
    }
    cout << num;
    return 0;
}


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

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

Measured memory_bytes: 256
N, M, X, Y = map(int, input().split())
x_list = list(map(int, input().split()))
y_list = list(map(int, input().split()))
max_x = max(x_list)
min_y = min(y_list)
for i in range(max_x + 1, min_y + 1):
    if (X < i and i <= Y):
        print("No War")
        exit()
print("War")

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

int main(){
    string N;cin>>N;
    char a = N.at(N.size()-1);
    if(a=='2'||a=='4'||a=='5'||a=='7'||a=='9')cout<<"hon"<<endl;
    else if(a=='0'||a=='1'||a=='6'||a=='8')cout<<"pon"<<endl;
    else cout<<"bon"<<endl;
}

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

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

typedef long long ll;

const int INF = 1 << 30;
const ll LLINF = 1LL << 62;

int mod = 1000000007;

int main(void){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll K; cin >> K;
  ll A[K]; rep(i, K) cin >> A[i];
  if(A[K-1] != 2) cout << -1 << endl;
  else{
    ll dlim = 2, ulim = 3; //ラウンドに参加する可能性のある子供の下限と上限
    for(int i = K-2; i >= 0; i--){
      //A[i]の倍数になるようにdlimとulimを調整
      dlim = dlim + ((A[i] - dlim%A[i]) % A[i]);
      ulim = ulim - (ulim%A[i]);
      if(dlim > ulim){cout << -1 << endl; return 0;}
      ulim = ulim + A[i] - 1;

      //cout << dlim << " " << ulim << endl;
    }

    cout << dlim << " " << ulim << endl;
  }
  return 0;
}

Measured memory_bytes: 4368
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <set>
#include <string>
#include <vector>
#define SORT(a) sort((a).begin(), (a).end())
#define RSORT(a) sort((a).rbegin(), (a).rend())
#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(a) a.begin(), a.end()
typedef long long int ll;
using namespace std;

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

    vector<int> a(7);
    REP(i, 6) cin >> a[i];

    int ac = 0, bc = 0, cc = 0, dc = 0;

    REP(i, 6) {
        if (a[i] == 1)
            ac++;
        if (a[i] == 2)
            bc++;
        if (a[i] == 3)
            cc++;
        if (a[i] == 4)
            dc++;
    }
    if (ac > 2 || bc > 2 || cc > 2 || dc > 2) {
        cout << "NO" << endl;
    } else {
        cout << "YES" << endl;
    }
    return 0;
}

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

int main(){
	int N, W, volume[100001], value[100001];
	long long** dp = new long long*[102];
	for(int i=1; i<=101; i++) dp[i] = new long long[100001];
	for(int i=1; i<=101; i++){
		for(int j=0; j<=100000; j++){
			dp[i][j] = 0;
		}
	}
	
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	
	cin >> N >> W;
	for(int i=1; i<=N; i++) cin >> volume[i] >> value[i];
	
	for(int obj=1; obj<=N; obj++){
		for(int vol=0; vol<=W; vol++){
			if(volume[obj] > vol)
				dp[obj+1][vol] = dp[obj][vol];
			else
				dp[obj+1][vol] = max(dp[obj][vol], dp[obj][vol-volume[obj]]+value[obj]);
		} 
	}
	
	cout << dp[N+1][W] << '\n';
}

Measured memory_bytes: 82852
#define _GLIBCXX_DEBUG
#include"bits/stdc++.h"

using namespace std;

//loops
#define REP(i,n) for(int i=0;i<(ll)(n);i++)
#define REPD(i,n) for(int i=(ll)(n)-1;i>=0;i--)
#define OneToN(i,n) for(int i=1;i<(ll)(n+1);i++)
#define ZeroToN(i,n) for(int i=0;i<(ll)(n+1);i++)
#define AToB(i,a,b) for(int i=a;i<(ll)(b+1);i++)
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)

//bitsearch
#define BITSEARCH(bit, n) for (int bit = 0; bit < (1<<n); ++bit)
#define isOne(bit, i) bit & (1<<i)

//arrays
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define add push_back


#define remove_unique(v) v.erase(unique(ALL(v)), v.end())

//pair
#define fir first
#define sec second

//types
#define ll long long
#define vec vector
#define cord2d pair<int,int>
//UNCOMMENT WHEN NEEDED
//#define int ll

//input
template <class T> T get(){ T s; cin >> s; return(s);}
#define gi get<int>()
#define gs get<string>()

template <class T> vector<T> getv(int n) { vec<T> v(n); REP(i, n) cin >> v[i]; return v; }
#define gim(n) getv<int>(n)
#define gsm(n) getv<string>(n)

//output
void print(int a){ cout << a << endl; }
void print(string a){ cout << a << endl; }
void print(char a){ cout << a << endl; }
void print(double a){ cout << a << endl; }
void print(double a, int dig){ cout << std::setprecision(dig) << a << endl; }

template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

template <class T = int>
void print(vec<T> v){ cout << v << endl; }

template <class T = int>
void print2dVec(vec<vec<T>> v2d){for(vec<T> v: v2d) {print(v);}}

void YesNo1(bool i = true){ return print(i?"Yes":"No"); }
void YESNO2(bool i = true){ return print(i?"YES":"NO"); }

//debug output
#define var_name(var) #var
template <class T> void debug(T &var, int nest = 0, string before = "") { cout << string("          ", nest) << before; print(var); }

//name replacement
#define y0 y0__
#define y1 y1__
#define j0 j0__
#define j1 j1__
#define next next__
#define prev prev__

//bool lambdas
#define lamb(exp) [](auto i){return exp;}
#define isEven [](int i){return i % 2 == 0;}
#define isOdd [](int i){return i % 2 != 0;}

//constants
const ll INF = 1e18;
const int MOD = 10000007;

//maths
int factorial(int k){ int sum = 1; for (int i = 1; i <= k; ++i) { sum *= i; } return sum; }

void Main() {
    //code here
    int n = gi;
    set<int> nums;
    REP(i,n) {
        nums.insert(gi);
    }

    int q = gi;
    vec<int> ques = gim(q);
    int res = 0;
    for (int que: ques) {
        if (nums.count(que) != 0) res ++;
    }
    print(res);
}

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    Main();
}


Measured memory_bytes: 7820
def maxHeapify(heap_tree, i)
  heap_size = heap_tree.size
  #i_p = (i - 1) / 2
  i_l = 2 * i + 1
  i_r = 2 * i + 2
  largest = i

  if i_l <= heap_size - 1
    case heap_tree[i_l] <=> heap_tree[i]
    when 1
      largest = i_l
    end
  end

  if i_r <= heap_size - 1
    case heap_tree[i_r] <=> heap_tree[largest]
    when 1
      largest = i_r
    end
  end

  if largest != i
    heap_tree[i], heap_tree[largest] = heap_tree[largest], heap_tree[i]
    maxHeapify(heap_tree, largest)
  end
end

def buildMaxHeap(heap_tree)
  ((heap_tree.size - 1) / 2).downto(0) do |i|
    maxHeapify(heap_tree, i)
  end
end

n = gets.chomp.to_i
heap = gets.chomp.split(" ").map(&:to_i)
buildMaxHeap(heap)
print " "
puts heap.join(" ")

Measured memory_bytes: 100048
n,k=map(float,input().split())
ans=0
l=[[k,0]]
k1=k
ll=0
while k1>1:
    k1/=2
    ll+=1
    l+=[[k1,ll]]
l.reverse()
ll+=1
l+=[[100001,ll]]
for i in range(ll):
    if l[i+1][0]<n:
        ans+=(int(l[i+1][0]-0.000001)-int(l[i][0]-0.000001))/n/2**l[i][1]
    else:
        ans+=(n-int(l[i][0]-0.000001))/n/2**l[i][1]
        break
print(ans)

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

#ifdef _DEBUG
#define debug(x) cerr << "line: " << __LINE__ << ", func: " << __func__ << " ->  " << #x << " = " << x << endl
#else
#define debug(x)
#endif

#define all(s) begin(s), end(s)
#define rall(s) rbegin(s), rend(s)
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = ((a)-1); i >= (b); i--)
#define pb push_back
#define sz(a) int((a).size())
#define put(a) ((cout) << (a) << (endl))
#define putf(a, n) ((cout) << (fixed) << (setprecision(n)) << (a) << (endl))
#define deg2rad(x) (((x)*PI) / (180.0))
#define rad2deg(x) (((x) * (180.0)) / PI)
#define fi first
#define se second

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;
using i_i = pair<int, int>;
using ll_ll = pair<ll, ll>;
using d_ll = pair<double, ll>;
using ll_d = pair<ll, double>;
using d_d = pair<double, double>;
template <class T> using vec = vector<T>;

static constexpr ll LL_INF = 1LL << 60;
static constexpr int I_INF = 1 << 28;
static constexpr double PI = static_cast<double>(3.14159265358979323846264338327950288);
static constexpr double EPS = numeric_limits<double>::epsilon();
static constexpr const char* YES = "Yes";
static constexpr const char* NO = "No";

static map<type_index, const char* const> scanType = {
    {typeid(int), "%d"}, {typeid(ll), "%lld"}, {typeid(double), "%lf"}, {typeid(char), "%c"}};

template <class T> static void scan(vector<T>& v);
[[maybe_unused]] static void scan(vector<string>& v, bool isWord = true);
template <class T> static inline bool chmax(T& a, T b);
template <class T> static inline bool chmin(T& a, T b);
template <class T> static inline T gcd(T a, T b);
template <class T> static inline T lcm(T a, T b);
template <class A, size_t N, class T> static void Fill(A (&arr)[N], const T& val);
template <class T> T mod(T a, T m);

int main(int argc, char* argv[]) {
  string s;
  cin >> s;

  rep(i, 0, 3) {
    if (s[i] == '7') {
      put(YES);
      return 0;
    }
  }
  put(NO);

  return 0;
}

template <class T> static void scan(vector<T>& v) {
  auto tFormat = scanType[typeid(T)];
  for (T& n : v) {
    scanf(tFormat, &n);
  }
}

static void scan(vector<string>& v, bool isWord) {
  if (isWord) {
    for (auto& n : v) {
      cin >> n;
    }
    return;
  }

  int i = 0, size = v.size();
  string s;
  getline(cin, s);

  if (s.size() != 0) {
    i++;
    v[0] = s;
  }

  for (; i < size; ++i) {
    getline(cin, v[i]);
  }
}

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

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

template <class T> inline T gcd(T a, T b) { return __gcd(a, b); }

template <class T> inline T lcm(T a, T b) {
  T c = min(a, b), d = max(a, b);
  return c * (d / gcd(c, d));
}

template <class A, size_t N, class T> void Fill(A (&arr)[N], const T& val) {
  std::fill((T*)arr, (T*)(arr + N), val);
}

template <class T> T mod(T a, T m) { return (a % m + m) % m; }


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



int main() {
    int n;
    cin >> n;
    
    vector<int> l(n);
    rep(i,n) {
        cin >> l[i];
    }
    
    int cnt = 0;
    for(int i = 0; i < n-2; i++) {
        for(int j = i+1; j < n-1; j++) {
            for(int k = j+1; k < n; k++) {
                if(l[i] != l[j] && l[j] != l[k] && l[k] != l[i]) {
                    vector<int> th = {l[i],l[j],l[k]};
                    sort(th.begin(),th.end());
                    if(th[2] < th[1] + th[0]) {
                        cnt++;
                    }
                }
            }
        }
    }
    
    cout << cnt << endl;
    
    
    return 0;
}




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

int main(){

  int a, b, c, d, p, x, y;

  cin >> a >> b >> c >> d >> p;

  x = a * p;
  
  if (p <= c){
    y = b;
  }
  else {
  y = b + (p - c) * d;
  }

  if (x < y){
    cout << x << endl;
  }
  else {
      cout << y << endl;
  }

}

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

using namespace std;

typedef pair<int,int> ii;

bool isPrime[10000002];
bool cards[10000002];

vector<vector<int>> adjlist;
vector<int> pairs;
vector<bool> visited;

bool dfs(int v) {
  if (visited[v]) return false;
  visited[v] = true;
  for (auto w : adjlist[v]) if (pairs[w] < 0 || dfs(pairs[w])) {
    pairs[w] = v; pairs[v] = w; return true;
  }
  return false;
}

int kuhn(int n) { // n = #Knoten links.
  pairs.assign(adjlist.size(), -1);
  int ans = 0;
  // Greedy Matching. Optionale Beschleunigung.
  for (int i = 0; i < n; i++) for (auto w : adjlist[i])
    if (pairs[w] == -1) { pairs[i] = w; pairs[w] = i; ans++; break; }
  for (int i = 0; i < n; i++) if (pairs[i] == -1) {
    visited.assign(n, false);
    ans += dfs(i);
  }
  return ans; // Größe des Matchings.
}

int main() {
  memset(isPrime, true, sizeof(isPrime));
  isPrime[1] = false;
  for (int i = 2; i <= 10000001; i++) {
    if (isPrime[i]) {
      for (int j = 2 * i; j <= 10000001; j += i) isPrime[j] = false;
    }
  }

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

  vector<int> flips;
  int odd = 0, even = 0;
  for (int i = 1; i <= 10000001; i++) {
    if (cards[i - 1] != cards[i]) {
      flips.push_back(i);
      if (i & 1) odd++;
      else even++;
    }
  }

  adjlist.resize(2 * flips.size());
  for (int i = 0; i < (int)flips.size(); i++) {
    if (flips[i] & 1) {
      for (int j = 0; j < (int)flips.size(); j++) {
        if (!(flips[j] & 1)) {
          int diff = abs(flips[i] - flips[j]);
          if (isPrime[diff]) {
            adjlist[i].push_back(flips.size() + j);
          }
        }
      }
    }
  }
  int m = kuhn(flips.size());
  int res = m + ((even - m) / 2 + (odd - m) / 2) * 2 + (even - m) % 2 * 3;
  printf("%d\n", res);
  return 0;
}


Measured memory_bytes: 17920
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define FORR(I,A,B) for(int I = ((B)-1); I >= (A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define REV(x) (reverse(x.begin(),x.end())) //reverse
int gcd(int a,int b){if(a<b)swap(a,b);if(a%b==0)return b;return gcd(b,a%b);}
int lcm(int a,int b){int c=gcd(a,b);return ((a/c)*(b/c)*c);}//saisyo kobaisu
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=1e18+7;
const ll MOD=1e9+7;
#define pri(a) cout << (a) << endl

struct Inversions{// tentosu
	// after init,u can get number of inversions num_inverstion(A)
	vector<ll> L,R;
	void initsize(ll n){//input size of A
		L.resize(n/2+2);
		R.resize(n/2+2);
	}
	ll merge(vector<ll> &A,ll n,ll left,ll mid,ll right){
		ll i,j,k;
		ll cnt = 0;
		ll n1 = mid - left;
		ll n2 = right - mid;
		for(i=0;i<n1;i++)L[i]=A[left+i];
		for(i=0;i<n2;i++)R[i]=A[mid+i];
		L[n1]=R[n2]=INT_MAX;//
		i=j=0;
		for(k=left;k<right;k++){
			if(L[i]<=R[j]){
				A[k]=L[i++];
			}else{
				A[k]=R[j++];
				cnt += n1-i;
			}
		}
		return cnt;
	}
	ll mergeSort(vector<ll> &A,ll n,ll left,ll right){
		ll mid;
		ll v1,v2,v3;
		if(left+1<right){
			mid = (left+right)/2;
			v1 = mergeSort(A,n,left,mid);
			v2 = mergeSort(A,n,mid,right);
			v3 = merge(A,n,left,mid,right);
			return v1+v2+v3;
		}else return 0;
	}
	ll num_inversion(vector<ll> A){
		vector<ll> B=A;//Aの順番を変えたくないなら
		return mergeSort(B,B.size(),0,B.size());
	}
};


int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	Inversions In;
	string s;
	cin >> s;
	ll b = 0;
	ll w = 0;
	ll ans = 0;
	FOR(i,0,s.size()){
		if(s[i]=='B')b++;
		else ans += b;
	}
	cout << ans << endl;
}

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


int main() {
long N,M;
cin>>N>>M;
vector<long> s(M);
vector<long> c(M);

if(N==1&&M==0){
  cout<<0<<endl;
  return 0;
}
for(int i=0;i<M;i++) cin>>s[i]>>c[i];

vector<long> a(N,-1);
for(int i=0;i<M;i++){
  if(a[s[i]-1]==-1) a[s[i]-1]=c[i];
  else{
    if(a[s[i]-1]!=c[i]){
      cout<<-1<<endl;
      return 0;
    }
  }
}

for(int i=0;i<3;i++){
  if(a[0]==-1) a[i]=1;
  else if(a[i]==-1) a[i]=0;
}
if(a[0]==0){
  if(N!=1){
  cout<<-1<<endl;
  return 0;
  }
}
for(int i=0;i<N;i++){
  cout<<a[i];
}
cout<<endl;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int N;
int A[3][101];
int main(){
	int cnt = 0;
	
	cin >> N;
	
	for(int i = 1;i < 3;i++){
		for(int j = 1;j < N+1;j++){
			cin >> A[i][j];
		}
	}
	
	for(int j = 2;j<N+1;j++)A[1][j] += A[1][j-1];
	
	A[2][1] += A[1][1]; 
	for(int j = 2;j < N+1;j++){
		if(A[1][j] > A[2][j-1])A[2][j] += A[1][j];
		else A[2][j] += A[2][j-1];
	}
	
	
	
	cout << A[2][N];
	
	return 0;
}

Measured memory_bytes: 256
'use strict'

function main(input) {
  input = input.split('\n').map(v => v.split(' ').map(v => ~~v))
  const n = input[0][0]

  //累積和
  let sums = [0]
  for (let i = 0; i < n; i++) {
    sums.push(input[1][i] + sums[i])
  }
  sums = sums.slice(1, sums.length)

  let tmpmin = Number.MAX_SAFE_INTEGER
  for (let i = 0; i < n - 1; i++) {
    let x = sums[i]
    let y = sums[n - 1] - sums[i]

    let diff = x >= y ? x - y : y - x
    // console.log(diff, x,y, sums)
    if (tmpmin > diff) {
      tmpmin = diff
    }
  }
  const ans = tmpmin

  console.log(ans)
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'))

Measured memory_bytes: 39448
#[allow(unused_imports)]
use std::cmp::*;
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n: i32 = read();
    let l: i32 = read();

    let mut ans = 0;
    let mut eat: i32 = 1000;
    for i in 0..n {
        let aji: i32 = l + i;
        if aji.abs() < eat.abs() {
            eat = aji;
        }
        ans += aji;
    }

    println!("{}", ans - eat);
}

Measured memory_bytes: 4352
#include <iostream>
#include <deque>

using namespace std;

string field[50]; 

struct Data{
	int x;
	int y;
	int score;
};

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

	int max = 0;

	for(int i=0;i<h;i++){
		cin >> field[i];
		for(int j=0;j<w;j++){
			if(field[i][j] == '.')
				max += 1;
		}
	}

	deque<Data> deq;
	Data p;
	p.x = 0;
	p.y = 0;
	p.score = 1;
	field[0][0] = '#';
	deq.push_back(p);

	int res = -1;

	while(!deq.empty()){
		Data q;
		p = deq.front();
		deq.pop_front();
		//cout << p.x <<" " << p.y << endl;

		if(p.x == w-1 && p.y == h-1){
			res = max - p.score;
			break;
		}

		q.score = p.score + 1;

		if(p.x > 0 && field[p.y][p.x-1] == '.'){
			field[p.y][p.x-1] = '#';
			q.x = p.x - 1;
			q.y = p.y;
			deq.push_back(q);
		}
		if(p.x < w-1 && field[p.y][p.x+1] == '.'){
			field[p.y][p.x+1] = '#';
			q.x = p.x + 1;
			q.y = p.y;
			deq.push_back(q);
		}
		if(p.y > 0 && field[p.y-1][p.x] == '.'){
			field[p.y-1][p.x] = '#';
			q.x = p.x;
			q.y = p.y - 1;
			deq.push_back(q);
		}
		if(p.y < h-1 && field[p.y+1][p.x] == '.'){
			field[p.y+1][p.x] = '#';
			q.x = p.x;
			q.y = p.y + 1;
			deq.push_back(q);
		}


	}

	cout << res << endl;

	return 0;

}


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

int main() {
  int n;
  string s;

  cin >> n >> s;
  stack<char> st;
  string ans = "";

  for (int i = 0; i < s.length(); ++i) {
    if (s[i] == ')') {
      if (st.empty() || st.top() == ')') {
        ans = ans + s[i];
        if (!st.empty()) {
          st.pop();
        } else {
          ans = '(' + ans;
        }
      } else {
        ans = ans + ')';
        st.pop();
      }
    } else {
      ans = ans + '(';
      st.push('(');
    }
  }

  for (int j = 0; j < st.size(); ++j) {
    ans = ans + ')';
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n, k;
  cin >> n >> k;
  
  int a = 0;
  int b;
  
  for (int i = 0; i < n; i++) {
    cin >> b;
    if (b < k - b)
      a += b * 2;
    
    else
      a += (k - b) * 2;
  }
  
  cout << a << endl;
}

Measured memory_bytes: 256
def main() :
	n = int(input().strip())
	num = list(int(j) for j in input().strip().split())
	l = num[0]
	s = 0
	for j in num :
		if j < l : s = s + (l - j)
		if j > l : l = j
	print(s)

if __name__ == '__main__' :
	main()

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

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

using ll = long long int;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
int main()
{
    int N, K;
    cin >> N >> K;
    string S;
    cin >> S;
    string S_red;
    S_red.push_back(S[0]);

    int n_change = 0;
    int n_happy = 0;
    rep(i, N - 1)
    {
        if (S[i + 1] != S[i])
        {
            S_red.push_back(S[i + 1]);
            n_change++;
        }
        else
        {
            n_happy++;
        }
    }

    int k = K;
    while (n_change >= 2 and k > 0)
    {
        n_change -= 2;
        k--;
        n_happy += 2;
    }
    if (k > 0)
    {
        n_happy += n_change;
    }

    cout << n_happy << endl;
}

Measured memory_bytes: 640
s=int(input())

a=[s]
k=0
ans=2
while k==0:
    if a[-1]%2==0:
        p=a[-1]//2
    else:
        p=3*a[-1]+1
    for i in a:
        if i==p:
            print(ans)
            k=1
            break
    a.append(p)
    ans+=1




Measured memory_bytes: 2940
#https://atcoder.jp/contests/abc117/tasks/abc117_b
S_list = [input() for i in range(2)]
N = map(int,S_list[0].split())    
L_list = list(map(int,S_list[1].split()))

L_max = max(L_list)
L_sum = sum(L_list) - L_max
if L_sum - L_max > 0:
    result ="Yes"
else:
    result ="No"
print(result)


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

int main(void) {
  string str;
  bool bo = false;
  int u, cou = 0;
  cin >> str;
  for (int i = 0; i < 26; i++) {
    bo = false;
    for (int j = 0; j < str.length(); j++) {

      if ((char)('a' + i) == str[j]) {
        bo = true;
      }
      if (bo == true)
        continue;
      if (j == str.length() - 1) {
        bo = false;
        cout << (char)('a' + i) << endl;
        return 0;
      }
    }
  }
  cout << "None" << endl;

  return 0;
}


Measured memory_bytes: 512
import java.util.*;
public class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
  int a = sc.nextInt();
  if(a%2 == 0){
    System.out.println((a/2)*(a/2));
  }
  else{
    System.out.println((a/2)*((a/2)+1));
  }
}}

Measured memory_bytes: 25300