akhauriyash/Code-Regression huggingface dataset:
#include <iostream>

using namespace std;
static const int MAX = 1000;


int main() {
    int A[MAX], n;
    cin >> n;
    for (int i = 0; i < n; i++) cin >> A[i];

    for (int i = 0; i < n; ++i) {
        int v = A[i];
        int j = i - 1;
        while(j >= 0 && A[j] > v) {
            A[j+1] = A[j];
            j--;
        }
        A[j+1] = v;

        for (int k = 0; k < n; ++k) {
            cout << A[k];
            if(k < n - 1) cout << " ";
        }
        cout << endl;
    }
}


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

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

    int A[n], B[n];
    for(int i = 0; i < n; i++){
        cin >> A[i] >> B[i];
    }
    sort(A, A + n);
    sort(B, B + n);
    
    int cnt = 0, damage = 0, idx = n - 1;
    bool f = true;
    while(true){
        if(f and idx >= 0){
            damage += B[idx];
            if(idx >= 1 and B[idx - 1] <= A[n - 1]) f = false;
            else idx--;
        }else damage += A[n - 1];
        cnt++;
        if(h <= damage) break;
    }
    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <cfenv>
#include <algorithm>
#include <cmath>
#include <vector>
#include <map>
#include <iomanip>
#include <limits>

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

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

    vector<string> s(n,"");
    vector<int> t(n,0);

    rep(i,n){
        cin >> s[i] >> t[i];
    }

    string x;
    cin >> x;

    int index_num = 50;
    int sum = 0;

    for (int i = 0; i<n; i++){
        if (s[i] == x)
            index_num = i;
    }

    for (int i=index_num+1; i<n; i++) {
        sum += t[i];
    }

    cout << sum << endl;
}

Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
int main() {
    int A,B,K;
    cin >> A >> B >> K;
 int C = 101;
 int D = 0;
    while(D<K){
        if ( A % C == 0 && B % C == 0){
             D = D + 1;
        }
        C = C - 1;
    }
    cout << C + 1 << endl;
}


Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))
a.sort(reverse=True)

size = sum(a)
capa = size*2
count = 1

for i,x in enumerate(a[1:]):
    size -= a[i]
    capa = size * 2
    if a[i] <= capa:
        count += 1
    else:
        break

print(count)

Measured memory_bytes: 86044
#include <iostream>
#include <iomanip>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>
#include <numeric>
#include <set>

using namespace std;
struct aaa{aaa(){cin.tie(nullptr); ios::sync_with_stdio(false); cout<<fixed<<setprecision(20);};}aaa;
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;}
#define debug(v) {cerr<<"\033[1;36m[debug]\033[m "<<#v<<" : "<<v<<endl;}

using int64 = long long;

int main() {
    string s;
    cin >> s;
    int n = s.size();
    vector<int> ss(n+1,0);
    reverse(s.begin(), s.end());

    int d = 1;
    for (int i=0; i<n; i++) {
        ss[i+1] += ss[i] + (s[i]-'0') * d;
        ss[i+1] %= 2019;
        d *= 10; d %= 2019;
    }

    int ans = 0;
    map<int,int> cnt;
    for (int i=0; i<=n; i++) {
        ans += cnt[ss[i]]++;
    }

    cout << ans << endl;
}

Measured memory_bytes: 4052
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
const ll mod = (int) 1e9 + 7;
ll n;
double a[3005];
double dp[3005][3005];
double solve(ll coins, ll heads){
    if(heads == 0){
        return 1;
    }
    if(coins == 0){
        return 0;
    }
    if(dp[coins][heads] > -0.9){
        return dp[coins][heads];
    }
    return dp[coins][heads] = a[coins] * solve(coins-1, heads-1) + (1 - a[coins]) * solve(coins-1, heads);
}
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a[i];
    }
    memset(dp,-1,sizeof(dp));
    cout<<fixed<<setprecision(10)<<solve(n,((n+1)/2))<<"\n";
}
    
    


Measured memory_bytes: 70912
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mt make_tuple
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef tuple<int,int,int> tp;
typedef vector<tp> vt;
typedef vector<vd> vvd;
typedef pair<int,pii> pip;
typedef vector<pip>vip;
const double PI=acos(-1);
const double EPS=1e-7;
const int inf=1e8;
const ll INF=1e16;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
ll n;
vi in;
ll f(int a){
	ll ans=0;
	ll sum=0;//=in[0];
	if(a){
		ans=max(1-in[0],0ll);
		sum=max(1-in[0],0ll)+in[0];
	}else{
		ans=max(in[0]+1,0ll);
		sum=in[0]-max(in[0]+1,0ll);
	}
	loop(i,1,n){
		if(sum<0){
			ll t=-sum+1;
			ans+=max(t-in[i],0ll);
			sum+=max(t-in[i],0ll)+in[i];
		}else{
			ll t=-sum-1;
			ans+=max(in[i]-t,0ll);
			sum+=in[i]-max(in[i]-t,0ll);
		}
//		cout<<ans<<" "<<sum<<endl;
	}
	return ans;
}
int main(){
	cin>>n;
	in=vi(n);
	rep(i,n)cin>>in[i];
	ll out=INF;
	out=min(out,f(0));
	out=min(out,f(1));
	cout<<out<<endl;
}





Measured memory_bytes: 1024
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

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

const int MOD=1000000007;

int main(){
  int h,w,k;
  cin>>h>>w>>k;
  
  ll dp[110][8];
  rep(i,110){
    rep(j,8) dp[i][j]=0;
  }
  dp[0][0]=1;

  vector<int> C(7);
  C[0]=1;
  C[1]=2;
  C[2]=3;
  C[3]=5;
  C[4]=8;
  C[5]=13;
  C[6]=21;
  
  for(int i=1;i<=h;i++){
    for(int j=0;j<w;j++){
      if(j==0){
        dp[i][j]=((dp[i-1][j]*C[max(0,j-1)]%MOD)*C[max(0,w-j-2)]%MOD+
        (dp[i-1][j+1]*C[max(0,j-1)]%MOD)*C[max(0,w-j-3)]%MOD)%MOD;
      }
      else if(j==w-1){
        dp[i][j]=((dp[i-1][j-1]*C[max(0,j-2)]%MOD)*C[max(0,w-j-2)]%MOD+
        (dp[i-1][j]*C[max(0,j-1)]%MOD)*C[max(0,w-j-2)]%MOD)%MOD;
      }
      else{
        dp[i][j]=((dp[i-1][j-1]*C[max(0,j-2)]%MOD)*C[max(0,w-j-2)]%MOD+
        (dp[i-1][j]*C[max(0,j-1)]%MOD)*C[max(0,w-j-2)]%MOD+
        (dp[i-1][j+1]*C[max(0,j-1)]%MOD)*C[max(0,w-j-3)]%MOD)%MOD;
      }
    }
  }

  cout<<dp[h][k-1]<<endl;
  
  return 0;
}

