akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<utility>
#include<algorithm>
#include<cstdio>
#include<iomanip>
#include<queue>
#include<stack>

#define ll int64_t
#define Rep(i, n) for (ll i = 0; i < n; i++)

using namespace std;

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

    ll N;
    cin >> N;

    vector<ll> A(N);
    Rep (i, N) cin >> A.at(i);

    sort(A.begin(), A.end(), greater<ll>());
    ll ans = 0;
    if (N % 2) {
        vector<ll> w;
        Rep (i, N/2) w.push_back(2);
        Rep (i, 2) w.push_back(-1);
        Rep (i, N/2-1) w.push_back(-2);
        // for (auto e : w) cout << e << " ";
        // cout << "\n";
        ll sub = 0;
        Rep (i, N) sub += A[i] * w[i];
        Rep (i, N) w[i] *= -1;
        sort(w.begin(), w.end(), greater<ll>());
        Rep (i, N) ans += A[i] * w[i];
        // cout << ans << " " << sub << "\n";
        ans = max(ans, sub);
    } else {
        Rep (i, N) {
            if (i < N/2-1) ans += 2*A[i];
            else if (i < N/2) ans += A[i];
            else if (i < N/2+1) ans -= A[i];
            else ans -= 2*A[i]; 
        }
    }
    cout << ans << "\n";
}

Measured memory_bytes: 2168
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n, a[];
		double ave = 0.0;
		
		n = sc.nextInt();
		a= new int[n];
		for(int i = 0; i < n; ++i) {
			a[i] = sc.nextInt();
			ave += a[i];
		}
		ave /= n;
		sc.close();
		
		
		
		double a2[];
		a2 = new double[n];
		
		for(int i = 0; i < n; ++i)
			a2[i] = Math.abs(ave - (double)a[i]);
		
		double min = 1000;
		for(double i:a2)min = Math.min(min,  i);
		
		int ans = 0;
		for(int i = 0; i < n; ++i) {
			if(min == a2[i]) {
				ans = i;
				break;
			}
		}
		
		System.out.println(ans);
	}

}


Measured memory_bytes: 22996
// #include <boost/multiprecision/cpp_int.hpp> 
// using namespace boost::multiprecision; 
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define f first
#define s second
#define pb push_back
#define REP(i,a,b) for(long long int i=a ; i<b ; i++)
#define mp make_pair
#define INF 1000000000000000000
#define mod 1000000007
#define pi pair<ll,ll>
#define pd pair<ld,ld>
#define vi vector<ll>
#define vd vector<ld>
#define vvi vector<vi>
#define vvd vector<vd>
#define vpi vector<pi>
#define vpd vector<pd>
#define us unordered_set<ll>
#define um unordered_map<ll,ll>
#define sortA(a) sort(a.begin(),a.end())
#define sortD(a) sort(a.begin(),a.end(),greater<ll>())
#define all(a) a.begin(),a.end()
#define N 100005


#include <ext/pb_ds/assoc_container.hpp> 
using namespace __gnu_pbds; 
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> new_data_set; 
#define in insert
#define fbo find_by_order
#define ook order_of_key


void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

ll powmod(ll x,ll y)
{
	if(x==0)
		return 0;
	if(y==0 || x==1)
		return 1;
	if(y%2==0)
		return powmod((x*x)%mod,y/2)%mod;
	return (x*powmod(x,y-1)%mod)%mod;
}
void print1D(vi a)
{
	for(ll i=0;i<a.size();++i)
	{
		cout<<a[i]<<" ";
	}
	cout<<endl;
}
void print2D(vector<vi> a)
{
	for(ll i=0;i<a.size();++i)
	{
		for(ll j=0;j<a[i].size();++j)
		{
			cout<<a[i][j]<<" ";
		}
		cout<<endl;
	}
}
void solve()
{
	ll n,w;
	cin>>n>>w;
	vvi a(n+1,vi(2));
	for(ll i=1;i<=n;++i)
	{
		cin>>a[i][0]>>a[i][1];
	}
	vvi dp(n+1,vi(N,INF));
	for(ll i=0;i<=n;++i)
	{
		dp[i][0]=0;
	}
	ll ans=0;
	for(ll i=1;i<=n;++i)
	{
		for(ll j=1;j<N;++j)
		{
			dp[i][j]=dp[i-1][j];
			if((j-a[i][1])>=0)
			{
				dp[i][j]=min(dp[i][j],dp[i-1][j-a[i][1]]+a[i][0]);
			}
			// if(dp[i][j]!=INF)
			// {
			// 	debug(i,j,dp[i][j]);
			// }
			if(dp[i][j]<=w)
			{
				ans=max(ans,j);
			}
		}
	}
	cout<<ans<<endl;
}
int main()
{
	ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL);
	ll t=1;
	// cin>>t;
	while(t--)
	{
		solve();
	}
}


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

int main() {
    ios::sync_with_stdio(false);
    ll x;
    cin >> x;
    ll best = 1;
    for (ll a = 2; a*a <= x; ++a) {
        for (ll b = a*a; b <= x; b *= a) {
            best = max(best, b);
        }
    }
    cout << best << '\n';
}



Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    // Your code here!

    int N;
    int R;
    int IR;
    cin >> N;
    cin >> R;
    
    if(N >= 10){
        IR = R;
    }
    else{
        IR = R + (100 * (10 - N));
    }
    
    cout << IR;
}

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

a = []
for i in range(n):
    p = -1
    for j in range(len(b)-1, -1, -1):
        if b[j] == j + 1:
            p = j + 1
            break
    if p == -1:
        print(-1)
        exit()
    a.append(p)
    b.remove(p)

a.reverse()
print('\n'.join(map(str, a)))


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

using namespace std;

int main() {

    int n,k; cin >> n >> k;

    if(k == 1) {
        cout << 0 << endl;
        return 0;
    } else {
        cout << n - k << endl;
        return 0;
    }
}

Measured memory_bytes: 256
def calc():
    n, a, b = map(int, input().split())
    if a > b:
        return 0
    if n == 1 and a < b:
        return 0

    upper = a + b * (n - 1)
    lower = b + a * (n - 1)
    return upper - lower + 1


print(calc())


