akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <cstdio>
#include <functional>
using namespace std; 
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)
inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }
const int INF = (((1<<30)-1)<<1)+1;
const int nINF = 1<<31;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<char, int> pci;

/////////////////////////////////////////////////////////////////////

const ll N = 1e5;
ll n, used[N];
pll inv[N];
pair<pll, ll> invr[N], invl[N];

ll sim(bool left) {
	fill(used, used+N, 0);
	ll ridx = 0, lidx = 0, cur = 0, ans = 0;
    REP(i, n) {
    	if(left) {
    		while(used[invr[ridx].second]) ++ridx;
    		used[invr[ridx].second] = 1;
    		// DEBUG(invr[ridx].first.first);
    		// DEBUG(invr[ridx].first.second);
    		if(cur < invr[ridx].first.first) {
    			ans += abs(invr[ridx].first.first-cur);
    			cur = invr[ridx].first.first;
    		} else if(cur > invr[ridx].first.second) {
    			ans += abs(invr[ridx].first.second-cur);
    			cur = invr[ridx].first.second;
    		}
    	} else {
    		while(used[invl[lidx].second]) ++lidx;
    		used[invl[lidx].second] = 1;
    		// DEBUG(invl[lidx].first.first);
    		// DEBUG(invl[lidx].first.second);
    		if(cur < invl[lidx].first.first) {
    			ans += abs(invl[lidx].first.first-cur);
    			cur = invl[lidx].first.first;
    		} else if(cur > invl[lidx].first.second) {
    			ans += abs(invl[lidx].first.second-cur);
    			cur = invl[lidx].first.second;
    		}
    	}
    	left = !left;
    }
    ans += abs(cur);
    cur = 0;
    return ans;
}

