akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
const int inf = 1e9;
int dx[8] = {1, 1, 1, 0, 0,-1,-1,-1};
int dy[8] = {1, 0,-1, 1,-1, 1, 0,-1};
vector<vector<char> > field(21, vector<char>(17, '.'));
int solve(int sy, int sx){
    if(sy == 20 || (sy == 19 && 1 <= sx && sx <= 15)){
        return 0;
    }
    if(sy <= 0 || 20 <= sy || sx <= 0 || 16 <= sx){
        return inf;
    }
    int ret = inf;
    for(int i=0; i<8; i++){
        int ny = sy +dy[i];
        int nx = sx +dx[i];
        if(field[ny][nx] != 'X') continue;
        while(field[ny][nx] == 'X'){
            field[ny][nx] = '.';
            ny += dy[i];
            nx += dx[i];
        }
        ret = min(ret, solve(ny, nx));
        while(ny != sy || nx != sx){
            ny -= dy[i];
            nx -= dx[i];
            field[ny][nx] = 'X';
        }
        field[sy][sx] = '.';
    }
    return ret+1;
}

int main(){
    int sy, sx;
    for(int i=1; i<=19; i++){
        for(int j=1; j<=15; j++){
            cin >> field[i][j];
            if(field[i][j] == 'O'){
                sy = i;
                sx = j;
            }
        }
    }
    int ans = solve(sy, sx);
    if(ans >= inf){
        cout << -1 << endl;
    }else{
        cout << ans << endl;
    }
    return 0;
}



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

int a[10000];
int b[10000];

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
#ifdef LOCAL
	std::ifstream in("in");
	std::cin.rdbuf(in.rdbuf());
#endif

	int N;
	cin >> N;
	for(int i = 0; i < N; i++){
		cin >> a[i];
	}
	for(int i = 0; i < N; i++){
		cin >> b[i];
	}

	ll asum = 0, bsum = 0;
	for(int i = 0; i < N; i++){
		if(a[i] < b[i]){
			asum += (abs(a[i] - b[i]) + 1) / 2;
			if(abs(a[i] - b[i]) % 2) bsum++;
		}
		if(b[i] < a[i]){
			bsum += abs(a[i] - b[i]);
		}
	}
	cerr << asum << " " << bsum << endl;
	if(asum >= bsum) cout << "Yes" << endl;
	else cout << "No" << endl;
}


Measured memory_bytes: 384
#include <iostream>
#include <functional>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <queue>
#include <map>
#include <iomanip>
#include <complex>
#include <random>
#include <bitset>
#include <list>
// #include <prettyprint.hpp>
using namespace std;
#define repi(i,n) for(int i=0;i<n;++i)
#define rep(i,n) for(ll i=0;i<n;++i)
#define repinvi(i,n) for(int i=n-1;i>=0;--i)
#define sll(n) scanf("%lld", &n);
#define sii(n) scanf("%d", &n);
#define slf(n) scanf("%lf", &n);
#define pll pair<ll,ll>
#define pii pair<int,int>
#define psi pair<si,si>
typedef long long ll;
typedef double lf;
typedef short int si;


void Main(){
    ll N;
    cin >> N;
    map<ll,ll> counter;
    ll ans = 0;
    for(ll x=1;x*x<N;x++){
        for(ll y=1;y*y+x*x<N;y++){
            for(ll z=1;z*z+x*x+y*y<N;z++){
                ll v = x*x + y*y+z*z;
                v += (x*y + y*z+z*x);
                if(v<=N){
                    counter[v] ++;
                }
            }   
        }
    }
    rep(i, N){
        cout << counter[i+1] <<endl;
    }
}

int main(){
    Main();
}

Measured memory_bytes: 3752
# -*- coding: utf-8 -*-
from sys import setrecursionlimit
setrecursionlimit(100000)
 
class Cake():
 
    def __init__(self, N, W, D):
        self.P = [-1]*2*(N+1)
        self.L = [-1]*2*(N+1)
        self.R = [-1]*2*(N+1)
        self.W = [0]*2*(N+1)
        self.W[1] = W
        self.D = [0]*2*(N+1)
        self.D[1] = D
 
    def find(self, target):
        count = 0
        for i in range(1, 2*N+2):
            count += (self.L[i] == -1)
            if count == target:
                return i
 
    def cut(self, target, s, l):
        w = self.W[target]
        d = self.D[target]
        L = w+d
        s %= L
        if s <= w:
            nw, nW = s, w-s
            if nw > nW:
                nw, nW = nW, nw
            nd, nD = d, d
        else:
            s -= w
            nd, nD = s, d-s
            if nd > nD:
                nd, nD = nD, nd
            nw, nW = w, w
        assert 0 < nw
        assert 0 < nd
        r = l + 1
        self.L[target], self.R[target] = l, r
        self.P[l], self.P[r] = target, target
        self.W[l], self.W[r] = nw, nW
        self.D[l], self.D[r] = nd, nD
 
    def show(self):
        tmp = []
        for i in range(1, len(self.L)):
            if self.L[i] == -1:
                tmp.append(self.W[i] * self.D[i] )
        print(" ".join(map(str, sorted(tmp))))
 
N, W, D = map(int, input().split())
while W:
    cake = Cake(N, W, D)
    for i in range(N):
        p, s = map(int, input().split())
        target = cake.find(p)
        cake.cut(target, s, 2*(i+1))
    cake.show()
    N, W, D = map(int, input().split())


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

using namespace std;

typedef unsigned long long ull;
#define loop(i,a,b) for(int i=(a);i<ull(b);++i)
#define rep(i,n) loop(i,0,n)
#define all(a) (a).begin(), (a).end()

const double eps = 1e-10;
const double pi  = acos(-1.0);
const double inf = (int)1e8;

int main(){
	int n;
	cin >> n;
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	a--; b--; c--; d--;
	int ret = inf;

	for(int i = 1; i <= n; i++){
		ret = min(abs(a%i-b%i)+abs(a/i-b/i)+abs(c%i-d%i)+abs(c/i-d/i), ret);
	}
	cout << ret << endl;
}

