akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cmath>
#include <array>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include <cstdint>
#include <unordered_set>
#include <ctime>
#include <numeric>
#include <cstdint>

typedef long long int llint;

int main(void){

  llint n;
  std::cin >> n;

  std::set<llint> s;
  std::set<llint> primes;
  llint MAGIC = 1000000;
  for(int i=3; i<=MAGIC; i+=2){
    s.insert(i);
  }
  primes.insert(2);

  while(!s.empty()){
    llint smallest = *(s.begin());
    primes.insert(smallest);
    for(int i=smallest; i<=MAGIC; i+=smallest){
      if(s.find(i) != s.end()) s.erase(i);
    }
  }

  std::map<llint, llint> m;
  for(const auto& elem: primes){
    m[elem] = 0;
    while(n % elem == 0){
      m[elem]++;
      n/=elem;
      //std::cout << n << std::endl;
    }
    if(m[elem]==0) m.erase(elem);
  }
  if(n!=1) m[n] = 1;

  int ret = 0;
  for(const auto& elem: m){
    llint count = elem.second;
    //std::cout << "count" << count << std::endl;
    for(llint i=0; i<=MAGIC; i++){ 
      //std::cout << "count" << count << " i" << i << std::endl;
      //std::cout << ((i+1)*i)/2 << std::endl;
      if( ((i+1)*i)/2 > count){
	ret += i-1;
	break;
      }
    }
  }
  
  std::cout << ret << std::endl;
  return 0;
}


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

int main() {
  string s;cin>>s;
  string ans="";
  for(auto c:s) {
    if (c=='B') { if(ans.size()>0) ans.pop_back(); }
    else ans.push_back(c);    
  }
  cout<<ans;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <functional>
#include <string>
#include <string.h>
#include <math.h>

using namespace std;

int main(){
	char ans;
	string S;
	long long K;
	cin >> S >> K;
	int c = 0;

	while (c < S.size() && S[c] == '1')
		++c;
	if (c >= K)
		ans = '1';
	else
		ans = S[c];
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void myout(Object text){//standard output
		System.out.println(text);
	}
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		//String tmp = sc.next();
		//int tmp = sc.nextInt();
		//Long tmp = sc.nextLong();
      Long N = sc.nextLong();
      Long output = new Long(0);
      if(N <= 2){
        myout(output);
        return;
      }
      ArrayList<Long> list = getDivisorList(N);
      for(int i = 0; i < list.size(); i++){
        if(list.get(i) > Math.ceil(Math.sqrt(N))){
        	output += list.get(i) - 1;
      	}else{
          break;
        }
      }
      //myout(list);
      myout(output);
      
      /*ArrayList<Long> test = new ArrayList<Long>(100000);
      Long testout = new Long(0);
      for(int i = 1; i <= N; i++){
        if(N / i == N % i){
          test.add(new Long(i));
          testout += new Long(i);
        }
      }
      Collections.sort(test,Comparator.reverseOrder());
      myout(test);
      myout(testout);
      myout(output.equals(testout));*/
      
	}
  public static ArrayList<Long> getDivisorList(Long val){
	ArrayList<Long> list = new ArrayList<Long>();
	for(Long i = new Long(1); i * i <= val; i++){
		if(val % i == 0){
			list.add(i);
			if(i * i != val){
				list.add(val / i);
			}
		}
	}
    Collections.sort(list,Comparator.reverseOrder());
	return list;
}
}


