akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

typedef long long ll;
typedef uint64_t ull;
typedef pair<int, int> P;
constexpr double PI = 3.1415926535897932;   // acos(-1)
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)

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

    int n, p;
    string s;
    cin >> n >> p >> s;
    reverse(s.begin(), s.end());
    if(p == 2 || p == 5){
        ll ans = 0;
        for(int i = 0; i < n; ++i){
            int num = s[i] - '0';
            if(num % p == 0)    ans += n - i;
        }
        cout << ans << endl;
        return 0;
    }
    vector<ll> sum(n + 1);
    sum[0] = 0;
    int mul = 1;
    for(int i = 0; i < n; ++i){
        int num = s[i] - '0';
        sum[i + 1] = (sum[i] + num * mul) % p;
        mul *= 10;
        mul %= p;
    }
    map<int, int> mp;
    for(int i = 0; i <= n; ++i) ++mp[sum[i]];
    ll ans = 0;
    for(auto it : mp)   ans += (ll)it.second * (it.second - 1) / 2;
    cout << ans << endl;
}

Measured memory_bytes: 5452
#include <iostream>
#include <algorithm>
#include <cmath>
#include <functional>
#include <string>
#include <vector>
#include <set>
using namespace std;

#define int long long
#define rep(n, i) for (int i = 0; i < n; i++)
#define rep2(m, n, i) for (int i = m; i < n; i++)
#define rep_r(n, i) for (int i = n - 1; i >= 0; i--)

const int INF = 1LL << 60;
const int MOD = 1e9 + 7;