int main() {
    ios::sync_with_stdio(false);
    //cout << fixed << setprecision(7);
    fill(used, used+N, 0);
    cin >> n;
    REP(i, n) cin >> inv[i].first >> inv[i].second;
    REP(i, n) {
    	invr[i] = {inv[i], i};
    	invl[i] = {inv[i], i};
    }
    sort(invl, invl+n, [](auto& left, auto& right){
    	return left.first.first > right.first.first || (left.first.first == right.first.first && left.first.second > right.first.second);
    });
    sort(invr, invr+n, [](auto& left, auto& right){
    	return left.first.second < right.first.second || (left.first.second == right.first.second && left.first.first < right.first.first);
    });
    ll ans = sim(0);
    ans = max(ans, sim(1));
    
    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 7424
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#define ll long long
using namespace std;
int main(){
    ll l,r;
    cin>>l>>r;
    if(r-l>2019){
        cout<<0<<endl;
        return 0;
    }
    ll ans=3000;

    for(ll i=l;i<r;i++){
        for(ll j=i+1;j<r+1;j++){
            ll r=(i*j)%2019;
            if(ans>r) ans=r;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
import math
import sys
import itertools
import queue
from fractions import gcd

def lcm(a, b):
    return a * b // gcd(a, b)

def combination(n, r):
    return factorial(n) // (factorial(n - r) * factorial(r))

sys.setrecursionlimit(10000)

mod = 1000000007

"""
# 0埋め, 小数点出力桁指定時のときの出力
a = 100
b = 0.987654321
print("{0:06d}-{1:6f}".format(a,b))
000100-0.987654

# 文字列をリストに格納
char_list = list("abcd") # ["a","b","c","d"]

# 標準入力取得
## 文字列
    = sys.stdin.readline().rstrip()
    = list(sys.stdin.readline().rstrip())

## 数値
    = int(sys.stdin.readline())
    = map(int, sys.stdin.readline().split())
    = list(map(int, sys.stdin.readline().split()))
    = [list(map(int,list(sys.stdin.readline().split()))) for i in range(h)]  # 二次元配列入力　二次元マップみたいな入力のとき
"""



if __name__ == "__main__":
    L = [2, 1]
    N = int(sys.stdin.readline())
    if N == 1:
        print(1)
        exit()

    for i in range(2, N + 1):
        L.append(L[i - 1] + L[i - 2])

    print(L[N])


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

using namespace std;
typedef long long ll;

ll ar[100005];

int main(void)
{
	int n;
	cin >> n;
	ll sum = 0;
	ll suma = 0;
	for (int i = 0; i < n; ++i)
	{
		ll tmp;
		cin >> tmp;
		ar[i] = tmp * 2;
		sum += tmp;
		if (i % 2 == 0)
		{
			suma += tmp * 2;
		}
	}
	int a = suma - sum;
	cout << a << " ";
	int tmp = a;
	for (int i = 0; i < n - 1; ++i)
	{
		cout << ar[i] - tmp;
		tmp = ar[i] - tmp;
		if (i != n - 2)
		{
			cout << " ";
		}
		else
		{
			cout << endl;
		}
	}

	return 0;
}


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

using namespace std;
using llong = long long int;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()

const int MOD = 1000000007;
const int INF = 1000000000;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int main (int argc, char *argv[]) {
    cin.tie(0); 
    ios::sync_with_stdio(false);

    int n, m;
    cin >> n >> m;
    vector<bool> AC(n, false);
    vector<int> WA(n, 0);
    int AC_cnt = 0, WA_cnt = 0;
    rep(_, m) {
        int p;
        string S;
        cin >> p >> S;
        if (! AC[p - 1]) {
            if (S == "AC") {
                AC[p - 1] = true;
                ++AC_cnt;
                WA_cnt += WA[p - 1]; 
            } else {
                ++WA[p - 1];
            }
        }
    }

    cout << AC_cnt << " " << WA_cnt << endl;

    return 0;
}

Measured memory_bytes: 640
#!/usr/bin/env python
# coding: utf-8


def is_right_triangle(a, b, c):
    return a ** 2 + b ** 2 == c ** 2


def main():
    input_count = int(raw_input())
    for i in xrange(input_count):
        L = raw_input().split(" ")
        L = map(long, L)
        L.sort()
        print ("NO", "YES")[is_right_triangle(*L)]

if __name__ == '__main__':
    main()

Measured memory_bytes: 4260
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<stdio.h>
#include<set>
using namespace std;
int main(){
   /* string s;
    cin>>s;
    int long long n=s.size();
    int os[n+1];
    os[0]=0;
    int long long j=1;
    int ans=0;
    for(int long long i=0;i<n;i++){
        if(s[i]=='B'){
            os[j]=os[j-1]+1;
            //cout<<"B"<<os[j]<<endl;
            j++;
        }else if(s[i]=='W'){
            os[j]=os[j-1];
            // cout<<"C"<<os[j]<<endl;
            ans+=os[j];
            j++;
        }
        
    }
    cout<<ans<<endl;*/
    
    char s[1000000];
    int long long jj=0;
    while(true){
        if(cin.eof())break;
        cin>>s[jj];
        jj++;
    }
    int long long n=jj;
    int long long os[300000];
    os[0]=0;
    int long long j=1;
    int long long ans=0;
    for(int long long i=0;i<n;i++){
        if(s[i]=='B'){
            os[j]=os[j-1]+1;
            //cout<<"B"<<os[j]<<endl;
            j++;
        }else if(s[i]=='W'){
            os[j]=os[j-1];
            // cout<<"C"<<os[j]<<endl;
            ans+=os[j];
            j++;
        }
    }
    cout<<ans<<endl;
    
    return 0;
}

Measured memory_bytes: 3456
use std::io::*;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
  let stdin = stdin();
  let stdin = stdin.lock();
  let token: String = stdin
    .bytes()
    .map(|c| c.expect("failed to read char") as char)
    .skip_while(|c| c.is_whitespace())
    .take_while(|c| !c.is_whitespace())
    .collect();
  token.parse().ok().expect("failed to parse token")
}

use std::cmp::{max, min};
use std::collections::HashMap;

fn main() {
  let n = read::<i64>();
  let mut vec_n: Vec<i64> = vec![0; n as usize + 1];

  vec_n[0] = 2;
  vec_n[1] = 1;
  for i in 2..n + 1 {
    let i_size = i as usize;
    vec_n[i_size] = vec_n[i_size - 1] + vec_n[i_size - 2];
  }

  println!("{}", vec_n[n as usize]);
}



Measured memory_bytes: 4352
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <cstdlib>
#define rep(i,n) for(int i = 0;i<(n);i++);
#define all(a) (a).begin(),(a).end()
using namespace std;
using ld = long double;
using ll = long long;
const ll INF = 100100100100100;

ll keta(ll x) {
	ll n = 0;
	while (x) {
		x /= 10;
		n++;
	}
	return n;
}
int main() {
	ll N;
	cin >> N;
	ll A = 1, B = N;
	for (ll i = 1; i * i <= N; i++) {
		if (N % i == 0) {
			A = i;
			B = N / i;
		}
	}
	cout << keta(B) << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
	int a,b,c,x,y;
	scanf("%d%d%d",&a,&b,&c);
	y = 0;  //初期化し、約数の数を数えるために使用する
	for(int x = a;x <= b; x++){  //整数aから整数bの間の数ｘ
		if(c % x == 0) y++;  //xがcの約数ならばｙに1加算していく
	}
	printf("%d\n", y);
	return 0;
}


Measured memory_bytes: 2108
w = str(input())
s = {}
 
for wrd in w:
  if s.get(wrd) is None:
    s[wrd] = 1
  else:
    s[wrd] += 1
 
ans = 1
for wrd in s:
  if s[wrd] %2 !=0:
    ans = 0
    break
if ans:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 3060
/*/ Author: KaySeeKay /*/

#include<bits/stdc++.h>
using namespace std;  

/*/---------------------------Defines-----------------------------------------/*/

#pragma GCC optimize("Ofast") 
#define int long long
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back 
#define eb emplace_back
#define fn for(int i =0 ;i <n;i++)  
#define fn1 for( int i =1;i<=n; i++)
#define fm for(int j =0 ;j <m;j++)
#define fm1 for(int j =1;j<=m;j++)
#define fi first
#define se second
#define endl '\n'
#define PI  3.14159265358979323846
#define MOD 1000000007
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
const int N = 2e6+5;  
const int INF = 1e18L;
//mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
/*/-----------------------------Debug begins----------------------------------/*/
vector<string> split(const string& s, char c) {
    vector<string> v; stringstream ss(s); string x;
    while (getline(ss, x, c)) v.emplace_back(x); return move(v);
}
template<typename T, typename... Args>
inline string arrStr(T arr, int n) {
    stringstream s; s << "[";
    for(int i = 0; i < n - 1; i++) s << arr[i] << ",";
    s << arr[n - 1] << "]";
    return s.str();
}
#define trace(args...) {__trace_begin(__LINE__); __trace(split(#args, ',').begin(), args);}
inline void __trace_begin(int line) { cerr << "#" << line << ": "; }
template<typename T> inline void __trace_out_var(vector<T> val) { cerr << arrStr(val, val.size()); }
template<typename T> inline void __trace_out_var(T* val) { cerr << arrStr(val, 10); }
template<typename T> inline void __trace_out_var(T val) { cerr << val; }
inline void __trace(vector<string>::iterator it) { cerr << endl; }
 
template<typename T, typename... Args>
inline void __trace(vector<string>::iterator it, T a, Args... args) {
    cerr << it->substr((*it)[0] == ' ', it->length()) << "=";
    __trace_out_var(a);
    cerr << "; ";
    __trace(++it, args...);
}
/*/-----------------------------Code begins----------------------------------/*/
int ar[N];
int dp[N];
inline int add(int x, int y, int mod) {
   if (y >= mod) y %= mod;
   if (x >= mod) x %= mod;
   x  += y;
   return (x >= mod ? x - mod : x);
} 
inline int mul(int x, int y, int mod) {
  if (x >= mod) x %= mod;
  if (y >= mod) y %= mod;
  return (x*y) % mod;
}
inline int sub(int x, int y, int mod) {
  x -= y;
  if (x + mod <= 0) {
  x %= mod;
  }
  return (x < 0 ? x+mod : x);
}
int PowerMod(int x, int n, int mod) {
  int res = 1;
  for (;n > 0;) {
  if (n & 1) {
    res   = mul(res, x, mod);
  }
  x = mul(x, x, mod);
  n /= 2;
  }
  return res;
}
signed main(){
  #ifndef ONLINE_JUDGE
  freopen("input.txt","r",stdin);
  freopen("output.txt","w",stdout);
  #endif
  IOS;
  int T=1;
  // cin >> T;
  while(T--){
    int n;
    cin >> n;
    int ans =PowerMod(10,n,MOD);
    ans=add(ans,PowerMod(8,n,MOD),MOD);
    ans=sub(ans,mul(2,PowerMod(9,n,MOD),MOD),MOD);
    cout << ans;
    
  }

  return 0;
}
/*
2-2
3-54
4-974
5-14670
6-199262
*/

Measured memory_bytes: 3656
#include <algorithm>
#include <iostream>
#include <vector>

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

    if (n[0] == '9' || n[1] == '9') {
        std::cout << "Yes" << std::endl;
    } else {
        std::cout << "No" << std::endl;
    }
}


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

#define all(a) a.begin(), a.end()
#define allr(a) a.rbegin(), a.rend()
#define rev(v) reverse(v.begin(), v.end());
#define io() ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); srand(time(NULL));

using namespace std;

using ll = long long;
using ld = long double;
using ull = unsigned long long;

signed main(){
    io();
    int k, x; cin >> k >> x;
    cout << (k*500 >= x ? "Yes" : "No") << '\n';
    return 0;
}

Measured memory_bytes: 3640
import java.util.*;

public class Main {

	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		int h,w;
		
		while(true) {
			h = sc.nextInt();
			w = sc.nextInt();
			if (h==0 && w==0) {
				break;
			}
			for (int i=0 ; i<h ; i++) {
				for (int j=0 ; j<w ; j++) {
					System.out.printf("#");
				}
				System.out.println("");
			}
			System.out.println("");
		}
		
		
	}

}


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

int main() {
  int n,d;
  cin>>n>>d;
  double a[n][d];
  for(int i=0;i<n;i++){
    for(int j=0;j<d;j++){
      cin>>a[i][j];
    }
  }

  int count=0;

  for(int i=0;i<n;i++){
    for(int j=1;j<n-i;j++){
      double dis=0;
      for(int k=0;k<d;k++){
        // cout<<"a[i][k]="<<a[i][k]<<endl;
        // cout<<"a[i+j][k]="<<a[i+j][k]<<endl;
        //
        dis += pow(a[i][k]-a[i+j][k],2);
        //
        // cout<<"i="<<i<<",j="<<j<<",k="<<k<<endl;
        // cout<<"dis="<<dis<<endl;
      }
      dis = sqrt(dis);
      if(lround(dis)==dis)  {
        count++;
        // cout<<"sqrt_dis="<<dis<<endl;
        // cout<<endl;
      }
    }
  }

  cout<<count<<endl;
  return 0;
}


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

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define watch(a) { std::cout << #a << " = " << a << "\n"; }
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }
template<class T, class V> istream& operator>> (istream& ist, pair<T, V>& p) { return ist >> p.first >> p.second; }
template<class T> ostream& operator<< (ostream& ost, pair<T, T>& p) { return ost << p.first << ", " << p.second; }
template<class T> istream& operator>> (istream& ist, vector<T>& vs) { for(auto& e: vs) ist >> e; return ist; }

typedef long long ll;
int const inf = INT_MAX / 2;

ll get(ll B) {
  ll ans = 0;
  if ((B + 1) % 2 == 0) {
    ans = (B + 1) % 4 == 0 ? 0 : 1;
  } else {
    ans = B % 4 == 0 ? 0 : 1;
    ans ^= B;
  }
  return ans;
}

int main() {
  ll A, B; cin >> A >> B;
  ll ans = get(A - 1) ^ get(B);
  cout << ans << endl;
}


Measured memory_bytes: 256
N = input()
n = int(N)

jugde = []
for i in range(n):
  s = input()
  jugde.append(s)
  
print('AC x',jugde.count('AC'))
print('WA x',jugde.count('WA'))
print('TLE x',jugde.count('TLE'))
print('RE x',jugde.count('RE'))


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

int main() {

    long long n,m;
    cin >> n >> m;
    rep(i,m){
        long long tmp = 0;
        cin >> tmp;
        n = n - tmp;
    }

    if(n >= 0) cout << n << endl;
    else        cout << "-1"<< endl;
}   

Measured memory_bytes: 3596
process.stdin.setEncoding('utf8');

process.stdin.on('data', function (chunk) {
    const chunks = chunk.split(' ');
    var hight = parseInt(chunks[0]);
    var width = parseInt(chunks[1]);
    var areaOfRectanglar = hight * width;
    var lengthOfRectanglar = (hight + width) * 2;
    console.log(areaOfRectanglar, lengthOfRectanglar);
})

Measured memory_bytes: 15596
/* vim:set foldmethod=marker: */
#include <bits/stdc++.h>
using namespace std;

//{{{
#define all(x) (x).begin(),(x).end()
#define REP(i,a,b) for(int i=(int)(a); i<(int)(b); i++)
#define RREP(i,a,b) for(int i=(int)(a); i>=b; i--)
#define rep(i,n) REP(i,0,n)
#define rrep(i,n) RREP(i,n,0)
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pii> vp;

#define dump(x) (cerr << #x << "=" << x << endl)
template<class T> ostream& osContainer(ostream& os,T c) { os<<'[';for(decltype(c.begin()) it=c.begin();it!=c.end();it++)os<<*it<<',';os<<']';return os; }
template<class T> ostream& operator<<(ostream& os,const vector<T>& v) { return osContainer(os,v); }
template<class T> ostream& operator<<(ostream& os,const set<T>& s) { return osContainer(os,s); }
template<class T> ostream& operator<<(ostream& os,const multiset<T>& s) { return osContainer(os,s); }
template<class T,class S> ostream& operator<<(ostream& os,const map<T,S>& m) { return osContainer(os,m); }
template<class T,class S> ostream& operator<<(ostream& os,const multimap<T,S>& m) { return osContainer(os,m); }
template<class T1,class T2>
ostream& operator<<(ostream& os, const pair<T1,T2>& p){ os << '(' << p.first << ',' << p.second << ')'; return os; }

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

const int Y = 1000;
const int Y1 = 20 * 10;
const int Y2 = 20 * 5 + 19 * 5;

void solve()
{
    int n;
    cin >> n;

    rep(i, n) {
        int y, m, d;
        cin >> y >> m >> d;

        int cnt = 1;
        if (y % 3) {
            cnt += (m & 1 ? 20 : 19) - d;
        } else {
            cnt += 20 - d;
        }

        REP(j, m + 1, 10 + 1) {
            if (y % 3) {
                cnt += (j & 1 ? 20 : 19);
            } else {
                cnt += 20;
            }
        }

        REP(j, y + 1, Y) {
            if (j % 3) {
                cnt += Y2;
            } else {
                cnt += Y1;
            }
        }

        cout << cnt << endl;
    }
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(12);
    solve();
}

Measured memory_bytes: 3104
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Scanner;

public class Main {

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

  static void resolve(InputStream is, PrintStream pw) {
    Scanner sc = new Scanner(is);
    int n = Integer.parseInt(sc.next());
    int[] a = new int[n];
    int[] ans = new int[n];
    for (int i = 0; i < n; i++) {
      a[i] = Integer.parseInt(sc.next());
    }

    int m = 0;
    for (int i = n; i > 0; i--) {
      int an = a[i - 1];
      int multiplesCount = 0;
      int sum = 0;
      for (int j = 1; i * j <= n; j++) {
        multiplesCount++;
        sum += ans[i * j - 1];
      }
      if (multiplesCount == 1) {
        ans[i - 1] = an;
        if (ans[i - 1] == 1) {
          m++;
        }
        continue;
      }
      int remain = sum % 2;
      if (remain == an) {
        // OK
        if (ans[i - 1] == 1) {
          m++;
        }
        continue;
      }
      ans[i - 1] = (ans[i - 1] + 1) % 2;
      if (ans[i - 1] == 1) {
        m++;
      }
    }

    pw.println(m);
    if (m == 0) {
      return;
    }
    boolean first = true;
    for (int i = 0; i < n; i++) {
      if (ans[i] == 1) {
        if (first) {
          pw.print(i + 1);
          first = false;
        } else {
          pw.print(" " + (i + 1));
        }
      }
    }
  }
}


Measured memory_bytes: 59516
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
#define fi first
#define se second
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define repn(i,n) for(ll i=0;i<=(ll)(n);i++)
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
const ll mod = 1000000007;
const ll INF = 1000000099;
vector<ll> dx={-1,1,0,0},dy={0,0,-1,1};
//cin.tie(0);
//ios::sync_with_stdio(false);



signed main(){
    string s;cin>>s;
    ll n=siz(s);
    vector<ll> ans(n,0);

    for(int i=0;i < n;i++)
    {
        ll cnt=0,x=i+1;
        if(s[i]=='R' && s[i+1]=='L'){

            while(x<n && s[x]=='L'){
                cnt++;
                x++;
                if(cnt%2==0){
                    ans[i]+=1;
                }
                else ans[i+1]+=1;
            }
            cnt=0;
            x=i;
            while(0<=x && s[x]=='R'){
                cnt++;
                x--;
                if(cnt%2==0)ans[i+1]+=1;
                else ans[i]+=1;
            }
            i++;
        }
    }

    rep(i,n) cout<<ans[i]<<(i<n ? ' ' : '\n');


}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,b) for(int i=(a); i<(b); i++)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
typedef long long ll;
int main(){
    int m1, d1; cin >> m1 >> d1;
    int m2,d2; cin >> m2 >> d2;
    if(d2 == 1) cout << 1 << endl;
    else cout << 0 << endl;
}

