akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define full(a) a.begin(),a.end()
#define rfull(a) a.rbegin(),a.rend()

using namespace std;
const double pi=acos(-1.0);
const double pii=2*pi;
const double eps=1e-6;
const long long MOD=1e9+7;

void dfs(int ind, int node, vector<bool>& vis, vector<int>& parent, vector<vector<int>>& gr){
	if(vis[ind]){
		vis[ind]=false;
		parent[ind]=node;
		for(int i=0;i<gr[ind].size();i++){
			dfs(gr[ind][i],node,vis,parent,gr);
		}
	}
}

void solve(){
	int n,m,k;
	cin>>n>>m>>k;
	vector<vector<int>> gr(n),bl(n);
	for(int i=0;i<m;i++){
		int x,y;
		cin>>x>>y;
		x--;
		y--;
		gr[x].pb(y);
		gr[y].pb(x);
	}

	for(int i=0;i<k;i++){
		int x,y;
		cin>>x>>y;
		x--;
		y--;
		bl[x].pb(y);
		bl[y].pb(x);
	}


	vector<bool> vis(n,true);
	vector<int> parent(n,-1),friends(n,0),enemies(n,0);
	for(int i=0;i<n;i++){
		dfs(i,i,vis,parent,gr);
	}

	for(int i=0;i<n;i++){
		friends[parent[i]]++;
	}

	for(int i=0;i<n;i++){
		friends[i]=friends[parent[i]];
	}

	for(int i=0;i<n;i++){
		int ans=friends[i]-1;
		set<int> s;
		for(int j=0;j<gr[i].size();j++)
			s.insert(gr[i][j]);
		for(int j=0;j<bl[i].size();j++)
			s.insert(bl[i][j]);
		for(auto itr=s.begin();itr!=s.end();itr++){
			if(parent[i]==parent[*itr])
				ans--;
		}
		cout<<max(0,ans)<<" ";
	}
	cout<<"\n";
}

int main(){
	std::ios::sync_with_stdio(false);
	std::cin.tie(NULL);
	std::cout.tie(NULL);
	solve();
	return 0;
}

Measured memory_bytes: 17656
#include<iostream>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
  int N;
  cin >> N;
  pair<int, int>p[N];
  rep(i, N){
    int a;
    cin >> a;
    p[i] = {a, i};
  }
  sort(p, p+N, greater<pair<int, int>>());
  int K = p[0].second;
  rep(i, N){
    if(i==K) cout << p[1].first << endl;
    else cout << p[0].first << endl;
  }
    
    
 
}

Measured memory_bytes: 3200
#include <bits/stdc++.h>
//#include "atcoder/all"
using namespace std;
//using namespace atcoder;
///////////////////////////////////////////
const long long int INF = 1LL<<60;
const long long int Mod = 1000000007;
const long long int sMod = 998244353;
using ll = long long int; using ci = const int;
using vi = vector<int>;  using Vi = vector<long long int>;
using P = pair<int, int>;  using PLL = pair<ll, ll>;
using matrix = vector<vector<ll>>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define rp(i,N) for(ll i = 0; i < (ll)N; i++)
#define repi(i,a,b) for(ll i = ll(a); i < ll(b); ++i)
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
#define p_queue(v) priority_queue<v, vector<v>, greater<v> >
template<class T> inline void princ(T x){cout<<x<<" ";}; 
template<class T> inline void print(T x){cout<<x<<"\n";};
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
///////////////////////////////////////////////////////////////////////////////////

void solve(){
    ll n;
    cin >> n;
    Vi posi(n),neg(n);
    rp(i,n){
        ll x,y;
        cin >> x >> y;
        posi[i]=y-x;
        neg[i]=x+y;
    }
    Sort(posi);
    Sort(neg);
    ll pi=posi.size();
    ll ni=neg.size();
    print(max(posi[0]-posi[pi-1],neg[0]-neg[ni-1]));
    return;
}
int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    std::cout<<std::fixed<<std::setprecision(30);
    solve();
    return 0;
}

Measured memory_bytes: 6360
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<numeric>
#include<map>
#include<iostream>
#include<iomanip>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--)
typedef long long ll;
typedef pair<ll, ll> mp;

/*
WA
dp[総和をDで割った余りがi][0~9まで自由に選べるかどうか]
*/

ll d,dp[110][2],dp2[110][2],mod=1e9+7,ans;
string s;