Measured memory_bytes: 3556
inf = 10**15
mod = 10**9+7
n,m,x,y = map(int, input().split())
xlist = list(map(int, input().split()))
ylist = list(map(int, input().split()))
xmax = max(xlist)
ymin = min(ylist)
if xmax < ymin and xmax < y and ymin > x:
    print('No War')
else:
    print('War')

Measured memory_bytes: 38256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for(int i = 0; i < n; i++)
bool m[3000][3000];
pair<ll,ll> cost[3000][3000];

int main(void){
    ll h, w;
    cin >> h >> w;
    ll ma = 0;

    for(int i = 3; i < h + 3; i++){
        for(int j = 3; j < w + 3; j++){
            char tmp;
            cin >> tmp;

            if(tmp == '#'){
                m[i][j] = false;
            }else{
                m[i][j] = true;
            }
        }
    }

    for(int i = 3; i < h + 3; i++){
        for(int j = 3; j < w + 3; j++){
            if(m[i][j]){
                if(m[i-1][j]){
                    cost[i][j].first = cost[i-1][j].first;
                }else{
                    for(int k = i; k < h + 3; k++){
                        if(m[k][j])
                            cost[i][j].first++;
                        else
                            break;
                    }
                }
                if(m[i][j-1]){
                    cost[i][j].second = cost[i][j-1].second;
                }else{
                    for(int k = j; k < w + 3; k++){
                        if(m[i][k])
                            cost[i][j].second++;
                        else
                            break;
                    }
                }
                ma = max(ma, cost[i][j].first + cost[i][j].second - 1);
            }
        }
    }

    cout << ma << endl;
    return 0;
}


Measured memory_bytes: 102016
#include <stdio.h>
#include <string>
#include <iostream>
using namespace std;
int main(void)
{
	string ans[1000];
	string str,left, right;
	int m, h, Bool, cou = 0;
	while(1){
		cin >> str;
		if (str == "-") break;
		cin >> m;
		for (int i = 0; i < m;i++){
			cin >> h;
			left = str.substr(0, h);right = str.substr(h, str.size()-h);
			str = right + left;
		}
		ans[cou] = str;
		cou++;
	}
	for (int i = 0; i < cou; i++) {
		cout << ans[i] << endl;
	}
	
}

Measured memory_bytes: 1224
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int,int>;
#define rep(i,n) for(int i=0; i<n; i++)
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) //sortしてから使う
#define INF 2147483647
#define LLINF 9223372036854775807LL

int main(){
  int n; cin >> n;
  int k = sqrt(n)/1;
  //cout << "k:" << k << endl;
  int ans = 0;
  for (int a=1; a<=k; a++){
    ans += ((n/a) - a);
  }
  int count = 0;
  for (int i=1; i*i<=n; i++){ //約数をひく
    if (n%i == 0){
      if (i*i != n) count += 2;
      else count ++;
    }
  }
  //cout << "count:" << count << endl;
  ans *= 2;
  ans += k;
  ans -= count;
  cout << ans << endl;
}

Measured memory_bytes: 3596
#include<iostream>
#include<algorithm>
#include<cmath>
#define ll long long 
using namespace std;
int n,m;
ll x[3000],y[3000],z[3000];
ll ts[3000];

int s[3];
ll ans;
bool cmp(ll a,ll b)
{
    return a>b;
}
ll check()
{
    ll tans;
    ll t=0;
    for (int i=1; i<=n; ++i)
    {
        tans=0;
        if (s[0] == 0)
        {
            tans+=(x[i]);
        }else
        {
            tans-=(x[i]); 
        }

        if (s[1] == 0)
        {
            tans+=y[i];
        }else
        {
            tans-=y[i];
        }

        if (s[2] == 0)
        {
            tans+=z[i];
        }else
        {
            tans-=z[i];
        }
        ts[t++]=tans;
    }
    sort(ts,ts+t,cmp);
    tans=0;
    for (int i=0; i<m; ++i)
    {
        tans+=ts[i];
    }
    return tans;
}