Measured memory_bytes: 38484
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 0> { using type = T; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
template <class T> inline void chmin(T &a, const T& b) { if (b < a) a = b; }
template <class T> inline void chmax(T &a, const T& b) { if (b > a) a = b; }
/* clang-format on */

const ll INF = 1ll << 60;

struct edge_t {
  int to;
  int w;
};

int main() {
#ifdef DEBUG
  ifstream ifs("in.txt");
  cin.rdbuf(ifs.rdbuf());
#endif
  int N, M, P;
  while (cin >> N >> M >> P) {
    vec<edge_t, 2> G(N), rG(N);
    for (int i = 0; i < M; i++) {
      int a, b, c;
      cin >> a >> b >> c;
      --a;
      --b;
      c -= P;
      G[a].push_back({b, -c});
      rG[b].push_back({a, -c});
    }
    vector<bool> used(N, false);
    auto dfs = [&](auto& f, int v) {
      if (used[v]) return;
      used[v] = true;
      for (auto& e : rG[v]) f(f, e.to);
    };
    dfs(dfs, N - 1);
    int V = count(used.begin(), used.end(), true);
    vector<ll> dist(N, INF);
    dist[0] = 0;
    bool hasNegativeCycle = false;
    for (int k = 1; k <= V; k++) {
      for (int v = 0; v < N; v++) {
        for (auto& e : G[v]) {
          if (used[v] && used[e.to] && dist[v] != INF && dist[e.to] > dist[v] + e.w) {
            dist[e.to] = dist[v] + e.w;
            if (k == V) {
              hasNegativeCycle = true;
            }
          }
        }
      }
    }
    if (hasNegativeCycle) {
      cout << -1 << endl;
    } else {
      cout << max(0ll, -dist[N - 1]) << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
const int INF = 10000000;

double n,k;
void input()
{
    std::cin>>n>>k;
}

int main()
{
    input();
    double p = 0;
    //最初に出た数で場合分けをする
    for(int i=1;i<=n;i++){
        double tmp = 1/n;
        double now = i;
        while(now < k){now*=2; tmp/=2;}
        p += tmp;
    }
    std::cout<<std::setprecision(10)<<p<<std::endl;
}

Measured memory_bytes: 256
def main():
    n = int(input())
    a_s = list(map(int, input().split()))
    results = [0]*n
    a_r = reversed(a_s)
    for i, a in enumerate(a_r):
        idx = (n-1) - i
        if sum(results[idx::(idx+1)]) % 2 != a:
            results[idx] = 1
    print(sum(results))
    idxs = [str(i+1) for i, r in enumerate(results) if r == 1]
    if results:
        print(' '.join(idxs))
 
 
if __name__ == '__main__':
    main()

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

int Func(int n) {
  int sum = 0;
  while(n > 0) {
    sum += n % 10;
    n /= 10;
  }
  return sum;
}

int main() {
  int N, A, B;
  cin >> N >> A >> B;
  
  int total = 0;
  for(int i = 1; i <= N; i++) {
    int sum2 = Func(i);
    if(A <= sum2 && sum2 <= B) total += i;
  }
  
  cout << total;
}  
  

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <complex>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <cstring>
#include <stack>
#include <cmath>
#include <iomanip>
#include <sstream>
#include <cassert>

using namespace std;

typedef long long ll;
typedef ll li;
typedef pair<int,int> PI;
#define EPS (1e-10L)
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define F first
#define S second
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define SZ(a) (int)((a).size())
#define ALL(a) a.begin(),a.end()
#define CLR(a) memset((a),0,sizeof(a))
#define FOR(it,a) for(__typeof(a.begin())it=a.begin();it!=a.end();++it)
void pkuassert(bool t){t=1/t;};
int dx[]={0,1,0,-1,1,1,-1,-1};
int dy[]={1,0,-1,0,-1,1,1,-1};

int memo[600][600];
string in;

int rec(int s,int t){
  if(s==t) return 1;
  if(memo[s][t]!=-1) return memo[s][t];
  int& ret=memo[s][t]=0;
  if(in[s]!='m' || in[t-1]!='w') return 0;
  for(int i=s+1;i+1<t;++i)
    if(in[i]=='e' && rec(s+1,i) && rec(i+1,t-1))
      return ret=1;
  return 0;
}

int main(int argc, char *argv[])
{
  cin >> in;
  memset(memo,-1,sizeof(memo));
  cout << (rec(0,SZ(in))?"Cat":"Rabbit") << endl;
  return 0;
}

Measured memory_bytes: 2604
//Get Many Persimmon Trees
#include<bits/stdc++.h>
using namespace std;

#define rep(i,n) for(int i=0; i<n; i++)

int field[100][100];
int s, t;
int solve(int x, int y){
  int ret=0;
  rep(i,s)rep(j,t)ret+=field[i+x][j+y];
  return ret;
}

int main(){
  while(true){
    int N;
    cin>>N;
    if(N==0)break;
    int W, H;
    cin>>W>>H;
    memset(field, 0, sizeof(field));
    rep(i,N){
      int x, y;
      cin>>x>>y;
      field[x-1][y-1]=1;
    }
    cin>>s>>t;
    int ans=0;
    rep(i,W-s+1)rep(j,H-t+1){
      if(ans<solve(i, j))ans=solve(i, j);
    }
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 1212
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
	    int n = sc.nextInt();
      int[] m = new int[n];
      int sum = 1;
	    for(int i =0; i<n; i++) {
    	  m[i] = sc.nextInt();
    	    }
	    for(int i =1; i<n; i++) {
	    	 int c = 0;
	    	for(int j =0; j<i; j++) {
	    	 
	    	  if(m[i]>=m[j]) {c++;}
	    	   } 
	    	if(c==i) {sum++;}
	    	  
		    } 
	    	
	   
	


	    System.out.println(sum);
	}
	}

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

#define ABS(X) ((X)<0?-(X):(X))

using namespace std;

int main(void){
  int n;
  vector<int> v;
  long long ans;

  cin >> n;
  for (int i=0; i<n; i++){
    int t; cin >> t;
    v.push_back(t);
  }
  sort(v.begin(), v.end());
  ans = 0;
  for (int i=0; i<n-1; i+=2){
    ans += ABS(v[i]+v[i+1]);
  }
  if (n%2==1) ans += v[n-1];
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 892
#include <bits/stdc++.h>
using namespace std;
#define null NULL
#define mp make_pair
#define pb(a) push_back(a)
#define sz(a) ((int)(a).size())
#define all(a) a.begin() , a.end()
#define fi first
#define se second
#define relaxMin(a , b) (a) = min((a),(b))
#define relaxMax(a , b) (a) = max((a),(b))
#define SQR(a) ((a)*(a))
#define PI 3.14159265358979323846
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;

int n;
vi in;

vector<ll> sum, xsum;

ll Sum(int l, int r){
  return l == 0 ? sum[r] : (sum[r] - sum[l - 1]);
}

ll Xsum(int l, int r){
  return l == 0 ? xsum[r] : (xsum[r] ^ xsum[l - 1]);
}

bool Fine(int l, int r){
  return Sum(l, r) == Xsum(l, r);
}

int main(){
  scanf("%d", &n);
  in.resize(n);
  for(int& e : in) scanf("%d", &e);

  sum.resize(n);
  xsum.resize(n);

  sum[0] = in[0];
  xsum[0] = in[0];
  for(int i = 1;i < n;++i)
    sum[i] = sum[i - 1] + in[i],
    xsum[i] = xsum[i - 1] ^ in[i];

  ll ans = 0;
  for(int i = 0;i < n;++i){
    int lo = i, hi = n - 1, mid;
    for(;;){
      if(lo + 1 >= hi){
        if(Fine(i, hi)) mid = hi;
        else mid = lo;
        break;
      }
      mid = (lo + hi) / 2;
      if(Fine(i, mid)) lo = mid;
      else hi = mid;
    }

    //cout << i << ' ' << mid << endl;

    ans += mid - i + 1;
  }

  cout << ans << '\n';

  return 0;
}


Measured memory_bytes: 4096
import sys

sys.setrecursionlimit(1000000)


def dfs(v, parent, adj, dist):
    for tail, weight in adj[v]:
        if tail == parent:
            continue
        dist[tail] = dist[v] + weight
        dfs(tail, v, adj, dist)


def main():
    n = int(input())
    adj = [[] for i in range(n + 1)]
    for i in range(n - 1):
        a, b, c = [int(x) for x in input().split()]
        adj[a].append((b, c))
        adj[b].append((a, c))
    q, k = [int(x) for x in input().split()]
    dist = [0] * (n + 1)
    dfs(k, k, adj, dist)
    for j in range(q):
        l, r = [int(x) for x in input().split()]
        print(dist[l] + dist[r])


main()
# print(*data, sep='\n')


Measured memory_bytes: 131660
<?php

fscanf(STDIN, '%d', $n);
$line = trim(fgets(STDIN));
$arr = array();
foreach (explode(' ', $line) as $m) {
    $arr[] = (int)$m;
}
$cnt = 0;
mergeSort(0, $n);
echo implode(' ', $arr), PHP_EOL, $cnt, PHP_EOL;

function merge($left, $mid, $right)
{
    global $arr, $cnt;
    $n1 = $mid - $left;
    $L = array();
    for ($i = 0; $i < $n1; $i++) {
        $L[] = $arr[$left + $i];
    }
    $L[$n1] = PHP_INT_MAX;

    $n2 = $right - $mid;
    $R = array();
    for ($i = 0; $i < $n2; $i++) {
        $R[] = $arr[$mid + $i];
    }
    $R[$n2] = PHP_INT_MAX;

    for ($i = 0, $j = 0, $k = $left; $k < $right; $k++) {
        if ($L[$i] <= $R[$j]) {
            $arr[$k] = $L[$i];
            $i++;
        } else {
            $arr[$k] = $R[$j];
            $j++;
        }
        $cnt++;
    }
}

function mergeSort($left, $right)
{
    if ($left + 1 < $right) {
        $mid = (int)(($left + $right) / 2);
        mergeSort($left, $mid);
        mergeSort($mid, $right);
        merge($left, $mid, $right);
    }
}

Measured memory_bytes: 169508
#include<iostream>
using namespace std;
int main(){
  string u[256],t;
  int n,m,i,j,f=0,k;
  cin>>n;
  for(i=0;i<n;i++)cin>>u[i];
  cin>>m;
  for(i=0;i<m;i++){
    cin>>t;
    k=f;
    for(j=0;j<n;j++)if(t==u[j]){
	if(f==0)f=1,cout<<"Opened by "<<t<<endl;
	else f=0,cout<<"Closed by "<<t<<endl;
      }
    if(k==f)cout<<"Unknown "<<t<<endl;
  }
  return 0;
}

Measured memory_bytes: 1216
#include <bits/stdc++.h>
using namespace std;;
#define ll long long
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define INF 1<<30
#define LINF 1LL<<62
const int MOD = 1000000007;
 
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

int main(){
    ll n; cin >> n;
    ll a[n];
    ll nummax = 0;
    REP(i,n){
        cin >> a[i];
        nummax = max(nummax , a[i]);
    }
    ll b = -1;
    ll m = (long double)nummax/2.0;
    REP(i,n){
        if(abs(m-a[i]) < abs(m-b) && a[i] != nummax){
            b = a[i];
        }
    }
    cout << nummax << " " << b << endl;
    

}



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

int gu(char *s)
{
    int len = strlen(s);
    if (len % 2 == 1) {
        return 0;
    }
    for (int i = 0; i < len/2; ++i) {
        if (s[i] != s[i+len/2]) {
            return 0;
        }
    }
    return 1;
}

int main(int argc, char **argv)
{
    char s[256];
    scanf("%s", s);

    int len = strlen(s);
    for (int i = 0; i < len-1; ++i) {
        s[len-1-i] = '\0';
        if (gu(s)) {
            printf("%d\n", strlen(s));
            break;
        }
    }
    return 0;
}

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

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

  if (A == B) {
    cout << "Draw" << endl;
  } else if (A == 1) {
    cout << "Alice" << endl;
  } else if (B == 1) {
    cout << "Bob" << endl;
  } else if (A > B) {
    cout << "Alice" << endl;
  } else if (A < B) {
    cout << "Bob" << endl;
  }
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(void) {
    long long A, B, C, K;
    cin >> A >> B >> C >> K;

    if (K <= A) {
        cout << K;
    } else if (K <= A + B) {
        cout << A;
    } else {
        cout << A - (K - (A + B));
    }
    return 0;
}


Measured memory_bytes: 3624
N,L=map(int,input().split())
if L>=0:
  print((N-1)*(L-1)+int(N*(N+1)/2)-1)
else:
  if L+N>0:
    print(N*(L-1)+int(N*(N+1)/2))
  else:
    print(N*(L-1)+int(N*(N+1)/2)-(L+N-1))

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod = 1e9 + 7;
const ll inf = (1 << 30) - 1;
const ll infll = (1LL << 61) - 1;

template <typename T>
struct edge
{
    int src, to;
    T cost;

    edge(int to, T cost) : src(-1), to(to), cost(cost) {}

    edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}

    edge &operator=(const int &x)
    {
        to = x;
        return *this;
    }

    operator int() const { return to; }
};

//Weighted edge set
template <typename T>
using Edges = vector<edge<T>>;

//Weighted graph
template <typename T>
using WeightedGraph = vector<Edges<T>>;

template <typename T>
T Prim(WeightedGraph<T> &g)
{
    T res = 0;
    vector<bool> used(g.size(), false);
    priority_queue<pair<T, int>, vector<pair<T, int>>, greater<pair<T, int>>> que;
    que.emplace(0, 0);
    while (que.empty() != true)
    {
        auto p = que.top();
        que.pop();
        if (used[p.second] == true)
            continue;
        used[p.second] = true;
        res += p.first;
        for (auto &e : g[p.second])
        {
            que.emplace(e.cost, e.to);
        }
    }
    return res;
}

int N, a, b, c, d, p1, p2;

int main()
{
    cin >> N;
    vector<pair<pair<int, int>, int>> x, y;
    WeightedGraph<int> G(N);

    for (int i = 0; i < N; i++)
    {
        scanf("%d%d", &a, &b);
        a--, b--;
        x.emplace_back(make_pair(a, b), i);
        y.emplace_back(make_pair(b, a), i);
    }

    sort(x.begin(), x.end());
    sort(y.begin(), y.end());

    for (int i = 0; i + 1 < N; i++)
    {
        a = x[i].first.first, b = x[i].first.second, c = x[i + 1].first.first, d = x[i + 1].first.second, p1 = x[i].second, p2 = x[i + 1].second;
        G[p1].emplace_back(p2, min(abs(a - c), abs(b - d)));
        G[p2].emplace_back(p1, min(abs(a - c), abs(b - d)));
    }

    for (int i = 0; i + 1 < N; i++)
    {
        a = y[i].first.first, b = y[i].first.second, c = y[i + 1].first.first, d = y[i + 1].first.second, p1 = y[i].second, p2 = y[i + 1].second;
        G[p1].emplace_back(p2, min(abs(a - c), abs(b - d)));
        G[p2].emplace_back(p1, min(abs(a - c), abs(b - d)));
    }

    printf("%d\n", Prim(G));
}

Measured memory_bytes: 14636
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    try (Scanner sc = new Scanner(System.in)) {
      int N = Integer.parseInt(sc.next());
      int K = Integer.parseInt(sc.next());
      System.out.println(N % K == 0 ? "0" : "1");
    }
  }
}


Measured memory_bytes: 23636
from math import sqrt
n=input()
for i in range(n):
    x1,y1,x2,y2,x3,y3=map(float,raw_input().split())
    A1=2*(x2-x1)
    B1=2*(y2-y1)
    C1=x2**2+y2**2-x1**2-y1**2
    A2=2*(x3-x2)
    B2=2*(y3-y2)
    C2=x3**2+y3**2-x2**2-y2**2
    x=(C1*B2-C2*B1)/(A1*B2-A2*B1)
    y=(A1*C2-A2*C1)/(A1*B2-A2*B1)
    R=sqrt((x1-x)**2+(y1-y)**2)
    print"%.3f %.3f %.3f"%(x,y,R)


Measured memory_bytes: 4768
#include <bits/stdc++.h>
using namespace std;
#define repeat(i,a,b) for(int i=(a),_=(b);i<_;i++)
#define repeat_back(i,a,b) for(int i=(b)-1,_=(a);i>=_;i--)
#define mst(a,x) memset(a,x,sizeof(a))
#define fi first
#define se second
#define endl "\n"
int cansel_sync=(ios::sync_with_stdio(0),cin.tie(0),0);
//mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
const int N=200010; typedef long long ll; const int inf=~0u>>2; const ll INF=~0ull>>2; ll read(){ll x; if(scanf("%lld",&x)==-1)exit(0); return x;} typedef double lf; const lf pi=acos(-1.0); lf readf(){lf x; if(scanf("%lf",&x)==-1)exit(0); return x;} typedef pair<ll,ll> pii;
const int mod=(1?1000000007:998244353); ll mul(ll a,ll b,ll m=mod){return a*b%m;} ll qpow(ll a,ll b,ll m=mod){ll ans=1; for(;b;a=mul(a,a,m),b>>=1)if(b&1)ans=mul(ans,a,m); return ans;}
//#define int ll
int a[N],n,sum;
void Solve(){
	cin>>n;
	repeat(i,0,n){
		cin>>a[i]; sum^=a[i];
	}
	repeat(i,0,n)cout<<(sum^a[i])<<' '; 
}
signed main(){
	int T=1; //cin>>T;
	while(T--)Solve();
	return 0;
}

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

#ifdef _PRINTDEBUG
  #include "lib/printdebug.hpp"
#else
  #define printdebug(...) 1
#endif
#define MOD_1_000_000_007 (1000000007)
#define IINF (1<<28)
#define LINF (1LL<<60)
#define rep(i, n)      REP(i, 0, (n))
#define repc(i, n)     REPC(i, 0, (n))
#define REP(i, n, m)   for (int i = (int)(n); i <  (int)(m); i++)
#define REPC(i, n, m)  for (int i = (int)(n); i <= (int)(m); i++)
#define REPCM(i, n, m) for (int i = (int)(n); i >= (int)(m); i--)
#define yesno(cond)       YESNO((cond), "Yes", "No")
#define YESNO(cond, a, b) cout << ((cond) ? (a) : (b)) << "\n"

namespace solver {
  using namespace std;
  typedef long long ll;

  // static const int MAX = 100010;
  int N, table[10][10];

  void init() {
    cin >> N;
  }

  void solve() {
    REPC(i, 1, N) {
      int s = i;
      while(s / 10 > 0) s /= 10;
      int t = i % 10;
      table[s][t]++;
    }
    ll ans = 0;
    REPC(i, 1, 9) REPC(j, 1, 9) {
      ans += table[i][j] * table[j][i];
    }
    cout << ans << "\n";
  }
}

int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  solver::init();
  solver::solve();
  return 0;
}


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

int main(){
    string S;  cin >> S;
    int N = S.length();
    ll mod = 1e9 + 7;
    vector<vector<ll>> dp(N+1, vector<ll>(4, 0));
    dp[N][3] = 1;
    for(int i=N-1; i>=0; i--) for(int j=3; j>=0; j--){
        dp[i][j] = ((S[i] == '?' ? 3 : 1)*dp[i+1][j])%mod;
        if(j < 3 && (S[i] == '?' || S[i] == "ABC"[j])){
            dp[i][j] += dp[i+1][j+1];
        }
        dp[i][j] %= mod;
    }
    cout << dp[0][0] << endl;
}


Measured memory_bytes: 7424
#include<iostream>
using namespace std;
#include<cstdio>       // k-D_tree. (k = 2)
#include<algorithm>

class Point
{
public:
    int id, x, y;
    Point(){};
    Point(int no, int pos_x, int pos_y) : id(no), x(pos_x), y(pos_y) {};
    void print(){ printf("%d\n", id); }
};

bool cmp_x(const Point &P1, const Point &P2){ return P1.x < P2.x; }
bool cmp_y(const Point &P1, const Point &P2){ return P1.y < P2.y; }
bool cmp_id(const Point &P1, const Point &P2){ return P1.id < P2.id; }

class node // nodes of 2-D_tree.
{
public:
    Point *mark;
    node *less, *more;
    int depth;   // parity of depth is important.
    node() : mark(NULL), less(NULL), more(NULL), depth(0) {};
    node(Point* pos, node* l, node* m, int d) : mark(pos), less(l), more(m), depth(d) {};
};

node* make_tree(Point S[], int left, int right, int d) // recursive construction of 2-D_tree.
{
    if(left > right){ return NULL; }
    if(left == right){
        node* leaf = new node;
        *leaf = node(&S[left], NULL, NULL, d);    // arrived at leaf.
        return leaf;
    }

	if(d & 1){
		sort(S + left, S + right + 1, cmp_x);
	}else{
        sort(S + left, S + right + 1, cmp_y);
	}

    int mid = (left + right) / 2;

    node* n = new node;   // make a new node.
    n->mark = &S[mid];
    n->depth = d;
    n->less = make_tree(S, left, mid - 1, d + 1);
    n->more = make_tree(S, mid + 1, right, d + 1);

    return n;
}

int cnt;

void find(Point S[], int sx, int tx, int sy, int ty, node* kd_n)
{
    if(kd_n == NULL) return;
    int a = kd_n->mark->x, b = kd_n->mark->y;

    if(sx <= a && a <= tx && sy <= b && b <= ty){
        S[cnt] = *(kd_n->mark);
        cnt++;
    }
    int d = kd_n->depth;

    if(d & 1){
        if(sx <= a) find(S, sx, tx, sy, ty, kd_n->less);
        if(a <= tx) find(S, sx, tx, sy, ty, kd_n->more);
    }else{
        if(sy <= b) find(S, sx, tx, sy, ty, kd_n->less);
        if(b <= ty) find(S, sx, tx, sy, ty, kd_n->more);
    }
}

int main()
{
    int i, pos_x, pos_y, n;
    Point P[500000], Q[100];

    scanf("%d", &n);
    for(i = 0; i < n; i++){ scanf("%d %d", &pos_x, &pos_y); P[i] = Point(i, pos_x, pos_y); }
	
    node* root;
    root = make_tree(P, 0, n - 1, 0);  // make a 2-D_tree.

    int q, sx, tx, sy, ty;
    scanf("%d", &q);
    while(q){
        cnt = 0;
        scanf("%d %d %d %d", &sx, &tx, &sy, &ty);      // input data.
        find(Q, sx, tx, sy, ty, root);   // counting.
        sort(Q, Q + cnt, cmp_id);
        for(i = 0; i < cnt; i++){ Q[i].print(); }  // print out.
        printf("\n");
        q--;
    };

    return 0;
}

Measured memory_bytes: 29732
import java.util.Scanner;

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

        if(s.length() + 1 == t.length() && s.length() >= 1 && s.length() <= 10 && t.substring(0, t.length()-1).equals(s) == true){
            System.out.println("Yes");
        }
        else{
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 35400
fun main(args: Array<String>) {
    while (true) {
        val inStr = readLine()
        val (h, w) = inStr?.split(' ')?.map { s -> s.toInt() } ?: return

        if ((h == 0) && (w == 0)) {
            return
        }
        printRectangle(h, w)
    }
}

fun printRectangle(height:Int, width:Int) {
    val line = "#".repeat(width)
    val rectAngle = (line + "\n").repeat(height)
    println(rectAngle)
}



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


int main() {
    int n,k;
    string s;
    cin >> n >> k >> s;
    s[k-1] += 32;
    cout << s << endl;
    return 0;
}

/*
やっほい！
　　　　　　　やほほい！
　　　　+　　 　*
　　　 ∧∧　　. ∧∞∧　*
*　ヽ(=´ω｀)人(´ω｀*)ﾉ
　.～（ O x.） （ 　 O)～　+
。*　 　∪　　　　∪
*/

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

int main(){
    string S;
    cin >> S;
    map<string, int> mp;
    for(int i=0; i<4; i++){
        string a = S.substr(i,1);
        if(mp.count(a) == 0){
            mp[a] = 1;
        }
        else{
            mp[a] += 1;
        }
    }
    int flag = 1;
    if(mp.size() == 2){
        map<string, int>::iterator begin = mp.begin(), end = mp.begin();
        for(map<string, int>::iterator iter = begin; iter != end; iter++){
            if(iter->second != 2){
                flag = 0;
            }
        }
    }
    else{
        flag = 0;
    }
    if(flag == 1){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}


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

int main() {
	ios_base::sync_with_stdio( false );

	int N, X;
	cin >> N >> X;

	int a = INT_MAX;
	for( int i = 0; i < N; ++i ) {
		int m;
		cin >> m;
		X -= m;

		if( m < a ) {
			a = m;
		}
	}

	cout << N + X/a << endl;
	return 0;
}


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

using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> Vi;
//typedef tuple<int, int, int> T;
#define FOR(i,s,x) for(int i=s;i<(int)(x);i++)
#define REP(i,x) FOR(i,0,x)
#define ALL(c) c.begin(), c.end()
#define DUMP( x ) cerr << #x << " = " << ( x ) << endl

const int dr[4] = {-1, 0, 1, 0};
const int dc[4] = {0, 1, 0, -1};

#define INF 1<<30

template <typename T>
struct Edge {
  int src, dst; T weight;
  Edge(int src, int dst, T weight) : src(src), dst(dst), weight(weight) { }
  bool operator < (const Edge<T> &e) const {
    return weight < e.weight;
  }
};

template <typename T>
struct Graph {

  int V;
  vector<Edge<T>> E;

  Graph(int V) : V(V) { }

  void add_edge(int src, int dst, T weight) {
    E.push_back(Edge<T>(src, dst, weight));
  }
};

struct DisjointSet {
  vector<int> parent, rank;

  DisjointSet(int N) {
    parent.resize(N), rank.resize(N, 0);
    for (int i = 0; i < N; i++) parent[i] = i;
  }

  int find(int x) {
    if (parent[x] == x) {
      return x;
    } else {
      return parent[x] = find(parent[x]);
    }
  }

  void unite(int x, int y) {
    x = find(x), y = find(y);
    if (x == y) return ;
    if (rank[x] < rank[y]) {
      parent[x] = y;
    } else {
      parent[y] = x;
      if (rank[x] == rank[y]) rank[x]++;
    }
  }

  bool same(int x, int y) { return find(x) == find(y); }
};

template <typename T>
struct MinimumSpanningTree {
  Graph<T> g;
  vector<Edge<T>> mst;
  T mincost;

  MinimumSpanningTree(const Graph<T> &g) : g(g) { }

  T kruskal() {
    mincost = 0;
    sort(g.E.begin(), g.E.end());

    DisjointSet uf(g.V);

    for (int i = 0, edge_count = g.V - 1; edge_count; i++) {
      assert(i < (int)g.E.size());
      Edge<T> e = g.E[i];
      if (!uf.same(e.src, e.dst)) {
	uf.unite(e.src, e.dst);
	mst.push_back(e);
	mincost += e.weight;
	edge_count--;
      }
    }
    return mincost;
  }
};

int main() {
  // use scanf in CodeForces!
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  int V, E; cin >> V >> E;
  Graph<int> g(V);
  REP(_, E) {
    int s, t, w; cin >> s >> t >> w;
    g.add_edge(s, t, w);
  }
  MinimumSpanningTree<int> mst(g);
  cout << mst.kruskal() << endl;

  return 0;
}

Measured memory_bytes: 5460
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
using namespace std;
int main()
{
    int n,ans=0;
    scanf("%d",&n);
    if(n==10||n==100||n==1000||n==10000||n==100000)
    {
        printf("10\n");
    }
    else {while(n)
    {
        ans+=n%10;
        n=n/10;
    }
    printf("%d\n",ans);
    }
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
typedef struct{
  int parent;
  int left;
  int right;
} Tree;
Tree tree[10000];
//int s=0,t=0;
#define NIL -1
int getheight(int);
int main()
{
  int i,id,j,n,k,depth=0,num,l,r,degree=0,height=0;
 
  scanf("%d",&n);
 
  for(i=0;i<n;i++){
    tree[i].parent=NIL;
  }
 
  for(i=0;i<n;i++){
    scanf("%d%d%d",&id,&l,&r);
    tree[id].left=l;
    tree[id].right=r;
    if(l!=NIL && r!=NIL){
      tree[l].parent=id;
      tree[r].parent=id;
    }
    else if(l!=NIL && r==NIL){
      tree[l].parent=id;
    }
    else if(l==NIL && r!=NIL){
      tree[r].parent=id;
    }
  }
   
  for(i=0;i<n;i++){
    printf("node %d: parent = %d, ",i,tree[i].parent);
    if(tree[i].parent==NIL){
      printf("sibling = -1, ");
    }
    else if(tree[tree[i].parent].left==i){
      printf("sibling = %d, ",tree[tree[i].parent].right);
    }
    else{
      printf("sibling = %d, ",tree[tree[i].parent].left);
    }
    printf("degree = ");
    if(tree[i].left!=NIL && tree[i].right!=NIL){
      printf("2, ");
    }
    else if(tree[i].left==NIL && tree[i].right==NIL){
      printf("0, ");
    }
    else printf("1, ");
 
    num=i;
    while(tree[num].parent!=NIL){
      depth++;
      num=tree[num].parent;
    }
    printf("depth = %d, ",depth);
    depth=0;
 
    printf("height = ");
    height=getheight(i);
    printf("%d,",height);
    //s=0;t=0;
     
    if(tree[i].parent==NIL){
      printf(" root\n");
    }
    else if(tree[i].left==NIL && tree[i].right==NIL){
      printf(" leaf\n");
    }
    else {
      printf(" internal node\n");
      }
  }
  return 0;
}

int getheight(int i)
{
  int s=0,t=0;
  if(tree[i].left==NIL && tree[i].right==NIL)return 0;

  if(tree[i].left!=NIL){
  s=getheight(tree[i].left)+1;
  }
  if(tree[i].right!=NIL){
  t=getheight(tree[i].right)+1;
  }
  if(s>t){
    
    return s;
  }
  else{
    return t;
  }
}

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

int cnt[31];

int main() {
    for(int i=0; i<31; ++i) cnt[i] = 0;
    cnt[0] = 1;
    cnt[1] = 1;
    cnt[2] = 2;

    for(int i=3; i<31; ++i)
        cnt[i] = (cnt[i-1] + cnt[i-2] + cnt[i-3]);
    int y;
    while(cin>>y,y) cout<<cnt[y]/3650+(cnt[y]%3650>=1?1:0)<<endl;
}

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

typedef long long ll;

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

  ll A, B, C, D;
  std::cin >> A >> B >> C >> D;

  std::cout << std::max(A*B, C*D) << std::endl;

  return 0;
}


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

#define rep(i, n) for(int i = 0; i < n; i++)

typedef long long ll;
using namespace std;
int mod = 1000000007;

int main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N, M; cin >> N >> M;
    int left = 1, right = N;
    rep(i, M){
        int l, r; cin >> l >> r;
        left = max(left, l);
        right = min(right, r);
    }
    cout << max(right-left+1, 0);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)n; i++)
#define all(x) (x).begin(),(x).end()
typedef long long int ll;
using namespace std;
int main()
{
  string a,b;
  cin >> a>>b;
  if(a[0] == b[2]&&a[1] == b[1] &&a[2] == b[0]){
    cout << "YES" << endl;
  }else{
    cout << "NO" << endl;
  }
  

}


Measured memory_bytes: 256
#C
N = int(input())
V = list(map(int,input().split()))

M = 10**5
C = [0 for i in range(M)]
D = [0 for i in range(M)]
for i in range(N):
    if i%2 == 0:
        C[V[i]-1]+=1
    else:
        D[V[i]-1]+=1
        
c,d = (N+1)//2,N//2

MC = max(C)
MD = max(D)

ans = 0
if C.index(MC) == D.index(MD):
    C[C.index(MC)]-=MC
    D[D.index(MD)]-=MC
    
    MC2 = max(C)
    MD2 = max(D)
    if c-MC + d-MD2 >= c-MC2 + d-MD:
        ans = c-MC2 + d-MD
    else:
        ans = c-MC + d-MD2
    
else:
    ans = c-MC + d-MD

print(ans)


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

using namespace std;

int main(void) {

	int A, B;
	cin >> A >> B;

	if (A > 12) { cout << B << endl; }
	else if (A >= 6) { cout << B / 2 << endl; }
	else { cout << 0 << endl; }


	return 0;
}

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

const int maxn = 1000;
int n, a[maxn];
bool ans[maxn];

int main(void) {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%d", a + i);
  }
  long long sum0 = 0, sum1 = 0;
  for (int i = 0; i < n; ++i) {
    if (i & 1) sum1 += max(a[i], 0); else sum0 += max(a[i], 0);
  }
  for (int i = 0; i < n; ++i) {
    if (sum0 > sum1 && !(i & 1) && a[i] > 0 ||
        sum0 <= sum1 && (i & 1) && a[i] > 0) {
      ans[i] = true;
    }
  }
  vector<int> out;
  if (count(ans, ans + n, true)) {
    printf("%lld\n", max(sum0, sum1));
    for (int i = n - 1; i >= 0; --i) {
      if (ans[i]) break;
      //printf("%d\n", i + 1);
      out.push_back(i + 1);
    }
    for (int i = 0; i < n; ++i) {
      if (ans[i]) break;
      //puts("1");
      out.push_back(1);
    }
    for (int i = 0; i < n; ++i) {
      if (ans[i]) {
        int j = i + 1;
        while (j < n && !ans[j]) {
          ++j;
        }
        if (j < n) {
          for (int k = 0; k < j - i - 2; k += 2) {
            //puts("2");
            out.push_back(3);
          }
          out.push_back(2);
        }
      }
    }
  } else {
    int minid = -1, minval = -2e9;
    for (int i = 0; i < n; ++i) {
      if (a[i] > minval) {
        minval = a[i];
        minid = i;
      }
    }
    printf("%d\n", minval);
    for (int i = n - 1; i > minid; --i) {
      //printf("%d\n", i + 1);
      out.push_back(i + 1);
    }
    for (int i = 0; i < minid; ++i) {
      //puts("1");
      out.push_back(1);
    }
  }
  printf("%d\n", (int)out.size());
  for (int i : out) {
    printf("%d\n", i);
  }
  return 0;
}


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

