akhauriyash/Code-Regression huggingface dataset:
use std::io::*;
use std::str::*;
#[allow(unused_imports)]
use std::collections::*;

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

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

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

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

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

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

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

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

fn main() {
    input!{
        v:[usize;3]
    }
    let mut v = v;
    v.sort();
    println!("{}", v[2] * 10 + v[1] + v[0]);
}


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

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

ll N;
int kakuinowa(ll A){
    int ret = 0;
    int i;
    FOR(i,5){
        int amari = A % 10;
        ret += amari;
        A /= 10;
    }
    return ret;
}

void solve() {
    //,j,k,l,r,x,y; string s;
    bool exit = false;
    ll A;
    cin>>N;
    int ret = INT_MAX;
    FOR(A, N){
        if (A==0)
            continue;
        int x = kakuinowa(A)+kakuinowa(N-A);
        if(x<ret)
            ret = x;
    }
    cout<<ret<<endl;
    /*cin>>N;
    vector<ll> V;
    FOR(x,N+1) {
            FOR(y,N+1) {
                    ll ret=1;
                    FOR(i,x) ret*=2;
                    FOR(i,y) ret*=5;
                    V.push_back(ret);
            }
    }
    sort(ALL(V));
    FORR(v,V) cout<<v<<endl;*/
}


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



Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <string>
#include <numeric>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <vector>
using namespace std;
#define INF 1000000007
#define ll long long
#define rep(i_, __start, __end) for(ll i_=(ll)__start; i_<(ll)__end; i_++)
#define print(_a) cout << _a << endl;
#define printarray(a, len) rep(ii,0,len) cout << a[ii] << " ";
#define printarray2(aa, len) rep(ij,0,len) printarray(aa[ij], aa[ij].size()); print("");


int main(){
    ll a, b, c;
    cin >> a >> b >> c;
    print(max(max(a, b), c) * 10 + a + b + c - max(max(a, b), c));
   
  return 0;
}

Measured memory_bytes: 256
import heapq

N = int(input())
A = list(map(int, input().split()))

pre = A[:N]
epi = A[2*N:]
epi = [epi[j]*(-1) for j in range(N)]
t_pre = sum(pre)
t_epi = sum(epi)

heapq.heapify(pre)
heapq.heapify(epi)

pre_sum = []
epi_sum = []

pre_sum.append(t_pre)

for i in range(N):
	t_push = A[N+i]
	heapq.heappush(pre, t_push)
	t_pop = heapq.heappop(pre)
	t_pre = t_pre + t_push - t_pop
	pre_sum.append(t_pre)


epi_sum.append(t_epi)

for i in range(N):
	t_push = A[-(N+i+1)] * (-1)
	heapq.heappush(epi, t_push)
	t_pop = heapq.heappop(epi)
	t_epi = t_epi + t_push - t_pop
	epi_sum.append(t_epi)

epi_sum = [epi_sum[-i] for i in range(1,N+2)]
ans = []

for i in range(N+1):
	ans.append(pre_sum[i]+epi_sum[i])

print(max(ans))

Measured memory_bytes: 40340
#include <stdio.h>
#include <string.h>
int main(){
  
  char s[100000] = "";
  int max;
  int cnt = 0;
  int cnt_0 = 0;
  int cnt_1 = 0;
  
  scanf("%s", s);

  max = strlen(s);

  for(int i = 0; i < max; i++){
    if(s[i] == '0'){
      cnt_0++;
    }else if(s[i] == '1'){
      cnt_1++;
    }
  }

  if(cnt_0 >= cnt_1){
    printf("%d\n",  cnt_1 * 2);
  }else{
    printf("%d\n",  cnt_0 * 2);
  }
  
  
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#define LL long long 
LL H, W, A, B;
LL mod = 1000000007;
LL mul[200010];
LL dis[200010];
LL ans;
LL fermat(LL x, LL y) {
	//std::cout << y << std::endl;
	if (y == 0) return 1;
	if (y == 1)	return x;
	if (y % 2 == 1) {
		LL F = fermat(x, y / 2);
		F *= F;
		F%=mod;
		return F*x%mod;
	}
	if (y % 2 == 0) {
		LL F = fermat(x, y / 2);
		F *= F;
		return F%mod;
	}
}

int main() {
	std::cin >> H >> W >> A >> B;
	mul[1] = 1;
	mul[0] = 1;
	for (LL i = 1; i <= H + W - 2; i++) {
		mul[i] = mul[i - 1] * i;
		mul[i]%=mod;
		dis[i] = fermat(mul[i], mod - 2);
	}
	dis[0] = 1;
	for (LL i = B; i < W; i++) {
		LL plus = mul[H - A + i - 1];
		plus %= mod;
		plus *= dis[i];
		plus %= mod;
		plus *= dis[H - A - 1];
		plus %= mod;
		plus *= mul[W + A - i - 2];
		plus %= mod;
		plus *= dis[A - 1];
		plus %= mod;
		plus *= dis[W - i - 1];
		plus %= mod;
		ans += plus;
		ans %= mod;
	}
	std::cout << ans << std::endl;
	return 0;
}

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

int main() {

  char str[1050] = {0};
  char ch[1050] = {0};
  char mei[30] = {0};
  char pl[1050]={0};
  int i,j,k,l,m,n,o,p;

 
  scanf("%s",str);
  scanf("%d",&n);
   
  for(i=0; i<7 ;i++) {
    ch[i] = str[i];
  }

  j=0;
  o=0;
  k=l=0;

  for ( i = 0; i < n; i++ ){
    scanf("%s", mei);
    scanf("%d %d", &k, &l);
    // printf("mei= %s",mei);
  
    
    if(mei[2] =='p') {
     
      scanf("%s", pl);

      for(m=0;m<l-k+1;m++) {

	//	printf("str[%d]%c = pl[%d]%c\n",m+k,str[m+k] ,m,pl[m]);
	str[m+k] = pl[m];	
      }
    }

    else if(mei[2] == 'v') {
      
      for(m=0; m<strlen(str);m++) {
	ch[m] = str[m];
      }
      
      for(m=0;m<l-k+1;m++) {
	//	printf("str[%d]%c = ch[%d]%c\n",k+m,str[k+m],l-m,ch[l-m]);
	str[k+m] = ch[l-m];
      }
    
    }

    else if(mei[0] = 'p') {   
      
      for(m=k; m<=l;m++) {
	printf("%c" ,str[m]);
      }
      printf("\n");
    }
    
  }

   
  return 0;

}



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

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

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

    int ans = c;
    ans = min(c, b / a);
    cout << ans << endl;
    
}

