akhauriyash/Code-Regression huggingface dataset:
import io.StdIn.readLine


object Main {

  def main(args: Array[String]): Unit = {
    var s = readLine()
    var state = 0

    while (state == 0) {
      if      (s.endsWith("dream"))   s = s.slice(0, s.length - 5)
      else if (s.endsWith("dreamer")) s = s.slice(0, s.length - 7)
      else if (s.endsWith("erase"))   s = s.slice(0, s.length - 5)
      else if (s.endsWith("eraser"))  s = s.slice(0, s.length - 6)
      else if (s.isEmpty) state = 1
      else              state = 2
    }
    state match {
      case 1 => println("YES")
      case 2 => println("NO")
    }
  }

}


Measured memory_bytes: 107736
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

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

    int N = scanner.nextInt();
    Set<String> count = new HashSet<>();
    for (int i = 0; i < N; i++) count.add(scanner.next());
    System.out.println(count.size());
  }
}


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


int main()
{
    int n;
    string s,s1,s2;
    cin>>n;
    cin>>s1;
    cin>>s2;
    s = "";
    for(int i=0;i<n;i++){
        s = s+s1[i]+s2[i];
    }
    cout<<s;
    return 0;
}


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

int main () {
  int N; 
  cin >> N;
  vector<int> A(N);
  vector<int> C(N);
  for (int i=1; i<N; i++) {
    cin >> A.at(i);
    C.at(A.at(i)-1)++;
  }

  for (int i=0; i<N; i++) {
    cout << C.at(i) << endl;
  }
}

Measured memory_bytes: 4844
/*  ex4_2 Colon
    pandacodeb  */

#include <stdio.h>
#include <math.h>

double findAng(double h, double m);
double findDist(double lenH, double lenM, double h, double m);

int main(void){
    double lenH, lenM, h, m;
    scanf("%lf %lf %lf %lf", &lenH, &lenM, &h, &m);
    printf("%.10f\n", findDist(lenH, lenM, h, m));          //少数10桁まで距離の値を出力
    return 0;
}

double findAng(double h, double m){
    double angleH = (2 * M_PI * h/12) + (M_PI/6 * m/60);    //時針の角度の計算
    double angleM = 2 * M_PI * m/60;                        //分針の角度の計算
    return angleM - angleH;
}

double findDist(double lenH, double lenM, double h, double m){
    double angle = findAng(h, m);                                            //なす角度の計算
    double dist = sqrt(lenH*lenH + lenM*lenM - 2*lenH*lenM*cos(angle));     //距離の計算
    return dist;
}

Measured memory_bytes: 2544
#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, a, b;
    cin >> n >> a >> b;
    int ans = min(b, a * n);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3548
#include <stdio.h>

int main(){
	int i;
	double a,sum;

	while(scanf("%lf",&a) != EOF){
		sum = 0.0;
		for(i = 0;i < 10;i++){
			sum += a;
			if(i%2){
				a /= 3.0;
			}else{
				a *= 2.0;
			}
		}
		printf("%.8f\n",sum);
	}

	return 0;
}

Measured memory_bytes: 652
#include <bits/stdc++.h>
using namespace std;
struct dat{int a,b,c,d;};

vector<dat> block[2];
dat move(dat t,int dy,int dx){
  int mp[4][4] = {};
  mp[1+dy][1+dx] = t.a;
  mp[1+dy][2+dx] = t.b;
  mp[2+dy][1+dx] = t.c;
  mp[2+dy][2+dx] = t.d;
  for(int i=0;i<4;i++)
    for(int j=0;j<4;j++){
      if((i==1&&j==1)||(i==1&&j==2)||(i==2&&j==1)||(i==2&&j==2))continue;
      if(mp[i][j] == 0)continue;
      return (dat){-1,-1,-1,-1};
    }
  return (dat){mp[1][1],mp[1][2],mp[2][1],mp[2][2]};
}

bool isEmpty(dat a){return (!a.a && !a.b && !a.c && !a.d);}
bool isFull(dat a){return (a.a && a.b && a.c && a.d);}
bool isTouch(dat a,dat t){return ((a.a && t.a)||(a.b && t.b)||(a.c && t.c)||(a.d  && t.d));}

dat merge(dat t,dat a){
  t.a|=a.a, t.b|=a.b, t.c|=a.c, t.d|=a.d;
  return t;
}

int drop(dat a,dat b,vector<dat> &mp){
  if(!isEmpty(mp.back()))mp.push_back((dat){0,0,0,0});
  
  int res = 0;
  int idx = mp.size() - 2;
  while(!isTouch(a,mp[idx]) && !isTouch(b,mp[idx+1]))idx--;
  idx++;

  if(!isEmpty(a))mp[idx] = merge(mp[idx],a);

  if(idx+1<(int)mp.size()) mp[idx+1] = merge(mp[idx+1],b);
  else if(!isEmpty(b)) mp.push_back(b);

  for(int i=mp.size()-1;i>=1;i--) if(isFull(mp[i])) mp.erase(mp.begin()+i),res++;
  return res;
}

int sim(int idx,vector<dat>mp){
  if(idx == (int)block[0].size()) return 0; 

   int res = 0; 
  for(int i=-1;i<=1;i++)
    for(int j=-1;j<=1;j++){
      dat nx1 = move(block[0][idx],i,j);
      dat nx2 = move(block[1][idx],i,j);
      if(nx1.a == -1 || nx2.a == -1)continue;
      vector<dat> nmp = mp;
      int r = drop(nx1,nx2,nmp);
      res = max(res,r+sim(idx+1,nmp));
    }
  return res;
}

int main(){
  while(1){
    int h,n;
    cin>>h>>n;
    if(h==0&&n==0)break;
    vector<dat> mp(h+1);
    mp[0] = (dat){1,1,1,1};
    for(int i=1;i<=h;i++){
      char  a,b,c,d;
      cin>>a>>b>>c>>d;
      mp[i].a = (a == '#');
      mp[i].b = (b == '#');
      mp[i].c = (c == '#');
      mp[i].d = (d == '#');
    }

    
    block[0].resize(n); block[1].resize(n);
    for(int j=0;j<n;j++)
      for(int i=0;i<2;i++){
        char  a,b,c,d;
        cin>>a>>b>>c>>d;
        block[i][j].a = (a == '#');
        block[i][j].b = (b == '#');
        block[i][j].c = (c == '#');
        block[i][j].d = (d == '#');
      }
    cout<<sim(0,mp)<<endl;
    
  }
  return 0;
}

