akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define mod2 998244353 
#define PI 3.14159265
#define ll long long
#define ld long double
#define pi pair<ll,ll>
#define pb push_back
#define vi vector<ll>
#define sz size()
#define fi first
#define se second
#define lz length()
#define all(x) (x).begin(),(x).end()
#define scf(x) scanf("%lld",&x)
#define rep(i,n) for(ll i=0;i<n;i++)
const int INF = (int)1e9;
const ll IINF=1LL<<62;
const int maxn=10000005;
int divr[maxn];
/*ll modexpo(ll a,ll b)
{
     ll res=1LL;
     while(b>0)
     {
          if(b&1)res=(res*a)%mod;
          a=(a*a)%mod;
          b>>=1;
     }
     return res;
}*/
void divisor()
{for(int i=2;i<sqrt(maxn);i++)
     {
          if(!divr[i])
          {
               for(int j=i*i;j<maxn;j+=i)if(!divr[j])divr[j]=i;     
          }
     }
     for(int i=1;i<maxn;i++)if(!divr[i])divr[i]=i;
}
 
/*const int N=1000005;
ll n;
struct line {
    long long m, c;
    long long eval(long long x) { return m * x + c; }
    long double intersectX(line l) { return (long double) (c - l.c) / (l.m - m); }
};
vector<pair<pi,ll>> rect;
deque<line> dq;
*/
 
 
 
 
 














int main()
{
     string s;
     cin>>s;
     int ct0=0,ct1=0;
     for(int i=0;i<s.length();i++)
     {
          if(s[i]=='1')ct1++;
          else ct0++;
     }
     cout<<2*min(ct1,ct0);

}




















 
 
 
 
 

















Measured memory_bytes: 512
package main

import (
	"fmt"
	"sort"
)

func main() {
	// 7 5 5 OK 17
	// 5 7 5 OK 17
	// 5 5 7 OK 17
	// 5 7 7 NG 19
	// 7 7 3 NG 17

	var intArray = make([]int, 3)
	for i := 0; i < 3; i++ {
		fmt.Scan(&intArray[i])
	}

	sort.Sort(sort.IntSlice(intArray))

	if intArray[0] == 5 && intArray[1] == 5 && intArray[2] == 7 {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}


Measured memory_bytes: 512
N = int(input())
graph = [0 for i in range(N+1)]
for i in range(N):
  a = int(input())
  graph[i+1] = a

d = [999999 for i in range(N+1)]
d[1]=0
seen = [0 for i in range(N+1)]

q = [1]
seen[1]=1

while q:
  v = q[0]
  del q[0]

  if seen[graph[v]]==0:
    q.append(graph[v])
    seen[graph[v]]=1
  if d[v]+1<d[graph[v]]:
    d[graph[v]]=d[v]+1
print(-1 if d[2]==999999 else d[2] )
  

Measured memory_bytes: 11864
#include <iostream>
using namespace std;
const long long INF = 1e18;

int main() {
    int n;
    cin >> n;
    bool is_z = false;
    bool is_r = false;
    long long a = 1;
    for (int i=0; i<n; ++i) {
        if (is_z) continue;
        long long num; cin >> num;
        if (num == 0) is_z = true;
        if (is_r) continue;
        if (a * num > INF || num > INF / a) is_r = true;
        a *= num;
    }
    if (is_z) cout << 0 << endl;
    else if (is_r) cout << -1 << endl;
    else cout << a << endl;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
const long long MOD = 1e9+7;
using namespace std;

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

	int A,B,C;
	cin >> A >> B >> C;

	if (C>=A && C<=B) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}
}


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

int main(){
	int n,a,b;
	string s;
	cin >> n >> a >> b >> s;
	int A = 0;
	int B = 0;
	for(int i = 0; i < n; i++){
		if(s[i] == 'a' && A + B < a + b){
			cout << "Yes" << endl;
			A++;
		}
		else if(s[i] == 'b' && A + B < a + b && B < b){
			cout << "Yes" << endl;
			B++;
		}
		else cout << "No" << endl;
	}
	return 0;
}

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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define all(a) (a).begin(), (a).end()
#define bit32(x) (1 << (x))
#define bit64(x) (1ll << (x))
#define sz(v) ((int) v.size())

using namespace std;

using i64 = long long;
using f80 = long double;
using vi32 = vector<int>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

void yes() { cout << "Yes" << endl; exit(0); }
void no() { cout << "No" << endl; exit(0); }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> void amax(T &x, T y) { x = max(x, y); }
template <typename T> void amin(T &x, T y) { x = min(x, y); }
template <typename T> T exp(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { for (auto &x : v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }

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

int f(int n) {
  int ret = 0;
  for (int i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret += 1;
      if (n / i != i) ret += 1;
    }
  }
  return ret;
}

void solve() {
  int n;
  cin >> n;
  int MAX = n;
  vi64 memo(MAX + 1, 1);
  for (int i = 2; i <= MAX; i++) {
    for (int j = i; j <= MAX; j += i) {
      memo[j] += 1;
    }
  }
  i64 ans = 0;
  reps(i, n) {
    memo[i] *= i;
    ans += memo[i];
  }
  cout << ans << endl;
}


Measured memory_bytes: 81320
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
class Program
{
    public static void Main()
    {
        String[] input = Console.ReadLine().Split();
        long N = long.Parse(input[0]);
        long M = long.Parse(input[1]);
        long Q = long.Parse(input[2]);
        long[,] a = new long[4,Q];
        for (int i = 0; i < Q; i++)
        {
            input = Console.ReadLine().Split();
            a[0,i]= long.Parse(input[0]);
            a[1,i] = long.Parse(input[1]);
            a[2,i] = long.Parse(input[2]);
            a[3,i] = long.Parse(input[3]);
        }
        int[] num = Enumerable.Repeat(1, (int)N).ToArray();
        num[0] = 1;

        long max = 0;
        while (num[0] == 1)
        {
            long point = 0;
            for (int i = 0; i < Q; i++)
                if (num[a[1,i] - 1] - num[a[0,i] - 1] == a[2,i])
                    point += a[3,i];
            if (max < point)
                max = point;
            long j = N - 1;
            while (j > 0 && num[j] == M)
                j--;
            int value = ++num[j];
            while (++j < N)
                num[j] = value;
        }
        Console.WriteLine(max);
    }
}

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

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<long long> vec(N);
    for (int i = 0; i < N; ++i)
        cin >> vec[i];
    long long dif = *max_element(vec.begin(), vec.end()) - *min_element(vec.begin(), vec.end());
    cout << dif << "\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
int main() {
    int n, m;
    cin >> n >> m;
 
    vector<int> l(m);
    vector<int> r(m);
 
    for(int i = 0; i < m; i++) {
        cin >> l.at(i) >> r.at(i);
    }
    sort(l.begin(), l.end());
    sort(r.begin(), r.end());
 
    int lmax = l[m-1];
    int rmin = r[0];
 
    if(rmin >= lmax){
        cout << rmin - lmax + 1 << endl;
    }
    else{
        cout << 0 << endl;
    }
    return 0;
}


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

#define lli long long int
#define pb push_back
#define in insert
#define pi pair<int, int>
#define pii pair<int, pi>
#define mp make_pair
#define fir first
#define sec second
#define MAXN 100001

signed main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  string s;
  cin >> s;

  if (s[2] == s[3] && s[4] == s[5])
  {
    cout << "Yes\n";
  }
  else
  {
    cout << "No\n";
  }

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <queue>
#include <map>
#include <stack>
#include <bitset>
#include <numeric> //lcm
#include <iomanip> //double精度 setprecision

using namespace std;

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = n-1; i >= 0; --i)
#define rep1(i,n) for(int i = 1; i <= (n); ++i)
#define rrep1(i,n) for(int i = (n); i >= 1; --i)
#define REP(i,n,m) for(int i = (n); i < (m); ++i)
#define all(vec) (vec).begin(),(vec).end()

