akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <string>

using namespace std;

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

	int ans = 0;
	int c = 0; int l = 0;
	for (int r = 0; r < n; r++) {
		if (s[r] == '0') {
			// 2: 区間の数を数える
			if (r == 0 || s[r - 1] == '1') c++;
		}
		if (c > k) {
			// 3: 区間数が k を超えたところで "111...111000...000" を
			//    先頭から 1 ペアずつ取り除く (取り除いた数は l になる)
			while (s[l] == '1') l++;
			while (s[l] == '0') l++;

			c--;
		}

		// 1 : 制限に突き当たるまで貪欲にとる (まずは l は無視)
		// 4 : l があれば l 分だけ引く
		ans = max(ans, r - l + 1);
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define nmax 100001
#define INF 1e9
using namespace std;

int arr[nmax],n,k;
long long dp[nmax];

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

    cin>>n>>k;
    for(int i=1;i<=n;i++){
        cin>>arr[i];
        dp[i]=INF;
    }
    dp[1]=0;
    for(int i=2;i<=n;i++){
        for(int j=1;j<=k && i>j;j++){
            if((abs(arr[i]-arr[i-j]) + dp[i-j]) < dp[i]) dp[i]=abs(arr[i]-arr[i-j]) + dp[i-j];
        }
    }
    cout<<dp[n];
}


Measured memory_bytes: 1408
#include<bits/stdc++.h>
//ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<pll,ll> ppll;
typedef pair<ll,pll> plpl;
typedef tuple<ll,ll,ll> tl;
ll mod=1000000007;
ll mod2=998244353;
ll mod3=1000003;
ll mod4=998244853;
ll inf=1000000000000000000;
double pi=acos(-1.0);
#define rep(i,m,n) for(ll i=m;i<n;i++)
#define rrep(i,n,m) for(ll i=n;i>=m;i--)
int dh[4]={1,-1,0,0};
int dw[4]={0,0,1,-1};
int ddh[8]={-1,-1,-1,0,0,1,1,1};
int ddw[8]={-1,0,1,-1,1,-1,0,1};
ll lmax(ll a,ll b){
    if(a<b)return b;
    else return a;
}
ll lmin(ll a,ll b){
    if(a<b)return a;
    else return b;
}
ll gcd(ll a,ll b){
    if(a<b)swap(a,b);
    if(b==0)return a;
    if(a%b==0)return b;
    return gcd(b,a%b);
}
ll Pow(ll n,ll k){
    ll ret=1;
    ll now=n;
    while(k>0){
        if(k&1)ret*=now;
        now*=now;
        k/=2;
    }
    return ret;
}
ll beki(ll n,ll k,ll md){
  ll ret=1;
  ll now=n;
  while(k>0){
    if(k%2==1){
      ret*=now;
      ret%=md;
    }
    now*=now;
    now%=md;
    k/=2;
  }
  return ret;
}
ll gyaku(ll n,ll md){
  return beki(n,md-2,md);
}
int main(){
    ios::sync_with_stdio(false);cin.tie(0);
    string s;cin>>s;
    int now=0;
    int n=s.size();
    for(;;){
        if(now==n)break;
        if(now+5>n){
            cout<<"NO"<<endl;
            return 0;
        }
        string t=s.substr(now,5);
        if(t=="dream"){
            now+=5;
            
        }
        else if(t=="erase")now+=5;
        else{
            cout<<"NO"<<endl;
            return 0;
        }
        if(now==n)break;
        if(s[now]=='r'){
            now++;
            continue;
        }
        if(now+2>n){
            cout<<"NO"<<endl;
            return 0;
        }
        t=s.substr(now,2);
        if(t=="dr")continue;
        else if(t=="er"){
            if(now+2==n){
                break;
            }
            if(s[now+2]=='e'||s[now+2]=='d')now+=2;
            else if(s[now+2]=='a')continue;
            else{
                cout<<"NO"<<endl;
                return 0;
            }
        }
        else{
            cout<<"NO"<<endl;
            return 0;
        }
    }
    cout<<"YES"<<endl;
}


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

long long int arr[3005];
long long int dp[3005][3005];
int n;
long long int call(int i,int j)
{
	 if(i<0 || j<0)
	  return INT_MAX;
	  
	  if(i>=n || j>=n)
	   return INT_MAX;
	   
	 if(j==i+1)
	 return max(arr[j],arr[i]);
	 
	 if(j==i)
	  return arr[i];
	  
	  if(dp[i][j]!=-1)
	   return dp[i][j];
	   
	return dp[i][j]=max(arr[i]+min(call(i+2,j),call(i+1,j-1)),arr[j]+min(call(i,j-2),call(i+1,j-1)));
}

 int main()
{ 
    
     cin>>n;
     long long int sum=0;
     for(int i=0;i<n;i++)
    {
	   cin>>arr[i];
       sum+=arr[i];
   }
       for(int i=0;i<=n;i++)
         for(int j=0;j<=n;j++)
          dp[i][j]=-1;
          
     cout<<2*call(0,n-1)-sum<<endl;  
       
     return 0;
}




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

int main() {
    int N, K;
    cin >> N >> K;
    vector<ll> A(N);
    rep(i, N) cin >> A[i];
    for(int i = K; i < N; i++) {
        if(A[i - K] < A[i])
            cout << "Yes" << endl;
        else
            cout << "No" << endl;
    }
}

Measured memory_bytes: 4784
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <climits>
#include <numeric>
#include <cmath>
#include <queue>
#include <sstream>

using namespace std;
typedef long long ll;

int main() {
  int n, k;
  cin >> n >> k;
  
  ll a = 0;
  for (int i = 1; i <= n; i++) {
    if (i % k == 0) {
      a++;
    }
  }
  ll b = 0;
  for (int i = 1; i <= n; i++) {
    if (i % k == k / 2) {
      b++;
    }
  }
  
  ll ans = a * a * a;
  if (k % 2 == 0) {
    ans += b * b * b;
  }
  
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var d rune
	var rArr []rune

	rArr = make([]rune, 4)
	for i := 0; i < 4; i++ {
		fmt.Scanf("%c", &rArr[i])
	}

	fmt.Scanf("%c", &d) // dummy

	isBad := false

	for i, v := range rArr {
		if i >= 1 {
			if rArr[i-1] == v {
				isBad = true
			}
		}
	}

	if isBad {
		fmt.Print("Bad")
	} else {
		fmt.Print("Good")
	}
}


