akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstring>
#include <cmath>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <math.h>
#include <stdlib.h>

using namespace std;

int main()
{
    int n;
    int k;
    
    cin >> n >> k;
    
    vector<int> h(n,0);
    for(int i = 0;i < n;i++){
        cin >> h[i];
    }
    sort(h.begin(),h.end());
    int ans = h[k-1]-h[0];
    for (int i = 1;i <= n-k;i++){
        if (h[k-1+i]-h[i] < ans){
            ans = h[k-1+i]-h[i];
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define o(a) cout << a << endl
#define int long long
#define first first
#define second se
using namespace std;
typedef pair<int, int> P;
typedef vector<int> vi;

signed main(){
    int n;
    cin >> n;
    int t = 0, a = 0;
    rep(i, 0, n){
        int ti, ai;
        cin >> ti >> ai;
        if(i == 0){
            t = ti;
            a = ai;
        }else{
            int tmp = max((t - 1) / ti + 1, (a - 1) / ai + 1);
            t = tmp * ti;
            a = tmp * ai;
        }
    }
    o(t + a);
}

Measured memory_bytes: 256
import java.util.Scanner;

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

        while(true){
        int x = sc.nextInt();
        String op = sc.next();
        int y = sc.nextInt();

            if(op.equals("+")){
                System.out.println(x + y);
            }else if(op.equals("-")){
                System.out.println(x - y);
            }else if(op.equals("*")){
                System.out.println(x * y);
            }else if(op.equals("/")){
                System.out.println(x / y);
            }else{
                break;
            }
        }
        sc.close();
    }
}


Measured memory_bytes: 26312
import java .util.*;

public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		String S = sc.nextLine();
		String T = sc.nextLine();
		
		Map<Character, Character> map = new HashMap<Character, Character>();
		for(int i = 0; i < S.length(); i++) {
			Character str1 = S.charAt(i);
			Character str2 = T.charAt(i);
			if(!map.containsKey(str1) && !map.containsValue(str2)) {
				map.put(str1, str2);
			} else {
				if(!str2.equals(map.get(str1))) {
					System.out.println("No");
					return;
				}
			}
		}
		
		System.out.println("Yes");
	}
}


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

using namespace std;

typedef vector<int> vec;
typedef vector<vec> Graph;

Graph G(110);

int main()
{
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	{
		int u,t;
		scanf("%d%d",&u,&t);
		for(int j=0;j<t;j++)
		{
			int v;
			scanf("%d",&v);
			G[u].push_back(v);
		}
	}
	queue<int> que;
	int d[110];
	fill(d+1,d+n+1,-1);
	d[1]=0;
	que.push(1);
	while(!que.empty())
	{
		int t=que.front();que.pop();
		for(int i=0;i<G[t].size();i++)
			if(d[G[t][i]]==-1||d[t]+1<d[G[t][i]])
			{
				d[G[t][i]]=d[t]+1;
				que.push(G[t][i]);
			}
	}
	for(int i=1;i<=n;i++)
		printf("%d %d\n",i,d[i]);
	return 0;
}

Measured memory_bytes: 3236
#include<string>
#include<vector>
#include<algorithm>
#include<iostream>
#include<cmath>

using namespace std;

int main() {
	int n, r;
	cin >> n >> r;
	if (n >= 10) {
		cout << r;
	}
	else {
		cout << 100 * (10 - n) + r;
	}
}

Measured memory_bytes: 3632
#include<bits/stdc++.h> 
//#define <- プログラムの文字列を置換する
//typedef <- 新しい型に名前を付けるためのキーワード

using namespace std;

#define MAX_N 1

typedef long long ll;

const double pi = 3.141592653589793;
const long long MOD = 1e9 + 7;
const long long INF = 1e15;

int main(){
    ll n,m;
    cin >> n >> m;
    vector<ll> v;
    ll maxi = 0;
    for(ll i = 1; i <= sqrt(m); i++){
        if(m % i == 0){
            ll temp = 0;
            ll i2 = m / i;
            if(n * i <= m) temp = i;
            if(n * i2 <= m) temp = i2;
            maxi = max(maxi,temp); 
        } 
    }
    cout << maxi << endl;
    return 0;
}

Measured memory_bytes: 256
import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;
import std.math, std.random, std.bigint, std.datetime, std.format;
void main(string[] args){ if(args.length > 1) if(args[1] == "-debug") DEBUG = 1; solve(); }
void log()(){ writeln(""); } void log(T, A ...)(T t, lazy A a){ if(DEBUG) write(t, " "), log(a); } bool DEBUG = 0; 
string read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //
void solve(){
	int n = read.to!int;
	int l = read.to!int;
	
	int x;
	if(l >= 0) x = l;
	else if(l + n - 1 <= 0) x = l + n - 1;
	else x = 0;
	
	int ans;
	foreach(i; 0 .. n) ans += l + i;
	
	ans -= x;
	
	ans.writeln;
	
}


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

const long long inf = 1e18;

struct line_t {
	int a; long long b;
	line_t(int a = 0,long long b = 0) : a(a), b(b) {}
	long long f(int x) { return 1LL * a * x + b; };
};

double slope(line_t ln1, line_t ln2) {
	return (double) (ln2.b - ln1.b) / (double) (ln2.a - ln1.a);
}

struct convex_hull {
	vector<line_t> lns;
	int ptr = 0;
	void add(int a,long long b) {
		line_t ln(a, b);
		while (lns.size() > 1 && slope(lns[lns.size() - 2], lns.back()) <= slope(lns[lns.size() - 2], ln)) lns.pop_back();
		lns.push_back(ln); ptr = min(ptr, int(lns.size()) - 1);
	}
	long long get(int x) {
		if (lns.empty()) return inf;
		while (ptr + 1 < int(lns.size()) && lns[ptr].f(x) > lns[ptr + 1].f(x)) ptr++;
		return lns[ptr].f(x);
	}
};

const int N = 200005;

int n;
long long C;
int h[N];
long long f[N];
convex_hull ch;

int main() {
	scanf("%d %lld", &n, &C);
	for (int i = 1; i <= n; ++i) {
		int h; scanf("%d", &h);
		f[i] = (i == 1 ? 0 : ch.get(h) + 1LL * h * h + C);
		ch.add(-2 * h, 1LL * h * h + f[i]);
	}
	printf("%lld\n", f[n]);
}

Measured memory_bytes: 7408
import heapq

N = int(input())
abc = [list(map(int,input().split())) for _ in range(N-1)]
Q,K = list(map(int,input().split()))
xy = [list(map(int,input().split())) for _ in range(Q)]

connect = [[] for _ in range(N)]
INFTY = 10**15
for a,b,c in abc:
    connect[a-1].append([b-1,c])
    connect[b-1].append([a-1,c])

