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

int main(){
	int n, m, i;
	while(true){
		cin>>n>>m; if(n==0 && m==0) break;
		queue<int> a;
		for(i=0;i<n;i++){
			a.push(i+1);
		}
		while(a.size() > 1){
			for(i=0;i<m-1;i++){
				a.push(a.front());
				a.pop();
			}
			a.pop();
		}
		cout<<a.front()<<endl;
	}
	return 0;
}

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

#define all(x) x.begin(),x.end()
#define pb(x) emplace_back(x)
#define forn(i,N) for(int i=0;i<N;i++)

using namespace std;
using ll=long long int;
using ld=long double;

//Uradi: https://codeforces.com/problemset/problem/1345/B
//I ovaj je zanimljiv: https://codeforces.com/contest/214/problem/B

int main() {
//freopen("input.txt","rt",stdin);
ios::sync_with_stdio(false);
cin.tie(nullptr);

int N,ans=0;
cin>>N;
vector<int> v,t(N),cnt(1e6+5);
for(int i=0;i<N;i++) {
  cin>>t[i];
  cnt[t[i]]++;
}
for(auto& x: t) {
  if(cnt[x]==1) {
    v.pb(x);
  }
}
N=v.size();
if(cnt[1]==1) {
  cout<<1<<endl;
  return 0;
}
if(cnt[1]>0) {
  cout<<0<<endl;
  return 0;
}
for(int i=0;i<N;i++) {
  bool ok=true;
  for(int j=2;j*j<=v[i];j++) {
    if(v[i]%j==0) {
      if(cnt[j]>0 or cnt[v[i]/j]>0) {
        ok=false;
        break;
      }
     }
   }
   if(ok)
    ans++;
}
cout<<ans<<endl;
return 0;
}


Measured memory_bytes: 8892
#include "bits/stdc++.h"
#define ALL(x) x.begin(), x.end()
#define LEN(x) (int)x.size()
#define iostreamBooster() do{ cin.tie(nullptr); ios_base::sync_with_stdio(false); }while(0)
using namespace std;
typedef int64_t i64;
typedef pair<int,int> pii;
template<class A, class B>inline bool chmax(A &a, const B &b){return b>a ? a=b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b<a ? a=b,1 : 0;}
constexpr int INF = 0x3f3f3f3f;

int N, M;
struct UnionFind {
  vector<int> uni;
  explicit UnionFind(int n): uni(n+5, -1) {}
  int  root(int x)        { return (uni[x] < 0)? x : uni[x] = root(uni[x]); }
  int  size(int i)        { return (-uni[root(i)]); }
  bool same(int x, int y) { return root(x) == root(y); }
  bool unite(int x, int y){
    if ( (x=root(x)) == (y=root(y)) )return false;
    if ( uni[y] < uni[x] ) swap(x,y);
    uni[x] += uni[y];  uni[y] = x;
    return true;
  }
};

signed main()
{
  cin >> N >> M;
  vector<pii> edges(M);
  for (int i= 0; i < M; ++i) {
    int s, t; cin >> s >> t; --s, --t;
    edges[i] = pii(s, t);
  }

  reverse(ALL(edges));
  i64 ans = ((i64)N * (N-1) / 2);
  UnionFind uf(N);
  vector<i64> buf;

  for (const auto &e : edges) {
    buf.push_back(ans);

    if (uf.same(e.first, e.second)) continue;
    i64 p = uf.size(e.first);
    i64 q = uf.size(e.second);
    // p = p * (p - 1) / 2;
    // q = q * (q - 1) / 2;

    uf.unite(e.first, e.second);
    ans -= (p) * (q);
    chmax(ans, 0);
  }

  for (int i = buf.size()-1; i >= 0; --i) {
    cout << buf[i] << endl;
  }

  return 0;
}




Measured memory_bytes: 3444
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
      int a = sc.nextInt();
      int b = sc.nextInt();
      int c = sc.nextInt();
      int k = sc.nextInt();
      int score;
      
   if (k <= a) {
     score = k;
   } else if ( k >a && k <= a+b) {
     score = a;
   } else {
     score = a-(k-a-b) ;
   }
      
   System.out.println(score);
  }
}
      

Measured memory_bytes: 35768
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

using ll = long long;
using ull = uint64_t;
using P = pair<int, int>;
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
// constexpr int mod = 1000000007;
constexpr int mod = 998244353;

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

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

    int n, k;
    cin >> n >> k;
    ll ans = 0;
    for(int b = k + 1; b <= n; ++b){
        ans += (ll)n / b * (b - k);
        ans += max(0, n % b - k + 1);
    }
    if(k == 0)  ans -= n;
    cout << ans << endl;
}

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

int main()
{
    int N, count = 0;
    cin >> N;
    if (N == 1)
    {
        cout << 0;
        exit(0);
    }
    
    vector<int> X(N, 0);
    for (int i = 0; i < N; i++)
    {
        cin >> X.at(i);
    }

    sort(X.begin(), X.end());

    if (X.at(N-1) == X.at(0))
    {
        cout << 0;
        exit(0);
    }
    

    vector<int> A(X.at(N-1)-X.at(0)-1, 0);

    for (int i = X.at(0)+1; i < X.at(N-1); i++)
    {
        for (int j = 0; j < N; j++)
        {
            A.at(count) += (X.at(j)-i)*(X.at(j)-i);
        }
        
        count++;
    }

    sort(A.begin(), A.end());

    cout << A.at(0);
    
    
}

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

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

int main(){
    long long a, b, g;
    while(cin >> a >> b){
        g=gcd(a, b); 
        cout << g << " " << a*b/g <<  endl;
    }
}
//g++ -o proa.exe proa.cpp

//VSCなら./test
//Atomならtest.exe



Measured memory_bytes: 3080
from math import factorial
from itertools import permutations

n = int(input())
d = [list(map(int, input().split())) for _ in range(n)]

def dist(a, b):
    return ((d[a][0]- d[b][0])**2 + (d[a][1]- d[b][1])**2 )**(1/2)
ls = list(range(n))
total = 0
for perm in permutations(ls):
    for i in range(n-1):
        total += dist(perm[i], perm[i+1])

ans = total/factorial(n)
print(ans)


            

Measured memory_bytes: 40812
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <vector>

using namespace std;

