akhauriyash/Code-Regression huggingface dataset:
// C
 #ifndef _GLIBCXX_NO_ASSERT
 #include <cassert>
 #endif
 #include <cctype>
 #include <cerrno>
 #include <cfloat>
 #include <ciso646>
 #include <climits>
 #include <clocale>
 #include <cmath>
 #include <csetjmp>
 #include <csignal>
 #include <cstdarg>
 #include <cstddef>
 #include <cstdio>
 #include <cstdlib>
 #include <cstring>
 #include <ctime> 
 #ifdef __GXX_EXPERIMENTAL_CXX0X__
 #include <ccomplex>
 #include <cfenv>
 #include <cinttypes>
 #include <cstdbool>
 #include <cstdint>
 #include <ctgmath>
 #include <cwchar>
 #include <cwctype>
 #endif
 
 // C++
 #include <algorithm>
 #include <bitset>
 #include <complex>
 #include <deque>
 #include <exception>
 #include <fstream>
 #include <functional>
 #include <iomanip>
 #include <ios>
 #include <iosfwd>
 #include <iostream>
 #include <istream>
 #include <iterator>
 #include <limits>
 #include <list>
 #include <locale>
 #include <map>
 #include <memory>
 #include <new>
 #include <numeric>
 #include <ostream>
 #include <queue>
 #include <set>
 #include <sstream>
 #include <stack>
 #include <stdexcept>
 #include <streambuf>
 #include <string>
 #include <typeinfo>
 #include <utility>
 #include <valarray>
 #include <vector> 
 #ifdef __GXX_EXPERIMENTAL_CXX0X__
 #include <array>
 #include <atomic>
 #include <chrono>
 #include <condition_variable>
 #include <forward_list>
 #include <future>
 #include <initializer_list>
 #include <mutex>
 #include <random>
 #include <ratio>
 #include <regex>
 #include <system_error>
 #include <thread>
 #include <tuple>
 #include <typeindex>
 #include <type_traits>
 #include <unordered_map>
 #include <unordered_set>
 #endif
using namespace std;
const long long MOD = 1000000007;

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

int main(){
    int m,n;
    cin >> m >> n;
    cout << modpow(m,n,MOD) << endl;
    return 0;
}


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

const int N = 1e5 + 7;
const int L = 17;

int go[N][L];

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    vector <int> x(n);
    for (int i = 0; i < n; i++) {
        cin >> x[i];
    }
    int l;
    cin >> l;
    vector <int> who(n);
    int ptr = n - 1;
    for (int i = n - 1; i >= 0; i--) {
        while (ptr > i && x[ptr] - x[i] > l) ptr--;
        who[i] = ptr;
    }
    for (int i = n - 1; i >= 0; i--) {
        go[i][0] = who[i];
        for (int j = 1; j < L; j++) {
            go[i][j] = go[go[i][j - 1]][j - 1];
        }
    }
    int q;
    cin >> q;
    while (q--) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        if (a > b) swap(a, b);
        int pos = a;
        int res = 0;
        for (int i = L - 1; i >= 0; i--) {
            if (go[pos][i] < b) {
                pos = go[pos][i];
                res += (1 << i);
            }
        }
        cout << res + 1 << '\n';
    }
    return 0;
} 

Measured memory_bytes: 8320
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c,n,t,i,j,flag=0;
    string s,s1="",s2="";
    cin>>t;
    cin>>s;

    for(i=0;i<s.size();i++)
    {
        if(i<=(t/2)-1)
            s1+=s[i];
        else
            s2+=s[i];
    }

   if(s1==s2)
    cout<<"Yes"<<"\n";
   else
    cout<<"No"<<"\n";

return 0;
}


Measured memory_bytes: 256
from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations # (string,3) 3回
from collections import deque
from collections import defaultdict
import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
S = input()
for i in range(0,len(S),2):
    if S[i:i+2] == 'hi':
        pass
    else:
        print('No')
        exit()
print('Yes')


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

#define INF INT_MAX
#define MOD 1000000007
#define REP(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()

typedef long long ll;
typedef std::pair<int,int> pii;

using namespace std;

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

    int n;
    int a[1005];
    cin >> n;
    REP(i,n)cin >> a[i];
 
    double ans = 0;

    REP(i,n)ans += 1.0 / (double)a[i];
    ans = 1.0 / ans;

    printf("%.5lf\n",ans);
    return 0;
}    

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


int main(){
  int n,i;
  long long sum;
  cin >> n;
  sum=0;
  vector<int> a(n+1);
  vector<int> b(n);
  for(i=0;i<n+1;++i){
    cin >> a[i];
  }
  for(i=0;i<n;i++){
    cin >> b[i];
  }
  for(i=0;i<n;++i){
    int left;
    left = min(a[i],b[i]);
    sum += left;
    a[i] -= left;
    b[i] -= left;

    int right;
    right =min(a[i+1],b[i]);
    sum += right;
    a[i+1] -= right;
    b[i] -= right;
  }
  cout << sum << endl;
}


Measured memory_bytes: 1024
#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 maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#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 bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
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;
inline int in() { int x; scanf("%d",&x); return x;}
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
#define dame { puts("-1"); return 0;}
#define yn {puts("YES");}else{puts("NO");}
  
int main() {
  string s;
  cin >> s;
  rep(i,1<<3) {
    int n = s[0] - '0';
    rep(j,3) {
      if(i>>j&1) {
        n += s[j+1] - '0';
      } else {
        n -= s[j+1] - '0';
      }
    }
    if(n == 7) {
      rep(j,3) {
        cout << s[j];
        if(i>>j&1){
          cout << '+';
        } else {
          cout << '-';
        }
      }
      cout << s[3] << "=7" << endl;
      return 0;
    }
  }
  return 0;
}

Measured memory_bytes: 256
import itertools as itr

def main():
	N, Y = map(int, input().split())

	for a, b in itr.product(range(N+1), repeat = 2):
		c = N - a - b
		if c >= 0 and 10000*a + 5000*b + 1000*c == Y:
			print(str(a) + " " + str(b) + " " + str(c))
			return
	print("-1 -1 -1")
	return


main()



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

int main(){
	int a,b,c,d,e,f;
	while(1){
		cin >> a >> b >> c >> d >> e >> f;
		if(a + b + c + d + e + f == 0) break;
		a += d;
		b += e;
		c += f;
		int ma = 0;
		for(int i = 0;i < 3;i++){
			ma = max(ma,i + a / 3 + b / 3 + c / 3);
			a--;
			b--;
			c--;
			if(a < 0 || b < 0 || c < 0) break;
		}
		cout << ma << endl;
	}
	return 0;
}

