akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize("Ofast","unroll-loops","omit-frame-pointer","inline") //Optimization flags
#pragma GCC option("arch=native","tune=native","no-zero-upper") //Enable AVX
#pragma GCC target("avx2")  //Enable AVX
#include<bits/stdc++.h>
using namespace std;
#define int ll
#define all(a) a.begin(),a.end()
#define F first
#define S second
#define pb push_back
#define ll long long
#define vi vector<int>
#define pi pair<int,int>
#define mp make_pair
 
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif
 
const int mod=998244353;
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
int mul(int a,int b)
{
	return ((a)*1ll*(b))%mod;
}
 
void add(int &a,int b)
{
	a+=b;
	if(a>=mod)a-=mod;
}
 
int sub(int a,int b){
	a-=b;
	if(a<0){
		a+=mod;
	}
	return a;
}
 
int powz(int a,int b)
{
	int res=1;
	while(b)
	{
		if(b&1){
			res=mul(res,a);
		}
		b/=2;
		a=mul(a,a);
	}
	return res;
}
 
template <typename A, typename B>
istream& operator>>(istream& input,pair<A,B>& x) {
	input>>x.F>>x.S;
	return input;
}
 
template <typename A>
istream& operator>>(istream& input,vector<A>& x) {
	for(auto& i:x)
		input>>i;
	return input;
}
 
template<typename A>
ostream& operator<<(ostream& output,vector<A>& x) {
	for(auto& i:x)
		output<<i<<' ';
	return output;
}
 
const int N=1000002;

void solve(){
	int n;
	cin>>n;
	vector<pair<string,int>>a(n);
	cin>>a;
	string s;
	cin>>s;
	ll ans=0;
	int flag=0;
	for(int i=0;i<n;i++){
		if(flag){
			ans+=a[i].S;
		}
		if(a[i].F==s){
			flag++;
		}
	}
	cout<<ans;
}

signed main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int tc=1;
	//~ cin>>tc;
	for(int _=0;_<tc;_++){
		//~ cout<<"Case #"<<_+1<<": ";
		solve();
		if(_!=tc-1)
		cout<<"\n";
	}
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#define ll long long
#define N 100005
#define inf 0x3f3f3f3f
using namespace std;
ll sum,a[N],t,tmp,n;
int main() {
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		sum+=a[i];
		t+=i;
	}

	if(sum%t)cout<<"NO";
	else{
		tmp=a[1];
		for(int i=1;i<n;i++)a[i]=a[i+1]-a[i];
		a[n]=tmp-a[n];
		ll d=sum/t,ok=1;
		for(int i=1;i<=n&&ok;i++){
			a[i]-=d;
			if(a[i]%n||a[i]>0)ok=0;
		}
		if(ok)cout<<"YES";
		else cout<<"NO";
	}
	return 0;
}

Measured memory_bytes: 1024
//  Copyright © 2019 Diego Garcia Rodriguez del Campo. All rights reserved.
#include<bits/stdc++.h>
#define MAX 300005
using namespace std;
#define optimiza_io cin.tie(0); ios_base::sync_with_stdio(0);
typedef long long i64;

int A, B, C;

int main()
{
    optimiza_io 
    cin >> A >> B >> C;
    cout << ( C / A ) * B << "\n";
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] a = new int[N];
		for(int i = 0;i < N;++i)
			a[i] = sc.nextInt()-1;
		sc.close();
		
		int ans = 0;
		int current = 0;
		while(ans < N) {
			ans++;
			if(a[current] == 1)
				break;
			else
				current = a[current];
		}
		if(ans < N)
			System.out.println(ans);
		else
			System.out.println("-1");
	}
}


Measured memory_bytes: 50876
<?php /*atcoder.php*/

$at = new Atcoder();
$at->main();
unset($at);

class Atcoder{
	private function lineIn(){
		$buf = fgets(STDIN);
		return $this->killNewLine($buf);
	}
	private function killNewLine($buf = null){
		$buf = str_replace("\r\n", "", $buf);
		$buf = str_replace("\n", "", $buf);
		$buf = str_replace("\r", "", $buf);
		return $buf;
	}

	public function main(){
		$s = $this->lineIn();
		
		if("A" !== $s[0]){
			echo "WA\n";
			return true;
		}

		$size = count(str_split($s));
		$cc = 0;
		$buf = $s[1];

		for($i = 2; $i < ($size - 1); $i++){
			if("C" === $s[$i]){
				$cc++;
			}else{
				$buf .= $s[$i];
			}
		}
		if(1 !== $cc){
			echo "WA\n";
			return true;
		}
		$buf .= $s[($size - 1)];

		if(ctype_lower($buf)){
			echo "AC\n";
		}else{
			echo "WA\n";
		}
	}
}
?>


Measured memory_bytes: 4732
#include<bits/stdc++.h>
using namespace std;
string t,p;
char c;
int i,j,k,l,x;
main(){
  for(cin>>t>>p;i<t.size();++i){
    if(t[i]==c&&t[i]!=p[j]){
      c='0';
      break;
    }
    if(t[i]==p[j])++j,c=t[i];
  }
  x=c-'0'?1:0;
  c='0';
  for(reverse(t.begin(),t.end()),reverse(p.begin(),p.end());k<t.size();++k){
    if(t[k]==c&&t[k]!=p[l]){
      c='0';
      break;
    }
    if(t[k]==p[l])++l,c=t[k];
  }
  x&=c-'0'?1:0;
  cout<<(x&&j==p.size()?"yes\n":"no\n");
}

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

const int N = 200005;

int n, d;
int a[N];

int solve() {
  scanf("%d %d", &n, &d);
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    int x, y;
    scanf("%d %d", &x, &y);
    if (1LL * x * x + 1LL * y * y <= 1LL * d * d) ++ans;
  }

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

int main() {
  int t = 1;
  // scanf("%d", &t);
  while (t--) solve();
  return 0;
}


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

#define mid ((left + right) >> 1)

const int N = 3e5 + 10;
const int LOG_N = 20;

struct Node {
  int l, r;
  int v;
} t[N * LOG_N * LOG_N];

int n, m;
int root[N], ord[N], sz;
vector<int> Q[N];

int Insert(int rt, int left, int right, int u) {
  int id = ++sz;
  t[id] = t[rt], t[id].v += 1;
  if(left == right) return id;
  if (mid >= u) t[id].l = Insert(t[id].l, left, mid, u);
  else if (mid < u) t[id].r = Insert(t[id].r, mid + 1, right, u);
  return id;
}

