akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

// 最大公約数
ll gcd(ll a,ll b){
   if (a%b == 0) return(b);
   else return(gcd(b, a%b));
}

// 最小公倍数
ll lcm(ll a, ll b){
    return a*b/gcd(a, b);
}

int main()
{
    cout << fixed << setprecision(15);
    ll N;
    cin >> N;

    if(N%2 == 0){
        cout << 0.5 << endl;
    }
    else{
        cout << double(N/2+1) /double(N) << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#define INF -1
#define N 2000005

int heap_size = 0, A[N];

void maxHeapify(int i){
  int l, r, largest, tmp;

  l = getLeft(i);
  r = getRight(i);
  if(l <= heap_size && A[l] > A[i]){
    largest = l;
  }else{
    largest = i;
  }
  if(r <= heap_size && A[r] > A[largest]){
    largest = r;
  }
  if(largest != i){
    tmp = A[i];
    A[i] = A[largest];
    A[largest] = tmp;
    maxHeapify(largest);
  }
}

int getLeft(int i){
  return i *= 2;
}

int getRight(int i){
  return i = i * 2 + 1;
}

int getParent(int i){
  return i = i / 2;
}

int heapExtractMax(){
  int max;
  if(heap_size < 1){
    printf("error\n");
    return;
  }
    max = A[1];
    A[1] = A[heap_size];
    heap_size = heap_size - 1;
    maxHeapify(1);
    return max;
}

void heapIncreaseKey(int i, int key){
  int tmp;
  if(key < A[i]){
    return;
  }
  A[i] = key;
  while(i > 1 && A[getParent(i)] < A[i]){
    tmp = A[i];
    A[i] = A[getParent(i)];
    A[getParent(i)] = tmp;
    i = getParent(i);
  }
}

void maxHeapInsert(int key){
  heap_size = heap_size + 1;
  A[heap_size] = INF;
  heapIncreaseKey(heap_size, key);
}

main(){
  int i, key;
  char com[20];

  while(scanf("%s", com), strcmp(com, "end")){
    if(com[0] == 'i'){
      scanf("%d", &key);
      maxHeapInsert(key);
    }
    if(com[0] == 'e'){
      printf("%d\n", heapExtractMax());
    }
  }
  return 0;
}

Measured memory_bytes: 4692
n = int(input())
dp = [float("inf")]*(n+1)
dp[0] = 0
for i in range(n):
	j = 0
	while i+6**j <= n:
		dp[i+6**j] = min(dp[i+6**j],dp[i]+1)
		j += 1
	k = 0
	while i+9**k <= n:
		dp[i+9**k] = min(dp[i+9**k],dp[i]+1)
		k += 1
print(dp[n])

Measured memory_bytes: 3828
def ismof9(n):
    _str = str(n)
    _sum = 0
    for ch in _str:
        _sum += int(ch)
    if _sum % 9 == 0:
        return "Yes"
    else:
        return "No"


def main():
    n = int(input())
    print(ismof9(n))

main()


Measured memory_bytes: 9284
import sys
sys.setrecursionlimit(100000)

N = int(input())
T = []
for i in range(N):
    T.append(int(input()))

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

lcm = 1
for i in T:
    lcm = int(lcm * i // gcd(lcm, i))

print(lcm)

Measured memory_bytes: 3060
#include<stdio.h>

int main(){
	int a,b,c;
	scanf("%d %d %d",&a,&b,&c);
	while(c!=0){
		if(a%2==1)
			a--;
		a=a/2;
		b=b+a;
		c--;
		if(c==0)
			break;
		if(b%2==1)
			b--;
		b=b/2;
		a=a+b;
		c--;
	}
	printf("%d %d\n",a,b);
}

Measured memory_bytes: 128
N, L = map(int, input().split())

ans = 0
for i in range(1, N+1):
    ans += L+i-1
    

if L+N-1 < 0:
    ans -= (L+N-1)
elif L <= 0 <= L+N-1:
    ans = ans
else:
    ans -= L
print(ans)


Measured memory_bytes: 9120
#include<stdio.h>
long long MAX(long long a,long long b){return  a<b?b:a;}
int main(){
  long long n,i,j,s,a,m,b[1010];
  while(scanf("%lld",&n),n){
    for(i=0;i<1010;i++)b[i]=0;
    for(i=s=0;i<n;i++){
      scanf("%lld",&a);
      s+=a;
    }
    for(i=0;i<n-1;i++){
      scanf("%lld",&a);
      b[a]++;
    }
    a=n;
    m=0;
    for(i=1000;i;i--){
      for(j=0;j<b[i];j++){
	m=MAX(m,s*a);
	a--;
	s+=i;
      }
    }
    printf("%lld\n",MAX(m,s));
  }
  return 0;
}



Measured memory_bytes: 2104
#n//m=kかつn%m=kはつまりn=k(m+1)、また、k<m

n=int(input())

sq = int(n**(1/2))+2
ans = 0
for i in range(1,sq):
    if n%i==0:
        j = n//i-1
        if j:#nが小さいと0になる？
            if n//j==n%j:#境界処理が面倒なので試す
                ans +=j

print(ans)



Measured memory_bytes: 40172
n=input()
a=raw_input()
la=len(a)
count=0
for r in range(n):
	b=raw_input()
	lb=len(b)
	flag=0
	for skip in range(lb):
		for ini in range(lb-(skip+1)*(la-1)):
			if b[ini:ini+(skip+1)*la:skip+1]==a:
				count+=1
				flag=1
				break
		if flag==1:break
print count
	

Measured memory_bytes: 4232
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#define ll long long
#define ull unsigned long long
#define dd double
#define oo 1001007000
#define ff float
#define ooo 1000000100000000000
#define iii pair<ll,ll>
#define vii vector<ll>
#define viii vector<iii>
#define sss pair<str,str>
#define str string
#define sii set<ll>
#define siii set<iii>
#define st size_t
#define r0 return 0
#define pb push_back
#define sz size
using namespace std;

const char E='\n';
const int N=2015;
const int NN=1000001;
const ll md=998244353;


int main(){
    cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);
    int a,b,c;
    cin >> a >> b >> c;
    cout << c << " " << a << " " << b << E;
    r0;
}


Measured memory_bytes: 256
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let v = read_vec::<usize>();
    let (w, h) = (v[0], v[1]);
    let mut p = vec![0i64; w];
    for i in 0..w {
        p[i] = read();
    }
    let mut q = vec![0i64; h];
    for i in 0..h {
        q[i] = read();
    }

    let mut que = BinaryHeap::new();
    for num in p {
        que.push((-num, 'W'));
    }
    for num in q {
        que.push((-num, 'H'));
    }

    let mut w_count = w as i64 + 1;
    let mut h_count = h as i64 + 1;

    let mut ans = 0;
    while let Some((num, dir)) = que.pop() {
        if dir == 'W' {
            w_count -= 1;
            ans -= h_count * num;
        } else {
            h_count -= 1;
            ans -= w_count * num;
        }
    }
    println!("{}", ans);
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


Measured memory_bytes: 12140
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
 
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef long double ld; 
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds;

vector<int> fact;
vector<int> ifact;
vector<int> inv;
vector<int> pow2;
const int MOD = 998244353;
int add(int a, int b)
{
	a+=b;
	while(a>=MOD) a-=MOD;
	return a;
}
void radd(int &a, int b)
{
	a=add(a,b); 
}
int mult(int a, int b)
{
	return (a*1LL*b)%MOD;
}
void rmult(int &a, int b)
{
	a=mult(a,b);
}
int modpow(int a, int b)
{
	int r=1;
	while(b)
	{
		if(b&1) r=mult(r,a);
		a=mult(a,a);
		b>>=1;
	}
	return r;
}
int choose(int a, int b)
{
	if(a<b) return 0;
	if(b==0) return 1;
	if(a==b) return 1;
	return mult(fact[a],mult(ifact[b],ifact[a-b]));
}
int inverse(int a)
{
	return modpow(a,MOD-2);
}
void init(int _n)
{
	fact.clear(); ifact.clear(); inv.clear(); pow2.clear();
	fact.resize(_n+1);
	ifact.resize(_n+1);
	inv.resize(_n+1);
	pow2.resize(_n+1);
	pow2[0]=1;
	ifact[0]=1;
	fact[0]=1;
	for(int i=1;i<=_n;i++)
	{
		pow2[i]=add(pow2[i-1],pow2[i-1]);
		fact[i]=mult(fact[i-1],i);
		//ifact[i]=mult(ifact[i-1],inv[i]);
	}
	ifact[_n] = inverse(fact[_n]);
	for(int i=_n-1;i>=1;i--)
	{
		ifact[i] = mult(ifact[i + 1], i + 1);
	}
	for(int i=1;i<=_n;i++)
	{
		inv[i] = mult(fact[i-1],ifact[i]);
	}
}

int dp[3333][3333];

int a,b,c,d; 

int solve(int n, int m)
{
	if(n<a||m<b) return 0;
	if(n==a&&m==b) return 1;
	if(dp[n][m]!=-1) return dp[n][m];
	int ans=0;
	if(n==a)
	{
		ans=mult(a,solve(n,m-1));
	}
	else if(m==b)
	{
		ans=mult(b,solve(n-1,m));
	}
	else
	{
		ans=mult(m,solve(n-1,m));
		radd(ans,mult(n,solve(n,m-1)));
		radd(ans,MOD-mult((n-1)*(m-1),solve(n-1,m-1)));
		//ans=mult(m-1,solve(n-1,m));
		//radd(ans,solve(n-1,m));
		//radd(ans,solve(n,m-1));
		//radd(ans,mult(n+m-2,solve(n-1,m-1)));
	}
	return (dp[n][m]=ans);
}

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	init(5555);
	cin>>a>>b>>c>>d;
	memset(dp,-1,sizeof(dp));
	cout<<solve(c,d)<<'\n';
}


Measured memory_bytes: 47516
n = int(input())
ab = [list(map(int, input().split())) for _ in range(n - 1)]

adj = [[] for _ in range(n)]
for a, b in ab:
    a -= 1
    b -= 1
    adj[a].append(b)
    adj[b].append(a)


def dfs(s):
    d = [-1] * n
    p = [-1] * n
    d[s] = 0
    stack = [s]
    while stack:
        u = stack.pop()
        for v in adj[u]:
            if d[v] == -1:
                d[v] = d[u] + 1
                p[v] = u
                stack.append(v)

    return d, p


depth, par = dfs(0)
rev = (depth[n-1] - 1) // 2
root = n - 1
for _ in range(rev):
    root = par[root]

p = par[root]
adj[p].remove(root)
adj[root].remove(p)

depth, _ = dfs(n-1)
snuke = len([e for e in depth if e != -1])
fennec = n - snuke
if fennec > snuke:
    ans = "Fennec"
else:
    ans = "Snuke"
print(ans)



Measured memory_bytes: 48808
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        try (Scanner sc = new Scanner(System.in)) {
            String S = sc.next();
            StringBuilder xxx = new StringBuilder();
            for (int j = 0; j < S.length(); j++) {
                xxx.append("x");
            }
            System.out.println(xxx.toString());
        }
    }
}

