akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

#define speed ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
#define ub(a,x) upper_bound(a.begin(),a.end(),x)-a.begin()
#define lb(a,x) lower_bound(a.begin(),a.end(),x)-a.begin()
#define ll long long
#define endl "\n"
#define all(v) v.begin(),v.end()
#define ff first
#define ss second
#define pb push_back
#define PI 3.1415926535897932384626
#define inf 1e18
#define forn(i, n) for (int i = 0; i < int(n); i++)
int main()
{
    speed;
    ll n;
    cin>>n;
    ll a[n+1],h[n+1];

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

    ll ctr=0;
    for(ll i=0;i<n;++i)
    {

        if(h[i]<=a[i])
            ctr+=h[i];
        else
        {
            ctr+=a[i];
            h[i]= h[i]-a[i];

            if(a[i+1]<=h[i])
                {
                    ctr+=a[i+1];
                    a[i+1]=0;
                }
            else
            {
                ctr+=h[i];
                a[i+1]-=h[i];
            }

        }
    }
    ctr += min(h[n],a[n]);
    cout<<ctr<<endl;
    return 0;
}




Measured memory_bytes: 1792
n,x,y = map(int,input().split())

import heapq

def dijkstra(s):
    hq = [(0, s)]
    heapq.heapify(hq) # リストを優先度付きキューに変換
    cost = [float('inf')] * n # 行ったことのないところはinf
    cost[s] = 0 # 開始地点は0
    while hq:
        c, v = heapq.heappop(hq)
        if c > cost[v]: # コストが現在のコストよりも高ければスルー
            continue
        for d, u in e[v]:
            tmp = d + cost[v]
            if tmp < cost[u]:
                cost[u] = tmp
                heapq.heappush(hq, (tmp, u))
    return cost

e = [[] for _ in range(n)]
for i in range(n-1):
    e[i].append((1, i+1))
    e[i+1].append((1, i)) # 有向グラフでは削除
e[x-1].append((1, y-1))
e[y-1].append((1, x-1))

d = [sorted(dijkstra(i)[i:]) for i in range(n)]

import bisect

for i in range(1,n):
    ans = 0
    for j in range(n):
        ans += bisect.bisect_right(d[j], i) - bisect.bisect_left(d[j], i)
    print(ans)

Measured memory_bytes: 94712
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <map>
#include <cmath>
 
#define rep(i,n) for(int i = 0;i < (n);i++)
#define all(x) (x).begin(),(x).end()

using namespace std;

typedef long long int ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<pair<int, int> > vpi;
typedef vector<pair<ll, ll> > vpl;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
  string n;
  int k;
  cin >> n >> k;
  vi d(k);
  rep(i,k) cin >> d[i];

  vi l;
  int idx = 0;
  rep(i,10){
    if(i != d[idx]){
      l.push_back(i);
    }else{
      idx++;
    }
  }
#ifdef debug
  for(int a : l) cout << a << " ";
  cout << endl;
#endif

  rep(i,(int)l.size()){
    if(l[i] == (int)(n[0]-'0')) break;
    if(l[i] > (int)(n[0]-'0')){
      cout << l[i];
      rep(j,(int)n.size()-1) cout << l[0];
      cout << endl;
      return 0;
    }
  }

  string ans = "";
  int count = 0;
  bool flag = false;
  for(int i=(int)n.size()-1;i >= 0;i--){
    rep(j,(int)l.size()){
      if((int)(n[i]-'0')+count <= l[j]){
        ans = (char)(l[j]+'0')+ans;
        count = 0;
        flag = true;
        break;
      }
    }
    if(!flag){
      ans = (char)(l[0]+'0')+ans;
      count++;
    }else
      flag = false;
  }
  if(count > 0){
    for(int a : l){
      if(a != 0){
        ans = (char)(a+'0')+ans;
        break;
      }
    }
  }
  cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
package main

import "fmt"

var A, B, C, D int

func main() {
	fmt.Scanf("%d %d %d %d", &A, &B, &C, &D)

	if A+B == C+D {
		fmt.Println("Balanced")
	} else if A+B > C+D {
		fmt.Println("Left")
	} else {
		fmt.Println("Right")
	}
}


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

using namespace std;

const int MOD = 1000000007;

int main()
{
	int H, W, K;
	cin >> H >> W >> K;
	//dp[i][j]=縦棒を上からi刻み分についての入れ方のうち、
	//1からスタートしてjで終わるようなものの個数。
	vector<vector<int>> dp(H + 1, vector<int>(W, 0));
	dp[0][0] = 1;
	for (int i = 0;i < H;i++) {
		for (int j = 0;j < W;j++) {
			//
			for (int bit = 0;bit < (1 << (W - 1));bit++) {
				bool ok = true;
				for (int k = 0;k < W - 2;k++) {
					if ((bit & (1 << k)) && (bit & (1 << (k + 1)))) {
						ok = false;
					}
				}
				if (!ok) {
					continue;
				}
				//恐らくこの部分は
				int nj = j;
				if (bit & (1 << j)) {
					nj = j + 1;
				}
				else if (j > 0 && (bit & (1 << (j - 1)))) {
					nj = j - 1;
				}
				//
				dp[i + 1][nj] = (dp[i + 1][nj] + dp[i][j]) % MOD;
			}
		}
	}

	cout << dp[H][K-1] << endl;


	return 0;
}


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

using namespace std;
typedef long long ll;
#define int ll

#define REP(i,n) for(int i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const double DINF = std::numeric_limits<double>::infinity();
const int MOD = 1000000007;
#define MAX_N 200010

template< typename T >
class CumulativeSum
{
public:
    vector< T > m_data;
    CumulativeSum() {};
    CumulativeSum(int sz) : m_data(sz, 0) {};

    // k に x を加える O(1)
    void Add(int k, int x) {
        assert(m_data.size() >= k);
        if(m_data.size() <= k) { m_data.push_back(x); }
        else { m_data[k] += x; }
    }

    // 累積和の構築 O(m_data.size())
    void Build() { for(int i = 1; i < m_data.size(); i++) { m_data[i] += m_data[i - 1]; } }

