akhauriyash/Code-Regression huggingface dataset:
import kotlin.math.ceil

fun next() = readLine()!!
fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun nextList() = next().split(" ")
fun nextIntList() = next().split(" ").map{ it.toInt() }
fun nextLongList() = next().split(" ").map{ it.toLong() }
fun nextDoubleList() = next().split(" ").map{ it.toDouble() }
fun nextListNull() = next().split("").filter { it != "" }.map{ it.toInt() }

/* fun main(args: Array<String>){
  val a = nextInt()
  println("$a")
} */

        // template
        /*
        A 500
        B 100
        C 50
        X 合計
         */

        // input
        /*
        30
        40
        50
        6000
         */

        // output
        /*
        213
         */
        fun main(args: Array<String>){
            val output = 0
            val n = nextInt()
            var ac = 0
            var wa = 0
            var tle = 0
            var re = 0

            for (i in 1..n) {
                val si = next()
                when (si) {
                    "AC"  -> ac++
                    "WA"  -> wa++
                    "TLE" -> tle++
                    "RE"  -> re++
                }
            }

            println("AC x $ac")
            println("WA x $wa")
            println("TLE x $tle")
            println("RE x $re")
        }

Measured memory_bytes: 58128
import java.io.{BufferedReader, InputStream, InputStreamReader, PrintWriter}
import java.util.StringTokenizer

import scala.collection.mutable
import scala.util.Sorting
import math.{abs, max, min}
import scala.collection.mutable.{ArrayBuffer, ListBuffer}
import scala.reflect.ClassTag

object Main {
  val MOD = 1000000007
  val out = new PrintWriter(System.out)
  def solve(): Unit = {
    val sc = new InputReader(System.in)
    val N = sc.nextInt()
    val A = map(N)(_ => sc.nextInt())
    val ans = (A.grpBy(identity) mapValues (_.length) map { case (num, cnt) =>
      if (cnt >= num) cnt - num
      else cnt
    }).sum

    out.println(ans)
  }


  def main(args: Array[String]): Unit = {
    solve()
    out.flush()
  }


  class InputReader(val stream: InputStream) {
    private val reader = new BufferedReader(new InputStreamReader(stream), 32768)
    private var tokenizer: StringTokenizer = null

    def next: String = {
      while (tokenizer == null || !tokenizer.hasMoreTokens)
        tokenizer = new StringTokenizer(reader.readLine)
      tokenizer.nextToken
    }

    def nextInt(): Int = next.toInt
    def nextLong(): Long = next.toLong
    def nextChar(): Char = next.charAt(0)
  }

  private def rep(n: Int)(f: Int => Unit): Unit = {
    var i = 0
    while(i < n) {
      f(i)
      i += 1
    }
  }

  private def map[@specialized A: ClassTag](n: Int)(f: Int => A): Array[A] = {
    val res = Array.ofDim[A](n)
    var i = 0
    while(i < n) {
      res(i) = f(i)
      i += 1
    }
    res
  }

  private implicit class ArrayOpts[A](val as: Array[A]) extends AnyVal {
    def maxByOpt[B: Ordering](f: A => B): Option[A] = {
      if (as.nonEmpty) Some(as.maxBy(f)) else None
    }

    def grpBy[K](f: A => K): mutable.Map[K, ArrayBuffer[A]] = {
      val map = mutable.Map.empty[K, ArrayBuffer[A]]
      as.rep { a =>
        val k = f(a)
        map.getOrElseUpdate(k, ArrayBuffer()) += a
      }
      map
    }

    def rep[@specialized B](f: A => B): Unit = {
      var i = 0
      val N = as.length
      while(i < N) {
        f(as(i))
        i += 1
      }
    }
  }
}


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


ll check(int n,vector<ll> &a, ll x){
    ll total=0;
    for(int i=0; i<n; i++){
        if(a.at(i)<0){
            int l=-1;
            int r=n;
            while(l+1<r){
                int mid=(l+r)/2;
                if(a.at(i)*a.at(mid)<x) r=mid;
                else l=mid;
            }
            total+=n-r;
        }
        else{
            int l=-1;
            int r=n;
            while(l+1<r){
                int mid = (l+r)/2;
                if(a.at(i)*a.at(mid)<x) l=mid;
                else r=mid;
            }
            total+=l+1;
        }
        if(a.at(i)*a.at(i) < x) total--;
    }
    return total/2;
}

int main(){
    ll n,k;
    cin >> n >> k;
    ll INF= ll(1e18)+ 1;
    vector<ll> a(n);
    for(int i=0; i<n; i++){
        cin >> a.at(i);
    }
    sort(a.begin(), a.end());
    ll l = -INF;
    ll r = INF;
    while(l+1<r){
        ll mid=(l+r)/2;
        if(check(n, a, mid) <k) l=mid;
        else r=mid;
    }
    cout << l << endl;
}


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

using namespace std;

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

    int n, m, t, a;

    cin >> n >> m >> t;
    vector<bool> used(t + m + 1, false);
    for (int i = 0; i < n; ++i) {
        cin >> a;
        for (int j = max(a - m, 0); j < min(a + m, t); ++j)
            used[j] = true;
    }

    int cnt = 0;
    for (int i = 0; i < t; ++i)
        if (!used[i]) ++cnt;

    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 3160
package main
import (
  "fmt"
)

func main() {
  var A int = 0
  var B int = 0
  fmt.Scanf("%d %d", &A, &B)
  
  if( (A+B) % 2 == 0 ) {
    fmt.Println( (A+B)/2 )
  } else {
    fmt.Println("IMPOSSIBLE")
  }
}


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

int main(void) {
	int N, M;
	string s[100], t[100];
	map<string, int> m;
	scanf("%d", &N);
	for (int i = 0; i < N; i++) {
		cin >> s[i];
		m[s[i]]++;
	}
	scanf("%d", &M);
	for (int i = 0; i < M; i++) {
		cin >> t[i];
		m[t[i]]--;
	}
	int ans = 0;
	for (auto itr = m.begin(); itr != m.end(); itr++) {
		ans = max(ans, itr->second);
	}
	printf("%d\n", ans);


	return 0;
}


Measured memory_bytes: 3800
#include <bits/stdc++.h>
using namespace std;
 
// 型名の省略
typedef unsigned int uint;
typedef long long lint;
typedef unsigned long long ulint;
 
const int MOD = 1000000007;
const lint INF = 1LL << 60;
const double PI=acos(-1.0);
 