Measured memory_bytes: 26684
#include<bits/stdc++.h>
using namespace std;
#define maxn 2010
int pos[2][maxn];
int dp[maxn][maxn],cost1[maxn][maxn],cost2[maxn][maxn];
main()
{
    int n;scanf("%d",&n);
    for(int i=1;i<=2*n;i++)
    {
        int x;char c[2];
        scanf("%s %d",c,&x);
        if(c[0]=='B')pos[0][x]=i;
        else pos[1][x]=i;
    }
    for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)
    {
        cost1[i][j]=cost1[i][j-1];
        cost2[j][i]=cost2[j][i-1];
        if(pos[0][i]<pos[1][j])cost1[i][j]++;
        else cost2[j][i]++;
    }
    for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)
        dp[i][j]=min(dp[i-1][j]+cost1[i][j],dp[i][j-1]+cost2[j][i]);
    int ans=0;
    for(int i=1;i<=n;i++)for(int j=i+1;j<=n;j++)
    {
        if(pos[0][i]>pos[0][j])ans++;
        if(pos[1][i]>pos[1][j])ans++;
    }
    printf("%d\n",ans+dp[n][n]);
    return 0;
}


Measured memory_bytes: 47488
#include <bits/stdc++.h>
#define lli long long int
#define vec2 vector<vector<lli>>
#define fio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define FRE freopen("input.txt","r",stdin);freopen("ans.txt","w",stdout)
#define mp make_pair
#define pll pair <lli,lli>
#define vll vector <lli>
#define pq2 priority_queue<pair<lli,lli>>
#define f first
#define s second
#define pb push_back
#define pf push_front
#define minii LLONG_MAX
#define all(x) x.begin(), x.end()
#define mem(a,b) memset(a,b,sizeof(a))
#define ld long double
const long double pi = 3.1415926535898;
#define dec greater<lli>()
const lli mod=1000000007;
//const lli mod=100000000;
using namespace std;
lli lcm (lli a, lli b) {return ((a*b)/__gcd(a,b));}
lli modpower (lli a,lli b)
{
    if(b==0) return 1;
    lli c=modpower(a,b/2)%mod;
    if (b%2) return (((a*c)%mod)*c)%mod;
    else return (c*c)%mod;
}
lli power (lli a,lli b)
{
    if(b==0) return 1;
    lli c=power(a,b/2);
    if (b%2) return (a*c*c);
    else return c*c;
}
bool prime (lli k)
{
    if (k==1||k==0) return 0;
    bool flag=1;
    lli a=sqrt(k);
    for (int i=2;i<=a;i++)
    {
        if (k%i==0)
        {flag=0;break;}
    }
    return flag;
}
lli sieve (int n)
{
    bool qrr[n+1];
    for (int i=0;i<=n;i++)
    qrr[i]=1;qrr[0]=0;qrr[1]=0;
    for (int i=2;i<=n;i++)
    {
        if (qrr[i]==1)
        {
            for (int j=i;j<=n;j+=i)
            {qrr[j]=0;}
        }
    }
    return 0;
}
lli a[500005],last[500005]={-1},fen[500005],n;
lli update(lli i,lli x)
{
    while (i<=n)
    {
        fen[i]+=x;
        i+=i&(-i);
    }
    return 0;
}
lli soln(lli i)
{
    lli sum=0;
    while (i>=1)
    {
        sum+=fen[i];
        i-=i&(-i);
    }
    return sum;
}
int main()
{
    lli q;
    cin>>n>>q;
    for (int i=1;i<=n;i++)
    cin>>a[i];
    vector <pair<pll,lli>> qq;
    lli ans[q+5];
    lli l,r;
    for (int i=0;i<q;i++)
    {
        cin>>l>>r;
        qq.pb({{r,l},i});
    }
    int j=1;
    sort(all(qq));
    for (int i=0;i<q;i++)
    {
        l=qq[i].f.s;
        r=qq[i].f.f;
        while (j<=r)
        {
            //cout<<last[a[j]]<<" "<<j<<"\n";
            if (last[a[j]]==0)
            {
                last[a[j]]=j;
                update(j,1);
            }
            else
            {
                //cout<<last[a[j]]<<" "<<j<<"\n";
                update(last[a[j]],-1);
                last[a[j]]=j;
                update(j,1);
            }
            j++;
        }
        ans[qq[i].s]=soln(r)-soln(l-1);
    }
    for (int i=0;i<q;i++)
    cout<<ans[i]<<"\n";
    return 0;
}