Measured memory_bytes: 512
// abc136d.cpp : Gathering Children
#include <bits/stdc++.h>
using namespace std;
#define up(i,s,e,d) for(int i=(s);i<(e);i+=(d))
#define ot(x) cout<<(x)

int main(){
  string S; cin>>S; int n = S.length();

  vector<int> ans(n);
  bool sepOrCenter = false; // 切れ目 か 集合場所
  int il, ir, even, odd;
  il = ir = -1;
  up(i,0,n,1){
    if(!sepOrCenter && S[i]=='R'){ // 切れ目
      sepOrCenter = true;
      if(il>=0){
        ans[il] = il%2? odd: even; ans[ir] = ir%2? odd: even;
      }
      even = odd = 0; il = ir = -1;
    }
    else if(sepOrCenter && S[i]=='L'){ // 集合場所（L側）
      sepOrCenter = false;
      il = i; ir = i-1;
    }
    if(i%2) odd++; else even++;
  }
  ans[il] = il%2? odd: even; ans[ir] = ir%2? odd: even;

  ot(ans[0]); up(i,1,n,1) cout<<" "<<ans[i]; ot("\n");
}

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

typedef long long int LLI;

void solve()
{
    int x,y;
    cin>>x>>y;
    bool found=false;
    for(int turtles=0;turtles<=x;++turtles){
        int cranes=x-turtles;
        int legs=turtles*4+cranes*2;
        if(legs==y){
            found=true;
        }
    }
    if(found) cout<<"Yes";
    else cout<<"No";
    return;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    solve();
    return 0;
}

Measured memory_bytes: 3660
#include<iostream>
#include<sstream>
#include<vector>
#include<iterator>
#include<algorithm>
using namespace std;

int main(void)
{
    string S;
    cin >> S;


    vector<int> a(S.size() + 1, -1);
    if (S.front() == '<') {
        a[0] = 0;
        for (int i = 0; i < (int)S.size() && S[i] == '<'; i++)
            a[i + 1] = max(a[i + 1], a[i] + 1);
    }

    if (S.back() == '>') {
        a[S.size()] = 0;
        for (int i = (int)S.size() - 1; i >= 0 && S[i] == '>'; i--)
            a[i] = max(a[i], a[i + 1] + 1);
    }

    for (int i = 0; i < (int)S.size() - 1; i++) {
        if (S[i] == '>' && S[i + 1] == '<') {
            a[i + 1] = 0;

            for (int j = i; j >= 0 && S[j] == '>'; j--)
                a[j] = max(a[j], a[j + 1] + 1);
            for (int j = i + 1; j < (int)S.size() && S[j] == '<'; j++)
                a[j + 1] = max(a[j + 1], a[j] + 1);
        }
    }

    long long ans = 0;
    for (int i = 0; i < (int)a.size(); i++)
        ans += a[i];

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 2820
#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define ll long long
#define maxn 2000005
#define inf 1e9
#define pb push_back
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=a;i>=b;i--)
using namespace std;

inline ll read()
{
	ll x=0,w=1; char c=getchar();
	while(c<'0'||c>'9') {if(c=='-') w=-1; c=getchar();}
	while(c<='9'&&c>='0') {x=(x<<1)+(x<<3)+c-'0'; c=getchar();}
	return w==1?x:-x;
}

int main()
{
	int T=read();
	while(T--)
	{
		ll a=read(),b=read(),c=read(),d=read(); ll tmp=__gcd(b,d);
		if(a<b||d<b) {puts("No"); continue;}
		d%=b; a%=tmp; a-=tmp; a+=b;
		if(a>c) puts("No"); else puts("Yes");
		//cout<<a<<" "<<b<<" "<<c<<" "<<d<<endl;
	}
	return 0;
}

Measured memory_bytes: 3552
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> P;
typedef priority_queue<P,vector<P>,greater<P>> P_queue;

#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define mp make_pair
#define ALL(a) a.begin(),a.end()
#define SORT(a) sort(ALL(a))
#define U_ERASE(V) V.erase(unique(ALL(V)), V.end());

const ll MOD=998244353;
const ll mod=1000000007;
const ll INF=1e10;
vec dx={1,0,-1,0};
vec dy={0,1,0,-1};
ll N; 
vec d(3);
vec Sousa;
vec ans;


bool Solve(ll x){
    vector<bool> S(3,true);
    S[Sousa[x]]=false;
    vec K;
    rep(i,3) if(S[i]) K.pb(i);
    ll a=K[0], b=K[1];
    //cout<<x<<' '<<a<<' '<<b<<endl;
    if(d[a]==0 && d[b]==0) return false;
    if(d[a]>d[b]){
        d[a]--;
        d[b]++;
        ans.pb(b);
    }
    else if(d[b]>d[a]){
        d[a]++;
        d[b]--;
        ans.pb(a);
    }
    else{
        if(x==N-1) ans.pb(a);
        else{
            if(Sousa[x+1]==b) {
                d[a]++; d[b]--; ans.pb(a);
            }
            else{
                d[b]++; d[a]--; ans.pb(b);
            }

        }
    }
    if(x==N-1) return true;
    return Solve(x+1);
}

int main(){
    cin>>N;
    rep(i,3) cin>>d[i];
    rep(i,N){
        string S; cin>>S;
        if(S=="AB") Sousa.pb(2);
        else if(S=="AC") Sousa.pb(1);
        else Sousa.pb(0);
    }
    //rep(i,N) cout<<Sousa[i]<<' ';
    //cout<<endl;
    bool able=Solve(0);
    if(!able) cout<<"No"<<endl;
    else{
        cout<<"Yes"<<endl;
        rep(i,N){
            if(ans[i]==0) cout<<"A"<<endl;
            if(ans[i]==1) cout<<"B"<<endl;
            if(ans[i]==2) cout<<"C"<<endl;
        }
    }
    


}

