akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <algorithm>
using namespace std;
#define mod 10000
int day[100];
long long dp[100][3][3];
int main() {
    int n, k; scanf("%d%d",&n,&k);
    for (int i=0; i<k; i++) {
        int a,b; scanf("%d%d",&a,&b);
        day[a-1]=b;
    }
    if (day[0]) {
        dp[0][day[0]-1][0]=dp[0][day[0]-1][2]=1;
    } else {
        dp[0][0][0]=dp[0][1][0]=dp[0][2][0]=1;
        dp[0][0][2]=dp[0][1][2]=dp[0][2][2]=1;
    }
    for (int i=1; i<n; i++) {
        if (day[i]==1) {
            dp[i][0][0]=(dp[i-1][1][2]+dp[i-1][2][2])%mod;
            dp[i][0][1]=dp[i-1][0][0];
            dp[i][0][2]=(dp[i][0][1]+dp[i][0][0])%mod;
        } else if (day[i]==2) {
            dp[i][1][0]=(dp[i-1][0][2]+dp[i-1][2][2])%mod;
            dp[i][1][1]=dp[i-1][1][0];
            dp[i][1][2]=(dp[i][1][1]+dp[i][1][0])%mod;
        } else if (day[i]==3) {
            dp[i][2][0]=(dp[i-1][0][2]+dp[i-1][1][2])%mod;
            dp[i][2][1]=dp[i-1][2][0];
            dp[i][2][2]=(dp[i][2][1]+dp[i][2][0])%mod;
        } else {
            dp[i][0][0]=(dp[i-1][1][2]+dp[i-1][2][2])%mod;
            dp[i][0][1]=dp[i-1][0][0];
            dp[i][0][2]=(dp[i][0][1]+dp[i][0][0])%mod;
            dp[i][1][0]=(dp[i-1][0][2]+dp[i-1][2][2])%mod;
            dp[i][1][1]=dp[i-1][1][0];
            dp[i][1][2]=(dp[i][1][1]+dp[i][1][0])%mod;
            dp[i][2][0]=(dp[i-1][0][2]+dp[i-1][1][2])%mod;
            dp[i][2][1]=dp[i-1][2][0];
            dp[i][2][2]=(dp[i][2][1]+dp[i][2][0])%mod;
        }
    }
    printf("%lld\n",(dp[n-1][0][2]+dp[n-1][1][2]+dp[n-1][2][2])%mod);
}

Measured memory_bytes: 0
<?php
$n = trim(fgets(STDIN));

$last = function($words) {
    return end($words);
};

$words[] = trim(fgets(STDIN));
foreach(range(1, $n-1) as $i) {
    $word = trim(fgets(STDIN));
    $end = $last($words);

    if(in_array($word, $words) || $end[strlen($end)-1] != $word[0]) {
        echo 'No';
        exit;
    }

    $words[] = $word;
}

echo 'Yes';