int main() {
  int n, m;

  cin >> n >> m;

  vector<int> cond(n, -1);

  bool fin = false;

  for (int i = 0; i < m; i++) {
    int s, c;

    cin >> s >> c;

    // 一桁目が0であるをはじく
    if (s == 1 && c == 0 && n != 1) {
      fin = true;
    }

    // 既に異なる条件が入っていた
    if (cond.at(s - 1) != -1 && cond.at(s - 1) != c) {
      fin = true;
    }

    cond.at(s - 1) = c;
  }

  if (fin) {
    cout << -1 << endl;
    return 0;
  }

  if (n == 1 && m == 0) {
    cout << 0 << endl;
    return 0;
  }

  int res = 0;

  for (int i = 0; i < n; i++) {
    if (cond.at(i) != -1) {
      res += cond.at(i) * pow10(n - i - 1);
    }
  }
  if (cond.at(0) == -1) {
    res += pow10(n - 1);
  }

  cout << res << endl;

  return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define pb push_back
const ll mod = 1e9+7;
const int N = 2020;
ll dp[N][N];
ll pos[N];
ll val[N];
void solve(){
    int n;
    cin>>n;
    vector<pair<int,int> >  v;
    for(int i=1;i<=n;i++){
        int x;
        cin>>x;
        v.pb({x,i});
    }
    sort(v.begin(),v.end());
    reverse(v.begin(),v.end());
    for(int i=1;i<=n;i++){
        pos[i] = v[i-1].second;
        val[i] = v[i-1].first;
    }
    for(int l=0;l<=n;l++){
        for(int r=0;r<=n;r++){
            int x = l+r+1;
            if(x>n)break;
            dp[l][r+1] = max(dp[l][r+1],dp[l][r]+val[x]*abs(pos[x]-(n-r)));
            dp[l+1][r] = max(dp[l+1][r],dp[l][r]+val[x]*abs(pos[x]-(l+1)));
        }
    }
    ll ans = 0;
    for(int i=0;i<=n;i++){
        ans = max(ans,dp[i][n-i]);
    }
    cout<<ans<<endl;
}
int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t=1;
    while(t--){
        solve();
    }
    return 0;
}


Measured memory_bytes: 26384
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        try (Scanner sc = new Scanner(System.in)) {
            int N = sc.nextInt();
            int K = sc.nextInt();

            int digit = 0;
            for (; N > 0;) {
                N = N / K;
                digit++;
            }

            System.out.println(digit);
        }
    }
}

Measured memory_bytes: 27056
def dfs1(v, pv):
    for nv, _ in adj_list[v]:
        if nv==pv:
            continue
        
        is_leaf[v] = False
        dfs1(nv, v)
    
    return is_leaf
    
def dfs2(v, pv, d):
    dist[v] = d
    
    for nv, w in adj_list[v]:
        if nv==pv:
            continue
        
        dfs2(nv, v, d+w)
    
    return dist

while True:
    N = int(input())
    
    if N==0:
        break
    
    a, b, t = [], [], []
    adj_list = [[] for _ in range(N)]
    
    for _ in range(N-1):
        ai, bi, ti = map(int, input().split())
        a.append(ai-1)
        b.append(bi-1)
        t.append(ti)
        adj_list[ai-1].append((bi-1, ti))
        adj_list[bi-1].append((ai-1, ti))
        
    is_leaf = [True]*N
    dist = [-1]*N
    
    dfs1(0, -1)
    dfs2(0, -1, 0)
    
    tmp = 0
    
    for ai, bi, ti in zip(a, b, t):
        if (not is_leaf[ai]) and (not is_leaf[bi]):
            tmp += 2*ti
        
    ans = tmp
    
    for i in range(N):
        if not is_leaf[i]:
            ans = min(ans, tmp-dist[i])
    
    print(ans)


Measured memory_bytes: 5616
import java.util.Scanner;

public class Main{
    
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        
        while(true){
            int H = sc.nextInt();
            int W = sc.nextInt();
            if(H == 0 && W == 0) break;
            else{
                for(int i = 0 ; i < H ; i++){
                    for(int j = 0 ; j < W ; j++){
                        System.out.print("#");
                    }
                    System.out.println();
                }
                System.out.println();
            }
        }
    }
}


Measured memory_bytes: 32536
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep2(i, a, n) for(ll i = a; i < (ll)(n); i++)
#define memi cout << endl
#define kono(n) cout << fixed << setprecision(n)
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define hina cout << ' '
#define in(n) cin >> n
#define in2(n, m) cin >> n >> m
#define in3(n, m, l) cin >> n >> m >> l
#define out(n) cout << n
const ll mei = (ll)1e9 + 7;

int main(){
  ll n, a, b, k;
  in2(n, k);
  vector<ll> c(n);
  rep(i, n)
    in(c[i]);
  bool h = false;
  rep(i, n - 1){
    if(c[i] + c[i + 1] >= k){
      a = i;
      h = true;
    }
  }
  if(!h){
    out("Impossible");
    memi;
    return 0;
  }
  out("Possible");
  memi;
  rep(i, a){
    out(i + 1);
    memi;
  }
  b = n - 2;
  while(b >= a){
    out(b + 1);
    memi;
    b--;
  }
}

Measured memory_bytes: 1664
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory.h>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <sstream>
#include <utility>
#include <vector>
using namespace std;

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

#define ALL(x) x.begin(),x.end()

#define DEB(args...) fprintf(stderr,args)

#define PB push_back
#define MP make_pair
#define ST first
#define ND second 

const int INF = 0x3f3f3f3f;