Measured memory_bytes: 3072
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <map>

#define rep(i,x) for(int i = 0; i < x; i++)
#define rrep(i,x) for(int i = 1; i <= x; i++)
#define srep(i,s,t) for (int i = s; i < t; ++i)
using ll = long long;
using namespace std;
const int INF = 1001001001;
const ll LINF = 1002003004005006007;
const int mod = 998244353;

int main(){
    int n; cin >> n;
    int ans = n / 500 * 1000;
    n %= 500;
    ans += n / 5 * 5;
    cout << ans << endl;
}



Measured memory_bytes: 256
// I SELL YOU...! 
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<chrono>
#include<iomanip>
#include<map>
#include<set>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using TP = tuple<ll,ll,ll>;
void init_io(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout <<fixed<< setprecision(18);
}
double ans=0;
ll k;
double p,e,t;
void solve(ll i,double l,double r,double per){
  //cout << i <<" "<<l<<" "<<r<<" "<<per<<endl;
  if(i==k){
    double v= (l+r)/2;
    if(abs(v-t)<=e){
      ans += per;
    }
    return;
  }
  i++;
  if(t+e<l||r<t-e){
    return;
  }
  if(t-e<=l&&r<=t+e){
    ans += per;
    return;
  }
  double h = (l+r)/2;
  if(h<=t){
    solve(i,h,r,per*(1-p));
    solve(i,l,h,per*p);
  }else{
    solve(i,l,h,per*(1-p));
    solve(i,h,r,per*p);
  }
}
signed main(){
  init_io();
  double r,l;
  cin >> k >> l >> r >> p >> e >> t;
  solve(0,l,r,1.0);
  cout << ans << endl;
}



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

int main(){
    int n;
    cin >> n;
    if(n>=30){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}


Measured memory_bytes: 3628
#include<stdio.h>
int m[100000][3];
int h[100000][3];
int n;
int min(int i,int j)
{
    return i>j?i:j;
}
int f(int j,int i)
{
    int k;
    if(n==j)
        return 0;
    if(m[j][i]!=-1)
        return m[j][i];
    int ans=0;
    for(k=0;k<3;k++)
    {
        if(k==i)
            continue;
        ans=min(ans,h[j][i]+f(j+1,k));
    }
    m[j][i]=ans;
    return ans;
}
int main()
{
     int i,j,l=0;
     scanf("%d",&n);
     for(i=0;i<n;i++)
     {
         for(j=0;j<3;j++)
            {
                scanf("%d",&h[i][j]);
            }
     }
     for(i=0;i<n;i++)
     {
         for(j=0;j<3;j++)
            m[i][j]=-1;
     }
     for(i=0;i<3;i++)
     {
         l=l>f(0,i)?l:f(0,i);

     }
     printf("%d",l);
    return 0;
}


Measured memory_bytes: 11836
n,q=[int(i) for i in input().split()]
s = input()
qs = []
for i in range(q):
    qs.append([int(i) for i in input().split()])

counts = [0] * n
count = 0
for i in range(1,n):
    if s[i] == "C" and s[i-1] == "A":
        count += 1
    counts[i] = count
counts = [0] + counts

for i in range(q):
    st, en = qs[i]
    print(counts[en] - counts[st])

Measured memory_bytes: 24464
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
typedef long long ll;
namespace mp = boost::multiprecision;
using Mint = mp::cpp_int;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i = int(a); i < int(b); i++)
#define all(v) v.begin(), v.end()
#define uni(v) v.erase(unique(all(v)), v.end())
#define sort_g(v) sort(all(v), greater<int>())
#define dump(x) cerr << #x << ' ' << '=' << ' ' << x << endl

