akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define all(a) a.begin(), a.end()
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,int> pli;
typedef pair<int,int> pii;
#define rep(i,a,b) for(ll i=a ; i<b ; i++)
#define qrep(que, ite) for(auto ite=begin(que) ; ite!=end(que) ; ite++)
const int max_n = 1e5;
const ll mod = 1e9+7;
const ll INF = 1e17;
const int inf = 1e5;
typedef long double ld;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
ll gcd(ll a, ll b) { return a ? gcd(b%a, a) : b; }
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
ll mo = 998244353;
struct UnionFind {
    vector<int> par;

    UnionFind(int n) : par(n, -1) { }
    void init(int n) { par.assign(n, -1); }

    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }

    bool issame(int x, int y) {
        return root(x) == root(y);
    }

    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y); // merge technique
        par[x] += par[y];
        par[y] = x;
        return true;
    }

    int size(int x) {
        return -par[root(x)];
    }
};
struct SegmentTree{
  int N;
  vector<int> node;
  public :
    void intit(vector<int>v){
      int sz = v.size();
      N=1;
      while(N<sz) N*=2;
      node.resize(N);
      for(int i=0 ; i<sz ; i++) node[i+N-1] = v[i];
      for(int i=N-2 ; i>=0 ; i--) node[i] = min(node[i*2+1], node[i*2+2]);
    }
    void update(int x, int val){
      x += N-1;
      node[x+N-1] = val;
      while(x>0){
        x = (x-1)/2;
        node[x] = min(node[x*2+1], node[x*2+2]);
      }
    }
    int getmin(int a, int b, int k, int l, int r){
      if(b<=l || r<=a) return inf;
      else if(a<=l && r<=b) return node[k];
      else{
        int vl = getmin(a, b, 2*k+1, l, (l+r)/2);
        int vr = getmin(a, b, 2*k+2, (l+r)/2, r);
        return min(vl, vr);
      }
    }
};
int main(){
  int N,K;  cin>>N>>K;
  vector<int> d(N);
  rep(i,0,N) cin>>d[i];
  sort(all(d));
  ll sum=0;
  rep(i,0,K){
    sum += d[i];
  }
  cout<<sum<<endl;
  return 0;
}


Measured memory_bytes: 3612
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    int a[n];
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    int q;
    cin >> q;
    int m[q];
    for (int i = 0; i < q; i++)
    {
        cin >> m[i];
    }

    bool can[q][n+1][*max_element(m, m + q) + 1] = {};
    for (int i = 0; i < q; i++)
    {
        can[i][0][0] = true;
    }
    
    for (int i = 0; i < q; i++)
    {
        for (int j = 0; j < n; j++)
        {
            for (int k = 0; k <= m[i]; k++)
            {
                can[i][j+1][k] |= can[i][j][k];
                if(k >= a[j]) can[i][j+1][k] |= can[i][j][k-a[j]];
            }
        }
    }
    
    for (int i = 0; i < q; i++)
    {
        if(can[i][n][m[i]]) cout << "yes" << endl;
        else cout << "no" << endl;
    }
    
}


Measured memory_bytes: 11224
from itertools import accumulate
N = int(input())
Alist = [[0] + list(accumulate(list(map(int, input().split())))) for _ in range(2)]
ans = 0
for i in range(N):
    ans = max(ans, Alist[0][i + 1] + Alist[1][-1] - Alist[1][i])
print(ans)


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

from collections import deque
import itertools as it
import sys
import math

sys.setrecursionlimit(1000000)

INF = 10 ** 18

N = input()
v = map(int, raw_input().split())

cnt1 = [0] * 110000
cnt2 = [0] * 110000

for i in range(0, N, 2):
    cnt1[v[i]] += 1
    cnt2[v[i + 1]] += 1

v1, v2 = [], []
for i in range(110000):
    v1.append((cnt1[i], i))
    v2.append((cnt2[i], i))

v1.sort(reverse = True)
v2.sort(reverse = True)

if v1[0][1] != v2[0][1]:
    print N - v1[0][0] - v2[0][0]
else:
    print N - max(v1[1][0] + v2[0][0], v1[0][0] + v2[1][0])


Measured memory_bytes: 30536
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
int main(){
    int N, K; cin>>N>>K;
    vector<int> h(N,0); for(int i =0 ; i < N; i++) cin>>h[i];
    vector<int> dp(N,1e9);
    dp[0] = 0;
    for(int i = 1; i < N; i++){
	for(int j = 1; j <= min(K, i); j++){
	    dp[i] = min(dp[i], dp[i-j] + abs(h[i]-h[i-j]));
	}
    }
    cout<<dp[N-1]<<endl;
}


Measured memory_bytes: 1024
import sys
import numpy as np
input = sys.stdin.readline

def main():
    s = input().strip()

    count = np.zeros((len(s), ord("z") - ord("a") + 1), dtype=int)
    s_ = [0] * len(s)
    s_[0] = ord(s[0]) - ord("a")
    count[0][s_[0]] += 1
    for i in range(1, len(s)):
        s_[i] = ord(s[i]) - ord("a")
        count[i] += count[i-1]
        count[i][s_[i]] += 1
    
    ans = 0
    for i in range(len(s)-1):
        tmp = len(s) - i - 1 - (count[-1, s_[i]] - count[i, s_[i]])
        ans += tmp
    print(ans+1)

if __name__ == "__main__":
    main()

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

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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))

int dx4[4] = {1,0,-1,0}, dy4[4] = {0,1,0,-1};

int main(){
    ll n,a,b,c,d;
    string s;
    cin>>n>>a>>b>>c>>d>>s;
    a--;
    b--;
    c--;
    d--;
    bool ok=true;
    for (ll i = a; i < c; i++)
    {
        if(s[i]=='#' && s[i+1]=='#')
        {
            ok=false;
            break;
        }
    }
    for (ll i = b; i < d; i++)
    {
        if(s[i]=='#' && s[i+1]=='#')
        {
            ok=false;
            break;
        }
    }
    if(ok && d<c)
    {
        bool nukaseru = false;
        for (int i = b; i <= d; i++)
        {
            if(s[i-1]=='.' && s[i]=='.' && s[i+1]=='.')
            {
                nukaseru = true;
                break;
            }
        }
        if(nukaseru==false)
        {
            ok=false;
        }
    }

    if(ok) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;

    return 0;
}

