akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
int main()
{
  int i,j,n,x,y,a,b;;
  char c,t;
  int map[30][30];
  for(;scanf("%d",&n),n;puts(n?"No":"Yes"))
    {
      for(i=0;i<30;i++)
	for(j=0;j<30;j++)
	  map[i][j]=0;
      for(j=n;j--;map[x][y]=1)
	  scanf("%d%d",&x,&y);
      scanf("%d",&j);
      getchar();
      for(a=b=10;j--;)
	{
	  i=c=0;
	  while((t=getchar())!='\n')
	    if(t>='0' &&t<='9')
	      i=i*10+t-'0';
	    else if(t>'A' && t<'Z')
	      c=t;
	  for(;i--;)
	    {
	      if(c=='N')
		b++;
	      if(c=='E')
		a++;
	      if(c=='S')
		b--;
	      if(c=='W')
		a--;
	      if(map[a][b]==1)
		  map[a][b]=0,n--;
	    }
	}
    }
  exit(0);
}

Measured memory_bytes: 0
#include<iostream>
#include<math.h>
#include<vector>
#include<array>
#include<algorithm>
#include<numeric>
#include<map>
#include<queue>
#include<deque>
#include<set>
#include<cstdio>
#include<cstring>
#include<string>
using namespace std;
typedef long long ll;
typedef vector<double> vec;
typedef vector<vector<double>> mat;

int main(){
    int N;scanf("%d",&N);
    vec p(N);
    for(int i=0;i<N;i++) scanf("%lf",&p[i]);
    mat dp(2,vec(N+1,0.0));
    dp[0][0]=1.0;
    for(int i=1;i<=N;i++){
        dp[1][0]=dp[0][0]*(1.0-p[i-1]);
        for(int j=1;j<=i;j++){
            dp[1][j]=p[i-1]*dp[0][j-1]+(1.0-p[i-1])*dp[0][j];
        }
        dp[0]=dp[1];
    }
    double ans=0.0;
    for(int i=(N+1)/2;i<=N;i++) ans+=dp[0][i];
    printf("%.10lf\n",ans);
    return 0;
}

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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

/**
 * ワーシャルフロイド法
 * 隣接行列で受け取り、全頂点間最短経路を算出
 */
void warshall_floyd(Graph &graph) {
    int V = graph.size();
    for (int k = 0; k < V; ++k) {
        for (int i = 0; i < V; ++i) {
            for (int j = 0; j < V; ++j) {
                graph[i][j] = min(graph[i][j], graph[i][k] + graph[k][j]);
            }
        }
    }
}

void Main() {
    int H, W;
    cin >> H >> W;
    Graph graph(10, vector<ll>(10, INF));
    rep(i, 10) {
        rep(j, 10) {
            int c;
            cin >> c;
            graph[i][j] = c;
        }
    }
    warshall_floyd(graph);
    ll ans = 0;
    rep(i, H) {
        rep(j, W) {
            int a;
            cin >> a;
            if (a != -1) ans += graph[a][1];
        }
    }
    cout << ans << '\n';
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
}


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

const long long INF = (long long)1e18;

long long count_cross(long long num, long long key, const vector<long long>& dat) {
    int res = 0;
    for (int lo=0,hi=(int)dat.size()-1; lo<=hi; ) {
        int mid = (lo + hi) / 2;
        long long ret = num * dat[mid];

        if (ret <= key) {
            res = max(res, (int)dat.size()-mid);
            hi = mid - (long long)1;
        } else {
            lo = mid + (long long)1;
        }
    }
    return res;
}

long long count_inside(int idx, long long key, const vector<long long>& dat) {
    long long num = dat[idx];

    int res = 0;
    for (int lo=idx+1,hi=(int)dat.size()-1; lo<=hi; ) {
        int mid = (lo + hi) / 2;
        long long ret = num * dat[mid];

        if (ret <= key) {
            res = max(res, mid-idx);
            lo = mid + (long long)1;
        } else {
            hi = mid - (long long)1;
        }
    }

    return res;
}

vector<long long> positive;
vector<long long> negative;
long long zeros;

long long count_less_than(long long key) {
    long long res = (long long)0;

    for (long long x: negative) {
        res += count_cross(-x, key, positive);
    }

    for (int idx=0; idx<(int)negative.size(); idx++) {
        res += count_inside(idx, key, negative);
    }

    for (int idx=0; idx<(int)positive.size(); idx++) {
        res += count_inside(idx, key, positive);
    }

    if (key >= (long long)0) {
        res += zeros * (zeros-(long long)1) / (long long)2;
        res += zeros * (long long)positive.size();
        res += zeros * (long long)negative.size();
    }

    return res;
}

int main() {
    positive.clear();
    negative.clear();
    zeros = 0;

    int n; scanf("%d", &n);
    long long k; scanf("%lld", &k);
    for (int i=1; i<=n; i++) {
        long long a; scanf("%lld", &a);

        if (a < (long long)0) {
            negative.push_back(-a);
        } else if (a == (long long)0) {
            zeros += (long long)1;
        } else if (a > (long long)0) {
            positive.push_back(a);
        }
    }

    sort(positive.begin(), positive.end());
    sort(negative.begin(), negative.end());

    long long res = INF;
    for (long long lo=-INF,hi=INF; lo<=hi; ) {
        long long mid = (lo + hi) / 2;
        long long ret = count_less_than(mid);

        if (ret < k) {
            lo = mid + (long long)1;
        } else {
            res = min(res, mid);
            hi = mid - (long long)1;
        }
    }

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


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

typedef pair<int,int> ii;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<ll> vll;
#define pb push_back
#define eb emplace_back
#define pob pop_back
#define psf push_front
#define pof pop_front
#define mkp make_pair
#define mkt make_tuple
#define all(x) x.begin(), x.end()

const int MAXS = 104;
ll dp[MAXS][100002];
ll val[MAXS];
ll we[MAXS];

ll solve(ll elem, ll weight){
    if (elem < 0) return 0;
    ll &ans = dp[elem][weight];
    if (ans != -1) return ans;
    ll take, not_to_take;
    take = not_to_take = 0;
    if (weight - we[elem] >= 0) take = val[elem] + solve(elem-1, weight - we[elem]);
    not_to_take = solve(elem-1, weight);
    return ans = max(take, not_to_take);
}

int main(){
	ios::sync_with_stdio(false), cin.tie(nullptr);
    int n,w; cin>>n>>w;
    for (int i=0; i<n; i++){
        cin>>we[i];
        cin>>val[i];
    }
    memset(dp, -1, sizeof dp);
    cout<<solve(n-1, w)<<'\n';
    
	return 0;
}
/*
NARCO
*/


Measured memory_bytes: 84876
#include <bits/stdc++.h>
#define ALL(A) (A).begin(), (A).end()
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); i++)

