akhauriyash/Code-Regression huggingface dataset:
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Main main = new Main();
		main.run();
	}

	void run() {
		Scanner sc = new Scanner(System.in);

		//Dは割り切る回数
		int D = sc.nextInt();
		//NはN番目に小さいという順序の指定。
		int N = sc.nextInt();

		int cnt=0;
		for (int i = 1; i < 10000000; i++) {

			int num=howisdiv(i);

			if(num==D) {
				cnt++;
			}

			if(cnt==N) {
				pln(i);
				return;
			}
		}
	}

	public int howisdiv(int x) {

		int ans=0;

		while(true) {

			if(x%100==0 && x/100!=0) {
				x/=100;
				ans++;
			}else {
				break;
			}

		}

		return ans;

	}

	//以下テンプレート

	public static int[] extgcd(int a, int b) {

		int x0 = 1;
		int x1 = 0;

		int y0 = 0;
		int y1 = 1;

		while (b != 0) {
			int q = a / b;
			int r = a % b;

			int x2 = x0 - q * x1;
			int y2 = y0 - q * y1;

			a = b;
			b = r;

			x0 = x1;
			x1 = x2;

			y0 = y1;
			y1 = y2;
		}

		return new int[] { a, x0, y0 };

	}

	static int gcd(int a, int b) {

		if (b == 0)
			return a;

		if (a < b) {
			int t = a;
			a = b;
			b = t;
		}

		return gcd(b, a % b);

	}

	static int lcm(int a, int b) {
		return a * b / gcd(a, b);
	}

	static void swap(int[] a) {
		int t;

		t = a[0];
		a[0] = a[1];
		a[1] = t;

		return;
	}

	static <T> void output(List<T> list) {

		for (int i = 0; i < list.size(); i++) {
			System.out.print(list.get(i));

			if (i != list.size() - 1) {
				System.out.print(" ");
			} else {
				nl();
			}
		}

	}

	static void output(String[][] str) {

		for (int i = 0; i < str.length; i++) {
			for (int j = 0; j < str[i].length; j++) {
				print(str[i][j]);
			}

			nl();
		}

	}

	static void output(boolean flg, String Yes, String No) {

		if (flg) {
			pln(Yes);
		} else {
			pln(No);
		}

	}

	static void output(String[][] str, int digit) {

		String dig = "%" + String.valueOf(digit) + "s";

		for (int i = 0; i < str.length; i++) {
			for (int j = 0; j < str[i].length; j++) {
				System.out.printf(dig, str[i][j]);
			}
			nl();
		}

	}

	static void pln(String str) {
		System.out.println(str);
	}

	static void pln(int x) {
		System.out.println(x);
	}

	static void print(String str) {
		System.out.print(str);
	}

	static void print(int x) {
		System.out.print(x);
	}

	static void print(String str, int times) {
		for (int i = 0; i < times; i++) {
			print(str);
		}
	}

	static void print(int x, int times) {
		for (int i = 0; i < times; i++) {
			print(x);
		}
	}

	static void nl() {
		System.out.println();
	}

}


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

#define int long long
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rep1(i,n) for(int i=1;i<=(int)(n);++i)
#define rep11(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define repm(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define sperase(v,n) (v).erase(remove(all(v), n), (v).end())
#define vdelete(v) (v).erase(unique(all(v)), (v).end())
#define pb(n) push_back(n)
#define mp make_pair
#define MOD 1000000007
#define INF LONG_LONG_MAX

int n,ans;

signed main() {
    cin >> n;
    rep(i,n) ans += i;
    cout << ans << endl;
}






Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int n,a,b,i,j;
  scanf("%d",&n);
  j=1000000000;
  a=n;
  for(i=0;i<10;i++){
    b+=a/j;
    a=a%j;
    j=j/10;
  }
  puts(n%b?"No":"Yes");
}

Measured memory_bytes: 128
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define FOR(i, a, b) for(i = a; i < b; ++i)
#define REP(i, n) FOR(i, 0, n)
#define comp(a, b) int comp(const void *a, const void *b)
#define MOD  1000000007

typedef unsigned int uint;
typedef unsigned long ul;
typedef long long ll;
typedef unsigned long long ull;

void TF_print(char boolean, char T[], char F[]){
    if(boolean){
        printf("%s\n", T);
    }else{
        printf("%s\n", F);
    }
}

int main(){
    uint N, i;
    ul lim;

    scanf("%u %lu", &N, &lim);
    ul C[N], D[N], LEFT = 0, RIGHT = 0;

    REP(i, N){
        scanf("%lu", &C[i]);
        D[i] = C[i];
    }

    if(C[0] > lim){
        LEFT = C[0] - lim;
        C[0] = lim;
    }

    FOR(i, 1, N){
        if(C[i - 1] + C[i] > lim){
            LEFT += (C[i - 1] + C[i] - lim);
            C[i] = lim - C[i - 1];
        }
    }

    if(D[N - 1] > lim){
        RIGHT = D[N - 1] - lim;
        D[N - 1] = lim;
    }

    FOR(i, 1, N){
        if(D[N - i] + D[N - i - 1] > lim){
            RIGHT += (D[N - i] + D[N - i - 1] - lim);
            D[N - i - 1] = lim - D[N - i];
        }
    }

    if(LEFT < RIGHT){
        printf("%lu\n", LEFT);
    }else{
        printf("%lu\n", RIGHT);
    }

    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(v) v.begin(),v.end()
using namespace std;
typedef long long ll;
 
int main(){
  int n,k,q;
  cin>>n>>k>>q;
  vector<int> a(q);
  rep(i,q) cin>>a[i];
  vector<int> st(n,k-q);
  rep(i,q) st[a[i]-1]++;
  rep(i,n){
    if(st[i]>0){
      cout<<"Yes"<<endl;
    }
    if(st[i]<=0){
      cout<<"No"<<endl;
    }
  }
}

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

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

  vector<pair<int, int>> arr;
  for (auto v : m) {
    arr.push_back(make_pair(v.second, v.first));
  }

  sort(arr.begin(), arr.end(), greater<pair<int, int>>());

  int sum = 0;
  for (int i = k; i < arr.size(); i++) {
    sum += arr[i].first;
  }
  cout << sum << endl;
}

Measured memory_bytes: 12536
n,tt = map(int, input().split( ))
t = tuple(map(int, input().split( )))
ans  = 0
ti = 0;
for i in range(n):
    if t[i] >= ti+tt:
        ans += tt 
    else:
        ans += t[i] - ti
    ti = t[i]
print(ans+tt)##最後の分
    

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

using namespace std;
typedef long long ll;

