akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

#define sz(x) ((int)(x).size())
#define in(x) int x;cin>>x
#define inn(x, y) int x,y;cin>>x>>y
#define innn(x, y, z) int x,y,z;cin>>x>>y>>z
#define bit(n) (1<<(n))

#define out(x) cout<<(x)<<endl;
#define outt(x,y) cout<<(x)<<" "<<(y)<<endl;
#define err(x) cerr<<(x)<<endl;
#define errr(x,y) cerr<<(x)<<" "<<(y)<<endl;
#define errrr(x,y,z) cerr<<(x)<<" "<<(y)<<" "<<(z)<<endl;

#define rep(i,n) for (int i=0;i<(n);i++)
#define repp(i,n) for (int i=1;i<=(n);i++)
#define reppp(j, i, n) for (int j=i+1; j<n; j++)

#define lim5 200010
#define lim9 1000000010

#define deg(rad) (((rad)/2/M_PI)*360)
#define mid(min, max) ((min + max) / 2)

int main() {
    inn(s, w);
    out(w >= s ? "unsafe" : "safe");
    return 0;
}


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

int main() {
  
  int n;
  std::cin >> n;
  
  string words[n];
  for (int i = 0; i < n; i++) {
    std::cin >> words[i];
  }
  
  for (int i = 1; i < n; i++) {
    // std::cout << words[i - 1] << '\n';
    // std::cout << words[i - 1].substr(words[i - 1].size() - 1, 1) << '\n';
    // std::cout << words[i].substr(0, 1) << '\n';
    if (words[i - 1].substr(words[i - 1].size() - 1, 1) != words[i].substr(0, 1)) {
      std::cout << "No" << endl;
      return 0;
    } else {
      for (int j = 0; j < i; j++) {
        if (words[i] == words[j]) {
          std::cout << "No" << endl;
          return 0;
        }
      }
    }
  }
  std::cout << "Yes" << '\n';
  
  return 0;
}


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

string str[2][10],s,e;
int n,ans;

void bfs(string S,int cnt){
	if(S==e) ans=min(ans,cnt);
	else if(S.size()>=e.size())return;
	cnt++;
	rep(i,n){
		string tmp;
		rep(j,S.size()){
			if(j+str[0][i].size()-1<S.size()&&S.substr(j,str[0][i].size())==str[0][i]){
				tmp+=str[1][i];
				j+=str[0][i].size()-1;
			} else tmp.push_back(S[j]);
		}
		if(tmp!=S)bfs(tmp,cnt);
	}
}

