akhauriyash/Code-Regression huggingface dataset:
/*
 * atcoder/abc116_2nd/c.cpp
 */

// C++ 14
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstring> // memset
#include <cassert>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)
template <class T> bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false; }
template <class T> bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false; }

int N;
int H[101];

void solve() {
  cin >> N;
  loop(n,0,N) cin >> H[n];

  int count = H[0];
  loop(n,1,N) {
    if (H[n] > H[n-1]) count += H[n] - H[n-1];
  }
  cout << count << endl;
}
int main() {
  // cout.precision(15);
  // cout << fixed << double

  solve();

  return 0;
}


Measured memory_bytes: 256
from itertools import*
from math import*
from collections import*
from heapq import*
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf = 10**18
mod = 10**9+7
from functools import reduce
import sys
sys.setrecursionlimit(10**7)

#A+B+Cの美味しさがK番目以内ということはA+Bの美味しさがK番目以内である必要がある
#まずA+Bの美味しさをすべて求めて上からKを取り最後にCを加えたものをすべて考える

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()))
AB = []
for i in range(X):
    for j in range(Y):
        AB.append(A[i]+B[j])
AB.sort(reverse=True)
ABK = AB[:min(K,X*Y)]
D = []
for i in range(min(K,X*Y)):
    for j in range(Z):
        D.append(ABK[i]+C[j])
D.sort(reverse=True)
for i in range(K):
    print(D[i])

Measured memory_bytes: 147776
#include<bits/stdc++.h>
#define rep(i,a,...) for(int i = (a)*(strlen(#__VA_ARGS__)!=0);i<(int)(strlen(#__VA_ARGS__)?__VA_ARGS__:(a));++i)
#define per(i,a,...) for(int i = (strlen(#__VA_ARGS__)?__VA_ARGS__:(a))-1;i>=(int)(strlen(#__VA_ARGS__)?(a):0);--i)
#define foreach(i, n) for(auto &i:(n))
#define pii pair<int, int>
#define pll pair<long long, long long>
#define all(x) (x).begin(), (x).end()
#define bit(x) (1ll << (x))
using ll = long long;
//const ll MOD = (ll)1e9+7;
const ll MOD = 998244353;
const int INF = (ll)1e9+7;
const ll INFLL = (ll)1e18;
using namespace std;
template<class t>
using vvector = vector<vector<t>>;
template<class t>
using vvvector = vector<vector<vector<t>>>;
template<class t>
using priority_queuer = priority_queue<t, vector<t>, greater<t>>;
template<class t, class u> bool chmax(t &a, u b){if(a<b){a=b;return true;}return false;}
template<class t, class u> bool chmin(t &a, u b){if(a>b){a=b;return true;}return false;}
#ifdef DEBUG
#define debug(x) cout<<"LINE "<<__LINE__<<": "<<#x<<" = "<<x<<endl;
#else
#define debug(x) (void)0
#endif

namespace templates{
  ll modpow(ll x, ll b){
    ll res = 1;
    while(b){
      if(b&1)res = res * x % MOD;
      x = x * x % MOD;
      b>>=1;
    }
    return res;
  }

  ll modinv(ll x){
    return modpow(x, MOD-2);
  }

  bool was_output = false;
  template<class t>
  void output(t a){
    if(was_output)cout << " ";
    cout << a;
    was_output = true;
  }
  void outendl(){
    was_output = false;
    cout << endl;
  }
  ll in(){
    ll res;
    scanf("%lld", &res);
    return res;
  }

  template<class t>
  istream& operator>>(istream&is, vector<t>&x){
    for(auto &i:x)is >> i;
    return is;
  }

  template<class t, class u>
  istream& operator>>(istream&is, pair<t, u>&x){
    is >> x.first >> x.second;
    return is;
  }

  template<class t>
  void in(t&x){
    cin >> x;
  }

  template<class t>
  t in(){
    t res; cin >> res; return res;
  }

  template<class t>
  void out(t x){
    cout << x;
  }

  template<class t>
  vector<t> sorted(vector<t> line,function<bool(t,t)> comp=[](t a,t b){return a<b;}){
    sort(line.begin(),line.end(),comp);
    return line;
  }

  template<class t>
  vector<t> reversed(vector<t> line){
    reverse(line.begin(),line.end());
    return line;
  }
}

using namespace templates;

int func(int x){
  if(x%3==0)return 0;
  if(x%5==0)return 0;
  return x;
}

int main(){
  int n = in();
  ll ans = 0;
  rep(i,1,n+1){
    ans += func(i);
  }
  cout << ans << endl;

  return 0;
}


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

typedef long long ll;

const int Maxn = 200005;

int n;
int A[Maxn];
ll zer[Maxn], ev[Maxn], od[Maxn];
ll res;

int evCost(int a) { return a == 0? 2: bool(a % 2 != 0); }

int odCost(int a) { return bool(a % 2 != 1); }

int main()
{
    scanf("%d", &n);
    for (int i = 1; i <= n; i++)
        scanf("%d", &A[i]);
    for (int i = n - 1; i >= 0; i--) {
        zer[i] = A[i + 1] + zer[i + 1];
        ev[i] = min(zer[i], evCost(A[i + 1]) + ev[i + 1]);
        od[i] = min(ev[i], odCost(A[i + 1]) + od[i + 1]);
    }
    res = od[0];
    ll myzer = 0, myev = 0;
    for (int i = 1; i <= n; i++) {
        myzer = A[i] + myzer;
        myev = min(myzer, evCost(A[i]) + myev);
        res = min(res, myev + od[i]);
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 5760
import java.util.*;
import static java.lang.System.*;
import java.math.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] eat = new int[n];
		for(int i = 0; i < n; i++) {
			eat[i] = sc.nextInt();
		}
		int[] point = new int[n];
		for(int i = 0; i < n; i++) {
			point[i] = sc.nextInt();
		}
		int[] adp = new int[n-1];
		for(int i = 0; i < n-1; i++) {
			adp[i] = sc.nextInt();
		}
		int sum = 0;
		for(int i = 0; i < n; i++) {
			int eating = eat[i] - 1;
			sum += point[eating];
			if(i < n-1) {
				if((eat[i] + 1) == eat[i+1]) {
					sum += adp[eating];
				}
			}
		}
		out.println(sum);
	}
}

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

