akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <unordered_map>

using namespace std;

int main() {
    int n;cin>>n;
    unordered_map<int,int> mp;
    for(int i=0;i<n;i++) {
        int x;cin>>x;
        mp[x]++;
    }
    int res=0;
    for(auto i:mp) {
        if(i.first <= i.second)
            res += i.second-i.first;
        else
            res += i.second;
    }
    cout<<res<<endl;
}

Measured memory_bytes: 4260
n = int(input())
a = list(map(int,input().split()))
amin = min(a)
before = 0
ans = amin
count = 0
for i in range(n):
    now = a[i]-amin
    if before - now < 0:
        count += abs(before - now)
    before = now
print(ans+count)

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

#define whole(f, x, ...)                                 \
  ([&](decltype((x)) whole) {                            \
    return (f)(begin(whole), end(whole), ##__VA_ARGS__); \
  })(x)

using namespace std;
using ll = long long;

void solve() {
  int n;
  cin >> n;

  set<string> s;

  for (int i = 0; i < n; i++) {
    string ss;
    cin >> ss;
    s.insert(ss);
  }
  cout << s.size() << endl;
}

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);

  solve();
  return 0;
}


Measured memory_bytes: 19276
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

typedef long long ll;
typedef uint64_t ull;
typedef pair<int, int> P;
constexpr double PI = 3.1415926535897932;   // acos(-1)
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)

template<typename Monoid>
struct SegmentTree{
    using F = function<Monoid(Monoid, Monoid)>;

    int sz;
    vector<Monoid> seg;

    const F f;      // モノイドに対して二項演算を行う関数オブジェクト
    const Monoid M1;

    SegmentTree(int n, const F f, const Monoid &M1) : f(f), M1(M1){
        sz = 1;
        while(sz < n)   sz <<= 1;
        seg.assign(2 * sz, M1);
    }

    void set(int k, const Monoid &x){
        seg[k + sz] = x;
    }

    void build(){
        for(int k = sz - 1; k > 0; --k){
            seg[k] = f(seg[k << 1], seg[k << 1 | 1]);
        }
    }

    void update(int k, const Monoid &x){
        k += sz;
        seg[k] = x;
        while(k >>= 1){
            seg[k] = f(seg[k << 1], seg[k << 1 | 1]);
        }
    }

    Monoid query(int a, int b){
        Monoid L = M1, R = M1;
        for(a += sz, b += sz; a < b; a >>= 1, b >>= 1){
            if(a & 1)   L = f(L, seg[a++]);
            if(b & 1)   R = f(seg[--b], R);
        }
        return f(L, R);
    }

    Monoid operator[](const int &k) const{
        return seg[k + sz];
    }
};

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

    int n;
    cin >> n;
    vector<P> h(n);
    vector<int> a(n);
    for(int i = 0; i < n; ++i){
        cin >> h[i].first;
        h[i].second = i;
    }
    for(int i = 0; i < n; ++i)  cin >> a[i];

    sort(h.begin(), h.end());
    SegmentTree<ll> dp(n + 5, [](ll a, ll b){return max(a, b);}, 0ll);
    for(int i = 0; i < n; ++i){
        int id = h[i].second;
        dp.update(id, dp.query(0, id) + a[id]);
    }
    cout << dp.query(0, n) << endl;
}

Measured memory_bytes: 6656
import java.util.*;
public class Main {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int d = sc.nextInt();
        System.out.println(Math.min(a, b) + Math.min(c, d));
    }
}

Measured memory_bytes: 21460
h, w = map(int, input().split())
a = [['#'] * (w + 2)] + [['#'] + list(input()) + ['#']
                          for _ in range(h)] + [['#'] * (w + 2)]
p = [(i, j) for i in range(1, h + 1) for j in range(1, w + 1) if a[i][j] == '#']
d = (-1, 0), (1, 0), (0, -1), (0, 1)
r = -1
while p:
    r += 1
    s = []
    for i, j in p:
        for di, dj in d:
            di += i
            dj += j
            if a[di][dj] == '.':
                a[di][dj] = '#'
                s.append((di, dj))
    p = s
print(r)


Measured memory_bytes: 133840
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define krep(i,k,n,m) for(int i=k;i<n;i+=m)
#define erep(i,k,n) for(int i=k;i<n;i++)
#define mod 1000000007;
//最大公約数
int gcd(int s,int b){
    if(b==0)return s;
    return gcd(b,s%b);
}
signed main(){
    int n,m;
    cin>>n>>m;
    cout<<n*m<<endl;
}



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

