akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<algorithm>
#include<cassert>
using namespace std;


int main()
{

  int N;
  while(cin>>N){
    vector<int> vn;
    for(int i = 0; i < N; ++i){
      int tmp;
      cin >> tmp;
      vn.push_back( tmp );
    }
    sort( vn.begin(), vn.end() );
    //    cout << N << endl;continue;
    int zero_num = 0;
    int one_num = 0;
    int minimum_num = 2000000000;
    int two_num = 0;
    int three_num = 0;
    int min_id = -1;
    bool flag23 = true;
  
    for(int i = 0; i < (int)vn.size(); ++i){
      if( vn[i] == 0 ) ++zero_num;
      if( vn[i] == 1 ) ++one_num;
      if( vn[i] == 2 ) ++two_num;
      if( vn[i] == 3 ) ++three_num;
      if( vn[i] > 3 ) flag23 = false;
    }
    
  
    if( zero_num % 2 == 1 ){
      if( one_num == 0 ){
        for(int i = 0; i < (int)vn.size(); ++i){
          if( vn[i] < minimum_num && vn[i] > 1 ){
            minimum_num = vn[i];
            min_id = i;
          }
        }
        if( min_id >= 0 ){
          //cout << "MIN : " << min_id << " " << vn.size() <<  endl;
          vn.erase(vn.begin() + min_id);
          if( minimum_num == 2 ) --two_num;
          if( minimum_num == 3 ) --three_num;
          //cout << "MIN after: " << min_id << " " << vn.size() <<  endl;
          //for(int i=0;i<vn.size();i++)cout << vn[i] <<"  ";cout << endl;
        }
      }
    }
  

    if( flag23 && (two_num >= 1 && three_num == 1) ) {
      int two_last_id = -1;
      for(int i = 0; i < (int)vn.size(); ++i){
        if( vn[i] == 2 ) two_last_id = i;
      }
      swap( vn[vn.size()-1], vn[two_last_id] );
    }
    
  

    if( zero_num == 0 ){

      for(int i = 0; i < (int)vn.size(); ++i){
        if( vn[i] > 1 ) cout << vn[i] << endl;
      }
      for(int i = 0; i < one_num; ++i){
        cout << 1 << endl;
      }
    
    }else if( zero_num % 2 == 0 ){

      for(int i = 0; i < (int)vn.size(); ++i){
        if( vn[i] > 1 ) cout << vn[i] << endl;
      }
      for(int i = 0; i < zero_num; ++i){
        cout << 0 << endl;
      }
      for(int i = 0; i < one_num; ++i){
        cout << 1 << endl;
      }
    
    }else{//zero_num%2==1

      if( one_num == 0 ){
      
        for(int i = 0; i < (int)vn.size(); ++i){
          if( vn[i] > 1 ) cout << vn[i] << endl;
        }
        for(int i = 0; i < zero_num - 1; ++i){
          cout << 0 << endl;
        }
        if( min_id >= 0 )
          cout << minimum_num << endl;
        cout << 0 << endl;
      
      }else{
      
        for(int i = 0; i < (int)vn.size(); ++i){
          if( vn[i] > 1 ){
            cout << vn[i] << endl;
          }
        }
        for(int i = 0; i < zero_num - 1; ++i){
          cout << 0 << endl;
        }
        if( one_num > 0 ){
          cout << 1 << endl;
          --one_num;
        }
        cout << 0 << endl;
        for(int i = 0; i < one_num; ++i){
          cout << 1 << endl;
        }
        //cout << 0 << endl;

      }
    
    }
#ifdef DEBUG
    //cout <<"end " << endl;
#endif
  }
  return 0;
}

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

const int MOD = 1000000007;
const ll INF = numeric_limits<ll>::max();
const int inf = 1e8;

typedef pair<int,int> P;

char grid[21][21];
int h,w;
int sx,sy;
int gx,gy;

int d[21][21];

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

int bfs(){
    queue<P> que;
    int res=0;
    rep(i,h){
        rep(j,w){
            d[i][j]=-1;
        }
    }
    que.push(P(sx,sy));
    d[sx][sy]=0;

    while(que.size()){
        P p = que.front(); que.pop();
        //if(p.first == gx && p.second == gy) break;

        rep(i,4){
            int nx = p.first + dx[i], ny = p.second + dy[i];

            if(0 <= nx && nx < h && 0 <= ny && ny < w && grid[nx][ny]!='#' && d[nx][ny]==-1){
                que.push(P(nx,ny));
                d[nx][ny] = d[p.first][p.second]+1;
                res=max(res,d[nx][ny]);
            } 
        }
    }
    return res;
}

int main(){
    cin.tie( 0 ); ios::sync_with_stdio( false );
    cin >> h >> w;
    rep(i,h){
        rep(j,w){
            cin >> grid[i][j];
        }
    }
    int ans;
    int res;
    int max_=0;
    rep(i,h){
        rep(j,w){
            if(grid[i][j]=='#') continue;

            sx=i;
            sy=j;
            ans=bfs();
            //cout <<"i:j"<<i<<":"<<j<<" "<< ans << endl;
            max_=max(max_,ans);
        }
    }

    cout << max_;
    return 0;
}

Measured memory_bytes: 256
n = gets.to_i
a = gets.split.map(&:to_i)

ans = 0
j = 0
(n-1).times do |i|
    case j
    when 0
        j = a[i+1] <=> a[i]
    when -1
        next if a[i+1] <= a[i]
        ans += 1
        j = 0
    when 1
        next if a[i+1] >= a[i]
        ans += 1
        j = 0
    end
end

puts ans + 1

Measured memory_bytes: 8452
#include <bits/stdc++.h>
#define pb push_back
#define Nmax 200005
#define INF 1000000000
#define MOD 1000000007
#define mp make_pair
#define fi first
#define se second
#define ch s[p]-'a'
#define pii pair <int,int>

using namespace std;

int n,val[Nmax],ans[Nmax],v[Nmax],fr[Nmax];
vector <int> L1[Nmax],L2[Nmax],Comp[Nmax],Ev[Nmax];
bool viz[Nmax];

inline void Dfs1(int nod, int ind)
{
    Comp[ind].pb(nod);
    viz[nod]=1;
    for(auto it : L1[nod])
    {
        if(viz[it]) continue;
        Dfs1(it,ind);
    }
}

inline void Dfs2(int nod, int ind)
{
    val[nod]=ind;
    for(auto it : L2[nod])
    {
        if(val[it]) continue;
        Dfs2(it,ind);
    }
}

