akhauriyash/Code-Regression huggingface dataset:
n = int(input())
a = [int(i) for i in input().split()]

def gcd(a,b):
  if a==0:
    return b
  if b==0:
    return a
  
  if a<b:
    a, b = b, a 
  while (a%b!=0):
    a, b = b, a%b  
  return b

left = [0,a[0]]
right = [0,a[n-1]]
for i in range(1,n-1):
  left.append(gcd(left[-1],a[i]))
  right.append(gcd(right[-1],a[n-1-i]))

merge = [gcd(left[i],right[-i-1]) for i in range(n)]

print(max(merge))

Measured memory_bytes: 14400
package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	inputs := scanJointStrings()
	fmt.Println(inputs)
}

func scanJointStrings() string {
	sc.Scan()
	sstring := strings.Split(sc.Text(), " ")

	s := sstring[1] + sstring[0]
	return s
}

Measured memory_bytes: 640
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int h = sc.nextInt();
    int w = sc.nextInt();
    int[][] aisle = new int[h+1][w+1];
    for(int i = 0;i<h;i++){
      String s = sc.next();
      char[] c = s.toCharArray();
      for(int j = 0;j<w;j++){
        if(c[j]=='#')aisle[i][j]=1;
      }
    }
    boolean ans = true;
    int nowh = 0,noww = 0;
    while(nowh<h && noww<w){
      if(nowh==h-1&&noww==w-1)break;
      if(aisle[nowh][noww+1]==0&&aisle[nowh+1][noww]==0 || aisle[nowh][noww+1]==1&&aisle[nowh+1][noww]==1){
        ans = false;
        break;
      }
      if(aisle[nowh][noww+1]==1){
        aisle[nowh][noww]=0;
        for(int i = 0;i<h;i++){
          if(aisle[i][noww]==1){
            ans = false;
            break;
          }
        }
        noww++;
      }
      if(aisle[nowh+1][noww]==1){
        aisle[nowh][noww]=0;
        for(int i = 0;i<w;i++){
          if(aisle[nowh][i]==1){
            ans = false;
            break;
          }
        }
        nowh++;
      }
    }

    if(ans){
      System.out.println("Possible");
    }else{
      System.out.println("Impossible");
    }
  }
}


Measured memory_bytes: 35656
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
int main(){
  ll n,m;
  cin >> n >> m;
  vector<vector<ll>> G(n);
  rep(i,m){
    ll a,b;
    cin >> a >> b;
    a--;
    b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  ll ans=0;
  queue<ll> que;
  vector<ll> dis(n,-1);
  for(ll i=0;i<n;i++){
    que.push(i);
    ll sum=0;
    while(!que.empty()){
      ll v=que.front();
      que.pop();
      for(ll nv: G[v]){
        if(dis.at(nv)!=-1){
          continue;
        }
        dis.at(nv)=dis.at(v)+1;
        que.push(nv);
        sum++;
      }
    }
    ans=max(ans,sum);
  }
  if(ans==0){
    ans=1;
  }
 
  cout << ans;
}

Measured memory_bytes: 18444
#include<iostream>
#include<string>
#include<string.h>
#include<algorithm>

using namespace std;

long long a[100000+10];
int main()
{
    memset(a,0,sizeof(a));
    int n,k,q;
    cin>>n>>k>>q;
    for(int i=0;i<q;i++)
    {
        int x;
        cin>>x;
        a[x]++;
    }
    for(int i=1;i<=n;i++)
    {
        if(q-a[i]>=k)
            cout<<"No"<<endl;
        else cout<<"Yes"<<endl;
    }
    return 0;
}


Measured memory_bytes: 1536
<?php
list($n) = ints();
for ($i = 0; $i < $n; ++$i) list($a[]) = ints();
$_a = $a;
rsort($a);
sort($_a);
for ($i = 0; $i < intdiv($n, 2); ++$i) {
    if ($i % 2 === 0) {
        $r[] = $_a[$i];
        $l[] = $a[$i];
    } else {
        $r[] = $a[$i];
        $l[] = $_a[$i];
    }
}
if ($n % 2) {
    if (abs($r[$i - 1] - $a[$i]) > abs($l[$i - 1] - $a[$i])) $r[] = $a[$i];
    else $l[] = $a[$i];
}
$aa = array_merge(array_reverse($l), $r);
$ans = 0;
for ($i = 0; $i < $n - 1; ++$i)
    $ans += abs($aa[$i + 1] - $aa[$i]);
echo $ans;
function ints()
{
    return array_map('intval', explode(' ', trim(fgets(STDIN))));
}


Measured memory_bytes: 32588
#include<cstdio>
#define mod 1000000007
using namespace std;
int n,a[21][21],two[22];
long long dp[5000000];

long long dfs(int x,int y){
    if(dp[y]!=-1){
        return dp[y];
    }
    if(x==n){
        return 1;
    }
    dp[y]=0;
    for(int i=0;i<n;i++){
        if(a[x][i]==1&&(y&two[i])){
            dp[y]+=dfs(x+1,(y^two[i]));
            dp[y]%=mod;
        }
    }
    return dp[y];
}
int main(){
    scanf("%d",&n);
    two[0]=1;
    for(int i=1;i<=n;i++){
        two[i]=2*two[i-1];
    }
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            scanf("%d",&a[i][j]);
        }
    }
    for(int i=0;i<two[n];i++){
        dp[i]=-1;
    }
    dp[0]=1;
    dfs(0,two[n]-1);
    printf("%lld\n",dp[two[n]-1]);
}

Measured memory_bytes: 18688
/* 

*/
// #pragma GCC optimize("Ofast")
// #pragma GCC target("avx,avx2,fma")
#include <iostream>
#include <iomanip>
#include <sstream>
#include <fstream>
#include <string>
#include <cstring>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <queue>
#include <stack>
#include <deque>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <utility>
#include <bitset>
 
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
 
#define LSOne(S) (S & (-S))
#define EPS 1e-9
 
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pd;
typedef tree<pi, null_type, less<pi>, rb_tree_tag, tree_order_statistics_node_update> ordered_multiset;

int main()
{
    std::ios::sync_with_stdio(false);
    cin.tie(0); // BEFORE SUBMIT DON'T FORGET TO UNCOMMENT THIS
    int n, k;
    cin >> n >> k;
    vector<int> vec(n);
    for(int i = 0; i < n; ++i) cin >> vec[i];
    vector<int> dp(k+5);
    for(int i = 1; i <= k; ++i)
    {
        bool hasLose = false;
        for(auto& num : vec)
        {
            if(i-num < 0) break;
            if(!dp[i-num])
            {
                hasLose = true;
                break;
            }
        }
        dp[i] = hasLose;
    }
    (dp[k]) ? cout << "First\n" : cout << "Second\n";
    return 0; 
}


