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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;

#define EACH(i,a) for (auto& i : a)
#define FOR(i,a,b) for (ll i=(a);i<(b);i++)
#define RFOR(i,a,b) for (ll i=(b)-1;i>=(a);i--)
#define REP(i,n) for (ll i=0;i<(n);i++)
#define RREP(i,n) for (ll i=(n)-1;i>=0;i--)
#define debug(x) cout<<#x<<": "<<x<<endl
#define pb push_back
#define ALL(a) (a).begin(),(a).end()

const ll linf = 1e18;
const int inf = 1e9;
const double eps = 1e-12;
const double pi = acos(-1);

template<typename T>
istream& operator>>(istream& is, vector<T>& vec) {
	EACH(x,vec) is >> x;
	return is;
}
template<typename T>
ostream& operator<<(ostream& os, vector<T>& vec) {
	REP(i,vec.size()) {
		if (i) os << " ";
		os << vec[i];
	}
	return os;
}
template<typename T>
ostream& operator<<(ostream& os, vector< vector<T> >& vec) {
	REP(i,vec.size()) {
		if (i) os << endl;
		os << vec[i];
	}
	return os;
}

bool m1[3000][3000] = {0};
ld m2[3000][3000];
ld C(int n, int k) {
	assert(n >= 0);
	if (n <= 0 || k > n) return 0;
	if (k == 0 || n == k) return 1;
	if (m1[n][k]) return m2[n][k];
	return m1[n][k] = true, m2[n][k] = C(n-1, k-1) + C(n-1, k);
}

ld power(ld x, int n) {
	ld res = 1;
	for (int i = 1; i <= n; i <<= 1) {
		if (n & i) {
			res *= x;
		}
		x *= x;
	}
	return res;
}

int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	int N, M; cin >> N >> M;
	vector< vector<int> > v(N, vector<int>(3)); cin >> v;
	const int score[3] = {5, 3, 2};
	vector<ld> B(M+1, 0);
	REP(i, M+1) {
		FOR(j, i, M+1) {
			B[i] += C(M, j) * power(1.0/3, j) * power(2.0/3, M-j);
		}
	}
	vector< vector<ld> > e(3, vector<ld>(M+1, 0));
	REP(i, 3) {
		REP(j, M+1) {
			ll p = j * v[0][i];
			vector<ld> per(N-1);
			REP(k, N-1) {
				ll need = (p+(v[k+1][i]-1))/v[k+1][i];
				per[k] = need == 0 ? 1 : need > M ? 0 : B[need];
			}
			ld dp[3000][3] = {0}; dp[0][0] = 1;
			REP(k, N-1) REP(l, 3) {
				dp[k+1][l] += dp[k][l] * (1-per[k]);
				if (l+1 < 3) {
					dp[k+1][l+1] += dp[k][l] * per[k];
				}
			}
			ld alllose = 1;
			REP(k, N-1) alllose *= per[k];
			e[i][j] = alllose * (-1) + (dp[N-1][0]+dp[N-1][1]+dp[N-1][2]) * score[i];
		}
	}
	ld ans = -linf;
	cout << fixed << setprecision(15);
	REP(i, M+1) REP(j, M+1) {
		int k = M - (i+j);
		if (k < 0) continue;
//		cout << i << " " << j << " " << k << " " << e[0][i] + e[1][j] + e[2][k] << endl;
		ans = max(ans, e[0][i] + e[1][j] + e[2][k]);
	}
	cout << fixed << setprecision(15) << ans << endl;
}

Measured memory_bytes: 48720
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
using namespace std;
#define CLR(a,b) memset(a,b,sizeof(a))
const int maxn = 1e7 + 10;
int a[maxn];
int b[maxn];
int n;

int point[210];
int edge[210][210];
int cnt = 0;

int nx,ny;
int vis[220];
int cx[220],cy[220];
int dx[220],dy[220];

int prime[maxn],primesize,phi[maxn];
bool isprime[maxn];
void getlist(int listsize)
{
    memset(isprime,1,sizeof(isprime));
    isprime[1]=false;
    for(int i=2;i<=listsize;i++)
    {
        if(isprime[i])prime[++primesize]=i;
         for(int j=1;j<=primesize&&i*prime[j]<=listsize;j++)
         {
            isprime[i*prime[j]]=false;
            if(i%prime[j]==0)break;
        }
    }
}


void pre()
{
    getlist(maxn-1);
    cin>>n;
    for(int i=1;i<=n; i++){
        int num;
        cin>>num;
        a[num] = 1;
        if(a[num-1]!=a[num]) b[num] = 1;
        else b[num] = 0;
        if(a[num]!=a[num+1]) b[num+1] = 1;
        else b[num+1] = 0;
    }
    for(int i=1; i<maxn; i++){
        if(b[i] == 1) point[++cnt] = i;
    }
    for(int i=1; i<=cnt; i++){
        if(point[i]%2 == 1) nx++,dx[nx] = point[i];
        else ny++,dy[ny] = point[i];
    }
//    cout<<nx<<" "<<ny<<endl;
    for(int i=1; i<=nx; i++){
        for(int j=1; j<=ny; j++){
            if(isprime[abs(dx[i] - dy[j])])
                edge[i][j] = 1;
//            cout<<dx[i]<<" "<<dy[j]<<endl;
        }
    }
}

bool path(int u)
{
    for(int i=1; i<=ny; i++){
        if(edge[u][i] && !vis[i]){
            vis[i] = 1;
            if(path(cy[i]) || cy[i] == -1){
                cx[u] = i;
                cy[i] = u;
                return 1;
            }
        }
    }
    return 0;
}

int maxmatch()
{
    int res = 0;
    CLR(cx,0xff);
    CLR(cy,0xff);

    for(int i=1;i<=nx;i++){
        CLR(vis,0);
        res += path(i);
    }
    return res;
}

