akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
int gcd(int a, int b)
{
	return (!b ? a : gcd(b, a % b));
}
 
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int k, ans = 0; cin >> k;
    for(int i = 1; i <= k; i++) for(int j = 1; j <= k; j++) for(int l = 1; l <= k; l++) ans += gcd(i, gcd(j, l));
    cout << ans;
 
    return 0;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define mp make_pair
#define all(vec) vec.begin(), vec.end()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll INF = 1LL << 30;
const ll LINF = 1LL << 60;
const double eps = 1e-9;
const ll MOD = 1000000007LL;

template <class U>
struct RangeSum {
    using T = U;
    static T op(const T& a, const T& b) { return a + b; }
    static constexpr T id() { return 0; }
};

template <class Monoid>
struct Segtree {
    int n;
    using T = typename Monoid::T;
    vector<T> dat;
    Segtree(int n_) {
        n = 1;
        while(n < n_) n <<= 1;
        dat.resize(2 * n, Monoid::id());
    }
    T get(int k) {
        assert(k < n);
        return dat[k + n];
    }
    void set(int k, const T& x) {
        assert(k < n);
        k += n;
        dat[k] += x;
        for(k >>= 1; k > 0; k >>= 1) {
            dat[k] = Monoid::op(dat[k << 1], dat[k << 1 | 1]);
        }
    }
    T query(int a, int b) {  //[a,b]->[a,b)
        if(a < 0) a = 0;
        if(a > b) return Monoid::id();
        if(b > n) b = n;
        T vl = Monoid::id(), vr = Monoid::id();
        int l = a + n, r = b + n + 1;
        for(; l < r; l >>= 1, r >>= 1) {
            if(l & 1) vl = Monoid::op(vl, dat[l++]);
            if(r & 1) vr = Monoid::op(dat[--r], vr);
        }
        return Monoid::op(vl, vr);
    }
};
int main() {
    int n, q;
    cin >> n >> q;
    Segtree<RangeSum<ll>> seg(n);
    while(q--) {
        int t, x, y;
        cin >> t >> x >> y;
        if(t == 0) {
            --x;
            seg.set(x, y);
        } else {
            --x;
            --y;
            cout << seg.query(x, y) << endl;
        }
    }
}



Measured memory_bytes: 4920
#include <iostream>
using namespace std;
int main(void){
	int a,b;
	cin>>a>>b;

	if(a>b)cout<<"a > b"<<endl;
	else if(a<b)cout<<"a < b"<<endl;
	else if(a==b)cout<<"a == b"<<endl;


	return 0;
}


Measured memory_bytes: 3112
// Problem : C - Green Bin
// Contest : AtCoder - AtCoder Beginner Contest 137
// URL : https://atcoder.jp/contests/abc137/tasks/abc137_c
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
 
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
 
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,b,a) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
#define trav(a,x) for (auto& a : x)
 
#define bug(x) cout<<#x<<"="<<x<<endl; 
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert
 
template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
const ld pii=3.14159265359; 
const int MOD = 1000000007;
const char nl = '\n';
const int MX = 200001; //check the limits, dummy
 vl hsh={2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199};
int main() 
{
	ios_base::sync_with_stdio(0); cin.tie(0);    
	// cout<<sz(hsh);
	int N;
	cin>>N;
	unordered_map<ll,int> m;
	ll ans=0;
	F0R(x,N)
	{
		string str;
		cin>>str;
		ll val=1;
		F0R(x,sz(str))
			val=val*(hsh[str[x]-'a']);
		ans+=m[val];
		m[val]++;
	}
	cout<<ans<<nl;
	return 0;
}
 
// read the question correctly (ll vs int)
// template by bqi343

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

#define      ll      long long int

vector<int> v1, v2;
int cnt[27];

int main( )
{
    int i, j, k, x;
    string s, t;
    int n;
    cin >> s >> t;
    int l = (int) s.size();
    for (i = 0; i < l; i++) {
        x = s[i] - 'a';
        cnt[x]++;
    }
    for (i = 0; i < 26; i++) {
        if (cnt[i] != 0) {
            v1.push_back(cnt[i]);
        }
    }
    memset(cnt, 0, sizeof cnt);
    for (i = 0; i < l; i++) {
        x = t[i] - 'a';
        cnt[x]++;
    }
    for (i = 0; i < 26; i++) {
        if (cnt[i] != 0) {
            v2.push_back(cnt[i]);
        }
    }
    if ((int) v1.size() != (int) v2.size()) {
        cout << "No\n";
        return 0;
    }
    sort(v1.begin(), v1.end());
    sort(v2.begin(), v2.end());
    for (i = 0; i < (int) v1.size(); i++) {
        if (v1[i] != v2[i]) {
            cout << "No\n";
            return 0;
        }
    }
    cout << "Yes\n";
    return 0;
}


Measured memory_bytes: 776
#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <math.h>
#include <numeric>
#include <iomanip>
#include <string>
#include <map>
#include <queue>
#include <list>

#define REP(i, n ,N) for(ll i = (n); i < (N); i++)
//#define RREP(i, n ,N) for(ll i = (N-1); i >= (n); i--)
#define p(s) cout<<(s)<<endl
#define p2(a, b) cout<<(a)<<" "<<(b)<<endl
#define vint vector<int>
#define INF 1e9

using namespace std;
typedef long long  ll;

