akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F(i, a, b) for (int i = (a); i <= (b); i++)
#define D(i, a, b) for (int i = (a); i >= (b); i--)
#define R(i, a, b) for (int i = (a); i < (b); i++)
#define N 500000
#define ALL(vt) vt.begin(), vt.end()
ll tachso(int n){
    ll ans = 0;
    ans += (n / 500) * 1000;
    n = n - (n/500)*500;
    ans += (n/5)*5;
    return ans;
}
int main(){
    int n; cin >> n;
    cout << tachso(n);
    
}

Measured memory_bytes: 256
#include<stdio.h>

static const int N = 1000;

void trace(int A[], int n){
  int i;
  for ( i = 1; i <= n; i++ ){
    if ( i > 1 ) printf(" ");
    printf("%d", A[i]);
  }
  printf("\n");
}

int main(){
  int n, i, j, key;
  int A[N+1];
  scanf("%d", &n);

  for ( i = 1; i <= n; i++ ) scanf("%d", &A[i]);
  
  trace(A, n);
  
  for( i = 2; i <= n; i++){
    key = A[i];
    j = i - 1;
    while(j >= 0 && A[j] > key){
      A[j+1] = A[j];
      j--;
      A[j+1] = key;
    }
    trace(A,n);
  }

  return 0;
}

Measured memory_bytes: 608
#include<iostream>
#include<string>
#include<algorithm>    
#include<cmath>
#include<map>
#include<vector>
#include<math.h>
#include<stdio.h>
#include<stack>
#include<queue>
#include<tuple>
#include<cassert>
#include<set>
#include<functional>
//#include<bits/stdc++.h>
using ll = long long;
using ld = long double;
using namespace std;
const ll INF = 1000000000000000000;
const ll mod = 1000000007;
const ld pi = 3.141592653589793238;
//printf("%.10f\n", n);

ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (a % b == 0)return b;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}
ll modpow(ll x, ll y) {
	ll res = 1;
	while (y) {
		if (y % 2) { res *= x; res %= mod; }
		x = x * x % mod; y /= 2;
	}
	return res;
}

ll test[12345678];
signed main() {
	/*ll n, x, l, q, a = 0, b = 0, c = 0, d = 0, ans = 0; cin >> n >> x;
	for (int h = 0; h < n; h++) {
		cin >> test[h];
		if (test[h] % 2 == 0) { a++; }
		else { b++; }
	}
	b /= 2; a += b;
	cout << modpow(2, a) << endl;*/
	ll D, c, s; cin >> D;
	for (int h = 0; h < 26; h++) {
		cin >> c;
	}
	for (int i = 0; i < D; i++) {
		for (int h = 0; h < 26; h++) {
			cin >> s;
		}
	}
	for (int h = 0; h < D; h++) {
		ll cnt = h % 26 + 2;
		if (cnt >= 27) { cnt -= 26; }
		cout << cnt << endl;
	}
	return 0;
}

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