int main()
{
    int m1,m2,x,y,i,j;
    /*#ifndef ONLINE_JUDGE
        freopen ("date.in","r",stdin);
        freopen ("date.out","w",stdout);
    #endif*/
    cin>>n>>m1>>m2;
    while(m1--)
    {
        cin>>x>>y;
        L1[x].pb(y); L1[y].pb(x);
    }
    while(m2--)
    {
        cin>>x>>y;
        L2[x].pb(y); L2[y].pb(x);
    }

    int nr1=0;
    for(i=1;i<=n;++i)
        if(!viz[i])
        {
            ++nr1;
            Dfs1(i,nr1);
        }

    int nr=0;
    for(i=1;i<=n;++i)
        if(!val[i])
        {
            ++nr;
            Dfs2(i,nr);
        }

    int p=0;
    for(i=1;i<=nr1;++i)
    {
        int lft = p+1 , rgt = p+Comp[i].size();
        for(auto it : Comp[i])
        {
            v[++p]=val[it];
            Ev[lft-1].pb(-it);
            Ev[rgt].pb(it);
        }
    }

    for(i=1;i<=n;++i)
    {
        ++fr[v[i]];
        for(auto it : Ev[i])
            if(it<0) ans[-it]-=fr[val[-it]];
            else ans[it]+=fr[val[it]];
    }

    for(i=1;i<=n;++i) cout<<ans[i]<<" ";
    return 0;
}


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

// {U}{INT,LONG,LLONG}_{MAX,MIN}
#define INF         INT_MAX/3
#define LLINF       LLONG_MAX/3
#define MOD         (1000000007LL)
#define MODA(a, b)  a=((a)+(b))%MOD
#define MODP(a, b)  a=((a)*(b))%MOD
#define inc(i, l, r)   for(int i=(l);i<(r);i++)
#define dec(i, l, r)   for(int i=(r)-1;i>=(l);i--)
#define pb          push_back
#define se          second
#define fi          first
#define mset(a, b)  memset(a, b, sizeof(a))

using LL  = long long;
using G   = vector<vector<int>>;

int di[] = {0, -1, 0, 1};
int dj[] = {1, 0, -1, 0};
// }}}

int main() {
    cin.tie(0);ios::sync_with_stdio(false);
    int a, b;cin >> a >> b;
    int k;cin >> k;
    vector<int> ans;
    for(int i=1;i<=100;i++){
        if(a%i == 0 && b%i == 0){
            ans.pb(i);
        }
    }
    sort(ans.begin(), ans.end());
    reverse(ans.begin(), ans.end());
    cout << ans[k-1] << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define x first
#define y second

using namespace std;

typedef long long ll;

const int MX = 2000 * 2000 + 3;

int a[2005];
bitset <MX> dp[2];

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n, sum = 0;
    cin >> n;
    for (int i = 1; i <= n; i++)
    {
        cin >> a[i];
        sum += a[i];
    }

    dp[0] = 1;
    for (int i = 1; i <= n; i++)
    {
        int t = i % 2;
        dp[t] = (dp[t ^ 1] | (dp[t ^ 1] << a[i]));
    }

    int t = n % 2;
    for (int i = (sum + 1) / 2; i <= sum; i++)
        if (dp[t][i] == 1) cout << i, exit(0);
    return 0;
}



Measured memory_bytes: 2688
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<functional>
#include<vector>
#include<queue>
#include<stack>
#include<set>
using namespace std;

int main(){
	long long a[100001];
	int n;
	long long x, y, z;
	long long k,s, ans;
	bool v = true;
	ans = 0;
	scanf("%d", &n);
	for (int i = 0; i < n; i++){
		scanf("%lld", &a[n-i-1]);
	}
	if (a[0] != 2){
		printf("-1\n");
		return 0;
	}
	x = 2;
	y = 3;
	for (int i = 1; i < n; i++){
		k = (x+a[i]-1)/ a[i];
		x = a[i] * k;
		k = y / a[i];
		if (k <= 0){
			printf("-1\n");
			return 0;
		}
		y = (a[i] * k) + a[i] - 1;
	}
	if (x>y)printf("-1\n");
	else{
		printf("%lld %lld\n", x, y);
	}


	return 0;
}

Measured memory_bytes: 896
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <limits>
#include <ios>
#include <iomanip>
#include <stdio.h>
#include <iomanip>
#include <queue>
using namespace std;

#define rep(i,N) for(int (i)=0; (i)<(N); (i)++)
#define revrep(i,N) for(int (i)=(N)-1; (i)>=0; (i)--)
#define dump(vec) for(int i = 0; i < (vec).size(); i++){cout << vec.at(i) << ",";}cout << endl

typedef long long ll;

int main(void)
{
    int r;
    cin >> r;

    cout << r*r << endl;

    return 0;
}


Measured memory_bytes: 256
n,k=map(int,input().split())
arr=list(map(int,input().split()))
brr=list(map(lambda x: max(x,0),arr))
crr=[0]
cum=0
for b in brr[:(n-k)]:
    cum+=b
    crr.append(cum)
drr=[0]
cum=0
for b in list(reversed(brr))[:(n-k)]:
    cum+=b
    drr.append(cum)
drr.reverse()
K=sum(arr[:k])
krr=[]
for i in range(n-k):
    krr.append(max(0,K))
    K-=arr[i]
    K+=arr[i+k]
krr.append(max(0,K))

ans=0
for i in range(n-k+1):
    ans=max(ans,crr[i]+drr[i]+krr[i])
print(ans)


Measured memory_bytes: 21960
#include <iostream>
#include <sstream>
#include <stdio.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include <set>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <limits>
#include <bitset>
#include <stack>
#include <queue>
#include <ctype.h>

typedef long long int lli;
#define rep(i,s,N) for(int i=s;i<N;i++)
#define MOD 1000000007
#define more(a,b) (((a)>(b))?(a):(b))
#define less(a,b) (((a)<(b))?(a):(b))

using namespace std;


int main(void)
{
	int N; cin >> N;
	map<lli, lli> cnt;
	vector<lli> A(N);
	rep(i, 0, N) {
		cin >> A[i];
		cnt[A[i]]++;
	}
	lli sum = 0;
	map<lli, lli>::iterator it;
	for (it = cnt.begin(); it != cnt.end(); it++) {
		sum += it->second * (it->second - 1) / 2;
	}

	rep(i, 0, N) {
		lli ans = sum - cnt[A[i]] + 1;
		cout << ans << endl;
	}


	return 0;
}


Measured memory_bytes: 11008
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <cmath>

using namespace std;

const double DTR = (2 * acos(-1)) / 360;


enum ans {
        ABC, ACD, ADB, BCD,
};