#define debug(vec) for(auto v : vec) cerr << v << " "; cerr << endl;
#define debug2D(vec2D) for(auto vec : vec2D) { for (auto v : vec) cerr << v << " "; cerr << endl; } 
#define debugP(vec) for(auto v : vec) cerr << "(" << v.first << "," << v.second << ") "; cerr << endl;
#define debug2DP(vec2D) for(auto vec : vec2D) { for (auto v : vec) cerr << "(" << v.first << "," << v.second << ") "; cerr << endl; } 

const char en = '\n';

typedef long long ll;

constexpr ll INF = 1000000000; //10^10
//const ll MOD = 998244353;
constexpr ll MOD = 1000000007;

template<class T> inline bool chmax(T& a, T b) { if (a <= b) { a = b; return true; } else return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } else return false; }

map<ll, int> primeFactor0(ll n) {
	map<ll, int> ret;

	while (n % 2 == 0) {
		n /= 2;
		ret[2]++;
	}

	int i = 3;
	while (n > 1 && (ll)i * i <= n) {
		while (n % i == 0) {
			n /= i;
			ret[i]++;
		}
		i += 2;
	}

	if (n != 1) ret.insert({ n,1 });

	return ret;
}

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

	ll n; cin >> n;

	map<ll,int> mp;
	mp = primeFactor0(n);

	ll ans = 0;
	for (auto& pe : mp) {
	  ll cnt = pe.second;
		int i = 1;
		for (int all = 1; all <= cnt; i++, all += i);

		ans += i-1;
	}
	cout << ans << endl;
}


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

   public static void main(String[] args) {
    int count=0;
    int temp=0;
  	Scanner scan=new Scanner(System.in); 
    String s=scan.next(); 
    char[] ch = new char[s.length()];
    char[] rev = new char[s.length()];
    for (int i = 0; i < ch.length; i++) { 
            ch[i] = s.charAt(i); 
    } 
    for (int i = rev.length-1; i >=0; i--) { 
            rev[temp] = s.charAt(i); 
      		temp++;
    } 
    for(int i = 0; i<= (ch.length/2)-1; i++) {
    	if(ch[i] != rev[i]){
        count++;
        }
    }
    System.out.println(count);
   }
}

Measured memory_bytes: 22868
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 0> { using type = T; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
template <class T> inline void chmin(T &a, const T& b) { if (b < a) a = b; }
template <class T> inline void chmax(T &a, const T& b) { if (b > a) a = b; }
/* clang-format on */

using P = pair<int, int>;

int main() {
#ifdef DEBUG
  ifstream ifs("in.txt");
  cin.rdbuf(ifs.rdbuf());
#endif
  int N;
  while (cin >> N) {
    vector<ll> A(N);
    for (ll& x : A) cin >> x;
    sort(A.begin(), A.end());
    vec<int, 2> G(1);
    auto branch = [&](int p) {
      int v = G.size();
      G.resize(v + 2);
      G[p].push_back(v);
      G[p].push_back(v + 1);
      return v;
    };
    branch(0);
    int plus = 1, neg = 2;
    for (int i = 1; i < N - 1; i++) {
      if (A[i] < 0) {
        plus = branch(plus);
      } else {
        neg = branch(neg);
      }
    }
    vector<P> leafs;
    auto dfs = [&](auto f, int v, int s) -> void {
      if (G[v].empty()) {
        leafs.emplace_back(s, v);
      } else {
        f(f, G[v][0], s);
        f(f, G[v][1], -s);
      }
    };
    dfs(dfs, 0, 1);
    sort(leafs.begin(), leafs.end());
    vector<ll> val(G.size());
    for (int i = 0; i < N; i++) val[leafs[i].snd] = A[i];
    auto dfs2 = [&](auto f, int v) -> ll {
      if (G[v].empty()) {
        return val[v];
      } else {
        ll a = f(f, G[v][0]);
        ll b = f(f, G[v][1]);
        cout << a << " " << b << endl;
        return a - b;
      }
    };
    ll M = 0;
    for (int i = 0; i < N; i++) M += leafs[i].fst * A[i];
    cout << M << endl;
    dfs2(dfs2, 0);
  }
  return 0;
}


Measured memory_bytes: 22316
using System;

namespace atcoderA
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            int ans = 0;
            for(int i = 1; i <= N; i++)
            {
                ans += i;
            }
            Console.WriteLine(ans);
        }
    }
}

