akhauriyash/Code-Regression huggingface dataset:
PROGRAM walkingTakahashi
      IMPLICIT NONE
      INTEGER,PARAMETER :: p = 16
      integer(p) :: x,k,d, right,left
      
      read*,x,k,d
      
      x = abs(x)
      
      !rightまでたどり着かないorギリ
      if( k<=x/d )then
        print*,x-k*d
        stop
      end if
      
      right = x - x/d*d
      k = k - x/d
      
      left = right - d
      
      if( mod(k,2)==0 )then
        print*,right
      else
        print*,abs(left)
      end if
      
      
      
      
      
      stop
      !debugg
      
      
      
      END PROGRAM

Measured memory_bytes: 2844
N, K = [int(x) for x in input().split()]
A = [int(x) - 1 for x in input().split()]

i = 0
T = []
S = set()
st = 0
while True:
    T.append(i)
    S.add(i)
    i = A[i]
    if i in S:
        st = T.index(i)
        break

# print(T)


idx = (K - st) % (len(T) - st)

if K > st:
    print(T[st + idx] + 1)
else:
    print(T[K] + 1)





Measured memory_bytes: 32620
#include <cstdlib>
#include <iostream>
#include <typeinfo>
#include <bits/stdc++.h>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

int main()
{
  int a, b;
  char c;
  cin >> a >> c >> b;
  if (c == '+')
  {
    cout << a + b << endl;
  }
  else
  {
    cout << a - b << endl;
  }
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner scan = new Scanner(System.in);
        
        String s = scan.next();
        String t = scan.next();
        String u = scan.next();
        
        char S = (s.toUpperCase()).charAt(0);
        char T = (t.toUpperCase()).charAt(0);
        char U = (u.toUpperCase()).charAt(0);
        
        System.out.print(S);
        System.out.print(T);
        System.out.println(U);
    }
}


Measured memory_bytes: 20948
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin, log, log10, gcd
from itertools import permutations, combinations, product, accumulate, combinations_with_replacement
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
#from fractions import gcd
from decimal import *
import heapq
def debug(*args):
    if debugmode:
        print(*args)
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def FLOAT(): return float(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 1, 0, -1, 1, -1, -1, 1]
dy = [1, 0, -1, 0, 1, -1, 1, -1]
debugmode = True

x = INT()
if x >= 30:
    print("Yes")
else:
    print('No')

Measured memory_bytes: 72752
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <tuple>
# include <unordered_map>
# include <numeric>
# include <complex>
# include <bitset>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
constexpr int INF = 2000000000;
constexpr int HINF = INF / 2;
constexpr double DINF = 100000000000000000.0;
constexpr long long LINF = 9223372036854775807;
constexpr long long HLINF = 4500000000000000000;
constexpr long long MMOD = 500000004;
const double PI = acos(-1);
int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
# define ALL(x)     (x).begin(),(x).end()
# define UNIQ(c)    (c).erase(unique(ALL((c))), end((c)))
# define mp         make_pair
# define eb         emplace_back
# define FOR(i,a,b) for(int i=(a);i<(b);++i)
# define REP(i,n)   FOR(i,0,n)
# define INIT       std::ios::sync_with_stdio(false);std::cin.tie(0);

int main() {
	int a, b;
	cin >> a >> b;
	if (a % 2 && b % 2) {
		cout << "Odd" << endl;
	}
	else {
		cout << "Even" << endl;
	}
}

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

int main(){
  long long n; cin >> n;
  vector<long long> a(n);
  long long count = 0;
  vector<vector<int>> b(n, vector<int>(60, 0));
  for(int i = 0; i < n; i++){
    cin >> a.at(i);
    for(int j = 0; j < 60; j++){
      if(a.at(i) >> j & 1) b.at(i).at(j) = 1;
    }
    if(a.at(i) == 0) count++;
  }
  if(count == n){
    cout << "Yes";
    return 0;
  }
  sort(a.begin(), a.end());
  if(n % 3 != 0){
    cout << "No";
    return 0;
  }
  if(n == 3){
    for(int i = 0; i < 60; i++){
      long long zero = 0, one = 0;
      for(int j = 0; j < n; j++){
        if(b.at(j).at(i) == 0){
          zero++;
        }else{
          one++;
        }
      }
      if(zero == n) continue;
      if(zero * 2 != one){
        cout << "No";
        return 0;
      }
    }
    cout << "Yes";
    return 0;
  }
  for(int i = 1; i < n / 3; i++){
    if(a.at(i) != a.at(i - 1)){
      cout << "No";
      return 0;
    }
  }
  for(int i = n / 3 + 1; i < 2 * (n / 3); i++){
    if(a.at(i) != a.at(i - 1)){
      cout << "No";
      return 0;
    }
  }
  for(int i = 2 * (n / 3) + 1; i < n; i++){
    if(a.at(i) != a.at(i - 1)){
      cout << "No";
      return 0;
    }
  }
  for(int i = 0; i < 60; i++){
    long long zero = 0, one = 0;
    for(int j = 0; j < n; j++){
      if(b.at(j).at(i) == 0){
        zero++;
      }else{
        one++;
      }
    }
    if(zero == n) continue;
    if(zero * 2 != one){
      cout << "No";
      return 0;
    }
  }
  cout << "Yes";
}


Measured memory_bytes: 28416
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  bool a=true;
  vector<int>vec(n);
  for (int i=0;i<n;i++){
    cin>>vec.at(i);
  }
  for (int i=0;i<n;i++){
    if(vec.at(i)%2==0&&vec.at(i)%3!=0&&vec.at(i)%5!=0){
      a=false;
      break;
    }
  }
  if(a){cout<<"APPROVED"<<endl;}
  else{cout<<"DENIED"<<endl;}
}

Measured memory_bytes: 3564
#include <bits/stdc++.h>
#define itn int
#define REP(i, n) for (int i = 0; i < n; i++)
#define IREP(i, n) for (int i = n - 1; i >= 0; i--)
#define REPEACH(i,k) for(auto& i:k)
#define all(a) a.begin(),a.end()
#define MOD 1000000007
using namespace std;
typedef long long ll;

const ll INF = 1LL << 60;