cost = [[INFTY,False] for _  in range(N)]
cost[K-1][0] = 0
q = [(0,K-1)]
while q:
    _,i = heapq.heappop(q)
    if cost[i][1]:
        continue
    cost[i][1] = True
    ci0 = cost[i][0]
    for j,c in connect[i]:
        if cost[j][1]:
            continue
        tmp_cost = ci0+c
        if tmp_cost < cost[j][0]:
            cost[j][0] = tmp_cost
            heapq.heappush(q,(tmp_cost,j))

for x,y in xy:
    print(cost[x-1][0] + cost[y-1][0])

Measured memory_bytes: 98856
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <numeric>
#include <string>
#include <vector>
#include <iostream>
#include <forward_list>
using namespace std;

#define SCAN_INT(i) scanf("%lld", i)
#define FOR(i, start, end) for (int i = start; i < end; i++)
#define PRINT_INT(i) printf("%lld\n", i)
#define PRINT_TWO_INT(i, j) printf("%d %d\n", i, j)
#define PRINT_THREE_INT(i, j, k) printf("%d %d %d\n", i, j, k)

void foo(int *a, int *aa)
{
    *aa = (*a / 10 + 1) * 10;
    if (*a % 10 == 0)
        *aa -= 10;
}

int main()
{
    long long N, tra[5], turntime[5];
    SCAN_INT(&N);
    for (int i = 0; i < 5; i++)
        SCAN_INT(&tra[i]);

    long long m = tra[0];
    for (int i = 1; i < 5; i++)
    {
        m = m > tra[i] ? tra[i] : m;
        turntime[i] = N / m;
        if (N % m != 0)
            turntime[i]++;
    }
    PRINT_INT(4 + turntime[4]);
    return 0;
}

Measured memory_bytes: 256
from collections import defaultdict, deque
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(1000000)
# MOD = 10 ** 9 + 7
# INF = float("inf")


def bfs(s, n, g):
    dist = [-1] * n
    dist[s] = 0
    que = deque([])
    que.append(s)
    while que:
        v = que.popleft()
        for nv in g[v]:
            if dist[nv] != -1:
                continue  # すでに探索している時はスルー
            dist[nv] = dist[v] + 1
            que.append(nv)
    if -1 in dist:
        return True
    else:
        return False


def main():
    n, m = map(int, input().split())
    g = [[] for _ in range(n)]
    gg = []
    for _ in range(m):
        a, b = [int(i) - 1 for i in input().split()]
        g[a].append(b)
        g[b].append(a)
        gg.append((a, b))
    ans = 0
    for a, b in gg:
        g[a].remove(b)
        g[b].remove(a)
        if bfs(0, n, g):
            ans += 1
        g[a].append(b)
        g[b].append(a)
    print(ans)
    return


if __name__ == "__main__":
    main()

Measured memory_bytes: 3316
// https://atcoder.jp/contests/agc047/tasks/agc047_a

#include "algorithm"
#include "bitset"
#include "cmath"
#include "functional"
#include "iomanip"
#include "iostream"
#include "map"
#include "numeric"
#include "queue"
#include "set"
#include "string"
#include "vector"
#define rep(i, to) for (ll i = 0; i < (to); ++i)
#define rep1(i, to) for (ll i = 1; i <= (to); ++i)
#define repf(i, from, to) for (ll i = from; i < (to); ++i)
#define repr(i, from) for (ll i = from - 1; i >= 0; --i)
#define all(vec) vec.begin(), vec.end()
#define unless(cond) if (!(cond))
#define fi first
#define se second
using namespace std;
using ll = long long;
using ld = long double;
template <typename T>
using V = vector<T>;
using VL = V<ll>;
template <typename T>
using VV = V<V<T>>;
using VVL = VV<ll>;
template <typename T>
using VVV = VV<V<T>>;
template <typename T, typename U>
using P = pair<T, U>;
using PL = P<ll, ll>;
using VPL = V<PL>;
template <typename T>
using asc_pq = priority_queue<T, V<T>, greater<T>>;

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

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

template <typename T>
inline ll len(V<T> arr) {
  return arr.size();
}

struct exit_exception : public std::exception {
  const char* what() const throw() { return "Exited"; }
};

template <typename T>
void drop(T res) {
  cout << res << endl;
  throw exit_exception();
}

const ll INF = 1e18;

void solve();

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

  try {
    solve();
  } catch (exit_exception& e) {
  }

  return 0;
}
#endif

void solve() {
  ll N;
  cin >> N;

  VL as(N);

  rep(i, N) {
    ld d;
    cin >> d;
    d *= 1e9;
    as[i] = d + 0.5;
  }

  VVL ct(19, VL(19));  // 0 ~ 18

  for (ll a : as) {
    ll ct2 = 0;
    ll ct5 = 0;

    while (a % 2 == 0) {
      a /= 2;
      ct2++;
    }

    while (a % 5 == 0) {
      a /= 5;
      ct5++;
    }

    ct2 = min(ct2, 18ll);
    ct5 = min(ct5, 18ll);

    ct[ct2][ct5]++;
  }

  ll res = 0;

  rep(i2, 19) rep(i5, 19) rep(j2, 19) rep(j5, 19) {
    unless(i2 + j2 >= 18) continue;
    unless(i5 + j5 >= 18) continue;

    if (i2 == j2 && i5 == j5) {
      res += ct[i2][i5] * (ct[j2][j5] - 1);
    } else {
      res += ct[i2][i5] * ct[j2][j5];
    }
  }

  res /= 2;
  cout << res << "\n";
}


Measured memory_bytes: 4704
import string
alphabets = string.ascii_lowercase   
n = int(input())
S = [input() for _ in range(n)]
counter = {}

for alphabet in alphabets:
    alphabet_count = [s.count(alphabet) for s in S]
    counter[alphabet] = min(alphabet_count)
ans = ""
for alphabet, count in counter.items():
    ans += alphabet*count
print("".join(sorted(ans)))

Measured memory_bytes: 3956
A = int(input())
B = int(input())
C = int(input())
X = int(input())
ans = 0
for a in range(A+1):
  for b in range(B+1):
    for c in range(C+1):
      if X == 500*a + 100*b + 50*c:
        ans += 1
print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
 