Measured memory_bytes: 1160
//
//  main.cpp
//  CADDi_2018
//
//  Created by Joe Mori on 2020/06/30.
//  Copyright © 2020 Joe Mori. All rights reserved.
//

#include <iostream>
#include<vector>
#include<map>
#include<cmath>
int main() {
    long long int N,P,sub,ans;
    std::cin>>N>>P;
    ans=1;
//    std::vector<bool>is_prime(P,true);
//    is_prime[0]=is_prime[1]=false;
    sub=P;
    std::map <long long int ,long long int>yaku;
    if(N==1){
        std::cout<<P<<std::endl;
        return 0;
    }
    yaku[1]=N;
    for(long long int i=2;i*i<=P;i++){
//        std::cout<<i<<std::endl;
        while(sub%i==0){
            yaku[i]++;
            sub=sub/i;
//            std::cout<<"sub:"<<std::endl;
        }
        if(sub==1)break;
    }
    for(auto i:yaku){
        auto key=i.first;
        auto y=i.second;
        //std::cout<<"約数"<<key<<"個数"<<y<<std::endl;
        if(y>=N){
            for(int j=1;j<=y/N;j++){
                ans*=key;
            }
        }
    }
    std::cout<<ans<<std::endl;
    return 0;
}


Measured memory_bytes: 3600
def InS(): return input()


def InL(): return list(map(int, input().split()))


def InI(): return int(input())


A, B, K = InL()

if A >= K:
    print(A - K, B)
elif A + B >= K:
    print(0, B - (K-A))
else:
    print(0, 0)


Measured memory_bytes: 3060
#include <algorithm>
#include <cstdio>
#include <cstring>
#define L 16*9*5*7*11
int Q[25][25]; // d周期のi時間目の量
int T[L];
int main(){
	int N,d,t,q;
	for(;scanf("%d",&N),N;){
		memset(Q,0,sizeof(Q));
		for(int i=0;i<N;++i){
			scanf("%d%d",&d,&t);
			for(int j=0;j<d;++j){
				scanf("%d",&q);
				Q[d][(j+d-t)%d] += q;
			}
		}
		int sum=0;
		memset(T,0,sizeof(T));
		for(int d=1;d<=24;++d){
			if(d==13 || d==17 || d==19 || d==23 || d==1)
				sum+=*std::max_element(Q[d],Q[d]+d);
			else
				for(int i=0;i<L;++i)T[i]+=Q[d][i%d];
		}
		printf("%d\n",sum+*std::max_element(T,T+L));
	}
}

Measured memory_bytes: 1252
import java.util.Scanner;
public class Main {
	public static void main(String[] args) throws Exception{
		Scanner stdIn=new Scanner(System.in);
		int N=stdIn.nextInt();
		int M=stdIn.nextInt();
		long ans=1,n=N,m=M;
		if(N-M>=-1&&N-M<=1){
			while(N>0){
				ans*=N;
				ans=ans%1000000007;
				N--;
			}
			while(M>0){
				ans*=M;
				ans%=1000000007;
				M--;
			}
			if(n-m==0){
				ans*=2;
				ans%=1000000007;
			}
			System.out.println(ans);
		}
		else
			System.out.println(0);
	}
}

Measured memory_bytes: 23124
#include <bits/stdc++.h>
#include <iomanip>
#include <math.h>
//#include <unistd.h>
//#include <stdio.h>
#define rep(i,x) for(ll i = 0;i<x;i++)
#define all(a) (a).begin(),(a).end()
using ll = long long;
using ld = long double;
using namespace std;
using dou = double;
const ll INF = 1LL << 60;
const ll mod = 1000000007;
typedef pair<ll,ll> P;
using graph = vector<vector<ll>>;
template<class T> inline bool chmax(T& a, T b){if(a < b){a = b; return true;}return false;}
template<class T> inline bool chmin(T& a, T b){if(a > b){a = b; return true;}return false;}
ll gcd(ll a,ll b){
    if(a < b)swap(a,b);
    if(a % b == 0)return b;
    else return gcd(b,a%b);
}
bool isp(ll n){
    bool res = true;
    if(n == 1)return false;
    else{
        for(ll i = 2;i * i <= n;i++){
            if(n % i == 0){
                res = false;
                break;
            }
        }
        return res;
    }
}
const int MAX = 510000;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % mod;
        inv[i] = mod - inv[mod%i] * (mod / i) % mod;
        finv[i] = finv[i - 1] * inv[i] % mod;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}
/*
int main() {
    // 前処理
    COMinit();

    // 計算例
    cout << COM(100000, 50000) << endl;
}*/

//printf("%.10f\n", N);
/*
ll fibo(ll n){
    if(memo[n] != 0)return memo[n];
    if(n <= 1)return n;
    else return memo[n] = fibo(n - 1)+ fibo(n - 2);
}*/
/*  vector<ll> vec = {1,2,5,6,8,9,10};
    cout << binary_search(all(vec),5) << endl; -> true*/
/*
    vector<ll> vec = {1,2,5,6,8,9,10};
    auto n = upper_bound(all(vec),4);
    cout << *n << endl; -> 5*/
/*
    cout << fixed << setprecision(15);
*/
int main(){
    ll N,C,K;
    cin >> N >> C>>K;
    vector<ll> num(N);
    ll ans = 0;
    ll cnt = 0;
    rep(i,N)cin >> num[i];
    sort(all(num));
    ll limit = num[0] + K;
    rep(i,N){
        if(num[i] > limit){
            ans++;
            limit = num[i] + K;
            cnt = 1;
        }
        else if(cnt == C){
            limit = num[i] + K;
            ans++;
            cnt = 1;
        }
        else cnt++;
    }
    if(cnt)cout << ans + 1 << endl;
    else cout << ans << endl;
}

Measured memory_bytes: 1024
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include <queue>
#include <utility>
#include <map>
#include <set>
#include <deque>
#include <numeric>
using namespace std;

int main() {

    int X,t;
    cin >> X>>t;
    
    cout << ((X>t)?X-t:0) << endl;

    return 0;

}

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

int main()
{
	int a, b, c;
	scanf("%d %d %d", &a, &b, &c);
	if (a + b <= b + c && a + b <= c + a)
		printf("%d", a + b);
	else if (a + c <= a + b && a + c <= b + c)
		printf("%d", a + c);
	else
		printf("%d", b + c);

	return 0;
}

