akhauriyash/Code-Regression huggingface dataset:
n,k=map(int,input().split())
x=list(map(int,input().split()))

#連続するk本に火をつけるのが最適
ans=float("inf")
for i in range(n-k+1):
    if x[i] <= 0 and x[i+k-1] >= 0:
        ans = min(abs(x[i])+abs(x[i+k-1]) + min(abs(x[i]),abs(x[i+k-1])),ans)
    if x[i] >= 0 and x[i+k-1] >= 0:
        ans = min(x[i+k-1],ans)
    if x[i] <= 0 and x[i+k-1] <= 0:
        ans = min(abs(x[i]),ans)
print(ans)

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

using namespace std;
using ll = long long;

int main() {
    ios::sync_with_stdio(false); cin.tie(0);
    
    int N, K; cin >> N >> K;
    vector<ll> P(N+1), C(N+1);
    
    for (int i=1; i<=N; ++i) cin >> P[i];
    for (int i=1; i<=N; ++i) cin >> C[i];
    
    vector<ll> scores(N+1);
    ll maxscore = -1e18;
    
    for (int i=1; i<=N; ++i) {
        int cur = P[i];
        ll score = C[cur];
        int cnt = 1;
        scores[cnt] = score;
        while (cur != i && cnt < K) {
            cnt++;
            cur = P[cur];
            score += C[cur];
            scores[cnt] = max(scores[cnt-1], score);
        }
        if (cnt == K) {
            maxscore = max(scores[cnt], maxscore);
        } else {
            if (score > 0) {
                maxscore = max((K/cnt-1)*score + scores[cnt],max((K/cnt)*score + scores[K%cnt], maxscore));
            } else {
                maxscore = max(scores[cnt], maxscore);
            }
        }
    }
    
    cout << maxscore << endl;
}


Measured memory_bytes: 3780
import java.util.LinkedList;
import java.util.List;
import java.util.Scanner;


public class Main {

    static class Vertex {

        int num;

        List<Integer> edges = new LinkedList<>();

        public Vertex(int num) {

            this.num = num;
        }
    }

    static int N;

    static int K;

    static long result = 1;

    static long mod = 1000000007;
    static int[] leaf;

    static Vertex[] nodes;


    static boolean check[];

    public static void main(String[] args) {

        Scanner s = new Scanner(System.in);

        N = s.nextInt();

        K = s.nextInt();

        leaf = new int[N];

        nodes = new Vertex[N+1];

        check = new boolean[N+1];

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

            nodes[i]= new Vertex(i);
        }

        for (int i = 0; i < N-1; i++) {

            int v1 = s.nextInt();

            int v2 = s.nextInt();

            nodes[v1].edges.add(v2);

            nodes[v2].edges.add(v1);
        }



        System.out.println( (K *dfs(nodes[1],0)) %mod);

    }

    public static long dfs(Vertex v , int depth) {

        int num = Math.max(K-2, K-depth-1);

        long tot = 1;

        for (int k : v.edges) {

            if (check[k] == true) continue;
            tot *= num;

            tot %= mod;

            num--;


        }
        check[v.num] = true;

        for (int k : v.edges) {


            if (check[k] == true) continue;

            tot *= dfs(nodes[k], depth+1);

            tot %= mod;
        }

        return tot;

    }
}


Measured memory_bytes: 118024
#include <stdio.h>
int main(void){
    int x[9<<14];
    int i=0;
    int j=0;
    int min=9<<25;
    
    for(;~scanf("%d",x+i++););
    for(;j<x[0]-x[1]+1;j++)min=fmin(x[j+x[1]+1]-x[j+2]+fmin(abs(x[j+2]),abs(x[j+x[1]+1])),min);
    printf("%d",min);
}

Measured memory_bytes: 2528
#include<string>
#include<iostream>
using namespace std;
int main() {
    string s, t;
    cin >> s >> t;
    int i, len = s.length();
    while(i < len){
        if(s == t) {
            cout << "Yes";
            return 0;
        }
        s = s.substr(len - 1) + s.substr(0, len - 1);
        i++;
    }
    cout << "No";
    return 0;
}


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

#define int long long
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rep1(i,n) for(int i=1;i<=(int)(n);++i)
#define rep11(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define repm(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define pb(n) push_back(n)
#define mp make_pair
#define MOD 1000000007
#define INF LONG_LONG_MAX

int n,a,ans,now=1;

signed main() {
    cin >> n;
    rep(i,n) {
        cin >> a;
        if (a == now) now++;
        else ans++;
    }
    if (ans == n) cout << -1 << endl;
    else cout << ans << endl;
}


Measured memory_bytes: 384
def pk(x):
  x=int(x)
  return (x+1)//2 if x%2 else x//2+0.5
n,k = map(int,input().split())
l = list(map(pk,input().split()))
p = m=sum(l[:k])
for i in range(k,n):
  p=p-l[i-k]+l[i]
  m=max(p,m)
print(m)


Measured memory_bytes: 24292
//#pragma comment(linker, "/stack:200000000") //  (UNCOMMENT WHEN HAVING LOTS OF RECURSIONS)
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("unroll-loops")  // $ (UNCOMMENT WHEN TRYING TO BRUTEFORCE WITH A LOT OF LOOPS)\

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define endl "\n"
#define int long long
#define ll long long
#define pb push_back
#define all(c) (c).begin(), (c).end()
#define fi first
#define se second
#define vi vector<int>
#define vii vector< vector<int> >
#define vpi vector< pair<int,int> >
#define pair <int, int> pii

typedef tree< int, null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update>
    ordered_set;
// order_of_key (val): returns the no. of values less than val
// find_by_order (k): returns the iterator to kth largest element.(0-based)

#define TRACE
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr << name << " : " << arg1 << endl;}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<"  ";__f(comma+1, args...);}
#else
#define trace(...)
#endif

template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
	o<<"{";
	for(const T& v:vc) o<<v<<",";
	o<<"}";
	return o;
}

int modpow(int x, int n, int mod)
{
	x %= mod ;
	int res = 1;
	while(n > 0) {
		if(n & 1)
			res = res * x % mod ;
		x = x * x % mod ;
		n >>= 1 ;
	}
	return res;
}

const long long inf = 2e18 ;
const int mod = 1e9+7 ;
// const int mod = 998244353 ;
const int N = 1e5 + 10 ;

