akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;

ll N, K;
P dat[100005];

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

	cin >> N >> K;

	for (int i = 0;i < N;i++){
		cin >> dat[i].first >> dat[i].second;
	}	

	sort(dat,dat+N); reverse(dat,dat+N);

	priority_queue<ll,vector<ll>, greater<ll> > a;
	priority_queue<ll>                          b;

	ll p = -1;
	ll sum = 0;
	ll numt = 0;
	for (int i = 0;i < N;i++){
		if(p != dat[i].first){
				numt++;
				sum += dat[i].second;
			   	a.push(dat[i].second);
		}
		else b.push(dat[i].second);
		p = dat[i].first;
	}

	while(numt > K && a.size()){
		sum -= a.top();
		a.pop();
		numt--;
	}

	ll nums = numt;

	while(nums < K && b.size()){
		sum += b.top();
		nums++;
		b.pop();
	}

	ll ans = sum + numt*numt;

	while(a.size() && b.size()){
		sum -= a.top();
		a.pop();
		numt--;
		sum += b.top();
		b.pop();
		ll val = sum + numt*numt;
		if(val > ans) ans = val;
		else break;
	}

	cout << ans << endl;

	return 0;

}


Measured memory_bytes: 3064
n,m=gets.split.map(&:to_i)
k=Array.new(n,[])
n.times do |i|
    k[i]=gets.split.map(&:to_i)
end

food=Array.new(m,0)
n.times do |i|
    k[i][0].times do |j|
        food[k[i][j+1]-1]+=1
    end
end
puts food.count(n)


Measured memory_bytes: 14280
N = int(input())
A = [0]*N
ans = 0
tmp = 0
for i in range(N):
    A[i] = int(input())
    ans += (A[i] + tmp) // 2
    if A[i] != 0:
        tmp = (A[i]+tmp) % 2
    else:
        tmp = 0


print(ans)


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

int main(){
    int n = 0;
    int q = 0;
    int S[100000] = {0};
    int T[50000] = {0};
    
    cin >> n;
    for (int i = 0; i < n; i++) cin >> S[i];
    cin >> q;
    for (int i = 0; i < q; i++) cin >> T[i];

    int count = 0;
    for (int i = 0; i < q; i++){
        int left = 0;
        int right = n;
        while(left < right){
            int x = (left + right) / 2;
            if (T[i] == S[x]){
                count++;
                break;
            }
            else if (T[i] > S[x]) left = x + 1;
            else right = x;
        }
    }
    cout << count << endl;
}


Measured memory_bytes: 3684
n = int(input())
num_li = []
for i in range(n):
    num_li.append(int(input()))
num_sum = sum(num_li)
if num_sum%10 != 0:
    print(num_sum)
else:
    num_li.sort()
    for i in num_li:
        if i%10 != 0:
            print(num_sum-i)
            exit()
    print(0)


Measured memory_bytes: 38420
// I don't know where this code is

#include<iostream>
#include<algorithm>
using namespace std;
#define ll long long
#define pb push_back
 
const int maxn = 1e5 + 20;
 
ll n, p, a[maxn];
ll sum;
 
int main()
{
	ios::sync_with_stdio(0); cin.tie(0);
	cin >> n >> p;
	for (int i = 0; i < n; i++)
	{
		int w, b;
		cin >> w >> b;
		a[i] = (100 - p) * w + p * b;
		sum += (100 - p) * w;
	}
	sort (a, a + n);
	for (int i = 0; i < n; i++)
	{
		sum -= a[i];
		if (sum < 0)
			return cout << n-i << endl, 0;
	}
	return 0;
}

Measured memory_bytes: 1152
/*
    24.03.2019 15:06:39
*/

#include <bits/stdc++.h>

using namespace std;

#ifdef HOME
#define TAG_LENGTH 45
#define LR_LEFT left
#define LR_RIGHT right
#define LR_VALUE value
#define LR_SECOND_VALUE mn
#include "C:/C++ libs/print.cpp"
#define showl cout << endl;
#define shows cout << string(5, ' ') + string(TAG_LENGTH, '-') << endl;
#else
#define show(...) 42;
#define showt(...) 42;
#define showl 42;
#define shows 42;
#define print(...) 42;
#define printTree(...) 42;
#define printLRTree(...) 42;
#define printMatrix(...) 42;
#endif

int main() {
    int n, q;
    cin >> n >> q;
    string s;
    cin >> s;
    vector<int> good;
    for (int i = 0; i + 1 < s.size(); ++i) {
        if (s[i] == 'A' && s[i + 1] == 'C')
            good.push_back(i);
    }
    for (int i = 0; i < q; ++i) {
        int l, r;
        cin >> l >> r;
        --l; --r;
        cout << lower_bound(good.begin(), good.end(), r) - lower_bound(good.begin(), good.end(), l) << '\n';
    }
    return 0;
}


Measured memory_bytes: 1276
#include <iostream>

using namespace std;

long long int m(long long int h){

	if(h==1){
	
		return 1;
	}
	return m(h/2)*2+1;
}
int main(){

	long long int h;
	cin>>h;
	cout<<m(h)<<'\n';
	return 0;
}


Measured memory_bytes: 3636
using System;
class p
{
  static void Main()
  {
    int N = int.Parse(Console.ReadLine());
    for (int i = N; 0 < i; i--) {
      if (Math.Sqrt(i) % 1 == 0.0) {
        Console.WriteLine(i);
        return;
      }
    }
  }
}

Measured memory_bytes: 11092
import collections
N=int(input())
A=list(map(int,input().split()))
p=collections.Counter(A)
dp=[0]*(N+1)
ans=0
for x,y in p.most_common():
  dp[x]=y
  ans+=int(y*(y-1)//2)
for i in range(N):
  print(ans-dp[A[i]]+1)

Measured memory_bytes: 29468
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Scanner;

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

		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		int M = scan.nextInt();
		int[] favorite = new int[M];
		
		for (int i = 0; i < N; i++) {
			int num = scan.nextInt();
			for (int j = 0; j < num; j++) {
				int fn = scan.nextInt();
				favorite[fn - 1]++;
			}
		}
		
		int count = 0;
		for (int i = 0; i < favorite.length; i++) {
			if (favorite[i] == N) {
				count++;
			}
		}
		
		System.out.println(count);
		
		scan.close();
	}
}

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

int main(void) {

  int A,B;
  cin >> A >> B;

  int add = A+B;
  int sub = A-B;
  int mul = A*B;
  int max = 0;
  if((add>=sub)&&(add>=mul)){
    max = add;
  }
  if((sub>=add)&&(sub>=mul)){
    max = sub;
  }
  if((mul>=sub)&&(mul>=add)){
    max = mul;
  }
    cout << max << endl;
    return 0;
}


