akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<string>
#include<set>
#include<climits>
#include<map>
#define ll long long
using namespace std;
int main() {
	ll n, k,sum=0;
	cin >> n >> k;
	vector<ll>l(n);
	for (ll i = 0; i < n; i++) {
		cin >> l[i];
	}
	sort(l.begin(), l.end(),greater<ll>());
	for (ll i = 0; i < k; i++) {
		sum += l[i];
	}
	cout << sum << endl;

}


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

namespace Atcoder
{
    public class Program
    {
        static void Main(string[] args)
        {
            var r = ReadSplit();
            var a = r[0].ToDouble();
            var b = r[1].ToDouble();
            var c = r[2].ToDouble();
            var d = r[3].ToDouble();
            var ta = Math.Ceiling(c / b);
            var ao = Math.Ceiling(a / d);
            var ans = "No";
            if (ta <= ao)
            {
                ans = "Yes";
            }
            WriteRead(ans);
        }

        public static string Read()
        {
            return Console.ReadLine();
        }

        public static string[] ReadSplit()
        {
            return Console.ReadLine().Split(' ');
        }

        public static void WriteRead(object str)
        {
            Console.WriteLine(str);
            Read();
        }

        public static void Write(object str)
        {
            Console.WriteLine(str);
        }

        private static bool ChangeMin<T>(ref T a, T b) where T : IComparable
        {
            if (a.CompareTo(b) > 0)
            {
                a = b;
                return true;
            }
            return false;
        }

        private static bool ChangekMax<T>(ref T a, T b) where T : IComparable
        {
            if (b.CompareTo(a) > 0)
            {
                a = b;
                return true;
            }
            return false;
        }
    }
}


public static class Extentions
{
    public static int ToInt32(this object obj)
    {
        return int.Parse(obj.ToString());
    }

    public static long ToLong(this object obj)
    {
        return long.Parse(obj.ToString());
    }

    public static decimal ToDecimal(this object obj)
    {
        return decimal.Parse(obj.ToString());
    }

    public static double ToDouble(this object obj)
    {
        return double.Parse(obj.ToString());
    }

    public static T2 GetValueZero<T1, T2>(this Dictionary<T1, T2> d, T1 key) where T2 : struct
    {
        T2 value;
        if (d.TryGetValue(key, out value))


        {
            return value;
        }
        return new T2();
    }
}



Measured memory_bytes: 17968
import java.util.Scanner;

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

		int result = (int)Math.ceil((double)h / a);

		System.out.println(result);
	}
}


Measured memory_bytes: 23124
#include<stdio.h>
#include<string.h>
#define len 100000

typedef struct QQ{
  char name[100];
  int time;
} Q;

Q stuff[len];
int head, tail, n;

void enq(Q );
Q deq();
int minmam(int , int );

int main(){
  int e=0, c;
  int i, q;
  Q u;
  scanf("%d %d", &n, &q);

  for(int i=1; i<=n; i++){
    scanf("%s", stuff[i].name);
    scanf("%d", &stuff[i].time);
  }
  head = 1;
  tail = n+1;
  while(head!=tail){
    u = deq();
    c = minmam(q, u.time);
    u.time=u.time-c;
    e=e+c;
    if(u.time > 0) enq(u);
    else{
      printf("%s %d\n", u.name, e);
    }
  }
  return 0;
}





void enq(Q x){
  stuff[tail] = x;
  tail = (tail+1) % len;
}

Q deq(){
  Q x = stuff[head];
  head = (head+1) % len;
  return x;
}

int minmam(int x, int y){
  if(x>y){return y;}
  else{return x;}
}






Measured memory_bytes: 11920
N = int(input())
A = [0] + list(map(int, input().split())) + [0]
S = sum([abs(A[i + 1] - A[i]) for i in range(N + 1)])
for i in range(1, N + 1):
    diff = abs(A[i + 1] - A[i - 1]) - \
        abs(A[i] - A[i - 1]) - abs(A[i + 1] - A[i])
    print(S + diff)


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

class Program
{
    static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        var dic = new Dictionary<char, int>();
        for (int i = 0; i < n; i++)
        {
            string s = Console.ReadLine();
            if (s[0] == 'M' || s[0] == 'A' || s[0] == 'R' || s[0] == 'C' || s[0] == 'H')
            {
                // 存在したら++、しなければ値1で追加
                if (dic.ContainsKey(s[0])) dic[s[0]]++;
                else dic[s[0]] = 1;
            }
        }
        long ans = 0;
        for (int i = 0; i < 1 << dic.Count; i++)
        {
            // ビット演算で3つの掛け算を全部計算
            var bits = new bool[dic.Count];
            int m = 0;
            for (int j = 0; j < dic.Count; j++)
            {
                if ((i >> j & 1) == 1)
                {
                    bits[j] = true;
                    m++;
                }
            }
            if (m == 3)
            {
                long tmp = 1;
                for (int j = 0; j < dic.Count; j++)
                {
                    if (bits[j]) tmp *= dic.ElementAt(j).Value;
                }
                ans += tmp;
            }
        }
        Console.WriteLine(ans);
    }
}

Measured memory_bytes: 15328
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx2")

#include <iostream>
#include <cmath>
#include <algorithm>
#include <functional>
#include <numeric>
#include <vector>
#include <bitset>
#include <deque>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <random>
#include <cassert>

using namespace std;

const int N = 1e6 + 7;

int n;
char a[N];

int d[N];

void build_d() {
	for (int i = 1; i < N; ++i) {
		d[i] = d[i - 1];
		int x = i;
		while (~x & 1) {
			++d[i];
			x >>= 1;
		}
	}
}

int f() {
	build_d();
	int ans = 0;
	for (int i = 0; i < n; ++i) {
		if (a[i]) {
			ans ^= (d[n - 1] == d[i] + d[n - 1 - i]);
		}
	}
	return ans;
}

signed main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	cin >> n;
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
		a[i] -= '1';
	}
	if (count(a, a + n, 1) == 0) {
		for (int i = 0; i < n; ++i) {
			a[i] /= 2;
		}
		cout << f() * 2 << '\n';
	}
	else {
		for (int i = 0; i < n; ++i) {
			a[i] %= 2;
		}
		cout << f() << '\n';
	}
	//system("pause");
	return 0;
}

Measured memory_bytes: 5120
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define N 4
#define T 1
#define F 0

int dx[4] = {0,-1,0,1}, dy[4] = {1,0,-1,0}, limit, t[N][N];

void swap(int *x,int *y)
{
  int tmp = *x;

  *x = *y;
  *y = tmp;

  return;
}

int Heuristic()
{
  int i, j, sum = 0, x;

  for(i = 0; i < N; i++)
    for(j = 0; j < N; j++){
      if(t[i][j] == 0)
	continue;
      x = t[i][j] -1;
      sum += abs(x/4-i) + abs(x%4-j);
    }

  return sum;
}