// cinとcoutの高速化
#define endl "\n"
struct cinacc{cinacc(){cin.tie(0);ios::sync_with_stdio(false);}}cinaccc;
struct coutacc{coutacc(){cout.setf(ios::fixed);cout.precision(12);}}coutaccc;
 
// 繰り返し
#define rep(i,n) for(lint i=0;i<(lint)(n);i++)
#define reps(i,n) for(lint i=0;i<=(lint)(n);i++)
#define rrep(i,n) for(lint i=(lint)(n)-1;i>0;i--)
#define rreps(i,n) for(lint i=(lint)(n)-1;i>=0;i--)

#define pb push_back

#define p pair<int, int>
#define plint pair<lint, lint>

#define ALL(s) (s.begin(), s.end())
#define SZ(s) (s.size())

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(b<a){a=b;return true;}return false;}

// Union-Find-Tree
class UnionFind {
    vector<int> par;
    UnionFind(int n):par(n){rep(i,n)par[i]=i;}
    int root(int x){if(par[x]==x)return x;return par[x]=root(par[x]);}
    void unite(int x,int y){int rx=root(x);int ry=root(y);if(rx==ry)return;par[rx]=ry;}
    bool same(int x,int y){return root(x)==root(y);}
};

// Final Weapon!
// #define int lint

#define MAX_N 100000
lint dp[MAX_N];

int main(void) {
    int n;
    cin >> n;
    vector<int> h(n);
    rep(i, n) cin >> h[i];
    rep(i, n) dp[i] = INF;
    dp[0] = 0;
    for(int i = 0; i < n; i++) {
        chmin(dp[i+1], dp[i] + abs(h[i+1] - h[i]));
        chmin(dp[i+2], dp[i] + abs(h[i+2] - h[i]));
    }
    cout << dp[n-1];
    return 0;
}


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

using namespace std;

int main()
{
    string s;
    cin>>s;
    
    if(s[0]=='7' or s[1]=='7' or s[2]=='7')
        cout<<"Yes\n";
    else
        cout<<"No\n";
        
    return 0;
}

Measured memory_bytes: 3128
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define int long long int

template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}

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

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
constexpr ll INF = 1001001001001001LL;
constexpr ll MOD = 1000000007LL;

int N, M;
int rb[100010], lb[200010], ub[200010];

