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

int gcd(int a, int b) {
  if (b == 0) return a;
  else return gcd(b, a % b);
}

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

  int ans = A[0];
  for (int i = 0; i < N; i++) {
    ans = gcd(A[i], ans);
  }
  
  cout << ans << endl;
}


Measured memory_bytes: 640
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from bisect import bisect

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

H, W = MAP()

a = [LIST() for _ in range(H)]

op = []
for i in range(H):
	for j in range(W-1):
		if a[i][j]%2 != 0:
			a[i][j+1] += 1
			a[i][j] -= 1
			op.append([i+1, j+1, i+1, j+2])

for i in range(H-1):
	if a[i][-1]%2 != 0:
		a[i+1][-1] += 1
		a[i][-1] -= 1
		op.append([i+1, W, i+2, W])

print(len(op))
print(*[" ".join(map(str, x)) for x in op], sep="\n")


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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define INF INT_MAX/3

bool sorter(const P& a,const P& b){
  return a.fi<b.fi;
}

int n;
string s[111];
vector<P> ps[2];

int main(){
	cin.sync_with_stdio(false);
  cin>>n;
  rep(i,n)cin>>s[i];
  rep(i,n){
    int l=0,r=0;
    stack<char> st;
    rep(j,s[i].size()){
      if(s[i][j]=='(')st.push(s[i][j]);
      else{
        if(st.size()>0)st.pop();
        else l++;
      }
    }
    r=st.size();
    if(r-l>=0)ps[0].push_back(P(l,r));
    else ps[1].push_back(P(r,l));
  }
  sort(all(ps[0]),sorter);
  sort(all(ps[1]),sorter);
  int suma=0,sumb=0;
  rep(i,ps[0].size()){
    if(suma<ps[0][i].fi){
      cout<<"No"<<endl;
      return 0;
    }
    suma+=ps[0][i].se-ps[0][i].fi;
  }

  rep(i,ps[1].size()){
    if(sumb<ps[1][i].fi){
      cout<<"No"<<endl;
      return 0;
    }
    sumb+=ps[1][i].se-ps[1][i].fi;
  }
  if(suma==sumb){
    cout<<"Yes"<<endl;
  }else cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 3272
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
#include <stdio.h>
#include <ctype.h>
#include <random>
#include <string.h>
#include <cmath>
#include <unordered_map>
#include <cstdio>
using namespace std;
#define pie 3.141592653589793238462643383279
#define int long long
#define P pair<int,int>
#define all(vec) vec.begin(),vec.end()

int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}
int kai(int x, int y, int m) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= m;
	}
	return res;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}

int comb(int x, int y, int m) {
	if (y > x)return 0;
	return kai(x, y, m) * mod_pow(kai(y, y, m), m - 2, m) % m;
}

int g(int a, int k) {
	if (a%k == 0)return a / k;
	int s = a / k;
	a = k * s + (a + k) % (s + 1);
	if (a%k == 0)return a / k;
	return g(a - s - 1, k);
}

int n;
int cnt;
int x;

signed main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		int a, k; cin >> a >> k;
		x ^= g(a, k);
	}
	if (x)cout << "Takahashi" << endl;
	else cout << "Aoki" << endl;
}

Measured memory_bytes: 256
n=int(input())
member=[0]*(n+1)
count=0
a=list(map(int,input().split()))
for i in range(1,a[0]+1):
    member[a[i]]+=1
b=list(map(int,input().split()))
for i in range(1,b[0]+1):
    member[b[i]]+=2
c=list(map(int,input().split()))
for i in range(1,c[0]+1):
    member[c[i]]+=4
for i in member:
    if i==4 or i>5:count+=1
print(count)


Measured memory_bytes: 5600
#!/usr/bin/env python3
import sys


def solve(N: int, K: int):
    N = N % K
    if N > K // 2:
        print(K - N)
    else:
        print(N)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    solve(N, K)

if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
d={}
r=[input() for _ in range(int(input()))]
for _ in range(int(input())):
  a=input()
  if a in r:
    r.pop(r.index(a))
for i in r:
  if i not in d:
    d[i] = 1
  else:
    d[i] += 1
d=sorted(d.items(),key=lambda x:-x[1])
print([0,d[0][1]][d[0][1]>0] if d else 0)

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

int main() {
    string s;
    cin >> s;
    int zb = 0;
    for (int i = 0; i < s.size(); i++) {
        zb += s[i] - '0';
        zb %= 9;
    }

    if (zb == 0) {cout << "Yes";}
    else {cout << "No";}

}



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

int main(){
  int a[5];
  for (int i; i<5; i++) cin >> a[i];
  int ans = 0;
  for (int i; i<5; i++) ans += (a[i]+9)/10;
  ans = ans*10;
  int res=10;
  for (int p:a){
    if(p%10!=0)
    res =min(res,p%10);
  }
  if (res==10) ans = ans;
  else ans = ans-10+res;
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
  int i, j;
  int h, w;

  while(1){
    scanf("%d %d", &h, &w);

    if(h == 0 && w == 0) break;
  
    for(i = 0; i < h; i++){
      for(j = 0; j < w; j++){
	printf("#");
      }
      printf("\n");
    }
    printf("\n");
  }
  
  return 0;
}



Measured memory_bytes: 2112
#include <iostream>
#include <algorithm>
#include <utility>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <math.h>
#include <string.h>
#include <iomanip>
#include <numeric>
#include <cstdlib>
#include <cstdint>
#include <cmath>

using ll = long long;
using pll = std::pair<ll, ll>;
using vl = std::vector<ll>;
using vll = std::vector<vl>;
using vpll = std::vector<pll>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define pb push_back
#define eb emplace_back