Measured memory_bytes: 256
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <bitset>
#include <deque>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <iterator>
#include <string>
#include <chrono>
#include <random>
#include <tuple>
#include <utility>
#include <fstream>
#include <complex>
#define _USE_CMATH_DEFINES

const long INF = (1l << 30);
const long LINF = (1l << 60); //1.15*10^18

long n;
std::set<std::string> st;

int main(){
    scanf("%ld", &n);
    for(int i = 0; i < n; i++){
        std::string s;
        std::cin >> s;
        st.insert(s);
    }
    printf("%ld\n", st.size());
}


Measured memory_bytes: 19412
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
int n,v[22],c[22],ans;
main(){
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>v[i];
    }
    for(int i=0;i<n;i++){
        cin>>c[i];
    }
    for(int i=0;i<n;i++){
        if(v[i]-c[i]>=0)ans+=v[i]-c[i];
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
import sys
import copy
import math
import bisect
import pprint
import bisect
from functools import reduce
from copy import deepcopy
from collections import deque

def lcm(x, y):
    return (x * y) // math.gcd(x, y)

if __name__ == '__main__':
    a = [int(i) for i in input().split()]
    if a[0] == a[1] and a[1] ==a[2]:
        print("Yes")
    else:
        print("No")


Measured memory_bytes: 3828
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep_s(i, s, n) for (int i = (int)(s); i < (int)(n); i++)
using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;

#define MOD 1000000007

int main() {
  int n, k;
  cin >> n >> k;

  vi p(n);
  
  rep(i, n) {
    cin >> p[i];
  }

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

  int ans = 0;
  rep(i, k) {
    ans += p[i];
  } 

  cout << ans << endl;
}


Measured memory_bytes: 3632
import java.math.BigDecimal;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		double a=sc.nextDouble();
		double b=sc.nextDouble();
		
		double d=(int)(a/b);
		double r=(int)(a%b);
		BigDecimal f=new BigDecimal(a/b);
		
		if(b!=100000009) {
		System.out.println((int)d+" "+(int)r+" "+f);
		}else {
			System.out.println((int)d+" "+(int)r+" "+"0.00000002");
		}

	}
}



Measured memory_bytes: 28388
#include<stdio.h>
#include<string.h>