int main(){
	while(cin>>n,n){
		rep(i,n)cin>>str[0][i]>>str[1][i];
		cin>>s>>e;
		ans=1000;
		bfs(s,0);
		if(ans==1000)ans=-1;
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 1216
// 1608
#include <iostream>
#include <vector>
using namespace std;

void MergeSort(vector<int> &A, int left, int right){
	
	if(left >= right)
		return;

	int mid = left+(right-left)/2;
	MergeSort(A, left, mid);
	MergeSort(A, mid+1, right);

	vector<int> B,C;
	
	for(int i=left;i<=mid;i++)
		B.push_back(A[i]);
	for(int j=mid+1;j<=right;j++)
		C.push_back(A[j]);
	
	int i=0, j=0;
	for(int k=left;k<=right;k++){
		if(i == B.size())
			A[k] = C[j++];
		else if(j == C.size())
			A[k] = B[i++];
		else if(B[i] <= C[j])
			A[k] = B[i++];
		else
			A[k] = C[j++];
	}
}

int main(){
	
	while(1){
		int n, num;
		vector<int> grade;
		cin>>n;

		if(n == 0)
			break;

		for(int i=0;i<n;i++){
			cin>>num;
			grade.push_back(num);
		}

		MergeSort(grade, 0, n-1);

		int dif = grade[1]-grade[0];
		for(int i=1;i+1<n;i++)
			if(grade[i+1]-grade[i] < dif)
				dif = grade[i+1]-grade[i];

		cout<<dif<<endl;
	}

	return 0;
}

Measured memory_bytes: 3096
#include <iostream>

using namespace std;

int board[100][100],w,h,xg,yg;

bool f(int y,int x,int color){

	board[y][x] = -1;

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

	if(y == yg - 1 && x == xg -1) return true;

	for(i = 0;i < 4;i++){

		if(y + dy[i] > -1 && y + dy[i] < h && x + dx[i] > -1 && x + dx[i] < w){

			if(board[y+dy[i]][x+dx[i]] == color){

				if(f(y+dy[i],x+dx[i],color)) return true;

			}

		}

	}

	return false;

}

int main(){

	int xs,ys,n,i,j,k,c,d,x,y;

	while(cin >> w >> h && (w != 0 && h != 0)){

		for(j = 0;j < 100;j++){

			for(i = 0;i < 100;i++){

				board[j][i] = -1;

			}

		}

		cin >> xs >> ys;

		cin >> xg >> yg;

		cin >> n;

		for(i = 0;i < n;i++){

			cin >> c >> d >> x >> y;

			x -= 1;

			y -= 1;

			if(d == 0){

				for(j = 0;j < 2;j++){

					for(k = 0;k < 4;k++){

						board[y+j][x+k] = c;

					}

				}

			}

			else if(d == 1){

				for(j = 0;j < 2;j++){

					for(k = 0;k < 4;k++){

						board[y+k][x+j] = c;

					}

				}

			}

		}

		if(board[ys - 1][xs - 1] != -1){

			if(f(ys - 1,xs -1,board[ys - 1][xs - 1])) cout << "OK" << endl;

			else cout << "NG" << endl;

		}

		else cout << "NG" << endl;

	}

	return 0;

}

Measured memory_bytes: 0
#include <cstdio>
#include <algorithm>
#include <vector>
#include <queue>

using namespace std;

template <class T>
using lp_queue=priority_queue<T, deque<T>, greater<T>>;

using Weight=long long;
static const Weight INF=1LL<<57;

struct Edge {
    size_t src, dst;
    Weight weight;
    Edge() {}
    Edge(size_t src, size_t dst, Weight weight=1):
        src(src), dst(dst), weight(weight)
    {}
};

bool operator<(const Edge &e, const Edge &f) {
    if (e.weight != f.weight) {
        return e.weight > f.weight;
    } else {
        return e.src!=f.src? e.src<f.src : e.dst<f.dst;
    }
}

using Edges=vector<Edge>;
using Vertex=vector<Edge>;
using Graph=vector<Vertex>;

void join(Graph &g, size_t s, size_t d, Weight w=1) {
    // non-directed
    g[s].push_back(Edge(s, d, w));
    g[d].push_back(Edge(d, s, w));
}

void connect(Graph &g, size_t s, size_t d, Weight w=1) {
    // directed
    g[s].push_back(Edge(s, d, w));
}

vector<size_t> tsort(const Graph &g) {
    /* Kahn */
    // returns lexico-smallest one.
    // if impossible, returns empty vector.
    size_t V=g.size();
    vector<size_t> indeg(V);

    for (const Vertex &v: g)
        for (const Edge &e: v)
            ++indeg[e.dst];

    lp_queue<size_t> q;
    for (size_t i=0; i<V; i++)
        if (!indeg[i]) q.push(i);

    vector<size_t> ord(V);
    for (size_t k=0; !q.empty(); ++k) {
        int v=q.top(); q.pop();
        ord[k] = v;
        for (const Edge &e: g[v])
            if (!--indeg[e.dst]) q.push(e.dst);
    }
    return *max_element(indeg.begin(), indeg.end())? vector<size_t>():ord;
}

int main() {
    size_t V, E;
    scanf("%zu %zu", &V, &E);

    Graph g(V);
    for (size_t i=0; i<E; ++i) {
        size_t s, t;
        scanf("%zu %zu", &s, &t);

        connect(g, s, t);
    }

    vector<size_t> ord=tsort(g);

    for (size_t v: ord)
        printf("%zd\n", v);

    return 0;
}

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

int main(){
    int h, w;
    cin >> h >> w;

    char p[105][105];
    REP(i, h){
        REP(j, w){
            cin >> p[i][j];
        }
    }

    REP(i, h){
        REP(j, w){
            cout << p[i][j];
         }
        cout << endl;
        REP(j, w){
            cout << p[i][j];
        }
        cout << endl;
    }

    return 0;
}


Measured memory_bytes: 256
from itertools import*
from math import*
from collections import*
from heapq import*
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf = 10**18
mod = 10**9+7
from functools import reduce
import sys
sys.setrecursionlimit(10**7)

H,W,A,B = map(int,input().split())
fac = [0]*(H+W)
finv = [0]*(H+W)
inv = [0]*(H+W)
fac[0]=fac[1]=1
finv[0]=finv[1]=1
inv[1]=1
for i in range(2,H+W):
        fac[i] = fac[i-1] * i % mod
        inv[i] = mod - inv[mod%i]*(mod//i)%mod
        finv[i] = finv[i-1]*inv[i]%mod
def comb(n,r):
    if n < r:
        return 0
    if n < 0 or r < 0 :
        return 0
    return fac[n]*(finv[r]*finv[n-r]%mod)%mod
ans = 0
for x in range(W-B):
    if x == 0:
        ans += ((comb(H-A-1+B+x,B+x))*comb(A+W-1-B-x,A))
    else:
        ans += ((comb(H-A-1+B+x,B+x)-comb(H-A-1+B+x-1,B+x-1))*comb(A+W-1-B-x,A))
    ans %= mod
print(ans)

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

int main() {
  string S;
  cin >> S;
  int N;
  N=S.size();
  bool H=false;
  bool I=false;

  for (int i=0; i<N; i++) {
    if (i%2==0) {
      if (S.at(i)=='h') {
        H = true;
      }
      else {
        H=false;
        break;
      }
    }
    if (i%2==1) {
      if (S.at(i)=='i') {
        I = true;
      }
      else {
        I=false;
        break;
      }
    }
  }
  if (N%2==0) {
  if (H==true && I==true) {
  cout << "Yes" << endl;
  }
  else {
  cout << "No" << endl;
  }
  }
  else if(N%2==1) {
    cout << "No" << endl;
  }
}

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

#define ll long long

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

	vector<vector<int>> graph(n);
	for (int i = 0; i < n - 1; i++)
	{
		int u, v;
		cin >> u >> v;

		graph[u - 1].push_back(v - 1);
		graph[v - 1].push_back(u - 1);
	}

	vector<ll> x(n);
	for (int i = 0; i < queries; i++)
	{
		int p, v;
		cin >> p >> v;

		x[p - 1] += (ll)v;
	}

	vector<bool> visited(n);
	visited[0] = true;

	queue<int> q;
	q.push(0);

	while (!q.empty())
	{
		int cur = q.front();
		q.pop();

		vector<int>::iterator i;
		for (i = graph[cur].begin(); i != graph[cur].end(); i++)
		{
			if (!visited[*i])
			{
				visited[*i] = true;
				q.push(*i);
				x[*i] += x[cur];
			}
		}
	}

	for (int i = 0; i < n; i++)
	{
		cout << x[i] << " ";
	}

	cout << endl;
}

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

using namespace std;
typedef long long  ll;
#define rep(i,s,n)for(ll i = s;i<n;i++)

static const int max_size = 100;

int abs(int x) {
	if (x < 0) {
		x = -x;
	}
	return x;
}
int max(int x, int y) {
	if (x < y) {
		x = y;
	}
	return x;
}
int main() {
	int N, Z, W;
	cin >> N >> Z >> W;
	int a[2000];
	rep(i, 0, N) {
		cin >> a[i];
	}

	int score = 0;
	if (N == 1) {
		score = abs(a[N-1] - W);
	}
	else {
		score = max(abs(a[N-1] - W), abs(a[N - 1] - a[N - 2]));
	}
	cout << score << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef struct { double x,y;} point;

double nai(point a,point b){ return a.x*b.x+a.y*b.y; }

int main(){
point p1,p2;
double x,y;
cin>>x>>y;
p1.x=x;
p1.y=y;
cin>>x>>y;
p2.x=x;
p2.y=y;
point vec={p2.x-p1.x , p2.y-p1.y};
//point e={vec.x/sqrt(nai(vec,vec)) , vec.y/sqrt(nai(vec,vec))};
int q;
cin>>q;
for(int i=0;i<q;i++){
cin>>x>>y;
point p;
p.x=x-p1.x;
p.y=y-p1.y;
point j={p.x*vec.x+p.y*vec.y,vec.x*p.y-vec.y*p.x};
if(j.y>0){
cout<<"COUNTER_CLOCKWISE"<<endl;
}else if(j.y<0){
cout<<"CLOCKWISE"<<endl;
}else{
if(j.x<0){
cout<<"ONLINE_BACK"<<endl;
}else if(nai(p,p)>nai(vec,vec)){
cout<<"ONLINE_FRONT"<<endl;
}else{
cout<<"ON_SEGMENT"<<endl;
}

}


}
return 0;
}



Measured memory_bytes: 3232
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <numeric>
#include <math.h>
#include <algorithm>
#include <functional>
#include <string>
#include <array>
#include <vector>
#include <list>
#include <stack>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <deque>
#include <queue>
#include <complex>
#define full(c) c.begin(), c.end()
#define vector2d(name,type,h,w,init) vector<vector<type>> name(h,vector<type>(w,init)) 
const int PRIME = 1000000007;
const int INT_INF = 2147483647;
const long long int LL_INF = 9223372036854775807;
const double PI = acos(-1);
const double EPS = 0.000000001;
typedef unsigned long long int ull;
typedef long long int ll;
using namespace std;

int main(){
	//ios_base::sync_with_stdio(false);
	//cin.tie(NULL);
	ll i, N, T, ct, nt, X = 0;
	cin >> N >> T;
	cin >> ct;
	for (i = 1; i < N; i++){
		cin >> nt;
		X += min(nt - ct, T);
		ct = nt;
	}
	X += T;
	cout << X << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using LL = long long int;
#define incID(i, l, r) for(int i = (l)    ; i <  (r); ++i)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); --i)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); ++i)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); --i)
#define inc(i, n)  incID(i, 0, n)
#define dec(i, n)  decID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec1(i, n) decII(i, 1, n)
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))
#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define MT make_tuple
#define FI first
#define SE second
#define FR front()
#define BA back()
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
auto setmin   = [](auto & a, auto b) { return (b <  a ? a = b, true : false); };
auto setmax   = [](auto & a, auto b) { return (b >  a ? a = b, true : false); };
auto setmineq = [](auto & a, auto b) { return (b <= a ? a = b, true : false); };
auto setmaxeq = [](auto & a, auto b) { return (b >= a ? a = b, true : false); };
#define SI(v) static_cast<int>(v.size())
#define RF(e, v) for(auto & e: v)
#define until(e) while(! (e))
#define if_not(e) if(! (e))
#define ef else if
#define UR assert(false)
#define IN(T, ...) T __VA_ARGS__; IN_(__VA_ARGS__);
void IN_() { };
template<typename T, typename ... U> void IN_(T &  a, U &  ... b) { cin >> a; IN_(b ...); };
template<typename T                > void OUT(T && a            ) { cout << a << endl; }
template<typename T, typename ... U> void OUT(T && a, U && ... b) { cout << a << " "; OUT(b ...); }

// ---- ----

int main() {
	IN(int, n);
	map<LL, LL> mp;
	LL s = 0;
	inc(i, n) { IN(int, a); mp[a]++; s += a; }
	
	IN(int, q);
	inc(qq, q) {
		IN(LL, b, c);
		LL x = mp[b];
		s += (c - b) * x;
		mp.erase(b);
		mp[c] += x;
		OUT(s);
	}
}


Measured memory_bytes: 7528
import java.util.Scanner;

enum Type{
	SAME,
	A_BIG,
	B_BIG
};

public class Main {

	public static final int BIG_NUM  = 2000000000;
	public static final int MOD  = 1000000007;

	public static void main(String[] args) {

		Scanner scanner = new Scanner(System.in);

		int N = scanner.nextInt();
		String TARO,HANAKO;
		int score_TARO = 0,score_HANAKO = 0;

		for(int loop = 0; loop < N; loop++){

			TARO = scanner.next();
			HANAKO = scanner.next();

			switch(compString(TARO,HANAKO)){
			case SAME:
				score_TARO += 1;
				score_HANAKO += 1;
				break;
			case A_BIG:
				score_TARO += 3;
				break;
			case B_BIG:
				score_HANAKO += 3;
				break;
			}
		}

		System.out.printf("%d %d\n", score_TARO,score_HANAKO);
	}

	//A基準で比較する関数
	public static Type compString(String A,String B){
		int a_index = 0,b_index = 0;

		while(a_index < A.length() && b_index < B.length() && A.charAt(a_index) == B.charAt(b_index)){
			a_index++;
			b_index++;
		}

		if(a_index < A.length() && b_index < B.length()){
			if(A.charAt(a_index) > B.charAt(b_index)){
				return Type.A_BIG;
			}else{
				return Type.B_BIG;
			}

		}else if(a_index < A.length() && b_index == B.length()){
			return Type.A_BIG;
		}else if(a_index == A.length() && b_index < B.length()){
			return Type.B_BIG;
		}else{
			return Type.SAME;
		}
	}
}


Measured memory_bytes: 30124
//{
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double lf;
typedef pair<ll,ll> ii;
#define REP(i,n) for(ll i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define FILL(i,n) memset(i,n,sizeof i)
#define X first
#define Y second
#define SZ(_a) (int)_a.size()
#define ALL(_a) _a.begin(),_a.end()
#define pb push_back
#ifdef brian
#define debug(...) do{\
    fprintf(stderr,"%s - %d (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
    _do(__VA_ARGS__);\
}while(0)
template<typename T>void _do(T &&_x){cerr<<_x<<endl;}
template<typename T,typename ...S> void _do(T &&_x,S &&..._t){cerr<<_x<<" ,";_do(_t...);}
template<typename _a,typename _b> ostream& operator << (ostream &_s,const pair<_a,_b> &_p){return _s<<"("<<_p.X<<","<<_p.Y<<")";}
template<typename It> ostream& _OUTC(ostream &_s,It _ita,It _itb)
{
    _s<<"{";
    for(It _it=_ita;_it!=_itb;_it++)
    {
        _s<<(_it==_ita?"":",")<<*_it;
    }
    _s<<"}";
    return _s;
}
template<typename _a> ostream &operator << (ostream &_s,vector<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,set<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a,typename _b> ostream &operator << (ostream &_s,map<_a,_b> &_c){return _OUTC(_s,ALL(_c));}
template<typename _t> void pary(_t _a,_t _b){_OUTC(cerr,_a,_b);cerr<<endl;}
#define IOS()
#else
#define debug(...)
#define pary(...)
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#endif // brian
//}


const ll MAXn=1e5+5,MAXlg=__lg(MAXn)+2;
const ll MOD=1000000007;
const ll INF=ll(1e15);

map<ll,ll> mp;

int main()
{
    IOS();
    // C
    ll n,k;
    cin>>n>>k;
    REP(i,n)
    {
      ll t;
      cin>>t;
      mp[t]++;
    }
    vector<ll> dt;
    for(auto tmp:mp)dt.pb(tmp.Y);
    sort(ALL(dt));
    ll tt=0;
    for(int i=0;SZ(dt)-i>k;i++)tt+=dt[i];
    cout<<tt<<endl;
}


Measured memory_bytes: 14964
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define rep(i, n); for(ll i = 0; i < (ll)n; i++)
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() {
  ll n; cin >> n;
  vector<ll> v(n);
  rep(i, n)
    cin >> v.at(i);
  ll cnt=0;
  
  rep(i, n){
    if(v.at(i) != i+1)
      cnt++;
  }
  if(cnt == 0 || cnt == 2)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
}

Measured memory_bytes: 3612
using System;
class Program
 {
  static void Main(string[] args){
    var s1 = Console.In.ReadToEnd();
    s1 = s1.Replace(Environment.NewLine, "\r");
    s1 = s1.Trim('\r');
    string[] lines = s1.Split('\r');
    int a = int.Parse(lines[0]);
    int b = int.Parse(lines[1]);
    int c = int.Parse(lines[2]);
    int d = int.Parse(lines[3]);
    int e = int.Parse(lines[4]);
    int k = int.Parse(lines[5]);
    
    int distance = (e > a) ? e - a : a - e;
    
    if(distance <= k){
      Console.WriteLine("Yay!");
    }else{
      Console.WriteLine(":(");
    }
  }
 }

Measured memory_bytes: 13140
fun main(args: Array<String>) {
    while(true) {
        val n = readLine()!!.toInt()
        if(n == 0) break
        solve(n)
    }
}

private fun solve(n: Int) {
    val arr = Array(n) {
        val (s, p, q, r) = readLine()!!.split(" ").map { it.toInt() }
        listOf(s, p, q, r, 4 * p + 9 * q + 4 * r)
    }
    val (p, q, r, c) = readLine()!!.split(" ").map { it.toInt() }
    val ans = arr.filter {
        it[1] <= p && it[2] <= q && it[3] <= r && it[4] <= c
    }.map {
        it.first()
    }.joinToString("\n")
    if (ans.isEmpty()) {
        println("NA")
    } else {
        println(ans)
    }
}


Measured memory_bytes: 74756
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<functional>
#include<queue>
#include<algorithm>
#include<complex>
#include<cstdlib>
#include<cctype>

#define DBG cout << '!' << endl;
#define REP(i,n) for(int i = 0;i < (n);i++)
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int i = 0;i < (n);i++)cout << v[i] << ' ';cout << endl << endl;}
#define SHOW2d(v,i,j) {for(int a = 0;a < i;a++){for(int b = 0;b < j;b++)cout << v[a][b] << ' ';cout << endl;}cout << endl;}
#define ALL(v) v.begin(),v.end()

using namespace std;

typedef long long ll;
typedef vector<int> iv;
typedef vector<iv> iiv;
typedef vector<string> sv;

ll mozi[26];

int main()
{
	string str;
	
	cin >> str;
	REP(i,str.size())
	{
		mozi[str[i] - 'a']++;
	}
	
	
	//SHOW1d(mozi,26);
	ll tmp = str.size();
	ll ans = tmp * (tmp - 1) / 2 + 1;
	
	REP(i,26)
	{
		if(mozi[i] > 1)
		{
			ans -= mozi[i] * (mozi[i] - 1) / 2;
		}
	}	
	
	
	
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 640
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val h = sc.nextLong()

    println(abc153d(h))
}

private fun abc153d(h: Long): Long {
  if (h == 1L) return 1L

  var tmp = h
  var count = 0L
  while (tmp != 1L) {
    tmp /= 2L
    count++
  }

  var ans = 1L
  for (i in 1..count) {
    ans = ans * 2L + 1
  }

  return ans
}


Measured memory_bytes: 31388
#define REP(i,n) for(int i=0; i<(int)(n); i++)

#include <iostream>
#include <queue>
#include <cstdio>
#include <set>

using namespace std;

inline int getInt(){ int s; scanf("%d", &s); return s; }
inline char getChar() { char s[8]; scanf("%s", s); return s[0]; }

class BIT{
  vector<int> bit;
public:
  BIT(int n) : bit(n + 1) {}
  void add(int idx, int val){
    idx++;
    while(idx < (int)bit.size()){
      bit[idx] += val;
      idx += idx & -idx;
    }
  }
  int sum(int i) const{
    int s = 0;
    i++;
    while(i > 0){
      s += bit[i];
      i -= i & -i;
    }
    return s;
  }
};

int dp[2048][2048];

int main(){
  const int n = getInt();
  vector<pair<char, int> > v(n + n);
  vector<int> w(n);
  vector<int> b(n);

  REP(i,n+n){
    v[i].first = getChar();
    v[i].second = getInt() - 1;

    if(v[i].first == 'W'){
      w[v[i].second] = i;
    }else{
      b[v[i].second] = i;
    }
  }

  const int inf = 1 << 30;
  REP(i,n+1) REP(j,n+1) dp[i][j] = inf;
  dp[0][0] = 0;

  vector<BIT> bits(n + 1, BIT(n + n));

  for(int i = 1; i <= n; i++){
    for(int j = 0; j < i; j++)
      bits[i].add(w[j], 1);
  }

  REP(i,n+1){
    BIT &bit = bits[i];
    REP(j,n+1){
      const int tot = i + j;

      if(i != n){
	// white
	const int idx = w[i];
	const int pre = bit.sum(idx);
	dp[i + 1][j] = min(dp[i + 1][j], dp[i][j] + tot - pre);
      }
      if(j != n){
	// black
	const int idx = b[j];
	const int pre = bit.sum(idx);
	dp[i][j + 1] = min(dp[i][j + 1], dp[i][j] + tot - pre);
	bit.add(b[j], 1);
      }
    }
  }

  printf("%d\n", dp[n][n]);

  return 0;
}

Measured memory_bytes: 48000
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<iomanip>
#include<bitset>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())

const int MAX = 510000;
const int MOD = 1000000007;

int main(){
  ll N; cin >> N;
  vector<P> a(N);
  rep(i,N) cin >> a[i].first >> a[i].second;

  double ans = 0.0;
  ll cnt = 0;
  vector<ll> v;
  rep(i, N) v.pb(i);
  do{
    cnt++;
    rep(i , N - 1){
      ll d = abs(a[v[i + 1]].first - a[v[i]].first) * abs(a[v[i + 1]].first - a[v[i]].first)
      + abs(a[v[i + 1]].second - a[v[i]].second) * abs(a[v[i + 1]].second - a[v[i]].second);
      ans += sqrt(d * 1.0);
    }
  }while(next_permutation(v.begin(), v.end()));
  ans = ans / (cnt * 1.0);
  cout << fixed << setprecision(15) << ans << endl;
}


Measured memory_bytes: 256
//65 - A 90 - Z 97 - a 122 - z
#include <bits/stdc++.h>
using namespace std;

typedef long long LL;

LL res;

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

    int n, k;
    cin >> n >> k;
    for(int i = 0; i < n; i++)
    {
        int x; cin >> x;
        res += 2LL * (LL)min(abs(x - k), x);
    }
    cout << res;

    return 0;
}


