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

using namespace std;

typedef long long ll;

const ll MOD = 1000000007;
const ll INF = 1LL<<60;
//int INF = numeric_limits<int>::max();

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

ll lcm(ll a, ll b) {
	return a * b / gcd(a, b);
}

int main(int, char**) {
	ll a, b; cin >> a >> b;
	cout << lcm(a, b) << endl;
	return 0;
}

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

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
typedef long double ld;

const int INF = 1e9;
const ld EPS = 1e-8;

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

  int ret = 0;
  for (int m = 1; m <= M; m++) {
    for (int d = 10; d <= D; d++) {
      if ((d / 10 == 1) || (d % 10 == 1)) continue;
      if (m == (d / 10) * (d % 10)) ret++;
    }
  }

  cout << ret << endl;
  return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout << (#x) << " is " << (x) << endl

typedef long long ll;
typedef long double ld;
using namespace std;

const int MOD = 1e9 + 7;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int maxi = 0;
    int n;
    cin >> n;
    vector<int> l(n);
    for(int i = 0; i < n; i++)
    {
        cin >> l[i];
        maxi = max(maxi, l[i]);
    }
    if(accumulate(l.begin(), l.end(), 0) > 2 * maxi)
    {
        cout << "Yes";
    }
    else
    {
        cout << "No";
    }

    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
  while(true){
    int n, x, sum = 0;
    cin >> n >> x;
    if(n == 0 && x == 0)break;
    for(int i = 1; i <= n; i++){
      for(int j = 1; j <= n; j++){
        for(int k = 1; k <= n; k++){
          if(i + j + k == x && i < j && j < k) sum++;
        }
      }
    }
    cout << sum << endl;
  }
}



Measured memory_bytes: 3072
main :: IO()
main = do
  ws <-  getLine :: IO String
  print . head . foldl rpn [] $ words ws

rpn :: [Int] -> String -> [Int]
rpn (x:y:zs) "+" = (x + y):zs
rpn (x:y:zs) "-" = (y - x):zs
rpn (x:y:zs) "*" = (x * y):zs
rpn acc w = (read w):acc



Measured memory_bytes: 4108
#include <iostream>
#include <vector>

using namespace std;

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

int main()
{
  int n,b;
  cin >> n;
  vector<int> a;

  REP(i,n){
    cin >> b;
    a.push_back(b);
  }

  int min=2100000000,max=0;

  REP(i,n){
    if(min>a[i])min=a[i];
    if(max<a[i])max=a[i];
  }

  cout << max-min << endl;

  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	char a[4];
	int s=0;
	for(int i=0;i<4;i++)
	{
		cin>>a[i];
		if(a[i]=='+') s++;
		else s--;
	}
	cout<<s;
	return 0;
}

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

int main() {
  int a[3][3], n;

  for(int i = 0; i < 3; i++){
    for(int j = 0; j < 3; j++){
      cin >> a[i][j];
    }
  }
  cin >> n;
  int b[n];

  for(int i = 0; i < n; i++){
    cin >> b[i];

    for(int k = 0; k < 3; k++){
      for(int j = 0; j < 3; j++){
        if(b[i] == a[k][j]){
          a[k][j] = 0;
        }
      }
    }
  }

  for(int i = 0; i < 3; i++){
    if(a[i][0] == a[i][1] && a[i][1] == a[i][2]){
      cout << "Yes" << endl;
      return 0;
    }
    else if(a[0][i] == a[1][i] && a[1][i] == a[2][i]){
      cout << "Yes" << endl;
      return 0;
    }
  }

  if(a[0][0] == a[1][1] && a[1][1] == a[2][2]){
    cout << "Yes" << endl;
    return 0;
  }
  else if(a[0][2] == a[1][1] && a[1][1] == a[2][0]){
    cout << "Yes" << endl;
    return 0;
  }

  cout << "No" << endl;

  return 0;

}


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<map>
#include<string.h>
#include<complex>
#include<math.h>
#include<queue>
#include <functional>
#include<time.h>
#include <stack>
#include<iomanip>
using namespace std;
#define rep(i,a,n) for(int i=(a);i<(n);i++)
#define ll long long
#define llint long long int
#define sort(s) sort(s.begin(),s.end())
#define reverse(v)  reverse(v.begin(), v.end());
#define Yes(ans) if(ans)cout<<"Yes"<<endl; else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl; else cout<<"NO"<<endl;
#define hei(a) vector<a>
#define whei(a) vector<vector<a>>
#define UF  UnionFind 
#define Pint pair<int,int>
#define Pll pair<llint,llint>
#define keta(a)  fixed << setprecision(a)
constexpr auto INF = 1000000000000000000;
constexpr auto mod = 1000000007;
//辞書順はnext_permutation( begin( v ), end( v ) );やで！
struct edge { int to, cost; };

ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0)return a;
	return gcd(b, a % b);
}

long long modpow(long long a, long long n, long long mod) {
	long long res = 1;
	while (n > 0) {
		if (n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}

// mod. m での a の逆元 a^{-1} を計算するよ！
long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}


//aCbをmod.mで割った余りを求める
int c(int a, int b, int m) {
	int ans = 1;
	for (int i = 0; i < b; i++) {
		ans *= a - i;
		ans %= m;
	}
	for (int i = 1; i <= b; i++) {
		ans *= modinv(i, m);
		ans %= m;
	}
	return ans;
}
struct UnionFind {
	vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

	UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
		for (int i = 0; i < N; i++) par[i] = i;
	}
	int size(int a) {
		return par[root(a)];
	}

	int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
		if (par[x] == x) return x;
		return par[x] = root(par[x]);
	}

	void unite(int x, int y) { // xとyの木を併合
		int rx = root(x); //xの根をrx
		int ry = root(y); //yの根をry
		if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
		par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
	}

	bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
		int rx = root(x);
		int ry = root(y);
		return rx == ry;
	}
};

int b_s(vector<int>& a, int key) {
	int left = -1;
	int right = a.size();
	while (right - left > 1) {
		int mid = left + (right - left) / 2;
		if (a[mid] >= key)right = mid;
		else left = mid;
	}
	return left;
}