Measured memory_bytes: 25176
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
REP(i,v.size()){if(i)os<<" ";os<<v[i];}return os;}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
REP(i,v.size()){if(i)os<<endl;os<<v[i];}return os;}

int main() {
    ll a,b,c;
  	cin >> a >> b >> c;
  	if(a+b==c){
        cout << "Yes" << endl;
    }else if(b+c==a){
        cout << "Yes" << endl;
    }else if(c+a==b){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}


Measured memory_bytes: 256
#include <vector>
#include <iostream>
using namespace std;
const int mod = 100000;
int N, M, S;
int main() {
	while (cin >> N >> M >> S, N) {
		N *= N;
		M -= N;
		S -= N * (N + 1) / 2;
		vector<vector<int> > dp(M + 1, vector<int>(S + 1, 0));
		dp[0][0] = 1;
		for (int i = 0; i < N; i++) {
			for (int j = 1; j <= M; j++) {
				for (int k = S; k >= j; k--) {
					dp[j][k] = dp[j][k - j];
					if (j >= 1) {
						dp[j][k] += dp[j - 1][k - 1];
						if (dp[j][k] >= mod) dp[j][k] -= mod;
					}
				}
			}
		}
		int ret = 0;
		for (int i = 0; i <= M; i++) {
			ret += dp[i][S];
			if (ret >= mod) ret -= mod;
		}
		cout << ret << endl;
	}
	return 0;
}

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

int main()
{
    ll a,b,c,d,i,j,k;
    cin>>a>>b>>c;
    d=c-b;
    if(d%2==0)cout<<d/2<<endl;
    else
    {
        j=c-b-1;
        j=b+j/2;
        d=a-c;
        k=a-b-d-1;
        k=d+1+k/2;

        d=min(j,k);
        cout<<d<<endl;
    }
    return 0;
}


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

from pprint import pprint
from collections import deque, defaultdict
import itertools
import math
import sys

sys.setrecursionlimit(10 ** 6)
input = sys.stdin.buffer.readline
INF = float('inf')

N, M, X = map(int, input().split())
C = []
for _ in range(N):
    line = list(map(int, input().split()))
    C.append(line)
# pprint(C)

res = INF
for i in range(2 ** N):
    books = []
    for j in range(N):
        if i & (1 << j):
            books.append(C[j])
    total = 0
    level = [0] * M
    for book in books:
        total += book[0]
        for idx, l in enumerate(book[1:]):
            level[idx] += l
    flag = True
    for lev in level:
        if lev < X:
            flag = False
    if flag:
        res = min(res, total)

if res == INF:
    print('-1')
else:
    print(res)


Measured memory_bytes: 75644
import java.util.*;
public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int d = sc.nextInt();
		double range = (double)d * 2 + 1;
		System.out.println((int)Math.ceil(n / range));
	}
}

Measured memory_bytes: 22612
N=int(input())
p=list(map(float,input().split()))

dp=[[0]*(N+1) for _ in range(N+1)]

dp[0][0]=1

for i in range(1,N+1):
    dp[i][0]=dp[i-1][0]*(1-p[i-1])

for i in range(1,N+1):
    for j in range(1,N+1):
        dp[i][j] = dp[i-1][j]*(1-p[i-1]) + dp[i-1][j-1]*p[i-1]

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

Measured memory_bytes: 345864
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Text;
using System.Text.RegularExpressions;
using System.Linq;
using System.IO;
using System.Diagnostics;

class Scanner
{
    private readonly char Separator = ' ';
    private int Index = 0;
    private string[] Line = new string[0];
    public string Next()
    {
        if (Index >= Line.Length)
        {
            Line = Console.ReadLine().Split(Separator);
            Index = 0;
        }
        var ret = Line[Index];
        Index++;
        return ret;
    }

    public int NextInt()
    {
        return int.Parse(Next());
    }

    private long NextLong()
    {
        return long.Parse(Next());
    }
}

class Program
{
    private int K;
    private long[] A;
    private void Scan()
    {
        var sc = new Scanner();
        K = sc.NextInt();
        A = new long[K];
        for (int i = 0; i < K; i++)
        {
            A[i] = sc.NextInt();
        }
    }

    public void Solve()
    {
        Scan();
        long max = 2, min = 2;
        for (int i = K - 1; i >= 0; i--)
        {
            if (((min + A[i] - 1) / A[i]) * A[i] > max)
            {
                Console.WriteLine(-1);
                return;
            }
            max = (max / A[i]) * A[i] + A[i] - 1;
            min = ((min + A[i] - 1) / A[i]) * A[i];
        }
        Console.WriteLine($"{min} {max}");
    }

    static public void Main()
    {
        new Program().Solve();
    }
}

Measured memory_bytes: 27356
#!/usr/bin/perl

my($A,$B,$K)=split(/ /, <>);
my @ar;
for my $i(1..100){
  if($A%$i==0 && $B%$i==0){
    push(@ar,$i);
  }
}
@ar = sort{$b<=>$a}@ar;
print $ar[$K-1];

Measured memory_bytes: 512
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<unordered_map>
#include<array>
#include<map>
#include<bitset>
#include<iomanip>
using namespace std;
typedef long long int llint;
typedef long double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
#define dme cout<<"IMPOSSIBLE"<<endl;return 0
//ios::sync_with_stdio(false);
//std::cin.tie(0);
//<< setprecision(20)
//19234567892927;
const int mod=1e9+7;
const llint big=1e13+100;
const long double pai=3.141592653589793238462643383279502884197;
const long double ena=2.71828182845904523536;
const long double eps=1e-7;
template <class T,class U>void mineq(T& a,U b){if(a>b){a=b;}}
template <class T,class U>void maxeq(T& a,U b){if(a<b){a=b;}}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){return a/gcd(a,b)*b;}
//abcabcabc...
int main(void){
	int a=0,b=0,c=0,n;
	string str;cin>>str;
	for(auto e:str){
		if(e=='a'){a++;}
		if(e=='b'){b++;}
		if(e=='c'){c++;}
	}
	
	if(a>b){swap(a,b);}
	if(b>c){swap(b,c);}
	if(a>b){swap(a,b);}
	if(a==c||a+1==c){cout<<"YES"<<endl;}
	else{cout<<"NO"<<endl;}
	return 0;
}

