akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <vector>
#include <array>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <tuple>
#include <cmath>
#include <algorithm>
#include <functional>
#include <numeric>
#include <cfloat>
#include <climits>
#include <cassert>
#include <random>
class UnionFind {
	std::vector<int> vec;
public:
	UnionFind(int size) : vec(size, -1) {}
	int find(int a) {
		return vec[a] < 0 ? a : vec[a] = find(vec[a]);
	}
	bool same(int a, int b) {
		return find(a) == find(b);
	}
	void unite(int a, int b) {
		a = find(a);
		b = find(b);
		if (a != b) {
			if (vec[a] > vec[b]) std::swap(a, b);
			vec[a] += vec[b];
			vec[b] = a;
		}
	}
	int size_of(int a) {
		return -vec[find(a)];
	}

};

int main(){
	constexpr long long int MOD = 1000000007;
	while (true) {
		int n, m; std::cin >> n >> m; if (n == 0 && m == 0) break;
		UnionFind uft(n + 1);
		for (auto i = 0; i < m; ++i) {
			int a, b; std::cin >> a >> b; --a; --b;
			uft.unite(a, b);
		}
		long long int result = 1;
		for (auto i = 0; i < n; ++i) if (!uft.same(i, n)){
			result <<= 1;
			result %= MOD;
			uft.unite(i, n);
		}
		if (m != 0) ++result;
		std::cout << result << std::endl;
	}
}


Measured memory_bytes: 3400
#include <bits/stdc++.h>
 
using namespace std;
 
#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
 
int main() {
  int n,m,t,count = 0;
  cin >> n >> m >>t;
  int T[10001] = {};
  int a[n];
  for(int i = 0;i < n;i++){
    cin >> a[i];
    for(int j = max(0,a[i]-m);j <= min(10000,a[i] + m);j++){
      T[j] = 1;
    } 
  }
  for(int i = 0;i < t;i++){
    if(T[i] == 0 || T[i+1] == 0){
      count++;
    }
  }
  cout << count <<endl;
  return 0;
}

Measured memory_bytes: 3116
#include<iostream>
#include<cstdio>
#define maxn 2000010
using namespace std;
int n,tot=0,st=0;
int a[maxn],q1[maxn],q2[maxn],cnt[maxn];
int ans[2][10]={{0,1,0,1,1,2,1,0},{0,1,0,1,1,0,1,0}};
char s[maxn];
void solve(int l,int r,int now){
	int len=(q1[now]-q2[now-1])%q1[now];
	if(!len){
		for(register int i=l;i<=r;i++){
			st^=(1<<a[i]);
		}
	}
	else{
		int res=(r-l+1-len)>>1;
		solve(l,l+res-1,now-1);
		solve(r-res+1,r,now-1);
	}
}
int main(){
	scanf("%d%s",&n,s+1);
	bool flag=0; 
	for(register int i=1;i<=n;i++){
		if(s[i]=='2')flag=1;
		a[i]=s[i]-'1';
	}
	for(register int i=n,j=1,k=0;i;i>>=1,j<<=1){
		if(i&1){
			q1[++tot]=j;
			k+=j;
			q2[tot]=k;
		}
	}
	solve(1,n,tot);
	printf("%d",ans[flag][st]);
	return 0;
} 

Measured memory_bytes: 11520
#include <algorithm>
#include <climits>
#include <complex>
#include <cstring>
#include <iostream>
#include <map>
#include <set>
#include <vector>

// using
using namespace std;

// typedef
typedef long long ll;

// define
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REVERSE(c) reverse(ALL(c))
#define UNIQ(c) unique(ALL(c))
#define FOR(i, a, b, c) for (int i = (int)(a); i < (int)(b); i += (int)(c))
#define REP(i, n) FOR(i, 0, n, 1)
#define RFOR(i, a, b, c) for (int i = (int)(a); i >= (int)(b); i -= (int)(c))
#define RREP(i, n) RFOR(i, n, 0, 1)

// functions
template <class T> T ceil(T a, T b) {
    return (a + b - 1) / b;
}
int round(int a, int b) {
    return (a + b / 2) / b;
}
int gcd(int a, int b) {
    return b ? gcd(b, a % b) : a;
}
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}
template <class T> bool amax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> bool amin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}

// main
int main() {
    const int MAX_N = 1000;
    ll N, T, A;
    cin >> N;
    ll res[2] = {1, 1};
    REP(i, N) {
        cin >> T >> A;
        ll r = max(ceil(res[0], T), ceil(res[1], A));
        res[0] = T * r;
        res[1] = A * r;
    }
    cout << res[0] + res[1] << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
  int a=9;
  int b;
  int n;
  cin>>n;
  while(a>=1)
  {
    if(n%a==0)
    {
      b=n/a;
      break;
    }
    a--;
  }
  if(b<10)
    cout<<"Yes";
  else
    cout<<"No";
}

Measured memory_bytes: 256
X = open(0).readlines()
n = int(X[0])
F = []
for x in X[1:n+1]:
    F.append(list(map(int, x.split())))
P = []
for x in X[n+1:]:
    P.append(list(map(int, x.split())))

ans = -10**10
for i in range(1, 2**10):
    A = [(i >> j) & 1 for j in range(10)]
    s = 0
    for j in range(n):
        c = sum(p and a for p, a in zip(F[j], A))
        s += P[j][c]
    if ans < s:
        ans = s
print(ans)

Measured memory_bytes: 3188
n = gets.to_i
p = gets.split(" ").map(&:to_i)
p_ = p.sort
diff = 0

p.each_with_index do |pn, i|
  diff += 1 if pn != p_[i]
end

if diff == 2 || diff == 0
  puts "YES"
else
  puts "NO"
end

Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string s;
  cin >> s;
  int l = s.size();
  for(int i=1;i<l;i++){
    int l2 = l/2-i;
    string a = "",b = "";
    for(int j=0;j<l2;j++){
      a += s.at(j);
      b += s.at(j+l2);
    }
    if(a == b){
      cout << l2*2 << endl;
      return 0;
    }
  }
  return -1;
}

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

int main() {
  int n, k, ans = 0;
  cin >> n >> k;
  vector<int> p(n);
  for(int i = 0; i < n;i++){
    cin >> p.at(i);
  }
  sort(p.begin(), p.end());
  
  for(int i = 0; i < k; i++){
      ans += p.at(i);
    }
  
  cout << ans <<endl;
  
}


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

using namespace std;


const long long INF = 1LL << 60;

long long h[100010];