Measured memory_bytes: 640
def resolve():
    n, m = map(int, input().split())
    ab = [list(map(int, input().split()))for i in range(m)]
    ans = [0] * n
    edge = [[]for _ in range(n)]
    for a, b in ab:
        edge[a - 1].append(b - 1)
        edge[b - 1].append(a - 1)
    visited = {0}
    stack = [0]
    for i in stack:
        for j in edge[i]:
            if j in visited:
                continue
            stack.append(j)
            visited.add(j)
            ans[j] = i + 1
    print("Yes")
    print('\n'.join(map(str, ans[1:])))


resolve()

Measured memory_bytes: 85436
fun main(args: Array<String>) {
    val m = readLine()!!.toInt()
    var cSum = 0L
    var dSum = 0L
    (1..m).forEach {
        val (d, c) = readLine()!!.split(' ').map(String::toLong)
        cSum += c
        dSum += c * d
    }
    println(cSum - 1 + (dSum-1) / 9)
}

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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> ii;
typedef map<int, int> MPII;
typedef set<int> SETI;

const int mxN = 2e5;
const ld pi = 4.0 * atanl(1.0);
const int iinf = 1e9 + 10;
const int inf = 1e18 + iinf + 10;
const int mod = 1000000007;
const ld prec = .000001;

#define F first
#define S second
#define pb push_back
#define mp make_pair
#define all(c) c.begin(), c.end()
#define rall(c) c.end(), c.begin()

int A, B, M, x, y, c, a[mxN], b[mxN];

void fast() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); }

int main() {
  fast();
  cin >> A >> B >> M;
  int mnA = mxN, mnB = mxN;
  for (int i = 0; i < A; ++i) {
    cin >> a[i];
    mnA = min(a[i], mnA);
  }
  for (int i = 0; i < B; ++i) {
    cin >> b[i];
    mnB = min(b[i], mnB);
  }

  int mn = mxN;
  for (int i = 0; i < M; ++i) {
    cin >> x >> y >> c;
    mn = min((a[x - 1] + b[y - 1]) - c, mn);
  }

  if (mnB + mnA < mn)
    cout << mnB + mnA;
  else
    cout << mn;

  return 0;
}



Measured memory_bytes: 4400
import java.util.Scanner;

public class Main {

	@SuppressWarnings("resource")
	public static void main(String args[]) {
		Scanner scanner = new Scanner(System.in);
		int k = scanner.nextInt();
		int s = scanner.nextInt();

		int ans = 0;
		for (int x = 0; x <= k; x++) {
			for (int y = 0; y <= k; y++) {
				if (0 <= s - x - y && s - x - y <= k) {
					ans++;
				}
			}
		}

		System.out.println(ans);
	}
}

Measured memory_bytes: 22740
#include <iostream>
#include <algorithm>
#include <set>
#include <utility>

using namespace std;

typedef pair <int, int> pii;

pii A[100000];

int main() {
    int n, m; cin >> n >> m;
    for(int i = 0; i < n; ++i)
        cin >> A[i].first >> A[i].second;
    int mx = 0;
    set <int> box;
    for(int i = 1; i <= m; ++i)
        box.insert(i);
    
    sort(A, A + n, [](pii& x, pii& y) -> bool {
        return x.second > y.second;
    });
    
    for(int i = 0; i < n; ++i)
        if(box.lower_bound(A[i].first) != box.end()) {
            mx += A[i].second;
            box.erase(box.lower_bound(A[i].first));
        }
        
    cout << mx;
    
    return 0;
}

Measured memory_bytes: 5760
#include<stdio.h>
int main(void){
  int n,w,a[100];
  int x,y,z=0,i;
  scanf("%d",&n);
  scanf("%d",&w);
  for(i=1;i<=n;i++)
    a[i]=i;
  for(i=0;i<w;i++){
    scanf("%d,%d",&x,&y);
    z=a[x];
    a[x]=a[y];
    a[y]=z;
  }
  for(i=1;i<=n;i++)
    printf("%d\n",a[i]);
  return(0);
}

Measured memory_bytes: 596
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
using namespace std;
#define REP(i,n) for(int i=0;i<n;i++)
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
	
	int A,B,C;
	cin>>A>>B>>C;
	
	if(A==(B+C) || B==(A+C) || C==(A+B))
		cout<<"Yes"<<endl;
	else
		cout<<"No"<<endl;
			
	return 0;
}

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

int main() {
  int add = 10;
  int ans = 0;
  for(int i = 0; i < 5; i++){
   	int temp; cin >> temp;
    int mod = temp % 10;
	ans += temp - temp%10;
    
	if(mod != 0) {
      ans += 10;
      add = min(add, mod);
    }
  }
  
  ans -= (10 - add);
  
  cout << ans << endl;
  
  
  return 0; 
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
 
using namespace std;
 
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl;
#define DEBUG_MAT(v) cerr<<#v<<endl;for(int i=0;i<v.size();i++){for(int j=0;j<v[i].size();j++) {cerr<<v[i][j]<<" ";}cerr<<endl;}
typedef long long ll;
// #define int ll
 
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(int)(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.end()
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 (a>b) { a = b; return 1; } return 0; }
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = (ll)1e18 + 1;
const long double pi = 3.1415926535897932384626433832795028841971L;
#define Sp(p) cout<<setprecision(25)<< fixed<<p<<endl;
// int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
// int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
vi dx = {1, 0, -1, 0}, dy = {0, 1, 0, -1};
// vi dx2 = { 1,1,0,-1,-1,-1,0,1 }, dy2 = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
const ll MOD = 1000000007;
// const ll MOD = 998244353;
// #define mp make_pair
//#define endl '\n'



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

    int f = 0, t = 0, o = 0;
    rep (i, n) {
        if (a[i] % 4 == 0) f++;
        else if (a[i] % 4 == 2) t++;
        else o++;
    }

    if (t == 0) {
        if (o <= f + 1) {
            cout << "Yes" << endl;
        }
        else {
            cout << "No" << endl;
        }
    }
    else {
        if (o <= f) {
            cout << "Yes" << endl;
        }
        else {
            cout << "No" << endl;
        }
    }
}