int main()
{
    scanf("%d%d",&n,&m);
    for (int i=1; i<=n; ++i)
        scanf("%lld%lld%lld",&x[i],&y[i],&z[i]);
    for (int i=0; i<=1; ++i)
        for (int j=0; j<=1; ++j)
            for (int k=0; k<=1; ++k)
            {
                s[0]=i;
                s[1]=j;
                s[2]=k;
                ans=max(ans,check());
            }
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 256
// Try yahoo procon 2019 qual
// author: Leonardone @ NEETSDKASU 

fn main() {
	let mut stdin = String::new();
    std::io::Read::read_to_string(
    	&mut std::io::stdin(),
        &mut stdin).unwrap();
	let mut stdin = stdin.split_whitespace();
    let mut get = || stdin.next().unwrap();
    macro_rules! get {
    	($t:ty) => (get().parse::<$t>().unwrap());
        () => (get!(i64));
    }
    
    let mut r = vec![vec![false; 4]; 4]; 
    
    for _ in 0..3 {
    	let a = get!(usize) - 1;
        let b = get!(usize) - 1;
        r[a][b] = true;
        r[b][a] = true;
    }
    
	for i in 0..4 {
    	for j in 0..4 {
        	if i == j { continue; }
        	for k in 0..4 {
            	if i == k || j == k {
                	continue;
                }
            	for l in 0..4 {
                	if i == l || j == l || k == l {
                    	continue;
                    }
                	if r[i][j] && r[j][k] && r[k][l] {
                    	println!("YES");
                        return;
                    }
                }
            }
        }
    }
    println!("NO");
}

Measured memory_bytes: 4352
#include <algorithm>
#include <cassert>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

#include <limits.h>

using namespace std;

typedef long long ll;

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

vector<vector<int>> sushis;
vector<vector<int>> as;

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

    sushis.resize(N);
    for (int i = 0; i < N; i++) {
        int t, d;
        cin >> t >> d;
        t--;
        sushis[t].push_back(d);
    }

    priority_queue<int> q;
    vector<int> bs;

    for (int i = 0; i < N; i++) {
        sort(sushis[i].begin(), sushis[i].end());
        reverse(sushis[i].begin(), sushis[i].end());

        if ((int) sushis[i].size() > 0) {
            bs.push_back(sushis[i][0]);
        }

        for (int j = 1; j < (int) sushis[i].size(); j++) {
            q.push(sushis[i][j]);
        }
    }

    sort(bs.begin(), bs.end());
    reverse(bs.begin(), bs.end());

    ll delicious = 0;
    ll kind = 0;
    ll cand = 0;
    for (int i = 0; i < min((int) bs.size(), K); i++) {
        delicious += bs[i];
        kind++;
    }

    for (int i = kind; i < (int) bs.size(); i++) {
        q.push(bs[i]);
    }

    for (int i = kind; i < K; i++) {
        auto v = q.top();
        q.pop();
        delicious += v;
    }

    cand = delicious + kind * kind;
    // printf("delicious: %lld, kind: %lld, cand: %lld\n", delicious, kind, cand);

    while (kind > 0) {
        auto remove = bs[kind - 1];
        delicious -= remove;
        q.push(remove);
        auto v = q.top();
        q.pop();
        delicious += v;

        kind--;
        chmax(cand, delicious + kind * kind);
        // printf("delicious: %lld, kind: %lld, cand: %lld\n", delicious, kind, cand);
    }

    cout << cand << endl;

    return 0;
}


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

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pair<int, int> > vpii;
typedef vector<pair<ll, ll> > vpll;

#define pll pair<ll,ll>
#define pii pair<int, int>
#define all(x) x.begin(), x.end()
#define F first
#define S second
#define rep(i,n) for (int i = 0; i < n; ++i) 
#define REP(i,k,n) for (int i = k; i <= n; ++i) 
#define REPR(i,k,n) for (int i = k; i >= n; --i)
#define pb push_back
#define watch(x) cout << (#x) << " is " << (x) << endl
#define sz(a) int((a).size())
#define endl '\n' // remove for interactive

const int INF = 1e9;
const ll mod = 1e9 + 7;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}

const int N = 3e5 + 10;

void solve()
{
    vi rows(N), cols(N);
    map<pair<int, int>, int> mp;
    int n, m, t; cin>>n>>m>>t;
    rep(i, t)
    {
        int x, y; cin>>x>>y;
        rows[x]++; cols[y]++;
        mp[{x, y}] = 1;
    }
    int mxr = 0, mxc = 0;
    int indr, indc;
    REP(i, 1, 3e5) {
        if(rows[i] > mxr) {
            mxr = rows[i];
            indr = i;
        }
        else if(rows[i] == mxr && !mp[{i, indc}]) {
            mxr = rows[i];
            indr = i;
        }
        if(cols[i] > mxc) {
            mxc = cols[i];
            indc = i;
        }
        else if(cols[i] == mxc && !mp[{indr, i}]) {
            mxc = cols[i];
            indc = i;
        }
        
        
    }
    // watch(cols[2]);
    // watch(indr);
    // watch(indc);
    cout<<mxr+mxc - (mp[{indr, indc}])<<endl;
}

int main()
{
    // clock_t start, end;
    // start = clock();
    ios_base::sync_with_stdio(0); //cant use scanf, printf
    cin.tie(0);cout.tie(0); // no longer auto flush cout before each cin, remove for interactive
    int t = 1;
    // cin>>t;
    REP(i, 1, t)
    {
        solve();
        
    }
    // end = clock();
    // double time_taken = double(end - start) / double(CLOCKS_PER_SEC); 
    // watch(time_taken);
    ll x = INF; x++;
    return 0;
    
}



/*before sub
TEST: 0(1 by 1 too), 1, equal, -ve, bounds(random and ez)
ERR/WA: loop vars, out of bounds, endl, finish taking inputs, large doubles, larger INF, corr mod, t, early/late mod
RE: double dec, integer overflow(ll or 1LL mult)
*/





Measured memory_bytes: 61816
today = input()

if today == "SUN":
    print("7")
elif today == "MON":
    print("6")
elif today == "TUE":
    print("5")
elif today == "WED":
    print("4")
elif today == "THU":
    print("3")
elif today == "FRI":
    print("2")
else:
   print("1")

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

void solve() {
  vector<int> a(5);
  rep(i, 5) cin >> a[i];
  rep(i, 5) {
    if (a[i] == 0) {
      cout << i+1 << endl;
      return;
    }
  }
}
void solve(bool tests) {
  int t;
  cin >> t;
  while (t--) solve();
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  solve();
}

Measured memory_bytes: 3604
from bisect import bisect_left
n = int(input())
a = list(map(int, input().split()))
q = int(input())
for i in range(q):
  k = int(input())
  t = bisect_left(a, k)
  if t>=n or a[t]!=k:
    print(0)
  else:
    print(1)


Measured memory_bytes: 17212
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
using namespace std;

#include <math.h>
#include <iomanip>
#include <vector>
#include <queue>
#include <climits>
using Graph = vector<vector<int>>;
const double PI = 3.14159265358979323846;



