akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#define ll long long
using namespace std;

ll rez;
int n;
int curent[25];
int nr[200005];
int main()
{
    ios_base::sync_with_stdio(false);
    cin >> n;
    int l = 1;
    for (int i = 1; i <= n; i++)
    {
        cin >> nr[i];
        for (int b = 0; (nr[i] >> b); b++)
            curent[b] += ((nr[i] >> b) & 1);

        for (int b = 0; b < 20; b++)
            while (curent[b] > 1)
            {
                for (int b2 = 0; (nr[l] >> b2); b2++)
                    curent[b2] -= ((nr[l] >> b2) & 1);
                l++;
            }
        rez += i - l + 1;
    }
    cout << rez;
    return 0;
}


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

int main(){
    int N;
    cin>>N;
    vector<bool> d;
    for(int i=1;i<=N;i++){
        int x;
        cin>>x;
        if(x==i) d.push_back(false);
        else d.push_back(true);
    }

    int ans=0;
    int i=0;
    while(i<N-1){
        if(d.at(i)) i++;
        else{
            ans++;
            if(!d.at(i+1)) d.at(i+1)=true;
            i++;
        }
    }
    if(!d.at(N-1)) ans++;
    cout<<ans<<endl;
}

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

ll a, b, k;

int main(){
cin>>a>>b>>k;
for(int i=0;i<k;i++){
if(i%2==0){
if(a%2==1) a--;
b+=a/2; a/=2;
} else {
if(b%2==1) b--;
a+=b/2; b/=2;
}
}
cout<<a<<" "<<b<<endl;
return 0;
}