template <std::uint_fast64_t Modulus> class modint {
  using u64 = std::uint_fast64_t;

public:
  u64 a;

  constexpr modint(const u64 x = 0) noexcept : a(x % Modulus) {}
  constexpr u64 &value() noexcept { return a; }
  constexpr const u64 &value() const noexcept { return a; }
  constexpr modint operator+(const modint rhs) const noexcept {
    return modint(*this) += rhs;
  }
  constexpr modint operator-(const modint rhs) const noexcept {
    return modint(*this) -= rhs;
  }
  constexpr modint operator*(const modint rhs) const noexcept {
    return modint(*this) *= rhs;
  }
  constexpr modint operator/(const modint rhs) const noexcept {
    return modint(*this) /= rhs;
  }
  constexpr modint &operator+=(const modint rhs) noexcept {
    a += rhs.a;
    if (a >= Modulus) {
      a -= Modulus;
    }
    return *this;
  }
  constexpr modint &operator-=(const modint rhs) noexcept {
    if (a < rhs.a) {
      a += Modulus;
    }
    a -= rhs.a;
    return *this;
  }
  constexpr modint &operator*=(const modint rhs) noexcept {
    a = a * rhs.a % Modulus;
    return *this;
  }
  constexpr modint &operator/=(modint rhs) noexcept {
    u64 exp = Modulus - 2;
    while (exp) {
      if (exp % 2) {
        *this *= rhs;
      }
      rhs *= rhs;
      exp /= 2;
    }
    return *this;
  }
};

struct Edge{
    int to;
    int weight;
    Edge(int t, int w) : to(t), weight(w){ }
};

using Graph = std::vector<std::vector<Edge>>;
using graph = std::vector<std::vector<int>>;

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;
}

template <class T>
T gcd(T a, T b){
    if( b==0 ) return a;
    else return gcd(b, a%b);
}

template <class T>
T lcm(T a, T b){
    return (a*b)/gcd(a,b);
}

using mint = modint<1000000007>;

int  INF = 1e9+7;

std::vector<int> dx = {-1,0,1,0};
std::vector<int> dy = {0,-1,0,1};

int main(){
    ll n;
    std::cin >> n;
    if(n<=2){
        std::cout << 0 << '\n';
        return 0;
    }
    ll x = std::sqrt(n);
    std::vector<ll> z;
    ll ans = 0;
    for(ll i=2; i<=x+1; i++){
        if(n%i==0){
            z.emplace_back(i);
            z.emplace_back(n/i);
        }
    }
    z.emplace_back(n);
    for(ll i = 0; i < z.size() ; i++){
        ll m = z[i]-1;
        if(n/m==n%m){
            ans +=m;
        }
    }
    std::cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 384
/*
ABC119-D
問題
A社の神社とB軒の寺がある。
西からi社目の神社はsiメートル、i軒目の寺はtiメートルの地点
があります。
以下Q個の問いに答える。
問i:道路のxiメートルの地点から出発して自由に移動したとき、
神社1社と寺1軒に訪れるのに必要な最小の移動距離は何メートルか。
制約
1<=A,B<=10^5
1<=Q<=10^5
1<=si,ti,xi<=10^10
方針
単純にxiに一番近い神社と寺に行くのが最短距離なのはわかる。
ただし、パターンとしては以下があるので、全パターン試す。
・最初に前方最寄りの神社に行き、前方最寄りの寺にいく
・最初に前方最寄りの神社に行き、後方最寄りの寺にいく
・最初に後方最寄りの神社に行き、前方最寄りの寺にいく
・最初に後方最寄りの神社に行き、後方最寄りの寺にいく
・最初に前方最寄りの寺に行き、前方最寄りの神社にいく
・最初に前方最寄りの寺に行き、後方最寄りの神社にいく
・最初に後方最寄りの寺に行き、前方最寄りの神社にいく
・最初に後方最寄りの寺に行き、後方最寄りの神社にいく
最寄りを調べるためには以下の二分探索を用いる(O(logN))
lower_bound
・探索したい値以上が現れる最初の位置のイテレータ
v ={1,2,3,4,5} x = 3だったら、index:2の位置のイテレータ
upper_bound
・探索したい値より大きい値が現れる最初の位置のイテレータ
v ={1,2,3,4,5} x = 3だったら、index:3の位置のイテレータ
・前方のindex(自分自身を含む)
upper_bound(v.begin(), v.end(), x) - v.begin() - 1
・前方のindex(自分自身を含まない)
lower_bound(v.begin(), v.end(), x) - v.begin() - 1
・後方のindex(自分自身を含む)
lower_bound(v.begin(), v.end(), x) - v.begin()
・後方のindex(自分自身を含まない)
upper_bound(v.begin(), v.end(), x) - v.begin()
*/

#include <bits/stdc++.h>
#include <math.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rrep(i, n) for(int i = 0; i <= (n); i++)
using namespace std;
typedef long long ll;
const int MOD = 1000000007;
const ll INF = 1LL<<60;
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 Graph = vector<vector<int>>;

typedef pair<int, int> P;

int main(){
    char X, Y; cin >> X >> Y;
    if (X < Y){
        cout << "<" << endl;
    }
    else if (X==Y){
        cout << "=" << endl;
    }
    else{
        cout << ">" << endl;
    }
}

Measured memory_bytes: 3612
#include <stdio.h>

int
main(int argc, char *argv[])
{
        int n, data;
        int i, min, max;
        long int sum;

        scanf("%d\n", &n);
        min = 1000001; max = -1000001; sum = 0;
        for (i = 0; i < n; i++) {
                scanf("%d", &data);
                if (min > data) min = data;
                if (max < data) max = data;
                sum += data;
        }

        printf("%d %d %ld\n", min, max, sum);
        
        return 0;
}

Measured memory_bytes: 600
// May this submission get accepted!

#pragma GCC optimize ("O3")
#pragma GCC target ("tune=native")
#pragma GCC target ("avx")

#include <bits/stdc++.h>

// 汎用マクロ
#define ALL_OF(x) (x).begin(), (x).end()
#define REP(i,n) for (long long i=0, i##_len=(n); i<i##_len; i++)
#define RANGE(i,is,ie) for (long long i=(is), i##_end=(ie); i<=i##_end; i++)
#define DSRNG(i,is,ie) for (long long i=(is), i##_end=(ie); i>=i##_end; i--)
#define STEP(i, is, ie, step) for (long long i=(is), i##_end=(ie), i##_step = (step); i<=i##_end; i+=i##_step)
#define UNIQUE(v) do { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); } while (false)
template<class T> bool chmax(T &a, const T &b) {if (a < b) {a = b; return true;} return false; }
template<class T> bool chmin(T &a, const T &b) {if (a > b) {a = b; return true;} return false; }
#define INF 0x7FFFFFFF
#define LINF 0x7FFFFFFFFFFFFFFFLL
#define Yes(q) ((q) ? "Yes" : "No")
#define YES(q) ((q) ? "YES" : "NO")
#define Possible(q) ((q) ? "Possible" : "Impossible")
#define POSSIBLE(q) ((q) ? "POSSIBLE" : "IMPOSSIBLE")
#define DUMP(q) cerr << "[DEBUG] " #q ": " << (q) << " at " __FILE__ ":" << __LINE__ << endl
#define DUMPALL(q) do { cerr << "[DEBUG] " #q ": ["; REP(i, (q).size()) { cerr << (q)[i] << (i == i_len-1 ? "" : ", "); } cerr << "] at " __FILE__ ":" << __LINE__ << endl; } while (false)
template<class T> T gcd(const T &a, const T &b) { return a < b ? gcd(b, a) : b ? gcd(b, a % b) : a; }
template<class T> T lcm(const T &a, const T &b) { return a / gcd(a, b) * b; }

// gcc拡張マクロ
#define popcount __builtin_popcount
#define popcountll __builtin_popcountll

// エイリアス
#define DANCE_ long
#define ROBOT_ unsigned
#define HUMAN_ signed
#define CHOKUDAI_ const
using  ll = DANCE_ HUMAN_ DANCE_;
using ull = DANCE_ ROBOT_ DANCE_;
using cll = DANCE_ DANCE_ CHOKUDAI_;
using  ld = long double;
using namespace std;

// モジュール


// 処理内容
int main() {
    
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    ll n; cin >> n;
    vector<ll> a(n);
    REP(i, n) cin >> a[i];

    vector<ll> rank(n);
    iota(ALL_OF(rank), 0LL);
    sort(ALL_OF(rank), [&](ll i, ll j) {
        return a[i] < a[j];
    });
    REP(i, n) {
        cout << rank[i]+1 << " \n"[i==i_len-1];
    }
    
}

Measured memory_bytes: 2432
#include <bits/stdc++.h>
#define rep(i, m, n) for(int i = m; i < (n); i++)
#define print(x) cout << (x) << endl;
#define printa(x,n) for(int i = 0; i < n; i++){ cout << (x[i]) << " ";} cout << endl;
#define printa2(x,m,n) for(int i = 0; i < m; i++){ for(int j = 0; j < n; j++){ cout << x[i][j] << " ";} cout << endl;}
#define printp(x,n) for(int i = 0; i < n; i++){ cout << "(" << x[i].first << ", " << x[i].second << ") "; } cout << endl;
#define INF (1e18)
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
typedef struct{
    int x;
    int y;
} P;
typedef struct{
    ll to;
    ll cost;
} edge;
typedef pair<ll, ll> lpair;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    string s = to_string(N);
    int nn = s.size();
    ll ans = 0;
    rep(i,1,nn+1){
        rep(j,0,pow(3,i)){
            ll tt = j;
            ll v[11] = {};
            ll idx = 0;
            while(tt > 0){
                v[idx] = tt % 3;
                tt /= 3;
                idx++;
            }
            ll cnt[3] = {};
            rep(m,0,i){
                cnt[v[m]]++;
            }
            if(cnt[0] > 0 && cnt[1] > 0 && cnt[2] > 0){
                ll val = 0;
                rep(m,0,i){
                    if(v[m] == 0){
                        val += 3 * pow(10, m);
                    }else if(v[m] == 1){
                        val += 5 * pow(10,m);
                    }else{
                        val += 7 * pow(10,m);
                    }
                }
                if(val <= N){
                    ans++;
                }
            }

        }
    }
    print(ans);
    // ll ans = 0;
    // rep(i,0,nn){
    //     if(nn-i < 3) continue;
    //     ll tt = 1;
    //     rep(j,i,nn){
    //         char sv = s[j];
    //         print(sv);
    //         int sn = sv - '0';
    //         if(sn >= 3 && sn < 5){
    //             tt *= 1;
    //         }else if(sn >= 5 && sn < 7){
    //             tt *= 2;
    //         }else if(sn >= 7){
    //             tt *= 3;
    //         }else{
    //             tt *= 0;
    //         }
    //     }
    //     print(tt);
    //     print("---");
    //     ans += tt;
    //     // ll tt = 1;
    //     // char sv = s[nn-i-1];
    //     // int sn = sv - '0';
    //     // if(sn >= 3 && sn < 5){
    //     //     ans += pow(3,i-1);
    //     // }else if(sn >= 5 && sn < 7){
    //     //     ans += 2 * pow(3,i-1);
    //     // }else if(sn >= 7){
    //     //     ans += 3 * pow(3,i-1);
    //     // }
    // }
    // ll tt = 1;
    // rep(i,0,nn){
    //     char sv = s[i];
    //     int sn = sv - '0';
    //     if(s[i] >= 3 && s[i] < 5){
    //         tt *= 1;
    //     }else if(s[i] >= 5 && s[i] < 7){
    //         tt *= 2;
    //     }else if(s[i] >= 7){
    //         tt *= 3;
    //     }else{
    //         tt *= 0;
    //     }
    // }
    // ans += tt;
    // print(ans);

}


