akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

int main(void){
    int n;
    cin >> n;
    int a[n],b[n];
    for(int i = 0;i < n;i++)cin >> a[i] >> b[i];
    int max = 0,c = 0;
    for(int i = 0;i < n;i++){
        if(max < a[i]){
            max = a[i];
            c = b[i];
        }
    }
    cout << max+c;
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <string>
#include <cmath>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <set>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define INF (ll)1e18
#define MOD (ll)1e9 + 7
#define pb push_back

typedef long long ll;
typedef long long int llt;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

int main(void){
    cin.tie(0);
   	ios::sync_with_stdio(false);
	int n, h, w;
	cin >> n >> h >> w;
	int x = n - h + 1, y = n - w + 1;
	cout << x * y << endl;
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <vector>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <ctype.h>
#include <climits>
#include <queue>
using namespace std;
typedef long long ll;
#define REP(i, n) for(ll i = 0; i < (ll)(n); ++i)
template<class T> inline bool chmax(T& a, T b) { if(a < b){ a=b; return 1; } return 0;}
template<class T> inline bool chmin(T& a, T b) { if(a > b){ a=b; return 1; } return 0;}

int main(){
	ll a,b,x;
	cin >> a >> b >> x;
	long double ans;
	
	ll L = a*a*b -x;
	
	if(L <= x){
		ans = atan((long double)(2*L)/(a*a*a))*45 /atan(1);
	}else{
		ans = atan((long double)(b*b*a)/(2*x)) *45 /atan(1);
	}
	
	printf("%.12Lf\n",ans);
	
	return 0;
}

Measured memory_bytes: 3792
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define All(v) (v).begin(),(v).end()

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a,b;
    cin>>a>>b;
    if(a<=b)cout<<"unsafe"<<endl;
    else cout<<"safe"<<endl;
}

Measured memory_bytes: 3624
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <deque>

using namespace std;

#define rep1(i, n) for (long long i = 0; i < (long long)(n); i++)
#define rep2(i, n, m) for (long long i = (long long)(n); i <= (long long)(m); i++)
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return 1; } return 0; }
const long long mod = 1e9 + 7;

int main() {
    string s;
    cin >> s;
    bool result = s.length() % 2 == 0;
    rep1(i, s.length()) {
        result = result && (i % 2 == 0 ? s.at(i) == 'h' : s.at(i) == 'i');
    }
    if (result) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

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

typedef long long ll;

ll keyValue = 1000000007;

void  calc(int num, std::vector<ll>& dp)
{
    for(int i=2; i<=num+1; ++i)
        dp[i] = (dp[i-1] + dp[i-2])%keyValue;
}

int main() {

    int N, M;
    std::vector<ll> a;

    std::cin >> N >> M;

    std::vector<ll> dp(N+2, 0);
    dp[0] = 0;
    dp[1] = 1;
    calc(N, dp);

    a.resize(M);
    for(int i=0; i<M; ++i)
        std::cin >> a[i];

    ll ans = 1;

    for(int i=0; i<a.size(); ++i)
    {
        if(i==0)
        {
            ll num = a[0];
            ans = ans * dp[num] % keyValue;
        }
        else
        {
            ll num = a[i] - a[i-1] -1;
            ans = ans * dp[num] % keyValue;
        }

        if(ans == 0)
        {
            std::cout << 0 << std::endl;
            return 0;
        }
    }

    if(M>0)
    {
        ll num = N - a[a.size()-1];
        ans = ans * dp[num] % keyValue;
    }
    else
    {
        std::cout << dp[N+1] % keyValue << std::endl;
        return 0;
    }

    std::cout << ans % keyValue << std::endl;


    return 0;
}

Measured memory_bytes: 1792
N = int(input())
a = list(map(int,input().split()))
odd=[]
two=[]
four=[]
for i in range(N):
    if a[i]%2!=0:
        odd.append(a[i])
    elif a[i]%4==0:
       four.append(a[i])
    else:
       two.append(a[i])
O=len(odd)
T=len(two)
F=len(four)

if O>F+1:
    print('No')
elif O==F+1:
    if T==0:
        print('Yes')
    else:
        print('No')
else:
    print('Yes')

Measured memory_bytes: 14252
#include<stdio.h>

struct dice{
    int d[6],tmp[6];
};
struct dice dice1;
struct dice dice2;
struct dice dice3[110];

void copy1(int a){
    int i;
    for(i=0;i<6;i++){
        dice3[a].d[i]=dice2.d[i];
        dice3[a].tmp[i]=dice2.tmp[i];
    }
}
void copy2(int a){
    int i;
    for(i=0;i<6;i++){
        dice2.d[i]=dice3[a].d[i];
        dice2.tmp[i]=dice3[a].tmp[i];
    }
}

void init1(int n[6]){
    int i;
    for(i=0;i<6;i++){
        dice1.d[i]=n[i];
    }
}
void init2(int n[6]){
    int i;
    for(i=0;i<6;i++){
        dice2.d[i]=n[i];
    }
}
void rooldice(char c){
    int i;
    for(i=0;i<6;i++){
        dice1.tmp[i]=dice1.d[i];
    }
    if(c=='N'){
        dice1.d[0]=dice1.tmp[1];
        dice1.d[1]=dice1.tmp[5];
        dice1.d[2]=dice1.tmp[2];
        dice1.d[3]=dice1.tmp[3];
        dice1.d[4]=dice1.tmp[0];
        dice1.d[5]=dice1.tmp[4];
    }
    else if(c=='E'){
        dice1.d[0]=dice1.tmp[3];
        dice1.d[1]=dice1.tmp[1];
        dice1.d[2]=dice1.tmp[0];
        dice1.d[3]=dice1.tmp[5];
        dice1.d[4]=dice1.tmp[4];
        dice1.d[5]=dice1.tmp[2];
    }
    else if(c=='W'){
        dice1.d[0]=dice1.tmp[2];
        dice1.d[1]=dice1.tmp[1];
        dice1.d[2]=dice1.tmp[5];
        dice1.d[3]=dice1.tmp[0];
        dice1.d[4]=dice1.tmp[4];
        dice1.d[5]=dice1.tmp[3];
    }
    else if(c=='S'){
        dice1.d[0]=dice1.tmp[4];
        dice1.d[1]=dice1.tmp[0];
        dice1.d[2]=dice1.tmp[2];
        dice1.d[3]=dice1.tmp[3];
        dice1.d[4]=dice1.tmp[5];
        dice1.d[5]=dice1.tmp[1];
    }
    else if(c=='R'){
        dice1.d[0]=dice1.tmp[0];
        dice1.d[1]=dice1.tmp[3];
        dice1.d[2]=dice1.tmp[1];
        dice1.d[3]=dice1.tmp[4];
        dice1.d[4]=dice1.tmp[2];
        dice1.d[5]=dice1.tmp[5];
    }
}

int compare(){
        int i;
        for (i=0; i<6; i++) {
        if(dice1.d[i]!=dice2.d[i]){
    
    return 0;
        }
    }
    return 1;
}

    int main()
{
    int n[6];
    int m;
    int i,j,k,l;
   int ok=0;
    scanf("%d",&m);
    for(i=0;i<6;i++){
        scanf("%d",&n[i]);
   }
    init2(n);
    copy1(0);
    for(i=0;i<m-1;i++){
        for (j=0; j<6; j++) {
            scanf("%d",&n[j]);
        }
    init1(n);
    for(j=0;j<i+1;j++){
        copy2(j);
        for(k=0;k<4;k++){
            for (l=0; l<4; l++){
            rooldice('N');
            rooldice('E');
            rooldice('S');
            if(compare()) ok=1;
        }
        rooldice('N');
}
   rooldice('E');
    for(k=0;k<2;k++){
        for(l=0;l<4;l++){
            rooldice('N');
            rooldice('E');
            rooldice('S');
            if(compare()) ok=1;
       }
        rooldice('W');
        rooldice('W');
      }
    }
    copy1(i+1);
    }
    if(!ok) puts("Yes");
    else puts("No");
    return 0;
}

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

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
const int mod = (int)1e9 + 7;
void dbg(){ cerr << "\n"; } template <typename T,typename ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }

int main()
{
	
	//cin.tie(0); ios_base::sync_with_stdio(false);
	int t;
	cin >>t;
	rep(i, t){
		ll a,b,c,d; bool ok=1;
		cin >>a >>b >>c >>d;
		if(a < b || b > d) ok=0;
		else if(c >= b) ok=1;
		else{
			ll x = ((a-b)/ __gcd(b, d) +1) * __gcd(b, d);
			if(c < a - x) ok=0;
		}
		puts(ok? "Yes":"No");
	}
	return 0;
}


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

int main()
{
	string O, E;
	cin >> O >> E;
	int o = 0, e = 0;
	for (int i = 0; i < O.size() || i < E.size(); i++) {
		if (i < O.size()) cout << O[i];
		if (i < E.size()) cout << E[i];
	}
	cout << endl;
	return 0;
}

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

using namespace std;
using ll = long long;

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

int main() {
  int h, w, k;
  cin >> h >> w >> k;
  int c[h][w];
  rep(i, h) rep(j, w) {
    char x;
    cin >> x;
    c[i][j] = (x == '#');
  }

  int ans = 0;
  rep(sh, 1 << h) {
    rep(sw, 1 << w) {
      int b = 0;
      rep(i, h) rep(j, w) {
        if (sh >> i & 1 || sw >> j & 1) continue;
        if (c[i][j]) ++b;
      }
      if (b == k) ++ans;
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3636
#include<iostream>
#include<string>
#include<vector>
#include<iomanip>
#include<algorithm>
#include<queue>
#include<stack>
#include<list>
#include<map>
#include<deque>
#include<math.h>
using namespace std;
#define ll long long
int main(){
    string S;
    cin >> S;
    if(S[2]==S[3]&&S[4]==S[5])cout << "Yes";else cout << "No";
    return 0;
}


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

int main() {
  int n, m, l;
  cin >> n >> m >> l;
  vector<vector<int> > adata(n, vector<int>(m));
  for(int i=0; i<n; i++) {
    for(int j=0; j<m; j++) {
      cin >> adata.at(i).at(j);
    }
  }
  
  vector<vector<int> > bdata(m, vector<int>(l));
  for(int i=0; i<m; i++) {
    for(int j=0; j<l; j++) {
      cin >> bdata.at(i).at(j);
    }
  }
  
  long sum = 0;
  vector<vector<long> > cdata(n, vector<long>(l));
  for(int i=0; i<n; i++) {
    for(int j=0; j<l; j++) {
      for(int k=0; k<m; k++) {
        if(j != l-1) {
          if(k != m-1) {
            sum += adata.at(i).at(k) * bdata.at(k).at(j);
          }
          else {
            sum += adata.at(i).at(k) * bdata.at(k).at(j);
            cdata.at(i).at(j) = sum;
            cout << cdata.at(i).at(j) << " ";
            sum = 0;
          }
        }
        else {
          if(k != m-1) {
            sum += adata.at(i).at(k) * bdata.at(k).at(j);
          }
          else {
            sum += adata.at(i).at(k) * bdata.at(k).at(j);
            cdata.at(i).at(j) = sum;
            cout << cdata.at(i).at(j) << endl;
            sum = 0;
          }
        }
      }
    }
  }
    
  return 0;
}


Measured memory_bytes: 3308
#include <bits/stdc++.h>
using namespace std;
#define print(x) cout << (x) << endl;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, X;
    cin >> N >> X;
    int sum = 0, count = 1, L;
    for (int i = 0; i < N; i++) {
        cin >> L;
        if (sum + L <= X) {
            count++;
        }
        sum += L;
    }
    print(count);
}

Measured memory_bytes: 256
from functools import reduce
from fractions import gcd
def lcm(x,y):return x*y//gcd(x,y)
def lcmm(l):return reduce(lcm,l)
a = int(input())
List=list(map(int,input().split()))
b = lcmm(List)
c = 0
for i in range(a):
  c = c + b // List[i]
print(c%1000000007)

Measured memory_bytes: 6084
let words str =
  let len = String.length str in
  let buf = Buffer.create 10 in
  let rec loop acc = function
      i when i = len -> acc, (Buffer.contents buf |> int_of_string)
    | i ->
      loop
        (match str.[i] with
         | ' ' ->
           let v = Buffer.contents buf |> int_of_string in
           Buffer.clear buf; v
         | c ->
           Buffer.add_char buf c; acc)
        (i+1)
  in loop 0 0

let bsearch predicate maxv =
  let rec loop minp maxp =
    if minp >= maxp then maxp else
    let middle = (maxp+minp)/2  in
      match predicate middle with
        true -> loop minp middle
      | false -> loop (middle+1) maxp
  in
  loop 1 maxv
    
let check num_of_truck goods capacity =
  let len = Array.length goods in
  let rec loop acc = function
      _, i when i >= len -> true
    | 0, _  -> false
    | rem_truck, i -> match goods.(i)+acc with
        x when x > capacity -> loop 0 (rem_truck-1,i)
      | x -> loop x (rem_truck,i+1)
  in
  loop 0 (num_of_truck,0)
    
let () =
  let n,num_of_truck = read_line () |> words in
  let goods = Array.init n (fun _ -> read_int ()) in
  let sum = Array.fold_left (fun acc v -> acc+v) 0 goods in
  bsearch (check num_of_truck goods) sum |> Printf.printf "%d\n"

Measured memory_bytes: 5220
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<queue>
#include<cmath>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<stack>
#include<cstdio>
#include<cstring>
#include<bitset>
#include<unordered_map>
#include<climits>
#include<fstream>
#include<time.h>
#include<cassert>

using namespace std;
#define ll long long
#define ld long double
#define int long long
#define all(a) (a).begin(),(a).end()
#define EPS (1e-13)
#define fs first
#define sc second
#define xx first
#define yy second.first
#define zz second.second
#define H pair<int, int>
#define P pair<int, pair<int, int>>
#define Q(i,j,k) mkp(i,mkp(j,k))
#define rep(i,n) for(int (i) = 0 ; (i) < (n) ; (i)++)
#define mkp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define crdcomp(b) sort(all((b)));(b).erase(unique(all((b))),(b).end())
#define ssp(i,n) (i==n-1?"\n":" ")
const int mod = 1e9 + 7;
const int Mod = 998244353;
const ll Inf = 3 * 1e18;
const int inf = 15 * 1e8;
ll read() {
	ll u, k = scanf("%lld", &u);
	return u;
}
ll gcd(ll i, ll j) {
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcd(j % i, i);
}
ll mod_pow(ll x, ll n, ll p) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * x % p;
		x = x * x % p;
		n >>= 1;
	}
	return res;
}
ll bcount(ll x) {
	int sum = 0;
	for (int i = 0; i < 20; i++)
		if ((1ll << i) & x) sum++;
	return sum;
}
const int fn_ = 2000000;
ll fact_[fn_], comp_[fn_];
ll comb(ll x, ll y, ll Mod = mod) {
	if (!fact_[0]) {
		fact_[0] = 1; comp_[0] = 1;
		for (int i = 1; i < fn_; i++) {
			fact_[i] = fact_[i - 1] * i % Mod;
			comp_[i] = mod_pow(fact_[i], Mod - 2, Mod);
		}
	}
	if (x < y) return 0;
	return fact_[x] * comp_[x - y] % Mod * comp_[y] % Mod;
}
//------------------------]---------------------------
signed main() {
	int n, m;
	cin >> n >> m;
	cout << n * m << endl;
}


