akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<map>
#include<string.h>
#include<complex>
#include<math.h>
#include<queue>
#include <functional>
#include<time.h>
#include <stack>
using namespace std;
#define rep(i,a,n) for(int i=(a);i<(n);i++)
#define ll long long
#define llint long long int
#define sort(s) sort(s.begin(),s.end())
#define reverse(v)  reverse(v.begin(), v.end());
#define Yes(ans) if(ans)cout<<"Yes"<<endl; else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl; else cout<<"NO"<<endl;
#define hei(a) vector<a>
#define whei(a) vector<vector<int>>
constexpr auto mod = 1000000007;


//2のn乗を求めるよ！！！
int ni(int n) {
	if (n == 0)return 1;
	int x = ni(n / 2);
	x *= x;
	if (n % 2 == 1)x *= 2;
	return x;
}

//フィボナッチ数列のx番目を求めるよ！
int f(int x,vector<int> s) {
	if (x == 0)return 0;
	if (x == 1)return 1;
	if (s[x] != 0)return s[x];
	s[x] = f(x - 1,s) + f(x - 2,s);
	return s[x];
}

//aとｂの最大公約数を求めるよ！
llint gcd(llint a, llint b) {
	if (a < b)swap(a, b);
	if (b == 0)return a;
	return gcd(b, a % b);
}



// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
	long long res = 1;
	while (n > 0) {
		if (n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}

// mod. m での a の逆元 a^{-1} を計算するよ！
long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}


//aCbをmod.mで割った余りを求める
ll int c(ll int a, ll int b,ll int m) {
	ll int ans = 1;
	for (ll int i = 0; i < b; i++) {
		ans *= a - i;
		ans %= m;
	}
	for (ll int i = 1; i <= b; i++) {
		ans *= modinv(i, m);
		ans %= m;
	}
	return ans;
}

//m進数のn桁を全列挙やで
void dfs(int m, int n) {

	stack<string> st;
	st.push("");
	while (!st.empty()) {
		string now = st.top();
		st.pop();
		if (now.size() == n) {
			cout << now << endl;
		}
		else {
			for (int i = m-1; i >= 0; i--) {
				string next = now + to_string(i);
				st.push(next);
			}
		}
	}
}

int main(){
ll n, q, k;
cin >> n >> k >> q;
hei(ll) a(n, 0);
rep(i, 0, q) {
	int s;
	cin >> s;
	a[s - 1]++;
}
rep(i, 0, n) {
	Yes(q - a[i] < k)
}	
	return 0;
}




  


Measured memory_bytes: 1536
#include <bits/stdc++.h>
 
using namespace std;
 
int main() {
    constexpr int A_MAX = 1000000;
    vector<int> min_factor(A_MAX + 1);
    vector<int> q(A_MAX + 1, 1);
    vector<int> primes;
    for (int i = 2; i <= A_MAX; ++i) {
        if (!min_factor[i]) {
            min_factor[i] = i;
            primes.push_back(i);
        }
        for (int p : primes) {
            int n = i * p;
            if (n > A_MAX) {
                break;
            }
            min_factor[n] = p;
            if (p == min_factor[i]) {
                q[n] = q[i];
                break;
            } else {
                q[n] = i;
            }
        }
    }
 
    int N = 0;
    char c = getchar_unlocked();
    do {
        N = 10 * N + c - '0';
    } while ((c = getchar_unlocked()) >= '0');
    vector<int> a(A_MAX + 1);
    for (int i = 0; i < N; ++i) {
        int A = 0;
        c = getchar_unlocked();
        do {
            A = 10 * A + c - '0';
    	} while ((c = getchar_unlocked()) >= '0');
        ++a[A];
    }
 
    bool is_pairwise_coprime = true;
    for (int n = A_MAX; n > 1; --n) {
        if (a[n] > 1) {
            if (a[n] == N) {
                printf("not coprime\n");
                return 0;
            }
            is_pairwise_coprime = false;
        }
        a[min_factor[n]] += a[n];
        a[q[n]] += a[n];
    }
    if (is_pairwise_coprime) {
        printf("pairwise coprime\n");
    } else {
        printf("setwise coprime\n");
    }
 
    return 0;
}

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

