akhauriyash/Code-Regression huggingface dataset:
fun main(args: Array<String>) {
    val n = readInputLine().toInt()
    val aList = readInputLine().split(" ").map { it.toInt() }.toMutableList()
    
    aList.sort()

    var ans = 0
    var currentNum = 0
    var count = 0
    
    for (a in aList) {
        if (a == currentNum) {
            count++
        } else {
            ans = addAns(currentNum, count, ans)
            currentNum = a
            count = 1
        }
    }
    
    ans = addAns(currentNum, count, ans)
    
    println(ans)
}

fun readInputLine(): String {
    return readLine()!!
}

fun addAns(num: Int, count: Int, ans: Int): Int {
    if (count < num) {
        return ans + count
    } else {
        return ans + count - num
    }
}


Measured memory_bytes: 59884
#include "bits/stdc++.h"
using namespace std;
static const int MAX = 100000;

bool compare(pair<int, int> a, pair< int, int> b) {
    return a.second < b.second;
}

int main() {
    int n;
    pair<int, int> A[MAX];

    cin >> n;
    for (int i = 0; i < n; ++i) {
        int a; cin >> a;
        A[i] = make_pair(i + 1, a);
    }

    sort(A, A + n, compare);
    for (int i = 0; i < n; ++i) {
        if (i) cout << " ";
        cout << A[i].first;
    }

    return 0;
}


Measured memory_bytes: 1536
#include<vector>
#include<iostream>
#include<string>
#include<algorithm>
#include<math.h>
#include<map>
#include<functional>
#include<queue>
#include<stack>
#include<string.h>
#define ll long long int
#define MOD 1000000007LL
using namespace std;
int main() {
    int n;
    cin>>n;
    int a=0;
    int b=(n-1)/2;
    int c=n-1;
    int d[100001]={};
    string s;
    cout<<a<<endl;
    cin>>s;
    if(s=="Male"){
        d[a]=1;
    }else if(s=="Female"){
        d[a]=2;
    }else{
        return 0;
    }
    cout<<b<<endl;
    cin>>s;
    if(s=="Male"){
        d[b]=1;
    }else if(s=="Female"){
        d[b]=2;
    }else{
        return 0;
    }
    while(1){
        if((((b-a)%2==0)&&(d[a]==d[b]))||(((b-a)%2==1)&&(d[a]!=d[b]))){
             a=b;
            b=(b+c)/2;
        }else{

            c=b;
            b=(a+b)/2;
        }
        if(c-a==1){
            cout<<a<<endl;
            cin>>s;
            if(s!="Vacant"){
                cout<<c<<endl;
                cin>>s;
                if(s=="Vacant"){
                    return 0;
                }
            }else{
                return 0;
            }  
        }
        cout<<b<<endl;
        cin>>s;
        if(s=="Male"){
            d[b]=1;
        }else if(s=="Female"){
            d[b]=2;
        }else{
            return 0;
        }
    }
}

Measured memory_bytes: 1236
import sys
input=sys.stdin.readline

class list2D:
    def __init__(self, H, W, num):
        self.__H = H
        self.__W = W
        self.__dat = [num] * (H * W)

    def __getitem__(self, a):
        return self.__dat[a[0]*self.__W+a[1]]

    def __setitem__(self, a, b):
        self.__dat[a[0]*self.__W+a[1]] = b

    def debug(self):
        print(self.__dat)

class list3D:
    def __init__(self, H, W, D, num):
        self.__H = H
        self.__W = W
        self.__D = D
        self.__X = W * D
        self.__dat = [num] * (H * W * D)

    def __getitem__(self, a):
        return self.__dat[a[0]*self.__X+a[1]*self.__D + a[2]]

    def __setitem__(self, a, b):
        self.__dat[a[0]*self.__X+a[1]*self.__D + a[2]] = b

    def debug(self):
        print(self.__dat)

def main():
    r,c,k=map(int,input().split())
    v = list2D(r, c, 0)

    for _ in range(k):
        ri,ci,a=map(int,input().split())
        v[ri-1, ci-1] = a

    dp = list3D(r, c, 4, 0)
    #print(dp)
    if v[0, 0]>0: dp[0, 0, 1] = v[0, 0]

    for i in range(r):
        for j in range(c):
            val = v[i, j]
            if i>0:
                x = max(dp[i-1, j, 0], dp[i-1, j, 1], dp[i-1, j, 2], dp[i-1, j, 3])
                dp[i, j, 1]=x+val
                dp[i, j, 0]=x

            if j>0:
                X = dp[i, j-1, 0]
                Y = dp[i, j-1, 1]
                V = dp[i, j-1, 2]
                Z = dp[i, j-1, 3]
                dp[i, j, 0]=max(dp[i, j, 0],X)
                dp[i, j, 1]=max(dp[i, j, 1],X+val,Y)
                dp[i, j, 2]=max(Y+val,V)
                dp[i, j, 3]=max(V+val,Z)

    #print(dp)
    ans=0
    for i in range(4): ans=max(dp[r-1, c-1, i],ans)
    return print(ans)
if __name__=="__main__":
    main()


Measured memory_bytes: 428792
using System;
using System.Linq;
using System.Collections.Generic;