Measured memory_bytes: 11092
#include<bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
#define fil(x) memset(x, 0, sizeof(x))
#define fillb(x) memset(x,false,sizeof(x))
#define fillm(x) memset(x, -1, sizeof(x))
#define mp make_pair
#define pll pair<int, int>
#define pf printf
#define sf scanf
#define all(x) x.begin(),x.end()
#define pb push_back
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define np std::string::npos
#define fo(i,n) for(int i=0;i<n;i++)
#define fo1(i,n) for(int i=1;i<n;i++)
#define fof(i,a,b) for(int i=a;i<=b;i++)
#define off(i,a,b) for(int i=a;i>=b;i--)
#define of(i,n) for(int i=n-1;i>=0;i--)
#define highest(x) numeric_limits<x>::max()
#define lowest(x) numeric_limits<x>::min()
#define Inf INFINITY
#define minv(v) *min_element(v.begin(),v.end())
#define maxv(v) *max_element(v.begin(),v.end())
#define cases(cs,t) for(int cs=1;cs<=t;cs++)
#define PI acos(-1)
#define nl endl

typedef unsigned long long lll;
typedef long long ll;
int knigtx8[] = {2, 2, -2, -2, 1, 1, -1, -1}; ///knight move in chess
int knigty8[] = {1, -1, 1, -1, 2, -2, 2, -2}; ///knight move in chess
int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1}; ///for 8 directions
int dy8[] = {1,-1, 1, -1, 0, 0, -1, 1}; ///for 8 directions
int dx4[] = {0, 0, 1, -1}; ///for 4 directions
int dy4[] = {1, -1, 0, 0}; ///for 4 directions
const int maxx=100005;

//this fuction sorts vector pair according to first element in descending order.
bool sortinrev(const pair<int,int> &a,const pair<int,int> &b)
{
    return a.first>b.first;
}
ll pw(ll a, ll b)
{
    ll ans = 1;
    for(ll i = 1; i <= b; ++i)
        ans = (ans * a);
    return ans;
}
template<typename T>inline T Bigmod(T base, T power, T MOD){
    T ret=1;
    while(power)
    {
        if(power & 1)ret=(ret*base)%MOD;
        base=(base*base)%MOD;
        power>>=1;
    }
    return ret;
}

int main()
{
    IOS;
    int a[5],ans;
    fo(i,5){cin>>a[i]; if(a[i]==0)ans=i+1;}
    cout<<ans<<endl;
    return 0;
}

///Alhamdulillah


Measured memory_bytes: 3608
#include "bits/stdc++.h"
#define ALL(obj) (obj).begin(),(obj).end()
#define RALL(obj) (obj).rbegin(),(obj).rend()
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define REPR(i, n) for(int i = (int)(n); i >= 0; i--)
#define FOR(i,n,m) for(int i = (int)(n); i < int(m); i++)
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;
const int INF = 1e9 + 6;
const ll LLINF = 4e18;

int main() {
    int n; cin >> n;
    vector<int> p(n),cnt(n,0);
    REP(i, n) cin >> p[i];
    int ans = 1;
    REP(i, n) {
        if (p[i] != 1) {
            cnt[p[i] - 1] = cnt[p[i] - 2] + 1;
            ans = max(ans, cnt[p[i] - 1]);
        }
        else cnt[0] = 1;
    }
    cout << n - ans << endl;
    getchar(); getchar();
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main(){
    int n,a[200000];
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i];
        a[i]-=i+1;
    }
    sort(a,a+n);
    int b=a[n/2];
    int ans=0;
    for(int i=0;i<n;i++)
        ans+=abs(a[i]-b);
    cout<<ans<<endl;
}


Measured memory_bytes: 1792
n = int(input())
alphabet = [chr(i) for i in range(97, 97+26)]
ans = ""
i = 0
# 次26**iを引いたらマイナスになるよ、というところで抜ける
while n - 26**i >= 0:
    n -= 26**i
    i += 1
# ここを抜けた時,iは桁数、nは「i桁の中でn番目」を表す

# したからk番目は、26**kで割った余り（に対応するアルファベット）
# 「上の桁で表現しきれなかった数」＝「その桁での表現」
for _ in range(i):
    q,r = divmod(n,26)
    n = q
    ans += alphabet[r]
print(ans[::-1])




Measured memory_bytes: 9076
import sys
from collections import Counter

n, m, *r = map(int, sys.stdin.read().split())

def main():
    c = Counter(r)
    for v in range(1, n+1):
        yield c.get(v, 0)

if __name__ == '__main__':
    ans = main()
    print(*ans, sep='\n')

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

using namespace std;

vector <int> idx;
vector < pair<int,int> > point;

double dist (pair<int,int> x, pair<int,int> y) {
	long long a = x.first - y.first;
	long long b = x.second - y.second;
	return sqrt(a*a + b*b);
}


double calc_len () {
	double len = 0;
	for (int i = 1; i < int(point.size()); ++i) {
		len += dist (point[idx[i]], point[idx[i - 1]]);
	}
	return len;
}

