akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<algorithm>
using namespace std;
struct point{
    int x, y;
    bool operator<(const point &p)const{
        return x!=p.x?x<p.x:y<p.y;
    }
}w[110];
char p[10][10];
int n, m, cnt;
int main(){
    int i,j;
    scanf("%d%d",&n,&m);
    for(i=1;i<=n;i++){
        scanf("%s",p[i]+1);
        for(j=1;j<=m;j++){
            if(p[i][j]=='#'){
                w[cnt].x=i,w[cnt].y=j,cnt++;
            }
        }
    }
    sort(w,w+cnt);
    for(i=0;i<cnt-1;i++){
        if(w[i].y > w[i+1].y){
            printf("Impossible\n");
            return 0;
        }
    }
    printf("Possible\n");
    return 0;
}


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

int main() {
  int r, g, b;
  cin >> r >> g >> b;
  int num = r * 100 + g * 10 + b;
  if (num % 4 == 0) cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC optimize("unroll-loops")
#include"bits/stdc++.h"
using namespace std;
vector<bool> vis;
vector<vector<int>>g;
int n,m,u,v;
void dfs(int node)
{
	vis[node]=1;
	for(auto i:g[node])
	{
		if(!vis[i])
		{
			dfs(i);
		}
	}
}
int32_t main()
{
	
	cin>>n>>m;
	vis=vector<bool>(n);
	g=vector<vector<int>>(n);
	int z;
	for(int i=0;i<m;i++)
	{
		cin>>u>>v>>z;
		u--;v--;
		g[u].push_back(v);
		g[v].push_back(u);
		
	}
	int ans=0;
	for(int i=0;i<n;i++)
	{
		if(!vis[i]){ans++;dfs(i);}
	}
	
	cout<<ans;
	
	
	
}

Measured memory_bytes: 13480
#include<stdio.h>
int main(void) {
	int a, h, m, s;
	scanf("%d", &a);
	h = a / 3600;
	m = a % 3600 / 60;
	s = a % 3600 % 60;
	printf("%d:%d:%d\n", h, m, s);
	return 0;
}

Measured memory_bytes: 592
function Main(input) {
  input.trim();
  input = input.split("\n");
 input.shift();
 input.reverse();
 var arr = {};
 var ruiseki=0;
 for(var i=1;i<input.length;i++){
   var mem = input[i].split(" ");
   mem[1]-=0
   arr[mem[0]] = ruiseki;
      ruiseki += mem[1]
 }
 console.log( arr[input[0]] )
}Main(require("fs").readFileSync("/dev/stdin", "utf8").trim());
function arr1dto2d (arr){
	for(var i=0;i<arr.length;i++){
    arr[i]=arr[i].split("");
    }
  return arr;
}

Measured memory_bytes: 7372
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,A;
  cin>>N;
  int s,i,j,x;
  x=201;
  for(i=0;i<N;i++){
    cin>>A;
    s=0;
    for(j=A;j>0;j/=2){
      if(j%2!=0){
        break;
      }
      else{
        s++;
      }
    }
    if(x>=s){
      x=s;
    }
    else{
      continue;
    }
  }
  cout<<x<<endl;
}


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

int main(){
	string s;
	cin>>s;
	bool playable = true;
	for(int i=0; s[i]; i++){
		if((i+1)%2 && s[i]=='L'){
			playable = false;
			break;
		}
		else if((i+1)%2==0 && s[i] == 'R'){
			playable = false;
			break;
		}
	}
	if(!playable) cout<<"No";
	else cout<<"Yes";
}

Measured memory_bytes: 3632
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
    int a,b,c,d;
    cin >> a >> b >> c >> d;

    if( abs(a - c) <= d ){
        cout << "Yes\n";
        return 0;
    }
    else if( abs(a - b) <= d && abs(b - c) <= d ){
        cout << "Yes\n";
        return 0;

    }
        cout<< "No\n";
    return 0;
}

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

using namespace std;

struct data_t{
	int x;
	int y;
	int t;
	bool operator<( const data_t& right) const {
		return ( t == right.t ) || ( t < right.t );
	}
};

int main(void) {
	int N;
	cin >> N;
	vector<data_t> data(N);
	for (int i = 0; i < N; ++i) {
		cin >> data[i].t >> data[i].x >> data[i].y;
	}
	sort(data.begin(),data.end());

	bool trip = true;
	int xn,yn,tn;
	xn = yn = tn = 0;
	for (int i = 0; trip && i < N; ++i) {
		int cm = data[i].t - tn;
		int rm = (abs(data[i].x-xn)) + (abs(data[i].y-yn));
		if (cm < rm || (cm-rm)%2 == 1) {
			trip = false;
		}
		else {
			xn = data[i].x;
			yn = data[i].y;
			tn = data[i].t;
		}
	}

	if (trip) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

	return 0;
}


Measured memory_bytes: 1408
#include <cstdio>
#include <string>
#include <cstring>
#include <algorithm>
#include <iostream>

using namespace std;

int a,b;

int main(void) {
	cin >> a >> b;
	if((a * b) & 1) puts("Odd");
	else puts("Even");
	return 0;
} 

Measured memory_bytes: 384
#![allow(non_snake_case)]

use std::io::{stdin, Read};
use std::str::FromStr;
fn read_option<T: FromStr>() -> Option<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()
}
fn read<T: FromStr>() -> T {
    let opt = read_option();
    opt.expect("failed to parse token")
}

fn main() {
    let X: i64 = read();
    let K: i64 = read();
    let D: i64 = read();
    let X = if X < 0 { -X } else { X };
    let rem = X % D;
    let div = X / D;
    if div > K {
        println!("{}", X - K * D);
        return;
    }
    if div % 2 == K % 2 {
        println!("{}", rem);
    } else {
        println!("{}", D - rem);
    }
}


Measured memory_bytes: 2176
from collections import defaultdict, deque

def main():
    N = int(input())
    S = input()
    ans = 0
    for i in range(10):
        for j in range(10):
            for k in range(10):
                a = 0
                password = str(i) + str(j) + str(k)
                for s in S:
                    if s == password[a]:
                        a += 1
                    if a == 3:
                        ans += 1
                        break

    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 41308
#include <bits/stdc++.h>
// #include <atcoder/all>
using namespace std;
// using namespace atcoder;
typedef long long ll;
/* clang-format off */
#define MOD 1000000007
#define INF 1000000000000000000ll
#define REP(i, n) for (ll i = 0, i##_len = (n); i < i##_len; ++i)
#define ALL(a) (a).begin(), (a).end()
//#define __DEBUG__
#ifdef __DEBUG__
#define CH_P(a) cout <<"check_point("<<#a<<")" << "\n";
#define DEBUG(x) cout<<#x<<":"<<x<<"\n"
#define DEBUGS(v) cout << #v << ":";for(auto x:v){cout<<x<<" ";}cout<<"\n"
#endif
#ifndef __DEBUG__
#define CH_P(a) 
#define DEBUG(x) 
#define DEBUGS(v) 
#endif
/* clang-format on */

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n, m;
  cin >> n >> m;
  vector<ll> a(n), b(n), ans(n), c(m), d(m);
  REP(i, n) { cin >> a[i] >> b[i]; }
  REP(i, m) { cin >> c[i] >> d[i]; }
  REP(i, n) {
    ll dist = INF;
    REP(j, m) {
      if (dist > abs(a[i] - c[j]) + abs(b[i] - d[j])) {
        dist = abs(a[i] - c[j]) + abs(b[i] - d[j]);
        ans[i] = j;
      }
    }
  }
  REP(i, n) { cout << ans[i]+1 << endl; }
  return 0;
}


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