Measured memory_bytes: 256
/*
ID: zhaowei10
TASK:
LANG: C++14
*/
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

#ifdef LOCAL
string to_string(char c) { return string(1, c); }
string to_string(string s) { return '"' + s + '"'; }
string to_string(const char *s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
string to_string(vector<bool> v) {
  string res = "{";
  for (int i = 0; i < v.size(); ++i) {
    res += char('0' + v[i]);
  }
  res += "}";
  return res;
}
template <size_t N>
string to_string(bitset<N> b) {
  string res = "";
  for (int i = 0; i < N; ++i) {
    res += char('0' + b[i]);
  }
  return res;
}
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> t) {
  return "(" + to_string(get<0>(t)) + ", " + to_string(get<1>(t)) + ", " +
         to_string(get<2>(t)) + ")";
}
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> t) {
  return "(" + to_string(get<0>(t)) + ", " + to_string(get<1>(t)) + ", " +
         to_string(get<2>(t)) + ", " + to_string(get<3>(t)) + ")";
}
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += '}';
  return res;
}

void _debug() { cerr << '\n'; }
template <typename Head, typename... Tail>
void _debug(Head H, Tail... T) {
  cerr << ' ' << to_string(H);
  _debug(T...);
}
#define debug(...) cerr << '[' << #__VA_ARGS__ << "]:", _debug(__VA_ARGS__)
#else
#define debug(...) 0
#endif

#define eb emplace_back

using ll = long long;
using ld = long double;
using ii = pair<int, int>;
using vi = vector<int>;
using vii = vector<ii>;
using vc = vector<char>;
using vb = vector<bool>;
using vll = vector<ll>;

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

#ifdef LOCAL
  freopen("test.in", "r", stdin);
  freopen("test.out", "w", stdout);
#else
#endif

  int k;
  cin >> k;
  string s;
  cin >> s;
  cout << s.substr(0, min(k, (int)s.size()));
  if (s.size() > k) cout << "...";
}


Measured memory_bytes: 3104
#include<iostream>
using namespace std;
int main(){
  string input;
  cin>>input;
  for(int i=0;input[i]!='\0';i+=2){
    if(input[i]!='h'||input[i+1]!='i'){cout<<"No";return 0;}
  }
  cout<<"Yes";
  return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;


public class Main {

	public static void main(String[] args) {
		try {
			BufferedReader br = new BufferedReader(new InputStreamReader(
					System.in));

			String[] strs = (String[])br.readLine().split(" ");
			int num1 = Integer.parseInt(strs[0]);
			int num2 = Integer.parseInt(strs[1]);

			if(num1<num2){
				System.out.println("a < b");
			}else if(num1>num2){
				System.out.println("a > b");
			}else{
				System.out.println("a == b");
			}
		} catch (Exception e) {
			e.printStackTrace();
		}

	}

}

Measured memory_bytes: 17084
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

const ll MOD = 1e9 + 7;
const ll INF = 1e16;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); 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; }

void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}
//--------------------------------------------------------------------------------//

int main() {
    init();
    ll N, x;
    cin >> N >> x;
    ll un = 2 * N - 1;

    if(un==2&&x==2){
        cout << "Yes" << endl
             << 1 << endl
             << 2 << endl
             << 3 << endl;
        return 0;
    }else if(x==1||x==un){
        cout << "No" << endl;
        return 0;
    }
    cout << "Yes" << endl;

    ll li = 1, ri = 1;
    vc<ll> l = {x - 1}, r = {x + 1};
    if (x - 2 > 0) r.eb(x - 2), ri++;
    if (x + 2 <= un - 1) l.eb(x + 2), li++;
    queue<ll> q;
    repe(i, 1, x - 2) q.emplace(i);
    repe(i, x + 1 + li, un + 1) q.emplace(i);

    while(li<N-1){
        ll a = q.front();
        q.pop();
        l.eb(a);
        li++;
    }
    while(ri<N-1){
        ll a = q.front();
        q.pop();
        r.eb(a);
        ri++;
    }

    reverse(all(l));
    rep(i, N - 1) cout << l[i] << "\n";
    cout << x << "\n";
    rep(i, N - 1) cout << r[i] << "\n";
}

Measured memory_bytes: 4856
acgt = ['A', 'C', 'G', 'T']

s = list(input())

tmp = 0
ans = 0

for i in range(len(s)) :
    if acgt.count(s[i]) == 1 :
        tmp += 1
    else :
        tmp = 0
    
    if tmp > ans :
        ans = tmp

print(ans)

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

#define rep2(x,fr,to) for(int x=(fr);x<(to);x++)
#define rep(x,to) for(int x=0;x<(to);x++)
#define repr(x,fr,to) for(int x=(fr);x>=(to);x--)
#define all(c) c.begin(),c.end()
#define sz(v) (int)v.size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
typedef vector<ll> VL; const int MD = (int)1e9 + 7;
void dbg(){ cerr << "\n"; } template <typename T,typename ...T2> void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }
template <class T, class T2> void amax(T& a,T2 b){ if(a < b) a = b;}


int main()
{
	cin.tie(0); ios_base::sync_with_stdio(false);
	int n;
	cin >>n;
	VI d(n);
	VI a(n);
	rep(i, n) cin >>d[i];
	sort(all(d));

	int ans = d[n/2] - d[n/2 -1];
	cout << ans <<"\n";
	return 0;
}


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

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

int X;
vector<int> exps;

int main() {
  scanf("%d", &X);
  
  exps.push_back(1);
  int m = ceil(sqrt(X));
  FOR(i,2,m+1) {
    int buf = i;
    while (buf * i <= X) {
      buf *= i;
      exps.push_back(buf);
    }
  }

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

  printf("%d\n", exps[exps.size()-1]);
  return 0;
}

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

using namespace std;

using int64 = long long;

int main() {
  int N, X[200000];

  cin >> N;
  vector< int > vs;
  for(int i = 0; i < N; i++) {
    cin >> X[i];
    vs.emplace_back(X[i]);
  }
  sort(begin(vs), end(vs));
  int mex1 = vs[(N - 1) / 2];
  int mex2 = vs[(N + 1) / 2];
  for(int i = 0; i < N; i++) {
    if(X[i] <= mex1) cout << mex2 << endl;
    else cout << mex1 << endl;
  }
}