bool chk(int x)
{
	if( x>=1 && x<=9 )
		return true ; 
	return false ; 
}

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

	int n ; 
	cin >> n ; 

	for(int i=1 ; i*i<=n ; i++)
	{
		if(n%i==0)
		{
			if( chk(i) && chk(n/i) )
			{
				cout << "Yes" ; 
				return 0 ; 
			}

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


Measured memory_bytes: 256
#include<iostream>
#include<queue>
#include<vector>
#include<functional>
using namespace std;
typedef long long ll;
ll INF = 1e15;
struct Edge {
	ll from;
	ll to;
	ll cost;
};
using P = pair<ll, ll>;
vector<Edge>G[100005];
ll d[100005];
Edge es[200005];

int main() {
	int r;
	int V;
	int E;
	cin >> V >> E >> r;
	for (int i = 0; i < E; i++) {
		d[i] = INF;
	}
	for (int i = 0; i < E; i++) {
		cin >> es[i].from >> es[i].to >> es[i].cost;
	}
	d[r] = 0;
	bool update = true;
	int count = 0;
	while (update) {
		update = false;
		for (int i = 0; i < E; i++) {
			Edge e = es[i];
			if (d[e.from] != INF && d[e.to] > d[e.from] + e.cost) {
				d[e.to] = d[e.from] + e.cost;
				update = true;
			}
		}
		
		if (count == V) {
			cout << "NEGATIVE CYCLE" << endl;
			return 0;
		}
		if (!update)break;
		count++;
	}
	for (int i = 0; i < V; i++) {
		if (d[i] == INF) {
			cout << "INF" << endl;
		}
		else {
			cout << d[i] << endl;
		}
	}
	return 0;
}


Measured memory_bytes: 5476
#include<bits/stdc++.h>
#include<cctype>
using namespace std;
#define rep(i,n) for (int i=0;i<(n);i++)
#define all(v) (v).begin(),(v).end()
typedef long long int ll;
#define pi 3.1415926535897932384
#define E9 1000000000
#define eps 1e-4
#define pii pair<int,int>


int main(){
  int H1, M1, H2, M2, K; cin >> H1 >> M1 >> H2 >> M2 >> K;
  cout << (H2*60+M2) - (H1*60+M1) - K << endl;
  
  // cout << fixed << setprecision(6);
  return 0;
}


Measured memory_bytes: 3636
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
namespace AtCoder_Beginner_Contest_135
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }
        static void Main(string[] args)
        {
            SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            Solve();
            Out.Flush();
        }
        static void Solve()
        {
            var S = ReadLine();
            var Si = new long[S.Length];
            var xor10 = new long[S.Length];
            var mod = 13L;
            long Mod = 1000000000 + 7;
            //10^n%13
            xor10[0] = 1;
            for (var i = 1; i < S.Length; ++i)
            { xor10[i] = xor10[i - 1] * 10 % mod; }
            var numxor = 0L;//?が0のときのmod
            var cnt = 0L;
            for (var i = S.Length - 1; 0 <= i; --i) 
            {
                if ('?' != S[i])
                {
                    var n = long.Parse(S[i].ToString());
                    numxor += xor10[cnt] * n;
                    numxor %= mod;
                }
                ++cnt;
            }
            var dp = new long[S.Length + 1, mod];
            for (var i = 1; i <= S.Length; ++i)
            {
                if ('?' != S[i - 1])//?ではない場合そのまま遷移
                {
                    for (var k = 0; k < mod; ++k)
                    {
                        dp[i, k] = dp[i - 1, k];
                    }
                    continue;
                }
                var tmp = new long[mod];
                //i*10^n%modを計算。0は除く
                for (var j = 1; j < 10; ++j)
                {
                    var num = (xor10[S.Length - i] * j) % mod;
                    tmp[num]++;
                }
                //0じゃない場合遷移
                for (var j = 0; j < mod; ++j)
                {
                    //i=0の場合は前のをそのまま加える
                    dp[i, j] += dp[i - 1, j];
                    for (var k = 0; k < mod; ++k)
                    {
                        dp[i, (j + k) % mod] += dp[i - 1, j] * tmp[k];
                    }
                }
                //0から遷移する場合
                for (var j = 0; j < mod; ++j)
                {
                    dp[i, j] += tmp[j];
                    dp[i, j] %= Mod;
                }
            }
            dp[S.Length, 0]++;//全て0の場合;
            WriteLine(dp[S.Length, (5 - numxor + mod) % mod] % Mod);
        }
    }
}


Measured memory_bytes: 27228
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MAX_N = 1<<17;
ll n,dat[2*MAX_N-1];

void init(int n_){
  n=1;
  while(n<n_)n*=2;
  for(int i=0;i<2*n-1;i++)dat[i]=0;
}

void update(ll k,ll a){
  k+=n-1;
  dat[k]=a;
  while(k>0){
    k=(k-1)/2;
    dat[k]=max(dat[k*2+1],dat[k*2+2]);
  }
}

ll query(ll a,ll b,ll k,ll l,ll r){
  if(r<=a||b<=l)return 0;
  if(a<=l&&r<=b)return dat[k];
  else{
    ll v1=query(a,b,k*2+1,l,(l+r)/2);
    ll vr=query(a,b,k*2+2,(l+r)/2,r);
    return max(v1,vr);
  }
}

int main(){
  cin>>n;
  ll nn=n;
  ll ans=0;
  init(n);
  for(ll i=0,x;i<nn;i++){
    cin>>x;
    ll p=query(0,x,0,0,n);
    update(x-1,p+x);
    ans=max(ans,p+x);
  }
  cout<<nn*(nn+1)/2-ans<<endl;
  return 0;
}

Measured memory_bytes: 5112
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repi(i, s, n) for (int i = (s); i < (n); i++)
#ifdef LOCAL
#define INPUT_FILE                              \
  ifstream in("atcoder-problems/agc032_a.txt"); \
  cin.rdbuf(in.rdbuf());
#define print_vec(v)                        \
  rep(l, v.size()) { cout << v[l] << " "; } \
  cout << endl;
#else
#define INPUT_FILE
#define print_vec(v)
#endif
#define CIN_OPTIMIZE \
  cin.tie(0);        \
  ios::sync_with_stdio(false);
typedef pair<int, int> P;
typedef long long ll;
typedef pair<ll, ll> pl;
const int INF = 100100100;
const ll LINF = 1e18 + 100;
const int MOD = 1e9 + 7;

