akhauriyash/Code-Regression huggingface dataset:
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;
using ll = long long int;
using int64 = long long int;
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const int INF = 1001001001;
const ll LONGINF = 1001001001001001LL;
const ll MOD = 1000000007LL;
 
int main() {
    string s; cin >> s;
    int K; cin >> K;

    vector< pair<char, ll> > vec;
    for(auto c : s) {
        if(vec.empty() or vec.back().first != c) vec.emplace_back(c, 1);
        else vec.back().second++;
    }

    ll ans = 0;
    if(vec.size() >= 3) {
        // 最初と最後が同じ
        if(vec.front().first == vec.back().first) {
            ans += vec.front().second / 2;
            ans += vec.back().second / 2;
            ans += (vec.front().second + vec.back().second) / 2 * (K - 1);

            for(int i=1; i+1<vec.size(); i++) {
                ans += vec[i].second / 2 * K;
            }
        }
        // 違う
        else {
            for(auto e : vec) ans += e.second / 2 * K;
        }
    }
    else if(vec.size() == 2) {
        for(auto e : vec) ans += e.second / 2 * K;
    }
    else {
        ans += vec.front().second * K / 2;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
fun main() {
    val n = readLine()!!.trim().toInt()
    val series = readLine()!!.trim().split(' ').map(String::toLong)
    val count = LongArray(100001){0L}
    for (i in series) count[i.toInt()]++
    var currentSum = series.sum()
    repeat(readLine()!!.trim().toInt()) {
        val (b, c) = readLine()!!.trim().split(' ').map(String::toInt)
        val move = count[b]
        count[b] = 0
        count[c] += move
        currentSum += (c - b) * move
        println(currentSum)
    }
}

Measured memory_bytes: 70172
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main(void){
  int n,m, xt, yt;
  vector<int> x, y;
  
  cin >> n >> m >> xt >> yt;
  x.push_back(xt);
  y.push_back(yt);
  for (int i=0; i<n; i++){
    cin >> xt; x.push_back(xt);
  }
  for (int i=0; i<m; i++){
    cin >> yt; y.push_back(yt);
  }
  sort(x.begin(), x.end());
  sort(y.begin(), y.end());
  if (x[n] >= y[0]){
    cout << "War" << endl;
  } else {
    cout << "No War" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <cstdlib>
#define rep(i,n) for(int i = 0;i<(n);i++);
#define all(a) (a).begin(),(a).end()
using namespace std;
using ld = long double;
using ll = long long;
const ll INF = 100100100100100;
ll gcd(ll a,ll b) {//a>b
	if (a < b)swap(a, b);
	if (a % b == 0) return b;
	else return gcd(b, a % b);
}
int main() {
	ll N;
	cin >> N;
	vector<ll> num(N);
	for (int i = 0; i < N; i++) cin >> num[i];
	ll ans = gcd(num[0], num[1]);
	for (int i = 0; i < N - 1; i++) {
		ans = gcd(num[i], ans);
	}
	cout << ans << endl;
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <math.h>
#include <limits.h>

int sort(const void *a, const void *b){
    return *(int*)a-*(int*)b ;
}

int main(void){
    long long n,a,b,max=0;
    scanf("%lld%lld%lld",&n,&a,&b);
    long long h[n],p[n];
    for (int i=0; i<n; i++){
        scanf("%lld",&h[i]);
        if (max<h[i]){
            max=h[i];
        }
    }
    
    long long  small=0,big=(max+b-1)/b;
    while (small!=big){
        long long t=small+(big-small)/2,count=0;
        for (int i=0; i<n; i++){
            p[i]=h[i];
            p[i]-=t*b;
            if (p[i]>0){
                count+=(p[i]+(a-b)-1)/(a-b);
            }        
        }
        if (count>t){
            small=t+1;
        } else {
            big=t;
        }
    }
    printf("%lld\n",big);
	return 0 ;
}

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

int main()
{
    string A;
    cin>>A;
    long long n  = A.length();
    map<char, long long> cnt;
    for (int i=0; i<n; i++)
        cnt[A[i]]++;
    long long ans = n*(n+1)/2 + 1;
    for (auto p: cnt)
        ans -= p.second*(p.second+1)/2;
    cout<<ans;
}

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

string sml(int a, int b) {
    string ret;
    if (a > b)
        ret = "a > b";
    else if (a == b)
        ret = "a == b";
    else
        ret = "a < b";
    return ret;
}

int main(){
    int a, b;
    cin >> a >> b;

    cout << sml(a, b) << endl;
    return 0;
}


Measured memory_bytes: 3160
n = int(input())
r = 55555
sosu = [1] * (r+1)
sosu[0],sosu[1] = 0,0
sosu[2] = 1
for i in range(2,int(r**0.5)+3):
    for j in range(i*2,r+1,i):
        sosu[j] = 0

a = []
for i in range(r+1):
    if sosu[i] == 1:
        if i%5 == 1:
            a.append(i)
            
ans = []
for i in range(n):
    ans.append(a[i])
    
print(*ans)

Measured memory_bytes: 67496
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define int long long int

template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}

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

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
constexpr ll INF = 1001001001001001LL;
constexpr ll MOD = 1000000007LL;

int P[210];

signed main() {
    int M, Nmi, Nma;
    while(cin >> M >> Nmi >> Nma, M || Nmi || Nma) {
        rep(i,0,M) cin >> P[i];
        sort(P, P+M, greater<int>());
        int gapmax = -1, ans = 0;
        rep(i,0,M) {
            if(!(Nmi <= i+1 && i+1 <= Nma)) continue;
            int gap = P[i] - P[i+1];
            if(gapmax <= gap) {
                gapmax = gap;
                ans = i+1;
            }
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 3044
/* 	* In the name of GOD 
	* Thanks God */
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
#define F first
#define S second
#define int long long

int f(int n) {
	if (n == 0)
		return 0;
	return (2 * f(n / 2)) + 1;
}

int32_t main(){
	int n;
	cin >> n;
	cout << f(n);
}


Measured memory_bytes: 3640
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <vector>
using namespace std;
int main() {
    int n;
    while(cin>>n&&n!=0){int cnt=0;
        for(int i=2;i<n;i++){
            int tmp=0;
            for(int j=1;j<=i;j++)
                tmp+=j;
            if((n-tmp)%i==0&&tmp<=n)cnt++;
        }
        cout<<cnt<<endl;}}

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

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

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

	int ans = 0;
	for (int i = 0; i < n - 1; i++) {
		for (int j = i + 1; j < n; j++) {
			ans += d[i] * d[j];
		}
	}

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

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

int main(void){
  string s[3];

  for(int i = 0; i < 3; i++){
    cin >> s[i];
  }

  for(int i = 0; i < 3; i++){
    cout << char(toupper(s[i][0]));
  }
  cout << endl;

  return 0;
}

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

def MDD(p,x,y):#Malti Dimension Distance
    ans=0
    for i,j in zip(x,y):
        ans+=abs(i-j)**p
    ans=ans**(1/p)
    print(ans)
MDD(1,x,y)
MDD(2,x,y)
MDD(3,x,y)
print(max(abs(i-j) for i,j in zip(x,y)))


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

int main(){
int max = 0;
int all= 0;
int N;
cin >> N;
int A[100];
for(int i =1;i < N+1;i++){
  cin >> A[i];
  if(max < A[i])max = A[i];
  all = all + A[i];
}   
           
if(max < all- max)cout << "Yes";
else cout << "No";
return 0;
}


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

int main(){

    int N;
    cin >> N;

    vector<ll> a(3*N);
    for (int i=0; i<3*N; i++){
        cin >> a.at(i);
    }

    sort(a.begin(), a.end());

    ll sum = 0;
    int cnt = 0;
    for (int i=3*N-2; i>=0; i -= 2){
        sum += a.at(i);
        cnt++;

        if (cnt >= N) break;
    }

//    cout << cnt << endl;    // debug
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 2688
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<stdio.h>

using namespace std;

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


int main()
{
    string s;
    cin >> s;
    
    if (s.find("AC") != std::string::npos) {
       cout << "Yes"<< endl;
    }
    else  cout << "No"<< endl;
}

Measured memory_bytes: 256
program ABC169E
    implicit none
    integer(8)::N,i
    integer(8),allocatable,dimension(:)::A,B
    read*,N
    allocate(A(N))
    allocate(B(N))
    do i=1,N
        read*,A(i),B(i)
    end do
    call heapsort(N,A)
    call heapsort(N,B)

    if(mod(N,2)==1)then
        print'(i0)',abs(A(N/2+1)-B(N/2+1))+1
    else
        print'(i0)',abs(A(N/2)+A(N/2+1)-B(N/2)-B(N/2+1))+1
    end if
end program ABC169E

subroutine heapsort(n,array)
    implicit none
    integer(8),intent(in) :: n
    integer(8),intent(inout) :: array(1:n)
   
    integer(8) ::i,k,j,l
    integer(8) :: t
   
    if(n.eq.1)return
  
    l=n/2+1
    k=n
    do while(k.ne.1)
       if(l.gt.1)then
          l=l-1
          t=array(L)
       else
          t=array(k)
          array(k)=array(1)
          k=k-1
          if(k.eq.1) then
             array(1)=t
             exit
          endif
       endif
       i=l
       j=l+l
       do while(j.le.k)
          if(j.lt.k)then
             if(array(j).lt.array(j+1))j=j+1
          endif
          if (t.lt.array(j))then
             array(i)=array(j)
             i=j
             j=j+j
          else
             j=k+1
          endif
       enddo
       array(i)=t
    enddo
  
    return
end subroutine heapsort

Measured memory_bytes: 6072
// author : Kartikey Tewari
// date: 2020-02-22   17:50:19
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define endl '\n'
#define pii pair<ll,ll>
using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);

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

    double a=log10(n+1)/log10(k);
    cout << ceil(a) << endl;

    return 0;
}

Measured memory_bytes: 768
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Globalization;
using System.Diagnostics;
using static System.Console;
using Pair = System.Collections.Generic.KeyValuePair<int, int>;
using System.Numerics;

class Program
{
    static void Main()
    {
        //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
        new Program().Solve();
        Out.Flush();
    }
    Scanner cin = new Scanner();
    Random rnd = new Random();
    Stopwatch sw = new Stopwatch();
    readonly int[] dd = { 0, 1, 0, -1, 0 };
    readonly int mod = 1000000007;
    readonly string alfa = "abcdefghijklmnopqrstuvwxyz";


    void Solve()
    {
        var A = BigInteger.Parse(ReadLine());
        var B = BigInteger.Parse(ReadLine());
        if (A > B)
        {
            WriteLine("GREATER");
        }
        else if (A < B)
        {
            WriteLine("LESS");
        }
        else
        {
            WriteLine("EQUAL");
        }
    }

}

class Scanner
{
    string[] s; int i;
    char[] cs = new char[] { ' ' };
    public Scanner() { s = new string[0]; i = 0; }
    public string[] Scan { get { return ReadLine().Split(); } }
    public int[] Scanint { get { return Array.ConvertAll(Scan, int.Parse); } }
    public long[] Scanlong { get { return Array.ConvertAll(Scan, long.Parse); } }
    public double[] Scandouble { get { return Array.ConvertAll(Scan, double.Parse); } }
    public string Next
    {
        get
        {
            if (i < s.Length) return s[i++];
            string st = ReadLine();
            while (st == "") st = ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            i = 0;
            return Next;
        }
    }
    public int Nextint { get { return int.Parse(Next); } }
    public long Nextlong { get { return long.Parse(Next); } }
    public double Nextdouble { get { return double.Parse(Next); } }
}

Measured memory_bytes: 13392
def main():
	N, M = map(int, input().split())
	S = []
	for i in range(N):
		a, b = map(int, input().split())
		S.append([a, b])
	sorted_shop_list = sorted(S, key=lambda x: x[0])
	cost = 0
	for i in sorted_shop_list:
		a = i[0]
		b = i[1]
		if b < M:
			M -= b
			cost += a * b
		else:
			cost += a * M
			break
	print(cost)
	return

if __name__ == '__main__':
	main()


Measured memory_bytes: 22032
#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>;
const long long INF = 1ll << 60;

template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

//



int N, W;

int main () {
  cin >> N >> W;
  vector<int> w(N);
  vector<ll> v(N);
  vector<vector<ll>> dp(N+1,vector<ll>(W+1,0));
  rep(i,N) cin >> w[i] >> v[i];

  rep(i,N){
    for(int j = 0; j <= W; j++){
      if( j - w[i] >= 0){
        chmax(dp[i + 1][j], dp[i][j - w[i]] + v[i]);
      }
      chmax(dp[i+1][j], dp[i][j]);
    }
  }

  cout << dp[N][W] << endl;

}

Measured memory_bytes: 83252
#!/usr/bin/env python3
n, k = map(int, input().split())
ans = 0
for p in range(1, n + 1):
    c = 0
    while (True):
        if p >= k:
            ans += (1 / n) * (1 / 2) ** c
            break
        p *= 2
        c += 1
print(ans)


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

int main(void) {
  string ss;
  cin >> ss;
  
  if(ss=="Sunny") cout << "Cloudy" << endl;
  else if(ss=="Cloudy") cout << "Rainy" << endl;
  else cout << "Sunny" << endl;

  return (0);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef struct {
  int a1;
  int a2;
  int a3;
  int a4;
  int a5;
  int a6;
}dice_t;

int main(){
  int a[6];
  for(int i=0;i<6;i++){
    cin>>a[i];
  }
  dice_t p = {a[0],a[1],a[2],a[3],a[4],a[5]};
  int q;
  cin>>q;
  for(int i=0;i<q;i++){
    int u,z;
    cin>>u>>z;
    if(u==p.a1){
      if(z==p.a2){
	cout<<p.a3<<endl;
      }
      else if(z==p.a3){
	cout<<p.a5<<endl;
      }
      else if(z==p.a5){
	cout<<p.a4<<endl;
      }
      else if(z==p.a4){
	cout<<p.a2<<endl;
      }
    }
    else if(u==p.a2){
      if(z==p.a1){
	cout<<p.a4<<endl;
      }
      else if(z==p.a3){
	cout<<p.a1<<endl;
      }
      else if(z==p.a6){
	cout<<p.a3<<endl;
      }
      else if(z==p.a4){
	cout<<p.a6<<endl;
      }
    }
    else if(u==p.a3){
      if(z==p.a1){
	cout<<p.a2<<endl;
      }
      else if(z==p.a2){
	cout<<p.a6<<endl;
      }
      else if(z==p.a6){
	cout<<p.a5<<endl;
      }
      else if(z==p.a5){
	cout<<p.a1<<endl;
      }
    }
    else if(u==p.a4){
      if(z==p.a1){
	cout<<p.a5<<endl;
      }
      else if(z==p.a5){
	cout<<p.a6<<endl;
      }
      else if(z==p.a6){
	cout<<p.a2<<endl;
      }
      else if(z==p.a2){
	cout<<p.a1<<endl;
      }
    }
    else if(u==p.a5){
      if(z==p.a1){
	cout<<p.a3<<endl;
      }
      else if(z==p.a3){
	cout<<p.a6<<endl;
      }
      else if(z==p.a6){
	cout<<p.a4<<endl;
      }
      else if(z==p.a4){
	cout<<p.a1<<endl;
      }
    }
    else if(u==p.a6){
      if(z==p.a2){
	cout<<p.a4<<endl;
      }
      else if(z==p.a4){
	cout<<p.a5<<endl;
      }
      else if(z==p.a5){
	cout<<p.a3<<endl;
      }
      else if(z==p.a3){
	cout<<p.a2<<endl;
      }
    }
  }

  return 0;
}
    



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

class FFroute{
    int H;
    int W;
    std::vector< std::vector< bool > > square;
    std::vector< std::vector< int > > square_N;
    std::deque< std::vector< int > > deq;
    std::deque< std::vector< int > > deq_next;
public:
    FFroute(int H_in, int W_in){
        H = H_in;
        W = W_in;
        square.resize(H);
        for(int i=0; i<H; i++){
            square[i].resize(W);
        }
        square_N.resize(H);
        for(int i=0; i<H; i++){
            square_N[i].assign(W, 200);
        }
    }
    
    void BW_in(int i, int j, bool BW){
        square[i][j] = BW;
    }
    
    int walk(){
        std::vector< int > tmp(3);
        tmp[0] = 0;
        tmp[1] = 0;
        if(square[0][0]){
            tmp[2] = 0;
        }else{
            tmp[2] = 1;
        }
        deq.push_back(tmp);
        int n = -1;
        while(n < 0){
            while(!deq.empty()){
                n = walk_1square(deq[0][0], deq[0][1], deq[0][2]);
                deq.pop_front();
                if(n >= 0){break;}
            }
            deq = deq_next;
            deq_next.clear();
        }
        return n;
    }
    
    int walk_1square(int i, int j, int n){
        if(i == H-1 && j == W-1){
            return n;
        }
        if(square_N[i][j] <= n){
            return -1;
        }
        square_N[i][j] = n;
        bool cur_bw = square[i][j];
        int B_inc = cur_bw ? 1 : 0;
        if(i != H-1){
            if(square[i+1][j] == cur_bw){
                std::vector< int > tmp(3);
                tmp[0] = i + 1;
                tmp[1] = j;
                tmp[2] = n;
                deq.push_back(tmp);
            }else{
                std::vector< int > tmp(3);
                tmp[0] = i + 1;
                tmp[1] = j;
                tmp[2] = n + B_inc;
                deq_next.push_back(tmp);
            }
        }
        if(j != W-1){
            if(square[i][j+1] == cur_bw){
                std::vector< int > tmp(3);
                tmp[0] = i;
                tmp[1] = j + 1;
                tmp[2] = n;
                deq.push_back(tmp);
            }else{
                std::vector< int > tmp(3);
                tmp[0] = i;
                tmp[1] = j + 1;
                tmp[2] = n + B_inc;
                deq_next.push_back(tmp);
            }
        }
        return -1;
    }
};

int main(){
    int H, W;
    std::cin >> H >> W;
    FFroute O(H, W);
    
    for(int i=0; i<H; i++){
        std::string tmp;
        std::cin >> tmp;
        for(int j=0; j<tmp.size(); j++){
            bool BW = tmp[j] == '.' ? true : false;
            O.BW_in(i, j, BW);
        }
    }
    
    int ans = O.walk();
    
    std::cout << ans << std::endl;
    
    
    return 0;
}



Measured memory_bytes: 384
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
const int maxn=1e7+5;
ll d[maxn];
void cal()
{
	for(int i=1;i<=maxn;i++)
		for(int j=i;j<maxn;j+=i)
			++d[j];
	d[1]=1;
}
int main()
{
	ios::sync_with_stdio(0);cin.tie(0);
	ll res=0,n;
	cin >> n;
	cal();
	for(int i=1;i<=n;i++)
		res+=(i*d[i]);
	cout << res;
}

Measured memory_bytes: 81708
//int a = stoi(c); 文字列をintへ
//小文字から大文字
//transform(a.begin(), a.end(), a.begin(), ::toupper);
//途中の出力をそのまま残さない
//数値計算 個数以外はdouble
//map<キー,値> p は辞書。p[キー] = 値
//map 全探索
//auto begin = p.begin(), end = p.end();
//for (auto it = begin; it != end; it++) {}
//mapのキー：it->first mapのバリュー：it->second
//絶対値 abs()
//入力は空白で切れる
//大文字判定 isupper(文字) 小文字判定 islower(文字)
//do{}while(next_permutation(ALL(配列)))
//while(N)で回すとき、Nはコピーを作っておく
//小文字に対応する文字コード：S[i] - 'a'
//文字コード→小文字：(char)(数字+'a')
//グラフの距離:隣接行列で扱う
//等価なものに変換する思考
//bool型　初期値はTrue
//島渡りの問題：中間ノードに着目
//配列はvector<>を使う：意味わからないエラーがなくなる。
//背反な事象にちゃんとわける
//チェックリストはマップを使う
//数が大きい時の比較はstring型で行う
//全て0になったか調べたい->0になるたびにcntする
//またはかかつか
//例外処理は最初にする
#include <bits/stdc++.h>
#define rep(i,N) for(int i = 0; i < N;i++)
#define ALL(a) (a).begin(),(a).end()
#define ll long long int
using namespace std;

// K進数でのNの桁数
ll dig(ll N, ll K) {
	ll dig = 0;
	while (N) {
		dig++;
		N /= K;
	}
	return dig;
}
// a,bの最大公約数
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a%b);
}

ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}

//nC2の計算
ll C(ll N) {
	return N * (N - 1) / 2;
}

//円周率
const double PI = 3.14159265358979323846;
//割るやつ
const ll MOD = (pow(10, 9) + 7);

int main() {
	ll N; cin >> N;
	string S; cin >> S;

	ll r=0, g=0, b=0;
	queue<ll> rx, gx, bx;
	rep(i, N) {
		if (S[i] == 'R') {
			r++;
		}
		if (S[i] == 'G') {
			g++;
		}
		if (S[i] == 'B') {
			b++;
		}
	}

	ll ans = r * g * b;

	ll C = (N - 3) / 2;
	for (int d = 0; d <= C; d++) {
		for (int s = 0; s <= N - 3 - 2 * d; s++) {
			if (S[s] != S[s + d + 1] && S[s + d + 1] != S[s + 2 * d + 2] && S[s] != S[s + 2 * d + 2]) {
				ans--;
			}
			else continue;
		}
	}

	cout << ans << endl;
}

Measured memory_bytes: 3628
#include <iostream>
using namespace std;
int main(void){
    int s1,s2,s3,s4;
    int t1,t2,t3,t4;
    cin >> s1 >> s2 >> s3 >> s4;
    cin >> t1 >> t2 >> t3 >> t4;
    
    int S,T;
    S = s1+s2+s3+s4;
    T = t1+t2+t3+t4;
    
    if(S>=T){
        cout << S << endl;
    }
    
    else{
        cout << T << endl;
    }
}


Measured memory_bytes: 3048
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = int(A); I < int(B); ++I)
#define FORR(I,A,B) for(ll I = int((B)-1); I >= int(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(a%b==0)return b;return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}//saisyo kobaisu
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=1e18+7;
const ll MOD=1e9+7;

int main(){
	ll n;
	cin >> n;
	ll a = n/100;
	ll b = n%100;
	if(a>0&&a<=12 && b>0&&b<=12){
		cout << "AMBIGUOUS" << endl;
	}else if(a>0&&a<=12 && b>=0&&b<=99){
		cout << "MMYY" << endl;
	}else if(a>=0&&a<=99 && b>0&&b<=12){
		cout << "YYMM" << endl;
	}else{
		cout << "NA" << endl;
	}
}

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

#define bigmod 1000000007
#define lli long long int

lli h, w, k, memo[10][110], kombinasi[10];

lli combine(lli x) {
	if (x < 3)
		return (x + 1);
	if (kombinasi[x] != -1)
		return kombinasi[x];
	kombinasi[x] = combine(x - 1) + combine(x - 2);
	return kombinasi[x];
}

lli dp(lli pos, lli tinggi) {
	lli ret, banyak = 1;
	if (tinggi == 0) {
		if (pos == k)
			return 1;
		return 0;
	}
	if (memo[pos][tinggi] != -1)
		return memo[pos][tinggi];
	if (pos > 2)
		banyak *= combine(pos - 2);
	if (pos < w - 1)
		banyak *= combine(w - pos - 1);
	ret = dp(pos, tinggi - 1) * banyak;
	ret %= bigmod;
	if (pos > 1) {
		banyak = 1;
		if (pos > 3)
			banyak *= combine(pos - 3);
		if (w > pos + 1)
			banyak *= combine(w - pos - 1);
		ret += (dp(pos - 1, tinggi - 1) * banyak);
		ret %= bigmod;
	}
	if (pos < w) {
		banyak = 1;
		if (pos > 2)
			banyak *= combine(pos - 2);
		if (w > pos + 2)
			banyak *= combine(w - pos - 2);
		ret += (dp(pos + 1, tinggi - 1) * banyak);
		ret %= bigmod;
	}
	memo[pos][tinggi] = ret;
	return ret;
}

int main() {
	lli ans;
	scanf("%lld %lld %lld", &h, &w, &k);
	memset(memo, -1, sizeof memo);
	memset(kombinasi, -1, sizeof kombinasi);
	ans = dp(1, h);
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 256
using System;
class Program
 {
        static void Main(string[] args)
        {
    　　int a,b,c;
            a = int.Parse(Console.ReadLine()); //標準入力
            //string[] str = Console.ReadLine().Split(' ');//2つ以上のスペース区切り入力の取得
            //b = int.Parse(str[0]);  //数値で受け取りたい場合は変換する
            //c = int.Parse(str[1]);
　　　　　　　//Console.Write("改行なし a = {0} b = {1} c = {2}", a, b, c)//改行なし出力
            //Console.WriteLine("改行あり a = {0} b = {1} c = {2}", a, b, c);//改行付き出力
          int count = 0;
          for(int i = 0; i<=a; i++){
             count += i;
         }
          Console.Write(count);
        }
 }

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

int main(){

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

    int l,r,d,c=0;
    cin>>l>>r>>d;
    for(int i=l;i<=r;i++)c+=i%d==0;
    cout<<c<<endl;

    return 0;
}

Measured memory_bytes: 3636
package main

import "fmt"

func main() {
	var st string
	fmt.Scan(&st)
	flag := false
	if len(st)%2 == 1 {
		fmt.Println("No")
		return
	}
	for i, s := range st {
		if (i%2 == 0 && string(s) == "h") || (i%2 == 1 && string(s) == "i") {
			flag = true
		} else {
			fmt.Println("No")
			return
		}
	}
	if flag {
		fmt.Println("Yes")
	}
}


Measured memory_bytes: 512
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.function.IntPredicate;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author AnandOza
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        DDivGame solver = new DDivGame();
        solver.solve(1, in, out);
        out.close();
    }

    static class DDivGame {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            long n = in.nextLong();

            long answer = 0;
            for (long p = 2; p * p <= n; p++) {
                int c = 0;
                while (n % p == 0) {
                    c++;
                    n /= p;
                }
                if (c == 0)
                    continue;
                int finalC = c;
                answer += -1 + BinarySearch.binarySearch(x -> x * (x + 1) / 2 > finalC);
            }

            if (n > 1) {
                answer++;
            }

            out.println(answer);
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

    }

    static class BinarySearch {
        public static int binarySearch(IntPredicate bigEnough) {
            int tooSmall = 0, tooBig;
            if (bigEnough.test(tooSmall)) {
                return tooSmall;
            }

            for (tooBig = 1; !bigEnough.test(tooBig); tooBig *= 2)
                ;

            if (!bigEnough.test(tooBig - 1)) {
                return tooBig;
            }

            while (tooBig - tooSmall > 1) {
                int center = tooSmall + (tooBig - tooSmall) / 2;
                if (!bigEnough.test(center)) {
                    tooSmall = center;
                } else {
                    tooBig = center;
                }
            }

            return tooBig;
        }

    }
}



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

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


#define rep(i,n) for(ll (i)=0; (i)<(ll)(n); (i)++)
#define frep(i,m,n) for(ll (i)=(m); (i)<=(ll)(n); (i)++)
#define rrep(i,n) for(ll (i)=(n)-1; (i)>-1; (i)--)
#define frrep(i,m,n) for(ll (i)=(n); (i)>(ll)(m); (i)--)
#define ALL(x) (x).begin(), (x).end()

const ll INF = 100100100100100100;
const ll MOD = 1000000007;

// get abs
ll my_abs(ll a);
// a^n
ll a_n(ll a, ll n);
// get gcd
ll my_gcd(ll a, ll b);
// a^(-1) % MOD 
ll inv(ll a);

int main() {
    ll n, m;
    cin >> n >> m;
    vector<P> d;
    rep(i, n) {
        ll a, b;
        cin >> a >> b;
        d.push_back(make_pair(a, b));
    }
    sort(ALL(d));
    ll ans = 0, num = 0;
    rep(i, n) {
        if(num + d[i].second >= m) {
            ans += (m-num)*d[i].first;
            break;
        }
        else {
            ans += d[i].first*d[i].second;
            num += d[i].second;
        }
    }
    cout << ans << endl;
    return 0;
}

ll my_abs(ll a) {
    if(a >= 0) return a;
    else return -1 *a;
}

ll a_n(ll a, ll n) { 
    if(n == 0) return 1;
    
    ll ret = a, count = 1;
    while(count * 2 < n) {
        ret *= ret;
        count *= 2;
    }
    if(count == n) return ret;
    else return (ret * a_n(a, n-count));
}

ll my_gcd(ll a, ll b) {
    if(b == 0) return a;
    return my_gcd(b, a%b);
}

ll inv(ll a) {
    return a_n(a, MOD-2);
}



Measured memory_bytes: 2420
d[150][120];j,s,t,m,n,*p;main(i){for(;scanf("%d%d",&n,&m)*n;printf("%d\n",s)){for(memset(d,9,7e4);t=m--;d[i][j]=d[j][i]=s)scanf("%d%d%d",&i,&j,&s);for(s=i=0;++i-n;s+=d[n][t=m])for(d[j=m=n][t]=0;j--;*p&&d[n][m]>*p?m=j:0)p=d[n]+j,*p=fmin(*p,d[t][j]);}}

Measured memory_bytes: 0
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;


class Program
{
    internal static void Main(string[] args)
    {
        int[] inp = ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
        int A = inp[0];
        int B = inp[1];
        int ans = 0;

        for (int i = A; i <= B; i++) {
            var ch = i.ToString().ToCharArray();
            if (ch[0] == ch[4] && ch[1] == ch[3]) {
                ans++;
            }
        }
        WriteLine(ans);
    }
}


Measured memory_bytes: 15568
#include <iostream>
using namespace std;
#define RINGO '@'
#define KAKI '#'
#define MIKAN '*'
#define DONE '.'
int w,h;
char area[1000][1000];

int di[]={1,-1,0,0}, dj[]={0,0,1,-1};
void rec(int i, int j, char c){
  if( i<0 || j<0 )
    return;
  if( i>=h || j>=w )
    return;
  if( area[i][j] != c )
    return;

  area[i][j] = DONE;

  for( int d=0;d<4;d++ )
    rec(i+di[d], j+dj[d], c);
}

int main(){
  while( cin >> h >> w, w ){
    for( int i=0;i<h;i++ )
      for( int j=0;j<w;j++ )
	cin >> area[i][j];

    int ans=0;
    for( int i=0;i<h;i++ ){
      for( int j=0;j<w;j++ ){
	if( area[i][j]== DONE )
	  continue;
	ans++;
	rec(i, j, area[i][j]);
      }
    }
    cout << ans << endl;
  }

  return 0;
}

Measured memory_bytes: 1728
fn :: Bool -> (String, String) -> Bool
fn f pair =
    f && last (fst pair) == head (snd pair)

main :: IO ()
main = do
    abc <- words <$> getLine
    let pairs = zip (init abc) (tail abc)
    if foldl fn True pairs then
        putStrLn "YES"
    else
        putStrLn "NO"

Measured memory_bytes: 380
package main

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

func scanAll() []int {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	t := []int{}
	for sc.Scan() {
		i, _ := strconv.Atoi(sc.Text())
		t = append(t, i)
	}
	return t
}
func diffs(t []int) []int {
	d := []int{}
	for key, value := range t {
		if key == 0 {
			continue
		}
		diff := value - t[key-1]
		d = append(d, diff)
	}
	return d
}
func main() {
	var n, m int
	fmt.Scan(&n, &m)
	// _cut := n - 1
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	t := scanAll()
	sort.Ints(t)

	d := diffs(t)
	sort.Ints(d)
	p := len(d) - n + 1
	if p < 0 {
		p = 0
	}
	ctd := d[:p]

	sum := 0
	for _, x := range ctd {
		sum += x
	}
	fmt.Println(sum)
	// cutNum := []
}


Measured memory_bytes: 7680
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define INF             1e14
#define dd              double
#define MOD             1000000007
#define my_sizeof(type) ((char *)(&type+1)-(char*)(&type)) 
#define nl              cout<<endl
#define fill(a,val)     memset(a,val,sizeof(a))
#define mp              make_pair
#define endl            "\n"
#define pb              push_back
#define ff              first    
#define ss              second
#define SIZE            200005
#define all(v)          v.begin(),v.end()
#define s(ar,n)         sort(ar,ar+n)
#define rs(ar,n)        sort(ar, ar+n, greater<ll>()) 
#define oa(a,n)         for(ll i=0;i<n;i++)cout<<a[i]<<" ";nl
#define cn(a,n)         for(ll i=0;i<n;i++)cin>>a[i];
#define maxa(ar,N)      *max_element(ar,ar+N)
#define mina(ar,N)      *min_element(ar,ar+N)
#define fastio()        ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define printclock      cerr<<"Time : "<<1000*(long double)clock()/(long double)CLOCKS_PER_SEC<<"ms\n";
ll power(ll x, ll y){
    ll res=1;x=x;
    while(y>0){
        if(y&1)
            res = (res*x);
        y = y>>1;
        x = (x*x);
    }
    return res;
}  
ll logtwo(ll n){
    if(n==1)
        return 0;
    return logtwo(n/2)+1;
}
signed main()
{
    fastio();   
    int t=1;
    //cin>>t;
    while(t--)
    {
        ll r;
        cin>>r;
        cout<<fixed<<setprecision(5)<<2*3.1415*r<<endl;
    }
}

Measured memory_bytes: 3740
#include <stdio.h>
int main (){
int a ,b,c,d;
scanf ("%d%d%d%d",&a,&b,&c,&d);

if (a+ b > c +d )
    printf("Left\n");

else
   if (a+ b < c +d )
    printf("Right\n");

else if (a+ b == c +d )
    printf("Balanced\n");

return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
    #include <cstdio>
    #include <cstring>
    #include <cmath>
    #include <cstring>
    #include <chrono>
    #include <complex>
    #define endl "\n"
    #define int long long int
    #define vi vector<int>
    #define vll vector<ll>
    #define vvi vector < vi >
    #define pii pair<int,int>
    #define pll pair<long long, long long>
    #define mod 1000000007
    #define inf 1000000000000000001;
    #define all(c) c.begin(),c.end()
    #define mp(x,y) make_pair(x,y)
    #define mem(a,val) memset(a,val,sizeof(a))
    #define eb emplace_back
    #define f first
    #define s second

    using namespace std;
int power(int base, int exp)
{
    if (exp == 0)
       return 1;
    else if (exp == 1)
       return base;
    else
    {
       int calc;
       if (exp % 2 == 0)
       {
         calc = power(base, exp/2);
         calc =(calc* calc)%mod;
       }
       else
       {
         calc = (base*power(base, exp-1))%mod;
       }
       return calc%mod;
    }
}
    int32_t main()
    {
        std::ios::sync_with_stdio(false);
        int n;
        cin>>n;
        int a[n];
        int ans=1;
        for(int i=0;i<n;i++)
        {
            cin>>a[i];
            if(a[i]==0)
            {
                cout<<0<<endl;
                return 0;
            }
        }
        for(int i=0;i<n;i++)
        {
            if(a[i]<=1000000000000000000/ans)
            {
                ans*=a[i];
            }
            else
            {
                cout<<-1<<endl;
                return 0;
            }
        }
        cout<<ans<<endl;

        return 0;
    }


Measured memory_bytes: 4400
package main

import "fmt"

const mod = 1000000007

func pow(x, y int) int {
	if y == 0 {
		return 1
	} else if y%2 == 0 {
		x2 := pow(x, y/2)
		return x2 * x2 % mod
	} else {
		return x * pow(x, y-1) % mod
	}
}

func cmb(x, y int) int {
	if y > x {
		return 0
	}

	nu, de := 1, 1
	for i := 0; i < y; i++ {
		nu = nu * (x - i) % mod
		de = de * (i + 1) % mod
	}
	return nu * pow(de, mod-2) % mod
}

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

	ans := 0
	if n >= 2 {
		ans += cmb(n, 2)
	}
	if m >= 2 {
		ans += cmb(m, 2)
	}
	fmt.Println(ans)
}


Measured memory_bytes: 512
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <iomanip>
#include <queue>
#include <deque>
#include <map>
#include <unordered_map>
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define repr(e,x) for(auto& e:x)
using namespace std;
typedef long long ll;
typedef long double ld;
//typedef pair<int,int> P;
int const INF=1001001001;
ll const LINF=1001001001001001001;
ll const MOD=1000000007;

ll a,b,c,d;

int main(){
    cin>>a>>b>>c>>d;

    ll ans=max(max(a*c,a*d),max(b*c,b*d));

    cout<<ans<<endl;
}

Measured memory_bytes: 3628
#include <iostream>
#include <string>

using namespace std;

struct dice {
    int sai[6];
    void direc(char c) {
        int b;
        if (c == 'N')
        {
            b = sai[0];
            sai[0] = sai[1];
            sai[1] = sai[5];
            sai[5] = sai[4];
            sai[4] = b;
        }
        if (c == 'E')
        {
            b = sai[0];            //
            sai[0] = sai[3];
            sai[3] = sai[5];
            sai[5] = sai[2];
            sai[2] = b;
        }
        if (c == 'W')
        {
            b = sai[0];
            sai[0] = sai[2];
            sai[2] = sai[5];
            sai[5] = sai[3];
            sai[3] = b;
        }
        if (c == 'S')
        {
            b = sai[0];
            sai[0] = sai[4];
            sai[4] = sai[5];
            sai[5] = sai[1];
            sai[1] = b;
        }
        if (c == 'R') {
            b = sai[1];
            sai[1] = sai[2];
            sai[2] = sai[4];
            sai[4] = sai[3];
            sai[3] = b;
        }
    }
    int top() {
        return sai[0];
    }
    int right() {
        return sai[2];
    }
    int left() {
        return sai[3];
    }
    int front() {
        return sai[1];
    }
};
bool same(dice a, dice b) {
    int i;

    for(i = 0; i < 6; i++)
        if (a.sai[i] != b.sai[i]) return false;
    return true;
}

int main() {
    int i;
    int j;
    int n;
    int k;
    int l;
    dice ind[100];
    cin >> n;
    for (j = 0; j < n; j++)
        for (i = 0; i < 6; i++)
            cin >> ind[j].sai[i];

    bool ff = true;
    for (k = 0; k < n - 1; k++) {
        for (l = k + 1; l < n; l++) {
            bool f = false;
            for (i = 0; i < 4; i++) {
                ind[l].direc('R');
                for (j = 0; j < 4; j++) {
                    ind[l].direc('N');
                    if (same(ind[k], ind[l])) f = true;
                }
            }
            ind[l].direc('E');

            for (j = 0; j < 4; j++) {
                ind[l].direc('N');
                if (same(ind[k], ind[l])) f = true;
            }

            ind[l].direc('W');
            ind[l].direc('W');
            for (j = 0; j < 4; j++) {
                ind[l].direc('N');
                if (same(ind[k], ind[l]))f = true;
            }
            if (f) ff = false;
        }
    }
    cout << (ff ? "Yes" : "No") << endl;
    return 0;

}


Measured memory_bytes: 3104
#include <bits/stdc++.h>
using namespace std;
#define GET_MACRO(_1, _2, _3, NAME, ...) NAME
#define _repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define _rep(i,n) _repl(i,0,n)
#define rep(...) GET_MACRO(__VA_ARGS__, _repl, _rep)(__VA_ARGS__)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#define fi first
#define se second
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
void _dbg(string){cout<<endl;}
template<class H,class... T> void _dbg(string s,H h,T... t){int l=s.find(',');cout<<s.substr(0,l)<<" = "<<h<<", ";_dbg(s.substr(l+1),t...);}
template<class T,class U> ostream& operator<<(ostream &o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream &o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

#define INF 1120000000

int cnt[200005][26];

int main(){
  string s;
  cin>>s;
  int n = s.size();

  rep(i,26) cnt[n][i] = 0;
  for(int i=n-1; i>=0; i--){
    rep(j,26) cnt[i][j] = cnt[i+1][j];
    cnt[i][s[i]-'a']++;
  }

  long ans = 0;
  rep(i,n){
    ans += (n-i) - cnt[i][s[i]-'a'];
  }

  cout << ans+1 << endl;

  return 0;
}


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

int main() {
    int n;
    cin >> n;
    map<ll, int> mp;
    bool flag = true;
    rep(i,n) {
        int a;
        cin >> a;
        mp[a]++;
        if (mp[a] > 1) flag = false;
    }
    if (flag) puts("YES");
    else puts("NO");
    return 0;
}

Measured memory_bytes: 12800
#include <bits/stdc++.h>
using namespace std;
const int MX = 1e5+3, MOD = 1e9+7;
int a[MX];
vector<int> pos[MX];
long long ans = 1;
int main() {
	ios::sync_with_stdio(0);cin.tie(0);
	int n, mxp = 0;
	cin >> n;
	for(int i=0; i<n; i++) {
		cin >> a[i];
		pos[a[i]].push_back(i);
		mxp = max(mxp, a[i]);
		if(pos[a[i]].size() > 3)
			return !(cout << 0);
	}
	for(int i=0; i<=mxp; i++) {
		if(pos[i].empty() || (i && pos[i-1].size() < pos[i].size()))
			return !(cout << 0);
	}
	ans = (pos[0].size() >= 2 ? 6 : 3);
	for(int i=1; i<=mxp; i++) {
		int p = 0;
		for(int t: pos[i]) {
			int cnt = 0;
			for(int s: pos[i-1]) {
				cnt += s < t;
			}
			if(cnt <= p)
				return !(cout << 0);
			ans *= (cnt - p);
			p++;
		}
		ans %= MOD;
	}
	cout << ans;
}

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

int main()
{
	int a, b;
	int sum, count;
	double avg;
	sum = 0; count = 0; avg = 0.0;
	while (scanf("%d,%d",&a, &b) != EOF) {
		sum += a*b;
		avg += (double)b;
		count++;
	}
	avg /= (double)count;
	cout<<sum<<endl;
	cout<<(int)(avg+0.5)<<endl;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
#define ll long long int
#define pb push_back
#define mp make_pair
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
using namespace std;
//Some custom functions for quick use(fast_power,nCr,lcm,gcd)
ll power(ll a, ll b)
{
  if(b == 0)
   {
      return 1;
   }
   else if(b % 2 == 0)
   {
      return power(a*a, b/2);
   }
   else
   {
      return a * power(a*a, b/2);
   }
}
long long int nChoosek( long long int n, long long int k )
{
if (k > n) return 0;
if (k * 2 > n) k = n-k;
if (k == 0) return 1;
    int result = n;
for( int i = 2; i <= k; ++i )
{
        result *= (n-i+1);
        result /= i;
}
    return result;
}

long long int lcm(long long int a,long long int b)
{
    long long int m,n;
    m=a;
    n=b;
    while(m!=n)
    {
        if(m < n)
        {
            m=m+a;
        }
        else
        {
            n=n+b;
        }
    }
    return m;
}

long long int gcd(long long int a,long long int b)
{ 
if (a == 0) 
return b; 
return gcd(b % a, a);
}
/* Basic DFS Boilerplate */ 
vector<ll> adj[10005]; // graph is stored as adjacency list
bool visited[10005];
void dfs(ll s)  //given node s
{
    if(visited[s])
        return;
    visited[s]=true;
    //the process on node 's'
    for(auto u : adj[s])
    {
        dfs(u);
    }    
}
/* Basic BFS Boilerplate */
ll x;   // given node
queue<ll>q;
bool vis[10005];
ll dist[10005];
//
void bfs(ll x)
{
    vis[x]=true;
    dist[x]=0LL;
    q.push(x);
    while (!q.empty())
    {
        ll s=q.front();
        q.pop();
        //the process
        //on node x
        for(auto u :adj[x])
        {
            if(vis[u]==true)
                continue;
            vis[u]=true;
            dist[u]=dist[x]+1;
            q.push(u);
        }
    }
    
}
int main()
{
    fastio
    ll a[5];
    for (ll i = 0; i < 5; i++)
    {
        /* code */
        cin>>a[i];
    }
    for (ll i = 0; i < 5; i++)
    {
        /* code */
        if(a[i]==0)
        {
            cout<<i+1<<'\n';
            return 0;
        }
    }
    
    
    return 0;
}


Measured memory_bytes: 3900
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
#include <queue>

#define pb push_back
     
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
     
bool debug = false;
     

struct state
{
    ll a,b,c;

    state(ll a, ll b, ll c) : a(a), b(b), c(c)
    {

    }

  bool operator==(const state &other) const
  { return (a == other.a
            && b == other.b
            && c == other.c);
  }
};


struct KeyHasher
{
    size_t operator()(const state& k) const
  {
    //using std::size_t;
    //using std::hash;
    //using std::string;

    return ((hash<ll>()(k.a)
               ^ (hash<ll>()(k.b) << 1)) >> 1)
               ^ (hash<ll>()(k.c) << 1);
  }
};  


void solve(ll casen)
{
    ll res = 0;
    
    cout << "Case #" << casen << ": " << res << endl;
}

int main()
{
    // $ g++ -std=c++14 -Wshadow -Wall -o c C.cpp

    // !!! Here, unordered map was too slow!!!
    std::ios::sync_with_stdio(false);
    cin.tie(NULL);
    
    ll h1, m1, h2, m2, k;
    cin >> h1 >> m1 >> h2 >> m2 >> k;

    ll start = h1*60 + m1;
    ll end = h2*60 + m2;

    ll res = end - start - k;

    cout << res << endl;


    return 0;
}

Measured memory_bytes: 3656
N,M=map(int,input().split())
s=list(map(int,input().split()))
w=0
if s[0]+s[1]>M and s[0]>M:
    w+=s[1]+s[0]-M
    s[1]=0
    s[0]=M
for i in range(0,N-1):
    if s[i]+s[i+1]>M:
        w+=s[i]+s[i+1]-M
        s[i+1]=M-s[i]
print(w)        

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

typedef long long lli;
typedef vector<int> Vi;
typedef vector<lli> Vl;
typedef pair<int, int> Pii;
typedef pair<lli, lli> Pll;


//===




int main()
{
	int H, W;
	cin >> H >> W;

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

	queue<Pii> q;
	vector<Vi> dist(H, Vi(W, -1));

	for (int i = 0; i < H; ++i) {
		for (int j = 0; j < W; ++j) {
			if (A[i][j] == '#') {
				q.push(make_pair(i, j));
				dist[i][j] = 0;
			}
		}
	}

	// 移動方向の候補
	vector<Pii> moves = {
		{0, 1},
		{0, -1},
		{1, 0},
		{-1, 0}
	};

	// 幅優先探索
	while (!q.empty()) {
		auto front = q.front();
		q.pop();
		int x = front.first, y = front.second;
		for (const auto& move : moves) {
			int nx = x + move.first, ny = y + move.second;
			if (nx < 0 || nx >= H || ny < 0 || ny >= W) continue;  // 範囲外
			if (dist[nx][ny] >= 0) continue;  // 探索済み
			dist[nx][ny] = dist[x][y] + 1;  // 幅優先探索であるからminはいらない
			q.push(make_pair(nx, ny));
		}
	}

	int ans = 0;
	for (int i = 0; i < H; ++i) {
		for (int j = 0; j < W; ++j) {
			ans = max(ans, dist[i][j]);
		}
	}

	cout << ans << endl;
}


Measured memory_bytes: 13456