akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
const int N=1000;
int d1[N],d2[N],n;
int main()
{
    cin>>n;
    int flag=0;
    for(int i=1;i<=n;i++)
    {
        cin>>d1[i]>>d2[i];
    }
    for(int i=1;i<=n-2;i++)
    {
        if(d1[i]==d2[i]&&d1[i+1]==d2[i+1]&&d1[i+2]==d2[i+2])
        {
             flag=1;
             break;
        }
    }
    if(flag==1)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
}


Measured memory_bytes: 3556
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define fi first
#define se second
#define pb push_back
#define mod 1000000007
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

using namespace std;

int main()
{
    IOS;
    ll n,m;
    cin>>n>>m;
    ll s[n],t[m];
    for(int i=0;i<n;i++) cin>>s[i];
    for(int i=0;i<m;i++) cin>>t[i];
    ll dp[n+1][m+1];
    memset(dp,0,sizeof dp);
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            dp[i][j]=(dp[i-1][j]+dp[i][j-1])%mod;
            dp[i][j]=(dp[i][j]-dp[i-1][j-1]+mod)%mod;
            if(s[i-1]==t[j-1])
            {
                dp[i][j]=(1+(dp[i][j]+dp[i-1][j-1])%mod)%mod;
            }
        }
    }
    cout<<(dp[n][m]+1)%mod<<endl;
}
 

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

int main() {
  string s;
  cin>>s;
  if(s[0]==s[1]&&s[0]!=s[2]&&s[2]==s[3]){
    cout<<"Yes"<<endl;
  }
  else if(s[0]==s[2]&&s[0]!=s[1]&&s[1]==s[3]){
    cout<<"Yes"<<endl;
  }
  else if(s[0]==s[3]&&s[0]!=s[1]&&s[1]==s[2]){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
  
}

Measured memory_bytes: 256
#include <iostream>
#include <ccomplex>
#include <vector>
#include <cassert>

using namespace std;

const double PI = acos(-1);

typedef complex<double> Comp;

bool is_pow_of2(int n) {
	int a = 1;
	while (n >= a) {
		if (n == a) {
			return true;
		}
		a <<= 1;
	}
	return false;
}


vector<Comp> fft(vector<Comp> v) {
	int n = v.size();
	assert(is_pow_of2(n));

	for (int j = 1, i = 0; j < n - 1; j++) {
		for (int k = n >> 1; k >(i ^= k); k >>= 1);
		if (j < i) swap(v[i], v[j]);
	}

	for (int m = 2; m <= n; m <<= 1) {
		double deg = (-1) * 2 * PI / m;
		Comp r(cos(deg), sin(deg));
		for (int i = 0;i < n;i += m) {
			Comp w(1, 0);
			for (int j = i, k = i + m / 2;k < i + m;j++, k++) {
				Comp t1 = v[j], t2 = w*v[k];
				v[j] = t1 + t2, v[k] = t1 - t2;
				w *= r;
			}
		}
	}
	return v;
}

vector<Comp> ifft(vector<Comp> v) {
	int n = v.size();
	assert(is_pow_of2(n));
	for (int j = 1, i = 0; j < n - 1; j++) {
		for (int k = n >> 1; k >(i ^= k); k >>= 1);
		if (j < i) swap(v[i], v[j]);
	}
	for (int m = 2; m <= n; m <<= 1) {
		double deg = 2 * PI / m;
		Comp r(cos(deg), sin(deg));
		for (int i = 0;i < n;i += m) {
			Comp w(1, 0);
			for (int j = i, k = i + m / 2;k < i + m;j++, k++) {
				Comp t1 = v[j], t2 = w*v[k];
				v[j] = t1 + t2, v[k] = t1 - t2;
				w *= r;
			}
		}
	}
	for (int i = 0; i < n;++i) v[i] *= 1.0 / n;
	return v;
}

vector<Comp> convolution(vector<Comp> P, vector<Comp> Q) {
	P = fft(P), Q = fft(Q);
	for (int i = 0;i < P.size();i++) P[i] *= Q[i];
	return ifft(P);
}

#include <bits/stdc++.h>
#define rep(i,n) for(int i=0,i##_len=n;i<i##_len;i++)
#define all(x) begin(x),end(x)
#define lim(x,r,l) (r<=x&&x<l)

#define int long long

signed main(){
  int n; cin >> n;
  vector<vector<int>> c(n, vector<int>(n, 0));
  int zero = 0;
  rep(i,n)rep(j,n){
    int cc; cin >> cc;
    c[i][j] = cc;
    if(cc>=2) zero += (cc-1)*(cc) / 2;
  }
  vector<Comp> a(1 << 22), b(1 << 22);

  rep(i,n){rep(j,n){
    a[2*n * i + j] = c[i][j];
    b[2*n * i + j] = c[n - i - 1][n - j - 1];
  }}

  vector<Comp> res = convolution(a, b);

  double sum = 0;
  int num = 0;
  map<int, int> ans;

  rep(i, res.size()){
    int px = n - i / (2*n) - 1;
    int py = n - i % (2*n) - 1;
    int s = real(res[i]) + 0.5;
    int len = px*px + py*py;
    //cout << s << endl;
    if(s==0) {continue;}
    if(len == 0) {continue;}
    if(ans.find(len) != ans.end()){
      ans[len] += s;
    }else{
      ans[len] = s;
    }
    sum += sqrt(len) * s;
    num += s;
  }

  cout << setprecision(12) << sum / 2 /  (num / 2+ zero) << endl;
  int ii = 0;
  if(zero>0){
    cout <<"0 " << zero << endl;
    ii++;
  }
  for(auto aa: ans){
    if(ii>=10000) break;
    int l, s; tie(l, s) = aa;
    cout << l << " " << s / 2<< endl;
    ii++;
  }

}

Measured memory_bytes: 339276
#include<bits/stdc++.h>
using namespace std;pair<int,int>p[1<<20];int N,i,c,b,n[1<<20],d[1<<20];main(){cin>>N;for(;i<N;i++)cin>>c>>b,p[i]={c,c+b};sort(p,p+N);for(d[N]=1;c=i--;d[i]=(d[i+1]+d[n[i]=c])%998244353)for(;c<N&&p[c].first<p[i].second;c=n[c]);cout<<*d;}

Measured memory_bytes: 5248
#include <chrono>

#include <iostream>
#include <iomanip>
#include <algorithm>
#include <bitset>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <time.h>
#include <random>
#include <string>
#include <cassert>
#include <vector>
#include <ostream>
#include <istream>
#include <stack>
#include <deque>
#include <queue>
#include <functional>

using namespace std;

#define int long long
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define pii pair<int, int>
#define ld long double

ostream& operator << (ostream &a, const vector<int> &b) {
    for (auto k : b) cout << k << " ";
    return a;
}

#ifdef LOCAL
    #define dbg(x) cout << #x << " : " << (x) << "\n";
    const int INF = 1e18;
//    const int mod = 2600000069;
//    const int p = 10;
//    const ld PI = 3.1415926535;
#else
    #define dbg(x)
    const int INF = 1e18;
//    const int mod = 2600000069;
//    const int p = 179;
//    const ld PI = 3.1415926535;
#endif

//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,sse3,sse4")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("fast-math")
//#pragma GCC target("avx2")
//#pragma GCC optimize("section-anchors")
//#pragma GCC optimize("profile-values,profile-reorder-functions,tracer")
//#pragma GCC optimize("vpt")
//#pragma GCC optimize("rename-registers")
//#pragma GCC optimize("move-loop-invariants")
//#pragma GCC optimize("unswitch-loops")
//#pragma GCC optimize("function-sections")
//#pragma GCC optimize("data-sections")

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

signed main() {
    #ifdef LOCAL
    #else
//        freopen("capitals.in", "r", stdin);
//        freopen("capitals.out", "w", stdout);
    #endif
    int n, m;
    cin >> n >> m;
    vector<int> a(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    sort(all(a));
    a.resize(unique(all(a)) - a.begin());
    n = a.size();
    int kek = a[0];
    bool one = 0;
    for (int i = 0; i < n; i++) {
        kek = (kek * a[i]) / gcd(kek, a[i]);
        if (kek > m) {
            one = 1;
            break;
        }
    }
    int val = -1;
    int lol = kek / 2;
    bool ok = 1;
    for (int i = 0; i < n; i++) {
        ok &= ((lol - a[i] / 2) % a[i] == 0);
    }
    if (!ok) cout << 0;
    else cout << (m - lol + kek) / kek;
}


Measured memory_bytes: 1024
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))