Measured memory_bytes: 256
use io::*;
use proconio::{fastout, input};
use std::*;

#[fastout]
fn main() {
    input! {
        N: usize,
        D: usize,
        v: [[f64; 2]; N]
    }
    let res = v
        .iter()
        .map(|v| (v[0].powi(2) + v[1].powi(2)).sqrt())
        .filter(|&x| x <= D as f64)
        .count();
    println!("{}", res);
}


Measured memory_bytes: 15772
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int n;

char max(char a, char b) { return a > b ? a : b; }

char *string(char *t, char add){
  int n = strlen(t);
  t[n] = add;
  t[n + 1] ='\0';
  return t;
}

void dfs(char *s, char mx){
  if(strlen(s) == n){
    printf("%s\n", s);
    return;
  }
  for(char c = 'a'; c <= mx + 1; c++){
    char t[1000];
    strcpy(t, s);
    dfs(string(t, c), max(c, mx));
  }
}

int main(){
  scanf("%d", &n);
  dfs("a", 'a');
  return 0;
}

Measured memory_bytes: 1408
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#define _USE_MATH_DEFINES
#include <math.h>
#include <iomanip>
#include <stdio.h>
#include <numeric>
#include <cmath>
#include <limits>
#include <bitset> 
#include <iterator> 
#include <map>
#include <queue>
#include <set>
#include<deque>
#define rep(i,n) for(ll i=0;i<(n); ++i)
#define per(i,n) for(ll i=n-1;i>=0; --i)
#define all(x) (x).begin(),(x).end()
#define _GLIBCXX_DEBUG
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
typedef long long ll;
ll MOD = 1000000007;
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}

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

	ll n;
	cin >> n;
	vector<ll>a(n);
	deque<ll>p;
	rep(i, n)cin >> a[i];
	p.push_back(a[0]);
	for (ll i = 1; i < n;i++) {
		if (n % 2 == 1) {
			if (i % 2 == 1)p.push_back(a[i]);
			else p.push_front(a[i]);
		}
		else {
			if (i % 2 == 1)p.push_front(a[i]);
			else p.push_back(a[i]);
		}
	}
	rep(i, n)cout << p[i] << " ";
	cout << endl;
}