signed main() {
    cin >> N >> M;
    memset(rb, -1, sizeof(rb));
    iota(lb, lb+N, 0);
    iota(ub, ub+N, 1);
    rep(i,0,M) {
        int x, y; cin >> x >> y;
        rb[x] = y-1;
    }

    rep(i,0,100000) {
        if(rb[i] == -1) continue;
        int v = rb[i];
        int nl = min(lb[v], lb[v+1]);
        int nr = max(ub[v], ub[v+1]);

        lb[v] = lb[v+1] = nl;
        ub[v] = ub[v+1] = nr;
    }

    rep(i,0,N) {
        if(i == 0) printf("%lld", ub[i] - lb[i]);
        else printf(" %lld", ub[i] - lb[i]);
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 7136
import fractions as math
from functools import reduce
def gcd_list(numbers):
    return reduce(math.gcd, numbers)
N,K = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
x = gcd_list(A)
if(K%x==0 and max(A)>=K):
    print('POSSIBLE')
else:
    print('IMPOSSIBLE')


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

#define int long long

#define ii pair<int,int>
#define fi first
#define sc second
#define lwb lower_bound
#define upb upper_bound
#define all(x) (x).begin(),(x).end()

signed main() {
#ifdef _DEBUG
  //freopen("in", "r", stdin);
#endif
  ios::sync_with_stdio(0); cin.tie(0);
  string s;
  cin >> s;
  for (auto i : s) {
    if (i == '7') {
      cout << "Yes" << '\n';
      return 0;
    }
  }
  cout << "No" << '\n';
}


Measured memory_bytes: 3568
N,M,C = map(int,input().split())
b_list = [int(i) for i in input().split()]
right_answer = 0
for i in range(N):
  a_list = [int(j) for j in input().split()]
  sum = 0
  for k in range(M):
    sum =sum + a_list[k] * b_list[k]
  if sum+C > 0:
    right_answer +=1
print(right_answer)


Measured memory_bytes: 3060
import java.util.Scanner;

class Main{
  public static void main(String args[]){

    Scanner scan = new Scanner(System.in);

    int W = scan.nextInt();
    int H = scan.nextInt();
    int x = scan.nextInt();
    int y = scan.nextInt();
    int r = scan.nextInt();

    if(0 > (x-r) || 0 > (y-r) || (x+r) > W || (y+r) > H){
      System.out.println("No");
    }else{
      System.out.println("Yes");
    }
  }
}

Measured memory_bytes: 26304
x = gets.to_i

ans = case x
      when 400 .. 599
        8
      when 600 .. 799
        7
      when 800 .. 999
        6
      when 1000 .. 1199
        5
      when 1200 .. 1399
        4
      when 1400 .. 1599
        3
      when 1600 .. 1799
        2
      when 1800 .. 1999
        1
      end

puts ans


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


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


Measured memory_bytes: 3120
#include<iostream>
#define int long long
using namespace std;
const int ovo=2001,mo=1e9+7;
int n,m,f[2*ovo+5][2*ovo+5],ans,fac[4*ovo+5],inv[4*ovo+5];
struct asuka{int x,y;}po[200001];
inline int qpow(int a,int b)
{
    int s=1;
    while(b){if(b&1)s=s*a%mo;a=a*a%mo;b>>=1;}
    return s%mo;
}
int cal(int n,int m)
{
    return fac[n]*inv[n-m]%mo*inv[m]%mo;
}
void prep()
{
    fac[0]=1;
    for(int i=1;i<=4002*2;i++)fac[i]=fac[i-1]*i%mo;
    for(int i=0;i<=4002*2;i++)inv[i]=qpow(fac[i],mo-2);
}
signed main()
{
	cin>>n;
    prep();
    for(int i=1;i<=n;i++)
    {
        scanf("%lld%lld",&po[i].x,&po[i].y);
        f[-po[i].x+ovo][-po[i].y+ovo]++;
    }
    for(int i=1;i<=4002;i++)
    for(int j=1;j<=4002;j++)
    {
        f[i][j]=(f[i][j]+f[i-1][j]+f[i][j-1])%mo;
    }
  //  cout<<"fine";
    for(int i=1;i<=n;i++)
    {
        ans+=f[po[i].x+ovo][po[i].y+ovo];
        ans-=cal(po[i].x*2+po[i].y*2,po[i].x*2);
        ans=(ans+mo)%mo;
    }
    ans*=inv[2];ans%=mo;
    cout<<ans;
	
}

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

int main() {
	int n,x,ans=0,t=0;
	cin>>n>>x;
	int a[n];
	for(int i=0;i<n;i++)
	cin>>a[i];
	for(int i=0;i<n;i++)
	{
		int min=i;
		for(int j=i+1;j<n;j++)
		{
			if(a[j]<a[min])
			min=j;
		}
		int temp=a[i];
		a[i]=a[min];
		a[min]=temp;
	}
	for(int i=0;i<n;i++)
	{
		t=t+a[i];
		if(t<=x)
		ans++;
		else
		break;
	}
	t=x-t;
	ans=ans+t/a[0];
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
open Printf
open Scanf

let () =
  let n = scanf "%d " (fun x -> x) in
  let tb = Hashtbl.create n in
  let rec read x =
    if x = 0 then ()
    else let d = scanf "%d " (fun i -> i) in
         if Hashtbl.mem tb d then Hashtbl.replace tb d (1 + Hashtbl.find tb d)
         else Hashtbl.add tb d 1;
         read (x - 1) in
  read n;
  let m = scanf "%d " (fun x -> x) in
  let rec check x =
    if x = 0 then "YES"
    else let t = scanf "%d " (fun i -> i) in
         if Hashtbl.mem tb t then
           let v = Hashtbl.find tb t in
           if v = 0 then "NO"
           else begin Hashtbl.replace tb t (v - 1); check (x - 1) end
         else "NO" in
  check m |> printf "%s\n"


Measured memory_bytes: 19072
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {

	Scanner sca = new Scanner(System.in);
	// 入力
	int n = sca.nextInt();
	String s = sca.next();
	int ans = 0;
	for(int i = 0; i < s.length()-2; i++) {
		if(s.charAt(i) == 'A') {
			if(s.charAt(i+1) == 'B' && s.charAt(i+2) == 'C') {
				ans++;
			}
		}
	}

	System.out.println(ans);

	// 後始末
	sca.close();
	}
}

Measured memory_bytes: 22996
use std::io;
use std::str::FromStr;

fn input_int_tuple() -> (i32, i32) {
    let mut line: String = String::new();
    io::stdin().read_line(&mut line);
    let vec: Vec<i32> = line.split_whitespace().map(|s| s.parse().unwrap()).collect();
    (vec[0], vec[1])
}

fn main() {
    let (k, x) = input_int_tuple();
    let mut start: i32;
    let mut end: i32;
    if x - k + 1 < -1000000 {
        start = -1000000
    } else {
        start = x - k + 1;
    }
    if start + k * 2 - 1 > 1000000 {
        end = 1000000;
    } else {
        end = start + k * 2 - 1;
    }
    for i in start..(end) {
        print!("{} ", i);
    }
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")
//#pragma GCC target ("avx,tune=native")
//Use above if bruteforcing with lots of small operations. Or just use it anytime, there's no downside.
//AVX is better slightly
using namespace std;
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef long double ld;

ll inv(ll a, ll b){
    return (a > 1 ? b - inv(b%a, a)*b/a : 1);
}

#define rc(s) return cout << s, 0
#define fi first
#define se second
#define L (nod << 1)
#define R (L | 1)
#define smax(X, Y) ((X) > (Y) ? (X) : (Y))
#define smin(X, Y) ((X) < (Y) ? (X) : (Y))
#define N 200100

const ld e = 2.71828182845904523536028747;
const ld PI = 3.14159265359;
const ll inf = (1LL<<62);
const int iinf = (1<<30);
//CLOCKS_PER_SEC

int n, a[N], fv[N];
ll ans;
pair <ll, ll> b[N], dp[N];

int main(){
    //mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    //ios_base::sync_with_stdio(0); cin.tie(0);
    //ifstream cin ("test.in");
    cin >> n;
    for (int i=1; i<=n; i++) cin >> a[i], fv[a[i]]++;
    for (int i=1; i<=n; i++){
        //dp[i] = {0, 0};
        if (fv[i] < 2) continue;
        ans += 1LL * fv[i] * (fv[i] - 1) / 2;
        //b[i].fi = 1LL * fv[i] * (fv[i] - 1) / 2;
        //ans += b[i].fi;
        //if (fv[i] < 3) continue;
        //b[i].se = 1LL * fv[i] * (fv[i] - 2) * (fv[i] - 3) / 2;
        //ans += b[i].se;
    }
    for (int i=1; i<=n; i++){
        cout << ans - fv[a[i]] + 1 << '\n';
    }
    return 0;
}


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


void solve(std::string S){
    int ans = 0;
    int result = 0;
    for (int i = 0; i < 3; i++) {
        if (S[i] == 'R') {
            ans++;
        } else {
            ans = 0;
        }
        result = max(ans, result);
    }
    cout << result << endl;
}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    std::string S;
    std::cin >> S;
    solve(S);
    return 0;
}


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

int main(){
  char c[3][3];
  string S;
  for(int i=0;i<3;i++){
    cin>>S;
    for(int j=0;j<3;j++){
      c[i][j]=S[j];
    }
  }
  cout<<c[0][0]<<c[1][1]<<c[2][2]<<endl;
  return 0;
}

Measured memory_bytes: 256
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate, product # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
import math
import bisect
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入g
#
# インデックス系
# int min_y = max(0, i - 2), max_y = min(h - 1, i + 2);
# int min_x = max(0, j - 2), max_x = min(w - 1, j + 2);
#
#
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
#mod = 998244353
from sys import stdin
readline = stdin.readline
def readInts():
  return list(map(int,readline().split()))
def readTuples():
    return tuple(map(int,readline().split()))
def I():
  return int(readline())
n,a,b = readInts()
ab = abs(b-a)
if ab%2 == 0:
    print(ab//2)
else:
    print(min(a-1, n-b) + 1 + (b-a-1)//2)


Measured memory_bytes: 10344
n,a,b,c = list(map(int, input().split()))
q = []
for i in range(n):
    s = input()
    if(s == 'AB'):
        q.append(0)
    elif(s == 'BC'):
        q.append(1)
    else:
        q.append(2)

act = []
for i in range(n):
    if(q[i]==0): #case AB
        if(a==0 and b==0):
            print("No")
            exit()
        elif(a==1 and b==1):
            if(i!=n-1 and q[i+1]==1):
                act.append('B')
                b+=1
                a-=1
            else:
                act.append('A')
                b-=1
                a+=1
        elif(a>=b):
            act.append('B')
            b+=1
            a-=1
        else:
            act.append('A')
            b-=1
            a+=1
    elif(q[i]==1):
        if(b==0 and c==0):
            print("No")
            exit()
        elif(b==1 and c==1):
            if(i!=n-1 and q[i+1]==2):
                act.append('C')
                c+=1
                b-=1
            else:
                act.append('B')
                c-=1
                b+=1
        elif(b>=c):
            act.append('C')
            c+=1
            b-=1
        else:
            act.append('B')
            c-=1
            b+=1
    else:
        if(c==0 and a==0):
            print("No")
            exit()
        elif(c==1 and a==1):
            if(i!=n-1 and q[i+1]==0):
                act.append('A')
                a+=1
                c-=1
            else:
                act.append('C')
                a-=1
                c+=1
        elif(c>=a):
            act.append('A')
            a+=1
            c-=1
        else:
            act.append('C')
            a-=1
            c+=1

print("Yes")
for i in range(n):
    print(act[i])



Measured memory_bytes: 82708
#include<iostream>
#include<stack>
#include<algorithm>
#define fi first
#define se second
using namespace std;
const int M=1400;
int h,w;
int T[M][M+1];
int get(int size)
{
	stack<pair<int,int>>s;
	int maxv=0;
	pair<int,int>r,p;
	int t;
	
	for(int i=0;i<=w;i++)
	{
		r.fi=T[size][i];
		r.se=i;
		if(s.empty())s.push(r);
		else
		{
			if(s.top().fi<r.fi)s.push(r);
			else if(s.top().fi>r.fi)
			{
				t=i;
				while(!s.empty()&&s.top().fi>r.fi)
				{
					p=s.top();s.pop();
					maxv=max(maxv,p.fi*(i-p.se));
					t=p.se;
				}
				r.se=t;
				s.push(r);
			}
		}
	}
	return maxv;
}

int main()
{
	cin>>h>>w;
	int c[M][M];
	for(int i=0;i<h;i++)
	{
		for(int j=0;j<w;j++)
		{
			cin>>c[i][j];
		}
	}
	for(int i=0;i<h;i++)
	{
		for(int j=0;j<w;j++)
		{
			T[i][j]=(c[i][j]?0:i>0?T[i-1][j]+1:1);
		}
		T[i][w]=0;
	}
	int maxv=0;
	for(int i=0;i<h;i++)
	{
		maxv=max(maxv,get(i));
	}
	cout<<maxv<<endl;
	return 0;
}

Measured memory_bytes: 18328
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
typedef long long LL;
int N;
LL D;
LL a[500001];
int main(){
	cin>>N>>D;
	LL now=0;
	//LL aa=0;
	REP(i,N){
		cin>>a[i];
		a[i]-=1;
		a[i]%=(D+1);
		//aa=(a[i]/(D+1));
		now=now^a[i];
	}
	if(now==0){
		cout<<"Second"<<endl;
	}else{
		cout<<"First"<<endl;
	}
}


Measured memory_bytes: 5036
#include<stdio.h>
#include<iostream>
#include<string>
#include<vector>
using namespace std;

int main()
{
	string s;

	string p;

	cin >> s >> p;

	s += s;

	if (s.find(p) != string::npos)cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}

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


void solve(){
    string s;
    cin>>s;
    if(s[0] == 'R' && s[1] == 'R' && s[2] == 'R') cout<<3<<endl;
    else if(s[0] == 'R' && s[1] == 'R' || s[1] == 'R' && s[2] == 'R') cout<<2<<endl;
    else if(s[0] == 'R' || s[1] == 'R' || s[2] == 'R') cout<<1<<endl;
    else cout<<0;


}


int main(){
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    int q;
    q=1;
    // cin>>q;
    while(q--) solve();


    return 0;
}

Measured memory_bytes: 3640
object Main extends App {
    val scanner = new java.util.Scanner(System.in)
    val n = scanner.next().toInt
    val k = scanner.next().toInt
    println(sim(1, k, n).min)
    
    def sim(n: Int, k: Int, cnt: Int): List[Int] = {
        if (cnt == 0) { 
            List(n)
        } else {
            sim(n+k, k, cnt-1) ::: sim(n*2, k, cnt-1)
        }
    }
}

Measured memory_bytes: 25672
X,Y,Z,K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = sorted(list(map(int, input().split())), reverse=True)

AB = []
for i in range(X):
	for j in range(Y):
		AB.append(A[i]+B[j])

AB.sort(reverse = True)
AB = AB[:min(K,len(AB))]

ABC = []
for i in range(min(K,len(AB))):
	for j in range(Z):
		ABC.append(AB[i]+C[j])

ABC.sort(reverse = True)

for i in range(K):
	print(ABC[i])

Measured memory_bytes: 151216
from bisect import bisect_left, bisect_right
N = int(input())
upper = sorted(list(map(int, input().split())))
middle = list(map(int, input().split()))
lower = sorted(list(map(int, input().split())))

ans = 0
for m in middle:
    idx_u = bisect_left(upper, m)
    idx_l = N-bisect_right(lower, m)
    ans += idx_u*idx_l
print(ans)

Measured memory_bytes: 23328
N = int(input())

W = [input() for i in range(N)]

flag=1
for i in range(N-1):
  #print(W[i],W[i][-1],W[i+1],W[i+1][0])
  if W[i][-1]!=W[i+1][0]:
    flag=0
    break
  if W.count(W[i])>=2:
    flag=0
    break
    
print('Yes' if flag==1 else 'No')
  




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

int main(){
    string S;
    long long K;
    cin >> S >> K;
    int N = S.length();
    if(N == 1){
        cout << K / 2 << endl;
        return 0;
    }
    string str = S;
    sort(str.begin(), str.end());
    if(str[0] == str[N - 1]){
        long long ans = N * K / 2;
        cout << ans << endl;
        return 0;
    }
    
    long long ans = 0;
    if(S[0] == S[N - 1]){
        int f = 0, b = 0;
        for(int i = 0; i < N; i++){
            if(S[0] == S[i])f++;
            else break;
        }
        for(int i = N - 1; i >= 0; i--){
            if(S[N - 1] == S[i])b++;
            else break;
        }
        
        if(f % 2 == 1 && b % 2 == 1){
            ans += (K - 1);
        }
    }
        
    
    long long cnt = 0;
    long long ch = 1;
    S = S + "A";
    N = S.length();
    for(int i = 1; i < N; i++){
        if(S[i - 1] == S[i])ch++;
        else{
            cnt += (ch / 2);
            ch = 1;
        }
    }
    
    ans += cnt * K;
    
    cout << ans << endl;
    return 0;
}

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

int main(){
    string s;
    cin >> s;
    if(s[1] == 'B'){
        cout << "ARC" << endl;
    }else{
        cout << "ABC" <<endl;
    }
    

    return 0;
}

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

ll a[MAX];
vector<vector<vector<ll>>> dp(MAX,vector<vector<ll>>(MAX,vector<ll>(2,-1)));

ll dfs(int i, int j, int c){
    if(dp[i][j][c] != -1) return dp[i][j][c];
    if(i == j) {
        if(c == 1) return dp[i][j][c] = a[i];
        else return dp[i][j][c] = -a[i];
    }
    if(c == 1) {
        ll d = max(a[i]+dfs(i+1,j,0),a[j]+dfs(i,j-1,0));
        return dp[i][j][c] = d;
    } else {
        ll d = min(-a[i]+dfs(i+1,j,1),-a[j]+dfs(i,j-1,1));
        return dp[i][j][c] = d;
    } 
}

int main(){
    int n;
    cin >> n;
    rep(i,n) cin >> a[i];
    cout << dfs(0,n-1,1) << endl;
    return 0;
}

Measured memory_bytes: 494976
#[allow(unused_imports)]
use itertools::Itertools;
#[allow(unused_imports)]
use num::*;
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;
#[allow(unused_imports)]
use std::collections::*;

fn is_palindrome(s: &[char]) -> bool {
    let rev = s.into_iter().copied().rev().collect::<Vec<_>>();
    s == &rev[..]
}

fn solve() {
    input! {
        s: Chars
    };

    let len = s.len();
    let mid = len / 2;
    let is_ok = is_palindrome(&s) && is_palindrome(&s[0..mid]) && is_palindrome(&s[mid + 1..]);
    let res = if is_ok { "Yes" } else { "No" };
    println!("{}", res);
}

fn main() {
    std::thread::Builder::new()
        .name("big stack size".into())
        .stack_size(256 * 1024 * 1024)
        .spawn(|| {
            solve();
        })
        .unwrap()
        .join()
        .unwrap();
}


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

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;

#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert
#define pi  3.14159265359
#define mod 1000000007


int main()
{
    //ios_base::sync_with_stdio(false);
    //cin.tie(NULL);
    ll n,d;
    cin>>n>>d;
    ll ans=0;
    for(int i=1;i<=n;i++)
    {
        ll x,y;
        cin>>x>>y;


            double chek=sqrt(x*x+y*y);
            if(chek<=(double)d){
                ans++;
            }


    }
    cout<<ans<<endl;
}


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

int main()
{
ll n ;
cin >> n ;
vector<ll> h(n);
rep(i, n){
  cin >> h[i];
}
ll anss=0;
rep(i,n-1){
  if(h[i]>=h[i+1])ans++;
  else ans=0;
  anss=max(anss,ans);
}

cout << anss << endl;
return 0;
}


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

namespace AtCoder03
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] z = Console.ReadLine().Split('/');
            int a = int.Parse(z[0]);
            int b = int.Parse(z[1]);
            int c = int.Parse(z[2]);
            if (a > 2019)
            {
                Console.WriteLine("TBD");
            }else if(a == 2019 && b>4)
            {
                Console.WriteLine("TBD");
            }else Console.WriteLine("Heisei");
        }
    }
}