int Query(int rt, int left, int right, int l, int r) {
  if(!rt || l > r) return 0;
  if(left == l && r == right) return t[rt].v;
  if(mid >= r) return Query(t[rt].l, left, mid, l, r);
  else if(mid < l) return Query(t[rt].r, mid + 1, right, l, r);
  else return Query(t[rt].l, left, mid, l, mid) + Query(t[rt].r, mid + 1, right, mid + 1, r);
}

int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    int l, r;
    scanf("%d%d", &l, &r);
    Q[r].push_back(l);
  }
  for (int i = 1; i <= m; i++) {
    sort(Q[i].begin(), Q[i].end());
  }
  int cnt = 1, nxt = 0;
  for (int i = 1; i <= m; i++) {
    for (int j = 0; j < Q[i].size(); j++) {
      root[cnt] = Insert(root[cnt - 1], 1, m, Q[i][j]);
      cnt++;
    }
    ord[i] = cnt - 1;
  }
  for (int i = 1; i <= m; i++) {
    int ans = 0;
    for (int j = i; j <= m; j += i) {
      ans += Query(root[ord[min(m, j + i - 1)]], 1, m, 1, j) - Query(root[ord[j - 1]], 1, m, 1, j - 1);
    }
    printf("%d\n", ans);
  }
  return 0;
}

Measured memory_bytes: 77824
#include<bits/stdc++.h>
#define F(i,a,b) for(int i=(a);i<=(b);++i)
#define F2(i,a,b) for(int i=(a);i<(b);++i)
#define dF(i,a,b) for(int i=(a);i>=(b);--i)
#define dF2(i,a,b) for(int i=(a);i>(b);--i)
#define dF3(i,a,b) for(int i=(a)-1;i>=(b);--i)
using namespace std;typedef long long ll;typedef double ld;int INF=0x3f3f3f3f;int INF2=0x7fffffff;ll LNF=0x3f3f3f3f3f3f3f3f;ll LNF2=0x7fffffffffffffff;

#define M 1000000007
int n,C;
int a[401],b[401];
int c[401][401],f[401][401];
void P(int&x,ll y){x=(x+y)%M;}

int main(){
	scanf("%d%d",&n,&C);
	F(i,1,n) scanf("%d",a+i);
	F(i,1,n) scanf("%d",b+i);
	f[0][0]=1;
	F(i,1,n){
		F(k,a[i],b[i]){
			int K=1;
			F(j,0,C){
				P(c[i][j],K);
				K=(ll)K*k%M;
			}
		}
		F(j,0,C){
			F(k,0,j){
				P(f[i][j],(ll)c[i][k]*f[i-1][j-k]);
			}
		}
	} printf("%d",f[n][C]);
	return 0;
}

Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
#define rep(i,c) for(int i=0;i<c;++i)
int main(){
 int a,b;
 cin >> a>>b;
 int count = 0;
 while(a-b>0){
     a-=b;
     count ++;
 }
 cout << count+1 << endl;
return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = long long;
using std::cout;
using std::endl;
using std::cin;

template<typename T>
std::vector<T> make_v(size_t a){return std::vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return std::vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

int main() {
	std::string s; cin >> s;
	
	int count = 0;
	for(auto c: s) count += (c == 'o');
	
	if(count + (15 - (int)s.size()) >= 8) printf("YES\n");
	else printf("NO\n");
	return 0;
}


Measured memory_bytes: 256
#include<algorithm>
#include<iostream>
#include<utility>
#include<vector>
using namespace std;
typedef long long lint;
typedef vector<int>vi;
typedef pair<int,int>pii;
#define rep(i,n)for(int i=0;i<(int)(n);++i)

const int DEBUG=0;

const int A=18;

bool inc(vi &a,int lim){
  int i=0;
  while(i<(int)a.size()){
    a[i]++;
    if(a[i]<lim)return true;
    a[i]-=lim;
    i++;
  }
  return false;
}

lint p10[A];

bool match(lint n,lint pat,lint msk){
  while(msk>0){
    if(msk%10!=0){
      if(n%10!=pat%10)return false;
    }
    msk/=10;
    n/=10;
    pat/=10;
  }
  return true;
}

lint calc(lint n,const vi &t){
  int m=t.size();
  rep(i,m-1){
    if(t[i]+4>t[i+1])return 0;
  }
  if(t[m-1]>A-4)return 0;
  lint pat=0,msk=0;
  rep(i,m){
    pat+=5103*p10[t[i]];
    msk+=1101*p10[t[i]];
  }
  lint ans=0;
  lint cur=1;
  n++;
  while(n>0){
    if(msk%10==0){
      if(match(n/10,pat/10,msk/10))ans+=cur*(n%10);
      n/=10;
      pat/=10;
      msk/=10;
      cur*=10;
      continue;
    }
    if(match(n/10,pat/10,msk/10)&&n%10>pat%10)ans+=cur;
    n/=10;
    pat/=10;
    msk/=10;
  }
  if(DEBUG&&ans!=0){
    cerr<<"t=";
    rep(i,m)cerr<<" "<<t[i];
    cerr<<endl;
    cerr<<"ret="<<ans<<endl;
  }
  return ans;
}

int main(){
  rep(i,A){
    if(i==0)p10[i]=1;
    else p10[i]=10*p10[i-1];
  }
  lint n;
  cin>>n;
  lint ans=0;
  rep(i,5){
    if(i==0)continue;
    vi t(i,0);
    do{
      ans+=(i%2==0?-1:1)*calc(n,t);
    }while(inc(t,A));
  }
  cout<<ans<<endl;
}



Measured memory_bytes: 3104
require 'prime'
while n = gets
	n = n.to_i
	l,h = Enumerator.new {|y|
		t = 0
		Prime.each {|prim|
			t = prim if n> prim
			if prim > n
				y << t
				y << prim
			end
		}
	}.take(2).to_a
	printf("%d %d",l,h)
	puts
end

Measured memory_bytes: 6268
package main

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

var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Split(bufio.ScanWords)
	sc.Buffer([]byte{}, math.MaxInt64)
}

func readString() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	s := readString()
	fmt.Println(strings.Repeat("x", len(s)))
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)
#define VL vector<ll>
#define INF 100000000

int main(){
    ll A,B;
    cin>>A>>B;
    if(B%A==0)cout<<(A+B)<<endl;
    if(B%A!=0)cout<<(B-A)<<endl;
}

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