signed main() {
    string s;
    cin >> s;
    rep(s.size(), i) {
        if (i % 2 && s[i] == 'R') {
            cout << "No" << endl;
            return 0;
        }
        if (i % 2 == 0 && s[i] == 'L') {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 256
from itertools import product

def main():
    n = [i for i in input()]
    for i in product(('+', '-'), repeat=3):
        formula = n[0]
        for op, num in zip(i, n[1:]):
            formula += op
            formula += num
        if eval(formula) == 7:
            print(formula+'=7')
            exit()

if __name__ == '__main__':
    main()



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

typedef long long LL;

#define FOR(i, a, b) for (int i = (a), i##_END_ = (b); i <= i##_END_; i++)
#define DNF(i, a, b) for (int i = (a), i##_END_ = (b); i >= i##_END_; i--)

template <typename Tp> void in(Tp &x) {
	char ch = getchar(), f = 1; x = 0;
	while (ch != '-' && (ch < '0' || ch > '9')) ch = getchar();
	if (ch == '-') ch = getchar(), f = -1;
	while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
	x *= f;
}

template <typename Tp> void out(Tp x) {
	if (x > 9) out(x / 10);
	putchar(x % 10 + '0');
	return;
}

template <typename Tp> Tp Max(const Tp &x, const Tp &y) {return x > y ? x : y;}
template <typename Tp> Tp Min(const Tp &x, const Tp &y) {return x < y ? x : y;}
template <typename Tp> bool chkmax(Tp &x, Tp y) {return x >= y ? 0 : (x=y, 1);}
template <typename Tp> bool chkmin(Tp &x, Tp y) {return x <= y ? 0 : (x=y, 1);}

const int MAXN = 100010;

int n, m, A[MAXN], B[MAXN], to[MAXN];
int head[MAXN], data[MAXN << 1], nxt[MAXN << 1], cnt;

int fa[MAXN], rnk[MAXN];

LL need[MAXN];
LL sum[MAXN];

char cmp(const int &x, const int &y) {return A[x] - B[x] < A[y] - B[y];}

void add(int x, int y)
{
	nxt[cnt] = head[x]; data[cnt] = y; head[x] = cnt++;
	nxt[cnt] = head[y]; data[cnt] = x; head[y] = cnt++;
}

int find(int x) {while (x != fa[x]) x = fa[x] = fa[fa[x]]; return x;}

int main()
{
	in(n); in(m);
	FOR(i, 1, n) in(A[i]), in(B[i]);
	FOR(i, 1, n) to[i] = i;

	std::sort(to + 1, to + n + 1, cmp);

	memset(head, -1, sizeof head);
	FOR(i, 1, n) fa[i] = i;
	FOR(i, 1, m) {int x, y; in(x); in(y); add(x, y);}

	FOR(i, 1, n) rnk[to[i]] = i;
	FOR(i, 1, n) sum[i] = 0;

	LL all = 0;

	FOR(i, 1, n) all += B[i];

	memset(need, 0x3f, sizeof need);
	
	FOR(i, 1, n) {
		int now = to[i];
		
		for (int j = head[now]; j != -1; j = nxt[j]) {
			int fx;
			if ((fx = find(data[j])) != find(now) && rnk[data[j]] < i) {
				fa[fx] = find(now); sum[find(now)] += sum[fx];
				chkmin(need[find(now)], Max(need[fx], Max(0ll, A[now] - B[now] - sum[fx])));
			}
		}

		chkmin(need[find(now)], Max(0ll, A[now] - B[now] + 0ll));
		sum[find(now)] += B[now];
	}

	printf("%lld\n", need[find(1)] + all);
	
	return 0;
}


Measured memory_bytes: 5760
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;

namespace AtTest.ABC_166
{
    class B
    {
        static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(OpenStandardOutput()) { AutoFlush = false };
            SetOut(sw);

            Method(args);

            Out.Flush();
        }

        static void Method(string[] args)
        {
            int[] nk = ReadInts();
            int n = nk[0];
            int k = nk[1];
            int[] cnts = new int[n];
            for(int i = 0; i < k; i++)
            {
                int d = ReadInt();
                int[] array = ReadInts();
                for(int j = 0; j < d; j++)
                {
                    cnts[array[j] - 1]++;
                }
            }

            int res = 0;
            for(int i = 0; i < n; i++)
            {
                if (cnts[i] == 0)
                {
                    res++;
                }
            }
            WriteLine(res);
        }

        private static string Read() { return ReadLine(); }
        private static char[] ReadChars() { return Array.ConvertAll(Read().Split(), a => a[0]); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


Measured memory_bytes: 27680
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using mti = vector<vector<int>>;
using vl = vector<ll>;
using mtl = vector<vector<ll>>;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (int i = j; i < (int)(n); i++)
#define _GLIBCXX_DEBUG
#define n_p(v) next_permutation(v.begin(),v.end())
#define print(a) cout<<(a)<<endl;
#define to_ll(b) stoll(b)
#define MOD 1000000007

int main(){
	ll N,K; cin>>N>>K;
	ll ans=N;
	ll m=N/K;
	while(1){
		ll x=N;
		x-=K*m;
		if(x<0){
			x*=-1;
		}
		if(ans<x){
			break;
		}
		else{
			ans=x;
			m++;
		}
	}
	cout<<ans;
		
	
	
}

Measured memory_bytes: 3564
#include<iostream>
#include<cstdio>
using namespace std;
int main() {
	int n, b, sum2;
	float y, r, t, joe;
	float sum = 0, math, s, d;
	while (1) {
		cin>>n;
		if (n == 0)return 0;
		cin >> y;
		for (int i = 0; i < n; i++) {
			cin >> b >> r >> t;
			if (t == 1) {
				math = 10000 * (1 + y*(r / 100));
				s = math;
			}
			else if (t == 2) {
				math = 1 + (r / 100);
				joe = math;
				for (int i = 0; i < y - 1; i++) {
					joe = joe*math;
				}
				math = 10000 * joe;
			}
			if (i == 0) {
				sum = math;
				sum2 = b;
				continue;
			}

			if (sum < math) {
				sum = math;
				sum2 = b;
			}

		}
		cout << sum2 << endl;
		sum = sum2 = 0;
	}
}

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

int main(){
    int n;
    string s;
    cin >> n >> s;
    int t = n % 26;
    for(int i= 0; i < s.size(); i++){
        if('Z' < (char)(s.at(i) + t)){
            cout << (char)('A' + s.at(i) + t - 'Z' - 1);
        }
        else{
            cout << (char)(s.at(i) + t);
        }
    }
    cout << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

namespace CSharpSample01
{
    
    class Program
    {
        

        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            int N = int.Parse(input[0]);
            int K = int.Parse(input[1]);

            Console.WriteLine(N - K + 1);
            
        }
    }
}

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

int main(){
	string S,T;
	int q;
	cin >> S >> T >> q;
	vector<bool> ans(q);
	
	vector<int> ss;
	vector<int> tt;
	ss.push_back(0);
	tt.push_back(0);
	for(int i=0;i<S.size();i++){
		int add;
		if(S[i]=='A')add=1;
		else add=2;
		ss.push_back(ss[i]+add);
	}
	for(int i=0;i<T.size();i++){
		int add;
		if(T[i]=='A')add=1;
		else add=2;
		tt.push_back(tt[i]+add);
	}
	
	for(int i=0;i<q;i++){
		int a,b,c,d;
		cin >> a >> b >> c >> d;
		if(((ss[b]-ss[a-1])%3)==((tt[d]-tt[c-1])%3))ans[i]=true;
		else ans[i]=false;
	}
	for(int i=0;i<q;i++){
		if(ans[i])cout << "YES" << endl;
		else cout << "NO" << endl;
	}
	return 0;
}

Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
const int dx[]={1,0,0,-1,1,-1,-1,1};
const int dy[]={0,1,-1,0,1,1,-1,-1};
const int INF = 1e8;
const double EPS = 1e-8;
#define PB push_back
#define mk make_pair
#define fr first
#define sc second
#define reps(i,j,k) for(int i = (j); i < (k); ++i)
#define rep(i,j) reps(i,0,j)
#define MOD 1000000007
#define lengthof(x) (sizeof(x) / sizeof(*(x)))
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> Pii;
typedef pair<int,vi > P;
typedef unsigned long long ll;
int target[128];
int score[128];
int main(){
	int N;
	int M;
	cin >> N >> M;
	rep(i,M){
		cin >> target[i];
	}
	rep(i,M){
		int miss = 0;
		rep(j,N){
			int tmp;
			cin >> tmp;
			if(tmp == target[i]){
				score[j]++;
			}
			else miss++;
		}
		score[target[i]-1]+=miss;
	}
	rep(i,N){
		cout << score[i] << "\n";
	}
	return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <cstring>
#include <string>    
#include <vector>
#include <queue>
#include <map>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
ll m, k;
string ans;

ll pow(ll n, ll p){
	ll r = 1;
	for(ll i = 1; i <= n; i++){r *= p;}
	return r;
}

int main(){
	cin >> m >> k;
	if(m == 0 && k == 0){cout << "0 0" << endl; return 0;}
	if(m == 1 && k == 0){cout << "0 0 1 1" << endl; return 0;}
	if(m == 1 && k == 1){cout << -1 << endl; return 0;}
	if(k >= pow(2, m)){cout << -1 << endl; return 0;}
	
	cout << k;
	for(ll i = 0; i < pow(2, m); i++){
		if(i != k){cout << " " << i;}
	}
	cout << " " << k;
	for(ll i = pow(2, m)-1; i >= 0; i--){
		if(i != k){cout << " " << i;}
	}
	return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // std::ifstream in("input.txt");
    // std::cin.rdbuf(in.rdbuf());
    ll n;
    cin >> n;
    map<ll, ll> m;
    rep(i, n) {
        ll a;
        cin >> a;
        m[a] = i;
    }
    set<ll> s;
    s.insert(-1);
    s.insert(n);
    ll ans = 0;
    reps(i, 1, n + 1) {
        auto it = s.lower_bound(m[i]);
        ll r = *it - m[i];
        it--;
        ll l = m[i] - *it;
        ans += l * r * i;
        s.insert(m[i]);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 22144
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = ll(1e9) + 1;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, n) for(int i = 1; i <= (int)(n); i++)
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; }

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

  int ap[A];
  int bp[B];
  for(int i = 0; i < A; ++i) cin >> ap[i];
  for(int i = 0; i < B; ++i) cin >> bp[i];

  int price = *min_element(ap, ap + A) + *min_element(bp, bp + B);

  int xp[M];
  int yp[M];
  int cp[M];
  for(int i = 0; i < M; ++i) {
    int x, y, c;
    cin >> x >> y >> c;
    int new_price = ap[x - 1] + bp[y - 1] - c;
    chmin(price, new_price);
  }

  cout << price << endl;

  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
    int k, a, b;
    cin >> k >> a >> b;
    for (int i = a; i <= b; i++) {
        if (i % k == 0) {
            cout << "OK" << endl;
            return 0;
        }
    }
    cout << "NG" << endl;
}

Measured memory_bytes: 3636
import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline

h, w, k= map(int, input().split())

if k%h==0 or k%w==0:
    print('Yes')
    exit()

for i in range(1,w):
    if w-i*2 != 0:
        if (k-i*h) % (w-i*2) == 0 and 0<(k-i*h) // (w-i*2)<=h:
            print('Yes')
            exit()

for i in range(1,h):
    if h-i*2 != 0:
        if (k-i*w) % (h-i*2) == 0 and 0<(k-i*w) // (h-i*2)<=w:
            print('Yes')
            exit()

print('No')


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	int d=n%10;
	if(d==2 || d==4 || d==5 || d==7 || d==9)
	cout<<"hon\n";
	else if(d==0 ||d==1 || d==6 || d==8)
	cout<<"pon\n";
	else
	cout<<"bon\n";
	return 0;
}


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

int main() {
  int W, H, n;
  cin >> W >> H >> n;
  int w=0, h=0;
  rep(i,n) {
    int x, y, A;
    cin >> x >> y >> A;
    if(A==1) w=max(w,x);
    else if(A==2) W=min(W,x);
    else if(A==3) h=max(h,y);
    else if(A==4) H=min(H,y);
  }
  int ans = (W-w)*(H-h);
  if(W-w<0||H-h<0) ans = 0;
  
  cout << ans << endl;
}


Measured memory_bytes: 256
//	-*- mode: C++ -*-
//	Dice I
//
//		Write a program to simulate rolling a dice, which can be constructed by the following net.
//
//
//
//
//
//
//		As shown in the figures, each face is identified by a different label from 1 to 6.
//
//		Write a program which reads integers assigned to each face identified by the label and a sequence of commands to roll the dice, and prints the integer on the top face. At the initial state, the dice is located as shown in the above figures.
//
//	Input
//		In the first line, six integers assigned to faces are given in ascending order of their corresponding labels.
//
//		In the second line, a string which represents a sequence of commands, is given. The command is one of 'E', 'N', 'S' and 'W' representing four directions shown in the above figures.
//
//	Output
//		Print the integer which appears on the top face after the simulation.
//
//	Constraints
//		0≤ the integer assigned to a face ≤100
//		0≤ the length of the command ≤100
//	Sample Input 1
//		1 2 4 8 16 32
//		SE
//	Sample Output 1
//		8
//		You are given a dice where 1, 2, 4, 8, 16 are 32 are assigned to a face labeled by 1, 2, ..., 6 respectively. After you roll the dice to the direction S and then to the direction E, you can see 8 on the top face.
//
//
//
//	Sample Input 2
//		1 2 4 8 16 32
//		EESWN
//	Sample Output 2
//		32

#include <iostream>
#include <vector>
#include <string>

const unsigned int	faces	{6};

void	E(std::vector<unsigned int>& dice);
void	N(std::vector<unsigned int>& dice);
void	S(std::vector<unsigned int>& dice);
void	W(std::vector<unsigned int>& dice);

int	main(int	argc,
		 char*	argv[])
{
	std::vector<unsigned int>	dice	{};
	dice.resize(faces, 0);

	for(unsigned int i = 0; i < faces; i++){
		std::cin >> dice[i];
	}

	std::string	commands	{};
	std::cin >> commands;

	for(unsigned int i = 0; i < commands.length(); i++){
		switch(commands[i]){
		case 'E':
			E(dice);
			break;
		case 'N':
			N(dice);
			break;
		case 'S':
			S(dice);
			break;
		case 'W':
			W(dice);
			break;
		default:
			break;
		}
	}

	std::cout << dice[0] << '\n';
    return 0;
}

void	E(std::vector<unsigned int>& dice)
{
	unsigned int	x	= dice[0];
	dice[0]	= dice[3];
	dice[3]	= dice[5];
	dice[5]	= dice[2];
	dice[2]	= x;
}

void	N(std::vector<unsigned int>& dice)
{
	unsigned int	x	= dice[0];
	dice[0]	= dice[1];
	dice[1]	= dice[5];
	dice[5]	= dice[4];
	dice[4]	= x;
}

void	S(std::vector<unsigned int>& dice)
{
	unsigned int	x	= dice[0];
	dice[0]	= dice[4];
	dice[4]	= dice[5];
	dice[5]	= dice[1];
	dice[1]	= x;
}

void	W(std::vector<unsigned int>& dice)
{
	unsigned int	x	= dice[0];
	dice[0]	= dice[2];
	dice[2]	= dice[5];
	dice[5]	= dice[3];
	dice[3]	= x;
}



Measured memory_bytes: 3180
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <vector>
#include <string>
#include <iostream>
#include <algorithm>
#include <map>
#include <iterator>
#include <functional>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <fstream>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <list>
#include <sstream>
#include <complex>
#include <stdio.h>
#include <unordered_set>
using namespace std;
#pragma GCC optimize("O3")
#pragma GCC target("sse4")

typedef double LD;
typedef long long LL;
typedef pair<int, int> PII;
typedef pair<LD, LD> PDD;
typedef pair<LL, LL> PLL;
typedef vector<int> VI;
typedef vector<LL> VLL;
typedef vector<char> VCH;
typedef vector<LD> VLD;
typedef vector<string> VS;
typedef vector<VS> VSS;
typedef vector<VI> VVI;
typedef vector<VLL> VVLL;
typedef vector<VCH> VVCH;
typedef vector<PII> VPII;
typedef vector<PLL> VPLL;
typedef vector<PDD> VPDD;
#define MP make_pair
#define PB push_back
#define X first
#define Y second
#define next fake_next
#define prev fake_prev
#define left fake_left
#define right fake_right

#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define RFOR(i,b,a) for(int i = (b) - 1; i >= (a); --i)
#define REP(i, t) FOR(i,0,t)
#define ALL(a) a.begin(), a.end()
#define SZ(a) (int)((a).size())

const LD PI = acos(-1.0);
const LL mod = 1000000007;
const LL INF = 1e9;
const LL LINF = 1e18;
const LL MAXN = 1e5 + 1;
const LL MAXS = 100 + 1;
const LL MAXT = 100 + 1;

void bad()
{
	cout << -1;
	exit(0);
}

int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	//freopen("In.txt", "r", stdin);
	//freopen("In.txt", "w", stdout);

	LL n;
	cin >> n;
	VLL a(n);
	FOR(i, 0, n)
		cin >> a[i];

	LL mi = 2, ma = 2;
	RFOR(i, n, 0)
	{
		mi = ((mi + a[i] - 1) / a[i])*a[i];
		ma = (ma / a[i])*a[i];

		if (mi > ma)
			bad();

		ma += (a[i] - 1);
	}

	cout << mi << " " << ma;
	cin >> n;
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <string>

using namespace std;

using ll = long long;


int main() {
	ll w,h;
	ll x,y;
	cin >> w >> h >> x >> y;

	ll ans =  w * h / 2;
	string s = to_string(ans);
	if (w * h % 2 == 1) {
		s += ".5";
	}




	cout << s << " ";



	if (w % 2 == 0 && x == w / 2 && h % 2 == 0 && y == h / 2) {
		cout << 1;
	} else {
		cout << 0;
	}
	cout << endl;

	return 0;
}

Measured memory_bytes: 888
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,ans=0;;
  cin>>n;
  vector<int> b(n);
  for(int i=0;i<n-1;i++){
    cin>>b[i];
  }
  b[n-1]=b[n-2];
  ans+=b[0];
  
  for(int i=0;i<n-1;i++){
    ans+=min(b[i],b[i+1]);

  }
 cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main() {
	int a, i;
	i = 1;
	while (1) 
	{
		scanf("%d", &a);
		if (a == 0) {
			break;
		}
		printf("Case %d: %d\n", i, a);

		i++;
	}
	return 0;
}

Measured memory_bytes: 2592
#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>
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;

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

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

int main(void){
    int n;
    cin >> n;
    VL a(n);
    REP(i,n) a[i] = in();
    vector<PL> p(n);
    REP(i,n) p[i] = PL(a[i], i);
    sort(ALL(p));
    reverse(ALL(p));
    VVL dp(n + 1, VL(n + 1));
    dp[0][n] = 0;
    REP(x,n){
        int i = p[x].second;
        REP(left,x+1){
            int right = left + n - x;
            chmax(dp[left + 1][right], dp[left][right] + a[i] * abs(left - i));
            chmax(dp[left][right - 1], dp[left][right] + a[i] * abs(right - 1 - i));
        }
    }
    ll ans = 0;
    REP(i,n + 1) chmax(ans, dp[i][i]);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 34744
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cstdio>
#include <cstring>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>
#include <iomanip> 

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

#define FALSE printf("false\n");
#define TRUE printf("true\n");
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i = 0;(i) < ((int)(n));++(i))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )
#define test(a) cout<<"line:"<<__LINE__<<"["<<(#a)<<": "<<(a)<<"]"<<endl

const int INF = 1e9+7;
const ll INFL = 9*1e18;

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

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

ll inline digit(ll num){int tmp = 0;while(num){tmp++;num/=10;}return tmp;} // 桁数
template<typename T>inline void print(T&& x){cout<<x<<endl;}// 改行付き出力
template<typename T>inline T SUM(vector<T> vec){return accumulate(all(vec),(T)0);} // vectorの中身を全部足す
template<typename T>inline T digitSum(T num){T sum = 0;while(num){sum+=num%10;num/=10;}return sum;} // 各桁の和
template<typename T>inline T gcd(T a,T b){if(b == 0)return a;return gcd(b,a%b);} // 最大公約数
template<typename T>inline T lcm(T a, T b){T g = gcd(a,b);return a/g*b;} // 最小公倍数
template<typename T>inline T power(T a,T b){T tmp=1;rep(i,b){tmp*=a;}return tmp;} // 累乗
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int ctoi(char c){return c-'0';}


// TODO: write
int main() {
  int n;cin>>n;
  map<string,int> m;
  rep(i,n){
    string s;cin>>s;sort(all(s));
    m[s]++;
  }
  ll ans = 0;
  for(auto&& one: m){
    ll cnt = one.se;
    ans += (cnt*(cnt-1))/2;
  }
  print(ans);
  return 0;
}

Measured memory_bytes: 11296
#include <bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i, a, b) for(ll i = (a); i < (ll)b; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF (1ll << 60)
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
using vl = vector<ll>;
using vvl = vector<vl>;
typedef double db;
typedef string str;
typedef pair<ll, ll> p;
constexpr int MOD = 1000000007;
using ll = long long;
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;
}

void print(const std::vector<int> &v) {
    std::for_each(v.begin(), v.end(), [](int x) { std::cout << x << " "; });
    std::cout << std::endl;
}
int main() {
    ll A, B, C, D;
    cin >> A >> B >> C >> D;
    cout << max(A * B, C * D) << endl;
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<cassert>

typedef long long ll;
typedef unsigned long long ull;

using namespace std;

int n,x,Ans;
vector<int> v;

int main()
{
	cin>>n>>x;
	v.push_back(x);
	while(n--) cin>>x,v.push_back(x);
	sort(v.begin(),v.end());
	for(int i=0;i<v.size()-1;i++)
		Ans=__gcd(Ans,v[i+1]-v[i]);
	cout<<Ans<<endl;
}

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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
string char_to_string(char val) {
  return string(1, val);
}
int char_to_int(char val) {
  return val - '0';
}
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;
}
int vector_finder(std::vector<ll> vec, int number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) { // 発見できたとき
    return 1;
  }
  else { // 発見できなかったとき
    return 0;
  }
}
struct edge {
  ll to, cost;
};

int main() {
  int H, W; cin >> H >> W;
  vector<vector<string>> S(H, vector<string>(W));
  REP(i, H) {
    REP(k, W) {
      cin >> S[i][k];
    }
  }
  REP(i, H) {
    REP(k, W) {
      if(S[i][k] == "snuke") {
        char c = 'A' + k;
        cout << c << (i + 1) << endl;
      }
    }
  }
}

Measured memory_bytes: 3504
while True:
    n = int(input())
    if n == 0:
        break

    s = list(map(int, input().split()))
    kei = 0
    for p in s:
        kei += p

    m = kei / n

    a = 0
    for p in s:
        a += ((p - m)**2) / n

    import math
    h = math.sqrt(a)
    print(h)

Measured memory_bytes: 7788
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cfenv>
#define rep(i, n) for(int i=0 ; i<n; ++i)
#define rep2(i, j, n) for(int i=j; i<n; ++i)
using namespace std;
typedef long long ll;
typedef unsigned long ul;


int main(){
    ll n;
    cin>>n;
    ll num = n;
    ll ans, flag=0;
    ll max, min= 1000000000000002;
    for(ll i=2; i*i<=n; i++){
        if(num%i==0 && min>i+num/i){
            min = i+num/i;
            flag = 1;
        }
    }
    if(flag==0)min=n+1;
    cout<<min-2<<endl;
}
vector<ll> divisor(ll n) {
  vector<ll> ret;
  for(ll i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,res;
    cin>>n;
    vector<int>v(n);
    for(int i=0;i<n;i++)
        cin>>v[i];
        sort(v.begin(),v.end());
       res=v[n/2]-v[n/2-1];

    cout<<res<<endl;
    return 0;
}


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

int main() {
    int H1, M1, H2, M2, K;
    cin >> H1 >> M1 >> H2 >> M2 >> K;

    int startTime = H1 * 60 + M1;
    int endTime = H2 * 60 + M2;

    cout << endTime - startTime - K << endl;
}

Measured memory_bytes: 3636
using System;
using System.Linq;
using System.Collections.Generic;

using E = System.Linq.Enumerable;

public class Program
{
    public static void Main()
    {
        var s = Console.ReadLine().Trim();

        var ss = s.Select(x => x == 'R' ? 1 : -1).ToArray();
        var n = s.Length;

        var traps = new List<int>();
        for (int i = 1; i < n; ++i)
        {
            if (ss[i] - ss[i - 1] != -2)
            {
                continue;
            }

            traps.Add(i - 1);
        }

        var a = new int[n];
        int k = 0;
        for (int j = 0; j < traps.Count; ++j)
        {
            for (; k < n; ++k)
            {
                if (ss[k] < 0)
                {
                    break;
                }

                ++a[traps[j] + (traps[j] - k & 1)];
            }
            for (; k < n; ++k)
            {
                if (ss[k] > 0)
                {
                    break;
                }

                ++a[traps[j] + 1 - (1 - (k - traps[j] & 1))];
            }
        }

        Console.WriteLine(string.Join(" ", a));
    }
}


Measured memory_bytes: 15200
import itertools
def main():

    N, M, R = map(int, input().split())
    r = list(map(int, input().split()))
    r = [v-1 for v in r]

    dist = [[float('inf') for _ in range(N)] for _ in range(N)]
    for i in range(N): dist[i][i] = 0
    for _ in range(M):
        a, b, c = map(int, input().split())
        dist[a-1][b-1] = c
        dist[b-1][a-1] = c

    for k in range(N):
        for i in range(N):
            for j in range(N):
                dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j])

    path = itertools.permutations(r)
    ans = float('inf')
    for p in path:
        d = 0
        for i in range(len(p)-1):
            d += dist[p[i]][p[i+1]]
        ans = min(ans, d)

    return ans