int main()
{
//    freopen("in.txt","r",stdin);
    pre();
    int ans = 0;
    int edgenum = maxmatch();
//    cout<<"edge "<<edgenum<<endl;
//    for(int i = 1; i<=nx; i++)
//        cout<<dx[i]<<" "<<dy[cx[i]]<<endl;
    ans += edgenum;
    ans += ((nx-edgenum)/2)*2;
    ans += ((ny-edgenum)/2)*2;
    if((nx-edgenum)%2 == 1) ans+=3;
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 96512
#pragma GCC optimize("Ofast") 

////////////////////////////////////////////////////////////////////////////////

#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define endl "\n"
#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#define bew ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define all(x) x.begin(),x.end()
#define pb push_back
#define fi first
#define se second
#define mod (long)(1e9+7)
#define ip(ar,n) for(int i=0;i<n;++i)cin>>ar[i];
#define op(ar,n) for(int i=0;i<n;++i)cout<<ar[i]<<" ";
#define print(...) for(auto xas:{__VA_ARGS__})cerr<<xas<<" ";
#define test int t;cin>>t;while(t--)
#define tar(x) int x;cin>>x;
#define fil(ar,val) memset(ar,val,sizeof ar)
#define loop(n) for(int i=0;i<n;++i)
#define coutd(x,y) printf("%0.y lf",x);
#define verdict(x,y) if(flag)cout<<x;else cout<<y;


////////////////////////////////////////////////////////////////////////////////

typedef vector<int> vec; 
typedef pair<int, int> pa; 
typedef vector<pa> vecp; 
typedef set<int> se;
typedef map<int,int> ma;

////////////////////////////////////////////////////////////////////////////////

void manupulate(string &str)
{
    for(int i=0;i<str.size();++i)
    str[i]-=48;
}

bool isprime(int n)
{
    if(n<=1)
        return false;
    for(int i=2;i*i<=n;++i)
    if(n%i==0)
        return false;
    return true;
}

int expo(int a,int n)
{
    if(n==0)
        return 1;
    if(n==1)
        return a;
    int tmp=expo(a,n/2);
    tmp=(tmp*tmp)%mod;
    if(n&1)
        tmp=(tmp*a)%mod;
    return tmp;
}


////////////////////////////////////////////////////////////////////////////////



signed main() {
bew;


    tar(n);
    map<string,int> m;
    loop(n)
    {
        string tmp;
        cin>>tmp;
        ++m[tmp];
    }
cout<<m.size();






















return 0;
}

Measured memory_bytes: 19244
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cctype>
#include <functional>１
#include <map>
#include <cmath>

using namespace std;
typedef long long ll;

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

int main(){
    int n;
    cin >> n;
    vector<int> vec(n);
    rep(i,n) cin >> vec[i];
    int ans = 0;
    rep(i,n){
        ans += (vec[i] - 1);
    }
    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 256
# -*- coding: utf-8 -*-


def main():
    from fractions import gcd
    from functools import reduce

    n, large_x = map(int, input().split())
    x = sorted(list(map(lambda x: int(x) - large_x, input().split())) + [0])

    diff = [0 for _ in range(n + 1)]

    for i in range(1, n + 1):
        diff[i] = x[i] - x[i - 1]

    ans = reduce(gcd, diff)

    print(ans)


if __name__ == '__main__':
    main()


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

using namespace std;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
//#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) ll(x.size())
typedef long long ll;
//typedef pair<int, int> P;
//typedef pair<ll, ll> P;
//const double INF = 1e10;
//const ll INF = 10e15;
const ll MINF = -10e10;
const int INF = INT_MAX;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)


//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);

//typedef priority_queue<P, vector<P>, greater<P>> PQ_ASK;
const int mod = 1000000007;

bool check(string s, string t, int i) {
    for (int j = 0; j < t.size(); j++) {
        char a = s[i + j];
        char b = t[j];
        if (a == '?') continue;
        if (a == b) continue;
        return false;
    }
    return true;

}

string merge(string s, string t, int i) {
    return s.substr(0, i) + t + s.substr(i + t.size());
}

string replace(string s) {
    for (int j = 0; j < s.size(); j++) {
        if (s[j] == '?') {
            s[j] = 'a';
        }
    }
    return s;
}

int main() {
    string s, t;
    cin >> s >> t;

    vector<string> candidate;

    if (s.size() < t.size()) {
        cout << "UNRESTORABLE" << endl;
        return 0;
    }

    for (int i = 0; i <= s.size() - t.size(); i++) {
        bool b = check(s, t, i);
        if (b) {
            string n = merge(s, t, i);
            string now = replace(n);
            candidate.push_back(now);
        }
    }

    if (candidate.empty()) {
        cout << "UNRESTORABLE" << endl;
        return 0;
    }

    string ans = *min_element(candidate.begin(), candidate.end());

    cout << ans << endl;

}


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

typedef long long s64;
#define rep(i,l,r) for(int i=l;i<=r;++i)
#define per(i,r,l) for(int i=r;i>=l;--i)
const int N=1e5+5;
s64 w[N],w0[N],q[N];

int main()
{
	//freopen("1.in","r",stdin);
	int n,m;
	cin>>n>>m;
	int top=0;q[0]=n;
	rep(i,1,m)
	{
		s64 qi;
		scanf("%lld",&qi);
		while(top>=0&&q[top]>=qi)--top;
		q[++top]=qi;
	}
	w[top]=1;
	per(i,top,0)
	{
		s64 l=q[i];
		int j=i;
		while(l>q[0])
		{
			j=lower_bound(q,q+j,l)-q-1;
			w[j]+=l/q[j]*w[i];
			l%=q[j];
		}
		w0[l]+=w[i];
	}
	per(i,q[0],1)w0[i]+=w0[i+1];
	rep(i,1,n)printf("%lld\n",w0[i]);
}

Measured memory_bytes: 4096
//AOJ0118
#include<iostream>
#include<string>
using namespace std;
int H,W;
char table[102][102];

void kesu(int y,int x,char now){
	if(table[y][x]!=now)
		return ;
		
	table[y][x]='x';
	
	kesu(y+1,x,now);
	kesu(y-1,x,now);
	kesu(y,x+1,now);
	kesu(y,x-1,now);
		


}


int main(){

	while(true){
		cin>>H>>W;
		if(H==0&&W==0)break;
		for(int i=0;i<102;i++)for(int j=0;j<102;j++)table[i][j]='x';
		for(int i=1;i<=H;i++){
			for(int j=1;j<=W;j++){
				char tmp;
				cin>>tmp;
				table[i][j]=tmp;
			}
		}
	
		int ans;
		ans=0;
		
		for(int i=1;i<=H;i++){
			for(int j=1;j<=W;j++){
				if(table[i][j]!='x'){
					kesu(i,j,table[i][j]);
					ans++;
				}
			}
		}
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 3384
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); ++i)
#define all(x) (x).begin(),(x).end()
#define pb push_back
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>; // グラフ型

int main()
{
  string s; cin >> s;
  if(s == "Sunny") printf("Cloudy");
  if(s == "Cloudy") printf("Rainy");
  if(s == "Rainy") printf("Sunny");
}


Measured memory_bytes: 3696
#include <iostream>
#include <vector>
using namespace std;
#define rep(i, n) for (int i=0; i<n; ++i)

const int D = 60;
const int MAX_N = 2e5 + 10;
int to[D][MAX_N]; //to[n][m] = (town num 2^n times from m)

int main() {
    int n; long long k;
    cin >> n >> k;
    rep(i, n) {
        cin >> to[0][i];
        to[0][i]--;
    }
    rep(i, D-1) {
        rep(j, n) {
            to[i+1][j] = to[i][to[i][j]];
        }
    }
    int now = 0;
    for (int i=D-1; i >= 0; --i) {
        if (k & (1ll << i)) {
            now = to[i][now];
        }
    }
    cout << now +1 << endl;
}

Measured memory_bytes: 50528
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
#define sz(x) int(x.size())
typedef unsigned long long ll;
typedef long double ld;
typedef pair<int,int> P;
constexpr ll INF = (1LL << 60);

int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<P>> g(n);
  for (int i = 1; i < n; i++) {
    g[i].emplace_back(make_pair(i - 1, 0));
  }
  for (int i = 0; i < m; i++) {
    int l, r, c;
    cin >> l >> r >> c;
    l--; r--;
    g[l].emplace_back(make_pair(r, c));
  }

  priority_queue<pair<ll, int>, vector<pair<ll, int>>, greater<pair<ll, int>>> pq;
  vector<ll> dp(n, INF);
  dp[0] = 0;
  pq.push(make_pair(0LL, 0));

  while (!pq.empty()) {
    auto p = pq.top(); pq.pop();
    int u = p.second;
    if (dp[u] < p.first) continue;
    for (auto e : g[u]) {
      if (dp[e.first] > dp[u] + e.second) {
        dp[e.first] = dp[u] + e.second;
        pq.push(make_pair(dp[e.first], e.first));
      }
    }
  }
  ll res = dp[n-1];
  if (res == INF) cout << -1 << endl;
  else cout << res << endl;
  return 0;
} 

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