Measured memory_bytes: 256
class SegmentTree:
    n=0
    node=[]

    def __init__(self, sz):
        self.n=1
        while self.n<sz: self.n *= 2
        self.node = [INF] * (2*self.n-1)

    def update(self, a, b, x=-1, k=0, l=0, r=-1):
        if r<0: r = self.n
        if r<=a or  b<=l: return
        if a<=l and r<=b: 
            if x>=0: self.node[k] = x
            return
        if self.node[k]!=INF:
            self.node[k*2+1] = self.node[k*2+2] = self.node[k]
        self.node[k] = INF
        self.update(a, b, x, 2*k+1, l, (l+r)//2)
        self.update(a, b, x, 2*k+2, (l+r)//2, r)

    
INF = 2**31-1
sz, q = map(int, input().split())
ruq = SegmentTree(sz)
for _ in range(q):
    c, *l = map(int, input().split())
    if c:
        ruq.update(l[0], l[0]+1)
        print(ruq.node[l[0]+ruq.n-1])
    else:
        s, t, x = l
        ruq.update(s, t+1, x)




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



M, W = map(int, input().split())                                # M: 品物の種類 W: 重量制限
single = True                                                   # True = 重複なし

price_list = [0]
weight_list = [0]
for _ in range(M):
    weight, price = map(int, input().split())
    price_list.append(price)
    weight_list.append(weight)


################################################################################################################################################

dp_min = 0                                                      # 総和価値の最小値

""" dp[item <= M ][weight <= W] = 重さ上限を固定した時の"最大"価値 """
dp = [[dp_min] * (W + 1) for _ in range(M + 1)]                 # 左端と上端の境界条件で W, M を一個ずつ多めに取る

""" 重さ 0 の時の境界条件 """
for item in range(M+1):
    dp[item][0] = 0                                             # 重さ 0 を実現するのに必要な品物の個数は 0 個

""" 品物 0 個の時の境界条件 """
# for weight in range(W+1):
#     dp[0][weight] = dp_min                                    # 0 種類の品物で実現できる重量は存在しない　（dpの初期化で自動的に課せる場合が多い）


for item in range(1,M+1):                                       # 境界条件を除いた M 回のループ（※ f[item] = g.f[item-i] の漸化式なので、list index out of range となる）
    for weight in range(1, W + 1):
        if weight < weight_list[item]:                          # weight (重量価値) < weight_list[item] (品物の重量) の時は無視してよい
            dp[item][weight] = dp[item - 1][weight]
        else:
            temp = dp[item - single][weight - weight_list[item]] + price_list[item]  # single = True: 重複なし
            if temp > dp[item-1][weight]:                       # max(dp[item-1][weight], temp)
                dp[item][weight] = temp
            else:
                dp[item][weight] = dp[item-1][weight]

print(dp[M][W])

Measured memory_bytes: 152564
#include<iostream>
using namespace std;
class QQ{
	public:
	QQ();
};
QQ::QQ(){
	for(int i=11;i<100;i++)
	if(i%10)cout<<i/10<<'x'<<i%10<<'='<<(i/10)*(i%10)<<endl;
}
int main(){
	QQ qq;
	return 0;
}

Measured memory_bytes: 1116
import java.util.*;

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

        Scanner sc = new Scanner(System.in);
        
        int N = sc.nextInt();
        int M = sc.nextInt();
        int[] a = new int[N];
        int[] b = new int[N];
        int[] c = new int[M];
        int[] d = new int[M];
        int[] ans = new int[N];
        
        for(int i = 0; i < N; i++){
            a[i] = sc.nextInt();
            b[i] = sc.nextInt();
            ans[i] = Integer.MAX_VALUE - 1;
        }
        for(int i = 0; i < M; i++){
            c[i] = sc.nextInt();
            d[i] = sc.nextInt();
        }
        
        for(int i = 0; i < N; i++){
            
            int temp = Integer.MAX_VALUE;
            for(int j = 0; j < M; j++){
                int min = Math.abs(a[i] - c[j]) + Math.abs(b[i] - d[j]);
                if(temp > min){
                    temp = min;
                    ans[i] = j + 1;
                }
            }
        }
        for(int i : ans) System.out.println(i);
    }
}


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