const int MOD=1000000007;
//~ const int MOD=998244353;
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;

string s[10];
int main(){
	int h,w,K;cin>>h>>w>>K;
	rep(i,h)cin>>s[i];
	int ans=0;
	rep(i,1<<h)rep(j,1<<w){
		int cnt=0;
		rep(k,h)rep(t,w){
			if(s[k][t]=='#'&&!(i>>k&1)&&!(j>>t&1)){
				cnt++;
			}
		}
		if(cnt==K)ans++;
	}
	cout<<ans<<endl;
}

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

int main()
{
 int a,b;
 int count;
 int wa;
 while(cin >> a&&cin >> b){
  count = 1;
  wa = a + b;
  while((wa/=10) != 0){
   count++;
  }
  cout << count << endl;
 }
 return 0;
}

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

typedef pair<int, int> pii;

#define fi first
#define se second

const int MAXN = 1 << 14;
const int MAXX = 1e9 + 5;

pii f[2 * MAXN];
int p[MAXN][2];
vector<int> ed[8 * MAXN], edinv[8 * MAXN];
int scc[8 * MAXN], dfsv[8 * MAXN], dfsvn;
bool chk[8 * MAXN];
int ppp;

void mkedge(int x, int y) {		// x -> y
	//printf("mkedge(%d, %d)\n", x, y);
	ed[x].push_back(y);
	ed[(y + 4 * MAXN) % (8 * MAXN)].push_back((x + 4 * MAXN) % (8 * MAXN));
	edinv[y].push_back(x);
	edinv[(x + 4 * MAXN) % (8 * MAXN)].push_back((y + 4 * MAXN) % (8 * MAXN));
}

void con(int idx, int l, int r, int x, int p, int q) {
	//if(idx == 1) printf("con(x = %d, p = %d, q = %d)\n", x, p, q);
	if(p <= l && r <= q) {
		mkedge(x + 2 * MAXN, idx + 4 * MAXN);
	}
	else if(l <= q && p <= r) {
		int m = (l + r) / 2;
		con(idx * 2, l, m, x, p, q);
		con(idx * 2 + 1, m + 1, r, x, p, q);
	}
}

void mkdfsv(int x) {
	chk[x] = true;
	for(auto a : ed[x]) if(!chk[a]) mkdfsv(a);
	dfsv[dfsvn++] = x;
}

void mkscc(int x, int s) {
	scc[x] = s;
	for(auto a : edinv[x]) if(scc[a] == -1) mkscc(a, s);
}

int main() {
	int N;

	cin >> N;
	for(int i = 0; i < N; i++) cin >> f[2 * i].fi >> f[2 * i + 1].fi;

	for(int i = 0; i < 2 * N; i++) f[i].se = i / 2;
	sort(f, f + 2 * N);
	for(int i = 0; i < N; i++) p[i][0] = -1;
	for(int i = 0; i < 2 * N; i++) {
		if(p[f[i].se][0] == -1) p[f[i].se][0] = i;
		else p[f[i].se][1] = i;
	}

	//for(int i = 0; i < N; i++) printf("%d %d\n", p[i][0], p[i][1]);

	int s = 0, e = MAXX;
	while(s < e) {
		//if(++ppp < 100) printf("s = %d, e = %d\n", s, e);
		for(int i = 0; i < 8 * MAXN; i++) {
			ed[i].clear();
			edinv[i].clear();
			scc[i] = -1;
			chk[i] = false;
		}
		dfsvn = 0;

		for(int i = 0; i < N; i++) {
			mkedge(p[i][0] + 2 * MAXN, p[i][1] + 6 * MAXN);
			mkedge(p[i][1] + 6 * MAXN, p[i][0] + 2 * MAXN);
		}
		for(int i = 2; i < 4 * MAXN; i++) mkedge(i, i / 2);
		int m = (s + e + 1) / 2;
		int x = 0, y = 0;
		for(int i = 0; i < 2 * N; i++) {
			while(f[x].fi <= f[i].fi - m) x++;
			con(1, 0, 2 * MAXN - 1, i, x, i - 1);
			while(y < 2 * N && f[y].fi < f[i].fi + m) y++;
			con(1, 0, 2 * MAXN - 1, i, i + 1, y - 1);
		}
		/*
		for(int i = 0; i < 8 * MAXN; i++) {
			printf("ed[%d] = [", i);
			for(auto a : ed[i]) printf("%d ", a);
			printf("]\n");
		}
		*/
		for(int i = 0; i < 8 * MAXN; i++) if(!chk[i]) mkdfsv(i);
		for(int i = 8 * MAXN - 1; i >= 0; i--) if(scc[dfsv[i]] == -1) mkscc(dfsv[i], i);
		//for(int i = 0; i < 8 * MAXN; i++) printf("scc[%d] = %d\n", i, scc[i]);
		bool b = true;
		for(int i = 0; i < 4 * MAXN; i++) if(scc[i] == scc[i + 4 * MAXN]) b = false;
		if(b) s = m;
		else e = m - 1;
	}

	cout << s;
	return 0;
}


Measured memory_bytes: 39424
program sample
	implicit none
    integer :: A,B,C
    
    read(*,*) A,B,C
    
    if (A==B .or. A==C .or. B==C) then
    	if (A==B .and. B==C) then
    		write(*,*) 'No'
        else
        	write(*,*) 'Yes'
        end if
    else 
    	write(*,*) 'No'
    end if
    
    stop
end program sample


Measured memory_bytes: 2860
n = int(input())
list_a=list(map(int, input().split()))  #リスト入力
list_b=list(map(int, input().split()))  #リスト入力
count = 0
list_b.append(0)
yuu_amari = 0
for i in range(n):
    if list_a[i] > yuu_amari:
        mon_now = list_a[i] - yuu_amari
    else:
        mon_now = 0
    yuu_now = list_b[i]
    count += min(mon_now, yuu_now)
    
    if yuu_now - mon_now > 0:
        yuu_amari = yuu_now - mon_now
        count += min(list_a[i+1], yuu_amari)
    else :
        yuu_amari = 0
print(count)
   


Measured memory_bytes: 19156
#include<stdio.h>
#include<iostream>
#include<math.h>
#include<string>
#include<vector>
#include<map>
#include<queue>
#include<cmath>
#include <algorithm>
using namespace std;
using ll = long long;