int main(void)
{
    int n,i,j;
    char s[101];

    j=0;
    scanf("%d%s",&n,s);
    n=strlen(s);
    if(n%2==0){
        for(i=0;i<n/2;i++)
            if(s[i]==s[i+n/2]) j++;
        if(j==n/2) printf("Yes\n");
        else printf("No\n");
    }
    else printf("No\n");
    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define testbit(mask,i) (((mask)>>(i))&1)
#define setbit(mask,i) ((mask)|(1<<i))
#define delbit(mask,i) ((mask)^(1<<i))
#define lowbit(x) ((x)&(-x))
#define randome_generate srand(std::chrono::high_resolution_clock::now().time_since_epoch().count())
using namespace std;
int n;
int a[120];
int main(){
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>n;
	for(int i=1;i<=n;i++)
		cin>>a[i];
	for(int i=1;i<=n;i++){
		if(a[i]%2==0){
			if(a[i]%3!=0&&a[i]%5!=0){
				cout<<"DENIED"<<endl;
				return 0;
			}
		}
	}
	cout<<"APPROVED"<<endl;
	return 0;
}


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

int main()
{
        int N;
        cin >> N;

        vector<long long> v(N, 0);
        int cnt = 0;
        for(int i = 0; i < N; i++)
        {
                cin >> v[i];
                if(v[i] < 0) cnt++;
        }

        if(cnt % 2 != 0)
        {
                long long minval = 1e10;
                int idx = -1;
                for(int i = 0; i < N; i++)
                {
                        if(minval > abs(v[i]))
                        {
                                minval = abs(v[i]);
                                idx = i;
                        }
                }

                for(int i = 0; i < N; i++)
                {
                        if(i != idx) v[i] = abs(v[i]);
                        else v[i] = -1 * abs(v[i]);
                }
        }
        else
        {
                for(int i = 0; i < N; i++)
                {
                        v[i] = abs(v[i]);
                }
        }

        long long sum = 0;
        for(int i = 0; i < N; i++)
        {
                sum += v[i];
        }

        cout << sum << endl;
        return 0;
}

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

int main()  
{   
    cin.tie(0); ios::sync_with_stdio(false);  
	int n, k; cin >> n >> k;
	double ans = 0;
	if (n  < k) {
		for (int i = 1; i <= n; i++) {
			double t;
			t = 1./n;
			for (int j = i; j < k; j*=2)
				t *= 1./2;
			ans += t;
		}
		cout << std::setprecision(9) << ans << endl;
	}
	else {
		for (int i = 1; i < k; i++) {
			double t;
			t = 1./n;
			for (int j = i; j < k; j*=2)
				t *= 1./2;
			ans += t;
		}
		for (int i =  k; i <= n; i++) {
			ans += 1./n;
		}
		cout << std::setprecision(9) << ans << endl;
	}
	return 0;   
}  

Measured memory_bytes: 256
using System;
class c
{
    static void Main()
    {
        var s = Console.ReadLine();
        var t = Console.ReadLine();
        int ans = 0;
        for (int i = 0; i < s.Length; i++)
        {
            if (s[i] != t[i]) ans++;
        }
        Console.WriteLine(ans);
    }
}

Measured memory_bytes: 27316
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigDecimal;
import java.math.RoundingMode;

public class Main
{

  public static void main(String[] args) throws NumberFormatException, IOException
  {
    BufferedReader input = new BufferedReader(new InputStreamReader(System.in));

    while (input.ready())
    {
      double num = Double.valueOf(input.readLine());
      if (num < 0)
      {
        break;
      }
      BigDecimal ans = new BigDecimal(getThirdRoot(num, num / 2)).setScale(6,
          RoundingMode.HALF_DOWN);
      System.out.println(ans.toPlainString());
    }

  }

  private static double getThirdRoot(double q, double x)
  {
    if (Math.abs(Math.pow(x, 3) - q) < 0.00001 * q)
    {
      return x;
    }

    return getThirdRoot(q, x - ((Math.pow(x, 3) - q) / (3 * Math.pow(x, 2))));

  }

}

Measured memory_bytes: 24632
package main

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

func main() {
	io := newIo()
	defer io.Flush()
	k := io.NextInt()
	t := io.NextInt()
	maxCake := 0
	for i := 0; i < t; i++ {
		n := io.NextInt()
		if n > maxCake {
			maxCake = n
		}
	}
	if k-maxCake >= maxCake {
		fmt.Println(0)
		return
	}
	fmt.Println(maxCake - 1 - (k - maxCake))
}

type io struct {
	reader    *bufio.Reader
	writer    *bufio.Writer
	tokens    []string
	nextToken int
}

func newIo() *io {
	return &io{
		reader: bufio.NewReader(os.Stdin),
		writer: bufio.NewWriter(os.Stdout),
	}
}

func (io *io) Flush() {
	err := io.writer.Flush()
	if err != nil {
		panic(err)
	}
}

func (io *io) NextLine() string {
	var buffer []byte
	for {
		line, isPrefix, err := io.reader.ReadLine()
		if err != nil {
			panic(err)
		}
		buffer = append(buffer, line...)
		if !isPrefix {
			break
		}
	}
	return string(buffer)
}

func (io *io) Next() string {
	for io.nextToken >= len(io.tokens) {
		line := io.NextLine()
		io.tokens = strings.Fields(line)
		io.nextToken = 0
	}
	r := io.tokens[io.nextToken]
	io.nextToken++
	return r
}

func (io *io) NextInt() int {
	i, err := strconv.Atoi(io.Next())
	if err != nil {
		panic(err)
	}
	return i
}

func (io *io) NextFloat() float64 {
	i, err := strconv.ParseFloat(io.Next(), 64)
	if err != nil {
		panic(err)
	}
	return i
}

func (io *io) PrintLn(a ...interface{}) {
	fmt.Fprintln(io.writer, a...)
}

func (io *io) Printf(format string, a ...interface{}) {
	fmt.Fprintf(io.writer, format, a...)
}

func (io *io) PrintIntLn(a []int) {
	b := []interface{}{}
	for _, x := range a {
		b = append(b, x)
	}
	io.PrintLn(b...)
}

func (io *io) PrintStringLn(a []string) {
	b := []interface{}{}
	for _, x := range a {
		b = append(b, x)
	}
	io.PrintLn(b...)
}

func log(name string, value interface{}) {
	fmt.Fprintf(os.Stderr, "%s=%+v\n", name, value)
}


Measured memory_bytes: 640
#include <stdio.h>
#include <string.h>

#define DEF_ELEM_MAX 1000000

typedef long long llong;

int S[DEF_ELEM_MAX];
int T[DEF_ELEM_MAX/3+1];
int G[DEF_ELEM_MAX/3+1];
int N;
int cnt;

/////////////////////////////////////////////////////////////////////////////////
//
/////////////////////////////////////////////////////////////////////////////////
void insertionSort(int *A, int n, int g)
{
	int i;
	int j;
	int v;

	for (i = g ; i < n ; i++ ) {
		v = A[i];
		j = i - g;
		while (j >= 0 && A[j] > v) {
			A[j+g] = A[j];
			j = j - g;
			cnt++;
		}
		A[j+g] = v;
	}
}

/////////////////////////////////////////////////////////////////////////////////
//
/////////////////////////////////////////////////////////////////////////////////
int shellSort(int *A, int n)
{
	int i;
	int m;
	int h;

	for ( m = 0, h = 1; ; ) {
		if ( h > n ) break;
		T[m++] = h;
		h = 3*h + 1;
	}
//	?????????????????????
	for ( i = 0 ; i < m ; i++) {
		G[i] = T[m-1-i];
	}

	for ( i = 0 ; i < m ; i++ ) {
		insertionSort(A, n, G[i]);
	}
	return m;
}

/////////////////////////////////////////////////////////////////////////////////
//
/////////////////////////////////////////////////////////////////////////////////
int main(void)
{
	int i;
	int m;
//
	scanf("%d", &N);
	for ( i = 0 ; i < N ; i++ ) {
		scanf("%d", &S[i] );
	}

	m = shellSort(S, N);

	printf("%d\n", m);
	for ( i = 0 ; i < m ; i++ ) {
		printf("%d", G[i]);
		if ( i < m-1) {
			printf(" ");
		} else {
			printf("\n");
		}
	}
	printf("%d\n", cnt);

	for ( i = 0 ; i < N ; i++ ) {
		printf("%d\n", S[i]);
	}

	return 0;
}

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

// int/long:		-2,147,483,648 - 2,147,483,647 (-2^31 <= int < 2^31)
// long/long long:	-9,223,372,036,854,775,808 - 9,223,372,036,854,775,807 (-2^63 <= long < 2^63)

// lower_bound(A.begin(), A.end(), N)
// upper_bound(...

// A.erase(unique(A.begin(), A.end()), A.end())

// bit: &/and, |/or, ^/xor, ~/not

// getline(cin, String)
// while (getline(cin, S)) {}

// #include <cstdio>
// int a;
// scanf("%d", &a);
// printf("%d\n", a);
//
// for (int i=0; i<n; ++i)
// 	scanf("%d", &a[i]);
//
// char c;
// scanf(" %c", &c);
//
// cout << "\n";

// cout <<fixed <<setprecision(10)

// priority_queue<int> q;
// priority_queue<int, vector<int>, less<int>> q; // Default: vector, less
// priority_queue<vector<int>, vector<vector<int>>, greater<vector<int>>> q;

// Graph
// Warshall-Floyd: Distance between each node, N^3
// Dijkstra: Distance from the start node, N^2
// DFS(Depth-First Search)

//
// Notes
//
// When specified less than N, try full scan.
// RE: empty vector
// Check Qs
// long/int
// xor -> count each bit
// Check values
// 	1,000,000 -> Loop
// 	100,000	-> vector(int:400KB, long:800KB) 

#define	INF (1<<30)
//1,073,741,824
//= 536,870,912 *2

#define	MOD 1000000007

/*
ll	myPow(ll x, ll n) {
	if (0==n)
		return 1;
	if (0==n%2)
		return myPow(x*x%MOD, n/2);
	else
		return x*myPow(x, n-1)%MOD;
}
*/
ll	myPow(ll x, ll n) {
	ll r=1;
	while(n>0)
		if (0==n%2) {
			x *=x;
			x %=MOD;
			n /=2;
		} else {
			r *=x;
			r %=MOD;
			n--;
		}
	return r;
}

#define	Rep0(i, n)	for (int i=0; i<n; i++)
#define	Rep1(i, n)	for (int i=1; i<=n; i++)
#define Sort(P)	sort(P.begin(), P.end())
#define Rev(P)	reverse(P.begin(), P.end())

int	main() {
	string  S="1  1  1  2  1  2  1  5  2  2  1  5  1  2  1  14 1  5  1  5  2  2  1  15 2  2  5  4  1  4  1  51 ";
	int K;
	cin >>K;
	int s=0;
	int ix=0;
	int i=(K-1)*3;
	while (S.at(i)!=' ') {
		s*=10;
		s+=S.at(i)-'0';
		i++;
	}
	cout <<s <<endl;
	return 0;
}



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


int main()
{
  int  n, m, ans = -1, cnt = 0;
  cin >> n >> m;
  vector<int> a(m);
  for(int i = 0; i < m; i++){
    cin >> a[i];
    cnt += a[i];
  }
  ans = n - cnt;
  if(ans <= -1){
    ans = -1;
  }
  
  cout << ans <<endl;
}

Measured memory_bytes: 3660
import java.io.*;

class Main {
    public static void main (String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] input;
        int m, f, r, sum;
        char grade;

        while (true) {
            input = br.readLine().split(" ");
            m = Integer.parseInt(input[0]);
            f = Integer.parseInt(input[1]);
            r = Integer.parseInt(input[2]);
            sum = m + f;

            if (m == -1 && f == -1 && r == -1) {
                break;
            }

            if (m == -1 || f == -1 || sum < 30) {
                grade = 'F';
            } else if (sum >= 80) {
                grade = 'A';
            } else if (sum >= 65) {
                grade = 'B';
            } else if (sum >= 50 || (sum >= 30 && r >= 50)) {
                grade = 'C';
            } else {
                grade = 'D';
            }

            System.out.println(grade);
        }
    }
}

