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

using ll = long long;
#define rep(inc, bgn, end) for (int inc = bgn; inc < end; ++inc)
#define repe(inc, bgn, end) for (int inc = bgn; inc <= end; ++inc)

using namespace std;

int main() {
    int n;
    cin >> n;
    int isChange = false;
    int cnt      = 0;
    rep(i, 0, n) {
        int val;
        cin >> val;
        if (isChange) {
            cnt++;
            isChange = false;
        } else {
            if (val - 1 == i) {
                isChange = true;
                if (i == n - 1) {
                    cnt++;
                }
            }
        }
    }
    cout << cnt << endl;
    return 0;
}


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

using namespace std;

// http://www.prefield.com/algorithm/container/union_find.html
struct UnionFind {
  vector<int> data;
  UnionFind(int size) : data(size, -1) { }
  bool unionSet(int x, int y) {
    x = root(x); y = root(y);
    if (x != y) {
      if (data[y] < data[x]) swap(x, y);
      data[x] += data[y]; data[y] = x;
    }
    return x != y;
  }
  bool findSet(int x, int y) {
    return root(x) == root(y);
  }
  int root(int x) {
    return data[x] < 0 ? x : data[x] = root(data[x]);
  }
  int size(int x) {
    return -data[root(x)];
  }
};


int main() {
    int N,K,L;
    cin>>N>>K>>L;
    UnionFind ufR(N+1),ufT(N+1);
    for(int i=0;i<K;i++){
        int p,q;cin>>p>>q;ufR.unionSet(p,q);
    }
    for(int i=0;i<L;i++){
        int p,q;cin>>p>>q;ufT.unionSet(p,q);
    }
    map<int,set<int>>R,T;
    for(int i=1;i<N+1;i++){
        R[ufR.root(i)].insert(i);
        T[ufT.root(i)].insert(i);
    }
    int ans[N+1];
    for(int i=0;i<N+1;i++)ans[i]=0;
    for(int i=1;i<N+1;i++){
        if(ans[i]!=0)continue;
        set<int>& r=R[ufR.root(i)];
        set<int>& t=T[ufT.root(i)];
        if(r.size()==0||t.size()==0)continue;
        set<int> s;
        set_intersection(r.begin(),r.end(),t.begin(),t.end(),inserter(s,s.begin()));
        for(auto c:s){
            ans[c]=s.size();
            r.erase(c);t.erase(c);
        }
    }
    for(int i=1;i<N+1;i++){
        cout<<ans[i]<<" ";
    }
    cout<<endl;
    
    return 0;
}

Measured memory_bytes: 49664
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
using namespace std;

