akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
const int MOD = 998244353;
int m, a, b, c, d[100005], u, k;
ll n, t;
map<ll, int> M;
void as(int a, int b, int c){
	k = M[t = a*n+b] != c;
	if(!M[t] && (M[t] = c)) u++;
	else if(a == 2) as(0,b+1,k+1);
	else if(a == 1) d[b] = k+1;
	else if(k){
		puts("0");
		exit(0);
	}
}
ll exp(ll b, ll n){
	ll res = 1;
	for(; n; n/=2,(b*=b)%=MOD) if(n%2) (res *= b) %= MOD;
	return res;
}
int main(){
	scanf("%lld%d", &n, &m);
	rep(i,m){
		scanf("%d%d%d", &a, &b, &c);
		if(a<b) swap(a, b);
		as(a-b,b-1,c+1);
	}
	rep(i,n) if(d[i] && M[i]){
		as(0,i+1,(M[i]!=d[i])+1);
		d[i] = 0;
	}
	for(int i = n-2; i >= 0; i--) if(d[i] && M[i+1]){
		as(0,i,(M[i+1]!=d[i])+1);
		d[i] = 0;
	}
	rep(i,n) if(d[i]) u++;
	printf("%lld\n", exp(2,n*(n+1)/2-u));
}

Measured memory_bytes: 3840
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
	ll t,ans = 0,c = 1;
	string s;
	cin >> s;
	cin >> t;
	int k = s.size();
	if(s.size() == 1)
	{
		cout << t/2;
		return 0;
	}
	for (int i = 1; i < s.size(); ++i)
	{
		
		if (s[i-1] == s[i])
		{
			c += 1;
		}
		else
		{
			ans += (c/2);
			c = 1;
		}
	}
	ans += (c/2);
	if((s[0] == s[k-1]) )
	{
		int f=1;
		for (int i = 1; i < s.size(); ++i)
		{			
			if(s[i] == s[0])
			{
				f++;
			}
			else
			{
				break;
			}
		}
		if (f == k)
		{
			ans = (k*t)/2;
		}
		else if (c%2 != 0)
		{
			if (f%2 != 0)
			{
				ans = ans+(ans+1)*(t-1);
			}
			else
			{
				ans = ans+ans*(t-1);
			}
			
		}
		else
		{
			ans = ans+ans*(t-1);
		}
	}
	else
	{
		ans *= t;
	}
	cout << ans;
	return 0;
}  

Measured memory_bytes: 256
d,m=1e9+7,dp[10001][2][100];l;
char s[11111];
dfs(i,k,t)
{
	if(i==l)return!k;
	int*r=dp[i][t]+k;
	if(!~*r)
	{
		*r=0;
		int L=t?9:s[i]-48;
		for(int l=0;l<=L;l++)
		{
			*r+=dfs(i+1,(k+l)%d,t|l<L);
			*r%=m;
		}
	}
	return*r;
}
main()
{
	scanf("%s%d",s,&d);
	memset(dp,-1,sizeof dp);
	l=strlen(s);
	printf("%d",(dfs(0,0,0)-1+m)%m);
}


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

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

    static class FloorFunction {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            long a = in.nextLong();
            long b = in.nextLong();
            long n = in.nextLong();

            long border = Math.min(b - 1, n);
            out.append(String.valueOf((int) cal(border, a, b)));

        }

        public double cal(long x, long a, long b) {
            return Math.floor(a * x / b) - a * Math.floor(x / b);
        }

    }
}



Measured memory_bytes: 35812
from math import *
import sys

N = int(input())
all_input_list = [list(map(int, input().split())) for i in range(N)]
x_y_h = [all_input_list[i] for i in range(N) if all_input_list[i][2] > 0][0]
for cx in range(101):
    for cy in range(101):
        flag = 1
        H = x_y_h[2] + abs(cx - x_y_h[0]) + abs(cy - x_y_h[1])
        for input_list in all_input_list:
            if (input_list[2] != max(H - abs(cx - input_list[0]) - abs(cy - input_list[1]), 0)):
                flag = 0
                break
        if (flag == 1):
            print("%s %s %s" % (cx, cy, H))
            sys.exit(0)

Measured memory_bytes: 3064
from math import sqrt

def main():
    n, d = map(int, input().split())
    xy = [list(map(int, input().split())) for _ in range(n)]
    cnt = 0
    for x, y in xy:
        xy_d = sqrt(x**2 + y**2)
        if xy_d <= d:
            cnt +=1
    print(cnt)

if __name__ == '__main__':
    main()

Measured memory_bytes: 45472
import sys

class Node:
    def __init__(self, key):
        self.key = key
        self.parent = None
        self.left = None
        self.right = None

def insert(z):
    global root
    y = None
    x = root
    while x is not None:
        y = x
        if z.key < x.key:
            x = x.left
        else:
            x = x.right
    z.parent = y
    if y is None:
        root = z
    elif z.key < y.key:
        y.left = z
    else:
        y.right = z

def find(node, key):
    if node is None:
        return False
    elif node.key == key:
        return True
    elif node.key > key:
        return find(node.left, key)
    else:
        return find(node.right, key)

def inorderTreeWalk(node):
    global In
    if node:
        inorderTreeWalk(node.left)
        In.append(str(node.key))
        inorderTreeWalk(node.right)

def preorderTreeWalk(node):
    global Pre
    if node:
        Pre.append(str(node.key))
        preorderTreeWalk(node.left)
        preorderTreeWalk(node.right)

if __name__ == "__main__":
    lines = sys.stdin.readlines()
    del lines[0]

    root = None
    for line in lines:
        if line[0] == "p":
            In = []
            Pre = []
            inorderTreeWalk(root)
            print " " + " ".join(map(str, In))
            preorderTreeWalk(root)
            print " " + " ".join(map(str, Pre))
        else:
            com = line.split()
            if com[0][0] == "i":
                insert(Node(int(com[1])))
            else:
                if find(root, int(com[1])):
                    print "yes"
                else:
                    print "no"

Measured memory_bytes: 244208
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
#include <fstream>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    int n, k, z = 0;
    cin >> n >> k;
    while (n) n /= k, z++;
    cout << z;
}


Measured memory_bytes: 3648
#define dbg(fmt,...) fprintf(stderr,fmt,__VA_ARGS__)
#define dpri(x) dbg(#x ": %d\n", x)
#define dprs(x) dbg(#x ": %s\n", x)
#include <stdio.h>
typedef long long ll;
const int MYINF = 1e9+7;