long long modpow(long long a, long long n, long long mod) {
	long long res = 1;
	while (n > 0) {
		if (n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}


//約数をベクトル形式で返す
vector<int> vect_yakusuu(int n) {
	vector<int> ret;
	for (int i = 1; i*i <= n; i++) {
		if (n%i == 0) {
			ret.push_back(i);
			if (i*i != n) ret.push_back(n / i);
		}
	}
	sort(begin(ret), end(ret));
	return ret;
}



int main() {

	long long ans;
	int N;
	int a[200020];

	cin >> N;

	for (int i = 0; i < N; i++) {
		cin >> a[i];
	}
	
	int sum=0;

	for (int i = 0; i < N; i++) {
		sum = sum ^ a[i];
	}

	for (int i = 0; i < N; i++) {
		ans = sum^a[i];
		cout << ans << " ";
	}

	cin >> ans;

	return 0;


}

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

int main() {
	
	int n; cin >> n;
	map<string, int> mp;
	for (int i = 0; i < n; i++) {
		string s; cin >> s;
		mp[s]++;
	}
	int m; cin >> m;
	for (int i = 0; i < m; i++) {
		string t; cin >> t;
		mp[t]--;
	}
	int ans = 0;
	for (auto u : mp) {
		ans = max(ans, u.second);
	}
	cout << max(0, ans) << endl;
    return 0;
}

Measured memory_bytes: 3644
#include <stdio.h>

int main(void)
{
	int a, b, c, sum;
	
	while (scanf("%d%d", &a, &b) != EOF){
		sum = a + b;
		for (c = 0; sum != 0; c++){
			sum /= 10;
		}
		
		printf("%d\n", c);
	}
	
	return (0);
}

Measured memory_bytes: 600
# /////[UnionFind準備]//////////////////////////////////////////////////////
class UnionFind(): # 0インデックス
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        '''
        xとyは-=1して使う
        '''
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

# /////[main]]//////////////////////////////////////////////////////
if __name__ == "__main__":
    N, M = map(int, input().split())
    bridges = [tuple(map(int, input().split())) for _ in range(M)]

    answer_list = []
    total = N * (N-1) // 2
    answer_list.append(total)
    # すべて崩落したところから逆に調べていく
    union_find = UnionFind(N)
    for i in range(M-1, 0, -1):
        A, B = bridges[i]
        A -= 1
        B -= 1
        if not union_find.same(A, B):
            total -= union_find.size(A) * union_find.size(B)
            union_find.union(A, B)

        answer_list.append(total)

    len_answer = len(answer_list)
    for i in range(len_answer-1, -1, -1):
        print(answer_list[i])




Measured memory_bytes: 28472
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

#include <iostream>
#include "bits/stdc++.h"

using namespace std;

typedef unsigned long long ll;
typedef int                     integer;
#define int                     long long
#define ii                      pair<int,int>
#define vii                     vector<pair<int,int>>
#define vi                      vector<int>
#define vvi                     vector<vector<int>>
#define f(a,b,c)                for(int a=(b);a<(c);a++)
#define s(x)                    in>>x
#define s2(x,y)                 in>>x>>y
#define s3(x,y,z)               in>>x>>y>>z
#define s4(x,y,z,w)             in>>x>>y>>z>>w
#define p(x)                    out<<(x)<<endl
#define p2(x,y)                 out<<(x)<<" "<<(y)<<endl
#define pl(x)                   out<<(x)
#define p2l(x,y)                out<<(x)<<" "<<(y)
#define p1d(a,n)                for(int ix=0;ix<(n);ix++) out<<a[ix]<<" "; out<<endl
#define p2d(a,n,m)              for(int ix=0;ix<(n);ix++){ for(int jx=0;jx<(m);jx++) out<<a[ix][jx]<<" "; out<<endl;}
#define range(v)                v.begin(),v.end()
#define w(x)                    while(x--)
#define rst(x)                  memset(x, -1, sizeof(x))

void ssolve(std::istream& in, std::ostream& out){
    int d,t,s;
    s3(d,t,s);

    out<< ( s*t >= d ? "Yes": "No")<< endl;

}

class ADontBeLate {
public:
	void solve(std::istream& in, std::ostream& out) {
        ios_base::sync_with_stdio(false);
        in.tie(0);out.tie(0);
        int t;
        int READ = 0;
        if(READ) s(t);
        else t = 1;
        while(t--){
            ssolve(in, out);
        }
	}
};


integer main() {
	ADontBeLate solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
}


Measured memory_bytes: 3620
# -*- coding: utf-8 -*-

import sys

I = list(input())

A = 0
L = []
LH = []
k = 0
while len(I) > 0:
    i = I.pop()

    if i == '/':
        d = 1
        a = 0.5
        tmp_I = ['/']

        # print("[{}] d: {}".format(i, d))

        while len(I) > 0:
            i = I.pop()

            tmp_I.append(i)

            if i == '/':
                d += 1
                a += 0.5 + d - 1
            elif i == '\\':
                a += 0.5 + d - 1
                d -= 1
                if d == 0:
                    A += a
                    L.append(a)
                    k += 1
                    tmp_I = []
                    break
            elif i == '_':
                a += d

            # print("[{}] d: {}".format(i, d))

        # print("{}".format(tmp_I))

        if len(tmp_I) > 0:
            d = a = 0
            while len(tmp_I) > 0:
                i = tmp_I.pop()
                # print("{}".format(i))
                if i == '\\':
                    d += 1
                    a += 0.5 + d - 1
                elif i == '_':
                    a += d
                elif i == '/' and d > 0:
                    a += 0.5 + d - 1
                    d -= 1

                    if d == 0:
                        # print("Add tmp: {} ({})".format(a, tmp_I))
                        A += a
                        LH.append(a)
                        k += 1
                        a = 0

print(int(A))
sys.stdout.write(str(k))
for l in LH:
    sys.stdout.write(" {}".format(int(l)))
while len(L) > 0:
    sys.stdout.write(" {}".format(int(L.pop())))
sys.stdout.write('\n')

Measured memory_bytes: 7680
#include <iostream>
#include <cstring>
#include <utility>
#include <vector>
#include <cmath>
#include <algorithm>

using namespace std;


int N, W;
vector<int> w;
vector<int> v;


long long memo[101][100001];


long long get_max_value(int i, int maxW) {
    if (i == N) {
        return 0;
    } else {
        long long a = v[i] + get_max_value(i+1, maxW - w[i]);
        long long b = get_max_value(i+1, maxW);

        if (w[i] > maxW) {
            return b;
        } else {
            return max(a, b);
        }
    }
}



long long get_max_value_using_memo_cache(int i, int maxW) {
    if (memo[i][maxW] != -1) {
        return memo[i][maxW];
    }

    if (i == N) {
        return 0;
    } else {
        long long ans;
        long long b = get_max_value_using_memo_cache(i+1, maxW);

        if (w[i] > maxW) {
            ans = b;
        } else {
            long long a = v[i] + get_max_value_using_memo_cache(i+1, maxW - w[i]);
            ans = max(a, b);
        }

        memo[i][maxW] = ans;
        return ans;
    }
}



int main() {
    cin >> N >> W;
    w.resize(N);
    v.resize(N);
    for (int i = 0; i < N; i++) {
        cin >> w[i] >> v[i];
    }

    // recursive
    // long long ans = get_max_value(0, W);


    // memo
    memset(memo, -1, sizeof(memo));
    long long ans = get_max_value_using_memo_cache(0, W);
    
   
    // DP

    cout << ans;
    return 0;
}




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

// 隣接リストで使う辺を表す型
struct Edge {
  int to, cost; // 辺の接続先頂点、辺の重み
  Edge(int to, int cost) : to(to), cost(cost) {}  // コンストラクタ
};
typedef long long ll;
const ll INF = 1e18;
typedef vector<vector<Edge> > AdjList;  // 隣接リストの型
AdjList graph; // グラフの辺を格納した構造体
               // graph[v][i]は頂点vから出るi番目の辺Edge
vector<ll> dist; // 最短距離
vector<bool> nega; // 負の閉路があるかどうか

// 戻り値がtrueなら負の閉路を含む
void bellman_ford(int n, int s) { // nは頂点数、sは開始頂点
  dist = vector<ll>(n, INF);
  nega = vector<bool>(n, false);
  dist[s] = 0; // 開始点の距離は0
  for (int i = 0; i < n; i++) {
    for (int v = 0; v < n; v++) {
      for (int k = 0; k < graph[v].size(); k++) {
        if (dist[v] == INF) continue;
        Edge e = graph[v][k];
        if (dist[e.to] > dist[v] + e.cost) {
          //if (i == n - 1) return true; // n回目にも更新があるなら負の閉路が存在
          dist[e.to] = dist[v] + e.cost;
        }
      }
    }
  }
  for (int i = 0; i < n; i++) {
    for (int v = 0; v < n; v++) {
      for (int k = 0; k < graph[v].size(); k++) {
        if (dist[v] == INF) continue;
        Edge e = graph[v][k];
        if (dist[e.to] > dist[v] + e.cost) {
          dist[e.to] = dist[v] + e.cost;
          nega[e.to] = true;
        }
        if (nega[v]) nega[e.to] = true;
      }
    }
  }
  //return false;
}

int main() {
  int n, m;
  cin >> n >> m;
  graph = AdjList(n);
  for (int i = 0; i < m; i++) {
    int from, to, cost;
    cin >> from >> to >> cost;
    from--; to--;
    graph[from].push_back(Edge(to, -cost));
  }
  // ベルマンフォード法
  // if (bellman_ford(n, 0)) {
  //   cout << "inf" << endl;
  //   return 0;
  // }
  bellman_ford(n, 0);
  // 解答
  if (nega[n-1]) {
    cout << "inf" << endl;
  } else {
    cout << -dist[n-1] << endl;
  }
  return 0;
}


Measured memory_bytes: 256
H, W, D = gets.split(' ').map(&:to_i)
grid = Array.new(H * W + 1)
1.upto(H) do |i|
  line = gets.split(' ').map(&:to_i)
  W.times do |j|
    grid[line[j]] = [i, j + 1]
  end
end

dis = [0] * (H * W + 1)
(D + 1).upto(H * W) do |i|
  dis[i] = dis[i - D] + (grid[i][0] - grid[i - D][0]).abs + 
  (grid[i][1] - grid[i - D][1]).abs
end

Q = gets.to_i
Q.times do
  l, r = gets.split(' ').map(&:to_i)
  puts dis[r] - dis[l]
end

Measured memory_bytes: 12540
//SILENT KILLER
              //HARD WORK BEATS TALENT WHEN TALENT DOESNOT WORK HARD
#include<bits/stdc++.h>
//typedef long long ll;
using namespace std;
int main()
{
  int i,t;
  cin>>t;
   for (i = 0; i < t; i++) {
    cout<<"ACL";
}

}



















Measured memory_bytes: 3632
#!/usr/bin/env python3

S = list(input())
S.reverse()

for i in range(1, len(S)):
    s = S[i:]
    if len(s) % 2 == 1: continue
    x = len(s) // 2
    if s[:x] == s[x:]:
        print(len(s))
        exit()


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
int n, k;

struct data {
	int a[100001];

	void init() {
		for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
	}
}f[7], A, ans;

data operator + (const data &a, const data &b) {
	data ans;
	for (int i = 1; i <= n; ++i)
		ans.a[i] = a.a[b.a[i]];
	return ans;
}

data inv(const data &a) {
	data ans;
	for (int i = 1; i <= n; ++i)
		ans.a[a.a[i]] = i;
	return ans;
}

data fpow(data x, int y) {
	data ans;
	for (int i = 1; i <= n; ++i) ans.a[i] = i;
	while (y) {
		if (y & 1) ans = ans + x;
		y >>= 1; x = x + x;
	}
	return ans;
}

int main() {
	scanf("%d%d", &n, &k);		
	f[1].init(); f[2].init();
	for (int i = 3; i <= 6; ++i)
		f[i] = f[i - 1] + inv(f[i - 2]);
	int mod = k % 6 ? k % 6 : 6;
	A = f[2] + inv(f[1]) + inv(f[2]) + f[1];
	ans = fpow(A, (k - mod) / 6);
	ans = ans + f[mod];
	ans = ans + fpow(inv(A), (k - mod) / 6);
	for (int i = 1; i <= n; ++i)
		printf("%d ", ans.a[i]);
}


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

int main()
{
    int n, a;
    cin >> n >> a;
    vector<int> x(n + 1);
    for (auto i = 1; i <= n; i++)
    {
        int xi;
        cin >> xi;
        x[i] = xi;
    }

    int X = max(a, *max_element(x.begin(), x.end()));
    vector<vector<vector<long long>>> dp(n + 1, vector<vector<long long>>(n + 1, vector<long long>(n * X + 1)));

    for (auto j = 0; j < n + 1; j++)
    {
        for (auto k = 0; k < n + 1; k++)
        {
            for (auto s = 0; s < n * X + 1; s++)
            {
                if (j == 0 && k == 0 && s == 0)
                {
                    dp[j][k][s] = 1;
                }
                else if (j >= 1 && x[j] > s)
                {
                    dp[j][k][s] = dp[j - 1][k][s];
                }
                else if (j >= 1 && k >= 1 && x[j] <= s)
                {
                    dp[j][k][s] = dp[j - 1][k][s] + dp[j - 1][k - 1][s - x[j]];
                }
                else
                {
                    dp[j][k][s] = 0;
                }
            }
        }
    }

    long long ans = 0;
    for (auto i = 1; i < n + 1; i++)
    {
        ans += dp[n][i][a * i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 52224
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		int counter = 0;
		String DNA, RNA;
		try (Scanner sc = new Scanner(System.in)) {
			RNA = sc.nextLine();
			while(true) {
				DNA = sc.next();
				if(DNA.equals("END_OF_TEXT")) {
					break;
				}
				DNA = DNA.toLowerCase();
				if(DNA.equals(RNA)) {
					counter++;
				}
			}
		}
		System.out.println(counter);
	}
}



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

int main() {
	string n;
	cin >> n;
	for (int i = 0; i < 3; i++) {
		if (n[i] == '9') {
			n.replace(i, 1, "1");
		} else {
			n.replace(i, 1, "9");
		}
	}
	cout << stoi(n) << endl;
}


Measured memory_bytes: 256
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();

		double loan = 100_000.0;
//		BigDecimal bdl = new BigDecimal(loan);
//		BigDecimal interest = new BigDecimal(1.05);
//		for (int i = 0; i < n; i++) {
////			loan = loan * 1.05;
//			bdl = bdl.multiply(interest);
//			bdl = bdl.setScale(-3, RoundingMode.UP);
//		}
//		System.out.println(bdl.intValue());
		for (int i = 0; i < n; i++) {
			loan = loan * 1.05;
			BigDecimal bdl = new BigDecimal(loan);
			bdl = bdl.setScale(-3, RoundingMode.UP);
			loan = bdl.doubleValue();
		}
		System.out.println( (int)loan );
	}

}

Measured memory_bytes: 26040
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const int MOD = 1e9 + 7;

int main(){
	int n,x;
	cin >> n >> x;
	int l[n];
	REP(i,n) cin >> l[i];
	int num = 0,cnt = 0;
	REP(i,n){
		if(num <= x) cnt++;
		num += l[i];
	}
	if(num <= x) cnt++;
	cout << cnt << endl;
}

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

#define SORT(c) sort((c).begin(), (c).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
#define ANS(ans) cout << (ans) << endl;
#define UNIQUE(v) (v).erase(unique((v).begin(), (v).end()), (v).end());
typedef vector<int> VI;
typedef pair<int, int> P;

// repetition
//------------------------------------------
#define FOR(i, a, b) for (int i = (a); i <= (b); ++i)
#define REP(i, n) for (long long i = 0; i < (n); ++i)

int main() {
  int n;
  cin >> n;
  VI v(n);
  REP(i, n) {
    cin >> v[i];
  }

  int m = v[0];
  ll ans = 0;
  REP(i, n) {
    if (v[i] < m) {
      ans += m - v[i];
    } else if (v[i] > m) {
      m = v[i];
    }
  }

  ANS(ans);
  return 0;
}


Measured memory_bytes: 4012
#include<bits/stdc++.h>
#include<boost/variant.hpp>
using namespace std;
typedef long long ll;
typedef vector<boost::variant<bool, ll, int, string, double, char*, const char*>> any;
template<typename T> inline void pr(const vector<T> &xs){
	for(int i=0; i<xs.size()-1; i++) cout<<xs[i]<<" ";
	(xs.empty()?cout:(cout<<xs[xs.size()-1]))<<endl;
}
#ifdef DEBUG
#define debug(...) pr(any{__VA_ARGS__})
#define debugv(x) pr((x))
#else
#define debug(...)
#define debugv(x)
#endif

int dfs(int u, vector<vector<int>> &ch){
	vector<int> cnt;

	for(int v: ch[u]){
		cnt.push_back(dfs(v, ch));
	}

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

	for(int i=0; i<cnt.size(); i++){
		cnt[i] += cnt.size()-i;
	}

	int m = 0;
	for(int i=0; i<cnt.size(); i++) m = max(m, cnt[i]);
	debug(u+1, m);
	return m;
}


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

	vector<vector<int>> ch(N);
	for(int i=0; i<N-1; i++){
		ch[A[i]].push_back(i+1);
	}

	cout << dfs(0, ch) << endl;

	return 0;
}


