akhauriyash/Code-Regression huggingface dataset:
A = int(input())
B = int(input())
C = int(input())
X = int(input())

counter = 0
for a in range(A + 1):
  for b in range(B + 1):
    for c in range(C + 1):
      if X == a * 500 + b * 100 + c * 50:
        counter += 1
print(counter)

Measured memory_bytes: 3060
#include <iostream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <vector>

using namespace std;

int main(){
    int p;
    cin >> p;
    while(true){
        bool flag = true;
        for(int i = 2;i < sqrt(p);i++){
            if(p % i == 0){
                flag = false;
            }
        }
        if(flag){
            cout << p << endl;
            break;
        }
        p++;
    }
}

Measured memory_bytes: 256
O_list = list(input())
E_list = list(input())
output_str = ""
for i, j in zip(O_list, E_list):
    output_str += i + j
    
if  len(O_list) - len(E_list) == 1:
    output_str += O_list[-1]
    
print(output_str)

Measured memory_bytes: 2940
#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<algorithm>
#include<cmath>
using namespace std;
#define INF 0x3f3f3f3f
#define _rep(i,a,b) for(int i=(a);i<=(b);++i)
int n;
int s[20];
void dfs(int k,int maxnum)
{
    if(k==n)
    {
        for(int i=0;i<k;i++)
            cout<<(char)(s[i]+'a');
        cout<<endl;
        return;
    }
    int now=min(k,maxnum+1);
    for(int i=0;i<=now;i++)
    {
        s[k]=i;
        maxnum=max(maxnum,i);
        dfs(k+1,maxnum);
    }
}

int main()
{
    #ifdef __LOCAL__
        freopen("1.in","r",stdin);
        freopen("1.out","w",stdout);
    #endif
    cin>>n;
    dfs(0,0);    
    
    return 0;
}

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

int main(){
    int64_t X;
    cin >> X;
    int64_t now = 100;
    int ans = 0;
    while(now < X){
        ans++;
        now += now/100;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3636
/* 
二部グラフの最大マッチングを求める
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=GRL_7_A&lang=jp
*/
#include <bits/stdc++.h>
#define DUMP(x)  cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define IFOR(i, m, n) for(int i = n - 1; i >= m; i-- )
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define FOREACH(x,a) for(auto& (x) : (a) )
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
const ll INF = 1e18;
/* テンプレートここまで */
ll dfs(ll v, vector<ll>& visited, vector<ll>& matched, vector<vector<ll>>& edges){
  FOREACH(u, edges[v]){
    //uが通過済みなら，次のノードを探索する
    if(find(ALL(visited), u) != visited.end()) continue;
    visited.push_back(u);
    //増加道がある
    if(matched[u] == -1 || dfs(matched[u], visited, matched, edges)){
      matched[u] = v;
      return 1;
    }
  }
  //増加道がない
  return 0;
}

int main() {
  ll N;
  cin >> N;
  vector<vector<ll>> edges(N);
  vector<pair<ll,ll> > ab(N), cd(N);
  REP(i, N){
    cin >> ab[i].first >> ab[i].second;
  }
  REP(i, N){
    cin >> cd[i].first >> cd[i].second;
  }

  REP(i, N){
    REP(j, N){
      if(ab[i].first < cd[j].first && ab[i].second < cd[j].second){
        edges[i].push_back(j);
      }
    }
  }

  vector<ll> matched(N,-1);
  ll ans = 0;
  REP(i, N){
    vector<ll> visited;
    ans += dfs(i, visited, matched, edges);
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
/*g++ file.cpp -o file.out*/
/*./file.out*/

#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;

#define LL long long
#define Mod 1000000007
#define L_Mod 17100000013

int main()
{
    
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    cout<<max(a*b,c*d);
    return 0;
}

Measured memory_bytes: 256
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
using namespace std;
typedef long long ll;
const int N = 1e+5;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b){ a>b?:a=b; }
template<class T, class C> void chmin(T& a, C b){ a<b?:a=b; }

void solve() {
    int n, d;
    set<int> st;
    cin >> n;
    rep(i, n) {
        cin >> d;
        st.insert(d);
    }
    cout << st.size() << endl;
}

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


Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

public class Main {
	 private static String[][] map;

	public static void main(String[] args){
		FastScanner sc = new FastScanner();
		int x = sc.nextInt();
		int y = sc.nextInt();
		map = new String[x][y];
		for(int i=0; i<x;i++){
			String line = sc.next();
			for(int j=0; j<y; j++){
				map[i][j] = String.valueOf(line.charAt(j));
			}
		}
		for(int i=0;i<x;i++){
			StringBuilder sb = new StringBuilder();
			for(int j=0;j<y;j++){
				if(map[i][j].equals("#")){
					sb.append("#");
				} else {
					sb.append(check(i,j));
				}
			}
			System.out.println(sb.toString());
		}

	}

	private static String check(int x, int y){
		int count = 0;
		String target;
		for(int i=-1; i<=1; i++){
			for(int j=-1;j<=1;j++){
				try {
					target = map[x+i][y+j];
					if(target.equals("#")){
						count++;
					}
				} catch (IndexOutOfBoundsException e){
					continue;
				}
			}
		}
		return String.valueOf(count);
	}


}



class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() { return Double.parseDouble(next());}
}

Measured memory_bytes: 22740
#include <iostream>
#include <algorithm>
#include <string>
#include <set>

#include <regex>
#include <locale>
#include <iomanip>

using namespace std;
using ll = long long;

#define OVERLOAD3(_1,_2,_3,name,...) name
#define REP(i,n) REPI(i,0,n)
#define REPI(i,a,b) for(int i=int(a),i##_Len=int(b);i<i##_Len;++i)
#define rep(...) OVERLOAD3(__VA_ARGS__,REPI,REP,)(__VA_ARGS__)
#define ALL(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())

int main () {
  int n; cin >> n;
  cout << n / 3 << endl;
}

Measured memory_bytes: 3120
import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as BS
import Data.List

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine

main = do
    [a, b, c] <- getIntList
    print $ min c (b `div` a)

Measured memory_bytes: 380
#include "bits/stdc++.h"

using namespace std;

typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;

#define dump(x)  cerr << #x << " = " << (x) << endl
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back


int main(){
    int n;
    while(cin>>n){
        if(n==0)break;
        
        int data[6000];
        
        rep(i,n) cin>>data[i];
        
        ll maxi=-999999999999;
        
        for(int i=0;i<n;i++){
            ll sum[6000]={};
            sum[i]=data[i];
            maxi=max(maxi,sum[i]);
            
            for(int j=i+1;j<n;j++){
                sum[j]=sum[j-1]+data[j];
                maxi=max(maxi,sum[j]);
            }

        }
        
        
        cout<<maxi<<endl;
    }
}

Measured memory_bytes: 1228
#include<iostream>
#include<cstring>
using namespace std;	
int arr[101];	
int n,k;
int dp[100001];
 bool solve(int k)
{  
      if(k==0)
        return 0;
        if(dp[k]!=-1)
         return dp[k];
	  for(int i=0;i<n;i++)
	   if(k>=arr[i])
      if(!solve(k-arr[i]))
       return dp[k]=1;
       return dp[k]=0;
	
	
}
int main()
{
 memset(dp,-1,sizeof(dp));
	cin>>n>>k;

	 for(int i=0;i<n;i++)
	  cin>>arr[i];
	  if(solve(k))
	   cout<<"First";
	   else
	    cout<<"Second";
	
}

Measured memory_bytes: 3712
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int n = s.nextInt();
        if(n%1000 == 0)
            System.out.println(0);
        else
            System.out.println(1000-(n%1000));
    }
}