using namespace std; 

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef pair<LL, LL> PLL;
typedef vector<PLL> VPLL;
typedef priority_queue<LL> PQ_DESC;
typedef priority_queue<LL, VL, greater<LL>> PQ_ASC;
typedef priority_queue<PII> PQ_DESC_PII;
typedef priority_queue<PII, vector<PII>, greater<PII>> PQ_ASC_PII;
typedef priority_queue<VL> PQ_DESC_VL;
typedef priority_queue<VL, vector<VL>, greater<VL>> PQ_ASC_VL;
typedef priority_queue<PLL> PQ_DESC_PLL;
typedef priority_queue<PLL, vector<PLL>, greater<PLL>> PQ_ASC_PLL;

#define ALL(c) (c).begin(),(c).end()
#define PB push_back
#define MP make_pair
#define SORT_ASC(c) sort(ALL(c))
//#define SORT_DESC(c) sort(ALL(c), greater<typeof(*((c).begin()))>())
#define SORT_DESC(c) sort((c).rbegin(),(c).rend())
#define REV(c) reverse((c).begin(), (c).end())
#define SIZE(a) int((a).size())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ROF(i,a,b) for(int i=(b-1);i>=(a);--i)
#define REP(i,n) FOR(i,0,n)
#define PER(i,n) ROF(i,0,n)

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int LARGE_INT = 1e9+100;
const int INF = 2e9+100;
const LL INF_LL = (LL)INF*(LL)INF;
const int MOD = 1e9+7;

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

LL modpow(LL a, LL n) {
    LL res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}

void Main()
{
    int n,m;cin>>n>>m;
    cout<<(n-1)*(m-1)<<endl;
    
	return;
}

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

Measured memory_bytes: 3580
using System;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            string s = Console.ReadLine();
            double r = double.Parse(s);
            double p = 3.141592653589;
            Console.WriteLine(r * r * p + " " + 2 * r * p);
        }
    }
}

Measured memory_bytes: 9220
import sys
  
IDX_TBL = {1:[2,3,5,4], 2:[3,1,4,6], 3:[1,2,6,5],4:[1,5,6,2], 5:[1,3,6,4], 6:[2,4,5,3]}
l1=["_"] + raw_input().split(" ")
l2=["_"] + raw_input().split(" ")
if l1[1] in l2:
    idx_list = [i for i,x in enumerate(l2) if x==l1[1]]
    for idx in idx_list:
        nums1 = "".join([l1[i] for i in IDX_TBL[1]])
        nums2 = "".join([l2[i] for i in IDX_TBL[idx]])
        if nums2 in nums1*2:
            print "Yes"
            sys.exit(0)
print "No"


Measured memory_bytes: 4692
#include <bits/stdc++.h>	
#define pb push_back
#define MAX 200005
typedef long long ll;
const int inf = 2e9;
using namespace std;


//char S[MAX];
//for(int i=0; i<n; i++) scanf("%d",&A[i]);

int n,k;
int A[MAX];


int main(){
	
	scanf("%d%d",&n,&k);
	int minimo = 0;
	for (int i = 0; i < n; ++i)
	{
		int x; scanf("%d",&x);
		minimo+=min(abs(x)*2,abs(x-k)*2);
	}

	printf("%d\n", minimo);

	return 0;
}	

Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int h,w,n,a[10000],i,j,k=0,t;
  scanf("%d%d%d",&h,&w,&n);
  for(i=1;i<=n;i++){scanf("%d",&t);for(j=0;j<t;j++){a[k]=i;k++;}}
  for(i=0;i<h;i++){for(j=0;j<w;j++)printf("%d ",i%2?a[w*(i+1)-j-1]:a[w*i+j]);printf("\n");}
}


Measured memory_bytes: 1768
def W(d):
    #d[i][j]: iからjへの最短距離
    for k in range(n):
        for i in range(n):
            for j in range(n):
                d[i][j] = min(d[i][j],d[i][k] + d[k][j])
    return d

##############################
n,w,l= map(int,input().split()) #n:頂点数　w:辺の数

d = [[10**14]*n for i in range(n)] 
#d[u][v] : 辺uvのコスト(存在しないときはinf)
for i in range(w):
    x,y,z = map(int,input().split())
    if z>l:
      continue
    x=x-1
    y=y-1
    d[x][y] = z
    d[y][x] = z
for i in range(n):
    d[i][i] = 0 #自身のところに行くコストは０
D=W(d)
G=[[10**4]*n for i in range(n)]
for i in range(n):
  for j in range(n):
    if D[i][j]>l:
      continue
    G[i][j]=1
WW=W(G)
for i in range(int(input())):
  a,b=map(int,input().split())
  a=a-1
  b=b-1
  if WW[a][b]>=10**4:
    print(-1)
  else:
    print(WW[a][b]-1)

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

int main(){
    long long a,b,v,w,t;
    cin>>a>>v>>b>>w>>t;

    if(b-a==0) cout << "YES" << endl;
    else if(v-w>0 && abs(b-a)<=abs(t*(v-w))) cout << "YES" << endl;
    else cout << "NO" << endl;

    return 0;
}

Measured memory_bytes: 3600
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#define _USE_MATH_DEFINES
#include <cmath>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <iomanip>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007;
// const int MOD = 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
// const int dy[] = {1, 1, 0, -1, -1, -1, 0, 1},
//           dx[] = {0, -1, -1, -1, 0, 1, 1, 1};