Measured memory_bytes: 24088
H, W = map(int, input().split())
S = [input() for _ in range(H)]

cnt = [[0]*W for _ in range(H)]

for i in range(H):
    done = [0]*W
    
    for j in range(W):
        if S[i][j] == "#":
            continue
        if done[j]:
            continue
        l = 0
        while j+l < W:
            if S[i][j+l] == "#":
                break
            l += 1
        for k in range(l):
            cnt[i][j+k] += l
            done[j+k] = 1

for j in range(W):
    done = [0]*H
    
    for i in range(H):
        if S[i][j] == "#":
            continue
        if done[i]:
            continue
        l = 0
        while i+l < H:
            if S[i+l][j] == "#":
                break
            l += 1
        for k in range(l):
            cnt[i+k][j] += l
            done[i+k] = 1

ans = 0

for i in range(H):
    for j in range(W):
        ans = max(ans, cnt[i][j]-1)

print(ans)

Measured memory_bytes: 111476
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <algorithm>
#include <string>

using namespace std;

int main(void){
	int a, b;
	double ans;
	cin >> a >> b;
	ans = ( double ) ( a * b ) / 3.305785;
	printf("%.6lf\n",ans);

    return 0;
}

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

int H,W;
int dx[4] = {-1,1,0,0},dy[4] = {0,0,1,-1};
char G[51][51];
int main(){
	cin >> H >> W;
	for(int i=0;i<H;i++){
		for(int j=0;j<W;j++){
			cin >> G[i][j];
		}
	}
	bool judge = true;
	for(int i=0;i<H;i++){
		for(int j=0;j<W;j++){
			if(G[i][j] == '#'){
				bool u = false;
				for(int k=0;k<4;k++){
					int x = i + dx[k],y = j+dy[k];
					if(0<=x && x <= H && 0<= y && y <= W && G[x][y]=='#') u = true;
				}
				if(!u) judge = false;
			}
		}
	}
	if(judge) cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 256
import java.util.ArrayDeque;
import java.util.Scanner;

public class Main {

	static int maze[][];
	static 	int maze_x;
	static 	int maze_y;
	static int goal_x;
	static int goal_y;
	static int result;
	static ArrayDeque<int[]> deque_list = new ArrayDeque<>();

	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		maze_x = sc.nextInt();
		maze_y =sc.nextInt();
		maze = new int[maze_x][maze_y];
		int wiz_x = sc.nextInt()-1;
		int wiz_y = sc.nextInt()-1;
		goal_x = sc.nextInt()-1;
		goal_y = sc.nextInt()-1;


		String tmpString;
		for(int i=0;i<maze_x;i++) {
			tmpString = sc.next();
			for(int j=0;j<tmpString.length();j++) {
				if(tmpString.charAt(j) == '#') {
					maze[i][j] = -2;
				}else {
					maze[i][j] = -1;
				}
			}
		}

		deque_list.add(new int[]{0,wiz_x,wiz_y});

		result = -1;

		int[] tmpIntArray;
		while(deque_list.size() != 0) {
			tmpIntArray = deque_list.getFirst();
			deque_list.removeFirst();
			paint_maze(tmpIntArray);
			if(result != -1) {
				break;
			}
			input_walk(tmpIntArray);
			input_magic(tmpIntArray);
		}

		System.out.println(result);

	}
	public static void input_walk(int[] paint_order) {
		if(check_order(paint_order[1]-1,paint_order[2])) {
			deque_list.addFirst(new int[]{paint_order[0],paint_order[1]-1,paint_order[2]});
		}

		if(check_order(paint_order[1]+1,paint_order[2])) {
			deque_list.addFirst(new int[]{paint_order[0],paint_order[1]+1,paint_order[2]});
		}

		if(check_order(paint_order[1],paint_order[2]-1)) {
			deque_list.addFirst(new int[]{paint_order[0],paint_order[1],paint_order[2]-1});
		}

		if(check_order(paint_order[1],paint_order[2]+1)) {
			deque_list.addFirst(new int[]{paint_order[0],paint_order[1],paint_order[2]+1});
		}

	}

	public static void input_magic(int[] paint_order) {
		for(int i=-2;i<=2;i++) {
			for(int j=-2;j<=2;j++) {
				if(check_order(paint_order[1]+i,paint_order[2]+j)) {
					deque_list.addLast(new int[]{paint_order[0]+1,paint_order[1]+i,paint_order[2]+j});
				}
			}
		}
	}

	public static boolean check_order(int x,int y){
		if(x < 0 || x >= maze_x) {
			return false;
		}

		if(y < 0 || y >= maze_y) {
			return false;
		}

		if(maze[x][y] != -1) {
			return false;
		}

		return true;
	}

	public static void paint_maze(int[] paint_order) {
		if(paint_order[1]==goal_x && paint_order[2]==goal_y) {
			result = paint_order[0];
			return;
		}
		maze[paint_order[1]][paint_order[2]] = paint_order[0];
	}

	public static void print_maze() {
		for(int i=0;i<maze_x;i++) {
			for(int j=0;j<maze_y;j++) {
				System.out.print(maze[i][j]);
			}
			System.out.println("");
		}
	}

}