Measured memory_bytes: 640
using System;

public class Program{
    public static void Main(){
    
     string[] input=Console.ReadLine().Split(' ');
     int N=int.Parse(input[0]);
     int A=int.Parse(input[1]);
     int B=int.Parse(input[2]);
     
     Console.WriteLine(SomeSum(A,B,N));
    }
    
    
    
    
    public static int SomeSum(int A, int B, int N) {
        int AllSum=0;
        int sum=0;
     
        for(int i=1;i<=N;i++) {
            int hitotsu=0;
            int futatsu=0;
            int mittsu=0;
            int yottsu=0;
            int itsutsu=0;
  
            hitotsu=i%10;
            if(i>=10) {
                futatsu=(i/10)%10;
                if(i>=100) {
                    mittsu=(i/100)%10;      
                    if(i>=1000) {
                        yottsu=(i/1000)%10;
                        if(i>=10000) {
                            itsutsu=(i/10000)%10;
                        }
                    }
                }
            }
            sum=hitotsu+futatsu+mittsu+yottsu+itsutsu;

            if(A<=sum && sum<=B) {
                AllSum+=i;
            }
            
        }   

        return AllSum;
    }
    
}


Measured memory_bytes: 11220
s=input()

a=s[0]
b=''
for i in range(1,4):
  if s[i]!=a:
    b=s[i]
    break
ca=0
cb=0
for i in range(4):
  if s[i]!=a and s[i]!=b:
    print('No')
    exit()
  if s[i]==a:
    ca+=1
  elif s[i]==b:
    cb+=1
if ca==2 and cb==2:
  print('Yes')
else:
  print('No')

Measured memory_bytes: 3064
#include <stdlib.h> 
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <math.h>

using namespace std; 

int main()
{
	int a,b;
	
  	cin>>a>>b;
  	
  	int ans;
  	
  	ans = ( b - 1 + a - 2) / ( a - 1);
  	
  	cout<<ans;
  	
	return 0;
}


Measured memory_bytes: 3584
a, b, c, k = map(int, input().split())
sc = 0

if a - k < 0:
    sc = a
    k = abs(a - k)
else:
    print(k)
    exit()

if b - k < 0:
    k = abs(b - k)
else:
    print(sc)
    exit()

if c - k < 0:
    sc-=c
else:
    sc-=k
print(sc)

Measured memory_bytes: 9136
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(10000)


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(AB):
    c = Counter()
    for a, b in AB:
        c[a] += 1
        c[b] += 1
    
    return 'YES' if c[c.most_common()[0][1]] == 2 else 'NO'


def main():
    AB = [read_int_n() for _ in range(3)]
    print(slv(AB))


if __name__ == '__main__':
    main()


Measured memory_bytes: 7868
#include <bits/stdc++.h>
using namespace std;
const int MOD = 2019;

int main() {
  int N; cin >> N;
  long long A[N], sum=0, cumsumLtoR[N], cumsumRtoL[N];
  for (int i=0; i<N; i++) cin >> A[i];
  for (int i=0; i<N; i++) sum += A[i];
  cumsumLtoR[0] = A[0];
  cumsumLtoR[1] = A[1];
  for (int i=2; i<N; i++) {
    cumsumLtoR[i] = cumsumLtoR[i-2] + A[i];
  }
  cumsumRtoL[N-1] = A[N-1];
  cumsumRtoL[N-2] = A[N-2];
  for (int i=N-3; i>=0; i--) {
    cumsumRtoL[i] = cumsumRtoL[i+2] + A[i];
  }
  for (int i=0; i<N; i++) {
    long long ans = sum;
    if (i >= 2) ans -= cumsumLtoR[i-2] * 2;
    if (i <= N-2) ans -= cumsumRtoL[i+1] * 2;
    if (i < N-1) cout << ans << " ";
    else cout << ans << endl;
  }
}


Measured memory_bytes: 3712
package main

// -----問題文-----
// N頂点の木Gが与えられます。頂点には1からNまでの番号がついており、
// i本目の辺は頂点aiと頂点biを結んでいます。
// Gの辺を何色かで塗り分けることを考えます。 このとき、各頂点について、
// その頂点を端点に持つ辺の色がすべて相異なるようにしたいです。
// 上記の条件を満たす塗り分けの中で、使用する色の数が最小であるようなものを
// 1つ構築してください。
// -----制約-----
// 2≦N≦10^5
// 1≦ai＜bi≦N
// 入力は全て整数
// 与えられるグラフは木である

// -----入力-----
// 入力は以下の形式で標準入力から与えられる。
// N
// a1 b1
// a2 b2
//   ⋮
// aN−1 bN−1

// -----出力-----
// 出力はN行からなる
// 1行目のに使用する色の数Kを出力せよ
// i+1（1≦i≦N-1）にi番目の辺の色を表す整数ciを出力せよ
// ここで1≦ci≦kでなければならない
// 問題分中の条件を満たし、使用する色の数が最小であるような塗分けが
// 複数存在するときは、そのうちのどれを出力しても構わない

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

type Edge struct {
	ToNode int
	EdgeI int
}

var stdin = func() *bufio.Scanner {
	stdin := bufio.NewScanner(os.Stdin)
	stdin.Split(bufio.ScanWords)
	return stdin
}()
var edges [][]Edge
var edgeColors []int
var maxColor int

func main() {
	n := readInt()

	// n木作成
	var root int
	edges = make([][]Edge, n+1)
	for i := 1; i < n; i++ {
		a := readInt()
		if i == 1 {
			root = a
		}
		b := readInt()
		edges[a] = append(edges[a], Edge{ToNode: b, EdgeI: i})
		edges[b] = append(edges[b], Edge{ToNode: a, EdgeI: i})
	}

	edgeColors = make([]int, n)
	depthFirstSearchForEdge(root, -1, -1)

	fmt.Println(maxColor-1)

	for i := 1; i < n; i++ {
		fmt.Println(edgeColors[i])
	}
}
// readString() 読み込んだ文字列を返す
func readInt() int {
	stdin.Scan()
	x, err := strconv.Atoi(stdin.Text())
	if err != nil {
		panic(err)
	}
	return x
}
// depthFirstSearchForEdge() 深さ優先探索に似たものを用いて、辺に色を付ける
func depthFirstSearchForEdge(currentNode, fromNode, usedColor int) {
	color := 1
	for _, e := range edges[currentNode] {
		if e.ToNode == fromNode {
			continue
		}
		if color == usedColor {
			color++
			if color > maxColor {
				maxColor = color
			}
		}
		edgeColors[e.EdgeI] = color
		depthFirstSearchForEdge(e.ToNode, currentNode, color)
		color++
		if color > maxColor {
			maxColor = color
		}
	}
}


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