using namespace std;

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

const ll mod=1e9+7;

int main(){
    ll x,y;
    cin >> x >> y;
    for(ll i=0;i<=x;i++){
        if((i*2+(x-i)*4)==y){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
} 


Measured memory_bytes: 3628
#include <stdio.h>  
#include <algorithm>  
#include <assert.h>
#include <bitset>
#include <cmath>  
#include <complex>  
#include <deque>  
#include <functional>  
#include <iostream>  
#include <limits.h>  
#include <map>  
#include <math.h>  
#include <queue>  
#include <set>  
#include <stdlib.h>  
#include <string.h>  
#include <string>  
#include <time.h>  
#include <unordered_map>  
#include <unordered_set>  
#include <vector>  
#include <chrono>
#include <random>
#include <time.h>
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pq priority_queue<int>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define vec vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define endl "\n"
#define all(c) begin(c),end(c)
using namespace std;
int in() {int x;scanf("%d",&x);return x;}
ll lin() {ll x;scanf("%lld",&x);return x;}

#define INF 1e9+7
#define LLINF 1e18+7
#define N 500000
ll MOD=1e9+7;
int dp[1<<26+2];
main(){
    string ss;cin>>ss;
    rep(i,ss.size()-1){
        if(ss[i]=='A'&&ss[i+1]=='C'){
            cout<<"Yes";
            return 0;
        }
    }
    cout<<"No";
    return 0;
}



Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		long n = sc.nextLong();
		long min = Long.MAX_VALUE;
		for (long i = 1; i <= Math.sqrt(n); i++) {
		    if (n % i == 0) {
		        min = Math.min(min, i - 1 + n / i - 1);
		    }
		}
		System.out.println(min);
   }
}


Measured memory_bytes: 23764
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define gc getchar
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(),(x).end()
#define x1 uvuvwevwevwe
#define y1 onyetenyevwe
#define x2 ugwemubwem
#define y2 ossas
typedef long long LL;
typedef long double LD;
typedef pair<int,int> pii;
template <typename T> void scan(T &angka){
	angka=0;char input=gc();T kali=1;
	while(!(48<=input&&input<=57)){	if(input=='-')	kali=-1;input=gc();}
	while(48<=input&&input<=57)	angka=(angka<<3)+(angka<<1)+input-48,input=gc();angka*=kali;
}
template <typename T1,typename T2> void scan(T1 &angka1,T2 &angka2){
	scan(angka1);scan(angka2);
}
int n,m;
int par[100005],pos[100005];
int finds(int x){
	if(par[x]!=x)
		par[x]=finds(par[x]);
	return par[x];
}
bool connected(int u,int v){
	return finds(u)==finds(v);
}
void gabung(int u,int v){
	u=finds(u);
	v=finds(v);
	if(u==v)
		return;
	par[u]=v;
}
int main()
{
	scan(n,m);
	for(int i=1;i<=n;i++)
	{
		par[i]=i;
		int input;
		scan(input);
		pos[input]=i;
	}
	for(int i=0;i<m;i++)
	{
		int u,v;
		scan(u,v);
		gabung(u,v);
	}
	int ans=0;
	for(int i=1;i<=n;i++)
		if(connected(pos[i],i))
			ans++;
	cout<<ans<<endl;
}


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

int main() {
    int n;cin >> n;
    long long k;cin >> k;
    vector<long long> a(n);
    for(int i=0;i<n;i++){
        cin >> a[i];
    }

    vector<int> cnt(40, 0);
    for(int i=0;i<n;i++){
        for(int j=0;j<40;j++){
            cnt[j] += a[i] >> j & 1;
        }
    }

    long long ans = 0;

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

    long long now = 0;
    for(int i=40;i>=0;i--){
        int bit = k >> i & 1;
        if(bit){
            // 0 greedy
            long long d = 0;
            for(int j=i-1;j>=0;j--){
                d += max(0LL, (1LL << j) * ((n - cnt[j]) - (cnt[j])));
            }
            ans = max(ans, sum + now + d);

            // 1
            now += (1LL << i) * ((n - cnt[i]) - (cnt[i]));
        }else{
            // 0
            now += 0;
        }
    }
    ans = max(ans, sum + now);

    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 1024
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;

namespace atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var ab = Console.ReadLine().Split(' ').Select(num => long.Parse(num)).ToArray();
            var gcd = GCD(ab[0], ab[1]);

            var pCnt = 1;
            for (var i = 2; i <= Math.Sqrt(gcd); i++)
            {
                if (gcd % i == 0)
                {
                    pCnt++;
                    while (gcd % i == 0) gcd /= i;
                }
            }

            if (gcd != 1) pCnt++;

            Console.WriteLine(pCnt);

            long GCD(long x, long y)
            {
                var max = Math.Max(x, y);
                var min = Math.Min(x, y);

                var remain = max % min;
                if (remain == 0)
                {
                    return min;
                }
                else
                {
                    return GCD(min, remain);
                }
            }
        }
    }
}

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

