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

long long int combination(int a, int b){
  if(b == 1) return a;
  if(b == 0) return 1;
  if(b > a || b < 0) return 0;
  return combination(a-1, b-1) * a / b;
}

int main(){
  int n, a, b;
  cin >> n >> a >> b;
  vector<long long int> v(n);
  for(int i = 0; i < n; i++){
    cin >> v[i];
  }
  long long int sum = 0;
  sort(v.begin(), v.end(), greater<long long int>());
  for(int i = 0; i < a; i++){
    sum += v[i];
  }
  if(sum/a > 1e7)cout << sum / a << endl;
  else cout << sum * 1.0 /a << endl;

  int ind = -1;
  int ind2 = n;
  for(int i = 0; i < n; i++){
    if(v[i] == v[a-1] && ind == -1){
      ind = i;
    }
    else if(ind != -1 && v[i] != v[a-1]){
      ind2 = i;
      break;
    }
  }
  if(ind != 0) cout << combination(ind2 - ind, a - ind) << endl;
  else{
    long long int sum2 = 0;
    for(int i = a-1; i < b; i++){
      sum2 += combination(ind2, i+1);
    }
    cout << sum2 << endl;
  }
}

Measured memory_bytes: 256
# coding: utf-8
N = int(input())
A = list(map(int, input().split()))

dict = {}
for i in range(N):
  if A[i] in dict.keys():
    dict[A[i]] += 1
  else:
    dict[A[i]] = 1

def comb(n):
  if n<2:
    return 0
  return int(n * (n - 1) / 2)

# all
ret = 0
for key in dict.keys():
  val = dict[key]
  ret += comb(val)

# i >= 0
for i in range(N):
  val_n = dict[A[i]]
  next_ret = ret - comb(val_n) + comb(val_n - 1)
  print(next_ret)

Measured memory_bytes: 26140
#include<bits/stdc++.h>
using ll  = long long;
#define int ll
#define rep(i,n) for(int i=0;i<n;i++)
#define erep(e,v) for(auto && e :v)
#define INF (sizeof(int) == 4 ? (int)1e9:(int)1e18)
using namespace std;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
signed main(){
    int d,g; cin >> d >> g;
    vector<vector<int>>dp(d,vector<int>(100001,0));
    vector<int>lim(d),c(d);
    rep(i,d) cin >> lim[i] >> c[i];
    rep(i,d){
        if (i == 0){
            rep(j,lim[0]){
                dp[0][j+1] = 100 * (j+1) + (j+1 == lim[i] ? c[i]:0);
            }
            continue;
        }
        rep(j,dp[i - 1].size()){
            if(j == 0 or dp[i-1][j] != 0){
                cmax(dp[i][j],dp[i-1][j]);
                rep(k,lim[i]){
                    cmax(dp[i][j + k + 1],dp[i - 1][j] + 100 * (i+1) * (k+1) +
                         (k+1 == lim[i] ? c[i] : 0));
                }
            }
        }
    }
    int ans = INF;
    rep(i,dp.size()){
        rep(j,dp[i].size()){
            if(dp[i][j] >= g)
                cmin(ans,j);
        }
    }
    cout << ans ;
}




Measured memory_bytes: 8832
N = int(input())
A = list(map(int, input().split()))
money = 1000
stock = 0
mi = min(A)
last = -1
for i, (a, b) in enumerate(zip(A, A[1:])):
    if a > b:
        if stock > 0:
            money += stock * a
            stock = 0
            last = money
    elif a < b:
        stock += money // a
        money %= a

now = money + stock * A[-1]


print(max(last, now))

Measured memory_bytes: 61908
#include<iostream>
#include<vector>
#include<cmath>
#include<string>
#include<algorithm>
#include<map>
#include<utility>
#include<cstdio>

using namespace std;

typedef pair<int,bool> Pair;