Measured memory_bytes: 888
import java.util.*;
import java.math.*;
public class Main {
	static int x;
	static int ans;
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		long ans = 0;
		for(int i = 1; i <= n; i++) {
			String str = i + "";
			if(str.length() == 1) {
				ans += 1L;
			}else if(str.length() == 2){
				if((str.charAt(1) != '0')) {
					int a = Integer.parseInt(str.substring(0, 1));
					int b = Integer.parseInt(str.substring(1, 2));
					if(a > b) ans += 2;
					else if(a == b) ans += 3;
				}
			}else {
				if((str.charAt(str.length() - 1) != '0')) {
					int a = Integer.parseInt(str.substring(0, 1));
					int b = Integer.parseInt(str.substring(str.length() - 1, str.length()));
					if(a == b) ans += 2;
					ans += 2;
					int size = str.length() - 2;
					int cnt = 1;
					long mult = 1;
					String createnew = "";
					while (cnt <= size) {
						if((a < b) && (cnt == size)) break;
						mult *= 10;
						ans += mult + mult;
						cnt += 1;
						createnew += "9";
					}
					if(a == b) {
						int newnum = Integer.parseInt(createnew);
						int midnum = Integer.parseInt(str.substring(1, str.length() - 1));
						if(newnum == midnum) {
							ans -= 1;
						}else if(newnum > midnum) {
							ans -= (newnum - midnum) * 2;
							ans -= 1;
						}
					}
					
				}
			}
		}
		System.out.println(ans);
	}
} 

Measured memory_bytes: 59328
##########
import math
#import numpy as np
from itertools import product as prod
#from itertools import permutations as perm
#from itertools import combinations as comb
#from itertools import combinations_with_replacement as combr

ii = lambda:int(input())
li = lambda:list(map(int,input().split()))
##########
def main(k):
    res = 0
    for item in prod(range(1,k+1),repeat=3):
        res += calc(item)
    return res
        
def calc(item):
    a,b,c = item
    return math.gcd(a,math.gcd(b,c))

k = ii()
print(main(k))

Measured memory_bytes: 67740
import numpy as np

mod = 998244353
N = int(input())
A = [int(input()) for i in range(N)]
S = sum(A)


def fastpow(a, n):
    i = 0
    result = 1
    pow = [a]
    while (1 << i) <= n:
        pow.append(pow[-1] * pow[-1] % mod)
        i += 1
    for j in range(i):
        if (n >> j) % 2 == 1:
            result = result * pow[j] % mod
    return result

# D1[i][r]: i個塗った時点でR=rとなる場合の数
D1 = np.zeros((N+1, S+1), dtype=int)
D1[0][0] = 1
# D2[i][r]: i個塗った時点でR=r, B=0となる場合の数
D2 = np.zeros((N+1, S+1), dtype=int)
D2[0][0] = 1

for i in range(N):
    D1[i+1] += D1[i] * 2
    D1[i+1][A[i]:] += D1[i][:-A[i]]
    D1[i+1] = D1[i+1] % mod

    D2[i+1] += D2[i]
    D2[i+1][A[i]:] += D2[i][:-A[i]]
    D2[i+1] = D2[i+1] % mod

border = (S + 1) // 2

result = fastpow(3, N)
result -= 3 * sum(D1[N][border:])
if border * 2 == S:
    result += 3 * D2[N][border]

print(result % mod)


Measured memory_bytes: 433548
# coding: utf-8
from sys import stdin
import sys, fractions
import numpy as np

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


a,b,c,d = [int(x) for x in stdin.readline().rstrip().split()]
#print(a, b, c, d)
#bまでで3で割り切れる数
three_all = b // c
#a-1までで3で割り切れる数
three_less = (a-1) // c
three_range = three_all - three_less
    
two_all = b // d
two_less = (a-1) // d
two_range = two_all - two_less
    
z = lcm(c,d)
six_all = b // z
six_less = (a-1) // z
six_range = six_all - six_less
    
num = three_range + two_range - six_range
    
ans = b-a+1-num
print(ans)
    


    




Measured memory_bytes: 13580
def missingcheck(data,suit):
    for i in range(13):
        if '{} {}'.format(suit,str(i+1)) not in data:
            print('{} {}'.format(suit,str(i+1)))

n = int(input())
data = []
for i in range(n):
    data.append(input())
missingcheck(data,'S')
missingcheck(data,'H')
missingcheck(data,'C')
missingcheck(data,'D')



Measured memory_bytes: 5600
sx, sy, tx, ty = [int(x) for x in input().split()]

# 1周目
dx = tx - sx
dy = ty - sy
route1 = "U" * dy + "R" * dx + "D" * dy + "L" * dx

# 2周目
route2 = "L" + "U" * (dy + 1) + "R" * (dx + 1) + "D" + "R" + "D" * (dy + 1) + "L" * (dx + 1) + "U"

print(route1 + route2)


Measured memory_bytes: 3064
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;

public class Remainder
{
    static int[] PrimeFactors;

    static public void Main()
    {
        var NK = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();
        var N = NK[0];
        var K = NK[1];
        var H = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();
      
        Array.Sort(H);
      
        for(int i = 1;i <= K && i <= N ;i++){
          H[N-i] = 0;
        }
        

        Console.WriteLine(H.Sum());

    }

}


Measured memory_bytes: 41472
#include <stdio.h>
#include <ctype.h>

int main(void){
	setvbuf(stdout,NULL,_IONBF,0);

	char str[1200] = {};
	int i;
	for(i = 0;i < 1200;i++){
		scanf("%c",&str[i]);
		if(str[i] == '\n'){
			break;
		}
	}


	for(i = 0;i < 1200;i++){
		if(islower(str[i])){
			str[i] = toupper(str[i]);
			printf("%c",str[i]);
		}
		else if(isupper(str[i])){
			printf("%c",tolower(str[i]));
		}
		else if(str[i] == '\n'){
			break;
		}
		else{
			printf("%c",str[i]);
		}
	}
	puts("");
	return 0;
}