Measured memory_bytes: 256
#include <stdio.h>

int min(int a, int b) {
  return (a < b) ? a : b;
}

char S[1000001], *s;
int main(void) {
  int f[] = {0, 1, 2, 3, 4, 5, 5, 4, 3, 2, 1};
  int a = 0, b = 1, tmp;
  int x;
  scanf("%s", &S);
  for (s = S; *s; ++s) {
    x = *s - 48;
    tmp = min(a + f[x], b + f[10 - x]);
    b = min(a + f[1 + x], b + f[9 - x]);
    a = tmp;
  }
  printf("%d\n", a);
  return 0;
}

Measured memory_bytes: 1152
let ans, x, a_s = Scanf.(scanf "%d %d" @@ fun n x -> ref 0, x, Array.init n @@ fun _ -> scanf " %d" (+) 0)
let _ = Array.iteri (fun i a -> if i > 0 then let m = max 0 @@ a_s.(i - 1) + a - x in a_s.(i) <- max 0 @@ a - m; ans := !ans + m) a_s; Printf.printf "%d\n" !ans

Measured memory_bytes: 5504
#define _CRT_SECURE_NO_WARNINGS
//#define _USE_MATH_DEFINES
#include<stdio.h>
//#include<stdlib.h>
//#include<math.h>
//#include<string.h>
#define P(type,x) fprintf(stdout,"%"#type"\n",x)
int main() {
	int d,c;
	fscanf(stdin, "%d%d", &d, &c);
	P(d, d*c);
	return 0;
}

Measured memory_bytes: 600
from itertools import permutations
N,M = map(int,input().split())
G = {i:[] for i in range(1,N+1)}
for _ in range(M):
    a,b = map(int,input().split())
    G[a].append(b)
    G[b].append(a)
cnt = 0
for x in permutations(range(2,N+1),N-1):
    flag = 0
    for i in range(N-1):
        if i==0:
            if x[0] in G[1]:continue
            else:
                flag = 1
                break
        if x[i] in G[x[i-1]]:continue
        else:
            flag = 1
            break
    if flag==0:
        cnt += 1
print(cnt)

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

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

typedef long long int64;

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

  vector<int> p(n);

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

  int cnt = 0;
  
  for(int i=1; i<n-1; i++){
    if(p[i-1] > p[i] && p[i+1] < p[i]) cnt++;
    else if (p[i-1] < p[i] && p[i+1] > p[i]) cnt++;
  }

  cout << cnt << endl;

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <map>
#include <queue>

using namespace std;

int main()
{
	string s;
	while (cin >> s, s[0] != '0') {
		map<string, bool> m;

		queue<string> q, r;

		q.push(s);

		int cnt = 0;

		while (q.size()) {
			while (q.size()) {
				string t = q.front(); q.pop();
				if (m[t]) continue;
				m[t] = true;
				bool f = true;
				for (int i = 0; i < t.size() - 1; ++i) {
					if ((t[i] == 'r' && t[i + 1] == 'b') || (t[i] == 'b' && t[i + 1] == 'r')) {
						char c = t[i], d = t[i + 1];
						t[i] = t[i + 1] = 'g';
						r.push(t);
						t[i] = c, t[i + 1] = d;
						f = false;
					} else if ((t[i] == 'b' && t[i + 1] == 'g') || (t[i] == 'g' && t[i + 1] == 'b')) {
						char c = t[i], d = t[i + 1];
						t[i] = t[i + 1] = 'r';
						r.push(t);
						t[i] = c, t[i + 1] = d;
						f = false;
					} else if ((t[i] == 'r' && t[i + 1] == 'g') || (t[i] == 'g' && t[i + 1] == 'r')) {
						char c = t[i], d = t[i + 1];
						t[i] = t[i + 1] = 'b';
						r.push(t);
						t[i] = c, t[i + 1] = d;
						f = false;
					}
				}
				if (f) {
					cout << cnt << endl;
					goto nxt;
				}
			}
			while (r.size()) {
				string t = r.front(); r.pop();
				q.push(t);
			}
			cnt++;
		}

		cout << "NA" << endl;
nxt:;
	}
}

Measured memory_bytes: 3316
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=2e5+50;
inline int gi() {
  char ch=getchar(); int q=0,x=0;
  while(ch<'0'||ch>'9') q=(ch=='-'?1:q),ch=getchar();
  while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
  return q?(-x):x;
}
int a[N],b[N];
ll sa[N],sb[N];
int main(){
  int L=gi(),n=gi();
  for (int i=1; i<=n; ++i){
    a[i]=gi(),b[i]=L-a[i];
    sa[i]=sa[i-1]+a[i],sb[i]=sb[i-1]+b[i];
  }
  ll ans=0;
  for (int i=1; i<=n; ++i){
    int t=min(i-1,n-i);
    ans=max(ans,2*(sa[i-1]-sa[i-t-1]+sb[i+t]-sb[i])+a[i]);
    t=min(i,n-i);
    ans=max(ans,2*(sa[i]-sa[i-t]+sb[i+t]-sb[i])-a[i]);
  }
  for (int i=1; i<=n; ++i)
    swap(a[i],b[i]);
  reverse(a+1,a+n+1),reverse(b+1,b+n+1);
  for (int i=1; i<=n; ++i)
    sa[i]=sa[i-1]+a[i],sb[i]=sb[i-1]+b[i];
  for (int i=1; i<=n; ++i){
    int t=min(i-1,n-i);
    ans=max(ans,2*(sa[i-1]-sa[i-t-1]+sb[i+t]-sb[i])+a[i]);
    t=min(i,n-i);
    ans=max(ans,2*(sa[i]-sa[i-t]+sb[i+t]-sb[i])-a[i]);
  }
  cout<<ans;
  return 0;
}

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

using ll = long long;
using Pi = pair < ll, ll >;

int main()
{
	int N, M;
	Pi dat[100005];
	
	cin >> N >> M;

	for ( int i = 0; i < N; i++ ) {
		cin >> dat[i].first >> dat[i].second;
	}

	sort(dat, dat + N);

	ll ans = 0;
	for ( int i = 0; i < N; i++ ) {
		if ( dat[i].second < M ) {
			ans += dat[i].first * dat[i].second;
			M -= dat[i].second;
		} else {
			ans += dat[i].first * M;
			M = 0;
			break;
		}
	}

	cout << ans << endl;

	return ( 0 );
}


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