Measured memory_bytes: 4604
#include <bits/stdc++.h>
using namespace std;
const int N = 2003;
vector<int> row[N], col[N];
string a[N];
int h, w;
int gsearch(vector<int> &v, int k, int n)
{
	int low = 0, high = (int)v.size() - 1, ans = n;
	while (low <= high)
	{
		int mid = (low + high) / 2;
		if (v[mid] > k)
		{
			ans = v[mid] - 1;
			high = mid - 1;
		}
		else
			low = mid + 1;
	}
	return ans;
}
int ssearch(vector<int> &v, int k, int n)
{
	int ans = n;
	int low = 0, high = (int)v.size() - 1;
	while (low <= high)
	{
		int mid = (low + high) / 2;
		if (v[mid] < k)
		{
			ans = v[mid] + 1;
			low = mid + 1;
		}
		else
			high = mid - 1;
	}
	return ans;
}
int main(int argc, char const *argv[])
{
	cin >> h >> w;
	for (int i = 0; i < h; ++i)
	{
		cin >> a[i];
		for (int j = 0; j < w; ++j)
		{
			if (a[i][j] == '#')
			{
				col[j].push_back(i);
				row[i].push_back(j);
			}
		}
	}
	int ans = 0;
	for (int i = 0; i < h; ++i)
	{
		for (int j = 0; j < w; ++j)
		{
			if (a[i][j] == '#')
				continue;
			int l = ssearch(row[i], j, 0), r = gsearch(row[i], j, w - 1), u = ssearch(col[j], i, 0), d = gsearch(col[j], i, h - 1);
			int c = r - l + 1 + d - u;
			//cout << i << ' ' << j << ' ' << l  << ' ' << r << ' ' << u << ' ' << d << '\n';
			ans = max(ans, c);

		}
	}
	cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 44424
import sys


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    n, k = list(map(int, readline().split()))
    for i in range(10 ** 10):
        if n < k ** i:
            print(i)
            exit()


if __name__ == '__main__':
    solve()


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

using namespace std;

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define REP(i, n) FOR(i, 0, n)
#define RFOR(i, a, b) for(int i=(a);i>=(b);i--)
#define RREP(i, n) RFOR(i, n, 0)
#define MFOR(i, m) for(auto i=(m).begin();i!=(m).end();i++)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((int)(x).size())

typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;

const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1 << 30;

template<typename T>
void printv(vector<T> const& s) {
  REP(i, SZ(s)) {
    cout << s[i] << " ";
  }
  cout << endl;
}

#define int ll

signed main () {
  cin.tie(0);
  cout << setprecision(10);

  ll n, c; cin >> n >> c;
  vll x(n), v(n);
  REP(i, n) {
    cin >> x[i] >> v[i];
  }

  // clockwise go
  vll sr(n);
  sr[0] = v[0] - x[0];
  FOR(i, 1, n) {
    sr[i] = sr[i-1] + v[i] - (x[i] - x[i-1]);
  }
  
  vll sl(n);
  sl[0] = v[n-1] - (c - x[n-1]);
  FOR(i, 1, n) {
    sl[i] = sl[i-1] + v[n-i-1] - (x[n-i] - x[n-i-1]);
  }

  vll ma1r(n);
  ma1r[0] = max(0ll, sr[0]);
  FOR(i, 1, n) {
    ma1r[i] = max(ma1r[i-1], sr[i]);
  }

  vll ma1l(n);
  ma1l[0] = max(0ll, sl[0]);
  FOR(i, 1, n) {
    ma1l[i] = max(ma1l[i-1], sl[i]);
  }

  vll ma2r(n);
  ma2r[0] = max(0ll, sr[0] - x[0]);
  FOR(i, 1, n) {
    ma2r[i] = max(ma2r[i-1], sr[i] - x[i]);
  }

  vll ma2l(n);
  ma2l[0] = max(0ll, sl[0] - (c - x[n-1]));
  FOR(i, 1, n) {
    ma2l[i] = max(ma2l[i-1], sl[i] - (c - x[n-i-1]));
  }


  // printv(sr);
  // printv(sl);
  // printv(ma1r);
  // printv(ma1l);
  // printv(ma2r);
  // printv(ma2l);

  ll ans = max(ma1r[n-1], ma1l[n-1]);
  FOR(i, 0, n-1) {
    // cout << i << ":" << ans << endl;
    ans = max(ans, max(ma1r[i] + ma2l[n-2-i], ma2r[i] + ma1l[n-2-i]));
  }
  cout << ans << endl;
}


Measured memory_bytes: 6528
// C - String Transformation
#include <bits/stdc++.h>
using namespace std;

int main(){
	string S, T; cin>>S>>T;
	vector<int> st(26, -1), ts(26, -1);//st:S->T, ts:T->S
	int c;//common number
	for(c=0; c<S.size(); ++c){
		int s = S[c]-'a', t = T[c]-'a';
		if(st[s] != ts[t]) break;
		st[s] = ts[t] = c;
	}
	puts(c==S.size()? "Yes":"No");
}

Measured memory_bytes: 776
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Graph vector<vector<int>>
typedef long long ll;
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int inf=1000000000; //10^9

int main(){
    int A,B;
    cin>>A>>B;
    cout<<A*B;
}

Measured memory_bytes: 3636
#include <iostream>
#include <string>
#include <cstring>
#include <iostream>
#include <string>
#include <cstring>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <utility>
using namespace std;
int main(){
    vector<int> a(3);
    for(int i=0;i<3;i++)cin>>a.at(i);
    sort(a.begin(),a.end());
    if((a.at(2)-a.at(1)+a.at(2)-a.at(0))%2==0)cout<<(a.at(2)-a.at(1)+a.at(2)-a.at(0))/2<<endl;
    else cout<<(a.at(2)-a.at(1)+a.at(2)-a.at(0)+3)/2<<endl;
    return 0;
}



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

using namespace std;

int main()
{
    int n;
    cin>>n;
    vector<int>v(n,0);
    for(int i=0;i<n;i++)cin>>v[i];
    sort(v.begin(),v.end());
    float ans=0,temp=v[0];
    for(int i=0;i<n-1;i++)
    {
     ans=(temp+v[i+1])/2;
     temp=ans;
    }
    cout<<ans;
    return 0;
}


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

int main(){
    int n;
    cin >> n;
    vector<int> a;
    for(int i=0;i<3*n;++i){
        int tmp;
        cin >> tmp;
        a.push_back(tmp);
    }
    sort(a.begin(), a.end());
    int right = 3*n - 1, left = 0;
    long long int ans = 0;
    while(right > left){
        right--;
        left++;
        ans += a[right--];
    }
    cout << ans << endl;

    return 0;
}


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

using namespace std;
using ll = long long;
using ld = long double;

#define rep(i, a, b) for (auto i = (a); i < (b); ++i)
#define trav(e, x) for (auto &e : x)
#define eb(x...) emplace_back(x)
#define all(x) begin(x), end(x)
#define sz(x) int((x).size())

template<class T> bool ckmin(T& a, const T& b) { return a > b ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	int a, b, c, k; cin >> a >> b >> c >> k;
	while (b <= a) b *= 2, --k;
	while (c <= b) c *= 2, --k;
	// cout << k << '\n';
	cout << (k < 0 ? "No" : "Yes");
}

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

int main(){
    int n;
    cin >> n;
    vector<int> w(n);
    int wsum=0;
    rep(i, n){
        cin >> w.at(i);
        wsum += w.at(i);
    }
    int s1=0, res=wsum;
    rep(i,n){
        s1+=w.at(i);
        if(res > abs(s1-(wsum-s1))) res = abs(s1-(wsum-s1));
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 764
import qualified Data.Vector.Unboxed as U
import qualified Data.Vector as V
import qualified Data.ByteString.Char8 as C
import Debug.Trace
import Data.List
import Control.Monad
import Control.Arrow
import Data.Ord


r :: Int -> IO (U.Vector Int)
r n = U.unfoldrN n (C.readInt . C.dropWhile (==' ')) <$> C.getLine

r' :: IO [Int]
r'  =   unfoldr    (C.readInt . C.dropWhile (==' ')) <$> C.getLine



main :: IO ()
main = do
    n <- readLn :: IO Int
    print $ sum (filter (\x -> x`rem`3/=0 && x`rem`5/=0) [1..n])



Measured memory_bytes: 3884
#include<iostream>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    double d,t,s;
    cin>>d>>t>>s;
    if((d/t)<=s)
    cout<<"Yes";
    else
    {
        cout<<"No";
    }

}


Measured memory_bytes: 3736
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
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; }
const int INF=1001001001;
const int mod=1e9+7;

int main() {
  string s;
  cin>>s;
  int n=s.size();
  vector<int>p(n);
  int odd=0,even=0;
  for(int i=0;i<n;i++){
    if(s[i]=='R'){
      if(i%2==0){even++;}
      else{odd++;}
    }
    if(s[i]=='L'){
      if(i%2==0){p[i]+=even;p[i-1]+=odd;}
      else{p[i]+=odd;p[i-1]+=even;}
      odd=0,even=0;
    }
  }

  odd=0,even=0;
  for(int i=n-1;i>=0;i--){
    if(s[i]=='L'){
      if(i%2==0){even++;}
      else{odd++;}
    }
    if(s[i]=='R'){
      if(i%2==0){p[i]+=even;p[i+1]+=odd;}
      else{p[i]+=odd;p[i+1]+=even;}
      odd=0,even=0;
    }
  }
  for(int i=0;i<n;i++){
    cout<<p[i];
    if(i<n){cout<<" ";}
  }cout<<endl;
  return 0;
}

Measured memory_bytes: 3852
#include <iostream>
#include <stdio.h>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>

using namespace std;

#define x first
#define y second
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define all(x) x.begin(),x.end()
#define SZ(x) int(x.size())
#define rep(i, a, b) for(int i = a; i < b; i++)
#define per(i, a, b) for(int i = b-1; i >= a; i--)
#define DBG(x) cerr << (#x) << "=" << x << "\n";
#define ll long long
#define inf 1000000007
#define mod 998244353 //1000000007
#define N 100005

template<typename U, typename V> void Min(U &a, const V & b){if(a > b)a = b;}
template<typename U, typename V> void Max(U &a, const V & b){if(a < b)a = b;}
template<typename U, typename V> void add(U &a, const V & b){a = (a + b) % mod;} 
template<typename U> U gcd(U a, U b){
	if(a == 0)return b;
    if(b == 0)return a;
	if(a >= b)return gcd(a-b, b);
	else return gcd(a, b - a);
} 
int pow(int a, int b){
    int ans = 1;
    while(b){
        if(b & 1)ans = 1LL * ans * a % mod;
        a = 1LL * a * a % mod;
        b >>= 1;
    }
    return ans;
}

int f[N], sz[N], cnt[N];
int find(int a){return a == f[a] ? a : f[a] = find(f[a]);}
int merge(int a, int b){
    a = find(a), b = find(b);
    if(a == b)return 0;
    if(sz[a] < sz[b])swap(a, b);
    sz[a] += sz[b];
    f[b] = a;
    return 1;
}
pii q[N];
int main(){
    int T, m, n, i, j, k, K;
    scanf("%d%d%d", &n, &m, &K);
    rep(i, 0, n)f[i] = i, sz[i] = 1;
    int t = 0, ok = 1;
    while(K--){
        scanf("%d%d%d", &i, &j, &k);
        if(!ok)continue;
        if(k == 0){
            if(merge(i, j) == 1){
                m--;
            }
        }
        else{
            q[t++] = {i, j};
        }
    }
    if(!ok || m < 0){
        puts("No");return 0;
    }
    rep(i, 0, t){
        if(find(q[i].x) == find(q[i].y)){
            puts("No");return 0;
        }
        cnt[f[q[i].x]]++;
        cnt[f[q[i].y]]++;
    }
    int e = 0;
    K = 0;
    rep(i, 0, n)if(f[i] == i){
        if(cnt[i])K++;
        e++;
    }
    if(K > 0)Max(K, 3);
    ll w = 1LL * e * (e-1) / 2;
    if(m >= K && m <= w){
        puts("Yes");
    }
    else puts("No");
}


Measured memory_bytes: 2176
#include<bits/stdc++.h>
using namespace std;
int a[100007],b[100007],c[100007];
int main(){
    int n;
    scanf("%d",&n);
    int mx=0;
    int minn=1e9;
    for(int i=1;i<=n;i++){
        scanf("%d",&a[i]);
        mx=max(mx,a[i]);
        minn=min(minn,a[i]);
    }
    int mn=1e9;
    for(int i=1;i<=n;i++){
        if(mx==a[i])
            continue;
        b[i]=mx%a[i];
        if(b[i]==0)
            continue;
        while(1){
            c[i]=a[i]%b[i];
            if(c[i]){
                mn=min(mn,c[i]);
                a[i]=b[i];
                b[i]=c[i];
            }
            else{
                if(b[i])
                    mn=min(mn,b[i]);
                break;
            }
        }
    }
    mn=min(minn,mn);
    printf("%d",mn);
    return 0;
}


Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
#define int long long
int n;
vector<string> w,v;
vector<string> xyz[30];
string s;
vector<char> vc,ans;
typedef pair<int,int> P;
vector<P> vp;
vector<int> used;
int valid;
vector<int> wc1,wc2;
void dfs(){
  for(int i=0;i<(int)v.size();i++){
    string& t=v[i];
    bool flg=0;
    for(int j=0;j<(int)xyz[t.size()].size();j++){
      string& u=xyz[t.size()][j];
      bool ok=1;
      for(int k=0;k<(int)t.size();k++){
    if(!used[t[k]-'A']) continue;
    if(!used[u[k]-'A']){
      ok=0;
      break;
    }
    ok&=vc[t[k]-'A']==u[k]-'A';
    if(!ok) break;
      }
      //cout<<t<<" "<<u<<":"<<ok<<endl;
      if(ok){
    flg=1;
    break;
      }
    }
    if(!flg) return;
  }
  int cnt=0;
  for(int i=0;i<26;i++) if(used[vp[i].second]) cnt++;
  //cout<<cnt<<endl;
  //if(cnt>1) return;
  if(cnt==26){
    valid++;
    ans=vc;
    return;
  }
  int x=0;
  while(used[vp[x].second]) x++;
  //cout<<x<<endl;
  if(vp[x].first){
    for(int k=0;k<26;k++){
      if(used[vp[k].second]) continue;
      used[vp[x].second]=used[vp[k].second]=1;
      vc[vp[x].second]=vp[k].second;
      vc[vp[k].second]=vp[x].second;
      //cout<<x<<" "<<k<<endl;
      //cout<<(char)(vp[x].second+'A')<<"<->"<<(char)(vp[k].second+'A')<<endl;
      dfs();
      if(valid>1) return; 
      used[vp[x].second]=used[vp[k].second]=0;
      vc[vp[x].second]=vc[vp[k].second]=0;   
    }
  }else{
    used[vp[x].second]=1;
    vc[vp[x].second]=vp[x].second;
    dfs();
    used[vp[x].second]=0;
    vc[vp[x].second]=0;
  }
}
signed main(){
  while(cin>>n,n){
    for(int i=0;i<30;i++) xyz[i].clear(); 
    w.resize(n);
    for(int i=0;i<n;i++) cin>>w[i],xyz[w[i].size()].push_back(w[i]);
    cin.ignore();
    getline(cin,s);
    assert(s.back()=='.');
    s.pop_back();
    v.clear();
    for(int i=0;i<(int)s.size();i++){
      string t;
      while(i<(int)s.size()&&s[i]!=' ') t+=s[i++];
      //cout<<t<<endl;
      v.push_back(t);
    }
    vc.clear();
    vc.resize(26,0);
    wc2.clear();
    wc2.resize(26,0);
    for(int i=0;i<(int)v.size();i++)
      for(int j=0;j<(int)v[i].size();j++)
    wc2[v[i][j]-'A']++;
    vp.resize(26);
    for(int i=0;i<26;i++) vp[i]=P(wc2[i],i);
    sort(vp.rbegin(),vp.rend());
    used.clear();
    used.resize(26,0);
    valid=0;
    dfs();
    //cout<<valid<<endl;
    if(valid!=1){
      cout<<"-."<<endl;
      continue;
    }
    //puts("found");
    for(int i=0;i<(int)v.size();i++){
      if(i) cout<<" ";
      for(int j=0;j<(int)v[i].size();j++){
    //cout<<v[i][j]-'A'<<endl;
    cout<<(char)(ans[v[i][j]-'A']+'A');
      }
    }
    cout<<"."<<endl;
  }
  return 0;
}

Measured memory_bytes: 3164
n = int(input())
s = input()

d = [0] * n
res = ""
for i in range(n):
    if(d[i] == 1):
        continue
    for j in range(1, n-i):
        if s[i] == s[i+j]:
            d[i+j] = 1
        else:
            break

    res += s[i]

print(len(res))


Measured memory_bytes: 4084
N,C,K=map(int,input().split())
T=sorted([int(input()) for j in range(N)])
Bcount=1
person=0
Time=T[0]
for i in T:
  if person < C:
    if i-Time > K:
      Bcount += 1
      person = 1
      Time=i
    else:
      person += 1
  else:
    Bcount += 1
    person = 1
    Time=i

print(Bcount)

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

int main(void){
    int a,b,c,d;
    int result1,result2;
    cin >> a >> b >> c >> d;
    result1 = a * b;
    result2 = c * d;
    if(result1 > result2)
        cout << result1 << '\n';
    else if(result1 < result2)
        cout << result2 << '\n';
    else
        cout << result1 << "\n";
    
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<map>
using namespace std;
const int N=2e5+2;
vector<int> adj[N];
int c[N],max1[N];
map<int,int> dp[N];
int dfs1(int x,int p,int val){
	if(dp[x].count(val)){
		return dp[x][val];
	}	
	int i,j=0;
	for(i=0;i<adj[x].size();i++){
		if(adj[x][i]!=p&&adj[x][i]<val){
			j+=1+dfs1(adj[x][i],x,val);
		}
	}
	dp[x][val]=j;
	return j;
}
void dfs(int x,int p){
	int i,j;
	if(x!=1){
		if(x>max1[p]){
			j=dfs1(x,p,max1[x])+1;
		}
		else{
			j=dfs1(x,p,max1[x])-dfs1(x,p,max1[p]);
		}
		c[x]=c[p]+j;
	}
	for(i=0;i<adj[x].size();i++){
		if(adj[x][i]!=p){
			max1[adj[x][i]]=max(x,max1[x]);
			dfs(adj[x][i],x);
		}
	}
}
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n,i,j,k,l;
	cin>>n;
	for(i=1;i<n;i++){
		cin>>j>>k;
		adj[j].push_back(k);
		adj[k].push_back(j);
	}
	dfs(1,1);
	for(i=2;i<=n;i++){
//		cout<<dp[i].size()<<endl;
		cout<<c[i]<<' ';
	}
}

Measured memory_bytes: 54784
//om nama sivaya
#include<bits/stdc++.h>
#define ll long long
#define mod 1000000007
#define pb push_back
#define ff first
#define ss second
#define pb push_back
using namespace std;
void solve(){
    ll n,m;
    cin>>n>>m;
    char a[n][m];
    for(int i=0;i<n;i++)
    for(int j=0;j<m;j++)
    {cin>>a[i][j];}
    ll dp[n][m];
    for(int i=0;i<n;i++)
    for(int j=0;j<m;j++)
    dp[i][j]=0;
    for(int i=0;i<n;i++)
    if(a[i][0]!='#')
    dp[i][0]=1;
    else
    break;
    for(int i=0;i<m;i++)
    if(a[0][i]!='#')
    dp[0][i]=1;
    else
    break;
    if(a[0][0]=='#'){
        cout<<"0";return;
    }
    dp[0][0]=0;
    for(int i=1;i<n;i++)
    for(int j=1;j<m;j++){
        //dp[i][j]=0;
        if(a[i][j]!='#'){
        if(a[i-1][j]!='#')
        dp[i][j]+=dp[i-1][j];
        if(a[i][j-1]!='#')
        dp[i][j]+=dp[i][j-1];}
        dp[i][j]%=mod;
    }
    //dp[i][j]=dp[i-1][j]+dp[i][j-1],dp[i][j]%=mod;
    cout<<dp[n-1][m-1];
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int tt=1;
    //cin>>tt;
    while(tt--){
        solve();
    }
}


Measured memory_bytes: 12416
def B_GoodDistance():
    N, D = map(int, input().split())
    x = [list(map(int, input().split())) for _ in range(N)]
    ans = 0
    for i in range(N-1):
        for j in range(i + 1, N):
            if distance(x[i], x[j]):
                ans += 1
    print(ans)

def distance(y, z):
    from math import sqrt
    d = 0
    for i in range(len(y)):
        d += (y[i] - z[i]) * (y[i] - z[i])
    d = sqrt(d)
    return (d == d // 1)

if __name__ == "__main__":
    B_GoodDistance()

Measured memory_bytes: 3064
/*Author : Kartik Bansal
 *Date : 07/09/19
 *Time : 16:14 */
#include <bits/stdc++.h>
using namespace std;
typedef long long ll ;
#define tc int t ;cin>>t ;while(t--)
#define pb push_back
#define FOR(i,n) for(int i =0;i<n;i++)
#define loop(i,a,b) for(int i=a;i<b;i++)
#define all(v) v.begin() , v.end()
#define sort(v) sort(all(v))
#define vi  vector<int>
#define vll  vector<long long >
#define inf INT_MAX
#define minf INT_MIN
const ll mod  = 1e9 + 7 ;
int  primes[1010] = {0} ;
vector<int> v ;

void genrate_primes()
{
       FOR(i,1010)
              primes[i] = 1 ;
       primes[0] = primes[1] = 0 ;
       for(int i = 2 ; i<=1001 ;i++ )
              {
                     if(primes[i])
                     {
                            for(int j = 2 *i ;j<=1001 ; j+=i)
                                   primes[j] = 0 ;
                            v.pb(i) ;
                     }
              }
              // for(auto it : v)
              //      cout <<it <<" " ;
}


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

  genrate_primes() ;
  int  n ;
  cin>>n ;

  // cout <<primes[2 ] ;
  // for(auto it : v )
  //      cout <<it<<' '  ;
  map<int , int > m ;
  ll ans = 1 ;

       for(int i =2   ; i<=n ;i++)
       {
                     int num = i  ;
                     for(auto it : v )
                     {
                            while(num%it == 0 )
       {                            num /= it ;
                                   m[it]++ ;
       }
              }

       }
for(auto it : m )
{
  ans *= it.second + 1 ;
  ans %= mod ; 
}
cout <<ans ;


  return 0 ;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(int argc, const char * argv[])
{
    int depth,width,i,j;
    
    while(1){
        scanf("%d %d",&depth,&width);
    
        if(depth==0 && width==0){
            break;
        }
    
        for(i = 0;depth > i;i+=1){
            
            for(j = 0;width > j;j+=1){
                printf("#");
            }
        
            printf("\n");
        
        }
        printf("\n");
    }
        
    return 0;
}

Measured memory_bytes: 572
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define Max(a, b) (a > b ? a : b)
#define Min(a, b) (a < b ? a : b)
#define ii pair<int, int>
#define fi first
#define se second
const int MAX = 200000; //2 * 10^5
const int MOD = 1000000007; //10^9 + 7
const int OO = 0x3f3f3f3f; // 0x3f3f3f3f;

int32_t main()
{
	int n, sum = 0;
	cin >> n;
	map<int, int> mapa;
	for(int i = 0; i < n; i++)
	{
		int a;
		cin >> a;
		mapa[a]++;
		sum += a;
	}

	int q;
	cin >> q;
	while(q--)
	{
		int a, b;
		cin >> a >> b;
		sum -= mapa[a] * a;
		mapa[b] += mapa[a];
		sum += mapa[a] * b;
		mapa[a] = 0;
		cout << sum << '\n';
	}

	return 0;
}


Measured memory_bytes: 9384
/*  -*- coding: utf-8 -*-
 *
 * 2918.cc: Surmise
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

/* typedef */

/* global variables */

/* subroutines */

/* main */

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

  int cnt = 0;
  for (int i = 0; i < n; i++) {
    int ai;
    scanf("%d", &ai);
    if (! (ai & 1)) cnt++;
  }
  printf("%d\n", cnt);
  return 0;
}



Measured memory_bytes: 3228
#!/usr/bin/env python3
import sys


def solve(N: int, M: int, A: "List[int]"):
    s = sum(A)
    print(max(-1, N-s))
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(M)]  # type: "List[int]"
    solve(N, M, A)