struct IOSetup {
  IOSetup() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    cerr << fixed << setprecision(10);
  }
} iosetup;
/*-------------------------------------------------*/
int main() {
  int n; long long k; cin >> n >> k;
  vector<long long> a(n);
  REP(i, n) {
    cin >> a[i];
    a[i] %= k;
  }
  vector<long long> sum(n);
  sum[0] = a[0];
  FOR(i, 1, n) sum[i] = (sum[i - 1] + a[i]) % k;
  REP(i, n) {
    (sum[i] -= i + 1) %= k;
    if (sum[i] < 0) sum[i] += k;
  }
  // REP(i, n) cout << sum[i] << ' ';
  map<long long, int> mp;
  for (int i = 0; i < k - 2 && i < n; ++i) ++mp[sum[i]];
  long long ans = 0, now = 0;
  REP(i, n) {
    if (i + k - 2 < n) ++mp[sum[i + k - 2]];
    ans += mp[now];
    // cout << ans << ' ' << now << '\n';
    --mp[sum[i]];
    (now += a[i] - 1) %= k;
    if (now < 0) now += k;
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 15872
#include<bits/stdc++.h>
#define N 500001
using namespace std;
#define int long long
int n;
int X[N]={};
int ans=0;
void update(int a,int i){
  int len = X[n-1];
  int la = X[a]-X[i];
  int bu = upper_bound(X+a,X+3*n,X[a]+(len-la)/2)-X;
  int bl = bu - 1;
  int lbu = X[bu] - X[a];
  int lbl = X[bl] - X[a];
  int lcu = len-la-lbu;
  int lcl = len-la-lbl;
  ans = max(ans,min(la,min(lbu,lcu)));
  ans = max(ans,min(la,min(lbl,lcl)));
}

signed main(){

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

  X[0] = A[0];
  for(int i=1;i<3*n;i++) X[i] += A[i%n] + X[i-1];
   
int len = X[n-1];
  for(int i=0;i<=n;i++){
    int au  = upper_bound(X+i,X+3*n,X[i]+len/3)-X-1;
    int al = au - 1;
    update(au,i);
    update(al,i);
  }
  cout<< ans << endl;
  return 0;
}

Measured memory_bytes: 6208
S = input()
ans = "Yes"
for i, c in enumerate(S):
  if (i + 1) % 2 == 1:
    if not c in ["R", "U", "D"]:
      ans = "No"
      break
  if (i + 1) % 2 == 0:
    if not c in ["L", "U", "D"]:
      ans = "No"
      break
print(ans)

Measured memory_bytes: 3060
package main

import "fmt"

func main() {
	var n, m int
	fmt.Scan(&n, &m)

	b := make(map[int]bool, m)
	var a int
	for i := 0; i < m; i++ {
		fmt.Scan(&a)
		b[a] = true
	}

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

	mod := int(1e9 + 7)
	for i := 0; i <= n; i++ {
		if !b[i+1] {
			dp[i+1] = (dp[i+1] + dp[i]) % mod
		}
		if !b[i+2] {
			dp[i+2] = (dp[i+2] + dp[i]) % mod
		}
	}

	fmt.Println(dp[n])
}


Measured memory_bytes: 5504
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define bit(n) (1<<(n))
#define ii(x) int x; cin >> (x)
#define ii2(x, y) int x, y; cin >> (x) >> (y)
#define ii3(x, y, z) int x, y, z; cin >> (x) >> (y) >> (z)
#define yn(x, ok, ng) cout << ((x)?(ok):(ng)) << endl
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1;} return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1;} return 0;}
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}
int const INF = 1001001001;


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

ll n,k; cin >> n >> k;

if(k % 2 == 1) {
    ll a = n/k;
    cout << a*a*a << endl;
}
else {
    ll a = n/k;
    ll b = (n + (k/2)) / k;
    cout << a*a*a + b*b*b << endl;
}

return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 1002
#define i197 1000000007

using namespace std;

typedef long long ll;
typedef pair<int,ll> Pil;
typedef pair<int,int> Pi;
typedef pair<double,Pi> Pdi;
typedef pair<ll,int>Pli;
typedef pair<ll,ll> Pl;
typedef pair<Pil,ll> P2;
const ll INF=1000000000000000001;
const int inf=1000000000;
//struct edge{int to,cost;};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};

int main(){

	int n,m;
	int d[31]={};
	int k,a;
	int total=0;

	cin>>n>>m;
	rep(i,n){
		cin>>k;
		rep(j,k){
			cin>>a;
			d[a]++;
		}
	}
	rep(i,m+1){
		if(d[i]==n)total++;
	}
	cout<<total<<endl;
	return 0;
}


Measured memory_bytes: 256
/* Mashiro Shiina best girl */
#include<bits/stdc++.h>
using namespace std;

#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<ll, ll> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
	
	int n; cin >> n;
	int a[n];
	for(int i=0;i<n;i++){
		cin >> a[i];
	}
	sort(a,a+n);
	for(int i=0;i<n-1;i++){
		if(a[i] == a[i+1]){
			cout << "NO" << endl; return 0;
		}
	}
	cout << "YES" << endl;
	return 0;
}


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

int main()
{
    int n, x, t;
    cin >> n >> x >> t;
    int a = 0;
    if (n % x == 0)
        a = n / x;
    else
        a = n / x + 1;
    cout << a * t << endl;
    return 0;
}

Measured memory_bytes: 3588
#include<iostream>
#include<algorithm>
#include<vector>
#include<climits>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)

const int MAX=16;
int p[MAX];
int c[MAX];

int counter(int x){
  if (x==0)return 0;
  return counter(x>>1)+(x&1);
}

void solve(){
  int D,G;
  cin>>D>>G;
  int N=0;
  for(int i=1;i<D+1;i++){
    cin>>p[i]>>c[i];
    N+=p[i];
  }
  int score,cnt;
  int max_i=-1;
  int min_cnt=N;
  for(int bits=0;bits<(1<<D);bits++){
    score=0;
    cnt=0;
    for(int i=1;i<D+1;i++){
      if ((bits>>(i-1))&1){
        score+=100*i*p[i]+c[i];
        cnt+=p[i];
      }else{
        max_i=i;
      }
    }
    if (score>=G && cnt<min_cnt){
      min_cnt=cnt;
      continue;
    }
    for(int i=1;i<p[max_i];i++){
      score+=100*max_i;
      cnt++;
      if (score>=G && cnt<min_cnt){
        min_cnt=cnt;
        break;
      }
    }
  }
  cout<<min_cnt<<endl;
  return;
}
  
int main(){
  solve();
  return 0;
}
    

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

int main() {
  int N;
  cin >> N;
  
  int i;
  string S;
  
  for (i=0; i<N; i++) {
    cin >> S;
    if (S=="Y"){
      cout << "Four" << endl;
      break;
    }
    else if (i==N-1)
      cout << "Three" << endl;
  }
}


Measured memory_bytes: 256
n = gets.to_i
a = gets.split.map(&:to_i)
count = 0
(1..n).each do |i|
  unless a[i-1] == i
    count += 1
  end
end

if count == 0
  puts "YES"
  exit
end

if count == 2
  puts "YES"
  exit
end

puts "NO"

Measured memory_bytes: 1788
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<climits>
 
using namespace std;
 
using ll = long long;
 
int main() {
    ll x;
    cin >> x;
    int count=0;
    for (ll val=100; val<x; val=1.01*val) {
        ++count;
    }
    cout << count << endl;
}

Measured memory_bytes: 3640
#include "iostream"
#include "algorithm"
#include "vector"
#include "string"
#include "cmath"
typedef long long ll;
using namespace std;