int main(){
	string a;
	cin >> a;
	int mx = INF;
	int n = a.size();
	//printf("%d\n", n);
	for(int i = 0; i < 26; i++){
		string aux = a;
		string nxt = aux;
		sort(nxt.begin(),nxt.end());
		nxt.resize(distance(nxt.begin(),unique(nxt.begin(),nxt.end())));
		if(nxt.size()==1){
			mx=min(mx,0);
		}
		for(int j = n-1; j > 0; j--){
			nxt = "";
			for(int k = 0; k < j; k++){
				if(aux[k]==('a'+i)||aux[k+1]==('a'+i)){
					nxt+='a'+i;
				}
				else{
					nxt+=aux[k];
				}
			}
			aux = nxt;
			sort(nxt.begin(),nxt.end());
			nxt.resize(distance(nxt.begin(),unique(nxt.begin(),nxt.end())));
			if(nxt.size()==1){
				mx=min(mx,n-j);
			}
		}
	}
	cout << mx << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
typedef long long ll;

int main() {
  int n, m, X, Y, x, y;
  scanf("%d%d%d%d", &n, &m, &X, &Y);
  int maxx = X, miny = Y;
  for (int i = 0; i < n; i++) scanf("%d", &x), maxx = max(x, maxx);
  for (int i = 0; i < m; i++) scanf("%d", &y), miny = min(y, miny);
  if (maxx < miny) printf("No War\n");
  else printf("War\n");
}


Measured memory_bytes: 128
n, k = map(int, input().split())
p = list(map(int, input().split()))

e = [(i+1)/2 for i in p]

sume = [0 for _ in range(n)]
for i in range(n):
    if i == 0:
        sume[i] = e[i]
    else:
        sume[i] = sume[i-1]+e[i]

ans = []

if n == k:
    ans.append(sume[-1])
else:
    for i in range(n-k):
        ans.append(sume[i+k]-sume[i])

print("%.12f"%max(ans))
    

Measured memory_bytes: 28228
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repp(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define rrep(i, n, m) for (int i = n; i >= m; i--)
#define p(s) cout << s << endl;
typedef long long LL;
template <class T>
bool contain(const std::string &s, const T &v)
{
    return s.find(v) != std::string::npos;
}

int main()
{
    int a,b,h; cin>>a>>b>>h;
    cout<<(a+b)*h/2<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+1;
int n,c,k,t[N],l=1,A=1;
int main()
{
	cin>>n>>c>>k;
	for(int i=1;i<=n;i++)
		cin>>t[i];
	sort(t+1,t+n+1);
	for(int i=1;i<=n;i++)
		if(i-l+1>c||t[l]+k<t[i])
			l=i,A++;
	cout<<A;
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#include <numeric>
#include <random>
#include <unordered_map>
#include <unordered_set>
#define all(a) a.begin(),a.end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define pb push_back
#define debug(x) cerr << __LINE__ << ' ' << #x << ':' << x << '\n'
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;
typedef complex<ld> com;
constexpr int inf = 1000000010;
constexpr ll INF = 1000000000000000010;
constexpr ld eps = 1e-12;
constexpr ld pi = 3.141592653589793238;
template<class T, class U> inline bool chmax(T &a, const U &b) { if (a < b) { a = b; return true; } return false; }
template<class T, class U> inline bool chmin(T &a, const U &b) { if (a > b) { a = b; return true; } return false; }


int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(20);

	int h, w;
	cin >> h >> w;
	vector<int> a(h), b(h);
	rep(i, h) {
		cin >> a[i] >> b[i];
		a[i]--; b[i]--;
	}
	multiset<P> st;
	rep(i, w) st.insert({ i,0 });
	st.insert({ inf,-inf });
	multiset<int> mst;
	rep(i, w) mst.insert(0);
	rep(i, h) {
		vector<P> vec;
		auto itr = st.lower_bound({ a[i],-inf });
		while ((*itr).first <= b[i]) {
			vec.pb(*itr);
			itr++;
		}
		if (vec.size()) {
			int idx = -1;
			for (P p : vec) {
				st.erase(st.find(p));
				mst.erase(mst.find(-p.second));
			}
			if (b[i] + 1 < w) {
				P p = vec.back();
				int dis = b[i] + 1 - p.first;
				p.first += dis;
				p.second -= dis;
				st.insert(p);
				mst.insert(-p.second);
			}
		}
		if (mst.empty()) {
			cout << "-1\n";
		}
		else {
			int s = *mst.begin();
			cout << s + i + 1 << '\n';
		}
	}
}


Measured memory_bytes: 26672
#include<stdio.h>

int get_count (char str[], int n)
{
	int c = 0;
//	int min = n / 2;
	int i;
	for (i = 0; i < n; i++)
	{
		if (str[i] == str[i + (n / 2)])
		{
			c++;
		}
	}
	
	return c;
}

int main()
{
	int n;
	scanf("%d", &n); // 0
	
	char str[n]; // str[0]
	scanf("%s", str);
	
	int mid = n / 2; // mid = 0
	int count = get_count(str, n);
	
	if (count == mid && n > 0 && n % 2 == 0)
	{
		puts("Yes");
	}
	else if (count != mid)
	{
		puts("No");
	}
	else if (n % 2 != 0)
	{
		puts("No");
	}
	else if (count <= 0)
	{
		puts("No");
	}
	
	return 0;
}

Measured memory_bytes: 1620
// Why I am so dumb? :c
#include <bits/stdc++.h>

#define pb push_back
#define mp make_pair

#define all(x) (x).begin(), (x).end()

#define fi first
#define se second

using namespace std;

typedef long long ll;

char s[105][105];

bool u[105][105];

int n, m;

void solve() {                   
	scanf("%d %d", &n, &m);
	
	for (int i = 1; i <= n; ++i) {
		scanf("%s", s[i] + 1);
	}

	int x = 1, y = 1;

	while (x != n || y != m) {
		u[x][y] = 1;

		if (x == n) {
			++y;
			continue;
		}

		if (y == m) {
			++x;
			continue;
		}

		if (s[x + 1][y] == '#') {
			++x;
		}
		else {
			++y;
		}
	}

	u[n][m] = 1;

	for (int i = 1; i <= n; ++i) {
		for (int j = 1; j <= m; ++j) {
			if (s[i][j] == '#' && u[i][j] == 0) {
				printf("Impossible\n");
				return;
			}

			if (s[i][j] == '.' && u[i][j] == 1) {
				printf("Impossible\n");
				return;
			}
		}
	}
    
    printf("Possible\n");
}

int main() {    
    int tt = 1;

    while (tt--) {
        solve();
    }

    return 0;
}

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

using namespace std;

int main(){
    int S;
    int hour;
    int minute;
    int second;

    cin >> S;
    
    hour = (S - (S % 3600)) / 3600;
    minute = (S - hour * 3600 - ((S - hour * 3600) % 60)) / 60;
    second = S - hour * 3600 - minute * 60;
    
    cout << hour << ":" << minute << ":" << second << endl;
    
    return 0;
}


Measured memory_bytes: 3088
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main()
{
	int a, b, c;
	
	scanf("%d %d %d", &a, &b, &c);
	
	if(b / a >= c)
		printf("%d", c);
	else
		printf("%d", b / a);
	

	return 0;
}

Measured memory_bytes: 128
#include "bits/stdc++.h"
#include <set>

using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(i) (i).begin(), (i).end()
#define rall(i) (i).begin(), (i).end(), greater<int>()
#define int long long
#define elif else if
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fst first
#define sec second
#define mod 1000000007
#define INF 10e10
template <typename T>

void print(T x)
{
	std::cout << x << " ";
}
template <typename T>

void println(T x)
{
	std::cout << x << "\n";
}

struct UnionFind {
	vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

	UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
		for (int i = 0; i < N; i++) par[i] = i;
	}

	int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
		if (par[x] == x) return x;
		return par[x] = root(par[x]);
	}

	void unite(int x, int y) { // xとyの木を併合
		int rx = root(x); //xの根をrx
		int ry = root(y); //yの根をry
		if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
		par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
	}

	bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
		int rx = root(x);
		int ry = root(y);
		return rx == ry;
	}
};