Measured memory_bytes: 524
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <iomanip>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define pie 3.141592653589793238462643383279
#define mod 1000000007
#define inf 10000000000000007
#define all(vec) vec.begin(),vec.end()
#define ggr getchar(); getchar();return 0;
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}
bool prime(int x) {
	for (int i = 2; i <= sqrt(x); i++) {
		if (x%i == 0)return false;
	}
	return true;
}

int kai(int x) {
	if (x == 1)return 1;
	return kai(x - 1)*x;
}

int mod_pow(int x, int y, int moder) {
	int res = 1;
	while (y > 0) {
		if (y & 1)res = res * x%moder;
		x = x * x%moder;
		y >>= 1;
	}
	return res;
}

int a[5];
int ans, mu = 10;
bool ta;


signed main() {
	rep(i, 5) {
		cin >> a[i];
		if (a[i] % 10) {
			ans += (a[i] / 10 + 1) * 10;

			ta = true;
			mu = min(mu, a[i] % 10);
		}
		else {
			ans += a[i];
		}
	}
		if (ta)cout << ans - 10 + mu << endl;
		else cout << ans << endl;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#define llint long long
#define mod 998244353

using namespace std;

llint n;
llint a[1000005];
bool prime[1000005];
vector<llint> pvec;

llint modpow(llint a, llint n)
{
	if(n == 0) return 1;
	if(n % 2){
		return ((a%mod) * (modpow(a, n-1)%mod)) % mod;
	}
	else{
		return modpow((a*a)%mod, n/2) % mod;
	}
}

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n;
	llint x, ans = 0;
	for(int i = 1; i <= n; i++){
		cin >> x;
		a[x] += x, a[x] %= mod;
		ans += mod - x%mod, ans %= mod;
	}
	
	for(int i = 2; i < 1005; i++){
		if(prime[i]) continue;
		for(int j = 2*i; j < 1000005; j+=i) prime[j] = true;
	}
	for(int i = 2; i < 1000005; i++) if(!prime[i]) pvec.push_back(i);
	
	for(int i = 0; i < pvec.size(); i++){
		llint p = pvec[i];
		for(int j = 1000005/p+1; j >= 1; j--){
			if(j*p < 1000005) a[j] += a[j*p], a[j] %= mod;
		}
	}
	
	for(int i = 1; i < 1000005; i++) a[i] = a[i]*a[i]%mod;
	
	for(int i = 0; i < pvec.size(); i++){
		llint p = pvec[i];
		for(int j = 1; j*p < 1000005; j++){
			a[j] += mod - a[j*p], a[j] %= mod;
		}
	}
	
	for(int i = 1; i < 1000005; i++){
		ans += a[i] * modpow(i, mod-2) % mod, ans %= mod;
	}
	ans *= modpow(2, mod-2), ans %= mod;
	cout << ans << endl;
	
	return 0;
}

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

int main()
{
 
  char s[4];
  
  scanf("%s",s);
  
  if(strcmp(s,"ABC")==0)
  {
    printf("ARC\n");
  }
  else
  {
    printf("ABC\n");
  }
  return 0;
}

Measured memory_bytes: 1612
s = gets.chomp.split('')

r = 0
n = 0
s.each do |c|
  if "ATCG".include?(c)
    if n == 0
      n = 1
    else
      n += 1
    end
  else
    if n != 0
      if r < n
        r = n
      end
      n = 0
    end
  end
end

if r < n
  r = n
end
puts r



Measured memory_bytes: 1788
package main

import (
	"fmt"
	"sort"
)

func main() {
	var n int
	fmt.Scan(&n)
	a := make([]int, n)
	for i := range a {
		fmt.Scan(&a[i])
	}

	sort.Ints(a)
	fmt.Println(a[len(a)-1] - a[0])
}


Measured memory_bytes: 512
# -*- coding: utf-8 -*-

def input_int():
    return int(input())


def input_array():
    return input().split()


def answer():
    n = input_int()
    same_counter = 0
    for i in range(n):
        d1, d2 = input_array()
        if d1 == d2:
            same_counter += 1
            if same_counter >= 3:
                print('Yes')
                return
        else:
            same_counter = 0
    print('No')


answer()

Measured memory_bytes: 9032
import java.util.Scanner;

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

        int N = scanner.nextInt();

        int[] V = new int[N];
        int[] C = new int[N];

        for(int i=0; i<N; i++){
            V[i] = scanner.nextInt();
        }

        for(int i=0; i<N; i++){
            C[i] = scanner.nextInt();
        }

        int ans = 0;

        for(int i=0; i<N; i++){
            ans += Math.max(0, V[i]-C[i]);
        }

        System.out.println(ans);
    }
}


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

int main() {
  
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  
  if (abs(a-c)<=d) cout << "Yes" << endl;
  else if (abs(a-b)<=d && abs(b-c)<=d) cout << "Yes" << endl;
  else cout << "No" << endl;
}

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

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

const int N=20;

vector<vector<int>> adj;
vector<bool> visited;

int bfs(int start) {
    int ans = 0;
    queue<int> Q;
    Q.push(start);
    visited[start] = true;
    
    vector<int> level(N*N, 0);
    
    level[start] = 0;
    
    while(Q.size() > 0) {
        int node = Q.front();
        Q.pop();
        int child;
        
        for(int i = 0; i < adj[node].size(); ++i) {
            child = adj[node][i];
            
            if(!visited[child]) {
                Q.push(child);
                visited[child] = true;
                level[child] = level[node] + 1;
                ans = max(ans, level[child]);
            }
        }
    }
    
    return ans;
}

