akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <string.h>
#include <algorithm>

char voc[105][50], str[50];
int  page[105][105];

using namespace std;

int main(void)
{
	int n, i, j, k, c, ii;
	
	i = 0;
	while (scanf("%s %d", str, &n) != EOF){
		
		c = 0;
		
		for (j = 0; j < i; j++){
			if (strcmp(str, voc[j]) == 0){
				
				k = 0;
				while (page[j][k] != 0){
					k++;
				}
				page[j][k] = n;
				c = 1;
			}
		}
		
		if (c == 0){
			strcpy(voc[i], str);
			page[i][0] = n;
			i++;
		}
	}
	
	for (j = 0; j < i; j++){
		for (k = 0; k < i - j - 1; k++){
			
			if (strcmp(voc[k], voc[k + 1]) > 0){
				strcpy(str, voc[k]);
				strcpy(voc[k], voc[k + 1]);
				strcpy(voc[k + 1], str);
				
				ii = 0;
				while (page[k][ii] != 0 || page[k + 1][ii] != 0){
					page[k][ii] += page[k + 1][ii];
					page[k + 1][ii] = page[k][ii] - page[k + 1][ii];
					page[k][ii] -= page[k + 1][ii];
					
					ii++;
				}
			}
		}
	}
	
	for (j = 0;j < i; j++){
		k = 0;
		while (page[j][k] != 0){
			k++;
		}
		sort(&page[j][0], &page[j][0] + k);
	}
	
	for (j = 0; j < i; j++){
		printf("%s\n", voc[j]);
		k = 0;
		
		while (1){
			printf("%d", page[j][k]);
			k++;
			
			if (page[j][k] == 0){
				break;
			}
			else{
				printf(" ");
			}
		}
		printf("\n");
	}
	
	return (0);
}
		

Measured memory_bytes: 1096
N = int(input())
A = list(map(int, input().split()))

p = int(1e9 + 7)

result = 0
total = 0
for i in range(N - 1, 0, -1):
    total = (total + A[i]) % p
    result = (result + A[i-1] * total) % p
print(result)

Measured memory_bytes: 31540
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
  int x;
  cin >> x;
  int sum = 0;
  int i = 0;
  while (sum < x) sum += ++i;
  cout << i << endl;
  return 0;
}

Measured memory_bytes: 3636
#define _CRT_SECURE_NO_WARNINGS

/* include ***********************/
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>

/* define *************************/
//for
#define REP(i,n) for(int i=0,i##_len=(int)(n);i<i##_len;i++)
#define REPS(i,n) for(int i=1,i##_len=(int)(n);i<=i##_len;i++)
#define RREP(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define RREPS(i,n) for(int i=(int)(n);i>0;i--)
#define FOR(i,s,n) for(int i=(int)(s),i##_len=(int)(n);i<i##_len;i++)
#define RFOR(i,s,n) for(int i=(int)(n)-1,i##_len=(int)(s);i>=i##_len;i--)

//printf
#define PRINTD(d) printf("%d\n",(d))
#define PRINTL(d) printf("%lld\n",(d))

//memset
#define m0(s) memset(s,0,sizeof(s))
#define ml(s) memset(s,63,sizeof(s))
#define fill(s,c) memset(s,c,sizeof(s))

#define INF 1e9
#define MOD 1000000007

typedef long long ll;
typedef unsigned long long ull;

int diff[4][2] = {
	{ 0, -1 },
	{ -1, 0 },
	{ 1, 0 },
	{ 0, 1 },
};
//今回の変数
int d[100000];

int Min(int a, int b) {
	return (a)<(b) ? (a) : (b);
}
int Max(int  a, int  b) {
	return (a) > (b) ? (a) : (b);
}
ll Minl(ll a, ll b) {
	return (a)<(b) ? (a) : (b);
}
ll Maxl(ll a, ll b) {
	return (a)>(b) ? (a) : (b);
}
ll getPow(ll a, ll b){
	if (b == 0) return 1;
	if (b % 2 == 0) {
		ll d = getPow(a, b / 2);
		return (d*d) % MOD;
	}
	else {
		return (a*getPow(a, b - 1))%MOD;
	}
}


int main() {
	int n,a,b;
	scanf("%d%d%d", &n, &a, &b);

	PRINTD(Min(n*a,b));
}


Measured memory_bytes: 128
n=int(input())
p=[int(i) for i in input().split()]
ans=0
for i in range(1,n-1):
  if max(p[i],p[i-1],p[i+1])!=p[i] and min(p[i],p[i-1],p[i+1])!=p[i]:
    ans+=1
print(ans)

Measured memory_bytes: 3060
import java.util.*;

public class Main {
    public void main(Scanner sc) {
        int n = sc.nextInt();
        int res[] = new int[n];
        res[0] = 2;
        res[1] = 3;
        int sum = 5;

        if (n <= 5) {
            for (int i = 2; i < n; i++) {
                sum += res[i - 1] + 1;
                for (int num = res[i - 1] + 1; num <= 30000; num++, sum++) {
                    if (sum % 6 != 0) {
                        continue;
                    }
                    res[i] = num;

                    boolean isOk = true;
                    for (int j = 0; j <= i; j++) {
                        if (gcd(res[j], sum) == 1) {
                            isOk = false;
                            break;
                        }
                    }

                    if (isOk) {
                        break;
                    }
                }
            }
        } else {
            for (int i = 2; i < n; i++) {
                res[i] = 6 * (i / 4) + (2 + i % 2) * (1 + (i % 4) / 2);
                sum += res[i];
            }

            switch (sum % 6) {
            case 2:
                res[4] = 6 * ((n + 1) / 4) + 6;
                sum = sum - 8 + res[4];
                break;
            case 3:
                res[5] = 6 * ((n + 1) / 4) + 6;
                sum = sum - 9 + res[5];
                break;
            case 5:
                res[5] = 6 * ((n + 1) / 4) + 4;
                sum = sum - 9 + res[5];
                break;
            default:
                break;
            }
        }

        System.out.println(Arrays.toString(res).replaceAll("[^ 0-9]", ""));
    }