Measured memory_bytes: 2984
import java.util.*;
import javax.lang.model.util.ElementScanner6;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        // 入力
        int h = sc.nextInt();
        int a = sc.nextInt();

        // 処理
        int out = 0;
        int count = h / a;
        out = count + ((h % a) != 0 ? 1 : 0);

        // 出力
        System.out.println(out);
    }
}

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

typedef unsigned int ui;
typedef long long ll;
typedef unsigned long long ull;
#define SZ(a) int((a).size())
#define _REP(_1,_2,_3,_4,name,...) name
#define _REP4(i,b,e,s) for(decltype(e) _b=(b),_e=(e),i=_b+(0<(s)?0:(s));(0<(s)?i<_e:_e<=i);i+=(s))
#define _REP3(i,b,e) for(decltype(e) _b=(b),_e=(e),i=(_b<_e?_b:_b-1);(_b<_e?i<_e:_e<=i);(_b<_e?i++:i--))
#define _REP2(i,n) for(decltype(n) i=0,_n=(n);i<_n;i++)
#define _REP1(n) for(decltype(n) _i=0,_n=(n);_i<_n;_i++)
#define REP(...) _REP(__VA_ARGS__,_REP4,_REP3,_REP2,_REP1)(__VA_ARGS__)
#define FOR(it,c) for(auto&& it=begin(c);it!=end(c);it++)
#define ROF(it,c) for(auto&& it=rbegin(c);it!=rend(c);it++)
#define EB emplace_back
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define INT(n) int n;assert(0<scanf("%d",&n))
#define STR(s) string s;cin>>s