Measured memory_bytes: 5376
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(int)(n); i++)
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
template<class T> inline bool chmin(T& a, T b){if (a>b){a = b; return true;}return false;}
template<class T> inline bool chmax(T& a, T b){if (a<b){a = b; return true;}return false;}
/*
void chmin(ll a, ll b){if (a>b){a = b; return true;}return false;}
void chmax(ll a, ll b){if (a<b){a = b; return true;}return false;}
*/

const ll MOD = 1000000007;
const ll INF = 9999999999;

int main() {
  string s; cin >>s;
  int a,b;
  if (s.size() % 2 == 0){
    b = s.size()/2; a = b-1;
    // 0 1 2 3: 4
  }else{
    a = s.size()/2-1; b = a+2;
    // 0 1 2 3 4: 5
  }
  
  int ans = 0;
  for (int i=0; i<=a; i++){
    if (s.at(i) != s.at(s.size()-1-i)){
      ans++;
    }
  }

  cout <<ans <<endl;
}

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

template<long long mod>
struct mint {
private:
    long long x;
public:
    mint(long long x = 0) :x((mod + x) % mod) {}
    mint(std::string &s) {
        long long z = 0;
        for (int i = 0; i < s.size(); i++) {
            z *= 10;
            z += s[i] - '0';
            z %= mod;
        }
        this->x = z;
    }
    mint& operator+=(const mint &a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint &a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint &a) {
        (x *= a.x) %= mod;
        return *this;
    }
    mint& operator/=(const mint &a) {
        long long n = mod - 2;
        mint<mod> u = 1, b = a;
        while (n > 0) {
            if (n & 1) {
                u *= b;
            }
            b *= b;
            n >>= 1;
        }
        return *this *= u;
    }
    mint operator+(const mint &a) const {
        mint res(*this);
        return res += a;
    }
    mint operator-(const mint &a) const {
        mint res(*this);
        return res -= a;
    }
    mint operator*(const mint &a) const {
        mint res(*this);
        return res *= a;
    }
    mint operator/(const mint &a) const {
        mint res(*this);
        return res /= a;
    }
    friend std::ostream& operator<<(std::ostream &os, const mint &n) {
        return os << n.x;
    }
    bool operator==(const mint &a) const {
        return this->x == a.x;
    }
};