Measured memory_bytes: 3828
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define all(a) a.begin(), a.end()
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; }
using namespace std;
typedef long long ll;

int main(){

    int W, H;
    cin >> W >> H;

    vector<pair<ll, int>> vec(W + H);
    rep(i, W){
        cin >> vec[i].first;
        vec[i].second = 1;
    }
    rep(i, H){
        cin >> vec[i + W].first;
        vec[i + W].second = -1;
    }
    sort(all(vec));

    ll vert = H + 1, side = W + 1;
    ll ans = 0;
    rep(i, W + H){
        if(vec[i].second == 1){
            ans += vec[i].first * vert;
            side--;
        } else {
            ans += vec[i].first * side;
            vert--;
        }
    }

    cout << ans << endl;
    return 0;

}

Measured memory_bytes: 3328
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>

using namespace std;

int w, h;
int sx, sy;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int result;

bool isIn(int x, int y){
    return 0 <= x && x < h && 0 <= y && y < w;
}

int dfs(int x, int y, int direction, int count, vector<vector<int> > field){
    if(count >= result || 10 < count || !isIn(x, y)) return 100;
    else if(field[x][y] == 1) return 100;
    else if(field[x][y] == 3) return count;
    else {

        while(isIn(x, y) && field[x][y] == 0){
            x+=dx[direction]; y+=dy[direction];
        }
        if(!isIn(x, y)) return 100;
        else if(field[x][y] == 3) return count;
        else {
            x-=dx[direction]; y-=dy[direction];
            int result = 100;
            field[x+dx[direction]][y+dy[direction]] = 0;
            for(int i=0; i< 4; i++){
                int nx = x+dx[i], ny = y+dy[i];
                result = min(result, dfs(nx, ny, i, count+1, field));
            }
            return result;
        }
    }
}

int main(){
    while(cin >> w >> h, w+h){
        vector<vector<int> > field(h);
        for(int i=0; i< h; i++){
            for(int j=0; j< w; j++){
                int t; scanf("%d", &t); field[i].push_back(t);
                if(field[i][j] == 2){sx = i; sy = j; field[i][j] = 0;}
            }
        }
        result = 20;
        for(int i=0; i< 4; i++){
            result = min(result, dfs(sx+dx[i], sy+dy[i], i, 1, field));
        }
        cout << (result==20?-1:result) << endl;
    }
}

Measured memory_bytes: 1324
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define pb push_back
#define all(v) v.begin(), v.end()
#define bigger (char)toupper
#define smaller (char)tolower
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long long ll;
typedef unsigned long long ull;

int main() {
    int N; cin>>N;
    vi v(N);
    rep(i,N) {
        cin>>v[i];
    }
    bool ok=true;
    rep(i,N) {
        if(v[i]%2==1) continue;
        else if(v[i]%3!=0&&v[i]%5!=0) {
            ok=false;
            break;
        }
        else continue;
    }
    if(ok) cout<<"APPROVED"<<endl;
    else cout<<"DENIED"<<endl;
    
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
using namespace std;
int gcd(int x,int y)
{
	if(y==0)return x;
	return gcd(y,x%y);
}
int main()
{
	int n;
	scanf("%d",&n);
	long long ans=0;
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=n;j++)
		{
			for(int k=1;k<=n;k++)
			{
				ans+=gcd(i,gcd(j,k));
			}
		}
	}
	printf("%d\n",ans);
	return 0;
} 

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

int main(){
  ll a,b;
  cin >> a >> b;
  if(a>0&&b>0)cout << "Positive" << endl;
  else if(a<=0&&b>=0)cout << "Zero" << endl;
  else if(abs((a-b)%2)==1)cout << "Positive" << endl;
  else cout << "Negative" << 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 rep(i,a,b) for(int i=a;i<(b);++i)
# define p(s) std::cout << s ;
# define pl(s)  std::cout << s << endl;
# define printIf(j,s1,s2) cout << (j ? s1 : s2) << endl;
# define YES(j) cout << (j ? "YES" : "NO") << endl;
# define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
# define yes(j) std::cout << (j ? "yes" : "no") << endl;
# define all(v) v.begin(),v.end()
# define showVector(v) REP(i,v.size()){p(v[i]);p(" ")} pl("")
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;}
typedef long long int ll;
typedef pair<ll,ll> P_ii;
typedef pair<double,double> P_dd;

template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}

template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}

template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
  for(auto &e:t) fill_v(e,v);
}


const int MOD = 1000000007;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;

void addM(long long &a, long long b) {
    a += b;
    if (a >= MOD) a -= MOD;
}

void mulM(long long &a, long long b) {
    a = ((a%MOD)*(b%MOD))%MOD ;
}

const int MAX = 510000;
long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

vector<pair<long long, long long> > prime_factorize(long long n) {
    vector<pair<long long, long long> > res;
    for (long long p = 2; p * p <= n; ++p) {
        if (n % p != 0) continue;
        int num = 0;
        while (n % p == 0) { ++num; n /= p; }
        res.push_back(make_pair(p, num));
    }
    if (n != 1) res.push_back(make_pair(n, 1));
    return res;
}

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

    map<char,int> mp;
    REP(i,s.size()){
        mp[s[i]]++;
    }

    bool ans = true;
    for(auto m:mp){
        if(m.second != 2) ans = false;
    }

    Yes(ans)

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a[45000];
  int n,l;
  a[1]=1;
  for(int i=2;i<100000;i++){
    a[i]=a[i-1]+i;
    if(a[i]>1000000000){
      break;
    }
  }
  cin>>n;
  for(int i=1;i<45000;i++){
    if(n<=a[i]){
      l=i;
      break;
    }
  }
  for(int i=0;i<n-a[l-1];i++){
    cout<<")";
  }
  cout<<"(";
  for(int i=0;i<a[l]-n;i++){
    cout<<")";
  }
  for(int i=0;i<l-1;i++){
    cout<<"(";
  }
  cout<<endl;
  return 0;
}


