akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
int main(){
int n,i,a[10000];
int max,min;
long sum;
  
scanf("%d",&n);
scanf("%d",&a[0]);
max=a[0];
min=a[0];
sum=a[0];
for(i=1;i<n;i++){
scanf("%d",&a[i]);
sum=sum+a[i];
if(max<a[i])max=a[i];
if(min>a[i])min=a[i];
}
  
printf("%d %d %ld\n",min,max,sum);
  
return 0;
}

Measured memory_bytes: 636
#include<iostream>
#include<cmath>
using namespace std;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    long int n,count=0,i;
    long long int num;
    cin >> n;
    while(n--){
        cin >> num;
        bool flag = 0;
        for(i=2;i<=sqrt(num);i++){
            if(num%i==0){
                flag = 1;
                break;
            }
        }
        if(flag==0)  count++;
    }
    cout << count << "\n";
    return 0;
}

Measured memory_bytes: 3148
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <utility>
#include <climits>
#include <vector>
using namespace std;

#define ll long long int

const int MOD = 1000000007;

int max(int a, int b) {

	if (a > b)return a;
	else return b;

}
int main() {

	int N, ans = 0;

	cin >> N;

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

		ans += i;

	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>

int main()
{
    int n;
    std::cin >> n;
    std::string s;
    std::cin >> s;

    int x = 0, max_x = 0;
    for (const char c : s)
    {
        if (c == 'I')
        {
            ++x;
        }
        else
        {
            --x;
        }
        max_x = std::max(x, max_x);
    }

    std::cout << max_x << std::endl;
    return 0;
}


Measured memory_bytes: 3604
/*
 * AtCode Beginner Contest 130 : B.Bounding
 * Author : anaksoleh
 * 27 August 2019
 *
 */

#include <bits/stdc++.h>
using namespace std;

int N,X;
int L[105];
int D[105];

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

	cin >> N >> X;

	for(int i = 1 ; i <= N ; i++){
		cin >> L[i];
	}

	D[1] = 0;
	int ans = 1;
	for(int i = 2 ; i <= (N + 1) ; i++){
		D[i] = D[i-1] + L[i - 1];
		if(D[i] > X){
			break;
		}
		++ans;
	}

	cout << ans << '\n';

	return 0;
}

Measured memory_bytes: 256
#ifdef __GNUC__
#pragma GCC target("avx2")
#pragma GCC optimize ("O25")
#pragma GCC optimize ("tree-vectorize")
#pragma GCC optimize("unroll-loops")
#define iss std::cin
#endif
#include "bits/stdc++.h"
#define rep(i, times) for(ll i = 0; i < (times); ++i)
#define p(x) (cout << (x) << "\n")
using ll = long long; using ld = long double; using namespace std;

#ifndef __GNUC__
string text =
R"X(
6
3 14 159 2 6 53
58 9 79 323 84 6
2643 383 2 79 50 288
)X";
stringstream iss{text};
#endif 

class Festival
{
	ll N{0};
	vector<vector<ll>> A;
	void inp( ) {
		iss >> N; A.resize(3, vector<ll>(N));
		rep(a, 3) {	rep(i, N) { iss >> A[a][i]; };}
		sort(begin(A[0]), end(A[0]));
		sort(begin(A[2]), end(A[2]));
	}
	void biSearch( ) {
		ll cnt{0};
		for (auto &b : A[1]) {
			auto itA = lower_bound(begin(A[0]), end(A[0]), b);//A<bなる最大要素の位置
			auto itC = upper_bound(begin(A[2]), end(A[2]), b);//b<Cなる最小要素の位置
			cnt += (end(A[2]) - itC) * (itA - begin(A[0]));
		}
		p(cnt);
	}
public:
	void procedures( ) {
		inp( );	biSearch( );
	}
};
int main( ) {
	cin.tie(0);	ios::sync_with_stdio(0);
	class Festival a; a.procedures( );
}