int main()
{
    int n, k;
    long total;

    cin >> n >> k;
    vector<int> p(n);
    rep(i, n)
        cin >> p.at(i);

    sort(p.begin(), p.end());
    total = 0;
    rep(i, k)
        total += p.at(i);

    cout << total << endl;
}

Measured memory_bytes: 3592
import sys
readline = sys.stdin.readline

# 最後の一枚を取るか、その直前を取るかしかない
# なぜなら、最後から数えて3枚目を取る場合は相手に最後から2枚目を取ることを期待するが、
# それなら自分が最後から2枚目を取ったほうが有利なため。

N,Z,W = map(int,readline().split())
A = list(map(int,readline().split()))

if N == 1:
  # 1枚の場合は取るしかない
  print(abs(A[0] - W))
  exit(0)
  
# 最後の一枚を取る場合
last_one = abs(A[-1] - W)

# 最後から二枚目を取る場合
last_two = abs(A[-1] - A[-2])

if last_one > last_two:
  print(last_one)
else:
  print(last_two)

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

using namespace std;

int main () {
	int n;
	cin >> n; 
	long long ans = 0; 
	for (int i=1; i<=n; i++) {
		if ((i % 15 !=0) && (i % 3 !=0) && (i % 5 !=0)) {
			ans = ans + i;
		}
	
	}
	cout << ans << endl;
}


Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp(x) fixed << setprecision(x)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const int inf = (1<<30)-1;
const ll INF = (1LL<<60)-1;
const ld EPS = 1e-10;
template<typename T> bool chmax(T &x, const T &y) {return (x < y)? (x = y, true) : false;};
template<typename T> bool chmin(T &x, const T &y) {return (x > y)? (x = y, true) : false;};

template<ll mod> struct Mod_Int{
    ll x;
    Mod_Int() {}
    Mod_Int(ll y) : x (y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}

    Mod_Int &operator += (const Mod_Int &p) {
        x = (x + p.x) % mod;
        return *this;
    }

    Mod_Int &operator -= (const Mod_Int &p) {
        x = (x + mod - p.x) % mod;
        return *this;
    }

    Mod_Int &operator *= (const Mod_Int &p) {
        x = (x * p.x) % mod;
        return *this;
    }

    Mod_Int &operator /= (const Mod_Int &p) {
        *this *= p.inverse();
        return *this;
    }

    Mod_Int &operator ++ () {return *this += (Mod_Int)1;}

    Mod_Int operator ++ (int) {
        Mod_Int tmp = *this;
        ++*this;
        return tmp;
    }

    Mod_Int &operator -- () {return *this -= (Mod_Int)1;}

    Mod_Int operator -- (int) {
        Mod_Int tmp = *this;
        --*this;
        return tmp;
    }

    Mod_Int operator - () const {return Mod_Int(-x);}

    Mod_Int operator + (const Mod_Int &p) const {return Mod_Int(*this) += p;}

    Mod_Int operator - (const Mod_Int &p) const {return Mod_Int(*this) -= p;}

    Mod_Int operator * (const Mod_Int &p) const {return Mod_Int(*this) *= p;}

    Mod_Int operator / (const Mod_Int &p) const {return Mod_Int(*this) /= p;}

    bool operator == (const Mod_Int &p) const {return x == p.x;}

    bool operator != (const Mod_Int &p) const {return x != p.x;}

    Mod_Int pow (ll n) const {
        Mod_Int now = *this, ret = 1;
        while(n > 0){
            if(n & 1) ret *= now;
            now *= now, n >>= 1;
        }
        return ret;
    }

    Mod_Int inverse () const {
        return pow(mod-2);
    }
};

using mint = Mod_Int<MOD>;
const int MAX_N = 2e6;
mint fac[MAX_N+1], ifac[MAX_N+1];

void init(){
    fac[0] = 1;
    rep2(i, 1, MAX_N){
        fac[i] = fac[i-1]*i;
    }
    ifac[MAX_N] = fac[MAX_N].inverse();
    rep3(i, MAX_N, 1){
        ifac[i-1] = ifac[i]*i;
    }
}

mint comb(int n, int k){
    return fac[n]*ifac[n-k]*ifac[k];
}

mint perm(int n, int k){
    return fac[n]*ifac[n-k];
}

int main(){
    int K;
    string S;
    cin >> K >> S;
    int N = sz(S);
    init();
    mint ans = 0;
    rep(i, K+1){
        ans += mint(25).pow(i)*comb(N+K, i); 
    }
    cout << ans.x << endl;
}

Measured memory_bytes: 35648
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#include <unordered_map>
#include <iomanip>
//#pragma GCC optimize("Ofast")
//#define _GLIBCXX_DEBUG
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
//#define int ll
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef pair<int,int> pii;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define floatprec(dig) fixed << setprecision(dig)
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
#define invar(typ, var) typ var; cin >> var;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;} return 0;}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;} return 0;}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX / 2;
const ll LLINF = 1LL<<60;
constexpr ll MOD = 1000000007;
const double EPS = 1e-9;

