akhauriyash/Code-Regression huggingface dataset:
n, k = gets.to_s.split.map{|t|t.to_i}
s = gets.to_s.chomp

a = []
s.scan(/(1*)(0*)/) do 
   a << $1.size
   a << $2.size
end
a.flatten!

ans = t = a[0, 2*k+1].reduce(0){|s,t| s+t }
i = 2
while i+2*k < a.length
  t = t - a[i-1] - a[i-2] + a[i+2*k-1] + a[i+2*k]
  ans = t if ans < t
  i += 2
end
 
puts ans

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

class Point
{
    public double x;
    public double y;
    public Point(double x = 0.0, double y = 0.0)
    {
        this.x = x;
        this.y = y;
    }
}

class Program
{
    static List<Point> Koch(int n, Point p1, Point p2)
    {
        List<Point> res = new List<Point>();
        res.Add(p1);
        KochSub(n, res, p1, p2);
        res.Add(p2);
        return res;
    }

    static void KochSub(int n, List<Point> plist, Point p1, Point p2)
    {
        if (n == 0) return;
        Point s = new Point((p1.x * 2.0 + p2.x) / 3.0, (p1.y * 2.0 + p2.y) / 3.0);
        Point t = new Point((p1.x + p2.x * 2.0) / 3.0, (p1.y + p2.y * 2.0) / 3.0);
        Point u = new Point();
        u.x = (t.x - s.x) * Math.Cos(Math.PI / 3.0) - (t.y - s.y) * Math.Sin(Math.PI / 3.0) + s.x;
        u.y = (t.x - s.x) * Math.Sin(Math.PI / 3.0) + (t.y - s.y) * Math.Cos(Math.PI / 3.0) + s.y;
        KochSub(n - 1, plist, p1, s);
        plist.Add(s);
        KochSub(n - 1, plist, s, u);
        plist.Add(u);
        KochSub(n - 1, plist, u, t);
        plist.Add(t);
        KochSub(n - 1, plist, t, p2);
    }

    public static void Main(string[] args)
    {
        int n = int.Parse(Console.ReadLine());
        List<Point> res = Koch(n, new Point(0.0, 0.0), new Point(100.0, 0.0));
        for (int i = 0; i < res.Count; i++) Console.WriteLine("{0:F8} {1:F8}", res[i].x, res[i].y);
    }
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull; 
typedef vector<int> vi;
typedef pair<int,int> pi;

#define F first
#define S second
#define PB push_back
#define MP make_pair
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define SQ(a) (a)*(a)

template <class T, class U> ostream& operator<< (ostream &out, pair<T,U> c) { out << "(" << c.first << " "; out << c.second << ")"; return out; }
template <class T> ostream& operator<< (ostream &out, vector<T> c) { for (auto it = c.begin(); it != c.end(); ++it) { if (it != c.begin()) out << " "; out << *it; } return out; }
template <class T> ostream& operator<< (ostream &out, set<T> c) { for (auto it = c.begin(); it != c.end(); ++it) { if (it != c.begin()) out << " "; out << *it; } return out; }
const double PI  = 3.141592653589793238463;


int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    string s, t;
    cin >> s >> t;
    sort(s.begin(),s.end());
    sort(t.begin(),t.end());
    reverse(t.begin(),t.end());
    if(t > s){
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;

main() {
    int64_t n;
    cin >> n;

    string s;
    cin >> s;

    vector<int64_t> w;
    w.push_back(0);
    for (auto c : s) {
        w.push_back(w.back());
        if (c == '.') {
            ++w.back();
        }
    }

    int64_t m = numeric_limits<int64_t>::max();
    for (auto i : irange(0L, n + 1)) {
        auto mm = (i - w[i]) + (w.back() - w[i]);
        m = min(m, mm);
    }

    cout << m << endl;
}

Measured memory_bytes: 2680
#include <cstdio>
#include <cstring>
#include <vector>
#include <string>
#include <algorithm>

#define rep(i, n) for(int i = 0; i < (n); ++i)

using namespace std;

int n;
char s[10001];

int dfs(int p, int q){
	// printf("%s\n", string(s + p, s + q).c_str());

	if(s[p] != '['){
		return (atoi(string(s + p, s + q).c_str()) + 1) / 2;
	}

	vector<int> v;
	int c = 0;
	int a = p + 1, b = p + 1;
	while(a < q){
		while(s[b] != ']' || c > 0){
			if(s[b] == '['){
				++c;
			}
			else if(s[b] == ']'){
				--c;
			}
			++b;
		}
		v.push_back(dfs(a, b));
		b += 2;
		a = b;
	}
	sort(v.begin(), v.end());
	int k = 0;
	rep(i, (v.size() + 1) / 2){
		k += v[i];
	}
	return k;
}

int main(){
	scanf("%d", &n);
	rep(i, n){
		scanf("%s", s);
		printf("%d\n", dfs(1, strlen(s) - 1));
	}
	return 0;
}

Measured memory_bytes: 1116
import java.util.*;

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

        int X = sc.nextInt();
        int Y = sc.nextInt();
        int Z = sc.nextInt();
        int K = sc.nextInt();

        CakeSet.A = new long[X];
        CakeSet.B = new long[Y];
        CakeSet.C = new long[Z];

        for (int a = 0; a < X; a++) {
            CakeSet.A[a] = sc.nextLong();
        }
        for (int b = 0; b < Y; b++) {
            CakeSet.B[b] = sc.nextLong();
        }
        for (int c = 0; c < Z; c++) {
            CakeSet.C[c] = sc.nextLong();
        }

        Arrays.sort(CakeSet.A);
        Arrays.sort(CakeSet.B);
        Arrays.sort(CakeSet.C);

        TreeSet<CakeSet> cakeSets = new TreeSet<>();
        cakeSets.add(new CakeSet(X - 1, Y - 1, Z - 1));

        for (int k = 0; k < K; k++) {
            CakeSet first = cakeSets.first();
            cakeSets.remove(first);
            System.out.println(first.getTaste());

            int a = first.getA();
            int b = first.getB();
            int c = first.getC();

            if (a > 0) {
                cakeSets.add(new CakeSet(a - 1, b, c));
            }
            if (b > 0) {
                cakeSets.add(new CakeSet(a, b - 1, c));
            }
            if (c > 0) {
                cakeSets.add(new CakeSet(a, b, c - 1));
            }
        }
    }

    public static class CakeSet implements Comparable {
        public static long A[];
        public static long B[];
        public static long C[];

        private int a;
        private int b;
        private int c;
        private long taste;

        public CakeSet(int a, int b, int c) {
            this.a = a;
            this.b = b;
            this.c = c;
            this.taste = A[a] + B[b] + C[c];
        }

        public long getTaste() {
            return taste;
        }

        public int getA() {
            return a;
        }

        public int getB() {
            return b;
        }

        public int getC() {
            return c;
        }