int main(){
    int64_t N;
    cin >> N;
    int64_t ans=0;
    for(int i=1;i<=N;i++){
        for(int j=i;j<=N;j+=i){
            ans+=j;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3140
#include <bits/stdc++.h>
#define ALL(v) std::begin(v), std::end(v)
#define ALLR(v) std::rbegin(v), std::rend(v)
using ll = std::int64_t;
using ull = std::uint64_t;
using pll = std::pair<ll, ll>;
using tll = std::tuple<ll, ll, ll>;
template <typename T> using vec = std::vector<T>;
template <typename T> using vvec = vec<vec<T>>;
template <typename T> const T& var_min(const T &t) { return t; }
template <typename T> const T& var_max(const T &t) { return t; }
template <typename T, typename... Tail> const T& var_min(const T &t, const Tail&... tail) { return std::min(t, var_min(tail...)); }
template <typename T, typename... Tail> const T& var_max(const T &t, const Tail&... tail) { return std::max(t, var_max(tail...)); }
template <typename T, typename... Tail> void chmin(T &t, const Tail&... tail) { t = var_min(t, tail...); }
template <typename T, typename... Tail> void chmax(T &t, const Tail&... tail) { t = var_max(t, tail...); }
template <typename T> const T& clamp(const T &t, const T &low, const T &high) { return std::max(low, std::min(high, t)); }
template <typename T> void chclamp(T &t, const T &low, const T &high) { return t = clamp(t, low, high); }
namespace init__ { struct InitIO { InitIO() { std::cin.tie(nullptr); std::ios_base::sync_with_stdio(false); std::cout << std::fixed << std::setprecision(30); } } init_io; }
#define mv_rec make_v(init, tail...)
template <typename T> T make_v(T init) { return init; }
template <typename T, typename... Tail> auto make_v(T init, size_t s, Tail... tail) { return vec<decltype(mv_rec)>(s, mv_rec); }
#undef mv_rec

int main() {
    ll n, a, b;
    std::cin >> n >> a >> b;
    ll cnt = n / (a + b);
    ll ans = cnt * a;
    ll rest = n - (a + b) * cnt;
    ans += std::min(a, rest);
    std::cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] a) {
        Scanner s = new Scanner(System.in);
        for (;;) {
            int h = s.nextInt() + 1;
            int w = s.nextInt() + 1;
            if (h * w == 1)
                break;
            int[][] l = new int[h][w];
            int[][] t = new int[h][w];
            int m = 0;
            for (int i = 1; i < h; i++) {
                char[] c = s.next().toCharArray();
                for (int j = 1; j < w; j++) {
                    if (c[j - 1] == '.')
                        l[i][j] = l[i][j - 1] + 1;
                    t[i][j] = l[i][j];
                    for (int k = 0; k < i; k++) {
                        t[k][j] = Math.min(t[k][j], l[i][j]);
                        m = Math.max(m, t[k][j] * (i - k + 1));
                    }
                }
            }
            System.out.println(m);
        }
    }
}



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

using namespace std;

#define ll long long

void solve() {
	ll a, b;
	cin >> a >> b;
	vector<ll> v;
	for (ll i = a; i <= b; i*=2) {
		v.push_back(i);
	}
	cout << v.size();
}

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

	int t = 1, i = 1;
	//cin >> t;
	while(t--) {
		//cout << "Case #" << i << ": ";
		solve();
		//i++;
	}
	return 0;
}



Measured memory_bytes: 3656
#include	<stdio.h>

int		main(void)
{	
	int	a,b;
	char	op;
	
	do{
	  scanf("%d %c %d",&a,&op,&b);
	  
	   if(op == '+')
	     printf("%d\n",a + b);
	   else if(op == '-')
	     printf("%d\n",a - b);
           else if(op == '*')
             printf("%d\n",a * b);
           else if(op == '/')
             printf("%d\n",a / b);
	  
	}while(!(op == '?'));



  return(0);
}

Measured memory_bytes: 1032
<?php
  
$num500 = trim(fgets(STDIN));

for ($i = 0; $i < 3; $i++) {
  $s = trim(fgets(STDIN));
  $s = str_replace(array("\r\n","\r","\n"), '', $s);
  $s = explode(" ", $s);
  if ($i == 0) {
  	$num100 = $s[0];
  } else if ($i == 1) {
  	$num50 = $s[0];
  } else if ($i == 2) {
  	$sum = $s[0];
  }
}

$result = 0;

for ($a = 0; $a <= $num500; $a++) {
	for ($b = 0; $b <= $num100; $b++) {
    	for ($c = 0; $c <= $num50; $c++) {
        	$total = (500 * $a) + (100 * $b) + (50 * $c);
            if ($sum == $total) {
            	$result++;
            }
        }
    }
}

echo $result;
?>

Measured memory_bytes: 3956
import sys
sys.setrecursionlimit(700000)

def s_in():
    return input()

def n_in():
    return int(input())

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

def print_l(l):
    print(' '.join(map(str, l)))

class Interval():
    def __init__(self, li):
        self.li = li
        self.n = len(li)
        self.sum_li = [li[0]]
        for i in range(1, self.n):
            self.sum_li.append(self.sum_li[i-1] + li[i])

    def sum(self, a, b=None):
        if b is None:
            return self.sum(0, a)

        res = self.sum_li[min(self.n-1, b-1)]
        if a > 0:
            res -= self.sum_li[a-1]
        return res

N = n_in()
edges = [[] for _ in range(N)]

for _ in range(N-1):
    a,b = l_in()
    edges[a-1].append(b-1)
    edges[b-1].append(a-1)


# Euler Tour の構築
S = []
depth = [0]*N
visited = set()

def dfs(v, d):
    visited.add(v)
    depth[v] = d
    S.append(v)
    for w in edges[v]:
        if w in visited:
            continue
        dfs(w, d+1)
        S.append(v)


root = 0
dfs(root, 0)

res = [0 for _ in range(N)]

from collections import deque
q0 = deque(i for i in range(1,N+1) if i%3 == 0)
q1 = deque(i for i in range(1,N+1) if i%3 == 1)
q2 = deque(i for i in range(1,N+1) if i%3 == 2)

even_depth = len(list(filter(lambda d: d%2 == 0, depth)))
odd_depth = len(list(filter(lambda d: d%2 != 0, depth)))

if even_depth > N//3 and odd_depth > N//3:
    for i, d in enumerate(depth):
        if d%2 == 0:
            if len(q1) > 0:
                res[i] = q1.popleft()
            else:
                res[i] = q0.popleft()
        else:
            if len(q2) > 0:
                res[i] = q2.popleft()
            else:
                res[i] = q0.popleft()
elif even_depth <= N//3:
    for i, d in enumerate(depth):
        if d%2 == 0:
            res[i] = q0.popleft()
        else:
            if len(q1) > 0:
                res[i] = q1.popleft()
            elif len(q2) > 0:
                res[i] = q2.popleft()
            else:
                res[i] = q0.popleft()
else:
    for i, d in enumerate(depth):
        if d%2 != 0:
            res[i] = q0.popleft()
        else:
            if len(q1) > 0:
                res[i] = q1.popleft()
            elif len(q2) > 0:
                res[i] = q2.popleft()
            else:
                res[i] = q0.popleft()