long long dp[100010];

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

    for (int i = 0; i < N; i++) cin >> h[i];

    for (int i = 0; i < 100010; i++) dp[i] = INF;

    dp[0] = 0;

    for (int i = 1; i < N; i++){
        dp[i] = min(dp[i], dp[i-1] + abs(h[i] - h[i-1]));

        if (i > 1){
            dp[i] = min(dp[i], dp[i-2] + abs(h[i] - h[i-2]));
        }
    }

    cout << dp[N-1] << endl;

    return 0;
}




Measured memory_bytes: 1792
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <climits>
#define MAX 105

using namespace std;

static const long long INF=(1LL<<32);

int v;
long long a[MAX][MAX];

void floyd() {
	int i,j,k;
	for(k=0;k<v;k++) {
		for(i=0;i<v;i++) {
			if(a[i][k]==INF) continue;
			for(j=0;j<v;j++) {
				if(a[k][j]==INF) continue;
				a[i][j]=min(a[i][j],a[i][k]+a[k][j]);
			}
		}
	}
}

int main() {
	int e,i,j,k;
	
	scanf("%d %d",&v,&e);
	
	for(i=0;i<v;i++) {
		for(j=0;j<v;j++) {
			if(i==j) a[i][j]=0;
			else a[i][j]=INF;
		}
	}
	
	for(i=0;i<e;i++) {
		int d1,d2,w;
		scanf("%d %d %d",&d1,&d2,&w);
		a[d1][d2]=w;
	}
	
	floyd();
	
	bool negative=false;
	for(i=0;i<v;i++) if(a[i][i]<0)	negative=true;
	
	if(negative) {
		printf("NEGATIVE CYCLE\n");
	} else {
		for(i=0;i<v;i++) {
			for(j=0;j<v;j++) {
				if(j!=0) printf(" ");
				if(a[i][j]==INF) printf("INF");
				else printf("%lld",a[i][j]);
			}
			printf("\n");
		}
	}
	
	return 0;
}


Measured memory_bytes: 3284
import java.util.*;

public class Main {
    public static void sort(int array[], int array2[], int left, int right){
        if(left <= right){
            int p = array[(left + right) >>> 1];
            int l = left;
            int r = right;
            while(l <= r){
                while (array[l] < p){
                    l++;
                }
                while (array[r] > p){
                    r--;
                }
                if (l <= r){
                    int tmp = array[l];
                    array[l] = array[r];
                    array[r] = tmp;
                    
                    int tmp2 = array2[l];
                    array2[l] = array2[r];
                    array2[r] = tmp2;
                    l++;
                    r--;
                }
            }
            Main.sort(array, array2, left, r);
            Main.sort(array, array2, l, right);
        }
    }
    
    public static void main(String args[]){
        Scanner stdIn = new Scanner(System.in);
        int n = stdIn.nextInt();
        int c[] = new int[26];
        int s[][] = new int[n][26];
        int ind[] = new int[26];
        
        for(int i = 0; i < 26; i++){
            c[i] = stdIn.nextInt();
            ind[i] = i;
        }
        
        for(int i = 0; i < n; i++){
            for(int j = 0; j < 26; j++){
                s[i][j] = stdIn.nextInt();
            }
        }
        
        for(int i = 0; i < n - 26; i++){
            int max = 0;
            int index = 0;
            for(int j = 0; j < 26; j++){
                if(s[i][j] > max){
                    max = s[i][j];
                    index = j;
                }
            }
            System.out.println(index + 1);
        }
        
        Main.sort(c, ind, 0, 25);
        
        for(int i = 25; i >= 0; i--){
            System.out.println(ind[i] + 1);
        }

        //System.out.println("XXXXXXXX");
    }
}


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

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n,m,sum=0;
	cin>>n>>m;
	vector<pair<ll,ll>>v(n);
	for(int i=0;i<n;i++){
		cin>>v.at(i).first>>v.at(i).second;
	}
	sort(v.begin(),v.end());
	ll i=0;
	while(m>0){
		if(v.at(i).second>0){
			v.at(i).second--;
			sum+=v.at(i).first;
			m--;
		}else{
			i++;
		}
	}
	cout<<sum<<endl;
}


Measured memory_bytes: 1792
#include <stdio.h>

int main(){
    int a,b,c,d,l,i;
    scanf("%d %d %d %d %d",&l,&a,&b,&c,&d);
    for(i=0;a>0||b>0;i++){
        a=a-c;
        b=b-d;
    }
    l=l-i;
    printf("%d\n",l);
    return 0;
}

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

using namespace std;

int main(){
    int D,G,p[11],c[11];
    cin >> D >> G;
    for(int i=0; i<D; i++){
        cin >> p[i] >> c[i];
    }

    int ans=1e9;
    for(int mask = 0; mask < (1<<D); mask++){
        int s=0,num = 0, rest_max = -1;
        for(int i=0; i<D; i++){
            if(mask >> i & 1){
                s += 100*(i+1)*p[i] + c[i];
                num += p[i];
            }else{
            rest_max = i;
            }
        }
        if(s < G){
            int s1 = 100* (rest_max +1);
            int need = (G -s + s1 -1)/s1;
            if(need >= p[rest_max]){
                continue;
            }
            num += need;
        }
        ans = min(ans,num);
    }
    cout << ans << endl;
}

Measured memory_bytes: 3636
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;

long long  digsum(long long  n) {
    long long  res = 0;
    while(n > 0) {
        res += n%10;
        n /= 10;
    }
    return res;
}

int main()
{
	int N, A, B;
	cin >> N >> A >> B;
	vector<int> x(N);
	int ans = 0;
	for (int i = 1; i <= N; i++) {
        int dig = digsum(i);
        //i%10　1の位 , i%100(下二桁)/10(切り捨てで10の位) (i%1000)/100 100の位 i/1000
        int digsu = ((i % 10) + ((i % 100) / 10) + ((i % 1000) / 100) + i / 1000);
        
		if (A <= dig  && dig <= B) {
			ans+=  i;
		}
		else continue;
	}
	/*for (int i = 0; i < N; i++) {
		ans += x[i];
	}*/
	cout << ans << endl;
}


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

typedef long long ll;

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

int main() { 
    int x;
    cin >> x;
    if (x == 0) {
        cout << 1 << "\n";
    } else {
        cout << 0 << "\n";
    }
    return 0;
}


Measured memory_bytes: 3540
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <stack>
#include <deque>
#include <cmath>
#include <map>
using ll = long long;
using namespace std;

int main() {
  string a, b, c;
  cin >> a >> b >> c;
  if (a[a.length()-1] == b[0] && b[b.length()-1] == c[0]) cout << "YES" << endl;
  else cout << "NO" << endl;
}


Measured memory_bytes: 256
S = input()
T = input()

