akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>

using namespace std;

int main () {
  int N, X;
  cin >> N >> X;
  int L[N];
  for (int i = 0; i<N; i++) cin >> L[i];
  int ans = 1;

  int d = 0;
  for (int i=1; i<N+1; i++) {
    d = d + L[i-1];
    if (d > X) break;
    ans++;
  }

  cout << ans;
}


Measured memory_bytes: 256
from math import sqrt
from collections import Counter
from functools import reduce
from operator import mul
n = int(open(0).read().rstrip())
c = Counter()

sieve = [True]*(n+1)
sieve[0] = sieve[1] = False

tmp = n
while tmp:
    c[2] += tmp//2
    tmp //= 2

for i in range(4, n+1, 2):
    sieve[i] = False
for i in range(3, n+1, 2):
    if sieve[i]:
        tmp = n
        while tmp//i:
            c[i] += tmp//i
            tmp //= i
        for j in range(2*i, n+1, i):
            sieve[j] = False

ans = 1
for x in sorted(c.values()):
    ans *= x+1
    ans %= 10**9 + 7
print(ans)

Measured memory_bytes: 68688
//Moh_K_Imar .......
//28/08/2020  ... 11,13.
//Ya Rab....
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
int main(){
    ll n,a,b;
    cin>>n>>a>>b;
    ll x=n*a;
    if(x<=b)cout<<x<<endl;
    else cout<<b<<endl;

    return 0;
}



Measured memory_bytes: 3596
def main():
    num = int(input())
    for i in range(num):
        t = list(input())

        tlist = []
        for j in range(len(t) - 1):
            j += 1
            k = len(t) - j
            a = t[:j]
            b = t[-k:]
            arev = []
            brev = []
            for i in range(len(a)):
                j = len(a) - i - 1
                arev.append(a[j])
            for i in range(len(b)):
                j = len(b) - i - 1
                brev.append(b[j])
            app(tlist, a + b)
            app(tlist, a + brev)
            app(tlist, arev + b)
            app(tlist, arev + brev)
            app(tlist, b + a)
            app(tlist, b + arev)
            app(tlist, brev + a)
            app(tlist, brev + arev)
        print(len(tlist))
        
def app(tlist, new):
    for item in tlist:
        if item == new: return
    tlist.append(new)
    return

main()



Measured memory_bytes: 6032
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(300000)


def solve(A: int, B: int, C: int, D: int):
    def gcd(a, b):
        if b == 0:
            return a
        return gcd(b, a % b)
    g = gcd(C, D)
    c = B // C - (A - 1) // C
    d = B // D - (A - 1) // D
    cd = B // (C * D // g) - (A - 1) // (C * D // g)
    #print(c, d, cd)
    ret = B - A - c - d + cd + 1
    print(ret)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    C = int(next(tokens))  # type: int
    D = int(next(tokens))  # type: int
    solve(A, B, C, D)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;

import static java.lang.Math.*;
import static java.util.Arrays.*;

public class Main{

	Scanner sc;

	static final int INF=1<<28;
	static final double EPS=1e-9;

	void run(){
		sc=new Scanner(System.in);
		for(; sc.hasNext();){
			int n=sc.nextInt();
			println((n*(n+1)/2+1)+"");
		}
		sc.close();
	}

	void print(String s){
		System.out.print(s);
	}

	void println(String s){
		System.out.println(s);
	}

	public static void main(String[] args){
		new Main().run();
	}
}

Measured memory_bytes: 12000
S = input()

if S == "SUN":
  print("7")
elif S == "MON":
  print("6")
elif S == "TUE":
  print("5")
elif S == "WED":
  print("4")
elif S == "THU":
  print("3")
elif S == "FRI":
  print("2")
elif S == "SAT":
  print("1")
else:
  pass

