akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <utility>
#include <cmath>

#define ll long long int
#define pb push_back
#define mk make_pair
#define pq priority_queue

using namespace std;
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
const int inf = 1e9;
const ll linf = 1LL << 50;

int a, b;
int n;
ll ans[17][17];

int main(int argc, char const* argv[])
{
  while(true){
    cin >> a >> b;
    if(a == 0)break;
    cin >> n;
    for(int i = 0; i < a; i++){
      for(int j = 0; j < b; j++){
        ans[i][j] = -1;
      }
    }
    for(int i = 0; i < n; i++){
      int x, y;
      cin >> x >> y;
      x--; y--;
      ans[x][y] = 0;
    }
    ans[0][0] = 1;
    for(int i = 0; i < a; i++){
      for(int j = 0; j < b; j++){
        if(ans[i][j] != -1)continue;
        ans[i][j] = 0;
        if(i != 0)ans[i][j] += ans[i-1][j];
        if(j != 0)ans[i][j] += ans[i][j-1];
      }
    }
    cout << ans[a-1][b-1] << endl;
  }
	return 0;
}



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

#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define REP(i,n) FOR(i,0,n)
using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using mii = map<int, int>;
using msi = map<string, int>;
using pii = pair<int, int>;

struct Edge {
    int to;     // 辺の行き先
    int weight; // 辺の重み
    Edge(int t, int w) : to(t), weight(w) { }
};
using Graph = vector<vector<Edge>>;

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

    vector<pii> x(n);
    REP(i, n) {
        int a, b;
        cin >> a >> b;
        x[i].first = a + b;
        x[i].second = a - b;
    }
    sort(x.begin(), x.end());
    int ans = 0, t = -1e9;
    REP(i, n) {
        if(t <= x[i].second) {
            ans++;
            t = x[i].first;
        }
    }
    cout << ans << endl;

     
    return 0;
}

Measured memory_bytes: 1024
# nimber: 0, 1, 2, 1, 4, 1, 2, 1, 8, 1, 2, 1, 4, 1, 2, 1, 16, 1, 2, 1, 4, 1, 2, 1, 8, 1, 2, 1, 4, 1, 2, 1, 32, ...

class Node:
    def __init__(self, size, avail):
        self.end = False
        self.nxt = [None] * size
        self.avail = avail
    def __setitem__(self, i, x): self.nxt[i] = x
    def __getitem__(self, i): return self.nxt[i]

def makeTrie(strs, size):
    root = Node(size, l)
    for s in strs:
        n = root
        for c in s:
            i = int(c) # Change this to adapt. ex: ord(c)-ord("A")
            if not n[i]: n[i] = Node(size, n.avail-1)
            n = n[i]
        n.end = True
    return root

def nimber(n):
    x = 1
    while n%2 == 0: n//= 2; x*= 2
    return x

input = __import__('sys').stdin.readline
n, l = map(int,input().split())
strs = [input().rstrip() for i in range(n)]
T = makeTrie(strs, 2)

ans = 0
stack = [T]
while stack:
    n = stack.pop()
    for i in 0, 1:
        if not n[i]: ans^= nimber(n.avail)
        elif not n[i].end: stack.append(n[i])
print("Alice" if ans else "Bob")

Measured memory_bytes: 58332
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int) n; i++)
using ll = long long;
template <class T>
using vt = std::vector<T>;
using vvi = std::vector<vt<int>>;

int main(){
  int n, cnt = 1;
  bool up = false, down = false;
  std::cin >> n;
  rep(i,n){
    ll a, tmp;
    std::cin >> a;
    if(i == 0){
      tmp = a;
      continue;
    }
    if(a > tmp) up = true;
    else if(tmp > a) down = true;
    if(up && down){
      cnt++;
      up = false; down = false;
    }
    tmp = a;
  }

  std::cout << cnt << '\n';
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <cmath>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#define rep(i,n) for (int i=0;i<n;i++)
using ll = long long;
using namespace std;

void solve(){

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

    string s;
    string t;
    cin >> s >> t;
    int sl = s.size();
    int tl = t.size();

    int smin = min(sl,tl);

    sort(s.begin(),s.end());
    sort(t.begin(),t.end(),greater<int>());


    if(s<t){
        cout << "Yes";
    }
    else{
        cout << "No";
    }



    return 0;
}

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

using namespace std;

string n;
vector<int> num;
long long dp[200005][2][100], k, d;
const long long oo = 1e9 + 7;

void get_num(string s, vector<int> &num)
{
    for (int i = 0; i < s.size(); i++)
    {
        num.push_back(s[i] - '0');
    }
}
long long calc(int idx, int tight, int mod) 
{
    if (idx == num.size())
        if (mod % k == 0)
            return 1;
        else
            return 0;
    if (dp[idx][tight][mod] != -1)
        return dp[idx][tight][mod];
    long long t = 0;
    int luu;
    if (tight == 1)
        luu = num[idx];
    else
        luu = 9;
    for (int i = 0; i <= luu; i++)
    {
        int new_tight = tight;
        if (tight == 1 && i < luu)
            new_tight = 0;
        t = (t + calc(idx + 1, new_tight, (i + mod) % k)) % oo;
    }
    dp[idx][tight][mod] = t % oo;
    return dp[idx][tight][mod] % oo;
}

long long solve(string s)
{
    num.clear();
    memset(dp, -1, sizeof(dp));
    get_num(n, num);
    return calc(0, 1, 0);
}

int main()
{
    cin >> n >> k;
    cout << ((solve(n) - 1)+oo) % oo;
}

Measured memory_bytes: 313728
// https://atcoder.jp/contests/abc099/tasks/abc099_d
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define DIV(a, b) ((a - 1) / b + 1)

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N, C;
    cin >> N >> C;
    vector<vector<int>> D(C, vector<int>(C));
    REP(i, C) REP(j, C) { cin >> D[i][j]; }
    vector<vector<int>> E(N, vector<int>(N));
    REP(i, N) REP(j, N) {
        cin >> E[i][j];
        E[i][j]--;
    }
    // 予め色を変更した違和感を計算
    vector<vector<int>> iwa(3, vector<int>(C));
    REP(c, C) REP(i, N) REP(j, N) { iwa[(i + j) % 3][c] += D[E[i][j]][c]; }

    // 異なる色を３種類決める
    int minv = 1e9;
    REP(c1, C) {
        REP(c2, C) {
            if (c1 == c2)
                continue;
            REP(c3, C) {
                if (c1 == c3 || c2 == c3)
                    continue;
                int sum = iwa[0][c1] + iwa[1][c2] + iwa[2][c3];
                minv = min(minv, sum);
            }
        }
    }
    cout << minv << endl;

    return 0;
}