int main(void){
	cin>>s>>d;
	//
	rep(j,d)rep(k,2)dp[j][k]=0;
	dp[0][0]=1;
	//
	rep(i,s.size()){
		rep(j,d)rep(k,2)dp2[j][k]=0;
		rep(j,d){//前からの余り
			rep(k,10){//今の桁の数
				ll res = (j+k)%d;
				//自由に選べるやつの遷移先
				dp2[res][1]=(dp2[res][1]+dp[j][1])%mod;
				//自由に選べないやつの遷移先
				if(k<s[i]-'0'){//Kより小さい数字にするなら
					dp2[res][1]=(dp2[res][1]+dp[j][0])%mod;
				}else if(k==(s[i]-'0')){
					dp2[res][0]=(dp2[res][0]+dp[j][0])%mod;
				}
			}
		}
		rep(j,d)rep(k,2)dp[j][k]=dp2[j][k];
	}
	//dp[0][0]+dp[0][1]がちょうど1e9+7になったらやばいので
	ans=(mod+dp[0][0]+dp[0][1]-1)%mod;//0は除く
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python

from functools import reduce

# GCD and LCM are not in math module.  They are in gmpy, but these are simple enough:

def gcd(a,b):
    """Compute the greatest common divisor of a and b"""
    while b > 0:
        a, b = b, a % b
    return a
    
def lcm(a, b):
    """Compute the lowest common multiple of a and b"""
    return a * b // gcd(a, b)

N = int(input())
ts = []
for _ in range(N):
  T = int(input())
  ts.append(T)

print(reduce(lcm, ts))
# ans = 1
# for i in range(N):
#   ans = lcm(ans, ts[i])
# print(ans)


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

std::vector<int> graph[100001];
int dp[100001]; // represent length of longest path starting at node i

int solve(int src)
{
	if (dp[src] != -1)
		return dp[src];
	bool leaf = 1;
	int bestChild = 0;

	for (int child : graph[src])
	{
		leaf = 0;
		bestChild = max(bestChild, solve(child));
	}
	return dp[src] = leaf ? 0 : 1 + bestChild;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int n, m;
	cin >> n >> m;
	memset(dp, -1, sizeof dp);

	for (int i = 0; i < m; i++)
	{
		int u, v;
		cin >> u >> v;
		graph[u].push_back(v);
	}

	int ans = 0;
	for (int i = 1; i <= n; i++)
		ans = max(ans, solve(i));
	cout << ans << endl;
}

Measured memory_bytes: 11572
if __name__ == '__main__':
    N = int(input())
    a = [int(x) for x in input().split()]
    num_len = len(a)
    ans = 0
    for i in range(num_len):
        if a[a[i]-1] == i+1:
            ans += 1
    print(int(ans / 2))

# if __name__ == '__main__':
#     N = int(input())
#     a = [int(x) for x in input().split()]
#     num_len = len(a)
#     ans = 0
#     for i in range(1, num_len+1):
#         for j in range(1, num_len+1):
#             if i == a[j-1] and j == a[i-1]:
#                 ans += 1
#     print(int(ans / 2))


Measured memory_bytes: 13880
h, w, k = gets.split.map(&:to_i)
rows = Array.new(h){gets.chomp.bytes.map{|c| (c == '#'.ord) ? 1 : 0}}
cnt = 0
[0, 1].repeated_permutation(h) do |x|
  m = []
  x.each_with_index do |y, i|
    if y == 0
      m << rows[i]
    else
      m << [0] * w
    end
  end
  [0, 1].repeated_permutation(w) do |u|
    mc = []
    u.each_with_index do |v, l|
      if v == 0
        mc << m.transpose[l]        
      end
    end
    cnt += 1 if mc.flatten.sum == k
  end
end
puts cnt

Measured memory_bytes: 14484
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define INF 10000000000000009
#define INF 9223372036854775807
typedef long long ll;
#define REP(i,n) for(int i=0;i<(n);++i)
#define OREP(i,n) for(int i=1;i<=(n);++i)
#define ORREP(i,n) for(int i=(n);i>=1;--i)
#define ZREP(i,n) for(int i=1;i<(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define rollcall cout<<"I'm Sucu."<<endl;
#define YES(s) s?cout << "YES" << endl:cout << "NO" << endl
#define Yes(s) s?cout << "Yes" << endl:cout << "No" << endl
#define Taka(s) s?cout << "Takahashi" << endl:cout << "Aoki" << endl
#define out(s,t,u) s?cout << t << endl:cout << u << endl
#define int ll
#define Endl endl


signed main(){
    int N,K;
    int A[1004];
    int B[1004];
    int C[1114514];
    cin >> N >> K;
    REP(i,N){
        cin >> A[i];
        B[i+1]=B[i]+A[i];
    }
    int c=0;
    REP(i,N+1){
        REP(j,i){
            C[c]=B[i]-B[j];
            c++;
        }
    }
    sort(C,C+c,greater<>());
    int L=(int)log2(C[K-1]);
    vector<int> D;
    int E=(int)pow(2,L);
    
    REP(i,c){
        if(E<=C[i]){
            D.push_back(C[i]);
        }else{
            break;
        }
    }
    
   // cout << E << endl;
    
    REP(j,L){
        E/=2;
        int cou=0;
        REP(i,D.size()){
            if((D[i]/E)%2==1)cou++;
        }
        if(cou<K){
            continue;
        }
        REP(i,D.size()){
            if((D[i]/E)%2==0){
                D.erase(D.begin()+i);
                i--;
            }
        }
    }
    int Ans=D[0];
    REP(i,D.size()){
        Ans=(Ans&D[i]);
    }
    cout << Ans << endl;
    
    return 0;
}   


Measured memory_bytes: 7416
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define MM 1000000000;
#define mod MM + 7;
#define INF (ll)1e18
#define pi acos(-1.0)
#define MAX 1000000005
#define NIL -1
int main(){
    int a[3]; cin >> a[0] >> a[1] >> a[2];
    sort(a, a + 3);
    int sum = a[0] + a[1] + a[2];
    int cnt = 0;
    if(sum % 2 == a[2]%2){
        cnt = (3*a[2] - sum)/2;
    } else {
        cnt = (3*(a[2]+1) - sum)/2;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 2e5 + 10;
const int INF = 0x3f3f3f3f;
const ll inf = 0x3f3f3f3f3f3f3f3f;
const ll mod = 998244353;
const double PI = acos(-1);
double a, b;
double h, m;
int main() {
	cin >> a >> b >> h >> m;
	double t1;
	t1 = (h * 60 + m) / (12.0*60.0) * 2 * PI;
	double t2 = m / 60.0 * 2 * PI;
	double t = abs(t1 - t2);
	t = min(t, 2*PI - t);
	printf("%.12lf\n", sqrt(a*a + b * b - 2 * a*b*cos(t)));
	return 0;
}

Measured memory_bytes: 4212
#include<cstdio>
using namespace std;
int n,qzh0[300001],qzh1[300001],ans=0x7fffffff;
char a[300001];
int main()
{
	scanf("%d%s",&n,a+1);
	for(int i=1;i<=n;++i) {
		qzh0[i]=qzh0[i-1];qzh1[i]=qzh1[i-1];
		if(a[i]=='E') qzh1[i]++;else qzh0[i]++;
	}
	for(int i=1;i<=n;++i) if(ans>qzh0[i-1]+qzh1[n]-qzh1[i]) ans=qzh0[i-1]+qzh1[n]-qzh1[i];
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 2816
#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 n; cin >> n;
    int ans = 1;
    while (ans*2 <= n) {
        ans *= 2;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <limits>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <stdio.h>
#include <map>
#include <utility>
using namespace std;
#define rep(i, n) for (int i =0; i < (int)(n); i++)
typedef pair<int, string> P;




int main() {
    int n;
    cin >> n;
    int ans = 0;
    ans = n % 10;

    if (ans == 3) {
        cout << "bon" << endl;
        return 0;
    }

    if (ans == 0 || ans==1 || ans==6 ||ans==8) {
        cout << "pon" << endl;
        return 0;
    }

    if (ans == 2 || ans == 4 || ans == 5 || ans == 7 || ans == 9) {
        cout << "hon" << endl;
        return 0;
    }
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using ll = long long;
ll n;
int f, s;
int ans = 100;
std::vector<std::pair<ll, ll>> vec;

int main() {
    std::cin >> n;
    for (ll i = 1; i*i <= n; i++) {
        if (n % i == 0) {
            ll p = n / i;
            vec.push_back(std::make_pair(i, p));
        }
    }
    for (ll j = 0; j < vec.size(); j++) {
        f = std::to_string(vec[j].first).size();
        s = std::to_string(vec[j].second).size();
        int m = std::max(f, s);
        if (m < ans) {
            ans = m;
        }
    }
    std::cout << ans << std::endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
int n,ans=400000;
char a[300010];
int cnt[300010];
int main()
{
	scanf("%d%s",&n,a);
	if (a[0]=='E') cnt[0]=1;
	for (int i=1;i<n;i++)
	{
		if (a[i]=='E') cnt[i]=cnt[i-1]+1;
		else cnt[i]=cnt[i-1];
	}
	for (int i=0;i<n;i++)
	{
		int t;
		if (i!=0) t=cnt[n-1]-cnt[i]+i-cnt[i-1];
		else t=cnt[n-1]-cnt[i];
		if (ans>t) ans=t;
	}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 1664
#include<stdio.h>
#include<math.h>
int main(){
    int N;
    int T,A;
    double H[1000];
    int near = 0; //初期化
    
    scanf("%d",&N);
    scanf("%d %d",&T,&A);
    
    for(int i = 0 ; i < N ; i++){
        scanf("%lf",&H[i]);
    }
    double abs_min = fabs(H[0]-A);
    
    for(int i = 0 ; i < N ; i++){
        H[i] = T - H[i] * 0.006;
        if(fabs(H[i]-A) < abs_min){
            abs_min = fabs(H[i]-A);
            near = i+1;
        }
    }
    printf("%d\n",near);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <numeric>
#include <limits>
#include <cmath>
#include <iomanip>
 
#define ALL(a)  (a).begin(),(a).end()
 
using namespace std;
typedef long long int ll;
typedef pair <int,int> P;
 
int main() {
    int n, m;
    int ac = 0, wa = 0;

    cin >> n >> m;

    bool *p = new bool[n];
    int *w = new int[n];

    for (int i = 0; i < n; i++) {
        w[i] = 0;
    }

    for (int i = 0; i < m; i++) {
        int j;
        string s;
        cin >> j >> s;
        if (p[j-1] == 0) {
            if (s.compare("AC") == 0) {
                p[j-1] = true;
                ac++;
            } else w[j-1]++;
        }
    }

    for (int i = 0; i < n; i++) {
        if (p[i]) wa += w[i];
    }

    cout << ac << ' ' << wa << endl;
    delete p;
    return 0;
}

Measured memory_bytes: 768
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <algorithm>
#include <numeric>
#include <random>
#include <vector>
#include <array>
#include <bitset>
#include <queue>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
 
using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;

int main() {
    int a, b;
    cin >> a >> b;
    if(a <= 5){
        cout << "0";
    } else if((a <= 12) && (a >= 6)){
        cout << b / 2;
    } else if(a >= 13){
        cout << b;
    }
    return 0;
}

Measured memory_bytes: 3640
function Main(input) {
  input = input.replace(/\n/g, ' ');
  input = input.split(" ");
  var A = Number(input[0]);
  var B = Number(input[1]);
  var C = Number(input[2]);
  var D = Number(input[3]);
  var E = Number(input[4]);
  if(A>C){C+=24;}
  var a = A*60+B;
  var b = C*60+D;
  console.log(b-a-E);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

int main(){

  int a[10];

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

  a[0] = min(a[0],a[1]);

  cout << min(a[3],a[4]) + min(a[0],a[2]) - 50 << endl;

}

Measured memory_bytes: 1160
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
    vector<int> v(3);
    cin >> v[0] >> v[1] >> v[2];
    sort(v.begin(), v.end());
    if (v[0] == 5 && v[1] == 5 && v[2] == 7)
        puts("YES");
    else
        puts("NO");
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define bit(x) (1L << (x))
using ll = long long;
using namespace std;

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

  function<int(int, int)> pow = [&](int x, int n){
    if(n == 0) return 1;
    else return x * pow(x, n-1);
  };

  vector<int> v{1};

  FOR(i, 2, 32){
    for(int j=2; ; j++){
      if(pow(i, j) > 1000) break;
      v.push_back(pow(i, j));
    }
  }

  sort(v.begin(), v.end());

  int ans = -1;
  for(const auto& u: v) {
    if(u <= x) ans = u;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**8)
INF = float("inf")


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


def GCDs(*a):
    # リストで入力しないよう注意。
    if len(a) == 0:
        return -1  # エラー

    if len(a) == 1:
        return a[0]

    res = a[0]
    for i in range(1, len(a)):
        res = GCD(res, a[i])
    return res


def solve(K: int):
    tot = 0
    for i in range(1, K+1):
        for j in range(i, K+1):
            b = GCD(i, j)
            for k in range(j, K+1):
                c = GCD(b, k)
                if i == j == k:
                    tot += c
                elif i == j or j == k or i == k:
                    tot += 3*c
                else:
                    tot += 6*c
    print(tot)
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    K = int(next(tokens))  # type: int
    solve(K)


if __name__ == '__main__':
    main()


Measured memory_bytes: 9264
#include<bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define ld long double
#define mk make_pair
#define fi first
#define se second
#define vll vector<ll>
#define pii pair<ll,ll>
#define vvll vector< vector<ll> >
#define pb push_back
#define sz(v) (v).size()
#define inf 1e18
#define md 998244353
#define all(v) (v).begin(),(v).end()
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define tel(a){cout<<a<<"\n";}
#define tell(a,b){cout<<a<<" | "<<b<<"\n";}
#define telll(a,b,c){cout<<a<<" | "<<b<<" | "<<c<<"\n";}
#define teln(v,n){cout<<"v- ";rep(i,0,n)cout<<v[i]<<" ";cout<<"\n";}
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define tihs if(fopen("inp.txt","r"))freopen("inp.txt", "r", stdin),freopen("out.txt", "w", stdout);
using namespace std;

#define M 1000010
ll ex(ll a,ll b){ll ans=1;while(b){if(b&1)ans=(ans*a)%md;a=(a*a)%md,b/=2;}return ans;} 
inline ll add(ll a,ll b){a=a%md+b%md;if(a>md)a%=md;return a;}
inline ll sub(ll a,ll b){a=a%md-b%md;if(a<0)a+=md;return a;}
inline ll mul(ll a,ll b){return (a*b)%md;}

ll f[M],iv[M];
ll C(ll n,ll r){
	if(n<r)return 0;
	return mul(f[n],mul(iv[r],iv[n-r]));
}
// f(n,k) = f(n-1,k-1) + (m-1)f(n-1,k)   G(n)=sum k>=0 f(n,k)x^k  
// G(n) = (x+m-1)G(n-1)
// G(n) = { x^k} (x+m-1)^n G(0)   C(n,k)(m-1)^(n-k) C(2,0)+C(2,1)
// for 1st f(n,k)= m f(n-1,k)
// 
int main(){
	IOS;
	tihs;
	
	f[0]=1;
	rep(i,1,M)f[i]=mul(i,f[i-1]);
	iv[M-1]=ex(f[M-1],md-2);
	for(ll i=M-2;i>=0;--i)iv[i]=mul(i+1,iv[i+1]);
	
	
	ll n,m,k;cin>>n>>m>>k; n--;
	ll ans=0;
	rep(i,0,k+1){
		ans=add(ans,mul(C(n,i),ex(m-1,n-i)));
	}
	ans=mul(ans,m);
	cout<<ans;
	


	return 0;
}

	

Measured memory_bytes: 19284
#include <stdio.h>
int main(){
  int a[200000],i,minv,maxv;
  scanf("%d",&a[0]);
  for(i=1;i<=a[0];i++){
	scanf("%d",&a[i]);
  }
  minv=a[1];
  maxv=a[2]-a[1];
  for(i=2;i<=a[0];i++){
	 if(maxv<a[i]-minv)
	  maxv = a[i]-minv;
	if(minv>a[i])
	  minv = a[i];
  }
  printf("%d\n",maxv);
  return 0;
}



Measured memory_bytes: 2636
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define REP(i,b) FOR(i,0,b)
#define INF 1e9

int w,h,c[50][50],i_num;
int dx[] = {1,0,-1}, dy[] = {1,0,-1};

void search(int x, int y){
  if(c[y][x] == 1 && x >=0 && x < w && y >=0 && y < h){
    c[y][x] = i_num;
    REP(i,3) REP(j,3){
      if(i != 0 || j != 0 || x-1 >= 0 || x+1 < w || y-1 >= 0 || y+1 < h)
      search(x+dx[i],y+dy[j]);
    }
  }
}

void solve(int X, int Y){
  i_num = 2;
  REP(i,20) REP(j,20) c[i][j] = 0;
  //0:ocean, 1:land, 2~:island_number

  REP(i,Y){
    REP(j,X){
      cin>>c[i][j];
    }
  }

  REP(i,Y){
    REP(j,X){
      if(c[i][j] == 1){
        search(j,i);
        i_num++;
      }
    }
  }

  cout<<i_num-2<<endl;
  /*REP(i,20){
     REP(j,20) cout<<c[i][j];
     cout<<endl;
  }*/
}

int main(){

  while(1) {
    cin>>w>>h;
    if(w == 0 && h == 0) break;
    solve(w,h);
  }

  return 0;
}


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

using namespace std;

int main()
{
	int n, m;
	cin >> n >> m;
	string a[50], b[50];
	for (int i = 0; i < n; i++)
		cin >> a[i];
	for (int i = 0; i < m; i++)
		cin >> b[i];
	bool ok = false;
	for (int i = 0; i <= n - m; i++)
		for (int j = 0; j <= n - m; j++)
		{
			bool tmp = true;
			for (int k = 0; k < m; k++)
				if (a[i + k].substr(j, m) != b[k])
					tmp = false;
			if (tmp)
				ok = true;
		}
	if (ok)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
	return 0;
}


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

using namespace std;

int main() {
	int n;

	while (cin >> n) {
		if (n == 0) {
			break;
		}

		string str;
		cin >> str;
		
		for (int i = 0; i < n; ++i) {
			auto it = str.begin();
			string temp_str;
			while (it != str.end()) {
				auto it_e = find_if(it, str.end(), [it](char x) {return *it != x;});
				auto duration = it_e - it;
				temp_str += to_string(duration);
				temp_str.push_back(*it);
				it = it_e;
			}
			str = temp_str;
		}
		cout << str << endl;
	}

	return 0;
}

Measured memory_bytes: 1368
from math import floor,ceil,sqrt,factorial,log
from collections import Counter, deque
from functools import reduce
def S(): return input()
def I(): return int(input())
def MS(): return map(str,input().split())
def MI(): return map(int,input().split())
def LS(): return list(MS())
def LI(): return list(MI())
def LLS(): return [list(map(str, l.split() )) for l in input()]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def LLSN(n: int): return [LS() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]

MOD = 10**9 + 7

n, a, b = LI()

def combination(r):
    numerator = reduce(lambda x, y: x * y % MOD, [n - r + i + 1 for i in range(r)])
    denominator = reduce(lambda x, y: x * y % MOD, [i + 1 for i in range(r)])

    return numerator * pow(denominator, MOD-2, MOD) % MOD

ans = pow(2, n, MOD) - 1 - combination(a) - combination(b)

print(ans % MOD)

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

using namespace std;

int main() {
	int N, L;
	cin >> N >> L;
	int taste = 0;
	for (int i = 0; i < N; i++) {
		taste += (L + i);
	}
	if (L > 0)taste -= L;
	else if (L + N - 1 < 0)taste -= (L + N - 1);
	cout << taste << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<limits>
#include<set>
#include<queue>
using namespace std;
#define int long  long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
typedef pair<int, int>P;
const int INF = 1e8;

signed main() {
	int N, K;
	cin >> N >> K;
	int num, sum = 0;
	rep(i, N) {
		cin >> num;
		sum += 2 * min(num, abs(K - num));
	}
	cout << sum;
}

Measured memory_bytes: 256
N = gets.to_i
A = gets.split.map(&:to_i).sort

r = [1, 400, 800, 1200, 1600, 2000, 2400, 2800, 3200, 10000]
R = r.zip(r.map{|i| i - 1}.drop(1)).take(9).map{|x, y| (x..y)}

inds = A.map{|a| R.index{|x| x === a}}
red = inds.count{|x| 7 < x}
cmin = inds.select{|x| x < 8}.uniq.size
if cmin == 0
  puts [1, red].join(" ")
else
  puts [cmin, cmin + red].join(" ")
end


Measured memory_bytes: 1788
import java.io.*;
import java.lang.*;
import java.util.*;

public class Main {
    static Scanner x = new Scanner(System.in);
    public static void main(String[] args) {
	int n=x.nextInt();
	int cnt=0;
	n--;
	while(n>0) {
	    n/=3;
	    cnt++;
	}
	System.out.println(cnt);
    }
}


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

using namespace std;

int main() {
#ifdef  DEBUG
  ifstream in("input.txt");
  cin.rdbuf(in.rdbuf());
#endif  // for local.
  int a;
  cin >> a;
  if (a%27 == 26 || a%27 == 13) {
    cout << ":(";
  } else {
    cout << ceil(double(a) / 1.08);
  } cout << endl;
  
  return 0;
}

Measured memory_bytes: 256
from collections import defaultdict, deque
n, k = map(int, input().split())
a = list(map(int, input().split()))
s = sum(a)

x = []
for i in range(1, s+1):
    if i * i > s:
        break
    if s % i == 0:
        x.append(i)
        x.append(s//i)

ans = 0
for xi in x:
    b = []
    for i in range(n):
        if a[i] % xi != 0:
            b.append(a[i] % xi)

    b.sort()
    b = deque(b)

    c = 0
    r = 0
    while b:
        q = b.pop() + r

        while q < xi:
            p = b.popleft()
            q += p
            c += p

        r = q - xi

    if c <= k:
        ans = max(ans, xi)
    # print(xi, b, c)

print(ans)


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

using namespace std;

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

int main(){
	
	while(1){
		int m;
		cin >> m;
		if(m==0) break;
		
		int n=0,e=0,s=0,w=0;
		
		int t[m][2]={};
		
		for(int i=1;i<m;i++){
			int a,b;
			cin >> a >> b;
			t[i][0]=t[a][0]+dx[b];
			t[i][1]=t[a][1]+dy[b];
			n=min(n,t[i][1]);
			s=max(s,t[i][1]);
			w=min(w,t[i][0]);
			e=max(e,t[i][0]);
		}
		cout << e-w+1 << " " << s-n+1 << endl;
	}
	return 0;
}


Measured memory_bytes: 3072
#include <iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<queue>
#include<cmath>
#include<set>
using namespace std;
typedef long long ll;

const ll MOD_CONST = 1000000007;



int main(){
	string s;
	cin >> s;
	char c = s[0];
	for (int i = 1; i < 3; i++) {
		if (s[i] != c) {
			cout << "Yes" << endl;
			return 0;
		}
	}

	cout << "No" << endl;
	return 0;
}  



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


int main()
{
	int a[3];
	cin >> a[0] >> a[1] >> a[2];
	sort(a, a + 3);
	cout << a[0] << " " << a[1] << " " << a[2] << endl;
	return 0;
}

Measured memory_bytes: 3128
import java.util.*;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long[] a = new long[n];
        for(int i = 0; i < n; i++){
            a[i] = sc.nextInt();
        }
        long len = 0;
        for(int i = 1; i < n; i++){
            if(a[i-1] > a[i]){
                len += a[i-1] - a[i];
                a[i] += a[i-1]-a[i];
            }
        }
        System.out.println(len);
    }
}

Measured memory_bytes: 63492
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {

	FastScanner in;
	PrintWriter out;

	void solve() {
		int n = in.nextInt();
		int m = in.nextInt();
		int l = in.nextInt();

		long d1[][] = new long[n][n];
		long MAX = Long.MAX_VALUE / 4;

		// グラフの初期化
		for (int i = 0; i < n; ++i)
			Arrays.fill(d1[i], MAX);

		// 町間の距離を入力
		for (int i = 0; i < m; ++i) {
			int a = in.nextInt() - 1;
			int b = in.nextInt() - 1;
			int c = in.nextInt();

			d1[a][b] = d1[b][a] = c;
		}

		// ワーシャルフロイド法で町間の最短距離を算出
		for (int k = 0; k < n; ++k) {
			for (int i = 0; i < n; ++i) {
				for (int j = 0; j < n; ++j) {
					if (d1[i][j] > d1[i][k] + d1[k][j])
						d1[i][j] = d1[i][k] + d1[k][j];
				}
			}
		}

		// 燃料算出用グラフの初期化
		long d2[][] = new long[n][n];
		for (int i = 0; i < n; ++i) {
			Arrays.fill(d2[i], MAX);
		}

		// 燃料算出用グラフの入力
		for (int i = 0; i < n; ++i) {
			for (int j = 0; j < n; ++j) {
				if (d1[i][j] <= l) {
					d2[i][j] = d2[j][i] = 1;
				}
			}
		}
		d1 = d2;

		// ワーシャルフロイド法で町間の最小燃料量を算出
		for (int k = 0; k < n; ++k) {
			for (int i = 0; i < n; ++i) {
				for (int j = 0; j < n; ++j) {
					if (d1[i][j] > d1[i][k] + d1[k][j])
						d1[i][j] = d1[i][k] + d1[k][j];
				}
			}
		}

		int q = in.nextInt();
		for (int i = 0; i < q; ++i) {
			int s = in.nextInt() - 1;
			int t = in.nextInt() - 1;

			long x = d1[s][t];
			out.println(x == MAX ? -1 : x - 1);
		}

	}

	void run() {
		try {
			in = new FastScanner(new File("Main.in"));
			out = new PrintWriter(new File("Main.out"));

			solve();

			out.close();
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		}
	}

	void runIO() {

		in = new FastScanner(System.in);
		out = new PrintWriter(System.out);

		solve();

		out.close();
	}

	class FastScanner {
		BufferedReader br;
		StringTokenizer st;

		public FastScanner(File f) {
			try {
				br = new BufferedReader(new FileReader(f));
			} catch (FileNotFoundException e) {
				e.printStackTrace();
			}
		}

		public FastScanner(InputStream f) {
			br = new BufferedReader(new InputStreamReader(f));
		}

		String next() {
			while (st == null || !st.hasMoreTokens()) {
				String s = null;
				try {
					s = br.readLine();
				} catch (IOException e) {
					e.printStackTrace();
				}
				if (s == null)
					return null;
				st = new StringTokenizer(s);
			}
			return st.nextToken();
		}

		boolean hasMoreTokens() {
			while (st == null || !st.hasMoreTokens()) {
				String s = null;
				try {
					s = br.readLine();
				} catch (IOException e) {
					e.printStackTrace();
				}
				if (s == null)
					return false;
				st = new StringTokenizer(s);
			}
			return true;
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}
	}

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


Measured memory_bytes: 45384
#include <iostream>
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <climits>
#include <vector>
#include <iomanip>
#include <string>
#include <queue>
#include <numeric>
#include <functional>
#include <array>
#include <map>
#include <set>

using namespace std;
using P = pair<int, int>;
using T = tuple<int, int, int>;

long long MOD = 1000000007;
long long dp[100005][4];

P channel[30];

bool compare_by_second(pair<int, int> a, pair<int, int> b) {
	if (a.second != b.second) {
		return a.second < b.second;
	}
	else {
		return a.first < b.first;
	}
}

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

	int ans = 0;
	for (int i = 0; i < 3;++i) {
		if (S[i] == C[i])ans++;
	}

	cout << ans << endl;
}


Measured memory_bytes: 256
#110 B
N,M,X,Y= map(int,input().split())
x =[int(j) for j in input().split()]
y =[int(j) for j in input().split()]
for i in range(-100,101):
    if X<i<=Y and max(x) <i and min(y) >=i:
        print('No War')
        exit()
print('War')

Measured memory_bytes: 3060
import java.util.*;
public class Main {
     public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int B = sc.nextInt();
        int H = sc.nextInt();
        int M = sc.nextInt();

        double HR = 30 * H + M * 0.5;
        double MR = 360 / 60 * M;

        double r = Math.abs(HR - MR);
        double cos = Math.cos(Math.toRadians(r));
        double result = Math.pow(A, 2) + Math.pow(B, 2) - 2 * A * B * cos;
        result = Math.sqrt(result);
       
       
        System.out.println(result);
    }
}

Measured memory_bytes: 35824
import java.util.Scanner;

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

    int x = 0;
    int i = 1;
    while(0 != (x = sin.nextInt())){
      System.out.println("Case " + i +": " + x);
      i++;
    }

    sin.close();
  }
}


Measured memory_bytes: 41308
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
    public static void main(String []args) throws IOException {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st=new StringTokenizer(br.readLine());
        int N=Integer.parseInt(st.nextToken());
        int X=Integer.parseInt(st.nextToken());
        int T=Integer.parseInt(st.nextToken());
        int sum=0;
        while (N>0){
            N-=X;
            sum+=T;
//            System.out.println(sum);
        }
        System.out.println(sum);
    }
}


Measured memory_bytes: 32688
#include <iostream>
#include <cstdio>
#include <math.h>
#include <algorithm>
#include <queue>
#include <deque>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
#include <set>
#include <map>
#include <bitset>
#include <stdlib.h>
#include <cassert>
#include <time.h>
#include <numeric>
#include <iomanip> 
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef tree<int,null_type,less<int>,rb_tree_tag, tree_order_statistics_node_update> indexed_set;
typedef vector<int> vi;
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define sz(v) (int)v.size()
#define ll unsigned long long int
#define ld long double
#define pii pair<int, int>
#define pll pair<ll, ll>
#define fill(a,v) memset(a,v,sizeof(a));
#define all(v) v.begin(),v.end()
#define rep(i, a, b) for(int i = a; i < b; i++)


#define trarr(a,n) forn(i,0,n) cerr<<a[i]<<" \n"[i==n-1];
#define trmat(g,n,m) forn(i,0,n)forn(j,0,m) cerr<<g[i][j]<<" \n"[i==m-1];
#define tr(...) cerr<<__FUNCTION__<<' '<<__LINE__<<" = ";trace(#__VA_ARGS__, __VA_ARGS__)
template<typename S, typename T> 
ostream& operator<<(ostream& out,pair<S,T> const& p){out<<'('<<p.ff<<", "<<p.ss<<')';return out;}
template<typename T>
ostream& operator<<(ostream& out,vector<T> const& v){
int l=v.size();for(int i=0;i<l-1;i++)out<<v[i]<<' ';if(l>0)out<<v[l-1];return out;}
template<typename T>
void trace(const char* name, T&& arg1){cout<<name<<" : "<<arg1<<endl;}
template<typename T, typename... Args>
void trace(const char* names, T&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');cout.write(names, comma-names)<<" : "<<arg1<<" | ";trace(comma+1,args...);}

const ld PI = acos(-1);
const ld EPS = 1e-9;
const int inf = 1e9+10;
const ll INF = 1e18+10;
const int P = 1e9+7;
const int N = 10000001;
int sieve[N], primes[N], pcnt;

void getSieve(){
	for(int i = 2; i < N; i++){
		if(sieve[i] == 0){
			sieve[i] = i; primes[pcnt++] = i;
		}
		for(int j = 0; j < pcnt and primes[j] <= sieve[i] and i*primes[j] < N; j++) sieve[i*primes[j]] = primes[j];
	}
	return;
}
ll getDiv(int n){
	ll ans = 1;
	while(n > 1){
		int cnt = 0;
		int p = sieve[n];
		while(n>1&& n%p == 0){
			cnt++;
			n/=p;
		}
		ans*=(cnt+1);
	}

	return ans;
}
void solve(int _t){
	ll ans = 0;
	int n;
	cin >> n;
	for(int i = 1 ; i <= n; i++){
		ans += i*getDiv(i);
	}
	cout<<ans<<endl;
}
int main(){
	getSieve();
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int t = 1;
	// cin >> t;
	rep(test, 1, t+1){
		solve(test);
	}
	return 0;
}  

Measured memory_bytes: 45264
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
typedef long long ll;
namespace mp = boost::multiprecision;
using Mint = mp::cpp_int;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i = int(a); i < int(b); i++)
#define all(v) v.begin(), v.end()
#define uni(v) v.erase(unique(all(v)), v.end())
#define sort_g(v) sort(all(v), greater<int>())
#define dump(x) cerr << #x << ' ' << '=' << ' ' << x << endl

int sum_digit(int n) {
    int sum = 0;
    while(n > 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}

int main() {
    int N;
    cin >> N;
    int S = sum_digit(N);
    cout << (N % S == 0 ? "Yes" : "No") << endl;
}


Measured memory_bytes: 256
n = input()
nums = map(int,raw_input().split())
nums = sorted(nums)
i=n-2
x=1
while True:
    if i<0:
        break
    tmp =nums[n-1]*x 
    if tmp%nums[i]==0:
        i-=1
    else:
        x+=1
        i=n-2
print tmp

Measured memory_bytes: 6420
def main():
    from sys import stdin
    readline = stdin.readline
    H, N = map(int, readline().split())
    AB = [list(map(int, readline().split())) for _ in range(N)]

    max_A = max(a for a, _ in AB)
    dp = [100000000] * (H + max_A+ 1)
    dp[0] = 0
    for i in range(H):
        if dp[i] == 100000000:
            continue
        for a, b in AB:
            t = dp[i] + b
            if t < dp[i + a]:
                dp[i + a] = t
    print(min(dp[H:]))


main()


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

ll bit[200001];
int N, K;

ll sum(int i) {
  ll s = 0;
  while (i > 0) {
    s += bit[i];
    i -= i & -i;
  }
  return s;
}

void add(int i, ll x) {
  while (i <= N + 1) {
    bit[i] += x;
    i += i & -i;
  }
}

int main() {
  cin >> N >> K;
  vector<ll> s(N + 1, 0);
  for (int i = 1; i < N + 1; ++i) {
    int a; cin >> a;
    s[i] = s[i - 1] + a - K;
  }
  vector<ll> st(s), c;
  sort(begin(st), end(st));
  st.erase(unique(begin(st), end(st)), end(st));
  for (auto&& x : s) c.push_back(lower_bound(begin(st), end(st), x) - begin(st));
  ll ans = 0;
  for (int i = 0; i < N + 1; ++i) {
    ans += sum(c[i] + 1);
    add(c[i] + 1, 1);
  }
  cout << ans << endl;
  return 0;
}


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

using namespace std;

typedef long long ll;

const int maxn=1e6+5,mod=1e9+7;
const double pi=acos(-1);

int main()
{
    string s;
    cin>>s;
    cout<<s[0]<<s[1]<<s[2]<<endl;
    return 0;
}


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

int n;
vector<vector<int>> x;
void dfs (int now, int n, int used, vector<int> &v) {
  if (now == n) {
    x.emplace_back(v);
    return;
  }
  vector<int> y = v;
  for (int i = 0; i <= used + 1; i++) {
    y.at(now) = i;
    dfs(now + 1, n, used + (i == used + 1), y);
  }
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int n;
  cin >> n;
  
  vector<int> z(n);
  dfs(0, n, -1, z);
  
  for (int i = 0; i < x.size(); i++) {
    for (int j = 0; j < n; j++) {
      cout << (char) (x[i][j] + 'a');
    }
    cout << '\n';
  }
}

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

template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b)a=b;};
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b)a=b;};

template<typename T> void drop(T x){cout<<x<<endl;exit(0);};


int MOD;
template<typename T>
struct Mint{
  T v;
  Mint():v(0){}
  Mint(signed v):v(v){}
  Mint(long long t){v=t%MOD; if(v<0) v += MOD;}

  Mint pow(long long k){
    Mint res(1), tmp(v);
    while(k){
      if(k&1)  res *= tmp;
      tmp *= tmp;
      k>>=1;
    }
    return res;
  }

  static Mint add_identity(){return Mint(0);}
  static Mint mul_identity(){return Mint(1);}

  Mint inv(){return pow(MOD- 2);}

  Mint& operator+=(Mint a){v += a.v; if(v>=MOD) v -= MOD; return *this;}
  Mint& operator-=(Mint a){v += MOD - a.v; if(v>=MOD) v-=MOD; return *this;}
  Mint& operator*=(Mint a){v = 1LL * v * a.v%MOD; return *this;}
  Mint& operator/=(Mint a){return (*this) *= a.inv();}

  Mint operator+(Mint a)const{return Mint(v)+=a;}
  Mint operator-(Mint a)const{return Mint(v)-=a;}
  Mint operator*(Mint a)const{return Mint(v)*=a;}
  Mint operator/(Mint a)const{return Mint(v)/=a;}

  Mint operator-()const{return v?Mint(MOD-v):Mint(v);}

  bool operator==(const Mint a)const{return v == a.v;}
  bool operator!=(const Mint a)const{return v != a.v;}
  bool operator <(const Mint a)const{return v < a.v;}
};

template<typename T>
ostream& operator<<(ostream &os, Mint<T> m){os<<m.v;return os;}

using Mi=Mint<ll>;

const int MX=2100;

Mi comb[MX][MX]={};
Mi A[MX][MX]={};
Mi B[MX][MX]={};
Mi C[MX][MX]={};

bool valid(int a,int b){return a>=0 && b>=0;}

const vector<int> dx={0,-1};
const vector<int> dy={-1,0};
const char z='0';

signed main(){
  cin.tie(0);
  ios::sync_with_stdio(0);
  ll H,W;
  cin>>H>>W>>MOD;
  vector<string> M(H);
  for(auto &I:M){cin>>I;}

  comb[0][0]=1;
  for(int i=0;i<MX;i++){
    for(int j=0;j<MX;j++){
      for(int k=0;k<2;k++){
        int x=i+dx[k];
        int y=j+dy[k];
        if(valid(x,y)){
          comb[i][j]+=comb[x][y];
        }
      }
    }
  }

  A[0][0]=M[0][0]-z;
  B[0][0]=1;
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      for(int k=0;k<2;k++){
        int x=i+dx[k];
        int y=j+dy[k];
        if(!valid(x,y)){continue;}
        if(!isdigit(M[i][j])){
          A[i][j]+=A[x][y];
          B[i][j]+=B[x][y];
          C[i][j]+=C[x][y];
          continue;
        }
        ll d=M[i][j]-z;
        if(isdigit(M[x][y])){
          A[i][j]+=A[x][y]*10+B[x][y]*d;
          B[i][j]+=B[x][y];
          C[i][j]+=C[x][y];
        }
        else if(M[x][y]=='*'){
          A[i][j]+=A[x][y]*d;
          B[i][j]+=A[x][y];
          C[i][j]+=C[x][y];
        }
        else{
          A[i][j]+=comb[x][y]*d;
          B[i][j]+=comb[x][y];
          C[i][j]+=A[x][y]+C[x][y];
        }
      }
    }
  }
  Mi ans=A[H-1][W-1]+C[H-1][W-1];
  cout<<ans<<endl;



  return 0;
}



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

int getSumOfDigits(int n) {
  int sum = 0;
  while (n > 0) {
    sum += n % 10;
    n /= 10;
  }
  return sum;
}


int main() {
  int n, a, b;
  cin >> n >> a >> b;
  
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    int result = getSumOfDigits(i);
    if (result >= a && result <= b) {
      ans += i;  
    }
  }
  cout << ans << endl;
}


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