Measured memory_bytes: 3272
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int h[] = new int[n];
		boolean heigher[] = new boolean[n];
		for(int i = 0; i < n; i++) {
			h[i] = sc.nextInt();
			heigher[i] = true;
		}

		for(int i = 0; i < m; i++) {
			int a = sc.nextInt();
			int b = sc.nextInt();

			if(h[a-1] < h[b-1]) {
				heigher[a-1] = false;
			}else if(h[b-1] < h[a-1]) {
				heigher[b-1] = false;
			}else {
				heigher[a-1] = false;
				heigher[b-1] = false;
			}
		}
		int ans = 0;
		for(int i = 0; i < n; i++) {
			if(heigher[i]) {
				ans++;
			}
		}
		System.out.println(ans);
	}

}

Measured memory_bytes: 59460
#include <bits/stdc++.h>
 
#define REP(i, x, n) for(int i = x; i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x.size())
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define uniq(x) x.erase(unique(x.begin(), x.end()), x.end())
#define F first
#define S second
#define mp make_pair
#define eb emplace_back
#define pii pair<int, int>
#define pll pair<ll, ll>
 
using namespace std;
 
typedef long long ll;

int main(){
	ll n, y;
	cin >> n >> y;
	
	rep(i, n + 1){
		for(int j = 0; j + i <= n; j++){
			if(1000*i + 5000*j + 10000*(n - i - j) == y){
				cout << n - i - j <<" "<< j <<" "<< i << endl;
				
				return 0;
			}
		}
	}
	
	cout <<"-1 -1 -1"<< endl;
	
	return 0;
}

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

#define		fuckshitup  ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0) // don't use for small inputs
#define		endl		"\n"
#define		ll			long long int
#define		mod			1000000007
#define		f(i,a,b)	for(ll i = (ll)(a); i < (ll)(b); i++)
#define		rf(i,a,b)   for(ll i = (ll)(a); i > (ll)(b); i--)
#define		ull			unsigned long long
#define		ld			long double

struct custom_hash{
    static uint64_t splitmix64(uint64_t x) {
    x += 0x9e3779b97f4a7c15;
    x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
    x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
    return x ^ (x >> 31);
}

size_t operator()(uint64_t x) const {
    static const uint64_t FIXED_RANDOM = std::chrono::steady_clock::now().time_since_epoch().count();
    return splitmix64(x + FIXED_RANDOM);
}
};

