akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define SZ(x) ((int)(x).size())
typedef long long ll;
typedef long double ld;
using namespace std;

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cout.setf(ios::fixed); cout.precision(20);
    int n; cin >> n;
    string s; cin >> s;
    ll ones = count(s.begin(), s.end(), '1');
    vector<ll> powers1(n), powers2(n);
    ll mod1 = ones - 1, mod2 = ones + 1;
    if (mod1 > 0) {
        powers1[0] = 1;
        for (int i = 1; i < n; i++) {
            powers1[i] = (powers1[i - 1] * 2) % mod1;
        }
    }
    powers2[0] = 1;
    for (int i = 1; i < n; i++) {
        powers2[i] = (powers2[i - 1] * 2) % mod2;
    }
    ll res1 = 0, res2 = 0;
    for (int i = 0; i < n; i++) {
        if (s[n - 1 - i] == '1') {
            if (mod1 > 0) {
                res1 = (res1 + powers1[i]) % mod1;
            }
            res2 = (res2 + powers2[i]) % mod2;
        }
    }
    vector<ll> res(n);
    for (int i = 0; i < n; i++) {
        if (s[i] == '0') {
            res[i] = (res2 + powers2[n - i - 1]) % mod2;
        } else {
            if (mod1 > 0) {
                res[i] = (res1 - powers1[n - i - 1] + mod1) % mod1;
            }
        }
    }
    vector<ll> dp((int) 2e5 + 10, -1);
    dp[0] = 0;
    function<ll(int)> calc = [&](ll x) {
        if (dp[x] != -1) {
            return dp[x];
        }
        return 1 + calc(x % __builtin_popcountll(x));
    };
    for (int i = 0; i < n; i++) {
        if (s[i] == '1' && mod1 == 0) {
            cout << 0 << "\n";
            continue;
        }
        cout << 1 + calc(res[i]) << "\n";
    }
}


Measured memory_bytes: 9768
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
int main(){
	long long n;
	cin>>n;
	long long ans=999999999999;
	for(int i=1;i<=sqrt(n);i++)
	{
		if(n%i==0)
		{
			if(i+(n/i)-2<ans)
			{
				ans=i+(n/i)-2;
			}
			
		}
	}
	cout<<ans;
	return 0;
} 

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

int main() {
	string s, t, u;
	int a, b;
	cin >> s >> t;
	cin >> a >> b;
	cin >> u;
	if (s == u) {
		a--;
	}
	else {
		b--;
	}
	cout << a << " " << b; 

	return 0;
}


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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define eb emplace_back

using ll = long long;
using vll = vector<ll>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using P = pair<int, int>;

vector<pair<ll,int>> factorize(ll n){
	vector<pair<ll,int>> res;
  	for(ll i = 2; n >= i*i; i++){
    	if(n%i) continue;
        res.emplace_back(i,0);
        while(n%i == 0){
        	n /= i;
          	res.back().second++;
        }
    }
  	if(n!=1){
  		res.emplace_back(n,1);
    }
  	return res;
}

void Main() {
    ll n;
    cin >> n;
    auto fac = factorize(n);
    
    vi tri(1005);
    rep(i, 1005){
        tri[i] = i*(i+1)/2;
    }
    
    int ans = 0;
    for(auto [p,e] : fac){
        // cout << p << "^" << e << endl;
        rep(i, 1000){
            if(e >= tri[i] && e < tri[i+1]){
                ans += i;
                break;
            }
        }
    }
    
    cout << ans << endl;
    
	return;
}

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


Measured memory_bytes: 3656
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <tuple>
#include <vector>
#include <set>
#include <map>
#include <iterator>
#include <random>
#include <cmath>

using namespace std;
using lint = long long int;