Measured memory_bytes: 2940
import sys
sys.setrecursionlimit(10**7)

def dfs(v,p,d):
    dist[v]=d
    for nv in G[v]:
        if nv==p:
            continue
        dfs(nv,v,d+1)
        
def getSP(v):
    p=v
    if dist[v]==lim:
        return p
    for nv in G[v]:
        if dist[nv]<dist[v]:
            p=getSP(nv)
    return p
    
def depth(v,p,d):
    global maxd
    maxd=max(maxd,dist[v])
    for nv in G[v]:
        if dist[nv]<dist[v]:
            continue
        depth(nv,v,d+1)
    
N,u,v=map(int,input().split());u,v=u-1,v-1

G=[[] for i in range(N)]
for i in range(N-1):
    a,b=map(lambda x:int(x)-1,input().split())
    G[a].append(b)
    G[b].append(a)
    
dist=[-1]*N
dfs(v,-1,0)

lim=dist[u]-(dist[u]-1)//2
SP=getSP(u)
 
maxd=-1
depth(SP,-1,0)

print(maxd-1)

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

int main(){

  int N;
  int ans,num=0;
  cin >> N;
  int A[N];
  For(i,N) cin >> A[i];

  sort(A,A+N);
  For(i,N-1) if(A[i]==A[i+1]) num++;
  if(num>0 && num%2!=0) num++;
  ans = N-num;

  cout << ans << endl;

  return 0;
}



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

using namespace std;

#define PI 3.14159265358979323846264338327950L

int main(void){
    int N,p,K;
    long long ans=0;
    vector<int> vec;

    cin>>N>>K;

    for(int i=0;i<N;i++){
        cin>>p;
        vec.push_back(p);
    }

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

    for(int i=0;i<K;i++){
        ans=ans+vec[i];
    }

    cout<<ans<<endl;


    return 0;
}



Measured memory_bytes: 3640
#include<bits/stdc++.h>
#include<atcoder/all>
using namespace std;
using namespace atcoder;
#define REP(i, n) for(int i = 0;i < (n);i++)
#define lint long long
const lint mod=1e9+7;
const lint inf=2.19e15+1;
const long double eps=1e-10;
template <class T,class U>bool chmin(T& a,U b){if(a>b){a=b;return true;}return false;}
template <class T,class U>bool chmax(T& a,U b){if(a<b){a=b;return true;}return false;}

signed main(){
    int n, q;
    cin >> n >> q;
    dsu uni(n + 1);
    REP(i,q){
        int t, u, v;
        cin >> t >> u >> v;
        if (t==0){
            uni.merge(u, v);
        }
        else{
            if (uni.same(u,v)){
                cout << 1 << endl;
            }
            else{
                cout << 0 << endl;
            }
        }
    }
}

Measured memory_bytes: 4064
import sys
read = sys.stdin.read

N, *A = map(int, read().split())

if A[0] != 0:
    print(-1)
    exit()


answer = 0
A.append(0)
for i in range(N):
    if A[i + 1] - A[i] > 1:
        print(-1)
        exit()
    if A[i + 1] <= A[i]:
        answer += A[i]

print(answer)

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

void solve()
{
    int x, a, b;
    cin >> x >> a >> b;
    x -= a;
    x %= b;
    cout << x << endl;
}

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

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

using namespace std;

namespace {

    typedef double real;
    typedef long long ll;

    template<class T> ostream& operator<<(ostream& os, const vector<T>& vs) {
        if (vs.empty()) return os << "[]";
        auto i = vs.begin();
        os << "[" << *i;
        for (++i; i != vs.end(); ++i) os << " " << *i;
        return os << "]";
    }
    template<class T> istream& operator>>(istream& is, vector<T>& vs) {
        for (auto it = vs.begin(); it != vs.end(); it++) is >> *it;
        return is;
    }

    template<typename INT>
    struct BinaryIndexedTree {
        int n;
        vector<INT> data; // data[i]???[floor2(i), i)???????????????. ?????????floor2???2????????¢??°.
        BinaryIndexedTree(int n) : n(n), data(n + 1, 0) {}
        INT sum(int i) {
            // [0, i)???????????????
            INT s = 0;
            while (i > 0) {
                s += data.at(i);
                i -= (i & -i);
            }
            return s;
        }
        void add(int i, INT x) {
            // ??????i???x?????????
            i++;
            while (i <= n) {
                data.at(i) += x;
                i += (i & -i);
            }
        }
    };

    ll countInversion(const vector<int>& perm) {
        // [0, n)?????????perm?????¢?????°?????°??????. ?¨???????O(N).
        // [0, n)??????????????????????????????????????????????????????. ????????¨???.
        ll n = perm.size();
        ll ans = 0;
        BinaryIndexedTree<ll> bit(n);
        for (int i = 0; i < n; i++) {
            ans += i - bit.sum(perm[i]);
            bit.add(perm[i], 1);
        }
        return ans;
    }

    int N;
    vector<int> P;
    void input() {
        cin >> N;
        P.resize(N);
        cin >> P;
    }

    template<typename T>
    vector<int> rank(vector<T> xs) {
        vector<int> rank(xs.size());
        iota(rank.begin(), rank.end(), 0);
        stable_sort(rank.begin(), rank.end(), [&](int a, int b) -> bool {
            return xs[a] < xs[b];
        });
        return rank;
    }

    void solve() {
        auto ans = countInversion(forward<vector<int>>(rank(P)));
        stable_sort(P.begin(), P.end());
        bool flg = true;
        for (auto p : P) {
            if (flg) {
                flg = false;
            } else {
                cout << " ";
            }
            cout << p;
        }
        cout << endl;
        cout << ans << endl;
    }
}

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

Measured memory_bytes: 3104
#include <bits/stdc++.h>
#include <stdio.h>
 
using namespace std;
 
#define int long long
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define trav(i, a) for (auto &i: (a))
#define sz(x) (int)(x).size()
#define all(v) (v).begin(), (v).end()
#define fr(i, a, b) for (int i = (a); i <= (b); ++i)

void solve();