#define ln                '\n'
#define all(dat)           dat.begin(), dat.end()
#define loop(i, to)        for (int i = 0; i < to; ++i)
#define cont(i, to)        for (int i = 1; i <= to; ++i)
#define circ(i, fm, to)    for (int i = fm; i <= to; ++i)
#define foreach(i, dat)    for (__typeof(dat.begin()) i = dat.begin(); i != dat.end(); ++i)

typedef long long          num;

using namespace std;

template<int mod>
struct modulo {
	int w;
	operator int&() { return w; }
	
	modulo() {}
	modulo(int w, bool f = 0) { this->w = w; if (f) fix(); }
	void inline fix() { w %= mod; if (w < 0) w += mod; }
	modulo inline fix(int w) const { w %= mod; if (w < 0) w += mod; return w; }
	
	inline modulo& operator += (const modulo &b) { if ((w += b.w) >= mod) w -= mod; return *this; }
	inline modulo& operator -= (const modulo &b) { if ((w -= b.w) < 0) w += mod; return *this; }
	inline modulo& operator *= (const modulo &b) { w = (num) w * b.w % mod; return *this; }
	inline modulo& operator /= (const modulo &b) { w = (num) w * b.inv() % mod; return *this; }
	inline modulo  operator +  (const modulo &b) { modulo r = *this; r += b; return r; }
	inline modulo  operator -  (const modulo &b) { modulo r = *this; r -= b; return r; }
	inline modulo  operator *  (const modulo &b) { modulo r = *this; r *= b; return r; }
	inline modulo  operator /  (const modulo &b) { modulo r = *this; r /= b; return r; }
	
	modulo inline inv() const {
		int a = w, m = mod, u = 0, v = 1, t;
		for (; a != 0; t = m / a, m -= t * a, swap(a, m), u -= t * v, swap(u, v));
		return fix(u);
	}
	
	modulo inline pow(int p) const {
		if (!w)  return 0;
		modulo a = *this, r = 1;
		for (; p > 0; a *= a, p >>= 1) if (p & 1) r *= a;
		return r;
	}
};
const int mod = int(1e9 + 7);
typedef modulo<mod> rem;

const int nsz = int(5e3);
int n, k, a[nsz + 5];
rem dp[nsz + 5], ans;
vector<int> r;

struct union_find {
	int pr[nsz + 5], siz[nsz + 5];
	
	union_find() {
		cont (u, nsz) pr[u] = u, siz[u] = 1;
	}
	
	int inline operator [] (int id) { return qry(id); }
	
	int qry(int u) { return pr[u] == u ? u : pr[u] = qry(pr[u]); }
	
	bool inline link(int u, int v) {
		int pu = qry(u), pv = qry(v);
		if (pu == pv) return 0;
		pr[pv] = pu;
		siz[pu] += siz[pv];
		return 1;
	}
};
union_find uf;

int main() {
	scanf("%d", &n);
	cont (i, n) {
		scanf("%d", &a[i]);
		if (a[i] != -1) uf.link(a[i], i);
		if (a[i] == -1) r.push_back(i);
	}
	k = int(r.size());
	
	cont (u, n) {
		if (uf[u] != u || a[u] == -1) continue;
		ans += rem(n - 1).pow(k);
	}
	
	dp[0] = 1;
	loop (i, k) {
		int sz = uf.siz[r[i]];
		for (int j = i; j >= 0; --j) {
			dp[j + 1] += dp[j] * (j ? rem(j) : rem(1)) * rem(sz);
		}
	}
	
	cont (j, k) {
		ans += dp[j] * rem(n - 1).pow(k - j);
	}
	cont (u, n) {
		if (uf[u] != u || a[u] != -1) continue;
		ans -= rem(n - 1).pow(k - 1);
	}
	
	ans = rem(n) * rem(n - 1).pow(k) - ans;
	printf("%d\n", ans);
}

Measured memory_bytes: 3916
#include<bits/stdc++.h>
using namespace std;
#define INF 1<<28
#define ll long long
#define MOD 998244353

int n, a[100005];
ll dp[100005];

ll frog(int i)
{
    if(dp[i]!=-1)
        return dp[i];

    dp[i] = min(frog(i-1)+abs(a[i] - a[i-1]), frog(i-2)+abs(a[i] - a[i-2]));

    return dp[i];
}

int main()
{
    memset(dp, -1, sizeof(dp));
    cin>>n;
    for(int i = 0; i < n; i++)
        cin>>a[i];

    dp[0] = 0;
    dp[1] = abs(a[0] - a[1]);

    cout<<frog(n-1)<<endl;
    return 0;
}


Measured memory_bytes: 2944
def selectionsort(a, n):
    n_exchange = 0
    for i in range(0, n):
        min_j = i
        for j in range(i, n):
            if a[j] < a[min_j]:
                min_j = j

        if a[i] != a[min_j]:
            n_exchange += 1

        a[i], a[min_j] = a[min_j], a[i]

    return a, n_exchange


n = int(input())
a = list(map(int, input().split()))

sorted_a, n_exchange = selectionsort(a, n)

print(' '.join([str(x) for x in sorted_a]))
print(n_exchange)