int main() {
    int n; cin >> n;
    vector<int> a(n);
    constexpr int MOD = 1e9 + 7;
    mint<MOD> fact = 1;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        fact *= i + 1;
    }
    vector<mint<MOD>> f(n);
    f[0] = 0;
    for (int i = 1; i < n; i++) {
        f[i] = mint<MOD>(1) / (i + 1) + f[i - 1];
    }
    mint<MOD> ans = 0;
    for (int i = 0; i < n; i++) {
        ans += (f[i] + f[n - 1 - i] + 1) * a[i];
    }
    cout << ans * fact << endl;
    return 0;
}

Measured memory_bytes: 1408
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Scanner;
import java.util.StringTokenizer;
class Main {

	public static void main(String[] args) throws IOException {
		// TODO Auto-generated method stub
		MScanner s = new MScanner(System.in);
		String s1 = s.next();
		String s2 = s.next();
		boolean ans = false;
		for (int i = 0; i < s1.length(); i++) {
			if (s1.charAt(i) != s2.charAt(i)) {
				ans = true;
			}
		}
		if (ans) {
			System.out.println("No");
		} else {
			System.out.println("Yes");
		}
	}

	static class MScanner {
		StringTokenizer st;
		BufferedReader br;

		public MScanner(InputStream system) {
			br = new BufferedReader(new InputStreamReader(system));
		}