#ifdef LOCAL
#include "../../dump.hpp"
#else
#define dump(...)
#endif

#define int ll
#define rep(i,n) for(int i=0,i##_cond=(n);i<i##_cond;++i)
#define FOR(i,a,b) for(int i=(a),i##_cond=(b);i<i##_cond;++i)
#define ROF(i,a,b) for(int i=(a)-1,i##_cond=(b);i>=i##_cond;--i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend() //sortで大きい順
#define sz(x) ((int)(x).size())
#define pb push_back
#define fst first
#define snd second
#define mp make_pair
using ll  = long long;
using vi  = vector<int>;
using vvi = vector<vi>;
using vs  = vector<string>;
using pii = pair<int,int>;
constexpr ll mod = 1e9+7;
template<class T>bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T>void add(T &a, const T &b){a += b; a %= mod;}

using Cost = ll;
Cost inf = 1ll<<61;
class node {
public:
  ll v;
  Cost d;
  node(ll _a, Cost _b):v(_a),d(_b){}
  bool operator<(const node &n) const { return d > n.d; }
};
class edge {
public:
  ll to;
  Cost d;
  edge(){}
  edge(ll _to, Cost _d):to(_to),d(_d){}
};
class dijkstra{
public:
  vector<vector<edge>> G;
  vector<Cost> dist;
  vector<ll> prev;