Measured memory_bytes: 11092
#include <iostream>
#include <string>
#include <algorithm>
#include <sstream>
#include <vector>
#include <set>
#include <stack>
#include <cstdlib>

int main(void)
{
    std::string commands;
    short x_goal, y_goal;
    std::cin >> commands >> x_goal >> y_goal;

    std::vector<short> xm;
    std::vector<short> ym;
    bool d_is_x = true;
    short distance = 0;
    bool first_x = true;
    commands += 'T';
    for(int i=0; i<commands.size(); ++i)
    {
        if(commands[i] == 'T')
        {
            if(d_is_x)
            {
                if(first_x)
                {
                    x_goal -= distance;
                    first_x = false;
                }
                else
                    xm.push_back(distance);
            }
            else
                ym.push_back(distance);
            distance = 0;
            d_is_x = !d_is_x;
        }
        else // F
            ++distance;
    }
    std::sort(xm.begin(), xm.end(), std::greater<short>());
    std::sort(ym.begin(), ym.end(), std::greater<short>());
    for(auto v : xm)
    {
        if(abs(x_goal+v) > abs(x_goal-v))
            x_goal -= v;
        else
            x_goal += v;
    }
    for(auto v : ym)
    {
        if(abs(y_goal+v) > abs(y_goal-v))
            y_goal -= v;
        else
            y_goal += v;
    }
    std::cout << (x_goal == 0 && y_goal == 0 ? "Yes" : "No") << std::endl;
    return 0;
}


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