namespace Algorithm
{
    class Program
    {
        static void Main(string[] args)
        {
            // 写経
            var n = int.Parse(Console.ReadLine());
            var cEnu = Enumerable.Repeat(int.MaxValue, 26);

            for (var i = 0; i < n; i++)
            {
                var p = new int[26];
                foreach (var c in Console.ReadLine())
                {
                    p[c - 'a']++;
                }
                cEnu = cEnu.Zip(p, (x, y) => Math.Min(x, y));
            }

            var ans = "";
            var cArray = cEnu.ToArray();
            for (var i = 0; i < 26; i++)
                ans += new string(char.ConvertFromUtf32('a' + i)[0], cArray[i]);
            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 13268
n,m=gets.split.map(&:to_i)
to=Array.new(n+1){[]}
m.times do
  a,b=gets.split.map(&:to_i)
  to[a] << b
  to[b] << a
end
ans=[nil,1]
queue=[]
to[1].each do |i|
  queue << i
  ans[i]=1
end

while !queue.empty?
  s=queue.shift
  to[s].each do |t|
    unless ans[t]
      queue << t
      ans[t] = s
    end
  end
end

if ans[2..n+1].any? nil
  puts 'No'
else
  puts 'Yes'
  puts  ans[2..n+1]
end


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

int main() {
   int n,m;cin>>n>>m;
   int arr[m];
   for(int i=0;i<m;i++)
   {
       cin>>arr[i];
   }
   long long sum=0;
   for(int i=0;i<m;i++)
   {
       sum+=arr[i];
   }
   sum=n-sum;
   if(sum>=0)
   cout<<sum;
   else
   cout<<"-1";
   
	return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
 
int main() {

	char c;
	cin >> c;

	if ((c == 'a') ||(c == 'i') ||(c == 'u') ||(c == 'e') ||(c == 'o')) {
		cout << "vowel" << endl;
	}
	else {
		cout << "consonant" << endl;
	}
}

Measured memory_bytes: 256
# ABC_054_C_One_Stroke_Path.py

from itertools import permutations
N, M = list(map(int, input().split()))
L=[]
for _ in range(M):
    L.append(list(map(int, input().split())))
# print(L)

P = list(permutations(range(1,N+1)))
# print(P)
ct = 0
for i in P:
    if i[0]==1 and \
    all((sorted([i[j], i[j+1]]) in L) for j in range(N-1)):
        ct += 1
print(ct)

Measured memory_bytes: 74852
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define eps 1e-10
#define MAXN 205
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {
    res = 0;T f = 1;char c = getchar();
    while(c < '0' || c > '9') {
	if(c == '-') f = -1;
	c = getchar();
    }
    while(c >= '0' && c <= '9') {
	res = res * 10 +c - '0';
	c = getchar();
    }
    res *= f;
}
template<class T>
void out(T x) {
    if(x < 0) {x = -x;putchar('-');}
    if(x >= 10) {
	out(x / 10);
    }
    putchar('0' + x % 10);
}
int H,W,sum[MAXN][MAXN];
int f[2][MAXN][MAXN][MAXN],g[2][MAXN][MAXN][MAXN];
char s[MAXN][MAXN];
bool check(int xa,int ya,int xb,int yb) {
    if(yb > W || xb > H) return false;
    int all = (yb - ya + 1) * (xb - xa + 1);
    int t = sum[xb][yb] + sum[xa - 1][ya - 1] - sum[xb][ya - 1] - sum[xa - 1][yb];
    if(t == all || t == 0) return true;
    return false;
}
void Solve() {
    read(H);read(W);
    for(int i = 1 ; i <= H ; ++i) {
	scanf("%s",s[i] + 1);
	for(int j = 1 ; j <= W ; ++j) sum[i][j] = (s[i][j] == '#');
	for(int j = 1 ; j <= W ; ++j) sum[i][j] += sum[i][j - 1];
    }
    for(int i = 1 ; i <= H ; ++i) {
	for(int j = 1 ; j <= W ; ++j) sum[i][j] += sum[i - 1][j];
    }
    int cur = 0;
    for(int i = 1 ; i <= H ; ++i) {
	for(int j = i ; j <= H ; ++j) {
	    for(int c = 1 ; c <= W ; ++c) {
		int t = f[cur][i][j][c - 1];
		if(check(i,c,j,c)) t = max(t,c);
		if(t >= c) {
		    while(check(i,c,j,t + 1)) ++t;
		}
		else t = c - 1;
		f[cur][i][j][c] = t;
	    }
	}
    }
    for(int i = 1 ; i <= W ; ++i) {
	for(int j = i ; j <= W ; ++j) {
	    for(int r = 1 ; r <= H ; ++r) {
		int t = g[cur][i][j][r - 1];
		if(check(r,i,r,j)) t = max(t,r);
		if(t >= r) {
		    while(check(r,i,t + 1,j)) ++t;
		}
		else t = r - 1;
		g[cur][i][j][r] = t;
	    }
	}
    }
    for(int k = 0 ; k <= 20 ; ++k) {
	if(f[cur][1][H][1] >= W || g[cur][1][W][1] >= H) {
	    out(k);enter;return;
	}
	memset(f[cur ^ 1],0,sizeof(f[cur ^ 1]));
	memset(g[cur ^ 1],0,sizeof(g[cur ^ 1]));
	for(int i = 1 ; i <= H ; ++i) {
	    for(int j = i ; j <= H ; ++j) {
		for(int c = 1 ; c <= W ; ++c) {
		    int t = f[cur][i][j][c];
		    if(t >= W) {f[cur ^ 1][i][j][c] = W;continue;}
		    t = f[cur][i][j][t + 1];
		    while(1) {
			int k = g[cur][c][t + 1][i];
			k = g[cur][c][t + 1][k + 1];
			if(k >= j) ++t;
			else break;
		    }
		    f[cur ^ 1][i][j][c] = t;
		}
	    }
	}
	for(int i = 1 ; i <= W ; ++i) {
	    for(int j = i ; j <= W ; ++j) {
		for(int r = 1 ; r <= H ; ++r) {
		    int t = g[cur][i][j][r];
		    if(t >= H) {g[cur ^ 1][i][j][r] = H;continue;}
		    t = g[cur][i][j][t + 1];
		    while(1) {
			int k = f[cur][r][t + 1][i];
			k = f[cur][r][t + 1][k + 1];
			if(k >= j) ++t;
			else break;
		    }
		    g[cur ^ 1][i][j][r] = t;
		}
	    }
	}
	cur ^= 1;
    }
}
int main() {
#ifdef ivorysi
    freopen("f1.in","r",stdin);
#endif
    Solve();
    return 0;
}


Measured memory_bytes: 135040
#include<bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < (int)n; i++)
#define all(x) x.begin(), x.end()
#define MOD 1000000007//1e9+7
typedef long long ll;
using namespace std;
int main()
{
  int a,b;
  cin >> a>>b;
  int ans = 0;
  int tmp;
  for(int i = 1;i <= 9; i++){
    for(int j = 0;j <= 9; j++){
      for(int k = 0;k <= 9; k++){
	tmp = 10000*i + 1000*j + 100*k + 10*j + i;
	if(a <= tmp&&tmp <= b){
	  ans ++;
	}
      }
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
[r,c] = map(int, input().split())
mat = [list(map(int, input().split())) for i in range(r)]
for i in range(r):
    mat[i].append(sum(mat[i]))
r_sum = []
for j in range(c+1):
    r_sum.append(sum([mat[i][j] for i in range(r)]))
for i in range(r):
    print(" ".join(list(map(str, mat[i]))))
print(" ".join(list(map(str, r_sum))))

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

using namespace std;

/* g++ -g -fsanitize=address -lasan -std=c++11 -Dfoo_ */

/* freopen("input.txt", "rt", stdin); */
/* freopen("output.txt", "wt", stdout); */

#define ALL(c)          (c).begin(), (c).end()
#define ALLR(c)         (c).rbegin(), (c).rend()
#define FOR(i,a,b)      for (int i=(a); i < (b); ++i)
#define FORR(i,a,b)     for (int i=(a); i > (b); --i)
#define FOR_ALL(i,c)    for (__typeof((c).begin()) i=(c).begin();   \
                             i != (c).end(); ++i)
#define FOR_ALLR(i,c)   for (__typeof((c).rbegin()) i=(c).rbegin(); \
                             i != (c).rend(); ++i)
#define SZ(array)       (sizeof(array)/sizeof(array[0]))
#define lc(x)           (x<<1)     /* 2*x */
#define rc(x)           (x<<1 | 1) /* 2*x+1 */
#define lowbit(x)       (x & (-x)) /* 0b10100 -> 0b100 */

typedef long long       LL;
typedef map<int,int>    MII;
typedef pair<int,int>   PII;
typedef set<int>        SI;
typedef vector<bool>    VB;
typedef vector<double>  VD;
typedef vector<int>     VI;
typedef vector<string>  VS;

/* check if a key is in container C */
template <class C>
inline bool in_(const typename C::key_type& k, const C& A)
{ return A.find(k) != A.end(); }
inline bool in_(const string& s, const string& S)
{ return S.find(s) != string::npos; }

VI H;

int main()
{
    int n;
    while (cin >> n) {
        H.resize(n);
        FOR(i,0,n)
            cin >> H[i];
        int i = 0, ans = 0;
        while (i < n) {
            int j = i;
            while (j+1 < n && H[j+1] <= H[j])
                j++;
            ans = max(ans,j-i);
            i = j+1;
        }
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 640
#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 rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define yn {puts("Yes");}else {puts("No");}
#define printd(x) printf("%.12f\n", ans);
template<class T> bool chmin(T& a, const T& b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> bool chmax(T& a, const T& b) {if (a < b) {a = b; return 1;} return 0;}
using namespace std;
using ll = long long;
using P = pair<int, int>;

const int INF = 1e9 + 9;

int main(void) {
	int h, w;
	cin >> h >> w;
	vector<vector<int>> c(10, vector<int>(10));
	rep (i, 10) rep (j, 10) cin >> c[i][j];
	int a[h][w];
	rep (i, h) rep (j, w) cin >> a[i][j];

	vector<vector<P>> g(10);
	rep (i, 10) rep (j, 10) {
		g[i].eb(j, c[i][j]);
		g[j].eb(i, c[i][j]);
	}

	rep (k, 10) rep (i, 10) rep (j, 10) chmin(c[i][j], c[i][k] + c[k][j]);

	ll ans = 0;
	rep (i, h) rep (j, w) {
		if (a[i][j] == -1 || a[i][j] == 1) continue;
		ans += c[a[i][j]][1];
	}
	
	cout << ans << endl;
	return 0;
}

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

const int MOD = (int)1e9+7;

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

  vector<int> prime(101,0);
  for(int i=1;i<=N;i++){
    int j=i;
    int x=2;
    while(j>1){
      if(j%x==0){
        prime.at(x)++;
        j/=x;
      }
      else  x++;
    }
  }
  vector<int> divi(5,0);
  vector<int> check={3,5,15,25,75};
  for(int i=0;i<prime.size();i++){
    //cout << i << ":" << prime.at(i) << endl;
    for(int j=0;j<5;j++){
      if(prime.at(i)+1>=check.at(j))  divi.at(j)++;
    }
  }
  //for(int i=0;i<5;i++)  cout << i << ":" << divi.at(i) << endl;
  int ans=0;
  ans+=divi.at(4);
  ans+=divi.at(3)*max(0,(divi.at(0)-1));
  ans+=divi.at(2)*max(0,(divi.at(1)-1));
  ans+=divi.at(1)*max(0,(divi.at(1)-1))/2*max(0,(divi.at(0)-2));
  cout << ans << endl;

  return 0;
}


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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
//const ull mod = 1e9 + 7;
const ll mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

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

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

// conversion number to bit
string num2bit(ll num, ll len){
  string bit = "";
  REP(i, len){
    bit += char('0'+(num>>i & 1));
  }
  return bit;
}

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

    ll N, Q;
    string S;
    cin >> N >> S >> Q;
   	set<ll> st[26];
   	REP(i, N){
   		st[S[i]-'a'].insert(i);
   	}
    while(Q--){
    	ll t;
    	cin >> t;
    	if(t==1){
    		ll idx;
    		char c;
    		cin >> idx >> c;
    		idx--;
    		char moto = S[idx];
    		S[idx] = c;

    		st[moto-'a'].erase(idx);
    		st[c-'a'].insert(idx);
    	}else{
    		ll l, r;
    		cin >> l >> r;
    		l--, r--;
  			ll res = 0;
    		REP(i, 26){
    			auto itr1 = st[i].lower_bound(l);
    			auto itr2 = st[i].lower_bound(r+1);
    			if(itr1 != itr2) res++;
    		}
    		cout << res << endl;
    	}
    }
    return 0;
}

Measured memory_bytes: 24220
#include <stdio.h>
int main()
{
	int i = 0;
	char str[1200] = "";
	while(1)
	{
		scanf("%c", &str[i]);
		if(str[i] == '\n')
			break;
		if(str[i] >= 'a' && str[i] <= 'z')
			printf("%c", str[i] - 32);
		else
			if(str[i] >= 'A' && str[i] <= 'Z')
				printf("%c", str[i] + 32);
			else
				printf("%c", str[i]);
		i ++;
	}
	printf("\n");
	return 0;
}


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

int n;

std::vector<int> a,b;

int main(){

    int tmp;

    std::cin>>n;

    for(int i=0;i<n;i++){
        std::cin>>tmp;
        a.push_back(tmp);
    }

    b=a;

    std::sort(b.begin(), b.end(), std::greater<int>());

    for(auto&& x:a){
        if(x==b[0])
        std::cout<<b[1]<<std::endl;
        else
        std::cout<<b[0]<<std::endl;
        
    }

    return 0;
}

Measured memory_bytes: 3316
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <numeric>
#include <string>
#include <sstream>
#include <cmath>
#include <cstring>
#include <assert.h>
#include <utility>
#include <tuple>
#include <array>
#include <bitset>
#include <cstdlib>

using int64 = long long;

using namespace std;

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

    int N;
    cin >> N;

    int64 ans = 0;
    map<int64, int64> counter;
    for (int i = 0; i < N; i++) {
        int64 A;
        cin >> A;

        ans += counter[i - A];
        counter[i + A]++;
    }

    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 25904
//#include <bits/stdc++.h>
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <climits>
#include <iomanip>
#include <stack>
#include <bitset>

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define ROF(i, j, k) for(int i = (int)(j); i >= (int)(k); --i)
#define FORLL(i, n, m) for(long long i = n; i < (long long)(m); i++)
#define SORT(v, n) sort(v, v+n)
#define REVERSE(v) reverse((v).begin(), (v).end())

using namespace std;
using ll = long long;
const ll MOD=1000000007LL;
typedef pair<int, int> P;

ll ADD(ll x, ll y) { return (x+y) % MOD; }
ll SUB(ll x, ll y) { return (x-y+MOD) % MOD; }
ll MUL(ll x, ll y) { return x*y % MOD; }
ll POW(ll x, ll e) { ll v=1; for(; e; x=MUL(x,x), e>>=1) if (e&1) v = MUL(v,x); return v; }
ll DIV(ll x, ll y) { /*assert(y%MOD!=0);*/ return MUL(x, POW(y, MOD-2)); }

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

int ans[12];

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

  ll r, D, x;  
  cin >> r >> D >> x;


  ans[0] = x;

  FOR(i, 1, 11){
    ans[i] = ans[i-1]*r - D;
  }

  REP(i, 10){
    cout << ans[i+1] << endl;
  }
  
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
const int MOD=1000000007;

int main(){
    int n,m,i;
    cin>>n>>m;
    vector< pair<int,string> > ps(m);
    rep(i,m) cin>>ps[i].first>>ps[i].second;
    vector< pair<int,int> > flag(n);
    rep(i,n) flag[i].first=flag[i].second=0;
    int ac=0;
    int pe=0;
    rep(i,m){
        if(flag[ps[i].first-1].first==0 && ps[i].second=="AC"){
            ac+=1;
            flag[ps[i].first-1].first=1;
            pe+=flag[ps[i].first-1].second;
        }else if(flag[ps[i].first-1].first==0 && ps[i].second=="WA"){
            flag[ps[i].first-1].second+=1;
        }
    }
    cout<<ac<<" "<<pe;
    return 0;
}

Measured memory_bytes: 7296
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
typedef long long ll;

using namespace std;

class e
{
	public:
	int cost;
	int next;

	e(int n,int c)
	{
		next=n;
		cost=c;
	}
};

int v[10][10];
int A[200][200];

int main()
{
	int h,w;
	int c[10];
	ll ans=0;
	
	cin>>h>>w;
	for(int i=0;i<10;i++)
	{
		for(int j=0;j<10;j++)
		{
			cin>>v[i][j];
		}
	}
	for(int i=0;i<h;i++)
	{
		for(int j=0;j<w;j++)
		{
			cin>>A[i][j];
		}
	}

	//ワーシャルフロイド
	for(int k=0;k<10;k++)
	{
		for(int i=0;i<10;i++)
		{
			for(int j=0;j<10;j++)
			{
				v[i][j]=min(v[i][j],v[i][k]+v[k][j]);
			}
		}
	}

	for(int i=0;i<10;i++)
	{
		c[i]=v[i][1];
		//cerr<<i<<": "<<c[i]<<endl;
	}
	c[1]=0;

	for(int i=0;i<h;i++)
	{
		for(int j=0;j<w;j++)
		{
			if(A[i][j]!=-1)
			{
				ans+=c[A[i][j]];
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 384
#ifdef _MSC_VER
#include <__msvc_all_public_headers.hpp>
#undef min
#undef max
#else
#define NDEBUG
#include <bits/stdc++.h>
#endif

using namespace std;
using large = long long;

int main()
{
    int n;
    cin >> n;
    auto sum = 0LL;
    auto h = 0;
    for (int i = 0; i < n; ++i) {
        int a;
        cin >> a;
        h = max(h, a);
        sum += h - a;
    }

    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 3584
import math

A,B,H,M = map(int,input().split())

degH = 30 * H + 0.5 * M
degM = 6 * M

digA = abs(degH - degM) * math.pi / 180
#度 × 円周率 ÷ 180
if digA <= math.pi /2 :
    ans = float(math.sqrt((A**2) + (B**2) - (2*A*B*math.cos(digA))))
else:
    ans = float(math.sqrt((A**2) + (B**2) - (2*A*B*math.cos(-digA))))

print('{:.21f}'.format(ans))


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

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treeMinimum(Node x){
  while(x->left != NIL){
    x = x->left;
  }
    return x;
}

Node treeSearch(Node u, int k){
  if(u == NIL || k == u->key) return u;
  if(k < u->key) return treeSearch(u->left,k);
  else return treeSearch(u->right,k);

}

Node treeSuccessor(Node x){
  Node y;
  if(x->right != NIL) return treeMinimum(x->right);
  y = x->parent;
  while(y != NIL && x == y->right){
    x = y;
    y = y->parent;
  }
    return y;
}

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y



}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

 while(x != NIL){
   y = x;
   if(z->key < x->key) x = x->left;
   else x = x->right;
 }
 
 z->parent = y;
 if(y == NIL){
   root = z;
   // printf("root = %d\n" ,z->key);
 }
 else if(z->key < y->key) {
   y->left = z;
   // printf("key = %d yl = %d\n" ,z->key,y->key);
 }
 else {
   y->right = z; 
   // printf("key = %d yr = %d\n" ,z->key,y->key);
 }
 
 
}

void inorder(Node u){
  if(u->left != NIL)inorder(u->left);
  printf(" %d",u->key);
  if(u->right != NIL)inorder(u->right); 
}
void preorder(Node u){
  printf(" %d",u->key);
  if(u->left != NIL)preorder(u->left);
  if(u->right != NIL)preorder(u->right);
}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }

  return 0;
}

Measured memory_bytes: 19360
#include <stdio.h>
#include <math.h>

int main(void){
    double r;
    scanf("%lf",&r);
    double menseki,nagasa;
    menseki = r*r*M_PI;
    nagasa = 2*r*M_PI;
    printf("%.6lf %.6lf\n",menseki,nagasa);
    return 0;
}


Measured memory_bytes: 2140
#include "bits/stdc++.h"
using namespace std;

typedef long long ll;

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

int main() {
	ll N, W;
	cin >> N >> W;
	vector<ll> w(N), v(N), x[4];
	cin >> w[0] >> v[0];
	x[0].push_back(v[0]);
	for (ll i = 1; i < N; i++) {
		cin >> w[i] >> v[i];
		x[w[i]-w[0]].push_back(v[i]);
	}

	for (int i = 0; i < 4; i++) {
		sort(x[i].rbegin(), x[i].rend());
		x[i].insert(x[i].begin(),0);
	}

	for (ll i = 0; i < 4; i++) {
		for (ll j = 1; j < x[i].size(); j++) {
			x[i][j] += x[i][j-1];
		}
	}

	ll mx=0;
	for (ll i = 0; i < x[0].size(); i++) {
		for (ll j = 0; j < x[1].size(); j++) {
			for (ll k = 0; k < x[2].size(); k++) {
				for (ll l = 0; l < x[3].size(); l++) {
					//cout << i <<" "<< j <<" "<< k <<" "<< l << endl;
					ll vv = x[0][i] + x[1][j] + x[2][k] + x[3][l];
					ll ww = w[0]*i+(w[0]+1)*j+(w[0]+2)*k+(w[0]+3)*l;
					if(ww<=W) mx = max(mx, vv);
				}
			}
		}
	}

	cout << mx << endl;
}



Measured memory_bytes: 256
package main

import (
	"bufio"
	_ "container/heap"
	"fmt"
	"os"
	_ "sort"
	"strconv"
)

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

func ceil(a, b int) int {
	if a%b == 0 {
		return a / b
	} else {
		return a/b + 1
	}
}

func gcd(a, b int) int {
	if b == 0 {
		return a
	}
	return gcd(b, a%b)
}

func lcm(a, b int) int {
	return a / gcd(a, b) * b
}

// Sort
type RuneSlice []rune

func (a RuneSlice) Len() int           { return len(a) }
func (a RuneSlice) Less(i, j int) bool { return a[i] < a[j] }
func (a RuneSlice) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

// Main
const MOD = int(1e+9) + 7
const INF = 1 << 60

func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	defer wtr.Flush()
	N, M := sc.nextInt(), sc.nextInt()
	sum1 := N * (N - 1) / 2
	sum2 := M * (M - 1) / 2

	fmt.Fprintln(wtr, sum1+sum2)
}


Measured memory_bytes: 640
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		boolean f = true;
		while(true){
			int a = sc.nextInt();
			int b = sc.nextInt();
			if(a == 0 && b == 0)break;
			if(!f)System.out.println();
			f = false;
			List<Integer> list = new ArrayList<Integer>();
			for(int i=a;i<=b;i++){
				if(i%4==0&&(i%100!=0||i%400==0)){
					list.add(i);
				}
			}
			if(list.isEmpty()){
				System.out.println("NA");
			}else{
				for(int i : list){
					System.out.println(i);
				}
			}
		}
	}
}

Measured memory_bytes: 12000
k = int(input())
a = [0,7]
for i in range(2,10**6+1):
    x = a[i-1]*10
    x %= k
    a.append(x)
tnp = 0
for i in range(1,len(a)):
    tnp += a[i]
    tnp %= k
    if (tnp==0):
        print(i)
        exit()
print(-1)

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

int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int n;
	while (cin >> n) {
		long long stool = 0;
		int prev = 0;
		for (int i = 0; i < n; ++i) {
			int aux;
			cin >> aux;
			if (aux <= prev) {
				stool += (prev - aux);
			} else {
				prev = aux;
			}
		}
		cout << stool << endl;
	}
	return 0;
}

Measured memory_bytes: 3612
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;

int main() {
    int N;
    cin >> N;
    int tl[N + 2], tr[N + 2], v[N + 2];
    tl[0] = 0;
    tr[0] = 0;
    int endt = 0;
    for (int i = 1; i <= N; i++) {
        int tmp;
        cin >> tmp;
        tl[i] = tr[i - 1];
        tr[i] = tl[i] + tmp;
        endt += tmp;
    }
    tl[N + 1] = tr[N];
    tr[N + 1] = tl[N + 1];
    for (int i = 1; i <= N; i++) {
        cin >> v[i];
    }
    v[0] = 0;
    v[N + 1] = 0;

    double spd[2 * endt + 1];
    for (int i = 0; i <= 2 * endt; i++) {
        spd[i] = 1000000000;
        for (int j = 0; j < N + 2; j++) {
            double tmp;
            double tnow = double(i) / 2;
            //cout << "tnow" << tnow << endl;
            //cout << tl[j] << tr[j] << endl;
            if (tnow < tl[j]) {
                tmp = v[j] + tl[j] - tnow;
            } else if (tr[j] < tnow) {
                tmp = v[j] + tnow - tr[j];
            } else if (tl[j] <= tnow && tnow <= tr[j]) {
                tmp = v[j];
            }
            spd[i] = min(spd[i], tmp);
        }
        //cout << "i=" << i << " " << spd[i] << endl;
    }

    /*for(int i=0;i<N+2;i++){
      cout << tl[i] << " " << tr[i] << " " << v[i] << endl;
    }*/

    double sum = 0;
    for (int i = 1; i <= 2 * endt; i++) {
        sum += (spd[i] + spd[i - 1]) * 0.5 / 2;
    }

    //printf("%.15lf\n", sum);
    cout << fixed << setprecision(12) << sum << "\n";
    return 0;
}

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

int main(){
    int N,M; cin >> N >> M;
    vector<int> a(M); rep(i,M) cin >> a[i];
    vector<ll> dp(N+1);
    dp[0] = 1;
    dp[1] = 1;
    rep(i,N-1) dp[i+2] = (dp[i+1] + dp[i]) % MOD;
    ll ans;
    if(M == 0){
        ans = dp[N];
    }else{
        ans = dp[a[0]-1] % MOD;
        rep(i,M-1){
            if(a[i+1] == a[i]) continue;
            if(a[i+1] - a[i] - 1 == 0){
                ans = 0;
                break;
            }else{
                ans *= (dp[a[i+1]-a[i]-2]) % MOD;
            }
            ans %= MOD;
        }
        ans *= dp[N-a[M-1]-1];
        ans %= MOD;
    }
    cout << ans << endl;
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int a,b,c,n,m,i,j,sum = 0;
    vector<long long int>v;
    map<long long int,long long int>mp;
    set<long long int>s;
    string str;
    cin>>a>>b>>n;
    if(b>n)
        m = n;
    else
        m = b-1;
    sum = (a*m)/b - a*(m/b);
    cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 3596
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <cstring>

using namespace std;
// ascending order
#define vsort(v) sort(v.begin(), v.end())
// descending order
#define vsort_r(v) sort(v.begin(), v.end(), greater<int>())
#define vunique(v) unique(v.begin(), v.end())
#define mp make_pair
#define ts(x) to_string(x)
#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define repm(i, a, b) for(int i = (int)a; i > (int)b; i--)
#define bit(a) bitset<8>(a)
#define des_priority_queue priority_queue<int, vector<int>, greater<int> >
#define all(v) (v).begin(), (v).end()
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1e18;

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

	int H, W;
	cin >> H >> W;
	char maze[H][W];
	int rsl = H * W;
	rep(i, 0, H) rep(j, 0, W) {
		cin >> maze[i][j];
		if(maze[i][j] == '#') rsl--;
	}

	queue<pair<int, int> > q;
	q.push(make_pair(0, 0));

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

	int dis[H][W];
	rep(i, 0, H) rep(j, 0, W) dis[i][j] = -1;
	dis[0][0] = 0;
	while(!q.empty()) {
		pair<int, int> p = q.front();
		q.pop();
		int x = p.first, y = p.second;
		if(x == (W - 1) and y == (H - 1)) break;

		rep(i, 0, 4) {
			int nx = x + dx[i], ny = y + dy[i];
			if(0 <= nx and nx < W and 0 <= ny and ny < H) {
				if(dis[ny][nx] == -1) {
					if(maze[ny][nx] == '.') {
						dis[ny][nx] = dis[y][x] + 1;
						q.push(make_pair(nx, ny));
					}
				}
			}
		}
	}

	if(dis[H - 1][W - 1] == -1) cout << -1 << endl;
	else {
		rsl -= dis[H - 1][W - 1];
		cout << rsl - 1<< endl;
	}
}


Measured memory_bytes: 256
#[allow(unused_macros)]
macro_rules! invec {
    ( $t:ty ) => {{
        let mut s = String::new();
        match std::io::stdin().read_line(&mut s) {
            Ok(0) => Vec::<$t>::new(),
            Ok(n) => s.trim().split_whitespace().map(|s| s.parse::<$t>().unwrap()).collect::<Vec<$t>>(),
            Err(_) => Vec::<$t>::new(),
        }
    }}
}

#[allow(unused_macros)]
macro_rules! input {
    ( $($t:ty),* ) => {{
        let mut s = String::new();
        std::io::stdin().read_line(&mut s);
        let mut splits = s.trim().split_whitespace();
        ($(
            {
                 splits.next().unwrap().parse::<$t>().unwrap()
            },
        )*)
    }}
}

#[allow(unused_must_use)]
#[allow(unused_variables)]
fn solve() {
    let (n, k) = input!(usize, i64);

    let mut loc = vec![];
    for _ in 0..n {
        let coordinate = input!(i64, i64);
        loc.push(coordinate);
    }

    let mut min_area = std::i64::MAX;
    for x1 in 0..n {
        for x2 in (x1 + 1)..n {
            for y1 in 0..n {
                for y2 in (y1 + 1)..n {
                    let mut count = 0;
                    let x_min = if loc[x1].0 < loc[x2].0 {
                        loc[x1].0
                    } else {
                        loc[x2].0
                    };
                    let x_max = if loc[x1].0 > loc[x2].0 {
                        loc[x1].0
                    } else {
                        loc[x2].0
                    };
                    let y_min = if loc[y1].1 < loc[y2].1 {
                        loc[y1].1
                    } else {
                        loc[y2].1
                    };
                    let y_max = if loc[y1].1 > loc[y2].1 {
                        loc[y1].1
                    } else {
                        loc[y2].1
                    };
                    for i in 0..n {
                        if x_min <= loc[i].0 && loc[i].0 <= x_max && y_min <= loc[i].1 &&
                            loc[i].1 <= y_max
                        {
                            count += 1;
                        }
                    }
                    if k <= count {
                        let area = (x_max - x_min) * (y_max - y_min);
                        if area < min_area {
                            min_area = area;
                        }
                    }
                }
            }
        }
    }

    println!("{}", min_area);
}

fn main() {
    solve();
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
bool bo[100];
#define ll long long int
int main()
{
	string s;
	getline(cin,s);
	stringstream ss;
	ss<<s;
	string wo;
	vector<string>v;
	while(ss>>wo)
	{
		v.pb(wo);
	}
	for(int i=0;i<v.size();i++)
	{
		string q;
		q=v[i];
		cout<<q[0];
	}
}


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

using namespace std;

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

typedef int64_t ll; typedef vector<int> VI; typedef pair<int,int> pii;
const ll mod = 1e9+7;

int main()
{
	
	//cin.tie(0); ios_base::sync_with_stdio(false);
	int n;
	cin >>n;
	VI p(n), b(100010,0);
	int sm =0;
	rep(i,n){
		cin >>p[i];
		if(i == p[i] -1){
			sm++;
			b[i]=1;
		}
	}
	if(sm==0){puts("0"); return 0;}
	//for(auto x :b) printf("%d, ",x); puts("");
	int ans =0;
	rep(i,100008) if(b[i]==1 && b[i+1]==1){
		ans++;
		b[i]=b[i+1]=0;
	}
	rep(i,100008) if(b[i]==1) ans++;

	cout << ans<<"\n";
	return 0;
}

Measured memory_bytes: 1024
import sys
sys.setrecursionlimit(10000000)
input = sys.stdin.readline

N, Q = map(int, input().split())

T = [[] for i in range(N)]

for i in range(N-1):
    a, b = map(int, input().split())
    T[a-1].append(b-1)
    T[b-1].append(a-1)

ans = [0 for i in range(N)]

for i in range(Q):
    p, x = map(int, input().split())
    ans[p-1] += x

def dfs(n, r):
    for i in T[n]:
        if i != r:
            ans[i] += ans[n]
            dfs(i, n)

dfs(0, -1)

print(*ans)


Measured memory_bytes: 230908
import bisect
N, M = map(int, input().split())
P, Y = [], []
pref = [[] for _ in range(N+1)] # non-0-indexed
for m in range(M):
    p,y = map(int, input().split())
    P.append(p)
    Y.append(y)
    pref[p].append(y)

for i,pre in enumerate(pref):
    pref[i] = sorted(pre)

for p,y in zip(P,Y):
    a = "{:0>6}".format(p)
    i = bisect.bisect(pref[p], y)
    a += "{:0>6}".format(i)
    print(a)

Measured memory_bytes: 24116
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int a,b;cin>>a>>b;
  if((a==1&b==2)|(a==2&b==1))cout<<3<<endl;
  if((a==1&b==3)|(a==3&b==1))cout<<2<<endl;
  if((a==2&b==3)|(a==3&b==2))cout<<1<<endl;
}

Measured memory_bytes: 384
# -*- coding: utf-8 -*-
import sys,copy,math,heapq,itertools as it,fractions,re,bisect,collections as coll

N, P = map(int, raw_input().split()) 
A = map(int, raw_input().split()) 

ans = 0
zero = 1
one = 0
for i in xrange(N):
    if A[i] % 2 == 0:
        zero *= 2
        one *= 2
    else:
        zero, one = zero + one, zero + one

print zero if P == 0 else one



Measured memory_bytes: 4392
n=int(input())
a=list(map(int,input().split()))

ans=1

d={}

ch=0

mod=10**9+7

for i in range(n):
  if a[i]==0:
    if 0 not in d:
      d[0]=1
      ans*=3
    else:
      if d[0]==1:
        d[0]=2
        ans*=2
      elif d[0]==2:
        d[0]=3
      else:
        ch+=1
        break
      
  else:
    if a[i] not in d:
      d[a[i]]=1
      if a[i]-1 not in d:
        ch+=1
        break
      else:
        ans*=d[a[i]-1]
    else:
      if d[a[i]]==1:
        d[a[i]]=2
        if a[i]-1 not in d:
          ch+=1
          break
        else:
          if d[a[i]-1]>=2:
            ans*=d[a[i]-1]-1
          else:
            ch+=1
            break
      elif d[a[i]]==2:
        d[a[i]]=3
        if a[i]-1 not in d:
          ch+=1
          break
        else:
          if d[a[i]-1]>=3:
            ans*=1
          else:
            ch+=1
            break
      else:
        ch+=1
        break
        
  ans=(ans%mod)
  
if ch==0:
  print(ans)
else:
  print(0)




Measured memory_bytes: 88612
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
int dx[4]={1,0,-1,0} , dy[4]={0,1,0,-1} ;

int main(){
   ll n,k;
   cin>>n>>k;
   ll a[n+1];
   a[0]=0;
   rep(i,n)cin>>a[i+1];
   rep(i,n){
       a[i+1]+=a[i];
       a[i+1]%=k;
   }
   map <ll,ll> cnt;
   rep(i,n+1)cnt[a[i]]++;
   ll ans=0;
   for(auto e:cnt)ans+=e.second*(e.second-1)/2;
   cout<<ans<<endl;
   return 0;
}

Measured memory_bytes: 4992
def find(x):
    if par[x] == x:
        return x
    else:
        par[x] = find(par[x])
        return par[x]

def unite(x, y):
    x = find(x)
    y = find(y)
    if x == y:
        return
    if rank[x] < rank[y]:
        par[x] = y
        size[y] += size[x]
    else:
        par[y] = x
        size[x] += size[y]
        if rank[x] == rank[y]:
            rank[x] += 1

N, M = map(int, input().split())
par = [i for i in range(N)]
rank = [1] * N
ans = [0] * M
size = [1] * N
ab = [list(map(int, input().split())) for i in range(M)]
for i in reversed(range(M)):
    fa = find(ab[i][0] - 1)
    fb = find(ab[i][1] - 1)
    if fa != fb:
        ans[i] = size[fa] * size[fb]
        unite(ab[i][0] - 1, ab[i][1] - 1)
an = 0
for i in ans:
    an += i
    print(an)

Measured memory_bytes: 34904
//--------------------------------------------------template----------------------------------------//
//c
#include <stdio.h>
#include <time.h>
#include <math.h>
//c++
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <sstream>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <vector>
#include <complex>
#include <cmath>
//c++11
#include <tuple>
#define all(c) ((c).begin(),(c).end())
#define rall(c) (c).rbegin(),(c).rend()
//#define sort(v,n) sort(v,v+n)
//#define vsort(v) sort(v.begin(),v.end())
#define vvsort(v) sort(v.rbegin(),v.rend())
#define ll long long
#define pb(a) push_back(a)
#define fi first
#define se second
#define inf 999999999
using namespace std;
const ll MOD = 1e9 + 7;
const double PI = acos(-1.0);
//---------------------------------------------------------------------------------------------//
int n;

inline void pri(int a) {
	cout << a<<":";
}

int main() {
	cin >> n;
	pri(n);
	int now = 2;
	while (now*now <= n) {
		if (n%now == 0)cout << " " << now, n /= now;
		else now++;
	}
	if (n != 1)cout <<" "<< n;
	cout << endl;
	return 0;
}

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

//***********************************************************************
int MAXNUM = 5e3+5;
vector <int>vis(MAXNUM);
vector<int> pr;
void sieve() {
	pr.push_back(2);
	for(ll i=3;i<MAXNUM;i+=2) if(!vis[i]) {
		pr.push_back(i);
		for(ll j=i*i;j<MAXNUM;j+=2*i) vis[j]=true;
	}
}
//************************************************************************
ll mod=1000000007;
void solve()
{
    ll n;
    cin >> n;
    string s;
    cin >>s;
    vector<vector<ll>> dp(n);
    for(ll i=0;i<n;i++)
    {
        dp[i].resize(n+1);

    }
    //cout << "check" << endl;
    if(s[0]=='<')
    {
        dp[1][1]=0;
        dp[1][2]=1;
    }
    else
    {
        dp[1][1]=1;
        dp[1][2]=1;
    }
    //cout << dp[1][1] << " " << dp[1][2] << endl;
    for(int i=2;i<n;i++)
    {
        for(int j=1;j<=i+1;j++)
        {
            ll add=0;
            if(s[i-1]=='>')
            {
                add=(dp[i-1][i]-dp[i-1][j-1]+mod)%mod;
            }
            else
            {
                add=dp[i-1][j-1];
            }
            dp[i][j]=(dp[i][j-1]+add)%mod;
          //  cout << dp[i][j] << " ";
        }
        //cout << endl;
    }
    cout << dp[n-1][n] << endl;
	
}


int main()
{ 
	ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
	ll t;
	//cin >> t;
	t=1;
	while(t--)
	{
		solve();
	}

	return 0;
}

Measured memory_bytes: 70656
#include<stdio.h>
int main(void)
{
	int a,b,c,d,e,f,g,h;
	scanf("%d %d %d %d %d",&a,&b,&c,&d,&e);
	if(a>=b){
		if(a>=c){
			if(b>=c) f=c;
			else f=b;
		}
		else f=b;
	}
	if(b>=a){
		if(b>=c){
			if(a>=c) f=c;
			else f=a;
		}
		else f=a;
	}
	if(d>=e) g=e;
	if(e>=d) g=d;
	h=f+g-50;
	printf("%d\n",h);
	return 0;
}
			

	


Measured memory_bytes: 2140
// by Balloons
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <algorithm>
#define mpr make_pair
#define debug() puts("okkkkkkkk")
#define rep(i,a,b) for(int (i)=(a);(i)<=(b);(i)++)

using namespace std;

typedef long long LL;

const int inf = 1e9;
const int maxn=2e5+5; 

int n,m;
struct edges{
	int to,nxt;
}ed[maxn << 1];
int head[maxn],ecnt=0;
int dis[maxn],pre[maxn];
struct ee{
	int to,dis;
	bool operator<(ee b) const {
		return dis>b.dis;
	}
};
priority_queue<ee>pq;

void add(int x,int y){
	ed[++ ecnt].to=y;ed[ecnt].nxt=head[x];head[x]=ecnt;
}

void dij(){
	memset(dis,127,sizeof dis);
	pq.push((ee){1,0});
	dis[1] = 0;
	while(!pq.empty()){
		ee u = pq.top();pq.pop();
		for(int i=head[u.to];~i;i=ed[i].nxt){
			int v=ed[i].to;
			if(dis[v] > dis[u.to] + 1){
				dis[v] = dis[u.to] + 1;
				pq.push((ee){v,dis[v]});
				pre[v] = u.to;
			}
		}
	}
//	for(int i=1;i<=n;i++)printf("%d ",dis[i]);puts("");
}

signed main(){
	memset(head,-1,sizeof head);
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++){
		int x,y;scanf("%d%d",&x,&y);
		add(x,y);add(y,x);
	}
	dij();
	int imp = dis[0];
	for(int i=1;i<=n;i++)if(dis[i] == imp)return puts("No"), 0;
	puts("Yes");for(int i=2;i<=n;i++)printf("%d\n",pre[i]);
/*
有n个点，给m个两点之间得关系，问是否每个点都能到1，是输出“Yes”，并且输出每个点到1得最短路上得前一个点，否则输出“No”。
6 5
1 2
2 3
2 4
4 5
2 6
*/
	return 0;
}



Measured memory_bytes: 9240
#include <stdio.h>
#include <math.h>
 
int main()
{
	double x1,y1,x2,y2,x3,y3,xp,yp;
	double s,s1,s2,s3;
	double ab,bc,ca,ap,bp,cp;
	while(scanf("%lf%lf%lf%lf%lf%lf%lf%lf",&x1,&y1,&x2,&y2,&x3,&y3,&xp,&yp)!=EOF){
	ab=sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
	bc=sqrt((x2-x3)*(x2-x3)+(y2-y3)*(y2-y3));
	ca=sqrt((x3-x1)*(x3-x1)+(y3-y1)*(y3-y1));
	ap=sqrt((x1-xp)*(x1-xp)+(y1-yp)*(y1-yp));
	bp=sqrt((x2-xp)*(x2-xp)+(y2-yp)*(y2-yp));
	cp=sqrt((x3-xp)*(x3-xp)+(y3-yp)*(y3-yp));
	s=sqrt(((ab+bc+ca)*(-ab+bc+ca)*(ab-bc+ca)*(ab+bc-ca))/16);
	s1=sqrt(((ap+ab+bp)*(-ap+ab+bp)*(ap-ab+bp)*(ap+ab-bp))/16);
	s2=sqrt(((bp+bc+cp)*(-bp+bc+cp)*(bp-bc+cp)*(bp+bc-cp))/16);
	s3=sqrt(((cp+ca+ap)*(-cp+ca+ap)*(cp-ca+ap)*(cp+ca-ap))/16);
	if(fabs(s1+s2+s3-s)<0.00000001)puts("YES");
	else puts("NO");
	}
	return 0;
}

Measured memory_bytes: 612
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let n = read::<usize>();
    let mut s = HashSet::new();
    for i in 0..n {
        s.insert(read::<String>());
    }
    println!("{}", s.len());
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


Measured memory_bytes: 15364
#include <iostream>
#include <cmath>
#include <map>
#include <utility>
#include <list>
#include <string>
#include <vector>
#include <algorithm>
#include <set>

using namespace std;

#define LL long long


int main() {
    string s;
    cin >> s;

    int r = 0, b = 0;
    for (int i=0; i < s.size(); i++) {
        if (s[i] == '0') {
            r++;
        } else {
            b++;
        }
    }

    cout << 2 * min(r, b) << endl;
    
    return 0;
}


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

int main() {
    int n;
    cin>>n;
    int d[n];
    for(int i=0;i<n;i++) cin>>d[i];
    sort(d,d+n);
    int ans=0,nowd=-1;
    for(int i=0;i<n;i++){
        if(d[i]>nowd){
            ans++;
            nowd=d[i];
        }
    }
    cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
/*test7.c*/
#include<stdio.h>
int main(void){
   int s,m,h;
   scanf("%d",&s);
   h=s/3600;
   m=s/60;
   if(h>=1){
      m=m-h*60;
   }
   s=s-3600*h-60*m;
   printf("%d:%d:%d\n",h,m,s);
   return 0;
}

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

int main() {
int A,B,C,D;
cin>>A>>B>>C>>D;

if(A+B > C+D){
cout<<"Left"<<endl;
}
else if( A+B ==C+D ){
cout<<"Balanced"<<endl;
}
else if( A+B<C+D){
cout<<"Right"<<endl;
}
}


Measured memory_bytes: 256