int main () {

	int n;
	scanf("%d", &n);

	for (int i = 0, a, b; i < n; ++i) {
		scanf("%d %d", &a, &b);
		
		idx.push_back (i);
		point.push_back ({a, b});
	}

	int div = 0;
	double sum = 0;

	do {
		div++;
		sum += calc_len ();
	}
	while (next_permutation(idx.begin(), idx.end()));

	double resp = sum / (double)div;

	printf("%.10lf\n", resp);

	return 0;
}





Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int wa(int n){
    int sum=0;
    while (n>0)
    {
        sum+=n%10;
        n /=10;
    }
    return sum;
}
int main(){
    int N;
    cin >> N;
    int a[110];
    for (int i = 0; i < N; i++)
    {
        cin >> a[i];
    }
    sort(a,a+N);
    int Alice,Bob;
    Alice=0;
    Bob=0;
    
    if (N%2==0)
    {
        for (int i = 0; i < N; i++)
        {
            if (i%2==0)
            {
                Bob+=a[i];              
            }   
            else
            {
                Alice+=a[i];                                    
            }
            
        }                           
        
    }
    else
    {
        for (int i = 0; i < N; i++)
        {
            if (i%2==0)
            {
                Alice+=a[i];        
            }
            else
            {
                Bob+=a[i];  
            }
            
        }
        
    }
    cout << Alice-Bob<<endl;
    
    
    
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int n,b[102],h;
int main()
{
	scanf("%d",&n);
	for(int i=2;i<=n;i++)
		scanf("%d",&b[i]);
	h=b[2];
	for(int i=2;i<n;i++)
		h+=min(b[i],b[i+1]);
	h+=b[n];
	printf("%d",h);
}

Measured memory_bytes: 128
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
 
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<pair<int, int> > vpii;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
#define INF 0x3f3f3f3f
#define MOD 1000000007
#define EPSILON 0.00001
#define f first
#define s second
#define pb push_back
#define mp make_pair
 
#define FOR(i, a, b) for (int i=(a); i<=(signed)(b); i++)
#define F0R(i, a) for (int i=0; i<(signed)(a); i++)
#define RFOR(i, a, b) for (int i=(a); i >= b; i--)

#define MN 100005
int n;
ll x[MN];
ll fac[MN];

pll gcd(ll a, ll b){ //a*first+b*second=gcd
    if(a == 0){
        return mp(0, 1);
    }

    pll prev = gcd(b%a, a);

    return mp(prev.s-(b/a)*prev.f, prev.f);
} //using ll's just to be safe wrt overflow issues

ll modInv(ll x){ //return x^-1 % MOD
    pll res = gcd(x, MOD);

    res.f = (res.f+MOD)%MOD;

    //cout << "modinv of " << x << " is " << res.f << "\n";

    return res.f;
}

ll modDiv(ll x, ll y){
    return (x*modInv(y))%MOD;
}

ll getFacs(){
    fac[0] = 1;
    FOR(i, 1, MN-1){
        fac[i] = (fac[i-1]*i)%MOD;
    }
}

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

    getFacs();

    cin >> n;
    F0R(i, n){
        cin >> x[i];
    }
    ll sm = 0;
    ll cur = 0;
    FOR(i, 1, n-1){
        ll d = x[i]-x[i-1];
        cur += modDiv(fac[n-1], i);
        cur %= MOD;
        sm += (cur*d)%MOD;
        sm %= MOD;
    }
    //ll ans = (sm*fac[n-1])%MOD;
    cout << sm << "\n";

    return 0;
}


Measured memory_bytes: 1792
#include<iostream>
#include<cstdio>
using namespace std;
int r,c,arr[100][100],s[100],sum;
int main() {
	cin>>r>>c;
	for(int i =0; i<r; i++)
		for(int j=0; j<c; j++) {
			int t;
			cin>>t,arr[i][j]=t;
		}
	for(int i =0; i<r; i++) {
		sum=0;
		for(int j=0; j<c; j++) {
			cout<<arr[i][j]<<" ",s[j]+=arr[i][j],sum+=arr[i][j];
		}
		cout<<sum<<endl,sum=0;
	}
	for(int j=0; j<c; j++) {
			sum+=s[j],cout<<s[j]<<" ";
		}
	cout<<sum<<endl;
	return 0;
}


Measured memory_bytes: 3100
use std::io;
use std::str;

pub struct Scanner<R> {
    reader: R,
    buffer: Vec<String>,
}

impl<R: io::BufRead> Scanner<R> {
    pub fn new(reader: R) -> Self {
        Scanner {
            reader: reader,
            buffer: Vec::new(),
        }
    }

    pub fn token<T: str::FromStr>(&mut self) -> T {
        loop {
            if let Some(token) = self.buffer.pop() {
                return token.parse().ok().expect("failed to parse token");
            }
            let mut input = String::new();
            self.reader.read_line(&mut input).expect("failed to read");
            self.buffer = input.split_whitespace().rev().map(String::from).collect();
        }
    }
}

use io::Write;
fn main() {
    let (stdin, stdout) = (io::stdin(), io::stdout());
    let mut stdout = io::BufWriter::new(stdout);
    let mut scanner = Scanner::new(stdin.lock());

    let k: usize = scanner.token();
    let mut s: Vec<char> = scanner.token::<String>().chars().collect();

    if s.len() > k {
        for i in 0..k {
            write!(&mut stdout, "{}", s[i]);
        }
        writeln!(&mut stdout, "...");
    } else {
        for x in s {
            write!(&mut stdout, "{}", x);
        }
        writeln!(&mut stdout, "");
    }
}


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