Measured memory_bytes: 35692
#include <bits/stdc++.h>
using ll = long long;
#define FOR(i, k, n) for(ll i = (k); i < (n); i++)
#define FORe(i, k, n) for(ll i = (k); i <= (n); i++)
#define FORr(i, k, n) for(ll i = (k)-1; i > (n); i--)
#define FORre(i, k, n) for(ll i = (k)-1; i >= (n); i--)
#define REP(i, n) FOR(i, 0, n)
#define REPr(i, n) FORre(i, n, 0)
#define ALL(x) (x).begin(), (x).end()
#define ALLr(x) (x).rbegin(), (x).rend()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;
using P = pair<int, int>;
const int INF = 1001001001;

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

  vector<int> w(n+1), e(n+1);
  w[0] = e[n] = 0;
  REP(i, n){
    w[i+1] = w[i];
    if(s[i] == 'W') w[i+1] = w[i]+1;

    e[n-i-1] = e[n-i];
    if(s[n-i-1] == 'E') e[n-i-1] = e[n-i] + 1;
  }

  int ans = INF;
  REP(i, n){
    chmin(ans, w[i]+e[i+1]);
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3076
/**
*    created: 11.05.2020 13:12:30
**/
#include <bits/stdc++.h>
#define int long long
const int INF = 1e18L + 5;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using namespace std;

struct Node{ int parent, left, right; };

vector<Node> T(25);

vector<int> pre;
vector<int> in;
vector<int> post;

void prePerse(int i){
    if (i == -1) return;
    pre.push_back(i);
    prePerse(T[i].left);
    prePerse(T[i].right);
    return;
}

void inPerse(int i) {
    if (i == -1) return;
    inPerse(T[i].left);
    in.push_back(i);
    inPerse(T[i].right);
    return;
}

void postPerse(int i){
    if (i == -1) return;
    postPerse(T[i].left);
    postPerse(T[i].right);
    post.push_back(i);
    return;
}


signed main() {

    cin.tie(0);
    ios_base::sync_with_stdio(false);
    
    int n; cin >> n;
    rep(i,n) T[i].parent = -1; //初期化

    //入力
    int k, l, r;
    rep(i,n) {
        cin >> k >> l >> r;
        T[k].left = l;
        T[k].right = r;
        if (l != -1) T[l].parent = k;
        if (r != -1) T[r].parent = k;
    }

    int root;

    rep(i,n) {
        if (T[i].parent == -1) root = i;
    }
    
    prePerse(root);
    inPerse(root);
    postPerse(root);
    
    cout << "Preorder" << endl;
    rep(i,n) {
        cout << " " << pre[i];
    }
    cout << endl;
    cout << "Inorder" << endl;
    rep(i,n) {
        cout << " "  << in[i];
    }
    cout << endl;
    cout << "Postorder" << endl;
    rep(i,n) {
        cout << " " << post[i];
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 3220
#include <algorithm>
#include <functional>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <climits>

#define all(c) (c).begin(), (c).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
#define fr first
#define sc second

const int INF=100000000;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
using namespace std;
typedef pair<int ,int > P;
typedef long long ll;

int n;
int a[102];

int bubble_sort() {
    int res=0;
    for(int i=0;i<n;i++) {
        for(int j=n-1;j>=i+1;j--) {
            if(a[j]<a[j-1]) swap(a[j-1],a[j]),res++;
        }
    }
    return res;

}

int main() {
    cin>>n;
    rep(i,n) cin>>a[i];
    int ans = bubble_sort();
    rep(i,n) cout<<(i==0?"":" ")<<a[i];
    cout<<endl;
    cout<<ans<<endl;
    return 0;
}

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

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

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

int main() {
  // use scanf in CodeForces!
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  ll N, M; cin >> N >> M;
  vector<ll> dp(N+1, 0);
  vector<bool> kaidan(N+1, true);
  ll mod = 1e9+7;
  dp[0] = 1;
  REP(i, M) {
    int d; cin >> d; kaidan[d] = false;
  }
  REP(i, N) {
    if (kaidan[i]) dp[i+1] += dp[i];
    if (i > 0 and kaidan[i-1]) dp[i+1] += dp[i-1];
    dp[i+1] %= mod;
  }
  cout << dp[N] << endl;



  return 0;
}


Measured memory_bytes: 1024
using System;
using System.Collections.Generic;
using System.Text;


namespace ConsoleApplication4
{
    class Program
    {
        static void Main(string[] args)
        {
            
        
           double r = double.Parse(Console.ReadLine());
           double area = r * r *Math.PI;
           double rect = 2 * r * Math.PI;



            Console.WriteLine(area+ " " + rect);



        }
    }
}

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

char solve(int m, int f, int r)
{
  if (m == -1 || f == -1)
  {
    return 'F';
  }
  if (m + f >= 80)
  {
    return 'A';
  }
  if (m + f >= 65)
  {
    return 'B';
  }
  if (m + f >= 50)
  {
    return 'C';
  }
  if (m + f >= 30)
  {
    if (r >= 50)
    {
      return 'C';
    }
    return 'D';
  }
  return 'F';
}

int main()
{
  while (1)
  {
    int m, f, r;
    cin >> m >> f >> r;
    if (m == -1 && f == -1 && r == -1)
    {
      break;
    }
    cout << solve(m, f, r) << endl;
  }
}


Measured memory_bytes: 3092
#include <bits/stdc++.h>
#define rep(i, z, n) for(int i = z; i < n; i++)
#define all(v) v.begin(), v.end()
typedef long long ll;
//const int INF = 1<<29;
//const int MODINF = 1000000007;
using namespace std;

int main(){
    int a, b;
    cin >> a >> b;
    vector<int> x(1001);
    x.at(0) = 0;
    rep(i, 1, 1000){
        x.at(i) = x.at(i - 1) + i;
    }
    int y = b - a;
    cout << x.at(y - 1) - a << endl;
    
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,1,n+1)
#define RFOR(i,l,r) for(long long i=(l);i>=(r);--i)
#define RREP(i,n) RFOR(i,n-1,0)
#define RREPS(i,n) RFOR(i,n,1)
#define int long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
const int INF=1e18;
const int MOD=1e9+7;

const int MAX_V=1002;

struct edge{
    int to;double cost;
    edge(int to,double cost):to(to),cost(cost) {}
    bool operator<(const edge& a) const{
        return cost >a.cost;
    }
};
typedef pair<int,int> P;

vector<edge>Graph[MAX_V];
double d[MAX_V];
int v;

void dijkstra(){
    priority_queue<edge> q;
    fill(d,d+v+2,INF);
    d[0]=0;
    q.push({0,0});
    while(!q.empty()){
        int now=q.top().to;
        int dep=q.top().cost;
        q.pop();
      	if(d[now]<dep)continue;
        for(int i=0;i<Graph[now].size();i++){
            edge e =Graph[now][i];
            if(d[e.to]>d[now]+e.cost){
                d[e.to]=d[now]+e.cost;
                q.push({e.to,d[e.to]});
            }
        }
    }
}

signed main(){
    int sx,sy,gx,gy;cin>>sx>>sy>>gx>>gy>>v;
    vector<pair<P,int>>place(v+2);
    place[0]={{sx,sy},0};
    place[1]={{gx,gy},0};
    REP(i,v){
        int x,y,r;cin>>x>>y>>r;
        place[i+2]={{x,y},r};
    }
    REP(i,v+2)REP(j,v+2){
        double dist=sqrt((place[i].first.first-place[j].first.first)*(place[i].first.first-place[j].first.first)+(place[i].first.second-place[j].first.second)*(place[i].first.second-place[j].first.second));
    	Graph[i].eb(j,max(dist-place[i].second-place[j].second,0.0));
    }
    dijkstra();
    cout<<fixed<<setprecision(20.20);
    cout<<d[1]<<endl;
}

Measured memory_bytes: 22640
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define pb push_back
#define fi first
#define se second

#define Mod 998244353
 
ll gcd(ll a,ll b){
    if(a>b) swap(a,b);
    if(b%a==0) return a;
    else return gcd(a,b%a);
}

int main(){
    int i,j;
    int n;

    cin>>n;
    ll a[n];

    for(i=0;i<n;i++){
        cin>>a[i];
    }
    sort(a,a+n);
    ll mi=a[0];

    for(i=2;i<n;i++){
        mi*=gcd(a[i],i);
        mi%=Mod;
    }

    cout<<mi<<endl;
    return 0;
}

Measured memory_bytes: 1024
using System;
using System.Collections.Generic;
namespace E___Strings_of_Impurity
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine(solver());
        }

        static long solver()
        {
            var s = Console.ReadLine();
            var t = Console.ReadLine();

            var alphabets = new List<int>[26];
            for (int i = 0; i < 26; i++) alphabets[i] = new List<int>();
            for (int i = 0; i < s.Length; i++) alphabets[s[i] - 'a'].Add(i + 1);

            long result = 0;
            var currentIndex = 0;
            for (int i = 0; i < t.Length; i++)
            {
                var currentChar = alphabets[t[i] - 'a'];
                if (currentChar.Count == 0) return -1;
                currentIndex = binarySearch(currentChar, currentIndex);
                if (currentIndex == -1)
                {
                    result += s.Length;
                    currentIndex = currentChar[0];
                }
            }
            return result + currentIndex;
        }
        static int binarySearch(List<int> list, int key)
        {
            int left = -1;
            int right = list.Count;

            while (right - left > 1)
            {
                int mid = left + (right - left) / 2;
                if (list[mid] > key)
                {
                    right = mid;
                }
                else
                {
                    left = mid;
                }
            }
            if (right >= list.Count)
            {
                return -1;
            }
            else
            {
                return list[right];
            }
        }
    }
}