#define lint long long
#define P pair<int, int>
#define LLP pair<long long, long long>
#define REP(i, x, n) for(int i = (x), i##_len = (int)(n) ; i < i##_len ; ++i)
#define rep(i, n) for(int i = 0, i##_len = (int)(n) ; i < i##_len ; ++i)
#define reps(i, n) for(int i = 1, i##_len = (int)(n) ; i <= i##_len ; ++i)
#define rrep(i, n) for(int i = (int)(n) - 1 ; i >= 0 ; --i)
#define rreps(i, n) for(int i = (int)(n) ; i > 0 ; --i)
#define SORT(x) sort((x).begin(), (x).end())
#define SORT_INV(x) sort((x).rbegin(), (x).rend())

const int IINF = (1 << 30) - 1;
const long long LLINF = 1LL << 61;
const long long MOD = 1000000007LL;
const int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
const int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};
const double EPS = 1e-8;

template<typename T>
bool chmax(T &_a, T _b){
    if(_a < _b){
        _a = _b;
        return true;
    }else{
        return false;
    }
}

template<typename T>
bool chmin(T &_a, T _b){
    if(_a > _b){
        _a = _b;
        return true;
    }else{
        return false;
    }
}

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

    int h, w;
    cin >> h >> w;

    vector<string> a(h);
    queue< pair<P, int> > que;
    vector< vector<int> > cost(h, vector<int>(w, IINF));
    rep(i, h){
        cin >> a[i];
        rep(j, w){
            if(a[i][j] == '#'){
                que.push({{i, j}, 0});
                cost[i][j] = 0;
            }
        }
    }

    while(!que.empty()){
        pair<P, int> now = que.front();
        que.pop();
        if(cost[now.first.first][now.first.second] < now.second){
            continue;
        }
        cost[now.first.first][now.first.second] = now.second;
        rep(i, 4){
            int ny = now.first.first + dy4[i], nx = now.first.second + dx4[i];
            if(0 <= ny && ny < h && 0 <= nx && nx < w && chmin(cost[ny][nx], now.second + 1)){
                que.push({{ny, nx}, now.second + 1});
            }
        }
    }

    int ans = 0;
    rep(i, h){
        rep(j, w){
            chmax(ans, cost[i][j]);
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 17424
import math
N, K = tuple(map(int, input().split()))
base = 1 / N

if N == K:
  s = base
  end = K
elif N > K:
  s = (N-K+1) / N
  end = K
else:
  s = 0
  end = N+1
for i in range(1, end):
  n = math.ceil(math.log2(K/i))
  s += base * (0.5 ** n)
print(s)

Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue> 
#include <stack>
#include <set>
#include <list>

using namespace std;
typedef long long ll;
#define rep(i, s, e) for (int(i) = (s); (i) <= (e); ++(i))
#define all(x) x.begin(),x.end()


int main()
{
	int n; cin >> n;
	int ans = 0;
	rep(i, 1, n)
	{
		if (floor(i*1.08) == n)ans = i;
	}
	if (ans == 0)cout << ":(" << endl;
	else cout << ans << endl;
}


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

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

#define REP(i, l, n) for(int i=(l), i##_len=(n); i<i##_len; ++i)
#define ALL(x) (x).begin(),(x).end()
#define pb push_back

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

char alpha[26] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};

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

int main(){
    int n; cin >> n;
    vector<ll> lis(n);
    REP(i, 0, n){cin >> lis[i];}
    reverse(ALL(lis));
    if(lis[0] == 2){
        ll mi = 2, ma = 3;
        REP(i, 1, n){
            ll prema = ma, premi = mi;
            mi = lis[i] * ((mi + (lis[i]-1)) / lis[i]);
            ma = max(mi + (lis[i]-1), (ma/lis[i])*lis[i] + (lis[i]-1) );
            if(ma < premi || mi < premi || (prema+1) <= mi){
                cout << -1 << endl;
                return 0;
            }
        }
        cout << mi << " " << ma << endl;
    }else if(lis[0] == 1){
        ll mi = 2, ma = 2;
        REP(i, 1, n){
            ll prema = ma, premi = mi;
            mi = lis[i] * ((mi + (lis[i]-1)) / lis[i]);
            ma = max(mi + (lis[i]-1), (ma/lis[i])*lis[i] + (lis[i]-1) );
            if(ma < premi || mi < premi || (prema+1) <= mi){
                cout << -1 << endl;
                return 0;
            }
        }
        cout << mi << " " << ma << endl;
    }else{
        cout << -1 << endl;
        return 0;
    }
}

Measured memory_bytes: 1024
///HELLO EVERYONE! TODAY I FEEL SO GOOD :)
#include <bits/stdc++.h>
using namespace std;
#define reset(x) memset(x, 0,sizeof(x))
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define Task "agc040"
#define maxn 500005
#define MOD 1000000007
#define pii pair<int, int>
#define endl "\n"
int n,L[maxn],R[maxn],dem;
long long res;
string s;
main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
//    freopen(Task".inp", "r", stdin);
//    freopen(Task".out", "w", stdout);
    cin >> s;
    n=s.size();
    for(int i=0; i<n; ++i)
    {
        if(s[i]=='<') dem++;
        else dem=0;
        L[i+1]=dem;
    }
    dem=0;
    for(int i=n-1; i>=0; --i)
    {
        if(s[i]=='>') dem++;
        else dem=0;
        R[i]=dem;
    }
    for(int i=0; i<=n; ++i)
        res+=max(L[i],R[i]);
  cout<<res;
}


Measured memory_bytes: 4764
#include <bits/stdc++.h>
typedef long long LL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

using namespace std;

int main(void)
{
  int n;
  cin >> n;
  vector<int> a(n+2 ,0);
  REP(i,n) cin >> a[i+1];
  int sum = 0;
  REP(i, n+1) sum+=abs(a[i]-a[i+1]);
  REP(i, n) {
    int answer = sum;
    answer += abs(a[i+2]-a[i]) - abs(a[i+2]-a[i+1]) - abs(a[i+1]-a[i]);
    cout << answer << endl;
  }
  return 0;
}


Measured memory_bytes: 1664