typedef pair<int,int> P;
 
int main(void){
    double D,T,S;
    double time;
    cin >> D>>T>>S;
    time=(double)D/S;
    if(T>=time){
        cout <<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
}

Measured memory_bytes: 3736
#include <bits/stdc++.h>
#define N 1001000
#define inf 0x3f3f3f3f
#define LL long long
#define pi acos(-1)
#define MOD 1000000007
using namespace std;

LL a[N];
int n;

int main()
{
	//freopen("dark.in","r",stdin);
	//freopen("dark.out","w",stdout);
	scanf("%d",&n);
	for (int i = 1; i <= n; ++i) scanf("%lld",&a[i]);
	LL m1 = a[1],mi = 1;
	for (int i = 2; i <= n; ++i) if (a[i]>m1) {m1 = a[i];mi = i;}
	LL m2;
	if (mi==1) m2 = a[2];else m2 = a[1];
	for (int i = 1; i <= n; ++i) if (mi!=i) m2 = max(m2,a[i]);
	for (int i = 1; i <= n; ++i) if (mi==i) printf("%lld\n",m2); else printf("%lld\n",m1);
	return 0;
}


Measured memory_bytes: 3200
import java.util.Scanner;
public class Main{
        public static void main(String[] args){
            Scanner sc = new Scanner(System.in);
            int x = sc.nextInt();
            int y = sc.nextInt();
            int area = x*y;
            int length = 2*x + 2*y;
            System.out.println(area + " " + length);
            sc.close();
        }
}


Measured memory_bytes: 26084
#include <bits/stdc++.h>
typedef long long ll;
#define pb push_back
using namespace std;
const int mx = 100000;
const int mod = 1e9 + 7;
ll dp[mx + 5][2];
vector <int> vec[mx + 5];
void dfs(int a, int p) {
	dp[a][0] = dp[a][1] = 1;
	for (int b : vec[a]) {
		if (b != p) {
			dfs(b, a);
			ll white = dp[b][0] + dp[b][1];
			white %= mod;
			ll black = dp[b][0];
			dp[a][0] *= white;
			dp[a][1] *= black;
			dp[a][0] %= mod;
			dp[a][1] %= mod;
		}
	}
}

int main() {
	ios_base :: sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int n;
	cin >> n;
	for (int i = 1; i < n; ++i) {
		int a, b;
		cin >> a >> b;
		vec[a].pb(b);
		vec[b].pb(a);
	}
	dfs(1, -1);
	cout << (dp[1][0] + dp[1][1]) % mod << endl;
}

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

int main() {
    int n;
    cin >> n;
    int a[n];
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    int m = 0;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            m = max(m, abs(a[i]-a[j]));
        }
    }
    cout << m << endl;
    return 0;
}

Measured memory_bytes: 256
A, B = list(map(int, input().split(" ")))
hand = [2,3,4,5,6,7,8,9,10,11,12,13,1]

if hand.index(A) > hand.index(B):
    print("Alice")
elif hand.index(A) == hand.index(B):
    print("Draw")
else:
    print("Bob")

Measured memory_bytes: 3060
n = int(input())
d = [list(map(lambda x: int(x), input().split())) for i in range(n)]
a = 0
f = 0
for [x, y] in d:
    if x == y:
        a += 1
        if a >= 3:
            f = 1
    else:
        if a >= 3:
            f = 1
        a = 0
if f:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 9112
#include <iostream>
#include <algorithm>
#include <string>

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

    std::string s, p;
    std::cin >> s >> p;
    size_t sSize = s.size();
    s+=s;
    for(size_t i=0; i<sSize; ++i){
        if(s.substr(i, p.size())==p){
            std::cout << "Yes\n";
            return 0;
        }
    }
    std::cout << "No\n";
    return 0;
}

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

using ll = long long;
using pii = pair<int, int>;

#define     endl               "\n"
#define     fast_io            ios::sync_with_stdio(false); cin.tie(0);
#define     file_io            freopen("input.txt", "r", stdin);   \
                               freopen("output.txt", "w", stdout);
#define     all(x)             begin(x), end(x)
#define     debug(x)           cerr <<"Line "<< __LINE__ <<" : "<< #x " = "<< x <<endl;
 
template<typename T, typename TT>
ostream& operator<<(ostream &os, const pair<T, TT> &t) { return os<<"("<<t.first<<", "<<t.second<<")"; }
template<typename T>
ostream& operator<<(ostream& os, const vector<T> &t) { for(auto& i: t) os<<i<<" "; return os; }
 



int main(int argc, char** argv) {
    fast_io
   
	int h, w;
	
	while(cin >> h >> w && (h || w)) {
		
	    for(int i = 0; i < h; ++i) {
	        for(int j = 0; j < w; ++j) cout << '#';
	        cout << endl;
	    }
	    cout << endl;
	}
	
	

    return 0;
}























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

using namespace std;
typedef long long ll;
#define tr(container, it) \
        for (auto it = container.begin(); it != container.end(); it++)
#define scontains(c, x) ((c).find(x) != (c).end())   //O(log n)
#define contains(c, x) (find((c).begin(),(c).end(),x) != (c).end()) //O(n)
#define ill(_x)  ll _x;scanf("%lld",&_x);
#define idb(_x)  double _x;scanf("%lf",&_x);i
#define all(x) (x).begin(),(x).end()
#define pll pair<ll,ll>
#define mll map<ll,ll>
#define vll vector<ll>
#define sll set<ll>
#define vs vector<string>
#define in0(x, a, b)((x)>=a && (x)<=b    )
#define in1(x, a, b)((x)>a && (x)<b)
#define  rep(i, begin, end) for (__typeof(end) i = (begin); i != (end); i += 1 - 2 * ((begin) > (end)))
const double pi = 3.14159265358979323846;
const int INF = 0x3f3f3f3f;
const int X10 = 1024, X11 = 2048, X12 = 4096, X13 = 8196, X14 = 16392, X15 = 32786, X16 = 65536, X17 = 131072, X18 = 262144, X19 = 524288, X20 = 1048576;

const int MOD = (int)(1e9+7);
template<typename T>
T read(){T x;cin >>x;return x;}

int A[26], B[26];
void _(){
    string s1, s2;
    cin >> s1 >> s2;
    for(auto c : s1)A[c-'a'] ++;
    for(auto c : s2)B[c-'a'] ++;
    sort(A, A+26);
    sort(B, B+26);
    for (int i = 0; i < 26; ++i) {
        if(A[i] != B[i]){
            cout << "No";return;
        }
    }
    cout <<"Yes";



}