int T[100];
int H[100];
int main(){
	int n, m;
	int Half,Tsum, Hsum;
	int Tn, Hn,Tans,Hans;
	while (1){
		cin >> n >> m;
		if (n == 0 && m == 0) break;
		Tsum = Hsum = 0;

		for (int i = 0; i < n; i++){
			cin >> T[i];
			Tsum += T[i];
		}
		for (int i = 0; i < m; i++){
			cin >> H[i];
			Hsum += H[i];
		}
		int flg = 0;
		if ((Hsum + Tsum) % 2 == 0){
			Half = (Hsum + Tsum) / 2;
			for (int i = 0; i < n; i++){
				Tn = Half - (Tsum - T[i]);
				for (int j = 0; j < m; j++){
					if (Tn == H[j]){
						Hn = Half - (Hsum - H[j]);
						if (Hn == T[i]){
							Tans = T[i];
							Hans = H[j];
							flg = 1;
							break;
						}
					}
				}
				if (flg == 1) break;
			}
		}
		if (flg == 1){
			cout << Tans << " " << Hans << endl;
		}
		else {
			cout << -1 << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb(x) push_back(x)
#define f(i,st,n) for(i=st;i<n;i++)
#define qu queue
#define ps(x) push(x)
#define vec vector
#define ft() front()
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define mst(a,b) memset(a,b,sizeof(a))
#define mod 1000000007
#define sfl(x) scanf("%lld",&x)
#define pfl(x) printf("%lld\n",x)
#define pf(x) printf("%lld",x)
#define mpr make_pair
#define fs first
#define se second
#define inf LLONG_MAX
#define nnf LLONG_MIN





ll gcd(ll a, ll b) {
  if (a == 0) {
    return b;
  }
  return gcd(b % a, a);
}
ll power(ll x, ll y) {
  ll res = 1;
  while (y > 0) {
    if (y % 2 == 1) {
      res = ((res) * (x)) ;
    }
    x = ((x) * (x)) ;
    y = y / 2;
  }
  return res;
}



int main() {

  fast

/*#ifndef ONLINE_JUDGE

  freopen("input.txt", "r", stdin);

  freopen("output.txt", "w", stdout);
#endif*/

  ll l=0,r=100,a,b,n,ans,i,j;

  sfl(n);


  vec<ll>v;

  f(i,-1000,1001){
      v.pb(i);
  }
    ll x=v.size();
  for(i=0;i<x;i++){

      for(j=0;j<x;j++){

            if(power(v[i],5)-power(v[j],5)==n){
                cout<<v[i]<<" "<<v[j];
                return 0;
            }
      }
  }


  return 0;





}

Measured memory_bytes: 3740
// スタックサイズ: 100MB

#include <iostream>
#include <fstream>
#include <vector>
#include <map>
#include <unordered_map>
#include <string>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <functional>
#include <numeric>
#include <iomanip>
#include <queue>
#include <list>
#include <set>
using namespace std;

typedef int64_t ll;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
const ll INF = 1000000000000000000;
#define fori(i, a, b) for (ll i = (a); i < (b); ++i)
#define ford(i, a, b) for (ll i = (b - 1); (a) <= i; --i)
#define rep(i, n) fori(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define fst first
#define snd second
ll pw(ll x, ll y) { ll r = 1;  rep(i, y) { r *= x; }; return r; }



int main() {
	
	ll H, W, D;
	cin >> H >> W >> D;
	vector<vll> A(H, vll(W));
	vll coor_x(H * W), coor_y(H * W);
	rep(i, H) rep(j, W) {
		cin >> A[i][j];
		--A[i][j];
		coor_x[A[i][j]] = i; coor_y[A[i][j]] = j;
	}

	vll arr(H * W, 0);
	rep(i, D) {
		ll tmp = i;
		while (tmp < H * W) {
			if (tmp < D);
			else {
				arr[tmp] = arr[tmp - D];
				arr[tmp] += abs(coor_x[tmp] - coor_x[tmp - D]) + abs(coor_y[tmp] - coor_y[tmp - D]);
			}

			tmp = tmp + D;
		}
	}

	ll Q;
	cin >> Q;
	rep(loop, Q) {
		ll L, R;
		cin >> L >> R;
		--L, --R;

		cout << arr[R] - arr[L] << endl;
	}
}

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

/*第二引数で第一引数を割ったときの切り上げの計算*/
long long int maxtime(long long int x, long long int y) {
	return(x + y - 1) / y;

}
/*最大公約数*/
long long int lcm(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;

	if (number2 > number1) {
		m = number2;
		n = number1;
	}
	long long int s = -1;
	while (s != 0) {
		s = m % n;
		m = n;
		n = s;
	}
	return m;
}
/*最大公倍数*/
long long int gcd(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;
	return m / lcm(m, n) * n;
}
int main() {
	string S;
	cin >> S;
	int ans = 10000;
	for (int i = 0; i < S.size()-2;i++) {
		int k = 0;
		k = 100 * (S[i]-'0') + 10 * (S[i+1] - '0') + (S[i+2] - '0');
		ans = min(ans, abs(k - 753));
	}
	cout << ans;
}

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

using namespace std;

class Slice {
 public:
  Slice(const char* p, size_t len) : p_(p), len_(len) {}

  Slice substr(size_t pos, size_t len) const {
    // for simplicity, intentionally omit check the values of pos and
    // len
    return Slice(p_ + pos, len);
  }

  const char* data() const { return p_; }
  size_t length() const { return len_; }

  std::string to_string() const {
    return std::string(p_, len_);
  }

 private:
  const char* p_;
  size_t len_;
};

inline std::string merge(const Slice& lhs, const Slice& rhs) {
  std::string r = rhs.to_string();
  r.append(lhs.data(), lhs.length());
  return r;
}

int main() {
  for (;;) {
    std::string s;
    cin >> s;
    if (s[0] == '-')
      break;

    int m;
    cin >> m;
    int h;

    const size_t len = s.length();
    for (int i = 0; i < m; ++i) {
      cin >> h;
      const Slice slice(s.data(), len);
      const Slice lhs = slice.substr(0, h);
      const Slice rhs = slice.substr(h, len-h);
      s = merge(lhs, rhs);
    }
    cout << s << endl;
  }
  return 0;
}

Measured memory_bytes: 3084
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
 
int main() {
    int n,m;
    cin >> n>>m;
    vector<string> a(n);
    vector<string> b(n);
    bool f=true;
    bool f_tf=true;
    for(int i=0;i<n;i++){
        cin >>a[i];
    }
    for(int i=0;i<m;i++){
        cin >>b[i];
    }
    for(int i=0;i<n-m;i++){
        for(int j=0;j<n-m;j++){
            for(int k=0;k<m;k++){
                f_tf=true;
                if(a[i+k].substr(j,m)!=b[k]){
                    f=false;
                    f_tf=false;
                    break;
                }
            }
            if(f_tf==true) break;
        }
        if(f_tf==true)break;
    }
    if(f_tf==true) cout << "Yes"<<endl;
    else cout << "No" <<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
long long ans=1010101010101010ll,now;
int mi[2020];
int a[2020];
int main()
{
	int n,x;
	scanf("%d%d",&n,&x);
	for(int i=0;i<n;i++)
	{
		scanf("%d",&a[i]);
		mi[i]=a[i];
	}
	for(int i=0;i<n;i++)
	{
		now=(long long)i*x;
		for(int j=0;j<n;j++)
		{
			mi[j]=min(mi[j],a[(j-i+n)%n]);
			now+=mi[j];
		}
		ans=min(now,ans);
	}
	printf("%lld",ans);
	return 0;
}

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

typedef pair<int, int> P;
const int N = (int)2e4 + 50, INF = (int)1e9;

struct edge{
    int to, cap, rev;
    edge(int _to, int _cap, int _rev){
        to = _to, cap = _cap, rev = _rev;
    }
};


struct Ford {
    vector<edge> G[N];
    bool used[N];

    void add_edge(int from, int to, int cap){
        G[from].push_back(edge(to, cap, G[to].size()));
        G[to].push_back(edge(from, 0, G[from].size() - 1));
    }

    void add_double_edge(int from, int to, int cap){
        G[from].push_back(edge(to, cap, G[to].size()));
        G[to].push_back(edge(from, cap, G[from].size() - 1));
    }


    int dfs(int v, int t, int f){
        if(v == t) return f;
        used[v] = true;

        for(int i = 0; i < G[v].size(); i++){
            edge &e = G[v][i];
            if(!used[e.to] && e.cap > 0){
                int d = dfs(e.to, t, min(e.cap, f));
                if(d > 0){
                    e.cap -= d;
                    G[e.to][e.rev].cap += d;
                    return d;
                }
            }
        }
        return 0;
    }

    int max_flow(int s, int t){
        int f = 0;
        for(;;){
            fill(used, used + N, false);
            int d = dfs(s, t, INF);
            if(d == 0) return f;
            f += d;
        }
    }
}flow;

int n,m;
string str[105];

P find(char c) {
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < m; j++) if(str[i][j] == c) return {i, j};
    }
    return {-1, -1};
}

int main() {
    cin >> n >> m;
    for(int i = 0; i < n; i++) cin >> str[i];
    int s = n + m, t = s + 1;

    P ps = find('S');
    flow.add_double_edge(s, ps.first, INF);
    flow.add_double_edge(s, n + ps.second, INF);
    P pt = find('T');
    flow.add_double_edge(pt.first, t, INF);
    flow.add_double_edge(n + pt.second, t, INF);
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < m; j++) {
            if(str[i][j] != 'o') continue;
            flow.add_double_edge(i, n + j, 1);
//            flow.add_double_edge(i, m + j, 1);
        }
    }
    int res = flow.max_flow(s, t);
    cout << (res >= INF ? -1 : res) << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <cmath>
#include <iomanip>
#include <functional>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define REP(i, n) for (int i = 1; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) (int)(x).size()
using namespace std;
using ll = long long;
constexpr int inf = 1000000000;
constexpr ll INF = 5000000000000000000;

int main() {
    int N, K;
    cin >> N >> K;
    vector<int> x(N), y(N);
    rep(i, N) cin >> x[i] >> y[i];
    
    vector<pair<int, int>> S1(N);
    rep(i, N) S1[i] = pair<int, int>{x[i], i};
    sort(ALL(S1));
    vector<int> X(N, 0);
    X[S1[0].second] = 0;
    REP(i, N) X[S1[i].second] = X[S1[i - 1].second] + 1;
    vector<pair<int, int>> S2(N);
    rep(i, N) S2[i] = pair<int, int>{y[i], i};
    sort(ALL(S2));
    vector<int> Y(N, 0);
    Y[S2[0].second] = 0;
    REP(i, N) Y[S2[i].second] = Y[S2[i - 1].second] + 1;
    
    vector<vector<int>> S(N, vector<int>(N, 0));
    rep(i, N) S[X[i]][Y[i]] = 1;
    vector<vector<int>> sum(N + 1, vector<int>(N + 1, 0));
    rep(i, N) rep(j, N) sum[i + 1][j + 1] = S[i][j] + sum[i + 1][j] + sum[i][j + 1] - sum[i][j];
    ll ans = INF;
    rep(i, N + 1) rep(j, N + 1) rep(k, N + 1) rep(l, N + 1) {
        if (i < j && k < l) {
            if (sum[j][l] - sum[i][l] - sum[j][k] + sum[i][k] >= K) {
                ans = min(ans, ((ll)S1[j - 1].first - (ll)S1[i].first) * ((ll)S2[l - 1].first - (ll)S2[k].first));
            }
        }
    }
    cout << ans << "\n";
    return 0;
}


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

using namespace std;

const int N = 1e6 + 100;

int divisor[N];

int main()
{
	int n;	scanf("%d", &n);

	for (int i = 1; i < n; i++)
		for (int j = i; j < n; j += i)
			divisor[j]++;

	int ans = 0;
	for (int i = 0; i < n; i++)
		ans += divisor[i];
		
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 7640
import java.util.*;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String a = sc.next();
        String b = sc.next();
        char[] s = a.toCharArray();
        char[] t = b.toCharArray();
        char[] s2 =a.toCharArray();
        int cnt = 0;
        int cnt2 =0;
        //System.out.println(a.length());

        while(cnt<a.length()){
            for(int i =0;i<a.length();i++){
                if(i==a.length()-1){
                    s2[0]=s[i];
                }else{
                    s2[i+1]=s[i];
                }

            }
            //System.out.println(s2);
            if(Arrays.equals(t,s2)){
                cnt2++;
            }
            s=s2.clone();
            cnt++;
        }

        if(cnt2>0){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
    }
}


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


int main(){
	string s,s2,s3;
	cin >> s;
	if(s.size()<5){
		cout << "NO" << endl;
		return 0;
	}
	if(s[0]!='A') s = "A" +s;
	if(s[4]!='A'){
		s2=s.substr(0,4);
		s3="A" + s.substr(4);
		s=s2+s3;
	}
	if(s[6]!='A'){
		s2=s.substr(0,6);
		s3="A"+s.substr(6);
		s=s2+s3;
	}
	if(s[8]!='A'){
		s+="A";
	}
	
	if(s!="AKIHABARA") cout << "NO" << endl;
	else cout << "YES" << endl;
	return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <numeric>
#include <functional>
#include <cctype>
#include <list>
#include <limits>
#include <cassert>
//#include <boost/multiprecision/cpp_int.hpp>

const double EPS = (1e-10);


using namespace std;
using Int = long long;
//using namespace boost::multiprecision;

const Int MOD = 1000000007;

long long mod_pow(long long x, long long n) {
    long long res = 1;
    for(int i = 0;i < 60; i++){
        if(n >> i & 1) res = res * x % MOD;
        x = x * x % MOD;
    }
    return res;
}

template<typename T>
T gcd(T a, T b) {
    return b != 0 ? gcd(b, a % b) : a;
}

template<typename T>
T lcm(T a, T b) {
    return a * b / gcd(a, b);
}

void fast_input() {
    cin.tie(0);
    ios::sync_with_stdio(false);
}

int main(void) {
    int N; cin >> N;
    int K; cin >> K;

    if ((N-1)*(N-2)/2 < K) {
        cout << "-1" << endl;
        return 0;
    }
    K -= (N-1)*(N-2)/2;
    K *= -1;
    vector<pair<int, int>> outputs;
    for (int i = 1; i <= N-1 && K > 0; i++) {
        for (int j = i+1; j <= N-1 && K > 0; j++) {
            outputs.push_back({i, j});
            K--;
        }
    }
    cout << outputs.size() + N-1 << endl;
    for (int i = 1; i <= N-1; i++) {
        cout << i << " " << N << endl;
    }
    for (int i = 0; i < outputs.size(); i++) {
        cout << outputs[i].first << " " << outputs[i].second << endl;
    }
}

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

int main(int argc, char const *argv[])
{
	char ch[7];

	gets(ch);

	if((ch[2]==ch[3]) && (ch[4]==ch[5])){
		printf("Yes\n");
	}
	else{
		printf("No\n");
	}


	return 0;
}


Measured memory_bytes: 128
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        a: usize,
        b: usize,
    }
    println!("{}",
        match (a,b) {
            (1,1) => "Draw",
            (1,_) => "Alice",
            (_,1) => "Bob",
            (a,b) => if a > b { "Alice" }
                     else if a < b { "Bob" }
                     else { "Draw" },
        });
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
    using namespace std;
    const int N = 3010;
    const int MOD = 1000000007;
    int f[N][N][2];
    int n, m, ans;
    void ADD(int &a, int b) {a = a + b; if (a >= MOD) a -= MOD;}
    int main()
    {
        cin >> n >> m;
        for (int i = 0; i <= n; ++ i) f[0][i][0] = 1;
        for (int i = 0; i < m; ++ i)
            for (int j = 0; j <= n; ++ j)
                for (int k = 0; k < 2; ++ k)
                {
                    if (j > 0)
                    {
                        ADD(f[i + 1][j - 1][k || (j == 1)], f[i][j][k]);
                        ADD(f[i + 1][j][k || (j == 1)], f[i][j][k]);
                    }
                    if (j < n)
                    {
                        ADD(f[i + 1][j + 1][k || (j == 0)], f[i][j][k]);
                        ADD(f[i + 1][j][k || (j == 0)], f[i][j][k]);
                    }
                }
        for (int i = 0; i <= n; ++ i) ADD(ans, f[m][i][1]);
        cout << ans;
    }

Measured memory_bytes: 70784
//BISMILLAHIR RAHMANIR RAHEEM
//ALLAH IS WATCHING ME
#include<bits/stdc++.h>
#include<iostream>
#include<cstring>
#include<cmath>
#include<iterator>
#include<cstdlib>
#define IOS   ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define test IOS long long t;cin >> t;while(t--)
#define ses   "\n"
#define whp   " "
#define mxi 200003
#define mp make_pair
#define PII pair<long long, long long>
#define pf printf
#define sf scanf
#define ff first
#define ss second
#define ALL(x) x.begin(),x.end()
#define pb push_back
#define rep0(i,a,b) for(int i=a; i<b; i++)
#define rep1(i,a,b) for(int i=a; i<=b; i++)
#define rep0in(i,a,b) for(int i=a-1; i>=b; i--)
#define rep1in(i,a,b) for(int i=a; i>b; i--)
#define repv(i,a) for(auto i=a.begin(); i!=a.end();++i)
#define INF 0x3f3f3f3f
#define CLR(a,b) memset(a,b,sizeof(a));
#define PI acos(-1)
#define what_is(x) cout<<x<<ses;
//set <int, greater <int> > ::iterator it;
//vector<pair<int,int> >a;
//memset(arr,0,sizeof(hg));
//priority_queue <int, vector<int>, greater<int> > pq;
///  string single character erase-
///             s.erase(s.begin()+x); where s is st ring name
///               ans x is index;
///    transform(sl.begin(), sl.end(), sl.begin(), ::tolower);
///    transform(su.begin(), su.end(), su.begin(), ::toupper);
typedef long long v99;
typedef unsigned long long ull;
using namespace std;
v99 fx[4]= {1,-1,0,0};
v99 fy[4]= {0,0,1,-1};
v99 ox8[] = {0, 0, 1, 1, 1, -1, -1, -1};
v99 oy8[] = {1,-1, 1, -1, 0, 0, -1, 1};
bool sort2val(const pair<int,int> &a,const pair<int,int> &b)
{
    if(a.second==b.second)return a.first<b.first;
    return a.second<b.second;
}
template< class T > T gcd(T a, T b) { return (b != 0 ? gcd<T>(b, a%b) : a); }
template< class T > T lcm(T a, T b) { return (a / gcd<T>(a, b) * b); }
/**bool prime[10000020];vector<v99>prm;
void SieveOfEratosthenes(v99 n)
{
	memset(prime, true, sizeof(prime));
	for(v99 i=4;i<=n;i+=2)prime[i]=false;
	for (v99 p=3; p*p<=n; p+=2)
	{
		if (prime[p] == true)
		{
			/// Update all multiples of p
			for (v99 i=p*p; i<=n; i += 2*p)
				prime[i] = false;
		}
	}
	rep1(i,2,n)if(prime[i])prm.push_back(i);

}*/
v99 pw(v99 a, v99 b)
{
	v99 ans = 1;
	for(v99 i = 1; i <= b; ++i)
		ans = (ans * a);
	return ans;
}

template <class T> inline T bigmod(T n,T p,T m)
{
    if(p==0)return 1;
    else if(p%2==0)
    {
        v99 val=bigmod(n,p/2,m);
        return (T)((val*val)%m);
    }
    else return (T)(((v99)n*(v99)bigmod(n,p-1,m))%m);
}
///-------------------------------------------------------------------------------------------------------



void solve()
{
    /// code is here->
    v99 n,taka=1000;cin>>n;v99 a[n+1];
    rep0(i,0,n)cin>>a[i];
    rep0(i,0,n-1)
    {
        if(a[i]<a[i+1])
        {
            v99 k=taka/a[i];
            taka+=(a[i+1]-a[i])*k;
        }
    }
    cout<<taka<<ses;
}






int main()
{

    //freopen("data.out","w",stdout);
    //while(1)
    //test
    solve();

    return 0;
}



      ///  Alhamdulillah...



Measured memory_bytes: 3652
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>
#include <random>
#include <cstdio>
#include <cmath>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int) n; i++)

int main() {
    int x,a,b; cin >> x >> a >> b;
    cout << (x-a)%b << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
using namespace std;
int main(){
  int n;
  while(cin >> n,n){
    vector< pair<int, int> > V;
    int p, t;
    for(int i = 0; i < n; ++i){
      cin >> p >> t;
      V.push_back(make_pair(p, t));
    }
    int INF = 1000000000;
    vector< vector<int> > dp(n,vector<int>(4,INF));

    if(V[0].first > V[0].second){
      cout << "NG 1" << endl;
      continue;
    }
    dp[0][1] = V[0].first;
    
    bool f = true;
    for(int i = 1; i < n; ++i){
      bool g = false;
      for(int j = 1; j <= 3; ++j){
        if(dp[i-1][j] == INF) continue;
        if(j+1 <= 3 && abs(V[i].first-V[i-1].first)*(j+1) <= V[i].second - V[i-1].second){
          g = true;
          dp[i][j+1] = min(dp[i][j+1], dp[i-1][j]+abs(V[i].first-V[i-1].first));
        }

        if(V[i].first+V[i-1].first*(j+1) <= V[i].second - V[i-1].second){
          g = true;
          dp[i][1] = min(dp[i][1], dp[i-1][j]+V[i].first+V[i-1].first);
        }

      }
      if(!g){
        cout << "NG " << i+1 << endl;
        f = false;
        break;
      }
    }
    if(f){
      int ans = INF;
      for(int i = 0; i < 4; ++i){
        ans = min(ans, dp[n-1][i]+V[n-1].first);
      }
      cout << "OK " << ans << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 3136
#include<bits/stdc++.h>
using namespace std;
int isprime(long long int x)
{
  long long int i;
  for(i=2;i<sqrt(x);i++)
  {
    if(x%i==0)
      return 1;
  }
  return 0;
}
int main()
{
  long long int x;
  cin>>x;
  if(x==2)
  {
    cout<<2;
  }
  
  else
  {	while(isprime(x))
  {
    if(isprime(x)==0)
    {	
      break;
    }
    else
      x++;
  }
   cout<<x;
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int N,K;
  cin>>N>>K;
  string S;
  cin>>S;
  
 if(S.at(K-1)=='A'){
   S.at(K-1)='a';
 }
  if(S.at(K-1)=='B'){
    S.at(K-1)='b';
  }
  if(S.at(K-1)=='C'){
    S.at(K-1)='c';
  }
cout<<S<<endl;
}


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

using namespace std;

using ll = long long;

template<typename T> using V = std::vector<T>;
using Vi = V<int>;
using VVi = V<V<int>>;
using Vl = V<ll>;
using VVl = V<V<ll>>;
using Vs = V<string>;

template<typename T1, typename T2> using P = std::pair<T1, T2>;
using Pii = P<int, int>;
using Pll = P<ll, ll>;
using Pdd = P<double, double>;

template<typename T1, typename T2> using M = std::map<T1, T2>;
using Mii = M<int, int>;
using Msi = M<string, int>;

#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define REP2(i,s,e) for(int i=(int)(s);i<(int)(e);++i)
#define RREP(i,s,e) for(int i=(int)(s);i>=(int)(e);--i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin(),ie=(c).end();i!=ie;++i)
#define ALL(c) (c).begin(), (c).end()

const double PI = acos(-1);
const ll MOD = 1e9+7;

int a, b;

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

    int minb = 10*b, maxb = 10*(b+1);
    int mina = (100*a + 7)/8, maxa = (100*(a+1) + 7)/8;

    REP2(i, mina, maxa) {
        if (i >= minb && i < maxb) {
            cout << i << '\n';
            return 0;
        }
    }
    cout << -1 << '\n';

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cassert>
#include <cstdint>
#include <cctype>
#include <numeric>
#include <bitset>
#include <functional>

using namespace std;

using ll =  long long;
using Pll = pair<ll, ll>;
using Pii = pair<int, int>;

constexpr int INF = 1 << 30;
constexpr ll LINF = 1LL << 60;
constexpr ll MOD = 1000000007;
constexpr long double EPS = 1e-10;
constexpr int dyx[4][2] = {
    { 0, 1}, {-1, 0}, {0,-1}, {1, 0}
};

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int n;
    cin >> n;
    vector<ll> a(n+2, 0);
    for(int i=1;i<=n;++i) {
        cin >> a[i];
    }
    vector<ll> b(a);

    // + から
    ll ans1 = 0LL;
    // - から
    ll ans2 = 0LL;
    for(int i=1;i<=n;++i) {
        if(i % 2) {
            if(b[i] >= 0) {
                ans2 += b[i] + 1;
                b[i] = -1;
            }
            if(a[i] <= 0) {
                ans1 += -a[i] + 1;
                a[i] = 1;
            }
        } else {
            if(b[i] <= 0) {
                ans2 += -b[i] + 1;
                b[i] = 1;
            }
            if(a[i] >= 0) {
                ans1 += a[i] + 1;
                a[i] = -1;
            }
        }
        a[i+1] += a[i];
        b[i+1] += b[i];
    }

    cout << min(ans1, ans2) << endl;
}


Measured memory_bytes: 4776
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second
 
const int mx=200010;
const ll mod=1e9+7;

int main(){  
  string s;
  cin >> s;
  int n=s.size();
  int ans=-1,cnt=0;
  rep(i,n){
    if(s[i]=='A'||s[i]=='C'||s[i]=='G'||s[i]=='T'){
      cnt++;
    } else {
      ans = max(ans,cnt);
      cnt = 0;
    }
  }
  ans = max(ans,cnt);

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

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main ()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); 
    
	string a,b;
	cin >> a >> b;
	
	int cnt = 0;
	for(int i = 0 ; i < (int)a.size(); i++)
		if(a[i] != b[i])
			cnt++;
			
	cout << cnt << "\n";
}


Measured memory_bytes: 3440
#include <algorithm>
#include <complex>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
using namespace std;
typedef long long int lli;
typedef pair<lli, lli> P;
lli MOD = 1000000007;
int main()
{
    int h, w;
    cin >> w >> h;
    int ans = 0;
    char c;
    rep(i, w * h)
    {
        cin >> c;
        if (c == '#')
            ans++;
    }
    cout << (ans == w + h - 1 ? "Possible" : "Impossible") << endl;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Collections;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;
using static System.Math;
using System.Numerics;
static class Program{
	const int mod=(int)1e9+7;
	static void Main(){
		Sc sc=new Sc();
		var n=sc.I;
		var a=sc.Ia;
		for(int i = 0;i<n;i++) {
			if(a[i]%2==0){
				if(a[i]%3!=0&&a[i]%5!=0){
					Console.WriteLine("DENIED");
					return;
				}
			}
		}
		Console.WriteLine("APPROVED",0);
	}
}
public class Sc{
	public int I{get{return int.Parse(Console.ReadLine());}}
	public long L{get{return long.Parse(Console.ReadLine());}}
	public double D{get{return double.Parse(Console.ReadLine());}}
	public string S{get{return Console.ReadLine();}}
	public int[] Ia{get{return Array.ConvertAll(Console.ReadLine().Split(),int.Parse);}}
	public long[] La{get{return Array.ConvertAll(Console.ReadLine().Split(),long.Parse);}}
	public double[] Da{get{return Array.ConvertAll(Console.ReadLine().Split(),double.Parse);}}
	public string[] Sa{get{return Console.ReadLine().Split();}}
	public object[] Oa{get{return Console.ReadLine().Split();}}
	public int[] Ia2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),int.Parse);}}
	public int[] Ia3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),int.Parse);}
	public int[] Ia3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),int.Parse);}
	public long[] La2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),long.Parse);}}
	public long[] La3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),long.Parse);}
	public long[] La3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),long.Parse);}
	public double[] Da2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),double.Parse);}}
	public double[] Da3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),double.Parse);}
	public double[] Da3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),double.Parse);}
	public T[] Arr<T>(int n,Func<T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f();}return a;}
	public T[] Arr<T>(int n,Func<int,T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i);}return a;}
	public T[] Arr<T>(int n,Func<string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(Console.ReadLine().Split());}return a;}
	public T[] Arr<T>(int n,Func<int,string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i,Console.ReadLine().Split());}return a;}
}

