akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace abc163_b
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            int N = int.Parse(input[0]); //夏休みの日にち
            int M = int.Parse(input[1]); //宿題の数
            int[] A = new int[M]; //i番目の宿題をやるにはA日間かかる
            int H = 0; //経過日数

            input = Console.ReadLine().Split();

            for (int i = 0; i < M; i++)
            {
                A[i] = int.Parse(input[i]);
                H = H + A[i];
            }

            if (N - H >= 0)
            {
                Console.WriteLine(N - H);
            }

            if (N - H < 0)
            {
                Console.WriteLine(-1);
            }

            Console.Read();

        }
    }
    
}


Measured memory_bytes: 28288
import math
A,B,H,M=map(int,input().split())


if abs(30*H-5.5*M)%360<=180:
    theta=abs(30*H-5.5*M)%360*math.pi/180
else:
    theta=(360-abs(30*H-5.5*M)%360)*math.pi/180

print(math.sqrt(A**2+B**2-2*A*B*math.cos(theta)))

Measured memory_bytes: 9508
import bisect, copy, heapq, math, sys
from collections import *
from functools import lru_cache
from itertools import accumulate, combinations, permutations, product
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
def celi(a,b):
    return -(-a//b)
sys.setrecursionlimit(5000000)
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

n=int(input())
a=list(map(int,input().split()))

sm=sum(a)
ans=0
for i in range(n):
    ans+=(sm-a[i])*a[i]%mod
    sm-=a[i]
    ans%=mod
print(ans)

Measured memory_bytes: 103876
#include <bits/stdc++.h>
#define int long long
#define rep(i, a, n) for(int i = (int)(a);(i) < (int)(n);++(i))
#define repe(i, a, n) for(int i = (int)(a);(i) <= (int)(n);++(i))
#define repif(i, a, x) for(int i = (int)(a);(x);++(i))
#define repr(i, a, n) for(int i = ((int)(a)-1);(i) >= (int)(n);--(i))
#define reper(i, a, n) for(int i = (int)(a);(i) >= (int)(n);--(i))
#define SZ(x) ((int)(x).size())
#define ALL(x) begin(x), end(x)
#define RNG(x, a, n) begin(x)+(a), begin(x)+(n)
#define ADD(a, b) ((((a)%MOD+MOD)%MOD+((b)%MOD+MOD)%MOD)%MOD)
#define SUB(a, b) ((((a)%MOD+MOD)%MOD-((b)%MOD+MOD)%MOD+MOD)%MOD)
#define MUL(a, b) (((((a)%MOD+MOD)%MOD)*(((b)%MOD+MOD)%MOD))%MOD)
#define CHADD(a, b) (a = ADD(a, b))
#define CHMUL(a, b) (a = MUL(a, b))
#define CEIL(x) ((int)ceil(((double)x)))
#define POW(x, y) ((int)pow(x, y))
#define UNIQUE(x) (x).erase(unique(ALL((x))), (x).end())
#define gcd(x, y) __gcd(x,  y)
#define lcm(x, y) ((x)/gcd(x,y)*(y))
#define isin(x, l, r) ((l) <= (x) and (x) < (r))
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define yes cout << "yes" << endl
#define no cout << "no" << endl
#define fcout cout << fixed << setprecision(10)
#define pb push_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define PI (acos(-1))
#define EPS (1e-10)
#define INF LLONG_MAX
#define MOD 1000000007LL
using namespace std;
using VI = vector<int>;
using PII = pair<int, int>;
using TIII = tuple<int, int, int>;
using VPII = vector<PII>;
using VTIII = vector<TIII>;
using Complex = complex<double>;
template<typename T, template<typename> typename C = less> using PQ = priority_queue<T, vector<T>, C<T>>;
template<typename T> bool chmax(T& a, const T& b){ if(a<b){ a=b; return true; } return false; }
template<typename T> bool chmin(T& a, const T& b){ if(a>b){ a=b; return true; } return false; }


string N;
int K;
int dp[110][2][10];


signed main(){
    cin >> N >> K;

    dp[0][1][0] = 1;
    rep(i, 0, SZ(N)) rep(j, 0, 2) repe(k, 0, K){
        int x = j ? N[i]-'0' : 9;
        repe(r, 0, x) dp[i+1][j and r == x][k+(!!r)] += dp[i][j][k];
    }

    cout << dp[SZ(N)][0][K]+dp[SZ(N)][1][K] << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define lson l, mid
#define rson mid+1, r
#define PII pair<int, int>
#define Size(x) (int)(x.size())
using namespace std;
typedef long long LL;
//const int MOD = 1e9+7;
const auto INF = 0x3f3f3f3f;
const int N = 3e2+5;
int a[N][N], num[N], Next[N];
bool visit[N];

int main() {
    int n, m;
    scanf("%d%d", &n, &m);
    for(int i=1; i<=n; i++) {
        for(int j=1; j<=m; j++) {
            scanf("%d", &a[i][j]);
        }
    }
    for(int i=1; i<=n; i++) {
        num[a[i][1]]++;
        Next[i] = 1;
    }
    int maxx = INF;
    for(int T=1; T<=m; T++) {
        int temp = 0, pos = 0;
        for(int i=1; i<=m; i++) {
            if(temp < num[i]) {
                temp = num[i];
                pos = i;
            }
        }
        maxx = min(maxx, temp);
        visit[pos] = true;
        for(int i=1; i<=n; i++) {
            if(a[i][Next[i]] == pos) {
                num[pos]--;
                for(int j=Next[i]; j<=m; j++) {
                    if(visit[a[i][j]])
                        continue;
                    num[a[i][j]]++;
                    Next[i] = j;
                    break;
                }
            }
        }
    }
    printf("%d\n", maxx);
}


Measured memory_bytes: 640
def get_i() #空白区切の入力を数値(整数)の配列で返す
  return gets.chomp.split(" ").map(&:to_i)
end
def get_f() #空白区切の入力を数値(実数)の配列で返す
  return gets.chomp.split(" ").map(&:to_f)
end
def get() #空白区切の入力を文字列の配列で返す
  return gets.chomp.split(" ")
end
def get_nsp() #入力されたものを一文字ずつに区切った文字列の配列で返す
  return gets.chomp.split("")
end
def yn_judge(bool,y="Yes",n="No") #boolに真偽を投げることで、trueならy、falseならnの値を出力する
  return bool ? y : n 
end
def array(size1,init=nil,size2=1) #size2に二次元配列時の最初の要素数、size1に次の配列の大きさ、initに初期値を投げることでその配列を返す
  if size2==1
    return Array.new(size1){init}
  else
    return Array.new(size2){Array.new(size1){init}}
  end
end

N=gets.to_i
A=get_i
accum_sum=array(N+1,0)
A.each_with_index do|a,i|
  accum_sum[i+1]=accum_sum[i]+a
end
dict={}
accum_sum.each do|s|
    dict[s]=0 if dict[s].nil?
    dict[s]+=1
end
ans=0
dict.each do|key,num|
  ans+=(num-1)*num/2
end
puts ans

Measured memory_bytes: 32652
//
// Created by yamunaku on 2019/08/19.
//

#include <bits/stdc++.h>

using namespace std;

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repl(i, l, r) for(int i = (l); i < (r); i++)
#define per(i, n) for(int i = ((n)-1); i >= 0; i--)
#define perl(i, l, r) for(int i = ((r)-1); i >= (l); i--)
#define all(x) (x).begin(),(x).end()
#define MOD9 998244353
#define MOD1 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000
#define SP <<" "<<
#define CYES cout<<"Yes"<<endl
#define CNO cout<<"No"<<endl
#define CFS cin.tie(0);ios::sync_with_stdio(false)
#define CST(x) cout<<fixed<<setprecision(x)

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int>> mti;
typedef vector<ll> vl;
typedef vector<vector<ll>> mtl;

int main(){
    int n;
    cin >> n;
    double a=0;
    rep(i,n){
        double c;
        cin >> c;
        a+=1/c;
    }
    CST(10);
    cout << 1/a << endl;
    return 0;
}


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

using namespace std;
typedef long long ll;

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

int divide_2(int n)
{
    int res = 0;
    while (n % 2 == 0 && n)
    {
        res++;
        n /= 2;
    }
    return res;
}

int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];

    int cnt = 0;
    rep(i, n) if (a[i] % 2 == 0) cnt += divide_2(a[i]);

    cout << cnt << '\n';
    return (0);
}