#define rep(i, N) for (int i = 0; i < (int)N; i++)
#define MOD pow(10,9)+7
#define LLINF pow(2,61)-1
#define INF pow(2,29)-1


int main() {
  int N; cin >> N;
  string result = "No";
  for (int i=1; i<=9; i++) {
    for (int j=1; j<=9; j++) {
      if (i*j==N) result = "Yes";
    }
  }
  cout << result << endl;
  return 0;
}

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

#define VIC ios::sync_with_stdio(0);cin.tie(0);ios_base::sync_with_stdio(0);
#define wtf(s) freopen((s), "w", stdout)
#define rff(s) freopen((s), "r", stdin)
#define pi (2 * acos(0))
typedef long double ld;
typedef long long ll;
#define endl '\n'
#define matrix vector<vector<ll>>
const int N = 700 + 3, mod = 1e9 + 7;

int dp[N][N], col[N];
bool con[N][N], vis[N];
vector<pair<int, int>> ve;
int solve(int i, int sum, int n)
{
    if (i == ve.size())
    {
        int f = n - sum;
        return (f * (f - 1)) / 2 + (sum * (sum - 1)) / 2;
    }
    if (dp[i][sum] != -1)
        return dp[i][sum];
    return dp[i][sum] = min(solve(i + 1, sum + ve[i].first, n),
                            solve(i + 1, sum + ve[i].second, n));
}

void dfs(int node, int c, int ans[], int n)
{
    col[node] = c;
    ans[c]++;
    for (int i = 1; i <= n; i++)
        if (con[i][node] && i != node)
        {
            if (col[i] == c)
            {
                cout << -1;
                exit(0);
            }
            if (col[i] == -1)
                dfs(i, !c, ans, n);
        }
}

int main()
{
    VIC
    int n, m;
    cin >> n >> m;
    for (int i = 1; i <= n; col[i++] = -1)
        for (int j = 1; j <= n; j++)
            con[i][j] = con[j][i] = true;
    while (m--)
    {
        int x, y;
        cin >> x >> y;
        con[x][y] = con[y][x] = false;
    }
    for (int i = 1; i <= n; i++)
    {
        if (col[i] != -1)
            continue;
        int ans[] = {0, 0};
        dfs(i, 0, ans, n);
        ve.emplace_back(ans[0], ans[1]);
    }
    memset(dp, -1, sizeof dp);
    cout << solve(0, 0, n);
    return 0;
}

Measured memory_bytes: 2688
#include <bits/stdc++.h>
using ll = long long;
using ld = long double;
using namespace std;

const int MAXN = 200001;

ll a[MAXN];

int main() {
#ifdef PAUNSVOKNO
    freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(false); cout.setf(ios::fixed); cout.precision(20); cout.tie(nullptr); cin.tie(nullptr);
    int n, a, b;
    cin >> n >> a >> b;
    vector<string> v = { "Alice", "Borys" };
    cout << v[(a + b) % 2] << "\n";
}

Measured memory_bytes: 256
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <regex>
#define REP(i,n) for(int i = 0; i < n; i++)
#define FOR(i,j,n) for(int i = j; i < n; i++)
#define RFOR(i,j,n) for(int i = j-1; i >= n; i--)
#define PREC(n) fixed << setprecision(n)
#define print_array(v) REP(__k, v.size()) { cout << v[__k]; if(__k != v.size()-1) cout << " "; else cout << endl; }
#define YesorNo(a) printf(a?"Yes\n":"No\n")
#define _LIBCPP_DEBUG 0
using namespace std;
int64_t MOD = 1000000007;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  string n;
  cin >> n;
  bool f = false;
  if(n[0] == n[1] && n[1] == n[2]) f = true;
  if(n[1] == n[2] && n[2] == n[3]) f = true;
  YesorNo(f);
  return 0;
}
//templete by private_yusuke

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef set<int> S;
bool dfs(bool t,S a,S b,int c,int d){
  //cout << t << " " << c << " " << d << endl;
  if(a.size()==0) return true;
  if(b.size()==0) return false;
  bool f;
  S n;
  if(t){
    f=false;
    if(a.find(c-1)!=a.end()){
      n=a;n.erase(c-1);
      f|=dfs(!t,n,b,c-1,d);
    }
    if(a.find(d+1)!=a.end()){
      n=a;n.erase(d+1);
      f|=dfs(!t,n,b,c,d+1);
    }
    if(a.find(c-1)==a.end()&&
       a.find(d+1)==a.end()){
      f=dfs(!t,a,b,c,d);
    }
  }else{
    f=true;
    if(b.find(c-1)!=b.end()){
      n=b;n.erase(c-1);
      f&=dfs(!t,a,n,c-1,d);
    }
    if(b.find(d+1)!=b.end()){
      n=b;n.erase(d+1);
      f&=dfs(!t,a,n,c,d+1);
    }
    if(b.find(c-1)==b.end()&&
       b.find(d+1)==b.end()){
      f=dfs(!t,a,b,c,d);
    }
  }
  return f;
}

int main(){
  int N,i,k;cin>>N;
  while(N--){
    S a,b;
    bool u[13]={};
    u[6]=1;
    for(i=0;i<6;i++){
      cin>>k;
      u[k-1]=1;
      a.insert(k);
    }
    k=0;
    for(i=0;i<13;i++){
      if(!u[i]){
        b.insert(i+1);
	k++;
      }
    }
    cout<<(dfs(1,a,b,7,7)?"yes":"no")<<endl;
  }
  return 0;
}

Measured memory_bytes: 3124
#include <bits/stdc++.h>
using ll = long long;
#define FOR(i, k, n) for(ll i = (k); i < (n); i++)
#define FORe(i, k, n) for(ll i = (k); i <= (n); i++)
#define FORr(i, k, n) for(ll i = (k)-1; i > (n); i--)
#define FORre(i, k, n) for(ll i = (k)-1; i >= (n); i--)
#define REP(i, n) FOR(i, 0, n)
#define REPr(i, n) FORre(i, n, 0)
#define ALL(x) (x).begin(), (x).end()
#define ALLr(x) (x).rbegin(), (x).rend()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;

const int INF = 1001001001;