signed main(void) {
	int N, M;
	cin >> N >>M;
	UnionFind u(N);
	vector<int>p(N);
	rep(i, N) {
		int inp;
		cin >> inp;
		p[i] = inp - 1;
	}
	int x, y;
	rep(i, M) {
		cin >> x >> y;
		x--;
		y--;
		u.unite(x, y);
	}
	int ans = 0;
	rep(i, N) {
		if (u.same(i,p[i]))ans++;
	}
	print(ans);
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0;i < (int)n;i++)
#define repb(i, n) for(int i = (int)n;i >= 0;i--)
#define reps(i, m, n) for(int i = (int)m;i < (int)n;i++)
#define repsb(i, m, n) for(int i = (int)m;i >= (int)n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define pb(a) push_back(a)
#define INF 999999999999999999
using namespace std;
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};
using namespace std;
int main(int argc, char const *argv[]) {
  int n;
  int ans[100],cnt=0;
    cin>>n;
    rep(i,n){
      cin>>ans[i];
      if(i!=0&&ans[i-1]==ans[i]) {
        cnt++;
        ans[i]=10000+i;
      }
    }
    cout<<cnt<<endl;

    return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.buffer.readline
N, C = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = [0] * (N * (C + 1))
mod = 10 ** 9 + 7
for i in range(N):
  c[i * (C + 1)] = b[i] - a[i] + 1
for i in range(N):
  for k in range(a[i], b[i] + 1):
    t = 1
    for j in range(C):
      t *= k
      t %= mod 
      c[i * (C + 1) + j + 1] += t
      c[i * (C + 1) + j + 1] %= mod
dpx = [0] * (C + 1)
dpy = [0] * (C + 1)
dpx[0] = 1
for i in range(N):
  if i % 2:
    dpx = [0] * (C + 1)
  else:
    dpy = [0] * (C + 1)
  for j in range(C + 1):
    for k in range(j, C + 1):
      if i % 2:
        dpx[k] += dpy[j] * c[i * (C + 1) + k - j]
        dpx[k] %= mod
      else:
        dpy[k] += dpx[j] * c[i * (C + 1) + k - j]
        dpy[k] %= mod
if N % 2:
  print(dpy[-1] % mod)
else:
  print(dpx[-1] % mod)

Measured memory_bytes: 44200
#include <bits/stdc++.h>
#define ll long long
#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))

using namespace std;

int gcd(int x, int y) { return (x % y)? gcd(y, x % y): y; }

int main(){
    int n; cin >> n;
    vector<int> el;
    vector<int> p(n), q(n);
    int a=0, b=0;
    bool a_flg = false, b_flg = false;

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

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

    for (int i = 1; i <= n; ++i) {
        el.push_back(i);
    }

    do {
        if (el==p) a_flg = true;
        if (el==q) b_flg = true;
        if (!a_flg) a++;
        if (!b_flg) b++;
        if (a_flg&&b_flg) break;
    }
    while (next_permutation(el.begin(), el.end()));

    cout << abs(a-b) << endl;

    return 0;

}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
int A,B;
cin>>A>>B;
A=(A+11)%13;
B=(B+11)%13;
if (A>=B)
{
if (A>B)cout<<"Alice";
else
cout<<"Draw";
}
else
cout<<"Bob";
system ("pause");
return 0;
}

Measured memory_bytes: 504
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<map>
#include<queue>
#include<string>
#include<numeric>
#include<sstream>
#include<cmath>
using namespace std;
long long int mod = 1e9+7;

int main(){
  long long int n, a, b, c, d, e;
  cin >> n >> a >> b >> c >> d >> e;
  long long int mn = min({a, b, c, d, e});
  long long int ans = 5;
  ans += n / mn;
  if(n%mn == 0) ans -= 1;
  cout << ans << endl;

  return 0;
}


// EOF


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

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

    int count = 0;
    for(int i = 0; i < N; i++)
    {
	int j = i + 1;
	if(S[i] == S[j])
	    continue;
	count++;
    }
    cout << count << endl;

    return 0;
}


Measured memory_bytes: 512
#include<iostream>
#include <iomanip>
#include<vector>
#include<algorithm>
#include<string>
#include <cmath>
#include <limits>
#include <utility>
#include <map>


#define rep(p,q) for(int i = p;i < q;i++)
#define ll long long

using namespace std;

const int cons = 1e9 + 7;

int n;
vector<double> v;
vector<double> l;
vector<double> r;
double speed(double t) {
	double maxV = 100;
	rep(0, n + 2) {
		double reti = 0;
		if (t <= l[i]) reti = v[i] + l[i] - t;
		else if (r[i] <= t) reti = v[i] + t - r[i];
		else reti = v[i];
		maxV = min(maxV, reti);
	}
	return maxV;
}

//D

int main(void) {
	
	cin >> n;	
	v = vector<double>(n + 2);
	l = vector<double>(n + 2);
	r = vector<double>(n + 2);
	v[0] = 0; l[0] = 0; r[0] = 0;
	v[n + 1] = 0;
	int T= 0;
	rep(1, n+1) {
		int ti = 0;
		cin >> ti;
		r[i] = r[i - 1] + ti;
		l[i] = r[i - 1];
		T += ti;
	}
	l[n] = r[n - 1];
	rep(1, n + 1) {
		cin >> v[i];
	}
	l[n + 1] = T; r[n + 1] = T;
	double ans = 0;
	for (double i = 0; i < T; i += 0.5) {
		double s1 = speed(i);
		double s2 = speed(i + 0.5);
		ans += 0.25*(s1 + s2);
	}
	cout << setprecision(20) << ans << endl;
}


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

struct UnionFind {
  // 子は親のID,親は-サイズ
  vector<int> d;
  UnionFind(int n = 0) : d(n, -1) {}
  int find(int x) {
    if (d[x] < 0) return x;
    return find(d[x]);
  }
  bool unite(int x, int y) {
    x = find(x), y = find(y);
    if (x == y) return false;
    if (d[x] > d[y]) swap(x, y);
    d[x] += d[y];
    d[y] = x;
    return true;
  }
  bool same(int x, int y) { return find(x) == find(y); }
  int size(int x) { return -d[find(x)]; }
};

int friendsNum[100005];
vector<int> block[100005];

int main() {
  int n, m, k;
  cin >> n >> m >> k;
  UnionFind uf(n);
  rep(i, m) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    friendsNum[a]++, friendsNum[b]++;
    uf.unite(a, b);
  }
  rep(i, k) {
    int c, d;
    cin >> c >> d;
    c--, d--;
    block[c].push_back(d), block[d].push_back(c);
  }

  rep(i, n) {
    ll ans = 0;
    ans += uf.size(i) - 1 - friendsNum[i];
    for (int b : block[i])
      if (uf.same(b, i)) ans--;
    cout << ans << " ";
  }
  cout << endl;

  return 0;
}