Measured memory_bytes: 3936
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author silviase
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        DWeLikeAGC solver = new DWeLikeAGC();
        solver.solve(1, in, out);
        out.close();
    }

    static class DWeLikeAGC {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            ModInt[][] dp = new ModInt[n + 1][64];
            ModInt[] tmp = new ModInt[64];
            ModInt res = new ModInt(0);

            for (int i = 0; i < 64; i++) {
                if (i == 6 || i == 9 || i == 33) {
                    dp[3][i] = new ModInt(0);
                } else {
                    dp[3][i] = new ModInt(1);
                }
            }

            for (int i = 3; i < n; i++) {
                Arrays.fill(tmp, new ModInt(0));
                for (int j = 0; j < 64; j++) {
                    for (int k = 0; k < 4; k++) {
                        if ((j / 4 == 2 || (j / 16 == 0 && j % 4 == 2)) && k == 1) {
                            continue;
                        }
                        tmp[(j * 4 + k) % 64] = tmp[(j * 4 + k) % 64].add(dp[i][j]);
                    }
                }

                for (int j = 0; j < 64; j++) {
                    if (j != 33 && j != 6 && j != 9) {
                        dp[i + 1][j] = tmp[j];
                    } else {
                        dp[i + 1][j] = new ModInt(0);
                    }
                }
            }


            for (int i = 0; i < 64; i++) {
                res = res.add(dp[n][i]);
            }

            out.println(res.getVal());


        }

    }

    static class ModInt {
        long val;
        int MOD = (int) 1e9 + 7;

        public ModInt(long i) {
            this.val = (i + MOD) % MOD;
        }

        public ModInt add(ModInt m) {
            return new ModInt(this.val + m.getVal());
        }

        public long getVal() {
            return val;
        }

        public String toString() {
            return Long.toString(val);
        }

    }
}



Measured memory_bytes: 23764
n = int(input())
a = list(map(int, input().split()))
flg = True
for i in range(n) :
    if a[i] % 2 == 0 :
        if (a[i] % 3 != 0 and a[i] % 5 != 0) :
            flg = False
if flg :
    print("APPROVED")
else :
    print("DENIED")

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <set>
#define ll long long 
#include <string>
#define pb push_back
#define mp make_pair
# define pi 3.14159265358979323846
#define mod 1000000007
#define rep(i,n) for(i=0;i<n;i++)
using namespace std;
void fastio()
{					
	#ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w", stdout);
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

}
ll int multiply(ll int a,ll int b)
{
	ll int ans=(a%mod*b%mod)%mod;
	return ans;
}
ll int add(ll int a, ll int b)
{
	ll int ans=(a%mod+b%mod)% mod;	
	return ans;
}


ll int dp[100001][3];
ll int c[100001][3];
void solve()
{
	ll int  n;
	cin>>n;
	memset(dp,0,sizeof dp);
	ll int i,j;
	rep(i,n)
	rep(j,3)
	cin>>c[i][j];
	// func(n-1,0);
	// func(n-1,1);
	// func(n-1,2);
	for(i=0;i<n;i++)
	{
		for(j=0;j<3;j++)
		{
			if (i==0)
			{
				
					dp[i][j]=max(dp[i][j],c[i][j]);

			}
			else
			{
				for(int k=0;k<3;k++)
				{
					if (j!=k)
					{
						dp[i][j]=max(dp[i][j],c[i][j]+dp[i-1][k]);
					}
				}
			}
		}
	}
	ll int ans=0;
	ans=max(ans,dp[n-1][0]);
	ans=max(ans,dp[n-1][1]);
	ans=max(ans,dp[n-1][2]);
	cout<<ans<<endl;

		
}
int  main()
{
	fastio();
	ll int t;
	t=1;
	// cin>>t;
	while(t--)
	{
		solve();
	}
	

}




Measured memory_bytes: 8264
from itertools import permutations

dishes = [int(input()) for _ in range(5)]

minT = 10000
for sample in permutations(dishes, 5):
    t = 0
    for dish in sample:
        if t%10 != 0:
            t += 10 - t%10
        t += dish
    minT = min(minT, t)
print(minT)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)