Measured memory_bytes: 13140
// Problem D

#include <stdio.h>
#include <iostream>
#include <vector>
#include <string.h>
#include <cassert>
#include <algorithm>
#include <set>
#include <map>
#include <math.h>
#include <queue>
#include <stack>

#define MAXN 1000
#define pb push_back
#define mp make_pair

using namespace std;

typedef long long int ll;
typedef pair<int, int> ii;

ll N;

int main() {
  cin >> N;
  ll copyN = N;
  // trovo divisori
  vector<ll> div;
  vector<int> contadiv;
  int cont = 0;
  ll i = (ll)2;
  while (i <= ceil(sqrt(double(copyN)))) {
    if (N % i == 0) {
      div.pb(i);
      contadiv.pb(0);
      while (N%i == 0) {
	contadiv[cont]++;
	N = N/i;
      }
      cont++;
    }
    i++;
  }
    
  if (N != 1) { // quello che resta dovrebbe essere primo
    div.pb(N);
    cont++;
    contadiv.pb(1);
  }
  
  int res = 0;
  for (int j=0; j<cont; j++) {
    int guess = 1;
    while ((guess+2) * (guess+1) <= 2*contadiv[j])
      guess++;
    res += guess;
    //~ cout << "div " << div[j] << " we have " << contadiv[j] << " of them, guess = " << guess << endl;
  }
  
  cout << res << endl;
  
  return 0;
}