signed main () {
    clock_t beg = clock();
    cout << fixed << setprecision(15);
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    #ifdef LOCAL
    freopen("input.txt", "r", stdin);
    #endif 
    int t = 1; 
    // cin >> t;    
    int tt = t;
    while (t--) {
        // cout << "Case #" << tt - t << ": "; 
        solve();
    }
    cerr << "\nExecution time: " << (clock() - beg) / 1000 << '\n';
    return 0;
}
int diff (string s, string t) {
    int ans = 0;
    for (int i = 0; i < (int) s.size(); ++i) {
        if (s[i] != t[i])
            ++ans;
    }
    return ans;
}
void solve() {  
    string s, t;
    cin >> s >> t;
    int ans = 1e5 + 5;
    int n = (int) s.size(), m = (int) t.size();
    for (int i = 0; i < n; ++i) {
        if (i + m - 1 >= n) 
            break;
        ans = min(ans, diff(t, s.substr(i, m)));
    }
    cout << ans;
}       

Measured memory_bytes: 3676
#include <iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<math.h>
using namespace std;

int main()
{
	int n,a[200005];
	pair<int, int>p[200005];
	cin >> n;
	int max1 = -1, max2 = -1, ind1, ind2;
	for (int i = 0; i < n; i++) {
		
		cin >> a[i];
		p[i] = make_pair(a[i], i);
	}
	sort(p, p + n);
	 max1=p[n - 1].first ;
	  max2= p[n - 2].first;
	ind1 = p[n - 1].second;
	ind2 = p[n - 2].second;
	for (int i = 0; i < n; i++) {
		if (a[i] == max1 && i == ind1)cout << max2 << endl;
		else cout << max1 << endl;
	}
}


Measured memory_bytes: 3968
A, B, C, X, Y = map(int, input().split())

ans = 0

ans += min(X, Y) * min(A+B,2*C)

if(X<Y):
  ans += (Y-X)*min(B,2*C)
else:
  ans += (X-Y)*min(A,2*C)
  
print(ans)

Measured memory_bytes: 3060
#include<cstdio>
#include<iostream>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<list>
#include<map>
#include<algorithm>

using namespace std;

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

    vector<vector<int> > a(n, vector<int>(3));
    for (int i = 0; i < n; i++) {
        cin >> a[i][0] >> a[i][1] >> a[i][2];
    }

    vector<vector<int> > dp(n, vector<int>(3, 0));
    for (int i = 0; i < 3; i++) {
        dp[0][i] = a[0][i];
    }

    for (int i = 1; i < n; i++) {
        for (int j = 0; j < 3; j++) {
            for (int k = 0; k < 3; k++) {
                if (j == k) {
                    continue;
                }
                dp[i][k] = max(dp[i][k], dp[i - 1][j] + a[i][k]);
            }
        }
    }

    cout << *max_element(dp[n - 1].begin(), dp[n - 1].end()) << endl;

    return 0;
}


Measured memory_bytes: 11136
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vii = vector<vi>;
using in6 = int64_t;
using ind = double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
  int n;
  cin >> n;
  vector<char> a(n);
  vector<char> b(n);
  rep(i,n) cin >> a[i];
  rep(i,n) cin >> b[i];
  rep(i,n) cout << a[i] << b[i];
  cout << endl;
}


Measured memory_bytes: 256
S=input()

n=len(S)-1
total=0
for i in range(2**n):
    SS=S[0]
    x=format(i,'0'+str(n)+'b')
    #print('x',x)
    for j in range(n):
        if x[j]=='1':
            SS+="+"
        SS+=S[j+1]
        #print("SS",SS)
    total+=eval(SS)
print(total)


Measured memory_bytes: 3060
# coding: utf-8
import sys

input = sys.stdin.readline

N, Q = map(int, input().split())
S = input().strip()
td_list = [input().split() for _ in range(Q)]
dest = [-2] * (N+1)

def sim(i): # i番目のゴーレムの最終結果を得る
  idx = i
  if dest[i] != -2:
    return dest[i]
  for td in td_list:
    if idx == -1:
      dest[i] = -1
      return -1
    elif idx == N:
      dest[i] = N
      return N
    elif td[0] == S[idx]:
      if td[1] == "L":
        idx -= 1
      else:
        idx += 1
  dest[i] = idx
  return idx


# 左側の境界を探索
left, right = -1, N

while right - left != 1:
  mid = (left + right) // 2
  if sim(mid) == -1:
    left = mid
  else:
    right = mid

lb = right

# 右側の境界を探索
left, right = -1, N

while left+1 < right:
  mid = (left + right) // 2
  if sim(mid) == N:
    right = mid
  else:
    left = mid

rb = left

print(rb - lb + 1)



Measured memory_bytes: 40884
using System;

namespace AizuOnLine
{
    class Program
    {
        static void Main(string[] args)
        {
            while (true)
            {
                string[] data = Console.ReadLine().Split(' ');
                int n = int.Parse(data[0]);
                int x = int.Parse(data[1]);

                if(n == 0 && x == 0)
                {
                    break;
                }

                int count = 0;
                for (int a = 1; a <= n; a++)
                {
                    if (x < 2 * a + 1)
                    {
                        break;
                    }

                    for (int b = a + 1; b < n; b++)
                    {
                        int c = x - a - b;
                        if (x < a + 2 * b + 1)
                        {
                            break;
                        }
                        else if (n < c)
                        {
                            continue;
                        }

                        count++;
                    }

                }

                Console.WriteLine(count);
            }
        }
    }
}

Measured memory_bytes: 9176
N, M = map(int, input().split())

# union-find改良
parent = list(range(N+1))
rank = [0] * (N+1)
pardist = [0] * (N+1) # ルートとの距離

def getRoot(x):
  if parent[x] == x:
    return x, 0
  else:
    # ルートに繋ぎ変える
    parent[x], dist = getRoot(parent[x])
    # ルートとの距離に更新
    pardist[x] += dist
    return parent[x], pardist[x]

def unite(left, right, dist):
  lRoot, lPardist = getRoot(left)
  rRoot, rPardist = getRoot(right)
  # print(parent)
  # print(pardist)
  if lRoot == rRoot:
    # 矛盾がないかチェック
    if -(rPardist - lPardist) != dist:
      print('No')
      exit()
  else:
    # 矛盾は起きない
    # ルート間の距離だけ更新して併合
    if rank[lRoot] < rank[rRoot]:
      parent[lRoot] = rRoot
      pardist[lRoot] = dist + rPardist - lPardist
    else:
      parent[rRoot] = lRoot
      pardist[rRoot] = -(dist + rPardist - lPardist)
      if rank[lRoot] == rank[rRoot]:
        rank[lRoot] += 1

