akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

// clang-format off
#define forn(i, x, y) for(int i = x; i < y; i++)
#define IOS ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(NULL)
#define printVector(a) for(auto it = a.begin() ; it != a.end(); it++) {cout << *it << endl;}
// clang-format on

using VD = vector<double>;
using VVD = vector<VD>;

int main()
{
  IOS;

  int N;
  cin >> N;
  vector<double> P(N);
  forn(i, 0, N) cin >> P[i];

  VVD dp(N + 1, VD(N + 1));
  dp[0][0] = 1.0;
  for (int i = 0; i < N; i++)
    for (int j = 0; j <= i; j++)
    {
      dp[i + 1][j] += dp[i][j] * (1.0 - P[i]);
      dp[i + 1][j + 1] += dp[i][j] * P[i];
    }

  double res = 0;
  for (int i = N / 2 + 1; i <= N; i++)
    res += dp[N][i];
  cout << fixed << setprecision(10) << res << endl;

  return 0;
}


Measured memory_bytes: 73700
#!/usr/bin/env python3

def main(S):
    counter = {}
    for c in S:
        cnt = counter.setdefault(c, 1)
        counter[c] = cnt + 1
    #print(counter)
    n = 1
    for v in counter.values():
        n = (n * v) % 1000000007
        #n = (n * v)# % 1000000007
    return n-1

def test(S, e):
    import sys
    if main(S) != e:
        print("expected", e, "but", main(S))
        sys.exit(1)

test("abcd", 15)
test("baa", 5)
test("abcab", 17)
input()
S = input()
print(main(S))



Measured memory_bytes: 3188
N = input()

N_a = N[:3]
N_b = N[1:]

N_a_1 = int(N_a)
N_b_1 = int(N_b)

if N_a_1%111 == 0 or N_b_1%111 == 0:
  print("Yes")
