akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<stdio.h>
using namespace std;

int main(void) {
	char b;
	scanf("%c", &b);
	if (b == 'A') printf("T\n");
	else if (b == 'T') printf("A\n");
	else if (b == 'C') printf("G\n");
	else printf("C\n");
	return 0;
}


Measured memory_bytes: 3552
import sys
input = sys.stdin.readline

B = int(1E8)

def main():

    H, W = map(int, input().split())
    
    l = 0
    q = []
    checked = []
    for h in range(H):
        S = input()
        L = []
        for w in range(W):
            if S[w] == '#':
                l += 1
                L.append(True)
                q.append(B*h+w)
            else:
                L.append(False)
        checked.append(L)

    Next = [[[] for _ in range(W)] for _ in range(H)]
    for h in range(H):
        for w in range(W):
            if h != 0:
                Next[h][w].append(B*(h-1) + w)
            if h != H-1:
                Next[h][w].append(B*(h+1) + w)
            if w != 0:
                Next[h][w].append(B*h + w-1)
            if w != W-1:
                Next[h][w].append(B*h + w+1)

    c = -1
    for _ in range(H+W+2):
        qq = []
        if len(q) == 0:
            break
        for hw in q:
            h, w = hw//B, hw%B
            for nhw in Next[h][w]:
                nh, nw = nhw//B, nhw%B
                if not checked[nh][nw]:
                    qq.append(B*nh + nw)
                    checked[nh][nw] = True
        q = qq
        c += 1

    print(c)


if __name__ == "__main__":
    main()

Measured memory_bytes: 169976
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define Max(x,y,z) max(x,max(y,z))
#define Min(x,y,z) min(x,min(y,z))
#define fr(i,s,e) for(i=s;i<e;i++)
#define rf(i,s,e) for(i=s-1;i>=e;i--)
#define pb push_back
#define mp make_pair

typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<pair<long long,long long> > vpll;
typedef vector<vector<ll> > vvll;

template<typename T> T gcd(T a,T b) { if(a==0) return b; return gcd(b%a,a); }
template<typename T> T pow(T a,T b, ll m){T ans=1; while(b>0){ if(b%2==1) ans=(ans*a)%m; b/=2; a=(a*a)%m; } return ans%m; }

bool sortbysec(const pair<int,int> &a, 
              const pair<int,int> &b) 
{ 
    return (a.second < b.second); 
} 

bool sortinrev(const pair<int,int> &a,  
               const pair<int,int> &b) 
{ 
       return (a.first > b.first); 
} 
int main() {
	ll n,i;
	cin>>n;
	ll a[n];
	fr(i,0,n)
	{
		cin>>a[i];
	}
	if(n<3)
	{
		cout<<0;
	}
	else
	{
	sort(a,a+n);ll c=0,j,k;
	fr(i,0,n-2)
	{fr(j,i+1,n-1)
	{	fr(k,j+1,n)
		if(a[i]+a[j]>a[k])
	{
		if(a[i]!=a[j] && a[j]!=a[k] && a[k]!=a[i])
		{
			c++;
		}
	}
	}	
	}
	cout<<c;
	}
	return 0;
}


Measured memory_bytes: 3640
X=int(input())
A=0
B=0
flag = False
for a in range(120):
    for b in range(120):
        if a**5 - b**5 == X:
            A=a
            B=b
            flag = True

        if a ** 5 + b**5 == X:
            A=a
            B=-b

        if -a**5 + b**5 ==X:
            A =-a
            B = b

        if flag:
            break
    if flag:
        break
print(str(A)+" "+str(B))

Measured memory_bytes: 9212
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;


int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(12);

    int n, L;
    cin >> n >> L;

    vector<string> S;
    for (int i = 0; i < n; ++i) {
        string s;
        cin >> s;
        S.push_back(s);
    }

    sort(S.begin(), S.end());

    string res;
    for (auto& s : S) {
        res += s;
    }

    cout << res << '\n';


    return 0;
}

Measured memory_bytes: 3660
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
vector<ll> gf[100005];
struct im{
	int dpn,dps;
};
vector<im> dp(100005);
vector<ll> rdp(100005);
deque<ll> tp;
int main(){
	ll n,m,a,b,ans=0;
	cin>>n>>m;
	while(m--){
		cin>>a>>b;
		gf[a].push_back(b);
		dp[b].dpn++;
	}
	for(int i=1;i<=n;i++){
		if(dp[i].dpn==0)rdp[i]=1,tp.push_back(i);
	}
	while(!tp.empty()){
		int fn=tp[0];
		tp.pop_front();
		for(int i=0;i<gf[fn].size();i++){
			dp[gf[fn][i]].dpn--;
			rdp[gf[fn][i]]=max(rdp[gf[fn][i]],rdp[fn]+1);
			if(dp[gf[fn][i]].dpn==0)tp.push_back(gf[fn][i]);
		}
		
	}
	for(int i=1;i<=n;i++){
		ans=max(ans,rdp[i]);
//		cout<<rdp[i]<<' ';
	}
	cout<<ans-1<<'\n';
	return 0;
}

Measured memory_bytes: 7296
#include<bits/stdc++.h>
using namespace std;
#define se second
#define fi first
#define ll long long
#define ld long double
#define pll pair<ll ,ll >
#define ppll pair<ll, pll>
#define pii pair<int, int> 
#define mod 1000000007
ll power(ll a,ll b){
    ll res=1;
    while(b>0){
        if(b%2!=0) res=(res*a)%mod;
        a=(a*a)%mod;
        b/=2;
    }
    return res;
}
ll ncr(ll n,ll k){
    if(k==0||k==n) return 1ll;
    if(k>n-k) k=n-k;
    ll pro=1;
    for(ll i=0;i<k;i++){
        pro=(pro*(n-i))%mod;
        pro/=(i+1);
    }
    return (pro%mod);
}
vector<int> prime;
void seive(){
    vector<bool > isprime(1000001,true);
    for(int i=2;i*i<=1000000;i++){
        if(isprime[i]){
            for(int j=i*i;j<=1000000;j+=i){
                isprime[j]=false;
            }
        }
    }
    for(int i=2;i<=1000000;i++){
        if(isprime[i]) prime.push_back(i);
    }
}
int main(void){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n;
    cin>>n;
    string str;
    cin>>str;
    int cnt=0;
    for(int i=0;i<n;){
        int j=i+1;
        char ch=str[i];
        while(ch==str[j]){
            j++;
        }
        cnt++;
        i=j;
    }
    cout<<cnt;
    return 0;
}