int main(){

  int N; 
  string S,T;

  cin >> N;
  cin >> S >> T;

  for(int i =0;i < N;++i) cout << S[i] << T[i];

  cout << endl;

  return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define PI 3.14159265358979323846
#define MAXINF (1e18L)
#define INF (1e9L)
#define EPS (1e-9)
#define MOD ((ll)(1e9+7))
#define REP(i, n) for(int i=0;i<int(n);++i)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define ALL(v) v.begin(),v.end()
#define FIND(v,x) (binary_search(ALL(v),(x)))
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v));reverse(ALL(v))
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define YES(n) cout<<((n)?"YES":"NO")<<endl
#define pb push_back
#define fi first
#define se second
using namespace std;
template<class A>void pr(A a){cout << (a) << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;pr(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;pr(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;pr(b,c,d);}
template<class T> inline bool chmin(T& a, T b){return a>b ? a=b, true : false;}
template<class T> inline bool chmax(T& a, T b){return a<b ? a=b, true : false;}
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;

int main(void)
{
    int N;
    cin >> N;
    vector<pll> v;
    REP(i, N){
        ll X,L;
        cin >> X >> L;

        v.pb(pll(X+L, X-L));
    }
    SORT(v);

    int ans = 0;
    ll end = -MAXINF;
    REP(i, N){
        if(end <= v[i].se){
            ans++;
            end = v[i].fi;
        }
    }
    pr(ans);
}

Measured memory_bytes: 2420
#include<bits/stdc++.h>
#define ll long long
#define F first
#define S second
using namespace std;

vector<ll> factorial = {1, 1, 2, 6, 24, 120, 720, 5040, 40320 };

double distance(ll x1, ll x2, ll y1, ll y2) {
    return sqrt((x1 - x2)*(x1 - x2) + (y1 - y2)*(y1 - y2));
}

int main(int argc, char const *argv[])
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    ll N;
    cin >> N;
    ll fac = factorial[N];

    vector<pair<int, int>> points(N);
    for (int i = 0; i < N; i++) {
        cin >> points[i].F >> points[i].S;
    }

    long double contri = 2*factorial[N - 1];
    long double answer = 0;
    for (int i = 0; i < N; i++) {
        for (int j = i + 1; j < N; j++) {
            answer += contri*(distance(points[i].F, points[j].F, points[i].S, points[j].S));
        }
    }

    cout << setprecision(12) << answer/fac;

    return 0;
}

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

using namespace std;

int main(void){
    int N, M;
    cin >> N >> M;
    vector<vector<int>> v(N, vector<int>(N, 0));
    for(int i=0;i<M;i++){
        int a, b;
        cin >> a >> b;
        a--; b--;
        v[a][b]++;
        v[b][a]++;
    }

    for(int i=0;i<N;i++){
        int ans = 0;
        for(int k=0;k<N;k++){
            ans += v[i][k];
        }
        cout << ans << endl;
    }
    return 0;
}

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

using namespace std; 
  
int main() {
  map <string, int> s;
  s["SUN"] = 7;
  s["MON"] = 6;
  s["TUE"] = 5;
  s["WED"] = 4;
  s["THU"] = 3;
  s["FRI"] = 2;
  s["SAT"] = 1;
  string x; cin >> x;
  cout << s[x] << '\n';
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
using LL = long long;
const LL LINF = 1e18;
const double EPS = 1e-10;
using namespace std;
class Edge{
public:
    int from,to,value;
    Edge(LL a,LL b,LL c){
        from = a;
        to = b;
        value = c;
    }
    Edge(LL a,LL b){
        from = a;
        to = b;
    }
};

int main(){
    int N;cin >> N;
    vector<int> vec;
    for(int i = 0;i < N;i++){
        int b;cin >> b;
        vec.push_back(b);
    }
    sort(vec.begin(),vec.end());
    int b = N/2;
    cout<<vec.at(b)-vec.at(b-1)<<endl;
}


Measured memory_bytes: 892
#include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<algorithm>
#include<functional>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cassert>
#include<ctime>
using namespace std;

#define mind(a,b) (a>b?b:a)
#define maxd(a,b) (a>b?a:b)
#define absd(x) (x<0?-(x):x)
#define pow2(x) ((x)*(x))
#define rep(i,n) for(int i=0; i<n; ++i)
#define repr(i,n) for(int i=n-1; i>=0; --i)
#define repl(i,s,n) for(int i=s; i<=n; ++i)
#define replr(i,s,n) for(int i=n; i>=s; --i)
#define repf(i,s,n,j) for(int i=s; i<=n; i+=j)
#define repe(e,obj) for(auto e : obj)

#define SP << " " <<
#define COL << " : " <<
#define COM << ", " <<
#define ARR << " -> " <<
#define PNT(STR) cout << STR << endl
#define POS(X,Y) "(" << X << ", " << Y << ")"
#define DEB(A) " (" << #A << ") " << A
#define DEBREP(i,n,val) for(int i=0; i<n; ++i) cout << val << " "; cout << endl
#define ALL(V) (V).begin(), (V).end()
#define INF 1000000007
#define INFLL 1000000000000000007LL
#define EPS 1e-9

typedef unsigned int uint;
typedef unsigned long ulong;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
#define P_TYPE int
typedef pair<P_TYPE, P_TYPE> P;
typedef pair<P, P_TYPE> PI;
typedef pair<P_TYPE, P> IP;
typedef pair<P, P> PP;
typedef priority_queue<P, vector<P>, greater<P> > pvqueue;

#define N 100007

int n;
ll m;
vector<P> g[N];

ll memo[2*N];
ll dfs0(int v, int p, int e) {
  ll r = 1;
  repe(&pr, g[v]) {
    int w = pr.first, d = pr.second;
    if(w == p) continue;
    r *= 1 + dfs0(w, v, d);
    r %= m;
  }
  return memo[e] = r;
}

ll lv[2*N], rv[2*N];
void dfs1(int v, int p, ll par) {
  ll s = 1 + par;
  repe(&pr, g[v]) {
    int w = pr.first, d = pr.second;
    if(w == p) continue;
    lv[d] = s;
    s *= 1 + memo[d];
    s %= m;
  }
  s = 1;
  repr(i, g[v].size()) {
    P &pr = g[v][i];
    int w = pr.first, d = pr.second;
    if(w == p) continue;
    rv[d] = s;
    s *= 1 + memo[d];
    s %= m;
  }
  repe(&pr, g[v]) {
    int w = pr.first, d = pr.second;
    if(w == p) continue;
    dfs1(w, v, memo[d^1] = lv[d] * rv[d] % m);
  }
}

int main() {
  scanf("%d %lld", &n, &m);
  rep(i, n-1) {
    int x, y; scanf("%d %d", &x, &y); --x; --y;
    g[x].push_back(P(y, 2*i));
    g[y].push_back(P(x, 2*i+1));
  }
  rep(i, 2*n) memo[i] = -1;
  dfs0(0, -1, 2*n);
  dfs1(0, -1, 0);
  rep(v, n) {
    ll r = 1;
    repe(&p, g[v]) {
      int w = p.first, d = p.second;
      r *= 1 + memo[d];
      r %= m;
    }
    printf("%lld\n", r);
  }
  return 0;
}

Measured memory_bytes: 16000
#include<bits/stdc++.h>
#define ll long long
#define vi vector<int>
#define vll vector<ll>
#define F first
#define S second
#define f(i,s,n) for(int i=(int)s;i<=(int)n;++i)
#define Fast ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
using namespace std;
const int N=1e5+10;
int dp[N];
vi a(N);
int find(int i,int n){
	if(i==n-1)
	return dp[i]=0;
	if(dp[i]!=-1)
	return dp[i];
	return dp[i]=min(abs(a[i]-a[i+1])+find(i+1,n),find(min(i+2,n-1),n)+abs(a[i]-a[min(i+2,n-1)]));
}
void solve()
{
	int n;cin>>n;
	int ans=0;
	f(i,0,n-1)cin>>a[i];
//	cout<<"HII\n";
	cout<<find(0,n);
}
int main()
{	Fast;
	memset(dp,-1,sizeof(dp));
//	int t;
//	cin>>t;
//	while(t--)
	solve();
}

Measured memory_bytes: 7116
#include <algorithm>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
// const int INF = (1 << 30) - 1;
// const ll LL_INF = (1LL << 62) - 1;
// const ll MOD = 1e9 + 7;

int N, X;
vector<int> L;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> N >> X;
  L.resize(N);
  for (int i = 0; i < N; i++) {
    cin >> L[i];
  }

  int ans = 1;
  int cur = 0;
  for (int i = 0; i < N; i++) {
    cur += L[i];
    if (cur <= X) {
      ans++;
    }
  }

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

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

using namespace std;

const int MOD = 1000000007;

int main() {
    string S;
    cin >> S;
    if (S == "SUN") {
        cout << 7 << endl;
    } else if (S == "MON") {
        cout << 6 << endl;
    } else if (S == "TUE") {
        cout << 5 << endl;
    } else if (S == "WED") {
        cout << 4 << endl;
    } else if (S == "THU") {
        cout << 3 << endl;
    }else if(S=="FRI"){
        cout<<2<<endl;
    }else if(S=="SAT"){
        cout<<1<<endl;
    }
    
    


}





Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

int main()
{
    while(1)
    {
        int x[6];
        rep(i,6) cin >>x[i];

        int s = 0;
        rep(i,6) s += x[i];
        if(s==0) break;

        int a = x[0] + x[3];
        int b = x[1] + x[4];
        int c = x[2] + x[5];

        int m = min({a,b,c});

        int ans = 0;
        for(int i=m; i>=max(0,m-3); --i) ans = max(ans, i+(a-i)/3+(b-i)/3+(c-i)/3);
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int A = sc.nextInt();
        int B = sc.nextInt();


        if(A==B) {
            System.out.println(A + A);
        } else if(A>B) {
            System.out.println(A + (A-1));
        } else {
            System.out.println(B + (B-1));
        }


    }
}

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

vector<int> s[2];
vector<ull> u[2];

const int N = 500;
int n;
int val[2][N];
int d[N][N];

void flip() {
    rep(i,n)rep(j,i) {
        swap(d[i][j], d[j][i]);
    }
}
bool solve() {
    rep(i,n)rep(j,n) d[i][j] = -1;
    rep(k,2) {
        rep(i,n) {
            int x = val[k][i];
            if (s[k][i] != x) {//0 and    1   or
                rep(j,n) {
                    if (d[i][j] == !x) return false;
                    d[i][j] = x;
                }
            }
        }
        flip();
    }

    bool changed = false;
    /*rep(_,2) */{
        rep(k,2) {
            rep(i,n) {
                int x = val[k][i];
                if (s[k][i] == x) {//0 and    1   or
                    vector<int> p;
                    bool ok = false;
                    rep(j,n) {
                        if (d[i][j] == -1) p.push_back(j);
                        if (d[i][j] == x) ok = true;
                    }
                    if (ok) continue;
                    if (p.size() == 0) return false;
                    if (p.size() == 1) {
                        d[i][p[0]] = x;
                        changed = true;
                    }
                }
            }
            flip();
        }
    }

    if (changed){
        rep(k,2) {
            if (k==0)
            rep(i,n) {
                int x = val[k][i];
                if (s[k][i] == x) {//0 and    1   or
                    vector<int> p;
                    bool ok = false;
                    rep(j,n) {
                        if (d[i][j] == -1) p.push_back(j);
                        if (d[i][j] == x) ok = true;
                    }
                    if (ok) continue;
                    if (p.size() == 0) return false;//need this the second iteration
                    if (p.size() == 1) {
                        d[i][p[0]] = x;
                    }
                }
            }
            flip();
        }
    }

    vector<int> is, js;
    rep(i,n) {
        bool filled = true;
        rep(j,n) if (d[i][j] == -1) filled = false;
        if (!filled) is.push_back(i);
    }
    rep(j,n) {
        bool filled = true;
        rep(i,n) if (d[i][j] == -1) filled = false;
        if (!filled) js.push_back(j);
    }
    rep(i,is.size())rep(j,js.size()) {
        d[is[i]][js[j]] = (i+j)%2;
    }
    return true;
}

ull ans[N][N];

int main() {
    cin >> n;
    rep(i,2) {
        s[i] = vector<int>(n);
        rep(j,n) cin >> s[i][j];
    }
    rep(i,2) {
        u[i] = vector<ull>(n);
        rep(j,n) cin >> u[i][j];
    }

    rep(b,64) {
        rep(i,2)rep(j,n) val[i][j] = u[i][j]>>b&1;
        if (!solve()) {
            cout << "-1" << endl;
            return 0;
        }
        rep(i,n)rep(j,n) ans[i][j] |= ull(d[i][j])<<b;
    }
    rep(i,n) {
        rep(j,n) {
            cout<<ans[i][j]<<(j==n-1?'\n':' ');
        }
    }
    return 0;
}


Measured memory_bytes: 8400
def convp(p)
  st = []
  while p.size > 0
    x = p.shift
    case x
    when "+" then st.push(st.pop+st.pop)
    when "-" then st.push(-st.pop+st.pop)
    when "*" then st.push(st.pop*st.pop)
    when "/" then st.push(1.0/st.pop*st.pop)
    else st << x.to_f end
  end
  return st
end

while gets
  ln = $_.split.map(&:to_s)
  puts convp(ln)
end

Measured memory_bytes: 8636
#include <cstdio>

int main() {
	int n, x, t;
	scanf ("%d %d %d", &n, &x, &t);
	int t_ = n / x + 1;
	if(n % x == 0)
		t_--;
	printf("%d\n", t_ * t);
	return 0;
}

Measured memory_bytes: 3228
#include<bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define lli long long int
#define ulli unsigned long long int
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define pf pop_front()
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define loopl(i,a,b) for(lli i=a;i<b;i++) 
#define loop(i,a,b) for(int i=a;i<b;i++)
#define mod 1000000007
#define inf 1000000000000000000
#define lld long double
#define pll pair<long long int,long long int>
#define vll vector<lli>
#define eps 0.000001
#define endl '\n'
#define mo 998244353
 
using namespace std ;
 
#define MAXN 10000000 + 2
 
typedef tree<pll,null_type,less<pll>,rb_tree_tag,
tree_order_statistics_node_update> indexed_set;

int main()
{
////////////////////////////////////////////
    fastio;
    
    lli n,m;
    cin>>n>>m;

    lli a[n];
    loopl(i,0,n) cin>>a[i];

    sort(a,a+n);

    pll p[m];
    loopl(i,0,m)
    {
        cin>>p[i].ss>>p[i].ff;
    }

    sort(p,p+m,greater<pll>());

    lli i=0,j=0;

    while(i<=n-1 && j<=m-1)
    {
        lli k = p[j].ss , oo = i;

        lli flag=0;
        for(i;i<oo+k;i++)
        {
            if(a[i] < p[j].ff)
                a[i] = p[j].ff;

            else
            {
                flag=1;
                break;
            }
        }
        j++;

        if(flag==1) break;
    }

    lli cnt=0;

    loopl(i,0,n) 
    {
        //cout<<a[i]<<" ";
        cnt+=a[i];
    }

    cout<<cnt<<endl;
}


Measured memory_bytes: 2688
#include <cstdio>

int main(){
  int q1,b,c1,c2,q2;

  while(scanf("%d" ,&q1) ,q1){
    scanf("%d %d %d %d" ,&b ,&c1 ,&c2 ,&q2);

    int cnt1 = b / c1;
    if(cnt1 > q2){
      cnt1 = q2;
    }
    b -= cnt1 * c1;

    int cnt2 = b / c2;
    if(cnt2 < 0){
      cnt2 = 0;
    }
    b -= cnt2 * c2;

    while(true){
      if(cnt1 + cnt2 >= q1 || cnt1 <= 0){    
	break;	
      } 

      cnt1--;
      b += c1;

      b += cnt2 * c2;
      cnt2 = b / c2;
      b -= cnt2 * c2;
    }

    if(cnt1 <= 0){
      puts("NA");
    }else{
      printf("%d %d\n" ,cnt1 ,cnt2);
    }
  }

  return 0;
}

Measured memory_bytes: 1040
def combination(A, B, C, X):
    x = X/50
    
    count = 0
    for a in range(A+1):
        for b in range(B+1):
            for c in range(C+1):
                if 10*a + 2*b + c == x:
                    count += 1
    return count
        
if __name__ == '__main__':
    A = int(input())
    B = int(input())
    C = int(input())
    X = int(input())
    print(combination(A, B, C, X))

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
using lli = long long;
#define rep(i,n) for(int i=0;i<n;i++)
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; }

lli n;

int main(void){
	cin >> n;
	lli dp[n+5][3];
	rep(i, 3) dp[0][i] = 0;
	rep(i, n){
		lli a, b, c;
		cin >> a >> b >> c;
		dp[i+1][0] = max(dp[i][1], dp[i][2])+a;
		dp[i+1][1] = max(dp[i][2], dp[i][0])+b;
		dp[i+1][2] = max(dp[i][0], dp[i][1])+c;
	}
	cout << max({dp[n][0], dp[n][1], dp[n][2]}) << endl;
	return 0;
}


Measured memory_bytes: 5976
#include "bits/stdc++.h"

using namespace std;
typedef long long ll;
#define rep(i,j,n) for (ll i = j; i < (n); i++)
#define CLR(mat,f) memset(mat, f, sizeof(mat))
#define IN(a, b, x) (a<=x&&x<b)
#define out(ans) cout << ans << endl
typedef pair<ll, ll>P;
const ll mod = 1e9 + 7;
const int INF = 1000000;
const double PI = 3.14159265359;


int main() {

	int n, m; cin >> n >> m;

	if (n == m)out("Yes");
	else out("No");



	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define LL long long 
#define INF 12000000000
using namespace std;
int main(){
    LL x,y,ans = INF;
   	cin>>x>>y;
    if(x % 3 == 0 || y % 3 == 0)
       	cout<<0;
    else
    {
        if(x < y) x ^= y ^= x ^= y;
        ans = y;
        LL tem=0,tem_=12000000000;
        for(int i = x/3; i <= x/3+1; i++)
            for(int j = y/2; j <= y/2+1; j++)
            {
                tem=0,tem_=12000000000;
                tem=max(y*i, tem);
                tem=max(tem, (x-i)*j);
                tem=max(tem, (x-i)*(y-j));
                tem_=min(y*i, tem_);
                tem_=min(tem_, (x-i)*j);
                tem_=min(tem_, (x-i)*(y-j));
                ans = min(ans, tem - tem_);
            }
        for(int i = y/3; i <= y/3+1; i++)
            for(int j = x/2; j <= x/2+1; j++)
            {
                tem = 0, tem_ =12000000000;
                tem=max(x*i, tem);
                tem=max(tem, (y-i)*j);
                tem=max(tem, (y-i)*(x-j));
                tem_=min(x*i, tem_);
                tem_=min(tem_, (y-i)*j);
                tem_=min(tem_, (y-i)*(x-j));
                ans = min(ans, tem - tem_);
            }
       	cout<<ans;
    }
    return 0;
}

Measured memory_bytes: 256
N,K,*A=map(int,open(0).read().split())
A.sort()
M=10**9+7
S=0
C=1
for k in range(K,N+1):S+=C*(A[k-1]-A[-k]);C=C*k*pow(k-K+1,M-2,M)%M
print(S%M)

Measured memory_bytes: 14060
INF = 10 ** 18

n = int(input())
a = [int(i) for i in input().split()]

if 0 in a:
    print(0)
    exit()

ans = 1
for i in range(len(a)):

    ans = ans * a[i]
    if ans > INF:
        print("-1")
        exit()

print(ans)

Measured memory_bytes: 21708
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <cmath>
#define FUP(i,x,y) for(int i=(x);i<=(y);i++)
#define FDW(i,x,y) for(int i=(x);i>=(y);i--)
#define MAXN 40
#define INF 0x3f3f3f3f
#define MOD 1000000007
#define ll long long
#define db double
using namespace std;
int read(){
    int w=0,flg=1;
    char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')flg=-1;ch=getchar();}
    while(ch<='9'&&ch>='0'){w=w*10-'0'+ch,ch=getchar();}
    return w*flg;
}
int n,m1,m2,a,b,c,ans=INF,cnt=1,suma,sumb;
int f[410][410];
int main(){
	memset(f,0x3f,sizeof(f));
	f[0][0]=0;
	n=read(),m1=read(),m2=read();
	FUP(i,1,n)
	{
		a=read(),b=read(),c=read();
		suma+=a,sumb+=b;
		FDW(j,suma,a)
		{
			FDW(k,sumb,b)
			{
				f[j][k]=min(f[j][k],f[j-a][k-b]+c);
				if(j*1.0/m1==k*1.0/m2) ans=min(ans,f[j][k]);
			}
		}
	}
	printf("%d\n",ans==INF?-1:ans);
    return 0;
}

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

int main(void){
    int n,m;
    cin >> n >> m;
    int p[m];
    string s[m];
    for(int i = 0;i < m;i++)cin >> p[i] >> s[i];
    int ans[1000000] = {},num[1000000] = {};
    for(int i = 0;i < m;i++){
        if(s[i] == "WA" && num[p[i]] == 0){
            ans[p[i]]++;
        } else if(s[i] == "AC"){
            num[p[i]]++;
        }
    }
    int sum1 = 0,sum2 = 0;
    for(int i = 0;i < n+1;i++){
        if(ans[i] > 0 && num[i] > 0)sum1 += ans[i];
        if(num[i] > 0)sum2++;
    }
    cout << sum2 << " " << sum1;
}


Measured memory_bytes: 13952
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <utility>
#include <queue>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <climits>
using namespace std;

#define MOD1097 1000000007

#define ll long long
#define pint pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define mpair make_pair
#define pm(first, second) pb(mpair(first, second))
#define SPACE " "
#define fpf first.first
#define fps first.second
#define spf second.first
#define sps second.second

#define all(X) (X).begin(), (X).end()
#define reall(X) (X).rbegin(), (X).rend()
#define divcel(a, b) (((a) + ((b) - 1)) / (b))

int main(){

	int a, b;
	cin >> a >> b;
	cout << 6-a-b << endl;

	return 0;
}


Measured memory_bytes: 3532
def make_divisor_list(num):
    if num < 1:
        return []
    elif num == 1:
        return [1]
    else:
        divisor_list = []
        divisor_list.append(1)
        for i in range(2, num // 2 + 1):
            if num % i == 0:
                divisor_list.append(i)
        divisor_list.append(num)

        return divisor_list

if __name__ == "__main__":
    A, B = [int(i) for i in input().split()]
    B_list = make_divisor_list(B)
    if A in B_list:
        print(A+B)
    elif A not in B_list:
        print(B-A)


Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <algorithm>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
string s, t, B = "~";
bool isOK(string ss,string t)
{//sをi文字目からtと同じ文字数で切り取ったものがssとして届く
 //cout << ss<<":"<<t<<endl;
 rep(i,ss.size())
 { 
   if(ss[i]!='?'&&ss[i]!=t[i])
   {return false;}
 }
 //cout<<"true!"<<endl;
 return true;

}
int main() {
	cin >> s >> t;
	for (int i = 0; i <= (int)s.size() - (int)t.size(); i++) {
		string U = s.substr(i, t.size());
		if (isOK(U, t) == true) {
			string v = s;
			//for (int j = i; j < i + t.size(); j++)v[j] = t[j - i];
			for(int j=0; j<t.size(); j++)
	    	{v[j+i]=t[j];}
			for (int j = 0; j < i; j++) { if (v[j] == '?')v[j] = 'a'; }
			for (int j = i + t.size(); j < v.size(); j++) { if (v[j] == '?')v[j] = 'a'; }
			B = min(B, v);

	  		/*string v=s;
	    	for(int j=0; j<t.size(); j++)
	    	{v[j+i]=t[j];}
	    	//?を置き換え
	 		rep(j,i)//i(挿入開始地点)まで見る
	 		{if(v[j]=='?')v[j]='a';}
	 		for(int j=i+t.size(); j <s.size();j++)
	 		{if(v[j]=='?')v[j]='a';}*/
		}
	}
	if (B == "~")cout << "UNRESTORABLE" << endl;
	else cout << B << endl;
	return 0;
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)
var out = bufio.NewWriter(os.Stdout)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}

func main() {
	buf := make([]byte, 1024*1024)
	sc.Buffer(buf, bufio.MaxScanTokenSize)
	sc.Split(bufio.ScanWords)
	defer out.Flush()

	N := nextInt()
	ac, wa, tle, re := 0, 0, 0, 0
	for i := 0; i < N; i++ {
		s := next()
		if s == "AC" {
			ac++
		} else if s == "WA" {
			wa++
		} else if s == "TLE" {
			tle++
		} else if s == "RE" {
			re++
		}
	}

	fmt.Fprintf(out, "AC x %d\n", ac)
	fmt.Fprintf(out, "WA x %d\n", wa)
	fmt.Fprintf(out, "TLE x %d\n", tle)
	fmt.Fprintf(out, "RE x %d\n", re)
}


Measured memory_bytes: 2180
#include <bits/stdc++.h>
using namespace std;
struct Fast {
    Fast() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(20);
    }
} fast;

int r, p, s;

int opnum(char x) {
    if (x == 's') {
        return (r);
    }
    if (x == 'r') {
        return (p);
    }
    if (x == 'p') {
        return (s);
    }
    return 0;
}
char op(char x) {
    if (x == 's') {
        return ('r');
    }
    if (x == 'r') {
        return ('p');
    }
    if (x == 'p') {
        return ('s');
    }
    return 0;
}

int main() {
    long a, b, c;
    cin >> a >> b >> c;
    cout << max(0l, c - (a - b)) << endl;
}

Measured memory_bytes: 256
#include <atcoder/mincostflow>
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<ll,ll>;

struct Convert_ID_HW {
    ll H, W;
    Convert_ID_HW(ll H, ll W) : H(H), W(W) {}
    ll id(ll h_, ll w_) { return h_*W + w_;}
    ll h(ll id_) { return id_/W;}
    ll w(ll id_) { return id_%W;}
};

ll solve() {
    ll N, M;
    cin >> N >> M;
    vector<string> S(N);
    for ( int i = 0; i < N; i++ ) cin >> S[i];

    ll NM = N*M;
    Convert_ID_HW ix(N,M);
    atcoder::mcf_graph<ll,ll> g(2*NM+2);
    int id_f = 2*NM, id_t = 2*NM+1;
    ll n_o = 0;
    for ( int i = 0; i < N; i++ ) {
        for ( int j = 0; j < M; j++ ) {
            if ( S[i][j] == 'o' ) {
                g.add_edge(id_f, ix.id(i,j),1,0);
                n_o++;
            }
            g.add_edge(NM+ix.id(i,j),id_t,1,0);
        }
    }    
    for ( int i0 = 0; i0 < N; i0++ ) {
        for ( int j0 = 0; j0 < M; j0++ ) {
            if ( S[i0][j0] == 'o' ) {
                vector<vector<int>> d(N, vector<int>(M,-1));
                priority_queue<pii> q;
                d[i0][j0] = 0;
                q.push(pii(0,ix.id(i0,j0)));
                for ( int i = 0; i < N; i++ ) {
                    for ( int j = 0; j < M; j++ ) {
                        if ( i+1 < N && d[i][j] >= 0 && S[i+1][j] != '#') {
                            if ( d[i+1][j] < d[i][j]+1 ) {
                                d[i+1][j] = d[i][j]+1;
                                q.push(pii(d[i+1][j],ix.id(i+1,j)));
                            }
                        }
                        if ( j+1 < M && d[i][j] >= 0 && S[i][j+1] != '#') {
                            if ( d[i][j+1] < d[i][j]+1 ) {
                                d[i][j+1] = d[i][j]+1;
                                q.push(pii(d[i][j+1],ix.id(i,j+1)));
                            }
                        }
                    }
                }
                ll n_e = 0;
                while ( !q.empty() && n_e < n_o + min(N,M)) {
                    int id = q.top().second;
                    ll dd = q.top().first;
                    int i = ix.h(id), j = ix.w(id);
                    q.pop();
                    if ( d[i][j] == dd ) {
                        g.add_edge(ix.id(i0,j0), NM+ix.id(i,j), 1, N+M-dd);
                        n_e++;
                    }
                }
            }
        }
    }

    auto c = g.flow(id_f,id_t);
    auto v = g.edges();
    ll ans = (N+M)*n_o - c.second;
    return ans;
}

int main() {
    auto ans = solve();
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 5260
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
ll s,x1,x2,x3,y1,y2,y3;
int main(){
	scanf("%lld",&s);
	x1=0; y1=0;
	x2=1e9; y2=1;
	x3=1e9-s%int(1e9); y3=s/int(1e9)+1;
	if (s==1e18) x3=0,y3=1e9;
	printf("%lld %lld %lld %lld %lld %lld\n",x1,y1,x2,y2,x3,y3);
	return 0;
}


Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;


public class Test
{
	public static void Main( )
	{
		int n = int.Parse( Console.ReadLine().Trim() );
		int[] S = new int[n];
		S = Console.ReadLine().Trim().Split().Select( x => int.Parse( x )  ).ToArray();
		
		int q = int.Parse( Console.ReadLine().Trim() );
		int[] T = new int[q];
		T = Console.ReadLine().Trim().Split().Select( x => int.Parse( x )  ).ToArray();

		int cnt = 0;
		for( int i=0; i<q; i++ ) {
			for( int j=0; j<n; j++ ) {
				if( T[i] == S[j] ) {
					cnt++;
					break;
				}
			}
		}
		Console.WriteLine( cnt );
		return;
	}
}



Measured memory_bytes: 18384
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define REP(i, start, end) for (int i = start, i##Len = (end); i < i##Len; ++i)
#define REPR(i, start, end) for (int i = start, i##Len = (end); i > i##Len; --i)
using ll = long long;
using namespace std;

struct Item
{
    ll x, y, p;
    vector<ll> x_cost, y_cost;
    ll defcost = 0;

    Item(ll x, ll y, ll p, ll n) : x(x), y(y), p(p)
    {
        defcost = min(abs(x), abs(y)) * p;
        x_cost.assign(1 << n, defcost);
        y_cost.assign(1 << n, defcost);
    }

    ll get_cost_x(ll dist)
    {
        return min(defcost, abs(x - dist) * p);
    }

    ll get_cost_y(ll dist)
    {
        return min(defcost, abs(y - dist) * p);
    }
};

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

    ll n, x, y, p;
    cin >> n;
    vector<Item> a;
    REP(i, 0, n)
    {
        cin >> x >> y >> p;
        a.emplace_back(x, y, p, n);
    }

    REP(bit, 0, 1 << n)
    REP(i, 0, n)
    if ((1 << i) & bit)
        REP(j, 0, n)
        {
            a[j].x_cost[bit] = min(a[j].x_cost[bit], a[j].get_cost_x(a[i].x));
        }
    REP(bit, 0, 1 << n)
    REP(i, 0, n)
    if ((1 << i) & bit)
        REP(j, 0, n)
        {
            a[j].y_cost[bit] = min(a[j].y_cost[bit], a[j].get_cost_y(a[i].y));
        }

    int N = 1;
    REP(_, 0, n)
    N *= 3;
    vector<ll> ans(n + 1, 1LL << 60);
    REP(bit, 0, N)
    {
        int x = bit, popcnt = 0;
        int bits[3] = {};
        REP(i, 0, n)
        {
            if (x % 3)
            {
                bits[x % 3] |= (1 << i);
                ++popcnt;
            }
            x /= 3;
        }
        ll cost = 0;
        REP(i, 0, n)
        cost += min(a[i].x_cost[bits[1]], a[i].y_cost[bits[2]]);
        ans[popcnt] = min(ans[popcnt], cost);
    }

    REP(i, 0, n + 1)
    cout << ans[i] << "\n";
}

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


#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
const int MD = (int)1e9 + 7; typedef vector<ll> VL;
void dbg(){ cerr << "\n"; }  template <class T, class ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }
template <class T> void amax(T& a,T b){ a=max(a,b);}


int main() {
	//cin.tie(0); ios_base::sync_with_stdio(false);
	int n;
	cin >>n;
	vector<string> vs(n);
	VI t(n);
	rep(i, n) cin >> vs[i] >>t[i];
	string s;
	cin >>s;
	
	int k=-1;
	rep(i ,n) if(s==vs[i]) k=i;
	ll ans =0;
	rep2(i, k+1, n) ans +=t[i];
	cout << ans <<"\n";
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

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


int main() {
int H,W;
cin>>H>>W;
int h,w;
cin>>h>>w;
cout<<(H-h)*(W-w)<<endl;

}



Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
  int h,m,s,hh,mm,ss;
  for(int i=0;i<3;i++){
    cin >> h >> m >> s >> hh >> mm >> ss;    
    h = (hh - h);
    m = (mm - m);
    s = (ss - s);
    if (s<0){
      s += 60;
      m--;
    }
    if (m<0){
      m += 60;
      h--;
    }
    cout << h << " " << m << " " << s << endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include <stdio.h>
int main(void)
{
	int n,x,y,b,p,i,g,t,m;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d%d%d%d",&x,&y,&b,&p);
		g=x*b+y*p;
		if(b>=5&&p>=2)
		{
			m=0.8*(x*b+y*p);
			printf("%d\n",m);
		}
		else
		{
		if(b<5)
		{
			b=5;
		}
		if(p<2)
		{
			p=2;
		}
		t=0.8*(x*b+y*p);
		if(g<t)
		{
			printf("%d\n",g);
		}
		else
		{
			printf("%d\n",t);
		}
		}
	}
	return 0;
}

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

using namespace std;
typedef long long ll;

int main() {
  ll n, ans = 0, x;
  cin >> n;
  unordered_map<ll, ll> mp;
  for (int i = 1; i <= n; ++i) scanf("%lld", &x), ans += mp[i - x], mp[i + x]++;
  printf("%lld", ans);
  return 0;
}


Measured memory_bytes: 18504
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
)

var (
	readString func() string
	stdout     *bufio.Writer
)

func init() {
	readString = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = readInt()
	}
	return b
}