const int MOD = 1000000007;
const int INF = 1e9;

//long long
using ll = long long;

//出力系
#define print(x) cout << x << endl
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
 
// begin() end()
#define all(x) (x).begin(),(x).end()

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

//最大公約数 
unsigned gcd(unsigned a, unsigned b) {
  if(a < b) return gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
} 

int main(){
    int N;
    cin >> N;
    vector<int>p(N);
    int cnt = 0;
    REP(i, N) {
        cin >> p.at(i);
        p.at(i)--;
        if(i != p.at(i)) cnt++;
    }

if(cnt == 2 || cnt == 0) YES;
else NO;

}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#define N 10000
#define NIL -1
#define max(a,b) ((a) > (b) ? (a) : (b))

struct Node {int p,l,r;};
struct Node T[N];

int H[N];

int getDepth(u){
  int d = 0;
  while(T[u].p != NIL){
    u = T[u].p;
    d++;
  }
  return d;
}

int setHight(int H[],int u){
  int h1 = 0, h2 = 0;
  if(T[u].r != NIL){
    h1 = setHight(H,T[u].r) + 1;
  }
  if(T[u].l != NIL){
    h2 = setHight(H,T[u].l) + 1;
  }

  return H[u] = max(h1,h2);
}

int getSibling(int u){
  if(T[u].p == NIL) return NIL;
  if(T[T[u].p].l != u && T[T[u].p].l != NIL){
    return T[T[u].p].l;
  }
  if(T[T[u].p].r != u && T[T[u].p].r != NIL){
    return T[T[u].p].r;
  }
  return NIL;
}


/*void printChildren(u){
  int c = T[u].l;
  while(c != NIL){
    if(T[c].r == NIL) printf("%d",c);
    else printf("%d, ",c);
    c = T[c].r;
  }
  }*/

int main(){
  int n,i,j,d,v,c,l,r;
  
  scanf("%d",&n);

  for(i = 0; i < n; i++){
    T[i].p = NIL;
    T[i].l = NIL;
    T[i].r = NIL;
  }

  /* for(i = 0; i < n; i++){
    scanf("%d%d",&v,&d);
    for(j = 0; j < d; j++){
      scanf("%d",&c);
      if(j == 0) T[v].l = c;
      else T[l].r = c;
      l = c;
      T[c].p = v;
    }
    }*/
  for(i = 0; i < n; i++){
    scanf("%d%d%d",&v,&l,&r);
    T[v].l = l;
    T[v].r = r;
    if(l != NIL) T[l].p = v;
    if(r != NIL) T[r].p = v;
  }
  
  for(i = 0; i < n; i++){
    if(T[i].p == NIL) r = i;
  }
  for(i = 0; i < n; i++){
    printf("node %d: ",i);
    printf("parent = %d, ",T[i].p);
    printf("sibling = %d, ",getSibling(i));
    int deg = 0;
    if(T[i].l != NIL) deg++;
    if(T[i].r != NIL) deg++;
    printf("degree = %d, ",deg);
    printf("depth = %d, ",getDepth(i));
    setHight(H,i);
    printf("height = %d, ",H[i]);

    if(T[i].p == NIL) printf("root\n");
    else if(T[i].l == NIL && T[i].r == NIL) printf("leaf\n");
    else printf("internal node\n");
    
  }

}



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

inline int pairs(int u) {
    int ans = 1;
    for (int q, p = 2; p*p <= u; ++p)
        if (u%p == 0) {
           for (q = 2, u /= p; u%p == 0; ++q)
        		u /= p;
        	ans *= q; }
    if (u > 1)
    	ans *= 2;
    return ans; }
    
int main() {
    int n, ans = 0; 
    ios_base::sync_with_stdio(0), cin.tie(0), cin >> n;
    for (int u = 1; u < n; ++u)
        ans += pairs(u);
    cout << ans; }


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

using namespace std;

int N, a[100009], frst[100009];
long long s[100009];
char sg[100009];

long long sum (int i, int j)
{
    if (j > N) j = N;
    if (i > j) return 0;
    return s[j] - s[i - 1];
}

int main ()
{
//freopen ("input", "r", stdin);
//freopen ("output", "w", stdout);

scanf ("%d", &N);
scanf ("%d", &a[1]), s[1] = a[1];
for (int i=2; i<=N; i++)
    scanf (" %c %d", &sg[i], &a[i]), s[i] = s[i - 1] + a[i];
frst[N + 1] = N + 1;
for (int i=N; i>=2; i--)
    if (sg[i] == '-') frst[i] = i;
    else frst[i] = frst[i + 1];
long long curr = a[1], ans = -1LL << 50;
for (int i=2; i<=N; i++)
{
    if (sg[i] == '-')
    {
        if (i == 2)
            i = 2;
        ///try putting a bracket right before a[i] and after its preceding minus
        long long curr2 = curr + sum (frst[i + 1], N) - sum (i, frst[i + 1] - 1);
        if (curr2 > ans) ans = curr2;
        ///
        curr -= a[i];
    }
    else curr += a[i];
}
if (curr > ans) ans = curr;
printf ("%lld\n", ans);
return 0;
}


Measured memory_bytes: 1920
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<cstring>
#define N 100005
typedef long long ll;
using namespace std;
ll a[N];
ll b[N];
int main(){
    ll n;
    ll num=0;
    cin>>n;
    for (int i=0;i<n;i++){
        cin>>a[i];
        if (a[i]<=N)
            b[a[i]]++;
        else
            num++;
    }
    for (int i=0;i<=N;i++){
        if (b[i]<i)
            num+=b[i];
        else
            num+=(b[i]-i);
    }
    cout << num << endl;
         return 0;
}


Measured memory_bytes: 1024
using System;

namespace atcoder
{
    internal class Program
    {
        private static void Main(string[] args)
        {
            string indata;
            indata = Console.ReadLine();
            if (Char.IsUpper(char.Parse(indata))){
                Console.WriteLine("A");
            }
            else
            {
                Console.WriteLine("a");
            }
        }
    }
}