int solve() {
        string xy;
        cin >> xy;
        int d, l;
        scanf("%d%d", &d, &l);
        double base = 
                xy == "BC" ? -60 :
                xy == "CD" ? 0 :
                xy == "DB" ? 60:
                0;
        double theta = (base + d) * DTR;
        double y = l * sin(theta);
        double x = l * cos(theta);
        double z60 = x + sqrt(3) / 3.0 * y;
        double z120 = -x + sqrt(3) / 3.0 * y;
        z60 = fmod(fmod(z60, 2.0) + 2.0 + 1e-8, 2.0);
        z120 = fmod(fmod(z120, 2.0) + 2.0 + 1e-8, 2.0);
        y = (z60 + z120) * sqrt(3) / 2.0;
        if (z60 < 1.0) {
                if (z120 < 1.0) {
                        if (y < sqrt(3) / 2.0) {
                                return ADB;
                        } else {
                                return BCD;
                        }
                } else {
                        if (y < sqrt(3)) {
                                return ABC;
                        } else {
                                return ACD;
                        }
                } 
        } else {
                if (z120 < 1.0) {
                        if (y < sqrt(3)) {
                                return ACD;
                        } else {
                                return ABC;
                        }
                } else {
                        if (y < 3.0 * sqrt(3) / 2.0) {
                                return BCD;
                        } else {
                                return ADB;
                        }
                }
        }
}

int main() {
        int a = solve(), b = solve();
        puts(a == b ? "YES" : "NO");
        return 0;
}

Measured memory_bytes: 3516
#include<iostream>
#include <string.h>
#include <algorithm>
using namespace std;

int main()
{
    int n;
    int a[100000],b[100000];
    memset(a,0,sizeof(a));
    memset(b,0,sizeof(b));

    cin >> n;

    int m = n/2;

    for(int i = 0;i < m;i++)
    {
        int s,t;
        cin >> s >> t;
        a[s-1]++;
        b[t-1]++;
    }

    int im = 1, km = 1, am, bm;

    for(int i = 0;i < 100000;i++)
    {
        if(im < a[i])
        {
            im = a[i];
            am = i;
        }
        if(km < b[i])
        {
            km = b[i];
            bm = i;
        }
    }

    if(am == bm)
    {
        int as = 0, bs = 0;
        for(int i = 0; i < 100000; i++)
        {
            if(i != am && as < a[i])
                as = a[i];
            if(i != am && bs < b[i])
                bs = b[i];
        }
        cout << n -max(im + bs, km + as) << endl;
    }
    else
            cout << n-(im + km) << endl;

    return 0;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
#define ENDL '\n'
#define io ios_base::sync_with_stdio(false);cin.tie(0);
#define sayy cout<<"YES"<<ENDL;
#define sayn cout<<"NO"<<ENDL;

typedef long long ll;
using namespace std;

int main(){
    io

    int a,b,c;
    cin >> a >> b >> c;
    cout << c - min(a-b,c) << ENDL;
 
    return 0;
}

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

namespace ConsoleApp1
{
    public static class MyExtensions
    {
        public static string Slice(this string str, int start = 0, int stop = 0)
        {
            if (start > str.Length || stop > str.Length || start < 0 || stop < 0)
                return "";

            if (stop == 0) stop = str.Length;
            return str.Substring(start, stop - start);
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            A();
        }

        static void A()
        {
            var abcd = ReadSplitInt();
            var a = abcd[0];
            var b = abcd[1];
            var c = abcd[2];
            var d = abcd[3];

            if (Math.Abs(a - c) <= d || (Math.Abs(a - b) <= d && Math.Abs(b - c) <= d))
                Console.WriteLine("Yes");
            else
                Console.WriteLine("No");
        }

        static IEnumerable<int> Range(int start, int stop)
        {
            if (start < 0 || stop < 0 || start > stop || (start <= 0 && stop <= 0))
                return new List<int>();

            return Enumerable.Range(start, stop - start);
        }

        static bool IsDigit(string str)
        {
            var i = 0;
            return int.TryParse(str, out i);
        }

        static int DigitsSum(long num)
        {
            return num.ToString().Select(x => x.ToString()).Sum(int.Parse);
        }

        static int[] ToIntArray(string str)
        {
            return str.Select(x => x.ToString()).Select(int.Parse).ToArray();
        }

        static string Read() => Console.ReadLine();
        static int ReadInt() => int.Parse(Read());
        static long ReadLong() => long.Parse(Read());

        static IList<string> ReadSplit() => Read().Split().ToList();
        static IList<int> ReadSplitInt() => Read().Split().Select(int.Parse).ToList();
    }
}

Measured memory_bytes: 11348
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
 
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
#define start_routine() int begtime = clock();
#define end_routine() int endtime = clock(); cerr << endl << "Time elapsed: " << (endtime - begtime)*1000/CLOCKS_PER_SEC << " ms"; return 0
#define speed() cin.tie(0), cout.tie(0), ios_base::sync_with_stdio(false)
// #define exit(a, b) return cout << a, b;
 
// debugger
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#define debug(stuff) cout << #stuff << ": " << stuff <<endl
#define debugc(stuff) cout << #stuff << ": "; for(auto x: stuff) cout << x << " "; cout << endl;
// 
 
#define loop(i,a,b) for(ll i=a;i<b;i++)
#define all(v) v.begin(), v.end() 
 
#define print(stuff) cout << stuff << endl
#define printc(stuff) for(auto x: stuff) cout << x << " "; cout << endl;
#define printPrec(stuff) cout << fixed << setprecision(15) << stuff << endl;
#define len length
#define ret0 return 0
#define ret return 
 
 
#define ll long long
#define ld long double
#define fi first
#define endl '\n'
#define se second
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define fill(ar, x) memset(ar, x, sizeof ar)
 
#define vl vector<ll> 
#define sl set<ll>
#define pll pair<ll, ll>
#define mll map<ll, ll> 
#define pq priority_queue<ll>
 
// typedef tree<ll,null_type,less<ll>,rb_tree_tag,
// tree_order_statistics_node_update> indexed_set;
 
#define inf (long long int) 1e18
#define eps 0.000001
#define mod 1000000007
#define mod1 998244353
#define MAXN (ll)2e5+5
#define N (1ll<<10)

void solve(){
    ll a, b, c, d;
    cin>>a>>b>>c>>d;
    while(1){
        c -= b;
        if(c <= 0){
            print("Yes");
            ret;
        }
        a -= d;
        if(a <= 0){
            print("No");
            ret;
        }
    }
}
 
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
 
 
    ll t = 1;
    // cin>>t;
    while(t--){
        solve();
    }
      
}


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

  int main()
  {
    ll a, b, c;
    cin >> a >> b >> c;
    ll d = c - a - b;
    if(d > 0 && d * d > 4 * a * b)
      cout << "Yes" << endl;
    else
      cout << "No" << endl;
    return 0;
  }




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