int main(){
  INT(h); INT(w); INT(k);
  string s; vector<string> ss;
  REP(h){cin >> s; ss.PB(s);}
  int ans = h * w;
  REP(i, 1 << (h - 1)){
    int tmp, mx = 0, cnt, sz;
    vector<vector<int>> vv;
    REP(j, w){
      tmp = i;
      cnt = 0;
      sz = 0;
      vector<int> v;
      REP(c, h){
        if (ss[c][j] == '1'){cnt++;}
        if (tmp & 1 || c == h - 1){v.PB(cnt); mx = max(mx, cnt); cnt = 0; sz++;}
        tmp >>= 1;
      }
      vv.PB(v);
    }
    if (k < mx){continue;}
    vector<int> v;
    REP(sz){v.PB(0);}
    cnt = sz - 1;
    REP(j, w){
      REP(c, sz){v[c] += vv[j][c];}
      bool ok = true;
      REP(c, sz){if (k < v[c]){ok = false; break;}}
      if (!ok){
        REP(c, sz){v[c] = vv[j][c];}
        cnt++;
      }
    }
    ans = min(ans, cnt);
  }
  printf("%d\n", ans);
  return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define fori(i,a,n) for(i=a;i<=n;i++)
#define ford(i,n,a) for(i=n;i>=a;i--)
typedef long long ll;
typedef double db;
typedef long double ld;
typedef unsigned long long ull;
const int p=1e9+7;
ll n,a,b,ans;
void exgcd(ll a,ll b,ll &x,ll &y)
{
    ll t;
    if (b==0) 
     {
     	x=1; y=0;
     }
    else 
    {
    	exgcd(b,a%b,x,y);
    	t=x; x=y; y=t-(a/b)*y;
    }
}
ll c(ll x,ll y)
{
	ll i,k,t,xx,yy;
	k=1;
	for (i=y;i>=y-x+1;i--)
	{
		k=k*i%p;
		k=(k+p)%p;
	}
	t=1;
	for (i=x;i>=1;i--)
	{
		t=t*i%p;
		t=(t+p)%p;
	}
	exgcd(t,p,xx,yy);
	return (xx*k%p+p)%p;
}
ll lucas(ll n,ll m)
{
	if (m==0) return 1;
	else return c(n%p,m%p)*lucas(n/p,m/p)%p;
}
ll qpow(ll x,ll y)
{
    ll t;
    if (y==1) return x%p;
    if (y==0) return 1;
    t=qpow(x,y/2);
    t=t*t%p;
    if (y%2==0) return t;
    else return t*x%p;
}
int main()
{
	cin>>n>>a>>b;
	ans=qpow(2,n)%p-1;
	cout<<((ans-lucas(a,n)-lucas(b,n))%p+p)%p<<endl;
}

Measured memory_bytes: 256
#include <iostream>


using namespace std;


int main(void){
    int a,b,c;
    cin>>a>>b>>c;
    if(a==b){
        cout<<c<<endl;
    }else if(b==c){
        cout<<a<<endl;
    }else{
        cout<<b<<endl;
    }
    return 0;
}


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

const int mod = 1e9 + 7, N = 1e5 + 10;

ll pw(ll a, ll b) {
    ll r = 1;
    for( ; b ; b >>= 1, a = a * a % mod) {
        if(b & 1) {
            r = r * a % mod;
        }
    }
    return r;
}

ll getinv(ll n) {
    return pw(n, mod - 2);
}

ll n, x, l[N];

int main() {
	ll d = 0;
	cin >> n >> x;
	int ans = d <= x;
	for(int i = 1 ; i <= n ; ++ i) {
		int y; cin >> y;
		d += y;
		ans += d <= x;
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef pair< int , int > P;
typedef pair< int , P > PP;

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

int ey[]={-1,-1,0,1,2,2,1,0};
int ex[]={0,1,2,2,1,0,-1,-1};


int H,W;
char t[50][50];
int sy,sx;
int py0,px0,py1,px1;



int d[50][50];

int calc(int gy,int gx,int sy,int sx,int ty,int tx,bool flg=false){
  for(int i=0;i<H;i++)
    for(int j=0;j<W;j++)
      d[i][j]=1e8;
  d[sy][sx]=0;
  
  queue<int> qy,qx;
  qy.push(sy);
  qx.push(sx);
  while(!qy.empty()){
    int y=qy.front();qy.pop();
    int x=qx.front();qx.pop();
    if(y==ty&&x==tx)break;
    for(int i=0;i<4;i++){
      int ny=y+dy[i];
      int nx=x+dx[i];
      if(ny<0||nx<0)continue;
      if(ny>=H||nx>=W)continue;
      if(t[ny][nx]=='*')continue;
      if(gy<=ny&&ny<gy+2&&gx<=nx&&nx<gx+2)continue;
      if(d[ny][nx]>d[y][x]+1){
        d[ny][nx]=d[y][x]+1;
        qy.push(ny);
        qx.push(nx);
      }
    }
  }
  
  return d[ty][tx];
}

int dd[50][50][4];
int solve(int sy,int sx,int sd){
  for(int i=0;i<H;i++)
    for(int j=0;j<W;j++)
      for(int k=0;k<4;k++)
        dd[i][j][k]=1e8;

  dd[sy][sx][sd]=0;
  priority_queue< PP , vector<PP> , greater<PP> > Q;
  Q.push( PP(0, P(sy*50+sx,sd) ) );

  while(!Q.empty()){
    PP pp = Q.top();Q.pop();
    int y=pp.second.first/50;
    int x=pp.second.first%50;
    int dir=pp.second.second;
    if(y==0&&x==0)return dd[y][x][dir];
    if(pp.first > dd[y][x][dir])continue;
    
    for(int i=0;i<4;i++){
      int ncost=dd[y][x][dir];
      int ay=y+ey[i*2],ax=x+ex[i*2];
      int by=y+ey[i*2+1],bx=x+ex[i*2+1];
      int flg=(dir+2)%4;
      int Ay=y+ey[flg*2],Ax=x+ex[flg*2];
      int By=y+ey[flg*2+1],Bx=x+ex[flg*2+1];
      int ny=y+dy[i],nx=x+dx[i];
      if(ay<0||ax<0||ay>=H||ax>=W)continue;
      if(by<0||bx<0||by>=H||bx>=W)continue;
      if(t[ay][ax]=='*'||t[by][bx]=='*')continue;
      
      ncost+=min( calc(y,x,ay,ax,Ay,Ax)+calc(y,x,by,bx,By,Bx) ,
                  calc(y,x,ay,ax,By,Bx)+calc(y,x,by,bx,Ay,Ax) );

      ncost++;
      if(dd[ny][nx][i]>ncost){
        dd[ny][nx][i]=ncost;
        Q.push(PP(ncost,P(ny*50+nx,i)));
        
      }
    }
  }
  return 1e8;
}

int main(){
  while(1){
    cin>>H>>W;
    if(H==0&&W==0)break;
    
    sy=sx=-1;
    py0=px0=-1;
    py1=px1=-1;
    
    for(int i=0;i<H;i++){
      for(int j=0;j<W;j++){
        cin>>t[i][j];
        if(t[i][j]=='X'&&sy==-1&&sx==-1){
          sy=i;
          sx=j;
        }
        if(t[i][j]=='.'){
          py0=py1;
          px0=px1;
          py1=i;
          px1=j;
        }
      }
    }
    
    int ans=1e9;
    if(sy==0&&sx==0)ans=0;
    
    for(int i=0;i<4;i++){
      int ay=sy+ey[i*2],ax=sx+ex[i*2];
      int by=sy+ey[i*2+1],bx=sx+ex[i*2+1];
      if(ay<0||ax<0||by<0||bx<0)continue;
      if(ay>=H||ax>=W||by>=H||bx>=W)continue;
      if(t[ay][ax]=='*'||t[by][bx]=='*')continue;
      int cost=min(   calc(sy,sx,py0,px0,ay,ax) + calc(sy,sx,py1,px1,by,bx)
                    , calc(sy,sx,py0,px0,by,bx) + calc(sy,sx,py1,px1,ay,ax) );

      ans=min(ans,cost+solve(sy,sx,(i+2)%4));
    }
    if(ans>=1e8)ans=-1;
    cout<<ans<<endl;
  }
  return 0;
}

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

#define print2(a, b) cerr << "(" << a << "," << b << ")" << endl
#define print3(a, b, c) cerr << "(" << a << "," << b << "," << c << ")" << endl


void solve(long long N, std::vector<long long> A){
    multiset<ll> s;
    s.insert(A[0]);
    for (int i = 1; i < N; i++) {
        auto it = s.lower_bound(A[i]);
        if (it == s.begin())
            s.insert(A[i]);
        else {
            it--;
            s.erase(it);
            s.insert(A[i]);
        }
    }
    cout << s.size() << endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> A(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&A[i]);
    }
    solve(N, std::move(A));
    return 0;
}


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

int main(){
    int H, N;
    cin >> H >> N;
    int total = 0;

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

    //cout << total << endl;

    if(total >= H){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }

    
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
const int N=1<<18;
string a[N];

int main()
{
	string str;
	cin>>str;
	int k;
	scanf("%d",&k);
	int n=0;
	for(int i=0;i<str.size();i++)
	{
		for(int j=1;j<6 && i+j<=str.size();j++)
		{
			a[n++]=str.substr(i,j);
		}
	}
	sort(a,a+n);
	n=unique(a,a+n)-a;
	cout<<a[k-1]<<endl;
	return 0;
}

Measured memory_bytes: 3456
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, D, X;
  cin >> N >> D >> X;
  vector<int> A(N);
  int ans = 0;
  for(int i = 0; i < N; i++) {
    cin >> A.at(i);
    ans += ((D - 1) / A.at(i) + 1);
  }
  cout << ans + X << endl;
}

Measured memory_bytes: 3600
#include "bits/stdc++.h"
using namespace std;
int main() {
	long long A, B, C;
	cin >> A >> B >> C;
	long long ans = 0, num = 0;
	while (num < C) {
		ans++;
		num += A;
		if (ans % 7 == 0) num += B;
	}
	cout << ans << endl;
}


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

using ll = long long;

template<typename T>
T gcd(T a, T b)
{
	if (a < b)	return gcd(b, a);
	T r;
	while ((r = a % b))
	{
		a = b;
		b = r;
	}
	return b;
}

template<typename T>
T lcm(T a, T b)
{
	return a * b / gcd(a, b);
}

template<typename T>
T ext_gcd(T a, T b, T& x, T& y)
{
	x = 1;
	y = 0;
	T x0 = 0, y0 = 1;
	while (b != 0)
	{
		T q = a / b;
		a -= q * b;
		swap(a, b);
		x -= q * x0;
		swap(x, x0);
		y -= q * y0;
		swap(y, y0);
	}
	return a;
}

template<typename T>
T inv_mod(T a, T mod)
{
	T t1, t2;
	ext_gcd(a, mod, t1, t2);
	t1 %= mod;
	if (t1 < 0)		t1 += mod;
	return t1;
}

template<typename T>
T combination_large(T n, T k, T mod)
{
	if (n < k || n < 0 || k < 0)	return 0;
	vector<T> inv(n + 1, 1), fact(n + 1, 1), fact_inv(n + 1, 1);
	for (T i = 2; i <= n; ++i)
	{
		inv[i] = mod - inv[mod % i] * (mod / i) % mod;
		fact[i] = (fact[i - 1] * i) % mod;
		fact_inv[i] = fact_inv[i - 1] * inv[i] % mod;
	}
	return fact[n] * (fact_inv[k] * fact_inv[n - k] % mod) % mod;
}

template<typename T>
T combination(T n, T k, T mod = 1)
{
	vector<vector<T>> table(n + 1, vector<T>(k + 1, 1));
	for (T i = 1; i <= n; ++i)
	{
		table[i][0] = 1;
		for (T j = 1; j <= n; ++j)
		{
			table[i][j] = (table[i - 1][j - 1] + table[i - 1][j]) % mod;
		}
	}
}


int main(int, char**)
{
	long long H;
	scanf("%lld",&H);

	ll sum = 0;
	ll es = 1;
	ll h = H;
	while (h > 1) {
		sum += es;
		es = es << 1;
		h = h >> 1;
	}
	sum += es;
	cout << sum << endl;

	return 0;
}


Measured memory_bytes: 256
class UnionFind():
    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 = 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())

n,m = map(int,input().split())
uf = UnionFind(n)
bridges = []
for i in range(m):
    ai,bi = map(int,input().split())
    bridges.append((ai,bi))
bridges = bridges[::-1]
ans = n*(n-1)//2
answers = [ans]
for i in range(m):
    x,y = bridges[i][0]-1,bridges[i][1]-1
    if not uf.same(x,y):
        ans -= uf.size(x) * uf.size(y)
    answers.append(ans)
    uf.union(x,y)
answers = answers[::-1]
for i in range(1,m+1):
    print(answers[i])

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

int main() {
  double pi = 3.141592653589793238;
  double x;
  scanf("%lf",&x);
  printf("%.12lf\n", 2.0*x*pi);
}


Measured memory_bytes: 3788
#include<bits/stdc++.h>
#include<string.h>
#define pb push_back
#define all(v) v.begin(),v.end()
#define see(x) cout<<#x<<" : "<<(x)<<endl;
#define ya cout<<"YES"<<endl;
#define no cout<<"NO"<<endl;
#define ff first
#define sc second
typedef long long ll;
using namespace std;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL),cout.tie(NULL);
    //freopen("test.txt","r",stdin);
    ll a,b,v,w,i,j,t;
    cin>>a>>v>>b>>w>>t;
    i=b+(w*t);
    j=a+(t*v);
    if(a<b)
    {
        if(j>=i)
        {
            ya
            return 0;
        }
    }
    else
    {
        i=b-(w*t);
        j=a-(t*v);
        if(j<=i)
        {
            ya
            return 0;
        }
    }
    no
    return 0;
}


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