Measured memory_bytes: 2304
A,B,M=map(int,input().split())
AList=list(map(int,input().split()))
BList=list(map(int,input().split()))

ans = min(AList) + min(BList)
arr = []
arr.append(ans)

for i in range(M):
  x,y,c=map(int,input().split())
  
  a = AList[x-1]
  b = BList[y-1]
  arr.append(int(a+b-c))
  
print(min(arr))

Measured memory_bytes: 73196
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_B main
#include "bits/stdc++.h" 
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LONG_MAX/2)
const int MGN = 8;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>;
// functions
ll count_div(ll n, ll m) {
    if (n%m != 0) return 0;
    else return 1 + count_div(n/m, m);
}
#endif


int main_B() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll D, N; cin >> D >> N;

    ll M = 1;
    REP(i, D) M *= 100;

    ll ans = 0;
    int j = 0;
    FOR(i,1,(N+2)*M) {
        if (count_div(i, 100) == D) {
            j++;
        
            if (j == N) {
                ans = i;
                break;
            }
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<vector>
using namespace std;

const int N=607,INF=1e9;
int n,m,a[N*N],b[N*N];
vector <int> V[N];
double  f[N],ans;
double calc(int p)
{
    for(int i=1;i<=n;i++) f[i]=0;
    f[n]=0;
    for(int i=n-1;i>=1;i--)
    {
        int len=V[i].size();
        if(p==i&&len==1) { f[i]=INF; continue; }
        double t=1.0/(len-(p==i)),mx=0;
        for(int j=0;j<len;j++)
        {
            int v=V[i][j]; mx=max(mx,(f[v]+1)*t);
            f[i]+=(f[v]+1)*t;
        }
        if(p==i) f[i]-=mx;
    }
    return f[1];
}
int main()
{
    scanf("%d%d",&n,&m);

    for(int i=1;i<=m;i++)
    {
        scanf("%d%d",&a[i],&b[i]);
        V[a[i]].push_back(b[i]);
    }
    ans=calc(0);
    for(int i=1;i<=n;i++)
        ans=min(ans,calc(i));
    printf("%.9lf\n",ans);
    return 0;
}




Measured memory_bytes: 2816
#include<bits/stdc++.h>
using namespace std;
#define pii pair<int,int>
#define fi first
#define se second
#define pb push_back
typedef long long ll;


ll a[100];
int main(){
    ll n,sk=0;
    ll mn=1000;
    scanf("%lld",&n);
    for(int i=0;i<n;i++){
        scanf("%lld",&a[i]);
    }
    for(int i=0;i<n;i++){
        if(a[i]<=a[i+1]&&(!i||a[i]<a[i-1])){
            //cout<<mn/a[i]<<' '<<a[i]<<endl;
            sk+=mn/a[i];
            mn-=mn/a[i]*a[i];
        }
        while(a[i]<=a[i+1]&&i<n) i++;
        mn+=a[i]*sk;
        //cout<<mn<<endl;
        sk=0;
    }
    printf("%lld",mn);
}


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

lis = sorted(list(map(int, input().split())))

query = []
for i in range(m):
    b, c = map(int, input().split())
    query.append([c, b])

query.sort(reverse = 1)

i = 0
for j in query:
    for k in range(j[-1]):
        if i < n:
            if lis[i] < j[0]:
                lis[i] = j[0]
                i += 1 
            else:
                break
        else:
            break
        
print(sum(lis))

Measured memory_bytes: 24512
#include <algorithm>
#include <iostream> //入出力
#include <stdio.h>
#include <map>
#include <set>
#include <string>
#include <math.h> //算術演算子
#include <vector>
#include <cstdlib>
#include <queue>
#include <stack>
#include <list>
#include <iomanip> //小数点以下を表示させる(setprecision())
//#include <bits/stdc++.h>
using namespace std;
typedef long long ll; //64bit型

#define debug(x) cerr << x << " " \
                      << "(L:" << __LINE__ << ")" << '\n'
#define PRINT(V)                                   \
        {                                          \
                for (int i = 0; i < V.size(); i++) \
                {                                  \
                        cout << V[i] << " ";       \
                }                                  \
                cout << endl;                      \
        }

int gcd(int a, int b)
{
        return b ? gcd(b, a % b) : a;
}

int main()
{
        //input->compute->output//
        int N, S, B;
        cin >> N >> S >> B;
        cout << min({N+S,N+B,S+B}) << endl;

        return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#include <tuple>
#include <cassert>
#include <functional>
#include <set>
#include <deque>
using namespace std;
typedef long long ll;
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
const int INF = 1<<29;
#define LNF __LONG_LONG_MAX__
const ll MOD = 1000000007;
const int MAX = 200000;

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

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

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
// 法mでのaの逆元を計算
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
//最大公約数
int gcd(int x, int y) { return (x % y)? gcd(y, x % y): y; }
//最小公倍数
int lcm(int x, int y) { return x / gcd(x, y) * y; }
// nが大きく,kが10^7程度の時の二項係数
long long com[200005];
void combination(long long n,long long k){
    com[0] = 1;
    for(int i=1;i<=k;i++){
        com[i] = (com[i-1]*(n-i+1)%MOD)*modinv(i,MOD)%MOD;
    }
}

int main(){
    int N,M; cin >> N >> M;
    vector<int> a(N,0);
    for(int i=0;i<M;i++){
        int x,y; cin >> x >> y;
        x--;y--;
        a[x]++;
        a[y]++;
    }
    for(int i=0;i<N;i++){
        cout << a[i] << endl;
    }
    return 0;
}


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

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

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

//Minimum ways to reach from 1 to n
//(frog1)

int n;
int a[100005];
int dp[100005];

int solve(int ind)
{
	if (ind >= n - 1)//No of ways to reach last step when we are at last step
	{
		return 0;
	}
	if (dp[ind] != -1)
	{
		return dp[ind];
	}

	int op1 = (ind + 1 >= n) ? INT_MAX : abs(a[ind] - a[ind + 1]) + solve(ind + 1);

	int op2 = (ind + 2 >= n) ? INT_MAX : abs(a[ind] - a[ind + 2]) + solve(ind + 2);

	return dp[ind] = min(op1, op2);
}

int32_t main()
{
	FIO();
	cin >> n;

	for (int i = 0; i < n; i++)
		cin >> a[i];

	memset(dp, -1, sizeof(dp));

	cout << solve(0) << '\n';
	return 0;
}

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

int main() {
  int n, m;
  cin>>n>>m;
  int a[m];
  for (int i=0; i<m; i++) cin>>a[i];
  int sum = 0;
  for (int i=0; i<m; i++) sum += a[i];
  if (sum > n) {
    cout<<-1<<endl;
  } else {
    cout<<n - sum<<endl;
  }
}

Measured memory_bytes: 3652
//https://onlinejudge.u-aizu.ac.jp/challenges/sources/PCK/Prelim/0316?year=2015

#include <bits/stdc++.h>

using namespace std;

int main() {
    int h1, h2, k1, k2;
    cin >> h1 >> h2 >> k1 >> k2;

    int a, b, c, d;
    cin >> a >> b >> c >> d;

    int hiroshi = h1 * a + h2 * b + (h1 / 10) * c + (h2 / 20) * d;
    int kenjiro = k1 * a + k2 * b + (k1 / 10) * c + (k2 / 20) * d;

    if (hiroshi > kenjiro) {
        cout << "hiroshi" << endl;
    } else if (hiroshi < kenjiro) {
        cout << "kenjiro" << endl;
    } else {
        cout << "even" << endl;
    }
    return 0;
}

/*
 *
 */


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

string str;

void change(){
    for(char i = 'a' ; i <= 'z' ; i++) str[i] = i;
    for(char i = 'A' ; i <= 'Z' ; i++) str[i] = i;
    for(char i = '0' ; i <= '9' ; i++) str[i] = i;
}

int main(){
    int n;
    
    while(cin >> n,n){
        str = "";
        change();
        char a,b;
        for(int i = 0 ; i < n ; i++){
            cin >> a >> b;
            str[a] = b;
        }
        string tmp = "";
        int m; char c;
        cin >> m;
        for(int i = 0 ; i < m; i++){
            cin >> c;
            tmp += str[c];
        }
        cout << tmp << endl;
    }
    
    return 0;
}

Measured memory_bytes: 1336
h, w = map(int,input().split())
arr = [input() for i in range(h)]
ans = []
for s in arr:
  ans.append(list(s))
dx = [1, 0, -1, 0, 1, -1, -1, 1]
dy = [0, 1, 0, -1, 1, 1, -1, -1]
for y in range(h):
  for x in range(w):
    if arr[y][x] == "#":
      continue
    num = 0
    for dx1,dy1 in zip(dx,dy):
      if x+dx1 < 0 or x+dx1 >= w:
        continue
      elif y+dy1 < 0 or y+dy1 >= h:
        continue
      if arr[y+dy1][x+dx1] == "#":
        num += 1
    ans[y][x] = num
for i in ans:
  print("".join(map(str,i)))

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

int main(void) {

    string S; cin>>S;
    if(S=="SUN") cout<<7<<endl;
    else if(S=="MON") cout<<6<<endl;
    else if(S=="TUE") cout<<5<<endl;
    else if(S=="WED") cout<<4<<endl;
    else if(S=="THU") cout<<3<<endl;
    else if(S=="FRI") cout<<2<<endl;
    else if(S=="SAT") cout<<1<<endl;
    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

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

#define int long long
#define endl '\n'

const int N = 200005;

signed main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	string s;
	cin >> s;
	string t;
	cin >> t;
	int ans = 0;
	for(int i = 0 ; i < 3 ; i ++)
		if(s[i] == t[i]) ans ++;
	cout << ans;
}


Measured memory_bytes: 256
#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() {
	ios::sync_with_stdio(false);
	cin.tie(0);

	ll a, b;
	cin >> a >> b;
	ll n;
	n = a * b;
	if (b > a)
		swap(a, b);
	while (a % b)
	{
		ll temp;
		temp = b;
		b = a % b;
		a = temp;
	}
	cout << n / b << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,b) for(ll i=0;i<b;i++)
ll mod=1000000007;
#define vl vector<ll>
#define pl pair<ll,ll>
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define RFOR(i,a,b) for(ll i=b-1;i>=a;i--)
#define rsort(v) sort((v).rbegin(), (v).rend())
#define all(v) (v).begin(),(v).end()

ll n,r,l,ans;

int main()
{
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>r;
        if(r>l)ans+=r-l;
        l=r;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
import java.util.*;

class Main {

  public static void main(String args[]) {
    Scanner sc = new Scanner(System.in);

    int n = sc.nextInt();
    int l[] = new int[100003];
    for (int i = 0; i < n; i++) {
      l[sc.nextInt()]++;
      l[sc.nextInt()+1]--;
    }
    for (int i = 1; i < 100003; i++)
      l[i] += l[i-1];
    int max = 0;
    for (int i = 1; i <= n + 1; i++) {
      if (i - 1 <= l[i]) {
        max = i - 1;
      }
    }
    System.out.println(max);
  }
}



Measured memory_bytes: 100384
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static string[] s_rd;
T RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }
T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
long lcm(long x, long y) { return x * y / gcd(x, y); }

long mod = 10^^9 + 7;
//long mod = 998244353;
//long mod = 1_000_003;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }

void main()
{
	auto N = RD;
	auto AB = new long[2][](N);
	foreach (i; 0..N)
	{
		AB[i] = [RD, RD];
	}

	long ans;
	foreach_reverse (i; 0..N)
	{
		auto a = AB[i][0] + ans;
		auto b = AB[i][1];
		auto x = b * ((a / b) + (a % b != 0 ? 1 : 0));
		ans   += x - a;
	}

	writeln(ans);
	stdout.flush();
	debug readln();
}


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

int main(){

    string r, g, b;
    cin >> r >> g >> b;

    int num;
    string s = r + g + b;

    istringstream iss(s);
    iss >> num;

    cout << ((num % 4 == 0) ? "YES" : "NO") << endl;
    return 0;
}

Measured memory_bytes: 256
import sys
input = lambda: sys.stdin.buffer.readline()

L = 26
d = int(input())
c = list(map(int, input().split()))
s = [list(map(int, input().split())) for _ in range(d)]

t = [int(input()) for _ in range(d)]

def evl(a):
    score = 0
    last = [-1] * L
    for i, x in enumerate(a):
        x -= 1
        score += s[i][x]
        last[x] = i
        for j, l in enumerate(last):
            score -= c[j] * (i - l)
        print(score)
    
    return score

evl(t)


Measured memory_bytes: 68480
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;

int main() {
  int N, M;
  cin >> N >> M;

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

  vector<int> dist(N, -1);
  queue<int> que;

  dist[0] = 0;
  que.push(0);

  while (!que.empty()) {
    int v = que.front();
    que.pop();

    for (int nv : G[v]) {
      if (dist[nv] != -1) continue;
      dist[nv] = dist[v] + 1;
      que.push(nv);
    }
  }

  if (dist[N - 1] == 2)
    cout << "POSSIBLE" << endl;
  else
    cout << "IMPOSSIBLE" << endl;
}

Measured memory_bytes: 13296
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#include <bits/stdc++.h>
using namespace std;
template<class t> inline t read(t &x){
	char c=getchar();bool f=0;x=0;
	while(!isdigit(c)) f|=c=='-',c=getchar();
	while(isdigit(c)) x=(x<<1)+(x<<3)+(c^48),c=getchar();
	if(f) x=-x;return x;
}
template<class t,class ...A> inline void read(t &x,A &...a){
	read(x);read(a...);
}
template<class t> inline void write(t x){
	if(x<0) putchar('-'),write(-x);
	else{if(x>9) write(x/10);putchar('0'+x%10);}
}

#define int long long
#define x first
#define p second
#define pii pair<int,int>

const int N=2e5+5;
priority_queue<pii> q;
int n,a[N],b[N],ans;

void GG(){
	write(-1);
	exit(0);
}

signed main(){
	read(n);
	for(int i=1;i<=n;i++) read(a[i]);
	for(int i=1;i<=n;i++) read(b[i]);
	for(int i=1;i<=n;i++) if(a[i]>b[i]) GG();
	for(int i=1;i<=n;i++) if(b[i]>a[i]) q.push(pii(b[i],i));
	while(!q.empty()){
		int p=q.top().p,x=p-1,y=p+1;q.pop();
		if(!x) x=n;
		if(y>n) y=1;
		if(a[p]>=b[x]&&a[p]>=b[y]){
			if((b[p]-a[p])%(b[x]+b[y])) GG();
			ans+=(b[p]-a[p])/(b[x]+b[y]);
			b[p]=a[p];
			continue;
		}
		if(b[p]<b[x]+b[y]) GG();
		ans+=b[p]/(b[x]+b[y]);
		b[p]%=b[x]+b[y];
		if(a[p]==b[p]) continue;
		if(b[p]<a[p]) GG();
		q.push(pii(b[p],p));
	}
	write(ans);
}

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

int main()
{
    ll n, m, k = 0, ans = 0;
    cin>>n;
    ll sq = sqrt(n);
    for(int i = 1; i <= n; i++){
        ll x = n - i;
        ans += ( x / i  + (x % i != 0) );
       // cout<<ans<<"\n";
    }
    cout<<ans<<"\n";
    return 0;
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl '\n'
#define ll int64_t
#define ull uint64_t
using namespace std;

int main()
{
  #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    freopen("error.txt","w",stderr);
  #endif
 ll n,d;
 cin>>n>>d;
 ll D = d*d;
 int c=0;
 for(int i=0;i<n;i++)
 {
 	ll x,y;
 	cin>>x>>y;
 	ll a = x*x,b = y*y;
 	if((a+b-D)<=0)
 		c++;
 }
 cout<<c<<endl;
 return 0;
}

Measured memory_bytes: 3620
#include <iostream>
#define TREESIZE 30
#define NIL -1
using namespace std;

struct Node
{
    int parent = NIL;
    int left_child = NIL;
    int right_child = NIL;
};

Node Tree[TREESIZE];

// Preorder Tree walk by recursion
// (1) print root node (2) move left child (3) move right child
void Preorder(int node_id)
{
    printf(" %d", node_id);                                                   // (1)
    if(Tree[node_id].left_child != NIL)  Preorder(Tree[node_id].left_child);  // (2)
    if(Tree[node_id].right_child != NIL) Preorder(Tree[node_id].right_child); // (3)
}

// Inorder Tree walk by recursion
// (1) move left child (2) print root node (3) move right child
void Inorder(int node_id) 
{
    if(Tree[node_id].left_child != NIL)  Inorder(Tree[node_id].left_child);  // (1)
    printf(" %d", node_id);                                                   // (2)
    if(Tree[node_id].right_child != NIL) Inorder(Tree[node_id].right_child); // (3)
}

// Postorder Tree walk by recursion
// (1) move left child (2) move right child (3) print root node
void Postorder(int node_id) 
{
    if(Tree[node_id].left_child != NIL)  Postorder(Tree[node_id].left_child);  // (1)
    if(Tree[node_id].right_child != NIL) Postorder(Tree[node_id].right_child); // (2)
    printf(" %d", node_id);                                                   // (3)
}

int main() 
{
    int node_num, node_id, l_child, r_child, root = 0;
    scanf("%d", &node_num);

    for (int i = 0; i < node_num; ++i) 
    {
        scanf("%d %d %d", &node_id, &l_child, &r_child);
        Tree[node_id].left_child = l_child;
        Tree[node_id].right_child = r_child;
        // if the node has children, set the node as parent
        if (Tree[node_id].left_child != NIL ) Tree[Tree[node_id].left_child].parent = node_id;
        if (Tree[node_id].right_child != NIL) Tree[Tree[node_id].right_child].parent = node_id;
    }

    // search root
    while (Tree[root].parent != NIL) ++root;

    // execute Tree walk
    printf("Preorder\n");
    Preorder(root);
    printf("\nInorder\n");
    Inorder(root);
    printf("\nPostorder\n");
    Postorder(root);
    printf("\n");
}


Measured memory_bytes: 3180
using System;
class Program
{
    static void Main()
    {
        string z;
        string x = Console.ReadLine();
        string[] a = x.Split(' ');
        int n = int.Parse(a[0]);
        int m = int.Parse(a[1]);
        int o = int.Parse(a[2]);
        if (n < m)
            if (m < o) 
            { z = "Yes"; }
            else { z = "No"; }
        else { z = "No"; }
        Console.WriteLine(z);
    }
}



Measured memory_bytes: 15840
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while(true) {
            int H = sc.nextInt(), W = sc.nextInt();
            if(H==0 && W==0) {
                break;
            }
            for(int i=0; i<H; i++){
                for(int j=0; j<W; j++) {
                    System.out.printf("#");
                }
                System.out.printf("\n");
            }
            System.out.printf("\n");
        }
    }
}


Measured memory_bytes: 63808
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

using P = pair<int, int>;

int main() {
    int n, k;
    cin >> n >> k;
    vector<vector<int>> sub(4 * k, vector<int>(4 * k, 0)),
                        kanae(4 * k + 1, vector<int>(4 * k + 1, 0));
    for (int i=0; i<n; i++) {
        int x, y; char c;
        cin >> x >> y >> c;
        if (c == 'B') x += k;
        x %= (2*k);
        y %= (2*k);
        int x1 = x,
            y1 = y,
            x2 = x+k,
            y2 = y+k,
            x3 = x+2*k,
            y3 = y+2*k;
        sub[x1][y1]++;
        sub[x1][y2]--;
        sub[x2][y1]--;
        sub[x2][y2]+=2;
        sub[x2][y3]--;
        sub[x3][y2]--;
        sub[x3][y3]++;
    }
    // for (auto &si:sub) {
    //     for (auto s:si) {
    //         cerr << (s >= 0 ? s : 2) << ' ';
    //     }
    //     cerr << endl;
    // }
    int best = 0;
    for (int i=0; i<4*k; i++) {
        for (int j=0; j<4*k; j++) {
            kanae[i+1][j+1] = sub[i][j] + kanae[i+1][j] + kanae[i][j+1] - kanae[i][j];
            if (i >= 2*k && j >= 2*k) {
                int x1 = i+1,
                    y1 = j+1,
                    x2 = i+1-2*k,
                    y2 = j+1-2*k;
                best = max(best, kanae[x1][y1] + 
                                 kanae[x1][y2] + 
                                 kanae[x2][y1] + 
                                 kanae[x2][y2]);
            }
        }
    }
    cout << best << '\n';
    return 0;
}

Measured memory_bytes: 125568
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/integer/common_factor.hpp>
#include <boost/integer/common_factor_rt.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>

using std::string;
using std::vector;
using std::set;
using std::multiset;
using std::unordered_set;
using std::map;
using std::multimap;
using std::unordered_map;
using std::pair;
using std::cin;
using std::cout;

using boost::multiprecision::cpp_int;
using cpp_dec_float_1000 = boost::multiprecision::number<boost::multiprecision::cpp_dec_float<1000>>;

typedef uintmax_t    ull;
typedef intmax_t     ll;
typedef uint64_t     ul;
typedef uint32_t     ui;
typedef uint8_t      uc;

constexpr char CRLF  = '\n';
constexpr char SPACE = ' ';
constexpr char VECTOR_COUT_SEPARATOR = SPACE;
constexpr ll INF = 1000'000'007;
constexpr int MOD = 1000'000'007;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> std::ostream& operator<< (std::ostream& os, const std::vector<T>& vc) { for(auto it = vc.begin(); it != vc.end(); ++it) { if (std::next(it) == vc.end()) os << *it; else os << *it << VECTOR_COUT_SEPARATOR; } return os; }
template<class T1, class T2> inline std::ostream & operator<< (std::ostream & os, const std::pair<T1, T2> & p) { return os << p.first << ' ' << p.second; }
template<class T> T modinv(T a, T m) { T b = m, u = 1, v = 0; while (b) { T t = a / b; a -= t * b; boost::swap(a, b); u -= t * v; boost::swap(u, v); } u %= m; if (u < 0) u += m; return u; }

struct Tmp
{
public:
  Tmp(int N);
};

Tmp::Tmp(int N){}

void solve(void)
{
  int N; cin >> N;
  vector<string> A(N);
  vector<int> B(N);
  map<string, int> m{};
  for (auto& a : A) {
    cin >> a;
    ++m[a];
  }
  for (int i = 0; i < N; ++i) {
    B[i] = m[A[i]];
  }
  auto cnt = *boost::max_element(B);
  set<string> res{};
  for (int i = 0; i < N; ++i) {
    if (B[i] == cnt) {
      res.emplace(A[i]);
    }
  }
  // boost::sort(res, std::greater<string>());
  while (!res.empty()) {
    // auto s = *(res.end() - 1);
    auto it = res.begin();
    // --it;
    auto s = *it;
    cout << s << CRLF;
    res.erase(it);
  }
  return;
}

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

  solve();

  return 0;
}


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