ll mod = 1e09;

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

  ll n;
  double t, a;
  cin >> n >> t >> a;
  double h[n];

  double dif = 100000;
  ll ans;

  REP(i, n){
    cin >> h[i];
    double p = t - 0.006 * h[i];
    if(abs(p - a) < dif){
      dif = abs(p - a);
      ans = i + 1;
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
using namespace std;
void read(int& x){ scanf("%d",&x); }
void read(long long& x){ scanf("%lld",&x); }
template<typename T,typename... Args> void read(T& a,Args&... b){ read(a); read(b...); }
int n, x;

int a[2010];

int mv[2010][2010];
typedef long long ll;

int main()
{
    read(n, x);
    for(int i=1; i<=n; ++i){
        read(a[i]);
        mv[i][i]=a[i];
    }
    for(int i=1; i<n; ++i){
        int ns = 1;
        for(int s=1; s<=n; ++s){
            ns = ns%n+1;
            int y = (s+i-1)%n+1;
            mv[s][y] = min(a[s], mv[ns][y]);
        }
    }
    ll ans = (1LL<<60);
    for(int i=0; i<=n; ++i){
        ll cs = 0;
        for(int j=1; j<=n; ++j){
            int rev = (j+n-i+n-1)%n + 1;
            cs += mv[rev][j];
        }
        ans = min(ans, cs + i*1LL*x);
    }
    printf("%lld\n", ans);
    return 0;
}


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

using namespace std;

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

	int k;
	int s;
	vector<int> masks(m, 0);
	for (int i = 0; i < m; i++) {
		cin >> k;
		for (int j = 0; j < k; j++) {
			cin >> s;
			masks[i] |= 1 << (s - 1);
		}
	}

	vector<int> p(m, 0);
	for (int i = 0; i < m; i++) {
		cin >> p[i];
	}

	int ans = 0;
	for (int i = 0; i < (1 << n); i++) {
		bool is_on = true;

		for (int j = 0; j < m; j++) {

			if(__builtin_popcount(i & masks[j]) % 2 != p[j]) {
				is_on = false;
				break;
			}
		}

		if (is_on) {
			ans++;
		}
	}

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


Measured memory_bytes: 384
fun main(args: Array<String>) {
    fun calcFactors(n: Int): Map<Int, Int> {//素因数分解
        val factors = mutableMapOf<Int, Int>()
        var tmp = n
        var i = 2
        while (i * i <= tmp) {
            while (tmp % i == 0) {
                factors[i] = factors.getOrElse(i) { 0 } + 1
                tmp /= i
            }
            i++
        }
        if (tmp > 1) factors[tmp] = 1
        return factors
    }

    fun calcCombination(n: Long, r: Long, modNum: Long = 1L): Long {
        val tr = if (n - r < r) n - r else r
        if (tr == 0L) return 1
        if (tr == 1L) return n
        val numerator = (0 until r).map { n - tr + it + 1 }.toMutableList()
        val denominator = (0 until r).map { it + 1 }.toMutableList()

        for (p in 2..tr.toInt()) {
            val pivot = denominator[p - 1]
            if (pivot > 1) {
                val offset = (n - tr) % p
                for (k in p - 1 until r step p.toLong()) {
                    numerator[(k - offset).toInt()] /= pivot
                    denominator[k.toInt()] /= pivot
                }
            }
        }
        var result = 1L
        for(k in 0 until r){
            if(numerator[k.toInt()]>1){
                result *= numerator[k.toInt()]
                result %= modNum

            }
        }
        return result
    }

    val mod = 1000000007L
    val (n, m) = readLine()!!.split(' ').map(String::toLong)
    val factors = calcFactors(m.toInt())

    var ans = 1L
    for ((key, value) in factors) {
        ans *= calcCombination(value + n - 1, value.toLong(), mod)
        ans %= mod
    }
    println(ans)
}

Measured memory_bytes: 38216
import math

def prime_detector(num):
    sqrt = int(math.sqrt(num))
    if any(num % i == 0 for i in range(2,sqrt+1)): return False
    else: return True
    
def main():

    number = int(input())
    
    numbers_tuple = tuple(int(input()) for i in range(number))
    
    print(sum(prime_detector(n) for n in numbers_tuple))

main()

Measured memory_bytes: 8104
import collections
n, m = [int(i) for i in input().split()]
ps = [[i for i in input().split()] for _ in range(m)]

fails = collections.defaultdict(int)
acstatus = collections.defaultdict(bool)

successct, failct = 0,0
for p, s in ps:
    if s == "AC":
        if not acstatus[p]:
            failct += fails[p]
            acstatus[p] = True
            successct += 1
    else:
        fails[p] += 1
print(successct, failct)

Measured memory_bytes: 41652
#include <iostream>
#include <vector>
#include <cstdlib>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const long long INF = 1LL << 60;

// 入力
int n, m;
vector<vector<int> > G;

int dp[100100];
int record(int v) {
    if (dp[v] != -1) return dp[v];
    
    int res = 0;
    for (auto nv : G[v]) {
        chmax(res, record(nv) + 1);
    }
    return dp[v] = res;
}

int main() {
    cin >> n >> m;
    // 初期化 (最大問題なので 0 に初期化)

    // 初期条件
    G.assign(n,vector<int>());
    // ループ
    for (int i = 0;i < m;i++) {
        int x,y; cin >> x >> y;
        --x;--y;
        G[x].push_back(y);
    }

    for (int i = 0;i<n;i++) dp[i] = -1;

    int res = 0;
    for (int v = 0; v < n; v++) chmax(res, record(v));
    // 答え
    cout << res << endl;
}

Measured memory_bytes: 8192
//AUTHOR: RAVAN_2070
//PUNE INSTITUTE OF COMPUTER TECHNOLOGY
/*                                                    
      I ♥ CLARICE STARLING...                                                               
        EXPLAINATION BELOW->
       Same as Editorial
*/
//F-Intervals on Tree
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vi;
typedef vector<pair<ll,ll>> vii;
typedef pair<ll,ll> pii;
typedef map<ll,ll> mii;
#define MOD7 1000000007
#define MOD9 1000000009
#define pi 3.1415926535
#define Test_cases ll TC;cin>>TC;while(TC--)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(), x.rend()
#define sp(x) fixed<<setprecision(x)
#define sz(x) (ll)(x.size())
#define fo(i,a,b) for(i=a;i<b;i++)
#define foe(i,a,b) for(i=a;i<=b;i++)
const ll INF = (ll)2e18 + 77;
void solve()
{
   ll n,i,u,v;cin>>n;
   ll edge,vertex;
   edge=vertex=0;
   fo(i,0,n-1)
   {
       cin>>u>>v;
       if(u>v)swap(u,v);
       edge+=u*(n+1-v);
   }
   foe(i,1,n)vertex+=(i)*(n+1-i);
   cout<<vertex-edge<<"\n";
}
int main()
{
   fastio
   //Test_cases
   solve();
  return 0;
}
//map<ll,ll,greater<int>> to sort in descending order ,in iterator declaration no greater<int>
//if you want to apply lowerbound on set use s.lower_bound(key),not the one used for vector
// Syntax to create a min heap for priority queue priority_queue <int, vector<int>, greater<int>>; 
//for modinverse use modularexponention(x,M-2,M);
//for "each" subtraction from ans(ans-k) if(ans<0) do ans+=MOD,ans%=MOD
//vector<vector<int>>dp(201,vector<int>(n+1)); A way to initialize vector of vector
//If wrong on pretest 2 means logically wrong


/* TIPS FOR DEBUGGING
 * Check if values are not overflowing (use long long where required)
 * Check if ranges are inclusive or not.
 * Check properly if greedy will work or not before using it.
 * Check EDGE CASES!! Seriously, even in 2B, saving 8 points by being
 * 2 minutes faster will bite you in the ass if you don't make sure
 * it works on edge cases.
 * Keep adding to this list.
*/


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#define repl(i, l, r) for (ll i = (l); i < (r); i++)
#define rep(i, n) repl(i, 0, n)
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define CST(x) cout << fixed << setprecision(x)
using ll = long long;
const ll MOD = 1000000007;
const int inf = 1e9 + 10;
const ll INF = 4e18 + 10;
const int dx[9] = {1, 0, -1, 0, 1, -1, -1, 1, 0};
const int dy[9] = {0, 1, 0, -1, 1, 1, -1, -1, 0};
int main() {
	cin.tie(0);
	cout.tie(0);
	ios::sync_with_stdio(false);

	int n;
	cin >> n;
	int now = 7, cnt = 1;
	rep(i, 1000000) {
		if (now % n == 0) {
			cout << cnt << endl;
			return 0;
		}
		now = (now * 10 + 7) % n;
		cnt++;
	}
	cout << -1 << endl;
	return 0;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
#define ll long long int

using namespace std;

const ll mod=1000000007;
const ll inf=1e18;

int main(){

  double n;
  cin >> n;
  if((ll)(n/1)%2==0)cout << 0.5 << endl;
  else if(n==1) cout << 1 << endl;
  else{
    printf("%.12f",(n+1)/(2*n));
  }

}

Measured memory_bytes: 3772
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
int main()
{
    fast;
    char a[7];
    cin>>a;
    if(a[2]==a[3] && a[4]==a[5])
        cout<<"Yes";
    else
        cout<<"No";
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;
long long runrun[10][10]; // m+1けた、最大けたがnのルンルン個数
long long lrun[10]; // m+1けたまでのルンルン個数
int main() {
    long long K;
    cin >> K;

    for (int i=0; i<10; i++) {
        runrun[0][i] = 1;
    }
    lrun[0] = 9;

    for (int m=1; m<10; m++) {
        for (int n=0; n<10; n++) {
            if (n>0) runrun[m][n] += runrun[m-1][n-1];
            runrun[m][n] += runrun[m-1][n];
            if (n<9) runrun[m][n] += runrun[m-1][n+1];
        }
        lrun[m] = lrun[m-1];
        for (int n=1; n<10; n++) lrun[m] += runrun[m][n];
    }

    int answer[10] = {0};
    bool leading = true;
    long long size = 0;
    for (int m=9; m>=1; m--) {
        if (leading) {
            size = lrun[m-1];
            if (size >= K) {
                size = 0;
                answer[m] = 0;
            }
            else {
                leading = false;
                for (int n=1; n<10; n++) {
                    size += runrun[m][n];
                    if (size >= K) {
                        size -= runrun[m][n];
                        answer[m] = n;
                        break;
                    }
                }
            }
        } else {
            for (int n=max(answer[m+1]-1,0); n<=answer[m+1]+1 && n < 10; n++) {
                size += runrun[m][n];
                if (size >= K) {
                    size -= runrun[m][n];
                    answer[m] = n;
                    break;
                }
            }
        }
    }

    if (leading) answer[0] = K;
    else {
        answer[0] = K - size + max(0, answer[1]-1) - 1;
    }
    bool ll = true;
    for (int m=9; m>=0; m--) {
        if (ll && answer[m] == 0) continue;
        ll = false;
        cout << answer[m];
    }
    cout << endl;
    
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <unordered_map>
#include <unordered_set>

using namespace std;
using ll = long long;

constexpr int MaxN = 100000 + 10;
int n;
ll a, b;
ll H[MaxN];

ll Solve() {
    ll lower = 0, upper = 0;
    for (int i = 0; i < n; i++) {
        upper += (H[i] - 1) / b + 1;
    }
    upper += 10;

    while (lower < upper) {
        //cout << lower << " " << upper << endl;

        ll middle = (lower + upper) / 2;
        ll count = 0;
        for (int i = 0; i < n; i++) {
            ll remain = H[i] - b * middle;
            if (remain > 0) {
                count += (remain - 1) / (a - b) + 1;
            }
        }

        //cout << count << endl;

        if (count > middle) {
            lower = middle + 1;
        } else {
            upper = middle;
        }
    }

    return lower;
}

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

    ll ans = Solve();
    cout << ans << endl;
}

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

int main(){
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  int L = A + B;
  int R = C + D;
  if ( L > R ){
    cout << "Left" << endl;
  }
  else if ( L == R ){
    cout << "Balanced" << endl;
  }
  else{
    cout << "Right" << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0);cin.tie(0);
#define X first
#define Y second
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define All(x) x.begin() , x.end()
#define mem(aa,x) memset(aa,x,sizeof aa)
#define pb push_back
#define INF 1e18
typedef long long ll;
typedef pair<int,int> ii;
const int maxn=4e5+5;

main(){IOS
	ll n,x,y;
	cin>>n;
	n--;
	cin>>x>>y;
	while(n--){
		ll cx,cy,t1x,t1y,t2x,t2y;
		cin>>cx>>cy;
		//t1
		if(x%cx==0){
			t1x=x;
			t1y=t1x/cx*cy;
			if(t1y<y) t1x=t1y=INF;
		}
		else{
			t1x=x+(cx-x%cx);
			t1y=t1x/cx*cy;
			if(t1y<y) t1x=t1y=INF;
		}
		//t2
		if(y%cy==0){
			t2y=y;
			t2x=t2y/cy*cx;
			if(t2x<x) t2x=t2y=INF;
		}
		else{
			t2y=y+(cy-y%cy);
			t2x=t2y/cy*cx;
			if(t2x<x) t2x=t2y=INF;
		}
		
		if(t1x+t1y<t2x+t2y){
			x=t1x;
			y=t1y;
		}
		else{
			x=t2x;
			y=t2y;
		}
	}
	cout<<x+y<<"\n";
}


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

#define debug(s) cout << s << endl
#define debug1(s, t) cout << s << " " << t << endl

using namespace std;
using i64 = long long;

i64 p = 1000000007LL;

i64 powmod(i64 x, i64 y)
{
    if (y == 1)
        return x % p;
    if (y % 2 == 0)
    {
        i64 pwmd = powmod(x, y / 2) % p;
        return (pwmd * pwmd) % p;
    }
    else
    {
        return (x * powmod(x, y - 1)) % p;
    }
}

i64 bicomod(int n, int a)
{
    if (n == a)
        return 1;
    if (a > n / 2)
        return bicomod(n, n - a);
    i64 anom = 1;
    i64 adom = 1;
    for (int i = 1; i <= a; i++)
        anom = anom * i % p;
    for (int i = n - a + 1; i <= n; i++)
        adom = adom * i % p;

    return (adom * powmod(anom, p - 2)) % p;
}

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

    i64 ca = bicomod(n, a);
    i64 cb = bicomod(n, b);


    i64 ans = powmod(2LL, n) - ca - cb - 1;
    while (ans < 0)
        ans += p;

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>

int main() {
  float l, r;

  int a_l = 0;
  int a_r = 0;
  int b_l = 0;
  int b_r = 0;
  int c_l = 0;
  int c_r = 0;
  int d_l = 0;
  int d_r = 0;

  while (std::cin >> l >> r) {
    if (1.1 <= l) {
      ++a_l;
    } else if (0.6 <= l) {
      ++b_l;
    } else if (0.2 <= l) {
      ++c_l;
    } else {
      ++d_l;
    }

    if (1.1 <= r) {
      ++a_r;
    } else if (0.6 <= r) {
      ++b_r;
    } else if (0.2 <= r) {
      ++c_r;
    } else {
      ++d_r;
    }
  }

  std::cout << a_l << " " << a_r << std::endl;
  std::cout << b_l << " " << b_r << std::endl;
  std::cout << c_l << " " << c_r << std::endl;
  std::cout << d_l << " " << d_r << std::endl;
  return 0;
}



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

using namespace std;

#define sp(x) cout<<setprecision(x);
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define all(a) (a).begin(), (a).end()
#define inf 10000000
#define linf INT64_MAX*0.99
#define print(s) cout<<(s)<<endl
#define lint long long
#define yes "Yes"
#define no "No"

typedef pair<int, int> P;
 
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m; cin>>n>>m;
    vector<lint> l(m), r(m);
    REP(i,m){
        cin>>l[i]>>r[i];
    }
    sort(all(l),greater<lint>());
    sort(all(r));
    if(r[0]-l[0]>=0) print(r[0]-l[0]+1);
    else print(0);
    return 0;
}

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

ll gcd(ll x,ll y){
    if (x < y) return gcd(y,x);
    if(y == 0) return x;
    return gcd(y, x%y);
}

int main(){
    ll a,b;
    cin >> a >> b;
    ll ans = (a*b/gcd(a,b));
    cout << ans << endl;
}

Measured memory_bytes: 256
import bisect, collections, copy, heapq, itertools, math, numpy, string
import sys
from bisect import bisect_left, bisect_right, insort
def S(): return sys.stdin.readline().rstrip()
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int, sys.stdin.readline().rstrip().split())
def MS(): return map(str, sys.stdin.readline().rstrip().split())
def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())
# N = I()
# A = [LI() for _ in range(N)]

n = I()
a = n % 10
if a in [2,4,5,7,9]:
    print('hon')
elif a in [0,1,6,8]:
    print('pon')
else:
    print('bon')


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

using namespace std;
typedef long long ll;
using Pll = pair<ll,ll>;

const ll INF = 1LL<<60;
const ll MOD = 1000000007;

//cout << fixed << setprecision(10);

int main() {
    ll N;
    cin >> N;
    vector<ll> A(N),B,C;
    priority_queue<ll> M,P;
    for(int i=0;i<N;i++){
        cin >> A[i];
        if(A[i]>=0){
            B.push_back(A[i]);
        }
        else {
            C.push_back(A[i]);
        }
    }
    if(N==2){
        sort(A.begin(),A.end());
        cout << A[1]-A[0] << endl;
        cout << A[1] << " " << A[0] << endl;
        return 0;
    }

    sort(B.begin(),B.end());
    sort(C.rbegin(),C.rend());

    vector<Pll> Ps;
    
    if(C.size()==0){
        while(B.size()>1){
            if(B[0]==B[B.size()-1]){
                Ps.push_back(Pll(B[0],B[B.size()-1]));
                B[0]=0;
                B.erase(B.end()-1);
            }
            else{
                
                if(B.size()==2){
                    Ps.push_back(Pll(B[B.size()-1],B[0]));
                    cout << B[B.size()-1]-B[0] << endl;
                    for(int i=0;i<Ps.size();i++){
                        cout << Ps[i].first <<" " << Ps[i].second << endl;
                    }
                    return 0;
                }
                Ps.push_back(Pll(B[0],B[B.size()-1]));
                M.push(B[0]-B[B.size()-1]);
                B.erase(B.begin());
                B.erase(B.end()-1);
                break;
            }
        }
    }
    else if(B.size()==0){
        while(C.size()>1){
            if(C[0]==C[C.size()-1]){
                Ps.push_back(Pll(C[0],C[C.size()-1]));
                C[0]=0;
                C.erase(C.end()-1);
            }
            else{
                if(C.size()==2){
                    Ps.push_back(Pll(C[0],C[C.size()-1]));
                    cout << C[0]-C[C.size()-1] << endl;
                    for(int i=0;i<Ps.size();i++){
                        cout << Ps[i].first <<" " << Ps[i].second << endl;
                    }
                    return 0;
                }
                Ps.push_back(Pll(C[0],C[C.size()-1]));
                P.push(C[0]-C[C.size()-1]);
                C.erase(C.begin());
                C.erase(C.end()-1);
                break;
            }
        }
    }
    for(int i=0;i<B.size();i++) P.push(B[i]);
    for(int i=0;i<C.size();i++) M.push(C[i]);


    while(M.size()>0 && P.size()>0){
        ll tmpm,tmpp;
        tmpm=M.top();M.pop();
        tmpp=P.top(),P.pop();
        if(M.size()>=P.size()){
            Ps.push_back(Pll(tmpp,tmpm));
            P.push(tmpp-tmpm);
        }
        else{
            Ps.push_back(Pll(tmpm,tmpp));
            M.push(tmpm-tmpp);
        }
    }
    cout << P.top() << endl;

    for(int i=0;i<Ps.size();i++){
        cout << Ps[i].first <<" " << Ps[i].second << endl;
    }

    

    return 0;
}

Measured memory_bytes: 6772
import java.util.*;
 
public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        long m = sc.nextLong();
        if(n == 1 && m == 1){
            System.out.println(1);
        }else if(n == 1 || m == 1){
            System.out.println(n*m-2);
        }else{
            System.out.println(n*m-(2*m+2*n-4));
        }
    }
}