Measured memory_bytes: 31224
#include "bits/stdc++.h"
using namespace std;
const int N = 2e5 + 5;
const int M = 100000000;
const double pi = acos(-1);
int n;
pair < int , int > arr[N];
int dp[N];
int bit[N];
map < int , int > mp;
int ori[N];
void update(int idx , int val){
	while(idx <= n){
		bit[idx] = max(bit[idx] , val);
		idx += idx & -idx;
	}
}
int query(int idx){
	int res = 0;
	while(idx){
		res = max(res , bit[idx]);
		idx -= idx & -idx;
	}
	return res;
}
int main(){
	int x1 , y1 , x2 , y2;
	scanf("%d %d %d %d" , &x1 , &y1 , &x2 , &y2);
	scanf("%d" , &n);
	for(int i = 1 ; i <= n ; ++i){
		scanf("%d %d" , &arr[i].first , &arr[i].second);
	}
	if(x1 > x2){
		x1 = M - x1;
		x2 = M - x2;
		for(int i = 1 ; i <= n ; ++i){
			arr[i].first = M - arr[i].first;
		}
	}
	if(y1 > y2){
		y1 = M - y1;
		y2 = M - y2;
		for(int i = 1 ; i <= n ; ++i){
			arr[i].second = M - arr[i].second;
		}
	}
	mp.clear();
	for(int i = 1 ; i <= n ; ++i){
		mp[arr[i].second];	
	}
	int cur = 0;
	for(auto &it : mp){
		it.second = ++cur;
		ori[cur] = it.first;
	}
	for(int i = 1 ; i <= n ; ++i){
		arr[i].second = mp[arr[i].second];
	}
	sort(arr + 1 , arr + 1 + n);
	int profit = 0;
	for(int i = 1 ; i <= n ; ++i){
		if(arr[i].first < x1 || arr[i].first > x2 || ori[arr[i].second] < y1 || ori[arr[i].second] > y2){
			continue;
		}
		dp[i] = query(arr[i].second - 1) + 1;
		update(arr[i].second , dp[i]);
		profit = max(profit , dp[i]);
	}
	printf("%.12lf\n" , (x2 - x1 + y2 - y1) * 100LL - 10LL * ((2.0 - (pi / 2.0)) * profit) + ((profit > min(y2 - y1 , x2 - x1)) ? 5 * pi : 0));
}

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

int n,k;
int w[1000000];

int nn(int n){
   int sum=1;
   rep(i,n) sum *= (i+1);
   return sum;
}
int main(){
   int n;
   cin >> n;
   int x[n],y[n];
   rep(i,n)cin >> x[i] >> y[i];

   double distance,sum=0;
  
   rep(i,n-1){
      for(int k=i+1;k<n;k++){
         distance += sqrt(pow(x[i]-x[k],2)+pow(y[i]-y[k],2));
      }
      sum += distance*2*nn(n-1);
      distance = 0;
   }
   
  
   cout <<fixed<< sum/nn(n) << endl;
   return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

void trace(int A[], int N) {
	int i;
	for (i = 0; i < N; i++) {
		if (i > 0)printf(" ");
		printf("%d", A[i]);
	}
	printf("\n");
}

void insertionSort(int A[], int N) {
	int j, i, v;
	for (i = 1; i < N; i++) {
		v = A[i];
		j = i - 1;
		while (j >= 0 && A[j]>v) {
			A[j + 1] = A[j];
			j--;
		}
		A[j + 1] = v;
		trace(A, N);
	}
}

int main(void) {
	int N, i, j;
	int A[100];

	scanf("%d", &N);
	for (i = 0; i < N; i++) {
		scanf("%d", &A[i]);
	}

	trace(A, N);
	insertionSort(A, N);

	return 0;

}

Measured memory_bytes: 604
#include <bits/stdc++.h>
    using namespace std;
     
    int main() {
      int n;
      bool j = false;
      string a;
      cin >> n;
      
      for (int i=0; i < n; i++){
        cin >> a;
        if (a == "Y"){
          j = true;
          break;
        }
        else{
          continue;
        }
      }
      
      if (j == true){
        cout << "Four" << endl;
      }
      else {
        cout << "Three" << endl;
      }
      
    }

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

func print(A []int) {
	s := make([]string, len(A))
	for i, o := range A {
		s[i] = strconv.Itoa(o)
	}
	fmt.Println(strings.Join(s, " "))
}

func main() {
	var sc = bufio.NewScanner(os.Stdin)

	sc.Scan()
	N, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}

	sc.Scan()
	A := make([]int, N)
	for i, v := range strings.Split(sc.Text(), " ") {
		n, e := strconv.Atoi(v)
		if e != nil {
			panic(e)
		}
		A[i] = n
	}

	c := 0
	for i := 0; i < N-1; i++ {
		min := i
		for j := i + 1; j < N; j++ {
			if A[j] < A[min] {
				min = j
			}
		}
		if min != i {
			A[i], A[min] = A[min], A[i]
			c++
		}
	}
	print(A)
	fmt.Println(c)
}