bool IsPrime(int n) {
	for (int i = 2; i * i <= n; i++) {
		if(n % i == 0) {
            		return false;
		}
	}
	return true;
}

int main(void) {
	int count = 0, n;
	cin >> n; 
	for (int i = 0; i < n; i++) {
   		int p;
		cin >> p;
		if (IsPrime(p)) {
			count++;
			}
	}
	cout << count << endl;
	return 0;
}


Measured memory_bytes: 3088
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define sz(x) (int)(x.size())

const int N = 54;
int a[N], dp[N][N * N] = {0};

signed main() {
    int n, A;
    cin >> n >> A;
    for(int i = 1; i <= n; i++) {
        cin >> a[i];
    }

    dp[0][0] = 1;
    for(int i = 1; i <= n; i++) {
        for(int j = i - 1; j >= 0; j--) {
            for(int k = 0; k < N * N; k++) {
                dp[j + 1][a[i] + k] += dp[j][k];
            }
        }
    }
    int ans = 0;
    for(int k = 1; k <= n; k++) {
        ans += dp[k][k * A];
    }
    cout << ans << "\n";
}


Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
/*#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
/*template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
*/typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll,ll> pl;
typedef pair<int,int> pii;

#define int ll
#define LOCAL 0
#define dbg(x) cout << #x << " is " << x << "\n"
#define gll(x) scanf("%d",&x)
#define gll2(x,y) scanf("%d%d",&x,&y)
#define gll3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define gllarr(arr,n) f(i,n) gll(arr[i]);
#define sz(x) ((int)x.size())
#define s(x) sort(x.begin(),x.end())
#define all(v) v.begin(),v.end()
#define rs(v) { s(v) ; r(v) ; }
#define r(v) {reverse(all(v));}
#define pb push_back
#define f(i,n) for(int i=0;i<n;i++)
#define fr(i,n) for(int i=n-1;i>=0;i--)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,a,b) for(int i=a;i>=b;i--)

const ll mod = (ll)1e9 + 7;
const ll inf = (ll)1e16;
const ld eps = 1e-12;
const ll N = (int)1e5 + 5;
const ll LOGN = 19;
const ld PI = 3.14159265358979323846;
inline ll mul(ll a, ll b, ll m = mod) { return (ll)(a * b) % m;}
inline ll add(ll a, ll b, ll m = mod) { a += b; if(a >= m) a -= m; if(a < 0) a += m; return a;}
inline ll power(ll a, ll b, ll m = mod) { if(b == 0) return 1; if(b == 1) return (a % m); ll x = power(a, b / 2, m); x = mul(x, x, m); if(b % 2) x = mul(x, a, m); return x;}