Measured memory_bytes: 6784
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;

int main(){
  int n,slen;
  string s,d[38]={
    "a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t",
    "u","v","w","x","y","z","ld","mb","mp","nc","nd","ng","nt","nw","ps","qu","cw","ts"
  };
  map<P,int> m;
  vector<int> v;
  cin>>n;
  for(int i=0;i<38;i++)
    for(int j=0;j<38;j++)
      m.insert(make_pair(P(i,j),0));
  while(cin>>s){
    slen=s.size();
    s+="#####";    
    for(int i=0;i<slen;i++){
      string subs=s.substr(i,2);
      int f=0,ind;
      for(int j=0;j<38;j++){
	if(j<26&&s[i]==d[j][0])ind=j;
	if(subs==d[j]){
	  f=1;
	  i++;
	  v.push_back(j);
	}
      }
      if(!f)v.push_back(ind);
    }
    for(int i=0;i<v.size()-1;i++)
      m[P(v[i],v[i+1])]++;
    v.clear();
  }
  map<P,int>::iterator ite;
  int ans1=0,ans2=0,ansmax=m[P(0,0)];
  for(ite=m.begin();ite!=m.end();ite++){
    if(ans1!=(*ite).first.first){
      cout<<d[ans1]<<' '<<d[ans2]<<' '<<ansmax<<endl;
      ans1++;
      if(ansmax<(*ite).second){
	ans2=(*ite).first.second;
	ansmax=(*ite).second;
      }
      ans2=0,ansmax=m[P(ans1,0)];
    }else{
      if(ansmax<(*ite).second){
	ans2=(*ite).first.second;
	ansmax=(*ite).second;
      }
    }
  }
  cout<<d[ans1]<<' '<<d[ans2]<<' '<<ansmax<<endl;
 
  m.clear();
  return 0;
}

Measured memory_bytes: 1340
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>; // グラフ型
typedef long long ll;
#define _GLIBCXX_DEBUG

/*
 // 深さ優先探索
vector<bool> seen;
int dfs(const Graph &G, ll v) {
    seen[v] = true; // v を訪問済にする
    int score = 0; 

    // v から行ける各頂点 next_v について
    for (auto next_v : G[v]) { 
        if (seen[next_v]) continue; // next_v が探索済だったらスルー

        // 負荷さ優先探索中の処理



        dfs(G, next_v); // 再帰的に探索, 毎回mat渡してええの？
    }
    return score;
} */

/*
//桁数の計算
ll keta(ll num){
  ll ans= 0 ;
  ll rem;

  for (ll i = 4; i >= 0 ; i--){
    rem = pow(10,i);
    ans += (num / rem); 
    num = num % rem;
  }
  return ans;
}
*/


int main() {
  string S;
  ll N, M;
  cin >> N >> M;
  //vector<ll> a(N);
  //vector<vector<int>> data(3, vector<int>(4));
  
  cout << N * M << endl;

  return 0;
}


Measured memory_bytes: 3636
from collections import defaultdict

S=input()
cnt=defaultdict(int)
for i in range(len(S)):
  cnt[S[i]]+=1
ans=0
for a,b in cnt.items():
  if b%2==1:
    ans+=1
if S[0]==S[-1]:
  if ans%2==0:
    print("First")
  else:
    print("Second")
else:
  if ans%2==0:
    print("Second")
  else:
    print("First")


Measured memory_bytes: 3572
def char_to_index(char)
  char.ord - "a".ord
end

def beautiful?(string)
  count = Array.new(char_to_index("z") + 1){ 0 }
  string.each_char{ |char| count[char_to_index(char)] += 1 }
  count.each do |n|
    return false unless n % 2 == 0
  end
  return true
end

puts beautiful?(gets.strip) ? "Yes" : "No"


Measured memory_bytes: 1788
/* KYA CODEFORCES MERE BAS KI BAT NHI HAI  */
 
 #include<iostream>
 #include<cstring>
 #include<string>
 #include<vector>
 #include<utility>
 #include<stdlib.h>
 #include<limits.h>
 #include<cmath>
 #include<set>
 #include<initializer_list>
 #include<unordered_set>
 #include<unordered_map>
 #include<map>
 #include<iomanip>
 #include<algorithm>
 #include<queue>
 #include<stack>
#include <cstdint>
  
 #define sze 1000005
 #define ld long double
 //#define ll unsigned long long
 #define ll long long
 #define endl "\n"
 #define pb push_back
 #define mkp make_pair
 #define mod 1000000007
 #define ff first
 #define ss second
 #define F(i,a,b) for(int i = (int)(a); i <= (int)(b); i++)
 #define RF(i,a,b) for(int i = (int)(a); i >= (int)(b); i--)
 #define all(c) (c).begin(),(c).end()
 #define pi                   pair<int,int>
 #define pll                  pair<ll,ll>
 #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  
 using namespace std;
 
//cout << fixed << setprecision(0) << pi <<" "<<npi<<endl;
 //const ll inf=1ll<<60;
 //const double pi = 3.14159265358979323846;


 int main()
 {
     string str; cin>>str;
     ll n = str.length();
     cout<<str;
     if(str[n-1]=='s')
     {
         cout<<"es"<<endl;
     }
     else
     {
         cout<<"s"<<endl;
     }
     
 }


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

using namespace std;

int A, B, C, D;

int main(int argc, char* argv[]) {
  cin >> A >> B >> C >> D;
  int L = A + B;
  int R = C + D;

  if (L > R)
    cout << "Left" << endl;
  else if (L == R)
    cout << "Balanced" << endl;
  else
    cout << "Right" << endl;

  return 0;
}

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

int main() {
	int n;
	long long a, min = 1000000, max = -1000000, sum = 0;
	cin >> n;
	for (long long i = 1; i <= n; i++) {
		cin >> a;
		if (min > a)min = a;
		if (max < a)max = a;
		sum += a;
	}
	cout << min << ' ' << max << ' ' << sum << endl;
	
	return 0;
}

Measured memory_bytes: 1164
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ul;
typedef signed long long ll;
ul over = 1000000007;

typedef tuple< int, int > node;