public class Main {
	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		System.out.println((a-b)%c);
	}
}

Measured memory_bytes: 21844
#include<numeric>
#include<iostream>
#include<algorithm>
 
using namespace std;
 
int main()
{
    int a[5];
    for(int i=0;i<5;i++) cin>>a[i];
    sort(a,a+5,greater<int>());
    for(int i=0;i<5;i++) cout<<(i?" ":"")<<a[i];
    cout<<endl;
    return 0;
}

Measured memory_bytes: 1176
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

const int N = 1005;
char str[N];

int main() {
	while (~scanf("%s", str)) {
		int len = strlen(str);
		int f1 = 0, f2 = 0, f3 = 0, f4 = 0;
		for (int i = 0; i < len; i++) {
			if (str[i] == 'N') f1 = 1;
			if (str[i] == 'S') f2 = 1;
			if (str[i] == 'W') f3 = 1;
			if (str[i] == 'E') f4 = 1;
		}
		if ((f1^f2) || (f3^f4)) printf("No\n");
		else printf("Yes\n");
	}
	return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<utility>
#include<algorithm>
#include<cstdio>
#include<iomanip>
#include<queue>
#include<stack>

#define ll int64_t
#define Rep(i, n) for (ll i = 0; i < n; i++)

using namespace std;

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

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

    ll N, K;
    cin >> N >> K;
    vector<ll> A(N);
    Rep (i, N) {
        cin >> A[i];
    }

    vector<vector<ll>> dp(41, vector<ll>(2, -1));
    dp[0][0] = 0;

    Rep (d, 40) {
        ll mask = 1LL << (40-d-1);
        int num = 0;
        Rep (i, N) {
            if (A[i] & mask) num++;
        }

        ll cost0 = mask * num;
        ll cost1 = mask * (N - num);

        if (dp[d][1] != -1) {
            chmax(dp[d+1][1], dp[d][1] + max(cost0, cost1));
        }

        if (dp[d][0] != -1) {
            if (K & mask) {
                chmax(dp[d+1][1], dp[d][0] + cost0);
            }
        }

        if (dp[d][0] != -1) {
            if (K & mask) chmax(dp[d+1][0], dp[d][0] + cost1);
            else chmax(dp[d+1][0], dp[d][0] + cost0);
        }
    }

    cout << max(dp[40][0], dp[40][1]) << endl;
}

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