int main() {
  INPUT_FILE CIN_OPTIMIZE;

  int N;
  cin >> N;

  vector<int> c(N);
  rep(i, N) { cin >> c[i]; }

  vector<int> d(0);
  rep(i, N) {
    int max = -1;
    rep(j, c.size()) {
      if (c[j] == j + 1) {
        max = j;
      }
    }
    if (max == -1) {
      cout << -1 << endl;
      return 0;
    } else {
      d.push_back(c[max]);
      c.erase(c.begin() + max);
    }
  }

  reverse(d.begin(), d.end());
  rep(i, N) { cout << d[i] << endl; }
}

Measured memory_bytes: 3640
#include<stdio.h>
int main(void) {
  
  int i,j,k,a[3][3],n,b[10],bingo=0;
  
  for(i=0; i<3; i++) {
    for(j=0; j<3; j++) scanf("%d",&a[i][j]);
  }
  scanf("%d",&n);
  for(k=0; k<n; k++) scanf("%d",&b[k]);
  
  for(i=0; i<3; i++) {
    for(j=0; j<3; j++) {
      for(k=0; k<n; k++) if(a[i][j]==b[k]) a[i][j]=1000;
    }
  }
  for(i=0; i<3; i++) if(a[i][0]==a[i][1]&&a[i][1]==a[i][2]) bingo=1;
  for(j=0; j<3; j++) if(a[0][j]==a[1][j]&&a[1][j]==a[2][j]) bingo=1;
  if(a[0][0]==a[1][1]&&a[1][1]==a[2][2]) bingo=1;
  if(a[0][2]==a[1][1]&&a[1][1]==a[2][0]) bingo=1;
  
  if(bingo==1) printf("Yes");
  else         printf("No");
  
  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
main(){
  int n;
  string s;
  cin>>n;
  if(!n){cout<<0;return 0;}
  while(n){
    if(n%2){s="1"+s;n--;}
    else s="0"+s;
    n/=(-2);
  }
  cout<<s;
}

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

#define rep(i, a, n)  for(ll i=a; i<n; i++)
#define per(i, a, n)  for(ll i=n-1; i>=a; i--)
#define fill0(n)  setfill('0') << right << setw(n)
#define all(x)  (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define LONGMAX 1e18
#define INTMAX 1000000000
using namespace std;
typedef long long ll;
typedef pair<ll,ll> p;

ll n;
vector<ll> city(6,0);
vector<ll> way(5,0);

int main(){
  cin >> n;
  for(int i=0;i<5;i++){
    cin >> way[i];
  }
  ll Min = *min_element(all(way));
  ll ans = ceil(n*1.0/Min) + 4;
  cout << ans << endl;
}

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

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

typedef long long ll;
typedef pair<int, int> P;

const int MAX = 1e5 + 5;
const int INF = 1001001001;
const int MOD = 1e9 + 7;

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

    vector<bool> dp(max(106, X + 1));
    dp[100] = dp[101] = dp[102] = dp[103] = dp[104] = dp[105] = true;

    for (int i = 106; i <= X; ++i) {
        rep(j, 6) {
            dp[i] = dp[i] || dp[i - 100 - j];
        }
    }

    if (dp[X]) puts("1");
    else puts("0");
}

Measured memory_bytes: 256
# vim: fileencoding=utf-8


def main():
    s = input()
    li = [0] * 26
    for i in list(s):
        n = ord(i) - ord("a")
        li[n] = 1
    for i in range(26):
        if li[i] == 0:
            print(chr(i + ord("a")))
            return

    print("None")


if __name__ == "__main__":
    main()


Measured memory_bytes: 68572
import sys
N = int(input())
A  = list(map(int,input().split()))
S = int(1)
for iter in range(len(A)):
    if A[iter] == 0:
        print(0)
        sys.exit(0)

for iter in range(len(A)):
    S *= A[iter]
    if S > 10**18:
        print(-1)
        sys.exit(0)
print(S)


Measured memory_bytes: 21628
import java.io.*;

public class Main{
	public static void main(String[] args)throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int toki,zikan,hun,byou;
		
		toki = Integer.parseInt(br.readLine());
		zikan = toki / 3600;
		hun = (toki % 3600)/60;
		byou = (toki % 3600) % 60;
		
		System.out.println(zikan+":"+hun+":"+byou);
	}
}

Measured memory_bytes: 24356
from sys import stderr, setrecursionlimit
from functools import reduce
from operator import add
setrecursionlimit(2147483647)
def f(): return [int(i) for i in input().split()]
def yes(n): print("Yes" if n else "No")
def debug(*x, sep=" ", end="\n"):
    for item in x:
        stderr.write(str(item))
        stderr.write(sep)
    stderr.write(end)

n = int(input())
t, a = f()
h = [abs(t-i*0.006 - a) for i in f()]
print(h.index(min(h))+1)


Measured memory_bytes: 3700
#include<bits/stdc++.h>
using namespace         std;
#define                 int long long
#define                 pb push_back
#define                 mp make_pair
#define st(arr,a)       memset(arr,a,sizeof arr)
#define                 nl cout<<endl
#define                 real signed
#define                 endl '\n'              
#define countBit(x)     __builtin_popcountll(x)
const int mod = 1000000007ll;
#define all(x)          x.begin() , x.end()
#define pi pair<int,int>
#define X first
#define Y second
#define inf 1e16
#define Integer int
#define Double long double
#define String string
#define HashMap unordered_map
#define ArrayList vector
#define HashSet unordered_set
#define TreeSet ordered_set 
#define TreeMap ordered_map
#define Long int
#define containsKey count
#define Stack stack 
#define PriorityQueue priority_queue
#define Deque deque
#define addFirst push_front
#define addLast push_back
#define removeFirst pop_front
#define removeLast pop_back
#define Boolean bool
#define boolean bool
const int N=100;
int A[N][N],B[N][N];
bool dp[N][N][2*(2*N+2)*N+5];
int h=0,w=0;
void dfs(int i,int j,int s){
    if(i>=h||j>=w){
        return ;
    }
    int c=A[i][j]-B[i][j];
    if(i==h-1&&j==w-1){
        dp[i][j][s-c]=1;
        dp[i][j][s+c]=1;
        return ;
    }
    if(dp[i][j][s])return ;
    dfs(i+1,j,s+c);
    dfs(i+1,j,s-c);
    dfs(i,j+1,s+c);
    dfs(i,j+1,s-c);
    dp[i][j][s]=1;
}
signed main(){
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
        cin>>h>>w;
        for(int i=0;i<h;i++){
            for(int j=0;j<w;j++){
                cin>>A[i][j];
            }
        }
        for(int i=0;i<h;i++){
            for(int j=0;j<w;j++){
                cin>>B[i][j];
            }
        }
        int off=(2*N+2)*N;
        int ans=inf;
        for(int i=0;i<h;i++){
            for(int j=0;j<w;j++){
                for(int k=0;k<=2*off+2;k++){
                    dp[i][j][k]=0;
                }
            }
        }
        dfs(0,0,off);
        for(int k=0;k<=2*off+2;k++){
            if(dp[h-1][w-1][k]){       
                int cur=0;
                if(k>=off)cur=k-off;
                else cur=off-k;
                ans=min(ans,cur);
            }
        }
        cout<<ans;
        return 0;
}

