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

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

    // if (N < A) {
    //     cout << "Yes" << endl;
    // }
    // else if (A == 0) {
    //     if (N%500 == 0) {
    //         cout << "Yes" << endl;
    //     }
    //     else {
    //         cout << "No" << endl;
    //     }
    // }
    if (N%500 <= A) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
n,k = map(int,input().split())
a = list(map(int,input().split()))
e = [0]*n
b = [0]*(n-(k-1))
for i in range(n):
  e[i] = (1+a[i])/2

b[0] = sum(e[0:k])
for i in range(1, len(b)):
  b[i] = e[i+k-1] + b[i-1] - e[i-1]
print(max(b))

Measured memory_bytes: 73352
#include<iostream>
#include<queue>
#include<map>
#include<cstring>
using namespace std;

typedef pair<int,int> P;

int n,t,y,x;
int g[200][200];
int d[200][200];
int dy[] = {1,1,0,-1,-1,0}, dx[] = {0,1,1,0,-1,-1};
const int B = 100;

int main(){
  while(cin >> t >> n, t||n){
    memset(g,0,sizeof(g));
    memset(d,-1,sizeof(d));
  
    for(int i=0;i<n;i++){
      cin >> x >> y;
      g[y+B][x+B] = 1;
    }

    cin >> x >> y;
    queue<P> q; q.push(P(y+B,x+B));
    d[y+B][x+B] = 0;

    int res = 1;
    while(q.size()){
      P p = q.front(); q.pop();
      y = p.first; x = p.second;
      
      for(int i=0;i<6;i++){
	int ny = y + dy[i], nx = x + dx[i];
	if(g[ny][nx])continue;

	if(d[ny][nx]<0 && d[y][x]<t){
	  d[ny][nx] = d[y][x] + 1;
	  q.push(P(ny,nx));
	  res++;
	}
      }
    }
    cout << res << endl;
  }
}
    

Measured memory_bytes: 1536
package main
import "fmt"
func main(){
    // Your code here!
    var k int64
    fmt.Scan(&k)
    

    var x,y,z,sum int64
    sum = 0
    for x = 1; x <= k; x++{
        for y = 1; y <= k; y++{
            for z = 1; z <= k; z++{
                sum = sum + gcd(gcd(z,y),x)
            }
        }
    }
    fmt.Println(sum)
}

func gcd(a int64, b int64) int64{
    var t int64
    if a < b{
        t = b
        b = a
        a = t
    }
    for ;;{
        if a % b == 0{
            return b
        }else{
            t = a
            a = b
            b = t % b
        }
    }
}

Measured memory_bytes: 1776
a,b,c=map(int,input().split())
k=int(input())
m=0
for i in range(k+1):
    for j in range(k+1-i):
        s=a*(2**i)+b*(2**j)+c*(2**(k-i-j))
        if m<s:
            m=s
print(m)

Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) FOR(i,0,n)
typedef long long ll;
int main(){


	string s;
	cin >> s;

	rep(i, (int)s.size()) {
		if (i%2==0) {
			if (s[i]=='R'||s[i]=='U'||s[i]=='D') {
				continue;
			} else {
				cout << "No" << endl;
				return 0;
			}
		} else {
			if (s[i]=='L'||s[i]=='U'||s[i]=='D') {
				continue;
			} else {
				cout << "No" << endl;
				return 0;
			}

		}
	}
	cout << "Yes" << endl;
}

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