int dfs(int depth, int prev, int py, int px)
{
  int i, h, tx, ty;
  h = Heuristic();
  if (h == 0)
    return T;
  if (depth+h > limit)
    return F;
  for (i = 0; i < 4; i++){
    if(abs(i-prev) == 2)
      continue;
    tx=px+dx[i];
    ty=py+dy[i];
    if(tx < 0 || ty < 0 || tx >= N || ty >= N)
      continue;
    swap(&t[ty][tx],&t[py][px]);
    if(dfs(depth+1,i,ty,tx))
      return T;
    swap(&t[ty][tx],&t[py][px]);
  }
  return F;
}

void issolved(int py,int px)
{
  for(limit = 0;; limit++)
    if(dfs(0,99,py,px)){
      printf("%d\n",limit);
      return;
    }
}

int main()
{
  int i,j,px,py;

  for(i = 0; i < N; i++)
    for(j = 0; j < N; j++){
      scanf("%d",&t[i][j]);
      if(t[i][j] == 0){
        py = i;
        px = j;
      }
    }
  issolved(py,px);
  
  return 0;
}



Measured memory_bytes: 2084
#include<iostream>
using namespace std;
int main()
{int n;
 cin>>n;
 int a[n];
 float r,s=0.0;
 for(int i=0;i<n;i++)
 {cin>>a[i];
  s=s+(float)1/a[i];
 }
 r=(float)1/s;
 cout<<r;
 return 0;}
 

Measured memory_bytes: 256
using System;
using System.Collections.Generic;

namespace abc172_c
{
  class Program
  {
    static void Main(string[] args)
    {
      var N = CIn.ReadInt();
      var M = CIn.ReadInt();
      var K = CIn.ReadInt();
      var A = CIn.ReadIntArray(N);
      var B = CIn.ReadIntArray(M);

      var sumA = new long[N + 1];

      for (int i = 0; i < N; i++)
      {
        sumA[i + 1] = sumA[i] + A[i];
      }

      var sumB = 0L;

      var max = 0;

      for (int i = 0; i <= M; i++)
      {
        if (i > 0) sumB += B[i - 1];
        if (K < sumB) break;
        var bs = Array.BinarySearch(sumA, K - sumB);
        if (bs < 0) bs = (~bs) - 1;
        max = Math.Max(max, bs + i);
      }

      Console.WriteLine(max);
    }
  }

  static class CIn
  {
    private static readonly Queue<string> fieldBuffer = new Queue<string>();

    public static string Read()
    {
      if (fieldBuffer.Count == 0)
      {
        foreach (var field in Console.ReadLine().Split())
        {
          fieldBuffer.Enqueue(field);
        }
      }
      return fieldBuffer.Dequeue();
    }

    public static int ReadInt() => int.Parse(Read());
    public static long ReadLong() => long.Parse(Read());
    public static double ReadDouble() => double.Parse(Read());

    public static string[] ReadStringArray(int n)
    {
      var array = new string[n];
      for (var i = 0; i < n; i++)
      {
        array[i] = Read();
      }
      return array;
    }

    public static int[] ReadIntArray(int n)
    {
      var array = new int[n];
      for (var i = 0; i < n; i++)
      {
        array[i] = ReadInt();
      }
      return array;
    }

    public static long[] ReadLongArray(int n)
    {
      var array = new long[n];
      for (var i = 0; i < n; i++)
      {
        array[i] = ReadLong();
      }
      return array;
    }

    public static double[] ReadDoubleArray(int n)
    {
      var array = new double[n];
      for (var i = 0; i < n; i++)
      {
        array[i] = ReadDouble();
      }
      return array;
    }

    public static char[,] ReadCharMatrix(int h, int w)
    {
      var array = new char[h, w];
      for (var i = 0; i < h; i++)
      {
        var l = Console.ReadLine().ToCharArray();
        for (var j = 0; j < w; j++)
        {
          array[i, j] = l[j];
        }
      }
      return array;
    }
  }
}


Measured memory_bytes: 73560
#include<stdio.h>

int main(void){
  
  char s[4];
  char swap;
  
  scanf("%s",s);
  
  if(s[2]==0){
    
	printf("%s\n",s);
    
  }else
  {
    swap=s[0];
    
    s[0]=s[2];
    
    s[2]=swap;
  
    printf("%s\n",s);
    
  }
  
  return 0;
  
}
    

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

//vector…可変長、データの大きさに合わせてサイズを変える
//list…双方向リスト、要素を挿入、削除の多いとき
//forward_list
//array…固定長配列
//set…集合
//multiset
//bitset…2進数、固定長ビット列
//map…連想配列、キーと値を関連付ける
//multimap
//deque
//stack…FILO
//queue…FIFO
//priority_queue
//pair…二つの値を一組
//tuple…複数の値を一組

template<typename T>
void remove(std::vector<T>& vector, unsigned int index) {
    vector.erase(vector.begin() + index);
}

template<class T>
T ma(std::vector<T> &v) {
    T maxi = 0;
    for(auto &i:v) maxi = max(maxi, i);
    return maxi;
}

template<class T>
T mi(std::vector<T> &v) {
    T mini = 0;
    for(auto &i:v) mini = min(mini, i);
    return mini;
}

template <class T>
T pow(T x, T y, T n = numeric_limits<T>::max()) {
    if(y == 0) return 1;
    if(y % 2 == 0) return pow((x * x) % n, y / 2);
    return (x * pow(x, y - 1)) % n;
}

#define rep(i, n, m) for (int i = n; i <= m; i++)
#define Rep(i, n, m) for (int i = m; i >= 1; i--)

typedef long long ll;
typedef unsigned long long ull;

ull ans = 0;
/*
int gcd(int x, int y) {
    if (x < y) swap(x, y);
    return !y ? x : gcd(x % y, y);
}
*/
int main() {
    vector<unsigned int> c(3);
    unsigned int r = 0, b = 0, g = 0;
    ll n;
    rep(i, 0, 2) cin >> c[i];
    cin >> n;

    sort(c.begin(), c.end());

    for (int i = n / c[0]; i >= 0; i--) {
        for (int j = n - i; j >= 0; j--) {
            if (n - (i * c[0] + j * c[1]) >= 0 && (n - (i * c[0] + j * c[1])) % c[2] == 0) {
                ans++;
            }
        }
    }

    cout << ans;
}

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

using namespace std;

int main() {
    string s;
    cin >> s;

    int res = 0;
    for (int i = 0; i < 6; i++) {
        if (s[i] == '1') {
            res++;
        }
    }

    cout << res << endl;
}


Measured memory_bytes: 3588
#include <stdio.h>