  dijkstra(ll s,const vector<vector<edge>> &_G):G(_G){ // sからの最短経路
    dist.resize(G.size(),inf);
    //prev.resize(G.size(),-1);
  
    priority_queue<node> que;
    que.push(node(s, 0));
    dist[s] = 0;
    
    while(!que.empty()){
      ll v = que.top().v;
      Cost d = que.top().d;
      que.pop();
      
      rep(i, G[v].size()){
	Cost tmp = d + G[v][i].d;
	if(dist[G[v][i].to] > tmp){
	  dist[G[v][i].to] = tmp;
	  //prev[G[v][i].to] = v;
	  que.push(node(G[v][i].to, tmp));
	}
      }
    }
  }

  dijkstra(ll s,ll t,const vector<vector<edge>> &_G):G(_G){ // sからtへの最短経路
    dist.resize(G.size(),inf);
    //prev.resize(G.size(),-1);
  
    priority_queue<node> que;
    que.push(node(s, 0));
    dist[s] = 0;
    
    while(!que.empty()){
      ll v = que.top().v;
      Cost d = que.top().d;
      que.pop();
      if(v == t) break;
      
      rep(i, G[v].size()){
	Cost tmp = d + G[v][i].d;
	if(dist[G[v][i].to] > tmp){
	  dist[G[v][i].to] = tmp;
	  //prev[G[v][i].to] = v;
	  que.push(node(G[v][i].to, tmp));
	}
      }
    }
  }