Measured memory_bytes: 256
#
# Written by NoKnowledgeGG @YlePhan
# ('ω')
#
#import math
#mod = 10**9+7
#import itertools
#import fractions
#import numpy as np
#mod = 10**4 + 7
def kiri(n,m):
  r_ = n / m
  if (r_ - (n // m)) > 0:
    return (n//m) + 1
  else:
    return (n//m)

""" n! mod m 階乗
mod = 1e9 + 7
N = 10000000
fac = [0] * N
def ini():
  fac[0] = 1 % mod
  for i in range(1,N):
    fac[i] = fac[i-1] * i % mod"""

"""mod = 1e9+7
N = 10000000
pw = [0] * N
def ini(c):
  pw[0] = 1 % mod
  for i in range(1,N):
    pw[i] = pw[i-1] * c % mod"""

"""
def YEILD():
  yield 'one'
  yield 'two'
  yield 'three'
generator = YEILD()
print(next(generator))
print(next(generator))
print(next(generator))
"""
"""def gcd_(a,b):
  if b == 0:#結局はc,0の最大公約数はcなのに
    return a
  return gcd_(a,a % b) # a = p * b + q"""
"""def extgcd(a,b,x,y):
  d = a
  if b!=0:
    d = extgcd(b,a%b,y,x)
    y -= (a//b) * x
    print(x,y)
  else:
    x = 1
    y = 0
  return d"""


def readInts():
  return list(map(int,input().split()))

def main():
  s = input()
  slen = len(s)
  ans = 0
  for i in range(2**(slen-1)):
    nya = [0]
    for j in range(slen-1):
      if i >> j & 1:
        nya.append(j+1)
    nya.append(slen)
    #print(nya)
    # [0, 3]
	# [0, 1, 3]
	# [0, 2, 3]
	# [0, 1, 2, 3]
    for j in range(len(nya) - 1):
      ans += int(s[nya[j]:nya[j+1]])
  print(ans)
if __name__ == '__main__':
  main()

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

ll a[3010], n, res[3010][3010];

bool vis[3010][3010];
ll dp(ll st, ll en)
{
    if(st==en)
    {
        if(n%2==1) return a[st];
        else return -a[st];

    }


    if(vis[st][en]!=0) return res[st][en];
    ll ans;
    if((n-(en-st))%2==1) ans=max(a[st]+dp(st+1, en), a[en]+dp(st, en-1));
    else ans=min(dp(st+1, en)-a[st], dp(st, en-1)-a[en]);

    res[st][en]=ans;
    vis[st][en]=1;
    return ans;
}

main()
{
    ll i, j;

    cin>>n;

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

    j=dp(0, n-1);

    cout<<j<<endl;
}


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

using namespace std;

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    int n;
    cin >> n;
    int dp[n][3];
    memset(dp, 0, sizeof dp);
    int a, b, c; cin>>a>>b>>c;
    dp[0][0]=a;dp[0][1]=b;dp[0][2]=c;
    for (int i = 1; i < n; i++) {
        cin>>a>>b>>c;
        dp[i][0]+= max(dp[i-1][1], dp[i-1][2]) + a;
        dp[i][1]+= max(dp[i-1][0], dp[i-1][2]) + b;
        dp[i][2]+= max(dp[i-1][0], dp[i-1][1]) + c;
    }
    cout<<max(max(dp[n-1][0],dp[n-1][1]), dp[n-1][2]) <<endl;
}


Measured memory_bytes: 1408
# util functions

# debug
$debugFlag = ( ARGV[0] != nil )
p "==== DEBUG MODE ====" if $debugFlag

def pd(str)
  p str if $debugFlag
end

# input
inputs = []
lc = 0
while l = $stdin.gets do
  if false
    inputs << l.chomp.split(" ").map(&:to_s)
  else
    inputs << l.chomp.split(" ").map(&:to_i)
  end
  lc += 1
end

nn = inputs[0][0]

# input check
if $debugFlag
  p "--- INPUT (begin) ---"
  inputs.each do |l_i|
    p l_i
  end
  p "--- INPUT (end) ---"
  print "\n"
end

# body
if $debugFlag
end

puts 180*(nn-2)

Measured memory_bytes: 1788
from math import *
from decimal import * 
N = int(input())
T = []
A = []
for i in range(0, N):
    ti, ai = [Decimal(int(x)) for x in input().split()]
    T.append(ti)
    A.append(ai)

prevT = T[0]
prevA = A[0]
for i in range(1, N):
    nextfacT = int(ceil(prevT / T[i]))
    nextfacA = int(ceil(prevA / A[i]))
    nextfac = max(nextfacT, nextfacA)
    prevT = nextfac * T[i]
    prevA = nextfac * A[i]

print(prevA+prevT)


Measured memory_bytes: 5200
import math
a,b,h,m = map(float, input().split())

s_theta =  m * 6
l_theta =  (h*60 + m)*0.5

if abs(s_theta - l_theta) > 180:
    theta = 360 - abs(s_theta - l_theta) 
else:
    theta = abs(s_theta - l_theta)

rad = math.radians(theta)
ans = math.sqrt(a**2 + b**2 - 2*a*b*math.cos(rad))
print(ans)

Measured memory_bytes: 9512
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  vector<long long> Lucas(100);
  Lucas[0] = 2;
  Lucas[1] = 1;
  
  for(int i=2; i<=N; i++){
    Lucas[i] = Lucas[i-2] + Lucas[i-1];
  }
  
  cout << Lucas[N] << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	
	static int n;
	static int a;
	static int [][]x;
	static int []y;	
	static int []honest;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		n = sc.nextInt();
		x = new int [n][n];
		y = new int [n];
		
		for(int i = 0 ; i < n ;i++) {
			for(int j = 0 ; j < n ;j++) {
				x[i][j] = -1;               //初期化
			}
		}
		
		for(int i = 0 ;i < n ;i++) {
			int a = sc.nextInt();
			for(int j = 0 ; j < a ;j++) {
				int p = sc.nextInt();
				x[i][p-1] = sc.nextInt();   //i番目の人の証言でp番目の人が正直者かどうか
			}
		}

		solve();
	}
	
	static void solve() {
		int N = (int)Math.pow(2, n);
		int max = 0;
		
		for(int i = 0 ;i < N ;i++) {
			boolean flag = true;
			honest = new int [n];
			
	       for(int j = 0 ; j < n ;j++) {
				honest[j] = (1 & (i >> j));
			}
			
		point:for(int k = 0 ; k < n; k++) {  //証言者を全探査
			if(honest[k] == 0) {               //信頼できない人は飛ばす
				continue;
			}
			
				for(int l = 0 ; l < n ;l++) { //証言されている人を全探査
					if(x[k][l] == -1) {       
						continue;
					}
					
					else {
						if(honest[l] != x[k][l]) { //証言が正しいか
							flag = false;
							break point;
						}
						
					}
				}
			}
			if(flag) {
				int cnt = Integer.bitCount(i);
				
				max = Math.max(cnt, max);
			}
		}
		System.out.println(max);
	}

}


Measured memory_bytes: 23892
#include <iostream>
#include<algorithm>
#include<stdio.h>
#include<string.h>
#include<string>
#include<queue>
#include<set>
#include<vector>
#include<cmath>
#include<stack>
#include<map>
#define inf 0x3f3f3f3f
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
double na,nb;
string s;
int q;
int cnt=0;
int main()
{
    cin>>s>>q;
    while(q--)
    {
        int t;cin>>t;
        if(t==1)cnt++;
        else
        {
            int f;char c;
            cin>>f>>c;
            if(f==1)
            {
                if(cnt%2)s.insert(s.end(),c);
                else s.insert(s.begin(),c);
            }
            else
            {
                if(cnt%2==0)s.insert(s.end(),c);
                else s.insert(s.begin(),c);
            }
        }
    }
    if(cnt%2)reverse(s.begin(),s.end());
    cout<<s<<endl;
    return 0;
}


Measured memory_bytes: 900
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
using ll = long long ;
using P = pair<int,int> ;
using pll = pair<long long,long long>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e17;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979323846;

int main(){
    int n,h,w;
    cin >> n >> h >> w;
    cout << (n-h+1)*(n-w+1) << endl;
    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;

int main() {
  string s;
  cin >> s;
  int n = sz(s);
  ll k;
  cin >> k;
  rep(i,n){
    if(s[i] == 'a')continue;
    ll a = 26LL - (s[i]-'a');
    if(k>=a){
      s[i]-=(26LL-a);
      k-=a;
    } 
  }
  s[n-1] = 'a'+ (s[n-1]-'a'+k)%26;
  cout<<s<<endl;
  return 0;
}

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

using namespace std;
long long int dizi[10000005]; 
#define MOD 1000000007
long long int a,b;
long long int mavi;
long long int kirmizi;

long long int hizlius(long long int a,long long int b)
{
	if(b==0){
		return 1;
	}
	if(b==1){
		return a;
	}
	long long int kl=hizlius(a,b/2);
	if(b%2==0){
		return (kl*kl)%MOD;
	}
	if(b%2==1){
		return (((kl*kl)%MOD)*a)%MOD;
	}
	
} 

long long int komb(long long int a,long long int b){
	long long int c=b;
	long long int d=a-b;
	long long int reelc=hizlius(dizi[c],MOD-2);
	long long int reeld=hizlius(dizi[d],MOD-2);
	return (((dizi[a]*reelc)%MOD)*reeld)%MOD;
	
}
void coz(int hareket){
	long long	int mav=mavi-hareket;//2
	long long	int kir=kirmizi-(hareket-1);//2
	if(kir <0){
		cout<<0<<" ";
		return;
	}
	long long int toplam=((komb(mav+hareket-1,hareket-1)%MOD)*(komb(kir+hareket,hareket)%MOD))%MOD;
	cout<<toplam<<endl;
}

int main(){
	
	cin>>a>>b;
	mavi=b;
	kirmizi=a-b;
	dizi[0]=1;
	for(long long int i =1;i<a+2;i++){
		dizi[i]=(dizi[i-1]*i)%MOD;
	}
	for(int i=1;i<=b;i++){
		coz(i);
	}
}

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

#define infinity 1000000
#define white 2
#define gray 1
#define black 0
#define N 100

void dijkstra(void);

int n ,M[N][N];

int main(){
  int i, j, num, k, comp, weight;

  scanf("%d", &n);

  for(i = 0; i < n; i++)
    for(j = 0; j < n; j++)
      M[i][j] = infinity;

  for(i = 0; i < n; i++){
    scanf("%d%d", &num, &k);

    for(j = 0; j < k; j++){
      scanf("%d%d", &comp, &weight);

      M[num][comp] = weight;
    }
  }

  dijkstra();

  return 0;
}

void dijkstra(){
  int i, cost, top, col[N], dist[N], pa[N];

  for(i = 0; i < n; i++){
    col[i] = white;
    dist[i] = infinity;
  }

  dist[0] = 0;

  while(1){
    cost = infinity;

    for(i = 0; i < n; i++){
      if(col[i] != black && dist[i] < cost){
	cost = dist[i];
	top = i;
      }
    }

    //探索終了時
    if(cost == infinity)
      break;

    col[top] = black;

    for(i = 0; i < n; i++){
      if(col[i] != black && M[top][i] != infinity){
	if(dist[top] + M[top][i]  < dist[i]){
	  dist[i] = dist[top] + M[top][i];
	  col[i] = gray;
	}
      }
    }
  }

  for(i = 0; i < n; i++)
    printf("%d %d\n", i, dist[i]);
}



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


int main(void) {
  int a, b, c, k;
  cin >> a >> b >> c >> k;

  rep(i, k) {
    if (b <= a) {
      b *= 2;
    } else if (c <= b) {
      c *= 2;
    }
  }

  if (c > b && b > a) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  
  return 0;
}

Measured memory_bytes: 3596
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

#define ll long long 
#define forn(i,n) for(int i = 0;i<int(n);i++)

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    long long sum = 0;
    for(int i = 1;i<=n;i++){
        if( i%3!=0 && i%5 !=0 )
            sum+=i;
    }
    cout<<sum<<endl;
}



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

// #define int long long
#define rep(i, n) for (int i = 0; i < (int) (n); i++)
#define reps(i, n) for (int i = 1; i <= (int) (n); i++)
#define all(x) (x).begin(), (x).end()
#define uniq(x) (x).erase(unique(all(x)), (x).end())
#define bit(n) (1LL << (n))
#define cdiv(a, b) (((a) - 1) / (b) + 1)
#define dump(x) cerr << #x " = " << (x) << endl
using vint = vector<int>;
using vvint = vector<vint>;
using pint = pair<int, int>;
using vpint = vector<pint>;
template<typename T> using priority_queue_rev = priority_queue<T, vector<T>, greater<T>>;
constexpr double PI = 3.1415926535897932384626433832795028;
constexpr int DY[8] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr int DX[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int gcd(int a, int b) {
    while (b) { swap(a %= b, b); }
    return a;
}
int lcm(int a, int b) { return a / gcd(a, b) * b; }
template<typename T> void fin(T mes) {
    cout << mes << endl;
    exit(0);
}
template<typename T, typename U> bool chmax(T &a, const U &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> bool chmin(T &a, const U &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &rhs) {
    os << "(" << rhs.first << ", " << rhs.second << ")";
    return os;
}
template<typename T> ostream &operator<<(ostream &os, const vector<T> &rhs) {
    os << "{";
    for (auto itr = rhs.begin(); itr != rhs.end(); itr++) {
        os << *itr << (next(itr) != rhs.end() ? ", " : "");
    }
    os << "}";
    return os;
}
struct setup {
    static constexpr int PREC = 20;
    setup() {
        cout << fixed << setprecision(PREC);
        cerr << fixed << setprecision(PREC);
    };
} setup;

int D;
int c[33];
int s[440][33];
int A = 26;

vint score(vint history) {
    vint last(A + 1);
    vint ret(history.size());
    reps(i, D) {
        ret[i] = ret[i - 1];
        ret[i] += s[i][history[i]];
        last[history[i]] = i;
        reps(j, A) { ret[i] -= c[j] * (i - last[j]); }
    }
    return ret;
}

int main() {
    cin >> D;
    reps(i, A) { cin >> c[i]; }
    reps(i, D) {
        reps(j, A) { cin >> s[i][j]; }
    }
    vint history(D + 1);
    reps(i, D) { cin >> history[i]; }
    vint ans = score(history);
    reps(i, D) { cout << ans[i] << endl; }
    
}


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

using namespace std;

int main ()
{
    //similar to Stepping Numbers in GeeksForGeeks
    int k;
    cin >> k;
    queue<unsigned long long> my_queue;
    for (unsigned long long i=1; i<=9; i++) {
        my_queue.push(i);
    }
    for (int i=1; i<=k-1; i++) {
        if (!my_queue.empty()) {
            unsigned long long p = my_queue.front();
            my_queue.pop();
            if (p%10 == 0) {
                my_queue.push(p*10 + p%10);
                my_queue.push(p*10 + p%10 + 1);
            }
            else if (p%10 == 9) {
                my_queue.push(p*10 + p%10 - 1);
                my_queue.push(p*10 + p%10);
            }
            else {
                my_queue.push(p*10 + p%10 - 1);
                my_queue.push(p*10 + p%10);
                my_queue.push(p*10 + p%10 + 1);
            }
        }
    }
    cout << my_queue.front() << endl;
    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define INF (1<<30)
#define MOD 1000000007
#define l_ength size
using ll = long long;
using namespace std;

int gcd( int a, int b ){
	return b ? gcd(b, a % b) : a;
}

int main(){
	int n, x;
	cin >> n >> x;
	vector<int> v;
	int temp;
	for( int i = 0; i < n; ++i ){
		cin >> temp;
		v.push_back(abs(temp-x));
	}
	if( n == 1 ){
		cout << v.at(0) << endl;
		return 0;
	}
	int a = gcd(v.at(0), v.at(1));
	for( int i = 2; i < n-1; ++i ) a = gcd(a, v.at(i));
	cout << a << endl;
	return 0;
}

Measured memory_bytes: 892
#define Oo ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#include <bits/stdc++.h>
using namespace std;
#define PI acos(-1.0)
typedef long long ll;
int main()
{
      Oo
      ll a,b,c,d;
      cin >> a >> b >> c >> d;
      ll t1, t2;
            if (abs(a)<abs(b))t1=a;
            else t1=b;
            if (abs(c)<abs(d))t2=c;
            else t2=d;
      cout << max(b*d, max(a*c, t1*t2)) << endl;

	return 0;
}


Measured memory_bytes: 3648
s=input()
mod=10**9+7
retnum={"?":0,"A":1,"B":2,"C":3}
count=[[0 for i in range(len(s))] for j in range(4)]
for i in range(len(s)):
    for j in range(4):
        if retnum[s[i]] == j:
            count[j][i]=count[j][i-1]+1
        else:
            count[j][i]=count[j][i-1]
ans=0
g=[1]*100002
for i in range(1,100002):
    g[i]=g[i-1]*3
    g[i]%=mod
for i in range(1,len(s)-1):
    if s[i]=="B" or s[i]=="?":
        ans+=(g[max(0,count[0][i-1]-1)]*count[0][i-1]+g[count[0][i-1]]*count[1][i-1])*(g[max(0,count[0][-1]-count[0][i]-1)]*(count[0][-1]-count[0][i])+g[count[0][-1]-count[0][i]]*(count[3][-1]-count[3][i]))
        ans%=mod
print(ans)

Measured memory_bytes: 13540
// Author: wlzhouzhuan
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#include <bits/stdc++.h>
using namespace std;

#define ll long long 
#define rint register int 
#define rep(i, l, r) for (rint i = l; i <= r; i++)
#define per(i, l, r) for (rint i = l; i >= r; i--)
#define mset(s, _) memset(s, _, sizeof(s))
#define pb push_back
#define pii pair <int, int>
#define mp(a, b) make_pair(a, b)

inline int read() {
  int x = 0, neg = 1; char op = getchar();
  while (!isdigit(op)) { if (op == '-') neg = -1; op = getchar(); }
  while (isdigit(op)) { x = (x << 3) + (x << 1) + op - '0'; op = getchar(); }
  return neg * x;
}

const int N = 100005;
const int mod = 1e9 + 7;
int a[N], n, ans;
int inv[N];

ll fac(int n) {
  ll res = 1;
  for (rint i = 1; i <= n; i++) {
    res = 1ll * res * i % mod;
  }
  return res;
}

int main() {
  n = read();
  inv[1] = 1;
  for (rint i = 2; i <= n; i++) {
    inv[i] = 1ll * inv[mod % i] * (mod - mod / i) % mod;
  }
  for (rint i = 2; i <= n; i++) {
    inv[i] = (inv[i] + inv[i - 1]) % mod;
  }
  for (rint i = 1; i <= n; i++) {
    a[i] = read();
    if (i > 1) {
      ans += 1ll * (a[i] - a[i - 1]) * inv[i - 1] % mod;
      if (ans > mod) ans -= mod;
    }
  }
  printf("%lld\n", 1ll * ans * fac(n - 1) % mod);
  return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(i=0;i<n;i++)
int main(){
  long long i,N,bf=1,cnt=0,ans=0;
  cin>>N;
  vector<long long> a(N),s(N+1,0);
  rep(i,N){
    cin>>a[i];
    s[i+1]=s[i]+a[i];
  }
  sort(s.begin(),s.end());
  rep(i,N+1){
    if(bf==s[i]){
      cnt++;
    }else{
      ans+=cnt*(cnt+1)/2;
      cnt=0;
      bf=s[i];
    }
  }
  ans+=cnt*(cnt+1)/2;
  cout <<ans<<endl;
}

Measured memory_bytes: 3456
#include <iostream>
#include <math.h>
using namespace std;

int main(){
    int a,b,c,n,tmp;
    cin >> n;
    for (int i = 0; i < n; ++i)
    {
        cin >> a >> b >> c;
        if (b>a)
        {
            tmp = a;
            a = b;
            b = tmp;
        }
        if (c>a)
        {
            tmp = a;
            a = c;
            c = tmp;
        }
        if (a*a == b*b + c*c)
        {
            cout << "YES" << endl;
        }
        else cout << "NO" << endl;
    }
    return 0;
}

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

vector<int> hmv{1, -1, 0, 0};
vector<int> vmv{0, 0, 1, -1};

void colour(vector<vector<int>> &maze, int r, int c, int col) {

	maze[r][c] = col;
	for(int i = 0; i < 4; i++) {
		int rr = r + hmv[i];
		int cc = c + vmv[i];

		if(rr >= 0 && rr < maze.size() && cc >= 0 && cc < maze[0].size() && maze[rr][cc] == INT_MAX) {
			colour(maze, rr, cc, col);
		}
	}
}

int bfs(vector<set<int>> &graph, int s, int e, int col)
{
	vector<bool> visited(col);
	deque<int> q, steps;
	q.push_back(s);
	steps.push_back(0);

	visited[s] = true;

	while(!q.empty())
	{
		int i = q.front();
		q.pop_front();
		int currentstep = steps.front();
		steps.pop_front();

		if(i == e)
			return currentstep;

		for(int j : graph[i])
		{
			if(visited[j])
				continue;

			visited[j] = 1;
			q.push_back(j);
			steps.push_back(currentstep + 1);

			if(j == e)
				return currentstep + 1;
		}
	}

	return -1;
}

int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int h, w; cin >> h >> w;
    int ch, cy; cin >> ch >> cy; ch--; cy--;
    int dh, dy; cin >> dh >> dy; dh--; dy--;

    vector<string> grid(h);
    for(int i = 0; i < h; i++) {
    	cin >> grid[i];
    }

    vector<vector<int>> maze(h, vector<int>(w, INT_MAX));
    
    for(int i = 0; i < h; i++) {
    	for(int j = 0; j < w; j++) {
    		if(grid[i][j] == '#') {
    			maze[i][j] = -1;
    		}
    	}
    }

    // This is the colouring part 
    int col = 0;
    for(int i = 0; i < h; i++) {
    	for(int j = 0; j < w; j++) {
    		if(maze[i][j] == INT_MAX)
    			colour(maze, i, j, col++);
    	}
    }


	vector<int> mov{-2, -1, 0, 1, 2};

    vector<set<int>> graph(col);

    for(int i = 0; i < h; i++) {

    	for(int j = 0; j < w; j++) {

    		if(maze[i][j] == -1) 
    			continue;

    		for(int k = 0; k < 5; k++) {

    			for(int l = 0; l < 5; l++) {

	    			int rr = i + mov[k];
	    			int cc = j + mov[l];

			 		if(rr >= 0 && rr < maze.size() && cc >= 0 && cc < maze[0].size() && maze[rr][cc] != -1 && maze[rr][cc] != maze[i][j]) {
						graph[maze[i][j]].insert(maze[rr][cc]);
					} 
				}
				  			
    		}
    	}
    } 

    int s = maze[ch][cy];
    int e = maze[dh][dy];

    cout << bfs(graph, s, e, col) << endl;

}


Measured memory_bytes: 32488
#include <string.h>
#include <stdio.h>
#include <iostream>
#include <string>
#include <cstring>
#include <math.h>
#include <set>
#include <vector>
#include <algorithm>
#include <map>

using namespace std;

typedef long long ll;
#define INF 0x3f3f3f3f
#define ESP 1e-8
#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
const double PI = acos(-1.0);

const ll N = 1e5+5;
char s1[N], s2[N];
ll n, m;

ll gcd(ll x, ll y){
    if(x < y)
        swap(x, y);
    ll r = x % y;
    while(r){
        x = y, y = r;
        r = x % y;
    }
    return y;
}

int main(){
    // FILE *fp = freopen("out.txt", "w", stdout);
    // freopen("in.txt", "r", stdin);
    ll i, j;
    while(scanf("%lld%lld", &n, &m) != EOF){
        scanf("%s%s", s1+1, s2+1);
        ll L = n*m/gcd(n, m);
        i = j = 1;
        ll t1=L/n, t2=L/m;
        bool flag = 1;
        while(i<=L && j<=L){
            if(i==j){
                if(s1[(i-1)/t1+1]!=s2[(j-1)/t2+1]){
                    flag = 0;
                    break;
                }
                i += t1;
                j += t2;
            }
            else if(i < j)
                i += t1;
            else if(i > j)
                j += t2;
        }
        if(flag)
            printf("%lld\n", L);
        else
            printf("-1\n");
    }

    // fclose(fp);
    return 0;
}

Measured memory_bytes: 384
#include <algorithm>
#include <bitset>
#include <cmath>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#include <iomanip>

using namespace std;
using ll = int64_t;
using VL = vector<ll>;
using VD = vector<double>;
using VVL = vector<VL>;
using VVD = vector<VD>;

#define FOR(i, start, end) for(ll i = (start), (i ## xxxx_end)=(end); i < (i ## xxxx_end); ++i)
#define FORD(i, start, end) for(ll i = (start), (i ## xxxx_end)=(end); i > (i ## xxxx_end); --i)
#define REP(i, n) FOR(i, 0, n)
#define REPD(i, n) FORD(i, n - 1, -1)

#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))

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

template <class T, class U>ostream &operator<<(ostream &o, const map<T, U>&obj) {o << "{"; for (auto &x : obj) o << " {" << x.first << " : " << x.second << "}" << ","; o << " }"; return o;}
template <class T>ostream &operator<<(ostream &o, const set<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const multiset<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const vector<T>&obj) {o << "{"; for (int i = 0; i < (int)obj.size(); ++i)o << (i > 0 ? ", " : "") << obj[i]; o << "}"; return o;}
template <class T, class U>ostream &operator<<(ostream &o, const pair<T, U>&obj) {o << "{" << obj.first << ", " << obj.second << "}"; return o;}
template <template <class tmp>  class T, class U> ostream &operator<<(ostream &o, const T<U> &obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr)o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
void print(void) {cout << endl;}
template <class Head> void print(Head&& head) {cout << head;print();}
template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) {cout << head << " ";print(forward<Tail>(tail)...);}

#define INF 1000000000000
#define MOD 1000000007

ll N, TARO;
VL A;
VVL dp;

ll f(ll i, ll j) {
    if(dp[i][j] != -1)
        return dp[i][j];
    
    if(i == j)
        return dp[i][j] = 0;
    
    if((j - i) % 2 == TARO) {
        return dp[i][j] = max(f(i + 1, j) + A[i], f(i, j - 1) + A[j - 1]);
    }
    else {
        return dp[i][j] = min(f(i + 1, j) - A[i], f(i, j - 1) - A[j - 1]);
    }
}

void solve() {
    cin >> N;
    TARO = N % 2;
    A = VL(N);
    for(auto& a : A) cin >> a;
    dp = VVL(N + 1, VL(N + 1, -1));
    print(f(0, N));
}

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

Measured memory_bytes: 70912
#include<bits/stdc++.h>
#define pb push_back
using namespace std;
const int N=1e5+50;
int n,r1,r2,ans[N],f1[N],f2[N],id[N];
vector<int>v1[N],v2[N],vv[N];
void dfs1(int x){
	for(int i=0;i<v1[x].size();i++)dfs1(v1[x][i]);
    for(int i=1,y,z;i<v1[x].size();i+=2)
        y=id[v1[x][i-1]],z=id[v1[x][i]],vv[y].pb(z),vv[z].pb(y);
    if(v1[x].size()&1)id[x]=id[v1[x].back()],ans[x]=0;
}
void dfs2(int x){
	for(int i=0;i<v2[x].size();i++)dfs2(v2[x][i]);
    for(int i=1,y,z;i<v2[x].size();i+=2)
        y=id[v2[x][i-1]],z=id[v2[x][i]],vv[y].pb(z),vv[z].pb(y);
    if(v2[x].size()&1)id[x]=id[v2[x].back()],ans[x]=0;
}
void dfs(int x){
	for(int i=0,y;i<vv[x].size();i++)
		if(ans[y=vv[x][i]]>1)ans[y]=-ans[x],dfs(y);
}
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++)ans[i]=2;
	for(int i=1,x;i<=n;i++){
		scanf("%d",&x);
		if(~x)v1[x].pb(i);else r1=i;
	}
	for(int i=1,x;i<=n;i++){
		scanf("%d",&x);
		if(~x)v2[x].pb(i);else r2=i;
	}
	for(int i=1;i<=n;i++)if((v1[i].size()&1)^(v2[i].size()&1))puts("IMPOSSIBLE"),exit(0);
    for(int i=1;i<=n;i++)id[i]=i;dfs1(r1);
    for(int i=1;i<=n;i++)id[i]=i;dfs2(r2);
	for(int i=1;i<=n;i++)if(ans[i]>1)ans[i]=1,dfs(i);
	puts("POSSIBLE");
	for(int i=1;i<=n;i++)printf("%d ",ans[i]);
	return 0;
}

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

long long int A, B, C, K, a;

int main(){
    scanf("%lld%lld%lld%lld", &A, &B, &C, &K);
    a = A + B + C;
    a += (max({A, B, C}) * ((1 << K) - 1));
    cout << a << endl;
    return 0;
}

Measured memory_bytes: 256
A, B = [int(i) for i in input().split(' ')]

count = B - A + 1

res = 0
ones = (count - (count % 2)) / 2
if count % 2:
    seed = A if A % 2 else B
    res = 1 ^ seed if ones % 2 else seed
else:
    res = ((A % 2)*(A ^ B ^ 1)) ^ (1 if ones % 2 else 0)

print(res)


Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <stack>
#include <deque>
#include <cmath>
#include <map>
using ll = long long;
using namespace std;

int main() {
  int n;
  cin >> n;
  int sq = (int)sqrt(n);
  cout << sq * sq << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for(ll i=0; i<ll(n); i++)
#define REPR(i, n) for(ll i=n-1; i>=0; i--)
#define FOR(i, m, n) for(ll i=m; i<ll(n); i++)
#define ALL(v) v.begin(), v.end()
#define SIZE(x) ll(x.size()) 
using P = pair<int, int>;
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; }
const int INF = 2e9;
const ll LINF = (1LL<<60);

const int MAX_V = 1e6+5;
const int dx[] = {0, 0, -1, 1};
const int dy[] = {-1, 1, 0, 0};

struct edge
{
  int to;
  int cost;
};

int V;
vector<edge> G[MAX_V];
int d[MAX_V];

void dijkstra(int s)
{
  priority_queue<P, vector<P>, greater<P>> que;
  fill(d, d + V, INF);
  d[s] = 0;
  que.emplace(0, s);

  while (!que.empty()){
    P p = que.top();
    que.pop();
    int v = p.second;
    if (d[v] < p.first) continue;

    for(auto nv: G[v]){
      if (d[nv.to] > d[v] + nv.cost){
        d[nv.to] = d[v] + nv.cost;
        que.emplace(d[nv.to], nv.to);
      }
    }
  }
}

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int h,w; cin >> h >> w;
  int ch,cw,dh,dw;
  cin >> ch >> cw >> dh >> dw;
  ch--, cw--, dh--, dw--;
  vector<string> field(h);
  REP(i,h) cin >> field[i];

  V = h*w;
  REP(i,h) REP(j,w){
    if(field[i][j]=='#') continue;
    REP(k,4){
      int nh = i + dy[k];
      int nw = j + dx[k];
      if(nh<0 || nh>=h || nw<0 || nw>=w) continue;
      if(field[nh][nw]=='#') continue;
      G[i*w+j].push_back((edge){nh*w+nw, 0});
    }

    for(int x=-2; x<=2; x++){
      for(int y=-2; y<=2; y++){
        if(x==0 && y==0) continue;
        int nh = i + y;
        int nw = j + x;
        if(nh<0 || nh>=h || nw<0 || nw>=w) continue;
        if(field[nh][nw]=='#') continue;
        G[i*w+j].push_back((edge){nh*w+nw, 1});
      }
    }
  }

  dijkstra(ch*w+cw);

  cout << (d[dh*w+dw]==INF ? -1 : d[dh*w+dw]) << '\n';
  return 0;
}