int dfs(int idx, vector< vector< int > > & child, vector< int >  & x)
{
  if (child[idx].size()==0) return 0;
  vector< node > c_node;
  int x_sum = 0;
  for (auto c : child[idx]) {
    int c_ans = dfs(c, child, x);
    if (c_ans == -1) return -1;
    c_node.push_back(make_tuple(c_ans, x[c]));
    x_sum += c_ans + x[c];
  }
  int dp[c_node.size()][x[idx]+1];
  for (int j = 0; j < c_node.size(); ++j) {
    for (int i = 0; i <= x[idx]; ++i) {
      dp[j][i] = 0;
    }
  }
  if (get<0>(c_node[0]) <= x[idx]) {
    dp[0][get<0>(c_node[0])] = 1;
  }
  if (get<1>(c_node[0]) <= x[idx]) {
    dp[0][get<1>(c_node[0])] = 1;
  }
  for (int i = 1; i < c_node.size(); ++i) {
    int c0 = get<0>(c_node[i]);
    int c1 = get<1>(c_node[i]);
    for (int xi = 0; xi <= x[idx]; ++xi) {
      if (dp[i-1][xi] == 0) continue;
      int xi0 = xi + c0;
      int xi1 = xi + c1;
      if (xi0 <= x[idx]) dp[i][xi0] = 1;
      if (xi1 <= x[idx]) dp[i][xi1] = 1;
    }
  }
  for (int i = x[idx]; i >= 0; --i) {
    if (dp[c_node.size()-1][i] != 0) {
      return x_sum - i;
    }
  }
  return -1;
}

int main(void)
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed;
  int n;
  cin >> n;
  if (n<=2) {cout << "POSSIBLE" << endl; return 0;}
  vector< vector< int > > child(n);
  for (int i = 1; i < n; ++i) {
    int p;
    cin >> p;
    p--;
    child[p].push_back(i);
  }
  vector< int > x(n);
  for (int i = 0; i < n; ++i) cin >> x[i];
  int ans = dfs(0, child, x);
  cerr << ans << endl;
  cout << (ans != -1 ? "POSSIBLE" : "IMPOSSIBLE") << endl;
  return 0;
}


Measured memory_bytes: 1280
#include<iostream>
using namespace std;
int main()
{
	int flag,n,i,j;
	while(cin>>n){
		flag=0;
		for(i=0;i<=n/4;i++){
			for(j=0;j<=n/7;j++)
				if(4*i+7*j==n)
				{
					flag=1;
					break;
				}
			if(flag) break;
		}
		if(flag)
		cout<<"Yes\n";
		else cout<<"No\n";
	}
	return 0;
}


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

namespace agc010_a
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int a = 0;
            for (int i = 0; i < n; i++)
            {
                if (x[i] % 2 == 1)
                {
                    a++;
                }
            }
            Console.WriteLine(a % 2 == 0 ? "YES" : "NO");
        }
    }
}

Measured memory_bytes: 13528
#include <cstdio>
#include <cstdlib>
#include <algorithm>

int n;
int h[100000];
int dp[100001];

int main(){
  scanf("%d", &n);
  for(int i = 0; i < n; i++)
    scanf("%d", h+i);

  dp[1] = std::abs(h[1] - h[0]);
  for(int i = 2; i < n; i++){
    dp[i] = std::min(dp[i-1] + std::abs(h[i] - h[i-1]), dp[i-2] + std::abs(h[i] - h[i-2]));
  }

  printf("%d\n", dp[n-1]);

  return 0;
}


Measured memory_bytes: 896
import random
random.seed(42)

D = int(input())
C = [int(i) for i in input().split()]
S = [[int(i) for i in input().split()] for j in range(D)]

def score_calc(T):
    total = 0
    last = [0] * 26
    for i in range(1, D+1):
        t = T[i-1]
        total += S[i-1][t-1]
        last[t-1] = i
        for j in range(26):
            total -= C[j] * (i - last[j])
    return total
    
N = 1000
T_ls = [[random.randint(1, 26) for i in range(D)] for j in range(N)]
best_score = 0
ans = [1] * D
for i in range(N):
    if score_calc(T_ls[i]) > best_score:
        best_score = score_calc(T_ls[i])
        ans = T_ls[i]

for i in range(D):
    print(ans[i])

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

int main() {
  
  int N;
  cin>>N;
  
  string stone;
  cin >> stone;
  
  int ans;
  int A=0;
  int B=0; int C;
  
  
  for (int k = 0; k <N; k++) {
     if(stone.at(k)=='.'){
       A++;
       }
  } //まず白を数える
  
    ans=min(A,N-A);
    C=A;
        
    for (int j = 0; j < N; j++){
        if(stone.at(j)=='#'){
        B++; 
        } 
        if(stone.at(j)=='.'){
        C--;
        }
    if(B+C<ans){
    ans=B+C;
    }
  }
 cout<<ans<<endl;
}


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

int main() {
    int n, m;
    cin>>n>>m;
    vector<int>a(m);
    rep(i,m) cin>>a[i];
    rep(i,m) n -= a[i];
    cout<<max(-1, n)<<endl;
}

Measured memory_bytes: 3588
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i=0;i<n;i++)
int luja(int n,int prime){
    int count=0;
    while(n>0){
        n/=prime;
        count+=n;
    }
    return count;
}
int main(void){
    vector<int>P;vector<int>v(101,1);
    v.at(0)=0;v.at(1)=0;
    for(int i=2;i*i<=100;i++){
        if(v.at(i)==1)
        {for(int j=2;i*j<=100;j++)v.at(i*j)=0;}
    }
    rep(i,101){
        if(v.at(i)==1)P.push_back(i);
    }
    int n;cin>>n;int c2,c4,c14,c24,c74;c2=0;c4=0;c14=0;c24=0;c74=0;
    rep(i,P.size()){
        int c=luja(n,P.at(i));
        if(2<=c&&c<4)c2++;
        if(4<=c&&c<14)c4++;
        if(14<=c&&c<24)c14++;
        if(24<=c&&c<74)c24++;
        if(74<=c)c74++;
    }
    cout<<c74+(c24+c74)*(c2+c4+c14+c24+c74-1)+(c14+c24+c74)*(c4+c14+c24+c74-1)+(c4+c14+c24+c74)*(c4+c14+c24+c74-1)*(c2+c4+c14+c24+c74-2)/2;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define REP(i,b) FOR(i,0,b)
#define RFOR(i,a,b) for (int i = a-1; i >= b; i--)
#define RREP(i,a) RFOR(i,a,0)
#define REPALL(i,x) for (int i = 0; i < x.size(); i++)
#define RREPALL(i,x) for (int i = x.size()-1; i >= 0; i--)
#define ALL(x) x.begin(), x.end()
#define SORT(x) sort(ALL(x))
#define MIN_ELEMENT(x) min_element(ALL(x))
#define MAX_ELEMENT(x) max_element(ALL(x))
#define COUNT(x,num) count(ALL(x), num)
#define MEMSET(x,val) memset(x, val, sizeof(x))
#define MAX(a,b) a = max(a,b)
#define MIN(a,b) a = min(a,b)
void YES(bool flag) {cout<<(flag ? "YES" : "NO")<<endl;}
void Yes(bool flag) {cout<<(flag ? "Yes" : "No")<<endl;}
void yes(bool flag) {cout<<(flag ? "yes" : "no")<<endl;}
#define fst first
#define scd second
#define nextline putchar('\n')
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> VI;
typedef vector<vector<int>> VVI;
typedef vector<ll> VLL;
typedef vector<vector<ll>> VVLL;
const int INF = 1e7;
const ll MOD = 1e9 + 7;

int p, ep;

int main()
{
    while (cin>>p, p) {
        REP(i,9) {
            cin>>ep;
            p -= ep;
        }
        cout<<p<<endl;
    }
    return 0;
}



Measured memory_bytes: 3056
#include <cstdio>
#include <vector>

using namespace std;

int main() {
    int n, k;
    scanf("%d%d", &n, &k);
    vector<int> h(n);
    for (int i = 0; i < n; i++) {
        scanf("%d", &h[i]);
    }
    int result = 0;
    for (int i = 0; i < n; i++) {
        if (h[i] >= k) {
            result++;
        }
    }
    printf("%d", result);
    return 0;
}

Measured memory_bytes: 640
import java.util.*;

public class Main {

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

        char c = str.charAt(0);
        boolean same = true;
        for(int i = 1 ; i < 3 ; i++) {
            if (str.charAt(i) != c) {
                same = false;
            }
        }

        System.out.println(!same? "Yes" : "No");
    }
}