int main() {
    int N, A, B;
    cin >> N >> A >> B;

    int Q1 = 0, Q2 = 0, Q3 = 0;
    rep(i, N) {
        int P;
        cin >> P;
        if(P <= A) Q1++;
        else if(A + 1 <= P && P <= B) Q2++;
        else Q3++;
    }
    cout << min({Q1, Q2, Q3}) << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
vector<int>adj[100005];
bool vis[100005];
void dfs(int x)
{
    vis[x]= 1;
    for(int i=0; i<adj[x].size(); i++)
    {
        int y= adj[x][i];
        if(!vis[y])dfs(y);
    }
    return;
}
int main()
{
    int n, m;
    scanf("%d %d", &n, &m);
    while(m--)
    {
        int x, y;
        scanf("%d %d", &x, &y);
        adj[x].push_back(y);
        adj[y].push_back(x);
    }
    int res= -1;
    for(int i=1; i<=n; i++)
    if(!vis[i])dfs(i), res++;
    printf("%d\n", res);
    return 0;
}


Measured memory_bytes: 9804
//   _/                _/                 _/_/_/   _/
//_/_/_/_/   _/_/   _/_/_/_/   _/_/    _/       _/_/
// _/     _/    _/   _/     _/    _/  _/_/_/     _/
//_/     _/    _/   _/     _/    _/  _/    _/   _/
// _/_/   _/_/       _/_/   _/_/      _/_/     _/
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<vector>
#include<random>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const double pi=3.14159265358979323846;
const int inf=1e9;
const ll INF=1e18;
int main() {
  cin.tie(0),cout.tie(0);
  ios::sync_with_stdio(false);
  int h,a;
  cin >> h >> a;
  cout << (h+a-1)/a << endl;
 }

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
#define MOD (1000000007)
#define INF (1e9)
#define INFL (1e18)
 
typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
template<class T>using arr=vector<vector<T>>;
template<class T>void pr(T x){cout << x << endl;}
template<class T>void prvec(vector<T>& a){rep(i, a.size()-1){cout << a[i] << " ";} cout << a[a.size()-1] << endl;}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

void IsRightTriangle(int a, int b, int c){
    a *= a;
    b *= b;
    c *= c;
    if(a == b + c || b == c + a || c == b + a) pr("YES");
    else pr("NO");
}

int main()
{
    int n; cin >> n;
    rep(i, n){
        int a, b, c; cin >> a >> b >> c;
        IsRightTriangle(a, b, c);
    }
    return 0;}


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

int main(){
  int n,k; cin>>n >>k;
  int a=1;
  for(int i=0;i<n;i++){
    if(a*2>a+k)a+=k;
    else a*=2;
  }
   cout<<a<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
    ll N, S;
    cin >> N >> S;
    ll ans = -1;
    if ( S > N ) {
    } else if ( S == N ) {
        ans = N + 1;
    } else {
        ll d = N - S;
        vector<ll> bs, bs2;
        for ( ll i = 1; i*i <= d; i++ ) {
            bs.emplace_back(i+1);
            if ( i*i != d ) bs2.emplace_back(d/i+1);
        }
        bs.insert(bs.end(), bs2.rbegin(), bs2.rend());
        for ( ll b : bs ) {
            ll nt = N, st=0;
            while ( nt ) {
                st += nt % b;
                nt /= b;
            }
            if ( st == S ) {
                ans = b;
                break;
            }
        }
    }
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 13532
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#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 ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;



int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    ll a_max = 1;
    ll a_min = (ll)1e9;
    ll b_max = 0;
    ll b_min = (ll)1e9;
    REP(i, n){
        ll a, b;
        cin >> a >> b;
        a_max = max(a_max, a);
        a_min = min(a_min, a);
        b_max = max(b_max, b);
        b_min = min(b_min, b);
    }

    cout << a_max + b_min << "\n";
    return 0;
}


Measured memory_bytes: 892
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <cmath>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <deque>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <unordered_map>

using namespace std;
#define MAX 100000
#define  INFTY (1<<30)

class Edge{
public:
    int t,w;
    Edge(){}
    Edge(int t, int w): t(t),w(w){}
};

vector <Edge> G[MAX];
int n,d[MAX];

bool vis[MAX];
int cnt;

void bfs(int s){
    for (int i=0;i<n;i++){
        d[i] = INFTY;
    }
    queue <int> Q;
    Q.push(s);
    d[s] = 0;
    int u;
    while(!Q.empty()){
        u = Q.front(); Q.pop();
        for (int i=0;i<G[u].size();i++){
            Edge e = G[u][i];
            if (d[e.t] == INFTY){
                d[e.t] = d[u] + e.w;
                Q.push(e.t);
            }
        }
    }
}

void solve(){
    bfs(0);
    int maxv = 0;
    int tgt = 0;
    for (int i=0;i<n;i++){
        if (d[i] == INFTY){
            continue;
        }
        if (maxv < d[i]){
            maxv = d[i];
            tgt = i;
        }
    }

    bfs(tgt);
    maxv = 0;
    for (int i=0;i<n;i++){
        if (d[i] == INFTY){
            continue;
        }
        maxv = max(maxv,d[i]);
    }
    cout << maxv << endl;
}
int main() {
    

    int s,t,w;
    cin >>  n;
    for (int i=0;i<n-1;i++){
        cin >> s >> t >> w;
        G[s].push_back(Edge(t,w));
        G[t].push_back(Edge(s,w));
    }
    solve();
}


Measured memory_bytes: 9940
package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
	return i
}

func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}

func main() {
	fp := os.Stdin
	wfp := os.Stdout

	if len(os.Args) > 1 {
		fp, _ = os.Open(os.Args[1])
		if len(os.Args) > 2 {
			wfp, _ = os.Create(os.Args[2])
		}
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(wfp)

	n := getNextInt(scanner)
	pp := make([]int, n)

	for i := 0; i < n; i++ {
		pp[getNextInt(scanner)-1] = i
	}

	cnt := 0
	c := 0
	for i := 1; i < n; i++ {
		if pp[i] > pp[i-1] {
			c++
			if c > cnt {
				cnt = c
			}
			continue
		}
		c = 0
	}

	fmt.Fprintln(writer, n-cnt-1)

	writer.Flush()
}


Measured memory_bytes: 4096
//list index out of rangeエラー表示用
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep1(i, n) for (int i = 0; i < (int)(n); i++)

int main(){
  string s;
  cin >> s;
  rep1(i, s.size()){
    cout << 'x';
  }
}

Measured memory_bytes: 3584
#include <bits/stdc++.h>
#define INF 1000000000000000001
#define ll long long
#define pll pair<ll, ll>
using namespace std;

ll N;
void start_check(ll a, ll b, vector<vector<bool>>& ans, vector<vector<char>>& board)
{
  for (ll i = N - 2; i >= 0; --i)
  {
    for (ll j = i + 1; j < N; ++j)
    {
      if (board.at(a + i).at(b + j) == board.at(a + j).at(b + i))
      {
        continue;
      }
      else
      {
        ans.at(a).at(b) = false;
        ll bad_num = min(i, j);
        for (ll k = 0; k < bad_num + 1; ++k)
        {
          if (a + k >= N || b + k >= N)
          {
            break;
          }
          ans.at(a + k).at(b + k) = false;
        }
        return;
      }
    }
  }
}

void check(ll a, ll b, vector<vector<bool>>& ans, vector<vector<char>>& board)
{
  for (ll i = N - 2; i >= 0; --i)
  {
    if (board.at(a + i).at(b + N - 1) == board.at(a + N - 1).at(b + i))
    {
      continue;
    }
    for (ll j = 0; j < i + 1; ++j)
    {
      ans.at(a + j).at(b + j) = false;
    }
    return;
  }
  return;
}

int main()
{
  cin >> N;
  vector<vector<char>> board(2 * N - 1, vector<char>(2 * N - 1));
  for (ll i = 0; i < N; ++i)
  {
    for (ll j = 0; j < N; ++j)
    {
      char s;
      cin >> s;
      board.at(i).at(j) = s;
      if (i + N < 2 * N - 1)
      {
        board.at(i + N).at(j) = s;
        if (j + N < 2 * N - 1)
        {
          board.at(i + N).at(j + N) = s;
        }
      }
      if (j + N < 2 * N - 1)
      {
        board.at(i).at(j + N) = s;
      }
    }
  }
  vector<vector<bool>> ans(N, vector<bool>(N, true));
  // start_check(0, 0, ans, board);
  for (ll i = 0; i < N; ++i)
  {
    for (ll j = 0; j < N; ++j)
    {
      if (!ans.at(i).at(j))
      {
        continue;
      }
      if (i == 0 || j == 0)
      {
        start_check(i, j, ans, board);
      }
      else if (ans.at(i - 1).at(j - 1))
      {
        check(i, j, ans, board);
      }
      else
      {
        start_check(i, j, ans, board);
      }
    }
  }
  // for (ll i = 0; i < N; ++i)
  // {
  //   for (ll j = 0; j < N; ++j)
  //   {
  //     if (ans.at(i).at(j))
  //     {
  //       cout << 1;
  //     }
  //     else
  //     {
  //       cout << 0;
  //     }
  //   }
  //   cout << endl;
  // }
  //
  //
  // for (ll i = 0; i < 2 * N - 1; ++i)
  // {
  //   for (ll j = 0; j < 2 * N - 1; ++j)
  //   {
  //     cout << board.at(i).at(j);
  //   }
  //   cout << endl;
  // }
  ll cnt = 0;
  for (ll i = 0; i < N; ++i)
  {
    for (ll j = 0; j < N; ++j)
    {
      if (ans.at(i).at(j))
      {
        cnt += 1;
      }
    }
  }
  cout << cnt << endl;
}


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

using namespace std;

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

  int num_reds = 0;
  for (int n = 0; n < N; ++n) {
    if (S[n] == 'R') {
      ++num_reds;
    }
  }
  int res = 0;
  for (int i = 0; i < num_reds; ++i) {
    if (S[i] == 'W') ++res;
  }
  cout << res << endl;

  return 0;
}


