akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
ll N,Q;
int main(){
 cin>>N>>Q;
 ll c1=N;ll c2=N;
  ll sum=0;map<ll,ll>xx;map<ll,ll>yy;
  set<ll>X;set<ll>Y;X.insert(0);Y.insert(0);
  for(ll i=0;i<Q;i++){
  ll x;cin>>x;
    if(x==1){
    ll y;cin>>y;Y.insert(y);auto itr=Y.lower_bound(y);itr--;
      if(*itr==0){
    sum+=(c2-2);yy[y]=c2;
      if(y<c1)c1=y;
      }else{
      ll c=yy.at(*itr);
        sum+=(c-2);yy[y]=c;
       if(y<c1)c1=y;
      }
    }else{
     ll y;cin>>y;X.insert(y);auto itr=X.lower_bound(y);itr--;
      if(*itr==0){
    sum+=(c1-2);xx[y]=c1;
      if(y<c2)c2=y;
      }else{
      ll c=xx.at(*itr);
        sum+=(c-2);xx[y]=c;
       if(y<c2)c2=y;
      }
    }
  }ll ans=(N-2)*(N-2);
  ans-=sum;
  cout<<ans<<endl;
  return 0;
}
    

Measured memory_bytes: 25476
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {
    private static final Reader reader = new Reader();

    public static void main(String[] args) throws Exception{
        int[] inp = reader.readIntArray();
        int n = inp[0];
        int k = inp[1];
        int[] nums = reader.readIntArray();
        Arrays.sort(nums);
        int sum = 0;
        for(int i=0;i<k;i++){
            sum+=nums[i];
        }
        System.out.println(sum);
    }

    private static int difference(int n,int b1,int b2){
        int diff = Math.abs(b1-b2);
        return Math.min(n-diff,diff);
    }

    private static class Reader{
        private final BufferedReader br;
        public Reader(){
            br = new BufferedReader(new InputStreamReader(System.in));
        }
        public int readInt() throws Exception{
            return Integer.parseInt(br.readLine());
        }
        public int readLong() throws Exception {
            return Integer.parseInt(br.readLine());
        }
        public double readDouble() throws Exception {
            return Double.parseDouble(br.readLine());
        }
        public String readLine() throws Exception{
            return br.readLine();
        }
        public int[] readIntArray() throws Exception{
            String[] tokens = br.readLine().split(" ");
            int[] nums = new int[tokens.length];
            for(int i=0;i<tokens.length;i++){
                nums[i] = Integer.parseInt(tokens[i]);
            }
            return nums;
        }
        public long[] readLongArray() throws Exception{
            String[] tokens = br.readLine().split(" ");
            long[] nums = new long[tokens.length];
            for(int i=0;i<tokens.length;i++){
                nums[i] = Long.parseLong(tokens[i]);
            }
            return nums;
        }
        public double[] readDoubleArray() throws Exception {
            String[] tokens = br.readLine().split(" ");
            double[] nums = new double[tokens.length];
            for(int i=0;i<tokens.length;i++){
                nums[i] = Double.parseDouble(tokens[i]);
            }
            return nums;
        }
        public String[] readWords() throws Exception {
            return br.readLine().split(" ");
        }
    }
}

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


using namespace std;
#define rep(i,n) for (int i = 0; i < (int)(n); ++i)
#define reps(i,n) for (int i = 1; i <= (int)(n); ++i)
#define repd(i,n) for (int i = (int)(n - 1); i >= 0; --i)
#define repds(i,n) for (int i = (int)(n); i > 0; --i)
#define loop(i,x,n) for (int i = (int)(x); i < (n); ++i)
#define loops(i,x,n) for (int i = (int)(x); i <= (n); ++i)
#define loopd(i,x,n) for (int i = (int)(x); i > (n); --i)
#define loopds(i,x,n) for (int i = (int)(x); i >= (n); --i)
#define itrep(i,s) for (auto i = begin(s); i != end(s); ++i)
#define itrepd(i,s) for (auto i = --end(s); i != begin(s); --i)
#define all(f,x,...) [&](decltype(x)& whole) { return (f)(begin(whole), end(whole), ##__VA_ARGS__); }(x)
#define rall(f,x,...) [&](decltype(x)& whole) { return (f)(rbegin(whole), rend(whole), ##__VA_ARGS__); }(x)
using ll = long long;
using ld = long double;
constexpr ll inf = static_cast<ll>(1e17);
constexpr int iinf = static_cast<int>(1e9);
constexpr double dinf = 1e10;
constexpr ld ldinf = 1e17;
constexpr ll mod = static_cast<ll>(1e9 + 7);
std::ostream& endn(std::ostream& os) { return os.put(os.widen('\n')); }
template<class T> constexpr int sz(const T& a) { return (int)a.size(); }
template<class T, class ... Args> constexpr T mins(T& a, Args... args) { return a = min<T>({ a, args... }); }
template<class T, class... Args> constexpr T maxs(T& a, Args... args) { return a = max<T>({ a,args... }); }

int n, m;
vector<int> to[1005];
vector<int> bfs(int s) {
    vector<int> prev(n, -1);
    queue<int> que;
    que.push(s);
    while (!que.empty()) {
        auto p = que.front(); que.pop();

        for (auto& v : to[p]) {
            if (v == s) {
                vector<int> res;
                auto nv = p;
                while (nv != -1) {
                    res.push_back(nv);
                    nv = prev[nv];
                }
                return res;
            }
            if (prev[v] != -1) continue;

            prev[v] = p;
            que.push(v);
        }
    }

    return vector<int>(n + 1);
}

void solve() {
    cin >> n >> m;

    rep(i, m) {
        int a, b; cin >> a >> b; --a, --b;
        to[a].push_back(b);
    }

    vector<int> ans(n + 1);
    rep(i, n) {
        auto res = bfs(i);
        if (res.size() < ans.size()) ans = res;
    }

    if (ans.size() == n + 1) { cout << -1 << endn; return; }

    cout << ans.size() << endn;
    for (auto& v : ans) cout << v + 1 << endn;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
    cout << flush;
    return 0;
}


Measured memory_bytes: 384
// 2014/11/12 Tazoe