if __name__ == '__main__':
    main()

Measured memory_bytes: 68568
{-# LANGUAGE OverloadedStrings, ViewPatterns #-}
import Control.Arrow
import Control.Monad
import Data.List
import qualified Data.ByteString.Char8 as B
import qualified Data.Vector as V 
main :: IO ()
main = readLine >>= main'
    where
        main' [h, w] = replicateM h B.getLine >>= print . solve h w 

solve :: Int -> Int -> [B.ByteString] -> Int
solve h w ss = maximum [count i j | i <- [0..(h - 1)], j <- [0..(w - 1)]]
    where
        count i j = hs V.! i V.! j + ws V.! j V.! i - 1

        vs = V.fromList ss

        hs = V.fromList $ map counth ss
        
        counth s = V.fromList $ check 0 0
            where
                check p i
                    | i == w - 1 && c == '#' = replicate (i - p) (i - p) ++ [0]
                    | i == w - 1 = replicate (i - p + 1) (i - p + 1)
                    | c == '#' = replicate (i - p) (i - p) ++ 0 : check (i + 1) (i + 1)
                    | otherwise = check p $ i + 1
                    where
                        c = B.index s i

        ws = V.fromList $ map countw [0..(w - 1)]
        
        countw idx = V.fromList $ check 0 0
            where
                check p i 
                    | i == h - 1 && c == '#' = replicate (i - p) (i - p) ++ [0]
                    | i == h - 1 = replicate (i - p + 1) (i - p + 1)
                    | c == '#' = replicate (i - p) (i - p) ++ 0 : check (i + 1) (i + 1)
                    | otherwise = check p $ i + 1
                    where
                        c = B.index (vs V.! i) idx
        
readLine :: IO [Int]
readLine = unfoldr (fmap (second (maybe B.empty snd . B.uncons)) . B.readInt) <$> B.getLine

readContents :: Int -> IO [[Int]]
readContents = flip replicateM readLine

Measured memory_bytes: 138876
n = int(input())
l = [list(map(int, input().split())) for _ in range(n)]
l = sorted(l, key = lambda x:x[1])

now = 0
flag = 0
for i in range(n):
  now += l[i][0]
  if now > l[i][1]:
    flag = 1
    break

print("Yes" if flag == 0 else "No")

Measured memory_bytes: 55264
#include <iostream>
#include <vector>
#include <string>


using namespace std;

int main() {

	/* ----- 変数宣言 ----- */
	string s;

	/* ----- 入力 ----- */
	cin >> s;

	/* ----- 計算 ----- */
	s[3] = '8';

	cout << s << endl;
}

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

int best[300010];

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

    int l = 0;

    for (int i = 1; i <= n; i++) {
        int x;
        cin >> x;
        best[x] = 1 + best[x - 1];
        l = max(l, best[x]);
    }

    cout << n - l;
    return 0;
}