Measured memory_bytes: 22868
#include <stdio.h>
#define MAX 100005
#define NIL -1
struct Node {
    int p;
    int l;
    int r;
};

struct Node T[MAX];
int n, D[MAX];

void rec( int u, int p ) {
    D[u] = p;
    if (T[u].r != NIL) rec(T[u].r, p);
    if (T[u].l != NIL) rec(T[u].l, p+1);
}

int main(void) {
    int i, j, d, v, c,l, r, u;
    scanf("%d", &n);
    for (i = 0 ; i < n ; i ++) T[i].p = T[i].r = T[i].l = NIL;

    for (i = 0 ; i < n ; i ++) {
        scanf("%d %d",&v, &d);
        for ( j = 0 ; j < d ; j++ ) {
            scanf("%d", &c);
            if (j == 0 ) T[v].l = c;
            else T[l].r = c;
            l = c;
            T[c].p = v;
        }
    }

    for (i = 0 ; i < n ; i ++ ){
        if (T[i].p == NIL ) r = i;
    }
    rec(r, 0);
    
    for (u = 0 ; u < n ; u ++) {

        printf("node %d: parent = %d, depth = %d, ", u, T[u].p, D[u]);

        if ( T[u].p == NIL ) printf("root, ");
        else if (T[u].l == NIL ) printf("leaf, ");
        else printf("internal node, ");

        printf("[") ;
        for ( i = 0 , c = T[u].l; c != NIL ; c = T[c].r, i ++ ) {
            if (i) printf(", ");
            printf("%d",c);
        }

        printf("]\n");
    } 
    return 0;
}

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