int main() {
    ll A,B,C,X;
    cin>>A>>B>>C>>X;
    ll ans=0;
    for(ll i=0;i<=A;++i){
        for(ll j=0;j<=B;++j){
            for(ll k=0;k<=C;++k){
                if(i*500+j*100+k*50==X) ++ans;
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}

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

vector<ll> tree[100001];
ll n, M;
ll bd1[100001], bd2[100001], presum[100001], sufsum[100001];

void dp1(ll n, ll par) {
    bd1[n] = 1;
    for (auto ch:tree[n]) {
        if (ch!=par) {
            dp1(ch, n);
            bd1[n] *= (bd1[ch]+1);
            bd1[n] %= M;
        }
    }
}

void dp2(ll n, ll par) {
    ll prev = 1;
    for (int i=0; i<tree[n].size(); i++) {
        if (tree[n][i]!=par) {
            presum[tree[n][i]] = prev;
            prev *= bd1[tree[n][i]]+1;
            prev %= M;
        }   
    }
        
    prev = 1;
    for (int i=tree[n].size()-1; i>=0; i--) {
        if (tree[n][i]!=par) {
            sufsum[tree[n][i]] = prev;
            prev *= bd1[tree[n][i]]+1;
            prev %= M;
        }   
    }
        
    for (auto ch:tree[n]) {
        if (ch!=par) {
            bd2[ch] = (presum[ch]*sufsum[ch])%M;
            bd2[ch] = (bd2[ch]*bd2[n])%M+1;
            dp2(ch, n);
        }
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
   
    cin >> n >> M;
    for (int i=2; i<=n; i++) {
        int a, b;
        cin >> a >> b;
        tree[a].push_back(b);
        tree[b].push_back(a);
    }
   
    memset(bd1, 0, sizeof(bd1));
    dp1(1, -1);
   
    memset(bd2, 0, sizeof(bd2));
    bd2[1] = 1;
    dp2(1, -1);
    
    for (int i=1; i<=n; i++) {
        cout << (bd1[i]*bd2[i])%M << "\n";
    }
}

Measured memory_bytes: 13312
package main

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

var sc = bufio.NewScanner(os.Stdin)

func init() {
	const maxWord = (1 << 30)
	buf := []byte{}
	sc.Buffer(buf, maxWord)
	sc.Split(bufio.ScanWords)
}

func input() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	n, _ := strconv.Atoi(input())
	d := make([]int, n)
	for i := 0; i < n; i++ {
		d[i], _ = strconv.Atoi(input())
	}
	sort.Ints(d)

	diff := d[n/2] - d[n/2-1]
	fmt.Println(diff)
}


Measured memory_bytes: 2048
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<vector>
#define MAX 2000000002
#define NIL NULL
using namespace std;
struct node{
    int data=0;
    node *parent=NIL,*left=NIL,*right=NIL;
};

vector<int> PreOrder,InOrder;
node *root=NIL;

void getPre(node *root){
    if(root==NIL) return;
    PreOrder.push_back(root->data);
    getPre(root->left);
    getPre(root->right);
}
void getIn(node *root){
    if(root==NIL) return;
    getIn(root->left);
    InOrder.push_back(root->data);
    getIn(root->right);
}

//void insertToTree(node *root,node *z){
void insertToTree(node *z){
    node *x,*y;
    y=NIL;
    x=root;
    while(x!=NIL){
        y=x;
        if(z->data<x->data){
            x=x->left;
        }else{
            x=x->right;
        }
    }
    z->parent=y;
    if(y==NIL){
        root=z;
    }else if(z->data<y->data){
        y->left=z;
    }else{
        y->right=z;
    }

}
void show(vector<int> B){
    for(int i=0;i<B.size();i++){
        cout<<' '<<B[i];
    }
    cout<<endl;
}

int main(){
    int n,i;
    string str;
    int num;
    node *z=NIL;
    cin>>n;
    for(i=0;i<n;i++){
        cin>>str;
        if(str=="insert"){
            cin>>num;
            z=(node *)malloc(sizeof(node));
            z->data=num;
            z->left=NIL;
            z->right=NIL;
            z->parent=NIL;
            //insertToTree(root,z);
            insertToTree(z);
        }else if(str=="print"){
            getIn(root);
            show(InOrder);
            InOrder.clear();
            getPre(root);
            show(PreOrder);
            PreOrder.clear();
            //root=NULL;
        }
    }
}



Measured memory_bytes: 32312
import java.util.*;
//import java.util.stream.Collectors;

public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		int a = Integer.parseInt(sc.next());
		int b = Integer.parseInt(sc.next());
		int c = Integer.parseInt(sc.next());
		if(a > b){
			int temp = a;
			a = b;
			b = temp;
		}
		boolean flg = false;
		for(int i=a; i<b; i++){
			if(i == c){
				flg = true;
				break;
			}
		}
		System.out.println(flg ? "Yes" : "No");
	}
}


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

template<typename T> void drop(const T &x){cout<<x<<'\n';exit(0);}

void solve() {
  int a, b, c, k;
  cin >> a >> b >> c >> k;

  int tmp = min(a, k);
  int ans = tmp;
  k -= tmp;
  if(!k) drop(ans);
  tmp = min(b, k);
  k -= tmp;
  if(!k) drop(ans);
  tmp = min(c, k);
  ans -= tmp;
  cout << ans << '\n';
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int T=1;
  //cin >> T;
  while(T--) solve();

  return 0;
}


Measured memory_bytes: 3636
#include<stdio.h>
#include<algorithm>
using namespace std;
char in[50];
int c[400];
int d[3][400];
int dp[310][310];
int main(){
	int a,b;
	while(~scanf("%d%d",&a,&b)){
		for(int i=0;i<a;i++){
			gets(in);gets(in);
			scanf("%d%d%d%d",c+i,&d[0][i],&d[1][i],&d[2][i]);
		}
		int ret=0;
		for(int i=0;i<3;i++){
			for(int j=0;j<=a;j++)for(int k=0;k<=b;k++)dp[j][k]=-19999999;
			dp[0][0]=0;
			for(int j=0;j<a;j++)for(int k=0;k<=b;k++){
				if(dp[j][k]<0)continue;
				dp[j+1][k]=max(dp[j+1][k],dp[j][k]);
				if(k+c[j]<=b)dp[j][k+c[j]]=max(dp[j][k+c[j]],dp[j][k]+d[i][j]);
			}
			for(int j=0;j<=b;j++)ret=max(ret,dp[a][j]);
		}
		printf("%d\n",ret);
	}
}

Measured memory_bytes: 1400
A = int(input())
B = int(input())
C = int(input())
X = int(input())
count = 0
for i in range(A+1):
  for j in range(B+1):
    for k in range(C+1):
      if (i)*500+(j)*100+(k)*50 == X:
        count += 1
      else:
        pass
print(count)


Measured memory_bytes: 3060
HM = input().split()
H, M = [int(HM[i]) for i in range(len(HM))]

S = [input() for i in range(H)]
#print(S)
#print(T[0][1])
#S2 = list([S[i] for i in range(H)] for j in range(M))
S2 = []
for i in range(H):
    S2.append(list(S[i]))
#print(S2)

def minesweeper():
    for i in range(H):
        for j in range(M):
            if S[i][j] == ".":
                c = count(i, j)
                #print(c)
                S2[i][j] = c
    for i in range(H):
        for j in range(M-1):
            print(S2[i][j], end="")
        print(S2[i][M-1])
    return 0


def count(x,y):
    c = 0
    #print("x={}".format(x))
    if (x >= 1 and y >= 1):
        if S[x-1][y-1] == '#':
            c += 1
            #print('1')
    if (x >= 1):
        if S[x-1][y] == "#":
            c += 1
            #print('2')
    if x >= 1 and y <= M - 2:
        if S[x-1][y+1] == "#":
            c += 1
            #print("x={}".format(x))
            #print('3')
    if (y >= 1):
        if S[x][y-1] == "#":
            c += 1
            #print('4')
    if (y <= M - 2):
        if S[x][y+1] == "#":
            c += 1
            #print('5')
    if (x <= H-2 and y >= 1):
        if S[x+1][y-1] == "#":
            c += 1
            #print('6')
    if (x <= H-2):
        if S[x+1][y] == "#":
            c += 1
            #print('7')
    if (x <= H-2 and y <= M-2):
        if S[x+1][y+1] == "#":
            c += 1
            #print('8')
    return c

minesweeper()

Measured memory_bytes: 3572
# -*- coding: utf-8 -*-
 
import math
import itertools
import sys
import copy
 
# 入力
#N, K = map(int, input().split())
#L = list(map(int, input().split()))
#N = int(input())
S = str(input())

print (S[0] + str(len(S)-2) + S[-1])


Measured memory_bytes: 38256
'use strict';

function main(arg) {
    const N     = parseInt(arg.split("\n")[0]);
    const words = arg.split("\n").slice(1);
    const memo  = new Set();

    let lastLetter = words[0].slice(0, 1);

    for(let i=0; i<N; i++) {
        if(lastLetter !== words[i].slice(0, 1) || memo.has(words[i])) {
            console.log('No');
            return;
        }

        lastLetter = words[i].slice(-1);
        memo.add(words[i]);
    }
    
    console.log('Yes');
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 9548
import numpy as np
N, M=map(int, input().split(' '))
shops = []
for i in range(N):
    a, b = map(int, input().split(' '))
    shops.append([a,b])
shops =sorted(shops, key=lambda list: list[0])
n_bought = 0
p_bought = 0
i = 0
while n_bought < M:
    n = min(shops[i][1], M - n_bought)
    n_bought += n
    p_bought += shops[i][0]*n
    i += 1
print(p_bought)

Measured memory_bytes: 31024
n = int(input())
nums = list(map(int, input().split() ))
nums.sort()

if nums[0] >= 0:
	# all 0以上
	print(sum(list(map(abs, nums))) - 2 * nums[0])

	hikareru = nums[0]
	for idx in range(2,n):
		print("{} {}".format(hikareru, nums[idx]) )
		hikareru -= nums[idx]

	print("{} {}".format(nums[1], hikareru) )

elif nums[-1] <= 0:
	# all 0以下
	print(sum(list(map(abs, nums))) - 2 * (-1)*nums[-1] )

	hikareru = nums[-1]
	for idx in range(n-1):
		print("{} {}".format(hikareru, nums[idx]) )
		hikareru -= nums[idx]

else:
	print(sum(list(map(abs, nums))) )

	hikareru = nums[0]
	idx = n-2
	while True:
		if nums[idx] < 0:
			break
		print("{} {}".format(hikareru, nums[idx]) )
		hikareru -= nums[idx]
		idx -= 1

	hiku = hikareru
	print("{} {}".format(nums[n-1], hiku) )
	hikareru = nums[n-1] -  hiku

	idx = 1
	while True:
		if nums[idx] >= 0:
			break
		print("{} {}".format(hikareru, nums[idx]) )
		hikareru -= nums[idx]
		idx += 1


Measured memory_bytes: 14088
n = int(input())

max_s = 1 - (10 ** 9)
min_s = 2 * (10 ** 9)
max_t = 1 - (10 ** 9)
min_t = 2 * (10 ** 9)
for _ in range(n):
    x, y = map(int, input().split())
    s = x - y
    t = x + y
    
    max_s = max(max_s, s)
    min_s = min(min_s, s)
    max_t = max(max_t, t)
    min_t = min(min_t, t)

print(max(max_s - min_s, max_t - min_t))


Measured memory_bytes: 9204
#include <iostream>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <ctime>
#include <complex>

using namespace std;

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define RFOR(i,b,a) for (int i = (b)-1; i >= (a); i--)
#define ITER(it,a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a,value) memset(a, value, sizeof(a))

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

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;

const double PI = acos(-1.0);
const int INF = 1000 * 1000 * 1000 + 7;
const LL LINF = INF * (LL) INF;

const int MAX = 100 * 1000 + 47;


int A[MAX], B[MAX];
int AA[MAX], BB[MAX];
int V[MAX];
int P[MAX];

int find(int v)
{
    if (v == P[v])return v;
    return P[v] = find(P[v]);
}


int main()
{
    // freopen("in.txt", "r", stdin);
    int n, a = 0, b = 0;
    
    scanf("%d", &n);
    FOR(i, 0, n)scanf("%d", A + i), a ^= A[i];
    FOR(i, 0, n)scanf("%d", B + i), b ^= B[i];
    
    int idx = 0;
    FOR(i, 0, n)
        if (A[i] != B[i])
        {
            A[idx] = A[i];
            B[idx] = B[i];
            ++idx;
        }
    
    n = idx;
    
    A[n] = a, B[n] = b, ++n;
    
    int sz = 0;
    FOR(i, 0, n)V[sz++] = A[i], V[sz++] = B[i];
    sort(V, V + sz);
    sz = unique(V, V + sz) - V;
    
    FOR(i, 0, n)
    {
        AA[i] = A[i] = lower_bound(V, V + sz, A[i]) - V;
        BB[i] = B[i] = lower_bound(V, V + sz, B[i]) - V;
    }
    
    sort(AA, AA + n), sort(BB, BB + n);
    
    FOR(i, 0, n)
        if (AA[i] != BB[i])
        {
            printf("-1\n");
            return 0;
        }
    
    
    FOR(i, 0, sz)P[i] = i;
    
    
    int ans = n + sz - 2;
    FOR(i, 0, n)
    {
        int aa = find(A[i]);
        int bb = find(B[i]);
        if (aa == bb)continue;
        if (rand() & 1)swap(aa, bb);
        P[aa] = bb;
        ans--;
    }
    
    printf("%d\n", ans);
    
    
    return 0;
}





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

int main()
{
	int n;cin>>n;int a[n+1][3];
	for(int i=0;i<n;i++)
	for(int j=0;j<3;j++)
	cin>>a[i][j];
	
	int dp[n][3];
	
	dp[0][0]=a[0][0];dp[0][1]=a[0][1];dp[0][2]=a[0][2];
	
	for(int i=1;i<n;i++)
{	
	dp[i][0]=max(dp[i-1][1],dp[i-1][2])+a[i][0];
	
	dp[i][1]=max(dp[i-1][0],dp[i-1][2])+a[i][1];
	
	dp[i][2]=max(dp[i-1][1],dp[i-1][0])+a[i][2];
	
}

cout<<max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]))<<endl;