int main(){
  string a, b;
  cin >> a >> b;
  sort(a.begin(), a.end());
  sort(b.begin(), b.end());
  reverse(b.begin(), b.end());
  
  if(a < b)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

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

using namespace std;

int gcd(int a, int b){
    int r;
    if(b > a) swap(a, b);
    while(r = a%b){
        a = b;
        b = r;
    }
    return b;
}

int main() {
    int N, X; cin >> N >> X;
    vector<int> G(N-1);
    vector<int> diff(N);
    vector<int> x(N+1);
    for(int i=0; i<N; i++) cin >> x[i];
    x[N] = X;
    sort(x.begin(), x.end());
         
    for(int i=0; i<N; i++){
        diff[i] = x[i+1] - x[i];
    }
    
    if(diff.size()==1){
        cout << diff[0] << endl;
        return 0;
    }
    
    for(int i=0; i<N-1; i++){
        if(i==0) G[i] = gcd(diff[i], diff[i+1]);
        else {
            G[i] = gcd(G[i-1], diff[i+1]);
        }
    }
    
    cout << G[N-2] << endl;
    return 0;
}


Measured memory_bytes: 1408
import java.util.Scanner;
public class Main{

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		
		int temp = -1;
		
		for(int i = 1 ; i <= 9 ;i++) {
			for(int j = 1 ; j <= 9 ;j++) {
				int ans  = i * j;
				if(ans == n) {
					temp = 0;
					break;
				}
			}
		}
		
		if(temp == 0) {
			System.out.println("Yes");
		}
		else {
			System.out.println("No");
		}

	}

}


Measured memory_bytes: 23124
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i <= b; ++i)
#define per(i, a, b) for (int i = a; i >= b; i--)
#define ll long long
#define mset(s, _) memset(s, _, sizeof s)
#define ALL(a) (a).begin(), (a).end()
using namespace std;

