akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<vector>
#include<math.h>
using namespace std;
typedef long long int ll;
#define cinf(n,x) for(int i=0;i<(n);i++) cin >> x[i];
ll cnt[200005];
int main(){
  int n; cin >>n;
  vector<ll> a(n);
  cinf(n,a);
  for(int i=0;i<n;i++){
    cnt[i]+=a[i];
    if(i>0)cnt[i]+=cnt[i-1];
  }
  int left=0;
  int right=2;
  ll ans=1e18;
  ll b,c,d,e,f;
  b=cnt[left];
  c=cnt[1]-b;
  e=cnt[n-1]-cnt[right];
  d=cnt[n-1]-b-c-e;
  for(int mid=1;mid<n-2;mid++){
    while(left<mid-1){
      ll Min=abs(b-c);
      if(abs((b+a[left+1])-(c-a[left+1]))<Min){
        left++;
        b+=a[left];
        c-=a[left];
      }
      else break;
    }
    while(right<n-1){
      ll Min=abs(d-e);
      if(abs((d+a[right+1])-(e-a[right+1]))<Min){
        right++;
        d+=a[right];
        e-=a[right];
      }
      else break;
    }
    f=max(max(b,c),max(d,e))-min(min(b,c),min(d,e));
    ans=min(ans,f);
    c+=a[mid+1];
    d-=a[mid+1];
    //cout << left << " " << mid << " " << right << " " << f << endl;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3328
N=int(input())
count=[[0]*9 for i in range(9)]
for i in range(N+1):
  j=str(i)
  if j[0] != '0' and j[-1] != '0':
    count[int(j[0])-1][int(j[-1])-1]+=1
ans=0
for i in range(9):
  for j in range(9):
    ans+=count[i][j]*count[j][i]
print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main(){
  int A,B,C,D,a;
  cin>>A>>B>>C>>D;
  a=max(A*B,C*D);
  if(A*B==C*D){
  cout<<A*B<<endl;
  }else{
       cout<<a<<endl;
       }
}

Measured memory_bytes: 256
#pragma region Macros
#include <bits/stdc++.h>
using namespace std;
//#include <boost/multiprecision/cpp_int.hpp>
//using multiInt = boost::multiprecision::cpp_int;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pld = pair<ld, ld>;
template <typename Q_type>
using smaller_queue = priority_queue<Q_type, vector<Q_type>, greater<Q_type>>;

const int MOD_TYPE = 1;
const ll MOD = (MOD_TYPE == 1 ? (ll)(1e9 + 7) : 998244353);
const int INF = (int)1e9;
const ll LINF = (ll)4e18;
const ld PI = acos(-1.0);
const ld EPS = 1e-11;

#define REP(i, m, n) for (ll i = m; i < (ll)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << "\n"
#define Yes(n) cout << ((n) ? "Yes" : "No") << "\n"
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << "\n"
#define possible(n) cout << ((n) ? "possible" : "impossible") << "\n"
#define Yay(n) cout << ((n) ? "Yay!" : ":(") << "\n"
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x) cerr << #x << ":" << x << "\n";

vector<int> Dx = {0, 0, -1, 1, -1, 1, -1, 1, 0};
vector<int> Dy = {1, -1, 0, 0, -1, -1, 1, 1, 0};

#pragma endregion

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

  int n, a, b;
  cin >> n >> a >> b;
  string s;
  cin >> s;
  int pass = 0, bi = 0;
  rep(i, n)
  {
    bool can = false;
    if (s[i] == 'a')
    {
      if (pass < a + b)
      {
        can = true;
        pass++;
      }
    }
    else if (s[i] == 'b')
    {
      if (pass < a + b && bi < b)
      {
        can = true;
        pass++;
        bi++;
      }
    }
    Yes(can);
  }
  return 0;
}