int main() {
	int a;
	cin >> a;
	int ans = 0;
	rep(i, 0, a) {
		int s;
		cin >> s;
		if (i % 2 == 0 && s % 2 == 1)ans++;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3584
#include<iostream>
using namespace std;
int main(){
  int n;
  cin>>n;
  int ok=0;
  int k;
  
  for(int i=1;i<50000;i++){
    if(int(i*1.08)==n){
      ok=1;
      k=i;
      break;
    }
  }
  if(ok==1)cout<<k<<endl;
  else cout<<":("<<endl;
  
 return 0; 
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll=long long;
using Graph = vector<vector<int>>;
using P = pair<int,int>;
const int MOD=(int)1e9+7;
const int INF=(int)1e9;
const ll LINF=(ll)1e18;


int main(){
    int n;cin>>n;
    vector<int> h(n+2,INF);
    rep(i,n) cin>>h[i];
    vector<int> dp(n+10,INF);
    dp[0] = 0;
    rep(i,n){
        dp[i+1] = min(dp[i+1],dp[i] + abs(h[i] - h[i+1]));
        dp[i+2] = min(dp[i+2],dp[i] + abs(h[i] - h[i+2]));
    }
    cout << dp[n-1] << endl;
}

Measured memory_bytes: 1024
import heapq


def main():
    n, m = map(int, input().split())
    a_list = list(map(lambda x: -int(x), input().split()))

    heapq.heapify(a_list)
    for _ in range(m):
        a = heapq.heappop(a_list)
        heapq.heappush(a_list, -(-a // 2))

    print(-sum(a_list))


if __name__ == '__main__':
    main()


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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
//const ull mod = 1e9 + 7;
const ll mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

// debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}
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; }

// conversion number to bit
string num2bit(ll num, ll len){
  string bit = "";
  REP(i, len){
    bit += char('0'+(num>>i & 1));
  }
  return bit;
}

ll dp[1010][20202];
const ll INF = (1ll<<60);

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

    ll H, N;
    cin >> H >> N;
    vector<ll> A(N), B(N);
    REP(i, N){
    	cin >> A[i] >> B[i];
    }

    REP(i, 1010)REP(j, 20202) dp[i][j] = INF;
    REP(i, 20202) dp[0][0] = 0;

    REP(i, N){
    	REP(j, 20202){
    		if(j<A[i]){
    			dp[i+1][j] = min(dp[i][j], dp[i+1][j]);
    		}else{
    			dp[i+1][j] = min(dp[i][j], dp[i+1][j-A[i]]+B[i]);
    		}
    	}
    }

	ll res = INF;    
    REP(i, 20202){
    	if(i>=H){
    		chmin(res, dp[N][i]);
    	}
    }

    cout << res << endl;
    

    /*
    REP(i, N+1){
    	REP(j, 20){
    		cout << (dp[i][j] <= INF/2 ? dp[i][j] : -1) << " ";
    	}
    	cout << endl;
    }
    */
    
    return 0;
}

Measured memory_bytes: 159744
import sys
def 解():
    L,N=[int(_) for _ in input().split()]
    aX=[int(_) for _ in sys.stdin.readlines()]
    iMax = max(aX[0],L-aX[0],aX[-1],L-aX[-1])
    accX = [0]*(N+1)
    accX[0]=aX[0]
    for i in range(1,N):
        accX[i]=accX[i-1]+aX[i]

    if 1 < N:
        for i in range(N-1):

            lN = min(i,N-i-1)
            rN = min(i+1,N-i-1)
            #R1 = aX[i]+ 2*sum(aX[i-lN:i]) + 2*(rN*L-(sum(aX[i+1:i+rN+1])))
            R1 = aX[i]+ 2*(accX[i-1]-accX[i-lN-1]) + 2*(rN*L-(accX[i+rN]-accX[i]))

            i += 1
            lN = min(i,N-i)
            rN = min(i,N-i-1)
            #R2 = (L- aX[i])+ 2*sum(aX[i-lN:i]) + 2*(rN*L-(sum(aX[i+1:i+rN+1])))
            R2 = (L- aX[i])+ 2*(accX[i-1]-accX[i-lN-1]) + 2*(rN*L-(accX[i+rN]-accX[i]))

            iMax = max(R1,R2,iMax)
    print(iMax)
解()


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

#define all(x) (x).begin(),(x).end()
#define pb push_back
#define pf push_front
#define sz(x) (int)(x).size()
#define lb lower_bound 
#define ub upper_bound 
#define mp make_pair
#define fi first
#define se second
#define setbits(x) __builtin_popcount(x)
#define zerobits(x) __builtin_ctz(x)
#define setbitsll(x) __builtin_popcountll(x)
#define zerobitsll(x) __builtin_ctzll(x)
#define inf 1e18
#define ps(x,y) fixed<<setprecision(y)<<x

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)
#define trav(a,x) for (auto& a: x)

typedef vector<int> vi;
typedef long long ll;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef vector<string> vs;
typedef unsigned long long ull;
typedef long double ld;
typedef map<int,int> mii;

const int MOD = 1e9+7;
const ld PI = acos((ld)-1);
const int maxN = 3005;
int grid[maxN][maxN];
ll dp[maxN][maxN][4];
int n,m;

ll f (int r,int c,int rowCnt) {
	if (r <= 0 || c <= 0 || r > n || c > m) return 0;
	if (rowCnt >= 3) return 0; 
	ll & ret = dp[r][c][rowCnt];
	if (ret != -1) {
		return ret;
	}
	ll op1 = grid[r][c]+f(r+1,c,0);
	ll op2 = grid[r][c]+f(r,c+1,rowCnt+1);
	ll op3 = f(r,c+1,rowCnt);
	ret = max(op1,max(op2,op3));
	return ret;
}

void solve () {
	memset(dp,-1,sizeof(dp));
	cin >> n >> m;
	int k;
	cin >> k;
	for (int i = 0;i < k;++i) {
		int row,col,val;
		cin >> row >> col >> val;
		grid[row][col] = val;
	}
	ll ans = f(1,1,0);
	cout << ans << '\n';
}

int main () {
#ifndef ONLINE_JUDGE
	freopen("input1.txt","r",stdin);
	freopen("output1.txt","w",stdout);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	solve();
	return 0;
}



Measured memory_bytes: 321336
#include<bits/stdc++.h>
using namespace std;
#define		pb              push_back
#define		PB              pop_back
#define		nn              "\n"
#define		all(p)          p.begin(),p.end()
#define		zz(v)           v.size()
#define		ss              ' '
#define 	S(a)            scanf("%lld",&a)
#define 	SS(a,b)         scanf("%lld %lld",&a,&b)
#define 	SSS(a,b,c)      scanf("%lld %lld %lld",&a,&b,&c)
#define		gcd(a,b)        __gcd(a,b)
#define		lcm(a,b)        (a*b)/gcd(a,b)
#define		pi              acos(-1.0)
typedef		long long       ll;
typedef		vector<ll>      vll;

int main()
{
    ll a,b,c,i,j,t,k,lie,m,n,o,x,y,z,ar[200010];
    string s1,s2;
    cin>>s1;
    S(lie);
    for(i=0;i<zz(s1);i+=lie){
        s2.pb(s1[i]);
    }
    cout<<s2<<nn;

    return 0;
}



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


#define li          long long int
#define rep(i,to)   for(li i=0;i<((li)(to));i++)
#define repp(i,start,to)    for(li i=(li)(start);i<((li)(to));i++)
#define pb          push_back
#define sz(v)       ((li)(v).size())
#define bgn(v)      ((v).begin())
#define eend(v)     ((v).end())
#define allof(v)    (v).begin(), (v).end()
#define dodp(v,n)       memset(v,(li)n,sizeof(v))
#define bit(n)      (1ll<<(li)(n))
#define mp(a,b)     make_pair(a,b)
#define rin rep(i,n)
#define EPS 1e-12
#define ETOL 1e-8
#define MOD 1000000007
typedef pair<li, li> PI;

#define INF bit(60)

#define DBGP 1


#define idp if(DBGP)
#define F first
#define S second
#define p2(a,b)     idp cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)       idp cout<<a<<"\t"<<b<<"\t"<<c<<endl
#define p4(a,b,c,d)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<endl
#define p5(a,b,c,d,e)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<endl
#define p6(a,b,c,d,e,f)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<endl
#define p7(a,b,c,d,e,f,g)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<endl
#define p8(a,b,c,d,e,f,g,h)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<endl
#define p9(a,b,c,d,e,f,g,h,i)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<endl
#define p10(a,b,c,d,e,f,g,h,i,j)        idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<"\t"<<j<<endl
#define foreach(it,v)   for(__typeof((v).begin()) it=(v).begin(); it!=(v).end(); ++it)
#define p2p(x)      idp p2((x).F, (x).S)
#define dump(x,n)   idp{rep(i,n){cout<<x[i]<<" ";}puts("");}
#define dump2(x,n)  idp{rep(i,n){cout<<"["<<x[i].F<<" , "<<x[i].S<<"] ";}puts("");}
#define dumpi(x)    idp{foreach(it, x){cout<<(*it)<<" ";}puts("");}
#define dumpi2(x)   idp{foreach(it, x){cout<<"["<<(it)->F<<" , "<<(it)->S<<"] ";}puts("");}

#define read2d(a,w,h)   rep(i,h)rep(j,w)cin>>a[i][j]
#define dump2d(a,w,h)   rep(i,h){rep(j,w)cout<<a[i][j]<<" ";puts("");}

typedef pair<li, li> PI;

li n;
li a[200200];

int main() {
    cin >> n;
    rin{
        cin >> a[i];
    }
    vector<li> last(n + 1, -1);
    rin{
        auto it = partition_point(allof(last), [&](li x) {
            return x >= a[i];
        });
        last[it - last.begin()] = a[i];
    }

    rep(i, n + 1) {
        if (last[i] < 0) {
            cout << i << endl;
            return 0;
        }
    }


    return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <string>
#define llint long long

using namespace std;

llint a, b, k;

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> a >> b >> k;
	
	if(k <= a) a -= k;
	else if(k <= a+b) b -= k-a, a = 0;
	else a = b = 0;
	cout << a << " "<< b << endl;
	
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
using P = pair<ll, ll>;
using V = vector<ll>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep1(i, n) for(ll i=1;i<=(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define MOD 1000000007
#define INF 1000000000

vector<bool> dp;

void solve_abc_d() {
	ll n, m;
	//ll a, b;
	//ll x, y;
	ll k;
	ll l_ans = 0;

	cin >> n;
	V a(n);
	ll am = 0;
	rep(i, n) {
		cin >> a[i];
		am = max(am, a[i]);
	}

	sort(ALL(a));
	dp = vector<bool>(am + 1);
	dp[0] = true;

	ll now;
	ll old = -1;
	rep(i, n) {
		now = a[i];
		if (now != old) {
			while (now < dp.size()) {
				now += a[i];
				if (now < dp.size()) {
					dp[now] = true;
				}
			}
		}
		else {
			dp[now] = true;
		}
		old = a[i];
	}

	rep(i, n) {
		if (!dp[a[i]]) {
			l_ans++;
		}
	}

	cout << l_ans << "\n";
	return;
}

int main(void) {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed;
	cout << setprecision(7);

	solve_abc_d();

	return 0;
}


Measured memory_bytes: 4924
# 10のp乗の桁のmod 13
def coefficient(p):
    a = p % 6
    if a == 0:
        return 1
    if a == 1:
        return 10
    if a == 2:
        return 9
    if a == 3:
        return 12
    if a == 4:
        return 3
    if a == 5:
        return 4


def submit():
    s = input()
    clist = [c for c in s]
    n = len(clist)
    ansmod = 10 ** 9 + 7

    # dp[x][y] : 上位x桁まで見たときに、y mod 13になるパターン数
    dp = [
        [0 for _ in range(13)] for _ in range(n + 1)
    ]

    dp[0][0] = 1

    for i, c in enumerate(clist):
        if c == '?':
            for x in range(10):
                for y in range(13):
                    dig_mod = y
                    dig_mod += coefficient(n - i - 1) * x
                    dig_mod %= 13
                    dp[i + 1][dig_mod] += dp[i][y]
                    dp[i + 1][dig_mod] %= ansmod
        else:
            x = int(c)
            for y in range(13):
                dig_mod = y
                dig_mod += coefficient(n - i - 1) * x
                dig_mod %= 13
                dp[i + 1][dig_mod] += dp[i][y]
                dp[i + 1][dig_mod] %= ansmod

    print(dp[n][5] % ansmod)


if __name__ == '__main__':
    submit()

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

const int C=1000000007;

int n,m,ans=1;

int main()
{
	cin>>n>>m;
	if(abs(n-m)>=2)
	{
		cout<<0;
		return 0;
	}
	for(int i=1;i<=n;i++)
		ans=1ll*ans*i%C;
	for(int i=1;i<=m;i++)
		ans=1ll*ans*i%C;
	ans=1ll*ans*(2-abs(n-m))%C;
	cout<<ans;
	return 0;
}

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

using namespace std;

typedef pair<int, int> II;
typedef pair<long long, int> LLI;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<II> VII;

#define For(i,a,b) for(int i = a;i <= b; i++)
#define Rep(i,a,b) for(int i = a;i >= b; i--)
#define REP(i, n) for(int i = 0; i < n; i++)
#define FOR(i, f) for(auto i : f)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define BUG(x) (cerr << #x << " = " << x << "\n")
#define ARRAY(f) {cerr << #f << " = "; FOR(i, f) cout << i << ' '; cout << "\n";}
#define sz(s) int(s.size())
#define reset(f, x) memset(f, x, sizeof(f))
#define all(x) x.begin(), x.end()
#define two(x) (1LL << x)
#define getbit(x, i) ((x >> (i)) & 1LL)
#define onbit(x, i) (x | (1LL << (i)))
#define offbit(x, i) (x & ~(1 << (i)))

const int N = 100 + 1;
int n, a[N];

int main() {
    ios_base::sync_with_stdio(false);
    srand(time(NULL));
    #ifndef ONLINE_JUDGE
        //freopen("in.txt","r",stdin);
        //freopen("","w",stdout);
    #endif
    cin >> n;
    For(i, 1, n) cin >> a[i];
    int res = 0;
    For(i, 2, n) if (a[i] == a[i-1]) {
    	res++;
    	a[i] = 0;
    }
    cout << res;
}




Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
	int a;
	int b;
	int c;

	scanf("%d",&a);
	scanf("%d",&b);
	scanf("%d",&c);
		
	if(a < b){
		if(b < c){
			printf("Yes\n");
		}else{            
			printf("No\n");
		}
	}else{            
			printf("No\n");
	}
	return 0;
}

Measured memory_bytes: 580
n = int(input())

a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())

location = [n, 0, 0, 0, 0, 0]
cap = [a, b, c, d, e]


min_cap = min(cap)
if min_cap >= n:
	print(5)

else:
	total = int((n-1)/min_cap) + 5
	print (total)



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

int main() {
  int64_t N;
  cin >> N;
  
  int64_t Y, X = 100;
  int cnt = 0;
  
  while(X <= 1000000000000000000){
    if(X >= N){
      break;
    }
    cnt++;
      Y = X / 100;
      X += Y;
  }
  
  cout << cnt << endl;
  
  return 0;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define l_ength size
const int inf = (1<<30);
const int mod = 1000000007; // 998244353
using ll = long long;
using namespace std;

int main(){
	ll n, m; cin >> n >> m;
	vector<ll> a(m);
	for( auto &k : a ) cin >> k;
	ll sum = accumulate( a.begin(), a.end(), 0ll );
	if( sum > n ) cout << -1 << endl;
	else cout << n-sum << endl;
}

Measured memory_bytes: 3680
#include<iostream>
#include<stdlib.h>
using namespace std;

struct node{
  int key;
  struct node *p;
  struct node *l;
  struct node *r;
};

typedef struct node *pointer;

node s;
pointer nil=&s;
pointer R=nil;


void insert(pointer z){
  pointer y=nil;
  pointer x=R;
  while(x!=nil){
    y=x;
    if(z->key < x->key)x=x->l;
    else x=x->r;
  }
  z->p=y;
  if(y==nil) R = z;
  else if(z->key < y->key) y->l= z;
  else y->r=z;
}


void print(pointer t,int pp){
  if(t==nil) return;
  if(pp)cout<<" "<<t->key;
  print(t->l,pp);
  if(!pp)cout<<" "<<t->key;
  print(t->r,pp);
}


int main(){
  int n;
  cin>>n;
  string str;
  for(int i=0;i<n;i++){
    cin>>str;
    if(str=="insert"){
      pointer   T=(pointer)malloc(sizeof(node));
      cin>>T->key;
      T->l=nil;
      T->r=nil;
      insert(T);
    }
    else if(str=="print"){
      print(R,0);
      cout<<endl;
      print(R,1);
      cout<<endl;
    }
  }
  



  return 0;
}

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

int main(){
	int ar[4];
	int ara[2];
	
	cin>>ar[0]>>ar[1]>>ar[2]>>ar[3]>>ara[1]>>ara[0];
	sort(ar,ar+4);
	sort(ara,ara+2);
	cout<<ar[1]+ar[2]+ar[3]+ara[1]<<endl;
	
	return 0;
	}

Measured memory_bytes: 3144
fn main() {
    let nums: Vec<i32> = read_vec();

    let result = 15 - (nums.iter().sum::<i32>());

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

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

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


Measured memory_bytes: 2000
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <cmath>
#include <vector>
#include <numeric>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <tuple>

using ll = long long int;
using ul = unsigned long long int;
const ll LL_MAX (1LL<<60);
const ll MOD (1000000007);

#define rep(i,s,e) for(ll i=(s); i<(e); i++) 

using namespace std;

using Graph = vector<vector<ll>>;

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

    ll N, M;
    cin >> N >> M;
    vector<ll> h(N);
    rep(n,0,N) cin >> h[n];

    Graph g(N);

    rep(m,0,M)
    {
        ll from, to;
        cin >> from >> to;
        --from, --to;
        g[from].emplace_back(to);
        g[to].emplace_back(from);
    }

    //for (auto l: g)
    //{
    //    for (auto i: l)
    //        cout << " " << i;
    //    cout << endl;
    //}
        
    ll ans(0);
    rep(n,0,N)
    {
        bool tmp(true);
        for (auto i: g[n])
            tmp &= h[i]<h[n];
        if (tmp)
            ++ans;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 9800
#include <algorithm>
#include <bits/stdc++.h>
#include <cmath>
#include <limits>

#define ll long long
#define pi (acos(-1))
#define rep(i, n) for (unsigned long long i = 0; i < (unsigned long long)(n); ++i)
using namespace std;
std::vector<unsigned ll> genprimevec(const unsigned ll N);
int main()
{

    int a, b, m;
    cin >> a >> b >> m;
    vector<int> x(a), y(b);
    vector<pair<pair<int, int>, int>> z;
    ll ans = 1001001000;
    rep(i, a) { cin >> x[i]; }
    rep(i, b) { cin >> y[i]; }
    int q, w, e;
    rep(i, m)
    {
        cin >> q >> w >> e;
        z.push_back(pair<pair<int, int>, int>(pair<int, int>(q,w),e));
#ifdef dbg
	cout<<"dbg z:"<<z[i].first.first<<' '<<z[i].first.second
		<<' '<<z[i].second<<endl;
#endif
    }

    ll tmp;
    rep(i, m)
    {
        tmp = x[z[i].first.first - 1] + y[z[i].first.second - 1] - z[i].second;
#ifdef dbg
	cout<<"tmp "<<tmp<<endl;
#endif
        ans = min(tmp, ans);
    }
 sort(x.begin(),x.end());
sort(y.begin(),y.end())
	;tmp=x[0]+y[0];
ans=min(ans,tmp);
    cout << ans << endl;
    return 0;
}

/*author  https://qiita.com/drken/items/0c88a37eec520f82b788*/
ll extgcd(ll a, ll b, ll &x, ll &y)
{
    if (b == 0)
    {
        x = 1, y = 0;
        return a;
    }
    ll d = extgcd(b, a % b, y, x);
    y -= a / b * x;
    return d;
}


std::vector<unsigned ll> genprimevec(const unsigned ll N)
{
    std::vector<bool> is_prime(N + 1);
    for (unsigned ll i = 0; i <= N; i++) { is_prime[i] = true; }
    std::vector<unsigned ll> P;
    for (unsigned ll i = 2; i <= N; i++)
    {
        if (is_prime[i])
        {
            for (unsigned ll j = 2 * i; j <= N; j += i) { is_prime[j] = false; }
            P.emplace_back(i);
        }
    }
    return P;
}


Measured memory_bytes: 5744
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
    int n;
    string s;
    cin >> n >> s;

    vector<int> a(n + 1);
    for (int i = 0; i < n; i++) {
        a[i + 1] = a[i];
        if (s[i] != '.')a[i + 1]++;
    }
    vector<int> b(n + 1);
    for (int i = n - 1; i >= 0; i--) {
        b[i] = b[i + 1];
        if (s[i] != '#')b[i]++;
    }

    int ret = 1145141919;
    for (int i = 0; i <= n; i++) {
        ret = min(ret, a[i] + b[i]);
    }

    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 2180
import java.util.Scanner;

public class Main {

public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while(true){
        int H = sc.nextInt();
        int W = sc.nextInt();
        if ( H < 3 ) break;
        for ( int i = 0; i < H; i++ ){
        	 if(i==0 || i==H-1){
            for ( int j = 0; j < W; j++ ){
               
                    System.out.print("#");
                    
                }
        	 }
            else{
            	for ( int j = 0; j < W; j++ ){
            		if(j==0 || j==W-1){
            			System.out.print("#");
            		}
            		else{
            			System.out.print(".");
            		}
            }
            }
            System.out.println("");
        }
        System.out.println();
    }
}
}


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

using namespace std;

#define pb push_back
#define ff first
#define ss second
#define sz(x) (int)x.size()
#define all(x) (x).begin(),(x).end()
#define F(i,x,n,y) for(i=x;i<n;i+=y)
#define fi(i,x,n) for(i=x;i<n;++i)
#define f(n) for(int i=0;i<n;++i)
#define fr(i,x,n) for(i=x;i>=n;--i)
#define endl '\n'

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

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    vi v;
    int x;
    cin>>x;
    v.pb(x);
    cin>>x;
    v.pb(x);
    cin>>x;
    v.pb(x);
    sort(all(v));
    cout<<v[0]+v[1]<<endl;

    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define vll vector<ll>
#define vvll vector<vll>
#define mll map<ll,ll>
#define f(i,m,n) for(i=m;i<n;i++)
#define ee endl
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define take(v,n) for(i=0;i<n;i++) cin>>v[i];
#define NO() cout<<"IMPOSSIBLE"<<endl
#define YES() cout<<"Yes"<<endl
#define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define sot(v) sort(v.begin(),v.end());
ll mod =1000000007;  
bool isPrime(int n) 
{ 
    // Corner cases 
    if (n <= 1)  return false; 
    if (n <= 3)  return true; 
  
    // This is checked so that we can skip  
    // middle five numbers in below loop 
    if (n%2 == 0 || n%3 == 0) return false; 
  
    for (int i=5; i*i<=n; i=i+6) 
        if (n%i == 0 || n%(i+2) == 0) 
           return false; 
  
    return true; 
}

ll powe(ll x, ll y){
    ll res = 1;
    while (y > 0){
        if (y & 1) res = (res*x)%mod;
        y = y>>1;
        x = (x*x)%mod;
    }
    return res;
}

void solve()
{
    ll i,j,n,k,m,w,q;
    cin>>n;
    vll v(n);
    take(v,n);
    ll ans=0;
    ll sum=0;
    for(i=0;i<n;i++)
    {
        ans=(ans+((sum)*v[i])%mod)%mod;
        sum=(sum+v[i])%mod;
    }
    cout<<ans<<ee;
}
int main() {
    fast;
    ll i,j,l,k,t,n;
    t=1;
    for(i=1;i<=t;i++)
    {
        // cout<<"Case #"<<i<<": ";
        solve();
    }
}

Measured memory_bytes: 4704
import fractions
from collections import deque
import numbers as np
import math


def main():
    N, D = map(int, input().split())
    tmp = 0
    cnt = 0
    while tmp < N:
        tmp += 2*D + 1
        cnt += 1

    print(cnt)


if __name__ == "__main__":
    main()


Measured memory_bytes: 5048
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define rush() int T;scanf("%d",&T);while(T--)
#define mm(a,b) memset(a,b,sizeof(a))
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define sc(a) scanf("%d",&a)
#define sc2(a,b) scanf("%d%d",&a,&b)
#define pf(a) printf("%d\n",a)
#define pf2(a,b) printf("%d %d\n",a,b)
#define p_f(a) printf("%d ",a)
#define fi first
#define se second
#define db double
#define ll long long
using namespace std;
const int inf=0x3f3f3f3f;
const ll INF=0x3f3f3f3f3f3f3f3f;
const db eps=1e-9;
int a,b,c;
int main()
{
	cin>>a>>b>>c;
	if(a+b+c>=22)puts("bust");
	else puts("win");
    return 0;
}


Measured memory_bytes: 256
N = int(input())
a = list(map(int, input().split())) 

import fractions

#最小公倍数
ans = a[0]
for i in range(1, N):
    ans = ans * a[i] // fractions.gcd(ans, a[i])

mn = 0

for i in a:
    mn += (ans-1) % i

print(mn)

Measured memory_bytes: 5176
package main

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

func main() {
	fmt.Printf("%d\n", resolve(parseProblem(os.Stdin)))
}

func parseProblem(r io.Reader) ([][]int, []int, int) {
	const (
		initialBufSize = 100000
		maxBufSize     = 1000000
	)
	buf := make([]byte, initialBufSize)

	sc := bufio.NewScanner(r)
	sc.Buffer(buf, maxBufSize)
	sc.Split(bufio.ScanWords) // bufio.ScanLines
	n, m, c := scanInt(sc), scanInt(sc), scanInt(sc)
	b := nextMatrix(1, m, sc)
	mx := nextMatrix(n, m, sc)
	return mx, b[0], c
}

func nextMatrix(n, m int, sc *bufio.Scanner) (matrix [][]int) {
	matrix = make([][]int, n)
	for i := 0; i < n; i++ {
		matrix[i] = make([]int, m)
		for j := 0; j < m; j++ {
			matrix[i][j] = nextInt(sc)
		}
	}
	return
}

func nextInt(sc *bufio.Scanner) int {
	sc.Scan()
	a, _ := strconv.Atoi(sc.Text())
	return int(a)
}

func nextString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}

func resolve(mx [][]int, b []int, c int) (num int) {
	for i := 0; i < len(mx); i++ {
		if mul(i, mx, b)+c > 0 {
			num++
		}
	}
	return num
}

func mul(i int, mx [][]int, v []int) int {
	sum := 0
	for j := 0; j < len(mx[i]); j++ {
		sum += mx[i][j] * v[j]
	}
	return sum
}

// snip-scan-funcs
func scanInt(sc *bufio.Scanner) int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return int(i)
}
func scanString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}


Measured memory_bytes: 640
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <iostream>
#include <stdlib.h>
#include <string.h>
using namespace std;

bool findCycle(int **Edges, int numEdge, int numVert)
{
	int *nums = (int*)malloc(sizeof(int) * numVert);
	memset(nums, 0, sizeof(int) * numVert);
	bool flag = false;

	int remainNumVert = numVert;
	while(remainNumVert > 0)
	{
		flag = false;
		for(int j = 0; j < numEdge; j++)
		{
			if(nums[Edges[j][0]] != -1)
				nums[Edges[j][1]] = 1;
		}
		int k;
		for(k = 0; k < numVert; k++)
		{
			//cout<<nums[0]<<" "<<nums[1]<<" "<<nums[2]<<" "<<nums[3]<<" "<<nums[4]<<"aaaa"<<endl;
			if(nums[k] == 0)
			{//cout<<"asdf\n";
				nums[k] = -1;   //ys: means this node has been deleted;
				remainNumVert--;
				flag = true;
			}
			else if(nums[k] == 1)
				nums[k] = 0;
			//cout<<nums[0]<<" "<<nums[1]<<" "<<nums[2]<<" "<<nums[3]<<" "<<nums[4]<<"a+a+a+"<<endl;
		}
		//cout<<"555\n";
		if(!flag)
			return 1;

	}
	return 0;
}

int main()
{
	int numVert,numEdge;
	
	cin>>numVert>>numEdge;

	int **Edges = (int**)malloc(sizeof(int*) * numEdge);
	Edges[0] = (int*)malloc(sizeof(int) * numEdge * 2);
	for(int i = 0; i < numEdge; i++)
	{
		Edges[i] = &Edges[0][i*2];
		cin>>Edges[i][0]>>Edges[i][1];
	}

	cout<<findCycle(Edges, numEdge, numVert)<<endl;
	return 0;
}

Measured memory_bytes: 1216
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int k = scanner.nextInt();
        int[] p = new int[n];
        for (int i = 0; i < n; i++) {
            p[i] = scanner.nextInt();
        }
        System.out.println(maxMathExpectation(p,k));
    }

    public static float maxMathExpectation(int[] p, int k){
        int tmp = 0;
        for (int i = 0; i < k; i++) {
            tmp+=p[i];
        }
        int max = tmp;
        for (int i = k; i < p.length; i++) {
            tmp+=p[i]-p[i-k];
            max = Math.max(max, tmp);
        }
        return (max+k)/2.0f;
    }
}