long long countDigit(long long x){
  long long res = 0;
  while(1){
    if(x){
      res++; 
    }else{
      break;
    }
    x /= 10;
  }
  return res;
}

int main() {
  long long N;
  cin >> N;
  long long res=1000000000000;
  for(long long i=1;i<(long long)sqrt(N)+1;i++){
    if(N%i == 0){
      long long tmp = max(countDigit(N/i), countDigit(i));
      if(res > tmp){ res = tmp; }
    }
  }
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string a,b;
    int n,i,j,m,p;
    cin>>n;
    cin>>a>>b;
    //gets(a);
    //gets(b);
    m=a.size();
    p=b.size();
    for(i=0; i<m; i++)
    {
        for(j=i; j<=i; j++)
        {
            cout<<a[i]<<b[j];
        }
    }

    return 0;
}

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

ll ys[51];
ll ps[51];

ll ans = 0;

void solve(int n, ll x)
{
    if (x == 0 && n == 0) ++ans;
    if (x ==       0) return;
    if (x == ys[n]-1) { ans += ps[n]; return; }
    if (x == ys[n]/2) { ans += ps[n-1]+1; return; }

    if (x >= ys[n]/2) { ans += ps[n-1]+1; solve(n-1, x-ys[n-1]-2); return; }
    
    solve(n-1, x-1);
}