Measured memory_bytes: 2940
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main(){
    ll n,ans; cin>>n;
    ans=n*(n+1)/2;
    vector<ll> a(n,0);
    rep(i,n) cin>>a[i];
    ll l=0,r=0,sum=a[0],xsum=a[0];
    while(r<n){
        if(sum==xsum){
            r++;
            if(r==n) break;
            sum+=a[r];
            xsum^=a[r];
        }
        else{
            ans-=n-r;
            sum-=a[l];
            xsum^=a[l];
            l++;
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 1792
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Mon Feb 11 05:38:56 2019

@author: shinjisu
"""


# ABC 200点問題
import math


def getInt(): return int(input())


def getIntList(): return [int(x) for x in input().split()]


def zeros(n): return [0]*n


def dmp(x):
    global debug
    if debug:
        print(x)


debug = True


def getIntLines(n): return [int(input()) for i in range(n)]


def getIntMat(n):
    mat = []
    for i in range(n):
        mat.append(getIntList())
    return mat


def zeros2(n, m): return [zeros(m)]*n


def prob096():  # Maximum Sum
    X = getIntList()
    K = getInt()
    dmp((X, K))
    total = sum(X) - max(X) + max(X)*2**K
    return total


def prob097():  # Exponential
    X = getInt()
    dmp(X)
    if X == 1:
        return 1
    for n in range(X, 0, -1):
        dmp(n)
        for b in range(2, int(math.sqrt(X))+1):
            a = n
            exp = True
            while a > 1:
                if a % b != 0:
                    exp = False
                    break
                a //= b
            if exp:
                break
        if exp:
            break
    return n


def prob098():  # Cut and Count
    N = getInt()
    S = input()
    dmp((N, S))
    maxChCount = 0
    for i in range(1, N):
        before = S[:i]
        after = S[i:]
        dmp((before, after))
        chCount = 0
        for j in range(26):
            ch = chr(ord('a')+j)
            if ch in before and ch in after:
                chCount += 1
        maxChCount = max(maxChCount, chCount)
    return maxChCount


def prob099():  # Stone Momument
    a, b = getIntList()
    height = 0
    for i in range(b-a+1):
        height += i
    height -= b
    return height

def prob000():  # 
    return 0


debug = False  # True False
print(prob099())


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

long long n;
int x, m;
int nxt[100005];
long long ans;

int main() {
	scanf("%lld", &n);
	scanf("%d%d", &x, &m);
	memset(nxt, -1, sizeof nxt);
	long long cur = x;
	while (n > 0) {
		ans += cur;
		n--;
		if (nxt[cur] != -1) {
			int temp = nxt[cur];
			long long cyclew = cur;
			int cycle = 1;
			while (temp != cur) {
				cycle++;
				cyclew += temp;
				temp = nxt[temp];
			}
			ans += cyclew * (n / cycle);
			n %= cycle;
			temp = nxt[cur];
			while (n > 0) {
				ans += temp;
				n--;
				temp = nxt[temp];
			}
			break;
		}
		nxt[cur] = (cur * cur) % m;
		cur = nxt[cur];
	}
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 4220
N, Q = map(int, input().split())
l=[None]*N
l[0]=[1,1,0]
for i in range(1,N):
    a,b=map(int,input().split())
    l[i]=[b,a,0]
l.sort()
for i in range(Q):
    p,x=map(int,input().split())
    l[p-1][2]+=x
t=[l[0][2]]+[None]*(N-1)
for i in range(1,N):
    t[i]=t[l[i][1]-1]+l[i][2]
print(*t)

Measured memory_bytes: 55604
#include <bits/stdc++.h>
#define int long long
#define gcd            __gcd
#define setbits(x)     __builtin_popcountll(x)
#define zrobits(x)     __builtin_ctzll(x)
#define mod            1000000007
#define mod2           998244353
#define maxe           *max_element
#define mine           *min_element
#define inf            1e18
#define deci(x,y)      fixed<<setprecision(y)<<x
#define w(t)           int t; cin>>t; while(t--)
#define nitin          ios_base::sync_with_stdio(false); cin.tie(NULL)
#define PI             3.141592653589793238
using namespace std;

int power(int x, int y, int p)
{
    int res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = (res * x) % p;
        y = y >> 1;
        x = (x * x) % p;
    }
    return res;
}
int modi(int a, int m)
{
    return power(a, m - 2, m);
}
int32_t main()
{
    nitin;
    int n;
    cin>>n;
    vector<int>v(2*n,0);
    for(int i=0;i<2*n;i++)
        cin>>v[i];
    sort(v.begin(),v.end());
    int ans=0;
    for(int i=0;i<2*n;i+=2)
    {
        ans+=v[i];
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3636
#include<stdio.h>
int return_max(int a,int b){
  if(a>b){
    return a;
  }else{
    return b;
  }
}

int main(void)
{
  int a,b;
  scanf("%d %d",&a,&b);
  printf("%d\n",return_max(a+b,return_max(a-b,a*b)));
  return 0;
}


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

using namespace std;

#define int long long int
#define ld long double
#define F first
#define S second
#define P pair<int,int>
#define pb push_back
#define type int
const int N = 100005;


int find(int cur,int a[],int n,int k){
    int dp[n+1];
    dp[0]=0;
    for(int i=1;i<n;i++){
        int m=INT_MAX;
        for(int j=1;j<=k;j++){
            if(i-j>=0)
            {
            int q=abs(a[i]-a[i-j])+dp[i-j];
            m=min(m,q);
            }
        }
        dp[i]=m;
    }
    return dp[n-1];
}

int32_t main()
{
    // #ifndef ONLINE_JUDGE
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    // #endif
    ios_base:: sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    // int t;cin>>t;while(t--){
    // }
    // memset(memo,0,sizeof(int)*N);
    int n,k;
    cin>>n>>k;
    int a[n];
    for(int i=0;i<n;i++)
        cin>>a[i];
    cout<<find(0,a,n,k);
}


Measured memory_bytes: 1792
#include<iostream>
#include<algorithm>

using namespace std;

int main(){
  for(int n;cin>>n,n;){
    int t=0,p=0;
    int dp[41][5];
    fill(dp[0],dp[41],1e9);
    dp[0][0]=0;
    for(int i=0;i<n;i++){
      int ti,pi;
      cin>>pi>>ti;
      bool f=false;
      for(int j=0;j<=3;j++){
	if(dp[i][j]>1e8)continue;
	if(j<3&&abs(pi-p)*(j+1)<=(ti-t)){
	  f=true;
	  dp[i+1][j+1]=min(dp[i+1][j+1],dp[i][j]+abs(pi-p));
	}
	if(p*(j+1)+pi<=ti-t){
	  f=true;
	  dp[i+1][1]=min(dp[i+1][1],dp[i][j]+pi+p);
	}
      }
      t=ti;
      p=pi;
      if(!f){
	cout<<"NG "<<i+1<<endl;
	while(i++,i<n){
	  int a,b;
	  cin>>a>>b;
	}
	goto next;
      }
    }
    cout<<"OK "<<*min_element(dp[n],dp[n+1])+p<<endl;
  next:
    ;
  }
}

Measured memory_bytes: 1160
use std::cmp::max;

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

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

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

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

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

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

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

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

fn main() {
    input! {
        n: usize,
        a: [i64; n],
    }
    let mut dp0 : Vec<i64> = Vec::new();
    let mut dp1 : Vec<i64> = Vec::new();
    dp0.resize(n + 1, 0);
    dp1.resize(n + 1, 0);
    dp0[0] = a[0];
    dp1[0] = -a[0];
    for i in 1..n - 1 {
        dp0[i] = max(dp0[i - 1] + a[i], dp1[i - 1] - a[i]);
        dp1[i] = max(dp0[i - 1] - a[i], dp1[i - 1] + a[i]);
    }
    dp0[n - 1] = dp0[n - 2] + a[n - 1];
    dp1[n - 1] = dp1[n - 2] - a[n - 1];
    println!("{}", max(dp0[n - 1], dp1[n - 1]));
}


Measured memory_bytes: 6396
/**
 *    author:  FromDihPout
 *    created: 2020-08-09
**/

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

#define all(x) (x).begin(), (x).end()

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    sort(all(a));
    
    int ans = 0;
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            int sum = a[i] + a[j];
            int l = j + 1, r = n;
            while (l < r) {
                int mid = (l + r) / 2;
                if (a[mid] >= sum) {
                    r = mid;
                }
                else {
                    l = mid + 1;
                }
            }
            ans += r - j - 1;
        }
    }
    cout << ans << '\n';
    return 0;
}

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

int main(){
	int N;
	cin >> N;
	int Size = ceil(sqrt(N));
	vector<string> table[Size];
	int sum = 0;
	while(N-- > 0){
        string S;
        cin >> S;

        int temp = 0;
        for(int a = 0; a < S.size(); a++){
            temp += S[a] - 'a' + 1;
            temp *= 26;
            temp %= Size;
        }

        int found = false;
        for(int a = 0; a < table[temp].size(); a++){
            if(S.compare(table[temp][a]) == 0){
                found = true;
                break;
            }
        }

        if(!found){
            sum++;
            table[temp].push_back(S);
        }
	}

	cout << sum << endl;
	return 0;
}


Measured memory_bytes: 11164
N, M = map(int, input().split())
imos = [0]*(N+2)
for i in range(M):
    L, R = map(int, input().split())
    imos[L] += 1
    imos[R+1] -= 1

for i in range(2, N+1):
    imos[i] += imos[i-1]

ans = 0
for i in range(1, N+1):
    if imos[i] == M:
        ans += 1

print(ans)


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

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define mp make_pair
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define MOD 1000000007

int main(){
  char b;
  cin >> b;
  if(b=='A') cout <<"T" <<endl;
  else if(b=='T') cout << "A" <<endl;
  else if(b=='C') cout << "G" <<endl;
  else if(b=='G') cout << "C" <<endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<algorithm>
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;

int main() {
    int h, w, n;
	cin >> h >> w >> n;
	int ans;
	int a = max(h, w);
	ans = (n + a - 1) / a;
	cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
typedef struct 
{
  char mark;
  int number;
}card;

void bubblesort(card*,int);
void selectionsort(card*,card*,int);

int main(){
  int n,i,j,t;
   card detail[36],detail2[36];
  char a;
  

  scanf("%d",&n);
  
  for(i=0; i<n; i++)
    {
    scanf(" %c%c",&detail[i].mark,&a);
    detail[i].number = atoi(&a);
  }

  for(i=0; i<n; i++)
  detail2[i]=detail[i];
  bubblesort(detail,n);
  selectionsort(detail,detail2,n);
  return 0;
}
  

void bubblesort(card a[],int n){
  int i,j;
  card tmp;
  for(i=0;i<n;i++){
    for(j=n-1;j>i;j--){
      if(a[j].number<a[j-1].number){
	tmp=a[j];  //swap
	a[j]=a[j-1];
	a[j-1]=tmp;
      }
    }
  }

  for(i=0; i<n; i++){
    if(i>0)printf(" ");
    printf("%c%d",a[i].mark,a[i].number);
  }

  printf("\n");
  printf("Stable\n");    
}


void  selectionsort(card a[],card a2[],int n){
  int i,j,minj,count=0;
  card tmp;
  for(i=0; i<=n; i++){
    minj=i;
    for(j=i; j<n; j++){
      if(a2[j].number<a2[minj].number){
	minj=j;
      }
    }
    tmp=a2[i]; //swap
    a2[i]=a2[minj];
    a2[minj]=tmp;
}
  for(i=0; i<n; i++){
    if(i>0)printf(" ");
    printf("%c%d",a2[i].mark,a2[i].number);
  }
  printf("\n");

  
  for(i=0;i<n;i++){
    if(a[i].mark != a2[i].mark || a[i].number != a2[i].number){
      printf("Not stable\n");
      count=1;
      break;
    } }
  
  if(count != 1) printf("Stable\n");
  
}

 



Measured memory_bytes: 2108
#include <bits/stdc++.h>
using namespace std;
#define LL long long 
#define LLU long long unsigned
#define rarr(arr, n) for(int aab = 0; aab < n; aab++){cin >> arr[aab];}
#define parr(arr, n) for(int aab = 0; aab < n; aab++){cout << arr[aab] << " ";}
#define pb push_back
#define f first
#define s second
#define all(x) x.begin(), x.end()
#define debug(x) cout << #x << " = " << x << "\n";

#define freopen freopen("in.txt", "r", stdin);freopen("out.txt", "w", stdout);ios_base::sync_with_stdio(0);cin.tie(0);

bool flag = 0;

void recursive(int a, int b, int c, int k, int counter){
	if(c > b && b > a){
		flag = true;
		return;
	}
	if(counter == k){
		return;
	}
	recursive(a * 2, b, c, k, counter + 1);
	recursive(a, b * 2, c, k, counter + 1);
	recursive(a, b, c * 2, k, counter + 1);
}

int main(){
	int a, b, c, k;
	cin >> a >> b >> c >> k;
	recursive(a, b, c, k, 0);
	cout << (flag ? "Yes" : "No");
}

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

#define lint long long
#define P pair<int, int>
#define LLP pair<long long, long long>
#define REP(i, x, n) for(int i = (x), i##_len = (int)(n) ; i < i##_len ; ++i)
#define rep(i, n) for(int i = 0, i##_len = (int)(n) ; i < i##_len ; ++i)
#define reps(i, n) for(int i = 1, i##_len = (int)(n) ; i <= i##_len ; ++i)
#define rrep(i, n) for(int i = (int)(n) - 1 ; i >= 0 ; --i)
#define rreps(i, n) for(int i = (int)(n) ; i > 0 ; --i)
#define SORT(x) sort((x).begin(), (x).end())
#define SORT_INV(x) sort((x).rbegin(), (x).rend())

const int IINF = (1 << 30) - 1;
const long long LLINF = 1LL << 61;
const long long MOD = 1000000007LL;
const int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
const int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};
const double EPS = 1e-8;

struct edge{
    int to;
    lint yen, snuuk;
};

struct node{
    int id;
    lint cost;

    bool operator<(const node & right) const {
        return cost > right.cost;
    }
};

template<typename T>
bool chmin(T &_a, T _b){
    if(_a > _b){
        _a = _b;
        return true;
    }else{
        return false;
    }
}

template<typename T>
bool chmax(T &_a, T _b){
    if(_a < _b){
        _a = _b;
        return true;
    }else{
        return false;
    }
}

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

    int n, m, s, t;
    cin >> n >> m >> s >> t;
    --s;
    --t;

    vector< vector<edge> > g(n);
    rep(i, m){
        int u, v;
        lint a, b;
        cin >> u >> v >> a >> b;
        --u;
        --v;
        g[u].push_back({v, a, b});
        g[v].push_back({u, a, b});
    }

    vector<lint> yen(n, LLINF), snuuk(n, LLINF);
    priority_queue<node> que;
    que.push({s, 0LL});
    while(!que.empty()){
        node now = que.top();
        que.pop();
        if(!chmin(yen[now.id], now.cost)){
            continue;
        }
        for(auto e : g[now.id]){
            if(yen[e.to] > now.cost + e.yen){
                que.push({e.to, now.cost + e.yen});
            }
        }
    }
    que.push({t, 0LL});
    while(!que.empty()){
        node now = que.top();
        que.pop();
        if(!chmin(snuuk[now.id], now.cost)){
            continue;
        }
        for(auto e : g[now.id]){
            if(snuuk[e.to] > now.cost + e.snuuk){
                que.push({e.to, now.cost + e.snuuk});
            }
        }
    }

    vector<lint> ans(n, (lint)1e15);
    rep(i, n){
        ans[i] -= yen[i] + snuuk[i];
    }
    rrep(i, n - 1){
        chmax(ans[i], ans[i + 1]);
    }

    rep(i, n){
        cout << ans[i] << endl;
    }

    return 0;
}

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

int main(){
  int n;
  cin >> n;
  int ans = (int)(n/1.08);
  int ans1 = ans + 1;
  if((int)(ans*1.08) == n){
    cout << (int)ans;
  }else if((int)(ans1*1.08) == n){
    cout << (int)ans1;
  }else{
    cout << ":(";
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define r(i,n) for(int i=0;i<n;i++)
typedef pair<int,int>P;
typedef pair<P,P>PP;
string s;
int p,n,c=0;
string bnf1();
string get(){
  string res;
  if(s[p]=='(')p++,res=bnf1(),p++;
  else if(isdigit(s[p])||isalpha(s[p])){
    while(isdigit(s[p])||isalpha(s[p])){
      res+=s[p++];
      if(res.size()>1000000)return res.substr(0,1000009);
    }
  }
  return res;
}
string bnf2(){
  string res=get();
  while(s[p]=='*'){
    if(res.size()>1000000)return res.substr(0,1000009);
    p++;
    string res2=get();
    int num=0;
    r(i,res.size())num=num*10+(res[i]-'0');
    res=res2;
    r(i,num-1){
      res+=res2;
      if(res.size()>1000000)return res.substr(0,1000009);
    }
  }
  return res;
}
string bnf1(){
  string res=bnf2();
  while(s[p]=='+'){
    if(res.size()>1000000)return res.substr(0,1000009);
    p++;
    string res2=bnf2();
    res+=res2;
    if(res.size()>1000000)return res.substr(0,1000009);
  }
  return res;
}
int main(){
  while(cin>>s>>n,s!="0"){
    p=0;
    r(i,(int)s.size()-1){
      if(isdigit(s[i])&&s[i+1]=='('||isdigit(s[i])&&isalpha(s[i+1])){
        s=s.substr(0,i+1)+"*"+s.substr(i+1);
        i--;
      }
      else if(s[i]==')'&&isalpha(s[i+1])||s[i]==')'&&isdigit(s[i+1])||isdigit(s[i+1])&&isalpha(s[i])){
        s=s.substr(0,i+1)+"+"+s.substr(i+1);
        i--;
      }
    }
    string ans=bnf1();
    if(n<ans.size())cout<<ans[n]<<endl;
    else cout<<0<<endl;
  }
}

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

int main(){
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  while(c>0&&a>0){
    c=c-b;
    if(c<=0) {
      cout<<"Yes"<<endl;
      return 0;
    }
    a=a-d;
    if(a<=0) {
      cout<<"No"<<endl;
      return 0;
    }
  }
}

Measured memory_bytes: 3620
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<array>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<functional>
#include<limits>
#include<list>
#include<map>
#include<numeric>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<unordered_map>
#include<queue>
#include<vector>
using namespace std;

//#define int long long
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()
#define dump(o) if(DEBUG){cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) if(DEBUG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
const int MOD = 1e9 + 7;
const bool DEBUG = false;

signed main() {
	string X; cin >> X;
	stack<char> st;
	rep(i, 0, X.size()) {
		if (X[i] == 'T' && !st.empty() && st.top() == 'S') {
			st.pop();
		}
		else st.push(X[i]);
	}
	cout << st.size() << endl;
	return 0;
}

Measured memory_bytes: 644
#include <cstdio>
#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <cmath>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#define rep(i,n) for (int i=0;i<n;i++)
using ll = long long;
using namespace std;

void solve(){

}
int main (){
    ios::sync_with_stdio(0);
    cin.tie(0);
    vector<vector<int>> a(3,vector<int> (3));
    vector<bool> b(101,false);
    rep(i,3){
        rep(j,3){
            cin >> a[i][j];
        }
    }
    int n;
    cin >> n;
    rep(i,n){
        int m;
        cin >> m;
        b[m] = true;
    }
    
    rep(i,3){
        bool q1=false;
        rep(j,3){
            if(b[a[i][j]]){
                q1 = true;
            }
            else{
                q1 = false;
                break;
            }
        }
        if(q1){
            cout << "Yes";
            return 0;
        }
    }
    rep(i,3){
        bool q2=false;
        rep(j,3){
            if(b[a[j][i]]){
                q2 = true;
            }
            else{
                q2 = false;
                break;
            }
        }
        if(q2){
            cout << "Yes";
            return 0;
        }
    }
    if(b[a[0][0]]&&b[a[1][1]]&&b[a[2][2]]){
        cout << "Yes";
        return 0;
    }
    if(b[a[0][2]]&&b[a[1][1]]&&b[a[2][0]]){
        cout << "Yes";
        return 0;
    }
    cout << "No";
    return 0;
}

Measured memory_bytes: 3664
#include "bits/stdc++.h"

#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i, x, n) for(int i = x; i >= n; i--)
#define rrep(i, n) RREP(i,n,0)
#define pb push_back

using namespace std;

// #define DEBUG_IS_VALID

#ifdef DEBUG_IS_VALID
#define DEB 1 
#else
#define DEB 0
#endif
#define DUMPOUT cout
#define dump(...) if(DEB) DUMPOUT<<"  "<<#__VA_ARGS__<<" :["<<__LINE__<<":"<<__FUNCTION__<<"]"<<endl<<"    "; if(DEB) dump_func(__VA_ARGS__)
template<typename T>ostream& operator << (ostream& os, vector<T>& vec) { os << "{"; for (int i = 0; i<vec.size(); i++) os << vec[i] << (i + 1 == vec.size() ? "" : ", "); os << "}"; return os; }
// template<typename T>ostream& operator << (ostream& os, map<T>& mp) { 
//   os << "{";
//   for (auto itr = mp.begin();itr != mp.end();itr++)
//    os << itr->first << "," << itr->second << (itr==mp.rbegin() ? "" : ", ");
//   os << "}";
//   return os;
// }
void dump_func(){DUMPOUT << endl;}
template <class Head, class... Tail>void dump_func(Head&& head, Tail&&... tail){ DUMPOUT << head; if (sizeof...(Tail) == 0) { DUMPOUT << " "; } else { DUMPOUT << ", "; } dump_func(std::move(tail)...);}
template<class T> inline void chmax(T& a,T const& b){a=max(a,b);}
template<class T> inline void chmin(T& a,T const& b){a=min(a,b);}

using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;

const int mod=1e9+7,INF=1<<30;
const double EPS=1e-12,PI=3.1415926535897932384626;
const ll lmod = 1e9+7,LINF=1LL<<60; 
const int MAX_N = 200005;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s[14];
  int H,W; cin >> H >> W;
  rep(i,H) cin >> s[i];
  map<char,int> cnt1[14],cnt2[14];
  rep(i,H){
    rep(j,W) cnt1[i][s[i][j]] = (cnt1[i].count(s[i][j]) ? cnt1[i][s[i][j]]+1 : 1);
  }
  rep(j,W){
    rep(i,H) cnt2[j][s[i][j]] = (cnt2[j].count(s[i][j]) ? cnt2[j][s[i][j]]+1 : 1);
  }
  bool used = false;
  rep(i,H/2){
    bool update = false;
    REP(ii,i+1,H){
      if(cnt1[i]==cnt1[ii]){
        swap(s[ii],s[H-1-i]);
        swap(cnt1[ii],cnt1[H-1-i]);
        update = true;
        break;
      }
    }
    if(used) continue;
    if(!update){
      if(H%2==1 && i!=H/2){
        swap(s[i],s[H/2]);
        swap(cnt1[i],cnt1[H/2]);
        i--;
        used = true;
      }
    }
  }
  string s2[12];
  rep(i,W) s2[i] = string(H,' ');
  rep(i,H) rep(j,W) s2[j][i] = s[i][j];
  used = false;
  rep(i,W/2){
    bool update = false;
    REP(ii,i+1,W){
      if(cnt2[i]==cnt2[ii]){
        swap(s2[ii],s2[W-1-i]);
        swap(cnt2[ii],cnt2[W-1-i]);
        update = true;
        break;
      }
    }
    if(used) continue;
    if(!update){
      if(W%2==1 && i!=W/2){
        swap(s2[i],s2[W/2]);
        swap(cnt2[i],cnt2[W/2]);
        i--;
        used = true;
      }
    }
  }
  rep(i,H) rep(j,W) s[i][j] = s2[j][i];
  
  bool ans = true;
  rep(i,H/2) rep(j,W) ans &= (s[i][j]==s[H-1-i][W-1-j]);
  cout << (ans ? "YES" : "NO") << endl; 

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define all(vec) vec.begin(),vec.end()
typedef long long int ll;
typedef pair<ll,ll> P;
const ll MOD=10000;
const ll INF=1000000010;
const ll LINF=1000000000000000010;
int dx[4]={1,0,-1,0};
int dy[4]={0,-1,0,1};
int h,w,k;
bool field(int x,int y){
    if(x<1||x>w||y<1||y>h){
        return false;
    }
    return true;
}
int main(){
    cin>>h>>w>>k;
    char a[810][810];
    int sx,sy;
    for(int i=1;i<=h;i++){
        string s;cin>>s;
        for(int j=1;j<=w;j++){
            a[i][j]=s[j-1];
            if(a[i][j]=='S'){
                sx=j;sy=i;
            }
        }
    }
    queue<P> q;
    q.push(P(sx,sy));
    int v[810][810];memset(v,-1,sizeof(v));
    v[sy][sx]=0;
    while(!q.empty()){
        int x=q.front().first;
        int y=q.front().second;
        q.pop();
        for(int j=0;j<4;j++){
            int nx=x+dx[j];
            int ny=y+dy[j];
            if(field(nx,ny)&&(a[ny][nx]!='#')&&v[ny][nx]==-1){
                v[ny][nx]=v[y][x]+1;
                q.push(P(nx,ny));
            }
        }
    }
    int res=INF;
    for(int i=1;i<=h;i++){
        for(int j=1;j<=w;j++){
            if(v[i][j]==-1)continue;
            int d1=(v[i][j]+k-1)/k;
            int d2=min(min(i-1,j-1),min(h-i,w-j));
            res=min(res,max(1,d1)+(d2-1+k)/k);
        }
    }
    cout<<res<<endl;
	return 0;
}

Measured memory_bytes: 3456
#include <iostream>
#include <string>
using namespace std;
int main() {
	int n, m,x,a;
	cin >> n >> m;
	a = (n - m)*100;
	int sum = a + m * 1900;
	int kakuritu = 1;
	for (int i = 0; i < m; i++)kakuritu *= 2;
	cout << sum*kakuritu << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define f first
#define s second
using namespace std;
int32_t main(){
    if(fopen("input.txt", "r"))
    freopen("input.txt", "r", stdin),
    freopen("output.txt", "w", stdout);
    ios::sync_with_stdio(0),cin.tie(0);
    int n;
    cin >> n;
    int a[n+1]={0};
    for(int i=1;i<n;i++){
        int x;
        cin >> x;
        a[x]++;
    }
    for(int i=1;i<=n;i++)
        cout << a[i] << '\n';
}

Measured memory_bytes: 5204
def main():
    N = int(input())
    A = int(input())
    B = int(input())
    C = int(input())
    D = int(input())
    E = int(input())

    m = min(A, B, C, D, E)
    if N % m == 0:
        print(N//min(A, B, C, D, E)+4)
    else:
        print(N//min(A, B, C, D, E)+5)


main()


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i,n) for(int64_t i=0;i < (int64_t)(n);i++)
#define invrep(i,n) for(int64_t i=n-1;i >= 0;i--)
using namespace std;

//////全探索したいときに開けよ////////
vector<vector<int>> fspattern;
vector<int> fspattern_draft;
int fspcnt = 0;

void setfspattern_core(int floor,int number,int degree){
  if(floor==degree){
    fspattern.at(fspcnt) = fspattern_draft;
    fspcnt++;
  }else{
    rep(i,number){
      fspattern_draft.at(floor) = i;
      setfspattern_core(floor+1,number,degree);
    }
  }
}

void setfspattern(int number,int degree){
  fspcnt = 0;
  int64_t array_num = 1;
  rep(i,degree){
    array_num *= number;
  }
  fspattern = vector<vector<int>>(array_num,vector<int>(degree));
  fspattern_draft = vector<int>(degree);
  setfspattern_core(0,number,degree);
}

//////nCrのmodを求めたいときに開けよ/////////
//int64_t univMod = 1000000007;
//int64_t factnum = 100000
//vector<int64_t> modfact(factnum);
//vector<int64_t> modinvfact(factnum);

/*void setmodfact(){
  for(int i=0;i<factnum;i++){
    if(i == 0){
      modfact.at(i) = 1;
    }else{
      modfact.at(i) = (modfact.at(i-1)*i)%univMod;
    }
  }
}

int64_t calcmodpower(int64_t a,int64_t n){
  int64_t res = 1;
  while(n != 0){
    if(n & 1){
      res = (res * a) % univMod;
    }
    a = (a*a) % univMod;
    n = n >> 1;
  }
  return res;
}

int64_t calcinverse(int64_t n){
	return calcmodpower(n,univMod-2);
}

void setmodinvfact(){
  for(int i=0;i<factnum;i++){
    if(i==0){
      modinvfact.at(i) = 1;
    }else{
      modinvfact.at(i) = calcmodpower(modfact.at(i),univMod-2);
    }
  }
}*/


/*
int64_t calcGCD(int64_t a,int64_t b){
	int64_t p = a;
	int64_t q = b;
	int64_t c = a%b;
	while(c != 0){
		p = q;
		q = c;
		c = p%q;
	}
	return q;
}
*/

int main(){
  string s;
  cin >> s;
  int n = s.size();
  rep(i,s.size()){
    if( i+1<n && s.at(i) == s.at(i+1)){
      printf("%d %d\n",i+1,i+2);
      return 0;
    }
    if( i+2<n && s.at(i) == s.at(i+2)){
      printf("%d %d\n",i+1,i+3);
      return 0;
    }
  }
  printf("-1 -1\n");
       
}
      

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll

#define INF 1e16
#define mod 1000000007

int N;
ll X[1001],Y[1001];
vector<ll> ds;

ll dx[]={+1,0,-1,0};
ll dy[]={0,+1,0,-1};
string cs="RULD";

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

  cin>>N;
  rep(i,N)cin>>X[i]>>Y[i];
  ll sgn=(X[0]+Y[0]+3000000000)%2;
  rep(i,N){
    if((X[i]+Y[i]+3000000000)%2!=sgn){
      cout<<-1<<endl;
      return 0;
    }
  }
  for(ll i=(1LL<<32LL);i>=1LL;i>>=1LL){
    ds.push_back(i);
  }
  if(sgn==0)ds.push_back(1);

  cout<<ds.size()<<endl;
  rep(i,ds.size())cout<<ds[i]<<" ";
  cout<<endl;
  rep(i,N){
    ll crtX=0,crtY=0;
    string res="";
    rep(j,ds.size()){
      ll bestX=0,bestY=0,bestD=1e18,bestdir=0;
      rep(dir,4){
        ll nxtX=crtX+dx[dir]*ds[j],nxtY=crtY+dy[dir]*ds[j];
        if(bestD>abs(X[i]-nxtX)+abs(Y[i]-nxtY)){
          bestD=abs(X[i]-nxtX)+abs(Y[i]-nxtY);
          bestX=nxtX; bestY=nxtY; bestdir=dir;
        }
      }
      crtX=bestX; crtY=bestY;
      res+=cs[bestdir];
    }
    assert(crtX==X[i]);
    assert(crtY==Y[i]);
    cout<<res<<endl;
  }

  return 0;
}


Measured memory_bytes: 256
# coding: utf-8
# Your code here!
import sys
def input():
    return sys.stdin.readline()
n,m=map(int,input().split())
a=[0]*(m+1)
b=[0]*(m+1)
c=[0]*(n+1)
f1=[]
f2=[]
for i in range(m):
    a[i],b[i]=map(int,input().split())
    if a[i]==1:
        c[b[i]]=1

ans='IMPOSSIBLE'
for i in range(m):
    if b[i]==n:
        if c[a[i]]==1:
            ans='POSSIBLE'
print(ans)


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

using namespace std;

typedef vector<int> Vec;
typedef pair<Vec,int> P;

bool check(Vec &v){
  for(int i = 0 ; i < 32 ; i++){
    if((i+1) % 8 == 0) continue;
    if((i/8+1)*10+i%8+1 != v[i]) return false;
  }
  return true;
}

int bfs(Vec &start,Vec &space){
  queue<P> Q;
  queue<Vec> S;
  Q.push(P(start,0));
  S.push(space);
  set<Vec> visited;
  visited.insert(start);

  while(!Q.empty()){
    P p = Q.front(); Q.pop();
    Vec s = S.front(); S.pop();
    if(check(p.first)) return p.second;
    
    for(int i = 0 ; i < 4 ; i++){
      if(p.first[s[i]-1] % 10 == 7) continue;
      for(int j = 0 ; j < 32 ; j++){
        if(p.first[s[i]-1]+1 == p.first[j]){
          swap(p.first[s[i]],p.first[j]);
          int tmp = s[i]; s[i] = j;
          if(!visited.count(p.first)){
            visited.insert(p.first);
            Q.push(P(p.first,p.second+1));
            S.push(s);
          }
          s[i] = tmp;
          swap(p.first[s[i]],p.first[j]);
        }
      }
    }
  }
  return -1;
}

int main(){
  int Tc;
  cin >> Tc;
  while(Tc--){
    Vec v(32),space;
    for(int i = 0 ; i < 32 ; i++){
      if(i % 8 != 0){
        cin >> v[i];
        if(v[i]%10 == 1){
          v[i] = 0;
          space.push_back(i);
        }
      }else{
        v[i] = (i/8+1)*10+1;
      }
    }
    cout << bfs(v,space) << endl;
  }
  return 0;
}

Measured memory_bytes: 15116
#include "bits/stdc++.h"

using namespace std;

#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl

typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define rep1(i,n) for(ll i=1;i<=(ll)(n);i++)
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define rrep1(i,n) for(ll i=(ll)(n);i>0;i--)
#define REP(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.end()
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a = b; return 1; } return 0; }
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = 1e18;
const ll MOD = 1000000007;
const double pi = 3.14159265358979323846;
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
int dx[4] = { 1,0, -1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
#define mp make_pair


int main() {
  int k;
  cin >> k;
  cout << (k / 2) * (k - k / 2) << endl;
}


Measured memory_bytes: 256
use std::cmp::max;

#[allow(unused_macros)]
macro_rules! scan {
    () => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().to_string()
        }
    };
    (;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().split_whitespace().map(|s| s.to_string()).collect::<Vec<String>>()
        }
    };
    (;;$n:expr) => {
        {
            (0..$n).map(|_| scan!()).collect::<Vec<_>>()
        }
    };
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
    ($t:ty;;$n:expr) => {
        (0..$n).map(|_| scan!($t;;)).collect::<Vec<_>>()
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
                    scan!($t)
        ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
                    scan!($($t),*)
        ).collect::<Vec<_>>()
    };
}

fn main() {
    let (a, b, c, d) = scan!(i64, i64, i64, i64);
    println!("{}", max(a * b, c * d));
}


Measured memory_bytes: 4352
def solution():
    n = int(input())
    s = input()

    ans = s.count('R') * s.count('G') * s.count('B')
    for i in range(n):
        for j in range(i+1, n+1):
            k = (j - i) + j
            if k >= n:
                break
            if s[i] != s[j] and s[j] != s[k] and s[i] != s[k]:              
                ans -= 1
    print(ans)

solution()


Measured memory_bytes: 68068
import java.util.*
import kotlin.math.*

fun str() = readLine()!!
fun int() = str().toInt()
fun long() = str().toLong()

fun read(d: String = " ") = str().split(d)
fun <T> list(d: String = " ", f: String.() -> T) = read(d).map { f(it) }
fun list() = list { toInt() }

fun <T> MutableList<T>.removeLast() = this.removeAt(this.lastIndex)

const val mod = 1000000007L

fun main() {
    abc000X()
}

fun abc000X() {
    val n = int()
    val a = Array(n) {
        val (t, u) = list()
        t + u to t - u
    }

    val t = a.map { it.first }.sorted()
    val u = a.map { it.second }.sorted()

    println(max(t.last() - t.first(), u.last() - u.first()))
}


Measured memory_bytes: 79128
#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<vector>
#include<stdio.h>
#include<cstring>
#include<math.h>
#include<map>
#include<bitset>
#include<iomanip>
#include<queue>
#include<functional>
#include<stack>
#include<tuple>
#include<cassert>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
using ll = long long;
using P = pair<int, int>;
using MATRIX = vector< vector<ll> >;

int main() {
  int N;
  int p[20];
  cin >> N;
  rep(i, N) {
    cin >> p[i];
  }
  int cnt = 0;
  rep(i, N - 2) {
    if((p[i] < p[i+1] && p[i+1] < p[i+2]) || (p[i] > p[i+1] && p[i+1] > p[i+2])) cnt++;
  }
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 3540
"use strict";

function main(input) {
  input = input.split(/\n/).map(v => ~~v);
  const X = input[3];
  const A = input[0];
  const B = input[1];
  const C = input[2];

  let ans = 0;
  for (let i = 0; i <= A; i++) {
    for (let j = 0; j <= B; j++) {
      for (let k = 0; k <= C; k++) {
        if (i * 500 + j * 100 + k * 50 === X) ans++;
      }
    }
  }

  console.log(ans);
}

main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 11468
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
//INSERT ABOVE HERE
signed main(){
  Int n;
  cin>>n;
  vector<Int> a(n);
  for(Int i=0;i<n;i++) cin>>a[i];
  Int q;
  cin>>q;
  for(Int i=0;i<q;i++){
    Int b,m,e;
    cin>>b>>m>>e;
    rotate(a.begin()+b,a.begin()+m,a.begin()+e);
  }
  for(Int j=0;j<n;j++){
    if(j) cout<<" ";
    cout<<a[j];
  }
  cout<<endl;
  return 0;
}



Measured memory_bytes: 3156
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1145141919810893364
#define PI 3.141592653589
typedef pair<int,int> PP;
typedef long long ll;
#define int ll
#define setdouble setprecision
#define REP(i,n) for(int i=0;i<(n);++i)
#define OREP(i,n) for(int i=1;i<=(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define GOODBYE do { cout << "0" << endl; return 0; } while (false)
#define MM <<" "<<
#define Endl endl

signed main(void){
    int A,B;
    cin >> A >> B;
    if(A<=9 && B<=9){
        cout << A*B << endl;
    }else{
        cout << -1 << endl;
    }
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    vector<int> a(n);
    vector<bool> c(n,true);
    for(int i = 0; i < n; i++)
        cin>>a[i];
    int i = 0,count=1;
    while(a[i]!=2){
        if(!c[i]){
            cout<<"-1";
            return 0;
        }
        c[i] = false;
        i = a[i]-1;
        count++;
    }
    cout<<count;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vl = vector<long>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvb = vector<vector<bool>>;
using vvc = vector<vector<char>>;
using vvl = vector<vector<long>>;
using pii = pair<int, int>;
using pil = pair<int, long>;
using pll = pair<long, long>;
#define fix20 cout << fixed << setprecision(20)
#define YES cout << "Yes" << endl
#define NO cout << "No" << endl
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define REP(i,s,t) for(int i=s; i<t; i++)
#define RNG(i,s,t,u) for(int i=s; i<t; i+=u)
#define MOD 1000000007
#define all(vec) vec.begin(), vec.end()


bool check(vb &animal, string s){
  int n = s.size();
  REP(i,1,n-1){
    if(animal.at(i)){
      if(s.at(i) == 'o') animal.at(i+1) = animal.at(i-1);
      else animal.at(i+1) = (!animal.at(i-1));
    }else{
      if(s.at(i) == 'o') animal.at(i+1) = (!animal.at(i-1));
      else animal.at(i+1) = animal.at(i-1);
    }
    //cout << animal.at(i) << " " << s.at(i) << " " << animal.at(i-1) << " " << animal.at(i+1) << endl;
  }
  bool flag;
  if(animal.at(n-1)){
    if(s.at(n-1) == 'o') flag = animal.at(0) == animal.at(n-2);
    else flag = animal.at(0) != animal.at(n-2);
  }else{
    if(s.at(n-1) == 'o') flag = animal.at(0) != animal.at(n-2);
    else flag = animal.at(0) == animal.at(n-2);
  }
  if(!flag) return false;
  if(animal.at(0)){
    if(s.at(0) == 'o') return animal.at(n-1) == animal.at(1);
    else return animal.at(n-1) != animal.at(1);
  }else{
    if(s.at(0) == 'o') return animal.at(n-1) != animal.at(1);
    else return animal.at(n-1) == animal.at(1);
  }
}

int main(){
  int n;
  string s;
  cin >> n >> s;
  rep(i,2){
    rep(j,2){
      vector<bool> animal(n);
      animal.at(0) = i;
      animal.at(1) = j;
      if(check(animal,s)){
        rep(i,n){
          if(animal.at(i)) cout << "S";
          else cout << "W";
        }
        cout << endl;
        return 0;
      }
    }
  }
  cout << -1 << endl;
}


Measured memory_bytes: 512
#include<cstdio>
#include<algorithm>
#include<queue>
#include<cstring>
#include<bitset>
#include<deque>
#include<cstdio>
#include<cstdlib>
#include<stdint.h>
#include<set>
#include<stack>
#include<cmath>
#include<cstring>
#include<vector>
#include<iomanip>
#include<iostream>
#include<ctime>
using namespace std;
long long n,k,i,res;
int main()
{
	cin>>n>>k;
	if (!k) return cout<<n*n<<endl,0;
	for (i=k+1;i<=n;i++)
	{
		if (n%i>=k) res+=n%i-k+1;
		res+=n/i*(i-k);
	}
	cout<<res<<endl;
	return 0; 
}

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

int A, B, C, D, E, F;

int main() {
   cin >> A >> B >> C >> D >> E >> F;

   // 砂糖、水をそれぞれ独立して作る
   set<int> waterSet, sugarSet;

   // 水
   for (int i = 0; i <= 33; i++) {
      for (int j = 0; j <= 33; j++) {
         int w = 100*A*i + 100*B*j;
         if (w <= F) waterSet.insert(w);
      }
   }

   // 砂糖
   for (int i = 0; i < 3010; i++) {
      for (int j = 0; j < 3010; j++) {
         int s = C*i + D*j;
         if (s <= F) sugarSet.insert(s);
      }
   }

   const double nLim = (double)E/(100+E); // 濃度の限界値
   double noudo = -1; // 初期値を-1にしないと一度も更新されなくなってしまう
   int ans1 = 0, ans2 = 0;
   for (int s : sugarSet) {
      for (int w : waterSet) {
         int sum = s + w; // 砂糖水
         double x = (double)s/sum; // 作った砂糖水の濃度
         if (sum <= F && x <= nLim && x > noudo) { // 条件を満たす && 濃度が最大値
            noudo = x;
            ans1 = sum, ans2 = s;
         }
      }
   }
   printf("%d %d\n", ans1, ans2);

   return 0;
}


Measured memory_bytes: 384
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace B
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] line1 = Console.ReadLine().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
            int k = int.Parse(line1[1]);

            string[] line2 = Console.ReadLine().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
            Console.WriteLine(line2.Select(int.Parse).Where(i => i >= k).Count());
        }
    }
}


Measured memory_bytes: 15840