//       g++ -g main.cpp ; ./a.exe

Measured memory_bytes: 315776
long M=1e9+7,m[1<<18],h,w,a,s;
long p(a,b)long a,b;{return b?b%2?p(a*a%M,b/2)*a%M:p(a*a%M,b/2):1;}
main(i)
{
	for(*m=1;i<1<<18;i++)m[i]=m[i-1]*i%M;
	for(scanf("%d%d%d%d",&h,&w,&a,&i);i<w;i++)s=(s+m[h-a-1+i]*p(m[h-a-1],M-2)%M*p(m[i],M-2)%M*m[a+w-i-2]%M*p(m[a-1],M-2)%M*p(m[w-i-1],M-2)%M)%M;
	printf("%d",s);
}

Measured memory_bytes: 2176
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
int main(){
 int n,i;
 int max=0;
 int X[101],Y[101],D[101];
 double Da=0,Db=0,Dc=0,Dd=0;
 
 scanf("%d",&n);
 
 for(i=1;i<n;i++){
  scanf("%d ",&X[i]);
 }
  scanf("%d",&X[n]);

 for(i=1;i<n;i++){
  scanf("%d ",&Y[i]);
 }
  scanf("%d",&Y[n]);
 
 for(i=1;i<=n;i++){
  D[i]=abs(X[i]-Y[i]);
  Da+=D[i];
  if(D[i]>max){
   max=D[i];
  }
 }
 for(i=1;i<=n;i++){
  Db+=pow(D[i],2);
 }
  Db=sqrt(Db);
 
 for(i=1;i<=n;i++){
  Dc+=pow(D[i],3);
 }
  Dc=pow(Dc,1.0/3.0);
 
  Dd=max;
 
 printf("%lf\n%lf\n%lf\n%lf\n",Da,Db,Dc,Dd);
 
return 0;
}


Measured memory_bytes: 2112
a = gets.split(" ")
$n = a[0].to_i
$k = a[1].to_i

$f = [1]
$prefix_f = [1]

$l = []
$r = []

$k.times do 
  a = gets.split(" ")
  ll = a[0].to_i
  rr = a[1].to_i
  $l.push(ll)
  $r.push(rr)
end

def sum_from(ll, rr) 
  if rr < 0
    0
  else
    ret = $prefix_f[rr]
    if ll > 0 
      ret -= $prefix_f[ll - 1]
    end
    ret
  end
end 

$mod = 998244353

$n.times do |i|
  ff = 0
  $k.times do |j|
    ff = (ff + sum_from(i + 1 - $r[j], i + 1 - $l[j])) % $mod
  end
  # byebug
  $f.push(ff)
  # p ff
  $prefix_f.push($prefix_f[i] + ff)
end

# p $f[4]
puts $f[$n - 1]

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

int main()
{
    int n;
    cin >> n;
    if (n%1000 == 0) cout << 0 << endl;
    else cout << 1000 - n%1000 << endl;
    return 0;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(a); i<(b); i++)
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define sort(v,n) sort(v,v+n);
#define vsort(v) sort(v.begin(),v.end());
#define vvsort(v) sort(v.begin(),v.end(),greater<int>());
#define ll long long
#define pb(a) push_back(a)
#define fi first
#define se second
#define inf 999999999
using namespace std;
typedef pair<int,int> p;
typedef pair<ll,ll> lp;
typedef priority_queue<int> pq;
typedef priority_queue<int,vector<int>,greater<int> > rpq;
bool is_uruu(int y) {
        return y % 4 == 0 && (y % 100 != 0 || y % 400 == 0);
}
const ll MOD=1e9+7;
const double PI=acos(-1.0);
//----------------------------------------------------------------------------------------------------------------------------------//
int n;
ll sum=0;
ll a[100001];
int main(){
        cin>>n;
        rep(i,0,n){
                cin>>a[i];
                sum+=a[i];
        }
        if(sum%((1LL+n)*n/2)!=0) {
                cout<<"NO"<<endl;
                return 0;
        }
        ll k=2LL*sum/((1LL+n)*n);
        ll k2=0;
        rep(i,0,n){
                if((a[(i+1)%n]-a[i]-k)%n!=0 || (a[(i+1)%n]-a[i]-k)>0) {
                        cout<<"NO"<<endl;
                        return 0;
                }
                if((a[(i+1)%n]-a[i]-k)!=0) {
                        k2+=(-1)*(a[(i+1)%n]-a[i]-k)/n;
                }
        }
        if(k2==k) {
                cout<<"YES"<<endl;
                return 0;
        }
        cout<<"NO"<<endl;
}


Measured memory_bytes: 1152
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;
const ld eps=1e-9;

//// < "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\a.txt" > "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\b.answer"
int main() {
	for (int i = 0; i < 3; ++i) {
		int a, b;
		{

			int h, m, s; cin >> h >> m >> s;
			a = h * 3600 + m * 60 + s;
		}
		{

			int h, m, s; cin >> h >> m >> s;
			b = h * 3600 + m * 60 + s;
		}
		int c = b - a;
		int h = c / 3600;
		int m = (c%3600)/60;
		int s = c % 60;
		cout << h << " " << m << " " << s << endl;
	}
	return 0;
}

Measured memory_bytes: 2984
#include "bits/stdc++.h"
using namespace std;

int main(){
  unordered_map<long long, int> pows;
  int x;
  for (int i = 0; i <= 4000; ++i) {
    pows[(long long)i * i * i * i * i] = i;
  }
  cin >> x;
  for (const auto& [k, v]: pows) {
    if (pows.count(k - x)) {
      cout << v << ' ' << pows[k-x] << endl;
      break;
    } else if (pows.count(x - k)) {
      cout << v << ' ' << -pows[x-k] << endl;
      break;
    }
  }
  return 0;
}