int main() {
	int w,h,x,y,z,n;
	
	cin>>w>>h>>n;
	int x1=0,x2=w,y1=0,y2=h;
	for(int i=0;i<n;i++){
		cin>>x>>y>>z;
		if(z==1){
			if(x1<=x)x1=x;
		}else if(z==2){
			if(x2>=x)x2=x;
		}else if(z==3){
			if(y1<=y)y1=y;
		}else if(z==4){
			if(y2>=y)y2=y;
		}
	}
	//cout<<x1<<" "<<x2<<" "<<y1<<" "<<y2<<endl;
	if(x2<=x1||y2<=y1){
		cout<<0<<endl;
	}else{
	cout<<(x2-x1)*(y2-y1)<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
def p_c():
    from collections import defaultdict
    d = defaultdict(int)
    ac_list = set()
    n, m = map(int, input().split())
    for _ in range(m):
        p, s = input().split()
        if s == "WA" and p not in ac_list:
            d[p] += 1
        if s == "AC":
            ac_list.add(p)
    wa = 0
    for key in d.keys():
        if key in ac_list:
            wa += d[key]
    print(len(ac_list), wa)
    
p_c()

Measured memory_bytes: 54488
n = int(input())
cnt = False
for i in range (26):
  for j in range (19):
    s = i*4 + j*7
    if s == n:
      cnt = True
      break
  if cnt:
    break
#print(n, cnt, i, j)

#if cnt == True: 以外に下の書き方もあり
if cnt:
  print("Yes")
else:
  print("No")

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

class Aamondai
{
    static void Main()
    {
        var ab = Console.ReadLine().Split(' ').Select(x => Int32.Parse(x)).ToArray();
        var A = ab[0];
        var B = ab[1];
        var ans = ab.Max();
        if (A == ans) A--;
        else B--;
        ans += A > B ? A : B;
        Console.WriteLine(ans);
    }
}

Measured memory_bytes: 13396
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
#define ll long long
 
//const int INF = 1e8;
typedef pair<int,int>P;
int dx[4] = {1,0,-1,0};int dy[4] = {0,1,0,-1};
queue<P> que;

int main(void){
  int h,w;cin >> h >> w;cin.ignore();
  bool frag[w+1][h+1];
  char m[w+1][h+1];
  for(int i = 0;i<h;i++){
    string s;getline(cin,s);
    for(int j = 0;j<w;j++){
      m[j][i] = s.at(j);
      frag[j][i] = false;
    }
  }
  for(int i = 0;i<h;i++){
    bool tmp = true;
    for(int j = 0;j<w;j++){
      if(m[j][i] == '#') tmp = false;
    }
    if(tmp == true) {
      for(int k = 0;k<w;k++)frag[k][i] = true;
    }
  }
  for(int i = 0;i<w;i++){
    bool tmp = true;
    for(int j = 0;j<h;j++){
      if(m[i][j] == '#') tmp = false;
    }
    if(tmp == true){
      for(int k = 0;k<h;k++)frag[i][k] = true;
    }
  }
  for(int i = 0;i<h;i++){
    bool tmp = false;
    for(int  j = 0;j<w;j++){
      if(frag[j][i] == false){
        cout << m[j][i];
        tmp = true;
      }
    }
    if(tmp == true) cout << endl;
  }
  /*for(int i = 0;i<h;i++){
    for(int  j = 0;j<w;j++){
      if(frag[j][i] == false){
        cout << 0 << " ";
      }else{
        cout << 1 << " ";
      }
    }
    cout << endl;
  }
  */
}

Measured memory_bytes: 256
#define f(i,s,v) for(int i=(int)s;i<(int)v;++i)
#define rf(i,s,v) for(int i=(int)s-1;i>(int)v;--i)
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
const ll oo=1e15;
int n,k;
int a[100005];
bool calculated[100005];
ll value[100005];
ll solve(int idx){
    if(idx>=n) return oo;
    if(idx==n-1) return 0ll;
    if(calculated[idx]) return value[idx];
    ll best=oo;
    f(i,1,k+1)
        best=min(best,solve(idx+i)+abs(a[idx+i]-a[idx]));
    calculated[idx]=true;
    value[idx]=best;
    return best;
}
int main()
{
    scanf("%d %d",&n,&k);
    f(i,0,n)
        scanf("%d",&a[i]);
    cout<<solve(0)<<'\n';
    return 0;
}


Measured memory_bytes: 6144
n,m=map(int,input().split())
py=[list(map(int,(str(_+1)+' '+input()).split())) for _ in range(m)]
py.sort(key=lambda x:x[1]*10**10+x[2])
pi=0
x=0
b='000000'
ans=[]
for pyi in py:# pyi=[i,pi,yi]
  if pyi[1]!=pi:
    x=1
    pi=pyi[1]
  else:
    x+=1
  ans.append([pyi[0],(b+str(pyi[1]))[-6:]+(b+str(x))[-6:]])
ans.sort(key=lambda x:x[0])
for ansi in ans:# ansi=[i,識別番号]
  print(ansi[1])

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

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

    map<char, int> mp;
    rep(i, s.size()) mp[s.at(i)]++;

    if (s == "zyxwvutsrqponmlkjihgfedcba")
    {
        cout << -1 << endl;
        return 0;
    }

    string answer = "-1";

    if (s.size() != 26)
    {
        for (char c = 'a'; c <= 'z'; c++)
        {
            if (mp.count(c) == 0)
            {
                answer = s + c;
                break;
            }
        }
        cout << answer << endl;
        return 0;
    }
    else
    {
        string t = s;
        answer = "";
        next_permutation(s.begin(), s.end());
        for (int i = 0; i < s.length(); i++)
        {
            answer += s.at(i);
            if (t.at(i) != s.at(i))
                break;
        }
        cout << answer << endl;
        return 0;
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<math.h>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;

#define FOR(i, n) for(int i = 0; i < (n); i++)
#define FORq(i, m, n) for(int i = (m); i < (n); i++)
#define FORr(i, n) for (int i = (n); i >= 0; i++)


int main() {
	int year, month, date;
	scanf("%d/%d/%d", &year, &month, &date);

	if (month > 4) {
		cout << "TBD" << endl;
	}
	else {
		cout << "Heisei" << endl;
	}
}

Measured memory_bytes: 256
# https://onlinejudge.u-aizu.ac.jp/problems/ALDS1_10_B
import functools

INF = float('inf')
@functools.lru_cache(maxsize=None)
def rec(l, r):
    if l + 1 == r:
        return 0
    ret = INF
    for mid in range(l+1, r):
        ret = min(ret, rec(l, mid) + rec(mid, r)+R[l]*R[mid]*C[r-1])
    return ret


if __name__ == "__main__":
    N = int(input())
    R = []
    C = []
    for _ in range(N):
        r, c = list(map(int, input().split()))
        R.append(r)
        C.append(c)

    print(rec(0, N))



Measured memory_bytes: 6844
#include<iostream>
#include<string.h>
#include<string>
#include<bitset>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<math.h>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
typedef long double db;
typedef pair<int,int> pii;
const int N=10000;
const db pi=acos(-1.0);
#define lowbit(x) (x)&(-x)
#define sqr(x) (x)*(x)
#define rep(i,a,b) for (register int i=a;i<=b;i++)
#define per(i,a,b) for (register int i=a;i>=b;i--)
#define go(i,u) for (register int i=head[u];i;i=sq[i].nxt)
#define fir first
#define sec second
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define maxd 998244353
#define eps 1e-8
int n;
bitset<4002000> f;

int read()
{
    int x=0,f=1;char ch=getchar();
    while ((ch<'0') || (ch>'9')) {if (ch=='-') f=-1;ch=getchar();}
    while ((ch>='0') && (ch<='9')) {x=x*10+(ch-'0');ch=getchar();}
    return x*f;
}

int main()
{
	n=read();
	f[0]=1;
	int sum=0;
	rep(i,1,n)
	{
		int a=read();
		f|=(f<<a);
		sum+=a;
	}
	rep(i,(sum+1)/2,sum)
		if (f[i]) {printf("%d",i);return 0;}
	return 0;
}


Measured memory_bytes: 1792
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        @SuppressWarnings("resource")
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        List<Integer> list = new ArrayList<>();
        while (n > 0) {
            list.add((int)( n % 10));
            n = (long) n / 10l;
        }
        if (list.size() == 1) {
            System.out.println(list.get(0));
            return;
        }
        boolean flg = true;
        for (int i = 0 ; i < list.size() - 1 ; i++) {
            if (list.get(i) != 9) {
                flg = false;
            }
        }
        if (flg) {
            System.out.println(list.get(list.size() - 1) + (list.size() - 1) * 9);
        } else {
            System.out.println(list.get(list.size() - 1) + (list.size() - 1) * 9 - 1);
        }
    }

}


Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
#define forN(n, N) for(int n=0; n<N; n++)
#define res_out(ans) cout << ans << "\n";
#define ll long long

ll A[int(1e6)];
int B[int(1e6)], ind[int(1e6)];

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, M, m = 0;
    ll ans = 0;
    cin >> N >> M;
    forN(n, N)cin >> A[n] >> B[n];
    iota(ind, ind+N, 0);
    sort(ind, ind+N, 
    [](int i1, int i2){return A[i1] < A[i2];}
    );
    forN(n, N){
        if(m + B[ind[n]] < M){
            m += B[ind[n]];
            ans += B[ind[n]] * A[ind[n]];
        }
        else{
            ans += (M - m) * A[ind[n]];
            break;
        }
    }
    res_out(ans)
    return 0;
}

Measured memory_bytes: 8832
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define SZ(x) ((int)(x).size())
#define rep(i,n) for(int i=0;i<(n);++i)
#define fore(i,a) for(auto &i:a)
#define min(...) min({__VA_ARGS__})
#define max(...) max({__VA_ARGS__})
#define Yes cout << "Yes" << endl;
#define No cout << "No" << endl;
#define answer cout << ans << endl;
signed _main(); signed main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
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> using v = vector<T>;
template<class T> using vv = vector<v<T>>;
const int MOD=1e9+7;
const long long INF = 1LL << 60;

class Edge {
public:
  int to;     // 辺の行き先
  int weight; // 辺の重み
  Edge(int t, int w) : to(t), weight(w) { }
};

using Graph = vector<vector<Edge>>;
typedef pair<int,int> P;// first は最短距離、 second は頂点の番号