        @Override
        public String toString() {
            return "CakeSet{" +
                    "a=" + a +
                    ", b=" + b +
                    ", c=" + c +
                    ", taste=" + taste +
                    '}';
        }

        @Override
        public int compareTo(Object o) {
            CakeSet cakeSet2 = (CakeSet) o;

            long diffTaste = getTaste() - cakeSet2.getTaste();
            if (diffTaste > 0) return -1;
            if (diffTaste < 0) return 1;

            int diffA = getA() - cakeSet2.getA();
            int diffB = getB() - cakeSet2.getB();
            int diffC = getC() - cakeSet2.getC();

            return (diffA != 0) ? -diffA : ((diffB != 0) ? -diffB : -diffC);
        }
    }
}


Measured memory_bytes: 30492
function main(input) {
    var args = input.trim().split(/\r\n|\n/);
    var N = Number(args[0].trim());
    var Ps = args[1].trim().split(" ").map(v => Number(v.trim()));

    var targets = [];
    for(var i = 0; Ps.length > i; i++) {
        if (i + 1 !== Ps[i]) {
            targets.push(Ps[i - 1]);
        }

        if (targets.length > 2) {
            console.log("NO");
            return;
        };
    }
    console.log("YES");
}

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

Measured memory_bytes: 7372
#include <iostream>
#include <cstdio>
using namespace std;
int main(){
  int a,b,c,d;
  int n;
  while(cin >> n,n){
    int sum = 0;
    for(int i = 0 ; i < n ; i++ ){
      cin >> a >> b >> c >> d;
      int m = a+b+c;
      if(m <= 60 && d <= 2){
	sum += 600;
      }else if(m <= 80 && d <= 5){
	sum += 800;
      }else if(m <= 100 && d <= 10){
	sum += 1000;
      }else if(m <= 120 && d <= 15){
	sum += 1200;
      }else if(m <= 140 && d <= 20){
	sum += 1400;
      }else if(m <= 160 && d <= 25){
	sum += 1600;
      }
    }
    cout << sum << endl;
  }
}

Measured memory_bytes: 1160
import java.util.*;

public class Main {
    public static void main(String[] args)  {
        // Your code here!
        Scanner sc = new Scanner(System.in);	
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = Math.max(a+b,a-b);
        int ans = Math.max(a * b, c);
        
        System.out.println(ans);
    }
}

Measured memory_bytes: 21844
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE TypeSynonymInstances #-}

import Control.Applicative
import Control.DeepSeq
import Control.Monad
import Control.Monad.ST
import qualified Data.Array as A
import qualified Data.Array.IArray as IA
import qualified Data.Array.IO as AI
import qualified Data.Array.MArray as MA
import qualified Data.Array.ST as STA
import qualified Data.Array.Unboxed as AU
import Data.Bits
import qualified Data.ByteString.Char8 as BS
import Data.Char
import qualified Data.Graph as G
import Data.Int
import qualified Data.IntMap as IM
import qualified Data.IntSet as IS
import Data.List
import qualified Data.Map.Strict as M
import Data.Maybe
import Data.Ord
import qualified Data.Sequence as SQ
import qualified Data.Set as S
import Data.Time
import qualified Data.Tree as T
import qualified Data.Vector as V
import qualified Data.Vector.Mutable as VM
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM

readInt :: IO [Int]
readInt = map (fst . fromJust . BS.readInt) . BS.words <$> BS.getLine

readInts :: Int -> IO [[Int]]
readInts n = replicateM n readInt

readInteger :: IO [Integer]
readInteger = map (fst . fromJust . BS.readInteger) . BS.words <$> BS.getLine

readIntegers :: Int -> IO [[Integer]]
readIntegers n = replicateM n readInteger

readString :: IO [String]
readString = map BS.unpack . BS.words <$> BS.getLine

readStrings :: Int -> IO [[String]]
readStrings n = replicateM n <$> readString

toPair :: [a] -> (a, a)
toPair [x, y] = (x, y)

count :: Eq a => a -> [a] -> Int
count a as = length $ filter (== a) as

put :: Show a => a -> IO ()
put = putStr . show

putLn :: Show a => a -> IO ()
putLn = print

putList :: Show a => [a] -> IO ()
putList [n] = put n
putList (n:ns) = do
  put n
  putStr " "
  putList ns

putStrList :: [String] -> IO ()
putStrList [n] = putStr n
putStrList (n:ns) = do
  putStr n
  putStr " "
  putStrList ns

yesNoUpper b
  | b = putStrLn "YES"
  | otherwise = putStrLn "NO"

yesNo b
  | b = putStrLn "Yes"
  | otherwise = putStrLn "No"

main = do
  [n, l] <- readInt
  s <- replicateM n getLine
  putStrLn $ solve s

solve s = foldl1 (++) $ sort s

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

int main() {
    int n, m;
    cin >> n >> m;
    vector<vector<int>> a(n, vector<int>(2));
    vector<vector<int>> c(m, vector<int>(2));
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < 2; j++) cin >> a[i][j];
    }
    for (int i = 0; i < m; i++) {
        for (int j = 0; j < 2; j++) cin >> c[i][j];
    }
    int s;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            if (j == 0) s = abs(a[i][0]-c[j][0]) + abs(a[i][1]-c[j][1]);
            else {
                if (s > abs(a[i][0]-c[j][0]) + abs(a[i][1]-c[j][1])) {
                    s = abs(a[i][0]-c[j][0]) + abs(a[i][1]-c[j][1]);
                }
            }
        }
        for (int j = 0; j < m; j++) {
            if (s == (abs(a[i][0]-c[j][0]) + abs(a[i][1]-c[j][1]))) {
                cout << j+1 << endl;
                break;
            }
        }
    }
}

Measured memory_bytes: 256
N, T = map(int, input().split())

c = [0] * N
t = [0] * N
for i in range(N):
    c[i], t[i] = map(int, input().split())

if(min(t) > T):
    print("TLE")
    exit()
else:
    ans = 1000
    for i in range(N):
        if t[i] <= T:
            ans = min(ans, c[i])

print(ans)

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

void sol(vector<int>&a,int n,int b,int e,int&mini)
{
  if(b>e)
  return;
  
  int i,m,res;
  m=(b+e)/2;
  
  res=0;
  for(i=0;i<n;++i)
  res+=(m-a[i])*(m-a[i]);
  
  mini=min(mini,res);
  
  sol(a,n,b,m-1,mini);
  sol(a,n,m+1,e,mini);
}

int main()
{
  int n,i,mini=INT_MAX;
  vector<int>a;
  
  cin>>n;
  a.resize(n);
  for(i=0;i<n;++i)
  cin>>a[i];
    
  sort(a.begin(),a.end());
  sol(a,n,a[0],a[n-1],mini);
  
  cout<<mini;
  
  return 0;
} 

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
import collections
import copy
import heapq
from collections import defaultdict
from heapq import heappop, heappush
import itertools
input = sys.stdin.readline