print_l(res)


Measured memory_bytes: 193596
#include<iostream>
#include<vector>
#include<algorithm>
#include<stdlib.h>
#include<utility>
#include<functional>
#include<cfenv>
#include<cmath>
#include<string>
#include<queue>
#include<stack>
#include<map>
#include<set>

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define vint vector<int>
#define vvint vector<vint>
#define P pair<int,int>
#define INT_MAX 2147483647
#define MOD 1000000007
using namespace std;
typedef long long ll;


int main(void) {
	int n, m; cin >> n >> m;
	int ans = (m*(m - 1)) / 2 + n * (n - 1) / 2;
	cout << ans;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i = 0; i < (N); i++)
#define repo(i,N) for(int i = 1; i < (N); i++)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
//#define num 1000000007
#define pi acos(-1.0)
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//#define int long long


int main() {
  int a,b;
  cin >> a >> b;

  if(a==b) {
  cout << "Draw" << endl;
  return 0;
  }
  else if (a==1 || (a>b && b!=1)) {
  cout << "Alice" << endl;
  return 0;
  }
  
  cout << "Bob" << endl;
  
}


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

int main() {

  int H, N;
  cin >> H >> N;

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

  // ダメージの総和が j になるように選んだときの魔法消費量の総和の最小値
  vector<int> dp(H + 1, 100000000);

  dp[0] = 0;

  for (int i = 0; i < N; i++) {
    for (int j = 0; j <= H; j++) {
      int k = min(j + A[i], H);
      dp[k] = min(dp[k], dp[j] + B[i]);
    }
  }

  cout << dp[H] << endl;
}

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

using namespace std;

typedef long long ll;

const int T=100000;

int main(){
  int n, c; cin >> n >> c;
  int used[c+1][T+1];
  for(int i=0;i<=c;i++){
    for(int j=0;j<=T;j++){
      used[i][j]=0;
    }
  }
  for(int i=0;i<n;i++){
    int s, t, cc; cin >> s >> t >> cc;
    for(int ss=s-1; ss<t; ss++){
      used[cc][ss]=1;
    }
  }
  /*for(int i=1;i<=c;i++){
    for(int j=1;j<=T;j++){
      cout << used[i][j] << " ";
    }
    cout << endl;
  }*/
  int ans=0;
  for(int i=1;i<=T;i++){
    int used_sum=0;
    for(int j=1;j<=c;j++) used_sum=used_sum+used[j][i];
    ans = max(ans, used_sum);
  }
  cout << ans << endl;
}

Measured memory_bytes: 12416
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<iostream>
#include<algorithm>
using namespace std;
bool pan(string s,int length,char ch) {
	bool wh = true;
	for (int i = 0; i < length; i++) {
		if (s[i]!=ch) {
			wh = false;
			break;
		}
	}
	return wh;
}
int main() {
	char a[105],b[105];
	scanf("%s",a);
	strcpy(b,a);
	int ans = 99999999,i,j;
	for (i = 0; i < strlen(a); i++) {
		strcpy(b,a);
		char cur = a[i];
		int length =  strlen(a);
		int f =  strlen(a);
		int p = 0;
		while (!pan(b,length,cur)) {
			length--;
			for (j = 0; j < length; j++) {
				if (b[j]==cur||b[j+1]==cur) b[j]=cur;
			}

		}
		ans = min(ans,f-length);
	}
	printf("%d",ans);
	return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
  int N, A[200];
  int co = 0;
  int count = 0;
  cin >> N;
  for (int i = 0; i < N; i++)
    cin >> A[i];
  while (co == 0) {
    for (int i = 0; i < N; i++) {
      if (A[i] % 2 == 1)
	co = 1;
    }
    if (co == 0) {
      for (int i = 0; i < N; i++)
	A[i] /= 2;
      count++;
    }
  }
  cout << count << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
int main(){
  int N, M;
  cin >> N >> M;
  vector<int> k(M);
  vector<int> p(M);
  int** s = new int*[N];
  for(int i=0; i<M; i++){
    cin >> k[i];
    s[i] = new int[k[i]];
    for(int j=0; j<k[i]; j++){
      cin >> s[i][j];
    }
  } 
  for(int i=0; i<M; i++) cin >> p[i];
  int ret = 0;
  for(int st=0; st<(1<<N); st++){
    int c = 0;
    for(int i=0; i<M; i++){
      int su = 0;
      for(int j=0; j<k[i]; j++){
        int sij = s[i][j];
        int ms = 1<<(sij-1);
        int mk = ms&st;
        if(mk>0){
          su++;
        }
      }
      if(su%2==p[i]) c++;
    }
    if(c==M) ret++;
  }
  cout << ret << endl;
  return 0;
}

Measured memory_bytes: 256
#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 << "Right" << endl;
}else
  { 
    cout << "Balanced" << endl;
}
return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cstdio>
#include <algorithm>

using namespace std;

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

    if (S.size() < 26)
    {
        for (char c = 'a'; c <= 'z'; c++)
        {
            if (S.find(c) == std::string::npos) {
                S = S + c;
                break;
            }
        }
    }
    else
    {
        bool ans = false;
        for (int i = 24; i >= 0; i--)
        {
            string chars = S.substr(i+1);
            sort(chars.begin(), chars.end());

            for (int j = 0; j < chars.size(); j++)
            {
                if (S[i] < chars[j])
                {
                    S = S.substr(0, i) + chars[j];
                    //cout << S.substr(0,i) << "  " << chars[j] << endl;
                    ans = true;
                    goto LAST;
                }
            }
        }
    LAST:
        S = ans ? S : "-1";
    }

    cout << S << endl;
}

Measured memory_bytes: 256
from itertools import combinations_with_replacement
n,m,q=map(int,input().split())
a,b,c,d=[0]*q,[0]*q,[0]*q,[0]*q
for i in range(q):
    x,y,z,w=map(int,input().split())
    x-=1
    y-=1
    a[i],b[i],c[i],d[i]=x,y,z,w
ans=0
for v in combinations_with_replacement(range(1,m+1),n):
    res=0
    for i in range(q):
        if v[b[i]]-v[a[i]]==c[i]:
            res+=d[i]
    ans=max(ans,res)