Measured memory_bytes: 848
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#define ll long long
#define pr(x) cout<<#x<<"="<<x<<endl
using namespace std;
ll n,num[100110],a,tmp[110000],b,i,ans;
bool pan(ll x)
{
	ll t=0,nd=0;
	for (i=1;i<=n;i++)
	{
		if (num[i]-x*b>=0) tmp[++t]=num[i]-x*b;
	}
	for (i=1;i<=t;i++)
	{
		if (tmp[i]%(a-b)==0) nd+=tmp[i]/(a-b);
		else nd+=tmp[i]/(a-b)+1;
	}
	if (x>=nd) return true;
	else return false;
}
int main()
{
	scanf("%lld %lld %lld",&n,&a,&b);
	for (i=1;i<=n;i++)
	{
		scanf("%lld",&num[i]);
	}
	ll l=0,r=1000000000;
	while (l<=r) 
	{
		int mid=(l+r)/2;
		if (pan(mid))
		{
			ans=mid;
			r=mid-1;
		}
		else l=mid+1;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 1792
#include <stdio.h>

int main()
{
	int N, K, A, B;

	scanf("%d %d", &N, &K);

	int i, x[100];
	for(i = 0; i < N; i++)
		scanf("%d", &x[i]);

	int ans = 0;
	for(i = 0; i < N; i++) {
		A = x[i] * 2;
		B = (K - x[i]) * 2;
		if(A < B)
			ans += A;
		else
			ans += B;
	}

	printf("%d\n", ans);

	return 0;
}

Measured memory_bytes: 128
N,M=map(int,input().split())
mod=10**9+7
 
from math import factorial
from collections import Counter
 
def soinsuu(n):
    list_=[]
    while(n!=1):
        for i in range(2,int(n**0.5)+1):
            if n%i==0:
                list_.append(i)
                n=n//i
                break
        else:
            list_.append(n)
            n=1
    return sorted(list_)
 
def product(a):
    pro=1
    for b in a:
        pro=pro*b%mod
    return pro
 
#n!,nPr,nCrの高速計算
def n_func(n,mod=10**9+7):
    ans=1
    for i in range(1,n+1):
        ans=(ans*i)%mod
    return ans
def inv_n(n,mod=10**9+7):
    return pow(n,mod-2,mod)
def nPr(n,r,mod=10**9+7):
    ans=n_func(n-r,mod)
    ans=inv_n(ans,mod)
    return ans*n_func(n,mod)%mod
    
nPr_list=[nPr(N,i) for i in range(30)]
bunbo_list=dict()

def dp(cur,init,seq,lest,num):
    #print(cur,init,seq,lest,num)
    if cur==N:
        if lest==0:
            cnt=sorted(list(Counter(seq).values())+[N-len(seq)],reverse=True)
            bunbo=product(map(factorial,cnt[1:]))
            if bunbo not in bunbo_list.keys():
                bunbo_list[bunbo]=inv_n(bunbo)
            memo[num]=(memo[num]+nPr_list[N-cnt[0]]*bunbo_list[bunbo])%mod
    elif lest==0:
        dp(N,init,seq,0,num)
    else:
        if cur==0:
            for i in range(1,lest+1):
                dp(cur+1,init,seq+[i],lest-i,num)
        else:
            for i in range(1,min(lest,seq[-1])+1):
                dp(cur+1,init,seq+[i],lest-i,num)
 
p=list(Counter(soinsuu(M)).values())
memo=[0]*len(p)


for i in range(len(p)):
    dp(0,p[i],[],p[i],i)
print(product(memo))

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

int main()
{
	long long i,j,k,n,res,tab[100010];
	cin>>n;
	for (i=1;i<=n;i++)
	 cin>>tab[i];
	sort(tab+1,tab+n+1);
	tab[0]=-5;
	i=n;
	long long sisi1=-1;
	long long simpan;
	while (i)
	{
		//cout<<i<<" i\n";
		bool cek=false;
		if (tab[i-1]==tab[i])
		{
			sisi1=tab[i];
			simpan=tab[i];
			cek=true;
		}
		if (cek)
		{
			simpan=i-2;
			break;
		}
		else
		 i--;
	}
	//cout<<sisi1<<" sisi\n";
	//cout<<simpan<<" simpan\n";
	if (sisi1==-1)
	{
		cout<<0<<"\n";
		return 0;
	}
	i=simpan;
	//cout<<i<<"i\n";
	long long sisi2=0;
	while (i)
	{
		//cout<<i<<" i\n";
		bool cek=false;
		if (tab[i-1]==tab[i])
		{
			sisi2=tab[i];
			break;
		}
		else
		 i--;
	}
	res=sisi1*sisi2;
	cout<<res<<"\n";
}

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

int main() {
 int N,A,B;
  cin>>N>>A>>B;
 vector<char>S(N);
  for(int i=0;i<N;i++){cin>>S.at(i);}
 int T=A+B;int K=B;//定員
 for(int i=0;i<N;i++){
   if(S.at(i)=='a'&&T>0){cout<<"Yes"<<endl;T--;}
    else if(S.at(i)=='b'&&T>0&&K>0){cout<<"Yes"<<endl;T--;K--;}
     else{cout<<"No"<<endl;}}
  return 0;
}

Measured memory_bytes: 896
using System;

namespace ITP1_5_A
{
    class Program
    {
        static void Main(string[] args)
        {
            while (true)
            {
                string[] x = Console.ReadLine().Split(' ');
                int h = int.Parse(x[0]);
                int w = int.Parse(x[1]);
                if (h == 0 && w == 0) break;
                
                for (int j = 0; j < h; j ++)
                {
                    for (int i = 0; i < w; i ++)
                    {
                        Console.Write("#");
                    }
                    Console.WriteLine();
                }
                Console.WriteLine();
            }
            
        }
    }
}


Measured memory_bytes: 15980
#include<stdio.h>
#include <limits.h>
  
#define N 101
 
#define White 0
#define Gray  1
#define Black 2
  
  
int n=0;
int G[N][N];
int d[N];
int color[N];
int que[N];
int head=0;
int tail=0;
  
void Enqueue(int);
int Dequeue();
void BFS(int);
 
int main()
{
  int i,j,s,v,r;
  int p=1;
 
  scanf("%d",&n);
 
  for(i=1;i<=n;i++)
    {
    for(j=1; j<=n;j++)
      {
    G[i][j] = 0;
      }
    }
  
  for(i=1;i<=n;i++){
    scanf("%d%d", &v,&r);
    for(j=1;j<=r;j++){
      scanf("%d",&s);
      G[i][s] = 1;
    }
  }
 
  BFS(p);
  for(i=1;i<=n;i++){
    printf("%d %d\n",i, d[i]);
  }
  return 0;
}

void Enqueue(int s)
{
  que[tail]=s;
  tail+=1;
}
 
int Dequeue()
{
  int sugiyama;
  sugiyama = que[head];
  head+=1;
  return sugiyama;
} 
 
void BFS(int s)
{
  int sugi,yama;
  for(sugi=1;sugi<=n;sugi++){
    color[sugi] = White;
    d[sugi] = -1;
  }
  color[s] = Gray;
  d[s] = 0;
  Enqueue(s);
  while(head != tail){
    sugi = Dequeue();
    for(yama=1;yama<=n;yama++){
      if(color[yama] == White && G[sugi][yama] == 1){
        color[yama] = Gray;
        d[yama] = d[sugi] + 1;
        Enqueue(yama);
      }
    }
    color[sugi] = Black;
  }
}

Measured memory_bytes: 636
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>

using namespace std;

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define BW(a,x,b) ((a)<=(x)&&(x)<=(b))
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define AY second.first.first
#define AX second.first.second
#define BY second.second.first
#define BX second.second.second
#define INF 1 << 30
#define EPS 1e-10

typedef pair<int, int> P;
typedef pair<int, P> pii;
typedef pair<P, P>pipi;
typedef vector<int> vi;
typedef queue<int> qi;
typedef long long ll;

int dy[] = {0, -1,0,1,0}, dx[] = {0, 0,-1,0,1};
int gdy[] = {0, 0, 1, 0, 0, 0, 0, 0, -1}, gdx[] = {0, 0, 0, 0, -1, 0, 1, 0, 0};
int H, W;
char field[32][32], pattern[16];

P nexta(int y, int x, int d){
  int ny = y+dy[d], nx = x+dx[d];
  ny = max(0, min(H-1, ny));
  nx = max(0, min(W-1, nx));
  if(field[ny][nx] == '#'){
    ny = y;
    nx = x;
  }
  return MP(ny, nx);
}

P nextb(int y, int x, int c){
  int L = strlen(pattern);
  int ny = y+gdy[pattern[c%L]-'0'], nx = x+gdx[pattern[c%L]-'0'];
  ny = max(0, min(H-1, ny));
  nx = max(0, min(W-1, nx));
  return MP(ny, nx);
}

int main(){
  while(scanf("%d%d", &H, &W) && H+W){
    rep(i, H) scanf("%s", field[i]);
    scanf("%s", pattern);
    int ay, ax, by, bx;
    rep(i, H) rep(j, W){
      if(field[i][j] == 'A'){ ay = i; ax = j;}
      else if(field[i][j] == 'B'){ by = i; bx = j;}
    }

    queue<pair<int, pipi> >q;
    map<pair<pipi, int>, int>m;
    q.push(MP(0, MP(MP(ay, ax), MP( by, bx))));
    m[MP(MP(MP(ay, ax), MP(by, bx)), -1)] = 1;

    while(!q.empty()){
      pair<int, pipi> now = q.front(); q.pop();
      if(now.AY == now.BY && now.AX == now.BX){
	printf("%d %d %d\n", now.F, now.AY, now.AX);
	goto e;
      }
      //      printf("%d %d %d %d %d\n", now.F, now.AY, now.AX, now.BY, now.BX);
      rep(d, 5){
	P na = nexta(now.AY, now.AX, d);
	P nb = nextb(now.BY, now.BX, now.F);
	//	int any = now.AY+dy[d], anx = now.AX+dx[d];
	//	int bny = now.BY+gdy[pattern[(now.F%strlen(pattern))]-'0'], bnx = now.BX+gdx[pattern[(now.F%strlen(pattern))]-'0'];
	//	printf("%d %d %d %d\n", any, anx, bny, bnx);
	//	if(any < 0 || any >= H || anx < 0 || anx >= W || bny < 0 || bny >= H || bnx < 0 || bnx >= W ||
	//	   field[any][anx] == '#' || m.count(MP(MP(any, anx), MP(bny, bnx)))) continue;
	if(m.count(MP(MP(na, nb), (now.F%strlen(pattern))))) continue;

	m[MP(MP(na, nb), now.F%strlen(pattern))] = 1;
	q.push(MP(now.F+1, MP(na, nb)));
      }
    }
    puts("impossible");
  e:;
  }
  return 0;
}

Measured memory_bytes: 3332
use strict;
use utf8;
use warnings;

my $n = <STDIN>;
chomp($n);
my $line = <STDIN>;
chomp($line);
my @a = split(/ /, $line);

my $min = 1000;
my $max = 0;
for my $x (@a){
    if ($x < $min){
        $min = $x;
    }
    if ($max < $x){
        $max = $x;
    }
}
my $ans = $max - $min;
print "$ans\n";

Measured memory_bytes: 768
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;
import java.util.stream.IntStream;
import java.util.stream.Stream;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = Integer.parseInt(sc.next());
		
		int total = 0;
		for (int i = 1; i <= N; i++) {
			total += 800;
			if (i % 15 == 0) total -= 200;
		}
		
		System.out.println(total);		
	}
}