#include <iostream>
using namespace std;

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

	int M[200][3];
	for(int i=0; i<N; i++){
		for(int j=0; j<3; j++){
			cin >> M[i][j];
		}
	}

	for(int j=0; j<3; j++){
		int cnt[101] = {0};

		for(int i=0; i<N; i++){
			cnt[M[i][j]]++;
		}

		for(int i=0; i<N; i++){
			if(cnt[M[i][j]]>=2){
				M[i][j] = 0;
			}
		}
	}

	for(int i=0; i<N; i++){
		cout << M[i][0]+M[i][1]+M[i][2] << endl;
	}

	return 0;
}

Measured memory_bytes: 1164
#include<bits/stdc++.h>
using namespace std;
bool check(int p)
{
	if(p%9==0)
	return true;
	else
	return false;
}
int main()
{
	string s;
	cin>>s;
	int i;
	int sum=0;
	for(i=0;i<s.length();i++)
	{
		sum+=s[i]-'0';
	}
	bool x=check(sum);
	if(x==true)
	cout<<"Yes";
	else
	cout<<"No";
	
}

Measured memory_bytes: 3692
#include <algorithm>
#include <iostream>

using namespace std;
using ll = long long;

int main() {
    ll N;
    cin >> N;
    ll A[N];
    for (int i = 0; i < N; ++i) {
        cin >> A[i];
        A[i] -= i + 1;
    }

    sort(A, A + N);
    ll b = A[N / 2];

    ll ans = 0;
    for (int i = 0; i < N; ++i) {
        ans += abs(A[i] - b);
    }

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


Measured memory_bytes: 1792
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	sc.Split(bufio.ScanWords)

	n := nextInt()
	ans := 1 << 63 - 1

	for i := 1; i*i <= n; i++ {
		if n % i == 0 {
			if ans > i+n/i-2 {
				ans = i+n/i-2
			}
		}
	}

	fmt.Println(ans)
}


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

int main(){
	
	int n;
	cin >> n;
	if (n%2 == 1) {
		cout << 0;
		return 0;
	}
	vector<int> v(n);
	for (int& x: v){
		cin >> x;
	}
	sort(v.begin(),v.end());
	int elem1 = v[n/2-1];
	int elem2 = v[n/2];
	//cout << elem1 << elem2;
	if (elem1!=elem2) cout << elem2 - elem1;
	else cout << 0;
	
}


Measured memory_bytes: 640
#include<map>
#include<vector>
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
map<string,int> cnt;
vector<string> s;
int main() {
	#ifdef LOACL
	freopen("in.txt","r",stdin);
	freopen("out.txt","w",stdout);
	#endif
	int N,M;
	scanf("%d",&N);
	for(int i=1;i<=N;i++) {
		string t;
		cin>>t;
		cnt[t]++;
		s.push_back(t);
	}
	scanf("%d",&M);
	for(int i=1;i<=M;i++) {
		string t;
		cin>>t;
		cnt[t]--;
		s.push_back(t);
	}
	unique(s.begin(),s.end());
	int ans=0;
	for(int i=0;i<s.size();i++)
		ans=max(ans,cnt[s[i]]);
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	static int MOD = 1000*1000*1000+7;

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

		Arrays.sort(a);
		Arrays.sort(b);

		int j = 0;
		int k = 0;

		long ans = 1;
		int status = 0;

		while (j<n || k<n) {
			if (j>=n || (k < n && a[j]>b[k])) {
				if (status > 0) {
					ans = (ans*status)%MOD;
				}
				status--;
				k++;
			} else {
				if (status < 0) {
					ans = (ans*(-status))%MOD;
				}
				status++;
				j++;
			}
		}

		System.out.println(ans);
	}

}


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

const int Inf = 10000 * 100000 + 100;

int main(){
  int V,E,R;
  cin >> V >> E >> R;
  vector<int> s(E),t(E),d(E);
  for(int i = 0; i < E; i++)
    cin >> s[i] >> t[i] >> d[i];
  vector<int> cost(V, Inf);
  cost[R] = 0;

  for(int p = 0; p < V; p++){
    bool update = false;
    for(int i = 0; i < E; i++){
      int ns = s[i], nt = t[i], nd = d[i];
      if(cost[ns] < Inf && cost[ns] + nd < cost[nt]){
        update = true;
        cost[nt] = cost[ns] + nd;
      }
    }
    if(!update) break;
  }

  for(int i = 0; i < V; i++){
    if(cost[i] == Inf)
      cout << "INF";
    else
      cout << cost[i];

    cout << endl;
  }
}

Measured memory_bytes: 8764
N=int(input())
a=list(map(int,input().split()))
gray=brown=green=lblue=blue=yellow=orange=red=any=0
mini=0
maxi=0

for i in a:
    if i >= 1 and i <= 399 and gray==0:
        gray+=1 
    elif i >= 400 and i <= 799 and brown==0:
        brown+=1
    elif i >= 800 and i <= 1199 and green==0:
        green+=1
    elif i >= 1200 and i <= 1599 and lblue==0:
        lblue+=1
    elif i >= 1600 and i <= 1999 and blue==0:
        blue+=1    
    elif i >= 2000 and i <= 2399 and yellow==0:
        yellow+=1
    elif i >= 2400 and i <= 2799 and orange==0:
        orange+=1
    elif i >= 2800 and i <= 3199 and red==0:
        red+=1
    elif i >= 3200:
        any+=1
    else:
        pass
if gray+brown+green+lblue+blue+yellow+orange+red==0 and any>=1:
    mini=1
else:
    mini=gray+brown+green+lblue+blue+yellow+orange+red
maxi=gray+brown+green+lblue+blue+yellow+orange+red+any
print(mini,maxi)

Measured memory_bytes: 3064
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;
import java.util.StringTokenizer;
import java.util.stream.LongStream;
import java.util.stream.Stream;

public class Main {
    public static void main(final String[] args) {
        final FastScanner scanner = new FastScanner(System.in);
        final long n = scanner.nextLong();
        final Map<Long, Long> map = primeFactorization(n);
        final long sum = map.values().stream()
            .mapToLong(value -> LongStream.iterate(1, l -> l * (l + 1) / 2 <= value, l -> l + 1)
                .reduce((l1, l2) -> l2)
                .orElseThrow())
            .sum();
        System.out.println(sum);
    }

    private static Map<Long, Long> primeFactorization(long n) {
        final double sqrt = Math.sqrt(n);
        final Map<Long, Long> countMap = new HashMap<>();
        for (long i = 2; i <= sqrt; i++) {
            if (n % i == 0) {
                countMap.compute(i, (k, v) -> v = v == null ? 1 : v + 1);
                n /= i;
                i--;
            }
        }

        if (n != 1) {
            countMap.compute(n, (k, v) -> v = v == null ? 1 : v + 1);
        }

        return countMap;
    }