Measured memory_bytes: 512
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int h[] = new int[n + 1];
		int answer[] = new int[n + 1];

		Arrays.fill(answer, 1);
		answer[0] = 0;

		for (int i = 1; i <= n; i++) {
			h[i] = sc.nextInt();
		}

		for (int i = 1; i <= m; i++) {
			int a = sc.nextInt();
			int b = sc.nextInt();
			if (h[a] <= h[b]) {
				answer[a] = -1;
//				System.out.println(a);
			}
			if (h[b] <= h[a]) {
				answer[b] = -1;
//				System.out.println(a);
			}
		}

		int sum = 0;
		for (int i : answer) {
			if (i == 1) sum++;
		}
		System.out.println(sum);

		sc.close();
	}

}


Measured memory_bytes: 60160
from collections import deque
N,M = map(int, input().split())
E = [[] for _ in range(N)]
for _ in range(M):
    a,b = map(int, input().split())
    E[a-1].append(b-1)
    E[b-1].append(a-1)

q = deque()
q.append(0)
ans = [0]*N
while q:
    par = q.popleft()
    for e in E[par]:
        if ans[e] > 0:
            continue
        ans[e] = par+1
        q.append(e)

print("Yes")
for i in range(1, N):
    print(ans[i])

Measured memory_bytes: 98944
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <functional>
#include <stack>
#include <iomanip>
#include <limits>
using namespace std;
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
using Graph=vector<vector<int>>;
using edge= struct{int to;ll cost;};


template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}
using Graph =vector<vector<int>>;
//xor


int main(){
  ll x;cin>>x;
  ll ans1,ans2,ans3;
  ans1=0;
  ans2=0;
  ans3=0;
  ans1=x/500;
  ans1=ans1*1000;
  x=x%500;
  ans2=x/5;
  ans2=ans2*5;
  cout<<ans1+ans2<<endl;
}

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

using ll = long long;
using ull = unsigned long long;
using st = string;
using db = double;
using vll = vector<long long>;
using vvll = vector<vll>;
using vchar = vector<char>;
#define rep(i, m, n) for (int i = (int)(m); i < (int)(n); i++)
#define vrep(vec) for(auto& i : vec)
#define vin(vec) for(auto& i : vec) cin >> i
#define all(v) v.begin(), v.end()
ll mod = 1000000007;