signed main() {
	int n;
	cin >> n;
	vector<int> l(n);
	REP(i,n){
		cin >> l[i];
	}
	sort(l.begin(),l.end());
	int ans=0;
	REP(i,n){
		for(int j=i+1;j<n;j++){
			auto itr = lower_bound(l.begin()+j,l.end(),l[i]+l[j]);
			ans += distance(l.begin() + j, itr-1);
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using Pt = pair<int, int>;


namespace
{
	class Calculater
	{
	public:
		Calculater(vi c, vvi s)
			: c_(c), s_(s), D_((int)s.size()) {}
		ll CalcSatisfaction(const vi& selection)
		{
			ll v = 0;
			vi ld(26, -1);
			for (int i = 0; i < D_; ++i)
			{
				int x = selection[i];
				for (int j = 0; j < 26; ++j)
				{
					if (j == x)
					{
						v += s_[i][j];
						ld[j] = i;
					}
					else
						v -= c_[j] * (i - ld[j]);
				}
			}
			return v;
		}

	private:
		vi c_;
		vvi s_;
		int D_;
	};

}
void Heuristics_Introduction_C()
{
	int D;
	cin >> D;
	vi c(26);
	for (auto& x : c)
		cin >> x;

	vvi s(D, vi(26));
	for (int i = 0; i < D; ++i)
	{
		for (int j = 0; j < 26; ++j)
			cin >> s[i][j];
	}

	vi t(D);
	for (auto& x : t)
	{
		cin >> x;
		--x;
	}

	Calculater x(c, s);
	
	int M;
	cin >> M;
	for (int i = 0; i < M; ++i)
	{
		int d, q;
		cin >> d >> q;
		--d; --q;
		t[d] = q;
		cout << x.CalcSatisfaction(t) << endl;
	}
}


int main()
{
	Heuristics_Introduction_C();
	return 0;
}


Measured memory_bytes: 3740
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner stdIn=new Scanner(System.in);
		int N=stdIn.nextInt();
		String A=stdIn.next();
		String B=stdIn.next();
		String C=stdIn.next();
		char[]a=new char[N];
		char[]b=new char[N];
		char[]c=new char[N];
		int z=0,y=0;
		while(z<N){
			a[z]=A.charAt(z);
			b[z]=B.charAt(z);
			c[z]=C.charAt(z);
			if(a[z]==b[z]||a[z]==c[z])
				y++;
			else
				if(b[z]==c[z])
					y++;
				else
					y+=2;
			if(a[z]==b[z]&&a[z]==c[z])
				if(b[z]==c[z])
					y--;
			z++;
		}
		System.out.println(y);
	}

}

Measured memory_bytes: 21332
function main(input){
  var args = input.split(' ')
  var a = parseInt(args[0], 10)
  var b = parseInt(args[1], 10)
  
  if ((a * b) % 2 === 0){
    console.log('Even');
  }else{
  	console.log('Odd');
  }
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 29600
use std::io;

fn main() {
  let stdin = io::stdin();
  let mut buf = String::new();
  stdin.read_line(&mut buf).unwrap();
  let raw_sec = buf.trim().parse::<i32>().unwrap();
  let sec = raw_sec % 60;
  let min = raw_sec / 60 % 60;
  let hour = raw_sec / 3600;

  println!("{}:{}:{}", hour, min, sec);
}


Measured memory_bytes: 5036
S = input()
A = int(S[0:2])
B = int(S[2:4])
if (1 <= A <= 12) and (1 <= B <= 12):
    print("AMBIGUOUS")
elif (not 1 <= A <= 12) and(not 1 <= B <= 12):
    print("NA")
elif (1 <= A <= 12) and (not 1 <= B <= 12):
    print("MMYY")
else:
    print("YYMM")


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n,m;
    cin>>n>>m;
    vector<int> a(m);
    for(int i=0;i<m;i++){
        cin>>a.at(i);
    }
    for(int i=0;i<m;i++){
        n-=a.at(i);
    }
    if(n<0){
        n=-1;
    }
    cout<<n<<endl;
}


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

using namespace std;

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

    vector<int> h(N+1);
    for (int i = 1; i <= N; i++) {
        cin >> h[i];
    }

    // 足場iに辿り着くまでに支払うコストの総和の最小値dp[i]
    vector<int> dp(N+1, 0);

    // 初期条件
    dp[1] = 0, dp[2] = abs(h[1] - h[2]);

    // dp開始
    for (int i = 3; i <= N; i++) {
        dp[i] = min(dp[i-2] + abs(h[i-2] - h[i]), dp[i-1] + abs(h[i-1] - h[i]));
    }

    cout << dp[N] << endl;
	return 0;
}

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

int main() {
  string s;
  cin >> s;
  string t = s;
  reverse(s.begin(), s.end());
  int n = s.size();
  int count;
  for(int i; i<n; i++){
    if(s.at(i)!=t.at(i)) count++;
  }
  cout << count/2 << endl;
}



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

const int MOD = 1e9 + 7;
const int MAXN = 1e5 + 10;
vector<int> G[MAXN];
int ans;
int n, k;

int mul(int x, int y) {
    return 1LL * x * y % MOD;
}



void dfs(int u, int fa) {
    int w = 2;
    if (fa == -1) {
        w--;
    }
    for (auto v : G[u]) {
        if (v == fa) {
            continue;
        }
        ans = mul(ans, k - w < 0 ? 0 : k - w);
        dfs(v, u);
        w++;
    }
    
}

int main() {
    scanf("%d%d", &n, &k);// don't forget &
    for (int i = 1; i <= n - 1; i++) {
        int x, y;
        scanf("%d%d", &x, &y);// don't forget &
        G[x].push_back(y);
        G[y].push_back(x);
    }
    ans = k;
    dfs(1, -1);
    printf("%d", ans);
    return 0;
}


Measured memory_bytes: 10368
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>
#include <queue>
#include <deque>
#include <set>
#include <iomanip>
#include <utility>
typedef long long ll;
typedef long double ld;
using namespace std;

int mn[200010], pl[200010];

int f(int x){
	if(x==0) return 0;
	int t=0, y=x;
	while(y>0){
		t += y&1;
		y /= 2;
	}
	return 1+f(x%t);
}