Measured memory_bytes: 3724
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll read(){
	ll a=0,b=getchar(),c=1;
	while(!isdigit(b))c=b=='-'?-1:1,b=getchar();
	while(isdigit(b))a=a*10+b-'0',b=getchar();
	return a*c;
}
int n,ans,a[105];
int main(){
	n=read();
	memset(a,0x3f,sizeof(a));
	for(int i=1;i<n;i++)
		a[i]=read();
	for(int i=1;i<=n;i++)
		ans+=min(a[i],a[i-1]);
	cout << ans;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>

#include <vector>
#include <list>
#include<stack>
#include<queue>
#include<array>

#include <set>
#include<map>

#include<string>
#include<stdlib.h>

#include<algorithm>
#include <functional>
#include<math.h>

#include<fstream>
#include<iomanip>

using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int,int>;

#define FOR(k,m,n) for(ll (k)=(m);(k)<(n);(k)++)
#define REP(i,n) FOR((i),0,(n))
#define WAITING(str) int str;std::cin>>str;
#define DEBUGING(str) cout<<str<<endl

constexpr int INF = (1 << 30);
constexpr ll INFL = (1ll << 60);
constexpr ll MOD = 1000000007;// 10^9+7


//変数
int N, M;
string s;
vector<vector<int>> edges;
vector<bool> looks;
bool finalResult = false;




//サブ関数
//入力
void input()
{
	cin >> N >> M >> s;
	edges.resize(N);
	looks.resize(N, false);
	REP(i, M) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		edges[a].push_back(b);
		edges[b].push_back(a);
	}
}