Measured memory_bytes: 13952
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstring>
#include <cmath>
#define ll long long
using namespace std;
int main()
{
  ios_base::sync_with_stdio(0);
  int a,b,c;
  cin >> a >> b >> c;
  if(c>=a && c<=b)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}


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

using namespace std;

const int mod = 1e9 + 7;

long long add(long long a, long long b) {
    long long res = a + b;
    if (res >= mod) res -= mod;
    return res;
}

long long sub(long long a, long long b) {
    long long res = a - b + mod;
    if (res >= mod) res -= mod;
    return res;
}

long long mul(long long a, long long b) {
    return (((a % mod) * (b % mod)) % mod);
}

long long potolok(long long a, long long b){   // округление вверх для целых
    return (a + b - 1) / b;
}


long long gcd(long long x, long long y){
    if(y == 0){
        return x;
    }
    if(x > y){
         return gcd(y, x % y);
    }
    else{
         return gcd(x, y % x);
    }
}

bool cmpr(int x, int y){            // сортировка по абсолютной величине
    if(abs(x) < abs(y)) return true;
    else{
        return false;
    }
}

bool comp(pair<int, int> x, pair<int, int> y){  // сортировка по первой компоненте
    if(x.first < y.first)return true;
    else if(x.first == y.first){
        if(x.second < y.second)return true;
        else return false;
    }
    else{
        return false;
    }
}