const ll mod = 1e9 + 7;
const ll INF = -1 * ((1LL << 63) + 1);
const int inf = -1 * ((1 << 31) + 1);

using namespace std;

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    int N;
    cin >> N;
    char S;
    set<char> st;
    rep(i,N){
        cin >> S;
        st.insert(S);
    }

    if(st.size()==3)cout << "Three" << endl;
    else cout << "Four" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
using namespace std;
#define MOD 1000000007

int N;
double dp[3333][3333];
double p[3333];

int main(){
    cin >> N;
    for(int i=0; i<N; i++)
        cin >> p[i];

    dp[0][0] = 1.0;
    for(int i=0; i<N; i++){
        for(int j=0; j<=N; j++){
            dp[i+1][j] = dp[i][j]*(1.0-p[i]);
            if(j != 0)
                dp[i+1][j] += dp[i][j-1]*p[i];
        }
    }
    double ans = 0;
    for(int i=N/2+1; i<=N; i++)
        ans += dp[N][i];
    cout << fixed << setprecision(32) << ans << endl;
    return 0;
}

Measured memory_bytes: 80128
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
int main(int argc, char const *argv[]) {
    int n;
    cin >> n;
    vector<int> a(n);
    REP(i,n) cin >> a[i];
    int cnt = 0;
    REP(i,n) {
        if (a[i] == i+1) {
            cnt++;
            if (i != n-1 && a[i+1] == i+2) i++;
        }
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 640
var
	n,i,a,b,ca,cb,cc,p:Longint;
begin
	read(n,a,b);
	for i:=1 to n do begin
		read(p);
		if p<=a then inc(ca)else if p<=b then inc(cb)else inc(cc);
	end;
	if ca>cb then ca:=cb;
	if ca>cc then ca:=cc;
	writeln(ca);
end.


Measured memory_bytes: 128
h, w = map(int, input().split())
a = [''] * h 
for i in range(h):
    a[i] = input()
row = [False] * h
col = [False] * w
for i in range(h):
        for j in range(w):
                if a[i][j] == '#':
                        row[i] = True
                        col[j] = True
for i in range(h):
        if row[i]:
                for j in range(w):
                        if col[j]:
                                print(a[i][j], end = '')
                print()

Measured memory_bytes: 4468
#include <stdio.h>

int main(void) {
   int  N,A,B,C,D,price;
   scanf( "%d %d %d %d %d" , &N,&A,&B,&C,&D );
   price=((N/A+( N%A != 0 ))*B<(N/C+( N%C != 0 ))*D)*(N/A+( N%A != 0 ))*B+((N/A+( N%A != 0 ))*B>=(N/C+( N%C != 0 ))*D)*(N/C+( N%C != 0 ))*D;
   printf("%d\n" , price);
   return 0;
}



Measured memory_bytes: 2140
#include <iostream>
#include<stdio.h>
using namespace std;

void ini(int* p,int n);
void print(int *p);
void check(int *p);
bool judge(int *p);

int main(){
  int n;
  while(1){
    bool ans;
    cin >> n;
    if(n == 0) break;
    int state[21];
    for(int i = 0; i<21 ; i++){
      state[i] = 0;
    }
    
    ini(state,n);
    //print(state);
    check(state);
    ans = judge(state);
    if(ans == 0) printf("Yes\n");
    else printf("No\n");
    //print(state);
  }
  return 0;
}


void ini(int* state,int n){
  int x, y;
  int mask;
  for(int i = 0; i<n; i++){
    cin >>x >> y;
    mask = (04000000 >> x);
    state[y] =( state[y] | mask);
  }
}

void check(int* state){
  int n;
  char dir;
  int step;
  int nowx = 10, nowy = 10;
  int mask;
  
  cin >> n;
  for(int i  = 0;  i< n; i++){
    //printf("x = %d y = %d",nowx, nowy);
    cin >>dir >> step;
    // printf("%c %d\n",dir,step);
    switch(dir){
    case 'N':
      mask = ~(04000000 >>nowx);
      for(int j = 0; j<step; j++){
	nowy ++;
	//printf("%d\n",nowy);
	state[nowy] = (state[nowy] & mask);
      }
      break;
    case 'S':
      mask = ~(04000000 >>nowx);
      for(int j = 0; j<step; j++){
	nowy --;
	state[nowy] = (state[nowy] & mask);
      }
      break;
    case 'E':
      for(int j = 0; j<step; j++){
	nowx ++;
	mask = ~(04000000 >>nowx);
	state[nowy] = (state[nowy] & mask);
      }
      break;
    case 'W':
      for(int j = 0; j<step; j++){
	nowx --;
	mask = ~(04000000 >>nowx);
	state[nowy] = (state[nowy] & mask);
      }
      break;
    }
  }
}

bool judge(int *state){
  for(int i = 0; i< 21; i++){
    if(state[i] != 0) return 1;
  }
  return 0;
}


	
void print(int *p){
  for(int i = 0; i<21; i++){
    printf("[ %d] %o\n",i,p[i]);
  }
}

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

int main() {
  unsigned int n;
  cin >> n;
  string s;
  cin >> s;
  if(s.size()<=n){
    cout << s << endl;
  }
  else {
  for(unsigned int i=0;i<n;i++){
    cout << s.at(i);
  }
    cout << "..." << endl; 
  }
}

Measured memory_bytes: 3628
#include<iostream>
#include<cstring>
#include<queue>
#include<map>
using namespace std;
int main(){
  int N,T,E,data[101],flg=0;
  int ok[10001][2];
  memset(ok,0,sizeof(ok));
  cin >> N >> T >> E;
  for(int i=0;i<N;i++){
    cin >> data[i];
    ok[data[i]][0]=1;
    ok[data[i]][1]=i+1;
  }
  for(int i=0;i<N;i++){
    for(int j=2;data[i]*j<10001;j++){
      ok[data[i]*j][0]=1;
      ok[data[i]*j][1]=ok[data[i]][1];
    }
  }
  for(int i=T-E;i<=T+E;i++){
    if(ok[i][0]==1){
      cout << ok[i][1] << endl;
      flg=1;
      break;
    }
  }
  if(flg==0)cout << -1 << endl;
}

Measured memory_bytes: 1248
#include <algorithm>

int uf[100010];
void init(int n){ for(int i = 0; i < n; i++) uf[i] = -1; }
int find(int x){
    if(uf[x] < 0) return x;
    return uf[x] = find(uf[x]);
}
void unite(int x, int y){
    x = find(x); y = find(y);
    if(x != y){ uf[x] += uf[y]; uf[y] = x; }
}
bool same(int x, int y){
    return find(x) == find(y);
}

#include <cstdio>

int main(){
    int n,q;
    scanf("%d%d",&n,&q);
    init(n);
    while(q--){
        int c,x,y;
        scanf("%d%d%d",&c,&x,&y);
        if(c){
            printf("%d\n",same(x,y));
        } else {
            unite(x,y);
        }
    }
}

Measured memory_bytes: 1048
module StringMap = Map.Make (struct
  type t = string
  let compare = compare
end)

let () = Scanf.scanf "%d\n" @@ fun n ->
  let ss = Array.init n @@ fun _ ->
    Scanf.scanf "%s\n" @@ fun s ->
      let a = Array.init (String.length s) (String.get s) in
      Array.sort compare a;
      String.init (String.length s) (Array.get a) in
  Printf.printf "%d\n" @@
  StringMap.fold (fun _ n acc -> acc + n * (n - 1) / 2)
    (Array.fold_left (fun m s ->
      StringMap.add s
        (1 + try StringMap.find s m with Not_found -> 0) m)
    StringMap.empty ss) 0




Measured memory_bytes: 17152
<?php
  fscanf(STDIN,"%d %d %d",$a,$b,$c);
  $k = trim(fgets(STDIN));
  $max = max($a,$b,$c);
  $total = $a+$b+$c-$max;
  
  for($i=0; $i<$k; $i++){
    $max = $max*2;
  }
  echo $max+$total."\n";

Measured memory_bytes: 4604
#include <bits/stdc++.h>
#define Rint register int
#define C(n,m) (n<m?0:1ll*fac[n]*invfac[n-m]%mod*invfac[m]%mod)
using namespace std;
int T,n,m,p,k;
int fa[100010],sz[100010],a[100010],b[100010],c[100010],deg[100010];
bool nocy[100010];
int Y[100010],Z[100010];
int X=0;
int find(int a){
	return fa[a]==a?a:fa[a]=find(fa[a]);
}
void merge(int a,int b){
	a=find(a),b=find(b);
	if(a==b) return;
	fa[a]=b;
	sz[b]+=sz[a];
}
int main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++) fa[i]=i,sz[i]=1;
	for(int i=1;i<=m;i++){
		scanf("%d%d%d",&a[i],&b[i],&c[i]);c[i]--;
		merge(a[i],b[i]);deg[a[i]]++,deg[b[i]]++;
	}
	for(int i=1;i<=n;i++) if(deg[i]>2) nocy[find(i)]=true;
	for(int i=1;i<=n;i++) if(find(i)==i&&!nocy[i]&&sz[i]>=2) X++;
	int now=0;
	bool flag=0;
	for(int i=1;i<=m;++i) if(c[i]){
		if(nocy[find(a[i])]){
			if(a[i]==b[i]) Z[++Z[0]]=c[i];
			else flag=true,now+=c[i];
		}
		else{
			if(a[i]==b[i]) Y[++Y[0]]=c[i]-1;
			else now+=c[i];
		}
	}
	sort(Y+1,Y+Y[0]+1),reverse(Y+1,Y+Y[0]+1);
	sort(Z+1,Z+Z[0]+1),reverse(Z+1,Z+Z[0]+1);
	for(int i=1;i<=Y[0];++i) now+=Y[i];
	int ans=INT_MAX;
	for(int i=1,j=Y[0];i<=Z[0]+1;i++){
		while(j>=1&&now-Y[j]>=X) now-=Y[j--];
		if((flag||i>1||X==0)&&now>=X) ans=min(ans,i+2*j-1);
		if(i<=Z[0]) now+=Z[i];
	}
	if(ans>2e9) puts("-1");
	else{
		ans+=X;
		for(int i=1;i<=m;i++) if(a[i]!=b[i]) ans++;
		printf("%d\n",ans);
	}
}