int main(int argc, char const *argv[]) {
  ll NN;

  std::cin >> NN;

  ll A[NN], B[NN];

  for (size_t i = 0; i < NN; i++) {
    std::cin >> A[i]>>B[i];
  }

  std::vector<pair<ll, ll>> bi(NN);


  for (ll i = 0; i < NN; i++) {
    bi[i] = make_pair(-(A[i] + B[i]), i);
  }
  // for (size_t i = 0; i < NN; i++) {
  //   std::cout << bi[i].first << '\n';
  // }

  //
  sort(bi.begin(), bi.end());

  // for (size_t i = 0; i < NN; i++) {
  //   std::cout << bi[i].first << '\n';
  // }

  ll takahashi_ans = 0, aoki_ans = 0;
  for (ll i = 0; i < NN; i++) {
    if (i % 2 == 0) {
      takahashi_ans += A[bi[i].second];
    }else{
      aoki_ans += B[bi[i].second];
    }
  }

  std::cout << takahashi_ans - aoki_ans << '\n';

  return 0;
}


Measured memory_bytes: 3328
#include<stdio.h>
#include <string.h>
#include<iostream>
using namespace std;

int main()
{
    long long A, B, C, K;
    int sum = 0;
    int temp;
    string str;


    cin >> A >> B >> C >> K;

    if (A >= K) {
        cout << K << endl;
    }
    else if (A + B >= K) {
        cout << A << endl;
    } else {
        cout << A - (K - A - B) << endl;
    }

    return 0;
}

Measured memory_bytes: 3624
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;

constexpr long long int MOD = 1000000007;
//constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
//constexpr long long int MOD = 998244353;
constexpr double EPS = 1e-9;

//int N, M, K, H, W, L, R;
long long int N, M, K, H, W, L, R;

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

	long double a, b, c, d;
	cin >> a >> b >> c >> d;

	c += d / 60;
	c /= 12;
	d /= 60;
	c *= 2 * 3.141592653589793238;
	d *= 2 * 3.141592653589793238;
	long double cx, cy, dx, dy;
	cx = a * cos(c), cy = a * sin(c), dx = b * cos(d), dy = b * sin(d);
	cout << setprecision(20) << sqrt((cx - dx)*(cx - dx) + (cy - dy)*(cy - dy)) << endl;
}

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

int main() {
  long long N, H=1;
  cin >> N;
  for(int i=1; i<pow(N,0.5)+1; i++) {
    if(N%i==0) {
      H=i;
    }
  }
  cout << H+N/H-2 << endl;
}

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

#define int             long long
#define FOR( i, m, n )  for( int (i) = (m); (i) < (n); (i)++ )
#define REP( i, n )     FOR( i, 0, n )
#define REPR( i, m )    for( int (i) = (m); (i) >= 0; (i)-- )
#define REPONE( i, n )  FOR( i, 1, n + 1 )
#define ALL( a )        (a).begin(), (a).end()
#define MP              make_pair

using namespace std;
using P = pair<int, int>;

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

const int INF = 1e18;
const int MOD = 1e9 + 7;

int dp[10001];

signed main(){
    int N, W; cin >> N >> W;
    vector<int> v( N ), w( N );
    REP( i, N ) cin >> v[i] >> w[i];

    fill( dp, dp + 10001, INF );
    dp[0] = 0;

    REP( i, N ){
        for( int j = 10000; j >= v[i]; j-- ){
            chmin( dp[j], dp[j - v[i]] + w[i] );
        }
    }

    int ans = 0;
    REP( i, 10001 ){
        if( dp[i] <= W ) chmax( ans, i );
    }

    cout << ans << endl;
}



Measured memory_bytes: 3184
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define INF 1000000000
#define mod 1000000007
using ll=long long;
const ll LINF=1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
// ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return true;}return false;}

int n;
vector<int> g[1001];
int x[1001];
set<int> st[1001];

pair<int,int> dfs(int pre,int now){
    set<pair<int,int>> res;
    int dp[5001];
    rep(i,5001)dp[i]=INF;dp[0]=0;
    for(auto to:g[now])if(pre!=to){
        auto p=dfs(now,to);
        
        int dp_new[5001];
        rep(i,5001) dp_new[i]=INF;
        for(int i=x[now];i>=0;i--){
            if(i+p.first<=x[now]) chmin(dp_new[i+p.first],dp[i]+p.second);
            if(i+p.second<=x[now])chmin(dp_new[i+p.second],dp[i]+p.first);
        }
        swap(dp,dp_new);
    }

    int k=INF;
    rep(i,x[now]+1){
        chmin(k,dp[i]);
    }
    // cout<<now<<" : "<<k<<" "<<x[now]<<endl;
    // cout<<"     dp: ";
    // rep(i,x[now]+1){
    //     if(dp[i]>=INF) cout<<"I ";
    //     else cout<<dp[i]<<" ";
    // }cout<<endl;
    return make_pair(x[now],k);
}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    
    cin>>n;
    for(int u=1;u<n;u++){
        int v;cin>>v;v--;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    rep(i,n) cin>>x[i];
    auto ans=dfs(-1,0);
    if(ans.first<INF and ans.second<INF) cout<<"POSSIBLE\n";
    else cout<<"IMPOSSIBLE\n";
    return 0;
}