Measured memory_bytes: 6340
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define f first
#define s second
#define pb push_back
#define eb emplace_back
#define mk make_pair
#define mt make_tuple
#define MOD 1000000007
#define fo(i,a,b) for(i=a;i<b;i++)
#define foe(i,a,b) for(i=a;i<=b;i++)
#define all(x) x.begin(), x.end()
#define vi vector<int>
#define vl vector <long long int>
#define pii pair <int,int>
#define pll pair <long long int, long long int>
#define vpii vector< pair<int,int> >
#define vpll vector < pair <long long int,long long int> > 
#define boost ios::sync_with_stdio(false); cin.tie(0)
using namespace std;
const int inf = 1e9 + 5;
const ll inf64 = 1e18 + 5;
int main()
{
	boost;
	ll n, r, k, i;
	cin >> n >> r;
	if(n >= 10) cout << r << '\n';
	else{
		int x = 100 * (10 - n);
		cout << r + x << '\n';
	}
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#define h 500000

void maxheapify(int *,int);
void buildMaxHeap(int *);

int H;
int main(){
  int i;
  int *A;


  scanf("%d",&H);
  A=malloc(sizeof(int)*h);
  for(i=1 ; i<H+1 ; i++){
    scanf("%d",&A[i]);
  }

  buildMaxHeap(A);

  for(i=1 ; i<H+1 ; i++){
    printf(" %d",A[i]);
  }
  printf("\n");
  return 0;
}

void maxHeapify(int *A,int i){
  int l,r,largest,F;

  l = i*2;
  r = i*2+1;
  if(l<=H && A[l]>A[i]){
    largest = l;
  }
  else largest = i;
  if (r<=H && A[r]>A[largest])
    largest = r;
  if(largest!=i){
    F=A[i];
    A[i]=A[largest];
    A[largest]=F;
    maxHeapify(A,largest);
  }
}

void buildMaxHeap(int *A){
  int i;
  for(i=H/2 ; i>0 ; i--){
    maxHeapify(A,i);
      }
}

Measured memory_bytes: 2556
#include <iostream>
#include <string>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <numeric>
#define MOD 1000000007

using namespace std;

int main(void) {
    long long a = 0;
    long long b = 0;
    long long c = 0;
    long long x = 0;
    long long y = 0;
    cin >> a >> b >> c >> x >> y;
    long long minxy = min(x,y);
    long long buya = 0;
    long long buyb = 0;
    long long buyc = 0;
    if(a+b < 2*c){
        buya += x;
        buyb += y;
//        if(x<y){
//            buya += x;
//        }else{
//            buyb += y;
//        }
    }else if(a+b >= 2*c){
        buyc += 2 * minxy;
        
        if(x<y){
            if(b<2*c){
                buyb += y - x;
            }else{
                buyc += 2*y - 2*x;
            }
        }else{
            if(a<2*c){
                buya += x-y;
            }else{
                buyc += 2*x - 2*y;
            }
        }
        
    }
    cout << buya*a + buyb*b + buyc*c << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize ("-ffloat-store")  
#pragma GCC optimize ("-fno-defer-pop")
#define all(a) a.begin(),a.end()
#define ll long long int
#define ld long double
ll power(ll a,ll b,ll m){ if(b==0) return 1; if(b==1) return a%m; ll t=power(a,b/2,m)%m; t=(t*t)%m; if(b&1) t=((t%m)*(a%m))%m; return t;}
ll modInverse(ll a, ll m) { return power(a, m-2, m); }
#define ps push_back
#define fs first
#define sc second
#define N 3000005
#define endl "\n"
#define mod 1000000007
int main(){

	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	
	ll i,j,k,p,q,r;
	cin>>p>>q>>r;

	string s="ABC";
	ll mn=1e18;
	do{
		//cout<<s<<endl;
		k=0;
		for(i=1;i<3;i++){
			if(s[i]=='A'){
				if(s[i-1]=='B'){
					k+=p;
				}
				else {
					k+=r;
				}
			}
			else if(s[i]=='B'){
				if(s[i-1]=='A'){
					k+=p;
				}
				else {
					k+=q;
				}
			}
			else {
				if(s[i-1]=='A'){
					k+=r;
				}
				else {
					k+=q;
				}
			}
		}
		mn=min(mn,k);
	}while(next_permutation(all(s)));
	cout<<mn;
	return 0;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10000000)


n = input()
h2 = list(map(int, input().split()))
j2 = -2
count2 = 0


def maax(count, j, h):
    if max(h) == 0:
        print(count)
        return
    k = max(h)
    
    for i in range(len(h)):
        if h[i] == k:
            if j+1 != i:
                count = count+1
    
            j = i
            h[i] = k-1
            maax(count, j, h)
    

maax(count2, j2, h2)


Measured memory_bytes: 8820
N,A,B,C = map(int,input().split())
l = [int(input()) for i in range(N)]


def dfs(n, a, b, c):
  if n == N:
    return abs(a - A) + abs(b - B) + abs(c - C) - 30 if min(a, b, c) > 0 else 10 ** 9
  ret0 = dfs(n + 1,a + l[n],b,c) + 10
  ret1 = dfs(n + 1,a,b + l[n],c) + 10
  ret2 = dfs(n + 1,a,b,c + l[n]) + 10
  ret3 = dfs(n + 1,a,b,c)
  return min(ret0, ret1, ret2, ret3)
 
ans = dfs(0, 0, 0, 0)
print(ans)

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

#define fast ios::sync_with_stdio(false); cin.tie(0);cout.tie(0); 
 
using namespace std;
 
typedef  long long int lli; 

int main(){
    
    lli i,x,n; 
    fast;

    cin>>n;
    if(n<=26){
        char t=n+'a'-1;;
        cout<<t;
        return 0;
    }
    string str="";
    while(n>=1){
        x=n%26;
        if(x==0){
            x=26;
        }
        str+='a'+x-1;
        n=n/26;
        if(x==26){
            n--;
        }
    }
    reverse(str.begin(),str.end());
    cout<<str;
    
    

    return 0;
}

Measured memory_bytes: 3680
package main

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

// input scanner
var sc = bufio.NewScanner(os.Stdin)

const (
	initialBufSize = 10e4
	maxBufSize     = 10e6
)

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

func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}

func nextInt64() int64 {
	a, _ := strconv.ParseInt(next(), 10, 64)
	return a
}

func nextFloat64() float64 {
	a, _ := strconv.ParseFloat(next(), 64)
	return a
}

func nextInts(n int) []int {
	ret := make([]int, n)
	for i := 0; i < n; i++ {
		ret[i] = nextInt()
	}
	return ret
}
func nextFloats(n int) []float64 {
	ret := make([]float64, n)
	for i := 0; i < n; i++ {
		ret[i] = nextFloat64()
	}
	return ret
}
func nextStrings(n int) []string {
	ret := make([]string, n)
	for i := 0; i < n; i++ {
		ret[i] = next()
	}
	return ret
}

// util
func max(l []int) (int, int) {
	idx := 0
	ans := l[idx]
	for i, n := range l {
		if n > ans {
			idx = i
			ans = n
		}
	}
	return idx, ans
}

func min(l []int) (int, int) {
	idx := 0
	ans := l[idx]
	for i, n := range l {
		if n < ans {
			idx = i
			ans = n
		}
	}
	return idx, ans
}

// main
func main() {
	buf := make([]byte, initialBufSize)
	sc.Buffer(buf, maxBufSize)
	sc.Split(bufio.ScanWords)
	n := nextInt()
	c := make(map[string]int)
	max := 1
	for i := 0; i < n; i++ {
		s := next()
		_, exist := c[s]
		if !exist {
			c[s] = 1
			continue
		}
		c[s]++
		if max < c[s] {
			max = c[s]
		}
	}
	var ans []string
	for key, val := range c {
		if val == max {
			ans = append(ans, key)
		}
	}
	sort.Strings(ans)
	for _, s := range ans {
		fmt.Println(s)
	}
}


Measured memory_bytes: 30848
#include <stdio.h>
#define N 100005
#define NIL -1
struct Node{
  int parent;
  int left;
  int right;
};
struct Node A[N];
int n,B[N];
void print(int j){
  int i,c;
  printf("node %d: ",j);
  printf("parent = %d, ",A[j].parent);
  printf("depth = %d, ",B[j]);
  if(A[j].parent==NIL)printf("root, ");
  else if(A[j].left==NIL)printf("leaf, ");
  else printf("internal node, ");
  printf("[");
  for(i=0,c=A[j].left;c!=NIL;i++,c=A[c].right){
    if(i)printf(", ");
    printf("%d",c);
  }
  printf("]\n");
}
int rec(int z,int p){
  B[z]=p;
  if(A[z].right!=NIL)rec(A[z].right,p);
  if(A[z].left!=NIL)rec(A[z].left,p+1);
}

int main() {
  int i,j,d,v,c,left,right;
  scanf("%d",&n);
  for(i=0;i<n;i++)A[i].parent=A[i].left=A[i].right=NIL;
  for(i=0;i<n;i++){
    scanf("%d%d",&v,&d);
    for(j=0;j<d;j++){
      scanf("%d",&c);
      if(j==0)A[v].left=c;
      else A[left].right=c;
      left=c;
      A[c].parent=v;
    }
  }
  for(i=0;i<n;i++){
    if(A[i].parent==NIL)right=i;
  }
  rec(right,0);
  for(i=0;i<n;i++)print(i);
  return 0;
}



Measured memory_bytes: 6456
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
  int n;
  cin >> n;
  vector<ll> a(n);
  for(int i=0; i<n; i++) cin >> a[i];
  int sum = 0;
  for(int i=0; i<n; i++){
    sum += a[i]-1;
  }
  cout << sum << endl;
}

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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, int> Pi;
typedef vector<ll> Vec;
typedef vector<int> Vi;
typedef vector<string> Vs;
typedef vector<vector<ll>> VV;
typedef vector<vector<int>> VVi;