Measured memory_bytes: 25876
#include <bits/stdc++.h>
#define pb push_back
#define tam 310000
#define offset 100000
#define se second
#define fi first
#define forr(i,p,n) for(ll i=p;i<n;i++)
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;
ll mult(ll a,ll b, ll p=MOD){return ((a%p)*(b%p))%p;}
ll add(ll a, ll b, ll p=MOD){return (a%p + b%p)%p;}
typedef pair<ll,ll> ii;
ll N,A;
ll dp[60][1000][60];
ll val[60];
ll f(ll posi,ll suma,ll cant)
{
    if (posi==N)
    {
        
        if (cant>0 && suma%A==0 && suma==A*cant)
            return 1;
            return 0;
    }
    if (dp[posi][suma][cant]!=-1)
        return dp[posi][suma][cant];
    ll tot=0;
    tot=f(posi+1,suma+val[posi],cant+1);
    tot+=f(posi+1,suma,cant);
    return dp[posi][suma][cant]=tot;
}
int main()
{
    cin>>N>>A;
    forr(i,0,N)
    {
        cin>>val[i];
    }
    memset(dp,-1,sizeof dp);
    cout<<f(0,0,0)<<endl;
}

Measured memory_bytes: 28416
#include <stdio.h>
#include <vector>
#include <queue>

int main(void) {
  int i, j, k, n, m, a, b;
  scanf("%d%d", &n, &m);
  std::vector<int> vec[n];
  for(i = 0; i < m; ++i) {
    scanf("%d%d", &a, &b);
    a--, b--;
    vec[a].push_back(b);
    vec[b].push_back(a);
  }
  std::queue<int> q;
  for(i = 0; i < vec[0].size(); ++i) q.push(vec[0][i]);
  while(!q.empty()) {
    int t = q.front();
    q.pop();
    for(i = 0; i < vec[t].size(); ++i) if(vec[t][i] == n - 1) {
      printf("POSSIBLE");
      return 0;
    }
  }
  printf("IMPOSSIBLE");
  return 0;
}

Measured memory_bytes: 12400
import math

def makelist(n, m):
    return [[0 for _ in range(m)] for _ in range(n)]

# n = int(input())
# a, b = list(map(int, input().split()))
# 

N = int(input())
S, T = input().split()

ans = []
for i in range(N):
    ans.append(S[i])
    ans.append(T[i])

print("".join(ans))


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

using namespace std;

int main() {
    std::ios::sync_with_stdio(false); 
    cin.tie(nullptr);
    
    int H, W;
    cin >> H >> W;
    vector<string> A(H);
    constexpr int INF = 1'000'000;
    vector<vector<int>> dist(H, vector<int>(W, INF));
    queue<pair<int, int>> q;
    for (int i = 0; i < H; ++i) {
        cin >> A[i];
        for (int j = 0; j < W; ++j) {
            if (A[i][j] == '#') {
                dist[i][j] = 0;
                q.emplace(i, j);
            }
        }
    }
    int dx[]{1, -1, 0, 0};
    int dy[]{0, 0, 1, -1};
    while (!q.empty()) {
        int i = q.front().first, j = q.front().second;
        q.pop();
        for (int k = 0; k < 4; ++k) {
            int ni = i + dx[k], nj = j + dy[k];
            if (ni >= 0 && ni < H && nj >= 0 && nj < W) {
                if (dist[i][j] + 1 < dist[ni][nj]) {
                    q.emplace(ni, nj);
                    dist[ni][nj] = dist[i][j] + 1;
                }
            }
        }
    }
    int res = 0;
    for (int i = 0; i < H; ++i) {
        res = max(res, *max_element(begin(dist[i]), end(dist[i])));
    }
    cout << res << "\n";

    return 0;
}

Measured memory_bytes: 13456
#define _CRT_SECURE_NO_WARNINGS

#include <unordered_map>
#include <string>
#include <math.h>
#include <vector>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#define MAXN 1005
#define INF 0x3f3f3f3f
#define MOD 1000000007
#define PI acos(-1)
typedef long long ll;
typedef unsigned long long ull;

using namespace std;

int n, a[100005];

int cmp(int a, int b) {
	return a > b;
}

int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n; ++i)
		scanf("%d", &a[i]);
	sort(a + 1, a + n + 1,cmp);
	int i = 1, j;
	while (a[i] >= i) ++i;
	--i;
	j = i + 1;
	while (a[j] == i) ++j;
	--j;
	if ((a[i] - i) % 2 || (j - i) % 2)
		cout << "First" << endl;
	else
		cout << "Second" << endl;
}

Measured memory_bytes: 640
#include<iostream>
#include<cstring>
#include<algorithm>
#define ll long long
using namespace std;
int main() {
	int n;
	string s;
	cin>>n;
	cin>>s;
	ll r=0,g=0,b=0;
	for(int i=0; i<s.length(); i++) {
		if(s[i]=='R') {
			r++;
		}
		if(s[i]=='G') {
			g++;
		}
		if(s[i]=='B') {
			b++;
		}
	}
	ll ans=r*g*b;
	ll an=0;
	for(int i=0; i<s.length(); i++) {
		for(int j=i+1; j<n; j++) {
			int k=j+(j-i);
			if(k>n-1) {
				continue;
			}
			if(s[i]!=s[j]&&s[j]!=s[k]&&s[i]!=s[k]) {
				an++;
			}
		}
	}
	printf("%lld\n",ans-an);
//	cout<<ans-an<<endl;
	return 0;
}










Measured memory_bytes: 3688
N,M = map(int,input().split())
A = list(map(int,input().split()))
A.sort()
T = []
for i in range(M):
    a,b = map(int,input().split())
    T.append([b,a])
T.sort(reverse=True)

ans = 0
c = 0
k = 0
t = len(T)
for i in range(N):
    if c == t:
        break
    n = T[c][0]
    l = T[c][1]
    k += 1
    if A[i] < n:
        A[i] = n
    else:
        break
    if k == l:
        c += 1
        k = 0
print(sum(A))

Measured memory_bytes: 76268
#include<iostream>
using namespace std;
int main()
{
  int a,b,c,d,e,k,c2=0;
  cin>>a;
  cin>>b;
  cin>>c;
  cin>>d;
  cin>>e;
  cin>>k;
  int arr[5]={a,b,c,d,e};
  for(int i=4;i>=0;i--)
  {
    for(int j=i-1;j>=0;j--)
    {
      if((arr[i]-arr[j])<=k)
      {
        c2=c2+1;
      }
    }
  }
  if(c2==10)
  {
    cout<<"Yay!";
  }
  else
  {
    cout<<":(";
  }
  return 0;
}