int main(void) {
  int n;
  cin >> n;
  int a, b, c;
  vector<int> A, B, C;
  rep(i, 1, n) {
    cin >> a >> b >> c;
    A.push_back(a);
    B.push_back(b);
    C.push_back(c);
  }

  vector<vector<int>> dp(n, vector<int>(3, 0));
  dp[0][0] = A[0];
  dp[0][1] = B[0];
  dp[0][2] = C[0];

  // rep(i, 1, n - 1) {
  //   dp[i][0] = dp[i - 1][0] + max(B[i], C[i]);
  //   dp[i][1] = dp[i - 1][1] + max(A[i], C[i]);
  //   dp[i][2] = dp[i - 1][2] + max(A[i], B[i]);
  // }

  rep(i, 1, n - 1) {
    dp[i][0] = A[i] + max(dp[i - 1][1], dp[i - 1][2]);
    dp[i][1] = B[i] + max(dp[i - 1][0], dp[i - 1][2]);
    dp[i][2] = C[i] + max(dp[i - 1][0], dp[i - 1][1]);
  }

  // rep(i, 0, n - 1) {
  //   cout << dp[i][0] << " ";
  //   cout << dp[i][1] << " ";
  //   cout << dp[i][2] << " ";
  //   cout << endl;
  // }

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


Measured memory_bytes: 6892
package main

import (
	"fmt"
	"sort"
)

func main() {
	var n int
	fmt.Scan(&n)
	vs := make([]int, n)
	for i := range vs {
		fmt.Scan(&vs[i])
	}

	odd := make([]int, 100000)
	even := make([]int, 100000)

	for i, v := range vs {
		if (i+1)%2 == 0 {
			even[v-1]++
		} else {
			odd[v-1]++
		}
	}

	// flag1: 最頻出の数字が同じかどうか
	// flag2: 2番目に頻出の数字の出現回数を比較、どっちが多いか？
	flag1, flag2 := check(odd, even)

	sort.Ints(odd)
	sort.Ints(even)

	if flag1 == true {
		if flag2 == "odd" {
			fmt.Println(n - odd[99998] - even[99999])
			return
		}
		fmt.Println(n - odd[99999] - even[99998])
		return
	}
	fmt.Println(n - odd[99999] - even[99999])
}

func check(odd, even []int) (bool, string) {
	var maxOddIndex, secondOddIndex, maxEvenIndex, secondEvenIndex int

	for i := 0; i < 100000; i++ {
		if odd[i] > odd[maxOddIndex] {
			secondOddIndex = maxOddIndex
			maxOddIndex = i
		} else if odd[i] > odd[secondOddIndex] {
			secondOddIndex = i
		}

		if even[i] > even[maxEvenIndex] {
			secondEvenIndex = maxEvenIndex
			maxEvenIndex = i
		} else if even[i] > even[secondEvenIndex] {
			secondEvenIndex = i
		}
	}

	flag1 := false
	flag2 := ""
	if maxOddIndex == maxEvenIndex {
		flag1 = true
		if odd[secondOddIndex] > even[secondEvenIndex] {
			flag2 = "odd"
		} else {
			flag2 = "even"
		}
	}

	return flag1, flag2
}


Measured memory_bytes: 5504
{-# LANGUAGE MultiParamTypeClasses,FlexibleContexts,FlexibleInstances,TypeSynonymInstances,BangPatterns,RankNTypes,TupleSections #-}
import Control.Monad
import Control.Monad.ST
import Control.Applicative
import Control.Arrow
import Debug.Trace
import Text.Printf

import Data.List
import Data.Int
import Data.Bits
import Data.Maybe
import Data.Monoid
import Data.Array.Unboxed
import Data.Array.ST
import Data.Array.Base
import Data.Function(on)
import Data.Tuple(swap)
import qualified Data.Map as M
import qualified Data.Set as S
import qualified Data.ByteString.Char8 as B

main :: IO ()
main = do
    (n, x) <- readIntPair
    as <- readInts
    let ans = minimum [ d * x + calc d | d <- [0..n-1]]
        calc d = sum [ arr ! d   | arr <- tbl ]
        tbl :: [UArray Int Int]
        tbl = map (listArray (0,n-1).scanl1 min.take n) $ take n $ tails $ cycle $ reverse as
    print ans


-- IO
readInt :: B.ByteString -> Int
readInt = fromJust . fmap fst . B.readInt
readInts :: IO [Int]
readInts = map readInt . B.words <$> B.getLine
readIntPair :: IO (Int,Int)
readIntPair = l2p . map readInt . take 2 . B.words <$> B.getLine
readAllInts :: IO [[Int]]
readAllInts = map (map readInt . B.words) . B.lines <$> B.getContents
readLns :: Read a => IO [a]
readLns = map read . words <$> getLine

-- Utilities
l2p :: [a] -> (a,a)
l2p (a:b:_) = (a,b)
l2p _ = error "l2p: the input list is too short"
p2l :: (a,a) -> [a]
p2l (a,b) = [a,b]
itof :: Int -> Double
itof = fromIntegral
inf :: Int
inf = maxBound `div` 2

-- Monad
stepM_ :: Monad m => a -> (a -> Bool) -> (a -> a) -> (a -> m ()) -> m ()
stepM_ i0 judge incr step = sub i0 where 
    sub i | judge i = step i >> sub (incr i) 
          | otherwise = return ()
rep_ :: Monad m => Int -> (Int -> m ()) -> m ()
rep_ n = stepM_ 0 (<n) (+1)
thru :: Monad m => (v -> m ()) -> v -> m v
thru m v = m v >> return v
memoize :: (Monad m) => (k -> m (Maybe v)) -> (k -> v -> m ()) -> k -> m v -> m v
memoize getter setter key action = do
    mv <- getter key
    case mv of
        Just v -> return v
        Nothing -> action >>= thru (setter key)

-- Array
newUArray :: (MArray (STUArray s) e (ST s),Ix i) => 
             (i,i) -> e -> ST s (STUArray s i e)
newUArray = newArray
newBArray :: (Ix i) => (i,i) -> e -> ST s (STArray s i e)
newBArray = newArray
defaultArray :: (IArray a e,Ix i) => e -> (i,i) -> [(i,e)] -> a i e
defaultArray = accumArray $ curry snd
fromEdges :: Ix i => (i,i) -> [(i,e)] -> Array i [e]
fromEdges = accumArray (flip (:)) []


Measured memory_bytes: 33660
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <queue>
#include <map>
#include <set>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <bitset>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
const int INF = 1<<29;

struct rect {
  int x1,y1;
  int x2,y2;
};
const bool operator<(const rect &a, const rect &b) {
  return a.x1!=b.x1?a.x1<b.x1:a.y1!=b.y1?a.y1<b.y1 :
    a.x2!=b.x2?a.x2<b.x2:a.y2<b.y2;
}

bool visited[1<<16];

int main() {
  int n;
  cin >> n;
  set<rect> se;

  REP(i,n) {
    int h, w;
    cin >> h >> w;
    for (int r=-3; r<=3; ++r) {
      for (int c=-3; c<=3; ++c) {
        int x1=4,y1=4,x2=0,y2=0;
        for (int rr=max(0,r); rr<min(4,r+h); ++rr) {
          for (int cc=max(0,c); cc<min(4,c+w); ++cc) {
            x1 = min(x1, cc);
            y1 = min(y1, rr);
            x2 = max(x2, cc);
            y2 = max(y2, rr);
          }
        }
        if (x1!=4) {
          se.insert((rect){x1,y1,x2,y2});
        }
      }
    }
  }
  int ba[4][4];
  REP(i,4) {
    REP(j,4) {
      char c;
      cin >> c;
      if (c=='R') ba[i][j] = 0;
      else if (c=='G') ba[i][j] = 1;
      else ba[i][j] = 2;
    }
  }

  vector<int> correct;
  vector<int> wrong;

  FOR(it, se) {
//    printf("(%d,%d) (%d,%d)\n", it->x1,it->y1,it->x2,it->y2);
    int x1=it->x1,y1=it->y1,x2=it->x2,y2=it->y2;
    REP(c, 3) {
      int cor=0, wro=0;
      for (int x=x1;x<=x2;++x) {
        for (int y=y1;y<=y2;++y) {
          if (ba[y][x] == c) cor |= 1<<(y*4+x);
          else wro |= 1<<(y*4+x);
        }
      }
      // if (x1==2&&y1==1&&x2==2&&y2==1) {
      //   cout << cor << " " << wro << endl;
      // }
      correct.push_back(cor);
      wrong.push_back(wro);
    }
  }
  int m = correct.size();
  typedef pair<int,int> pii;
  queue<pii> Q;
  Q.push(pii(0,0));
  while(!Q.empty()) {
    pii p = Q.front(); Q.pop();
    int S = p.first, num = p.second;
    if (visited[S]) continue;
    // if (num == 1) {
    //   stringstream ss;
    //   ss << bitset<16>(S);
    //   string s = ss.str();
    //   if (s[6]=='1') {
    //     REP(i,4) {
    //       REP(j,4) {
    //         cout << s[i*4+j];
    //       }
    //       cout << endl;
    //     }
    //     cout << endl;
    //   }
    // }
      //cout << S << endl;
    visited[S] = 1;
    if (S==(1<<16)-1) {
      cout << num << endl;
      break;
    }
    REP(i, m) {
      int s = S;
      s |= correct[i];
      s &= ~wrong[i];
      if (!visited[s]) {
        Q.push(pii(s, num+1));
      }
    }
  }
}

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

def get_input() -> tuple:
    """
    標準入力を取得する.

    Returns:\n
        tuple: 標準入力
    """
    D, T, S = list(map(int, input().split()))

    return D, T, S


def main(D: int, T: int, S: int) -> None:
    """
    メイン処理.

    Args:\n
        D (int): 待ち合わせ場所(1 <= D <= 10000)
        T (int): 待ち合わせ時間(1 <= T <= 10000)
        S (int): 分速(1 <= S <= 10000)
    """
    # 求解処理
    ans = str()
    if D <= S * T:
        ans = "Yes"
    else:
        ans = "No"

    # 結果出力
    print(ans)


if __name__ == "__main__":
    # 標準入力を取得
    D, T, S = get_input()

    # メイン処理
    main(D, T, S)


Measured memory_bytes: 9048
///not today

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

#define SZ(x) (int)(x).size()
#define pb push_back
#define ll long long
#define xmax(x, y) (x) = max((x), (y))
#define xmin(x, y) (x) = min((x), (y))
#define F first
#define S second
#define pii pair<int, int>
#define pll pair<long long, long long>
#define int long long
#define pipii pair< int, pair<int, int> >
#define plpll pair< ll, pair<ll, ll> >

using namespace std;

int32_t main(){
      int n, k, ans = 0;
      cin >>n >>k;
      for(int i = 0; i < n; i ++){
            int x;
            cin >>x;
            if(x >= k)
                  ans ++;
      }
      cout <<ans <<endl;
      return false;
}


Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
int main(){
    int nowpoint,wran[3]={0},kran[3]={0},wsum=0,ksum=0;
    for(int i=0;i<10;i++){
        scanf("%d",&nowpoint);
        if(wran[0]<nowpoint)
            wran[2]=wran[1],wran[1]=wran[0],wran[0]=nowpoint;
        else if(wran[1]<nowpoint)
            wran[2]=wran[1],wran[1]=nowpoint;
        else if(wran[2]<nowpoint)
            wran[2]=nowpoint;
    }
    for(int i=0;i<10;i++){
        scanf("%d",&nowpoint);
        if(kran[0]<nowpoint)
            kran[2]=kran[1],kran[1]=kran[0],kran[0]=nowpoint;
        else if(kran[1]<nowpoint)
            kran[2]=kran[1],kran[1]=nowpoint;
        else if(kran[2]<nowpoint)
            kran[2]=nowpoint;
    }
    for(int i=0;i<3;i++)
        wsum+=wran[i],ksum+=kran[i];
    printf("%d %d\n",wsum,ksum);
    return 0;
}

Measured memory_bytes: 1188
#include <bits/stdc++.h>
typedef unsigned long long ull;
typedef long long ll;
#define __TRUE "Yes"
#define __FALSE "No"
#define cout(x) cout << (x) << endl
#define MAX 100001
using namespace std;

int main() {
  string a,b;
  cin >> a >> b;
  string ans = a+b;
  int ansi = stoi(ans);
  bool flag=false;
  for(int i=1;i*i<=ansi;i++) {
    if(i*i == ansi) {
      flag=true;
      break;
    }
  }
  if(flag) cout(__TRUE);
  else cout(__FALSE);
}

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

using namespace std;

#define NMAX 123456

int main(){

	string S[10]={"NULL",".,!? ","abc","def","ghi","jkl","mno","pqrs","tuv","wxyz"};
	string in;
	int N;

	cin>>N;
	while(N--){
		cin>>in;
		int c;
		if(in[0]=='0') c=0;
		else c=1;
		for(int i=1;i<in.size();i++){
			if(in[i]=='0'){
				if(c!=0){
					cout<<S[in[i-1]-'0'][(c-1)%S[in[i-1]-'0'].size()];
					c=0;
				}
			}
			else c++;
		}
		cout<<endl;
	}

}

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



int main(void)
{
    int MOD = 1000000007;

    int n, m;
    scanf("%d %d", &n, &m);
    int a[m+1];
    for (int i=1; i < m+1; i++) scanf("%d", &a[i]);


    long d[n+1];
    int hole = 1;
    for (int i=1; i <= n; i++){
        if (a[hole] == i && hole <= m){
            d[i] = -1;
            hole++;
        }
        else {
            d[i] = 0;
        }
    }

    d[0] = 1;
    if (d[1] == -1) d[1] = 0;
    else d[1] = 1;
    for (int i=2; i <= n; i++){
        if (d[i] == -1){
            d[i] = 0;
        }
        else if(d[i-1] == 0 && d[i-2] == 0){
            d[n] = 0;
            break;
        }
        else{
            d[i] = d[i-1] + d[i-2];
            d[i] %= MOD;
        }
    }

    printf("%ld\n", d[n]);


    return 0;
} 



Measured memory_bytes: 1280
n = int(input())
haiten = list(map(int, [input() for i in range(n)]))
haiten.sort()
score = sum(haiten)
if score%10 == 0:
    for k, i in enumerate(haiten):
        if i%10 ==0:
            pass
        else:
            del haiten[k]
            score = sum(haiten)
            break
if score%10 == 0:
    print(0)
else:
    print(score)        

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define int long long
int dp[55][55][2600]={};

signed main(){
  int n,a;
  cin>>n>>a;
  int x[50];
  for(int i=0;i<n;i++)cin>>x[i];
  dp[0][0][0]=1;
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      for(int k=0;k<2505;k++){
	dp[i+1][j+1][k+x[i]]+=dp[i][j][k];
	dp[i+1][j][k]+=dp[i][j][k];
      }
    }
  }
  int ans=0;
  for(int i=1;i<=n;i++){
    for(int j=0;j<2505;j++){
      if(j%i)continue;
      if(j/i==a){
	//cout<<i<<" "<<j<<" "<<dp[n][i][j]<<endl;
	ans+=dp[n][i][j];
      }
    }
  }
  cout<<ans<<endl;  
  return 0;
}