Measured memory_bytes: 3760
#include <bits/stdc++.h>
using namespace std;
//型に気を付けよう

#define rep(i,n) for(int i=0;i<n;i++)
typedef long long  ll;
const double pi=3.1415926535;
const ll  mod=1000000007;
//桁数指定　cout << fixed << setprecision(2)
int main() {
  ll n;
  cin>>n;
  ll cnt=0;
  ll ans=0;
  while(1){
    cnt++;
    n/=2;
    if(!n){break;}
  }
  ans=pow(2,cnt)-1;
  cout<<ans;
}

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

namespace CSharp
{
    class Program
    {
        public static void Main()
        {
            var N = int.Parse(Console.ReadLine());
            var A = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
            var B = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();

            var result = 0L;
            for (int i = 0; i < N; i++)
            {
                if (B[i] > A[i])
                {
                    B[i] -= A[i];
                    result += A[i];
                    A[i] = 0;
                }
                else
                {
                    A[i] -= B[i];
                    result += B[i];
                    B[i] = 0;
                }

                if (B[i] > A[i + 1])
                {
                    B[i] -= A[i + 1];
                    result += A[i + 1];
                    A[i + 1] = 0;
                }
                else
                {
                    A[i + 1] -= B[i];
                    result += B[i];
                    B[i] = 0;
                }
            }
            Console.WriteLine(result);
        }
    }
}


Measured memory_bytes: 37728
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <iomanip>
#include <queue>
#include <deque>
#include <map>
#include <unordered_map>
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define repr(e,x) for(auto& e:x)
using namespace std;
typedef long long ll;
typedef long double ld;
ll const MOD=1000000007;

ll N;
ll A[100000];
ll B[100000];
ll cnt[100001];

int main(){
    cin>>N;
    rep(i,N) cin>>A[i]>>B[i];

    for(int i=N-1;i>=0;i--){
        cnt[i]=cnt[i+1];
        cnt[i]+=(B[i]-(A[i]+cnt[i])%B[i])%B[i];
    }

    ll ans=cnt[0];
    cout<<ans<<endl;
}

Measured memory_bytes: 5968
#include<iostream>
#include<stdio.h>
//#include <bits/stdc++.h>
#include<vector>
#include<float.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cstring>
#include<math.h>
#include<cmath>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include<cassert>
#include<cmath>
#include<cstdint>


     
#define INF 1e9
#define LINF 1e19
#define rep(i,n)for(int i=0;(i)<(int)(n);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
#define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define vec(type,n) vector<type>(n)
#define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
#define ALL(a)  (a).begin(),(a).end()
#define chmin(a, b) a = min(a, b)
#define chmax(a, b) a = max(a, b)
#define pb push_back
#define sz size()
     
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<ll, ll>;

     
const ll MOD = 1e9 + 7;
const ll ZER = 0;

ll f(ll n){
    ll sum = 0;
    for(ll i = 1; i <= n; i *= 2){
        //i桁目の1の個数
        ll now = n / (2 * i) * i + max(ZER, n % (i * 2) - i);
        now %= 2;
        sum += now * i;
        //cout << now << " " << i << endl;
    }
    return sum;
}

int main(){
    string s;
    ll k;
    cin >> s >> k;
    vector<ll> a(s.sz);
    rep(i, s.sz){
        a[i] = 'z' - s[i] + 1;
        a[i] %= 26;
    }
    rep(i, s.sz){
        if(a[i] <= k){
            k -= a[i];
            s[i] = 'a';
        }
    }
    k %= 26;
    s[s.sz - 1] = (char)('a' + ((s[s.sz - 1] - 'a') + k) % 26);
    cout << s << endl;
}





Measured memory_bytes: 4316
#include<iostream>
using namespace std;
 
int main (void)
{
  int N, K, temp, count=0;
  cin>>N>>K;
  for(int i=0;i<N;i++)
  {
    cin>>temp;
    if(temp>=K)
      count++;
  }
  cout<<count;
  return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
//#pragma GCC target("avx")
#include <bits/stdc++.h>
using namespace std;
class FastIO
{
    static const int rdata_sz = (1 << 22), wdata_sz = (1 << 22);
    char rdata[rdata_sz], wdata[wdata_sz], *rb, *wb;
    char tmp_s[10];

public:
    FastIO()
    {
        fread(rdata, 1, rdata_sz, stdin);
        rb = rdata;
        wb = wdata;
    }
    ~FastIO()
    {
        fwrite(wdata, 1, wb - wdata, stdout);
    }

    template <typename T>
    inline void read(T &x)
    {
        bool neg = false;
        x = 0;
        while ((*rb < '0' || *rb > '9') && *rb != '-')
            ++rb;
        while ('0' <= *rb && *rb <= '9')
        {
            x = 10 * x + (*rb - '0');
            ++rb;
        }
        if (neg)
            x = -x;
    }

#define pc(x) *(wb++) = x
    template <typename T>
    inline void write(T x)
    {
        if (x == 0)
        {
            pc('0');
            pc(' ');
            return;
        }
        char *t = tmp_s;
        while (x)
        {
            T y = x / 10;
            *(t++) = (x - y * 10) + '0';
            x = y;
        }
        while (t != tmp_s)
            pc(*(--t));
        pc(' ');
    }
#undef pc
};
int par[500001];
int ran[500001];
//要素xが所属する木の根を再帰的に発見する
inline int root(int x)
{
    if (par[x] == x)
        return x;
    return par[x] = root(par[x]); //経路圧縮
}
//要素xが属する木と要素yが属する木の併合
inline void unite(int x, int y)
{
    int rx = root(x);
    int ry = root(y);
    if (rx == ry)
        return; //同じ木に属してたらそのまま
    if (ran[rx] < ran[ry])
    {
        par[rx] = ry; //根がryの木に併合
    }
    else
    {
        par[ry] = rx; //根がrxの木に併合
        if (ran[rx] == ran[ry])
            ran[rx]++;
    }
}
//要素xが属する木と要素yが属する木が同じならtrueを返す
inline bool same(int x, int y)
{
    return root(x) == root(y);
}
int main()
{
    FastIO io;
    register int N, Q;
    io.read(N);
    io.read(Q);
    for (register int i = 0; i < N; i++)
    {
        par[i] = i;
        ran[i] = 0;
    }
    for (register int i = 0; i < Q; i++)
    {
        register int a, b, c;
        io.read(a);
        io.read(b);
        io.read(c);
        if (a == 1)
            if (same(b, c))
                io.write(1);
            else
                io.write(0);
        if (a == 0)
            unite(b, c);
    }
    return 0;
}

Measured memory_bytes: 7212
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
using System.Numerics;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            Solve();
            //Out.Flush();
            Read();
        }

        static void Solve()
        {
            WriteLine(24 + 24 - Sarray()[0]);
        }

        static long Mod = (long)1e9 + 7;
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }
        static public (T1 a, T2 b) Slice<T1, T2>()
        {
            var t = ReadLine().Split();
            return (
            (T1)Convert.ChangeType(t[0], typeof(T1)),
            (T2)Convert.ChangeType(t[1], typeof(T2)));
        }
        static public (T a, T b) Slice2<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)));
        }
        static public (T a, T b, T c) Slice3<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)),
            (T)Convert.ChangeType(t[2], typeof(T)));
        }
    }
}