##### リストの 二分木検索 #####
# bisect_left(lists, 3)
# bisect_right(lists, 3)

##### プライオリティキュー #####
# heapq.heapify(a) #リストaのheap化
# heapq.heappush(a,x) #heap化されたリストaに要素xを追加
# heapq.heappop(a) #heap化されたリストaから最小値を削除＆その最小値を出力

# heapq.heappush(a, -x) #最大値を取り出す時は、pushする時にマイナスにして入れよう
# heapq.heappop(a) * (-1) #取り出す時は、-1を掛けて取り出すこと

##### タプルリストのソート #####
# sorted(ans) #(a, b) -> 1st : aの昇順, 2nd : bの昇順
# sorted(SP, key=lambda x:(x[0],-x[1])) #(a, b) -> 1st : aの昇順, 2nd : bの降順
# sorted(SP, key=lambda x:(-x[0],x[1])) #(a, b) -> 1st : aの降順, 2nd : bの昇順
# sorted(SP, key=lambda x:(-x[0],-x[1])) #(a, b) -> 1st : aの降順, 2nd : bの降順

# sorted(SP, key=lambda x:(x[1])) #(a, b) -> 1st : bの昇順
# sorted(SP, key=lambda x:(-x[1])) #(a, b) -> 1st : bの降順

def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))

def main():
	N,K = inputMap()
	H = inputList()
 
	H.sort()
	H = H[::-1]
 
	ans = 0
	for i,vol in enumerate(H):
		if K > 0:
			K -= 1
			#print(K)
			continue
		ans += vol
 
	print(ans)



if __name__ == "__main__":
	main()


Measured memory_bytes: 82160
def main():
    h, w, k = map(int, input().split())
    c = [list(input()) for _ in range(h)]
    hp, wp = [], []
    def dfs_h(hl):
        if len(hl) == h:
            hp.append(hl)
            return
        dfs_h(hl + [0])
        dfs_h(hl + [1])
    
    def dfs_w(wl):
        if len(wl) == w:
            wp.append(wl)
            return
        dfs_w(wl + [0])
        dfs_w(wl + [1])
    
    dfs_h([])
    dfs_w([])
    
    ans = 0
    for fh in hp:
        for fw in wp:
            num = 0
            for hi, i in enumerate(fh):
                if i == 1:
                    continue
                for wi, j in enumerate(fw):
                    if j == 1:
                        continue
                    if c[hi][wi] == "#":
                        num += 1
            if num == k:
                ans += 1
    print(ans)
                    
            
            
            

if __name__ == "__main__":
    main()

Measured memory_bytes: 67980
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())

struct S {
    ll a, b, c;
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    const ll inf = LONG_LONG_MAX / 2 - 1;
    ll n, ma, mb;
    cin >> n >> ma >> mb;
    vector<S> s(n);
    ll suma = 0, sumb = 0;
    rep(i, n) {
        cin >> s[i].a >> s[i].b >> s[i].c;
        suma += s[i].a;
        sumb += s[i].b;
    }
    vector<vector<vector<ll>>> dp(n + 1, vector<vector<ll>>(suma + 1, vector<ll>(sumb + 1, inf)));
    dp[0][0][0] = 0;
    ll ans = inf;
    rep(i, n) {
        rep(j, suma + 1) {
            rep(k, sumb + 1) {
                dp[i + 1][j][k] = dp[i][j][k];
                if ((j >= s[i].a) && (k >= s[i].b) && (dp[i][j - s[i].a][k - s[i].b] != inf)) {
                    dp[i + 1][j][k] = min(dp[i + 1][j][k], dp[i][j - s[i].a][k - s[i].b] + s[i].c);
                }
                if ((dp[i + 1][j][k] != inf) && (j != 0) && (k != 0) && (j % ma == 0) && (k % mb == 0) && ((j / ma) == (k / mb))) {
                    ans = min(ans, dp[i + 1][j][k]);
                }
            }
        }
    }
    if (ans == inf) ans = -1;
    cout << ans << endl;
    return 0;
}


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

#define fr first
#define se second

using namespace std;

const long long N = 2e5 + 7;
const long long inf = 1e9 + 7;
const long long mod = 1e9 + 7;

int main()
{
    ios_base::sync_with_stdio(false);

    int n;
    cin >> n;
    int cnt = 0, mn = inf;
    for(int i = 1; i <= n; i ++){
        int x;
        cin >> x;
        cnt += (x <= mn);
        mn = min(mn, x);
    }
    cout << cnt << "\n";
}



Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <functional>
#include <cstdio>
#include <climits>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