else:
  print("No")


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
#define int long long int
int32_t main(){
	string a,b;cin>>a>>b;
	if(a.length()>b.length()) cout<<"GREATER";
	else if(a.length()<b.length()) cout<<"LESS";
	else if(a>b) cout<<"GREATER";
	else if(a<b) cout<<"LESS";
	else cout<<"EQUAL";
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstdio>
#include <iomanip>
#include <cmath>
#include <string>
#include <string.h>
#include <stack>
#include <queue>
#include <map>
#include <stdlib.h>
#include <set>
typedef long long ll;
using namespace std;

int main() {
	int n,sum=0;
	cin>>n;
	vector<int>v(n),c(n);
	for(int i=0;i<n;i++)cin>>v.at(i);
	for(int i=0;i<n;i++)cin>>c.at(i);
	for(int i=0;i<n;i++){
		if(v.at(i)-c.at(i)>=0){
			sum+=v.at(i)-c.at(i);
		}
	}
	cout<<sum<<endl;

	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cctype>	// ?°????????????§??????????????????????????¨

using std::cin;
using std::cout;
using std::endl;
using std::string;

int main() {
	string s, s1;
	getline(cin, s);
	for (size_t i = 0; i < s.size(); i++)
	{
		if (islower(s[i]))		s[i] = toupper(s[i]);
		else if (isupper(s[i]))	s[i] = tolower(s[i]);
		else					s[i] = s[i];

	}
	cout << s << endl;
	return 0;
}

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

typedef struct _string_mode
{
	char str[33] ;
	short num ;
} stm ;


int main()
{
	char get[33] ;
	char longest[33] = { '\0' } ;
	stm string[1000] ;
	int mode = 0;
	int i = 0, j ;

	while( cin >> get )
	{
		if( strlen(longest) < strlen(get) )	strcpy( longest,get ) ;

		i ++ ;
		strcpy( string[i].str, get ) ;
		string[i].num = 1 ;
		for( j = 0 ; j < i ; j ++ )
		{
			if( strcmp(string[j].str,string[i].str) == 0 )
			{
				string[j].num += string[i].num ;
				if( mode < string[j].num ){ mode = string[j].num ; }
				break ;
			}
		}
	}

	for( j = 0 ; j < i ; j ++ )
	{
		if( string[j].num == mode )
		{
			cout << string[j].str << " " << longest << endl ;
			break ;
		}
	}

	return 0 ;
}

Measured memory_bytes: 1156
#include<bits/stdc++.h>
using namespace std;
typedef  long long ll;
using vll=vector<ll>;
using vi=vector<int>;
using vvi=vector<vector<int>>;
using vb=vector<bool>;
using pii=pair<int,int>;
using vpii=vector<pair<int,int>>;

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

//pow(llpow,modpow)
template<class T> ll llpow(ll x,T n){ll ans=1;if(x==0)ans=0;while(n){if(n&1)ans*=x;x*=x;n>>=1;}return ans;}
long long modpow(long long a, long long n, long long mod) {long long res = 1;while (n > 0) {if (n & 1) res = res * a % mod;a = a * a % mod;n >>= 1;}return res;}
//最大公約数
template<class T> inline T gcd(T x,T y){if(y==0)return x; else {return gcd(y,x%y);}}
//最小公倍数
template<class T> inline T lcm(T x,T y){return x/gcd(x,y)*y;}
//逆元
long long modinv(long long a, long long m) {long long b = m, u = 1, v = 0;while (b) {long long t = a / b;a -= t * b; swap(a, b);u -= t * v; swap(u, v);}u %= m;if (u < 0) u += m;return u;}

#define rep(i, begin_i, end_i) for (ll i = (ll)begin_i; i < (ll)end_i; i++)
//試験導入
#define irep(i, end_i, begin_i) for (ll i = (ll)begin_i-1; i >= (ll)end_i; i--)
long long INF = 1LL<<60;

int h,w;
int main( ){
    cin>>h>>w;
    vvi a(h,vi(w,0));
    ll sum=0;
    ll odd=0;
    int starti=-1,startj=-1;
    rep(i,0,h)rep(j,0,w){
        cin>>a[i][j];
        sum+=a[i][j];
        if(a[i][j]%2)odd++;
    }
    vpii ansres;
    if(sum%2)odd--;
    int wayj[]={0,0};
    int wayi[]={-1,1};
    bool way=true;
    int i=0,j=0;
    while(odd){
        if(a[i][j]%2==0){
            int ni=i+wayi[way];
            int nj=j+wayj[way];
            if(ni>=h||ni<0){
                way^=true;
                j++;
                continue;
            }
            i=ni; j=nj;
            continue;
        }
        while(odd&&a[i][j]%2){
            pii t=make_pair(i,j);
            ansres.push_back(t);
            a[i][j]--;
            int ni=i+wayi[way];
            int nj=j+wayj[way];
            if(ni>=h||ni<0){
                way^=true;
                j++;
                a[i][j]++;
                pii n=make_pair(i,j);
                ansres.push_back(n);
                continue;
            }
            i=ni; j=nj;
            pii n=make_pair(i,j);
            ansres.push_back(n);
            a[i][j]++;
        }
        odd-=2;
    }
    cout<<ansres.size()/2<<endl;
    for(int i=0;i<ansres.size();i+=2){
        pii first,second;
        first=ansres[i];
        second=ansres[i+1];
        cout<<first.first+1<<" "<<first.second+1<<" "<<second.first+1<<" "<<second.second+1<<endl;
    }
   return 0;
}




Measured memory_bytes: 5232
import sys
sys.setrecursionlimit(10**7)

n = int(input())

graph = [[] for i in range(n)]
for i in range(n-1):
    a,b = map(int,input().split())
    a,b = a-1,b-1
    graph[a].append([b,i])

    
ans = [0]*(n-1)

def col(now,color):
    c = 1
    for (b,j) in graph[now]:
        if c == color:
            c += 1
        ans[j] = c
        col(b,c)
        c += 1

col(0,0)
print(max(ans))
for a in ans:
    print(a)



Measured memory_bytes: 70976
#include<iostream>
#include<queue>
using namespace std;
#define MAX 500
#define rep(i, n) for ( int i = 0; i < n; i++)

bool G[MAX][MAX];
int n, m;

int bfs(){
  queue<int> q;
  int d[MAX];
  rep(i, n) d[i] = (1<<21);

  q.push(0);
  d[0] = 0;

  int u;
  while(!q.empty()){
    u = q.front(); q.pop();

    rep(v, n){
      if ( d[v] == (1<<21) && G[u][v] ){
	d[v] = d[u] + 1;
	q.push(v);
      }
    }
  }

  int cnt = 0;
  rep(i, n) if ( d[i] == 1 || d[i] == 2 ) cnt++;
  return cnt;
}

main(){
  int s, t;
  while(1){
    cin >> n >> m;
    if ( n == 0 && m == 0 ) break;
    rep(i, n) rep(j, n) G[i][j] = false;

    rep(i, m){
      cin >> s >> t;
      s--; t--;
      G[s][t] = G[t][s] = true;
    }
    
    cout << bfs() << endl;
  }
}

Measured memory_bytes: 0
public class Main {

  private static void solve() {
    int n = ni();
    int[] a = na(n);

    int[] ret;
    if (n % 2 == 0) {
      ret = solve(a);
    } else {
      int[] b = new int[n - 1];
      for (int i = 0; i < n - 1; i++) {
        b[i] = a[i];
      }
      b = solve(b);

      ret = new int[n];
      for (int i = 0; i < n - 1; i++) {
        ret[i] = b[i];
      }

    }

    for (int v : ret) {
      out.print(v + " ");
    }
    out.println();
  }

  private static int[] solve(int[] a) {
    int x = 0;
    for (int v : a) {
      x ^= v;
    }
    int n = a.length;
    int[] ret = new int[n];
    for (int i = 0; i < n; i++) {
      ret[i] = a[i] ^ x;
    }
    return ret;
  }

  public static void main(String[] args) {
    new Thread(null, new Runnable() {
      @Override
      public void run() {
        long start = System.currentTimeMillis();
        String debug = args.length > 0 ? args[0] : null;
        if (debug != null) {
          try {
            is = java.nio.file.Files.newInputStream(java.nio.file.Paths.get(debug));
          } catch (Exception e) {
            throw new RuntimeException(e);
          }
        }
        reader = new java.io.BufferedReader(new java.io.InputStreamReader(is), 32768);
        solve();
        out.flush();
        tr((System.currentTimeMillis() - start) + "ms");
      }
    }, "", 64000000).start();
  }

  private static java.io.InputStream is = System.in;
  private static java.io.PrintWriter out = new java.io.PrintWriter(System.out);
  private static java.util.StringTokenizer tokenizer = null;
  private static java.io.BufferedReader reader;

  public static String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }

  private static double nd() {
    return Double.parseDouble(next());
  }

  private static long nl() {
    return Long.parseLong(next());
  }

  private static int[] na(int n) {
    int[] a = new int[n];
    for (int i = 0; i < n; i++)
      a[i] = ni();
    return a;
  }

  private static char[] ns() {
    return next().toCharArray();
  }

  private static long[] nal(int n) {
    long[] a = new long[n];
    for (int i = 0; i < n; i++)
      a[i] = nl();
    return a;
  }

  private static int[][] ntable(int n, int m) {
    int[][] table = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[i][j] = ni();
      }
    }
    return table;
  }

  private static int[][] nlist(int n, int m) {
    int[][] table = new int[m][n];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[j][i] = ni();
      }
    }
    return table;
  }

  private static int ni() {
    return Integer.parseInt(next());
  }

  private static void tr(Object... o) {
    if (is != System.in)
      System.out.println(java.util.Arrays.deepToString(o));
  }
}


Measured memory_bytes: 59328
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef tree<pair<int,int>, null_type, less<pair<int,int>>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
#define int long long
#define ld long double
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define all(x) (x).begin(), (x).end()
#define forn(i,n) for(int i=0;i<(int)(n);i++)
#define for1(i,n) for(int i=1;i<=(int)(n);i++)
const int MOD = 1e9 + 7 ;
int mpow(int a,int b,int p=MOD){a=a%p;int res=1;while(b>0){if(b&1)res=(res*a)%p;a=(a*a)%p;b=b>>1;}return res%p;}
const int N=400002;