Measured memory_bytes: 3760
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using bint = boost::multiprecision::cpp_int;

int main()
{
    std::string S;
    std::cin >> S;
    std::string a1 = ""; std::string b1 = "keyence";
    std::string a2 = "k"; std::string b2 = "eyence";
    std::string a3 = "ke"; std::string b3 = "yence";
    std::string a4 = "key"; std::string b4 = "ence";
    std::string a5 = "keye"; std::string b5 = "nce";
    std::string a6 = "keyen"; std::string b6 = "ce";
    std::string a7 = "keyenc"; std::string b7 = "e";
    std::string a8 = "keyence"; std::string b8 = "";
    std::regex reb1(R"(^.*keyence$)");
    if (std::regex_match(S, reb1)) {
        std::cout << "YES" << std::endl;
        return 0;
    }
    std::regex rea2(R"(^k.*$)");
    std::regex reb2(R"(^.*eyence$)");
    if (std::regex_match(S, rea2) and std::regex_match(S, reb2)) {
        std::cout << "YES" << std::endl;
        return 0;
    }
    std::regex rea3(R"(^ke.*$)");
    std::regex reb3(R"(^.*yence$)");
    if (std::regex_match(S, rea3) and std::regex_match(S, reb3)) {
        std::cout << "YES" << std::endl;
        return 0;
    }
    std::regex rea4(R"(^key.*$)");
    std::regex reb4(R"(^.*ence$)");
    if (std::regex_match(S, rea4) and std::regex_match(S, reb4)) {
        std::cout << "YES" << std::endl;
        return 0;
    }
    std::regex rea5(R"(^keye.*$)");
    std::regex reb5(R"(^.*nce$)");
    if (std::regex_match(S, rea5) and std::regex_match(S, reb5)) {
        std::cout << "YES" << std::endl;
        return 0;
    }
    std::regex rea6(R"(^keyen.*$)");
    std::regex reb6(R"(^.*ce$)");
    if (std::regex_match(S, rea6) and std::regex_match(S, reb6)) {
        std::cout << "YES" << std::endl;
        return 0;
    }
    std::regex rea7(R"(^keyenc.*$)");
    std::regex reb7(R"(^.*e$)");
    if (std::regex_match(S, rea7) and std::regex_match(S, reb7)) {
        std::cout << "YES" << std::endl;
        return 0;
    }
    std::regex rea8(R"(^keyence.*$)");
    if (std::regex_match(S, rea8)) {
        std::cout << "YES" << std::endl;
        return 0;
    }
    std::cout << "NO" << std::endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<string>
#include<math.h>
#include<vector>
#include<iomanip>
using namespace std;

long long int gcd(long long int x, long long int y)
{
	if (y == 0) { return x; }
	return gcd(y, x % y);
}

int main(void)
{
	int n, k, h[100010],ans = 99999999990;
	cin >> n >> k;
	for (int i = 0; i < n; i++) { cin >> h[i]; }
	sort(h, h + n);
	
	for (int i = 0; i <= n - k; i++)
	{
		if (h[i + k - 1] - h[i] < ans) { ans = h[i + k - 1] - h[i]; }
	}
	cout << ans << endl;
	return 0;
}


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

int main () {
    string X;
    cin >> X;
    int size = X.size();
    int diff = 999;
    for (int i = 0; i <= size-3; ++i) {
        int num = (X[i]-'0')*100 + (X[i+1] - '0')*10 + (X[i+2] - '0');
        diff = min(abs(num - 753), diff);
    }

    cout << diff << endl;
}

Measured memory_bytes: 256
# %% library docs
# ---------------

"""
    @collect [cond] ex

Constructs [`Array`](@ref) from lastly evaluated values from a `for` loop block that appears
  first within given `ex` expression.
If the optional `cond` expression is given, iterations  where the `cond` is `false` are
  effectively filtered out.

```julia-repl
julia> @collect isodd(i) for i = 1:3
           println("i = ", i); i
       end
i = 1
i = 3
2-element Array{Int64,1}:
 1
 3
```

See also: [`@generator`](@ref)
"""
macro collect end

"""
    @generator [cond] ex

Constructs [`Base.Generator`](@ref) from lastly evaluated values from a `for` loop block
  that appears first within given `ex` expression.
If the optional `cond` expression is given, iterations where the `cond` is `false` are
  effectively filtered out.

```julia-repl
julia> @generator isodd(i) for i = 1:3
           println("i = ", i); i
       end |> sum
i = 1
i = 3
4
```

See also: [`@collect`](@ref)
"""
macro generator end

# %% library body
# ---------------

function decompose_forblk(forblk)
    @assert Meta.isexpr(forblk, :for) "for block expression should be given"
    itrspec, body = forblk.args
    @assert Meta.isexpr(itrspec, :(=)) "invalid for loop specification"
    v, itr = itrspec.args
    return body, v, itr
end

function recompose_to_comprehension(forblk, cond = nothing; gen = false)
    body, v, itr = decompose_forblk(forblk)
    return isnothing(cond) ?
        esc(gen ? :(($body for $v in $itr)) : :([$body for $v in $itr])) :
        esc(gen ? :(($body for $v in $itr if $cond)) : :([$body for $v in $itr if $cond]))
end

function walk_and_transform(x, cond = nothing; gen = false)
    Meta.isexpr(x, :for) && return recompose_to_comprehension(x, cond; gen = gen), true
    x isa Expr || return x, false
    for (i, ex) in enumerate(x.args)
        ex, transformed = walk_and_transform(ex, cond; gen = gen)
        x.args[i] = ex
        transformed && return x, true # already transformed
    end
    return x, false
end

macro collect(ex) first(walk_and_transform(ex)) end
macro collect(cond, ex) first(walk_and_transform(ex, cond)) end

macro generator(ex) first(walk_and_transform(ex; gen = true)) end
macro generator(cond, ex) first(walk_and_transform(ex, cond; gen = true)) end

# %% constants
# ------------

# %% body
# -------

function main(io = stdin)
    readto(target = '\n') = readuntil(io, target)
    readnum(T::Type{<:Number} = Int; dlm = isspace, kwargs...) =
        parse.(T, split(readto(), dlm; kwargs...))

    # handle IO and and stuff
    N, D = readnum()
    @generator for _ in 1:N
        x, y = readnum()
        distance(x, y) ≤ D
    end |> sum |> println
end

distance(x, y) = √(x^2 + y^2)

@static if @isdefined(Juno) || @isdefined(VSCodeServer)
    main(open(replace(@__FILE__, r"(.+)\.jl" => s"\1.in")))
else
    main()
end


Measured memory_bytes: 238608
#include <iostream>
#define MAX_T 1261
#define MAX_M 10001
#define MAX_R 1000
using namespace std;

int imos[MAX_M][MAX_T];
int rec[MAX_R][4];

void answer(int s, int t, int student) {
  int count = 0;
  for (int i = s; i < t; i++) {
    if (imos[student][i]) count++;
  }
  cout << count << endl;
}

void search(int n, int m) {
  for (int i = 0; i < n; i++) {
    if (rec[i][3] == 0) continue;
    imos[rec[i][2]][rec[i][0]]++;
    for (int j = i + 1; j < n; j++) {
      if (rec[j][1] == rec[i][1] && rec[j][3] == 0) {
	imos[rec[j][2]][rec[j][0]]--;
	break;
      }
    }
  }

  for (int i = 0; i <= m; i++) {
    for (int j = 500; j < MAX_T; j++) {
      imos[i][j] += imos[i][j - 1];
    }
  }
}

void init() {
  for (int i = 0; i < MAX_M; i++) {
    for (int j = 0; j < MAX_T; j++) {
      imos[i][j] = 0;
    }
  }
  for (int i = 0; i < MAX_R; i++) {
    for (int j = 0; j < 4; j++) {
      rec[i][j] = 0;
    }
  }
}

int main() {
  while (true) {
    int n, m;
    cin >> n >> m;
    if (n == 0 && m == 0) return 0;
    init();
    int r;
    cin >> r;
    for (int i = 0; i < r; i++) {
      cin >> rec[i][0] >> rec[i][1] >> rec[i][2] >> rec[i][3];
    }

    search(r, m);

    int q;
    cin >> q;
    for (int i = 0; i < q; i++) {
      int ts, te, m;
      cin >> ts >> te >> m;
      answer(ts, te, m);
    }
  }
}

Measured memory_bytes: 52344
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        boolean[] bs = new boolean[s.length()];
        boolean[] p = new boolean[s.length()];
        for (int i = 0; i < s.length(); i++) {
            if (s.charAt(i) == '0') {
                bs[i] = false;
            } else {
                bs[i] = true;
            }
            if (i % 2 == 0) {
                p[i] = false;
            } else {
                p[i] = true;
            }
        }
        int counter1 = 0;
        int counter2 = 0;
        for (int i = 0; i < bs.length; i++) {
            if (bs[i] != p[i]) {
                counter1++;
            } else {
                counter2++;
            }
        }
        System.out.println(Math.min(counter1, counter2));
        sc.close();
    }
}

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