int main() {
	int r;
	cin >> r;
	cout << r * r << endl;
	return 0;

}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
        String s = sc.next();
        
        int ans  = 0;
        for (char a: s.toCharArray()){
        	if (a == '1'){
        		ans ++;
        	}
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 22868
from sys import stderr
from functools import reduce
from operator import add
def f(): return [int(i) for i in input().split()]
def debug(*x, sep=" ", end="\n"):
    for item in x:
        stderr.write(repr(item))
        stderr.write(sep)
    stderr.write(end)

a1,a2,a3 = f()

a = abs(a1-a2)
b = abs(a2-a3)
c = abs(a3-a1)
print(min(a+b,b+c,c+a))

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

#define LL long long
#define LD long double
#define SC(t,x) static_cast<t>(x)
#define AR(t) vector < t >
#define PII pair < int, int >
#define PLL pair < LL, LL >
#define PIL pair < int, LL >
#define PLI pair < LL, int >
#define MP make_pair
#define PB push_back
#define PF push_front
#define POB pop_back
#define POF pop_front
#define PRF first
#define PRS second
#define INIT(ar,val) memset ( ar, val, sizeof ( ar ) )
#define lp(loop,start,end) for ( int loop = start; loop < end; ++loop )
#define lpd(loop,start,end) for ( int loop = start; loop > end; --loop )
#define lpi(loop,start,end) for ( int loop = start; loop <= end; ++loop )
#define lpdi(loop,start,end) for ( int loop = start; loop >= end; --loop )
#define qmax(a,b) (((a)>(b))?(a):(b))
#define qmin(a,b) (((a)<(b))?(a):(b))
#define qabs(a) (((a)>=0)?(a):(-(a)))

const int INF = 0x3fffffff;
const int SINF = 0x7fffffff;
const long long LINF = 0x3fffffffffffffff;
const long long SLINF = 0x7fffffffffffffff;

int n;

void init ();
void input ();
void work ();

int getv ( int x )
{
	int ans = 0;
	while ( x ) {
		ans += x % 10;
		x /= 10;
	}
	return ans;
}



int main ()
{
	init ();
	input ();
	work ();
}



void init ()
{
	// Init Everything Here

	ios::sync_with_stdio ( false );
}

void input ()
{
	// input method

	cin >> n;
}

void work ()
{
	// main work

	int ans = INF;
	lp ( i, 1, n ) ans = min ( ans, getv ( i ) + getv ( n - i ) );
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cmath>

#include <list>
#include <queue>
#include <algorithm>

#define INF 1000000000

using namespace std;

int main(void)
{
    string s;
    cin >> s;
    int count=0;
    int max=0;
    for (int i=0; i<3; i++) {
        if (s[i]=='S') {
            count=0;
        } else {
            count++;
            if (count > max) max=count;
        }
    }
    cout << max;
}

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

using namespace std;
const int maxn =  1e6 + 10;
#define ll long long
#define ios std::ios::sync_with_stdio(false)
const ll INF(0x3f3f3f3f3f3f3f3fll);
const int inf(0x3f3f3f3f);
/*


ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
ll pow_mod(ll x,ll n,ll mod){ll res=1;while(n){if(n&1)res=res*x%mod;x=x*x%mod;n>>=1;}return res;}//xµÄn´Î·½mod


ll mult(ll a,ll b,ll p){a%=p;b%=p;ll r=0,v=a;while(b){if(b&1){r+=v;if(r>p)r-=p;}v<<=1;if(v>p)v-=p;b>>=1;}return r;}
ll quick_pow(ll a,ll b,ll p){ll r=1,v=a%p;while(b){if(b&1)r=mult(r,v,p);v=mult(v,v,p);b>>=1;}return r;}
bool CH(ll a,ll n,ll x,ll t)
{ll r=quick_pow(a,x,n);ll z=r;for(ll i=1;i<=t;i++){r=mult(r,r,n);if(r==1&&z!=1&&z!=n-1)return true;z=r;}return r!=1;}
bool Miller_Rabin(ll n)
{if(n<2)return false;if(n==2)return true;if(!(n&1))return false;ll x=n-1,t=0;while(!(x&1)){x>>=1;t++;}srand(time(NULL));
ll o=8;for(ll i=0;i<o;i++){ll a=rand()%(n-1)+1;if(CH(a,n,x,t))return false;}return true;}


*/

#define int long long
#define sc(t) scanf("%lld",&t)
#define pr(ans) printf("%lld\n",ans)
ll pow_mod(ll x,ll n,ll mod){ll res=1;while(n){if(n&1)res=res*x%mod;x=x*x%mod;n>>=1;}return res;}//xµÄn´Î·½mod
template<typename T>void read(T &res){bool flag=false;char ch;while(!isdigit(ch=getchar()))(ch=='-')&&(flag=true);
for(res=ch-48;isdigit(ch=getchar());res=(res<<1)+(res<<3)+ch - 48);flag&&(res=-res);}
typedef unsigned long long ULL;
const double pi = 3.1415926535897932384626;
int gcd(int a,int b){return !b?a:gcd(b,a%b);}
int lcm(int a,int b){return a/gcd(a,b)*b;}
#define debug(x) cout << #x << " : " << x << '\n';
#define sb cout << "sb\n";
#define fi first
#define se second
#define pb(a) push_back(a)
#define cn cout << '\n'
#define mp(a , b) make_pair(a , b)
const double ep = 1e-6;

signed main()
{
    ios;///60 10 50
    cin.tie(0);
    int l , r , d;
    cin >> l >> r >> d;
    int ans = (r / d) - ((l - 1) / d);
    cout << ans << '\n';
	return 0;
}
/*
18
2 3 3
*/


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

int main()
{
	int A, B, Q; cin >> A >> B >> Q;
	vector<long long> s(A), t(B), x(Q);

	for (int i = 0; i < A; i++) cin >> s[i];
	for (int i = 0; i < B; i++) cin >> t[i];

	sort(s.begin(), s.end());
	sort(t.begin(), t.end());


	for (int i = 0; i < Q; i++) {
		long long x; cin >> x;

		long long ls, rs, lt, rt;

		if (x < s[0]) {
			ls = -10e10 * 2;
			rs = s[0];
		}
		else if (x > s[A - 1]) {
			ls = s[A - 1];
			rs = 10e10 * 2;
		}
		else {
			ls = *(lower_bound(s.begin(), s.end(), x)-1);
			rs = *lower_bound(s.begin(), s.end(), x);
		}

		if (x < t[0]) {
			lt = -10e10 * 2;
			rt = t[0];
		}
		else if (x > t[B - 1]) {
			lt = t[B - 1];
			rt = 10e10 * 2;
		}
		else {
			lt = *(lower_bound(t.begin(), t.end(), x)-1);
			rt = *lower_bound(t.begin(), t.end(), x);
		}

		ls = x - ls;
		lt = x - lt;
		rs = rs - x;
		rt = rt - x;

		long long ans;
		ans = min(min(min(
			max(ls, lt),
			max(rs, rt)),
			ls + rt + min(ls, rt)),
			rs + lt + min(rs, lt));
		cout << ans << endl;
	}
}

Measured memory_bytes: 3712
#include <iostream>
#include <cstdio>
#include <cstring>
#define c2i(x) (x-'a')
using namespace std;
const int MAXN = 500005;
int son[26][MAXN],sum[MAXN],n,sz,val[MAXN],ans[26][26][100005],t[26][26];
char s[MAXN];
inline void insert(char *s,int id)
{
  int p=0,len=strlen(s+1);
  for(int i=1;i<=len;++i){
    int o=c2i(s[i]);
    if(!son[o][p])son[o][p]=++sz;
    p=son[o][p];
    ++sum[p];
  }
  val[p]=id;
}
int init[MAXN];
void dfs(int x,int pre)
{
  if(val[x]){
    init[val[x]]=pre;
    for(int i=0;i<26;++i)
      for(int j=0;j<26;++j)
	ans[i][j][val[x]]=t[i][j];
  }
  for(int i=0;i<26;++i){
    if(son[i][x]){
      for(int j=0;j<26;++j){
	if(i!=j && son[j][x])t[i][j]+=sum[son[j][x]];
      }
      dfs(son[i][x],pre+!!val[x]);
      for(int j=0;j<26;++j){
	if(i!=j && son[j][x])t[i][j]-=sum[son[j][x]];
      }
    }
  }
}
int m,pos[MAXN];
int main()
{
  scanf("%d",&n);
  for(int i=1;i<=n;++i){
    scanf("%s",s+1);
    insert(s,i);    
  }
  dfs(0,0);
  scanf("%d",&m);
  while(m--){
    int k;
    scanf("%d",&k);
    scanf("%s",s);
    for(int i=0;i<26;++i)
      pos[c2i(s[i])]=i;
    int ret=0;
    for(int i=0;i<26;++i)
      for(int j=0;j<26;++j)
	if(pos[j]<pos[i])ret+=ans[i][j][k];
    printf("%d\n",ret+init[k]+1);                     
  }
  return 0;
}


Measured memory_bytes: 346112
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using Pld = pair<ld, ld>;
using Vec = vector<ll>;
using VecP = vector<P>;
using VecB = vector<bool>;
using VecC = vector<char>;
using VecD = vector<ld>;
using VecS = vector<string>;
using Graph = vector<VecP>;
#define REP(i, m, n) for(ll (i) = (m); (i) < (n); ++(i))
#define REPR(i, m, n) for(ll (i) = (m); (i) > (n); --(i))
#define rep(i, n) REP(i, 0, n)
#define R cin>>
#define i64 unsigned long long
#define repr(i, n) REPR(i, n, 0)
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define in(a) insert(a)
#define P(p) cout<<(p)<<endl;
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define SORT(a) sort((a).begin(), (a).end())
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<long long int> vll;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<ll, ll> pll;
void sonic(){ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);}
void setp(const ll n){cout << fixed << setprecision(n);}
const ll INF = 1e9+1;
const ll LINF = 1e18+1;
const ll mod = 1e9+7;
//const ll MOD = 998244353;
const ld PI = acos(-1);
const ld EPS = 1e-11;
template<typename T> void co(T e){cout << e << "\n";}
template<typename T> void co(const vector<T>& v){for(const auto& e : v)
    { cout << e << " "; } cout << "\n";}
ll gcd(ll a, ll b) {
    if (a < b)swap(a, b);
    if (b == 0) return a;
    unsigned r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}
ll lcm(ll a, ll b) {
    ll g = gcd(a, b);
    return a * b / g;
}
bool prime(ll n) {
    for (ll i = 2; i <= sqrt(n); i++) {
        if (n%i == 0)return false;
    }
    return n != 1;
}


int pow(int x, int y, int mod){
    int ret=1;
    for(;y;y>>=1,x=1ll*x*x%mod){
        if(y&1) ret=1ll*ret*x%mod;
    }
    return ret;
}
void kill()
{
    cout << "No" << endl;
    exit(0);
}

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

void  twice(int& a){
    std::cout << a << std::endl;
    a *= 2;
    std::cout << a << std::endl;
}

ll dp[5000][5002];
char s[5010];

int main(){
    sonic();
    ll n, ss;
    scanf("%lld %s", &n, s);
    ss = strlen(s);
    dp[0][0]=1;
    dp[0][1]=2;
    REP(i,1,n)rep(j,n+1){
            if(j!=0)dp[i][j]+=dp[i-1][j-1]*2;
            else dp[i][j]+=dp[i-1][j];
            dp[i][j]+=dp[i-1][j+1];
            dp[i][j]%=mod;
        }
    co(1ll*dp[n-1][ss]*pow(pow(2,ss,mod),mod-2,mod)%mod);
}


Measured memory_bytes: 199064
s = input()
a = 0
z = 0
for i in range(len(s)):
    if s[i] == 'A' and a == 0:
        a = i + 1
    if s[-i] == 'Z' and z == 0 and i != 0:
        z = len(s) -i + 1
print(z - a + 1)

Measured memory_bytes: 3516
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
#define PI 3.1415926535897932384626433
#define mod 1000000007
 
int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }
 