int main() {
  int N;
  cin >> N;
  switch (N) {
    case 1:
      cout << "Hello World" << endl;
      break;
    case 2:
      int A, B;
      cin >> A >> B;
      cout << A+B << endl;
      break;
    default:
      break;
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    int N;
    cin >> N;
    int A[N+1],B[N+1];
    for(int i=0; i<N+1; i++){
        cin >> A[i];
    }
    for(int i=0; i<N; i++){
        cin >> B[i];
    }
    B[N] = 0;
    
    long long int cnt = 0;
    for(int i=N; i>=0; i--){
        //cout << "-----" <<endl;
        //cout << "B[" << i << "] = " << B[i] << endl;
        if(B[i] != 0){
            if(A[i]<=B[i]){
                cnt += A[i];
                A[i] = 0;
            }else{
                cnt += B[i];
                A[i] -= B[i];
            }
            //cout << "cnt = " << cnt << endl;
        }
        if(i != 0){
            //cout << "B[" << i << "-1] = " << B[i-1] << endl;
            if(A[i]<=B[i-1]){
                cnt += A[i];
                B[i-1] -= A[i];
            }else{
                cnt += B[i-1];
                B[i-1] = 0;
            }
            //cout << "cnt = " << cnt << endl;
        }
    }
    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 1024
import java.util.Scanner;

/**
 * 線形探索
 * @author nobu
 * @see <a href="http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_4_A&lang=ja">ALDS1_4_A</a>
 */
public class Main {

	private static final int NOT_FOUND = -1;

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

		int q = sc.nextInt();
		int t[] = new int[q];
		for (int i = 0; i < q; i++) {
			t[i] = sc.nextInt();
		}

		int answer = 0;
		for (int i = 0; i < q; i++) {
			if (linearSearch2(s, t[i]) != -1) answer++;
		}

		System.out.println(answer);

		sc.close();
	}

	private static int linearSearch1(int x[], int key) {
		for (int i = 0; i < x.length; i++) {
			if (x[i] == key) return i;
		}
		return NOT_FOUND;
	}

	private static int linearSearch2(int x[], int key) {
		int y[] = new int[x.length + 1];

		for (int i = 0; i < x.length; i++) y[i] = x[i];
		y[x.length] = key;

		int i = 0;
		while (y[i] != key) {
			i++;
		}
		if (i == x.length) return NOT_FOUND;
		return i;
	}

}



Measured memory_bytes: 43636
#include <iostream>
#include <algorithm>
#include <math.h>
#include <string>
#include <stack>
#include <set>
#include <vector>
using namespace std;
typedef long long ll;

void printarray(int n, int a[])
{
    for (int i = 0; i < n; i++)
    {
        cout << a[i];
        /*if (i != n - 1)
            cout << " ";*/
    }
    cout << endl;
}

void printpairaraay(int n, pair<int, int> a[])
{
    int x, y;
    for (int i = 0; i < n; i++)
    {
        x = a[i].first;
        y = a[i].second;
        cout << x << " " << y << "\n";
    }
    cout << endl;
}

void swaprange(int b, int t, int e, int a[])
{
    for (int i = 0; i < e - b; i++)
    {
        swap(a[b + i], a[i + t]);
    }
}

int my_binarysearch(int n, int a[], int x)
{
    int ret = 0;
    if (distance(lower_bound(a, a + n, x), upper_bound(a, a + n, x)) != 0)
        ret = 1;
    return ret;
}

void printbit(unsigned int x)
{
    unsigned int b, y;
    
    b = 32;
    int a[b];
    y = pow(2, 31);
    cin >> x;

    for (int i = 0; i < b; i++)
    {
        if (x >= y)
        {
            a[i] = 1;
            x -= y;
        }
        else
            a[i] = 0;

        y = y >> 1;
    }
    printarray(b, a);
}

int main()
{	
  	const unsigned int max = 4294967295;
  	unsigned int a, b;
    cin >> a >> b;
    printbit(a & b);
    printbit(a | b);
    printbit(a ^ b);
    return 0;
}

// getline(cin,s);
// a = strtok(s, ",");  ","で分解
// for (int i = 0; i < n; i++)


Measured memory_bytes: 3108
n=int(input())
a=list(map(int,input().split()))
med=sum(a)/n#平均の値
gosa=[]
for i in range(n):
    gosa.append(abs(med-a[i]))
ans=min(gosa)
for i in range(n):
    if ans==gosa[i]:
        print(i)
        exit()
    


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define rep0(i,n) for(i=0;i<n;i++)
#define rep1(i,n) for(i=1;i<=n;i++)
#define test(a) cout << "*" << a << endl
#define ll long long
int main(){
  int n,k;
  int d[101];
  int A[101][101];
  int i,j;
  bool human[101]={false};
  int humanNo=0;
  
  cin >> n >> k;
  rep1(i,k){
    cin >> d[i];
    rep1(j,d[i]){
      cin >> A[i][j];
      human[A[i][j]] = true;
    }
  }
  rep1(i,n){    
    if(human[i]==false){
      humanNo++;  
      //test(i);
    }
  }
  cout << humanNo << endl;
  
  /*rep1(i,k){
    test(d[i]);
    rep1(j,d[i]){
      test(A[i][j]);
    }
  }*/
  

  
}

Measured memory_bytes: 3672
height,width=map(int,input().split())
graph = [[s for s in input()] for i in range(height)]

for r in range(height):
    for c in range(width):
        if graph[r][c]==".":
            continue

        if r>0 and graph[r-1][c]=="#":
            continue

        if r<width-1 and graph[r+1][c]=="#":
            continue

        if c>0 and graph[r][c-1]=="#":
            continue

        if c<height-1 and graph[r][c+1]=="#":
            continue

        print("No")
        exit()
print("Yes")

Measured memory_bytes: 3064
num = input()
x = ['+', '-']

for i in x:
  for j in x:
    for k in x:
      n = eval(num[0]+ i + num[1] + j + num[2] + k + num[3])
      if n == 7:
        print(num[0] + i + num[1] + j + num[2] + k + num[3] + '=7')
        exit()

Measured memory_bytes: 9044
#include <stdio.h>
#include <math.h>
 
int main(){
  long long x=1;
  int s, z=0;
  scanf("%d", &s);
  long long y[s];
  for(int i=0; i<s; i++){
    scanf("%lld", &y[i]);
    if(y[i] == 0){
      printf("0\n");
      return 0;
    }
  }
  for(int i=0; i<s; i++){
    if(x > 1000000000000000000/y[i] || x*y[i] < 0){
      printf("-1\n");
      return 0;
    }
    x*=y[i];
  }
  printf("%lld\n", x);
}

Measured memory_bytes: 2492
import math

#素数判定
def IsPrime(n):
    if n == 1:
        return False
    for i in range(2, int(math.sqrt(n)) + 1):
        if n % i == 0:
            return False
    return True

q = int(input())

a = [0] * (10**5 + 1)

for i in range(10**5 + 1):
    #条件を満たすなら1
    if IsPrime(i) and IsPrime((i + 1) / 2) and i % 2 == 1:
        a[i] = 1
    else:
        a[i] = 0

#先頭からの累積和をとる
for i in range(10**5):
    a[i + 1] += a[i]

#クエリ処理
for i in range(q):
    l, r = map(int, input().split())
    print(a[r] - a[l - 1])

Measured memory_bytes: 12008
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=998244353;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

int n;

int main(){
	cin>>n;
	map<int,int> mp;
	ll res=0;
	for(int i=0;i<n;i++){
		int x;
		cin>>x;
		res+=mp[i-x];
		mp[x+i]++;
	}
	cout<<res<<endl;
}

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

using namespace std;

using ull = unsigned long long;

int main() {
    int N, p[50], cnt = 0;
    cin >> N;
    for(int i = 0; i < N; ++i) {
        cin >> p[i];
        if(p[i] != i + 1) {
            cnt++;
        }
    }
    cout << (cnt < 3 ? "YES" : "NO") << endl;
    return 0;
}


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

#define mem(arr,x) memset(arr,x,sizeof(arr))
#define pb push_back
#define ll long long
#define mp make_pair
#define rep(i,n)  for(ll i=0;i<n;i++)
#define repi(i,n)  for(ll i=1;i<=n;i++)
#define all(x)   (x.begin(),x.end())

int max(int a,int b)
{
	if(a>b)
	return a;
	return b;
}

int main()
{
	
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
 ll int n,w;
	cin>>n>>w;
	ll int wt[n],v[n];
	rep(i,n)
	cin>>wt[i]>>v[i];
	
	ll int dp[n+1][w+1];
	for(ll int i=0;i<=n;i++)
	{
		for(ll int j=0;j<=w;j++)
		{
			if(i==0 || j==0)
			dp[i][j]=0;  
			else if(wt[i-1]<=j)
			 {  
				 dp[i][j]=max(dp[i-1][j],v[i-1]+dp[i-1][j-wt[i-1]]);
			 }
			 else
			 {
				 dp[i][j]=dp[i-1][j];
			 }
		 }
	 }
	 cout<<dp[n][w]<<'\n';
 }
	
	
	


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

int main() {
  vector<ll> v(3);
  rep(i, 3)
  cin >> v.at(i);
  sort(v.begin(),v.end());
  ll a,b,c;
  a = v.at(0);
  b = v.at(1);
  c = v.at(2);
  
  if(a%2==0 || b%2==0 || c%2==0)
    cout << 0 << endl;
  else
    cout << (a*b*(1+c/2))-(a*b*(c/2)) << endl;
}

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

int main(){
  string S;
  cin>>S;
  int n=S.size();
  int c=0;
  if(n%2==0){
    rep(i,n/2){
      if(S.at(2*i)!='h' || S.at(2*i+1)!='i'){
        c++;
        break;
      }
    }
  }
  else{
    c++;
  }
  
  if(c==0){
    cout<<"Yes"<<endl;
  }
  
  if(c==1){
    cout<<"No"<<endl;
  }
}
  
        
  

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int h = Integer.parseInt(scan.next());
        int a = Integer.parseInt(scan.next());
        //int c = Integer.parseInt(scan.next());
        int cnt = 0;
        while(h>0) {
            h = h-a;
            cnt++;
        }
        System.out.println(cnt);
    }
}