using namespace std;

#define fi first
#define se second
#define pb push_back
#define sz(x) ((int) x.size())
#define all(x) (x).begin(), (x).end()
#define re return
#define mp make_pair
#define makeunique(x) sort(all(x)), x.resize(unique(all(x)) - x.begin())
#define endl '\n'

typedef pair<int, int> ii;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<ll> vll;
typedef vector<string> vs;

template <class T> T abs (T x) { re x > 0 ? x : -x; }
template <class T> T sqr (T x) { re x * x; }

const double pi = acos(-1.);
const ll inf = 1e18 + 7;
const int N = 3e5 + 17;

int n, m;
int x[N], y[N], r[N];

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	cin >> n;
	ll cur = 0;
	for (int i = 0; i < n; i++) {
		cin >> x[i] >> y[i];
	}
	reverse(x, x + n), reverse(y, y + n);

	for (int i = 0; i < n; i++) {
		cin >> x[i] >> y[i];
		r[i] = (y[i] - (x[i] + cur) % y[i]) % y[i];
		cur += r[i];
	}
//	for (int i = 0; i < n; i++) cout << x[i] << " " << y[i] << " " << r[i] << endl;
	cout << cur << endl;
}

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

int mod = 1000000007;

int N;
string a,b;
int main () {
    cin >> N >> a >> b;
    long long int cnt = ( a[0] != b[0] ? 6 : 3 );

    for(int i=1; i<N; i++) {
        if( a[i] == a[i-1] ) continue;
        if( a[i-1] == b[i-1] ) cnt *= 2;
        else if( a[i] != b[i] ) cnt *= 3;
        cnt %= mod;
    }
    cout << cnt << endl;
    return 0;
}


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