int main()
{
	fuckshitup;
    string s;
    cin >> s;
    if (s[0] == s[1] && s[1] == s[2] && s[0] == s[2])
    {
        cout << "No\n";
    }
    else
    {
        cout << "Yes\n";
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define op_io ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define fo(i,a,b) for(int i=a;i<b;i++)
#define maxn 105
using namespace std;
typedef vector<int> vi;

long long inp[maxn][2];

long long solve(int n, long long W){
  long long res[n+1][W+1];
  fo(i,0,n+1){
    fo(j,0,W+1){
      if(i == 0 || j == 0){
	res[i][j] = 0;
      }else if(inp[i-1][0] <= j){
	res[i][j] = max(inp[i-1][1] + res[i-1][j-inp[i-1][0]], res[i-1][j]);
      }else{
	res[i][j] = res[i-1][j];
      }
    }
  }
  return res[n][W];
}

int main(){
  op_io;
  int n;
  long long w;
  cin>>n>>w;
  fo(i,0,n){
    cin>>inp[i][0]>>inp[i][1];
  }
  cout<<solve(n,w)<<endl;
  return 0;
}


Measured memory_bytes: 79104
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
#define int long long
signed main() {
	int n, k; cin >> n >> k; k--;
	int a[114514]; for (int i = 0; i < n; i++)cin >> a[i]; sort(a, a + n);
	int ans = a[k] - a[0];
	for (int i = 1; i < n - k; i++) 
		ans = min(ans, a[i + k] - a[i]);
	cout << ans << endl;
}

Measured memory_bytes: 1024
import java.util.Scanner;
public class Main {
	static Scanner scan=new Scanner(System.in);
	static int gcd (int a, int b) {return b>0?gcd(b,a%b):a;}
	static long lcm (int a, int b) {return a*b/gcd(a,b);}
	static int max(int a,int b) {return a>b?a:b;}
	static int min(int a,int b) {return a<b?a:b;}
	static long factorial(int i) {return i==1?1:i*factorial(i-1);}
	static int lower_bound(int a[],int key) {
		int low=0,high=a.length;
		while(low<high) {
			int mid=((high-low)/2)+low;
			if(a[mid]<=key)low=mid+1;
			else high=mid;
		}
		return high;
		}
	static int upper_bound(int a[],int key) {
		int low=0,high=a.length;
		while(low<high) {
			int mid=((high-low)/2)+low;
			if(a[mid]<key)low=mid+1;
			else high=mid;
		}
		return high;
		}
	static boolean isPrime (int n) {
		if (n==2) return true;
		if (n<2 || n%2==0) return false;
		double d = Math.sqrt(n);
		for (int i=3; i<=d; i+=2)if(n%i==0){return false;}
		return true;
	}
	static int upper_division(int a,int b) {
		if(a%b==0) {
			return a/b;
		}
		else {
			return a/b+1;
		}
	}
	static long lupper_division(long a,long b) {
		if(a%b==0) {
			return a/b;
		}
		else {
			return a/b+1;
		}
	}
	static long lmax(long a,long b) {return Math.max(a, b);}
	static long lmin(long a,long b) {return Math.min(a, b);}
	static int[] setArray(int a) {
		int b[]=new int[a];
		for(int i=0;i<a;i++) {
			b[i]=scan.nextInt();
		}
		return b;
	}
	public static void main(String[] args) {
		String str=scan.next();
		long cnt=0;
		long ans=0;
		for(int i=0;i<str.length();i++) {
			char ch=str.charAt(i);
			if(ch=='W') {
				ans+=i-cnt;
				cnt++;
			}
		}
		System.out.println(ans);
	}
}

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

signed main(void)
{
	ll k, a, b, cnt;
	cin >> k >> a >> b;
	k -= a;
	if (k <= 0)
		cnt = 1;
	else
	{
		if (a > b)
		{
			cnt = k / (a - b);
			if (k % (a - b) != 0)
				cnt++;
			cnt *= 2;
			cnt++;
		}
		else
			cnt = -1;
	}
	cout << cnt << endl;
	return 0;
}


Measured memory_bytes: 256
import fractions
N=int(input())
A=list(map(int,input().split()))
x=0
ans=A[0]
for i in range(1,N):
  ans=ans*A[i]//fractions.gcd(ans,A[i])
for i in range(N):
  x=x+ans//A[i]
print(ans/x)

Measured memory_bytes: 5688
#include <stdio.h>
#define N 100000
int main() {
  int n,i,j,A[N],key,smallf=0,bigf=0,cnt;
  scanf("%d",&n);
  for(i=0;i<n;i++)scanf("%d",&A[i]);
  key=A[n-1];
  j=0;
  for(i=0;i<n-1;i++){
    if(A[i]<=key){
      cnt=A[i];
      A[i]=A[bigf];
      A[bigf]=cnt;
      bigf++;
    }
    else;
  }
  for(i=0;i<n;i++){
    if(i==bigf){
      cnt=A[bigf];
      A[bigf]=A[n-1];
      A[n-1]=cnt;
      printf(" [%d]",A[i]);
      continue;
    }
    if(i>0)printf(" ");
    printf("%d",A[i]);
  }
  printf("\n");
  return 0;
}



Measured memory_bytes: 2128
#include <iostream>
#include <list>
#include <algorithm>

int n;
std::list<int> b;
bool isOdd;

int main(int argc, char *argv[])
{
    std::cin >> n;
    isOdd = n % 2;
    int tmp;
    for(int i = 0; i < n; i++){
        std::cin >> tmp;
        if(isOdd){
            b.push_front(tmp);
        }
        else{
            b.push_back(tmp);
        }
        isOdd = !isOdd;
    }
    for(auto itr = b.begin(); itr != b.end(); itr++){
        std::cout << ' ' << *itr;
    }
    return 0;
}


Measured memory_bytes: 8448
use std::collections::HashMap;

fn main() {
    let nk = read_vec::<usize>();
    let _ = nk[0];
    let k = nk[1];
    let v = read_vec::<usize>();
    let mut map: HashMap<usize, usize> = HashMap::new();
    for a in v.into_iter() {
        let entry = map.entry(a).or_insert(0);
        *entry += 1;
    }

    let mut v: Vec<usize> = map.values().into_iter().map(|e| *e).collect();
    v.sort();

    let mut n = v.len();
    let mut cnt = 0;
    let mut i = 0;
    while n > k {
        cnt += v[i];
        i += 1;
        n -= 1;
    }
    println!("{}", cnt);
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().split_whitespace().map(|e| e.parse().ok().unwrap()).collect()
}


Measured memory_bytes: 18060
#include <iostream>
#include <vector>
#include <algorithm>
#include <unordered_map>
#include <string>
#include <queue>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

using namespace std;
int x[90001] = { 0 };
int y[90001] = { 0 };
int cost[90001] = { 0 };

int main()
{
    int H, W,D;
    cin >> H >> W >> D;

    REP(i, H) {
        REP(j, W) {
            int aij;
            cin >> aij;
            x[aij] = i;
            y[aij] = j;
        }
    }

    REP(i, H*W+1) {
        if (i <= D) {
            cost[i] = 0;
        }
        else {
            cost[i] = cost[i - D] + abs(x[i]-x[i-D])+abs(y[i]-y[i-D]);
        }
    }
    int Q;
    cin >> Q;
    REP(i, Q) {
        int L, R;
        cin >> L >> R;
        cout << cost[R] - cost[L] << endl;
    }

    return 0;
}

Measured memory_bytes: 2176
#include <iostream>
#include <cstring>
#include <cmath>
#include <vector>
#include <algorithm>

using namespace std;

int a[32];

int main()
{
    int k;
    a[0] = a[1] = a[2] = a[4] = a[6] = a[10] = a[12] = a[14] = a[16] = a[18] = a[22] = a[28] = a[30] = 1;
    a[3] = a[5] = a[8] = a[9] = a[13] = a[20] = a[21] = a[24] = a[25] = 2;
    a[7] = a[11] = a[17] = a[19] = a[26] = 5;
    a[27] = a[29] = 4;
    a[15] = 14;
    a[23] = 15;
    a[31] = 51;
    
    cin >> k;
    cout << a[k-1] << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define debug(x) cerr << #x << ':' << x << endl
#define REP(i,n) for(int i=0;i<(int)n;++i)
#define ALL(c) (c).begin(), (c).end()
using namespace std;
typedef long long ll;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;

    int cnt=0;
    for(int i=1; i<=n; i++){
        string s = to_string(i);
        if(s.size()%2==1){
            cnt++;
        }
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;

int main()
{
    ll n;
    cin >> n;
    n++;
    vector<int> ans;
    int k = 0, l;
    if(n & 1) k++;
    for(l = 1; l < 100; l++){
        if((1ll << l) > n) break;
        if((n >> l) & 1) k++;
        ans.push_back(l);
    }
    int j;
    for(j = l; j < l + k - 1; j++){
        ans.push_back(j);
    }
    j--;
    for(int i = 0; i < l - 1; i++){
        if((n >> i) & 1){
            ans.push_back(j);
            j--;
        }
        ans.push_back(i + 1);
    }
    cout << (int)ans.size() << endl;
    for(int x : ans) cout << x << " ";
    cout << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#define N 50
using namespace std;
struct data{
  string l;
  int p,a,b,c,d,e,f,s,m;
  double cal;
};
int main(){
  int n,i,j,time;
  struct data d[N];
  while(1){
    cin >> n;
    if(n==0) break;
    for(i=0;i<n;i++){
      cin >> d[i].l >> d[i].p >> d[i].a >> d[i].b >> d[i].c;
      cin >> d[i].d >> d[i].e >> d[i].f >> d[i].s >> d[i].m;
      time=(d[i].a+d[i].b+d[i].c+d[i].d+d[i].e);
      d[i].m--;
      time+=(d[i].d+d[i].e)*d[i].m;
      d[i].cal=((double)d[i].f*d[i].s*(d[i].m+1)-d[i].p)/time;
    }
    for(i=0;i<n;i++){
      for(j=1;j<n;j++){
    if(d[j].l<d[j-1].l) swap(d[j],d[j-1]);
      }
    }
    for(i=0;i<n;i++){
      for(j=1;j<n;j++){
    if(d[j].cal>d[j-1].cal) swap(d[j],d[j-1]);
      }
    }
    for(i=0;i<n;i++) cout << d[i].l << endl;
    cout << '#' << endl;
  }
  return 0;
}

Measured memory_bytes: 1212
object Main {
  def judge(ret: Boolean, ok: String, ng: String): Unit = if (ret) println(ok) else println(ng)

  def main(args: Array[String]): Unit = {
    val sc = new java.util.Scanner(System.in)
    val a, b = sc.nextInt

    val ret = if (a % 2 == 1 && b % 2 == 1) true else false

    judge(ret, "Odd", "Even")
  }
}


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

#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) cin>>aa;(p).push_back(aa);
#define vecpl2(p) long long a	b;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define set0(k,n) for(int nn=0;nn<(n);nn++){ (k).push_back(0); }
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define vecsize(b,size) vector<int> (b)((size));
#define pb(b,a) (b).push_back((a));
#define doublece(a,b) cout<<(a)<<' '<<(b)<<endl;
#define pairs(s) vector<pair<int,int>> (s);
#define pairsl(s) vector<pair<ll,ll>> (s);
#define pairss(s) vector<pair<string,string>> (s);
#define pairsp(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairspl(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsps(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsREV(s) (s).push_back(make_pair(bb,aa));
#define pairslREV(s) (s).push_back(make_pair(bb,aa));
#define pairssREV(s) (s).push_back(make_pair(bb,aa));
#define MOD 1000000007

int main()
{

	int N, A, B;
	cin >> N >> A >> B;
	string S;
	cin >> S;
	int sum = 0,count = 0;
	fx(N) {
		if (S[x]=='a') {
			if (sum < A + B) {
				ce("Yes")
				sum++;
			}
			else {
				ce("No")
			}
		}
		else if(S[x]=='b'){
			if (sum<A+B) {
				if (count<B) {
					ce("Yes")
					sum++;
					count++;
				}
				else {
					ce("No")
				}
			}
			else {
				ce("No")
			}
		}
		else {
			ce("No")
		}
	}
    return 0;
}



Measured memory_bytes: 896
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String[] str1 = sc.nextLine().split(" ");
    String[] str2 = sc.nextLine().split(" ");
    int x = Integer.parseInt(str1[0]);
    int n = Integer.parseInt(str1[1]);
    if(n==0) {
        System.out.println(x);
    }
    else {
        List<String> list = new ArrayList<String>();
        for(int i = -1 ; i < 102;i++) {
          list.add((((Integer)i).toString()));
        }
        for(int i = 0 ; i < str2.length;i++) {
            list.remove (str2[i]);
        }
        int cnt=9999;
        int ansX=9999;
        for(String num2 : list) {
            int num = Integer.parseInt(num2);
            if(Math.abs(num-x) <cnt) {
                cnt = Math.abs(num-x);
                ansX = num;
            }
        }
        System.out.println(ansX);
    }
  }
}

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

const int m = 2019;

int main() {
  string s;
  cin >> s;
  int n = s.size();
  reverse(s.begin(), s.end());
  int x = 1, tot = 0;
  vector<int> cnt(m);
  ll ans = 0;
  rep(i,n) {
    cnt[tot]++;
    tot += (s[i]-'0')*x;
    tot %= m;
    ans += cnt[tot];
    x = x*10%m;
    //printf("x:%d tot:%d\n",x, tot);
  }
  cout << ans << endl;
  return 0;
}


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

/* define const */

/* end up defineing const */

int n;
long a[100010];
long x;

int main()
{
  cin >> n >> x;
  for (int i = 0; i < n; i++) cin >> a[i];
  // input

  long cnt = 0;
  for (int i = 1; i < n; i++) {
    /*
    while (a[i] + a[i-1] > x) {
      cnt += 1;
      if (a[i] <= 0) {
	a[i-1] -= 1;
      }
      else {
	a[i] -= 1;
      }
    }
    */

    if (a[i] + a[i-1] > x) {
      int sub = a[i] + a[i-1] - x;
      cnt += sub;
      if (a[i] < sub) {
	a[i-1] -= (sub - a[i]);
	a[i] = 0;
      }
      else {
	a[i] -= sub;
      }
      /*
      cout << ":";
      for (int j = 0; j < n; j++) cout << a[j] << " ";
      cout << endl;
      */
    }

  }
  cout << cnt << endl;
}


Measured memory_bytes: 1024
n = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
ans = 0
for i in range(n):
    if b[i] >= a[i]:
        ans += a[i]
        b[i] -= a[i]
        a[i] = 0
    else:
        ans += b[i]
        a[i] -= b[i]
        b[i] = 0
    if b[i]:
        if b[i] >= a[i+1]:
            ans += a[i+1]
            a[i+1] = 0
            b[i] -= a[i+1]
        else:
            ans += b[i]
            a[i+1] -= b[i]
            b[i] = 0
print(ans)

Measured memory_bytes: 19004
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

long long n, k;

int main() {
    cin >> n >> k;
    long double ans = 0.0;
    for(int i = 1; i <= n; ++i) {
        long long check = i;
        // cnt回表を連続で出す必要がある
        long long cnt = 0;
        while(check < k) {
            cnt++;
            check *= 2;
        }
        long double chans = 1.0 / (long double)n;
        long double pcnt = powl(0.5, (long double)cnt);
        chans *= pcnt;
        ans += chans;
    }

    cout << setprecision(14) << ans << endl;
}

Measured memory_bytes: 512
N = int(input())
H = list(map(int, input().split(' ')))
I = []
for i in range(N-1):
  I.append(H[i]-H[i+1])
a = 0
A = []
for j in range(N-1):
  if I[j] >= 0:
    a += 1
  else:
    A.append(a)
    a = 0
A.append(a)
print(max(A))

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

#define ll long long
#define vi vector<int>
#define vll vector<long long>
#define si set<int>
#define stk stack<int>
#define que queue<int>
#define pb push_back
#define ff first
#define ss second
#define pii pair<int,int>
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

using namespace std; 

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

	int n=s.size(),ans=0;
	for(int i=0;i<n/2;i++){
		if(s[i]!=s[n-i-1])
			ans++;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h> //C++の標準ライブラリを一行で一括でインクルードする
#include <math.h> //数学関数と数学定数を利用する
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;


int main(){
  int n;
  cin >> n;
  vector<string> w(n);
  
  rep(i,n) cin >> w[i];
  map<string,int> mp;
  
  char last = w[0][0];
  rep(i,n){
    string a = w[i];
    if (last != a[0] || mp[a] > 0){ //もし最後の言葉と頭が同じじゃなかったり、前に言った言葉だったら
      cout << "No";
      return 0;
    }
    
    last = a[a.size() -1]; //最後の言葉を記録
    mp[a]++;
  }
  
  cout << "Yes";
  
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
  int a,j,v,N,count=0;
  int A[100];

  scanf("%d",&N);
  for(a=0;a<=N-1;a++)scanf("%d ",&A[a]);
  for(a=1 ;a<=N-1 ;a++){
    v = A[a];
    j = a-1;
    while(j >= 0 && A[j] > v){
      A[j+1] = A[j];
      j--;
      A[j+1] = v;
      count++;
    }
  }
  for(a=0 ;a<=N-2 ;a++)printf("%d ",A[a]);
  printf("%d\n",A[a]);
  printf("%d\n",count);
  return 0;
}



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

using namespace std;

typedef long long ll;

int main(){
	string s;
	cin >> s;
	int ans = 0,n = s.size();
	for (int i = 0; i < n / 2; i++){
		if(s[i] != s[n - 1 - i]){
			ans++;
		}
	}
	cout << ans;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
    using namespace std;
    
    int main(){
        long x , a , b;
        cin >> x >> a >> b;
        a = abs(x-a);
        b = abs(x-b);
        if(a <= b ){
            cout << "A" << endl;
        }else{
            cout << "B" << endl;
        }
        
        return 0;
    }

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

int main()
{
   int h,n;
   int a[100000];
   int i;
   int sum=0;
   scanf("%d %d",&h,&n);
   for (i=0;i<n;i++)
    scanf("%d",&a[i]);
   
   for (i=0;i<n;i++)
    sum=sum+a[i];
   
   if (sum<h)
    printf("No\n");
   else
    printf("Yes\n");
    return 0;
}


Measured memory_bytes: 512
/*
	************	************    ************	***      ***	************	***               ***
	************	************    ************	****     ***	************	 ***             ***
	***      ***	***      ***    ***      ***	*****    ***	***      ***	  ***           ***
	***      ***	***      ***    ***      ***	******   ***	***      ***	   ***         ***
	************	************    ************	*** ***  ***	************	    ***       ***
	************	************    ************	***  *** ***	************	     ***     ***
	***				***   ***       ***      ***	***   ******	***      ***	      ***   ***
	***				***    ***      ***      ***	***    *****	***      ***	       *** ***
	***				***     ***     ***      ***	***     ****	***      ***	        *****
	***				***      ***    ***      ***	***      ***	***      ***	         ***
*/

#define named(blockname) goto blockname; \
                         blockname##_skip: if (0) \
                         blockname:

#define break(blockname) goto blockname##_skip
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define readarr(a,n) for (int i=0; i<n; i++) {cin>>a[i];}
#define printarr(a,n) for (int i=0; i<n; i++) {cout<<a[i]<<' ';}
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define vint vector <int>
#define pb push_back
#define pf push_front
#define endl "\n"

ll maxSubArraySum(ll a[], ll size) 
{ 
	// ll max = 0 ;
	ll m = 0 ;
    ll max_so_far = INT_MIN, max_ending_here = 0; 
  
    for (ll i = 0; i < size; i++) 
    { 
    	m = max(a[i],m) ;
        max_ending_here = max_ending_here + a[i]  ; 
        if (max_so_far < max_ending_here) 
            max_so_far = max_ending_here; 
  
        if (max_ending_here < 0) {
            max_ending_here = 0; 
            max_so_far -= m ;
            m = 0 ;
        }
    } 
    // cout << max_so_far ;
    return max_so_far; 
}

signed main() {
	
	fast ;
	
	ll q ;
	q = 1 ;
	// cin >> q ;
	while (q--)
	{
		ll a,b,c,d,e ;
		cin >> a>>b>>c>>d>>e ;
		// ll a[n] ;
		// readarr(a,n) ;
		// maxSubArraySum(a, n);
		cout << (c-a)*60+d-b-e ;
	}
	
	return 0;
}

Measured memory_bytes: 3648
#include<iostream>
#include<queue>
using namespace std;
     
const int INF=100000000;
     
char maze[20][20];
int w, h;
int sx, sy;
int cnt;
     
int d[20][20];
     
int dx[4]={1, 0, -1, 0}, dy[4]={0, 1, 0, -1};
     
     
int bfs(){
  queue< pair<int, int> > que;
     
  for(int i=0;i<h;i++) for(int j=0;j<w;j++) d[i][j]=INF;
     
  que.push(pair<int, int>(sy, sx));
  d[sy][sx]=0;
     
  while(que.size()){
    pair<int, int> p=que.front();
    que.pop();
     
    for(int i=0;i<4;i++){
      int ny=p.first+dy[i], nx=p.second+dx[i];
     
      if(0<=ny&&ny<h&&0<=nx&&nx<w&&maze[ny][nx]!='#'&&d[ny][nx]==INF){
	que.push(pair<int, int>(ny, nx));
	d[ny][nx]=d[p.first][p.second]+1;
	cnt++;
      }
    }
  }
  return cnt+1;
}
     
int main(){
     
  while(cin>>w>>h, w){
  
    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
	cin>>maze[i][j];
	if(maze[i][j]=='@'){
	  sy=i;
	  sx=j;
	}
      }
    }
    cnt=0;
    int res=bfs();
     
    cout<<res<<endl;

  }
     
  return 0;
}

Measured memory_bytes: 3108