Measured memory_bytes: 21716
N, A, B = map(int,input().split())
lst_1 = []
def digitSum(n):
    # 数値を文字列に変換
    s = str(n)
    # １文字ずつ数値化し配列にする。
    array = list(map(int, s))
    # 合計値を返す
    return sum(array)

sub = [k for k in range(1,N+1)]

for j in sub:
    if A <= digitSum(j) <= B:
        lst_1.append(j)
print(sum(lst_1))

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

typedef long long ll;

#define REP(i,n) for(int i=0;i<n;i++)

int N, x;
vector<int> swap_arr(vector<int> v, int i, int j) {
  int tmp = v[i];
  v[i] = v[j];
  v[j] = tmp;
  return v;
}

int main() {
  scanf("%d %d", &N, &x);
  vector<int> v;
  if (x == 1 || x == 2*N-1) {
    printf("No\n");
  } else if (N == 2) {
    printf("Yes\n1\n2\n3\n");
  } else if (x == 2) {
    REP(i, 2*N-1) {
      if (i+1 >= x-1 && i+1 <= x+2) continue;
      v.push_back(i+1);
    }
    printf("Yes\n");
    REP(i, N-2) {
      printf("%d\n", v.back());
      v.pop_back();
    }
    printf("%d\n", x+2);
    printf("%d\n", x);
    printf("%d\n", x-1);
    printf("%d\n", x+1);
    REP(i, N-3) {
      printf("%d\n", v.back());
      v.pop_back();
    }
  } else {
    REP(i, 2*N-1) {
      if (i+1 >= x-2 && i+1 <= x+1) continue;
      v.push_back(i+1);
    }
    printf("Yes\n");
    REP(i, N-2) {
      printf("%d\n", v.back());
      v.pop_back();
    }
    printf("%d\n", x-1);
    printf("%d\n", x);
    printf("%d\n", x+1);
    printf("%d\n", x-2);
    REP(i, N-3) {
      printf("%d\n", v.back());
      v.pop_back();
    }
  }

  return 0;
}


Measured memory_bytes: 2420
#![allow(unused_imports)]
#![allow(dead_code)]
#![macro_use]
use std::io::prelude::*;
use std::cmp::{max, min};
use std::collections::BinaryHeap;

const MOD: i64 = 1e9 as i64 + 7;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn gcd(x: usize, y: usize)->usize{
    if y == 0{
        return x
    }
    gcd(y, x % y)
}