using pss = pair<set<int>, set<int>>;
using vpss = vector<pss>;
vpss good_set() {
	vpss goods;
	REP(i, N) {
		pss good;
		for (int to : edges[i]) {
			if (s[to] == 'A')good.first.insert(to);
			else good.second.insert(to);
		}
		goods.push_back(good);
	}
	return goods;
}

vector<bool> make_goods(const vpss joint) {
	vector<bool> v(N, false);
	REP(i, N)v[i] = (!joint[i].first.empty()) & (!joint[i].second.empty());
	return v;
}

void apply(vpss& joint, vector<bool>& goods, int now) {
	for (auto to : edges[now]) {
		if (s[now] == 'A' &&
			joint[to].first.find(now) != joint[to].first.end()) {
			joint[to].first.erase(now);
			if (goods[to] && joint[to].first.empty()) {
				goods[to] = false;
				apply(joint, goods, to);
			}
		}
		if (s[now] == 'B' &&
			joint[to].second.find(now) != joint[to].second.end()) {
			joint[to].second.erase(now);
			if (goods[to] && joint[to].second.empty()) {
				goods[to] = false;
				apply(joint, goods, to);
			}
		}
	}
}


//計算
void calc()
{
	auto joint = good_set();
	auto goods = make_goods(joint);
	REP(i, N) {
		if (!goods[i]) {
			apply(joint, goods, i);
		}
	}
	for (auto f : goods)finalResult |= f;
}