    private static class FastScanner {
        private final BufferedReader reader;
        private StringTokenizer tokenizer;

        FastScanner(final InputStream in) {
            reader = new BufferedReader(new InputStreamReader(in));
        }

        String next() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (final IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

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

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

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

        String nextLine() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    return reader.readLine();
                } catch (final IOException e) {
                    throw new RuntimeException(e);
                }
            }

            return tokenizer.nextToken("\n");
        }
    }
}


Measured memory_bytes: 34624
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define BIG 1000000010
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
typedef long long int ll;

struct xy{
  int x,y;
};

int main(){
  int dx[4]={0,1,0,-1};
  int dy[4]={1,0,-1,0};
  int h,w,ans=0;
  xy p;
  queue<pair<int,xy>> q;
  pair<int,xy> a;
  cin>>h>>w;
  char mp[1010][1010];
  repi(i,1,h+1){
    repi(j,1,w+1){
      cin>>mp[i][j];
      if(mp[i][j]=='#'){
	p.x=i;
	p.y=j;

	a=make_pair(0,p);
	q.push(a);
      }
    }
  }
  while(1){
    if(q.empty()) break;
   
    pair<int,xy> c;
    c=q.front();
    p=c.second;
    int b=c.first;
    q.pop();
    ans=max(ans,b);
    rep(i,4){
      if(p.x+dx[i]==0 || p.x+dx[i]==h+1 || p.y+dy[i]==0 || p.y+dy[i]==w+1) continue;
      else if(mp[p.x+dx[i]][p.y+dy[i]]=='.'){
	xy P;
	P=p;
	mp[p.x+dx[i]][p.y+dy[i]]='#';
	P.x=p.x+dx[i];P.y=p.y+dy[i];
	a=make_pair(b+1,P);
	q.push(a);
      }
    }
  }
  cout<<ans<<endl;
  
  return 0;
}




Measured memory_bytes: 13328
#include <bits/stdc++.h>
using Int = long long;  // clang-format off
#define REP_(i, a_, b_, a, b, ...) for (Int i = (a), lim##i = (b); i < lim##i; i++)
#define REP(i, ...) REP_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define ALL(v) std::begin(v), std::end(v)
struct SetupIO { SetupIO() { std::cin.tie(nullptr), std::ios::sync_with_stdio(false), std::cout << std::fixed << std::setprecision(13); } } setup_io;
#ifndef dump
#define dump(...)
#endif  // clang-format on

/**
 *    author:  knshnb
 *    created: Sat Aug 29 21:18:24 JST 2020
 **/

template <class T> T pow(T x, long long n, const T UNION = 1) {
    T ret = UNION;
    while (n) {
        if (n & 1) ret *= x;
        x *= x;
        n >>= 1;
    }
    return ret;
}

/// @docs src/Math/ModInt.md
template <int Mod> struct ModInt {
    int x;
    static int runtime_mod;
    static std::unordered_map<int, int> to_inv;
    // テンプレート引数が負のときは実行時ModInt
    static int mod() { return Mod < 0 ? runtime_mod : Mod; }
    static void set_runtime_mod(int mod) {
        static_assert(Mod < 0, "template parameter Mod must be negative for runtime ModInt");
        runtime_mod = mod;
        to_inv.clear();
    }
    ModInt() : x(0) {}
    ModInt(long long x_) {
        if ((x = x_ % mod() + mod()) >= mod()) x -= mod();
    }

    ModInt& operator+=(ModInt rhs) {
        if ((x += rhs.x) >= mod()) x -= mod();
        return *this;
    }
    ModInt& operator*=(ModInt rhs) {
        x = (unsigned long long)x * rhs.x % mod();
        return *this;
    }
    ModInt& operator-=(ModInt rhs) {
        if ((x -= rhs.x) < 0) x += mod();
        return *this;
    }
    ModInt& operator/=(ModInt rhs) {
        x = (unsigned long long)x * rhs.inv().x % mod();
        return *this;
    }
    ModInt operator-() const { return -x < 0 ? mod() - x : -x; }
    ModInt operator+(ModInt rhs) const { return ModInt(*this) += rhs; }
    ModInt operator*(ModInt rhs) const { return ModInt(*this) *= rhs; }
    ModInt operator-(ModInt rhs) const { return ModInt(*this) -= rhs; }
    ModInt operator/(ModInt rhs) const { return ModInt(*this) /= rhs; }
    bool operator==(ModInt rhs) const { return x == rhs.x; }
    bool operator!=(ModInt rhs) const { return x != rhs.x; }
    ModInt inv() const { return to_inv.count(this->x) ? to_inv[this->x] : (to_inv[this->x] = pow(*this, mod() - 2).x); }

    friend std::ostream& operator<<(std::ostream& s, ModInt<Mod> a) {
        s << a.x;
        return s;
    }
    friend std::istream& operator>>(std::istream& s, ModInt<Mod>& a) {
        long long tmp;
        s >> tmp;
        a = ModInt<Mod>(tmp);
        return s;
    }
    friend std::string to_string(ModInt<Mod> a) { return std::to_string(a.x); }
};
template <int Mod> std::unordered_map<int, int> ModInt<Mod>::to_inv;
template <int Mod> int ModInt<Mod>::runtime_mod;

#ifndef CALL_FROM_TEST
using mint = ModInt<1000000007>;
#endif

signed main() {
    Int n;
    std::cin >> n;
    mint sum = 0, sum2 = 0;
    REP(i, n) {
        Int x;
        std::cin >> x;
        sum += x;
        sum2 += x * x;
    }
    std::cout << (sum * sum - sum2) / 2 << std::endl;
}


Measured memory_bytes: 3612
R, C, K = map(int, input().split())

V = [[0]*(C+1) for _ in range(R+1)]
for _ in range(K):
    r, c, v = map(int, input().split())
    V[r][c] = v