int n, m, ans, a[200005], b[200005];
int main() {
	cin >> n;
	for(int i=0; i<n; i++) scanf("%d%d", &a[i], &b[i]);
	sort(a, a+n);
	sort(b, b+n);
	m = n/2;
	ans = b[m] - a[m] + 1;
	if(n%2==0) ans += b[m-1] - a[m-1];
	cout << ans;
	return 0;
}

Measured memory_bytes: 5236
#include<bits/stdc++.h>
using namespace std;
int main(void)
{
    int N, K;
    string S;
    cin >> N >> K >> S;
    K -= 1;
    if (S[K] == 'A') S[K] = 'a';
    else if (S[K] == 'B') S[K] = 'b';
    else S[K] = 'c';

    cout << S << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();

    for(int i = 1; i <=n; i ++){
      int x = i;
      if(x % 3 == 0){
        System.out.print(" " + i);
      }else{
        while(true){
          if(x % 10 == 3){
            System.out.print(" " + i);
            break;
          }
          x /= 10;
          if(x == 0){
            break;
          }
        }
      }
    }
    System.out.println();
  }
}

Measured memory_bytes: 28256
#include<stdio.h>

int main(void)
{
	int b1,b2,b3;


	scanf("%d %d %d",&b1,&b2,&b3);

	if (b1==1&&b2==1&&b3==0||b1==0&&b2==0&&b3==1){
		printf("Open\n");
		}
	else {
		printf("Close\n");
		}

	return 0;
}

Measured memory_bytes: 584
/* C++14 (Clang 3.8.0) for AtCoder */

#include <iostream>
#include <vector>
#include <string>
// #include <cmath>
// #include <math.h>
// #include <map>
// #include <algorithm>

namespace AtCoder {
	using Str = std::vector<std::string>;
	using Num = std::vector<int>;
	using BigNum = std::vector<long long>;

	class InputData {
	public:
		void getInput(void);
		void skipInput(void);
		Str getStr(void);
		Num getNum(void);
		BigNum getBigNum(void);
	private:
		Str str;
		Num num;
		BigNum bNum;
	};
	Str AtCoder::InputData::getStr(void) {
		return this->str;
	}
	Num AtCoder::InputData::getNum(void) {
		return this->num;
	}
	BigNum AtCoder::InputData::getBigNum(void) {
		return this->bNum;
	}
	void AtCoder::InputData::skipInput(void) {
		std::string buf = "";
		std::getline(std::cin, buf);
	}
	void AtCoder::InputData::getInput(void) {
		this->str.clear();
		this->num.clear();
		this->bNum.clear();

		std::string buf = "", row = "";
		std::getline(std::cin, buf);
		for (unsigned int i = 0; i < buf.size(); i++) {
			if (' ' == buf[i]) {
				this->str.push_back(row);
				this->num.push_back(std::atoi(row.c_str()));
				this->bNum.push_back(std::atoll(row.c_str()));
				row = "";
			} else {
				row += buf[i];
			}
		}
		this->str.push_back(row);
		this->num.push_back(std::atoi(row.c_str()));
		this->bNum.push_back(std::atoll(row.c_str()));
	}

	class Ans {
	public:
		void showResult(void);
		void increment(void);
		void increment(long long);
		void decrement(void);
		void decrement(long long);
		long long getResult(void);
	private:
		long long result;
	};
	void Ans::showResult(void) {
		printf("%lld\n", this->result);
	}
	void AtCoder::Ans::increment(void) {
		this->result++;
	}
	void AtCoder::Ans::increment(long long value) {
		this->result += value;
	}
	void AtCoder::Ans::decrement(void) {
		this->result--;
	}
	void AtCoder::Ans::decrement(long long value) {
		this->result -= value;
	}
	long long AtCoder::Ans::getResult(void) {
		return this->result;
	}

	void exp(std::string* str,  Str* newStr) {
		std::string pre = *str;
		newStr->clear();
		for (unsigned int i = 0; i < pre.length(); i++) {
			newStr->push_back(pre.substr(i, 1));
		}
	}
}

int main(void) {

	AtCoder::InputData* data = new AtCoder::InputData();
	data->getInput();

	AtCoder::Str str = data->getStr();

	AtCoder::exp(&str[0], &str);

	bool ans = false;
	if (str[2] == str[3] &&
		str[4] == str[5]) {
		ans = true;
	}

	if (ans) {
		printf("Yes\n");
	} else {
		printf("No\n");
	}

	delete(data);

	return 0;
}


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

int main() {
	double a,b;
	int d,r;
	
	cin >> a >> b;
	
	double f;
	f = a / b;

	d = a / b;
	r = fmod(a,b);
	
	cout << d << " " << r <<  " " <<fixed<< setprecision(5)<< f << "\n";
}


Measured memory_bytes: 3356
import numpy as np
N, M, K = map(int, input().split())
data = np.array([list(map(int, input().split())) for _ in range(N)])

costs = data[:, 0]
knows = data[:, 1:]

mincost = 1e+9
for i in range(2 ** N):
    bits = np.array([((i >> j) & 1) for j in range(N)])
    sumknows = (knows * bits[:, None]).sum(axis=0)
    if (sumknows >= K).all():
        cost = (costs * bits).sum()
        mincost = min(mincost, cost)
print(mincost if mincost < 1e+9 else -1)

Measured memory_bytes: 27284
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;