int main() {
	int N;
	string X;
	cin >> N >> X;
	int cnt=0, ms=0, ps=0;
	for(int i=0; i<N; ++i){
		if(X[i]=='1') ++cnt;
	}
	if(cnt>1){
		mn[N-1]=1;
		for(int i=N-2; i>=0; --i){
			mn[i]=(mn[i+1]*2)%(cnt-1);
		}
		for(int i=0; i<N; ++i){
			if(X[i]=='1') ms=(ms+mn[i])%(cnt-1);
		}
	}
	if(cnt<N){
		pl[N-1]=1;
		for(int i=N-2; i>=0; --i){
			pl[i]=(pl[i+1]*2)%(cnt+1);
		}
		for(int i=0; i<N; ++i){
			if(X[i]=='1') ps=(ps+pl[i])%(cnt+1);
		}
	}
	for(int i=0; i<N; ++i){
		if(X[i]=='0'){
			cout << 1+f((ps+pl[i])%(cnt+1)) << endl;
		}
		else{
			if(cnt==1){
				cout << 0 << endl;
			}
			else{
				cout << 1+f((ms+cnt-1-mn[i])%(cnt-1)) << endl;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 5280
#include <bits/stdc++.h>
using namespace std;
int n,arr[100009];
int sum;
int main(){
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>arr[i];
    }
    int ans = 1000000009;
    for(int i=-100;i<=100;i++){
        int curr = 0;
        for(int j=0;j<n;j++){
            curr += (arr[j]-i)*(arr[j]-i);
        }
        ans = min(ans,curr);
    }
    cout<<ans<<endl;
}


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

int main(){
  int N;
  cin >> N;
  vector<int64_t> A(N);
  bool check = false;
  for(int i = 0; i < N; i++){
    cin >> A[i];
    if(A[i] == 0)
      check = true;
  }
  
  if(check)
    cout << 0 << endl;
  else{
    int64_t ans = 1;
    for(int i = 0; i < N; i++){
      if(A[i] > 1000000000000000000/ans){
        ans = -1;
        break;
      }
      ans *= A[i];
    }
    cout << ans << endl;
  }
  
  return 0;
}

Measured memory_bytes: 4052
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const double pi = acos(-1);

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

    vl f(n+1);  // f[i] : iの正の約数の個数
    exrep(i, 1, n) {
        for(ll j = i; j <= n; j += i) {
            f[j]++;
        }
    }
    
    ll ans = 0;
    exrep(i, 1, n) {
        ans += i*f[i];
    }

    out(ans);
    re0;
}

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

int main() {
    int N;
    cin >> N;
    vl A(N);
    vl sum(N + 1);
    rep(i, N) {
        cin >> A[i];
        sum[i + 1] = A[i];
    }

    for (int i = 0; i < N; i++) {
        sum[i + 1] += sum[i];
    }

    ll summin = __LONG_LONG_MAX__;
    for (int i = 1; i < N; i++) {
        ll s = sum[i];
        ll a = sum[N] - sum[i];

        summin = min(summin, abs(s - a));
    }
    cout << summin << endl;
}

Measured memory_bytes: 6440
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define Rep(i,s,n) for(int i=s;i<n;i++)
#define per(i,s,n) for(int i=n-1;i>=s;i--)
#define fi first
#define se second
#define all(c) c.begin(),c.end()
typedef long long int ll;
typedef pair<int, int> P;
typedef long double ld;
void Ans(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}

const ll INF=1001001001;
const ll mod=1000000007;

int main(){
  int a;
  cin>>a;
  int c=0;
  int d=0;
  if(a/100<=12&&a/100>=1){
    c++;
  }
  if(a%100<=12&&a%100>=1){
    d++;
  }
  
  if(c==1&&d==1){
    cout<<"AMBIGUOUS"<<endl;
  }
  else if(c==1) cout<<"MMYY"<<endl;
  else if(d==1) cout<<"YYMM"<<endl;
  else cout<<"NA"<<endl;
}



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

int main(){
  int N;
  cin >> N;
  vector<int> A(N);
  int count=0;
  long int a=1;
  long int b=1;
  for(int i=0;i<N;i++){
    cin >> A.at(i);
    if(A.at(i)%2==0){
      count++;
    }
  }
  for(int i=0;i<N;i++){
    a*=3;
  }
  for(int i=0;i<count;i++){
    b*=2;
  }
  cout <<a-b << endl;
}

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

using namespace std;
typedef long long ll;

int N;
int prime_cnt[101];

void factoring(int a) {
	int div = 2;
	while (div <= a) {
		if (a % div == 0) {
			a /= div;
			prime_cnt[div]++;
		}
		else {
			div++;
		}
	}
}

//75 = 3 * 5 * 5 = (2+1) * (4+1) * (4+1) = (4+1) * (14+1) = (2+1) * (24+1)

int main() {
	cin >> N;
	for (int i = 1; i <= N; i++) {
		factoring(i);
	}
	int ans = 0;
	int over2 = 0, over4 = 0, over14 = 0, over24 = 0, over74 = 0;
	for (int i = 2; i <= N; i++) {
		if (prime_cnt[i] >= 2)over2++;
		if (prime_cnt[i] >= 4)over4++;
		if (prime_cnt[i] >= 14)over14++;
		if (prime_cnt[i] >= 24)over24++;
		if (prime_cnt[i] >= 74)over74++;
	}

	ans += (over2 - 2) * over4 * (over4 - 1) / 2;//(over2 - 2) * over4C2
	ans += (over4 - 1) * over14;
	ans += (over2 - 1) * over24;
	ans += over74;
	cout << ans << endl;
	return 0;
}

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

int main() {
  int y,m,d;
  while(cin >> y >> m >> d) {
    if(y<1868 || (y==1868 && (m<9 || (m==9 && d<8)))) {
      cout << "pre-meiji" << endl;
      continue;
    }
    else if(y<1912 || (y==1912 && (m<7 || (m==7 && d<=29)))) cout << "meiji " << y-1867;
    else if(y<1926 || (y==1926 && (m<12 || (m==12 && d<=24)))) cout << "taisho " << y-1911;
    else if(y<1989 || (y==1989 && m==1 && d<=7)) cout << "showa " << y-1925;
    else cout << "heisei " << y-1988;
    cout << " " << m << " " << d << endl;
  }
  return 0;
}


Measured memory_bytes: 1164
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <math.h>
#include <assert.h>
#include <vector>
#include <queue>
#include <string>
#include <map>
#include <set>

using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
static const double EPS = 1e-9;
static const double PI = acos(-1.0);

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define FOREQ(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define FORIT(it, c) for (__typeof((c).begin())it = (c).begin(); it != (c).end(); it++)
#define MEMSET(v, h) memset((v), h, sizeof(v))

typedef vector<int> Edges;
typedef vector<Edges> Graph;
int deg[100010];
bool use[100010];
int n, m;
const ll MOD = 1000000009;

int main() {
  while (scanf("%d %d", &n, &m) > 0) {
    Graph g(n);
    MEMSET(use, true);
    MEMSET(deg, 0);
    REP(i, m) {
      int f, t;
      scanf("%d %d", &f, &t);
      f--; t--;
      g[f].push_back(t);
      g[t].push_back(f);
      deg[f]++; deg[t]++;
    }
    REP(from, n) {
      FORIT(it, g[from]) {
        int to = *it;
        if (deg[from] > deg[to] || (deg[from] == deg[to] && from > to)) { use[from] = false; }
      }
    }
    ll ans1 = 0;
    ll ans2 = 1;
    REP(from, n) {
      if (!use[from]) { continue; }
      ans1++;
      ll sum = 1;
      FORIT(it, g[from]) {
        if (deg[from] == deg[*it]) { sum++; }
      }
      ans2 = ans2 * sum % MOD;
    }
    printf("%lld\n%lld\n", ans1, ans2);
  }
}

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

int main(){
  int N; cin >> N;
  int ans;
  
  ans = N%1000;
  if (ans == 0){
    cout << ans << endl;
  } else {
    ans = 1000 - ans;
    cout << ans << endl;
  }

}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
#define inf 0x3f3f3f3f
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef double dd;
const int N = 1e5+5;
const dd eps = 1e-8;
const int mod = 1e9+7;

int n,p,a[N],vis[N];
string now;
ll ans;


int main(){
  ios::sync_with_stdio(false);
  // freopen("input.txt","r",stdin);
  cin>>n>>p>>now;
  if(p == 2 || p == 5){
    for(int i = 0;i < n;i++){
      int num = now[i] - '0';      
      if(num%p == 0) ans += i+1;      
    }
  }
  else{
    int last = 0,e = 1;
    vis[0] = 1;
    for(int i = n-1;i >= 0;i--){
      int num = now[i] - '0';
      last = (last + (e*num)%p)%p;
      ans += vis[last];
      vis[last]++;
      e = (e*10)%p;      
    }
  }
  cout<<ans<<endl;  
  return 0;
}


Measured memory_bytes: 720
n = gets.to_i
A = gets.split(" ").map &:to_i

for i in 0..n-1
    tmp = A[i]
    j = i - 1
    while j >= 0 and A[j] > tmp do
        A[j+1] = A[j]
        j -= 1
    end
    A[j+1] = tmp
    for j in 0..n-1
        if j != 0 then
            print(" ")
        end
        print(A[j])
    end
    print("\n")
end




Measured memory_bytes: 6876
#include<bits/stdc++.h>
#include<unordered_map>
/*
*▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
*    ▀▀       ▀▀▀▀▀▀    ▀     ▀▀▀▀▀▀      ▀    ▀
*   ▀  ▀      ▀         ▀     ▀            ▀  ▀
*  ▀    ▀     ▀ ▀ ▀     ▀     ▀ ▀ ▀         ▀
* ▀ ▀▀▀▀ ▀    ▀         ▀     ▀             ▀
*▀        ▀   ▀         ▀     ▀             ▀
*▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
*/
using namespace std;
void afify()
{
	ios::sync_with_stdio(0);
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
}
#define ll long long
#define ld long double
#define mk make_pair
#define loop(i,intial,n)  for(int i=int(intial);i<n;i++)
#define loopn(j,n) for(int j=int(n-1);j>=0;j--)
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define all(v) v.begin(),v.end()
///////////////////////////////////////
#define SCD(a) scanf("%d",&a)
#define SCD2(a,b) scanf("%d %d",&a,&b)
#define SCLL(a) scanf("%lld",&a)
#define SCLL2(a,b) scanf("%lld %lld",&a,&b)
#define PRD(a) printf("%d\n",a)
#define PRLL(a) printf("%lld\n",a)
///////////////////////////////////////
typedef vector <int> vi;
typedef vector <ll> vll;
typedef vector <vi> vvi;
typedef vector <vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vpll> vvpll;
typedef vector<vpii> vvpii;
typedef stringstream ss;
const ll oo = (ll) 10e9 + 7;
const double EPS = 1e-4;
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
//ifstream ifs("input.txt");
//ofstream ofs("output.txt");
int main()
{
	afify();
	int n;
	cin >> n;
	ll g = 0, b = 0, gn = 0, c = 0, b1 = 0, y = 0, o = 0, r = 0, dif = 0;
	loop(i, 0, n) {
		ll x;
		cin >> x;
		if (x >= 1 && x <= 399) {
			g = 1;
		}
		else if (x >= 400 && x <= 799) {
			b = 1;
		}
		else if (x >= 800 && x <= 1199) {
			gn = 1;
		}
		else if (x >= 1200 && x <= 1599) {
			c = 1;
		}
		else if (x >= 1600 && x <= 1999) {
			b1 = 1;
		}
		else if (x >= 2000 && x <= 2399) {
			y = 1;
		}
		else if (x >= 2400 && x <= 2799) {
			o = 1;
		}
		else if (x >= 2800 && x <= 3199) {
			r = 1;
		}
		else if (x > 3199) {
			dif++;
		}
	}
	int z = g + b + gn + c + b1 + y + o + r;
	cout << max(z,1) << " " << z + dif;


	return 0;
}

Measured memory_bytes: 256
N = int(input())
XY = []
for i in range(N):
  x,y = map(int,input().split())
  XY.append((x,y,i))
E = []
XY.sort()
for i in range(N-1):
  E.append((abs(XY[i+1][0] - XY[i][0]),XY[i][2],XY[i+1][2]))
XY = sorted(XY,key=lambda x:x[1])
for i in range(N-1):
  E.append((abs(XY[i+1][1] - XY[i][1]),XY[i][2],XY[i+1][2]))

*p, = range(N)
def root(x):
    if x == p[x]:
        return x
    p[x] = y = root(p[x])
    return y

def unite(x, y):
    px = root(x); py = root(y)
    if px == py:
        return 0
    if px < py:
        p[py] = px
    else:
        p[px] = py
    return 1

E.sort()
ans = 0
for c, v, w in E:
    if unite(v, w):
        ans += c
print(ans)

Measured memory_bytes: 47344
#include<bits/stdc++.h>
#define ll long long
#define MAX 1000000000
#define INF 1000000
#define M 1000000007
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std; 
int main(){
    fast_io
    ll n,k;
    cin>>n>>k;
    ll a[n];
    for(ll i = 0;i<n;i++) cin>>a[i];
    sort(a,a+n);
    ll sum = 0;
    for(ll i = 0;i<k;i++){
        sum += a[i];
    }
    cout<<sum<<endl;
    return 0;
}

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

#define rep(i, N) for (int i = 0; i < (N); i++)
#define all(a) (a).begin(), (a).end()
#define pb push_back

using ll = long long;
using i_i = tuple<int, int>;

int main() {
    int H, W; cin >> H >> W;
    int N; cin >> N;
    int mi = INT_MAX;
    rep(y, H + 1) rep(x, W + 1) {
        int z = y * W + x * H - y * x;
        if (z >= N) mi = min(mi, x + y);
    }
    cout << mi << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int a,b;
	scanf("%d",&a);
	scanf("%d",&b);
	if(a<b) {
		printf("a < b\n");
	}
	else if(a>b) {
		printf("a > b\n");
	}
	else {
		printf("a == b\n");
	}
	return 0;
}


Measured memory_bytes: 1968
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <utility>
#include <stack>
#include <queue>

typedef long long ll;
using namespace std;

int main(){
  ll i,j,k,n,m,c;
  cin >> n >> m >> c;
  ll b[m],cnt=0;
  for(i=0;i<m;i++)cin >> b[i];
  for(i=0;i<n;i++){
    ll ret = c;
    for(j=0;j<m;j++){
      cin >> k;
      ret+=k*b[j];
    }
    if(ret>0)cnt++;
  }
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 256
N = int(input())


def f(s):

	if int(s) > N:
		return 0
		
	if all([s.count(i) for i in '357']):
		ret = 1
	else:
		ret = 0
		
	for i in '357':
		ret += f(s + i)
	return ret
	
	
print(f('0'))


Measured memory_bytes: 2940
# -*- coding: utf-8 -*-
import numpy as np
from collections import deque
import collections
import heapq
# import time

n, m = list(map(int, input().split()))
a = [0] * m
b = [0] * m
path = [[] for i in range(n+1)]

for i in range(m):
    # a[i], b[i] = list(map(int, input().split()))
    a, b = list(map(int, input().split()))
    path[a].append(b)
    path[b].append(a)
# start = time.time()
# 部屋1から出発して、
ans = [0]*(n+1)
visited = []
que = deque([[1, 1]])  # 今の場所、前の場所
que_items = set([1])

# BFS
while len(que) > 0:
    now, prev = que.popleft()
    # print('pop', now)
    for can_go in path[now]:
        if(not (can_go in que_items)):  # ここが遅い
            # print('push', can_go)
            que.append([can_go, now])
            que_items.add(can_go)
    ans[now] = prev
    visited.append(now)
    # print(visited)

if (len(visited) != n):
    print('No')
else:
    print('Yes')
    for _ans in ans[2:]:
        print(_ans)

# print(time.time() - start)


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

using namespace std;

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

  int ans = 0;
  int r = s.size()-1;
  int l = 0;
  for(int i=0; true; i++){
    if( r <= l ) break;
    if( s.at(r) != s.at(l) ) ans++;
    r--;
    l++;
  }

  std::cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 888
import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, std.bitmanip;

immutable long MOD = 10^^9 + 7;
immutable long INF = 1L << 59;
int[4] dr = [0, 0, 1, -1];
int[4] dc = [1, -1, 0, 0];

void main() {
    auto s = readln.split.map!(to!int).array;
    auto H = s[0];
    auto W = s[1];
    auto A = H.iota.map!(_ => readln.chomp).array;

    auto q = new DList!(Tuple!(int, int, int));
    q.insertBack(tuple(0, 0, 0));
    auto used = new bool[][](H, W);
    int ans = 1 << 29;

    int cnt = 0;
    foreach (i; 0..H) foreach (j; 0..W) cnt += A[i][j] == '#';

    while (!q.empty) {
        auto t = q.front;
        q.removeFront;
        int r = t[0];
        int c = t[1];
        int d = t[2];
        if (r == H-1 && c == W-1) {
            ans = d;
            break;
        }
        if (used[r][c]) continue;
        used[r][c] = true;
        foreach (i; 0..4) {
            int nr = r + dr[i];
            int nc = c + dc[i];
            if (nr < 0 || nr >= H || nc < 0 || nc >= W || A[nr][nc] == '#' || used[nr][nc]) continue;
            q.insertBack(tuple(nr, nc, d+1));
        }
    }

    if (ans >= 1 << 29) {
        writeln(-1);
    } else {
        writeln(H * W - cnt - ans - 1);
    }
}


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

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

    int n;
    cin >> n;
    int w[110];
    rep(i, n) {
        cin >> w[i];
    }

    int min = 1000000;
    rep(i, n) {
        int g1 = 0, g2 = 0;
        rep(j, n) {
            if (j <= i) g1 += w[j];
            else g2+= w[j];
        }
        g2 -= g1;
        if (g2 < 0) g2 = -g2;
        if (min > g2) min = g2;
    }
    cout << min << endl;
}

Measured memory_bytes: 3640
import java.util.*;

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

      while(true) {
        int a = sc.nextInt();
        String op = sc.next();
        int b = sc.nextInt();
        if (op.equals("?")) {
          break;
        }
        if (op.equals("+")) {
          System.out.println(a + b);
        } else if (op.equals("-")) {
          System.out.println(a - b);
        } else if (op.equals("*")) {
          System.out.println(a * b);
        } else {
          System.out.println((int) Math.floor(1.0 * a / b));
        }
      }

      sc.close();
  }
}


Measured memory_bytes: 26244
S = input()
T = input()

len_T = len(T)
len_S = len(S)
output = len_T

for i in range(len_S-len_T+1):
    diff = 0
    for j in range(len_T):
        if T[j] != S[i+j]:
            diff += 1
    output = min(output, diff)

print(output)

Measured memory_bytes: 9056
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <algorithm>

using namespace std;
using ll = long long;
using ld = long double;

int main() {

    int N;
    cin >> N;
    if(N == 1){
        cout << "Hello World" << endl;
    }else{
        int a,b;
        cin >> a >> b;
        cout << a+b << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
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; }

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    rep(i,s.size()){
        if(i%2 == 0) cout << s[i];
    }
    cout << endl;
	return 0;
}

Measured memory_bytes: 592
MOD=10**9+7
cnt=0; sum=0; prev=nil; can=true; h=Hash.new(0)
def gs() gets.chomp end
def gi() gets.to_i end
def gsmi() gets.chomp.split.map(&:to_i) end

def desc(ar) ar.sort!{|x,y|y<=>x} end
def min(a,b) a<=b ? a : b end
def max(a,b) a>=b ? a : b end
def sum(ar) ar.inject(:+) end
def bs(ar,eq,n) en=(eq==1 ? :>= : :>); ar.bsearch_index{|x|x.send(en,n)} end

def puts_yesno(can) puts(can ? 'Yes' : 'No') end
def putsend(s) puts s; exit end
def debug(k,v) puts "#{k}:#{v}" end
########### ( ˘ω˘ )ｽﾔｧ… ###########
n = gi
v = gsmi

h1=Hash.new(0)
h2=Hash.new(0)

n.times do |i|
  if i%2==0
    h1[v[i]]+=1
  else
    h2[v[i]]+=1
  end
end

h1=h1.to_a.sort!{|x,y|y[1]<=>x[1]}
h2=h2.to_a.sort!{|x,y|y[1]<=>x[1]}
min = 0
#debug(:h1,h1.to_s)
#debug(:h2,h2.to_s)
if h1[0][0]==h2[0][0]
  if h1.size==1 && h2.size==1
    min = n/2
  elsif h1.size==1
    min = n-h1[0][1]-h2[1][1]
  elsif h2.size==1
    min = n-h1[1][1]-h2[0][1]
  else
    min = min(n-h1[1][1]-h2[0][1],n-h1[0][1]-h2[1][1])
  end
else
  min = n-h1[0][1]-h2[0][1]
end

puts min


Measured memory_bytes: 20304
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<vector>
#include<functional>
#include<algorithm>
#include<stdlib.h>
#include<string>
#include<string.h>
#define _USE_MATH_DEFINES
#include<math.h>
#include<deque>
#include<set>
#include<map>
#include<queue>
#include<list>
#include<iostream>
#include <bitset>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(auto i=a;i<b;i++)
#define all(_x) _x.begin(), _x.end()
#define r_sort(_x) sort(_x.begin(), _x.end(), std::greater<int>())
#define vec_cnt(_a, _n) (upper_bound(all(_a), _n) - lower_bound(all(_a), _n))
#define vec_unique(_a) _a.erase(std::unique(all(_a)), _a.end());
#define vvec vector<vector<ll>>
ll gcd(ll a, ll b) { return a % b == 0 ? b : gcd(b, a % b); }
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }
#define INF 1 << 30
const int mod = 1000000007;
ll power(ll x, ll p) { ll a = 1; while (p > 0) { if (p % 2 == 0) { x *= x; p /= 2; } else { a *= x; p--; } }return a; }
ll mpower(ll x, ll p) { ll a = 1; while (p > 0) { if (p % 2 == 0) { x = x * x % mod; p /= 2; } else { a = a * x % mod; p--; } }return a; }
ll ac(ll n, ll k) { ll a = 1; rep(i, 1, k) { a *= n - i + 1; a /= i; }return a; }
ll mc(ll n, ll m) { ll k = 1, l = 1; rep(i, n - m + 1, n + 1) k = k * i % mod; rep(i, 1, m + 1) l = l * i % mod; l = mpower(l, mod - 2); return k * l % mod; }