int main(void){
  vector<vector<int>> a(3, vector<int>(3));
  REP(i, 3) REP(j, 3) cin >> a[i][j];
  int n;
  cin >> n;
  REP(i, n){
    int b;
    cin >> b;
    REP(j, 3) REP(k, 3){
      if(a[j][k] == b) a[j][k] = 0;
    }
  }
  bool ans = false;
  REP(i, 3){
    if(a[i][0]+a[i][1]+a[i][2] == 0) ans = true;
    if(a[0][i]+a[1][i]+a[2][i] == 0) ans = true;
  }
  if(a[0][0]+a[1][1]+a[2][2] == 0) ans = true;
  if(a[2][0]+a[1][1]+a[0][2] == 0) ans = true;
  if(ans)cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
using System;

namespace lisson2
{
    class Program
    {
        static void Main(string[] args)
        {
            // 整数の入力
            int N = int.Parse(Console.ReadLine());
            if (!(0 <= N && N <= 10000)) return;
            int x = N / 3;
            Console.WriteLine(x);
        }
     }
}

Measured memory_bytes: 11092
#include<bits/stdc++.h>
#include<math.h>
#include <stdio.h>
#include<vector>
#include<deque>
#include<stdlib.h>
//#include <algorithm>
#include<set>
#include <limits>
#include<iomanip>
#include<string>
#define rep(i,n) for(int i = 0; i < n; i++)
typedef long long ll;
using namespace std;
#define llMAX numeric_limits<long long>::max()
#define intMAX numeric_limits<int>::max()
#define ll long long
#define d_5 100000
#define d9_7 1000000007
int main(void){
  int n;
  cin >> n;
  vector<int> a;
  int tmp;
  rep(i,n){
    cin >> tmp;
    tmp--;
    a.push_back(tmp);
  }
  int dup=0;
  vector<int> nums(d_5,0);
  rep(i,n){
    nums[a[i]]++;
  }
  rep(i,d_5){
    dup+=max(0,nums[i]-1);
  }

  cout<<n-((dup+1)/2)*2;
	return 0;
}

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

int main(){
    int N,M;
    cin >> N >> M;
    vector<vector<int>> S(M, vector<int>(N,0));
    for (int i=0; i<M; i++){
        int k;
        cin >> k;
        for(int j=0; j<k; j++){
            int s;
            cin >> s;
            S.at(i).at(s-1) = 1;
        }
    }
    vector<int> p(M);
    for(int i=0; i<M; i++){
        cin >> p.at(i);
    }
    int ans=0;
    for(int bit=0; bit<(1<<N); bit++){
        vector<int> switches(N,0);
        for(int i=0; i<N; i++){
            if(bit & (1<<i)){
                switches.at(i) = 1;
            }
        }
        // int check = 0;
        bool lights_on = true;
        for(int i=0; i<M; i++){
            // i番目の電球
            int check = 0;
            for(int j=0; j<N; j++){
                // j番目のスイッチ
                check += S.at(i).at(j) * switches.at(j);
            }
            if(check%2 != p.at(i)){
                lights_on = false;
                break;
            }
        }
        if(lights_on){
            ans++;
        }
    }
    cout << ans << endl;

}


Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep1(i, n) for (ll i = 1; i < (ll)(n); i++)
const ll mo = 1000000007;
const ll INF = 1LL << 60; //MAX 9223372036854775807
ll ans = INF;
ll t[401][401] = {};

int main()
{
ll n,ma,mb;
cin >> n>>ma>>mb;

rep(i,401)rep(j,401){
    t[i][j]=INF;
}
t[0][0]=0;
tuple<ll, ll, ll> data[n];
rep(i,n){
    ll a,b,c;
    cin >> a>>b>>c;
    data[i] = make_tuple(a, b, c);
}
rep(i,n){
    ll x,y,z;
    tie(x, y, z) = data[i];
    rep(j,401)rep(k,401){
        if(t[400-j][400-k]!=INF){
            t[400-j+y][400-k+x]=min(t[400-j+y][400-k+x],t[400-j][400-k]+z);
        }
    }
}
ll ca=ma,cb=mb;
bool ch=0;
while(ca<401&&cb<401){
    if(t[cb][ca]!=INF){
        ch=1;
        ans=min(ans,t[cb][ca]);
    }
    ca+=ma;
    cb+=mb;
}
if(ch)cout << ans << endl;
else cout << "-1" << endl;
return 0;
}

Measured memory_bytes: 1536
#include <bits/stdc++.h>
#define all(a) (a).begin(), (a).end()
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define RREP(i, n) for(int (i)=(n)-1, (i)>=0; (i)--)
#define ios() cin.tie(0), ios::sync_with_stdio(false)
typedef long long ll;
typedef unsigned long long ull;
ll const MOD = 1e9+7;
ll const INF = 1e18;
using namespace std;

int main(){
    string s, t;
    cin >> s >> t;
    REP(i, s.length()){
        cout << s[i];
        if(i < t.length()){
            cout << t[i];
        }
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
#define X first
#define Y second
#define mod 1e9+7
#define pb push_back
#define mp make_pair
#define abs(x) ((x)>0?(x):(-(x)))
#define F(n) Fi(i,n)
#define Fi(i,n) Fl(i,0,n)
#define Fl(i,l,n) for(int i=l;i<n;i++)
#define memres(a) memset(a,0,sizeof(a))
int gcd(int a,int b){if(b==0)return a;return gcd(b,a%b);}

int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);
	int a[200000],n,k=0;
	cin>>n;
	F(n)cin>>a[i];
	F(n)if(a[i]==k+1)k++;
	if(k==0)cout<<"-1"<<endl;
	else cout<<n-k<<endl;
return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <utility>
#include <functional>
#include <bitset>
#include <cstdint>

using namespace std;
using lli = long long int;
using i64 = int64_t;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0) 
{ v = vector<T>(n+o); for (size_t i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> void read_n(T a[], size_t n, size_t o = 0)
{ for (size_t i=o; i<n+o; ++i) cin >> a[i]; }
template<class T> T gabs(const T& x) { return max(x, -x); }
#define abs gabs

int main() {
  i64 n;
  cin >> n;
  i64 y = 1;
  for (; 2 * y <= n; y *= 2);
  cout << y << '\n';
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
class Dice {
private:
    void shift(int i, int j, int k, int l) {
        int t=a[i];a[i]=a[j];a[j]=a[k];a[k]=a[l];a[l]=t;
    }
public:
    int a[7]={0};
    void move(char d) {
        if(d=='N') shift(1,2,6,5);
        else if(d=='E') shift(1,4,6,3);
        else if(d=='W') shift(1,3,6,4);
        else if(d=='S') shift(1,5,6,2);
    }
};
int main() {
    Dice d; string s;
    for(int i = 1; i <= 6; ++i) cin >> d.a[i];
    cin >> s;
    for(int i = 0; i < s.length(); ++i) d.move(s[i]);
    cout << d.a[1] << endl;
    return 0;
}


Measured memory_bytes: 3204
#include <bits/stdc++.h>
 
#define rep(i,n) for(ll i=0;i<n;++i)
#define all_map(pos,mp) for(ll pos=mp.begin();pos!=mp.end();pos -++)
#define ALL(a) (a).begin(),(a).end()

using namespace std;
using ll  = long long;
using pll = pair<ll, ll>;

const ll MOD  = 1e9 + 7;
const ll LINF = 1LL << 62;
const int INF = 1e9 + 7;

int main(){
    ll n, k;
    cin >> n >> k;

    ll p[n], c[n];
    rep(i, n){
        cin >> p[i];
        p[i]--;
    }
    rep(i, n)cin >> c[i];

    ll ans = -LINF;
    rep(i, n){
        ll loop_cnt = 0;
        ll loop_sum = 0;
        ll pos = i;
    
        //ループを見つける
        while(true){
            loop_cnt++;
            loop_sum += c[pos];

            pos = p[pos];
            if(pos == i)break;
        }

        ll cnt = 0;
        ll score = 0;
        while(true){
            cnt++;
            score += c[pos];

            if(cnt > k)break;

            ll num_loop = (k - cnt) / loop_cnt;
            ans = max(ans, score + max(0ll, loop_sum)*num_loop);

            pos = p[pos];
            if(pos == i)break;
         }
    }

    cout << ans << endl;
}

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

typedef long long ll;
typedef long double ld;
typedef vector<ll> vi;
typedef pair<ll, ll> pii;
typedef vector<pii> vii;
typedef map<ll, ll> mii;
const int MOD = 1e9 + 7;

#define fastIO() \
ios_base::sync_with_stdio(false); cin.tie(nullptr);
#define endl "\n"
#define pb push_back
#define ff first
#define ss second
#define mp make_pair 

struct Matrix {
    vector<vi> mat; // the contents of matrix as a 2D-vector
    int n_rows, n_cols; // number of rows and columns

    Matrix(vector<vi> values): mat(values), n_rows(values.size()), 
        n_cols(values[0].size()) {}

    static Matrix identity_matrix(int n) {
        // Return I_n - the identity matrix of size n.
        // This function is static, because it creates a new Matrix instance
        vector<vi> values(n, vi(n, 0));
        for (int i = 0; i < n; ++i)
            values[i][i] = 1;
        return values;
    }

    Matrix operator*(const Matrix &other) const {
        int n = n_rows, m = other.n_cols;
        vector<vi> result(n_rows, vi(m, 0));
        for (int i = 0; i < n; ++i) {
            for (int j = 0; j < m; ++j) {
                for (int k = 0; k < n_cols; ++k) {
                    result[i][j] = (result[i][j] + mat[i][k] * 1ll
                                     * other.mat[k][j]) % MOD;
                }
            }
        }
        // Multiply matrices as usual, then return the result as the new Matrix
        return Matrix(result);
    }

    inline bool is_square() const {
        return n_rows == n_cols;
    }
};

Matrix fast_exponentiation(Matrix m, ll power) {
    assert(m.is_square());
    Matrix result = Matrix::identity_matrix(m.n_rows);

    while(power) {
        if(power & 1)
            result = result * m;
        m = m * m;
        power >>= 1;
    }

    return result;
}


int main() {
    int n;
    ll k;
    cin >> n >> k;
    vector<vi> A(n, vi(n));
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            cin >> A[i][j];
        }
    }
    Matrix C(A);
    C = fast_exponentiation(C, k);
    ll ans = 0;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            ans = (ans + C.mat[i][j]) % MOD;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#include <algorithm>
#include <vector>
#include <iostream>
#include <string>
using namespace std;
 
int main() {
  //input
  int n; cin >> n;
  long m;
  m = 1000000007;
  long long ten,nine,eight;
  long long temp;
  long long ans;
  ten = 1;
  nine = 1;
  eight = 1;
  
  //compute
    for(int i = 0;i < n; i++){
        ten = (ten * 10) % m;
        nine = (nine * 9) % m;
        eight = (eight * 8) % m;
 
     }
   
  if(ten - nine - nine < 0){
    temp = ((ten - nine - nine) % m) + m;
  }else{
    temp = ((ten - nine - nine) % m);
  }
   ans = (temp + eight) % m;
 
  //output
  cout << ans << endl;
}

Measured memory_bytes: 3552
#include "bits/stdc++.h"

// clang-format off
template <typename T> T gcd(T a, T b) { return b == 0 ? a : gcd(b, a % b); }
template <typename T> T lcm(T a, T b) { return a * b / gcd(a, b); }
template <typename T> T clamp(T val, T min, T max) { return val < min ? min : (max < val ? max : val); }
template <typename T> size_t max_index(T begin, T end) { return distance(begin, max_element(begin, end)); }
template <typename T> size_t min_index(T begin, T end) { return distance(begin, min_element(begin, end)); }
// clang-format on

#define int long long
#define YES "Yes"
#define NO  "No"

using namespace std;

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

  bool flag = true;
  int num = 0;

  string s; cin >> s;
  for (int i = 0; i < 3; ++i) if (s[i] == '1') ++num;

  cout << num << endl;
  // cout << (flag ? YES : NO) << endl;
  
  return 0;
}


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

using namespace std;

int main() {

	int n, x, sum;

	while (true) {

		sum = 0;
		cin >> n >> x;
		if (n == 0 && x == 0)break;

		for (int i = 1; i <= n;i++) {

			for (int j = 2; j <= n;j++) {

				for (int k = 3; k <= n;k++) {

					if (i + j + k == x&& i < j && j < k)sum++;
				}
			}
		}
		cout << sum << endl;
	}
	//cin >> /*変数他*/;
	//cout << /*文字列*/ << endl;
	return 0;
}


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

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()
#define all2(a, b) (a).begin(), (a).begin() + (b)
#define debug(vari) cerr << #vari << " = " << (vari) << endl;

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

	sort(all(s));
	sort(all(t));
	reverse(all(t));

	cout << ((s < t) ? "Yes" : "No") << endl;
	return (0);
}


Measured memory_bytes: 3524
def PrintArr(a)
	a.length.times { |i|
		print " " unless i == 0
		print a[i]
	}
	puts
end

def InsertionSort(a, g)
	for i in g...a.length
		v = a[i]
		j = i - g
		while j >= 0 and v < a[j]
			a[j+g] = a[j]
			j = j - g
			$cnt += 1
		end
		a[j+g] = v
	end
end

a = Array.new
gets.to_i.times { a << gets.to_i }

$cnt = 0
g = Array.new
m = 0
n = 0

while true
	n += 5**m
	break if n > a.length
	g << n
	m = g.length
end

g.sort!.reverse!

for i in 0...m
	InsertionSort(a, g[i])
end

puts m
PrintArr(g)
puts $cnt
a.each {|n| puts n }

Measured memory_bytes: 16688
/*
・問題をグラフに言い換える（グラフ上の良い辺集合のうち最適なものを見つける問題に言い換える）
・「良い辺集合である」ことを，すぐ判定可能な条件に言い換える
・クラスカル的な貪欲法で解く
いずれも発想できず・・・
*/
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define MOD 1000000007
typedef long long int ll;

using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;

ll extgcd(ll a, ll b, ll &x, ll &y) {
  ll g = a; x = 1; y = 0;
  if (b != 0) g = extgcd(b, a % b, y, x), y -= (a / b) * x;
  return g;
}
ll gcd(ll a, ll b) { ll x, y; return extgcd(a, b, x, y);}

class llm{
	ll n;
public:
	llm(){n = 0;}
	llm(ll n){this->n = (n >= 0) ? (n % MOD) : (MOD - 1 - (-n-1 % MOD));}
	operator ll() const {return n;}
	llm operator+(const llm &y) const{ return llm((ll)*this + (ll)y);}
	llm operator+=(const llm &y) { *this = *this + y; return *this;}
	llm operator-(const llm &y) const{ return llm((ll)*this - (ll)y);}
	llm operator-=(const llm &y) { *this = *this - y; return *this;}
	llm operator-() const{ return llm(0) - *this;}
	llm operator*(const llm &y) const{ return llm((ll)*this * (ll)y);}
	llm operator*=(const llm &y) { *this = *this * y; return *this;}
	llm operator/(const llm &y) const{ return *this * y.inv();}
	llm operator/=(const llm &y) { *this = *this / y; return *this;}
	llm inv() const{
		ll x, y;
		if (extgcd(n, MOD, x, y) == 1) return llm(x);
  		return llm(0); // unsolvable
	}
	friend istream& operator >> (istream& os, llm& x);
	friend ostream& operator << (ostream& os, const llm& x);
};
istream& operator >> (istream& is, llm& x){ll n; is >> n; x = llm(n); return is;}
ostream& operator << (ostream& os, const llm& x){os << (ll)x; return os;}

template<typename T> T comb(ll n, ll k){
	T ret = 1;
	for(ll i=1;i<=k;i++) ret = ret * T(n - k + i) / T(i);
	return ret;
}

ll N, H, W;
ll r[114514], c[114514], a[114514];

ll p[214514], v[214514], e[214514];


int parent(int n){
	while(p[n] != -1){
		n = p[n];
	}
	return n;
}


int main(void){
	cin >> N >> H >> W;
	
	vector<pair<int, pair<int, int> > > cards;
	for(int i=0;i<N;i++){
		cin >> r[i] >> c[i] >> a[i]; r[i]--; c[i]--;
		cards.pb(mp(-a[i], mp(r[i], c[i])));
	}
	sort(cards.begin(), cards.end());

	// vertex index: 0, ..., H-1, H, ..., H+W-1 
	for(int i=0;i<H+W;i++){
		p[i] = -1;
		v[i] = 1;
		e[i] = 0;
	}

	ll ans = 0;
	for(auto card : cards){
		ll i = card.second.first, j = H + card.second.second;
		ll parI = parent(i), parJ = parent(j);
		if (parI != parJ){ // 非連結の場合
			if (v[parI] + v[parJ] >= e[parI] + e[parJ] + 1){
				// 繋ぐ
				ans += -card.first;
				if (v[parI] > v[parJ]) swap(parI, parJ);
				//小さな方から大きな方へ繋ぐ
				p[parI] = parJ;
				v[parJ] += v[parI];
				e[parJ] += e[parI] + 1;
			}
		}else{ // 連結の場合
			if (v[parI] >= e[parI] + 1){
				// 繋ぐ
				ans += -card.first;
				e[parI]++;
			}
		}
	}
	cout << ans << endl;

    return 0;
}


Measured memory_bytes: 8948
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<string>
#include<cmath>
#include<numeric>
#include<vector>
#include<tuple>
using namespace std;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define vint vector<int> 
#define vvint vector<vint>
#define ct(a) cout<<a<<endl
typedef long long ll;
const int MOD = 1e9 + 7;
ll N,T,ans=0;
int main(void)
{
	cin >> N>>T;
	ll cur=0;
	int u;
	FOR(i, 0, N) {
		cin >> u;
		int cul = u + T;
		if(cul-cur<T)ans += cul - cur;
		else ans += T;
		cur = cul;
	}
	cout << ans << endl;

return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for (register int i=(a); i<=(b); ++i)
#define per(i,a,b) for (register int i=(a); i>=(b); --i)
using namespace std;

inline char getch() {
	static char buf[300000], *p1 = buf, *p2 = buf;
	return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 300000, stdin), p1 == p2) ? EOF : *p1++;
}
inline int read() {
	char ch = getch(); int x = 0;
	while (!isdigit(ch)) ch = getch();
	while (isdigit(ch)) { x = (x<<3) + (x<<1) + ch - '0'; ch = getch(); }
	return x;
}