void fill(vector<bool> &vec) {
    for(int i = 0; i < vec.size(); ++i) {
        visited[i] = vec[i];
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
    
    
    int n, m;
    
    cin >> n >> m;
    
    visited.resize(n*m+1, false);
    adj.resize(n*m+1);
    
    vector<vector<char>> grid(n, vector<char>(m));
    string line;
    
    for(int i = 0; i < n; ++i) {
        cin >> line;
        for(int j = 0; j < m; ++j) {
            grid[i][j] = line[j];
        }
    }
    
    int index = -1;
    
    for(int i = 0; i < n; ++i) {
        for(int j = 0; j < m; ++j) {
            index++;
            
            if(grid[i][j] == '#') {
                visited[index] = true;
                continue;
            }
            
            if( (i-1) >= 0 && grid[i-1][j] == '.') {
                adj[index].push_back(index-m);
                adj[index-m].push_back(index);
            }
            
            if((j-1) >= 0 && grid[i][j-1] == '.') {
                adj[index].push_back(index-1);
                adj[index-1].push_back(index);
            }
            
            if((i+1) < n && grid[i+1][j] == '.') {
                adj[index].push_back(index+m);
                adj[index+m].push_back(index);
            }
            
            if((j+1) < m && grid[i][j+1] == '.') {
                adj[index].push_back(index+1);
                adj[index+1].push_back(index);
            }
        }
    }
    
    int ans = 0;
    
    vector<bool> vec(visited);
    
    for(int i = 0; i < n*m; ++i) {
        ans = max(ans, bfs(i));
        fill(vec);
    }

    
    cout << ans << endl;
    
   return 0;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
mul4 = 0
mul2 = 0
has_mul2 = 0
other = 0
for i in a:
    if i%4 == 0:
        mul4 += 1
    elif i%2 == 0:
        mul2 += 1
        has_mul2 = 1
    else:
        other += 1

if mul4 >= (has_mul2+other-1) or other == 0:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 15020
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
#[allow(unused_imports)]
use std::collections::{HashMap, HashSet};

mod util {
    use std::io::stdin;
    use std::str::FromStr;
    use std::fmt::Debug;

    #[allow(dead_code)]
    pub fn line() -> String {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.trim().to_string()
    }

    #[allow(dead_code)]
    pub fn get<T: FromStr>() -> T
    where
        <T as FromStr>::Err: Debug,
    {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.trim().parse().unwrap()
    }

    #[allow(dead_code)]
    pub fn gets<T: FromStr>() -> Vec<T>
    where
        <T as FromStr>::Err: Debug,
    {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.split_whitespace()
            .map(|t| t.parse().unwrap())
            .collect()
    }

    #[allow(dead_code)]
    pub fn get2<T: FromStr, U: FromStr>() -> (T, U)
    where
        <T as FromStr>::Err: Debug,
        <U as FromStr>::Err: Debug,
    {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        let mut iter = line.split_whitespace();
        (
            iter.next().unwrap().parse().unwrap(),
            iter.next().unwrap().parse().unwrap(),
        )
    }

    #[allow(dead_code)]
    pub fn get3<S: FromStr, T: FromStr, U: FromStr>() -> (S, T, U)
    where
        <S as FromStr>::Err: Debug,
        <T as FromStr>::Err: Debug,
        <U as FromStr>::Err: Debug,
    {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        let mut iter = line.split_whitespace();
        (
            iter.next().unwrap().parse().unwrap(),
            iter.next().unwrap().parse().unwrap(),
            iter.next().unwrap().parse().unwrap(),
        )
    }
}

// std::cmp::Reverse doesn't have Clone.
#[derive(Eq, PartialEq, Clone)]
struct Rev<T>(pub T);

impl<T: PartialOrd> PartialOrd for Rev<T> {
    fn partial_cmp(&self, other: &Rev<T>) -> Option<Ordering> {
        other.0.partial_cmp(&self.0)
    }
}

impl<T: Ord> Ord for Rev<T> {
    fn cmp(&self, other: &Rev<T>) -> Ordering {
        other.0.cmp(&self.0)
    }
}

#[allow(unused_macros)]
macro_rules! debug {
    ($x: expr) => {
        println!("{}: {:?}", stringify!($x), $x)
    }
}

fn main() {
    let n: usize = util::get();
    let ab: Vec<(usize, usize)> = (0..n).map(|_| util::get2()).collect();

    println!("{}", ab.iter().max().map(|&(a, b)| a + b).unwrap());
}


Measured memory_bytes: 6524
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <cfloat>
#include <complex>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

int main() {
  ll N, K, Q;

  cin >> N >> K >> Q;

  vector<ll> score(N, 0);
  for (int i = 0; i < Q; i++) {
    int idx;
    cin >> idx;
    score[idx-1]++;
  }

  for (int i = 0; i < N; i++) {
    if(Q - score[i] < K){
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
  }

  return 0;
}


Measured memory_bytes: 1408
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        
        Scanner sc = new Scanner(System.in);
        
        int n = Integer.parseInt(sc.next());
        int k = Integer.parseInt(sc.next());
        int[] x = new int[n];
        for(int i = 0; i < n; i++){
            x[i] = Integer.parseInt(sc.next());
        }
        
        int min = 1000000000;
        for(int i = 0; i < n-k+1; i++){
            int a = x[i+k-1] - x[i] + Math.min(Math.abs(x[i+k-1]), Math.abs(x[i]));
            if(a < min){
                min = a;
            }
        }
        
        System.out.println(min);
    }
}

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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define eb emplace_back

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

void Main(){
	int n, x;
	cin >> n >> x;
	vi m(n);
	int sum = 0;
	rep(i,n) {
		cin >> m[i];
		sum += m[i];
	}
	sort(all(m));
	x -= sum;
	int ans = n;
	ans += x/m[0];
	cout << ans << endl;
	return;
}

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef int ll;
typedef long long int li;
const ll MAXN=2e5+51;
ll kk,n,res;
ll num[MAXN];
inline ll read()
{
    register ll num=0,neg=1;
    register char ch=getchar();
    while(!isdigit(ch)&&ch!='-')
    {
        ch=getchar();
    }
    if(ch=='-')
    {
        neg=-1;
        ch=getchar();
    }
    while(isdigit(ch))
    {
        num=(num<<3)+(num<<1)+(ch-'0');
        ch=getchar();
    }
    return num*neg;
} 
int main()
{
	kk=read(),n=read();
	for(register int i=0;i<n;i++)
	{
		num[i]=read();
	}
	for(register int i=1;i<n;i++)
	{
		res=max(res,num[i]-num[i-1]);
	}
	res=max(res,num[0]+kk-num[n-1]);
	printf("%d\n",kk-res);
}

Measured memory_bytes: 1024
#include <set>
#include <unordered_set>
#include <map>
#include <string>
#include <iostream>

using namespace std;

void insert(unordered_set<string> &s, string word)
{
    s.insert(word);
    return;
}

void find(unordered_set<string> &s, string word)
{
    s.count(word) ? printf("yes\n") : printf("no\n");
    return;
}

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

    string query, word;
    unordered_set<string> S;
    map<string, int> cmd;
    cmd["insert"] = 0;
    cmd["find"] = 1;

    for (int i = 0; i < n; i++)
    {
        cin >> query >> word;
        switch (cmd[query])
        {
        case 0:
            insert(S, word);
            break;
        case 1:
            find(S, word);
            break;
        default:
            break;
        }
    }
}