int main() {
#ifdef Debug
    freopen("/home/hiroo/Desktop/competitive-programming/IO/Input.txt", "r", stdin);
    freopen("/home/hiroo/Desktop/competitive-programming/IO/Output.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    _();
    return 0;

}




Measured memory_bytes: 916
n=int(input())
P=[int(x) for x in input().split()]
count=0
for i in range(1,n-1):
    if (P[i]>P[i-1] and P[i]<P[i+1]) or (P[i]<P[i-1] and P[i]>P[i+1]):
        count=count+1
print(count)


Measured memory_bytes: 3060
def main():
    n = int(input())

    min_t = 100000
    for i in range(n+1):
        x, six = i, 0
        while x > 0:
            six += x % 6
            x //= 6

        y, nine = n - i, 0
        while y > 0:
            nine += y % 9
            y //= 9

        if six + nine < min_t:
            min_t = six + nine

    print(min_t)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include<bits/stdc++.h>
const int N=3005;
int n,mo,i,j,k,s[N][N],C[N][N],m1[N],m2[N],ans,x,y;
int main(){
	scanf("%d%d",&n,&mo);
	for(i=*m1=1,*m2=2;i<=n;++i)m1[i]=2*m1[i-1]%mo,m2[i]=1ll*m2[i-1]*m2[i-1]%mo;
	for(i=**C=1;i<=n;++i)for(j=*C[i]=1;j<=i;++j)C[i][j]=(C[i-1][j-1]+C[i-1][j])%mo;
	for(i=1,s[0][0]=1;i<=n;++i)for(s[i][1]=m1[i]-1,s[i][0]=1,j=2;j<=i;++j)
		s[i][j]=(s[i-1][j-1]+s[i-1][j]+1ll*s[i-1][j]*j)%mo;
	for(i=0;i<=n;++i){
		x=0;y=1;
		for(k=0;k<=i;++k)x=(x+1ll*s[i][k]*y)%mo,y=1ll*y*m1[n-i]%mo;
		ans=(ans+1ll*(i&1?mo-C[n][i]:C[n][i])*m2[n-i]%mo*x)%mo;
	}
	printf("%d\n",ans);
	return 0;
}

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

const int MOD = (int)1e9+7;

bool is_bipartite_graph(vector<vector<bool>> &graph){
	//bfsを使って2部グラフかどうかを判定する
	//入力のgraphはtrueなら辺がある、falseなら辺がない
	//入力されるgraphは連結無向グラフを前提としている!!
	//visitedで各頂点を1,-1に塗り分ける（隣接する頂点は必ず1,-1となるようにする）
	//それができないなら、2部グラフではない
	queue<int> V;
	vector<int> visited(graph.size(),0);
	V.push(0);
	visited.at(0)=1;

	while(!V.empty()){
		int v=V.front();
		V.pop();
		for(int i=0;i<graph.size();i++){
			if(!graph.at(v).at(i))  continue;
			if(visited.at(i)==0){
				if(visited.at(v)==1)	visited.at(i)=-1;
				else if(visited.at(v)==-1)	visited.at(i)=1;
				V.push(i);
			}
			else{
				if(visited.at(i)+visited.at(v)!=0){
					return false;
				}
			}
		}
	}
	return true;
}

int main(){
	int N;
	cin >> N;
	vector<string> S(N);
	for(int i=0;i<N;i++)	cin >> S.at(i);

	vector<vector<bool>> graph(N,vector<bool>(N,false));
	for(int i=0;i<N;i++){
		for(int j=0;j<N;j++){
			if(S.at(i).at(j)=='1')	graph.at(i).at(j)=graph.at(j).at(i)=true;
		}
	}

	if(!is_bipartite_graph(graph)){
		cout << -1 << endl;
		return 0;
	}

	int ans=0;
	vector<vector<int>> gg(N,vector<int>(N,1e9));
	for(int i=0;i<N;i++){
		for(int j=0;j<N;j++){
			if(S.at(i).at(j)=='1')	gg.at(i).at(j)=gg.at(j).at(i)=1;
		}
	}
	//warshall-floyd
	for(int k=0;k<N;k++){
		for(int i=0;i<N;i++){
			for(int j=0;j<N;j++){
				gg.at(i).at(j)=min(gg.at(i).at(j),gg.at(i).at(k)+gg.at(k).at(j));
				gg.at(j).at(i)=gg.at(i).at(j);
			}
		}
	}
	for(int i=0;i<N;i++){
		for(int j=0;j<N;j++){
			if(i==j)	continue;
			ans=max(ans,gg.at(i).at(j));
		}
	}
	cout << ans+1 << endl;

	return 0;
}


Measured memory_bytes: 512
#!python3.8
# -*- coding: utf-8 -*-
# abc174/abc174_d
import sys

s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in list(ss)]
ss2nnn = lambda ss: [s2nn(s) for s in list(ss)]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [i2s() for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))

def main():
    N = i2n()
    c = list(i2s())
    l = 0
    r = N - 1
    ans = 0
    while True:
        while l < N and c[l] != 'W':
            l += 1
        while r >= 0 and c[r] != 'R':
            r -= 1
        if l < r and c[l] == 'W' and c[r] == 'R':
            c[l] = 'R'
            c[r] = 'W'
            ans += 1
        else:
            break
    print(ans)
    return

main()


Measured memory_bytes: 10724
import java.util.*;
import java.util.function.*;
import java.util.stream.*;

public class Main{
	Scanner s=new Scanner(System.in);

	void solve(){
		int[] f=INTS(9).toArray();
		for(int i:ints(gInt())) {
			for(int j=0;j<9;++j)
				if(i==f[j])
					f[j]=0;
		}

		boolean r=false;
		r|=f(f,0,4,8);
		r|=f(f,2,4,6);
		for(int i=0;i<3;++i) {
			r|=f(f,i,i+3,i+6);
			r|=f(f,i*3,i*3+1,i*3+2);
		}
		System.out.println(r?"Yes":"No");
	}
	boolean f(int[] f,int i,int j,int k){
		return f[i]+f[j]+f[k]==0;
	}

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

	int gInt(){
		return Integer.parseInt(s.next());
	}
	long gLong(){
		return Long.parseLong(s.next());
	}
	double gDouble(){
		return Double.parseDouble(s.next());
	}

	SupplyingIterator<Integer> ints(int n){
		return new SupplyingIterator<>(n,this::gInt);
	}
	SupplyingIterator<Long> longs(int n){
		return new SupplyingIterator<>(n,this::gLong);
	}
	SupplyingIterator<Double> doubles(int n){
		return new SupplyingIterator<>(n,this::gDouble);
	}
	SupplyingIterator<String> strs(int n){
		return new SupplyingIterator<>(n,s::next);
	}

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

	IntStream REP(int v){
		return IntStream.range(0,v);
	}
	IntStream REP(int l,int r){
		return IntStream.rangeClosed(l,r);
	}

	IntStream INTS(int n){
		return IntStream.generate(this::gInt).limit(n);
	}
	LongStream LONGS(int n){
		return LongStream.generate(this::gLong).limit(n);
	}
	Stream<String> STRS(int n){
		return Stream.generate(s::next).limit(n);
	}

}

class SupplyingIterator<T> implements Iterable<T>,Iterator<T>{
	int t;
	Supplier<T> supplier;