Measured memory_bytes: 1120
#include <iostream>
#include <cstdio>
#include <set>
#include <algorithm>
using namespace std;

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

    long long a[n];

    for(long long i = 0; i < n; i++) cin >> a[i];

    multiset<long long> T;

    for(long long i = 0; i < n; i++){
        auto it = T.lower_bound(a[i]);

        if(it != T.begin()) T.erase(--it);
        T.insert(a[i]);
    }

    cout << T.size() << endl;
    return 0;
}

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

#define REP(i,n) for(auto i=0;i<n;++i)
#define REPR(i,n) for(auto i=n;i>=0;--i)
#define REPI(itr,v) for(auto itr=v.begin();itr!=v.end();++itr)
#define REPIR(itr,v) for(auto itr=v.rbegin();itr!=v.rend();++itr)
#define FOR(i,a,b) for(auto i=a;i<b;++i)
#define SORT(v,n) sort(v, v+n)
#define SORTV(v) sort(v.begin(), v.end())
#define ALL(v) v.begin(),v.end()
#define llong long long
#define ll long long
#define INF 999999999
#define MOD 1000000007
#define pb push_back
#define pf push_front
#define MP make_pair
#define SV(n,v) {int tmp;for(int i=0;i<n;++i){scanf("%d",&tmp);v.push_back(tmp);}}

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

using namespace std;

typedef pair<int,int> pii;

int main(){

  int n;
  scanf("%d", &n);

  vector<int> v;
  SV(n,v);

  int ans = -1;
  REP(i,n){
    REP(j,n){
      if(i != j){
        ans = max(ans, abs(v[i] - v[j]));
      }
    }
  }
  printf("%d\n", ans);

  return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FIXED_FLOAT(x) std::fixed <<std::setprecision(2)<<(x)
#define what_is(x) cerr << #x << " is " << x << endl;
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define inf std::numeric_limits<int>::max();
#define highest_2_pow(n)  __builtin_clzll((long long)0)- __builtin_clzll((long long)n) - 1
//-----------------------------------------------------------------------------------------------------
#define lli long long int 
#define int long long
#define all(x)            (x).begin(),(x).end()
#define uniq(v)           (v).erase(unique(all(v)),(v).end())
#define sz(x)             (int)((x).size())
#define fr                first
#define sc                second
#define pii               pair<int,int>
#define vi vector<int>
#define vlli vector<long long int>
#define si set<int>
#define slli set<long long int>
#define mt make_tuple
#define mp make_pair
#define eb emplace_back
#define mem1(a)           memset(a,-1,sizeof(a))
#define mem0(a)           memset(a,0,sizeof(a))
#define ppc               __builtin_popcount
#define ppcll             __builtin_popcountll
//---------------------------------------------------
using namespace std;
// GCD and LCM are available
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
cerr << *it << " = " << a << endl;
err(++it, args...);
}

void faster(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
}
void solve(){
    int n,k;
    cin>>n>>k;
    string s;
    cin>>s;
    vector<int> arr;
    if(s[0]=='0') arr.eb(0);
    int cnt;
    // cout<<"hey!"<<endl;
    for(int i=1;i<s.size();i++){
        // cout<<"-- "<<i<<endl;
        cnt=1;
        while(i<s.size() && s[i]==s[i-1]){ 
            cnt++;
            i++;
        }
        arr.eb(cnt);
    }
    
    if(s.back()=='0') arr.eb(0);
    vector<int> sum(arr.size()+1,0);
    // cout<<"here1"<<endl;
    rep(i,0,arr.size()) sum[i+1] = sum[i] + arr[i];
    int ans=1,right;
    for(int left=0;left<sum.size();left+=2){
        right = left+2*k+1;
        if(right>=sum.size()) right = sz(sum)-1;
        ans = max(ans,sum[right]-sum[left]);
    }
    cout<<ans<<endl;
        

}
signed main()
{
    faster();
    int t=1;
    //cin>>t;
    while(t--) solve();
}

Measured memory_bytes: 2116
import sys
INPUT = sys.stdin.readline
S = list(input())
S.reverse()
L = len(S)
A, B, C = 'A', 'B', 'C'

followingAs = 0
searchABC = 0
ans = 0

while S:

    last = S.pop()

    if last == A:
        if searchABC == 0:
            searchABC = 1
            followingAs += 1
            continue
        
        elif searchABC == 1:
            followingAs += 1
            continue
        
        else: #searchABC == 2:
            searchABC = 1
            followingAs = 1
            continue
    
    elif last == B:
        if searchABC == 0:
            continue

        elif searchABC == 1:
            searchABC += 1
            continue

        else: # searchABC == 2:
            searchABC = 0
            followingAs = 0
            continue

    else: # last == C

        if searchABC == 0:
            continue

        elif searchABC == 1:
            followingAs = 0
            searchABC = 0
            continue

        else:
            ans += followingAs
            searchABC = 1
            continue

print(ans)

Measured memory_bytes: 4968
#include <iostream>
#include <fstream>
#include <cassert>
#include <typeinfo>
#include <vector>
#include <stack>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <iomanip>
#include <cctype>
#include <random>
#include <time.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<P,int> pip;
typedef vector<pip> vip;
const int inf=1<<28;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

int n,w;
vi a;

int main(){
	cin>>n>>w;
	a=vi(n);
	for(int i=0;i<n;i++) cin>>a[i];
	sort(a.begin(),a.end());
	vi dp(w+1,1);
	int s=0;
	for(int i=0;i<n;i++){
		int A=a[i];
		s+=A;
		vi DP(w+1);
		for(int j=0;j<=w;j++){
			if(j>=A) DP[j]=dp[j-A];
			if(j<s) (DP[j]+=dp[j])%=mod;
		}
		dp=DP;
	}
	cout<<dp[w]<<endl;
}

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

using namespace std;

using i64 = int64_t;

const i64 MOD = 1e9+7;

const i64 INF = 1e18+7;