Measured memory_bytes: 6748
n = int(input())
listA=  list(map(int, input().split()))

index=0
countTwo =0
countFour=0
while index < len(listA):
    if listA[index]%4 ==0:
        countFour+=1
    elif listA[index]%2 ==0:
        countTwo+=1
    else:
        pass
    index+=1

if countFour + countTwo//2 > n//2-1:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 14252
import numpy as np
h,w=map(int,input().split())
a=np.array([[0 if i!="." else 1 for i in input()]for j in range(h)])
s,t,u,p=np.zeros((h,w)),np.zeros((h,w)),np.zeros((h,w)),np.zeros((h,w))
for i in range(h):
    s[i]=(s[i-1]+1)*a[i]
    t[-i-1]=(t[-i]+1)*a[-i-1]
for i in range(w):
    u[:,i]=(u[:,i-1]+1)*a[:,i]
    p[:,-i-1]=(p[:,-i]+1)*a[:,-i-1]
print(int(np.max(s+t+u+p))-3)

Measured memory_bytes: 253884
#include<stdio.h>
int main()
{
int  n, m, a[200001]={0}, b[200001]={0};
int  i, j, k, f=0;

scanf("%d %d", &n, &m);
for( k=0; k<m; k++){
scanf("%d %d", &i, &j);
if( i == 1) a[j] = 1;
if( j == n) b[i] = 1;
}

for( i=1; i<=n; i++){
if(a[i]==1){
if(b[i]==1){
f = 1;
}
}
}

if(f)
printf("POSSIBLE\n");
else
printf("IMPOSSIBLE");

return 0;
}

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

int main()
{
    int n;
    string s;

    cin >> n;

    while( n-- )
    {
        cin >> s;

        string min, max = "";
        for( int i = 0; i < 7; i++ )
        {
            for( int j = i + 1; j < 8; j++ )
            {
                if( s[i] - '0' > s[j] - '0' )
                {
                    char temp = s[i];
                    s[i] = s[j];
                    s[j] = temp;
                }
            }
        }
        min = s;

        for( int i = 7; i >= 0; i-- )
            max += min[i];
        
        int mi = 0, ma = 0, mul = 1;
        for( int i = 7; i >= 0; i-- )
        {
            mi += ( min[i] - '0' ) * mul;
            ma += ( max[i] - '0' ) * mul;
            mul *= 10;
        }
        cout << ma - mi << endl;
    }
    return 0;
}


Measured memory_bytes: 3176
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repr(i,n) for(int i = (int)(n); i >= 0; i--)
#define all(v) v.begin(),v.end()
typedef long long ll;

int main(){
    int K;
    cin >> K;
    rep(i,K){
        cout << "ACL";
    }
    cout << endl;
}

Measured memory_bytes: 3528
N,M = map(int, input().split())
A,B = [],[]
for i in range(N):
    A_next, B_next = map(int,input().split())
    A.append(A_next)
    B.append(B_next)