const int maxm = 100005, MOD = 1000000007;
int p[30][3][3], q[3][3], t[3][3], A[3][3];
int x, last = -1, n, m;

inline void mul33(int a[3][3], int b[3][3], int c[3][3]) {
	t[0][0] = (1LL * a[0][0] * b[0][0] + 1LL * a[0][1] * b[1][0] + 1LL * a[0][2] * b[2][0]) % MOD;
	t[0][1] = (1LL * a[0][0] * b[0][1] + 1LL * a[0][1] * b[1][1] + 1LL * a[0][2] * b[2][1]) % MOD;
	t[0][2] = (1LL * a[0][0] * b[0][2] + 1LL * a[0][1] * b[1][2] + 1LL * a[0][2] * b[2][2]) % MOD;
	t[1][0] = (1LL * a[1][0] * b[0][0] + 1LL * a[1][1] * b[1][0] + 1LL * a[1][2] * b[2][0]) % MOD;
	t[1][1] = (1LL * a[1][0] * b[0][1] + 1LL * a[1][1] * b[1][1] + 1LL * a[1][2] * b[2][1]) % MOD;
	t[1][2] = (1LL * a[1][0] * b[0][2] + 1LL * a[1][1] * b[1][2] + 1LL * a[1][2] * b[2][2]) % MOD;
	t[2][0] = (1LL * a[2][0] * b[0][0] + 1LL * a[2][1] * b[1][0] + 1LL * a[2][2] * b[2][0]) % MOD;
	t[2][1] = (1LL * a[2][0] * b[0][1] + 1LL * a[2][1] * b[1][1] + 1LL * a[2][2] * b[2][1]) % MOD;
	t[2][2] = (1LL * a[2][0] * b[0][2] + 1LL * a[2][1] * b[1][2] + 1LL * a[2][2] * b[2][2]) % MOD;
	c[0][0] = t[0][0]; c[0][1] = t[0][1]; c[0][2] = t[0][2];
	c[1][0] = t[1][0]; c[1][1] = t[1][1]; c[1][2] = t[1][2];
	c[2][0] = t[2][0]; c[2][1] = t[2][1]; c[2][2] = t[2][2];
}