signed main(){
    int a, b, c, d, n, m, x, y, h, w;
    string s, t;


    auto Yes = [&](bool t){
        cout << (t ? "Yes" : "No") << endl;
    };
    auto YES = [&](bool t){
        cout << (t ? "YES" : "NO") << endl;
    };
    auto tri = [&](bool t, string a, string b){
        cout << (t ? a : b) << endl;
    };

    cin >> h >> w >> n;
    vector<vector<int>> v(h, vector<int>(w, 0));
    for(int i = 0; i < n; ++i){
        cin >> x >> y >> a;
        if(a == 1){
            for(int ii = 0; ii < x; ++ii)
                for(int jj = 0; jj < w; ++jj)
                    v[ii][jj] = 1;
        }
        if(a == 2){
            for(int ii = x; ii < h; ++ii)
                for(int jj = 0; jj < w; ++jj)
                    v[ii][jj] = 1;
        }
        if(a == 3){
            for(int jj = 0; jj < y; ++jj)
                for(int ii = 0; ii < h; ++ii)
                    v[ii][jj] = 1;
        }
        if(a == 4){
            for(int jj = y; jj < w; ++jj)
                for(int ii = 0; ii < h; ++ii)
                    v[ii][jj] = 1;
        }
    }

    x = 0;
    for(int i = 0; i < h; ++i)
        for(int j = 0; j < w; ++j)
            x += v[i][j];
    cout << h * w - x << endl;

}


Measured memory_bytes: 256
// clang-format off
#include <bits/stdc++.h>

#define mp make_pair
#define fst first
#define snd second
#define forn(i,n) for (int i = 0; i < int(n); i++)
#define forn1(i,n) for (int i = 1; i <= int(n); i++)
#define popcnt __builtin_popcount
#define ffs __builtin_ffs
#define ctz __builtin_ctz
#define clz __builtin_clz
#define all(a) (a).begin(), (a).end()
 
using namespace std;

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pli = pair<ll,int>;
using pil = pair<int,ll>;
using pll = pair<ll,ll>;
template <typename T> using vec = vector<T>;
using vi = vec<int>;
using vl = vec<ll>;
template <typename T> using que = queue<T>;
template <typename T> using deq = deque<T>;

template <typename T> T id(T b) {return b;};
template <typename T> void chmax(T &x, T y) {if (x < y) x = y;}
template <typename T> void chmin(T &x, T y) {if (x > y) x = y;}
template <typename S, typename K> bool contains(S &s, K k) { return s.find(k) != s.end(); }
void fastio() { ios_base::sync_with_stdio(false); cin.tie(nullptr); }
constexpr ll TEN(int n) { if (n == 0) return 1LL; else return 10LL*TEN(n-1); }
// clang-format on