void solve() {
    int n, k;
    cin>>n>>k;
    cout<<min(n % k, abs(k - (n % k)));
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    if (LOCAL) {
        freopen("C:\\Users\\Dishant\\Desktop\\Collection-DEV c++\\input.txt", "r", stdin);
        freopen("C:\\Users\\Dishant\\Desktop\\Collection-DEV c++\\output.txt", "w", stdout);
    }
    int t = 1;
    //cin>>t;
    for(int tests = 1; tests <= t; tests++) {
        //cout<<"Case #"<<tests<<": ";
        solve();
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
typedef int long long ll;
using namespace std;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int main(){
    ll n,x;
    cin>>n>>x;
    vector<ll> v(n);
    rep(i,n){
        cin>>v[i];
    }
    sort(v.begin(),v.end());
    int ans=0;
    rep(i,n){
        x-=v[i];
        if(x==0){
            cout<<i+1<<endl;return 0;
        }else if(x<0){
            cout<<i<<endl;return 0;
        }
    }
     if(x>0){
        cout<<n-1<<endl;
    }
  
  
    
  
return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pp;
const int INF = 1e9;
const int MOD = 1000000007;
#define rep(i,n) for(int i=0;i<n;i++)
 
int main() {
  ll n,m;
  cin >> n >> m;
  vector<ll> A(n);
  vector<ll> cum(n+1,0);
  rep(i,n) cin >> A.at(i);
  rep(i,n) cum.at(i+1) = (cum.at(i) + A.at(i))%m;
  map<ll,ll> Mer;
  rep(i,n+1) Mer[cum.at(i)] ++;
  ll ans = 0;
  for(auto i:Mer){
    ans += i.second*(i.second-1)/2;
    //cout << i.first << endl;
  }
  cout << ans << endl;
    
  return 0;
}




Measured memory_bytes: 5760
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
//var input = Console.ReadLine().Split().Select(int.Parse).ToArray();
namespace AtCoderSolve
{
    class Solve
    {
        const int mod = 1000000007;
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            var a = Console.ReadLine().Split().Select(int.Parse).ToArray();
            Array.Sort(a);
            Console.WriteLine(a[2] - a[0]);

            Console.Out.Flush();
        }
    }
    


    public class Calculation
    {
        
    }

    public class Graph
    {

    }
}
    

Measured memory_bytes: 13396
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define ll long long
#define pb push_back
#define mp make_pair
bool isPrime(ll n) 
{ 
    
    if (n <= 1)  return false; 
    if (n <= 3)  return true; 
   
    if (n%2 == 0 || n%3 == 0) return false; 
  
    for (ll i=5; i*i<=n; i=i+6) 
        if (n%i == 0 || n%(i+2) == 0) 
           return false; 
  
    return true; 
} 
ll minthis(ll a, ll b){
if(a < b){
return a;
}
return b;
}
ll maxthis(ll a, ll b){
if(a > b){
return a;
}
return b;
}
int gcd(int a, int b){
    if( a<0 ) a = -a;
    if( b<0 ) b = -b;
    while( b!=0 ){
        a %= b;
        if( a==0 ) return b;
        b %= a;
    }
    return a;
}
 
int findLargestDivisor(int n) 
{ 
	int max = 1;
    for (int i = 2; i < n; i++) {        
        if(n %(i) == 0) { 
            max = i;
        } 
    }
    return max;     
} 
	 
 
ll power(ll x, ll y)  
{  
    ll temp;  
    if(y == 0)  
        return 1;  
    temp = power(x, y / 2);  
    if (y % 2 == 0)  
        return temp * temp;  
    else
    {  
        if(y > 0)  
            return x * temp * temp;  
        else
            return (temp * temp) / x;  
    }  
} 
bool sortbysec(const pair<int, int>& a, 
               const pair<int, int>& b) 
{ 
    return (a.second < b.second); 
} 


void solve(){
	int ans = 0;
	for(int i = 1 ; i <= 5 ;i++){
		int x; cin >> x; if(x == 0) ans = i; 
	}
	cout << ans << "\n";
	
}

int main(){ 
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int t = 1;
    //cin >> t;
    while(t--){
		solve();
	}
    return 0; 
}



Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
using lint = long;
using ll = long long;
#define rep(i,n) for(lint (i) = 0;(i) < (lint)(n);(i)++)
#define repInRange(i,start,end) for(lint (i) = (start);(i) < (end);++(i))
#define pb push_back
using Vecint = vector<lint>;

void Main() {
	lint N,K,x,sum = 0;
	cin >> N >> K;
	if (K > N) {
		cout << 0 << '\n';
		return;
	}
	Vecint H(N);
	rep(i,N) {
		cin >> x;
		H[i] = x;
	}
	sort(H.begin(),H.end());
	rep (i,N-K) {
		sum += H[i];
	}
	cout << sum << '\n';
}

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

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#include<algorithm>
#include<math.h>
using namespace std;
 
template <class T> using V = vector<T>;
 
using ll = long long;
using db = double;
using st = string;
using ch = char;
using vll = V<ll>;
using vpll =V<pair<ll,ll>>;
using vst = V<st>;
using vdb = V<db>;
using vch = V<ch>;
 
 
#define FOR(i,a,b) for(ll i=(a);i<(ll)(b);i++)
#define rFOR(i,a,b) for(ll i=(a);i>(ll)(b);i--)
#define oFOR(i,a,b) for(ll i=(a);i<(ll)(b);i+=2)
#define bgn begin()
#define en end()
#define SORT(a) sort((a).bgn,(a).en)
#define REV(a) reverse((a).bgn,(a).en)
#define M(a,b) max(a,b)
#define rM(a,b) min(a,b)
#define fi first
#define se second
#define sz size()
#define gcd(a,b) __gcd(a,b)
#define co(a) cout<<a<<endl;
#define ci(a) cin>>a;
 
 
ll sum(ll n) {
  ll m=0;
  FOR(i,0,20){
    m+=n%10;
    n/=10;
    if(n==0){
      break;
    }
  }
  return m;
}
 
 
ll combi(ll n,ll m) {
  ll ans=1;
  rFOR(i,n,n-m){
    ans*=i;
  }
  FOR(i,1,m+1){
    ans/=i;
  }
  return ans;
}
 
 
ll lcm(ll a,ll b){
  ll n;
  n=a/gcd(a,b)*b;
  return n;
}
 
 
/****************************************\
| Thank you for viewing my code:)        |
| Written by RedSpica a.k.a. RanseMirage |
| Twitter:@asakaakasaka                  | 
\****************************************/
 
 
signed main() {
  ch a;
  	ci(a);
  if(a=='a'||a=='i'||a=='u'||a=='e'||a=='o') co("vowel")
    else co("consonant")
    }

Measured memory_bytes: 256
s = gets.chomp.chars
dpr = Array.new(s.size, 0)
dpb = Array.new(s.size, 0)
s.reverse.each.with_index do |c, j|
  dpr[j] = 1 if c == "0"
  dpb[j] = 1 if c == "1"
end
res = 0
(1...s.size).each do |i|
  dpr[i] += dpr[i - 1]
  dpb[i] += dpb[i - 1]
  t = [dpr[i], dpb[i]].min
  res = t if t > res
end
puts res * 2

Measured memory_bytes: 12028
import sys
from math import ceil as C, floor as F, sqrt, gcd as G
from collections import defaultdict as D, Counter as CNT
from functools import reduce as R
import heapq as HQ

class Heap:
  def __init__(self, data, reverse=False):
    self.reverse = -1 if reverse else 1
    self.data = [self.reverse * d for d in data]
    HQ.heapify(self.data)
  def push(self, x): return HQ.heappush(self.data, self.reverse * x)
  def pop(self): return self.reverse * HQ.heappop(self.data) 

ALP = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
alp = 'abcdefghijklmnopqrstuvwxyz'
def _X(): return sys.stdin.readline().rstrip().split(' ')
def _S(ss): return tuple(ss) if len(ss) > 1 else ss[0]
def S(): return _S(_X())
def Ss(): return list(S())
def _I(ss): return tuple([int(s) for s in ss]) if isinstance(ss, tuple) else int(ss)
def I(): return _I(S())
def _Is(ss): return list(ss) if isinstance(ss, tuple) else [ss]
def Is(): return _Is(I())

n = I()

ans = 0
for i in range(1, n+1):
    for j in range(1, n+1):
        for k in range(1, n+1):
           ans += G(i, G(j, k))

print(ans)
            


Measured memory_bytes: 74344
#include <stdio.h>

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

  if (N <= 111) {
    x = 111;
  } else if (N <= 222) {
    x = 222;
  } else if (N <= 333) {
    x = 333;
  } else if (N <= 444) {
    x = 444;
  } else if (N <= 555) {
    x = 555;
  } else if (N <= 666) {
    x = 666;
  } else if (N <= 777) {
    x = 777;
  } else if (N <= 888) {
    x = 888;
  } else {
    x = 999;
  }

  printf("%d\n", x);
  return 0;
}


Measured memory_bytes: 128
#include <iostream>
using namespace std;
int main()
{
    int i, j, k, h, w;
   
    cin >> h >> w;
    while(h>0 || w>0)
    {
        for(i=1; i<=h; i++)
        {
            if(i%2==0)
            {
                for(j=1; j<=w; j++)
                {
                    if(j%2==0)
                    cout << "#";
                
                    else
                    cout << "." ;
                }
                cout << endl;
            }
            
            else
            {
                for(j=1; j<=w; j++)
                {
                    if(j%2==0)
                    cout << ".";
                
                    else
                    cout << "#" ;
                }
                cout << endl;
            }
        }
        cout << endl;
        cin >> h >> w;
    }
}


Measured memory_bytes: 3092
import java.util.Scanner;

 
public class Main {
 
	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] array = new int[n];
		
		for(int i = 0; i < n - 1; i++) {
			array[sc.nextInt() - 1] += 1;  
		}

		for(int i = 0; i < n; i++) {
			System.out.println(array[i]);
		}
		
		sc.close();
	}
	
}