Measured memory_bytes: 17280
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
    int n;
    cin >> n;
    vector<int> dp(100001);
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        dp[a]++;
    }
    int ans = 0;
    for (int i = 0; i < 99999; i++) {
        ans = max(ans, dp[i]+dp[i+1]+dp[i+2]);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 640
from collections import Counter
n=int(input())
a = list(map(int, input().split()))
q=int(input())
b = [list(map(int, input().split())) for i in range(q)]
vi=Counter(a)
s=sum(a)
for i in b:
    v=vi[i[0]]
    d=(i[1]-i[0])*v
    s+=d
    vi[i[0]]=0
    vi[i[1]]+=v
    print(s)


Measured memory_bytes: 40244
#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <bitset>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
#include <functional>
#include <cassert>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
#define ALL(v) v.begin(),v.end()
template < class T > inline bool chmax(T& a, T b) {if (a < b) { a=b; return true; } return false; }
template < class T > inline bool chmin(T& a, T b) {if (a > b) { a=b; return true; } return false; }
#define DEBUG_VLL(vec) REP(sz, vec.size()) std::cerr<<vec[sz]<<(sz==vec.size()-1?'\n':' ');

const long long MOD = 1000000007;
const long long HIGHINF = (long long)1e18;
const int INF = (int)1e9;

struct Edge {
    ll to, id;
    Edge(ll to, ll id) : to(to), id(id) {}
};

ll n;
V< V< Edge > > edges;
vll path;

bool dfs(ll fr, ll to, ll p) {
    if (fr == to) return true;
    for (Edge e: edges[fr]) {
        if (e.to == p) continue;
        if (dfs(e.to, to, fr)) {
            path.emplace_back(e.id);
            return true;
        }
    }
    return false;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    edges.resize(n);
    for (ll i = 0; i < n - 1; i++) {
        ll a, b; cin >> a >> b;
        a--, b--;
        edges[a].emplace_back(Edge(b, i));
        edges[b].emplace_back(Edge(a, i));
    }

    ll m; cin >> m;
    vll cs(m, 0);
    for (ll i = 0; i < m; i++) {
        ll u, v; cin >> u >> v;
        u--, v--;
        path.clear();
        dfs(u, v, -1);
        for (ll j = 0; j < path.size(); j++) cs[i] += (1LL << path[j]);
    }

    ll ans = 0;
    for (ll state = 1; state < (1 << m); state++) {
        ll tmp = 0;
        for (ll i = 0; i < m; i++) if ((state >> i) & 1) tmp |= cs[i];
        ll wedge = __builtin_popcountll(tmp);
        if (__builtin_popcountll(state) & 1) ans += (1LL << (n - 1 - wedge));
        else ans -= (1LL << (n - 1 - wedge));
    }
    cout << (1LL << (n - 1)) - ans << '\n';
    return 0;
}


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

int64_t Q=1000000007;
int64_t si(int64_t x,int64_t y){
   int64_t A=x,B=y,C=1;//A,Bを入れる
  for(int64_t i=1;i<=B;i++){
    C=(C*i)%Q;
  }
  int64_t N=Q-2,a=1,b=0,c=1;
  while(N>0){
    a*=2;
    if(N%a!=0){
      N-=a/2;
      int64_t d=C;
      for(int j=0;j<b;j++){
        d=(d*d)%Q;
      }
      c=(c*d)%Q;
    }
    b++;
  }
  C=c;
  for(int i=0;i<B;i++){
    C=(C*(A-i))%Q;
  }//答はC
  return C;
}
vector<int64_t> J(2000001,1);
int64_t S(int64_t a,int64_t b){
  int A=(si(a+b-1,a)+si(a+b-1,b)-1+Q)%Q;
  return A;
}

int main(){
  for(int i=1;i<=2000000;i++){
    J[i]=J[i-1]*2;
    J[i]%=Q;
  }
  int64_t o,p,q,r;
  cin>>o>>p>>q>>r;
  q++,r++;
  int64_t Z=(2*Q+S(q,r)+S(o,p)-S(o,r)-S(p,q))%Q;
  cout<<Z<<endl;
}

Measured memory_bytes: 18620
#include<cstdio>
#include<algorithm>
#include <functional>
#define MAX 200005
using namespace std;
 
int main(){
  int n, k, a[MAX], b[MAX], i, j = 0, l = 0, ans;
  scanf("%d%d", &n, &k);
  for(i = 0; i < n; i++) scanf("%d", &a[i]);
  sort(a, a+n);
  b[0] = 1;
  for(i = 1; i < n; i++){
    if(a[i-1] != a[i]){
      j++;
      b[j] = 1;
    }else b[j]++;
  }
  sort(b, b+j+1, greater<int>());
  for(i = 0; i < k && i <= j; i++)  l += b[i];
  ans = n - l;
  printf("%d\n", ans);
}


Measured memory_bytes: 1664
total = 0
from decimal import Decimal, ROUND_HALF_UP
N = int(input())
A = list(map(int,input().split(" ")))
sum_number = sum(A) / N
sum_number = Decimal(str(sum_number))
sum_number = sum_number.quantize(Decimal('0'), rounding=ROUND_HALF_UP)
for i in range(N):
    total += abs(A[i] - sum_number) ** 2
print(total)

Measured memory_bytes: 5588
#include<bits/stdc++.h>
#define int long long
#define rep(i,a,b) for(int i=a;i<b;i+=1)
#define reps(i,a,b) for(int i=a;i>=b;i-=1)
#define vi vector<int>
#define vvi vector<vector<int>>
#define pb push_back
#define pi pair<int, int>
#define mp make_pair
#define ff first
#define ss second
#define in1(x) int x; cin>>x;
#define in2(x, y) int x, y; cin>>x>>y;
#define in3(x, y, z) int x, y, z; cin>>x>>y>>z;
#define in4(x, y, z, w) int x, y, z, w; cin>>x>>y>>z>>w;
#define mi unordered_map<int,int>
#define mem(x) memset(x, 0, sizeof(x))
#define IOS ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
#define pi 3.141592653589793238462643
using namespace std;
long double min(long double x, long double y){  
    return (x < y)? x: y;  
}  
  
long double calcAngle(double h, double m)  
{  
    // validate the input  
    if (h <0 || m < 0 || h >12 || m > 60)  
        printf("Wrong input");  
  
    if (h == 12) h = 0;  
    if (m == 60) m = 0;  
    long double hour_angle = 0.5 * (h * 60 + m);  
    long double minute_angle = 6 * m;  
  
    // Find the difference between two angles  
    long double angle = abs(hour_angle - minute_angle);  
  
    // Return the smaller angle of two possible angles  
    angle = min(360 - angle, angle);  
  
    return angle;  
}  

int32_t main(void){
	IOS;
	long double a, b, h, m;
	cin>>a>>b>>h>>m;
	long double ans;
	long double angle = calcAngle(h, m);
	angle *= (pi/180);
	ans = sqrt(a*a + b*b - 2*a*b*cos(angle));
	cout<<fixed<<setprecision(10)<<ans<<endl;
}

Measured memory_bytes: 4188
while True:
  sum = []
  count = 0
  n, x = map(int, input().split())
  if n == 0 and x == 0:
    break
  for i in range(1, n-1):
    for j in range(i+1, n):
      for k in range(j+1, n+1):
        num = i + j + k
        sum.append(num)
  for i in range(len(sum)):
    if x == sum[i]:
      count += 1
  print(count)



Measured memory_bytes: 6860
#pragma GCC optimize("Ofast")
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"

using namespace std;

using u8 = uint8_t;
using u16 = uint16_t;
using u32 = uint32_t;
using u64 = uint64_t;
using i8 = int8_t;
using i16 = int16_t;
using i32 = int32_t;
using i64 = int64_t;

using vi = vector<int>;

constexpr char newl = '\n';
constexpr double eps = 1e-10;

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define F0R(i,b) FOR(i,0,b)
#define RFO(i,a,b) for (int i = ((b)-1); i >=(a); i--)
#define RF0(i,b) RFO(i,0,b)
#define fi first
#define se second
#define show(x) cout << #x << " = " << x << '\n';
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define sz(x) (int)(x).size()
#define YesNo {cout<<"Yes";}else{cout<<"No";}
#define YESNO {cout<<"YES";}else{cout<<"NO";}
#define v(T) vector<T>

template<typename T1, typename T2> inline void chmin(T1& a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
template<class T> void Print(vector<T> v) {
  F0R(i, v.size()) {
    cout << v[i] << ' ';
  }
  cout << newl;
}
template<class T> bool lcmp(const pair<T, T>& l, const pair<T, T>& r) {
  return l.first < r.first;
}
template<class T> istream& operator>>(istream& i, v(T)& v) {
  F0R(j, sz(v)) i >> v[j];
  return i;
}

#if 1


// INSERT ABOVE HERE
signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  string s;
  cin >> s;

  int r = 999;
  F0R(i, s.size() - 2) {
    auto b = s.substr(i, 3);
    chmin(r, abs(753 - atoi(b.c_str())));
  }
  cout << r;
}
#endif


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

int main() {
  int s;
  cin >> s;
  
  int hour, minute, second;
  hour = s/3600;
  s = s%3600;
  minute = s/60;
  second = s%60;
  
  cout << hour << ":" << minute << ":" << second << endl;
}


Measured memory_bytes: 3108
import java.util.Arrays;
import java.util.Scanner;

public class Main{
    void solve(){
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int[] s = new int[n];
        int sum = 0;
        for(int i = 0; i < n; i++){
            s[i] = in.nextInt();
            sum += s[i];
        }
        
        if(sum % 10 != 0){
            System.out.println(sum);
            return;
        }else{
            Arrays.sort(s);
            int i = 0;
            while(sum%10==0 && i < n){
                if(s[i]%10 != 0){
                    sum -= s[i];
                }
                i++;
            }
            if(i == n){
                sum = 0;
            }
        }
        System.out.println(sum);
    }
    
    public static void main(String[] args){
        new Main().solve();
    }
}

Measured memory_bytes: 25556
#ifdef LOCAL_BUILD
#include "pch.h"
#define DLOG(msg) cout << "#" << __LINE__ << ":" << msg << endl;
#define DLOG_V(var) \
  cout << "#" << __LINE__ << ":" << #var << " : " << var << endl;
#else
#include <bits/stdc++.h>
#define DLOG(msg)
#define DLOG_V(var)
#endif
using namespace std;

struct Heap {
  Heap() : buf_(1, 0) {}

  void insert(int v) {
    buf_.push_back(v);
    DLOG_V(buf_.size());
    bool modified = true;
    for (auto i = (buf_.size() - 1) / 2; modified && i >= 1; i /= 2) {
      modified = false;
      heapify(i, modified);
    }
  }

  int extractMax() {
    if (buf_.size() < 2) {
      throw std::logic_error("heap is empty");
    }
    auto v = buf_[1];
    swap(buf_[1], buf_.back());
    buf_.resize(buf_.size() - 1);
    bool modified = false;
    heapify(1, modified);
    return v;
  }

 private:
  void heapify(size_t i, bool& modified) {
    auto l = i * 2;
    auto r = i * 2 + 1;
    auto max_ = i;
    if (l < buf_.size() && buf_[l] > buf_[max_])
      max_ = l;
    if (r < buf_.size() && buf_[r] > buf_[max_])
      max_ = r;
    if (max_ == i) {
      return;
    }
    modified = true;
    swap(buf_[max_], buf_[i]);
    return heapify(max_, modified);
  }

  vector<int> buf_;
};

int main() {
  Heap heap;
  string buf;
  int v;
  for (;;) {
    cin >> buf;
    if (!buf.compare("end")) {
      break;
    } else if (!buf.compare("insert")) {
      cin >> v;
      heap.insert(v);
    } else if (!buf.compare("extract")) {
      cout << heap.extractMax() << endl;
    }
  }
}

Measured memory_bytes: 6996
import java.util.Scanner;
import java.util.HashMap;
 
class Main {
	public static void main(String[] args) {
 
	    Scanner sc = new Scanner(System.in);
	    int N = sc.nextInt();
	    HashMap<Integer, Integer> map = new HashMap<>();
	    for (int i = 1; i < N; i++) {
	      int temp = sc.nextInt();
	      Integer count = map.get(temp);
	      if (count == null) { count = 1;} else { count++;}
	      
	      map.put(temp, count);
	    }
	    
	    int ans = 0;
	    for (int j = 1; j <= N; j++) {
	      if (map.get(j) == null) { ans = 0;} else { ans = map.get(j);}
	      System.out.println(ans);
	    }
	  }
}

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

#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif

const int inf=1e9;
const int64_t inf64=1e18;
const double eps=1e-9;

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
    	os << v << ",";
    }
    os << "]";
    return os;
}