	SupplyingIterator(int t,Supplier<T> supplier){
		this.t=t;
		this.supplier=supplier;
	}

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

	@Override
	public boolean hasNext(){
		return t>0;
	}

	@Override
	public T next(){
		--t;
		return supplier.get();
	}

}

class Range implements Iterable<Integer>,PrimitiveIterator.OfInt{
	int to,cur,d;

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

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

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

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

	@Override
	public int nextInt(){
		return cur+=d;
	}
	static Range rep(int i){
		return new Range(i);
	}
	static Range rep(int f,int t,int d){
		return new Range(f,t,d);
	}
	static Range rep(int f,int t){
		return rep(f,t,1);
	}
	static Range rrep(int f,int t){
		return rep(f,t,-1);
	}
}


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

#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <string>
#include <functional>
#include <math.h>

typedef long long ll;
typedef unsigned long long ull;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define RFOR(i,a,b) for(int i=(b-1);i>=(a);--i)
#define REP(i,n)   FOR(i,0,n)
#define RREP(i,n)   RFOR(i,0,n)

const int INF = 1e9;
const int MOD = 1e9+7;

using namespace std;

template <typename _Ty>
ostream& operator << (ostream& ostr, const vector<_Ty>& v) {if (v.empty()) {ostr << "{ }"; return ostr;}
    ostr << "{" << v.front(); for (auto itr = ++v.begin(); itr != v.end(); itr++) {ostr << ", " << *itr;}
    ostr << "}";
    return ostr;}

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 main(){
int a,b;scanf("%d%d",&a,&b);
double ret=0;
for(int i=1;i<=a;i++){
double tmp=1.0/a;
int now=i;
while(now<b){
now*=2;
tmp/=2;
}
ret+=tmp;
}
printf("%.12f\n",ret);
}






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

int main(void) {
  int N, D, X;
  cin >> N >> D >> X;
  for (int i = 0; i < N; i++) {
    int a;
    cin >> a;
    for (int j = 0;; j++) {
      if (1 + a * j <= D) {
        X++;
      } else {
        break;
      }
    }
  }
  cout << X << endl;
  return 0;
}

Measured memory_bytes: 256
/*  -*- coding: utf-8 -*-
 *
 * a.cc: A: Between Two Integers
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

/* typedef */

/* global variables */

/* subroutines */

/* main */

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

  if (a <= c && c <= b) puts("Yes");
  else puts("No");

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<utility>
#include<string>
#include<stack>
#include<queue>
#include<set>
#include<math.h>
#include <map>
using namespace std;
typedef long long int ll;
#define repi(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,a) repi(i,0,a)
#define all(u) u.begin(),u.end()
#define pl pair<ll,ll>
#define fi first
#define se second
#define inf 1000000007

ll H,W;
char s[52][52];

int main(){
    rep(i,52){
        rep(j,51){
            s[i][j] = '.';
        }
    }
    cin >> H >> W;
    rep(i,H){
        rep(j,W){
            cin >> s[i+1][j+1];
        }
    }
    ll possible = 1;
    rep(i,H){
        rep(j,W){
            if (s[i+1][j+1] == '#'){
                if ((s[i+2][j+1] == '#' ||s[i+1][j+2] == '#') ||(s[i][j+1] == '#' ||s[i+1][j] == '#')){
                    continue;
                }
                else {
                    possible = 0;
                    break;
                }
            
            }
        }
    }
    if (possible) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
# s = input()
# n = int(input())
# A = list(map(int, input().split()))
H, W = map(int, input().split())
S = []
vertical = []
horizontal = []

for _ in range(H):
    s = input()
    S.append(s)
    vertical.append([-1]*W)
    horizontal.append([-1]*W)

def search_vertical(i, j, current):
    i2 = i

    while not (i2 == H-1 or S[i2+1][j] == '#'):
        i2 += 1
        current += 1

    for i3 in range(i, i2+1):
        vertical[i3][j] = current

def search_horizontal(i, j, current):
    j2 = j

    while  not (j2 == W-1 or S[i][j2+1] == '#'):
        j2 += 1
        current += 1

    for j3 in range(j, j2+1):
        horizontal[i][j3] = current


res = -2
for i in range(H):
    for j in range(W):
        if S[i][j] == '#':
            continue
        if vertical[i][j] == -1:
            search_vertical(i, j, 1)
        if horizontal[i][j] == -1:
            search_horizontal(i, j, 1)
        res = max(res, vertical[i][j] + horizontal[i][j] -1)

# print(vertical)
print(res)


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

int main(){

  int N, K;

  cin >> N >> K;

  vector<int> h(N);

  for (int i = 0; i < N;i++){
    cin >> h.at(i);
  }

  int count=0;

  for(int x : h){
    if(x >= K){
      count++;
    }
  }

  cout << count << endl;
}


Measured memory_bytes: 640
#include <iostream>
#include <cstring>

using namespace std;

int main(){
	int N;
	int t[1000], r[1000];
	int dp[2][1000];
	while(cin >> N && N){
		int sumT = 0, sumR = 0, maxIdx = 0;
		for(int i=0;i<N;i++){
			cin >> t[i] >> r[i];
			sumT += t[i];
			sumR += r[i];
			if(t[maxIdx] < t[i]) maxIdx = i;
		}
		int waitTime = max(0, 2*t[maxIdx] - sumT);
		memset(dp, 0, sizeof(dp));
		dp[0][0] = 1;
		int cur = 0, next = 1;
		for(int i=0;i<N;i++){
			if(i == maxIdx) continue;
			memcpy(dp[next], dp[cur], sizeof(dp[next]));
			for(int j=0;j+r[i]<=waitTime;j++){
				if(dp[cur][j]==0) continue;
				dp[next][j+r[i]] = 1;
			}
			int maxIdx = 0;
			for(int j=0;j<1000;j++) if(dp[next][j]) maxIdx = j;
			swap(cur, next);
		}
		for(int i=waitTime;i>=0;i--){
			if(!dp[cur][i]) continue;
			cout << sumT + sumR + waitTime - i << endl;
			break;
		}
	}
}

Measured memory_bytes: 1176
import java.util.*

fun main(`$`: Array<String>) {
    val v = readLine()!!
    var c = 'a'
    while (c <= 'z') {
        if (v.indexOf(c) < 0) {
            println(v + c)
            return
        }
        ++c
    }

    val set = TreeSet<Char>()
    set.add(v[v.length - 1])
    for (i in v.length - 2 downTo 0) {
        val c = v[i]
        val h = set.higher(c)
        if (h != null) {
            println(v.substring(0, i) + h)
            return
        }
        set.add(c)
    }
    println(-1)
}


Measured memory_bytes: 33644
#include <stdio.h>
#include <algorithm>
using namespace std;
int a, b, c;
int main(){
    scanf("%d%d%d", &a, &b, &c);
    if (a > b){
        swap(a, b);
    }
    if (a > c){
        swap(a, c);
    }
    if (b > c){
        swap(b, c);
    }
    int cnt = c-a+c-b;
    if (cnt & 1){
        printf("%d\n", (cnt+3)/2);
    }
    else {
        printf("%d\n", cnt/2);
    }
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define pb push_back
#define all(a) a.begin(), a.end()
#define sz(a) (int)a.size()
#define x first
#define y second
#define debug(...) cout << "[" << #__VA_ARGS__ << ": " << __VA_ARGS__ << "]\n"
#define rd() abs((int)rng())
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int>pii;
const int maxn = 3e5 + 100;
const int mod = 1e9 + 7;
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
int main()
{
	ios_base::sync_with_stdio(false), cin.tie(0);
	string s; cin >> s;
	int o = 0;
	for(char c : s)
		o += (c == 'o');
	cout << (o + (15 - sz(s)) >= 8 ? "YES" : "NO");
	return 0;
}

Measured memory_bytes: 256
a=int(input())
b=int(input())
c=int(input())
d=int(input())
e=int(input())
k=int(input())

antennas=[a,b,c,d,e]
def check():
    for i in range(0,4):
        for j in range(1,5):
            if antennas[j]-antennas[i]>k:
                print(':(')
                return None
    print('Yay!')

check()



Measured memory_bytes: 3060
/*GRATITUDE*/
/*1916057*/
//Arise Awake and Stop Not Till the Goal is reached. 
//Break through all barriers..
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
using namespace std;
#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define vi              vector<int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define endl            "\n"
#define PI                 acos(-1)
#define w(t)              int t; cin>>t; while(t--)
#define for_f(a,b,c)      for(int i=a;i<=b;i=i+c)
#define for_r(a,b,c)      for(int i=a;i>=b;i=i-c) 
#define trace1(x) cout << '>' << #x << ':' << (x) << "\n"
#define trace2(x,y) cout<< '>' << #x << ':' << (x) << " | " << #y << ':' << (y) << "\n"
#define trace3(a,b,c) cout<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<"\n"
#define trace4(a,b,c,d) cout<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<", "<<#d<<"="<<(d)<<"\n"
void ash_god()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); 
#ifndef ONLINE_JUDGE
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif
}