Measured memory_bytes: 32236
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

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

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

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

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

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

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

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

fn main() {
    input! {
        n: usize,
        a: [i64; n],
    }
    let mut alice = 0;
    let mut bob = 0;
    let mut alices_turn = true;
    let mut a = a;
    a.sort();
    for i in a.iter().rev() {
        if alices_turn {
            alice = alice + i;
        } else {
            bob = bob + i;
        }
        alices_turn = !alices_turn;
    }
    println!("{}", alice - bob);
}


Measured memory_bytes: 4352
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll x;
    cin >> x;
    ll ans = (x / 11) * 2;
    x -= (x / 11) * 11;
    if(x > 0 && x <= 6) ans += 1;
    else if(x > 6) ans += 2;
    cout << ans << endl;


    return 0;
}


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

p, q = 0, 0
for i in a:
    if i % 2 == 0:
        p += 1
    else:
        q += 1
    
if p == 0 or q == 0:
    print(0)
    exit()

res = p

if q % 2 == 0:
    res += 2 * max(q // 2 - 1, 0)
else:
    res += (q // 2) * 2

print(res)


Measured memory_bytes: 27368
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <numeric>
#include <cmath>
#include <cstdlib>

typedef long long ll;
typedef unsigned long long ull;

#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
#define INF (1001000000)
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define UNIQ(c) (c).erase(unique((c).begin(),(c).end()), (c).end());
#define P(p) cout<<(p)<<endl;

using namespace std;

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

    int a, b, c;
    cin >> a >> b >> c;

    int ans = min(c, b/a);
    P(ans);

    return 0;
}


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

using namespace std;

#define INF 100000000
#define YJ 1145141919
#define INF_INT_MAX 2147483647
#define INF_LL 9223372036854775
#define INF_LL_MAX 9223372036854775807
#define EPS 1e-10
#define MOD 1000000007
#define MOD9 998244353
#define Pi acos(-1)
#define LL long long
#define ULL unsigned long long
#define LD long double

#define int long long

using II = pair<int, int>;

int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a * b / gcd(a, b); }
int extgcd(int a, int b, int &x, int &y) { int g = a; x = 1; y = 0; if (b != 0) g = extgcd(b, a % b, y, x), y -= (a / b) * x; return g; }

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(a)  begin((a)), end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())

int N;

signed main()
{
  cin >> N;
  cout << (N-1)*N/2 << endl;
  return 0;
}


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

using namespace std;

int main(){
    int n, k;
    cin >> n >> k;
    vector<int> H(n);
    copy_n(istream_iterator<int>(cin), n, H.begin());
    sort(H.begin(), H.end(), greater<int>());

    int64_t ans = 0;
    for (int i = k; i < n; i++){
        ans += H[i];
    }

    cout << ans << endl;
}

Measured memory_bytes: 1152
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip> 
#include <complex> 
#include <string>
#include <vector> 
#include <list>
#include <deque> 
#include <stack> 
#include <queue> 
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <utility>
#include <algorithm> 
#include <numeric> 
#include <typeinfo> 
#include <cstdio>
#include <cstdlib> 
#include <cstring>
#include <cmath>
#include <climits> 
#include <ctime>

using namespace std;

int main(void){
	string num1;
	int num[10];
	int ans[10];
	int a,b;
	while(cin >> num1){
		for(a=0;a<10;a++){
			num[a]=num1[a]-'0';
		}
		for(a=0;a<10;a++){
			for(b=0;b<9-a;b++){
				ans[b]=(num[b]+num[b+1])%10;
			}
			for(b=0;b<9-a;b++){
				num[b]=ans[b];
			}
		}
		printf("%d\n",ans[0]);
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) for (int i = 0; i < (n); i++)
#define fi first
#define se second
using ii = pair<int, int>;

constexpr int HOGE = 1e17 + 100;
int exp1(const string& s, int& i, int r);
int exp2(const string& s, int& i, int r);
int exp1(const string& s, int& i, int r) {
    int acc = exp2(s, i, r);
    while (i < r) {
        if (s[i] == '+') {
            acc += exp2(s, ++i, r);
        } else if (s[i] == '-') {
            acc -= exp2(s, ++i, r);
        } else
            return acc;
        // assert(0);
    }
    return acc;
}
int exp2(const string& s, int& i, int r) {
    if (s[i] == '(') {
        int ret = exp1(s, ++i, r);
        assert(s[i++] == ')');
        return ret;
    }
    if (isdigit(s[i])) return s[i++] - '0';
    // assert(0);
    return exp1(s, i, r);
}
bool is_valid(const string& s, int i, int r) {
    int acc = 0;
    for (int j = i; j < r; j++) {
        if (s[j] == '(') acc++;
        if (s[j] == ')') acc--;
        if (acc < 0) return false;
    }
    return acc == 0;
}
signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);

    string s;
    cin >> s;
    vector<int> num, idx, op_idx;
    op_idx.push_back(-1);
    vector<char> ops;
    REP(i, s.size()) {
        if (isdigit(s[i])) {
            num.push_back(s[i] - '0');
            idx.push_back(i);
        }
        if (s[i] == '+' || s[i] == '-') {
            ops.push_back(s[i]);
            op_idx.push_back(i);
        }
    }
    op_idx.push_back(s.size());

    auto valid = [&](int i) { return 0 <= i && i < s.size(); };

    constexpr ii DMY = {1e17, 1e17};
    int m = num.size();
    vector<vector<ii>> dp(m, vector<ii>(m, DMY));
    function<ii(int, int)> dfs = [&](int i, int j) {
        if (dp[i][j] != DMY) return dp[i][j];
        if (i == j) return dp[i][j] = {num[i], num[i]};
        int mi = 1e18, ma = -1e18;
        int l_idx = idx[i];
        int r_idx = idx[j];
        if (is_valid(s, l_idx, r_idx + 1)) {
            mi = ma = exp1(s, l_idx, r_idx + 1);
        }
        for (int k = i; k < j; k++) {
            if (k != i && valid(idx[k] - 1) && s[idx[k] - 1] == '(') continue;
            if (k != j - 1 && valid(idx[k + 1] + 1) && s[idx[k + 1] + 1] == ')') continue;
            ii l = dfs(i, k);
            ii r = dfs(k + 1, j);
            if (ops[k] == '+') {
                mi = min(mi, l.fi + r.fi);
                ma = max(ma, l.se + r.se);
            } else {
                // assert(ops[k] == '-');
                mi = min(mi, l.fi - r.se);
                ma = max(ma, l.se - r.fi);
            }
        }
        return dp[i][j] = {mi, ma};
    };
    dfs(0, m - 1);
    cout << dp[0][m - 1].se << endl;
}