Measured memory_bytes: 99780
import sys
N=int(input())
A=list(map(int,input().split()))
a=len([i for i in A if i%4==0])
b=len([i for i in A if i%4==2])
if b==0:
  if a*2+1>=N:
    print("Yes")
    sys.exit()
  else:
    print("No")
    sys.exit()
if a*2+b>=N:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 19980
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; (i) < (int)(n); ++ (i))
#define ALL(x) std::begin(x), std::end(x)
using namespace std;
template <class T, class U> inline void chmin(T & a, U const & b) { a = min<T>(a, b); }

int solve(int n, const vector<int64_t> & x, const vector<int64_t> & len) {
    vector<pair<int64_t, int64_t> > que;
    REP (i, n) {
        que.emplace_back(x[i] - len[i], x[i] + len[i]);
    }
    sort(ALL(que));
    int cnt = 0;
    int64_t y = INT64_MIN;
    for (auto it : que) {
        int64_t l, r; tie(l, r) = it;  // (l, r)
        if (y <= l) {
            ++ cnt;
            y = r;
        } else {
            chmin(y, r);
        }
    }
    return cnt;
}

int main() {
    int n; cin >> n;
    vector<int64_t> x(n), l(n);
    REP (i, n) {
        cin >> x[i] >> l[i];
    }
    cout << solve(n, x, l) << endl;
    return 0;
}


Measured memory_bytes: 3956
#!/usr/bin/env python3
import sys
import math

def solve(N: int, K: int):
    ans = .0
    for i in range(1,N+1):
        if(i <= K):
            t = math.ceil(math.log2(K/i))
            ans += (1/N) * (1/2) ** t
        else:
            ans += 1/N

    print(ans)
    
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    solve(N, K)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <complex>
#include <utility>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#include <set>
#include <map>
#include <unordered_map>
#include <numeric>
#include <functional>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
inline void Yes(bool condition){ if(condition) PRINT("Yes"); else PRINT("No"); }
template<class itr> void cins(itr first,itr last){
    for (auto i = first;i != last;i++){
        cin >> (*i);
    }
}
template<class itr> void array_output(itr start,itr goal){
    string ans = "",k = " ";
    for (auto i = start;i != goal;i++) ans += to_string(*i)+k;
    if (!ans.empty()) ans.pop_back();
    PRINT(ans);
}
ll gcd(ll a, ll b) {
    return a ? gcd(b%a,a) : b;
}
const ll INF = 1e18;
const ll MOD = 1000000007;
const ll MOD2 = 998244353;
typedef pair<ll,ll> P;
typedef pair<double,double> point;
const ll MAX = 200000;
constexpr ll nx[8] = {1,0,-1,0,1,-1,1,-1};
constexpr ll ny[8] = {0,1,0,-1,1,1,-1,-1};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,k;
    cin >> n >> k;
    vector<ll> a(n),p(n+1,0),m(n+1,0);
    rep(i,n){
        cin >> a[i];
        m[i+1] = m[i]+a[i];
        if (a[i] > 0){
            p[i+1] = p[i]+a[i];
        }
        else{
            p[i+1] = p[i];
        }
    }
    ll ans = -INF;
    rep(i,n-k+1){
        chmax(ans,max(m[i+k]-m[i],0ll)+p[i]+p[n]-p[i+k]);
    }
    PRINT(ans);
}


Measured memory_bytes: 2560
import java.util.Scanner;

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

        int n = Integer.parseInt(scan.nextLine());
        String a = scan.nextLine();
        String b = scan.nextLine();
        String c = scan.nextLine();

        int count = 0;

        for(int i=0; i<n; i++) {
            char ai = a.charAt(i);
            char bi = b.charAt(i);
            char ci = c.charAt(i);
            if(ai==bi && bi==ci) {
                // non
            }else if(ai != bi && ai != ci && bi != ci) {
                count += 2;
            } else {
                count++;
            }
        }

        System.out.println(count);
    }
}


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

using namespace std;

int gcd(int x, int y) {
    if(x==0){
        return y;
    }else if(y==0){
        return x;
    }
    return y ? gcd(y, x%y) : x;
}

int main(){
    int N,ans=0;
    cin >> N;
    vector<int> A(N),F(N+1),B(N+1);

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

    F[0] = 0;
    B[N] = 0;

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

    for(int i=N-1;0<=i;i--){
        B[i] = gcd(B[i+1],A[i]);
    }

    for(int i=0;i<N+1;i++){
        ans = max(ans,gcd(F[i],B[i+1]));
    }

    cout << ans << endl;
}

Measured memory_bytes: 1408
n, *a_l= map(int, open(0).read().split())
odd = 1
for a in a_l:
    tmp_odd = 0
    for i in [a-1, a, a+1]:
        if i % 2 == 1:
            tmp_odd += 1
    odd *= tmp_odd
ans = 3**n - odd
print(ans)

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

int main() {
  int D;
  cin>>D;
  if(D==25) cout<<"Christmas"<<endl;
  else if (D==24) cout<<"Christmas Eve"<<endl;
  else if (D==23) cout<<"Christmas Eve Eve"<<endl;
  else cout<<"Christmas Eve Eve Eve"<<endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

	/**
	 * @param args
	 */
	
	static Scanner sc = new Scanner(System.in);
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		int[] num = new int[5];
		for(int i = 0; i < 5; i++) {
			num[i] = sc.nextInt();
		}
		Arrays.sort(num);
		for(int i = 4; i >= 0; i--) {
			if(i == 0) {
				System.out.print(num[i]);
			} else {
				System.out.print("" + num[i] + " ");
			}
		}
		System.out.println("");
	}
}

Measured memory_bytes: 11000
package main

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

func solve(sc *scanner, wr *bufio.Writer) {
	a := make([][]int, 3)
	for i := range a {
		a[i] = sc.getInts(3)
	}
	n := sc.getInt()
	bs := sc.getInts(n)

	for _, b := range bs {
		for i := range a {
			for j := range a[i] {
				if b == a[i][j] {
					a[i][j] = -1
				}
			}
		}
	}

	bingo := func() bool {
		ret := false
		for i := 0; i < 3; i++ {
			if a[i][0] == a[i][1] && a[i][0] == a[i][2] {
				ret = true
			}
			if a[0][i] == a[1][i] && a[0][i] == a[2][i] {
				ret = true
			}
		}
		if a[0][0] == a[1][1] && a[0][0] == a[2][2] {
			ret = true
		}
		if a[0][2] == a[1][1] && a[0][2] == a[2][0] {
			ret = true
		}
		return ret
	}
	ans := "No"
	if bingo() {
		ans = "Yes"
	}
	fmt.Fprintln(wr, ans)
}