int main() {
    fastio();

    int n;
    ll d;

    cin >> n >> d;
    int ans = 0;
    forn(i, n) {
        ll x, y;
        cin >> x >> y;
        if (x * x + y * y <= d * d) {
            ans++;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3612
import sys
if sys.version_info.minor >= 5:
    from math import gcd
else:
    from fractions import gcd



N = int(input())
As = list(map(int, input().split()))

left_gcds = [gcd(As[0], As[0])]
for i in range(1, len(As)):
    left_gcds.append(gcd(left_gcds[i-1], As[i]))

right_gcds = [gcd(As[-1], As[-1])]
for i in range(1, len(As)):
    right_gcds.append(gcd(right_gcds[i-1], As[-(i+1)]))
right_gcds.reverse()

gcds = []
for i in range(N):
    if i == 0:
        gcds.append(right_gcds[1])
    elif i == N-1:
        gcds.append(left_gcds[-2])
    else:
        gcds.append(gcd(left_gcds[i-1], right_gcds[i+1]))
print(max(gcds))

Measured memory_bytes: 16156
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))
a,b = iim()

ans = 0

if a>b:
    ans += a
    ans += max(a-1,b)
else:
    ans += b
    ans += max(a,b-1)

print(ans)

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

int main(){
  int dp[100010][3];
  int n;
  cin >> n;
  int a[n][3];
  
  for(int q=0;q<3;q++){
     cin >> dp[0][q];
   }
  
    if(n==1){int ans2 =max(dp[0][2],max(dp[0][0],dp[0][1]));
  cout << ans2 << endl;
            return 0;}
  
  
  for(int i=1;i<n;i++){
   for(int q=0;q<3;q++){
     cin >> a[i][q];
   }
  }
  
  for(int i=0;i<n;i++){
    dp[i+1][0]=a[i+1][0]+max(dp[i][1],dp[i][2]);
    dp[i+1][1]=a[i+1][1]+max(dp[i][2],dp[i][0]);
    dp[i+1][2]=a[i+1][2]+max(dp[i][1],dp[i][0]);
  }
  int ans =max(dp[n-1][2],max(dp[n-1][0],dp[n-1][1]));
  cout << ans << endl;
}

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

#define all(x)        (x).begin(),(x).end()
#define eb            emplace_back
#define mp            make_pair
#define pb            push_back
#define fi            first
#define se            second
#define sz(x)         ((int)(x).size())
#define rep(x,y,z)    for(int x=y;x<z;x++)
#define per(x,z,y)    for(int x=z-1;x>=y;x--)
#define trav(y,x)     for(auto& y:x)
#define pii           pair<int, int>
#define pll           pair<ll, ll>
#define vi            vector<int>
#define vpi           vector<pii>

int dbg = 0;
#define cri           if(0)
#define shame         cri cerr<<(++dbg)<<"\n\n";

const int MAX = 2e5 + 1;

int N;
vi col;
vi adj[MAX];
int sbT[MAX];
ll ans[MAX];

ll NC2(ll n) {
  ll x = n - 1;
  return (n * x) / 2;
}

void get(int node, int par) {
  trav(ch, adj[node])
    if (ch != par) {
      get(ch, node);
      sbT[node] += sbT[ch];
    }
}
map<int, ll> dfs(int node, int par) {
  ll sub;
  map<int, ll> res;
  trav(ch, adj[node]) {
    if (ch == par) continue;
    auto kid = dfs(ch, node);
    auto it = kid.find(col[node]);
    if (it == kid.end()) sub = 0;
    else sub = kid[col[node]];
    ans[col[node]] += NC2(sbT[ch] - sub + 1);

    if (sz(kid) > sz(res)) swap(res, kid);
    trav(p, kid) {
      it = res.find(p.fi);
      if (it == res.end())
        res[p.fi] = 0;
      res[p.fi] += p.se;
    }
  }
  int c = col[node];
  auto it = res.find(c);
  if (it == res.end())
    res[c] = 0;
  res[c] = sbT[node];
  return res;
}

// aaaaaaaaaaaaaaaa
void solve() {
  scanf("%d", &N);
  int c;
  rep(i, 0, N) {
    scanf("%d", &c);
    col.pb(--c);
  }
  int u, v;
  rep(i, 1, N) {
    scanf("%d%d", &u, &v);
    --u; --v;
    adj[u].pb(v);
    adj[v].pb(u);
  }
  fill(sbT, sbT + N, 1);
  get(0, -1);

  fill(ans, ans + N, 0);
  auto rt = dfs(0, -1);
  rep(i, 0, N) {
    auto it = rt.find(i);
    if (it == rt.end())
      rt[i] = 0;
    ll paths = NC2(sbT[0] - rt[i] + 1);
    ans[i] += paths;
  }
  
  ll tot = NC2(N + 1);
  rep(i, 0, N) {
    ans[i] = tot - ans[i];
    printf("%lld\n", ans[i]);
  }
}

int main() {
  // int _; scanf("%d", &_); while (_--)
  solve();
	return 0;
}

Measured memory_bytes: 70548
/*
    Code written by Talant I.D.
*/
   
#include <bits/stdc++.h>
   
using namespace std;
   
typedef long long ll;
typedef pair <int, int> pii;
typedef tuple <int, int, int> tiii;
   
#define precision(n) fixed << setprecision(n)
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define mp make_pair
#define mt make_tuple
#define mod (int)1e9+7
#define eps (double)1e-9
#define PI 2*acos(-0.0);
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define do_not_disturb ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define curMod 998244353
 
inline bool isvowel(char ch){
    ch = tolower(ch);
    return (ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u');
}
 
bool isprime(int n){
	if(n < 2 || (n % 2 == 0 && n != 2))
		return false;
	for(int i = 3; i*i <= n; i += 2) 
		if(n % i == 0) return false;
	return true;
}

string lcs(string a, string b, int n, int m){
	int ar[n+1][m+1], i, j;
	string tmp = "";
	for(i = 0; i <= n; i++){
		for(j = 0; j <= m; j++){
			if(!i || !j){
				ar[i][j] = 0;
			}
			else if(a[i-1] == b[j-1]){
				ar[i][j] = ar[i-1][j-1]+1;
			}
			else{
				ar[i][j] = max(ar[i-1][j], ar[i][j-1]);
			}
		}
	}
	i = n; j = m;
	while(i && j){
		if(a[i-1] == b[j-1]){
			tmp = a[i-1] + tmp;
			i--; j--;
		}
		else if(ar[i-1][j] > ar[i][j-1]){
			i--;
		}
		else{
			j--;
		}
	}
	return tmp;
}
 
int main(){ 
    do_not_disturb
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    //freopen("milkvisits.in", "r", stdin);
    //freopen("milkvisits.out", "w", stdout);
    string s, t;
    cin >> s >> t;
    cout << lcs(s, t, (int)s.size(), (int)t.size());
    
    return 0;
} // What is to be written here?


Measured memory_bytes: 35456
#include<stdio.h>
#include<vector>
#include<queue>
#include<algorithm>
#include<string.h>
#include<stack> 
#include<set>
#include<map>
#include<iostream>
#include<assert.h>
//#define Min(a,b,c) min((a),min((b),(c)))
#define mp(a,b) make_pair((a),(b))
#define pii pair<int,int>
#define pll pair<LL,LL>
#define pb(x) push_back(x)
#define x first
#define y second
#define sqr(x) ((x)*(x))
#define EPS 1e-11
#define pi 3.14159265359
typedef long long LL;
using namespace std;
const int mod = 1e9+7;
int main(){
	LL n,m;
	scanf("%lld %lld",&n,&m);
	if(n*2>m)
	printf("%lld",m/2);
	else
	printf("%ld",(m-n*2)/4+n);
}

Measured memory_bytes: 256
n=int(input())
ans = [0 for _ in range(10050)]
for i in range(1,105):
	for j in range(1,105):
		for k in range(1,105):
			v = i*i+j*j+k*k+i*j+j*k+k*i;
			if v<10050:
				ans[v]+=1

for i in range(n):
	print(ans[i+1])

Measured memory_bytes: 9432
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define cu continue
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define inf LLONG_MAX
#define pll pair <ll,ll>
#define min_pq priority_queue <pll> ,vector <pll>, greater <pll> > > 
#define f first
#define s second
#define vll vector <ll>
#define dbg(n) cout<<n<<' ';

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


    ll m,n;
    cin>>m>>n;
    ll s=0;
    for(ll i=0;i<n;i++)
    {
        ll x;
        cin>>x;
        s+=x;
    }
    if(s>=m)
        cout<<"Yes\n";
    else
        cout<<"No\n";
}       


Measured memory_bytes: 256
n,a,b = map(int,input().split())
 
def modComb(n,r,mod):
    tmp = 1
    for i in range(1,r+1):
        tmp = tmp * (n-i+1) % mod
        tmp = tmp * pow(i,mod-2,mod) % mod
    
    return tmp % mod
 
 
mod = 10**9+7
ans = pow(2,n,mod) - 1
 
print((ans-modComb(n,a,mod)-modComb(n,b,mod)) % mod)

Measured memory_bytes: 38512
#include <bits/stdc++.h>
using namespace std;
/*#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
Apparently, the tree supports the same operations as the set 
(at least I haven't any problems with them before), but also there are two new features — 
find_by_order() — The first returns an iterator to the k-th largest element (counting from zero)
order_of_key() — the number of items in a set that are strictly smaller than our item. 
https://codeforces.com/blog/entry/11080
using namespace __gnu_pbds; */
using namespace std;
#define test() int t;cin>>t;for(int test=1;test<=t;test++)
#define int long long
#define MOD 1000000007
#define pb push_back 
#define ins insert
#define fast(); ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ld long double
#define endl '\n'
int m(int a) {
    return ((a%MOD)+MOD)%MOD;
}
int p(int a, int b) {
    int res = 1;
    while(b > 0){
        if(b&(int)1) res = res*a;
        a = a*a;
        b >>= (int)1;
    }
    return res;
}
signed main(){
    fast();
    int n;
    cin >> n;
    // vector<int> a;
    // a.pb(26);
    // for(int i=1; i<=9; i++){
    //     a.pb(a.back()*26);
    // }
    // for(int i=1; i<=9; i++){
    //     a[i] += a[i-1];
    // }
    string ans = "";
    while(n > 0){
        n--;
        int m = n%26;  
        ans += ('a'+m);
        n /= 26;
    }
    reverse(ans.begin(), ans.end());
    cout << ans << endl;
    cerr << "\nTime elapsed : " << 1000 * clock() / CLOCKS_PER_SEC << " ms\n";
}

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

int main() {
    string S,T;
    int cnt = 0;

    cin >> S >> T;

    for (int i=0;i<S.size();i++){
        if (S.at(i) != T.at(i)){
            cnt++;
        }
    }

    cout << cnt << endl;

}


Measured memory_bytes: 3840
#include <iostream>
#include <string>

const int H = 50+5;
const int W = 50+5;

int main() {
    using namespace std;
    int h, w;
    char s[H][W];

    cin >> h >> w;

    int i, j;
    for (i=0; i<h; ++i) {
        for (j=0; j<w; ++j) {
            cin >> s[i][j];
        }
    }

    int k, l;
    int count;
    for (i=0; i<h; ++i) {
        for (j=0; j<w; ++j) {
            count = 0;
            if (s[i][j] == '.') {
                for (k=i-1; k<i+2; ++k) {
                    for (l=j-1; l<j+2; ++l) {
                        if ((k>=0 && k<h) && (l>=0 && l<w)) {
                            if (s[k][l] == '#') ++count;
                        }
                    }
                }
            s[i][j] = '0' + count;
            }
        }
    }

    for (i=0; i<h; ++i) {
        for (j=0; j<w; ++j) {
            cout << s[i][j];
        }
        cout << endl;
    }

    return 0;
}

Measured memory_bytes: 256
object Main extends App {
  import scala.io.StdIn._
  val n = readInt()
  var a = readLine().split(" ").map(_.toLong)
  var b = readLine().split(" ").map(_.toLong)
  val aAll = a.sum
  for(i <- (0 until(n))){
    if(b(i) >= a(i)){
      b(i) = b(i) - a(i)
      a(i) = 0
      if(a(i + 1) >= b(i)){
        a(i+1) -= b(i)
      }else{
        a(i+1) = 0
      }
    }else{
      a(i) -= b(i)
      b(i) = 0
    }
  }
  println(aAll - a.sum)
}

Measured memory_bytes: 72092
#include<bits/stdc++.h>
#include <sstream>
#include <string>
#define ll long long
using namespace std;
int main()
{ long long int  a,b;
cin>>a>>b;
if(a>b)
{
    swap(a,b);
}
string str2,str1 = to_string(a);

for(int i= 0;i<b;i++)
{
    str2+=str1;
}

cout<<str2<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdlib>
#include <ctime>
using namespace std;

int M;
int a[7];
int s, g;
int N[301];

bool isChecked[301];
bool can_reach_the_goal[301];
vector<int> milestone[301];  //そのマスで出せばゴールにたどり着ける目を格納する

int iabs(int x){ return x >= 0 ? x : -x; }

bool search(int now){
	if (isChecked[now]){
		return false;
		//return can_reach_the_goal[now];
	}
	else if (now == g){
		return true;
	}

	isChecked[now] = true;
	for (int dice = 1; dice <= 6; dice++){
		if (now + a[dice] == g){
			milestone[now].push_back(a[dice]);
		}
		else if (now - a[dice] == g){
			milestone[now].push_back(-a[dice]);
		}
	}
	for (int dice = 1; dice <= 6; dice++){
		if (now + a[dice] <= M && search(now + a[dice] + N[now + a[dice]])){
			milestone[now].push_back(a[dice]);
		}
		if (now - a[dice] >= 1 && search(now - a[dice] + N[now - a[dice]])){
			milestone[now].push_back(-a[dice]);
		}
	}

	//return can_reach_the_goal[now];
	can_reach_the_goal[now] = milestone[now].size() > 0 ? true : false;
	return can_reach_the_goal[now];
}

int main(){
	srand((unsigned int)time(NULL));
	cin >> M;
	for (int i = 1; i <= 6; i++){
		cin >> a[i];
	}
	cin >> s >> g;
	for (int i = 1; i <= M; i++){
		cin >> N[i];
	}
	bool canGoal = search(s);

	/*
	for (int i = 1; i <= M; i++){
		for (vector<int>::iterator it = milestone[i].begin(); it != milestone[i].end(); it++){
			cout << i << " " << *it << endl;
		}
	}
	//*/
	int now = s; //自分が今いるマスの番号
	for (;;){
		int dice;
		cin >> dice;

		bool found = false;
		for (vector<int>::iterator it = milestone[now].begin(); it != milestone[now].end(); it++){
			if (iabs(*it) == a[dice]){
				if (*it > 0){
					now = now + a[dice] + N[now + a[dice]];
					cout << 1 << endl;
				}
				else{
					now = now - a[dice] + N[now - a[dice]];
					cout << -1 << endl;
				}
				found = true;
				break;
			}
		}
		if(!found) cout << 0 << endl;
		cout.flush();

		if (now == g) return 0;
	}
	
	return 0;
}

Measured memory_bytes: 1304
#include<iostream>
//#include<algorithm>
#include<cmath>
#include<string>
//#include<set>
//#include<vector>
#include<iomanip>
using namespace std;
int main(){

    int n;
    cin>>n;
    long long x=0;
    for(int i=1;i<=n;i++){
        if(!(i%3==0||i%5==0)){x+=i;}
    }
    cout<<x;
    return 0;
}


Measured memory_bytes: 3568
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define MOD 1000000007
#define PI 3.141592653589793

int main(){
    int n;
    cin >> n;
    vector<int> v(n);
    for(int i = 0; i < n; i++)
        cin >> v[i];
    
    int ans = 0;
    while(1){
        for(int i = 0; i < n; i++){
            if(v[i] % 2){
                cout << ans << endl;
                return 0;
            }
            v[i] /= 2;
        }
        ans++;
    }
}

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

using namespace std;

int main() {
	string s;
  	cin >> s;
	int count0 = 0,count1=0;
	for (int i = 0;i<s.size();++i) {
    	if (s[i] == '0')++count0;
		else  ++count1;
    }
	int ans = 2*min(count0, count1);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 512
#  --*-coding:utf-8-*--

MOD = 10**9 + 7


fact = [1]

k = 1
for i in range(10**5):
    k = k*(i+1)%MOD
    fact.append(k)


def getModInv(a, b):
    return 1 if (a == 1) else int((1-b*getModInv(b%a, a))/a%b)


def modPerm(n, m):
    if m > n:
        return 0

    if m == 0:
        return 1

    return fact[n]*getModInv(fact[n-m], MOD)%MOD



def main():
    N, K = map(int, input().split())
    AB = [tuple(map(int, input().split())) for _ in range(N-1)]

    subNodes = [set() for _ in range(N+1)]
    for a, b in AB:
        subNodes[a].add(b)
        subNodes[b].add(a)

    G = [set() for _ in range(N+1)]
    Q = set([1])
    
    while len(Q) > 0:
        q = Q.pop()
        for subNode in subNodes[q]:
            if len(G[subNode]) == 0:
                G[q].add(subNode)
                Q.add(subNode)

    p = K*modPerm(K-1, len(G[1]))%MOD

    for subNodes in G[2:]:
        p = p*modPerm(K-2, len(subNodes))%MOD

    print(p)

        

if __name__ == '__main__':
    main()


Measured memory_bytes: 84264
/**
*     ________   ________   ___        ________          ________   ___        ________       ___    ___  _______    ________
*    |\   ____\ |\   __  \ |\  \      |\   __  \        |\   __  \ |\  \      |\   __  \     |\  \  /  /||\  ___ \  |\   __  \
*    \ \  \___|_\ \  \|\  \\ \  \     \ \  \|\  \       \ \  \|\  \\ \  \     \ \  \|\  \    \ \  \/  / /\ \   __/| \ \  \|\  \
*     \ \_____  \\ \  \\\  \\ \  \     \ \  \\\  \       \ \   ____\\ \  \     \ \   __  \    \ \    / /  \ \  \_|/__\ \   _  _\
*      \|____|\  \\ \  \\\  \\ \  \____ \ \  \\\  \       \ \  \___| \ \  \____ \ \  \ \  \    \/  /  /    \ \  \_|\ \\ \  \\  \|
*        ____\_\  \\ \_______\\ \_______\\ \_______\       \ \__\     \ \_______\\ \__\ \__\ __/  / /       \ \_______\\ \__\\ _\
*       |\_________\\|_______| \|_______| \|_______|        \|__|      \|_______| \|__|\|__||\___/ /         \|_______| \|__|\|__|
*       \|_________|                                                                        \|___|/
*/

#include <ext/rope>
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_cxx;
using namespace __gnu_pbds;

template<class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define ll long long
#define ull unsigned long long
typedef vector<vector<ll>> mat;

int main()
{
    ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0);

    int x;
    cin >> x;
    cout << 3 * x * x;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define arep(i,x,n) for(int i=int(x);i<(int)(n);i++)
#define rep(i,n) for(long long i = 0;i < n;++i)
#define pi 3.141592653589793
#define eps 0.00000001
#define INF 1e9+7  
using ll = long long; 
using P=pair<int,int>;
using lP=pair<ll,ll>;
using fP=pair<double,double>;


int main(){
    string s;
    cin>>s;
    vector<char>ans(100);
    int index=0;
    rep(i,(int)s.size()){
        char a=s[i];
        if(a=='0'){
            ans[index]='0';
            index++;
        }
        else if(a=='1'){
            ans[index]='1';
            index++;
        }
        else if(index>0){
            index--;
        }
    }
    rep(i,index)cout<<ans[i];
    cout<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
map<string,int>mp;

int main(){
	int t;
	cin >> t;
	int cnt=0;
	while(t--){
		string inp;
		cin >> inp;
		if(mp[inp]==0) {
			mp.insert(pair<string,int>(inp,1));
			mp[inp]=1;
			cnt++;
			//cout << mp["apple"] << "\n";
		}
	}
	cout << cnt << "\n";
}

Measured memory_bytes: 18996
$n = gets.chomp.to_i

$a = gets.chomp.split(' ').map(&:to_i)

def abs(num)
  num < 0 ? -num : num
end

$a = $a.sort

n = $a.delete_at($n - 1)

r = $a.min_by { |t| abs(n / 2.0 - t) }

puts "#{n} #{r}"


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

using lint = long long;

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int n;
    cin >> n;
    map<string, int> how_many;
    int maxn = 0;
    for (int i = 0; i < n; ++i) {
    	string s;
    	cin >> s;
    	how_many[s]++;
    	maxn = max(maxn, how_many[s]);
    }
    for (auto u : how_many) 
    	if (u.second == maxn) cout << u.first << '\n';
}

Measured memory_bytes: 23808
N=int(input())
A=[int(i) for i in input().split()]
plus=0
minus=0
ans=1
for i in range(N-1):
    plus += A[i]<A[i+1]
    minus += A[i]>A[i+1]
    if plus and minus:
        ans += 1
        plus = 0
        minus = 0
print(ans)


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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<long long> a(n + 1);
    for (int i = 0; i <= n; ++i)
        cin >> a[i];
    vector<long long> lb(n + 1), ub(n + 1);
    lb[n] = ub[n] = a[n];
    for (int i = n; i >= 1; --i) {
        lb[i - 1] = ((lb[i] + 1) >> 1) + a[i - 1];
        ub[i - 1] = ub[i] + a[i - 1];
    }
    if (n == 0 && a[0] != 1) { cout << "-1\n"; return 0; }
    if (n == 0 && a[0] == 1) { cout << "1\n"; return 0; } 
    if (1 < lb[0] || ub[0] < 1) {
        cout << "-1\n";
        return 0;
    }
    long long tot = 1, ans = tot;
    for (int i = 1; i <= n; ++i) {
        ans += tot = min((long long) ub[i], (tot - a[i - 1]) * 2);
    }
    cout << ans << '\n';
    return 0; 
}

Measured memory_bytes: 5576
/**
*   Bismillahir Rahmanir Rahim.
*   Imtiaz_rafi
*   PCIU, CHITTAGONG
**/
#include<bits/stdc++.h>
using namespace std;
#define speed() ios::sync_with_stdio(0);cin.tie(0);
#define file() freopen ("input.txt", "r", stdin);freopen ("output.txt", "w", stdout);
#define rep(i,a) for(ll i=0;i<a;i++)
#define rep1(i,begin,end) for(ll i=begin;i<=end;i++)
#define mem(dp,i) memset(dp,i,sizeof(dp))
#define all(v)   v.begin(),v.end()
#define rall(v)   v.rbegin(),v.rend()
#define pb push_back
#define pf push_front
#define mp make_pair
#define pi acos(-1)
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*(b/gcd(a,b)))
// bitshift (1LL<<(3)) *2^3
typedef long long int ll;
typedef vector<ll>vi;
typedef map<ll,ll>mi;
typedef pair<ll,ll>pll;
typedef set<ll>st;
typedef set<char>sc;
ll dx[] ={-1,+1,0,0,+1,-1,+1,-1};
ll dy[] ={0,0,-1,+1,+1,+1,-1,-1};
const ll mx = 1e5+123;
const ll MOD = 1e9+7;
bool vis[mx];
vi adj[mx];
int main()
{
    speed();
    ll a,b,i,j,x,y;
    cin>>a>>b;
    ll c[a];
    for(i=0;i<a;i++)
    {
        cin>>c[i];
    }
    j=0;
    x = 0,y = 0;
    for(i=0;i<b;i++)
    {
        x = (x)+(c[i]);
        j++;
    }
    y = x;
    for(i = 0;i<a;i++)
    {
        if(b==a)
            break;
        y = ((y-c[i]))+(c[b]);
        if(x<y)
        {
            cout<<"Yes"<<endl;
        }
        else
            cout<<"No"<<endl;
        x=y;
        //cout<<y<<endl;
        b++;
    }
}


Measured memory_bytes: 7604