#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define PER(i, a, b) for(ll i=(a); i>=(b); i--)
#define rep(i, n) REP(i, 0, n)
#define per(i, n) PER(i, n, 0)
const ll INF=1e18+18;
const ll MAX=100005;
const ll MOD=1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;
#define ALL(v) v.begin(), v.end()
#define rALL(v) v.rbegin(), v.rend()
#define pb(x) push_back(x)
#define mp(a, b) make_pair(a,b)
#define Each(a,b) for(auto &a :b)
#define REPM(i, mp) for (auto i = mp.begin(); i != mp.end(); ++i)
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define dbgmap(mp) cerr << #mp << ":"<<endl; for (auto i = mp.begin(); i != mp.end(); ++i) { cerr << i->first <<":"<<i->second << endl;}
#define dbgarr(n,m,arr) rep(i,n){rep(j,m){cerr<<arr[i][j]<<" ";}cerr<<endl;}
#define dbgdp(n,arr) rep(i,n){cerr<<arr[i]<<" ";}cerr<<endl;
#define sum(v) accumulate(ALL(v),0)
#define fi first
#define se second

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; }

template<typename T1, typename T2>
ostream &operator<<(ostream &s, const pair<T1, T2> &p) { return s<<"("<<p.first<<", "<<p.second<<")"; }

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

// 2 dimentional vector
template<typename T>
ostream &operator<<(ostream &s, const vector<vector<T> > &vv) {
    int len=vv.size();
    for(int i=0; i<len; ++i) {
        s<<vv[i]<<endl;
    }
    return s;
}

Vs g;

ll h,w;
bool seen[410][410];

int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
ll cntb =0;
ll cntw =0;

ll dfs(ll i,ll j,char col){
    if(i>=0&&i<=h-1&&j>=0&&j<=w-1){
        if(g[i][j]!=col) return 0;
        if(seen[i][j]) return 0;
        seen[i][j] = true;
        if(col=='#'){
            cntb++;
           rep(k,4){
               dfs(i+dx[k],j+dy[k],'.');
           }
        }else{
            cntw++;
            rep(k,4){
                dfs(i+dx[k],j+dy[k],'#');
            }
        }
    }else{
        return 0;
    }

}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<std::setprecision(10);

    cin>>h>>w;
    g.resize(h);
    rep(i,h){
        cin>>g[i];
    }
    ll ans=0;

    rep(i,h){
        rep(j,w){
            if(g[i][j]=='#'){
                if(seen[i][j])continue;
                cntb = cntw = 0;
                dfs(i,j,'#');
                ans += cntb*cntw;
            }
        }
    }

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


Measured memory_bytes: 8064
#include <bits/stdc++.h>
using namespace std;
int main(void){
    string input;
    cin>>input;
    int tmp=0;
    int a=input[0]-'0';
    int b=input[1]-'0';
    int c=input[2]-'0';
    int d=input[3]-'0';
    tmp=a+b+c+d;
    if(tmp==7){
        cout<<a<<"+"<<b<<"+"<<c<<"+"<<d<<"=7"<<endl;
        return 0;
    }
    tmp=a-b+c+d;
    if(tmp==7){
        cout<<a<<"-"<<b<<"+"<<c<<"+"<<d<<"=7"<<endl;
        return 0;
    }
    tmp=a+b-c+d;
    if(tmp==7){
        cout<<a<<"+"<<b<<"-"<<c<<"+"<<d<<"=7"<<endl;
        return 0;
    }
    tmp=a+b+c-d;
    if(tmp==7){
        cout<<a<<"+"<<b<<"+"<<c<<"-"<<d<<"=7"<<endl;
        return 0;
    }
    tmp=a-b-c+d;
    if(tmp==7){
        cout<<a<<"-"<<b<<"-"<<c<<"+"<<d<<"=7"<<endl;
        return 0;
    }
    tmp=a+b-c-d;
    if(tmp==7){
        cout<<a<<"+"<<b<<"-"<<c<<"-"<<d<<"=7"<<endl;
        return 0;
    }
    tmp=a-b+c-d;
    if(tmp==7){
        cout<<a<<"-"<<b<<"+"<<c<<"-"<<d<<"=7"<<endl;
        return 0;
    }
    tmp=a-b-c-d;
    if(tmp==7){
        cout<<a<<"-"<<b<<"-"<<c<<"-"<<d<<"=7"<<endl;
        return 0;
    }
}


Measured memory_bytes: 256
#include <map>
#include <set>
#include <cmath>
#include <queue>
#include <stack>
#include <cctype>
#include <cstdio>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>

#define INF (2 << 28)
#define fr first
#define sc second
using namespace std;

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

int main(){
  
  long long N, M, P[100000], sum[100001] = { 0 };
  long long A[100000], B[100000], C[100000];
  
  cin >> N >> M;
  for(int i = 0; i < M; i++)
    cin >> P[i];
  for(int i = 0; i < N - 1; i++) {
    cin >> A[i] >> B[i] >> C[i];
  }

  for(int i = 0; i < M - 1; i++)
    sum[min(P[i], P[i + 1])]++, sum[max(P[i], P[i + 1])]--;
  for(int i = 1; i <= N; i++)
    sum[i] += sum[i - 1];

  long long ans = 0;
  for(int i = 1; i <= N; i++) {
    ans += min(A[i - 1] * sum[i], C[i - 1] + B[i - 1] * sum[i]);
  }
  cout << ans << endl;
}

Measured memory_bytes: 5072
#include <bits/stdc++.h>
//#define int long long

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

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

#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