//出力
void output()
{
	cout << (finalResult ? "Yes" : "No") << endl;
}


//デバッグ
void debug()
{
	int N;
	cin>>N;
}


//メイン関数
int main()
{
	input();
	calc();
	output();
	debug();
	
	return 0;
}


Measured memory_bytes: 82344
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
using namespace std;
typedef long long int ll;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}

const int MAX = 510000;
const int MOD = 1000000007;

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

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

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

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

    COMinit();

    ll ans = 0;

    rep(i,n){
        rep(j,m){
            ll ii = i;
            ll jj = j;
            ll x = (n-1-ii)*(n-ii)/2%MOD*m%MOD;
            ll y = ((jj*(jj+1)/2%MOD)*(n-1-ii)%MOD + (m-1-jj)*(m-jj)/2%MOD*(n-ii)%MOD)%MOD;
            ans += (x+y)%MOD * COM(n*m-2,k-2) % MOD;
            ans %= MOD;
        }
    }
    
    cout << ans << endl;
    return 0;
}
 
 


Measured memory_bytes: 12160
n = int(input())
s = [ input() for _ in range(n)]
march = [ 0 for _ in range(5)]
for i in range(n):
    if s[i][0]=="M":
        march[0]+=1
    elif s[i][0]=="A":
        march[1]+=1
    elif s[i][0]=="R":
        march[2]+=1
    elif s[i][0]=="C":
        march[3]+=1
    elif s[i][0]=="H":
        march[4]+=1