#define rep(i, N) for(int (i) = 0; (i) < (N); i++)
#define all(v) v.begin(), v.end()
using i64 = int_fast64_t;

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

    cout << T+S << endl;
}

Measured memory_bytes: 256
n = int(input())
A = [0]*n
B = [0]*n
for i in range(n):
    A[i],B[i]=map(int,input().split())
A.sort()
B.sort()

def median(li):
    if n%2==1:
        return li[n//2]
    else:
        return sum(li[n//2-1:n//2+1])
print(median(B)-median(A)+1)

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

int main(){
  int k, a, b;
  cin >> k >> a >> b;
  if(a%k==0 || b%k==0){
    cout << "OK";
    return 0;
  }
  if(a/k!=b/k){
    cout << "OK";
    return 0;
  }
  cout << "NG";
  return 0;
}

Measured memory_bytes: 3096
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
	int n;
	while(~scanf("%d",&n)){
		int a[25]={0};
		for(int i=0;i<n;i++){
			scanf("%d",&a[i]);
		}
		int ans=0;
		for(int i=1;i<n-1;i++){
			if((a[i]>a[i-1]&&a[i]<a[i+1])||(a[i]<a[i-1]&&a[i]>a[i+1])){
				ans++;
			}
		}
		printf("%d\n",ans);
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
const int inf = 1e9 + 7;
const ll INF = 1e18;
const int mod = 1000000007;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template<typename T> T pow(T a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
ll modpow(ll a, int b, int _mod) { return b ? modpow(a * a % _mod, b / 2, _mod) * (b % 2 ? a : 1) % _mod : 1; }
template<class T> ostream& operator << (ostream& os, const vector<T>& vec) { rep(i, sz(vec)) { if (i) os << " "; os << vec[i]; } return os; }
template<class T, class U> ostream& operator << (ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }
template<typename T >inline istream& operator >> (istream& is, vector<T>& v) { rep(j, sz(v)) is >> v[j]; return is; }
template<class T> inline void add(T &a, int b) { a += b; if (a >= mod) a -= mod; }




void solve();

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout << fixed << setprecision(10);
    
    int T;
    // cin >> T;
    T = 1;
    
    while (T--) {
        solve();
    }
}


// https://atcoder.jp/contests/dp/submissions/3944283
int n;
ll c;
vector<ll> a, dp;

// Convex Hull Trick
ll A(int j) { return -2 * a[j]; }
ll B(int j) { return dp[j] + a[j] * a[j]; }
ll C(int i) { return c + a[i] * a[i]; }
ll f(int j, int x) { return A(j) * x + B(j); }
using pll = pair<ll, ll>;
struct CHT {
    deque<int> d;
    ll get(int x) {
        while (sz(d) >= 2) {
            ll a = f(d[0], x);
            ll b = f(d[1], x);
            if (a <= b) break;
            d.pop_front();
        }
        return f(d[0], x);
    }
    void add(int x2) {
        pll x = pll(A(x2), B(x2));
        while (sz(d) >= 2) {
            pll y = pll(A(d[sz(d) - 1]), B(d[sz(d) - 1]));
            pll z = pll(A(d[sz(d) - 2]), B(d[sz(d) - 2]));
            
            ll a1 = y.F, b1 = y.S, a2 = z.F, b2 = z.S, a3 = x.F, b3 = x.S;
            if ((b3 - b1) * (a2 - a1) >= (a1 - a3) * (b1 - b2)) break;
            d.pop_back();
        }
        d.push_back(x2);
    }
};



void solve() {
    cin >> n >> c;
    
    a.resize(n);
    cin >> a;
    dp.resize(n);
    dp[0] = 0;
    
    CHT d;
    d.add(0);
    
    rep3(i, 1, n) {
        dp[i] = d.get(a[i]) + C(i);
        d.add(i);
    }
    cout << dp[n - 1] << endl;
}


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

int main() {
  
  int n;
  cin >> n;
  
  if ( n < 10){
    cout << n;
  }else if ( n >= 10 && n < 100 ){
    cout << 9;
  }else if ( n >= 100 && n < 1000 ){
    cout << n - 90;
  }else if ( n >= 1000 && n < 10000 ){
    cout << 909;
  }else if ( n >= 10000 && n < 100000 ){
    cout << n - 9090;
  }else if ( n = 100000 ){
    cout << 90909;
  }
  
  cout << endl;
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <vector>
#include <map>
#define ll long long
#define h   "\n"
#define ios
using namespace std;

int main()
{

  int n,ev=0,ans=0;

  cin>>n;

  vector <int> v(n);

  for(int i=0;i<n;i++)
  {
    cin>>v[i];
    if(v[i]%2==0)
        ev++;
  }

  for(int i=0;i<n;i++)
    {
        if(v[i]%2==0)
        {
            if(v[i]%3!=0 && v[i]%5!=0)
             {
                cout<<"DENIED"<<h;
                break;
             }
            else
                ans++;
        }
    }

    if(ans==ev)
        cout<<"APPROVED"<<h;

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>

int main(void){
  char s[30],t[30];
  int i,j,cnt;
  scanf("%s",s);
  strcpy(t,s);
  for(i=0;i<strlen(s);i++){
    cnt=0;
    for(j=0;j<strlen(s);j++){
      if(s[i]==t[j]) cnt++;
    }
    if(cnt!=1){
      printf("no\n");
      return 0;
    }
  }
  printf("yes\n");
  return 0;
}

Measured memory_bytes: 128
# coding: utf-8

s = input()
k = int(input())

not_one_index = 0
for i in range(len(s)):
    if s[i] == '1':
        not_one_index = not_one_index + 1
    else:
        break

if k <= not_one_index:
    print(1)
else:
    print(s[not_one_index])


Measured memory_bytes: 2940
/* Don't try to hack it :|
 
            _/﹋\_
            (҂`_´)
            <,︻╦╤─҉- - - - - - - - - - - - - - -
            _/﹋\_
*/

#include <bits/stdc++.h>
#define ll long long 
#define all(v) v.begin() , v.end()
#define pb push_back
#define f first
#define s second
#define mp make_pair
#define tr(con) for(auto it = con.begin(); it!= con.end() ; it++)
#define INF 1e9+7   
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define fo(i,n) for(ll i=0;i<n;i++)
using namespace std;
ll gcd(ll a, ll b){
	if(b==0) return a;
	return gcd(b ,a%b);
}
int main(){
	
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll a ,b ; cin >> a >> b ;
	cout << (a*b)/gcd(a,b);
	return 0;
}



Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
//#include<boost/multiprecision/cpp_int.hpp>
//#include<boost/multiprecision/cpp_dec_float.hpp>
//namespace mp=boost::multiprecision;
//#define mulint mp::cpp_int
//#define mulfloat mp::cpp_dec_float_100
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
//constexpr int MOD=1000000007;
constexpr int MOD=998244353;
#define INF (1<<30)
#define LINF (lint)(1LL<<56)
#define endl "\n"
#define rep(i,n) for(lint (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(lint (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcount(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
#define plint pair<lint,lint>
#define fi first
#define se second
typedef long long lint;
int dx[8]={1,1,0,-1,-1,-1,0,1};
int dy[8]={0,1,1,1,0,-1,-1,-1};
const int MAX_N=2e5+5;

int main(void){
    lint n,m,d;
    cin >> n >> m >> d;
    cout << (d?2:1)*(n-d)*(m-1)/pow(n,2) << endl;
}

Measured memory_bytes: 3792
h, w, k = map(int, input().split())
table = []
for _ in range(h):
    table.append([l for l in input()])

ans = 0
for rbit in range(1 << h):
    for cbit in range(1 << w):
        black = 0
        for i in range(h):
            for j in range(w):
                if (rbit >> i) & 1 == 0 and (cbit >> j) & 1 == 0 and table[i][j] == '#':
                    black += 1
        if black == k:
            ans += 1
print(ans)

Measured memory_bytes: 9052
#include <stdio.h>
 
int main(void) 
{
   int a[4][13], n, x, i, j;
   char c, dummy;
   
   scanf("%d", &n);
   
   for(i = 0; i < 4; i++) 
   {
	   for(j = 0; j < 13; j++) 
	   {
		   a[i][j] = 0;
	   }
   }
   
   for(i = 0; i < n; i++) 
   {
	   scanf("%c",&dummy);
	   scanf("%c%d", &c, &x);
	   
	   if(c == 'S') 
	   {
		   a[0][x-1] = 1;
	   } 
    
	   if(c == 'H') 
	   {
		   a[1][x-1] = 1;
	   }
    
	   if(c == 'C') 
	   {
		   a[2][x-1] = 1;
	   }
    
	   if(c == 'D')  
	   {
		   a[3][x-1] = 1;
	   }
   }
  
   for(i = 0; i < 4; i++) 
   {
	   for(j = 0; j < 13; j++) 
	   {
		   if(a[i][j] == 0) 
		   {
			   if(i == 0) 
			   {
				   printf("S %d\n", j+1);
			   }
			   
			   if(i == 1) 
			   {
				   printf("H %d\n", j+1);
			   }
			   
			   if(i == 2) 
			   {
				   printf("C %d\n", j+1);
			   }
			   
			   if(i == 3) 
			   {
				   printf("D %d\n", j+1);
			   }
		   }
	   }
   }
 
  return 0;
 
}

Measured memory_bytes: 596