/*************************************************************************************************/
//Write your functions here..............................
 


/***************************************************************************************************/

void solve() {
/*Write your code here*/
  string s; cin>>s;
  int res=0;
  for (char c : s) {
    res+=c-'0';
  }
  if(res%9==0) cout<<"Yes";
  else cout<<"No";
 
}
int32_t main()
{
ash_god();
bool tc=0;
if(tc)  {
    w(t) solve();
}
else solve();

return 0;
} 

Measured memory_bytes: 3752
N, K = list(map(int, input().split()))
R, S, P = list(map(int, input().split()))
T = [i for i in input()]
my_T = []
result = 0

for i in T:
  if i == "r":
    my_T.append("p")
  elif i == "s":
    my_T.append("r")
  elif i == "p":
    my_T.append("s")

for i in range(K, N):
      if my_T[i] == my_T[i-K]:
            if i+K < N:
                  if my_T[i+K] == "r":
                        my_T[i] = "s"
                  elif my_T[i+K] == "s":
                        my_T[i] = "p"
                  elif my_T[i+K] == "p":
                        my_T[i] = "r"
            else:
                  if my_T[i-K] == "r":
                        my_T[i] = "s"
                  elif my_T[i-K] == "s":
                        my_T[i] = "p"
                  elif my_T[i-K] == "p":
                        my_T[i] = "r"
      else:
        if my_T[i] == "r":
              result += R
        elif my_T[i] == "s":
              result += S
        elif my_T[i] == "p":
              result += P

for i in range(K):
      if my_T[i] == "r":
            result += R
      elif my_T[i] == "s":
            result += S
      elif my_T[i] == "p":
            result += P


print(result)

Measured memory_bytes: 4800
#include<stdio.h>
#include<string.h>

int main(){
  char t[300000];
  scanf("%s",t);
  
  int len=strlen(t);
  
  for(int i=0;i<len;i++){
    if(t[i]=='?'){
      t[i]='D';
    }
  }
  
  printf("%s",t);
  return 0;
}

Measured memory_bytes: 1936
import std.stdio;
import std.conv, std.array, std.algorithm, std.string;
import std.math, std.random, std.range, std.datetime;
import std.bigint;

class Node{
	Node[] adjnodes;
	int x;
	int _value;
	bool hasValue = false;
	int color = 0; // 0: undef, 1: black, 2: white
	int min = 0, max = 1_000_000;
	int isDeadend = false;
	static hasError = false;
	this(){
		x = uniform(0, 100000);
		}
	void add(Node nd){
		this.adjnodes ~= nd;
		nd.adjnodes ~= this;
		}
	void setColor(int c){
		if(this.color > 0) return;
		this.color = c;
		foreach(nd; adjnodes) nd.setColor(1 + 2 - c);
		}
	int value(int v){
		this._value = v;
		this.hasValue = 1;
		return _value;
		}
	int value(){	
		return _value;
		}
	void markEnd(){
		if(this.hasValue) return;
		else if(this.adjnodes.length > 1) return;
		this.isDeadend = true;
		Node nd = this.adjnodes[0];
		while(1){
			if(nd.adjnodes.length != 2) break;
			if(nd.hasValue) break;
			nd.isDeadend = true;
			if(!nd.adjnodes[0].isDeadend) nd = nd.adjnodes[0];
			else if(!nd.adjnodes[1].isDeadend) nd = nd.adjnodes[1];
			else break;
			}
		}
	void start(){
		Node[] q;
		foreach(nd; this.adjnodes) q ~= [this, nd];
		while(q.length){
			Node nd0, nd;
			nd0 = q[0], q = q[1 .. $];
			nd = q[0], q = q[1 .. $];
//			if(nd.isDeadend) continue;
			if(nd.min < nd0.min - 1 || nd.max > nd0.max + 1){
				if(nd.min > nd0.max + 1 || nd.max < nd0.min - 1){
					hasError = true;
					return;
					}
				if(nd.min < nd0.min - 1) nd.min = nd0.min - 1;
				if(nd.max > nd0.max + 1) nd.max = nd0.max + 1;
				foreach(nd2; nd.adjnodes) q ~= [nd, nd2];
				}
			}
		}
	string toString(){
		return (isDeadend? "*": " ") ~ adjnodes.length.to!string ~ (hasValue? ("(" ~ value.to!string ~ ")"): "");
		}
	}