    // 区間 [0, k] の和を返す O(1)
    // 閉区間なので k が含まれることに注意
    T Query(int k) {
        if(k < 0) { return 0; }
        return (m_data[min(k, (int) m_data.size() - 1)]);
    }

    // 区間 [l, h] の和を返す O(1)
    // 閉区間なので k が含まれることに注意
    T Query(int l, int h) { return this->Query(h) - this->Query(l-1); }
};

ll X, N;
ll x[MAX_N];
CumulativeSum<ll> cs;

signed main()
{
    cin >> N >> X;
    REP(i, N) {
        cin >> x[i];
        cs.Add(i, x[i]);
    }

    cs.Build();

    // 往復する回数 k でループ
    // 往復する回数 k のとき、最適は残っているもののうち最も遠くのものを 2 個、
    // それ以降 k 間隔で取っていくことになる
    ll ans = LLINF;
    for(int k = 1; k <= N; ++k) {
        ll cand = 0;
        ll first_num = 2;
        ll mul = 5;
        bool isTooBig = false;
        for(int i = N-1; i >= 0;) {
            ll tmp = cs.Query(i - (k * first_num - 1), i);
            i -= k * first_num;
            // LLINF 検査
            if(LLINF / tmp > mul) {
                cand += tmp * mul;
                cand = min(cand, LLINF);
            } else {
                isTooBig = true;
            }
            first_num = 1;
            mul += 2;
        }
        cand += k * X + N * X;
        if(!isTooBig) { ans = min(ans, cand); }
    }

    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 3444
program CADDi2018_A

  ! <module>s to import
  use, intrinsic :: iso_fortran_env

  ! require all variables to be explicitly declared
  implicit none

  ! constants for this <program>
  integer, parameter :: num_digits = 4
  
  ! variables for this <program>
  character(len=4, kind=1) :: digit_char
  integer                  :: num_two

  ! support variables for this <program>
  integer :: itr

  ! STEP.01
  ! read out the target number as a string
  read(unit=INPUT_UNIT, fmt='(A4)') digit_char(1:num_digits)

  ! STEP.02
  ! count up the number of `2`
  num_two = 0

  do itr = 1, num_digits, 1
    if (digit_char(itr:itr) .eq. '2') num_two = num_two + 1
  end do

  ! STEP.03
  ! output the result
  write(unit=OUTPUT_UNIT, fmt='(I0)', advance='yes') num_two

end program CADDi2018_A

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

using namespace std;

int N;
vector<pair<int, int>> ans;

int main(){
    cin >> N;
    int S = N;
    if(S%2 == 0){
        S++;
    }
    for(int i = 1; i<=N; i++){
        for(int j = i+1; j<=N; j++){
            if(i+j != S){
                ans.push_back({i, j});
            }
        }
    }
    cout << ans.size() << "\n";
    for(auto p : ans){
        cout << p.first << " " << p.second << "\n";
    }
}


Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
#include <vector>
#include <queue>
#include <string>
#include <cmath>
#include <algorithm>

using namespace std;

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define BIT(X, i) ((X>>i)&1)

typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> pii;
typedef vector<pii> vii;
typedef priority_queue<ll> pq;

const int MOD = 1e9+7;
const int INF = (1<<30);
const ll INFL = 9e18;

int main() {
  ll N, K, ans = 0; cin >> N >> K; K++;
  // int D = 0; while (K >> D++); D--;
  vi A(N), bits_K(50, 0), sum_bit(50, 0), bits_X(50, 0);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    for (int j = 0; j < 50; j++) {
      sum_bit[j] += BIT(A[i], j);
    }
  }
  for (int i = 0; i < 50; i++) {
    bits_K[i] = BIT(K, i);
  }

  for (int i = 50-1; i >= 0; i--) {
    if (bits_K[i] == 1) {
      bits_X[i] = 0;
      for (int j = i-1; j >= 0; j--) {
        bits_X[j] = (N < 2*sum_bit[j]) ? 0 : 1;
      }
      ll fx = 0, base = 1;
      for (int j = 0; j < 50; j++) {
        fx += (bits_X[j] ? N - sum_bit[j] : sum_bit[j]) * base;
        base <<= 1;
      }
      ans = max(ans, fx);
    }

    bits_X[i] = bits_K[i];
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1152
//{{{
#pragma GCC diagnostic ignored "-Wunknown-pragmas"
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef vector<int> vi;
typedef pair<int, int> pii;
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define clr(a, b) memset(a, b, sizeof(a))
#ifdef LOCAL
#include "prettyprint.hpp"
#endif
// clang-format off
void _print() { cerr << "]\033[0m\n"; }
template <typename T> void __print(T x) { cerr << x; }
template <typename T, typename... V> void _print(T t, V... v) { __print(t); if (sizeof...(v)) cerr << ", "; _print(v...); }
#ifdef LOCAL
#define debug(x...) cerr << "\033[1;34m[" << #x << "] = \033[1;32m["; _print(x)
#define debug_arr(x...) cerr << "\033[1;34m[" << #x << "] = \033[1;32m" << (x) << "\033[0m\n"
#else
#define debug(x...)
#define debug_arr(x...)
#endif
// clang-format on
//}}}

int T;

const int N = 5e3 + 10;

const LL inf = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9 + 7;

int n, k;

LL p[N], c[N];
LL sum[N], cnt[N];
bool vis[N];

LL func(int pos)
{
    LL t = k;
    LL ret = 0;

    if (t > 2 * cnt[pos])
    {
        if (sum[pos] > 0)
        {
            LL d = t / cnt[pos];
            assert(d >= 2);
            d -= 2;
            ret += d * sum[pos];
            t -= cnt[pos] * d;
        }
        else
            t = cnt[pos];
    }

    // if (sum[pos] > 0)
    //{
    // ret += t / cnt[pos] * sum[pos];
    // t = t % cnt[pos];
    //}
    // else
    //{
    // t = t % cnt[pos];
    // if (t == 0) t = cnt[pos];
    //}

    // if (t == 0) return ret;

    int cur = pos;
    LL val = c[p[cur]];
    cur = p[cur];

    LL v = val;
    for (int i = 2; i <= t; i++)
    {
        int nxt = p[cur];
        v += c[nxt];
        val = max(val, v);
        cur = nxt;
    }
    ret += val;

    return ret;
}

int main()
{
#ifdef LOCAL
    freopen("in", "r", stdin);
    // freopen("out", "w", stdout);
#endif

    while (cin >> n >> k)
    {
        for (int i = 1; i <= n; ++i) cin >> p[i];
        for (int i = 1; i <= n; ++i) cin >> c[i];

        clr(vis, false);
        for (int i = 1; i <= n; i++)
        {
            if (vis[i] == true) continue;

            set<int> st;
            LL cur = i;
            LL v = c[p[cur]];
            st.insert(p[cur]);

            cur = p[cur];

            for (int a = 2; a <= 2 * n; a++)
            {
                int nxt = p[cur];
                if (st.find(nxt) != st.end())
                {
                    break;
                }
                assert(a < n + 1);
                v += c[nxt];
                st.insert(nxt);
                cur = nxt;
            }

            for (auto idx : st)
            {
                vis[idx] = true;
                cnt[idx] = st.size();
                sum[idx] = v;
            }
        }

        LL ans = func(1);
        for (int i = 2; i <= n; i++)
        {
            LL v = func(i);
            ans = max(ans, v);
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 3944
#include <iostream>
#include <numeric>
#include <algorithm>
using namespace std;

int s[110];

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

    int sum = accumulate(s, s + N, 0);
    if (sum % 10 != 0) {
        cout << sum << endl;
        return 0;
    }

    sort(s, s + N);
    
    bool flag = false;
    for (int i = 0; i < N; i++) {
        if (s[i] % 10 != 0) {
            sum -= s[i];
            flag = true;
            break;
        }
    }
    if (flag)cout << sum << endl;
    else cout << 0 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<cd> vcd;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvl;
typedef unordered_map<int, int> umpii;
typedef unordered_map<ll, ll> umpll;
template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int MOD = 1000000007;
const ll INF = 1e18;
const int inf = 1e9;
const int MX = 100001; //check the limits, dummy

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

    int n; cin >> n;
    cout << (n & 1 ? ((((double)n - 1)/2) + 1)/(double)n : 0.5) << endl;
}

Measured memory_bytes: 256
# solution

import numpy as np
import io
import math
from scipy.sparse.csgraph import shortest_path

nim,mike = map(int,input().split())

array = [[int(x) for x in input().split()] for _ in range(mike)]

graph = np.zeros((nim,nim)) # 0-indexed
for a,b,c in array:
  graph[a-1,b-1] = c

dist = shortest_path(graph,directed=False).astype(int)

answer = 0
for a,b,c in array:
  if c != dist[a-1,b-1]:
    answer += 1
print(answer)

Measured memory_bytes: 16840
#include<bits/stdc++.h>
using namespace std;
//define
typedef pair<int,int>pi;
#define int long long
#define elif else if
#define rep(x,y) for(int i=x;i<y;i++)
#define REP(x,y) for(int j=x;j<y;j++)
#define Rep(x,y) for(int k=x;k<y;k++)
#define all(x) x.begin(),x.end()
#define pb push_back
#define vint vector<int>
#define vvint vector<vector<int>>
#define vtr vector<string>
#define vvtr vector<vector<string>>
#define vhar vector<char>
#define vvhar vector<vector<char>>
#define mod 100000007
#define elif else if
#define str string
int digitsum(int a){
  int b=0;
  while(a){
    b+=a%10;
    a/=10;
  }
  return b;
}
signed main(){
  int N,M,O,P=0,c=1,co=0,cou=0,minN=mod;
  double D,Do;
  char C,Ca;
  str S,T;
  cin>>N;
  while(N>=1){
    c+=c;
    N/=2;
  }
  cout<<c-1<<endl;
}


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

int main(void){

    int N,D;
    cin >> N >> D;
    int X[N][D];
    for (int i = 0; i < N; i++){
        for(int j = 0; j < D ; j++){
            cin >> X[i][j]; 
        }
    }

    double dis = 0.0;
    int ans = 0;
    for(int i = 0; i < N-1; i++){
        for (int j = i+1; j < N; j++ ){
            dis = 0.0;
            for(int k = 0; k < D; k++){
                dis += pow((X[i][k]-X[j][k]),2.0);
            }
            dis = pow(dis,0.5);
            if(dis - (int)dis==0.0){
                ans++;
            }

        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
import bisect

n=int(input())
l=list(map(int,input().split()))

l.sort()

ans=0
for i in range(n):
  for j in range(i+1,n):
    a=l[i]
    b=l[j]
    le=bisect.bisect_left(l,max(a-b,b-a)+1)
    ri=bisect.bisect_right(l,a+b-1)
    #print(le,ri)
    f=0
    if le<=i<=ri:
      f-=1
    if le<=j<=ri:
      f-=1
    if ri-le+f>0:
      ans+=ri-le+f
    #print(a,b,ans)

print(ans//3)

Measured memory_bytes: 75400
#include <iostream>
#include <string>

using namespace std;
using ll = long long;

int main() {
	string s;
	cin >> s;
	int last = s.size()-1;
	if(s[last] == '3'){
		cout << "bon" << endl;
	} else if(s[last] == '0' || s[last] == '1' || s[last] == '6' || s[last] == '8'){
		cout << "pon" << endl;
	} else {
		cout << "hon" << endl;
	}
    return 0;
}


Measured memory_bytes: 3628
#include<iostream>
using namespace std;
int ten(char x){
	if(x == 'I') return 1;
	if(x == 'V') return 5;
	if(x == 'X') return 10;
	if(x == 'L') return 50;
	if(x == 'C') return 100;
	if(x == 'D') return 500;
	if(x == 'M') return 1000;
}

int main(){
	char roman[102];
	int i;
	int ans;
	while(cin >> roman){
		i = 0; ans = 0;
		while(roman[i] != '\0'){
			if(roman[i+1] != '\0' && ten(roman[i]) < ten(roman[i+1])) ans = ans - ten(roman[i]);
			else ans = ans + ten(roman[i]);
			i++;
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 1140
#include <stdio.h>
int main(){
    int W;
    int H;
    int r;
    int x;
    int y;
    char *check;
    
    scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);
    
        if(x-r>=0 && x +r <= W) check = "Yes";
    else if(y-r>=0 && y+r<=H) check = "Yes";
    if(x - r< 0 || x + r > W) check = "No";
    else if(y + r > H || y - r < 0) check = "No";

    
    printf("%s\n",check);
    return 0;
}



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

using namespace std;

#define ll long long
#define ld long double
#define pll pair <ll , ll>

#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define mp make_pair

#define X first
#define Y second

#define LB(x) (x & -(x))
#define BIT(a,b) ((ll)(a&(1<<b))==0 ? false : true)

const ll MAXN=1e5+10;

ll x[MAXN];

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

    ll n,a,b,res=0;
    cin>>n>>a>>b;

    for(ll i=0;i<n;i++)
    {
        cin>>x[i];
    }

    for(ll i=1;i<n;i++)
    {
        res+=min(a*(x[i]-x[i-1]) , b);
    }

    cout<<res;
}


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

using namespace std;
typedef long long ll;

int main() {
    string s;
    cin >> s;
    int saishoiti=0;//最初イチパターンでない
    int saishozero=0;//最初ゼロパターンでない
    for(int i=0;i!=s.size();i++){
        if(s[i]=='0'){
            if(i%2==0){
                saishoiti++;
            }
            else{
                saishozero++;
            }
        }
        else{
            if(i%2==0){
                saishozero++;
            }
            else{
                saishoiti++;
            }
        }
    }
    if(saishozero>saishoiti){
        cout << saishoiti << endl;
    }
    else{
        cout << saishozero << endl;
    }
}


Measured memory_bytes: 512
n, m = map(int, input().split())
ab = [list(map(int, input().split())) for i in range(n)]
cd = [list(map(int, input().split())) for i in range(m)]
for i in ab:
    l = []
    for j in cd:
        l.append(abs(i[0] - j[0]) + abs(i[1] - j[1]))
    print(l.index(min(l)) + 1)

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

#define froop1(a,n) for(int i = a;i < n;i++)
#define froop2(a,n) for(int i = a;i > n;i--)
int main(){
	long long N,zc = 0,sum = 1;
  cin >> N;
  vector<long long> a(N);
  froop1(0,N){
   cin >> a.at(i);
    if(a.at(i) == 0){
      zc++;
    }
  }
  if(zc > 0){
    cout << 0 << endl;
    return 0;
  }
  froop1(0,N){
    if(a.at(i) > 1000000000000000000LL / sum){
      cout << -1 << endl;
      return 0;
    }
    sum *= a.at(i);
  }
  cout << sum << endl;

return 0;
}

Measured memory_bytes: 3984
#include "bits/stdc++.h"
using namespace std;

// 定義
typedef long long         ll;
typedef pair<ll, ll>      P;
#define ALL(x)            (x).begin(),(x).end()
#define REP(i, n)         for(ll i = 0 ; i < (ll)n ; ++i)
#define REPN(i, m, n)     for(ll i = m ; i < (ll)n ; ++i)
#define REVREP(i, n)      for(ll i = n - 1; i >= 0 ; i--)
#define VL                vector<ll>
#define VVL               vector<vector<ll>>
#define VVVL              vector<vector<vector<ll>>>
#define VC                vector<char>
#define VVC               vector<vector<char>>
#define INF               (ll)2e9
#define INF_LL            1LL<<60
//#define MOD             998244353
#define MOD               1000000007

ll Ceil(ll val, ll div)   { return (val + div - 1) / div; }
ll CeilN(ll val, ll div)  { return Ceil(val, div) * div; }
ll FloorN(ll x, ll n)     { return (x - x % n); }
bool IsOdd(ll x)          { return ((x & 1) == 1); }
bool IsEven(ll x)         { return ((x & 1) == 0); }
template<class T> bool chmax(T& a, T b) { if (a <= b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T& a, T b) { if (a >= b) { a = b; return 1; } return 0; }

void Solve()
{
	ll N, X, T;
	cin >> N >> X >> T;

	ll ans = Ceil(N, X) * T;
//	string ans = "Yes";

	cout << ans << endl;
}

// メイン
int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Solve();
	return 0;
}


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



int main(){
    long N,A[5];
    cin>>N>>A[0]>>A[1]>>A[2]>>A[3]>>A[4];

    
    sort(A,A+5);
    long ans=5+(N/A[0]);
  if(N%A[0]==0)ans--;
    cout<<ans<<endl;
}

Measured memory_bytes: 256
// AOJ ALDS1_7_D Reconstruction of a Tree
// 2018.5.7 bal4u

#include <stdio.h>

#if 1
#define gc() getchar_unlocked()
#else
#define gc() getchar()
#endif
int in()
{
	int n = 0, c = gc();
	do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
	return n;
}

int pre[45], ind[45];
int post[45], sz, pos;
int idx[45];

void rebuild(int l, int r)
{
	int c, m;

	if (l >= r) return;
	c = pre[pos++];
	m = idx[c];
	rebuild(l, m);
	rebuild(m+1, r);
	post[sz++] = c;
}

int main()
{
	int n, i;

	n = in();
	for (i = 0; i < n; i++) pre[i] = in();
	for (i = 0; i < n; i++) idx[in()] = i;

	sz = 0, pos = 0;
	rebuild(0, n);
	
	printf("%d", post[0]);
	for (i = 1; i < n; i++) {
		putchar(' '), printf("%d", post[i]);
	}
	putchar('\n');
	return 0;
}


Measured memory_bytes: 2128
#include<stdio.h>
#include<iostream>
#include<string>
#include<memory>
#include<cmath>
#include<algorithm>
#include<vector>
#include<unordered_map>
double min_double(double a,double  b){
    if(a<b) return a;
    else return b;
}
void swap(int *x,int *y){
    int tmp;
    tmp=*x;
    *x=*y;  
    *y=tmp;
}
int gcd(int a,int b){
    if(a<b) swap(&a,&b);
    if(b<1) return -1;

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

int main(){
    int N;
    std::cin>>N;
    std::vector<int> order(N);
    for(int i=1;i<=N;i++){
        int a;
        std::cin>>a;
        order[a-1]=i;
    }

    for(int i=0;i<N;i++) std::cout<<order[i]<<" ";
    std::cout<<std::endl;

    return 0;
}

Measured memory_bytes: 3784
import sys
N = int(input())
t, x, y = [], [], []
p_x, p_y = 0, 0
for i in range(N):
    t_t, x_t, y_t = map(int, input().split())
    t.append(t_t)
    x.append(x_t)
    y.append(y_t)
for i in range(N):
    if int(t[i]) < int(x[i]) + int(y[i]) or t[i] % 2 != (x[i] + y[i]) % 2:
        print("No")
        sys.exit()
print("Yes")



Measured memory_bytes: 11716
# AtCoder Beginner Contest 149 : B (2019/12/29)
A, B, K = map(int, input().split())
if A >= K:
    A = A - K
elif A < K:
    if B >= K-A:
        B = B -(K-A)
    else:
        B = 0
    A = 0
print(A, B)

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
using namespace std;
const int inf = 10e9 + 7;
#define int long long
#define rep(i,n) for(int i=1;i<=n;i++)
#define loop(i,m,n) for(int i=m;i<n;i++)
#define endre getchar(); getchar();return 0;
int a[100010], b[100010];
signed main() {
	int n;
	cin >> n;
	rep(i, n) {
		cin >> a[i] >> b[i];
	}
	int cnt = 0;
	for (int i = n; i > 0; --i) {
		if ((a[i] + cnt) % b[i] != 0) {
			cnt += b[i] - (a[i] + cnt) % b[i];
		}
	}
	cout << cnt << endl;
	endre;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
int main(){
    // interesting
    int A[]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    int k;cin>>k;
    k--;
    cout<<A[k]<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int a,b;
	scanf("%d %d",&a,&b);
	if(a==1){
		a=14;
	}
	if(b==1){
		b=14;
	}
	if(b<a){
		printf("Alice\n");
	}
	else if(a<b){
		printf("Bob\n");
	}
	else{
		printf("Draw\n");
	}
	return 0;
}

Measured memory_bytes: 128
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from itertools import permutations, accumulate, combinations, combinations_with_replacement
from math import sqrt, ceil, floor, factorial
from bisect import bisect_left, bisect_right, insort_left, insort_right
from copy import deepcopy
from operator import itemgetter
from functools import reduce, lru_cache  # @lru_cache(None)
from fractions import gcd
import sys
def input(): return sys.stdin.readline().rstrip()
def I(): return int(input())
def Is(): return (int(x) for x in input().split())
def LI(): return list(Is())
def TI(): return tuple(Is())
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def TIR(n): return [TI() for _ in range(n)]
def S(): return input()
def Ss(): return input().split()
def LS(): return list(S())
def SR(n): return [S() for _ in range(n)]
def SsR(n): return [Ss() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
sys.setrecursionlimit(10**6)
MOD = 10**9+7
INF = 10**18
# ----------------------------------------------------------- #

n, l, t = Is()
XW = TIR(n)
ANS = []
count = 0
for x, w in XW:
    if w == 1:
        tmp = (x+t)%l
        count += (x+t)//l
    else:
        tmp = (x-t)%l
        count += (x-t)//l
    ANS.append(tmp)
count %= n
ANS.sort()
ANS = ANS[count:] + ANS[:count]
for ans in ANS:
    print(ans)


Measured memory_bytes: 90968
N, X, Y = map(int, input().split())

from collections import defaultdict
ds = defaultdict(int)
for i in range(N):
    for j in range(i+1, N):
        d = min(j-i, abs(X-1-i)+1+abs(Y-1-j))
        ds[d] += 1

for i in range(1, N):
    print(ds[i])


Measured memory_bytes: 48988
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<fstream>

int main() {
	int D = 0;

	std::cin >> D;

	//std::cout << D << std::endl;

	if (D == 25) {
		std::cout << "Christmas" << std::endl;
	}
	else if (D == 24) {
		std::cout << "Christmas Eve" << std::endl;
	}
	else if (D == 23) {
		std::cout << "Christmas Eve Eve" << std::endl;
	}
	else if (D == 22) {
		std::cout << "Christmas Eve Eve Eve" << std::endl;
	}
	else {
		std::cout << "error" << std::endl;
	}
}



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

int main(){
    int N,K,d,x;
    cin >> N >>K;
    int a[N+1];
    int count=N;

    for(int j=1;j<=K;j++){
        cin >> d;
        for(int k=0;k<d;k++){
            cin >> x;
            a[x]=x;
        } 
    }

    for(int i=1;i<=N;i++){
        if(a[i]==i){
            count--;
        }
    }
    cout << count <<endl;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x.size())
#define PI 3.1415926535897932384626433832795
int MOD=1e9+7;
int powmod(int a,int l, int md){int res=1;while(l){if(l&1)res=res*a%md;l/=2;a=a*a%md;}return res;}
int binpow(int a,int l){int res=1;while(l){if(l&1)res=res*a;l/=2;a=a*a;}return res;}
typedef long long ll; typedef vector<ll> vi; typedef pair<ll, ll> ii; typedef vector<ii> vii;
#define pb push_back
int __set(int b, int i) {return b|(1<<i);} //set ith bit
int __unset(int b, int i) {return b&(~(1UL<<i));}
int __check(int b, int i) {return b&(1<<i);} //returns 0 if ith bit is 0
int mulmod(int a, int b, int md) {return ((a%md)*(b%md))%md;}
int addmod(int a, int b, int md) {return (a+b)%md;}
int submod(int a, int b, int md) {return (((a-b)%md)+md)%md;}
int divmod(int a, int b, int md) {return mulmod(a, powmod(b, md-2, md), md);} //if md is prime;
const ll inf = 0xFFFFFFFFFFFFFFFL; //very large number
priority_queue<int, vector<int>, greater<int> > pq; //for min priority_queue
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
clock_t time_p=clock();
void time()
{
    time_p=clock()-time_p;
    cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";
}


signed main(void) {
	IOS;
	int h,w,n;
	cin>>h>>w>>n;
	int p = max(h,w);
	if(n%p==0) cout<<n/p<<endl;
	else {
		cout<<n/p+1<<endl;
	}
	time();
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1e9
#define PI 3.14159265359
#define MOD 1000000007
#define ALL(v) v.begin(),v.end()
#define ALLR(v) v.rbegin(),v.rend()
typedef long long ll;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//isPrime
//modpow modinv
//getDigit
int main() {
  cout << fixed << setprecision(10);
  int n,m,x,y;
  cin >> n >> m >> x >> y;
  vector<int> a(n);
  vector<int> b(m);
  rep(i,n) cin >> a.at(i);
  rep(i,m) cin >> b.at(i);
  int amax = x;
  int bmin = y;
  rep(i,n){
    amax = max(amax,a.at(i));
  }
  rep(i,m){
    bmin = min(bmin,b.at(i));
  }
  if(bmin>amax){
    cout << "No War" << endl;
  }else{
    cout << "War" << endl;
  }
}


Measured memory_bytes: 256
s = input()
t = input()
ans = []
for i in range(len(s)-len(t)+1):
    tmp = s[i:i+len(t)]
    flg = True
    for j in range(len(t)):
        if tmp[j]!=t[j]:
            if tmp[j]!='?':
                flg = False
    if flg:
        c = s[:i]+t+s[i+len(t):]
        ans.append(c.replace('?', 'a'))
print('UNRESTORABLE' if len(ans)==0 else min(ans))

Measured memory_bytes: 3064
iN,iM = [int(x) for x in input().split()]
iD = 10**9 +7 #法

def fPrimeCounter(iM):
    iS = int(iM ** 0.5) + 1
    aRet = []
    for i in range(2,iS + 1):
        iCounter = 0
        while iM % i == 0:
            iM /= i
            iCounter += 1
        if 0 < iCounter : aRet.append(iCounter)
        if iM == 1 : break
    if 1 < iM  : aRet.append(1)
    return aRet
def fnCr(iN,iR,iD):
    iR = min(iR,iN-iR)
    if iR == 0 :
        return 1
    elif iR == 1 :
        return iN
    return (iN % iD) * pow(iR,iD-2,iD) * fnCr(iN-1,iR-1,iD) % iD

aP = fPrimeCounter(iM)
#if aP == []:
#   print(1)
#   exit()
iRet = 1
for i in aP:
    # i + iN -1  C  iN -1
    iRet *= fnCr(i+iN-1,i,iD)
iRet %= iD
print(iRet)


Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <set>
#include <cstdlib>
#include <deque>
#include <stack>

using namespace std;
const long long P = 1000000007;
const long long INF = 1LL << 60;

long long conbi(long long n,long long k) {
  long long res = 1;
  long long inv;
  for(long long i = n-k+1; i <= n; i++) {
    res *= i;
    //res %= P;
  }
  for(long long i = 1; i <= k; i++) {
    res /= i;
    //inv = modinv(i,P);
    //res *= inv;
    //res %= P;
  }
  return res;
}


int main() {
  long long n;
  cin >> n;
  long long a[n];
  for(int i = 0; i < n; i++) {
    cin >> a[i]; 
  }
  sort(a,a+n);
  long long amx = a[n-1];
  long long half = amx/2 + amx%2;
  long long min = INF;
  long long ans;
  for(int i  = 0; i < n-1; i++) {
    if(min > abs(half-a[i])) {
      min = abs(half-a[i]);
      ans = a[i];
    }
  }
  cout << amx << " " << ans << endl;
  return 0;
}


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

using namespace std;

int main(){
  int d,g;cin >> d >> g;
  g=int(g/100);
  vector< pair<int,int> > pc(d);
  int P=0;int C=0;
  for(int i=0;i<d;i++){
    int p,c;cin >> p >> c;c=int(c/100);
    pc[i]=make_pair(p,c);
    C+=(c+p*(i+1));P+=p;
  }
  vector<int> dp(C+1,0);
  for(int i=0;i<d;i++){
    vector<int> dp_sub(C+1,0);
    for(int j=0;j<C+1;j++){
      if(j==0){
        for(int k=1;k<pc[i].first+1;k++){
          if(k!=pc[i].first){dp_sub[k*(i+1)]=k;}
          else{dp_sub[k*(i+1)+pc[i].second]=k;}
        }
      }else if(dp[j]!=0){
        for(int k=1;k<pc[i].first+1;k++){
          if(k!=pc[i].first){
            if(dp_sub[j+k*(i+1)]!=0){
              dp_sub[j+k*(i+1)]=min(dp[j]+k,dp_sub[j+k*(i+1)]);
            }else{
              dp_sub[j+k*(i+1)]=dp[j]+k;
            }
          }else{
            if(dp_sub[j+k*(i+1)+pc[i].second]!=0){
              dp_sub[j+k*(i+1)+pc[i].second]=min(dp[j]+k,dp_sub[j+k*(i+1)+pc[i].second]);
            }else{
              dp_sub[j+k*(i+1)+pc[i].second]=dp[j]+k;
            }
          }
        }
      }
    }
    for(int j=0;j<C+1;j++){
      if(dp_sub[j]!=0){
        if(dp[j]==0){
          dp[j]=dp_sub[j];
        }else{
          dp[j]=min(dp[j],dp_sub[j]);
        }
      }
    }
  }
  int m=P;
  for(int i=g;i<C+1;i++){
    if(dp[i]!=0){m=min(m,dp[i]);}
  }
  cout << m << endl;
}


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

typedef long long ll;
const int MAXN = 100010;

inline int read() {
	int x = 0, f = 1;
	char ch = getchar();
	for(; !isdigit(ch); ch = getchar()) if(ch=='-') f=-1;
	for(; isdigit(ch); ch = getchar()) x = (x*10)+(ch^48);
	return x * f;
}

int n, a[MAXN];

int main() {

	int i;
	n = read();
	generate(a+1, a+n+1, read);
	sort(a+1, a+n+1);
	int lst = 0;
	ll sum = 0;
	for(i = 1; i < n; i++) {
		sum += a[i];
		if(sum * 2 < a[i+1]) lst = i;
	}

	printf("%d\n", n-lst);
	return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define vite ios_base::sync_with_stdio(false); cin.tie(NULL);
#define tst lli T; cin>>T; while(T--)
#define mod 1000000007
#define MAX 1e9
#define MIN -1e9
#define lli long long int
#define vt vector
#define pb push_back
int main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
    lli n;
    cin>>n;
    lli a[n];
    for(lli i=0;i<n;i++) cin>>a[i];

    sort(a,a+n);

    lli t=0;
    for(lli i=0;i<n;i++)
    {
        for(lli j=i+1;j<n;j++)
        {
            if(a[i]==a[j]) continue;
            for(lli k=j+1;k<n;k++)
            {
                if(a[j]==a[k]) continue;

                if(a[i]+a[j]>a[k]) t++;
            }
        }
    }
    cout<<t;
    cout<< endl;
    // cout<< fixed << 1.0 * clock() / CLOCKS_PER_SEC << setprecision(10);
    return 0;
}

Measured memory_bytes: 3620
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n = read();
    let k: i32 = read();
    let mut p_arr = vec![0; n];
    for i in 0..n {
        p_arr[i] = read();
    }
    let mut max = 0;
    let mut max_start = 0;
    let mut max_end = 0;
    for (i, _) in p_arr.iter().enumerate() {
        let before_i: i32 = if k - 2 < 0 { 0 } else { k - 2 };
        if i > before_i as usize {
            let mut sum = 0;
            let start = i - (k as usize - 1);
            let end = i + 1;
            for p in p_arr[start..end].iter() {
                sum += *p;
            }
            if max < sum {
                max = sum;
                max_start = i - (k as usize - 1);
                max_end = i + 1;
            }
        }
    }
    let mut res = 0.0;
    for p in p_arr[max_start..max_end].iter() {
        let mut sum = 0;
        for i in 1..*p + 1 {
            sum += i;
        }
        let expected = sum as f64 / *p as f64;
        res += expected;
    }
    if res == 0.0 {
        let p = p_arr[0];
        let mut sum = 0;
        for i in 1..p + 1 {
            sum += i;
        }
        let expected = sum as f64 / p as f64;
        println!("{}", expected);
    } else {
        println!("{}", res);
    }
}


Measured memory_bytes: 4352
#include <iostream>

int n, t, e;

bool res(int lb, int rb, int x) {
	int m = rb / x*x;
	return m >= lb;
}

int main() {
	std::cin >> n >> t >> e;
	int lb = t - e, rb = t + e;
	int x;
	for (int i = 0; i < n; ++i) {
		std::cin >> x;
		if (res(lb, rb, x)) {
			std::cout << i + 1 << std::endl;
			goto a;
		}
	}
	std::cout << -1 << std::endl;
a:;
	return 0;
}

Measured memory_bytes: 1164
#include <stdio.h>

long long int l[100];
long long int r[100];

long long int ln[100];
long long int rn[100];

bool use[100];

long long int ko(long long int a,long long int b)
{
	while(1)
	{
		long long int w = a % b;
		if(w == 0)
		{
			return b;
		}
		a = b;
		b = w;
	}
}

long long int ju(int b)
{
	long long int ld,rd;
	if(l[b] >= 0)
	{
		ld = ju(l[b]);
	}
	else
	{
		ld = 1;
	}
	if(r[b] >= 0)
	{
		rd = ju(r[b]);
	}
	else
	{
		rd = 1;
	}
	long long int lk = ld * ln[b];
	long long int rk = rd * rn[b];
	long long int ww = ko(ld,rd);
	long long int w = ko(lk,rk);
	long long int sai = lk * rk / w;
	return sai / ln[b] + sai / rn[b];
}

int main()
{
	while(1)
	{
		int n;
		scanf("%d",&n);
		if(n == 0)
		{
			break;
		}
		for(int i = 0; i < n; i++)
		{
			int lne,rne;
			long long int lw,rw;
			scanf("%lld %lld %d %d",&lw,&rw,&lne,&rne);
			l[i] = lne - 1;
			r[i] = rne - 1;
			long long int w = ko(lw,rw);
			ln[i] = lw / w;
			rn[i] = rw / w;
		}
		for(int i = 0; i < n; i++)
		{
			use[i] = true;
		}
		for(int i = 0; i < n; i++)
		{
			if(l[i] >= 0)
			{
				use[l[i]] = false;
			}
			if(r[i] >= 0)
			{
				use[r[i]] = false;
			}
		}
		int oya;
		for(int i = 0; i < n; i++)
		{
			if(use[i])
			{
				oya = i;
				break;
			}
		}
		printf("%lld\n",ju(oya));
	}
	return 0;
}

Measured memory_bytes: 1024
while True:
	n = int(input())
	if n == 0:
	   break
	s, vn, vx = 0, 1001, -1
	for i in range(n):
		a = int(input())
		vn = min(vn, a)
		vx = max(vx, a)
		s += a
	print((s-vn-vx)//(n-2))


Measured memory_bytes: 5600
#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 1000000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007

typedef long long ll;
typedef pair<ll,ll> P;
/*
0-index
functionの中を書いて使う
宣言の時に単位元を書く
*/
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 getmin(string str){
	char c = str[0];
	bool isFirst = true;
	int cou = 0;
	int ret = INF;
	REP(i, str.size()){
		if(str[i] == c)cou++;
		else {
			if(isFirst && cou % 2 == 0)cou++;
			if(cou % 2)ret = min(ret, cou);
			isFirst = false;
			cou = 0;
		}
	}

	return ret;
}

bool oneKind(string str){
	REP(i, str.size())if(str[0] != str[i])return false;
	return true;
}

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

	ll n, m;cin >> n >> m;
	string str;cin >> str;
	ll ans = 0;

	int k = getmin(str);
	segtree<ll> seg(n, [](ll a, ll b){return (a + b) % MOD;}, 0);

	seg.update(0, 1);

	if(oneKind(str)){
		for(ll i = 2;i < n;i++){
			ll l = max(0LL, i - k - 1);
			ll r = i - 1;
			seg.update(i, seg.que(l, r));
		}
		REP(i, n-1){
			if(n - (i + 1) <= k){
				//cout << "pass " << seg.get(i) * (n - i) % MOD << endl;
				ans = (ans + seg.get(i) * (n - i) % MOD) % MOD;
			}
		}
		ans = (ans + 1) % MOD;
	}
	else {
		for(ll i = 2;i < n;i++){
			if(i % 2)continue;
			ll l = max(0LL, i - k - 1);
			ll r = i - 1;
			seg.update(i, seg.que(l, r));
		}

		//REP(i, n)cout << seg.get(i) << " ";cout << endl;
		REP(i, n-1){
			if(n - (i + 1) <= k && ((n - (i + 1)) % 2)){
				//cout << "pass " << seg.get(i) * (n - i) % MOD << endl;
				ans = (ans + seg.get(i) * (n - i) % MOD) % MOD;
			}
		}
	}

	cout << ans << endl;

	return 0;
}


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

using namespace std;
using ll = long long;

void fact(int n, map<int,int>& Map){
    for(int i = 2; i * i <= n; i++){
        while(n % i == 0){
            Map[i]++;
            n /= i;
        }
    }
    if(n == 1)return;
    Map[n]++;
}




int main()
{
    int n;
    cin >> n;
    cout << n << ": ";
    map<int,int> mp;
    fact(n, mp);
    vector<int> ans;
    for(auto i : mp){
        for(int j = 0; j < i.second;j++)ans.push_back(i.first);
    }
    for(int i = 0; i < (int)ans.size(); i++)cout << ans[i] << (i == (int)ans.size() - 1 ? '\n' : ' ' ); 
}


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

int main() {
  long long N;
  cin >> N;
  
  if (N % 2 == 1) {
    cout << 0 << endl;
    return 0;
  }
  
  long long a = 10;
  long long ans = 0;
  while (N / a != 0) {
    ans += N / a;
    a *= 5;
  }
  
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 256
import sys
import math
sys.setrecursionlimit(1000000)

cache = {}
def solve(K):
    s = 0
    for a in range(1, K+1):
        cache[a] = 0
        for b in range(1, K+1):
            cache[a] += math.gcd(a, b)

    for a in range(1, K+1):
        for b in range(1, K+1):
            n = math.gcd(a, b)
            s += cache[n]
    return s

if __name__ == "__main__":
    N = int(input())
    print(solve(N))


Measured memory_bytes: 9208
/* Code by : Suraj (@suraj1611) */

#include<bits/stdc++.h>
#include <string>

using namespace std;

#define ll long long int
#define rep(i,n) for(int i=0; i<n; i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define mx INT_MAX
#define mn INT_MIN
#define md 1000000007
#define pb push_back
#define mp make_pair
#define maxsize 1100005
#define lb cout<<endl;
#define endl "\n"
#define F first
#define S second
#define label cout<<"hello!"<<endl
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);

ll power(ll x, ll  y) 
{ 
	ll m=md;
   	ll ans=1;
    while (y > 0) 
    {
        if (y & 1)
            ans = (ans * x) % m;
        x = (x * x) % m;
        y >>= 1;
    }
    return ans;
} 

int main()
{
	IOS
	


	ll n;
	cin>>n;
	ll a[n];
	rep(i,n)
	{
		cin>>a[i];
	}


	if(n==2)
	{
		cout<<max(a[0],a[1]);
		return 0;
	}
	ll left[n+1],right[n+1];
	left[0]=0;
	right[n]=0;
	rep(i,n)
	{
		left[i+1]=(__gcd(left[i],a[i]));
	}

	for(ll i=n-1;i>=0;i--)
	{
		right[i]=(__gcd(right[i+1],a[i]));
	}
	ll ans=mn;
	rep(i,n)
	{
		ans=max(ans,__gcd(left[i],right[i+1]));
	}

	cout<<ans<<endl;





    return 0;
}

Measured memory_bytes: 2560
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 s = sc.next();
            String t = sc.next();
            int ans = t.length() + 1;
            for (int i = 0; i < (s.length() - t.length()) + 1; i++) {
                  int tmp =0;
                  for(int j = 0;j<t.length();j++){
                        if (t.charAt(j) != s.charAt(i+j)){
                              tmp++;
                        }
                  }
                  ans = Math.min(ans,tmp);
            }
            System.out.println(ans);

      }


}


Measured memory_bytes: 35696
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n;i>0;i--)
#define rep1(i,s,n) for(int i=s;i<n;i++)
#define max0(a,b,c) max(max(a,b),c)
#define min0(a,b,c) min(min(a,b),c)
#define ft first
#define sc second
#define pb push_back
#define mp make_pair
#define mt make_tuple
using namespace std;
using Graph = vector<vector<int>>;
typedef long long lint;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ldouble;
typedef vector<int> vec;
typedef vector<ll> lvec;
typedef vector<ull> ulvec;
typedef vector<pair<int,int>> pvec;
typedef vector<pair<ll,ll>> plvec;
typedef vector<tuple<ll,ll,ll>> tvec;
typedef vector<string> svec;

int main(){
    ll r;
    cin>>r;
    cout<<r*r;
}

Measured memory_bytes: 256
def main
  islands_num, req_num = ARGF.gets.split.map(&:to_i)

  # ソートしない解法 ※islands_num分のArrayを最初から用意しておくだけ
  requests = Array.new(islands_num) {Array.new}
  req_num.times do
    req = ARGF.gets.split.map(&:to_i)
    # 配列indexは0始まりである点に注意
    requests[req[1]-1] << req
  end

  # 切断した場所 例）1の場合、1-2 の間を切断したという意味
  last = 0
  cnt = requests.inject(0) do |cnt, rs|
    if 0 < rs.size
      rs.each do |req|
        if last < req[0]
          last = req[1] - 1
          cnt += 1
        end
      end
    end
    cnt
  end

  puts cnt
end

if __FILE__ == $0
  main
end


Measured memory_bytes: 15740
#include <bits/stdc++.h>
using namespace std;
int main(){
  vector<vector<char>> C(2,vector<char>(3));
  for(int i=0;i<2;i++){
    for(int j=0;j<3;j++){
      cin>>C.at(i).at(j);
    }
  }
  bool ok = true;
  for(int i=0;i<2;i++){
    for(int j=0;j<3;j++){
      if(C.at(i).at(j)!=C.at(1-i).at(2-j)){
        ok = false;
      }
    }
  }
  
  if(ok){
    cout<<"YES"<<endl;
  }else{
    cout<<"NO"<<endl;
  }
  return 0;
}

Measured memory_bytes: 256