fn main() {
    input! {
        n: usize,
    }

    let ans = if n % 2 == 1{
        0
    }else{
        let mut k = 10;
        let mut res = 0;
        while k <= n{
            res += n / k;
            k *= 5;
        }
        res
    };
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
 
int main()
{
    int n;
    cin >> n;
    vector<ll> a(n);
    rep(i, n)
    {
        cin >> a[i];
        if (a[i] == 0)
        {
            cout << 0 << endl;
            return 0;
        }
    }
    ll ans = a[0];
    const ll INF = 1e18;
    for (int i = 1; i < n; i++)
    {
        if (a[i] > INF / ans)
        {
            cout << -1 << endl;
            return 0;
        }
        else
        {
            ans *= a[i];
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 4048
#from matplotlib import pyplot as plt
def binary_search(mn,mx,a,x,y):
    #リストlからaの値のインデックスをサーチする。
    #二分探索を可能にするためにはリストlはソートされていなければならない。
    z = (mx+1)//2
    low = mn
    high = mx+1
    while low <= high:
        temp = rule2(x,y,z)
        if temp == a:
            if z <= 0:
                return None
            return z
        elif temp < a:
            low = z + 1
        elif temp > a:
            high = z - 1

        z = (low + high) // 2
    return None

def rule2(x,y,z):
    return x ** 2 + y ** 2 + z**2 + x * y + y * z + z*x
def main():
    n = int(input())
    x = []
    y = []
    for i in range(1,n+1):
        #x.append(i)
        #y.append(f(i))
        print(f(i))
    #plt.scatter(x,y)
    #plt.show()


def f(n):
    counter = 0
    for x in range(1,n):
        if x ** 2 > n:
            break
        for y in range(x,n-x**2):
            if y < x:
                continue
            if x ** 2 + y ** 2 > n:
                break
            z = binary_search(y,n-x**2-y**2-x*y,n,x,y)
            if z == None:
                continue
            else:
                if rule2(x,y,z) == n:
                    if x == y and y == z and z == x:
                        counter += 1
                    elif x != y and y != z and z != x:
                        counter += 6
                    else:
                        counter += 3

    return counter


if __name__ == '__main__':
    main()

#6 24 54 96
#1  4  9 16
#18

Measured memory_bytes: 72988
//
//  AOJ 2170 Marked Ancestor
//
//  Created by TaoSama on 2015-03-16
//  Copyright (c) 2015 TaoSama. All rights reserved.
//
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <set>
#include <vector>
#define CLR(x,y) memset(x, y, sizeof(x))

using namespace std;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const int N = 1e5 + 10;

int n, q, par[N];

int find(int x) {
	if(par[x] == x) return x;
	return find(par[x]);
}

int main() {
#ifdef LOCAL
	freopen("in.txt", "r", stdin);
//	freopen("out.txt","w",stdout);
#endif
	ios_base::sync_with_stdio(0);

	while(~scanf("%d%d", &n, &q) && n && q) {
		par[1] = 1;
		for(int i = 2; i <= n; ++i) scanf("%d", &par[i]);

		long long ans = 0;
		for(int i = 1; i <= q; ++i) {
			char op[2]; int x;
			scanf("%s%d", op, &x);
			if(op[0] == 'Q') ans += find(x);
			else par[x] = x;
		}
		printf("%lld\n", ans);
	}
	return 0;
}

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

int main() {
  int N;
  int A;
  	cin >> N >> A;
  int x;
  	x = N % 500;
      if(x <= A){
        cout << "Yes" << endl;
      }
  		else{
          cout << "No" << endl;
        }
}

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


ll findpow(ll a,ll b){
    ll cnt=0,i,j;
    while(a>1){
        a=a/b;
        cnt++;
    }
    return cnt;
}


int main(){
    long double i,j,k,sum=0,n,sum1=0,t,ans=1000000000,p,max1=0,l=0,m,a,b,c;
   // string c;
    cin>>n;
    i=n/3;
    j=i;
    k=n-i-j;
    a=n/3+1;
    b=a;
    c=n-a-b;
    cout<<fixed<<setprecision(12)<<max(a*b*c,i*j*k)<<endl;
    
    
    
    
    
   
   
   
    
    
	return 0;
}

Measured memory_bytes: 256
S = input()

length = len(S)
pattern1 = ""
for i in range(length):
    pattern1 += "0" if i % 2 == 0 else "1"
# print(pattern1)

count1 = 0
count2 = 0

for i in range(length):
    if pattern1[i] == S[i]:
        count2 += 1
    else:
        count1 += 1

print(min(count1, count2))


Measured memory_bytes: 3316
/// Rustで競技プログラミングの入力をスッキリ記述するマクロ
///
/// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[inline]
#[allow(dead_code)]
fn gcd(mut m: u64, mut n: u64) -> u64 {
    if m < n {
        std::mem::swap(&mut m, &mut n);
    }

    loop {
        let k = m % n;
        if k == 0 {
            return n;
        }

        m = n;
        n = k;
    }
}

#[inline]
#[allow(dead_code)]
fn lcm(m: u64, n: u64) -> u64 {
    m / gcd(m, n) * n
}

macro_rules! eprint(
    ($($arg:tt)*) => { {
        use std::io::Write;
        let r = write!(&mut ::std::io::stderr(), $($arg)*);
        r.expect("failed printing to stderr");
    } }
);

macro_rules! eprintln(
    ($($arg:tt)*) => { {
        use std::io::Write;
        let r = writeln!(&mut ::std::io::stderr(), $($arg)*);
        r.expect("failed printing to stderr");
    } }
);

macro_rules! dbg {
    ($val:expr) => {
        // Use of `match` here is intentional because it affects the lifetimes
        // of temporaries - https://stackoverflow.com/a/48732525/1063961
        match $val {
            tmp => {
                eprintln!("[{}:{}] {} = {:#?}",
                          file!(), line!(), stringify!($val), &tmp);
                tmp
            }
        }
    }
}

fn main() {
    input!{
        n: usize,
        time: u64,
        t_v: [u64; n],
    }

    let mut answer = 0u64;
    for t_v in t_v.windows(2) {
        let t_a = t_v[0];
        let t_b = t_v[1];

        if t_b - t_a < time {
            answer += t_b - t_a;
        } else {
            answer += time;
        }
    }

    answer += time;

    println!("{}", answer);
}


Measured memory_bytes: 6396
# coding: utf-8
# Your code here!

from heapq import heappush, heappop
def dijkstra(g,start): #g: 隣接リスト
    inf = float("inf")
    dist = [inf]*(len(g))
    q = [(start,0)] #(点、そこまでの距離)
    dist[start] = 0
    while q:
        v,c = heappop(q)
        if dist[v] < c: continue
        for to, cost in g[v]:
            if dist[v] + cost < dist[to]:
                dist[to] = dist[v] + cost
                heappush(q, (to, dist[to]))
    return dist


n,m,R = [int(i) for i in input().split()]
r = [int(i)-1 for i in input().split()]

inf = 10**9
g = [[] for _ in range(n)]
for _ in range(m):
    a,b,c = [int(i) for i in input().split()]
    g[a-1].append((b-1, c))
    g[b-1].append((a-1, c))


dvec = [None]*R
for i, ri in enumerate(r):
    dvec[i] = dijkstra(g, ri)

m = {ri:i for i, ri in enumerate(r)}    

ans = inf
import itertools
for x in itertools.permutations(r):
    c = 0
    for i, xi in enumerate(x):
        if i > 0:
            c += dvec[m[xi]][x[i-1]]
    if c < ans:
        ans = c
            
print(ans)














Measured memory_bytes: 66904
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <iostream>
using namespace std;
using namespace boost::multiprecision;

int main(){
    cpp_dec_float_100 a, b, c;
    cin >> a >> b >> c;
    cout << (sqrt(a) + sqrt(b) < sqrt(c) ? "Yes": "No") << endl;
}

Measured memory_bytes: 256
n = int(input())
MOD = 10**9 + 7
a = 1
b = 1
c = 1
for i in range(n):
    a *= 10
    b *= 9
    c *= 8
    a %= MOD
    b %= MOD
    c %= MOD
ans = (a - 2*b +c) % MOD
print(ans)

Measured memory_bytes: 9056
#include<stdio.h>
int main(void){
    int a,b,c,d,dis_ab,dis_bc,dis_ac;
    scanf("%d %d %d %d",&a,&b,&c,&d);
    dis_ac=(a>c)?a-c:c-a;
    dis_ab=(a>b)?a-b:b-a;
    dis_bc=(b>c)?b-c:c-b;
    if(dis_ac<=d||(dis_ab<=d&&dis_bc<=d)){
        printf("Yes\n");
    }
    else{
        printf("No\n");
    }
	return 0;		
}

Measured memory_bytes: 128
import java.io.*;
import java.util.*;

public class Main {
    public static void main(String[] args) {
        PrintWriter out = new PrintWriter(System.out);

        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        int[] a = new int[2 * N - 1];
        for (int i = 0; i < a.length; ++i) {
            a[i] = sc.nextInt();
        }

        int high = 2 * N - 1;
        int low = 1;
        while ((high - low) > 1) {
            int mid = (high + low) / 2;
            if (go(a, mid)) {
                low = mid;
            } else {
                high = mid;
            }
        }
        out.println(low);
        out.flush();
    }
    private static boolean go(int[] a, int mid) {
        int len = a.length;
        int[] b = new int[len];
        for (int i = 0; i < len; ++i) {
            b[i] = a[i] >= mid ? 1 : 0;
        }

        int start = -1;
        for (int i = 1; i < len; ++i) {
            if (b[i] != b[i - 1]) {
                if (start == -1) {
                    start = i - 1;
                }
            } else {
                if (start != -1) {
                    if ((i - start) % 2 == 1) {
                        for (int j = start; j <= i; ++j) {
                            b[j] = b[i];
                        }
                    } else {
                        for (int j = start; j < start + (i - start) / 2; ++j) {
                            b[j] = b[start];
                        }
                        for (int j = start + (i - start) / 2; j <= i; ++j) {
                            b[j] = b[i];
                        }
                    }
                }
                start = -1;
            }
        }
        if (start != -1) {
            int i = len;
            if ((i - start) % 2 == 1) {
                for (int j = start; j < i; ++j) {
                    b[j] = b[start];
                }
            } else {
                for (int j = start; j < start + (i - start) / 2; ++j) {
                    b[j] = b[start];
                }
                for (int j = start + (i - start) / 2; j < i; ++j) {
                    b[j] = b[start] == 1 ? 0 : 1;
                }
            }
        }
        return b[len / 2] == 1;
    }
}

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

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  int n; cin>>n;
  string s,t;
  cin>>s>>t;

  for(int i=0;i<n;i++){
    cout<<s[i]<<t[i];
  }


  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <functional>
#include <algorithm>
#include <numeric>
#include <string>
#include <map>
#include <queue>
#include <bitset>
#include <sstream>
#include <iomanip>

using namespace std;
typedef long long ll;


int main(){
        string S;
        cin >> S;
        ll Count_p=0, Point=0;
        for(int i=0; i<S.size(); i++){
                char hand = S[i];
                if(hand == 'g'){
                        if(Count_p>0){
                                Count_p--;
                                Point++;
                        }
                        else{
                                Count_p++;
                        }
                }
                else
                        if(Count_p>0) Count_p--;
                        else{
                                Count_p++;
                                Point--;
                        }
        }
        cout << Point;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pi 3.141592653589793238
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define mod 1000000007
int main(){
	fast;
	int a,b;
	cin>>a>>b;
	if((a+b)%3==0||(a)%3==0||b%3==0)
		cout<<"Possible";
	else
		cout<<"Impossible";
	return 0;
}



Measured memory_bytes: 3596
#![allow(unused_imports)]
use itertools::Itertools;
use proconio::{input, marker::*};
use std::cmp::*;
use std::collections::*;
use superslice::*;

fn main() {
    input! {
        x: i64,
        y: i64,
    }

    if (4 * x - y) % 2 == 0 && 4 * x - y >= 0 && 2 * x - y <= 0 {
        println!("Yes");
    } else {
        println!("No");
    }
}


Measured memory_bytes: 2144
h, w, d = map(int, input().split())

clr = {'R':'Y', 'Y':'R', 'G':'B', 'B': 'G'}

ans = [['.' for _ in range(w)] for _ in range(h)]
if d % 2 == 1:
    d = 1
    ls = ["R"]
elif d == 2:
    ls = ["RR", "GB"]
else:
    ls = [['.' for _ in range(d)] for _ in range(d)]
    for i in range(d // 2 - 1, -1, -1):
        for j in range(d):
            if j < d // 2 - i - 1:
                ls[i][j] = 'G'
            elif d // 2 + i < j:
                ls[i][j] = 'B'
            else:
                ls[i][j] = 'R'
    for i in range(d // 2, d - 1):
        for j in range(d):
            if j <= (i - d // 2):
                ls[i][j] = 'B'
            elif 3 * d // 2 - i - 1 <= j:
                ls[i][j] = 'G'
            else:
                ls[i][j] = 'R'
    for j in range(d):
        if j < d // 2:
            ls[d - 1][j] = 'B'
        else:
            ls[d - 1][j] = 'G'
for i in range(h):
    for j in range(w):
        if i % (2 * d) < d and j % (2 * d) < d:
            ans[i][j] = ls[i % d][j % d]
        elif d <= i % (2 * d) and d <= j % (2 * d):
            ans[i][j] = ls[i % d][j % d]
        else:
            ans[i][j] = clr[ls[i % d][j % d]]
for row in ans:
    print(''.join(row))

Measured memory_bytes: 53980
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <algorithm>
using namespace std;
const int N=100001;
int f[N];
int f1[N];
int d[N];
int n,ans,ans1;
int main()
{
	scanf("%d",&n);
	for(int i=n;i>=1;i--)
		scanf("%d",&d[i]);
	int len=1,len1=1;
	f[1]=f1[1]=d[1];
	for(int i=2;i<=n;i++)
	{
		if(f[len]>=d[i])
			f[++len]=d[i];
		else
		{
			int wz=upper_bound(f+1,f+1+len,d[i],greater<int >())-f;
			f[wz]=d[i];
		}
		if(f1[len1]<=d[i])
			f1[++len1]=d[i];
		else
		{
			int wz=upper_bound(f1+1,f1+1+len1,d[i])-f1;
			f1[wz]=d[i];
		}
	}
	printf("%d\n",len1);
	return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> P;
static const int MAX=500;
int N,t[MAX+1],s[MAX+1],c[MAX+1],f[MAX+1];
int main(){
    cin>>N;
    for(int i=1;i<N;i++){
        cin>>c[i]>>s[i]>>f[i];
    }

    for(int i=1;i<N;i++){
        t[i]=s[i];
        for(int j=i;j<N-1;j++){   
            t[i]+=c[j];
            while(t[i]%f[j+1]||t[i]<s[j+1])
                t[i]++;
        }
        t[i]+=c[N-1];
    }
    t[N]=0;

    for(int i=1;i<=N;i++){
        cout<<t[i]<<"\n";
    }

    return 0;
}


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

ll fact(ll n, int p){
  if (n == 0) return 0;
  return n/p + fact(n/p,p);
}

ll fact2(ll n, int p) {
  if (n % 2 == 1) return fact(n,p) - fact(n-1,p);
  if (p == 2) return fact(n/2, p) + n/2;
  return fact(n/2, p);
}

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

  if (n % 2 != 0){
    cout << 0 << endl;
    return 0;
  }

  ll ans = min(fact2(n, 2), fact2(n,5));
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3608
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial
from heapq import heappop, heappush, heappushpop
inf=float('inf')
mod = 10**9+7
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    # UnionFind
    class UnionFind():
        def __init__(self, n):
            self.nodes=[-1] * n  # nodes[x]: 負なら、絶対値が木の要素数

        def get_root(self, x):
            # nodes[x]が負ならxが根
            if self.nodes[x] < 0:
                return x
            # 根に直接つなぎ直しつつ、親を再帰的に探す
            else:
                self.nodes[x]=self.get_root(self.nodes[x])
                return self.nodes[x]

        def unite(self, x, y):
            root_x=self.get_root(x)
            root_y=self.get_root(y)
            # 根が同じなら変わらない
            # if root_x == root_y:
            # pass
            if root_x != root_y:
                # 大きい木の方につないだほうが計算量が減る
                if self.nodes[root_x] < self.nodes[root_y]:
                    big_root=root_x
                    small_root=root_y
                else:
                    small_root=root_x
                    big_root=root_y
                self.nodes[big_root] += self.nodes[small_root]
                self.nodes[small_root]=big_root
    
    N = I()
    uf=UnionFind(N)
    get_root, unite, nodes=uf.get_root, uf.unite, uf.nodes
    xlist = []
    ylist = []
    for i in range(N):
        x, y = MI()
        xlist.append((x, i))
        ylist.append((y, i))
    xlist.sort()
    ylist.sort()
    
    edges = [] #(重み、頂点a,b)
    for i in range(N - 1):
        edges.append((xlist[i+1][0]-xlist[i][0], xlist[i][1],xlist[i+1][1]))
        edges.append((ylist[i+1][0]-ylist[i][0],ylist[i][1], ylist[i + 1][1]))
    edges.sort(reverse=True)

    cnt = 1
    ans=0
    while cnt<N:
        c, a, b = edges.pop()
        if get_root(a) != get_root(b):
            unite(a, b)
            cnt += 1
            ans += c
    print(ans)
if __name__ == '__main__':
    main()

Measured memory_bytes: 119132
#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <set>
using namespace std;

#define rep(i,n) for(int i=0;i<(n);i++)
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define dbg(x) cout<<#x"="<<x<<endl

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<pii, int> ppi;

#define INF 1000000000

//decode num
int dc(char *n){
  int idx=0;
  int res=0;

  int sz=strlen(n);
  while(idx<sz){
    int current=1;
    if(n[idx]>='2' && n[idx]<='9'){
      current = n[idx] - '0';
      idx++;
    }
    switch(n[idx]){
    case 'm': current*=1000; break;
    case 'c': current*=100; break;
    case 'x': current*=10; break;
    }
    idx++;
    res+=current;
  }
  return res;
}

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

  while(n-->0){
    char n1[10], n2[10];
    scanf("%s %s", n1, n2);

    int num= dc(n1)+dc(n2);
    string res;

    rep(i,4){
      int k[]={1000,100,10,1};
      string c[]={"m","c","x","i"};
      if(num>=2*k[i]){
	res += (num/k[i]+'0');
	  res += c[i];
	num%=k[i];
      }
      else if(num>=k[i]){
	res += c[i];
	num%=k[i];
      }
    }
    cout << res<<endl;
  }
}

Measured memory_bytes: 1232
#include<bits/stdc++.h>
#define ios ios_base::sync_with_stdio(0);cin.tie(0);
using namespace std ;
typedef long long int ll ;
#define MXN 100005

bool b[MXN]={};

void p(){
	b[0]=b[1]=1;
	b[2]=0;
	for(int i=2; i<MXN; i++){
		if(!b[i]){
		for(int j=2*i; j<MXN; j+=i){
			b[j]=1; 
		}
	}
}
}

int main(){
	ios;
	int n;
	cin>>n;
	p();
	for(int i=n; i<MXN; i++){
		if(!b[i]){
			cout<<i<<"\n";
			return 0;
		}
	}

	return 0;
}



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

int main(){
    int slong[255],b,count, sum, check;
    char theme[255][255], str[255];
    sum = 0;
    scanf("%d",&b);
    for(int i = 0; i < b; i++){
        scanf("%s",theme[i]);
        scanf("%d",&slong[i]);
    }
    scanf("%s",str);

    for(count = 0; count < b; count++){
        if(strcmp(theme[count], str) == 0){
            break;
        }
    }

    for( check = count + 1; check < b; check++){
        sum = sum + slong[check];
    }

    printf("%d", sum);


    return 0;
}

Measured memory_bytes: 128
# coding: utf-8
# Your code here!
SIZE=300000; MOD=10**9+7 #998244353 #ここを変更する

inv = [0]*(SIZE+1)# inv[j] = j^{-1} mod MOD
fac = [0]*(SIZE+1)# fac[j] = j! mod MOD
finv = [0]*(SIZE+1)# finv[j] = (j!)^{-1} mod MOD
inv[1] = 1
fac[0] = fac[1] = 1
finv[0] = finv[1] = 1
for i in range(2,SIZE+1):
    inv[i] = MOD -(MOD//i)*inv[MOD%i]%MOD
    fac[i] = fac[i-1]*i%MOD
    finv[i]= finv[i-1]*inv[i]%MOD

def choose(n,r): # nCk mod MOD の計算
    if 0 <= r <= n:
        return (fac[n]*finv[r]%MOD)*finv[n-r]%MOD
    else:
        return 0


import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline #文字列入力のときは注意

n = int(input())
a = [int(i)-1 for i in readline().split()]

d = [-1]*n
for i,ai in enumerate(a):
    if d[ai] == -1:
        d[ai] = i
    else:
        p,q = d[ai], n-i
        break

#print(p,q)

"""
for k in range(1,n+2):
    res = 0
    for l in range(k):
        res += choose(p,l)*choose(q,k-1-l)
    
    print((choose(n+1,k) - res)%MOD)
"""

for k in range(1,n+2):
    res = choose(p+q,k-1)
    print((choose(n+1,k) - res)%MOD)

    







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

using namespace std;

#define int long long
#define all(v) begin(v), end(v)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for(int i = (int)(s); i < (int)(n); i++)

template<class T1, class T2> void chmin(T1 &a, T2 b){if(a>b)a=b;}
template<class T1, class T2> void chmax(T1 &a, T2 b){if(a<b)a=b;}

using pint = pair<int, int>;
using tint = tuple<int, int, int>;
using vint = vector<int>;

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

signed main()
{
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  int N, S[200002];
  cin >> N;
  rep(i, N) cin >> S[i];
  reps(i, 1, N+1) {
    if(N%i) continue;
    bool flag = true;
    rep(j, N-i) if(S[j] != S[j+i]) flag = false;
    if(flag) {
      cout << N / i << endl;
      return 0;
    }
  }

  return 0;
}

Measured memory_bytes: 4768
#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 = 10e15;
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)


//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);

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


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

    int ans = 0;

    for (int i = 0; i <= a; i++) {
        for (int j = 0; j <= b; j++) {
            for (int k = 0; k <= c; k++) {
                int now = i * 500 + j * 100 + k * 50;
                if (now == x) ans++;
            }
        }
    }

    cout << ans << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int MX = 1e5+2;
vector<int> adj[MX];
int seen[MX];
int main() {
	ios::sync_with_stdio(0);cin.tie(0);
	int n, u, v;
	cin >> n >> u >> v;
	for(int i=0; i<n-1; i++) {
		int a, b;
		cin >> a >> b;
		adj[a].push_back(b);
		adj[b].push_back(a);
	}
	queue<int> q1({u}), q2({v});
	seen[u] = 1;
	seen[v] = 2;
	int tm = 0, ans = 0;
	while(1) {
		int s = q1.size();
		while(s--) {
			int t = q1.front();
			q1.pop();
			for(int a: adj[t]) {
				if(!seen[a]) {
					seen[a] = 1;
					q1.push(a);
				}
			}
		}
		s = q2.size();
		while(s--) {
			int t = q2.front();
			q2.pop();
			for(int a: adj[t]) {
				if(seen[a] <= 1) {
					if(seen[a] == 1)
						ans = tm;
					seen[a] = 2;
					q2.push(a);
				}
			}
		}
		if(!q2.size()) {
			return !(cout << ans);
		}
		tm++;
	}
}

Measured memory_bytes: 6392
# -*- coding: utf-8 -*-
N = int(input())

prime = [2]
for n in range(3,55555+1):
    flag = True
    for p in prime:
        if n%p==0:
            flag = False
            break
        if n<p*p:
            break
    if flag:
        prime.append(n)

ret = []
for n in prime:
    if len(ret)==N:
        break
    if n%5==1:
        ret.append(str(n))
print(" ".join(ret))


Measured memory_bytes: 3188
#include <stdio.h>

int main()
{
  int n, a, i, x;
  int max = 0;
  int min = 1000;

  scanf("%d", &n);
  for(i=0;i<n;i++)
  {
    scanf("%d", &a);
    if(max < a)
    {
      max = a;
    }
    if(a < min)
    {
      min = a;
    }
  }

  x = max - min;
  printf("%d", x);

  return 0;
}

Measured memory_bytes: 128
N,M=map(int,input().split())
a=[]
b=[]
for i in range(M):
	X,Y=map(int,input().split())
	a.append(X)
	b.append(Y)
if min(b)<max(a):
	print(0)
else:
	print(min(b)-max(a)+1)

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

using namespace std;
#define ll  long long
#define ld  long double
#define endl '\n'
#define FAST ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const ll mod = 998244353;
const double PI = 3.141592653589793238463;
const int MAXN = 2e5 + 5;

ll fastPow(ll x, ll b) {
    if (b == 0)
        return 1;
    else if (!(b & 1)) {
        return fastPow(x * x, b / 2);
    } else
        return x * fastPow(x * x, (b - 1) / 2);
}

//__builtin_popcount ();
int main() {
    FAST
int n,m;
    cin>>n>>m;
    int f=n*(n-1)/2;
    int s=m*(m-1)/2;
cout<<f+s<<endl;
    return 0;
}

Measured memory_bytes: 256
parseInt(x::String) = parse(Int, x)
parseInt(x::SubString{String}) = parse(Int, x)
parseInt(x::Char) = parse(Int, x)
parseInt(x::Float64) = trunc(Int, x)
parseFloat(x::String) = parse(Float64, x)
parseFloat(x::Int) = trunc(Float64, x)
parseFloat(x::SubString{String}) = parse(Float64, x)
parseFloat(x::Char) = parse(Float64, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
    s=readline()
    println(findlast(x->x=='Z',s)-findfirst(x->x=='A',s)+1)
end
main()

Measured memory_bytes: 112136
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            string input;

            int[] rankL = new int[4];
            int[] rankR = new int[4];

            while (!string.IsNullOrEmpty(input = Console.ReadLine()))
            {
                string[] temp = input.Split(' ');
                double l = double.Parse(temp[0]);
                double r = double.Parse(temp[1]);

                rankL[Check(l)]++;
                rankR[Check(r)]++;
            }

            for (int i = 0; i < 4; i++)
            {
                Console.WriteLine("{0} {1}", rankL[i], rankR[i]);
            }
        }

        static int Check(double d)
        {
            if (d < 0.2) return 3;
            if (d < 0.6) return 2;
            if (d < 1.1) return 1;
            return 0;
        }
    }
}

Measured memory_bytes: 9236
import java.util.Scanner;

public class Main
{
 public static void main(String[] args)
 {
 // ?¨??????\??????????????????????????????????????????
  Scanner sc = new Scanner(System.in); int w = sc.nextInt();
  int n = sc.nextInt();
  int[] values = new int[w];
  for (int i = 0; i < values.length; i++)
  {
   values[i] = i + 1;
  }
  for (int i = 0; i < n; i++)
  {
   String str = sc.next();
   String[] ab = str.split(",");
   int a = Integer.parseInt(ab[0]) - 1;
   int b = Integer.parseInt(ab[1]) - 1;

   int c = values[a];
   values[a] = values[b];
   values[b] = c;
  }
  for(int i=0;i<values.length;i++)
  {
   System.out.println(values[i]);
  }
 }
}

Measured memory_bytes: 26144
#include<bits/stdc++.h>
using namespace std;
long N,M,K,ans,a[1<<18],b[1<<18];
int main(){
	cin>>N>>M>>K;
	for(int i=1;i<=N;i++)cin>>a[i],a[i]=a[i-1]+a[i];
	for(int i=1;i<=M;i++)cin>>b[i],b[i]=b[i-1]+b[i];
	for(int i=0;i<=N;i++)if(K>=a[i])ans=max(ans,upper_bound(b+1,b+M+1,K-a[i])-b-1+i);
	cout<<ans;
}

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

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()

int f(int n)
{
    return ((n % 2 == 0) ? n / 2 : 3 * n + 1);
}

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

    cout << n+m/2 << '\n';
    return 0;
}


Measured memory_bytes: 3632
#include<iostream>
#include<cstring>
#include<algorithm>
#include<vector>
#include<cmath>
#include<limits>
#define ll long long
#define ALL(x) (x).begin(),(x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define MAX 1000000
using namespace std;
int main(){
  int N;
  cin >> N;
  vector<int> cnt(MAX);// N >= 3 implicitly
  vector<int> sub(MAX);
  rep(i,N){
    int a;
    cin >> a;
    cnt[a]++;
  }
  //cout << 1 << endl;
  for(int i = 1; i < MAX - 1; i++){
    sub[i-1] = cnt[i-1] + cnt[i] + cnt[i+1];
    //cout << i << endl;
  }
  vector<int>::iterator iter = max_element(ALL(sub));
  size_t index = distance(sub.begin(),iter);
  //cout << 2 << endl;
  cout << sub[index] << endl;

}


Measured memory_bytes: 8064
size = input().split(' ')
H = int(size[0])
W = int(size[1])
S = []
for k in range(H):
    row = input()
    S.append(row)

answer = 'Yes'
for i in range(H):
    for j in range(W):
        #if S[i][j] == '#':
            #print('i={},j={},i-1={},i+1={},j-1={},j+1={}'.format(i,j,i-1,i+1,j-1,j+1))
        if (S[i][j] == '#') and (((i - 1) >= 0) and (S[i-1][j] != '#')) and (((j - 1) >= 0) and (S[i][j-1] != '#')) and (((j + 1) < W) and (S[i][j+1] != '#')) and (((i + 1) < H) and (S[i+1][j] != '#')):
            answer = 'No'
            break
print(answer)


Measured memory_bytes: 3064