print(ans)

Measured memory_bytes: 68140
def divisors(n):
    div = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            div.append(i)
            if i**2 != n:
                div.append(n//i)
    div.sort()
    return div

n,k = map(int, input().split())
a = list(map(int, input().split()))

d = divisors(sum(a))
d.reverse()

for x in d:
    b = []
    for i in range(n):
        b.append(x-a[i]%x)
    b.sort()
    c = sum(b)//x
    if sum(b[:-c]) <= k:
        print(x)
        exit()


Measured memory_bytes: 41708
// includes {{{
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<tuple>
#include<cmath>
#include<random>
#include<cassert>
// #include<deque>
// #include<multiset>
// #include<bitset>
// #include<cstring>
// #include<bits/stdc++.h>
// }}}
using namespace std;
using ll = long long;

ll n, k;

/// --- math {{{ ///
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll extgcd(ll a, ll b, ll &x, ll &y) {
  ll d;
  return b == 0 ? (x = 1, y = 0, a) : (d = extgcd(b, a % b, y, x), y -= a / b * x, d);
}
ll modinv(ll a, ll mod) {
  ll x, y;
  extgcd(a, mod, x, y);
  if(x < 0) x += mod;
  return x;
}
ll modpow(ll a, ll b, ll mod) {
  ll r = 1;
  a %= mod;
  while(b) {
    if(b & 1) r = r * a % mod;
    a = a * a % mod;
    b >>= 1;
  }
  return r;
}
/// }}}--- ///

// O(N^.5)
/// --- divisor {{{ ///
#include <vector>
vector< ll > divisor(ll n) {
  vector< ll > res;
  for(ll i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      res.emplace_back(i);
      if(i != n / i) res.emplace_back(n / i);
    }
  }
  return res;
}
/// }}}--- ///

const ll mod = 1e9 + 7;

int main() {
  ios::sync_with_stdio(false), cin.tie(0);
  cin >> n >> k;
  auto ds = divisor(n);
  sort((ds).begin(), (ds).end());
  vector<ll> num(ds.size());
  ll ans = 0;
  for(int i = 0; i < ds.size(); i++) {
    ll d = ds[i];
    num[i] = modpow(k, (d + 1) / 2, mod);
    for(int j = 0; j < i; j++) {
      if(d % ds[j] == 0) num[i] -= num[j];
    }
    num[i] %= mod;
    ans += num[i] * (d & 1 ? d : d / 2) % mod;
  }
  ans = (ans % mod + mod) % mod;
  cout << ans << endl;
  return 0;
}


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

#include <fstream>
using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << setprecision(20) << fixed;
  /*
  ifstream in("input.txt");
  cin.rdbuf(in.rdbuf());
  //*/
  int N;
  cin >> N;
  if(N <= 999) cout << "ABC" <<endl;
  else cout << "ABD" <<endl;
}

Measured memory_bytes: 3644
#include<bits/stdc++.h>
#include<string.h>
#include<stdlib.h>
using namespace std;
int main(){
    int a,c=0;
    cin>>a;
    for(int i=1;i<=a;i++){
        int b=0;
        for(int j=1;j<=i;j++){
            if(i%2==1&&i%j==0) b++;
        }
        if(b==8) c++;
    }
    cout<<c<<endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int isPrime(int n){
	int i;
	if(n==2){
		return 1;
	}
	else if(n==1){
		return 0;
	}
	if(n % 2 == 0){
		return 0;
	}
	for(i = 3; i * i <= n; i += 2)
		if(n % i == 0){
			return 0;
		}
	return 1;
}

int main(){
	int n,a,d,i,j;
	int t=0;
	while(1){
		t=0;

		scanf("%d %d %d",&a,&d,&n);
		if(!a && !d&&!n)break;
		for(i=a;1;i+=d){
			t+=isPrime(i);
			if(t==n){
				printf("%d\n",i);
				break;
			}
		}

	}

	return 0;
}

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

using namespace std;

int main() {
    int n,m;
    cin >> n >> m;
    vector<int> a(m+1,0);
    for (int i=0; i<n; i++) {
        int k;
        cin >> k;
        for (int j=0; j<k; j++) {
            int ai;
            cin >> ai;
            a[ai]++;
        }
    }

    int ans = 0;
    for (int i=1; i<=m; i++) ans += a[i]>=n;
    cout << ans << endl;
}


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

using ll = long long;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;

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

#define ALL(v) (v).begin(), (v).end()
#define CHMAX(a,b) a=max(a,b)
#define CHMIN(a,b) a=min(a,b)

#define DEBUG(x) cerr<<#x<<": "<<(x)<<endl

int s,n,t,p,m;
char weekday[52], times[52];

bool allday, alltime, night;

int main(){
    int po = 0;
    while(true){
        scanf("%d%d%d%s%s%d%d",&s,&n,&t,weekday,times,&p,&m);
        if(s+n+t+p+m==0)break;
        allday = weekday[0]=='A';
        alltime = times[0]=='A';
        night = times[0]=='N';
        double ans = 0.0;
        double pr = 1.0;
        REP(i,n)pr *= (1.0 - 1.0 / p);
        using R = int;
        REP(begintime,24*60){
            R cur = begintime;
            double qr = 1.0;
            REP(i,m){
                R st = cur;
                R ed = st + s;
                bool cross = false;
                if(allday && alltime){
                    cross = true;
                }else if(allday && !alltime){
                    if(s > 12*60){
                        cross = false;
                    }else{
                        // s <= 12*60
                        while(st >= 24*60){
                            st -= 24*60;
                            ed -= 24*60;
                        }
                        cross = (0<=st && ed<12*60);
                    }
                }else if(!allday && alltime){
                    if(s > 24*60){
                        cross = false;
                    }else{
                        cross = (0<=st && ed<24*60);
                    }
                }else if(!allday && !alltime && !night){
                    if(s > 12*60){
                        cross = false;
                    }else{
                        cross = (0<=st && ed<12*60);
                    }
                }else if(!allday && !alltime && night){
                    if(s > 6*60){
                        cross = false;
                    }else{
                        cross = (0<=st && ed<6*60) || (18*60<=st && ed<24*60);
                    }
                }
                if(cross)qr *= pr;
                cur = (cur + t) % (7*24*60);
            }
            CHMAX(ans, 1.0-qr);
        }
        printf("%.10f\n",ans);
    }
    return 0;
}


Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
 
#define MAXN (int)(2*1e5 + 1)
#define MAXL 20
#define F first
#define endl "\n"
#define S second
#define MOD (int)(1e9 + 7)
#define lli long long int
#define sz(a) int(a.size())
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};