  vector<ll> getpath(ll t){ // tへの最短経路を返す
    vector<ll> path;
    while(t != -1){
      path.push_back(t);
      t = prev[t];
    }
    reverse(path.begin(), path.end());
    return path;
  }
};

signed main(){
  int n; cin >> n;
  vector<vector<edge>> g(n);
  rep(i,n-1){
    int u,v,w; cin >> u >> v >> w; u--; v--;
    g[u].pb(edge(v,w));
    g[v].pb(edge(u,w));
  }
  dijkstra d(0,g);
  rep(i,n){
    if(d.dist[i]%2==0) cout << 0 << endl;
    else cout << 1 << endl;
  }
}


Measured memory_bytes: 15744
#include<bits/stdc++.h>
using namespace std;
int main(){
  int x,y;
  cin>>x>>y;
  bool res=false;
  for(int i=0;i<=x;i++){
    int b=x-i;
    if((2*b+4*i)==y)
      res=true;
  }
  if(res)
    cout<<"Yes";
  else
    cout<<"No";
  return 0;
}

Measured memory_bytes: 3632
S = list(map(int, list(input())))
lenS = len(S)
count0 = S.count(0)
if count0 == 0 or count0 == len(S):
	print(lenS)
	exit()

if lenS % 2 == 1:
	center = int(lenS/2)
	K = 1
	while K < center:
		if S[center-K] == S[center] and S[center + K] == S[center]:
			K += 1
			continue
		else:
			break
	K = center + K