l = sorted(list(zip(A,B)), key=lambda x:x[0])
count = 0
value = 0
i = 0
while(count<M):
    if(M-count<l[i][1]):
        value = value + l[i][0]*(M-count)
        break
    else:
        value = value + l[i][0]*l[i][1]
        count = count + l[i][1]
        i = i + 1
print(value)

Measured memory_bytes: 20480
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define INF (1LL<<50)
#define MOD 1000000007

int main(){
    string S;
    cin >> S;
    reverse(S.begin(),S.end());
    string dream = "maerd";
    string dreamer = "remaerd";
    string erase = "esare";
    string eraser = "resare";
    int i;
    for(i=0;i<S.length();i++){
        string tmp_dr,tmp_er;
        if(S[i]=='r'){
            tmp_dr = S.substr(i,7);
            tmp_er = S.substr(i,6);
            if(tmp_dr==dreamer){
                i+=6;
                continue;
            }
            if(tmp_er==eraser){
                i+=5;
                continue;
            }
            cout << "NO" << endl;
            return 0;
        }else{
            tmp_dr = S.substr(i,5);
            tmp_er = S.substr(i,5);
            if(tmp_dr==dream){
                i+=4;
                continue;
            }
            if(tmp_er==erase){
                i+=4;
                continue;
            }
            cout << "NO" << endl;
            return 0;
        }
    }
    if(i!=S.length()){
        cout << "NO" << endl;
        return 0;
    }
    cout << "YES" << endl;
    return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<string>
#include<string.h>
#include<algorithm>
#include<stdio.h>
#include<cmath>
#include<vector>
#include<utility>
#include<stack>
#include<queue>
#include<list>
#include<bitset>
#include<functional>

#define FOR(i, a, b) for(long long int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for(long long int i=(a);i>=(b);i--)
#define MOD 1000000007
#define INF 1000000000 //2000000000
#define LLINF 1000000000000000000 //9000000000000000000
#define PI 3.14159265358979

using namespace std;
typedef long long int ll;
typedef pair<long long int, long long int> P;


int main(void) {
	ll  n, m;
	ll count = 0;
	

	cin >> n >> m;

	if (n == 1 || m == 1) {
		if (n == 1 && m == 1) {
			count = 1;
		}
		else if (n == 1) {
			if (m <= 2) {
				count = 0;
			}
			else {
				count = m - 2;
			}
		}
		else {
			if (n <= 2) {
				count = 0;
			}
			else {
				count = n - 2;
			}
		}
	}
	else {
		if (m - 2 <= 0) {
			count = 0;
		}
		else {
			count = m - 2;
		}
		if (n - 2 <= 0) {
			count = 0;
		}
		else {
			count *= (n - 2);
		}
	}

	

	cout << count << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define P pair<int,int>
using ll=int64_t;
using namespace std;
#define ketasuu(n) fixed<<setprecision(n)
#define btoe(p) p.begin(),p.end()
#define etob(p) p.rbegin(),p.rend()




int main(){
    string s;
    cin>>s;
    if((s[5]-'0')*10+s[6]-'0'<5) cout<<"Heisei"<<endl;
    else cout<<"TBD"<<endl;
}

Measured memory_bytes: 256
from bisect import bisect_left

INF = 2 * 10**10

A, B, Q = map(int, input().split())
S = [-INF] + [int(input()) for _ in range(A)] + [INF]
T = [-INF] + [int(input()) for _ in range(B)] + [INF]
X = [int(input()) for _ in range(Q)]
ans = []
for x in X:
    sr = bisect_left(S, x) 
    sl = sr if S[sr] == x else sr -1
    tr = bisect_left(T, x)
    tl = tr if T[tr] == x else tr -1

    ll = x - min(S[sl], T[tl])
    rr = max(S[sr], T[tr]) - x
    lsrt = 2*(x-S[sl]) + (T[tr] - x)
    ltrs = 2*(x-T[tl]) + (S[sr] - x)
    rslt = 2*(S[sr] - x) + (x - T[tl])
    rtls = 2*(T[tr] - x) + (x - S[sl])

    ans.append(min(ll, rr, lsrt, ltrs, rslt, rtls))
print(*ans, sep='\n')

Measured memory_bytes: 21832
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func main() {
	scanInit()

	n := nextInt()
	cnt := 0
	for i := 1; i <= n; i += 2 {
		cntt, _ := getDivlist(i)

		if cntt == 8 {
			cnt++
		}
	}

	fmt.Println(cnt)
}

// 約数列挙リストを作成
func getDivlist(a int) (cnt int, divlist []int) {
	divlist = make([]int, a/2+1)
	idx := 0
	for i := 1; i*i <= a; i++ {
		if a%i == 0 {
			cnt++
			divlist[idx] = i
			idx++
			if i*i != a {
				cnt++
				divlist[idx] = a / i
				idx++
			}
		}
	}
	return cnt, divlist
}

// 約数の数をカウントする(愚直)
func numYaku(a int) int {
	cnt := 1
	for i := 1; i <= a/2; i++ {
		if a%i == 0 {
			cnt++
		}
	}
	return cnt
}

// ---- readfunc
func scanInit() {
	const cap = 200 * 1024 // Default=64
	var buf = make([]byte, cap)
	sc.Buffer(buf, cap)
	sc.Split(bufio.ScanWords)
	return
}
func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}
func nextStr() string {
	sc.Scan()
	return sc.Text()
}


Measured memory_bytes: 1916
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define REV(c) reverse((c).begin(),(c).end())

using namespace std;
typedef pair<int,int> P;

// 最大公約数
int64_t gcd(int64_t a, int64_t b) {
  return b != 0 ? gcd(b, a % b) : a;
}

// 最小公倍数
int64_t lcm(int64_t a, int64_t b) {
  return a * b / gcd(a, b);
}

int ctoi(char c){
  return c - '0';
}

std::vector<int> enum_div(int n)//nの約数を列挙
{
  std::vector<int> ret;
  for(int i=1 ; i*i<=n ; ++i)
  {
    if(n%i == 0)
    {
      ret.push_back(i);
      if(i!=1 && i*i!=n)
      {
        ret.push_back(n/i);
      }
    }
  }
  return ret;
}

int main(){
  int64_t n;
  cin >> n;
  vector<int> vec(n);
  REP(i,n){
    cin >> vec.at(i);
  }
	if (n==1){
		if (vec.at(0) == 0){
  		cout << 0 << endl;
		}else{
  		cout << 1 << endl;
  		cout << 1 << endl;
		}
		return 0;
	}
  vector<int> vec2(n+1, 0);
  for(int i=n;i>0;i--){
    int c = vec2.at(i) % 2;
    if (vec.at(i-1) == 0){
      if (c == 0){
				vec2.at(i) = 0;
      }else{
        vec2.at(i) = 1;
        auto r = enum_div(i);
        for (auto a: r){
          if (i!=a){
            vec2.at(a)++;
          }
        }
      }
    }else{
      if (c == 0){
        vec2.at(i) = 1;
        auto r = enum_div(i);
        for (auto a: r){
          if (i!=a){
            vec2.at(a)++;
          }
        }
      }else{
				vec2.at(i) = 0;
      }
    }
  }
  int t = 0;
  REP(i,n+1){
    if (i!=0){
      if (vec2.at(i) % 2 == 1){
        t++;
      }
    }
  }
  cout << t << endl;
  bool chk = false;
  REP(i,n+1){
    if (i!=0){
      if (vec2.at(i) % 2 == 1){
        if (!chk){
          cout << i;
          chk = true;
        }else{
          cout << " " << i;
        }
      }
    }
  }
	if (chk){
  	cout << endl;
  }
  return 0;
}



Measured memory_bytes: 2432
/*
ЗАПУСКАЕМ 
░ГУСЯ░▄▀▀▀▄░РАБОТЯГУ░░
▄███▀░◐░░░▌░░░░░░░
░░░░▌░░░░░▐░░░░░░░
░░░░▐░░░░░▐░░░░░░░
░░░░▐░░░░░▐░░░░░░░
░░░░▐░░░░░▐░░░░░░░
░░░░▐░░░░░▐░░░░░░░
░░░░▐░░░░░▐░░░░░░░
░░░░▐░░░░░▐░░░░░░░
░░░░▐░░░░░▐░░░░░░░
░░░░▐░░░░░▐░░░░░░░
░░░░▌░░░░░▐▄▄░░░░░
░░░░▌░░░░▄▀▒▒▀▀▀▀▄
░░░▐░░░░▐▒▒▒▒▒▒▒▒▀▀▄
░░░▐░░░░▐▄▒▒▒▒▒▒▒▒▒▒▀▄
░░░░▀▄░░░░▀▄▒▒▒▒▒▒▒▒▒▒▀▄
░░░░░░▀▄▄▄▄▄█▄▄▄▄▄▄▄▄▄▄▄▀▄
░░░░░░░░░░░▌▌░▌▌░░░░░
░░░░░░░░░░░▌▌░▌▌░░░░░
░░░░░░░░░▄▄▌▌▄▌▌░░░░░ 
 */
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>


using namespace std;
template<typename T1, typename T2> inline void chkmin(T1 &a, T2 b) {if (a > b) a = b;}
template<typename T1, typename T2> inline void chkmax(T1 &a, T2 b) {if (a < b) a = b;}
#define files(FILENAME) read(FILENAME); write(FILENAME)
#define read(FILENAME) freopen((FILENAME + ".in").c_str(), "r", stdin)
#define write(FILENAME) freopen((FILENAME + ".out").c_str(), "w", stdout)
#define all(c) (c).begin(), (c).end()
#define sz(c) (int)(c).size()
#define left left228
#define right right228
#define y1 y1228
#define mp make_pair
#define pb push_back
#define y2 y2228
#define rank rank228
using ll = long long;
using ld = long double;
const string FILENAME = "input";
const int Mod = 998244353;
const int MAXN = 305;


int sum(int a, int b) {
	return (a + b >= Mod ? a + b - Mod: a + b);
}

int mul(int a, int b) {
	return (ll)a * b % Mod;
}



void add(int &a, int b) {
	a += b;
	if (a >= Mod) {
		a -= Mod;
	}
}


int n;
int f[MAXN][MAXN][MAXN];
bool g[MAXN][MAXN][MAXN];
int ans;



int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
 	//read(FILENAME);
	string s;
	cin >> s;
	n = sz(s);
	g[0][0][0]=1;
	for (int i=1;i<=n;i++) for (int p0=0;p0<=i;p0++) for (int p1=0;p1<=i;p1++) {
		g[i][p0][p1]=g[i-1][p0][p1];
		if (i>=2) {
			if ((s[i-1]=='0'||s[i-2]=='0')&&p0>0) g[i][p0][p1]|=g[i-2][p0-1][p1];
			if ((s[i-1]=='1'||s[i-2]=='1')&&p1>0) g[i][p0][p1]|=g[i-2][p0][p1-1];
		}
		if (s[i-1]=='0'&&p0>0) g[i][p0][p1]|=g[i-1][p0-1][p1+1];
		if (s[i-1]=='1'&&p1>0) g[i][p0][p1]|=g[i-1][p0+1][p1-1];
	}
	f[0][0][0]=1;
	for (int d=0;d<=n;d++) {
		for (int p0=0;p0<=d;p0++) for (int p1=0;p0+p1<=d;p1++) {
			int mt=d-p0-p1;
			if (g[n-mt][p0][p1]) {
				add(ans,f[d][p0][p1]);
			}
			if (d==n) continue;
			char t=s[n-1-mt];
			if (t=='0') add(f[d+1][p0][p1],f[d][p0][p1]);
			else add(f[d+1][p0+1][p1],f[d][p0][p1]);
			if (t=='1') add(f[d+1][p0][p1],f[d][p0][p1]);
			else add(f[d+1][p0][p1+1],f[d][p0][p1]);
		}
	}
	ans = sum(ans, Mod - 1);
	cout << ans << '\n';
	return 0;	 	
}