dp0 = [[0]*(C+1) for _ in range(R+1)]
dp1 = [[0]*(C+1) for _ in range(R+1)]
dp2 = [[0]*(C+1) for _ in range(R+1)]
dp3 = [[0]*(C+1) for _ in range(R+1)]
for i in range(R+1):
    for j in range(C+1):
        v = V[i][j]

        a = dp0[i][j]
        b = dp0[i][j]
        c = dp0[i][j]
        d = dp0[i][j]

        pa = pb = pc = pd = 0
        if i > 0:
            pa = dp0[i-1][j]
            pb = dp1[i-1][j]
            pc = dp2[i-1][j]
            pd = dp3[i-1][j]

        la = lb = lc = ld = 0
        if j > 0:
            la = dp0[i][j-1]
            lb = dp1[i][j-1]
            lc = dp2[i][j-1]
            ld = dp3[i][j-1]

        a = max(a, pa)
        b = max(b, pa+v)
        a = max(a, la)

        a = max(a, pb)
        b = max(b, pb+v)
        b = max(b, lb, la+v)

        a = max(a, pc)
        b = max(b, pc+v)
        c = max(c, lc, lb+v)

        a = max(a, pd)
        b = max(b, pd+v)
        d = max(d, ld, lc+v)

        dp0[i][j] = a
        dp1[i][j] = b
        dp2[i][j] = c
        dp3[i][j] = d

print(max(dp0[R][C], dp1[R][C], dp2[R][C], dp3[R][C]))


Measured memory_bytes: 432928
import numpy as np

def main():
    k, q = [int(x) for x in input().split()]
    d = np.fromstring(input(), np.int64, sep=' ')

    def solve1(d, n):
        # 同じ場合
        zero = np.where(d == 0)[0]
        n_zero = zero.shape[0] * ((n - 1) // k)
        n_zero += np.count_nonzero(zero < (n - 1) % k)
        return n_zero

    def solve2(d, n, x, m):
        # 小さくなる場合
        a_max = np.sum(d) * ((n - 1) // k) + np.sum(d[:(n - 1) % k])
        return (a_max + x) // m - x // m

    for _ in range(q):
        n, x, m = [int(x) for x in input().split()]
        dm = d % m
        n_zero = solve1(dm, n)
        n_dec = solve2(dm, n, x, m)
        print(n - 1 - n_zero - n_dec)

if __name__ == '__main__':
    main()

Measured memory_bytes: 12524
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define int long long int

template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}

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

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
constexpr ll INF = 1001001001001001LL;
constexpr ll MOD = 1000000007LL;

bool used[10];
string S;
int N, M, len, ma, ans;

void solve(int p, int num) {
    if(p == len) {
        int v = min(abs(N - num), M - abs(N - num));
        if(ma <= v) {
            if(ma < v) ans = num;
            else chmin(ans, num);
            ma = v;
        }
    }
    else {
        rep(i,0,10) {
            if(used[i]) continue;
            used[i] = true;
            solve(p+1, num*10 + i);
            used[i] = false;
        }
    }
}

signed main() {
    cin >> S;
    len = S.length();
    N = atoll(S.c_str());
    M = 1; ans = INF;
    rep(i,0,len) M *= 10;
    solve(0, 0);
    string res = to_string(ans);
    int rest = len - res.length();
    rep(i,0,rest) res = '0' + res;
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 3276
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
#include <random>
#include <cassert>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
#define MEM(a,b) memset((a),(b),sizeof(a))
const LL INF = 1e9 + 7;
const int N = 2e5 + 10;
int a[N];
int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int n;
	cin >> n;
	for (int i = 0; i <= n; i++) cin >> a[i];
	LL ans = 0;
	for (int i = 0; i < n; i++)
	{
		int x;
		cin >> x;
		for (int j = 0; j < 2; j++)
		{
			int o = min(x, a[i + j]);
			ans += o;
			x -= o;
			a[i + j] -= o;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 640
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		Scanner scn = new Scanner(System.in);
		long X = scn.nextLong();
		long ans = 0;
		while(true) {
			ans++;
			if(ans * (ans + 1)/2 >= X)break;
		}
		System.out.println(ans);
	}

}


Measured memory_bytes: 21844
#include <iostream>

using namespace std;

int main()
{
	int coin[6] = {500, 100, 50, 10, 5, 1};
	int cost;
	
	
	while (cin >> cost, cost){
		int count = 0;
		cost = 1000 - cost;
		 
		for (int i = 0; i < 6; i++){
			if (cost >= coin[i]){
				count += cost / coin[i];
				cost %= coin[i];
			}
		}
		
		cout << count << endl;
	}
	return (0);
}

Measured memory_bytes: 1160
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <tuple>

using ll = long long;
using namespace std;
#define modmod 1000000007

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,k,n) for(int i=k;i<n;i++)





int main(){
    ll H,W;
    cin >> H >> W;

    ll result;

    if(H % 3 == 0){
        cout << 0 << endl;
        return 0;
    }else{
        result = W;
    }

    if(W % 3 == 0){
        cout << 0 << endl;
        return 0;
    }else{
        result = min(result,H);
    }

    REP(x,1,W){
   long long a = H*x;
   long long y = H/2;
   long long b = (W-x) * y;
   long long c = (W-x) * (H-y);
   result = min(max({a,b,c})-min({a,b,c}),result);

 }
 REP(y,1,H){
   long long a = W*y;
   long long x = W/2;
   long long b = (H-y) * x;
   long long c = (H-y) * (W-x);
   result = min(max({a,b,c})-min({a,b,c}),result);
 }

    cout << result << endl;

    return 0;
}


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

const int N=1e5+5,zqm=1e9+7;
int f[N][2];
vector<int> g[N];

void dfs(int u,int fa) {
	f[u][0]=f[u][1]=1;
	for(int v:g[u]) if(v!=fa) {
		dfs(v,u);
		f[u][0]=(f[u][0]*1ll*(f[v][0]+f[v][1]))%zqm;
		f[u][1]=(f[u][1]*1ll*f[v][0])%zqm;
	}
	//cerr<<u<<' '<<f[u][0]<<' '<<f[u][1]<<endl;
}

int main() {
	//freopen("in.txt","r",stdin);
	//freopen("out.txt","w",stdout);
	
	int n; scanf("%d",&n);
	for(int i=1,u,v;i<n;++i) {
		scanf("%d%d",&u,&v);
		g[u].push_back(v),g[v].push_back(u);
	}
	dfs(1,0);
	printf("%d\n",(f[1][0]+f[1][1])%zqm);
	
	return 0;
}


Measured memory_bytes: 13440
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
using u64 = unsigned long long;
#define REP(i, n) for (int i = 0; (i64)(i) < (i64)(n); ++i)

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int X, Y, Z, K;
  cin >> X >> Y >> Z >> K;
  vector<i64> A(X), B(Y), C(Z);
  for (auto& x : A) cin >> x;
  for (auto& x : B) cin >> x;
  for (auto& x : C) cin >> x;
  sort(A.rbegin(), A.rend());
  sort(B.rbegin(), B.rend());
  sort(C.rbegin(), C.rend());
  priority_queue<tuple<i64, int, int, int>> que;
  set<tuple<int, int, int>> done;
  que.emplace(A[0] + B[0] + C[0], 0, 0, 0);
  int cnt = 0;

  while (que.size()) {
    i64 sm = get<0>(que.top());
    int ai = get<1>(que.top());
    int bi = get<2>(que.top());
    int ci = get<3>(que.top());
    que.pop();
    auto tpl = make_tuple(ai, bi, ci);
    if (done.count(tpl)) {
      continue;
    }
    done.insert(tpl);
    cout << sm << "\n";
    if (++cnt == K) break;
    if (ai + 1 < X && !done.count(make_tuple(ai + 1, bi, ci))) {
      que.emplace(A[ai + 1] + B[bi] + C[ci], ai + 1, bi, ci);
    }
    if (bi + 1 < Y && !done.count(make_tuple(ai, bi + 1, ci))) {
      que.emplace(A[ai] + B[bi + 1] + C[ci], ai, bi + 1, ci);
    }
    if (ci + 1 < Z && !done.count(make_tuple(ai, bi, ci + 1))) {
      que.emplace(A[ai] + B[bi] + C[ci + 1], ai, bi, ci + 1);
    }
    que.emplace();
  }
}