int main()
{
    int N;
    ll  X;
    cin >> N;
    cin >> X;

    ys[0] = 1;
    for (int i=1; i<=N; ++i) ys[i] = ys[i-1]*2+3;

    ps[0] = 1;
    for (int i=1; i<=N; ++i) ps[i] = ps[i-1]*2+1;

    solve(N, X-1);

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


Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Text;
using System.Text.RegularExpressions;
using System.Linq;
using System.IO;

class Program
{
    static void Main()
    {
        new Magatro().Solve();
    }
}

class Magatro
{
    private int N, M;
    private int[][] A;
    private bool[] U;
    private void Scan()
    {
        var line = Console.ReadLine().Split(' ');
        N = int.Parse(line[0]);
        M = int.Parse(line[1]);
        A = new int[N][];
        for (int i = 0; i < N; i++)
        {
            A[i] = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        }
    }

    private int C(out int o)
    {
        int[] a = new int[M + 1];
        foreach(var i in A)
        {
            foreach(int j in i)
            {
                if (U[j])
                {
                    a[j]++;
                    break;
                }
            }
        }
        int result = -1;
        o = -1;
        for(int i = 1; i <= M; i++)
        {
            if (result < a[i])
            {
                result = a[i];
                o = i;
            }
        }
        return result;
    }


    public void Solve()
    {
        Scan();
        U = new bool[M + 1];
        for (int i = 1; i <= M; i++)
        {
            U[i] = true;
        }
        int ans = int.MaxValue;

        for (int i = 0; i < M; i++)
        {
            int o;
            ans = Math.Min(ans, C(out o));
            U[o] = false;
        }
        Console.WriteLine(ans);
    }
}


Measured memory_bytes: 15820
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
	Scanner s = new Scanner (System.in);
	int a = s.nextInt();
	int b = s.nextInt();
	int c = s.nextInt();
	int d = s.nextInt();
	if (Math.abs(c-a)<=d || Math.abs(c-b)<=d && Math.abs(b-a)<=d ) {
        System.out.println("Yes");
    } else {
        System.out.println("No");
    }
    }
}