Measured memory_bytes: 5604
#include <bits/stdc++.h>
using namespace std;
void __print(int x) {cout << x;}
void __print(long x) {cout << x;}
void __print(long long x) {cout << x;}
void __print(unsigned x) {cout << x;}
void __print(unsigned long x) {cout << x;}
void __print(unsigned long long x) {cout << x;}
void __print(float x) {cout << x;}
void __print(double x) {cout << x;}
void __print(long double x) {cout << x;}
void __print(char x) {cout << '\'' << x << '\'';}
void __print(const char *x) {cout << '\"' << x << '\"';}
void __print(const string &x) {cout << '\"' << x << '\"';}
void __print(bool x) {cout << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cout << '{'; __print(x.first); cout << ','; __print(x.second); cout << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cout << '{'; for (auto &i: x) cout << (f++ ? "," : ""), __print(i); cout << "}";}
void _print() {cout << "\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cout << ", "; _print(v...);}
#define debug(x...) cout << #x << " = "; _print(x)
typedef long long ll; typedef vector<int> vi; typedef vector<ll> vll;
#define rep(i,a,b) for (int i = (a); i < (b); ++i)
#define per(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define all(x) begin(x), end(x)
#define mp make_pair 
#define pb push_back
#define ff first
#define ss second
#define fast ios_base::sync_with_stdio(NULL);cin.tie(NULL);cout.tie(NULL) 

int solve(){
	int a, b, k;
	cin>> k>> a>> b;
	rep(i, a, b + 1)
		if(i%k == 0)
			return cout<< "OK", 0;
	cout<< "NG";
	return 0;
}
 
int main()
{
	fast;
	int t = 1;
	//cin>> t;
	while(t--){  
		solve();
	}
	return 0;
}
//upper_bound returns an iterator pointing to the 
//first element in the range [first,last) which has a value greater than ‘val’
//v.clear(), vis.clear(); vis.resize(n + 1, 0), v.resize(n + 1);

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

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

def lcm(a, b):
    return a * b // gcd (a, b)

if A%C == 0:
    start1 = A // C
else:
    start1 = A // C
    start1 += 1


if A%D == 0:
    start2 = A // D
else:
    start2 = A // D
    start2 += 1


tmp = lcm(C, D)


if A%(C*D) == 0:
    start3 = A // tmp
else:
    start3 = A // tmp
    start3 += 1

end1 = B // C
end2 = B // D
end3 = B // tmp


res = (B - A + 1) - (end1 - start1 + 1) - (end2 - start2 + 1) + (end3 - start3 + 1)


print(res)

Measured memory_bytes: 38384
n,k,*d=map(int,open(0).read().split())
c=0
for i in range(n*10):
  if n<=i:
    for j in str(i):
      if not int(j) in d:
        c+=1
      if c==len(str(i)):
        print(i)
        exit()
    c=0

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <math.h>
using namespace std;

int main() {

    int N;
    cin >> N;
    int A[30];
    int B[30];
    int C[30];
    int sum = 0;
    for(int i = 0; i < N; i++) {
        cin >> A[i];
    }
    for(int i = 0; i < N; i++) {
        cin >> B[i];
    }
    for(int i = 0; i < N - 1; i++) {
        cin >> C[i];
    }
    for(int i = 0;i < N; i++) {
        int k = A[i];
        sum += B[k -1];
        if(i > 0) {
        if(A[i] - 1 == A[i - 1]) {
            sum += C[A[i-1] - 1];
        }
        }
    }
    cout << sum << endl;
    return 0;
}

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

typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
typedef vector <ll> vec;
typedef pair <ll, ll> pr;
typedef pair <ll, pr> pr2;
typedef map <ll, vector<ll> > mv;

const int MX = 2e6+10;
const int mod = 998244353;
const ll inf = 1LL << 62;

int dx4[] = { 0, 0, -1, 1 };
int dy4[] = { 1, -1, 0, 0 };

int dx[] = { 1, 1, 1, 0, 0, -1, -1, -1 };
int dy[] = { 1, 0, -1, 1, -1, 1, 0, -1 };

// TOOLS
#define LCM(a,b)        (a / __gcd(a,b) ) *b
#define gcd(a,b)        __gcd(a,b)
#define all(x)          (x).begin(), (x).end()
#define mem(a, n)       memset(a, n, sizeof(a))
#define for1(i, n)      for(int i=1; i<=n; i++)
#define for0(i, n)      for(int i=0; i<n; i++)
#define rof0(i, n)      for(int i=n-1; i>=0; i--)
#define rof1(i, n)      for(int i=n; i>=1; i--)
#define forab(i, a, b)  for(int i=a; i<=b; i++)
#define rofab(i, a, b)  for(int i=b; i>=a; i--)
#define pb              push_back
#define pbb             pop_back

// CIN/COUT
#define sin(s)          getline(cin, s)
#define case(a)              cout << "Case "<<(a)<<": "

// SCANF/PRINTF
#define fYES            printf("YES\n")
#define fNO             printf("NO\n")
#define Scf(a)          scanf("%lld", &a)
#define Scf2(a, b)      scanf("%lld %lld", &a, &b)
#define Scf3(a, b, c)   scanf("%lld %lld %lld", &a, &b, &c)
#define Scf4(a,b,c,d)   scanf("%lld %lld %lld %lld", &a, &b, &c, &d)
#define Pnf(a)          printf("%lld\n", a)
#define Pnf2(a, b)      printf("%lld %lld\n", a, b)
#define Pnf3(a, b, c)   printf("%lld %lld %lld\n", a, b, c)
#define Bug(n)          printf(">> %lld <<\n", n)

// OTHERS
#define sz(n)          n.size()
#define clr(v)          v.clear()
#define min3(a, b, c)   min(a, min(b, c))
#define max3(a, b, c)   max(a, max(b, c))
#define in              freopen("input.txt", "r", stdin)
#define out             freopen("output.txt", "w", stdout)
#define FastIO          { ios_base::sync_with_stdio(false); cin.tie(0); }
#define F               first
#define S               second
#define mpp             make_pair
//End
int mark[100010],mark1[100010];
map<ll,vector<ll> > mp,mp1;
priority_queue<pair<ll,ll> > PQ;
vector<ll > v,v1;
set<int>S;
int n;
ll dp[200001][3];
ll Dp(int i,int last)
{
    ll temp=0,temp1=0;
    if(i==n-1)
    {
        if(last==0)
            return v[n-1];
        else
            return (v[n-1]*-1);
    }
    if(dp[i][last]!=-1)
        return dp[i][last];
    if(last==0)
    {
        temp=v[i]+Dp(i+1,0);
        temp1=(v[i]*-1)+Dp(i+1,1);
    }
    else
    {
        temp=(v[i]*-1)+Dp(i+1,0);
        temp1=v[i]+Dp(i+1,1);
    }
    dp[i][last]=max(temp,temp1);
    return dp[i][last];
}
int main()
{

    ll m, k, q, t, cnt = 0, sum = 0,ans=0, mx = -inf, mn = inf, a, b, c,d,e,f,g,h,i,j,x, y, z,temp, temp1;
    string s, s1, s2, s3,s4,s5,s6,s7;
    cin>>n;
    for0(i,n)
    {
        cin>>a;
        v.pb(a);
    }
    for0(i,n+5)
    {
        dp[i][0]=-1;
        dp[i][1]=-1;
    }
    cout<<Dp(0,0)<<endl;
    return 0;
}


Measured memory_bytes: 9972
#include<bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){return b!=0?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}

const ll mod=1e9+7;

ll modfact(ll n){
    if(n==1) return 1;
    return n*modfact(n-1)%mod;
}

int main(){
    ll n,m;
    cin>>n>>m;
    if(abs(n-m)>1) cout<<0<<endl;
    else if(n==m) cout<<2*modfact(n)*modfact(m)%mod<<endl;
    else cout<<modfact(n)*modfact(m)%mod<<endl;
    return 0;
}

Measured memory_bytes: 1792
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <string>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
using namespace std;

int main() {
    string s;
    cin >> s;
    int N = s.length();
    bool ok = true;
    for (int i = 0; i <= N/2; ++i) {
        if (s[i] != s[N-i-1]) {
            ok = false;
            break;
        }
    }
    N /= 2;
    for (int i = 0; i <= N / 2; ++i) {
        if (s[i] != s[N-i-1]) {
            ok = false;
            break;
        }
    }
    if (ok) {
        cout << "Yes\n";
    } else {
        cout << "No\n";
    }
    return 0;
}


Measured memory_bytes: 256
//https://atcoder.jp/contests/abc064/tasks/abc064_d
#include <bits/stdc++.h>
using namespace std;
using ll=int64_t;
#define FOR(i,a,b) for(int64_t i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
int main() {
#if LOCAL&01
    std::ifstream in("./test/sample-1.in"); //input.txt
    std::cin.rdbuf(in.rdbuf());
#else
    cin.tie(0);
    ios::sync_with_stdio(false);
#endif
    ll N; cin>>N;
    string S; cin>>S;
    ll count=0;
    ll head=0;
    REP(i,S.size()){
        auto c = S.at(i);
        if(c=='('){
            ++count;
        }else{
            --count;
        }
        if(count<0){
            head -= count;
            count = 0;
        }
    }
    assert(count>=0);
    string h(head,'(');
    string f(max(count,(ll)0), ')');
    cout<<(h+S+f)<<endl;
    return 0;
}

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

using namespace std;

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

using ll = long long;
using ld = long double;

const ll INF = 1e18;
const int Inf = 1e9;
const double EPS = 1e-9;
const ll MOD = 1e9 + 7;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(0);
    int n;
	cin >> n;
	vector<int> a(n + 1);
	rep (i, n) cin >> a[i];
	a[n] = -1;
	ll m = 1000;
	ll stock = 0;
	rep (i, n) {
	  if (a[i] > a[i + 1]) {
		m += stock * a[i];
		stock = 0;
	  } else {
		ll buy = m / a[i];
		stock += buy;
		m -= buy * a[i];
	  }
	}
	cout << m << endl;
	
    return 0;
}