int lcm(int a, int b) { return a * b / gcd(a, b); }
 
int main(){
    int k, x;
    cin >> k >> x;
    for (int i = x - k + 1; i < x + k; i++){
        if (i == x + k - 1)
        {
            cout << i;
        }else{
            cout << i << " ";
        }
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using Library;
using static Library.Input;

namespace AtCoderTemplate
{
    class ProgramE
    {
        static void Main()
        {
            int n = NextInt;
            var a = TakeLine(n).Select(l => new Queue<long>(l)).ToArray();
            var matrix = Enumerable.Range(0, n).Select(_ => Enumerable.Repeat(false, n).ToArray()).ToArray();
            int battle = n * (n - 1), day = 0;
            var queue = new Queue<long>();

            for (int i = 0; i < n; i++)
            {
                matrix[i][a[i].First() - 1] = true;
                if (matrix[a[i].First() - 1][i])
                {
                    queue.Enqueue(i);
                    queue.Enqueue(a[i].First() - 1);
                }
            }

            // System.Console.WriteLine(string.Join("\n", matrix.Select(l => string.Join(" ", l))));

            while (queue.Any())
            {
                var tomorrow = new Queue<long>();
                while (queue.Any())
                {
                    var tmp = queue.Dequeue();
                    a[tmp].Dequeue();
                    battle--;
                    if (a[tmp].Any())
                    {
                        matrix[tmp][a[tmp].First() - 1] = true;
                        if (matrix[a[tmp].First() - 1][tmp])
                        {
                            tomorrow.Enqueue(tmp);
                            tomorrow.Enqueue(a[tmp].First() - 1);
                        }
                    }
                }

                // System.Console.WriteLine(battle);
                // System.Console.WriteLine(string.Join("\n", matrix.Select(l => string.Join(" ", l))));

                queue = tomorrow;
                day++;
            }

            if (battle == 0)
            {
                System.Console.WriteLine(day);
            }
            else
            {
                System.Console.WriteLine(-1);
            }
        }
    }
}

namespace Library
{
    class Input
    {
        static IEnumerator<string> enumerator = new string[] { }.AsEnumerable().GetEnumerator();

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

        public static string[] StrArr => Line.Split(' ');

        public static int NextInt => int.Parse(NextWord());

        public static long NextLong => long.Parse(NextWord());

        public static List<int> IntList => StrArr.Select(int.Parse).ToList();

        public static List<long> LongList => StrArr.Select(long.Parse).ToList();

        public static IEnumerable<long[]> TakeLine(int N)
        {
            return Enumerable.Repeat(0, N).Select(_ => Console.ReadLine().Split(' ').Select(long.Parse).ToArray());
        }

        public static string NextWord()
        {
            while (!enumerator.MoveNext())
            {
                enumerator = StrArr.AsEnumerable().GetEnumerator();
            }
            return enumerator.Current;
        }
    }
}


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

int main() {
  long long int N, M;
  cin >> N >> M;
  long long int a, b;
  a = min(N, M);
  b = max(N, M);
  if (a == 1 && b == 1) cout << 1 << endl;
  else if (a == 1) cout << b - 2 << endl;
  else cout << (a - 2) * (b - 2) << endl;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var s string
	fmt.Scanf("%s", &s)
	if len(s)%2 == 0 {
		s = s[:len(s)-2]
	} else {
		s = s[:len(s)-1]
	}
	for 1 < len(s) {
		if s[:len(s)/2] == s[len(s)/2:] {
			fmt.Println(len(s))
			break
		}
		s = s[:len(s)-2]

	}
}


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

void fnInput(vector<string>& rvsStrX, vector<string>& rvsStrY)
{
  int nMaxSiz;
  cin >> nMaxSiz;
  rvsStrX.resize(nMaxSiz);
  rvsStrY.resize(nMaxSiz);

  for (int i = 0; i < nMaxSiz; ++i)
  {
    cin >> rvsStrX[i] >> rvsStrY[i];
    rvsStrX[i] = ' ' + rvsStrX[i];
    rvsStrY[i] = ' ' + rvsStrY[i];
  }
}

int fnLngCmnSubseq(const vector<string>& cnrvsStrX, const vector<string>& cnrvsStrY)
{
  vector<vector<int>> vvnLcsDP;
  for (int i = 0; i < cnrvsStrX.size(); ++i)
  {
    const int nMAXNX = cnrvsStrX[i].size();
    const int nMAXNY = cnrvsStrY[i].size();

    vvnLcsDP.clear();
    vvnLcsDP.resize(nMAXNX, vector<int>(nMAXNY, 0));

    for (int nx = 1; nx < nMAXNX; ++nx)
      for (int ny = 1; ny < nMAXNY; ++ny)
        if (cnrvsStrX[i][nx] == cnrvsStrY[i][ny])
          vvnLcsDP[nx][ny] = vvnLcsDP[nx - 1][ny - 1] + 1;
        else
          vvnLcsDP[nx][ny] = max(vvnLcsDP[nx - 1][ny], vvnLcsDP[nx][ny - 1]);

    cout << vvnLcsDP[nMAXNX - 1][nMAXNY - 1] << endl;
  }
}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  vector<string> vsStrX, vsStrY;

  fnInput(vsStrX, vsStrY);
  fnLngCmnSubseq(vsStrX, vsStrY);
  return 0;
}

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

using namespace std;

int main()
{
    int n;

    cin >> n;

    set<int> d;

    int i,k;

    for(i=0;i<n;i++)
    {
        cin >> k;

        d.insert(k);


    }

    if(d.size()==n)
    {
        cout << "YES" << endl;
    }
    else
    {
        cout << "NO" << endl;
    }

    return 0;
}


Measured memory_bytes: 12752
#include<bits/stdc++.h>
using namespace std;
#define db(x){if(cond)cerr<<__LINE__<<" "<<#x<<" " <<x<<endl;}
#define rep(i,b)for(auto i=(0);i<(b);++i)
#define fo(i,a,b)for(auto i=(a);i<=(b);++i)
#define ford(i,a,b)for(auto i=(a);i>=(b);--i)
#define all(x) (x).begin(),(x).end()
#define vv vector
#define pb push_back
template<typename X>void MA(X&a,X b){a=max(a,b);}template<typename X>void MI(X&a,X b){a=min(a,b);}
template<typename X>void clr(X&x,int a){memset(x,a,sizeof(a));};typedef long long ll;typedef long double ld;
typedef array<int,2>i2;typedef vv<int>vi;int cond=0,multi=0,gcj=0;

struct solver_t;solver_t *solver;
struct solver_t{

  int C[600],S[600],F[600];

  void solve(){
    int N;cin>>N;
    N--;
    rep(i,N)cin>>C[i]>>S[i]>>F[i];
    fo(i,0,N){
      int t=0;
      for(int p=i;p<N;p++){
        t=max(t,S[p]);
        while(t%F[p])t++;
        t+=C[p];
      }
      cout<<t<<"\n";
    }
  }
};

void gen(){}
void brute(){}
int main(int argc,char** argv){
  fo(i,1,argc-1)if(argv[i]==string("q"))cond=1<<30;
  fo(i,1,argc-1)if(argv[i]==string("gen")){gen();exit(0);}
  fo(i,1,argc-1)if(argv[i]==string("brute")){brute();exit(0);}
  ios::sync_with_stdio(false),cin.tie(0);
  cout.setf(ios::fixed),cout.precision(10);int t;if(multi||gcj)cin>>t;else t=1;
  fo(i,1,t){if(cond)cerr<<__LINE__<<" "<<i<<endl;if(gcj)cout<<"Case #"<<i<<": ";
    solver = new solver_t();
    solver->solve();
  }return 0;
}


Measured memory_bytes: 256
import bisect

s=input()
t=input()

i=1
dic=[[] for _ in range(27)]
for ss in s:
    dic[ord(ss) - 97].append(i) 
    i+=1

for index,item in enumerate(dic):
    item.sort()
    dic[index]=item

posi=-1
count=0
for tt in t:
    if dic[ord(tt) - 97]==[]:
        print(-1)
        exit()
    
    r=bisect.bisect_right(dic[ord(tt) - 97],posi)

    flag=0
    if r>=len(dic[ord(tt) - 97]):
        count+=1
        posi=dic[ord(tt) - 97][0]
    else:
        posi=dic[ord(tt) - 97][r]
    
print(count*len(s)+posi)


        





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

using namespace std;

const int Nmax = 2e5 + 5;

double ans = 0;
bool ok;
vector< pair<int,int> > v;
int x_1, x_2, y_1, y_2, X1, X2, Y1, Y2, x, y, i, n, nr = 0, a[Nmax];


int modul(int x)
{
    return max(x, -x);
}

int dist(int x_1, int y_1, int x_2, int y_2)
{
    return modul(x_1 - x_2) + modul(y_1 - y_2);
}

void baga(int val)
{
    int st = 1, dr = nr, mid;
    while(st <= dr)
    {
        mid = (st+dr) / 2;
        if(a[mid] < val) st = mid+1;
            else dr = mid-1;
    }

    a[st] = val; if(st == nr+1) ++nr;
}

int main()
{
  //  freopen("input", "r", stdin);
    cin.sync_with_stdio(false);

    cin >> X1 >> Y1 >> X2 >> Y2;
    cin >> n;

    x_1 = min(X1, X2); x_2 = max(X1, X2);
    y_1 = min(Y1, Y2); y_2 = max(Y1, Y2);
    ans = (double) (x_2 - x_1) * 100 + (double) (y_2 - y_1) * 100;

    if(X1 > X2)
    {
        swap(X1, X2); swap(Y1, Y2);
    }


    for(i=1; i<=n; ++i)
    {
        cin >> x >> y;

/*        if(x_1 == x_2)
            if(x == x_1 && y_1 < y && y < y_2) { ans += 10 * M_PI - 20; continue; }

        if(y_1 == y_2)
            if(y == y_1 && x_1 < x && x < x_2) { ans += 10 * M_PI - 20; continue; }

  */      if(x_1 <= x && x <= x_2 && y_1 <= y && y <= y_2) v.push_back( {x, y} );
    }

   // if(x_2 - x_1 >= 2 && y_2 - y_1 >= 2)
    {
        sort(v.begin(), v.end());
        if(y_1 != Y1) reverse(v.begin(), v.end());

        nr = 0;
        for(auto it : v) baga(it.second);

        if(nr == x_2 - x_1 + 1 && nr == v.size())
        {
            ok = 1;
            for(i=0; ok && i<v.size(); ++i)
                if(v[i].first != x_1 + i) ok = 0;
            if(ok) --nr, ans += (10 * M_PI - 20);
        }
        else if(nr == y_2 - y_1 + 1 && nr == v.size())
        {
            ok = 1;
            for(i=0; ok && i<v.size(); ++i)
                if(v[i].second != y_1 + i && v[i].second != y_1 + v.size() - i - 1) ok = 0;
            if(ok) --nr, ans += (10 * M_PI - 20);
        }

        ans += (5 * M_PI - 20) * nr;
    }

    cout << setprecision(20);
    cout << ans << '\n';

    return 0;
}


Measured memory_bytes: 2672
import java.util.*;
import java.util.stream.*;
import java.io.*;

public class Main {

  static int n;
  
  public static void main(String[] args) throws Exception {
    
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

    Set<String> s = new HashSet<>();

    String[] in = br.readLine().split(" ");
    n = Integer.parseInt(in[0]);

    for(int i = 0; i < n; i++){

      in = br.readLine().split(" ");
      s.add(in[0]);
    }

    br.close();

    System.out.println(s.size());
    
  }
}

Measured memory_bytes: 60588
k, n = map(int, input().split())
a = list(map(int, input().split()))
d = []

maxV = 0

for i in range(1, len(a)):
    d.append(abs(a[i] - a[i-1]))

d.append(k - a[-1] + a[0])

# print(d)

print(sum(d) - max(d))

Measured memory_bytes: 86348
#include<stdio.h>
int main()
{
    int n,i,t,s=0;
    scanf("%d",&n);
    t=n;
    for(;;)
    {
        s=s+(n%10);
        n=n/10;
        if(n==0)
        break;
    }
    if(t%s==0)
    printf("Yes");
    else
    printf("No");
}

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

using namespace std;

int main()
{
    int n,k;
    int inputs[100000];
    cin >> n >> k;
    int passed = 0;
    for (int i = 0; i < n; i++)
    {
        cin >> inputs[i];
        if(inputs[i] >= k)
        {
            passed++;
        }
    }
    cout << passed;
    return 0;
}

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

int N, K;
int ans = 0;

vector<vector<int>> edge;

int dfs(int now, int pre) {
    int height = 0;
    for (int nxt : edge[now]) {
        height = max(height, dfs(nxt, now));
    }
    if (height == K-1 && pre != 1 && pre != 0) {
        ans++;
        return 0;
    }
    if (height == K && pre == 1) {
        ans++;
        return 0;
    }
    return height+1;
}

int main() {
    cin >> N >> K;
    edge.resize(N+1);
    vector<int> A(N+1);
    for (int i = 1; i <= N; i++) {
        cin >> A[i];
        if (i >= 2) edge[A[i]].push_back(i);
    }
    if (A[1] != 1) ans++;
    
    dfs(1, 0);
    
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 10752
#include <iostream>
#include <map>
using namespace std;
typedef long long ll;
const ll maxn = 1e5 + 5;
ll a[maxn],sum[maxn],ans;
map<ll,ll> num;
int main(int argc, char const *argv[])
{
	int n,m;
	cin>>n>>m;
	for(int i = 1;i <= n; ++i)
	{
		cin>>a[i];
		sum[i] = (sum[i - 1] + a[i]) % m;
		num[sum[i]]++;
	}
	ans = (1 + num[0]) * (num[0]) / 2;  
	for(map<ll,ll>::iterator iter = num.begin();iter != num.end(); ++iter)
	{
		if(iter->first == 0)
		{
			continue;
		}
		ans += iter->second * (iter->second - 1) / 2; 
	}
	cout<<ans<<endl;
	return 0;
}

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

#define ll                   long long int
#define MOD                  1000000007
#define fast()               ios_base::sync_with_stdio(false);  cin.tie(NULL);
#define loop(i,a,b)          for(ll i=(ll)a;i<(ll)b;i++)
#define pool(i,a,b)          for(ll i=(ll)a;i>=(ll)b;i--)
#define pb                   push_back
#define vi                   vector<ll>
#define test()               ll t; cin>>t; while(t--)
#define endl                 "\n"
#define param                greater<ll>()
#define ff                   first
#define ss                   second
#define all(v)               v.begin(),v.end()
#define keep_unique(v) sort(v.begin(), v.end()); v.erase(unique(v.begin(), v.end()), v.end());
#define sor(vec) sort(vec.begin(),vec.end());

using namespace std;

const int N = 1e5+10;
#define MAX  10000000000;
// const int MOD = 998244353;

ll fast_exp(ll x,ll n){ll ans=1;while(n){if(n&1)ans*=x;n=n>>1;x=x*x;}return ans;}
ll mod_exp(ll x, ll y,ll p){ll res = 1;x = x % p;while(y>0){if(y&1)res = (res*x) % p;y = y>>1;x=(x*x)%p;}return res;}


//  vector < ll > vec(N);

// ll fib[N];

ll dp[N];


int main()
{
    
    fast()
    
    
    ll t;
    // cin>>t;
    t=1;
    
    while(t--)
    {
        ll a,b,c,i,n,k,p,j,d,m;
        
        string s;
        
        cin>>n>>k;
        
        vector<ll>vec(n+1);
      
        for(i=1;i<=n;i++)
        {
          cin>>vec[i];
        }
        
        
        
        
        dp[1]=0;
        dp[2]=abs(vec[2]-vec[1]);
        
         m=min(n,k);
    
        
        for(i=3;i<=m;i++)
        {
            dp[i]=MAX;
            
            for(j=1;j<i;j++)
            {
                dp[i]=min(dp[i] , dp[j]+abs(vec[i]-vec[j]) );
            }
            
        }
        
        for(i=m+1;i<=n;i++)
        {
            dp[i]=MAX;
            for(j=i-k;j<i;j++)
            {
                dp[i]=min(dp[i] , dp[j]+abs(vec[i]-vec[j]) );
            }
        }
        
        
        
        cout<<dp[n]<<endl;
    
        
        
        // string ans=vec[0];
        
       
   


      
    }
   
   
   
   
    return 0;
}


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

namespace CompetitiveProgramming
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] ab = Console.ReadLine().Split();
            int a = int.Parse(ab[0]);
            int b = int.Parse(ab[1]);

            if(a%2==0 || b%2==0)  
            {
                Console.WriteLine("No");
            }else{
                Console.WriteLine("Yes");
            }
        }
    }
}