inline void mul31(int a[3][3], int b[3][3], int c[3][3]) {
	t[0][0] = (1LL * a[0][0] * b[0][0] + 1LL * a[0][1] * b[1][0] + 1LL * a[0][2] * b[2][0]) % MOD;
	t[1][0] = (1LL * a[1][0] * b[0][0] + 1LL * a[1][1] * b[1][0] + 1LL * a[1][2] * b[2][0]) % MOD;
	t[2][0] = (1LL * a[2][0] * b[0][0] + 1LL * a[2][1] * b[1][0] + 1LL * a[2][2] * b[2][0]) % MOD;
	c[0][0] = t[0][0]; c[1][0] = t[1][0]; c[2][0] = t[2][0];
}

inline void mulPower(int k, int a[3][3]) {
	per (i, 29, 0) if (k>>i&1) mul31(p[i], a, a);
}


int main() {
	p[0][0][0] = 1; p[0][0][1] = 0; p[0][0][2] = 1;
	p[0][1][0] = 2; p[0][1][1] = 1; p[0][1][2] = 2;
	p[0][2][0] = 1; p[0][2][1] = 1; p[0][2][2] = 2;
	q[0][0] = 1; q[0][1] = 0; q[0][2] = 0;
	q[1][0] = 2; q[1][1] = 1; q[1][2] = 0;
	q[2][0] = 1; q[2][1] = 1; q[2][2] = 1;
	rep (i, 1, 29) mul33(p[i-1], p[i-1], p[i]);
	A[0][0] = 1; n = read(); m = read();
	while (m--) {
		x = read();
		mulPower(x-last-1, A);
		mul31(q, A, A);
		last = x;
	}
	mulPower(n-last-1, A);
	printf("%d\n", A[2][0]);
	return 0;
}

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

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

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