Measured memory_bytes: 28120
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN = 2e5 + 5;
const int MOD = 1e9 + 7;

int n, m, a, b, fa[MAXN], sz[MAXN], ans;

inline int find(int x) { return fa[x] == x ? x : fa[x] = find(fa[x]); }

inline void unionn(int a, int b) {
    int r1 = find(a), r2 = find(b);
    if (r1 != r2) fa[r1] = r2, sz[r2] += sz[r1];
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> m;
    for (int i = 1; i <= n; i++) fa[i] = i, sz[i] = 1;
    for (int j = 1; j <= m; j++) cin >> a >> b, unionn(a, b);
    for (int i = 1; i <= n; i++)
        if (fa[i] == i) ans = max(ans, sz[i]);
    cout << ans;
    return 0;
}


Measured memory_bytes: 5168
#include <bits/stdc++.h>
#pragma GCC optimize("O3")

#define fi first
#define se second
#define em emplace
#define eb emplace_back
#define mp make_pair
#define pi pair<int,int>
#define vi vector<int>
#define vpi vector<pair<int,int>>
#define vll vector<ll>
#define vpll vector<pair<ll,ll>>
#define endl '\n'

#define si(v) int(v.size())
#define all(v) v.begin(), v.end()
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rep2(i, n, m) for (ll i = n; i <= (m); ++i)
#define rep3(i, n, m) for (ll i = n; i >= (m); --i)

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

using ll = long long;
using ld = long double;
using namespace std;

constexpr ll MOD = 1000000007, MAX = 55555;

vi prime() 
{
  vi ret;

  rep2(i, 3, MAX) {
    bool ok = true;
    rep2(j, 2, sqrt(i)) {
      if (i % j == 0) {
        ok = false;
        break;
      }
    }

    if (ok && i % 10 == 1) ret.eb(i);
  }
  return ret;
}

signed main()
{
  cout << fixed << setprecision(20);
  ios::sync_with_stdio(false);
  cin.tie(0);
  
  int n; cin >> n;
  auto v = prime();

  rep(i, n) {
    if (i) cout << " ";
    cout << v[i];
  }
  cout << endl;
  
  return (0);
}

Measured memory_bytes: 3616
#include<bits/stdc++.h>
#define maxn 100005
using namespace std;
typedef long long LL;
int read()
{
    char c=getchar();int f=1,sum=0;
    while(c<'0' || c>'9'){if(c=='-')f=-1;c=getchar();}
    while(c>='0' && c<='9'){sum=sum*10+c-'0';c=getchar();}
    return sum*f;
}
char s[maxn];
int a[maxn];
void add(int u,int v)
{
	printf("%d %d\n",u,v);
}
int main()
{
	scanf("%s",s+1);
	int n=strlen(s+1);
	s[0]='0';
	if(s[1]!='1') return puts("-1"),0;
	for(int i=0;i<=n;i++)
	{
		if(s[i]!=s[n-i]) return puts("-1"),0;
		a[i]=s[i]-'0';
	}
	int now=1,cnt=1;
	for(int i=1;i<n;i++)
	{
		if(!a[i]) add(now,++cnt);
		else add(now,++cnt),now=cnt;
	}
	return 0;
}


Measured memory_bytes: 1920
#include<stdio.h>
#include<stdlib.h>

struct Tree{
  int parent;
  int left;
  int right;
};

struct Tree T[100000];
int D[100000];
int a=0;

void rec(int u,int p){
  D[u]=p;
  if(T[u].right!=-1) rec(T[u].right,p);
  if(T[u].left!=-1) rec(T[u].left,p+1);
}

int main(){
  int n,i,j,d,v,c,l=0,r=0,max=0;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    T[i].parent=-1;
    T[i].left=-1;
    T[i].right=-1;
  }
  for(i=0;i<n;i++){
    scanf("%d",&v);
    scanf("%d",&d);
    if(d>max)max=d;
    for(j=0;j<d;j++){
      scanf("%d",&c);
      if(j==0) T[v].left=c;
      else T[l].right=c;
      l=c;
      T[c].parent=v;
    }
  }
  for(i=0;i<n;i++){
    if(T[i].parent==-1)r=i;
  }
  
  rec(r,0);
  
  for(i=0;i<n;i++){
    printf("node %d: parent = %d, depth = %d, ",i,T[i].parent,D[i]);
    if(T[i].parent==-1){
      printf("root, ");
    }
    else if(T[i].left==-1){
      printf("leaf, ");
    }
    else printf("internal node, ");
    
    printf("[");
    for(j=0,c=T[i].left;c!=-1;j++,c=T[c].right){
      if(j>0)printf(", ");
      printf("%d",c);
    }
    printf("]\n");
  }
  
  return 0;
  
}
  



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

int main() {
  int N, M, K;
  cin >> N >> M >> K;
  vector<long> A(++N), B(++M);
  for (int i = 1, a; i < N && cin >> a; i++) A.at(i) = A.at(i - 1) + a;
  for (int i = 1, b; cin >> b; i++) B.at(i) = B.at(i - 1) + b;
  int ans = 0;
  for (int i = 0; i < N; i++) {
    if (A.at(i) > K) break;
    int b = upper_bound(B.begin(), B.end(), K - A.at(i)) - B.begin();
    ans = max(ans, i + b - 1);
  }
  cout << ans << "\n";
}

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