int main(){
  ll h, w;
  cin >> h >> w;
  cout << (h == 1 || w == 1 ? 1 : (h * w + 1) / 2) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string>
#include <algorithm>
#include <math.h>
#include <map>
#include <vector>
#include <list>

using namespace std;
int main() {
	string s, t;
	int c = 0;
	cin >> s >> t;
	for (int i = 0; i < 3; i++) {
		if (s[i] == t[i]) {
			c++;
		}
	}
	cout << c << endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#define MAX 100001
int partition(int*, int, int);




int main(){
        int n, i, P;
        int A[MAX];

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

        P = partition(A, 0, n-1);

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

          if(i == P)      printf("[%d]", A[i]);
          else printf("%d", A[i]);
                if(i!=n-1) printf(" ");
        }
        printf("\n");
        return 0;
}


int partition(int *A, int p, int r){
        int x, i, j;
        int tmp = 0;

        x = A[r];
        i = p-1;

        for(j = p; j<r; j++) {
                if(A[j]<=x) {
                        i = i+1;

                        tmp = A[j];
                        A[j] = A[i];
                        A[i] = tmp;
                }
        }
        tmp = A[i+1];
        A[i+1] = A[r];
        A[r] = tmp;
        return i+1;
}

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

#define M 1000000
#define L 14

char H[M][L];

int getChar(char ch){
  if ( ch == 'A') return 1;
  else if ( ch == 'C') return 2;
  else if ( ch == 'G') return 3;
  else if ( ch == 'T') return 4;
  else return 0;
}

long long getKey(char str[]){
  long long sum = 0, p = 1, i;
  for ( i = 0; i < strlen(str); i++ ){
    sum += p*(getChar(str[i]));
    p *= 5;
  }
  return sum;
}

int h1(int key){ return key%M; }
int h2(int key){ return 1+(key%(M-1)); }

int find(char str[]){
  long long key, i,h;
  key=getKey(str);
  
    for(i=0;;i++){
      h=(h1(key)+i*h2(key))%M;  
     
    if(strcmp(H[h],str)==0)return 1;
    else if(strlen(H[h])==0)return 0;
  }
  return 0;

}

int insert(char str[]){
 long long key, i,h;
 key=getKey(str);
 
  for(i=0; ;i++){
    h=(h1(key)+i*h2(key))%M;
    if(strcmp(H[h],str)==0)return 1;
    else if(strlen(H[h])==0){
      strcpy(H[h],str);
      return 0;
   }
  }
  return 0;

}

int main(){
    int i, n, h;
    char str[L], com[9];
    for ( i=0; i<M; i++ )H[i][0] = '\0';
    
    scanf("%d", &n);
    
    for ( i = 0; i < n; i++ ){
	scanf("%s %s", com, str);
	if ( com[0] == 'i' ){
	    insert(str);
	} else {
	    if (find(str)){
		printf("yes\n");
	    } else {
		printf("no\n");
	    }
	}

    }

    return 0;
}



Measured memory_bytes: 15404
'use strict';
function main(input) {
  let textAmount = input[0]*1;
  let textArr = input[1].split(" ");
  let text1 = textArr[0];
  let text2 = textArr[1];
  let ans = "";
  for(let i = 0; i < textAmount; i++){
    ans += text1[i];
    ans += text2[i];
  }
  console.log(ans);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8').trim().split("\n"))


Measured memory_bytes: 7372
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout<< (x) << " "
//acgt
int main(){
    string s;cin>>s;
    int mx = 0;
    int tmp = 0;
    rep(i,s.size()){
        if(s[i]=='A'||s[i]=='G'||s[i]=='C'||s[i]=='T')tmp++;
        else{mx = max(mx,tmp);tmp=0;}
    }
    co(max(mx,tmp));
}

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

int main(){
 ll N,M; cin >> N >> M;
  vector<vector<int>> to(N);
  for(ll i = 0; i < M; i++){
    ll a,b; cin >> a >> b; a--; b--;
    to[a].push_back(b); to[b].push_back(a);
  }
  
  bool flag = false; //奇数ループが存在するか否か
  
  //閉路検索はBFSで可能
  vector<ll> visited(N,-1);//-1は未到達
  vector<bool> color(N,true); //trueは白
  ll black = 0; ll white = 0; //偶数を黒、奇数を白
  
  queue<ll> Q; Q.push(0); visited[0] = 0;
  
  while( !Q.empty()){
    ll p = Q.front(); Q.pop();
    for(auto q : to[p]){
      if( visited[q] == -1){ //　未到達なら進める
        color[q] = !color[p];
        visited[q] = visited[p]+1;
        Q.push(q);
      }
      else if( abs(visited[q]-visited[p]) == 1){ //直前におとづれていた時
        continue;}
      else{ //ループ検出
        if( (visited[p]+visited[q])% 2 == 0){ //奇数ループ発見
          flag = true; break;
        }
      }
    }
    if(flag){ break;}
  }
        
  for(auto ne : color){
    if(ne){ white++;} else{ black++;}
  }
  
  if(flag){
    cout << (N*(N-1))/2-M << endl;
  }
  else{
    cout << black*white-M << endl;
  }
  
  return 0;
}
  
  

Measured memory_bytes: 6656
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

int descending_compare(const void *a, const void *b){
    if (*(int*)a > *(int*)b){
        return -1;
    }else if (*(int*)a == *(int*)b){
        return 0;
    }else{
        return 1;
    }
}

int ascending_compare(const void *a, const void *b){
    if (*(int*)a < *(int*)b){
        return -1;
    }else if (*(int*)a == *(int*)b){
        return 0;
    }else{
        return 1;
    }
}


int lower_bound(int *a, int n, int key){
    int left, mid, right;
    left = 0, right = n;
    mid = (left + right)/2;
    while ((left+1 != mid || mid+1 != right) && mid != left){
        if (key > a[mid]){
            left = mid;
        }else{
            right = mid+1;
        }
        mid = (left + right)/2;
    }
    if (a[left] >= key)return left;
    if (a[mid] >= key)return mid;
    if (a[right] >= key)return right;
    return n;
}

//greatest common divisor
unsigned long  gcd(unsigned long x, unsigned long y){
    if (y == 0){ 
        return x;
    }else if (x > y){
        return gcd(y, x % y);
    }else{
        return gcd(x, y % x);
    }
}



long long factorial(int x){
    long long rtn = 1;
    int i;
    for (i = x; i > 1; i--){
        rtn = (rtn*i);
    }
    return rtn;
}

long long dp[200] = {0};

int main(void){
    int l, k;
    long long ans;
    scanf("%d %d", &l, &k);
    dp[1] = 1;
    dp[k] = 1;
    for (int i = 0; i < (l-1)/2; i++){
        for (int j = l; j >= 0; j--){
            if (dp[j] > 0){
                dp[j+k+1] += dp[j];
                dp[j+2] += dp[j]; 
                ans += dp[j];
                dp[j] = 0;
            }
        }
    }
    for (int i = 1; i <= l; i++){
        ans += dp[i];
    }
    printf("%lld\n", ans);

    return 0;
}



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

using namespace std;

const int inf = 1e9;

int main () {
    int N;
    std::cin >> N;
    std::vector< std::vector<int> > input(N, std::vector<int>(3));
    for ( int i = 0; i < N; ++i ) 
        std::cin >> input[i][0] >> input[i][1] >> input[i][2];

    int dp[N][3];
    dp[0][0] = input[0][0];
    dp[0][1] = input[0][1];
    dp[0][2] = input[0][2];
    for ( int i = 1; i < N; ++i ) {
        dp[i][0]  = input[i][0] + max(dp[i-1][1], dp[i-1][2]);
        dp[i][1]  = input[i][1] + max(dp[i-1][0], dp[i-1][2]);
        dp[i][2]  = input[i][2] + max(dp[i-1][1], dp[i-1][0]);
    } 
    std::cout << *max_element(dp[N-1], dp[N-1] + 3) << std::endl;
    return 0;
}


Measured memory_bytes: 6912
#include<bits/stdc++.h>
using namespace std;
const int mxn=5010,md=924844033;
int n,k,a[mxn],fct[mxn],f[mxn][2],g[mxn][2];
int main()
{
	cin >> n >> k;
	fct[0]=1;
	for (int i=1;i<=n;++i)
		fct[i]=1ll*fct[i-1]*i%md;
	f[0][0]=1;
	for (int i=1;i<=n&&i<=k;++i){
		int m=(n-i)/k;
		for (int j=1;j<=m;++j)
			for (int l=n;l>=0;--l){
				f[l][0]=(f[l][0]+f[l][1])%md;
				if (l) f[l][1]=f[l-1][0];
			}
		for (int j=0;j<=n;++j)
			f[j][0]=(f[j][0]+f[j][1])%md,f[j][1]=0;
		for (int j=1;j<=m;++j)
			for (int l=n;l>=0;--l){
				f[l][0]=(f[l][0]+f[l][1])%md;
				if (l) f[l][1]=f[l-1][0];
			}
		for (int j=0;j<=n;++j)
			f[j][0]=(f[j][0]+f[j][1])%md,f[j][1]=0;
	}
	int ans=0;
	for (int i=0,flg=1;i<=n;++i,flg*=-1)
		ans=(ans+1ll*flg*f[i][0]*fct[n-i])%md;
	cout << (ans+md) % md << '\n';
	return 0;
}

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

#define int long long
#define itn int
#define For(i, a, b) for (int i = (a); i <= static_cast<int>(b); i++)
#define Forr(i, a, b) for (int i = (a); i >= static_cast<int>(b); i--)
#define rep(i, n) For(i, 0, n - 1)
#define repall(i, arr) for (auto& i : (arr))
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define dump(x) cerr << #x << " = " << (x) << '\n'
#define dump2(x, y) \
    cerr << #x << " = " << (x) << " " << #y << " = " << (y) << '\n'
#define SZ(x) ((int)(x).size())
#define bit(n) (1LL << (n))
constexpr int MOD = 1e9 + 7;

template <typename T>
using pq = priority_queue<T>;
template <typename T>
using pqr = priority_queue<T, vector<T>, greater<T>>;
const int INF = LLONG_MAX / 2;
using P = pair<int, int>;
using vec = vector<int>;
template <typename T>
using mat = vector<vector<T>>;

// clang-format off
template <typename T1, typename T2>
ostream& operator<<(ostream& stream, const pair<T1, T2>& p) { return stream << p.first << "," << p.second; }
template <typename T>
void print(const vector<T> vec) { rep (i, vec.size() - 1) cout << vec[i] << ' '; cout << vec[vec.size() - 1] << '\n'; }
template <typename Arg>
void print(const Arg arg) { cout << arg << '\n'; }
template <typename Head, typename... Args>
void print(const Head head, const Args... args) { cout << head << " "; print(args...); }
template <typename T, typename U>
void init(vector<T>& v, vector<U>& w) { rep (i, v.size()) cin >> v[i] >> w[i]; }
template <typename T>
void init(vector<T>& v) { rep (i, v.size()) cin >> v[i]; }
template <typename T>
T sum_(vector<T> vec, T init = 0) { return std::accumulate(all(vec), T(init)); }
template<typename T>
bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } return false; }
template<typename T>
bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } return false; }
template <typename T>
int index(const T& vec, const typename T::iterator it) { return distance(vec.begin(), it); }
template <typename T = int>
mat<T> mmat(int n, int m=0) { return mat<T>(n, vector<T>(m)); }
template <typename T = int>
vector<T> ivec(int n) { vector<T> v(n); init(v); return v; }
// clang-format on