int main()
{
	ll n, i;
	cin >> n;
	vector<ll> a(n + 1), l(n + 1), r(n + 1);
	rep(i, 0, n + 1)cin >> a[i];
	l[n] = r[n] = a[n];
	for (i = n - 1; i >= 0ll; i--) {
		l[i] = a[i] + (l[i + 1] + 1) / 2;
		r[i] = a[i] + r[i + 1];
	}
	if (l[0] > 1ll) {
		puts("-1");
		return 0;
	}
	ll c = 1, ans = 0;
	for (i = 0ll; i < n; i++) {
		ans += c;
		c -= a[i];
		c = min(c * 2, r[i + 1]);
	}
	printf("%lld\n", ans + c);
	return 0;
}


Measured memory_bytes: 5636
s = [[ int(i) for i in input().split(" ")] for _ in range(3)]

sum = s[0][0] + s[1][1] + s[2][2]

fail = 0

if s[0][0] + s[1][2] + s[2][1] != sum:
  fail = 1
if s[1][1] + s[0][2] + s[2][0] != sum:
  fail = 1
if s[2][2] + s[0][1] + s[1][0] != sum:
  fail = 1
  
if fail == 0:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 3064
#include<stdio.h>

#define N 100000

int partition(int,int);

int A[N];
int x;