Measured memory_bytes: 3608
#include "bits/stdc++.h"
using namespace std;
#define repr(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repr(i,0,n)
#define reprrev(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define reprev(i,n) reprrev(i,0,n)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define mp make_pair
#define mt make_tuple
#define MOD 1000000007
#define PI 3.1415926535
#define SEGMAX 131072
typedef long long ll;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<Pi> vPi;
typedef vector<Pll> vPll;
typedef vector<vector<int>> vvi;
typedef vector<vector<bool>> vvb;
typedef vector<vector<ll>> vvll;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;
typedef vector<vector<double>> vvd;
typedef vector<vector<Pi>> vvPi;
typedef priority_queue<int, vector<int>, greater<int>> pqli;
typedef priority_queue<ll, vector<ll>, greater<ll>> pqlll;
typedef priority_queue<Pi, vector<Pi>, greater<Pi>> pqlP;
string YN(bool y) { return (y?"YES":"NO"); }
string yn(bool y) { return (y?"Yes":"No"); }
string ON(bool y) { return (y?"OK":"NG"); }
int main(void)
{
	int n, m;

	cin>>n>>m;

	vi a(n), b(n), c(m), d(m);

	rep(i, n) cin>>a[i]>>b[i];

	rep(i, m) cin>>c[i]>>d[i];

	rep(i, n){
		int min=1e9, ans=0;
		rep(j, m){
			int dist=abs(a[i]-c[j])+abs(b[i]-d[j]);
			if(min>dist){
				min=dist;
				ans=j+1;
			}
		}
		cout<<ans<<endl;
	}
}

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

using namespace std;
#define IOS cin.sync_with_stdio(0); cin.tie(0); cout.tie(0);

using ll = long long;
using ld = long double;


//dp[i][j] - max value obtained if Taro picks
//    'j' weight in total and has the options of item numbers
//     [0, i]

ll dp[105][(int)1e5+10];


int main(){
    IOS

    int n, W;
    cin>>n>>W;

    vector<ll> w(n), v(n);

    memset(dp, 0ll, sizeof dp);
    

    for(int i = 0; i < n; i++){
        cin>>w[i]>>v[i];
    }

    
    for(int i = 0; i <= n; i++){
        for(int j = 0; j <= W; j++){
            if(i==0 || j==0)
                dp[i][j] = 0;
            else if(j >= w[i-1])
                dp[i][j] = max(v[i-1]+dp[i-1][j-w[i-1]], dp[i-1][j]);
            else
                dp[i][j] = dp[i-1][j];
        }
    }

    cout<<dp[n][W]<<"\n";

    
    
}


Measured memory_bytes: 82432
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
int main()
{
  int n;cin >> n;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  map<int,int> mp;
  rep(i,n) mp[a[i]]++;
  int res = 0;
  for(auto m : mp) {
    if(m.first < m.second) res += m.second - m.first;
    else if(m.first > m.second) res += m.second;
  }
  cout << res << "\n";
  return 0;
}


Measured memory_bytes: 5120
#include <cstdio>
#include <cstring>
#include <vector>

#define INF (1 << 30)

using namespace std;

typedef struct {
	int par;
	vector<int> son;
} Node;

Node T[20];
int n;
int cost[20][20];
bool vis[20];
int cSum;

void makeTree(int v, int p)
{
	T[v].par = p;
	vis[v] = true;
	for (int i = 0; i < n; i++){
		if (vis[i] == false && cost[v][i] != INF){
			T[v].son.push_back(i);
			makeTree(i, v);
		}
	}
}

void dfs(int v, int c)
{
	vis[v] = true;
	if (T[v].son.size() == 0){
		return;
	}
	
	for (int i = 0; i < T[v].son.size(); i++){
		if (vis[T[v].son[i]] == false){
			dfs(T[v].son[i], cost[v][T[v].son[i]]);
		}
	}
	cSum += c * 2;
}

int bomb()
{
	cSum = 0;
	int pNode = 0;
	
	while (~pNode){
		dfs(pNode, 0);
		if (~T[pNode].par) cSum += cost[pNode][T[pNode].par];
		pNode = T[pNode].par;
	}
	
	return (cSum);
}