int main() {
    int H, W;
    cin >> H >> W;
    vector<string> a(H, string(W, ' '));
    for (int i = 0; i < H; i++) {
        cin >> a[i];
    }

    set<int> row, col;
    for (int i = 0; i < H; i++) {
        row.insert(i);
    }
    for (int j = 0; j < W; j++) {
        col.insert(j);
    }
    for (int i = 0; i < H; i++) {
        bool remove = true;
        for (int j = 0; j < W; j++) {
            if (a[i][j] != '.') {
                remove = false;
                break;
            }
        }
        if (remove) {
            row.erase(i);
        }
    }
    for (int j = 0; j < W; j++) {
        bool remove = true;
        for (int i = 0; i < H; i++) {
            if (a[i][j] != '.') {
                remove = false;
                break;
            }
        }
        if (remove) {
            col.erase(j);
        }
    }

    for (auto& i : row) {
        for (auto& j : col) {
            cout << a[i][j];
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.util.stream.Collectors;
import java.io.*;
import java.nio.charset.StandardCharsets;

public class Main {
	public static void main(String[] args) throws IOException {
		InputStreamReader reader = new InputStreamReader(System.in, StandardCharsets.UTF_8);
		BufferedReader in = new BufferedReader(reader);
		Main ins = new Main(in);
		ins.calc();
		ins.showResult();
	}

	Main(BufferedReader in) throws IOException {
		String S = in.readLine();
		System.out.println(S.substring(0, 3));
	}

	void calc() {
	}

	void showResult() {
	}
}

Measured memory_bytes: 32720
#include<stdio.h>
int main()
{
	int a,b,max;
	scanf("%d%d",&a,&b);
	max=a+b;
	if(a-b>max) max=a-b;
	if(a*b>max) max=a*b;
	printf("%d",max);
	return 0;
 } 

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

int main() {
  int M, D; cin >> M >> D;
  int ans = 0;
  for(int i = 22; i <= D; ++i) {
    int d = i % 10, dd = i / 10;
    if(d < 2 || dd < 2) continue;
    for(int j = 1; j <= M; ++j) {
      if(d * dd == j) ans++;
    }
  }
  std::cout << ans << std::endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <string.h>
using namespace std;

long int MOD = 1000000007;

int main(){
    int n,m;
    cin >> n >> m;
    int* a_arr = (int*)malloc(sizeof(int)*m);
    for (int i = 0; i < m; i++)
    {
        cin >> a_arr[i];
    }

    long int* patterns = (long int*)malloc(sizeof(long int)*(n+1));
    patterns[0] = 1;//0step目
    int i = 1;
    int j = 0;
    while (i<=n)
    {
        patterns[i] = (patterns[i-1]+(i==1 ? 0 : patterns[i-2]))%MOD;
        if (a_arr[j]==i)
        {
            patterns[i] = 0;
            j++;//a1=1のときに注意．境界のケース．大丈夫だと思っても一応確認してみる
        }
        
        i++;
    }

    cout << patterns[n] << endl;

    return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using ll = long long;
const ll MOD = 1e9+7; int INF=INT_MAX; ll LLINF = 1LL << 60;
const vector<int> d8x = {1, 0, -1, 0, 1, -1, -1, 1}; vector<int> d8y = {0, 1, 0, -1, 1, 1, -1, -1};
const vector<int> d4x = {1, 0, -1, 0}; vector<int> d4y = {0, 1, 0, -1};

//

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

    sort(all(a));
    sort(all(b));
    sort(all(c));

    ll ans=0;
    rep(j,n){
        auto lb=lower_bound(all(a),b[j]);
        auto ub=upper_bound(all(c),b[j]);
        ll dl = distance(a.begin(),lb);
        ll du = distance(ub,c.end());
        ans+=dl*du;
    }
    cout<<ans<<endl;
}


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

struct UnionFind{
    vector<int> d;//d[i]:iの親の番号。根なら木のサイズ*(-1)
    UnionFind(int n=0):d(n,-1){}//全ての木のサイズが１と初期.n点
    
    int find(int x){//根を返す
    if(d[x] < 0) return x;//xが根の時はxを返す
    return d[x] = find(d[x]);
    }

    bool unite(int x,int y){//xとyの木をつなげたらtrue.大きい方に小さい方をつなげる.
    x = find(x);y = find(y);//根を求める
    if(x==y) return false;//同じ木に属していたらつなげる必要なし
    if(d[x]>d[y]) swap(x,y);//yの方がサイズが大きい時は交換する
    d[x] += d[y];//サイズの更新
    d[y] = x;//根の更新
    return true;
    }

    bool same(int x,int y){return find(x)==find(y);}//xとyが同じ木にあるか

    int size(int x){return -d[find(x)];}//xの木のサイズを返す
};

int main(){
int n,q;
cin >> n >> q;
vector<int>p(n);
UnionFind tree(n);//////////////////定義の仕方
for (int i = 0; i <n; i++)
{
    cin>>p[i];
}

for(int i=0;i<q;i++){
    int x,y;cin>>x>>y;
    tree.unite(x-1,y-1);
}
int cnt=0;
for (int i = 0; i < n; i++)
{
    if(tree.same(p[i]-1,i)) {cnt++;}
}

cout << cnt << endl;
return 0;
}



Measured memory_bytes: 1024
#include<iostream>
using namespace std;
int main(){
  int n;
  while(cin>>n,n){
    int h[101][101];
    for(int i=0;i<=n;i++){
      cin>>h[i][0];
      for(int j=1;j<=h[i][0];j++)cin>>h[i][j];
    }
    int m[101]={};
    for(int i=1;i<=h[n][0];i++)
      for(int j=0;j<n;j++)
	for(int k=1;k<=h[j][0];k++)
	  if(h[j][k]==h[n][i])m[j]++;
    int cnt=0,ans;
    for(int i=0;i<n;i++)
      if(m[i]==h[n][0]){
	cnt++;
	ans=i+1;
      }
    
    if(cnt==1)cout<<ans<<endl;
    else cout<<-1<<endl;
  }
  return 0;
}

Measured memory_bytes: 3072
#include<bits/stdc++.h>
	using namespace std;
	#define ll long long
	#define vv vector<ll>
	#define pp pair<ll,ll>
	#define ff first
	#define ss second
	#define vp vector<pp>
	#define ld long double
	#define pb push_back
	#define mp make_pair
	const ll mod=7+1e9;
	const ll N=400004;
	bool prime[N];
	void isprime()
	{
		memset(prime,true,N);
		for(ll i=2;i*i<N;i++)
		{
			if(prime[i]==true)
			{
				for(ll j=i*i;j<N;j+=i)
				{
					prime[j]=false;
				}
			}
		}
	}
	ll power(ll a,ll n)
	{
		ll ans=1;
		a=a%mod;
		while(n>0)
		{
			if(n&1)
			{
				ans=(ans*a)%mod;
			}
			n=n>>1;
			a=(a*a)%mod;
		}
		return ans;
	}
	
	bool comp(pair<pair<string,ll>,ll> const &a,pair<pair<string,ll>,ll> const &b)
	{
		if(a.ff.ff==b.ff.ff)
		{
			return a.ff.ss>b.ff.ss;
		}
		return a.ff.ff < b.ff.ff;
	}
	
	
	int main() 
	{
		ios_base::sync_with_stdio(false);
	    cin.tie(NULL);
	    ll n;
	    cin>>n;
	    ll k=n;
	    ll h=1;
	    vector<pair<pair<string,ll>,ll> > g;
	    while(n--)
	    {
	    	
	    	string s;
	    	ll j;
	    	cin>>s;
	    	cin>>j;
	    	g.pb(mp(mp(s,j),h));
	    	h++;
		}
		sort(g.begin(),g.end(),comp);
		for(ll i=0;i<k;i++)
		{
			cout<<g[i].ss<<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;
using ll = long long;
using P = pair<int,int>;

int main() {
    int H, W, m;
    cin >> H >> W >> m;
    map<int, int> hmp, wmp;
    map<P, int> x;
    int hmax = 0, wmax = 0;
    int indh = 0, indw = 0;
    rep(i,m) {
        int h, w;
        cin >> h >> w;
        h--; w--;
        x[P(h,w)]++;
        hmp[h]++;
        if (hmp[h] > hmax) {
            //indh = h;
            hmax = hmp[h];
        }
        wmp[w]++;
        if (wmp[w] > wmax) {
            //indw = w;
            wmax = wmp[w];
        }
    } 
    vector<int> hm, wm;
    rep(i,H) {
        if (hmp[i] == hmax) hm.push_back(i);
    }
    rep(i,W) {
        if (wmp[i] == wmax) wm.push_back(i);
    }
    int ans = hmax + wmax;
    rep(i,hm.size())rep(j,wm.size()) {
        if (x[P(hm[i],wm[j])] != 1) {
            cout << ans << endl;
            return 0; 
        }
    }
    cout << ans-1 << endl;
    return 0;
}

Measured memory_bytes: 54220
#include<stdio.h>

int main(void){
	
	int i,j,data[5],l;
	
	for(i=0;i<5;i++){
		scanf("%d",&data[i]);
	}
	
	for(i=0;i<5;i++){
		for(j=0;j<5;j++){
			if(data[i]>data[j]){
				l=data[i];
				data[i]=data[j];
				data[j]=l;
			}
		}
	}
	
	for(i=0;i<4;i++){
		printf("%d ",data[i]);
	}
	
	printf("%d\n",data[4]);
	
	return 0;
}

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

class Main{
	static int imax=Integer.MAX_VALUE;
	static long lmax=Long.MAX_VALUE;
	
	public static void main(String[] args) throws FileNotFoundException{
		
		Scanner sc=new Scanner(System.in);
		int n=readI(sc);
		int[] num=readlnI(sc," ");
		int mn=1000; int mx=0;
		for(int i=0;i<n; i++){
			if(mn>num[i]) mn=num[i];
			if(mx<num[i]) mx=num[i]; 
		}
		puts(mx-mn);
		}//main_end
	
	//utility
	static int readI(Scanner sc){
		return Integer.parseInt(sc.nextLine().trim());
	}
	static long readL(Scanner sc){
		return Long.parseLong(sc.nextLine().trim());
	}
	static String readS(Scanner sc){
		return sc.nextLine().trim();
	}
	static int[] readlnI(Scanner sc, String dl){
		return Arrays.stream(sc.nextLine().trim().split(dl)).mapToInt(Integer::parseInt).toArray();
	}
	static long[] readlnL(Scanner sc, String dl){
		return Arrays.stream(sc.nextLine().trim().split(dl)).mapToLong(Long::parseLong).toArray();
	}
	static String[] readlnS(Scanner sc, String dl){
		return sc.nextLine().trim().split(dl);
	}
	@SuppressWarnings("unchecked")
	static <T> void puts(T... args){
		for(int i=0; i<args.length-1; i++){
			System.out.printf("%s ",args[i]);
		}
		System.out.println(args[args.length-1]);
	}
	static void puts(int[] ary){
		for(int i=0; i<ary.length-1; i++){
			System.out.printf("%d ",ary[i]);
		}
		System.out.println(ary[ary.length-1]);
	}
	static void puts(long[] ary){
		for(int i=0; i<ary.length-1; i++){
			System.out.printf("%d ",ary[i]);
		}
		System.out.println(ary[ary.length-1]);
	}
	static void bs(){
		System.out.println("");
	}
	static void tblSort(int[][] tbl){
		Arrays.sort(tbl, new Comparator<int[]>(){
			@Override
			public int compare(int[] a, int[] b){
				if(a[0]==b[0]){
					return b[1]-a[1];
				}else{
					return b[0]-a[0];
				}
			}
		});
	}
}


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

int main()
{
    int numa, numb;
    scanf("%d %d",&numa,&numb);
    char str[110][110];
    for(int i=0;i<numa;i++){;
        scanf("%s",str[i]);
    }
    for(int i=0;i<numb+2;i++){
        printf("#");
    }
    printf("\n");
    for(int i=0;i<numa;i++){
        printf("#%s#\n",str[i]);
    }
    for(int i=0;i<numb+2;i++){
        printf("#");
    }
    printf("\n");
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define ff first
#define ss second
using namespace std;
typedef pair<int,int> pii;
const int N=100005;

int n,m,tot;
int vis[N],low[N];
vector<int>G[N];
vector<pii>ans;

void dfs(int u,int p) {
    vis[u]=low[u]=++tot;
    for (int v:G[u]) {
        if (v==p) continue;
        if (!vis[v]) {
            dfs(v,u);
            low[u]=min(low[u],low[v]);
            if (low[v]>vis[u]) ans.pb({min(u,v),max(u,v)});
        }
        low[u]=min(low[u],low[v]);
    }
}

int main() {
    ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    cin>>n>>m;
    while (m--) {
        int u,v; cin>>u>>v,
        G[u].pb(v),
        G[v].pb(u);
    }
    for (int i=0;i<n;++i) if (!vis[i]) dfs(i,-1);
    sort(ans.begin(),ans.end());
    for (auto p:ans) cout<<p.ff<<' '<<p.ss<<'\n';
}


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

#define IL inline 
IL int read() {
	char ch = getchar(); int u = 0, f = 1;
	while (!isdigit(ch)) { if (ch == '-') f = -1; ch = getchar(); }
	while (isdigit(ch)) { u = (u << 1) + (u << 3) + ch - 48; ch = getchar(); }
	return u * f; 
}

const int maxn = 1e5 + 10;
char s[maxn]; int n;
int a[maxn];
IL void Solve(char inx) {
	for (int i = 1; i <= n; ++i) 
		if (s[i] == inx) a[i] = 1;
		else a[i] = -1;
	int Min = 0, pos = 0;
	int Sum = 0;
	for (int i = 1; i <= n; ++i) {
		Sum += a[i]; 
		if (Sum > Min && pos != i - 1) { cout << pos + 1 << " " << i << endl; exit(0); }
		if (Sum < Min) {
			Min = Sum;
			pos = i;
		}
	}
}
int main() {
	scanf("%s", s + 1);
	n = strlen(s + 1);
	for (char i = 'a'; i <= 'z'; ++i) 
		Solve(i);
	puts("-1 -1");
	return 0;
}	

Measured memory_bytes: 768
def solve():
    N = int(input())
    a = list(map(int, input().split()))
    
    cumsum = [0] * (N + 1)
    for i in range(N):
        cumsum[i + 1] = cumsum[i] + a[i]
    
    ans = 10 ** 10
    for i in range(1, N):
        ans = min(ans, abs(cumsum[i] - (cumsum[N] - cumsum[i])))
    print(ans)


if __name__ == '__main__':
    solve()


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

using namespace std;

const long long mod = 1e9 + 7ll ;

long long modpower(long long a , long long b)
{
    if(b == 0)
        return 1ll ;
    long long x = modpower(a , b / 2ll) ;
    x = (x * x) % mod ;
    if(b & 1)
        return (x * a) % mod ;
    return (x % mod) ;
}

struct combination
{
    vector<long long>fact , inv ;
    combination(int sz) : fact(sz + 1) , inv(sz + 1)
    {
        fact[0] = 1ll ;
        inv[0] = 1ll ;
        for(long long i = 1 ; i <= sz ; ++i)
        {
            fact[i] = (fact[i-1] * i) % mod ;
            inv[i] = modpower(fact[i] , mod - 2ll) ;
        }
    }
    long long choose(int n , int k) const
    {
        if(k < 0 || n < k)
            return 0 ;
        return ((((fact[n] * inv[k]) % mod) * inv[n - k]) % mod) ;
    }
};

combination comb(2e5+2) ;

int main()
{
    int n , m , a , b;
    cin>>n>>m>>a>>b ;
    int nowx = n-a ;
    long long sum = 0ll ;
    /*for(int i = 1 ; i <= b ; ++i)
    {
        long long x = (comb.choose(n-nowx + m-i , a-1ll) - sum + mod) % mod ;
        sum = (sum + x) % mod ;
    }*/
    /*long long cnt = 0ll ;
    for(int i = 1 ; i <= b ; ++i)
    {
        long long x = (comb.choose(nowx-1ll + i-1ll , i-1ll) - cnt + mod) % mod ;
        x = x * (comb.choose(n-nowx + m-i , (m-i)) - cnt + mod % mod) % mod ;
        sum = (sum + x) % mod ;
        cnt++ ;
    }*/
    long long ans = 0ll ;
    for(int i = b+1 ; i <= m ; ++i)
    {
        long long x = (comb.choose(nowx-1ll + i-1ll , i-1ll))%mod ;
        long long y = (comb.choose(n-nowx-1+m-i , m-i)) % mod ;
        ans = (ans + ((x * y) % mod)) % mod ;
        ans = (ans % mod) ;
    }
    return cout<<ans<<"\n" , 0 ;
}


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

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

        Arrays.sort(a);
        
        System.out.println(a[0] + " " + a[1] + " " + a[2]);
    }
}

Measured memory_bytes: 26088
N, M = gets.split.map(&:to_i)

cs = readlines.map.with_index(1){|l, i| [i, *l.split.map(&:to_i)]}.sort_by{|i, p, y| y}
       .group_by{|i, p, y| p}.values.flat_map{|a| a.map.with_index(1){|(i, p, y), j| [i, p, j]}}.sort
cs.each{|i, p, j| printf "%06d%06d\n", p, j}

Measured memory_bytes: 41148
import math

EPS = 1e-10

def equals(a, b):
    return abs(a - b) < EPS


class Point:
    def __init__(self, x=0, y=0):
        self.x = x
        self.y = y

    def __add__(self, p):
        return Point(self.x + p.x, self.y + p.y)

    def __sub__(self, p):
        return Point(self.x - p.x, self.y - p.y)

    def __mul__(self, a):
        return Point(self.x * a, self.y * a)

    def __rmul__(self, a):
        return self * a

    def __truediv__(self, a):
        return Point(self.x / a, self.y / a)

    def norm(self):
        return self.x * self.x + self.y * self.y

    def abs(self):
        return math.sqrt(self.norm())

    def __lt__(self, p):
        if self.x != p.x:
            return self. x < p.x
        else:
            return self.y < p.y

    def __eq__(self, p):
        return equals(self.x, p.x) and equals(self.y, p.y)


class Segment:
    def __init__(self, p1, p2):
        self.p1 = p1
        self.p2 = p2


def dot(a, b):
    return a.x * b.x + a.y * b.y


def cross(a, b):
    return a.x * b.y - a.y * b.x


def ccw(p0, p1, p2):
    a = p1 - p0
    b = p2 - p0
    if cross(a, b) > EPS:
        return 'COUNTER_CLOCKWISE'
    if cross(a, b) < -EPS:
        return 'CLOCKWISE'
    if dot(a, b) < -EPS:
        return 'ONLINE_BACK'
    if a.norm() < b.norm():
        return 'ONLINE_FRONT'
    return 'ON_SEGMENT'


if __name__ == '__main__':
    x0, y0, x1, y1 = [int(v) for v in input().split()]
    p0 = Point(x0, y0)
    p1 = Point(x1, y1)
    q = int(input())
    ans = []
    for i in range(q):
        x2, y2 = [int(v) for v in input().split()]
        p2 = Point(x2, y2)
        ans.append(ccw(p0, p1, p2))

    for v in ans:
        print(v)


Measured memory_bytes: 5880
n, m, x = map(int, input().split())
squares = list(map(int, input().split()))

left_cost = 0
right_cost = 0
for square in squares:
    if square < x:
        left_cost = left_cost + 1
    else:
        right_cost = right_cost + 1

print(min(right_cost, left_cost))


Measured memory_bytes: 9076
input_num = [int(input()) for i in range(4)]

coin_list = input_num[0:3]
result_yen = input_num[3]

count = 0

for yen_500 in range(coin_list[0]+1):
    for yen_100 in range(coin_list[1]+1):
        for yen_50 in range(coin_list[2]+1):
            if result_yen == yen_500*500 + yen_100*100 + yen_50 *50:
                count += 1
                
print(count)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int n,k,s;

int main(){
	cin>>n>>k;
	int h[n+5];
	for(int i=1;i<=n;i++)
	    cin>>h[i];
	for(int i=1;i<=n;i++)
	    if(h[i]>=k)
	        s++;
	cout<<s;
	return 0;
} 

Measured memory_bytes: 640
import numpy as np
H, W=map(int, input().split())
S=[]
for i in range(H):
  s=list(input())
  S.append(s)
S=np.array(S)  
vec=[(0,1),(1,0),(0,-1),(-1,0)]
ok=True
for i in range(H):
  for j in range(W):
    now=S[i,j]
    if now=="#":
      suround=False
      for dx,dy in vec:
        nx,ny=i+dx,j+dy
        if 0<=nx and nx<H and 0<=ny and ny<W:
          if S[nx,ny]=="#":
            suround=True
      if not suround:
        ok=False
        break
if ok:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 12432
local mma = math.max
local n, t = io.read("*n", "*n")
local a, b = {}, {}
for i = 1, n do
  a[i], b[i] = io.read("*n", "*n")
end

local function solve()
  if t == 1 then
    local t1ret = b[1]
    for i = 2, n do
      t1ret = mma(t1ret, b[i])
    end
    return t1ret
  end
  local totret = 0
  local tail = {}
  for i = 1, n do
    tail[i] = {}
    for j = 1, t - 1 do
      tail[i][j] = 0
    end
  end
  local curmax = 0
  for i = n, 1, -1 do
    for j = 1, curmax do
      tail[i][j] = mma(tail[i][j], tail[i + 1][j])
      if j + a[i] < t then
        tail[i][j + a[i]] = mma(tail[i][j + a[i]], tail[i + 1][j] + b[i])
        curmax = mma(curmax, j + a[i])
      end
    end
    if a[i] < t then
      tail[i][a[i]] = mma(tail[i][a[i]], b[i])
      curmax = mma(curmax, a[i])
    end
  end
  local head = {}
  for i = 1, t - 1 do
    head[i] = 0
  end
  curmax = 0
  for i = 1, n - 1 do
    local headmax = {}
    headmax[1] = head[1]
    for j = 2, t - 1 do
      headmax[j] = mma(head[j], headmax[j - 1])
    end
    local tailmax = {}
    tailmax[1] = tail[i + 1][1]
    for j = 2, t - 1 do
      tailmax[j] = mma(tail[i + 1][j], tailmax[j - 1])
    end
    local iret = 0
    if 1 < t then iret = mma(headmax[t - 1], tailmax[t - 1]) end
    for j = 1, t - 2 do
      iret = mma(iret, headmax[j] + tailmax[t - 1 - j])
    end
    iret = iret + b[i]
    totret = mma(totret, iret)
    for j = t - 1 - a[i], 1, -1 do
      head[j + a[i]] = mma(head[j + a[i]], head[j] + b[i])
    end
    if a[i] < t then
      head[a[i]] = mma(head[a[i]], b[i])
    end
  end
  do -- i == n
    local headmax = {}
    headmax[1] = head[1]
    for j = 2, t - 1 do
      headmax[j] = mma(head[j], headmax[j - 1])
    end
    local iret = 1 < t and headmax[t - 1] or 0
    iret = iret + b[n]
    totret = mma(totret, iret)
  end
  return totret
end
print(solve())


Measured memory_bytes: 230784
n, m = map(int, input().split())
if n >= m:
    print(0)
    exit()
l = list(map(int, input().split()))
l.sort()
t = l[0]
a = []
for i in l[1:]:
    a.append(i-t)
    t = i
a.sort(reverse=True)
print(sum(a[n-1:]))

Measured memory_bytes: 13968
#pragma GCC optimize("O3")

#include "bits/stdc++.h"
#include "ext/pb_ds/tree_policy.hpp"
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/rope"

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

typedef long long ll;
typedef pair<int, int> pii;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define F0R(i, a) for(int i = 0; i < (a); ++i)
#define pb push_back
#define sz size
#define f first
#define s second

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

struct custom_hash 
{
    static uint64_t splitmix64(uint64_t x) 
    {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const 
    {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
vector<ll> factors(ll x) 
{
    vector <ll> result;
    ll i = 1;
    while(i*i <= x) 
    {
        if(x % i == 0) 
        {
            result.pb(i);
            if(x/i != i) 
            {
                result.pb(x/i);
            }
        }
        i++;
    }
    return result;
}

int main()
{
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n;
    cin >> n;
    vector<ll> fac = factors(n);
    ll res = 0;
    F0R(i, fac.sz())
    {
        if(fac[i] > sqrt(n) + 1)
        {
            res += fac[i] - 1;
        }
    }
    cout << res;
    return 0;
}

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

int main(){
    int n;
    cin >> n;
    int R[n];
    
    for(int m = 0; m < n; m++){
        int o;
        cin >> o;
        R[m] = o;
    }
    
    int minv = R[0];
    int maxv = -1000000000;
    
    for(int j = 1; j < n; j++){
        maxv = max(maxv, R[j] - minv);
        minv = min(minv, R[j]);
    }
    
    cout << maxv << endl;
    
    return 0;
}


Measured memory_bytes: 3880
#include <stdio.h>
 
int main(void) {
	// your code goes here
	int x,y,a,b;
	scanf("%d",&a);
	scanf("%d",&b);
	x = a*b;
	y = a*2+b*2;
	printf("%d %d\n",x,y);
	return 0;
}


Measured memory_bytes: 2040
from collections import Counter

n, k = map(int, input().split())
dic = Counter(list(map(int, input().split())))
kv = dic.items()
kv = sorted(kv, key=lambda x: x[1])
ans = 0
cnt = 0
while len(kv)-cnt > k:
    ans += kv[cnt][1]
    cnt+=1
print(ans)

Measured memory_bytes: 37780
#include <iostream>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
using namespace std;
int main()
{

	cout << 1 << endl;
	cout << 6 << endl;
	cout << 11 << endl;
	cout << 13 << endl;
	cout << 9 << endl;
	return 0;
}

Measured memory_bytes: 1116
import sys

INPUT = lambda: sys.stdin.readline().rstrip()
INT = lambda: int(INPUT())
LIST = lambda: list(map(int, INPUT().split()))

sys.setrecursionlimit(10 ** 9)


def main():
    N = INT()
    A = LIST()
    InvA = []

    for i in range(N):
        InvA.append(1/A[i])

    print(1/sum(InvA))


if __name__ == '__main__':
    main()


Measured memory_bytes: 38384
#include<iostream>

using namespace std;

int main()
{
    int n, m;
    cin >> n >> m;
    int ans;

    if (n > 0 && m > 0) {
        ans = m * (m - 1) / 2 + n * (n - 1) / 2;
    } else if (m == 0 && n == 0) {
        ans = 0;
    } else if (m == 0) {
        ans = n * (n - 1) / 2;
    } else if (n == 0) {
        ans = m * (m - 1) / 2;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
N=int(input())
P=0
def f(x):
  r=[]
  for i in range(1,int(x**0.5)+1):
    if x%i==0:
      r.append(i)
      if x!=i*i:
        r.append(x//i)
  return r

A=f(N)
M=0
for i in range(len(A)):
  if A[i]==1:
    continue
  M=N
  while M%A[i]==0:
    M//=A[i]
  if M%A[i]==1:
    P+=1
P+=len(f(N-1))-1
print(P)

Measured memory_bytes: 65968
#include <bits/stdc++.h>
using namespace std;
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    long int n,a,b,c,k;
    cin >> a >> b >> c >> k;
    if(k<=a)
        cout << k << endl;
    else if(k<=a+b)
        cout << a << endl;
    else if(k<=a+b+c)
        cout << a-(k-a-b) << endl;
    return 0;    
}

Measured memory_bytes: 3660
#include<iostream>
#include<cstdlib>
#include<complex>
#define EPS 1e-10
using namespace std;

typedef complex<double> Po;


Po p[3],o;

double dot(Po x, Po y){return x.real()*y.real()+x.imag()*y.imag();}

double cross(Po x, Po y){return x.real()*y.imag() - x.imag()*y.real();}

double area(Po a, Po b, Po c){return abs(cross(b-a,c-a))/2;}

bool inter(Po a, Po b, Po c, Po x){
  return (fabs(area(a,b,x)+area(b,c,x)+area(c,a,x)-area(a,b,c)) < EPS);
}

double seg_dis(Po a, Po b, Po c){
  if(dot(b-a,c-a)<EPS)return abs(c-a);
  if(dot(a-b,c-b)<EPS)return abs(c-b);
  return abs(cross(b-a,c-a))/abs(b-a);
}

int main(){
  double x[4],y[4],r;

  for(;;){
    cin >> x[0] >> y[0];
    if(!x[0] && !y[0])break;

    for(int i=1;i<4;i++)cin >> x[i] >> y[i];
    cin >> r;

    for(int i=0;i<3;i++)p[i] = Po(x[i],y[i]);
    o = Po(x[3],y[3]);


    bool f[3];
    for(int i=0;i<3;i++)f[i] = !(abs(o-p[i])>r);
    if(f[0] && f[1] && f[2])cout << "b\n";
    else{
      if(inter(p[0],p[1],p[2],o)){
	for(int i=0;i<3;i++)f[i] = !(seg_dis(p[i],p[(i+1)%3],o)<r);
	if(f[0] && f[1] && f[2])cout << "a\n";
	else cout << "c\n";
      }else{
	for(int i=0;i<3;i++)f[i] = !(seg_dis(p[i],p[(i+1)%3],o)>r);
	if(f[0] || f[1] || f[2])cout << "c\n";
	else cout << "d\n";
      }
    }
  }
}

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

long long INF = LONG_LONG_MAX / 3;
const int N = (int) 1e5 + 5;

int n;
long long c;
long long x[N], v[N];
long long dp[N][2];
// 0: clockwise
// 1: counter - clockwise

void maximize(long long &a, long long b) {
	if (a < b) a = b;
}

void minimize(long long &a, long long b) {
	if (a > b) a = b;
}

int main() {
	//freopen("1.inp", "r", stdin); freopen("1.out", "w", stdout);
	scanf("%d %lld", &n, &c);
	for (int i = 1; i <= n; i++) scanf("%lld %lld", &x[i], &v[i]);
	long long ans = -INF;
	long long temp = 0;
	for (int i = 1; i <= n; i++) {
		temp += v[i];
		temp -= (x[i] - x[i - 1]);
		maximize(ans, temp);
	}
	temp = 0;
	x[n + 1] = c;
	for (int i = n; i >= 1; i--) {
		temp += v[i];
		temp -= (x[i + 1] - x[i]);
		maximize(ans, temp);
	}
	// cout << ans << endl;
	temp = 0;
	dp[n + 1][1] = -INF;
	for (int i = n; i >= 1; i--) {
		temp += v[i];
		temp -= (x[i + 1] - x[i]);
		maximize(dp[i][1], dp[i + 1][1]);
		maximize(dp[i][1], temp);
	}
	temp = 0;
	dp[0][0] = -INF;
	for (int i = 1; i <= n; i++) {
		temp += v[i];
		temp -= (x[i] - x[i - 1]);
		maximize(dp[i][0], dp[i - 1][0]);
		maximize(dp[i][0], temp);
	}
	// for (int i = 1; i <= n; i++) cout << dp[i][0] << " "; cout << endl;
	// for (int i = n; i >= 1; i--) cout << dp[i][1] << " "; cout << endl;
	for (int i = 1; i <= n; i++) {
		maximize(ans, dp[i][0] + dp[i + 1][1] - x[i]);
	}
	for (int i = n; i >= 1; i--) {
		maximize(ans, dp[i][1] + dp[i - 1][0] - (c - x[i]));
	}
	maximize(ans, 0);
	printf("%lld", ans);
	return 0;
}

Measured memory_bytes: 3328
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;

namespace AtCoder.B
{
    public class Program
    {
        public static void Main() { var r = GetResult(); Debug.WriteLine(r); Console.Write(r); }

        private static object GetResult()
        {
            var s = ReadText();
            return s[0].ToString() + (s.Length - 2) + s[s.Length - 1].ToString();
        }

        #region Console.Read

        public static string ReadText() { return Console.ReadLine(); }
        public static List<string> ReadTexts() { return Console.ReadLine().Split(' ').ToList(); }
        public static long ReadLong() { return long.Parse(Console.ReadLine()); }
        public static (long, long) Read2Longs() { var ls = ReadLongs(); return (ls[0], ls[1]); }
        public static (long, long, long) Read3Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2]); }
        public static (long, long, long, long) Read4Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2], ls[3]); }
        public static (long, long, long, long, long) Read5Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2], ls[3], ls[4]); }
        public static List<long> ReadLongs() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList(); }

        #endregion
    }
}