Measured memory_bytes: 23252
#pragma region
#include <bits/stdc++.h>
using namespace std;
inline void ci(void){
  return;
}
template <typename First, typename... Rest>
void ci(First& first, Rest&... rest){
  cin >> first;
  ci(rest...);
  return;
}
inline void co(void){
  cout << endl;
  return;
}
template <typename First, typename... Rest>
void co(First first, Rest... rest){
  cout << first << "";
  co(rest...);
  return;
}
#define ll long long
#define ld long double
#define st string
#define wh while
#define ve vector
#define mp make_pair
#define tp tuple
#define mt make_tuple
#define pb push_back
#define pof pop_front
#define pob pop_back
#define pf push_front
#define fr front
#define ft first
#define sc second
#define tos to_string
#define len length
#define rt return
#define br break
#define con continue
#define lcm(n, m) (n * m / __gcd(n, m))
#define np next_permutation
#define repi(i, m, n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i, n) repi(i, 0, n)
#define revi(i, m, n) for(ll i=(ll)(m) - 1;i>=(ll)(n);i--)
#define rev(i, m) revi(i, m, 0)
#define sz(v) ((int)(v).size()) 
#define each(i, n) for(auto&& i: n)
#define all(n) n.begin(), n.end()
#define allr(n) n.rbegin(), n.rend()
#define sp(n) cout << fixed << setprecision(n)
#define pi 3.14159265358979323846
#define inf 1000000007
#pragma endregion
// sqrt ルート, int 2*10^9, gcd　最大公約数
// __builtin_popcount bitの個数

ve<int> dx = {0, 0, 1, -1}, dy = {1, -1, 0, 0};

int main() {
  ll n, m, k;
  ci(n, m, k);
  ve<ll> A(n + 1), B(m + 1);
  A.at(0) = 0;
  rep(i, n){
    ll a;
    ci(a);
    A.at(i + 1) = A.at(i) + a;
  }
  B.at(0) = 0;
  rep(i, m){
    ll b;
    ci(b);
    B.at(i + 1) = B.at(i) + b;
  }
  ll cnt = m + 1, ans = 0;
  rep(i, n + 1){
    rev(j, cnt){
      if(A.at(i) + B.at(j) <= k){
        ans = max(ans, i + j);
        cnt = j + 1;
        br;
      }
    }
  }
  co(ans);
}


Measured memory_bytes: 6384
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
	long long X;
	cin >> X;
	for (long long A = 0; A <= 1000; A++)
	{
		for (long long B = 0; B <= 1000; B++)
		{
			if (pow(A, 5) - pow(B, 5) == X)
			{
				cout << A << " " << B << endl;
				return 0;
			}
			else if (pow(A, 5) + pow(B, 5) == X)
			{
				cout << A << " " << (-1)*B << endl;
				return 0;
			}
		}
	}
}

Measured memory_bytes: 4100
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define sbits(a) __builtin_popcount(a)
#define smin(a, b) a = min(a, b)
#define smax(a, b) a = max(a, b)
#define gcd __gcd
#define lcm(a, b) ((a * b) / gcd(a, b))
#define pq priority_queue
#define um unordered_map
#define us unordered_set
#define lb lower_bound
#define ub upper_bound
#define F first
#define B begin()
#define E end()
#define ln length()
#define sz size()
#define S second
#define em empty()
#define nani(x) cerr << #x << " is " << x << endl;
#define ch(x) (x - 'a' + 1)
#define mp make_pair
#define pb push_back
#define loop(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define scan(x, n) loop(i, 0, n) cin >> x[i];
#define adde(g, u, v) g[u].pb(v), g[v].pb(u);
#define addew(g, u, v, w) g[u].pb({ v, w }), g[v].pb({ u, w });
#define print(x, n) loop(i, 0, n) cout << x[i] << " ";
#define fast ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define inf 10000000000
#define mod 1000000007

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<long> vl;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef pair<long, long> pll;
typedef vector<ii> vii;
typedef vector<pll> vll;
typedef um<int, int> umii;
typedef um<char, int> umci;
typedef map<char, int> mci;
typedef map<int, int> mii;

const int N = 1e5 + 1;
int A[N];