ans = 0
for i in range(3):
    for j in range(i+1, 4):
        for k in range(j+1, 5):
            ans = march[i]*march[j]*march[k] + ans
print(ans)


Measured memory_bytes: 9776
#include <iostream>
using namespace std;
int main(void){
int W,H,x,y,r;
cin >> W >> H >> x >> y >> r;
if (x-r<0 || x+r>W || y-r<0 || y+r>H) cout << "No" <<endl;
else cout << "Yes" <<endl;
return 0;
}



Measured memory_bytes: 3080
class Combination:
    """階乗とその逆元のテーブルをO(N)で事前作成し、組み合わせの計算をO(1)で行う"""
    def __init__(self, n, MOD):
        self.fact = [1]
        for i in range(1, n + 1):
            self.fact.append(self.fact[-1] * i % MOD)
        self.inv_fact = [0] * (n + 1)
        self.inv_fact[n] = pow(self.fact[n], MOD - 2, MOD)
        for i in reversed(range(n)):
            self.inv_fact[i] = self.inv_fact[i + 1] * (i + 1) % MOD
        self.MOD = MOD

    def factorial(self, k):
        """k!を求める O(1)"""
        return self.fact[k]

    def inverse_factorial(self, k):
        """k!の逆元を求める O(1)"""
        return self.inv_fact[k]

    def permutation(self, k, r):
        """kPrを求める O(1)"""
        if k < r:
            return 0
        return (self.fact[k] * self.inv_fact[k - r]) % self.MOD

    def combination(self, k, r):
        """kCrを求める O(1)"""
        if k < r:
            return 0
        return (self.fact[k] * self.inv_fact[k - r] * self.inv_fact[r]) % self.MOD


n, a, b, c = map(int, input().split())
MOD = 10 ** 9 + 7
comb = Combination(10 ** 6, MOD)

pa = a * pow(a + b, MOD - 2, MOD) % MOD
pb = b * pow(a + b, MOD - 2, MOD) % MOD

ec = 100 * pow(100 - c, MOD - 2, MOD) % MOD

ans1 = 0
tmp = pow(pa, n, MOD)
for i in range(n):
    ans1 += tmp * pow(pb, i, MOD) * comb.combination(n - 1 + i, i) * (n + i) * ec
    ans1 %= MOD

ans2 = 0
tmp = pow(pb, n, MOD)
for i in range(n):
    ans2 += tmp * pow(pa, i, MOD) * comb.combination(n - 1 + i, i) * (n + i) * ec
    ans2 %= MOD

print((ans1 + ans2) % MOD)

Measured memory_bytes: 115440
#n = int(input())
#L = list(map(int, input().split()))
#import math
#import sys
#import heapq
#import fractions
#import bisect
#import numpy
#import queue
import math

def com(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def main():
    l = [[0]*10, [0]*10, [0]*10, [0]*10, [0]*10, [0]*10, [0]*10, [0]*10, [0]*10]
    ans = 0
    N = int(input())

    for i in range(1,N+1):
        i = str(i)
        if i[0] != 0 and i[-1] != 0:
            l[int(i[0])-1][int(i[-1])-1] += 1

    for i in range(9):
        for j in range(9):
            ans += l[i][j]*l[j][i]
    return ans
print(main())



Measured memory_bytes: 41196
#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);
  int a, b;
  cin >> a >> b;
  if((a + b) % 2 == 0) cout << (a + b) / 2 << endl;
  else cout << "IMPOSSIBLE" << endl;
  return 0;
}
//templete by private_yusuke