Measured memory_bytes: 25760
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <string>
#include <istream>
 
#define INPUT_FROM_FILE (0)
#if INPUT_FROM_FILE
#include <fstream>
#endif

 int main(int argc, char **argv){
	int n = 0;
	int u = 0;
	int v = 0;
	int k = 0;
	std::vector<int> A;
 
#if INPUT_FROM_FILE
	std::ifstream ifs("test.txt");
#endif
 
 
#if INPUT_FROM_FILE
	ifs >> n;
#else
	std::cin >> n;
#endif

	A.resize(n * n, 0);

	for(int i = 0; i < n; i++){
#if INPUT_FROM_FILE
		ifs >> u >> k;
#else
		std::cin >> u >> k;
#endif
		for(int j = 0; j < k; j++){
#if INPUT_FROM_FILE
			ifs >> v;
#else
			std::cin >> v;
#endif
			A[(u - 1) * n + v - 1] = 1;
		}
	}
 
	for(int r = 0; r < n; r++){
		int offset = r * n;
		std::cout << A[offset];
		for(int c = 1; c < n; c++){
			std::cout << " " << A[offset + c];
		}
		std::cout << std::endl;
	}
    return 0;
}


Measured memory_bytes: 3096
#include <bits/stdc++.h>
using namespace std;
const int MAXH = 85;
const int init = 85 * (85 * 2);
int diff[MAXH][MAXH];
bool dp[MAXH][MAXH][init * 2]; // 赤 - 青 + init