int main()
{
    int a, b, t;
    int res;
    
    while (scanf("%d", &n) && n){
		
		for (int i = 0; i < n; i++){
			for (int j = 0; j < n; j++){
				cost[i][j] = INF;
			}
		}
        
        for (int i = 0; i < n - 1; i++){
            scanf("%d %d %d", &a, &b, &t);
            cost[a - 1][b - 1] = cost[b - 1][a - 1] = t;
        }
        
        res = INF;
		
		for (int i = 0; i < n; i++){
			for (int j = 0; j < n; j++) T[j].son.clear();
			memset(vis, false, sizeof(vis));
			makeTree(i, -1);
			memset(vis, false, sizeof(vis));
			res = min(res, bomb());
		}
		
        printf("%d\n", res);
    }
    
    return (0);
}

Measured memory_bytes: 1052
N = int(input())
s = [None]*N
s_sort = [None]*N
for _ in range(N):
    s[_] = sorted(list(input()))
    s_sort[_] = ''.join(s[_])
s_sort.sort()
inst = s_sort[0]
s_sort.append("fuckatcorder")
count = 0
lis = []
for i in range(1,N+1):
    if s_sort[i] == inst:
        count += 1
    else:
        if count != 0:
            lis.append(count)
            count = 0
            inst = s_sort[i]
        else:
            inst = s_sort[i]
ans = 0
for k in range(len(lis)):
    ans += lis[k]*(lis[k]+1)//2
print(ans)

Measured memory_bytes: 31748
/**
 *   created: 03 June 2019  00:25:23
**/
#include<bits/stdc++.h>
using namespace std;

typedef vector<int> vi;
typedef pair<int , int> pii;
typedef vector< pair<int , int> > vii;
typedef long long ll;
typedef vector<long long> vl;
typedef pair<long long , long long> pll;
typedef vector< pair<long long , long long> > vll;

#define PB push_back
#define PPB pop_back
#define all(c) c.begin(),c.end()
#define rep(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
#define rrep(i,a,b) for(int i = (int)(a-1); i>=(int)(b); i--)
#define INFLL 2000000000000000007
#define INF 2000000007
#define MOD 1000000007


#define TRACE

#ifdef TRACE
#define trace1(x)                cerr << #x << ": " << x << endl;
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
#define trace5(a, b, c, d, e)    cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
#define trace6(a, b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;

#else

#define trace1(x)
#define trace2(x, y)
#define trace3(x, y, z)
#define trace4(a, b, c, d)
#define trace5(a, b, c, d, e)
#define trace6(a, b, c, d, e, f)

#endif


void optimizeIO()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
}

//                                        //AUTHOR: Kaushalesh Shukla

//=========================================================================================================

int main()
{
	optimizeIO();
	int tt=1;
	//cin>>tt;
	while(tt--){
		int n,m;
		cin>>n>>m;
		vi v(m);
		rep(i,0,m)
			cin>>v[i];
		sort(all(v));
		vi dist(m-1);
		rep(i,0,m-1){
			dist[i] = v[i+1]-v[i];
		}
		sort(all(dist));
		int sum=0;
		rep(i,0,m-n){
			sum += dist[i];
		}
		cout<<sum;
	}
	return 0;
}


Measured memory_bytes: 1024
package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	call(n)
}

func call(n int) {
	for i := 1; i <= n ;i++ {
		x := i
		if x % 3 == 0 {
			fmt.Printf(" %d", i)
		} else {
			for {
				if x%10 == 3 {
					fmt.Printf(" %d", i)
					break
				}
				x /= 10
				if x == 0 {
					break
				}
			}
		}
		if (1 + i) > n {
			break
		}
	}
	fmt.Print("\n")

}


Measured memory_bytes: 1136
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <bitset>

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

using namespace std;

typedef long long ll;


int main(){

    int N,M;
    cin>>N>>M;
    ll K;
    cin>>K;
    ll A[N+1],B[M+1]; 
    ll a,b;

    int ans=0;

    A[0]=0;
    B[0]=0;
    
    for(int i=1;i!=N+1;++i){
        cin>>a;
        A[i]=a+A[i-1];
    };
    for(int i=1;i!=M+1;++i){
            cin>>b;
            B[i]=b+B[i-1];
    }

    ll* x;
    ll total;

    for(int i=0;i<=N;++i){
       x=upper_bound(B,B+M+1,K-A[i]);

       //cout<<A[i]<<":"<<K-A[i]<<":"<<(*x)<<":"<<x-B-1<<":"<<i<<endl;
       ans=ans>=(i+x-B-1)?ans:(i+x-B-1);
       if(A[i]>K){
          break;
       }
    }

    cout<<ans<<endl;
}

Measured memory_bytes: 6728
import itertools as it

N = int(input())
march = {"M": 0, "A": 0, "R": 0, "C": 0, "H": 0}
for i in range(N):
    ini = input()[0]
    if ini in march:
        march[ini] += 1
ans = 0
for i, j, k in it.combinations("MARCH", 3):
    ans += march[i] * march[j] * march[k]
print(ans)


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


int main() {
	int a=0, b=0;
	std::string str;
	std::string saa;
	std::string sbb;

	std::cin >> str;


	//std::cout << str.size() << std::endl;

	for (int i = 0; i < str.size(); i++) {
		std::string sw("0");
		std::string sq("1");
		

		if (i % 2 == 0) {
			saa = saa + sw;
			sbb = sbb + sq;
		}
		else {
			saa = saa + sq;
			sbb = sbb + sw;
		}
	}

	//std::cout << saa << std::endl;
	//std::cout << sbb << std::endl;

	
	for (int i = 0; i < str.size(); i++) {
		if (str[i] != saa[i]) {
			a++;
		}

		if (str[i] != sbb[i]) {
			b++;
		}
	}


	std::cout << std::min(a,b) << std::endl;
	
	return 0;
}

Measured memory_bytes: 976
#include <iostream>
#include <cmath>
using namespace std;

const int MAX = 1000000;
bool prime[MAX] = { true };
int pcount[MAX];

int main(){
	int n;
	prime[0] = prime[1] = false;
	for(int i = 2;i < MAX;++i) prime[i] = true;
	for(int i = 2;i <= sqrt(MAX);++i){
		if(prime[i]){
			for(int j = i + i;j < MAX;j += i){
				prime[j] = false;
			}
		}
	}
	pcount[0] = 0;
	for(int i = 1;i < MAX;++i){
		pcount[i] = pcount[i - 1];
		if(prime[i]) pcount[i]++;
	}
	while(cin >> n){
		cout << pcount[n] << endl;
	}
	return 0;
}

Measured memory_bytes: 6044
#include <iostream>   
using namespace std;