const int INF = (int)1e9;
const LL INFL = (LL)1e18;
const int MOD = (int)1e9 + 7;

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    bool ans = true;
    int curt = 0, curx = 0, cury = 0;
    REP(i, n){
        int t, x, y;
        cin >> t >> x >> y;
        int dis = abs(curx - x) + abs(cury - y);
        ans &= t - curt >= dis && ((t - curt) - dis) % 2 == 0;
        curt = t, curx = x, cury = y;
    }
    cout << (ans ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
n,a,b = map(int, input().split())
rs = (b-a)//2

if (b-a) % 2 == 0:
    print(rs)
else:
    if a==1 and b==n:
        print(n//2)
    elif (a-1) > (n-b):
        print(rs+(n-b+1))
    else:
        print(rs+a)

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

int main(){
    ll n,m;
    cin>>n>>m;
    ll ans=min(n,m/2);
    if(2*n<m){
        m-=2*n;
        ans+=m/4;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	 public static void main(String args[]){
	Scanner scanner = new Scanner(System.in);
		int l=scanner.nextInt();
       int r=scanner.nextInt();
       int d=scanner.nextInt();
       int total=0;

	// 変数strの長さ分回す
	for (int i = l; i <=r; i++) {
	   if(i%d==0){
       total=total+1;
       }

	}
	System.out.println(total);}
}


Measured memory_bytes: 35600
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, from, to) for (int i = from; i < (to); ++i)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define pb push_back
using ll = long long;
using vin=vector<int>;
using vll=vector<ll>;
using P = pair<int, int>;
const int inf=1e9+7;
const ll INF=1e18;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

int main() {
  string s;
  cin>>s;
  int n=s.size();
  cout<<s[0]<<n-2<<s[n-1]<<endl;
}

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

typedef long long ll;

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl

const int maxn = 1e6 + 5;

int n;
string s;
int cache[maxn][2];

int go(int i, int carry) {
  if (i < 0) return carry;
  if (cache[i][carry]) return cache[i][carry];

  int& res = cache[i][carry];
  res = 1e9;
  int val = carry + (s[i]-'0');

  // try just paying the digit flat out
  if (val<10) {
    res = min(res, go(i-1,0)+val);
  }

  // rely on a future carry, and we'll receive some bills back
  res = min(res, go(i-1, 1) + (10 - val));
  return res;
}

int main() {
  ios_base::sync_with_stdio(false); cin.tie(0);  cout.tie(0);
  cin>>s;
  n = s.length();

  cout<<go(n-1, 0)<<endl;
  return 0;
}
// don't forget to read in the input :^)


Measured memory_bytes: 56092
#include <iostream>
#include <set>
#include <vector>
#include <string>
#include <algorithm>
#include <iterator>
#include <map>
#include <utility>
#include <list>
#include <climits>
#include <bitset>

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define repi(i, n) for(auto i = (n).begin(); i != (n).end(); i++)
#define in_arr(type, a, n) copy_n(istream_iterator<type>(cin), n, (a).begin());
#define ll long long int

int main(){
    int a, b, w;
    cin >> w >> a >> b;
    cout << max(max(0, b - a - w), a - b - w) << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<string.h>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
using namespace std;
int main()
{
    int n,i;
    scanf("%d",&n);
    for (i=0;i<=n;i+=4)
        if ((n-i)%7==0) {printf("Yes");return 0;}
    printf("No");
    return 0;
}

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

using namespace std;
typedef long long ll;

constexpr ll INF = 1e16;

#define rep(i, N) for(ll i=0; i<N; ++i)

ll max(ll a, ll b) {return a < b ? b : a; }
ll min(ll a, ll b) {return a > b ? b : a; }

int main() {
  ll N, M, R;
  cin >> N >> M >> R;
  vector<ll> r(R);
  rep(i, R) cin >> r[i];
  vector<ll> A(M);
  vector<ll> B(M);
  vector<ll> C(M);
  rep(i, M) cin >> A[i] >> B[i] >> C[i];
  
  //ワーシャルフロイド
  vector<vector<ll>> G(N, vector<ll>(N, INF));
  for(ll i=0; i<N; ++i) {
    G[i][i] = 0;
  }
  //デフォルトは直接の辺の長さ
  for(ll i=0; i<M; ++i) {
    G[A[i] - 1][B[i] - 1] = C[i];
    G[B[i] - 1][A[i] - 1] = C[i];
  }
  //更新．辺kを経由した時，など
  for(ll k=0; k<N; ++k) {
    for(ll i=0; i<N; ++i) {
      for(ll j=0; j<N; ++j) {
        G[i][j] = min(G[i][j], G[i][k] + G[k][j]);
      }
    }
  }
  
  //次に全探索して8!通りのうちから最短を探す
  //rを破壊的に更新
  vector<int> v;
  rep(i, R) v.push_back(i);
  
  ll mv = INF;
  do {
    ll len = 0;
    for(ll i=0; i<r.size()-1; ++i) {
      len += G[r[v[i]] - 1][r[v[i+1]] - 1];
    }
    mv = min(len, mv);
  } while(next_permutation(v.begin(), v.end()));
  
  cout << mv << endl;
  
}

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

int main()
{
	string s;
	s+='2';
	s+='0';
	s+='1';
	s+='8';
	string a;
	cin>>a;
	for(int i=4;i<10;i++)
	{
		s+=a[i];
	}
	cout<<s<<endl;
	return 0;
}

Measured memory_bytes: 256
R,G,B,N = map(int,input().split())

rcount=0
gcount=0
b=0
ans = 0

while rcount <= N:
    gcount = 0
    while rcount+gcount <= N:
        if (N - (rcount + gcount) ) % B == 0 :
            ans += 1
        gcount += G
    rcount += R

print(ans)

Measured memory_bytes: 3060
s = input()
judge = True
while 0<len(s): 
    if s[:5]=='dream':
        s = s[5:]
        if s[:2]=='er' and not s[:5]=='erase':
            s = s[2:]
    elif s[:5]=='erase':
        s = s[5:]
        if s[:1]=='r':
            s = s[1:]
    else:
        judge = False
        break
print('YES' if judge else 'NO')



Measured memory_bytes: 134236
#include <bits/stdc++.h>
using namespace std;
template <typename T> void read(T &t) {
	t=0; char ch=getchar(); int f=1;
	while ('0'>ch||ch>'9') { if (ch=='-') f=-1; ch=getchar(); }
	do {(t*=10)+=ch-'0';ch=getchar();} while ('0'<=ch&&ch<='9'); t*=f;
}
const int maxn=610;
int n,m,x,lg;
bool c[maxn][maxn];
void solve() {
	lg=0;
	read(x);
	while (x%4==0)
		x/=4,lg++;
	if (x%2==1) {
		for (int i=0;i<2*n;i++)
		for (int j=0;j<2*n;j++)
			c[i][j]|=((i>>lg)+(j>>lg))&1;
	} else {
		for (int i=0;i<2*n;i++)
			if (i&(1<<lg))
				for (int j=0;j<2*n;j++) c[i][j]=1;
	}
}
int main() {
	//freopen("1.txt","r",stdin);
	read(n);
	solve();
	solve();
	int tot=0;
	for (int i=0;i<2*n;i++)
	for (int j=0;j<2*n;j++)
		if (!c[i][j]) {
			printf("%d %d\n",i,j);
			tot++;
			if (tot==n*n) return 0;
		}
    return 0;
}

Measured memory_bytes: 1280
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <algorithm>

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

using namespace std;

int main() {
  int n;
  cin>>n;
  vector<vector<int>> t(n,vector<int>(n));
  REP(i,n)REP(j,n) cin>>t[i][j];
  int64_t sum = 0;
  REP(i,n)REP(j,i) {
    sum += min(t[i][j], t[j][i]);
  }
  cout<<sum<<endl;
  return 0;
}

Measured memory_bytes: 1252
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define INF LLONG_MAX/10
#define rep(i,n) for(int i=0;i<n;i++)
#define krep(i,k,n,m) for(int i=k;i<n;i+=m)
#define erep(i,k,n) for(int i=k;i<n;i++)
#define mod 1000000007
//最大公約数
int gcd(int s,int b){
    if(b==0)return s;
    return gcd(b,s%b);
}
signed main(){
    int n;
    cin>>n;
    int a[n];
    rep(i,n){
        cin>>a[i];
    }
    sort(a,a+n);
    int m;
    cin>>m;
    int b[m];
    rep(i,m){
        cin>>b[i];
    }
    sort(b,b+m);
    int kai=0;
    rep(i,n){
        if(a[i]==b[kai]){
            kai++;
        }
    }
    if(kai!=m){
        cout<<"NO"<<endl;
    }
    else{
        cout<<"YES"<<endl;
    }
}


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

typedef long long LL;

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(x) (x).begin(),(x).end()
const int IINF = 1e9;
const LL LINF = 1e18;
const LL mod = 1e9+7;

int main() {
    map<int, int> m;
    int N;
    cin >> N;
    REP(i, N) {
        int d;
        cin >> d;
        m[d]++;
    }
    cout << m.size() << endl;
    return 0;
}


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

int main(void){
	char w[110];
	int l;
	int c[26] = {};
	int i;
	int f;

	scanf("%s",w);

	l = strlen(w);

	for(i=0;i<l;i++){
		c[w[i] - 'a']++;
	}

	f = 0;

	for(i=0;i<26;i++){
		if(c[i] % 2 == 1){
			f = 1;
		}
	}

	if(f==1){
		printf("No\n");
	}else{
		printf("Yes\n");
	}

	return 0;
}

Measured memory_bytes: 128
#include <stdio.h>

int main(void) {
    int A, B;
    int i;

    // input
    scanf("%d %d", &A, &B);

    for (i = 0; i < 1251; i++) {
        int pre8 = (int)((double)i * 0.08);
        if (pre8 == A) {
            int pre10 = (int)((double)i * 0.1);
            if (pre10 == B) {
                printf("%d\n", i);
                return 0;
            }
        }
    }
    printf("%d\n", -1);
    return 0;

}

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

int main() {
    ll ans = 1e9, res = 0;
    string s, t;
    cin >> s >> t;
    int n = s.length(), m = t.length();
    for(int i=0; i<=n-m; i++) {
        for(int j=0; j<m; j++) {
            if(s[i+j] != t[j]) res++;
        }
        ans = min(ans, res);
        res = 0;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3608
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>
#include <bitset>
#include <time.h>
#include <tuple>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e12;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1
#define MAX_N 100100 * 3

string s;

int main() {
	cin >> s;
	cout << s.substr(0, s.size() - 8) << endl;
}

Measured memory_bytes: 256
def main():
    import sys
    # readline = sys.stdin.readline
    readlines = sys.stdin.readlines
    N, M = map(int, input().split())
    edge = []
    dp = [[10 ** 9] * N for _ in range(N)]
    for i in range(N):
        dp[i][i] = 0
    for s in readlines():
        a, b, c = map(int, s.split())
        a -= 1; b -= 1
        edge.append((a, b, c))
        dp[a][b] = c
        dp[b][a] = c
    
    for k in range(N):
        for i in range(N):
            for j in range(N):
                dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j])

    cnt = 0
    for a, b, c in edge:
        if dp[a][b] < c:
            cnt += 1
    
    print(cnt)


if __name__ == "__main__":
    main()


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


long long int Exp(long long int exp_n,long long int exp_e, long long exp_mod);


int main(){
  int N,K;
  cin >> N >> K;
  long long int P[N],C[N],S,O;
  for(int i=0;i<N;i++){
    cin >> P[i];
  }
  
  
  for(int i=0;i<N;i++){
    cin >> C[i];
  }
  
  O=-1000000000;
  for(int i=0;i<N;i++){
    S=0;
    int c=i,tmp,a=0;
    for(int j=0;j<K;j++){
      c=P[c]-1;
      S=S+C[c];
      if(c==i && a==0){
        a=1;
        tmp=K/(j+1);
        if(tmp != 1){
          S= S*(tmp-1);
          j=(j+1)*(tmp-1)-1;
        }
      }
      if(S>O){
        O=S;
      }
    }
  }
  cout << O;
  
  return 0;
}


long long int Exp(long long int exp_n,long long int exp_e, long long int exp_mod){
  long long int exp_o = 1;
  long long int exp_x=exp_n;
  long long int exp_tmp;
  
  while(0<exp_e){
    exp_tmp = exp_e/2;
    if(exp_e - exp_tmp*2 == 1){
      exp_o = exp_o*exp_x;
      if(exp_o>exp_mod){
        exp_o=exp_o%exp_mod;
      }
    }
    
    exp_x = exp_x*exp_x;
    if(exp_x>exp_mod){
      exp_x=exp_x%exp_mod;
    }
    exp_e = exp_tmp;
  }
  return exp_o;
}


Measured memory_bytes: 3676
n, k = map(int, input().split())
MOD = 10** 9 + 7
a = k * (k - 1) // 2
c = k * (2 * n - k + 1) // 2
ans = 0
for i in range(k, n + 2):
	ans = (ans + c - a + 1) % MOD
	a += i
	c += n - i
print(ans)

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

using namespace std;

#define IOS ios::sync_with_stdio(0);cin.tie(0);

int main(){
	IOS;
	int n;
	while(cin>>n){
		bool flag=false;
		for(int i=0;i<n;i++){
			char a;
			cin>>a;
			if(a == 'Y'){
				flag=true;
			}
		}
		if(flag){
			cout<<"Four"<<endl;
		}
		else{
			cout<<"Three"<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 256
from collections import defaultdict, deque
n, m = map(int, input().split())
g = defaultdict(set)

if m == 0:
    print(1)

else:
    for _ in range(m):
        a, b = map(int, input().split())
        g[a - 1].add(b - 1)
        g[b - 1].add(a - 1)


    visited = [False]*n
    ans = 0
    for i in range(n):
        if not visited[i]:
            # cc = []
            count = 1
            q = deque([i])
            visited[i] = 1
            while q:
                node = q.pop()
                for nbr in g[node]:
                    if not visited[nbr]:
                        q.append(nbr)
                        visited[nbr] = True
                        count += 1
                
            # ans = max(ans, len(cc))
            ans = max(ans, count)

    print(ans)

Measured memory_bytes: 172852
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<iomanip>
using namespace std;
typedef long long ll;
const int INF=100000000;
const int MOD=1000000007;

int main()
{
  int k, s, ans=0;
  cin >> k >> s;
  for(int i=0;i<k+1;i++){
      for(int j=0;j<k+1;j++){
       if((s-i-j>=0)&&(s-i-j<=k)) ans+=1;
      }
  }
 cout<< ans;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <iomanip>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>

#define debug(x) cout << #x << " = " << x << endl
#define fori(i, ini, lim) for(int i = int(ini); i < int(lim); i++)
#define ford(i, ini, lim) for(int i = int(ini); i >= int(lim); i--)

using namespace std;

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

vector<ll> divisors(ll x) {
    vector<ll> d;
    for (ll i = 1; i * i <= x; i++) {
        if (x % i == 0) {
            d.push_back(i);
            if (i * i != x) {
                d.push_back(x / i);
            }
        }
    }
    return d;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    ll n;
    cin >> n;
    vector<ll> d = divisors(n);
    ll ans = 0;
    for (const auto &e : d) {
        if (e == 1) {
            continue;
        }
        ll a = n;
        while (a % e == 0) {
            a /= e;
        }
        if (a % e == 1) {
            ans++;
        }
    }
    ll a = n - 1;
    d = divisors(a);
    ans += d.size() - 1;
    cout << ans << endl;
    return 0;
}



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

int main()
{
  int a,b,c2;
  float c;
  cin >> a >> b;
  c=(a+b)/2.0;
  c2=c;
  if(c-c2>=0.5)
  {
    c2++;
  }
  
  cout << c2 << endl;
}
  

Measured memory_bytes: 256
import math
N = int(input())
P = list(map(int, input().split()))
Q = list(map(int, input().split()))

Pn=list(range(N) )
Qn=Pn
ans=0
for i in range(N):
    P_ind=Pn[P[i]-1]
    Q_ind=Qn[Q[i]-1]
    ans+=(P_ind-Q_ind)*math.factorial(N-i-1)
    Pn=[s if ind < P[i]-1 else s-1 for ind, s in enumerate(Pn)]
    Qn=[s if ind < Q[i]-1 else s-1 for ind, s in enumerate(Qn)]
    
ans=abs(ans)
print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
const int maxn=3e5+10;
int a[maxn],b[maxn],n;
set<pair<int,int>,greater<pair<int,int>>> s;
long long ans=0;

int main(){
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%d",&a[i]);
    }
    for(int i=0;i<n;i++){
        scanf("%d",&b[i]);
        s.insert(make_pair(b[i],i));
    }
    int l,r;
    while(!s.empty()){
        auto it=*s.begin();
        if(it.first==a[it.second]){
            s.erase(s.begin());
            continue;
        }
        int l=((it.second)-1);
        if(l<0)l=n-1;
        int r=(l+2)%n;
        int sum=(b[l]+b[r]);
        if(b[it.second]<sum||b[it.second]-sum<a[it.second]){
            return !printf("-1");
        }
        if(a[it.second]>sum){
            if((b[it.second]-a[it.second])%sum)
                return !printf("-1");
            ans+=(b[it.second]-a[it.second])/sum;
            b[it.second]=a[it.second];
            s.erase(s.begin());continue;
        }
        ///find the first number that is in form of
        ///b-sum*k<=sum sum*(k+1)>=b
        int cur=b[it.second]/sum-(b[it.second]%sum==0?1:0);
        b[it.second]-=sum*cur;
        ans+=cur;
        s.erase(s.begin());
        s.insert(make_pair(b[it.second],it.second));
    }
    printf("%lld\n",ans);
}
/*
    Good Luck
        -Lucina
*/


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

const int MAXN = 1e5+5;
const ll p = 1e9+7;
const ll inf = (1<<30);

string s;
ll v[MAXN], dp[MAXN][3], part[MAXN][3][3], r[MAXN][3], n;
vector<int> pos[3];

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> s;
	n = s.length();
	v[0] = 0;
	for (int i = 1; i <= n; ++i)
		v[i] = (v[i-1] + 1 + (s[i-1] == 'b'))%3;
	n++;
	for (int i = 0; i < n; ++i)
		pos[v[i]].push_back(i);

	for (int i = n-1; i >= 0; --i) {
		for (int j = 0; j < 3; ++j) {
			if (v[i] == j)
				r[i][j] = i;
			else
				r[i][j] = max(i+1LL, r[i+1][j]);
		}
	}

	dp[0][0] = 1;
	for (int i = 1; i < n; ++i) {
		for (int j = 0; j < 3; ++j)
			for (int k = 0; k < 3; ++k) {
				if (v[i] != k && v[i-1] == j)
					part[i][j][k] = (part[i-1][j][k] + dp[i-1][j])%p;
				else
					part[i][j][k] = part[i-1][j][k];
			}
		for (int j = 0; j < 3; ++j) {
			if (v[i] == j)
				continue;
			//find the range of j that "project" onto i
			int k = 3-v[i]-j;
			//j -> k -> v[i]
			int lo = 0, hi = pos[j].size();
			//find first guy who is >= i;
			if (pos[j].size() == 0)
				continue;
			while (lo != hi) {
				int mid = (lo+hi)/2;
				int x = pos[j][mid];
				if (r[x][k] >= i) {
					hi = mid;
					continue;
				}
				if (r[r[x][k]][v[i]] >= i)
					hi = mid;
				else
					lo = mid+1;
			}
			if (lo == pos[j].size())
				continue;
			int val1 = pos[j][lo];
			lo = -1, hi = pos[j].size()-1;
			//find last guy who is <= i
			while (lo != hi) {
				int mid = (lo+hi+1)/2;
				int x = pos[j][mid];
				if (r[x][k] > i) {
					hi = mid-1;
					continue;
				}
				if (r[r[x][k]][v[i]] > i)
					hi = mid-1;
				else
					lo = mid;
			}
			if (lo == -1)
				continue;
			int val2 = pos[j][lo];
			if (val1 > val2)
				continue;
			dp[i][v[i]] = (dp[i][v[i]] + part[val2+1][j][v[i]] + p - part[val1][j][v[i]])%p;
		}
		dp[i][v[i]] = (dp[i][v[i]] + dp[i-1][v[i-1]])%p;
	}

	ll ans = 0;
	for (int i = 0; i < n-2; ++i) {
		if (v[i] == v[n-1])
			continue;
		int k = 3-v[i]-v[n-1];
		if (r[i][k] >= n)
			continue;
		if (r[r[i][k]][v[n-1]] >= n)
			continue;
		ans = (ans + dp[i][v[i]])%p;
	}
	ans = (ans + dp[n-2][v[n-2]])%p;
	int g = -1;
	for (int i = n-1; i >= -1; --i) {
		if (i == -1)
			g = -1;
		if (v[i] == v[n-2])
			g = i;
		if (v[i] == 3-v[n-2]-v[n-1])
			break;
	}
	if (g != -1) {
		for (int k = g; k < n-2; k += 2)
			ans = (ans + dp[k][v[k]])%p;
	}
	cout << ans << endl;
}

Measured memory_bytes: 13564
import Control.Monad
import Data.List
main = do
    [n, m] <- map read . words <$> getLine
    l <- map (map (read :: String -> Int) . words) <$> replicateM m getLine
    print $ length $ (\[x, y] -> [x..y]) $ foldl1' sub l
    where sub [a, b] [c, d] = [max a c, min b d]


Measured memory_bytes: 100732
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <queue>
#include <utility>
using namespace std;

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

#define For(i, a, b) for(int i = (a); i < (b); i++)
#define Rep(i, n) For(i, 0, (n))

//const int inf = 999999999;
const ll inf = 99999999999;
const int mod = 1000000007;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

int main(){
	ll n; cin >> n;
	ll a[n]; fill((ll*)a, (ll*)a + sizeof(a)/sizeof(ll), 0);
	Rep(i, n) Rep(j, 10){
		ll x; cin >> x;
		if(x == 1) a[i] += (1 << j);
	}
	ll p[n][11];
	Rep(i, n) Rep(j, 11){
		ll x; cin >> x;
		p[i][j] = x;
	}
	ll ans = -inf;
	For(i, 1, 1 << 10){
		ll t = 0;
		Rep(j, n){ 
			ll count = 0;
			Rep(k, 10){
				if( (i & (1 << k)) & (a[j] & (1 << k)) ){
					count += 1;
				}
			}
			t += p[j][count];
		}
		ans = max(ans, t);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int int64_t
#define REP(i, n) for (int i = 0; (i) < (int)(n); ++ (i))
#define REP3(i, m, n) for (int i = (m); (i) < (int)(n); ++ (i))
#define REP_R(i, n) for (int i = (int)(n) - 1; (i) >= 0; -- (i))
#define REP3R(i, m, n) for (int i = (int)(n) - 1; (i) >= (int)(m); -- (i))
#define REPP(i, n) for (int i = 1; (i) < (int)(n+1); ++ (i))
#define REPR(i, n) for (int i = (int)(n) - 1; (i) >= 0; -- (i))
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define FORR(i, m, n) for(int i=(m)-1; i>=(n); i--)
#define ALL(v) v.begin(), v.end()
#define SZ(a) int((a).size())
#define SORT(c) sort((c).begin(),(c).end())
#define SORTR(c) sort((c).begin(),(c).end(),greater<int>());
#define BIT(n) (1LL<<(n))
#define PCNT(x) __builtin_popcountll(x)
#define GCD(x,y) __gcd(x,y)
#define LCM(x,y) x/__gcd(x,y)*y
#define PB push_back
#define MP make_pair
#define endl "\n"
#define pa cout << ans << endl
#define p(x) cout << x << endl
#define pall(x) for(auto iter : x) p(iter)
#define yes cout << "Yes" << endl
#define no cout << "No" << endl
#define yn(x) cout << (x ? "Yes" : "No") << endl
using namespace std;
using Graph = vector<vector<int> >;
using WeightedGraph = vector<vector<pair<int, int> > >;
typedef long double LD;
typedef vector<int> VI;
typedef vector<vector<int> > VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
const int MOD = 1000000007;
const int INF = 2000000000;
const long double PI = acosl(-1);
void print() {cout << endl;}
template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) {cout << head; if (sizeof...(tail) != 0) cout << " ";print(forward<Tail>(tail)...);}
template <class T> void print(vector<T> &vec) {for (auto& a : vec) {cout << a; if (&a != &vec.back()) cout << " ";} cout << endl;}
template <class T> void print(vector<vector<T>> &df) { for (auto& vec : df) { print(vec);}}
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; }

signed main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    cout << fixed << setprecision(10);
    int A, B, M;
    cin >> A;
    vector<int> a(A);
    cin >> B;
    vector<int> b(B);
    cin >> M;
    vector<int> x(M), y(M), c(M);
    REP (i, A) {
        cin >> a[i];
    }
    REP (i, B) {
        cin >> b[i];
    }
    REP (i, M) {
        cin >> x[i] >> y[i] >> c[i];
    }

    int ans = *min_element(ALL(a))+(*min_element(ALL(b)));
    REP(i,M) ans = min(ans, a[x[i]-1]+b[y[i]-1]-c[i]);
    pa;

    
    
    return 0;
}

/*
cd ~/Desktop/Programming/AtCoder/contest/hitachi2020/hitachi2020_b && sh test.sh
cd ~/Desktop/Programming/AtCoder/contest/hitachi2020/hitachi2020_b && sh etest.sh
cd ~/Desktop/Programming/AtCoder/contest/hitachi2020/hitachi2020_b && sh submit.sh
*/


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

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define watch(a) { cout << #a << " = " << a << endl; }
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }

typedef long long ll;
int const inf = 1<<29;

int main() {

  static ll dp[55][55][2555];
  int N, A; cin >> N >> A;

  int xs[N]; rep(i, N) cin >> xs[i];

  dp[0][0][0] = 1;

  rep(i, N) rep(k, N) {
    rep(j, 2501) {
      dp[i+1][k][j]         += dp[i][k][j];
      dp[i+1][k+1][j+xs[i]] += dp[i][k][j];
    }
  }
  
  ll ans = 0;

  REP(k, 1, N + 1) {
    ans += dp[N][k][A * k];
  }

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

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

#define ll long long
#define ar array

const int M=1e9+7;
ll iv[400000], f1[400000], f2[400000]; 
//f1 stores factorial of all numbers %M and f2 stores inverse factorial of all numbers%M

ll nck(int n, int k) {
 //this is the n Choose k combinatorial function
  //this calculated fast ie O(1) using precomputation of factorial and inverse factorials
/*
 long long binomial_coefficient(int n, int k) {
    return factorial[n] * inverse(factorial[k]) % m * inverse(factorial[n - k]) % m;
} */
  return f1[n]*f2[n-k]%M*f2[k]%M;
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  /* Finding modular inverse for every number modulo M (which must be a prime)
   Here we present a better algorithm with complexity O(m). However for this specific algorithm we require that the modulus m is prime.

We denote by inv[i] the modular inverse of i. Then for i>1 the following equation is valid:

///Principle formula///
inv[i]=−⌊m/i⌋⋅inv[m mod i]mod m

Thus the implementation is very simple:

inv[1] = 1;
for(int i = 2; i < m; ++i)
    inv[i] = (m - (m/i) * inv[m%i] % m) % m;


proof at : https://cp-algorithms.com/algebra/module-inverse.html#mod-inv-all-num
*/
  iv[1]=1;
  for(int i=2; i<4e5; ++i)
    iv[i]=M-M/i*iv[M%i]%M;
  f1[0]=f2[0]=1;
  for(int i=1;i <4e5; ++i) {
    f1[i]=f1[i-1]*i%M;
    f2[i]=f2[i-1]*iv[i]%M;
  }
  int n, k;
  cin >> n >> k;
  /* Main Question's logic
  E. Roaming
  n people, n rooms, k roaming moves, find number of ways of people staying there,
  
  */
  ll ans=nck(2*n-1, n-1); //Application of star and bars theorem
  //so from k+1 to n-1 we find the number of ways and subtract them, because in the end we only want k strict zeros
  for(++k; k <= n-1; ++k) {
    //k zeros
    //k fit in n-k
    ans=(ans+M-nck(n, k)*nck(n-1, n-k-1)%M)%M;
  }
  cout << ans;
}


Measured memory_bytes: 13036
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val n = sc.nextInt()
    val m = sc.nextInt()
    val c = sc.nextInt()
    val b = (1..m).map { sc.nextInt() }
    var ans = 0
    repeat(n) {
        val cost = (0 until m).map { sc.nextInt() * b[it] }.sum() + c
        if (cost > 0) {
            ans++
        }
    }
    println(ans)
}

Measured memory_bytes: 31640
#include <iostream>
#include <vector>

const int MOD = 1000 * 1000 * 1000 + 7;

int main(void) {
  int n, m;
  std::cin >> n >> m;
  std::vector<int> s(n);
  std::vector<int> t(m);
  for (int i = 0; i < n; ++i) {
    std::cin >> s[i];
  }
  for (int i = 0; i < m; ++i) {
    std::cin >> t[i];
  }
  int sl = n + 1;
  int tl = m + 1;
  std::vector<int64_t> dp(sl * tl);
  std::vector<int64_t> sum(sl * tl);

  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) {
      if (s[i - 1] == t[j - 1]) {
        dp[i * tl + j] = (sum[(i - 1) * tl + j - 1] + 1) % MOD;
      }
      sum[i * tl + j] = (sum[(i - 1) * tl + j] + sum[i * tl + j - 1] -
                         sum[(i - 1) * tl + j - 1] + dp[i * tl + j] + MOD) %
                        MOD;
    }
  }

  std::cout << (sum[n * tl + m] + 1) % MOD << std::endl;

  return 0;
}


Measured memory_bytes: 62848
import java.io.*;
import java.util.*;

class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n=Integer.parseInt(br.readLine());
        long[] array=new long[n];
        StringTokenizer st=new StringTokenizer(br.readLine());
        long sum=0;
        for(int i=0;i<n;i++){ array[i]=Long.parseLong(st.nextToken()); sum+=array[i]; }
        Arrays.sort(array);
        System.out.println(array[0]+" "+array[n-1]+" "+sum);
    }
}