Measured memory_bytes: 23124
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
const int INF = 100010001;
const ll LINF = (ll)INF*INF*10;

int main() {
    int a, b;
    cin >> a >> b;

    int h = 100;
    int w = 100;

    vs maa(100);
    rep(i, 100) {
        if(!(i/50)) {
            rep(j, 100) {
                maa[i] += '#';
            }
        } else {
            rep(j, 100) {
                maa[i] += '.';
            }
        }
    }

    rep(i, a-1) {
        int ni = i/50*2;
        int nj = i%50*2;
        maa[ni][nj] = '.';
    }
    rep(i, b-1) {
        int ni = i/50*2 + 51;
        int nj = i%50*2;
        maa[ni][nj] = '#';
    }


    cout << h << ' ' << w << endl;

    rep(i, 100) {
        cout << maa[i] << endl;
    }
}

Measured memory_bytes: 256
import java.io.InputStream;
import java.io.PrintStream;
import java.util.*;

public class Main {

  public static void main(String[] args) {
    solve(System.in, System.out);
  }

  static void solve(InputStream is, PrintStream os) {
    Scanner sc = new Scanner(is);

    /* read */
    int n = sc.nextInt();
    
    // matrix
    // boolean[][] matrix = new boolean[n][n];
    // list
    Map<Integer, List<Integer>> lists = new HashMap<>();
    
    for (int i = 0; i < n; i++) {
      String s = sc.next();
      List<Integer> list = new ArrayList<>();
      
      for (int j = 0; j < n; j++) {
        if (s.charAt(j) == '1') {
          // matrix[i][j] = true;
          list.add(j);
        }
      }
      lists.put(i, list);
    }
    
//    List<Integer> leaves = new ArrayList<>();
//    for (int i = 0;i < n; i++) {
//      if (lists.get(i).size() == 1) {
//        leaves.add(i);
//      }
//    }
//    if (leaves.isEmpty()) {
//      os.println("-1");
//      return;
//    }
//    
//    int max = -1;
//    for (int leaf : leaves) {
//      max = Math.max(depth(leaf, lists), max);
//    }

    int max = -1;
    for (int i = 0; i < n; i++) {
      max = Math.max(depth(i, lists), max);
    }

    os.println(max);
  }
  
  private static class Node {
    int node;
    Set<Integer> parents = new HashSet<>();
  }
  
  private static int depth(int start, Map<Integer, List<Integer>> lists) {
    Set<Integer> visited = new HashSet<>();
    Set<Node> curr = new HashSet<>();
    Node s = new Node();
    s.node = start;
    curr.add(s);

    int count = 0;
    while (visited.size() < lists.size()) {
      count++;
      Map<Integer, Node> next = new HashMap<>();
      for (Node n : curr) {
        List<Integer> nexts = lists.get(n.node);
        for (int nx : nexts) {
          if (n.parents.contains(nx)) {
            // parent. ignore
            continue;
          }
          if (visited.contains(nx)) {
            // visiting again
            return -1;
          }
          Node node;
          if (next.containsKey(nx)) {
            node = next.get(nx);
          } else {
            node = new Node();
            node.node = nx;
            next.put(nx, node);
          }
          node.parents.add(n.node);
        }
        for (Node c : curr) {
          visited.add(c.node);
        }
      }
      curr = new HashSet<>(next.values());
    }
    return count;
  }
}

Measured memory_bytes: 95360
S = input()
for bit in range(8):
    f = S[0]
    ans = int(S[0])
    for i in range(3):
        if bit&(1<<i):
            f += "+"
            ans += int(S[i + 1])
        else:
            f += "-"
            ans -= int(S[i + 1])
        f += S[i + 1]
    if ans == 7:
        print(f + "=7")
        break

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

int main(){
  int h,w,n;
  cin >> h >> w >> n;
  vector<int> v(n),ans(h*w);
  int k= 0;
  r(i,n)cin >>v[i];
  r(i,h*w){
    if(v[k]==0)k++;
    ans[i]=k+1;
    v[k]--;
  }
  r(i,h){
    r(j,w){
      if(i%2==0)cout<<ans[i*w+j]<<" ";
      else cout<<ans[(i+1)*w-j-1]<<" ";
    }
    cout<<endl;
  }
}


Measured memory_bytes: 384
#include <cstdio>

#define N 500050
int t1[N],tn[N];
int main()
{
	int n,m;scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++)
	{
		int p1,p2;scanf("%d%d",&p1,&p2);
		if(p1==1) t1[p2]=1;
		if(p2==1) t1[p1]=1;
		if(p1==n) tn[p2]=1;
		if(p2==n) tn[p1]=1;
	}
	for(int i=2;i<n;i++)
		if(t1[i] && tn[i])
		{
			puts("POSSIBLE");
			return 0;
		}
	puts("IMPOSSIBLE");
}


Measured memory_bytes: 1664
#include<iostream>
#include<string>
#include<algorithm>
#include<stack>
#include<vector>
#define rep(i, n) for(int i = 0; i < n; i++ )
using namespace std;