long double Pow(ll a, ll n) {
  if (n == 1) return a;
  if (n % 2 == 1) return (a * Pow(a, n-1));
  ll t = Pow(a, n/2);
  return t*t;
}

int main() {
  int N;
  cin >> N;
  vector<long double> v(N);
  for (int i = 0; i < N; i++) cin >> v[i];
  sort(v.begin(), v.end());
  reverse(v.begin(), v.end());
  long double ans = 0;
  for (int i = 0; i < N-1; i++) {
    long double div = Pow(2, i+1);
    long double tmp = v[i]/div;
    ans += tmp;
  }
  ans += v[N-1] / Pow(2, N-1);
  cout << ans << endl;
}


Measured memory_bytes: 3760
#include <bits/stdc++.h>
#define SORT(x) sort(x.begin(),x.end())
#define ALL(x) x.begin(),x.end()
#define rep(i, n) for(int i = 0; i < n; i++)
#define reps(i, m, n) for(int i = m; i < n; i++)
#define repr(i, m, n) for(int i = m; i >= n; i--)
#define INF 1000000007 //1000000000000000003
#define PI (acos(-1))
#define MOD 1000000007
using namespace std;
typedef long long ll;



void Main(){

  int N,K;
  cin >> N>>K;

  string S;
  cin>>S;

  int ct=0;
  rep(i,N-1){
    ct+= S[i]==S[i+1];
  }

  cout<< min(ct+2*K,N-1)<<"\n";

}


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


