akhauriyash/Code-Regression huggingface dataset:
//競技プログラミング用のテンプレート
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <string>
#include <math.h>

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

using namespace std;
using ll = long long int;
using p = pair<int, int>;
using pl = pair<ll, ll>;
using v = vector<int>;
using vd = vector<double>;
using vs = vector<string>;
using vl = vector<ll>;

int main()
{
    ll n, m;
    cin >> n >> m;
    vl a(n, 0);
    vl s(200000 + 1, 0);
    vl c(n, 0);
    rep(i, n)
    {
        cin >> a[i];
        s[a[i]]++;
    }
    for(int i = 200000 - 1; i >= 0; i--)
    {
        s[i] += s[i + 1];
    }
    sort(a.begin(), a.end());
    reverse(a.begin(), a.end());
    c[0] = a[0];
    rep(i, n) if(i) c[i] += a[i] + c[i - 1];
    ll l = 0;
    ll r = 200000 + 1;
    while(l < r - 1)
    {
        int mid = (l + r) / 2;
        //増加量がmid以上の組み合わせが何個あるか
        auto check = [=](){
            ll cnt = 0;
            rep(i, n)
            {
                cnt += s[max(0ll, mid - a[i])];
            }
            return m <= cnt;
        };
        if(check())
        {
            l = mid;
        }else{
            r = mid;
        }
    }
    ll ans = 0;
    ll sum = 0;
    rep(i, n)
    {
        ll temp = s[max(0ll, l - a[i])];
        sum += temp;
        if(temp) ans += temp * a[i] + c[temp - 1];
    }
    ans -= l * (sum - m);
    cout << ans << endl;
}

Measured memory_bytes: 5760
#!/usr/bin/env python3
import bisect
import collections
import sys

sys.setrecursionlimit(1000000)
ACMOD = 1000000007
INF = 1 << 62