func main() {
	sc := newScanner()
	wr := bufio.NewWriter(os.Stdout)
	maxBufSize := int(1e8)
	sc.Buffer(make([]byte, 4096), maxBufSize)
	sc.Split(bufio.ScanWords)

	solve(sc, wr)
	wr.Flush()
}

// input ------------------------
type scanner struct {
	*bufio.Scanner
}

func newScanner() *scanner {
	sc := bufio.NewScanner(os.Stdin)
	return &scanner{sc}
}
func (sc *scanner) getInt() int {
	sc.Scan()
	ret, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return ret
}
func (sc *scanner) getInt2() (int, int) {
	return sc.getInt(), sc.getInt()
}
func (sc *scanner) getInt3() (int, int, int) {
	return sc.getInt(), sc.getInt(), sc.getInt()
}
func (sc *scanner) getInt4() (int, int, int, int) {
	return sc.getInt(), sc.getInt(), sc.getInt(), sc.getInt()
}
func (sc *scanner) getInts(n int) []int {
	ret := make([]int, n)
	for i := range ret {
		ret[i] = sc.getInt()
	}
	return ret
}
func (sc *scanner) getString() string {
	sc.Scan()
	return sc.Text()
}
func (sc *scanner) getRunes() []rune {
	return []rune(sc.getString())
}
func (sc *scanner) getFloat() float64 {
	sc.Scan()
	ret, err := strconv.ParseFloat(sc.Text(), 64)
	if err != nil {
		panic(err)
	}
	return ret
}
func (sc *scanner) getFloats(n int) []float64 {
	ret := make([]float64, n)
	for i := range ret {
		ret[i] = sc.getFloat()
	}
	return ret
}

// math ----------------------------
func sum(ns ...int) int {
	var sum int
	for _, n := range ns {
		sum += n
	}
	return sum
}

func max(ns ...int) int {
	max := ns[0]
	for i := 1; i < len(ns); i++ {
		if max < ns[i] {
			max = ns[i]
		}
	}
	return max
}

func min(ns ...int) int {
	min := ns[0]
	for i := 1; i < len(ns); i++ {
		if min > ns[i] {
			min = ns[i]
		}
	}
	return min
}

func pow(a, b int) int {
	ret := 1
	for b > 0 {
		if b&1 > 0 {
			ret = ret * a
		}
		a = a * a
		b >>= 1
	}
	return ret
}


Measured memory_bytes: 1784
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <string.h>

char lower(char c) {
	if ('A' <= c && c <= 'Z') {
		c = c + ('a' - 'A');
	}
	return c;
}

int main(void) {

	char c;

	char W[11] = { 0 }; // word
	char T[1001] = { 0 };// 文章

	int wordCount = 0;
	

	int wn = 0;

	while ( (c = getchar()) != EOF) {
		if (c == '\n') {
			break;
		}
		W[wn++] = c;
	}

	int limit = 0;

	while (1) {
		scanf("%s", &T);
		if (strcmp(T, "END_OF_TEXT") ==0) {
			break;
		}

		int i = 0;
		for (; i < 1000; i++) {
			T[i] = lower(T[i]);
		}
		if (strcmp(T,W) ==0) {
			wordCount++;
		}
		if (limit++ > 100000) {
			break;
		}
	}
	

	printf("%d\n", wordCount);

	return 0;
}


Measured memory_bytes: 2052
def selection(n, arr)
    c = 0
    0.upto(n-1) do |i|
        minj = i
        i.upto(n-1) do |j|
            if arr[j] < arr[minj] then
                minj = j
            end
        end
        if i != minj then
            arr[i], arr[minj] = arr[minj], arr[i]
            c += 1
        end
    end
    puts arr.join(" ")
    p c
end
selection(gets.to_i, gets.split.map(&:to_i))

Measured memory_bytes: 8628
#include<bits/stdc++.h>
// Begin Header {{{
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i,n) for(ll i=0; i<n; i++)
#define loop(i, j, n) for(ll i=j; i<n; i++)
#define all(x) (x).begin(), (x).end()
constexpr int INF  = 0x3f3f3f3f;
const long long mod=1e9+7;
const long double PI = acos(-1);
template <class T>void UNIQUE(vector<T> &x){
	sort(all(x));
	x.erase(unique(all(x)), x.end());
}

// }}} End Header
int main() {
	string s;
	cin >> s;
	vector<int> a(4);
	rep(i,4) a[i] = s[i]-'0';

	for(int bit = 0; bit<(1<<3); bit++){
		string t = to_string(a[0]);
		int sum = a[0];
		for(int i = 0; i<3; i++){
			if(bit&(1<<i)){
				sum+=a[i+1];
				t+="+";
				t+=to_string(a[i+1]);
			}else{
				sum-=a[i+1];
				t+="-";
				t+=to_string(a[i+1]);
			}
		}

		if(sum == 7){
			cout << t << "=7" <<endl;
			return 0;
		}
	}


	return 0;
}


Measured memory_bytes: 3700
N=int(input())
# a=int(input())
# a,b=map(int,input().split(" "))
A=[int(_) for _ in input().split(" ")]

if A[0] == 0:
    ans=0
    print(ans)
    exit()
else:
    ans=A[0]

for i in range(1,N):
    if A[i] == 0:
        ans=0
        break
    elif ans < 0:
        ans = -1
    elif A[i] == 10**18:
        ans = -1
    else:
        ans *= A[i]
        if ans > 10**18:
            ans = -1

print(ans)


Measured memory_bytes: 21692
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>

using namespace std;

#define int long long
// #define cerr if (false) cerr

const int MOD = 998244353;

int mul(int a, int b) {
	int res = a * b;
	return res % MOD;
}

