akhauriyash/Code-Regression huggingface dataset:
// 22
/****************************************************
https://searleser97.gitlab.io/algorithms/template.cpp
****************************************************/

#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define fors(_, x, n, s) for (int _ = x; _ < n; _ += s)
#define forn(_, x, n) fors(_, x, n, 1)
#define rep(_, n) forn(_, 0, n)
#define forrs(_, x, n, s) for (int _ = x; _ > n; _ -= s)
#define forrn(_, x, n) forrs(_, x, n, 1)
#define rrep(_, n) forrn(_, n - 1, -1)
#define fi first
#define se second
#define pb push_back
#define pairii pair<int, int>
#define all(x) x.begin(), x.end()
#define cerr(s) cerr << "\033[48;5;196m\033[38;5;15m" << s << "\033[0m"
// typedef __int128_t lli;
typedef long long int li;
typedef long double ld;
// 12
void _main(int tc) {
  li n, W;
  cin >> n >> W;
  vector<int> w(n), v(n);
  rep(i, n) { cin >> w[i] >> v[i]; }
  vector<vector<li>> mem(n + 1, vector<li>(W, -1));
  function<li(int, int)> knapsack = [&](int i, int k) -> li {
    assert(k <= W);
    if (i == n - 1)
      if (k + w[i] <= W)
        return v[i];
      else
        return 0;
    if (mem[i][k] != -1) return mem[i][k];
    mem[i][k] = 0;
    if (k + w[i] <= W) mem[i][k] = v[i] + knapsack(i + 1, k + w[i]);
    if (k <= W) mem[i][k] = max(mem[i][k], knapsack(i + 1, k));
    return mem[i][k];
  };
  cout << knapsack(0, 0) << endl;
}

int main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  _main(0);
  return 0;
  int tc;
  cin >> tc;
  rep(i, tc) _main(i + 1);
}

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

typedef long long int LLI;

int N;
LLI ans;
LLI as[214514];
LLI bs[214514];
LLI ps[214514];
LLI qs[214514];

int main() {
  scanf("%d", &N);
  for (int i=0; i<N; i++) {
    scanf("%lld", &as[i]);
  }

  for (int i=0; i<N; i++) {
    scanf("%lld", &bs[i]);
  }

  for (LLI k=0; k<30; k++) {
    for (int i=0; i<N; i++) {
      ps[i] = as[i] % (1LL << (k+1));
      qs[i] = bs[i] % (1LL << (k+1));
    }
    sort(qs, qs+N);

    LLI cnt = 0;
    for (int i=0; i<N; i++) {
      auto r = lower_bound(qs, qs+N, (1LL << (k+1)) - ps[i]);
      auto l = lower_bound(qs, qs+N, (1LL << k) - ps[i]);
      cnt += r-l;
      r = lower_bound(qs, qs+N, (1LL << (k+2)) - ps[i]);
      l = lower_bound(qs, qs+N, (1LL << k) + (1LL << (k+1)) - ps[i]);
      cnt += r-l;
    }
    ans += (cnt%2) << k;
  }
  printf("%lld\n", ans);
}


Measured memory_bytes: 6784
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define re register
#define gc getchar
#define pc putchar
#define cs const

inline
ll getint(){
	re ll num;
	re char c;
	while(!isdigit(c=gc()));num=c^48;
	while(isdigit(c=gc()))num=(num<<1)+(num<<3)+(c^48);
	return num;
}

inline
void outint(int a){
	static char ch[13];
	if(a==0)pc('0');
	while(a)ch[++ch[0]]=a-a/10*10,a/=10;
	while(ch[0])pc(ch[ch[0]--]^48);
}

cs int N=100005;

int last[N],nxt[N],to[N],ecnt;
inline
void addedge(int u,int v){
	nxt[++ecnt]=last[u],last[u]=ecnt,to[ecnt]=v;
}

map<ll,int> id;
int n;
ll d[N];
int siz[N];

int dist[N];
inline
void dfs(int u){
	for(int re e=last[u],v=to[e];e;v=to[e=nxt[e]]){
		dist[v]=dist[u]+1;
		dfs(v);
	}
}

vector<pair<int,int> > edge;

signed main(){
	n=getint();
	for(int re i=1;i<=n;++i)d[i]=getint(),id[d[i]]=i;
	
	sort(d+1,d+n+1);
	for(int re i=1;i<=n;++i)siz[i]=1;
	
	for(int re i=n;i>1;--i){
		int u=id[d[i]];
		int tmp=n-2*siz[u];
		if(tmp<=0)return puts("-1"),0; 
		ll t=d[i]-tmp;
		if(id.count(t)==0)return puts("-1"),0;
		int pos=id[t];
		addedge(pos,u);
		siz[pos]+=siz[u];
		edge.push_back(make_pair(pos,u));
	}
	ll sum=0;
	dfs(id[d[1]]);
	for(int re i=1;i<=n;++i){
		sum+=dist[i];
	}
	if(sum!=d[1])return puts("-1"),0;
	for(int re i=0;i<edge.size();++i)outint(edge[i].first),pc(' '),outint(edge[i].second),pc('\n');
	return 0;
}

Measured memory_bytes: 12152
n=int(input())
c=input().split()
d=c[:]

for i in range(n):
    for j in range(n-1,i,-1):
        if d[j][1]<d[j-1][1]:
            d[j],d[j-1]=d[j-1],d[j]
print(*d)
print("Stable")

for i in range(n):
    minj=i
    for j in range(i, n):
        if c[j][1] < c[minj][1]:
            minj=j
    c[i],c[minj]=c[minj],c[i]

print(*c)
if c==d:
    print("Stable")
else:
    print("Not stable")


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

#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define mem(x,val) memset((x),(val),sizeof(x))
#define all(x) x.begin(),x.end()
#define pb push_back
#define mp make_pair
#define PI acos(-1.0) 
#define MAXN 111111

const int INF = 1 << 29 ;
typedef long long ll ;
typedef pair < int , int > pii ;

int b[MAXN] ;

int main() {
    int n , h  ,a, count = 0  , mx = 0;
    scanf("%d %d" ,&n ,&h) ;

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

    sort(b , b+n , greater<int>()) ;

    for(int i =0 ;i<n && b[i] >= mx && h >0 ; i++)
        h-=b[i]  , count++ ;

    printf("%d\n" ,count+ (h>0?(h+mx-1)/mx:0)) ;

    return 0 ;
}

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

def s(n):
    r = 0
    while n > 0:
        r += n % 10
        n = n // 10
    return r
    