func readLengthAndSlice() []int {
	n := readInt()
	return readIntSlice(n)
}

func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(stdout, f, args...)
}

func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(stdout, args...)
}

func minInt(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func minUint(a, b uint) uint {
	if a < b {
		return a
	}
	return b
}

func minInt64(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}

func minUint64(a, b uint64) uint64 {
	if a < b {
		return a
	}
	return b
}

func maxInt(a, b int) int {
	if a < b {
		return b
	}
	return a
}

func maxUint(a, b uint) uint {
	if a < b {
		return b
	}
	return a
}
func maxInt64(a, b int64) int64 {
	if a < b {
		return b
	}
	return a
}

func maxUint64(a, b uint64) uint64 {
	if a < b {
		return b
	}
	return a
}

func absInt(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func absInt64(a int64) int64 {
	if a < 0 {
		return -a
	}
	return a
}

// readString() string
// readInt() int
// readIntSlice(n int) []int
// readLengthAndSlice() []int
func main() {
	defer stdout.Flush()
	a := readString()
	b := readString()
	if len(a) < len(b) {
		println("LESS")
		return
	} else if len(b) < len(a) {
		println("GREATER")
		return
	}

	for i := 0; i < len(a); i++ {
		if a[i] < b[i] {
			println("LESS")
			return
		} else if b[i] < a[i] {
			println("GREATER")
			return
		}
	}
	println("EQUAL")
}


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

int main(){
  int n;
  char ch;
  cin>>n;
  for(int i = 0; i < n; i++){
    cin>>ch;
    if(ch == 'Y'){
      cout<<"Four"<<"\n";
      return 0;
    }
  }
  cout<<"Three"<<"\n";
}


Measured memory_bytes: 256
#include<iostream>
#include<map>
#include<vector>
#include<algorithm>
#include<cmath>
#include<climits>
#include<ctime>
#include<cstring>
#include<stack>
#include<queue>

#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define DUMP(list) cout << "{ "; for(auto nth : list){ cout << nth << " "; } cout << "}" << endl;


using namespace std;



int main()
{

  while(true){
    string text;
    getline(cin,text);

    if(text=="."){
      break;
    }

    stack<char> kakko;
    bool flag=true;

    for(int i=0;i<text.length();i++){
      
      //cout << text[i] << endl;
      
      if(text[i]=='('||text[i]=='['){
        kakko.push(text[i]);
      }


      if(text[i]==')'||text[i]==']'){
       if(kakko.empty()){
          flag = false;
          break; 
        }else if((kakko.top()=='(' && text[i]==']')||((kakko.top()=='[' && text[i]==')'))){
          flag = false;
          break;
        }else{
          kakko.pop();
        }
      }

    }
    
    if(!kakko.empty()){
      flag = false;
    }
    
    if(flag){
      cout << "yes" << endl;
    }else{
      cout << "no" << endl;
    }

  }

  return 0;
}

Measured memory_bytes: 1180
import sys
from collections import Counter


def c2f(data):
    num = 0
    while True:
        counter = Counter(data)
        next = [counter[item] for item in data]
        if data == next:
            break
        num += 1
        data = next

    return num, data

while True:
    num = int(sys.stdin.readline())
    if num == 0:
        break
    line = sys.stdin.readline()
    data = [int(item) for item in line.split(' ')]

    num, result = c2f(data)
    print(num)
    print(*result, sep = ' ')

Measured memory_bytes: 8068
class Stack<T> {
    val values = emptyList<T>().toMutableList()

    fun push(value: T) = values.add(value)

    fun pop() = values.removeAt(values.size - 1)

    override fun toString() = values.toString()
}
class Queue<T> {
    val values = emptyList<T>().toMutableList()

    fun enqueue(value: T) = values.add(value)

    fun dequeue() = values.removeAt(0)

    override fun toString() = values.toString()
}

fun <T> List<T>.get1Origin(index: Int) = this[index - 1]
fun <T> List<T>.subList1Origin(fromIndex: Int, toIndex: Int) = this.subList(fromIndex - 1, toIndex - 1)
fun <T> MutableList<T>.set1Origin(index: Int, element: T) = this.set(index - 1, element)
fun <T> MutableList<T>.removeAt1Origin(index: Int) = this.removeAt(index - 1)

fun String.splitToString() = this.split(" ")
fun String.splitToInt() = this.split(" ").map { it.toInt() }
fun String.splitToLong() = this.split(" ").map { it.toLong() }

fun main(args: Array<String>) {
    val (A, B, K) = readLine()!!.splitToLong()

    val (postA, postK) = if (A > K) A - K to 0L else 0L to K - A
    val postB = if (B > postK) B - postK else 0L
    println("$postA $postB")
}


Measured memory_bytes: 37992
#include<bits/stdc++.h>
using namespace std;
#define R register
#define L 200002

inline void read(int &x){
    static int ch; static bool flag;
    for(flag=0,ch=getchar(); ch>'9'||ch<'0'; ch=getchar()) flag |= ch=='-';
    for(x=0; ch>='0'&&ch<='9'; ch=getchar()) x = (x<<1) + (x<<3) + ch-48;
    x = flag ? -x : x; 
}

int N,M,A[L],B[L];
struct edge {int l,r,val;} line[L];

inline bool check(int x){
	for(R int i=1;i<=M;++i) B[i] = A[i]>=x;
	R int cnt=0;
	for(R int i=1,j;i<=M;++i){
		j=i;
		while(j<M && B[i]==B[j+1]) j++;
		if(i==j) continue;
		line[++cnt]=(edge){i,j,B[i]};
		i=j;
	}
	if(!cnt) return B[1];
	line[0].r=0;
	for(R int i=1;i<=cnt;++i){
		R int l=line[i-1].r+1,r=line[i].l-1;
		if(l>r) continue;
		R int mid=l+r>>1;
		line[i-1].r=mid,line[i].l=mid+1;
	}
	R int l=line[cnt].r+1,r=M,mid=l+r>>1;
	if(l<=r) line[cnt].r=mid;
	for(R int i=1;i<=cnt;++i)
		if(line[i].l<=N && N<=line[i].r) return line[i].val;
}

int main()
{
	read(N); M=N*2-1; R int l=1,r=M;
	for(R int i=1;i<=M;++i) read(A[i]);
	while(l<=r){
		R int mid=l+r>>1;
		if(check(mid)) l=mid+1;
		else r=mid-1;
	}
	printf("%d\n",r);
	return 0;
}

/*
4
1 6 3 7 4 5 2
*/

Measured memory_bytes: 2432
#include <stdio.h>
int main(void){
  int X,Y,i;
  scanf("%d %d",&X,&Y);

  for(i=0;i<=X;i++){
    if(2*(X-i) + 4*i == Y){
        printf("Yes\n");
        return 0;
      }
  }
  printf("No\n");
  return 0;
}

Measured memory_bytes: 1608
#pragma comment(linker, "/STACK:10240000")
#include <bits/stdc++.h>

using namespace std;

char s[10];
int a[10], b[10];

int main ()
{
    scanf ("%s", &s);
    for (int i = 0; i < 4; i ++)
    {
        a[i] = s[i] - '0';
    }
    int x, y, z;
    for (int i = -1; i <= 1; i += 2)
    {
        for (int j = -1; j <= 1; j += 2)
        {
            for (int t = -1; t <= 1; t += 2)
            {
                if (a[0] + i * a[1] + j * a[2] + t * a[3] == 7)
                {
                    b[1] = i, b[2] = j, b[3] = t;
                    break;
                }
            }
        }
    }
    printf ("%d", a[0]);
    for (int i = 1; i < 4; i ++)
    {
        if (b[i] == -1)
        {
            printf ("-");
        }
        else
        {
            printf ("+");
        }
        printf ("%d", a[i]);
    }
    printf ("=7\n");
    return 0;
}


Measured memory_bytes: 256
N,L=map(int,input().split())
if L*(L+N-1)<=0:
  print(int((L-1)*N+N*(N+1)/2))
  
elif L<0:
  print(int((L-1)*N+N*(N+1)/2-(L+N-1)))

else:
  print(int((L-1)*N+N*(N+1)/2-L))

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

using namespace std;

const int N = 100000 + 10;

vector<int> G[N];
int prv[N];
int Q[N];
int n, m;

bool bfs(int u)
{
	int p, q, v, i;
	for (i=1; i<=n; i++) prv[i] = -1;
	prv[1] = 0;
	Q[0] = u;
	p = 0;
	q = 1;
	while (p < q)
	{
		u = Q[p];
		for (i=0; i<G[u].size(); i++)
		{
			v = G[u][i];
			if (prv[v] == -1)
			{
				prv[v] = u;
				Q[q++] = v;
			}
		}
		p ++;
	}
	return q == n;
}

int main()
{
	int u, v, i;
	cin>>n>>m;
	for (i=0; i<m; i++)
	{
		cin>>u>>v;
		G[u].push_back(v);
		G[v].push_back(u);
	}
	if (bfs(1))
	{
		cout<<"Yes"<<endl;
		for (i=2; i<=n; i++) cout<<prv[i]<<endl;
	}
	else cout<<"No"<<endl;
	return 0;
}

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


 
int main(){
 int N;
  cin>>N;
  vector<int>a(N);
  for(int i=0;i<N;i++)cin>>a[i];
  int exist=1;
  for(int i=0;i<N;i++){
    if(a[i]==exist){
      exist++;
    }
  }
  exist--;
  if(exist==0)cout<<-1<<endl;
  else{
  cout<<N-exist<<endl;
  }
  }

Measured memory_bytes: 1024
# https://atcoder.jp/contests/abc116/tasks/abc116_c
# C - Grand Garden
import copy

n = int(input().split()[0])
h_list = list(map(int, input().split()))

now_h_list = [0] * n
nokori_h_list = copy.copy(h_list)
# 連続するコマの最小値分だけOK
# 最初の1回は、0以外全部いける
count = 0

for i in range(n):

    while nokori_h_list[i] > 0:
        zero_index = nokori_h_list[i:].index(0) if 0 in nokori_h_list[i:] else - 1
        zero_index += i
        if zero_index < i:
            h_add = min(nokori_h_list[i:])
            count += h_add
            nokori_h_list[i:] = map(lambda x: x - h_add, nokori_h_list[i:])
        else:
            h_add = min(nokori_h_list[i:zero_index])
            count += h_add
            nokori_h_list[i:zero_index] = map(lambda x: x - h_add, nokori_h_list[i:zero_index])
        # print(nokori_h_list)

print(count)

Measured memory_bytes: 3444
import std.stdio;
import std.string;
import std.algorithm;
import std.conv;

void main() {
  int[3] coins;
  int x, ans;

  for (int i = 0; i < 3; i++) {
    coins[i] = readln.chomp.to!int + 1;
  }
  x = readln.chomp.to!int;

  foreach (i; 0..coins[0]) {
    foreach (j; 0..coins[1]) {
      foreach (k; 0..coins[2]) {
        int sum = 500 * i + 100 * j + 50 * k;

        if (sum == x) {
          ans++;
        }
        else if (sum > x) {
          break;
        }
      }
    }
  }

  ans.writeln;
}

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

using i64 = int64_t;

vector<i64> divisor(i64 n) {
    vector<i64> res;
    for (i64 i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            res.push_back(i);
            if (i != n / i)
                res.push_back(n / i);
        }
    }
    return res;
}

int main(){
    int n;
    cin >> n;
    vector<int> v;
    int tmax = 0;
    for(int i=0;i<n;++i){
        int t;
        cin >> t;
        v.push_back(t);
        tmax = max(tmax, t);
    }
    auto div = divisor(tmax);
    sort(div.begin(), div.end());

    int ans = 0;
    for(int i=0;i<n;++i){
        for(int j=0;j<div.size();++j){
            if(v[i] <= div[j]){
                ans += abs(div[j]-v[i]);
                break;
            }
        }
    }

    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 3508
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A,B;
  cin>>A>>B;
  if(B==1){
    cout<<0<<endl;
    return 0;
  }
  if(A>=B){
    cout<<1<<endl;
    return 0;
  }
  int kotae=1;
  int kazu=A;
  while(B>kazu){
    kotae++;
    kazu+=A-1;
    if(B<=kazu)break;
  } 
  cout << kotae<<endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5;
int n,m,tot,head[N],nex[2*N],to[2*N],wi[2*N];
bool vis[N];
void add(int u,int v,int w)
{
    to[++tot]=v;
    nex[tot]=head[u];
    head[u]=tot;
    wi[tot]=w;
}
void dfs(int u)
{
    for(int i=head[u];i;i=nex[i])
    {
        int v=to[i];
        if(!vis[v])
        {
            vis[v]=true;
            dfs(v);
        }
    }
}
int main()
{
    scanf("%d%d",&n,&m);
    for(int i=1;i<=m;i++)
    {
        int u,v,w;
        scanf("%d%d%d",&u,&v,&w);
        add(u,v,w);
        add(v,u,w);
    }
    int ans=0;
    for(int i=1;i<=n;i++)
        if(!vis[i])
    {
        ans++;
        vis[i]=true;
        dfs(i);
    }
    printf("%d\n",ans);
}


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

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

  int n;
  cin >> n;
  vector<int> w(n), acum(n), acumr(n);
  rep(i, 0, n) cin >> w[i];

  acum[0] = w[0];
  acumr[n - 1] = w[n - 1];
  rep(i, 1, n) acum[i] += acum[i - 1] + w[i];
  repr(i, 0, n - 1) acumr[i] += acumr[i + 1] + w[i];

  int ans = 1e9;
  rep(i, 0, n - 1) { ans = min(ans, abs(acum[i] - acumr[i + 1])); }
  cout << ans << endl;
}


Measured memory_bytes: 256