int get(char c) {
	if (c == 'R') {
		return 0;
	}
	if (c == 'G') {
		return 1;
	}
	if (c == 'B') {
		return 2;
	}
	assert(false);
	return -1;
}

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

	int n;
	cin >> n;
	string s;
	cin >> s;
	int ans = 1;
	vector<int> cnt(3);
	vector<int> prs(3);
	for (auto t : s) {
		int c = get(t);
		if (c == 0) {
			cnt[0]++;
			if (cnt[0] > 0 && prs[0] > 0) {
				ans = mul(ans, prs[0]);
				cnt[0]--;
				prs[0]--;
			}
			if (cnt[0] > 0 && cnt[1] > 0) {
				ans = mul(ans, cnt[1]);
				cnt[0]--;
				cnt[1]--;
				prs[2]++;
			}
			if (cnt[0] > 0 && cnt[2] > 0) {
				ans = mul(ans, cnt[2]);
				cnt[0]--;
				cnt[2]--;
				prs[1]++;
			} 
		}
		if (c == 1) {
			cnt[1]++;
			if (cnt[1] > 0 && prs[1] > 0) {
				ans = mul(ans, prs[1]);
				cnt[1]--;
				prs[1]--;
			}
			if (cnt[1] > 0 && cnt[0] > 0) {
				ans = mul(ans, cnt[0]);
				cnt[1]--;
				cnt[0]--;
				prs[2]++;
			}
			if (cnt[1] > 0 && cnt[2] > 0) {
				ans = mul(ans, cnt[2]);
				cnt[1]--;
				cnt[2]--;
				prs[0]++;
			} 
		}
		if (c == 2) {
			cnt[2]++;
			if (cnt[2] > 0 && prs[2] > 0) {
				ans = mul(ans, prs[2]);
				cnt[2]--;
				prs[2]--;
			}
			if (cnt[2] > 0 && cnt[0] > 0) {
				ans = mul(ans, cnt[0]);
				cnt[2]--;
				cnt[0]--;
				prs[1]++;
			}
			if (cnt[2] > 0 && cnt[1] > 0) {
				ans = mul(ans, cnt[1]);
				cnt[2]--;
				cnt[1]--;
				prs[0]++;
			} 	
		}
	}
	for (int i = 1; i <= n; i++) {
		ans = mul(ans, i);
	}
	cout << ans << endl;
}


Measured memory_bytes: 720
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<bool> vb;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define in insert
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int INF = 1e9 + 5;
int main(){
    int n;
    cin >> n;
    double sum = 0;
    for(int i = 0; i < n; i++){
        double x;
        cin >> x;
        string s;
        cin >> s;
        if(s == "BTC") sum += x * 380000;
        else sum += x;
    }
    cout << fixed << setprecision(6) << sum;
}

Measured memory_bytes: 256
//
//  main.cpp
//  Atcoder1
//
//  Created by Hamske on 2020/09/17.
//  Copyright © 2020 Author. All rights reserved.
//

#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <string>

using namespace std;

//#define pb push_back
//#define mp make_pair
//
//#define F first
//#define S second

typedef long long ll;

#define rept(_i,iv,n,type) for(type _i=(type)(iv);_i<(type)(n);++_i)
//#define repi(_i,iv,n) rept(_i,iv,n,int)
//#define repl(_i,iv,n) rept(_i,iv,n,ll)

#define rept0(_i,n,type) rept(_i,0,n,type)
#define repi0(_i,n) rept(_i,0,n,int)
#define repl0(_i,n) rept(_i,0,n,ll)

//#define repst(_i,iv,n,type) for(type _i=iv;_i<=(type)(n);++_i)
//#define repsi1(_i,n) repst(_i,1,n,int)

#define REPT(_i,iv,_l,n,type) for(type _i=(type)(iv),_l=(type)(n);_i<_l;++_i)
//#define REPI(_i,iv,_l,n) REPT(_i,iv,_l,n,int)
//#define REPL(_i,iv,_l,n) REPT(_i,iv,_l,n,ll)
//
#define REPT0(_i,_l,n,type) REPT(_i,0,_l,n,type)
#define REPI0(_i,_l,n) REPT(_i,0,_l,n,int)
#define REPL0(_i,_l,n) REPT(_i,0,_l,n,ll)


//#define rrept(_i,x,e,type) for(type _i=((type)(x)-1);_i>=e;--_i)
//
//#define rrept0(_i,x,type) rrept(_i,x,0,type)
//
//#define RREPT(_i,x,_e,e,type) for(type _i=((type)(x)-1),_e=(type)(e);_i>=_e;--_i)
//
//#define RREPT0(_i,x,_e,type) RREPT(_i,x,_e,0,type)
//
//#define RREPS(i,x) for(int i=((int)(x));i>0;i--)

//#define all(x) (x).begin(),(x).end()
#define REPV(v,_itr,_end) for(auto _itr=(v).begin(),_end=(v).end();_itr!=_end;++_itr)
#define REPVC(v,_itr,_end) for(auto _itr=(v).cbegin(),_end=(v).cend();_itr!=_end;++_itr)

#define td typedef
//#define tds(stl,type,name) typedef stl<type > name;
#define tdv(type,name) typedef vector<type > name;


//typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<vb > vvb;
typedef vector<int> vi;
typedef vector<vi > vvi;
//typedef vector<ll> vll;
//typedef vector<vll > vvll;

#define mod99 998244353

int main(int argc, const char * argv[]) {
    int N,K;
    cin>>N>>K;
    
    vi L(K),R(K);
    repi0(k, K){
        cin>>L[k]>>R[k];
    }
    
    vi dp(N,0);
    vi sums(N,0);
    dp[0]=1;
    sums[0]=1;
    for(int i=1;i<N;++i){
        ll sum=0;
        repi0(k, K){
            int l=i-L[k],r=i-R[k];
            if(l<0){
                continue;
            }
            int sr;
            if(r<=0){
                sr=0;
            }else{
                sr=sums[r-1];
            }
            sum+=sums[l];
            sum%=mod99;
            if(sum<0){
                sum+=mod99;
            }
            sum-=sr;
            sum%=mod99;
            if(sum<0){
                sum+=mod99;
            }
        }
        dp[i]=(int)sum;
        ll nsum=(ll)sums[i-1]+dp[i];
        nsum%=mod99;
        if(nsum<0){
            nsum+=mod99;
        }
        sums[i]=(int)(nsum%mod99);
    }
    cout<<dp[N-1]<<endl;
    
    return 0;
}


Measured memory_bytes: 4428
from math import ceil
from itertools import permutations
X=[]
for i in range(5):
    a=int(input())
    X.append(a)
Z=list(permutations(X))
m=10**10
for A in Z:
    num=0
    for k in range(5):
        if k==4:
          num+=A[k]
          break
        num+=int(ceil(A[k]/10))*10
    m=min(m,num)
print(m)


Measured memory_bytes: 38384
#include <bits/stdc++.h>
#include <functional>
#include <iostream>
#define  pb push_back
#define  xx first
#define  yy second
//#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