int main(void)
{
	char a[100][101], b[102][102];
	int h, w;
	int i, j;
	
	scanf("%d %d", &h, &w);
	for (i = 0; i < h; i++) {
		scanf("%s", a[i]);
	}
	
	for (i = 0; i < h + 2; i++) {
		for (j = 0; j < w + 2; j++) {
			b[i][j] = '#';
		}
	}
	for (i = 0; i < h; i++) {
		for (j = 0; j < w; j++) {
			b[i + 1][j + 1] = a[i][j];
		}
	}
	for (i = 0; i < h + 2; i++) {
		for (j = 0; j < w + 2; j++) {
			printf("%c", b[i][j]);
		}
		puts("");
	}
	return 0;
}


Measured memory_bytes: 128
package main

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

var sc = bufio.NewScanner(os.Stdin)
var out = bufio.NewWriter(os.Stdout)

func main() {
	buf := make([]byte, 1024*1024)
	sc.Buffer(buf, bufio.MaxScanTokenSize)
	sc.Split(bufio.ScanWords)
	defer out.Flush() // !!!!caution!!!! you must use Fprint(out, ) not Print()
	/* --- code --- */
	n, m, q := nextInt(), nextInt(), nextInt()
	var a, b, c, d []int

	point := func(wl []int) int {
		p := 0
		for i := 0; i < q; i++ {
			if wl[b[i]-1]-wl[a[i]-1] == c[i] {
				p += d[i]
			}
		}
		//fmt.Fprintln(out, "[DEBUG]", wl, p)
		return p
	}
	for i := 0; i < q; i++ {
		a = append(a, nextInt())
		b = append(b, nextInt())
		c = append(c, nextInt())
		d = append(d, nextInt())
	}

	ans := search(0, make([]int, n), n, m, point)

	fmt.Fprintln(out, ans)
}
func search(i int, wl []int, n, m int, point func([]int) int) int {
	if i == n {
		return point(wl)
	}
	var start int
	if i == 0 {
		start = 1
	} else {
		start = wl[i-1]
	}
	wmax := 0
	for j := start; j <= m; j++ {
		wl[i] = j
		wans := search(i+1, wl, n, m, point)
		if wmax < wans {
			wmax = wans
		}
	}
	return wmax
}

// -*-*-*-*-*-*-*-*-
// * I/O utilities *
// -*-*-*-*-*-*-*-*-

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

func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}

func nextFloat64() float64 {
	a, _ := strconv.ParseFloat(next(), 64)
	return a
}

func nextInts(n int) []int {
	ret := make([]int, n)
	for i := 0; i < n; i++ {
		ret[i] = nextInt()
	}
	return ret
}
func nextFloats(n int) []float64 {
	ret := make([]float64, n)
	for i := 0; i < n; i++ {
		ret[i] = nextFloat64()
	}
	return ret
}
func nextStrings(n int) []string {
	ret := make([]string, n)
	for i := 0; i < n; i++ {
		ret[i] = next()
	}
	return ret
}

func chars(s string) []string {
	ret := make([]string, len([]rune(s)))
	for i, v := range []rune(s) {
		ret[i] = string(v)
	}
	return ret
}


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

int main() {
    int N, Q; cin >> N >> Q;
    vector<int> c;
    
    for (int i=0; i<N; i++) {
        int ci; cin >> ci;
        c.push_back(ci);
    }
    
    sort(c.begin(), c.end());
    
    for (int i=0; i<Q; i++) {
        int qi; cin >> qi;
        int p = 1;
        int ans = 0;
        
        while (true) {
            int idx = lower_bound(c.begin(), c.end(), p*qi)-c.begin();
            idx--;
            
            if (idx==-1) {
                p += 1;
                continue;
            }
            
            ans = max(ans, c[idx]%qi);
            p += 1;
            
            if (idx==N-1) {
                break;
            }
        }
        
        cout << ans << endl;
    }
}


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

typedef long long ll;

int main() {	
	int n;
    cin >> n;
    string s;
    cin >> s;
    vector<int> e(n + 2);
    vector<int> w(n + 2);
    for (int i = 1; i <= n; ++i) {
		e[i] = e[i - 1];
		if (s[i - 1] == 'W') {
			e[i]++;
		}
	}
	 for (int i = n; i > 0; --i) {
		w[i] = w[i + 1];
		if (s[i - 1] == 'E') {
			w[i]++;
		}
	}
	int ans = 1e9 + 7;
	for (int i = 1; i <= n; ++i) {
		ans = min(ans,e[i - 1] + w[i + 1]);
	}
	cout << ans;
}


Measured memory_bytes: 6168
using System;
using System.Linq;

namespace a
{
    class Program
    {
        static void Main(string[] args)
        {
            var s = Console.ReadLine().Split().Select(i => long.Parse(i)).Select(i => i == 1 ? 1 + 13 : i).ToArray();
            var a = s[0];
            var b = s[1];

            if(a == b){
                Console.WriteLine("Draw");
            }else if(a > b){
                Console.WriteLine("Alice");
            }else{
                Console.WriteLine("Bob");
            }
        }
    }
}


Measured memory_bytes: 13396
#include<iostream>
#include<algorithm>
#include<bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define int long long
#define pi 3.141592653589793238462643383279502
#define M 1000000007
#define F first
#define S second
#define pii pair<int,int>
#define rep(i,n) for(int i=0;i<n;i++)
bool isPowerOfTwo(int n)
{
   if(n==0)
   return false;

   return (ceil(log2(n)) == floor(log2(n)));
}
int power(int x, unsigned int y)
{
    if (y == 0)
        return 1;
    else if (y % 2 == 0)
        return power(x, y / 2) * power(x, y / 2);
    else
        return x * power(x, y / 2) * power(x, y / 2);
}
int findXor(int arr[], int n)
{

    // Calculate xor of all the elements
    int xoR = 0;
    for (int i = 0; i < n; i++) {
        xoR = xoR ^ arr[i];
    }

    // Return twice of xor value
    return xoR * 2;
}

signed main()
{
 int a,b;
 cin>>a>>b;
 for(int i=1;i<=10000;i++)
 {

     int x=(i*8)/100;
     int y=(i*10)/100;
     if(x==a&&y==b)
     {cout<<i<<endl;return 0;}
 }
cout<<-1<<endl;

}





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

int main(){
	int y,m,d,p;
	while(cin >> y >> m >> d){
		p = y*10000 +100*m + d;
		if(p >= 1989*10000 + 100 + 8){
			cout << "heisei" << " " << y-1989+1 << " " << m << " " << d;
		}else if(p >= 1926*10000 + 1200 + 25){
			cout << "showa" << " " << y-1926+1 << " " << m << " " << d;
		}else if(p >= 1912*10000 + 700 + 30){
			cout << "taisho" << " " << y-1912+1 << " " << m << " " << d;
		}else if(p >= 1868*10000 + 900 + 8){
			cout << "meiji" << " " << y-1868+1 << " " << m << " " << d;
		}else{
			cout << "pre-meiji";
		}
		cout << endl;
	}
}