void yn(bool tf) { print(tf ? "Yes" : "No"); }
void YN(bool tf) { print(tf ? "YES" : "NO"); }

int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
// -------------------------------------------------------------------
// sort 1 2 3 4
// pqr 1 2 3 must impl >

signed main() {
    cin.tie(0), cout.tie(0), ios::sync_with_stdio(false);
    int m1, d1, m2, d2;
    cin >> m1 >> d1 >> m2 >> d2;

    if (m1 == m2)
        print(0);
    else
        print(1);

    return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder.Abc
{
    class QuestionC
    {
        public static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            //// 文字列の入力
            //string s = Console.ReadLine();

            //// 整数の入力
            //long n = long.Parse(Console.ReadLine());

            //// 文字列配列の入力
            //string[] inputStrArray = Console.ReadLine().Split(' ');

            //// 整数配列の入力
            //var inputLongArray = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();

            long[][] input = new long[3][];
            bool[][] ret = new bool[3][];

			for (int n = 0; n < 3; n++) {
                var inputLongArray = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();
                input[n] = new long[3];
                input[n][0] = inputLongArray[0];
                input[n][1] = inputLongArray[1];
                input[n][2] = inputLongArray[2];
                ret[n] = new bool[3];
            }

            long N = long.Parse(Console.ReadLine());
            var lists = new List<long>();

			for (int n = 0; n < N; n++) {
                lists.Add(long.Parse(Console.ReadLine()));
			}

			for (int n = 0; n < N; n++) {
			    for (int i = 0; i < 3; i++) {
				    for (int j = 0; j < 3; j++) {
						if (input[i][j] == lists[n]) {
                            ret[i][j] = true;
						}
				    }
			    }
			}


            string result = "No";

			if (ret[0][0] && ret[0][1] && ret[0][2]) {
                result = "Yes";
			}

            if (ret[1][0] && ret[1][1] && ret[1][2]) {
                result = "Yes";
            }

            if (ret[2][0] && ret[2][1] && ret[2][2]) {
                result = "Yes";
            }

            if (ret[0][0] && ret[1][0] && ret[2][0]) {
                result = "Yes";
            }

            if (ret[0][1] && ret[1][1] && ret[2][1]) {
                result = "Yes";
            }

            if (ret[0][2] && ret[1][2] && ret[2][2]) {
                result = "Yes";
            }

            if (ret[0][0] && ret[1][1] && ret[2][2]) {
                result = "Yes";
            }

            if (ret[0][2] && ret[1][1] && ret[2][0]) {
                result = "Yes";
            }

            Console.WriteLine(result);

            Console.Out.Flush();
        }
    }
}


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

int main () {
  string S;
  cin >> S;
  int N = S.size();
  
  for (int i = N-1; i >= 0; i--) {
    if (i <= 3){
      cout << "NO" << endl;
      return 0;
    }
    int count = 0;
    if (S.at(i-4) == 'd' && S.at(i-3) == 'r' && S.at(i-2) == 'e' && S.at(i-1) == 'a' && S.at(i) == 'm'){
      count++;
      i -= 4;
    }
    else if (S.at(i-4) == 'e' && S.at(i-3) == 'r' && S.at(i-2) == 'a' && S.at(i-1) == 's' && S.at(i) == 'e'){
      count++;
      i -= 4;
    }
    else if (i >= 5 && S.at(i-5) == 'e' && S.at(i-4) == 'r' && S.at(i-3) == 'a' && S.at(i-2) == 's' && S.at(i-1) == 'e' && S.at(i) == 'r'){
      count++;
      i -= 5;
    }
    else if (i >= 6 && S.at(i-6) == 'd' && S.at(i-5) == 'r' && S.at(i-4) == 'e' && S.at(i-3) == 'a' && S.at(i-2) == 'm' && S.at(i-1) == 'e' && S.at(i) == 'r'){
      count++;
      i -= 6;
    }
    if (count == 0){
      cout << "NO" << endl;
      return 0;
    }
  }
  cout << "YES" << endl; 
}
  
    
   

Measured memory_bytes: 3708
import java.util.*;
class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        char a;

        a = sc.next().charAt(0);

        if (Character.isUpperCase(a)) {
            System.out.println('A');
        } else {
            System.out.println("a");
        }
    }

}

Measured memory_bytes: 35696
#include <iostream>
using namespace std;
int n,m,q,dp[501][501],a,b;
int main(void){
    cin>>n>>m>>q;
    for(int i=0;i<m;i++){
        cin>>a>>b;
        dp[a][b]+=1;
    }
    for(int i=1;i<=n;i++){
        for(int j=0;j<n;j++){
            dp[i][j+1]+=dp[i][j];
        }
    }
    for(int i=1;i<=n;i++){
        for(int j=0;j<n;j++){
            dp[j+1][i]+=dp[j][i];
        }
    }
    while(q--){
        cin>>a>>b;
        cout<<dp[b][b]-dp[b][a-1]-dp[a-1][b]+dp[a-1][a-1]<<endl;
    }
}


Measured memory_bytes: 1920
p = [sorted(map((lambda x: (float(x[1]), x[1], x[0])), [raw_input().split() for i in xrange(8)]), reverse=True) for j in xrange(3)]
for i in xrange(3):
    for j in xrange(2):
        print "%s %s" % tuple(p[i].pop()[-1:0:-1])