#define li          long long int
#define rep(i,to)   for(li i=0;i<((li)(to));i++)
#define repp(i,start,to)    for(li i=(li)(start);i<((li)(to));i++)
#define pb          push_back
#define sz(v)       ((li)(v).size())
#define bgn(v)      ((v).begin())
#define eend(v)     ((v).end())
#define allof(v)    (v).begin(), (v).end()
#define dodp(v,n)       memset(v,(li)n,sizeof(v))
#define bit(n)      (1ll<<(li)(n))
#define mp(a,b)     make_pair(a,b)
#define rin rep(i,n)
#define EPS 1e-12
#define ETOL 1e-8
#define MOD 1000000007
typedef pair<li, li> PI;

#define INF bit(60)

#define DBGP 1


#define idp if(DBGP)
#define F first
#define S second
#define p2(a,b)     idp cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)       idp cout<<a<<"\t"<<b<<"\t"<<c<<endl
#define p4(a,b,c,d)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<endl
#define p5(a,b,c,d,e)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<endl
#define p6(a,b,c,d,e,f)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<endl
#define p7(a,b,c,d,e,f,g)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<endl
#define p8(a,b,c,d,e,f,g,h)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<endl
#define p9(a,b,c,d,e,f,g,h,i)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<endl
#define p10(a,b,c,d,e,f,g,h,i,j)        idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<"\t"<<j<<endl
#define foreach(it,v)   for(__typeof((v).begin()) it=(v).begin(); it!=(v).end(); ++it)
#define p2p(x)      idp p2((x).F, (x).S)
#define dump(x,n)   idp{rep(i,n){cout<<x[i]<<" ";}puts("");}
#define dump2(x,n)  idp{rep(i,n){cout<<"["<<x[i].F<<" , "<<x[i].S<<"] ";}puts("");}
#define dumpi(x)    idp{foreach(it, x){cout<<(*it)<<" ";}puts("");}
#define dumpi2(x)   idp{foreach(it, x){cout<<"["<<(it)->F<<" , "<<(it)->S<<"] ";}puts("");}

#define read2d(a,w,h)   rep(i,h)rep(j,w)cin>>a[i][j]
#define dump2d(a,w,h)   rep(i,h){rep(j,w)cout<<a[i][j]<<" ";puts("");}

typedef pair<li, li> PI;


inline bool solve(li a, li b, li c, li d) {
    // a>=b
    if (a < b) {
        return false;
    }
    // b<d
    if (b > d) {
        return false;
    }
    li g = __gcd(d, b);
    li cc = b - g + (a % g);
    return cc <= c;
}