Measured memory_bytes: 640
#include<cstdio>
#include<algorithm>
using namespace std;
char p[301000];
long long S = 1;
int C[26];
int main(){
    int i, j;
    scanf("%s",p);
    for(i=0;p[i];i++)C[p[i]-'a']++;
    for(i=0;i<26;i++)for(j=i+1;j<26;j++)S += 1ll*C[i]*C[j];
    printf("%lld\n",S);
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define all(x) (x).begin(),(x).end()
#define INF 10000000
using ll = long long ;

using namespace std;

int main(){
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    int start = max(a,c);
    int end = min(b,d);
    
    cout << max(0,end-start) << endl;
    
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(void)
{
    int n;
    int ans[100]={0};
    int kari;
    
    while(cin>>n)
        ans[n]++;
    
    kari=ans[0];
    for(int i=1;i<99;i++)
    {
        if(kari<ans[i])
            kari=ans[i];
    }
    
    for (int i=0; i<100; i++)
    {
        if(kari==ans[i])
            cout<<i<<endl;
    }
    
    return 0;
}

Measured memory_bytes: 1160
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<vector>
#include<string>
#include<bitset>
#include<queue>
#include<set>
#include<map>
using namespace std;

#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define ROF(i,b,a) for (int i=(b);i>(a);--i)
#define REP(i,n) FOR(i,0,n)
#define PER(i,n) ROF(i,n-1,-1)

typedef int i32;
typedef long long int i64;
typedef unsigned long long int ui64;
typedef float f32;
typedef double f64;
typedef long double f128;
typedef pair<int,int> Pi;

constexpr int INF = 1e9 + 7;
constexpr int dx[4] = {1,0,-1,0}, dy[4] = {0,1,0,-1};

i64 gcd(i64 a,i64 b) {
    if (b==0) return a;
    return gcd(b,a%b);
}

int main() {
    int N; cin>>N;
    i64 T;
    i64 ans = 1;
    REP(i,N) {
        cin>>T;
        ans *= T/gcd(T,ans);
    }
    cout<<ans<<endl;
}


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

#define pb push_back
#define sz size()

using namespace std;

const int N = 1e6 + 1;

typedef long double ld;

int n;

ld a[N];
ld dp[3005][3005];

main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    cin>> n;
    for(int i = 1; i <= n; i++){
        cin>> a[i];
    }
    dp[0][0] = 1.0;
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            dp[i + 1][j + 1] += dp[i][j] * a[i + 1];
            dp[i + 1][j] += dp[i][j] * (1.0 - a[i + 1]);
        }
    }
    double ans = 0.0;
    for(int i = (n + 1) / 2; i <= n; i++)ans+=dp[n][i];
    cout<<fixed<< setprecision(9)<< ans;
}


Measured memory_bytes: 141568
from collections import deque
import numpy as np

N = int(input())
B = list(map(int, input().split()))
Ans = deque()
Sa = np.zeros(N)
for a, b in enumerate(B):
    Sa[a] = a-b+1
while 0 in Sa:
    for i in range(N)[::-1]:
        if Sa[i] == 0:
            Ans.appendleft(B[i])
            Sa[i:] -= 1
            break
if len(Ans) != N:
    print(-1)
else:
    for i in range(len(Ans)):
        a = Ans.popleft()
        print(a)


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

int main(void){
	char s[100]={'\0'};
	int n;
	int i;

	scanf("%s",s);
	n=strlen(s);
	for(i=0;i<n/2;i++){
		if(s[i]!=s[n-i-1]){
			printf("No");
			exit(0);
		}
	}
	if(n>=5){
		for(i=0;i<n/4;i++){
			if(s[i]!=s[(n+1)/2-i-2]&&s[(n+3)/2+i-1]!=s[n-i-1]){
				printf("No");
				exit(0);
			}
		}
	}
	printf("Yes");
	return 0;
}


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