if __name__ == '__main__':
    print(main())

Measured memory_bytes: 61400
#include <iostream>
#include <math.h>
#include <string> 
#include <cstdlib>/*絶対値取得*/
using namespace std;
#define MAX 200000

int main(){
    int i=0;
    char a;
    while(cin>>a)if(++i%2)cout<<a;
    cout<<endl;
    return 0;
}

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

const int64_t MOD = 1e9+7;
void add(int64_t& a, int64_t b){
    a = (a+b) % MOD;
}
void mul(int64_t& a, int64_t b){
    a = a*b % MOD;
}

vector<int64_t> fact, seq_inv, fact_inv;

void create_fact_mod(int num){
    fact[0] = fact[1] = 1;
    for(int i=2; i<=num; i++) fact[i] = fact[i-1] * i % MOD;
}

void create_seq_inv_mod(int num){
    seq_inv[0] = seq_inv[1] = 1;
    for(int i=2; i<=num; i++) seq_inv[i] = (MOD - MOD/i) * seq_inv[MOD%i] % MOD;
}

void create_fact_inv_mod(int num){
    fact_inv[0] = fact_inv[1] = 1;
    for(int i=2; i<=num; i++) fact_inv[i] = fact_inv[i-1] * seq_inv[i] % MOD;
}