Measured memory_bytes: 29408
MOD=1000000007
def fact(x):
    k=1
    for i in range(x+1):
        if i!=0:
            k=(k*i)%MOD
    return k

def inverse(b):
    r=1;e=MOD-2
    while e:
        if (e%2==1):
            r = (r*b)%MOD
        b=(b*b)%MOD
        e>>=1
    return r

def Comb(i,j):
    if i==0 or j==0:
        return 0
    num=fact(i+j)
    num*=inverse(fact(i))
    num%=MOD
    num*=inverse(fact(j))
    num%=MOD
    return num
    
r1,c1,r2,c2 = map(int,input().split())
#おなじみパスカル行列を区間で和を取ろうという問題
#F[n][r]=nCr(n+r,r)と、
#G[a][b]をΣ[i,0~a-1](Σ[j,0~b-1](F[i][j]))と表す
#ここで、G[a][b]をO(N)くらいで計算できれば勝ち
#ところで、G[a][b]=F[a+1][b+1]-1になる
#なので、それぞれのGをO(N+logMOD)で計算できるのでAC
Ans=0
Ans+=Comb(r2+1,c2+1)
Ans-=Comb(r1,c2+1)
Ans-=Comb(r2+1,c1)
Ans+=Comb(r1,c1)
Ans+=MOD;Ans+=MOD;Ans%=MOD