def solve(N: int, A: "List[int]", B: "List[int]"):
    for i, a in enumerate(A):
        b = B[i]
    ca = sorted(A)

    def get_middle(arr):
        if len(arr) % 2 == 1:
            return arr[(len(arr)) // 2]
        return (arr[len(arr) // 2 - 1] + arr[len(arr) // 2]) / 2

    cb = sorted(B)
    min_ = (get_middle(ca))
    max_ = (get_middle(cb))
    if N % 2:
        print(max_ - min_ + 1)
    else:
        print(int(2 * max_ - 2 * min_ + 1))

    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word

    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int()] * (N)  # type: "List[int]"
    B = [int()] * (N)  # type: "List[int]"
    for i in range(N):
        A[i] = int(next(tokens))
        B[i] = int(next(tokens))
    solve(N, A, B)


if __name__ == '__main__':
    main()


Measured memory_bytes: 28924
#include<stdio.h>


int main(void){
  int a,b;
  char c;
  
  while(1){
    scanf("%d %c %d",&a,&c,&b);

    if(c=='+'){
      printf("%d\n",a+b);
    }else if(c=='-'){
      printf("%d\n",a-b);
    }else if(c=='*'){
      printf("%d\n",a*b);
    }else if(c=='/'){
      printf("%d\n",a/b);
    }else{
      break;
    }
  }
}



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

int main() 
{
    long long int a,b,tempa,tempb,c = 0;
    cin>>a>>b;
    if((a-1)%4==0)
    {
    	tempa = a-1;
	}
	else if((a-1)%4==1)
	{
		tempa = 1;
	}
	else if((a-1)%4==2)
	{
		tempa = a;
	}
	else if((a-1)%4==3)
	{
		tempa = 0;
	}
	
	if(b%4==0)
    {
    	tempb = b;
	}
	else if(b%4==1)
	{
		tempb = 1;
	}
	else if(b%4==2)
	{
		tempb = b+1;
	}
	else if(b%4==3)
	{
		tempb = 0;
	}
	c = tempa^tempb;
   	cout<<c;
}

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


int main(){
    int n;
    cin>>n;
    
    map<int,int> mp;
    
    ll ans = 0;
    
    rep(i,n){
        int a;
        cin>>a;
        mp[a]++;
        ans += a;
    }
    
    int q;cin>>q;
    vector<ll> out(q);
    rep(i,q){
        int b,c;
        cin>>b>>c;
        if(mp.count(b)){
            if(!mp.count(c))mp[c]=0;
            mp[c] += mp[b];
            ans += mp[b] * (c-b);
            mp[b] = 0;
        }
        //cout << ans <<endl;
        out[i] = ans;
    }
    
    rep(i,q){
        cout <<out[i] << endl;
    }
    
    return 0;
}

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

int main()
{
    int h, w;
    cin >> h >> w;

    int S[h+2][w+2]; //四方を壁で囲む
    rep(i,h+2)rep(j,w+2) S[i][j] = -1;

    int id = 0;
    char ch;
    rep(i,h)rep(j,w) {
        cin >> ch;
        if (ch == '#') S[i+1][j+1] = -1;
        else S[i+1][j+1] = id;++id;
    }

    // 木を構成する
    vector<int> T[id]; // 道の数だけノードをもった木
    for (int i=1; i<=h ; i++) {
        for (int j=1; j<=w; j++) {
            if (S[i][j] == -1) continue;
            if (S[i][j-1] != -1) T[S[i][j]].push_back(S[i][j-1]);
            if (S[i][j+1] != -1) T[S[i][j]].push_back(S[i][j+1]);
            if (S[i-1][j] != -1) T[S[i][j]].push_back(S[i-1][j]);
            if (S[i+1][j] != -1) T[S[i][j]].push_back(S[i+1][j]);
        }
    }

    auto bfs = [&](int i){
        int D[id];
        rep(i,id) D[i] = -1;
        int maxd = 0;
        D[i] = 0;
        queue<int> que;
        que.push(i);
        while(!que.empty()) {
            int x = que.front(); que.pop();
            for (auto v : T[x]) {
                if (D[v] == -1) {
                    D[v] = D[x] + 1;
                    que.push(v);
                    maxd = max(maxd, D[v]);
                }
            }
        }
        return maxd;

    };

    // ノード毎にBFS
    int ans = 0;
    rep(i, id) {
        int tmpd = bfs(i);
        ans = max(tmpd, ans);
    }

    cout << ans << endl;
    
    return 0;
}

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

using namespace std;

#define ll long long
#define ull unsigned ll
#define all(x) x.begin(), x.end()

bool cmp(pair<int, pair<string, int>> &a, pair<int, pair<string, int>> &b)
{
    if (a.second.first == b.second.first)
        return a.second.second > b.second.second;
    return a.second.first < b.second.first;
}

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

    sort(all(v), cmp);

    for (auto x : v)
        cout << x.first << endl;
}

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

int n,m;
vector<int> G[1010];
vector<int> ans;
int inf = 1e9;

int main() {
    cin >> n >> m;
    for (int i = 0; i < m; i++) {
        int from, to;
        cin >> from >> to;
        G[from].push_back(to);
    }

    for (int i = 1; i <= n + 1; i++) ans.push_back(i);

    for (int i = 1; i <= n; i++) {
        pair<int,int> d[n+1];
        for (int j = 1; j <= n; j++) d[j] = {inf, -1};
        priority_queue<int,vector<int>,greater<int>> pq;
        for (int j = 0; j < G[i].size(); j++) {
            pq.push(G[i][j]);
            d[G[i][j]] = {1,i};
        }
        while (!pq.empty()) {
            int tp = pq.top();
            pq.pop();
            for (int j = 0; j < G[tp].size(); j++) {
                if (d[G[tp][j]].first > d[tp].first + 1) {
                    d[G[tp][j]].first = d[tp].first + 1;
                    d[G[tp][j]].second = tp;
                    pq.push(G[tp][j]);
                }
            }
        }
        if (d[i].second == -1) continue;
        vector<int> tmp;
        int k = i;
        while (1) {
            tmp.push_back(k);
            k = d[k].second;
            if (k == i) break;
        }
        reverse(tmp.begin(),tmp.end());
        if (tmp.size() < ans.size()) ans = tmp;
    }

    if (ans.size() > n) cout << -1 << endl;
    else {
        cout << ans.size() << endl;
        for (int i = 0; i < ans.size(); i++) {
            cout << ans[i] << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 256
x,n = map(int, input().split())

if n == 0:
    print(x)
elif n ==100:
    if x >50:
        print(101)
    else:
        print(0)
else:
    p = list(map(int, input().split()))
    d = []
    c=0
    for e in p:
        d.append(abs(e-x))
    d1 = d[0]
    z=p[0]
    for i in range(len(d)):
        if d[i] < d1:
            d1 = d[i]
            z = p[i]
    for j in range(1,100):
        for g in p:
            if z+j != g:
                c +=1
                w1 = z+j
        if c == n:
            break
        c = 0
    c=0
    for j2 in range(1,100):
        for g2 in p:
            if z-j2 != g2:
                c +=1
                w2 = z-j2
        if c == n:
            break
        c = 0
    if w2 < 0:
        print(w1)
    elif abs(w1-x) < abs(w2-x):
        print(w1)
    else:
        print(w2)

Measured memory_bytes: 9276
a,b=map(int,input().split())
p=a/0.08
q=(a+1)/0.08
r=b/0.1
s=(b+1)/0.1
Min=max(p,r)
Max=min(q,s)
if Min>=Max:
    print(-1)
else:
    print(int(-(-Min//1)))

Measured memory_bytes: 3064
import fractions
A, B, C, D = [int(x) for x in input().split()]
p = B//C - (A-1)//C
q = B//D - (A-1)//D
g = C*D // fractions.gcd(C, D)
r = B//g - (A-1)//g
cnt = B-A+1 - (p+q-r)
print(cnt)   


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

int main(){
  int n;
  int64_t count = 0;
  cin >> n;
  std::vector<int> a(n - 1);
  for (int i = 0; i < n - 1; i++) {
    std::cin >> a.at(i);
  }
  std::map<int, int> mp;
  for (int i = 0; i < n; i++) {
    mp[i] = 0;
  }
  for (int i = 0; i < n - 1; i++) {
    mp[a.at(i)]++;
  }
  for (int i = 1; i < n + 1; i++) {
    cout << mp[i] << endl;
  }
  return 0;
}



Measured memory_bytes: 13480
#include <iostream>
#include <string>
#include <map>
#include <queue>
#include <algorithm>
#include <vector>
#include <math.h>
#include <bitset>
#include <cmath>
#include <set>

#define rep(i,s,n)for(int i = s;i<n;i++)
#define repe(i,s,n)for(int i = s;i<=n;i++)
#define rep_r(i,s,n)for(int i = n-1;i>=s;i--)
#define rep_re(i,s,n)for(int i = n;i>=s;i--)
using namespace std;
typedef long long ll;
static const ll MOD = 1e9 + 7;
static const ll INF = 1e25;
static const ll MAX_N = 100001;

ll a[100001];
ll b[100001];
vector<pair<ll, ll>> v;
int  main() {
	ll n; cin >> n;
	repe(i, 1, n) cin >> a[i] >> b[i];
	repe(i, 1, n) {
		v.push_back({ a[i] + b[i],i });
	}

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

	ll ans = 0;
	ll i = 0;
	for (auto e : v) {
		if (i & 1) {
			ans -= b[e.second];
		}
		else {
			ans += a[e.second];
		}
		i++;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3956
#include <bits/stdc++.h>
#include <chrono>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repl(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define rep2l(i, s, n) for (ll i = (ll)(s); i < (ll)n; i++)

int main() {
    int x;
    cin >> x;
    if (x ==1) {
        cout << 0 << endl;
    }
    else {
        cout << 1 << endl;
    }
}

Measured memory_bytes: 3632
//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

const ll nmax = 1e9 + 7;
const ll Mod = 998244353;
const double PI = 2 * asin(1);

ll Pow(ll A, ll B, ll mod){
  if (B == 0) return 1;
  else{
    if (B % 2 == 0){
      return Pow(A * A % mod, B / 2, mod) % mod;
    }else{
      return A * Pow(A * A % mod, B / 2, mod) % mod;
    }
  }
}

ll nCr(ll N, ll R, ll mod){
  ll ans = 1; R = min(R, N - R);
  for (ll i = 1; i <= R; i++){
    ans *= N - i + 1; ans %= mod;
    ans *= Pow(i, mod - 2, mod); ans %= mod;
  }
  return ans;
}

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

  for (int i = 0; i < N; i++){
    int A; cin >> A;
    if (A % 2 != 0) continue;
    if (A % 3 == 0 || A % 5 == 0) continue;

    cout << "DENIED" << endl;
    return 0;
  }
  

  cout << "APPROVED" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = 0x3f3f3f3f;
const int N = 1e5 + 10;
const int MAX = 1e5 + 10;
const double exps = 1e-8;
#define swap(a, b)            \
    {                         \
        register int tmp = a; \
        a = b;                \
        b = tmp;              \
    }

inline int max(int a, int b) { return a > b ? a : b; }
inline int min(int a, int b) { return a > b ? b : a; }

int main() {
    int k;
    cin >> k;
    queue<ll> q;
    for (int i = 1; i <= 9; ++i) q.push(i);
    int cnt = 0;
    ll x;
    while (1) {
        x = q.front();
        q.pop();
        cnt++;
        if (cnt == k) break;
        if (x % 10 != 0) q.push(10 * x + x % 10 - 1);
        q.push(x * 10 + x % 10);
        if (x % 10 != 9) q.push(10 * x + x % 10 + 1);
    }
    cout << x;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (long long i = j; i < (long long)(n); i++)
#define _GLIBCXX_DEBUG
const ll MOD = 1000000007;
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; }
//(a+b-1)/b
//priority_queue<ll, vector<ll>, greater<ll>> q;


signed main(){
	//cout << fixed << setprecision(10);
	ll n; cin>>n;
	vl a(n);
	rep(i,0,n)cin>>a[i];
	sort(all(a));
	ll ans=0;
	rep(i,0,n-2){
		rep(j,i+1,n-1){
			rep(k,j+1,n){
				if(a[i]==a[j] || a[j]==a[k] || a[i]==a[k])continue;
				if(a[i]+a[j]>a[k])ans++;
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3632
from itertools import groupby, accumulate, product, permutations, combinations
def solve():
    ans = float('inf')
    D, G = map(int, input().split())
    P = [0]*D
    C = [0]*D
    for i in range(D):
        P[i],C[i] = map(int, input().split())
    for p in product([0,1],repeat=D):
        cnt = 0
        num = 0
        for i in range(D):
            if p[i]==1:
                cnt += 100*(i+1)*P[i]+C[i]
                num += P[i]
        if cnt<G:
            for i in range(D-1,-1,-1):
                if p[i]==0:
                    if (G-cnt+100*i)//(100*(i+1))<P[i]:
                        num += (G-cnt+100*i)//(100*(i+1))
                        break
            else:
                continue
        ans = min(ans,num)
    return ans
print(solve())

Measured memory_bytes: 3064
#include <boost/multiprecision/cpp_int.hpp>
#include <iostream>

using namespace std;
using namespace boost::multiprecision;

int main(void)
{
	int n;
	cin >> n;
	cpp_int a[n];
	cpp_int ans = 1;
	for (int i = 0; i < n; i++) {
		long long v;
		cin >> v;
		if (v == 0) {
			cout << 0 << endl;
			return 0;
		}
		a[i] = cpp_int(v);
	}

	for (int i = 0; i < n; i++) {
		ans *= a[i];
		if (ans > cpp_int(1e18L)) {
			cout << "-1" << endl;
			return 0;
		}
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 6332
L,R = (int(x) for x in input().split())
if R-L > 2019*2:
  R -= ((R-L)//2019-1)*2019
ans = 2019
for i in range(L,R):
  for j in range(i+1,R+1):
    ans = min(ans,(i*j)%2019)
print(ans)

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

using namespace std;
using ll = long long;
using ull = unsigned long long;
constexpr int inf = 1<<30;
constexpr int mod = 1e9+7;
constexpr ll infl = 1ll<<60;
vector<int> E[10];
int n,m;
int rec(int u,int pre,int state){
    if((state | 1<<u) == ((1<<n)-1))return 1;
    int ret = 0;
    for(auto v : E[u])if(pre != v and !((state & 1<<v))){
        ret += rec(v,u,state|1<<u);
    }
    return ret;
}
int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    
    cin>>n>>m;
    for(int i=0;i<m;++i){
        int a,b;
        cin>>a>>b;
        a--;b--;
        E[a].push_back(b);
        E[b].push_back(a);
    }
    cout << rec(0,-1,0) << endl;
    return 0;
}

Measured memory_bytes: 3704
#include<iostream>

using namespace std;

int main() {
	int n, count;
	while (std::cin >> n) {
		count = 0;
		for (int a = 0; a < 10; a++) {
			for (int b = 0; b < 10; b++) {
				for (int c = 0; c < 10; c++) {
					for (int d = 0; d < 10; d++) {
						if (a + b + c + d == n) {
							count += 1;
						}
					}
				}
			}
		}
		std::cout << count << std::endl;
	}
	return 0;
}


Measured memory_bytes: 3060
#include <iostream>
#include <string>
using namespace std;
 
int main(){
  
	string str,mei;cin>>str;
  	int n;cin>>n;
  
  	for(int i=0;i<n;i++){
    		cin>>mei;
      		if(mei=="print"){
           		int a,b;cin>>a>>b;
           		cout<<str.substr(a,b-a+1)<<endl;
           }else if(mei=="replace"){
           		int c,d;cin>>c>>d;
            	string p;cin>>p;
            	str.replace(c,d-c+1,p);
           }else if(mei=="reverse"){
           		int e,f;cin>>e>>f;
             	string q;
             	q=str.substr(e,f-e+1);
             	    for (int j=0;j<q.size();j++){
                		str.at(e+j)=q.at(q.size()-j-1);
                    }
            }
    }
  return 0;
}



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

int main() {
  int a,b;
  cin >> a >> b;
  string s;
  cin >> s;
  int n=s.size();
  int ans = 0;
  for(int i=0;i<n-1;i++){
    if(s.at(i) == s.at(i+1)){
      ans++;
    }
  }
  if(a-1 < ans + 2*b){
    cout << a-1 << endl;
  }
  else {
    cout << ans + 2*b << endl;
  }
  return 0;
  
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define For(i, a, b) for (int(i) = (int)(a); (i) < (int)(b); ++(i))
#define rFor(i, a, b) for (int(i) = (int)(a)-1; (i) >= (int)(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<lint, lint> pll;
template <class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T>
bool chmin(T &a, const T &b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T>
T div_floor(T a, T b) {
    if (b < 0) a *= -1, b *= -1;
    return a >= 0 ? a / b : (a + 1) / b - 1;
}
template <class T>
T div_ceil(T a, T b) {
    if (b < 0) a *= -1, b *= -1;
    return a > 0 ? (a - 1) / b + 1 : a / b;
}

constexpr lint mod = 1000000007;
constexpr lint INF = mod * mod;
constexpr int MAX = 200010;

vector<int> min_factor, prime;

void sieve(int n) {
    min_factor.resize(n + 1, 0);
    For(i, 2, n + 1) {
        if (min_factor[i] == 0) {
            min_factor[i] = i;
            prime.push_back(i);
        }
        for (int x : prime) {
            if (x * i > n || x > i) break;
            min_factor[x * i] = x;
        }
    }
}

vector<pii> prime_factor(int n) {
    vector<pii> ret;
    while (n > 1) {
        if (ret.empty() || ret.rbegin()->fi != min_factor[n]) {
            ret.emplace_back(min_factor[n], 1);
        } else
            ++ret.rbegin()->se;
        n /= min_factor[n];
    }
    return ret;
}

void divisor_dfs(vector<pii> &p, int t, int cur, vector<int> &ret) {
    if (cur == p.size()) {
        ret.push_back(t);
        return;
    }
    divisor_dfs(p, t, cur + 1, ret);
    rep(i, p[cur].se) {
        t *= p[cur].fi;
        divisor_dfs(p, t, cur + 1, ret);
    }
}

vector<int> get_divisor(int n) {
    vector<int> ret;
    auto p = prime_factor(n);
    divisor_dfs(p, 1, 0, ret);
    sort(ret.begin(), ret.end());
    return ret;
}

bool exist[1000010];

int main() {
    sieve(1000010);
    int n;
    scanf("%d", &n);
    int a[n];
    rep(i, n) scanf("%d", &a[i]);

    memset(exist, false, sizeof(exist));
    bool flag = true;
    rep(i, n) if (a[i] != 1) {
        auto v = prime_factor(a[i]);
        for (auto [x, t] : v) {
            if (exist[x]) {
                flag = false;
                break;
            }
            exist[x] = true;
        }
        if (!flag) break;
    }
    if (flag) {
        puts("pairwise coprime");
    } else {
        auto g = 0;
        rep(i, n) g = gcd(g, a[i]);
        puts(g == 1 ? "setwise coprime" : "not coprime");
    }
}

Measured memory_bytes: 12444
#include <cstdio>
#include <algorithm>

using namespace std;

int a[16][16];
long long sum[1 << 16];
long long dp[1 << 16];

int main() {
    int n, i, j, k;
    
    scanf("%d", &n);
    
    for (i = 0; i < n; i++) {
        for (j = 0; j < n; j++) {
            scanf("%d", &a[i][j]);
        }
    }
    
    for (i = 0; i < (1 << n); i++) {
        for (j = 0; j < n; j++) {
            for (k = j + 1; k < n; k++) {
                if (((i >> j) & 1) && ((i >> k) & 1)) sum[i] += a[j][k];
            }
        }
    }
    
    for (i = 0; i < (1 << n); i++) dp[i] = -1e18;
    
    dp[(1 << n) - 1] = 0;
    
    for (i = (1 << n) - 1; i > 0; i--) {
        int x;
        
        for (x = i; x > 0; x--) {
            x &= i;
            
            dp[i ^ x] = max(dp[i ^ x], dp[i] + sum[x]);
        }
    }
    
    printf("%lld\n", dp[0]);
    
    return 0;
}


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

int main(void){
    int X,A,B,C;
    cin  >> A >> B >> C >> X;
    int result = 0;
    for(int i = 0; i <= min(A,X/500) ; i++){
        for(int j = 0; j <= min(B,(X-500*i)/100); j++){
            if((X - 500*i - 100*j)%50 ==0 && (X - 500*i - 100*j)/50 <= C){
                result += 1;
            }
        }
    }

    cout << result << endl;
    return 0;
}

Measured memory_bytes: 256
import sys
from collections import Counter
from collections import deque
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))

s=list(input())
t=list(input())
t.pop()
if s==t:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 9332
#include<bits/stdc++.h>
using namespace std;
int n,m,s;vector<int> a;
int main()
{
	cin>>n>>m;
	for(int i=0;i<n;i++){
		int x;cin>>x;a.push_back(x);s+=x;
	}
	sort(a.begin(),a.end());reverse(a.begin(),a.end());
	int o=a[m-1];
	double y=s*1.0/(4*m);
	cout<<((double)o>=y?"Yes":"No");
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<queue>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<vector>
#define ll long long 
using namespace std;
string s1, s2;
ll s, t, l;
int main()
{
	ll x, y, temp;
	cin >> s >> t;
	cin >> s1;
	cin >> s2;
	x = max(s, t);
	y = min(s, t);
	while (y != 0)
	{
		temp = x % y;
		x = y;
		y = temp;
	}
	l = s * t / x;
		for (ll i = 0; i < x; i++)
			if (s1[(s / x)*i] != s2[(t / x)*i])
			{
				cout << "-1";
				goto here;
			}
	cout << l;
	here:
	return 0;
}

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

#define int long long int
#define fi first
#define so second
#define pii pair<int,int>
#define ps push_back
#define TT int tt;cin>>tt;for(int cc=1;cc<=tt;cc++)
vector<vector<char>> v;

int ans,k,n,m;

signed main()
{
    cin>>n>>m>>k;
    int i,j;
    for(i=0;i<n;i++)
    {
        v.ps(vector<char>(m));
        for(j=0;j<m;j++)
        {
            cin>>v[i][j];
        }
    }
    for(i=0;i<pow(2,n);i++)
    {
        for(j=0;j<pow(2,m);j++)
        {
            int row[n]={0},col[m]={0},ct=0;
            int t=i,l=0;
            while(t)
            {
                row[l]=t%2;
                l++;
                t/=2;
            }
            l=0;
            t=j;
            while(t)
            {
                col[l]=t%2;
                l++;
                t/=2;
            }
            for(int a=0;a<n;a++) for(int b=0;b<m;b++) if(row[a] && col[b] && v[a][b]=='#') ct++;
            if(ct==k) ans++;
        }
    }
    cout<<ans;
}


Measured memory_bytes: 4104
//#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please

const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	int A = 0;
	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}

int N;
int E[200001], n[200001], H[100001];
ll k[100001];
int D[100001];
ll dfs(int p, int mae, int d) {
	D[p] = d;
	ll kazu = 1;
	if (p == N) kazu += 1ll << 32;
	for (int i = H[p]; i; i = n[i]) if (E[i] != mae) kazu += dfs(E[i], p, d + 1);
	return k[p] = kazu;
}

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


	N = getint();
	int kari = 1;
	rep(i, N - 1) {
		int a = getint(), b = getint();
		E[kari] = b;
		n[kari] = H[a];
		H[a] = kari++;
		E[kari] = a;
		n[kari] = H[b];
		H[b] = kari++;
	}

	dfs(1, 0, 1);

	int kyori = (D[N] + 1) / 2;
	ll kotae = 0;
	rep1(i, N) if (k[i] > (1ll << 32) && D[i] > kyori) kotae = max(kotae, k[i] - (1ll << 32));

	if (N - kotae > kotae) printf("Fennec");
	else printf("Snuke");

	Would you please return 0;
}

Measured memory_bytes: 9600
N = int(input())
W = [input() for i in range(N)]
ans = True
for i in range(1, N):
    if W[i][0] != W[i-1][-1]:
        ans = False
for i in range(N):
    for j in range(i+1, N):
        if W[i] == W[j]:
            ans = False
if ans:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3060
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();// N枚
        int Y = sc.nextInt();// Y円

        int x = -1;// 10000円をx枚
        int y = -1;// 5000円をy枚
        int z = -1;// 1000円をz枚

        for (int i = 0; i <= N; i++) {
            for (int j = 0; j <= N; j++) {
                int tmpX = i;
                int tmpY = j;
                int tmpZ = N - (i+j);
                if (tmpZ < 0) break;

                int tmpSum = (10000 * tmpX) + (5000 * tmpY) + (1000 * tmpZ);
                if (tmpSum == Y) {
                    x = tmpX;
                    y = tmpY;
                    z = tmpZ;

                    break;
                }
            }
        }

        System.out.println(x + " " + y + " " + z);
    }
}


Measured memory_bytes: 23892
/*input

*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define eb emplace_back
#define pb push_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define EL cout<<'\n'
#define BS(a,x) binary_search(ALL(a),x)
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
	out<<'('<<P.F<<','<<P.S<<')';
	return out;
}
template<typename T>
ostream& operator<<(ostream& out,vector<T> V){
	REP(i,SZ(V)) out<<V[i]<<((i!=SZ(V)-1)?" ":"");
	return out;
}
//}}}
const ll maxn=300005;
const ll maxlg=20;
const ll INF64=1e18;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const ld PI=acos(-1);
const ld eps=1e-9;
//const ll p=880301;
//const ll P=31;

ll mypow(ll a,ll b){
	ll res=1LL;
	while(b){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		b>>=1;
	}
	return res;
}


int main(){
	IOS;
	int a,b;
  cin>>a>>b;
  cout<<6-a-b;
	return 0;
}


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

int a[12][12];
int dx[4]  = {1,0,-1,0};
int dy[4]  = {0,1,0,-1};
char dc[4] = {'R','D','L','U'};

//©ªÌüÍS}XÌÇÌóÔð²×é
void cheakWall(int* wall , const int& px ,const int& py ,const int& d ){
	for(int i=0 ; i<4 ; ++i ){
		int mx = px + dx[(d+i)%4];
		int my = py + dy[(d+i)%4];
		wall[i] = a[my][mx];
	}
}

//iñ¾ü«ðL^
void record(string& s,int* wall,const int d){
	if( wall[1] ){
		s.push_back( dc[d] );
	}
}

//iÞ
void go(int& px, int& py, const int& d,int* wall, string& s){
	px += dx[d]*2;
	py += dy[d]*2;
	record( s , wall , d );
}

int main(){
	string s;

	//zñÌú»
	for(int y=0 ; y<12 ; ++y )
		for(int x=0 ; x<12 ; ++x )
			a[y][x] = 0;

	//üÍ
	for(int i=0 ; i<9 ; ++i ){
		cin >> s;
		int y = i+1;
		int x = (i+1)%2 + 1;
		for(int j=0 ; j<(int)s.size() ; ++j , x+=2 ){
			a[y][x] = s[j] - '0';
		}
	}

	int px = 2, py = 0, d = 0;
	bool flag = false;
	s.clear();

	while( 1 ){
		if( px == 0 && py == 0 ) break;

		int wall[4]; 
		//©ªÌüèÌóÔ
		cheakWall( wall , px , py , d );

		if( !wall[1] ){//EªÇ¶áÈ©Á½ç
			//ü«ðEü«Éñé
			d = (d+1)%4;
			//iÞ
			go( px , py , d , wall , s );
			flag = false;
		}else{
			if( !wall[0] ){//OªÇ¶áÈ©Á½ç
				//iÞ
				go( px , py , d , wall , s );
				flag = false;
			}else{
				if( !wall[3] ){//¶ªÇ¶áÈ©Á½ç
					if( flag == false ){
						//iñ¾ü«ðL^
						record( s , wall , d );
					}
					//ü«ð¶ü«Éñé
					d = (d+3)%4;
					//iÞ
					go( px , py , d , wall , s );
					flag = false;
				}else{//OEEE¶ªÇ¾Á½ç
					flag = true;
					//iñ¾ü«ðL^
					record( s , wall , d );
					//ü«ðEü«Éñé
					d = (d+3)%4;
					//iñ¾ü«ðL^
					s.push_back( dc[d] );
				}
			}
		}
	}
	cout << s << endl;
}

Measured memory_bytes: 0
# Aizu Problem 0267: Triangle of Blocks

import sys, math, os, datetime

# read input:
PYDEV = os.environ.get('PYDEV')
if PYDEV=="True":
    sys.stdin = open("sample-input.txt", "rt")


def is_triangle(heights):
    if heights[0] != 1:
        return False
    L = len(heights)
    diffs = [heights[k] - heights[k-1] for k in range(1, L)]
    return diffs == [1] * (L - 1)


def solve(n, heights):
    steps = 0
    while steps < 10000:
        if is_triangle(heights):
            return steps
        L = len(heights)
        for k in range(L):
            heights[k] -= 1
        heights.append(L)
        while heights.count(0) > 0:
            del heights[heights.index(0)]
        steps += 1
    return -1

while True:
    n = int(input())
    if n == 0:
        break
    heights = [int(_) for _ in input().split()]
    print(solve(n, heights))

Measured memory_bytes: 8256
$n,$m = gets.chomp.split(" ").map(&:to_i)
edge = $m.times.map{gets.chomp.split(" ").map(&:to_i)}
$mtr = Array.new($n).map{Array.new($n,0)}
edge.each do |coo|
  $mtr[coo[0]-1][coo[1]-1] = 1
  $mtr[coo[1]-1][coo[0]-1] = 1
end
list = [0]
depth = 1
def dfs(list,depth)
  if depth == $n
    $count += 1
  end
  for i in 0..$n-1
    if $mtr[list[-1]][i] == 1 && !(list.include?(i))
      depth += 1
      list << i
      #p list,i
      dfs(list,depth)
      depth -= 1
      list.slice!(-1)
    end
  end
end
$count = 0
dfs(list,depth)
puts $count

Measured memory_bytes: 1788
//#include <bits/stdc++.h>
//#include <stdio.h>
#include<iostream>
#include<cstdio>
#include<bitset>
#include<algorithm>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<string>
#include<string.h>
#include<cmath>
#include<utility>
#include<functional>
#include<map>
#include<set>
#include<cctype>
#include<fstream>


#define FOR(i, a, b) for( int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for( int i=(a);i>=(b);i--)
#define LFOR(i, a, b) for( long long int i=(a);i<=(b);i++)
#define LRFOR(i, a, b) for(long long int i=(a);i>=(b);i--)
#define MOD 1000000007
#define INF 1000000000 //2000000000
#define LLINF 1000000000000000000 //9000000000000000000
#define PI 3.14159265358979
#define MAXI 7500000

using namespace std;
typedef long long int ll;
typedef pair< long long int, long long  int> P;

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



int main(void) {
	long long int n;
	long long int a[6];
	long long int total = 0;
	long long int mini = LLINF;

	cin >> n;
	FOR(i, 0, 4) {
		cin >> a[i];
		mini = min(mini, a[i]);
	}


	if (n%mini == 0) {
		total = n / mini;
	}
	else {
		total = n / mini;
		total++;
	}
	total += 4;

	cout << total << endl;



	return 0;
}

Measured memory_bytes: 384
#include<stdio.h>
int main(void)
{
	int N,M,ans,i;
	ans=0;
	scanf("%d %d",&N,&M);
	for(i=1;i<N;i++){
		ans+=i;
	}
	for(i=1;i<M;i++){
		ans+=i;
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 1700
#include <bits/stdc++.h>
#include <cstdlib>
#include <cmath>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
const ll INF=1e18 ;
inline void chmax(ll& a,ll b){a=max(a,b);}
inline void chmin(ll& a,ll b){a=min(a,b);}

int main() {
 ll s ;
 cin>> s ;
 ll mod =1e9 ;
 ll n = s/mod ;
 ll k= s%mod ;
if(s== 1e18)
cout <<0<<" "<<0<<" "<<0<<" "<<mod<<" "<<mod<<" "<<0<<endl;
else
cout <<n<<" "<<0<<" "<<0<<" "<<k<<" "<<n+1<<" "<<mod<<endl ; 
    return 0;
}

Measured memory_bytes: 256
// </> : towhid1zaman

#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair< int, int > pii;
typedef pair< pii, int > ppi;
#define fill(a,b) memset(a,b,sizeof(a))
#define all(v) (v).begin(),(v).end()
#define sp(k) cout<<setprecision(k)<<fixed;
#define rep(i,a) for(int i=0;i<a;i++)
#define rep1(i,a,b) for(int i=(a);i<=(b);++i)
#define irep(i,b,a) for(int i=(b);i>=(a);--i)
#define minv(v) *min_element(all(v))
#define maxv(v) *max_element(all(v))
#define unq(v) sort(all(v)),(v).erase(unique(all(v)),(v).end())
#define _ ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl "\n"
#define sqr(a) ((a)*(a))
#define sz(a) int(a.size())
#define ff first
#define ss second
#define pb push_back

const double pi = acos(-1.0);
const int mod = 1000000007; // (int)1e9+7
const int inf = 0x3f3f3f3f;
const int maxn = 2000100;



int main(){
        _
        string a,b; cin >> a >> b;
        for(int i=0,j=0; i<a.length() or j<b.length(); i++, j++){
            if(i<a.length() and j<b.length())cout<<a[i]<<b[i];
                else if(i>=a.length())cout<<b[i];
                else if(j>=b.length())cout<<a[i];
        }

return 0;
}



Measured memory_bytes: 256
#include "iostream"
using namespace std;

int main()
{
	int a, b, c;
	cin >> a >> b >> c;
	int i=0;
	for (int x = a; x <= b;x++){

		if(c%x==0){
			i++;
		}

	}
	cout << i << endl;

	return 0;
}



Measured memory_bytes: 3100
#include<iostream>
#include<stdio.h>
//#include <bits/stdc++.h>
#include<vector>
#include<float.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cstring>
#include<math.h>
#include<cmath>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include <cassert>
#include <cmath>
#include<cstdint>

#define INF 1e9
#define rep(i,n)for(int i=0;(i)<(int)(n);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
#define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define vec(type,n) vector<type>(n)
#define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
#define ALL(a)  (a).begin(),(a).end()

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<int,int>;

vector<int>bitSearch(int bit,int n){
    vector<int>S;
    rep(i,n)if(bit&(1<<i))S.push_back(i);
    return S;
}

int d[100][100];             //スタートからの距離を保存
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};


int main(){
   int h, w;
   cin >> h >> w;
   vector<string> field(h);
   rep(i, h)cin >> field[i];

   int cnt_b = 0;

   rep(i, h){
       rep(j, w){
           if(field[i][j] == '#')cnt_b++;
           d[i][j] = INF;
       }
   }

   queue<P> que;
   que.emplace(0, 0);
   d[0][0] = 1;

   while(!que.empty()){
       P p = que.front();que.pop();

       if(p.first == h - 1 && p.second == w - 1)break;

       rep(i, 4){
           int ny = p.first + dy[i];
           int nx = p.second + dx[i];

           if(nx < 0 || nx >= w || ny < 0 || ny >= h)continue;
           if(field[ny][nx] == '#')continue;
           if(d[ny][nx] != INF)continue;
           d[ny][nx] = d[p.first][p.second] + 1;
           que.emplace(ny, nx);
       }
   }
   if(d[h - 1][w -1] == INF)cout << -1 << endl;
   else cout << h * w - cnt_b - d[h - 1][w - 1] << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; ++i)
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define ALL(vec) vec.begin(), vec.end()
#define rALL(vec) vec.rbegin(), vec.rend()
using namespace std;
using ll = long long;

int main() {
    int n;
    cin >> n;
    vector<vector<int>> vec(n, vector<int>(n, 0));
    rep(i, n) {
        int u, k;
        cin >> u >> k;
        rep(j, k) {
            int v;
            cin >> v;
            vec[i][--v] = 1;
        }
    }
    rep(i, n) rep(j, n) {
        if (j != n - 1) cout << vec[i][j] << " ";
        else cout << vec[i][j] << endl;
    }
    return 0;
}


Measured memory_bytes: 3148
#pragma GCC optimize(3, "Ofast", "inline")
#include <bits/stdc++.h>
#define String std::string
#define fi first
#define se second
#define mp std::make_pair
#define Pair std::pair<int, int>
#define Map std::map< int, int >
#define Vector std::vector<int>

using std::cin;
using std::cout;
using std::endl;

typedef long long ll;
typedef unsigned long long ull;

const int N = 1000000 + 5;
const int M = 3000 + 5;
const int K = 1e7 + 5;
const int MOD = 1e9 + 7;
const int inv2 = 500000004;
const int dx[] = { 0, 1, -1, 0, 1, -1, 1, -1 };
const int dy[] = { 1, 0, 0, -1, 1, -1, -1, 1 };
const double PI = acos(-1);

template<class T>
inline T readT() {
    T res = 0, f = 1;
    char ch = getchar();
    for (; !isdigit(ch); ch = getchar()) if (ch == '-') f = -1;
    for (; isdigit(ch); ch = getchar()) res = (res << 1) + (res << 3) + ch - '0';
    return res * f;
}
#define read readT<int>

int n, a, b, c;
int ans = INT_MAX;
int w[10];

void dfs(int x, int sa, int sb, int sc, int ca, int cb, int cc) {
    if (x == n + 1) {
        if (!sa || !sb || !sc) return;
        ca += std::abs(sa - a);
        cb += std::abs(sb - b);
        cc += std::abs(sc - c);
        ans = std::min(ans, ca + cb + cc);
        return;
    }

    for (int i = 0; i <= 3; i++) {
        if (i == 0) dfs(x + 1, sa, sb, sc, ca, cb, cc);
        else if (i == 1) {
            int tmp;
            if (!sa) tmp = 0;
            else tmp = 10;
            dfs(x + 1, sa + w[x], sb, sc, ca + tmp, cb, cc);
        } else if (i == 2) {
            int tmp;
            if (!sb) tmp = 0;
            else tmp = 10;
            dfs(x + 1, sa, sb + w[x], sc, ca, cb + tmp, cc);
        } else {
            int tmp;
            if (!sc) tmp = 0;
            else tmp = 10;
            dfs(x + 1, sa, sb, sc + w[x], ca, cb, cc + tmp);
        }
    }
}

int main() {
    cin >> n >> a >> b >> c;
    for (int i = 1; i <= n; i++) cin >> w[i];
    dfs(1, 0, 0, 0, 0, 0, 0);
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define REP(i, n) rep(i, 0, n)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e12;

int change_to_i(string s){
   stringstream ss; int k;
   ss<<s; ss>>k;
   return k;
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s;
    cin >> s;
    int old = change_to_i(s);
    int n = s.size();
    string ans = "";
    int MAX = -1;
    vector<int> a(10);
    rep(i, 0, 10) a[i] = i;
    do{
        string snxt = ""; 
        rep(i, 0, n){
            snxt += '0' + a[i];
        }
        int nxt = change_to_i(snxt);
        int diff = min(abs(nxt - old), (int)pow(10, n) - abs(nxt - old));
        if(diff > MAX){
            MAX = diff;
            ans = snxt;
        }
    }while(next_permutation(all(a)));
    cout << ans << endl;
}


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

int main(){
  string A,B,C;
  cin >> A >> B >> C;
  int na,nb,nc;
  nb=nc=0;
  na=1;
  char X=A.at(0);
  while(true){
    if(X=='a'){
      na++;
      if(na==A.size() || A.size()==1){
        cout << "A" << endl;
        return 0;
      }
      else X = A.at(na);
    }
     else if(X=='b'){
      nb++;
      if(nb==B.size()){
        cout << "B" << endl;
        return 0;
      }
      else X = B.at(nb-1);
    } 
     else if(X=='c'){
      nc++;
      if(nc==C.size()){
        cout << "C" << endl;
        return 0;
      }
      else X = C.at(nc);
    } 
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) (v).begin(),(v).end()
#define out(a) cout << (a) << endl
using namespace std;
using ll = long long;
int main(){
    int n;
    ll maxi = 0;
    cin >> n;
    vector<ll> vec(n, 0);
    for(int i=0; i<n; i++) cin >> vec[i];

    for(int i=1; i<n; i++){
        maxi = max(maxi, vec[i]);
        if(vec[i] < maxi - 1){
            vec[i]--;
            if(vec[i] < maxi - 1){
                out("No");
                return 0;
            }
        }
    }
    out("Yes");
    return 0;
}

Measured memory_bytes: 1024
import sys
input = sys.stdin.readline
from collections import Counter, deque

INF = float('inf')


def gcd(a, b):
    """
    Greatest Common Divisor
    Euclidean Algortihm
    """
    if a < b:
        gcd(b, a)
    while b != 0:
        a, b = b, a % b
    return a


def lcm(a, b):
    """
    Least Common Multiple
    """
    return a * b // gcd(a, b)


def main():
    A, B = map(int, input().split())
    print(lcm(A, B))


if __name__ == '__main__':
    main()


Measured memory_bytes: 38256
#include <bits/stdc++.h>
#define rep(i, a, b) for(ll i = ll(a); i < ll(b); i++)
#define rer(i, a, b) for(ll i = ll(a) - 1; i >= ll(b); i--)
#define sz(v) (int)(v).size()
#define pb push_back
#define sc second
#define fr first
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
using namespace std;
typedef long long int ll;
int M,N,K;
ll A[100000];
ll dp[100000][300];
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>N>>M>>K;
    rep(i,0,N) cin>>A[i];
    rep(i,0,N) dp[i][1]=A[i];
    rep(j,2,K+1){
        deque<ll> d;
        ll m=0;
        rep(i,j-1,N){
            while(sz(d)&&dp[d.back()][j-1]<=dp[i-1][j-1]){
                d.pop_back();
            }
            d.push_back(i-1);
            if(i-M+1>=j-1){
                dp[i][j]=dp[d.front()][j-1]+A[i]*j;
                if(d.front()==i-M) d.pop_front();
            }
            else{
                m=max(m,dp[i-1][j-1]);
                dp[i][j]=m+A[i]*j;
            }
        }
    }
    ll M=0;
    rep(i,K-1,N) M=max(M, dp[i][K]);
    cout <<M<<"\n";
}

Measured memory_bytes: 235392
# 優先度付きキューで解く問題
# Atcoder abc123 D - Cake 123

X, Y, Z, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

import heapq
import sys

INT_MIN = -1 * sys.maxsize

a_cakes = A[:]
a_cakes = sorted(a_cakes, reverse=True)
b_cakes = B[:]
b_cakes = sorted(b_cakes, reverse=True)
c_cakes = C[:]
c_cakes = sorted(c_cakes, reverse=True)


checked_dict = {'0_0_0': True}

a = a_cakes[0]
b = b_cakes[0]
c = c_cakes[0]
value_list = [(-a-b-c, (0, 0, 0))]
heapq.heapify(value_list)

for _ in range(K):
    val = heapq.heappop(value_list)
    print(-1*val[0])
    #print(val)
    index = (val[1][0]+1, val[1][1], val[1][2])
    key = '{}_{}_{}'.format(*index)
    if not key in checked_dict:
        if not a_cakes[index[0]: index[0]+1]:
            continue
        checked_dict[key] = True
        a = a_cakes[index[0]]
        b = b_cakes[index[1]]
        c = c_cakes[index[2]]
        heapq.heappush(value_list, (-a-b-c, index))
        
    index = (val[1][0], val[1][1]+1, val[1][2])
    key = '{}_{}_{}'.format(*index)
    if not key in checked_dict:
        if not b_cakes[index[1]: index[1]+1]:
            continue
        checked_dict[key] = True
        a = a_cakes[index[0]]
        b = b_cakes[index[1]]
        c = c_cakes[index[2]]
        heapq.heappush(value_list, (-a-b-c, index))
        
    index = (val[1][0], val[1][1], val[1][2]+1)
    key = '{}_{}_{}'.format(*index)
    if not key in checked_dict:
        if not c_cakes[index[2]: index[2]+1]:
            continue
        checked_dict[key] = True
        a = a_cakes[index[0]]
        b = b_cakes[index[1]]
        c = c_cakes[index[2]]
        heapq.heappush(value_list, (-a-b-c, index))
        
    
    


    
    
    
    
    



Measured memory_bytes: 61656
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define ArraySizeOf(array)     (sizeof(array) / sizeof(array[0]))
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define _GLIBCXX_DEBUG
int INF = 1e9 + 7;
unsigned NthDayOfWeekToDay(unsigned n, unsigned dow, unsigned dow1)
{
    unsigned day;
    if (dow < dow1) dow += 7;
    day = dow - dow1;
    day += 7 * n - 6;
    return day;
}
unsigned DayToWeekNumber(unsigned day)
{
    return (day - 1) / 7 + 1;
}
unsigned AnotherDayOfWeek(unsigned day, unsigned day0, unsigned dow0)
{
    return (dow0 + 35 + day - day0) % 7;
}
using namespace std;
signed main() {
    int N;
    string S; cin >> N >> S;
    rep(i, S.size()) {
        if (int(S.at(i)) + N > 90)S.at(i) = char(int(S.at(i) + N - 26));
        else S.at(i)=char(int(S.at(i) + N));
        cout << S.at(i);
    }
    cout << endl;
}

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

int main() {
  int n, m, s=0;
  cin >> n >> m;

  for(int i=0; i<m; i++) {
    int a[m];
    cin >> a[i];
    s += a[i];
  }

  if(s>n) cout << "-1";
  else cout << n-s;

}

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

int c[3][3];

void solve()
{
    rep(i, 3) rep(j, 3) cin >> c[i][j];
    rep(x, 101)
    {
        if (x == 0)
            continue;
        if (x == 2)
            break;
        vector<int> a(3), b(3);
        rep(i, 3) a[i] = c[0][i] - x;
        rep(i, 3) b[i] = c[i][0] - a[0];
        bool ok = true;
        rep(i, 3) rep(j, 3)
        {
            if (a[j] + b[i] != c[i][j])
                ok = false;
        }
        if (ok)
        {
            cout << "Yes" << endl;
            return;
        }
    }
    cout << "No" << endl;
}

int main()
{
    solve();
    return 0;
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
#define MAX_N 100001
#define INF_INT 2147483647
#define INF_LL 9223372036854775807
#define REP(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
void init(int n);
int find(int n);
void unite(int x,int y);
bool same(int x, int y);
ll bpow(ll,ll,ll);
typedef vector<int> vec;
typedef vector<vec> mat;
mat mul(mat &A,mat &B);
mat pow(mat A,ll n);
int dx[3] = {1,0,-1};
int dy[3] = {1,0,-1};
const int MOD = 1000000007;

bool cmp_P(const P &a,const P &b){
  return a.second < b.second;
}
int main()
{
  ll a,b,x;
  cin >> a >> b >> x;
  cout << (b/x - (a%x ? a/x : a/x - 1)) << endl;
  return 0;  
}



Measured memory_bytes: 256