Measured memory_bytes: 3120
N=int(input())
A=[]
for i in range(2):
  a=list(map(int,input().split()))
  A.append(a)

dp=[[0 for i in range(N)] for j in range(2)]

dp[0][0]=A[0][0]
dp[1][0] = A[0][0]+A[1][0]
for i in range(1,N):
  dp[0][i]=dp[0][i-1]+A[0][i]
  dp[1][i]=A[1][i]+max(dp[1][i-1],dp[0][i])

print(dp[1][N-1])

Measured memory_bytes: 9156
n,y=map(int, input().split())
count = 0
for i in range(n+1):
  for j in range(n-i+1):
    k = n - i - j
    if (i * 10000) + (j * 5000) + (k * 1000) == y:
      count += 1
      print(i, j, k)
      exit()
if count == 0:
  print(-1, -1, -1)
  

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define mp(a, b) make_pair(a, b)
#define lowbit(x) (x & (-x))
#define ls (rt << 1)
#define rs (rt << 1 | 1)
typedef long long ll;
typedef pair<int, int> pii;
const int maxn = 2e5 + 10;
int n, m;
pii a[maxn];
int pos[maxn], b[maxn], fa[maxn], cnt[maxn], siz[maxn];
vector<pii> E[maxn];
vector<int> ans;
int getfa(int x) { return fa[x] == x ? x : fa[x] = getfa(fa[x]);}
void dfs(int x, int fa, int id)
{
	siz[x] = b[x];
	for(auto e : E[x])
	{
		int v = e.first;
		if(v == fa) continue;
		dfs(v, x, e.second);
		siz[x] += siz[v];
	}
	if(siz[x] & 1)
		ans.push_back(id);
}
int main()
{
	scanf("%d%d", &n, &m);
	for(int i = 1; i <= n; ++i) scanf("%d%d", &a[i].first, &a[i].second);
	sort(a + 1, a + n + 1);
	for(int i = 1; i <= n; ++i) pos[i] = a[i].first;
	for(int i = 1; i <= n + 1; ++i) 
	{
		fa[i] = i;
		b[i] = a[i].second ^ a[i - 1].second;
	}
	for(int i = 1; i <= m; ++i)
	{
		int l, r;
		scanf("%d%d", &l, &r);
		l = lower_bound(pos + 1, pos + n + 1, l) - pos;
		r = upper_bound(pos + 1, pos + n + 1, r) - pos;
		int fl = getfa(l), fr = getfa(r);
		if(fl == fr) continue;
		fa[fr] = fl;
		E[l].push_back(mp(r, i));
		E[r].push_back(mp(l, i));
	}
	for(int i = 1; i <= n + 1; ++i)
	{
		if(b[i])
		{
			int fi = getfa(i);
			++cnt[fi];
		}
	}
	for(int i = 1; i <= n + 1; ++i)
		if(getfa(i) == i && (cnt[i] & 1))
		{
			puts("-1");
			return 0;
		}
	for(int i = 1; i <= n + 1; ++i)
		if(getfa(i) == i)
			dfs(i, 0, 0);
	sort(ans.begin(), ans.end());
	printf("%d\n", ans.size());
	for(auto v : ans) printf("%d ", v);
	return 0;
}

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

#define ull unsigned long long
#define ll long long


int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i=0; i<n; ++i)
        cin >> a[i];
    
    sort(a.begin(), a.end());

    double x = (double)(a[0]+a[1])/2;
    for(int i=2; i<n; ++i){
        x = (x+a[i])/2;
    }

    cout << x;
}


Measured memory_bytes: 3804
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); ++i)
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Pl = pair<long long,long long>;
using veci = vector<int>;
using vecl = vector<long long>;
using vecveci = vector<vector<int>>;
using vecvecl = vector<vector<long long>>;

int main() {
    int N; cin >> N;
    int cnt = 0;
    REP(i,N) {
        int a; cin >> a;
        cnt += (a%2 != 0);
    }
    cout << (cnt%2 == 0 ? "YES" : "NO") << endl;
}


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