Measured memory_bytes: 11092
package main

import (
	"fmt"
)

const MOD = 1000000007

func ModAdd(a, b int64) int64 {
	return (a + b) % MOD
}

func ModMul(a, b int64) int64 {
	return a * b % MOD
}

func ModSub(a, b int64) int64 {
	r := (a%MOD - b%MOD) % MOD
	if r < 0 {
		r += MOD
	}
	return r
}

func ModDiv(a, b int64) int64 {
	return a % MOD * ModInv(b) % MOD
}

func ModPow(a, n int64) int64 {
	var r int64 = 1
	for n > 0 {
		if n&1 == 1 {
			r = r * a % MOD
		}
		a = a * a % MOD
		n >>= 1
	}
	return r
}

func ModInv(a int64) int64 {
	var b, u, v int64 = MOD, 1, 0
	for b > 0 {
		t := a / b
		a -= t * b
		a, b = b, a
		u -= t * v
		u, v = v, u
	}
	u %= MOD
	if u < 0 {
		u += MOD
	}
	return u
}

type Q struct {
	idx, value int
	a, b       int
	index      int
}

type QS []*Q

func (p QS) Len() int           { return len(p) }
func (p QS) Less(i, j int) bool { return p[i].value > p[j].value }
func (pq QS) Swap(i, j int) {
	pq[i], pq[j] = pq[j], pq[i]
	pq[i].index = i
	pq[j].index = j
}