Measured memory_bytes: 0
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <cassert>

using namespace std;
typedef long long LL;
template <typename F, typename S> std::ostream& operator<<(ostream& os, const pair<F,S>& p) {
    os << "(" << p.first << "," << p.second << ")"; return os; }
template <typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
    os << "["; for(const T& a: v){ os << a << ", "; } os << "]"; return os; }
template <typename K, typename V> ostream& operator<<(ostream& os, const map<K,V>& m) {
    os << "{"; for(const auto& p: m){ os << p.first <<":"<< p.second << ", "; } os << "}"; return os; }

LL gcd(LL v1, LL v2){
    assert(v2 > 0);
    if(v1 < v2) swap(v1, v2);
    if(v1 % v2 == 0) return v2;
    return gcd(v2, v1 % v2);
}


int main(){
    LL n;
    cin >> n;
    LL ans = 0;
    for(LL i = 1; i <= n; ++i){
        ans += i;
        for(LL j = i+1; j <= n; ++j){
            LL ij = gcd(i, j);
            ans += ij * 6;
            for(LL k = j+1; k <= n; ++k){
                ans += gcd(ij, k) * 6;
            }
        }
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 3160
import std.algorithm;
import std.array;
import std.ascii;
import std.container;
import std.conv;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void log(A...)(A arg) {
    stderr.writeln(arg);
}
int size(T)(in T s) {
    return cast(int)s.length;
}

class Edge {
    int from, to;
    bool isBridge;
    this(int from, int to) {
        this.from = from;
        this.to = to;
    }
    override string toString() {
        return [from, to, isBridge].to!string;
    }
}
class Graph {
    Edge[][] G;
    int V;
    this(int V) {
        this.V = V;
        G = new Edge[][V];
    }
    void addEdge(int from, int to) {
        G[from] ~= new Edge(from, to);
        G[to] ~= new Edge(to, from);
    }
}

const int INF = int.max/4;
void solve() {
    int N, M; scanf("%d %d\n", &N, &M);
    auto W = stdin.readln.chomp.split(" ").map!(to!int).array;
    auto graph = new Graph(N);
    foreach (i; 0 .. M) {
        int u, v; scanf("%d %d\n", &u, &v); u--; v--;
        graph.addEdge(u, v);
    }
    auto g = graph.G;

    auto visited = new bool[N];
    Tuple!(bool, int, int) dfs(int v, int prev) {
        visited[v] = true;
        int ans = W[v];
        int diff_max = 0;
        bool can_ret = false;
        foreach (e; g[v]) {
            if (e.to == prev) continue;
            if (visited[e.to]) {
                can_ret = true;
                continue;
            }
            auto r = dfs(e.to, v);
            if (r[0]) can_ret = true;
            ans += max(0, r[1]);
            diff_max = max(diff_max, r[2] - max(0, r[1]));
        }
        //log([v, prev, can_ret, can_ret ? ans: -INF, ans + diff_max]);
        return tuple( can_ret, (can_ret ? ans : -INF), ans + diff_max);
    }
    dfs(0, -1)[2].writeln;
}


//import core.memory;
//alias base_t = long;
//const base_t STACK_SIZE = (base_t.sizeof) * (1<<24);
//__gshared void* stack;
//__gshared base_t org_esp;
//__gshared base_t esp;
void main() {
    //GC.disable();
    //stack = GC.malloc(STACK_SIZE);
    //esp = cast(base_t)(stack) + STACK_SIZE - 1;
    //asm {
    //    mov org_esp, RSP;
    //    mov RSP, esp;
    //}

    solve();

    //asm {
    //    mov RSP, org_esp;
    //}
}

Measured memory_bytes: 32300
#include<stdio.h>
#define M 151200
int main(){
  long long i;
  int j,n[60],m[100];
  char c[1000000]={1};
  for(i=0;i<60 ;i++)n[i]=i*i*i;
  for(i=0;i<100;i++)m[i]=(i*(i+1)*(i+2))/6;//printf("a\n");
  for(i=0;i<60;i++){
    for(j=0;j<100;j++){
      if(n[i]+m[j]<=M)c[n[i]+m[j]]=1;
    }
  }
  while(scanf("%d",&j),j){//printf("%d\n",c[j]);
    for(;c[j]==0;j--);
    printf("%d\n",j);
  }
  return 0;
}

Measured memory_bytes: 1584
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <iomanip>

using namespace std;
int N;
void dfs(int depth, string cur, char m){
   if(depth==N) cout << cur << endl;
   else {
      for(int i = 0 ; i <= m-'a'+1; i++){
         string next = cur;
         next += 'a'+i;
         dfs(depth+1, next, max(m, char('a'+i)));
      }
   }
   return;
}

int main(){
   cin >> N;
   dfs(1, "a", 'a');
   return 0;
}


Measured memory_bytes: 1536
#include <stdio.h>

int main(void)
{
	long long int a, b, k;

	scanf("%lld %lld %lld", &a, &b, &k);

	if (a >= k) //高橋君のクッキーだけで終わる場合
	{
		printf("%lld %lld\n", a - k, b);
	}
	else if (b + a >= k) //青木君のクッキーも食べる場合
	{
		printf("0 %lld\n", b - k + a);
	}
	else //両方のクッキーを食べ終わる場合
	{
		printf("0 0\n");
	}

	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n, k;
	int x[100];
	cin >> n >> k;
	for(int i = 0; i < n; ++i){
		cin >> x[i];
	}
	int ans = 0;
	for(int i = 0; i < n; ++i){
	int tmp = min(x[i], k - x[i]);
		ans += tmp;
	}
	cout << ans*2 << "\n";
}

Measured memory_bytes: 3544
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); ++i)
//#define DEBUG
#ifdef DEBUG
#define DEBUG_PRINT(fm, ...) do{std::printf("%s:%d(%s)", __FILE__, __LINE__, __func__);std::cout << "DEBUG PRINT ";std::printf(fm, __VA_ARGS__);}while(0)
#define DEBUG_VAL(a, b) do{std::printf("%s:%d(%s)", __FILE__, __LINE__, __func__);std::cout <<"DEBUG VAL " << a << ":" << b << endl;}while(0)
#else
#define DEBUG_PRINT(...)do{}while(0);
#define DEBUG_VAL(a, b)do{}while(0);
#endif

using namespace std;
using ll = long long;
using v1 = vector<int>;
using vl = vector<long long>;
using v2 = vector<vector<int>>;
using v3 = vector<vector<char>>;
int main(){
    set<string> S;
    int n;
    cin >> n;
    rep(i, n){
        string a;
        cin >> a;
        S.insert(a);
    }
    cout << S.size() << endl; 
}

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