Measured memory_bytes: 113908
#include "bits/stdc++.h"
#include <boost/range/irange.hpp>
//#include <boost/range/algorithm.hpp>

using namespace std;
using boost::irange;

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

#define ALL(x)              (x).begin(),(x).end()
#define REP(i, n)           for (ll i = 0 ; i < (ll)n ; ++i)
#define REPN(i, m, n)       for (ll i = m ; i < (ll)n ; ++i)
#define INF                 (ll)1e9
#define MOD                 (1000 * 1000 * 1000 + 7)
#define Ceil(x, n)          (((((x))+((n)-1))/n))
#define CeilN(x, n)         (((((x))+((n)-1))/n)*n)
#define FloorN(x, n)        ((x)-(x)%(n))
#define IsOdd(x)            (((x)&0x01UL) == 0x01UL)
#define IsEven(x)           (!IsOdd((x)))
#define M_PI                3.14159265358979323846

// 処理
void Solve()
{
	ll K;
	string s;
	cin >> s >> K;
	for_each(ALL(s), [&](char &one){ 
		if (one != 'a') {
			ll diff = 26 - (one - 'a');
			if (diff <= K) {
				one = 'a';
				K -= diff;
			}
		}
	});
	ll diff = ((s.back() - 'a') + K) % 26;
	s.back() = 'a' + diff;
	cout << s << endl;
}