lli l, r;

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

  cin >> l >> r;
  lli m =2019;
  
  lli ans = INT_MAX;
  
  for(lli i = l; i <= l + 6000 and i <= r; i++){
    for(lli j = i+1; j <= l+ 6000 and j <= r; j++){
      // cout << i << " - " << j << endl;
      // cout << (i*j)%m << endl;
      ans = min(ans, (i*j)%m);
    }
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
n,x=map(int,input().split())
a=list(map(int,input().split()))
cnt=0
for i in range(n-1):
    if a[i]+a[i+1]>x:
            cnt+=a[i]+a[i+1]-x
            a[i+1]-=a[i]+a[i+1]-x
    if a[i+1]<0:
        a[i+1]=0
print(cnt)

Measured memory_bytes: 14592
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

import static java.lang.Integer.parseInt;

/**
 * Pair of Primes
 */
public class Main {

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

		boolean[] primes = primeB(10000);

		while ((line = br.readLine()) != null && !line.isEmpty()) {

			int N = parseInt(line);
			int count = 0;

			for (int i = 1, j = N; i <= N; i++, j--) {
				if (primes[i] && primes[j]) count++;
			}

			System.out.println(count);
		}
	}

	static boolean[] primeB(int n) {

		boolean[] ret = new boolean[n + 1];
		int _n = (int) Math.sqrt(ret.length);

		//2..
		Arrays.fill(ret, 2, ret.length, true);

		for (int i = 2; i <= _n; i++) {
			if (ret[i]) {
				for (int j = i + i; j < ret.length; j += i) {
					if (ret[j]) ret[j] = false;
				}
			}
		}
		return ret;
	}
}

Measured memory_bytes: 26068
#include<stdio.h>
#include<math.h>
int main(){
  double a,b,C,S,L,h;
  scanf("%lf %lf %lf",&a,&b,&C);
  C=C*M_PI/180;
  S=0.5*a*b*sin(C);
  L=a+b+sqrt(a*a+b*b-2*a*b*cos(C));
  h=2*S/a;
  printf("%lf %lf %lf\n",S,L,h);
  return 0; 
}



Measured memory_bytes: 2120
#include<stdio.h>
#include<ctype.h>
int main(void)
{
  int moji;
  int count[26]={0};
  while( (moji=getchar())!=EOF )
  {
    if(isupper(moji))
      moji = tolower(moji);
    count[moji-'a']++;
  }
  for(int i=0;i<26;i++)
  {
    printf("%c : %d\n", 'a' + i, count[i]);
  }

}

Measured memory_bytes: 1764
#include <algorithm>
#include <cstdint>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <cfloat>

using namespace std;

using lint=int64_t;
using uint=uint32_t;
using ulint=uint64_t;

template<class T>
using vector2d=vector<vector<T>>;

template<class T>
bool UpdateMax(T &a, const T &b){
  if(a<b){
    a=b;
    return true;
  }else{
    return false;
  }
}

template<class T>
bool UpdateMin(T &a, const T &b){
  if(a>b){
    a=b;
    return true;
  }else{
    return false;
  }
}

template <class T>
void OutVec(const vector<T>& vec){
  for(int i = 0; i < vec.size() - 1; ++i){
    cout<<vec[i]<<" ";
  }
  cout<<vec.back()<<endl;
}

template <class T>
void OutVec2d(const vector2d<T>& vec){
  for(auto v:vec){
    OutVec(v);
  }
}

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

  string s,t;
  cin>>s>>t;
  for(int i=0;i<s.size();i++){
    if(s[i]!=t[i]){
      cout<<"No"<<endl;
      return 0;
    }
  }
  cout<<"Yes"<<endl;

  return 0;
}




Measured memory_bytes: 3648
#include <stdio.h>
#include <cmath>
int js(int n){
	return n%2;
}
int main(){
	int n;
	scanf("%d",&n);
	int cnt = 0;
	for(int i=0;i<n;i++){
		int t;
		scanf("%d",&t);
		if(js(i+1)&&js(t)){
			cnt++;
		}
	}
	printf("%d",cnt);
}


Measured memory_bytes: 1728
#include<cstdio>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
int main(){
    int N;
    int maxmax=0;
    cin>>N;
    int lis[200]={0};
    for(int i=0;i<N;i++){
        int a;
        cin>>a;
        lis[a]++;
        maxmax=max(maxmax,a);
    }
    //cout<<maxmax;
    if(maxmax%2==0){
        for(int i=maxmax;i>=maxmax/2;i--){

/*
                            for(int j=0;j<10;j++){
        printf("[%d]",lis[j]);
    }
    puts("");

*/


            lis[i]--;
            if(lis[i]<0){
                puts("Impossible");
                return 0;
            }
        }
/*
            for(int i=0;i<10;i++){
        printf("[%d]",lis[i]);
    }
    puts("");
*/

        for(int i=maxmax/2+1;i<=maxmax;i++){
            lis[i]--;
            if(lis[i]==-1){
                puts("Impossible");
                return 0;
            }
        }
    }
    else{
        for(int i=maxmax;i>maxmax/2;i--){
            lis[i]-=2;
            if(lis[i]<0){
                puts("Impossible");
                return 0;
            }
        }
    }
    for(int i=0;i<200;i++){
        if(lis[i]!=0){
            if(i<=(maxmax+1)/2){
                puts("Impossible");
                return 0;
            }
        }
    }
    puts("Possible");


/*
    for(int i=0;i<10;i++){
        printf("[%d]",lis[i]);
    }
    puts("");
*/


    return 0;
}



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

void solve(){
  string s;
  vector<int> a(100);
  int top = 0;
  while(cin >> s){
    if(s == "+"){
      int x = a[top--], y = a[top--];
      a[++top] = x + y;
    }
    else if(s == "-"){
      int x = a[top--], y = a[top--];
      a[++top] = y - x;
    }
    else if(s == "*"){
      int x = a[top--], y = a[top--];
      a[++top] = x * y;
    }
    else{
      a[++top] = stoi(s);
    }
  }
  cout << a[top] << endl;
  return;
}