int main() {
  int i,res;

  scanf("%d",&x);
  for(i = 0; i < x; i++) {
    scanf("%d",&A[i]);
  }

  res = partition(0,x - 1);

  for(i = 0; i < x; i++) {
    if(i) {
      printf(" ");
    }
    if(i == res) {
      printf("[");
    }
    printf("%d",A[i]);
   
    if(i == res) {
      printf("]");
    }
    
  }
  printf("\n");
  return 0;
}

int partition(int a, int b) {
  int y,i,j,t;

  y = A[b];
  i = a - 1;

  for(j = a; j < b; j++) {
    if(A[j] <= y) {
      i++;
      t = A[i];
      A[i] = A[j];
      A[j] = t;
    }
  }

  t = A[i + 1];
  A[i + 1] = A[b];
  A[b] = t;

  return i + 1;
}
  



Measured memory_bytes: 2132
#define NDEBUG

#include <algorithm>
#include <cassert>
#include <cstdlib>
#include <iostream>
using namespace std;

#define ALL(x) begin(x), end(x)

char   Letter(string::const_iterator&);
string String(string::const_iterator&);
string Cipher(string::const_iterator&);

char Letter(string::const_iterator &it) {
	if(*it == '+') {
		++it;
		char res = Letter(it);
		if(res != '?' && ++res > 'Z') res = 'A';
		return res;
	}
	else if(*it == '-') {
		++it;
		char res = Letter(it);
		if(res != '?' && --res < 'A') res = 'Z';
		return res;
	}
	else if(isupper(*it) || *it == '?') {
		const char res = *it;
		++it;
		return res;
	}
	assert(false);
}