Measured memory_bytes: 56448
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i <(n); ++i)
#define REP2(i,x,n) for (int i = x; i <(n); ++i)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using P = pair<int,int>;
static const double PI = acos(-1);



//--------------------------------------//
//N <= 10^4
//x*x + y*y + z*z + x*y + y*z + z*x = n
// x,y,z <=100
//--------------------------------------//

int main(){
  int n;
  cin >> n;
  vector<int> a(10001);
  for(int x = 1; x <= 100; x++){
    for(int y = 1; y <= 100; y++){
      for(int z = 1; z <= 100; z++){
        int f =  x*x + y*y + z*z + x*y + y*z + z*x;
        if(f <= 10000) ++a[f];
      }
    }
  }

  REP2(i,1,n+1) cout << a[i] << endl;
}


Measured memory_bytes: 3644
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<string>
#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;

int main(){

long long L,R;
cin >> L >> R;

long long Answer=2019;
long long  Ans;
long long a,b;

if(R-L>=2019){
    Answer=0;
}
else{
        for(int i=L;i<=R;i++){

            for(int k=L;k<=R;k++){
                if(i==k){
                    continue;
                }
                else{
                a=i%2019;
                Ans=(a*k)%2019;
                }
            Answer=min(Ans,Answer);
            }


        }
}
   


    
cout <<Answer<<endl;

 return 0;
}

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

int main(){
  int N;
  cin >> N;
  for(int i = 1;i < N+1;i++){
    int ANS = 0;
    for(int j = 1; j*j <= i;j++){
        for(int k = 1;(j+k) * (j+k) - j * k <= i ;k++){
          for(int l = 1;(j+k+l) * (j+k+l) - j * k - k * l - j * l <= i;l++){    
            if((j+k+l) * (j+k+l) - j * k - k * l - j * l == i){
               ANS++;
              }
          }  
       }
    }
    cout << ANS << endl;
  }

}


  

Measured memory_bytes: 3620
inf = 2**60
'''
def table(size, init): #配列生成
  x = len(size)
  l = [init for i in range(size[x-1])]
  for i in range(x-1):
    l = [l for k in range(size[x-2-i])]
  return l
'''

n, W = map(int, input().split())
w, v = [[0]*n for i in range(2)]
for i in range(n):
  w[i], v[i] = map(int, input().split())

dp = [[-1] * (W+1) for i in range(n+1)]
dp[0][0] = 0

for i in range(n):
  for j in range(W+1):
    if dp[i][j] != -1:
      dp[i+1][j] = max(dp[i][j], dp[i+1][j])
      if j+w[i] <= W:
        dp[i+1][j+w[i]] = max(dp[i][j] + v[i], dp[i+1][j+w[i]])

print(max(dp[n]))

Measured memory_bytes: 120172
import std.stdio;
import std.algorithm;
import std.array;
bool is_prime(int x)
{
	for (int i=2;i*i<=x;i++) if (x%i==0) return false;
	return x!=1;
}
int[] make_primes()
{
	int[] a;
	for (int i=5;i<=55555;++i) if (is_prime(i)) a~=i;
	return a;
}
void main()
{
	int n;
	readf("%d",&n);
	int[] ans=make_primes.filter!(x=>x%5==1).array;
	writef("%(%s %)",ans[0..n]);
}

Measured memory_bytes: 316
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author KY2001
 */


#include "bits/stdc++.h"
#define int long long
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(obj) begin(obj), end(obj)
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define LOWER_BOUND(A, key) distance(A.begin(), lower_bound(ALL(A), key))
#define UPPER_BOUND(A, key) distance(A.begin(), upper_bound(ALL(A), key))

using namespace std;
using ll      = long long;
const int MOD = (int)(1e9 + 7);
const int INF = (int)(1e13 + 7);