Measured memory_bytes: 3308
#include <iostream>
#include <vector>
typedef long long int ll;
using namespace std;
 
ll gcd_(ll a,ll b){
    if(a<b){  
        swap(a,b);
    }
    if(b==0){
        return a;
    }
    return gcd_(b,a%b);
}
 
ll gcd(vector<ll> l){
    ll ans=l[0];
    for(size_t i=0;i<l.size();i++){
        ans=gcd_(ans,l[i]);
    }
    return ans;
}
 
int main(){
    ll N;
    cin>>N;
    vector<ll> vec(N);
    for(ll i=0;i<N;i++){
        cin>>vec[i];
    }
    
    cout<<gcd(vec)<<endl;
 
    return 0;
}

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

const uint64_t MOD = 1e+9 + 7;
 
namespace IntegerMath
{
  int64_t sqrt(int64_t x) {
    return static_cast<int64_t>(
      ::floorl( ::sqrtl( 
        static_cast<long double>(x)
      ) )
    );
  }
  
  int64_t log2(int64_t x) {
    return static_cast<int64_t>(
      ::floorl( ::log2l( 
        static_cast<long double>(x)
      ) )
    );
  }
};

class Prime
{
private:
  std::set<uint64_t> _primes;
  
  bool _is_prmie(uint64_t n) const {
    uint64_t m = IntegerMath::sqrt(n);
    for (uint64_t d : _primes) {
      if (n % d == 0) { return false; }
      if (d > m) { break; }
    }
    return true;
  }
  
public:
  Prime(uint64_t n) {
    _primes.insert(2);
    
    for (uint64_t i = 3; i <= n; i += 2) {
      if (_is_prmie(i)) {
        _primes.insert(i);
      }
    }
  }
  
  std::set<uint64_t> set() const { return _primes; }
};

std::list<std::pair<uint64_t, uint64_t>> prime_division(uint64_t n)
{
  std::list<std::pair<uint64_t, uint64_t>> list;
  
  uint64_t m = IntegerMath::sqrt(n) + 1;
  
  for (uint64_t p : Prime(m).set()) {
    uint64_t e = 0;
    
    for (e = 0; n % p == 0; ++e) { n /= p; }
    
    if (e > 0) { list.emplace_back(p, e); }
    
    if (n == 1) { break; }
  }
  
  if (n > 1) { list.emplace_back(n, 1); }
  
  return list;
}

class ModuloOps
{
private:
  std::vector<uint64_t> _fact, _fact_inv;
  
  void _calc_fact(uint64_t n)
  {
    for (uint64_t i = 2; i <= n; ++i) {
      _fact[i] = (_fact[i - 1] * i) % MOD;
      _fact_inv[i] = inv(_fact[i]);
    }
  }

public:
  ModuloOps(uint64_t n)
  {
    _fact = std::vector<uint64_t>(n + 1);
    _fact_inv = std::vector<uint64_t>(n + 1);
    
    _fact[0] = 1;
    _fact[1] = 1;
    _fact_inv[0] = 1;
    _fact_inv[1] = 1;
    
    _calc_fact(n);
  }
  
  uint64_t power(uint64_t x, uint64_t y) const
  {
    if (y <= 1) {
      return (y == 0) ? 1 : (x % MOD);
    }
    
    uint64_t w = power(x, y >> 1);
    uint64_t z = (w * w) % MOD;
    
    if (y % 2 == 1) {
      z = (x * z) % MOD;
    }
    
    return z;
  }
  
  uint64_t inv(uint64_t n) { return power(n, MOD - 2); }
  
  uint64_t fact(uint64_t n) const { return _fact[n]; }
  uint64_t fact_inv(uint64_t n) const { return _fact_inv[n]; }
  
  uint64_t perm(uint64_t n, uint64_t k) const {
    return (_fact[n] * _fact_inv[n - k]) % MOD;
  }
  
  uint64_t comb(uint64_t n, uint64_t k) const {
    return (perm(n, k) * _fact_inv[k]) % MOD;
  }
  
  uint64_t comb_rep(uint64_t n, uint64_t k) const {
    return comb(n + k - 1, k);
  }
};

int main()
{
  uint64_t N, M;
  std::cin >> N >> M;
  
  uint64_t T = 1;
  
  ModuloOps mod_ops(1e+6);
  for (const std::pair<uint64_t, uint64_t> &pair : prime_division(M)) {
    T = (T * mod_ops.comb(pair.second + N - 1, pair.second)) % MOD;
  }
  
  std::cout << T << std::endl;
  
  return 0;
}

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

int main(){
  int n;
  cin>>n;
  vector<long long> a(n);

  int minus=0;
  bool flg=false;
  long long longmin=1000000000;
  for(int i=0; i<n; ++i){
    cin>>a[i];
    if(a[i]==0)flg=true;
    if(a[i]<0)++minus;
    longmin=min(longmin, abs(a[i]));
  }

  long long ans=0;
  if(minus%2==0 || flg==true){
    for(int i=0; i<n; ++i)ans+=abs(a[i]);
  }else{
    for(int i=0; i<n; ++i)ans+=abs(a[i]);
    ans-=longmin*2;
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 1024