string String(string::const_iterator &it) {
	if(*it == '[') {
		++it;
		string res = Cipher(it);
		assert(*it == ']');
		++it;
		reverse(ALL(res));
		return res;
	}
	return string(1, Letter(it));
}

string Cipher(string::const_iterator &it) {
	string res = "";
	while(*it != '\0' && *it != ']') {
		res += String(it);
	}
	return res;
}

string parse(const string &text) {
	auto it = text.cbegin();
	string res = Cipher(it);
	assert(it == text.cend());

	for(auto &e : res) {
		if(e == '?') e = 'A';
	}
	return res;
}

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

	for(string text; cin >> text && text != ".";) {
		cout << parse(text) << endl;
	}
	return EXIT_SUCCESS;
}

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

#define fi first
#define se second
#define sz(a) (int)(a).size()
#define all(a) (a).begin(), (a).end()
#define reset(a, v) memset((a), v, sizeof(a))

using namespace std;

typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ii> vii;

const int N = 10005;
const int MAX = 1000005;
const int MOD = (int)1e9 + 7;

int n;
int dat[N];
int mx[MAX];
vll primes;
bitset<MAX> isPrime;

void sieve() {
	isPrime.set();
	for (ll i = 2; i < MAX; i++) {
		if (isPrime[i]) {
			primes.push_back(i);
			for (ll j = i * i; j < MAX; j += i) {
				isPrime[j] = 0;
			}
		}
	}
}