using i64=int64_t;

vector<i64> fact;
void init_fact(i64 n,i64 m){
	fact.resize(n+1);
	fact[0]=fact[1]=1;
	for(i64 i=2; i<=n; ++i) fact[i]=(i*fact[i-1])%m;
}

i64 extgcd(i64 a,i64 b,i64 &x,i64 &y){
	i64 d=a;
	if(b!=0){
		d=extgcd(b,a%b,y,x);
		y-=(a/b)*x;
	} else {
		x=1; y=0;
	}
	return d;
}

i64 mod_inverse(i64 a,i64 m){
	i64 x,y;
	if(extgcd(a,m,x,y)==1) return (x+m)%m;
	return 0;
}

i64 rep_pow(i64 x,int64_t y,i64 mod){
	i64 res(1);
	while(y>0){
		if(y&1) res=res*x%mod;
		x=x*x%mod;
		y>>=1;
	}
	return res;
}

vector<vector<i64>> comb;
void init_mod_comb(int n,int k,i64 mod){
	comb.resize(n+1);
	for(int i=0; i<=n; ++i){
		comb[i].resize(min(i+1,k+1));
		comb[i][0]=1;
		if(i<=k) comb[i][i]=1;
	}
	for(int i=1; i<=n; ++i){
		for(int j=1; j<=min(i-1,k); ++j){
			comb[i][j]=(comb[i-1][j]+comb[i-1][j-1])%mod;
		}
	}
}

