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

public class Main {

    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    long p = sc.nextInt();

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

    void run() {

        char[] s = sc.next().toCharArray();

        long ans = 0;

        long sumMod = 0;

        Map<Long, Long> map = new HashMap<>();

//        map.put((long)0, (long)1);

        if (p == 2 || p == 5) {
            for (int i=n-1; 0<=i; i--) {
                if ((s[i]-'0') % p == 0) ans += i + 1;
            }

            System.out.println(ans);
            return;
        }

        for (int i=n-1; 0<=i; i--) {
            long tmp = s[i] - '0';
            tmp *= modPow(10, n-1-i);
            tmp %= p;
            sumMod += tmp;
            sumMod %= p;
            if (map.containsKey(sumMod)) {
                map.put(sumMod, map.get(sumMod)+(long)1);
            } else {
                map.put(sumMod, (long)1);
            }
        }

//        System.out.println(map);

        for (Long t: map.values()) {
            ans += t * (t - 1) / 2;
        }

//        System.out.println(ans);

        if (map.get((long)0) == null) {
            System.out.println(ans);
        } else {
            System.out.println(ans + map.get((long)0));
        }


    }

    long modPow(long x, long n) {
        long sum = 1;
        while (n > 0) {
            if ( (n & 1) == 1 ) {
                sum *= x;
                sum %= p;
            }
            x *= x;
            x %= p;
            n >>= 1;
        }
        return sum % p;
    }
}


Measured memory_bytes: 44660
import numpy as np
n, k = map(int,input().split())
p = np.array(input().split(),dtype=int)

sum = 0
for i in range(k):
    sum += p[i]
max = sum
for i in range(n-k):
    sum = sum+p[k+i]-p[i]
    if max<sum:
        max = sum
print(max/2+0.5*k)


Measured memory_bytes: 32360
#include <cmath>
#include <cstdio>
#include <iostream>

#define int long long

using namespace std;

int n, s;

int f(int b,int n)
{
	if (n < b) return n;
	return f(b,n/b) + n % b;
}