Measured memory_bytes: 79468
#include<bits/stdc++.h>
using namespace std;
#define MAX 100000
int n;
vector<pair<int, int>> adj[MAX+1];
string color[MAX+1];

void dfs(int u){
  for ( int i = 0; i < adj[u].size(); i++){
    pair<int, int> p = adj[u][i];
    if ( color[p.first] != "non" )continue;
    if ( p.second % 2 == 0){
      color[p.first] = color[u];
    } else {
      color[p.first] = color[u] == "white" ? "black":"white";
    }
    dfs(p.first);
  }
  return;
}

int main(){
  cin >> n;
  int u, v, w;
  for ( int i = 0; i < n-1; i++){
    cin >> u >> v >> w;
    adj[u].push_back(make_pair(v, w));
    adj[v].push_back(make_pair(u, w));
  }

  for ( int i = 1; i <= n; i++){
    color[i] = "non";
  }
  color[1] = "white";
  dfs(1);

  for ( int i = 1; i <= n; i++){
    if ( color[i] == "white"){
      cout << 0 << endl;
    } else {
      cout << 1 << endl;
    }
  }

  return 0;
}

Measured memory_bytes: 14720
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main(){
	int N,M;
	cin >> N >> M;
	vector<int> homework(N);
for(int j = 0 ;j < M ; j++){
		cin >>homework.at(j);
	}
for(int i = 0 ;i < M ; i++){
N = N - homework.at(i);
}
	if(N >= 0){
cout << N;
}
if(N < 0){
cout << "-1";
}
return 0;
}