Measured memory_bytes: 13244
const line = require('fs').readFileSync('/dev/stdin', 'utf-8').split('\n');

const insert = (map, str) => {
    map[str] = true;
    return map;
};

const find = (map, str) => str in map;

line.slice(1, line.length-1).reduce((acc, x) => {
    const cmd = x.split(' ');
    switch(cmd[0]) {
        case 'insert':
            acc = insert(acc, cmd[1]);
            break;
        case 'find':
            console.log(find(acc, cmd[1]) ? 'yes' : 'no');
            break;
    }

    return acc;
}, {});



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

#define ll signed long long 

bool ok(ll N, ll K) {
  while (N % K == 0) {
    N /= K;
  }
  N %= K;
  return N == 1;
}

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

  ll cnt = 0;
  for (ll i = 2; i * i <= N; ++i) {
  // for (int i = 2; i <= N; ++i) {
    if (ok(N, i)) {
      ++cnt;
      // cout << i << endl;
      if ((N - 1ll) % i == 0 &&
          (N - 1ll) != i * i) {
        ++cnt;
      }
    }
  }
  if (N == 2) {
    ++cnt;
  } else {
    cnt += 2;
  }

  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define mem(a, b) memset(a, (b), sizeof(a))
#define fore(i,a) for(int i=0;i<a;i++)
#define fore1(i,j,a) for(int i=j;i<a;i++)
#define print(ar) for(int i=0;i<ar.size();i++)cout<<ar[i]<<" ";
#define END cout<<'\n'
const double pi=acos(-1.0);
 