int main(){
int N,K;
  cin>>N>>K;
  vector<int>x(N);
 for(int i=0; i<N; i++){
  cin>>x[i];} 
 int sum=0; 
 for(int i=0; i<N; i++){ 
  if(x[i]<(K-x[i])){sum+=(x[i])*2;} 
  else{sum+=(K-x[i])*2;} 
 }
  cout<<sum<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>
#include <queue>
#include <string>

#define reps(i,s,n) for(int (i) = (s); (i) < (n); (i)++)
#define rep(i,n) reps(i,0,n)
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using vi = vector<int> ;
using vl = vector<ll>;

int main(){
    string s1,s2,s;
    cin >> s1 >> s2;
    s = s1 + s2;
    //cout << s << endl;

    int t =  stoi(s);
    for(int j = 1; j < 400; j++){
        if(j * j == t){
            cout << "Yes" << endl;
            return 0;
        }
    }

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


Measured memory_bytes: 3596
#include<bits/stdc++.h>
using namespace std;
int main(){
  long long n;cin >> n;
  long long a,b,c,d,e;
  cin >> a >> b >> c >> d >> e;
  long long minv=min({a,b,c,d,e});
  long long ans = ((n+minv-1)/minv)+4;
  cout << ans << endl;
}


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

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

int main(){
  ll n,k;
  cin >> n >> k;
  vector<ll> a(n);
  rep(i,n){
    cin >> a[i];
    a[i]--;
  }
  if(k <= n){
      ll ans = 0;
      rep(j,k){
          ans = a[ans];
      }
      cout << ans+1 << endl;
      return 0;
  }

  map<ll,ll> mp;
  ll  now = 0;
  ll s;
  ll t;
  rep(i,k){
      mp[now] = i;
      now = a[now];
      auto it = mp.find(now);
      if(it != mp.end()){
          s = it->first;
          t = i+1;
          break;
      }
  }
  map<ll,ll> mp2;
  ll now2 = s;
  ll s2;
  ll t2;
  rep(i,k){
      mp2[now2] = i;
      now2 = a[now2];
      auto it = mp2.find(now2);
      if(it != mp2.end()){
          s2 = it->first;
          t2 = i+1;
          break;
      }
  }

//   cout << s << t << endl;
//   cout << s2 << t2 << endl;
  
  k = (k-t)%t2;
  rep(i,k){
      s2 = a[s2];
  }
  cout << s2+1 << endl;

  return 0;
}

Measured memory_bytes: 21472
import re
import sys
sys.setrecursionlimit(10**6)


def main():
  s=input()
  if s == ".":
    return
  s=re.sub(r'[a-zA-Z .]+',"",s)
  while "()" in s or "[]" in s:
    s=s.replace("()","")
    s=s.replace("[]","")
  if s == "":
    print("yes")
  else:
    print("no")
  main()
  return

main()


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

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<ll> vll;

const int INF = 1e9 + 7;
const int MOD = 1e9 + 7;
const int MAXN = 1e6 + 3;

#define sortA(v) sort(v.begin(), v.end())
#define fill(a) memset(a, 0, sizeof(a))

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


void test() {
  
}   
 
int main ()     
{
    ios::sync_with_stdio(false);
    cin.tie(0);
 
    ll s = 0;
    string a;
    cin >> a;
    for(int i = 0; i < a.size(); i++) {
        s += a[i] - '0';
    }
    cout << (s % 9 == 0 ? "Yes" : "No") << endl;
}


Measured memory_bytes: 3724
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#define ll long long
#define inf 0x3f3f3f3f
#define maxn 710
inline ll read()
{
	ll x=0; char c=getchar(),f=1;
	for(;c<'0'||'9'<c;c=getchar())if(c=='-')f=-1;
	for(;'0'<=c&&c<='9';c=getchar())x=x*10+c-'0';
	return x*f;
}
inline void write(ll x)
{
	static char buf[20];
	int len=0;
	if(x<0)putchar('-'),x=-x;
	for(;x;x/=10)buf[len++]=x%10+'0';
	if(!len)putchar('0');
	else while(len)putchar(buf[--len]);
}
inline void writesp(ll x){write(x); putchar(' ');}
inline void writeln(ll x){write(x); putchar('\n');}
int mp[maxn][maxn];
int col[maxn];
int f[maxn],g[maxn];
int n,m;
int dfs(int now,int c,int& x,int& y)
{
	if(col[now]+c==0)return 0;
	else if(col[now])return 1;
	col[now]=c;
	x+=(c==1); y+=(c==-1);
	for(int i=1;i<=n;i++)
		if(mp[now][i]){
			if(!dfs(i,-c,x,y))return 0;
		}
	return 1;
}
int main()
{
	n=read(); m=read();
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)
			mp[i][j]=(i!=j);
	for(int i=1;i<=m;i++){
		int x=read(),y=read();
		mp[x][y]=mp[y][x]=0;
	}
	f[0]=1;
	for(int i=1;i<=n;i++)
		if(!col[i]){
			int x=0,y=0;
			if(!dfs(i,1,x,y)){
				puts("-1"); return 0;
			}
			for(int j=0;j<=n;j++){
				g[j]=0;
				if(j>=x)g[j]|=f[j-x];
				if(j>=y)g[j]|=f[j-y];
			}
			for(int j=0;j<=n;j++)
				f[j]=g[j];
		}
	int sz=n/2;
	while(!f[sz])--sz;
	writeln(sz*(sz-1)/2+(n-sz)*(n-sz-1)/2);
	return 0;
}

Measured memory_bytes: 2176
#include <stdio.h>

void Katsusando(int M, int N) {
  int i, j, K, food, A[M], B[M];
  for (i = 0; i < M; i++) {
    A[i] = 1;
  }
  for (i = 0; i < N && scanf("%d",&K); i++) {
    for (j = 0; j < M; j++) {
      B[j] = 0;
    }
    for (j = 0; j < K && scanf("%d",&food); j++) {
      B[food-1] = 1;
    }
    for (j = 0; j < M; j++) {
      if (!B[j]) {
        A[j] = 0;
      }
    }
  }
  for (i = 0, j = 0; i < M; i++) {
    if (A[i]) {
      j += 1;
    }
  }
  printf("%d",j);
}

int main(void) {
  int N, M;
  scanf("%d%d",&N,&M);
  Katsusando(M,N);
  return 0;
}

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

int main() {
  int n;
  ll k;
  cin>>n>>k;
  ll a[n];
  rep(i,0,n) cin>>a[i];
  ll s[n+1];
  s[0]=0;
  rep(i,0,n) s[i+1]=s[i]+a[i];
  ll t[n];
  rep(i,0,n+1) s[i]=(s[i]-i)%k;
  map<ll,ll> b;
  ll ans=0;
  rep(i,0,n+1){
    ans+=b[s[i]];
    b[s[i]]++;
    if(i+1-k>=0) b[s[i+1-k]]--;
  }
  cout<<ans<<endl;
}


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

using namespace std;
using ll = long long;
using vl = vector<ll>;
using pll = pair<ll, ll>;

#define rep(i, n) for (ll i = 0, xxx_rep_end = (n); i < xxx_rep_end; ++i)
#define all(x) (x).begin(), (x).end()

template <class T1, class T2>
inline void chmax(T1 &a, const T2 &b)
{
    if (a < b)
    {
        a = b;
    }
}
template <class T1, class T2>
inline void chmin(T1 &a, const T2 &b)
{
    if (a > b)
    {
        a = b;
    }
}

constexpr ll INF = 0x3f3f3f3f3f3f3f3fLL;

int main()
{
    string S, T;
    cin >> S >> T;

    ll S_len = S.size();
    ll T_len = T.size();

    ll ans = T_len;
    rep(i, S_len - T_len + 1)
    {
        ll tmp = 0;
        rep(j, T_len)
        {
            if (S[i + j] == T[j])
            {
                ++tmp;
            }
        }
        chmin(ans, T_len - tmp);
    }
    cout << ans << endl;
}

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

int n, m, L;
vector<pair<int, int>> adj[25];

void addEdge(int u, int v, int w) {
  ++m;
  adj[u].emplace_back(v, w);
}

int main() {
  ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  cin >> L;
  int r = 0;
  while (1 << (r + 1) <= L) ++r;
  n = r + 1;
  for (int i = 1; i < n; ++i) {
    addEdge(i, i + 1, 0);
    addEdge(i, i + 1, 1 << (i - 1));
  }
  int done = (1 << r) - 1;
  while (done < L - 1) {
    int t = 1;
    while (done + (1 << t) < L) ++t;
    addEdge(t, n, done + 1);
    done += 1 << (t - 1);
  }
  cout << n << " " << m << "\n";
  for (int i = 1; i <= n; ++i)
    for (auto &p: adj[i])
      cout << i << " " << p.first << " " << p.second << "\n";
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
void debug() {cout<<endl;}
template<typename T,typename... Args>
void debug(T x,Args... args) {cout<<x<<" ";debug(args...);}
#define forn(i,a,b) for(int i=a;i<b;++i)
#define pb push_back
#define F first
#define S second
#define endl "\n"
typedef long long ll;
typedef pair<int, int> pii;

const int N = 1005, M = 10005;
ll dp[N][M], inf = 1e18;
int n;

struct block{
  int w, s, v;
  bool operator < (const block &b)const{
    return w+s > b.w+b.s;
  }
};

vector<block> blocks;


ll f(int i, int j){
  if(j < 0)return -inf;
  if(i == n)return 0;
  ll &ans = dp[i][j];
  if(ans != -1)return ans;
  ans = 0;
  ans = max(ans, f(i+1, min(j-blocks[i].w, blocks[i].s))+blocks[i].v);
  ans = max(ans, f(i+1, j));
  return ans;
}




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

  int w, s, v;
  cin >> n;
  forn(i, 0, n){
    cin >> w >> s >> v;
    blocks.pb({w, s, v});
  }
  sort(blocks.begin(), blocks.end());
  memset(dp, -1, sizeof dp);
  ll mx = 0;
  forn(i, 0, n){
    mx = max(mx, f(i+1, blocks[i].s)+blocks[i].v);
  }
  cout << mx << endl;

}





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

int main(){
  int N;
  cin >> N;
  vector<int> X(N), Y(N), H(N);
  int t = -1;
  for(int i = 0; i < N; ++i){
    cin >> X[i] >> Y[i] >> H[i];
    if(H[i]) t = i;
  }
  for(int x = 0; x <= 100; ++x){
    for(int y = 0; y <= 100; ++y){
      int h = H[t] + abs(x-X[t]) + abs(y-Y[t]);
      bool f = true;
      for(int i = 0; i < N; ++i){
	if(H[i]){
	  int h_ = H[i] + abs(x-X[i]) + abs(y-Y[i]);
	  if(h != h_){
	    f = false;
	    break;
	  }
	}else{
	  int h_ = H[i] + abs(x-X[i]) + abs(y-Y[i]);
	  if(h > h_){
	    f = false;
	    break;
	  }
	}
      }
      if(f){
	cout << x << " " << y << " " << h << endl;
	return 0;
      }
    }
  }
  return 0;
}


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

bool solve(){
    int a,b;
    string s;
    cin>>a>>b>>s;
    if(s[a]=='-'){
        s[a] = '0';
        rep(i,a+b+1){
            if(!isdigit(s[i])){
                return false;
            }
        }
        return true;
    }
    return false;
}

int main(void){
    cout<<(solve()? "Yes" : "No")<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define dbug printf("I am here\n");
#define Fast ios_base::sync_with_stdio(false); cin.tie(0);
#define vs              v.size()
#define sot(v)        sort(v.begin(),v.end())
#define rev(v)        reverse(v.begin(),v.end())
#define ii                pair<int,int>
#define ll                long long
#define ull              unsigned long long
#define pb              push_back
#define mpp          make_pair
#define Okay         0
#define pi               3.14159

static ll int inf = 1e9;
const int cont = 10e5+10;
using namespace std;
bool ar[10];
int n,m;

bool wrong(int n){
    while(n>0){
        if(ar[n%10])return true;
        n/=10;
    }
    return false;
}


void solve(){
    int m,n;
    cin>>n>>m;
    for(int i=0; i<m;i++){
        int a;
        cin>>a;
        ar[a] = 1;
    }

   while(wrong(n)){
    n++;
   }
   cout<<n<<endl;
}

int main(){

solve();

	return Okay;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double ld;

#define for0(i, n) for (ll i = 0; i < (ll)(n); ++i) // 0 based indexing
#define for1(i, n) for (ll i = 1; i <= (ll)(n); ++i) // 1 based indexing
#define forc(i, l, r) for (ll i = (ll)(l); i <= (ll)(r); ++i) // closed interver from l to r r inclusive
#define forr0(i, n) for (ll i = (ll)(n) - 1; i >= 0; --i) // reverse 0 based.
#define forr1(i, n) for (ll i = (ll)(n); i >= 1; --i) // reverse 1 based

#define ff first
#define ss second
#define pb push_back

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	ll n;
	string s;
	ll ans =0;
	cin >> n >> s;
	forc(i,0,n-3){
		if(s[i] == 'A' && s[i+1] == 'B' && s[i+2] == 'C'){
			ans++;
		}
	}
	cout << ans <<endl;
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int a,b,x;
	scanf("%d",&a);
	scanf("%d",&b);
	
	if(a*b%2!=0) {
		printf("Yes\n");
	}
	else {
		printf("No\n");
	}
	return 0;
}
	
	

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

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<vii> vvii;

#define fastIO ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define forw(i,l,r) for(int i=(l);i<(r);i++)
#define forb(i,r,l) for(int i=(r);i>(l);i--)
#define log2i(x) 32 - __builtin_clz((x)) - 1
#define log2ll(x) 64 - __builtin_clzll((x)) - 1
#define Pi acos(-1.0)
#define sz(x) (int)x.size()
#define mt make_tuple
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()

const int N = 3007;
const ll M = 998244353;
int n,s;
int a[N];
ll dp[N][3];

int main() {
#ifndef ONLINE_JUDGE
    //freopen("test.inp","r",stdin);
    //freopen("test.out","w",stdout);
#endif
    fastIO;
    memset(dp,0,sizeof dp);
    dp[0][0]=1;
    cin >> n >> s;
    forw(i,0,n) cin >> a[i];
    forw(i,0,n) {
        forb(j,s-a[i],-1) {
            if(dp[j][0]) {
                dp[j+a[i]][0]=1;
                ll tmp=dp[j][1];
                if(j==0) tmp+=i+1;
                (dp[j+a[i]][1]+=tmp)%=M;
                (dp[j+a[i]][2]+=((n-i)*tmp)%M)%=M;
            }
        }
    }
    cout << dp[s][2];
    return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<iomanip>



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

using namespace std;
int a,b,c;

int main(){
  cin >> a >> b >> c;
  if(a==b&&b==c) cout << 1 << endl;
  else if(a==b) cout << 2 << endl;
  else if(a==c) cout << 2 << endl;
  else if(b==c) cout << 2 << endl;
  else cout << 3 << endl;
  
  return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define all(x) (x).begin,(x).end()

int main(){
  string s;
  cin >> s;
  sort(s.begin(),s.end());
  if(s[0] == s[1] && s[1] != s[2] && s[2] == s[3]){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 3632
#pragma region Macros

#include <bits/stdc++.h>

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((int)(x).size())
#define IN(x, a, b) x >= a and x < b

using namespace std;
using ll = long long;

template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename T> constexpr T INF = numeric_limits<T>::max() / 2;

#pragma endregion

template <typename T> struct edge {
  int src, to;
  T cost;
  edge(int to, T cost) : src(-1), to(to), cost(cost) {}
  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}
  edge &operator=(const int &x) {
    to = x;
    return *this;
  }
  operator int() const { return to; }
};

template <typename T> using Edges = vector<edge<T>>;
template <typename T> using WeightedGraph = vector<Edges<T>>;
using UnWeightedGraph = vector<vector<int>>;
template <typename T> using Matrix = vector<vector<T>>;

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

  int V, E;
  cin >> V >> E;
  UnWeightedGraph G(V);
  vector<int> deg(V);
  REP(i, E) {
    int s, t;
    cin >> s >> t;
    G[t].emplace_back(s);
    deg[s]++;
  }

  vector<bool> queued(V, false);
  queue<int> que;
  REP(i, V) {
    if (deg[i] == 0) {
      que.emplace(i);
      queued[i] = true;
    }
  }
  while (!que.empty()) {
    int v = que.front();
    que.pop();
    for (auto nv : G[v]) {
      --deg[nv];
      if (deg[nv] == 0) {
        que.emplace(nv);
        queued[nv] = true;
      }
    }
  }

  bool ans = false;
  REP(i, V) {
    if (deg[i] > 0) {
      ans = true;
      break;
    }
  }
  cout << (ans ? 1 : 0) << endl;

  return 0;
}


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

using namespace std;

long long a[100001];
vector <int> ans;

int main () {
	long long n, k;
	cin >> n >> k;
	long long id = 0;
	for (int i = 1;i <= n;i ++) {
		cin >> a[i];
	}
	for (int i = 1;i < n;i ++) {
		if (a[id] + a[id + 1] < a[i] + a[i + 1]) {
			id = i;
		}
	}
	if (a[id] + a[id + 1] < k) {
		cout << "Impossible";
		return 0;
	}
	cout << "Possible\n";
	for (int i = 1;i < id;i ++) cout << i << endl;
	for (int i = n - 1;i >= id + 1;i --) cout << i << endl;
	cout << id;
	return 0;
}

Measured memory_bytes: 1664
import sys;input=sys.stdin.readline
from heapq import *
def dijkstra(s,cost):
    d = [float("inf")] * NN
    used = [False] * NN
    d[s] = 0
    while True:
        v = -1
        for i in range(NN):
            if (not used[i]) and (v == -1):
                v = i
            elif (not used[i]) and d[i] < d[v]:
                v = i
        if v == -1:
            return d
        used[v] = True
        for j, c in cost[v]:
            d[j] = min(d[j],d[v]+c)

def dijkstra_heapq(s, cost):
    d = [float("inf")] * NN
    h = [(0, s)]
    d[s] = 0
    while h:
        vc, v = heappop(h)
#        print(h)
        if vc > d[v]:
            continue
        for j, c in cost[v]:
            if vc+c<d[j]:
                d[j] = vc+c
                heappush(h, (vc+c, j))
    return d

N,W,S = map(int,input().split())
V = 2500
NN = N*(V+1)

def enc(u, v):
    return u*NN + v

#print(NN)
cost = [[] for _ in range(NN)]
for i in range(W):
    x,y,z,u = map(int,input().split())
    x -= 1
    y -= 1
    for v in range(V+1):
        if v-z>=0:
            cost[x*(V+1)+v].append((y*(V+1)+v-z, u))
            cost[y*(V+1)+v].append((x*(V+1)+v-z, u))

for i in range(N):
    x, y = map(int, input().split())
    for v in range(V+1):
        cost[i*(V+1)+v].append((i*(V+1)+min(v+x, V), y))

S = min(V, S)
d = dijkstra_heapq(S,cost)
for i in range(1, N):
    print(min(d[i*(V+1):(i+1)*(V+1)]))


Measured memory_bytes: 119816
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <string>
#include <algorithm>
#include <cmath>
using ll = long long;
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
using P = pair<int, int>;

int main(){
  int n, m;
  cin >> n >> m;
  vector<vector<int>> ab(m);
  rep(i, n){
    int a, b;
    cin >> a >> b;
    a--;
    if (a < m) ab[a].push_back(b);
  }
  priority_queue<int> que;
  int ans = 0;
  rep(i, m){
    for(int x : ab[i]){
      que.push(x);
    }
    if (que.empty()) continue;
    ans += que.top();
    que.pop();
  }
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 8456
#include<bits/stdc++.h>
#define F first
#define S second
#define ll long long
#define pb push_back

using namespace std;

int x,ans;

int main()
{
    for (int i=1;i<6;i++)
    {
        cin >> x;
        if (x==0)ans=i;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3632
def F(A, B):
    tmp = A
    for i in range(A, B):
        tmp = tmp^(i+1)
    return tmp

def f(A):
    tmp = A%4
    if tmp == 0:
        ans = 0^A
    elif tmp == 1:
        ans = 1
    elif tmp == 2:
        ans = 1^A
    else:
        ans = 0
    return ans

def main():
    A, B = map(int, input().split())
    #print(F(A, B))
    ans = f(B)^f(A-1)
    print(ans)

if __name__ == "__main__":
    main()


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define int  long long int
#define mod 1000000000000007
#define pb push_back
#define mp make_pair
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
#define gcd __gcd
#define fastio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define all(i) i.begin(),i.end()
#define rep(i,a,b) for(int i=a;i<b;i++)
#define set_bit __builtin_popcount //gives number of set_bits
#define ff first
#define ss second
#define cases(t) int t;cin>>t; rep(casn,1,t+1)
#define el cout<<"\n";
#define deci(n) int n; scanf("%lld",&n);
#define decs(n) string n; cin>>n;
#define sz(v) v.size()
#define repit(m) for(auto it=m.begin();it!=m.end();it++)
// #define find(m,i) (m.find(i)!=m.end())
// #define find(m,i) (m.find(i)==m.end())
#define cYES cout<<"YES\n";
#define cNO cout<<"NO\n";
#define ins insert
#define imax 1000000000000000000
#define imin -1000000000000000000
// #define NP 50000
//  cerr << "\nTime : " << (double)clock() / (double)CLOCKS_PER_SEC << "s\n";
 
//  IIITA
//SUNEET KUMAR -->  ਸੁਨੀਤ
 
// scanning numbers extremely fast/////////
void fs(int &number)
{
    bool negative = false;
    register int c;
    number = 0;
    c = getchar();
    if (c=='-')
    {
        negative = true;
        c = getchar();
    }
    for (; (c>47 && c<58); c=getchar())
        number = number *10 + c - 48;
    if (negative)
        number *= -1;
}
// ========================================
int power(int a,int x)
{
        a%=mod;
    int res=1;
    while(x>0)
    {
        if(x&1)
        res=res*a%mod;
        a=a*a%mod;
        x>>=1;
    }
    return res;
}
int max(int a,int b)
{
    if(a>b)
    {
        return a;
    }
    else
    {
        return b;
    }
}
int min(int a,int b)
{
    if(a>b)
    {
        return b;
    }
    else
    {
        return a;
    }
}
int madd(int a,int b)
{
    int ans;
    ans=(a%mod+b%mod)%mod;
    return ans;
}
int mmult(int a,int b)
{
    int ans=1;
    ans=((a%mod)*(b%mod))%mod;
    return ans%mod;
}
int modinverse(int a)
{
    return power(a,mod-2);
}
 
void nhi_degi()
{
     int n,x;cin>>n;
     map<int,int>m;
     for(int i=2;i<=n;i++)
     {
        cin>>x;
        m[x]++;
     }
     for(int i=1;i<=n;i++)
     {
         cout<<m[i];el
     }
}
signed main()
{
    // cases(t)
    // {
        nhi_degi();
    // }
}

Measured memory_bytes: 16112
#include <bits/stdc++.h>
using namespace std;
main()
{
  string s;
  cin >> s;
  for (int i = 0; i < s.size();i++){
    for (int j = 0; j < s.size();j++){
      if(i!=j&&s[i]==s[j]){
        cout << "no" << endl;
        return 0;
      }
    }
  }
  cout << "yes" << endl;
}



Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
typedef unsigned int uint;
using namespace std;

typedef pair<ll,int> P;

map<ll,int> PrimeFact(ll N){
  map<ll,int> mp;

  while(1){
    bool isPrime = true;
    for(ll i = 2LL ; i*i <= N ; i++){
      if(N % i == 0LL){
        mp[i]++;
        N /= i;
        isPrime = false;
        break;
      }
    }
    if(isPrime){
      mp[N]++;
      break;
    }
  }

  return mp;
}

//===================================================

int main(){
  ll N,P;
  cin >> N >> P;

  map<ll,int> mp = PrimeFact(P);

  ll ans = 1LL;
  for(auto it = mp.begin() ; it != mp.end() ; it++){
    ll a = it->first;
    int cnt = it->second;

    while(cnt >= N){
      ans *= a;
      cnt -= N;
    }
  }

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


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

int N,M;
ll ans[200010];

int main() {
    cin >> N >> M;
    vector<pair<ll,pair<ll,ll> > > X;
    set<pair<ll,ll> > D;
    REP(i,N){
        int s,t,x;
        cin >> s >> t >> x;
        X.push_back(make_pair(x,make_pair(s-x,t-x)));
    }
    REP(i,M){
        int d;
        cin >> d;
        D.insert(make_pair(d,i));
        ans[i] = -1;
    }

    sort(X.begin(),X.end());

    REP(i,X.size()){
        if(D.empty()) break;
        // l <= start time < r の人は、xで止まる。
        ll x = X[i].first;
        ll l = X[i].second.first;
        ll r = X[i].second.second;

        auto itr = D.lower_bound(make_pair(l,-1));
        while(D.size() && itr != D.end() && (*itr).first < r){
            ans[(*itr).second] = x;
            D.erase(itr++);
        }
    }
    REP(i,M) cout << ans[i] << endl;
    return 0;
}

Measured memory_bytes: 21484
#include <iostream>

using namespace std;

int main() {
    int H, W;

    while (1) {
        cin >> H >> W;
        if (H == 0 && W == 0) break;
        else {
            for (int i = 0; i < H; i++) {
                for (int j = 0; j < W; j++) {
                    if (i == 0 || i == (H - 1)) {
                        cout << "#";
                    }
                    else if (j == 0 || j == (W - 1) ){
                        cout << "#";
                    }
                    else {
                        cout << ".";
                    }
                }
                cout << endl;
            }
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 3104
#include <bits/stdc++.h>
using namespace std;
#define r(i,a,n) for(int i=a;i<n;i++)
int main(){
	int a,ss=0,m=0;
	string s;
	cin>>a>>s;
	for(int i=0;i<s.size();i++){
		if(s[i]=='I')ss++;
		else ss--;
		m=max(m,ss);
	}cout<<m<<endl;
}

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

using namespace std;
#define DEBUG(x) cout<<#x<<": "<<x<<endl

#define PB push_back
#define MP make_pair
#define F first
#define S second
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define INT(a) int((a)+1e-9)
int DX[4]={1,0,-1,0};
int DY[4]={0,1,0,-1};

typedef pair<int,int> Pii;


#define SUPnl 100002

int nl;
Pii pt[SUPnl];	//pt[n].F == n's parent, pt[n].S == w[pt[n].F]-w[n]

void init(){REP(ni,nl){pt[ni]=MP(ni,0);}}

Pii getRoot(int n){
	if(pt[n].F==n) return pt[n];
	Pii rpnt = getRoot(pt[n].F);
	pt[n]= MP(rpnt.F, rpnt.S+pt[n].S);
	return pt[n];
}

void printW(int a, int b){
	Pii rat=getRoot(a); Pii rbt=getRoot(b);
	if(rat.F!=rbt.F) printf("UNKNOWN\n");
	else printf("%d\n", rbt.S - rat.S );
}

void setW(int a, int b, int w){
	Pii rat=getRoot(a); Pii rbt=getRoot(b);
	if(rat.F==rbt.F) return;
	if(rat.S+w>=rbt.S){
		pt[rbt.F]=MP(rat.F, rat.S+w-rbt.S);
	}else{
		pt[rat.F]=MP(rbt.F, rbt.S-w-rat.S);
	}
}

int main(){
	while(true){
		int ol;
		scanf("%d%d", &nl, &ol);
							if(!nl) return 0;
		init();
		REP(oi,ol){
			char ot; int a,b,w;
			scanf(" %c ", &ot);
			if(ot=='!'){
				scanf("%d%d%d",&a,&b,&w);
				setW(a-1,b-1,w);
			}
			if(ot=='?'){
				scanf("%d%d",&a,&b);
				printW(a-1,b-1);
			}
		}
	}
}

Measured memory_bytes: 3020
use std::io::*;
use std::str::FromStr;

fn main() {
    let s: Vec<char> = read::<String>().chars().collect();
    let t: Vec<char> = read::<String>().chars().collect();
    let mut stot = [30; 26];
    let mut ttos = [30; 26];
    let mut ok = true;
    for i in 0..s.len() {
        let mut si = (s[i] as u8 - 'a' as u8) as usize;
        let mut ti = (t[i] as u8 - 'a' as u8) as usize;
        if stot[si] == 30 {
            if ttos[ti] == 30 || ttos[ti] == si {
                stot[si] = ti;
                ttos[ti] = si;
            } else {
                ok = false;
                break;
            }
        } else {
            if stot[si] != ti || (ttos[ti] != 30 && ttos[ti] != si) {
                ok = false;
                break;
            } else {
                ttos[ti] = si;
            }
        }
    }
    println!("{}", if ok { "Yes" } else { "No" });
}

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}


Measured memory_bytes: 6396
#include <bits/stdc++.h>
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
#define lli long long int
#define uli unsigned long long int
#define INF 999999999999999999
#define rep(i,m,n) for(lli i = m;i < n;i++)
#define rrep(i,m,n) for(lli i=m-1;i>=n;i--)
#define pb(n) push_back(n)
#define UE(N) N.erase(unique(N.begin(),N.end()),N.end());
#define Sort(n) sort(n.begin(), n.end())
#define Rev(n) reverse(n.begin(),n.end())
#define Out(S) cout << S << endl
#define NeOut(S) cout << S
#define HpOut(S) cout << setprecision(25) << S << endl
#define Vec(K,L,N,S) vector<L> K(N,S)
#define DV(K,L,N,M,S) vector<vector<L>> K(N,vector<L>(M,S))
#define TV(K,L,N,M,R,S) vector<vector<vector<L>>> K(N,vector<vector<L>>(M,vector<L>(R,S)))
#define pint pair<lli,lli>
#define paf(L,R) pair<L,R>
#define mod 998244353
#define MAX 10000000
#define ALL(a)  a.begin(),a.end()
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  lli A,B,C,D,E,F,L,N,M,K,X,Y,Z,H,W,sum=0,num=0,flag=0;string S,T;
  cin >> X;
  rep(i,-3000,3000){
    lli A=pow(i,5);
    if(A<X){
      rep(j,-3000,0){
        if(A-pow(j,5)==X){
          cout << i << " " << j << endl;
          return 0;
      }
    }
  }
  else{
    rep(j,0,3000){
      if(A-pow(j,5)==X){
        cout << i << " " << j << endl;
        return 0;
      }
    }
  }
}
}

Measured memory_bytes: 4196
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        char[] str = sc.next().toCharArray();
        int l = -1;
        int r = -1;

        for(int i = 0 ; i < str.length-2 ; i++){
            if(str[i] == str[i+1]){
                l = i+1;
                r = i+2;
            }
            if(str[i] == str[i+2]){
                l = i+1;
                r = i+3;
            }
        }
        if(str[str.length-2] == str[str.length-1]){
            l = str.length-1;
            r = str.length;
        }

        System.out.println(""+l+" "+r);
    }
}


Measured memory_bytes: 27904
#include <bits/stdc++.h>
using namespace std;
#define REP(i, init, n) for(int i = (int)(init); i < (int)(n); i++)

#define vi vector<int>
#define vl vector<long>
#define vvi vector<vector<int>>
#define vvl vector<vector<long>>
#define pint pair<int, int>
#define plong pair<long, long>

int main() {
    int L;
    cin>>L;
    int N = 1, count = L;
    while(count > 0){
        N++;
        count /= 3;
    }
    vector<vector<int>> G;
    vi keta(N, 0), triple(N, 0);
    int i = 0, j = 1;
    REP(i, 0, N){
        keta[i] = L%3;
        triple[i] = j;
        L /= 3; j *= 3;     
    }
    reverse(keta.begin(), keta.end());
    int M = 0;
    REP(i, 0, N-2){
        REP(j, 0, 3){
            vi edge = {i+1, i+2, triple[i]*j};
            G.emplace_back(edge);
            M++;
        }
    }
    int max = 0;
    REP(i, 0, N){
        if(keta[i]){
            REP(j, 0, keta[i]){            
                vi edge = {N-i, N, max};            
                G.emplace_back(edge);
                max += triple[N-i-1];
                M++;
            }
        }
    }
/*
    cout << N << endl;
    REP(i, 0, N) cout << keta[i] << " ";
    cout << endl;
    */
    cout << N << " " << M << endl;
    for(auto x: G){
        for(auto y: x){
            cout << y << " ";
        }
        cout << endl;
    }
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
typedef long double ld;
const ll INF = 1e+14;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
 
void Yes(){
	cout<<"Yes"<<endl;
	exit(0);
}
 
void No(){
	cout<<"No"<<endl;
	exit(0);
}

int main(){
  
  int N,A,B;
  cin>>N>>A>>B;
  int ans=min(N*A,B);
  cout<<ans<<endl;
}
  

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

int main() {
int a,b;
cin>>a>>b;
if(a>b){
    for(int i=0;i<a;i++){
        cout<<b;
    }
}
else{
for(int i=0;i<b;i++){
    cout<<a;
}
}
return 0;
}


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

int N;
const int MOD = 1e9+7;
vector<bitset<60>> B;
vector<vector<int>> dp;

void input() {
    cin >> N;
    B = vector<bitset<60>>(N);
    dp = vector<vector<int>>(N+1, vector<int>(60, 0));
    rep(i, N) {
        ll a;
        cin >> a;
        bitset<60> b(a);
        B[i] = b;
        rep(j, 60) dp[i+1][j] = dp[i][j] + b[j];
    }
}

int main() {
    input();
    vector<ll> p2(60);
    p2[0] = 1;
    for (int i = 1; i < 60; i++) p2[i] = (p2[i-1] * 2) % MOD;
    ll ans = 0;
    rep(i, N) {
        rep(j, 60) {
            int x = dp[N][j] - dp[i+1][j];
            if (B[i][j]) {
                x = N - i - 1 - x;
            }
            ans = (ans + p2[j] * x) % MOD;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 84608
using System;

public class Hello
{
    public static void Main()
    {
        var n = int.Parse(Console.ReadLine().Trim());
        string[] line = Console.ReadLine().Trim().Split(' ');
        var a = Array.ConvertAll(line, int.Parse);
        var q = int.Parse(Console.ReadLine().Trim());
        for (int i = 0; i < q; i++)
        {
            line = Console.ReadLine().Trim().Split(' ');
            var b = int.Parse(line[0]);
            var e = int.Parse(line[1]);
            var t = new int[e - b];
            var p = 0;
            for (int j = b; j < e; j++) t[p++] = a[j];
            Array.Reverse(t);
            p = 0;
            for (int j = b; j < e; j++) a[j] = t[p++];
        }
        for (int i = 0; i < n; i++)
            if (i == n - 1) Console.WriteLine(a[i]);
            else Console.Write("{0} ", a[i]);
    }
}



Measured memory_bytes: 9428
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <vector>
#include <queue>
#include <algorithm>

using namespace std;

typedef pair<int,int> P;
typedef long long ll; 

ll mod = 1e9 + 7;

int main(){
	double a,b,x;
	cin >> a >> b >> x;
	
	if(x/a < a*b/2){
		double l = 2*(x/a)/b;
		double t = atan2(b,l)*180/M_PI;
		printf("%.10lf\n",t);
	}else{
		double x2 = a*b-(x/a);
		double l = 2*(x2)/a;
		double t = atan2(l,a)*180/M_PI;
		printf("%.10lf\n",t);
	}

	return 0;
}


Measured memory_bytes: 512
N, Ma, Mb = list(map(int, input().split()))
abc = [list(map(int, input().split())) for _ in range(N)]

an = 0
bn = 0
for a, b, c in abc:
  an += a
  bn += b

ma = max(an, bn) + 1

DP = [[10 ** 10] * ma for _ in range(ma)]

for i in range(N):
  a, b, c = abc[i]
  for j in range(ma - 1, -1, -1):
    for k in range(ma - 1, -1, -1):
      if j == 0 and k == 0:
        DP[a][b] = min(DP[a][b], c)
        continue
      if DP[j][k] == 10 ** 10: continue
      if j + a >= ma or k + b >= ma: continue
      DP[j + a][k + b] = min(DP[j + a][k + b], DP[j][k] + c)

ans = 10 ** 10
a, b = Ma, Mb
while a < ma and b < ma:
  ans = min(ans, DP[a][b])
  a += Ma
  b += Mb

if ans == 10 ** 10:
  print(-1)
else:
  print(ans)


Measured memory_bytes: 3956
#include<iostream>

using namespace std;

int main() {
	int numList[3];
	for (int i = 0; i < 3; i++) {
		cin >> numList[i];
	}

	for (int j = 0; j < 3; j++) {
		for (int l = j; l < 3; l++) {
			if (numList[l] < numList[j]) {
				int temp = numList[j];
				numList[j] = numList[l];
				numList[l] = temp;
			}
		}
	}

	cout << numList[0] << " " << numList[1] << " " << numList[2] << endl;
	//system("pause");

	return 0;
}

Measured memory_bytes: 3096
#include <bits/stdc++.h>
#define REP(i, n) for(int i=0; i<(int)(n); ++i)
#define FOR(i, s, n) for(int i=(int)(s); i<(int)(n); ++i)
#define ALL(n) (n).begin(), (n).end()
#define pb push_back

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> mat;

const ll MAX_V = 100000;
const ll INF = 1e9;
const ll MOD = 998244353;

int main(){
    int A, B; cin >> A >> B;
    int ans = 0;
    REP(i, 2){
        if (A > B){
            ans += A;
            A--;
        }else{
            ans += B;
            B--;
        }
    }
    cout << ans << endl;
}

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

// macros
#define pb emplace_back
#define mk make_pair
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) for(int i=((int)(n)-1);i>=0;i--)
#define irep(itr, st) for(auto itr = (st).begin(); itr != (st).end(); ++itr)
#define irrep(itr, st) for(auto itr = (st).rbegin(); itr != (st).rend(); ++itr)
#define whole(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define bit(n) (1LL<<(n))
#define F first
#define S second
// functions
template <typename T> void unique(T& c){c.erase(std::unique(c.begin(), c.end()), c.end());}
template <class T>bool chmax(T &a, const T &b){if(a < b){a = b; return 1;} return 0;}
template <class T>bool chmin(T &a, const T &b){if(a > b){a = b; return 1;} return 0;}
template <typename T> istream &operator>>(istream &is, vector<T> &vec){for(auto &v: vec)is >> v; return is;}
template <typename T> ostream &operator<<(ostream &os, const vector<T>& vec){for(int i = 0; i < vec.size(); i++){ os << vec[i]; if(i + 1 != vec.size())os << " ";} return os;}
template <typename T> ostream &operator<<(ostream &os, const set<T>& st){for(auto itr = st.begin(); itr != st.end(); ++itr){ os << *itr; auto titr = itr; if(++titr != st.end())os << " ";} return os;}
template <typename T> ostream &operator<<(ostream &os, const unordered_set<T>& st){for(auto itr = st.begin(); itr != st.end(); ++itr){ os << *itr; auto titr = itr; if(++titr != st.end())os << " ";} return os;}
template <typename T> ostream &operator<<(ostream &os, const multiset<T>& st){for(auto itr = st.begin(); itr != st.end(); ++itr){ os << *itr; auto titr = itr; if(++titr != st.end())os << " ";} return os;}
template <typename T> ostream &operator<<(ostream &os, const unordered_multiset<T>& st){for(auto itr = st.begin(); itr != st.end(); ++itr){ os << *itr; auto titr = itr; if(++titr != st.end())os << " ";} return os;}
template <typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p){os << "(" << p.first << ", " << p.second << ")"; return os;}
template <typename T1, typename T2> ostream &operator<<(ostream &os, const map<T1, T2> &mp){for(auto itr = mp.begin(); itr != mp.end(); ++itr){ os << "(" << itr->first << ", " << itr->second << ")"; auto titr = itr; if(++titr != mp.end())os << " "; } return os;}
template <typename T1, typename T2> ostream &operator<<(ostream &os, const unordered_map<T1, T2> &mp){for(auto itr = mp.begin(); itr != mp.end(); ++itr){ os << "(" << itr->first << ", " << itr->second << ")"; auto titr = itr; if(++titr != mp.end())os << " "; } return os;}
//  types
using ll = long long int;
using P = pair<int, int>;
// constants
const int inf = 1e9;
const ll linf = 1LL << 60;
const double EPS = 1e-10;
const int mod = 1000000007;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};
// io
struct fast_io{
  fast_io(){ios_base::sync_with_stdio(false); cin.tie(nullptr); cout << fixed << setprecision(20);}
} fast_io_;


int main(int argc, char const* argv[])
{
  vector<int> x(5); cin >> x;
  int sum = 0;
  rep(i, 5)sum += x[i];
  cout << 15 - sum << endl;
  return 0;
}


Measured memory_bytes: 3624
#include <iostream>
using namespace std;
#define MAX 2000000
#define Sen 1000000000000
typedef long long llong;
llong Left[MAX/2+2], Right[MAX/2+2], A[MAX+1];

llong merge(llong A[], int n, int left, int mid, int right){
	int n1 = mid - left;
	int n2 = right - mid;
	
	for(int i=0; i<n1; i++) Left[i] = A[left+i];
	for(int i=0; i<n2; i++) Right[i] = A[mid+i];
	Left[n1] = Sen; Right[n2] = Sen;
	int i=0, j=0; 
	llong cnt = 0;
	for(int k=left; k<right; k++){
		if(Left[i]<=Right[j]){
			A[k] = Left[i++];
		}
		else {
			A[k] = Right[j++];
			cnt+=n1-i;
		}
	}
	return cnt;
}

llong mergesort(llong A[], int n, int left, int right){
	llong v1, v2, v3;
	if(left+1<right){//这里right所指的是最后一个元素的下一位 left+1 = right 的话说明只有一个元素了
		int mid = (left+right) / 2;
		v1 = mergesort(A, n, left, mid);
		v2 = mergesort(A, n, mid, right);
		v3 = merge(A, n, left, mid, right);
		return v1+v2+v3;
	}else return 0;
	
}

int main(){

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

	llong sum = 0;
	sum = mergesort(A, n, 0, n);
	cout<<sum<<endl;
	return 0;
}


Measured memory_bytes: 6228
#include<stdio.h>
#include<stdlib.h>

int main(void)
{
int n,m,i,j,min,sum,sum1,sum2,d;
int ansa,ansb;
int a[100];
int b[100];

while(scanf("%d%d",&n,&m),n+m){

sum=0;
sum1=0;
sum2=0;
min=200;
for(i=0;i<n;i++){
scanf("%d",&a[i]);
sum1+=a[i];
}
for(i=0;i<m;i++){
scanf("%d",&b[i]);
sum2+=b[i];
}

sum=sum1+sum2;

if(sum%2){
printf("-1\n");
} else {
d=abs(sum1-sum2)/2;
for(i=0;i<n;i++){
for(j=0;j<m;j++){
if(d==(sum1>sum2?a[i]-b[j]:b[j]-a[i])){
if(min>a[i]+b[j]){
ansa=a[i];
ansb=b[j];
min=a[i]+b[j];
}
}
}
}
if(min==200) printf("-1\n");
else printf("%d %d\n",ansa,ansb);
}
}
return 0;
}

Measured memory_bytes: 608
#include<stdio.h>
int main(){
	long long int n;
	scanf("%lld", &n);
	long long int total=0;
	
	for(int i=1; i<=n; i++){
		
		if(i%3==0&&i%5==0) continue;
		else if(i%3==0) continue;
		else if(i%5==0) continue;
		total+=i;}
		
		
	
	printf("%lld", total);
}
		
		
		
	
	

Measured memory_bytes: 1732