int main() {
	int num;
	cin >> num;
	if(num == 0){
		cout << 0;
		return 0;
	}
	int base = -2;
	vector<int> ans;
	while(num != 0){
		int res = num%base;
		num/=base;
		
		if(res < 0){
			res-= base;
			num++;
		}
		ans.push_back(res);
	}
	
	for(int i = ans.size() - 1; i >= 0; --i) cout << ans[i];
	
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<cctype>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<stack>
#include<queue>
#include<set>
using namespace std;
typedef long long ll;
const int inf=0x3f3f3f3f, mod=1000000007;
int n, b[500500], d[500500], ans[500500], pre[1001000];
struct node{int id, l, r;}a[500500];
bool cmp(node a, node b){return a.r<b.r;}
vector<int> vec1[500500], vec2[500500];
bool vis[1000500];

inline int read()
{
    int x=0,f=1;char ch=getchar();
    for (;ch<'0'||ch>'9';ch=getchar()) if (ch=='-') f=-1;
    for (;ch>='0'&&ch<='9';ch=getchar()) x=(x<<1)+(x<<3)+ch-'0';
    return x*f;
}

void add(int x, int t)
{
    for (; x<=n; x+=x&-x)
        d[x]+=t;
}

int sum(int x)
{
    int t=0;
    for (; x>0; x-=x&-x)
        t+=d[x];
    return t;
}

int main()
{
    n=read(); int m=read();
    for (int i=1; i<=n; i++) b[i]=read();
    for (int i=1; i<=m; i++) 
        a[i].id=i, a[i].l=read(), a[i].r=read();
    sort(a+1, a+m+1, cmp);
    for (int i=1; i<=m; i++) 
        vec1[a[i].r].push_back(a[i].l),
        vec2[a[i].r].push_back(i);
    
    for (int i=1; i<=n; i++)
    {
        if (vis[b[i]]) 
            add(pre[b[i]], -1), add(i, 1), pre[b[i]]=i;
        else
            vis[b[i]]=true, add(i, 1), pre[b[i]]=i;
        for (int j=0; j<vec1[i].size(); j++)
        {
            int id=vec2[i][j];
            ans[a[id].id]=sum(a[id].r)-sum(a[id].l-1);
        }
    }
    for (int i=1; i<=m; i++) printf("%d\n",ans[i]);
    return 0;
}

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

#define rep(i,n) for(int i=0; i<(n); ++i)
#define rrep(i,n) for(int i=1; i<=(n); ++i)
#define drep(i,n) for(int i=(n)-1; i>=0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define fi first
#define se second
#define v(T) vector<T>
#define imposs {cout<<"-1\n";return 0;}
#define LL_MAX LLONG_MAX
#define LL_MIN LLONG_MIN

typedef unsigned int uint;
typedef long long int ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int,int> pii;
typedef vector<pii> vpii;
typedef set<int> si;
typedef multiset<int> msi;
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}

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

  int H, W, A, B;
  cin >> H >> W >> A >> B;
  rep(i,H) {
    rep(j,W) {
      cout << ((i<B)^(j<A)) ? '1' : '0';
    }
    cout << '\n';
  }
  return 0;
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) begin(a),end(a)
#define MS(m,v) memset(m,v,sizeof(m))
#define D10  fixed<<setprecision(5)
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<short, short> P;
typedef complex<double> Point;
typedef long long ll;
const int INF = 114514810;
const int MOD = 100000007;
const double EPS = 1e-10;
const double PI = acos(-1.0);
struct edge
{
	int from, to, cost;
	bool operator < (const edge& e) const { return cost < e.cost; }
	bool operator > (const edge& e) const { return cost > e.cost; }
};

int m, t, p, r;
struct data{ int sol, pe, team; };
bool comp(const data& d1, const data& d2)
{
	if (d1.sol != d2.sol) return d1.sol > d2.sol;
	else if (d1.pe != d2.pe) return d1.pe < d2.pe;
	else return d1.team>d2.team;
}

int main()
{
	while (cin >> m >> t >> p >> r,m)
	{
		vector<data> v;
		REP(i, t)
		{
			v.push_back(data{ 0, 0, i });
		}
		vector<vi> res(t, vi(p));
		while (r--)
		{
			int a, b, c, d;
			cin >> a >> b >> c >> d;
			b--; c--;
			if (d == 0)
			{
				v[b].sol++;
				v[b].pe += a+res[b][c];
			}
			else
			{
				res[b][c] += 20;
			}
		}

		sort(ALL(v),comp);

		REP(i, t)
		{
			cout << v[i].team+1;
			if (i == t - 1) cout << endl;
			else if (v[i].sol == v[i + 1].sol&&v[i].pe == v[i + 1].pe) cout << "=";
			else cout << ",";
		}
	}
}

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

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

    string s, t;
    cin >> s >> t;

    int ans = 0;
    for (int i = 0; i < s.size(); i++) ans += s[i] != t[i];

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3796
from collections import deque

N,M = map(int, input().split())
ways = [[] for _ in range(N+1)]

for i in range(M):
    a,b = map(lambda x: int(x), input().split())
    ways[a].append(b)
    ways[b].append(a)

dq = deque([1])
sign = [None] * (N+1)
sign[0] = 0
sign[1] = 0

while(dq):
    now = dq.popleft()
    for w in ways[now]:
        if not sign[w]:
            sign[w] = now
            dq.append(w)

if None in sign:
    print("No")
else:
    print("Yes")
    for i in range(2, N+1):
        print(sign[i])


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

using namespace std;
typedef long long ll;
typedef pair<ll, ll> pii;
const ll inf = 1e6+5;
typedef pair<int, bool> pib;