typedef pair<int, int> PII;
 
typedef vector<long long> VI;
 
typedef vector<string> VS;
 
typedef vector<PII> VII;
 
typedef vector<VI> VVI;
 
typedef map<int,int> MPII;
 
typedef set<int> SETI;
 
typedef multiset<int> MSETI;
 
typedef long int li;
 
typedef unsigned long int uli;
 
typedef long long int ll;
 
typedef unsigned long long int  ull;
ll fastexp (ll a, ll b, ll n) {
  ll res = 1;
  while (b) {
      if (b & 1) res = res*a%n;
      a = a*a%n;
      b >>= 1;
  }
  return res;
}
void fast(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
int main()
 {  fast();
	int s,w;
	cin >>s>>w;
	if(w>=s)cout<<"unsafe"<<endl;
     else cout<<"safe"<<endl;
 }

Measured memory_bytes: 3652
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
#include <cstdio>
#include <tuple>
using namespace std; using ll = long long; using pll = pair<ll, ll>;
using vl = vector<ll>; using vll = vector<vl>; using vpll = vector<pll>;
//**デバッグ準備**//
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
void debug_out() { cerr << endl; }
template<typename Head, typename... Tail>
void debug_out(Head h, Tail... t) {
	cerr << " " << h;
	if (sizeof...(t) > 0) cerr << " :";
	debug_out(t...);
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> vec) {
	for (size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
	return os;
}
ll ctoi(char c) {
	switch (c) {
	case '0': return 0; case '1': return 1; case '2': return 2;
	case '3': return 3; case '4': return 4; case '5': return 5;
	case '6': return 6; case '7': return 7; case '8': return 8;
	case '9': return 9;  default: return 0;
	}
}
bool pairCompare(const pll firstElof, pll secondElof)
{
	return firstElof.first > secondElof.first;
}
//**Snippetリスト**//
//rep, vin, all, iteLoop//
//gcdlcm, isPrime, eratos, Npow, divisor, modinv, bitSearch, bitList, dfs, bfs//
//dijkstra, WarshallFloyd, BellmanFord, UnionFind, COM, digitDP ,RMQ//
ll i, j, k, l; ll N, M, K, H, W, L, X, Y, Z;
ll MOD = 1000000007; ll INF = 1LL << 60; ll ans = 0; ll z = 0, o = 1;
vl flag, color, D; vll path;
//***********//
ll Npow(ll x, ll n) {
	if (n == 0) return 1;
	if (n % 2 == 0) return Npow(x * x % MOD, n / 2);
	else return x * Npow(x, n - 1) % MOD;
}
//main内でCOMinit(N+1)を忘れずに！
vl fac, finv, inv;
void COMinit(ll N) {
	fac.resize(N);
	finv.resize(N);
	inv.resize(N);
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (ll i = 2; i < N; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}
ll COM(ll n, ll k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
ll modinv(ll a, ll m) {
	ll b = m, u = 1, v = 0;
	while (b) {
		ll t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
int main() {
	cin >> N;
	COMinit(N + 1);
	vl C(N);
	for (i = 0; i < N; i++) cin >> C[i];
	sort(C.begin(), C.end());
	reverse(C.begin(), C.end());
	ll base = Npow(4, N - 1);
	for (i = 1; i <= N; i++) {
		ans = (ans + C[i - 1] * (i + 1)) % MOD;
	}
	cout << (ans * base) % MOD;
}

Measured memory_bytes: 6528
#define _USE_MATH_DEFINES

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <utility>
#include <vector>
#include <numeric>

using namespace std;

void bubbleSort(vector<int> &a)
{
	int cnt = 0;
	bool flg = true;

	for (; flg;)
	{
		flg = false;
		for (int i = a.size() - 1; i > 0; i--)
		{
			if (a.at(i) < a.at(i - 1))
			{
				swap(a.at(i), a.at(i - 1));
				flg = true;
				cnt++;
			}
		}
	}

	for (int i = 0; i < a.size(); i++)
	{
		cout << a.at(i) << (i == a.size() - 1 ? "" : " ");
	}

	cout << endl;
	cout << cnt << endl;
}

int main()
{
	int n;

	vector<int> a;
	for (cin >> n; n--;)
	{
		int x;
		cin >> x;

		a.push_back(x);
	}

	bubbleSort(a);
}



Measured memory_bytes: 3148
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
  string b;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> b;
    if (b == "Y") {
      cout << "Four" << endl;
      break;
    }
    else if (i == n-1) {
      cout << "Three" << endl;
      break;
    }
  }
}


Measured memory_bytes: 256
# include <bits/stdc++.h>
# define rep(i, n) for(ll i = 0; i < (n); ++i)
# define reps(i, n) for(ll i=1, i##_len=(n); i<=i##_len; ++i)
# define rrep(i, n) for(ll i=((int)(n)-1); i>=0; --i)
# define rreps(i, n) for(ll i=((int)(n)); i>0; --i)
# define ll long long
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define optimize_cin() cin.tie(0); ios::sync_with_stdio(false)
# define P pair<int, int>
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll lmax(ll a, ll b){if(a>= b) return a;return b;}
ll lmin(ll a, ll b){if(a>= b) return b;return a;}
static const ll INF = 1e18;

int main() {
  int n, m, x; cin >> n >> m >> x;
  vector<int> c(n);
  vector<vector<int>> a(n, vector<int> (m));
  rep(i, n){
    cin >> c[i];
    rep(j, m) cin >> a[i][j];
  }

  ll price = INF;

  rep(i, 1<<n){
    vector<int> understand(m, 0);
    ll sum = 0;
    rep(j, n){
      if((i>>j)&1){
        sum += c[j];
        rep(k, m){
          understand[k] += a[j][k];
        }
      }
    }

    bool flag = true;
    rep(i, m){
      if(understand[i] < x) flag = false;
    }
    if(flag) chmin(price, sum);
  }

  if(price == INF){
    cout << -1 << endl;
    return 0;
  }

  cout << price << endl;
  return 0;
}


Measured memory_bytes: 3616
def main():
    N = int(input())
    A = list(map(int, input().split()))

    if 0 in A:
        print(0)
        return
    
    prod = 1
    for a in A:
        prod *= a
        if prod > 1000000000000000000:
            print(-1)
            return
    
    print(prod)
    return

main()

Measured memory_bytes: 21768
import Foundation

let n = Int(readLine()!)!

var dic: [String] = []
for i in 0 ..< n {
    dic.append(readLine()!)
}

var w: [String: Int] = [:]

for i in 0 ..< n {
    if w[dic[i]] == nil {
        w[dic[i]] = 1
    } else {
        w[dic[i]]! += 1
    }
}

let sorted = w.sorted(by: <).sorted(){ $0.1 > $1.1 }
let max = sorted.first!.value
sorted.forEach {
    if $0.1 < max {
        return
    }
    print($0.0)
}

Measured memory_bytes: 40544
import java.util.*;

class Main{
  public static void main(String[] args){
    Scanner sc=new Scanner(System.in);
    int[] dx={1,0,-1,0};
    int[] dy={0,1,0,-1};
    int n=sc.nextInt();
    int m=sc.nextInt();
    String[] a=new String[n];
    for(int i=0;i<n;i++){
      a[i]=sc.next();
    }
    for(int i=0;i<n;i++){
      for(int j=0;j<m;j++){
        if(a[i].charAt(j)=='#'){
          boolean f=false;
          for(int k=0;k<4;k++){
            if(i+dy[k]<0||n<=i+dy[k]||j+dx[k]<0||m<=j+dx[k]){
              continue;
            }
            if(a[i+dy[k]].charAt(j+dx[k])=='#'){
              f=true;
              break;
            }
          }
          if(!f){
            System.out.println("No");
            return;
          }
        }
      }
    }
    System.out.println("Yes");
  }
}

Measured memory_bytes: 23380
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int L, R, d;

int main(void) {

	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: 3632
#include <bits/stdc++.h>
#define mk make_pair
#define fs first
#define sc second
using namespace std;
typedef long long ll;
typedef long double ld;
char s[300010];
ll mod=1e9+7;
ll mem[300010][2][2][2][2][2], n;
ll dp(int x, int l, int b, bool pre, bool l2, bool z){
//  cout<<x<<" "<<l<<" "<<b<<" "<<pre<<" "<<l2<<" "<<z<<endl;
  if(x==n)
    return (b&&l2)||(l&&pre)||(z)||(l2&&pre);
  if(mem[x][l][b][pre][l2][z]!=-1)
    return mem[x][l][b][pre][l2][z];
  if(s[x]!='?'){
    if(x==0)
      mem[x][l][b][pre][l2][z]=dp(x+1, 0, 0, s[x]-'0', s[x]-'0', 0);
    else
      mem[x][l][b][pre][l2][z]=dp(x+1, l||((s[x]=='1')&&pre&&(x%2==0)), b||(s[x]=='1'&&pre&&(x%2)), s[x]-'0', l2, z||(s[x]=='1'&&pre&&(x%2)&&l));
    mem[x][l][b][pre][l2][z]%=mod;
    return mem[x][l][b][pre][l2][z];
  }
  ll ans=0;
  if(x==0)
    ans=dp(x+1, 0, 0, 1, 1, 0)+dp(x+1, 0, 0, 0, 0, 0);
  else
    ans=dp(x+1, l||(pre&&(x%2==0)), b||(pre&&(x%2)), 1, l2, z||((pre&&(x%2))&&l))+dp(x+1, l, b, 0, l2, z);
  ans%=mod;
  mem[x][l][b][pre][l2][z]=ans;
  return ans;
}

int main(){
  scanf("%s",s);
  n=strlen(s);
  memset(mem, -1, sizeof mem);
  ll ans=dp(0,0,0,0,0,0);
  cout<<ans<<endl;
  return 0;
}



Measured memory_bytes: 108288
#!/usr/bin/perl

sub main() {
  my($N,$T)=split(/ /,<>);
  chomp($T);
  my$tmp=<>;
  chomp($tmp);
  my $t = [split(/ /,$tmp)];
  my $ans = prob($N,$T,$t);
  print $ans;
}

sub prob() {
  my($N,$T,$t) = @_;
  my $ans = $T;
  my $prev = 0;
  for my $i(1..$N-1) {
    if (($t->[$i] - $prev) < $T){
      $ans += $t->[$i] - $prev;
    } else {
      $ans += $T;
    }
    $prev = $t->[$i];
  }
  return $ans;
}

&main();

Measured memory_bytes: 36812
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<string>
#include<numeric>
#include<set>
#include<math.h>
using namespace std;

int N, M = 0;
map<int, vector<int>> ab;
vector<int> c, d;

void dfs(int node){
    if(d[node] != 0) return;
    else{
        d[node] = c.back();
        c.pop_back();
    }

    for(int n : ab[node]) dfs(n);

    return;
}

int main(){
    cin >> N;
    int tmpa, tmpb, tmpc;

    for(int i = 0; i < N-1; i++){
        cin >> tmpa >> tmpb;
        ab[tmpa-1].push_back(tmpb-1);
        ab[tmpb-1].push_back(tmpa-1);
    }
    for(int i = 0; i < N; i++){
        cin >> tmpc;
        c.push_back(tmpc);
    }

    // c をソート
    stable_sort(c.begin(), c.end());

    for(int i = 0; i < N - 1; i++) M += c[i]; // 最大値 c[N-1] 以外の総和

    cout << M << endl;

    for(int i = 0; i < N; i++) d.push_back(0);

    dfs(0);

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

    cout << endl;

    return 0;
}

Measured memory_bytes: 1920
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define repc(i, b, e) for(auto i = (b); i != (e); i++)

int main() {
    ll N, K;
    cin >> N >> K;
    double ans = 0;
    for(ll i = 1; i <= N; i++) {
        if(K <= i) {
            ans += 1;
        } else {
            double n = (ll)ceil(log2(K * 1.0 / i));
            ans += pow(0.5, n);
        }
    }
    cout << setprecision(15) << ans / N << endl;
    return 0;
}

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

int n,m;
int g[110][110];
int deg[110], use[110];
vector<int> V;

int rec(int d, int k){
  if(k==0){
    int res = 0;
    rep(i,V.size()){
      if(!use[i])continue;
      int minv = 1e9;
      rep(j,V.size()){
	if(i==j || !use[j])continue;
	minv = min(minv, g[V[i]][V[j]]);
      }
      res += minv;
    }
    return res;
  }

  if(d==(int)V.size())return 0;

  int res = rec(d+1,k);

  if(k>0){
    bool f = true;
    for(int i=0;i<d;i++){
      if(use[i] && !g[V[i]][V[d]]){
	f = false; break;
      }
    }

    if(f){
      use[d] = true;
      res = max(res, rec(d+1,k-1));
      use[d] = false;
    }
  }
  return res;
}

int max_clique(int k){
  V.clear();
  rep(i,n){
    if(deg[i]>=k-1)V.push_back(i);
  }

  memset(use,0,sizeof(use));
  return rec(0,k);
}

int main(){
  cin >> n >> m;
  rep(i,m){
    int a,b,c;
    cin >> a >> b >> c; a--; b--;
    g[a][b] = g[b][a] = c;
    deg[a]++; deg[b]++;
  }

  int res = 0;
  for(int k=2;k*(k-1)/2<=m;k++){
    res = max(res, max_clique(k));
  }
  cout << res << endl;
}

Measured memory_bytes: 1268
#include <iostream>
#include <vector>
#include <cstdlib>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <string>
#include <cmath>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
using vi = vector<int>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける
using vl = vector<ll>;  // long longの1次元の型に vl という別名をつける
using vvl = vector<vl>; // long longの2次元の型に vvl という別名をつける
int MOD = 1000000007; //10^9 + 7

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  lINF = 1LL << 60;
const int iINF = 1 << 29;

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

  vector<string> a(h);
  rep(i,h) cin >> a[i];

  rep(i,h+2){
    if(i==0 || i==h+1){
      rep(j,w+2)cout << '#';
      cout << endl;
    }
    else{
      rep(j,3){
        if(j==0) cout << '#';
        else if(j==1) cout << a[i-1];
        else cout << '#' << endl;
      }
    }
  }
  return 0;
} 

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

int main()
{
	int N, M;
	cin >> N;
	cin >> M;
	vector<int>vec_a, vec_b, road;

	for (int i = 0; i < N; i++)
	{
		road.push_back(0);
	}
	
	for (int i = 0; i < M; i++)
	{
		int num;
		cin >> num;
		vec_a.push_back(num);
		cin >> num;
		vec_b.push_back(num);
	}

	for (int i = 0; i < M; i++)
	{	
		road[vec_a[i] - 1]++;
		road[vec_b[i] - 1]++;
	}

	for (int i = 0; i < N; i++)
	{
		cout << road[i] << endl;
	}
}

Measured memory_bytes: 256
# coding: utf-8
import re
import math
import itertools
from copy import deepcopy
import fractions
import random
from functools import lru_cache
from heapq import heappop,heappush
import time
import sys
readline = sys.stdin.readline
sys.setrecursionlimit(2000)
#import numpy as np
alphabet="abcdefghijklmnopqrstuvwxyz"
mod=int(10**9+7)
inf=int(10**20)
def yn(b):
    if b:
        print("yes")
    else:
        print("no")
def Yn(b):
    if b:
        print("Yes")
    else:
        print("No")
def YN(b):
    if b:
        print("YES")
    else:
        print("NO")
class union_find():
    def __init__(self,n):
        self.n=n
        self.P=[a for a in range(N)]
        self.rank=[0]*n
 
    def find(self,x):
        if(x!=self.P[x]):self.P[x]=self.find(self.P[x])
        return self.P[x]
 
    def same(self,x,y):
        return self.find(x)==self.find(y)
 
    def link(self,x,y):
        if self.rank[x]<self.rank[y]:
            self.P[x]=y
        elif self.rank[y]<self.rank[x]:
            self.P[y]=x
        else:
            self.P[x]=y
            self.rank[y]+=1
 
    def unite(self,x,y):
        self.link(self.find(x),self.find(y))
 
    def size(self):
        S=set()
        for a in range(self.n):
            S.add(self.find(a))
        return len(S)
def bin_(num,size):
    A=[0]*size
    for a in range(size):
        if (num>>(size-a-1))&1==1:
            A[a]=1
        else:
            A[a]=0
    return A
def fac_list(n,mod_=0):
    A=[1]*(n+1)
    for a in range(2,len(A)):
        A[a]=A[a-1]*a
        if(mod>0):A[a]%=mod_
    return A
def comb(n,r,mod,fac):
    if(n-r<0):return 0
    return (fac[n]*pow(fac[n-r],mod-2,mod)*pow(fac[r],mod-2,mod))%mod
def next_comb(num,size):
    x=num&(-num)
    y=num+x
    z=num&(~y)
    z//=x
    z=z>>1
    num=(y|z)
    if(num>=(1<<size)):return False
    else:
        return num
def get_primes(n,type="int"):
    A=[True]*(n+1)
    A[0]=False
    A[1]=False
    for a in range(2,n+1):
        if A[a]:
            for b in range(a*2,n+1,a):
                A[b]=False
    if(type=="bool"):return A
    B=[]
    for a in range(n+1):
        if(A[a]):B.append(a)
    return B
def is_prime(num):
    if(num<=2):return False
    i=2
    while i*i<=num:
       if(num%i==0):return False
       i+=1
    return True
def join(A,c=" "):
    n=len(A)
    A=list(map(str,A))
    s=""
    for a in range(n):
        s+=A[a]
        if(a<n-1):s+=c
    return s
#main

@lru_cache(maxsize=None)#メモ化デコレータ
def f(num,k):
    if(num==0 and k==0):return 1
    elif(num<=0 or k<0):return 0
    else:
        r=num-(num//10)*10
        m=num//10
        return f(m,k-1)*r+f(m-1,k-1)*(9-r)+f(m,k)
s=int(input())
k=int(input())
print(f(s,k))


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

#define dump(...) do{print_vars(cout<<"# "<<#__VA_ARGS__<<'=',__VA_ARGS__);cout<<endl;}while(0)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define all(c) begin(c),end(c)
#define mp make_pair
#define mt make_tuple

using uint=unsigned;
using ll=long long;
using ull=unsigned long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using vd=vector<double>;
using vvd=vector<vd>;
using vs=vector<string>;

template<typename T,typename U>bool chmin(T& a,const U& b){return a>b?(a=b,1):0;}
template<typename T,typename U>bool chmax(T& a,const U& b){return a<b?(a=b,1):0;}

void print_vars(ostream&){}
template<typename Car,typename... Cdr>
void print_vars(ostream& os,const Car& car,const Cdr&... cdr){
	print_vars(os<<car<<(sizeof...(cdr)?",":""),cdr...);
}

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

template<int I,typename Tuple>
void print_tuple(ostream&,const Tuple&){}
template<int I,typename Car,typename... Cdr,typename Tuple>
void print_tuple(ostream& os,const Tuple& t){
	os<<get<I>(t)<<(sizeof...(Cdr)?",":"");
	print_tuple<I+1,Cdr...>(os,t);
}
template<typename... Args>
ostream& operator<<(ostream& os,const tuple<Args...>& t){
	print_tuple<0,Args...>(os<<'(',t);
	return os<<')';
}

template<typename Ch,typename Tr,typename C>
basic_ostream<Ch,Tr>& operator<<(basic_ostream<Ch,Tr>& os,const C& c){
	os<<'[';
	for(auto i=begin(c);i!=end(c);++i)
		os<<(i==begin(c)?"":" ")<<*i;
	return os<<']';
}

constexpr int INF=1e9;
constexpr int MOD=1e9+7;
constexpr double EPS=1e-9;

int main()
{
	#ifndef _GLIBCXX_DEBUG
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	constexpr char endl='\n';
	#endif

	for(int n;cin>>n&&n;){
		string s; cin>>s;
		int q; cin>>q;

		rep(_,q){
			int k; cin>>k;
			ll d=0,m=0,c=0,dm=0,mc=0,dmc=0;
			for(int l=0,r=0;;){
				for(;r-l<k;r++){
					if(s[r]=='D'){
						d++;
					}
					if(s[r]=='M'){
						m++;
						dm+=d;
					}
					if(s[r]=='C'){
						c++;
						mc+=m;
						dmc+=dm;
					}
				}

				if(r==n) break;

				if(s[l]=='D'){
					d--;
					dm-=m;
				}
				if(s[l]=='M'){
					m--;
					mc-=c;
				}
				if(s[l]=='C'){
					c--;
				}
				l++;
			}
			cout<<dmc<<endl;
		}
	}
}


Measured memory_bytes: 1948
N, P = map(int, input().split())
S = input()
ans = 0

d = [0]*(N+1)
# d[N-1] = 1

if 10%P == 0:
    ans = 0
    for i in range(N):
        if int(S[i]) % P == 0:
            ans += i + 1
    print(ans)
else:
    ## 10の何乗か
    ten = 1
    ## 一桁目から、Pの余りを累積和
    for i in range(N-1,-1,-1):
        a = int(S[i]) * ten % P
        d[i] = (d[i+1]+a)%P
        ten *= 10
        ten %= P

    ## dの値を累積カウントする
    counter = [0]*P
#     print(d)
    for j in range(N, -1, -1):
        ans += counter[d[j]]
#         print(ans)
        counter[d[j]] += 1

    print(ans)


Measured memory_bytes: 11088
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, a, b) for(int i = a; i < b; i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fi first
#define se second
#define debug(x) cerr <<__LINE__<< ": " <<#x<< " = " << x << endl
#define debug_vec(v) cerr<<__LINE__<<": "<<#v<<" = ";rep(i,v.size())cerr<<" "<<v[i];cerr<<endl
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 int INF = (1<<30) - 1;
const ll LINF = (1LL<<60) - 1;

int n;

void solve() {
    cin >> n;
    vector<int> X, P(8), Q(8);
    int a, b;
    REP(i, 1, n + 1) X.emplace_back(i);
    rep(i, n) cin >> P[i];
    rep(i, n) cin >> Q[i];
    auto check = [](vector<int> a, vector<int> b) {
        rep(i, n) if (a[i] != b[i]) return 0;
        return 1;
    };
    int cnt = 0;
    do {
        if (check(X, P)) a = cnt;
        if (check(X, Q)) b = cnt;
        cnt++;
    } while(next_permutation(all(X)));
    cout << abs(a - b) << endl;
}

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


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
typedef long long int ll;

int main()
{

	ios_base:: sync_with_stdio(false); cin.tie(0);
	ll x;
	cin>>x;
	if(x<=6) {
		cout<<1<<endl;
		return 0;
	}
	ll steps=2*(x/11);
	if((x%11>0)&&(x%11<=6)) {
		steps++;
	}
	else if((x%11)>6) {
		steps+=2;
	}
	cout<<steps<<endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i, n) for (int i = 0; i < (n); i++)
using P=pair<int,int>;
int main() {
    string s;cin>>s;
    int resu=0;
    for(int i=0;i<s.size()-1;i++){
        if(s.at(i)=='A' &&s.at(i+1)=='C') resu=1;
    }
    if(resu==1) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline
ra = range
enu = enumerate


def read_ints():
    return list(map(int, read().split()))


def read_a_int():
    return int(read())


def read_tuple(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(tuple(map(int, read().split())))
    return ret


def read_col(H):
    '''
    H is number of rows
    A列、B列が与えられるようなとき
    ex1)A,B=read_col(H)    ex2) A,=read_col(H) #一列の場合
    '''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return tuple(map(list, zip(*ret)))


def read_matrix(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return ret
    # return [list(map(int, read().split())) for _ in range(H)] # 内包表記はpypyでは遅いため


MOD = 10**9 + 7
INF = 2**31  # 2147483648 > 10**9
# default import
from collections import defaultdict, Counter, deque
from operator import itemgetter
from itertools import product, permutations, combinations
from bisect import bisect_left, bisect_right  # , insort_left, insort_right
from math import gcd

a = 100
X = read_a_int()
ans = 0
while a < X:
    a = int(a * 1.01)
    ans += 1
print(ans)


Measured memory_bytes: 67404
using System;
using System.Drawing;
using System.Linq;
using System.Text.RegularExpressions;
using System.Text;


namespace aizu
{
	public class EntryPoint
	{
		public static int[] Split(string line)
		{
			return Regex.Split(line, " ").Select(x => int.Parse(x)).ToArray();
		}
		public static void Main()
		{
			var line = Console.ReadLine();
			var v = Split(line);
			
			var a = v[0];
			var b = v[1];
			var c = v[2];
			var d = 0;
			
			for (int i = a; i <= b; i++)
			{
				if (0 == (c % i))
				{
					d++;
				}
			}
			
			Console.WriteLine(d);
		}
	}


}

Measured memory_bytes: 7136
#include <stdio.h>

int main(void)
{
	int i,t,n;
	for(i=0;i<4;i++){
		scanf("%d%d",&t,&n);
		if(t==1){
			printf("%d\n",n*6000);
		}else if(t==2){
			printf("%d\n",n*4000);
		}else if(t==3){
			printf("%d\n",n*3000);
		}else if(t==4){
			printf("%d\n",n*2000);
		}
	}
	return 0;
}

Measured memory_bytes: 600
#include<iostream>
#include<vector>

using namespace std;

int main(){
    int N,Q;
    int tmp;
    long K;

    cin >> N >> K >> Q;

    vector<long> vec(N,K-Q);

    for(int i = 0; i < Q; i++){
        cin >> tmp;
        vec.at(tmp-1) += 1;
      
    }

   

     for(int i = 0; i < N; i++){
        if(vec.at(i) > 0){
            cout << "Yes" << endl;
        }else{
            cout << "No" << endl;
        }
    }

    return 0;
}

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

#define ll long long
#define pb push_back
#define INF 1e9+7
#define cases int t;cin>>t;while(t--)
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define per(i,a,b) for(ll i=a;i>=b;i--)
#define ff first
#define ss second

#define test4(x,y,z,a) cout<<"x is "<<x<<"		y is "<<y<<"		z is "<<z<<"		a is "<<a<<endl;
#define test3(x,y,z) cout<<"x is "<<x<<"		y is "<<y<<"		z is "<<z<<endl;
#define test2(x,y) cout<<"x is "<<x<<"		y is "<<y<<endl;
#define test1(x) cout<<"x is "<<x<<endl;

int main(){
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	
	ll n,k;
	cin>>n>>k;
	ll p[n];
	rep(i,0,n){
		cin>>p[i];
	}
	sort(p,p+n);
	ll sum=0;
	rep(i,0,k){
		sum+=p[i];
	}
	cout<<sum;
	
	
	
	return 0;
}

Measured memory_bytes: 3616
/*   Then, everything changed when the Fire Nation attacked. */

#include<bits/stdc++.h>
#pragma GCC optimize("O3")
#define mod 1000000007
#define fi first
#define se second
using namespace std;
int a,b,c;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    // shuffle(permutation.begin(), permutation.end(), rng);
    cin>>a>>b;
    for(int i=1;i<=3;++i)
    {
        if((a*b*i)%2==1)
        {
            cout<<"Yes";
            return 0;
        }
    }
    cout<<"No";
    return 0;
}


Measured memory_bytes: 896
#include<stdio.h>

int n,A[50];

int solve(int i, int m){
  if(m==0) return 1;
  if(i>=n) return 0;
  int res=solve(i+1,m)||solve(i+1,m-A[i]);
  return res;
}

int main(){
  int q,M,i;

  scanf("%d",&n);
  for(i=0;i<n;i++) scanf("%d",&A[i]);
  scanf("%d",&q);
  for(i=0;i<q;i++){
    scanf("%d",&M);
    if(solve(0,M)) printf("yes\n");
    else printf("no\n");
  }
  return 0;
}



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

int main() {
	int N, L_sum = 0;
	cin >> N;
	vector<int> L(N);
	for (int i = 0; i < N; i++) {
		cin >> L[i];
		L_sum += L[i];
	}
	int max_L = *max_element(L.begin(), L.end());
	if (L_sum - max_L > max_L) cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 256