int main() {
	int n=0; 
  	cin >> n;
  	long long int ans = 0;
  	for(int i=1; i <= n; i++) {
      	if(i % 3 == 0 && i % 5 == 0)
          continue;
    	if(i % 3 == 0 || i % 5 == 0)
          continue;
      	ans = ans + i;
    }
   	cout << ans;
 	return 0;
}

Measured memory_bytes: 3612
#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;

typedef long long int ll;
typedef pair<ll,ll> pp;
typedef long double ld;
typedef vector<pp> vpl;
//typedef tree<pair<ll,ll>, null_type, less<pair<ll,ll>>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
 

 
const ll N = 100005;
const ll mod = 1000000007;
const long long int inf = 1e9;

#define MP make_pair
#define endl "\n"
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<n;i++)
#define rrep(i,n) for(ll i=n-1;i>=0;i--)
#define repb(i,n) for(ll i=1;i<n-1;i++) 
#define trace(i,a) for(auto i=a.begin();i!=a.end();i++) 
#define mtrace(i,a) for(auto i=a.begin();i!=a.end();i++)  cout<<i->first<<" "<<i->second<<endl;   
 
const ld pi = 3.14159265359;

mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count());
int rng(int lim) {
	uniform_int_distribution<int> uid(0,lim-1);
	return uid(rang);
}

 
void fastIO(void);
void decimal(int);
ll modmulti(ll, ll);
ll modadd(ll, ll);
ll modpower(ll, ll);
ll gcd(ll, ll );
ll modinv(ll);





int main(){
	fastIO();
	ll n,m;
	cin>>n>>m;
	ll a[m];
	rep(i,m) cin>>a[i];
	ll sum = 0;
	rep(i,m) sum+=a[i];
	cout<<max((ll)-1,n-sum)<<endl;





		



		
	

		
}
	


 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
void fastIO(void)
{  ios_base::sync_with_stdio(false);
   cin.tie(0);
   cout.tie(0);
}
 
void decimal(int n){
   cout<<fixed;
   cout<<setprecision(n);
}
ll modmulti(ll a, ll b){
   return ((a%mod)*1ll*(b%mod))%mod;
}
ll modadd(ll a, ll b){
   ll asdfgh =  ((a%mod)+(b%mod)+mod+mod)%mod;
   asdfgh = (asdfgh+mod)%mod;
   return asdfgh;
}
ll modpower(ll a, ll n){
   if(n==0) return 1;
   if(n==1) return a%mod;
   ll b = modpower(a,n/2);
   b = modmulti(b,b);
   if(n%2==0) return b;
   return modmulti(a,b);
}
ll gcd(ll a, ll b){
   if(b==0)
      return a;
   return gcd(b,a%b);
}
ll modinv(ll a){
   return modpower(a,mod-2);
}

Measured memory_bytes: 3652
import bisect
import heapq
import itertools
import math
import operator
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter, mul, add, xor

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7

N, Q = list(map(int, sys.stdin.readline().split()))
AB = [list(map(int, sys.stdin.readline().split())) for _ in range(N - 1)]
PX = [list(map(int, sys.stdin.readline().split())) for _ in range(Q)]

graph = [[] for _ in range(N + 1)]
for a, b in AB:
    graph[a].append(b)

counts = defaultdict(int)
for p, x in PX:
    counts[p] += x

ans = [0] * (N + 1)
ans[1] = counts[1]
que = deque([1])
while que:
    v = que.popleft()
    cnt = ans[v]
    for u in graph[v]:
        que.append(u)
        ans[u] = counts[u] + cnt

print(*ans[1:])