void main(){
	int n = readln.chomp.to!int;
	
	Node[] nodes;
	foreach(i; 0 .. n) nodes ~= new Node;
	foreach(i; 0 .. n - 1){
		int[] tmp = readln.chomp.split.map!(to!int).map!(x => x - 1).array;
		nodes[tmp[0]].add(nodes[tmp[1]]);
		}
	
	Node[] valuednodes;
	int k = readln.chomp.to!int;
	foreach(i; 0 .. k){
		int[] tmp = readln.chomp.split.map!(to!int).array;
		tmp[0] -= 1;
		nodes[tmp[0]].value = tmp[1];
		valuednodes ~= nodes[tmp[0]];
		}
	
	valuednodes.sort!("a.x < b.x")();
	
	valuednodes[0].setColor((valuednodes[0].value % 2)? 1: 2);
	foreach(nd; valuednodes) if(nd.color != ((nd.value % 2)? 1: 2)){
		"No".writeln;
		return;
		}
	
	foreach(nd; nodes) nd.markEnd;
	
	foreach(nd; valuednodes){
		if(nd.min > nd.value){
			"No".writeln;
			return;
			}
		if(nd.max < nd.value){
			"No".writeln;
			return;
			}
		nd.min = nd.value, nd.max = nd.value;
		nd.start;
		if(Node.hasError){
			"No".writeln;
			return;
			}
		}
	
	"Yes".writeln;
	foreach(nd; nodes) nd.max.writeln;
	
	debug nodes.writeln;
	
	}




/*

①偶奇でおかしくなっていないかチェックしておかしかったらNo

②偶奇はいいとして、
・各数字の入っているマスについて以下のことをする
	最大値と最小値がすでに入っている場合、範囲外ならNo
	最大値と最小値をその数字の値にセットする
	数字を消す
	隣のマスについて
		自分の最大値＋１、自分の最小値－１をそこの最大値、最小値とする
		最大値と最小値がすでにセットされていれば共通部分とする
			共通部分がなければNo
		数字が入っているマスだった場合はストップ
		数字が入っていないマスだった場合はそこから更に隣のマスへ
	そのマスを処理済とする
*/


Measured memory_bytes: 73980
cnt = Array.new(9, 0)
n = gets.to_i
gets.split.map(&:to_i).each do |x|
    if x / 400 >= 8
        cnt[8] += 1
    else
        cnt[x/400]=1
    end
end

h = cnt[0..7].inject(:+)
puts "#{[h, (cnt[8] > 0 ? 1 : 0)].max} #{h + cnt[8]}"

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

using namespace std;

#define YES cout << "YES" << endl;
#define NO  cout << "NO"  << endl;
#define Yes cout << "Yes" << endl;
#define No  cout << "No"  << endl;
 
#define INF INT_MAX
#define MOD 1000000007
#define PI  acos(-1)

using ll  = long long;
using ull = unsigned long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rrep(i, n) for (ll i = (n)-1; i >= 0; i--)

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

    ll x, y;
    cin >> x >> y;

    if (x == 0) {
        if (y >= 0) {
            cout << y << endl;
            return 0;
        } else {
            cout << abs(y)+1 << endl;
            return 0;
        }
    }

    if (y == 0) {
        if (x > 0) {
            cout << x+1 << endl;
            return 0;
        } else {
            cout << abs(x) << endl;
            return 0;
        }
    }

    ll ans = 0;
    if (x > 0) {
        if (y > 0) {
            if (abs(y) > abs(x)) {
                ans = abs(y)-abs(x);
            } else {
                ans = abs(x)-abs(y)+2;
            }
        } else {
            if (abs(y) > abs(x)) {
                ans = abs(y)-abs(x)+1;
            } else {
                ans = abs(x)-abs(y)+1;
            }
        }
    } else {
        if (y > 0) {
            if (abs(y) > abs(x)) {
                ans = abs(y)-abs(x)+1;
            } else {
                ans = abs(x)-abs(y)+1;
            }
        } else {
            if (abs(y) > abs(x)) {
                ans = abs(y)-abs(x)+2;
            } else {
                ans = abs(x)-abs(y);
            }
        }
    }

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
typedef long long ll;
#define MOD 998244353
using namespace std;
int main() {
    unordered_map<ll, ll> mp;
    int n;
    cin >> n;
    for(int i = 0; i < n; i++) {
        ll d;
        cin >> d;
        mp[d]++;
    }
    int m;
    cin >> m;
    for(int i = 0; i < m; i++) {
        ll t;
        cin >> t;
        if(mp[t]) {
            mp[t]--;
        } else {
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
}

Measured memory_bytes: 8520
#include <algorithm>
#include <array>
#include <cmath>
#include <deque>
#include <iostream>
#include <set>
#include <string>
#include <unordered_map>

using namespace std;

const double PI = 3.14159265358979323846;

int main() {
  int n;

  cin >> n;

  cout << 2 * PI * n << endl;

  return 0;
}

Measured memory_bytes: 3788
#include <iostream>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>

using namespace std;

int main(){
  int N; cin>>N;
  vector<pair<int,int> >A,B;
  for(int i=0;i<N;i++){
    int a,b; cin>>a>>b;
    A.push_back(make_pair(b,a));
  }

  for(int i=0;i<N;i++){
    int a,b; cin>>a>>b;
    B.push_back(make_pair(a,b));
  }

  sort(A.begin(),A.end()); sort(B.begin(),B.end());
  reverse(A.begin(),A.end());
  int ans=0;

  for(int i=0;i<N;i++){
    for(int j=0;j<A.size();j++){
      if(B[i].first>A[j].second&&B[i].second>A[j].first){
        ans++;
        A.erase(A.begin()+j);
        break;
      }
    }
  }

  cout<<ans<<endl;

  return 0;
}


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

using namespace std;

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

    vector<int> p(n);
    for(int i = 0; i < n; i++) cin >> p.at(i);
    int ans = 0;
    for (int i = 1; i < n - 1; i++){
        if(p[i-1] > p[i] && p[i] > p[i + 1]) ans++;
        else if(p[i-1] < p[i] && p[i] < p[i+1]) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3580
def a(q)
puts"? "+q.join(" ")
STDOUT.flush
gets
end
N=gets.to_i
s="! "
I=(0..2*N).to_a
f=a I[1..N]
l,r=1,N+1
9.times{
m=(l+r)/2
q=I[m,N]
f==a(q)?l=m:r=m
}
x=I[r,N-1]
y=I-[0]-I[l,N+1]
1.upto(2*N){|i|
s+=a([i]+(x.index(i)?y:x))[0]
}
puts s

Measured memory_bytes: 2380
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
using namespace std;
typedef long long LL;
typedef long double DD;
const int inf = 1e9;
const int mo= 1e9+7;
const int N = 200010;
int n,m,a[N],b[N],p[N];
int main(){
	scanf("%d", &n);
	for(int i = 1; i <= n; i++){
		int x;
		scanf("%d",&x);
		p[x]=i;
	}
	a[0]=0,b[0]=0;
	for(int i=1;i<=n;i++){
		a[i]=a[i-1]+1;
		b[i]=b[i-1]-1;
		int t=a[i]+b[i];
		if(t>p[i])b[i]-=t-p[i];
		if(t<p[i])a[i]+=p[i]-t;
	}
	for(int i=1;i<=n;i++){
		a[i]+=5e8;
		b[i]+=5e8;
	}
	for(int i=1;i<=n;i++)
		printf("%d ",a[i]);
	puts("");
	for(int i=1;i<=n;i++)
		printf("%d ",b[i]);
	puts("");
	return 0;
}

Measured memory_bytes: 768
n = int(input())
lis = list(map(int,input().split()))
num = [10 ** 7]
for i in range(n):
    num.append(min(num[-1],lis[i]))
ans = 0
for i in range(n):
    if lis[i] <= num[i]:
        ans += 1
print(ans)

Measured memory_bytes: 24744
#include <bits/stdc++.h>
#include <cstdlib>
#include <cmath>
#include <algorithm>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using Graph= vector<vector<ll>>;
struct edge{ll to ; ll cost ;} ;
using graph =vector<vector<edge>> ;
#define rep(i,n) for (ll i=0; i < (n); ++i)
#define rep2(i,n,m) for(ll i=n;i<=m;i++)
#define rep3(i,n,m) for(ll i=n;i>=m;i--)
#define pb push_back
#define eb emplace_back
#define ppb pop_back
#define mpa make_pair
#define fi first
#define se second 
#define set20 cout<<fixed<<setprecision(20) ;
const ll INF=1e18 ;
inline void chmax(ll& a,ll b){a=max(a,b);}
inline void chmin(ll& a,ll b){a=min(a,b);}
double pi=acos(-1) ;
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}
 


 int main(){
 string s ; cin>>s ;
 ll k= s.size() ;
 bool ok= 1 ;
 rep(i,k){
  if(s[i]==s[i+1]){
    cout<<(i+1)<<" "<<(i+2)<<endl ;
    ok=0 ;
    break ;
  }
 }
 if(!ok) return 0;
 rep(i,k-1){
   if(s[i]==s[i+2]){
     cout<<(i+1)<<" "<<(i+3)<<endl ;
     ok=0 ;
     break ;
   }
 }
 if(!ok) return 0 ;

 cout<<-1<<" "<<-1<<endl ;

   return 0 ;
 }



Measured memory_bytes: 3648
using System;

namespace ABC132
{
    class B
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            string[] input = Console.ReadLine().Split(' ');

            int[] p = new int[n];
            for (int i = 0; i < n; i++)
            {
                p[i] = int.Parse(input[i]);
            }

            int[] tmp = new int[3];
            int count = 0;
            for (int i = 1; i < n - 1; i++)
            {
                tmp[0] = p[i - 1];
                tmp[1] = p[i];
                tmp[2] = p[i + 1];

                Array.Sort(tmp);

                if (p[i] == tmp[1]) { count++; }

            }
            Console.WriteLine(count);
        }
    }
}