signed _main() {
  // 頂点数と辺数
  int N, M, r; cin >> N >> M >> r;

  Graph G(N);
  for (int i = 0; i < M; ++i) {
    int a, b, d;
    cin >> a >> b >> d;
    G[a].push_back(Edge(b,d));
  }

  // BFS のためのデータ構造
  vector<int> dist(N, INF); // 全頂点を「未訪問」に初期化
  priority_queue<P,vector<P>,greater<P>> que;

  // 初期条件 (頂点 0 を初期ノードとする)
  dist[r] = 0;
  que.push(P(0,r)); // 0 を橙色頂点にする

  // BFS 開始 (キューが空になるまで探索を行う)
  while (!que.empty()) {
    P p = que.top(); // キューから先頭頂点を取り出す
    int v=p.second;
    que.pop();

    if(dist[v]<p.first) continue;//
    // v から辿れる頂点をすべて調べる
    for (auto &nv : G[v]) {
      if(dist[nv.to]>dist[v]+nv.weight){
        dist[nv.to]=dist[v]+nv.weight;
        que.push(P(dist[nv.to],nv.to));
      }
    }
  }

  // 結果出力 (各頂点の頂点 0 からの距離を見る)
  for (int v = 0; v < N; ++v){
    if(dist[v]>=INF/2) cout << "INF" << endl;
    else cout << dist[v] << endl;
  }
}



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

int main(){
  int A,B,C,D;
  cin >> A >> B >> C >> D;
  
  if( (A + B) > (C + D)){
    cout << "Left" << endl;
  }else if((A + B) == (C + D)){
    cout << "Balanced" << endl;
  }else{
    cout << "Right" << endl;
  }
  
}

Measured memory_bytes: 256
n,k =map(int,input().split())
trees = sorted([int(input()) for _ in range(n)])
ans = float('inf')
for i in range(n):
  if i+k>n:
    print(ans)
    exit()
  else:
    ans = min(trees[i+k-1]-trees[i], ans)
    if ans==0:
      print(ans)
      exit()

Measured memory_bytes: 8280
var
	N,i,j,ans:int64;
begin
	read(N);
	i:=1;
	while i<=N do begin
		j:=N div(N div i)+1;
		inc(ans,(j-i)*(i+j-1)*(N div i)*(N div i+1)div 4);
		i:=j;
	end;
	writeln(ans);
end.

Measured memory_bytes: 1328
#include <iostream>
#include <fstream>
#include <string>
#include <cmath>
#include <vector>
#include <algorithm>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <cctype>
#include <bits/stdc++.h>
#include <queue>

using namespace std;
// for loop
#define F(i, L, R) for(long i = L; i < R; i++)
#define FE(i, L, R) for(long i = L; i <= R; i++)
// for (reversed)
#define FR(i, L, R) for(long i = L; i > R; i--)
#define FRE(i, L, R) for(long i = L; i >= R; i--)

// data types
#define Int long
#define ul unsigned long
#define ll long long
#define ull unsigned long long
#define ui unsigned int
#define us unsigned shoft

// vectors
typedef vector<int> vi;
typedef vector<long> vl;
typedef vector<long long> vll;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
#define ALL(c) (c).begin(),(c).end()
#define last(vec) vec.size()-1
#define lastEle(vec) vec[last(vec)]
#define pb push_back
#define InputV(a, n) F(i,0,n){long l; cin >> l; a.pb(l);}

// debug
#define DBG(vari) cerr<<#vari<<" = "<<(vari)<<endl;
#define printA(a, L, R) FE(i, L, R) cout << a[i] << (i==R?'\n':' ')
#define printAF(a, L) printA(a, 0, L-1)
#define printV(a) printA(a, 0, a.size()-1)

// utils
#define char2int(c) (c-'0')
#define bit(x, i) (x&(1<<i))
#define space ' '
#define PI 3.14159265358979323

#define TST 0
int main() {
#if TST==1
    ifstream in ("input.txt");
    cin.rdbuf(in.rdbuf());
#endif
    long n;
    cin >> n;
    vl h(n);
    // dp table has mininum cost to go i-1 th 
    vll dp(n);
    F(i, 0, n){
        cin >> h[i];
    }
    dp.assign(n, pow(10, 9));
    dp[0] = 0;
    dp[1] = abs(h[1] - h[0]);
    F(i, 2, n){
        dp[i] = min(dp[i], dp[i-1] + abs(h[i] - h[i-1]));
        dp[i] = min(dp[i], dp[i-2] + abs(h[i] - h[i-2]));
    }
    cout << dp[n-1] << endl;
#if TST==1

#endif
}


Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <cmath>

using namespace std;

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    a[0] = 0;
    for (int i = 1; i < n; i++) {
        cin >> a[i];
    }
    sort(a.begin(), a.end());
    int j = 1;
    for (int i = 1; i < n+1; i++) {
        int cnt = 0;
        while (a[j] == i && j < n) {
            cnt++;
            j++;
        }
        cout << cnt << endl;
    }
}


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

int main(){
	int n, sum, tmp;
	cin >> n;
	vector<int> d(n);
	for(int i=0; i<n; i++){
		cin >> d[i];
	}
	sum = 0;
	for(int i=0; i<n-1; i++){
		for(int j=i+1; j<n; j++){
			sum += d[i]*d[j];
		}
	}
	cout << sum << endl;
	return 0;
}


Measured memory_bytes: 256
# https://atcoder.jp/contests/abc044/tasks/arc060_a
# ソートしてからごちゃごちゃやればどうにかなりそう(無理でした)

'''
解説満点解法1
もしもk枚選んだとき、合計がsになる通りの数がわかったら？→s=k*Aとなる場合の数の合計をすれば良い

k枚選んだとき、合計がsになる通りの数は典型的なDP！
dp(j,k,s)... X[0:j]からk枚選んで、その合計をsにするような選び方の総数
と定義すると、

更新則
dp(j+1,k,s) = X[j]を選んだ結果sになったときの通りの数 + X[j]を選ばずにsになっている通りの数 なので
すなわち
dp(j+1,k,s) = dp(j,k-1,s-X[j]) + dp(j,k,s)

あとは初期条件と境界条件と伝播条件を付け加える。
境界条件 dp(j,k,0)=0 (数枚選んで合計が0になるのはありえない)
初期条件 dp(j,0,0)=1 (ただし、0枚選んだときは1通りとなる)(s-X[j]=0のときに1通りとなってほしいという気持ちもある)
伝播条件 s-X[j]<0に関しては dp(j,k-1,s-X[j])が必ず0通りとなる(ありえないので)
'''

import sys
read = sys.stdin.readline
from itertools import product


def read_ints():
    return list(map(int, read().split()))


N, A = read_ints()
X = read_ints()
# S = sum(X)

# # 満点解法1
# dp = [[[0] * (S + 1) for _ in range(N + 1)] for _ in range(N + 1)]
# for j in range(N + 1):  # 初期条件
#     dp[j][0][0] = 1  # 1枚も選ばずに0になるのは1通り
# # 0,0,0は1でいい∵ j,1,xで1通りになりたいときに1だと都合がいい