int main(){
    int x;
    cin >> x;
    if(x == 1)cout << 0 << endl;
    else{
        cout << 1 << endl;
    }
 }


Measured memory_bytes: 3596
#include<cstdio>
#include<cmath>
#include<cstring>
#include<iostream>
#include<vector>
#include<map>
#include<queue> 
#include<set>
#include<algorithm>
using namespace std;
#define maxn 200005
#define ll long long
void read(int &x){
    x=0;int f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    x*=f;
}
int n,m;
int a[maxn],b[maxn]; 
multiset<int> s;
bool cmp(int a,int b){
	return a>b;
}
int main(){
	read(n);
	for(int i=0;i<n;i++){
		int x;read(x);s.insert(x);
	}
	read(m);
	for(int i=0;i<m;i++){
		int x;read(x);
		multiset<int>::iterator pos=s.find(x);if(s.count(x)) s.erase(pos);
		else{
			puts("NO");return 0;
		}
	}
	puts("YES");
}

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

int main(){
    int a,b,c;
    long long k;
    cin >> a >> b >> c >> k;
    if(a>=k){
        cout << k << endl;
    }else if(a+b>=k){
        cout << a << endl;
    }else{
        cout << a-(k-a-b) << endl;
    }

}

Measured memory_bytes: 3584
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<int(n);++i)
#define all(a) (a).begin(),(a).end()
typedef long long ll;
#define rep1(i,n) for(int i=1;i<=int(n);++i)
#define lb(s,x) (lower_bound(all(s),x)-s.begin())
#define ub(s,x) (upper_bound(all(s),x)-s.begin())
#define uniq(a) a.erase(unique(all(a)),a.end())
#define bit(k) (1LL<<(k))
const int INF = 1e9;