int main(){
  solve();
  return 0;
}



Measured memory_bytes: 3220
//↓template↓

#include "bits/stdc++.h"
using namespace std;
#define Would
#define you
#define all(n)  n.begin(),n.end()
const long long INF = 1e18;
const long long MOD = 1e9 + 7;
const double pi = acos(-1);
const int SIZE = 1 << 17;
int dx[] = { 1,0,-1,0 }, dy[] = { 0,1,0,-1 }, alp[30];
long long fac[200005], finv[200005], inv[200005];
vector<long long>dij;
struct edge { long long to, cost; };
vector<vector<edge> >G;

long long mod_pow(long long a, long long b) {
	long long res = 1;
	while (b) {
		if (b & 1) { res = res * a%MOD; }
		a = a * a%MOD;
		b >>= 1;
	}
	return res;
}

void addedge(int from, int to, int cost) {
	G[from].push_back({ to,cost });
	G[to].push_back({ from,cost });
}

//↑template↑

long long a, b, n, m, ans;
int main() {
	cin >> a >> b;
	for (int i = 0; i < 11; i++) {
		n = 0;
		for (int j = 1; j <= 5; j++) {
			long m = 0;
			for (int k = 0; k < 3; ++k) {
				for (int l = 0; l < 3; ++l) { m += (i + l) * 7 + j + l; }
			}
			n += m % 11 == b;
		}
		ans += n *= a < i + 3 ? 0 : (a - i - 3) / 11 + 1;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <map>
#include <bitset>
#include <vector>
#include <queue>

typedef long long ll;

#define FOR(i,a,b)   for(ll i = (a); i < (b); i++ )
#define REP(i, n)    FOR(i,0,n)
#define fi first
#define se second


const ll mod = 1000000007;
//              123456789


using namespace std;
 

///////////////////////////////////////////////
//
//
///////////////////////////////////////////////

////////////////////////////////////////////////
////////////////////////////////////////////////

int g[11234];

int find( int key ){
	//cout<<key<<" "<<g[key]<<endl;
	if( g[key] < 0 ) return key;
	return g[key] = find( g[key] );
}

void unite( int x, int y ){
	x = find( x );
	y = find( y );
	if( x == y ) return;
	
	if( g[x] < g[y] ) swap( x, y );//????????°???x??????????°???????
	g[y] += g[x];
	g[x] = y;
}

int N;
int Q;
int p;
int a, b;

int main(){
	
	cin>>N>>Q;
	
	fill( g, g+N+1, -1 );
	
	REP( i, Q ){
		scanf("%d %d %d", &p, &a, &b);
		if( p ){
			if( find(a) == find(b) ) puts("1");
			else{				puts("0");}
		}
		else{
			unite( a, b );
			//cout<<g[a]<<" "<<g[b]<<"----"<<endl;
		}
	}
	
	return 0;

}

Measured memory_bytes: 3188
if __name__ == "__main__":
    num_vertices = int(input())
    adj_matrix = [[0] * num_vertices for i in range(num_vertices)]

    for _ in range(num_vertices):
        vertex, _, *adjs = map(lambda x: int(x), input().split())
        for adj in adjs:
            adj_matrix[vertex -1][adj - 1] = 1

    for row in adj_matrix:
        print(" ".join([str(elem) for elem in row]))



Measured memory_bytes: 5668
def f(A,B,M,N):
    ans=1
    MOD=10**9+7
    r,c=1,1
    if (M*N not in A) or (M*N not in B):
        return 0;
    # print("MN in A or B")
    for o in range(M*N-1,0,-1):
        ans=ans%MOD
        if o in A:
            r+=1
            #row i-th's max is o:
            if o in B:
                c+=1
                continue;
            else:
                # o must in colum j which not the max
                ans*=c
                continue
        if o in B:
            # o in B but not in A
            c+=1
            ans*=r
            continue
        ans*=(r*c-(M*N-o))
    return ans%MOD;
N,M=(map(int,input().split()))
A=list(map(int,input().split()))
B=list(map(int,input().split()))

A=set(A)
B=set(B)
if len(A)!=N or len(B)!=M:
    print(0)
else:
    print(f(A,B,M,N))

Measured memory_bytes: 3188
N, M = [int(x) for x in input().split()]

if N == 1 and M == 1:
    print(1)
elif N == 1 or M == 1:
    print(max(N, M) - 2)
elif N == 2 or M == 2:
    print(0)
else:
    print((N-2) * (M-2))


Measured memory_bytes: 2940
def inp():exec('global inppp\ninpmoto,inppp=input().split(),[]\nfor i in inpmoto:\n try:inppp.append(int(i))if float(i).is_integer()else inppp.append(float(i));\n except:\n  try:inppp.append(str(i))\n  except:print("error in inp")');return inppp[0]if len(inppp)==1else list(inppp)
k = inp()
s = inp()
if len(s) <= k:
    print(s)
else:
    print(s[:k]+"...")

Measured memory_bytes: 9172
import sys, os

def main():
	arr = [0,0,0,0]
	for _ in range(3):
		a,b = map(int, input().split())
		arr[a-1] += 1
		arr[b-1] += 1
	flg = True
	for i in range(4):
		if arr[i] is 3:
			flg = False
		if arr[i] is 0:
			flg = False
	print("YES" if flg else "NO")
	return

main()

Measured memory_bytes: 3060
import sys
import copy
from collections import deque
import collections
stdin = sys.stdin

mod = 10**9+7

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

n = ni()

a = na()
suma = sum(a)
collection = dict(collections.Counter(a))


q = ni()
res = []
for _ in range(q):
    b, c = na()
    if b in collection:
        bnum = collection[b]
        del collection[b]
    else:
        bnum = 0
    suma -= b*bnum
    suma += c*bnum
    if c in collection:
        collection[c] += bnum
    else:
        collection[c] = bnum
    res.append(suma)

for i in res:
    print(i)


Measured memory_bytes: 108628
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <utility>

#define INF 999999999
#define mod 1000000007

#define rep(i,n) for(int i=0;i<int(n);i++)
#define REP(i,a,b) for(int i=(a);i<int(b);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back
#define MOD(x) (x%(mod))
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int>pi;

/*---------------------------------------------------*/

int main(){
  int n;
  while(cin>>n){
    if(n==0)break;
    int mini=INF;
    for(int y=0;y*y<=n;y++){
      for(int z=0;z*z*z<=n;z++){
	int x=n-y*y-z*z*z;
	if(x<0)continue;
	//cout<<x<<" "<<y<<" "<<z<<endl;
	mini=min(mini,x+y+z);
      }
    }
    cout<<mini<<endl;
    
  }
  return 0;
}

Measured memory_bytes: 3080
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;

const int inf = 999999999;
const double pi = acos(-1);
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};

#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())
#define vsort(v) sort(v.begin(), v.end());
#define ft first
#define sd second
#define pb push_back
#define it insert
#define sz(x) ((int)(x).size())
#define lb(a,n,k) (lower_bound(a,a+n,k) - a) 
#define vlb(a,k)  (lower_bound(a.begin(),a.end(),k) - a.begin())
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define ret return

ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

///////////////////////////////////////////////////////////////////////////

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

	rep(i,0,sz(s)){
        if(s[i] != ',')cout <<s[i];
        else cout << " ";
	}
	cout << endl;

	return  0;
}