# for j, k, s in product(range(N), range(1, N + 1), range(S + 1)):
#     dp[j + 1][k][s] = dp[j][k][s] + \
#         (0 if s - X[j] < 0 else dp[j][k - 1][s - X[j]])

# # s=k*Aとなるような通りの数の総数
# ans = 0
# for k in range(1, N + 1):  # 0個はとる通りの数はいらない
#     s = k * A
#     if s <= S:
#         ans += dp[N][k][s]

# # print(dp)
# print(ans)


'''
満点解法2
平均値の特性からXから差っ引けば、選んだカードの合計が0になれば良くなる。Y=X-Aと定義する。
→そしたらYからいくつか選んで合計tをつくる総数をdpで求めれば良い。(ナップザックDPとコインDPの中間！)

0枚以上選んだときに合計がtに成るかどうか考える

dp(j,t)...Y[:j]の中から0枚以上選んで、その合計を(t-NX)(負になる可能性もあるだけ)にするような選び方の総数
dp(j,t+NX)...Y[:j]の中から0枚以上選んで、その合計をtにするような選び方の総数 この定義のほうがいいかな

更新則
dp(j+1,t+NX) = Y[j]を選んで合計がtになる総和 + Y[j]を選ばずに合計がtになっている総和
つまり
dp(j+1,t+NX) = dp(j,t+NX - Y[j]) + dp(j,t+NX)

境界条件
dp(0,t+NX)=0  一つも考慮しない状態では必ずスコアは作れない
初期条件
dp(0,0+NX)=1 ∵ただし一つも考慮しないならば合計が0になるのは当然1通り
伝播条件
0<=t+NX-Y[j]<=2NXとなる範囲外の場合はdp(j,t+NX - Y[j])を無視 
'''

# 満点解法2
# NXは十分幅を取れていればなんでもいい
# NX = N * max(X) #今回は最低限の幅Sで代用
S = sum(X)

Y = []
for x in X:
    Y.append(x - A)
dp = [[0] * (2 * S + 1) for _ in range(N + 1)]

# 初期条件
dp[0][S] = 1

for j, t in product(range(N), range(-S, S + 1)):
    ts = t + S
    dp[j + 1][ts] = dp[j][ts]
    dp[j + 1][ts] += dp[j][ts - Y[j]] if 0 <= ts - Y[j] <= 2 * S else 0

print(dp[N][S] - 1)


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

vector<string> divide = {"dream", "dreamer", "erase", "eraser"};

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

    reverse(s.begin(), s.end());
    for (int i=0;i<4;++i) reverse(divide.at(i).begin(), divide.at(i).end());

    bool ok = true;
    for (int i=0;i<s.size();) {
        bool can = false;
        for (int j=0;j<4;++j) {
            string d = divide.at(j);
            if (s.substr(i, d.size()) == d) {
                can = true;
                i += d.size();
            }
        }
        if (!can) {
            ok = false;
            break;
        }
    }

    if (ok) cout << "YES" << endl;
    else cout << "NO" << endl;
}

Measured memory_bytes: 512
N = int(input())

def fac(n):
    org = n

    fac = []
    i = 2
    while i * i <= org:
        if n % i == 0:
            ex = 0 # 指数
            while n % i == 0:
                ex += 1
                n //=  i
            fac.append([i, ex])
        i += 1

    if n != 1:
        fac.append([n, 1])
    return fac

def k(c):
    d = (1 + 8*c) ** (1/2)
    return (d - 1) / 2

print(sum(int(k(i[1])) for i in fac(N)))


Measured memory_bytes: 63364
/*
ID: Nipun Paul
LANG: C++
PROB: God knows
*/

#include<bits/stdc++.h>
using namespace std;