const int64_t MOD = 1e9+7;
void add(int64_t& a, int64_t b){
    a = (a+b) % MOD;
}
void mul(int64_t& a, int64_t b){
    a = a*b % MOD;
}

vector<int64_t> fact, seq_inv, fact_inv;

void create_fact_mod(int num){
    fact[0] = fact[1] = 1;
    for(int i=2; i<=num; i++) fact[i] = fact[i-1] * i % MOD;
}

void create_seq_inv_mod(int num){
    seq_inv[0] = seq_inv[1] = 1;
    for(int i=2; i<=num; i++) seq_inv[i] = (MOD - MOD/i) * seq_inv[MOD%i] % MOD;
}

void create_fact_inv_mod(int num){
    fact_inv[0] = fact_inv[1] = 1;
    for(int i=2; i<=num; i++) fact_inv[i] = fact_inv[i-1] * seq_inv[i] % MOD;
}

void create_mod_tables(int num){
    fact.resize(num+1);
    seq_inv.resize(num+1);
    fact_inv.resize(num+1);
    create_fact_mod(num);
    create_seq_inv_mod(num);
    create_fact_inv_mod(num);
}

int64_t comb_mod(int n, int k){
    return fact[n] * fact_inv[n-k] % MOD * fact_inv[k] % MOD;
}

int64_t perm_mod(int n, int k){
    return fact[n] * fact_inv[n-k] % MOD;
}

int64_t power_mod(int64_t num, int64_t power){
    int64_t prod = 1;
    num %= MOD;
    while(power > 0){
        if(power&1) prod = prod * num % MOD;
        num = num * num % MOD;
        power >>= 1;
    }
    return prod;
}

int64_t extgcd(int64_t a, int64_t b, int64_t& x, int64_t& y){
    int64_t d = a;
    if(b != 0){
        d = extgcd(b, a%b, y, x);
        y -= (a/b) * x;
    }else{
        x = 1; y = 0;
    }
    return d;
}

int64_t inv_mod(int64_t a){
    int64_t x, y;
    extgcd(a, MOD, x, y);
    return (MOD + x%MOD) % MOD;
}

int main(){
    int N;
    int X[100000];
    cin >> N;
    for(int i=0; i<N; i++) cin >> X[i];

    int64_t D[100000];
    for(int i=0; i<N-1; i++) D[i] = X[i+1] - X[i];
    int64_t sum[100001] = {0};
    for(int i=1; i<=N; i++){
        sum[i] = sum[i-1];
        add(sum[i], inv_mod(i));
    }

    int64_t ans = 0;
    for(int i=0; i<N-1; i++){
        int64_t res = D[i] * sum[i+1] % MOD;
        add(ans, res);
    }
    for(int i=1; i<N; i++) mul(ans, i);
    cout << ans << endl;
    return 0;

}


Measured memory_bytes: 2176
# -*- coding: utf-8 -*-
 
N = int(input())
v = [int(a) for a in input().split()]
 
v.sort()
 
for i in range(N-1):
    tmp = (v[0]+v[1])/2
    v.pop(0)
    v.pop(0)
    v.insert(0,tmp)
    v.sort()
 
print(v[0])

Measured memory_bytes: 3060
#include <stdio.h>

int main(void)
{
int i;
int a;

for(i=1;i<=9;i++){
	
	for(a=1;a<=9;a++){
		
		
		
		
		
		printf("%dx%d=%d\n",i,a,i*a);
		
		
		
		
		
		
		
	}
	
	
	
	
	
}
	return 0;
}

Measured memory_bytes: 520
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <functional>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <cmath>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> P;
#define rep(i,a,n) for(ll i = (a);i < (n);i++)
#define per(i,a,n) for(ll i = (a);i > (n);i--)
#define lep(i,a,n) for(ll i = (a);i <= (n);i++)
#define pel(i,a,n) for(ll i = (a);i >= (n);i--)
#define clr(a,b) memset((a),(b),sizeof(a))
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define sz size()
#define print(x) cout << x << endl
const int INF = 1e+8+7;
ll n,m;
int a,b,c = 0;
string s,t;
int d[100],dp1[500][500],dp2[500][500];
vi vec;

int main(){
  cin >> n;
  rep(i,0,n){
    cin >> a;
    vec.pb(a);
  }
  while(1){
    bool f = false;
    rep(i,0,vec.sz){
      if(vec[i] % 2 == 0)vec[i] /= 2;
      else f = true;
    }
    if(f)break;
    c++;
  }
  print(c);
  return 0;
}

Measured memory_bytes: 256
n=parse(Int,readline())
cnt=zeros(Int,4)
for i=1:n
    s=readline()
    if s=="AC"
        cnt[1]+=1
    elseif s == "WA"
        cnt[2]+=1
    elseif s=="TLE"
        cnt[3]+=1
    elseif s=="RE"
        cnt[4]+=1
    end
end
print("AC x ") 
println(cnt[1])
print("WA x ")
println(cnt[2])
print("TLE x ")
println(cnt[3])
print("RE x ") 
println(cnt[4])
    
    

Measured memory_bytes: 169224
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast", "unroll-loops")
using namespace std;
#define ll long long
#define FOR(i,a,b) for (int i = (a); i<(b); i++)
#define REP(i,n) FOR(i,0,n)
#define REP1(i,n) FOR(i,1,n+1)
#define RREP(i,n) for (int i=(n)-1; i>=0; i--)
#define f first
#define s second
#define pb push_back
#define ALL(x) x.begin(),x.end()
#define SZ(x) (int)(x.size())
#define SQ(x) (x)*(x)
#define pii pair<int, int>
#define endl '\n'
//#define TOAD
#define int ll
#ifdef TOAD
#define bug(x) cerr<<__LINE__<<": "<<#x<<" is "<<x<<endl
#define IOS() 
#else
#define bug(...)
#define IOS() ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#endif
const ll inf = 1ll<<60;
const int iinf=2147483647;
const ll mod = 998244353;
const ll maxn=300005;

signed main (){
  IOS();
  string str; cin>>str;
  int ans=0;
  bool trig=false;
  REP(i,SZ(str)){
    if (trig) {
      ans+=9;
      continue;
    }
    if (i==SZ(str)-1){
      ans+=str[i]-'0';
      continue;
    }
    if (str[i+1]!='9'){
      ans+=str[i]-'0'-1;
      trig=true;
    }
    else {
      ans+=str[i]-'0';
    }
  }
  cout<<ans<<endl;
 }

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

typedef long long ll;
const int maxn=100+10;
int n,a[maxn],x,cnt;