else:
	center = int(lenS/2)
	K = 1
	while K < center:
		if S[center-K] == S[center+K-1] and S[center-K] == S[center]:
			K += 1
			continue
		else:
			break
	K = center + K - 1

print(K)
"""
def reverse(A, l, n):
	for x in range(n):
		A[l+x] = 1 - A[l+x]

L = int(lenS/2)
while L < R:
	K = int((L+R+1)/2)
	test = [i for i in S]
	for i in range(lenS - K + 1):
		if test[i] == 1:
			reverse(test, i, K)
	flag = True
	for i in range(K):
		if test[i] == 1:
			flag = False
			break
	if flag:
		L = K
	else:
		R = K - 1
		S = test
print(L)
"""

Measured memory_bytes: 4776
import sys
sys.setrecursionlimit(700000)

def s_in():
    return input()

def n_in():
    return int(input())

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

def print_l(l):
    print(' '.join(map(str, l)))

class Interval():
    def __init__(self, li):
        self.li = li
        self.n = len(li)
        self.sum_li = [li[0]]
        for i in range(1, self.n):
            self.sum_li.append(self.sum_li[i-1] + li[i])

    def sum(self, a, b=None):
        if b is None:
            return self.sum(0, a)

        res = self.sum_li[min(self.n-1, b-1)]
        if a > 0:
            res -= self.sum_li[a-1]
        return res