func (pq *QS) Push(x interface{}) {
	n := len(*pq)
	item := x.(*Q)
	item.index = n
	*pq = append(*pq, item)
}

func (pq *QS) Pop() interface{} {
	old := *pq
	n := len(old)
	item := old[n-1]
	old[n-1] = nil  // avoid memory leak
	item.index = -1 // for safety
	*pq = old[0 : n-1]
	return item
}

func FactoredPrimeNumber(num int) map[int]int {
	m := map[int]int{}
	return factor(m, num, 2)
}

func factor(result map[int]int, num, pnum int) map[int]int {
	if pnum*pnum > num {
		if num != 1 {
			result[num] += 1
		}
		return result
	}

	if num%pnum == 0 {
		num /= pnum
		result[pnum]++
	} else {
		pnum++
	}
	return factor(result, num, pnum)
}

func GCD(a, b int) int {
	if b == 0 {
		return a
	}
	return GCD(b, a%b)
}

func LCM(a, b int) int {
	return a * b / GCD(a, b)
}

type P struct {
	l, r int
}

func main() {
	var N string
	fmt.Scanf("%s\n", &N)
	if N == "ARC" {
		fmt.Println("ABC")
	} else {
		fmt.Println("ARC")
	}

}

func Reverse(runes []rune) []rune {
	for i, j := 0, len(runes)-1; i < j; i, j = i+1, j-1 {
		runes[i], runes[j] = runes[j], runes[i]
	}
	return runes
}


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