int main() {
    int n,m; cin >> n >> m;
    if (n < m){
        cout << 0;
    }
    else{
        cout << 10;
    }
}



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

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

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define FORR(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--)

#define DEBUG(x) cout << #x << ": " << (x) << endl
#define DEBUG_VEC(v)                               \
  cerr << #v << ": ";                              \
  REP(__i, (v).size()) cerr << ((v)[__i]) << ", "; \
  cerr << endl
#define PRINT(x) cout << x << endl
#define all(x) x.begin(), x.end()
#define MM << " " <<
int main() {
  string s;
  cin >> s;

  if (s == "ABC") {
    cout << "ARC" << endl;
  } else {
    cout << "ABC" << endl;
  }
}


Measured memory_bytes: 3632
w,a,b = map(int,input().split())
if a <= b and b <= a+w:
    print("0")
elif a <= b+w and b+w <= a+w:
    print("0")
elif a+w < b and a+w < b+w:
    print(abs(b - (a+w)))
elif b+w < a and b < a:
    print(a - (b+w)) 

Measured memory_bytes: 3060
N=int(input())
A=list(map(int,input().split()))
B=[0 for i in range(N-1)]
for i in range(N-1):
  if A[i]<A[i+1]:
    B[i]=1
B=[0]+B
money=1000
tmp=0
up=[]
down=[]
for i in range(N-1):
  if B[i]==0 and B[i+1]==1:
    up.append(i)
  if B[i]==1 and B[i+1]==0:
    down.append(i)
import bisect   
if up:
  if down==[]:
    down.append(N-1)
  if down!=[] and down[-1]<up[-1]:
    down.append(N-1)