Measured memory_bytes: 256
n=int(input())
l = [input() for i in range(n)]
L = [[0]*26 for i in range(n)]
s = ''

for i in range(n):
    for j in l[i]:
        L[i][ord(j)-97] += 1

M = L[0]
for k in range(1,n):
    for g in range(26):
        M[g] = min(L[k][g],M[g])

for a in range(26):
    for b in range(M[a]):
        s += chr(a+97)
print(s)

Measured memory_bytes: 9116
S = input()
T = input()

flag = False
for i in range(len(S)):
    s = ""
    for j in range(len(S)):
        a = (i+j)%len(S)
        s = s+S[a]
    if s==T:
        flag = True
        break
if flag:
    print("Yes")
else:
    print("No")

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


int main(){
    int init_s;
    cin >> init_s;

    int val = init_s;

    int i = 2;
    while(true){
        if(val == 4 || val == 2 || val == 1){
            cout << i + 2 << endl;
            break;
        }

        if (val % 2 == 0){
            val = val/2;
        }else{
            val = 3*val+1;
        }


        i += 1;
    }
    return 0;
}

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

struct Card{char suit, value;};

void bubble(struct Card A[],int N){
    for(int i=0;i<N;i++){
        for(int j=N-1;j>=i+1;j--){
            if (A[j].value<A[j-1].value){
                Card t=A[j];A[j]=A[j-1];A[j-1]=t;
            
            }
        }
    }
}

void selection(struct Card A[],int N){
    for(int i=0;i<N;i++){
        int minj=i;
        for(int j=i;j<N;j++){
            if(A[j].value<A[minj].value) minj=j;
        }
        Card t =A[i];A[i]=A[minj];A[minj]=t;
    }
}

void print(struct Card A[],int N){
    for(int i=0;i<N;i++){
        if(i>0) cout<<" ";
        cout<<A[i].suit<<A[i].value;
    }
    cout<<endl;
}

bool isStable(struct Card C1[],struct Card C2[], int N){
    for(int i=0;i<N;i++){
        if(C1[i].suit != C2[i].suit) return false;
    }
    return true;
}

int main(){
    Card C1[100],C2[100];
    int N;
    char ch;
    
    cin>>N;
    for (int i=0;i<N;i++){
        cin>>C1[i].suit>>C1[i].value;
    }
    
    for(int i=0;i<N;i++) C2[i]=C1[i];
    
    bubble(C1,N);
    selection(C2,N);
    
    print(C1,N);
    cout<<"Stable"<<endl;
    print(C2,N);
    if (isStable(C1,C2,N)){
        cout<<"Stable"<<endl;
    }else{
        cout<<"Not stable"<<endl;
    }
    
    return 0;
}


Measured memory_bytes: 3088
#include <iostream>
#include <string>
#include <stack>
#include <cctype>
#include <algorithm>
#include <vector>
using namespace std;
const double PI = 3.14159265358979323846;

long long int N, K;



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

	if (s == "ABC") {
		cout << "ARC" << endl;
	}
	else {
		cout << "ABC" << endl;
	}
	return 0;
}

Measured memory_bytes: 3624
#include<iostream>

using namespace std;

int main()
{
	int n, m,count;
	count = 0;
	cin >> n >> m;
	int i, j, a[51], b[51];

	for (i = 1; i <= m; i++)
	{
		cin >> a[i] >> b[i];
	}
	for (i = 1; i <= n; i++)
	{
		for (j = 1; j <= m; j++)
		{
			if(a[j]==i||b[j]==i)
			{
				
				count++;
				
			}
			
		}
		cout << count << endl;
		count = 0;
	}

    
	



}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <algorithm>
#include <cstdio>
#include <iomanip>
#include <queue>
#include <deque>
#include <stack>
#include <fstream>
#include <cmath>

#define ll int64_t
#define Rep(i, n) for (ll i = 0; i < n; i++)
using namespace std;
typedef vector<ll> vec;
typedef vector<vec> mat;

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

    ll X, Y;
    ll ans = 0;
    cin >> X >> Y;
    if (X == 1 && Y == 1) {
        ans = 1e6;
    } else {
        ans += 1e5 * max((ll)0, 4-X);
        ans += 1e5 * max((ll)0, 4-Y);
    }

    cout << ans << "\n";
}

Measured memory_bytes: 256
import scala.io.StdIn

object Main extends App {
  val n  = StdIn.readLine().toInt
  val a: Array[Int]  = StdIn.readLine().split(" ").map(_.toInt)

  def solve(a: Array[Int]): String = {

    a.foldLeft(0) { (acc, i) =>
      if (acc < i) i - 1 else if (acc == i) i else return "No"
    }
    "Yes"
  }

  println(solve(a))
}
  



Measured memory_bytes: 44748
#include <stdio.h>
int main(void)
{
    int n,k,y;
    int ans=0;
    scanf("%d\n%d",&n,&k);
    int x[n];
    for(int p=0;p<n;p++)
    {
        scanf("%d",&x[p]);
        y=k-x[p];
        if(y>x[p])
          ans+=x[p]*2;
        else
          ans+=y*2;
    }
    printf("%d",ans);
}