// メイン
int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Solve();
	return 0;
}


Measured memory_bytes: 592
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
 
int main()
{
    int e[101][101];
    int R, C, r, c;
    int s, total;
 
    scanf("%d%d", &R, &C);
    for (r = 1; r <= R; r++) {
        for (c= 1; c <= C; c++) scanf("%d", &e[r][c]);
    }
     
    for (r = 1; r <= R; r++) {
        s = 0;
        for (c = 1; c <= C; c++) s += e[r][c];
        e[r][0] = s;
    }
    total = 0;
    for (c = 1; c <= C; c++) {
        s = 0;
        for (r = 1; r <= R; r++) s += e[r][c];
        e[0][c] = s;
        total += s;
    }
    for (r = 1; r <= R; r++) {
        for (c = 1; c <= C; c++) printf("%d ", e[r][c]);
        printf("%d\n", e[r][0]);
    }
    for (c = 1; c <= C; c++) printf("%d ", e[0][c]);
    printf("%d\n", total);
    return 0;
}


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

typedef long long ll;

using namespace std;

#define swap(a, b)    do { typeof(a) __tmp = (a); (a) = (b); (b) = __tmp; } while(0)
#define repd(i, a, b) for(typeof(b) i = a; i < (b); ++i)
#define rep(i, n)     repd(i, 0, n)
#define dump(x)       cerr << #x << " = " << (x) << endl
#define debug(x)      cerr << "L" << __LINE__ << ": " << #x << " = " << (x) << endl
#define YesNo(x)      cout << ((x) ? "Yes" : "No") << endl
#define YESNO(x)      cout << ((x) ? "YES" : "NO") << endl
#define absi(x)       ( ((x) >= 0) ? (x) : (-(x)) )