def find_next(n):
    d = 0
    m = n // 10
    sm = s(m)
    r = 0
    grad = 10 * m + 1 - sm - 9 * d - 1/(10**d)
    while grad > 0:
        r += 9 * 10**d
        d += 1
        sm -= m % 10
        m = m // 10
        grad = 10 * m + 1 - sm - 9 * d - 1/(10**d)
    r += (n // 10**d) * 10**d
    return r

for i in range(1, min(k, 9) + 1):
    print(i)
    
k -= min(k, 9)
p = 10

for i in range(0, k):
    p = find_next(p)
    print(p)
    p += 1

Measured memory_bytes: 3188
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int A[300000];

int main(){
    int n;
    cin>>n;
    for(int i=1;i<=n;i++) cin>>A[i];
    int Max = A[2],Min=A[1];
    int ans = Max-Min;
    int x=1,y=2;
    int index=2;
    while(index<=n) {
        if(A[index]>=Max) {
            Max = A[index];
            y = index;
            if(x<y) {
                if(Max-Min > ans) ans=Max-Min;
            }
        }
        if(A[index]<Min) {
            Min = A[index];
            x = index;
            if(x<y) {
                if(Max-Min > ans) ans=Max-Min;
            }
            else {
                y = index+1;
                if(y>n) break;
                Max=A[y];
                if(Max-Min > ans) ans=Max-Min;
            }
        }
        index++;
    }
    cout<<ans<<endl;
    return 0;
}


/*
4
8 1 4 1
3
4
8 5 4 5
1
4
8 5 4 2
-1
3
8 9 8
5
10 8 9 3 2
*/



Measured memory_bytes: 3844
#include <bits/stdc++.h>
using namespace std;
#define END '\n'
#define int long long
#define pb push_back
#define pii pair<int, int>
#define ff first
#define ss second
#define bug(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define loop(i, a, b) for(int i = (a); i < (b); i++)
#define loopb(i, b, a) for(int i = (b); i > (a); --i) 
const int mod = 1e9+7;
const int mod1 = 998244353;
const int inf = 9223372037ll;
const int nax = 200005;
int m,n,x,y,cnt;
bool vis[nax];
set<int> adj[nax];
void dfs(int node)
 {
  vis[node] = 1;
  cnt++;
  for(auto x : adj[node])
     {
      if(!vis[x])
         dfs(x);
     }
 }
void solve()
  {
   cin>>n>>m;
   loop(i,0,m)
    {
      cin>>x>>y;
      adj[x].insert(y);
      adj[y].insert(x);
    }
  int ans = 0;
  loop(i,1,n+1)
   if(!vis[i])
     {
      cnt = 0;
      dfs(i);
      ans = max(ans,cnt);
     }
  cout<<ans;

  } 
signed main()
 {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0); 
   /*int t;
   cin>>t;
   while(t--)*/
     solve();
  //cerr<<END<<1.0*clock();
  return 0;
} 

Measured memory_bytes: 38152
N, K=map(int, input().split())
ab=[list(map(int, input().split())) for i in range(N)]
ab.sort(key=lambda x:x[0])
counter=0
i=0
counter+=ab[i][1]
while counter<K:
  i+=1
  counter+=ab[i][1]
print(ab[i][0])

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

#define FOR(i,l,r) for(int i = int(l);i < int(r);i++)
template<typename T> bool chmax(T& a,const T& b){ return a < b ? (a = b,true) : false; }
template<typename T> bool chmin(T& a,const T& b){ return b < a ? (a = b,true) : false; }
typedef long long ll;

int H,W;
vector<string> S;
const int dx [] = {0,1,1,1,0,-1,-1,-1};
const int dy [] = {-1,-1,0,1,1,1,0,-1};

int main()
{
	cin >> H >> W;
	S.assign(H,"");
	FOR(i,0,H){
		cin >> S [i];
		FOR(j,0,W) if(S [i] [j] == '.'){
			S [i] [j] = '0';
		}
	}

	FOR(i,0,H) FOR(j,0,W) if(S [i] [j] == '#'){
		FOR(k,0,8){
			int y = i + dy [k],x = j + dx [k];
			if(y >= 0 && y < H && x >= 0 && x < W && S [y] [x] != '#'){
				S [y] [x]++;
			}
		}
	}
	FOR(i,0,H){
		cout << S [i] << endl;
	}

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, m, n) for(int (i) = (m); (i) < (n); ++i)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
using namespace std;
using Graph = vector<vector<int>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
typedef long long ll;
typedef pair<ll, ll> P;
const int INF = 1e9+7;
const ll LINF = 1LL<<60;

int main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    int a, b, k;
    cin >> a >> b >> k;

    for (int i = a; i <= min(b, a + k - 1); ++i) cout << i << endl;
    for (int i = max(b - k + 1, a + k); i <= b; i++) cout << i << endl;
    return 0;
}

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

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

  unordered_map<int, int> map;
  vector<int> balls;

  rep(i, n) {
    int a;
    cin >> a;
    map[a]++;
    balls.push_back(a);
  }

  ll total = 0;

  for (auto bucket : map) {
    ll count = bucket.second;
    total += (count * (count - 1)) / 2;
  }

  for (auto ball : balls) {
    int count = map[ball];
    cout << total - (count - 1) << endl;
  }

  return 0;
}


Measured memory_bytes: 11024
#include <stdio.h>

int main(void){
  int i , j , key , s_length , t_length ;
  int ans = 0;


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

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

  for(i = 0 ; i < t_length ; i++){
    key = T[i];
    for(j = 0 ; j < s_length ; j++){
      if(key == S[j]){
        ans++;
        break;
      }
    }
  }


  printf("%d\n",ans);

  return 0;
}



Measured memory_bytes: 2056
A, B, C, D = map(int, input().split())
ABC = [A,B,C]
if abs(ABC[0] - ABC[2]) <= D:
    print('Yes')
    exit(0)
for i in range(1,3):
    if abs(ABC[i] - ABC[i-1]) <= D:
        continue
    else:
        print('No')
        exit(0)
print('Yes')



Measured memory_bytes: 9076
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 1000001;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

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

ll lcm(ll a, ll b) {
	return a / gcd(a, b) *b;
}

struct edge {
	ll ind;
	ll to;
	ll d;
};


///////////////////////////



int main() {

	ll N;
	cin >> N;
	vector<ll> T(N + 1);
	repn(i, N) cin >> T[i];

	ll S = 0;
	repn(i, N) S += T[i];

	ll M;
	cin >> M;

	repn(i, M) {
		ll p, x;
		cin >> p >> x;
		cout << S - T[p] + x<<endl;
	}

	system("PAUSE");
}

Measured memory_bytes: 504
#include<cstdio>
#include<vector>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;