#define debug(x) cerr<<(#x)<<": "<<(x)<<endl
template<class T,class U>
ostream& operator<<(ostream& o, const pair<T,U> &p){
    o<<"("<<p.first<<", "<<p.second<<")";
    return o;
}
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }


typedef complex<double> Point;
typedef vector<Point> VP;
#define X real()
#define Y imag()
const double EPS = 1e-9;
#define LE(n,m) ((n) < (m) + EPS)
#define GE(n,m) ((n) + EPS > (m))
#define EQ(n,m) (abs((n)-(m)) < EPS)
#define ps_edge(PS,i) PS[i],PS[(i+1)%PS.size()]

namespace std {
    bool operator<(const Point a, const Point b) {
        return a.X != b.X ? a.X < b.X : a.Y < b.Y;
    }
}

double dot(Point a, Point b) {
    return a.X*b.X + a.Y*b.Y;
}

double cross(Point a, Point b) {
    return a.X*b.Y - a.Y*b.X;
}

int ccw(Point a, Point b, Point c) {
    b -= a;  c -= a;
    if (cross(b,c) >  EPS) return +1;  // counter clockwise
    if (cross(b,c) < -EPS) return -1;  // clockwise
    if (dot(b,c)   < -EPS) return +2;  // c--a--b on line
    if (norm(b) < norm(c)) return -2;  // a--b--c on line or a==b
    return 0;                          // a--c--b on line or a==c or b==c
}

// 点集合を含む最小の円の中心
Point minEnclosingCircle(const VP& ps) {
    Point c;
    double move = 0.5;
    rep(i,100) {  // 2^(-39-1) \approx 0.9e-12
        rep(t,100) {
            double max = 0;
            int k = 0;
            rep (j, ps.size()) if (max < norm(ps[j]-c)) {
                max = norm(ps[j]-c);
                k = j;
            }
            c += (ps[k]-c) * move;
        }
        move /= 2;
    }
    return c;
}


int main(void){
    int n;
    cin >> n;
    VP ps(n);
    rep(i,n){
        double x, y;
        cin >> x >> y;
        ps[i] = Point(x,y);
    }
    Point c = minEnclosingCircle(ps);
    double r = 0;
    rep(i,n){
        r = max(r, abs(c-ps[i]));
    }
    printf("%.20f\n",r);
    return 0;
}


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

int main(){
    ios::sync_with_stdio(0);
    cin.tie(NULL);
    string s,t;

    cin >> s >> t;


    for(int i=0;i<s.size();i++){
        if(s[i]!=t[i]){
            cout << "No" << endl;
            return 0;
        }
    }

    // cout << t.size()+1 << " "<<s.size()<<endl;

    if(s.size()+1==t.size()){
        cout << "Yes"<<endl;
    } else{
        cout << "No" <<endl;
    }

    return 0;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rrep(i,n) for(ll i = 1; i <= (n); ++i)
#define drep(i,n) for(ll i = (n)-1; i >= 0; --i)
#define all(v) v.begin(),v.end()
#define len(x) (ll)(x).length()
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define pb push_back
#define sz(x) (ll)(x).size()
#define v(T) vector<T>
#define vv(T) vector<vector<T>>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
ll gcd(ll a,ll b){if(a%b==0){return b;}else{return(gcd(b,a%b));}}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
const int INF=1e9;
const ll MX = 1e18;
const ll MOD=INF+7;
const int di[] = {-1,0,1,0};
const int dj[] = {0,-1,0,1};
const double PI=acos(-1);
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
const int MAX = 1000001;
long long 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() {
  int a,b;
  cin>>a>>b;
  int ans=a+b;
  maxs(ans,a-b);
  maxs(ans,a*b);
  cout<<ans<<endl;
}

Measured memory_bytes: 3632
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        C solver = new C();
        solver.solve(1, in, out);
        out.close();
    }

    static class C {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            // 入力
            long n = Long.parseLong(in.next());
            long m = Long.parseLong(in.next());
            long ans = 0;

            if (n == 1 && m == 1) {
                ans = 1;
            } else if (n == 1 && m != 1) {
                ans = m - 2;
            } else if (n != 1 && m == 1) {
                ans = n - 2;
            } else {
                ans = (n - 2) * (m - 2);
            }

            // 出力
            out.println(ans);

        }

    }
}



Measured memory_bytes: 21972
from collections import Counter
def main():
    S = list(input())
    c = Counter(S)
    if ((c["N"] == 0 and c["S"] == 0) or (c["N"] > 0 and c["S"] > 0)) and ((c["W"] == 0 and c["E"] == 0) or (c["W"] > 0 and c["E"] > 0)):
        print("Yes")
    else:
        print("No")

if __name__ == '__main__':
    main()

Measured memory_bytes: 38256
#include<cstdio>
#include<math.h>
#include<string>
#include<algorithm>
#include<functional>
#include<vector>
#include<set>
#include<map>
#include<iostream>
#define INF 999999
#define EPS 1.0e-6

using namespace std;

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