signed main(void)
{
	cin>>n>>s;
	if (n == s) return cout<<n+1,0; 
	for (int i=2;i<=(int)sqrt(n);++i)
	    if (f(i,n) == s) return cout<<i, 0; 
	int ans = 1e18;
	for (int i=1;i*i<=n;++i)
	    if ((n - s) % i == 0) {
	    	int b = (n - s) / i + 1;
	    	int x = i, y = s - i;
	    	if (x >= 0 && y >= 0 && b > sqrt(n) && x < b && y < b) 
	    		ans = min(ans,b);
		}
	cout<<(ans == 1e18 ? -1 : ans)<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#define REP(i, m, n) for(int i=int(m);i<int(n);i++)
#define EACH(i, c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s, e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

//#define LOCAL 1
#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR
#endif

//改造
typedef long long int ll;
using namespace std;

//ここから編集する

int main() {
    int a,b,c,d;
    int bef,aft;
    cin >> a >> b >> c >> d;
    bef = max(a,c);
    aft = min(b,d);
    if(aft - bef > 0){
        cout << aft - bef << endl;
    }else{
        cout << 0 << endl;
    }
    return 0;
}

Measured memory_bytes: 256
N, P = map(int, input().split())
A = list(map(int, input().split()))
odd, even = 0, 0
for i in range(N):
    if A[i] % 2:
        odd += 1
    else:
        even += 1
if odd == 0:
    if P:
        ans = 0
    else:
        ans = 2**N
else:
    ans = 2**(N-1)

print(int(ans))


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define FOR(I,A,B) for(ll I = (A); I < (B); ++I)
#define FORR(I,A,B) for(ll I = (B-1);I >= (A); --I)
const ll INF=1e18+3;
const ll MOD=1e9+7;

ll n,k;
bool d[10];
bool ok(int x){
	bool ans = true;
	while(x){
		int y = x%10;
		x /= 10;
		if(d[y])ans = false;
	}
	return ans;
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>n>>k;
	FOR(i,0,k){
		ll w;
		cin>>w;
		d[w] = true;
	}
	ll ans;
	FOR(i,n,n*100){
		if(ok(i)){
			ans = i;
			break;
		}
	}
	cout<< ans <<endl;
}

Measured memory_bytes: 256
#include <iostream>

int main (void)
{
	// variables for main process
	int val_age;
	int val_cost_need;
	int val_cost_adult;

	// STEP.01
	// read out the costs
	std::cin >> val_age;
	std::cin >> val_cost_adult;

	// STEP.02
	// calculate the cost to pay
	if      (val_age >= 13) { val_cost_need = val_cost_adult;     }
	else if (val_age >=  6) { val_cost_need = val_cost_adult / 2; }
	else                    { val_cost_need = 0;                  }

	// STEP.02
	// output the cost to pay
	std::cout << val_cost_need << std::endl;

	// STEP.END
	return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**7) #再帰関数の上限,10**5以上の場合python
import math
from copy import copy, deepcopy
from copy import deepcopy as dcp
from operator import itemgetter
from bisect import bisect_left, bisect, bisect_right#2分探索
#bisect_left(l,x), bisect(l,x)#aはソート済みである必要あり。aの中からx未満の要素数を返す。rightだと以下
from collections import deque
#deque(l), pop(), append(x), popleft(), appendleft(x)
##listでqueの代用をするとO(N)の計算量がかかってしまうので注意
from collections import Counter#文字列を個数カウント辞書に、
#S=Counter(l),S.most_common(x),S.keys(),S.values(),S.items()
from itertools import accumulate,combinations,permutations#累積和
#list(accumulate(l))
from heapq import heapify,heappop,heappush
#heapify(q),heappush(q,a),heappop(q) #q=heapify(q)としないこと、返り値はNone
#import fractions#古いatcoderコンテストの場合GCDなどはここからimportする
from functools import lru_cache#pypyでもうごく
#@lru_cache(maxsize = None)#maxsizeは保存するデータ数の最大値、2**nが最も高効率
from decimal import Decimal

def input(): 
    x=sys.stdin.readline()
    return x[:-1] if x[-1]=="\n" else x
def printl(li): _=print(*li, sep="\n") if li else None
def argsort(s, return_sorted=False): 
    inds=sorted(range(len(s)), key=lambda k: s[k])
    if return_sorted: return inds, [s[i] for i in inds]
    return inds
def alp2num(c,cap=False): return ord(c)-97 if not cap else ord(c)-65
def num2alp(i,cap=False): return chr(i+97) if not cap else chr(i+65)
def matmat(A,B):
    K,N,M=len(B),len(A),len(B[0])
    return [[sum([(A[i][k]*B[k][j]) for k in range(K)]) for j in range(M)] for i in range(N)]
def matvec(M,v):
    N,size=len(v),len(M)
    return [sum([M[i][j]*v[j] for j in range(N)]) for i in range(size)]
def T(M):
    n,m=len(M),len(M[0])
    return [[M[j][i] for j in range(n)] for i in range(m)]
def main():
    mod = 1000000007
    #w.sort(key=itemgetter(1),reversed=True)  #二個目の要素で降順並び替え

    H = int(input())
    #N, K = map(int, input().split())
    #A = tuple(map(int, input().split())) #1行ベクトル
    #L = tuple(int(input()) for i in range(N)) #改行ベクトル
    #S = tuple(tuple(map(int, input().split())) for i in range(N)) #改行行列

    cur=1
    tot=0
    while H>0:
        tot+=cur
        H=int(H*0.5)
        cur*=2

    print(tot)


if __name__ == "__main__":
    main()

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

// 総数を1000000007（素数）で割った余り
const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

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

int main(){
    int n, k;
    cin >> n >> k;
    vi l(n);
    rep(i, n) cin >> l[i];
    sort(l.begin(), l.end(), greater<int>());
    int ans = 0;
    rep(i, k) ans += l[i];
    cout << ans << endl;
    return 0;
}


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

#define mx 4000005
#define mod 1000007
#define ll long long

using namespace std;

bitset<mx> allSubSeqSum;

int main(int argc, char const *argv[])
{
      ios::sync_with_stdio(false);
      int total = 0, n;
      cin >> n;
      allSubSeqSum[0] = 1;
      while (n--)
      {
            int x;
            cin >> x;
            total += x;
            allSubSeqSum |= allSubSeqSum << x;
      }
      total = (total + 1) / 2;

      while (1)
      {
            if (allSubSeqSum[total])
            {
                  cout << total << "\n";
                  break;
            }
            total++;
      }

      return 0;
}

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

using ll=long long;
using int64=int64_t;
const int inf=100000000;

int in(){
  int a;
  cin >> a;
  return a;
}//int型関数の受け取り

void forin(int* x,int y){
  for (int i=0;i<y;i++){
    cin >> x[i];
  }
}//(x,y) int型配列x[y]の受け取り

int intpow(int x,int y){
  double a=x,b=y;
  return pow(a,b);
}//(x,y) xをy乗

int intfabs(int x){
  double a=x;
  return fabs(a);
}//(x) xの絶対値

int fact(int x){
  if (x == 1) return 1;
  return x*fact(x-1);
}//(x) x!

int fib(int x){
  if (x <= 2) return x;
  int a[x];
  a[0]=1;
  a[1]=2;
  for (int i=2;i<x;i++){
    a[i]=a[i-1]+a[i-2];
  }
  return a[x-1];
}//(x) フィボナッチ数列のx番目

int div1(ll x){
  return x%1000000007;
}

main(){
    int n=in(),k=in(),h[n],ans=0;
    forin(h,n);
    for (int a :h){
        if (a>=k) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 640
s = gets.chomp.to_i                                                 
    hh = 0                                                    
    mm = 0                                                    
    ss = 0
    hh = s / 3600                                             
    s = s % 3600
    mm = s / 60
    s = s % 60
    ss = s
    puts "#{hh}:#{mm}:#{ss}" 


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

ll gcd(ll a,ll b){
  if(b == 0) return a;
  return gcd(b, a % b);
}
const ll P =  1000000007;
ll factorial(ll n){
   ll ans = 1;
   for(int i = n;i>=1;i--){
     ans *= i;
     ans %= P;
   }
   return ans;
}
using Graph = vector<vector<int>>;

ll kzyou(ll a,ll k){//aのk乗を返す
    ll zyou = 1;
    for(ll i = 1;i<=k;i++){
        zyou *= a;
    }
    return zyou;
}

int main(){
  int N,R;
  cin >> N >> R;
  if(N >= 10) cout << R << endl;
  else cout << R + 100*(10 - N) << endl;
}


Measured memory_bytes: 256
import math

X=int(input())
ans = 0
if X==1:
    print(X)
    exit()
else:
    
    for b in range(2,int(X**0.5)+1):
        p= int(math.log10(X)/math.log10(b))
        N= b**p
        ans = max(N,ans)

    print(ans)
    

Measured memory_bytes: 3060
#include<stdio.h>
int main()
{
    int i=0;
    char s[1199],s1[1199];
   fgets(s,1199,stdin);

   while(s[i]!='\0')
 {

     if(s[i]>='A' && s[i]<='Z')
     {
        s1[i]=s[i]+32;
     }
        else if(s[i]>='a' && s[i]<='z')
        {
            s1[i]=s[i]-32;
        }
        else{
            s1[i]=s[i];
        }

i++;
    }

s1[i]='\0';
printf("%s",s1);



    return 0;
}




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

using namespace std;
using ll =long long;

#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cout << #x << " = " << (x) << endl;
void coY() {cout <<"Yes"<<endl;}
void coN(){cout <<"No"<<endl;}

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
const ll INF = 1LL << 60;

//Write From this Line

static const int N = 100;
int main()
{
	int n, p[N+1], m[N+1][N+1];
	cin >> n;
	rep(i,n) cin >> p[i] >> p[i+1];

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

	for(int l = 2; l <= n; l++){
		for(int i = 1; i<=n-l+1; i++){
			int j = i + l - 1;
			m[i][j] = (1 << 21);
			for(int k = i; k <= j - 1; k++){
				m[i][j] = min(m[i][j], m[i][k] + m[k + 1][j] +p[i-1] * p[k] * p[j]);
			}
		}
	}
	cout << m[1][n] << endl;
}



Measured memory_bytes: 3160
/*  "Sahand Alitanloo"  */
#include <bits/stdc++.h>
#define F first
#define S second
#define fast() ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define per(i) cout<<fixed<<setprecision(i)
#define pb push_back
#define all(v) begin(v),end(v)
#define endl '\n'
using namespace std;
typedef pair<int,int> pii;
typedef long double ld;
typedef long long ll;
const int MAX_N = 1e5+10;
const ll mod = 1e9+7;
const ll INF = 1e9;
inline ll bpow(ll t,ll n){ll ans=1;while(n>0){if(n&1)ans=(ans*t)%mod;t=(t*t)%mod,n>>=1;}return ans;}
/*
ll fact[MAX_N],ifact[MAX_N];
inline ll c(ll n,ll k){if(k>n||k<0)return 0;return (fact[n]*ifact[k]%mod*ifact[n-k])%mod;}
inline void get_fact(){fact[0]=1;ifact[0]=1;for(ll i=1;i<MAX_N;i++)fact[i]=(fact[i-1]*i)%mod,ifact[i]=bpow(fact[i],mod-2);}
*/

main(){
    fast();per(0);
    //get_fact();
	int a,b,c;cin>>a>>b>>c;
	cout<<min(a*b,c);
}

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

using namespace std;

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

    int num, cnt = 0, max = 1, maxCnt = 0;
    for(int i = 1; i <= N; i++) {
        num = i;
        cnt = 0;
        while(true) {
            if(num % 2 == 0) {
                ++cnt;
                num /= 2;
            } else {
                break;
            }
        }

        if(maxCnt < cnt) {
            max = i;
            maxCnt = cnt;
        }
    }

    cout << max << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAX = 1e3+2;
vector<string> s_grid;
int dist[MAX][MAX];
const int mod = 1000000007;
int H, W;
bool vis[MAX][MAX];
bool is_valid(int x, int y)
{
	return (x < H && x >= 0 && y < W && y >= 0);
}

void add_self(int &a, int b)
{
	a += b;
	if(a >= mod)
		a -= mod;
} 


int main()
{
	cin >> H >> W;
	for(int i = 0; i < H; ++i)
	{
		string s;
		cin >> s;
		s_grid.push_back(s);
	}
	std::vector<vector<int>> dp(H, vector<int>(W));
	dp[0][0] = 1;

	for(int row = 0; row < H; ++row)
	{
		for(int col = 0; col < W; ++col)
		{
			if(col < W && row+1 < H && s_grid[row+1][col] == '.')
			{
				add_self(dp[row+1][col], dp[row][col]);
			}
			if(col+1 < W && row < H && s_grid[row][col+1] == '.')
			{
				add_self(dp[row][col+1], dp[row][col]);
			}
		}
	}
	cout << dp[H-1][W-1] ;

}

Measured memory_bytes: 8600
#include<bits/stdc++.h>
using namespace std;
//#include<boost/multiprecision/cpp_int.hpp>
//using boost::multiprecision::cpp_int;

#define int long long
#define cint cpp_int
#define endl "\n"
#define REP(i,a,n) for(int i=a;i<n;++i)
#define REPR(i,a,n) for(int i=a;i>n;--i)
#define RUP(a,b) (((a)+(b)-1)/(b))
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define MOD 1000000007
#define INF LLONG_MAX/2
#define PI acos(-1.0)
#define leng(n) (int)(log10(n)+1)


typedef long long ll;
typedef pair<int,int> Pii;
typedef tuple<int,int,int> Tiii;
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef vector<Pii> VPii;
typedef vector<string> Vs;

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;}
template<class T> void YesNo(T a) {cout<<(a?"Yes":"No")<<endl;}
template<class T> void YESNO(T a) {cout<<(a?"YES":"NO")<<endl;}
void vout(Vi &v){for(int i=0;i<(v).size();i++) cout<<v[i]<<" ";cout<<endl;}
void vvout(VVi &v){for(int i=0;i<(v).size();i++) vout(v[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;}
int mypow(int x, int n, int m){if(n==0)return 1;if(n%2==0)return mypow(x*x%m,n/2,m);else return x*mypow(x,n-1,m)%m;}
int digit(int k,int i){string s = to_string(k);return s[s.size()-i]-'0';}
void uniq(Vi &v){sort(v.begin(),v.end()); v.erase(unique(v.begin(),v.end()),v.end());}
int ctoi(char c){if(c>='0'&&c<='9'){return c-'0';}return 0;}
Vi accum(Vi v){Vi ret((v).size());ret[0]=v[0];REP(i,1,(v).size()) ret[i]=ret[i-1]+v[i];return ret;}
bool comp(Pii a,Pii b){
    if(a.second != b.second) return a.second<b.second;
    else return a.first<b.first;
}

Vi yakusuu(int n){
    Vi ret;
    for(int i=1 ; i*i<=n ; ++i){
        if(n%i == 0){
            ret.push_back(i);
            if(i*i!=n) ret.push_back(n/i);
        }
    }
    sort(ALL(ret));
    return ret;
}

signed main(){cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(12);
    int n;
    cin>>n;
    Vs s(n);
    REP(i,0,n){
        cin>>s[i];
    }

    int ans=0;
    REP(i,0,n){
        Vs ss(n);
        REP(j,0,n){
            ss[j]=s[(j+i)%n];
        }
        // REP(j,0,n) cout<<ss[j]<<endl;
        // cout<<endl;
        bool check=false;
        REP(j,0,n){
            REP(k,0,n){
                if(ss[j][k]!=ss[k][j]){
                    check=true;
                    break;
                }
            }
            if(check) break;
        }
        if(check==false) ans += n;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 564
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;

#define ll long long
pair<ll, ll> a[maxn], tmp;

ll c[maxn];
ll dp[maxn];

bool cmp(pair<ll, ll> A, pair<ll, ll> B) {
    return A.first * (B.second + 1) > B.first * (A.second + 1);
}

void solve() {
    int n;
    ll T;
    scanf("%d %lld", &n, &T);
    int cnt1 = 0, cnt2 = 0;
    for (int i = 1; i <= n; ++i) {
        scanf("%lld %lld", &tmp.first, &tmp.second);
        if (tmp.first == 0) c[cnt2++] = tmp.second + 1;
        else a[cnt1++] = tmp;
    }

    sort(c, c + cnt2);
    sort(a, a + cnt1, cmp);
    for (int i = 1; i <= 30; ++i) dp[i] = T + 1;
    dp[0] = 0;
    for (int i = 1; i <= cnt2 - 1; ++i) {
        c[i] += c[i - 1];
    }

    for (int i = 0; i <= cnt1 - 1; ++i) {
        for (int j = 30; j >= 1; --j) {
            dp[j] = min(dp[j], (a[i].first + 1) * (dp[j - 1] + 1) + a[i].second);
        }
    }

    int ans = 0;
    for (int i = 0; i <= 30; ++i) {
        if (dp[i] > T) continue;
        int add = 0;
        if (cnt2) {
            add = upper_bound(c, c + cnt2, T - dp[i]) - c;
        }
        ans = max(ans, i + add);
    }
    printf("%d\n", ans);
    return ;

}

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

Measured memory_bytes: 4864
#include <stdio.h>
int main(){
    int carList[100] = {0}, num = 0;
    while (scanf("%d", &carList[num]) != EOF) {
        if(carList[num]){
            num++;
        }else{
            num--;
            printf("%d\n",carList[num]);
        }
    }
    return 0;
}

Measured memory_bytes: 1736
#include <iostream>

using namespace std;

int main(){

	unsigned long long a,b,c,d;

	while(cin>>a>>b){
		c=a;
		d=b;
		while(1){
			if(c>d)c=c-d;
			if(c<d)d=d-c;
			if(c==d){
				cout<<c<<" "<<a*b/c<<endl;
				;break;}
		}}
		


return 0;
}

Measured memory_bytes: 0
N = int(input())
L = list(map(int, input().split()))
ans = 0
for i in L:
  for j in L:
    for k in L:
      if i + j > k and j + k > i and k + i > j and i != j and j != k and k != i:
        ans += 1

ans = ans // 6
print(ans)

Measured memory_bytes: 9088
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define FORL(i,x) for(int i=head[x];i;i=nxt[i])
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define PB push_back
#define MP make_pair
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; }



int main() {
    string s1,s2;
    cin >> s1 >> s2;
    int ans = 0;
    if(s1[0]==s2[0]) ++ans;
    if(s1[1]==s2[1]) ++ans;
    if(s1[2]==s2[2]) ++ans;

    cout << ans << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
int main() {
    ll n,m;
    cin>>n>>m;
    ll co[n];
    ll judge[n];
    rep(i,n){
        co[i]=0;
        judge[i]=0;
    }
    ll p[m];
    string s[m];
    ll ac=0;
    ll wa=0;
    rep(i,m){
        cin>>p[i]>>s[i];
        if(judge[p[i]-1]==0&&s[i]=="AC"){
            judge[p[i]-1]=1;
            ac++;
            wa+=co[p[i]-1];
        }else if(judge[p[i]-1]==0&&s[i]=="WA"){
            co[p[i]-1]++;
        }
    }
    cout<<ac<<" "<<wa<<endl;
}


Measured memory_bytes: 8064
#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector,fast-math")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize (2)
#pragma G++ optimize (2)
#include<bits/stdc++.h>
using namespace std;
#define wuyt main
typedef long long ll;
#define HEAP(...) priority_queue<__VA_ARGS__ >
#define heap(...) priority_queue<__VA_ARGS__,vector<__VA_ARGS__ >,greater<__VA_ARGS__ > >
template<class T> inline T min(T &x,const T &y){return x>y?y:x;}
template<class T> inline T max(T &x,const T &y){return x<y?y:x;}
//#define getchar()(p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2) ? EOF : *p1++)
//char buf[(1 << 21) + 1], *p1 = buf, *p2 = buf;
ll read(){ll c = getchar(),Nig = 1,x = 0;while(!isdigit(c) && c!='-')c = getchar();
if(c == '-')Nig = -1,c = getchar();
while(isdigit(c))x = ((x<<1) + (x<<3)) + (c^'0'),c = getchar();
return Nig*x;}
#define read read()
const ll inf = 1e15;
const int maxn = 2e5 + 7;
const int mod = 1e9 + 7;
#define finished return 0 
int num[1000000],judge[1000000];
int n;
int wuyt(){
	n=read;
	for(int i=1;i<=n;i++)
		num[i]=read;
	if(n%2)
		for(int i=2;i<=n;i+=2)
		{
			judge[i]=i;
			judge[i+1]=judge[i]; 
		}
	else
		for(int i=1;i<=n;i+=2)
		{
			judge[i]=i;
			judge[i+1]=judge[i]; 
		}
	sort(num+1,num+1+n);
	for(int i=1;i<=n;i++)
	{
		if(judge[i]!=num[i]){
			printf("0\n");
			return 0;
		}
	}
	if(n%2)
		n=(n-1)/2;
	else
		n/=2;
	ll ans=1;
	for(int i=0;i<n;i++)
	{
		ans*=2;
		ans%=mod;
	}
	printf("%lld",ans);
	finished;
}

Measured memory_bytes: 4736
import sys, math
input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(input())
rl = lambda: list(map(int, input().split()))
mod = 10**9 + 7

N = ri()

m = N % 1000
if m == 0:
	print(0)
else:
	print(1000-m)


Measured memory_bytes: 61900
#include <cstdio>
#include <cstdint>
#include <cstdlib>
#include <cassert>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>

std::vector<std::pair<int, int>> neko(int X, int Y, int K) {
  if (X+Y == K) return {{X, Y}};

  std::vector<std::pair<int, int>> res;
  int x = 0;
  int y = 0;

  if (X+Y < K && (X+Y) % 2 != 0) {
    x += X;
    y -= K - X;
    res.emplace_back(x, y);
    x += (K+X-Y) / 2;
    y += K - (K+X-Y) / 2;
    res.emplace_back(x, y);
    res.emplace_back(X, Y);
    return res;
  }

  int c = (K - (X+Y) % K) % K;
  int n = 2;
  if (X+Y >= K) {
    n = (X+Y+K-1) / K;
    if (c % 2 != 0) ++n;
  }

  int d = -(K*n-(X+Y)) / 2;

  while (y-K >= d) {
    y -= K;
    res.emplace_back(0, y);
  }
  x += K - (y-d);
  y = d;
  res.emplace_back(x, y);
  while (x+K <= X) {
    x += K;
    res.emplace_back(x, y);
  }
  y += K - (X-x);
  x = X;
  res.emplace_back(x, y);
  while (y+K <= Y) {
    y += K;
    res.emplace_back(x, y);
  }

  // assert(x == X && y == Y);
  // assert(res.size() == static_cast<size_t>(n));
  return res;
}

int main() {
  int K, X, Y;
  scanf("%d %d %d", &K, &X, &Y);

  if ((X+Y) % 2 != 0 && K % 2 == 0) return puts("-1"), 0;

  bool xneg = (X < 0);
  if (xneg) X = -X;
  bool yneg = (Y < 0);
  if (yneg) Y = -Y;
  bool swapped = (X < Y);
  if (swapped) std::swap(X, Y);

  auto res = neko(X, Y, K);
  printf("%zu\n", res.size());
  for (auto p: res) {
    int x, y;
    std::tie(x, y) = p;
    if (swapped) std::swap(x, y);
    if (xneg) x = -x;
    if (yneg) y = -y;
    printf("%d %d\n", x, y);
  }

  res.insert(res.begin(), std::make_pair(0, 0));
  for (size_t i = 1; i < res.size(); ++i) {
    int dx = std::abs(res[i].first-res[i-1].first);
    int dy = std::abs(res[i].second-res[i-1].second);
    // assert(dx + dy == K);
  }
}


Measured memory_bytes: 3952
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <algorithm>
#include <numeric>
#include <math.h>
using namespace std;

#define N_MAX   (100000)
#define LL_MAX_NUM (1LL<<60)

typedef long long ll;
typedef long long int lli;

int main() {
    int A, B, C, res;
    vector<int> nums;
    cin >> A >> B >> C;
    nums.push_back(A);
    nums.push_back(B);
    nums.push_back(C);
    sort(nums.begin(), nums.end());
    res = 0;
    while(nums[0] != nums[1] || nums[1] != nums[2]) {
        if (nums[1] == nums[2]) {
            nums[0] += 2;
        } else {
            nums[0]++;
            nums[1]++;
        }
        res++;
        sort(nums.begin(), nums.end());
    }
    cout << res << endl;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <stack>
#include <iostream>
#include <string>
#include <tuple>
#include <random>
#include <map>
#include <queue>
#include <set>
#include <complex>
#include <algorithm>
#include <cassert>
#include <iterator>
#include <numeric>
#include <cmath>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;

const double eps = 1e-8;

const ll INF = 1e15;
const ll MOD = 1e9 + 7;

int main(){
	ll N;
	cin >> N;
	vector<ll> v(N);
	for (int i = 0;i < N;i++) {
		cin >> v[i];
	}
	sort(v.begin(), v.end());
	//賞から
	ll mini = 1 + N % 2;
	ll bigmini = N % 2 == 0;
	ll ans = 0;
	for (int i = 0;i < N / 2 + N % 2 - mini;i++)
		ans -= v[i] * 2;
	for (int i = N / 2 + N % 2 - mini; i < N / 2 + N % 2;i++)
		ans -= v[i];
	for (int i = N / 2 + N % 2; i < N / 2 + N % 2 + bigmini;i++)
		ans += v[i];
	for (int i = N / 2 + N % 2 + bigmini; i < N;i++)
		ans += v[i] * 2;
	sort(v.begin(), v.end());
	ll answer = ans;
	ans = 0;
	//大
	for (int i = 0;i < N / 2 - bigmini;i++)
		ans -= v[i] * 2;
	for (int i = N / 2 - bigmini; i < N / 2;i++)
		ans -= v[i];
	for (int i = N / 2; i < N / 2 + mini;i++)
		ans += v[i];
	for (int i = N / 2 + mini; i < N;i++)
		ans += v[i] * 2;
	answer = max(ans, answer);
	cout << answer << endl;
	return 0;
}


Measured memory_bytes: 1656
#include <stdio.h>

int main(void)
{
  int n,m;
  int i,a[10000];
  
  do {
    scanf("%d %d",&n,&m);
  } while((n<1 || n>1000000) || (m<1 || m>10000));
  
  for(i=1; i<=m; i++){
    do{
      scanf("%d",&a[i]);
    } while(a[i]<1 || a[i]>10000);
    n -= a[i];
  }
  if(n>=0)
    printf("%d\n",n);
  else
    printf("-1\n");
  
  return 0;
}

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

typedef vector<double> vec;
typedef vector<vec> mat;
const double EPS=1E-8;

vec gauss_jordan(const mat& A,const vec& b){
  int n=A.size();
  mat B(n,vec(n+1));
  for(int i=0;i<n;i++)
    for(int j=0;j<n;j++)B[i][j]=A[i][j]; //n*(n+1)の配列にする。

  for(int i=0;i<n;i++)B[i][n]=b[i]; //n番目に代入

  for(int i=0;i<n;i++){
    int pivot=i;//次の基準となる添え字。
    for(int j=i;j<n;j++)if(abs(B[j][i])>abs(B[pivot][i]))pivot=j;//0以外の1つを探す
    swap(B[i],B[pivot]);//i行目に持ってくる。

    if(abs(B[i][i])<EPS)return vec();//もしも０だったら解なしまたは複数存在。
    
    for(int j=i+1;j<=n;j++)B[i][j]/=B[i][i]; //左辺をB[i][i]で両辺を割る。
    
    for(int j=0;j<n;j++){ //
      if(i!=j)//i行目-i行目はスキップ
        for(int k=i+1;k<=n;k++)B[j][k]-=B[j][i]*B[i][k];//i列の値をi列目以外を0にする。
    }
  }
  vec x(n);
  for(int i=0;i<n;i++)x[i]=B[i][n];
  return x;
}

int main(){
  int n,s,t,q[100],a[100][100],d[100][100];
  while(cin>>n>>s>>t,n){
    vector<int> v[2][100];
    s--,t--;
    for(int i=0;i<n;i++)cin>>q[i];
    for(int i=0;i<n;i++)
      for(int j=0;j<n;j++){
	cin>>a[i][j];
	if(!a[i][j])a[i][j]=d[i][j]=1e9;
	else v[0][i].push_back(j),d[i][j]=a[i][j];
      }
    for(int i=0;i<n;i++)
      for(int j=0;j<n;j++)
	for(int k=0;k<n;k++)
	  d[j][k]=min(d[j][k],d[j][i]+d[i][k]);
    if(d[s][t]==1e9){cout<<"impossible"<<endl;return 0;}
    mat A(n,vec(n));
    vec b(n);
    for(int i=0;i<n;i++){
      if(d[i][t]==a[i][t])v[1][i].push_back(t);
      for(int j=0;j<n;j++)
	if(d[i][t]==a[i][j]+d[j][t])v[1][i].push_back(j);
      }
    for(int i=0;i<n;i++){
      int sz=v[q[i]][i].size();
      if(i==t){A[i][i]=1;continue;}
      double cnt=0;
      for(int j=0;j<sz;j++){
	int p=v[q[i]][i][j];
	A[i][p]=1.0/sz;
	cnt+=a[i][p];
      }
      A[i][i]-=1;
      b[i]-=cnt/sz;
    }
    vec res=gauss_jordan(A,b);
    printf("%.9lf\n",res[s]);
  }
  return 0;
}


Measured memory_bytes: 3416
import heapq

n = int(input())
arr = list(map(int, input().split()))
arr = sorted(arr, reverse= True)

ans = 0
q = []
heapq.heappush(q, -arr[0])
for i in range(1,n):
    tmp = heapq.heappop(q)*(-1)
    ans += tmp
    heapq.heappush(q, -arr[i])
    heapq.heappush(q, -arr[i])
print(ans)

Measured memory_bytes: 31680
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <functional>
#include <initializer_list>
#include <iostream>
#include <limits.h>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;
#define ull unsigned long long
#define ll long long
#define rep(i, a, n) for (int i = (a); i < (int)(n); i++)
#define repc(i, a, n) for (int i = (a); i <= (int)(n); i++)
#define all(t) t.begin(), t.end()
#define rall(t) t.rbegin(), t.rend()
#define mat(type, row, col, init)                                              \
  vector<vector<type>>(row, vector<type>(col, init));
#define Yes(cond) cout << (cond ? "Yes" : "No") << endl;
#define YES(cond) cout << (cond ? "YES" : "NO") << endl;
#define DBG(str) cerr << (str) << endl;
int main() {
  int n, m, x;
  cin >> n >> m >> x;
  vector<int> a(m);
  rep(i, 0, m) cin >> a[i];
  sort(all(a));
  int p = 0;
  rep(i, 0, m) {
    if (a[i] < x)
      p = i + 1;
  }
  cout << min(p, m - p);

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
const long long int mod1=1000000007;
const long long int mod2 = -1;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb push_back
#define pp pop_back                                       
#define ff first
#define ss second
#define ll long long int
#define ull unsigned long long int
#define ordered_set tree<ll,null_type,less_equal<ll>,rb_tree_tag,tree_order_statistics_node_update>
#define ordered1 tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>
 
ll gcd(ll a, ll b){
    ll c;
     while(b){
        c = b;
        b = a % b;
        a = c;
     }
     return a;
}
ll power1(ll a, ll b){
     if(b == 0) return 1;
     else if(b % 2) return a * power1(a, b - 1);
     else {
        ll temp = power1(a, b / 2);
        return temp * temp;
     }
}
ll power2(ll a, ll b, ll m){
     a %= m;
     if(b == 0) return 1;
     else if(b % 2) return (a * power2(a, b - 1, m)) % m;
     else{
        ll temp = power2(a, b / 2, m);
        return (temp * temp) % m;
     }
}
ll mod(ll x, ll p){
return (x % p + p) % p;
}
ll lcm(ll x, ll y){
return (x * y)/gcd(x, y);
}
int main(){
	fast;
	ll h = 1;
	//cin >> h;
	while(h--){
	ll x,y;
	cin >> x>>y;
	cout<<(x*y)/gcd(x,y);
	}}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define FIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define mod 1000000007
#define endl "\n"
#define test ll t; cin>>t; while(t--)
typedef long long int ll;
int main() {
    FIO;
    ll a[2],b[2],ans=-LONG_MIN;
    cin>>a[0]>>a[1];
    cin>>b[0]>>b[1];
    for(int i=0;i<2;i++){
        for(int j=0;j<2;j++){
            ans=max(ans,a[i]*b[j]);
        }
    }
    cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 3612
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define SZ(x) ((int)(x).size())
#define rep(i,n) for(int i=0;i<(n);++i)
#define fore(i,a) for(auto &i:a)
#define min(...) min({__VA_ARGS__})
#define max(...) max({__VA_ARGS__})
#define Yes cout << "Yes" << endl;
#define No cout << "No" << endl;
#define ALL(x) (x).begin(),(x).end()
signed _main(); signed main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> using v = vector<T>;
template<class T> using vv = vector<v<T>>;
const int MOD=1e9+7;
const long long INF = 1LL << 60;
using P=pair<int,int>;

signed _main(){
  string s; int K;
  cin >> s >> K;
  v<int> cnt(s.size());
  rep(i,s.size()){
    cnt[i]='z'-s[i]+1;
  }
  int index=0;
  while(index<s.size()){
    if(s[index]=='a'){
      index++;
      continue;
    }
    if(cnt[index]<=K){
      s[index]='a';
      K-=cnt[index];
    }
    index++;
  }
  K%=26;
  int num=s[s.size()-1]-'a'+K;
  if(num<=26) s[s.size()-1]='a'+num;
  else s[s.size()-1]='a'+num-26;
  cout << s << endl;
  return 0;
}


Measured memory_bytes: 1360
import java.util.*;

class Main{
  public static void main(String[] args){
      Scanner sc = new Scanner(System.in);
      int N = sc.nextInt();
      int L = sc.nextInt();
      String[] array = new String[N];
      
      for(int i = 0 ; i < N ; i++){
        array[i] = sc.next();
      }

      Arrays.sort(array);

      for (int j = 0 ; j < array.length ; j++){
        System.out.print(array[j]);

      }
      sc.close();
    }
}


Measured memory_bytes: 21716
use std::vec::Vec;
use std::cmp::*;

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace().map(|e| e.parse().ok().unwrap()).collect()
}

fn main() {
  let n: usize = read();
  let mut m: Vec<Vec<i64>> = Vec::new();

  for _ in 0..n {
    let v: Vec<i64> = read_vec();
    m.push(v);
  }

  let dist = warshal_floyd(n, &m);


  for i in 0..n {
    for j in i..n {
      if dist[i][j].0 < m[i][j] {
        println!("-1");
        return;
      }
    }
  }

  let mut ans = 0;
  for i in 0..n {
    for j in i..n {
      if dist[i][j].1 {
        ans += dist[i][j].0;
      }
    }
  }

  println!("{}", ans);
}


fn warshal_floyd(n: usize, v: &Vec<Vec<i64>>) -> Vec<Vec<(i64, bool)>> {
  let mut dist = vec![vec![(0, true); n]; n];

  for i in 0..n {
    for j in 0.. n{
      dist[i][j].0 = v[i][j];
    }
  }

  for k in 0..n {
    for i in 0..n {
      for j in 0..n {
        if dist[i][j].0 > dist[i][k].0 + dist[k][j].0 {
          dist[i][j].0 = dist[i][k].0 + dist[k][j].0;
        }
        if dist[i][j].0 == dist[i][k].0 + dist[k][j].0 && (i != k && j != k)  {
          dist[i][j].1 = false;
        }
      }
    }
  }
  dist
}


Measured memory_bytes: 6396
#include <bits/stdc++.h>
using namespace std;
int n,cnt[30];
char S[5];
int main()
{
	scanf("%d",&n);
	for (int i=1;i<=n;i++)
	{
		scanf("%s",S);
		cnt[S[0]-65]++;
	}
	printf("AC x %d\n",cnt[0]);
	printf("WA x %d\n",cnt['W'-65]);
	printf("TLE x %d\n",cnt['T'-65]);
	printf("RE x %d\n",cnt['R'-65]);
	return 0;
}


Measured memory_bytes: 3796
n=int(input())
a=list(map(int,input().split()))
mini=float('inf')
sum1=0
sum2=sum(a)
t=0
while t<10**7:
	t+=1
for i in range(n):
    sum1=sum1+a[i]
    sum2=sum2-a[i]
    mini=min(mini,abs(sum1-sum2))
print(mini)

Measured memory_bytes: 3064
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
 
//template
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(a);i>(b);i--)
#define ALL(v) (v).begin(),(v).end()
typedef long long int ll; typedef pair<ll, ll> P;
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; }
template<typename A,size_t N,typename T>void Fill(A(&array)[N],const T &val){fill((T*)array, (T*)(array+N), val);}
const int inf = INT_MAX / 2; const ll INF = LLONG_MAX / 2;
//template end

int mod = 1e9+7;
struct Mint {
  int val;
  Mint inv() const {
    int tmp, a = val, b = mod, x = 1, y = 0;
    while(b) tmp = a / b, a -= tmp * b, swap(a, b), x -= tmp * y, swap(x, y);
    return Mint(x);
  }
public:
  Mint() :val(0) {}
  Mint(ll x) :val(x >= 0 ? x % mod : x % mod + mod) {}
  int mtoi() { return this->val; }
  Mint pow(ll t) { Mint res = 1,b = *this; while(t){if(t&1)res *= b;b *= b;t >>= 1;}return res; }
  Mint& operator+=(const Mint& x) { if ((val += x.val) >= mod) val -= mod; return *this; }
  Mint& operator-=(const Mint& x) { if ((val += mod - x.val) >= mod) val -= mod; return *this; }
  Mint& operator*=(const Mint& x) { val = (ll)val * x.val % mod; return *this; }
  Mint& operator/=(const Mint& x) { return *this *= x.inv(); }
  bool operator==(const Mint& x) const { return val == x.val; }
  bool operator!=(const Mint& x) const { return val != x.val; }
  bool operator<(const Mint& x) const { return val < x.val; }
  bool operator<=(const Mint& x) const { return val <= x.val; }
  bool operator>(const Mint& x) const { return val > x.val; }
  bool operator>=(const Mint& x) const { return val >= x.val; }
  Mint operator+(const Mint& x) const { return Mint(*this) += x; }
  Mint operator-(const Mint& x) const { return Mint(*this) -= x; }
  Mint operator*(const Mint& x) const { return Mint(*this) *= x; }
  Mint operator/(const Mint& x) const { return Mint(*this) /= x; }
};
struct factorial {
  vector<Mint> Fact, Finv;
public:
  factorial(int maxx) {
    Fact.resize(maxx+1,Mint(1)),Finv.resize(maxx+1); rep(i,0,maxx)Fact[i+1]=Fact[i]*Mint(i+1);
    Finv[maxx]=Mint(1)/Fact[maxx]; rrep(i,maxx,0)Finv[i-1]=Finv[i]*Mint(i);
  }
  Mint fact(int n,bool inv) { if(inv) return Finv[n]; else return Fact[n]; }
  Mint nPr(int n,int r) { if(n<0||n<r||r<0) return Mint(0); else return Fact[n]*Finv[n-r]; }
  Mint nCr(int n,int r) { if(n<0||n<r||r<0) return Mint(0); else return Fact[n]*Finv[r]*Finv[n-r]; }
};

int main(){
  char c[10010]; int d; scanf("%s%d",c,&d);
  string k=c; int n=k.size();
  Mint dp[n+1][2][d]={};
  dp[0][0][0]=1;
  rep(i,0,n)rep(j,0,d){
    rep(digit,0,10)dp[i+1][1][(j+digit)%d]+=dp[i][1][j];
    rep(digit,0,(k[i]-'0'))dp[i+1][1][(j+digit)%d]+=dp[i][0][j];
    dp[i+1][0][(j+(k[i]-'0'))%d]+=dp[i][0][j];
  }
  dp[n][0][0]+=dp[n][1][0]-1;
  printf("%d\n",dp[n][0][0].mtoi());
  return 0;
}


Measured memory_bytes: 8064
#include <bits/stdc++.h>
using namespace std;
using lint = int64_t;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define all(v)    (v).begin(), (v).end()
#define in        []{lint n; cin>>n; return n;}()

int main() { cin.tie(0); ios::sync_with_stdio(false);
    int N = in, K = in;
    vector<int> v(200001, 0);
    rep( i, N ) { int a = in; v[a] ++; }

    sort( all(v), greater<int>() );

    int count = 0;
    rep( i, K ) count += v[i];

    cout << (N - count) << "\n";
}


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

using namespace std;
typedef long long ll;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    ll res=1;
    vector<ll> a(n);
    for(int i=0;i<n;i++)
    {
        cin >> a[i];
        if(a[i]==0) res=0;
    }
    const ll lim=1000000000000000000;
    if(res==0) cout << "0\n";
    else
    {
        for(int i=0;i<n;i++)
        {
            if(a[i]>lim/res) res=-1;
            if(res!=-1) res*=a[i];
        }
        cout << res << "\n";
    }
    return 0;
}


Measured memory_bytes: 3988
while true
    max=0
    a=gets.split.map(&:to_i)
    break if a.reduce(:+)==0
    for i in 1..a[2]-1 do
        t=0
        if a[2]==((a[2]-i).to_f/(100+a[0])*100).ceil*(100+a[0])/100+(i.to_f/(100+a[0])*100).ceil*(100+a[0])/100 then
            t=((a[2]-i).to_f/(100+a[0])*100).ceil*(100+a[1])/100.round+(i.to_f/(100+a[0])*100).ceil*(100+a[1])/100.round
        end
        max=t.round if t>max
    end
    puts max
    a.clear
end

Measured memory_bytes: 6124
#pragma GCC optimize("O3")
#pragma GCC target("avx")
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
#define rep(i ,n) for(int i=0;i<(int)(n);++i)
#define repr(i ,n) for(int i=n;i>(int)(n);--i)
#define rep1(i ,n) for(int i=1;i<=(int)(n);++i)
#define ALL(a) a.begin(), a.end()
#define RSORT(a) sort(ALL(a),greater<>())
#define SORT(a) sort(ALL(a))
#define bit_check(bit, i) ((bit>>(i)) & 1)
#define PRINT(x) cout << (x) << endl
#define ENDL cout << endl
#define EPS (1e-8)
using namespace std;
typedef long long int i64;
typedef unsigned long long u64;
template<class T> using V = vector<T>;
using VI = V<int>;
const int INF = 2e9;
const i64 MOD = 1e9 + 7;

template <class T> inline bool chmin(T& a, T b){if(a>b){a=b; return true;} return false;}
template <class T> inline bool chmax(T& a, T b){if(a<b){a=b; return true;} return false;}
struct Init_On{
    Init_On(){
        cin.tie(nullptr);
        ios_base::sync_with_stdio(false);
        cout << fixed << setprecision(16);
    }
};

signed main(){
    string s;
    while(cin >> s){
        string t1 , t2 , t3;
        int i = 0;
        while(s[i]!='+'){
            t1 += s[i++];
        }
        ++i;
        while(s[i]!='='){
            t2 += s[i++];
        }
        ++i;
        while(s[i]!=0){
            t3 += s[i++];
        }
        string s1 = t1;
        string s2 = t2;
        string s3 = t3;
        bool ans = false;
        for( i = 0; i < 10 ; ++i){
            t1 = s1; t2 = s2; t3 = s3;        
            rep(j , t1.size()){
                if(t1[j]=='X') t1[j]='0'+i;
            }
            rep(j , t2.size()){
                if(t2[j]=='X') t2[j]='0'+i;
            }
            rep(j , t3.size()){
                if(t3[j]=='X') t3[j]='0'+i;
            }
            if(t1.size() < t2.size()) swap(t1 , t2);
            for(int i = t1.size()-1 , j =t2.size()-1 ; i >=0 ; --i , --j){
                if( j >= 0 ) t1[i] += t2[j] - '0';
                    if(t1[i] > '9') {
                        t1[i]-=10;
                        if(i == 0) t1 = '1' + t1;
                        else ++t1[i-1];
                }
            }
            
            if( t1 == t3  ) { ans = true; break; }
        }
        if( ans ) cout << i << endl;
        else cout << "NA" << endl;
    }
}


Measured memory_bytes: 3028
#include <stdio.h>
int n, cnt;
int A[1000000];

void shellSort(); 
void insertionSort(int);

int main() {  
  int i;
  scanf("%d", &n);
  for(i = 0; i < n; i++) {
    scanf("%d", A+i);
  }
  shellSort();
  return 0;
}

void insertionSort(int g) { 
  int v;
  int i, j;
  for(i = g; i < n; i++) {
    v = A[i];
    j = i-g;

    while(j >= 0 && A[j] > v) {
      A[j+g] = A[j];
      j -= g;
      cnt++;
    }
    A[j+g] = v;
  }
}
void shellSort() {
  
  int G[100];
  int m = 0, g = 0;
  int i;
  
  while(3 * g + 1 <= n) {
    g = 3 * g + 1;
    G[m++] = g;

  }
  
  printf("%d\n", m);
  for(i = m - 1; i >= 0; i--) {

    if(i < m - 1) printf(" ");
    printf("%d", G[i]);
    insertionSort(G[i]);
  }

  puts("");
  printf("%d\n", cnt);

  for(i = 0; i < n; i++){
    printf("%d\n", A[i]);
  }
}

Measured memory_bytes: 4520
import bisect
import copy
import heapq
import sys
import itertools
import math
import queue
from functools import lru_cache
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
mod = 10 ** 9 + 7 

def read_values(): return map(int, input().split())
def read_index(): return map(lambda x: int(x) - 1, input().split())
def read_list(): return list(read_values())
def read_lists(N): return [read_list() for n in range(N)]


class Comb:
    def __init__(self, N):
        F = [1] * (N + 1)
        for i in range(N):
            F[i + 1] = (i + 1) * F[i] % mod

        self.d_inv = {}
        self.d_comb = {}
        self.F = F

    def inv(self, a):
        if a not in self.d_inv:
            self.d_inv[a] = pow(a, mod - 2, mod)
        return self.d_inv[a]

    def comb(self, a, b):
        if (a, b) not in self.d_comb:
            self.d_comb[(a, b)] = (self.F[a] * self.inv(self.F[a - b]) * self.inv(self.F[b])) % mod
            self.d_comb[(a, a - b)] = self.d_comb[(a, b)]
        return self.d_comb[(a, b)] 


def main():
    K = int(input())
    S = input().strip()

    F25 = [1] * (K + 2)
    F26 = [1] * (K + 2)
    T = [1] * (K + 2)
    for i in range(K + 1):
        F25[i + 1] = (25 * F25[i]) % mod
        F26[i + 1] = (26 * F26[i]) % mod
        if i != 0:
            T[i] = pow(i, mod - 2, mod)

    r = 1
    res = 0
    for k in range(K + 1):
        res += ((F25[k] * F26[K - k]) % mod * r) % mod
        r *= (len(S) - 1 + k + 1)
        r %= mod
        r *= T[k + 1]
        r %= mod
        res %= mod
     
    print(res)


if __name__ == "__main__":
    main()



Measured memory_bytes: 101544
from decimal import Decimal as de
q,h,s,d=map(de,input().split())
n=de(input())
ans=0

if n%2:
    ans+=min(4*q,2*h,s)
    n-=1
print(int((ans+n*min(4*q,2*h,s,d/2))//1))

Measured memory_bytes: 5076
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
		}
		sc.close();

		boolean[] rf = new boolean[8];
		int wc = 0;
		for (int i = 0; i < n; i++) {
			int r = a[i] / 400;
			if (r < 8) {
				rf[r] = true;
			} else {
				wc++;
			}
		}
		long count = IntStream.range(0, rf.length).filter(i -> rf[i]).count();
		System.out.println(String.format("%d %d", Math.max(count, 1), count + wc));
	}
}


Measured memory_bytes: 28372
#include "bits/stdc++.h"
using namespace std;
int main() {
	int N;
	cin >> N;
	vector<int>V(N+1);
	for (int n = 0;n< N - 1;++n) {
		int m = 0;
		cin >> m;
		V[m]++;
	}
	
	for (int i = 1;i <= N;++i) {
		cout << V[i] << endl;
	}
	return 0;
}

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

struct Edge {
  int to, id;
  Edge(int to, int id): to(to), id(id) {}
};

vector<Edge> g[55];

vector<int> es;
bool dfs(int v, int tv, int p=-1) {
  if (v == tv) return true;
  for (Edge e : g[v]) {
    if (e.to == p) continue;
    if (dfs(e.to, tv, v)) {
      es.push_back(e.id);
      return true;
    }
  }
  return false;
}

int main() {
  int n, m;
  cin >> n;
  rep(i,n-1) {
    int a, b;
    cin >> a >> b;
    --a; --b;
    g[a].emplace_back(b, i);
    g[b].emplace_back(a, i);
  }

  cin >> m;
  vector<ll> eset(m);
  rep(i,m) {
    int a, b;
    cin >> a >> b;
    --a; --b;
    es = vector<int>();
    dfs(a,b);
    for (int e : es) {
      eset[i] |= 1ll<<e;
    }
  }

  ll ans = 0;
  rep(i,1<<m) {
    ll mask = 0;
    rep(j,m) {
      if (i>>j&1) mask |= eset[j];
    }
    int white = __builtin_popcountll(mask);
    ll now = 1ll<<(n-1-white); // 2^(n-1-white)
    if (__builtin_popcountll(i)%2 == 0) ans += now;
    else ans -= now;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256