int main() {
  int i;
  double v,vmin;
  while(cin >> vmin) {
    i=1;
    while(1) {
      v = 9.8 * sqrt((5*i-5)/4.9);
        if(v >= vmin) break;
        i++;
    }
    cout << i << endl;
  }
}

Measured memory_bytes: 0
import sys
input = sys.stdin.readline

N = int(input())

imos = [[0 for j in range(1001)] for i in range(1001)]

for _ in range(N):
    x1, y1, x2, y2 = map(int, input().split())
    imos[x1][y1] += 1
    imos[x2][y2] += 1
    imos[x2][y1] -= 1
    imos[x1][y2] -= 1

for i in range(1001):
    for j in range(1000):
        imos[i][j + 1] += imos[i][j]

for j in range(1001):
    for i in range(1000):
        imos[i + 1][j] += imos[i][j]

res = 0

for i in range(1001):
    res = max(res, max(imos[i]))

print(res)


Measured memory_bytes: 45984
x = int(input())
vis = [False for _ in range(x+1)]
vis[1] = True
for i in range(2,x+1):
  tmp = i*i
  while tmp < x+1:
    vis[tmp] = True
    tmp *= i
best = 1
for i in range(1,x+1):
  if vis[i]:
    best = i
print(best)

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

int main() {
  int N,M,X;
  cin >> N >> M >> X;
  
  vector<int> A(M);
  for (int i = 0; i < M; i++) {
    cin >> A.at(i);
  }
  
  int counta = 0;
  int countb = 0;
  
  for (int i = 0; i < M; i++) {
    if (A.at(i) < X) {
      counta++;
    }
    else {
      countb++;
    }
  }
  
  if (counta > countb) {
    cout << countb << endl;
  }
  else {
    cout << counta << endl;
  }
}

Measured memory_bytes: 256
import java.io.*;

class Main
{
   public static void main(String[] args) throws IOException
   {

      BufferedReader br =
       new BufferedReader(new InputStreamReader(System.in));

      String str = br.readLine();
      int x = Integer.parseInt(str);

      //System.out.println( x^3 );   // ^はJavaでは○乗ではなくXORビット演算
      System.out.println( x*x*x );            // <= 正解
      //System.out.println( Math.pow(x,3) );  // Math.pow はdouble型を返す。
      //System.out.println( (int)Math.pow(x,3) ); // <= 正解

   }
}


Measured memory_bytes: 24176
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cmath>
#include <set>
#include <queue>
#include <vector>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
using namespace std;

int main()
{
	int N;
	cin >> N;
	vector<pair<int, int>> a(N);
	vector<pair<int, int>> b(N);
	vector<bool> used(N);
	for (auto i = 0; i < N; ++i)
	{
		auto& p = a[i];
		cin >> p.first >> p.second;
	}
	for (auto i = 0; i < N; ++i)
	{
		auto& p = b[i];
		cin >> p.second >> p.first;
	}

	sort(a.begin(), a.end(), greater<pair<int, int>>());
	sort(b.begin(), b.end());

	auto result = 0;
	for (auto& pa : a)
	{
		for (auto i = 0; i < N; ++i)
		{
			if (used[i] != false)
			{
				continue;
			}

			auto& pb = b[i];
			if (pa.first < pb.second && pa.second < pb.first)
			{
				++result;
				used[i] = true;
				break;
			}
		}
	}

	cout << result << endl;

	return 0;
}


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