Measured memory_bytes: 512
#include<stdio.h>
#define MAX 500001

//H heap size
//MAX max size
int H, A[MAX];
void maxHeapify(int i) {
    int l, r, largest, tmp;
    l = 2*i;
    r = 2*i + 1;
    if (l <= H && A[l] > A[i]) largest = l;
    else largest = i;
    
    if (r <= H && A[r] > A[largest]) largest = r;
    
    if (largest != i) {
	tmp = A[i]; A[i] = A[largest]; A[largest] = tmp;
	maxHeapify(largest);
    }
}

void buildMaxHeap() {
    int i;
    for (i = H/2; i> 0; i--) maxHeapify(i);
}

void print() {
    int i;
    for (i = 1; i < H+1; i++) printf(" %d", A[i]);
    printf("\n");
}
	
int main() {
    int i;
    scanf("%d", &H);
    for (i =1; i < H+1; i++) scanf("%d", &A[i]);

    buildMaxHeap();

    print();
    
    return 0;
}

Measured memory_bytes: 2552
import java.util.Scanner;

public class Main {
	public static Scanner sc = new Scanner(System.in);
	public static void main(String[] args){
		//A
		/*
		int a = sc.nextInt();
		int b = sc.nextInt();
		if(a+b < 17 && a < 9 && b < 9)
			System.out.println("Yay!");
		else
			System.out.println(":(");
		*/
		//B
		/*
		int d = sc.nextInt();
		int n = sc.nextInt();
		if(n == 100)
			System.out.println((long) Math.pow(100,d)*n+1);
		else
			System.out.println((long)Math.pow(100,d)*n);
			*/
		//C
		int n = sc.nextInt();
		int [] a = new int[n];
		int counter  =0;
		for(int i = 0; i < n ; i++){
			a[i] = sc.nextInt();
		}
		for(int j  =0 ; j < n ; j++){
			int x  = 0;
			while(true){
				if(a[j] % 2 == 1)
					break;
				else{
					a[j]/=2;
					x++;
				}
			}
			counter += x;
		}
		System.out.println(counter);
		//D

	}
}


Measured memory_bytes: 33644
// 22:52~
#include <bits/stdc++.h>
using namespace std;

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

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

template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p){
	return os<<'('<<p.first<<','<<p.second<<')';
}

template<typename Tuple>
void print_tuple(ostream&,const Tuple&){}
template<typename Car,typename... Cdr,typename Tuple>
void print_tuple(ostream& os,const Tuple& t){
	print_tuple<Cdr...>(os,t);
	os<<(sizeof...(Cdr)?",":"")<<get<sizeof...(Cdr)>(t);
}
template<typename... Args>
ostream& operator<<(ostream& os,const tuple<Args...>& t){
	print_tuple<Args...>(os<<'(',t);
	return os<<')';
}