int main(int argc, char **argv)
{
	int n, x, i, j, k, sum;
	for (;;) {
		sum = 0;
		scanf("%d %d", &n, &x);
		if (n == 0 && x == 0) break;
		for (i = 1; i <= n - 2; i++) {
			for (j = i+1; j <= n - 1; j++) {
				for (k = j+1; k <= n; k++) {
					if (i + j + k == x) sum++;
				}
			}
		}
		printf("%d\n", sum);
	}
	return 0;
}

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

int vis[405][405];
char mat[405][405];

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

int main() {
  ios::sync_with_stdio(0), cin.tie(0);
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; ++i) {
    cin >> (mat[i] + 1);
  }
  long long sol = 0;
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) {
      if (vis[i][j]) continue;
      int c1 = 0;
      int c2 = 0;
      queue<array<int, 2>> q;
      for (q.push({i, j}); q.size(); q.pop()) {
        int x = q.front()[0];
        int y = q.front()[1];
        if (vis[x][y]) continue;
        vis[x][y] = 1;
        c1 += mat[x][y] == '#';
        c2 += mat[x][y] == '.';
        for (int i = 0; i < 4; ++i) {
          if (mat[x + dx[i]][y + dy[i]]) {
            if (mat[x][y] != mat[x + dx[i]][y + dy[i]]) {
              q.push({x + dx[i], y + dy[i]});
            }
          }
        }
      }
      sol += 1LL * c1 * c2;
    }
  }
  cout << sol << '\n';
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 510000;
ll dy[8] = {0,1,0,-1,1,-1,1,-1};
ll dx[8] = {1,0,-1,0,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << endl;}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << endl;
}
const int mod = 1e9 + 7;

int main(){
	ll h,n; cin >> h >> n;
	vl a(n),b(n);
	rep(i,n) cin >> a[i] >> b[i];
	vl dp(h+1,linf);
	dp[0] = 0;
	rep(i,h){
		rep(j,n){
			if(dp[i] != linf){
				chmin(dp[min(h,i+a[j])], dp[i]+b[j]);
			} 
		}
	}
	cout << dp[h] << endl;
}

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

long long N, M, a[100009][3], maxn = -(1LL << 60);

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

    for (int i = 0; i < 8; i++)
    {
        vector<long long>vec;
        for (int j = 1; j <= N; j++)
        {
            long long S = 0;
            for (int k = 0; k < 3; k++)
            {
                if ((i / (1 << k)) % 2 == 0)
                    S += a[j][k];
                else
                    S -= a[j][k];
            }
            vec.push_back(S);
        }

        sort(vec.begin(), vec.end());
        reverse(vec.begin(), vec.end());

        long long ans = 0;
        for (int j = 0; j < M; j++)
        {
            ans += vec[j];
        }

        maxn = max(maxn, ans);
    }

    cout << maxn << endl;
    return 0;
}

Measured memory_bytes: 3628
#if __has_include("../library/Basic/Debug.hpp")

#include "../library/Basic/Debug.hpp"

#else

/* ----- Header Files ----- */
// IO
#include <cstdio>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm
#include <algorithm>
#include <cmath>
#include <numeric>

// container
#include <vector>
#include <array>
#include <string>
#include <tuple>
#include <complex>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>

// others
#include <random>
#include <limits>
#include <functional>
#include <ctime>
#include <cassert>
#include <cstdint>

/* ----- Type Alias ----- */
using lint = long long int;
using Real = long double;
template <class T>
using MaxHeap = std::priority_queue<T>;
template <class T>
using MinHeap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

template <class T>
T ndvec(T v) { return v; }

template <class T, class... Ts>
auto ndvec(size_t l, Ts... ts) {
    return std::vector<decltype(ndvec<T>(ts...))>(l, ndvec<T>(ts...));
}

template <class Cost = int>
struct Edge {
    int src, dst;
    Cost cost;
    Edge(int src = -1, int dst = -1, Cost cost = 1)
        : src(src), dst(dst), cost(cost){};

    bool operator<(const Edge<Cost>& e) const { return this->cost < e.cost; }
    bool operator>(const Edge<Cost>& e) const { return this->cost > e.cost; }
};

template <class Cost = int>
using Edges = std::vector<Edge<Cost>>;
template <class Cost = int>
using Graph = std::vector<std::vector<Edge<Cost>>>;

#endif

/* ----- Constants ----- */
constexpr lint INF = std::numeric_limits<lint>::max() / 3;
// constexpr Int MOD = 1000000007;
// const Real PI = acos(-1);
// constexpr Real EPS = 1e-10;
// std::mt19937 mt(int(std::time(nullptr)));