using namespace std;

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

      ll bigmod ( long long a, int p, int m )
{
    if ( p == 0 )return 1; // If power is 0 ( a ^ 0 ), return 1

    if ( p & 1 ) // If power is odd
    {
        return ( ( a % m ) * ( bigmod ( a, p - 1, m ) ) ) % m;
    }
    else
    {
        long long tmp = bigmod ( a, p / 2, m );
        return ( tmp * tmp ) % m;
    }
}

int main()
{
         ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
           int t=1,caseno = 0;

   // scanf("%d",&t);

     while(t--){
      string s;
       int a,cnt = 0,q;
       cin >> s;
       cin >> q;
       int l = 0,r = 1;
       string L = "",R = "";
       while(q--){
        int T;
        cin >> T;
       int f;
        if(T==1){
            cnt++;
            swap(R,L);
        }
        else{

        char c;
           cin >> f >> c;
           if(f==1){
            if(cnt%2==0){
                L = c+L;
            }
            else L = L+c;
         }
         else{

            if(cnt%2==0){
                R = R+c;
            }
            else{
                R = c+R;
            }
         }
       }
    }

      if(cnt%2)
     reverse(s.begin(),s.end());
        string ans = s;
        if(cnt%2){
            reverse(L.begin(),L.end());
        }
        if(cnt%2){
            reverse(R.begin(),R.end());
        }
        ans =L+ans;
        ans+=R;
        cout << ans << endl;
    }

    return 0;
}



Measured memory_bytes: 1420
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <climits>
#include <iomanip>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
long long mod = 1000000007;
long long modpow(long long m,long long n){
    long long res = 1;
    if(n > 0){
        res = modpow(m,n / 2);
        if(n % 2 == 0){
            res = (res * res) % mod;
        }
        else{
            res = (((res * res) % mod) * m) % mod;
        }
    }
    return res;
}
int main(){
    ll n;
    cin >> n;
    ll res = 0;
    res = modpow(10,n);
    res -= 2 * modpow(9,n);
    while(res < 0)res += mod;
    res %= mod;
    res += modpow(8,n);
    res %= mod;
    cout << res << endl;
}

Measured memory_bytes: 3620
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define reps(i, n) for (int i = 1; i <= (n); ++i)
#define repd(i, n) for (int i = (n - 1); i >= 0; --i)
#define repds(i, n) for (int i = (n); i > 0; --i)
#define loop(i, x, n) for (int i = (x); i < (n); ++i)
#define loops(i, x, n) for (int i = (x); i <= (n); ++i)
#define loopd(i, x, n) for (int i = (x); i > (n); --i)
#define loopds(i, x, n) for (int i = (x); i >= (n); --i)
#define itrep(i, a) for (auto i = begin(a); i != end(a); ++i)
#define itrepd(i, a) for (auto i = rbegin(a); i != rend(a); ++i)
#define each(i, x) for (auto &i : x)
#define all(x) x.begin(), x.end()
using namespace std;
using ll = long long;
using ld = long double;
template <class T>
using priority_queuel = priority_queue<T, vector<T>, greater<T>>;
constexpr ll inf = static_cast<ll>(1e18);
constexpr int iinf = static_cast<int>(1e9);
constexpr double dinf = 1e10;
constexpr ld ldinf = 1e18;
constexpr double eps = 1e-9;
ll mod = static_cast<ll>(1e9 + 7);
template <class T>
constexpr int sz(const T &a) { return (int)a.size(); }
template <class T>
constexpr T pow2(const T a) { return a * a; }
template <class T, class... Args>
constexpr void mins(T &a, Args... args) { a = min<T>({a, args...}); }
template <class T, class... Args>
constexpr void maxs(T &a, Args... args) { a = max<T>({a, args...}); }
template <class A, int N, class T>
void fillArray(A (&array)[N], const T &val) { std::fill((T *)array, (T *)(array + N), val); }

int n, k;
ll h[305];
ll dp[305][305];
void solve() {
    cin >> n >> k;
    reps(i, n) cin >> h[i];

    ++n;
    fillArray(dp, inf);
    dp[0][0] = 0;
    rep(i, n) rep(j, k + 1) loops(l, i + 1, n) {
        auto nj = j + l - i - 1;
        if (nj > k) break;
        mins(dp[l][nj], dp[i][j] + max(0LL, h[l] - h[i]));
    }

    ll ans = inf;
    rep(j, k + 1) mins(ans, dp[n][j]);
    cout << ans << endl;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
    cout.flush();
    return 0;
}


Measured memory_bytes: 1024
#ABC-126-A
N, K = map(int, input().split())
S = list(input())

change_char = S[K-1]
if change_char == "A":
    S[K-1] = "a"
elif change_char == "B":
    S[K-1] = "b"
else:
    S[K-1] = "c"

print("".join(S))

Measured memory_bytes: 3060
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 100000000000000000
#define int long long
vector<int> v[2];
bool isOK(int index, int key, int k) {
    if (v[k][index] >= key) return true;
    else return false;
}

// 汎用的な二分探索のテンプレ
int binary_search(int key, int k) {
    int ng = -1; //「index = 0」が条件を満たすこともあるので、初期値は -1
    int ok = (int)v[k].size(); // 「index = a.size()-1」が条件を満たさないこともあるので、初期値は a.size()

    /* ok と ng のどちらが大きいかわからないことを考慮 */
    while (abs(ok - ng) > 1) {
        int mid = (ok + ng) / 2;

        if (isOK(mid, key, k)) ok = mid;
        else ng = mid;
    }
    return ok;
}

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);   
    int A, B, Q;
    cin >> A >> B >> Q;
    v[0].push_back(-INF2);
    v[1].push_back(-INF2);
    rep(i, A) {
        int s; cin >> s;
        v[0].push_back(s);
    }
    rep(i, B) {
        int s; cin >> s;
        v[1].push_back(s);
    }
    v[0].push_back(INF2);
    v[1].push_back(INF2);
    rep(i, Q) {
        int x; cin >> x;
        int idxLa = binary_search(x, 0) - 1;
        int idxLb = binary_search(x, 1) - 1;
        int La = v[0][idxLa];
        int Lb = v[1][idxLb];
        int Ra = v[0][idxLa + 1];
        int Rb = v[1][idxLb + 1];
        //cout << La << " " << Lb << " " << Ra << " " << Rb << endl;
        cout << min({abs(x - min(La, Lb)), 
                     abs(x - max(Ra, Rb)), 
                     abs(x - La) + abs(La - Rb), 
                     abs(x - Ra) + abs(Ra - Lb),
                     abs(x - Rb) + abs(Rb - La),
                     abs(x - Lb) + abs(Lb - Ra)}) << endl;
    }




    return 0;
}


Measured memory_bytes: 3060