void solve(){
	i64 mod=1000000007;
	init_mod_comb(1024,1024,mod);
	init_fact(1024*1024,mod);
	/*
	vector<i64> inv(1001*1001);
	rep(i,1,1001*1001) inv[i]=mod_inverse(i,mod);
	*/
	//i64 inv_table[1000000];
	//rep(i,1,1000000) inv_table[i]=mod_inverse(i,mod);
	auto inv=[&](i64 x){
		//if(x<1000000) return inv_table[x];
		return mod_inverse(x,mod);
	};

    i64 N,A,B,C,D;
    cin >> N >> A >> B >> C >> D;
    static i64 dp[1024][1024];
    fill_n((i64*)dp,1024*1024,0);
    dp[A][0]=1;
    rep(i,C,D+1){
        if(A*i>N) break;
        dp[A][A*i]=comb[N][A*i]*fact[A*i]%mod*inv(fact[i]*rep_pow(fact[A],i,mod)%mod)%mod;
    }

	rep(i,A,B){
		rep(j,0,N+1){
			dp[i+1][j]=(dp[i+1][j]+dp[i][j])%mod;
			rep(k,C,D+1){
				if(j+(i+1)*k>N) break;
				dp[i+1][j+(i+1)*k]=(dp[i+1][j+(i+1)*k]+dp[i][j]*comb[N-j][(i+1)*k]%mod*fact[(i+1)*k]%mod*inv(fact[k]*rep_pow(fact[i+1],k,mod)%mod)%mod)%mod;
			}
		}
	}

	cout << dp[B][N] << endl;
}

int main(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(10);
    solve();
    return 0;
}


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

using namespace std;
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))
#define endl "\n"
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {os << "["; for (const auto &v : vec) {os << v << ","; } os << "]"; return os;}
template <typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &p) {os << "(" << p.first << ", " << p.second << ")"; return os;}

void solve() {
    string s;
    cin >> s;
    for (int i = 0; i + 1 < s.size(); i++) {
        if (s[i] == s[i + 1]) {
            cout << "Bad" << endl;
            return;
        }
    }
    cout << "Good" << endl;
}

int main() {
    #ifdef LOCAL_ENV
    cin.exceptions(ios::failbit);
    #endif
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    
    solve();
}

Measured memory_bytes: 256
n=int(input())
lst=[[0,0,0]]+[list(map(int,input().split())) for i in range(n)]
for i in range(1,n+1):
    t,x,y=lst[i-1]
    T,X,Y=lst[i]
    if T-t>=abs(x-X)+abs(y-Y):
        if (T-t)%2==(x+y-X-Y)%2:
            continue
        else:
            print("No")
            break
    else:
        print("No")
        break
else:
    print("Yes")

Measured memory_bytes: 61272
class Dice:
    def __init__(self, lst):
        self.a = lst[0]
        self.b = lst[1]
        self.c = lst[2]
        self.d = lst[3]
        self.e = lst[4]
        self.f = lst[5]
        
    def roll(self, orders):
        for order in orders:
            if order=='W':
                tmp = self.a
                self.a = self.c
                self.c = self.f
                self.f = self.d
                self.d = tmp
            elif order=='E':
                tmp = self.a
                self.a = self.d
                self.d = self.f
                self.f = self.c
                self.c = tmp
            elif order=='S':
                tmp = self.a
                self.a = self.e
                self.e = self.f
                self.f = self.b
                self.b = tmp
            elif order=='N':
                tmp = self.a
                self.a = self.b
                self.b = self.f
                self.f = self.e
                self.e = tmp
#             print(self.a, self.b, self.c, self.d, self.e, self.f)
#         print(self.a)
    
    def equal(self, dice_):
        if (self.a==dice_.a and
            self.b==dice_.b and
            self.c==dice_.c and
            self.d==dice_.d and
            self.e==dice_.e and
            self.f==dice_.f
           ):
            return True
        else:
            return False
       
            
import random
if __name__ == '__main__':
    lsts = [[int(x) for x in input().split()] for _ in range(2)]
    dice1 = Dice(lsts[0])
    dice2 = Dice(lsts[1])
    
    ans = 'No'
    for direction in 'EEENEEENEEESEEESEEENEEEN':
        if dice1.equal(dice2):
            ans = 'Yes'
            break
        else:
            dice1.roll(direction)
    print(ans)


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

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)

using ll = long long;
using ld = long double;
ll INF = LLONG_MAX;

using vi = vector<int>;
using vll = vector<ll>;
using pii = pair<int, int>;

namespace output {
	void pr(int x) { cout << x; }
	void pr(long x) { cout << x; }
	void pr(ll x) { cout << x; }
	void pr(unsigned x) { cout << x; }
	void pr(unsigned long x) { cout << x; }
	void pr(unsigned long long x) { cout << x; }
	void pr(float x) { cout << x; }
	void pr(double x) { cout << x; }
	void pr(ld x) { cout << x; }
	void pr(char x) { cout << x; }
	void pr(const char* x) { cout << x; }
	void pr(const string& x) { cout << x; }
	void pr(bool x) { pr(x ? "true" : "false"); }
	template<class T> void pr(const complex<T>& x) { cout << x; }
	
	template<class T1, class T2> void pr(const pair<T1,T2>& x);
	template<class T> void pr(const T& x);
	
	template<class T, class... Ts> void pr(const T& t, const Ts&... ts) { 
		pr(t); pr(ts...); 
	}
	template<class T1, class T2> void pr(const pair<T1,T2>& x) { 
		pr("{",x.f,", ",x.s,"}"); 
	}
	template<class T> void pr(const T& x) { 
		pr("{"); // const iterator needed for vector<bool>
		bool fst = 1; for (const auto& a: x) pr(!fst?", ":"",a), fst = 0; 
		pr("}");
	}
	
	void print() { pr("\n"); } // print w/ spaces
	template<class T, class... Ts> void print(const T& t, const Ts&... ts) { 
		pr(t); if (sizeof...(ts)) pr(" "); print(ts...); 
	}
}

using namespace output;

// dp[i][j] = # stocks, i = day, j = money left
ll dp [80][200] = {0};

int main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int N; cin >> N;
	vi arr (N);
	F0R(i, N) cin >> arr[i];

	ll ans = 1000;
	F0R(i, N) dp[i][1000%arr[i]] = 1000 / arr[i];

	F0R(i, N) F0R(j, 200) if (dp[i][j]) {
		int hi = arr[i];
		FOR(k, i+1, N) {
			ll money = j + hi * dp[i][j];
			dp[k][money%arr[k]] = max(dp[k][money%arr[k]], money/arr[k]);
			hi = max(hi, arr[k]);
		}
		ans = max(ans, dp[i][j] * hi + j);
	}
	print(ans);
}

Measured memory_bytes: 3696