int main() {
  int a, b;
  cin >> a >> b;
  int add, sub, prod;
  add = a + b; sub = a - b; prod = a * b;
  cout << max(add, max(sub, prod)) << endl;
  return 0;
}


Measured memory_bytes: 384
from collections import deque
n, m = map(int, input().split())

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

q = deque([1])
ans = {}

visited = [False] * (n+1)
visited[1] = True

while q:
    now = q.popleft()
    for i in graph[now]:
        if not visited[i]:
            q.append(i)
            visited[i] = True
            ans[i] = now

print("Yes")
for i in range(2, n+1):
    print(ans[i])


Measured memory_bytes: 41508
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
const int N = 5e5 + 5;
typedef long long ll; 
using namespace std;

int n, l, r, mn, mx, cnt;
struct node { int x, y; } p[N], q[N];
ll ans = 0x3f3f3f3f3f3f3f3f; 

template < typename T >
inline T read()
{
	T x = 0, w = 1; char c = getchar();
	while(c < '0' || c > '9') { if(c == '-') w = -1; c = getchar(); }
	while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return x * w; 
}

bool cmp(node a, node b) { return a.x == b.x ? a.y < b.y : a.x < b.x; }

bool cmp1(node a, node b) { return a.y == b.y ? a.x > b.x : a.y < b.y; }

int main()
{
#ifndef ONLINE_JUDGE
	freopen("cpp.in", "r", stdin); 
#endif
	n = read <int> ();
	for(int i = 1; i <= n; i++)
	{
		p[i].x = read <int> (), p[i].y = read <int> ();
		if(p[i].x > p[i].y) swap(p[i].x, p[i].y);
		if(p[i].x < p[mn].x || !mn) mn = i;
		if(p[i].y > p[mx].y || !mx) mx = i; 
	}
	if(mn != mx)
	{
		l = p[mn].y, r = p[mx].x; if(l > r) swap(l, r); 
		for(int i = 1; i <= n; i++)
		{
			if(i == mn || i == mx) continue; 
			if(p[i].y < l) l = p[i].y; 
			else if(p[i].x > r) r = p[i].x; 
		}
		for(int i = 1; i <= n; i++) if(p[i].x < l && p[i].y > r) q[++cnt] = p[i]; 
		sort(q + 1, q + cnt + 1, cmp1); 
		for(int tmp = 0x3f3f3f3f, i = cnt; i >= 1; i--)
			ans = min(ans, 1ll * (p[mx].y - p[mn].x) * (q[i].y - l)), tmp = min(tmp, q[i].x), l = min(l, tmp); 
		ans = min(ans, 1ll * (p[mx].y - p[mn].x) * (r - l)); 
	}
	sort(p + 1, p + n + 1, cmp), mn = mx = 0;
	for(int i = 1; i <= n; i++)
	{
		if(p[i].x < p[mn].x || !mn) mn = i;
		if(p[i].y > p[mx].y || !mx) mx = i; 		
	}
	r = p[mx].x, l = p[mn].y;
	for(int i = 1; i <= n; i++)
	{
		if(i == mn || i == mx) continue;
		l = min(l, p[i].y), r = max(r, p[i].x); 
	}
	ans = min(ans, 1ll * (p[mx].y - l) * (r - p[mn].x));
	printf("%lld\n", ans); 
	return 0; 
}


Measured memory_bytes: 4756
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//template<typename key, typename val>
//using ordered_tree =
//  tree<key, val, std::less<>, rb_tree_tag, tree_order_statistics_node_update>;
using namespace std;
typedef long long int64;
typedef unsigned long long uint64;
typedef complex<double> comp;
const double pi = 3.14159265358979323846;
const int inf = (int)1e+9 + 2;
const int64 inf64 = (int64)1e+18 + 2;
const double dinf = 1e+20;
const int mod = /*1'000'000'007;//*/998244353;
const int base = 2187;
const double eps = 1e-9;
const int N = 100'000;
const int LOGN = 19;

int n, m, k;

void solve(int) {
  cin >> n;
  vector<int> a(n), b(n);
  for (int& x : a) {
    cin >> x;
  }
  for (int& x : b) {
    cin >> x;
  }
  vector<int> c(n);
  iota(begin(c), end(c), 1);
  int i = 0, x, y;
  do {
    if (c == a) {
      x = i;
    }
    if (c == b) {
      y = i;
    }
    ++i;
  } while (next_permutation(begin(c), end(c)));
  cout << abs(x - y) << '\n';
}

void precalc() {
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  precalc();
  int test = 1;
  //cin >> test;
  //auto start = chrono::high_resolution_clock::now();
  for (int i = 1; i <= test; ++i) {
    solve(i);
  }
  //cerr << chrono::duration_cast<chrono::milliseconds>(chrono::high_resolution_clock::now() - start).count() << '\n';
  return 0;
}


Measured memory_bytes: 384
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		for(int i = 0; i <= b; i++) {
			if(a*i%b==c) {
				System.out.println("YES");
				return;
			}
		}
		System.out.println("NO");
	}
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll;
typedef pair<double, double> pdd;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef vector<pii> vii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
//const int mod = ;

int main() {
  std::ios::sync_with_stdio(false); std::cin.tie(0);
  string s;
  cin >> s;
  int n = s.size();
  int res = 0;
  int last = -1;
  for (int i = 0; i < n; ++i) {
    int val = s[i] - 'a';
    if (val != last) {
      ++res;
      last = val;
    } else {
      if (i + 1 < n) ++res;
      ++i;
      last = -1;
    }
  }
/*  vi v(1, 1);
  for (int i = 1; i < n; ++i) {
    if (s[i] == s[i - 1]) ++v.back();
    else v.push_back(1);
  }
  for (int x : v) {
    if (x % 3 == 1) res += x / 3 * 2 + 1;
    if (x % 3 == 2) res += x / 3 * 2 + 1;
    if (x % 3 == 0) res += x / 3 * 2;
  }*/
  cout << res << endl;
  return 0;
}


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

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

    int r = 0; int b = 0;

    for(int i = 0; i < N; i++)
    {
        if(S.at(i) == 'R')r++;
        else b++;
    }
    
    if(r > b)cout << "Yes\n";
    else cout << "No\n";
}

Measured memory_bytes: 256
n = STDIN.gets.chomp.to_i
s = STDIN.gets.chomp.split("")
k = STDIN.gets.chomp.to_i

r = s[k-1]
for i in 0..(n-1) do
  if s[i] == r
    print s[i]
  else
    print "*"
  end
end

Measured memory_bytes: 3836