template<typename Ch,typename Tr,typename C>
basic_ostream<Ch,Tr>& operator<<(basic_ostream<Ch,Tr>& os,const C& c){
	os<<'[';
	for(auto i=begin(c);i!=end(c);++i)
		os<<(i==begin(c)?"":" ")<<*i;
	return os<<']';
}

constexpr int INF=1e9;
constexpr int MOD=1e9+7;
constexpr double EPS=1e-9;

bool solve(const vvi& a,const vector<pii>& ss,int i,int j,int si,int rest,vvi& vis)
{
	int n=a.size();
	if(i<0 || n<=i || j<0 || n<=j || vis[i][j]) return false;
	if(a[i][j]<0){
		if(ss[si]!=mp(i,j)) return false;
		vis[i][j]=-1-si;
		rep(k,4){
			int ni=i+"\xff\x1\0\0"[k],nj=j+"\0\0\xff\x1"[k];
			if(solve(a,ss,ni,nj,si,rest,vis)) return true;
		}
		vis[i][j]=0;
	}
	else{
		if(rest<a[i][j]) return false;
		vis[i][j]=-1-si;
		rest-=a[i][j];
		if(rest==0){
			si++;
			if(si==ss.size()) return true;
			int ni=ss[si].first,nj=ss[si].second;
			if(solve(a,ss,ni,nj,si,-a[ni][nj],vis)) return true;
		}
		else{
			rep(k,4){
				int ni=i+"\xff\x1\0\0"[k],nj=j+"\0\0\xff\x1"[k];
				if(solve(a,ss,ni,nj,si,rest,vis)) return true;
			}
		}
		vis[i][j]=0;
	}
	return false;
}

int main()
{
	for(int n;cin>>n && n;){
		vvi a(n,vi(n));
		rep(i,n) rep(j,n) cin>>a[i][j];
		
		int pos=0,neg=0;
		rep(i,n) rep(j,n) (a[i][j]>0?pos:neg)+=a[i][j];
		if(pos+neg){
			cout<<"NO"<<endl;
			continue;
		}
		
		vector<pii> ss;
		rep(i,n) rep(j,n) if(a[i][j]<0) ss.emplace_back(i,j);
		vvi vis(n,vi(n));
		int i=ss[0].first,j=ss[0].second;
		bool res=solve(a,ss,i,j,0,-a[i][j],vis);
		cout<<(res?"YES":"NO")<<endl;
	}
}

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