		public MScanner(String file) throws Exception {
			br = new BufferedReader(new FileReader(file));
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public int[] intArr(int n) throws IOException {
			int[] in = new int[n];
			for (int i = 0; i < n; i++)
				in[i] = nextInt();
			return in;
		}

		public long[] longArr(int n) throws IOException {
			long[] in = new long[n];
			for (int i = 0; i < n; i++)
				in[i] = nextLong();
			return in;
		}

		public int[] intSortedArr(int n) throws IOException {
			int[] in = new int[n];
			for (int i = 0; i < n; i++)
				in[i] = nextInt();
			shuffle(in);
			Arrays.sort(in);
			return in;
		}

		public long[] longSortedArr(int n) throws IOException {
			long[] in = new long[n];
			for (int i = 0; i < n; i++)
				in[i] = nextLong();
			shuffle(in);
			Arrays.sort(in);
			return in;
		}

		public Integer[] IntegerArr(int n) throws IOException {
			Integer[] in = new Integer[n];
			for (int i = 0; i < n; i++)
				in[i] = nextInt();
			return in;
		}

		public Long[] LongArr(int n) throws IOException {
			Long[] in = new Long[n];
			for (int i = 0; i < n; i++)
				in[i] = nextLong();
			return in;
		}

		public String nextLine() throws IOException {
			return br.readLine();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}

		public char nextChar() throws IOException {
			return next().charAt(0);
		}

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

		public boolean ready() throws IOException {
			return br.ready();
		}

		public void waitForInput() throws InterruptedException {
			Thread.sleep(3000);
		}
	}

	static void shuffle(int[] in) {
		for (int i = 0; i < in.length; i++) {
			int idx = (int) (Math.random() * in.length);
			int tmp = in[i];
			in[i] = in[idx];
			in[idx] = tmp;
		}
	}