Measured memory_bytes: 128
#include <stdio.h>

#define MOD_BY 1000000007

int add(int a, int b) {
	return a + b - (a + b >= MOD_BY ? MOD_BY : 0);
}

int sub(int a, int b) {
	return b == 0 ? a : add(a, MOD_BY - b);
}

int mul(int a, int b) {
	int r = 0;
	while (b > 0) {
		if (b & 1) r = add(r, a);
		a = add(a, a);
		b >>= 1;
	}
	return r;
}

int pou(int a, int b) {
	int r = 1;
	while (b > 0) {
		if (b & 1) r = mul(r, a);
		a = mul(a, a);
		b >>= 1;
	}
	return r;
}

int inv(int a) {
	return pou(a, MOD_BY - 2);
}

int d2;

/*
https://www.kwansei.ac.jp/hs/z90010/sugakua/suuretu/tousasum/tousasum.htm

Sn = n(a+l) / 2
*/
int wa(int a, int l) {
	int n = l - a + 1;
	return mul(mul(n, add(a, l)), d2);
}

int main(void) {
	int N, K;
	int m;
	int kotae = 0;
	d2 = inv(2);
	if (scanf("%d%d", &N, &K) != 2) return 1;
	for (m = K; m <= N + 1; m++) {
		int sita, ue;
		/* 一番下m個 */
		sita = wa(0, m - 1);
		/* 一番上m個 */
		ue = wa(N - m + 1, N);

		kotae = add(kotae, add(sub(ue, sita), 1));
	}
	printf("%d\n", kotae);
	return 0;
}

/*

m個選ぶ時、一番下m個～一番上m個まで全て1個ずつ動かして作れる

*/


Measured memory_bytes: 1732
#include <iostream>
#include <map>
#include <vector>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <climits>
#include <stack>
#include <queue>
#include <set>
#include <cctype>
#include <bitset>
#include <type_traits>
#include <numeric>

#include <list>
using namespace std;

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define YES(j) cout << (j ? "YES" : "NO") << endl;
#define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
#define yes(j) std::cout << (j ? "yes" : "no") << endl;

int main(void)
{
    string s;
    long long k;
    cin >> s >> k;
    k--;
    int pos;
    if(k > 100) pos = 100;
    else pos = k;
    REP(i,s.length())
    {
        if(s[i] != '1')
        {
            cout << s[i] << endl;
            return 0;
        }
        else if(i == pos)
        {
            cout << s[i] << endl;
            return 0;
        }
    }
}


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

void fst()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
#endif
}
int nxt()
{
    int x;
    cin >> x;
    return x;
}
int nex_l()
{
    long long x;
    cin >> x;
    return x;
}

typedef long long ll;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<vi> vvi;
typedef vector<vb> vvb;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef vector<pair<int, int>> vpii;

#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define all(v) v.begin(), v.end()
#define binary(n) cout << bitset<31>(n) << "\n";
#define FOR(i, n) for (int i = 0; i < n; i++)
#define rep(i, a, b) for (int i = a; i < b; i++)
#define input_arr(a, n)         \
    for (int i = 0; i < n; i++) \
        cin >> a[i];
#define print_arr(a, n)         \
    for (int i = 0; i < n; i++) \
        cout << a[i] << " ";
#define deb(n) cerr << #n << "=" << n << "\n";

int main()
{

    int n;
    cin >> n;
    cout<<(1000-(n%1000))%1000;
}


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

#define rng(i, a, b) for (int i = int(a); i < int(b); i++)
#define rep(i, b) rng(i, 0, b)
#define gnr(i, a, b) for (int i = int(b) - 1; i >= int(a); i--)
#define per(i, b) gnr(i, 0, b)

using namespace std;

using ll = long long;
using P = pair<int, int>;

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a.at(i);

  int MaxA = 1'000'000;
  vector<int> sieve(MaxA + 1, 0);
  for (ll i = 0; i < n; i++) {
    int x = a.at(i);
    ll j = x;
    // 既に処理済みならばループを行う必要がない(行うと1だらけの入力とかで計算量オーバー)
    if (sieve.at(j) != 0) {
      sieve.at(j)++;
      continue;
    }
    while (j <= MaxA) {
      sieve.at(j)++;
      j += x;
    }
  }
  int res = 0;
  for (int i = 0; i < n; i++) {
    int x = a.at(i);
    if (sieve.at(x) == 1) {
      res++;
    }
  }
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 8008
import sys
from scipy.sparse.csgraph import floyd_warshall

N, M, L = map(int, input().split())
INF = 10 **9 +1
G = [[float('inf')] * N for i in range(N)]
for i in range(M):
  a, b, c = map(int, input().split())
  a, b, = a - 1, b -1
  G[a][b] = c
  G[b][a] = c

#全点間最短距離を計算
G = floyd_warshall(G)


#コストL以下で移動可能な頂点間のコスト1の辺を張る
E = [[float('inf')] * N for i in range(N)]
for i in range(N):
  for j in range(N):
    if G[i][j] <= L:
      E[i][j] = 1

#全点間最短距離を計算
E = floyd_warshall(E)

#クエリに答えていく
Q = int(input())
for i in range(Q):
  s, t = map(int, input().split())
  s, t = s - 1, t-1
  print(int(E[s][t] - 1) if E[s][t] != float('inf') else -1)

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

int main() {
	int N, X, T, Ans=0;
    cin >> N >> X >> T;
  	while (N>0){
      	N -= X;
      	Ans += T;
    }
  	cout << Ans << endl;
}

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

ll gcd(ll a, ll b){return b!=0 ? gcd(b, a%b) : a;}
ll lcm(ll a, ll b){return a / gcd(a, b) * b;}

int main(){
	int n;
	cin >> n;
	int d, x;
	cin >> d >> x;
	vector<int> a(n);
	rep(i, n) cin >> a[i];
	
	int ans = 0;
	rep(i, n){
		ans += (d - 1) / a[i] + 1;
	}
	
	ans += x;
	
	cout << ans << endl;
	
	return 0;
}



Measured memory_bytes: 256