int main() {

int N , l , r ;
  cin >> N;
  int s , a = 0;
  for(int i = 0; i < N; i++){
    cin >> l >> r;
    s = r - l + 1;
    a += s;
  }
  cout << a << endl;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define print(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl; 
int C[9];
int INV[200];
typedef long long ll;
int main()
{
    ll H, W;
    cin >> H >> W;
    
    if (H == 1 || W == 1){
        cout << 1;
    } else if (H % 2 == 0 || W % 2 == 0){
        cout << H * W/2;
        
    } else {
        cout << (H * W + 1)/2;
    }
    return 0;
}


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


def solve(D: int):
    ans = ""
    for d in range(0, 25-D):
        ans += " Eve"
    print("Christmas" + ans)
    return


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

if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
h,w=gets.split.map(&:to_i)
a=Array.new(h,[])
h.times do |i|
    a[i]=gets.split
end

ans=Array.new(h+2).map{Array.new(w+2,"#")}
1.upto(h) do |i|
    ans[i][0]="#"
    ans[i][w+1]="#"
    1.upto(w) do |j|
        ans[i][j]=a[i-1][j-1]
    end
end
ans.each do |ans|
    puts ans.join("")
end


Measured memory_bytes: 14296
#include <cstdio>
using namespace std;

const int N_MAX = 10000;

int N;
int A[N_MAX];

void solve() {
  int cnt = 0;
  for (int i = 0; i < N; i++) {
    int x = A[i];

    while (x % 2 == 0) {
      x = x / 2;
      cnt++;
    }
  }
  printf("%d\n", cnt);
}

int main() {
  scanf("%d", &N);

  for (int i = 0; i < N; i++) {
    scanf("%d", &A[i]);
  }

  solve();
}


Measured memory_bytes: 256
import bisect
A,B,Q=map(int,input().split())
inf=10**18
s=[-inf]+[int(input()) for i in range(A)]+[inf]
t=[-inf]+[int(input()) for i in range(B)]+[inf]

for i in range(Q):
  ans=inf
  x=int(input())
  b=bisect.bisect_left(s,x)
  d=bisect.bisect_left(t,x)
  for S in (s[b-1],s[b]):
    for T in (t[d-1],t[d]):
      ans=min(ans,abs(S-x)+abs(S-T),abs(T-x)+abs(S-T))
  print(ans)

Measured memory_bytes: 14744
from collections import defaultdict, Counter
N = int(input())
common_char = set()
d = defaultdict(int)

for i in range(N):
    counters = Counter(input())
    if i > 0:
        common_char = common_char & set(counters.keys())
    else:
        common_char = set(counters.keys())
    
    for c in common_char:
        if d[c] == 0:
            d[c] = counters[c]
        else:
            d[c] = min(d[c], counters[c])

ans = ""
for k in [chr(ord("a") + i) for i in range(26)]:
    if k in common_char:
        ans += k * d[k]
print(ans)

Measured memory_bytes: 3316
#include <cstdio>
#include <algorithm>
using namespace std;
int n,a,b,v;
int c1,c2,c3;
int main()
{
	scanf("%d%d%d",&n,&a,&b);
	for (int i=1;i<=n;i++)
	{
		scanf("%d",&v);
		if (v<=a)
			c1++;
		if (a<v&&v<=b)
			c2++;
		if (b<v)
			c3++;
	}
	printf("%d\n",min(c1,min(c2,c3)));
	return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner input = new Scanner(System.in); 
		int P = input.nextInt();
		int N = input.nextInt();
		int[] houses = new int[N];
		for (int i = 0; i < N; i++) {
			houses[i] = input.nextInt();
		}
		int MAX = 0;
		for (int i = 0; i < N-1; i++) {
			MAX=Math.max(MAX, houses[i+1]-houses[i]);
		}
		System.out.println(Math.min(P-MAX,houses[N-1]-houses[0]));
	}
}

Measured memory_bytes: 79040
import std.stdio, std.string, std.array, std.algorithm, std.conv, std.typecons, std.numeric, std.math;

void main()
{
    auto nm = readln.split.to!(int[]);
    auto N = nm[0];
    auto M = nm[1];
    auto CS = readln.split.to!(int[]);

    auto DP = new int[][](M+1, N+1);
    foreach (ref dp; DP) dp[] = int.max/3;
    DP[0][N] = 0;

    foreach (i; 0..M) {
        foreach_reverse (j; 0..N+1) {
            auto c = j-CS[i];
            if (c >= 0) {
                DP[i][c] = min(DP[i][c], DP[i][j] + 1);
            }
            DP[i+1][j] = min(DP[i+1][j], DP[i][j]);
        }
    }
    writeln(DP[M][0]);
}


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

int k, t, a[100];

int main(){
	cin >> k >> t;
	for (int i = 0; i < t; i++) {
		cin >> a[i];
	}
	sort(a, a + t);
	if (a[t - 1] * 2 - 1 > k) {
		cout << a[t - 1] * 2 - k - 1 << endl;
		return 0;
	}
	else {
		cout << 0 << endl;
		return 0;
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
char d[10];
int n,k;
int main()
{
	cin>>n>>k;
	while(k--)
	{
		int l;
		cin>>l;
		d[l]=1;
	}
	for (int i=n;;i++)
	{
		stringstream st;
		string s;
		st<<i;
		st>>s;
		bool flag=false;
		for (int j=0;j<s.size();j++)
		{
			if (d[s[j]-'0']==1)
			{
				flag=true;
			}
		}
		if (!flag)
		{
			cout<<i<<endl;
			return 0;
		}
	}
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <tuple>
#include <vector>
#include <string>
#include <queue>
#include <cmath>
#include <set>
#include <map>

using namespace std;
using ll = long long;

int dp[100005];

int main()
{
    int n;
    cin >> n;
    vector<int> h(n+1, 0);
    for(int i = 1; i <= n; i++){
        cin >> h[i];
    }
    dp[0]= 0;
    dp[1] = 0;
    dp[2] = abs(h[1]-h[2]);
    for(int i = 3; i <= n; i++){
        dp[i] = min(dp[i-1] + abs(h[i]-h[i-1]), dp[i-2] + abs(h[i]-h[i-2]));
    }
    cout << dp[n] << endl;
    return 0;
}

Measured memory_bytes: 3988
#include <iostream>
#include <cstring>
#include <stdlib.h>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <math.h>
#include <string>

using namespace std;

int main()
{
    int a, b;
    cin >> a >> b;
    int tmp;
    if(b<10){
        tmp=a*10+b;
    }else if(b==100){
        tmp=a*1000+b;
    }else{
        tmp=a*100+b;
    }
    double ans = sqrt(tmp);
    if(int(ans)==ans){
        cout << "Yes";
    }else{
        cout << "No";
    }
    return 0;
}

Measured memory_bytes: 256
// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools

#include <bits/stdc++.h>

using namespace std;

using i64 = long long;

const i64 MOD = 1e9 + 7;
const i64 INF = i64(1e18) + 7;


template <typename T>
bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

template <typename T>
bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}

template <typename T>
struct DisjointSparseTable{
    function<T(T, T)> f;
    vector<vector<T>> v;

    DisjointSparseTable(vector<T>& inp, function<T(T, T)> f) : f(f){
        int n = inp.size();
        int b;
        for(b = 0; (1 << b) <= inp.size(); ++b);
        v.assign(b, vector<T>(n));
        for(int i = 0; i < n; ++i)
            v[0][i] = inp[i];
        for(int i = 1; i < b; ++i){
            int siz = 1 << i;
            for(int j = 0; j < n; j += siz << 1){
                int t = min(j + siz, n);
                v[i][t - 1] = inp[t - 1];
                for(int k = t - 2; k >= j; --k)
                    v[i][k] = f(inp[k], v[i][k + 1]);
                if(t >= n)
                    break;
                v[i][t] = inp[t];
                int r = min(t + siz, n);
                for(int k = t + 1; k < r; ++k)
                    v[i][k] = f(v[i][k - 1], inp[k]);
            }
        }
    }

    T get(int l, int r){
        if(l >= --r)
            return v[0][l];
        int p = 31 - __builtin_clz(l ^ r);
        return f(v[p][l], v[p][r]);
    }
};


void solve(long long n, std::vector<long long> a){
    vector<i64> dp(n, 1000);
    DisjointSparseTable<i64> d(a, [](auto x, auto y){return max(x, y);});
    for(int i = 0; i < n; ++i){
        i64 num = dp[i] / a[i];
        i64 mod = dp[i] % a[i];
        for(int j = i + 1; j < n; ++j){
            i64 ma = d.get(i, j + 1);
            chmax(dp[j], mod + num * ma);
        }
    }
    cout << dp.back() << endl;
}


signed main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> A(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&A[i]);
    }
    solve(N, std::move(A));
    return 0;
}


Measured memory_bytes: 3704
package main

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

type pair struct {
	val int
	idx int
}

func main() {
	N, M := getStdinInt2()
	L := make([]int, M)
	R := make([]int, M)
	for i := 0; i < M; i++ {
		l, r := getStdinInt2()
		L[i] = l - 1
		R[i] = r - 1
	}

	left := 0
	right := N - 1
	for i := 0; i < M; i++ {
		if left < L[i] {
			left = L[i]
		}
		if right > R[i] {
			right = R[i]
		}
	}
	ans := (right + 1) - left
	if ans > N {
		ans = N
	}
	if ans < 0 {
		ans = 0
	}
	fmt.Printf("%d\n", ans)
}

var sc = bufio.NewReaderSize(os.Stdin, 1024*1024*10)

func getStdin() string {
	return readLine()
}
func getStdinInt() int {
	str := getStdin()
	rtn, _ := strconv.Atoi(str)
	return rtn
}
func getStdinInt2() (int, int) {
	list := getStdinIntArr()
	return list[0], list[1]
}
func getStdinInt3() (int, int, int) {
	list := getStdinIntArr()
	return list[0], list[1], list[2]
}
func getStdinInt64() int64 {
	str := getStdin()
	rtn, _ := strconv.ParseInt(str, 10, 64)
	return rtn
}
func getStdinInt64_2() (int64, int64) {
	list := getStdinIntArr64()
	return list[0], list[1]
}
func getStdinInt64_3() (int64, int64, int64) {
	list := getStdinIntArr64()
	return list[0], list[1], list[2]
}
func getStdinIntArr() []int {
	str := getStdin()
	list := strings.Split(str, " ")
	rtn := make([]int, len(list))
	for idx, val := range list {
		rtn[idx], _ = strconv.Atoi(val)
	}
	return rtn
}
func getStdinIntArr64() []int64 {
	str := getStdin()
	list := strings.Split(str, " ")
	rtn := make([]int64, len(list))
	for idx, val := range list {
		rtn[idx], _ = strconv.ParseInt(val, 10, 64)
	}
	return rtn
}
func readLine() string {
	buf := make([]byte, 0, 0)
	for {
		l, p, _ := sc.ReadLine()
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}


Measured memory_bytes: 10884
#include<bits/stdc++.h>
#include<atcoder/all>
using namespace std;
using namespace atcoder;
using ll=long long;
template<class T,class U> inline bool chmin(T&x,U y){if(x>y){x=y;return true;}return false;}
template<class T,class U> inline bool chmax(T&x,U y){if(x<y){x=y;return true;}return false;}

void solve(){
    int n,m;
    cin>>n>>m;
    dsu d(n);
    {
        int a,b;
        for(int i{};i<(m);++i){
            cin>>a>>b;--a,--b;
            d.merge(a,b);
        }
    }
    int ans{};
    for(int i{1};i<(n);++i) if(!d.same(0,i)){
        d.merge(0,i);
        ++ans;
    }
    cout<<ans<<'\n';
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    solve();
}

Measured memory_bytes: 3764
#include<map>
#include<set>
#include<list>
#include<cmath>
#include<queue>
#include<stack>
#include<cstdio>
#include<string>
#include<vector>
#include<complex>
#include<cstdlib>
#include<cstring>
#include<numeric>
#include<sstream>
#include<iostream>
#include<algorithm>
#include<functional>

#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,b,n) for(int i=b;i<n;i++)

using namespace std;

typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;

const int INF=1<<29;
const double EPS=1e-9;

const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};
const int MAX_N =100010;
int prime[MAX_N];//i番目の素数
bool is_prime[MAX_N+1];//is_prime[i]がtrueならiは素数

//n以下の素数の数を返す
int sieve(int n){
	int p = 0;
	for(int i = 0;i <=n;i++){
		is_prime[i] =true;
	}
	is_prime[0] = false;
	is_prime[1] = false;
	for(int i = 2;i <=n;i++){
		if(is_prime[i]){
			prime[p++] = i;
			for(int j = 2*i;j <=n;j +=i){
				is_prime[j] =false;
			}
		}
	}
	return p;
}
int main(){
	sieve(100008);
	double m,a,b;
	while(cin>>m>>a>>b,m||a||b){
		double k = a/b;
		int tmp = 0;
		int ans = 0;
		int ansx = 0;
		int ansy = 0;
		for(int i = 2;i <=sqrt(m);i++){
			if(!is_prime[i])
				continue;
			for(int j = i;j <=m/2;j++){
				if(!is_prime[j])
					continue;
				double l = (double)i/j;
				if(m>=i*j&&k<=l&&l<=1&&i*j>ans){
					ans = i*j;
					//cout <<k<<" "<<l<<endl;
					ansx = i;
					ansy = j;
				}
			}
		}
		cout <<ansx<<" "<<ansy<<endl;
	}
	return 0;
}

Measured memory_bytes: 1356
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define SZ(x) ((int)x.size())
#define ALL(x) x.begin(),x.end()
#define L(i,u) for (register int i=head[u]; i; i=nxt[i])
#define rep(i,a,b) for (register int i=(a); i<=(b); i++)
#define per(i,a,b) for (register int i=(a); i>=(b); i--)
using namespace std;
typedef long double ld;
typedef long long ll;
typedef unsigned int ui;
typedef pair<int,int> Pii;
typedef vector<int> Vi;
template<class T> inline void read(T &x){
	x=0; char c=getchar(); int f=1;
	while (!isdigit(c)) {if (c=='-') f=-1; c=getchar();}
	while (isdigit(c)) {x=x*10+c-'0'; c=getchar();} x*=f;
}
template<class T> T gcd(T a, T b){return !b?a:gcd(b,a%b);}
template<class T> inline void umin(T &x, T y){x=x<y?x:y;}
template<class T> inline void umax(T &x, T y){x=x>y?x:y;}
inline ui R() {
	static ui seed=416;
	return seed^=seed>>5,seed^=seed<<17,seed^=seed>>13;
}
const int N = 66;
double p[N],q[N];int n=6,_;
double calc(double x){
	double res=0;
	rep(i,1,n)res+=max(x*p[i],(1-x)*q[i]);
	return res;
}
int main() {
	rep(i,1,n)read(_),p[i]=1.0*_/100;
	rep(i,1,n)read(_),q[i]=1.0*_/100;
	double l=0,r=1,res=1;
	rep(k,1,60){
		double m1=(2*l+r)/3,m2=(l+2*r)/3;
		double v1=calc(m1),v2=calc(m2);
		umin(res,min(v1,v2));
		if(v1<v2)r=m2;else l=m1;
	}
	printf("%.11lf",res);
	return 0;
}


Measured memory_bytes: 256
n = int(input())
v = list(map(int,input().split()))
c = list(map(int,input().split()))
result = 0

for i in range(2**n):
    list_v = []
    list_c = []
    for j in range(n):
        if (i >> j) &1 ==1:
            list_v.append(v[j])
            list_c.append(c[j])
    if sum(list_v) - sum(list_c) >= result:
        result = sum(list_v) - sum(list_c)

print(result)

Measured memory_bytes: 44852
#include<bits/stdc++.h>
using namespace std;
int n;
int h[200005];
long long a[200005],dp[200005];
long long g[200005],ans;

void add(int x,long long y){
	for(int i=x;i<=n;i+=i&-i) g[i]=max(g[i],y);
}

long long ask(int x){
	long long res=0;
	for(int i=x;i;i-=i&-i) res=max(res,g[i]);
	return res;
}

int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",&h[i]);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
	for(int i=1;i<=n;i++){
		dp[i]=ask(h[i])+a[i];
		add(h[i],dp[i]);
		ans=max(ans,dp[i]);
	}
	printf("%lld\n",ans);
	
	return 0;
}