#define mp make_pair
#define fi first
#define se second
#define pb push_back
typedef double db;
const db eps=1e-6;
const db pi=acos(-1.0);

int sign(db k){//-----------
    if (k>eps) return 1; else if (k<-eps) return -1; return 0;
}
int cmp(db k1,db k2){return sign(k1-k2);}  //-----------
struct point{
    db x,y;
    // point (double _x =0,double _y=0){x=_x;y=_y;}//------
    // point operator + (const point &k1) const {return point(k1.x+x,k1.y+y);}//------
    // point operator - (const point &k1) const {return point(x-k1.x,y-k1.y);}//------
    // point operator * (db k1) const  {return point(x*k1,y*k1);};//--------
    // point operator / (db k1) const{return point(x/k1,y/k1);}
    point operator + (const point &k1) const{return (point){k1.x+x,k1.y+y};}  //两个点相加-----
    point operator - (const point &k1) const{return (point){x-k1.x,y-k1.y};}  //两个点相减------
    point operator * (db k1) const{return (point){x*k1,y*k1};}  //与原点的距离扩大k1倍-------
    point operator / (db k1) const{return (point){x/k1,y/k1};}  //与原点的距离缩小k1倍
    int operator == (const point &k1) const{return cmp(x,k1.x)==0&&cmp(y,k1.y)==0;}  //判断两个点相等
    point turn(db k1){return (point){x*cos(k1)-y*sin(k1),x*sin(k1)+y*cos(k1)};} // 绕原点逆时针旋转
    point turn2(db k1, point p){return p+((*this)-p).turn(k1);}//绕p逆时针旋转k1度
    point turn90(){return (point){-y,x};}   //逆时针旋转90度
    //在点k1左边返回1 相等时在下边返回1  根据（x，y）排序-------------
    bool operator < (const point k1) const{
        int a=cmp(x,k1.x);
        if (a==-1) return 1; else if (a==1) return 0; else return cmp(y,k1.y)==-1;
    }
    db abs(){return sqrt(x*x+y*y);}//返回距离原点欧式距离
    db abs2(){return x*x+y*y;}  //返回距离原点欧式距离的平方
    db dis(point k1){return ((*this)-k1).abs();}    //返回两个点之间的欧式距离
    point unit(){db w=abs(); return (point){x/w,y/w};}  //返回单位向量
    void scan(){double k1,k2; scanf("%lf%lf",&k1,&k2); x=k1; y=k2;} //输入一个点--------
    void print(){printf("%.11f %.11f\n",x,y);}    //输出一个点--------
    db getw(){return atan2(y,x);}   //返回方位角  取值[-π，π]
    //如果 x>=0&&y>=0 不变，其他关于原点对称
    point getdel(){if (sign(x)==-1||(sign(x)==0&&sign(y)==-1)) return (*this)*(-1); else return (*this);}
	int getP() const{return sign(y)==1||(sign(y)==0&&sign(x)==-1);}  //x>=0&&y<=0返回真
};
db cross(point k1,point k2){return k1.x*k2.y-k1.y*k2.x;}    //叉积-----
db area(vector<point> A){ // 多边形的面积，多边形用 vector<point> 表示 , 逆时针
    db ans=0;
    for (int i=0;i<A.size();i++) ans+=cross(A[i],A[(i+1)%A.size()]);
    return ans/2;
}
vector < point > ans;
int main()
{
    int n;
    ans.clear();
    scanf("%d", &n);
    while(n--)
    {
        point a;
        a.scan();
        ans.push_back(a);
    }
    double areaa = area(ans);
    printf("%.1f\n", areaa);
    return 0;
}



Measured memory_bytes: 2800
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define fore(b,c) for(int val0=b;val0<c;val0++)
#define forr(k,c,s) for(int k=c;k<s;k++)
#define pb push_back
#define mmp make_pair
#define oset(T) tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>
using namespace __gnu_pbds;
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef pair<int,int> ii;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef long double ld;
typedef vector<vii> al;
typedef vector<ll> vl;
const int INF = 1e9;
const ll INFL = 1LL<<61;
const int MN = 100100;
const ll M = 1e9+7;
ll mul(ll a, ll b) {return (a*b)%M;}
ll bp(ll b, ll p) {
	ll ac = 1;
	while(p) {
		if(p&1) {
			ac = mul(ac,b);
		}
		b = mul(b,b);
		p >>= 1;
	}
	return ac;
}
ll inv(ll val) {
	return bp(val,M-2);
}
ll fp[MN];
ll fac(ll val) {
	if(val <= 1) return 1;
	if(fp[val] != -1) return fp[val];
	return fp[val] = mul(val,fac(val-1));
}
ll w[MN];
int main() {
	ios::sync_with_stdio(0);cout.precision(20);cout.tie(0);cin.tie(0);
	ll n;
	cin >> n;
	memset(fp,-1,sizeof(fp));
	ll res = 0;
	ll acc = 0;
	for(int i=0;i<n;i++) {
		cin >> w[i];
	}
	for(int i=0;i<n-1;i++) {
		ll val = w[i+1]-w[i];
		val = ((val%M)+M)%M;
		acc += inv(i+1);
		res += mul(acc,val);
	}
	res = ((res%M)+M)%M;
	res = mul(res,fac(n-1));
	cout << res << '\n';
}



Measured memory_bytes: 3456
#include <cmath>
#include <iostream>
#include <vector>
#define rep(i, n) for(int i = 0; i < (n); i ++)
using ll = long long;
using namespace std;
const int mod = 998244353;

vector<ll> prime;


int main(int argc, const char * argv[]) {
    int n, k;
    cin >> n >> k;
    vector<int> l(k), r(k);
    rep (i, k) cin >> l[i] >> r[i];
    vector<int> dp(n + 1);
    vector<int> dpsum(n + 1);
    dp[1] = 1;
    dpsum[1] = 1;
    for(int i = 2; i <= n; i ++){
        rep(j, k){
            int li = i - r[j];
            int ri = i - l[j];
            if(ri < 0) continue;
            li = max(li, 1);
            dp[i] = (dp[i] + dpsum[ri] - dpsum[li - 1]) % mod;
            if (dp[i] < 0) {
                dp[i] += mod;
            }
        }
        dpsum[i] = (dpsum[i -1] + dp[i]) % mod;
    }
    cout << dp[n] <<endl;

    return 0;
}


Measured memory_bytes: 4452
function main(input) {
    var arr = [];
    var rows = input.split(" ");
    rows = rows.sort();
    if(rows[0] == 5 && rows[1] == 5 && rows[2] == 7){
    	console.log("YES");
    }else{
    	console.log("NO");
    }
}
main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