print(Ans)

Measured memory_bytes: 38640
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
typedef long long int lli;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    lli n;
    cin>>n;
    lli i,j,ending,a[12],tot=n,ans[12]={0};
    
    a[0]=1;
    for(i=1;i<12;i++) a[i]=a[i-1]*26;
    
    for(i=0;i<12;i++)
    {
        if(a[i]<=tot)
        {
            ending=i;
            tot-=a[i];
            ans[i]=1;
        }
    }
    
    for(i=ending;i>=0;i--)
    {
        for(j=1;j<=26;j++)
        {
            if(a[i]<=tot)
            {
                ans[i]++;
                tot-=a[i];
            }
        }
    }
    
    for(i=11;i>=0;i--)
    {
        if(ans[i]>0)
        {
            cout<<(char)(ans[i]+'a'-1);
        }
    }
    return 0;
}

Measured memory_bytes: 3644
N=int(input())
A=list(map(int,input().split()))
B=[]
#N-1から-1まで逆順に
for i in range(N-1,-1,-1):
  #iスタートから終わるまで、（i+1）ずつ加算
  #3（A[2]）,6,9…
  A[i]=(sum(A[i::i+1])%2)&1
  
B=[i+1 for i in range(N) if A[i]]
print(len(B))
if len(B)>0:
  print(*B)

Measured memory_bytes: 12724