akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>

using namespace std;

typedef pair < int, int > PII;

const int NMAX = 2e5 + 5;

int N, M;

long long dp[NMAX];
long long sum[NMAX];

vector < PII > G[NMAX];

static inline void Read ()
{
    ios_base :: sync_with_stdio(false);
    cin.tie(nullptr);

    cin >> N >> M;

    for(int i = 1; i <= M; ++i)
    {
        int l = 0, r = 0, a = 0;
        cin >> l >> r >> a;

        G[r].push_back({l, a});

        sum[r] += a;
    }

    return;
}

class SegmentTree
{
    long long A[(NMAX << 2)];
    long long Lazy[(NMAX << 2)];

public:
    inline void Go (int Node, int a, int b)
    {
        if(Lazy[Node] == 0)
            return;

        if(a == b)
            return;

        A[2 * Node] += Lazy[Node];
        A[2 * Node + 1] += Lazy[Node];

        Lazy[2 * Node] += Lazy[Node];
        Lazy[2 * Node + 1] += Lazy[Node];

        Lazy[Node] = 0;

        return;
    }

    inline void Update_1 (int Node, int a, int b, int ua, int ub, long long X)
    {
        if(ua <= a && b <= ub)
        {
            Lazy[Node] += X;
            A[Node] += X;

            return;
        }

        Go(Node, a, b);

        int Mid = (a + b) >> 1;

        if(ua <= Mid)
            Update_1(2 * Node, a, Mid, ua, ub, X);

        if(ub > Mid)
            Update_1(2 * Node + 1, Mid + 1, b, ua, ub, X);

        A[Node] = max(A[2 * Node], A[2 * Node + 1]);

        return;
    }

    inline void Update_2 (int Node, int a, int b, int pos, long long X)
    {
        if(a == b)
        {
            A[Node] = X;

            return;
        }

        Go(Node, a, b);

        int Mid = (a + b) >> 1;

        if(pos <= Mid)
            Update_2(2 * Node, a, Mid, pos, X);

        if(pos > Mid)
            Update_2(2 * Node + 1, Mid + 1, b, pos, X);

        A[Node] = max(A[2 * Node], A[2 * Node + 1]);

        return;
    }

    inline long long Query (int Node, int a, int b, int qa, int qb)
    {
        if(qa <= a && b <= qb)
            return A[Node];

        Go(Node, a, b);

        int Mid = (a + b) >> 1;

        long long p1 = 0, p2 = 0;

        if(qa <= Mid)
            p1 = Query(2 * Node, a, Mid, qa, qb);

        if(qb > Mid)
            p2 = Query(2 * Node + 1, Mid + 1, b, qa, qb);

        return max(p1, p2);
    }
} T;

static inline void Solve ()
{
    for(int i = 1; i <= (N + 1); ++i)
    {
        for(auto it : G[i - 1])
        {
            int Left = it.first;
            int Right = i;

            long long Cost = it.second;

            if(Left >= Right)
                continue;

            T.Update_1(1, 1, N, Left, Right - 1, Cost);
        }

        if(i > 1)
            dp[i] = max(0LL, T.Query(1, 1, N, 1, i - 1));

        if(i <= N)
            T.Update_2(1, 1, N, i, dp[i]);

        dp[i] += sum[i];
    }

    cout << dp[N + 1] << '\n';

    return;
}

int main()
{
    Read();

    Solve();

    return 0;
}


Measured memory_bytes: 26880
import java.io.*;
import java.util.*;


public class Main {

	private static Scanner sc;
	private static Printer pr;

	private static void solve() {
		int x = sc.nextInt();
		int y = sc.nextInt();
		int z = sc.nextInt();

		if (x < y + 2 * z) {
			pr.println(0);
		} else {
			pr.println((x - z) / (y + z));
		}
	}

	// ---------------------------------------------------
	public static void main(String[] args) {
		sc = new Scanner(System.in);
		pr = new Printer(System.out);

		solve();

		pr.close();
		sc.close();
	}

	private static class Printer extends PrintWriter {
		Printer(PrintStream out) {
			super(out);
		}
	}
}


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

const long long INF = 1LL<<61;
long long N, K;
vector<long long> A;

long long solve() {
    sort(A.begin(), A.end());
    long long left = -INF, right = INF;
    while (right - left > 1) {
        long long x = (left + right) / 2;
        long long S = 0, T = 0;
        for (int i = 0; i < N; ++i) {
            if (A[i] > 0) {
                int l2 = -1, r2 = N;
                while (r2 - l2 > 1) {
                    int m = (l2 + r2) / 2;
                    if (A[i] * A[m] <= x) l2 = m;
                    else r2 = m;
                }
                S += r2;
            }
            else if (A[i] < 0) {
                int l2 = -1, r2 = N;
                while (r2 - l2 > 1) {
                    int m = (l2 + r2) / 2;
                    if (A[i] * A[m] <= x) r2 = m;
                    else l2 = m;
                }
                S += N - r2;
            }
            else if (x >= 0) S += N;
            if (A[i] * A[i] <= x) ++T;
        }
        long long num = (S - T) / 2;
        if (num >= K) right = x;
        else left = x;
    }
    return right;
}

int main() {
    cin >> N >> K;
    A.resize(N);
    for (int i = 0; i < N; ++i) cin >> A[i];
    cout << solve() << endl;
}

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

namespace Sunuke
{
    class Program
    {
        static void Main(string[] args)
        {
            int input = int.Parse(Console.ReadLine());

            var dic = new Dictionary<int, int> {{0,0},
                                               {1,1},
                                               {10,1},
                                               {100,1},
                                               {11,2},
                                               {101,2},
                                               {110,2},
                                               {111,3}
            };

            Console.WriteLine(dic[input]);
        }
    }
}


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