int a[101][101];
int n=0;
int found[101];
int ended[101];
int aaa(int i, int time);

int main(){
  for(int i=0; i<101; i++)
    for(int j=0; j<101; j++)
      a[i][j]=0;
  int u, k, v;
  cin>>n;
  for(int i=0; i<n; i++){
    cin>>u>>k;
    for(int j=0; j<k; j++){
      cin>>v;
      a[u][v]=1;
    }
  }

  int time=0;
  for(int i=0; i<101; i++){
    found[i]=0;
    ended[i]=0;
  }

  for(int i=1; i<n+1; i++){
    if(found[i]>0)
      continue;
    time++;
    found[i]=time;
    time=aaa(i, time);
    ended[i]=time;
  } 

  for(int i=1; i<n+1; i++)
    cout<<i<<' '<<found[i]<<' '<<ended[i]<<endl;
}

int aaa(int i, int time){
  for(int k=1; k<n+1; k++){
    if(a[i][k]==1&&found[k]==0){
      time++;
      found[k]=time;
      time=aaa(k, time);
      ended[k]=time;
    } 
  }
  time++;
  return time;
}

Measured memory_bytes: 1200
#include <atcoder/all>
#include <bits/stdc++.h>

using namespace std;
using namespace atcoder;

#define REP(i,m,n) for(int i=(m);i<(n);++i)
#define rep(i,n) REP(i,0,n)

int main(){
  int T;
  scanf("%d",&T);
  long long n,m,a,b;
  rep(i,T){
    scanf("%lld%lld%lld%lld",&n,&m,&a,&b);
    printf("%lld\n",floor_sum(n,m,a,b));
  }
  return 0;
}

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

using namespace std;

template<typename S, typename T>
ostream& operator<<(ostream& out, const pair<S, T> p) {
    out << "(" << p.first << "," << p.second << ")";
    return out;
}

template<typename T>
ostream& operator<<(ostream& out, const vector<T>& v) {
    for (auto a: v)
        out << a << " ";
    return out;
}

template<typename T>
ostream& operator<<(ostream& out, const set<T>& S) {
    for (auto a: S)
        cout << a << " ";
    return out;
}

template<typename T>
ostream& operator<<(ostream& out, const multiset<T>& S) {
    for (auto a: S)
        cout << a << " ";
    return out;
}

template<typename S, typename T>
ostream& operator<<(ostream& out, const map<S, T>& M) {
    for (auto m: M)
        cout << "(" << m.first << "->" << m.second << ") ";
    return out;
}

template<typename S, typename T>
pair<S, T> operator+(pair<S, T> a, pair<S, T> b) {
    return make_pair(a.first + b.first, a.second + b.second);
}

template<typename S, typename T>
pair<S, T> operator-(pair<S, T> a, pair<S, T> b) {
    return make_pair(a.first - b.first, a.second - b.second);
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n, m;
    vector<pair<long long, long long>> A, B;
    cin >> n >> m;
    A.resize(n);
    for (int i = 0; i < n; i++)
        cin >> A[i].first >> A[i].second;
    B.resize(m);
    for (int i = 0; i < m; i++)
        cin >> B[i].first >> B[i].second;
    for (int i = 0; i < n; i++) {
        long long min_val = 1e18;
        int sol = -1;
        for (int j = 0; j < m; j++) {
            auto d = A[i] - B[j];
            long long val = abs(d.first) + abs(d.second);
            if (min_val > val) {
                min_val = val;
                sol = j;
            }
        }
        cout << sol + 1 << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<numeric>
#include<utility>
#include<unordered_map> //hash map
#include<cmath>

#define rep(i,a,n) for(int (i)=(a);(i)<(n);(i)++)
#define rrep(i,a,n) for(int (i)=(a);(i)>=(n);(i)--)

#define INF 10000007

typedef  long long ll;

using namespace std;

void factor(map<ll,ll> f, ll n){
    ll p = sqrt(n)+1;
  for(int i = 2;i < p && n!=0;i++){
    //cout << i << endl;
    if(n%i == 0){
      f[i]++;
      n/=i;
    } 
  }
  for(int  i = 2;i < p;i++){
      cout << f[i] << endl;
  }
}

  map<ll, ll> fa,fb;
void solve(){
  ll n;
  cin >> n;
  ll a[n];
  bool flag = true;
  for(int i = 0;i < n;i++){
    cin >> a[i];
    if(a[i] == 1) flag = false;
  }
  if(flag){
    cout << -1 << endl;
    return;
  }

  ll ans = 0;
  ll c = 1;
  for(int i = 0;i < n;i++){
    if(c == a[i]){
      c++;
    }else{
      ans++;
    }
  }

  cout << ans << endl;

}

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


Measured memory_bytes: 1792
def primes(n):
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    return [i for i in range(n + 1) if is_prime[i]]

n=int(input())

for num in primes(10**6):
  if num>=n:
    print(num)
    break

Measured memory_bytes: 14000
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>   
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
#include<stdio.h>
#include<string.h>
#include <bitset>

using namespace std;
#define int  long long
 
#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
#define MEM_SIZE 10000
#define DEBUG_OUT true
#define ALL(x) (x).begin(),(x).end()

// int DP[MEM_SIZE][MEM_SIZE] = {0};
// int GMEM[MEM_SIZE][MEM_SIZE] = {0};
template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return; std::cout << e <<" ";}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){std::cout<< e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T,class... Ts> void DEBUG(T d, Ts... e){if(DEBUG_OUT == false)return;DEBUG(d);DEBUG(e...);}
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }


//FUNCTION
void solve(void)
{
  int N; cin>>N;
  map<int,int> mp1,mp2;
  for (int i = 0; i < N; i++)
  {
    int A;
    cin>>A;
    if(i%2 == 0)mp1[A]++;
    else mp2[A]++;
  }
  int MAX1 = 0, MAX2 = 0;
  int i1 = 0,i2 = 0;
  for (auto i : mp1)
  {
    if(chmax(MAX1,i.second))
    {
      i1 = i.first;
    }
  }
  int TEMP_MAX = 0;
  for (auto i : mp2)
  {
    if(chmax(MAX2,i.second))
    i2 = i.first;
  }
  int NMAX1 = 0, NMAX2 = 0;
  if(i1 == i2)
  {
      for (auto m : mp2)
      {
        if(m.first == i2)continue;
        chmax(NMAX1,m.second);
      }
      
        for (auto m : mp1)
      {
        if(m.first == i1)continue;
        chmax(NMAX2,m.second);
      }
      if(NMAX1 > NMAX2) MAX1 = NMAX1;
      else MAX2 = NMAX2;
    
    // abort();
  }
  // DEBUG(MAX1,MAX2);
  // if(mp1.size() == 1 && mp2.size()==1 && mp1.begin()->first == mp2.begin()->first)
  // {
  //   cout<<N/2<<endl;
  //   return;
  // }
  cout<<N-MAX1-MAX2<<endl;
  
  
  
  return;
}