Measured memory_bytes: 23764
#include <bits/stdc++.h>
#define ll long long 
#define ld long double
using namespace std;
const ll INF = 1e18;
const ll MOD = 998244353;



int32_t main() {
	ios::sync_with_stdio(!cin.tie(NULL));

	int x;
	cin >> x;

	cout << 360 / (__gcd(360, x));
}



Measured memory_bytes: 3620
import itertools
H,W = map(int,input().split())
S = [input() for h in range(H)]
a = [[0 if cell=="." else "#" for cell in row] for row in S]

for h in range(H):
  for w in range(W):
    if S[h][w]!="#":
      continue
    for dx,dy in itertools.product([-1,0,1],repeat=2):
      x = h+dx
      y = w+dy
      if x<0 or H<=x:
        continue
      if y<0 or W<=y:
        continue
      if S[x][y]=="#":
        continue
      a[x][y]+=1

for row in a:
  print(*row,sep="")

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

int main() {
    int a,b;
    cin >>a>>b ;
    
  int  ans =-1;
    for(int i=0 ; i<100000 ;i++){
        if(8*i/100==a &&10*i/100==b){
            ans=i ;
        break;
        }
    }
 


  cout << ans  << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
using namespace std;
char s[105];
int main() {
    int k;
    scanf("%d%s", &k, s);
    int n = strlen(s);
    if(n > k) {
        for(int i = 0; i < k; i++) {
            printf("%c", s[i]);
        }
        printf("...\n");
    }else {
        printf("%s\n", s);
    }
    return 0;
}

Measured memory_bytes: 3772
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<iomanip>
#include<math.h>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
#define LINF (long long)4e18

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;


int main(){
    int N,K; cin >> N >> K;
    vector<int> h(N);
    rep(i,N) cin >> h[i];
    vector<int> dp(101800,INF);
    dp[0] = 0;
    rep(i,K){
        rep(j,i){
            dp[i] = min(dp[i],dp[j] + abs(h[i] - h[j]));
        }
    }
    rep(i,N-K){
        rep(j,K){
            dp[i+K] = min(dp[i+K],dp[i+j] + abs(h[i+K] - h[i+j]));
            
        }
    }
    cout << dp[N-1] << endl; 
}


Measured memory_bytes: 1024
from bisect import bisect_left

n = int(input())
s = list(map(int,input().split()))
q = int(input())
t = list(map(int,input().split()))
cou = 0
def find(x,a):
  #xにリスト,aに値　あったら1なかったら0
  k = bisect_left(x,a)
  if k!= len(x) and x[k]==a:
    return 1
  else:
    return 0
  
for i in t:
  cou += find(s,i)
print(cou)


Measured memory_bytes: 16740
from collections import Counter, defaultdict
import sys
sys.setrecursionlimit(10 ** 5 + 10)
# input = sys.stdin.readline
from math import factorial
import heapq, bisect
import math
import itertools
import queue
from collections import deque
from fractions import Fraction


def ternary (n, k, length):
    if n == 0:
        nums = ['0' for i in range(length)]
        nums = ''.join(nums)
        return nums
    nums = ''
    while n:
        n, r = divmod(n, k)
        nums += str(r)
    nums = nums[::-1]
    nums = nums.zfill(length)
    return nums

def main():
    num = int(input())
    say_count = []
    say_data = []
    for i in range(num):
        aaa = int(input())
        say_count.append(aaa)
        data = [list(map(int, input().split())) for i in range(aaa)]
        say_data.append(data)


    ans = 0
    for i in range(2 ** num):
        bin_data = list(map(int, ternary(i, 2, num)))
        kari_ans = bin_data.count(1)

        people_flg = [-1 for i in range(num)]
        dame_flg = 0
        for j in range(num):
            if people_flg[j] == -1:
                people_flg[j] = bin_data[j]
            else:
                if people_flg[j] != bin_data[j]:
                    dame_flg = 1

            if people_flg[j] == 0:
                continue

            for k in range(say_count[j]):
                people, flg = say_data[j][k]
                people -= 1
                if people_flg[people] == -1:
                    people_flg[people] = flg
                else:
                    if people_flg[people] != flg:
                        dame_flg = 1

            if dame_flg:
                break
        if dame_flg:
            continue
        ans = max(ans, kari_ans)

    print(ans)






if __name__ == '__main__':
    main()



Measured memory_bytes: 71128
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <utility>
#include <algorithm>
#include <cmath>
#include <climits>
#include <iomanip>
#include <queue>
#include <stack>

using namespace std;

typedef long long ll;

vector<pair<int, int> > func(int x) {
    vector<pair<int, int> > v;
    for (int i = 2; i * i <= x; i++) {
        int tmp = 0;
        if (x % i == 0) {
        while (x % i == 0) {
            x /= i;
            tmp++;
        }
        v.push_back(pair<int,int>(i, tmp));
        }
    }
    if (x > 1)
        v.push_back(pair<int,int>(x, 1));

    return v;
}

int gcd(int x, int y) { //x > y
    if (y == 0)
        return x;
    else 
        return gcd(y, x%y);
}

int main() {
    int n;  cin >> n;
    int *a = new int[n];
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }

    int g = a[0];
    for (int i = 1; i < n; i++) {
        g = gcd(g, a[i]);
    }

    if (g != 1) {
        cout << "not coprime" << endl;
        return 0;
    }

    map<int, int> mp;

    vector<vector<pair<int,int> > > v(n);
    for (int i = 0; i < n; i++) {
        v[i] = func(a[i]);
        
        for (int j = 0; j < v[i].size(); j++) {
            mp[v[i][j].first] += v[i][j].second;
            
        }
    }
    

    

    for (int i = 0; i < n; i++) {
        if (a[i] == 1)
            continue;
        for (int j = 0; j < v[i].size(); j++) {
            mp[v[i][j].first] -= v[i][j].second;
        }

        for (int j = 0; j < v[i].size(); j++) {
            if(mp[v[i][j].first] != 0) {
                cout << "setwise coprime" << endl;
                return 0;
            }
        }

        for (int j = 0; j < v[i].size(); j++) {
            mp[v[i][j].first] += v[i][j].second;
        }
    }

    cout << "pairwise coprime" << endl;

    return 0;
}

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