Measured memory_bytes: 256
import numpy as np
import scipy.sparse as sps
import scipy.misc as spm
import collections as col
import functools as func
import itertools as ite
import fractions as frac
import math as ma
from math import cos,sin,tan,sqrt
import cmath as cma
import copy as cp
import sys
import re
sys.setrecursionlimit(10**7)
EPS = sys.float_info.epsilon
PI = np.pi; EXP = np.e; INF = np.inf
MOD = 10**9 + 7

def sinput(): return sys.stdin.readline().strip()
def iinput(): return int(sinput())
def imap(): return map(int, sinput().split())
def fmap(): return map(float, sinput().split())
def iarr(n=0):
    if n: return [0 for _ in range(n)]
    else: return list(imap())
def farr(): return list(fmap())
def sarr(n=0):
    if n: return ["" for _ in range(n)]
    else: return sinput().split()
def adj(n): return [[] for _ in range(n)]

class unionfind():
    def __init__(self, n):
        self.n = n
        # 中身が負の数なら根であり、数字の絶対値はグループ数
        self.parents = [-1] * n
    def find(self, x):
        if self.parents[x] < 0: return x
        self.parents[x] = self.find(self.parents[x])
        return self.parents[x]
    def union(self, x, y):
        x,y = self.find(x), 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())

s,t = sinput(),sinput()
n = len(s)

ans = 0
for i in range(n):
    ss,tt = s[i],t[i]
    if ss==tt: continue
    else: ans += 1
print(ans)


Measured memory_bytes: 38156
integer(16) N,K,i,j
integer(16),allocatable,dimension(:)::A,B,C
integer(16) cnt
integer(16) ans
read*,N,K
allocate(A(N),B(N),C(N))
read*,A
do i=1,N
  cnt=0
  do j=i+1,N
    if(A(i)>A(j))cnt=cnt+1
  end do
  B(i)=cnt
end do
do i=1,N
  cnt=0
  do j=1,N
    if(A(i)>A(j))cnt=cnt+1
  end do
  C(i)=cnt
end do
ans=0
do i=1,N
  ans=mod(ans+B(i)*K,10**9+7)
  ans=mod(ans+C(i)*((K-1)*K)/2,10**9+7)
end do
print"(i0)",ans
end

Measured memory_bytes: 768
n = int(input())
a = [int(input()) for _ in range(n)]
#print(a)
a_sort = sorted(a)
#print(a_sort)

max_number = a_sort[-1]
sub_max_number = a_sort[-2]

for i in range(n):
  if a[i] == max_number:
    print(sub_max_number)
  else:
    print(max_number)


Measured memory_bytes: 14084
#include <bits/stdc++.h>
    #define rep(i,n) for(int i = 0; i < (n); i++)
     
    using namespace std;  
   
    int main() {
     int s;
     cin >> s;
     int h,m,sec;
     h=0;
     m=0;
     sec=0;
     while(true){
     	if(s>=3600){
     		h++;
     		s-=3600;
     	} else if(s>=60){
     		m++;
     		s-=60;
     	} else{
     		sec=s;
     		break;
     	}
     }
     
     cout << h << ':'<< m << ':'<< sec << '\n';
     	
     return 0;
    }


Measured memory_bytes: 3112
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define all(x) (x).begin(),(x).end()

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

typedef long long ll;

using namespace std;

int dp[3002];
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  int mod=1e9+7;
  string s;
  cin>>n>>s;
  dp[1]=1;
  rep(i,n-1)
  {
    if(s[i]=='<')
    {
      repi(j,1,i+1)
      {
        dp[j+1]+=dp[j];
        dp[j+1]%=mod;
      }
      for(int j=i+2;j>=1;j--)
      {
        dp[j]=dp[j-1];
      }
    }
    else
    {
      for(int j=i+1;j>1;j--)
      {
        dp[j-1]+=dp[j];
        dp[j-1]%=mod;
      }
    }
  }
  ll res=0;
  repi(i,1,n+1)res+=dp[i];
  cout<<res%mod<<endl;

  return 0;

}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int num = 2;
    if (n==1){
      System.out.println(1);
    }else{
      while(num*2<=n){
        num = num*2;
      }
      System.out.println(num);
    }
  }
}

Measured memory_bytes: 23764
import math

A,B,H,M=map(int,input().split())

theta=2*math.pi*(H/12)+2*math.pi*(M/(60*12))
phi=2*math.pi*(M/60)

a=A*math.cos(theta)-B*math.cos(phi)
b=A*math.sin(theta)-B*math.sin(phi)

dist=math.sqrt(a**2+b**2)

print(dist)

Measured memory_bytes: 9580
#include <bits/stdc++.h>                                   
using namespace std;                                       
                                                           
struct shop{                                               
  long int a;                                              
  long int b;                                              
  bool operator<(const shop& another) const{               
    return a < another.a;                                  
  };                                                       
};                                                         
                                                           
int main(void){                                            
  int n,m,count;                                           
  cin >> n >> m;                                           
  vector<shop> s;                                          
  long long int ans = 0;                                   
  struct shop ss;                                          
  for(int i = 0; i < n;++i){                               
    cin >> ss.a >> ss.b;                                   
    s.push_back(ss);                                       
  }                                                        
  sort(s.begin(),s.end());                                 
  count = m;                                               
  vector<struct shop>::iterator itr = s.begin();           
  while(count != 0){                                       
    if(count > itr->b){                                    
      ans += itr->a * itr->b;                              
      count -= itr->b;                                     
      itr++;                                               
    }                                                      
    else{                                                  
      ans += itr->a * count;                               
      count = 0;                                           
    }                                                      
  }                                                        
  cout << ans << endl;                                     
  return 0;                                                
}                                                          
                                                           

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

void print_res(vector<int> A) {
    for (auto e : A) {
        if (e <= 0) {
            cout << "No" << endl;
        }
        else {
            cout << "Yes" << endl;
        }
    }
}

void pri(vector<int> A) {
    cout << endl;
    for (auto e : A) {
        cout << e << ' ';
    }
    cout << endl;
}

int main(void) {
	int n, k, q;

    cin >> n >> k >> q;

    vector<int> A(n);

    for (auto& e : A) {
        e = k - q;
    }
    

    //pri(A);
    int winner;
    for (int i = 0; i < q; i++) {
        cin >> winner;
        A[winner - 1]++;
    }

    print_res(A);

	return 0;
}


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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = ((int)(n)-1); i >= 0; i--)
#define all(x) (x).begin(),(x).end()