min_cnt = 9999999999
for i in range(0, len(S) - len(T)+1):
    s = S[i: i + len(T)]
    cnt = 0
    for m, n in zip(s, T):
        if m != n:
            cnt +=1
    min_cnt = min(min_cnt, cnt)

print(min_cnt)



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

namespace AtCoder0525
{
    class Program
    {
        static void Main(string[] args)
        {
            string line = Console.ReadLine();
            string[] arr = line.Split(' ');
            int A = int.Parse(arr[0]);
            int B = int.Parse(arr[1]);
            int answer = 0;
            if (A >= 13)
            {
                answer = B;
            }
            else if (A > 5)
            {
                answer = B / 2;
            }
            Console.Write(answer);
        }
    }
}


Measured memory_bytes: 11092
from math import sqrt,ceil
n = int(input())
d = [0] * (n+1)
INF = int(1e9)+7
def prime_factor(x):
    for i in range(2,ceil(sqrt(n))+1):
        while x % i == 0:
            d[i] += 1
            x //= i
    if x != 1:
        d[x] += 1
    return
for i in range(1, n+1):
    prime_factor(i)
ans = 1
for i in range(n+1):
    if d[i] != 0:
        ans *= d[i] + 1
        ans %= INF
print(ans) 

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

int main() {
	long long n,i,j,ans,cur,jud=0,takecur=0,c,k;
	cin >> n;
	ans=0; cur=n*(n-1);
	vector<vector<long long>> a(n,vector<long long>(n-1));
	vector<long long> take(n),check(n);
	for(i=0; i<n; i++){
		for(j=0; j<n-1; j++){
			cin >> c;
			c--;
			a[i].push_back(c);
		}
		reverse(a[i].begin(),a[i].end());
		check[i]=n-1;
	}
	while(cur>0){
		jud=0;
		for(i=0; i<n; i++){
		//	cout << 'c'<<check[i];
			if(check[i]==0) continue;
			j=a[i].at(check[i]-1);
			
		//	cout << i+1 << j+1;
			if(check[j]==0) continue;
			if(a[j].at(check[j]-1)==i){
			//	cout <<'Y';
				take[takecur]=i; takecur++; jud=1;
			}
    		
		}
		for(k=takecur-1; k>=0; k--){
		//	cout << take[k] << ' ' << a[take[k]][check[take[k]]-1] << ' ';
			a[take[k]].pop_back();
			check[take[k]]--;
			cur--;
			
		}
		for(k=takecur-1; k>=0; k--){
			take[k]=0;
		}
		takecur=0;
		ans++;
		//cout << endl << ans << ' ' << cur << endl;
		if(jud==0){
			cout << -1; return 0;
		}
	}
	cout << ans;
	
}

Measured memory_bytes: 17920
#!/usr/bin/env python3

import sys

sys.setrecursionlimit(10**7)

input = sys.stdin.readline


def read_h(typ=int):
    return list(map(typ, input().split()))


def read_v(n, m=1, typ=int):
    return [read_h(typ) if m > 1 else typ(input()) for _ in range(n)]