int main() {
	ios_base::sync_with_stdio(0);cin.tie(0);
	string n;
	cin>>n;
	string t=n;
	reverse(t.begin(),t.end());
	cout<<(n==t?"Yes\n":"No\n");
}




Measured memory_bytes: 3604
// by newbiechd
#include <algorithm>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>

// DELETE the debugging information!
#define debug(x) std::cerr << #x << " = " << (x) << std::endl

const int N_MAX = 100003;
int a[N_MAX];

int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i)
    scanf("%d", a + i);
  std::sort(a + 1, a + n + 1, std::greater<int>());
  
  for (int i = 1; i <= n; ++i)
    if (i >= a[i + 1]) {
      bool ans = 0;
      for (int j = i + 1; a[j] == i; ++j)
        ans ^= 1;
      ans |= ((a[i] - i + 1) & 1) == 0;
      printf(ans ? "First\n" : "Second\n");
      break;
    }
  return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <string>
#include <algorithm>
#include <cmath>
using namespace std;
#define dump(a) cout << (a) << endl;
typedef long long ll;

int main() {
    int n, h;
    cin >>  n >> h;
    vector<ll> a(n), b(n);
    ll ma = -1;
    for( int i = 0; i < n; i++ ) {
        cin >> a[i] >> b[i];
        ma = max( a[i], ma );
    }
    int cnt = 0;
    sort( b.begin(), b.end());
    for( int i = n-1; i >= 0; i-- ) {
        if( b[i] > ma ) {
            h -= b[i];
            cnt++;
            if( h <= 0 ) {
                dump( cnt );
                return 0;
            }
        }
    }
    cnt += h/ma;
    if( h%ma != 0 ) cnt++;
    dump( cnt );
    return 0;  
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)

// Bit Matrix
const int MAX_ROW = 100010; // to be set appropriately
const int MAX_COL = 63; // to be set appropriately
struct BitMatrix {
    int H, W;
    bitset<MAX_COL> val[MAX_ROW];
    BitMatrix(int m = 1, int n = 1) : H(m), W(n) {}
    inline bitset<MAX_COL>& operator [] (int i) {return val[i];}
};

int GaussJordan(BitMatrix &A, bool is_extended = false) {
    int rank = 0;
    for (int col = 0; col < A.W; ++col) {
        if (is_extended && col == A.W - 1) break;
        int pivot = -1;
        for (int row = rank; row < A.H; ++row) {
            if (A[row][col]) {
                pivot = row;
                break;
            }
        }
        if (pivot == -1) continue;
        swap(A[pivot], A[rank]);
        for (int row = 0; row < A.H; ++row) {
            if (row != rank && A[row][col]) A[row] ^= A[rank];
        }
        ++rank;
    }
    return rank;
}

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

  int n;
  cin >> n;
  int MD = 63;
  BitMatrix B(n,MD);
  vector<ll> a(n);
  rep(i,n) cin >> a[i];
  set<int> use;
  ll ans = 0;
  rep(i,MD){
    ll v = 0;
    rep(j,n){
      v = v ^ ((a[j] & (1LL<<i)) > 0);
    }
    if(v==1) {
      ans += 1LL<<i;
      use.insert(i);
      // cout << i << endl;
    }
  }
  rep(i,MD){
    if(use.count(i)) continue;
    rep(j,n){
      if(a[j]&(1LL<<i)){
      // cout << i  << " " << j << endl;
        B[j][MD-1-i] = 1;
      }
      else B[j][MD-1-i] = 0;
    }
  }
  GaussJordan(B,false);
  rep(i,MD){   
    int cnt = 0;
    rep(j,n){
      if(B[j][MD-1-i]) cnt++;
    }
    if(cnt&1) {
      ans += 1LL<<(i+1);
      // cout << ans << endl;
    }
  }
  cout << ans << endl;
  return 0;
    

}


Measured memory_bytes: 1792
#include <iostream>

int main(){
    int a, b, c, d;
    std::cin >> a >> b >> c >> d;
    while(1){
        c -= b;
        if(c <= 0){
            std::cout << "Yes" << std::endl;
            break;
        }
        a -= d;
        if(a <= 0){
            std::cout << "No" << std::endl;
            break;
        }
    }
}


Measured memory_bytes: 3676
#include<stdio.h>
int main(){

  int n,q,i,j,count=0;
  int S[1000000];
  int T[1000000];
  int mid,left,right,key;
  
   scanf("%d",&n);
  for(i=0; i<n; i++)
    scanf("%d",&S[i]);

  scanf("%d",&q);
  for(i=0; i<q; i++)
    scanf("%d",&T[i]);

  for(j=0; j<q; j++){
    key = T[j];
    left = 0;
    right = n;
    
    while(left < right){
      mid = (left + right)/2;
      if(key == S[mid]){
	count++;
	break;
      }
      if(key > S[mid]){
	left = mid+1;
      }
      else if(key < S[mid]){
	right = mid;
      }
    }
  }

  printf("%d\n",count);
  return 0;
}



Measured memory_bytes: 2280
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		new Main().run();
	}

	private void run() {
		Scanner scanner = new Scanner(System.in);
		while (true) {
			max = scanner.nextInt();
			if (max == 0)
				break;
			n = scanner.nextInt();
			map = new int[n + 2];
			for (int i = 1; i <= n; i++)
				map[i] = scanner.nextInt();
			n += 2;
			boolean[] vis = new boolean[n];
			vis[0] = true;
			dfs(0, vis);
			if (!vis[n - 1]) {
				System.out.println("NG");
				continue;
			}
			boolean flag = true;
			for (int s = 1; s < n - 1; s++) {
				if (!vis[s])
					continue;
				boolean[] vis2 = new boolean[n];
				vis2[s] = true;
				dfs(s, vis2);
				if (!vis2[n - 1]) {
					flag = false;
					break;
				}
			}
			System.out.println(flag ? "OK" : "NG");

		}
	}

	private void dfs(int s, boolean[] vis) {
		Deque<Integer> deque = new ArrayDeque<Integer>();
		deque.push(s);
		while (!deque.isEmpty()) {
			int x = deque.poll();
			for (int i = 1; i <= max; i++) {
				int nx = Math.min(x + i, n - 1);
				nx = Math.max(Math.min(nx + map[nx], n - 1), 0);
				if (!vis[nx]) {
					vis[nx] = true;
					deque.push(nx);
				}
			}
		}
	}

	int max, n;
	int[] map;
}