using namespace std;
using ll = long long;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> P;
 
const int INF = 1e9;
//const ll INF = 1e18;
const double EPS = 1e-10;
const int MOD = 1e9+7;
const double PI = acos(-1.0);

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

int main()
{
	int x,a,b;
	cin >> x >> a >> b;
	if(abs(x-a) < abs(x-b)) cout << 'A' << endl;
	else cout << 'B' << endl;	

	return 0;
}

Measured memory_bytes: 256
/**
 * Created by hiramekun at 03:43 on 2020-06-21.
 */
#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using ld = long double;
using vl = vector<ll>;
using vvl = vector<vl>;
using vb = vector<bool>;
using P = pair<ll, ll>;
template<typename T> using pq = priority_queue<T>;
template<typename T> using minpq = priority_queue<T, vector<T>, greater<T>>;
template<typename T, typename K> using ump = unordered_map<T, K>;
const ll dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll e5 = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);

#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for (ll i = ll(n - 1); i >= 0; i--)
#define each(i, mp) for (auto &i : mp)
#define eb emplace_back
#define F first
#define S second
#define all(obj) (obj).begin(), (obj).end()

template<class T>
ostream &operator<<(ostream &out, const vector<T> &list) {
    ll n = list.size();
    rep(i, n) out << list[i] << ' ';
    return out;
}

template<class T>
istream &operator>>(istream &in, vector<T> &list) {
    ll n = list.size();
    rep(i, n) in >> list[i];
    return in;
}

template<class T>
ostream &operator<<(ostream &out, const vector<vector<T>> &list) {
    ll n = list.size();
    rep(i, n) out << list[i] << '\n';
    return out;
}

/* ------------- ANSWER ------------- */
/* ---------------------------------- */

void solve() {
    ll n;
    cin >> n;
    vl a(n);
    cin >> a;
    multiset<ll> s(all(a));
    ll ans = 0;
    while (!s.empty()) {
        ll now = *--s.end();
        s.erase(--s.end());
        ll val = 1;
        while (val <= now) val *= 2;
        if (s.find(val - now) != s.end()) {
            ans++;
            s.erase(s.find(val - now));
        }
    }
    cout << ans << '\n';
}

int main() {
#ifdef MY_DEBUG
    while (true) {
#endif
        solve();
#ifdef MY_DEBUG
    }
#endif
    return 0;
}