def main():
    n, = read_h()
    arr = read_h()

    s = [0] * (n + 1)
    for i, a in enumerate(arr):
        k = s[i] + a
        s[i + 1] = k
    #  print(s)

    cnts = {}
    for si in s:
        cnts[si] = cnts.get(si, 0) + 1
    #  print(cnts)

    ans = sum([cnt * (cnt - 1) // 2 for cnt in cnts.values()])
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 41196
// =====================================================================================
//
//       Filename:  res.cpp
//
//        Version:  1.0
//       Revision:  none
//       Compiler:  g++
//
//         Author:  Priyank Kumar Singh (), priyankkumar179@gmail.com
//   Organization:  RVCE Bangalore
//
// =====================================================================================


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

#define ll long long 
#define pb push_back
#define mp make_pair
#define F first
#define S second 
#define pl pair<long ,long >
#define pi pair<int ,int >
#define ct(i) cout<< i << "\n";
#define mod 1000000007
#define M 100005

/*
void dfs(int n,int p){
    vis[n]=1; 
    if(adj[n].size()!=2) f1=1;
    for(int i=0;i<adj[n].size();i++){
        if(vis[adj[n][i]]==0 ) dfs(adj[n][i],n);
        else if(adj[n][i]!=p){ f=1; }
    }
}*/
int c1=0;
void answer(){
    ll n,l,r,f=0;
    string s;
    cin>>s;
    if(s[0]=='7' || s[1]=='7'  || s[2]=='7') f=1;
    if(f==1) cout<<"Yes";
    else 
    cout<<"No";
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL); 
    int q;
    //cin>>q; while(q--)
        answer();

    return 0;
}


Measured memory_bytes: 3656
n= int(input())
a=list(map(int,input().split()))
ans = 1
if not 0 in a:
  for i in range(n):
    ans*=a[i]
    if ans>1e+18:
      print(-1)
      break     
  if ans<=1e+18:
    print(ans)
else:
  print(0)

Measured memory_bytes: 21792
package main

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

var (
	read  = bufio.NewReader(os.Stdin)
	write = bufio.NewWriter(os.Stdout)
)

func main() {
	defer write.Flush()

	var a, b, c int
	fmt.Fscan(read, &a, &b, &c)

	cnt := 0
	if a == b {
		cnt = cnt + 1
	}
	if a == c {
		cnt = cnt + 1
	}
	if b == c {
		cnt = cnt + 1
	}

	if cnt == 1 {
		fmt.Fprintln(write, "Yes")
	} else {
		fmt.Fprintln(write, "No")
	}
}


Measured memory_bytes: 640
#include "iostream"
using namespace std;

long long int N, K;
int ans;
long long int box[11];

int main() {
	cin >> N >> K;
	for (int i = 0; i < 11; i++) {
		box[i] = N / 11;
		if (N % 11 > (i+1))box[i]++;
	}
	if (N % 11 == 0)box[10]--;
	box[0]--;
	/*for (int i = 0; i < 11; i++) {
		cout << box[i] << "\n";
	}*/
	for (int i = 0; i < 11; i++) {
		for (int j = 2; j < 7; j++) {
			if ((i * 7 + j)*9 % 11 == K)ans += box[i];
		}
	}
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 384
n, k = map(int, input().split())
a = list(map(int, input().split()))

b = [0]*200000
c = []
ans = 0

for x in a:
    b[x-1] += 1

for x in b:
    if x > 0:
        c.append(x)

c.sort()

y = len(c) - k

if y > 0:
    ans = sum(c[:y])

print(ans)

Measured memory_bytes: 26012
import math
x, n = map(int, input().split())
if n == 0:
    print(x)
else:
    pn = list(map(int, input().split()))
    flag = 0
    if x not in pn:
        print(x)
    else:
        a,b = x-1, x+1
        while flag == 0:
            if a not in pn:
                print(a)
                flag = 1
            elif b not in pn:
                print(b)
                flag = 1
            else:
                a -= 1
                b += 1

Measured memory_bytes: 9204
n = int(input())
lst = input().split()
bub, sel = lst[:], lst[:]
def stable(sls):
    s, i = 1, n-1
    while s*i:
        if sls[i][1] == sls[i-1][1]:
            if lst.index(sls[i]) < lst.index(sls[i-1]) :
                s = 0
        i -= 1
    print('Stable' if s else 'Not stable')

for i in range(n):
    m = i
    for j in range(n-1,i,-1):
        if bub[j][1] < bub[j-1][1]:
            bub[j-1:j+1] = bub[j], bub[j-1]
    for k in range(i, n):
        if sel[k][1] < sel[m][1]:
            m = k
    if m != i:
        sel[i], sel[m] = sel[m], sel[i]

print(*bub)
stable(bub)
print(*sel)
stable(sel)

Measured memory_bytes: 7788
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b;
    cin>>a>>b;
    if((a>=1&&a<=9)&&(b>=1&&b<=9))
    {
        cout<<a*b<<endl;
    }
    else
    {
        cout<<-1<<endl;
    }
}


Measured memory_bytes: 3620
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <queue>

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define mp make_pair

using namespace std;
typedef long long ll;

int dx[6] = {1,1,0,-1,-1,0};
int dy[6] = {0,1,1,0,-1,-1};

int main()
{
    int t,n;
    while(cin >> t >> n) {
        if(t == 0 && n == 0) break;
        

        int GETA = 100;
        bool used[200][200];
        memset(used,0,sizeof(used));

        rep(i,n) {
            int x,y;
            cin >> x >> y;
            
            used[y+GETA][x+GETA] = true;
        }

        queue<pair<pair<int,int>,int> > que;
        int sx,sy;
        cin >> sx >> sy;

        sy += GETA;
        sx += GETA;

        que.push(mp(mp(sy,sx),0));

        int ans = 1;
        used[sy][sx] = true;

        while(que.size()) {
            int y = que.front().first.first;
            int x = que.front().first.second;
            int cnt = que.front().second;
            que.pop();

            if(cnt < t) {
                rep(i,6) {
                    int ny = y + dy[i];
                    int nx = x + dx[i];

                    if(!used[ny][nx]) {
                        used[ny][nx] = true;
                        ans++;

                        // cout << ny << " " << nx << endl;
                        
                        que.push(mp(mp(ny,nx),cnt+1));
                    }
                }
            }
        }

        cout << ans << endl;
        
    }

    return 0;
}

Measured memory_bytes: 1260
package main

/*
全探索.
*/

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

func solve(k int, ms []int) bool {
	for i := range ms {
		if isAssembleK(k, ms[i:len(ms)]) {
			return true
		}
	}
	return false
}

func isAssembleK(k int, ms []int) bool {
	for i, m := range ms {
		if k == m {
			return true
		}
		if m < k {
			if isAssembleK(k-m, ms[i+1:len(ms)]) {
				return true
			}
		}
	}
	return false
}

func main() {
	scanner := makeScanner(8192)
	eGetInt(scanner)
	ms := eGetInts(scanner)
	eGetInt(scanner)
	qs := eGetInts(scanner)
	for _, q := range qs {
		if solve(q, ms) {
			fmt.Println("yes")
		} else {
			fmt.Println("no")
		}
	}
}

////////////////////////////////////////////////////////////////////////////////
// ライブラリ
////////////////////////////////////////////////////////////////////////////////
func makeScanner(max int) *bufio.Scanner {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Buffer(make([]uint8, 0, 8192), max)
	return scanner
}
func eGetLine(r *bufio.Scanner) string {
	if r.Scan() {
		return r.Text()
	}
	err := r.Err()
	if err != nil {
		log.Fatal(err)
	}
	// EOF
	return ""
}
func eGetInt(r *bufio.Scanner) int {
	line := eGetLine(r)
	return eAtoi(line)
}
func eGetFields(r *bufio.Scanner) []string {
	line := eGetLine(r)
	return strings.Fields(line)
}
func eGetInts(r *bufio.Scanner) []int {
	fields := eGetFields(r)
	var ints []int
	for _, f := range fields {
		ints = append(ints, eAtoi(f))
	}
	return ints
}
func eGetChars(r *bufio.Scanner) []string {
	line := eGetLine(r)
	return strings.Split(line, "")
}
func eAtoi(s string) int {
	n, err := strconv.Atoi(s)
	if err != nil {
		log.Fatal(err)
	}
	return n
}

type ints []int

func (s ints) String() string {
	var buf bytes.Buffer
	sep := ""
	for _, v := range s {
		buf.WriteString(fmt.Sprintf("%s%d", sep, v))
		sep = " "
	}
	return buf.String()
}

func reverse(a ints) ints {
	r := make(ints, len(a))
	for i := 0; i < len(a); i++ {
		r[i] = a[len(a)-1-i]
	}
	return r
}
func max(a ints) (int, bool) {
	if len(a) == 0 {
		return 0, false
	}
	m := a[0]
	for _, e := range a {
		if e > m {
			m = e
		}
	}
	return m, true
}
func sum(a ints) int {
	if len(a) == 0 {
		return 0
	}
	sum := 0
	for _, e := range a {
		sum += e
	}
	return sum
}



Measured memory_bytes: 1184
#include <bits/stdc++.h>
#define pb push_back
#define pob pop_back
#define mp make_pair
#define ff first
#define ss second
#define endl "\n"
#define int long long int
using namespace std;

const int N = 1e6+5;
const int mod = 1e9+7;

vector<int> p(201);
void solve() {
	for(int i=0;i<=200;i++)
		p[i] = (int)pow(i,5);
	int x;
	cin >> x;
	int flg = 0;
	for(int i=0;i<=200;i++) {
		for(int j=0;j<=200;j++) {
			if(p[i]-p[j] == x) {
				cout << i << " " << j;
				flg = 1;
				break;
			}
			if(p[i]+p[j] == x) {
				cout << i << " " << -j;
				flg = 1;
				break;
			}
		}
		if(flg)
			break;
	}
	return;
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int testcases = 1,i = 1;
	//cin >> testcases;
    while(testcases--) {
        //cout << "Case #" << i << ": ";
        solve();
        //i++;
    }
    return 0;
}


Measured memory_bytes: 4084
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include<algorithm>
#include <iomanip>
#include <math.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define REPR(i,n) for(int i=n-1; i>=(int)(0); i--)
#define FOR(i,a,b) for(int i=(int)(a); i<(int)(b); i++)
#define FORR(i,a,b) for(int i=(int)(b)-1; i>=(int)(a); i--)
#define CHMIN(a,b) (a)=min((a),(b))
#define CHMAX(a,b) (a)=max((a),(b))
#define ALL(v) (v).begin(),(v).end()
//**関数リスト**//
int ctoi(char c) {
	switch (c) {
	case '0': return 0;
	case '1': return 1;
	case '2': return 2;
	case '3': return 3;
	case '4': return 4;
	case '5': return 5;
	case '6': return 6;
	case '7': return 7;
	case '8': return 8;
	case '9': return 9;
	default: return 0;
	}
}
bool pairCompare(const pll firstElof, pll secondElof)
{
	return firstElof.second < secondElof.second;
}
int nod(ll F) {
	int keta = 1;
	while (F/10 > 0) {
		keta++;
		F /= 10;
	}
	return keta;
}
int gcd(int x, int y) {
	int r;
	if(x<y){
		swap(x, y);
	}
	while (y > 0) {
		r = x % y;
		x = y;
		y = r;
	}
	return x;
}
int lcm(int x, int y) {
	return x * y / gcd(x, y);
}
int isPrime(int x) {
	int i;
	if (x < 2) {
		return 0;
	}
	else if(x==2){
		return 1;
	}
	else if (x % 2 == 0) {
		return 0;
	}
	else {
		for (i = 3; i * i <= x; i += 2) {
			if (x % 1 == 0) {
				return 0;
			}
		}
		return 1;
	}
}
void eratos(vi isPrime) {
	//(注)isPrimeのサイズはN+1にする！実際にはmain内に配置して使用
	int ii, jj;
	REP(ii, isPrime.size()) {
		isPrime[ii] = 1;
	}
	isPrime[0] = 0; isPrime[1] = 0;
	for (ii = 2; ii * ii <= isPrime.size() - 1; ii++) {
		if (isPrime[ii] == 1) {
			jj= ii * 2;
			while (jj <= isPrime.size() - 1) {
				isPrime[jj] = 0;
				jj = jj + ii;
			}
		}
	}
}
ll modinv(ll a, ll m) {
	ll b = m, u = 1, v = 0;
	while (b) {
		ll t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
void bitSearch(int n) {
	//実際にはコピーして中身を改変して使う
	int ii;
	REP(ii, pow(2, n)) {
		ll p = ii;
		REP(ii, n) {
			cout << p % 2;
			p /= 2;
		}
		cout << endl;
	}
}
//**定義場所**//
ll i, j, k, l, m, n;
ll N, M, K, H, W;
ll MOD = 1000000000 + 7;
ll ans = 1000000000;
//***********//
int main() {
	ll L, R;
	cin >> L >> R;
	if (R - L >= 2019) {
		cout << 0;
	}
	else {
		for (i = L; i <= R - 1; i++) {
			for (j = i + 1; j <= R; j++) {
				ans = min(ans, ((i % 2019) * (j % 2019)) % 2019);
			}
		}
		cout << ans;
	}
}

Measured memory_bytes: 256
fun main() {
    val memo = mutableMapOf<Set<Int>, Int>()

    //最大公約数・
    fun gcd(a: Int, b: Int): Int {
        return if (b > 0) gcd(b, a % b) else a
    }

    val K = readLine()!!.toInt()


    var sum = 0
    for (i in 1..K) {
        for (l in 1..K) {
            for (j in 1..K) {
                sum += gcd(gcd(i, l), j)
            }
        }
    }
    println(sum)
}

Measured memory_bytes: 34968
#include <stdio.h>
#include <math.h>

int main(){
    int manage[4][3][10];

    for(int b=0; b<4; b++){
        for(int f=0; f<3; f++){
            for(int r=0; r<10; r++){
                manage[b][f][r] = 0;
            }
        }
    }

    int n;
    scanf("%d", &n);

    int b, f, r, v;
    for(int i=0; i<n; i++){
        scanf("%d %d %d %d", &b, &f, &r, &v);
        manage[b-1][f-1][r-1] += v;
    }

    for(int b=0; b<4; b++){
        for(int f=0; f<3; f++){
            for(int r=0; r<10; r++){
                printf(" %d", manage[b][f][r]);
            }
            printf("\n");
        }

        if(b<3){
            for(int i=0; i<20; i++){
                printf("#");
            }
            printf("\n");
        }
    }

    return 0;
}


Measured memory_bytes: 2092
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4") 
#include <bits/stdc++.h> 
using namespace std;
 
typedef long long ll;
typedef long double ld;
#define PI 3.1415926535897932384626 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd; 
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
 
#define Rep(i, a, b) for (int i=a; i<(b); i++)
#define rep(i, a) for (int i=0; i<(a); i++)
#define Dep(i,a,b) for (int i = (b)-1; i >= a; i--)
#define dep(i,a) for (int i = (a)-1; i >= 0; i--)
#define trav(a,x) for(auto& a : x)
 
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); // Random No.
 
const int MOD = 1000000007;
const char nl = '\n';

void sol() {

    int a, b, c,k;
    cin >> a >> b >> c >> k;
    
    if(a >= b){
        while (b<=a && k)
        {
            b = b *2;
            k--;
        }        
    } 

    if(b>=c){
        while (c<=b && k)
        {
            c = c *2;
            k--;
        }  
    }

  //  cout << a <<b << c << endl;    
     (c> b && b > a) ? cout << "Yes" : cout << "No";




}               

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

    #ifndef ONLINE_JUDGE
    	freopen("inputA.txt", "r", stdin);
	  #endif    
	
    int T=1;
    while(T--) {            
        sol();                
    }
	
	return 0;
}

Measured memory_bytes: 3652
import itertools
import math

n = int(input())
xy_list = [ [ int(v) for v in input().split() ] for i in range(n) ]

total = 1
for i in range(n):
    total *= (i+1)

ans = 0
for i in itertools.permutations(range(n),n):
    l = 0
    for j in range(n-1):
        px, py = xy_list[i[j+1]]
        qx, qy = xy_list[i[j]]
        l += math.hypot(px-qx,py-qy)
    ans += l
print(ans/total)
    

Measured memory_bytes: 42476
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using P = pair<int, int>;
#define debug(var) cerr << "[" << #var << "] " << var << endl
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
const ll mod = 1000000007;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,-1,0,1};