int bpm(int x, int y) {
  if (x == 0)
    return 0;
  else if (y == 0) {
    return 1;
  }
  int ans = 1;
  x %= MOD;
  int digit = (int)((log((double)y) / log((double)2) / 1 + 1));
  for (int i = 0; i < digit; i++) {
    if (((y >> i) & 1u) == 1) {
      ans *= x;
      ans %= MOD;
    }
    x = x * x;
    x %= MOD;
  }
  return ans;
}

class CShoppingStreet {
public:
  int solve(std::istream &cin, std::ostream &cout) {
    int N;
    cin >> N;
    vector<vector<int>> F(N, vector<int>(10));
    rep(i, N) {
      rep(j, 10) {
        cin >> F[i][j];
      }
    }
    vector<vector<int>> P(N, vector<int>(11, 0));
    rep(i, N) {
      rep(j, 11) {
        cin >> P[i][j];
      }
    }
    int ans = -INF;
    rep(i, 1 << 10) {
      if (i == 0)
        i++;
      int temp_ans = 0;
      rep(j, N) {
        int num = 0;
        rep(k, 10) {
          if (F[j][k] && (i >> k) & 1) {
            num += 1;
          }
        }
        temp_ans += P[j][num];
      }
      ans = max(ans, temp_ans);
    }
    cout << ans << endl;
  }
};


signed main() {
	CShoppingStreet solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

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

    if (a < 1200) {
      System.out.println("ABC");
    } else {
      System.out.println("ARC");
    }
  }
}


Measured memory_bytes: 21844
#include <stdio.h>
int main(void){
	
	int a,b,c;
	
	scanf("%d %d %d",&a,&b,&c);
	
	
	
	if(a < b && a < c && b < c){
		printf("Yes\n");
	}else{
		printf("No\n");
	}
}

Measured memory_bytes: 1008
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line = "";

		int[][] price = new int[3][26];
		//
		for (int i = 0; i < 3; i++) {
			for (int j = 1; j < 26; j++) {
				switch (i) {
					case 0:
						price[i][j] = price[i][j - 1] + 380;
						if (j % 5 == 0) {
							price[i][j] -= 380;
						}
						break;
					case 1:
						price[i][j] = price[i][j - 1] + 550;
						if (j % 4 == 0) {
							price[i][j] -= 330;
						}
						break;
					case 2:
						price[i][j] = price[i][j - 1] + 850;
						if (j % 3 == 0) {
							price[i][j] -= 306;
						}
						break;
				}
			}
		}

		while ((line = br.readLine()) != null && !line.isEmpty()) {
			int n = Integer.parseInt(line);
			if (n == 0) {
				break;
			}
			int min = Integer.MAX_VALUE;
			for (int i = 0; i < n / 200 + 1; i++) {
				for (int j = 0; j < n / 300 + 1; j++) {
					for (int k = 0; k < n / 500 + 1; k++) {
						if (i * 200 + j * 300 + k * 500 == n) {
							int sum = price[0][i] + price[1][j] + price[2][k];
							if (sum < min) {
								min = sum;
							}
						}
					}
				}
			}
			System.out.println(min);
		}
	}
}

Measured memory_bytes: 18432
#pragma region template 2.4
#include <bits/stdc++.h>
using namespace std;
template <typename T>
using pq_asc = priority_queue<T, vector<T>, greater<T>>;
typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> ii;
typedef vector<ii> vii;
typedef vector<string> vs;
#define REP(i, n) for (ll i = 0; i < (n); ++i)
#define REP1(i, n) for (ll i = 1; i <= (n); ++i)
#define FOR(i, a) for (auto &i : a)
#define CH(f, x, y) x = f(x, y)
#define IN(T, x) \
    T x;         \
    cin >> x;
#define AIN(T, a, n) \
    vector<T> a(n);  \
    FOR(i, a)        \
    cin >> i;
#define A2IN(T1, a, T2, b, n) \
    vector<T1> a(n);          \
    vector<T2> b(n);          \
    REP(i, n)                 \
    cin >> a[i] >> b[i];
#define OUT(x) cout << (x) << endl;
#define FOUT(x) cout << fixed << setprecision(15) << (x) << endl;
#define ALL(a) (a).begin(), (a).end()
#define SORT(a) sort(ALL(a))
#define RSORT(a) \
    SORT(a);     \
    reverse(ALL(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define DUMPA(a)          \
    cout << #a << " = {"; \
    JOUT(ALL(a), ", ", cout) << "}" << endl;

template <typename T>
ostream &JOUT(T s, T e, string sep = " ", ostream &os = cout)
{
    if (s != e)
    {
        os << *s;
        ++s;
    }
    while (s != e)
    {
        os << sep << *s;
        ++s;
    }
    return os;
}

ostream &YES(bool cond, string yes = "Yes", string no = "No", ostream &os = cout)
{
    if (cond)
    {
        os << yes << endl;
    }
    else
    {
        os << no << endl;
    }
    return os;
}

template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p)
{
    os << '(' << p.first << ", " << p.second << ')';
    return os;
}

template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v)
{
    os << '[';
    JOUT(ALL(v), ", ", os) << ']';
    return os;
}

const ll INF = 1e18;
const ll MOD = 1e9 + 7;
#pragma endregion template

int main()
{
    IN(ll, N);
    AIN(ll, A, N);
    ll ans = 1;
    double p = 1;
    ll M = 1e18;
    FOR(a, A)
    {
        p *= a;
        if (a == 0)
        {
            ans = 0;
            break;
        }
        else if (ans != -1 and p <= M + 1 and ans * a <= M)
        {
            ans *= a;
        }
        else
        {
            ans = -1;
        }
    }
    OUT(ans);
}


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

#define ed cout << "\n";
#define speed                         \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define ll long long
#define ffor(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(i, n) ffor(i, 0, n)
#define All(obj) (obj).begin(), (obj).end()
#define INF ((ll)1e9 + 7)
#define c(a) cout << a << "\n";
using namespace std;
const int N = 100005;
ll gcd(ll a, ll b)
{
    return (b ? gcd(b, a % b) : a);
}
int main()
{
    speed;
    cout << fixed << setprecision(10);
    /*start*/
    int n;
    cin >> n;
    if (n % 2 == 0)
    {
        c(n / 2);
    }
    else
    {
        c(n / 2 + 1);
    }
    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using ll = long long;

int main(){
    string S;
    cin >> S;
    int N = S.size();
    ll sum = 0;
    int cnt = 0;
    for(int i = 0; i < N; i++){
        if(S[i] == 'B') cnt++;
        else sum += cnt;
    }
    cout << sum << endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <unordered_map>
#include <utility>
#include <algorithm>
#include <set>
#include <cmath>
#include <array>
#include <bitset>
using namespace std;
typedef long long ll;
const ll mod=1000000007;
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,n) for(int i=1;i<n+1;i++)
int main(){
    int N;
    ll W;
    cin>>N>>W;
    ll d[101][100001];
    rep(i,100001) d[0][i] = -1;
    d[0][0] = 0;
    int v;
    ll w;
    Rep(i,N){
        cin>>w>>v;
        for(int val=0;val<v;val++) d[i][val] = d[i-1][val];
        for(int val=v;val<100001;val++){
            if (d[i-1][val] == -1 && d[i-1][val-v] == -1)d[i][val] = -1;
            else if(d[i-1][val] == -1) d[i][val] = d[i-1][val-v] + w;
            else if(d[i-1][val-v] == -1) d[i][val] = d[i-1][val];
            else d[i][val] = min(d[i-1][val-v] + w, d[i-1][val]);
        }
    }
    for(int val = 100000;val>-1;val--){
        if(d[N][val] != -1 && d[N][val] <= W){
            cout<<val;
            return 0;
        }
        // if(d[N][val]!=-1){
        //     cout<<val<<" "<<d[N][val]<<endl;
        // }
    }
    return 0;
}

Measured memory_bytes: 79104
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc=new Scanner(System.in);
		
		int n=sc.nextInt();		//n個の整数
		
		for(int i=0;i<n;i++) {		//n個回す
			int a=sc.nextInt();
		    if(a%2==0&&a%3!=0&&a%5!=0){
			      System.out.println("DENIED");
			        return;
		    }
		}
		  System.out.println("APPROVED");

		sc.close();
	}
	
}