int main()
{
    int a,b,sum=0,flag=0;
    cin>>a>>b;
    for(int i=b; i<=a+b-1; i++)
    {
        if(i<=0)
        {
            flag=1;
        }
        sum=sum+i;
        //cout<<i<<endl;
    }
    if(flag==1 && a+b-1>=0)
    {
        cout<<sum<<endl;
    }
    else if(flag==1 && a+b-1<0)
    {
        cout<<sum-(a+b-1)<<endl;
    }
    else
    {
        cout<<sum-b<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("O3")
            #pragma comment(linker, "/stack:200000000")
            #pragma GCC optimize("unroll-loops")
             
            #include <algorithm>
            #include <bitset>
            #include <cassert>
            #include <chrono>
            #include <cmath>
            #include <complex>
            #include <cstdio>
            #include <cstdlib>
            #include <cstring>
            #include <ctime>
            #include <deque>
            #include <functional>
            #include <iomanip>
            #include <iostream>
            #include <iterator>
            #include <limits>
            #include <climits>
            #include <list>
            #include <map>
            #include <numeric>
            #include <queue>
            #include <random>
            #include <ratio>
            #include <set>
            #include <sstream>
            #include <stack>
            #include <string>
            #include <unordered_map>
            #include <unordered_set>
            #include <utility>
            #include <vector>
            using namespace std;
             
            typedef long long ll;
            typedef long double ld;
            #define int ll
            #define double ld
            #define pb push_back
            #define mp make_pair
            #define REP(i,n) for (int i = 0; i < n; i++)
            #define loop(i,n) for (int i = 0; i < n; i++)
            #define FOR(i,a,b) for (int i = a; i < b; i++)
            #define REPD(i,n) for (int i = n-1; i >= 0; i--)
            #define FORD(i,a,b) for (int i = a; i >= b; i--)
            #define remax(a,b) a = max(a,b)
            #define remin(a,b) a = min(a,b)
            #define mem(a, b) memset(a, b, sizeof a)
            #define append push_back
            #define all(v) v.begin(),v.end()
            #define F first
            #define S second
            #define print(x) cout << (x) << endl
            #define PRECISION(x) cout << fixed << setprecision(x)
            #define FAST_IO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
            
            const double PI=acos(-1);
            const int MOD = 1000000007;
            const int FMOD = 998244353;
            const double eps = 1e-9;
             
            mt19937 RNG(chrono::steady_clock::now().time_since_epoch().count()); 
 
signed main(){

	string s;
	cin>>s;
	if(s=="ABC")
	cout<<"ARC";
	else
	cout<<"ABC";
}
			

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

int main(){
    int N;
    cin >> N;
    vector<vector<int>> r(N, vector<int>(2));
    rep(i,N) cin >> r[i][0] >> r[i][1];
    rep(i,N){
        int savea = r[i][0], saveb = r[i][1];
        r[i][1] = savea - saveb;
        r[i][0] = savea + saveb;
    }
    sort(r.begin(), r.end());
    int ans = 1, save = 0;
    for(int i = 1; i < N; i++){
        if(r[i][1] >= r[save][0]){
            ans++;
            save = i;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 5760
//ABC064C
#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <numeric>
#include <math.h>
#include <stdio.h>
#include <climits>
#include <cfloat>
#include <string>
#include <unordered_map>
using namespace std;

int main(){
	int n;
	cin >> n;
	vector<int> a(n);
	set<int> x;
	int num = 0;
	for(int i=0;i<n;i++){
		cin >> a.at(i);
		if(a.at(i) < 3200){
			x.insert(a.at(i)/400);
		}else{
			num++;
		}
	}
	int p;
	if(x.size() == 0){
		p = 1;
	}else{
		p = x.size();
	}
	int q = x.size()+num;
	cout << p << " " << q << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
    #include<stdio.h>
    //#include <bits/stdc++.h>
    #include<vector>
    #include<float.h>
    #include<iomanip>
    #include<algorithm>
    #include<string>
    #include<cstring>
    #include<math.h>
    #include<cmath>
    #include<sstream>
    #include<set>
    #include<map>
    #include<queue>
    #include<cassert>
    #include<cmath>
    #include<cstdint>
     
    #define INF 1e18
    #define rep(i,n)for(int i=0;(i)<(int)(n);i++)
    #define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
    #define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
    #define vec(type,n) vector<type>(n)
    #define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
    #define ALL(a)  (a).begin(),(a).end()
     
    using namespace std;
    using ll = long long;
    using Graph = vector<vector<int>>;
    using P = pair<ll, ll>;
     
const int MOD = 1e9 + 7;

class UnionFind {
    public : 

        vector<int> par;

        UnionFind(int N){
            par = vector<int>(N, -1);
        }

        int parent(int x){
            return par[x];
        }

        int root(int x){
            if(par[x] < 0)return x;
            return par[x] = root(par[x]);
        }

        int size(int x){
            return -par[root(x)];
        }

        void connect(int x, int y){
            int rx = root(x);
            int ry = root(y);
            if(rx == ry)return;

            if(size(rx) < size(ry))swap(rx, ry);

            par[rx] += par[ry];
            par[ry] = rx;

            return;
        }

        bool same(int x, int y){
            return root(x) == root(y);
        }
};


int main(){
   int n;
   cin >> n;
   vector<int> a(n);
   rep(i, n)cin >> a[i];

   UnionFind uf(n + 1);
   vector<bool> seen(n + 1, false);
   rep(i, n){
      if(seen[a[i] - 1])uf.connect(a[i], a[i] - 1);
      seen[a[i]] = true;
   }
   int res = 0;
   rep(i, n){
      res = max(res, uf.size(i));
   }
   cout << n - res << endl;
}


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

int main() {
  int N, M, X, L=0, R=0, p;
  cin >> N >> M >> X;
  for (int i=0; i<M; i++) {
    cin >> p;
    if (p<X) {
      L++;
    }
    else {
      R++;
    }
  }
  int m=min(L, R);
  cout << m << endl;
  
  
}


Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <utility>
#include <set>
#include <algorithm>
using namespace std;
int main(){
  int h,w;
  cin >> h >> w;
  for(int i = 0; h > i; i++){
  for(int j = 0; w > j; j++){
   	string s;
    cin >> s;
    if(s == "snuke"){
     	cout << (char)('A' + j) << i + 1 << endl;
      	return 0;
    }
  }
  }
 	return 0;
}

Measured memory_bytes: 256
n,t=map(int,input().split())
a=[int(i) for i in input().split()]
p=a[0]
l=[]
for i in range(n):
    p=min(p,a[i])
    if a[i]-p>0:
        l.append(a[i]-p)

print(l.count(max(l)))

Measured memory_bytes: 14252
package main

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

func main() {
	n := readI()
	fmt.Println((n + 1) / 2)
}

/*-----------Input utils-----------*/

var sc = bufio.NewScanner(os.Stdin)

func init() {
	if len(os.Args) >= 2 {
		if os.Args[1] == "debug" {
			debug()
		}
	}
	const buf = 200100
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, buf), buf)
}

func debug() {
	testFile, err := os.Open("./test/sample-1.in")
	if err != nil {
		fmt.Fprintln(os.Stderr, "There is no testfile.")
		os.Exit(1)
	}
	sc = bufio.NewScanner(testFile)
}

func readS() string {
	sc.Scan()
	return sc.Text()
}

func readR() []rune {
	return []rune(readS())
}

func readI() int {
	i, _ := strconv.Atoi(readS())
	return i
}

func readF() float64 {
	f, _ := strconv.ParseFloat(readS(), 64)
	return f
}


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

/*#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")*/
#define mp make_pair
#define pb push_back
#define pll pair<LL,LL>
#define pii pair<int,int>
#define y second
#define x first
#define LL long long 
#define sqr(x) ((x)*(x))
#define pi acosl(-1)
#define MEM(x) memset(x,0,sizeof(x))
#define MEMS(x) memset(x,-1,sizeof(x))
using namespace std;
int f[200005];
int Size[200005];
int Find(int x){
    if(f[x]==x)return x;
    return f[x]=Find(f[x]);
}
void solve(){
    int n;
    scanf("%d",&n);
    for(int i = 0;i<=n;i++)f[i]=i,Size[i]=1;
    pair<pii,int> p[200005];
    for(int i = 0;i<n;i++){
        int x,y;
        scanf("%d %d",&x,&y);
        p[i]=mp(mp(x,y),i);
    }
    sort(p,p+n);
    vector<pii> stk;
    for(int i = 0;i<n;i++){
        int Min=p[i].x.y;
        while(stk.size()&&stk.back().x<p[i].x.y){
            int a=Find(stk.back().y);
            int b=Find(p[i].y);
            //printf("%d %d\n",a,b);
            if(a!=b){
                f[b]=a;
                Size[a]+=Size[b];
            }
            Min=min(Min,stk.back().x);
            stk.pop_back();
        }
      //  printf("add %d %d\n",Min,i);
        stk.pb(mp(Min,p[i].y));
    }
    for(int i = 0;i<n;i++){
        printf("%d\n",Size[Find(i)]);
    }
}
int main(){
    int t=1;
    //scanf("%d",&t);
    while(t--){
        solve();
    }
}
/*
1 6 6
2 7 4
3 5 2
4 3 1
5 2 5
6 4 0
7 1 3
*/
/*
100
5
5 4
4 2
4 2 3
5 4 2 3 1
*/


Measured memory_bytes: 9100
#include<iostream>
using namespace std;
int main()
{
	int a,b,c,i;
	cin>>a>>b>>c;
	int x[10]={0};
	x[a]++;
	x[b]++;
	x[c]++;
	int m=0,n=0;
	for(i=1;i<=9;i++)
	{
		if(x[i]==2)
		m=1;
		if(x[i]==1)
		n=1;
	}
	if(m==1 && n==1)
	cout<<"Yes";
	else
	cout<<"No";
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<sstream>
#include<iterator>
#include<list>

using namespace std;

typedef  long long int lint;

#define rep(i, n) for (lint i = 0; i < n; i++)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
#define upper(v,hoge) upper_bound(v.begin(),v.end(),hoge)
#define lower(v,hoge) lower_bound(v.begin(),v.end(),hoge)
#define mp make_pair
#define enld endl

int main() {
	lint N, K;
	cin >> N >> K;
	vector<lint>A(N);
	rep(i, N) {
		cin >> A[i];
	}
	for (lint i = K; i < N; i++) {
		if (A[i - K] < A[i]) {
			cout << "Yes" << enld;
		}
		else {
			cout << "No" << endl;
		}
	}
}

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

int main() {
    int n;
    cin >> n;
    int INF = 1000000;
    vector<int> dp(n+1, INF);
    dp[0] = 0;
    for (int i=1; i<=n; i++) {
        int tmp = dp[i-1] + 1;
        rep(j, 10) {
            if (i-pow(6, j)<0) break;
            tmp = min(tmp, dp[i-pow(6, j)] + 1);
        }
        rep(j, 10) {
            if (i-pow(9, j)<0) break;
            tmp = min(tmp, dp[i-pow(9, j)] + 1);
        }
        dp[i] = tmp;
    }
    cout << dp[n] << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define endl "\n"
#define sz(x) (int)(x).size()
using namespace std;
typedef long long int lli;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

int main() {
    string s;
    cin >> s;
    bool is = false;
    rep(i, 0, 4) {
        if (s[i] == s[i+1])
            is = true;
    }
    if (is)
        cout << "Bad" << endl;
    else
        cout << "Good" << endl;
    return 0;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))
l = [0]*n
l2 = []
for i in range(n):
    if (n-i)*2 > n:
        l[n-i-1] = a[n-i-1]
        if a[n-i-1] == 1:
            l2.append(n-i)
    else:
        count = n//(n-i)
        count1 = 0
        for x in range(2,count+1):
            count1 = l[((n-i)*x)-1] + count1
        if (count1)%2 == a[n-i-1]:
            l[n-i-1] = 0
        else:
            l[n-i-1] = 1
            l2.append(n-i)
print(len(l2))
if len(l2) > 0:
    for i in l2:
        print(i, end=" ")

Measured memory_bytes: 12536
#include <iostream>
#include <string>
#include <vector>
using namespace std;

class Time
{
  public:
    Time(int hour, int min);

  public:
    //  return min
    int operator-(const Time& right) const;

  private:
    int m_hour;
    int m_min;
};

inline Time::Time(int hour, int min) :
  m_hour(hour), m_min(min)
{
}

int Time::operator-(const Time& right) const
{
  int hour_diff = this->m_hour - right.m_hour;
  int min_diff = this->m_min - right.m_min;
  return hour_diff * 60 + min_diff;
}

struct Station
{
  Time time;
  string name;
};

struct Result
{
  int time;
  string name;
};

int main(void)
{
  int station_num, stay_min;
  cin >> station_num >> stay_min;

  Station arrival_sta = { Time(0, 0) , "" };
  Station leave_sta = { Time(0, 0) , "" };

  vector<Result> result;

  int h, m;
  char buf_ch;
  string buf_str;
  cin >> h >> buf_ch >> m >> buf_str;
  while (true)
  {
    cin >> h >> buf_ch >> m >> arrival_sta.name;
    arrival_sta.time = Time(h, m);
    cin >> h >> buf_ch >> m >> leave_sta.name;
    if (cin.eof() ) break;
    leave_sta.time = Time(h, m);

    int t;
    if ( (t = leave_sta.time - arrival_sta.time) >= stay_min)
    {
      result.push_back( {t, leave_sta.name} );
    }
  }

  cout << result.size() << endl;
  for (auto r : result)
  {
    cout << r.name << " " << r.time << endl;
  }
  return 0;
}

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

#define REP(i,n) for(int i=0;i<n;i++)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define EPS (1e-7)

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
typedef pair<double,int> pdi;

int vx[]={0,0,-1,1};
int vy[]={1,-1,0,0};

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

const ll mod=1e9+7;
const int INF=INT_MAX/2;
const int MAX=1e9;

int main(){
	ll n,k;
	cin>>n>>k;
	ll ans=0;
	if(k==0){
		ans=n*n;
		cout<<ans<<endl;
		return 0;
	}
	//a<b
	for(ll a=k;a<=n;a++){
		ans+=(n-a);
	}
	//a>b
	for(ll b=k+1;b<=n;b++){
		ll i=1;
		while(b*i+b-1<=n){
			ans+=(b-k);
			i++;
		}
		if(n>=b*i+k){
			ans+=n-b*i-k+1;
		}
	}
	cout<<ans<<endl;
	return 0;
}

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

using namespace std;

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define INF (1LL << 55)
#define MOD (1000 * 1000 * 1000 + 7)
#define maxn 200111

typedef long long ll;
typedef long double ld;

char str[maxn];
int dp[1 << 26];
int num[maxn];
int pre[maxn];

int main(){
	int n;	
	scanf("%s", str + 1);
	n = strlen(str + 1);
	for(int i = 0; i < (1 << 26); i++)
		dp[i] = 1e9;

	dp[0] = 0;
	pre[0] = 0;
	for(int i = 1; i <= n; i++)
		pre[i] = pre[i - 1] ^ (1 << (str[i] - 'a'));

	num[0] = 0;
	for(int i = 1; i <= n; i++){
		num[i] = 1e9;					
		num[i] = min(num[i], dp[pre[i]] + 1); // all characters even number of time
		for(int j = 0; j < 26; j++){		  // one character odd number od times
			int x = pre[i] ^ (1 << j);
			num[i] = min(num[i], dp[x] + 1);
		}
		dp[pre[i]] = min(dp[pre[i]], num[i]);
	}
	printf("%d\n", num[n]);
	return 0;
}

Measured memory_bytes: 264192
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_map>
#include <map>

//#define INF 100000000
//#define MOD (int) (1e9+7)
#define rep(i, a) for (int i = 0; i < (a); i++)
using namespace std;

const int MAX = 1000000;
const int MOD = 1000000007;

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

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        //そのまま計算すると負の値になるのでMODを足す
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

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

int main(){
    long long int n, m;
    cin >> n >> m;

    if(m == 1){
        //全部1の1通りしかありえない
        cout << 1 << endl;
        return 0;
    }

    long long int i;
    map<long long int, long long int> prime;

    //素因数分解
    long long int tmp = m;
    for(i = 2; i * i <= m; i++){
        long long int count = 0;
        while(tmp%i == 0){
            tmp /= i;
            count++;
        }
        prime[i] = count;
    }
    if(tmp*tmp > m) prime[tmp] += 1;

    COMinit();
    long long int ans = 1;
    for(auto itr = prime.begin(); itr != prime.end(); itr++){
        long long int val = itr->second;
        ans = (ans * COM(n+val-1, val))%MOD;
    }

    cout << ans << endl;
}


Measured memory_bytes: 25600
n, k = map(int, input().split())
a = list(map(int, input().split()))
mini = a.index(1)
l = mini // (k-1)
lm = mini % (k-1)
r = (n - mini - 1) // (k-1)
rm = (n - mini - 1) % (k-1)
# print(l, r, lm, rm)
print(l + r + ((lm + rm + 1) // k + ((lm + rm + 1) % k != 0 and (lm + rm) != 0)))

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

const int INF=1e9+1;

int main() {
  int n; cin>>n;
  vector<int> a(n);
  rep(i, n) cin>>a[i];

  vector<int> dp(n, INF);
  dp[0]=0;
  dp[1]=abs(a[1]-a[0]);
  for (int i=1; i<n-1; i++) {
    dp[i+1]=min(dp[i]+abs(a[i+1]-a[i]), dp[i-1]+abs(a[i+1]-a[i-1]));
  }
  cout<<dp[n-1]<<endl;
}


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

#define fi first
#define se second

const int N = 200200;
const long long mod = 1e9 + 7;

using namespace std;

int n;

vector < vector < int > > mult(vector < vector < int > > x, vector < vector < int > > y)
{
        vector < vector < int > > res(n);
        for(int i = 0; i < n; i++){
                for(int j = 0; j < n; j++){
                        res[i].push_back(0);
                        for(int h = 0; h < n; h++){
                                res[i][j] += 1ll * x[i][h] * y[h][j] % mod;
                                if(res[i][j] >= mod){
                                        res[i][j] -= mod;
                                }
                        }
                }
        }
        return res;
}

vector < vector < int > > pw(vector < vector < int > > x, long long n)
{
        if(n == 1){
                return x;
        }
        if(n % 2){
                return mult(x, pw(x, n - 1));
        }
        else{
                return pw(mult(x, x), n / 2);
        }
}

int main()
{
        //freopen("input.txt", "r", stdin);
        //freopen("output.txt", "w", stdout);
        ios_base::sync_with_stdio(0);

        long long k;
        cin >> n >> k;
        vector < vector < int > > v(n);
        for(int i = 0; i < n; i++){
                v[i].resize(n);
                for(int j = 0; j < n; j++){
                        cin >> v[i][j];
                }
        }
        v = pw(v, k);
        int res = 0;
        for(int i = 0; i < n; i++){
                for(int j = 0; j < n; j++){
                        res += v[i][j];
                        if(res >= mod){
                                res -= mod;
                        }
                }
        }
        cout << res << "\n";
}



Measured memory_bytes: 3072
import java.util.Scanner;
public class Main {
    public static void main(String[] args){
    
    Scanner sc = new Scanner(System.in);
    String S = sc.next();
    char[]ss = S.toCharArray();

    int all = 0;
      for(int i=0; i<S.length(); i++) {
    	all += ss[i]-48;
}
      if(Integer.valueOf(S)%all == 0){
      System.out.println("Yes");
      }else{
      System.out.println("No");
    }
}
}

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

long long int mod = 1000000007;

long long int kaijo(int x){
	long long int result = 1;
	for (int i = 1; i <= x; ++i){
		result = ((result % mod)*(i % mod)) % mod;
	}
	return result;
}

int main(){
	long long int n, m, r;
	cin >> n >> m;
	if (abs(n - m) >= 2){
		cout << "0" << endl;
		return 0;
	}
	r = kaijo(n) * kaijo(m);
	if (n == m){
		r *= 2;
	}
	cout << r % mod << endl;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>

int main() {
	char ABCD[5];
	std::scanf("%s", ABCD);
	int A, B, C, D;
	A = ABCD[0] - '0';
	B = ABCD[1] - '0';
	C = ABCD[2] - '0';
	D = ABCD[3] - '0';

	for (int i = 0; i <= 0b111; ++i) {
		int sum = A;
		char op1, op2, op3;
		if (i & 0b100) {
			sum += B;
			op1 = '+';
		} else {
			sum -= B;
			op1 = '-';
		}
		if (i & 0b010) {
			sum += C;
			op2 = '+';
		} else {
			sum -= C;
			op2 = '-';
		}
		if (i & 0b001) {
			sum += D;
			op3 = '+';
		} else {
			sum -= D;
			op3 = '-';
		}
		if (sum == 7) {
			char ans[10] = { A + '0', op1, B + '0', op2, C + '0', op3, D + '0', '=', '7', '\0' };
			std::printf("%s", ans);
			break;
		}
	}
}

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

const long long MOD = 1000000007;
const long long INF = 1LL << 60;
const int INT_INF = 1000000000;

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

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll A, B, N;
  cin >> A >> B >> N;
  ll x = min(N, B - 1);
  ll ans = (A * x) / B - A * (x / B);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3604
// inputに入力データ全体が入る
function Main(input) {

  var inp = input.split(" ");
  var N = parseInt(inp[0]);
  var A = parseInt(inp[1]);
  var B = parseInt(inp[2]);

  var ans = 0;
  for (var i = 1; i <= N; i++) {
    var sum = 0;
    var j = String(i);

    sum += parseInt(j.substr(0, 1));

    if (i >= 10) {
      sum += parseInt(j.substr(1, 1));
    }

    if (i >= 100) {
      sum += parseInt(j.substr(2, 1));
    }

    if (i >= 1000) {
      sum += parseInt(j.substr(3, 1));
    }
    
    if (sum >= A && sum <= B) {
      ans += i;
    }
  }

  console.log('%d', ans);

}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 8488
#include<cstdio>
#define ll long long
const int N=1e5+5,mo=1e9+7;
int n,i,lx,rx,ly,ry;
ll dx,dy,a[N],fx[N],gx[N],fy[N],gy[N];
ll read(){
	char c=getchar();ll k=0;for (;c<48||c>57;c=getchar());
	for (;c>47&&c<58;c=getchar()) k=(k<<3)+(k<<1)+c-48;return k;
}
int main(){
	n=read();dx=read();dy=read();
	for (i=1;i<=n;i++) a[i]=read();
	a[n+1]=2e18;fx[0]=gx[0]=fy[0]=gy[0]=1;
	for (i=1;i<=n;i++){
		if (a[i]-a[i-1]<dx) lx=i-1;
		if (a[i]-a[i-1]<dy) ly=i-1;
		for (;rx+1<i&&a[rx+1]<=a[i+1]-dy;rx++);
		for (;ry+1<i&&a[ry+1]<=a[i+1]-dx;ry++);
		if (lx<=rx) fx[i]=(gy[rx]-(lx?gy[lx-1]:0))%mo;
		if (ly<=ry) fy[i]=(gx[ry]-(ly?gx[ly-1]:0))%mo;
		gx[i]=(gx[i-1]+fx[i])%mo;
		gy[i]=(gy[i-1]+fy[i])%mo;
	}
	int ans=(fx[n]+fy[n])%mo;
	printf("%d",(ans+mo)%mo);
}

Measured memory_bytes: 4096
#include <bits/stdc++.h>
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;

int main() {
    string s;
    int k, cnt = 0;
    cin >> s >> k;
    vector<int> d;
    rep(i, s.size())d.push_back(s[i]-'0');
    vector<vector<vector<int>>> dp(d.size()+1, vector<vector<int>>(k+1, vector<int>(2, 0)));
    dp[0][0][1] = 1;
    REP(i, d.size()){
        rep(j, k+1){
            dp[i][j][0] += dp[i-1][j][0];
            if(d[i-1] == 0)dp[i][j][1] += dp[i-1][j][1];
            else{
                dp[i][j][0] += dp[i-1][j][1];
                if(j != 0){
                    dp[i][j][1] += dp[i-1][j-1][1];
                    dp[i][j][0] += dp[i-1][j-1][1] * (d[i-1]-1);
                }
            }
            if(j != 0)dp[i][j][0] += dp[i-1][j-1][0] * 9;
        }
    }
    cout << dp[d.size()][k][0] + dp[d.size()][k][1] << endl;
}

Measured memory_bytes: 256
//   _/                _/                 _/_/_/   _/
//_/_/_/_/   _/_/   _/_/_/_/   _/_/    _/       _/_/
// _/     _/    _/   _/     _/    _/  _/_/_/     _/
//_/     _/    _/   _/     _/    _/  _/    _/   _/
// _/_/   _/_/       _/_/   _/_/      _/_/     _/
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const double pi=3.14159265358979323846;
const int inf=2e9;
const ll INF=5e18;
typedef pair<int,int> P;
int main() {
  cin.tie(0),cout.tie(0);
  ios::sync_with_stdio(false);
  int n,ans=0,c1=0,c2=0,cnt1=0,cnt2=0,y,z;
  cin >> n;
  int p[n]={},q[n]={},x[n]={};
  for(int i=0; i<n; i++) {
    cin >> p[i];
  }
  for(int i=0; i<n; i++) {
    cin >> q[i];
  }
  for(int i=0; i<n; i++) {
    x[i]=i+1;
  }
  do{
    cnt1++;
    cnt2++;
    c1=0,c2=0;
    for(int i=0; i<n; i++) {
      if(x[i]==p[i]) {
        c1++;
      }
      if(x[i]==q[i]) {
        c2++;
      }
      if(c1==n) {
        y=cnt1;
      }
      if(c2==n) {
        z=cnt2;
      }
    }
  }while(next_permutation(x,x+n));
  cout << abs(y-z) << endl;
    
}

Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <deque>
#include <iostream>
#include <map>
#include <math.h>
#include <set>
#include <string.h>
#include <vector>
using namespace std;

// デバッグ用
#define _DEBUG
#ifdef _DEBUG
#define dlog(str) cout << "====" << str << endl;
#else
#define dlog(str)
#endif
// ここまで
#define INF 999999999
#define REP(i, n) for(int i = 0, i##_l = (n); i < i##_l; i++)
#define REPR(i, n) for(int i = n - 1; 0 <= i; i--)
#define FOR(i, s, e) for(int i = s; i <= e; i++)
#define FORR(i, s, e) for(int i = s; e <= i; i--)
#define LLI long long int
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define bit(a, shift) ((a>>shift)&1))
#define ALL(v) (v).begin(), (v).end()
#define SORT(v) sort(ALL(v))

int main() {
    int N;
    cin >> N;
    int ma = 0, cu, c = 0;
    REP(i, N) {
        cin >> cu;
        if(ma <= cu) {
            c++;
            chmax(ma, cu);
        }
    }
    cout << c;
    return 0;
}

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

typedef struct _book_
{
    unsigned price;
    unsigned *level;
} book;

book *scan_books(unsigned N, unsigned M)
{
    book *b = malloc(sizeof(book) * N);
    for (size_t i = 0; i < N; i++)
    {
        b[i].level = malloc(sizeof(unsigned) * M);
        scanf("%u", &b[i].price);
        for (size_t j = 0; j < M; j++)
        {
            scanf("%u", &b[i].level[j]);
        }
    }
    return b;
}

int main(int argc, char const *argv[])
{
    unsigned N, M, X;
    scanf("%u %u %u", &N, &M, &X);
    book *books = scan_books(N, M);

    unsigned limit = 1;
    limit <<= N;
    unsigned *combi = malloc(sizeof(unsigned) * limit);

    unsigned lowest_cost = 4294967295;
    for (unsigned i = 0; i < limit; i++)
    {
        unsigned combi = i;
        unsigned cost_sum = 0;
        unsigned *level_sum = calloc(M, sizeof(unsigned));
        for (size_t j = 0; j < N; j++)
        {
            if (combi & 1)
            {
                cost_sum += books[j].price;
                for (size_t k = 0; k < M; k++)
                {
                    level_sum[k] += books[j].level[k];
                }
            }
            combi >>= 1;
        }
        for (size_t j = 0; j < M; j++)
        {
            if (level_sum[j] < X)
            {
                goto CONTINUE;
            }
        }

        lowest_cost = lowest_cost > cost_sum ? cost_sum : lowest_cost;
        CONTINUE: continue;
    }

    if (lowest_cost == 4294967295)
    {
        printf("-1\n");
    } else
    {
        printf("%u\n", lowest_cost);
    }

    return 0;
}


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

int main() {
  ll k, a, b;
  cin >> k >> a >> b;
  ll ans = 1;
  if (a >= b) {
    cout << ans + k << endl;
    return 0;
  }

  if (k < a - 1) {
    cout << ans + k << endl;
    return 0;
  }

  if (a + 1 == b) {
    cout << ans + k << endl;
    return 0;
  }

  k -= (a - 1);

  ans = a;
  if (k % 2 == 0) {
    ans += (b - a) * k / 2;
  } else {
    ans += (b - a) * (k / 2) + 1;
  }

  cout << ans << endl;
}


Measured memory_bytes: 256