int a, b;

signed main() {
	cin >> a >> b;
	if (a <= b)cout << "unsafe" << endl;
	else cout << "safe" << endl;
}


Measured memory_bytes: 3592
#include<stdio.h>
int main(void){
  long h,w,s;
  scanf("%ld%ld",&h,&w);
  s=h*w;
  if(h==1||w==1){
    printf("1");
  }
  else if(s%2==0){
    printf("%ld",s/2);
  }
  else{
    printf("%ld",(s/2)+1);
  }
  return 0;
}
  


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

int main()
{
    long long N, A, B, C, D, E;
    cin >> N >> A >> B >> C >> D >> E;

    long long min = A;
    if (min > B) min = B;
    if (min > C) min = C;
    if (min > D) min = D;
    if (min > E) min = E;

    cout << (((N + (min - 1)) / min) + 4) << endl;
    return 0;
}


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

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cin>>n;
    ans=(n/3)*(n/3)*(n/3);
    cout<<fixed<<setprecision(8)<<ans<<endl;
}


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

const int N = 1e5;
struct Edge
{
	int v,nxt;
} e[(N<<1)+3];
int fe[N+3];
int sg[N+3];
int n,en;

void addedge(int u,int v)
{
	en++; e[en].v = v;
	e[en].nxt = fe[u]; fe[u] = en;
}

void dfs(int u,int prv)
{
	for(int i=fe[u]; i; i=e[i].nxt)
	{
		int v = e[i].v;
		if(v==prv) continue;
		dfs(v,u);
		sg[u] ^= sg[v];
	}
	if(u!=1) sg[u]++;
}

int main()
{
	scanf("%d",&n);
	for(int i=1; i<n; i++)
	{
		int u,v; scanf("%d%d",&u,&v);
		addedge(u,v); addedge(v,u);
	}
	dfs(1,0);
	if(sg[1]) puts("Alice");
	else puts("Bob");
	return 0;
}

Measured memory_bytes: 7296
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define FOR(i,a,b) for(int i=(a); i<=(b); i++)
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define chmin(a,b) if((a)>(b)) (a)=(b);
#define chmax(a,b) if((a)<(b)) (a)=(b);
#define vi vector<int>
#define pii pair<int,int>
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define pb push_back
#define pf push_front
int gcd(int a,int b){/*a>=0,b>=0,￢(a=b=0)*/
  while(min(a,b)>0){if(a<b)swap(a,b);a%=b;}return max(a,b);
}
int dx[]={1,0,-1,0,1,-1,-1,1};
int dy[]={0,1,0,-1,1,1,-1,-1};
const int MOD = 1e9+7;
const long long INF = 1e18+10;

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

signed main(){
	int n;
	cin>>n;
	vi a(n);
	rep(i,n){
		cin>>a[i];
	}

	int kane=1000;
	rep(i,n-1){
		if(a[i]<a[i+1]){
			int k=kane/a[i];
			kane+=k*(a[i+1]-a[i]);
		}
	}
	cout<<kane<<endl;
	return 0;


}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define mp make_pair
#define pb push_back
#define vll vector<ll>
#define endl "\n"
#define pll pair<ll,ll>
#define all(x) (x).begin() , (x).end()
#define f first
#define s second
#define pr(x) cout<<x<<endl;
#define pr2(x,y) cout<<x<<" "<<y<<endl;
#define pr3(x,y,z) cout<<x<<" "<<y<<endl;
#define prv(v) for(auto x:v) cout<<x<<" ";
#define ffs fflush(stdout);
#define int ll
using namespace std;
 
const ll N =(1e5+5);
const ll MOD = 1e9+7;
const ll INF = LLONG_MAX;
const ll LOG = 29;
#define PI 3.141592653589793238 


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

void solve(){
    ll a,b,n;
    cin>>a>>b>>n;
    ll x = min(b-1,n);
    cout<<(a*x)/b- a*(x/b)<<endl;
}   
 
 
signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
     
    ll t=1;
    while(t--){
        solve();
    }    
    }


Measured memory_bytes: 3604
//apc001_b.cpp
//Sun Dec  2 16:28:51 2018