int main() {
	long long N, K;
	cin >> N >> K;
	long long ans = (N / K) * (N / K) * (N / K);
	if (K % 2 == 0) {
		long long L = (N + K / 2) / K;
		ans += L * L * L;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
import sys
input = lambda : sys.stdin.readline().rstrip()

n, k = map(int, input().split())

p = 0

for i in range(1, n + 1):
    cnt = 0
    while 1 <= i <= k - 1:
        cnt += 1
        i *= 2
    p += 0.5**cnt

print(p / n)

Measured memory_bytes: 2940
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define _USE_MATH_DEFINES
#include <math.h>
#define rep(i,n) for(int i = 0;i < n;i++)
#define NIL = -1;

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

ll lcm(ll a,ll b){
    a / gcd(a,b) * b;
}
const ll mod = 1e9 + 7;

int main(){
    int n;
    cin >> n;
    vector<int> a(n),b(n),c(n);
    for (int i = 0;i < n;i++) cin >> a[i];
    for (int i = 0;i < n;i++) cin >> b[i];
    for (int i = 0;i < n;i++) cin >> c[i];

    sort(a.begin(),a.end());
    sort(b.begin(),b.end());
    sort(c.begin(),c.end());

    ll x,y,ans = 0;
    for(int i = n - 1;i >= 0;i--){
        x = c.end() - upper_bound(c.begin(),c.end(),b[i]);
        y = lower_bound(a.begin(),a.end(),b[i]) - a.begin();
        ans += x * y;
    }

    cout << ans << endl;
}   


Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define rep1(i, n) for(ll i = 1; i < n+1; i++)
#define sort(A) sort(A.begin(),A.end())
#define reverse(A) reverse(A.begin(),A.end());
#define vecmin(A) *min_element(A.begin(),A.end());
#define vecmax(A) *max_element(A.begin(),A.end());
typedef long long ll;

int main(){
  int n,m;
  cin >> n >> m;
  vector<int> a(m),b(m);
  rep(i,m) cin >> a[i] >> b[i];
  
  int ans = 0;
  
  rep(i,m){//i番目の辺を飛ばす
    vector<vector<int>> to(n+1,vector<int>(0));
    rep(j,m){//j番目の辺を加える
      int x,y;
      x = a[j];
      y = b[j];
      if(j==i) continue;//iなら飛ばす
      to[x].push_back(y);
      to[y].push_back(x);
    }
    
    //スタート地点を決める
    int start;
    for(auto p : to){
      if(p.size() > 0){
        start = p[0];
        break;
      }
    }
    
    //bfs
    queue<int> q;
    vector<bool> seen(n+1);
    q.push(start);
    while(!q.empty()){
      int x = q.front();
      q.pop();
      if(seen[x]) continue;
      seen[x] = 1;
      for(auto p : to[x]){
        q.push(p);
      }
    }
    
    //連結か？
    int check = 0;
    rep1(i,n) check += seen[i];
    if(check < n) ans ++;
    
  }//i
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <vector>
#include <list>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
using namespace std;
 
typedef long long LL;
typedef set <LL> SET;
 
const int size = 51;
const string YES = "YES";
const string NO = "NO";

int bek[size];
int vol[size];
int n;

SET visited[size];
 
bool dist( int now );
bool solve( int now );
 
bool dist( int now ) {
    if ( vol[now] == 0 ) return solve( now + 1 );

    LL state = 0;
    for ( LL i = now; i < n; ++ i ) {
        if ( vol[i] == bek[i] ) state |= 1LL << i;
    }
    
    if ( visited[now].find( state ) != visited[now].end() ) return false;
    visited[now].insert( state );
    if ( vol[now] == 0 ) return false;
    
    for ( int i = now + 1; i < n; ++ i ) {
        if ( vol[i] != 0 ) continue;
        if ( vol[now] < bek[i] ) continue;
        if ( i - 1 > now && bek[i - 1] == bek[i] && vol[i - 1] == 0 ) continue;
        vol[now] -= bek[i];
        vol[i] = bek[i];
        if ( dist( now ) ) return true;
        vol[i] = 0;
        vol[now] += bek[i];
    }
    return false;
}
 
bool solve( int now ) {
    if ( now == n ) return true;
    if ( vol[now] == 0 ) return false;
    if ( now + 1 < n && bek[now+1] == bek[now] && vol[now] == 0 ) return false;
    if ( solve( now + 1 ) ) return true;
    if ( dist( now ) ) return true;
    return false;
}
 
int main() {
    while ( cin >> n && n ) {
        for ( int i = 0; i < n; ++ i ) {
            cin >> bek[i];
            vol[i] = 0;
            visited[i].clear();
        }
        sort( bek, bek + n, greater<int>() );
        vol[0] = bek[0];
        cout << ( solve( 0 ) ? YES : NO ) << endl;
    }
    return 0;
}

Measured memory_bytes: 3160
#C
import heapq
n = int(input())
v = list(map(int,input().split()))

heapq.heapify(v)

while len(v)>1:
    tmp1 = heapq.heappop(v)
    tmp2 = heapq.heappop(v)
    heapq.heappush(v,(tmp1+tmp2)/2)
    
print(v[0])

Measured memory_bytes: 3060
#include<bits/stdc++.h>                                                                                               
using namespace std;
 
#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define int long long
#define mk_p(a,b)   make_pair((a),(b))
using pii = pair<int,int>;
constexpr int INF  = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;

int gcd(int a,int b){return b ? gcd(b,a%b) : a;} 
int lcm(int a,int b){return a/gcd(a,b)*b;}

signed main(){
    int r;
    cin >> r;
    if(r < 1200) cout << "ABC\n";
    else if(r < 2800) cout << "ARC\n";
    else cout << "AGC\n";
    return 0;
}


Measured memory_bytes: 764
import heapq
import sys
input=sys.stdin.readline
N,M=map(int,input().split())
lab=[]
for i in range(N):
    llab=list(map(int,input().split()))
    lab.append(llab)
lab.sort(key=lambda ab:ab[0])
hq=[]
ind=0
ans=0
#print(lab)
#c=0
for i in range(M):
    if hq:
            ans-=heapq.heappop(hq)
    for j in range(ind,N):
        #if f==0:
        #print(i,j,lab[j][0])
        if lab[j][0]==i+1:
            heapq.heappush(hq,-lab[j][1])#
        else:
            ind=j
            #j=N-1#これダメ、抜けられていない
            break
        #c+=1
    #if hq:
    #        ans-=heapq.heappop(hq)
    #print(hq)
#print(c)
if hq:
    ans-=heapq.heappop(hq)
print(ans)
#for i in range(3):
#    i=3
#    print(12345)


Measured memory_bytes: 31980
#include<bits/stdc++.h>
#define LL long long
#define rep(i,n) for(int i=0;i<n;++i)
#define FOR(i,a,b) for(int i=a;i<=b;++i)
using namespace std;
static const LL INF = 1LL<<61LL;
static const int MAX_N = 1<<18;
typedef pair<int,int> PII;

LL bit[MAX_N+1],n,q;

class BIT{
    public:
        int N;
        void init(int _N){
            N=_N;
            rep(i,N+1)bit[i]=0;
        }

        int getSum(int i){
            int s=0;
            while(i){
                s+=bit[i];
                i-=i&-i;
            }
            return s;
        }

        void add(int i,int x){
            while(i<=N){
                bit[i]+=x;
                i+=i&-i;
            }
        }
};

int main(){
    BIT bit;
    cin>>n>>q;
    bit.init(n);
    rep(i,q){
        int com,x,y;
        cin>>com>>x>>y;
        if(!com)bit.add(x,y);
        else cout<<bit.getSum(y)-bit.getSum(x-1)<<endl;
    }
    return 0;
}

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

int main(){
    int k,s,cnt=0;
    cin>>k>>s;
    for(int i=0;i<=k;i++){
        for(int j=0;j<=k;j++){
            int z=abs(s-i-j);
            if(z<=k&&(i+j+z==s)){
                cnt++;
            }
            //cout<<i<<" "<<j<<" "<<z<<endl;
        }
    }
    //cout<<endl;
    cout<<cnt<<"\n";
    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize ("Ofast")
#pragma GCC target ("avx2")
//#include<bits/stdc++.h>
#include<cstdio>
#include<cstring>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int CM = 130000, CL = 12;
char cn[CM + CL], * ci = cn + CM + CL, * owa = cn + CM, ct;
const ll ma0 = 1157442765409226768;
const ll ma1 = 1085102592571150095;
const ll ma2 = 71777214294589695;
const ll ma3 = 281470681808895;
const ll ma4 = 4294967295;
inline int getint1() {
	if (ci - owa > 0) {
		memcpy(cn, owa, CL);
		ci -= CM;
		fread(cn + CL, 1, CM, stdin);
	}
	ll tmp = *(ll*)ci;
	int dig = ((tmp & ma0) ^ ma0) ? 68 - __builtin_ctzll((tmp & ma0) ^ ma0) : 0;
	tmp = tmp << dig & ma1;
	tmp = tmp * 10 + (tmp >> 8) & ma2;
	tmp = tmp * 100 + (tmp >> 16) & ma3;
	tmp = tmp * 10000 + (tmp >> 32) & ma4;
	ci += (64 - dig >> 3);
	while ((ct = *ci++) >= '0') tmp = tmp * 10 + ct - '0';
	return tmp;
}
inline int getint2() {
	if (ci - owa > 0) {
		memcpy(cn, owa, CL);
		ci -= CM;
		fread(cn + CL, 1, CM, stdin);
	}
	ll tmp = *(ll*)ci;
	int dig = 68 - __builtin_ctzll((tmp & ma0) ^ ma0);
	tmp = tmp << dig & ma1;
	tmp = tmp * 10 + (tmp >> 8) & ma2;
	tmp = tmp * 100 + (tmp >> 16) & ma3;
	tmp = tmp * 10000 + (tmp >> 32) & ma4;
	ci += (72 - dig >> 3);
	return tmp;
}

bool NG[100001];
int main() {
	//cin.tie(0);
	//ios::sync_with_stdio(false);


	int N = getint2(), M = getint2();
	int H[100001];
	rep1(i, N) H[i] = getint1();
	rep(i, M) {
		int a = getint2(), b = getint2();
		if (H[a] >= H[b]) NG[b] = 1;
		if (H[a] <= H[b]) NG[a] = 1;
	}
	int kotae = N;
	rep1(i, N) kotae -= NG[i];

	printf("%d", kotae);

	Would you please return 0;
}

Measured memory_bytes: 2216
import sys

fin = sys.stdin.readline
N = [int(elem) for elem in fin().split()][0]
p_list = [int(elem) for elem in fin().split()]

sorted_p = sorted(p_list)

count = 0
for i in range(len(p_list)):
    if p_list[i] != sorted_p[i]:
        count += 1

if (count == 2) or (count == 0):
    print('YES')
else:
    print("NO")


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

using namespace std;

#define PB	push_back
#define ALL(x)	(x).begin(), (x).end()
#define ALLR(x)	(x).rbegin(), (x).rend()
#define MP	make_pair

#define debug(args...) { string _s = #args; replace(ALL(_s), ',', ' '); stringstream ss(_s); cerr << endl;_debug(ss, args); }
#define _rg auto it = next(v.begin()); it != v.end(); it++
#define _input ostream& operator <<(ostream& out

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

#define cont(c) template<typename T> _input, const c<T>& v) { \
					if (v.empty()) return out; \
					out << "[" << *v.begin(); \
					for (_rg) out << ", " << *it; \
					out << "]"; return out; \
				}
				
#define cont2(c) template<typename T, typename U> _input, const c<T, U>& v) { \
					if (v.empty()) return out; \
					out << "[" << *v.begin(); \
					for (_rg) out << ", " << *it; \
					out << "]"; return out; \
				}

cont(vector) cont(set) cont(multiset) cont(queue) cont2(map)

template<typename T, size_t n, typename= enable_if_t<!is_same<T, char>::value>>
_input, const T(&v)[n]) {
	if (n == 0) return out;
	out << "[" << v[0];
	for (int i = 1; i < (int)n; i++) out << ", " << v[i];
	out  << "]"; return out;
}

template<typename T, typename... Ts>
void _debug(stringstream& ss, const T &arg) {
	string name; ss >> name;
	cerr << name << " = " << arg << endl;
}

template<typename T, typename... Ts>
void _debug(stringstream& ss, const T& arg, const Ts&... args) {
	string name; ss >> name; 
	cerr << name << " = " << arg << ", ";
	if (is_class<T>::value || is_array<T>::value) cerr << endl;
	_debug(ss, args...);
}

#define FAST_IO ios::sync_with_stdio(false); cin.tie(0)

#define int long long int

typedef pair<int, int> ii;
typedef pair<pair<int, int>, int> iii;
typedef vector<int> vi;
typedef vector<iii> viii;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef unsigned long long ull;

const int INF = LONG_LONG_MAX>>1;
const int NINF = LONG_LONG_MIN/2;
const double PI = 3.141592653589793238;

int32_t main() {
	FAST_IO;

	int n;
	cin >> n;
	int a[n], b[n];
	for (int i = 0; i < n; i++) {
		cin >> a[i] >> b[i];
	}
	
	sort(a, a+n);
	sort(b, b+n);
		
	
	if (n%2 == 1) {
		n--;
		int med1 = a[(n+1)/2];
		int med2 = b[(n+1)/2];
		
		cout << med2-med1+1 << endl;
	} else {
		n--;
		int med1 = a[n/2] + a[n/2+1];
		int med2 = b[n/2] + b[n/2+1];
		
		
		cout << med2 - med1 + 1 << endl;
	}
	
}
// g++ -Wall -Wextra -Wshadow -fsanitize=undefined -std=c++17


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

int main(){
    string S;
    cin >> S;
    int counter=0;
    int ans=0;
    for(int i=0; i<S.size(); i++){
        if(S.at(i)=='A'||S.at(i)=='C'||S.at(i)=='G'||S.at(i)=='T') counter++;
        else counter=0;

        if(counter>ans) ans=counter;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3632
head = 0
tail = 0
max_i = 200000
elapsed_time = 0

def initialize():
  global head, tail
  head = tail = 0

def isEmpty():
  global head, tail
  return head == tail

def isFull():
  global head, tail, max_i
  return head == (tail + 1) % max_i

def enqueue(x):
  if isFull():
    print('over flow')
  global head, tail
  Q[tail] = x
  if tail + 1 == max_i:
    tail = 0
  else:
    tail += 1

def dequeue():
  if isEmpty():
    print('under flow')
  global head, tail
  x = Q[head]
  if head + 1 == max_i:
    head = 0
  else:
    head += 1
  return x

initialize()

N, q = map(int, input().split())
max_i = N + 2
Q = [('', 0) for i in range(max_i)]
for i in range(N): # 値を受け取り、tailを一つずらす
  Q[i] = list(input().split())
  Q[i][1] = int(Q[i][1])
  tail += 1

while (head != tail): # headがtailに追いつくまで
  task = dequeue()
  count = min(q, task[1])
  task[1] -= count
  elapsed_time += count
  if task[1] > 0:
    enqueue(task)
  else:
    print(f"{task[0]} {elapsed_time}")


Measured memory_bytes: 14092
#include<stdio.h>
#include<map>
#include<algorithm>
using namespace std;
typedef pair<int,int> P;
P mt[200];
int dp[1000][201];//hでn個のときのrの最小値
int min(int a,int b){return a<b?a:b;}
int max(int a,int b){return a>b?a:b;}
int main(){
	int n,m;
	int i,j,k;
	while(1){
	scanf("%d",&n);
	if(n==0)return 0;
	for(i=0;i<n;i++){
		int a,b;
		scanf("%d %d",&a,&b);
		mt[i]=P(a,b);
	}
	scanf("%d",&m);
	for(i=0;i<m;i++){
		int a,b;
		scanf("%d %d",&a,&b);
		mt[n+i]=P(a,b);
	}
	sort(mt,mt+m+n);
	for(i=0;i<1000;i++)for(j=0;j<=m+n;j++)dp[i][j]=1000;
	for(i=0;i<m+n;i++){
		int h=mt[i].first;
		int r=mt[i].second;
		dp[h][1]=min(dp[h][1],r);
		for(j=0;j<h;j++){
			for(k=0;k<m+n;k++){
				if(r>dp[j][k])dp[h][k+1]=min(dp[h][k+1],r);
			}
		}
	}
	int ans=0;
	for(i=0;i<1000;i++)for(j=0;j<=m+n;j++){
		if(dp[i][j]!=1000)ans=max(ans,j);
	}
	printf("%d\n",ans);
	}
}

Measured memory_bytes: 1812
function Main(input) {

	input = input.split("\n");
	var N = parseInt(input[0]);
	var lists = [];
	
	function List(name,score,num){
	    this.name = name;
	    this.score = score;
	    this.num = num;
	}
	
	List.prototype.show = function(){
	    return this.num;
	}
	
	for(var i = 0;i < N;i++){
	     pass = input[i+1].split(" ");
	     lists[i] = new List(pass[0],parseInt(pass[1]),parseInt(i+1));
	}
	
    lists.sort((a,b) => { return (a.name > b.name) ? 1
    							: (a.name < b.name) ? -1
      							: (b.score >= a.score)? 1 : -1; });
    
    for(var j = 0;j < N;j++){
        console.log(lists[j].show());
    }
    //console.log(lists);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 21064
import java.util.Scanner;

public class Main {

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

		int a;
		String op;
		int b;

		while (true) {
			a = sc.nextInt();
			op = sc.next();
			b = sc.nextInt();

			if (op.equals("?")) {
				break;
			} else if (op.equals("+")) {
				System.out.println(a + b);
			} else if (op.equals("-")) {
				System.out.println(a - b);
			} else if (op.equals("*")) {
				System.out.println(a * b);
			} else if (op.equals("/")) {
				System.out.println(a / b);
			}
		}

	}
}


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

int main(){
	int i,j,k,n,m,l,f,x,y,z; string s;
	cin >> n >> m >> x;
	int a[105];
	rep(i, m) cin >> a[i];

	f = 0;
	l = 0;
	rep(i, m){
		if(a[i] > x) f++;
		else l++;
	}

	cout << min(f, l) << endl;;
	
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define LOOP(i,x,n) for(int i=x;i<n;i++)
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define int long long
using namespace std;
const int MOD=1000000007;
const int INF=1000000009;

int dp[50][500][500];
signed main(){
  int n,ma,mb;
  cin>>n>>ma>>mb;
  vector<int> a(n),b(n),c(n);
  REP(i,n)cin>>a[i]>>b[i]>>c[i];

  REP(i,n+1)REP(j,401)REP(k,401)dp[i][j][k]=INF;
  dp[0][0][0]=0;
  REP(i,n)REP(j,401)REP(k,401){
    dp[i+1][j][k]=min(dp[i+1][j][k],dp[i][j][k]);
    dp[i+1][j+a[i]][k+b[i]]=min(dp[i+1][j+a[i]][k+b[i]],dp[i][j][k]+c[i]);
  }

  int ans=INF;
  LOOP(i,1,401){
    LOOP(j,1,401){
      if(i*mb==j*ma)ans=min(ans,dp[n][i][j]);
    }
  }
  cout<<(ans==INF?-1:ans)<<endl;

  return 0;
}


Measured memory_bytes: 79744
#include <bits/stdc++.h>
#define maxn (int)(2e5)
#define INF 1<<30
#define i64 long long
#define pii pair<i64,i64>
#define all(x) x.begin(),x.end()
#define LB(x,v) lower_bound(all(x), v) - x.begin()
#define fread() freopen("in.txt", "r", stdin);
using namespace std;

int mat[maxn+2][4], ans[maxn+2][4] , n;
const int k = 3;

void init(int n){
    for(int i = 0; i <= n; i++) 
        ans[i][0] = ans[i][1] = ans[i][2] = -1;
}

int solve(int day, int option){
    if(day >= n) return 0;

    if(ans[day][option] != -1) return ans[day][option];

    int res = -1;
    if(option == 0){
        res = mat[day][option] + max(solve(day+1, 1), solve(day+1, 2));
    }
    else if(option == 1){
        res = mat[day][option] + max(solve(day+1, 0), solve(day+1, 2));
    }
    else {
        res = mat[day][option] + max(solve(day+1, 0), solve(day+1, 1));
    }
    return ans[day][option] = res;
}

int main() {
    while(scanf("%d",&n)==1){
        init(n);
        for(int i=0;i<n;i++) scanf("%d %d %d",&mat[i][0], &mat[i][1], &mat[i][2]);
        printf("%d\n", max(solve(0,0), max(solve(0,1), solve(0,2)) ));
    }    
    return 0;
}

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

int tannsaku (vector<int>a,vector<int>b,vector<int>c){
  
}

int main(){
  vector<int> a(3);

  cin >> a.at(0) >> a.at(1) >> a.at(2);
  sort(a.begin(),a.end());
  int b =a.at(2)*10+a.at(1)+a.at(0);
  cout << b << endl;
  }

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <climits>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <fstream>

using namespace std;
#define SZ(x) (int)(x).size()
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REPR(i,n) for(int i=(n)-1;i>=0;i--)
#define ALL(s) (s).begin(), (s).end()
#define so(V) sort(ALL(V))
#define rev(V) reverse(ALL(V))
#define uni(v) v.erase( unique(ALL(v)) , v.end());

typedef long long unsigned int llu;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<bool> vb;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;
const int INF = (1 << 29);
const ll LINF = 1e18;
const double PI = acos(-1);

template<typename T>vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T, typename... Ts>auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...)); }
template<typename T, typename U, typename... V>
typename enable_if<is_same<T, U>::value != 0>::type
fill_v(U & u, const V... v) { u = U(v...); }
template<typename T, typename U, typename... V>
typename enable_if<is_same<T, U>::value == 0>::type
fill_v(U & u, const V... v) { for (auto& e : u) fill_v<T>(e, v...); }
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 (a > b) { a = b; return 1; } return 0; }

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N;
	cin >> N;
	vector<pair<ll, ll> > P(N);
	REP(i, N) {
		cin >> P[i].first >> P[i].second;
	}
	sort(ALL(P), [](const pair<ll, ll>& x, const pair<ll, ll>& y) {return x.second < y.second; });
	ll time = 0;
	REP(i, N) {
		time += P[i].first;
		if (time > P[i].second) {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	return 0;
}


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

using namespace std;

typedef long double ld;
typedef long long ll;

const int mod = 1e9 + 7;

int add(int x, int y) {
  x += y;
  if (x >= mod)
    x -= mod;
  return x;
}

int udd(int &x, int y) {
  return x = add(x, y);
}

int sub(int x, int y) {
  return add(x, mod - y);
}

int mul(ll x, ll y) {
  return x * y % mod;
}

int uul(int &x, int y) {
  return x = mul(x, y);
}

const int M = 239;
const int N = 103 * 103;

bitset<N> b[M];
int low[M];
int m = 0;

void add(bitset<N> x) {
  for (int i = 0; i < m; ++i)
    if (x[low[i]]) {
      x ^= b[i];
    }
  
  if (x.count()) {
    b[m] = x;
    for (int i = 0; i < N; ++i)
      if (x[i]) {
        low[m] = i;
        break;
      }
    ++m;
  }
}

int h, w;
string s[M];
int ans = 1;
bool u[M][M];


bool isPal(string s) {
  int n = s.length();
  for (int i = 0; i < n; ++i)
    if (s[i] != s[n - 1 - i])
      return false;
  return true;
}

int perm(string s) {
  set<string> ans;
  for (int i = 0; i < 24; ++i) {
    ans.insert(s);
    next_permutation(s.begin(), s.end());
  }
  //cout << "s = " << s << endl;
  //cout << "sz = " << ans.size() << endl;
  return ans.size();
}

void read() {
  cin >> h >> w;
  for (int i = 0; i < h; ++i)
    cin >> s[i];

  if (h % 2 == 1) {
    if (!isPal(s[h / 2]))
      uul(ans, 2);
  }

  if (w % 2 == 1) {
    string cur = "";
    for (int i = 0; i < h; ++i)
      cur.push_back(s[i][w / 2]);
    if (!isPal(cur))
      uul(ans, 2);
  }
}

void kill() {
  for (int i = 0; i < h - 1 - i; ++i)
    for (int j = 0; j < w - 1 - j; ++j) {
      string cur = "";
      for (int a : {i, h - i - 1})
        for (int b : {j, w - j - 1})
            cur.push_back(s[a][b]);

      int sz = perm(cur);
      if (sz == 24) {
        u[i][j] = true;
        uul(ans, 12);
      } else {
        uul(ans, sz);
      }
    }

  for (int i = 0; i < h - i - 1; ++i) {
    bitset<N> x;
    for (int j = 0; j < w - 1 - j; ++j)
      if (u[i][j]) {
        x[i * 102 + j] = 1;
      }
    add(x);
  }

  for (int j = 0; j < w - 1 - j; ++j) {
    bitset<N> x;
    for (int i = 0; i < h - 1 - i; ++i)
      if (u[i][j])
        x[i * 102 + j] = 1; 
    add(x);
  }

  for (int i = 0; i < m; ++i)
    uul(ans, 2);

  cout << ans << endl;
}

int main() {
#ifdef LOCAL
  assert(freopen("i.in", "r", stdin));
#endif

  ios_base::sync_with_stdio(false);

  read();
  kill();
}



Measured memory_bytes: 640
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>

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

typedef int long long ll;
using namespace std;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const ll MOD = 1e9 + 7;

int main() {
    int n;
    cin>>n;
    map<ll,ll>m;
    rep(i,n){
        ll a;cin>>a;
        m[a]++;
    }
    if(n%2==1){
        if(m[0]!=1){cout<<0<<endl;return 0;}
    }
    ll ans=1;
    ll a1=2;if(n%2==0){a1=1;}

    for(ll i=a1;i<=n-1;i+=2){
        if(m[i]!=2){cout<<0<<endl;return 0;}
        ans*=2;
        ans%=MOD;
    }
    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 4224
#include<bits/stdc++.h>
using namespace std;
const int N = 2e5+7;

int n;
int a[N],b[N];

int main()
{
	cin>>n;
	for(int i=1;i<=n;i++) cin>>a[i]>>b[i];
	sort(a+1,a+1+n);
	sort(b+1,b+1+n);
	if(n&1) cout<<b[n+1>>1] - a[n+1>>1] +1<<endl; //闭区间内整数个数 
	else cout<<b[n/2]+b[n/2+1]-a[n/2]-a[n/2+1] + 1<<endl; //整数个数加上带。5的数 
	return 0;
}

Measured memory_bytes: 5068
N = int(input())
s = input()
goukei_W = []
goukei_E = []
goukei = []
sum = []

count = 0
for i in range(N):
    if s[i] == 'W':
        count += 1
    goukei_W.append(count)

count = 0
for i in range(N):
    if s[N-i-1] == 'E':
        count += 1
    goukei_E.append(count)

for i in range(N):
    if i-1 < 0:
        goukei.append(goukei_E[N-i-2])
    elif N-i-2 < 0:
        goukei.append(goukei_W[i-1])
    else:
        goukei.append(goukei_W[i-1] + goukei_E[N-i-2])

print(min(goukei))


Measured memory_bytes: 30012
#include<bits/stdc++.h>
#define ll long long
#define f(i,l,r) for(int i=l;i<=r;i++)
#define debug(x) cout<<#x<<'='<<(x)<<endl
#define pb push_back
#define mp make_pair
#define rng(x) x.begin(),x.end()
#define fst first
#define scnd second
using namespace std;
template<class T> bool maxs(T& a,T& b)
{
    if(a<b)
    {
        T t;
        t=a;
        a=b;
        b=t;
        return true;
    }
    return false;
}
template<class T> bool maxi(T& a,T b)
{
    if(a<b)
    {
        a=b;
        return true;
    }
    return false;
}
template<class T> bool mini(T& a,T b)
{
    if(a>b)
    {
        a=b;
        return true;
    }
    return false;
}
int main()
{
#ifdef LOCAL
    freopen("output.txt","w",stdout);
    freopen("input.txt","r",stdin);
#else
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
#endif
    ll n;
    cin>>n;
    double p[n+1];
    f(i,1,n)  cin>>p[i];
    double dp[n+1][n+1];
    f(i,0,n)  f(j,0,n)  dp[i][j]=0;
    dp[1][1]=p[1];
    dp[1][0]=1-p[1];
    f(i,2,n)    dp[1][i]=0;
    f(i,2,n)
    {
        f(j,0,n)
        {
            dp[i][j]+=dp[i-1][j]*(1-p[i]);
            dp[i][j]+=dp[i-1][j-1]*p[i];
        }
    }
    double ans=0;
    f(j,n/2+1,n)    ans+=dp[n][j];
    cout<<setprecision(12)<<ans;  
    return 0;
}

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

int main()
{
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  
  while (1)
  {
    C -= B;
    
    if (0 >= C)
    {
      printf("Yes");
      break;
    }
    
    A -= D;
    
    if (0 >= A)
    {
      printf("No");
      break;
    }
  }

  return 0;
}

Measured memory_bytes: 3656
#include<stdio.h>

int main()
{
  int N,i,count=0;
  scanf("%d",&N);
  int a[N];
  for(i = 0;i < N;i++)
    {
      scanf("%d",&a[i]);
    }
  for(i = 0;i < N-2;i++){
    if(a[i]>a[i+1] && a[i+1]>a[i+2]){
      count += 1;
    }
    else if(a[i+2]>a[i+1] && a[i+1]>a[i]){
      count += 1;
    }
  }
  printf("%d\n",count);
  return 0;
}


Measured memory_bytes: 128
import itertools
n = int(input())
data = []
for x in range(n):
    for y in range(int(input())):
        k, l = map(int, input().split())
        data.append((x, k - 1, l))
ans = 0
for i in itertools.product([1,0], repeat=n):
    s = sum(i)
    for g in data:
        if i[g[0]] == 1 and i[g[1]] != g[2]:
            s = 0
            break
    ans = max(ans, s)
print(ans)

Measured memory_bytes: 3064
lastMonth={}
thisMonth={}

month="last"

while True:
    try:
        s=input()
        if s=="":
            month="this"
            continue
        c,d=[int(i) for i in s.split(",")]
        if month=="last":
            lastMonth[c]=lastMonth.get(c,0)+1
        else:
            thisMonth[c]=thisMonth.get(d,0)+1
    except EOFError:
        break


for key in sorted(list(set(thisMonth.keys()) & set(lastMonth.keys()))):
    print(key,thisMonth[key]+lastMonth[key])



Measured memory_bytes: 5600
import java.util.Arrays;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Scanner;
import java.util.Set;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		final int N = sc.nextInt();
		long[] arr = new long[N];
		for(int i = 0; i < N; i++){
			arr[i] = sc.nextLong();
		}
		
		final long sum = Arrays.stream(arr).sum();
		final long lo_avg = sum / N;
		final long hi_avg = (sum + N - 1) / N;
		
		long lo_answer = 0, hi_answer = 0;
		for(int i = 0; i < N; i++){
			lo_answer += (arr[i] - lo_avg) * (arr[i] - lo_avg);
			hi_answer += (arr[i] - hi_avg) * (arr[i] - hi_avg);
		}
		
		System.out.println(Math.min(lo_answer, hi_answer));
		
		
	}

}

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