for i in xrange(2):
    e = p[0][-1], p[1][-1], p[2][-1]
    k = 2
    if e[0]<e[1] and e[0]<e[2]: k=0
    elif e[1]<e[2]: k=1
    print "%s %s" % tuple(p[k].pop()[-1:0:-1])

Measured memory_bytes: 4264
// I can't tell you what it really is,
// I can only tell you what it feels like.
#include "bits/stdc++.h"
using namespace std;
 
#define int long long
#define F first
#define S second
#define sz(x) ((int)x.size())
#define rep(i,a,n) for (int i = a; i <= n; ++i)
#define all(v)  v.begin(), v.end()
#define pb push_back
#define P pair < int, int >
#define E cout << '\n'

const int mod = 1e9 + 7;
const int N = 4e5 + 5;

int a[N];
 
inline void solve() {
 	int n;
 	cin >> n;
 	cout << fixed << setprecision(10);
 	cout << ((n+1)/2) / (n*1.0);  
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  int t = 1;
  //cin >> t; while(t--)
  solve();
  return 0;
}

Measured memory_bytes: 256
a = int(input())
h_list = input().split()
h_list = [int(i) for i in h_list]


def grand_garden(h_list, count):
    hana_list = []
    kari_list = []
    if len(h_list) == 0:
        return
    for i in range(len(h_list)):
        if h_list[i] != 0:
            kari_list.append(h_list[i])
        else:
            hana_list.append(kari_list)
            kari_list = []
    if kari_list != []:
        hana_list.append(kari_list)
    for u in hana_list:
        if len(u) == 0:
            continue
        min_index = u.index(min(u))
        count.append(u[min_index])
        u = [i - u[min_index] for i in u]
        grand_garden(u, count)


count = []
grand_garden(h_list, count)
print(sum(count))


Measured memory_bytes: 3188
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <cmath>
using namespace std;
typedef long long ll;

int main() {
    ll N,K;
    cin >> N >> K;
    
    vector<ll> tree;
    ll temp;
    for(int i=0;i<N;i++){
        cin >> temp;
        tree.push_back(temp);
    }
    sort(tree.begin(),tree.end());
    ll ans=tree[K-1]-tree[0];
    ll tmp=0;
    for(int i=K-1;i<N;i++){
        tmp=tree[i]-tree[i-(K-1)];
        ans=min(ans,tmp);
    }
    cout << ans << endl;
}

Measured memory_bytes: 1400
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main()
{
    int N, M, X, Y;
    cin >> N >> M >> X >> Y;
    vector<int> x(N);
    vector<int> y(M);
    for(auto & in : x){
        cin >> in;
    }
    for(auto & in : y){
        cin >> in;
    }
    auto max_x = *max_element(x.begin(), x.end());
    auto min_y = *min_element(y.begin(), y.end());
    int iswar = 1;
    for(auto Z = X + 1; Z <= Y; ++Z){
        if(max_x < Z && Z <= min_y){
            iswar = 0;
            break;
        }
    }
    if(iswar){
        cout << "War";
    } else {
        cout << "No War";
    }
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <map>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <set>
#include <stack>
#include <stack>
#include <list>
#include <algorithm>
#include <numeric>
#include <utility>
#include <complex>
#include <functional>

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

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

int main(){
    int n;
    cin >> n;
    
    int build[4][3][10] = {{{}}};
    int b, f, r, v;
        
    rep(i,n){
        cin >> b >> f >> r >> v;
        build[b-1][f-1][r-1] += v;
    }
    
    rep(i,4){
        rep(j,3){
            rep(k,10){
                cout << " ";
                cout << build[i][j][k];
            }
            cout << endl;
        }
        if(i<3) cout << "####################" << endl;
    }
        
    return 0;
}



Measured memory_bytes: 3104
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
 
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=(n)-1;i>=0;i--)
#define VSORT(v) sort(v.begin(), v.end())
#define DVSORT(v) sort(v.begin(), v.end(),greater<int>())
#define SORT(v, n) sort(v, v+n)
#define DSORT(v,n) sort(v, v+n,greater<int>())
#define vi vector<int>
#define pb push_back
#define P pair<int,int>
#define Pll pair<ll,ll>

template <class T> void chmin(T&a,const T&b) { a = min(a,b); }
template <class T> void chmax(T&a,const T&b) { a = max(a,b); }
 
void print(){cout<<endl;}
template <class Head, class... Tail>
void print(Head&& h,Tail&&... t){ 
	if(sizeof...(t)==0)
		cout<<h;
	else
		cout<<h<<' ';
	print(move(t)...);
}
 
const double EPS =1e-9;
const int INF =2e+9;
const ll INFL =9e+18;
const long MOD =1e+9+7;
#define PI 3.14159265258979

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

int main(void){
	int H,W,D,A,Q,L,R;
	map<int,P> mp;	
	cin>>H>>W>>D;
	REP(i,H){
		REP(j,W){
			cin>>A;
			mp[A]=P(i+1,j+1);
		}
	}

	map<P,ll> mp2;
	FOR(i,1,D+1){
		mp2[P(i,i)]=0;
		ll sum=0;
		L=i;
		while(L<=H*W){
			sum+=(ll)abs(mp[L+D].first-mp[L].first);
			sum+=(ll)abs(mp[L+D].second-mp[L].second);
			mp2[P(i,L+D)]=sum;
			L+=D;
		}
	}


	cin>>Q;
	REP(i,Q){
		cin>>L>>R;
		if(L==R) print(0);
		else if(L%D==0) print(mp2[P(D,R)]-mp2[P(D,L)]);
		else print(mp2[P(L%D,R)]-mp2[P(L%D,L)]);
	}
	return 0;
}