int32_t main(){
      ios_base::sync_with_stdio(false);
      cin.tie(NULL);
      int n,k;
      cin>>n>>k;
      if(k==1)
      {
            cout<<0;
            return 0;
      }
      n-=k;
      cout<<(n);  
}
// I never lose. I either win or I learn

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int n;
const int N=100010;
int a[N];
int main(){
    cin>>n;
    for(int i=1;i<=n;i++)
        cin>>a[i];
    long long ans=0;
    for(int i=1;i<=n;i++){
        for(int j=i+1;j<=n;j++){
            ans+=a[i]*a[j];
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bits/stdc++.h>
#include <cstdint>
#include <iostream>
#include <iterator>
#include <vector>

// lib/util.hpp
#ifndef UTIL_HPP
#define UTIL_HPP


typedef ::std::int_fast64_t i64;
typedef ::std::uint_fast64_t u64;
typedef ::std::int_fast32_t i32;
typedef ::std::uint_fast32_t u32;

namespace tools {
  template <typename T>
  void read(::std::istream& is, ::std::vector<T>& vector, const typename ::std::vector<T>::size_type size) {
    vector.reserve(size);
    ::std::copy_n(::std::istream_iterator<T>(is), size, ::std::back_inserter(vector));
  }
  template <typename T>
  void read(::std::vector<T>& vector, const typename ::std::vector<T>::size_type size) {
    ::tools::read(::std::cin, vector, size);
  }

  template <typename T, ::std::size_t N>
  void read(::std::istream& is, ::std::array<T, N>& array) {
    ::std::copy_n(std::istream_iterator<T>(is), N, array.begin());
  }
  template <typename T, ::std::size_t N>
  void read(::std::array<T, N>& array) {
    ::tools::read(::std::cin, array);
  }
}

#endif

// main.cpp

int main() {
  i64 L;
  std::cin >> L;
  std::cout << std::fixed << std::setprecision(12) << L * L * L / 27.0 << std::endl;
  return 0;
}

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

using namespace std;

int a[100005];

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    for(int i = 1; i <= n; ++i) cin >> a[i];
    int ans = 0;
    for(int i = 1; i <= n; ++i) {
        int cnt = 0;
        while(a[i] >= a[i + 1] && i < n) ++cnt, ++i;
        ans = max(ans, cnt);
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
 
using namespace std;
 
int a[100001];
vector <int> g[100001];
int st = 1;

int dfs (int v, int pr) {
	int cost = a[v] + a[v];
	if (g[v].size () == 1 && v != st) {
		return a[v];
	}
	if (g[v].size () == 1) cost = a[v];
	int mx = 0;
	for (auto to : g[v]) {
		if (to == pr) continue;
		int len = dfs (to, v);
		cost -= len; 
		mx = max (mx, len);
	}        
	if (v == st && cost > 0) {
		cout << "NO";
		exit (0);
	}
	if (cost < 0) {
		cout << "NO";
		exit (0);
	}
	mx = max (mx, cost);
	if (mx > a[v]) {
		cout << "NO";
		exit (0);
	}
	return cost;
}

int main () {
	int n;
	cin >> n;
	for (int i = 1;i <= n;i ++) cin >> a[i];
	for (int i = 1;i < n;i ++) {
		int x, y;
		cin >> x >> y;
		g[x].push_back (y);
		g[y].push_back (x);
	}
	for (int i = 1;i <= n;i ++) {
		if (g[i].size () > 1) {
			st = i;
			break;
		}
	}   
	dfs (st, 0);
	cout << "YES";
	return 0;
}

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

namespace AtCoderBeginnerContest164
{
	class Program
	{
		static void Main(string[] args)
		{
			var inputs = ReadIntArray();

			while (true)
			{
				inputs[2] -= inputs[1];
				if(inputs[2] <= 0)
				{
					Console.WriteLine("Yes");
					break;
				}
				inputs[0] -= inputs[3];
				if(inputs[0] <= 0)
				{
					Console.WriteLine("No");
					break;
				}
			}

		}

		public static int ReadInt()
			=> int.Parse(Console.ReadLine());

		public static int[] ReadIntArray()
			=> Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();

		public static long ReadLong()
			=> long.Parse(Console.ReadLine());

		public static long[] ReadLongArray()
			=> Console.ReadLine().Split().Select(x => long.Parse(x)).ToArray();

		public static string ReadString()
			=> Console.ReadLine();

		public static string[] ReadStringArray()
			=> Console.ReadLine().Split();
	}
}


Measured memory_bytes: 28244
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cctype>
#include<cstdlib>
#include<algorithm>
#include<bitset>
#include<vector>
#include<list>
#include<deque>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cmath>
#include<sstream>
#include<fstream>
#include<iomanip>
#include<ctime>
#include<complex>
#include<functional>
#include<climits>
#include<cassert>
#include<iterator>
#include<random>
#include<unordered_set>
#include<unordered_map>

using namespace std;

#define MAX 200002
char buf[MAX];
string s;
int main() {
	scanf("%s", buf);
	s = buf;
	int cnt = 0;
	long long int ans = 0;
	for (int i = 0; i < s.size(); i++) {
		if (s[i] == 'B') {
			cnt++;
		}
		else {
			ans += cnt;
		}
	}
	printf("%lld\n", ans);
	return 0;
}

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

using namespace std;
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))
#define endl "\n"
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {os << "["; for (const auto &v : vec) {os << v << ","; } os << "]"; return os;}
template <typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &p) {os << "(" << p.first << ", " << p.second << ")"; return os;}

void solve() {
    ll H, W, h, w;
    cin >> H >> W >> h >> w;
    cout << (H - h) * (W - w) << endl;
}

int main() {
    #ifdef LOCAL_ENV
    cin.exceptions(ios::failbit);
    #endif
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    
    solve();
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
vector<vector<int> > adjik;
int main()
{
int n,m;
cin>>n>>m;
adjik.assign(n+1,vector<int>());
int arr[n];
for(int i=0; i<n; ++i)
cin>>arr[i];
for(int i=0; i<m; ++i)
{
int a,b;
cin>>a>>b;
adjik[a-1].push_back(b-1);
adjik[b-1].push_back(a-1);
}
int ans(0);
for(int i=0; i<n; ++i)
{
int fn4(0);
for(int j=0; j<adjik[i].size(); ++j)
{
if(arr[i]<=arr[adjik[i][j]])
fn4=1;
}
if(!fn4)
++ans;
}
cout<<ans;
}


Measured memory_bytes: 8800
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		int M = scan.nextInt();
		int[] ary = new int[2*M];
		for (int i =0; i <ary.length; i++){
			ary[i] = scan.nextInt();
		}
		for(int i=1; i <= N; i++){
			int cnt=0;
			for(int j : ary){
				if( j == i ) cnt++;
			}
			System.out.println(cnt);
		}
	}

}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < (int)(n); i++)
#define ALL(a) a.begin(), a.end()
#define MOD 1000000007
using namespace std;
using ll = long long;