Measured memory_bytes: 5760
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,d=1,e=0,f=1;
  string c;
  cin>>a>>b>>c;
  for(int i=0;i<=a+b;i++){
    if(i<a) if(c[i]=='-') d=0;	
    if(i==a) if(c[i]=='-') e=1;
    if(a<i) if(c[i]=='-') f=0;
  }
  if(d+e+f==3) cout<<"Yes";
  else cout<<"No";
  cout<<"\n";
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int read()
{
    char ch=getchar();
    int x=0,f=1;
    while(ch<'0' || ch>'9')
    {
        if(ch=='-')
            f=-1;
        ch=getchar();
    }
    while(ch>='0' && ch<='9')
    {
        x=x*10+ch-'0';
        ch=getchar();
    }
    return x*f;
}
int main()
{
    string ans;
    char ch;
    cin>>ans;
    int q,flag=1;
    int t;int f;
    char tt;
    q=read();
    while(q--)
    {

        t=read();
        if(t==1)
            flag*=-1;
        else
        {

            f=read();
            tt=getchar();
            if(f==1)
            {
                if(flag==-1)
                {
                    ans+=tt;
                }
                else
                {
                    ans.insert(ans.begin(),tt);
                }

            }
            else
            {
                if(flag==1)
                    ans+=tt;
                else
                {
                    ans.insert(ans.begin(),tt);
                }
            }

        }
    }
    if(flag==1)
    {
        int len=ans.size();
        for(int i=0; i<len; i++)
            putchar(ans[i]);
    }

    else
    {
        for(int i=ans.size()-1; i>=0; i--)
            putchar(ans[i]);
    }
    return 0;
}