Measured memory_bytes: 22912
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    int v[51];
    rep(i, N) cin >> v[i];
    sort(v, v + N);
    double ans = v[0];
    rep(i, N - 1) {
        ans = (ans + v[i + 1]) / 2.0;
    }
    cout << fixed << setprecision(12) << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse2")

    /*
    ||||||||||||||||||||||||||||||||||||||||||||||||
       |      |||         |      ||||    ||||  |   |
      | |     |   |      | |     |   |  |      |   |
     |   |    |    |    |   |    |   |  |      |   |
    |||||||   |    |   |||||||   |||     |||   |||||
    |     |   |   |    |     |   | |        |  |   |
    |     |   |||      |     |   |  ||  ||||   |   |
    ||||||||||||||||||||||||||||||||||||||||||||||||

    */
    using namespace std;
    //#include "testlib.h"
    #define ff first
    #define ss second
    #define mp make_pair
    #define all(v) v.begin(),v.end()
    #define int long long
    #define ll long long
    #define M 1000000007
    #define inputarr(a,n) for(int i=0;i<n;++i) cin>>a[i]
    #define GCD(m,n) __gcd(m,n)
    #define LCM(m,n) m*(n/GCD(m,n))
    #define mii  map<ll ,ll >
    #define msi  map<string,ll >
    #define mis  map<ll int, string>
    #define rep(a,b)    for(ll i=a;i<b;i++)
    #define rep0(n)    for(ll i=0;i<n;i++)
    #define repi(i,a,b) for(ll i=a;i<b;i++)
    #define pb push_back
    #define vi vector<ll>
    #define mp make_pair
    #define vs vector<string>
    #define ppb pop_back
    #define endl '\n'
    #define asdf ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    #define r0 return 0;
    #define FORD(i, a, b) for (int i = (int) (a); i >= (int) (b); --i)
    #define FORE(it, c) for (__typeof((c).begin()) it = (c).begin(); it != (c).end(); ++it)
    #define inputoutput freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
    #define input freopen("input.txt", "r", stdin);
    #define Set(a, s) 4(a, s, sizeof (a))
    #define FOR repi
    #define pii pair<int,int>
    //#define float long double
    ll max(ll a, ll b) { return (a > b)? a : b;}
    int min(int a, int b) { return (a < b)? a : b;}


     int solve()
     {
     	int n;
     	cin>>n;
     	vi a(n);
     	inputarr(a,n);
     	int ans=0;
     	rep0(n){
     		if(a[i]!=i+1) ans+=1;
         
     }
     if(ans>2) cout<<"NO";
     else cout<<"YES";
     	}
    signed main()
    {   
        asdf
        int t=1;
        //cin>>t;
        while(t--)
        {
            solve();
        }     
        
}

Measured memory_bytes: 256
import sys
def input(): return sys.stdin.readline().strip()


def main():
    N, K = map(int, input().split())
    sushi = []
    neta = set([])
    for _ in range(N):
        t, d = map(int, input().split())
        sushi.append((d, t))
        neta.add(t)
    sushi.sort()
    L = len(neta)

    eat_kind = set([])
    same_kind = []
    point = 0
    for _ in range(K):
        d, t = sushi.pop()
        point += d
        if t not in eat_kind:
            eat_kind.add(t)
        else:
            same_kind.append((d, t))
    l = len(eat_kind)
    point += l ** 2
    #print("l={}, point={}".format(l, point))

    """
    貪欲でおいしいもの順にネタを取った後、新しい種類のネタにどんどんスイッチしていく方針はあっていたのに
    実装がヘビーになりすぎるから考えを間違っているだろうと撤退したのが愚かだった...!
    
    今は実装力を上げるパートということですね。
    """

    remain = [(d, t) for d, t in sushi if t not in eat_kind]
    remain.sort()
    #print("remain={}".format(remain))
    val = point # 前状態のポイント
    for i in range(l, L): # 前よりポイントが下がったとしてもどんどんネタの入れ替えをしていく！
        val = val - i ** 2 + (i + 1) ** 2
        if not same_kind: break
        pre_d, _ = same_kind.pop()
        val -= pre_d
        if not remain: break
        d, t = remain.pop()
        while t in eat_kind: d, t = remain.pop()
        val += d
        eat_kind.add(t)
        point = max(point, val)
        #print("l={}, point={}".format(i, val))

    print(point)

    



if __name__ == "__main__":
    main()


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

int main() {
    int n; cin >> n;
    vector<long> s(n);
    for (int i=0; i<n; i++) cin >> s.at(i);
    int q; cin >> q;
    vector<long> t(q);
    for (int i=0; i<q; i++) cin >> t.at(i);

    int count=0;
    for (int i=0; i<q; i++) {
        for (int j=0; j<n; j++) {
            if (s.at(j) == t.at(i)) {
                count++;
                break;
            }
        }
    }
    cout << count << endl;
}


Measured memory_bytes: 3136
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
#define endl '\n'
typedef long long ll;
typedef pair<ll,ll> pll;
typedef long double ld;
const ll mod=1e9+7;
const ll inf=1e9+7;
signed main(){
    ll n;cin>>n;
    ll ans=0;
    REP(i,1,n+1){
        ans+=i*(n-i+1);
    }
    rep(i,n-1){
        ll u,v;cin>>u>>v;
        if(u>v)swap(u,v);
        ans-=u*(n+1-v);
    }
    cout<<ans<<endl;
}

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

int main() {

	int i = 0;

	int w, h;

	int nums[2][3000];

	while (true) {
		cin >> h >> w;

		if (w == 0 && h == 0) break;

		nums[0][i] = h;
		nums[1][i] = w;

		i++;
	}

	for (int j = 0; j < i; j++) {
		for (int y = 0; y < nums[0][j]; y++) {
			for (int x = 0; x < nums[1][j]; x++) {
				if ((y + x) % 2 == 0)
					cout << "#";
				else
					cout << ".";
			}
			cout << endl;
		}
		cout << endl;
	}

	return 0;
}


Measured memory_bytes: 3112
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1e9;
const int MOD = 1e9 + 7;

int main()
{
  int n;
  while (cin >> n, n)
  {
    ll dp[31] = {};
    dp[1] = dp[2] = dp[3] = 1;
    for (int i = 0; i < n; ++i)
    {
      dp[i + 1] += dp[i];
      dp[i + 2] += dp[i];
      dp[i + 3] += dp[i];
    }
    cout << (dp[n] - 1) / 3650 + 1 << endl;
  }

  return 0;
}



Measured memory_bytes: 3060
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <iterator>
#include <cmath>
#include <set>
#include <deque> 
#include <string>


using namespace std;

char s[10];


int main()
{
	scanf("%s", s);
	
	if (strcmp(s, "SUN") == 0) {
		printf("7\n");
	} else if (strcmp(s, "SAT") == 0) {
		printf("1\n");
	} else if (strcmp(s, "FRI") == 0) {
		printf("2\n");
	} else if (strcmp(s, "THU") == 0) {
		printf("3\n");
	} else if (strcmp(s, "WED") == 0) {
		printf("4\n");
	} else if (strcmp(s, "TUE") == 0) {
		printf("5\n");
	} else if (strcmp(s, "MON") == 0) {
		printf("6\n");
	}
	
		
	return 0;
}