int main() {
    int N; cin >> N;
    vector<int> A(N);
    REP(i, 0, N) cin >> A[i];

    sort(ALL(A));
    unordered_map<int, int> multiple;
    int ans = 0;
    REP(i, 0, N) {
        if (multiple[A[i]]) continue;
        multiple[A[i]]++;
        for (int j = A[i] * 2; j < 1000001; j += A[i]) multiple[j]++;
        if (i + 1 < N && A[i] == A[i + 1]) continue;
        ans++;
    }

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

Measured memory_bytes: 43488
#include <cstdio>
#include <iostream>
#include <cassert>
#include <string>
#include <algorithm>
#include <cstring>
#include <utility>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cmath>
#include <deque>
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
const int MAXN = 456;
LL a[MAXN], dp[MAXN][MAXN];
LL psum[MAXN];
bool visit[MAXN][MAXN];

LL dfs(int l, int r) {
   if (visit[l][r]) return dp[l][r];
   visit[l][r] = 1;
   if (r - l == 1) return dp[l][r] = 0;
   LL ans = (LL)1e18;
   for (int i = l + 1; i <= r - 1; i++) {
       ans = min(ans, dfs(l, i) + dfs(i, r) + psum[r - 1] - psum[l - 1]);
   }
   //printf("l = %d r = %d dp = %lld\n", l, r, ans);
   return dp[l][r] = ans;
}

int main() {
    int N;
    scanf("%d", &N);
    for (int i = 1; i <= N; i++) {
        scanf("%lld", &a[i]);
        psum[i] = psum[i - 1] + a[i];
    }
    printf("%lld\n", dfs(1, N + 1));
    return 0;
}


Measured memory_bytes: 1920
N = int(input())
n = int((N**(1/2))//1)
s =[0]*(n+10)
for i in range(1,n+1):
  if N%i == 0:
    s[i] = i
maxs = s[0]
for j in range(1,n+1):
  if s[j] > maxs:
    maxs = s[j]
p = int(N/maxs)
walk = p + maxs - 2
print(walk)


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

int main(void){
    string S;
    cin >> S;
    stack<int> stk;
    for(int i=0;i<S.length();i++){
        if(stk.empty()){
            stk.push(S[i]);
        }
        else{
            int top = stk.top(); stk.pop();
            if(S[i] != top) continue;
            else{
                stk.push(top);
                stk.push(S[i]);
            }
        }
    }
    cout <<  S.length() - stk.size() << endl;
    return 0;
}

Measured memory_bytes: 768
import copy
from collections import deque
def main():
  H, W = map(int, input().split())
  G = [['#' == x for x in input()] for _ in range(H)]
 
  black = deque([(i, j) for i in range(H) for j in range(W) if G[i][j]])
 
  ans = 0
  while True:
    ans += 1
    next_black = deque()
    while black:
      bi, bj = black.popleft()
      if bi > 0 and not G[bi - 1][bj]:
        G[bi - 1][bj] = True
        next_black.append((bi - 1, bj))
      if bj > 0 and not G[bi][bj - 1]:
        G[bi][bj - 1] = True
        next_black.append((bi, bj - 1))
      if bi < H - 1 and not G[bi + 1][bj]:
        G[bi + 1][bj] = True
        next_black.append((bi + 1, bj))
      if bj < W - 1 and not G[bi][bj + 1]:
        G[bi][bj + 1] = True
        next_black.append((bi, bj + 1))
    if next_black:
       black = copy.copy(next_black)
    else:
       break
  print(ans - 1)
  
if __name__ == "__main__":
  main()

Measured memory_bytes: 115544
#include <iostream>
#include <utility>
#include <stdint.h>
#include <vector>

using namespace std;

int main()
{
  int N, M;
  cin >> N >> M;

  vector<int> A;

  int sum = 0;
  
  for (int n=0; n<N; ++n) {
    int a;
    cin >> a;
    sum += a;
    A.push_back(a);
  }

  int count = 0;

  for (int a : A) {
    if (a*4*M < sum)
      continue;
    ++count;
    if (count >= M)
      break;
  }

  cout << (count >= M ? "Yes" : "No") << endl;

  return 0;
}


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

int main () {
  long long N;
  cin >> N;
  long long a[2][N];
  long long dp[2][N];
  for (long long i = 0; i < 2; i++) {
    for (long long j = 0; j < N; j++) {
      cin >> a[i][j];
      if (i == 0) {
        if (j == 0) {
          dp[i][j] = a[i][j];  
        }    
        else {
          dp[i][j] = dp[i][j - 1] + a[i][j];  
        }
      } 
      else {
        if (j == 0) {
          dp[i][j] = dp[i - 1][0] + a[i][j];
        }
        else {
          dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]) + a[i][j];    
        }
      } 
    }  
  }  
  cout << dp[1][N - 1] << endl;
}

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