int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(15);
  solve();

  return 0;
}


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

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

    long int sum = 0;

    int i;
    int B;
    int prevB = 100000;
    for (i = 1; i < N; i++) {
        scanf("%d", &B);
        if (B > prevB) {
            sum += prevB;
        } else {
            sum += B;
        }
        prevB = B;;
    }
    sum += B;
    printf("%ld\n", sum);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) REPI(i, 0, n)
#define REPI(i, a, b) for (int i = (int)(a) ; i < (int)(b) ; i++)

#define SZ(x) ((int)(x).size())


using ll = long long;
using uint = unsigned int;
using namespace std;

int main()
{
    uint S, W;
    cin >> S >> W;
    if (S <= W)
    {
        cout << "unsafe" << endl;
    } else 
    {
        cout << "safe" << endl;    
    }
    return 0;
}

Measured memory_bytes: 3632
import java.util.*;
class Main
{
	public static void main(String args[])
	{
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		
		for(int i=1; i<10; i++){
			for(int j=1; j<10; j++){
				int sum=i*j;
				
				if(sum==n){
				System.out.println("Yes");
				return;
				}
			}
		}
		System.out.println("No");
	}
}

Measured memory_bytes: 25172
#include <iostream>
#include <string>

using namespace std;

struct Dice{
    int number[6];

    void roll(char ch){
        if(ch == 'N'){
            int nb = number[0];
            number[0] = number[1];
            number[1] = number[5];
            number[5] = number[4];
            number[4] = nb;
        }else if(ch == 'S'){
            int nb = number[0];
            number[0] = number[4];
            number[4] = number[5];
            number[5] = number[1];
            number[1] = nb; 
        }else if(ch == 'E'){
            int nb = number[0];
            number[0] = number[3];
            number[3] = number[5];
            number[5] = number[2];
            number[2] = nb;
        }else{
            int nb = number[0];
            number[0] = number[2];
            number[2] = number[5];
            number[5] = number[3];
            number[3] = nb;
        }
    }

    void top(){
        cout << number[0] << endl;
    }

};

int main(){
    Dice dice;

    for(int i = 0; i < 6; i++)
        cin >> dice.number[i];

    string str;
    cin >> str;
    for(int i = 0; i < str.length(); i++)
        dice.roll(str[i]);

    dice.top();

    return 0;
}


Measured memory_bytes: 3208
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007

int main() {
  
  string S;
  cin >> S;

  int n = S.size();
  if(n%2 != 0) {
    cout << "No" << endl;
    return 0;
  }

  for(int i = 0;i < n-1;i++) {
    if(S.substr(i,2) != "hi") {
      cout << "No" << endl;
      return 0;
    }
    i++;
  }

  cout << "Yes" << endl;

}


Measured memory_bytes: 384
//long time no ac
#include<bits/stdc++.h>
using namespace std;


#define     SPEED     ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define 	ll          long long int
#define 	pb          push_back
#define 	pii         pair<int,int>
#define 	vi          vector<int>
#define 	pll         pair<ll,ll>
#define 	vll         vector<ll>
#define 	ff          first
#define 	ss          second
#define 	all(a)      (a).begin(),(a).end()
#define 	sz(x)       (ll)x.size()
#define 	hell        1000000007
#define 	rep(i,n)    for(i=0;i<n;i++)
#define 	repe(i,a,b) for(i=a;i<b;i++)
#define 	lbnd        lower_bound
#define 	ubnd        upper_bound
#define 	bs          binary_search
#define 	mp          make_pair

ll power(ll a,ll b)
{
	if(b==0)
		return 1;
	if(b==1)
		return a;
	ll c=power(a,b/2);
	if(b%2==0)
		return((c%hell)*(c%hell))%hell;
	return ((((c%hell)*(c%hell))%hell)*(a%hell))%hell;
}


int main()
{
	SPEED;
	ll n,k,t,c=0,i,j,m,cs=0;
	t=1;

	//cin>>t;
	string s;
	while(t--)
	{
		cin>>n>>m>>k;
		// n=s.length();
		// ll a[n];
		c=(n-m+1)*(n-k+1);
		
		cout<<c;
		if(t!=0)
	   		cout<<"\n";
	}
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#define rep(i, start, end) for (int i = (int)start; i < (int)end; ++i)
#define rrep(i, start, end) for (int i = (int)start - 1; i >= end; --i)
#define arep(i, c) for (auto i = (c).begin(); i != (c).end(); ++i)
#define all(x) (x).begin(), (x).end()
using namespace std;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    cout << fixed << setprecision(7);
    if (N % 2) cout << (double)((N + 1) / 2) / N << endl;
    else cout << 0.5 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <cstdlib>
#include <iostream>
#include <map>
#include <vector>
#include <cmath>

using namespace std;

typedef struct Plan {
    int t;
    int x;
    int y;
}Plan;

bool judge(Plan p1,Plan p2) {
    int dis = abs(p1.x - p2.x) + abs(p1.y - p2.y);
    int dt = p2.t - p1.t;
    return dis%2 == dt%2 && dis <= dt;
}

int main() {
    int N;
    Plan *plan;
    scanf("%d",&N);
    plan = new Plan[N + 1];
    plan[0].t = 0;
    plan[0].x = 0;
    plan[0].y = 0;
    for(int i = 1;i < N + 1;i++) {
        scanf("%d%d%d", &plan[i].t, &plan[i].x, &plan[i].y);
    }

    bool po = true;
    for(int i = 0;i < N;i++) {
        po = po && judge(plan[i],plan[i + 1]);
    }

    if(po) {
        printf("Yes\n");
    }else{
        printf("No\n");
    }

    delete[] plan;
}


Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
long long a,b,s,sum1,sum2,x;
long long i;
int main(){
    
    cin>>a>>b>>x;
        if(a%x==0)sum1=a/x; else sum1=a/x+1;
        sum2=b/x;
    cout<<sum2-sum1+1<<endl;
    return 0;
} 

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
    int d,t,s;
    int net=0;
    cin>>d>>t>>s;
    net=t*s;
    if(net>=d)
    {
        cout<<"Yes";
    }
    else
    {
        cout<<"No";
    }
    return 0;
}