int main() {
    int n;
    cin >> n;
    string s;
    cin >> s;
    int cnt = 0;
    for(int i = 0; i < s.size() - 2; i++) {
        if(s[i] == 'A' && s[i + 1] == 'B' && s[i + 2] == 'C')
            cnt++;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
typedef long long LL;
typedef long double LD;
#define x first
#define y second
#define mp(a, b) make_pair(a, b)
#define read(a) scanf("%d", &a)

#define N 205

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

int main() {
	read(n);
	n *= 2;
	for (int i = 1; i <= n; i++) read(a[i]);
	sort(a + 1, a + n +1);
	int ans = 0;
	for (int i = 1; i <= n; i += 2) {
		ans += a[i];
	}
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using P = pair<int, int>;
#define debug(var) cerr << "[" << #var << "] " << var << endl
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
const ll mod = 1000000007;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,-1,0,1};


int main(){
    int a, b;
    cin >> a >> b;
    int ans = a*b;
    
    cout << ans << endl;
    return 0;
}


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

/* snippet: useful macros and functions */
#define ARC(i, a, b) for(Int i = (a); i < (b); ++i)
#define RC(i, n) ARC(i, 0, n)
#define ARCH(i, a, b) for(Int i = (a) - 1; i >= (b); --i)
#define RCH(i, n) ARCH(i, n, 0)
template<class T> T ant(const T &a, const T &b){ return a > b ? a : b; }
template<class T> T ont(const T &a, const T &b){ return a < b ? a : b; }
template<class T> T rng(const T &a, const T &b){ return a < b ? b - a : a - b; }
template<class T> void th(T &a, const T &b, T (*f)(const T &, const T &)){ a = f(a, b); }
#define anth(a, b) th(a, b, ant)
#define onth(a, b) th(a, b, ont)

/* snippet: modint library */
template<class T, int MOD>
class Modint{
	T val;
public:
	Modint(T val = 0) : val(val % MOD + (val > 0 ? 0 : MOD)) {}
	operator T(){ return val; }
	Modint &operator+=(const Modint &a){ val += a.val; if(val >= MOD) val -= MOD; return *this; }
	Modint &operator-=(const Modint &a){ val -= a.val; if(val < 0) val += MOD; return *this; }
	Modint &operator*=(const Modint &a){ val = val * a.val % MOD; return *this; }
	void inverse(){T x[2]={MOD,val},a[2]={0,1};int i;for(i=0;x[!i];i^=1){a[i]-=x[i]/x[!i]*a[!i];x[i]=x[i]%x[!i];}if(!i)a[i]+= MOD;val=a[i];}
	Modint &operator/=(Modint a){ a.inverse(); return *this *= a; }
	friend Modint modpow(Modint a, int n){ Modint ret(1); while(n){ if(n & 1) ret *= a; a *= a; n >>= 1; } return ret; }
	friend Modint operator+(Modint a, const Modint &b){ return a += b; }
	friend Modint operator-(Modint a, const Modint &b){ return a -= b; }
	friend Modint operator*(Modint a, const Modint &b){ return a *= b; }
	friend Modint operator/(Modint a, const Modint &b){ return a /= b; }
	friend std::ostream &operator<<(std::ostream &os, const Modint &a){ return os << a.val; }
};

/* snippet: using declarations */
using Int = long long;
using std::cout;
using std::cin;
using std::endl;
using Mint = Modint<long long, 1000000007>;

int main(){
	Int a, b, n;
	cin >> a >> b >> n;
	Int x;
	if(n < b - 1){
		x = n;
	}else{
		x = b - 1;
	}
	cout << x * a / b - x / b * a << endl;
}


Measured memory_bytes: 3636
#include<cstdio>
#include<algorithm>
const long long mod = 1e9+7;
int row[1000005], col[1000005];
long long sumr[1000005], sumc[1000005];

int preWork(int n,int m){
	sumr[n*m+1] = sumc[n*m+1] = 0;
	for(int i = n*m; i >= 1; i--){
		if(row[i]>1) return 0;
		else sumr[i] = sumr[i+1]+row[i];
	}
	for(int i = n*m; i >= 1; i--){
		if(col[i]>1) return 0;
		else sumc[i] = sumc[i+1]+col[i];
	}
	return 1;
}

int main(){
	int n,m;
	scanf("%d%d",&n,&m);
	for(int i = 1; i <= n; i++){ 
		int u;
		scanf("%d",&u);
		row[u]++;
	}
	for(int i = 1; i <= m; i++){ 
		int u;
		scanf("%d",&u);
		col[u]++;
	}
	if(preWork(n,m)==0) printf("0\n");
	else{
		long long ans = 1;
		for(long long i = n*m; i >= 1; i--){
			if(row[i] && col[i]) ans *= 1;
			else{
				if(row[i]){
					long long mul = sumc[i+1];
					ans = ans*mul%mod;
				}
				else if(col[i]){
					long long mul = sumr[i+1];
					ans = ans*mul%mod;
				}
				else{
					long long used = n*m-i;
					long long have = sumr[i+1]*sumc[i+1]-used;
					if(have<=0){
						ans = 0;
						break;
					}
					else ans = ans*have%mod;
				}
			}
		}
		printf("%lld\n",ans);
	}
	return 0;
}


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

using namespace std;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
//#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) ll(x.size())
typedef long long ll;
//typedef pair<int, int> P;
typedef pair<ll, ll> P;
//const double INF = 1e10;
const ll INF = 10e10;
const ll MINF = -10e10;
//const int INF = INT_MAX;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)

typedef priority_queue<P, vector<P>, greater<P>> PQ_ASK;
const int mod = 1000000007;

//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);



int main() {
    string s;
    cin >> s;

    int ans = 700;
    for (int i = 0; i < 3; i++) {
        if (s[i] == 'o') {
            ans += 100;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
        using namespace std;
        #define ll long long int
        #define pb push_back
        #define mk make_pair
        #define ft first
        #define sc second
        #define ppb pop_back
        #define sz size
        #define forn(i,a,n) for(i=a;i<n;i++)
        #define M 998244353 
        #define inf 2e18
        
        int main() {
 
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        cout.tie(NULL);
        
        ll x,y,z;
        cin>>x>>y>>z;
        swap(x,y);
        swap(x,z);
        cout<<x<<" "<<y<<" "<<z;

        return 0;
    }

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <climits>
#include <cmath>
#include <complex>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <iomanip>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <cstdint>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
#define MP make_pair
#define PB push_back
#define inf 1000000007
#define rep(i,n) for(int i = 0; i < (int)(n); ++i)
#define all(x) (x).begin(),(x).end()

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}
 
template<class T> inline bool chmax(T &a, T b){
    if(a<b){
        a = b;
        return true;
    }
    return false;
}

template<class T> inline bool chmin(T &a, T b){
    if(a>b){
        a = b;
        return true;
    }
    return false;
}
int comb(int n,int k){
    while(n!=0){
        if(n%2<k%2)return 0;
        n/=2;
        k/=2;    
    }
    return 1;
}
int main(){
    int n;
    string s;
    cin >> n >> s;
    int k = 0;
    rep(i,n){
        k += (s[i]-'0')*comb(n-1,i);
    }
    if(k%2==1){
        cout << 1 << endl;
        return 0;
    }
    vector<int>a(n-1);
    rep(i,n-1){
        a[i] = abs(s[i]-s[i+1]);
    }
    bool flag = 0;
    rep(i,n-1){
        if(a[i]==1){
            flag = 1;
        }
    }
    if(flag){
        cout << 0 << endl;
    }else{
        rep(i,n-1)a[i] /= 2;
        int z = 0;
        rep(i,n-1){
            z += a[i]*comb(n-2,i); 
        }
        if(z%2==0){
            cout << 0 << endl;
        }else{
            cout << 2 << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 7724
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); i++)
using ll = long long;
 
int main(){
  int n;
  cin >> n;
  vector<ll> a(n), b(n);
  rep(i, n){
    cin >> a[i] >> b[i];
  }
  
  sort(a.begin(), a.end());
  sort(b.begin(), b.end());
  
  ll ans = 0;
  ll left, right;
  if(n%2==1){
    left = a[n/2]; right = b[n/2];
    ans = right - left + 1;
    if(ans < 0) ans == 0;
  }
  if(n%2==0){
    left = a[n/2-1]+a[n/2]; right = b[n/2-1] + b[n/2];
    ans = right - left + 1;
    if(ans < 0) ans == 0;
  }
    
  cout << ans << endl;  
  
	return 0;
}


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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}

vector<ll> G[205];
vector<ll> mark(205, -1);

bool is_bipartite(ll now, ll now_mark){
	if(mark[now]!=-1) return (mark[now]==now_mark);
	mark[now] = now_mark;
	bool flag = true;
	REP(i, G[now].size()){
		ll next = G[now][i];
		flag &= is_bipartite(next, 1-now_mark);
	}
	return flag;
}

ll N;

ll adj[205][205];
ll dist[205][205];
const ll INFLL = LLONG_MAX/3;

void WarhshallFloyd(){
	ll V = N;
	REP(i, N){
		REP(j, N){
			if(i==j) dist[i][j] = 0;
			else if(adj[i][j] == 1) dist[i][j] = 1;
			else dist[i][j] = INFLL;
		}
	}

	for(int k=0;k<V;k++){
		for(int i=0;i<V;i++){
			for(int j=0;j<V;j++){
				dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
			}
		}
	}
	return;
}

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

    REP(i, N){
    	string s;
    	cin >> s;
    	REP(j, N){
    		adj[i][j] = (s[j] - '0');
    	}
    }

    REP(i, N){
    	REP(j, N){
    		if(adj[i][j] == 1){
    			G[i].push_back(j);
    		}
    	}
    }

    bool bip = is_bipartite(0, 1);
    WarhshallFloyd();
    ll ma = -1;
    REP(i, N){
    	REP(j, N){
    		if(dist[i][j]<INFLL/2) ma = max(ma, dist[i][j]);
    	}
    }

    if(bip){
    	/*
    	REP(i, N) cout << mark[i] << " ";
    	cout << endl;
    	*/
    	cout << ma+1 << endl;
    }else{
    	cout << -1 << endl;
    }

    
    return 0;
}

Measured memory_bytes: 1280
import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline

n, x, m = map(int, input().split())

ans = 0

aa = x
ans += aa
aset = set([aa])
alist = [aa]

for i in range(1,n):
    aa = pow(aa,2,m)
    if aa in aset:
        offset = alist.index(aa)
        loop = alist[offset:i]
        nloop, tail = divmod(n-offset, len(loop))
        ans += sum(loop)*(nloop-1)
        ans += sum(loop[0:tail])
        break
    else:
        ans += aa
        aset.add(aa)
        alist.append(aa)

print(ans)



Measured memory_bytes: 76956
#include <iostream>

using namespace std;

int main(){
    int N;
    cin >> N;
    int A[N];
    int B[N];
    int C[N-1];
    int i;
    for(i=0; i<N; i++){
        cin >> A[i];
    }
    for(i=0; i<N; i++){
        cin >> B[i];
    }
    for(i=0; i<N-1; i++){
        cin >> C[i];
    }

    int ans=0;
    for(i=0; i<N; i++){
        ans+=B[i];
    }
    
    for(i=1; i<N; i++){
        if(A[i]-1==A[i-1]){
            ans+=C[A[i-1]-1];
        }
    }
    
    cout << ans<< endl;
    return 0;
}

Measured memory_bytes: 256
#N = int(input())
#L = list(map(int, input().split()))
import math
import sys

NK = list(map(int, input().split()))
RSP = list(map(int, input().split()))
T = input()
ansrr =[0]*NK[0]
for i in range(NK[1]):
    if T[i]=="r":
        ansrr[i] += RSP[2]
    elif T[i] == "p":
        ansrr[i] += RSP[1]
    else:
        ansrr[i] += RSP[0]

for i in range(NK[1],NK[0]):
    if T[i] == T[i-NK[1]]:
        if ansrr[i-NK[1]] == 0:
            if T[i] == "r":
                ansrr[i] += RSP[2]
            elif T[i] == "p":
                ansrr[i] += RSP[1]
            else:
                ansrr[i] += RSP[0]
        else:
            ansrr[i]=0
    else:
        if T[i] == "r":
            ansrr[i] += RSP[2]
        elif T[i] == "p":
            ansrr[i] += RSP[1]
        else:
            ansrr[i] += RSP[0]
#a = list(map(int, input().split()))
ans = 0
for i in range(NK[0]):
    ans += ansrr[i]
print(ans)


Measured memory_bytes: 7156
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;

ll dp[3001][3001];
string s,t;

vector<char> v;

ll lcs(ll n,ll m)
{
    if(n==0||m==0)
    {
        return 0;
    }
    else if(dp[n][m]!=-1)
    {
        return dp[n][m];
    }
    else
    {
        if(s[n-1]==t[m-1])
        {
            v.push_back(s[n-1]);
            dp[n][m]=1+lcs(n-1,m-1);return dp[n][m];
            
        }
        else
        {
            dp[n][m]=max(lcs(n,m-1),lcs(n-1,m));
            return dp[n][m];
        }
    }
    
}



int main() 
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    cin>>s>>t;
    memset(dp,-1,sizeof(dp));
    
    ll ans=lcs(s.size(),t.size());
    char haha[ans+1];
    haha[ans]='\0';
    ll k=ans-1;
      
    ll n=s.size(); ll m=t.size();
    
        while(n>0&&m>0)
        {
            if(s[n-1]==t[m-1])
            {
                haha[k]=s[n-1];
                n--;m--;k--;
            }
            else
            {
                if(dp[n-1][m]>=dp[n][m-1])
                {
                    n=n-1;
                }
                else
                {
                    m=m-1;
                }
            }
    
        }
        
        for(ll i=0;i<ans;i++)
        {
            cout<<haha[i];
        }

}








Measured memory_bytes: 75504
#include <iostream>
#include <climits>
#include <set>
#include <string>
#include <algorithm>
#include <vector>
#define MAX 1000000007

using namespace std;
#define ll long long
#define dbg if(0)
#define ISRANGE(val,lo,hi) ((lo<=val)&&(val<hi))




int main(){
    ll k,a,b,ans=1;
    cin >>k>>a>>b;

    if (a+2<b&&k>a){
        k-=(a-1);//交換
        ans=(k%2==0)?(b-a)*(k/2)+a:(b-a)*((k)/2)+a+1;
    }else{
        ans=1+k;
    }

    /*if((n+1)/2>=k)cout <<"YES"<<endl;
    else cout <<"NO"<<endl;*/

    cout <<ans<<endl;

    return 0;
}


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

int main() {
	//string s[100], res = "";
	//int N, M;
	//int a[60], b[60], res[60] = { 0 };
	//string S;
	int N, X;
	int m[110];

	cin >> N >> X;

	//int y = 700;
	for (int i = 0; i < N; ++i) {
		cin >> m[i];
	}
	for (int i = 0; i < N; ++i) {
		X -= m[i];
	}
	sort(m, m + N);
	int res = N;
	res += X / m[0];
	cout << res << endl;
	return 0;

}


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

int main() {
  string a, b, c;
  cin >> a >> b >> c;
  if (a.at(a.size()-1) == b.at(0) && b.at(b.size() -1) == c.at(0)) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
}

Measured memory_bytes: 3608