Measured memory_bytes: 159168
#include<bits/stdc++.h>
using ll=long long;
using namespace std;
#define rep(i, n) for(ll i=0; i<n; i++)
#define Rep(i, j, n) for(ll i=j; i<n; i++)
#define all(vec) vec.begin(), vec.end()
template<class T> inline bool chmin(T& a, T b) {if(a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if(a < b) {a = b; return true;} return false;}
ll MM = 1000000000; ll mod = MM + 7; ll MMM=9223372036854775807;//2^63 -1
ll GCD(ll x, ll y){ if(y == 0) return x; else return GCD(y, x % y);}
ll LCM(ll x, ll y){ return x / GCD(x, y) * y;}
int dh[4] = {-1, 0, 0, 1};
int dw[4] = {0, -1, 1, 0}; 
using P = pair<int, int>;
const double pi = acos(-1.0);

using Graph = vector<vector<ll>>;

int main(){
  int n,m;
  cin>>n>>m;
  vector<string>a(n);
  vector<string>b(m);
  rep(i,n)cin>>a[i];
  rep(i,m)cin>>b[i];
  bool cn;
  rep(i,n-m+1){
    
    rep(j,n-m+1){
      cn=true;
      rep(k,m){
	rep(l,m){
	  if(b[k][l]!=a[i+k][j+l])cn=false;
	}
      }if(cn){cout<<"Yes"<<endl;return 0;}
    }
   
  }

  cout<<"No"<<endl;
    
  return 0;
}


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

int main(){
	int b, f, r, v, n;
	int room[4][3][10];

	//配列初期化
	for(int i=0; i<4; i++){
		for(int j=0; j<3; j++){
			for(int k=0; k<10; k++){
				room[i][j][k]=0;
			}
		}
	}

	cin>>n;
	for(int i=0; i<n; i++){
		cin>>b>>f>>r>>v;
		room[b-1][f-1][r-1]+=v;
	}

	for(int i=0; i<4; i++){
		for(int j=0; j<3; j++){
			for(int k=0; k<10; k++){
				printf(" %d", room[i][j][k]);
				if(k==9)printf("\n");
			}
		}
		if(i!=3){
			printf("####################\n");
		}
	}
	return 0;

}


Measured memory_bytes: 3224
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define mp make_pair
#define F first
#define S second

signed main(){
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	int n;
	cin >> n;
	cout << 8 - n/200 + 2;


	
	

	return 0;
}

Measured memory_bytes: 3644
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

a.sort()
b.sort()
c.sort()
b_ceil = [n]*len(b)
b_ceil.insert(0, 0)
b_floor = [n]*len(b)
b_floor.insert(0, 0)
count = 0
for i in range(len(b)):
    for j in range(b_ceil[i], len(a)):
        if a[j] >= b[i]:
            b_ceil[i+1] = j
            break
    for k in range(b_floor[i], len(c)):
        if b[i] < c[k]:
            b_floor[i+1] = k
            break
    count += b_ceil[i+1] * (n - b_floor[i+1])

print(count)

Measured memory_bytes: 23940
#include <iostream>
#include <string>
using namespace std;
int main(int argc, char *argv[])
{
	int N, ans = 0;
	cin >> N;
	int f[100001] = {};
	for (int i = 0; i < N; ++i) {
		int a;
		cin >> a;
		ans += f[a] == (i + 1);
		f[i + 1] = a;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
long long n,m,k,cnt[20],cha;
map<long long,map<long long,long long> >mp;
int main()
{
	cin>>n>>m>>k;
	cnt[0]=(n-2)*(m-2);
	for(long long i=0;i<k;i++)
	{
		long long a,b;
		cin>>a>>b;
		for(long long j=-1;j<=1;j++)
		{
			for(long long l=-1;l<=1;l++)
			{
				long long x=a+j,y=b+l;
				if(x>=2 && y>=2 && x<n && y<m)
				{
					mp[x][y]++;
					long long now=mp[x][y];
					cnt[now]++;
					cnt[now-1]--;
				}
			}
		}
	}
	for(long long i=0;i<10;i++)
	{
		cout<<cnt[i]<<endl;
	}
	return 0;
}

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

typedef long long ll; // -9,223,372,036,854,775,808 から 9,223,372,036,854,775,807

template <class T> using vec = std::vector<T>;
template <class T> using vec2 = vec<vec<T>>;
template <class T> using vec3 = vec<vec<vec<T>>>;

#define DEBUG

void solve(long long X){
    ll N500 = X/500;
    X %= 500;
    ll N5 = X/5;
    cout << N500*1000 + N5*5 << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long X;
    scanf("%lld",&X);
    solve(X);
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define loop(i, a, b) for(li i=a; i<=b; i++)
#define stuff ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
typedef long long li;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<li, li> lii;
typedef vector<int> vi;
typedef vector<li> vli;
typedef vector<ii> vii;
typedef vector<lii> vlii;
li mod = 1e9+7;
li expo(li base, li exponent)
{
	li ans=1;
	while(exponent)
	{
		if(exponent&1) ans = (ans*base)%mod;
		base = (base*base)%mod;
		exponent >>= 1;
	}
	return ans;
}
li gcd(li x, li y)
{
	if(y==0) return x;
	return gcd(y, x%y);
}


typedef tree<li, null_type, less<li>,
rb_tree_tag, tree_order_statistics_node_update> ordered_set;

li n;
li col[200002];
li sub[200002], val[200002];
li ans[200002];
vector<vector<li> > g;

li calc(li a, li b)
{
	li x = a-b;
	return (x*(x+1))/2;
}
void dfs(li u, li p)
{
	li c = col[u];
	li og = val[c];
	for(auto v : g[u])
	{
		if(v==p) continue;
		li pre = val[c];
		dfs(v, u);
		li cur = val[c];
		ans[c] += calc(sub[v], cur-pre);
		sub[u] += sub[v]; 
	}
	sub[u]++;
	val[c] = sub[u]+og;
}
int main()
{
	stuff;
	// #ifndef ONLINE_JUDGE 
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
	// freopen("error.txt", "w", stderr);
	// #endif

	cin >> n;
	g.resize(n+1);
	// vector<bool> vis(n+1, 0);
	loop(i, 1, n) cin >> col[i];
	
	for(li i=1, u, v; i<=n-1; i++)
	{
		cin >> u >> v;
		g[u].pb(v);
		g[v].pb(u);
	}
	// for(int i)
	dfs(1, -1);
	// for(int i=1; i<=n; i++)
	// {
	// 	cout << sub[i] << " ";
	// }
	// cout << endl;
	for(int i=1; i<=n; i++)
	{
		ans[i] += calc(n, val[i]);
		cout << calc(n, 0)-ans[i] << "\n";
	}
	return 0;
}


Measured memory_bytes: 39028
#include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define pb push_back
#define MP(a, b) make_pair((a), (b))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;

int main() {
    int N, K;
    cin >> N >> K;
    vector<int> V(N);
    deque<int> que;
    rep(i, N) {
        cin >> V[i];
        que.push_back(V[i]);
    }
    ll res = -INF;
    for(int i = 0; i <= K; i++) {
        int lim = K - i;
        for(int j = 0; j <= K; j++) {
            if(i + j > N || i + j > K)
                break;
            deque<int> q = que;
            priority_queue<int, vector<int>, greater<int>> pq;
            rep(ii, i) {
                pq.push(q.front());
                q.pop_front();
            }
            rep(jj, j) {
                pq.push(q.back());
                q.pop_back();
            }
            int rest = K - i - j;
            while(!pq.empty() && pq.top() < 0 && rest > 0) {
                pq.pop();
                rest--;
            }
            ll tmp = 0;
            while(!pq.empty()) {
                tmp += pq.top();
                pq.pop();
            }
            res = max(res, tmp);
        }
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
n,a,b=map(int,input().split())
mod=10**9+7

#modあり
def pow_speed(x,n):
    res = 1
    while n > 0:
        if n & 1 == 1:
            res *= x
        x *= x
        x%=mod
        n >>= 1
    return res

#nCx(mod)
def comb_speed(n,x):
    rec=1
    for i in range(n-x+1,n+1):
        rec=rec*i%mod
    rec2=1
    for i in range(1,x+1):
        rec2=rec2*i%mod
    rec2=pow_speed(rec2,mod-2)
    return (rec*rec2)%mod

print((pow_speed(2,n)-comb_speed(n,a)-comb_speed(n,b)-1)%mod)

Measured memory_bytes: 3064
N, M = map(int, input().split())
H = [int(x) for x in input().split()]
AB = [[int(x) for x in input().split()] for _ in range(M)]

li = [0] + [-1] * N
for a, b in AB:
#     ma = max(H[a-1], H[b-1])
#     if ma==H[a-1]:
#         li[b]=-4
#     elif H[a-1]==H[b-1]:
#         li[a]=-4
#         li[b]=-4
#     else:
#         li[a]=-4
#     print(li)

    if H[a-1]>H[b-1]:
        li[b]=-4
    elif H[b-1]>H[a-1]:
        li[a]=-4
    else:
        li[a] = li[b] = -4

cnt=0

for i in range(N+1):
    if i==0:
        continue
    if li[i]==-4:
        cnt+=1
print(N-cnt)

Measured memory_bytes: 31292
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define ifaxb(a, x, b) if (a < x && x < b) // 比較は昇順
#define vi vector<int>
#define vii vector<vi>
#define vs vector<string>
#define vss vector<vs>
#define all(x) x.begin(), x.end()
#define ff first
#define ss second
#define pq priority_queue
#define ipair pair<int, int>
#define spair pair<string, string>
#define lpair pair<LL, LL>
#define MP make_pair
#define MM multimap
#define PB push_back
#define INF 2147483647
#define _INF -2147483647
#define pi 3.1415926536
#define MAXN 100004
using namespace std;
typedef long long ll;

int main()
{
  int d;
  cin >> d;
  cout << "Christmas";
  for (int i = d; i < 25; i++)
    cout << " Eve";
  cout << endl;
  return 0;

  return 0;
}


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

int read() {
	int num = 0; bool flag = 1; char c = getchar();
	for (; c < '0' || c > '9'; c = getchar())	
		if (c == '-') flag = 0;
	for (; c >= '0' && c <= '9'; c = getchar())
		num = (num << 3) + (num << 1) + c - 48;
	return flag ? num : -num;
}

int a[100010], s[100010 << 1];

int main() {
	int n, m;
	cin >> n >> m;
	char c;
	int cnt = 0;
	int last;
	bool flag = 0;
	for (int i = 1; i <= n; ++ i) {
		cin >> c;
		if (c == '0') {
			flag = 1;
			if (last == 0) -- a[cnt];
			else last = 0, a[++ cnt] = -1;
		} 
		else {
			if (last == 1) ++ a[cnt];
			else last = 1, a[++ cnt] = 1; 
		}
	}
	if (!flag) {
		printf("%d\n", n);
		return 0;
	}
	for (int i = 1; i <= cnt; ++ i) s[i] = s[i - 1] + abs(a[i]);
	for (int i = n + 1; i <= cnt << 1; ++ i) s[i] = s[i - 1];
	int ans = 0; 
	for (int i = 1; i <= cnt; ++ i) {
		if (a[i] < 0) ans = max(ans, s[min(i + m * 2 - 1, cnt)] - s[i - 1]);
		else ans = max(ans, s[min(i + m * 2, cnt)] - s[i - 1]);
	}
	printf("%d\n", ans);
	return 0;
} 

Measured memory_bytes: 1408
import java.util.*;


public class Main {
    public static void main(String[] args) {
        // 自分の得意な言語で
        // Let's チャレンジ！！

        Scanner sc = new Scanner(System.in);
        String line = sc.nextLine();
        String s[]=line.split("",0);
        int n=Integer.parseInt(line);
        int a=0;
        for(int i=0;i<s.length;i++){
            a+=Integer.parseInt(s[i]);
        }
        if((n/a)*a==n)
        System.out.println("Yes");
        else
        System.out.println("No");
    }
}

Measured memory_bytes: 21204
N = int(input())
s1 = input()
s2 = input()
MOD = 1000000007

dp = [0] * (N + 1)
if s1[0] == s2[0]:
    dp[0] = 3
    i = 1
else:
    dp[0] = 6
    i = 2
p1, p2 = s1[0], s2[0]
j = 0
while i < N:
    c1, c2 = s1[i], s2[i]
    if c1 == c2:
        if p1 == p2:
            dp[j+1] = dp[j] * 2 % MOD
        else:
            dp[j+1] = dp[j]
        i += 1
    elif c1 != c2:
        if p1 == p2:
            dp[j+1] = dp[j] * 2 % MOD
        else:
            dp[j+1] = dp[j] * 3 % MOD
        i += 2
    j += 1
    p1, p2 = c1, c2

print(dp[j])

Measured memory_bytes: 3064
/**********************************
	author:  mariogzsl
**********************************/

#include <bits/stdc++.h>

#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ROF(i,b,a) for(int i=b-1;i>=a;i--)
#define f first
#define s second
#define puts(x) cout<<x<<endl
using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int N;
	cin>>N;
	vector<int>V(N,-1);
	vector<int>C(N,-1);
	FOR(i,0,N)cin>>V[i];
	FOR(j,0,N)cin>>C[j];
	int ans=0;
	FOR(i,0,N){
		if(V[i]>C[i])ans+=V[i]-C[i];
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string.h>
#include <cmath>
#include <cstdio>

#define EPS 1e-9
#define MAX 102

using namespace std;

double dp[MAX][MAX];

bool relative_equal(double a, double b){
    if(a == 0) return fabs(b) < EPS;
    return fabs((a-b)/a) < EPS;
}

int main(void)
{
	int N,T,L,B;
	int i1,i2,i3;
	int lose,back;
	double temp1;
	int temp2;
	double c;

	while(1){
		cin>>N>>T>>L>>B;
		if(N+T+L+B==0) break;

		memset(dp,0,sizeof(dp));

		for(i1=0;i1<L;i1++){
			cin>>lose;
			dp[0][lose]=-1;
		}
		for(i1=0;i1<B;i1++){
			cin>>back;
			dp[0][back]=-2;

		}

		dp[0][0]=1;
		c=0;

		for(i1=0;i1<T;i1++){
			for(i3=0;i3<=N;i3++){

				if(dp[i1][i3]>0){
					temp1=dp[i1][i3]/6;
					for(i2=1;i2<=6;i2++){
						temp2=i3+i2;
						if(i3+i2>N) temp2=2*N-temp2;

						if(relative_equal(dp[0][temp2],-1)) dp[i1+2][temp2]+=temp1;
						else if(relative_equal(dp[0][temp2],-2)) {
							dp[i1+1][0]+=temp1;
							dp[i1+1][temp2]=0;
						} 
						else dp[i1+1][temp2]+=temp1;
					}
				}

			}
			c+=dp[i1+1][N];
			dp[i1+1][N]=0;
		}

		printf("%.6lf\n", c);
	}
	return 0;
}

Measured memory_bytes: 1272
#include <iostream>
#include <map>

using namespace std;

int main() {
	int n; cin >> n;
	long long s = 0;
	map<int, int> mp;
	for (int i = 0; i < n; ++i) {
		int a; cin >> a;
		s += a;
		++mp[a];
	}
	int q; cin >> q;
	while (q--) {
		int b, c; cin >> b >> c;
		long long t = mp[b];
		mp[b] = 0;
		mp[c] += t;
		s += t * (c - b);
		cout << s << endl;
	}

	return 0;
}

Measured memory_bytes: 8020
#include <bits/stdc++.h>
#include<vector>
using namespace std;
#define rep(i, n)        for(int i=0; i<(int)(n); ++i)
int main() {
  long int a,b,c=0;
  cin>>a>>b;
  vector<pair<long int,long int>>d(a);
  vector<pair<long int,long int>>e(b);
  rep(i,a)cin>>d[i].first>>d[i].second;
  rep(i,b)cin>>e[i].first>>e[i].second;
  rep(i,a){
    long int f=LONG_MAX,g,h,j=0;
    rep(o,b){
      g=fabs(d[i].first-e[o].first)+fabs(d[i].second-e[o].second);
      if(f==g)continue;
      f=min(g,f);
      if(f==g)h=o+1;
    }
   cout<<h<<endl;
  }
}


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

int main(){
    int n, q, op, a, b;
    cin >> n >> q;
    vector<int> A[n];

    for(int i = 0; i < q; i++){
        scanf("%d", &op);
        if(op == 0){
            scanf("%d %d", &a, &b);
            A[a].push_back(b);
        }else if(op == 1){
            scanf("%d", &a);
            for(int i = 0; i < A[a].size(); i++){
                if(i)   printf(" ");
                printf("%d", A[a][i]);
            }
            printf("\n");
        }else if(op == 2){
            scanf("%d", &a);
            A[a].clear();
        }
    }

    return 0;
}


Measured memory_bytes: 6024
#include <bits/stdc++.h>
using namespace std;
 
int main(){
   int X,Y;
   cin>>X>>Y;
   int flg=0;
   for(int i=0;i<=X;i++){
       if((2*i)+4*(X-i)==Y){
           flg = true;
       }
   }
   if(flg){
       cout<<"Yes"<<endl;
   }else{
       cout<<"No"<<endl;
   }
}

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

int main() {
   int a=0;
   int b=0;
   int c=0;
   int d=0;
  
   for(int i=0;i<6;i++){
      int n;
	   cin >>n;
	   if(n==1)a++;
	   if(n==2)b++;
	   if(n==3)c++;
	   if(n==4)d++;
	   
   }
   int e = max(max(max(a,b),c),d);
   if(e==3) cout << "NO" <<endl;
   if(e==2) cout << "YES" <<endl;
  
 
}


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

#define ll          long long
#define pb          push_back
#define pii         pair<ll,ll>
#define vpii        vector< pii >
#define vi          vector<ll>
#define vs			vector< string >
#define vvi         vector< vector< ll > >
#define inf			1'010'000'000'000'000'017LL
#define all(it,a)   for(auto it=(a).begin();it!=(a).end();it++) 
#define sz(x)       (ll)x.size()
#define rep(i,a,b)	for(ll i=a;i<b;i++)
#define repr(i,a,b) for(ll i=a;i>b;i--)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define mp          make_pair
#define whatis(x)   cout << #x << " is " << x << "\n";
#define graph(n)    adj(n,vector< ll > () )

using namespace std;

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


void Main() {
	ll N, M, K;
	cin >> N >> M >> K;
	vi A(N, 0), B(M, 0);
	rep(i, 0, N) cin >> A[i];
	rep(i, 0, M) cin >> B[i];

	vi canReadB(N + 1, 0);
	ll tempSumA = 0, tempSumB = 0;
	rep(i, 0, M) {
		if (B[i] + tempSumB > K) break;
		tempSumB += B[i];
		canReadB[0]++;
	}
	ll result = canReadB[0];
	rep(i, 1, N + 1) {
		if (A[i - 1] + tempSumA > K) break;
		tempSumA += A[i - 1];
		canReadB[i] = canReadB[i - 1];
		while (tempSumA + tempSumB > K) {
			canReadB[i]--;
			tempSumB -= B[canReadB[i]];
		}
		chmax(result, i + canReadB[i]);
	}

	cout << result << endl;
}


int main() {
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);

	Main();
	return 0;
}


Measured memory_bytes: 7972
use proconio::input;

#[allow(non_snake_case)]
fn main() {
    input! {
        N: usize,
        A: [u128; N],
    }
    for &a in A.iter() {
        if a == 0 {
            println!("0");
            return;
        }
    }
    let mut ans = 1;
    for &a in A.iter() {
        ans *= a;
        if ans > 1e18 as u128 {
            println!("-1");
            return;
        }
    }

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


Measured memory_bytes: 5324
#include<stdio.h>
#define null -1
#define max 100000

//leftがchild、rightがsiblingとなる
typedef struct{
  int parent,left,right;
}node;

node tree[max];

int num,depth[max],high[max];

//関数、出力、深さ、兄弟の数、高さ
void print(int a){
  int d=0;
  
  printf("node %d: ",a);
  printf("parent = %d, ",tree[a].parent);
  printf("sibling = %d, ",sibling(a));

  if(tree[a].right!=null)d++;
  if(tree[a].left!=null)d++;

  printf("degree = %d, ",d);
  printf("depth = %d, ",depth[a]);
  printf("height = %d, ",high[a]);

  if(tree[a].parent==null){
    printf("root\n");
  }else if(tree[a].left==null && tree[a].right==null){
    printf("leaf\n");
  }else{
    printf("internal node\n");
  }
}
//深さ、再帰
void deep(int a,int d){
  if(a==null)return;
  depth[a]=d;
  deep(tree[a].right,d+1);
  deep(tree[a].left,d+1);
}

//兄弟
int sibling(int a){
  if(tree[a].parent==null){
    return null;
  }
  if(tree[tree[a].parent].right!=a && tree[tree[a].parent].right!=null){
    return tree[tree[a].parent].right;
  }
  if(tree[tree[a].parent].left!=a && tree[tree[a].parent].left!=null){
    return tree[tree[a].parent].left;
  }
  return null;
  
}

//高さ、再帰
int tall(int a){
   int h1=0,h2=0;

   if(tree[a].left!=null){
     h1=tall(tree[a].left)+1;
   }
   if(tree[a].right!=null){
     h2=tall(tree[a].right)+1;
   }
   return high[a]=(h1>h2 ? h1:h2);
}

int main(){
  int i,id,left,right,root=0;
  //節点の個数
  scanf("%d",&num);
  //親を全て初期化
  for(i=0;i<num;i++){
    tree[i].parent=null;
  }
  //節点番号、左側、右側
  for(i=0;i<num;i++){
    scanf("%d%d%d",&id,&left,&right);
    tree[id].left=left;
    tree[id].right=right;
    //親を決めてあげる（イメージができない）
    if(left!=null){
      tree[left].parent=id;
    }
    if(right!=null){
      tree[right].parent=id;
    }
  }
  //根を求める
  for(i=0;i<num;i++){
    if(tree[i].parent==null){
      root=i;
    }
  }

  deep(root,0);
  tall(root);
  
  for(i=0;i<num;i++){
    print(i);
  }
  
  return 0;
}



Measured memory_bytes: 2108
n = int(input())
s = input()
passwords = []

firsts = []
firsts_seconds = [[]*10 for _ in range(10)]
firsts_seconds_thirds = [[]*10 for _ in range(100)]

for i in range(n-2):
    if len(firsts) == 10:
        break
    first =  s[i]
    if first in firsts:
        continue
    firsts.append(first)
    for j in range(i+1,n-1):
        if len(firsts_seconds[int(first)]) == 10:
            break
        second = s[j]
        first_second = first + second
        if first_second in firsts_seconds[int(first)]:
            continue
        firsts_seconds[int(first)].append(first_second)
        for k in range(j+1, n):
            password = first_second + s[k]
            if password not in firsts_seconds_thirds[int(first_second)]:
                firsts_seconds_thirds[int(first_second)].append(password)
                passwords.append(password)

print(len(passwords))



Measured memory_bytes: 3188