int main() {
    li n;
    cin >> n;
    rin{
        li a, b, c, d;
        cin >> a >> b >> c >> d;
        cout << (solve(a, b, c, d) ? "Yes" : "No") << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int gcd(int,int);

int main()
{
  int x,y;

  scanf("%d%d",&x,&y);

  printf("%d\n",gcd(y,x%y));

  return 0;
}

int gcd(int x,int y)
{
  if(y==0){
    return x;
  }
  else if(x<y){
    return gcd(x,y%x);
  }
  else return gcd(y,x%y);
}



Measured memory_bytes: 2144
n = int(input())
a = list(map(int, input().split()))
kane = 1000
kabu = 0 
if a[0] < a[1]:
    kabu = kane // a[0]
    kane %= a[0]
for i in range(1, n - 1):
    if a[i - 1] < a[i]:
        kane += a[i] * kabu
        kabu = 0
    if a[i] < a[i + 1]:
        kabu = kane // a[i]
        kane %= a[i]
kane += a[n - 1] * kabu
print(kane)

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

vector<int> a(1000000);

int main(){
    int n; cin >> n;
    for(int i=0; i<n; i++) cin >> a[i];
    int ans=0;
    for(int i=0; i<n; i++){
        for(int j=i+1; j<n; j++){
            if(a[i]==j+1 && a[j]==i+1){
                ans++;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 7076
#include <bits/stdc++.h>
#define mset(a,b) memset(a,b,sizeof a)
#define mcpy(a,b) memcpy(a,b,sizeof b)
#define lb(x) ((x)&(-(x)))
#define xx first
#define yy second
#define pb push_back
#define mp(a,b) make_pair(a,b)
#define pii pair<int,int> 
#define dalao 1000000007
#define inf 0x3f3f3f3f
#define N 3005
using namespace std;
typedef long long ll;
int n,m,f[N][N][2];
inline void upd(int& a,int b){a=(a+b)%dalao;}
int main(){
	cin>>n>>m;
	for(int i=0;i<=n;i++)f[0][i][i==0]=1;
	for(int i=0;i<m;i++)for(int j=0;j<=n;j++)for(int k=0;k<2;k++)if(f[i][j][k]){
		int val=f[i][j][k];
		if(j>0){
			upd(f[i+1][j][k|(j==1)],val);
			upd(f[i+1][j-1][k|(j==1)],val);
		}
		if(j<n){
			upd(f[i+1][j][k],val);
			upd(f[i+1][j+1][k],val);
		}
	}
	int ans=0;
	for(int i=0;i<=n;i++)upd(ans,f[m][i][1]);
	cout<<ans;
	return 0;
}

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


int main() {
    int a[5];
    cin >> a[0] >> a[1] >> a[2] >> a[3] >> a[4];
    for(int i = 0; i<5;i++){
        if(a[i] == 0){
            cout << i+1 << endl;
        }
    }
     return 0;
}

Measured memory_bytes: 3628
N,M=map(int, input().split())
A=list(map(int, input().split()))
if N-1==M:
  print(0)
  exit()
#連結成分の合計a,連結する辺の数b
a,b=N-M,N-M-1
if N<2*(N-M-1):
  print('Impossible')
  exit()

par=[i for i in range(N)]
rank=[0]*(N)
size=[1]*N

def find(x):
  if par[x]==x:
    return x
  else:
    par[x]=find(par[x])
    return par[x]
def same(x,y):
  return find(x)==find(y)
def union(x,y):
  x=find(x)
  y=find(y)
  if x==y:
    return 
  if rank[x]>rank[y]:
    par[y]=x
    size[x]+=size[y]
  else:
    par[x]=y
    size[y]+=size[x]
    if rank[x]==rank[y]:
      rank[y]+=1
      
for i in range(M):
  a,b=map(int,input().split())
  union(a,b)
D=[[10**9+1,-1] for i in range(N)]
C=[]
for i in range(N):
  a=find(i)
  if D[a][0]>A[i]:
    C.append([D[a][0],D[a][1]])
    D[a][0]=A[i]
    D[a][1]=i
  else:
    C.append([A[i],i])
ans=0
cnt=0
for a,b in D:
  if b!=-1:
    ans+=a
    cnt+=1
C=sorted(C)
for a,b in C:
  if cnt==2*(N-M-1):
    break
  ans+=a
  cnt+=1
print(ans)

Measured memory_bytes: 39180
N = int(input())
A = []
B = []
C = []
A = list(map(int, input().split(' ')))
B = list(map(int, input().split(' ')))
C = list(map(int, input().split(' ')))
satis = 0
for i in range(N - 1):
  satis += B[A[i] - 1]
  if A[i] + 1 == A[i + 1]:
    satis += C[A[i] - 1]
satis += B[A[N - 1] - 1]
print(satis)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define fi first
#define se second
#define m_p make_pair
#define p_b push_back
#define e_b emplace_back
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
using namespace std;
using ll = long long;
using ld = long double;
template<class T> bool chmax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<class T> bool chmin(T &a,T b){if(a>b){a=b;return true;}return false;}

template <class Abel> struct BIT {
  vector<Abel> dat[2];
  Abel UNITY_SUM = 0;                     // to be set

  /* [1, n] */
  BIT(int n) { init(n); }
  void init(int n) { for (int iter = 0; iter < 2; ++iter) dat[iter].assign(n + 1, UNITY_SUM); }

  /* a, b are 1-indexed, [a, b) */
  inline void sub_add(int p, int a, Abel x) {
    for (int i = a; i < (int)dat[p].size(); i += i & -i)
      dat[p][i] = dat[p][i] + x;
  }
  inline void add(int a, int b, Abel x) {
    sub_add(0, a, x * -(a - 1)); sub_add(1, a, x); sub_add(0, b, x * (b - 1)); sub_add(1, b, x * (-1));
  }

  /* a is 1-indexed, [a, b) */
  inline Abel sub_sum(int p, int a) {
    Abel res = UNITY_SUM;
    for (int i = a; i > 0; i -= i & -i) res = res + dat[p][i];
    return res;
  }
  inline Abel sum(int a, int b) {
    return sub_sum(0, b - 1) + sub_sum(1, b - 1) * (b - 1) - sub_sum(0, a - 1) - sub_sum(1, a - 1) * (a - 1);
  }

  /* debug */
  void print() {
    for (int i = 1; i < (int)dat[0].size(); ++i) cout << sum(i, i + 1) << ",";
    cout << endl;
  }
};

int main(){
  ios_base::sync_with_stdio(false);cin.tie(0);
  int N,Q;
  cin >> N >> Q;
  vector<int> c(N);
  for(int i=0;i<N;i++) cin >> c.at(i);

  vector<int> lefts(Q), rights(Q), ids(Q);
  for(int i=0;i<Q;i++){
    cin >> lefts.at(i) >> rights.at(i);
    lefts.at(i)--;
    ids.at(i)=i;
  }
  sort(ids.begin(), ids.end(), [&](int i, int j) {
      return rights[i] < rights[j];});

  BIT<int> bit(N+5);
  vector<int> prev(1100000, -1);
  vector<int> res(Q, 0);
  int r = 0;
  for (auto i : ids) {
    for (; r < rights[i]; ++r) {
      bit.add(prev[c[r]]+2, r+2, 1);
      prev[c[r]] = r;
    }
    int tmp = bit.sum(lefts[i]+1, lefts[i]+2);
    res[i] = max(res[i], tmp);
  }
  for (int i = 0; i < Q; ++i) cout << res[i] << endl;

  return 0;
}

Measured memory_bytes: 21756
#include<iostream>
#include<cmath>
#include<algorithm>
#include<vector>
#include<functional>
#include<string>
#include<iomanip>
#include<map>
#include<utility>
#include<string>
#include<unordered_map>
#include <queue>

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

using namespace std;

#define min_3(a, b, c) min(a, min(b, c))
#define max_3(a, b, c) max(a, max(b, c))
typedef long long ll;

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

    if(a >= 3200) cout << s << endl;
    else cout << "red" << endl;
    return 0;
}


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

int main(){
	string a;
	cin>>a;
	for(int i=0;i<a.length();++i){
		if(i%2==0){
			if(a[i]=='L'){
				cout<<"No"<<endl;
				return 0;
			}
		}else{
			if(a[i]=='R'){
				cout<<"No"<<endl;
				return 0;
			}
		}
	}
	cout<<"Yes"<<endl;
	
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<stdlib.h>

void push(int);
void pop(void);
void change_number(char);

int stac[1000];
int top=0;

int main(){
  char c;
  int num1, num2;

  while(1){

    scanf("%c",&c);
    if(c == '\n') break;
    
    if(c == '+'){
      num1 = stac[top-1];
      num2 = stac[top];
	    
      pop();
      pop();
     
      push(num1+num2);
    }
    else if(c == '-'){
      num1 = stac[top-1];
      num2 = stac[top];

      pop();
      pop();

      push(num1-num2); 
    }
    else if(c == '*'){
      num1 = stac[top-1];
      num2 = stac[top];

      pop();
      pop();

      push(num1*num2);
    }
    else if('1'<= c && c<='9'){
      change_number(c);
    }
  }

  printf("%d\n",stac[top]);
  return 0;
}

void push(int x){
  stac[top+1] = x;
  top++;
}

void pop(void){
  top--;
}

void change_number(char x){
  char array[100];
  int i=0, n;
  char c;
  
  array[i] = x;
  while(1){
    scanf("%c",&c);
    if(c == ' '){
      array[i+1] = '\n';
      n = atoi(array);
      push(n);
      break;
    }
    else{
      i++;
      array[i] = c;
    }
  }
}

Measured memory_bytes: 548
import heapq
n, m = map(int, input().split())
A = list(map(int, input().split()))

pq = []
for a in A:
    heapq.heappush(pq, -a)#'-'にすることで最大値を考えることができる！
#print(pq)
for _ in range(m):
    a = (-heapq.heappop(pq)) // 2
    heapq.heappush(pq, -a)
print(-sum(pq))

Measured memory_bytes: 14180
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second

const int mx=100010;
const ll mod=1e9+7;

int main(){
  int n,k; cin >> n >> k;
  ld ans=0;
  for(int i=1; i<=n; i++){
    ld tmp=1.0/n;
    int cur=i;
    while(cur<k){cur*=2; tmp/=2; }
    ans += tmp;
  }
  cout << fixed << setprecision(12) << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>

int main() {
  int k, a, b;
  std::cin >> k >> a >> b;
  for (int i = a; i <=b; ++i) {
    if (i % k == 0) {
      std::cout << "OK";
      return 0;
    }
  }
  std::cout << "NG";
}

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

int main(){
  string S;
  cin >> S;
  int x = S.size();
  
  string S_new;
  for(int i=0; i<8; i++){
    S_new = S;
    S_new.erase(i, x-7);
    if(S_new=="keyence"){
      cout << "YES";
      return 0;
    }
  }
  cout << "NO";
  return 0;
}

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

using namespace std;
typedef long long ll;
//typedef unsigned long long ll;

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

bool contain(set<P> &s, P a) { return s.find(a) != s.end(); }

//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);
const int mod = 1000000007;


void print_line(vector<ll> &line) {
    if (line.size() == 0ll) {
        cout << endl;
        return;
    }
    for (ll i = 0; i < line.size(); i++) {
        cout << line[i];
        if (i == line.size() - 1) cout << endl;
        else cout << ' ';
    }
}

typedef priority_queue<long long, vector<long long>, greater<long long>> PQ_ASK;

struct mint {
    ll x; // typedef long long ll;
    mint(ll x = 0) : x((x % mod + mod) % mod) {}

    mint &operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }

    mint &operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }

    mint &operator*=(const mint a) {
        (x *= a.x) %= mod;
        return *this;
    }

    mint operator+(const mint a) const {
        mint res(*this);
        return res += a;
    }

    mint operator-(const mint a) const {
        mint res(*this);
        return res -= a;
    }

    mint operator*(const mint a) const {
        mint res(*this);
        return res *= a;
    }

    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const {
        return pow(mod - 2);
    }

    mint &operator/=(const mint a) {
        return (*this) *= a.inv();
    }

    mint operator/(const mint a) const {
        mint res(*this);
        return res /= a;
    }
};

struct combination {
    vector<mint> fact, ifact;

    combination(int n) : fact(n + 1), ifact(n + 1) {
        assert(n < mod);
        fact[0] = 1;
        for (int i = 1; i <= n; ++i) fact[i] = fact[i - 1] * i;
        ifact[n] = fact[n].inv();
        for (int i = n; i >= 1; --i) ifact[i - 1] = ifact[i] * i;
    }

    mint operator()(int n, int k) {
        if (k < 0 || k > n) return 0;
        return fact[n] * ifact[k] * ifact[n - k];
    }

    mint nPk(int n, int k) {
        if (n < k) return 0;
        if (n < 0 || k < 0) return 0;
        return fact[n] * ifact[n - k];
    }

} combination(10000);


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

    mint ans = combination(k, n);

    cout << ans.x << endl;

}





Measured memory_bytes: 3240
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
typedef long long lint;
#define rep(i, n) for (int i = 0; i < (n); ++i)
typedef pair<int, int> P;
bool bitcheck(int bit, int position)
{
    if ((bit >> position) & 1)
        return true;
    else
        return false;
}
int main()
{
    string s;
    cin >> s;
    string ans;
    ans = s;
    rep(i, 1 << 3)
    {
        int cc = s[0] - '0';
        rep(j, 3)
        {
            if (bitcheck(i, j))
            {
                cc += s[j + 1] - '0';
            }
            else
            {
                cc -= s[j + 1] - '0';
            }
        }
        if (cc == 7)
        {
            rep(j, 3)
            {
                cout << ans.front();
                ans.erase(ans.begin() + 0);
                if (bitcheck(i, j))
                {
                    cout << '+';
                }
                else
                {
                    cout << '-';
                }
            }
            cout << ans.front() <<"=7"<< endl;
            return 0;
        }

    }
   
}

Measured memory_bytes: 256
#include<stdio.h>

int x,y,t[20][5];

int mat(int n){
	if(n<0)return 0;
	else{
		//printf("x=%d,y=%d,t[%d][0]=%d,t[%d][1]=%d,t[%d][2]=%d\n",x,y,n,t[n][0],n,t[n][1],n,t[n][2]);
		if(t[n][0]==x&&t[n][1]==y&&t[n][2]==0){
			t[n][2]=1;
			return 1;
		}else{
			mat(n-1);
		}
	}
}

int main(){
	int n,m,i,ch,tmp,cnt,mo;
	char ft;
	while(1){
		scanf("%d",&n);
		if(n==0)break;
		cnt=0;
		x=10;
		y=10;
		for(i=0;i<n;i++){
			scanf("%d %d",&t[i][0],&t[i][1]);
			t[i][2]=0;
		}
		scanf("%d",&m);
		while((ch=getchar())!='\n');
		for(i=0;i<m;i++){
			scanf("%c %d",&ft,&mo);
			while((ch=getchar())!='\n');
			if(ft=='N'){
				tmp=y+mo;
				for(;y<=tmp;y++)if(mat(n-1))cnt++;
				y--;
			}else if(ft=='S'){
				tmp=y-mo;
				for(;y>=tmp;y--)if(mat(n-1))cnt++;
				y++;
			}else if(ft=='E'){
				tmp=x+mo;
				for(;x<=tmp;x++)if(mat(n-1))cnt++;
				x--;
			}else if(ft=='W'){
				tmp=x-mo;
				for(;x>=tmp;x--)if(mat(n-1))cnt++;
				x++;
			}
		}
		if(cnt==n)printf("Yes\n");
		else printf("No\n");
	}
	return 0;
}

Measured memory_bytes: 588
#include <bits/stdc++.h>
#include <vector>
#include <queue>
#include <iostream>
#include <iomanip>
using namespace std;
typedef long long LL;
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)

int main(){
    int N, K;
    cin >> N >> K;
    vector<int> A(N,0);
    REP(i,N)cin>>A[i];

    int ans = 1;

    if(N <= K){
        cout << ans << endl;
        return 0;
    }

    ans += (N - K) / (K - 1);
    ans += ((N - K)%(K - 1) == 0)? 0 : 1;

    cout << ans << endl;
    return 0;

}

Measured memory_bytes: 3612
red, green, blue, n = map(int, input().split())

ans = 0
for i in range(n // red + 1):
    for j in range(n // blue + 1):
        k = n - red * i - blue * j
        
        if k % green != 0 or k < 0:
            continue
        
        ans += 1

print(ans)

Measured memory_bytes: 40556
#include<stdio.h>
int main(void)
{
	int w,h,x,y,r;
	scanf("%d%d%d%d%d",&w,&h,&x,&y,&r);
	if(x-r>=0&&x+r<=w&&y-r>=0&&y+r<=h)
	printf("Yes\n");
	else
	printf("No\n");
	return 0;
}

Measured memory_bytes: 584
/*
	2013 08 01
	Miyagi Technical High School
	J1 JK club Taiki F Watanabe
*/

#include<stdio.h>

typedef struct INFO_TEAM
{
	// チーム名
	char name[21];
	
	// 勝の数
	int win;
	// 負の数
	int lose;
	// 引分の数
	int draw;
	// 成績
	int points;
	// 順番
	int arr;
}INFO;

int main(void)
{
	int i = 0, j = 0, k = 0, num = 0;
	int flag = 0;
	INFO tmp;
	INFO team[2][10];

	
	while(1)
	{
		scanf("%d", &num);

		if(num == 0)
		{
			return 0;
		}

		if(flag)
		{
			putchar('\n');
		}

		for(i = 0; i < num; i++)
		{
			scanf("%s %d %d %d", &team[0][i].name, &team[0][i].win, &team[0][i].lose, &team[0][i].draw);

			team[0][i].points = 0;

			team[0][i].points += team[0][i].win * 3;
			team[0][i].points += team[0][i].draw;

			team[1][i].arr = i;
		}

		for(i = 0; i < num; i++)
		{
			for(j = 0; j < num; j++)
			{
				if(team[0][i].points >= team[0][j].points)
				{
					if(team[0][i].points == team[0][j].points)
					{
						if(team[1][i].arr >= team[1][j].arr)
						{
							tmp = team[0][i];
							team[0][i] = team[0][j];
							team[0][j] = tmp;

							tmp = team[1][i];
							team[1][i] = team[1][j];
							team[1][j] = tmp;
						}
					}
					else
					{
						tmp = team[0][i];
						team[0][i] = team[0][j];
						team[0][j] = tmp;
						 
						tmp = team[1][i];
						team[1][i] = team[1][j];
						team[1][j] = tmp;
					}
				}
			}
		}

		for(i = 0; i < num; i++)
		{
			for(j = 0; j < num; j++)
			{
				if(team[0][i].points == team[0][j].points)
				{
					if(team[1][i].arr < team[1][j].arr)
					{
						tmp = team[0][i];
						team[0][i] = team[0][j];
						team[0][j] = tmp;
					}
				}
			}
		}

		for(i = 0; i < num; i++)
		{
			printf("%s,%d\n", team[0][i].name, team[0][i].points);
		}

		flag = 1;
	}
}
/*
	2013 08 01
	Miyagi Technical High School
	J1 JK club Taiki F Watanabe

	パターン2
* /

#include<stdio.h>

typedef struct INFO_TEAM
{
	// チーム名
	char name[21];
	
	// 勝の数
	int win;
	// 負の数
	int lose;
	// 引分の数
	int draw;
	// 成績
	int points;
}INFO;

int main(void)
{
	int x = 0, y = 0, i = 0, j = 0, num = 0;
	int sum[1000];
	INFO tmp;
	INFO team[1000][10];
	
	for(x = 0; ; x++)
	{
		scanf("%d", &num);

		if(num == 0)
		{
			break;
		}

		for(i = 0; i < num; i++)
		{
			scanf("%s %d %d %d", &team[x][i].name, &team[x][i].win, &team[x][i].lose, &team[x][i].draw);

			team[x][i].points = 0;

			team[x][i].points += team[x][i].win * 3;
			team[x][i].points += team[x][i].draw;
		}

		for(i = 0; i < num; i++)
		{
			for(j = 0; j < num; j++)
			{
				if(team[x][i].points > team[x][j].points)
				{
					tmp = team[x][i];
					team[x][i] = team[x][j];
					team[x][j] = tmp;
				}
			}
		}

		sum[x] = num;

		putchar('\n');
	}

	putchar('\n');

	for(y = 0; y < x; y++)
	{
		for(i = 0; i < sum[y]; i++)
		{
			printf("%s,%d\n", team[y][i].name, team[y][i].points);
		}

		if(y + 1 != x)
		{
			putchar('\n');
		}
	}

	return 0;
}

*/

Measured memory_bytes: 604
from bisect import bisect_left


def solve(n, a_list, uv_list):
    res = [0] * n
    tree = [[] for _ in range(n)]
    for u, v in uv_list:
        tree[u - 1].append(v - 1)
        tree[v - 1].append(u - 1)

    # euler tour
    visited = [0] * n
    parent = [-1] * n
    tour = [0]
    p = 0
    while True:
        visited[p] = 1
        r = parent[p]
        while len(tree[p]):
            q = tree[p].pop()
            if visited[q] == 0:
                parent[q] = p
                r = q
                break
        if r == -1:
            break
        p = r
        tour.append(p)
    # assert len(tour) == 2 * n - 1
    # print(tour)

    # tree DP
    dp = [10 ** 9 + i for i in range(n + 1)]
    dp[0] = 0
    re_visited = [0] * n
    callbacks = []
    for p in tour:
        if re_visited[p] == 0:
            re_visited[p] = 1
            ind = bisect_left(dp, a_list[p])
            callbacks.append((ind, dp[ind]))
            dp[ind] = a_list[p]
            res[p] = bisect_left(dp, 10 ** 9) - 1
        else:
            ind, v = callbacks.pop()
            dp[ind] = v
        # print(dp)
    # print(res)
    return res


def main():
    n = int(input())
    a_list = list(map(int, input().split()))
    uv_list = [list(map(int, input().split())) for _ in range(n - 1)]
    res = solve(n, a_list, uv_list)
    for r in res:
        print(r)


def test():
    assert solve(10, [1, 2, 5, 3, 4, 6, 7, 3, 2, 4],
                 [[1, 2], [2, 3], [3, 4], [4, 5], [3, 6], [6, 7], [1, 8], [8, 9], [9, 10]]
                 ) == [1, 2, 3, 3, 4, 4, 5, 2, 2, 3]
    assert solve(10, [5, 2, 5, 3, 4, 6, 7, 3, 2, 4],
                 [[1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [1, 7], [1, 8], [1, 9], [1, 10]]
                 ) == [1, 1, 1, 1, 1, 2, 2, 1, 1, 1]
    assert solve(10, [5, 2, 5, 3, 4, 6, 7, 3, 2, 4],
                 [[1, 2], [2, 3], [2, 4], [2, 5], [2, 6], [2, 7], [2, 8], [2, 9], [2, 10]]
                 ) == [1, 1, 2, 2, 2, 2, 2, 2, 1, 2]
    assert solve(10, [3, 5, 5, 3, 4, 6, 7, 3, 2, 4],
                 [[1, 2], [2, 3], [2, 4], [2, 5], [2, 6], [2, 7], [2, 8], [2, 9], [2, 10]]
                 ) == [1, 2, 2, 2, 2, 3, 3, 2, 2, 2]
    assert solve(10, [3, 3, 3, 3, 3, 3, 3, 3, 3, 3],
                 [[1, 2], [2, 3], [2, 4], [2, 5], [2, 6], [2, 7], [2, 8], [2, 9], [2, 10]]
                 ) == [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]


if __name__ == "__main__":
    test()
    main()


Measured memory_bytes: 117008
fun main (args : Array<String>) {
	val (n, x) = readLine()!!.split(" ").map(String::toInt)
	val N : Int = n.toInt()
	val X : Int = x.toInt()
	val list = readLine()!!.split(" ").map(String::toInt)
	var lList : MutableList<Int> = mutableListOf()
	for (i in 0..N - 1) {
		lList.add(list[i])
	}
	var num : Int = 0
	var result : Int = 1
	for (i in 0..N - 1) {
		num += lList[i]
		if (num <= X) {
			result++
		}
	}
	println("${result}")
}

Measured memory_bytes: 36164
#include<bits/stdc++.h>
using namespace std;
#define int long long
int n,dp[100001][4],a[100001],b[100001],c[100001];

int vacation(int ind ,int fl){
	if(ind == n)return 0;
	
	if(dp[ind][fl] != -1)return dp[ind][fl];
	if(fl == 0){
		int A = a[0] + vacation(ind+1,1);
		int B = b[0] + vacation(ind+1,2);
		int C = c[0] + vacation(ind+1,3);
		return dp[ind][fl] = max(A,max(B,C));
	}
	else if(fl == 1){
		int B = b[ind] + vacation(ind+1,2);
		int C = c[ind] + vacation(ind+1,3);
		return dp[ind][fl] = max(B,C);
	}
	else if(fl == 2){
		int A = a[ind] + vacation(ind+1,1);
		int C = c[ind] + vacation(ind+1,3);
		return dp[ind][fl] = max(A,C);
	}
	else if(fl == 3){
		int A = a[ind] + vacation(ind+1,1);
		int B = b[ind] + vacation(ind+1,2);
		return dp[ind][fl] = max(A,B);
	}
}



signed main(){
	cin >> n;
	
	for(int i = 0;i<n;i++){
		cin >> a[i] >> b[i] >> c[i];
	}
	for(int i = 0;i<100001;i++){
		for(int j = 0;j<4;j++){
			dp[i][j] = -1;
		}
	}
	
	cout << vacation(0,0);
	
	return 0;
}

Measured memory_bytes: 13736
#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)
ll MOD=1e9+7;

ll f(pair<string,ll>&x ,pair<string,ll>&y) 
{
	if(x.first == y.first) 
	{
		return x.second>y.second;
	}
	else 
	{
		return x.first<y.first;
	}
}
 
void solve()
{
	ll n;
	cin>>n;
	vector<ll> a(n+1),pre(n+2),suf(n+2);
	for(ll i=1;i<=n;i++)
	{
		cin>>a[i];
		pre[i]=gcd(pre[i-1],a[i]);
	}
	ll ans=1;
	for(ll i=n;i>=1;i--)
	{
		suf[i]=gcd(suf[i+1],a[i]);
	}
	for(ll i=1;i<=n;i++)
	{
		ans=max(ans,gcd(pre[i-1],suf[i+1]));
	}
	cout<<ans;
	return;
}

int main()
{
        fast;
        ll q;
        q=1;
        // cin>>q;
        while(q--)
        	solve();
        
        return 0;
}


Measured memory_bytes: 5500
#include <bits/stdc++.h>
using namespace std;
#define li          long
#define ll          long long
#define ull         unsigned long long
#define ff          first
#define ss          second
#define pii         pair<int,int>
#define pli         pair<li,li>
#define pll         pair<ll,ll>
#define pb          push_back
#define fo(i,k,n)   for(int i = k;i<n; i++)
#define ro(i,k,n)   for(int i = k; i>=n; i--)
#define tc          int t;cin>>t;while(t--)
#define all(v)      v.begin(),v.end()
#define inf         INT_MAX
#define ninf        INT_MIN
#define v(x)        vector<x>
#define int         long long
#define ar(x,y)     array<x,y>
#define p(x,y)      pair<x,y>
const ll mod1 = 99844353;
const ll mod2 = 1e9+7;
/* template <class T>
using oset = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>; */

template<typename T>
T gcd(T a,T b){
    return b ? gcd(b, a%b) : a;
}

void fastio()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}

int power(int x,int y){
    int res = 1;
    while(y > 0){
         if(y & 1) res *= x;
         y >>= 1;
         x *= x;
    }
    return res;
}

int power(int x,int y,int mod){
     int res = 1;
     x %= mod;
     while(y > 0){
          if(y & 1) res = (res * x) % mod;
          y >>= 1;
          x = (x * x) % mod;
     }
     return res;
}

class Template {
    int* readArray(int n){
        int *res = new int[n];
        for(int i = 0; i<n; i++){
            cin >> res[i];
        }
        return res;
    }
    void destroy(int *x){
        delete[] x;
    }
    v(int) readVector(int n){
        v(int) res(n);
        for(int i = 0; i<n; i++){
            cin >> res[i];
        }
        return res;
    }
    public:
    void solveOne(istream &in, ostream &out) {
        int n;
        in >> n;
        set<int> posPos,negPos,posNeg,negNeg;
        int ans = -1;
        for(int i = 0; i<n; i++){
            int x,y;
            in >> x >> y;
            if(i != 0){
                ans = max({ans,(x+y - *posPos.begin()),(y-x - *negPos.begin()),(x-y-*posNeg.begin()),(-x-y-*negNeg.begin())});
            }
            posPos.insert(x+y);
            negPos.insert(-x+y);
            posNeg.insert(x-y);
            negNeg.insert(-x-y);
        }
        out << ans << "\n";
    }
    
    void solve(istream &in, ostream &out) {
        int nt = 1;
        //in >> nt;
        for (int it = 0; it < nt; ++it) {
            solveOne(in, out);
        }
    }
};
 
signed main() {
  fastio();
  Template solver;
  istream& in(cin);
  ostream& out(cout);
  solver.solve(in, out);
  return 0;
}

Measured memory_bytes: 41144
#include <iostream>
#include <vector>
int main(){
    using namespace std;
    int n,x,i,j,k,l,ans;
    vector<int> vn;
    vector<int> vx;
    while(1){
        cin >> n >> x;
        if(n==0&&x==0){
            break;
        }
        vn.push_back(n);
        vx.push_back(x);
    }
    int size = vn.size();
    for(i=0;i<size;i++){
        ans = 0;
        for(j=1;j<=(vx[i]/3);j++){
            for(k=j+1;k<=vn[i];k++){
                for(l=(vx[i]/3)+1;l<=vn[i];l++){
                    if(j+k+l==vx[i]&&j<k&&k<l){
                        ans++;
                    }
                }
            }
        }
        cout << ans << endl;
    }
    return 0;
}

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

int main() {
  int num;
  cin >> num;
  
  // 千の位の数
  int a = num / 1000;
  num -= a * 1000;
  
  // 百の位の数
  int b = num / 100;
  num -= b * 100;
  
  //　十の位の数
  int c = num / 10;
  num -= c * 10;
  
  // 一の位の数
  int d = num;
  
  
  bool isGoodNum = (a == b && b == c) || (b == c && c == d);
  
  if(isGoodNum)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100000;
int n, l[maxn + 10], r[maxn + 10];
long long ans;
int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n; ++i)
		scanf("%d%d", &l[i], &r[i]);
	sort(l, l + n + 1, greater<int>());
	sort(r, r + n + 1);
	for (int i = 0; i <= n; ++i)
		ans += 2 * max(l[i] - r[i], 0);
	printf("%lld", ans);
}


Measured memory_bytes: 1276
#include<bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#define show(x) cout<<#x<<"="<<x<<"\n"
using namespace std;

int n,m;
string s;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);
    cout<<fixed;
#ifdef LOCAL_DEFINE
    FILE *stream1;
    //FILE *stream2;
    stream1=freopen("in","r",stdin);
    //stream2=freopen("out","w",stdout);
    if(stream1==NULL)return 0;
    //if(stream2==NULL)return 0;
#endif
    cin>>n;
    cout<<24+(24-n)<<endl;
#ifdef LOCAL_DEFINE
    cerr<<"Time elapsed: "<<1.0*clock()/CLOCKS_PER_SEC<<"s.\n";
    fclose(stream1);
    //fclose(stream2);
#endif
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < n; i++)
using P = pair <int, int>;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
ll gcd(ll a,ll b) {return  b ? gcd(b,a%b) : a;}
const long long INF = 1LL << 60;
const int mod = 1000000007;
const double PI = acos(-1.0);
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};

int main () {
     string s;
     cin >> s;
     set<char> se;
     rep(i,s.size()){
          se.insert(s[i]);
     }     
     if(se.size()==4) cout << "Yes" <<endl;
     else if(se.size()==2&&se.count('E')&&se.count('W')){
          cout << "Yes" <<endl;
     }
     else if(se.size()==2&&se.count('N')&&se.count('S')){
          cout << "Yes" <<endl;
     }
     else cout << "No" <<endl;
}

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

typedef long long ll;

int main() {
    ll N, K, MOD = 1e9 + 7, ans = 0;
    cin >> N >> K;
    for (ll i = K; i <= N + 1; i++) {
        ans = (ans + (N - i + 1) * i + 1) % MOD;
    }
    cout << ans << "\n";
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	scanf("%d",&n);
	set<string>s;
	for(int i=0;i<n;i++){
		string str;
		cin>>str;
		s.insert(str);
	}
	cout<<s.size()<<endl;
	return 0;
}

Measured memory_bytes: 19268
N,M = map(int,input().split())
ans = []
if N % 2 == 1:
    N -= 1
    a = N // 2
    b = N // 2 + 1
    ans.append([a,b])
    for i in range(M):
        a -= 1
        b += 1
        ans.append([a,b])
else:
    a = N // 2
    b = N // 2 + 1
    ans.append([a,b])
    c = 1
    d = N - 1
    ans.append([c,d])
    for i in range(M):
        a -= 1
        b += 1
        ans.append([a,b])
        c += 1
        d -= 1
        ans.append([c,d])
for i in range(M):
    print('{0} {1}'.format(ans[i][0],ans[i][1])) 

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

int main(){
int N;
  cin >> N;
 int x[N];
 int count;
 for(int i=0;i<N;i++){
    cin >> x[i];    
 }
  
if(N>=3){
  int count =0;
for(int i=0;i<N;i++){
for(int j=i+1;j<N;j++){ 
for(int k=j+1;k<N;k++) {
  if(x[i]>abs(x[j]-x[k]) && x[i]<x[j]+x[k] && x[i]!=x[j] && x[j]!=x[k] && x[k]!=x[i]) count++;
  }  
  }
}
  cout << count << endl;
}
  else cout << 0 << endl;
}

Measured memory_bytes: 3624
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <functional>
#include <climits>
#include <cmath>

using namespace std;



int main(int argc, char *argv[])
{
	int N, M, C;
	//input
	cin >> N >> M >> C;

	vector<int> b;
	for (int i = 0; i < M; i++){
		int bi;
		cin >> bi;
		b.push_back(bi);
	}

	//calc
	int ans = 0;
	for (int j = 0; j < N; j++){
		int ab = 0;
		for (int i = 0; i < M; i++){
			int ai;
			cin >> ai;

			ab += ai * b[i];
		}
		if (ab + C > 0){
			ans++;
		}
	}


	//ans
	cout << ans << endl;


	return 0;
}


Measured memory_bytes: 256
import std.stdio,std.string,std.conv;
void main(){
	auto debt = 10_0000;
	auto week = to!int( readln().chomp() ) ;
	for( ; 0<week ; week-- ){
		debt *= 1.05;
		debt += (debt%1000)?1000-debt%1000:0;
	}
	writeln(debt);
}

Measured memory_bytes: 1040
#include <bits/stdc++.h>
 
const double pi = 3.141592653589793238462643383279;
 
 
using namespace std;
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<long long, long long> PLL;
typedef pair<int, PII> TIII;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
 
 
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SQ(a) ((a)*(a))
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
 
 
//repetition
//------------------------------------------
#define FOR(i,s,n) for(int i=s;i<(int)n;++i)
#define REP(i,n) FOR(i,0,n)
#define MOD 1000000007
 
 
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
 
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
const double EPS = 1E-10;
 
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)


//ここから編集
 
const int MAX = 2000010;
long long fac[MAX], finv[MAX], inv[MAX];
 
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
 
// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

ll dp[1000010][2];
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  string s; cin >> s;

  s = '0' + s;
  reverse(all(s));
  REP(i,s.size()+1) REP(j,2) dp[i][j] = (1LL<<60);
  dp[0][0] = 0;
  for(int i=0; i<s.size(); i++){
    dp[i+1][0] = min(dp[i+1][0], min(dp[i][0] + (s[i] - '0') , dp[i][1] + (s[i]-'0' + 1)));
    dp[i+1][1] = min(dp[i+1][1], min(dp[i][0] + (10-(s[i] - '0')) , dp[i][1] + 10 - (s[i]-'0') -1));
  }
  cout << dp[s.size()][0] << endl;
  return 0;
}

Measured memory_bytes: 20044