Measured memory_bytes: 256
def gcd(a,b):
	if a==0:
		return b
	return gcd(b%a,a)

def find_lcm(num1, num2):
    if(num1>num2):
        b = num1
        a = num2
    else:
        b = num2
        a = num1
    G = gcd(a,b)
    lcm = (num1*num2)//G
    return lcm
     
N=int(input())
A=list(map(int,input().split()))
lcm = find_lcm(A[0],A[1])
for I in range(2, N):
    lcm = find_lcm(lcm, A[I])
Ans=0
lcm-=1
for I in range(N):
	Ans+=(lcm%A[I])
print(Ans)

Measured memory_bytes: 3316
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <algorithm>
#include <typeinfo>
#define _USE_MATH_DEFINES
#include <cmath>

using namespace std;

vector<int> rollDice(char c, vector<int> dice){
    int tmp1, tmp2, tmp3, tmp4;
    switch (c) {
        case 'N':
            tmp1=dice[0]; tmp2=dice[1]; tmp3=dice[4]; tmp4=dice[5];
            dice[0]=tmp2; dice[1]=tmp4; dice[4]=tmp1; dice[5]=tmp3;
            break;
        case 'W':
            tmp1=dice[0]; tmp2=dice[2]; tmp3=dice[3]; tmp4=dice[5];
            dice[0]=tmp2; dice[2]=tmp4; dice[3]=tmp1; dice[5]=tmp3;
            break;
        case 'S':
            tmp1=dice[0]; tmp2=dice[1]; tmp3=dice[4]; tmp4=dice[5];
            dice[0]=tmp3; dice[1]=tmp1; dice[4]=tmp4; dice[5]=tmp2;
            break;
        case 'E':
            tmp1=dice[0]; tmp2=dice[2]; tmp3=dice[3]; tmp4=dice[5];
            dice[0]=tmp3; dice[2]=tmp1; dice[3]=tmp4; dice[5]=tmp2;
            break;
    }
    return dice;
}


int main(){

    vector<int> dice(6);
    for(int i=0; i<6; i++){
        cin >> dice[i];
    }

    string cmds;
    cin >> cmds;
    for(int i=0; i<cmds.size(); i++){
        char c = cmds[i];
        dice = rollDice(c, dice);

    }

    cout << dice[0] << endl;

    return 0;
}



Measured memory_bytes: 3212
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define fo(a,b) for(int a=0;a<b;a++)
#define Sort(a) sort(a.begin(),a.end())
 int wari(int a,int b) {
   if(a%b==0)
     return a/b;
   else
     return a/b+1;
 }
 int keta(int a){//桁数
  double b=a;
  b=log10(b);
  int c=b;
  return c+1;
 }
 int souwa(int a){
  return a*(a+1)/2;
 }
 int lcm(int a,int b){//最小公倍数
  int d=a,e=b,f;
  if(a<b)
    swap(a,b);
  int c,m=1;
  while(m){
    c=a%b;
    if(c==0){
       f=b;
      m--;
    }
    else{
      a=b;
      b=c;
 }
  }
  return d*e/f;
    }
  int gcm(int a,int b){//最大公約数
      int d=a,e=b,f;
  if(a<b)
    swap(a,b);
  int c,m=1;
  while(m){
    c=a%b;
    if(c==0){
       f=b;
      m--;
    }
    else{
      a=b;
      b=c;
 }
  }
  return f;
  }
signed main(){
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  cout<<min(a,b)+min(c,d)<<endl;
}
  

Measured memory_bytes: 256
/*
* @Author: 王文宇
* @Date:   2017-11-19 02:31:24
* @Last Modified by:   王文宇
* @Last Modified time: 2017-11-19 02:32:06
*/
#include <iostream>
#include<cmath>
using namespace std;
int main()
{
	int n;
	cin>>n;
	int k = sqrt(n+0.5);
	cout<<k*k<<endl;
	return 0;
}

Measured memory_bytes: 256
n,x = map(int,input().split())
xli = list(map(int,input().split()))

yli = list(map(lambda a:abs(a-x),xli))

def GCD(a, b):

    if b == 0:
        return a
    else:
        return GCD(b, a % b)

import functools
print(functools.reduce(GCD,yli))


Measured memory_bytes: 14252
#include<bits/stdc++.h>
using namespace std ;
int main ()
{
   int N , c=0 ;
   cin >> N ;
   for(int i =1 ; i<=N; i++)
 {

 if(i>=1 && i<=9 || i>=100 && i<=999 || i>=10000 && i<= 99999)
    c++;
}
cout << c;
    return 0 ;
}

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

int main(){
    string S;
    cin >> S;
    if(S == "AAA"){
        cout << "No" << endl;
    }else if(S == "BBB"){
        cout << "No" << endl;
    }else{
        cout << "Yes" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int p = Integer.parseInt(sc.next()), q = Integer.parseInt(sc.next()), r = Integer.parseInt(sc.next());

        int min = Math.min(Math.min(p + q, q + r), r + p);
        System.out.println(min);
    }
}


Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i,n) for (int i = 0; i < (n); ++i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll INF=1LL<<60;
const int inf=(1<<30)-1;
const int mod=1e9+7;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s,t;cin >> s >> t;
    if(t.substr(0,s.size())==s){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 3616
#include <iostream>

using namespace std;

int main() {
  int n;
  string s;
  cin >> n >> s;
  int x = 0;
  int m = 0;
  for (int i = 0; i < n; i++) {
    x += s[i] == 'I' ? 1 : -1;
    m = max(m, x);
  }
  cout << m << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main() {
    int r, c, x, tmp, total;
    total = 0;
    cin >> r >> c;
    int a[c] = {};
    for (int i=0; i<r; i++){
        tmp = 0;
        for (int j=0; j<c; j++) {
            cin >> x;
            tmp += x;
            a[j] += x;
            total += x;
            cout << x << " ";
        }
        cout << tmp << endl;
    }
    for (int l=0; l<c; l++) {
        cout << a[l] << " ";
    }
    cout << total << endl;
}


Measured memory_bytes: 3104