int main ()
{
	int n;
	long long a;
	long long minValue = 1000000;
	long long maxValue = -1000000;
	long long sum = 0;

	cin >> n;

	for ( int i = 0; i < n; i++ ){
		cin >> a;
		if ( a < minValue ) minValue = a;
		if ( a > maxValue ) maxValue = a;
		sum += a;
	}
	cout << minValue << " " << maxValue << " " << sum << endl;
	return 0;
}

Measured memory_bytes: 1172
#include <iostream>
#include <cstdio>
using namespace std;
int h, w, n, t, a[10005], b[105][105];
int main() {
	int i, j;
	scanf("%d%d%d", &h, &w, &n);
	for(i=1; i<=n; i++) scanf("%d", &t), a[i] = a[i-1] + t;
	for(i=1; i<=n; i++) for(j=a[i-1]; j<a[i]; j++) b[j/w][j%w] = i;
	for(i=1; i<h; i+=2) for(j=0; j<w/2; j++) swap(b[i][j], b[i][w-j-1]);
	for(i=0; i<h; i++, puts("")) for(j=0; j<w; j++) printf("%d ", b[i][j]);
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
int main() {
  int A,B,C,D;
  cin >> A >> B >> C >> D;
  if(A+B > C+D){
    cout << "Left" << endl;
  }else if(A+B == C+D){
    cout << "Balanced" << endl;
  }else{
    cout << "Right" << endl;
  }
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <tuple>
#include <functional>
#include <cmath>
#include <complex>

using namespace std;
#define PI       3.14159265358979323846
#define MOD 1000000007

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef pair<int, int> PII;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef complex<double> P;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

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


using namespace std;

int main() {
	int n, a;
	scanf("%d%d", &n, &a);
	if (a >= (n % 500))cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {


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

        int n = sc.nextInt();
        int m = sc.nextInt();

        int[] arr = new int[n];

        long ans = 0;

        for (int i=0; i<n; i++) arr[i] = sc.nextInt();
        Arrays.sort(arr);

        int[] b = new int[m];
        Pair[] c = new Pair[m];
//        int[] c = new int[m];

        for (int i=0; i<m; i++){
            int bCnt = sc.nextInt();
            int tmp = sc.nextInt();
            c[i] = new Pair(tmp, bCnt);
        }

        Arrays.sort(c);

        int idx = 0;

        for (int i=0; i<m; i++){
            int cnt = c[i].cnt;
            int change = c[i].change;
            while (idx<n && arr[idx]<change && cnt>0){
                arr[idx] = change;
                idx++;
                cnt--;
            }
        }

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

        System.out.println(ans);


    }

    public static class Pair implements Comparable<Pair>{
        int change;
        int cnt;
        Pair(int c, int i){
            this.change = c;
            this.cnt = i;
        }

        public int compareTo(Pair pair){
            if (this.change<pair.change) return 1;
            if (this.change>pair.change) return -1;
            return 0;
        }
    }
}



Measured memory_bytes: 93472
import bisect


n = int(input())
S = list(map(int, input().split()))

q = int(input())
T = list(map(int, input().split()))


cnt = 0

for t in T:
    
    index = bisect.bisect_left(S, t)

    if ((index < len(S)) and
        (S[index] == t)):
        cnt += 1
        

print(cnt)



Measured memory_bytes: 16744
n = int(input())
A=list(map(int, input().split()))

ans="No"
c1=c2=c4=0
for a in A:
    if a%4==0:
        c4+=1
    elif a%2==0:
        c2+=1
    else:
        c1+=1

if c4==0 and c1>0 :
    ans="No"
elif c1<=c4+(c2==0) :
    ans="Yes"
else:
    ans="No"

print( ans )



Measured memory_bytes: 20096
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
#define mp make_pair

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

int main() {
	int n;
	while(n=in()){
		int i;
		int res,mx=0;
		for(i=0;i<n;i++){
			int buf=in();
			int a=in(),b=in();
			if(mx<a+b){
				res=buf;
				mx=a+b;
			}
		}
		cout<<res<<" "<<mx<<endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //これつけるとA[N]でもいいらしい
//for文のマクロ
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define mp(a,b) make_pair(a,b)
#define big 1000000007
#define all(a) sort((a).begin(),(a).end()) //ソートのマクロ
#define Re(a) reverse((a).begin(),(a).end())
#define YN(a) if(a){cout<<"Yes"<<endl;}else cout<<"No"<<endl;//条件によってYes、Noを出力する
const int MOD=1000000007;
const double pi = 3.141592653589793;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin>>n;//nは偶数
    vector<int64_t> a(n);
    vector<bitset<30>> c(n);
    vector<bitset<30>> ans(n);
    rep(i,n){
        cin>>a[i];
        c[i] = a[i];
        //cout<<c[i]<<endl;
    }
    rep(j,30){
        int count=0;
        rep(i,n){
            if(c[i].test(j)){
                count++;
            }
        }
        if(count%2==0){
            rep(i,n){
                ans[i].set(j,c[i][j]);
            }
        }
        else{
            rep(i,n){
                ans[i].set(j,!c[i][j]);
            }
        }
    }
    rep(i,n){
        cout<<ans[i].to_ullong()<<" ";
    }
    cout<<endl;
}

Measured memory_bytes: 7920
from sys import stdin
def main():
    #入力
    readline=stdin.readline
    D=int(readline())
    c=list(map(int,readline().split()))
    s=[list(map(int,readline().split())) for _ in range(D)]
    t=[int(readline()) for _ in range(D)]
    M=int(readline())
    d=[0]*M
    q=[0]*M
    for i in range(M):
        d[i],q[i]=map(int,readline().split())

    kaisai_all=[[0]*26 for _ in range(D)]
    kaisai=[0]*26
    manzokudo=0
    for i in range(D):
        manzokudo+=s[i][t[i]-1]
        kaisai[t[i]-1]=i+1
        if i!=0:
            kaisai_all[i]=kaisai_all[i-1][:]
        kaisai_all[i][t[i]-1]=i+1
        for j in range(26):
            manzokudo-=c[j]*(i+1-kaisai[j])
    
    #クエリ処理
    for i in range(M):
        day=d[i]-1
        before_contest_type=t[day]-1
        after_contest_type=q[i]-1
        manzokudo-=s[day][before_contest_type]
        manzokudo+=s[day][after_contest_type]
        t[day]=q[i]

        if day==0:
            tmp=0
        else:
            tmp=kaisai_all[day-1][before_contest_type]
        j=day
        while 0<=j<D and kaisai_all[j][before_contest_type]==day+1:
            kaisai_all[j][before_contest_type]=tmp
            manzokudo-=c[before_contest_type]*(day+1-tmp)
            j+=1
        
        if day==0:
            tmp=0
        else:
            tmp=kaisai_all[day-1][after_contest_type]
        j=day
        while 0<=j<D and kaisai_all[j][after_contest_type]==tmp:
            kaisai_all[j][after_contest_type]=day+1
            manzokudo+=c[after_contest_type]*(day+1-tmp)
            j+=1
        print(manzokudo)

if __name__=="__main__":
    main()

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

using namespace std;

int main()
{
    int n;

    cin >> n;

    int c[10][10];

    for (int i = 0; i < 10; i++)
        for (int j = 0; j < 10; j++)
            c[i][j] = 0;

    for (int i = 1; i <= n; i++)
    {
        int m = i;

        int last = m % 10;

        int first = -1;

        while (m)
        {
            first = m % 10;
            m /= 10;
        }

        c[last][first]++;
    }

    int ans = 0;

    for (int i = 0; i < 10; i++)
    {
        for (int j = 0; j < 10; j++)
        {
            ans += c[i][j] * c[j][i];
        }
    }

    cout << ans << "\n";

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

#define N 1000

int main(){
  int n, i, j, k, key;
  int A[N];
  scanf("%d", &n);

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

  for (i = 0; i < n; i++) {
    key = A[i];
    j = i - 1;
    while (j >= 0 && A[j] > key) {
      A[j+1] = A[j];
      j--;
    }
    A[j+1] = key;
    for (k = 0; k < n; k++) {
      if (k > 0){
        printf(" ");
      }
      printf("%d",A[k]);
    }
    printf("\n");
  }
  return 0;
}

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

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


vector<ll> inv,fac;

void inverse(ll n){
    //要素数:n+1 (0~n)
    inv[0]=1;
    inv[1]=1;
    for(ll i=2;i<=n;i++){
        inv[i]=(MOD-inv[MOD%i]*(MOD/i))%MOD;
    }
}

void inverse_u(ll n){
    //要素数:n+1 (0~n)
    for(ll i=2;i<=n;i++){
        inv[i]=(inv[i]*inv[i-1])%MOD;
    }
}

void factorial(ll n){
    //要素数:n+1 (0~n)
    fac[0]=1;
    fac[1]=1;
    for(ll i=2;i<=n;i++){
        fac[i]=(fac[i-1]*i)%MOD;
    }
}

ll nCr(ll n,ll r){
    return fac[n]*inv[r]%MOD*inv[n-r]%MOD;
}

ll proinverse(ll x,ll m){
    ll res=1,M=m-2;
    while(M>0){
        if(M&1) res=res*x%m;
        x=x*x%m;
        M>>=1;
    }
    return res;
}

void init_nCr(ll n){
    inv.assign(n+1,0);
    fac.assign(n+1,0);
    inverse(n);
    factorial(n);
}

int main(){
    ll n,a,b,ans=1,c=2; cin>>n>>a>>b;
    init_nCr(200001LL);
    rep(i,32){
        if(n&(1<<i)) ans=(ans*c)%MOD;
        c=(c*c)%MOD;
    }
    ll an=1,bn=1;
    rep(i,a){
        an=(an*(n-i))%MOD;
        an=(an*inv[i+1])%MOD;
    }
    rep(i,b){
        bn=(bn*(n-i))%MOD;
        bn=(bn*inv[i+1])%MOD;
    }
    ans=(MOD+ans-an)%MOD;
    ans=(MOD+ans-1-bn)%MOD;
    cout<<ans<<endl;
}

Measured memory_bytes: 3328
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define debug(a) cout << #a << ": " << a << endl
#define sz(a) int(a.size())
#define rep(i,n) for(int i=0;i<n;i++)
#define forr(i, st, en) for(int i = st; i < en; i++)
#define all(v) (v).begin(),(v).end()
#define fast cin.tie(0); ios::sync_with_stdio(false)

int32_t main(){ fast;
	
	int n, m; cin>>n>>m;
	vector<int> a(n);
	int tot = 0;
	rep(i, n){
		cin>>a[i];
		tot += a[i];
	}
	sort(all(a), greater<int>());
	int thres = tot/(4 * m);
	if(tot % (4 * m) != 0){
		thres = thres + 1;
	}
	rep(i, m){
		if(a[i] < float(tot) * 1.0 /(4 * m)){
			cout<<"No"<<endl;
			return 0;
		}
	}
	cout<<"Yes"<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long ll;
#define F(i,L,R) for (ll i = L; i < R; i++)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define re(x) scanf("%lld",&x)
using namespace std;


void dfs(ll u, vector<ll> &vis, vector<ll> adj[]){
	vis[u] = 1;
	for(auto i: adj[u]) if(vis[i] == 0) dfs(i, vis, adj);
}

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll n,m, u,v, cnt = 0;
  cin>>n>>m;
  vector<ll> adj[n+1];
  F(i,0,m) cin>>u>>v, adj[u].pb(v), adj[v].pb(u);
  vector<ll> vis(n+1,0);
  F(i,1,n+1) if(!vis[i]) cnt++, dfs(i, vis, adj);
  cout<<cnt-1;
  return 0;
}

Measured memory_bytes: 11116
import java.util.*;
 
public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int x = sc.nextInt();
        int y = sc.nextInt();
        int xymin = Math.min(x,y);
        long ans = xymin * Math.min(a+b,c*2);
        x -= xymin;
        y -= xymin;
        if(x == 0){
            ans += y*Math.min(b,c*2);
        }else{
            ans += x*Math.min(a,c*2);
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 21844
/**
   Solution by Abil
**/
# include <bits/stdc++.h>

# define fr first
# define sc second
# define pb push_back
# define mk make_pair
# define sz(s) s.size()
# define all(s) s.begin(),s.end()
# define int long long

using namespace std;

const long long N = (1e5 + 10);
const long long mod = (1e9 + 7);
const long long inf = (1e9 + 7);

int dp[N],vis[N];
vector<int > v[N];

void dfs(int g){
    vis[g] = 1;
    int ans = 0;
    for(int i : v[g]){
        if(!vis[i]){
            dfs(i);
        }
        ans = max(dp[i] + 1, ans);
    }
    dp[g] = ans;
}
main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    int n, m, x, y;
    cin >> n >> m;
    for(int i = 1;i <= m; i++){
        cin >> x >> y;
        v[x].pb(y);
    }
    for(int i = 1;i <= n; i++){
        if(!vis[i]){
            dfs(i);
        }
    }

    cout << *max_element(dp + 1, dp + n + 1);
}


Measured memory_bytes: 9344