int n,m;

int main()
{

    cin>>n>>m;
    int l,r;

    vector<int> a;
    int ai;
    for(int i=0;i<n;i++){
        cin>>ai;
        a.push_back(ai);
    }
    sort(a.begin(),a.end());
    //vector<int> b;
    //vector<int> c;
    vector<p> v;
    int bi,ci;
    for(int i=0;i<m;i++){
        cin>>bi>>ci;

        v.push_back(make_pair(ci,bi));
    }
    sort(v.begin(),v.end(),greater<p>());
    
    int cur=0;
    ll ttl=0;
    for(int i=0;i<a.size();i++){
        if(cur==v.size()){
            ttl+=a[i];
        }
        else if(a[i]<v[cur].first){
            ttl+=v[cur].first;
            v[cur].second--;
            if(v[cur].second==0){
                cur++;
            }
            
        }
        else{
            ttl+=a[i];
        }
        //cout<<ttl<<" ";
    }
    //cout<<endl;
    cout<<ttl<<endl;
    return 0;
}

Measured memory_bytes: 1784
import sys
reader = (s.rstrip() for s in sys.stdin)
input = reader.__next__

class Binary_Indexed_Tree():
    def __init__(self, n):
        self.n = n
        self.data = [0]*(n+1)

    def add(self, i, x):
        i += 1
        while i <= self.n:
            self.data[i] += x
            i += i & -i

    def sum(self, i):
        i += 1
        ret = 0
        while i:
            ret += self.data[i]
            i &= i-1
        return ret

    def sum_range(self, l, r):
        return self.sum(r)-self.sum(l-1)

    def lower_bound(self, w):
        if w<=0:
            return 0
        i = 0
        k = 1<<(self.n.bit_length())
        while k:
            if i+k <= self.n and self.data[i+k] < w:
                w -= self.data[i+k]
                i += k
            k >>= 1
        return i

q = int(input())
query = [list(map(int, input().split())) for i in range(q)]

a_set = sorted(set(i[1] for i in query if len(i)>1))
n = len(a_set)
dd = {j:i+1 for i,j in enumerate(a_set)}

cnt_bit = Binary_Indexed_Tree(n+2)
sum_bit = Binary_Indexed_Tree(n+2)

offset = 0
cnt = 0
for i in query:
    if len(i) == 1:
        left = cnt//2 + cnt%2
        right = cnt-left
        j = cnt_bit.lower_bound(left)
        x = a_set[j-1]
        ans = offset
        left_cnt = cnt_bit.sum_range(0,j-1)
        ans -= sum_bit.sum_range(0, j-1)
        ans += left_cnt*x
        right_cnt = cnt_bit.sum_range(j+1, n+1)
        ans += sum_bit.sum_range(j+1, n+1)
        ans -= right_cnt*x
        print(x, ans)
    else:
        _, a, b = i
        cnt_bit.add(dd[a], 1)
        sum_bit.add(dd[a], a)
        offset += b
        cnt += 1



Measured memory_bytes: 108504
using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
	public static int Main(string[] args)
	{
        int ans=0;
        string[] str = Console.ReadLine().Split(' ');
        int N = int.Parse(str[0]);
        int x = int.Parse(str[1]);
        str = Console.ReadLine().Split(' ');
        int[] a = new int[N];
        for (int i = 0; i < N;i++){
            a[i] = int.Parse(str[i]);
        }
        Array.Sort(a);
        for (int i = 0; i < N;i++){
            if (i == N - 1)
            {
                if (x == a[N - 1]) ans++;
            }
            else{
                if (x - a[i] >= 0)
                {
                    x -= a[i];
                    ans++;
                }
                else
                {
                    break;
                }
            }
        }

        Console.WriteLine(ans);

        return 0;
	}
}


Measured memory_bytes: 13140
#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<queue>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
#define forn(i,a,b)for(int i=(a),_b=(b);i<=_b;i++)
#define fore(i,b,a)for(int i=(b),_a=(a);i>=_a;i--)
#define rep(i,n)for(int i=0,_n=n;i<n;i++)
#define ll long long
#define pii pair<int,int>
#define vi vector<int>
#define vpii vector<pii>
#define m_p make_pair
#define re return
#define pb push_back
#define si set<int>
#define ld long double
#define X first
#define Y second
#define st string
#define ull unsigned long long
#define mod 1000000007
#define INF 1000000007
#define x1 XZVJDFADSPFOE
#define y1 GASDIJSLDAEJF
#define x2 DFDAJKVOHKWIW
#define y2 PSFSAODSXVNMQ
#define LLINF 0x3f3f3f3f3f3f3f3fLL
using namespace std;
inline void read(int &x)
{
	short negative=1;
    x=0;
    char c=getchar();
    while(c<'0' || c>'9')
    {
		if(c=='-')
			negative=-1;
		c=getchar();
	}
    while(c>='0' && c<='9')
        x=(x<<3)+(x<<1)+(c^48),c=getchar();
    x*=negative;
}
ll quickpower(ll n,ll k){
	ll ans=1;
	while(k){
		if(k%2){
			ans*=n;
			ans%=mod;
		}
		n*=n;
		n%=mod;
		k/=2;
	}
	return ans;
}
string int_to_string(int n)
{
	string s="";
	while(n)
	{
		int now=n%10;
		s+=now+'0';
		n/=10;
	}
	reverse(s.begin(),s.end());
	return s;
}
int string_to_int(string s)
{
	int n=0;
	rep(i,s.size())
	{
		n*=10;
		n+=s[i]-'0';
	}
	return n;
}
int l[200100],r[200100];
string s;
int n,k,c;
int cnt; 
int main()
{
	ios::sync_with_stdio(0);
	//think twice,code once
	cin>>n>>k>>c;
	cin>>s;
	rep(i,s.size())
	{
		if(s[i]=='o')
		{
			l[cnt++]=i;
			i+=c;
			if(cnt==k)break;
		}
	}
	cnt=k-1;
	fore(i,s.size()-1,0)
	{
		if(s[i]=='o')
		{
			r[cnt--]=i;
			i-=c;
			if(cnt==-1)break;
		}
	}
	rep(i,k)if(l[i]==r[i])cout<<l[i]+1<<endl;
	return 0;
}



Measured memory_bytes: 3348