#include <iostream>
#include <string>
#include <queue>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#define INTINF 2147483647
#define LLINF 9223372036854775807
using namespace std;
using ll=long long;
typedef pair<int,int> P;

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

	ll a[n],b[n];
	for (int i=0;i<n;i++){
		cin >> a[i];
	}
	for (int i=0;i<n;i++){
		cin >> b[i];
	}

	ll pos = 0;
	ll neg = 0;
	ll total = 0;
	for (int i=0;i<n;i++){
		total = total + b[i]-a[i];
		if (a[i]>b[i]){
			pos = pos + a[i]-b[i];
		}else if (a[i]<b[i]){
			ll temp = ceil((long double)(b[i]-a[i])/2);
			neg = neg + temp;
//			neg = neg + (b[i]-a[i]+1)/2;
//			cout << i << " " << temp << endl;
		}
	}

//	cout << pos << " " << neg << endl;

	if (total >= neg){
		cout << "Yes" << endl;
	}else {
		cout << "No" << endl;
	}

}

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

using namespace std;

const int Value[6] = { 1,5,10,50,100,500 };

int main() {
	int cnt, sum;

	sum = 0;
	for (int i = 0; i < 6; ++i) {
		cin >> cnt;
		sum += Value[i] * cnt;
	}
	if (sum < 1000) {
		cout << "0" << endl;
	}
	else {
		cout << "1" << endl;
	}
}



Measured memory_bytes: 3100
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<char,char> P;
const LL mod=1000000007;
const LL LINF=1LL<<62;
const LL INF=1<<17;


vector<LL> fact;
vector<LL> inver(200001);
 
LL combi(int n,int r){
    if(n<r||n<0||r<0) return 0;
    return fact[n]%mod*inver[n-r]%mod*inver[r]%mod;
}
 
 
LL fpow(LL a, LL n){
    LL x = 1;
    while(n > 0){
        if(n&1){
            x=x*a%mod;
        }
        a=a*a%mod;
        n >>= 1;
    }
    return x;
}
 
void set_combi(){
    LL s=1;
    fact.push_back(1);
    for(int i=1;i<=200000;i++){
        s*=i;
        s%=mod;
        fact.push_back(s);
    }
    inver[200000]=fpow(fact[200000],mod-2);
    for(int i=199999;i>=0;i--){
        inver[i]=inver[i+1]*(i+1)%mod;
    }
}
 