    private int gcd(int a, int b) {
        return b == 0 ? a : gcd(b, a % b);
    }

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


Measured memory_bytes: 28400
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<map>
#include<stack>
#include<cmath>
#include<iomanip>
#include<set>
#include<numeric>
#include<sstream>
#include<random>
#include<cassert>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, st, n) for (int i = st; i < n; ++i)
using pii = pair<int, int>;
const int inf = 1e9 + 7;
int dy[] = {0, 0, -1, 1, -1, 1, -1, 1};
int dx[] = {1, -1, 0, 0, -1, 1, 1, -1};
#define ceil(a, b) a / b + !!(a % b)


int main() {
    cin.tie(0); ios::sync_with_stdio(false);
    int a, b; cin >> a >> b;
    cout << (a - 1) * (b - 1) << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
    int N, x;
    cin >> N >> x;
    int a[N];
    for(int i = 0; i < N; i++)
        cin >> a[i];

    sort(a, a + N);
    
    int cnt = 0, i = 0;
    while(x >= a[i] && i < N){
        cnt++;
        x -= a[i++];
    }
    if(i == N && x > 0)
        cnt--;

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

Measured memory_bytes: 3492
#include<iostream>
#include<algorithm>
#include<string>
#include<functional>
#include<utility>
#include<stack>
#include<queue>
#include<cmath>
#include<list>
#include<cstdint>
#include<vector>
#include<map>
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define rep(i,rept)	for(ll i = 0; i<rept;i++)
typedef long long ll;

ll nCr(ll n, ll r) {
	if (r > n) { return 0; }
	if (r * 2 > n) r = n - r;
	ll dividend = 1;
	ll divisor = 1;
	for (ll i = 1; i <= r; ++i) {
		dividend *= (n - i + 1);
		divisor *= i;
	}
	return dividend / divisor;
}
ll sumdigit(ll n) {
	ll dig = 0, sum = 0;
	while (n) {
		dig = n % 10;
		sum = sum + dig;
		n = n / 10;
	}
	return sum;
}



int main() {
	int n = 0, k = 0;
	int ans = 0;
	int ar[50] = {};
	std::cin >> n >> k;
	rep(i, n) {
		std::cin >> ar[i];
	}
	std::sort(ar, ar + n,std::greater<int>());
	rep(i, k) {
		ans += ar[i];
	}
	std::cout << ans << std::endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define INF ((1LL<<62)-(1LL<<31))
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define bit(n,m)(((n)>>(m))&1)
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}
ll pom(ll a,ll n,int m){ll x=1;for(a%=m;n;n/=2)n&1?x=x*a%m:0,a=a*a%m;return x;}
//#define MOD 998244353
#define MOD 1000000007
#define invp(a,p)pom(a,p-2,p)

int main(){
	ll a,b;
	scanf("%lld%lld",&a,&b);
	ll ans=(b+(b+a-1))*a/2;
	if(b*(b+a-1)>0){
		ans-=llabs(b)<llabs(b+a-1)?b:b+a-1;
	}
	printf("%lld",ans);
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#include <unordered_map>
#define endl '\n';
#define all(v) ((v).begin()), ((v).end())
#define sz(s)               (int)s.size()
#define Ceil(x,y)             ((x+y-1)/y)
#define RT(x)           return cout<<x,0;
#define mem(x,y)    memset(x,y,sizeof(x))
#define vi                    vector<int>
#define pii                 pair<int,int>
#define fx(n)           fixed<<setprecision(n)
#define watch(x) cout<<(#x)<<" = "<<x<<endl
#define forr(i, n) for (int i = 0; i < int(n); i++)
typedef long long ll;
typedef unsigned long long ull;
typedef double dl;
const double PI = acos(-1), EPS = 1e-7;
const int OO = 0x3f3f3f3f, N = 1e7 + 5, MOD = 1e9 + 7;
using namespace std;
void fast() { std::ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); }
int main()
{
	fast();
	int n;
	cin>>n;
	vector<int>v(n+1);
	ll ans=0;
	for(int i=1;i<=n;i++)
    {
        cin>>v[i];
        if(i%2!=0 && v[i]%2!=0)
            ans++;
    }
    cout<<ans<<"\n";

    return 0;
}


Measured memory_bytes: 3580
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
char s[100005];
int main()
{	
	scanf("%s",s+1);
	int n=strlen(s+1),ans=0;
	for(int i=1;i<n;i++)ans+=(s[i]!=s[i+1]);
	cout<<ans;
	return 0;
}

Measured memory_bytes: 384
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;
using static System.Array;

class Program
{
    public static void Main()
    {
        var n = ReadLine().Split().Select(int.Parse).ToArray();
        int a = n[0];
        int b = n[1];
        int h = n[2];
        int m = n[3];
        double hx = a * Sin(PI / 180 * 30 * (h + m / 60d));
        double hy = a * Cos(PI / 180 * 30 * (h + m / 60d));
        double mx = b * Sin(PI / 180 * 6 * m);
        double my = b * Cos(PI / 180 * 6 * m);
        double result = Sqrt((hx - mx) * (hx - mx) + (hy - my) * (hy - my));
        WriteLine(result.ToString("F16"));
    }
}


Measured memory_bytes: 19996
#include<bits/stdc++.h>
#define int long long
#define rep(i,a,b) for(int i=a;i<b;i+=1)
#define reps(i,a,b) for(int i=a;i>=b;i-=1)
#define vi vector<int>
#define vvi vector<vector<int>>
#define pb push_back
#define pi pair<int, int>
#define mp make_pair
#define ff first
#define ss second
#define in1(x) int x; cin>>x;
#define in2(x, y) int x, y; cin>>x>>y;
#define in3(x, y, z) int x, y, z; cin>>x>>y>>z;
#define in4(x, y, z, w) int x, y, z, w; cin>>x>>y>>z>>w;
#define mi unordered_map<int,int>
#define mem(x) memset(x, 0, sizeof(x))
#define IOS ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
#define mod 1000000007
using namespace std;
bool primes[1000001];vi prime; void seive(); int gcd(int a, int b); int power(int x, int y);

int32_t main(void){
	IOS;
	in3(n, x, t);
	int tmp = ceil((n*1.00)/x);
	cout<<tmp*t<<endl;
}

void seive(){memset(primes, true, sizeof(primes));primes[0] = primes[1] = false;for(int i = 2; i*i<=1000000;i += 1){
if(primes[i]){for(int j = i*i; j <= 1000000;j += i) primes[j] = false;}}rep(i, 2, 1000001){if(primes[i]) prime.pb(i);}}
int gcd(int a, int b){return b==0 ? a : gcd(b, a%b);}
int power(int x, int y){ int res = 1;x = x % mod; if (x == 0) return 0;
while (y > 0){ if(y & 1) res = (res*x) % mod; y = y>>1; x = (x*x) % mod;} return res;}


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

int main()
{
    int n;
    cin >> n;
    int store[n+1];

    for (int i = 1; i <= n; i++) {
        scanf("%d", &store[i]);
    }

    int mi = INT_MAX;
    for (int i = -100; i <= 100; i++) {
        int sum = 0;
        for (int j = 1; j <= n; j++) {
            sum += (store[j] - i) * (store[j] - i);
        }
        mi = min(sum, mi);
    }

    cout << mi << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#define MOD 1000000007
using namespace std;
typedef long long ll;
int main(void) {
  bool notprime[1001] = {};
  vector<int> primes;
  for (int i = 2; i <= 1000; i++) {
    if (!notprime[i]) {
      for (int j = i; j <= 1000; j += i) notprime[j] = 1;
      primes.push_back(i);
    }
  }
  int n;
  cin >> n;
  vector<int> cnt(primes.size(), 0);
  for (int i = 2; i <= n; i++) {
    int tmp = i;
    for (int j = 0; j < primes.size(); j++) {
      while (tmp % primes[j] == 0) {
        cnt[j]++;
        tmp /= primes[j];
      }
    }
  }
  ll ans = 1LL;
  for (int i = 0; i < primes.size(); i++) {
    ans = ans * (cnt[i] + 1) % MOD;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
import math

while True:
  n = int(input())
  if n == 0:
    break
  s = list(map(int,input().split()))
  
  a2 = 0
  avg = sum(s) / len(s)
  for i in s:
    a2 += (i-avg)**2
  a = math.sqrt(a2/n)
  
  print(a)


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

using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using vint = vector<int>;
using vvint = vector<vint>;
using vvvint = vector<vvint>;
using vdouble = vector<double>;
using vvdouble = vector<vdouble>;
using vvvdouble = vector<vvdouble>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using uint = unsigned int;
using ull = unsigned long long;

template<typename T> using uset = unordered_set<T>;
template<typename T1, typename T2> using umap = unordered_map<T1, T2>;

constexpr int INF = (1 << 30) - 1;
constexpr ll LLINF = 1LL << 60;
constexpr int dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr char el = '\n';
constexpr int mod = 1000000007;

template<typename T> T gcd(T a, T b) { return (b ? gcd(b, a % b) : a); }
template<typename T> T lcm(T a, T b) { return (a / gcd(a, b) * b); }
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) { return (a > b && (a = b, true)); }
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) { return (a < b && (a = b, true)); }

template<typename T>
ostream& operator <<(ostream &os, vector<T> &v) {
	os << v[0];
	for (int i = 1; i < v.size(); i++) os << " " << v[i];
	return (os);
}

template<typename T>
istream& operator >>(istream &is, vector<T> &v) {
	for (auto &u : v) is >> u; return (is);
}

template<typename T1, typename T2>
istream& operator >>(istream &is, pair<T1, T2> &p) {
	return (is >> p.first >> p.second);
}

inline bool match(char x, char y) {
	return (x == '?' || y == '?' || x == y);
}

void Main() {
	vector<string> abc(3);
	cin >> abc;
	vint dat = {0, 1, 2};

	int ans = 6000;
	do {
		string a = abc[dat[0]], b = abc[dat[1]], c = abc[dat[2]];
		int A = a.size(), B = b.size(), C = c.size();
		bitset<2000> ac;

		vint cab, cbc;
		for (int i = 0; i <= A; i++) {
			bool flag = true;
			for (int j = 0; j < B && i+j < A; j++) {
				flag &= match(a[i+j], b[j]);
			}
			if (flag) cab.push_back(i);
		}

		for (int i = 0; i <= max(A, B); i++) {
			bool flag = true;
			for (int j = 0; j < C && i+j < B; j++) {
				flag &= match(b[i+j], c[j]);
			}
			if (flag) cbc.push_back(i);
		}
		for (int i = 0; i < A; i++) {
			bool flag = true;
			for (int j = 0; j < C && i+j < A; j++) {
				flag &= match(a[i+j], c[j]);
			}
			ac[i] = flag;
		}
		
		for (auto &i : cab) for (auto &j : cbc) {
			if (i+j >= A || ac[i+j]) {
				chmin(ans, max({A, i + B, i+j + C}));
			}
		}
	} while (next_permutation(begin(dat), end(dat)));
	cout << ans << endl;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(0);
	cout << fixed << setprecision(20);
	Main();
	return (0);
}


Measured memory_bytes: 384
n = int(input())
d = {}
for i in range(1, 100):
    for j in range(1, i + 1):
        for k in range(1, j + 1):
            l = i ** 2 + j ** 2 + k ** 2 + i * j + j * k + k * i
            if i == j == k:
                m = 1
            elif i == j or j == k or k == i:
                m = 3
            else:
                m = 6
            if l in d:
                d[l] += m
            else:
                d[l] = m
for i in range(1, n + 1):
    if i in d:
        print(d[i])
    else:
        print(0)

Measured memory_bytes: 11660
line = list(input().split(" "))
n = int(line[0])
k = int(line[1])
p = list(input().split(" "))
result = 0
sum = 0
for i in range(k):
    sum += int(p[i])
for i in range(n-k):
    result = max(result,sum)
    sum += int(p[i+k]) - int(p[i])
result = max(result,sum)
print((result+k)/2)

Measured memory_bytes: 18852
#include <stdio.h>

#define Max 101

int main(){

  int i, n, m, j, u, k;
  int Adj[Max][Max];

  scanf("%d",&n);

  for(i = 0; i < n ; i++)
    for(j = 0 ; j < n ; j++)
      Adj[i][j] = 0;


  for(i = 0; i < n ; i++){
    scanf("%d%d",&u,&k);
    for( j = 0 ; j < k ; j++){
      scanf("%d",&m);
      Adj[u-1][m-1] = 1;     
    }
  }
  
  for(i = 0; i < n ; i++){
    for(j = 0 ; j < n ; j++){
      printf("%d",Adj[i][j]);
      if( j != n - 1)
	printf(" ");
    }
    printf("\n");
  }
  return 0;
}

Measured memory_bytes: 640
#nowarn "25"

open System

let INF = int64 1e18

let [|n; m|] = stdin.ReadLine().Split() |> Array.map(int)

let mutable graph = Array.create (int n + 1) []
for i in 1 .. m do
    let [|a; b|] = stdin.ReadLine().Split() |> Array.map(int)
    graph.[a] <- b :: graph.[a]
    graph.[b] <- a :: graph.[b]

let prev = Array.create (n + 1) (-1)

let mutable q = [ 1 ]

let rec loop (q : int list) =
    let mutable q2 = []
    for v in q do
        for t in graph.[v] do
            if prev.[t] = -1 then
                prev.[t] <- v
                q2 <- t :: q2
        
    if not q2.IsEmpty then
        loop q2

loop [ 1 ]

printfn "Yes"
for i in 2 .. n do
    printfn "%d" prev.[i]

Measured memory_bytes: 57440
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double lf;
typedef pair<ll,ll> ii;
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define RST(i,n) memset(i,n,sizeof i)
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(),a.end()
#define X first
#define Y second
#define mkp make_pair
#define pb push_back
#define eb emplace_back
#define pob pop_back
#ifdef cold66
#define debug(...) do{\
    fprintf(stderr,"%s - %d (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
    _do(__VA_ARGS__);\
}while(0)
template<typename T>void _do(T &&_x){cerr<<_x<<endl;}
template<typename T,typename ...S> void _do(T &&_x,S &&..._t){cerr<<_x<<", ";_do(_t...);}
template<typename _a,typename _b> ostream& operator << (ostream &_s,const pair<_a,_b> &_p){return _s<<"("<<_p.X<<","<<_p.Y<<")";}
template<typename It> ostream& _OUTC(ostream &_s,It _ita,It _itb)
{
    _s<<"{";
    for(It _it=_ita;_it!=_itb;_it++)
    {
        _s<<(_it==_ita?"":",")<<*_it;
    }
    _s<<"}";
    return _s;
}
template<typename _a> ostream &operator << (ostream &_s,vector<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,set<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a,typename _b> ostream &operator << (ostream &_s,map<_a,_b> &_c){return _OUTC(_s,ALL(_c));}
template<typename _t> void pary(_t _a,_t _b){_OUTC(cerr,_a,_b);cerr<<endl;}
#define IOS()
#else
#define debug(...)
#define pary(...)
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#endif // cold66
//}
template<class T> inline bool chkmax(T &a, const T &b) { return b > a ? a = b, true : false; }
template<class T> inline bool chkmin(T &a, const T &b) { return b < a ? a = b, true : false; }
template<class T> using MaxHeap = priority_queue<T>;
template<class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;

const ll MAXn=15,MAXlg=__lg(MAXn)+2;
const ll MOD=1000000007;
const ll INF=0x3f3f3f3f;

ll n,a,b,c;
ll ans = INF;
ll d[MAXn];
ll ta,tb,tc,cost;
void dfs(ll x){
	if (x == n) {
		if (ta && tb && tc) {
			ans = min(ans,abs(ta-a) + abs(tb-b) + abs(tc-c) + cost);
		}
		return;
	}
	dfs(x+1);

	if (ta) cost += 10;
	ta += d[x];
	dfs(x+1);
	ta -= d[x];
	if (ta) cost -= 10;

	if (tb) cost += 10;
	tb += d[x];
	dfs(x+1);
	tb -= d[x];
	if (tb) cost -= 10;

	if (tc) cost += 10;
	tc += d[x];
	dfs(x+1);
	tc -= d[x];
	if (tc) cost -= 10;
}
int main(){
  IOS();
	cin >> n >> a >> b >> c;
	REP (i,n) cin >> d[i];
	dfs(0);
	cout << ans << endl;
}


Measured memory_bytes: 256
#import numpy as np
import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial#, gcd
from bisect import bisect_left #bisect_left(list, value)
sys.setrecursionlimit(10**7)
enu = enumerate
MOD = 10**9+7
def input(): return sys.stdin.readline()[:-1]
pl = lambda x: print(*x, sep='\n')

A, V = map(int, input().split())
B, W = map(int, input().split())
T = int(input())

l = abs(B-A)
dV = V-W

if dV<=0 and l>0:
    print('NO')
else:
    if dV*T>=l:
        print('YES')
    else:
        print('NO')


Measured memory_bytes: 9488
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <array>
#include <vector>
#include <functional>
#include <unordered_map> 
#include <map> 
#include <numeric>
#include <limits>
#include <utility>
#include <queue>
#include <random>
#include <bitset>
#include <memory>
#include <complex>
using namespace std;
typedef long long LL;

vector<vector<LL>> dp(2000,vector<LL>(2000,-1));

LL combi(int n, int r) {
	if (dp[n][r] != -1) {
		return dp[n][r];
	}
	if (r == 0) {
		dp[n][r]=1;
		return 1;
	}
	if (n == 0) {
		dp[n][r] = 0;
		return 0;
	}
	dp[n][r]= (combi(n - 1, r) + combi(n - 1, r - 1))%  (1000000000 + 7);
	return dp[n][r];
}

LL c(LL n, LL r) {
	LL ans;
	bool ss=true;
	if (r == 0) {
		return 1;
	}

	LL na = 1, ra = 1;
	vector<LL> rr(r,1);
	for (LL i = n; i > n - r; i--) {
		na *= i;

		for (LL j = 0; j < r; j++) {
			if (rr[j] == 1) {
				if (na % (j + 1) == 0) {
					na/=(j+1);
					rr[j]=0;
					//j=0;
				}
			}
		}
		bool flag = true;
		
		if (ss) {
			for (LL j = 0; j < r; j++) {
				if (rr[j] == 1) {
					flag = false;
					break;
				}
			}
		}
		if (flag) {
			na %= 1000000000 + 7;
			ss=false;
		}
	}



	return na;
}





LL cc(LL n, LL r) {
	LL ans;
	bool ss = true;
	if (r == 0) {
		return 1;
	}

	LL na = 1, ra = 1;
	vector<LL> rr(r, 1);
	for (LL i = n; i > n - r; i--) {
		na *= i;

		for (LL j = 0; j < r; j++) {
			if (rr[j] == 1) {
				if (na % (j + 1) == 0) {
					na /= (j + 1);
					rr[j] = 0;
					//j = 0;
				}
			}
		}
	}



	return na;
}


int main(void)
{
	LL k,n,l,blue,red;
	cin >>n>>k;
	blue = k;
	red = n - k;
	if (red < blue) {
		l=red+1;
	}
	else {
		l=blue;
	}


	for (LL i = 0; i < k; i++) {
		LL r,b;
		b=combi(blue-1,i);
		r=combi(red+1,i+1);
		//cout <<b<<endl<<r<<endl;
		b=b*r;
		b%= 1000000000 + 7;
		cout <<b<<endl;
	}

	return 0;
}

Measured memory_bytes: 31744
#include <bits/stdc++.h>
#define rep(i, N) for (int i = 0; i < N; i++)
using namespace std;
int main()
{
    string S;
    cin >> S;
    int count1 = 0, count0 = 0;
    rep(i, S.size())
    {
        if (S[i] == '0')
        {
            count0++;
        }
        else if (S[i] == '1')
        {
            count1++;
        }
    }
    cout << min(count0, count1) * 2 << endl;
}


Measured memory_bytes: 512
import java.util.*;

class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n, ans, tmp, sqrt;
		boolean[] table;
		while(sc.hasNext()){
			n = sc.nextInt();
			ans = 0;
			table = new boolean[n + 1];
			for(int i = 2; i < n + 1; i++){
				if(!table[i]){
					for(int j = i; j < n + 1; j += i){
						table[j] = true;
					}
					ans++;
				}
			}
			
			System.out.println(ans);
		}
	}
}

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

namespace ARC061
{
    class Program
    {
        static readonly char DELIMITER = ',';

        static void Main(string[] args)
        {
            long result = 0L;

            string S = Console.ReadLine();
            int length = S.Length;

            for (uint bit = 0; bit < (1 << length); bit++)
            {
                string tmpS = string.Copy(S);
                // Console.WriteLine(Convert.ToString(bit, toBase: 2));

                // 追加した区切り文字の数
                int cnt = 1;

                for (int i = 0; i < length; i++)
                {
                    if (((bit >> i) & 1) == 1)
                    {
                        // iビット目が立っている場合
                        tmpS = tmpS.Insert(i + cnt, DELIMITER.ToString());
                        cnt++;
                    }
                }
                // Console.WriteLine(tmpS);

                List<long> list = tmpS.Split(new char[] { DELIMITER }, StringSplitOptions.RemoveEmptyEntries)
                    .Select(s => long.Parse(s))
                    .ToList();

                long sum = list.Sum();
                result += sum;
            }

            Console.WriteLine(result / 2);
            Console.ReadLine();
        }
    }
}

Measured memory_bytes: 13396
#include <bits/stdc++.h>
#define endl '\n'
#define pb push_back
#define ll long long
#define lli long long int
#define li long int
#define ld long double
#define vi vector<int>
#define vlli vector<lli>
#define vii vector<pair<int, int>>
#define pii pair<int, int>
#define mp(a, b) make_pair(a, b)
#define all(arr) arr.begin(), arr.end()
using namespace std;
const lli mod = 1e9 + 7;
const lli mod_ = 998244353;
const int INF = 1000000000;
const lli INF64 = (lli)1E18;
const int MAX = 1e5 + 5;

int main() {
	// ifstream cin("input.in");
	// ofstream cout("output.out");
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	int n, capacity, weight, value;
	cin >> n >> capacity;
	vlli dp(capacity+1);
	for(int item = 0; item < n; item++) {
		cin >> weight >> value;
		for(int weight_taken = capacity - weight; weight_taken >= 0; weight_taken--) {
			dp[weight_taken+weight] = max(dp[weight_taken+weight], value + dp[weight_taken]);
		}
	}
	cout << *max_element(all(dp));
	return 0;
}

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

#define MAX 100000

bool cmp(const int n1, const int n2) {
	return n1 < n2;
}

struct Data {
	int num;
	int i;
};

int main() {
	int n;
	int minValue = MAX;
	int sortAry[1000];
	Data ary[1000];
	vector<vector<int> > groups;
	int cost = 0;

	cin >> n;
	for (int i = 0; i < n; i++) {
		int temp;
		cin >> temp;
		sortAry[i] = ary[i].num = temp;
		minValue = min(minValue, temp);
	}

	sort(sortAry, sortAry + n, cmp);
	
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			if (ary[i].num == sortAry[j]) {
				ary[i].i = j;
				break;
			}
		}
	}