void create_mod_tables(int num){
    fact.resize(num+1);
    seq_inv.resize(num+1);
    fact_inv.resize(num+1);
    create_fact_mod(num);
    create_seq_inv_mod(num);
    create_fact_inv_mod(num);
}

int64_t comb_mod(int n, int k){
    return fact[n] * fact_inv[n-k] % MOD * fact_inv[k] % MOD;
}

int64_t perm_mod(int n, int k){
    return fact[n] * fact_inv[n-k] % MOD;
}

int64_t power_mod(int64_t num, int64_t power){
    int64_t prod = 1;
    num %= MOD;
    while(power > 0){
        if(power&1) prod = prod * num % MOD;
        num = num * num % MOD;
        power >>= 1;
    }
    return prod;
}

int64_t extgcd(int64_t a, int64_t b, int64_t& x, int64_t& y){
    int64_t d = a;
    if(b != 0){
        d = extgcd(b, a%b, y, x);
        y -= (a/b) * x;
    }else{
        x = 1; y = 0;
    }
    return d;
}

int64_t inv_mod(int64_t a){
    int64_t x, y;
    extgcd(a, MOD, x, y);
    return (MOD + x%MOD) % MOD;
}

int main(){
    int r1, c1, r2, c2;
    cin >> r1 >> c1 >> r2 >> c2;

    create_mod_tables(2100000);
    auto calc = [&](int r, int c){
        return comb_mod(r+c+2, r+1);
    };
    int64_t ans = (calc(r2, c2) - calc(r2, c1-1) - calc(r1-1, c2) + calc(r1-1, c1-1) + 2*MOD) % MOD;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 49408
#include<iostream>
#include<cmath>
#include<cstdio>
using namespace std;
#define PI  3.14159265358979

int main(){
  int C;
  double a,b,S,L,h;

  cin >> a >> b >> C;

  S = (a*b*sin(C/180.0*PI))/2;
  L = a+b+(sqrt(a*a+b*b -2*a*b*cos(C/180.0*PI)));
	   h = (S*2)/a;
	   printf("%.8f\n%.8f\n%.8f\n",S,L,h);
	 




  return 0;
}

Measured memory_bytes: 1248
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;

class Main {
	public static void main(String[] args) {
		InputStreamReader is = new InputStreamReader(System.in);
		BufferedReader br = new BufferedReader(is);
		ArrayList<Integer> output = new ArrayList<Integer>();
		String input;
		try {
			while ((input = br.readLine()) != null) {
				int a = Integer.parseInt(input.split(" ")[0]);
				int b = Integer.parseInt(input.split(" ")[1]);
				int c = a + b;
				output.add(Integer.toString(c).length());
			}
			for(int i: output){
				System.out.println(i);
			}
		} catch (IOException e) {
			System.out.println(e);
		}
	}
}

Measured memory_bytes: 24372
#include <stdio.h>

int main(void)
{
    int m, f, r, sum;
    
    while(scanf("%d %d %d", &m, &f, &r))
    {
        sum = m + f;

        if(m == -1 && f == -1 && r == -1)
        {
            return 0;
        }

        else if((m == -1 || f == -1) || sum < 30)
        {
            printf("F\n");
        }

        else if(sum >= 80)
        {
            printf("A\n");
        }

        else if(sum >= 65)
        {
            printf("B\n");
        }

        else if(sum >= 50)
        {
            printf("C\n");
        }

        else if(sum >= 30 && r >= 50)
        {
            printf("C\n");
        }

        else if(sum >= 30)
        {
            printf("D\n");
        }
    }
}

Measured memory_bytes: 584
#include <iostream>
#include <vector>
using namespace std;
int main() {
int h, w, i, j;
cin>>h>>w;
vector<vector<char>> ar(h, vector<char>(w));
vector<vector<int>> dp(h, vector<int>(w, 0));
for(i=0;i<h;i++)
{
    for(j=0;j<w;j++)
    cin>>ar[i][j];
}
dp[0][0]=1;
for(j=1;j<w;j++)
{
    if(ar[0][j]=='.')
    dp[0][j]+=dp[0][j-1];
    else if(ar[0][j]=='#')
    {
        dp[0][j]=-1;
        break;
    }    
}
for(i=1;i<h;i++)
{
    if(ar[i][0]=='.')
    dp[i][0]+=dp[i-1][0];
    else if(ar[i][0]=='#')
    {
        dp[i][0]=-1;
        break;
    }
}
for(i=1;i<h;i++)
{
    for(j=1;j<w;j++)
    {
       if(ar[i][j]!='#')
       {
           if(dp[i-1][j]>0)
           dp[i][j]=dp[i-1][j];
           if(dp[i][j-1]>0)
           dp[i][j]=(dp[i][j]+dp[i][j-1])%1000000007;
       }
    }
}
cout<<dp[h-1][w-1]<<endl;
return 0;
}


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

bool betemp(string sleft, string sright, int left, int right) {
    if (sleft == sright) return (right - left) % 2 == 1;
    else return (right - left) % 2 == 0;
}

void solve(int N) {
    string vac = "Vacant";
    string sleft, sright, str;
    int left = 0, right = N/2;
    cout << left << endl;
    cin >> sleft;
    if (sleft == vac) return;
    cout << right << endl;
    cin >> sright;
    if (sright == vac) return;

    if (!betemp(sleft, sright, left, right)) {
        swap(sleft, sright), left = right, right = N;
    }
    while (true) {
        int mid = (left + right) / 2;
        cout << mid << endl;
        cin >> str;
        if (str == vac) return;
        if (betemp(sleft, str, left, mid)) sright = str, right = mid;
        else sleft = str, left = mid;
    }
}

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

Measured memory_bytes: 852
#include <iostream>
#include <string>
#include <map>

using namespace std;

int main() {
    int n;
    cin >> n;
    string s;
    int count[n][26] = {0};

    for(int i=0; i<n; i++) {
        cin >> s;
        for(int j=0; j<s.length(); j++) count[i][s[j]-'a']++;
    }

    for(int i=1; i<n; i++) {
        for(int j=0; j<26; j++) {
            count[0][j]=(count[0][j]<count[i][j])?count[0][j]:count[i][j];
        }
    }

    for(int i=0; i<26; i++) {
        for(int j=0; j<count[0][i]; j++) cout << (char)('a' + i);
    }

    cout << endl;

    return 0;
}



Measured memory_bytes: 256
/* A/B Problem */
#include <stdio.h>

int main()
{
    int a, b, d, r;
    double f;

    scanf("%d %d", &a, &b);
    d = a / b;
    r = a % b;
    f = 1.0 * a / b;
    printf("%d %d %.5lf\n", d, r, f);
    return 0;
}


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

typedef long long ll;


int N = 26;
int D;

vector<int> c(N+1);
vector<vector<int>> s;
vector<int> t;

ll now_score = 0;

ll greedy(){
    vector<int> last(N+1, 0);
    ll greedy_score;
    for(int d = 1; d <= D; d++){
        ll max_score = -1e9;
        vector<int> max_last;
        for(int n = 1; n <= N; n++){
            ll tmp_score = 0;
            vector<int> tmp_last(N+1);
            tmp_last = last;
            
            tmp_score +=  s[d][n];
            tmp_last[n] = d;
     
            int penalty = 0;
            for(int i = 1; i <= N; i++){
                penalty += c[i]*(d-tmp_last[i]);    
                
            }
            
            tmp_score -= penalty;

            if(max_score < tmp_score){
                max_score = tmp_score;
                max_last = tmp_last;
                t[d] = n;
            }                    
            
        }
        
        last = max_last;
        greedy_score = max_score;
    }

    return greedy_score;
}


ll scoring(){
    vector<int> last(N+1, 0);
    ll score = 0;
    for(int d = 1; d <= D; d++){

        score += s[d][t[d]];
        last[t[d]] = d;

        int penalty = 0;
        for(int i = 1; i <= N; i++){
            penalty += c[i]*(d-last[i]);    
        }
        
        score -= penalty;            
    }
    return score;
}


void exchange(int d){
    swap(t[d], t[d+1]);

    ll swap_score = scoring();
    if(now_score > swap_score){
        swap(t[d], t[d+1]);
    }else{
        now_score = swap_score;
    }

}



int main(){

    cin>> D;

    s.resize(D+1);
    for(int i=0; i<=D; i++){
        s[i].resize(N+1);
    }
    t.resize(D+1);

    for(int i=1; i<=N; i++){
        cin>>c[i];
    }
 
    for(int i=1; i<=D; i++){
        for(int j=1; j<=N; j++){
            cin>>s[i][j];
        }
    }
    for(int i=1; i<=D; i++){
        cin>>t[i];
    }

    now_score = greedy();

    //解交換
    
    for(int d=1; d<D; d++){
        exchange(d);
    }
    
    for(int i=1; i<=D; i++){           
        cout<<t[i]<<endl;
    }
    return 0;
}

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

int main() {
    int N;
    cin >> N;
    vector<string> v(N);
    map<string, llint> mapa;
    for(auto& e: v) {
        cin >> e;
        sort(e.begin(), e.end());
        mapa[e]++;
    }
    llint rez = 0;
    for(auto e: mapa) {
        rez += (e.second - 1) * (e.second) / 2;
    }
    cout << rez;
}

Measured memory_bytes: 18176
import java.io.*;
import java.util.Arrays;
class Main{
	public static void main(String[] args) throws IOException {
		int i,m,max,min;
		long sum;
		int[] n = new int[990000];
		String[] str = new String[990000];
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		str = in.readLine().split(" ");
		m = Integer.parseInt(str[0]);
		str = in.readLine().split(" "); 
		sum = max = min = Integer.parseInt(str[0]);
		for(i=1;i<m;i++){
			n[i] = Integer.parseInt(str[i]);
			max = Math.max(max,n[i]);
			min = Math.min(min,n[i]);
			sum += n[i];
		}
		System.out.println(min+" "+max+" "+sum);
	}
}

Measured memory_bytes: 36256
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")

#include <bits/stdc++.h>

using namespace std;

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

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;

class CommonIO {
public:
    CommonIO() {
        std::cin.tie(0);
        std::ios::sync_with_stdio(false);
    }
    ~CommonIO() {}

    template <class T>
    void scan(T &v) {
        std::cin >> v;
    }
    template <class T, class... Rest>
    void scan(T &v, Rest&... rest) {
        scan(v);
        scan(rest...);
    }

    template <class T>
    void print(T v) {
        std::cout << v;
    }
    template <class T>
    void print(std::vector<T> &v) {
        if (v.size() == 0) return;
        print(*v.begin());
        for (auto it = ++v.begin(); it != v.end(); ++it) {
            print(' ');
            print(*it);
        }
    }
    template <class T>
    void print(std::vector< std::vector<T> > &grid) {
        if (grid.size() == 0) return;
        print(*grid.begin());
        for (auto it = ++grid.begin(); it != grid.end(); ++it) {
            print('\n');
            print(*it);
        }
    }
    template <class T, class... Rest>
    void print(T v, Rest... rest) {
        print(v);
        print(' ');
        print(rest...);
    }

    template <class T>
    void printl(T v) {
        print(v);
        std::cout << '\n';
    }
    template <class T, class... Rest>
    void printl(T v, Rest... rest) {
        print(v);
        print(' ');
        printl(rest...);
    }
} io;



int main() {
    int N, P; io.scan(N, P);
    string s; io.scan(s);

    ll res = 0;

    if (10 % P == 0) {
        REP(i, N) {
            if ((s[i] - '0') % P == 0) {
                res += i + 1;
            }
        }
    }
    else {
        reverse(s.begin(), s.end());
        vector<ll> mods(P, 0);
        mods[0] = 1;
        int mod = 0, mod10 = 1;
        REP(i, N) {
            mod = (mod + (s[i] - '0') * mod10) % P;
            mod10 = (mod10 * 10) % P;
            res += mods[mod];
            //io.printl(s[i] - '0', mod, mods[mod]);
            ++mods[mod];
        }
    }
    
    io.printl(res);

    return 0;
}


Measured memory_bytes: 720
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		char[] array = sc.next().toCharArray();
		long K = sc.nextLong();
		for (int i=0; i<array.length&&K>0; i++) {
			int k = score(array[i]);
			if (K<k) continue;
			array[i] = 'a';
			K -= k;
		}
		if (K>0) {
			array[array.length-1] += K%26;
		}
		System.out.println(String.valueOf(array));
		sc.close();
	}
	
	public static int score(char c) {
		return (25-c+98)%26;
	}
}