Measured memory_bytes: 7160
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Scanner;

public class Main 
{
	static class Node
	{
		HashSet<Node> e = new HashSet<>();
		int i;
		int dis1 = -1;
		int dis2 = -1;
		boolean census = false;
		int blacksize = 1;
		
		public Node(int id)
		{
			i=id;
		}
	}
	
	static int cen(Node n)
	{
//		System.out.println("census " + n.i);
		n.census = true;
		int score = 1;
		for(Node e : n.e)
		{
			if(!e.census)
			{
				e.census = true;
				score += cen(e);
			}
		}
		return score;
	}

	public static void main(String[] args) 
	{
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();

		Node[] nd = new Node[n];
		
		for(int i = 0; i < n; i++)
		{
			nd[i] = new Node(i);
		}
		
		for(int i = 0; i < n-1; i++)
		{
			int a = sc.nextInt()-1;
			int b = sc.nextInt()-1;
			nd[a].e.add(nd[b]);
			nd[b].e.add(nd[a]);
		}
		
		Node s1 = nd[0];
		Node s2 = nd[n-1];
		LinkedList<Node> q = new LinkedList<Node>();
		q.add(s1);
		s1.dis1 = 0;
		while(!q.isEmpty())
		{
			Node pos = q.pollFirst();
			for(Node e : pos.e)
			{
				if(e.dis1 == -1)
				{
					e.dis1 = pos.dis1+1;
					q.add(e);
				}
			}
		}
		
		q = new LinkedList<Node>();
		q.add(s2);
		s2.dis2 = 0;
		while(!q.isEmpty())
		{
			Node pos = q.pollFirst();
			for(Node e : pos.e)
			{
				if(e.dis2 == -1)
				{
					e.dis2 = pos.dis2+1;
					q.add(e);
				}
			}
		}
		
		int path = nd[0].dis2;
		Node fb = null;
		for(int i = 0; i < n; i++)
		{ //find frontline black
			Node x = nd[i];
			if(x.dis1 + x.dis2 == path && x.dis1 == path/2)
			{
				fb = x;
				break;
			}
		}
		
		int blackscore = 1;
		fb.census = true;
//		System.out.println("frontline " + fb.i + ", dis " + fb.dis1 + " " + fb.dis2);
		for(Node e : fb.e)
		{
//			System.out.println(fb.i + " " + e.i);
			if(!(e.dis1 + e.dis2 == path && e.dis2 < fb.dis2))
			{
//				System.out.println("Open census " + e.i + ", dis " + e.dis1 + " " + e.dis2);
				blackscore += cen(e);
			}
		}

		int whitescore = n-blackscore;
//		System.out.println(blackscore + " " + whitescore);
		if(blackscore>whitescore)
			System.out.println("Fennec");
		else System.out.println("Snuke");
	}

}