	for (int i = 0; i < n; i++) {
		vector<int> group;
		int j = i;
		int s = i;
		while (j != ary[j].i) {
			group.push_back(ary[j].num);

			int temp = ary[j].i;
			ary[j].i = j;
			j = temp;
		}
		if (!group.empty()) {
			groups.push_back(group);
		}
	}

	for (int i = 0; i < groups.size(); i++) {
		int sum = 0;
		int m = MAX;
		int num = groups[i].size();

		for (int j = 0; j < num; j++) {
			sum += groups[i][j];
			m = min(groups[i][j], m);
		}

		int c1, c2;
		c1 = sum + (num - 2) * m;
		c2 = sum + (num + 1) * minValue + m;
		cost += min(c1, c2);
	}

	cout << cost << endl;

	return 0;
}

Measured memory_bytes: 3176
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main(){
    int n; cin>>n;
    map<int,int> m;
    m[1]=0;
    rep(i,n){
        int a,cnt=0; cin>>a;
        while(a%2==0){
            a/=2;
            cnt++;
        }
        cnt=min(cnt,2);
        if(!(m.count(cnt))) m[cnt]=0;
        m[cnt]++;
    }
    m[1]=(m[1]>0 ? 1 : 0);
    int k=(m.count(2) ? m[2] : 0);
    int l=m[1]+(m.count(0) ? m[0] : 0);
    if(k>=l-1) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include"bits/stdc++.h"
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPS(i,n) for(int i=1, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val) { std::fill( (T*)array, (T*)(array+N), val ); }
#define INF 1e9
#define PI (acos(-1))
#define mod (int)1e9+7
int main() {
    int n;
    cin >> n;
    vector<ll> a(n);
    REP(i, n)cin >> a[i];
    sort(all(a),greater<ll>());
    ll sum = 0;
    vector<ll> v(n+1);
    REP(i, n/2) {
        v[2 * i] = a[i];
        v[2 * i + 1] = a[n - i - 1];
    }
    if (n % 2 == 1)v[n - 1] = a[n / 2];
    v[n] = v[0];
    REPS(i, ceil((double)n/2)) {
        sum += min(v[2 * i - 2], v[0]);
    }
    REPS(i, n / 2 + 1) {
        sum += min(v[2 * i - 2], v[2 * i]);
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 6436
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <cmath>
#include <algorithm>
#include <iomanip>
using namespace std;
#define MOD int(1e9 + 7)

int main()
{
    long long N, M;
    vector<long long> A;

    cin >> N >> M;
    map<long long, long long> count;
    long long tmp = 0;
    count[0]++;
    for(long long i = 0; i < N; i++){
        long long t;
        cin >> t;
        tmp = (tmp + t) % M;
        count[tmp]++;
    }

    long long total = 0;
    for(auto x : count)
        total += (x.second * (x.second - 1)) / 2;

    cout << total << endl;

}

Measured memory_bytes: 4224
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using ll = long long;
using pii = pair<int,int>;
using vi = vector<int>;
using vs = vector<string>;
using vll = vector<long long>;
using vpii = vector<pair<int,int>>;
using vivi = vector<vector<int>>;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};



int main(void) {
  ll n;
  cin >> n;
  ll sum = 0;
  for(ll i = 0;i<n;i++) sum += i;
  cout << sum << endl;
}


Measured memory_bytes: 384
fun main(args: Array<String>) {
    val (height, width) = readLine()!!.trim().split(' ').map {it.toInt()}

    val table: Array<Array<Boolean>> = Array(height) {Array(width) {false}}

    (0..(height - 1)).forEach { y ->
        val chars: List<Char> = readLine()!!.trim().map {it}

        chars.forEachIndexed { x, char ->
            if (char == '#') {
                table[y][x] = true
            }
        }
    }

    if (canPaint(table, height, width)) {
        println("Yes")
    } else {
        println("No")
    }
}

fun canPaint(table: Array<Array<Boolean>>, height: Int, width: Int): Boolean {

    table.forEachIndexed { y, row ->
        row.forEachIndexed { x, black ->
            if (black && !isExistNearBlack(y, x, table, height, width)) {
                return false
            }
        }
    }

    return true
}

fun isExistNearBlack(y: Int, x: Int, table: Array<Array<Boolean>>, height: Int, width: Int): Boolean {

    val diffs = listOf(Pair(-1, 0), Pair(1, 0), Pair(0, -1), Pair(0, 1))
    diffs.forEach { diff ->
        val yDiff = diff.first
        val xDiff = diff.second
        val targetY = y + yDiff
        val targetX = x + xDiff

        if (targetY >= 0 && targetY < height &&
                        targetX >= 0 && targetX < width &&
                        table[targetY][targetX]
        ) {
            return true
        }
    }

    return false
}

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

int main() {
  int num;
  int mod = 1000000007;
  cin >> num;
  long long sum=0;
  vector<int> kazu(num);
  vector<long long > sum_i(num+1,0);
  for(int i = 0;i < num;i++)
  {
    cin >>kazu.at(i);
    sum_i.at(i+1) = sum_i.at(i)+ kazu.at(i);
  }
  for(int i = 0;i < num; i++)
  {
    long long sub_sum = (sum_i.at(num)-sum_i.at(i+1))%mod;
    sum += kazu.at(i)*sub_sum;
    sum %= mod;
  }
  cout << sum;
}


Measured memory_bytes: 5636
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i <(n); ++i)
#define REP2(i,x,n) for (int i = x; i <(n); ++i)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using P = pair<int,int>;
static const double PI = acos(-1);
static const int INF = 1e9+7;



int main(){
  int n;
  cin >> n;
  int minus = n/15;
  int ans = n*800 - minus * 200;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3624
import sys
readline = sys.stdin.buffer.readline

n = int(readline())
T = list(map(int,readline().split()))
m = int(readline())
PX = [list(map(int,readline().split())) for i in range(m)]

class Input():
    def __init__(self,n,T,m,PX):
        self.n = n
        self.T = T
        self.m = m
        self.PX = PX

class Calc(Input):
    def __call__(self):
        time_sum = self.requre_sum()
        for i in range(self.m):
            substract = self.add_sub(i)
            print(time_sum - substract)
    
    def requre_sum(self):
        return sum(self.T)
    
    def add_sub(self,i):
        return self.T[self.PX[i][0]-1] - self.PX[i][1]


x = Calc(n,T,m,PX)

x()

Measured memory_bytes: 38384
import sys
# import re
import math
import collections
# import decimal
import bisect
import itertools
import fractions
# import functools
import copy
# import heapq
import decimal
# import statistics
import queue

# import numpy as np

sys.setrecursionlimit(10 ** 9)
INF = 10 ** 16
MOD = 10 ** 9 + 7
# MOD = 998244353

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===

def main():
    naf = lambda: list(map(float, sys.stdin.readline().split()))

    n = ni()
    p = naf()

    dp = [[0 for _ in range(n + 1)] for __ in range(n + 1)]
    dp[0][0] = 1

    # dp[i][j] : pのうちi個めまでを投げて、表がj個出る確率
    for i in range(n):
        for j in range(n):
            dp[i + 1][j + 1] += dp[i][j] * p[i]
            dp[i + 1][j] += dp[i][j] * (1 - p[i])

    print(sum(dp[n][(n + 1) // 2:]))


if __name__ == '__main__':
    main()


Measured memory_bytes: 228848
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>

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

typedef int long long ll;
using namespace std;
typedef pair<int, int> P;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const ll MOD = 1e9 + 7;
static const int MAX = 100;
static const int INF = (1 << 23);

int main() {
string s;
cin>>s;
int k;
cin>>k;
vector<int> v(s.size());

rep(i,s.size()){
    //cout<<26-(s[i]-'a')<<endl;
    v[i]=26-(s[i]-'a');
    if(s[i]=='a'){
        v[i]=0;
    }
}

rep(i,v.size()){
    if(k>=v[i]){
        s[i]='a';
        k-=v[i];
        v[i]=0;
    }
}



if(k>0) {
    if(k>=26){
        k%=26;
    }

   int t=s[s.size()-1]-'a';
    t+=26;
    t%=26;
    s[s.size()-1]=char(k+t+'a');
}

cout<<s<<endl;




    return 0;
}


Measured memory_bytes: 896
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>

using namespace std;

int Sum10(int n);

int main()
{
    // 入力
    int n;
    cin >> n;
    
    string ans = "No";
    for (int i=0;i<30;i++){
        for (int j=0;j<30;j++){
            if(i*4+j*7==n){
                ans = "Yes";
                break;
            }
        }
    }
    cout << ans <<endl;
    return 0;
}

int Sum10(int n){
    int sum = 0;
    while (n > 0){
        sum += n % 10;
        n /= 10;
    }
    return sum;
}



Measured memory_bytes: 256
mod = 1000000007
eps = 10**-9


def main():
    import sys
    from bisect import bisect_left
    input = sys.stdin.readline

    N = int(input())

    A = [1]
    a = 1
    for i in range(1, 10000):
        a += 26**i
        A.append(a)
        if a > 1000000000000001:
            break

    i = bisect_left(A, N+1)
    N0 = A[i]
    K = N - N0
    ans = [97] * i
    for j in range(i):
        ans[-j-1] += K % 26
        K //= 26
    print("".join(map(chr, ans)))


if __name__ == '__main__':
    main()


Measured memory_bytes: 62592
#include <iostream>
#include <vector>
#include <queue>

using namespace std;

struct MonoQueue {
    int i = 0;
    int k;
    deque<int> dq, dqi;//can use deque<pair<int, int>> with <index, value> pair.
    
    MonoQueue(int k): k(k){}
    
    void add(int v) {
          while (!dq.empty()) {
            if (dq.back() > v) {
               dq.pop_back();
               dqi.pop_back();
             }
             else {
                break;    
              }
            }
            dq.push_back(v);
            dqi.push_back(i);
            if (i - k >= 0) {
                if (i - k == dqi.front()) {
                    dq.pop_front();
                    dqi.pop_front();
                }
            }
            i++;
    }

    int query() {
           return dq.front();
    }
};

int main() {
    int n, k;
    cin >> n >> k;
    MonoQueue q(k);
    
    for (int i = 0; i < n; i++) {
        int v;
        cin >> v;
        q.add(v);
        if (i >= k - 1) {
            cout << q.query() << (i != n - 1? " " : "\n");
        }
    }
    return 0;
}

Measured memory_bytes: 3292
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <iostream>
#include <utility>
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) 
 
using namespace std;
using ll = long long;
using ld = long double;
using Vl = vector<ll>;
using pll = pair<ll, ll>;
using vb = vector<bool>;
using vs = vector<string>;

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

string S;
int main() {
    cin >> S;
    bool good = true;
    REP(i,S.size()){
        bool odd = i%2==0;
        if(odd){
            if(S[i]=='L'){
                good=false;
            }
        }else{
            if(S[i]=='R'){
                good=false;
            }
        }
    }
    if(good){
        cout<< "Yes" << endl;
    }else{
        cout<< "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long   // <-----!!!!!!!!!!!!!!!!!!!

#define rep(i,n) for (int i=0;i<(n);++i)
#define rep2(i,a,b) for (int i=(a);i<(b);++i)
#define rrep(i,n) for (int i=(n)-1;i>=0;--i)
#define rrep2(i,a,b) for (int i=(a)-1;i>=b;--i)
#define chmin(a,b) (a)=min((a),(b));
#define chmax(a,b) (a)=max((a),(b));
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define printV(_v) cout<<(#_v)<<":";for(auto(_x):(_v)){cout<<" "<<(_x);}cout<<endl;
#define printVS(vs) cout<<(#vs)<<":"<<endl;for(auto(s):(vs)){cout<<(s)<< endl;}
#define printVV(vv) cout<<(#vv)<<":"<<endl;for(auto(v):(vv)){for(auto(x):(v)){cout<<" "<<(x);}cout<<endl;}
#define printP(p) cout<<(#p)<<(p).first<<" "<<(p).second<<endl;
#define printVP(vp) cout<<(#vp)<<":"<<endl;for(auto(p):(vp)){cout<<(p).first<<" "<<(p).second<<endl;}

inline void output(){ cout << endl; }
template<typename First, typename... Rest>
inline void output(const First& first, const Rest&... rest) {
    cout << first << " "; output(rest...);
}

using ll = long long;
using Pii = pair<int, int>;
using TUPLE = tuple<int, int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
const int inf = 1e9;
const int mod = 1e9 + 7;
// using Graph = vector<vector<int>>;

// 15:41-16:07

struct edge {
    int to, cost;
    edge(){}
    edge(int _to, int _cost) : to(_to), cost(_cost) {}
};
using Graph = vector<vector<edge>>;

int dijkstra(const Graph& G, int s, int g) {
    int n = G.size();
    using State = pair<int, int>;
    priority_queue<State, vector<State>, greater<State>> pq;   // cost, vertex
    vector<int> d(n, inf);
    d[s] = 0;
    pq.push(State(0, s));

    while (!pq.empty()) {
        auto p = pq.top(); pq.pop();
        int v = p.second;
        if (v == g) break;
        if (d[v] < p.first) continue;
        for (const auto& e : G[v]) {
            if (d[e.to] > d[v] + e.cost) {
                d[e.to] = d[v] + e.cost;
                pq.push(State(d[e.to], e.to));
            }
        }
    }
    return d[g];
}

int n;
int p[100000];
int a[100000]; // a[i] = end of the path from i
bool visited[100000];

int dfs(int i) {
    if (p[i] == 0) return a[i] = i;
    if (a[i] != -1) return a[i];
    if (visited[i]) return inf;
    visited[i] = true;
    return a[i] = dfs(i + p[i]);
}

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

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

    memset(a, -1, sizeof(a));
    rep(i, n) {
        if (a[i] == -1) {
            dfs(i);
        }
    }

    Graph G(n);
    rep(i, n) {
        rep2(j, 1, 6 + 1) {
            if (i + j >= n) {
                G[i].emplace_back(n - 1, 1);
            }
            else if (a[i + j] != inf) {
                G[i].emplace_back(a[i + j], 1);
            }
        }
    }

    cout << dijkstra(G, 0, n - 1) << endl;
}

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

using ll = long long;
using pii = pair<int, int>; using pll = pair<ll, ll>;

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

template<class T> istream& operator >> (istream& s, vector<T>& v)
{ for (T& x: v) { s >> x; } return s;}
template<class F, class S> istream& operator >> (istream& s, pair<F, S>& p)
{ s >> p.first >> p.second; return s;}

int main()
{
    int A, B, V, W, T; cin >> A >> V >> B >> W >> T;

    ll d = abs((ll)A-B);
    ll dv = (ll)V - W; 
    if (dv * T >= d) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
}


Measured memory_bytes: 3636
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    use std::cmp;

    input! {
        N: usize,
        K: usize,
        H: [i64; N],
    }

    let mut dp = vec![std::i64::MAX / 10; N];
    dp[0] = 0;

    for i in 0..N {
        for d in 1..K + 1 {
            let j = i + d;

            if j >= N { continue; }
            dp[j] = cmp::min(dp[j], dp[i] + (H[i] - H[j]).abs())
        }
    };

    println!("{}", dp[N - 1]);
}

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N,L;
double T[3030];
double X[3030],Y[3030];
double W[3030];
double D[3030][3030];
double DX,DY;

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>L;
	double pi=atan(1)*4;
	FOR(i,N) {
		cin>>x;
		T[i]=2*pi*x/L;
	}
	
	FOR(x,N) FOR(y,N) if(x!=y) {
		int num;
		double d;
		if(y>x) {
			num=N-(y-x+1);
			d=(T[x]+T[y])/2;
		}
		else {
			num=x-y-1;
			d=(T[x]+T[y])/2+pi;
		}
		DX+=cos(d)*num;
		DY+=sin(d)*num;
		
	}
	
	
	DX/=1LL*N*(N-1)*(N-2)/6;
	DY/=1LL*N*(N-1)*(N-2)/6;
	_P("%.12lf %.12lf\n",DX,DY);
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#define INF 0x3FFFFFFF

int main(void){
	int dp[1 << 16], i, j, k, l, n, t[16][17];
	while(1){
		scanf("%d",&n);
		if(!n) break;
		for(i = 0;i < n;i++)
			for(j = 0;j < n + 1;j++) scanf("%d",&t[i][j]);
		for(i = 0;i < 1 << n;i++) dp[i] = INF;
		dp[0] = 0;
		for(i = 0;i < (1 << n);i++){ // 何を持っているか
			if(dp[i] != INF){
				for(j = 0;j < n + 1;j++){ // 使う装備
					if(j == 0 || (i & (1 << (j - 1)))){
						for(k = 0;k < n;k++){ // 次に攻略するステージ
							if((~i & (1 << k)) && dp[i | (1 << k)] > dp[i] + t[k][j]){
								dp[i | (1 << k)] = dp[i] + t[k][j];
							}
						}
					}
				}
			}
		}
		printf("%d\n",dp[(1 << n) - 1]);
	}
	return 0;
}

Measured memory_bytes: 1284
A, B, C, D = map(int, input().split())

def gcd(a, b):
  if b == 0:
    return a
  return gcd(b, a%b)
 
def lcm(a, b):
  return a*b // gcd(a,b)
 
x = lcm(C, D)
 
print((B-A+1) - (B//C) + ((A-1)//C) - (B//D) + ((A-1)//D) + (B//x) - ((A-1)//x))

Measured memory_bytes: 3060
n = int(input())
a = list(map(int,input().split()))
wa={}
sa={}
i=1
for x in a:
    w=x+i
    s=i-x
    if w in wa:
        wa[w]+=1
    else:
        wa[w]=1
    if s in sa:
        sa[s]+=1
    else:
        sa[s]=1
    i+=1
ans=0
for k,v in wa.items():
    if k in sa:
        ans+=sa[k]*v
#print(wa)
#print(sa)
print(ans)

Measured memory_bytes: 56588
#include <iostream>
#include <vector>
using namespace std;
int main(){
    int N, M;
    while(cin >> N >> M && N > 0){
        vector<int> h(N);
        vector<int> w(M);
        for(int i = 0; i < N; i++)
		{
            cin >> h[i];
		}
        for(int i = 0; i < M; i++)
		{
            cin >> w[i];
		}
        int count = 0;
        int H,W;
        for(int i = 0; i < N; i++){
            for(int j = 0; j < M; j++){
                int p = i;
                int q = j;
                H = 0;
                W = 0;
                while(1){
                    if(H >= W){
                        W += w[q];
                        q++;
                        if(q > M) break;
                    }else{
                        H += h[p];
                        p++;
                        if(p > N) break;
                    }
    
                    if(H == W){
                        
                        count++;
                    }
                }
            }
        }
        cout << count << endl;
    }
}

Measured memory_bytes: 3080