Measured memory_bytes: 14376
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <map>
#include <numeric>
#include <cmath>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <complex>
#include <string.h>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <iomanip>
#include <sys/time.h>
#include <tuple>
#include <random>
using namespace std;

#define endl '\n'
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define UNIQ(v) (v).erase(unique((v).begin(), (v).end()), (v).end())

typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef complex<double> comp;
typedef vector< vector<ld> > matrix;
struct pairhash {
public:
    template<typename T, typename U>
    size_t operator()(const pair<T, U> &x) const {
	size_t seed = hash<T>()(x.first);
	return hash<U>()(x.second) + 0x9e3779b9 + (seed<<6) + (seed>>2);
    }
};
const int inf = 1e9 + 9;
const ll mod = 1e9 + 7;
const double eps = 1e-8;
const double pi = acos(-1);

int n;
ll m;
int x[100100], y[100100];
vector<int> G[100100];

ll dp[100100];
ll dp2[100100];

ll calc(int v, int p) {
    ll res = 1;
    for (int u : G[v]) {
        if (u == p) continue;
        res *= (calc(u, v) + 1);
        res %= m;
    }
    return dp[v] = res;
}

void calc2(int v, int p, ll val) {
    dp2[v] = (dp[v] * val) % m;
    int sz = G[v].size();
    ll suf[sz+1], pre[sz+1];
    suf[0] = pre[0] = 1;
    for (int i = 0; i < sz; i++) {
        int u = G[v][i];
        if (u == p) {
            suf[i+1] = suf[i];
        } else {
            suf[i+1] = (suf[i] * (dp[u]+1)) % m;
        }

        int w = G[v][sz-i-1];
        if (w == p) {
            pre[i+1] = pre[i];
        } else {
            pre[i+1] = (pre[i] * (dp[w]+1)) % m;
        }
    }

    for (int i = 0; i < sz; i++) {
        int u = G[v][i];
        if (u == p) continue;

        calc2(u, v, ((val * suf[i] % m) * pre[sz-i-1] + 1) % m);
    }
}