Measured memory_bytes: 1028
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
#include <cstring>
using namespace std;

using ll = long long;
using P = pair<int, int>;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

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

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

    int N, M, L, Q;
    cin >> N >> M >> L;
    vector<vector<P>> graph(N);
    for(int i = 0; i < M; ++i){
        int A, B, C;
        cin >> A >> B >> C;
        --A, --B;
        if(C > L)   continue;
        graph[A].emplace_back(B, C);
        graph[B].emplace_back(A, C);
    }

    vector<vector<int>> dp(N, vector<int>(N, INF));
    vector<vector<int>> dp2(N, vector<int>(N, -1));
    for(int s = 0; s < N; ++s){
        dp[s][s] = 0;
        dp2[s][s] = L;
        int v = s;
        vector<bool> used(N, false);
        while(v >= 0){
            int cur = v;
            used[v] = true;
            for(auto& e : graph[cur]){
                int nxt = e.first, cost = e.second;
                if(used[nxt])   continue;
                int nxt_cost, nxt_gas;
                if(dp2[s][cur] >= cost){
                    nxt_cost = dp[s][cur];
                    nxt_gas = dp2[s][cur] - cost;
                }
                else{
                    nxt_cost = dp[s][cur] + 1;
                    nxt_gas = L - cost;
                }
                if(chmin(dp[s][nxt], nxt_cost)){
                    dp2[s][nxt] = nxt_gas;
                }
                else if(dp[s][nxt] == nxt_cost){
                    chmax(dp2[s][nxt], nxt_gas);
                }
            }

            v = -1;
            int min_cost = INF, max_gas = -1;
            for(int i = 0; i < N; ++i){
                if(used[i]) continue;
                if(chmin(min_cost, dp[s][i])){
                    max_gas = dp2[s][i];
                    v = i;
                }
                else if(min_cost == dp[s][i]){
                    if(chmax(max_gas, dp2[s][i])){
                        v = i;
                    }
                }
            }
        }
    }
    
    cin >> Q;
    for(int i = 0; i < Q; ++i){
        int s, t;
        cin >> s >> t;
        --s, --t;
        if(dp[s][t] == INF) cout << -1 << '\n';
        else    cout << dp[s][t] << '\n';
    }
}

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

// マクロ //
#define rep(v,times) for(int v = 0; v < (int)(times); v++)
#define req(v,first,endplus1) for(int v = first; v < (int)(endplus1); v++)
#define all(x) x.begin(), x.end()
#define sort(x) sort(all(x))
#define uniq(x) x.erase(unique(all(x)), x.end())
#define vsum(x) accumulate(all(x), 0)
#define cou(x) cout << x << endl
#define y() cout << "Yes" << endl
#define n() cout << "No" << endl
#define Y() cout << "YES" << endl
#define N() cout << "NO" << endl
#define x2(x) (x) * (x)

// 型エイリアス //
using lint = long long;
using pii = pair<int, int>;
using vpii = vector<pii>;
using plili = pair<lint, lint>;
using vplili = vector<plili>;
using vi = vector<int>;
using vli = vector<lint>;
using vc = vector<char>;
using vs = vector<string>;
using vb = vector<bool>;
using vvi = vector<vi>;
using vvli = vector<vli>;
using vvb = vector<vb>;
using vvc = vector<vc>;
using vvs = vector<vs>;
using mii = map<int, int>;
using mili = map<int, lint>;
using mci = map<char, int>;
using mcli = map<char, lint>;
using msi = map<string, int>;
using msli = map<string, lint>;


// 関数 //
template<class T, class Q> lint gcd_(T a, Q b) {
    int t;
    while (b != 0) {
        t = a % b;
        a = b;
        b = t;
    }
    return a;
}

template<class T, class Q> lint lcm_(T a, Q b) {
    return a * b / gcd_(a, b);
}