int main(int argc, const char* argv[]) {
	ll w, h, x, y;
	cin >> w >> h >> x >> y;

	cout << ((double)(w * h) / 2.0) << " " << ((w == x * 2) && (h == y * 2)) << endl;

	return 0;
}


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

const double pi  = 2 * acos(0.0);
const double eps = 1e-8;

#define REP(i,a,b) for(int i=(a); i<(b);++i)
#define rep(i,n) REP(i,0,n)
#define INF (1<<29)
#define INFLL (1LL<<61)

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

int main(void) {
  ios_base::sync_with_stdio(false); cin.tie(0);
  int N;
  map<int, int> cnt;

  cin >> N;

  rep(i, N) {
    int a;
    cin >> a;
    cnt[a]++;
    cnt[a+1]++;
    cnt[a-1]++;
  }

  int ans = 0;
  for (auto & p : cnt) {
    ans = max(p.second, ans);
  }

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


Measured memory_bytes: 4736
#include <iostream>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <string>
#include <sstream>
#include <algorithm>
#include <random>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
#include <cassert>
#include <climits>
#include <bitset>
#include <functional>
#include <iomanip>
#include <random>

#define FOR_LT(i, beg, end) for (int i = (int)(beg); i < (int)(end); i++)
#define FOR_LE(i, beg, end) for (int i = (int)(beg); i <= (int)(end); i++)
#define FOR_DW(i, beg, end) for (int i = (int)(beg); (int)(end) <= i; i--)
#define REP(n)              for (int repeat_index = 0; repeat_index < (int)n; repeat_index++)

using namespace std;

struct P {
	int64_t x;
	int64_t y;
};

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout << fixed << setprecision(20);

	int n; cin >> n;
	vector<P> ps(n); for (auto& p : ps) { cin >> p.x >> p.y;  }

	sort(ps.begin(), ps.end(), [](const auto& lhs, const auto& rhs) {
		return lhs.y > rhs.y;
		});

	P lv = ps[0];
	P rv = ps[0];
	int64_t ans = 0;
	FOR_LT(i, 1, n) {
		P& cp = ps[i];
		int64_t lvv = abs(lv.x - cp.x) + abs(lv.y - cp.y);
		int64_t rvv = abs(rv.x - cp.x) + abs(rv.y - cp.y);
		ans = max(ans, lvv);
		ans = max(ans, rvv);

		if (lv.x - cp.x >= lv.y - cp.y) {
			lv = cp;
		}
		if (cp.x - rv.x >= rv.y - cp.y) {
			rv = cp;
		}
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 6364
#include <iostream>
#include <string>
#include <math.h>
#include <algorithm>
#include <map>
#include <vector>
using namespace std;

int main() {
	string S, T;
	bool key = true;

	cin >> S >> T;
	
	for (int i = 0; i < S.size(); i++) {
		if (S[i] == T[i]) continue;
		else { key = false; }
	}

	if (key) { cout << "Yes"; }
	else { cout << "No"; }
	
	return 0;
}

Measured memory_bytes: 3036
/*
    Author : Nishant Gupta 2.0
*/
#include<bits/stdc++.h>
using namespace std;

#define LL long long int
#define getcx getchar_unlocked
#define X first
#define Y second
#define PB push_back
#define MP make_pair
#define MAX 100005
#define LOG_MAX 20
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL (LL(1e18))
#define chk(a) cerr << endl << #a << " : " << a << endl
#define chk2(a,b) cerr << endl << #a << " : " << a << "\t" << #b << " : " << b << endl
#define chk3(a,b,c) cerr << endl << #a << " : " << a << "\t" << #b << " : " << b << "\t" << #c << " : " << c << endl
#define chk4(a,b,c,d) cerr << endl << #a << " : " << a << "\t" << #b << " : " << b << "\t" << #c << " : " << c << "\t" << #d << " : " << d << endl
#define rep(i, a, n) for(i=a;i<n;i++)
#define rev(i, a, n) for(i=a;i>=n;i--)
#define in(x) scanf("%d", &x)
#define inl(x) scanf("%lld", &x)
#define in2(x, y) scanf("%d %d", &x, &y)
#define inl2(x, y) scanf("%lld %lld", &x, &y)
#define MSV(A,a) memset(A, a, sizeof(A))
#define rep_itr(itr, c) for(itr = (c).begin(); itr != (c).end(); itr++)
#define finish(x) {cout<<x<<'\n'; return;}
typedef pair<int, int> pi;
typedef pair<LL, LL> pl;
const char en = '\n';

void solve() {
	int n;in(n);
	if(n>=30) finish("Yes");
	finish("No");
}

int main() {
	int t = 1;
	
	//~cin>>t;
	while(t--) {
		solve();
	}
    return 0;
}


Measured memory_bytes: 3760
#include <iostream>
#include <vector>
#include <algorithm>

int main() {
  size_t N;
  std::cin >> N;

  std::vector<size_t> DictEven(100000, 0);
  std::vector<size_t> DictOdd(100000, 0);

  for (size_t i=0; i<N; i+=2) {
    size_t v;
    std::cin >> v;
    DictEven[v-1]++;

    std::cin >> v;
    DictOdd[v-1]++;
  }

  auto i_max_even =
    std::max_element(DictEven.begin(), DictEven.end());
  auto i_max_odd =
    std::max_element(DictOdd.begin(), DictOdd.end());

  auto max_even = *i_max_even;
  auto max_odd = *i_max_odd;

  if (std::distance(DictEven.begin(), i_max_even) ==
      std::distance(DictOdd.begin(), i_max_odd)) {
    *i_max_even = 0;
    *i_max_odd = 0;

    i_max_even =
      std::max_element(DictEven.begin(), DictEven.end());
    i_max_odd =
      std::max_element(DictOdd.begin(), DictOdd.end());

    if (*i_max_even > *i_max_odd) {
      max_even = *i_max_even;
    } else {
      max_odd = *i_max_odd;
    }
  }

  auto ans = N - max_even - max_odd;

  std::cout << ans << std::endl;

  return 0;
}


Measured memory_bytes: 1792
n, m = map(int, input().split())

l = [0]*(n + 1)
ac = 0
wa = 0

for i in range(m):
    p, s = input().split()
    p = int(p)
    if l[p] != -1:
        if s == "AC":
            ac += 1
            wa += l[p]
            l[p] = -1
        else:
            l[p] += 1

print(ac, wa)

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

using namespace std;

int main(void) {
    int a, b, ans;

    cin >> a >> b;

    for (int i = 1; i <= 1000; i++) {
        if (i * 8/100 == a && i * 10/100 == b) {
            ans = i;
            break;
        } else if (i * 8/100 > a || i * 10/100 > b) {
            ans = -1;
            break;
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

const int MOD = 1e9 + 7;

// thanks pekempey for struct // https://atcoder.jp/contests/abc132/submissions/6188715
struct mint { int n; mint(int n_ = 0) : n(n_) {} };
mint operator-(mint a) { return -a.n + MOD * (a.n != 0); }
mint operator+(mint a, mint b) { int x = a.n + b.n; return x - (x >= MOD) * MOD; }
mint operator-(mint a, mint b) { int x = a.n - b.n; return x + (x < 0) * MOD; }
mint operator*(mint a, mint b) { return (long long)a.n * b.n % MOD; }
mint &operator+=(mint &a, mint b) { return a = a + b; }
mint &operator-=(mint &a, mint b) { return a = a - b; }
mint &operator*=(mint &a, mint b) { return a = a * b; }
istream &operator>>(istream &i, mint &a) { return i >> a.n; }
ostream &operator<<(ostream &o, mint a) { return o << a.n; }

int N, K;

const int SQRTNTIMESTWO = 63246;

mint dp[SQRTNTIMESTWO + 5][2];


int main() {
    ios_base::sync_with_stdio(false);
    cin >> N >> K;

    vector <int> stuff;
    for(int i = 1; i * i <= N; i++) {
        stuff.push_back(i);
        stuff.push_back(N / i);
    }
    sort(stuff.begin(), stuff.end());
    stuff.erase(unique(stuff.begin(), stuff.end()), stuff.end());

    dp[0][0] = 1;
    for(int i = 1; i <= K; i++) {
        int step = i % 2;
        mint suma = 0;
        int idx = 0;
        for(int j = stuff.size() - 1; j >= 0; j--) {
            while(idx < stuff.size() && stuff[j] * 1LL * stuff[idx] <= N)
                suma += dp[idx++][!step];

            dp[j][step] = (stuff[j] - (j == 0 ? 0 : stuff[j - 1])) * suma;
        }
    }

    mint ans = 0;
    for(int i = 0; i < stuff.size(); i++)
        ans += dp[i][K % 2];
    cout << ans << endl;
}

Measured memory_bytes: 1152
c = []
for i in range(3):
    c.append(list(map(int, input().split())))

temp1, temp2 = [], []
temp3, temp4 = [], []
for i in range(3):
    temp1.append(c[1][i] - c[0][i])
    temp2.append(c[2][i] - c[0][i])
    temp3.append(c[i][1] - c[i][0])
    temp4.append(c[i][2] - c[i][0])
if len(set(temp1)) == len(set(temp2)) == len(set(temp3)) == len(set(temp4)) == 1:
    print('Yes')
else:
    print('No')


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

#define MIN(a, b) (a > b ? b : a)

int main(void) {
  int N; cin >> N;
  int c = 0, A = 0, B = 0, AB = 0;
  for (int i = 0; i < N; i++) {
    string si; cin >> si;
    for (int i = 0; i < si.length(); i++) if (i < si.length()-1 && si[i] == 'A' && si[i+1] == 'B') c++;
    if (si.front() == 'B' && si.back() == 'A') AB++;
    else if (si.front() == 'B') B++;
    else if (si.back() == 'A') A++;
  }

  if (AB == 0) cout << c + MIN(A, B) << endl;
  else {
    if (A > 0) {
      c++;
      A--;
    }
    if (B > 0) {
      c++;
      B--;
    }

    if (A == B) cout << c + AB-1 + A << endl;
    else cout << c + AB-1 + MIN(A, B) << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int,int> P;

const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

mint f(int n,int m) {
  if (n == 0) return 1;
  mint x = f(n/2,m);
  x *= x;
  if (n%2 == 1) x *= m;
  return x;
}

mint dp[100005];

int main(){
    int n,k;
    cin >> n >> k;
    mint ans = 0;
    for(int i=k;i>0;i--){
        int d = i;
        mint res = f(n,k/d);
        while(d+i<=k){
            d += i;
            res -= dp[d];
        }
        dp[i]=res;
    }
    rep(i,k)ans += dp[i+1]*(i+1);
    cout << ans.x << endl;
}


Measured memory_bytes: 4416
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define rush() int T;scanf("%d",&T);while(T--)
#define mm(a,b) memset(a,b,sizeof(a))
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define sc(a) scanf("%d",&a)
#define sc2(a,b) scanf("%d%d",&a,&b)
#define pf(a) printf("%d\n",a)
#define pf2(a,b) printf("%d %d\n",a,b)
#define p_f(a) printf("%d ",a)
#define fi first
#define se second
#define db double
#define ll long long
using namespace std;
const int inf=0x3f3f3f3f;
const ll INF=0x3f3f3f3f3f3f3f3f;
const db eps=1e-9;
const int N=1e3+5;
int h,n,a[N],b[N],f[25000];
int main()
{
    cin>>h>>n;
	rep(i,1,n)cin>>a[i]>>b[i];
	mm(f,inf);
	f[0]=0;
	rep(i,1,n)rep(j,a[i],h+10000){
		f[j]=min(f[j],f[j-a[i]]+b[i]);
	}
	int ans=inf;
	rep(i,h,h+10000)ans=min(ans,f[i]);
	cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <cstring>
#include <utility>
#include <numeric>

using namespace std;

int main(){

    int N;
    cin >> N;
    vector<int> p(N);
    for(int i = 0; i < N; i++){
        cin >> p[i];
    }

    vector<int> ans = p;
    sort(ans.begin(), ans.end());

    if(p == ans){
        cout << "YES" << endl;
        return 0;
    }

    for(int i = 0; i < N; i++){
        for(int j = i + 1; j < N; j++){
            vector<int> temp = p;
            swap(temp[i], temp[j]);
            if(ans == temp){
                cout << "YES" << endl;
                return 0;
            }
        }
    }
    cout << "NO" << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
using namespace std;
const int MOD = 1e9+7;
using ll = long long;
using vi = vector<int>;
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(x) x.begin(), x.end()
int main() {
  int a,b,sum=0;
  cin >> a >> b;
  vi ans(b,0);
  rep(i,a){
    int d;
    cin >> d;
    rep(j,d){
      int e;
      cin >> e;
      e--;
      ans.at(e)++;
    }
  }rep(i,b){
    if(ans.at(i)==a)sum++;
}
cout << sum;
}

Measured memory_bytes: 3608
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <string>
#include <algorithm>
#include <numeric>

typedef long long ll;
const ll INF = 1e18 + 1;

void print(){ std::cout << std::endl; }
template <typename Head> void print(Head&& head) { std::cout << head << std::endl; }
template <typename Head, typename... Tail> void print(Head&& head, Tail&&... tail)
{
  std::cout << head << " ";
  print(std::forward<Tail>(tail)...); // or print(tail...);
}
template<typename Iterator> void printVec(Iterator begin, Iterator end)
{
  for (Iterator it = begin; it != end; it++) {
    std::cout << "[" << std::distance(begin, it) << "] " << *it << " ";
    if (std::distance(begin, it) % 50 == 49) { std::cout << std::endl; }
  }
  std::cout << std::endl;
}


int main(int argc, char* argv[])
{
  std::cin.tie(nullptr);
  std::ios::sync_with_stdio(false);

  ll N;
  std::cin >> N;
  std::vector< ll > va(N, 0LL);
  std::vector< ll > vb(N, 0LL);
  std::vector< ll > vc(N, 0LL);
  for (ll i = 0; i < N; i++) { std::cin >> va[i];}
  for (ll i = 0; i < N; i++) { std::cin >> vb[i];}
  for (ll i = 0; i < N; i++) { std::cin >> vc[i];}

  std::sort(va.begin(), va.end());
  std::sort(vc.begin(), vc.end());

  std::vector< ll >::iterator ita;
  std::vector< ll >::iterator itc;

  ll ans = 0;
  for (ll j = 0; j < N; j++) {
    ita = std::lower_bound(va.begin(), va.end(), vb[j]);
    itc = std::upper_bound(vc.begin(), vc.end(), vb[j]);

    ans += std::distance(va.begin(), ita) * (N - std::distance(vc.begin(), itc));
  }

  print(ans);
  return 0;
}


Measured memory_bytes: 2560