int main() {
    int n;
    const int q = 1000000007;
    cin >> n;
    vector<long long> a(n,0); 
    vector<long long> b(n,0); 
    long long s=0;
    for (int i=0; i<n; i++) {
        cin >> a[i];
        s = (s+a[i])%q;
        if (i==0) b[i] = a[i];
        else      b[i] = (a[i] + b[i-1])%q;
    }
    long long sum = (s*s)%q;
    // cout << sum << endl;
    for (int i=0; i<n; i++) {
        long long ab = (a[i]*b[i])%q;
        // cout << a[i] <<"*" << b[i] << "="<<ab << endl;
        sum = (sum - ab)%q;
        if (sum<0) sum += q; 
    }
    // cout << -4/3 <<"," <<-4%3<< endl;
    // long long sum = 0;
    // for (int i=0; i<n-1; i++) {
    //     // cout << s << "-" << b[i]<< "="<< (s - b[i])%q<< endl;
    //     sum=(sum+(a[i]*(s - b[i])%q)%q)%q;
    // }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 6416
#include <iostream>
#include <string>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <bitset>
#include <functional>
#include <queue>
#include <utility>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define dump(x)  cerr << #x << " = " << (x) << endl;
typedef long long LL;

using namespace std;

int main(void)
{
	int N, M;
	vector<pair<LL, int>> AB;

	cin >> N >> M;
	FOR(i, 0, N) {
		LL A, B;
		cin >> A >> B;
		AB.push_back(pair<int, int>(A, B));
	}

	// ABのA(値段)が小さい順にソート
	// 昇順ソート
	sort(AB.begin(), AB.end(), [](const pair<LL, int> &x, const pair<LL, int> &y) {
		return x.first < y.first;
	});

	LL yen = 0;
	LL bottles = 0;
	FOR(i, 0, AB.size()) {
		if (bottles + AB[i].second < M) {
			yen += AB[i].first * AB[i].second;
			bottles += AB[i].second;
		}
		else {
			yen += AB[i].first * (M - bottles);
			bottles += (M - bottles);
			break;
		}
	}

	cout << yen << endl;

	return 0;
}

Measured memory_bytes: 2420
#include <bits/stdc++.h>
#define ll long long
#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))
#define INF = 1001001001
#define pi = acos(-1)
using namespace std;
int gcd(int x, int y) { return (x % y)? gcd(y, x % y): y; }


int main(){
    ll n; cin >> n;
    ll d = 0;
    int ans = 0;

    vector<pair<ll,int>> res;
    for (ll i=2; i*i<=n; i++) {
        int y = 0;
        while (n%i == 0) n /= i, ++y;
        if (y != 0) res.emplace_back(i,y);
    }
    if (n != 1) res.emplace_back(n,1);

    for(auto p: res){
        int x = p.second;
        int i = 1;
        while (i<=x){
            x -= i;
            i++;
            ans++;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3632
#include<iostream>
#include<algorithm>
#include<cmath>
#include<map>
#include<stdio.h>
#include<vector>
using namespace std;
#define int long long
#define rep(s,i,n) for(int i=s;i<n;i++)
#define c(n) cout<<n<<endl;
#define ic(n) int n;cin>>n;
#define sc(s) string s;cin>>s;
#define mod 1000000007
#define inf 1000000000000000007
#define f first
#define s second
#define mini(c,a,b) *min_element(c+a,c+b)
#define maxi(c,a,b) *max_element(c+a,c+b)
//printf("%.12Lf\n",);
int keta(int x){
	rep(0,i,30){
		if(x<10){
			return i+1;
		}
		x=x/10;
	}
}
int gcd(int x,int y){
	int aa=x,bb=y;
	rep(0,i,1000){
		aa=aa%bb;
		if(aa==0){
			return bb;
		}	
		bb=bb%aa;
		if(bb==0){
			return aa;
		}
	}
}	
int lcm(int x,int y){
	int aa=x,bb=y;
	rep(0,i,1000){
		aa=aa%bb;
		if(aa==0){
			return x/bb*y;
		}	
		bb=bb%aa;
		if(bb==0){
			return x/aa*y;
		}
	}
}
bool p(int x){
	if(x==1)return false;
	rep(2,i,sqrt(x)+1){
		if(x%i==0&&x!=i){
			return false;
		}
	}	
	return true;
}
int max(int a,int b){
	if(a>=b)return a;
	else return b;
}
int min(int a,int b){
	if(a>=b)return b;
	else return a;
}	
int n2[41];		
int nis[41]; 
int nia[41];
int mody[41];
int nn;
int com(int n,int y){
	int ni=1;
	for(int i=0;i<41;i++){
		n2[i]=ni;
		ni*=2;
	}
	int bunsi=1,bunbo=1;
	rep(0,i,y)bunsi=(bunsi*(n-i))%mod;
	rep(0,i,y)bunbo=(bunbo*(i+1))%mod;
	mody[0]=bunbo;
	rep(1,i,41){
		bunbo=(bunbo*bunbo)%mod;
		mody[i]=bunbo;
	}
	rep(0,i,41)nis[i]=0;
	nn=mod-2;
	for(int i=40;i>=0;i-=1){
		if(nn>n2[i]){
			nis[i]++;
			nn-=n2[i];
		}
	}
	nis[0]++;
	rep(0,i,41){
		if(nis[i]==1){
			bunsi=(bunsi*mody[i])%mod;
		}
	}
	return bunsi;
}
int yakuwa(int n){
	int sum=0;
	rep(1,i,sqrt(n+1)){
		if(n%i==0)sum+=i+n/i;
		if(i*i==n)sum-=i;
	}
	return sum;
}	
bool hei(int n){
	rep(0,i,100){
		if(i*i==n){
			return true;
		}
	}
	return false;
}
int pow(int b,int a){	
	int aa=1;
	rep(0,i,a)aa*=b;	
	return aa;
}
int a[114514];
int sum[114514];
signed main(){
	ic(n) ic(k)
	c(n-k+1)
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int a,b;
bool ok=true;
int main(){
	cin>>a>>b;
	if(a<=0&&b>=0)cout<<"Zero"<<endl;
	else if(a>0) cout<<"Positive"<<endl;
	else if((abs(a)-abs(b))%2==1) cout<<"Positive"<<endl;
	else cout<<"Negative"<<endl;
	
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <map>
#include <vector>
#define REP(i,n) for(int i=0;i<(int)n;i++)
#define REP1(j,n) for(int j=0;j<(int)n;j++)
#define REPS(i,n) for(int i=1;i<=(int)n;i++)
#define SZ(x) ((int)(x).size())	//size() unsigned -> int
using namespace std;
typedef long long ll;

int main() {
	int n, i;
	cin >> n >> i;
	cout << n - i + 1 << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rf(x) (x)=0;while(*p<48)p++;while(47<*p)(x)=((x)<<3)+((x)<<1)+(*p++&15);
#define pb push_back
#define eb emplace_back
#define sz(V) ((int)(V).size())
#define befv(V) ((V)[(sz(V)-2)])
#define allv(V) ((V).begin()),((V).end())
#define sorv(V) sort(allv(V))
#define revv(V) reverse(allv(V))
#define univ(V) (V).erase(unique(allv(V)),(V).end())
#define clv(V) (V).clear()
#define upmin(a,b) (a)=min((a),(b))
#define upmax(a,b) (a)=max((a),(b))
#define rb(x) ((x)&(-(x)))
#define INF (0x3f3f3f3f)
#define INFLL (0x3f3f3f3f3f3f3f3fll)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

vector<pii> G[105][105];
bitset<105> chk[105];

vector<int> V;

int A[55];

int H, W;

int f(int y, int x) {
	int ret = 1; chk[y][x] = true;
	for(pii &v : G[y][x]) {
		if(chk[v.first][v.second]) continue;
		ret += f(v.first, v.second);
	}
	return ret;
}

int main() {
	scanf("%d%d", &H, &W);
	for(int i = 0; i < H*W; i++) {
		char c; scanf(" %c", &c);
		A[c-'a']++;
	}

	for(int i = 0; i < H; i++) {
		for(int j = 0; j < W; j++)
			G[i][j].eb(i, W-j-1);
	}
	for(int j = 0; j < W; j++) {
		for(int i = 0; i < H; i++)
			G[i][j].eb(H-i-1, j);
	}

	for(int i = 0; i < H; i++) for(int j = 0; j < W; j++)
		if(!chk[i][j]) V.eb(f(i, j));
	
	sorv(V); revv(V);

	for(int v : V) {
		bool flag = false;
		int mx = -1, mxi = -1;
		for(int i = 0; i < 26; i++) {
			if(A[i] <= mx) continue;
			mx = A[i];
			mxi = i;
		}
		if(mx < v) {
			puts("No");
			return 0;
		}

		A[mxi] -= v;
	}

	puts("Yes");
	return 0;
}

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

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

  ll N; cin >> N;
  ll K; cin >> K;
  vector<ll> A(N); for (ll i = 0; i < N; i++) cin >> A[i];

  vector<ll> S(N + 1, 0);
  for (int i = 0; i < N; i++) {
    A[i]--;
    S[i + 1] = (S[i] + A[i]) % K;
  }

  ll ans = 0;
  map<ll, int> m;
  for (int i = 0; i < N + 1; i++) {
    ans += m[S[i] % K];
    m[S[i] % K]++;
    if (i + 1 - K >= 0) m[S[i + 1 - K] % K]--;
  }
  
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 15872
#include <iostream>
#include <cstdlib>
#include <string>
#include <cstdio>
using namespace std;

struct Node{
    int key;
    Node *right,*left,*parent;
};

Node *root ,*NIL;

void insert(int k){
    Node *y = NIL;
    Node *x = root;
    Node *z;

    z = (Node *)malloc(sizeof(Node));
    z ->key = k;
    z ->left = NIL;
    z ->right = NIL;

    while (x != NIL){
        y = x ;
        if (z -> key < x -> key){
            x = x -> left;
        } else{
            x = x -> right;
        }
    }
    z -> parent = y;
    if(y == NIL){
        root = z;
    }else{
        if (z -> key < y -> key){
            y -> left = z;
        }else{
            y -> right = z;
        }
    }
}

void inorder (Node *u){
    if(u == NIL) return;
    inorder(u->left);
    cout << " " << u -> key;
    inorder(u->right);
}

void preorder (Node *u){
    if(u == NIL) return;
    cout << " " <<u->key;
    preorder(u->left);
    preorder(u->right);
}

int main(){
    int n,x;
    string com;
    cin >> n;

    for (int i = 0; i < n ; ++i) {
        cin >> com;
        if(com == "insert"){
            cin >> x;
            insert(x);
        }else if(com == "print"){
            inorder(root);
            cout << endl;
            preorder(root);
            cout << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 24648
import java.util.Scanner;
class Main{

	
	public static void main(String[] a) {
		Scanner keyboad=new Scanner(System.in);
			int yama[]=new int[10];
			for(int i=0;i<10;i++){
				yama[i]=keyboad.nextInt();
			}
			int mob=0;
			int ans[]=new int[3];
			int mem[]=new int[3];
			for(int j=0;j<3;j++){
			for(int i=0;i<10;i++){
				if(i==0){
					mob=yama[i];
				}
				else{
					if(mob<yama[i]){
						mob=yama[i];
						mem[j]=i;
					}
				}
				ans[j]=mob;
			}
		yama[mem[j]]=-1;
			}
			for(int i=0;i<3;i++){
				System.out.println(ans[i]);
			}
	}

}

Measured memory_bytes: 17164
#![allow(unused_imports)]
use std::cmp::*;
use std::collections::*;
use itertools::Itertools;
use num::clamp;
use proconio::{input, marker::*, fastout};
use superslice::*;

#[fastout()]
fn main() {
    input! {
        s: Chars
    }

    let mut g = true;
    let mut ans = 0;
    for c in s {
        if g && c == 'p' {
            ans -= 1;
        } else if !g && c == 'g' {
            ans += 1;
        }
        g = !g;
    }
    println!("{}", ans);
}


Measured memory_bytes: 2568
from collections import deque
import sys
input = sys.stdin.readline
sys.setrecursionlimit(4100000)


def main():
    a = deque(input())
    a.pop()

    a_append = a.append
    a_appendleft = a.appendleft

    Q = int(input())
    count = 0
    for _ in range(Q):
        q = list(input().split())
        if q[0] == "1":
            count += 1
        else:
            if count % 2 == 0:
                if q[1] == "1":
                    a_appendleft(q[2])
                else:
                    a_append(q[2])
            else:
                if q[1] == "1":
                    a_append(q[2])
                else:
                    a_appendleft(q[2])

    b = list(a)
    if count % 2 != 0:
        b.reverse()
    print("".join(b))


if __name__ == '__main__':
    main()


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

int main(){
  int N;
  cin >> N;
  long I = 1;
  for(int i=1;i<=N;i++){
    I *= i;
    int z = std::pow(10, 9.0)+7;
    I %= z;
  }
  cout << I << endl;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
from itertools import accumulate
INF = float("inf")


def solve(N: int, K: int, p: "List[int]"):

    acc = [0]+list(accumulate(p))
    m, mi = 0, 0
    for i in range(N-K+1):
        if acc[i+K]-acc[i] > m:
            m = acc[i+K]-acc[i]
            mi = i
    print((m+K)/2)
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    p = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, K, p)


if __name__ == '__main__':
    main()


Measured memory_bytes: 34196
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.IO.Compression;
using System.Linq;
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Text;
using System.Text.RegularExpressions;
using Console = System.Console;

namespace Atcoder
{

    class Program
    {
        private const long COMDIV = 1000000007;

        static void Main(string[] args)
        {
            var NM = Console.ReadLine().Split().Select(long.Parse).ToArray();
            if (NM[0] * 2 >= NM[1])
            {
                Console.WriteLine(Math.Truncate((double)NM[1] / 2));
            }
            else
            {
                var remain = NM[1] - NM[0] * 2;
                Console.WriteLine(NM[0] + Math.Truncate((double)remain / 4));
            }
        }
    }
}

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

int main()
{
    int a, b, k;
    cin >> a >> b >> k;
    
    for (int i = 0; i < k; i++){
        if (i % 2 == 0){
            if (a % 2 != 0){
                a -= 1;
            }
            b += a / 2;
            a /= 2;
        }else{
            if (b % 2 != 0){
                b -= 1;
            }
            a += b / 2;
            b /= 2;
        }
    }
    cout << a << " " << b << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
const ll mod=1000000007;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
// head

int a,b,c;
int main() {
	scanf("%d%d%d",&a,&b,&c);
	if (c<=a+b) printf("%d\n",b+c);
	else printf("%d\n",2*b+a+1);
}


Measured memory_bytes: 256
from collections import defaultdict,deque
mod = 10**9+7
N = int(input())
g = [[] for _ in range(N)]
d = defaultdict(lambda:-1)
p2 = [1]*(N+1)
p2[1] = pow(2,mod-2,mod)
for i in range(N):
    p2[i+1] = (p2[i]*p2[1])%mod

for i in range(N-1):
    a,b = map(int,input().split())
    a -= 1
    b -= 1
    g[a].append(b)
    g[b].append(a)

q = deque([[a,b]])
while q:
    i,j = q.pop()
    s = 1
    f = True
    for k in g[j]:
        if k == i:
            continue
        if (j,k) not in d:
            if f:
                q.append([i,j])
            q.append([j,k])
            f = False
        else:
            s += d[(j,k)]
    if f:
        d[(i,j)] = s

q = deque([[b,a]])
while q:
    i,j = q.pop()
    s = 1
    f = True
    for k in g[j]:
        if k == i:
            continue
        if (j,k) not in d:
            if f:
                q.append([i,j])
            q.append([j,k])
            f = False
        else:
            s += d[(j,k)]
    if f:
        d[(i,j)] = s

ans = 1-p2[N]-N*p2[1]

for i in range(N):
    for j in g[i]:
        if j<i:
            continue
        n = max(d[(i,j)],d[(j,i)])
        ans += (1-p2[n])*(1-p2[N-n])
        ans %= mod

print(ans)

Measured memory_bytes: 142368
import Data.List.Split
type Dir = [Double]
type Round = Double

solve :: Round -> Dir -> [Double] -> Dir
solve _ d [] = d
solve r [f,s] (x:y:xs) = solve (y+r) (f+x*sin (pi/180*r) : s+x*cos (pi/180*r):[]) xs

floor' :: Double -> Int
floor' d
  | d < 0 = (0-) $ floor $ -d
  | otherwise = floor d

main = getContents >>= putStr . unlines . map (show . floor') . solve 0 [0,0] . map read . concat . map (splitOn ",") . lines

Measured memory_bytes: 4276
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=998244353;
main(){
   ll n,s,a,i,j,dp[6005]={1};
   cin>>n>>s;
   for(i=0;i<n;i++){
        cin>>a;
        for(j=s;j>=0;j--){
            dp[j+a]=(dp[j+a]+dp[j])%mod;
            dp[j]=dp[j]*2%mod;
        }
   }
   cout<<dp[s];
}


Measured memory_bytes: 3728
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>


using namespace std;
using ll = long long;
using ull = unsigned long long;

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

#define REP(i, n) for(ll i = 0; i < n; i++)




int main() {
    double n, m, d;
    cin >> n >> m >> d;
    
    if(d != 0){
        printf("%.8lf\n", 2.0 * (n - d) / (n * n) * (m - 1));
    }
    else{
        printf("%.8lf\n", 1.0 / n * (m - 1));
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
//using namespace boost::multiprecision;
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> P;
#define PI 3.141592653589793
#define MOD 1000000007
//#define MOD 998244353
#define ALL(obj) (obj).begin(),(obj).end()
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 ll INF = 1LL << 60;

//四方向への移動ベクトル
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

struct edge{//グラフに使うヤツ
    ll from,to,cost;
};

typedef vector<vector<edge> > G;
ll gcd(ll a,ll b){
    if (a%b==0)return(b);
    else return(gcd(b,a%b));
}

int main() {
    ll n,m;
    cin >> n;
    map<string,ll> red;
    map<string,ll> blue;
    for (ll i=0;i<n;i++){
        string a;
        cin >> a;
        if (blue.count(a)){
            blue[a]++;
        }else{
            blue[a]=1;
        }
    }
    cin >> m;
    for (ll i=0;i<m;i++){
        string a;
        cin >> a;
        if (red.count(a)){
            red[a]++;
        }else{
            red[a]=1;
        }

    }
    ll ans=0;
    for (auto b: blue){
        string s=b.first;
        if (blue[s]>red[s]){
            ans=max(ans,blue[s]-red[s]);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define REP(i, n) for (int (i) = 0; (i) < (int)(n); i++) 
#define FOR(i, a, b) for(int (i) = a; (i) < (int)b; i++)
#define RREP(i, n) for(int (i)=((int)(n)-1); (i)>=0; i--)
#define RFOR(i, a, b) for(int (i) =((int)(b)-1); (i)>=(int)a; i--)
#define ALL(v) (v).begin(),(v).end()
#define MOD 1000000007
#define F first
#define S second

using namespace std ;
typedef long long ll;
typedef vector<int> vint;
typedef vector<vint> vvint;
typedef pair<int, int> pint;
const int Inf = 1e9;
const double EPS = 1e-9;



int main()
{
  int n, x, y ;
  cin >> n >> x ;
  vector<int> m(n) ;
  int sum = 0 ;
  int ans ;
  
  REP(i,n){
    cin >> m.at(i) ;
    sum += m.at(i) ;
  }
  
  sort(ALL(m)) ;
  y = x-sum ;
  
  ans = n + y/m.at(0) ;
  
  cout << ans <<endl ;

  return 0 ;
}


Measured memory_bytes: 256