int main()
{
    fast;
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int n;
    cin >> n;
    scan(A, n);

    int c = 0, ans = 0;
    for (int i = 1; i < n; i++) {
        if (A[i] <= A[i - 1])
            c++;
        else {
            smax(ans, c);
            c = 0;
        }
    }
    cout << max(c, ans);
    return 0;
}


Measured memory_bytes: 640
#define _GLIBCXX_DEBUG
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <map>
#include <list>
using namespace std;
typedef long long ll;
#define ALL(v) (v).begin(), (v).end()
#define mp make_pair
const int INF = 1e9;
const ll LINF = 1e18;
const int MOD = 1e9+7;

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

	vector<int> a(M);
	vector<int> b(M);
	vector<int> c(M);
	for (int i = 0; i < M; i++) {
		cin >> a[i] >> b[i] >> c[i];
		a[i]--; b[i]--;
	}

	vector<ll> d(N, -LINF);

	d[0] = 0;
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < M; j++) d[b[j]] = max(d[b[j]], d[a[j]] + c[j]);
	}
	
	ll ans1 = d[N-1];
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < M; j++) d[b[j]] = max(d[b[j]], d[a[j]] + c[j]);
	}

	ll ans2 = d[N-1];
	if (ans1 != ans2) cout << "inf" << endl;
	else cout << ans1 << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cctype>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//template<typename key, typename val>
//using ordered_tree =
//  tree<key, val, std::greater<>, rb_tree_tag, tree_order_statistics_node_update>;
using namespace std;
typedef long long int64;
typedef unsigned long long uint64;
typedef complex<double> comp;
const double pi = 3.14159265358979323846;
const int inf = (int)1e+9 + 2;
const int64 inf64 = (int64)1e+18 + 2;
const double dinf = 1e+20;
const int mod = 1'000'000'007;//*/998244353;
const int base = 2187;
const double eps = 1e-9;
const int N = 300'000;
const int LOGN = 19;

int n, m, k;

map<int64, int64> mp;

int64 f(int64 x) {
  if (x == 1) {
    return 1;
  }
  auto it = mp.find(x);
  if (it != end(mp)) {
    return it->second;
  }
  int64 res = f(x / 2) + f(x / 2) + 1;
  mp.emplace(x, res);
  return res;
}

void solve(int) {
  int64 x;
  cin >> x;
  cout << f(x) << '\n';
}

void precalc() {
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  precalc();
  int test = 1;
  //cin >> test;
  //auto start = chrono::high_resolution_clock::now();
  for (int i = 1; i <= test; ++i) {
    solve(i);
  }
  //cerr << chrono::duration_cast<chrono::milliseconds>(chrono::high_resolution_clock::now() - start).count() << '\n';
  return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
    using namespace std;
     
    #include <ext/pb_ds/assoc_container.hpp> 
    #include <ext/pb_ds/tree_policy.hpp> 
    using namespace __gnu_pbds; 
     
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
     
    int getRand(int l, int r)
    {
        uniform_int_distribution<int> uid(l, r);
        return uid(rng);
    }
      
    #define pb push_back
    #define S second
    #define F first
    #define f(i,n) for(int i=0;i<n;i++)
    #define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
    #define vi vector<int>
    #define pii pair<int,int>
    #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
    #define precise(x) fixed << setprecision(x) 
     
    const int MOD = 1e9+7;
     
    int mod_pow(int a,int b,int M = MOD)
    {
        int res = 1;
        
        while(b)
        {
            if(b&1) res=(res*a)%M;
            a=(a*a)%M;
            b>>=1;
        }
        
        return res;
    }
     
    int n;
     
    void go(int len,int lim,string s)
    {
        if(len == n)
        {
          if(s[len-1] != ('a'+len-1))
            cout << s << '\n';
          else 
            cout << s;
          return;
        }
        
        for(int i=0;i<=min(25,(lim+1));i++)
        {
            string t = s;
            t+=(char)('a'+i);
            go(len+1,max(i,lim),t);
        }
    }
     
    void solve()
    {
       cin >> n;
       string s ="";
       go(0,-1,s); 
        
    }
     
    signed main()
    {
        fast;
        
        int t = 1;
        
    //    cin >> t;
        
        while(t--)
            
        solve();
    }

Measured memory_bytes: 1536
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
	int a,b,i,s=0;
	cin>>a>>b;
	int b_=b;
	if(b!=0)
		while(b_)
		{
			b_=b_/10;
			s++;
		}
	else
		s=1;
	for(i=1;i<=s;i++)
		a=a*10;
	if(sqrt(a+b)==int(sqrt(a+b)))
		cout<<"Yes";
	else
		cout<<"No";
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<queue>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
/************************************************/
#define rep(i,n) for(int i=0;i<n;i++)
#define m_p make_pair
#define pb push_back
#define fr first
#define se second
#define forn(i,a,n) for(int i=a;i<n;i++)
#define foreach(i,c) for(__typeof(c.begin())i=(c.begin());i!=(c).end();i++)
#define pii pair<int,int>
#define vi vector<int>
#define ll long long
#define sz(s) s.size()
#define all(s) s.begin(),s.end()
#define zero(x) memset(x,0,sizeof(x))
#define vii vector<pair<int,int> >
#define mpis map<int,string>
#define mpii map<int,int>
#define mpsi map<string,int>
#define re return
#define mod 1000000007
/************************************************/
using namespace std;

long long get(){
	char c=getchar();
	long long x=0LL;
	while(c<'0'||c>'9')
	c=getchar();
	while(c>='0'&&c<='9'){
		x*=10LL;
		x+=(c-'0');
		c=getchar();
	}
	return x;
}
ll dp[100001],h[100001];
int n;
int main(){
	ios::sync_with_stdio(0);
	cin>>n;
	rep(i,n)
	cin>>h[i];
	dp[0]=0;
	forn(i,1,n){
		dp[i]=dp[i-1]+abs(h[i]-h[i-1]);
		if(i>1)
		dp[i]=min(dp[i],dp[i-2]+abs(h[i]-h[i-2]));
	}
	cout<<dp[n-1];
	re 0;
}


Measured memory_bytes: 1792
/*                        ______
 _______   /\     |``\   |        |  /
    |     /  \    |__/   |____    |/
    |    / _ _\   |  \   |        |\
    |   /      \  |   \  |______  |  \

            Dept. of CSE
        Comilla  University

*/
#include<bits/stdc++.h>
#define pi 2*acos(0.0)
#define ll long long
#define FIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define Node struct node
#define spc " "
#define  E  2.71828182845904523536
#define pb push_back
#define pp pop_back
#define valid(nx,ny) nx>=0 && nx<n && ny>=0 && ny<m
#define ee endl
#define pii pair<int,int>
#define infinity 10000000000000000
#define mod 1000000007
int fx[]={0,0,+1,-1};
int fy[]={+1,-1,0,0};

using namespace std;
///check n=1;
///check corner case;
const int maX=1e5+1;
vector<ll>Graph[maX],cost[maX];
ll visit[maX];
ll x[10];
ll y[10];

int main()
{
    ll a,b;
    cin>>a>>b;
    if(a>12)cout<<b<<endl;
    else if(a>=6 && a<=12)cout<<b/2<<endl;
    else cout<<0<<endl;
return 0;
}


Measured memory_bytes: 4992
#include <bits/stdc++.h>
//#define int long long
using namespace std;

signed main()
{
	//ios::sync_with_stdio(false);
	int n,k;
	cin>>n>>k;
	int val=n/2;
	if(n%2==1) val++;
	if(k<=val) cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
	return 0;
}

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

const int INF = 1e+9;
int d[128][128], t[128][128];

int main() {
	int n, m, q, a, b, cst, tie, r;
	while(cin >> n >> m && (n || m)){
		for(int i = 0; i < m; ++i){
			for(int j = 0; j < m; ++j){
				d[i][j] = INF;
				t[i][j] = INF;
			}
		}
		for(int i = 0; i < n; ++i){
			scanf("%d%d%d%d", &a, &b, &cst, &tie);
			a--; b--;
			d[a][b] = cst; d[b][a] = cst;
			t[a][b] = tie; t[b][a] = tie;
		}
		for(int k = 0; k < m; ++k){
			for(int i = 0; i < m; ++i){
				for(int j = 0; j < m; ++j){
					d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
					t[i][j] = min(t[i][j], t[i][k] + t[k][j]);
				}
			}
		}
		cin >> q;
		for(int i = 0; i < q; ++i){
			scanf("%d%d%d", &a, &b, &r);
			a--; b--;
			if(r == 0){
				printf("%d\n", d[a][b]);
			}
			else{
				printf("%d\n", t[a][b]);
			}
		}
	}
	return 0;
}

Measured memory_bytes: 1320
import sys
import heapq
import math
import fractions
import bisect
import itertools
from collections import Counter
from collections import deque
from operator import itemgetter
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))