Measured memory_bytes: 21844
import java.util.Scanner;

public class Main {

	static long bignum = 1000000000+7;

	public static void main(String[] args){

		Scanner sc = new Scanner(System.in);
		
		int x = sc.nextInt();
		long[] fives = new long[200];
		
		for(int i=0;i<200;i++) {
			fives[i]=(long)i*i*i*i*i; 
		}
		
		boolean found = false;
		int a = 0;
		int b = 0;
		
		for(int i =0;i<200;i++) {//sum
			for(int j = 0;j<200;j++) {
				if(fives[i]+fives[j]==x) {
					a = i;
					b = -j;
					found = true;
					break;
				}
			}
		}
		if(!found) {
			for(int i =0;i<200;i++) {//sum
				for(int j = i;j<200;j++) {
					if(-fives[i]+fives[j]==x) {
						a = j;
						b = i;
						found = true;
						break;
					}
				}
			}
		}
		System.out.println(a+" "+b);
	}

	static long divn(int target, int times) {//10_9+7のあまり累乗版
		int sqtimes = (int)Math.sqrt(times);
		long ans = 1;
		for(int i =0;i<sqtimes;i++) {
			ans = (ans * target)%(1000000000+7);
		}
		long holder = ans;
		ans = 1;
		for(int i =0;i<sqtimes;i++) {
			ans = (ans*holder)%(1000000000+7);
		}
		for(int i=0;i<times - sqtimes*sqtimes;i++) {
			ans = (ans * target)%(1000000000+7);
		}
		return ans;
	}

	static long div(long a) {//10_9+7のあまり
		if(a<0)a+=1000000000+7;
		return a%(1000000000+7);
	}

}
/*
class City{
	int order;
	int prefecture;
	int year;
	int number;
	City(int order,int prefecture, int year){
		this.order = order;
		this.prefecture = prefecture;
		this.year = year;
	}
}
*/


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

using namespace std;
using namespace __gnu_pbds;

#define ll                 long long
#define LL                 long long
#define pii                pair<int, int>
#define pll                pair<ll, ll>
#define pil                pair<int, ll>
#define pli                pair<ll, int>
#define vi                 vector<int>
#define vl                 vector<ll>
#define vii                vector<pii>
#define vll                vector<pll>
#define vil                vector<pil>
#define vli                vector<pli>
#define pb                 push_back
#define mp                 make_pair
#define ff                 first
#define ss                 second
#define sz(x)              (int)x.size()
#define TN                 typename
#define all(v)             v.begin(), v.end()
#define fill(a, b)         memset(a, b, sizeof(a))
#define endl               '\n'
#define Int                in()
#define Long               Lin()
#define policy_set         tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define policy_multiset    tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>

template <TN T> T gcd(T a, T b) {return !b ? a : gcd(b, a % b);}
template <TN T> T lcm(T a, T b) {return a * (b / gcd(a, b));}
template <TN T> inline void smin(T &a, T b) {a = a < b ? a : b;}
template <TN T> inline void smax(T &a, T b) {a = a > b ? a : b;}

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {cout << endl ;}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cerr << *it << " = " << a << ", " ;
    err(++it, args...);
}

inline int in() {int n; scanf("%d", &n); return n;}
inline ll Lin() {ll n; scanf("%lld", &n); return n;}
inline double Din() {double n; scanf("%lf", &n); return n;}

const int mod        = (int)1e9 + 7;
const ll  Mod        = (ll)1e9 + 7;

inline int add(int a, int b) {a += b; return a >= mod ? a - mod : a;}
inline int sub(int a, int b) {a -= b; return a < 0 ? a + mod : a;}
inline int mul(int a, int b) {return (ll)a * b % mod;}

const int inf        = (int)2e9 + 5;
const ll  Inf        = (ll)1e18 + 5;
const int N          = 2e5 + 5;



int solve() {
    long long int a,b,c,d;
    cin>>a>>b>>c>>d;
    long long int ans=-1e18;
    ans=max(ans,a*c);
    ans=max(ans,a*d);
    ans=max(ans,b*c);
    ans=max(ans,b*d);
    cout<<ans<<endl;
    return 0;
}

int main() {
    //ios_base::sync_with_stdio(false); cin.tie(NULL);
    int test = 1, tc = 0;
    //scanf("%d", &test);
    //cin >> test;
    while (test--) {
        //printf("Case %d: ", ++tc);
        solve();
    }
    return 0;
}

Measured memory_bytes: 3564
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
#define rng(a) a.begin(),a.end()
using namespace std;
using ll = long long;