int main() {

  int A, B, C, D, E;
  int a, b, c, d, e;
  int S;
  
  cin >> A >> B >> C >> D >> E;
  
  a =(A % 10);
  b =(B % 10);
  c =(C % 10);
  d =(D % 10);
  e =(E % 10);
  
  S = A + B + C + D + E - a - b - c - d - e +50;
  
  if(a == 0){
   a=10;
    S = S-10;
  }
  if(b == 0){
    b=10;
  	S = S-10;
  }
  if(c == 0){
    c=10;
  	S = S-10;
  }
  if(d == 0){
    d=10;
  	S = S-10;
  }
  if(e == 0){
    e=10;
  	S = S-10;
  }
  
  for(int i; i<11; i++){
  	if(i==a){
    cout << S+i-10 << endl;
      break;
    }
    if(i==b){
    cout << S+i-10 << endl;
      break;
    }
    if(i==c){
    cout << S+i-10 << endl;
      break;
    }
    if(i==d){
    cout << S+i-10 << endl;
      break;
    }
    if(i==e){
    cout << S+i-10 << endl;
      break;
    }
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

int main()
{
    int a, odd = 0, even = 0;

    cin >> a;

    for (int i = 1; i <= a; i++) {
        if (i % 2 == 0) {
            even++;
        }
        else {
            odd++;
        }
    }

    cout << even * odd << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <map>
using namespace std;
int main(void){
    int n, W;
    cin >> n >> W;
    //int v[n];
    //int w[n];
    map<int, int> bests;
    for(int i = 0; i < n; i++){
        int v, w;
        cin >> v >> w;
        if(bests.find(w) == bests.end()){
            bests[w] = v;
        }else if(bests[w] < v){
            bests[w] = v;
        }
    }
    n = bests.size();
    int v[n], w[n];
    int index = 0;
    auto itr = bests.begin();
    while(itr != bests.end()){
        w[index] = itr->first;
        v[index] = itr->second;
        itr++;
        index++;
    }
    int table[n + 1][W + 1];
    for(int i = 0; i < n + 1; i++){
        for(int j = 0; j < W + 1; j++){
            table[i][j] = 0;
        }
    }
    
    for(int i = 1; i <= n; i++){
        for(int j = 0; j < W + 1; j++){
            if(j < w[ i - 1]){
                table[i][j] = table[i - 1][j];
            }else{
                int c = (j - (j % w[i - 1])) / w[i - 1];
                int result = table[i - 1][j];
                
                for(int k = 1; k <= c; k++){
                    if(table[i - 1][j] < table[i - 1][j - w[i - 1] * k] + v[i - 1] * k){
                        int tempResult = table[i - 1][j - w[i - 1] * k] + v[i - 1] * k;
                        result = max(tempResult, result);
                    }
                }
                table[i][j] = result;
            }
        }
    }
    cout << table[n][W] << endl;
    return 0;
}

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

int main() {
    //ios_base::sync_with_stdio(false);
    //cout<<setprecision(20);
    int n;
    ll a[400000];
    cin>>n;
    for(int i=0;i<n;i++) cin>>a[i];
    for(int i=0;i<n;i++) a[i]-=i;
    sort(a,a+n);
    int k=n/2;
    ll s=a[k];
    ll ans=0;
    for(int i=0;i<n;i++){
        ans+=abs(a[i]-s);
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 3328
#include<iostream>
#include<stdio.h>
#include <cstdlib>  // abs() for integer
#include <cmath>    // abs() for float, and fabs()

int main(void){
    int a, b, c, k;
    int i;
    int max;

    std::cin >> a >> b >> c;
    std::cin >> k;

    for(i=0; i<k; i++){
        if(a <=c && b <= c) c = 2*c;
        else if(a <= b && c <= b) b = 2*b;
        else if(b <= a && c <= a) a = 2*a;
    }

    max = a + b + c;
    std::cout << max << std::endl;

    return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')
 
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？

n=ii()
arr=limii()

mat=Counter(arr)
ans=0
for i,j in mat.items():
    if i<=j:
        ans+=j-i
    else:
        ans+=j
print(ans) 

Measured memory_bytes: 89500
// -*- mode:c++; coding:utf-8; indent-tabs-mode:nil; -*-
// ALDS1_2-A

#include <algorithm>
#include <iostream>

static void print_ints(const int as[], const unsigned int n) {
  const char* sep = "";
  for (unsigned int i = 0; i < n; ++i) {
    std::cout << sep << as[i];
    sep = " ";
  }
  std::cout << std::endl;
}

static unsigned int swap_count = 0;

static void print_swap_count(void) {
  std::cout << swap_count << std::endl;
}

inline
static void swap(int& a, int& b) {
  ++swap_count;
  std::swap(a, b);
}

void bubble_sort(int as[], const unsigned int n) {
  for (unsigned int j = 0; j < n-1; ++j) {
    for (unsigned int i = n-1; i > j; --i) {
      if (as[i] < as[i-1]) {
        swap(as[i], as[i-1]);
      }
    }
  }
}

int main(void) {
  unsigned int n;
  std::cin >> n;
  int as[n];
  for (unsigned int i = 0; i < n; ++i) {
    std::cin >> as[i];
  }

  bubble_sort(as, n);
  print_ints(as, n);
  print_swap_count();

  return 0;
}
// end

Measured memory_bytes: 1164
N=int(input())
listA=list(map(int,input().split()))
ans=0
L=[]
R=[]
L1=[0]*N
R1=[0]*N
for i in range(N):
  L+=[i+listA[i]]
  R+=[i-listA[i]]
  try:
    L1[i+1+listA[i]]+=1
  except:
    pass
  try:
    if i-listA[i]>0:
      R1[i+1-listA[i]]+=1
  except:
    pass
for i in range(N):
  ans+=L1[i]*R1[i]
print(ans)    

Measured memory_bytes: 38072
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <cmath>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <iostream>
#include <random>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include <fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;

using ll = long long;
using vll = vector<ll>;
using pll = pair<ll, ll>;
using qll = queue<ll>;
using vb = vector<bool>;
using mll = map<ll, ll>;
using sll = stack<ll>;
#define REP(i,n) for(ll i(0);(i)<(n);(i)++)
#define rep(i,n) for(ll i(0);(i)<(n);(i)++)
#define ALL(a) a.begin(), a.end()
#define enld endl //* missspell check
const ll INF = 1LL << 60;

ll calDist(vll &fixD, vll &floatD){
    vll tmp = fixD;
    tmp.insert(tmp.end(), ALL(floatD));
    ll res = 24;
    for(auto x: tmp){
        res = min( res, min(x, 24-x));
    }
    for(ll i=0; i< tmp.size()-1; i++){
        for(ll j = i+1; j < tmp.size(); j++){
            ll dist = abs(tmp[i]-tmp[j]);
            dist = min(dist, 24 - dist);
            res = min(res, dist);
        }
    }
    return res;
}

void solve(long long N, std::vector<long long> D){
    map<ll, ll> recD;
    REP(i, N) recD[D[i]]++;
    vll D1, D2;
    for(auto x: recD){
        if(x.second > 2){
            cout<<0<<endl; return;
        }
        if(x.second == 1) D1.push_back(x.first);
        if(x.second == 2) D2.push_back(x.first);
    }
    vll fixD;
    for(auto x: D2){
        fixD.push_back(x); fixD.push_back(24-x);
    }
    ll len = D1.size();
    ll ans = 0;
    for(ll S = 0; S < (1LL << len); S++){
        vll floatD;
        REP(j, len){
            if(S>>j & 1) floatD.push_back(D1[j]);
            else floatD.push_back(24-D1[j]);
        }
        ans = max(ans, calDist(fixD, floatD));
    }
    cout<<ans<<endl;
}

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


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

int main(){
  int N;
  cin >> N;
  vector<double> v(N);
  for(int i=0;i<N;i++){
    cin >> v.at(i);
  }
  sort(v.begin(),v.end());
  double ans = (v.at(0)+v.at(1))/2;
  for(int i=2;i<N;i++){
    ans = (ans+v.at(i))/2;
  }
  cout << ans << endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define sd(x) scanf("%d", &x)
#define slld(x) scanf("%lld", &x)
#define all(x) x.begin(), x.end()
#define For(i, st, en) for(ll i=st; i<en; i++)
#define tr(x) for(auto it=x.begin(); it!=x.end(); it++)
#define fast std::ios::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define ll long long
#define int long long
#define mp make_pair
#define F first
#define S second
typedef pair<int, int> pii;
#define MOD 1000000007


signed main(){
    fast;
    // #ifndef ONLINE_JUDGE
    //     freopen("/home/swapnil/Desktop/c++/input.txt","r",stdin);
    //     freopen("/home/swapnil/Desktop/c++/output.txt","w",stdout);
    // #endif
    int n;
    string a, b, c;
    cin>>n>>a>>b>>c;
    int ans = 0;
    for(int i=0; i<n; i++){
        if(a[i]==b[i] && b[i]==c[i]){
            continue;
        }
        if(a[i]==b[i]){
            ans++;
            continue;
        }
        if(a[i]==c[i]){
            ans++;
            continue;
        }
        if(b[i]==c[i]){
            ans++;
            continue;
        }
        ans+=2;
    }
    cout<<ans;
}

Measured memory_bytes: 256
n, k = map(int, input().split())
a = list(map(int, input().split()))

res = 1<<60
for i in range(1<<n):    
    if i % 2 == 0: continue

    use_idx = [0 for _ in range(n)]
    use_cnt = 0
    for j in range(n):
        if i & (1<<j):
            use_idx[j] = 1
            use_cnt += 1
    
    if use_cnt != k: continue

    sm = 0
    mx = a[0]
    for j in range(1, n):
        if use_idx[j]:
            if a[j] <= mx:
                sm += mx+1 - a[j]
                mx += 1
        mx = max(mx, a[j])
    
    res = min(res, sm)

print(res)

Measured memory_bytes: 3064
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <cassert>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <complex>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <functional>
#include <iterator>

using namespace std;

#define dump(n) cout<<"# "<<#n<<'='<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define foreach(i,c) for(auto i=(c).begin();i!=(c).end();++i)
#define all(c) begin(c),end(c)
#define mp make_pair

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;
typedef pair<int,int> pii;

const int INFTY=1<<29;
const double EPS=1e-9;

template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p){
	return os<<'('<<p.first<<','<<p.second<<')';
}
template<typename T>
ostream& operator<<(ostream& os,const vector<T>& a){
	os<<'[';
	rep(i,a.size()) os<<(i?" ":"")<<a[i];
	return os<<']';
}

int main()
{
	for(int h,w;cin>>h>>w,h|w;){
		int a=149,b=150;
		repi(i,1,151) repi(j,i+1,151)
			if(i*i+j*j>h*h+w*w || i*i+j*j==h*h+w*w && i>h)
				if(i*i+j*j<a*a+b*b || i*i+j*j==a*a+b*b && i<a)
					a=i,b=j;
		cout<<a<<' '<<b<<endl;
	}
}

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

int main(){
  // input the data
  int N,K;
  cin >> N >> K;
  vector<int> D(K);
  for(int i=0; i<K; i++){
    cin >> D.at(i);
  }
  
  for(int i=N; ; i++){
    string numstr=to_string(i);
    bool x=true;
    for(int j=0; j<numstr.size(); j++){
      for(int l=0; l<K; l++){
        if (numstr.at(j) == '0'+ D.at(l)) x=false;
      }
    }
    if (x==true){
      cout << i << endl;
      return 0;
    }
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i=0; i<(int)(n); i++)
#define REP1(i,a,b) for(int i=a; i<=(int)(b); i++)
#define ALL(x) begin(x),end(x)
#define PB push_back
using namespace std;
typedef int64_t LL;
typedef vector<int> VI;
typedef pair<int,int> PII;

template<class T> inline bool chmax( T &a, const T &b ) { return b>a ? a=b,true : false; }
template<class T> inline bool chmin( T &a, const T &b ) { return b<a ? a=b,true : false; }
template<class T> using MaxHeap = priority_queue<T>;
template<class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;
template<class T, class F=less<T>> void sort_uniq( vector<T> &v, F f=F() ) {
    sort(begin(v),end(v),f);
    v.resize(unique(begin(v),end(v))-begin(v));
}

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

    int n, Q;
    cin >> n >> Q;
    string s;
    cin >> s;
    int dp[n+1];

    dp[0]=0; dp[1]=0;
    for(int i=1; i<n; i++) {
        dp[i+1] = dp[i];  
        if(s[i-1]=='A' && s[i]=='C') dp[i+1]++; 
    }

    while(Q--) {
        int a, b; cin >> a >> b;
        cout << dp[b] - dp[a] << endl;
    }

    return 0;
}


Measured memory_bytes: 1488
#include <bits/stdc++.h>
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,s,e) for (int i=s;i<(e);i++)
#define All(v) (v).begin(),(v).end()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define int long long
using namespace std;
typedef long long llint;
typedef pair<int, int> P;
const int MOD = (int)1e9 + 7;
const int INF = (int)1e18 * 5;

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

    int n;
    cin >> n;
    vector<int> a(n);
    REP(i, n) cin >> a[i];
    int ans = 0;
    if(a[0] != 0) ans = -1;
    else{
        FOR(i, 1, n){
            if(a[i] == a[i-1]+1) ans++;
            else if(a[i] > a[i-1]){
                ans = -1;
                break;
            }else{
                ans += a[i];
            }
        }
    }
    cout << ans << "\n";
    
    return 0;
}

Measured memory_bytes: 1792
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

//Submission #3535255 - AtCoder Beginner Contest 113 | AtCoder 
// https://abc113.contest.atcoder.jp/submissions/3535255
public class Program_ABC113_C_kuuso1
{
    public static void Main()
    {
        Sol mySol = new Sol();
        mySol.Solve();
    }
}

class Sol
{
    int N, M;
    int[] P, Y;
    /// <summary>
    /// コントラクタ
    /// </summary>
    public Sol()
    {
        var d = ria();
        N = d[0];
        M = d[1];
        P = new int[M];
        Y = new int[M];
        for (int i = 0; i < M; i++)
        {
            d = ria();
            P[i] = d[0];
            Y[i] = d[1];
        }
    }

    public void Solve()
    {

        var di = new Dictionary<int, List<int[]>>();
        for (int i = 0; i < M; i++)
        {
            if (!di.ContainsKey(P[i]))
            {
                di.Add(P[i], new List<int[]>());
            }

            di[P[i]].Add(new[]{i, Y[i]});
        }

        String[] ans = new String[M];
        foreach (var pr in di.Keys)
        {
            var l = di[pr].ToList();
            l.Sort((p, q) => p[1].CompareTo(q[1]));
            for (int i = 0; i < l.Count; i++)
            {
                ans[l[i][0]] = String.Format("{0:D06}{1:D06}", pr, i + 1);
            }
        }

        Console.WriteLine(String.Join("\r\n", ans));

    }

    class Pair
    {
        public int Idx, Y;
        public Pair(int idx, int y)
        {
            Idx = idx;
            Y = y;
        }
    }



    static String rs() { return Console.ReadLine(); }
    static int ri() { return int.Parse(Console.ReadLine()); }
    static long rl() { return long.Parse(Console.ReadLine()); }
    static double rd() { return double.Parse(Console.ReadLine()); }
    static String[] rsa(char sep = ' ') { return Console.ReadLine().Split(sep); }
    static int[] ria(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => int.Parse(e)); }
    static long[] rla(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => long.Parse(e)); }
    static double[] rda(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => double.Parse(e)); }
}


Measured memory_bytes: 45060
#include <iostream>
#include <fstream>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <string>
#include <cmath>
#include <cassert>
#include <ctime>
#include <algorithm>
#include <sstream>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <cstdlib>
#include <cstdio>
#include <iterator>
#include <functional>
#include <bitset>

#ifdef LOCAL
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
clock_t __my_start_clock = clock();
#else
#define eprintf(...)
#endif

#define TIMESTAMP(x) eprintf("["#x"] Time : %.3lf s.\n", (clock() - __my_start_clock)*1.0/CLOCKS_PER_SEC)
#define TIMESTAMPf(x,...) eprintf("[" x "] Time : %.3lf s.\n", __VA_ARGS__, (clock() - __my_start_clock)*1.0/CLOCKS_PER_SEC)

using namespace std;

#ifdef LOCAL
static struct __timestamper {
  string what;
  __timestamper(const char* what) : what(what){};
  __timestamper(const string& what) : what(what){};
  ~__timestamper(){
    TIMESTAMPf("%s", what.data());
	}
} __TIMESTAMPER("end");
#else 
struct __timestamper {};
#endif

typedef long long ll;
typedef long double ld;

char s[1010][1010];
int d[1010][1010];

int main() {
#ifdef LOCAL
  freopen("a.in", "r", stdin);
  freopen("a.out", "w", stdout);
#endif

  int r, c;
  while (scanf("%d%d", &r, &c) == 2) {
    memset(d, -1, sizeof(d));
    queue<pair<int, int>> q;
    for (int i = 0; i < r; i++) {
      scanf("%s", s[i]);
      for (int j = 0; j < c; j++) {
        if (s[i][j] == '#') {
          q.emplace(i, j);
          d[i][j] = 0;
        }
      }
    }

    int ans = 0;

    while (!q.empty()) {
      int u, v;
      tie(u, v) = q.front();
      q.pop();
      ans = max(ans, d[u][v]);
      auto go = [&](int x, int y) {
        if (x >= 0 && x < r && y >= 0 && y < c && d[x][y] == -1) {
          d[x][y] = d[u][v] + 1;
          q.emplace(x, y);
        }
      };
      go(u - 1, v);
      go(u + 1, v);
      go(u, v - 1);
      go(u, v + 1);
    }

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

  return 0;
}


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

using i64 = long long;
using P = pair<i64, i64>;

#define overload3(_1, _2, _3, name, ...) name
#define rep1(i, n) for(i64 i = 0LL; i < (n); ++i)
#define rep2(i, a, b) for(i64 i = (a); i < (b); ++i)
#define rep(...) overload3(__VA_ARGS__, rep2, rep1)(__VA_ARGS__)
#define all(v) v.begin(), v.end()

const string YES = "Yes";
const string NO = "No";

void solve(std::string S){
    i64 n, w, s, e;
    n = w = s = e = 0;
    rep(i, S.length()){
        if(S[i] == 'N') n++;
        if(S[i] == 'W') w++;
        if(S[i] == 'S') s++;
        if(S[i] == 'E') e++;
    }
    if(((n == 0 && s == 0) || (n != 0 && s != 0)) && ((w == 0 && e == 0) || (w != 0 && e != 0))) cout << YES << endl;
    else cout << NO << endl;
}

struct IoSetup {
    IoSetup() {
        // cin.tie(nullptr);
        // ios::sync_with_stdio(false);
        cout << fixed << setprecision(10);
        cerr << fixed << setprecision(10);
    }
} iosetup;

int main(){
    std::string S;
    std::cin >> S;
    solve(S);
    return 0;
}


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

#define MAX_H 1000
#define MAX_W 1000

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

int h, w;
char a[MAX_H][MAX_W];
int d[MAX_H][MAX_W];

int bfs() {
    queue<P> q;
    int ans = 0;
    
    rep(i, h) {
        rep(ii, w) {
            d[i][ii] = INT_MAX;
            
            if (a[i][ii] == '#') {
                q.push(P(i, ii));
                d[i][ii] = 0;
            }
        }
    }
    
    while(q.size()) {
        P p = q.front();
        q.pop();
        
        rep(i, 4) {
            int nx = p.second + dx[i];
            int ny = p.first + dy[i];
            
            if (
                (nx < 0) || (nx >= w) ||
                (ny < 0) || (ny >= h) ||
                (d[ny][nx] != INT_MAX) ||
                (a[ny][nx] == '#')
            ) {
                continue;
            }
            
            q.push(P(ny, nx));
            d[ny][nx] = d[p.first][p.second] + 1;
        }
    }
    
    rep(i, h) {
        rep(ii, w) {
            if (d[i][ii] != INT_MAX) {
                ans = max(ans, d[i][ii]);
            }
        }
    }
    
    return ans;
}

int main() {
    cin >> h >> w;
    rep(i, h) rep(ii, w) cin >> a[i][ii];
    cout << bfs() << endl;
    return 0;
}

Measured memory_bytes: 13328
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int maxm=2e6+5;
//
const int mod=1e9+7;
const int p=1331;
int h[maxm];
int base[maxm];
//
char s[maxm];
int n;
void init(){
    base[0]=1;
    for(int i=1;i<maxm;i++)base[i]=1ll*base[i-1]*p%mod;
    for(int i=1;i<=n;i++){
        h[i]=(1ll*h[i-1]*p+s[i])%mod;
    }
}
int get(int l,int r){
    return (h[r]-1ll*base[r-l+1]*h[l-1]%mod+mod)%mod;
}
bool check(int mid){
    map<int,int>ma;
    for(int i=n;i>=1;i--){
        if(i+mid-1>n)continue;
        int t=get(i,i+mid-1);
        if(ma.count(t)){
            int x=ma[t];
            if(x>i+mid-1)return 1;
        }else{
            ma[t]=i;
        }
    }
    return 0;
}
signed main(){
    scanf("%d",&n);
    scanf("%s",s+1);
    init();
    int ans=0;
    int l=1,r=n/2;
    while(l<=r){
        int mid=(l+r)/2;
        if(check(mid))ans=mid,l=mid+1;
        else r=mid-1;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 11700
#include <iostream>
using namespace std ;
int main () {
string a;
cin >> a ;
for(int i = 0;i < 3; i++){
    if(a[i] == '1'){
        a[i] = '9';
    }else if(a[i] == '9'){
        a[i] = '1';
    }
}
cout << a << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <queue>
#include <algorithm>
#include <utility>
#include <cmath>
#include <map>
#include <set>

#define INF_LL 9000000000000000000
#define INF 2000000000

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

typedef long long ll;
typedef pair<int, int> PII;

class Union_find{
private:
	vector<int> par;
	vector<int> rank;
	int n;

public:
	Union_find(int a){
		n = a;
		for(int i = 0;i < n;i++){
			par.push_back(i);
			rank.push_back(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]++;
		}
	}

	bool same(int x, int y){
		return find(x) == find(y);
	}
};

int main(void){
	int N, x;
	int a[100000];
	ll res = 0;
	cin >> N >> x;
	REP(i, N){
		cin >> a[i];
	}
	FOR(i, 1, N){
		if(a[i-1] + a[i] <= x) continue;
		int must_min = a[i-1] + a[i] - x;
		res += must_min;
		if(must_min > a[i]){
			a[i-1] -= must_min - a[i];
			a[i] = 0;
		}else{
			a[i] -= must_min;
		}
	}
	cout << res << endl;
}


Measured memory_bytes: 640
from collections import defaultdict

def solve(n, m, PY):
    index = {
        y: i
        for i, (_, y) in enumerate(PY)
    }

    PY.sort(key=lambda py: py[1])
    counts = defaultdict(int)
    ret = [''] * m
    for p, y in PY:
        counts[p] += 1
        ret[index[y]] = '{0:06d}{1:06d}'.format(p, counts[p])
    return ret

_n, _m = map(int, input().split())
_PY = [list(map(int, input().split())) for _ in range(_m)]
print(*solve(_n, _m, _PY), sep='\n')


Measured memory_bytes: 55548
import java.util.*;

public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt(), M = sc.nextInt();
		int[] b = new int[M];
		for (int i = 0; i < N; i++) {
			int K = sc.nextInt();
			for (int j = 0; j < K; j++) {
				int a = sc.nextInt()-1;
				b[a]++;
			}
		}
		int count = 0;
		for (int i = 0; i < M; i++) {
			if (b[i] == N) count++;
		}
		System.out.println(count);
	}

}

Measured memory_bytes: 24404