int main() {
    int n;
    lint k;
    std::cin >> n >> k;

    std::vector<lint> a(n), f(n);
    for (auto& x : a) std::cin >> x;
    for (auto& x : f) std::cin >> x;
    std::sort(a.begin(), a.end());
    std::sort(f.rbegin(), f.rend());

    lint ok = INF, ng = -1;
    while (ok - ng > 1) {
        lint mid = (ok + ng) / 2;
        lint rem = k;
        for (int i = 0; i < n; ++i) {
            lint need = mid / f[i];
            rem -= std::max(0LL, a[i] - need);
            if (rem < 0) break;
        }

        (rem < 0 ? ng : ok) = mid;
    }

    std::cout << ok << std::endl;
    return 0;
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
vector<vector<int>> grh;
vector<int> ckd;
stack<int> stk;
vector<vector<int>> revgrh;
vector<int> cmp;
void dfs (int s) {
  ckd[s] = true;
  for (int t : grh[s]) {
    if (!ckd[t]) {
      dfs(t);
    }
  }
  stk.push(s);
}
void efs (int s, int org) {
  cmp[s] = org;
  for (int t : revgrh[s]) {
    if (cmp[t] == -1) {
      efs(t, org);
    }
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  grh.resize(n);
  revgrh.resize(n);
  ckd.resize(n, 0);
  cmp.resize(n, -1);
  for (int i = 0; i < m; i++) {
    int s, t;
    cin >> s >> t;
    grh[s].push_back(t);
    revgrh[t].push_back(s);
  }
  for (int i = 0; i < n; i++) {
    if (!ckd[i]) {
      dfs(i);
    }
  }
  while (!stk.empty()) {
    int org = stk.top();
    stk.pop();
    if (cmp[org] == -1) {
      efs(org, org);
    }
  }
  int q;
  cin >> q;
  while (q--) {
    int u, v;
    cin >> u >> v;
    if (cmp[u] == cmp[v]) {
      cout << 1 << '\n';
    } else {
      cout << 0 << '\n';
    }
  }
  return 0;
}


Measured memory_bytes: 4476
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back
#define INF (1LL<<59)

#define int ll

signed main(){
	int n,k;
	cin>>n>>k;
	vector<int> v(n);
	rep(i,n)cin>>v[i];
	
	int sum = 0;
	rep(i,n)if(v[i]>0)sum+=v[i];
	
	vector<int> p(n+1,0);
	rep(i,n)if(v[i]>0)p[i+1] = v[i];
	
	vector<int> r(n+1,0);
	rep(i,n)r[i+1] = v[i];
	rep(i,p.size()-1)p[i+1]+=p[i];
	rep(i,r.size()-1)r[i+1]+=r[i];
	
	
	int maxi = -INF;
	rep(l,v.size()){
		int rt = l+k-1;
		if(rt>=v.size())break;
		
//		cout<<p[rt+1]-p[l]<<" "<<r[rt+1]-r[l]<<endl;
		int t = sum - (p[rt+1]-p[l])+max<ll>(0,r[rt+1]-r[l]);
//		cout<<t<<endl;
		maxi = max<ll>(t,maxi);
	}
	cout<<maxi<<endl;
}

Measured memory_bytes: 2688
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <vector>
#include <regex>
#include <map>
#include <set>
#include <iomanip>

using namespace std;
using ll = long long;

int main(){
    int n;
    string s;
    cin >> n >> s;
    
	int res = 0;
	for(int j=1;j<n-1;++j){
		set<char> se1,se2,se3;
		for(int i=0;i<j;++i){
			se1.insert(s[i]);
		}
		for(int i=j;i<n;++i){
			se2.insert(s[i]);
		}
		int tmp = 0;
		for(auto a:se1){
			for(auto b:se2){
				if(a == b){
					tmp++;
					break;
				}
			}
		}
		res = max(res,tmp);
	}
	cout << res <<endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>

int main(){
    char b;
    std::cin >> b;
    if(b == 'A') std::cout << 'T' << std::endl;
    else if(b == 'C') std::cout << 'G' << std::endl;
    else if(b == 'G') std::cout << 'C' << std::endl;
    else if(b == 'T') std::cout << 'A' << std::endl;
    return 0;
}


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

int main(){
  string s;
  int a,b,c,d,e,f;
  while(cin >> s){
   a=0;b=0;c=0;d=0;e=0;f=0;
    while(a>=0||d>=0){
      a=s.find("JOI",b);
      d=s.find("IOI",e);
      if(a>=0){
          c++;
          b=a+1;
       }
      if(d>=0){
          f++;
          e=d+1;
      }
    }
    cout << c << endl << f << endl;
  }
  return 0;
}

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

typedef long long LL;
#define PB push_back

using namespace std;

int main(){
  LL n,k;
  cin >> n >> k;
  string s;
  cin >> s;

  for(LL i=0; i < n; i++){
    if(i != k-1){
      cout << s[i];
    }else{
      if(s[i] == 'A')cout << "a";
      else if(s[i] == 'B' ) cout << "b";
      else cout << "c";
    }
  }
  
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
// type alias
typedef long long LL;
typedef pair<int,int> II;
typedef tuple<int,int,int> III;
typedef vector<int> VI;
typedef vector<string> VS;
typedef unordered_map<int,int> MAPII;
typedef unordered_set<int> SETI;
template<class T> using VV=vector<vector<T>>;
// minmax
template<class T> inline T SMIN(T& a, const T b) { return a=(a>b)?b:a; }
template<class T> inline T SMAX(T& a, const T b) { return a=(a<b)?b:a; }
// repetition
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define REPE(i,n)  for(int i=0;i<=(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORR(x,arr) for(auto& x:arr)
#define SZ(a) int((a).size())
// collection
#define ALL(c) (c).begin(),(c).end()
// DP
#define MINUS(dp) memset(dp, -1, sizeof(dp))
#define ZERO(dp) memset(dp, 0, sizeof(dp))
// stdout
#define println(args...) fprintf(stdout, ##args),putchar('\n');
// debug cerr
template<class Iter> void __kumaerrc(Iter begin, Iter end) { for(; begin!=end; ++begin) { cerr<<*begin<<','; } cerr<<endl; }
void __kumaerr(istream_iterator<string> it) { (void)it; cerr<<endl; }
template<typename T, typename... Args> void __kumaerr(istream_iterator<string> it, T a, Args... args) { cerr<<*it<<"="<<a<<", ",__kumaerr(++it, args...); }
template<typename S, typename T> std::ostream& operator<<(std::ostream& _os, const std::pair<S,T>& _p) { return _os<<"{"<<_p.first<<','<<_p.second<<"}"; }
#define __KUMATRACE__ true
#ifdef __KUMATRACE__
#define dump(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); __kumaerr(_it, args); }
#define dumpc(ar) { cerr<<#ar<<": "; FORR(x,(ar)) { cerr << x << ','; } cerr << endl; }
#define dumpC(beg,end) { cerr<<"~"<<#end<<": "; __kumaerrc(beg,end); }
#else
#define dump(args...)
#define dumpc(ar)
#define dumpC(beg,end)
#endif

// $ cp-batch Multiplication1 | diff Multiplication1.out -
// $ g++ -std=c++14 -Wall -O2 -D_GLIBCXX_DEBUG -fsanitize=address Multiplication1.cpp && ./a.out

/*

 5/31/2020

 5:00-

 */

int a,b;

void solve() {
  cout<<a*b<<endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout<<setprecision(12)<<fixed;

  cin>>a>>b;
  solve();

  return 0;
}


Measured memory_bytes: 3656
#include <iostream>
#include <cstdio>
using namespace std;
int n, m, mn=1e9, a[35][35], c[5][35];

int f(int p, int q, int r) {
	int i, re=0;
	for(i=1; i<=m; i++) re += c[0][i] * a[i][p] + c[1][i] * a[i][q] + c[2][i] * a[i][r];
	return re;
}

int main() {
	int i, j, k, t;
	scanf("%d%d", &n, &m);
	for(i=1; i<=m; i++) for(j=1; j<=m; j++) scanf("%d", &a[i][j]);
	for(i=1; i<=n; i++) for(j=1; j<=n; j++) scanf("%d", &t), c[(i+j)%3][t]++;
	for(i=1; i<=m; i++)	for(j=1; j<=m; j++)	for(k=1; k<=m; k++)
		if(i!=j && i!=k && j!=k) mn = min(mn, f(i, j, k));
	printf("%d", mn);
	return 0;
}

Measured memory_bytes: 256
void main()
{
    long n = rdElem;
    long[] a = rdRow;

    long mod = 10L ^^ 9 + 7;
    long modPow(long x, long y)
    {
        long result = 1;
        while (y > 0)
        {
            if (y & 1) result = result * x % mod;
            x = x * x % mod;
            y >>= 1;
        }
        return result;
    }

    long[long] factors;
    foreach (x; a)
    {
        long num = x;
        long[long] lists;
        for (long i = 2; i * i <= num; ++i)
        {
            while (num % i == 0)
            {
                ++lists[i];
                num /= i;
            }
        }
        if (num > 1) ++lists[num];

        foreach (y; lists.byKeyValue)
        {
            if (y.key in factors)
            {
                factors[y.key] = max(factors[y.key], y.value);
            }
            else
            {
                factors[y.key] = y.value;
            }
        }
    }

    long l = 1L;
    foreach (x; factors.byKeyValue)
    {
        l = l * modPow(x.key, x.value) % mod;
    }

    long result;
    foreach (x; a)
    {
        result = (result + l * modPow(x, mod-2)) % mod;
    }

    result.writeln;
}

T rdElem(T = long)()
{
    //import std.stdio : readln;
    //import std.string : chomp;
    //import std.conv : to;

    return readln.chomp.to!T;
}

alias rdStr = rdElem!string;

dchar[] rdDchar()
{
    //import std.conv : to;

    return rdStr.to!(dchar[]);
}

T[] rdRow(T = long)()
{
    //import std.stdio : readln;
    //import std.array : split;
    //import std.conv : to;

    return readln.split.to!(T[]);
}

T[] rdCol(T = long)(long col)
{
    //import std.range : iota;
    //import std.algorithm : map;
    //import std.array : array;

    return iota(col).map!(x => rdElem!T).array;
}

T[][] rdMat(T = long)(long col)
{
    //import std.range : iota;
    //import std.algorithm : map;
    //import std.array : array;

    return iota(col).map!(x => rdRow!T).array;
}

void wrMat(T = long)(T[][] mat)
{
    //import std.stdio : write, writeln;

    foreach (row; mat)
    {
        foreach (j, compo; row)
        {
            compo.write;
            if (j == row.length - 1) writeln;
            else " ".write;
        }
    }
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.container;
import std.typecons;
import std.ascii;
import std.uni;

Measured memory_bytes: 2300
#include <bits/stdc++.h>
//#pragma GCC optimize(2)

using namespace std;

#define LL long long
#define Re register
#define U unsigned
#define forn(i,a,b) for(int i = a;i <= b;++i)
#define nfor(i,a,b) for(int i = a;i >= b;--i)
#define CLR(i,a) memset(i,a,sizeof(i))
#define BR printf("--------------------\n")
#define pb push_back
#define Rep(i,a,b) for(int i=a;i<=b;i++)
#define DEBUG(x) std::cerr << #x << '=' << x << std::endl
const double PI=atan(1.)*4.;
const int maxn=1e6+5;
const int inf = 0x3f3f3f3f;
const int mod=1e9+7;
const double e=2.71828182845904523536;
int dir[4][2]={1,0,0,1,-1,0,0,-1};
int num[maxn];
bool vis[maxn];
int main()
{
	ios::sync_with_stdio(false);
    cin.tie(0);
   	cout.tie(0);
    string s;
    cin>>s;
    memset(vis,false,sizeof(vis));
    int n=s.length();
    int now=1,cnt=1;
    int lftpos=0;
    for(int i=1;i<n;i++)
    {
        if(now==1)
        {
            if(s[i]=='R')
            {
                cnt++;
            }
            else
            {
                vis[i-1]=true;
                num[i-1]=cnt;
                now=2;
                lftpos=i;
                cnt=1;
                vis[i]=true;
            }
        }
        else if(now==2)
        {
            if(s[i]=='L')
            {
                cnt++;
            }
            else
            {
                num[lftpos]=cnt;
                cnt=1;
                now=1;
            }
        }
    }
    num[lftpos]=cnt;
    //DEBUG(n);
    for(int i=0;i<n;i++)
    {
        //DEBUG(i);
        //DEBUG(vis[i]);
        if(!vis[i])
            cout<<"0 ";
        else
        {
            int l=num[i],r=num[i+1];
            int sum=l+r;
            if(l==r)
            {
                cout<<l<<" "<<r<<" ";
            }
            else if(l<r)
            {
                int mi=(l+1)%2;
                int d=(r-l)&1;
                int z=(mi+d)%2;
                l=(sum)/2;
                r=(sum+1)/2;
                if(z&1)
                {
                    cout<<r<<" "<<l<<" ";
                }
                else
                {
                    cout<<l<<" "<<r<<" ";
                }
            }
            else
            {
                int mi=(r+1)%2;
                int d=(l-r)&1;
                int z=(mi+d)%2;
                l=(sum+1)/2;
                r=(sum)/2;
                if(z&1)
                {
                    cout<<r<<" "<<l<<" ";
                }
                else
                {
                    cout<<l<<" "<<r<<" ";
                }
            }
            i++;
        }
    }
	return 0;
}


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

#define watch(x) cerr << (#x) << ": " << (x) << endl
#define int long long

int h, a;

int32_t main() {

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin >> h >> a;

    int ans = (h+a-1)/a;

    cout << ans << '\n';
    
    return 0;
}


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

int main()
{
	int N,C=0;
	while(cin>>N, N)
	{
		cout << "Case " << ++C << ":" << endl;
	
		int x=0,y=0,d=1,i=0,f[9][9];
		while(true)
		{
			f[y][x] = ++i;
			if(i>=N*N) break;

			int nx=x+d,ny=y-d;
			if(nx<0 || N<=nx || ny<0 || N<=ny)
			{
				if(x==N-1)      { y++; d=-d; }
				else if(y==N-1) { x++; d=-d; }
				else if(y==0)   { x++; d=-d; }
				else if(x==0)   { y++; d=-d; }
			}
			else
			{
				x=nx; y=ny;
			}
		}

		for(int y=0; y<N; y++)
		{
			for(int x=0; x<N; x++)
			{
				cout.width(3);
				cout << f[y][x];
			}
			cout << endl;
		}
	}
}

Measured memory_bytes: 0
#include <deque>
#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
#define M 3005
#define LL long long

int m, d, ans;

int main(){
    scanf("%d%d", &m ,&d);
    for(int i = 2; i <= m; i ++){
        for(int j = 11; j <= d; j ++){
            if( i == (j%10) * (j/10) && j%10 > 1 && j/10 > 1 ){
                ans++;
            }
        }
    }
    printf("%d\n", ans);
}


Measured memory_bytes: 256
#include<iostream>
#include<map>
#include<cstring>
#include<cstdio>

using namespace std;

map <int,int> A;
int a[200100];

int main()
{
    int N,K,i,j,k;
    map<int,int>::iterator iter;
    memset(a,0,sizeof(a));
    scanf("%d%d",&N,&K);
    for(i=0;i<N;++i)
    {
        scanf("%d",&j);
        A[j]++;
        a[j]++;
    }
    if(A.size()<=K)printf("0\n");
    else
    {
        k=0;
        j=0;
        while(A.size()-j>K)
        {
            for(iter=A.begin();iter!=A.end();++iter)
            {
                if(iter->second!=0)--iter->second;
                if(a[iter->first]!=-1&&iter->second==0)
                {
                    k+=a[iter->first];
                    a[iter->first]=-1;
                    ++j;
                    if(A.size()-j<=K)break;
                }
            }
        }
    printf("%d\n",k);
    }
    return 0;
}


Measured memory_bytes: 10368
// AOJ 2468: Cache Control
// 2017.11.13 bal4u@uu

#include <stdio.h>

#define HASHSIZ 200009
int hash[HASHSIZ+2], *hashend = hash+HASHSIZ;

int sz;
int id[100005];
char ids[100005][12], *p;

int getint()
{
	int n = 0;
	while (*p >= '0') n = (n<<3) + (n<<1) + (*p++ & 0xf);
	return n;
}

int insert(int n)
{
	int *p = hash + n % HASHSIZ;
	while (*p) {
		if (*p == n) return 0;
		if (++p == hashend) p = hash;
	}
	*p = n;	sz++;
	return 1;
}

int main()
{
	int n, m, i;
	char buf[20];

	fgets(p=buf, 20, stdin);
	n = getint(), p++, m = getint();
	for (i = 0; i < n; i++) {
		fgets(p=ids[i], 12, stdin);
		id[i] = getint();
	}
	for (i = n-1; i >= 0 && sz < m; i--) {
		if (insert(id[i])) printf(ids[i]);
	}
	return 0;
}

Measured memory_bytes: 3500
#include<cstdio>
bool dp[1000001];
bool isprime(int& x){
  for(int i = 2 ; i * i <= x ; i++ ) if( x % i == 0) return true;
  return x == 1;
}
int solve(int& i){
  while(true){
    if(dp[i] && !isprime(i)) return i;
    i--;
  }
}
int main(){
  int n,x,data,ans;
  dp[0] = true;
  while(scanf("%d %d",&n,&x) , n){
    for(int i = 1 ; i <= x ; i++ ) dp[i] = false;
    for(int i = 0 ; i < n ; i++ ){
      scanf("%d",&data);
      for(int i = data ; i <= x ; i++ ) if(dp[i-data]) dp[i] = true;
    }
    if(ans = solve(x)) printf("%d\n",ans);
    else printf("NA\n");
  }
}

Measured memory_bytes: 2016
main = do
    _ <- getLine
    as <- fmap (fmap read . words) getLine
    bs <- fmap (fmap read . words) getLine
    putStrLn $ show $ solve as bs

solve :: [Int] -> [Int]-> Int
solve _ [] = 0
solve (a1:a2:as) (b:bs) = z + solve (a:as) bs
    where a = a2 - max 0 (z-a1)
          z = min (a1+a2) b

Measured memory_bytes: 93436
#include <stdio.h>
int isprime(int n) {
  int i;
  for (i = 2; i * i <= n; i++) {
    if (n % i == 0) {
      return 0;
    }
  }
  return 1;
}
int main() {
  int i;
  int k = 0;
  int n[10000] = {1};
  int p1[10000];
  int q1[10000];
  while (1) {
    scanf("%d", &n[k]);
    if (n[k] == 0) {
      break;
    }
    k++;
  }
  for (i = 0; i < k; i++) {
    while (1) {
      if (isprime(n[i]) == 1 && isprime(n[i] - 2) == 1) {
        p1[i] = n[i] - 2;
        q1[i] = n[i];
        printf("%d %d\n", p1[i], q1[i]);
        break;
	  }
      n[i]--;
    }
  }
  return 0;
}

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

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int res = 0;
        int n = sc.nextInt();
        int m = sc.nextInt();
        int[] H = new int[n];
        int[] arr = new int[n];
        Arrays.fill(arr, 1);
        Arrays.setAll(H, i -> Integer.parseInt(sc.next()));
        for(int i = 0; i < m; i++) {
            int a = Integer.parseInt(sc.next())-1, b = Integer.parseInt(sc.next())-1;
            if(arr[a] == 1 && H[a] <= H[b]) arr[a] = 0;
            if(arr[b] == 1 && H[b] <= H[a]) arr[b] = 0;
        }
        for(int a : arr) {
            res += a;
        }
        System.out.println(res);
    }
}


Measured memory_bytes: 59720
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const int MOD = 1e9+7;
const int larg = 1e5;

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

int main() {
	int m[9];
	rep(i, 9){
		cin >> m[i];
	}
	rep(i, 2){
		int delta = m[i+1] - m[i];
		if(m[i+4]-m[i+3] != delta || m[i+7]-m[i+6] != delta){
			cout << "No";
			return 0;
		}
		delta = m[i*3+3]-m[i*3];
		if(m[i*3+3+1]-m[i*3+1] != delta || m[i*3+3+2]-m[i*3+2] != delta){
			cout << "No";
			return 0;
		}
	}
	cout << "Yes";
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define INF ((1LL<<62)-(1LL<<31))
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define bit(n,m)(((n)>>(m))&1)
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}
ll pom(ll a,ll n,int m){ll x=1;for(a%=m;n;n/=2)n&1?x=x*a%m:0,a=a*a%m;return x;}
//#define MOD 998244353
#define MOD 1000000007
#define invp(a,p)pom(a,p-2,p)

ll n,m,ans;
ll x[99][99];
int main(){
	scanf("%lld%lld",&n,&m);
	if(m-n>4038)m=(m-n)%2019+n+2019;
	ll ans=INF;
	rep(i,n,m)rep(j,i+1,m+1){
		ans=min(ans,i*j%2019);
	}
	printf("%lld",ans);
}

Measured memory_bytes: 128
A,B=map(int,input().split())
N=[2,3,4,5,6,7,8,9,10,11,12,13,1]
a=N.index(A)
b=N.index(B)
if a<b:
    print('Bob')
elif a>b:
    print('Alice')
else:
    print('Draw')
    

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

int main(void){
   
   char a, b, c, d; cin >> a >> b >> c >> d;
   
      if(a == b && b == c && c == d) {
       
       cout << "No" << endl;
   }else{
   
   if(a == b){
       
       if(c == d){
       
           cout << "Yes" << endl;
       
       }else{
           
           cout << "No" << endl;
       }
   }else if(a == c){
       
         if(b == d){
           
           cout << "Yes" << endl;
           
       }else{
           
           cout << "No" << endl;
       }
   }else if(a == d){
       
         if(b == c){
           
           cout << "Yes" << endl;
       }else{
           
           cout << "No" << endl;
       }
   }else{
       cout << "No" << endl;
   }
}
   
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
  using namespace std;
  long long MOD=1000000007;
  #define IOS() ios_base::sync_with_stdio(0); cin.tie(0);
  typedef long long ll;
  #define pb push_back
  typedef pair<ll,ll> pi;

int main()
{
  IOS();
  ll n,w;
  cin>>n>>w;
  ll value_sum=0ll;

  ll a[n+1];
  ll values[n+1];
  ll ans=0ll;

  a[0]=0ll;
  values[0]=0ll;

  for (ll i = 1; i <=n; ++i)
  {
    cin>>a[i]>>values[i];
    value_sum+=values[i];
  }

  ll dp[n+1][value_sum+1];
  
  dp[0][0]=0ll;

   for(ll i=1;i<=value_sum;i++)
  {
    dp[0][i]=INT_MAX;
  }

  for(ll i=1;i<=n;i++)
  {
    for(ll j=0;j<=value_sum;j++)
    {
      if(j<values[i])
        dp[i][j]=dp[i-1][j];
      else
       dp[i][j]=std::min(dp[i-1][j],a[i]+dp[i-1][j-values[i]]);

      if(dp[i][j]<=w)
        ans=std::max(ans,j);
    }
  }

  cout<<ans<<endl;

  
  return 0;
}

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

using namespace std;

#define FOR(i, m, n) for (int i = m; i < n; ++i)
#define FORD(i, m, n) for (int i = m; i >= n; --i)
#define REP(i, n) for (int i = 0; i < n; ++i)
#define REP1(i, n) for (int i = 0; i <= n; ++i)
#define REPR(i, n) for (int i = n; i >= 0; --i)
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

using ll = long long;
using ull = unsigned long long;
using ld = long double;

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

	string s;
	cin>>s;
	if(s[0]==s[1]&&s[1]!=s[2]&&s[2]==s[3])cout << "Yes" << endl;
	else if(s[0]==s[2]&&s[1]==s[3]&&s[0]!=s[1])cout << "Yes" << endl;
	else if(s[0]==s[3]&&s[1]==s[2]&&s[0]!=s[1])cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 3600
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1e9+7;
const ll N=2666;
ll n,k,c[N][N];
ll C(ll n,ll m)
{
    if(n<m) return 0;
    if(c[n][m]) return c[n][m];
    if(m==0||n==m) return 1;
    if(m==1) return n;
    return c[n][m]=(C(n-1,m-1)+C(n-1,m))%mod;
}
int main()
{
    scanf("%lld%lld",&n,&k);
    ll s=n-k;
    for(ll i=1;i<=k;i++)
        printf("%lld\n",C(k-1,i-1)*C(n-k+1,i)%mod);
}


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

int main() {
    long long n,c=1,b=0;
    cin>>n;
 
    for(int i=0;i<n;i++) {
        int a;
        cin>>a;
        if(a==c) c++;
        else b++;
        
    }
        
    if(c==1) cout<<"-1\n";
    else cout<<b << "\n";
    
	return 0;
}


Measured memory_bytes: 3580
import java.util.*;
public class Main {

	private static Scanner sc;

	public static void main(String[] args) {
		sc = new Scanner(System.in);
		int x = sc.nextInt();
		int sum=0;
		int z=0;
		for(int i=0;i<=x;i++) {
			sum=i*(i+1)/2;
			if(x<=sum){
				z=i;
				break;
			}
		}
		System.out.println(z);

	}

}


Measured memory_bytes: 23892
# coding: utf-8
# Your code here!

N, X = map(int, input().rstrip().split(' '))
L = list(map(int, input().rstrip().split(' ')))

cumsum = 0
count = 0
for i in range(N):
    cumsum += L[i]
    if X >= cumsum:
        count += 1
    else:
        break
    
print(count + 1)

Measured memory_bytes: 38496
#include <bits/stdc++.h>
using namespace std;
template<typename T = int> vector<T> create(size_t n){ return vector<T>(n); }
template<typename T, typename... Args> auto create(size_t n, Args... args){ return vector<decltype(create<T>(args...))>(n, create<T>(args...)); }
const int maxn = 18;
int f[1<<maxn][55], a[2][maxn], n;
int solve(int msk, int lst){
	if(msk == (1<<n) - 1) return 0;
	if(~f[msk][lst]) return f[msk][lst];
	int ans = (1<<30), l = n - __builtin_popcount(msk), r = 0;
	for(int i = n - 1; i >= 0; i--){
		if((msk>>i)&1) r++;
		else {
			l--;
			int sig = (l % 2) ^ (r % 2);
			if(a[sig][i] >= lst){
				ans = min(ans, solve(msk | (1<<i), a[sig][i]) + l);
			}
		}
	}
	return f[msk][lst] = ans;
}
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> n;
	for(int r = 0; r < 2; r++) for(int i = 0; i < n; i++) cin >> a[r][i];
	memset(f, -1, sizeof(f));
	int p = solve(0, 0);
	if(p > n * n) p = -1;
	cout << p << endl;
	return 0;
}


Measured memory_bytes: 56704
#include <iostream>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
const int maxn = 4e5+10;
int n,tmp,a[100005];
ll cnt[100005];
int ret,id1,id2;
struct tree{
	int left;
	int right;
	ll max_num;
	int id;
	int flag;
}node[maxn];


void gx(int o){
	if(node[o*2].flag==-1&&node[o*2+1].flag==-1){
		if(node[o*2].max_num==node[o*2+1].max_num){
			node[o].max_num=node[o*2].max_num;
			node[o].flag=-1;
			node[o].id=node[o*2].id;
		}else{
			if(node[o*2].max_num>=node[o*2+1].max_num){
				node[o].max_num=node[o*2].max_num;
				node[o].id=node[o*2].id;
			}else{
				node[o].max_num=node[o*2+1].max_num;
				node[o].id=node[o*2+1].id;
			}
			node[o].flag=0;
		}
	}else{
			if(node[o*2].max_num>=node[o*2+1].max_num){
				node[o].max_num=node[o*2].max_num;
				node[o].id=node[o*2].id;
			}else{
				node[o].max_num=node[o*2+1].max_num;
				node[o].id=node[o*2+1].id;
			}
			node[o].flag=0;
	}
}

void build(int o,int l,int r){
	node[o].left=l;
	node[o].right=r;
	
	if(l==r){
		node[o].max_num=a[l];
		node[o].flag=-1;
		node[o].id=l;
		return;
	}
	build(o*2,l,(l+r)/2);
	build(o*2+1,(l+r)/2+1,r);
	
	gx(o);
}

void find_max(int o,int ql,int qr){
	if(ql<=node[o].left&&qr>=node[o].right){
		if(node[o].max_num>ret){
			ret=node[o].max_num;
			id2=node[o].id;
			return;
		}
	}else{
		int mid=(node[o].left+node[o].right)>>1;
		if(ql<=mid)find_max(o*2,ql,qr);
		if(qr>mid)find_max(o*2+1,ql,qr);
	}
}
 
void change(int o,int ql,int qr){
	
	if(node[o].max_num<=ret)return;
	if(node[o].flag==-1){
		cnt[id1]+=(node[o].max_num-ret)*(node[o].right-node[o].left+1);
		node[o].max_num=ret;
		return;
	}
	if(node[o].left==node[o].right){
		cnt[id1]+=(node[o].max_num-ret);
		node[o].max_num=ret;
		return;
	}
	int mid=(node[o].left+node[o].right)>>1;
	if(ql<=mid)change(o*2,ql,qr);
	if(qr>mid)change(o*2+1,ql,qr);
	
	gx(o);
}

void ans(int o,int l,int r){
	if(node[o].flag==-1){
		cnt[1]+=(node[o].right-node[o].left+1)*node[o].max_num;
		return;
	}
	if(l==r){
		cnt[1]+=node[o].max_num;
		return;
	}
	ans(o*2,l,(l+r)/2);
	ans(o*2+1,(l+r)/2+1,r);
}
int main(int argc, char** argv) {
	//freopen("in.txt","r",stdin);
	cin>>n;int x;ll sum=0;
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
        sum+=a[i];
	}
	build(1,1,n);
	//for(int i=1;i<=20;i++)cout<<node[i].left<<"-"<<node[i].right<<":"<<node[i].id<<"-"<<node[i].max_num<<endl;
	ret=node[1].max_num,id1=node[1].id;
	if(id1==1){
		cout<<sum<<endl;
		for(int i=2;i<=n;i++)cout<<0<<endl;
		return 0; 
	}
	while(id1!=1){
		ret=-1;
		find_max(1,1,id1-1);
		change(1,id1,n);
		id1=id2;
	
	}
	ans(1,1,n);
	//cout<<sizeof(long long)<<endl;
	for(int i=1;i<=n;i++)cout<<cnt[i]<<endl;
	return 0;
}

Measured memory_bytes: 11648
/* BISMILLAHIR RAHMANIR RAHIM */
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
 
int main() {
    ios_base :: sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    vector<int> a(3);
  	for(auto& i : a) cin >> i;
  	sort(a.begin(), a.end());
  	if( a[0] == a[1] and a[1] != a[2] ) cout << "Yes";
  	else if( a[1] == a[2] and a[1] != a[0] ) cout << "Yes";
  	else                                cout << "No";
}

Measured memory_bytes: 256
fn get_line() -> String {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().to_string()
}

fn reads<T>() -> Vec<T>
    where
        T: std::str::FromStr,
        <T as std::str::FromStr>::Err: std::fmt::Debug {
    get_line().split(' ').map(|x| x.parse().unwrap()).collect()
}

fn readln<T>() -> T
    where
        T: std::str::FromStr,
        <T as std::str::FromStr>::Err: std::fmt::Debug {
    get_line().parse().unwrap()
}

use std::collections::BinaryHeap;

fn main() {
    let n: i64 = readln();
    let mut xs: Vec<i64> = reads();

    xs.sort();

    let mut q = BinaryHeap::new();
    for x in xs {
        q.push(x);
    }

    let mut res = 0i64;
    loop {
        let x = q.pop().unwrap();
        let y = x + res;

        if y >= n {
            let m = (y - n + 1) % n;
            let r = (y - n + 1) / n +
            if m > 0 {
                1
            }
            else {
                0
            };

            res += r;

            q.push(x - (n + 1) * r);
        }
        else {
            break;
        }
    }

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


Measured memory_bytes: 4352
#include <iostream>
#include <stdio.h>
#include <vector>

typedef long long ll;

#define rep(i,n) for(int i = 0; i < n; i++)
#define debug(x) cerr << #x << ": " << x << "\n";

using namespace std;
 
const ll INF = ll(1e18)+1;
const double PI=3.14159265358979323846;

int main(){
  int N, M, total = 0;
  cin >> N >> M;

  int x;  
  rep(i,M){
    cin >> x;
    total+=x;
  }
  if(N-total<0) cout << -1 << endl;
  else cout << N-total << endl;
  
}


Measured memory_bytes: 3636
let solve h w c =
  let v0 = Array.make w 0 in
  let v1 = Array.make w 0 in
  let r = ref 0 in
  for i = 0 to h - 1 do if c.(i).(0) = 0 then r := 1 done;
  for j = 0 to w - 1 do if c.(0).(j) = 0 then begin v0.(j) <- 1; r := 1 end done;
  for i = 1 to h - 1 do
    if c.(i).(0) = 0 then v1.(0) <- 1;
    for j = 1 to w - 1 do
      if c.(i).(j) = 1 then v1.(j) <- 0
      else begin
        let t = if v0.(j) < v1.(j-1) then v0.(j) else v1.(j-1) in
        v1.(j) <- if v0.(j-1) < t then v0.(j-1) + 1 else t + 1;
        r := if v1.(j) > !r then v1.(j) else !r;
      end
    done;
    Array.iteri (fun i e -> v0.(i) <- e) v1
  done;
  !r * !r

let split_on_char sep s =
  let open String in
  let r = ref [] in
  let j = ref (length s) in
  for i = length s - 1 downto 0 do
    if get s i = sep then begin
      r := sub s (i + 1) (!j - i - 1) :: !r;
      j := i
    end
  done;
  sub s 0 !j :: !r

let read () = List.map int_of_string (split_on_char ' ' (read_line ()))

let () =
  match read () with
  | [h; w] ->
    let c = Array.make_matrix h w 0 in
    for i = 0 to h - 1 do
      let rec doit j = function
        | [] -> ()
        | x::xs ->
          c.(i).(j) <- x;
          doit (j + 1) xs in
      doit 0 (read ())
    done;
    Printf.printf "%d\n" (solve h w c)
  | _ -> ()

Measured memory_bytes: 25416
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define vi vector<int>
#define vll vector<ll>
#define vvll vector<vll>
#define vvi vector<vector<int>>
#define vvb vector<vector<bool>>
#define vb vector<bool>
#define pii pair<int, int>
#define vpli vector<pair<long long, int>>
#define deb(x) cout << "deb " << #x << " " << x << endl
#define all(x) x.begin(), x.end()
#define endl "\n"

void solve()
{
    int n;
    cin>>n;
    string s;
    cin>>s;
    int rc=0,wc=0;
    for(char &x : s)
    {
        if(x == 'R') rc++;
        else wc++;
    }
    string s1;
    for(int i=0;i<rc;i++) s1 += 'R';
    for(int i=0;i<wc;i++) s1 += 'W';
    int cnt = 0;
    for(int i=0;i<(int)s.size();i++)
    {
        if(s1[i] != s[i]) cnt++;
    }
    cout<<cnt/2<<endl;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    //pre();
    int t = 1;
    //cin >> t;
    //cout<<__gcd(-5,0)<<endl;
    while (t--)
        solve();
    return 0;
}


Measured memory_bytes: 3868
N = int(input())

count = [[0] * 10 for _ in range(10)]
for i in range(1, N + 1):
    s = str(i)
    head = int(s[0])
    tail = int(s[-1])
    count[head][tail] += 1

ans = 0
for a in range(1, N + 1):
    s = str(a)
    head = int(s[0])
    tail = int(s[-1])
    ans += count[tail][head]
print(ans)

Measured memory_bytes: 9144
using System;
using System.Collections.Generic;
using System.Linq;
class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner() {
        s = new string[0];
        i = 0;
    }

    public string next() {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int Int() {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0) {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++) {
            Array[i] = Int() + add;
        }
        return Array;
    }

    public long Long() {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0) {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++) {
            Array[i] = Long() + add;
        }
        return Array;
    }
}
class Program {
    static Scanner cin = new Scanner();
    static void Main() {
        int T = cin.Int();
        int X = cin.Int();
        Console.WriteLine((double)T / X);
        Console.ReadLine();
    }
}

Measured memory_bytes: 11092
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <map>
#include <iostream>

using namespace std;
map <pair <string, string> , int> cnt;

long long res;
int n;
char s[40];
int main() 
{
	scanf("%d%s", &n, s);
	for (int i = 0; i < (1 << n); i++) {
		string s1 = "", s2 = "";
		for (int j = 0; j < n; j++) {
			if(i & (1 << j)) s1 += s[j];
			else s2 += s[j];
		}
		cnt[make_pair(s1, s2)]++;
	}
	for (int i = 0; i < (1 << n); i++) {
		string s1 = "", s2 = "";
		for (int j = n - 1; j >= 0; j--) {
			if(i & (1 << j)) s1 += s[j + n];
			else s2 += s[j + n];
		}
		res += cnt[make_pair(s2, s1)];
	}
	printf("%lld\n", res);
	return 0;
}


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

int main() {
	int n;
	cin >> n;
	
	
	if (n >= 30) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 3632
x=int(input())
if x<7:
    print(1)
if x==7:
    print(2)
if x>7:
    if x%11==0:
        print(x//11*2)
    if x%11==1:
        print(x//11*2+1)
    if x%11==2:
        print(x//11*2+1)
    if x%11==3:
        print(x//11*2+1)
    if x%11==4:
        print(x//11*2+1)
    if x%11==5:
        print(x//11*2+1)
    if x%11==6:
        print(x//11*2+1)
    if x%11==7:
        print(x//11*2+2)
    if x%11==8:
        print(x//11*2+2)
    if x%11==9:
        print(x//11*2+2)
    if x%11==10:
        print(x//11*2+2)

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

using namespace std;
typedef long long ll;

const int MAX_N=1e5+5;

int main(void){
    string s;
    cin >>s;
    char res;
    if(s[0]=='A')   res='T';
    if(s[0]=='T')   res='A';
    if(s[0]=='C')   res='G';
    if(s[0]=='G')   res='C';
    cout <<res <<endl;

    return 0;
}


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

using namespace std;

#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

int main(){
    string S;
    cin >> S;
    bool flag;
    REP(i,S.length()/2-1){
        flag = true;
        REP(j,S.length()/2-1-i){
            if(S[j]==S[j+S.length()/2-1-i]&&flag){
                flag = true;
            }else{
                flag = false;
                break;
            }
        }
        if(flag){
            cout << S.length()-2*(i+1);
            break;
        }
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb(x) push_back(x)
#define rep(a,b) for(ll int a=0;a<b;a++)
#define Tcase int t;cin>>t;while(t--)
int main(){
  long long int a,b,k;
  cin>>a>>b>>k;
  if(k<=a){
  a=a-k;k=0;
  }
  else{
     k=k-a;
  a=0;
  }
 // cout<<k<<endl;
  if(k<=b){
    b=b-k;
  }
  else
    b=0;
  cout<<a<<" "<<b<<endl;
return 0;
}


Measured memory_bytes: 256