int main()
{
	int n;
	cin >> n;
	vector<int> as(n);
	for (auto &a : as)
	{
		cin >> a;
	}
	as.emplace_back(1e9);
	int ans = 0;
	for (int i = 1, j = 1; i <= n; i++)
	{
		if (as[i] != as[i - 1])
		{
			ans += j / 2;
			j = 1;
		}
		else
		{
			j++;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <deque>
#include <bitset>
#include <iomanip>
#include <limits>
#include <chrono>
#include <random>
#include <array>
#include <unordered_map>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const long long MAX = 5100000;
const long long INF = 1LL << 60;
const long long MOD = 1'000'000'007LL;
const long long mod = 998244353LL;

using namespace std;
typedef unsigned long long ull;
typedef long long ll;


int main()
{
	/*
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	*/
	ll MAX = 1050;
	ll N; scanf("%lld", &N);
	vector<vector<ll>> cnt(MAX, vector<ll>(MAX));
	for (ll i = 0; i < N; i++) {
		ll x1, y1, x2, y2; scanf("%lld %lld %lld %lld", &x1, &y1, &x2, &y2);
		cnt[x1][y1]++;
		cnt[x2][y1]--;
		cnt[x1][y2]--;
		cnt[x2][y2]++;
	}

	for (ll i = 0; i < MAX - 1; i++) {
		for (ll j = 0; j < MAX; j++) {
			cnt[i + 1][j] += cnt[i][j];
		}
	}
	for (ll j = 0; j < MAX - 1; j++) {
		for (ll i = 0; i < MAX; i++) {
			cnt[i][j + 1] += cnt[i][j];
		}
	}

	ll res = 0;
	for (ll i = 0; i < MAX; i++) {
		for (ll j = 0; j < MAX; j++) {
			chmax(res, cnt[i][j]);
		}
	}
	cout << res << endl;
	return 0;
}


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

#define ii pair<int, int>
#define lli long long int
#define ll pair<lli, lli>
#define pb push_back
#define mp make_pair
#define fi first
#define se second

using namespace std;

int main() {
	int n, a, cnt = 1;
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d", &a);
		if (a == cnt)
			cnt++;
	}
	if (cnt == 1)
		puts("-1");
	else
		printf("%d\n", n - cnt + 1);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <vector>
#include <iterator>
#include <cmath>

using namespace std;

int main(){
	
	int n;
	
	cin >> n;
	
	double d[1000] = {};
	double r[1000] = {};
	
	for(int i = 0; i < n; i++){
		cin >> r[i];
		double dist = 0;
		for(int j = 0; j < i; j++){
			dist = max(dist, d[j] + sqrt((r[i] + r[j]) * (r[i] + r[j]) - (r[i] - r[j]) * (r[i] - r[j])) );
		}
		d[i] = dist;
	}
	
	double le = 0;
	double ri = d[n - 1];
	
	for(int i = 0; i < n; i++){
		le = min(le, d[i] - r[i]);
		ri = max(ri, d[i] + r[i]);
	}
	
	printf("%.8f\n", ri - le);
	
	return 0;
}

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

int main()
{
  int n;
  int min_n = 1000001;
  int max_n = -1000001;
  long long sum = 0;

  cin >> n;
  for (int i = 0; i < n; i++)
  {
    int a;
    cin >> a;
    min_n = min(min_n, a);
    max_n = max(max_n, a);
    sum += a;
  }
  cout << min_n << " " << max_n << " " << sum << endl;
}



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

int main() {
    int a, b; cin >> a  >> b;
    bool ok = false;
    int ans = 0;
    rep(i,10001) {
        int f = i * 0.08;
        int s = i * 0.10;
        if(f==a && s==b) ok = true;
        if(ok) {
            ans = i;
            break;
        }
    }
    if(ok) cout << ans;
    else cout << -1;
}


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

#define ALL(a) begin(a),end(a)
#define COUNTOF(a) (sizeof(a)/sizeof(a[0]))
#define SP << " " <<
#define FMT(a) #a<<":"<<a 
#define FMT2(a,b) #a<<":"<<a<<", "<<#b<<":"<<b 
#define FMT3(a,b,c) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c 
#define FMT4(a,b,c,d) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c<<", "<<#d<<":"<<d 
typedef long long ll;
template<class T> istream& operator >> (istream& s, vector<T>& v) {
  for (T& x: v) s >> x;
  return s;
}
inline void Yes(bool f=true){cout<<(f?"Yes":"No")<<endl;}
inline void YES(bool f=true){cout<<(f?"YES":"NO")<<endl;}

int main()
{
    cin.tie(0); ios::sync_with_stdio(false);
    //cout<<std::fixed<<std::setprecision(10);

    string a,b; cin >> a>>b;
    

    cout << (a=="H"?b:(b=="H"?"D":"H")) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#ifdef _IS_LOCAL //
#define dout cout
#define debug() if (true)
#else
#define dout   \
	if (false) \
	cout
#define debug() if (false)
#endif //
#define next asdnext
#define prev asdprev
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define vrep(i, v) for (auto &i : v)
#define all(x) (x).begin(), (x).end()
#define vout(v)           \
	for (auto &i : v)     \
	{                     \
		cout << i << " "; \
	}                     \
	cout << "\n"; //配列出力
#define vin(v)        \
	for (auto &i : v) \
		cin >> i; //配列入力
#define vec(v, n) vector<int> v(n, 0);
#define mod (int)(1e9+7)
typedef long long ll;
typedef unsigned long long ull;
void Main()
{
	int N;
	cin>>N;
	int ans = 0;
	int mul=10;
	int cnt = 0;

	for(int i = 1; i <= N; i++){
		if(mul <= i){
			cnt++;
			mul *= 10;
		}
		if(!(cnt%2)){
			ans++;
		}
	}
	cout<<ans<<endl;
}
 
int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << std::fixed << std::setprecision(15);
	Main();
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	long long a,b;
	char c;
	long long op(long long a ,long long b,char c);
	scanf("%lld %c %lld",&a,&c,&b);
	op(a,b,c);
	printf("%lld\n",op(a,b,c));
	return 0;
}
long long op(long long a,long long b,char c)
{
	long long sum=0;
	if(c=='+') sum=a+b;
	if(c=='-') sum=a-b;
	return (sum);
}

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

int main(){
    int l, r, d;
    cin >> l >> r >> d;
    int ans = 0;
    for(int i  = l; i <= r; i++){
        if(i % d == 0) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A, B, C;
  cin>>A >> B>> C;
  if(A+B+C==17&&A*B*C==175&&A*B+A*C+B*C==95){
    cout <<"YES"<<endl;
  }
  else{
    cout <<"NO"<<endl;
  }
}


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

#define int long long
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rep1(i,n) for(int i=1;i<=(int)(n);++i)
#define rep11(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define repm(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define pb(n) push_back(n)
#define mp make_pair
#define MOD 1000000007
#define INF LONG_LONG_MAX

int n,k,s;

signed main() {
    cin >> n >> k >> s;
    rep(i,k) cout << s << " ";
    if (s > 100000) rep(i,n-k) cout << 1 << " ";
    else rep(i,n-k) cout << s+1 << " ";
    cout << endl;
}



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

using namespace std;
#define ll long long int
#define rep(i,n) for(i=0;i<(n);i++)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(c) c.begin(),c.end()
#define endl "\n"
typedef pair< ll, ll > lpair;

bool sortbysec(const pair<int,int> &a, const pair<int,int> &b)
{
    if(a.ff == b.ff)
        return (a.ss < b.ss);
    return (a.ff < b.ff);
}

vector< ll > prime(1000005,1);
void p()
{
    ll i,j;
    for(i=2;i<=1000000;i++)
    {
        if(prime[i] == 1)
        {
            for(j = 2*i;j<=1000000;j+=i) prime[j] = 0;
        }
    }
}

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

    ll n,i,j;
    cin>>n;
    vector< double > p(n+1);

    rep(i,n) cin>>p[i+1];

    double dp[n+1][n+1];

    for(i = 0;i<=n;i++) dp[0][i] = 0;
    dp[1][0] = 1 - p[1];
    dp[1][1] = p[1];
    for(i = 1;i<=n;i++)
    {
        for(j = 0;j<=n;j++)
        {
            if(i == 1 && j == 0) continue;
            if(i == 1 && j == 1) continue;
            dp[i][j] = dp[i-1][j] * (1-p[i]);
            if(j-1 >= 0) dp[i][j] += dp[i-1][j-1] * p[i];
        }
    }

    // for(i = 0;i<=n;i++)
    // {
    //     for(j = 0;j<=n;j++)
    //     {
    //         cout<<dp[i][j]<<" ";
    //     }
    //     cout<<endl;
    // }
    double ans = 0;

    for(i = n/2 + 1;i<=n;i++)
        ans += dp[n][i];
    cout<<setprecision(10)<<ans<<endl;

    return 0;
}

Measured memory_bytes: 78464
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#ifndef LOCAL
#define debug(x) ;
#else
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

template <typename T1, typename T2>
ostream &operator<<(ostream &out, const pair<T1, T2> &p) {
  out << "{" << p.first << ", " << p.second << "}";
  return out;
}

template <typename T>
ostream &operator<<(ostream &out, const vector<T> &v) {
  out << '{';
  for (const T &item : v) out << item << ", ";
  out << "\b\b}";
  return out;
}
#endif

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 51

ll dp[SIZE][SIZE][2*SIZE*SIZE];

int main() {
  int N, K;

  cin >> N >> K;

  dp[0][0][0] = 1;

  for (int i=0; i<N; i++) {
    for (int j=0; j<=i; j++) {
      for (int k=0; k<=2*i*i; k++) {
        // {i, i}
        dp[i+1][j][k+j*2] = (dp[i+1][j][k+j*2] + dp[i][j][k]) % mod;

        // {x, x}, {x, x}
        dp[i+1][j+1][k+(j+1)*2] = (dp[i+1][j+1][k+(j+1)*2] + dp[i][j][k]) % mod;

        // {i, 0}, {x, x}
        if (j > 0)
          dp[i+1][j][k+j*2] = (dp[i+1][j][k+j*2] + dp[i][j][k] * j * 2) % mod;

        // {i, 0}, {0, i}
        if (j > 0)
          dp[i+1][j-1][k+(j-1)*2] = (dp[i+1][j-1][k+(j-1)*2] + dp[i][j][k] * j % mod * j) % mod;
      }
    }
  }

  cout << dp[N][0][K] << endl;

  return 0;
}


Measured memory_bytes: 103936
def main():
    n = int(input())
    al = list(map(int, input().split(' ')))
    
    for i in range(n):
        v = al[i]
        j = i - 1
        while j >= 0 and al[j] > v:
            al[j + 1] = al[j]
            j -= 1
        al[j + 1] = v
        print(' '.join(list(map(str, al))))


if __name__ == '__main__':
    main()


Measured memory_bytes: 5604
import java.util.*;

public class Main {


    public static void main(String[] args) {

        Scanner scan = new Scanner(System.in);
        int s    = scan.nextInt();


        if(s == 4 || s == 2 || s == 1){
            System.out.println(4);
            return;
        }


        int input=s;
        int output=0;
        int i = 1;
        while(true){

            i++;

            if(input % 2 == 0 ){

                output = input/2;

            }else{

                output = input*3 + 1;

            }

            if(output == 4){
                System.out.println(i + 3);
                return;
            }

            input = output;
        }
    }
}


Measured memory_bytes: 23124
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define enld '\n'
#define rep(i,n) for(int i=0; i<(n); i++)
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("Ofast")
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[6] = {1, 0, -1, 0,1,-1};
const int dy[6] = {0, 1, 0, -1,1,-1};
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(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int temp = 0;
    for(int i=0; i<3; i++){
        temp *= 10;
        int a;
        cin >> a;
        temp += a;
    }
    if(temp%4){
       cout << "NO" << endl; 
    }else{
        cout <<"YES" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define mod 1000000007
#define pb push_back 
#define ll long long
using namespace std;
int main()
 {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
	ll a,b;
	cin>>a>>b;
	if((a+b)%2 == 0) cout<<(a+b)/2;
	else cout<<"IMPOSSIBLE";
	cout<<endl;
	return 0;
}

Measured memory_bytes: 256
n, w = map(int, input().split())
items = []

append = items.append
for i in range(n):
    append(list(map(int, input().split())))


def knapsack(n, w, items):
    c = [[0] * (w + 1) for _ in range(n + 1)]
    g = [[0] * (w + 1) for _ in range(n + 1)]

    for i in range(w + 1):
        g[0][i] = 1

    for i in range(1, n + 1):
        for j in range(1, w + 1):
            c[i][j] = c[i - 1][j]
            g[i][j] = 0
            item = items[i - 1]
            if item[0] > j:
                continue
            if item[1] + c[i - 1][j - item[0]] > c[i - 1][j]:
                c[i][j] = item[1] + c[i - 1][j - item[0]]
                g[i][j] = 1

    max_value = c[n][w]
    routes = []
    for i in range(n, 0, -1):
        if g[i][w] == 1:
            routes.append(i)
            w -= items[i - 1][0]
    return max_value, routes


result, _ = knapsack(n, w, items)
print(result)


Measured memory_bytes: 191260
#include<iostream>
#include<cstdio>
#include<cstring>
#define N (2020)
#define INF (21000010)
using namespace std;
int p[2][N],A[2][N][2][N],n,dp[N][N],a[2*N],C[2][N][N];
//0 B/1 W			//A存每个球后面的球的情况 
char c[2*N];
int main(){
	scanf("%d",&n); int j,i,i1,j1; getchar();
	for (i=1;i<=2*n;i++){
		scanf("%c %d",&c[i],&a[i]); getchar();
		p[(c[i]=='W')][a[i]]=i; 
	}
	for (i=1;i<=2*n;i++)
		for (j=i+1;j<=2*n;j++)
			A[(c[i]=='W')][a[i]][(c[j]=='W')][a[j]]=1;
	for (i1=0;i1<2;i1++) for(i=1;i<=n;i++)
		for (j1=0;j1<2;j1++) for (j=1;j<=n;j++)
			A[i1][i][j1][j]+=A[i1][i][j1][j-1];
 	
	for (i=0;i<=n;i++) for (j=0;j<=n;j++){
 		C[0][i][j]=A[0][i+1][0][i]+A[0][i+1][1][j]+p[0][i+1]-(i+j+1);
 		C[1][i][j]=A[1][j+1][0][i]+A[1][j+1][1][j]+p[1][j+1]-(i+j+1);
 	}

 	for (i=0;i<=n;i++) for (j=0;j<=n;j++){
 		if (!i&&!j) continue;
 		dp[i][j]=INF; 
 		if (i>0) dp[i][j]=min(dp[i][j],dp[i-1][j]+C[0][i-1][j]);
 		if (j>0) dp[i][j]=min(dp[i][j],dp[i][j-1]+C[1][i][j-1]);
	}
	cout<<dp[n][n];
}

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

template<class T>constexpr T f(const T& n)
{
  return n % 4 == 0 ? n : n % 4 == 1 ? 1 : n % 4 == 2 ? n + 1 : 0;
}

int main()
{
  uint64_t a, b;
  cin >> a >> b;
  if (a > 0) a--;
  cout << (f(a) ^ f(b)) << endl;
}


Measured memory_bytes: 256
while True:
  n = int(input())
  if n == 0:
    break
  dic = []
  for _ in range(n):
    lst = input().split()
    l = lst.pop(0)
    p, a, b, c, d, e, f, s, m = map(int, lst)
    time = a + b + c + (d + e) * m
    prof = f * s * m - p
    dic.append((-prof / time, l))
  
  dic.sort()
  for _, name in dic:
    print(name)
  print("#")



Measured memory_bytes: 5612
#include<bits/stdc++.h>
using namespace std;
int a[333][333],num[333];
bool err[333];
int main()
{	
	int n,m;scanf("%d%d",&n,&m);
	for (int i=1;i<=n;i++)
	for (int j=1;j<=m;j++)
		scanf("%d",&a[i][j]);
	int ans=n;
	for (int t=1;t<m;t++)
	{
		for (int i=1;i<=m;i++) num[i]=0;
		for (int i=1;i<=n;i++)
		{
			int w=1;while (err[a[i][w]]) w++;
			num[a[i][w]]++;
		}
		int mx=0,id;
		for (int i=1;i<=m;i++) if (num[i]>mx) {mx=num[i];id=i;}
	 	ans=min(ans,mx);
	 	err[id]=true;
	}
	printf("%d\n",ans);
}

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

using namespace std;

typedef long long ll;
typedef pair<int, int> PII;

const int MM = 1e9 + 7;
const double eps = 1e-8;
const int MAXN = 2e6 + 10;

int n, m;

int a[MAXN];

void read(){
	scanf("%d", &n);
	for(int i  =1; i <= n; i++)
		scanf("%d", &a[i]);
}

void solve(){
	long long cnt = 0;
	long long pre = 0;
	//f[0] = 0;
	for(int i = 1; i <= n; i++){
		if (a[i] == 0){
			pre = 0;
		}
		else{
			if (pre){
				cnt++;
				a[i]--;
				pre = 0;
			}
			cnt += a[i] / 2;
			pre = a[i] % 2;
		}
	}	
	cout<<cnt<<endl;
}

void printans(){

}
	

int main(){
	int T = 1;
//	cin>>T;
	while(T--){
		read();
		solve();
		printans();
	}
	return 0;
} 


Measured memory_bytes: 640
(let ((n (read))
      (ac 0)
      (wa 0)
      (tle 0)
      (re 0))
  (loop :for i :from 1 :to n
        :for s := (read-line)
        :do (cond ((string= "AC" s)
                   (incf ac))
                  ((string= "WA" s)
                   (incf wa))
                  ((string= "TLE" s)
                   (incf tle))
                  ((string= "RE" s)
                   (incf re))))
  (format t "AC x ~A~%" ac)
  (format t "WA x ~A~%" WA)
  (format t "TLE x ~A~%" TLE)
  (format t "RE x ~A~%" RE))


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

int main() {
  int n;string s;cin>>n>>s;
  int ans=0;
  for(int i=1;i<n-1;i++){
    vector<int> l(26),r(26);
    rep(j,i)l[s[j]-'a']=1;
    for(int j=i;j<n;j++)r[s[j]-'a']=1;
    int cnt=0;
    rep(j,26){
      if(l[j]==1&&r[j]==1)cnt++;
    }
    ans=max(ans,cnt);
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3620
fn get_line() -> String {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().to_string()
}

fn reads<T>() -> Vec<T>
    where
        T: std::str::FromStr,
        <T as std::str::FromStr>::Err: std::fmt::Debug {
    get_line().split(' ').map(|x| x.parse().unwrap()).collect()
}

fn readln<T>() -> T
    where
        T: std::str::FromStr,
        <T as std::str::FromStr>::Err: std::fmt::Debug {
    get_line().parse().unwrap()
}

fn main() {
    let n = readln();
    let xs: Vec<i64> = reads();

    let mut s = 0;
    let mut res = 0;
    for &x in &xs {
        s += x;
        res += x.abs();
    }

    let mut ls = vec![0; n + 1];
    let mut rs = vec![s; n + 1];

    for i in 0..n {
        let x = xs[i];

        ls[i + 1] = ls[i] + x;
        rs[i + 1] = rs[i] - x;
    }

    for i in 1..n {
        let d: i64 = ls[i] - rs[i];
        let tmp = d.abs();

        if res > tmp {
            res = tmp;
        }
    }

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


Measured memory_bytes: 13044
#include <bits/stdc++.h>
#define rep(i,n) for (ll i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
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(){
    ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    vector<ll> s1(n), s2(n), t1(n), t2(n);
    rep(i,n) {
        int a;
        cin >> a;
        s1[i] = a-i;
        s2[i] = -a-i;
        t1[i] = a+i;
        t1[i] = -a+i;
    }
    sort(s1.begin(), s1.end());
    sort(s2.begin(), s2.end());
    sort(t1.begin(), t1.end());
    sort(t2.begin(), t2.end());
    ll ans = 0;
    rep(i,n) {
        pair<vector<ll>::iterator, vector<ll>::iterator> p;
        p = equal_range (s1.begin(), s1.end(), s2[i]);
        if(p.first!=s1.end()) {
            ans+= p.second - p.first;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 9592
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<int,int> 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; }
const LL mod=1000000007;
const LL LINF=1LL<<60;
const int INF=1<<30;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};




int main(){
    int n,k;cin >> n >> k;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    vector<LL> fact(n+1,1);
    for (int i = 0; i < n; i++) {
        fact[i+1] = fact[i] * (i + 1) %mod;
    }
    vector<vector<vector<LL>>> dp(n+1,vector<vector<LL>> (n+1, vector<LL>(300,0)));
    LL ans = 0;
    dp[0][0][0] = 1;
    for (int i = 0; i < n; i++) {
        for (int l = 0; l <= i; l++) {
            for (int j = 0; j < 256; j++) {
                dp[i+1][l+1][j^a[i]] = (dp[i+1][l+1][j^a[i]] + dp[i][l][j])%mod;
                dp[i+1][l][j] = (dp[i+1][l][j] + dp[i][l][j])%mod;
            }
        }
    }
    for (int i = 0; i <= n; i++) {
        ans = (ans + dp[n][i][k] * fact[i])%mod;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 24832
def main(n: int, a: list):
    ans = 0

    for a in a:
        while True:
            a /= 2

            if a.is_integer():
                ans += 1
            else:
                break

    print(ans)


if __name__ == '__main__':
    n = int(input())
    a = list(map(int, input().split()))

    main(n, a)


Measured memory_bytes: 4148
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
int main(){
    int n,p[200000],ans=0,a=0;
    cin>>n;
    rep(i,n) cin>>p[i];
    rep(i,n){
        if(p[i]==i+1) a++;
        else ans+=(a+1)/2,a=0;
    }
    if(a) ans+=(a+1)/2;
    cout<<ans;
}

Measured memory_bytes: 640
#include <iostream>


typedef struct {
	char design;
	int num;
} card;


void merge(card *A, int left, int mid, int right){
	int n1,n2,i,j,k;
	card *L, *R;
	n1 = mid - left;
	n2 = right - mid;
	L = new card[n1+1];
	R = new card[n2+1];

	for(i=0;i<n1;i++){
		L[i] = A[left+i];
	}
	for(i=0;i<n2;i++){
		R[i] = A[mid+i];
	}
	
	L[n1].num = 1000000000;
	R[n2].num = 1000000000;
	i=0;
	j=0;
	for (k=left; k<right;k++){
		if(L[i].num <= R[j].num){
			A[k] = L[i];
			i++;
		}
		else{
			A[k]=R[j];
			j++;
		}
	}
	delete []L;
	delete []R;
}


void mergeSort(card *A, int left, int right){
	int mid;
	if(left+1 < right){
		mid = (left+right)/2;
		mergeSort(A, left, mid);
		mergeSort(A, mid, right);
		merge(A, left, mid, right);
	}
}


int partition(card *A, int p, int r){
	int i,j;
	card x;
	card temp;
	x = A[r];
	i = p-1;
	for(j=p;j<r;j++){
		if(A[j].num <= x.num){
			i++;
			temp = A[i];
			A[i] = A[j];
			A[j] = temp;
		}
	}
	temp = A[i+1];
	A[i+1] = x;
	A[r]=temp;
	return i+1;
}

void quickSort(card *A, int p, int r){
	int q;
	if(p<r){
		q = partition(A, p, r);
		quickSort(A, p, q-1);
		quickSort(A, q+1, r);
	}
}

int main(void){
	int i,n,num;
	char design;
	card *A_merge, *A_quick;

	std::cin >> n;
	
	A_merge = new card[n];
	A_quick = new card[n];
	for(i=0;i<n;i++){
		std::cin >> design >> num;
		A_merge[i].design = design;
		A_merge[i].num = num;
		A_quick[i].design = design;
		A_quick[i].num = num;
	}
	mergeSort(A_merge, 0, n);
	quickSort(A_quick, 0, n-1);
	
	for (i=0;i<n;i++){
		if (A_quick[i].design != A_merge[i].design){
			break;
		}
	}
	if (i!=n){
		std::cout << "Not stable";
	}
	else{
		std::cout << "Stable";
	}
	std::cout << std::endl;

	for(i=0;i<n;i++){
		std::cout << A_quick[i].design << " " << A_quick[i].num << std::endl;
	}
	
	delete []A_quick;
	delete []A_merge;
	return 0;
}

Measured memory_bytes: 5024
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<map>
#include<stack>
#include<set>
#include<queue>
#include<vector>
#include<stdlib.h>
 
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cstdlib>
 
#define inf 0x3f3f3f3f
using namespace std;
typedef long long ll;
const int maxn=1e6+6;
const int mod=1e9+7;
ll a[maxn]={1,0,0,1,1};
bool cmp(ll a,ll b){
    return a>b;
}
int main()
{
    cin.tie(0);std::ios::sync_with_stdio(false);
    int n;
    cin>>n;
    if(n>4){
        for(int i=5;i<=n;i++)
            a[i]=(a[i-1]+a[i-3])%mod;
    }
    cout<<a[n]<<endl;
	system("pause");
    return 0;
}

Measured memory_bytes: 3708
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;

class Prog
{
    public Prog() { }
    public static int Main()
    {
        new Prog().calc();
        return 0;
    }

    Scanner cin;

    public void calc()
    {
        cin = new Scanner();
        int W = cin.nextInt();
        int a = cin.nextInt();
        int b = cin.nextInt();

        if (b + W <= a) Console.WriteLine(a - (b + W));
        else if (a < b + W && b < a + W) Console.WriteLine(0);
        else Console.WriteLine(b - (a + W));
        Console.Read();        
    }
}


class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }

}

Measured memory_bytes: 11220
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll S;
const int maxN = 2 * (int)1e5 + 10;
ll a[maxN];
ll b[maxN];
int n;
int main() {
    //freopen("input.txt", "r", stdin);
    ios_base::sync_with_stdio(0);
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> a[i] >> b[i];
        S += a[i];
    }
    ll ans = 0;
    for (int i = 1; i <= n; i++) {
        if (a[i] > b[i]) ans = max(ans, S - a[i] + a[i] - b[i]);
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <vector>
#include <utility>
#include <numeric>
#include <string>
#include <set>
#include <map>
#include <tuple>
#include <queue>
#include <stack>
#define rep(i, a, n) for(int (i) = (int)(a);(i) < (int)(n);++(i))
#define repe(i, a, n) for(int (i) = (int)(a);(i) <= (int)(n);++(i))
#define repr(i, a, n) for(int (i) = (int)(a);(i) > (int)(n);--(i))
#define reper(i, a, n) for(int (i) = (int)(a);(i) >= (int)(n);--(i))
#define SIZE(x) ((int)(x).size())
#define ALL(x) (x).begin(), (x).end()
#define RNG(x, n) &((x)[0]), &((x)[n])
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define yes cout << "yes" << endl;
#define no cout << "no" << endl;
#define pb push_back
#define EPS (1e-20)
#define INF 2147483647
#define MOD 1000000007
using llint = long long;
using VI = std::vector<int>;
using PII = std::pair<int, int>;
using SI = std::set<int>;
using MII = std::map<int, int>;
using TIII = std::tuple<int, int, int>;
using namespace std;


int N;
int P[110][15];
int F[110];


int cntBit(int bit){
	int cnt = 0;
	do {
		cnt += bit&1;
	} while(bit/=2);
	return cnt;
}


int solve(){
	int ans = -INF;
	rep(i, 1, 1<<10){
		int sum = 0;
		rep(j, 0, N){
			int c = cntBit(i&F[j]);
			sum += P[j][c];
		}
		ans = max(ans, sum);
	}
	return ans;
}


signed main(){
	cin >> N;
	rep(i, 0, N){
		rep(j, 0, 10){
			int f;
			cin >> f;
			F[i] += f*(int)pow(2, 9-j);
		}
	}
	rep(i, 0, N)
		repe(j, 0, 10) cin >> P[i][j];

	cout << solve() << endl;

	return 0;
}

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

int main()
{
    int x;
    cin >> x;
    int ans = 0;
    while (x >= 500) {
        x -= 500;
        ans += 1000;
    }
    while (x >= 5) {
        x -= 5;
        ans += 5;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 888
let () =
  Scanf.scanf "%d %d %d\n" @@ fun n k q ->
  let points = Array.make n (k-q) in
  for i = 0 to q - 1 do
    Scanf.scanf "%d\n" @@ fun d ->
      points.(d-1) <- points.(d-1) + 1
  done;
  Array.iter (fun p -> if p > 0 then print_endline "Yes" else print_endline "No") points

Measured memory_bytes: 6620
#include<cstdio>

using namespace std;
 
#define god(x1,y1,x2,y2,x3,y3) x1*(y2-y3)+x2*(y3-y1)+x3*(y1-y2)

int main(){
	double x1,y1,x2,y2,x3,y3,ax,ay;

	while(scanf("%lf%lf%lf%lf%lf%lf%lf%lf",&x1,&y1,&x2,&y2,&x3,&y3,&ax,&ay) != EOF){
		if(god(x1,y1,x2,y2,x3,y3) > 0.0 && god(ax,ay,x1,y1,x2,y2) > 0.0 &&
			god(ax,ay,x3,y3,x1,y1) > 0.0 &&  god(ax,ay,x2,y2,x3,y3) > 0.0){
				printf("YES\n");
		}
		else if(god(x1,y1,x2,y2,x3,y3) < 0.0 && god(ax,ay,x1,y1,x2,y2) < 0.0 &&
			god(ax,ay,x3,y3,x1,y1) < 0.0 &&  god(ax,ay,x2,y2,x3,y3) < 0.0){
				printf("YES\n");
		}
		else printf("NO\n");
	}
	return 0;
}

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

int search(int a,int b,int c,int p)
{
	p += (a/3+b/3+c/3);
	int tta = a%3;
	int ttb = b%3;
	int ttc = c%3;
	int ttp = p;
	while(tta!=0 && ttb!=0 && ttc!=0){
		ttp++;
		tta--;ttb--;ttc--;
	}

	int ta = a%3;
	int tb = b%3;
	int tc = c%3;
	int tp = p;
	if(ta==2 || tb==2 || tc==2){
		if(ta==0 && ta+3 <= a){
			tp--;
			ta+=3;
		}
		if(tb==0 && tb+3 <= b){
			tp--;
			tb+=3;
		}
		if(tc==0 && tc+3 <= c){
			tp--;
			tc+=3;
		}
	}
	while(ta!=0 && tb!=0 && tc!=0){
		tp++;
		ta--;tb--;tc--;
	}
	return max(ttp,tp);
}

int main()
{
	int a,b,c,d,e,f;
	while(cin >> a >> b >> c >> d >> e >> f){
		if(!a && !b && !c && !d && !e && !f)
			break;
		cout << search(a+d,b+e,c+f,0) << endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <vector>
#include <string>
#include <stdlib.h>

using namespace std;

int main()
{
  int n;
  int m;
  vector<int> p;
  vector<string> s;

  cin >> n >> m;
  p.resize(m);
  s.resize(m);
  for (int i = 0; i < m; i++) {
    cin >> p[i] >> s[i];
  }

  vector<bool> ac_flag(n + 1, false);
  vector<int> wa_of_each_puloblem(n + 1, 0);
  int num_of_ac = 0;
  int num_of_wa = 0;

  for (int i = 0; i < m; i++) {
    if (ac_flag[p[i]]) continue;
    if (s[i] == "AC") {
      num_of_ac++;
      num_of_wa += wa_of_each_puloblem[p[i]];
      ac_flag[p[i]] = true;
    }
    else {
      wa_of_each_puloblem[p[i]]++;
    }
  }

  cout << num_of_ac << " " << num_of_wa << flush;

  return 0;
}


Measured memory_bytes: 6528
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>
#include <tuple>

#define DEBUG(x) cout<<#x<<": "<<x<<endl

using namespace std;

int main(){

	int N[4];

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

	for(int i =0 ;i <3; i++){
		for(int j =0 ;j <2; j++){
			int x;
			cin >> x;
			N[x-1]++;
		}
	}

	int one=0, two=0;
	for(int i =0 ;i <4; i++){
		if(N[i] == 1){
			one++;
		} else if(N[i] == 2){
			two++;
		}
	}

	if(one == 2 && two == 2){
		cout << "YES" << endl;
	} else {
		cout << "NO" << endl;
	}

	return 0;
}


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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

const int INF=1001001001;
const int INFLL=1001001001001001001ll;
const int mod=1000000007;
inline void add(int &a,int b){
    a+=b;
    if(a>=mod)a-=mod;
}
const double PI=acos(-1);
const double EPS=1e-7;

signed main(){
    int N;cin>>N;
    vint R(N);rep(i,N)cin>>R[i];

    sort(all(R));
    reverse(all(R));
    double ans=0;

    for(int k=3;k<=N;k++){
        vint r(R.begin(),R.begin()+k);
        sort(all(r));
        do{
            vector<double>L(k);
            rep(i,k)L[i]=r[i]*r[(i+1)%k]/2.0;
            double mi=*min_element(all(L));
            double lb=-mi;
            double ub=mi;
            rep(i,30){
                double mid=(ub+lb)/2;
                double sum=0;
                rep(j,k)sum+=acos(mid/L[j]);
                if(sum>=2*PI)lb=mid;
                else ub=mid;
            }

            double sum=0;
            rep(j,k)sum+=acos(lb/L[j]);
            if(abs(sum-2*PI)>EPS)continue;
            double val=0;
            rep(j,k)val+=sin(acos(lb/L[j]))*L[j];
            chmax(ans,val);
        }while(next_permutation(all(r)));
    }
    printf("%.20f\n",ans);
    return 0;
}

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

int main() {
  int count5 = 0, count7 = 0;
  // int arr[3];
  for (int i = 0; i < 3; i++) {
    int t;
    cin >> t;
    if (t == 5) count5++;
    if (t == 7) count7++;
  }
  if (count5 == 2 && count7 == 1)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
}

Measured memory_bytes: 3636
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    String s = in.readLine();
    System.out.println(Integer.parseInt(s.substring(5,7))>4?"TBD":"Heisei");
  }
}

Measured memory_bytes: 20820
#include <bits/stdc++.h>
 
#define int         long long
#define uint        unsigned int
#define ld          long double
#define showoff     ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb          push_back
#define pii         pair<int,int>
#define FOR(i,a,b)  for(int i=a;i<b;++i)
#define RFOR(i,a,b) for(int i=a;i>b;--i)
#define f           first
#define se          second
#define maxn        1000005
#define all(v)      v.begin(),v.end()
#define sz(x)       (int)x.size()
#define mod         1000000007
#define pqueue      priority_queue<int>
#define pdqueue     priority_queue< int,vector<int> ,greater< int >>
 
using namespace std;
 
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
 
int power(int a,int n)
{
    a %= mod;
    if(n == 1)return a;
    if(n == 0)return 1;
    if(n%2)return (a*(power((a*a)%mod,n/2)%mod))%mod;
    return power((a*a)%mod,n/2)%mod;
}
const int inf = (int) 1e18;
 
int inverse(int x){
    return power(x,mod-2)%mod;//little fermat....
} 
vector<int>v(maxn),spf(maxn),cnt(maxn);

void sieve(){
    for(int i = 1;i <= maxn;++i)if(cnt[i] > 0){
        if(spf[i])continue;
        spf[i] = i;
        for(int j = i;j <= maxn;j += i){
            if(!spf[j])spf[j] = i;
        }
    }
    //for(int i = 1;i <= maxn;++i)if(!spf[i] && cnt[i] > 0)spf[i] = i;
}

void solve(){
    int n;
    cin >> n;
    FOR(i,1,n+1)cin >> v[i],cnt[v[i]]++;
    sieve();
    int tot = 0;
    FOR(i,1,n+1)if(cnt[v[i]] == 1 && spf[v[i]] == v[i]){
        ++tot;
    }
    cout << tot << "\n";
}

signed main()
{
    showoff;
    int T = 1;
    //cin >> T;
    FOR(t,1,T+1){   
        solve();
        cout << "\n";
    }
    return 0;
}
//*->for large size of matrix take int not long long if possible......
//*->always take maximum as inf for safer side ...
 


Measured memory_bytes: 26668
#include <bits/stdc++.h>
using namespace std;
#define ll long long int;
#define pb push_back;
#define ios ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
int main() {
	ios;
	int n,i; cin>>n;
	vector<int> p(n),q(n);
	for(i=0;i<n;i++) cin>>p[i];
	for(i=0;i<n;i++) cin>>q[i];
	vector<int> ar(n);
	for(i=1;i<=n;i++) ar[i-1]=i;
	vector<vector<int> > per;
	do{
		per.push_back(ar);
		// cout<<ar<<" ";
	}while(next_permutation(ar.begin(),ar.end()));
	int x=lower_bound(per.begin(),per.end(),p)-per.begin();
	int y=lower_bound(per.begin(),per.end(),q)-per.begin();
	
	cout<<abs(y-x);
	return 0;
}

Measured memory_bytes: 3384
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i,n) for(int i=0, i##_len=(int)(n); i<i##_len; i++)
#define reps(i,n) for(int i=1 , i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;i--)
#define rreps(i,n) for(int i=((int)(n));i>0;i--)
#define repi(i,x) for(auto i=(x).begin(),i##_fin=(x).end();i!=i##_fin;i++)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define solve(a) ((a)?"Yes":"No")
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef pair<int , int> Pi;
typedef vector<Pi> VPi;
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long , long long> P;
typedef vector<P> VP;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1;} return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1;} return 0;}
const long long INFLL = 1LL<<60;
const int INF = 1<<30;
const double PI=acos(-1);
int main(){
	int n,p;
	ll ans=0;
	cin >>n>>p;
	string s;
	cin>>s;
	map<ll,ll>dis;
	if(p==2){
		for(int i=0;i<s.size();i++){
			if((s[i]-'0')%2==0){
				ans+=i+1;
			}
		}
		cout<<ans<<endl;
		return 0;
	}
	if (p == 5)
	{
		for (int i = 0; i < s.size(); i++)
		{
			if ((s[i] - '0') % 5 == 0)
			{
				ans += i + 1;
			}
		}
		cout << ans << endl;
		return 0;
	}
	ll base=1LL;
	ll cnt=0LL;
	dis[0]=1;
	for(int i=s.size()-1;i>=0;i--){
		cnt+=(base*(s[i]-'0'))%p;
		cnt%=p;
	//	clog<<cnt<<endl;
		dis[cnt]+=0;
		dis[cnt]++;
		base*=10LL;
		base%=p;

	}
	repi(itr,dis){
		
			ans+=(itr->S)*(-1+itr->S)/2;
		
	}
	cout<<ans<<endl;
}
/*
15938532
*/

Measured memory_bytes: 1028
import java.io.*;
import java.util.*;
import static java.lang.System.out;

public class Main {
    static MyReader in = new MyReader();

    public static void main(String[] args) {
        int N = in.i();
        int[] A = in.ii(N);
        long ans = 0;
        int r = 0;
        for (int i = 0; i < N; i++) {
            ans += (r + A[i]) / 2;
            r = r == 1 && A[i] == 0 ? 0 : r ^ (A[i] & 1);
        }
        out.println(ans);
    }
}

class MyReader extends BufferedReader {
    char[] cbuf = new char[1024];
    int head = 0;
    int tail = 0;

    MyReader() {
        super(new InputStreamReader(System.in));
    }

    char next() {
        if (head == tail) {
            try {
                tail = super.read(cbuf, 0, cbuf.length);
            } catch (IOException e) {
                e.printStackTrace();
            }
            head = 0;
        }
        return cbuf[head++];
    }

    void back() {
        head--;
    }

    boolean minus() {
        boolean minus;
        while (true) {
            char c = next();
            if (!isDelimiter(c)) {
                if (!(minus = c == '-')) back();
                return minus;
            }
        }
    }

    void skip() {
        while (isDelimiter(next()));
        back();
    }

    char[] s(int N) {
        char[] cbuf = new char[N];
        read(cbuf, 0, N);
        return cbuf;
    }

    public int read(char[] cbuf, int off, int len) {
        skip();
        int i;
        for (i = 0; i < cbuf.length; i++) {
            char c = next();
            if (isDelimiter(c)) {
                break;
            }
            cbuf[i] = c;
        }
        return i;
    }

    boolean isDelimiter(char c) {
        return c == ' ' || c == '\n' || c == '\r';
    }

    int i() {
        boolean minus = minus();
        int n = 0;
        while (true) {
            int k = next() - '0';
            if (k < 0 || 9 < k) break;
            n = 10 * n + k;
        }
        return minus ? -n : n;
    }

    int[] ii(final int N) {
        int[] a = new int[N];
        for (int j = 0; j < a.length; j++) a[j] = i();
        return a;
    }

    long l() {
        boolean minus = minus();
        long n = 0;
        while (true) {
            int k = next() - '0';
            if (k < 0 || 9 < k) break;
            n = 10 * n + k;
        }
        return minus ? -n : n;
    }
}


Measured memory_bytes: 36036
#include<stdio.h>
int main()
{
    long long int a,b,k;
    scanf("%lld%lld%lld",&a,&b,&k);
    if(a+b>k)
    {
        if(a>=k)
            printf("%lld %lld\n",a-k,b);
        else
        {
            printf("0");
            printf(" %lld\n",b-(k-a));
        }
    }
    else
        printf("0 0\n");
    return 0;
}


Measured memory_bytes: 1728
#include<bits/stdc++.h>
using namespace std;
#define nn 502
#define int long long
int n,mod;int dp[nn][nn];
int li[nn],ri[nn];
int id[nn];
#define pii pair<int,int>
#define mp make_pair
pii make(int x){
	if(li[x]) return mp(li[x]-1,ri[x]);
	else return mp(ri[x],li[x]); 
}
int cmp(int x,int y){
	return make(x)<make(y);
}
void add(int &x,int y){
	x=(x+y)%mod;
}

int solve(int diss){
	memset(dp,0,sizeof dp);dp[0][0]=1;int cnt=0,tnc=0;;
	for(int i=0;i<n;i++){
		int x=id[i];
		if(li[x]){
			for(int j=0;j<=diss;j++){
				add(dp[i+1][j],dp[i][j]*max(0ll,ri[x]+1-n/2-tnc-(diss-j)));
				add(dp[i+1][j+1],dp[i][j]*max(0ll,li[x]-j-cnt));
			}
			tnc++;
		}
		else{
			for(int j=0;j<=diss;j++) add(dp[i+1][j],dp[i][j]*max(0ll,ri[x]-j-cnt+1));
			++cnt;
		}
	}
//	cout<<dp[n][diss]<<" ";
	return dp[n][diss];
}
signed main(){
	scanf("%lld%lld",&n,&mod);n=n*2;
	for(int i=0;i<n;i++){
		li[i]=-1,ri[i]=n,id[i]=i;
		for(int j=0;j<n;j++) if(i*i+j*j<n*n/4) li[i]=j;li[i]++;
		for(int j=n-1;j>=0;j--) if(i*i+j*j>n*n) ri[i]=j;ri[i]--;
	//s	cout<<li[i]<<" "<<ri[i]<<"\n";
	}
	
	sort(id,id+n,cmp);
	
	int flg=1,ans=0;
	for(int diss=0;diss<=n/2;diss++,flg=-flg)
		ans=(ans+flg*solve(diss))%mod;
	ans+=mod;ans%=mod;
	printf("%lld\n",ans);
	return 0;
}

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

int main(){
    int a,b,N,s,f,i;
    int dupe=0;
    cin>>a>>b;
    cin>>N;

    for(i=0;i<N;i++){
        cin>>s>>f;
        if((a>=s && a<f) || (b>s && b<=f) || (a<=s && b>=f))dupe=1;
    }

    cout<<dupe<<endl;    
    return 0;
}


Measured memory_bytes: 3120
#!/bin/usr/env python3

n = int(input())

h = input().split()

li = [0]
for i in range(n):
    li.append(int(h[i]))

ans = 0
for i in range(1,n+1):
    if li[i-1] <= li[i]:
        ans += li[i] - li[i-1]

print(ans)



Measured memory_bytes: 3060
#include<stdio.h>
int main()
{
  int n,m,i,d;
  scanf("%d %d", &n,&m);
 
  int a[m];
  
  for(i=0;i<m;i++)
  {
	scanf("%d",&a[i]);  
  }
  
  d=0;
  for (i=0;i<m;i++)
  {
    d=d+a[i];
  }
  
  if (d>n)
  {
    printf("-1");
  }else{
  printf("%d",n-d);
	}
  return 0;
}

Measured memory_bytes: 1716
#include<cstdio>
#include<vector>
using namespace std;
int n;
const int MAXN=1e5+5;
vector<int>G[MAXN];
int dist[2][MAXN];
void dfs(int v,int p,int id,int t){
	dist[id][v]=t;
	for(int i=0;i<G[v].size();i++){
		int to=G[v][i];
		if(to!=p){
			dfs(to,v,id,t+1);
		}
	}
}
int main(){
	scanf("%d",&n);
	for(int i=0;i<n-1;i++){
		int a,b;
		scanf("%d%d",&a,&b);
		a--;b--;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	dfs(0,0,0,0);
	dfs(n-1,n-1,1,0);
//	for(int i=0;i<n;i++)printf("%d ",dist[0][i]);printf("\n");
//	for(int i=0;i<n;i++)printf("%d ",dist[1][i]);printf("\n");
	int n1=0,n2=0;
	for(int i=0;i<n;i++){
		if(dist[0][i]<=dist[1][i])n1++;
		else n2++;
	}
//	printf("%d %d\n",n1,n2);
	if(n1>n2)printf("Fennec\n");
	else printf("Snuke\n");
	return 0;
}

Measured memory_bytes: 14336
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define FILEIN freopen("in.txt","r",stdin)
bool is_prime(ll x){
    for(int i = 2;i*i<=x;i++){
        if(x%i==0) return false;
    }
    return true;
}
int main()
{
   // FILEIN;
    int x;
    cin >> x;
    ll p;
    p = x;
    while(!is_prime(p)) p++;
    cout << p << endl;
}


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

     int a[3],ans;

     scanf("%d %d %d",&a[0],&a[1],&a[2]);
     sort(a,a+3);

     ans=a[1]-a[0]+a[2]-a[1];
     printf("%d\n",ans);
     return 0;










}


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

void counting_sort(int A[], int k, int n)
{
    int i, j;
    int B[3000000], C[3000000];
    for (i = 0; i <= k; i++)
        C[i] = 0;
    for (j = 1; j <= n; j++)
        C[A[j]] = C[A[j]] + 1;
    for (i = 1; i <= k; i++)
        C[i] = C[i] + C[i-1];
    for (j = n; j >= 1; j--)
    {
        B[C[A[j]]] = A[j];
        C[A[j]] = C[A[j]] - 1;
    }

    for (i = 1; i <= n; i++)
    if(i==n)printf("%d\n", B[i]);
    else printf("%d ",B[i]);
}

int main()
{
    int n, k = 0;
    int A[3000000];
    int i;

    scanf("%d", &n);

    for (i = 1; i <= n; i++)
    {
        scanf("%d", &A[i]);
        if (A[i] > k) {
            k = A[i];
        }
    }
    counting_sort(A, k, n);

    return 0;
}


Measured memory_bytes: 17468
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
using i64 = int64_t;
using ll = long long;
int main() {
  int N;
  cin >> N;
  if(N >=30){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 3672
#include <stdio.h>
int main(){
    int N,d[101];
    int i,j,count,point;
    scanf("%d",&N);
    for(i=0;i<N;i++){
        scanf("%d",&d[i]);
    }
    count = 0;
    for(i=0;i<N;i++){
      point = 0;
        for(j=i+1;j<N;j++){
            
            if(d[i]==d[j]){
                point = 1;
                break;
            }
        }
        if(point==0){
            count++;
        }
    }
    
    printf("%d",count);
    return 0;
}



Measured memory_bytes: 128
#include<algorithm>
#include<iostream>
#include<string>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;
int main(){
  int i,j,k;
  int n;
  while(cin>>n&&n){
    int ct=0;
    for(i=0;i*i*4<n+1;i++){
      for(j=i;i*i+j*j*3<n+1;j++){
	for(k=j;i*i+j*j+k*k*2<n+1;k++){
	  if(k*k*2<=n-i*i-j*j&&pow((int)sqrt(n-i*i-j*j-k*k),2)==n-i*i-j*j-k*k)
	    ct++;
	}
      }
    }
    cout<<ct<<endl;
  }
  return 0;
}

Measured memory_bytes: 868