int main()
{
  int H, W, b;
  cin >> H >> W;
  for (int i = 0; i < H; i++)
  {
    for (int j = 0; j < W; j++)
    {
      cin >> diff[i][j];
    }
  }
  for (int i = 0; i < H; i++)
  {
    for (int j = 0; j < W; j++)
    {
      cin >> b;
      diff[i][j] -= b;
    }
  }
  dp[0][0][init + diff[0][0]] = true;
  dp[0][0][init - diff[0][0]] = true;
  for (int i = 0; i < H; i++)
  {
    for (int j = 0; j < W; j++)
    {
      for (int k = 0; k < init * 2; k++)
      {
        if (i - 1 >= 0)
        {
          dp[i][j][k] = dp[i - 1][j][k - diff[i][j]] || dp[i - 1][j][k + diff[i][j]];
        }
        if (j - 1 >= 0)
        {
          dp[i][j][k] = dp[i][j][k] || dp[i][j - 1][k - diff[i][j]] || dp[i][j - 1][k + diff[i][j]];
        }
      }
    }
  }
  int ans = init * 3;
  for (int i = 0; i < init * 2; i++)
  {
    if (dp[H - 1][W - 1][i])
      ans = min(ans, abs(init - i));
  }
  cout << ans << endl;
}


Measured memory_bytes: 184548
#include <stdio.h>

int main (void)
{
	//変数宣言
	int stomach,bought,ate,delicious_limit,safe_limit;//入力
	char str[64]; //標準入力読み取り用
	
	//標準入力読み込み
	fgets(str,sizeof(str),stdin);
	sscanf(str,"%d %d %d",&stomach,&bought,&ate);
	
	delicious_limit = bought - ate;
    safe_limit = delicious_limit + stomach;
	
	//出力
	if(delicious_limit >= 0)
	{
		puts("delicious");
	}else if (safe_limit >= 0)
	{
		puts("safe");
	}else
    {
    	puts("dangerous");
    }
	
	return 0;
}

Measured memory_bytes: 128