int main() {
  long long a, b, x;
  cin >> a >> b >> x;
  cout << (b / x) - (a / x) + !(a % x) << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
using namespace std;
int main() {

	int n, mi=100,ma=-100;
	cin >> n;

	vector<int>a(n);
	for (int i = 0; i < n; i++){
		cin >> a[i];
		mi = min(a[i], mi);
		ma = max(a[i], ma);
	}

	int now = 0;
	int ans = 1000000000;

	for (int i = mi; i <= ma; i++){
		now = 0;
		for (int j = 0; j < n; j++)
			now += pow(a[j] - i, 2);

		ans = min(ans, now);
	}
	cout << ans << endl;

	

	return 0;
}

Measured memory_bytes: 256
//agrawal117
//chahatagrawal117
#include<bits/stdc++.h>
#define endl '\n'
#define mod 1000000007
typedef long long int ll;
using namespace std;
ll two(ll n)
{
    ll ans=0;
    ll x=2;
    while(true){
        if(x>n) return ans;
        ans+=(n/x);
        x*=2;
    }
}
ll five(ll n)
{
   ll ans=0;
    ll x=5;
    while(true){
        if(x>n) return ans;
        ans+=(n/x);
        x*=5;
    }  
}
ll answer (ll n)
{
    if(n==0 || n==1 || n==2) return 0LL ;
    if(n%2==1){
        ll num2=two(n);
        ll num5=five(n);
        n--;
        n/=2;
        num2-=n;
        num2-=two(n);
        num5-=five(n);
        return min(num2,num5);
    }
    else{
        n=n/2;
        ll num2=n;
        num2+=two(n);
        ll num5=five(n);
        return min(num2,num5);
    }
    
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll n;
    cin>>n;
    ll ans=answer(n);
    cout<<ans<<endl;
    
}

Measured memory_bytes: 256
#include <math.h>
#include <algorithm>  //sort,二分探索,など
#include <array>
#include <bitset>         //固定長bit集合
#include <cmath>          //pow,logなど
#include <complex>        //複素数
#include <deque>          //両端アクセスのキュー
#include <functional>     //sortのgreater
#include <iomanip>        //setprecision(浮動小数点の出力の誤差)
#include <iostream>       //入出力
#include <map>            //map(辞書)s
#include <numeric>        //iota(整数列の生成),gcdとlcm(c++17)
#include <queue>          //キュー
#include <set>            //集合
#include <stack>          //スタック
#include <string>         //文字列
#include <unordered_map>  //イテレータあるけど順序保持しないmap
#include <unordered_set>  //イテレータあるけど順序保持しないset
#include <utility>        //pair
#include <vector>         //可変長配列

using namespace std;
typedef long long ll;

#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for (ll i = (ll)(n)-1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define FORD(i, a, b) for (ll i = (a); i >= (b); i--)
#define ALL(x) (x).begin(), (x).end()  // sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size())  // sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000
#define MOD 10000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

int main() {
  int a, b, c, k;
  cin >> a >> b >> c >> k;
  vector<int> v(3);
  v[0] = a;
  v[1] = b;
  v[2] = c;
  sort(v.begin(), v.end(), greater<int>());
  REP(i, k) {
    cin >> v[i];
    v[0] = 2 * v[0];
  }
  cout << v[0] + v[1] + v[2] << endl;
  return 0;
}

Measured memory_bytes: 256
# Aizu Problem 0189: Convenient Location
#
import sys, math, os, bisect

# read input:
PYDEV = os.environ.get('PYDEV')
if PYDEV=="True":
    sys.stdin = open("sample-input.txt", "rt")



while True:
    n = int(input())
    if n == 0:
        break
    L = []
    cities = set()
    for _ in range(n):
        city1, city2, weight = [int(_) for _ in input().split()]
        L.append([city1, city2, weight])
        cities.add(city1)
        cities.add(city2)
    m = len(cities)
    dist = [[2**31] * m for _ in range(m)]
    for i in range(m):
        dist[i][i] = 0
    for city1, city2, weight in L:
        dist[city1][city2] = weight
        dist[city2][city1] = weight
    for k in range(m):
        for i in range(m):
            for j in range(m):
                dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j])
    city, time = -1, 2**31
    for k in range(m):
        S = sum(dist[k])
        if S < time:
            time = S
            city = k
    print(city, time)
        

Measured memory_bytes: 7784
#include <bits/stdc++.h>
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define show(x) cout << #x << " = " << (x) << endl
#define show2(x,y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl
#define show3(x,y,z) cout << #x << " = " << (x) << ", " << #y << " = " << (y) <<  ", " << #z << " = " << (z) << endl
#define showv(v) rep(i,v.size()) printf("%d%c", v[i], i==v.size()-1?'\n':' ')
#define showv2(v) rep(j,v.size()) showv(v[j])
#define showt(t,n) rep(i,n) printf("%d%c", t[i], i==n-1?'\n':' ')
#define showt2(t,r,c) rep(j,r) showt(t[j],c)
#define showvp(p) rep(i,p.size()) printf("%d %d\n", p[i].first, p[i].second);
#define printv(v) rep(i,v.size()) printf("%d\n", v[i])
#define printt(t,n) rep(i,n) printf("%d\n", t[i])
#define incl(v,x) find(rng(v),x)!=v.end()
#define incls(s,c) s.find(c)!=string::npos
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define bit(n,k) ((n>>k)&1) // nのk bit目
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vs = vector<string>;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using vp = vector<P>;
using vt = vector<T>;
const int mod = 1000000007;
const double EPS = 1e-9;
const int INF = (1<<30)-1;
//const ll INF = (1LL<<62)-1;
#define dame { puts("No"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
//inline int in() { int x; scanf("%d",&x); return x;}
template<class T = int> inline T in() { T x; cin >> x; return (x);}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main () {
  int n, r;
  cin >> n >> r;
  if (n >= 10) cout << r << endl;
  else cout << r + 100*(10-n) << endl;
  return 0;
}

Measured memory_bytes: 256
from collections import defaultdict

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

data = defaultdict(int)
now = 0
data[0] = 1
for i in a:
    now = (now+i)%m
    data[now] += 1

ans = 0
for x in data.values():
    ans += x*(x-1)//2

print(ans)

Measured memory_bytes: 62576
#include <bits/stdc++.h>
using namespace std;
using Field = vector<string>;
//.は白, #は黒どれだけ黒に変更出来るか
int dh[4] = {1, 0, -1, 0};
int dw[4] = {0, 1, 0, -1};
int main() {
    int H;
    int W;
    cin >> H >> W;
    int allMatrix = H * W;
    int whiteMatrix = 0;
    int blackMatrix = 0;
    Field field;
    field.resize(H);
    for (int i = 0; i < H; i++) {
        cin >> field[i];
        for(int j = 0; j < W; j++) {
            if (field[i][j] == '.') {
                whiteMatrix += 1;
            } else {
                blackMatrix += 1;
            }
        }
    }
    //スタートとゴールの設定
    int sh = 0; int sw = 0; int gh = H - 1; int gw = W - 1;
    int dist[50][50];
    //スタートからの最短距離を示す示す配列。初期値は-1
    memset(dist, -1, sizeof(dist));
    dist[0][0] = 1;
    queue<pair<int, int>> que;
    que.push({0,0});
    while(!que.empty()) {
        int ch = que.front().first;
        int cw = que.front().second;
        que.pop();
        for(int i = 0; i < 4; i++) {
            int nh = ch + dh[i];
            int nw = cw + dw[i];
            if (nh >= H || nh < 0 || nw >= W || nw < 0) continue;
            if (dist[nh][nw] != -1) continue;
            if (field[nh][nw] == '#') continue;
            dist[nh][nw] = dist[ch][cw] + 1;
            que.push({nh, nw});
        }
    }
    int ans = whiteMatrix - dist[H-1][W-1];

    if (dist[H -1][W-1] == -1) {
        cout << "-1" << endl;
    } else {
        cout << ans << endl;
    }
    // cout << dist[0][2] << endl;



    // cout << dist[H-1][W-1] << endl;

    return 0;
}


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