int main(){
	cin>>n>>x;
	for(int i=1;i<=n;++i)
		cin>>a[i];
	sort(a+1,a+n+1);
	for(int i=1;i<=n;++i)
		if(x>=a[i])
			x-=a[i],++cnt;
	if(x&&cnt==n)
		--cnt;
	cout<<cnt<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 2e5 + 10;
string s[N];
int n, tries, codes[5 * N][26], cnt[5 * N][26];
bool f[5 * N][26]; 
ll ans;
inline bool cmp(const string &a, const string &b) {
    return a.size() > b.size();
}
inline void insert(string &s) {
    int code = 0;
    for(int i = 0; i < s.size(); ++i) {
        for(int j = 0; j < 26; ++j) {
            if(f[i][j]) {
                ++cnt[code][j];
            }
        }
        if(!codes[code][s[i] - 'a']) {
            codes[code][s[i] - 'a'] = ++tries;
        }
        code = codes[code][s[i] - 'a'];
    }
}
inline int count(string &s) {
    int code = 0;
    for(int i = 0; i < (int)s.size() - 1; ++i) {
        if(!codes[code][s[i] - 'a']) return 0;
        code = codes[code][s[i] - 'a'];
    }
    return cnt[code][s.back() - 'a'];
}
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    cin >> n;
    for(int i = 1; i <= n; ++i) {
        cin >> s[i];
        reverse(s[i].begin(), s[i].end());
    }
    sort(s + 1, s + n + 1, cmp);
    for(int i = 1; i <= n; ++i) {
        ans += count(s[i]);
        for(int j = 0; j <= s[i].size(); ++j) {
            for(int k = 0; k < 26; ++k) {
                f[j][k] = 0;
            }
        }
        for(int j = s[i].size() - 1; ~j; --j) {
            for(int k = 0; k < 26; ++k) {
                f[j][k] = f[j + 1][k];
            }
            f[j][s[i][j] - 'a'] = 1;  
        } 
        insert(s[i]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 235752
a, v = map(int, input().split())
b, w = map(int, input().split())
t = int(input())

if a < b:
  if a + v * t >= b + w * t:
    print("YES")
  else:
    print("NO")
else:
  if a - v * t <= b - w * t:
    print("YES")
  else:
    print("NO")


Measured memory_bytes: 9116
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class MainClass
{
	public const long Giri = 1000000007;
	public const long DpInf = 99999999999999;
	
	
	public static void Main(string[] args)
	{
 		var l = Console.ReadLine().ToInt();
		
		double hen = l / 3d;
		Console.WriteLine(hen * hen * hen);
	}
	
	
	static long GCD(long a, long b)
	{
		var v = new[] { a, b };
		while (v[1] != 0) { v = new[] { v[1], v[0] % v[1] }; }
		return v[0];
	}
	public static string[] Input() { return Console.ReadLine().Split(); }
}

public static class Smarter
{
	public static int ToInt(this string str) { return int.Parse(str); }
	public static long ToLong(this string str) { return long.Parse(str); }
	public static int[] ToInt(this string[] str, int offset = 0)
	{
		var r = new int[str.Length];
		for(int i = 0; i < str.Length; i++) r[i] = str[i].ToInt() + offset;
		return r;
	}
}

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

int main() {
  int n;
  cin >> n;
  vector <int> le(n);
  for (int i = 0; i < n; i++) {
	  cin >> le[i];
	}
  le.push_back(1e9);
  sort(le.begin(), le.end());
  long long ans = 0;
  for (int i = 0; i < n; i++) {
	  for (int j = i + 1; j < n; j++) {
		  int l = j;
		  int r = n;
		  while (l + 1 < r) {
			  int m = (l + r) / 2;
			  if (le[m] < le[i] + le[j]) {
				  l = m;
				}
			  else {
				  r = m;
				}
			}
		  ans += (l - j);
		}
	}
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
bool u[1010];
vector<int> v[1010];
int dfs(int x,bool f) {
  u[x]=1;
  for(int i=0; i<v[x].size(); i++) {
    if(!u[v[x][i]]) f=0,dfs(v[x][i],f);
  }
  return f;
}

int main() {
  int n,m;
  cin >> n >> m;
  for(int i=0,x,y; i<m; i++) {
    cin >> x >> y;
    v[x].push_back(y);
    v[y].push_back(x);
  }
  int x=0,y=0;
  for(int i=1; i<=n; i++) {
    if(!u[i]) dfs(i,1)?x++:y++;
  }
  cout << abs(x-y) << endl;
  return 0;
}


Measured memory_bytes: 3204
#include <cstdio>
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <set>

#define ll long long
#define pll pair<ll, ll>

#define reps(i, f, n) for (int i = (f); i < (int)(n); i++)
#define rep(i, n) reps(i, 0, n)

const int INF = 1111111111;
const double EPS = 1e-9;

using namespace std;

const int N = 200000;
int n;
int a[N];

void init()
{
	cin >> n;
	rep(i, n) cin >> a[i];
}

void solve()
{
	sort(a, a + n);
	reverse(a, a + n);

	ll sum = 0;
	rep(i, n)
	{
		if (i == 0)
		{
			continue;
		}

		sum += a[i / 2];
	}

	cout << sum << endl;
}

int main()
{
	init();
	solve();
}


Measured memory_bytes: 3968
#include <bits/stdc++.h>																							   
																									   
using namespace std; 																								   
		
const double eps = 1e-9;																							   
const int INF = 1e9;
const long long INFL = 1e18;																					   
const int mod = 1e9 + 7;																								   
typedef long long LL;																								   
																													   
typedef vector<int> vi;																								   																								   
typedef queue<int> qi; 																								   
typedef pair<int,int> ii;																							   										   
typedef vector<ii> vii; 		   
typedef priority_queue< ii, vector<ii>, greater<ii> > pq;    																								   																				   																						   
																													   																				   										   
#define pb push_back																							   
#define pf push_front																							   
#define mp(x, y) make_pair(x, y)
#define size(x) (int)x.size()
#define endl '\n'

int _X[] = {0, 1, 1, 1, 0, -1, -1, -1};
int _Y[] = {-1, -1, 0, 1, 1, 1, 0, -1};
int _X2[] = {1, 0, -1, 0};
int _Y2[] = {0, 1, 0, -1};

int main(int argc, char* argv[])																					 
{ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	
	
    string s;
    cin >> s;
    if(s[0] == 'R' && s[1] == 'R' && s[2] == 'R'){
        cout << 3 << endl;
    }
    else if(s[0] == 'R' && s[1] == 'R' && s[2] != 'R' || s[1] == 'R' && s[2] == 'R' && s[0] != 'R'){
        cout << 2 << endl;
    }
    else if(s[0] == 'R' || s[1] == 'R' || s[2] == 'R'){
        cout << 1 << endl;
    }
    else cout << 0 << endl;











	
	
	
	
	return 0;
}

Measured memory_bytes: 3616
#include <iostream>
#include <vector>
#include <algorithm>
#include <unordered_set>
#include <queue>

using namespace std;

typedef long long ll;

ll sqr(ll a) { return a * a; }

int main() {
    int n, k; cin >> n >> k;
    vector<pair<int, int> > deli(n);
    for (int i = 0; i < n; i++) {
        cin >> deli[i].second >> deli[i].first;
    }

    sort(begin(deli), end(deli));
    reverse(begin(deli), end(deli));

    
    unordered_set<int> tps;
    priority_queue<int, vector<int>, greater<int> > dup;

    ll ans = 0;
    for (int i = 0; i < k; i++) {
        int d = deli[i].first, t = deli[i].second;
        ans += d;
        if (tps.count(t) > 0) {
            dup.push(d);
        }
        tps.insert(t);
    }

    ll best = ans + sqr((ll) tps.size());

    for (int i = k; i < n; i++) {
        int d = deli[i].first, t = deli[i].second;
        if (tps.count(t) > 0) continue;

        if (dup.empty()) continue;

        int rm = dup.top();
        dup.pop();

        ans -= rm;
        ans += d;

        tps.insert(t);
        best = max(best, ans + sqr((ll) tps.size()));
    }

    cout << best << endl;
    return 0;
}

Measured memory_bytes: 4620
import random

class dice:
  def __init__(self,dice_number_list):
    self.top,self.front,self.right,self.left,self.rear,self.bottom = dice_number_list
    
  def roll(self,op):
    if   op=='N': 
      self.top, self.front, self.bottom, self.rear = \
      self.front, self.bottom, self.rear , self.top
    elif op=='E':
      self.top, self.left , self.bottom, self.right = \
      self.left , self.bottom, self.right, self.top
    elif op=='W': 
      self.top, self.right, self.bottom, self.left = \
      self.right, self.bottom, self.left , self.top
    elif op=='S': 
      self.top, self.rear , self.bottom, self.front = \
      self.rear , self.bottom, self.front, self.top
           
  def print_top(self):
    print(self.top)
  def print_right(self):
    print(self.right)
    
  def get_label(self):
    return([self.top, self.front, self.right, self.left, self.rear, self.bottom])
    
dice_number_list = list(map(int,input().split()))
d = dice(dice_number_list)

#全パターン24通りの取得
all_dice_number_list=[]
for i in range(10000):
  d.roll(random.choice("NEWS"))
  if d.get_label() not in all_dice_number_list:
    all_dice_number_list.append(d.get_label())
  if len(all_dice_number_list) == 24:
    break

#print(all_dice_number_list)

n=int(input())
for i in range(n):
  top,front = list(map(int,input().split()))
  for dice_list in all_dice_number_list:
    #print(dice_list)
    if dice_list[0]==top and dice_list[1]==front:
      print(dice_list[2]) #rightの面取得
    


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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
typedef long long ll;

int main(){
  ll x, k, d;
  cin >> x >> k >> d;

  ll ans;
  if(abs(x)/d>=k){
    ans = abs(x)-k*d;  
  }else{
    if((k-abs(x)/d)%2==0) ans=abs(x)-(abs(x)/d)*d;
    else ans=abs(abs(x)-(abs(x)/d)*d-d);
  }
  cout << ans;
}

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

int n, a[200005];
long long ans;

int main() {
    cin >> n;
    for(int i = 1; i <= n; i++)
        cin >> a[i];
    int mx = 0;
    for(int i = 1; i <= n; i++) {
        if(mx > a[i]) {
            ans += (mx - a[i]);
            a[i] = mx;
        }
        mx = max(a[i], mx);
    }
    cout << ans;
}


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

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

const ll MAX=1<<18;
const ll INF=0x3f3f3f3f;
vector<ll> w,q;
ll d,ans;
ll power(ll x,ll y){
    if(y==0) return 1;
    ll t=power(x,y/2);
    if(y%2) return t*t*x;
    return t*t;
}
ll fnum(ll val,ll idx){
    ll t=0;
    if(val>q[idx]+d||val<-q[idx]+d) return 0;
    if(idx==w.size()){
        if(val==d) return 1;
        return 0;
    }
    for(ll i=-9;i<=9;i++) {
        if(idx!=0) t+=(10-abs(i))*fnum(val+i*w[idx],idx+1);
        else t+=min(i+10,9-i)*fnum(val+i*w[idx],idx+1);
    }
    return t;
}
int main(){
    scanf("%lld",&d);
    for(ll i=1;i<20;i++){
        w.clear(); q.clear();
        for(ll j=0;j<(i+1)/2;j++){
            w.push_back(power(10,i-j)-power(10,j));
            q.push_back(0);
        }
        for(ll j=0;j<w.size();j++) {
            for(ll k=j;k<w.size();k++) q[j]+=w[k]*9;
        }
        //printf("\n");
        if(i%2==0) ans+=10*fnum(0,0);
        else ans+=fnum(0,0);
    }
    printf("%lld\n",ans);
}


Measured memory_bytes: 256
N = int(input())
A = list(map(int,input().split()))
S = []
P = A[:N]
Q = A[2*N:]
for i in range(N):
    Q[i] *= -1
R = A[N:2*N]
p = [0]*(N+1)
q = [0]*(N+1)
import heapq
heapq.heapify(P)
heapq.heapify(Q)
sp = sum(P)
sq = sum(Q)
p[0] = sp
q[0] = sq

for i in range(1,N+1):
    heapq.heappush(P,R[i-1])
    x = heapq.heappop(P)
    heapq.heappush(Q,-R[-i])
    y = heapq.heappop(Q)
    sp = sp + R[i-1] - x
    sq = sq - R[-i] - y
    p[i] = sp
    q[i] = sq
ans = -(10**100)
for k in range(N+1):
    ans = max(ans,p[k] + q[N-k])
    
print(ans)

Measured memory_bytes: 38676
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<math.h>
#include<stdio.h>
#include<string>


using namespace std;

int main(void)
{
	string str;
	cin >> str;
	int length = str.length();
	string ans(11, '5');
	int t = 0;
	int i;
	for (i = 0; i < length; i++)
	{
		if (str[i] == 'B')
		{
			if (t != 0)
			{
				t--;
			}
			ans[t] = 'm';

		}
		else if (str[i] == '0')
		{
			ans[t] = '0';
			t++;

		}
		else if (str[i] == '1')
		{
			ans[t] = '1';
			t++;
		}
	}

	for (i = 0; ans[i] != '5'; i++)
	{
		if (ans[i] == 'm')
		{
			continue;
		}
		cout << ans[i];
	}
	cout << endl;
	return 0;
}


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

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

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()

const int MN = 100010;

int N;
int a[3][MN];
pii b[MN];
ll flip[2], inv[2];

template<class T>
class BIT {
	T bit[MN];
	int n;

public:
	BIT() {
		n = N + 10;
		memset(bit, 0, sizeof(bit));
	}

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

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

int main() {
	cin >> N;

	rep(i, 3) {
		rep(j, N) {
			cin >> a[i][j];
			--a[i][j];
		}
	}

	rep(i, N) {
		if (a[1][i] == a[0][i] + 1 && a[2][i] == a[0][i] + 2) {
			b[i] = mp(a[0][i] / 3, 0);
		} else if (a[1][i] == a[0][i] - 1 && a[2][i] == a[0][i] - 2) {
			b[i] = mp(a[0][i] / 3, 1);
		} else {
			puts("No");
			return 0;
		}
		if (i % 4 >= 2) {
			b[i].se ^= 1;
		}
		if (b[i].fi % 2 != i % 2) {
			puts("No");
			return 0;
		}
	}

	BIT<int> T[2];

	rep(i, 2) { //parity
		for (int j = i; j < N; j += 2) {
			flip[i] += (b[j].se != (b[j].fi % 4 >= 2));
			inv[i] += T[i].sum(N) - T[i].sum(b[j].fi);
			T[i].add(b[j].fi, 1);
		}
	}

	puts(inv[0] % 2 == flip[1] % 2 && inv[1] % 2 == flip[0] % 2 ? "Yes" : "No");

	return 0;
}

Measured memory_bytes: 2944
#include<vector>
#include<bitset>
#include<cstdio>
#include<iostream>
#include<algorithm>
#define pb push_back
#define nc getchar
using namespace std;
inline void read(int &x) {
	char b = nc(); x = 0;
	for (; !isdigit(b); b = nc());
	for (; isdigit(b); b = nc()) x = x * 10 + b - '0';
}
struct Node {
	int x, y, id;	
	inline bool operator<(const Node &o) const {
		return x < o.x || (x == o.x && y < o.y);
	}
} a[100005];
int n, s, t, D, f[100005];
long long ans;
vector < int > g[100005];
bitset < 100005 > vis;
inline int ABS(int x) {return x > 0 ? x : -x;}
inline void ae(int u, int v) {
	g[u].pb(v); g[v].pb(u);	
}
void build(int k) {
	sort(a + 1, a + 1 + n); int i, j, l, r;
	for (i = j = l = r = 1; i <= n; ++i) {
		while (a[l].x < a[i].x - D || (a[l].x == a[i].x - D && a[i].y - a[l].y > k)) ++l;
		while (a[r].x < a[i].x - D || (a[r].x == a[i].x - D && a[r].y - a[i].y <= k)) ++r;
		f[a[i].id] += r - l; j = max(j, l); if (j < r) ae(a[i].id, a[j].id);
		for (; j + 1 < r; ++j) ae(a[j].id, a[j+1].id);
	}
}
void dfs(int u) {
	if (vis[u]) return; vis[u] = 1; ans += f[u];
	for (int i = 0; i < g[u].size(); ++i) dfs(g[u][i]);
}
int main() {
	read(n); read(s); read(t);
	for (int x, y, i = 1; i <= n; ++i)
		read(x), read(y), a[i] = (Node){x + y, x - y, i};
	D = max(ABS(a[s].x - a[t].x), ABS(a[s].y - a[t].y));
	build(D);
	for (int i = 1; i <= n; ++i) swap(a[i].x, a[i].y);
	build(D-1);
	dfs(s);
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 13312
A,B,C=map(int,input().split())
K=int(input())

for i in range(K+1) :
    for j in range(K+1-i) :
        a=A*(2**i)
        b=B*(2**j)
        c=C*(2**(K-i-j))
        if a<b<c :
            print("Yes")
            exit()

print("No")

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

const int M = 1000000007;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int m;
    string c;
    cin >> m >> c;
    int n = c.length();
    vector<long long> a(n);
    a[0] = 1;
    for (int i = 0; i + 1 < n; ++i) {
        a[i + 1] = a[i] * 10 % M;
    }
    vector<long long> k(10);
    for (int i = 0; i < n; ++i) {
        k[c[i] - '0'] = (k[c[i] - '0'] + a[n - i - 1]) % M;
    }
    vector<int> idx(10);
    for (int i = 0; i < 10; ++i) {
        idx[i] = i;
    }
    do
    {
        long long sum = 0;
        for (int i = 0; i < 10; ++i) {
            sum = (sum + k[i] * idx[i]) % M;
        }
        if (sum == m) {
            string ans(n, '0');
            for (int i = 0; i < n; ++i) {
                ans[i] = (char)(idx[c[i] - '0'] + '0');
            }
            if (ans[0] != '0') {
                cout << ans << '\n';
                return 0;
            }
            if (ans == "0") {
                cout << ans << '\n';
                return 0;
            }
        }
    } while (next_permutation(idx.begin(), idx.end()));

    cout << -1 << '\n';
    return 0;
}



Measured memory_bytes: 3868
from heapq import *
N,M=map(int,input().split())
G=[[] for i in range(N)]
for i in range(N-1):
  G[i+1].append((i,0))
l,r,c=0,0,0
for i in range(M):
  l,r,c=map(int,input().split())
  G[l-1].append((r-1,c))
D=[0]*N
INF=10**200
def ijk(s):
  global D,INF,G
  for i in range(len(G)):
    D[i]=INF
  D[s]=0
  Q=[]
  heapify(Q)
  heappush(Q,(0,s))
  p,v,e=0,0,0
  while len(Q):
    p=heappop(Q)
    v=p[1]
    if D[v]<p[0]:
      continue
    for i in range(len(G[v])):
      e=G[v][i]
      if D[e[0]]>D[v]+e[1]:
        D[e[0]]=D[v]+e[1]
        heappush(Q,(D[e[0]],e[0]))

ijk(0)
if D[-1]>=INF:
  print(-1)
else:
  print(D[-1])


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

int main() {
    int k;
    cin >> k;
    int x = 7 % k;
    set<int> s;
    int ans = 1;
    while(s.count(x) == 0){
        if(x == 0){
            cout << ans << endl;
            return 0;
        }
        s.insert(x);
        x = (x * 10 + 7) % k;
        ans++;
    }
    cout << -1 << endl;
    return 0;
}

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

using namespace std;

#define MAX 1000005

typedef long long ll;

int main(){

    int x;
    cin >> x;
    int res;
    vector<bool> arr(MAX, true);
    for(ll i = 2; i < MAX; i++)
        if( arr[i] ){
            if( i >= x ){
                res = i;
                break;
            }
            for(ll j = i*i; j < MAX; j+=i )
                arr[j] = false;
        }

    cout << res << endl;
    return 0;
}

Measured memory_bytes: 384
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

def main():
    a=II()
    b=II()
    if a>b:print("GREATER")
    elif a==b:print("EQUAL")
    else:print("LESS")
main()

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

int main() {
  int n;
  string s;
  cin >> n >> s;
  int ans = 1;
  rep(i, n-1) {
    if (s[i] != s[i+1]) ++ans;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 512
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Math;
using static System.Console;
using System.Text;

class Program
{
    static void Main(string[] args)
    {
        solve();
    }
    static Scanner cin;
    static long N;

    static void input()
    {
        cin = new Scanner();

        N = cin.nextLong();
    }
    static void solve()
    {
        input();
        int ans = int.MaxValue;
        for(int i = 1; (long)i * i <= N; i++)
        {
            if(N % i == 0)
            {
                int c = 1;
                long n = N / i;
                while(n >= 10)
                {
                    n /= 10;
                    c++;
                }
                ans = Min(ans, c);
            }
        }
        WriteLine(ans);
    }
    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 nextInt()
        {
            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] = nextInt() + add;
            }
            return Array;
        }

        public long nextLong()
        {
            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] = nextLong() + add;
            }
            return Array;
        }

        public double nextDouble()
        {
            return double.Parse(next());
        }

        public double[] ArrayDounble(int N, int add = 0)
        {
            double[] Array = new double[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextDouble() + add;
            }
            return Array;
        }
    }
}

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

#define INF 1000010000
#define nl '\n'
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define fi first
#define se second
#define pii pair<int,int>
#define pdd pair<double,double>
#define all(c) (c).begin(), (c).end()
#define SORT(c) sort(all(c))
#define sz(c) (c).size()
#define rep(i,n) for( int i = 0; i < n; ++i )
#define repi(i,n) for( int i = 1 ; i <= n; ++i )
#define repn(i,n) for( int i = n - 1 ; i >= 0 ; --i )
#define repf(j,i,n) for( int j = i ; j < n ; ++j )
#define die(s) {std::cout << s << nl;}
#define dier(s) {std::cout << s; return 0;}
#define vi vector<int>
typedef long long ll;
#define MAXN 202020
using namespace std;



int n;
vector<vi> t(2 , vi(2 * MAXN , INF));


void build(int par){
    for(int i = n - 1 ; i > 0 ; --i){
        t[par][i] = min(t[par][2 * i] , t[par][2 * i + 1]);
    }
}
 
void modify(int par , int p , int val){
    for(t[par][p += n] = val ; p > 1 ; p /= 2){
        t[par][p / 2] = min(t[par][p] , t[par][p ^ 1]);
    }
}
 
int query(int par , int l , int r){//[l , r)
    int res = INF;
    for(l += n , r += n ; l < r ; l /= 2 , r /= 2){
        if(l % 2){
            res = min(res, t[par][l]);
            ++l;
        }
        if(r % 2){
            --r;
            res = min(res , t[par][r]);
        }
    }
    return res;
}

int last = 0;
map<int , pii> code;
map<pii , int> rcode;
vi pos;

vi g[MAXN / 2];

void solve(vi & p , int l , int r , int prev = -1){
	if(r - l < 1)return;
	if(r >= sz(p) || l < 0)return;
	if(r - l == 1){
		code[last] = {p[l] , p[r]};
		rcode[{p[l] , p[r]}] = last;
		
		if(prev != -1){
			g[prev].pb(last);
		}
		prev = last;
		++last;
	}else{
		pii o = {0 , 0};
		
		int par = l % 2;
		o.fi = query(par , l , r + 1);
		
		int pos1 = pos[o.fi];
		o.se = query((pos1 + 1) % 2 , pos1 + 1 , r + 1);
		
		code[last] = o;
		rcode[o] = last;
		
		if(prev != -1){
			g[prev].pb(last);
		}
		prev = last;
		++last;	

		int pos2 = pos[o.se];

		solve(p , pos1 + 1 , pos2 - 1 , prev);
		solve(p , l , pos1 - 1 , prev);
		solve(p , pos2 + 1 , r  , prev);
		
	}
}

vi restore(){
	vi res;
	priority_queue<pii , vector<pii> , greater<pii>> q; 
	q.push(code[0]);
	
	while(!q.empty()){
		pii u = q.top();
		q.pop();
		
		res.pb(u.fi);
		res.pb(u.se);
		
		for(int c : g[rcode[u]]){
			q.push(code[c]);
		}
	}
	return res;
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.precision(0); 


	cin >> n;
	
	pos.resize(n + 1);
	
	vi p(n);
	rep(i , n){
		cin >> p[i];
		pos[p[i]] = i;
		
		int par = i % 2;
		
		t[par][n + i] = p[i];
		t[par ^ 1][n + i] = INF;
	}

	
	build(0);
	build(1);
	
	solve(p , 0 , n - 1);
	
	for(int e : restore()){
		cout << e << " ";
	}
	
	return 0;
}

Measured memory_bytes: 38612
#include <bits/stdc++.h>
#define int long long
#define f(i,n) for(int i=0;i<n;i++)
#define INF INT_MAX
#define LINF LLONG_MAX
#define mod 1000000007
#define pie 3.141592653589793238462643383279
#define P pair<int,int>
#define prique priority_queue
#define F first
#define S second
using namespace std;
signed main(){
	int ans=0;
	string s="CODEFESTIVAL2016",t;
	cin>>t;
	f(i,16){
		if(s[i]!=t[i]) ans++;
	}
	cout<<ans<<endl;
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
    using namespace std;
    using ll = long long;
     
     
    void solve(){
        ll n,m,d,j,k=1,c=0,f=0;
        cin>>n;
        ll a[n];j=n-2;
        for(int i=0;i<n;i++) cin>>a[i];
        c=a[0],f=a[n-1];
        while(k<=j){
            if(c>f){ f+=a[j];j--; }
            else{ c+=a[k];k++; }
        }
        cout<<abs(c-f);
    }
         
    int main() {
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        int q;
        //cin>>q;
        //for(int i=0;i<q;i++)
    	    solve();
    	return 0;
    }

Measured memory_bytes: 1792