long long dp[51][51][2501];

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

    int n, a;
    cin >> n >> a;
    vector<int> X(n);
    REP(i, n) cin >> X[i];

    dp[0][0][0] = 1;
    REP(i, n){
        REP(j, n){
            REP(k, 2500){
                if(dp[i][j][k]){
                    dp[i + 1][j][k] += dp[i][j][k];
                    dp[i + 1][j + 1][k + X[i]] += dp[i][j][k];
                }
            }
        }
    }

    long long ans = 0;
    for(int i = 1; i <= n; i++){
        ans += dp[n][i][i * a];
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 48128
#include <iostream>
#include <stdio.h>
using namespace std;

int main()
{
    int a,b,c,d;
    while(scanf("%d%d%d%d",&a,&b,&c,&d)!=EOF)
    {
        if(b<=c||d<=a)
        {
            printf("0\n");
            continue;
        }
        a=max(a,c);
        b=min(b,d);
        printf("%d\n",b-a);
    }
    return 0;
}



Measured memory_bytes: 256
code,implement = input().split(" ")

def prize_dict(rank):
    if rank == "1":
        prize = 300000
    elif rank == "2":
        prize = 200000
    elif rank == "3":
        prize = 100000
    else:
        prize = 0
    return prize


if code == "1" and implement == "1":
    prize = 1000000
else:
    prize = prize_dict(code)+prize_dict(implement)
print(prize)

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

int main() {
 
	//数字
   int N;
   cin >> N;
   int A[N];
   int B[N];

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

   int count=1;
   for(int i=0;i<N;i++){
      if(A[i]==count){
         B[count]=i;
         count++;
      }
   }

   int gomi=0;
   //cout << count << endl;
   for(int i=1;i<count;i++){
      if(i==1){gomi=B[i];
      }else{
         gomi+=B[i]-B[i-1]-1;
      }
      //cout << i << endl;
   }
   gomi+=N-B[count-1]-1;
   if(count == 1){
      cout << -1 << endl;
   }
   else{
      cout << gomi << endl;
   }
}

Measured memory_bytes: 1792
import heapq


def main():
    nvertices, nedges = map(int, input().split())
    Adj = [[] for i in range(nvertices)]
    for i in range(nedges):
        u, v, w = map(int, input().split())
        Adj[u].append((v, w))
        Adj[v].append((u, w))

    INF = float('inf')
    Q = [(0, 0)]
    for i in range(1, nvertices):
        Q.append((INF, i))
    heapq.heapify(Q)
    key = [INF] * nvertices
    key[0] = 0
    done = [False] * nvertices
    ans = 0
    while Q:
        val, u = heapq.heappop(Q)
        if val > key[u]:
            continue
        done[u] = True
        ans += val
        for v, w in Adj[u]:
            if not done[v] and w < key[v]:
                key[v] = w
                heapq.heappush(Q, (w, v))

    print(ans)


main()

Measured memory_bytes: 35788
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n,d;
  cin>>n>>d;
  int x=2*d+1;
  int a=1;
  while(n>x) {
    a++;
    n=n-x;
  }
  cout<<a;
  return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <vector>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <ctype.h>
#include <climits>
#include <queue>
using namespace std;
typedef long long ll;
#define REP(i, n) for(ll i = 0; i < (ll)(n); ++i)
#define FOR(i, a, b) for(ll i=(a); i < (ll)(b); ++i)
template<class T> inline bool chmax(T& a, T b) { if(a < b){ a=b; return 1; } return 0;}
template<class T> inline bool chmin(T& a, T b) { if(a > b){ a=b; return 1; } return 0;}


int main(){
	int n;
	string s;
	cin >> n >> s;
	
	
	int a[10][10][10]={};
	int b[10][10] = {};
	int last[10];
	REP(i,10) last[i] = -1;
	vector<vector<int>> exist(n+1, vector<int>(10,0));
	
	REP(i,n){
		int num=s[i]-'0';
		
		REP(j,10){
			if(exist[i][j]){
				REP(k,10){
					if(exist[last[j]][k]){
						a[k][j][num] = 1;
					} 
				}
			}
		}
		
		REP(j,10){
			exist[i+1][j] = exist[i][j];
		}
		if(exist[i+1][num]==0){
			exist[i+1][num]=1;
		}
		last[num] = i;
			
	}	
	
	int ans=0;
	REP(i,10) REP(j,10) REP(k,10) ans += a[i][j][k];
	
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 5368
#include <iostream>
/*
S(100000000)=1,
100000000/s(100000000)=100000000
そんなにないってことでは？
*/
using namespace std;
#define ll long long

ll least(ll a){
    if (a<10000){
        return 1;
    }else{
        ll n=1;
        while(a/10000>n)n*=10;
        return n;
    }
}

int main(){
    int k;
    cin >> k;
    double tmp=9999999990000000.0;
    int cnt=0;
    ll anslist[800];
    for(ll i=999999999999999;i>0;i-=least(i)){
        ll n=i;
        ll a=n,b=0;
        ll ans=0;
        while(n>0){
            b+=n%10;
            n/=10;
        }
        if(tmp>=double(a)/double(b)){
//            cout << double(a)/double(b) <<" "<< a<< endl,cnt++;
            anslist[cnt]=a;
            cnt++;
        }
        tmp=min(tmp,double(a)/double(b));
    }
    for(int i=cnt-1;i>cnt-1-k;i--){
        cout <<anslist[i]<<endl;
    }
    return 0;
}

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

int main(){
    int a[5];
    int b[5] = {};
    int sum = 0;
    cin >> a[0] >> a[1] >> a[2] >> a[3] >> a[4];
    for(int i = 0; i < 5; i++){
        if(a[i] % 10 == 0){
            b[i] = a[i];
        }else{
            b[i] = (a[i] / 10 + 1) * 10;
        }
        sum += b[i];
    }
    int min = 643;
    for(int i = 0; i < 5; i++){
        int x = sum - b[i] + a[i];
        if(x < min){
            min = x;
        }
    }
    cout << min << endl;
    return 0;
}

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

#define pb         push_back

const int INF = 100000000;

int w, h;
vector<int> ma[60];

void rec(int y, int x){
	int ny, nx;
	if(ma[y][x] != 1){
		return;
	}
	ma[y][x] = 0;
	for(int i=-1; i<=1; i++){
		for(int j=-1; j<=1; j++){
			if(i == 0 && j == 0) continue;
			nx =  x + i;
			ny =  y + j;
			if(ny >= 0 && ny < h && nx >= 0 && nx < w){
				rec(ny, nx);
			}
		}
	}
}
int main(void) {
	while(1){
		for(int i=0; i<60; i++){
			ma[i] = vector<int>();
		}
		cin >> w >> h;
		if(w == 0 && h == 0) break;

		for(int i = 0; i < h; i++){
			for(int j=0; j<w; j++){
				int t;
				cin >> t;
				ma[i].pb(t);
			}
		}

		int ans = 0;
		for(int i=0; i<h; i++){
			for(int j=0; j<w; j++){
				if(ma[i][j] == 1){
					ans++;
					rec(i, j);
				}
			}
		}
		/*
		for(int i=0; i<h; i++){
			for(int j=0; j<w; j++){
				cout << ma[i][j] << ' ';
			}
			cout << endl;
		}
		*/
		cout << ans << endl;
	}
	
	return 0;
}

Measured memory_bytes: 1368