template<class T, class Q> double distance(T a, Q b) {
    double dist;
    dist = sqrt(x2(a.first - b.first) + x2(a.second - b.second));
    return dist;
}

lint perm(int a) {
    lint perm = 1;
    for (int i = a; i >= 1; i--) {
        perm *= i;
    }
    return perm;
}

lint combination(int n, int m) {
    long double c = 1;
    for (int i = n, k = 1; i > m; i--, k++) {
        c *= i;
        c /= k;
    }
    return (lint)c;
}

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

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

// 定数 //
const double pi = acos(-1);
const int mod = 1000000007;
const int inf = 1045141919;
const lint linf = ((1LL << 62) - 1);
const int dx4[4] = { 1,0,-1,0 };
const int dy4[4] = { 0,1,0,-1 };
const int dx8[8] = { 1,1,0,-1,-1,-1,0,1 };
const int dy8[8] = { 0,1,1,1,0,-1,-1,-1 };

// End of Template //



int main() {

    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
        
    string T;
    cin >> T;

    rep(i, T.size()) if (T[i] == '?') T[i] = 'D';
    cou(T);


}

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

#define REP(i,n) for(int i=0; i < (n); ++i)
#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)

using ll = long long;
#define INF 1e9
const int mod = 1e9+7;
int N;
vector<int> soin(51, 0);

int num(int x){
  int result = 0;
  REP(i, 51){
    if(soin[i] >= x-1){
      result++;
    }
  }
  return result;
}
int main(){
  cin >> N;
  ll ans = 0;
  FOR(i, 2, N+1){
    int n = i;
    int j = 2;
    while(n != 1){
      while(n % j == 0){
        soin[j]++;
        n /= j;
      }
      j++;
    }
  }
  ans += num(75);
  ans += num(25) * (num(3)-1);
  ans += num(15) * (num(5)-1);
  ans += num(5) * (num(5)-1) * (num(3)-2) / 2;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define mod (int)(1e9+7)
#define inf (int)(3e18)
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define PP pair<P,P>
#define all(v) v.begin(),v.end()
#define mkp make_pair
#define mkt make_tuple
#define prique(T) priority_queue<T,vector<T>,greater<T>>
#define vecunique(vec) sort(vec.begin(), vec.end());decltype(vec)::iterator result = std::unique(vec.begin(), vec.end());vec.erase(result, vec.end())
using namespace std;
template<class T> inline void chmax(T& a, T b) { a = max(a, b); }
template<class T> inline void chmin(T& a, T b) { a = min(a, b); }

bool prime(int x) {
	for (int i = 2; i * i <= x; i++) {
		if (x % i == 0)return false;
	}
	return x > 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}
int get_rand(int MIN, int MAX) {
	random_device rnd;
	mt19937_64 mt64(rnd());
	uniform_int_distribution<int>engine(MIN, MAX);
	return engine(mt64);
}
/*--------Library Zone!--------*/

int n, m, pay;
struct edge { int f, t, c; };
edge es[5555];
int mo[2525];
bool can[2525];
vector<int>G[2525];
void bfs() {
	can[n - 1] = true;
	queue<int>que;
	que.push(n - 1);
	while (!que.empty()) {
		int i = que.front(); que.pop();
		for (int t : G[i]) {
			if (!can[t]) {
				can[t] = true;
				que.push(t);
			}
		}
	}
}
int bellmanford() {
	bfs();
	REP(i, n)mo[i] = -inf;
	for (int cnt = 1;; cnt++) {
		bool update = false;
		rep(i, m) {
			if (mo[es[i].f] == -inf)continue;
			if (!can[es[i].f] || !can[es[i].t])continue;
			if (mo[es[i].t] < mo[es[i].f] + es[i].c) {
				mo[es[i].t] = mo[es[i].f] + es[i].c;
				update = true;
				if (cnt > n + 5) {
					cout << -1 << endl; exit(0);
				}
			}
		}
		if (!update)break;
	}
	return max(0ll, mo[n - 1]);
}
signed main() {
	cin >> n >> m >> pay;
	rep(i, m) {
		cin >> es[i].f >> es[i].t >> es[i].c;
		es[i].f--; es[i].t--; es[i].c -= pay;
		G[es[i].t].push_back(es[i].f);
	}
	cout << bellmanford() << endl;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#pragma region Macros
#define ios\
    ios::sync_with_stdio(false);\
    cin.tie(nullptr);
#define VEC(type, name, size)\
    V<type> name(size);\
    IN(name)
#define VVEC(type, name, h, w)\
    VV<type> name(h, V<type>(w));\
    IN(name)
#define INT(...)\
    int __VA_ARGS__;\
    IN(__VA_ARGS__)
#define LL(...)\
    ll __VA_ARGS__;\
    IN(__VA_ARGS__)
#define STR(...)\
    string __VA_ARGS__;\
    IN(__VA_ARGS__)
#define CHAR(...)\
    char __VA_ARGS__;\
    IN(__VA_ARGS__)
#define DOUBLE(...)\
    DOUBLE __VA_ARGS__;\
    IN(__VA_ARGS__)
#define LD(...)\
    LD __VA_ARGS__;\
    IN(__VA_ARGS__)
template <class T> void scan(T &a) { cin >> a; }
template <class T> void scan(vector<T> &a) { for(auto &i : a) scan(i); }
template <class T, class L> void scan(pair<T, L> &p){ scan(p.first); scan(p.second); }
void IN() {}
template <class Head, class... Tail> void IN(Head &head, Tail &... tail) { scan(head); IN(tail...); }
template <class T> inline void print(T x){ cout << x << '\n';}
#define ll long long
#define ld long double
#define FOR(i,l,r) for(ll i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,1,n+1)
#define RFOR(i,l,r) for(ll i=(l);i>=(r);--i)
#define RREP(i,n) RFOR(i,n-1,0)
#define RREPS(i,n) RFOR(i,n,1)
#define pb push_back
#define eb emplace_back
#define SZ(x) ((ll)(x).size())
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
template<class T = ll> using V = vector<T>;
template<class T = ll> using VV = V<V<T>>;
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true; }return false; }
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true; }return false; }
inline void Yes(bool b = true) {cout << (b ? "Yes" : "No") << '\n';}
inline void YES(bool b = true) {cout << (b ? "YES" : "NO") << '\n';}
inline void err(bool b = true) {if(b) {cout << -1 << '\n'; exit(0);}}
template<class T> inline void fin(bool b = true, T e = 0) {if(b) {cout << e << '\n'; exit(0);}}
template<class T> T Roundup_div(T x, T y) {return (x+(y-1))/y;}
template <typename T> T pow(T a, long long n, T e = 1) {T ret = e; while (n) {if (n & 1) ret *= a; a *= a; n >>= 1; } return ret; }
const ll INF = 1e18;
#pragma endregion