Measured memory_bytes: 512
w,a,b=map(int,input().split())
if a>=b:
  if a>b+w:
    print(a-(b+w))
    exit()
  else:
    print("0")
    exit()
else:
  if b>a+w:
    print(b-(a+w))
    exit()
  else:
    print("0")
    exit()
  

Measured memory_bytes: 2940
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
using namespace std;

template <typename T>
class Queue {
private:
    static const int max = 100005;
    T q[max];
    int head = 0;
    int tail = 0;
public:
    void initialie() {
        head = tail = 0;
    }
    bool is_full() {
        return head == (tail+1)%max;
    }
    bool is_empty() {
        return head == tail;
    }
    void push(T x) {
        if (!is_full()) {
            q[tail] = x;
            if(tail+1 == max) tail=0;
            else ++tail;
        }
        else cout << "queue is full!" << endl;
    }
    T pop() {
        if (!is_empty()) {
            T x = q[head];
            if(head+1 == max) head =0;
            else ++head;
            return x;
        }
        else cout << "queue is empty!" << endl;
    }
};

struct P {
    string name;
    int t;
};

int main() {
    int n, q;
    cin >> n >> q;

    auto Q = Queue<P>();
    for(int i=0; i<n; ++i) {
        string name;
        int t;
        cin >> name >> t;
        // cout << name << t << endl;
        auto u = P();
        u.name = name; u.t = t;
        Q.push(u);
    }

    int time = 0;
    while(!Q.is_empty()) {
        auto p = Q.pop();
        if(p.t<=q) {
            time += p.t;
            cout << p.name << " " << time <<endl;
        }
        else {
            time += q;
            p.t -= q; 
            Q.push(p); 
        }
    }
}



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