Measured memory_bytes: 3656
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <map>
#include <numeric>
#include <queue>
#include <sstream>
#include <string>
#include <string.h>
#include <tuple>
#include <vector>

#define REP(i,x) for(int i{ 0 }; i < (int)(x); i++)
#define REPC(i,x) for(int i{ 0 }; i <= (int)(x); i++)
#define RREP(i,x) for(int i{ (int)(x) - 1 }; i >= 0 ;i--)
#define RREPC(i,x) for(int i{ (int)(x)}; i >= 0; i--)
#define REP1O(i,x) for(int i{ 1 }; i < (int)(x); i++)
#define REP1C(i,x) for(int i{ 1 }; i <= (int)(x); i++)
#define REPIT(i,x) for(auto i{(x).begin()}; i != (x).end(); i++) 

#define PB push_back
#define MP make_pair
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()

using namespace std;

typedef int64_t ll;
typedef double dbl;
typedef vector<bool> Vb;
typedef vector<char> Vc;
typedef vector<double> Vd;
typedef vector<int> Vi;
typedef vector<ll> Vl;
typedef vector<string> Vs;
typedef vector<vector<int>> VVi;
typedef vector<vector<ll>> VVl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;

template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
inline void swap(ll& a, ll& b) { a ^= b; b ^= a; a ^= b; }
inline void swap(int& a, int& b) { a ^= b; b ^= a; a ^= b; }
inline void YES() { cout << "YES" << endl; } inline void Yes() { cout << "Yes" << endl; }
inline void NO() { cout << "NO" << endl; } inline void No() { cout << "No" << endl; }

const int inf = 1 << 30;
const ll linf = 1LL << 60;
const int MOD = 1000000007;

template <class T> inline T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template <class T> void generatePrimes(T n);
template <class T> void factorize(T n);

vector<ll> primes;
int donePrime = 1;
ll ans = 1;


int main()
{
	ll a, b; cin >> a >> b;
	ll g = gcd(a, b);

	if (g == 1)
	{
		cout << 1 << endl;
		return 0;
	}

	factorize(g);

	cout << ans << endl;
}

template <class T> void factorize(T n)
{
	if (n < 2)
		return;

	T rt = (T)ceil(sqrt(n));

	if (donePrime < rt)
		generatePrimes(rt);

	for (T d : primes)
	{
		if (n < d) break;

		if (!(n % d))
		{
			++ans;
			while (!(n % d))
				n /= d;
		}
	}

	if (n != 1)
		++ans;
}


template <class T> void generatePrimes(T n)
{
	if (n <= donePrime)
		return;

	if (primes.empty())
		primes.push_back(2);

	if (primes.back() == 2 && n > 2)
		primes.push_back(3);

	bool isPrime;

	for (T k = primes.back() + 2; k <= n; k += 2)
	{
		if (!(k % 3))
			continue;

		T limit = (T)ceil(sqrt(k));

		isPrime = true;
		for (int i{ 2 }; i < primes.size() && primes[i] <= limit; i++)
		{
			if (!(k % primes[i]))
			{
				isPrime = false;
				break;
			}
		}

		if (isPrime)
			primes.push_back(k);
	}

	donePrime = n;
}

Measured memory_bytes: 1400
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        try (Scanner in = new Scanner(System.in)) {
            int X = in.nextInt();

            int N = (int) 1e6;
            boolean[] isPrime = new boolean[N];
            Arrays.fill(isPrime, true);
            for (int n = 2; n < N; n++) {
                if (!isPrime[n]) {
                    continue;
                }
                for (int i = n + n; i < N; i += n) {
                    if (isPrime[i]) {
                        isPrime[i] = false;
                    }
                }
            }

            for (int x = X; x < N; x++) {
                if (isPrime[x]) {
                    System.out.println(x);
                    return;
                }
            }

            throw new AssertionError();
        }
    }
}

Measured memory_bytes: 28748
#include <algorithm>
#include <cmath>
#include <complex>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
#include <functional>
#include <cstring>
#include <regex>
#include <random>
#include <cassert>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, s, n) for (int i = (s); i < (int)(n); i++)
#define revrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define revrepr(i, s, n) for (int i = (n) - 1; i >= s; i--)
#define debug(x) cerr << #x << ": " << x << "\n"
#define popcnt(x) __builtin_popcount(x)

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

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