Measured memory_bytes: 60720
#include<iostream>
#include<stdio.h>
#include<vector>
#include<ctype.h>
#include<string>
#include<cmath>
using namespace std;

class Dice{
    private:
    int face[7];
    
    public:
    
    void SetFace(){
        for(int i=1;i<sizeof(face)/sizeof(int);++i){
            cin>>face[i];
        }
    }
    void Up(){
        int buf=face[1];
        face[1]=face[2];
        face[2]=face[6];
        face[6]=face[5];
        face[5]=buf;
    }
    void Down(){
        int buf=face[1];
        face[1]=face[5];
        face[5]=face[6];
        face[6]=face[2];
        face[2]=buf;
    }
    void Right(){
        int buf=face[1];
        face[1]=face[4];
        face[4]=face[6];
        face[6]=face[3];
        face[3]=buf;
    }
    void Left(){
        int buf=face[1];
        face[1]=face[3];
        face[3]=face[6];
        face[6]=face[4];
        face[4]=buf;
    }
    void RightRolling(){
        int buf=face[2];
        face[2]=face[3];
        face[3]=face[5];
        face[5]=face[4];
        face[4]=buf;
    }
    void Rolling(char d){
        if(d=='N'){
            Up();
        }
        else if(d=='S'){
            Down();
        }
        else if(d=='E'){
            Right();
        }
        else if(d=='W'){
            Left();
        }
        else if(d=='R'){
            RightRolling();
        }
    }
    int GetFaceNum(int i){
        return face[i];
    }
};

bool ismatchDice(Dice d1,Dice d2){
    bool ismatch;
    Dice d3;
    for(int i=1;i<=6;++i){
        d3=d2;
        if(i==1);
        else if(i==2)d3.Up();
        else if(i==3)d3.Left();
        else if(i==4)d3.Right();
        else if(i==5)d3.Down();
        else if(i==6){
            d3.Up();
            d3.Up();
        }
        for(int j=0;j<4;++j){
            d3.RightRolling();
            ismatch=true;
            for(int i=1;i<=6;++i){
                if(d1.GetFaceNum(i) != d3.GetFaceNum(i)){
                    ismatch=false;
                    break;
                }
            }
            if(ismatch)break;
        }
        if(ismatch)break;
    }
    return ismatch;
}

Dice dice[3];
int n;
int main(){
    cin>>n;
    for(int i=0;i<n;++i){
        dice[i].SetFace();
    }
    bool ismatch=false;
    for(int i=0;i<n;++i){
        for(int j=i+1;j<n;++j){
            ismatch=ismatchDice(dice[i],dice[j]);
            if(ismatch)break;
        }
        if(ismatch)break;
    }
    if(!ismatch){
        cout<<"Yes"<<endl;
    }
    else cout<<"No"<<endl;
    return 0;
}



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

long long dfs(const vector<vector<int>> &G, const vector<int> &C, vector<int> &A, int v, int prev, int &t){
  long long ret = 0;
  for(auto v_ : G[v]){
    if(v_ == prev) continue;
    ret += dfs(G,C,A,v_,v,t);
  }
  A[v] = C[t];
  return ret + C[t++];
}