int main(){
    ios;
    REP(i,12){
        CHAR(a);
        cout << a;
        if(i == 3) cout << " ";
    }
    cout << endl;
}

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

#define repi(itr, ds) for(auto itr = ds.begin(); itr != ds.end(); itr++)
// vector
template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
  for(T &x : vec) is >> x;
  return is;
}
// pair
template <typename T, typename U>
ostream &operator<<(ostream &os, pair<T, U> &pair_var) {
  os << "(" << pair_var.first << ", " << pair_var.second << ")";
  return os;
}
// vector
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  os << "{";
  for(int i = 0; i < vec.size(); i++) {
    os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
  }
  os << "}\n   ";
  return os;
}
// map
template <typename T, typename U>
ostream &operator<<(ostream &os, map<T, U> &map_var) {
  os << "{";
  repi(itr, map_var) {
    os << *itr;
    itr++;
    if(itr != map_var.end()) os << ", ";
    itr--;
  }
  os << "}";
  return os;
}
// set
template <typename T>
ostream &operator<<(ostream &os, set<T> &set_var) {
  os << "{";
  repi(itr, set_var) {
    os << *itr;
    itr++;
    if(itr != set_var.end()) os << ", ";
    itr--;
  }
  os << "}";
  return os;
}

#define DUMPOUT cerr

void dump_func() { DUMPOUT << endl; }
template <class Head, class... Tail>
void dump_func(Head &&head, Tail &&... tail) {
  DUMPOUT << head;
  if(sizeof...(Tail) > 0) {
    DUMPOUT << ", ";
  }
  dump_func(std::move(tail)...);
}
#ifdef DEBUG_
#define DEB
#define dump(...)                                                             \
  DUMPOUT << "  " << string(#__VA_ARGS__) << ": "                             \
          << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]" << endl \
          << "    ",                                                          \
      dump_func(__VA_ARGS__)
#else
#define DEB if(false)
#define dump(...)
#endif

typedef long long int ll;

int main() {
  int A, B, C, D, E, F;
  cin >> A >> B >> C >> D >> E >> F;
  double max_dence = -10000.0;
  int ans_water = -1;
  int ans_sugar = -1;
  double houwa = E * 100.0 / (100.0 + E);
  dump(houwa);
  REP(a, F / (100 * A) + 1) {
    int A_water = a * A * 100;
    REP(b, (F - A_water) / (100 * B) + 1) {
      int B_water = b * B * 100;
      double water = A_water + B_water;
      REP(c, (F - water) / C + 1) {
        int C_sugar = c * C;
        REP(d, (F - water - C_sugar) / D + 1) {
          int D_sugar = d * D;
          double sugar = C_sugar + D_sugar;
          double dence = sugar * 100.0 / (water + sugar);
          if(dence <= houwa && water + sugar <= F) {
            if(max_dence < dence) {
              // dump(a, b, c, d);
              // dump(dence, water, sugar);
              max_dence = dence;
              ans_water = water;
              ans_sugar = sugar;
            }
          }
        }
      }
    }
  }
  cout << ans_water + ans_sugar << " " << ans_sugar << endl;
}


Measured memory_bytes: 256
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)

	a, b = b, a
	a, c = c, a

	fmt.Fprintln(write, a, b, c)
}


Measured memory_bytes: 640
#include "bits/stdc++.h"
using namespace std;
#define repr(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repr(i,0,n)
#define reprrev(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define reprev(i,n) reprrev(i,0,n)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define mp make_pair
#define mt make_tuple
#define MOD 1000000007
#define PI 3.1415926535
typedef long long ll;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<Pi> vPi;
typedef vector<Pll> vPll;
typedef vector<vector<int>> vvi;
typedef vector<vector<bool>> vvb;
typedef vector<vector<ll>> vvll;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;
typedef vector<vector<double>> vvd;
typedef vector<vector<Pi>> vvPi;
typedef priority_queue<int, vector<int>, greater<int>> pqli;
typedef priority_queue<ll, vector<ll>, greater<ll>> pqlll;
typedef priority_queue<Pi, vector<Pi>, greater<Pi>> pqlP;
string YN(bool y) { return (y?"YES":"NO"); }
string yn(bool y) { return (y?"Yes":"No"); }
string ON(bool y) { return (y?"OK":"NG"); }
int main(void)
{
	int a, b, c;

	cin>>a>>b>>c;

	cout<<YN(b-a==c-b)<<endl;
}

Measured memory_bytes: 256
data=list(map(int,input().split()))
goukei=0
num=data[3]
for i in range(0,len(data)-1):
    if data[i]<=num:
        if i==0:
            goukei=goukei+data[i]
        elif i==2:
            goukei=goukei-data[i]
        num=num-data[i]
    else:
        if i==0:
            goukei=goukei+num
        elif i==2:
            goukei=goukei-num
        num=0
print(goukei)

Measured memory_bytes: 9168
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <numeric>
#include <fstream>
#include <iomanip>

typedef long double ld;
typedef long long ll;
const ll INF = (ll)1e18 + 1;
const ll MOD = 1e9 + 7;

// Split
namespace util {

std::vector< std::string > split(std::string s, char delimiter)
{
  std::vector< std::string > vs;
  std::string sub;
  for (auto c : s) {
    if (c == delimiter) vs.push_back(sub), sub.clear();
    else sub += c;
  }
  vs.push_back(sub);
  return vs;
}

} // namespace util

// Minimum, Maximum
template<class T> T minimum(T head, T tail) { return std::min(head, tail); }
template<class H, class... T> H minimum(H head, T... tail) { return std::min(head, minimum(tail...)); }
template<class T> T maximum(T head, T tail) { return std::max(head, tail); }
template<class H, class... T> H maximum(H head, T... tail) { return std::max(head, maximum(tail...)); }