for i in range(len(up)):
  k=bisect.bisect_left(down,up[i])
  money+=(A[down[k]]-A[up[i]])*(money//A[up[i]])     
print(money)



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

using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
using pll = pair<ll, ll>;
using vl = vector<ll>;
using vll = vector<vl>;
using vpll = vector<pll>;
struct Edge {
	ll from;
	ll to;
	ll cost;
};
using Graph = vector<vector<Edge>>;

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define ALL(a) (a).begin(), (a).end()
#define RES(a, n) (a).resize(n)
/***** define constant start *******/
const ll MOD = 1000000007;
const double PI = 2.0 * asin(1.0);
const ll INF = 1L<<60;
string abc = "abcdefghijklmnopqrstuvwxyz";
string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const ll MAX = (ll)pow(10,7);
/****** define constant end ********/
/****** define variable start ******/
ll n;
/******* define variable end *******/
int solve() {
	cin >> n;
	for(ll i = 0;;i++){
		if(1000 * i >= n){
			cout << 1000 * i - n << endl;
			return 0;
		}
	}
	return 0;
}

int main() {
	//clock_t start = clock();
	cout << std::fixed << std::setprecision(10);
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int end_solve = solve();
	/*
	clock_t end = clock();
	const double time = static_cast<double>(end - start) / CLOCKS_PER_SEC *
	1000.0; printf("time %lf[ms]\n", time);
	*/

	return end_solve;
}


Measured memory_bytes: 3640
def main():
    N, M, X = map(int, input().split())
    C = []
    A = []
    for n in range(N):
        ls = list(map(int, input().split()))
        C.append(ls[0])
        A.append(ls[1:])

    result = -1
    for i in range(1 << N):
        t = [0] * M
        c = 0
        for j in range(N):
            if i & (1 << j):
                c += C[j]
                for k in range(M):
                    t[k] += A[j][k]

            if all(x >= X for x in t):
                if result == -1:
                    result = c
                else:
                    result = min(result, c)

    print(result)


if __name__ == "__main__":
    main()


Measured memory_bytes: 69824
N = int(input())
h = list(map(int,input().split()))
if N == 1:
	print("Yes")
	exit()
ans = 0
for i in range(N-1):
	if h[N-1-i-1] > h[N-1-i]+1:
		print("No")
		exit()
	elif h[N-1-i-1] == h[N-1-i]+1:
		h[N-1-i-1] -= 1
print("Yes")

Measured memory_bytes: 14396
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <random>

using namespace std;

const long long MOD = 998244353;

int main(){
    string a, b, c;
    cin >> a >> b >> c;
    if(a[a.size()-1] == b[0] && b[b.size()-1] == c[0]){
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
   int n;
   cin>>n;
   long long a[n];
   for(int i=0;i<n;i++)
   {
      cin>>a[i];
   }
   int ans=0;
   sort(a,a+n);
   for(int i=0;i<n-2;i++)
    for(int j=i+1;j<n-1;j++)
       for(int k=j+1;k<n;k++)
       {
         if(a[i]!=a[j]&&a[i]!=a[k]&&a[j]!=a[k])
          if(a[i]+a[j]>a[k])
           ans++;
       }
       cout<<ans<<endl;
   return 0; 
}

Measured memory_bytes: 3636
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
int main()
{
  int n,m;
  cin >> n >> m;
  vector<queue<int>> q(n);
  rep(i,n){
    rep(j,m){
      int a;
      cin >> a;
      q[i].push(a);
    }
  }
  
  int res=400;
  set<int> st;
  rep(I,m){
    map<int,int> mp;
    rep(i,n){
      while(st.find(q[i].front())!=st.end()){
	q[i].pop();
      }
      mp[q[i].front()]++;
    }
    int mx=0;
    int nax;
    for(auto it=mp.begin();it!=mp.end();++it){
      if(mx<it->second){
	mx = it->second;
	nax = it->first;
      }
    }
    res = min(res,mx);
    st.insert(nax);

  }
  cout << res << "\n";
  return 0;
}


Measured memory_bytes: 768
#include<cstdio>
#include <iostream>
#include<sstream>
#include<fstream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<complex>
#include <cstring>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<numeric>
#include<limits>
#include<climits>
#include<cfloat>
#include<functional>
#include<iterator>
#include <random>
#define inf  1000000000
#define mod  1073741824
#pragma GCC optimization ("O3")
using namespace std;
const long long int N = 6999999;
#define all(x) begin(x),end(x)
int main()
{
   
    // freopen("input.txt","r",stdin);
    // freopen("output.txt","w",stdout);
    //ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  	int n,b;
    cin >> n >> b;
    int dig = (int)(floor(log(n)/log(b)) + 1);
    cout << dig;
  	return 0;
}	

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

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

int main() {
  string S;
  cin >> S;
  vector<int> a(S.size()), ans(S.size());
  for(int i=0, b=0; i<S.size(); ++i) {
	if('L' == S[i]) a[i] = b;
	else b = i;
  } // 0 0 1 0 3
  for(int i=S.size()-1, b=S.size()-1; i>=0; --i) {
    if('L' == S[i]) b = i;
    else a[i] = b;
  } // 2 2 1 4 3
  for(int i=0; i<S.size(); ++i) {
    if('L' == S[i]) {
	  if((i-a[i])%2) ++ans[1 + a[i]];
	  else ++ans[a[i]];
	}
	else {
	  if((a[i]-i)%2) ++ans[a[i] - 1];
	  else ++ans[a[i]];
	}
  }
  
  rep(i, S.size()) cout << ans[i] << " ";
  return 0;
}

Measured memory_bytes: 1408
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue> 
#include <stack>
#include <set>
#include <list>

using namespace std;
typedef long long ll;
#define rep(i, s, e) for (int(i) = (s); (i) <= (e); ++(i))
#define all(x) x.begin(),x.end()


int main()
{
	int n, m; cin >> n >> m;
	priority_queue<int> pq;
	rep(i, 0, n - 1)
	{
		int a; cin >> a;
		pq.push(a);
	}
	rep(i, 1, m)
	{
		pq.push(pq.top() / 2);
		pq.pop();
	}
	ll ans = 0;
	while (!pq.empty())
	{
		ll x = pq.top();
		ans += x;
		pq.pop();
	}
	cout << ans << endl;
}

Measured memory_bytes: 892
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int n,a[105][105];
ll val[200005],f[200005];
int main()
{
	scanf("%d",&n);
	for(int i=0;i<n;i++) for(int j=0;j<n;j++) scanf("%d",&a[i][j]);
	for(int i=1;i<=(1<<n)-1;i++)
	{
		for(int j=0;j<n;j++)
		{
			for(int k=j+1;k<n;k++)
			{
				if((i&(1<<j))&&(i&(1<<k))) val[i]+=a[j][k];
			}
		}
	}
	for(int i=1;i<=(1<<n)-1;i++)
	{
		for(int j=i;j;j=i&(j-1))
		{
			f[i]=max(f[i],f[i-j]+val[j]);
		}
	}
	printf("%lld\n",f[(1<<n)-1]);
	return 0;
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
const ll MOD = 1000000007;
const ll INF = 10000000000000000;
vector<int> x4 = {0, 1, 0, -1};
vector<int> y4 = {1, 0, -1, 0};
vector<int> x8 = {0, 1, 1, 1, 0, -1, -1, -1};
vector<int> y8 = {1, 1, 0, -1, -1, -1, 0, 1};
template<class T> inline bool chmin(T& a, T b){if (a>b){a = b; return true;}return false;}
template<class T> inline bool chmax(T& a, T b){if (a<b){a = b; return true;}return false;}
template<class T> inline T powerM(T a,T b){if (b==0) return 1;
  T tmp = powerM(a,b/2); if (b%2==0) return tmp*tmp%MOD; else return tmp*tmp%MOD*a%MOD; }


template<class T> struct edge {int from, to; T cost;};

int N,M; // 頂点数と辺数
const int MAX_M = 100000;

vector<vector<edge<int>>> es(MAX_M);

template<class T> T prim(int v){
  using Pi = pair<T, int>;
  T res = 0;
  vector<bool> used(MAX_M, false);
  priority_queue<Pi, vector<Pi>, greater<Pi>> pq;
  pq.push({0, 0});
  while (!pq.empty()){
    Pi p = pq.top(); pq.pop();
    if (used[p.second]) continue;
    used[p.second] = true;
    res += p.first;
    for (edge<T> &e : es[p.second]){
      if (!used[e.to]) pq.push({e.cost, e.to});
    }
  }
  return res;
}

int main() {
  cin >>N >>M;
  rep(i, M){
    int s,t,w; cin >>s >>t >>w;
    edge<int> e = {s, t, w};
    es[s].push_back(e);
    e = {t, s, w};
    es[t].push_back(e);
  }
  cout <<prim<int>(0) <<endl;
}



Measured memory_bytes: 10236
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int n;

int main(void){
	scanf("%d",&n);
	int ans=n/2;
	if(n%2==0){
		ans--;
	}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 764
#include <stdio.h>
#define MAX 100000
int main(){

  int i, count=0;
  int left, right, mid;
  int n, q;
  int S[MAX], T[MAX];

  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&S[i]);
  }
  scanf("%d",&q);
  for(i=0;i<q;i++){
    scanf("%d",&T[i]);
  }

  for(i=0;i<q;i++){
    left = 0;
    right = n;
    
    while(left<right){
      mid = (left + right)/2;
      if(T[i] == S[mid]){
	count++;
	break;
      }
      if(T[i] > S[mid]){
	left = mid + 1;
      }
      else right = mid;
    }
  }

  printf("%d\n",count);
  
  return 0;
}

Measured memory_bytes: 1192
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#define rep(i, n)   for(int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

int solve(int n, int k){
    static vector<int>visited(k, 0);
    static int ans = 0;
    n %= k;
    if(visited[n] == 0){
        visited[n]++;
        ans++;
        if(n == 0){
            return ans;
        }
        return solve(n*10+7, k);
    }else{
        return -1;
    }
}

int main(){
    int k;  cin >> k;
    cout << solve(7, k) << endl;
}


Measured memory_bytes: 7140
import sys
#import numpy as np

stdin = sys.stdin

ri = lambda: int(rs())
rl = lambda: list(map(int, stdin.readline().split())) # applies to numbers only
rs = lambda: stdin.readline().rstrip()  # ignore trailing spaces

N = ri()
A = [ri() for _ in range(N)]
x_to_i = {x:i for i, x in enumerate(sorted(A))}
rank = [x_to_i[x] for x in A]
answer = sum(i&1 and (i^x)&1 for i,x in enumerate(rank))
print(answer)


Measured memory_bytes: 19876
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
int n,a[333333],sum,c[333333],d[333333],ans=-1e17;
priority_queue<int,vector<int>,greater<int>>q;
priority_queue<int>Q;
signed main(){
	cin>>n;
	rep(i,3*n)cin>>a[i];
	rep(i,n){
		q.push(a[i]);
		sum+=a[i];
	}
	c[n-1]=sum;
	for(int i=n;i<=2*n;i++){
		int p=q.top();
		if(p<a[i]){
			q.pop();
			q.push(a[i]);
			sum+=a[i]-p;
		}
		c[i]=sum;
	}
	sum=0;
	for(int i=3*n-1;i>=2*n;i--){
		Q.push(a[i]);
		sum+=a[i];
	}
	d[2*n]=sum;
	for(int i=2*n-1;i>=n;i--){
		int p=Q.top();
		if(p>a[i]){
			Q.pop();
			Q.push(a[i]);
			sum+=a[i]-p;
		}
		d[i]=sum;
	}
	for(int i=n;i<=2*n;i++)ans=max(ans,c[i-1]-d[i]);
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 8308
#include<bits/stdc++.h>
#define maxn 100005
#define pii pair<int,int>
using namespace std;
int n;
map<int,int> cnt1,cnt2;
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> n;
	for(int i=0,val1,val2;i<n/2;i++) {
		cin >> val1 >> val2;
		cnt1[val1]++;
		cnt2[val2]++;
	}
	vector<pii> v1,v2;
	for(pii now : cnt1)
		v1.emplace_back(now);
	for(pii now : cnt2)
		v2.emplace_back(now);
	v1.emplace_back(pii{-1,0});
	v2.emplace_back(pii{-2,0});
	sort(v1.begin(),v1.end(),[=](pii a,pii b)->bool
	    {return a.second > b.second;});
	sort(v2.begin(),v2.end(),[=](pii a,pii b)->bool
	    {return a.second > b.second;});
	int ans = n;
	for(int i=0;i<2;i++)
		for(int j=0;j<2;j++)
			if(v1[i].first != v2[j].first)
				ans = min(ans,n-v1[i].second-v2[j].second);
	cout << ans << endl;
	return 0;
}

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

int main(){
  int N;
  cin >> N;
  vector<long long> a(N); 
  for(int i=0; i<N; i++) cin >> a.at(i);
  vector<long long> div(N);
  div.at(0)=a.at(0);
  for(int i=1; i<N; i++){
    div.at(i)=div.at(i-1)+a.at(i);
  }
  long long ans=100000000000001;
  for(int i=0; i<N-1; i++){
    ans = min(ans, abs(div.at(N-1)-div.at(i)-div.at(i)));
  }
  cout << ans << endl;
}

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

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

    n = n % 10;

    if (n == 3) {
        cout << "bon" << endl;
    }
    else if (n == 0 || n == 1 || n == 6 || n == 8) {
        cout << "pon" << endl;
    }
    else {
        cout << "hon" << endl;
    }
}

Measured memory_bytes: 3636
def isPrime(n):
    # 素数判定
    if n < 2:
        return False
    for i in range(2, n + 1):
        if n < i ** 2:
            break
        if n % i == 0:
            return False
    return True


def main():
    X = int(input())
    while True:
        if isPrime(X):
            print(X)
            break
        X += 1
    return


main()


Measured memory_bytes: 3060
# import numpy as np
import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial  # , gcd
from bisect import bisect_left, bisect_right  # bisect_left(list, value)

sys.setrecursionlimit(10 ** 7)
enu = enumerate
MOD = 10 ** 9 + 7


def input():
    return sys.stdin.readline()[:-1]


pl = lambda x: print(*x, sep="\n")

N, K = map(int, input().split())

com = combinations

res = 0
if K % 2 == 0:
    res += len(range(0 + K // 2, N + 1, K)) ** 3
    res += len(range(K, N + 1, K)) ** 3
else:
    res += len(range(K, N + 1, K)) ** 3
print(res)


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

int main() {
    ll a,b,c,k;
    cin>>a>>b>>c>>k;
    if(k<=a){
        cout<<k<<endl;
    }else if(k<=a+b){
        cout<<a<<endl;
    }else{
        cout<<a-(k-a-b)<<endl;
    }
}


Measured memory_bytes: 3636
#include <algorithm>
#include <array>
#include <cstddef>
#include <iostream>
#include <queue>
#include <stack>
#include <string>
#include <vector>

int main() {
  long long unsigned N, A, B;
  std::cin >> N >> A >> B;

  long long unsigned ans = 0;
  ans = A * (N / (A + B));
  N = N % (A + B);
  if (N >= A) {
    ans += A;
  } else {
    ans += N;
  }
  std::cout << ans << std::endl;
  return 0;
}


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


int main() {

    int n;
    cin>>n;
    
    string s;
    cin>>s;

    int k;
    cin>>k;


    char cwk=s.at(k-1);
    for(int i=0;i<n;i++){
        if(s.at(i)!=cwk)
            s.at(i)='*';
    }

    cout<<s<<endl;


    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#define REP(i, m, n) for(int i=int(m);i<int(n);i++)
#define EACH(i, c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s, e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

//#define LOCAL 1
#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR
#endif


//改造
typedef long long int ll;
using namespace std;


//ここから編集する
ll mod = 1000000007;


int main() {
    //入力
    int N, A, B;
    ll ans;

    cin >> N >> A >> B;
    if (A > B) {
        ans = 0;
    } else if (N == 1) {
        if (A == B) {
            ans = 1;
        } else {
            ans = 0;
        }
    } else if (N == 2) {
        ans = 1;
    } else {
        ans = (ll)(B - A)*(ll)(N - 2) + 1;
    }

    cout << ans << endl;

}


Measured memory_bytes: 256
// https://qiita.com/e869120/items/eb50fdaece12be418faa

#include <bits/stdc++.h>
#define REP(i, m, n) for(int (i) = (m); (i) < (n); ++i)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
using namespace std;
using Graph = vector<vector<int>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
typedef long long ll;
typedef pair<ll, ll> P;
const int INF = 1e9+7;
const ll LINF = 1LL<<60;

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

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

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

    Graph dist(h, vector<int>(w, -1));
    queue<pair<int, int>> que;
    que.push(pair<int, int>(0, 0));
    dist[0][0] = 1;

    while(!que.empty()) {
        pair<int, int> v = que.front();
        que.pop();

        rep(i, 4) {
            int nx = v.second + dx[i];
            int ny = v.first + dy[i];
            if (ny < 0 || ny >= h || ny < 0 || nx >= w) continue;
            if (S[ny][nx] == '#') continue;
            if (dist[ny][nx] != -1) continue;
            dist[ny][nx] = dist[v.first][v.second] + 1;
            que.push(pair<int, int>(ny, nx));
        }
    }

    int res;
    if (dist[h-1][w-1] == -1) res = -1;
    else {
        res = h * w - dist[h-1][w-1] - sumb;
    }

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
    char S[101];
    scanf("%s", S);
    
    int len = 0;
    while(S[len] != '\0'){
        len++;
    }

    int cnt = 0;
    for(int i=0; i<=len/2; i++){
        if(S[i] != S[len-1-i]){
            cnt++;
            S[i] = S[len-1-i];
        }
    }

    printf("%d", cnt);
    return 0;

}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define rep(i,n) for (int i=0; i<n; i++)
#define REP(i,x,n) for (int i=x; i<n; i++)
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using ll = long long;
const int mod =1'000'000'007;

int main(){
    int n;
    cin >> n;
    vi a(n);
    rep(i,n) cin >> a.at(i);

    ll ans = 0;
    rep(i,n-1){
        if (a.at(i) > a.at(i+1)){
            ans += a.at(i) - a.at(i+1);
            a.at(i+1) += a.at(i) - a.at(i+1);
        }
    }

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


Measured memory_bytes: 4036
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <string>
#include <map>

#define ll long long
#define REP(i,n) for(int i = 0; i < n; i++)
#define PI 3.141592653589
#define MOD 1000000007

using namespace std;

template<typename T> T gcd(T a, T b){return (a % b)? gcd(b, a % b) : b;}
template<typename T> T lcm(T a, T b){return a * b / gcd(a, b);}

void solve_76B(){
    int n, k;
    cin >> n >> k;
    int ans = 1;
    REP(i,n){
        if(ans > k) ans += k;
        else ans *= 2;
    }
    cout << ans << endl;
}

int main(void){
    solve_76B();
    
    return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

	private static FastScanner sc = new FastScanner();
	private static char[] op = {'N', 'W', 'W', 'W', 'N', 'N'};

	public static void main(String[] args) {

		int n = sc.nextInt();

		int[] num = new int[6];
		Dice[] dice = new Dice[n];

		for(int i=0; i<n; i++) {
			for(int j=0; j<num.length; j++) {
				num[j] = sc.nextInt();
			}

			dice[i] = new Dice(num);
		}

		for(int l=0; l<n-1; l++){
			for(int m=l+1; m<n; m++){
				if(l != m){
					for(int i=0; i<op.length; i++) {
						for(int j=1; j<=4; j++) {

							boolean flag = true;
							for(int k=0; k<num.length; k++) {
								if(dice[l].getNum(k) != dice[m].getNum(k)) {
									flag = false;
									break;
								}
							}

							if(flag) {
								System.out.println("No");
								return;
							}

							dice[m].spin();
						}

						dice[m].lotate(op[i]);
					}
				}
			}
		}



		System.out.println("Yes");

	}

	static class Dice {

		//0:?????¢???1:S??´??¢???2:E??´??¢???3:W??´??¢???4:N??´??¢???5:?????¢
		int[] num = new int[6];

		Dice(int[] num) {
			for(int i=0; i<num.length; i++){
				this.num[i] = num[i];
			}
		}

		int getNum(int idx){
			return num[idx];
		}

		void lotate(char direction) {
			int temp;
			switch(direction) {
			case 'N':
				temp = num[0];
				num[0] = num[1];
				num[1] = num[5];
				num[5] = num[4];
				num[4] = temp;
				break;

			case 'S':
				temp = num[0];
				num[0] = num[4];
				num[4] = num[5];
				num[5] = num[1];
				num[1] = temp;
				break;

			case 'W':
				temp = num[0];
				num[0] = num[2];
				num[2] = num[5];
				num[5] = num[3];
				num[3] = temp;
				break;

			case 'E':
				temp = num[0];
				num[0] = num[3];
				num[3] = num[5];
				num[5] = num[2];
				num[2] = temp;
				break;
			}
		}

		//????¨????????????????
		void spin() {
			int temp = num[1];
			num[1] = num[2];
			num[2] = num[4];
			num[4] = num[3];
			num[3] = temp;
		}

	}

	static class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException  e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }


}

Measured memory_bytes: 24908
#include<bits/stdc++.h>
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

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


	int N;
	cin >> N;
	double k = 0;

	rep(i, N) {
		double A;
		cin >> A;
		k += 1 / A;
	}

	cout << setprecision(12) << 1 / k << endl;

	Would you please return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<vector>
using namespace std;
 
int main() {
  int a,d=1;
  char b,c;
  cin>>a;
  cin>>c;
for(int i=1;i<a;i++){
  cin>>b;
  if(b!=c)d++;
  c=b;
}
  cout<<d;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys


def solve(X: int):
    ns = []
    for i in range(10000):
        ns.append(i**5)
    nsSet = set(ns)
    for bi in range(len(ns)):
        # assume a must be positive
        # print(f"assume b is {bi},b^5={ns[bi]},then A^5 must be {X+ns[bi]} or {X-ns[bi]}")
        if X+ns[bi] in nsSet:
            ai = ns.index(X+ns[bi])
            print(ai,bi)
            exit()
        if X - ns[bi] in nsSet:
            ai = ns.index(X - ns[bi])
            print(ai, -(bi))
            exit()
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    X = int(next(tokens))  # type: int
    solve(X)

if __name__ == '__main__':
    main()


Measured memory_bytes: 68936
#include <iostream>
#include <algorithm> 
#include <cmath>
//#include <bitset>
//#include <deque>
#include <iterator>
#include <map> 
//#include <queue>
//#include <stack>
#include <string>
#include <vector>
#include <array>
//#include <tuple>
//#include <unordered_map>
//#include <unordered_set>

using namespace std;

typedef long long ll;
struct __{__(){ios_base::Init i;ios_base::sync_with_stdio(0);cin.tie(0);}}__; 



int main() {
	vector<int> v(3);
	cin >> v[0] >> v[1] >> v[2];
	sort(v.begin(),v.end());
	v[0] += v[2] - v[1];
	int d = v[2] - v[1] + (v[2] - v[0])/ 2;
	if ((v[2] - v[0]) % 2 != 0) {
		d += 2;
	}  
	cout << d;
}












Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
ll ans = 0;
 
int main()
{
    ll n;
    cin >> n;
    vector<int> A(n);

    rep(i,n){
        cin >> A[i];
    }
    double bunshi=1;
    double bunbo=0.;
    rep(i,n){
        bunshi*=A[i];
    }
    rep(i,n){
        bunbo+=(bunshi/A[i]);
    }
    double ans=bunshi/bunbo;
    cout << ans << endl;

  return 0;
}


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

candidate = [[0], [1]]
while True:
    temp = []
    for c in candidate:
        temp.append(c + [0])
        temp.append(c + [1])
    candidate = temp
    if len(temp[0]) == N:
        break

ans = float('inf')
for c in candidate:
    if sum(c) != K:
        continue
    high = a[0]
    temp = 0
    for i, value in enumerate(c):
        if i == 0:
            continue
        if value == 1 and a[i] <= high:
            high += 1
            temp += high - a[i]
        high = max(high, a[i])


    ans = min(ans, temp)

print(ans)

Measured memory_bytes: 12660
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>
#include <bitset>
#include <time.h>
#include <tuple>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e12;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1

ll sq(ll num) { return num*num; }
ll mod_pow(ll x, ll n) {
	if (n == 0)return 1;
	if (n == 1)return x%MOD;
	ll res = sq(mod_pow(x, n / 2));
	res %= MOD;
	if (n % 2 == 1) {
		res *= x;
		res %= MOD;
	}
	return res;
}
ll mod_add(ll a, ll b) { return (a + b) % MOD; }
ll mod_sub(ll a, ll b) { return (a - b + MOD) % MOD; }
ll mod_mul(ll a, ll b) { return a*b % MOD; }

typedef pair<long long, long long> P;

int v, e, r;

struct edge {
	int to;			//?????????to
	long long cost;	//????????????cost
	edge(int _to, long long _cost) :to(_to), cost(_cost) {}
};
vector<edge> G[100010];	//??£??\?????????
long long d[100010];	//?§????r????????????????????¢

void dijkstra(int start) {
	//(d[i],i)????????¢???priority_queue?????????
	//d????°?????????????????????????
	priority_queue<P, vector<P>, greater<P>> que;	
	
	for (int i = 0; i < v; i++)d[i] = 1e12;
	d[start] = 0;				//?§????????????¢???0?????????
	que.push(P(d[r], r));	//?????\???????§????????????±???push

	while (!que.empty()) {
		P p = que.top();
		que.pop();
		int v = p.second;

		if (d[v] < p.first)continue;	//???????????¢?????´??°??§???????????¨???
		

		for (int i = 0; i < G[v].size(); i++) {
			edge e = G[v][i];
			//??????v????????????????????£??????????????¢?????´??°??§?????????,
			//?????\????????´??°?????????????????¢??¨??????????????¢???push
			if (d[e.to] > d[v] + e.cost) {
				d[e.to] = d[v] + e.cost;
				que.push(P(d[e.to], e.to));
			}
		}
	}
}

int main() {
	cin >> v >> e >> r;

	for (int i = 0; i < e; i++) {
		int s, t, d;
		cin >> s >> t >> d;
		G[s].push_back(edge(t, d));	//??????s????????????t????????????d???????????????
	}

	dijkstra(r);

	for (int i = 0; i < v; i++) {
		if (d[i] != 1e12)cout << d[i] << endl;
		else cout << "INF" << endl;
	}
}

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

int main (){
  int N, M;
  cin >> N >> M;
  
  int score=0, pena=0;
  vector<int> sco(N);
  vector<int> sco1(N);
  
  for(int i=0 ; i<M ; i++){
    int X;
    string Y;
    cin >> X >> Y;
    X--;
    if(Y =="WA" && sco.at(X)<=0)
      sco.at(X)--;
    else if(sco.at(X)<=0 && sco1.at(X)==0){
      score++;
      sco1.at(X)=1;
      sco.at(X)*=(-1);
    }
  }

    for(int i=0 ; i<N ; i++)
      if(sco.at(i)>0)
        pena+=sco.at(i);
    
    cout << score << " " << pena << endl;
}

Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;

#define MAX_N 120
#define MAX_D 8
#define MAX_C 40320

int dp[MAX_N][MAX_C];
vector<int> fact1[MAX_C];
int fact2[8][8][8][8][8][8][8];
int D[MAX_N], X[MAX_N], n, cnt, maxn;

void fact() {
	cnt = 0;
	vector<int> p = { 0,1,2,3,4,5,6,7 };
	vector<int> a;

	//fact1
	do {
		for (int i = 0; i < MAX_D; i++) {
			fact1[cnt].push_back(p[i]);
		}
		cnt++;
	} while (next_permutation(p.begin(), p.end()));

	//fact2
	for (int i = 0; i < MAX_C; i++) {
		a = fact1[i];
		fact2[a[0]][a[1]][a[2]][a[3]][a[4]][a[5]][a[6]] = i;
	}
}

int Non_dp() {
	int G[8], H, maxx = 0;
	for (int i = 0; i < n; i++){
		G[i] = i;
	}
	do {
		H = 0;
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				if (abs(i - j) <= D[i] && G[i] > G[j]) {
					H += X[i];
				}
			}
		}
		maxx = max(maxx, H);
	} while (next_permutation(G, G + n));
	return maxx;
}

void First_dp() {
	cnt = 0;
	vector<int>q = { 0,1,2,3,4,5,6,7 };
	int A[MAX_D], C[MAX_D];
	pair<int, int>B[MAX_D];
	//shori.
	do {
		memset(A, 0, sizeof(A));
		memset(C, 0, sizeof(C));

		for (int i = 0; i < MAX_D; i++){
			B[i].first = q[i];
			B[i].second = i;
		}
		sort(B, B + MAX_D);

		for (int i = 0; i < MAX_D; i++) {
			A[B[i].second] = 1;
			for (int j = 0; j < MAX_D; j++) {
				if (A[j] == 0 && abs(B[i].second - j) <= D[B[i].second]) { C[j] += X[B[i].second]; }
			}
		}
		for (int i = 0; i < MAX_D; i++) {
			dp[MAX_D - 1][cnt] += C[i];
		}
		cnt++;
	}while (next_permutation(q.begin(), q.end()));
}

void Second_dp() {
	vector<int>r;
	pair<int, int>S[7];
	int s[8];
	int E;
	int F;
	for (int i = 8; i < n; i++) {
		for (int j = 0; j < MAX_C; j++) {

			r = fact1[j];
			memset(s, 0, sizeof(s));

			//seiri.
			for (int k = 1; k < MAX_D; k++) {
				S[k - 1].first = r[k];
				S[k - 1].second = k - 1;
			}
			sort(S, S + MAX_D - 1);
			for (int k = 0; k < MAX_D - 1; k++) {
				s[S[k].second] = k + 1;
			}

			//dp.
			for (int k = 0; k < MAX_D; k++) {
				//i-komeno xiao wo itsu ireruka.
				for (int l = 0; l < MAX_D - 1; l++) {
					if (s[l] == k) {
						s[l]--;
					}
				}
				s[MAX_D - 1] = k;
				F = 0;
				for (int l = 0; l < MAX_D - 1; l++) {
					if (abs(l - 7) <= D[i] && s[l] >= k) {
						F += X[i];
					}
				}
				for (int l = 0; l < MAX_D - 1; l++) {
					if (abs(l - 7) <= D[i + l - 7] && s[l] <= k) {
						F += X[i + l - 7];
					}
				}
				E = fact2[s[0]][s[1]][s[2]][s[3]][s[4]][s[5]][s[6]];
				dp[i][E] = max(dp[i][E], dp[i - 1][j] + F);
			}

		}
	}
}

int main() {
	fact();
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> D[i];
	}
	for (int i = 0; i < n; i++) {
		cin >> X[i];
	}
	if (n < MAX_D) {
		cout << Non_dp() << endl;
	}
	else {
		First_dp();
		Second_dp();
		for (int i = 0; i < MAX_C; i++) {
			maxn = max(maxn, dp[n - 1][i]);
		}
		cout << maxn << endl;
	}
	return 0;
}

Measured memory_bytes: 25812
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

#define lp(i,n) for(int i = 0; i <n;i++)
#define range(i,a,b) for(int i = int(a);i <= int(b);i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define MP make_pair
#define sz(v) ((int)((v).size()))
typedef long long ll;
typedef unsigned long long ull;
template<class T> using ordered_set=tree<
T,
null_type,
less<T>,
rb_tree_tag,
tree_order_statistics_node_update>;
const ll MOD = 1e9 + 7;
const int OO = (int)1e6;
const int N = (int)4e4+5;

void init(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}
// int n,m,k;
// int col[N],row[N];
//  vector<int>a(n),b(m);
// void get_row(){
//       int start = 0,end=0;
//     while(idx<n){

//     }
// }
// void get_col(){
//     int start = 0,end=0;
//     while(idx<m){
//         range(i,idx,n-1){
//             if(!a[])idx++;
//         }
//     }
// }
int main() {
	#   ifdef LOCAL_PROJECT
        freopen("in.txt", "r", stdin);
    #   endif
    
    // scanf("%d %d %d",&n,&m,&k);
    // a=vector<int>(n),b=vector<int>(m);
    // range(i,0,n-1){
    //     scanf("%d",&a[i]);
    // }    
    // range(i,0,m-1){
    //     scanf("%d",&b[i]);
    // }
    // string s;
    // cin>>s;
    // bool ok = 0;
    // lp(i,sz(s)){
    //     if(s[i]-'0'==7)ok=1;
    // }
    // ok?puts("Yes"):puts("No");
    int n;
    cin>>n;
    ll sum = 0;
    for(int i=1;i<=n;i++){
        if(i%3&&i%5)sum+=i;
    }
    cout<<sum<<endl;
    return 0;
}

Measured memory_bytes: 3636
import java.util.*;

public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		List<Integer> list = new ArrayList<>();
		for(int i=0; i<n; i++){
			list.add(sc.nextInt());
		}
		list.sort((i1, i2) -> i2.compareTo(i1));
		int alice = 0, bob = 0;
		for(int i=0; i<n; i++){
			if(i % 2 == 0){
				alice += list.get(i);
			}else{
				bob += list.get(i);
			}
		}
		System.out.println(alice - bob);
	}
}


Measured memory_bytes: 35720