int main() {
	int a;
	int b;
	int sum = 0;
	cin >> a >> b;
	vector<int> vec(b);
	for (int i=0; i < b; i++) {
		cin >> vec.at(i);
	}
	for (int i=0; i < b; i++) {
		sum = sum + vec.at(i);
	}
	if (a < sum) {
		cout << "-1" << endl;
	}
	else {
		cout << a - sum << endl;
	}
	return 0;
	
}

Measured memory_bytes: 3636
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <bitset>
#include <cassert>
using namespace std;
typedef long long ll;

int main() {
	int n, k; cin >> n >> k;
	string s; cin >> s;
	s = "@" + s;
	vector<int> a(n + 2);
	for (int i = 1; i <= n; i++) {
		if (s[i] == '0' && s[i] != s[i - 1]) a[i] = 1;
	}
	for (int i = 1; i <= n; i++) a[i] += a[i - 1];
	int ans = 0;
	for (int i = 1; i <= n; i++) {
		int lo = i, hi = n + 1;
		while (hi - lo > 1) {
			int mid = lo + (hi - lo) / 2;
			if (a[mid] - a[i] + (s[i] == '0') > k) hi = mid;
			else lo = mid;
		}
		ans = max(ans, hi - i);
	}
	cout << ans << endl;
	return 0;
}


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

#define pb push_back
#define mk make_pair
#define sc second
#define fr first

using namespace std;

typedef long long ll;

const long long N = (long long) 1e6 + 5;
const long long mod = (long long) 1e9 + 7;

long long n,a[N],sum,sum1;

int main () {
        cin >> n;

        for(long long i = 1; i <= 3 * n; i ++)
                cin >> a[i];

        sort(a + 1,a + n + n + n + 1);

        for(long long i = n + 1; i <= 2 * n; i ++)
                sum += a[i];

        for(long long i = n * 3 - 1; i >= n + 1; i -= 2)
                sum1 += a[i];

        cout << max(sum,sum1) << endl;
        return 0;
}


Measured memory_bytes: 4352
#include <iostream>
#include <vector>
 
using namespace std;
 
int main(){
  int N;
  double v[110] = {};
  double sum = 0.0;
  
  cin >> N;
  for(int i = 0;i<N;i++)cin >>v[i];
  for(int i = 0;i<N;i++)sum += 1.0/v[i];
  sum = 1.0/sum;
  cout << sum<<endl;
  
  return 0;
}

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

using namespace std;

int main(void) {
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<int> h(n);
  for (int i = 0; i < n; i++) {
    cin >> h[i];
  }
  vector<int> dp(n);
  dp[0] = 0;
  for (int i = 1; i < n; i++) {
    dp[i] = dp[i - 1] + abs(h[i] - h[i - 1]);
    if (i >= 2) {
      dp[i] = min(dp[i], dp[i - 2] + abs(h[i] - h[i - 2]));
    }
  }
  cout << dp.back() << endl;
	return 0;
}


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

#define rep(i,n) FOR(i,0,n)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
typedef vector<int> vi;
typedef vector<vi> vvi;

main(){
  vvi c(3,vi(3));
  rep(i,3) rep(j,3) cin >> c[i][j];

  rep(i,2) rep(j,2)
    if(c[i][j] - c[i][j+1] != c[i+1][j] - c[i+1][j+1]){
      cout << "No\n";
      return 0;
    }

  cout << "Yes\n";
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
const double eps = 1e-8;
const int NINF = 0xc0c0c0c0;
const int INF  = 0x3f3f3f3f;
const ll  mod  = 1e9 + 7;
const ll  maxn = 1e6 + 5;
const int N = 2e5 + 5;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin>>n;
	unordered_map<int,int>M;
	ll ans=0;
	for(int i=1;i<=n;i++){
		int x;cin>>x;
		M[-x-i]++;
		if(M.count(x-i)) ans+=M[x-i];
	}
	cout<<ans<<'\n';
	return 0;
}


Measured memory_bytes: 11244
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, x, n) for (int i = x; i < (n); i++)
#define all(n) begin(n), end(n)
struct cww
{
    cww()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
} star;
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<char> vchar;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template <typename T, typename... Ts>
auto make_v(size_t a, Ts... ts)
{
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }

template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v)
{
    for (auto &e : t)
        fill_v(e, v);
}
int N,M;
vvint graph,g;
struct edge
{
    long long to, cost;
};
using P = pair<int, int>;
int V;
const int MAX_V = 1e5 + 1;


vint dist;

int main()
{
    
    cin>>N>>M;
    int u,v;

    dist.resize(3*MAX_V+1);
    fill_v(dist,INT_MAX/2);
    g.resize(3*MAX_V+1);
    for (size_t i = 0; i < M; i++)
    {
        cin>>u>>v;
        u--;v--;
        for (size_t j = 0; j < 3; j++)
        {
            g[u+j*MAX_V].push_back(v+((j+1)%3)*MAX_V);
        }
        
    }
    int S,T;
    cin>>S>>T;
    S--;T--;
    dist[S]=0;
    queue<int> q;
    q.push(S);
    while(!q.empty())
    {
        int cur = q.front();
        q.pop();
        for (auto &&i : g[cur])
        {
            if(dist[cur]+1<dist[i])
            {
                q.push(i);
                dist[i]=dist[cur]+1;
            }
            
        }
        
    }
    if(dist[T]>=INT_MAX/2)
    cout<<-1;
    else
    cout<<dist[T]/3;

    return 0;
}

Measured memory_bytes: 17792