Measured memory_bytes: 1152
#include <iostream>
#include <vector>
#include <bitset>
#include <unordered_set>
#include <algorithm>
#include <cassert>

using namespace std;

template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
  os << "[ ";
  for(typename vector<T>::const_iterator it=v.begin(); it!=v.end(); ++it)
    os << '\"' << *it << '\"' << (it+1==v.end() ? "" : ", "); os << " ]"; 
  return os; 
}
template<typename T> ostream& operator<<(ostream& os, const unordered_set<T>& v) {
  os << "{ ";
  for(auto it=v.begin(); it!=v.end(); ++it) {
    if (it != v.begin())
      os << ", ";
    os << *it; 
  }
  os << " }"; 
  return os; 
}

#define HERE (cerr << "LINE: " << __LINE__ << " " << __FUNCTION__ << endl)
#define DBG(x) cerr << #x << ": " << x << endl

int main() {
  int H, W;
  cin >> H >> W;
  DBG(H);
  DBG(W);
  
  vector<vector<int>> A(H, vector<int>(W));
  vector<vector<int>> B(H, vector<int>(W));
  vector<vector<int>> C(H, vector<int>(W));

  for (int y=0; y<H; y++)
    for (int x=0; x<W; x++)
      cin >> A[y][x];

  for (int y=0; y<H; y++)
    for (int x=0; x<W; x++)
      cin >> B[y][x];

  for (int y=0; y<H; y++)
    for (int x=0; x<W; x++)
      C[y][x] = abs(A[y][x] - B[y][x]);

  for (int y=0; y<H; y++)
    for (int x=0; x<W; x++)
      C[y][x] = abs(A[y][x] - B[y][x]);

#if 0  
  vector<unordered_set<int>> memo(W+1, {0}), memo2(W+1);

  for (int y=0; y<H; y++) {
    DBG(y);
    for (int x=0; x<W; x++) {
      memo2[x+1].clear();
      for (const auto& s : {memo2[x], memo[x+1]}) {
        for (int a : s) {
          if (a + C[y][x] <= 80*200)
            memo2[x+1].insert(a + C[y][x]);
          memo2[x+1].insert(abs(a - C[y][x]));
        }
      }
      //cerr << x << "," << y << " " << memo2[x+1].size() << endl;
    }
    memo.swap(memo2);
  }

  cout << *min_element(memo[W].begin(), memo[W].end()) << endl;
#endif
  constexpr int K = 80*200;
  vector<bitset<K>> memo(W+1), memo2(W+1);

  for (int y=0; y<H; y++) {
    for (int x=0; x<W; x++) {
      memo2[x+1].reset();
      if (x == 0 && y == 0) {
        memo2[x+1][C[y][x]] = 1;
        continue;
      }
      
      for (const auto& s : {memo2[x], memo[x+1]}) {
        for (int a=0; a<K; a++) {
          if (s[a]) {
            if (a + C[y][x] < K)
              memo2[x+1][a + C[y][x]] = 1;
            memo2[x+1][abs(a - C[y][x])] = 1;
          }
        }
      }
#if 0      
      cerr << x << "," << y << " : ";
      for (int i=0; i<K; i++)
        if (memo2[x+1][i])
          cerr << i << " ";
      cerr << endl;
#endif
            
    }
    memo.swap(memo2);
  }

  //cout << *min_element(memo[W].begin(), memo[W].end()) << endl;
  for (int a=0; a<K; a++) {
    if (memo[W][a]) {
      cout << a << endl;
      break;
    }
  }
  
  

  return 0;
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define sz(x) (int)(x).size()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define EPS (1e-10)
#define equals(a, b) (fabs((a)-(b)) < EPS)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<double> vd;
typedef pair<double,double> PD;
typedef pair<int,P> ed;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
  
int main() {
  int A,B;
  cin >> A >> B;
  if(A+B>=10) {
    cout << "error" << endl;
  } else {
    cout << A+B << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rng(i, a, b) for (int i = int(a); i < int(b); i++)
#define rep(i, b) rng(i, 0, b)
#define gnr(i, a, b) for (int i = int(b) - 1; i >= int(a); i--)
#define per(i, b) gnr(i, 0, b)
#define bg begin()
#define ed end()
#define all(x) x.bg, x.ed
#define vi vector<int>
template <class t, class u>
bool chmax(t &a, u b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}
template <class t, class u>
bool chmin(t &a, u b)
{
    if (b < a)
    {
        a = b;
        return true;
    }
    return false;
}
signed main()
{
    int n;
    cin >> n;
    vector<ll> a(n);
    vector<ll> s(n);
    rep(i, n)
    {
        cin >> a[i];
        if (i == 0)
        {
            s[i] = a[i];
        }
        else
        {
            s[i] = s[i - 1] + a[i];
        }
    }
    ll ans = INT_MAX;
    rep(i, n - 1)
    {
        chmin(ans, abs(s[n - 1] - 2 * s[i]));
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 6360
#include <iostream>
#include <string>
using namespace std;
int w,h;
string str[71];
string mp[71][71];

int check(string a,string b) {
  //  cout << a <<" | "<<b<<endl;
  
  if(a.size() < b.size()) return 1;
  if(a.size() > b.size()) return 2;

  for(int i=0;i<a.size();i++) {
    if(a[i]-'0' < b[i]-'0') return 1;
    if(a[i]-'0' > b[i]-'0') return 2;
  }
  
  return 2;
}

int main() {


  while(1) {
    cin>> w >> h;
    if(w == 0 && h == 0) break;
    for(int i=0;i<h;i++) cin >> str[i];
  
    for(int i=0;i<h;i++)
      for(int j=0;j<w;j++){
	if('0'<=str[i][j] && str[i][j] <='9') mp[i][j] = str[i][j];
	else mp[i][j] = "x";
      }



    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++) {
	if(mp[i][j]=="x") continue;
	string t = mp[i][j];
	int flg = 0;
	if(j-1 >=0 && '0'<=mp[i][j-1][0] && mp[i][j-1][0] <='9' && mp[i][j-1] !="0"){
	  mp[i][j] = mp[i][j-1]+t;
	  //cout <<mp[i][j] <<endl;
	  flg = 1;
	}
	if(i-1 >=0 && '0'<=mp[i-1][j][0] && mp[i-1][j][0] <='9'&&mp[i-1][j] !="0"){
	  if(flg == 1) {
	    if(check(mp[i][j],mp[i-1][j]+t) == 1) mp[i][j] = mp[i-1][j]+t;
	  } else mp[i][j] = mp[i-1][j] + t;
	  // cout << mp[i-1][j]+t<<endl;
	}
      }
    }

    string ans="0";
    for(int i=h-1;i>=0;i--) {
      for(int j=w-1;j>=0;j--) {
	if(mp[i][j] == "x") continue;
	if(check(ans,mp[i][j]) == 1) ans = mp[i][j];
      }
    }

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

Measured memory_bytes: 1432
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
const double EPS = 1e-9;
const ll mod = 1000000007;
const int inf = 1 << 30;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;

#define MAX_V 2020

struct edge{int to; ll cap, cost; int rev; };

int V;
vector<edge> G[MAX_V];
ll h[MAX_V];
ll dist[MAX_V];
int prevv[MAX_V], preve[MAX_V];

void add_edge(int from, int to, ll cap, ll cost){
	G[from].push_back((edge){to, cap, cost, G[to].size()});
	G[to].push_back((edge){from, 0LL, -cost, G[from].size()-1});
}

ll min_cost_flow(int s, int t, ll f){
	ll res = 0;
	fill(h, h+V, 0);
	while(f > 0){	
		priority_queue<pl, vector<pl>, greater<pl> > que;
		fill(dist, dist+V, linf);
		dist[s] = 0;
		que.push(pl(0,s));
		while(!que.empty()){
			pl p = que.top(); que.pop();
			int v = p.second;
			if(dist[v] < p.first) continue;
			for(int i = 0; i < G[v].size(); i++){
				edge &e = G[v][i];
				if(e.cap > 0 && dist[e.to] > dist[v] + e.cost + h[v] - h[e.to]){
					dist[e.to] = dist[v] + e.cost + h[v] - h[e.to];
					prevv[e.to] = v;
					preve[e.to] = i;
					que.push(pl(dist[e.to],e.to));
				}
			}
		}
		if(dist[t] == linf){
			return -1;
		}
		for(int v = 0; v < V; v++) h[v] += dist[v];
		
		ll d = f;
		for(int v = t; v != s; v = prevv[v]){
			d = min(d, G[prevv[v]][preve[v]].cap);
		}
		f -= d;
		res += d*h[t];
		for(int v = t; v != s; v = prevv[v]){
			edge &e = G[prevv[v]][preve[v]];
			e.cap -= d;
			G[v][e.rev].cap += d;
		}
	}
	return res;
}

int n;

int main() {
    ll total = 0;
    cin >> n;
    V = 2*n+10;
    rep(i,n) {
        int x, y, c;
        cin >> x >> y >> c;
        add_edge(2*n, i, c, 0);
        add_edge(i, 2*n+2, inf, 100*(ll)inf - x - y);
        add_edge(i, 2*n+3, inf, 100*(ll)inf - x + y);
        add_edge(i, 2*n+4, inf, 100*(ll)inf + x - y);
        add_edge(i, 2*n+5, inf, 100*(ll)inf + x + y);
        total += c;
    }
    rep(i,4) add_edge(2*n+2+i, 2*n+6+i, inf, 0);
    rep(i,n) {
        int x, y, c;
        cin >> x >> y >> c;
        add_edge(n+i, 2*n+1, c, 0);
        add_edge(2*n+6, n+i, inf, 100*(ll)inf + x + y);
        add_edge(2*n+7, n+i, inf, 100*(ll)inf + x - y);
        add_edge(2*n+8, n+i, inf, 100*(ll)inf - x + y);
        add_edge(2*n+9, n+i, inf, 100*(ll)inf - x - y);
    }
    cout << -1 * (min_cost_flow(2*n, 2*n+1, total) - 200*total*inf) << endl;
}

Measured memory_bytes: 1456
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }
    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int N = scan.nextInt();
        List<Integer> b = new ArrayList<>();
        for (int i = 0; i < N; i++) {
            b.add(scan.nextInt());
        }
        List<Integer> answer = new ArrayList<>();
        while(!b.isEmpty()) {
            int choice = -1;
            for (int i = 1; i <= b.size(); i++) {
                if (i == b.get(i - 1)) {
                    choice = i;
                }
            }
            if (choice == -1) {
                break;
            }
            answer.add(choice);
            b.remove(choice-1);
        }
        if (!b.isEmpty()) {
            System.out.println(-1);
            return;
        }
        for (int i = answer.size(); 1 <= i; i--) {
            System.out.println(answer.get(i-1));
        }

    }
}


Measured memory_bytes: 23764
import numpy as np
import sys
input = sys.stdin.readline

N = int(input())
A = np.array(input().split(), dtype=np.int32)
B = np.array(input().split(), dtype=np.int32)
C = - np.array(input().split(), dtype=np.int32)

A.sort()
B.sort()
C.sort()

cnt_A = np.searchsorted(A,B,side='left')
cnt_C = np.searchsorted(C,-B,side='left')

answer = (cnt_A * cnt_C).sum()
print(answer)


Measured memory_bytes: 26000
from copy import deepcopy
N = int(input())
A = [int(input()) for i in range(N)]

B = deepcopy(A)
B.sort()
odd, even = set(), set()
for i in range(N):
    if i % 2 == 0:
        even.add(B[i])
    else:
        odd.add(B[i])

ans = 0
for i in range(N):
    if i % 2 == 0 and A[i] not in even:
        ans += 1
    if i % 2 == 1 and A[i] not in odd:
        ans += 1

print(ans // 2)


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

using namespace std;
double p[3100];
double dp[3100][3100];


/// dp[ i] [j]   : j is number of heads in tossing i coins
int main()
{
    int a;
    cin>>a;
    for(int i=0;i<a;i++)
    {
        cin>>p[i];
    }

    dp[0][0]=1;
    for(int i=1;i<=a;i++)
    {
        for(int j=0;j<=i;j++)
        {
            if(j)dp[i][j] += dp[i-1][j-1]*p[i-1];   ///probability of head ;
            dp[i][j] += dp[i-1][j] *(1-p[i-1]);   ///probability of tail;
        }
    }
    double sum =0;
    for(int i=0;i<=a;i++)
    {
        if(i>a-i)
        {
            sum+=dp[a][i];
        }
    }
    cout<<setprecision(10)<<sum<<endl;
}


Measured memory_bytes: 72320
import java.util.Scanner

object Main {

  def solve(sc: => Scanner): Unit = {
    sc.nextInt

    val A = Array.fill[Int](sc.nextInt)(sc.nextInt).toSet
    val B = Array.fill[Int](sc.nextInt)(sc.nextInt).toSet
    val C = Array.fill[Int](sc.nextInt)(sc.nextInt).toSet
    println(((B & C) | (C &~ A)).size)
  }

  def main(args: Array[String]): Unit = {
    val sc: Scanner = new Scanner(System.in)
    solve(sc)
  }
}

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

int main() {
	int N, M;
	cin >> N >> M;
	long long S;
	long long ans=0;
	priority_queue<double> P;
	for (size_t i = 0; i < N; i++)
	{
		cin >> S;
		P.push(S);
	}
	for (size_t i = 0; i < M; i++)
	{
		S=P.top()/2;
		P.pop();
		P.push(S);
	}
	for (size_t i = 0; i < N; i++)
	{
		ans += P.top();
		P.pop();
	}
	cout << ans;
 }

Measured memory_bytes: 1400
#include<bits/stdc++.h>
#define rg register
const int N=3000;

using namespace std;

char ans[N][N];
int n,m,a,b,fl=1;

namespace __{
	void solve(){
		//freopen("c.in","r",stdin);
		//freopen("c.out","w",stdout);
		scanf("%d%d%d%d",&n,&m,&a,&b);
		int nn=n,mm=m;
		for(int i=0; i<n; ++i)
			for(int j=0; j<m; ++j)
				ans[i][j]='.';

		if(n&1){			
			for(int i=0; i+1<m; i+=2){
				if(a){
					ans[n-1][i]='<';
					ans[n-1][i+1]='>';--a;
				}
			} --n;
		} else fl=0;
		if(m&1){
			for(int i=0; i+1<n; i+=2){
				if(b){
					ans[i][m-1]='^';
					ans[i+1][m-1]='v';--b;
				}
			} --m;
		} else fl=0;


		if((fl) && (a+(a&1)+b+(b&1)>(n*m)/2)){
		 	++n; ++m;
			ans[n-1][m-3]=ans[n-3][m-2]='<';
			ans[n-1][m-2]=ans[n-3][m-1]='>';
			ans[n-3][m-3]=ans[n-2][m-1]='^';
			ans[n-2][m-3]=ans[n-1][m-1]='v';
			--n;--m;a-=1;b-=1;
		}

		for(int i=0; i<n; i+=2)	
			for(int j=0; j<m; j+=2)if(ans[i][j]=='.'){
				if(a){
					a--;
					ans[i][j]='<';
					ans[i][j+1]='>';
					if(a){
						ans[i+1][j]='<';
						ans[i+1][j+1]='>';
						--a;
					}
				}
				else if(b){
					b--;
					ans[i][j]='^';
					ans[i+1][j]='v';
					if(b){
						ans[i][j+1]='^';
						ans[i+1][j+1]='v';
						--b;
					}
				}
			}
		if(!(a|b)){
			puts("YES");
			for(rg int i=0; i<nn; ++i) puts(ans[i]);
		}
		else{
			puts("NO");
		}
	}
}
int main(){
	__::solve();
}

Measured memory_bytes: 5248
n,m=map(int,input().split())
e=[[] for _ in range(n)]
b=[]

for i in range(m):
  x,y=map(int,input().split())
  e[x-1].append(y-1)
  e[y-1].append(x-1)
  b.append([x-1,y-1])

def ne(now,s,visit):
  visit.append(now)
  for i in e[now]:
    if i not in visit:
      ne(i, s, visit[:])
    elif len(visit)>2 and s==i:
      v1=visit[1]
      v2=visit[-1]
      if [s,v1] in b: b.remove([s,v1])
      elif [v1,s] in b: b.remove([v1,s])
      if [s,v2] in b:b.remove([s,v2])
      elif [v2,s] in b:b.remove([v2,s])
      break

for i in range(n):
  ne(i,i,[])
print(len(b))

Measured memory_bytes: 59612
import math
N = int(input())


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

A.sort()
ans = 0
flag = True
if N % 2 == 1:
  # 0,2,2,4,4,～みたいに並んでるはず
  if A[0] == 0:
    for i in range(1,N,2):
      if A[i] != i+1 or A[i+1] != i+1:
        flag = False
        break
  
    if flag: ans = 2**(N//2) % (10**9 + 7)

else:
  if A[0] != 0:
    for i in range(0,N,2):
      if A[i] != i+1 or A[i+1] != i+1:
        flag = False
        break
  
    if flag: ans = 2**(N//2) % (10**9 + 7)
    
    
    
print(ans)
    

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

int main(){
	int f = 0;
	string S, T, U;
	cin>>S>>T;
	for(int i =0; i <= S.size(); i++){
		U = "";
		if(S==T){f=1;break;}
		for(int j =0; j < S.size(); j++){
			U  += S[(S.size()+j-1)%S.size()];
		}
		S = U;
	}
	if(f)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
import java.io.*;
import java.math.*;
import java.util.*;
public class Main { 
 
	public static void main(String[] args) { 
		FastScanner I = new FastScanner(); //Input
		OutPut O = new OutPut(); //Output
		int R = I.nextInt();
		int C = I.nextInt();
		int K = I.nextInt();
		int Bl = 0;
		int ans = 0;
		char[][] grid = new char[R][C];
		for (int r = 0; r < R; r++) {
			grid[r] = I.next().toCharArray();
			for (int i = 0; i < C; i++) if (grid[r][i]=='#') Bl++;
		}
		for (int rnum = 0; rnum < (2<<R); rnum++) {
			int curK = Bl;
			boolean[]vis = new boolean[R];
			for (int row = 0; row < R; row++) {
				if ((rnum>>row)%2==1) {
					for (int c = 0; c < C; c++) {
						vis[row]=true;
						if (grid[row][c]=='#') curK--;
					}
				}
			}
			if (curK>=K) {
				int temp = curK;
				for (int cnum = 0; cnum < (2<<C); cnum++) {
					for (int col = 0; col < C; col++) {
						if ((cnum>>col)%2==1) {
							for (int r = 0; r < R; r++) {
								if (!vis[r]&&grid[r][col]=='#') temp--;
							}
						}
					}
					if (temp==K) ans++;
					temp=curK;
				}
			}	
		}
		O.pln(ans/4);
	}
	public static ArrayList<String> recur(int N){
		ArrayList<String> ret = new ArrayList<String>();
		if (N==1) {
			for (int i = 0; i <= N; i++) {
				ret.add(Integer.toString(i)+" ");
			}
			return ret;
		}
		ArrayList<String> prev = recur(N-1);
		for (int i = 0; i < prev.size(); i++) {
			String S = prev.get(i);
			String[] cur = prev.get(i).split(" ");
			int cmp = Integer.parseInt(cur[cur.length-1]);
			for (int j = cmp; j <= N; j++) {
				ret.add(S+Integer.toString(j)+" ");
			}
		}
		return ret;
	}
	public static long ceil(long num, long den) {long ans = num/den; if (num%den!=0) 
	ans++; return ans;}
	public static long GCD(long a, long b) {
		if (a==0||b==0) return Math.max(a,b);
		return GCD(Math.min(a, b),Math.max(a, b)%Math.min(a, b));
	}
	public static long FastExp(long base, long exp, long mod) {
		long ans=1;
		while (exp>0) {
			if (exp%2==1) ans*=base;
			exp/=2;
			base*=base;
			base%=mod;
			ans%=mod;
		}
		return ans;
	}
	public static long ModInv(long num,long mod) {return FastExp(num,mod-2,mod);}
	static class FastScanner {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer("");
		String next() {
			while (!st.hasMoreTokens())
				try {
					st=new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
		}
		int nextInt() {return Integer.parseInt(next());}
		long nextLong() {return Long.parseLong(next());};
	}
	static class OutPut{
		PrintWriter w = new PrintWriter(System.out);
		void pln(int x) {w.println(x);w.flush();}
		void pln(long x) {w.println(x);w.flush();}
		void pln(String x) {w.println(x);w.flush();}
		void pln(char x) {w.println(x);w.flush();}
		void pln(StringBuilder x) {w.println(x);w.flush();}
		void p(int x) {w.print(x);w.flush();}
		void p(long x) {w.print(x);w.flush();}
		void p(String x) {w.print(x);w.flush();}
		void p(char x) {w.print(x);w.flush();}
		void p(StringBuilder x) {w.print(x);w.flush();}
	}
}

Measured memory_bytes: 26816
#include <iostream>
#include <vector>
#include <map>
#include <stack>
#include <list>
#include <queue>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <math.h>

#define PREP(i, m, n) for(int i = m; i < n; i++)
#define MREP(i, m, n) for(int i = m - 1; i >= n; i--)

#define rep(i, n) for(int i = 0; i < (n); i++)
#define FOR(i, a, b) for(int i = a; i < b; i++)
#define all(v) v.begin(), v.end()
#define rev(v) v.rbegin(), v.rend()
#define X first
#define Y second
#define MP make_pair
#define PB push_back

using namespace std;



int main(){
	vector<int>  stairs;
	stairs.push_back(1);
	stairs.push_back(1);
	stairs.push_back(2);
	
	for(int i = 3; i < 31; i++){
		int tmp = stairs[i - 1] + stairs[i - 2] + stairs[i - 3];
		stairs.push_back(tmp);
	}

	int n = 0;
	while(cin >> n && n != 0){
		int tmp = 0;
		if(stairs[n] / 10 == 0) tmp = 1;
		else tmp = stairs[n] / 10;
		if(tmp % 365 == 0){
			cout << tmp / 365 << endl;
		}
		else{
			cout << tmp / 365 + 1 << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 1216
#include <iostream>
#include <string>
#include <vector>
#include <algorithm> 
#include <utility> 
#include <tuple> 
#include <cstdint> 
#include <cstdio> 
#include <map> 
#include <queue> 
#include <set> 
#include <stack> 
#include <deque> 
#include <unordered_map> 
#include <unordered_set> 
#include <bitset> 
#include <cctype> 
#include <cmath>
#include <iomanip>
#include <ctype.h>

using namespace std;
using ll = long long;
using PAIR = pair<int, int>;
using PAIRLL = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;

#define TR ","
#define fi first
#define se second
#define rep(i,N) for(int i=0;i<(int)N;++i)
#define all(v) v.begin(), v.end()
#define IO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)

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

ll lcm(ll x, ll y) {
    return x / gcd(x, y) * y;
}

ll waz = 76543217;

ll inv(ll x) {
    if (x == 1) { return 1; }
    if (x == 0) { return 0; }
    else {
        ll a = (waz - inv(waz % x) * (waz / x)) % waz;
        if (a >= 0) { return a; }
        else { return waz + a; }
    }
}

void printVector(const vector<int>& vec) {
    for (int value : vec) {
        cout << value << " ";
    }
    cout << endl;
}

vector<ll> p;

ll phi(ll x) {
    ll a = x;
    ll b = x;
    for (ll k = 0; k != p.size(); ++k) {
        if (a % p[k] == 0) {
            while (a % p[k] == 0) {
                a /= p[k];
            }
            b = b / p[k] * (p[k] - 1);
        }
        if (a == 1) { break; }
    }
    return b;
}

bool my_compare(pair<string, int> a, pair<string, int> b) {
    if (a.first != b.first) {
        return a.first < b.first;
    }

    if (a.second != b.second) {
        return a.second > b.second;
    }
    else {
        return true;
    }
}

int main()
{
    IO;

    ll A, B, C, D, E;
    vector<ll> F(3), G(3), H(3);
    cin >> A >> B >> C >> D;
    E = lcm(C, D);
    F[0] = (A - 1) / C;
    G[0] = B / C;
    H[0] = G[0] - F[0];
    F[1] = (A - 1) / D;
    G[1] = B / D;
    H[1] = G[1] - F[1];
    F[2] = (A - 1) / E;
    G[2] = B / E;
    H[2] = G[2] - F[2];
    cout << B - A + 1 - (H[0]+H[1]-H[2]) << endl;
}

Measured memory_bytes: 256