int main() {
  int n;
  cin >> n;
  int num[10][10];
  memset(num,0,sizeof(num));
  for(int i = 1; i <= n; i++) {
    string s = to_string(i);
    num[s[0]-'0'][i%10]++;
  }
  ll ans = 0;
  for(int i = 1; i <= 9; i++) {
    for(int j = 1; j <= 9; j++) ans += num[i][j]*num[j][i];
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3784
#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <list>

using namespace std;

typedef pair<long long int, long long int> P;

long long int INF = 1e18;
int const TREE_SIZE = 1 << 20;
long long int seg_tree[TREE_SIZE] = {};
long long int c_diff[TREE_SIZE] = {}; // 子との差

long long int find(int a, int b, int index, int diff, int l, int r){
	
	// [a, b) の最小値を求める
	
	seg_tree[index] += diff;
	c_diff[index] += diff;
	
	if(r <= a || b <= l){
		return INF;
	}
	if(a <= l && r <= b){
		return seg_tree[index];
	}
	
	long long int ret = INF;
	ret = min(ret, find(a, b, index * 2, c_diff[index], l, (l + r) / 2));
	ret = min(ret, find(a, b, index * 2 + 1, c_diff[index], (l + r) / 2, r));
	c_diff[index] = 0;
	return ret;
}

long long int add(int a, int b, int index, int num, int diff, int l, int r){
	
	// [a, b) に num を足す
	
	seg_tree[index] += diff;
	c_diff[index] += diff;
	
	if(r <= a || b <= l){
		//cout << l << " " << r << " " << seg_tree[index] << " " << c_diff[index] << endl;
		return seg_tree[index];
	}
	if(a <= l && r <= b){
		seg_tree[index] += num;
		c_diff[index] += num;
		//cout << l << " " << r << " " << seg_tree[index] << " " << c_diff[index] << endl;
		return seg_tree[index];
	}
	
	long long int ret = INF;
	ret = min(ret, add(a, b, index * 2, num, c_diff[index], l, (l + r) / 2));
	ret = min(ret, add(a, b, index * 2 + 1, num, c_diff[index], (l + r) / 2, r));
	c_diff[index] = 0;
	//cout << l << " " << r << " " << ret << endl;
	return seg_tree[index] = ret;
}

int main(){
	
	int n, q;
	cin >> n >> q;
	
	for(int i = 0; i < q; i++){
		long long int num, a, b, c;
		cin >> num;
		if(num == 0){
			cin >> a >> b >> c;
			add(a, b + 1, 1, c, 0, 0, TREE_SIZE / 2);
		}else{
			cin >> a >> b;
			cout << find(a, b + 1, 1, 0, 0, TREE_SIZE / 2) << endl;
		}
	}
	
	return 0;
}


Measured memory_bytes: 6284
N = int(input())
T = [0]
X = [0]
Y = [0]
for _ in range(N):
    t, x, y = map(int, input().split())
    T.append(t)
    X.append(x)
    Y.append(y)
for i in range(1, N + 1):
    dr = abs(X[i] - X[i-1]) + abs(Y[i] - Y[i-1])
    dt = T[i] - T[i-1]
    if dr > dt or (dr - dt) % 2:
        print("No")
        exit()
print("Yes")


Measured memory_bytes: 11832
package main

import "fmt"

func main() {
  var n int
  var k int
  fmt.Scan(&n, &k)
  k2 := k*2
  // 0 ≦ x,y ≦ 2K に圧縮
  squares := make([][]int, k2)
  for i := range squares {
    squares[i] = make([]int, k2)
  }
  for i := 0; i < n; i++ {
    var x int
    var y int
    var color string
    fmt.Scan(&x, &y, &color)
    // 'W'はY方向にKずらした'B'と同値
    if color == "W" {
      y += k
    }
    squares[x % k2][y % k2]++ 
  }
  // 計算量削減のために累積和を事前算出
  for i := 0; i < k2; i++ {
    for j := 1; j < k2; j++ {
      squares[i][j] += squares[i][j-1]
    }      
  }
  for j := 0; j < k2; j++ {
    for i := 1; i < k2; i++ {
      squares[i][j] += squares[i-1][j]
    }
  }  
  max_ := 0
  end := k2-1
  for i := 0; i < k; i++ {
    for j := 0; j < k; j++ {
      // ex) k = 2
      //      ■ □ □ ■ 
      //  j+k □ ■ ■ □
      //      □ ■ ■ □
      //    j ■ □ □ ■
      //      i   i+k
      cnt :=
      (squares[i][j]) +
      (squares[end][j] - squares[i+k][j]) +
      (squares[i+k][j+k] - squares[i+k][j] - squares[i][j+k] + squares[i][j]) +
      (squares[i][end] - squares[i][j+k]) +
      (squares[end][end] - squares[end][j+k] - squares[i+k][end] + squares[i+k][j+k])
      max_ = max(max(cnt, n - cnt), max_)
    }
  }  
  fmt.Print(max_)
}

func max(a int, b int) int {
  if a > b {
    return a
  } else {
    return b
  }
}

Measured memory_bytes: 45184
#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int ans=0;

int n,k;
int p[100005];
vector<int> al[100005];

int dfs(int i,int __p){
    int depth=0;
    for (auto &it:al[i]){
        if (it==__p) continue;
        depth=max(depth,dfs(it,i)+1);
    }
    
    if (p[i]!=1 && depth==k-1){
        ans++;
        return -1;
    }
    else return depth;
}

int main(){
    scanf("%d%d",&n,&k);
    for (int x=1;x<=n;x++) scanf("%d",&p[x]);
    
    if (p[1]!=1) p[1]=1,ans++;
    
    for (int x=2;x<=n;x++){
        al[p[x]].push_back(x);
        al[x].push_back(p[x]);
    }
    
    dfs(1,-1);
    
    printf("%d\n",ans);
}

Measured memory_bytes: 12416
# -*- coding: utf-8 -*-
from sys import stdin

ns = lambda: stdin.readline() # s = ns()
ni = lambda: int(stdin.readline()) # N = ni()
na = lambda: list(map(int, stdin.readline().split())) # Arr = na()

arr = na()
if 2 in arr:
    print('No')
else:
    print('Yes')


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

 using namespace std;
 typedef long long ll;

 int main() {
   string S;

   cin >> S;

   string ans = "Yes", hi = "hi";

   while (S.length() > 0) {
     if (S.length() % 2 == 1) {
       ans = "No";
       break;
     }
     if (S.substr(S.length() - 2, 2) == hi) {
       S = S.substr(0, S.length() - 2);
     }
     else {
       ans = "No";
       break;
     }
   }

   cout << ans << endl;
 }


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		double xa,ya,xb,yb,xc,yc,xp,yp;
		double abc, abp, bcp, cap;

		while(sc.hasNext()){
			xa = sc.nextDouble();
			ya = sc.nextDouble();
			xb = sc.nextDouble();
			yb = sc.nextDouble();
			xc = sc.nextDouble();
			yc = sc.nextDouble();
			xp = sc.nextDouble();
			yp = sc.nextDouble();			
			abc = calculate_area(xa,ya,xb,yb,xc,yc);
			abp = calculate_area(xa,ya,xb,yb,xp,yp);
			bcp = calculate_area(xb,yb,xc,yc,xp,yp);
			cap = calculate_area(xc,yc,xa,ya,xp,yp);

//			System.out.println(abc +"\n"+ abp +"\n"+ bcp +"\n"+ cap);

			if(abc-(abp+bcp+cap) == 0){
				System.out.println("YES");
			} else {
				System.out.println("NO");
			}
		}
	}

	static double calculate_area(double x1, double y1, double x2, double y2, double x3, double y3){
		double result;
		result = 0.5 * ((x3-x1)*(y2-y1)-(y3-y1)*(x2-x1));
		if(result < 0) result*=-1;
		return result;
	}
}

Measured memory_bytes: 23160