Measured memory_bytes: 117604
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int mod=1e9+7;
const int N=200050;
int pow(int x, int k)
{
	int ret=1;
	for(;k;k>>=1,x=(ll)x*x%mod) if(k&1) ret=(ll)ret*x%mod;
	return ret;
}
int inv(int x){ return pow(x,mod-2);}
int f[N],F[N],I[N],a[N];
int binom(int n, int k){ return (ll)F[n]*I[k]%mod*I[n-k]%mod;}
int main()
{
	int n,i;
	scanf("%i",&n);
	for(i=1;i<=n;i++) scanf("%i",&a[i]);
	F[0]=1;
	for(i=1;i<=n;i++) F[i]=(ll)F[i-1]*i%mod;
	I[n]=inv(F[n]);
	for(i=n-1;~i;i--) I[i]=(ll)I[i+1]*(i+1)%mod;
	for(i=1;i<n;i++) f[i]=(ll)F[i]*F[n-i-1]%mod*binom(n,i+1)%mod,f[i]=((ll)f[i]+f[i-1])%mod;
	int ans=0;
	for(i=1;i<=n;i++)
	{
		int l=i-1,r=n-i;
		int mul=((ll)f[l]+f[r])%mod;
		mul=((ll)mul+F[n])%mod;
		ans+=(ll)a[i]*mul%mod;
		ans%=mod;
	}
	printf("%i\n",ans);
	return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <vector>
using namespace std;
int main() {
  int w, d, ans, h;
  while (cin >> w >> d, w) {
    ans = 0;
    vector<int> Hw(21,0), Hd(21,0);
    for (int i = 0; i < w; ++i) {
      cin >> h;
      Hw[h]++;
    }
    for (int i = 0; i < d; ++i) {
      cin >> h;
      Hd[h]++;
    }
    for (int i = 0; i < 21; ++i) ans += max(Hw[i],Hd[i])*i;
    cout << ans << endl;
  }
}

Measured memory_bytes: 3080
#include <stdio.h>
#define INF 0x5fffffff
#define BYCOST 0
#define BYTIME 1

int m, n, cost[100][100], time[100][100];
int dijkstra(int, int, int);


int main()
{
	int i, j, a, b, c, t, k, p, q, r;
	while(1) {
		for(i = 0; i < 100; i++) {
			for(j = 0; j < 100; j++) {
				cost[i][j] = INF;
				time[i][j] = INF;
			}
		}
		scanf("%d %d", &n, &m);
		if(!n && !m) break;
		for(i = 0; i < n; i++) {
			scanf("%d %d %d %d", &a, &b, &c, &t);
			cost[a - 1][b - 1] = c;
			cost[b - 1][a - 1] = c;
			time[a - 1][b - 1] = t;
			time[b - 1][a - 1] = t;
		}
		scanf("%d", &k);
		for(i = 0; i < k; i++) {
			scanf("%d %d %d", &p, &q, &r);
			printf("%d\n", dijkstra(p - 1, q - 1, r));
		}
	}
	return 0;
}
int dijkstra(int start, int goal, int type)
{
	int i, used[100] = {}, d[100], minst;
	for(i = 0; i < 100; i++) d[i] = INF;
	d[start] = 0;
	while(1) {
		minst = -1;
		for(i = 0; i < m; i++) {
			if(!used[i] && (minst == -1 || d[i] < d[minst])) minst = i;
		}
		if(minst == -1) break;
		used[minst] = 1;
		switch(type) {
			case BYCOST:
				for(i = 0; i < m; i++) {
					if(d[i] > d[minst] + cost[minst][i]) d[i] = d[minst] + cost[minst][i];
				}
				break;
			case BYTIME:
				for(i = 0; i < m; i++) {
					if(d[i] > d[minst] + time[minst][i]) d[i] = d[minst] + time[minst][i];
				}
				break;
			default:
				break;
		}
	}
	return d[goal];
}

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

int main() {
  int N, K, X, Y, ans = 0;
  cin >> N >> K >> X >> Y;
  if (N>K) {
    ans += (N-K)*Y;
    N = K;
  }
  ans += N*X;
  cout << ans << endl;
  return 0;
}

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

using namespace std;

#define inf 1<<30
#define llong long long
#define usd unsigned
#define pqueue priority_queue
#define mp make_pair
#define pb push_back
#define fn fill_n
typedef pair<int, int> P;
int nw[9] = {0, 1, 0, -1, -1, 1, 1, -1, 0};
int nh[9] = {1, 0, -1, 0, 1, 1, -1, -1, 0};




int main(){
	string s;
	int n;
	map<string, int> m;
	pqueue<string> q;
	cin >> s >> n;
	for(int i = 0; i < s.size(); i++){
		for(int j = 1; j <= s.size()-i; j++){
			string in = s.substr(i, j);
			if(m[in]) continue;
			if(q.size() < n) q.push(in);
			else if(q.top() > in) q.push(in);
			else break;

			if(q.size() > n) q.pop();
			m[in]++;
		}
	}

	cout << q.top() << endl;
	return 0;
}

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

int main() {
  int K;
  string S;
  char a;
  cin  >> K>>S;
  if(S.size()<=K){
    cout << S <<endl;
  }
  else{
    string T="";
    for(int i=0; i< K;i++){
      a=S.at(i);
    T.append(1, a); 
    }
    cout <<T<<"..."<<endl;
  }

  return 0;
}


Measured memory_bytes: 3628
#include<stdio.h>
main(){
  int n,a,b,c,d,abcd,sum;
  while(scanf("%d",&n)!=EOF){
    abcd=0;

    for(a=0;a<=9;a++){
      for(b=0;b<=9;b++){
	for(c=0;c<=9;c++){
	  for(d=0;d<=9;d++){
	    sum=n;
	    sum=sum-a-b-c-d;
	    if(sum==0){
	      abcd++;
	    }
	  }
	}
      }
    }

    printf("%d\n",abcd);

  }
  return 0;
}

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

using namespace std;

int main(){
  long long n, k, q;
  cin >> n >> k >> q;
  long win[n];

  for (int i = 0; i < n; i++)
  {
    win[i] = 0;
  }
  

  for (long long i = 0; i < q; i++)
  {
    long winner;
    cin >> winner;
    win[winner-1]++;
  }

  for (int i = 0; i < n; i++)
  {
    if(k - (q - win[i]) <= 0){
      cout << "No" << endl;
    }else{
      cout << "Yes" << endl;
    }
  }
  
  
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(ll i = (a); i < (b); ++i)
#define iter(it,c) for(__typeof((c).begin()) it = (c).begin(); it != (c).end(); ++it)
#define pb push_back
#define fs first
#define sc second
typedef pair<ll,ll> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;

const int INF = ~(1<<31);
const double pi = acos(-1);
const int EPS = 1e-9;

int n, m;
vector<int> A;
vector<int> B;
ll mem[10000][10000];
ll dp(int i, int j){
    if(i == -1 || j == -1){
        return 0;
    }
    if(mem[i][j] != -1) return mem[i][j];
    if(A[i] == B[j]){
        return mem[i][j] = (dp(i-1, j)+dp(i, j-1)+1) % 1000000007;
    }else{
        return mem[i][j] = (dp(i-1, j)+dp(i,j-1)-dp(i-1,j-1)) % 1000000007;
    }
}

int main(){
    cin.sync_with_stdio(false);
    memset(mem, -1, sizeof(mem));
    int x, y;
    cin >> x >> y;
    if(y == 1) cout << 0 << endl;
    else cout << x-y << endl;
    return 0;
}


Measured memory_bytes: 781568
package main

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

var sc = bufio.NewScanner(os.Stdin)

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

func nextInt() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}

func nextFloat64() float64 {
	f, _ := strconv.ParseFloat(next(), 64)
	return f
}

func nextInts(n int) []int {
	slice := make([]int, n)
	for i := 0; i < n; i++ {
		slice[i] = nextInt()
	}
	return slice
}

func main() {
	sc.Split(bufio.ScanWords)
	n := 5
	a := nextInts(n)
	k := nextInt()
	for i := 0; i < n-1; i++ {
		for j := i + 1; j < n; j++ {
			if a[j]-a[i] > k {
				fmt.Println(":(")
				return
			}
		}
	}
	fmt.Println("Yay!")
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int main(void){
   int a,b,c=INT_MAX;
   cin>>a;
   for(int i=0; i<a; i++){
       int d=0;
       cin>>b;
       while(b%2==0){
           d++;
           b=b/2;
       }
       c=min(c,d);
}
cout<<c<<endl;
       return 0;
       }

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#define ll long long

using namespace std ;

ll dp[ 100007 ] ;

int main( void ) {
        int n, w ;
        scanf( "%d %d", &n, &w ) ;
        for( int num = n; num--; ) {
                int wt, val ;
                scanf( "%d %d", &wt, &val ) ;
                for( int i = w ; i >= wt ; --i ) {
                        dp[ i ] = max( dp[ i ], dp[ i - wt ] + val ) ;
                }
        }
        printf( "%lld\n", dp[ w ] ) ;
        return 0 ;
}


Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
int main() { 
    
    int a,b;

    cin >> a >> b;
    double k = double(a)/ double(b);
   	cout << a/b << " " << a%b << " " <<fixed << setprecision(5) << k << endl;



    


    return 0;
}


Measured memory_bytes: 3232
#include <bits/stdc++.h>
#define nmax 100005
#define lld long long
#define mod 1000000007
using namespace std;
int n, k, a[nmax];
lld ans = 0;
lld sum[nmax], fact[nmax];
namespace oMath
{
#define lld long long
    void extendedGcd(lld &x, lld &y, lld a, lld b)
    {
        if (!b)
            x = 1, y = 0;
        else
        {
            extendedGcd(x, y, b, a%b);
            lld aux = x;
            x = y;
            y = aux - y*(a/b);
        }
    }

    lld modularInverse(lld a, lld n)
    {
        lld x, y;
        extendedGcd(x, y, a, n);
        if (x < 0) x = n + x;
        return x;
    }
}
lld comb(lld n, lld k){
    lld inm1 = oMath::modularInverse(fact[k], mod);
    lld inm2 = oMath::modularInverse(fact[n-k],mod);
    lld ans = fact[n] * inm1;
    ans %= mod;
    ans *= inm2;
    ans %= mod;
    if (ans < 0){
        ans = mod + ans;
    }
    return ans;
}

int main()
{
    cin>>n>>k;
    fact[0] = 1;
    for (int i=1;i<=n;++i){
        fact[i] = (fact[i-1]*i)%mod;
    }
    for (int i=1;i<=n;++i){
        cin>>a[i];
    }
    sort(a+1,a+n+1);
    lld ans = 0;
    for (int i=1;i<=n;++i){
        if (i >= k){
            lld add = (comb(i-1, k-1)*a[i])%mod;
            ans += add;
            ans %= mod;
            if (ans < 0){
                ans = mod + ans;
            }
        }
        if (i <= n-k+1){
            lld sub = (comb(n-i,k-1)*a[i])%mod;
            ans -= sub;
            ans %= mod;
            if (ans < 0){
                ans = mod + ans;
            }
        }
    }
    cout<<ans<<'\n';
    return 0;
}


Measured memory_bytes: 1408
#include <stdio.h>

int main(void){
    int N;
    int D[100][2];
    int J[100] = {0};
    //input
    scanf("%d", &N);
    int i;
    for(i=0;i<N;i++){
        scanf("%d %d", &D[i][0], &D[i][1]);
        if(D[i][0] == D[i][1]) J[i] =1;
    }

    //check
    for(i=0;i<N;i++){
        if(i<= N-2){
            if(J[i]*J[i+1]*J[i+2] == 1){
                printf("Yes");
                return 0;
            }
        }
    }
    printf("No");
    return 0;
}

Measured memory_bytes: 2156
k = int(input())
seven = 0
i = 0
if k % 2 == 0:
    print(-1)
else:
    while True:
        i += 1
        seven = seven * 10 + 7
        seven = seven % k
        if seven == 0:
            print(i)
            break
        if i>1000000:
            print(-1)
            break

Measured memory_bytes: 63204
ss=input().strip()
ki=["R","U","D"]
gu=["L","U","D"]

ans="Yes"
for i in range(len(ss)):
  if (i+1)%2==0:
    if ss[i]=="R":
      ans="No"
      break
  else:
    if ss[i]=="L":
      ans="No"
      break
print(ans)

Measured memory_bytes: 3060