Measured memory_bytes: 14324
#include<cstdio>
#include<algorithm>
using namespace std;typedef long long ll;
int n;int p[20];int c[20];int g;int res=0x3f3f3f3f;
int main()
{
	scanf("%d%d",&n,&g);g/=100;
	for(int i=0;i<n;i++)scanf("%d%d",&p[i],&c[i]);
	for(int i=0;i<n;i++)c[i]/=100;
	for(int i=0;i<(1<<n);i++)
	{
		int tot=0;int ret=0;
		for(int j=0,t=i;t;t>>=1,j++)tot+=(t&1)*(p[j]*(j+1)+c[j]),ret+=(t&1)*p[j];
		//printf("i=%d,tot=%d\n",i,tot);
		if(tot>=g)res=min(ret,res);
		else 
		{
			for(int j=n-1;j>=0;j--)
				if(((i>>j)&1)==0)
				{
					if(tot+p[j]*(j+1)<g);
					else {ret+=(g-tot+j)/(j+1);res=min(res,ret);}
					goto ed;
				}
		}ed:;
	}printf("%d",res);return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define REP(i,a,b) for(int i=(a);i<(b);i++)
#define RREP(i,a,b) for(int i=(a);i>=(b);i--)
#define pq priority_queue
#define P pair<int,int>
#define P2 pair<int,P>
#define P3 pair<int,P2>
typedef long long ll; typedef long double ld;
using namespace std;
const int INF=1e9, MOD=1e9+7, around[]={0,1,1,-1,-1,0,-1,1,0,0};
const ll LINF=1e18;
const ld PI=abs(acos(-1));

int main(){
	int n,k; cin >> n >> k; int a[5010];
	REP(i,0,n) cin >> a[i];
	
	ll s = 0; sort(a, a+n); reverse(a, a+n);
	int ans = n;
	REP(i,0,n){
		if(s + a[i] < k) s += a[i];
		else ans = n - i - 1;
	}
	
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
(function(stdin) {
  // Define Function

  // Declare Variable
  const inputs = stdin.toString().trim().split('\n');

  // Main Procedure
  const result = (function(x) {

    return Math.pow(x, 3);

  }(parseInt(inputs[0], 10)));

  console.log(result);

}(require('fs').readFileSync('/dev/stdin', 'utf8')));

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

int main(void){

int n ;
int ar[100] ;
/* 配列の宣言は必ず定数式で行う。何か引数を引いてきて、、、ということはできな

い。やるならmalloc関数などを使う*/

cin >> n ;


for(int i=0;i<n;i++){
cin >> ar[i] ;
}

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

}

Measured memory_bytes: 1160
#include <iostream>
#include <vector>
#include <unordered_map>

using namespace std;

int main()
{
    int n;
    cin >> n;
    vector<int> primes;

    primes.push_back(2);
    for (int i = 3; i <= n; i += 2) {
        int x = 2;
        while (x * x < i) {
            if (i % x == 0) {
                break;
            }
            ++x;
        }
        if (x * x >= i) {
            primes.push_back(i);
        }
    }
    unordered_map<int, int> map;
    for (int i = 2; i <= n; ++i) {
        int t = i;
        for (auto p : primes) {
            while (t % p == 0) {
                ++map[p];
                t /= p;
            }
        }
    }
    long ans = 1;
    for (auto p : map) {
        ans = (ans * (p.second + 1)) % 1000000007L;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using Map = map<ll,ll>;
using T = tuple<ll,ll,ll>;
using vvl = vector<vector<ll>>;
#define all(v) v.begin(), v.end()
#define print(v) cout<<v<<endl;
#define fi(v) get<0>(v)
#define se(v) get<1>(v)
#define th(v) get<2>(v)
template <typename T> bool chmax(T &a, const T &b){if (a<b){a=b;return 1;}return 0;}
template <typename T> bool chmin(T &a, const T &b){if (a>b){a=b;return 1;}return 0;}
const ll INF=1LL<<60;
const ll MOD=1000000007;

vector<long long> divisor(long long n) {
vector<long long> ret;
for (long long i = 1; i * i <= n; i++) {
if (n % i == 0) {
ret.push_back(i);
if (i * i != n) ret.push_back(n / i);
}
}
sort(ret.begin(), ret.end()); // 昇順に並べる
return ret;
}


int main(){
    ll N;
    cin >> N;
    ll M;
    cin >> M;
    vl A=divisor(M);
    reverse(A.begin(), A.end());
    for(auto p: A){
        if(M/p>=N){
            print(p)return 0;
        }
    }

    return 0;
}

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

#define IOS ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define I insert
#define endl '\n'
#define all(x) x.begin(), x.end()

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

using vvll = vector< vector<ll> >;
using vll = vector<ll> ;

const ll maxs = 2e5+5;
const ll lmaxs = 20;
ll mod = 1e9+7;
ll oo = 1e15;


void pre(){



}

void solve(){
    
    ll N; 
    cin>>N;
    string ans;
    while(N){
        N--;
        char ch = 'a' + N%26;
        ans.pb(ch);
        N/=26;
    }
    reverse(ans.begin(), ans.end());
    cout<<ans;
}

int main(){
    // #ifndef ONLINE_JUDGE
    // freopen("input00.txt","r",stdin);
    // #endif
    IOS;
    pre();
    ll T = 1;
    //cin>>T;
    while(T--){
        solve();   
    }
    return 0;
}

Measured memory_bytes: 3624
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000
#define int long long
int A[200010], F[200010];
int N, K;
bool isOK(int maximam) {
    int cnt = 0;
    rep(i, N) {
        int less = F[i] * A[i] - maximam;
        cnt += max(0LL, (less + F[i] - 1) / F[i]);
        // if (maximam == 1 ) {
        //     cout << i << " " <<  max(0LL, (less + F[i] - 1) / F[i]) << endl;
        // }
    }
    //cout << maximam << "->" << cnt << endl;
    if (cnt <= K) return true;
    else return false;
}

// 汎用的な二分探索のテンプレ
int binary_search() {
    int ng = -1; //「index = 0」が条件を満たすこともあるので、初期値は -1
    int ok = INF2; // 「index = a.size()-1」が条件を満たさないこともあるので、初期値は a.size()

    /* ok と ng のどちらが大きいかわからないことを考慮 */
    while (abs(ok - ng) > 1) {
        int mid = (ok + ng) / 2;

        if (isOK(mid)) ok = mid;
        else ng = mid;
    }
    return ok;
}
signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N >> K;
    rep(i, N) cin >> A[i];
    rep(i, N) cin >> F[i];
    int ans = 0;
    sort(A, A + N);
    sort(F, F + N, greater<int>());
    rep(i, N) {
        ans += A[i] * F[i];
    }
    /*
    rep(i, N) cout << A[i] << " ";
    cout << endl;
    rep(i, N) cout << F[i] << " ";
    cout << endl;
    */
    cout << binary_search() << endl;
    //cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3328
#include<stdio.h>

int nextInt();
int dif(int a, int b){return a<b?b-a:a-b;}

int H, W, S[400][401], i, j, f, g, l;
int par[160000], rank[160000];
long long int num[160000][2];
long long int ans;

void init(int n){
	for(int i=0; i<n; i++){
		par[i] = i;
		rank[i] = 0;
	}
}

int find(int x){
	if(par[x] == x){
		return x;
	}else{
		return par[x] = find(par[x]);
	}
}

void unite(int x, int y){
	x = find(x);
	y = find(y);
	if(x == y){return;}
	if(rank[x] < rank[y]){
		par[x] = y;
	}else{
		par[y] = x;
		if(rank[x] == rank[y]){rank[x]++;}
	}
}

int main(){
	H = nextInt();
	W = nextInt();
	for(i=0; i<H; i++){
		for(j=0; j<W; j++){
			S[i][j] = getchar();
		}
		getchar();
	}
	init(W*H);
	for(i=0; i<H; i++){
		for(j=0; j<W; j++){
			if(i>0){
				if(S[i][j]!=S[i-1][j]){unite(W*i+j, W*(i-1)+j);}
			}
			if(j>0){
				if(S[i][j]!=S[i][j-1]){unite(W*i+j, W*i+(j-1));}
			}
		}
	}
	for(i=0; i<H; i++){
		for(j=0; j<W; j++){
			f = W*i+j;
			g = find(f);
			if((dif(i, g/W)+dif(j, g%W)) & 1){
				num[g][1]++;
			}else{
				num[g][0]++;
			}
		}
	}
	for(i=0, l=W*H; i<l; i++){
		ans += num[i][0]*num[i][1];
	}
	printf("%lld\n", ans);
	return 0;
}

int nextInt(){
	int f=0; char c=getchar();
	while((c<'0')||('9'<c)){c=getchar();}
	while((c>='0')&&(c<='9')){f=f*10+(c-'0'); c=getchar();}
	return f;
}


Measured memory_bytes: 4480
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    n = int(input())
    ac, wa, tle, re =0, 0, 0, 0
    for i in range(n):
        s = input()
        if s == "AC":
            ac += 1
        elif s == "WA":
            wa += 1
        elif s == "TLE":
            tle += 1
        else:
            re += 1

    print("AC x {}".format(ac))
    print("WA x {}".format(wa)) 
    print("TLE x {}".format(tle))
    print("RE x {}".format(re))

if __name__=='__main__':
    main()

Measured memory_bytes: 9220
#include<bits/stdc++.h>
#define U [1<<17]={}
#define G(a)((c=A[a]+A[P[a]]+C[a])%k?c:0)
typedef long long L;using namespace std;
map<L,L>T U;L P U,E U,Z U,H U,C U,A U,O U,X U,B U,k,n,a,b,c;char s U;
L D(L a){L d;Z[a]=1;for(map<L,L>::iterator I=T[a].begin();I!=T[a].end();I++)
	d=I->first,d-P[a]?P[d]=a,E[d]=E[a]+1,C[d]=I->second,D(d),Z[a]+=Z[d],!H[a]|Z[H[a]]<Z[d]?H[a]=d:0:0;}
L M(L i){return i?B[i]+M(i^i&-i):0;}
L S(L x,L i){for(x=G(x)+M(i++)-M(i);i<1e5;i+=i&-i)B[i]+=x;}
L K(L f){a=X[f];n=X[b];return a-n?M(O[E[a]<E[n]?a=n,n=b,b=f,n:f])-M(O[a])+G(a)+K(P[a]):abs(M(O[f])-M(O[b]));}
main(){for(cin>>n>>k;--n;T[a][b]=T[b][a]=c)cin>>a>>b>>c;
	for(D(b=0);n<*Z;n++)if(!n|H[P[a=n]]-n)for(;!b|a;S(a=H[a],O[a]=b++))X[a]=n;
	for(cin>>a;cin>>s>>a>>b;*s&2?cout<<K(a)<<endl,0:A[a]+=b,S(H[a],O[a]),a&&S(a,O[a]-1));}

Measured memory_bytes: 33392
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <queue>
#include <utility>
#include <vector>
using namespace std;

const int MAX_LEN = 6;
const int MAX_N = 40;
const int LIMIT = MAX_LEN * MAX_N;
const string INF(LIMIT, 'z');

struct edge {
	int to;
	string cost;
	edge(int t, const string& c):to(t), cost(c){}
};

bool to_goal[MAX_N];
vector<vector<edge> > es;

string dijkstra(int s, int g) {
	typedef pair<string, int> P;
	const int n = es.size();
	vector<vector<string> > dist(n, vector<string>(LIMIT + MAX_LEN + 1, INF));
	dist[s][0] = "";
	priority_queue<P, vector<P>, greater<P> > que;
	que.push(make_pair("", s));

	while(!que.empty()) {
		const string spell = que.top().first;
		const int v = que.top().second, len = spell.size();
		que.pop();

		if(!to_goal[v] || dist[v][len] != spell)
			continue;

		if(len > LIMIT)
			return "NO";

		if(v == g)
			return spell;

		for(int i = 0; i < es[v].size(); ++i) {
			const edge& e = es[v][i];
			if(!to_goal[e.to])
				continue;

			const string next_spell = spell + e.cost;
			const int next_len = next_spell.size();
			if(dist[e.to][next_len] > next_spell) {
				dist[e.to][next_len] = next_spell;
				que.push(make_pair(next_spell, e.to));
			}
		}
	}

	return "NO";
}

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

	for(int n, a, s, g; cin >> n >> a >> s >> g, n;) {
		es.clear();
		es.resize(n);
		for(int i = 0; i < a; ++i) {
			int x, y;
			string lab;
			cin >> x >> y >> lab;
			es[x].push_back(edge(y, lab));
		}

		memset(to_goal, false, sizeof(to_goal));
		to_goal[g] = true;

		for(int i = 0; i < n; ++i) {
			for(int j = 0; j < n; ++j) {
				if(!to_goal[j]) {
					for(int k = 0; k < (int)es[j].size(); ++k) {
						if(to_goal[es[j][k].to]) {
							to_goal[j] = true;
							break;
						}
					}
				}
			}
		}

		cout << dijkstra(s, g) << endl;
	}

	return EXIT_SUCCESS;
}

Measured memory_bytes: 5416
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
#include<sstream>
#include<vector>
#include<stack>
#include<math.h>
using namespace std;


int main() {
	const long long int mod = 1000000007;
	
	map<long long int, long long int>mp;
	//cout << fixed << setprecision(10);
	long long int  n,m,b,c,d,k,h,w;
	long long int e[200005], q, ok[30], tmp = 0, memo[1000005][2],memo2[1000005][2], num = 0,num2, no[1005][1005] = {};
	char a[1005][1005];
	string str = "abcdefghijklmnopqrstuvwxyz";
	cin >> h>>w;
	for (int i = 1; i <= h; i++) {
		for (int j = 1; j <= w; j++) {
			cin >> a[i][j];
			if (a[i][j] == '#') {
				num++;
				memo[num][0] = i;
				memo[num][1] = j;
			}
		}
	}
	while (1) {
		bool key = true;
		for (int i = 1; i <= h; i++) {
			for (int j = 1; j <= w; j++) {
				if (a[i][j] == '.') {
					key = false;
					goto next;
				}
			}
		}
	next:


		if (key) {
			cout << tmp;
			return 0;
		}
			tmp++;
			num2 = 0;
		for (int f = 1; f <= num; f++) {
			int i = memo[f][0], j = memo[f][1];
			if (i != 1 && a[i - 1][j] == '.') {
				a[i - 1][j] = '#';
				num2++;
				memo2[num2][0] = i - 1;
				memo2[num2][1] = j;
			}
			if (i != h && a[i + 1][j] == '.') {
				a[i + 1][j] = '#';
				num2++;
				memo2[num2][0] = i + 1;
				memo2[num2][1] = j;
			}
			if (j != 1 && a[i][j-1] == '.') {
				a[i ][j-1] = '#';
				num2++;
				memo2[num2][0] = i;
				memo2[num2][1] = j-1;
			}
			if (i != 1 && a[i][j+1] == '.') {
				a[i][j+1] = '#';
				num2++;
				memo2[num2][0] = i;
				memo2[num2][1] = j+1;
			}
			
			
		}
		for (int i = 1; i <= num2; i++) {
			memo[i][0] = memo2[i][0];
			memo[i][1] = memo2[i][1];
		}
		num = num2;
	}
}


Measured memory_bytes: 20224
#include <iostream>
#include <iomanip>
#include <vector>
#include <unordered_map>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <array>
#include <tuple>
#include <string>
#include <algorithm>
#include <functional>
#include <cmath>
#include <numeric>
#include <bitset>
#include <cstdint>
#include <stdexcept>
using namespace std;

// 整数型

using i32 = int32_t;
using i64 = int64_t;
using u32 = uint32_t;
using u64 = uint64_t;

// [0,n)を昇順/降順でループ

#define rep(i, n) for (int i = 0; i < static_cast<int>(n); ++i)
#define repd(i, n) for (int i = static_cast<int>(n) - 1; i >= 0; --i)

// [a,b)を昇順/降順でループ

#define FOR(i, a, b) for (int i = static_cast<int>(a); i < static_cast<int>(b); ++i)
#define FORD(i, a, b) for (int i = static_cast<int>(b) - 1; i >= static_cast<int>(a); --i)

// デバッグ

#ifdef DEBUG
#include <cassert>
#define my_assert(x) assert(x)
#else
#define my_assert(x)
#define assert(x)
#endif

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

int main()
{
    // 高速な入出力
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    // 浮動小数の表示の精度
    cout << setprecision(15);

    i64 x, k, d;
    cin >> x >> k >> d;
    x = abs(x);
    i64 k_min = x / d, x0 = x - d * k_min, x1 = d - x0;
    if (k < k_min)
    {
        cout << x - k * d << endl;
    }
    else
    {
        k -= k_min;
        cout << ((k & 1) ? x1 : x0) << endl;
    }

    return 0;
}


Measured memory_bytes: 3636