template<class T>
istream& operator >>(istream &is, vector<T> &v) {
    for (int i = 0; i < (int)v.size(); i++) cin >> v.at(i);
    return is;
}

template<class T, class U>
ostream& operator <<(ostream &os, pair<T, U> p) {
    cout << '(' << p.first << ", " << p.second << ')';
    return os;
}

template<class T>
void print(const vector<T> &v, const string &delimiter) { rep(i, v.size()) cout << (0 < i ? delimiter : "") << v.at(i); cout << endl; }

template<class T>
void print(const vector<vector<T>> &vv, const string &delimiter) { for (const auto &v: vv) print(v, delimiter); }

int main() {
    ll x;
    cin >> x;
    int a = x / 500;
    x %= 500;
    int b = x / 5;
    cout << a * 1000 + b * 5 << endl;
}

Measured memory_bytes: 256
use proconio::input;
use std::u128;

const INF: u128 = 1_000_000_000_000_000_000;
fn main() {
    input!(n: usize);
    input!(a: [u128; n]);
    let mut ans: u128 = 1;
    for i in 0..n {
        if a[i] == 0 {
            println!("{}", 0);
            return;
        }
    }

    for i in a {
        if ans * i > INF {
            println!("{}", -1);
            return;
        }
        ans *= i;
    }

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


Measured memory_bytes: 5332
#include<iostream>
#include<algorithm>
#include<string>
#include<math.h>
#include<vector>
#include<iomanip>
using namespace std;

int main(void)
{
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    cout << max(min(b,d) - max(a,c),0) << endl;
    return 0;
}

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

using namespace std;

int n,k,c,t[100010];
int p=1,cnt=1,tb;

int main(){
	scanf("%d%d%d",&n,&c,&k);
	for(int i=1;i<=n;i++){
		scanf("%d",&t[i]);
	}
	sort(t+1,t+n+1);
	tb=t[1]+k;
	for(int i=2;i<=n;i++){
		if(t[i]>tb||p==c){
			cnt++;
			tb=t[i]+k;
			p=1;
		}
		else p++;
	}
	printf("%d",cnt);
}

Measured memory_bytes: 768
#include <iostream>
//#include <set>
//#include <map>
//#include <iomanip>
//#include <algorithm>
//#include <numeric>
//#include <queue>
//#include <stack>
//#include <math.h>
#include <vector>
//#include <string>
//#include <list>
//#include <deque>
//#include <unordered_map>
//typedef long long LL;
//typedef long double LD;
using namespace std;
 
//#define MOD 1000000007
//#define MAX 200100
//#define NIL -1

int main() {
    int n;
    cin >> n;
    vector<vector<int>> a(2, vector<int>(n));

    for(int i=0; i<2; i++){
        for(int j=0; j<n; j++){
            cin >> a[i][j];
        }
    }

    int ans=a[0][0];
    for(int i=0; i<n; i++){
        ans+=a[1][i];
    }
    int max_ans = ans;
    for(int i=1; i<n; i++){
        ans=ans+a[0][i]-a[1][i-1];
        if(ans>max_ans){
            max_ans=ans;
        }
    }

    cout << max_ans << endl;

    return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline

N = int(input())

ans = 0
for i in range(1, N + 1):
    ans += (i * (i + 1)) // 2

for _ in range(N - 1):
    u, v = map(int, input().split())
    if u > v: # u の方が小さい状態にする
        u, v = v, u
    ans -= (u * (N - v + 1))

print (ans)

Measured memory_bytes: 9184
#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
#include<cassert>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
//問題文および制約はちゃんと確認しよう！
//サイズは10^5じゃなくて2×10^5とかかもしれないし、重要な制約・条件を見落としているかも
//とりあえずサンプルを読んでから解法を考えよう？
queue<int> q;
int zi[10100];
vector<int> gr[10100];
int c[10100],out[10100];
bool sumi[10100];
int main()
{
	memset(zi,0,sizeof(zi));
	int n,a,b;cin>>n;lint sum=0;
	rep(i,n-1){
		cin>>a>>b;a--;b--;
		zi[a]++;zi[b]++;
		gr[a].pb(b);gr[b].pb(a);
	}
	rep(i,n) cin>>c[i];sort(c,c+n);
	rep(i,n){
		if(zi[i]==1) q.push(i);
	}
	memset(sumi,false,sizeof(sumi));
	rep(i,n){
		int p=q.front();q.pop();
		out[p]=c[i];
		sumi[p]=true;
		//cout<<p<<' '<<c[i]<<endl;
		rep(j,gr[p].size()){
			int v=gr[p][j];
			zi[v]--;
			if(zi[v]==1 && !sumi[v]) q.push(v);
		}
		if(i<n-1) sum+=c[i];
	}
	cout<<sum<<endl;
	rep(i,n){
		cout<<out[i];
		if(i<n-1) cout<<' ';else cout<<endl;
	}
}


Measured memory_bytes: 1024
from bisect import bisect_left
import sys
sys.setrecursionlimit(10**7)
# sys.stdin.readline

# スペース区切りの入力を読み込んで数値リストにして返します。
def get_nums_l():
    return [ int(s) for s in input().split(" ")]

def log(*args):
    print("DEBUG:", *args, file=sys.stderr)

INF = 999999999999999999999999

n = int(input())
A = [-INF] + get_nums_l()

edges = [ [] for _ in range(n+1) ]
for line in map(lambda s: s.strip(), sys.stdin.readlines()):
    u,v = map(int, line.split())
    edges[u].append(v)
    edges[v].append(u)

def dfs(dp, u, p=None):

    # log(u)
    # log(dp)

    # dpの中でA[u]以上の値が入っている最小のindex
    i = bisect_left(dp, A[u])

    old = dp[i]
    dp[i] = A[u]

    # 有効値(INF以外)が入っている最大のindex
    ans[u] = bisect_left(dp, INF) - 1

    for v in edges[u]:
        if v == p:
            continue
        dfs(dp, v, u)

    # 巻き戻し
    dp[i] = old

# ans[i] = ノード1からノードiへの経路中の最長増加部分列長
ans = [0] * (n+1)

# dp[i] = 最長増加部分列長がiの場合の末尾ノード値の最小
# dp[0]は使用しないので負の無限大を入れておく
dp = [INF] * (n+1)
dp[0] = -INF

dfs(dp, 1, None)

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


Measured memory_bytes: 361444
function myout(text){console.log(text);}//standard output
function Main(input) {
	//input = parseInt(input);
	//input = input.trim().split(" ");
	//input = input.trim().split("\n");
	//input = input.trim().split(" ").map((a)=>Number(a));
	//input = input.trim().split("\n").map((a)=>Number(a));
  var S = input;
  var output = 1000;
  for(var i = 0; i <= S.length - 3; i++){
    var tmp = parseInt(S.slice(i,i+3));
    output = Math.min(output,Math.abs(753 - tmp));
  }
  myout(output);
}

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


Measured memory_bytes: 7372
using namespace std;
#include<iostream>
#include<stdio.h>

int main(){
int x;
cin >>x;
int a[x];

for (int j =1;j<=x;j++) cin>>a[j];

for (int i=1;i<=x;i++){
	cout<<"node "<<i<<": key = "<<a[i]<<", ";
	if(i>1) cout<<"parent key = "<<a[i/2]<<", ";
	if(i*2<=x)	cout<<"left key = "<<a[i*2]<<", ";
	if((i*2)+1<=x)	cout<<"right key = "<<a[(i*2)+1]<<", ";
cout<<endl;
}



	return 0;
}


Measured memory_bytes: 3076
#include <stdio.h>

int main() {
	int n, mini, tmp, swap;
	scanf("%d", &n);

	int arr[n];

	for (int i=0; i<n;i++) {
		scanf("%d", &arr[i]);
	}

	swap = 0;
	for (int i=0; i<n; i++) {
		mini = i;
		for (int j = i; j<n;j++) {
			if (arr[j] < arr[mini]) {
				mini = j;
			}
		}

		tmp = arr[i];
		arr[i] = arr[mini];
		arr[mini] = tmp;
		swap += (mini != i);
	}

	printf("%d", arr[0]);
	for (int i=1; i<n; i++) {
		printf(" %d", arr[i]);
	}
	printf("\n%d\n", swap);
}



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

template<long long mod>
class modint{
private:
  long long a;
public:
  constexpr modint(const long long x = 0) noexcept : a(x%mod) {}
  constexpr long long& value() noexcept { return a; }
  constexpr const long long& value() const noexcept { return a; }
  constexpr modint operator+(const modint rhs) const noexcept {
    return modint(*this) += rhs;
  }
  constexpr modint operator-(const modint rhs) const noexcept {
    return modint(*this) -= rhs;
  }
  constexpr modint operator*(const modint rhs) const noexcept {
    return modint(*this) *= rhs;
  }
  constexpr modint operator/(const modint rhs) const noexcept {
    return modint(*this) /= rhs;
  }
  constexpr modint& operator+=(const modint rhs) noexcept {
    a += rhs.a;
    if(a >= mod) a -= mod;
    return *this;
  }
  constexpr modint &operator-=(const modint rhs) noexcept {
    if(a < rhs.a) a += mod;
    a -= rhs.a;
    return *this;
  }
  constexpr modint& operator*=(const modint rhs) noexcept {
    a = a*rhs.a%mod;
    return *this;
  }
  constexpr modint& operator/=(modint rhs) noexcept {
    long long k = mod-2;
    while(k > 0){
      if(k&1){
        *this *= rhs;
      }
      rhs *= rhs;
      k /= 2;
    }
    return *this;
  }
  friend ostream& operator<<(ostream &os, const modint &X){
    return os << X.a;
  }
  friend istream& operator>>(istream &is, modint &X){
    is >> X.a;
    X.a %= mod;
    if(X.a < 0) X.a += mod;
    return is;
  }
};

int main(){
  using mint = modint<(int)1e9+7>;
  int N;
  cin >> N;
  //0=A,1=T,2=G,3=C
  //[0][2] に 3 はつけられない
  vector<vector<vector<vector<mint>>>> dp(N+1,vector<vector<vector<mint>>>(4,vector<vector<mint>>(4,vector<mint>(4,0))));
  dp[0][1][1][1] = 1;
  for(int i = 0; i < N; ++i){
    for(int j = 0; j < 4; ++j){
      for(int k = 0; k < 4; ++k){
        for(int l = 0; l < 4; ++l){
          for(int m = 0; m < 4; ++m){
            if(k == 0 and l == 2 and m == 3)//?AGC
              continue;
            if(j == 0 and l == 2 and m == 3)//A?GC
              continue;
            if(j == 0 and k == 2 and m == 3)//AG?C
              continue;
            if(k == 2 and l == 0 and m == 3)//GAC
              continue;
            if(k == 0 and l == 3 and m == 2)//ACG
              continue;
            dp[i+1][k][l][m] += dp[i][j][k][l];
          }
        }
      }
    }
  }
  mint ans = 0;
  for(int i = 0; i < 4; ++i){
    for(int j = 0; j < 4; ++j){
      for(int k = 0; k < 4; ++k){
        ans += dp[N][i][j][k];
      }
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
using ll =  long long ;
using P = pair<int,int> ;
const int INF = 1e9;
const int MOD = 1000000007;
int n = 100005;

struct edge{

    int from,to;
    long long cost;
    
    edge(long long  cost,int from,int to):cost(cost),from(from),to(to){}

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

vector<edge> EG;

struct Unionfind{
    vector<int> parents;
    int m;
    Unionfind(int n):parents(n,-1){
        m = n;
    }

    int find(int x){
        if(parents.at(x) < 0){
            return x;
        }else{
            parents.at(x) = find(parents.at(x));
            return parents.at(x);
        }
    }

    void unite(int x,int y){
        x = find(x);
        y = find(y);

        if(x==y) return;
        if(parents.at(x) > parents.at(x))swap(x,y);
        parents.at(x) += parents.at(y);
        parents.at(y) = x;
    }  

   int size(int x){
       return -parents.at(find(x));
   }

   bool same(int x,int y){
       return find(x) ==find(y);
   }

   vector<int> members(int x){
       int root = find(x);
       vector<int> A;
       for(int i=0;i<m;i++){
           if(find(i) ==root ){
               A.push_back(i);
           }
       }
      return A;
  }
};

long long  kruskal(){
    long long  res = 0;
    Unionfind uf(n);
    sort(EG.begin(),EG.end());
    for(edge ed:EG){
        if(uf.same(ed.from,ed.to)) continue;
        uf.unite(ed.from,ed.to);
        res += ed.cost;
    }
    return res;
}


int main(){
    cin >> n;
    vector<P> X(n),Y(n);
    rep(i,n){
        cin >> X[i].first >> Y[i].first;
        X[i].second = Y[i].second = i;
    }

    sort(X.begin(),X.end());
    sort(Y.begin(),Y.end());

    rep(i,n-1){
        edge eg1(X[i+1].first - X[i].first,X[i].second,X[i+1].second);
        edge eg2(Y[i+1].first - Y[i].first,Y[i].second,Y[i+1].second);
        EG.push_back(eg1);
        EG.push_back(eg2);
    }

    long long  ans = kruskal();
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 8048
import java.util.*;
    public class Main {
    public static void main(String[] args) {
    		Scanner sc=new Scanner(System.in);
    		String s=sc.next();
    		String m="";
    		String taihi="";
    		for(int i=0;i<s.length();i++){
    			if(s.charAt(i)=='B'){
    				for(int j=0;j<m.length()-1;j++){
    					taihi+=m.charAt(j);
    				}
    				m=taihi;
    				taihi="";
    			}else{
    				m+=s.charAt(i);
    	}
    	}
    		System.out.println(m);
    	}
        }

Measured memory_bytes: 21844
/***************************************************
 * Problem Name : A.cpp
 * Problem Link :
 * OJ           :
 * Verdict      : Trying
 * Date         : 2020-05-10
 * Problem Type :
 * Author Name  : Saikat Sharma
 * University   : CSE, MBSTU
 ***************************************************/
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <climits>
#include <cstring>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <list>
#include <unordered_map>
#include <unordered_set>
#include <cstdlib>
#include <deque>
#include <stack>
#include <bitset>
#include <cassert>
#include <map>
#include <set>
#include <cassert>
#include <iomanip>
#include <random>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef unsigned long long ull;

#define __FastIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define __FileRead freopen ("input.txt", "r", stdin)
#define __FileWrite freopen ("output.txt", "w", stdout)
#define SET(a,v) memset(a,v,sizeof(a))
#define SZ(v) (int)v.size()
#define pii pair<int,int>
#define pil pair <int, ll>
#define pli pair <ll, int>
#define pll pair <ll, ll>
#define debug cout <<"######\n"
#define debug1(x) cout <<"### " << x << " ###\n"
#define debug2(x,y) cout <<"# " << x <<" : "<< y <<" #\n"
#define nl cout << "\n";
#define sp cout << " ";
#define sl(n) scanf("%lld", &n)
#define sf(n) scanf("%lf", &n)
#define si(n) scanf("%d", &n)
#define ss(n) scanf("%s", n)
#define pf(n) scanf("%d", n)
#define pfl(n) scanf("%lld", n)
#define all(v) v.begin(), v.end()
#define rall(v) v.begin(), v.end()
#define srt(v) sort(v.begin(), v.end())
#define r_srt(v) sort(v.rbegin(), v.rend())
#define rev(v) reverse(v.rbegin(), v.rend())
#define Sqr(x) ((x)*(x))
#define Mod(x, m) ((((x) % (m)) + (m)) % (m))
#define max3(a, b, c) max(a, max(b, c))
#define min3(a, b, c) min(a, min(b, c))
#define pb push_back
#define mk make_pair
#define F first
#define S second
#define MAX 100005
#define INF 1000000009
#define MOD 1000000007

template<class T>
using min_heap = priority_queue<T, std::vector<T>, std::greater<T>>;
template<typename T>
using ordered_set  = tree<T, null_type, less<T>, rb_tree_tag,
      tree_order_statistics_node_update>;

template <typename T> string toString ( T Number ) {
    stringstream ss;
    ss << Number;
    return ss.str();
}
template<typename T> int toInt (T str) {
    stringstream ss;
    ss << str;
    int num;
    ss >> num;
    return num;
}
ll lcm ( ll a, ll b ) {
    return ( a / __gcd ( a, b ) ) * b;
}
/************************************ Code Start Here ******************************************************/
int main () {
    //~ __FastIO;
    //~ cout << setprecision (10) << fixed;
    string a, b;
    cin >> a >> b;
    b.pop_back();

    if (a == b) {
        cout << "Yes\n";

    } else {
        cout << "No\n";
    }

    return 0;
}


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

using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using LL = long long;
using VL = vector<LL>;
using VVL = vector<VL>;
using PLL = pair<LL, LL>;
using VS = vector<string>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define MT make_tuple
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

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

#define FF first
#define SS second

#define DUMP(x) cout<<#x<<":"<<(x)<<endl
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}
template<class T>
istream& operator>>(istream& is, vector<T>& xs){
  for(auto& x: xs)
	is >> x;
  return is;
}
template<class S, class T>
ostream& operator<<(ostream& os, const pair<S,T>& p){
  return os << p.FF << " " << p.SS;
}
template<class T>
ostream& operator<<(ostream& os, const vector<T>& xs){
  for(unsigned int i=0;i<xs.size();++i)
	os << (i?" ":"") << xs[i];
  return os;
}
template<class T>
void maxi(T& x, T y){
  if(x < y) x = y;
}
template<class T>
void mini(T& x, T y){
  if(x > y) x = y;
}


const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;

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

  int N;
  cin >> N;

  string prv;
  set<string> m;
  bool ok = true;
  REP(i,N){
	string t;
	cin >> t;
	if(m.count(t)) ok = false;
	if(!prv.empty() && prv.back() != t[0])
	  ok = false;

	prv = t;
	m.insert(t);
  }
  cout << (ok? "Yes": "No") << endl;

  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(){
	
	int a[7],i,ans=0,x,k=0;
	for(i=1;i<=5;i++){
		scanf("%d",&a[i]);
		x=(a[i]+9)/10*10;
		if(x-a[i]>k)k=x-a[i];
		ans+=x;
	}
	printf("%d",ans-k);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>

using namespace std;

int main(void){
    int R, G, B, N, r, g, b, count;

    cin >> R >> G >> B >> N;

    count = 0;
    for(r = 0;R*r <= N;r++){
        for(g = 0;G*g <= N;g++){
            b = (N - R*r - G*g) / B;
            if(R*r + G*g + B*b == N && b > -1){
                count++;
            }
        }
    }

    cout << count << endl;

    return 0;
}

Measured memory_bytes: 256
import scala.collection.mutable
import scala.collection.mutable.ArrayBuffer
object Main extends App {
  import scala.io.StdIn._

  val isChildOf = """^(\w+) is a child of (\w+).$""".r
  val isParentOf = """^(\w+) is the parent of (\w+).$""".r
  val isSiblingOf = """^(\w+) is a sibling of (\w+).$""".r
  val isDescendantOf = """^(\w+) is a descendant of (\w+).$""".r
  val isAncestorOf = """^(\w+) is an ancestor of (\w+).$""".r
  solve
  def solve: Unit = {
    val Array(personSize, querySize) = readLine.trim.split(' ').map(_.toInt)
    if (personSize == 0) return
    val persons = new ArrayBuffer[List[Person]]()
    val map = new mutable.HashMap[String, Person]()
    for (_ ← 0 until personSize){
      readLine.span(_ == ' ') match {
        case (k, name) ⇒
          if (persons.size <= k.length) persons.append(Nil)
          val p = if (k.length == 0) {
            Person()
          }else {
            val p = Person()
            p.ancestor = Some(persons(k.length - 1).head)
            p
          }
          persons(k.length) ::= p
          map.put(name, p)
      }
    }
    for (_ ← 0 until querySize){
      println(readLine.trim match {
        case a isChildOf b ⇒
          if (map(a).isChildOf(map(b))) "True"
          else "False"
        case a isParentOf b ⇒
          if (map(a).isParentOf(map(b))) "True"
          else "False"
        case a isSiblingOf b ⇒
          if (map(a).isSiblingOf(map(b))) "True"
          else "False"
        case a isDescendantOf b ⇒
          if (map(a).isDescendantOf(map(b))) "True"
          else "False"
        case a isAncestorOf b ⇒
          if (map(a).isAncestorOf(map(b))) "True"
          else "False"
        case _ ⇒ ???
      })
    }
    println()
    solve
  }
  object Person{
    def apply(): Person = new Person()
  }
  class Person(var ancestor: Option[Person] = None) {
    def isSiblingOf(that: Person): Boolean = {
      ancestor.flatMap(person ⇒ that.ancestor.map(_ == person)).getOrElse(false)
    }
    def isChildOf(that: Person): Boolean = {
      ancestor.contains(that)
    }
    def isParentOf(that: Person): Boolean = {
      that.ancestor.contains(this)
    }
    def isDescendantOf(that: Person): Boolean = {
      isChildOf(that) || ancestor.exists(_.isDescendantOf(that))
    }
    def isAncestorOf(that: Person): Boolean = {
      that.isDescendantOf(this)
    }
  }
}


Measured memory_bytes: 62812
n = int(input())
s = input()

max_n = 0

for i in range(1,n):
    x = set()
    y = set()
    for j in range(0,i):
        x.add(s[j])
    for j in range(i,n):
        y.add(s[j])

    if len(x&y) > max_n:
        max_n = len(x&y)

print(max_n)



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

int main(){
  int a,b,k,i;
  cin>>a>>b>>k;
  for(i=100;i>0;i--){
    if(a%i==0 && b%i==0){
      k--;
    }
    if(k==0){
      cout<<i;
      return 0;
    }
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
//#define int long long
#define loop(i, a, b) for(int i = a; i < b; i++)
#define rep(i, a) loop(i, 0, a)
#define all(a) (a).begin(),(a).end()
using namespace std;
const int MOD = 1e9 + 7, INF = 1e9;
using vi = vector <int>;
using vvi = vector <vi>;
//g++ -std==c++14 
 
signed main(){
    string s;
    cin >> s;

    rep(i , 2){
        int va = s[0] - '0';
        string ans = "";
        ans += s[0];
        ans += (i ? "+" : "-");
        ans += s[1];
        va = (i ? s[1] - '0' : (s[1] - '0') * -1) + va;
        string ans_memo1 = ans;
        int va_memo1 = va;
        rep(j, 2){
            ans = ans_memo1;
            va = va_memo1;
            ans += (j ? '+' : '-');
            ans += s[2];
            va = (j ? s[2] - '0' : (s[2] - '0') * -1) + va;
            string ans_memo2 = ans;
            int va_memo2 = va;
            rep(k, 2){
                ans = ans_memo2;
                va = va_memo2;
                ans += (k ? "+" : "-");
                ans += s[3];
                va = (k ? s[3] - '0' : (s[3] - '0') * -1) + va;
                if(va == 7){
                    cout << ans << "=7" << endl;
                    return 0;
                }
            }
        }
    }
}

Measured memory_bytes: 256
n = int(input())
t = 0
x = 0
y = 0
f = True
for _ in range(n):
    ti, xi, yi = (int(x) for x in input().split())
    dt = ti - t
    dd = abs(xi - x) + abs(yi - y)
    if dd > dt or (dt-dd)%2 != 0:
        f = False
        break
    else:
        t = ti
        x = xi
        y = yi
print('Yes' if f else 'No')


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;    using vvi = vector<vi>;
using vb = vector<bool>;   using vvb = vector<vb>;
using vl = vector<ll>;     using vvl = vector<vl>;
using vd = vector<double>; using vvd = vector<vd>;

#define REP(i,n) for(ll i = 0; i < (n); ++i)
#define ALL(c) (c).begin(), (c).end()
#define FOR(i,s,e) for (ll i = s; i < (ll)e; i++)
#define TEN(x) ((ll)1e##x)
const ll mod = TEN(9) + 7;

int main() {
#ifdef INPUT_FROM_FILE
	ifstream cin("sample.in");
	ofstream cout("sample.out");
#endif
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(50);
	ll n, l; cin >> n >> l;
	deque<ll> a(n);
	REP(i, n) cin >> a[i];

	vl ans;
	ll index = -1;
	REP(i, n - 1) if (a[i] + a[i + 1] >= l) index = i;

	if (index == -1) {
		cout << "Impossible" << endl;
		return 0;
	}

	cout << "Possible" << endl;
	REP(i, index) cout << i + 1 << endl;
	for (ll i = n - 1; i > index; --i) cout << i << endl;

	return 0;
}

Measured memory_bytes: 1664
#include <iostream>
#include <stdio.h>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <map>
#include <deque>
#include <algorithm>
#include <queue>
#include <stack>
#include <math.h>
#include <cstring>
using namespace std;

#define ll long long

unordered_map<ll, vector<ll>> ww;
ll res = 0;
vector<ll> sum;

void dfs(vector<ll>& ws, int k, ll left_w, ll tot_v) {
  if (k+1 == ws.size()) {
    if (left_w < 0) return;
    int n = (int)min((ll)ww[ws[k]].size(), left_w / ws[k]);
    tot_v += sum[n];
    res = max(res, tot_v);
  } else {
    dfs(ws, k+1, left_w, tot_v);
    for (int i = 0; i < ww[ws[k]].size(); ++i){
      left_w -= ws[k];
      if (left_w < 0) break;
      tot_v += ww[ws[k]][i];
      dfs(ws, k+1, left_w, tot_v);
    }
  }
}

int main() {
  int N;
  ll W;
  cin >> N >> W;
  ll w, v;
  for (int i = 0; i < N; ++i) {
    cin >> w >> v;
    ww[w].push_back(v);
  }
  vector<ll> ws;
  for (auto& p: ww) {
    ws.push_back(p.first);
    sort(begin(p.second), end(p.second), greater<ll>());
  }
  int k = ws.size()-1;
  sum.resize(ww[ws[k]].size()+1, 0);
  for (int i = 1; i <= ww[ws[k]].size(); ++i) {
    sum[i] = sum[i-1] + ww[ws[k]][i-1];
  }
  dfs(ws, 0, W, 0);
  cout << res << endl;
  return 0;
}



Measured memory_bytes: 256
#from math import gcd

from math import factorial as f

from math import ceil,floor,sqrt


import bisect
import re
import heapq


from copy import deepcopy
import itertools

from sys import exit

ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

yes = "Yes"
no = "No"

def main():
    n = ii()
    s = input()
    anslist = [0 for i in range(1005)]
    anslist1 = [0 for i in range(105)]
    anslist2 = [0 for i in range(15)]

    for _ in range(n):
        i = n-1-_
        tmp = int(s[i])

        for j in range(100):
            if anslist1[j]:
                anslist[tmp*100+j] = 1
        for j in range(10):
            if anslist2[j]:
                anslist1[tmp*10+j] = 1
        anslist2[tmp] = 1

    print(sum(anslist))



main()




Measured memory_bytes: 3828
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<string>
#include<algorithm>
#include<iostream>
#include<bitset>
#include<functional>
#include<numeric>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cassert>
#include<cmath>
#include<iomanip>
#include<random>
#include<ctime>
#include<complex>
using namespace std;
typedef long long LL;
typedef double D;
#define all(v) (v).begin(), (v).end()
mt19937 gene(233);
typedef complex<double> Complex;
#define fi first
#define se second
#define ins insert
#define pb push_back
inline char GET_CHAR(){
	const int maxn = 131072;
	static char buf[maxn],*p1=buf,*p2=buf;
	return p1==p2&&(p2=(p1=buf)+fread(buf,1,maxn,stdin),p1==p2)?EOF:*p1++;
}
inline int getInt() {
	int res(0);
	char c = getchar();
	while(c < '0') c = getchar();
	while(c >= '0') {
		res = res * 10 + (c - '0');
		c = getchar();
	}
	return res;
}

inline LL fastpo(LL x, LL n, LL mod) {
	LL res(1);
	while(n) {
		if(n & 1) {
			res = res * (LL)x % mod;
		}
		x = x * (LL) x % mod;
		n /= 2;
	}
	return res;
}
LL gcd(LL a, LL b) { return b ? gcd(b, a % b) : a; }

inline string itoa(int x, int width = 0) {
  string res;
  if(x == 0) res.push_back('0');
  while(x) {
    res.push_back('0' + x % 10);
    x /= 10;
  }
  while((int)res.size() < width) res.push_back('0');
  reverse(res.begin(), res.end());
  return res;
}
const int _B = 131072;
char buf[_B];
int _bl = 0;
inline void flush() {
	fwrite(buf, 1, _bl, stdout);
	_bl = 0;
}
__inline void _putchar(char c) {
	if(_bl == _B) flush();
	buf[_bl++] = c;
}
inline void print(LL x, char c) {
	static char tmp[20];
	int l = 0;
	if(!x) tmp[l++] = '0';
	else {
		while(x) {
			tmp[l++] = x % 10 + '0';
			x /= 10;
		}
	}
	for(int i = l - 1; i >= 0; i--) _putchar(tmp[i]);
	_putchar(c);
}
struct P {
	D x, y;
};
const int N = 1000011;
const int LOG = 20;
const int mod = 1e9 + 7;
const int inf = 1e9 + 7;
int n, m;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const int A = 26;
struct Rec {
	int cnt, go[A];

} trie[N];
int l;
int nw() {
	l++;
	trie[l] = trie[0];
	return l;
}
string s[222222];
int main() {
	int n;
	cin >> n;
	for(int i = 0; i < n; i++) {
		cin >> s[i];
	}
	LL ans =0;
	int rt;
	for(char c = 'a'; c <= 'z'; c++) {
		l = 0;
		rt = nw();
		for(int i = 0; i < n; i++) {
			int pos = find(all(s[i]), c) - s[i].begin();
			if(pos == s[i].size()) {
				
			}else {
				int p = rt;
				for(int j = s[i].size() - 1; j > pos; j--) {
					int x = s[i][j] - 'a';
					if(trie[p].go[x] == 0) {
						trie[p].go[x] = nw();
					}
					p = trie[p].go[x];
				}
				trie[p].cnt++;
			}
		}
		for(int i = l; i >= 1; i--) {
			for(int j = 0; j < A; j++) {
				if(trie[i].go[j]) {
					trie[i].cnt += trie[trie[i].go[j]].cnt;
				}
			}
		}
		for(int i = 0; i < n; i++) {
			if(s[i].front() != c) {
				
			}else {
				int p = rt;
				for(int j = s[i].size() - 1; j > 0; j--) {
					int x = s[i][j] - 'a';
					if(trie[p].go[x] == 0) {
						trie[p].go[x] = nw();
					}
					p = trie[p].go[x];
				}
				ans += trie[p].cnt;
			}
		}
		
	}
	cout << ans - n << endl;
}






Measured memory_bytes: 115636
#include<iostream>
#include<algorithm>
#define ios ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
using namespace std;
typedef long long ll;
int N;
const int maxn=2e6+10;
ll a[maxn],b[maxn];

int main()
{
	ios;
	cin>>N;
	int cnt=0;
	for(int i=1;i<=N;i++)
	{
		ll x,y;
		cin>>x>>y;
		a[cnt]=x+y;
		b[cnt++]=x-y;
	}
	sort(a,a+cnt);
	sort(b,b+cnt);
	ll maxsum=max(a[cnt-1]-a[0],b[cnt-1]-b[0]);
	cout<<maxsum<<"\n";
	return 0;
 } 

Measured memory_bytes: 6784
/* ---------- STL Libraries ---------- */
// IO library
#include <cstdio>

#include <fstream>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>

#include <cmath>
#include <numeric>
#include <random>
#include <cstring>
#include <cassert>

// container library
#include <array>
#include <bitset>
#include <deque>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>
#include <stack>

// type
#include <cstdint>
#include <functional>

/* ---------- Namespace ---------- */
using namespace std;

/* ---------- Type ---------- */
using ll = long long;
#define int ll
template <class T> using MaxHeap = priority_queue<T>;
template <class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;
#define P pair<ll, ll>

/* ---------- Constants  */
const double PI = 3.141592653589793238462643383279;
const ll MOD = 1e9 + 7;
const int INF = 1LL << 55;

/* ---------- Functions */
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }

/* v-v-v-v-v-v-v-v-v Main Part v-v-v-v-v-v-v-v-v */
int dx[] = {-1, 1, 0, 0};
int dy[] = {0, 0, 1, -1};

int table[500][500];
bool emp[500][500];
int N;

void f(int y, int x) {
    for (int i= 0; i < 4; i++) {
        int yy = y + dy[i];
        int xx = x + dx[i];
        if (yy < 0 || xx < 0 || yy >= N || xx >= N) continue;
        int val = table[y][x] + (emp[y][x] ? 0 : 1);
        if (table[yy][xx] > val) {
            table[yy][xx] = val;
            f(yy, xx);
        }
    }
}

signed main() {
    cin.sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    cin >> N;
    vector<int> A(N*N);
    for (int i = 0; i < N*N; i++) cin >> A[i];
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            table[i][j] = min({i, j, N-1-i, N-1-j});
        }
    }

    int ret = 0;

    for (int i = 0; i < N*N; i++) {
        int y = (A[i]-1) / N;
        int x = (A[i]-1) % N;
        ret += table[y][x];
        emp[y][x] = true;
        f(y, x);
    }

    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 26620
package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
    
    buf := make([]byte, 1000)
    sc.Buffer(buf, 1400000000)

    // input
    N := inputLineAsNumArray(1)[0]
    nums := inputLineAsNumArray(N)

    //median
    nums_sorted := make([]int, N)
    copy(nums_sorted, nums)
    sort.Ints(nums_sorted)

    medL := nums_sorted[N/2-1]
    medR := nums_sorted[N/2]
    
    for i := 0; i < N; i++ {
        if nums[i] <= medL {
            fmt.Println(medR)
        } else {
            fmt.Println(medL)
        }
    }
}

func inputLineAsNumArray(length int) []int {

    line := strings.Split(readLine(), " ")
    var nums []int
    for i := 0; i < length; i++ {
        num, _ := strconv.Atoi(line[i])
        nums = append(nums, num)
    }
    return nums
}


func readLine() string {

	sc.Scan()
	return sc.Text()
}

Measured memory_bytes: 18048
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main()
{
    int k, s;
    int x, y, z;
    int c = 0;
    scanf("%d %d", &k, &s);
    for (x = 0; x <= k; ++x)
        for (y = 0; y <= k; ++y)
            if (s - x - y >= 0 && s - x - y <= k)
                c++;
    printf("%d\n", c);
}

Measured memory_bytes: 128
using System;
using System.Linq;
using System.Collections.Generic;

namespace AtCoder.Contests.ABC159
{
    /// <summary>
    /// 
    /// </summary>
    static class C
    {
        static void Main(string[] args)
        {
            var n = NextInt();

            Console.WriteLine(Math.Pow((double)n, 3) / 27);
        }

        #region Console
        static int _index = 0;
        static string[] _buffer;

        static string Next()
        {
            if (_buffer == null || _index >= _buffer.Length)
            {
                _buffer = Console.ReadLine().Split();
                _index = 0;
            }

            return _buffer[_index++];
        }
        static int NextInt()
        {
            return int.Parse(Next());
        }
        static long NextLong()
        {
            return long.Parse(Next());
        }
        static int ReadInt()
        {
            return int.Parse(Console.ReadLine());
        }
        static long ReadLong()
        {
            return long.Parse(Console.ReadLine());
        }
        static int[] ReadIntArray()
        {
            return Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        }
        static int[] ReadIntArray(int n)
        {
            var a = new int[n];
            for (int i = 0; i < n; i++)
            {
                a[i] = ReadInt();
            }
            return a;
        }
        static long[] ReadLongArray()
        {
            return Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
        }
        static long[] ReadLongArray(int n)
        {
            var a = new long[n];
            for (int i = 0; i < n; i++)
            {
                a[i] = ReadLong();
            }
            return a;
        }
        static List<T> ReadObjects<T>(int n, Func<int[], T> creator)
        {
            var l = new List<T>(n);

            for (int i = 0; i < n; i++)
            {
                var a = ReadIntArray();
                l.Add(creator(a));
            }

            return l;
        }

        static int[,] ReadMatrix(int n, int m)
        {
            var r = new int[n, m];
            for (int i = 0; i < n; i++)
            {
                var a = ReadIntArray();
                for (int j = 0; j < m; j++)
                {
                    r[i, j] = a[j];
                }
            }
            return r;
        }
        #endregion
    }
}


Measured memory_bytes: 11092
#include <iostream>

int main()
{
  std::cin.tie(nullptr);
  std::ios::sync_with_stdio(false);
  
  int A;
  std::cin>>A;
  
  int result=A+A*A+A*A*A;
  
  std::cout<<result<<std::endl;
  
  return 0;
}

Measured memory_bytes: 3604
from collections import Counter

n = int(input())
a = list(map(int, input().split()))
q = int(input())
bc = []
for i in range(q):
    bc.append(map(int, input().split()))

sum = sum(a)

a = Counter(a)
a_keys = list(a.keys())
a_values = list(a.values())

for b, c in bc:
    add = a[b] * c
    red = a[b] * b
    a[c] += a[b]
    a[b] = 0
    sum = sum+add-red
    print(sum)


Measured memory_bytes: 119308