Measured memory_bytes: 11092
#include <iostream>

void selectionSort(int *a, int n){

    int min_idx;
    int counter = 0;

    for(int i = 0; i < n; i++){
        min_idx = i;
        for(int j = i+1; j < n; j++){
            if(a[min_idx] > a[j]){
                min_idx = j;
            }
        }
        if(i != min_idx){
            counter++;
            std::swap(a[min_idx], a[i]);
        }
    }


    for(int c = 0; c < n; c++){
        if(c == n-1){
            std::cout << a[c] <<std::endl;
        }else{
            std::cout << a[c] << " ";
        }
    }
    
    std::cout << counter << std::endl;

}

int main(){

    int n, tmp;
    std::cin >> n;

    int a[n];

    for(int i = 0; i < n; i++){
        std::cin >> tmp;
        a[i] = tmp;
    }

    selectionSort(a, n);

}


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

const ll mod = 1e9 + 7;
const ll mask = 1e9;

using node = tuple<ll, ll, ll>;

ll p2[300000];

void init_p2() {
  p2[0] = 1;
  for(int i = 1;i < 300000;++i) {
    p2[i] = (p2[i-1] * 2) % mod;
  }
}

ll gcd(ll a, ll b) {
  if (b > a) {
    swap(a, b);
  }
  if(a % b == 0) {
    return b;
  }
  return gcd(b, a % b);
}

int main(void) {
  init_p2();
  map<node, int> m;
  int n;
  cin >> n;
  auto fish = vector<node>(n);
  for(int i = 0;i < n;++i) {
    ll a,b;
    cin >> a >> b;

    node f;
    if (a == 0 && b == 0) {
      f = node{0, 0, 0};
    } else if (a == 0) {
      f = node{1, 0, 0};
    } else if (b == 0) {
      f = node{0, 1, 0};
    }else {
      ll abs_a = (ll)abs(a), abs_b = (ll)abs(b);
      ll g = gcd(abs_a, abs_b);
      ll s = (a / abs_a) * (b / abs_b);
      f = node{abs_a/g, abs_b/g, s};
    }
    fish[i] = f;
    m[f]++;
  }

  ll res = 1LL;
  for(int i = 0;i < n;++i) {
    ll a, b, s;
    tie(a, b, s) = fish[i];
    if(a == 0 && b == 0) {
      continue;
    }
    node inv = node{b, a, -s};
    if (m.find(inv) == m.end()) {
      res = (res * 2) % mod;
    }
  }

  for(auto kv : m) {
    ll a, b, s;
    tie(a, b, s) = kv.first;
    if(a == 0 && b == 0) {
      continue;
    }
    
    node inv = node{b, a, -s};
    if(m.find(inv) == m.end()) { 
      continue;
    }
    if(s == 0 && a == 0) {
      continue;
    }
    if(s < 0) {
      continue;
    }
    
    int n_pos = kv.second;
    int n_neg = m[inv];
    ll mult = (p2[n_pos] - 1LL + p2[n_neg] - 1LL + 1LL) % mod;
    res = (res * mult) % mod;
  }

  res = (res + m[node{0, 0, 0}]) % mod;

  cout << (res + mod - 1LL) % mod << endl;
  return 0;
}


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

using namespace std;
typedef long long ll;

int main() {
    int x;
    cin >> x;
    if (x >= 400 && x <= 599) {
        cout << 8 << endl;
    } else if (x >= 600 && x <= 799) {
        cout << 7 << endl;
    } else if (x >= 800 && x <= 999) {
        cout << 6 << endl;
    } else if (x >= 1000 && x <= 1199) {
        cout << 5 << endl;
    } else if (x >= 1200 && x <= 1399) {
        cout << 4 << endl;
    } else if (x >= 1400 && x <= 1599) {
        cout << 3 << endl;
    } else if (x >= 1600 && x <= 1799) {
        cout << 2 << endl;
    } else if (x >= 1800 && x <= 1999) {
        cout << 1 << endl;
    }
    return 0;
}


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

int main()
{
	int n;
	cin >> n;
	vector<int> a(n);
	double sum = 0, avg;
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
		sum += a[i];
	}
	avg = sum / n;
	int avg2 = avg, s = 0;
	avg2 += (avg - avg2 >= avg2 + 1 - avg) ? 1 : 0;
	for (int i = 0; i < n; i++)
		s += abs(avg2 - a[i]) * abs(avg2 - a[i]);
	cout << s << endl;
	return 0;
}


Measured memory_bytes: 256