int main(){
    set_combi();
    int N,X;cin >> N >> X;
    vector<int> s(N);
    vector<vector<LL>> dp(N+1,vector<LL> (100001,0));
    int mini = INF;
    for (int i = 0; i < N; i++) {
        cin >> s[i];
        mini = min(mini,s[i]);
    }
    sort(RALL(s));
    dp[0][X]++;
    for (int i = 0; i < N; i++) {
        for (int j = 0; j <= X; j++) {
            dp[i+1][j%s[i]]=(dp[i+1][j%s[i]]+dp[i][j])%mod;
            dp[i+1][j]=(dp[i+1][j]+dp[i][j]*(N-1-i))%mod;
        }
    }
    LL ans=0;
    for (int i = 0; i < mini; i++) {
        ans=(ans+dp[N][i]*i)%mod;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 161136
def Solve (A, B):
    score = 0
    r = [A, B]
    for i in r:
        if i == '3':
            score += 1
        elif i == '2':
            score += 2
        elif i == '1':
            score += 3
    if A == '1' and B == '1':
        score += 4
    return score*100000
    

A, B = input().split()
print(Solve(A, B))

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

struct Dice {
    enum {
        TOP,
        NORTH,
        WEST,
        SOUTH,
        EAST,
        BOTTOM
    };
    int spots[6];

    Dice() {
        spots[TOP] = 1;
        spots[NORTH] = 2;
        spots[WEST] = 3;
        spots[SOUTH] = 5;
        spots[EAST] = 4;
        spots[BOTTOM] = 6;
    }

    int top() {
        return spots[TOP];
    }

    void rotate(string dir) {
        if (dir == "north") {
            rotate_north();
        } else if (dir == "west") {
            rotate_west();
        } else if (dir == "south") {
            rotate_south();
        } else if (dir == "east") {
            rotate_east();
        } else {
            cerr << "ERROR" << endl;
        }
    }
    void rotate_north() {
        int nspots[6];
        nspots[TOP] = spots[SOUTH];
        nspots[NORTH] = spots[TOP];
        nspots[WEST] = spots[WEST];
        nspots[SOUTH] = spots[BOTTOM];
        nspots[EAST] = spots[EAST];
        nspots[BOTTOM] = spots[NORTH];
        for (int i = 0; i < 6; i++) spots[i] = nspots[i];
    }
    void rotate_south() {
        int nspots[6];
        nspots[SOUTH] = spots[TOP];
        nspots[TOP] = spots[NORTH];
        nspots[WEST] = spots[WEST];
        nspots[BOTTOM] = spots[SOUTH];
        nspots[EAST] = spots[EAST];
        nspots[NORTH] = spots[BOTTOM];
        for (int i = 0; i < 6; i++) spots[i] = nspots[i];
    }
    void rotate_west() {
        int nspots[6];
        nspots[SOUTH] = spots[SOUTH];
        nspots[TOP] = spots[EAST];
        nspots[WEST] = spots[TOP];
        nspots[BOTTOM] = spots[WEST];
        nspots[EAST] = spots[BOTTOM];
        nspots[NORTH] = spots[NORTH];
        for (int i = 0; i < 6; i++) spots[i] = nspots[i];
    }
    void rotate_east() {
        int nspots[6];
        nspots[SOUTH] = spots[SOUTH];
        nspots[EAST] = spots[TOP];
        nspots[TOP] = spots[WEST];
        nspots[WEST] = spots[BOTTOM];
        nspots[BOTTOM] = spots[EAST];
        nspots[NORTH] = spots[NORTH];
        for (int i = 0; i < 6; i++) spots[i] = nspots[i];
    }
};

int main() {
    int n;
    while (cin >> n, n) {
        string dir;
        Dice d;
        for (int i = 0; i < n; i++) {
            cin >> dir;
            d.rotate(dir);
        }
        cout << d.top() << endl;
    }
    return 0;
}

Measured memory_bytes: 1220
m = list(map(int,input().split()))
b = list(map(int,input().split()))
n=0
for k in range(m[0]):
  acc = 0
  for z,k in zip(list(map(int,input().split())), b):
    acc += z*k
  if acc + m[2] > 0:
    n += 1
print(n)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
typedef		long long       ll;
typedef         long double      dl;
#define		pb              push_back
#define		PB              pop_back
#define		nn              "\n"
#define     O_O             ios_base::sync_with_stdio(false); cin.tie(NULL)
#define		all(p)          p.begin(),p.end()
#define		zz(v)           (ll)v.size()
#define		ss              ' '
#define         arrsize(a)      (sizeof(a)/sizeof(a[0]))
//#define       arrsize(a)      (sizeof(a)/sizeof(*a))
#define 	S(a)            scanf("%lld",&a)
#define 	SS(a,b)         scanf("%lld %lld",&a,&b)
#define 	SSS(a,b,c)      scanf("%lld %lld %lld",&a,&b,&c)
#define		gcd(a,b)        __gcd(a,b)
#define		lcm(a,b)        (a*b)/gcd(a,b)
#define		pi              acos(-1.0)
typedef        pair <int, int>   pii;
typedef       pair <ll, ll>      pll;
typedef      vector< pair <ll, ll> >      vpll;
typedef		vector<ll>      vll;
typedef		map<string,ll>      msl;
typedef		map<ll,ll>      mll;
#define MAX 1000005


int main()
{
 //O_O ;
   string s ;ll c=0;
   cin>>s;
   ll l=s.length();
   for(ll i=0;i<l;i++)
    if(s[i]=='7') c++;

 if(c)
    cout<<"Yes"<<nn;
 else
    cout<<"No"<<nn;

    return 0;
}


Measured memory_bytes: 3620
import sys

sys.setrecursionlimit(10 ** 8)
ini = lambda: int(sys.stdin.readline())
inl = lambda: [int(x) for x in sys.stdin.readline().split()]
ins = lambda: sys.stdin.readline().rstrip()
debug = lambda *a, **kw: print("\033[33m", *a, "\033[0m", **dict(file=sys.stderr, **kw))


def solve():
    n = ini()
    s = ins()
    t = ins()
    for i in range(n + 1):
        if t.startswith(s[i:]):
            return len(s[:i] + t)

    return len(s + t)


print(solve())


Measured memory_bytes: 9148
#include <stdio.h>
#include <stdbool.h>

#define rep(i, a, n) for (i = (a); i < (n); i++)
#define MAX_H 50
#define MAX_W 50
#define QUEUE_SIZE ( MAX_H * MAX_W )
#define QUEUE_NEXT(n) (((n) + 1) % QUEUE_SIZE)

char map[MAX_H][MAX_W];
bool seen[MAX_H][MAX_W];
int costs[MAX_H][MAX_W];
int h, w;
int si = 0, sj = 0;
int gi, gj;

struct node {
	int i;
	int j;
	int cost;
};

struct node nodes[MAX_H * MAX_W];
int head = -1, tail = -1;

void push(int i, int j, int cost)
{
	tail = QUEUE_NEXT(tail);
	nodes[tail].i = i;
	nodes[tail].j = j;
	nodes[tail].cost = cost;
}

struct node pop()
{
	head = QUEUE_NEXT(head);
	return nodes[head];
}

bool isEmpty()
{
	return head == tail;
}

void bfs()
{
	while(1) {
		if (isEmpty()) break;
		struct node current_node = pop();
		int i = current_node.i;
		int j = current_node.j;
		int cost = current_node.cost;
		if (i < 0 || j < 0 || h  <= i || w <= j)  continue;
		if (map[i][j] != '.') continue;
		if (seen[i][j]) continue;
		seen[i][j] = true;
		costs[i][j] = cost;
		push(i, j + 1, cost + 1);
		push(i, j - 1, cost + 1);
		push(i + 1, j, cost + 1);
		push(i - 1, j, cost + 1);
	}
}

int main()
{
	scanf("%d %d", &h, &w);
	gi = h - 1; gj = w - 1;
	int i,j, white_counter = 0;
	rep(i, 0, h) {
		rep(j, 0, w) {
			scanf(" %c", &map[i][j]);
			seen[i][j] = false;
			if (map[i][j] == '.') white_counter++;
		}
	}
	push(si, sj, 0);
	bfs();
	int result = costs[gi][gj];
	if (result == 0) printf("-1\n");
	else printf("%d\n", white_counter - result - 1);
	return 0;
}

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

int main()
{
    int k;
    cin>>k;
    int arr[100000];
    int i;
    for(i=0;i<k;i++)
    {
        cin>>arr[i];
    }
    long long st=1, en=1e18;
    long long mi,ma;
    while(st<en)
    {
        long long mid= (st+en)/2LL;
        long long tm=mid;
        for(i=0;i<k;i++)
        {
            tm= tm-tm%arr[i];
        }
        if(tm<2)
        {
            st=mid+1;
        }
        else if(tm>=2)en=mid;
    }
    mi=st;
    for(i=0;i<k;i++)
        {
            st= st-st%arr[i];
        }
    int flg=0;
    
    if(st!=2) flg=1;
    
    if(flg==1){cout<<"-1\n";return 0;}
    
    st=1,en=1e18;
    while(st<en)
    {
        long long mid= st+(en-st+1)/2LL;
        //cout<<st<< " "<<en<<" "<<mid<<endl;
        long long tm=mid;
        
        for(i=0;i<k;i++)
        {  
            tm= tm-tm%arr[i];
        }
        if(tm<=2)
        {   
            st=mid;
        }
        else if(tm>2)en=mid-1;
        
        
    }
    ma=st;
    for(i=0;i<k;i++)
        {
            st= st-st%arr[i];
        }
    flg=0;
    
    if(st!=2) flg=1;
    
    if(flg==1){cout<<"-1\n";return 0;}

    cout<<mi<<" "<<ma<<endl;
}


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

using namespace __gnu_pbds;
#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>

using namespace std;

#define int long long
#define endl '\n'
#define maxn 1010  
const int MOD = 1000000007;
using int32 = __uint32_t;

int n, m;
vector<pair<int,int>> v;
int dp[maxn][5010];

int solve(int pos, int mask){
    if(__builtin_popcount(mask) == n){
        return 0;
    }
    else if(pos == m){
        return 1e10;
    }

    int &ans = dp[pos][mask];
    if(ans != -1)return ans;
    ans = 1e10;
    ans = min(ans, solve(pos + 1, mask));
    ans = min(ans, v[pos].first + solve(pos + 1, mask | v[pos].second));
    return ans;
}

void solve() {
    memset(dp, -1,sizeof dp);
    cin >> n >> m;

    v = vector<pair<int,int>>(m);
    for(int i = 0; i < m; i++){
        cin >> v[i].first;
        int key;
        cin >> key;
        
        int push = 0;
        for(int i = 0; i < key ;i++){
            int tp;
            cin >> tp;

            tp--;
            for(int i = 0; i <= 14; i++){
                if(tp == i){
                    push = push | (1 << i);
                    break;
                }
            }
        }
        v[i].second = push;
    }
    int ans = solve(0 , 0);
    if(ans >= 1e10)ans = -1;
    cout << ans << endl;
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int t = 1;
//    cin >> t;

    while (t--)
        solve();
    return 0;
}


Measured memory_bytes: 39808