for i in range(M):
  l, r, d = map(int, input().split())
  unite(l, r, d)

print('Yes')

Measured memory_bytes: 10868
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
using namespace std;

typedef long long ll;

ll vs[100000+10];
int n;

int visited[100000+10];

int main(void) {
  scanf("%d", &n);
  REP(i, n) {
    scanf("%lld", &vs[i]);
  }

  ll res = 0;
  for(int ab = 1; ab < n-1; ++ab) {
    ll leftSum = 0;
    ll rightSum = 0;
    for(int i = 1; ab*i < n && n-1-ab*i >= 0; ++i) {
      ll a = n-1 - ab*i;
      ll b = a - ab;
      if(a <= 0 || b <= 0) break;
      if(visited[ab*i] == ab) break;
      visited[ab*i] = ab;
      if(visited[n-1-ab*i] == ab) break;
      visited[n-1-ab*i] = ab;
      leftSum += vs[ab*i];
      rightSum += vs[n-1-ab*i];
      res = max(res, leftSum + rightSum);
    }
  }
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;

main() {
    int64_t n, k;
    cin >> n >> k;

    auto m = n * (n - 1) / 2 - k;
    if (m < n - 1) {
        cout << "-1" << endl;
        return 0;
    }
    cout << m << endl;

    for (auto i : irange(1L, n + 1)) {
        for (auto j : irange(i + 1, n + 1)) {
            cout << i << " " << j << "\n";
            --m;

            if (m == 0) {
                return 0;
            }
        }
    }

}

Measured memory_bytes: 256
<?php 
$N = intval(trim(fgets(STDIN)));
$tmp = trim(fgets(STDIN));
//$a = array_map("intval", explode(" ", $tmp));
$a = explode(" ", $tmp);

$l = 0;
$left = [];
$left[0] = 0;
foreach($a as $key => $value){
	$l += (int)$value;
	array_push($left, $l);
}

$r = 0;
$right = [];
$right[0] = 0;
$r_a = array_reverse($a);
foreach($r_a as $key => $value){
	$r += (int)$value;
	array_push($right, $r);
}
$right = array_reverse($right);

$ans = abs($right[1] - $left[1]);
for($i = 2;$i<count($right)-1;$i++){
	if($ans > abs($right[$i] - $left[$i])){
		$ans = abs($right[$i] - $left[$i]);
	}
}

echo $ans . PHP_EOL;

Measured memory_bytes: 53728
# https://atcoder.jp/contests/abc062/tasks/abc062_b

H, W = map(int, input().split())

ans = []

for i in range(H):
    ans_ = input()
    ans.append(ans_)

ans_t_ = '#' * (W + 2)
print(ans_t_)

for t in ans:
    ans_t = '#' + t + '#'
    print(ans_t)

print(ans_t_)

Measured memory_bytes: 3316
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define all(x) x.begin(),x.end()
#define dbg(x) cout<<#x<<":"<<x<<endl
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,P> PP;

struct edge{ll cost,to;};

int main(){
  ll n,m,INF=1LL<<60;
  cin>>n>>m;
  vector<edge> e(m,{0,0});
  for(ll i=0;i<m;i++){
    int b;
    cin>>e[i].cost>>b;
    for(ll j=0;j<b;j++){
      ll c;
      cin>>c;
      c--;
      e[i].to|=1<<c;
    }
  }

  vector<ll> d(1<<n,INF);
  priority_queue<P> que;
  que.push(P(0,0));
  while(que.size()){
    int cost=que.top().fi;
    int now=que.top().se;
    que.pop();
    if(cost>d[now])continue;
    d[now]=cost;
    for(int i=0;i<m;i++){
      int to=now|e[i].to;
      int tocost=d[now]+e[i].cost;
      if(d[to]>tocost){
	que.push(P(tocost,to));
	d[to]=tocost;
      }
    }
  }

  if(d[(1<<n)-1]==INF)cout<<-1<<endl;
  else cout<<d[(1<<n)-1]<<endl;
}


Measured memory_bytes: 384
#include <algorithm>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <set>

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

using namespace std;

typedef long long ll;

const int mod = (int)1e9+7;

ll mod_pow(ll x, ll n, ll mod) {
  ll ret = 1;
  while (n > 0) {
    if (n & 1) {
      ret *= x;
      ret %= mod;
    }
    x = x*x % mod;
    n >>= 1;
  }
  return ret;
}

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

  int n; cin >> n;
  vector<ll> a(n);

  rep(i, n) { cin >> a[i]; }

  vector<ll> cnt_zero(61, 0);
  vector<ll> cnt_one(61, 0);

  rep(i, n) {
    rep(d, 61) {
      if ( (a[i]>>d) & 1 ) {
        cnt_one[d]++;
      } else {
        cnt_zero[d]++;
      }
    }
  }

  ll ans = 0;
  rep(d, 61) {
    ans += mod_pow(2, d, mod)*(cnt_zero[d]*cnt_one[d]%mod);
    ans %= mod;
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 2560
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

r,c,k = map(int,readline().split())
data = list(map(int,read().split()))
d = dict()
it = iter(data)
for ri,ci,vi in zip(it,it,it):
    d[(ri-1)*5000 + (ci-1)] = vi

dp_max = [0] * (c)

for i in range(r):
    dp = [[0,0,0,0] for _ in range(4)]
    for j in range(c):
        dp[0][0] = max(dp[0][0],dp_max[j])
        if( i*5000+j  in d):
            ci = d[i*5000+j]
            #3
            if(dp[3][0] != 0):
                min_num = min(dp[3][1:4])
                if(min_num < ci):
                    dp[3][0] += ci-min_num
                    for k in range(1,4):
                        if(dp[3][k] == min_num):
                            dp[3][k] = ci
                            break
            if(dp[2][0] != 0):
                if(dp[3][0] <= dp[2][0] + ci):
                    dp[3][0] = dp[2][0] + ci
                    dp[3][1] = dp[2][1]
                    dp[3][2] = dp[2][2]
                    dp[3][3] = ci

            #2
            if(dp[1][0] != 0):
                if(dp[2][0] <= dp[1][0] + ci):
                    dp[2][0] = dp[1][0] + ci
                    dp[2][1] = dp[1][1]
                    dp[2][2] = ci
            #1
            if(dp[1][0] <= dp[0][0] + ci):
                dp[1][0] = dp[0][0] + ci
                dp[1][1] = ci
        # print(i,j)
        # print(dp)

        dp_max[j] = max(dp[0][0], dp[1][0],dp[2][0],dp[3][0])

    # print(i,j)
    # print(dp_max)

print(dp_max[-1])

Measured memory_bytes: 142148
#https://atcoder.jp/contests/abc131/tasks/abc131_c

import fractions

def gcd(x, y):
    if x < y:
        x, y = y, x
    while y > 0:
        x, y = y, x % y
    return x
'''
def lcm(a,b):
	return a*b//gcd(a,b)
'''
a,b,c,d = [int(i) for i in input().split()]
'''
C = 0
D = 0
E = 0
'''
'''
for i in range(int(a / max(c,d,lcm(c,d))),b-a):
    print(i)
    if c * i >= a and c * i <= b and C == 0:
        C = c * i
    if d * i >= a and d * i <= b and D == 0:
        D = d * i
    if lcm(c,d) * i >= a and lcm(c,d) * i <= b and E == 0:
        E = lcm(c,d) * i
    if C != 0 and D != 0 and E != 0:
        break
'''
'''
for i in range(int(a / lcm(c,d)) - 1,int(b / lcm(c,d))+2):
    if lcm(c,d) * i >= a and lcm(c,d) * i <= b and E == 0:
        E = lcm(c,d) * i
        break

for i in range(int(a / c) - 1,int(b / c)+2):
    if c * i >= a and c * i <= b and C == 0:
        C = c * i
        break

for i in range(int(a / d) - 1,int(b / d)+2):
    if d * i >= a and d * i <= b and D == 0:
        D = d * i
        break
'''
#print(lcm(c,d))
#print('')
#print(C,D,E)
'''
c2 = int(b / c) - int(C / c)+1
d2 = int(b / d) - int(D / d)+1
e2 = int(b / lcm(c,d)) - int(E / lcm(c,d))+1
'''
'''
if int(b / c) == b/c:
	print('c')
	c2 += 1
if int(b / d) == b/d:
	print('d')
	d2 += 1
if int(b / lcm(c,d)) == b/lcm(c,d):
	print('e')
	e2 += 1
'''
c2 = b // c - (a-1) // c
d2 = b // d - (a-1) // d
lcm = c * d // fractions.gcd(c,d)
e2 = b // lcm - (a-1) // lcm
'''
if a % c == 0:
	#print('c')
	c2 += 1
if a % d == 0:
	#print('d')
	d2 += 1
if a % lcm(c,d) == 0:
	#print('e')
	e2 += 1
'''
'''
if E == 0:
	e2 = 0
if C == 0:
	c2 = 0
if D == 0:
	d2 = 0
'''

#print(b-a+1,c2,d2,e2)
'''
c1 = list(range(C,b+1,c))
d1 = list(range(D,b+1,d))
e1 = list(range(E,b+1,lcm(c,d)))
print(b-a+1,len(c1),len(d1),len(e1))

print(c1,d1,e1)

print(b-a+1-len(c1)-len(d1)+len(e1))
'''
print(int(b-a+1 - c2 - d2 + e2))

Measured memory_bytes: 5536
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;

procedure Solve is
   A : Integer;
   B : Integer;
   Ans : Integer;
begin
   Get (A);
   Get (B);
   Ans := A+B;
   if Ans < 24 then
      Put_Line (Integer'Image (Ans));
   else
      Put_Line (Integer'Image (Ans-24));
   end if;
end Solve;

Measured memory_bytes: 3652
#include<bits/stdc++.h>
#define MAXN 200005
using namespace std;

int n,cnt,last[MAXN];
int father[MAXN],deep[MAXN],dis[MAXN];
int q[MAXN],nnn[MAXN],mx[MAXN];
int tim,a[MAXN][2],xx,yy;
bool vis[MAXN],win[MAXN];

struct edge
{
    int to,next,h;
}t[MAXN*4];

void add(int u,int v,int h)
{
    t[++cnt].to=v;t[cnt].h=h;
    t[cnt].next=last[u];last[u]=cnt;
    t[++cnt].to=u;t[cnt].h=h;
    t[cnt].next=last[v];last[v]=cnt;
}

void dfs(int x)
{
    deep[x]=deep[father[x]]+1;nnn[x]=++tim;
    for (int i=last[x];i;i=t[i].next)
        if (t[i].to!=father[x]) father[t[i].to]=x,dfs(t[i].to);
    mx[x]=++tim;
}

bool check(int x,int y)
{
    if (nnn[x]>nnn[y]) swap(x,y);
    if (nnn[x]<nnn[y]&&mx[x]>nnn[y]) return deep[y]-deep[x]>2 ? true : false;
    if (father[x]==father[y]) return false;
    return true;
}

void bfs()
{
    int h=1,tt=1;q[1]=xx;vis[xx]=1;
    while (h<=tt)
    {
        int x=q[h++];
        for (int i=last[x];i;i=t[i].next)
            if (!t[i].h&&!vis[t[i].to])
            {
                dis[t[i].to]=dis[x]+1;
                if (dis[t[i].to]<deep[t[i].to]) vis[t[i].to]=1,q[++tt]=t[i].to;
            }
    }
}


template<class T>inline void read(T &res)
{
    static char ch;T flag=1;
    while((ch=getchar())<'0'||ch>'9')if(ch=='-')flag=-1;res=ch-48;
    while((ch=getchar())>='0'&&ch<='9')res=res*10+ch-48;res*=flag;
}

int main()
{
    int ans=0;
    read(n);read(xx);read(yy);

    for (int i=1;i<n;i++) {read(a[i][0]);read(a[i][1]);}

    for (int i=1;i<n;i++)
    {
        int x,y;
        read(x);read(y);
        add(x,y,1);
    }

    deep[0]=-1;
    dfs( yy );

    for (int i=1;i<n;i++)
    {
        if (check(a[i][0],a[i][1]))
            win[a[i][0]]=win[a[i][1]]=1;
        else add(a[i][0],a[i][1],0);
    }

    bfs();

    for (int i=1;i<=n;i++)
        if (win[i]&&vis[i])
            {putchar('-');putchar('1');return 0;}

    for (int i=1;i<=n;i++)
        if (vis[i])
            ans=max(ans,deep[i]<<1);

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

Measured memory_bytes: 22656
using System;
using System.Linq;
class Program
{
    static void Main(string[] args)
    {
        int[] a = Console.ReadLine().Split().Select(int.Parse).ToArray();
        int A = a[0];
        int B = a[1];
        if(A < 6)
        {
            Console.WriteLine("0");
        }else if(A < 13)
        {
            Console.WriteLine(B / 2);
        }
        else
        {
            Console.WriteLine(B);
        }
    }
}

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

int main(){
    int n, k; cin >> n >> k;
    vector<ll> a(n);
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    sort(a.begin(), a.end());
    ll ans = 1000000000;
    for(int i = k-1; i < n; i++){
        ll res = abs(a[i-k+1] - a[i]) + abs(0-a[i-k+1]);
        ll res1 = abs(a[i-k+1] - a[i]) + abs(0-a[i]);
        //cout << res << endl;
        ans = min(res, min(ans, res1));
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <cmath>
using namespace std;
 
int main() {
  int X;
  cin >> X;
  int apple = ceil(X / 1.08f);
  int price = floor(apple * 1.08);
  if(X == price) cout << apple << endl;
  else cout << ":(" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <limits.h>
#include <algorithm>
#include <math.h>
#include <time.h>
#include <vector>
#include <map>
#include <queue>
#include <string>
using namespace std;
typedef long long ll;

int main(void){
    int a, b, c;
    cin >> a >> b >> c;
    
    cout << min(b / a, c) << endl;
    
    
    
}


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

int main()
{
    unsigned long long N, B, R, tmp1, tmp2;
    cin >> N >> B >> R;
    if(B==0){
        cout << 0 << endl;
        return 0;
    }
    tmp1 = (N / (B + R)) * B;
    if(N%(B+R)<=B){
        tmp2 = N % (B + R);
    }
    else{
        tmp2 = B;
    }
    cout << tmp1 + tmp2 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n; long long C; cin >> n >> C;
  vector<pair<long long, long long> > where;
  long long sum = 0;
  for(int i = 0; i < n; i++){
    long long a, b; cin >> a >> b;
    where.push_back({a, b});
    sum += b;
  }
  long long ans = 0;
  ans = max(ans, sum - where.back().first);
  ans = max(ans, - C + where[0].first + sum);
  {
    multiset<long long> delta;
    vector<long long> vals;
    long long cps = 0;
    for(int i = 0; i < n; i++){
    	cps += where[i].second;
      	delta.insert(cps - where[i].first);
      	vals.push_back(cps - where[i].first);
      ans = max(ans, vals[i]);
    }
    long long invs = 0;
    for(int i = n - 1; i >= 0; i--){
    	delta.erase(delta.find(vals[i]));
      	invs += where[i].second;
      	long long fac = 0;
      	if(!delta.empty()) fac = max(fac, *(--delta.end()));
      	ans = max(ans, - 2 * (C - where[i].first) + invs + fac);
    }
  }
  {
    multiset<long long> delta;
    vector<long long> vals;
    long long cps = 0;
    for(int i = 0; i < n; i++){
    	cps += where[i].second;
      	delta.insert(cps - 2 * where[i].first);
      	vals.push_back(cps - 2 * where[i].first);
    }
    long long invs = 0;
    for(int i = n - 1; i >= 0; i--){
    	delta.erase(delta.find(vals[i]));
      	invs += where[i].second;
      	long long fac = 0;
      	if(!delta.empty()) fac = max(fac, *(--delta.end()));
      	ans = max(ans, - (C - where[i].first) + invs + fac);
    }
  }
  cout << ans << endl;
  return 0;
}

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

int main() {
  int n;
  cin >> n;
  vector<ll> a(n);
  rep(i,n) cin >> a[i];
  
  sort(a.rbegin(), a.rend());
  int cnt = 2;
  ll ans = a[0];
  rep(i,n) {
    if (cnt+2 <= n) {
      ans += a[i+1]*2;
      cnt += 2;
    } else if (cnt+1 <= n) {
      ans += a[i+1];
      cnt += 1;
    } else break;
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 4832
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

void Swap(int x[],int i,int j)
{
	int tmp;
	tmp=x[i];
	x[i]=x[j];
	x[j]=tmp;
}

void QSort(int x[], int left, int right)
{
	int i, j;
	int pivot;

	i = left;
	j = right;

	pivot = x[(left + right) / 2];

	while(1)
	{
		while (x[i] > pivot)
		{
			i++;
		}
		while (pivot > x[j])
		{
			j--;
		}
		if (i >= j)
		{
			break;
		}
		Swap(x, i, j);
		i++;
		j--;
	}
	if (left < i - 1)
	{
		QSort(x, left, i - 1);
	}
	if (j + 1 <  right)
	{
		QSort(x, j + 1, right);
	}
}

int main()
{
	int n,k,i,max=0;
	int *l;

	scanf("%d%d",&n,&k);
	l = (int *)malloc(sizeof(int)*n);
	for(i=0;i<n;i++)
	{
		scanf("%d",&l[i]);
	}
	
	QSort(l,0,n-1);

	for(i=0;i<k;i++)
	{
		max+=l[i];
	}
	printf("%d\n",max);

	free(l);
	return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
#include<math.h>

int main(void){
    long A,B;
    scanf("%ld%ld",&A,&B);
    long base;

    int i;

    if(A<B){
        base=A;
        A=B;
        B=base;
    }

    long r;

    r=A%B;
    while(r!=0){
        A=B;
        B=r;
        r=A%B;
    }

    long gcm=B;

    int count=1;

    if(gcm%2==0){
        count++;
        while(gcm%2==0 && gcm!=0){
            gcm/=2;
        }
    }

    for(i=3;i<=sqrt(gcm);i+=2){
        if(gcm%i==0){
            count++;
            while(gcm%i==0 && gcm!=0){
                gcm/=i;
            }
        }
    }

    if(gcm>1){
        count++;
    }

    printf("%d",count);

    return 0;

}

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

int N,T;
int A[100010];

int main()
{
    scanf("%d%d",&N,&T);
    for(int i = 0; i < N; i++)
    {
        scanf("%d",&A[i]);
    }
    int min_mem = A[0],max_mem = A[0],ans = 0,mem = 0,now_max = 1,now_min = 1;
    for(int i = 1; i < N + 1; i++)
    {
        if(i == N)
        {
            if(max_mem - min_mem == mem)
            {
                ans += min(now_max,now_min);
            }
            continue;
        }
        if(A[i] <= min_mem)
        {
            if(A[i] < min_mem)
            {
                if(max_mem - min_mem == mem)
                {
                    ans += min(now_max,now_min);
                }
                min_mem = A[i];
                max_mem = A[i];
                now_min = now_max = 1;
            }
            else if(A[i] == min_mem)
            {
                now_min++;
            }
        }
        else if(A[i] >= max_mem)
        {
            if(A[i] == max_mem)
            {
                now_max++;
            }
            else if(A[i] > max_mem)
            {
                max_mem = A[i];
                now_max = 1;
                if(max_mem - min_mem > mem)
                {
                    ans = 0;
                    mem = max_mem - min_mem;
                }
            }
        }
    }
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <math.h>
#include <numeric>
#include <vector>
#include <map>
#include <algorithm>
#include <queue>
#include <tuple>
#include <functional>

#define PI 3.14159265359
#define INF 1e9
#define LINF 1e18
#define irep(i,n) for(int  i = 0; i < n; i++)
#define irep2(i,a,n) for(int i = a; i < n; i++)
#define lrep(i,n) for(long long  i = 0; i < n; i++)
#define lrep2(i,a,n) for(long long i = a; i < n; i++)
#define in(a) cin >> a
#define out(a) cout << a << endl
typedef long long ll;

typedef std::vector<int> v_int;
typedef std::vector<std::vector<int> > v2_int;
typedef std::vector<ll> v_ll;
typedef std::vector<std::vector<ll> > v2_ll;

using namespace std;

int main() 
{
    int ans = -1;
    int x; 
    cin >> x;

    irep2(i, 2, 33) {
        int pow = i*i;
        while(pow <= x){
            ans = max(pow, ans);
            pow *= i;
        }
    }
    ans = max(ans, 1);

    cout << ans << endl;

    return 0;
}
    



Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <iomanip>
using namespace std;
#define all(x) x.begin(), x.end()
typedef vector <int> vi;
typedef pair<int,int> ii;
typedef long long ll;
typedef long double ld;
const int mod = 1e9 + 7;
const ll inf = 3e18 + 5;
int add(int a, int b) { return (a += b) < mod ? a : a - mod; }
int mul(int a, int b) { return 1LL * a * b % mod; }

int main(){
    int n;
    cin >> n;
    vector <ii> v;
    for(int i = 0; i < n; i++){
        int a, b;
        cin >> a >> b;
        v.emplace_back(b, a);
    }
    sort(all(v));
    ll t = 0;
    for(int i = 0; i < n; i++){
        t += v[i].second;
        if(t > v[i].first)
            return cout << "No", 0;
    }
    cout << "Yes";
}

Measured memory_bytes: 2420
# -*- coding: utf-8 -*-
"""
Created on Sun Sep 15 20:38:18 2019

@author: Yamazaki Kenichi
"""

N, K, Q = map(int,input().split())
A = [int(input()) for i in range(Q)]

score = [0 for i in range(N)]

for a in A:
    score[a-1] += 1

for s in score:
    if Q - s < K:
        print('Yes')
    else:
        print('No')




Measured memory_bytes: 8644
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) debug(x) debug(y);
#define repn(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) for(int i = 0; i < (int)(a); i++)
#define all(v) v.begin(), v.end() 
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define sq(x) ((x) * (x))

template<class T> T gcd(T a, T b){ return ((b == 0) ? a : gcd(b, a % b)); }

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
	ll n, k;
	cin >> n >> k;
	map<ll, ll> m;
	for(ll i = 1LL; i <= n; i++) m[i % k]++;
	ll ans = 0;
	for(ll a = 1LL; a <= n; a++){
		ll remB = (k - (a % k)) % k;
		ll b = m[remB]; //number of acceptable b's
		ll c = m[(k - remB) % k];
		if(((a % k) + ((k - remB) % k)) % k == 0) ans += (ll)(b * c);
	}
	cout << ans << endl;
	return 0;
}
/*
Things to look out for:
	- Integer overflows
	- Array bounds
	- Special cases
Be careful!
*/


Measured memory_bytes: 12800
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>
#include <set>
#include <functional>
#include <iomanip>

using namespace std;

#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ;
#endif

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back

//#define int long long

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

const int MOD = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;

signed main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int K; cin >> K;
    VL A(K); REP(i,K) cin >> A[i];
    LL st = 2;
    LL fi = 2;

    for(int i = K-1; i >= 0; i--){
        if(st%A[i] == 0){
            st = st;
        }
        else{
            LL tmp;
            tmp = (st / A[i] +1) * A[i];
            if(tmp <= fi){
                st = tmp;
            }
            else{
                cout << -1 << endl;
                return 0;
            }
        }

        if(fi%A[i] == 0){
            fi = fi + A[i] - 1;
        }
        else{
            LL tmp;
            tmp = (fi / A[i]) * A[i];
            if(st <= tmp){
                fi = tmp + A[i] - 1;
            }
            else{
                cout << -1 << endl;
            }
        }
        if(st > fi){
            cout << -1 << endl;
            return 0;
        }
    }
    cout << st << " " << fi << endl;

}


Measured memory_bytes: 1024
import sys
input = sys.stdin.readline

N, W = [int(x) for x in input().split()]
wv = []
for _ in range(N):
    wv.append([int(x) for x in input().split()])
V = 10 ** 5
inf = float("inf")

dp = [[inf] * (V + 1) for _ in range(N + 1)]
dp[0][0] = 0
ans = -1

for i in range(N):
    for j in range(V + 1):
        w, v = wv[i]
        if j >= v:
            dp[i + 1][j] = min(dp[i][j], dp[i][j - v] + w)
        else:
            dp[i + 1][j] = dp[i][j]
        if dp[i + 1][j] <= W:
            ans = max(ans, j)
print(ans)

Measured memory_bytes: 311272
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a,b;
  string ans;
  cin >> a >> b;
  if(a%2==1 && b%2 == 1){
    ans = "Odd";
  }else{
    ans = "Even";
  }
  cout << ans << endl;
}

Measured memory_bytes: 3628
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;

int main() {
	//cout<<"GfG!";
	ll a, b, c, k, sum = 0;
	cin>>a>>b>>c>>k;
	if (k >= a)
	{
	    sum += a;
	    k = k - a;
	}
	else
	{
	    sum += k;
	    k = 0;
	}
	if (k)
	{
	    if (k >= b)
	    {
	        sum += 0;
	        k = k - b;
	    }
	    else
	    {
	        sum += k;
	        k = 0;
	    }
	    if (k)
	    {
	        if (k >= c)
	        {
	            sum += -c;
	            k = k - c;
	        }
	        else
	        {
	            sum += -k;
	            k = 0;
	        }
	        cout<<sum;
	    }
	    else
	        cout<<sum;
	}
	else
	    cout<<sum;
	return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef unsigned int ui32;
const long long INFLL = 1e18;

using namespace std;

const int MAXN = 100000;

int a[MAXN + 1];

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    //freopen("input.txt", "r", stdin);
    //freopen("input.txt", "w", stdout);

    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    sort(a, a + n);
    int mx = a[n - 1];
    double t = mx / 2.0;
    double best = 1e9;
    int cur = -1;
    for (int i = 0; i < n; i++) {
        if (abs(a[i] - t) < best) {
            best = abs(a[i] - t);
            cur = a[i];
        }
    }
    cout << mx << " " << cur << "\n";
    return 0;
}

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

int main() {
    int a, b; cin >> a >> b;
    int maxv = max(a+b, a-b);
    cout << max(maxv, a*b) << endl;
}

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

struct teamscore{
  int t, c, p;
  int w[10];
};

bool comp(const teamscore &a, const teamscore &b)
{
  if(a.c != b.c)
    return a.c > b.c;
  else if(a.p != b.p)
    return a.p < b.p;
  else
    return a.t < b.t;
}

int main()
{
  while(1){
    int T, P, R;
    cin >> T >> P >> R;
    if(T == 0 && P == 0 && R == 0) break;
    vector<teamscore> v(T);
    REP(i,T){
      v[i].t = i+1;
      v[i].c = v[i].p = 0;
      REP(j,10)
        v[i].w[j] = 0;
    }
    REP(i,R){
      int team, p, time;
      string m;
      cin >> team >> p >> time >> m;
      if(m == "WRONG"){
        v[team-1].w[p-1]++;
      }else{
        v[team-1].p += v[team-1].w[p-1]*1200 + time;
        v[team-1].c++;
      }
    } 
    sort(v.begin(), v.end(), comp);
    REP(i,T)
      cout << v[i].t << " " << v[i].c << " " << v[i].p << endl;
  }
}

Measured memory_bytes: 1244
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const string ln = "\n";
constexpr int INF = 1001001001;
constexpr int MOD = 1000000007;

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

  ll n;
  cin >> n;
  string s;
  cin >> s;

  if (n < 3) {
    cout << 0 << ln;
    return 0;
  }

  vector<int> r, g, b;
  for (int i = 0; i < n; i++) {
    if (s[i] == 'R') {
      r.push_back(i);
    } else if (s[i] == 'G') {
      g.push_back(i);
    } else {
      b.push_back(i);
    }
  }

  if (r.size() > 0 && g.size() > 0 && b.size() > 0) {
  } else {
    cout << 0 << ln;
    return 0;
  }

  ll ans = 0;
  sort(all(r));
  sort(all(g));
  sort(all(b));

  ll total = r.size() * g.size() * b.size();

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      int li = i - j;
      int ri = i + j;
      if (li < 0 || ri > n - 1) {
        continue;
      }

      set<char> st;
      st.insert(s[i]);
      st.insert(s[li]);
      st.insert(s[ri]);
      if (st.size() >= 3) {
        total--;
      }
    }
  }

  cout << total << ln;

  return 0;
}

Measured memory_bytes: 3700
#include <stdio.h>
#include <queue>
#include <algorithm>
#include <stdlib.h>

using namespace std;

struct Job
{
    int days;
    int reward;

    public:
        Job() { this->days = 0; this->reward = 0; }
        Job(int days, int reward) { this->days = days; this->reward = reward; }
};

// bool compareDays(Job const& jobA, Job const& jobB) 
// { 
//     if (jobA.days == jobB.days) return jobA.reward > jobB.reward;
//     return (jobA.days < jobB.days); 
// } 

// struct CompareReward
// {
//     bool operator()(Job const& jobA, Job const& jobB)
//     {
//         if (jobA.reward == jobB.reward) return jobA.days < jobB.days;
//         return (jobA.reward > jobB.reward);
//     }
// };


int main()
{
    int N, M;

    scanf("%d", &N);
    scanf("%d", &M);

    int days, reward;

    vector<Job> dayJobs[M];

    for (int i = 0; i < N; i++)
    {
        scanf("%d", &days);
        scanf("%d", &reward);

        if (days > M) continue;

        dayJobs[M - days].push_back(Job(days, reward));
    }

    priority_queue<int> maxRewardHeap;

    long long maxReward = 0;

    for (int i = M - 1; i >= 0; i--)
    {
        //printf("currDay: %d\n", currDay);
        while (!dayJobs[i].empty())
        {
            maxRewardHeap.push(dayJobs[i].back().reward);
            dayJobs[i].pop_back();
        }
        
        if (!maxRewardHeap.empty())
        {
            maxReward += maxRewardHeap.top();
            //printf("maxReward: %lld\n", maxReward);
            maxRewardHeap.pop();
        }
    }

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

    return 0;
}

Measured memory_bytes: 5504