// Output
template<class T, class S> std::ostream& operator << (std::ostream& os, std::pair<T, S> p)
{
  return os << "(" << p.first << " " << p.second << ")";
}

template<class T> std::ostream& operator << (std::ostream& os, std::vector< T > v)
{
  for (ll i = 0; i < (ll)v.size(); i++){ os << " [" << i << "]" << v[i]; if (i % 10 == 9) os << std::endl; }
  //os << v[0]; for (ll i = 1; i < (ll)v.size(); i++){ os << " " << v[i]; }
  return os;
}

template<class T, class S> std::ostream& operator << (std::ostream& os, std::map< T, S > m)
{
  ll i = 0; for (auto p : m){ os << " [" << i << "]" << p.first << "->" << p.second; i++;}
  return os;
}

void print(){ std::cout << std::endl; }
template<typename H> void print(H head) { std::cout << head << std::endl; }
template<typename H, typename... T> void print(H head, T... tail){ std::cout << head << " ", print(tail...); }

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

  ll N, D;
  std::cin >> N >> D;
  std::vector< std::vector<ll> > vx(N, std::vector<ll>(D, 0LL));

  for (ll y = 0; y < N; y++) {
    for (ll x = 0; x < D; x++) {
      std::cin >> vx[y][x];
    }
  }

  ll ans = 0LL;
  for (ll a = 0; a < N; a++) {
    for (ll b = a+1; b < N; b++) {
      ll sum = 0LL;
      for (ll x = 0; x < D; x++) {
	sum += (ll)std::pow(vx[a][x] - vx[b][x], 2);
      }
      for (ll i = 0; i * i <= sum; i++) {
	if (i * i == sum) ans++;
      }
    }
  }

  print(ans);
  return 0;
}


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

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

  int n;
  cin >> n;
  string s;
  cin >> s;
  vector<int> a(n);
  int sum = 0;
  for(int i = 0; i < n; ++i) {
    a[i] = sum;
    sum += (s[i] == 'W');
  }
  sum = 0;
  for(int i = n-1; i >= 0; --i) {
    a[i] += sum;
    sum += (s[i] == 'E');
  }
  cout << *min_element(a.begin(), a.end());
}

Measured memory_bytes: 1812
(defun counting (n)
  (if (eq n 0)
      0
      (+ (rem n 10) (counting (floor n 10)))))

(defun some-sums ()
    (let ((n (1+ (read)))
	  (a (read))
	  (b (read))
	  (ans 0))
      (dotimes (i n)
	(if (and
	     (>= (counting i) a)
	     (<= (counting i) b))
	    (setf ans (+ ans i))))
      ans))
      
(format t "~A~%" (some-sums))


Measured memory_bytes: 6504
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i, c) for(long long i=0; i<(long long)c; i++)
const ll INF=1000000000000001;
vector<ll>v(100000+1);
int main() {
	int n;
	cin >>n;
	vector<int>a(n);
	int s=0;
	rep(i,n){
		cin >> a[i];
		s^=a[i];
	}
	rep(i,n){
		int t;
		t= a[i] ^ s;
		cout << t;
		if (i<n-1) cout <<" ";
		else cout <<endl;
	}
	return 0;
}


Measured memory_bytes: 4844
#include <bits/stdc++.h>
using namespace std;
#define uint unsigned int
#define llong long long int
#define ullong unsigned long long int

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

    int a, b, c; cin >> a >> b >> c;
    int n = 1;
    bool flag = false;
    while(true) {
        if ((b * n + c) % a == 0) {
            break;
        }
        if (n > 10000) {
            flag = true;
            break;
        }
        ++n;
    }
    cout << (flag ? "NO" : "YES") << endl;
    return 0;
}

Measured memory_bytes: 256
package main

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

var INF = math.MaxInt32
var INF64 = math.MaxInt64

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

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

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func readLineNums(bf *bufio.Reader) []int {
	line, _ := bf.ReadString('\n')
	line = strings.Trim(line, "\n")
	fields := strings.Split(line, " ")
	nums := []int{}
	for _, field := range fields {
		num, _ := strconv.Atoi(field)
		nums = append(nums, num)
	}
	return nums
}

func readLineFloats(bf *bufio.Reader) []float64 {
	line, _ := bf.ReadString('\n')
	line = strings.Trim(line, "\n")
	fields := strings.Split(line, " ")
	nums := []float64{}
	for _, field := range fields {
		num, _ := strconv.ParseFloat(field, 64)
		nums = append(nums, num)
	}
	return nums
}

func readLineStrs(bf *bufio.Reader) []string {
	line, _ := bf.ReadString('\n')
	line = strings.Trim(line, "\n")
	return strings.Split(line, " ")
}

func main() {
	bf := bufio.NewReader(os.Stdin)
	nk := readLineNums(bf)
	N, K := nk[0], nk[1]
	A := readLineNums(bf)

	dp := make([]int, K+1)
	dp[0] = 1

	for i:=0; i<N; i++ {
		ai := A[i]
		// 忽略该小孩
		if ai == 0 {
			continue
		}

		// 为了优化内部的循环
		dpSums := make([]int, K+1)
		dpSums[0] = dp[0]
		for j:=1; j<=K; j++ {
			dpSums[j] = dpSums[j-1]+dp[j]
		}

		for j:=K; j>=0; j-- {
			startPos := j-ai
			endPos := j-1
			if startPos < 0 {
				startPos = 0
			}
			if endPos < 0 {
				continue
			}
			dp[j] += dpSums[endPos]-dpSums[startPos]+dp[startPos]
			dp[j] %= 1e9+7

			// 需要优化掉这个循环
			// 相当于增加dp[j-ai]~dp[j-1]之间的和
			//for k:=1; k<=j && k<=ai; k++ {
			//	dp[j] += dp[j-k]
			//}
		}
	}

	fmt.Println(dp[K])
}


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

typedef pair<int, int> pii;
typedef long long ll;
typedef vector<int> vi;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()
#define dump(x) cout << #x << " = " << (x) << endl

const int MN = 410;
const ll INF = 1e18;

ll dp[MN][MN];
ll a[MN];
ll s[MN];