class Program
{
    public static void Main()
    {
        while (true)
        {
            var s = Console.ReadLine();
            if (s == "0 0")
            {
                break;
            }
            var input = s.Split().Select(int.Parse).ToArray();
            var N = input[0];
            var M = input[1];
            var a = Console.ReadLine().Split().Select(int.Parse).ToArray();
            Console.WriteLine(a.Select(x => Math.Min(x, M / N)).Sum());
        }
    }
}


Measured memory_bytes: 16404
#include <iostream>      // cout, endl, cin
#include <string>        // string, to_string, stoi
#include <vector>        // vector
#include <algorithm>     // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility>       // pair, make_pair
#include <tuple>         // tuple, make_tuple
#include <cstdint>       // int64_t, int*_t
#include <cstdio>        // printf
#include <map>           // map
#include <queue>         // queue, priority_queue
#include <set>           // set
#include <stack>         // stack
#include <deque>         // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset>        // bitset
#include <cmath>         // abs
typedef long long ll;
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define mod 1000000007
#define fst first
#define pb push_back

int main()
{  
    int N;
    cin >> N;
    int pw = 0;
    int ans = 0;
    for(int i = 1; i <= N; i++){
        for(int j = 1; j <= N; j++){
            for(int k = 1; k <= N; k++){
                pw = i*100 + j*10 + k;
                // if(N == 1){
                   // cout << "1" << endl;
                    //break;
                //}
                ans++;
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#define _LIBCPP_DEBUG 0
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll MOD = 1e9 + 7;
int INF=1<<30;


int main(void) {

    int N,P; cin>>N>>P;
    string S; cin>>S;
    ll ans = 0;
    if(P==2 || P==5){
        for (int i = 0; i < N; ++i) {
            if((S[i]-'0')%P==0)ans += i+1;
        }
    }else{
        map<int, int> mp;
        mp[0]=1;
        reverse(S.begin(), S.end());
        int sum = 0;
        int base = 1;
        for (int i = 0; i < N; ++i) {
            sum += (S[i]-'0') * base;
            sum %= P;
            ans += mp[sum];
            mp[sum]++;
            base *= 10;
            base %= P;
        }
    }

    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 900
from collections import deque
from math import ceil

# n个怪物，d杀伤半径，a杀伤值
n, d, a = map(int, input().split())

ms = [map(int, input().split()) for i in range(n)]
ms = sorted([(pos, ceil(hp / a)) for pos, hp in ms])

bombs = deque()

ans = 0
valid_bomb = 0
for pos, hp in ms:
    # 查看队列里的bomb是否对当前怪物有效
    while bombs and bombs[0][0] < pos:
        bomb_border, bomb_cnt = bombs.popleft()
        valid_bomb -= bomb_cnt
    
    # 还需新加多少bomb才能灭掉当前怪物
    bomb_cnt = max(0, hp - valid_bomb)
    valid_bomb += bomb_cnt
    ans += bomb_cnt
    
    # 新加的bomb放入队列
    if bomb_cnt > 0:
        bombs.append([pos + d * 2, bomb_cnt])
 
print(ans)    

Measured memory_bytes: 100288
//#include "pch.h"
//#include "stdafx.h"
#include <iostream>
#include <queue>
#include <vector>
#include <algorithm>
#include <math.h>
#include <string>
#include <cstring>

using namespace std;

/*-----------------------------------------------------------------------------
　定義
 -------------------------------------------------------------------------------*/
#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))
#define INF				2e9
#define MOD				(1000 * 1000 * 1000 + 7)
#define MIN(a, b)		((a) < (b) ? a : b)
#define MAX(a, b)		((a) > (b) ? a : b)
#define IsOdd(x)		(((x)&0x01UL) == 0x01UL)		/* 奇数 */
#define IsEven(x)		(!IsOdd((x)))					/* 偶数 */
#define ArrayLength(x)	(sizeof(x) / sizeof(x[0]))
#define DWORD_MAX		(0xFFFFFFFF)

typedef short SWORD;
typedef unsigned short WORD;
typedef long SDWORD;
typedef unsigned long DWORD;
typedef long long int QWORD;
typedef pair<int, int> P;

#define N_MAX	(100000)
#define M_MAX	(1000)
#define H_MAX	(1000)
#define W_MAX	(1000)

/*-----------------------------------------------------------------------------
　処理
 -------------------------------------------------------------------------------*/
// メイン
int main()
{
	int r, D, x;
	cin >> r >> D >> x;

	REP(i, 10) {
		x = r * x - D;
		cout << x << endl;
	}

	cout << endl;
}


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

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

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


int main() {
    int K,X;
    cin >> K >> X;
    string ans = 500 * K >= X ? "Yes" : "No";
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
n = gets().to_i
a = gets().split(" ")

max = -10
min = 10000

for i in 0..n-1
	if max < a[i].to_i
		max = a[i].to_i
	end
	if min > a[i].to_i
		min = a[i].to_i
	end
end

print(max - min, "\n")

Measured memory_bytes: 1788
n, k = map(int, input().split())
s = input()
s += '0'
s = '0' + s

t = []
l = r = 0

for i in range(1, n + 1):
    if s[i - 1] == '0' and s[i] == '1':
        l = i
    if s[i] == '1' and s[i + 1] == '0':
        r = i
        t.append((l, r))

if len(t) > 0:
    res = 0

    if k < len(t):
        for i in range(len(t) - k):
            tmp = t[i + k][1] - t[i][0]
            res = max(res, tmp)
        if t[0][0] != 1:
            tmp = t[k - 1][1] - 1
            res = max(res, tmp)
        if t[-1][1] != n:
            tmp = n - t[-k][0]
            res = max(res, tmp)
    else:
        for i in range(len(t)):
            res = t[-1][1] - t[0][0]
        if t[0][0] != 1:
            tmp = t[min(k, len(t))-1][1] - 1
            res = max(res, tmp)
        if t[-1][1] != n:
            tmp = n - t[-min(k,len(t))][0]
            res = max(res, tmp)

    print(res + 1)
else:
    print(n)

Measured memory_bytes: 8448
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>

using namespace std;

const int N = 100010, M = 200010;

int n, m;
int tot = -1, head[N];
struct Edge {
    int p, nxt, w;
    Edge(int p = 0, int nxt = 0, int w = 0) : p(p), nxt(nxt), w(w) {}
} edge[M << 1];
inline void Add(int u, int v, int w) {
    edge[++tot] = Edge(v, head[u], w);
    head[u] = tot;
    return;
}

int dist[N];
bool vis[N];

void DFS(int u) {
    vis[u] = 1;
    for (int i = head[u]; ~i; i = edge[i].nxt) {
        int v = edge[i].p, w = edge[i].w;
        if (vis[v]) {
            if (dist[u] + w != dist[v]) {
                puts("No");
                exit(0);
            }
        } else {
            dist[v] = dist[u] + w;
            DFS(v);
        }
    }
    return;
}

int main() {
    scanf("%d%d", &n, &m);
    memset(head, -1, sizeof(head));
    for (int i = 1; i <= m; ++i) {
        int u, v, w;
        scanf("%d%d%d", &u, &v, &w);
        Add(u, v, w);
        Add(v, u, -w);
    }
    for (int i = 1; i <= n; ++i)
        if (!vis[i]) {
            dist[i] = 0;
            DFS(i);
        }
    puts("Yes");
    return 0;
}

Measured memory_bytes: 8832
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>
#include <stack>
#include <set>
#include <map>

using namespace std;

typedef long long int ll;

const ll MOD = 1000000007;

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

  string s, t;
  cin >> s;
  cin >> t;

  ll length = 0;
  vector<set<ll> > sap(256);
  for (int i = 0; i < s.size(); i++) {
    sap[s[i]].emplace(i);
  }

  int pointer = -1;
  for (int i = 0; i < t.size(); i++) {
    auto it1 = sap[t[i]].upper_bound(pointer);
    if (it1 != sap[t[i]].end()) {
      length += (*it1) - pointer;
      pointer = (*it1);
      continue;
    }
    length += s.size() - pointer - 1;
    pointer = -1;
    auto it2 = sap[t[i]].upper_bound(pointer);
    if (it2 != sap[t[i]].end()) {
      length += (*it2) - pointer;
      pointer = (*it2);
      continue;
    }
    cout << -1 << endl; // impossible
    return 0;
  }

  cout << length << endl;

  return 0;
}


Measured memory_bytes: 5200
n,m=map(int,input().split())
ab=[list(map(int,input().split())) for _ in range(n)]

ab.sort(key=lambda x:x[0])

i=0
cnt=0
money=0
while(i<len(ab)):
    if cnt + ab[i][1]>m:
        money+=(m-cnt)*ab[i][0]
        cnt=m
        break
    else:
        cnt+=ab[i][1]
        money+=ab[i][0]*ab[i][1]
    i+=1
print(money)

Measured memory_bytes: 29028
#time limit exceed
n = int(input())
COM = [list(input().split()) for _ in range(n)]

class Node:
    def __init__(self,data):
        self.data = data #int
        self.left = None #Node
        self.right = None #Node
        self.parent = None #Node

    def inorder(self,List):
        if self.data != None:
            if self.left != None:
                self.left.inorder(List)
            List.append(self.data)
            if self.right != None:
                self.right.inorder(List)
        return List

    def preorder(self,List):
        if self.data != None:
            List.append(self.data)
            if self.left != None:
                self.left.preorder(List)
            if self.right != None:
                self.right.preorder(List)
        return List

class BTree:
    def __init__(self):
        self.root = None

    def insert(self,z):
        y = None
        x = self.root
        while x != None:
            y = x
            if z.data < x.data:
                x = x.left
            else:
                x = x.right
        z.parent = y
        if y == None:
            self.root = z
        elif z.data < y.data:
            y.left = z
        else:
            y.right = z

    def print(self):
        print(""," ".join(map(str,self.root.inorder([]))))
        print(""," ".join(map(str,self.root.preorder([]))))

btree = BTree()
cnt = 0
for i in range(n):
    if COM[i][0] == "insert":
        node = Node(int(COM[i][1]))
        btree.insert(node)
        cnt += 1
    else:
        btree.print()



Measured memory_bytes: 251440
using System;

class Class2
{
    static void Main(string[] args)
    {
        int N = int.Parse(Console.ReadLine());
        string[] input = Console.ReadLine().Split(' ');
        long calc = 1;
        long max = (long)Math.Pow(10, 18);
        for (int i = 0; i < N; i++)
        {
            long a = long.Parse(input[i]);
            if (a == 0)
            {
                calc = 0;
                break;
            }
            if (calc == -1)
            {
                continue;
            }

            try
            {
                checked
                {
                    calc = calc * a;
                }
            }
            catch (OverflowException)
            {
                calc = -1;
            }

            if (calc > max)
            {
                calc = -1;
            }
        }

        Console.WriteLine((calc).ToString());
    }
}

Measured memory_bytes: 41680
unittest
{
	assert( [ "2 2", "3", "2 1 1" ].parse.expand.solve == "1 1\n3 2" );
	assert( [ "3 5", "5", "1 2 3 4 5" ].parse.expand.solve == "1 2 2 3 3\n4 4 4 4 3\n5 5 5 5 5" );
	assert( [ "1 1", "1", "1" ].parse.expand.solve == "1" );
}



import std.algorithm;
import std.conv;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto hw = input.front.split.to!( long[] );
	input.popFront;
	input.popFront;
	auto as = input.front.split.to!( long[] );
	return tuple( hw[ 0 ], hw[ 1 ], as );
}

auto solve( long h, long w, long[] as )
{
	auto ansss = new long[][]( h, w );
	auto c = 1L;
	auto hi = 0L;
	auto wi = 0L;
	auto wd = 1L;
	while( !as.empty )
	{
		// 色を塗る
		ansss[ hi ][ wi ] = c;
		as.front--;
		if( as.front == 0 )
		{
			as.popFront;
			c++;
		}
		
		// 移動して、端まで来たら一つ下に降りて向きを変える
		wi += wd;
		if( w <= wi )
		{
			hi++;
			wi = w - 1;
			wd = -1;
		}
		else if( wi < 0 )
		{
			hi++;
			wi = 0;
			wd = 1;
		}
	}
	return ansss.map!( ( x ) => x.to!( string[] ).join( " " ) ).join( "\n" );
}


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

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    A,B,M=MI()
    a=LI()
    b=LI()
    ans=min(a)+min(b)
    for i in range(M):
        x,y,c=MI()
        x-=1
        y-=1
        temp=a[x]+b[y]-c
        if ans>temp:
            ans=temp
    print(ans)

main()


Measured memory_bytes: 64800
#include<bits/stdc++.h>
using namespace std;
 
#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define SORT(c) sort((c).begin(),(c).end())
#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG false
 
typedef long long ll;
typedef pair<int, int> ii;

#define MAXI 1000000

int main() {

	string s;
	while(getline(cin, s), s != "."){
		stack<int> st;
		bool flag = true;
		rep(i, s.size()){
			if(s[i] == '(') st.push(1);
			if(s[i] == '[') st.push(2);
			if(s[i] == ')'){
				if(st.empty() || st.top() != 1){
					flag = false;
					break;
				}
				st.pop();
			}
			if(s[i] == ']'){
				if(st.empty() || st.top() != 2){
					flag = false;
					break;
				}
				st.pop();
			}
		}
		if(flag && st.empty()) cout << "yes" << endl;
		else cout << "no" << endl;
	}
	

	return 0;
}

Measured memory_bytes: 3068
from itertools import combinations_with_replacement
n, m, q = map(int, input().split())
pair = []
for i in range(q):
    pair.append(list(map(int, input().split())))


ans = 0
for A in combinations_with_replacement([j for j in range(1, m+1)], n):
    temp = 0
    for a, b, c, d in pair:
        if A[b-1] - A[a-1] == c:
            temp += d
    ans = max(temp, ans)

print(ans)


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

vector<bool> IsPrime;

void sieve(size_t max){
    if(max+1 > IsPrime.size()){     // resizeで要素数が減らないように
        IsPrime.resize(max+1,true); // IsPrimeに必要な要素数を確保
    }
    IsPrime[0] = false; // 0は素数ではない
    IsPrime[1] = false; // 1は素数ではない

    for(size_t i=2; i*i<=max; ++i) // 0からsqrt(max)まで調べる
        if(IsPrime[i]) // iが素数ならば
            for(size_t j=2; i*j<=max; ++j) // (max以下の)iの倍数は
                IsPrime[i*j] = false;      // 素数ではない
}
void solve(long long X){
    sieve(X+100);
    int i = X;
    while (!IsPrime[i]) {
        i++;
    }
    cout << i << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    int X;
    scanf("%d",&X);
    solve(X);
    return 0;
}


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

int sumdig(int N){
  int sd = 0;
  for(int i = 0;i<5;i++){
    sd += (int)(N/pow(10,i))%10;
  }
  return sd;
}

int main(){
  int N,A,B;
  int a;
  int total = 0;
  cin >> N >> A >> B;
  for(int i = 0;i<N+1;i++){
    a =  sumdig(i);
    if(a >= A && a <= B) total+=i;
  }
  cout << total << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n;
long long ans;
int gcd(int x,int y)
{
	if(!y)
	{
		return x;
	}
	return gcd(y,x%y);
}
int main()
{
	scanf("%d",&n);
	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("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 3760
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
 
int main() {
    int N;
    cin >> N;
    for(int i=N; i<1000; i++){
        if(i%111==0){
            cout << i << endl;
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main(String args[])
	{
		Scanner sc=new Scanner(System.in);
		long n=sc.nextLong();
		long right;
	
		long min=100000000000l;
		long max;
		for(long i=1;i<=Math.sqrt(n);i++)
		{
			if(n%i==0)
			{
				right=n/i;
				if(right>i) max=right;
				else max=i;
				min=Math.min(min,(long)Math.log10(max)+1);
				
			}
		}
		System.out.println(min);
		
	}

}


Measured memory_bytes: 35748
import math
K = int(input())
ans = 0
for i in range(1,K+1):
    for j in range(i,K+1):
        for k in range(j,K+1):
            if i==j and j==k:
                ans+= math.gcd(i,math.gcd(k,j))
            elif i==j or j==k:
                ans += 3*math.gcd(i,math.gcd(k,j))
            else:
                ans += 6*math.gcd(i,math.gcd(k,j))
print(ans)

Measured memory_bytes: 9204
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Scanner;
class Main{


	static final int MOD = 1000000007;


	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);			//文字の入力
		int N = sc.nextInt();
		int M = sc.nextInt();
		int inf = 1000000007;
		int[][] dp = new int[M+1][1<<N];				//i番目以降の鍵は購入せずに状態jにするのに必要な最小費用

		for(int i = 0;i <= M;i++){
			for(int j = 0;j<1<<N; j++){
				dp[i][j] = inf;
			}
		}
		
		
		dp[0][0] = 0;
		for(int i = 1;i <= M;i++){
			int a = sc.nextInt();			//値段
			int n = sc.nextInt();			//開けれる箱の個数
			int bit = 0;						//bit
			for(int j = 0;j < n;j++){			//開けれる鍵を全部表示=状態(0001000みたいな)
				int k = sc.nextInt()-1;
				bit += 1<<k;
			}
			for(int j = 0;j<1<<N;j++){
				dp[i][j] = dp[i-1][j];
			}
			for(int j = 0;j<1<<N;j++){
				int k = j|bit;					
				dp[i][k] = Math.min(dp[i][k], dp[i-1][j] + a);
			}
						
		}
		int ans = dp[M][(1<<N)-1];

		
		System.out.println(ans==inf?-1:ans);




	}

	static void sieve(ArrayList<Long> list){
		int n = 50000000;
		boolean[] is_prime = new boolean[n+1];
		int[] prime = new int[n];
		for(int i= 0;i <=n;i++){
			is_prime[i] = true;
		}
		list.add((long) 1);
		for(int i = 2;i <= n;i++){
			if(is_prime[i]){
				list.add((long)i);
				for(int j = 2*i;j <= n;j+=i){
					is_prime[j] = false;
				}
			}
		}



	}




	static int upperbond(int k,int min,int[] data){		//kより小さい最大の値をdataの中から探し、返す二分探索
		int max = data.length;
		//		if(min == data.length-1){
		//			if(data[min] > k){
		//				return min;
		//			}
		//		}

		while(max-min > 1){
			int mid = (max+min)/2;
			if(data[mid] >= k){
				max = mid;
			}else{
				min = mid;
			}
		}

		return max;
	}

	static int lowerbond(int k,int min,int[] data){		//kより大きい最小の値をdataの中から探し、返す二分探索
		int max = data.length;

		while(max-min > 1){
			int mid = (max+min)/2;
			if(data[mid] >= k){
				max = mid;
			}else{
				min = mid;
			}
		}
		return min;
	}



	static int gcd(int a,int b){				//最大公約数を返す
		if(b == 0){
			return a;
		}else{
			return gcd(b, a%b);
		}
	}
	static long gcd(long a,long b){
		if(b == 0){
			return a;
		}else{
			return gcd(b, a%b);
		}
	}



	static long lcm (long a, long b) {
		long g = gcd(a,b);
		return a/g*b;
	}




}


class Edge extends ArrayList<P>{

}

class P{
	int to;
	long cost;
	P(int to,long cost){
		this.to = to;
		this.cost = cost;
	}
}


class Pair implements Comparable{
	int from;
	int end;
	@Override
	public int compareTo(Object other) {
		Pair otherpair = (Pair)other;

		return   from- otherpair.from;
	}








}






Measured memory_bytes: 53604
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const ll mx = 1e18+10;
void solve(){
    string s,t;
    cin>>s>>t;
    int dp[s.length()+1][t.length()+1];
    memset(dp,0,sizeof(dp));
    for(int i=0;i<=s.length();i++){
        for(int j=0;j<=t.length();j++){
            if(i==0||j==0) dp[i][j]=0;
            else if(s[i-1]==t[j-1])
            dp[i][j] = 1+dp[i-1][j-1];
            else
            dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
        }
    }
    int len = dp[s.length()][t.length()];
    vector<char>ans(len);
    int i=s.length();int j=t.length();
    int index=0;
    while(index<len){
        if(s[i-1]==t[j-1]){
        ans[index]=s[i-1];i--;j--;index++;}
        else if(dp[i-1][j]>=dp[i][j-1])
        i--;
        else
        j--;
    }
    reverse(ans.begin(),ans.end());
    for(auto x:ans) cout<<x;
}
int main(){
    int T=1;
    //cin>>T;
    while(T--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 35456
#include <vector>
#include <algorithm>
#include <set>
#include <iostream>
#include <unordered_set>
#include <map>

using namespace std;
typedef long long ll;

ll k, a, b, ans = 0;

int main() {
    cin >> k >> a >> b;
    if (b - a <= 2) {
        ans = 1 + k;
    } else {
        ans = a;
        k -= (a - 1);
        ans += (b - a) * (k / 2);
        k = k - (k / 2 * 2);
        ans += k;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <algorithm> //STLͨ���㷨
#include <cmath> //������ѧ����
#include <cstdio> //��������/�������
#include <iostream> //����������/���
#include <cstring> //�ַ�������
#include <string> //�ַ�����
#include <ctime> //�������ʱ��ĺ���
#define itn int
#define fro for
#define ll long long
#define reg register
#define inf 1234567890
#define rep(i,a,b,c) for (int i=a;i<=b;i+=c)
/*#include <bitset> //STLλ������
#include <cstype> //�ַ�����
#include <cerrno> //���������
#include <complex> //������
#include <clocale> //���屾�ػ�����
#include <cstdlib> //������������ڴ���亯��
#include <deque> //STL˫�˶�������
#include <exception> //�쳣������
#include <fstream> //�ļ�����/���
#include <functional> //STL�������㺯��(���������)
#include <limits> //�����������������ֵ����
#include <list> //STL�����б�����
#include <map> //STLӳ������
#include <iomanip> //����������/���
#include <ios> //��������/���֧��
#include <iosfwd> //����/���ϵͳʹ�õ�ǰ������
#include <istream> //����������
#include <ostream> //���������
#include <queue> //STL��������
#include <set> //STL��������
#include <sstream> //�����ַ�������
#include <stack> //STL��ջ����
#include <stdexcept> //��׼�쳣��
#include <streambuf> //�ײ�����/���֧��
#include <utility> //STLͨ��ģ����
#include <vector> //STL��̬��������
#include <cwchar.h>//���ַ�����������/���
#include <cwctype.h> //���ַ�����*/

using namespace std;

int ans;

int max(int x,int y){return x>y?x:y;}

int min(int x,int y){return x<y?x:y;}

int abs(int x){return x>0?x:-x;}

int gcd(int x,int y){return (!y)?x:gcd(y,x%y);}

void exgcd(int a,int b,int &d,int &x,int &y){if (!b){d=a,x=1,y=0;}else{exgcd(b,a%b,d,y,x);y-=x*(a/b);}}

int quick_power(ll a,int b){ll r=1;for (;b;b>>=1,a=a*a)if (b&1) r=r*a;return r;}

inline char read() {
	static const int IN_LEN = 1000000;
	static char buf[IN_LEN], *s, *t;
	return (s == t ? t = (s = buf) + fread(buf, 1, IN_LEN, stdin), (s == t ? -1 : *s++) : *s++);
}
template<class T>
inline void read(T &x) {
	static bool iosig;
	static char c;
	for (iosig = false, c = read(); !isdigit(c); c = read()) {
		if (c == '-') iosig = true;
		if (c == -1) return;
	}
	for (x = 0; isdigit(c); c = read()) x = x * 10 + (c ^ '0');
	if (iosig) x = -x;
}

char sr[10000000],z[20];int C=-1,Z=0;
void Ot(){fwrite(sr,1,C+1,stdout),C=-1;}
void print(int x){
	if (x<0) sr[++C]='-',x=-x;
    while(z[++Z]=x%10+48,x/=10);
    while(sr[++C]=z[Z],--Z);sr[++C]='\n';
}
//int find(int x){return fa[x]=fa[x]==x?x:find(fa[x]);}

//void add(int x,int y,int z){to[++cnt]=y;v[cnt]=z;Next[cnt]=head[x];head[x]=cnt;}
const int N=200200;
int a[N],b[N];
char s[N];
int main()
{
	int n;
	scanf("%d",&n);
	scanf("%s",s+1);
	for (int i=1;i<=n;a[i+1]=a[i],i++)
		if (s[i]=='.') a[i]++;
	for (int i=n;i>=1;b[i-1]=b[i],i--)
		if (s[i]=='#') b[i]++;
	ans=inf;
	for (int i=0;i<=n;i++) ans=min(ans,n-a[i]-b[i+1]);
	cout<<ans;
	return 0;
}









Measured memory_bytes: 2048
n, m = map(int, input().split())

card = [0]*(n+2)
for _ in range(m):
    l, r = map(int, input().split())
    card[l] +=1
    card[r+1] -=1

import numpy as np
card = list(np.cumsum(card))
print(card.count(m))

Measured memory_bytes: 32084
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<cmath>
#include<math.h>
#include<algorithm>
#include<string.h>
#include <iomanip>
#include <sstream>
using namespace std;

int main() {
  int H, W;
  int h=0;
  int w=0;
  string tmp;
  int m =0;

  cin >> H >> W;

  vector<string> s(H);
  vector<string> ans(H);
  vector<int> a(W);
  for(int i = 0; i < H; i++){
    cin >> tmp;
    // cout << "tmp length = " <<tmp.length() << endl;
    int k = 0;
    for(int j = 0; j < tmp.length(); j++){
      if(tmp[j] == '.'){
        k++;
      }
    }
    // cout << "k = " << k << endl;
    if(k != tmp.length()){
      s[i-m] = tmp;
      h++;
    }else{
      m++;       
      // cout << "all ." << endl;
    }
  }
  // cout << "------------" << endl;  
  // for(int i = 0; i < h; i++){
  //   cout << s[i]<< endl;
  // }
  // cout << "------------" << endl;  

  for(int i = 0; i < W; i++){
    int flg = 0;
    for(int j = 0; j < h; j++){
      if(s[j][i] == '.'){
        flg++;
//        cout << "flg++ in i=" << i << ", j= " << j << endl;
      }
    }
    if(flg != h){
      for(int j = 0; j < h; j++){
        ans[j] += s[j][i]; 
      }    
    }else{
  //    cout << "all . !!" << endl;
    }
  }
  for(int i = 0; i < h; i++){
    cout << ans[i] << endl;
  }

}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>

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

using namespace std;

int main(){
    int n; cin >> n;
    int max_number = 0, second_max_number = 0;
    int index;

    REP(i, n){
        int x; cin >> x;
        if(max_number <= x){
            index = i;
            second_max_number = max_number;
            max_number = x;
        }else second_max_number = max(second_max_number, x);
    }

    REP(i, n){
        if(index != i) cout << max_number << '\n';
        else cout << second_max_number << '\n';
    }
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
constexpr ll mod = 1e9 + 7;
#define endl '\n'
 
ll dp[2001];

ll DFS(int i, int sum) {
  if (sum == 0) return 1;
  if (sum <= 2) return 0;
  if (dp[sum] != -1) return dp[sum];

  ll ans = 0;
  for (int x = 3; x <= sum; ++x) {
    ans += DFS(i+1, sum-x);
    ans %= mod;
  }
  return dp[sum] = ans;
}

int main() {
  ios::sync_with_stdio(0); cin.tie(0);
 
  ll S;
  cin >> S;
  memset(dp, -1, sizeof(dp));
  cout << DFS(0, S) << endl;

}


Measured memory_bytes: 3692
N = int(input())
S = str(input())

s = S

# 前の方の#と後ろの方の.の数を数えて足したい
dot_num = s.count('.')
sharp_num = 0

ans = dot_num

for c in s:
    if c == '#':
        sharp_num = sharp_num + 1
    else:
        dot_num = dot_num - 1
    
    ans = min(ans, sharp_num + dot_num)
print(ans)



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

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl << endl;}
#define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000000000000LL
#define LLINF 1000000000000000000LL
#define MOD 998244353

typedef long long ll;
typedef pair<ll,ll> P;

/*
0-index
functionの中を書いて使う
segtree<ll> seg(n, [](ll a, ll b){return a + b;}, 0);
*/
template<typename T>
struct segtree{
	int n;
	vector<T> dat;
	T ZERO;
	function<T(T,T)> func;//要素と要素をマージする関数

	segtree(int n_, function<T(T,T)> func_, T zero):func(func_), ZERO(zero){
	  n = 1;
	  while(n < n_)n*=2;
	  dat.resize(2*n);
	  for(int i = 0;i < 2*n;i++)dat[i] = ZERO;
	}

	void update(int k, T a){
	  k += n - 1;dat[k] = a;
	  while(k > 0){
		k = (k-1)/2;
		dat[k] = func(dat[k*2+1],dat[k*2+2]);
	  }
	}

	void set(int k, T a) {
		k += n - 1;dat[k] = a;
	}

	void build(){
		for(int i = n - 2;i >= 0;i--){
			dat[i] = func(dat[2 * i + 1], dat[2 * i + 2]);
		}
	}

	T get(int k){return dat[k+n-1];}

	T que(int a,int b){
		T L = ZERO,R = ZERO;
		int A = a + n - 1;
		int B = b + n - 1;
		while(A < B){
			if((A & 1) == 0)L = func(L,dat[A++]);
            if((B & 1) == 0)R = func(dat[--B],R);
            A = A >> 1;
            B = B >> 1;
		}
		return func(L,R);
	}
};


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

	ll n, m;cin >> n >> m;
	segtree<ll> seg(111111, [](ll a, ll b){return min(a, b);}, INF);
	seg.update(1, 0);

	vector<pair<P, ll>> v; // R, L, C

	REP(i, m){
		ll l, r, c;cin >> l >> r >> c;
		v.EB(MP(r, l), c);
	}

	sort(ALL(v));
	REP(i, m){
		ll l = v[i].FI.SE;
		ll r = v[i].FI.FI;
		ll c = v[i].SE;
		ll tmp = min(seg.que(l, r+1) + c, seg.get(r));
		seg.update(r, tmp);
		//cout << l << " " << r << " " << c << endl;
		//REP(ii, n)cout << seg.get(ii+1) << " ";cout << endl;
	}

	if(seg.get(n) != INF)cout << seg.get(n) << endl;
	else cout << -1 << endl;

	return 0;
}


Measured memory_bytes: 6900
N = int(input())
A = [ int(input()) for _ in range(N) ]

ans =  0
m = 1
for i,a in enumerate(A):
  if i == 0:
    ans += a-1
    m = 1
  elif a == m+1:
    m = m + 1
  else:
    ans += (a - 1) // (m+1)
print(ans)


Measured memory_bytes: 7080