int main(){
    int n, k;
    cin >> n >> k;
    vector<int> v(n);
    rep(i, n) cin >> v[i];
    

    int ans = 0;

    
    for (int l=0; l<=k; l++) {
        for (int r=0; r<=k-l; r++) {
            if (l+r>n) continue;
            int x = k-l-r;
            int score = 0;
            vector<int> now;
            rep(i, l) {
                score += v[i];
                now.push_back(v[i]);
            }
            rep(i, r) {
                score += v[n-1-i];
                now.push_back(v[n-1-i]);
            }
            sort(whole(now));
            auto it = lower_bound(whole(now), 0);
            int numit = it - now.begin();
            x = min(x, numit);
            rep(i, x) {
                score -= now[i];
            }
            chmax(ans, score);
        }
    }
    
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
def resolve():
    k = int(input())
    a, b = map(int, input().split())

    result = k
    count_bai = 1
    while result < b:
        result = k * count_bai
        if a <= result <= b:
            break
        count_bai += 1

    if a <= result <= b:
        print("OK")
    else:
        print("NG")

resolve()

Measured memory_bytes: 61776
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
        int sum = 0;
        
		// 整数の入力
		int cnt = sc.nextInt();
		int low = sc.nextInt();
		int high = sc.nextInt();
		
        for(int i = 1; i <= cnt; i++){
            int num = 0;
            int p;
            String q;
            p = String.valueOf(i).length();
            q = String.valueOf(i);
            
            for(int j = 0; j < p; j++){
                char ch = q.charAt(j);
                num += Character.getNumericValue(ch);
            }
            
            if((num >= low) && (num <= high)){
                sum += i;
            }
        }
        
        System.out.println(sum);
	}
}