ll d2(ll a) {
  ll c = 0;
  while(a%2==0) {
    c++;
    a/=2;
  }
  return c;
}

signed main(void) {
  cin.tie(0); ios::sync_with_stdio(false);
  
  int N;
  cin >> N;
  ll c = 0;
  rep(i, N) {
    ll a;
    cin >> a;
    c += d2(a);
  }
  
  fin(c);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (ll i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
 
int main(){
    int n, m, q;
    cin >> n >> m >> q;
    vector<vector<int>> a(q, vector<int>(4));
    rep(i, q){
        cin >> a.at(i).at(0) >> a.at(i).at(1) >> a.at(i).at(2) >> a.at(i).at(3);
    }
    vector<int> b(10);
    int ma = 0;
    for(b.at(0)=1; b.at(0)<=m; b.at(0)++){
    for(b.at(1)=b.at(0); b.at(1)<=m; b.at(1)++){
    for(b.at(2)=b.at(1); b.at(2)<=m; b.at(2)++){
    for(b.at(3)=b.at(2); b.at(3)<=m; b.at(3)++){
    for(b.at(4)=b.at(3); b.at(4)<=m; b.at(4)++){
    for(b.at(5)=b.at(4); b.at(5)<=m; b.at(5)++){
    for(b.at(6)=b.at(5); b.at(6)<=m; b.at(6)++){
    for(b.at(7)=b.at(6); b.at(7)<=m; b.at(7)++){
    for(b.at(8)=b.at(7); b.at(8)<=m; b.at(8)++){
    for(b.at(9)=b.at(8); b.at(9)<=m; b.at(9)++){
        int cou = 0;
        rep(i, q){
            if(b.at(a.at(i).at(1)-1) - b.at(a.at(i).at(0)-1) == a.at(i).at(2)) cou += a.at(i).at(3);
        }
        if(ma < cou) ma = cou;
    }}}}}}}}}}
    cout << ma << endl;
    return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <algorithm>
#include <string>
#include <map>
#include <vector>
using namespace std;


struct Str2 {
  string s;
  Str2() {}
  Str2(string s) : s(s) {}
  bool operator < (const Str2 &str) const {
    if(s.size() != str.s.size()) return s.size() > str.s.size();
    return s < str.s;
  }
};

const int MAX_H = 20;
const int MAX_W = MAX_H;
int H, W;
char G[MAX_H][MAX_W];
map<string, int> M;
vector<Str2> V;


string solve() {
  M.clear();
  V.clear();
  for(int i = 0; i < H; ++i) {
    for(int j = 0; j < W; ++j) {
      for(int dx = -1; dx <= 1; ++dx) {
	for(int dy = -1; dy <= 1; ++dy) {
	  if(dx == 0 && dy == 0) continue;
	  int x = j;
	  int y = i;
	  string s = "";
	  do {
	    s += G[y][x];
	    if(s.size() >= 2 && ++M[s] == 2) {
	      V.push_back(Str2(s));
	    }
	    int nx = (x+dx+W)%W;
	    int ny = (y+dy+H)%H;
	    x = nx;
	    y = ny;
	  } while(!(x == j && y == i));
	}
      }
    }
  }
  if(V.size() == 0) return "0";
  sort(V.begin(), V.end());
  return V[0].s;
}

int main() {
  while(cin >> H >> W && (H | W)) {
    for(int i = 0; i < H; ++i) {
      for(int j = 0; j < W; ++j) {
	cin >> G[i][j];
      }
    }
    cout << solve() << endl;
  }
  return 0;
}

Measured memory_bytes: 28000
#include <iostream>
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;

int main(int argc, const char * argv[]) {
  
  int H, W; cin >> H >> W;
  vector<vector<int>> field(H), log(H*W);
  int a;
  for (int h=0; h<H; h++){
    for (int w=0; w<W; w++){
      cin >> a;
      field[h].push_back(a);
    }
  }
  
  int count=0;
  for (int h=0; h<H; h++){
    for (int w=0; w<W; w++){
      if (field[h][w]%2 == 0)
        continue;
      else{
        if (w != W-1){
          field[h][w]--;
          field[h][w+1]++;
          log[count].push_back(h+1);
          log[count].push_back(w+1);
          log[count].push_back(h+1);
          log[count].push_back(w+2);
          count++;
        } else if (h != H-1){
          field[h][w]--;
          field[h+1][w]++;
          log[count].push_back(h+1);
          log[count].push_back(w+1);
          log[count].push_back(h+2);
          log[count].push_back(w+1);
          count++;
        } else
          continue;
      }
    }
  }
  
  cout << count << endl;
  for (int i=0; i<count; i++){
    for (int j=0; j<3; j++)
      cout << log[i][j] << " ";
    cout << log[i][3] << endl;
  }
  
  return 0;
}

Measured memory_bytes: 12928
#include "bits/stdc++.h"
#include <set>

using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(i) (i).begin(), (i).end()
#define rall(i) (i).begin(), (i).end(), greater<int>()
#define int long long
#define elif else if
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fst first
#define sec second
#define mod 1000000007
#define INF 10e10
template <typename T>

void print(T x)
{
	std::cout << x << " ";
}
template <typename T>

void println(T x)
{
	std::cout << x << "\n";
}

signed main(void) {
	string s, t,u;
	int a, b;
	cin >> s >> t >> a >> b >> u;
	if (s == u)
		cout << a - 1 << " " << b;
	else
		cout << a << " " << b-1;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
    public static void main(String[] defargs) {
        Scanner scanner = new Scanner(System.in);
	    int a = scanner.nextInt();
		int b = scanner.nextInt();
		int c = scanner.nextInt();
		int yakusu = 0;
		for (int i = a;i <= b; i++) {
			if (c % i == 0)
				yakusu++;
		}
		System.out.println(yakusu);
	}
}



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

#define N_MAX 100

int M[N_MAX][N_MAX];

int main(){

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

  for(int i=0; i<n*n; i++){
    scanf("%d", &M[i/n][i%n]);
  }

  /*
   * Find Mininum Spanning Tree using
   * Prim's Algorithm
  */
  vector<bool> is_belong_to_mst(n, false);
  is_belong_to_mst.at(0) = true;
  int total_cost = 0;
  for(int i=1; i<n; i++){
    // get t and adj
    vector<int> t;
    vector<int> adj;
    for(int i=0; i<n; i++){
      if(is_belong_to_mst.at(i)) t.push_back(i);
      else adj.push_back(i);
    }

    int min_cost = INT_MAX;
    int next_t = 0;
    for(int i=0; i<t.size(); i++){
      for(int j=0; j<adj.size(); j++){
        if(M[t.at(i)][adj.at(j)] != -1 && M[t.at(i)][adj.at(j)] < min_cost){
          min_cost = M[t.at(i)][adj.at(j)];
          next_t = adj.at(j);
        }
      }
    }

    is_belong_to_mst.at(next_t) = true;
    total_cost += min_cost;
  }

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

  return 0;
}



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

ll gcd(ll x, ll y) {
  if (y > x) {
    ll tmp = y;
    y = x;
    x = tmp;
  }
  if (x % y == 0) {
    return y;
  } else {
    return gcd(y, x % y);
  }
}

int main() {
  ll a, b, c, d, ans;
  ll tmpc1, tmpc2, tmpd1, tmpd2;
  ll tmpcd1, tmpcd2, cd;
  cin >> a >> b >> c >> d;
  ans = b - a + 1;
  cd = (c * d) / gcd(c, d);
  tmpcd1 = a / cd;
  if (a % cd == 0LL) {
    tmpcd1--;
  }
  tmpcd2 = b / cd;

  cd = tmpcd2 - tmpcd1;
  tmpc1 = a / c;
  if (a % c == 0LL) {
    tmpc1--;
  }
  tmpc2 = b / c;
  c = tmpc2 - tmpc1;
  tmpd1 = a / d;
  if (a % d == 0LL) {
    tmpd1--;
  }
  tmpd2 = b / d;
  d = tmpd2 - tmpd1;
  ans -= d + c;
  ans += cd;
  //cout << c << " " << d << " " << cd << endl;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3580
import collections

N = int(input())
a = list(map(int, input().split()))

a_count = collections.Counter(a)

ans = 0
for key in list(a_count.keys()):
    if a_count[key] < int(key):
        ans += a_count[key]
    else:
        ans += a_count[key] - int(key)

print(ans)

Measured memory_bytes: 18676
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i ++)
using namespace std;
using ll = long long;
using PL = pair<ll,ll>;
using P = pair<int,int>;
constexpr int INF = 1000000000;
constexpr long long HINF = 1000000000000000;
constexpr long long MOD = 1000000007;// = 998244353;
constexpr double EPS = 1e-4;
constexpr double PI = 3.14159265358979;
int dist[23][105][105];

vector<int> dijkstra(int n, vector<vector<P>>& G,int s) {
    vector<int> dist(n,INF);
    dist[s] = 0;

    priority_queue<P,vector<P>,greater<P>> q;
    q.push({0,s});

    while (!q.empty()) {
        P p = q.top(); q.pop();
        int d = p.first;
        int v = p.second;
        if (dist[v] < d) continue;
        for (P p: G[v]) {
            int e = p.first;
            int cost = p.second;
            if (dist[e] > dist[v] + cost) {
                dist[e] = dist[v] + cost;
                q.push({dist[e],e});
            }
        }  
    }
    return dist;
}

void solve(int N,int M,int C,int s,int g) {
    rep(i,C)rep(j,N)rep(k,N) dist[i][j][k] = INF;
    
    //input
    --s;--g;
    rep(i,M) {
        int x,y,d,c; cin >> x >> y >> d >> c;
        --x;--y;--c;
        dist[c][x][y] = min(dist[c][x][y],d);
        dist[c][y][x] = min(dist[c][y][x],d);
    }
    
    //caluculate cost
    vector<int> p(C);
    rep(i,C) cin >> p[i];
    vector<vector<int>> cost(C,vector<int>(20000,0));
    rep(i,C) {
        vector<int> Q(p[i] - 1),R(p[i]);
        rep(j,p[i] - 1) cin >> Q[j];
        rep(j,p[i]) cin >> R[j];
        int now = 1;
        rep(j,p[i] - 1) {
            int q = Q[j],r = R[j];
            while (now <= q) {
                cost[i][now] = cost[i][now - 1] + r;
                ++now;
            }
        }
        while (now <= 20000) {
            cost[i][now] = cost[i][now - 1] + R.back();
            ++now;
        }
    }

    //Floyd-Warshall
    rep(t,C)rep(k,N)rep(i,N)rep(j,N) dist[t][i][j] = min(dist[t][i][j],dist[t][i][k] + dist[t][j][k]);
    
    //make graph
    vector<vector<P>> G(N);
    rep(i,N)for(int j = i + 1;j<N;++j) {
        int d = INF;
        rep(k,C) {
            int x = dist[k][i][j];
            if (x >= 20000) continue;
            d = min(d,cost[k][x]);
        }
        G[i].push_back(P(j,d));
        G[j].push_back(P(i,d));
    }

    //dijkstra
    vector<int> dist = dijkstra(N,G,s = s);
    int x = dist[g];
    if (x == INF) cout << -1 << endl;
    else cout << x << endl;
}

int main() {
    while (1) {
        int N,M,C,s,g; cin >> N >> M >> C >> s >> g;
        if (N == 0 && M == 0) return 0;
        solve(N,M,C,s,g);
    }
    return 0;
}


Measured memory_bytes: 5628
#!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1

n,k = map(int,input().split())
print(min(n%k,abs(k-n%k)))

Measured memory_bytes: 38256
import java.util.*;

public class Main {

    public static void main(String[] args) {

        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int m = scan.nextInt();
		int[] height;		
		height = new int[n];		//標高
		for (int i=0; i<n; i++){
			height[i] =  scan.nextInt();
		}

		HashSet<Integer> hs = new HashSet<>();
		for (int i=0; i<n; i++){
			hs.add(i);
		}

		int a = -1;
		int b = -1;
		for (int i=0; i<m; i++){
			a = scan.nextInt()-1;
			b = scan.nextInt()-1;
//			System.out.println(a +":"+ b);

			if(height[a]>height[b]){
				hs.remove(b);
			} else if(height[a]<height[b]) {
				hs.remove(a);
			} else {		//同じ高さの場合は両方「良い展望台」に該当せず
				hs.remove(a);
				hs.remove(b);
			}
		}
		
		System.out.println(hs.size());
	    scan.close();	
    }
}

Measured memory_bytes: 66852
#include<iostream>
#include<string.h>
#include<algorithm>
using namespace std;
int main()
{
	int n,a,flag=1;
	cin>>n;int arr[n];
	for(int i=0;i<n;i++)
	{
		cin>>arr[i];
	}
	sort(arr,arr+n);
	for(int i=0;i<n-1;i++)
	{
		if(arr[i]==arr[i+1])
		{
			flag=0;
			break;
		}
	}
	if(flag==1)
	cout<<"YES";
	else 
	cout<<"NO";
	
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#include<string.h>
#define pb push_back
#define all(v) v.begin(),v.end()
#define see(x) cout<<#x<<" : "<<(x)<<endl;
#define ya cout<<"yes"<<endl;
#define no cout<<"no"<<endl;
#define ff first
#define sc second
typedef unsigned long long ll;
using namespace std;
int main()
{
//    ios::sync_with_stdio(false);
//    cin.tie(NULL),cout.tie(NULL);
    long double w,h,x,y,a,b,ans=0;
    cin>>w>>h>>a>>b;
    ans=(w*h);
    ans/=2;
    int p=0;
    if(a==(w/2) && b==(h/2.0))p=1;
    printf("%.6LF %d\n",ans,p);
    return 0;
}

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

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

  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    int tmp;
    cin >> tmp;
    a.at(i) = tmp;
  }

  for (int i = 0; i < n - 1; i++) {
    for (int j = 0; j < n - i - 1; j++) {
      if (a.at(j) < a.at(j + 1)) {
        int tmp;
        tmp = a.at(j);
        a.at(j) = a.at(j + 1);
        a.at(j + 1) = tmp;
      }
    }
  }

  int alice = 0;
  int bob = 0;
  for (int i = 0; i < n; i++) {
    if (i % 2 == 0) {
      alice += a.at(i);
    } else {
      bob += a.at(i);
    }
  }

  cout << alice - bob << endl;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
// Begin Header {{{
#define all(x)          (x).begin(), (x).end()
#define rep(i, s, n)    for (i64 i = (s), i##_limit = (n); i < i##_limit; ++i)
#define repr(i, s, t)   for (i64 i = (s), i##_limit = (t); i >= i##_limit; --i)
#define VAR(type, ...)  type __VA_ARGS__; read(__VA_ARGS__);
#ifndef DBG
#define dump(...)
#endif
using namespace std;
using i64 = int_fast64_t;
using pii = pair<i64, i64>;
template <class T, class U> inline bool chmax(T &a, const U &b) { return b > a && (a = b, true); }
template <class T, class U> inline bool chmin(T &a, const U &b) { return b < a && (a = b, true); }
constexpr int INF  = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;

template <class T>
inline vector<T> makeV(const T &initValue, size_t sz) {
    return vector<T>(sz, initValue);
}

template <class T, class... Args>
inline auto makeV(const T &initValue, size_t sz, Args... args) {
    return vector<decltype(makeV<T>(initValue, args...))>(sz, makeV<T>(initValue, args...));
}

template <class T>
inline istream& operator>> (istream &is, vector<T> &vec) {
    for (auto &e : vec) is >> e;
    return is;
}

inline void read() {}

template <class Head, class... Tail>
inline void read(Head &head, Tail&... tail) { cin >> head; read(tail...); }

inline void print() { cout << "\n"; }

template <class Head, class... Tail>
inline void print(Head &&head, Tail&&... tail) {
    cout << head;
    if (sizeof...(tail)) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
inline ostream& operator<< (ostream &os, const vector<T> &vec) {
    static constexpr const char *delim[] = { " ", "" };
    for (const auto &e : vec) os << e << delim[&e == &vec.back()];
    return os;
}
// }}} End Header

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

    constexpr int cost[] = { 0, 2, 5, 5, 4, 5, 6, 3, 7, 6 };

    VAR(int, N, M);

    bool can[20] {};
    rep(i, 0, M) {
        VAR(int, a);
        can[a] = true;
    }

    auto dp = makeV<int>(false, N/2 + 5, N+5);
    // dp[digit][rem]
    dp[0][0] = true;
    rep(digit, 1, N/2 + 5) {
        rep(rem, 1, N+1) {
            rep(n, 1, 10) {
                if (!can[n]) continue;
                if (rem - cost[n] >= 0) {
                    dp[digit][rem] |= dp[digit - 1][rem - cost[n]];
                }
            }
        }
        dump(digit, dp[digit][N]);
    }

    repr(digit, N/2 + 4, 1) {
        if (!dp[digit][N]) continue;
        string ans = "";
        int rem = N;
        for (int d = digit; d >= 0; --d) {
            repr(n, 9, 1) {
                if (!can[n]) continue;
                if (rem - cost[n] >= 0 && dp[d][rem - cost[n]]) {
                    rem -= cost[n];
                    ans += char('0' + n);
                    break;
                }
            }
        }
        print(ans);
        return 0;
    }

    return 0;
}


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

class UF{
public:
	vector<int> par, rank;
	UF(int n){
		for(int i = 0; i < n; i++){
			par.emplace_back(i);
			rank.emplace_back(0);
		}
	}

	int root(int x){
		return par[x] == x ? x : par[x] = root(par[x]);
	}

	bool same(int x, int y){
		return root(x) == root(y);
	}

	void unite(int x, int y){
		x = root(x);
		y = root(y);
		if(rank[x] < rank[y]) par[x] = y;
		else{
			par[y] = x;
			if(rank[x] == rank[y]) rank[x]++;
		}
	}
};

int main(){
	int n, k, l;
	cin >> n >> k >> l;
	UF road(n), train(n);
	while(k--){
		int p, q;
		cin >> p >> q;
		p--; q--;
		road.unite(p, q);
	}
	while(l--){
		int r, s;
		cin >> r >> s;
		r--; s--;
		train.unite(r, s);
	}
	map<pair<int, int>, int> mp;
	for(int i = 0; i < n; i++) mp[make_pair(road.root(i), train.root(i))]++;
	for(int i = 0; i < n; i++) cout << mp[make_pair(road.root(i), train.root(i))] << ' ';
	cout << endl;
}

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

using namespace std;

typedef long long	ll;

const ll mod = ll(1e9) + 7LL;

ll fast_expo(ll base, ll x, ll mod){
	ll r = 1LL;

	while(x){
		if(x & 1LL){
			r = (r * base) % mod;
		}

		base = (base * base) % mod;
		x >>= 1LL;
	}

	return r;
}

const int N = int(2e5 + 10);
ll fat[N];

ll mult(ll lo, ll hi){
	ll r = 1LL;

	for(; lo <= hi ; lo++){
		r = (lo * r) % mod;
	}

	return r;
}

ll comb(ll n, ll a){
	ll d = mult(n - a + 1LL, n);
	// d /= fat[a];
	d = (d * fast_expo(fat[a], mod - 2LL, mod)) % mod;

	return d;
}

int main(){
	ll n, a, b;

	fat[0] = 1LL;

	for(int i = 1 ; i < N ; i++){
		fat[i] = ll(i) * fat[i - 1];
		fat[i] %= mod;	
	}

	scanf("%lld %lld %lld", &n, &a, &b);

	ll tot = fast_expo(2LL, n, mod) - 1LL;

	// printf("%lld, %lld, %lld %lld\n", comb(n, a), comb(n, b), fat[b], tot);

	tot -= comb(n, a);

	if(tot < 0){
		tot += mod;
	}

	tot -= comb(n, b);

	if(tot < 0){
		tot += mod;
	}

	printf("%lld\n", tot);

	return 0;
}

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

ab = [tuple(map(int,input().split())) for i in range(n-1)]
es = [[] for i in range(n)]
for a,b in ab:
    a,b = a-1,b-1
    es[a].append(b)
    es[b].append(a)
INF = float('inf')
dist0 = [INF] * n
dist0[0] = 0
import heapq
hq = [(0,0)]
heapq.heapify(hq)
while hq:
    c,v = heapq.heappop(hq)
    for to in es[v]:
        if c+1 >= dist0[to]: continue
        dist0[to] = c+1
        heapq.heappush(hq,(c+1,to))

distn = [INF] * n
distn[n-1] = 0
hq = [(0,n-1)]
heapq.heapify(hq)
while hq:
    c,v = heapq.heappop(hq)
    for to in es[v]:
        if c+1 >= distn[to]: continue
        distn[to] = c+1
        heapq.heappush(hq,(c+1,to))


count_f = 0
for i in range(n):
    if dist0[i] <= distn[i]:
        count_f+=1

if count_f > n-count_f: print('Fennec')
else: print('Snuke')



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

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

int X, Y;
int mod = 1000000007;
int F[1000010], R[1000010];

int con(int n, int m)
{
    if(n < m)return 0;
    if(m < 0)return 0;
    return F[n] * R[m] % mod * R[n - m] % mod;
}

int pow_mod(int a, int b)
{
    if(b == 0)return 1;
    int ret = pow_mod(a * a % mod, b / 2);
    if(b & 1LL)ret = ret * a % mod;
    return ret;
}

signed main()
{
    cin >> X >> Y;

    if((X + Y) % 3)
    {
        cout << 0 << endl;
        return 0;
    }

    F[0] = 1;
    for(int i = 1; i < 1000010; i++)F[i] = F[i - 1] * i % mod;
    rep(i, 1000010)R[i] = pow_mod(F[i], mod - 2);

    int N = (X + Y) / 3;
    int d = (2 * Y - X) / 3;

    cout << con(N, d) << endl;

    return 0;
}


Measured memory_bytes: 19240
while True:
    n = input()
    if n == 0:
        break
    S = map(int,raw_input().split())
    S2 = [0] * n
    num = 0
    while True:
        for i in range(n):
            S2[i] = S.count(S[i])
        if S2 == S:
            break
        else:
            S, S2 = S2, S
            num += 1
    print num
    for i in S:
        print i,
    print

Measured memory_bytes: 4208
Imports System
Class B
	Shared Function Main() As Integer
	Dim N,K As Integer
	Dim inputs() As String
	inputs = Console.ReadLine().Split()
	N = Integer.Parse(inputs(0))
	K = Integer.Parse(inputs(1))

	Dim ans As Integer = 0
	While N > 0
		ans += 1
		N \= K
	End While
	Console.WriteLine(ans)
	Return 0
	End Function
End Class


Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int k, n;
  cin >>k >>n;
  
  vector<int> a(n);
  for (int i = 0; i < n; i++)
    cin >> a[i];
  
  int m = a[0] + k - a[n-1];
  for (int i = 1; i < n; i++) {
    m = max(a[i]-a[i-1], m);
  }
   
  int ans = k - m;
  cout << ans << endl;
}

Measured memory_bytes: 4044
(let ((x (concatenate 'list (read-line))))

  (defun comma-to-space (lst)
    (labels ((f (l acc)
                (if (null l)
                  acc
                  (if (char= (car l) #\,)
                    (f (cdr l) (cons #\Space acc))
                    (f (cdr l) (cons (car l) acc))))))
      (f lst nil)))

  (format t "~A~%"
          (concatenate 'string (reverse (comma-to-space x)))))


Measured memory_bytes: 23556
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int main()
{
    int a,b;
    while(~scanf("%d%d",&a,&b))
    {
        printf("%d\n",a*b+1-a-b);
    }
    return 0;
}

Measured memory_bytes: 128
/*
BY: SAFWAAN SHAIKH
PROBLEM: https://atcoder.jp/contests/abc177/tasks/abc177_d
KEY IDEAS: Graphs, Connected Components
TIME COMPLEXITY: 
*/

#define r(x) do{while((x=getchar())<'0'); for(x-='0'; '0'<=(_=getchar()); x=(x<<3)+(x<<1)+_-'0');}while(0)
#include <bits/stdc++.h>
#define f first
#define endl "\n"
#define s second
#define pb push_back
#define ms(a,b) memset(a,b,sizeof(a))
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
using namespace std;
typedef vector<int> vi;
typedef pair<int,int> pii;
char _;

int n,m,a,b;
int ans=0;
int root[200001],sze[200001];

int find_root(int v){
	if(v==root[v]){
		return v;
	}
	return root[v] = find_root(root[v]);
}

void unite(int x,int y){
	x = find_root(x);
	y = find_root(y);
	if(x!=y){
		if(sze[x] < sze[y]) swap(x,y);
		root[y]=x;
		sze[x]+=sze[y];
	}
}

int main(){
//	freopen("problemname.in", "r", stdin);
//  freopen("problemname.out", "w", stdout);
    ios_base::sync_with_stdio(false);
	cin.tie(NULL);cout.tie(NULL);	
	cin>>n>>m;
	for(int i=1;i<=n;i++){
		sze[i]=1;root[i]=i;
	}
	for(int i=0;i<m;i++){
		cin>>a>>b;
		unite(a,b);
	}
	for(int i=1;i<=n;i++)ans = max(ans,sze[i]);
	
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 5176
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <iomanip>
#include <functional>
#include "math.h"
#include <set>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define VI vector<int>
#define debug(x) cout<<#x<<": "<<x<<endl
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define MB 1000000007
#define NB 1000000000

int N,M;
vector<double> A;
int a[70];
int main()
{

	cin >> N >> M;
	if(N > M){
		cout << "No";
	} else {
		cout << "Yes";
	}

//	cout << fixed << setprecision(0) <<  N > M ? "No" : "Yes";


}




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

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

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
  int a[6],count=0;
  for(int i=0;i<6;i++)
    cin>>a[i];
  for(int i=0;i<6;i++){
    for(int j=0;j<6;j++){
      if(a[i]==a[j])
        count++;
    }
  }
  if(count==10)
    cout<<"YES"<<endl;
  else
    cout<<"NO"<<endl;
}

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

int main() {
  ll m = 1000,n;
  cin >> n;
  vector<ll>a(n);
  rep(i,0,n) cin >> a[i];
  ll k = 0,p = 0;
  rep(i,0,n-1){
    m += k*a[i];
    k = 0;
    p = 0;
    if(a[i] < a[i+1]){
      k = m/a[i];
      p = a[i];
      m -= k*p;
    }
  }
  m += k*a[n-1];
  cout << m << endl;
}

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

#define pb(a) push_back(a)

typedef long long ll;
const ll inf = 1e9+7;
const int dsize = 1e5+5;
int dx[] = {-1,0,1,0},dy[] = {0,1,0,-1};
vector<ll> prime;

ll inv[dsize],fac[dsize];

inline ll GCD(ll a,ll b){ll c;while(b!=0){c=a%b;a=b;b=c;}return a;}
inline ll LCM(ll a,ll b){return a*b/GCD(a,b);}
inline ll POW(ll a,ll b){ll c=1;while(b>0){if(b&1){c=a*c%inf;}a=a*a%inf;b>>=1;}return c;}
inline void _nCr(){fac[0]=1;for(int i=1;i<dsize;i++){fac[i]=fac[i-1]*i%inf;}for(int i=0;i<dsize;i++){inv[i]=POW(fac[i],inf-2);}}
inline ll nCr(ll n,ll r){return (fac[n]*inv[r]%inf)*inv[n-r]%inf;}
inline void PRI(ll n){bool a[n+1];for(int i=0;i<n+1;i++){a[i]=1;}for(int i=2;i<n+1;i++){if(a[i]){prime.pb(i);ll b=i;while(b<=n){a[b]=0;b+=i;}}}}

int main() {
	int n;cin>>n;
	ll a[n];
	ll sum[n];
	bool h=false;
	int pos=0;int ans=0;
	for(int i=0;i<n;i++){
		cin >> a[i];
	}
	sort(a,a+n);
	for(int i=0;i<n;i++){
		if(i)sum[i]=sum[i-1]+a[i];
		else sum[0]=a[i];
	}
	for(int i=0;i<n-1;i++){
		if(pos==i)pos++;
		while(sum[i]*2>=a[pos]){
			if(pos==n-1){		
				if(!h)ans=i;
				h=true;
				break;
			} else {
				sum[i]+=a[pos];
				pos++;
			}
		}
	}
	if(!h)ans=1;
	else{
		ans=n-ans;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 1792
//#include <bits/stdc++.h>
#include <iostream>
#include <list>
#include <vector>
#include <cstdlib>
using namespace std;
#define forr(i,m,n) for (int i=(m); i<=(n); i++)
#define DBG 0

#define MAXN 101
#define MAXV 100001
long a[MAXN][MAXV];

int main() {
  int n, W;
  cin >> n >> W;
  int w[MAXN];
  int v[MAXN];
  forr(i,0,n-1) {
    cin >> w[i] >> v[i];
    if (DBG) cout << w[i] << " ";
    a[i][0] = 0;
  }
  if (DBG) {
    cout << endl;
    forr(i,0,n-1) cout << v[i] << " ";
    cout << endl << n << " n|w " << W << endl;
  }

  forr(i,0,n-1)
  forr(j,0,MAXV)
    a[i][j] = W+1;
  a[0][v[0]] = w[0];

  forr(i,1,n-1) {
    forr(j,1,MAXV) {
      if (a[i][j] > a[i-1][j])
        a[i][j] = a[i-1][j];
      if (DBG) {
        cout << "i " << i << " j " << j << " wi " << w[i]
             << " vi " << v[i] << " ai1j " << a[i-1][j]
             << " ai1jwi " << a[i-1][j+w[i]] << endl;
      }
      if (a[i-1][j]+w[i] < a[i-1][j+v[i]])
          a[i][j+v[i]] = a[i-1][j]+w[i];
    }
    if (a[i][v[i]] > w[i])
      a[i][v[i]] = w[i];
  }

  if (DBG) {
    forr(i,0,n-1) {
      forr(j,0,MAXV) cout << a[i][j] << " ";
      cout << endl;
    }
  }

  for(int j = MAXV; j>0; j--)
   if (a[n-1][j] <= W) {
     cout << j;
     exit(0);
   }
}


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

using namespace std;

int main(){

	int n, k, c;
	string s;
	vector<int> a, b;

	cin>> n >> k >> c;
	cin>> s;

	for (int i = 0;i < n;i++) {
		if (s[i] == 'o') {
			a.push_back(i + 1);
			i += c;
		}
		if (a.size() == k) break;
	}

	for (int i = n - 1;i >= 0;i--) {
		if (s[i] == 'o') {
			b.push_back(i + 1);
			i -= c;
		}
		if (b.size() == k) break;
	}

	/*for (int i = 0;i < a.size();i++) cout << a[i] << " ";
	cout << endl;
	for (int i = 0;i < b.size();i++) cout << b[i] << " ";
	cout << endl;
	cout << a.size() << endl;
	cout << b.size() << endl;*/

	//sort(a.begin(), a.end());
	reverse(b.begin(), b.end());
	
	for(int i=0;i<k;i++){
		if (a[i] == b[i]) cout << a[i] << endl;
	}
	
	return 0;
}


Measured memory_bytes: 3448
n=int(input())
t=[]
for _ in range(n):
    t.append(int(input()))

import math
from functools import reduce

def lcm_base(x, y):
    return (x * y) // math.gcd(x, y)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

print(lcm_list(t))

Measured memory_bytes: 9528
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ll long long
#define lld long double
#define ALL(x) x.begin(), x.end()
#ifdef DEBUG
#define line() cerr << "[" << __LINE__ << "] ";
#define dump(i) cerr << #i ": " << i << " ";
#define dumpl(i) cerr << #i ": " << i << endl;
#else
#define line(i)
#define dump(i)
#define dumpl(i)
#endif
#define MOD 1000000007ll
using namespace std;
bool has(vector<int> &v,int n){
    rep(i,v.size()){
        if (v[i]==n)
            return true;
    }
    return false;
}
int main(void)
{
    int n,m;
    cin>>n>>m;
    map<int,vector<int>> g;
    rep(i,m){
        int a,b;
        cin>>a>>b;
        a--;
        b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    deque<vector<int>> q;
    q.push_back({0});
    int ans=0;
    while(!q.empty()){
        vector<int> path=q.front();
        q.pop_front();
        if (path.size()==n){

            ans++;
            continue;
        }
        int now=path.back();
        for (auto next:g[now]){
            if (!has(path,next)){
                
                auto _p=path;
                _p.push_back(next);
                q.push_back(_p);
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 640