a,b=mp()
if b==1:
    print(0)
    exit()
for i in range(1,100):
    if 1+(a-1)*i>=b:
        print(i)
        exit()

Measured memory_bytes: 72712
#include<iostream>
#include<string.h>
#include<vector>
#include<list>
#include<stdio.h>
#include<math.h>
#include<iomanip>
#include<map>
#include<stack>
#include<queue>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) range(i,0,b)
#define debug(x) cout << "debug " << x << endl;
using namespace std;

int solve(int b, int c){
    int d1;
    if(b % c == 0){
        d1 = b / c;
    }else{
        d1 = b / c + 1;
    }
    return d1;
}

int main(){
    int a,b,c,d,e;
    while(cin >> a >> b >> c >> d >> e){
        int d1, d2;
        d1 = solve(b, d);
        d2 = solve(c, e);
        cout << a - max(d1, d2) << endl;
    }
}

Measured memory_bytes: 1164
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define ios ios_base::sync_with_stdio(0) ; cin.tie(0) ; cout.tie(0)
int main()
{
    ios;
    ll n , k ;
    cin >> n >> k ;
    vector<ll > v;
    for(ll i =1 ;i<=n;++i){
            ll x;
    cin >> x;
        v.push_back(x);
    }
    sort(v.begin() , v.end());
    ll p1 = 0 ;
    ll p2 = 0+k-1;
    ll ans = abs(v[p1] - v[p2]);
    for(ll i = k;i<n;++i){
        ll foo = abs(v[i] - v[i-k+1]);
        ans = min(ans , foo);
    }
    cout << ans <<endl;

}


Measured memory_bytes: 1400
#include <cstdio>
#include <algorithm>
#define INF 1000000

int edge[10][10];
int n;
bool isexist[10];

int calc(int city){
	int cost[10];
	std::fill_n(cost, 10, INF);
	cost[city]=0;

	while(true){
		bool update=false;
		for(int i=0;i<10;i++){
			if(!isexist[i]) break;
			for(int j=0;j<10;j++){
				if(!isexist[j]) break;
				if(cost[i]+edge[i][j]<cost[j]){
					cost[j]=cost[i]+edge[i][j];
					update=true;
				}
			}
		}
		if(!update) break;
	}
	int sum=0;
	for(int i=0;i<10;i++){
		if(isexist[i]) sum+=cost[i];
	}
	return sum;
}

void solve(){
	int min_city;
	int min_cost=INF;
	for(int i=0;i<10;i++){
		if(isexist[i]){
			int cost=calc(i);
			if(min_cost>cost){
				min_city=i;
				min_cost=cost;
			}
		}
	}
	std::printf("%d %d\n",min_city,min_cost);
	return;
}

int main(){
	while(std::scanf("%d",&n),n){
		for(int i=0;i<10;i++){
			isexist[i]=false;
			for(int j=0;j<10;j++){
				edge[i][j]=INF;
			}
		}
		for(int i=0;i<n;i++){
			int a,b,c;
			std::scanf("%d %d %d",&a,&b,&c);
			edge[a][b]=c;
			edge[b][a]=c;
			isexist[a]=true;
			isexist[b]=true;
		}
		solve();
	}

	return 0;
}

Measured memory_bytes: 1028
n=int(input())
a=[0]*n
b=[0]*n
for i in range(n):
  x,y=map(int,input().split())
  a[i]=x
  b[i]=y

cur=0
for j in range(n-1,-1,-1):
  if (a[j]+cur)%b[j]!=0:
    cur+=b[j]-(a[j]+cur)%b[j]

print(cur)

Measured memory_bytes: 10868