int main() {
	int N; cin >> N;
	rep(i, MN) rep(j, MN) dp[i][j] = INF;

	rep(i, N) {
		cin >> a[i];
		s[i+1] = s[i] + a[i];
		dp[i][i] = 0;
	}

	for (int l = 2; l <= N; ++l) {
		for (int i = 0; i <= N - l; ++i) {
			int j = i + l - 1;
			for (int m = i; m < j; ++m) {
				dp[i][j] = min(dp[i][j], dp[i][m] + dp[m+1][j] + s[j+1] - s[i]);
			}
		}
	}

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

	return 0;
}

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

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a[3];
    cin >> a[0] >> a[1] >> a[2];
    sort(a,a+3);
    if(a[0] == a[1] && a[1] == 5 && a[2] == 7) {
        cout << "YES\n";
    } else {
        cout << "NO\n";
    }
    return 0;
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
#define int  long long 
#define speedrap ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
int be(int a,int b,int mod) {if(b == 0) return 1; if(b%2 == 1) return (a*be(a,b-1,mod))%mod; else return (be(a,b/2,mod)*be(a,b/2,mod))%mod;}
const int mod = 1e9+7;
#define PI 3.1415926535
#define pf push_front
#define pb push_back
#define bitcount __builtin_popcount
#define sc(a) scanf("%d", &a);
#define sz(s) (int)s.size()
#define eb emplace_back
#define pf push_front
const int siz = 2*(1e6 + 1);
const int logi = 21;
const double epsilon = 1e-6;
int prime[siz];
vector<int> vt;
bool cmp(const int &a,const int &b)
{
  return (abs(a-b)>1);
}


void sieve()
{
	int cnt = 0;
	prime[1] = prime[0] = 1;

	for(int i = 2 ; i < siz ; i++)
	{
		if(prime[i] != 1)
		{
			cnt++;
			for(int j = 2*i ; j < siz ; j+= i)
			{
				prime[j] = 1;
			}
		}
	}

	cout<<cnt<<"\n";
	
	


}



signed main()
{
	  
	speedrap
	int t;
	t = 1;
	//cin>>t;
	while(t--)
	{
		int n,k;
		cin>>n>>k;

		n = n%k;
		cout<<min(n,abs(k-n));
	}
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main {
    
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        
         int n = scan.nextInt();
        int k= 0;
        int f;
       int i;
        int A;
       int B;
       int GA[] = new int[5];
        int GB[] = new int[5];
       
        
        
         while(n != 0 && k < 5 ){
         
         
        
      
            
        for (i = 0; i < n; i++) {
            A = scan.nextInt();
            B = scan.nextInt();
            if (A > B) {
                GA[k] = GA[k] + A + B;
            } else if (B > A) {
                GB[k] = GB[k] + A + B;
            } else {
                GA[k] = GA[k] + A;
                GB[k] = GB[k] + B;
            }
        }
            
        k++;
         n = scan.nextInt();
          
    
        
       
        }
           for(f = 0;f<k;f++){
            System.out.println(GA[f]+" "+GB[f]);

    }
        
    }
}


Measured memory_bytes: 58440
#include<stdio.h>

int selectionSort(int A[],int N){
	int i,j,minj,tmp;
	int sw = 0;
	int flag;
	for(i=0;i<N;i++){
		minj = i;
		flag = 0;
		for(j=i;j<N;j++){
			if(A[minj]>A[j]){
				minj = j;
				flag = 1;
			}
		}
		if(flag){
			tmp=A[minj];
			A[minj]=A[i];
			A[i]=tmp;
			sw++;
		}
	}
	return sw;
}

int main(){
	int N,i,j,sw;
	int A[100];
	
	scanf("%d",&N);
	for(i=0;i<N;i++) scanf("%d",&A[i]);
	
	sw = selectionSort(A,N);
	
	for(j=0;j<N;j++){
		if(j) printf(" ");
		printf("%d",A[j]);
	}
	printf("\n%d\n",sw);
	
	return 0;
}

Measured memory_bytes: 1032
import java.util.Scanner;

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


		    String str1 = scanner.next();

            int A = Integer.parseInt(str1);


            if(A % 2 == 0)
            {
            	System.out.println(A);
            }
            else
            {
            	System.out.println(A * 2);
            }
        	scanner.close();}
		  }


Measured memory_bytes: 23892
#include <bits/stdc++.h>
#define int long long
#define mod (int)(1e9+7)
#define inf (int)(3e18)
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define P std::pair<int,int>
#define PiP std::pair<int,std::pair<int,int>>
#define all(v) v.begin(),v.end()
#define mkp std::make_pair
#define prique(T) std::priority_queue<T,vector<T>,greater<T>>
using namespace std;
template<class T> inline void chmax(T& a, T b) { a = std::max(a, b); }
template<class T> inline void chmin(T& a, T b) { a = std::min(a, b); }

bool prime(int x) {
	for (int i = 2; i * i <= x; i++) {
		if (x % i == 0)return false;
	}
	return x != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}
int get_rand(int MIN, int MAX) {
	std::random_device rnd;
	std::mt19937_64 mt64(rnd());
	std::uniform_int_distribution<int>engine(MIN, MAX);
	return engine(mt64);
}
/*--------Library Zone!--------*/


double toradian(double x) {
	return x * 3.14159265358979 / 180.;
}
signed main() {
	double a, b, x; cin >> a >> b >> x;
	double c;
	if (a * b / 2 * a <= x) {
		double ng = 101., ok = 0.;
		rep(i, 100) {
			double mid = (ok + ng) / 2;
			if ((mid + b) * a / 2. * a <= x)ok = mid;
			else ng = mid;
		}
		c = ok;
		ng = 90., ok = 0.;
		rep(i, 100) {
			double mid = (ok + ng) / 2.;
			double taka = sin(toradian(90. - mid)) * b;
			double taka2 = sin(toradian(mid)) * a;
			taka2 += sin(toradian(90. - mid)) * c;
			if (taka2 <= taka)ok = mid;
			else ng = mid;
		}
		printf("%.12lf\n", ok);
	}
	else {
		double ng = 101., ok = 0.;
		rep(i, 100) {
			double mid = (ok + ng) / 2;
			if (mid * b / 2 * a <= x)ok = mid;
			else ng = mid;
		}
		double c = ok;
		ng = 90, ok = 0;
		rep(i, 100) {
			double mid = (ok + ng) / 2;
			double taka = sin(toradian(90. - mid)) * b;
			double taka2 = sin(toradian(mid)) * c;
			if (taka2 <= taka)ok = mid;
			else ng = mid;
		}
		printf("%.12lf\n", ok);
	}
}


Measured memory_bytes: 384