Measured memory_bytes: 73268
#include <bits/stdc++.h>
using namespace std;
long long findNumberOfTriangles(long long arr[], long long n)
{
   long long count = 0;
    for (long long i= 0; i < n; i++)
    {
        for (long long j = i + 1; j < n; j++)
        {
            for (long long k = j + 1; k < n; k++){
                    if(arr[i]==arr[j]||arr[k]==arr[j]||arr[i]==arr[k])
                    continue;
                    if (
                    arr[i] + arr[j] > arr[k]
                    && arr[i] + arr[k] > arr[j]
                    && arr[k] + arr[j] > arr[i])
                    count++;
            }


        }
    }
    return count;
}

int main()
{
    long long n,arr[104],i;
    cin>>n;
    for(i=0;i<n;i++)
        cin>>arr[i];

    cout<< findNumberOfTriangles(arr, n);

    return 0;
}


Measured memory_bytes: 3636
import java.util.HashMap;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		sc.nextLine();
		HashMap<Integer, Integer> mapA = new HashMap<Integer, Integer>();
		HashMap<Integer, Integer> mapB = new HashMap<Integer, Integer>();
		for (int i = 0; i < m; i++) {
			int a = sc.nextInt();
			int b = sc.nextInt();
			if (a == 1) {
				if (mapB != null && mapB.get(b) != null) {
					System.out.println("POSSIBLE");
					sc.close();
					return;
				}
				mapA.put(b, b);
			} else if (a == n) {
				if (mapA != null && mapA.get(b) != null) {
					System.out.println("POSSIBLE");
					sc.close();
					return;
				}
				mapB.put(b, b);
			}
			if (b == 1) {
				if (mapB != null && mapB.get(a) != null) {
					System.out.println("POSSIBLE");
					sc.close();
					return;
				}
				mapA.put(a, a);
			} else if (b == n) {
				if (mapA != null && mapA.get(a) != null) {
					System.out.println("POSSIBLE");
					sc.close();
					return;
				}
				mapB.put(a, a);
			}
			sc.nextLine();
		}
		sc.close();
		String result = "IMPOSSIBLE";
		for (int i : mapA.keySet()) {
			if (mapB.get(i) != null) {
				result = "POSSIBLE";
				break;
			}
		}
		System.out.println(result);
	}
}