int main(){
  int N;
  cin >> N;
  vector<vector<int>> G(N);
  for(int i = 0; i < N-1; ++i){
    int a, b;
    cin >> a >> b;
    --a,--b;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  vector<int> C(N);
  for(int i = 0; i < N; ++i) cin >> C[i];
  sort(C.begin(), C.end());
  vector<int> A(N,-1);
  int t = 0;
  long long s = dfs(G,C,A,0,-1,t)-C.back();
  cout << s << endl;
  cout << A[0];
  for(int i = 1; i < A.size(); ++i) cout << " " << A[i];
  cout << endl;
}


Measured memory_bytes: 1920
#include <algorithm>
#include <iostream>
#include <string>

using namespace std;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  int a = 0;
  int b = 0;
  int ba = 0;
  int ans = 0;
  string s;
  for (int i = 0; i < n; i++) {
    cin >> s;
    for (int j = 0; j < s.size() - 1; ++j) {
      if (s[j] == 'A' && s[j + 1] == 'B') ++ans;
    }

    if (s[0] == 'B' && s.back() != 'A') ++b;
    if (s[0] != 'B' && s.back() == 'A') ++a;
    if (s[0] == 'B' && s.back() == 'A') ++ba;
  }
  int x = 0;
  if (ba == 0)
    x = min(a, b);
  else if (ba > 0 && b + a > 0)
    x = ba + min(a, b);
  else if (ba > 0 && b + a == 0)
    x = ba - 1;

  ans += x;
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include<string.h>

int main(void) {
    long int n,i;
	long long int a;
	long long int b[200000]={0};
	scanf("%ld",&n);
	if(n%2==1){
		for(i=0;i<n;i++){
			scanf("%lld",&a);
			if(i%2==0){
				b[n/2-i/2]=a;
			}else{
				b[n/2+i/2+1]=a;
			}
		}
	}else{
		for(i=0;i<n;i++){
			scanf("%lld",&a);
			if(i%2==0){
				b[n/2+i/2]=a;
			}else{
				b[n/2-i/2-1]=a;
			}
		}
	}
	for(i=0;i<n;i++){
		printf("%lld ",b[i]);
		if(i==n-1) printf("\n");
	}
	return 0;
}


Measured memory_bytes: 3712
#include<cstdio>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#define IOS ios::sync_with_stdio(false),cin.tie(0)
#define REP(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;


int main() {
	IOS;
	ll N, C, K;
	vector<int> T;
	int t;
	cin >> N >> C >> K;
	int i;
	for (i = 0; i < N; i++) {
		cin >> t;
		T.push_back(t);
	}
	sort(T.begin(), T.end());
	int cnt = 1, ans = 1;
	int j = 0;
	if (C == 1) {
		cout << N << endl;
		return 0;
	}
	for (i = 0; i < N; i++) {
		//T[i]は乗れるか
		if (cnt >= C || T[i] > T[j] + K) {
			ans++;
			j = i;
			cnt = 1;
		}
		else cnt++;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 892
package main

import (
  "fmt"
)

func main() {
  var r, g, b int
  
  fmt.Scanf("%d %d %d", &r, &g, &b)
  
  sum := 100*r + 10*g + b
  ans := "NO"
  if sum % 4 == 0 {
    ans = "YES"
  }
  fmt.Printf("%s", ans)
}

Measured memory_bytes: 1832
import java.util.*;

public class Main
{
	public static void main(String[] args)
	{
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[200001];

		for(int i = 1 ; i <= n ; i++){
			a[i] = sc.nextInt();
		}

		int ball = 0;
		int box = 0;
		int[] boxnum = new int[200001];
		for(int i = n ; i > 0 ; i--){
			ball = 0;
			for(int j = ((int)(n/i))*i ; j > i ; j -= i){
				ball += a[j];
			}
			ball %= 2;
			if(ball == a[i]){
				a[i] = 0;
			}else{
				a[i] = 1;
				boxnum[box] = i;
				box++;
			}
		}

		System.out.println(box);
		for(int i = 0 ; i < box ; i++){
			System.out.printf("" + boxnum[i] + " ");
		}
	}

}

Measured memory_bytes: 93068
#!/usr/bin/python3

from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def main():
    N, M = map(int, input().split())
    if N == 1 and M == 1:
        print(1)
    elif N == 1:
        print(M - 2)
    elif M == 1:
        print(N - 2)
    else:
        print((N - 2) * (M - 2))


if __name__ == '__main__':
    main()


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

int main() {
  int X, N;
  cin >> X >> N;
  
  if (N == 0)
    cout << X << endl;
  
  else if (N != 0) {
    vector<int> vec(102);
    vector<int> vecD(102);
    vector<int> vecAns(102, 1000);
    
    for (int i = 0; i < 102; i++)
      vec.at(i) = i; //0-101までの列
    
    for (int i = 0; i < N; i++) {
      int p;
      cin >> p;
      vec.at(p) = 1000; //入力した配列を1000で除外
    }
    
    for (int i = 0; i < 102; i++)
      vecD.at(i) = abs(vec.at(i) - X); //Xとの差の絶対値の配列
    
  int counter = 0;
  for (int j = 0; j < 101; j++) {
    for (int i = 0; i < 102; i++) {
      if (vecD.at(i) == j) { //差がjとなるかチェック
      vecAns.at(i) = vec.at(i);
      counter += 1;
      }
    }
      if (counter == 0)
        continue;
      else if (counter != 0)
        break;
  }
    int min = vecAns.at(0);
    for (int i = 0; i < 102; i++) {
      if (vecAns.at(i) <= min)
        min = vecAns.at(i);
    }
    cout << min << endl;
  }
}

Measured memory_bytes: 3636
import numpy as np
import math
from collections import defaultdict

n,m = input().split()
n = int(n)
m = int(m)
P,Y = [],[]
for _ in range(m):
	p,y = input().split()
	P.append(p)
	Y.append(y)

P = [int(p) for p in P]
Y = [int(y) for y in Y]

sorted = defaultdict(list)

sorted = [[] for i in range(n)]

for i,(p,y) in enumerate(zip(P,Y)):
	sorted[p-1].append((y,i))

ans = [None]*m
for i, d in enumerate(sorted):
	d.sort()
	for k, (y, j) in enumerate(d):
		ans[j] = "%06d%06d" % (i+1,k+1)
print(*ans, sep='\n')



Measured memory_bytes: 55600
#include<iostream>
#include<algorithm>
using namespace std;
long long int g,m,a[52][2]= {0},b[52]= {0},num=0;
int yun()
{
    int i,j;
    for(i=0; i<g; i++)
    {
        for(j=0; j<g; j++)
        {
            if(i==j)
                continue;
                a[j][1]+=a[i][0];
                a[j][0]+=a[j][1]/g;
                a[j][1]%=g;
        }
        num+=a[i][0];
        a[i][0]=0;
    }
}
int judge()
{
    int i,j,flag=0;
    for(i=0; i<g; i++)
        if(a[i][0]!=0)
        {
            flag=1;
            break;
        }
    return flag;
}
int main()
{
    int i,j;
    cin>>g;
    for(i=0; i<g; i++)
        cin>>b[i];
    for(i=0; i<g; i++)
    {
        a[i][0]=b[i]/g;
        a[i][1]=b[i]%g;
    }
    while(1)
    {
        if(judge()==0)
            break;
        yun();
    }
    cout<<num;
}

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

long long t[200000];

int main(){

    int n;
    cin >> n;

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

    if(n%2==0){
        for(int i=n;i!=0;i-=2){
            cout << t[i-1] << " ";
        }
        for(int i=0;i<n-3;i+=2){
            cout << t[i] << " ";
        }
        cout << t[n-2] << endl;
    }
    else if(n==1){
        cout << t[0] << endl;
    }
    else{
        for(int i=n;i!=-1;i-=2){
            cout << t[i-1] << " ";
        }
        for(int i=1;i<n-3;i+=2){
            cout << t[i] << " ";
        }
        cout << t[n - 2] << endl;

    }
    return 0;

}

Measured memory_bytes: 3712
// Problem : B - ... (Triple Dots)
// Contest : AtCoder - AtCoder Beginner Contest 168
// URL : https://atcoder.jp/contests/abc168/tasks/abc168_b
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

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

#define ll long long
#define endl "\n"
#define lb "lower_bound"
#define ub "upper_bound"
#define bs "binary_search"

int dif(int a,int b){if(a > b)return a - b;else return b - a;}
int min(int a,int b){if(a > b)return b;else return a;}
int max(int a,int b){if(a > b)return a;else return b;}
int gcd(int a, int b){if(b == 0)return a;return gcd(b, a%b);}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL),cout.tie(NULL);
    int k;
    cin>>k;
    string s;
    cin>>s;
    if(s.length() <= k)
    cout<<s;
    else
    {
    	for(int i =0;i < k;i++)
    	cout<<s[i];
    	cout<<"...";
    }
	return 0;
}


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

#define ll long long int
#define endl "\n"
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

const int MOD = 1e9 + 7;
typedef unsigned long long u64;

int main()
{
    IOS;
    int t = 1;
    //cin >> t;
    while (t--)
    {
        string s;
        cin>>s;
        if(s=="ABC")cout<<"ARC"<<endl;
        else cout<<"ABC"<<endl;
    }
    return 0;
}


Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define P pair<ll,ll>
#define lvector vector<ll> 
#define rep(i,n) for(ll (i)=0; i<(n); ++(i))
#define print(a) cout << (a) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll n,ans1=0,ans2=0;cin>>n;
  double avg=0.0;
  lvector v(n,0);rep(i,n) {cin>>v[i];v[i]-=i+1;}
  sort(v.begin(),v.end());
  ll b=v[n/2-1],c=v[n/2];
  rep(i,n) {ans1+=abs(v[i]-b);ans2+=abs(v[i]-c);}
  print(min(ans1,ans2));
  return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
 #define SPEED ios_base :: sync_with_stdio(false), cin.tie(NULL), cout.tie(0)
int main() 
{
	SPEED; 
	int n,m,count=0;
    cin>>n>>m;
    int a[m];
    for(int i=0;i<m;i++){
      cin>>a[i];
      count=count+a[i];
    }
  if(count>=n)
    cout<<"Yes";
  else
    cout<<"No";
  
     
   
    
    
     
     return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define deb(x) cerr << #x << " = " << x << "\n";
#define FIO {ios::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr);}

int main(){
	FIO
	
	int n;cin >> n;
	int a[n];
	map<long long, long long> m;
	for(int i = 0; i < n; i++){
		cin >> a[i];
		m[a[i]]++;
	}
	long long ans = 0;
	for(auto j:m)ans += (j.second *(j.second - 1) / 2);
	for(int i = 0; i < n; i++){
		long long cur = ans;
		cur -= m[a[i]] * (m[a[i]] - 1) / 2;
		m[a[i]]--;
		cur += m[a[i]] * (m[a[i]] - 1) / 2;;
		m[a[i]]++;
		cout << cur << "\n";
	}
	return 0;
}


Measured memory_bytes: 10368
// 2020-07-18 10:56:41
#include<bits/stdc++.h>
#ifdef LOCAL
#include "lib/debug.hpp"
#else
#define debug(...) 1
#endif
#define ALL(a) (a).begin(), (a).end()
#define rep(i, n) REP(i, 0, (n))
#define repc(i, n) REPC(i, 0, (n))
#define REP(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define REPC(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define REPCM(i, n, m) for (int i = (int)(n); i >= (int)(m); i--)
using namespace std;
using ll = long long;
using ld = long double;
using pr = pair<ll, ll>;
using vll = vector<ll>;
using vpr = vector<pr>;
template<class T> inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } else return false; }
template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }

const ll INF = 1e18;
void answer() {
  int n;
  cin >> n;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];
  int k = n%2+1;
  vector<ll> dp(k+1, -INF);
  dp[0] = 0;
  rep(i, n) {
    vector<ll> p(k+1, -INF);
    swap(p, dp);
    repc(j, k) {
      if(j<k) chmax(dp[j+1], p[j]);
      if((i+j)%2) {
        chmax(dp[j], p[j]);
      } else {
        chmax(dp[j], p[j] + a[i]);
      }
    }
  }
  cout << dp[k] << '\n';
}
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  answer();
  return 0;
}


Measured memory_bytes: 4780
g = {
    :a => {0 => :x, 1 => :y},
    :x => {1 => :z},
    :y => {0 => :x},
    :z => {0 => :w, 1 => :b},
    :w => {0 => :b, 1 => :y},
    :b => {0 => :y, 1 => :x},
    :d => {},
}
loop do
    q = gets.chomp
    break if q == ?#
    v = :a
    q.each_char do |c|
        if g[v][c.to_i]
            v = g[v][c.to_i]
        else
            v = :d
        end
    end
    puts v == :b ? 'Yes' : 'No'
end


Measured memory_bytes: 6872
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <bitset>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>

using namespace std;

int toInt(string input){
	int times = 1;
	int res = 0;
	for(int i = input.size() - 1; i >= 0; i--){
		res += (input[i] - '0') * times;
		times *= 10;
	}
	return res;
}

int main(){
	int n = 0;
	while(cin >> n){
		if(cin.eof()) break;
		vector<string> input(n);
		for(int i = 0; i < n; i++){
			string tmp;
			cin >> tmp;
			input[i] = tmp;
		}

		for(int i = 0; i < n; i++){
			sort(input[i].begin(), input[i].end());
			int min = toInt(input[i]);

			sort(input[i].begin(), input[i].end(), greater<int>());
			int max = toInt(input[i]);

			cout << max - min << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1228