Measured memory_bytes: 3580
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <complex>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <utility>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
#define all(c) (c).begin(), (c).end()
#define loop(i,a,b) for(ll i=a; i<ll(b); i++)
#define rep(i,b) loop(i,0,b)
#define each(e,c) for(auto&e:c)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define lb lower_bound
#define ub upper_bound
#ifdef DEBUG
#define dump(...) (cerr<<#__VA_ARGS__<<" = "<<(DUMP(),__VA_ARGS__).str()<<" ["<<__LINE__<<"]"<<endl)
struct DUMP:ostringstream{template<class T>DUMP &operator,(const T&t){if(this->tellp())*this<<", ";*this<<t;return *this;}};
#else
#define dump(...)
#endif
template<class T> ostream& operator<<(ostream& os, vector<T> const& v){
    rep(i,v.size()) os << v[i] << (i+1==v.size()?"":" ");
    return os;
}

typedef double R;
typedef complex<R> P;
R const eps = 1e-8;
R const pi = acos(-1);

int main(){
    int n;
    while(cin>>n && n){
        vector<P> ps(n);
        rep(i,n){
            R x,y; cin >> x >> y;
            ps[i] = P(x,y);
        }
        int ans = 1;
        rep(i,n)rep(j,n)if(i!=j){
            P & p = ps[i];
            P & q = ps[j];
            R d = abs(p-q)/2;
            if(d+eps > 1.0) continue;
            P m = (p+q)/R(2);
            R l = sqrt(1-d*d);
            P u = (p-m)/d*l*P(0,1);
            P c = m + u;
            int cnt = 0;
            dump(abs(c-p));
            rep(k,n) if(abs(c-ps[k]) < 1.0+eps) cnt++;
            ans = max(ans,cnt);
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 1272
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;



public class Main {

	public static void main(String[] args) throws IOException {
		// TODO 自動生成されたメソッド・スタブ
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		final long mod = 1_000_000_000 + 7;

		char[] input = br.readLine().toCharArray();

		int numOfC[] = new int[input.length];

		for(int i = input.length - 1; i >= 0; i--){
			if(input[i] == 'C' || input[i] == '?'){
				numOfC[i]++;
			}
			if(i != input.length - 1){
				numOfC[i] += numOfC[i + 1];
			}
		}

		//debug
//		printArray(numOfC);

		int bc[] = new int[input.length];

		//debug
//		printArray(bc);

		long abc[] = new long[input.length];

		//debug
//		printArray(abc);

		//Sの先頭からi-1文字目までに対する処理をすでにおこなっていて
		//これまでにj個○をつけている場合のSの残りの部分に対する処理のパターン数
		long dp[][] = new long[input.length + 1][4];

		//正常に終了した場合、何もしないの1通り
		dp[input.length][3] = 1;

		//○をつけ終わらないのに終了した場合は不正
		for(int j = 0; j < 3; j++){
			dp[input.length][j] = 0;
		}

		//途中で○を3個つけ終わっているなら?を置換するだけ
		for(int i = input.length - 1; i >= 0; i--){
			int m = 1;

			//?なら可能性が3倍
			if(input[i] == '?'){
				m = 3;
			}
			dp[i][3] = m * dp[i + 1][3];
			dp[i][3] %= mod;
		}

		char ABC[] = "ABC".toCharArray();

		for(int i = input.length - 1; i >= 0; i--){
			int m1 = 1;
			int m2 = 0;

			//?なら可能性3倍
			if(input[i] == '?'){
				m1 = 3;
			}

			for(int j = 2; j >= 0; j--){
				//?かあるいはABCのうちの適切な文字でなければ加算できない
				if(input[i] == '?' || input[i] == ABC[j]){
					m2 = 1;
				}
				else {
					m2 = 0;
				}
				//前半の項はi文字目に○をつけない場合
				//後半の項は○をつける場合
				dp[i][j] = m1*dp[i + 1][j] + m2*dp[i + 1][j + 1];
				dp[i][j] %= mod;
			}
		}

		//debug
//		for(int i = 0; i < dp.length ; i++){
//			for(int j = 0; j < dp[0].length ; j++){
//				System.out.print(dp[i][j]+" ");
//			}
//			System.out.println();
//		}

		System.out.println(dp[0][0]);
	}

	static void printArray(int[] array){
		for(int i = 0; i < array.length; i++){
			System.out.print(array[i]+" ");
		}
		System.out.println();
	}

	static void printArray(long[] array){
		for(int i = 0; i < array.length; i++){
			System.out.print(array[i]+" ");
		}
		System.out.println();
	}

}

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

int main() {
    int N;
    cin>>N;
    map<int,int> mp;
    for(int i=1;i<=N;i++){
        int A;
        cin >>A;
        mp[A]=i;
    }
    for(auto p:mp)cout<<p.second<<" ";
    cout<<endl;
}

Measured memory_bytes: 5504
import java.util.Scanner;

public class Main {
	void run() {
		Scanner scan = new Scanner(System.in);
		String S = scan.next();
		boolean[] s = new boolean[S.length()];
		for (int i = 0; i < S.length(); i++)
			s[i] = S.charAt(i) == '1';
		int ans = 0;
		for (int i = 0; i < S.length() - 1; i++) {
			if (s[i] == s[i + 1]) {
				s[i + 1] = !s[i + 1];
				ans++;
			}
		}
		System.out.println(ans);
	}
    public static void main(String[] args) {
    	new Main().run();
    }
}


Measured memory_bytes: 27352
s = list(map(int, list(input())))
one, two = False, False
if 0 < s[0]*10 + s[1] <= 12:
	one = True
if 0 < s[2]*10 + s[3] <= 12:
	two = True
if one and two:
	print("AMBIGUOUS")
elif one:
	print("MMYY")
elif two:
	print("YYMM")
else:
	print("NA")

Measured memory_bytes: 3060
N, K = map(int,input().split())
eliment = list(map(int,input().split()))
if 0 not in eliment:
    eliment.append(0)
    eliment.sort()
else:
    K -= 1
if K <= 0:
    print(0)
    exit()
endpoint = eliment.index(0)
stpoint = 0 if endpoint - K < 0 else endpoint - K
endpoint = N - K + 1 if endpoint + 1  > N - K else endpoint + 1

#print(eliment,stpoint,endpoint,K)
lessSum=999999999
for i in range(stpoint, endpoint):
    cal = eliment[i+K] - eliment[i] + min(abs(eliment[i+K]),abs(eliment[i]))
    #print(eliment[i],eliment[i+K],cal)
    if lessSum > cal: lessSum = cal
print(lessSum)

Measured memory_bytes: 62576
//atcoder.jp abc 120 d
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mk make_pair
#define pii pair<int,int>
#define fst first
#define scd second
using namespace std;

inline ll read() {
	ll f=1,x=0;
	char ch=getchar();
	
	while(!isdigit(ch)){
	   if(ch=='-')
	      f=-1;
	   ch=getchar();
	}
	
	while(isdigit(ch)){
	   x=x*10+ch-'0';
	   ch=getchar();
	}
	
	return x*f;
}

const int MAXN=1e5+5;
int n,m,fa[MAXN];

struct EDGE {
	int u,v;
}e[MAXN];

ll ans[MAXN],sz[MAXN];

int get_fa(int x) {
	if(x==fa[x]) return x;
	return fa[x]=get_fa(fa[x]);
}

int main() {
    //freopen("","r",stdin);
    //freopen("","w",stdout);
	ios::sync_with_stdio(0);
	cin.tie(0);/*syn加速*/
	
	cin >> n >> m;
	
	for(int i=1;i<=m;++i) {
		cin >> e[i].u >> e[i].v;
	}
	
	for(int i=1;i<=n;++i) 
	   fa[i]=i,sz[i]=1;
	
	ans[m]=(ll)n*(n-1)/2;   //c(n,2)
	
	for(int i=m;i>=1;--i) {
		int u=get_fa(e[i].u),v=get_fa(e[i].v);
		if(u==v) 
		    ans[i-1]=ans[i];
		else {
			ans[i-1]=ans[i]-sz[v]*sz[u];
			sz[v]+=sz[u]; fa[u]=v;
		}
	}
	
	for(int i=1;i<=m;++i) 
	   cout<<ans[i]<<endl;
	return 0;
}

Measured memory_bytes: 4096
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;

//
#define int long long
#define pb(x) push_back(x)
#define m0(x) memset((x), 0, sizeof(x))
#define mm(x) memset((x), -1, sizeof(x))

//container
#define ALL(x) (x).begin(), (x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define EACH(i, c) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define UNIQUE(v) (v).erase(unique((v).begin(), (v).end()), (v).end());
#define PERM(c) \
  sort(ALL(c)); \
  for (bool c##p = 1; c##p; c##p = next_permutation(ALL(c)))

// debug
#define GET_VAR_NAME(variable) #variable
#define test(x) cout << GET_VAR_NAME(x) << " = " << x << endl;

// bit_macro
#define bit(n) (1LL << (n))
#define bitset(a, b) (a) |= (1 << (b))
#define bitunset(a, b) (a) |= ~(1 << (b))
#define bitcheck(a, b) ((((a) >> (b)) & 1) == 1)
#define bitcount(a) __builtin_popcountll((a))

//typedef
typedef long long lint;
typedef unsigned long long ull;
typedef complex<long double> Complex;
typedef pair<int, int> P;
typedef tuple<int, int, int> TP;
typedef vector<int> vec;
typedef vector<vec> mat;

//constant
const int INF = (int)1e18;
const int MOD = (int)1e9 + 7;
const double EPS = (double)1e-10;
const int dx[] = {-1, 0, 0, 1, 0, -1, -1, 1, 1};
const int dy[] = {0, -1, 1, 0, 0, 1, -1, 1, -1};

//
template <typename T>
void chmax(T &a, T b) { a = max(a, b); }
template <typename T>
void chmin(T &a, T b) { a = min(a, b); }
//
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T>
inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

//
struct Accelerate_Cin {
  Accelerate_Cin() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(20);
  };
};

int H, W;
string s[410];
bool vis[410][410];

int x = 0, y = 0;

void rec(int h, int w) {
  if (vis[h][w] == true) return;
  vis[h][w] = true;
  for (int i = 0; i < 4; i++) {
    int ny = h + dy[i], nx = w + dx[i];
    if (ny >= H || ny < 0 || nx >= W || nx < 0 || vis[ny][nx] || s[ny][nx] == s[h][w]) continue;
    rec(ny, nx);
  }

  if (s[h][w] == '.') {
    x++;
  } else {
    y++;
  }
  return;
}

signed main() {
  cin >> H >> W;
  for (int i = 0; i < H; i++) {
    cin >> s[i];
  }

  int ans = 0;
  for (int h = 0; h < H; h++) {
    for (int j = 0; j < W; j++) {
      rec(h, j);
      ans += x * y;
      x = 0;
      y = 0;
    }
  }

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


Measured memory_bytes: 15616
#include "bits/stdc++.h"

#define MOD 1000000007
#define rep(i, n) for(ll i=0; i < (n); i++)
#define ALL(v) v.begin(),v.end()
#define DUMP(i, v)for(ll i=0;i<v.size();i++)cout<<v[i]<<" "

using namespace std;
typedef long long int ll;
typedef vector<ll> llvec;
typedef vector<double> dvec;
typedef pair<ll, ll> P;
struct Edge{ll from, to, cost;};
struct node{ll cost, to;
  bool friend operator>(node a, node b){
    return a.cost>b.cost;
  }
};

ll mod(ll a, ll mod){
  ll res = a%mod;
  if(res<0)res=res + mod;
  return res;
}

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

ll modinv(ll a, ll mod){
  return modpow(a, mod-2, mod);
}

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

bool is_prime(ll n){
  ll i = 2;
  if(n==1)return false;
  if(n==2)return true;
  bool res = true;
  while(i*i <n){
    if(n%i==0){
      res = false;
    }
    i = i+1;
  }

  //if(i==1)res = false;
  if(n%i==0)res=false;
  return res;
}
ll N, K;
vector<long double> An, Ap;
ll Nn, Np, Nz;


bool chk1(ll m){//積がm以下の組み合わせがK個未満か調べる
  ll ans = 0;
  for(ll i=0;i<Nn;i++){
    //ans+=(ll)(Ap.end() - lower_bound(ALL(Ap), (m+An[i]-1)/An[i]) );
    ans+=(ll)(Ap.end() - lower_bound(ALL(Ap), (long double) -m/An[i]) );
    if(ans>=K)break;
  }
  //cout << ans << "  at >"<<m << endl; 
  return ans < K;
}

bool chk2(ll m){//積がm以下の組み合わせがK個未満か調べる
  ll ans = 0;
  for(ll i=1;i<Nn;i++){
    ll tmp = (ll)(upper_bound(ALL(An), (long double)m/An[i]) - An.begin());
    ll cand = min(tmp, i);
    ans += cand;
  }
  for(ll i=1;i<Np;i++){
    ll tmp = (ll)(upper_bound(ALL(Ap),(long double)m/Ap[i]) - Ap.begin());
    ll cand = min(tmp, i);
    ans += cand;
    
  }
  //cout << ans << "  at >"<<m << endl; 
  return ans < K;
}



/**************************************
** A main function starts from here  **
***************************************/
int main(){
  cin >> N >> K;
  rep(i, N){
    ll tmp;
    cin >> tmp;
    if(tmp>0)Ap.push_back(tmp);
    if(tmp<0)An.push_back(-tmp);
  }
  sort(ALL(Ap));
  sort(ALL(An));

  Nn = An.size();
  Np = Ap.size();
  Nz = N - Nn -Np;

  if(K<=Nn*Np){
    ll ok = -1e18;
    ll ng = 0;
    while(abs(ok-ng)>1){
      ll m=(ok+ng)/2;
      if(chk1(m))ok = m;
      else ng=m;
      //cout << ok <<" " << ng << " " << m << endl;
    }
    cout << ng;
  }else{
    K -= Nn*Np;
    if (K<=(Nz*(Nz-1)/2 + Nz*(Np+Nn))){
      cout << 0;
      return 0;
    }else{
      K -= (Nz*(Nz-1)/2 + Nz*(Np+Nn));
      //cout << K << endl;
      ll ok = 0;
      ll ng = 1e18;
      while(abs(ok-ng)>1){
        ll m=(ok+ng)/2;
        if(chk2(m))ok = m;
        else ng=m;
        //cout << ok <<" " << ng << " " << m << endl;
      }
      cout << ng;
    }  
  }
  return 0;
}


Measured memory_bytes: 6000
#include<stdio.h>

int main(void){
	int n,a,b,o,ab,i;
	char c[3];
	
	a=0;
	b=0;
	o=0;
	ab=0;
	
	while(scanf("%d,%s",&n,c)!=EOF){
		//printf("%s\n",c);
		if(c[0]=='A' && (int)strlen(c)==1)a++;
		else if(c[0]=='B')b++;
		else if(c[0]=='O')o++;
		else ab++;
		
		for(i=0;i<3;i++)c[i]=NULL;
		
	}
	
	printf("%d\n%d\n%d\n%d\n",a,b,ab,o);
	
	return 0;
}

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

int gcd(int a, int b){
    if(a%b){
        return gcd(b,a%b);
    } else {
        return b;
    }
}

int main(){
    int n; cin >> n;
    long long ans=0;
    for(int a=1; a<=n; a++){
        for(int b=1; b<=n; b++){
            for(int c=1; c<=n; c++){
                ans += gcd(gcd(a,b),c);
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3636
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>
  
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
  
using namespace std;
  
typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;
  
const int INF=1<<29;
const double EPS=1e-9;
  
const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1};


int main() {
  int N, L;
  cin >> N >> L;
  vector<string> S(N);
  for (int i = 0; i < N; i++) {
    cin >> S[i];
  }
  sort(S.begin(), S.end());
  string ans = "";
  for (int i = 0; i < N; i++) {
    ans += S[i];
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10 ** 8)
from itertools import accumulate
from itertools import permutations
from itertools import combinations
from collections import defaultdict
from collections import Counter
import fractions
import math
from collections import deque
from bisect import bisect_left
from bisect import bisect_right
from bisect import insort_left
import itertools
from heapq import heapify
from heapq import heappop
from heapq import heappush
import heapq
from copy import deepcopy
from decimal import Decimal
alf = list("abcdefghijklmnopqrstuvwxyz")
ALF = list("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
#import numpy as np
INF = float("inf")
#d = defaultdict(int)
#d = defaultdict(list)
N,M = map(int,input().split())
fac = [1, 1]
inv = [0, 1]
finv = [1, 1]
MOD = 10**9+7
fac = [1, 1]
inv = [0, 1]
finv = [1, 1]
for i in range(2, M+1):
    fac.append(fac[-1] * i % MOD)
    inv.append(MOD - inv[MOD%i] * (MOD//i) % MOD)
    finv.append(finv[-1] * inv[-1] % MOD) 
def comb_mod(n, r, m):  #nCr mod m
    if (n<0 or r<0 or n<r): return 0
    r = min(r, n-r)
    return fac[n] * finv[n-r] * finv[r] % m

def chofuku(n,r): # nHr mod MOD の計算
    return comb_mod(n+r-1,r)
 
def nPr(n,r,m): #nPr mod m の計算
    return fac[n]*finv[n-r]%m
ans = 0
for i in range(1,N+1):
    if i % 2 == 1:
        flag = 1
    else:
        flag = -1
    s = flag*comb_mod(N,i,MOD)*nPr(M-i,N-i,MOD)
    ans += s
    if ans > MOD:
        ans %= MOD
ans1 = 1
for i in range(N):
    ans1 *= (M-i)
    ans1 %= MOD
ans2 = (ans1*ans1)%MOD
ans3 = (ans*nPr(M,N,MOD)) %MOD
print((ans2-ans3)%MOD)


Measured memory_bytes: 167768
using System;
using System.Linq;

namespace ACTest
{
    class AOJDPLB
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            int num = int.Parse(input[0]);
            int value = int.Parse(input[1])+1;
            int[] val = new int[num];
            int[] wgt = new int[num];

            for (int i = 0; i < num; i++)
            {
                input = Console.ReadLine().Split(' ');
                val[i] = int.Parse(input[0]);
                wgt[i] = int.Parse(input[1]);
            }

            //DP
            int[] tempVal = new int[value];
            int[] newVal = new int[value];
            tempVal = Enumerable.Repeat<int>(0, value).ToArray();

            for (int i = 0; i < num; i++)
            {
                for (int j = 0; j < value; j++)
                {
                    int Temp = 0;
                    if (j >= wgt[i])
                    {
                        Temp = tempVal[j - wgt[i]];
                        newVal[j] = Math.Max(Temp + val[i], tempVal[j]);
                    }
                    else
                    {
                        newVal[j] = tempVal[j];
                    }
                   
                }
                newVal.CopyTo(tempVal, 0);
            }
            Console.WriteLine(newVal[value-1]);
            //while (true) ;

        }
    }
}

Measured memory_bytes: 20196
import java.util.*;
class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long x = sc.nextLong();
        long y = sc.nextLong();
        if(x==2 || y==2) System.out.println(0);
        else System.out.println(Math.max(x-2,1)*Math.max(1,y-2));
    }
}

Measured memory_bytes: 23636
import math

K = int(input())

ans = 0
for i in range(1, K+1):
    for j in range(i, K+1):
        for k in range(j, K+1):
            x = math.gcd(math.gcd(i, j), k)
            if i == j == k:
                ans += x
            elif i != j != k:
                ans += x * 6
            else:
                ans += x * 3

print(ans)

Measured memory_bytes: 9196