Measured memory_bytes: 237596
import java.util.Scanner;
public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while(true){
            int m = sc.nextInt();
            String op = sc.next();
            int n = sc.nextInt();
            if(((String) op).equals("+")) {
                System.out.println(m + n);
            }
            if(((String) op).equals("-")) {
                System.out.println(m - n);
            }
            if(((String) op).equals("*")) {
                System.out.println(m * n);
            }
            if(((String) op).equals("/")) {
                System.out.println(m / n);
            }
            if(((String) op).equals("?")) {
                break;
            }
        }
    }
}


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

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

ll power(int b,int n)
{
	if(n==0) return 1LL;
	ll temp=power(b,n/2);
	temp*=temp;
	
	if(n%2) temp*=(ll)b;
	
	return temp;
}


int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	
	int n,k;
	cin>>n>>k;
	
	ld tot=0.0;
	
	for(int i=1;i<=n;i++)
	{
		int j=0;
		int temp=i;
		while(temp<k)
		{
			temp*=2;
			j++;
		}
		
		ld ans=1.0/(ld)power(2,j);		
		
		tot+=ans;
	}
	
	tot/=(ld)n;
	
	cout<<fixed<<setprecision(15)<<tot;
		
		
					                                				
	cerr<<"\nTime elapsed: " << 1000.0 * clock() / CLOCKS_PER_SEC << " ms\n";
	
	return 0;
}

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

int main(int argc, const char * argv[]) {
    
    int n;
    long total=0;
    std::cin >> n;
    
    for(int i=1; i<=n; i++){
        if(i%3!=0 && i%5!=0){
            total=total+i;
        }
    }
    
    std::cout << total;

    return 0;
}

Measured memory_bytes: 3636
#include <iostream>

int n, k;

int main()
{

    std::cin >> n >> k;

    int max = (n - 1) * (n - 2) / 2;

    if (k > max)
        std::cout << -1 << std::endl;

    else
    {

        int m = n - 1 + max - k;

        std::cout << m << std::endl;

        for (int i = 0; i < n - 1; ++i)
            std::cout << 1 << ' ' << i + 2 << std::endl;

        int node = 2;

        for (int i = 0; i < max - k; ++i)
        {

            int j = n * (node - 2) - (node - 2) * (node + 1) / 2;

            std::cout << node << ' ' << i - j + node + 1 << std::endl;

            if (i == j + n - node - 1)
                ++node;
        }
    }

    return 0;
}

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

using namespace std;
using ll = long long int;
#define long ll

int main(void) {
    cin.tie(0); ios::sync_with_stdio(false);
    string a, b;
    cin >> b;

    ll q;
    cin >> q;

    while(q--) {
        ll t;
        cin >> t;
        if(t == 1) {
            swap(a, b);
        } else {
            ll f;
            char c;
            cin >> f >> c;
            (f == 1 ? a : b) += c;
        }
    }

    reverse(a.begin(), a.end());
    cout << a << b << endl;
}


Measured memory_bytes: 980
#include <stdio.h>
int main(){
  char s[1001];
  char r,c;
  int i,v=0,j,h;
  while(1){
    scanf("%s",s);
    if(s[0]=='0') break;
    else{
      for(i=0;s[i]!='\0';i++){
	v=v+s[i]-'0';
      }
      printf("%d\n",v);
      v=0;
    }
  }
  return 0;
}

Measured memory_bytes: 964
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll inf = 1e18;
int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    ll n;
    cin >> n;
    ll arr[n];
    ll s = 0;
    ll pref = 0;
    for(ll &i : arr)
        cin >> i , s += i;
    int mod = 1e9 + 7;
    ll ans = 0;
    for(int i = 0 ; i < n ; i++){
        pref += arr[i];
        ans = ans + ((arr[i] % mod) * ((s - pref) % mod)) % mod;
        ans = ans % mod;
    }
    cout<<ans;
}


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

// 10^n - 9^n - 9^n + 8^n

const int mod = 1000000007;

struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
 

int main() {
    int n;
    cin >> n;
    if(n==1) {cout << 0 << endl; return 0;}
    mint ans = 1;
    rep(i,n){
        ans*=10;
    }
    mint x = 1;
    rep(i,n){
        x*=9;
    }
    x*=2;
    mint y = 1;
    rep(i,n){
        y*=8;
    }
    ans -=x;
    ans+=y;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3548
from sys import stdin
from collections import deque

n = int(stdin.readline())
l = list(map(int,stdin.readline().split()))
q = int(stdin.readline())

for i in range(q):
    inp_l = list(map(int,stdin.readline().split()))
    a = deque(l[inp_l[0]:inp_l[2]])
    a.rotate(inp_l[2] - inp_l[1])
    a = list(a)
    l = l[:inp_l[0]] + a + l[inp_l[2]:]
    
l = map(str,l)
print(' '.join(l))


Measured memory_bytes: 6048
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <queue>
#include <sstream>
#include <stack>
#include <time.h>
#include <vector>
#include <complex>
using namespace std;
string a[102];
string b[102];
int main(){
  int n;
  cin>>n;
  for (int i=0;i<n;i++)
    cin>>a[i];
  int m;
  cin>>m;
  for (int j=0;j<m;j++)
    cin>>b[j];
  int k=0,num=0;
  for (int q=0;q<n;q++){
    for (int q1=0;q1 < n;q1++)
      if (a[q1] == a[q]) 
        num++;
    for (int q2=0;q2 < m;q2++)
      if (b[q2] == a[q])
        num--;
      if (num > k)
        k = num;
    num=0;
    }
  cout<<k;
  system ("pause");
  return 0;
  }

Measured memory_bytes: 504
#include <bits/stdc++.h>
#define int long long
#define N 100010
#define rank Asdfiasofsad
using namespace std;
const int INF = 1LL<<55;
const int mod = (1e9)+7;
const double EPS = 1e-8;
const double PI = 6.0 * asin(0.5);
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}