void process(int x) {
	int cur = 0;
	while (primes[cur] * primes[cur] <= x) {
		if (x % primes[cur] == 0) {
			int cnt = 0;
			while (x % primes[cur] == 0) {
				cnt++;
				x /= primes[cur];
			}
			mx[primes[cur]] = max(mx[primes[cur]], cnt);
		}
		cur++;
	}

	if (x != 1) {
		mx[x] = max(mx[x], 1);
	}
}

ll fastExp(ll base, int p) {
	ll ret = 1;
	while (p) {
		if (p & 1) {
			ret *= base;
			ret %= MOD;
		}
		base *= base;
		base %= MOD;
		p >>= 1;
	}
	return ret;
}

int main() {
	sieve();
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d", &dat[i]);
		process(dat[i]);
	}
	ll lcm = 1;
	for (int i = 1; i < MAX; i++) {
		if (!isPrime[i] || mx[i] == 0) continue;
		lcm *= fastExp(i, mx[i]);
		lcm %= MOD;
	}
	// printf("lcm = %lld\n", lcm);
	ll ans = 0;
	for (int i = 0; i < n; i++) {
		ll add = lcm * fastExp(dat[i], MOD-2);
		add %= MOD;
		ans = (ans + add) % MOD;
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 3700
// 1:45
#include <iostream>
#include <cstring>
#include <cmath>
#include <string>
#include <algorithm>
#include <utility>
#include <vector>
#include <set>
#include <map>
#include <deque>
#include <tuple>
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using pll = pair<ll,ll>;
using tll = tuple<ll,ll,ll>;
#define pb push_back
#define for1(i,n) for (ll i=0;i<(n);i++)
#define for2(i,m,n) for (ll i=(m);i<(n);i++)
#define for3(i,m,n,d) for (ll i=(m);i<(n);i+=(d))
#define INF (1LL << 60)
#define DEBUG 0
#if DEBUG
    #define dump(v1) dump_1(#v1, v1)
    #define dump2(v1,v2) dump_2(#v1, v1, #v2, v2)
    #define dump3(v1,v2,v3) dump_3(#v1, v1, #v2, v2, #v3, v3)
#else
    #define dump(v1)
    #define dump2(v1,v2)
    #define dump3(v1,v2,v3)
#endif
#if DEBUG
template <typename T>
void dump_1(const string& n1, const T& v1)
{
    cerr << n1 << ": " << v1 << endl;
}
template <typename T1, typename T2>
void dump_2(const string& n1, const T1& v1, const string& n2, const T2& v2)
{
    cerr << n1 << ": " << v1 << "  " << n2 << ": " << v2 << endl;
}
template <typename T1, typename T2, typename T3>
void dump_3(const string& n1, const T1& v1, const string& n2, const T2& v2, const string& n3, const T3& v3)
{
    cerr << n1 << ": " << v1 << "  " << n2 << ": " << v2 << "  " << n3 << ": " << v3 << endl;
}
template <typename T1,typename T2>
ostream& operator << (ostream& os, const pair<T1,T2>& v)
{
    os << "(" << v.first << ", " << v.second << ")";
    return os;
}
template <typename T1,typename T2, typename T3>
ostream& operator << (ostream& os, const tuple<T1,T2,T3>& v)
{
    os << "(" << get<0>(v) << ", " << get<1>(v) << ", " << get<2>(v) << ")";
    return os;
}
template <typename T>
ostream& operator << (ostream& os, const vector<T>& v)
{
    os << "[";
    for (auto it = v.begin(); it != v.end(); it++) {
        if (it != v.begin()) {
            os << ", ";
        }
        os << *it;
    }
    os << "]";
    return os;
}
template <typename T>
ostream& operator << (ostream& os, const set<T>& v)
{
    os << "{";
    for (auto it = v.begin(); it != v.end(); it++) {
        if (it != v.begin()) {
            os << ", ";
        }
        os << *it;
    }
    os << "}";
    return os;
}
template <typename T1, typename T2>
ostream& operator << (ostream& os, const map<T1,T2>& v)
{
    os << "{";
    for (auto it = v.begin(); it != v.end(); it++) {
        if (it != v.begin()) {
            os << ", ";
        }
        os << it->first << ":" << it->second;
    }
    os << "}";
    return os;
}
#endif // DEBUG
template <typename T>
void print(const T& v)
{
    cout << v << endl;
}
//---------------------------------------------------------

void solve()
{
    ll a;
    set<ll> s;
    for1(i,3) {
        ll a;
        cin >> a;
        s.insert(a);
    }

    print(s.size());
}

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


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

#define rep(i,a,b) for(ll i=(a);i<=(b);i++)
#define END(x) do{cout<<(x)<<endl;exit(0);}while(0)
#define debug(x)  do{cerr<<#x<<": "<<x<<"\n";}while(0)
#define debugv(x) do{cerr<<#x<<": ";for(auto&e: (x))cerr<<e<<" ";cerr<<"\n";}while(0)
#define exp2(x)  (1LL<<(x))

using namespace std;
using ll=long long;


int main() {
  ios_base::sync_with_stdio(false); cin.tie(nullptr);
  int N, L;  cin >> N >> L;
  int lb = L + 1 - 1;
  int ub = L + N - 1;
  int f = (lb+ub)*N/2;
  if (lb <=0 and 0 <= ub) END(f-0);
  if (lb > 0) END(f-lb);
  if (ub<0) END(f-ub);
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program
{
    static void Main(string[] args)
    {
            // 入力
            string[] sS = System.Console.ReadLine().Trim().Split(' ');
            int iA = int.Parse(sS[0]);
            int iB = int.Parse(sS[1]);

            System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
            sw.Start();

            // 解析
            int iOut = 0;                           // Tap数
            if (iB > 1)                             // 1個必要な時はTapは必要なし
            {
                int iSum = 1;
                while (true)                        // タップを追加する
                {
                    iSum -= 1;                      // 1穴潰して
                    iSum += iA;                     // A穴増やす
                    iOut += 1;                      // Tapの数+1
                    if (iSum >= iB) { break; }      // 要求数以上で抜ける
                }
            }

            // 出力
            System.Console.WriteLine("{0}", iOut.ToString().Trim());

            sw.Stop();
#if DEBUG
            Console.WriteLine();
            Console.WriteLine("{0}", sw.Elapsed.ToString());
            Console.WriteLine("続行するには何かキーを押してください．．．");
            Console.ReadKey();
#endif
    }

}


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

typedef long long LL;
const int MAXN = 100010;
const LL INF = 0x3f3f3f3f3f3f3f3fLL;
int at[MAXN], T, n, E;
LL f[MAXN];
int main() {
	std::ios_base::sync_with_stdio(false), std::cin.tie(0);
	std::cin >> n >> E >> T;
	int cur = 0; LL pre = INF;
	for (int i = 1; i <= n; ++i) {
		std::cin >> at[i];
		while (2 * (at[i] - at[cur + 1]) >= T)
			pre = std::min(pre, f[cur] - 2 * at[cur + 1]), ++cur;
		f[i] = std::min(pre + 2 * at[i], f[cur] + T);
	}
	std::cout << f[n] + E << std::endl;
	return 0;
}


Measured memory_bytes: 1408
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <queue>
#include <algorithm>
#include <string.h>
using namespace std;
typedef pair<int,int> P;

#define INF 1000000
struct road{int to,cost;};

int main(){
  while(1){
    vector<road> roads[10];
    int d[10];
    int n,m;

    cin >> n;
    if(!n)break;
    m = 0;
    for(int i=0;i<n;i++){
      int x,y,z;
      scanf("%d%d%d",&x,&y,&z);
      if(m<x||m<y){
        m = max(x,y);
      }
      roads[x].push_back((road){y,z});
      roads[y].push_back((road){x,z});
    }
    m++;

    int minIndex;
    int mini = INF;
    for(int i=0;i<m;i++){
      priority_queue<P, vector<P>, greater<P> > que;
      que.push(P(0,i));
      fill(d,d+m,INF);
      d[i] = 0;
      while(que.size()){
        P p = que.top(); que.pop();
        int dist = p.first;
        int pos = p.second;
        if(d[pos]<dist) continue;
        for(int j=0;j<roads[pos].size();j++){
          int to = roads[pos][j].to;
          int cost = roads[pos][j].cost;
          if(d[to]>d[pos]+cost){
            d[to] = d[pos] + cost;
            que.push(P(d[to],to));
          }
        }
      }
      int sum = 0;
      for(int j=0;j<m;j++){
        //printf("%3d%c",d[j],j==m-1?'\n':' ');
        sum += d[j];
      }
      if(mini>sum){
        mini = sum;
        minIndex = i;
      }
    }
    cout << minIndex << " " << mini << endl;
  }
}

Measured memory_bytes: 1268
#include <iostream>
#include <algorithm>
#include <cstdlib>

using namespace std;

int main(){
  int N;
  int h[100001] = {0};
  int cost1to[100001] = {0};
  int cost2to[100001] = {0};
  int mincostto[100001] = {0};
  cin >> N;
  for(int i=1; i <= N; i++){
    cin >> h[i];
  }
  cost1to[1] = 0;
  cost1to[2] = abs(h[2]-h[1]);
  cost2to[1] = 0;
  cost2to[2] = 1000000000;
  cost2to[3] = abs(h[3]-h[1]);
  mincostto[1] = 0;
  mincostto[2] = cost1to[2];
  for(int i=3; i <= N; i++){
    cost1to[i] = abs(h[i] - h[i-1]);
    cost2to[i] = abs(h[i] - h[i-2]);
  }
  for(int i=3; i <= N; i++){
    mincostto[i] = min(mincostto[i-1]+cost1to[i],mincostto[i-2]+cost2to[i]);
  }
  cout << mincostto[N];
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define ll long long

using namespace std;

struct Node
{
    int data;
    struct Node* left;
    struct Node* right;
    Node(int x)
    {
        data=x;
        left=NULL;
        right=NULL;
    }
};
#define Node struct Node

ll modpow(ll a, ll n)
{
    ll m=1e9+7;
    if(n==0)
        return 1;
    ll y=modpow(a,n/2)%m;
    if(n%2==0)
        return (y*y)%m;
    return (((y*y)%m)*a)%m;
}

int main()
{
    int t=1;
    //cin>>t;
    while(t--)
    {
        ll n;
        cin>>n;
        ll x[n],y[n];
        for(int i=0;i<n;i++)
        {
            cin>>x[i]>>y[i];
        }
        ll p[n],q[n];
        for(int i=0;i<n;i++)
        {
            p[i]=x[i]+y[i];
            q[i]=x[i]-y[i];
        }
        sort(p,p+n);
        sort(q,q+n);
        cout<<max(p[n-1]-p[0],q[n-1]-q[0])<<endl;
    }
    return 0;
}







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

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

template<class T> inline T sqr(T x) {return x*x;}

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef long long ll;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())

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

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const long long INF = 1000000007;

#define CLR(a) memset((a), 0 ,sizeof(a))

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

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(void){
    int N; cin >> N;
    double p[N]; REP(i,N) cin >> p[i];

    double dp[N+1][N+1]; REP(i,N+1)REP(j,N+1) dp[i][j] = 0; dp[0][0] = 1.0;
    REP(i,N)REP(j,i+1){
        dp[i+1][j+1] += dp[i][j] * p[i];
        dp[i+1][j] += dp[i][j] * (1.0-p[i]);
    }
    double ans = 0;
    FOR(i,(N+1)/2,N+1) ans += dp[N][i];
    cout << fixed << setprecision(10) << ans << endl;
    return 0;
}

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


#define fast_IO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl '\n'
#define pb push_back
#define F first
#define S second
#define int long long int
#define ll long long
#define ld long double

bool isPrime(ll n){if(n<2)return false;for(ll i=2;i*i<=n;++i){if(n%i==0){return false;}}return true;}

ll lcm(ll x,ll y){
    return (x*y)/(__gcd(x,y));
}

ll nod(ll n){
    while(n%10==0){
        n/=10;
    }
    return n;
}


signed main(){
    fast_IO;
    int t=1;
    //cin>>t;
    while(t--){
        int n;
        cin>>n;
        string s;
        cin>>s;
        int r=0,w=0;
        for(int i=0;i<n;i++){
            if(s[i]=='R')
                r++;
            else
                w++;
        }
        string ans;
        for(int i=0;i<r;i++){
            ans+='R';
        }
        for(int i=0;i<w;i++){
            ans+='W';
        }
        int cnt=0;
        for(int i=0;i<n;i++){
            if(s[i]!=ans[i])
                cnt++;
        }
        cout<<cnt/2;
    }
    return 0;
}



Measured memory_bytes: 3876