void solve() {
    for (int i = 0; i < n-1; i++) {
        G[x[i]].push_back(y[i]);
        G[y[i]].push_back(x[i]);
    }

    calc(0, -1);
    calc2(0, -1, 1);
    
    for (int i = 0; i < n; i++) {
        cout << dp2[i] << endl;
    }
}

void input() {
    cin >> n >> m;
    for (int i = 0; i < n-1; i++) {
        cin >> x[i] >> y[i];
        x[i]--;
        y[i]--;
    }
}

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

    input();
    solve();
}


Measured memory_bytes: 21632
#include <iostream>
#include <vector>
#include <queue>

using namespace std;

struct Point {
    int x;
    int y;
};
int main() {
    int H, W;
    cin >> H >> W;
    vector<vector<int>> count(H, vector<int>(W, -1));
    queue<Point> que;
    for (auto i = 0; i < H; i++) {
        for (auto j = 0; j < W; j++) {
            char cell;
            cin >> cell;
            if (cell == '#') {
                count[i][j] = 0;
                Point p = {i, j};
                que.push(p);
            }
        }
    }

    while (!que.empty()) {
        Point src = que.front();
        que.pop();
        vector<Point> buf = {
            Point {src.x - 1, src.y},
            Point {src.x + 1, src.y},
            Point {src.x, src.y - 1},
            Point {src.x, src.y + 1}
        };
        for (auto p: buf) {
            if (0 <= p.x && p.x <= H-1 && 0 <= p.y && p.y <= W-1 && count[p.x][p.y] < 0) {
                count[p.x][p.y] = count[src.x][src.y] + 1;
                que.push(p);
            }
        }
    }

    int ans = 0;

    for (auto i = 0; i < H; i++) {
        for (auto j = 0; j < W; j++) {
            if (ans < count[i][j]) ans = count[i][j];
        }
    }

    cout << ans << endl;
    
}