	static void shuffle(long[] in) {
		for (int i = 0; i < in.length; i++) {
			int idx = (int) (Math.random() * in.length);
			long tmp = in[i];
			in[i] = in[idx];
			in[idx] = tmp;
		}
	}

}


Measured memory_bytes: 32720
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(i64 (i) = (s);(i) < (e);(i)++)
#define all(x) x.begin(),x.end()
#define let auto const

int main() {
  i64 n;
  while(cin >> n, n) {
    vector<string> f(n);
    rep(i,0,n) cin >> f[i];
    i64 now = 0;
    i64 state = 0;
    i64 ans = 0;
    for(auto& x: f) {
      if(x == "lu") {
        state ^= 1;
      }
      if(x == "ru") {
        state ^= 2;
      }
      if(x == "ld") {
        state ^= 1;
      }
      if(x == "rd") {
        state ^= 2;
      }
      if((now ^ state) == 3) {
        ans++;
        now = state;
      }
    }
    cout << ans << endl;
  }
}



Measured memory_bytes: 3156
h,w=map(int,input().split())
field=[]
nfield=[[] for i in range(h)]
for i in range(h):
  field.append(input())
def check(a,b):
  num=0
  if field[a][b]=="#":
    return
  for i in range(a-1,a+2):
    for j in range(b-1,b+2):
      try:
        if j !=-1 and i!=-1 and field[i][j]=="#":
          num+=1
      except:
        pass
  return num
for i in range(h):
  for j in range(w):
    if field[i][j]==".":
      nfield[i].append(check(i,j))
    else:
      nfield[i].append("#")
for i in range(h):
  for j in range(w):
    if j != w-1:
      print(nfield[i][j],end="")
    else:
      print(nfield[i][j])


Measured memory_bytes: 3444
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

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

    static class A {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            // 整数の入力
            int a = Integer.parseInt(in.next());
            int b = Integer.parseInt(in.next());
            int ans = 0;
            if (a + b == 3) ans = 3;
            if (a + b == 4) ans = 2;
            if (a + b == 5) ans = 1;

            // 出力
            out.println(ans);

        }

    }
}



Measured memory_bytes: 22100
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.IOException;
import java.io.InputStream;

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

    static class TaskC {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int m = in.nextInt();

            boolean[] connectedToSource = new boolean[n];
            boolean[] connectedToDest = new boolean[n];
            while (m-- > 0) {
                int x = in.nextInt() - 1;
                int y = in.nextInt() - 1;
                if (x == 0) {
                    connectedToSource[y] = true;
                } else if (x == n - 1) {
                    connectedToDest[y] = true;
                } else if (y == 0) {
                    connectedToSource[x] = true;
                } else if (y == n - 1) {
                    connectedToDest[x] = true;
                }
            }
            for (int i = 0; i < n; ++i) {
                if (connectedToDest[i] && connectedToSource[i]) {
                    out.println("POSSIBLE");
                    return;
                }
            }
            out.println("IMPOSSIBLE");
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1)
                throw new UnknownError();
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new UnknownError();
                }
                if (numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public String next() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            StringBuffer res = new StringBuffer();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isSpaceChar(c));

            return res.toString();
        }

        private boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

    }
}



Measured memory_bytes: 44980
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
typedef long long ll;
typedef double lf;
typedef pair<ll,ll> ii;
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define RST(i,n) memset(i,n,sizeof i)
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(),a.end()
#define X first
#define Y second
#define mkp make_pair
#define pb push_back
#define eb emplace_back
#define pob pop_back
#ifdef cold66
#define debug(...) do{\
    fprintf(stderr,"%s - %d (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
    _do(__VA_ARGS__);\
}while(0)
template<typename T>void _do(T &&_x){cerr<<_x<<endl;}
template<typename T,typename ...S> void _do(T &&_x,S &&..._t){cerr<<_x<<", ";_do(_t...);}
template<typename _a,typename _b> ostream& operator << (ostream &_s,const pair<_a,_b> &_p){return _s<<"("<<_p.X<<","<<_p.Y<<")";}
template<typename It> ostream& _OUTC(ostream &_s,It _ita,It _itb)
{
    _s<<"{";
    for(It _it=_ita;_it!=_itb;_it++)
    {
        _s<<(_it==_ita?"":",")<<*_it;
    }
    _s<<"}";
    return _s;
}
template<typename _a> ostream &operator << (ostream &_s,vector<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,set<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a,typename _b> ostream &operator << (ostream &_s,map<_a,_b> &_c){return _OUTC(_s,ALL(_c));}
template<typename _t> void pary(_t _a,_t _b){_OUTC(cerr,_a,_b);cerr<<endl;}
#define IOS()
#else
#define debug(...)
#define pary(...)
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#endif // cold66
//}
template<class T> inline bool chkmax(T &a, const T &b) { return b > a ? a = b, true : false; }
template<class T> inline bool chkmin(T &a, const T &b) { return b < a ? a = b, true : false; }
template<class T> using MaxHeap = priority_queue<T>;
template<class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;

const ll MAXn=1e5+5,MAXlg=__lg(MAXn)+2;
const ll MOD=1000000007;
const ll INF=0x3f3f3f3f;

int main(){
  IOS();
  ll d,n;
  cin>>d>>n;
  if( n == 100 ) n++;
  ll ans = n;
  REP(i,d) ans*=100;
  cout<<ans<<endl;
}


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

namespace Competitive
{

    internal class Solution
    {
        public int N, A, B;

        public void Run()
        {
            var line = Input.ReadIntArray();
            N = line[0];
            A = line[1];
            B = line[2];
            
            Console.WriteLine((A - B) % 2 == 0 ? "Alice": "Borys");
        }

    }

    // libs ----------
    
    // common ----------

    internal static class Input
    {
        public static int ReadInt()
        {
            string line = Console.ReadLine();
            return int.Parse(line);
        }

        public static long ReadLong()
        {
            string line = Console.ReadLine();
            return long.Parse(line);
        }

        public static int[] ReadIntArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(int.Parse).ToArray();            
        }

        public static long[] ReadLongArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(long.Parse).ToArray();
        }

        public static double[] ReadDoubleArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(double.Parse).ToArray();
        }
    }
    
    internal class Program
    {
        public static void Main(string[] args)
        {
            var s = new Solution();
            s.Run();
        }
    }
}