const long long N = 500005;
const long long mod = 1000000007;
long long fact[N]; 

void set_fact() {
	fact[0] = 1; for (long long i = 1; i < N; i ++) fact[i] = (fact[i-1] * i) % mod;
}

long long power(long long x, long long y) {
    long long ans = 1;
  	while (y > 0) {
        if (y % 2 == 1) ans = (ans*x) % mod;
        y /= 2; x = (x*x) % mod;  
    } return ans % mod;
}

long long nCr(long long n, long long r) {
	return (fact[n] * power(fact[n - r], mod - 2)) % mod * power(fact[r], mod - 2) % mod;
}

int main() {
    set_fact(); long long n, m; cin >> n >> m; long long sgn = 1;
    long long perm_arr[n+1]; perm_arr[0] = 1; 
    for (long long i = 1; i <= n; i ++) perm_arr[i] = (perm_arr[i-1] * ((m-n)+i)) % mod;
    long long ans = 0;
    for (long long fill = 0; fill <= n; fill ++) {
        long long prod = (nCr(n, fill) * perm_arr[n-fill]) % mod;
        ans = (ans + sgn*prod); sgn *= -1; ans %= mod;
    } ans = (ans * perm_arr[n]) % mod;
    cout << (ans+mod) % mod << endl;
}

Measured memory_bytes: 11260