Measured memory_bytes: 128
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
 
struct node{
  int key;
  struct node *next;
  struct node *prev;
};
 
typedef struct node * NodePointer;
 
NodePointer nil;
void insert(int key);
int delete(int key);
int deleteFirst();
int deleteLast();
void init();
 
main(){
  int n, i, keydata;
  char com[12];
  NodePointer p;
  scanf("%d",&n);
  nil=malloc(sizeof(struct node));
  init();
  
  for (i=0;i<n;i++){
    scanf("%s",com);
    if(strlen(com)>6){
      if(com[6]=='F') {
	deleteFirst();
      }else{
	deleteLast();
      }
    }else{
      scanf("%d",&keydata);
      if(com[0]=='i'){
	insert(keydata);
      }else{
	delete(keydata);
      }
    }
  }

  for(p=nil->next;p!=nil->prev;p=p->next){
    printf("%d ",p->key);
  }
  printf("%d\n",p->key);
  free(nil);
  return 0;
}
 
void insert(int keydata){
    NodePointer x;
    x=malloc(sizeof(struct node));
    x->key=keydata;
    x->next=nil->next;
    x->prev=nil;
    nil->next=x;
    x->next->prev=x;
}
 
int delete(int keydata){
  NodePointer p;
  p=nil->next;
  while(p!=nil&&p->key!=keydata){
    p=p->next;
  }
  if(p==nil){
    return 0;
  }else{
    p->prev->next=p->next;
    p->next->prev=p->prev;
    free(p);
    return 0;
  }
}
 
int deleteFirst(){
    NodePointer p;
    p=nil->next;
    nil->next=p->next;
    p->next->prev=nil;
    free(p);
    return 0;
}
 
int deleteLast(){
    NodePointer p;
    p=nil->prev;
    p->prev->next=nil;
    nil->prev=p->prev;
    free(p);
    return 0;
}

void init(){
  nil->next=nil;
  nil->prev=nil;
}

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

typedef unsigned long long ll;
typedef pair<ll,ll> pi;
typedef vector <ll> vi;
typedef vector <pi> vpi;
#define f first
#define s second
#define FOR(i,s,e) for(ll i=s;i<=ll(e);++i)
#define DEC(i,s,e) for(ll i=s;i>=ll(e);--i)
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define lbd(x, y) lower_bound(all(x), y)
#define ubd(x, y) upper_bound(all(x), y)
#define aFOR(i,x) for (auto i: x)
#define mem(x,i) memset(x,i,sizeof x)
#define fast ios_base::sync_with_stdio(false),cin.tie(0)
#define int ll
#define MOD 1000000007
#define maxn 200001

int N,M,a,b,p[maxn],sz[maxn];

int fl(int x){
	if (p[x] == x) return p[x];
	return p[x] = fl(p[x]);
}

void join(int a,int b){
	int x = fl(a), y = fl(b);
	if (x == y) return;
	
	sz[y] += sz[x];
	p[x] = y;
}

int32_t main()
{
    cin>>N>>M;
    
    iota(p,p+N+1,0); FOR(i,1,N) sz[i] = 1;
    FOR(i,1,M){
		cin>>a>>b;
		join(a,b);
	}
	
	cout << *max_element(sz+1,sz+N+1);
	
    
}


Measured memory_bytes: 6668
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long LL;
int main(){
    int n;
    cin>>n;
    int sum=0;
    int s[101];
    for(int i=0;i<n;i++){
        cin>>s[i];
        sum+=s[i];
    }
    if(sum%10==0){
        sort(s, s+n);
        for(int i=0;i<n;i++){
            if(s[i]!=0&&s[i]%10!=0){
                sum-=s[i];
                break;
            }
            if(i==n-1)sum=0;
        }

    }
        cout<<sum<<endl;
}

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

#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(a)  (a).begin(),(a).end()

template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}
typedef long long ll;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}

void solve() {
    int N,P;
    cin >> N >> P;
    string S;
    cin >> S;
    if (P==2 || P==5) {
        ll res = 0;
        REP(i,N) if ((S[N-i-1]-'0')%P == 0) res += N-i;
        cout << res << endl;
        return;
    }


    map<ll,ll> mp;
    // a_0は0なのでその分を考慮する。
    mp[0] = 1;
    ll tenfactor = 1,cur = 0;
    REP(i,N) {
        cur = (cur + (S[N-i-1] - '0') * tenfactor) % P;
        tenfactor = (tenfactor * 10) % P;
        if (mp.count(cur) == 0) mp[cur] = 0;
        mp[cur]++;
    }

    ll res = 0;
    for(const auto &it: mp) res += (it.second*(it.second-1))/2;
    cout << res << endl;
}

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


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