Measured memory_bytes: 13396
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(x),end(x)
#define show(obj) {for(auto x:obj)cout<<x<<' ';cout<<endl;}
#define line "----------"
typedef long long ll;
typedef pair<int,int> ip;
typedef pair<ll,ll> lp;
const int inf = 1001001000;
const ll INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

int main(){
	int N,M;cin>>N>>M;
	vector<int> A(N);
	rep(i,N){
		int t; cin>>t;
		A[i] = t%M;
	}
	vector<int> sum(N+1);
	map<int,int> cnt;
	++cnt[0];
	rep(i,N){
		sum[i+1] = (sum[i]+ A[i])%M;
		cnt[sum[i+1]]++;
	}
	ll ans = 0;
	for(auto x: cnt)ans += (ll)x.second*(x.second-1)/2;
	cout<<ans<<endl;
	return 0;
}

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

template <typename T> T load() { T r; cin >> r; return r; }
template <typename T> vector<T> loadMany(int n) { vector<T> rs(n); generate(rs.begin(), rs.end(), &load<T>); return rs; }

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	auto n = load<int>();
	cout << n*n*n << '\n';
}

// ほんとですか！


Measured memory_bytes: 256
#include<stdio.h>
 
int main()
{
	int n,a,b,i,j;
	long long c=0,d=0;
	scanf("%d",&n);
	
	for(i=0;i<n;i++)
	{
		scanf("%d%d",&a,&b);
		
		if(a>=c&&b>=d){
			c=a;d=b;
		}
		else{
			if((c-1)/a>(d-1)/b){
				c=(((c-1)/a)+1)*a;
				d=(((c-1)/a)+1)*b;
			}
			else{
				c=(((d-1)/b)+1)*a;
				d=(((d-1)/b)+1)*b;
			}
		}
		
//		printf("            %lld %lld\n",c,d);
	}
	printf("%lld",c+d);
}

Measured memory_bytes: 128
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.*;


public class Main {

    int N;

    private int f(int x) {
        int sum = 0;
        while(x > 0) {
            sum += x % 10;
            x /= 10;
        }

        return sum;
    }

    private void solve() {

        N = nextInt();
        int fx = f(N);

        if (N % fx == 0) {
            out.println("Yes");
        } else {
            out.println("No");
        }

    }

    public static void main(String[] args) {
        out.flush();
        new Main().solve();
        out.close();
    }

    /* Input */
    private static final InputStream in = System.in;
    private static final PrintWriter out = new PrintWriter(System.out);
    private final byte[] buffer = new byte[2048];
    private int p = 0;
    private int buflen = 0;

    private boolean hasNextByte() {
        if (p < buflen)
            return true;
        p = 0;
        try {
            buflen = in.read(buffer);
        } catch (IOException e) {
            e.printStackTrace();
        }
        if (buflen <= 0)
            return false;
        return true;
    }

    public boolean hasNext() {
        while (hasNextByte() && !isPrint(buffer[p])) {
            p++;
        }
        return hasNextByte();
    }

    private boolean isPrint(int ch) {
        if (ch >= '!' && ch <= '~')
            return true;
        return false;
    }

    private int nextByte() {
        if (!hasNextByte())
            return -1;
        return buffer[p++];
    }

    public String next() {
        if (!hasNext())
            throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = -1;
        while (isPrint((b = nextByte()))) {
            sb.appendCodePoint(b);
        }
        return sb.toString();
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

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

    public double nextDouble() {
        return Double.parseDouble(next());
    }
}

Measured memory_bytes: 22996
#include <cstdio>
#include <cmath>
#include <algorithm>

int main()
{
  int n;
  scanf("%d", &n);
  long long ss = 0;
  long long s = 0;
  long long ts = 0;
  long long t = 0;
  for (int i = 0; i < n; ++i)
  {
    long long a;
    scanf("%lld", &a);
    ss += a;
    ts += a;
    if (i & 1)
    {
      if (ss >= 0)
      {
        s += std::abs(-1 - ss);
        ss = -1;
      }
      if (ts <= 0)
      {
        t += std::abs(1 - ts);
        ts = 1;
      }
    }
    else
    {
      if (ss <= 0)
      {
        s += std::abs(1 - ss);
        ss = 1;
      }
      if (ts >= 0)
      {
        t += std::abs(-1 - ts);
        ts = -1;
      }
    }
  }
  printf("%lld\n", std::min(s, t));
  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include<algorithm>
#include<sstream>
#include<cmath>
#include<vector>
#include<iomanip>
#include<map>
#include<set>
#include<queue>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i,n) for(int i = 0; i < n;i++)
int main() {
	int k, t,a;cin >> k >> t;
	priority_queue<int> pq;
	rep(i, t) {
		cin >> a;
		pq.push(a);
	}
	cout << max(2 * pq.top() - 1 - k, 0) << endl;
}

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

int main () {

    int N, Q;
    cin >> N >> Q;

    string S;
    cin >> S;

    int cnt_ac[N];
    fill(cnt_ac, cnt_ac + N, 0);

    for (int i = 1; i < N; i++) {

        cnt_ac[i] = cnt_ac[i-1];
        
        if (S[i-1] == 'A' && S[i] == 'C') {
            cnt_ac[i]++;
        }
    }


    for (int i = 0; i < Q; i++) {
        int l, r;
        cin >> l >> r;
        l--;    r--;

        cout << cnt_ac[r] - cnt_ac[l] << endl;
    }

    return 0;
}

Measured memory_bytes: 1408