return 0;
	
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define Sort(x) sort((x).begin(), (x).end())
#define Reverse(x) reverse((x).begin(), (x).end())
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define INF INT_MAX
#define MOD 1000000007
#define fcout cout << fixed << setprecision(15) //15桁まで表示
#define str string
typedef std::pair<int,int> pii;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef pair<ui,ui> puu;
typedef pair<int, int> P;
typedef vector<int> vi;
int gcd(int a,int b){return b?gcd(b,a%b):a;};
int lcm(int a,int b){return a * b / gcd(a, b);};
int floor(int a,int b){return (a+b-1)/b;};
int month[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
template<class T>inline bool chmax(T& a,T b){if(a < b){a=b;return true;}return false;};
template<class T>inline bool chmin(T& a,T b){if(a > b){a=b;return true;}return false;};

int main() {
    int a,b;
    cin >> a>>b;
    if (a==1){a+=100;}
    if (b==1){b+=100;}
    if (a<b){cout << "Bob" << endl;}
    else if(a>b){cout << "Alice" << endl;}
    else{cout << "Draw" << endl;}
}

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

typedef long long ll;

using namespace std;

#define swap(a, b)    do { typeof(a) __tmp = (a); (a) = (b); (b) = __tmp; } while(0)
#define repd(i, a, b) for(typeof(b) i = a; i < (b); ++i)
#define rep(i, n)     repd(i, 0, n)
#define dump(x)       cerr << #x << " = " << (x) << endl
#define debug(x)      cerr << "L" << __LINE__ << ": " << #x << " = " << (x) << endl
#define YesNo(x)      cout << ((x) ? "Yes" : "No") << endl
#define YESNO(x)      cout << ((x) ? "YES" : "NO") << endl
#define absi(x)       ( ((x) >= 0) ? (x) : (-(x)) )

ll malof(ll n, ll a, ll b) {
	// return ((b % n == 0 ? b : (b / n) * n) - (a % n == 0 ? a : (a / n) * n + 1)) / n + 1;
	ll right = (b % n == 0) ? b : ((b / n) * n);
	ll left  = (a % n == 0) ? a : ((a / n + 1) * n);

	ll ret = 0;
	if(right < left) {
		ret = 0;
	} else {
		ret =  (right - left) / n + 1;
	}

	cerr << "malof(" << n << ", " << a << ", " << b << ") = " << ret << endl;
	debug(left);
	debug(right);

	return ret;
}

int main(int argc, const char* argv[]) {
	ll a, b, c, d;
	cin >> a >> b >> c >> d;

	cout << (b - a + 1) - malof(c,a,b) - malof(d, a, b) + malof(c * d / __gcd(c, d), a, b) << endl;

	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;

int main(){
	int n;
	long long ans=0,count[5];
	string s;
	
	for(int i=0;i<5;i++)count[i]=0;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>s;
		if(s[0]=='M')count[0]++;
		if(s[0]=='A')count[1]++;
		if(s[0]=='R')count[2]++;
		if(s[0]=='C')count[3]++;
		if(s[0]=='H')count[4]++;
	}
	for(int i=0;i<3;i++){
		for(int j=i+1;j<4;j++){
			for(int k=j+1;k<5;k++){
				ans+=count[i]*count[j]*count[k];
			}
		}
	}
	cout<<ans<<endl;
}

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

int main(){
  
  int A; int B;
  cin >> A >> B;
  int et_min; int et_max;
  if (A%2==0){
    et_min = A*25/2;
    et_max = (A+1)*25/2;
  }else{
    et_min = (A*25+1)/2;
    et_max = (A+1)*25/2-1;
  }
  int tn_min; int tn_max;
  tn_min = B*10;
  tn_max = (B+1)*10-1;
  
  if(et_min <= tn_min && tn_min <= et_max){
    cout << tn_min << endl;
  }else if(tn_min <= et_min && et_min <= tn_max){
    cout << et_min << endl;
  }else{
    cout << -1 << endl;
  }
  //cout << et_min << et_max << endl;
}

Measured memory_bytes: 256