Measured memory_bytes: 24020
#include <stdio.h>

int main(void)
{
    int x, y;
    int ans;

    scanf("%d", &x);
    scanf("%d", &y);

    ans = 0;
    if(x > y){
        ans += x;
        x--;
    }else{
        ans += y;
        y--;
    }
    if(x > y){
        ans += x;
        x--;
    }else{
        ans += y;
        y--;
    }

    printf("%d", ans);

    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
struct process{
	char s[12];
	int time;
};
const int MAX_NUM = 100000+7;
struct process ps[MAX_NUM];
int head, tail;
int n,q;
struct process dequeue(){
	head = (head+1)%(n+1);
	return ps[head];
}
void enqueue(struct process p){
	tail = (tail+1)%(n+1);
	strcpy(ps[tail].s,p.s);
	ps[tail].time = p.time;
}
int main(){
	cin >> n >> q;
	
	int i;
	head = 0;
	tail = 0;
	int finish_one = 0;
	int now_time=0;
	for(i = 1; i <= n; i++){
		scanf("%s %d", ps[i].s, &ps[i].time);
		tail++;
	}
	while(finish_one!=n){
		struct process p = dequeue();
		if(p.time<=q){
			finish_one++;
			now_time+=p.time;
			cout << p.s << " " << now_time << endl;
		}else{
			p.time-=q;
			now_time+=q;
			enqueue(p);
		}
		
	}
	
	
	
	return 0;
}


Measured memory_bytes: 3928
#include<iostream>
#include<string>
using namespace std;
int main()
{string s;
 cin>>s;
 int count=0;
 for(int i=0;i<3;i++)
 if(s.at(i)=='R')
   count++;
 else count=0;
 if(s.at(2)=='S')
   if(s.at(0)=='R'&&s.at(1)=='R')
     count=2;
 	else if (s.at(0)=='R'||s.at(1)=='R')
      count=1;
 cout<<count;
 return 0;}


Measured memory_bytes: 3624
#include <iostream>
#include <string>
#include <vector>
#include <cstdio>
#include <algorithm>
#include <array>
#include <cmath>

using namespace std;

using ll = long long int;

// GCDを計算します
template <typename NumType>
NumType calcGCD(NumType a, NumType b) {
    if (a < b) {
        NumType tmp = a;
        a = b;
        b = tmp;
    }

    NumType r = a % b;
    while (r != 0) {
        a = b;
        b = r;
        r = a % b;
    }

    return b;
}

// 約数を数えます
template <typename NumType>
NumType cntDivisor(const NumType & num) {
    NumType cnt = 0;
    for(NumType i = 1; i * i <= num; ++i) {
        if(num % i == 0) {
            cnt++;
            if(i * i != num) cnt++;
        }
    }

    return cnt;
}

// [beg, end)の範囲を，添え字indexでループするfor文に置換します
#define FOR_RANGE(index, beg, end)     for (ll index = beg; index < N; ++index)

#define DEBUG(x)     std::cout << #x << " : " << x << "\n"

template<class T>
T min(T a, T b) {
    return (a < b) ? a : b;
}

template<class T>
T max(T a, T b) {
    return (a > b) ? a : b;
}

int main() {
    int a1, a2, a3;

    cin >> a1 >> a2 >> a3;

    int sum = a1 + a2 + a3;

    if (sum >= 22) cout << "bust";
    else           cout << "win";

    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define dump(x) cout << (x) << '\n';
typedef int64_t Int;
Int mod = 1e9+7;
Int INF = 1e9+7;

int main() {
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    Int cnt = 0;
    Int ma = 0;
    for (Int i = 0; i < (Int)s.size(); i++) {
        if (s[i] == 'A' || s[i] == 'C' || s[i] == 'G' || s[i] == 'T') {
            cnt++;
            ma = max(cnt, ma);
        }
        else {
            cnt = 0;
        }
    }
    dump(ma);
    return 0;
} 

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#define MAX_V 200005

using namespace std;

vector<int> tree[MAX_V];
long long ans[MAX_V];

// 頂点 v のコストの総和
int cost[MAX_V] = {0};

// v: 今いる頂点, p: v の親
void dfs(int v, int p) {
    ans[v] += cost[v];
    if (p != -1) {
        ans[v] += ans[p];
    }
    for (int i = 0; i < tree[v].size(); i++) {
        int e = tree[v][i];
        // 戻らないようにする処理
        if (e == p) { continue; }
        dfs(e, v);
    }
}

int main() {
    int N, Q;

    cin >> N >> Q;

    for (int i = 0; i < N-1; i++) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        tree[a].push_back(b);
        tree[b].push_back(a);
    }


    for (int i = 0; i < Q; i++) {
        int p, x;
        cin >> p >> x;
        p--;
        cost[p] += x;
    }

    dfs(0, -1);
    for (int i = 0; i < N; i++) {
        cout << ans[i] << ( i == N-1 ? "\n" : " ");
    }
    return 0;
}


Measured memory_bytes: 24832
import sys
m,d = map(int, input().split())
if d < 22:
	print(0)
	sys.exit(0)

result = 0
for i in range(22, d+1):
	d10 = i // 10
	d1 = i % 10
	if d1 < 2:
		continue
	if d1 * d10 <= m and d1 * d10 != 0:
		result += 1

print(result)

Measured memory_bytes: 3060
#include<iostream>
#include<queue>
#include<vector>
#include<algorithm>

using namespace std;
typedef long long ll;

int main(){
    int n, m;
    cin >> n >> m;
    priority_queue<ll, vector<int>, greater<int>> q;
    vector<ll> v(n);
    vector<pair<ll,ll>> cb(m);
    for (int i = 0; i < n; i++)
    {
        cin >> v[i];
    }
    sort(v.begin(), v.end());
    for (int i = 0; i < m; i++)
    {
        ll b, c;
        cin >> b >> c;
        cb[i] = make_pair(c, b);
    }
    sort(cb.rbegin(), cb.rend());
    ll sum = 0;
    int itr = 0;
    for (int i = 0; i < m && itr <n; i++)
    {
        ll b, c;
        c = cb[i].first;
        b = cb[i].second;
        for (int j = 0; j < b; j++)
        {
            if (v[itr] < c)
            {
                v[itr] = c;
                itr++;
                if(itr==n)
                {
                    break;
                }
            }
            else
            {
                break;
            }
            
        }
        
    }
    for (int i = 0; i < n; i++)
    {
        sum += v[i];
    }

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

Measured memory_bytes: 2560
// F - Enclosed Points
#include <bits/stdc++.h>

using namespace std;

#define	MOD	998244353

void fen_update(vector<int> &tree, int i, int val)
{
	for (++i; i > 0 && i < tree.size(); i += i & -i) tree[i] += val;
}

int fen_get(vector<int> &tree, int i)
{
	int sum = 0;
	for ( ; i > 0; i &= i - 1) sum += tree[i];
	return sum;
}

int main(int argc, char *argv[])
{
	ios::sync_with_stdio(false); cin.tie(0);

	int n;
	cin >> n;
	vector<int> b;
	vector<pair<int, int> > a(n);
	for (int i = 0; i < n; i++) cin >> a[i].first >> a[i].second, b.push_back(a[i].second);
	sort(a.begin(), a.end());
	sort(b.begin(), b.end());
	map<int, int> m;
	for (int i = 0; i < b.size(); i++) m[b[i]] = i;

	vector<long long> two(n + 1, 1);
	for (int i = 1; i <= n; i++) two[i] = two[i - 1] * 2 % MOD;

	long long ans = n * two[n - 1] % MOD;

	vector<int> l(n + 1), r(n + 1);
	for (int i = 0; i < n; i++)  fen_update(r, i, 1);

	for (int i = 0; i < n; i++) {
		int y = m[a[i].second];
		fen_update(r, y, -1);
		long long l1 = fen_get(l, y), l2 = i - l1;
		long long r1 = fen_get(r, y), r2 = n - 1 - i - r1;
		long long t1 = (two[l1] - 1 + MOD) % MOD * (two[r2] - 1 + MOD) % MOD * two[l2 + r1] % MOD;
		long long t2 = (two[l2] - 1 + MOD) % MOD * (two[r1] - 1 + MOD) % MOD * two[l1 + r2] % MOD;
		long long d = (two[l1] - 1 + MOD) % MOD * (two[r2] - 1 + MOD) % MOD * (two[l2] - 1 + MOD) % MOD * (two[r1] - 1 + MOD) % MOD;
		ans = (ans + t1 + t2 -d + MOD) % MOD;
		fen_update(l, y, 1);
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 15092
#include <cstdio>

using namespace std;

char s[111111];

int main(void) {
  int n, a, b;
  int p, q;
  p = q = 0;
  scanf("%d%d%d%s", &n, &a, &b, s);
  for (int i = 0; i < n; i++) {
    bool ok = false;
    if (s[i] == 'a' && p < a+b) {
      ok = true;
      p += 1;
    } else if (s[i] == 'b' && p < a+b && q < b) {
      ok = true;
      p += 1;
      q += 1;
    }
    puts(ok ? "Yes" : "No");
  }
  return 0;
}


Measured memory_bytes: 640
import bisect
N = int(input())
ls = list(map(int,input().split()))
ls.sort()
ans = 0
for i in range(N-2):
    for j in range(i+1,N-1):
        ls1 = ls[j+1:]
        ans += bisect.bisect_left(ls1,ls[j]+ls[i])-bisect.bisect(ls1,ls[j]-ls[i])
print(ans)

Measured memory_bytes: 77216
#include <bits/stdc++.h>
#define ff first
#define ss second
#define ll long long
#define ld long double
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define pii pair<int, int>
#define vi vector<int>
#define vl vector<ll>
#define vii vector<pii>
#define sws ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl '\n'
#define teto(a, b) ((a+b-1)/(b))
using namespace std;

const int MAX = 200010;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LLINF = 1000000000000000000;
const ld EPS = 1e-7;

// Extra
#define forn(i, n) for(int i = 0; i < (int)n; i++)
#define forne(i, a, b) for(int i = a; i <= b; i++)
#define all(x) x.begin(), x.end()
//

ll sum(vl& v, int l, int r) {
    r = min(r, (int)v.size()-1);
    l = max(l, 0);

    ll val = v[r];
    if(l-1 >= 0)
        val = (val - v[l-1] + MOD) % MOD;

    return val;
}

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

    vector<vl> tab(n, vl(k+2, 0));

    vi a(n);
    forn(i, n)
        cin >> a[i];

    for(int j = 0; j <= a[0]; j++) {
        tab[0][j] = 1;
    }

    for(int i = 1; i < n; i++) {

        // prefix sum de tab[i-1]
        vl psum(k+1, 0);
        ll val = 0;
        for(int j = 0; j <= k; j++) {
            val = (val + tab[i-1][j]) % MOD;
            psum[j] = val;
        }

        for(int j = 0; j <= k; j++) {
            tab[i][j] = sum(psum, j-a[i], j);
        }
    }

    // forne(i, 0, n-1) {
    //     forne(j, 0, k) {
    //         cout << tab[i][j] << " ";
    //     }
    //     cout << endl;
    // }
    cout << tab[n-1][k] << endl;

    return 0;
}


Measured memory_bytes: 82228
/*   _/                _/                 _/_/_/   _/
  _/_/_/_/   _/_/   _/_/_/_/   _/_/    _/       _/_/
   _/     _/    _/   _/     _/    _/  _/_/_/     _/
  _/     _/    _/   _/     _/    _/  _/    _/   _/
   _/_/   _/_/       _/_/   _/_/      _/_/     _/ */
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;
using ll=long long;
const int MOD=1e9+7;
const double pi=3.14159265358979323846;
const int inf=2e9;
const ll INF=1e18;
using P=pair<int,int>;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int main() {
  cin.tie(0),cout.tie(0);
  ios::sync_with_stdio(false);
  int n,a[100005]={},ans=0;
  cin >> n;
  map<int,int> m;
  for(int i=0; i<n; i++) {
    cin >> a[i];
    m[a[i]]++;
  }
  for(auto p:m) {
    if(p.first<p.second) {
      ans+=p.second-p.first;
    }
    else if(p.first>p.second) {
      ans+=p.second;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 5120
#include<bits/stdc++.h>
#define ll long long int
#define PB emplace_back
#define MP make_pair
#define F first
#define S second
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;

int main() {
    IOS;
//      freopen("input.txt","r",stdin);
//  		freopen("output.txt","w",stdout);
//ll t;
//cin>>t;
//while(t--){
    ll i,s=0,n,x,y,h=INT_MAX;
   cin>>n;
   cin>>x;
   for(i=1;i<n;i++){
       cin>>y;
       if(y<=x){
           s+=x-y;
           y+=x-y;
       }
       x=y;
   }
   cout<<s<<endl;
//}
	return 0;
}

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

#define INF 1e9+7
#define pf2 pop_front
#define pb2 pop_back
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define sz size
#define eps 1e-7
#define fod find_by_order
#define fastio ios::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
#define ofk order_of_key
#define val(x) cout << "Value dari "<< #x << " adalah " << x  << "\n"
#define tr tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>
typedef long long ll;
using namespace __gnu_pbds;
using namespace std;

int dx[8] = {1,0,-1,0,1,1,-1,-1};
int dy[8] = {0,1,0,-1,1,-1,1,-1};

void readf(string x){
	freopen((x+".in").c_str(),"r",stdin);
	freopen((x+".out").c_str(),"w",stdout);
}

void pr(string x){
	freopen((x+".in").c_str(),"w",stdout);
}


int read()
{
	bool min = 0;
	int  result = 0;
	char ch;
	ch = getchar();
	while(1)
	{
		if(ch == '-') break;
		if(ch >='0' && ch <= '9') break;
		ch = getchar();
	}
	if(ch == '-') min = 1;else result = ch-'0';
	while(1)
	{
		ch =getchar();
		if(ch< '0' || ch>'9') break;
		result = result * 10 + (ch-'0');
	}
	if(min) return -result;
	return result;
}
//Reynaldo's Template

int main(){
	int N;
	cin >> N;
	int x[100005];
	memset(x,0,sizeof x);
	for(int i=1;i<=N;i++){
		int a;
		cin >> a;
		x[a]++;
	}
	int maks = 0;
	for(int i=1;i<=1e5;i++){
		maks = max(maks,x[i] + x[i+1] + x[i-1]);
	}
	cout << maks << "\n";
}



Measured memory_bytes: 640
#!/usr/bin/env python3

import math
a, b, n = list(map(int, input().split()))

if b-1 <= n:
    x = b-1
    ans = math.floor(a*x/b) - a * math.floor(x/b)
else:
    x = n
    ans = math.floor(a*x/b) - a * math.floor(x/b)
print(ans)


Measured memory_bytes: 9180
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

int main() {
    int n = 3;

    int a[3];
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }

    sort(a, a + n);

    int k;
    cin >> k;

    a[2] <<= k;

    cout << a[0] + a[1] + a[2] << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string>
using namespace std;
int main(){
  int a,b;
  cin >>a >>b;
  int sum = a+b;
  if(a-b>sum)sum=a-b;
  if(a*b>sum)sum=a*b;
  cout <<sum;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

int top,S[1000];
void push(int x){
	S[++top] = x;
} 

int pop(){
	top--;
	return S[top+1];
}
 
int main(){
	int a,b;
	top = 0;
	char s[100];
	while(scanf("%s",s) != EOF){
		if(s[0] == '+'){
			a = pop();
			b = pop();
			push(a+b);
		}
		else if(s[0]=='-'){
			b = pop();
			a = pop();
			push(a-b);
		}
		else if(s[0]=='*'){
			a = pop();
			b = pop();
			push(a*b);
		}
		else{
			push(atoi(s));
		}
	}
	printf("%d\n",pop());
	return 0;
}


Measured memory_bytes: 2120
#include<iostream>
#include<string>
#include<algorithm>
#include<queue>
#include<vector>
#include<cstdlib>
#include<set>

using namespace std;

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

#include<iostream>

int const MAX_N = 100000;
int par[MAX_N]; // 親
int depth[MAX_N]; // 木の深さ

// n要素で初期化
void init(int n){
    for(int i = 0; i < n; i++){
        par[i] = i;
        depth[i] = 0;
    }
}

// 木の根を求める
int find(int x){
    if (par[x] == x) {
        return x;
    }else{
        return par[x] = find(par[x]);
    }
}

// xとyの属する集合を合併
void unite(int x, int y){
    x = find(x);
    y = find(y);
    if (x == y) return;

    if (depth[x] < depth[y]) {
        par[x] = y;
    }else{
        par[y] = x;
        if (depth[x] == depth[y]) depth[x]++;
    }
}

// xとyが同じ集合に属するか否か
bool same(int x, int y){
    return find(x) == find(y);
}


int main(){
    int n, m;
    cin >> n >> m;
    int p[n];
    rep(i, n){cin >> p[i]; p[i]--;}
    init(n);
    int x, y;
    rep(i, m) {
        cin >> x >> y;
        x--; y--;
        unite(x, y);
    }
    int ans = 0;
    rep(i, n){
        if (i != p[i]){
            if (same(i, p[i])){
                ans++;
            }
        }else{
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define zero_pad(num) setfill('0') << std::right << setw(num)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;

int main() {
	int a, b;
	cin >> a >> b;
	cout << (a - 1) * (b - 1) << endl;

}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;
class Main
{
	 public static void  main (String[] args) throws IOException
    {
       try{
       BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
       String a="";
       a=br.readLine();
       if(a.charAt(a.length()-1)=='s')
       {
       	System.out.println(a+"es");
       }
       else
       {
       	System.out.println(a+"s");
       }
     }  	
    catch(Exception e){}
}}


Measured memory_bytes: 36448
#include<stdio.h>

int main(void){
  int m,i,n,sum;
  scanf("%d",&n);
  m = n;
  while(n){
    sum += n%10;
    n = n/10;
  } 
  //printf("%d ",sum);
  if(m%sum==0){
    printf("Yes\n");
  }else{
    printf("No\n");
  }
  
  return 0;
}

Measured memory_bytes: 128