int main(){
  int n;
  cin >> n;
  vector<ll> a(n), b(n);

  rep(i,n) cin >> a[i] >> b[i];

  ll m = 1;
  ll x = 1, y = 1;
  rep(i,n) {
    if (i != 0) m = max((a[i-1]*m + a[i]-1)/a[i],(b[i-1]*m + b[i]-1) / b[i]);
    x = a[i]*m;
    y = b[i]*m;
  }
  cout << x + y << endl;
  return 0;
}

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

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pll;
typedef vector<bool> vb;
const ll oo = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-9;
#define sz(c) ll((c).size())
#define all(c) begin(c), end(c)
#define FOR(i,a,b) for (ll i = (a); i < (b); i++)
#define FORD(i,a,b) for (ll i = (b)-1; i >= (a); i--)
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define TR(X) ({ if(1) cerr << "TR: " << (#X) << " = " << (X) << endl; })

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	ll n; cin >> n;
	vl a(n);
	FOR(i,0,n) cin >> a[i];

	FOR(i,0,n) FOR(j,0,n) {
		swap(a[i],a[j]);
		if (is_sorted(all(a))) {
			cout << "YES" << endl;
			return 0;
		}
		swap(a[i],a[j]);
	}
	cout << "NO" << endl;
}



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


int solve2(string x) {
    string ret = x;
    while (1) {
        int n = ret.size();
        bool flag = true;
        for (int i = 1; i < n; i++) {
            if (ret.at(i - 1) == 'S' && ret.at(i) == 'T') {
                flag = false;
                ret = ret.substr(0, i - 1) + ret.substr(i + 1);          
                break;
            }   
        }
        if (flag) {
            break;
        }
    }
    return ret.size();
}



int solve(string x) {
    int ret = 0;
    int n = x.size();
    int cnt_s = 0;
    int cnt_t = 0;
    for (int i = 0; i < n; i++) {
        if (x.at(i) == 'S') {
            if (i > 0 && x.at(i - 1) == 'T') {
                // ret += abs(cnt_s - cnt_t);
                if (cnt_s < cnt_t) {
                    ret += cnt_t - cnt_s;
                    cnt_s = 0;
                }
                else {
                    cnt_s -= cnt_t;
                }
                cnt_s++;
                cnt_t = 0;
            }
            else {
                cnt_s++;
            }
        }
        else {
            cnt_t++;
        }
    }
    ret += abs(cnt_s - cnt_t);
    return ret;    
}


void test() {
    for (int n = 1; n <= 6; n++) {
        for (int bit = 0; bit < (1 << n); bit++) {
            string x;
            for (int i = 0; i < n; i++) {
                if (bit & (1 << i)) {
                    x += "S";
                }
                else {
                    x += "T";
                }
            }
            if (solve(x) != solve2(x)) {
                cout << "x = " << x << endl;
                cout << "solve(x) = " << solve(x) << endl;
                cout << "solve2(x) = " << solve2(x) << endl;
                break; 
            }
        }
    }
}


int main() {
    string x;
    cin >> x;
    cout << solve(x) << endl;
    // cout << solve2(x) << endl;
    // test();
    return 0;
}

Measured memory_bytes: 3864
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws Exception {

    	try(BufferedReader r = new BufferedReader(new InputStreamReader(System.in))){

    		String S = r.readLine();
    		int all = S.length();
    		Long red = S.chars().parallel().filter(c -> c=='0').count();
    		Long blue = all - red;
	    	System.out.println(Math.min(red, blue) * 2);
    	}
    }
}

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

int divide_by_2_count(int N) {
  int count = 0;
  while (true) {
    if (N % 2 == 0) {
      count++;
      N /= 2;
    } else {
      break;
    }
  }
  return count;
}

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

  int max_divide_count = 0;
  int max_divide_num = N;
  for (int i = N; i >= 1; i--) {
    int count = divide_by_2_count(i);
    if (count > max_divide_count) {
      max_divide_count = count;
      max_divide_num = i;
    }
  }

  cout << max_divide_num << endl;
}

Measured memory_bytes: 3592
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
using namespace std;
typedef pair<int, int>pii;
typedef pair<pii, pii>pi4;
typedef long long ll;
int main()
{
	int nx, ny, nz;
	scanf("%d%d%d", &nx, &ny, &nz);
	vector<pi4>v;
	for (int i = 0; i < nx + ny + nz; i++)
	{
		int za, zb, zc;
		scanf("%d%d%d", &za, &zb, &zc);
		v.push_back(make_pair(make_pair(zb - zc, za), make_pair(zb, zc)));
	}
	sort(v.begin(), v.end());
	reverse(v.begin(), v.end());
	set<pii>s1, s2;
	ll ans = 0;
	for (int i = 0; i < ny; i++)
	{
		s1.insert(make_pair(v[i].second.first - v[i].first.second, i));
		ans += v[i].second.first;
	}
	for (int i = ny; i < v.size(); i++)
	{
		s2.insert(make_pair(v[i].second.second - v[i].first.second, i));
		ans += v[i].second.second;
	}
	set<pii>::iterator it1 = s1.begin(), it2 = s2.begin();
	for (int i = 0; i < nx; i++)
	{
		pii z = *it2;
		it2++;
		ans -= z.first;
	}
	ll maxi = ans;
	for (int i = ny; i < nx + ny; i++)
	{
		pii ze = make_pair(v[i].second.second - v[i].first.second, i);
		if (ze < (*it2))ans -= v[i].first.second;
		else
		{
			ans -= v[i].second.second;
			it2--;
			ans += (*it2).first;
		}
		s2.erase(ze);
		pii zi = make_pair(v[i].second.first - v[i].first.second, i);
		if (zi < (*it1))
		{
			ans += v[i].first.second;
			s1.insert(zi);
		}
		else
		{
			ans += v[i].second.first;
			s1.insert(zi);
			ans -= (*it1).first;
			it1++;
		}
		maxi = max(maxi, ans);
	}
	printf("%lld\n", maxi);
}

Measured memory_bytes: 6512
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <numeric>
#include <cmath>

#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
using P = pair<ll, ll>;

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

const ll MOD = 1000000007;
const int INF = 1<<30;
//const ll INF = (ll)1e18 + 1;