class UF{
public:
  int V;
  vector<int> par,rank,num;
  UF(){}
  UF(int V):V(V),par(V),rank(V,0),num(V,1){for(int i=0;i<V;i++)par[i]=i;}
  
  int find(int x){
    assert(x < V);
    if(par[x]==x)return x;
    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, num[y] += num[x], num[x] = 0;
    else{
      par[y]=x, num[x] += num[y], num[y] = 0;
      if(rank[x]==rank[y]) rank[x]++;
    }
  }

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

int mod_pow(int x,int y){
  int res = 1;
  for(int i=0;i<y;i++) res = res * x % mod;
  return res;
}

signed main(){
  while(1){
    int n,m;
    cin>>n>>m;
    if(!n && !m) break;
    UF U(n);
    for(int i=0;i<m;i++){
      int a,b;
      cin>>a>>b; a--,b--;
      U.unite(a,b);
    }
  
    set<int> grp;
    for(int i=0;i<n;i++) grp.insert(U.find(i));
    int ans = (mod_pow(2,grp.size()) + ((int)grp.size() != n)) % mod;
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 9868
#include<bits/stdc++.h>
using namespace std;
const int m=1000000000+7;
int h,w,dp[1010][1010],x;
char mp[1010][1010];
int find(int x,int y){return(x+=y)>=m?x-m:x;}
int main ( )
{
	scanf("%d%d",&h,&w);
	for(int i=1;i<=h;i++)
	    scanf("%s",mp[i]+1);
	
	dp[1][1]=1;
	for(int i=1;i<=h;++i)
	   for(int j=1;j<=w;++j)
	   {
	   	  if(i==1&&j==1) continue;
	   	  if(mp[i][j]=='#') continue;
	   	  dp[i][j]=find(dp[i-1][j],dp[i][j-1]);
	   }
	printf("%d",dp[h][w]);
	return 0;
}

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

int main() {
  int n, temp;
  long long int a = 0, b = 0;
  vector<int> nums;
  cin >> n;
  for (int i=0; i<n; i++) {
    cin >> temp;
    nums.push_back(temp);
  }
  sort(nums.begin(), nums.end());
  for (int i=nums.size()-1; i>=0; i-=2) {
    a+=nums[i];
  }
  for (int i=nums.size()-2; i>=0; i-=2) {
    b+=nums[i];
  }
  cout << a-b;
  return 0;
}

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

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    vector<int> h(n);
    for (int i = 0; i < n; ++i) {
        cin >> h[i];
    }
    int ans = 1, highest = h[0];
    for (int i = 1; i < n; ++i) {
        if (h[i] >= highest) {
            highest = h[i];
            ++ans;
        }
    }
    cout << ans;
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <queue>
using namespace std;
#define N (100)
#define INFINITY (1<<21)

int n,M[N][N];
int d[N];

void bfs(int s){
    queue<int> q;
    q.push(s);
    for(int i=0;i<n;i++){
        d[i]=INFINITY;
    }
    d[s]=0;
    int u;
    while(!q.empty()){
        u=q.front();q.pop();
        for(int v=0;v<n;v++){
            if(M[u][v]==0)continue;
            if(d[v]!=INFINITY)continue;
            d[v]=d[u]+1;
            q.push(v);
        }
    }
    for(int i=0;i<n;i++){
        cout<<i+1<<" "<<((d[i]==INFINITY)?(-1):d[i])<<endl;
    }
}

int main(void){
    int u,k,v;
    cin>>n;
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            M[i][j]=0;
        }
    }
    for(int i=0;i<n;i++){
        cin>>u>>k;
        u--;
        for(int j=0;j<k;j++){
            cin>>v;
            v--;
            M[u][v]=1;
        }
    }
    bfs(0);
    return 0;
}



Measured memory_bytes: 3148
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	n := getInt()
	m := getInt()

	as := make([]string, n)
	for i := range as {
		as[i] = getString()
	}

	bs := make([]string, m)
	for i := range bs {
		bs[i] = getString()
	}

	ans := "No"
	for i := 0; i < n-m+1; i++ {
		for j := 0; j < n-m+1; j++ {
			if bs[0] == as[i][j:j+m] {
				flag := true
				for k := 1; k < m; k++ {
					if bs[k] != as[k][j:j+m] {
						flag = false
						break
					}
				}
				if flag == true {
					ans = "Yes"
				}
			}
		}
	}

	fmt.Println(ans)
}

// -----------------------------------------

var scanner = wordScanner()

func wordScanner() *bufio.Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	return sc
}

func getInt() int {
	scanner.Scan()
	i, err := strconv.Atoi(scanner.Text())
	if err != nil {
		panic(err)
	}
	return i
}

func getString() string {
	scanner.Scan()
	s := scanner.Text()
	return s
}


Measured memory_bytes: 640
#include <stdio.h>
#include <string.h>
#define BUFMAX 1000

char* w[2]={"apple","peach"};

int main(void){
	char buf[BUFMAX]; int i=0, j;
	
	while((buf[i]=getchar())!=EOF) i++;
	
	i=0;
	while(buf[i]!=EOF){
		/* w[0]->w[1] */
		for(j=0; j<strlen(w[0]); j++)
			if(buf[i+j]!=w[0][j]) break;
				
		if(j==strlen(w[0])){
			printf("%s",w[1]);
			i+=strlen(w[0]);
			continue;
		}
			
		/* w[1]->w[0] */
		for(j=0; j<strlen(w[1]); j++)
			if(buf[i+j]!=w[1][j]) break;
			
		if(j==strlen(w[1])){
			printf("%s",w[0]);
			i+=strlen(w[1]);
			continue;
		}
			
		/* otherwise */
		printf("%c",buf[i]);
		i++;
	}
	
	return 0;
}

Measured memory_bytes: 0
object Main extends App {
 val n = readInt
 val s = readLine
 var num = 1
 var i = 1
 var crrentChar = s.charAt(0)
 while(i < n) {
  if(crrentChar != s.charAt(i)) {
    crrentChar = s.charAt(i)
    num += 1
  }
  i += 1   
 }
    
 println(num)  
  
}

Measured memory_bytes: 27116
def resolve():
    a = list(input())
    b = list(input())
    c = list(input())
    d = {"a": a, "b": b, "c": c}
    now = "a"
    while d[now]:
        now = d[now].pop(0)
    print(now.upper())


if __name__ == "__main__":
    resolve()