int main()
{
	int n, m;
	while (cin >> n >> m, n | m) {
		if (n <= 36) {
			int n1 = n / 2, n2 = n - n1;
			vector<vector<bool>> b(n, vector<bool>(m));
			for (int i = 0; i < n; i++) {
				for (int j = 0; j < m; j++) {
					char c;
					cin >> c;
					b[i][j] = c == '1';
				}
			}
			map<vector<bool>, int> mp;
			for (int i = 0; i < (1 << n1); i++) {
				vector<bool> bs(m);
				for (int j = 0; j < n1; j++) if (i & (1 << j)) {
					for (int k = 0; k < m; k++) {
						bs[k] = b[j][k] ^ bs[k];
					}
				}
				auto& val = mp[bs];
				val = max(val, __builtin_popcount(i));
			}
			int res = 0;
			for (int i = 0; i < (1 << n2); i++) {
				vector<bool> bs(m);
				for (int j = 0; j < n2; j++) if (i & (1 << j)) {
					for (int k = 0; k < m; k++) {
						bs[k] = b[n1 + j][k] ^ bs[k];
					}
				}
				if (mp.count(bs)) res = max(res, mp[bs] + __builtin_popcount(i));
			}
			cout << res << endl;
			continue;
		}
		vector<int> b(n);
		vector<int> dp(1 << m, -1e9);
		dp[0] = 0;
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++) {
				char c;
				cin >> c;
				b[i] |= (c == '1') << j;
			}
			auto tmp = dp;
			for (int j = 0; j < (1 << m); j++) {
				dp[j ^ b[i]] = max(dp[j ^ b[i]], tmp[j] + 1);
			}
		}
		cout << dp[0] << endl;
	}
	return 0;
}



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

// types
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;

// macros
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

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

  ll a, b;
  cin >> a >> b;

  ll ans = 0;
  REP1(i, b-a)
    ans += i;
  
  cout << ans-a << endl;
}


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

long long absdif(long long a, long long b){
	return ( a > b ) ? a-b: b-a;
}

int main(){
	int N;
	std::vector<long long> h, dp;
	std::cin >> N;
	h.resize(N);
	dp.resize(N+1);
	for(int i=0; i<N; i++){
		std::cin >> h[i];
	}

	dp[0] = 0;
	for(int i=1; i<N; i++){
		dp[i] = 1e9+9;
		if( i-1 >= 0 )
			dp[i] = std::min(dp[i], dp[i-1] + absdif(h[i], h[i-1]) );
		if( i-2 >= 0 )
			dp[i] = std::min(dp[i], dp[i-2] + absdif(h[i], h[i-2]) );
	}
	std::cout << dp[N-1] << '\n';
	return 0;
}

Measured memory_bytes: 1792
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
#define mpr make_pair
#define fi first
#define se second
using ll=long long int;
static const ll mod = 1e9 + 7;
static const ll INF = 1LL << 50;
using namespace std;

int main(){
	int n,d;
	cin>>n>>d;
	int ans=n/(2*d+1);
	if(n%(2*d+1)!=0)ans++;
	cout<<ans<<endl;
	return 0;
}




Measured memory_bytes: 256
let rec read () =
  try let n = read_int () in
      let rec get_area a = function
          i when i > n -> a
        | i -> get_area (a+i) (i+1)
      in Printf.printf "%d\n" (get_area 2 2)
        ;read ()
  with End_of_file -> ()
;;

let () = read ();;

Measured memory_bytes: 2208
n,x = map(int,input().split())
a = list(map(int,input().split()))

#p[i色のスライム][j回まで色を変えられる]=色変えのコストを含まない最小コスト
p = [[0]*n for i in range(n)]

#print(p)
for i in range(n):
  p[i][0]=a[i]
  for j in range(1,n):
    if i-j>=0:
      p[i][j]=min(a[i-j],p[i][j-1])
    elif i-j == -1:
      p[i][j]=min(a[n-1],p[i][j-1])
    else:  
      p[i][j]=min(a[n-(j-i)],p[i][j-1])
p = list(zip(*p))
ans = sum(p[0])
for i in range(1,n):
  ans = min(ans,sum(p[i])+x*i)
print(ans)

Measured memory_bytes: 166236
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < n; i++)
#define repr(i, n) for(ll i = n; i >= 0; i--)
#define for(i, m, n) for (ll i = m; i < n; i++)
#define inf LLONG_MAX
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;