using Graph = vector<vector<int>>;
int main(){
  int N; cin >> N;
  Graph G(N);
  vector<string> s(N);
  rep(i, N) cin >> s[i];

  rep(i, N) rep(j, N) if (s[i][j] == '1') G[i].push_back(j);
  queue<int> que;
  int ans = 0;
  for (int v = 0; v < N; ++v){
    bool is_bipartite = true;
    vector<int> dist(N, -1);
    dist[v] = 0;
    que.push(v);
    while (!que.empty()){
      int v = que.front(); que.pop();
      for (auto nv: G[v]){
        if (dist[nv] == -1){
          dist[nv] = dist[v] + 1;
          que.push(nv);
        }
        else{
          if (dist[v] == dist[nv]) is_bipartite = false;
        }
      }
    }
    if (is_bipartite) {
      int n_max = 0;
      rep(i, N) n_max = max(n_max, dist[i]);
      ans = max(ans, n_max + 1);
    }
  }
  if (ans == 0) cout << -1 << endl;
  else cout << ans << endl;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
typedef long double ld;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define mod 1000000007
#define inf 1000000000000000
#define autoit(x,it) for(auto it = x.begin(); it != x.end(); it++)
#define rep(n) for(ll i = 0; i < n; i++)
#define repi(i,n) for(ll i = 0; i < n; i++)

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 

#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 

using namespace std;


int main()
{
   FAST/**/
   
   ll powa[64];
   powa[0] = 1;
   for(ll i=1;i<64;i++)
        powa[i] = powa[i-1]*2;
   
   ll n;
   cin>>n;
   
   ll arr[n], arr1[n];
   rep(n)
        cin>>arr[i];
   
   rep(n)
        cin>>arr1[i];
   
   ll lim = (1ll<<n);
   ll ans = inf;
   rep(lim)
   {
       vector<pair<ll,ll>> v,v1;
       ll cst = 0;
       bool pos = 1;
       repi(j,n)
       {
            if(powa[j]&i)
                v.pb(mp(arr[j],j));
            else v.pb(mp(arr1[j],j));
            
            if(powa[j]&i)
                v1.pb(mp(arr[j],j));
            else v1.pb(mp(arr1[j],j));
       }
       ll posi[55][2];
       memset(posi,0,sizeof(posi));
       
       sort(v.begin(), v.end());
       repi(j,n)
            posi[v[j].ff][j%2]++;
       
       repi(j,n)
       {
           if(powa[v[j].ss]&i)
           {
               ll temp = v[j].ss % 2;
               if(posi[v[j].ff][temp] > 0)
                   posi[v[j].ff][temp]--;
               else pos = 0;       
           }
            else 
            {
                ll temp = v[j].ss % 2;
                temp = (1ll)^temp;
               if(posi[v[j].ff][temp] > 0)
                   posi[v[j].ff][temp]--;
               else pos = 0; 
            }
       }
       
       if(!pos)
            continue;
       
       vector<ll> posit[55][2];
       repi(j,n)
           posit[v[j].ff][j%2].pb(j);
       
       repi(j,55)
            repi(k,2)
                sort(posit[j][k].begin(), posit[j][k].end(), greater<ll>());
       
       vector<ll> fin;
       
       repi(j,n)
       {
            if(powa[v1[j].ss]&i)
           {
               ll temp = v1[j].ss % 2;
               fin.pb(posit[v1[j].ff][temp].back());
               posit[v1[j].ff][temp].pop_back();
           }
            else 
            {
                ll temp = v1[j].ss % 2;
                temp = (1ll)^temp;
                fin.pb(posit[v1[j].ff][temp].back());
                posit[v1[j].ff][temp].pop_back();
            }
       }
       //cout<<"siz = "<<fin.size()<<"\n";
       repi(j,n)
           for(ll k=j+1;k<n;k++)
               if(fin[k]<fin[j])
                    cst++;
       ans = min(ans, cst);                
       
   }
   
   if(ans == inf)
        cout<<-1;
   else cout<<ans;            
   
   return 0;        
}  
   

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

namespace cplib {
    template <typename T, typename U>
    T pow(T m, U n) {
        T res = 1;
        while (n > 0) {
            if (n % 2 == 1) {
                res *= m;
            }
            m *= m;
            n /= 2;
        }
        return res;
    }
}

int main() {
    int n;
    std::cin >> n;

    int min, max;
    if (n == 1) {
        min = 0;
        max = 10;
    } else {
        min = cplib::pow(10, n - 1);
        max = cplib::pow(10, n);
    }

    int m;
    std::cin >> m;
    std::vector<int> s(m), c(m);
    for (int i = 0; i < m; i++) {
        std::cin >> s[i] >> c[i];
        s[i]--;
    }
    for (int i = min; i < max; i++) {
        for (int j = 0; j < m; j++) {
            if (std::to_string(i)[s[j]] != '0' + c[j]) {
                goto next;
            }
        }

        std::cout << i << std::endl;
        return 0;

        next:;

    }

    std::cout << -1 << std::endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define oo 0x7fffffff
using namespace std;
inline int read()
{
	int out=0,fh=1;
	char cc=getchar();
	while ((cc>'9'||cc<'0')&&cc!='-')
		cc=getchar();
	if (cc=='-')
		{
			fh=-1;
			cc=getchar();
		}
	while (cc>='0'&&cc<='9')
		{
			out=out*10+cc-'0';
			cc=getchar();
		}
	return out*fh;
}
int n;
int a[101],b[101],c[101],m=0;
void add(int u,int v,int w)
{
	++m;
	a[m]=u;
	b[m]=v;
	c[m]=w;
}
void Build(int x,int L)
{
	if(L<0)
		return;
	if(L==0)
		{
			if(x<n)
				add(x,n,0);
			return;
		}
	if(L==1)
		{
			add(x,n,0);
			add(x,n,1);	
			return;
		}
	if((L&1)==0)
		add(x,n,L);
	L=(L+1)/2;
	int y=x+1;
	add(x,y,0);
	add(x,y,L);
	--L;
	Build(y,L); 
}
void pr()
{
	printf("%d %d\n",n,m);
	for(int i=1;i<=m;++i)
		printf("%d %d %d\n",a[i],b[i],c[i]);
}
int main()
{
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	int L=read();
	
	/*printf("%d %d\n",L,2*L-2);
	for(int i=1;i<L;++i)
		printf("%d %d %d\n",i,i+1,0);
	for(int i=2;i<=L;++i)
		printf("%d %d %d\n",1,i,i-1);*/
		
	n=20;
	Build(1,L-1);
	pr();
	//fclose(stdin);
	//fclose(stdout);
	return 0;
}


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 v1 = vector<int>;
using vl = vector<long long>;
using v2 = vector<vector<int>>;
using v3 = vector<vector<char>>;

int main(){
	int n;
	ll d;
	cin >> n >> d;
	d = d*d;
	vl x(n);
	vl y(n);
	rep(i, n){
		ll x1;
		ll y1;
		cin >> x1 >> y1;
		x[i] = x1*x1;
		y[i] = y1*y1;
	}
	ll ans = 0;
	rep(i, n){
		if(x[i] + y[i] <= d) ans++;
	}
	cout << ans << endl;
}


Measured memory_bytes: 6424
N = int(input())
A = list(map(int, input().split()))
S = sorted(A, reverse=True)
X = S[0]
N -= 2
i = 0
while N > 0:
    i += 1
    x = S[i]
    X += x
    if N == 1:
        break
    X += x
    N -= 2
print(X)

Measured memory_bytes: 31616
#include<stdio.h>
#include<stdlib.h>
void swap(int *x,int *y){
    int tmp=*x;
    *x=*y;
    *y=tmp;
}

int main(){
    int n;scanf("%d",&n);
    char s[n+1];scanf("%s",s);

    int r[4000]={},g[4000]={},b[4000]={};
    int r_i,g_i,b_i;r_i=g_i=b_i=0;
    for(int i=0;i<n;i++){
        if(s[i]=='R')r[r_i++]=i;
        if(s[i]=='G')g[g_i++]=i;
        if(s[i]=='B')b[b_i++]=i;
    }
    int cnt=0;
    for(int i=1;i<n-1;i++){
        int dist=1;
        while(i-dist>=0&&i+dist<n){
            if(s[i-dist]!=s[i]&&s[i]!=s[i+dist]&&s[i-dist]!=s[i+dist])
                cnt++;
            dist++;
        }
    }
    long long ans;
    ans=r_i*g_i;
    ans*=b_i;
    printf("%lld\n",ans-cnt);
}

Measured memory_bytes: 1732