MOD = 2019

def mod_add(a, b):
  return (a+b)%MOD

def mod_sub(a, b):
  return (a+MOD-b)%MOD

def mod_mul(a, b):
  return a*b%MOD

#互いに素なa,bについて、a*x+b*y=1の一つの解
def extgcd(a,b):
    r = (1,0,a)
    w = (0,1,b)
    while w[2]!=1:
        q = r[2]//w[2]
        r2 = w
        w2 = [r[0]-q*w[0],r[1]-q*w[1],r[2]-q*w[2]]
        r = r2
        w = w2
    return (w[0],w[1])

def mod_inv(a):
    x,_  = extgcd(a, MOD)
    return (MOD+x%MOD)%MOD

def mod_div(a, b):
    return a*mod_inv(b)%MOD

def mod_pow(a, b):
    res = 1
    while b > 0:
        if b & 1:
            res = res * a % MOD
        a = a * a % MOD
        b >>= 1
    return res    
s=s_in()

from collections import Counter


p = 2019
c = Counter()
current = int(s[len(s)-1])
c[0]+=1
c[current]+=1

for i in range(len(s)-2, -1,-1):
    current = mod_add(current, mod_mul(int(s[i]), mod_pow(10, len(s)-i-1)))
#    print(current)
    c[current%p] += 1