Measured memory_bytes: 38384
#include <iostream>
#include<stdio.h>
#include<stdlib.h>
#include<vector>
#include<string.h>
#include<string>
#include<algorithm>
using namespace std;
int a,b;
long long c;
int main()
{
    char ch;
    scanf("%d %c %d",&a,&ch,&b);
    c=a+b;
    if(ch=='+')
        printf("%lld\n",c);
    else if(ch=='-')
        printf("%d\n",a-b);
    return 0;
}


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

using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
typedef pair<ll, ll> P;
inline ll min(ll x, ll y) { return x < y ? x : y; }
inline ll max(ll x, ll y) { return x > y ? x : y; }

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << (x) << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)

int main() {
	string S;
	cin >> S;
	if (S.length() >= 4) {
		if (S.substr(0, 4) == "YAKI") {
			cout << "Yes";
			return 0;
		}
	}
	cout << "No";
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main{
	public static void main(String[] args) {
		try(Scanner sc = new Scanner(System.in)){
			for(;;) {
				int m = sc.nextInt();
				int f = sc.nextInt();
				int r = sc.nextInt();
				if(m==-1&&f==-1&&r==-1) break;
				int sum = m+f;
				
				if(m==-1||f==-1) {
					System.out.println("F");
				}
				else if(80<=sum) {
					System.out.println("A");
				}
				else if(65<=sum) {
					System.out.println("B");
				}
				else if(50<=sum) {
					System.out.println("C");
				}
				else if(30<=sum) {
					if(50<=r) {
						System.out.println("C");
					}
					else {
						System.out.println("D");
					}
				}
				else {
					System.out.println("F");
				}
			}
		}
	}
}


Measured memory_bytes: 26432
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;

struct ant
{
    int pos;
    int dir;
    int num;
};

bool cmp(ant a,ant b)
{
    return a.pos<b.pos;
}

int main()
{
    int n,l;
    while (1)
    {
        scanf("%d%d",&n,&l);
        if (!n && !l) break;
        ant a[25];
        char str[2];
        int i,j;
        for (i=0;i<n;i++)
        {
            scanf("%s%d",str,&a[i].pos);
            a[i].num=i+1;
            if (str[0]=='R') a[i].dir=0;
            else a[i].dir=1;
        }
        sort(a,a+n,cmp);
        
        for (i=n-1;i>=0;i--)
        {
            if (a[i].dir==1) continue;
            for (j=i+1;j<n;j++)
            {
                if (a[j].dir==0) continue;
                int mod=(a[i].pos+a[j].pos)%2;
                if (!mod)
                {
                    int temp=a[i].num;
                    a[i].num=a[j].num;
                    a[j].num=temp;
                }
            }
        }
        int rightmax=0;
        int leftmax=0;
        int rightrec=0,leftrec=0;
        for (i=0;i<n;i++)
            if (a[i].dir==0)
            {
                rightmax=l-a[i].pos;
                rightrec=a[i].num;
                break;
            }
        for (i=n-1;i>=0;i--)
            if (a[i].dir==1)
            {
                leftmax=a[i].pos;
                leftrec=a[i].num;
                break;
            }
        if (rightmax>leftmax)
            printf("%d %d\n",rightmax,rightrec);
        else if (leftmax>rightmax)
            printf("%d %d\n",leftmax,leftrec);
        else
            printf("%d %d\n",leftmax,leftrec);
    }
}

Measured memory_bytes: 1208
N = int(input())
Ds = list(map(int,input().split()))
dif = {}
for D in Ds:
  if D in dif:
    dif[D] += 1
  else:
    dif[D] = 1
M = int(input())
Ts = list(map(int,input().split()))
for T in Ts:
  if T not in dif:
    print('NO')
    exit()
  else:
    if 0 < dif[T]:
      dif[T] -= 1
    else:
      print('NO')
      exit()
print('YES')

Measured memory_bytes: 46304
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef tuple<int,int,int> tii;
#define rep(i,s,n) for(int i=(int)(s);i<(int)(n);i++)

int main(){
  ll N; cin >> N;
  ll A[N],B[N];
  ll sum = 0;
  ll exc = 0;
  for(int i=0;i<N;i++){
    cin >> A[i];
    if(i%2==1) exc += A[i];
    sum += A[i];
  }
  B[0] = sum - 2*exc;
  cout << B[0] << " ";
  for(int i=1;i<N;i++){
    B[i] = (A[i-1] - B[i-1]/2)*2;
    cout << B[i] << " ";
  }
}


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

int main(){
  int A,B,C,D;
  cin>>A>>B>>C>>D;
  
  
  rep(i,101){
    if(C<=0){cout<<"Yes"<<endl; break;}
    if(A<=0){cout<<"No"<<endl; break;}
    C=C-B;
    A=A-D;
  }
}


Measured memory_bytes: 3636
import java.util.Iterator;
import java.util.PrimitiveIterator;
import java.util.Scanner;
import java.util.stream.IntStream;
import java.util.stream.Stream;

class Main{

	private void solve(){
		int n=gInt();
		int[] a=ints(n).toArray(),b=ints(n).toArray();
		long d=0;
		for(int i=0;i<n;++i) {
			if(a[i]<b[i])
				d+=(b[i]-a[i])/2;
			else
				d-=a[i]-b[i];
		}
		System.out.println(d>=0?"Yes":"No");
	}

	public static void main(String[] $){
		new Main().solve();
	}

	static Scanner s=new Scanner(System.in);


	static int gInt(){
		return s.nextInt();
	}
	static long gLong(){
		return s.nextLong();
	}
	static long gDouble(){
		return s.nextLong();
	}


	static Range rep(int i){
		return new Range(i);
	}
	static Range rep(int f,int t,int d){
		return new Range(f,t,d);
	}
	static Range rep(int f,int t){
		return rep(f,t,1);
	}
	static Range rrep(int f,int t){
		return rep(f,t,-1);
	}

	static class Range implements Iterable<Integer>,PrimitiveIterator.OfInt{

		int to,cur,d;

		Range(int from,int to,int d){
			this.cur=from-d;
			this.to=to;
			this.d=d;
		}

		Range(int n){
			this(0,n-1,1);
		}

		@Override
		public Iterator<Integer> iterator(){
			return this;
		}

		@Override
		public boolean hasNext(){
			return cur+d==to||(cur!=to&&(cur<to==cur+d<to));
		}

		@Override
		public int nextInt(){
			return cur+=d;
		}
	}


	static IntStream REPS(int v){
		return IntStream.range(0,v);
	}

	static IntStream REPS(int l,int r){
		return IntStream.rangeClosed(l,r);
	}


	static IntStream ints(int n){
		return REPS(n).map(i->gInt());
	}

	static Stream<String> strs(int n){
		return REPS(n).mapToObj(i->s.next());
	}

}

Measured memory_bytes: 42620