Measured memory_bytes: 12432
n=int(input())
W=list(map(int,input().split()))
s=sum(W)
ans=0
cnt=0
for w in W:
    ans+=w
    cnt+=1
    if ans>=s/2:
        break
p=sum(W[:cnt])
q=sum(W[:cnt-1])
print(min(abs(s-2*p),abs(s-2*q)))

Measured memory_bytes: 3444
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<set>
#include<queue>
#include<stack>
#include<functional>
using namespace std;
int p = 1000000007;
#define int long long
#define vel vector<long long>
#define vvel vector<vel>
#define rep(i,n) for(long long i=0;i<n;i++)
#define sor(v) sort(v.begin(),v.end())
#define mmax(a,b) a=max(a,b)
#define mmin(a,b) a=min(a,b)
#define mkp make_pair
#define pin pair<int,int>
#define V vector
#define Endl endl
#define veb vector<bool>
#define sq(a) (a)*(a)
int kai_size = 100001;
vel kai(kai_size, 1);
vel ink(kai_size, 1);
vel dist;
int RE() {
	vel v(3, 2);
	return v.at(4);
}
void dis(int mid1, vvel &way,vel &conect) {
	int n = way.size();
	dist[mid1] = 0;
	queue<int> q;
	q.push(mid1);
	while (!q.empty()) {
		int st = q.front(); 
		conect.push_back(st);
		q.pop();
		rep(i, way[st].size()) {
			int to = way[st][i];
			if (dist[to] == -1) { 
				dist[to] = dist[st] + 1;
				q.push(to);
			}
		}
	}
}

signed main() {
	int n, m; cin >> n >> m;
	vvel way(n);
	rep(i, m) {
		int u, v; cin >> u >> v;
		u--; v--;
		way[u].push_back(v);
		way[v].push_back(u);
	};
	V<pin> list(0);
	dist = vel(n, -1);
	int nibu = 0;
	int not_nibu = 0;
	int only_one = 0;
	rep(i, n) {
		if (dist[i] == -1) {
			vel conect(0);
			dis(i, way, conect);
			if (conect.size() == 1) { only_one++; }
			else {
				bool is_nibu = true;
				for(auto st: conect) {
					for (auto to: way[st]) {
						if ((dist[st] + dist[to]) % 2 == 0) { is_nibu = false; }
					}
				}
				if (is_nibu) { nibu++; }
				else { not_nibu++; }
			}
		}
	}
	int ans = sq(n) - sq(n-only_one);
	ans += sq(nibu) + sq(nibu + not_nibu);
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 12536