#print(c)
res = 0
for k in c.values():
    res += k*(k-1)//2

print(res)
    
    


Measured memory_bytes: 9544
#include <iostream>
#include <functional>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <stack>

namespace TokorotenLab
{
    class Logger
    {
    private:
        bool isEnable;

    public:
        Logger(bool isEnable = true) : isEnable(isEnable) {}

        template<class T>
        Logger& operator<<(const T& val)
        {
            if(isEnable)
            {
                std::cout << val;
            }
            return *this;
        }

        void set_enable()
        {
            isEnable = true;
        }

        void set_disable()
        {
            isEnable = false;
        }

        void endl()
        {
            if(isEnable)
            {
                std::cout << std::endl;
            }
        }
    };

    Logger logger;

    /*
    Arguments:
        Search range: [begin, end)
        Target function: f(x)
    Requirement:
        f(x) => { false, ..., false, true, ..., true }
    Judge:
        true_bound == begin => All f(x) are true
        true_bound == end => All f(x) are false
    */
    std::pair<long long, long long> binary_search(long long begin, long long end, std::function<bool(long long)> f)
    {
        long long false_bound = begin - 1LL; // ( ..., false_bound] => false
        long long true_bound = end; // [true_bound, ... ) => true
        long long x;

        while(true_bound - false_bound > 1LL)
        {
            x = false_bound + (true_bound - false_bound) / 2LL;
            if(f(x))
            {
                true_bound = x;
            }
            else
            {
                false_bound = x;
            }
        }

        return std::make_pair(false_bound, true_bound);
    }
}

using namespace std;

int main()
{
    int a, b, c, d;
    vector<int> t;

    cin >> a >> b >> c >> d;

    t.resize(101, 0);

    for(int i = a; i <= b - 1; ++i) ++t[i];
    for(int i = c; i <= d - 1; ++i) ++t[i];

    int ans = 0;
    for(int i = 0; i <= 100; ++i)
    {
        if(t[i] == 2) ++ans;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
  int N , ans = 0,S ,y;

  scanf("%d" ,&N);
  while(N--){
    scanf("%d" ,&S);

    int flg = 0;
    for(y = 1 ; 2*y*y <= S ; y++){
      if((S - y) % (2*y + 1) == 0){
	flg = 1;
	break;
      }
    }
    if(!flg){
      ans++;
    }
  }
  printf("%d\n" ,ans);

  return 0;
}

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

using namespace std;

typedef long long int li;
typedef long double ld;
typedef vector<li> vi;
typedef pair<li,li> pi;
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define B begin()
#define E end()
#define f(i,l,r) for(li i=l;i<=r;++i)
#define fr(i,l,r) for(li i=l;i>=r;--i)
#define u_map unordered_map
#define endl "\n"

li fastpow(li base,li exp,li M) 
{
    li res=1;
    while(exp>0) {
        if(exp&1)
            res=(res*base)%M;

        base=(base*base)%M;
        exp>>=1;
    }
    return res;
}

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

    li n;

    cin>>n;

    li tp=n/500;

    n-=(tp*500);

    li tp2=n/5;

    cout<<tp*1000+tp2*5;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
struct Fast {Fast() {std::cin.tie(0); ios::sync_with_stdio(false);}} fast;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define mp make_pair
#define MOD 1000000007


int main() {
    string S;
    cin >> S;
    string t1 = S.substr(0, 2) , t2 = S.substr(2);
    int a = stoi(t1), b = stoi(t2);
    if (0 < a && a <= 12) {
        if (0 < b && b <= 12) {
            cout << "AMBIGUOUS" << endl;
        }
        else {
            cout << "MMYY" << endl;
        }
    }
    else {
        if (0 < b && b <= 12) {
            cout << "YYMM" << endl;
        }
        else {
            cout << "NA" << endl;
        }
    }


}


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

int n,s[100];
int temp,ave,sum;

void sort(void){
  for(int i=0;i<n;i++){
    for(int j=i;j<n;j++){
      if(s[i]>s[j]){
	temp=s[i];
	s[i]=s[j];
	s[j]=temp;
      }
    }
  }
}

int main(){
  while(cin >> n,n){
    for(int i=0;i<n;i++)
      cin >> s[i];  
    
    sort();
    
    sum=0;

    for(int i=0;i<n-2;i++)
      sum+=s[i+1];

    cout << sum/(n-2) << endl;
  }
  return 0;
}

Measured memory_bytes: 2988
#include<iostream>
#include<stack>
using namespace std;
int main() {
  stack<int> s;
  int n;
  while(cin>>n) {
    if(n==0){
      cout<<s.top()<<endl;
      s.pop();
    }
    else
      s.push(n);
  }
  return 0;
}



Measured memory_bytes: 3088
#include<iostream>
#include<stdio.h>
//#include <bits/stdc++.h>
#include<vector>
#include<float.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cstring>
#include<math.h>
#include<cmath>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include <cassert>
#include <cmath>
#include<cstdint>

#define INF 1e9
#define rep(i,n)for(int i=0;(i)<(int)(n);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
#define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define vec(type,n) vector<type>(n)
#define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
#define ALL(a)  (a).begin(),(a).end()

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<ll, ll>;



int main(){
    string s;
    cin >> s;
    cout << (s == "ABC" ? "ARC" : "ABC");
}



Measured memory_bytes: 3076