Measured memory_bytes: 62068
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <queue>

using namespace std;

void Diverta2019_B()
{
	int N;
	vector<int> ball(3);
	cin >> ball[0] >> ball[1] >> ball[2] >> N;
	sort(ball.begin(), ball.end(), greater<int>());

	int ct = 0;
	int m = N / ball[0];
	for (int i = 0; i <= m; ++i)
	{
		int r1 = N - ball[0] * i;
		
		int el = r1 / ball[1];
		for (int j = 0; j <= el; ++j)
		{
			int r2 = r1 - ball[1] * j;
			if (r2 % ball[2] == 0)
				++ct;
		}
	}
	cout << ct << endl;
}

int main()
{
	Diverta2019_B();
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
typedef long double ld;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define mod 1000000007
#define inf 1000000000000000
#define autoit(x,it) for(auto it = x.begin(); it != x.end(); it++)
#define rep(n) for(ll i = 0; i < n; i++)
#define repi(i,n) for(ll i = 0; i < n; i++)

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 

#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 

using namespace std;


int main()
{
   FAST/**/
   
   ll h;
   cin>>h;
   
   ll cnt = 0;
   ll temp = h;
   while(temp>0)
   {
       temp>>=1;
       cnt++;
   }
   
   cout<<((1ll<<(cnt))-1);
   
   return 0;        
}  
   

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
        long long int i,j,g=0,m=1000,ans,s=0,k,n,r,a[100000],b[100000];
        cin>>n;
        j=n%m;
        if(j==0)
        cout<<0<<endl;
        else
            {
                i=m-j;
            cout<<i<<endl;
            }

    return 0;
}



Measured memory_bytes: 3592
#include <iostream>
#include <string>
#include <cstring>
#include <iostream>
#include <string>
#include <cstring>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <utility>
#define int long long
using namespace std;
signed main(){
    int n,m;
    cin>>n>>m;
    vector<pair<int,int> > a(n);
    for(int i=0;i<n;i++)cin>>a[i].first>>a[i].second;
    sort(a.begin(),a.end());
    int price=0;
    int count=0;
    int c=0;
    while(1){
        price+=a[count].first*a[count].second;
        c+=a[count].second;
        if(c>=m){
            price-=(c-m)*a[count].first;
            break;
        }
        count++;
    }
    cout<<price<<endl;
    return 0;
}


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

int main(){
    int n, a, sum=0;
    cin >> n >> a;
    sum = n- (n/500) * 500 - a;
    if(sum<=0) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#include<bits/stdc++.h>
using namespace std;

/// Info.
///****************************************************************************************************************************************///
/// author                : BAHAA El-DEEN OSAMA .
/// Problem name          : E - An Odd Problem
/// Method                : brute force
/// Online judge          : vjudge(Contest)
/// Date                  : 8/6/2020
///****************************************************************************************************************************************///

long long val,n,cnt=0;

int main()
{

    cin>>n;
    for(int i=0 ;i<n;++i)
    {
         cin>>val;
         if( (val&1) && ((i+1)&1) )
         {
             ++cnt;
         }
    }
    cout <<cnt<<endl;



return 0;
}


Measured memory_bytes: 3556
lst = [1]*50021
for i in range(50021):
    if i == 0:
        lst[i] = 0
    else:
        if lst[i] == 1:
            j = i +1
            k = i
            while True:
                k = k + j
                if k >= 50021:
                    break
                        
                lst[k] = 0

while True:
    try:
        n = int(input())
        a = lst[0:n-1]
        b = lst[n:]
        print((n - 1 - a[::-1].index(1)),(n + 1 + b.index(1)))

    except EOFError:
        break


Measured memory_bytes: 7040
#include <stdio.h>
int main(void){
    // Your code here!
    int N,i,ans = 0,MAX=0,m=0;
    scanf("%d",&N);
    int P[N];
    for ( i= 0; i < N; i++){
        scanf("%d",&P[i]);
    }
    
    for(i = 0; i < N; i++){
        if(P[i]>=MAX){
            MAX = P[i];
            m = i;
        }
    }
    for(i = 0; i < N; i++){
        if (i == m){
            ans = ans + P[i]/2;
        }else{
            ans = ans + P[i];
        }
    }
    printf("%d",ans);
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <string>
#include <cmath>
using namespace std;
#define MOD 1000000007
#define INF 1<<30
#define LINF (ll)1<<62
#define MAX 510000
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(),(x).end()
#define uni(q) unique(all(q)),q.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> P;
typedef vector<pair<ll, ll>> vpl;

vl divisor(ll k){
    vl c;
    for(ll i=1; i*i<=k; i++){
        if(k % i == 0){
            c.push_back(i);
            if((k / i) != i){
                c.push_back(k/i);
            }
        }
    }
    sort(c.rbegin(), c.rend());
    return c;
}

ll getDigit(ll x){
    ll a = 0;
    while(x > 0){
        x /= 10;
        a++;
    }
    return a;
}

int main(){
    ll n; cin >> n;
    ll mn = INF;
    vl div = divisor(n);
    for(auto i : div){
        mn = min(mn, max(getDigit(i), getDigit(n/i)));
    }
    cout << mn << endl;
}


Measured memory_bytes: 256
n, m = map(int, input().split())
AB = []
for _ in range(m):
    a, b = map(int, input().split())
    AB.append((a, b))
C = [10**6] * n
for a, b in AB:
    C[a-1] = min(C[a-1], b-1)

count = 0
for i in range(n-1):
    if C[i] == i+1:
        count += 1
    else:
        C[i+1] = min(C[i+1], C[i])
print(count)


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

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define ll long long
const ll mod = 1e9+7;
int inf = 1000000000; //10e9

int main(){

    int n, x;
    cin >> n >> x;
    
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    sort(a.begin(),a.end());

    int ans = 0, total = x;
    rep(i,n){
        if(a[i]<=total){
            ans++;
            total -= a[i];
        }else{
            break;
        }
    }
    if(ans == n && total != 0){
        ans = n-1;
    }


    cout << ans << endl;

    return 0;

}

Measured memory_bytes: 3620
from math import factorial

N, M = map(int, input().split())

def comb2(n):
    if n > 1:
        return factorial(n) // factorial(2) // factorial(n - 2)
    else:
        return 0
    
s = 0    
for i in [N, M]:
    s += comb2(i)

print(s)


Measured memory_bytes: 2940