int main() {
  int y, m, d;
  char c;

  std::cin >> y >> c >> m >> c >> d;

  if( 10000 * y + 100 * m + d <= 20190430 ) {
		std::cout << "Heisei" << std::endl;
	} else {
		std::cout << "TBD" << std::endl;
	}

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(false), cin.tie(0);
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define endl '\n'

using namespace std;

main()
{
    fast;
    string s;
    cin>>s;
    int i,hash[26]={0},f=0;
    for (i=0;i<s.size();i++)
        hash[s[i]-97]++;
    for (i=0;i<26;i++)
    {
        if (hash[i]==0)
        {
            f=1;
            cout<<(char)(97+i)<<endl;
            break;
        }
    }
    if (!f)
        cout<<"None\n";
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define Y printf("YES\n")
#define N printf("NO\n")
#define mp make_pair
#define pb push_back
#define sc(a) scanf("%lld",&a)
#define sc2(a,b) scanf("%lld%lld",&a,&b)
#define pr(a) printf("%lld\n",a)

int main()
{
    ll n,m,i,j,k,l,t,x,y,z;

    cin>>x>>y;

    if(y%2){

        cout<<"No"<<endl;
        return 0;
    }

    if(y>4*x || y<2*x){

        cout<<"No"<<endl;
        return 0;
    }

    cout<<"Yes"<<endl;
    return 0;


}


Measured memory_bytes: 3640
package main

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

//Util
func nextStr() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func maxInt(a, b int) int {
	if a > b {
		return a
	} else {
		return b
	}
}

func minInt(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}

func absInt(a int) int {
	if a >= 0 {
		return a
	} else {
		return -a
	}
}

func absFloat64(a float64) float64 {
	if a >= 0 {
		return a
	} else {
		return -a
	}
}

func maxFloat64(a, b float64) float64 {
	if a > b {
		return a
	} else {
		return b
	}
}

func minFloat64(a, b float64) float64 {
	if a > b {
		return b
	} else {
		return a
	}
}

func str2Int(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}

func reverse(s string) string {
	runes := []rune(s)
	for i, j := 0, len(runes)-1; i < j; i, j = i+1, j-1 {
		runes[i], runes[j] = runes[j], runes[i]
	}
	return string(runes)
}

func powInt(p, q int) int {
	return int(math.Pow(float64(p), float64(q)))
}

func isPrime(x int) bool {
	if x == 1 {
		return false
	}
	if x == 2 {
		return true
	}
	if x%2 == 0 {
		return false
	}

	b := true
	rootx := int(math.Sqrt(float64(x)))
	i := 3
	for i <= rootx {
		if x%i == 0 {
			b = false
			break
		}
		i += 2
	}
	return b
}

func PrimeFactors(n int) (pfs []int) {
	// Get the number of 2s that divide n
	for n%2 == 0 {
		pfs = append(pfs, 2)
		n = n / 2
	}

	// n must be odd at this point. so we can skip one element
	// (note i = i + 2)
	for i := 3; i*i <= n; i = i + 2 {
		// while i divides n, append i and divide n
		for n%i == 0 {
			pfs = append(pfs, i)
			n = n / i
		}
	}

	// This condition is to handle the case when n is a prime number
	// greater than 2
	if n > 2 {
		pfs = append(pfs, n)
	}

	return
}

func sumInts(x []int) int {

	total := 0
	for _, v := range x {
		total += v
	}

	return total
}

//Main
const (
	initialBufSize = 10000
	maxBufSize     = 1000000
	mod            = 1e9 + 7
)

var (
	sc *bufio.Scanner = func() *bufio.Scanner {
		sc := bufio.NewScanner(os.Stdin)
		buf := make([]byte, initialBufSize)
		sc.Buffer(buf, maxBufSize)
		return sc
	}()
)

var N, M, K int

var P = powInt(10, 10)

func main() {
	sc.Split(bufio.ScanWords)

	N, M, K = nextInt(), nextInt(), nextInt()
	A := make([]int, N+1)
	B := make([]int, M+1)
	A[0] = 0
	for i := 1; i <= N; i++ {
		A[i] = nextInt() + A[i-1]
	}
	B[0] = 0
	for i := 1; i <= M; i++ {
		B[i] = nextInt() + B[i-1]
	}

	ans := 0
	j := M
	for i := 0; i <= N; i++ {
		if A[i] > K {
			break
		}
		for B[j] > K-A[i] {
			j--
			continue
		}

		ans = maxInt(ans, i+j)
	}

	fmt.Println(ans)
}


Measured memory_bytes: 8272
// By Atul Rathore

#include<bits/stdc++.h>
using namespace std;

#define ll long long int
#define f(n) for(int i=0;i<n;i++)
#define p(x) cout<<x<<endl;
#define fastio ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);


int main()
{
	fastio;
	int n,k;
	cin>>n>>k;
	ll ans=0;
	for(int i=k;i<=n+1;i++)
	{
		ll x=(ll)i*(n-i+1)+1LL;
		ll y=x%1000000007LL;
		ans+=y;
		ans=ans%1000000007LL;
		
	}
	cout<<ans<<endl;
		
	
	
	
}


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

#if DEBUG
template <typename Iter>
void debug_iter(Iter begin, Iter end);
template <typename T>
void debug(const T& value) {
  std::cerr << value;
}
template <typename T>
void debug(const std::vector<T>& v) {
  debug_iter(v.begin(), v.end());
}
template <typename T>
void debug(const std::set<T>& s) {
  debug_iter(s.begin(), s.end());
}
template <typename T, typename U>
void debug(const std::map<T, U>& m) {
  debug_iter(m.begin(), m.end());
}
template <typename T, typename U>
void debug(const std::pair<T, U>& p) {
  std::cerr << "{";
  debug(p.first);
  std::cerr << ", ";
  debug(p.second);
  std::cerr << "}";
}
template <typename T, typename... Ts>
void debug(const T& value, const Ts&... args) {
  debug(value);
  std::cerr << ", ";
  debug(args...);
}
template <typename Iter>
void debug_iter(Iter begin, Iter end) {
  std::cerr << "{";
  for (Iter it = begin; it != end; ++it) {
    if (it != begin) std::cerr << ", ";
    debug(*it);
  }
  std::cerr << "}";
}
#define dbg(...)                        \
  do {                                  \
    cerr << #__VA_ARGS__ << ": ";       \
    debug(__VA_ARGS__);                 \
    cerr << " (L" << __LINE__ << ")\n"; \
  } while (0)
#else
#define dbg(...)
#endif

void read_from_cin() {}
template <typename T, typename... Ts>
void read_from_cin(T& value, Ts&... args) {
  std::cin >> value;
  read_from_cin(args...);
}
#define rd(type, ...) \
  type __VA_ARGS__;   \
  read_from_cin(__VA_ARGS__);

template <typename T>
void write_to_cout(const T& value) {
  std::cout << value << '\n';
}
template <typename T, typename... Ts>
void write_to_cout(const T& value, const Ts&... args) {
  std::cout << value << ' ';
  write_to_cout(args...);
}
#define wt(...) write_to_cout(__VA_ARGS__);

#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)

template <typename T>
std::istream& operator>>(std::istream& is, std::vector<T>& v) {
  for (T& vi : v) is >> vi;
  return is;
}

template <typename T>
bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

template <typename T>
bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

#include <boost/hana/functional/fix.hpp>
auto Fix = [](auto&& f) { return boost::hana::fix(f); };

using ll = long long;

template <typename T>
using V = std::vector<T>;
template <typename T>
using VV = V<V<T>>;

using namespace std;

int main() {
#define int ll
  rd(int, x, k, d);
  if (x < 0) x = -x;
  if (x / d > k) {
    wt(x - k * d);
    return 0;
  }
  int y = x % d;
  k -= x / d;
  k %= 2;
  if (k == 1) y = d - y;
  wt(y);
#undef int
}


Measured memory_bytes: 3632