int main()
{
    string s, t;
    cin >> s >> t;
    ll a, b; cin >> a >> b;
    string u; cin >> u;
    if (s == u) a--;
    else if (t == u) b--;

    cout << a << " " << b << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
  
using namespace std;
  
int main()
{
  int n, m, l;
  int a[100][100];
  int b[100][100];
  
  cin >> n >> m >> l;
  
  // ??????A
  for ( int i = 0; i < n; i++ )
  {
    for ( int j = 0; j < m; j++ )
    {
      cin >> a[ i ][ j ];
    }
  }
  
  // ??????B
  for ( int i = 0; i < m; i++ )
  {
    for ( int j = 0; j < l; j++ )
    {
      cin >> b[ i ][ j ];
    }
  }
  
  // n ?? l ????§????????????C?????????
  for ( int i = 0; i < n; i++ )
  { 
    for ( int j = 0; j < l; j++ )
    {
      long long sum = 0;  // long long == long long int
      for ( int k = 0; k < m; k++ )
      {
        sum += a[ i ][ k ] * b[ k ][ j ];
       }
      if ( j ) cout << " ";
      cout << sum;
    }
    cout << endl;
  }
  return 0;
}

Measured memory_bytes: 1232
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>
#include<complex>

using namespace std;

#define ll long long
#define ld long double
#define INF 1e9
#define LINF (ll)INF*INF
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

const double PI=acos(-1);
const double EPS=1e-9; //うまくいかなかったらゆるめる

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef pair<pii,int> ppi;
typedef pair<int,pii> pip;
typedef vector<pii> vp;
typedef vector<vi> vvi;

int gcd(int a, int b){if(b==0) return a;return gcd(b,a%b);}
int lcm(int a, int b){return a/gcd(a,b)*b;}


signed main(void) {
    int n,k;
    cin >> n >> k;
    vi a(n);
    rep(i,n)cin >> a[i];
    vvi d(n,vi(100));
    rep(i,n)d[i][0] = a[i]-1;
    rep(j,99)rep(i,n)d[i][j+1] = d[d[i][j]][j];
    int ans = 0,cnt = 0;
    while(k){
        if(k%2)ans = d[ans][cnt];
        cnt++;
        k /= 2;
    }
    cout << ans+1 << endl;
}


Measured memory_bytes: 168408
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define REP(i,a,b) for(int i=int(a);i<(int)b;++i)
#define Graph vector<vecctor<ll>>
#define pairs vector<pair<ll,ll>>
#define pb push_back



using namespace std;
using ll = long long;
const ll INF = 1e18;
const double PI = acos(-1);

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 ll mod = 1e9 + 7;








int main(void)
{
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    ll n,ans = 0;
    cin >> n;
    for(int i=1;i < n;i++){
        if(n%i == 0){
            ans += n/i-1;
        }else{
            ans += n/i;
        }
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3644
#include <iostream>
#include <cstdio>
#include <string>

using namespace std;

int main() {
    int n;
    string s, t;
    cin >> n >> s >> t;
    for (int i = 0; i < n; ++i)
        if (s.substr(i, n-i) == t.substr(0, n-i)) {
           cout << i + n << "\n";
           return 0;
        }
    cout << 2*n << "\n";
    return 0;
}


Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)
var out = bufio.NewWriter(os.Stdout)

func main() {
	sc.Split(bufio.ScanWords)
	defer out.Flush() // !!!!coution!!!! you must use Fprint(out, ) not Print()
	/* --- code ---*/
	nums := make([]int, 3)
	for i := 0; i < 3; i++ {
		sc.Scan()
		t := sc.Text()
		x, _ := strconv.Atoi(t)
		nums[i] = x
	}
	n, a, b := nums[0], nums[1], nums[2]
	ans := 0
	// 10で割っていくやつ
	for i := 1; i <= n; i++ {
		j, c := i, 0
		for 0 < j {
			c += j % 10
			j /= 10
		}
		if a <= c && c <= b {
			ans += i
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 640
function main(input) {
    const H = input.split(' ');
    const A = parseInt(H[0], 10);
    const B = parseInt(H[1], 10 );
    if(  (A+B) % 2 === 0) {
       console.log( (A+B) / 2);
   } else { 
      console.log('IMPOSSIBLE');
   }
}

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

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

int main(){
    int N;
    cin >> N;
    vector<int> A(N);
    for(int i=0; i<N; i++){
        cin >> A[i];
    }

    long long count = round(pow(3, N));
    long long odd_count = (A[0] % 2 == 0)? 2 : 1;

    for(int i=1; i<N; i++){
        if(A[i] % 2 == 0){
            odd_count *= 2;
        }else{
            count *= 1;
        }
    }

    cout << count - odd_count << endl;
    return 0;

}

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

using namespace std;

int main() {
    string s, t;
    cin >> s >> t;
    int ans = t.length(), m = t.length();
    for (int i = 0; i + m <= (int)s.length(); ++i) {
        int cur = 0;
        for (int j = 0; j < m; ++j) cur += (s[i + j] != t[j]);
        ans = min(ans, cur);
    }
    cout << ans << '\n';
    return 0;
}

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

const ll mod = 1000000007;


int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
	ll n; cin >> n;
	ll ans = 1001001001001001;
	for(ll i = 1; i*i <= n; i++){
		if(n % i == 0){
			ll x = n/i;
			ans = min(ans, x + i - 2);
		}
	}
	cout << ans;
} 

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<utility>
#include<cstring>
#include<string>
#include<vector>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#define inf 0x3f3f3f3f
using namespace std;
typedef long long ll;
typedef pair<int,int> pll;
const int maxn= 1e5+10;
const int mod =1e9+7;
const double EPS = 1e-6;


int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n,r;
    cin >> n >> r;
    if(n>=10)
        cout << r << endl;
    else
    {
        cout << r+100*(10-n) << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(I,A,B) for(ll I = (A); I < (B); ++I)
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //ai>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //ai>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define REV(x) (reverse(x.begin(),x.end())) //reverse
#define TO(x,t,f) ((x)?(t):(f))
#define CLR(mat) memset(mat, 0, sizeof(mat))
#define FILV(x,a) fill(x.begin(),x.end(),a)
#define FILA(ar,N,a) fill(ar,ar+N,a)
#define NEXTP(x) next_permutation(x.begin(),x.end())
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(a%b==0)return b;else return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}//saisyo kobaisu
#define pb push_back
#define pri(aa) cout<<(aa)<<endl
const ll INF=1e9+7;
const ll N = 51;
int par[N];
int q,n,m;
int ans=0;
int a[N],b[N];

void init(int n){
    FOR(i,0,n)par[i]=i;
}
 
int root(int x){
    if(par[x]==x){
        return x;
    }else{
        return par[x] = root(par[x]);
    }
}
 
void unite(int x,int y){
    x=root(x);
    y=root(y);
    if(x==y)return;
    par[x]=y;
}
 
 
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>n>>m;
    FOR(i,0,m){
    	ll x,y;
    	cin>>x>>y;
    	a[i]=x-1;
    	b[i]=y-1;
    }
    FOR(i,0,m){
    	init(n);
    	FOR(j,0,m){
    		if(i!=j)unite(a[j],b[j]);
    	}
    	ll k = root(0);
    	FOR(j,0,n){
    		if(root(j)!=k){
    			ans++;
    			break;
    		}
    	}
    }
    pri(ans);
    return 0;
}


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

typedef long long ll;
typedef unsigned long long ull;

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

  vector<ll> l(n);
  for (ll i = 0; i < n; ++i) {
    cin >> l[i];
  }
  sort(l.begin(), l.end());
  
  ll ans = 0;
  for (ll i = 0; i < n; ++i) {
    for (ll j = i+1; j < n; ++j) {
      auto itr = lower_bound(l.begin(), l.end(), l[i]+l[j]);
      ll top = distance(l.begin(), itr) - 1;
      ans += top-j;
    }
  }

  cout << ans << endl;
  
  return 0;
}

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

int main(){
  int n,l=0;
  cin >> n;
  for(int i=3;i<=n;i++){
    if(i%2==0)continue;
    int k=0;
    for(int j=1;j<=i;j++){
      if(i%j==0)k++;
      if(j==i && k==8)l++;
    }
  }
  cout << l << endl;
}


Measured memory_bytes: 256
N= int(input())
x= 800 * N
if N < 15:
    y = 0
if 15 <= N < 30:
    y = 200
if 30 <= N < 45:
    y = 400
if 45 <= N < 60:
    y = 600
if 60 <= N < 75:
    y = 800
if 75 <= N <90:
    y = 1000
if 90 <= N <=100:
    y = 1200
print(x-y)

Measured memory_bytes: 9088
#include <stdio.h>
int main(void){
    
    int n;
    int a;
    int x=0,y=0,z=0;
    scanf("%d",&n);
    for(;~scanf("%d",&a);){
        if(a%4==0){
            z++;
        }else if(a%2==0){
            y++;
            }else{
            z--;
        }
    }
    
    if(y&&0<=z||!y&&-1<=z){
        puts("Yes");
    }else{
        puts("No");
    }
}

Measured memory_bytes: 1628
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;

i64 modpow(i64 a, i64 n, i64 mod)
{
  i64 res = 1;
  while (n > 0)
  {
    if (n & 1)
      res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

int main()
{
  i64 N, P;
  string S;
  cin >> N >> P >> S;
  i64 ans = 0, now = 0;
  if (P == 2 || P == 5)
  {
    for (i64 i = 0; i < N; i++)
      if ((S[i] - '0') % P == 0)
        ans += i + 1;
  }
  else
  {
    vector<i64> cnt(P);
    cnt[0]++;
    for (i64 i = N - 1; 0 <= i; i--)
    {
      (now = now + (S[i] - '0') * modpow(10, N - i - 1, P)) %= P;
      ans += cnt[now];
      cnt[now]++;
    }
  }
  cout << ans << endl;
  return 0;
}


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

int main()
{
  while (true) {
    int n;
    cin >> n;
    if (n == 0) break;

    vector<int> h(n + 1);
    for (int i = 0; i <= n; i++) cin >> h[i];

    for (int i = 0; i <= n; i++) {
      vector<int> v = h;
      v.erase(v.begin() + i);

      int kanade = v[1] - v[0];
      bool f = false;
      for (int j = 1; j < v.size(); j++) {
        if (kanade != v[j] - v[j - 1]) {
          f = true;
          break;
        }
      }

      if (!f) {
        cout << h[i] << endl;
        break;
      }
    }
  }

  return (0);
}

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

//template
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(a);i>(b);i--)
#define ALL(v) (v).begin(),(v).end()
typedef long long int ll; typedef pair<ll, ll> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename A,size_t N,typename T>void Fill(A(&array)[N],const T &val){fill((T*)array, (T*)(array+N), val);}
const int inf = INT_MAX / 2; const ll INF = LLONG_MAX / 2;
//template end



int main(){
    int a,b,x; scanf("%d%d%d",&a,&b,&x);
    int wantl=x/1000;
    int ans=wantl*min(a,2*b);
    if(x%1000)ans+=(x%1000>500?min(a,2*b):min(a,b));
    printf("%d\n",ans);
    return 0;
}


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

int main()
{
    double L;
    cin >> L;
    double a = L / 3;
    double b = L / 3;
    double c = L - a - b;
    cout << fixed << setprecision(10);
    cout << a * b * c << endl;
}


Measured memory_bytes: 256
n,q=map(int,input().split())
s=input()
i=0
d=""
while i<n-1:
	if s[i]=="A" and s[i+1]=="C":
		d+="0"*2
		i+=2
	else:
		d+=s[i]
		i+=1
d+=s[-1]
num=[0]*n
cnt=0
for i in range(n):
	if d[i]=="0":
		cnt+=1
	num[i]=cnt//2
for i in range(q):
	x,y=map(int,input().split())
	print(num[y-1]-num[x-1])

Measured memory_bytes: 7668
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <climits>
#include <queue>
#include <set>
#include <map>
#include <valarray>
#include <bitset>
#include <stack>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
typedef long long ll;
typedef pair<int,int> pii;
const int INF = 1<<29;
const double PI = acos(-1);
const double EPS = 1e-8;

int x[100];
string t1[100], t2[100];
int g[200][200];

int main() {
  int n;
  while(scanf("%d",&n),n) {
    REP(i,n) {
      char s1[20],s2[20];
      scanf("%*d %s %*c%*d%*c%d %s", s1, x+i, s2);
      t1[i] = string(s1);
      t2[i] = string(s2);
    }
    REP(i,2*n)REP(j,2*n) g[i][j]=INF;
    REP(i,2*n)g[i][i]=0;
    bool f = 1;
    map<string, int> mp;
    int num = 0;
    REP(i,n) {
      if (mp.count(t1[i]) == 0) mp[t1[i]] = num++;
      if (mp.count(t2[i]) == 0) mp[t2[i]] = num++;
      int a = mp[t1[i]];
      int b = mp[t2[i]];

      
      if (g[a][b] != INF) {
        if (g[a][b] != x[i]) {
          f = 0;
          break;
        }
      } else {
        g[a][b] = x[i];
        g[b][a] = -x[i];
        REP(i,num) {
          REP(j,num) {
            if (g[i][a] != INF && g[b][j] != INF) {
              g[i][j] = g[i][a] + g[a][b] + g[b][j];
              g[j][i] = -g[i][j];
            } else if (g[i][b] != INF && g[a][j] != INF) {
              g[i][j] = g[i][b] + g[b][a] + g[a][j];
              g[j][i] = -g[i][j];
            }
          }
        }
      } 
    //   REP(i,num) {
    //     REP(j,num) {
    //       if (g[i][j] == INF) cout << "*" << " ";
    //       else cout << g[i][j] << " ";
    //     }
    //     cout << endl;
    //   }
    //   cout << endl;
    }
    cout << (f?"Yes":"No") << endl;
  }
}

Measured memory_bytes: 1408
import numpy as np
w, h, n = map(int, input().split())
xya = [list(map(int, input().split())) for _ in range(n)]

field = [[1 for _ in range(w)] for _ in range(h)]

for x, y, a in xya:
        for i in range(h):
             for j in range(w):
                    if a == 1 and j < x:
                        field[i][j] = 0
                    if a == 2 and j >= x:
                        field[i][j] = 0
                    if a == 3 and i < y:
                        field[i][j] = 0
                    if a == 4 and i >= y:
                        field[i][j] = 0

print(sum(sum(np.array(field))))

Measured memory_bytes: 14420
def main():
    import sys
    from collections import Counter
    input = sys.stdin.readline

    N = int(input())
    A = sorted([int(a) for a in input().strip().split()])
    Acnt = Counter(A)
    if Acnt[1] == 1:
        print(1)
        return True
    elif Acnt[1] > 1:
        print(0)
        return True

    max_A = max(A)
    f = [True] * (max_A + 1)
    ans = 0
    for i in range(2, max_A + 1):
        if Acnt[i] > 0 and f[i]:
            if Acnt[i] == 1:
                ans += 1
            j = 1
            k = i
            while k <= max_A:
                f[k] = False
                j += 1
                k = i * j

    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 38328
import sys
from functools import lru_cache
def input(): return sys.stdin.readline().strip()
mod = 1000000007

class Combination:
    """
    O(n)の前計算を1回行うことで，O(1)でnCr mod mを求められる
    n_max = 10**6のとき前処理は約950ms (PyPyなら約340ms, 10**7で約1800ms)
    使用例：
    comb = Combination(1000000)
    print(comb(5, 3))  # 10
    """
    def __init__(self, n_max, mod=10**9+7):
        self.mod = mod
        self.modinv = self.make_modinv_list(n_max)
        self.fac, self.facinv = self.make_factorial_list(n_max)

    def __call__(self, n, r):
        return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n-r] % self.mod

    def make_factorial_list(self, n):
        # 階乗のリストと階乗のmod逆元のリストを返す O(n)
        # self.make_modinv_list()が先に実行されている必要がある
        fac = [1]
        facinv = [1]
        for i in range(1, n+1):
            fac.append(fac[i-1] * i % self.mod)
            facinv.append(facinv[i-1] * self.modinv[i] % self.mod)
        return fac, facinv

    def make_modinv_list(self, n):
        # 0からnまでのmod逆元のリストを返す O(n)
        modinv = [0] * (n+1)
        modinv[1] = 1
        for i in range(2, n+1):
            modinv[i] = self.mod - self.mod//i * modinv[self.mod%i] % self.mod
        return modinv

@lru_cache(maxsize=None)
def calc(n):
    """
    n個のものから隣り合わないように物をいくつか選択する場合の数(何も選ばないケースも許す)
    これは実はフィボナッチ数列になる
    """
    if n == -1: return 1
    if n == 0: return 1
    if n == 1: return 2
    return (calc(n - 1) + calc(n - 2)) % mod

@lru_cache(maxsize=None)
def func(h, w, k):
    if h == 0 and k == 1: return 1
    if h == 0: return 0
    if k == 1:
        val1 = func(h - 1, w, 1) * calc(w - 2) % mod
        val2 = func(h - 1, w, 2) * calc(w - 3) % mod
        return (val1 + val2) % mod
    if k == w:
        val1 = func(h - 1, w, w) * calc(w - 2) % mod
        val2 = func(h - 1, w, w - 1) * calc(w - 3) % mod
        return (val1 + val2) % mod
    val1 = func(h - 1, w, k - 1) * calc(k - 3) * calc(w - (k + 1)) % mod
    val2 = func(h - 1, w, k) * calc(k - 2) * calc(w - (k + 1)) % mod
    val3 = func(h - 1, w, k + 1) * calc(k - 2) * calc(w - (k + 2)) % mod
    return (val1 + val2 + val3) % mod

def main():
    H, W, K = map(int, input().split())
    if W == 1:
        print(1)
        return
    if W == 2:
        comb = Combination(H)
        if K == 1:
            ans = 0
            for i in range(H // 2 + 1): ans += comb(H, i * 2)
            print(ans)
        else:
            ans = 0
            for i in range(1, (H + 1) // 2 + 1): ans += comb(H, i * 2 - 1)
            print(ans)
        return
    print(func(H, W, K))
    

    




if __name__ == "__main__":
    main()


Measured memory_bytes: 42736
import sys

N,K=map(int, sys.stdin.readline().split())
X=[]
Y=[]
XY=[]

for _ in range(N):
	x,y=map(int, sys.stdin.readline().split())
	X.append(x)
	Y.append(y)
	XY.append( (x,y) )

ans=float("inf")
for x1 in X:
	for y1 in Y:
		for x2 in X:
			for y2 in Y:
				if x1<x2 and y1<y2:
					cnt=0
					for x, y in XY:
						if x1<=x<=x2 and y1<=y<=y2:
							cnt+=1
	
					menseki=abs(x1-x2)*abs(y1-y2)
					if K<=cnt:
						ans=min(ans, menseki)
			
print ans

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

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

    set <string> items;
    int n;
    cin >> n;
    string item;
    for(int i = 0; i < n; i++){
        cin >> item;
        items.insert(item);
    }
    cout << items.size();
    return 0;
}


Measured memory_bytes: 19184
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define INF 0x6fffffff
#define INFL 0x6fffffffffffffffLL

int main() {
	ll		a,b,c,h,i,j,k,l,m,n,x,y;
	ll		ans = 0;
	string	s;
	cin >> x;

	x = x / 200;
	ans = 10 - x;
	//vector<ll>	aa(n);
	//for(i=0;i<n;i++) cin >> aa[i];

	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3624
import java.util.*;

public class Main {
	
	/*
	 * default function
	 * */	
	int ni() {
		return cin.nextInt();
	}
	
	long nl() {
		return cin.nextLong();
	}
	
	String line() {
		return cin.nextLine();
	}
	
	void println(String str) {	
		System.out.println(str);
	}
	
	void print(String str) {
		System.out.print(str);
	}
	
	/*
	 * default variable
	 */
	
	static final int MOD = 1000000007;
	
	Scanner cin = new Scanner(System.in);	
	String  output;
	
	public static void main(String[] args) {			
		new Main().run();						
	}
	
	/* default above */		
	public void run() {
			
		input();
		/* 
		 * start
		 */	
		
		output = solve();
		
		/*
		 * finish
		 */
		
		
		println(output);
			
	}
	/* 
	 * define variable
	 */
	
	int N;
	String[] words;
	
	void input() {
		
		N = ni();
		words = new String[N];
		
		line();
		for (int i = 0; i < N; i ++) {
			words[i] = line();
		}
	}
	
	String solve() {
		
		int[] cnt1 = new int[26];
		int[] cnt2;
		
		//init
		for (char c: words[0].toCharArray()) {
			cnt1[c-'a'] ++;
		}
		
		for (int i = 1; i < N; i ++) {
			
			cnt2 = new int[26];
			for (char c: words[i].toCharArray()) {
				cnt2[c-'a'] ++;
			}
			
			for (int j = 0; j < 26; j ++) {
				if (cnt1[j] == 0) {
					continue;
				}
				
				cnt1[j] = Math.min(cnt1[j], cnt2[j]);
			}
		}
		
		
		StringBuilder res = new StringBuilder();
		
		for (int i = 0; i < 26; i ++) {
			
			if (cnt1[i] == 0) {
				continue;
			}
			
			for (int j = 0; j < cnt1[i]; j ++) {
				res.append((char)(i +'a'));
			}
		}
		
		return res.toString();
		
	}
	
}


Measured memory_bytes: 22740
#include <iostream>
#include <fstream>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <numeric>
using namespace std;
 
#define LOCAL  1
#define UPLOAD 2
 
#define ll long long
const long long INF = 1LL << 60;
 
template <class T = long long> T input(){T x;cin >> x;return x;}
template <class T> void output(T x){cout << x << endl;}
#define debug(x) cerr << #x<< ": " << x<< '\n';
#define debugBit(x,n) cerr << #x<< ": " << std::bitset<n>(x) << '\n';
#define REP(i,M) for(int i=0;i<M;i++)
 
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;}
ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
 
int main()
{
#if ENVIRONMENT == LOCAL
    std::ifstream in("input.txt");
    std::cin.rdbuf(in.rdbuf());
#endif
 
  ll N = input();
  ll sum = 0;
  for(int i=0;i<=N;i++){
    if(i % 3 && i % 5){
      sum += i;
    }
  }
 
  output(sum);
 
  return 0;
}

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

template<typename T>
istream& operator >> (istream& istr, vector<T>& vec){
    for(T& x: vec) istr >> x;
    return istr;
}

template<typename T>
ostream& operator << (ostream& ostr, vector<T>& vec){
    if(!vec.empty()){
        ostr << vec.front();
        for(auto itr = ++vec.begin(); itr != vec.end(); itr++)
            ostr << " " << *itr;
    }
    return ostr;
}

template<typename T>
ostream& operator << (ostream& ostr, vector<vector<T>>& mat){
    if(!mat.empty()){
        ostr << mat.front();
        for(auto itr = ++mat.begin(); itr != mat.end(); itr++)
            ostr << endl << *itr;
    }
    return ostr;
}

template<typename T, typename U>
ostream& operator << (ostream& ostr, pair<T,U>& p){
    ostr << p.first << " " << p.second;
    return ostr;
}

template<typename T, typename U>
ostream& operator << (ostream& ostr, vector<pair<T,U>>& mat){
    if(!mat.empty()){
        ostr << mat.front();
        for(auto itr = ++mat.begin(); itr != mat.end(); itr++)
            ostr << endl << *itr;
    }
    return ostr;
}

typedef long long ll;
typedef vector<ll> vll;
typedef vector<char> vc;
// vll x(n); x[i]=a;
typedef vector<vector<ll>> vvll;
typedef vector<vector<char>> vvc;
// vvll x(m,vi(n)); x[i][j]=a;
typedef pair<ll,ll> pll;
typedef vector<pair<ll,ll>> vpll;
// vpll x(n); x[i]={a,b}; x[i].first/second;

#define PI 3.1415926535897932
#define INF 1e+12
#define EPS 1e-12
#define REP(i,n) for(ll i=0; i<(n); i++)
#define RREP(i,n) for(ll i=(n)-1; i>=0; i--)
#define FOR(i,a,b) for(ll i=(a); i<(b); i++)
#define FORR(i,a,b) for(ll i=(b)-1; i>=(a); i--)
#define dump(x) cout << #x << " = " << (x) << endl
#define all(x) (x).begin(),(x).end()
// sort(all(x));

int main(){
    ll n, a, b, ans;
    cin >> n >> a >> b;
    ans = n/(a+b) * a;
    if(n%(a+b) >= a) ans+= a;
    else ans += n%(a+b);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main (){
    int N,Q,count=0;
    cin >> N >> Q;
    string s;
    cin >> s;
    vector<int> v(N+1,0);//累積和 要素数は一つ多くしておく
    //累積和を取っておくことで毎回カウントする代わりに累積和の差を取るだけで済む
    //累積和はきちんとメモしておくこと
    // 0 1 2 3 4 5 6 7
    
    // A C A C T A C G
    //0 0 1 1 2 2 2 3 3
    
    //0 1 2 3 4 5 6 7 8 
    
    for(int j=0;j<N-1;j++){
        if(s.at(j)== 'A'){
            if(s.at(j+1) == 'C'){
                count++;
            }               
        }
    v.at(j+2) = count;//最初の０と、Ｃが来るタイミングの分
    }//累積和計算
        
    int l,r;
    
    for(int i=0;i<Q;i++){
                cin >> l >> r;//l-1からr-1
                
            cout << v.at(r)-v.at(l) << endl;
    }
}



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

ll N;
string ans;

void dfs(ll &x, ll l, ll m, ll r, ll p) {
  if (l <= x && x <= r) {
    ans = "1";
    x -= p;
    return;
  }
  ll np = p * (-2);
  if (np > 0) {
    dfs(x, l, r, r+np, np);
  } else {
    dfs(x, l+np, l, r, np);
  }
  if (p > 0) {
    if (m < x && x <= r) {
      ans += "1";
      x -= p;
    } else {
      ans += "0";
    }
  } else {
    if (l <= x && x < m) {
      ans += "1";
      x -= p;
    } else {
      ans += "0";
    }
  }
}

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  cin >> N;
  if (N == 0) {
    cout << 0 << endl;
    return 0;
  }
  dfs(N, 0, 0, 1, 1);
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include<limits.h>
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(),v.end()
#define RALL(v) v.rbegin(),v.rend()
#define check(v) rep(i,v.size()) cout << v[i] << " ";\
cout << endl
#define INF 1e8
typedef long long ll;
using namespace std;
//オーバーフローに気をつけろよおおおおおお
//確認忘れるなよおおおおおお

int main() {
    int m, d; cin >> m >> d;
    int ans = 0;
    REP(i,1,m+1){
        REP(j,1,d+1){
            int a = j%10;
            int b = j/10;
            if(a>=2 && b>=2){
                if(a*b==i){
                    ans += 1;
                }
            }
        }
    }
    cout << ans << endl;

    return 0;
}

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

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

int main(void)
{
    ll x; cin>>x;
    ll ans=0,tmp=100;
    while(true){
        if(tmp>=x) break;
        tmp*=1.01;
        ++ans;
    }
    cout<<ans<<endl;
    return 0;
} 

Measured memory_bytes: 3612
#include <stdio.h>
long long solve(long long, long long);
long long pow2(long long);
long long a[5] = {0, 1, 2, 3, 3};
int main()
{
  long long n, x;
  scanf("%lld%lld", &n, &x);
  long long ans;
  ans = solve(n, x);
  printf("%lld\n",ans);
  return 0;
}
long long solve(long long n, long long x)
{
  if(x==0) return 0;
  if(n==0) return 1;
  long long st = pow2(n+1) - 1, ans;//每行面包 肉饼个数和 的一半 包括中间的
  if (n>=1)
  {
    if (x >= st){
      ans = pow2(n) + solve(n-1, x-st);
    }
    else{
      ans = solve(n-1, x-1);
    }
  }
  return ans;
}
long long pow2(long long n)
{
  long long x = 1;
  for (int i = 0; i < n; ++i)
    x *= 2;
  return x;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define x first
#define y second
#define dbg(x) cout << #x << '=' << x << '\n';
#define ll long long
#define pi pair<int,int>
#define pl pair<long long,long long>
#define lg length()
#define pb push_back
#define MAXN 100005
#define INF 1000000005
#define LINF 1000000000000000005

int a,b,c;

int32_t main(){
    ios_base :: sync_with_stdio(0); cin.tie(); cout.tie();
    cin >> a >> b >> c;
    if(a==b) cout << c;
    else if(a==c) cout << b;
    else cout << a;
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> VI;
 
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 (a>b) { a=b; return 1; } return 0; }
#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<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
const int mod=1e9+7;

int main(){
  int n;cin>>n;
  int n0=(1<<n);
  multiset<int> ideal;
  rep(i,n0){
    int tmp;cin>>tmp;
    ideal.insert(tmp);
  }
  vector<int> ans;
  auto ite=ideal.end();
  ans.push_back(*(--ite));ideal.erase(ite);
  rep(I,n){
    vector<int> children=ans;
    rep(i,ans.size()){
      int t=ans[i];
      auto it=ideal.lower_bound(t);
      if(ideal.begin()==it){
        cout<<"No"<<endl;exit(0);
      }
      it--;
      children.push_back(*it);
      ideal.erase(it);
    }
    swap(ans,children);
  }
  cout<<"Yes"<<endl;
}

Measured memory_bytes: 14200
import sys

def S(): return sys.stdin.readline().rstrip()
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())

A,B = LI()

ans = A-B-B
if ans <= 0:
    print(0)
else:
    print(ans)

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

#define REP(i, n, N) for(ll i=(n); i<(N); i++)
#define RREP(i, n, N) for(ll i=(N-1); i>=(n); i--)
#define LREP(lst,itr) for(auto itr = lst.begin(); itr != lst.end(); ++itr)
#define CK(n, a, b) ((a)<=(n)&&(n)<(b))
#define ALL(v) (v).begin(),(v).end()
#define MCP(a, b) memcpy(b,a,sizeof(b))
#define P(s) cout<<(s)<<endl
#define P2(a, b) cout<<(a)<<" "<<(b)<<endl
#define P3(a, b, c) cout<<(a)<<" "<<(b)<<" "<<(c)<<endl
#define V2(T) vector<vector<T>>
typedef long long ll;
using namespace std;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;

int main(){
    ll N,A,B;
    cin >> N >> A >> B;
    vector<ll> cities(N);
    REP(i,0,N){
        cin >> cities[i];
    }

    ll sum=0;
    REP(i,0,N-1){
        if(B>(cities[i+1]-cities[i])*A){
            sum+=(cities[i+1]-cities[i])*A;
        }else{
            sum+=B;
        }
    }
    P(sum);
}

Measured memory_bytes: 1024
#include "bits/stdc++.h"
	using namespace std;
	int main() {
		long long X, Y; cin >> X >> Y;
		if (Y % 2 != 0) cout << "No" << endl;
		else {
			for (long long i = 0; i <= X; i++) {
				if (i * 2 + (X - i) * 4 == Y) {
					cout << "Yes" << endl;
					return 0;
				}
			}
			cout << "No" << endl;
		}
	}


Measured memory_bytes: 3632
H, W = map(int, input().split())
if H%3 == 0 or H%3 == 0:
    ans = 0
else:
    ansl = [H] + [W] + [H*W] * 2
    if W%2 == 0:
        for i in range(1, H):
            tmp = abs(i * W - (H-i) * W // 2)
            if ansl[2] > tmp:
                ansl[2] = tmp
    else:
        for i in range(1, H):
            S1 = W * i
            S2 = (H-i) * (W//2)
            S3 = H*W - S1 - S2
            tmp = max(S1, S2, S3) - min(S1, S2, S3)
            if ansl[2] > tmp:
                ansl[2] = tmp
    if H == W:
        ansl[3] = ansl[2]
    elif H%2 == 0:
        for i in range(1, W):
            tmp = abs(i * H - (W-i) * H // 2)
            if ansl[3] > tmp:
                ansl[3] = tmp
    else:
        for i in range(1, W):
            S1 = H * i
            S2 = (W-i) * (H//2)
            S3 = H*W - S1 - S2
            tmp = max(S1, S2, S3) - min(S1, S2, S3)
            if ansl[3] > tmp:
                ansl[3] = tmp
    ans = min(ansl)
print(ans)


Measured memory_bytes: 3064
using System;

public class AtCoder
{
    public static void Main()
    {
        string[] t;
        t = NextS();
        string s = t[0];
        int n = 0;
        if (s.Substring(0,1) == "2") n++;
        if (s.Substring(1,1) == "2") n++;
        if (s.Substring(2,1) == "2") n++;
        if (s.Substring(3,1) == "2") n++;


        Console.WriteLine(n);
    }

    static void DebugWL(object x) { System.Diagnostics.Debug.WriteLine(x); }
    static string[] NextS() { return Console.ReadLine().Trim().Split(' '); }
}


Measured memory_bytes: 13140
n = int(input())

A = [ [] for i in range(n)]

for i in range(n):
  A[i] = list(map(int, input().split()))

B = [[ 0 for i in range(n)] for j in range(n)]

for i in range(n):
  a = A[i][0]
  j = A[i][1]
  if j != 0:
    for k in range(j):
      b = A[i][k+2]
      B[a-1][b-1] = 1

for i in range(n):
  print(" ".join(map(str, B[i])))


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

int main() {
  int64_t K,N;
  cin>>K>>N;
  vector<int64_t> a(N+1);
  for(int i=0;i<N;i++) {
    cin>>a[i];
  }
  a[N]=a[0]+K;
  int64_t x=0;
  for(int i=0;i<N;i++)
    x=max(x,a[i+1]-a[i]);
  cout<<K-x<<endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define F first
#define S second
#define forn(i, n) for (int i = 0; i < (int)n; i++)
#define pb push_back
#define fastIO ios::sync_with_stdio(0), cin.tie(0);
#define endl '\n'
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int, int> pii;

int main() {
#ifdef LOCAL
    // freopen("in.txt", "r", stdin);
    // freopen("out.txt", "w", stdout);
#else
    fastIO;
#endif
    string s;
    cin >> s;
    deque<char> p;
    forn(i, sz(s)) {
        if (s[i] == 'B') {
            if (p.empty()) continue;
            p.pop_back();
        } else {
            p.push_back(s[i]);
        }
    }
    for (auto x : p) {
        cout << x;
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long 
signed main(void){
    int H,W;
    cin >> H >> W;
    int Ans=810114514;
    int calc[3];
    calc[0]=((H+1)/3)*W;
    calc[1]=(int)(H-(int)((H+1)/3))*(int)(W/2);
    calc[2]=(int)((H-((H+1)/3))/2)*W;
    if(abs(calc[2]-H*W + calc[0] + calc[1])<abs(calc[1]-H*W + calc[0] + calc[1])){
        calc[1]=calc[2];
    }
    calc[2]=H*W - calc[0] - calc[1];
    //for(int i=0;i<3;i++){cout << calc[i] << " ";}cout << endl;
    sort(calc,calc+3);
    Ans=calc[2]-calc[0];
    
    calc[0]=((W+1)/3)*H;
    calc[1]=(int)(W-(int)((W+1)/3))*(int)(H/2);
    calc[2]=(int)((W-((W+1)/3))/2)*H;
    if(abs(calc[2]-H*W + calc[0] + calc[1])<abs(calc[1]-H*W + calc[0] + calc[1])){
        calc[1]=calc[2];
    }
    calc[2]=H*W - calc[0] - calc[1];
   // for(int i=0;i<3;i++){cout << calc[i] << " ";}cout << endl;
    sort(calc,calc+3);
    //cout << Ans << " " << calc[2]-calc[0] << endl;
    Ans=min(Ans,calc[2]-calc[0]);
    cout << Ans << endl;
    return 0;
}


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

#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)


int nCr(int n , int r ) {
	int p = 1, k = 1;

	if (n - r < r ) {
		r = n - r;
	}
	if (r != 0) {
		while (r != 0) {
			p *= n ;
			k *= r ;
			int m = __gcd(p, k);
			p /= m;
			k /= m;
			n--;
			r--;
		}
	}
	else {
		p = 1;
	}
	return p ;
}

void aryan_p() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	return;
}


int32_t main() {



	int r ;
	 cin>>r;

	 cout<<r*r;


	return 0;
}

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

int main() {
	// your code goes here
	int a,b;
	cin>>a>>b;
	
	if(a%3!=0 && b%3!=0 && (a+b)%3!=0) cout<<"Impossible"<<endl;
	else cout<<"Possible"<<endl;
	return 0;
}

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

// Z algorithm O(|S|)
vector<int> Z_algorithm(string s) {
  vector<int> Z(s.size());
  Z[0] = s.size();
  
  int i = 1, j = 0;
  while (i < s.size()) {
    while (i + j < s.size() && s[j] == s[i + j]) j++;
    Z[i] = j;
    if (j == 0) {
      i++;
      continue;
    }
    int k = 1;
    while (k < j && k + Z[k] < j) {
      Z[i + k] = Z[k];
      k++;
    }
    i += k;
    j -= k;
  }
  return Z;
}

// sのi文字目以降とtが何文字一致しているか
vector<int> cor_length(string s, string t) {
  vector<int> cor(s.size());
  vector<int> Z = Z_algorithm(t + s);
  for (int i = 0; i < s.size(); i++) {
    cor[i] = min((int) Z[i + t.size()], (int) t.size());
  }
  return cor;
}

// 隣接リストを用いた深さ優先探索（再帰ver.） O(|V|+|E|)
bool cycle = false;
vector<int> color(1e6, 0), d;

void dfs(const vector<vector<int>> &G, int u) {
  color[u] = 1; // GRAY
  int dist = 0;
  for (int i = 0; i < G[u].size(); i++) {
    if (color[G[u][i]] == 0) {
      dfs(G, G[u][i]);
      dist = d[G[u][i]] + 1;
    }
    else if (color[G[u][i]] == 1) {
      cycle = true;
      return;
    }
    else {
      dist = d[G[u][i]] + 1;
    }
  }
  color[u] = 2; // BLACK
  d[u] = dist;
  return;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  string tmp, t, s;
  cin >> tmp >> t;
  
  int len = max(t.size(), tmp.size()) * 2;
  while (s.size() < len) s += tmp;
  
  vector<int> cor = cor_length(s, t);
  
  vector<vector<int>> G(tmp.size());
  for (int i = 0; i < tmp.size(); i++) {
    if (cor[i] >= t.size()) G[i].emplace_back((i + t.size()) % tmp.size());
  }
  
  d.assign(tmp.size(), -1);
  for (int i = 0; i < tmp.size(); i++) {
    if (d[i] == -1) dfs(G, i);
  }
  
  if (cycle) {
    cout << -1 << '\n';
  }
  else {
    int ans = 0;
    for (int i = 0; i < tmp.size(); i++) ans = max(ans, d[i]);
    cout << ans << '\n';
  }
}

Measured memory_bytes: 68220