akhauriyash/Code-Regression huggingface dataset:
// see https://gist.github.com/LumaKernel/ff55d49ee1af69b7388f15b707e75c15
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <complex>
#include <random>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> VI;
typedef vector<P> VP;

#define omajinai ios::sync_with_stdio(false);cin.tie(0)

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

#define LFOR(i,a,b) for(ll i=(a);i<(b);++i)
#define RLFOR(i,b,a) for(ll i=(b)-1;i>=(a);--i)

#define ALL(a) (a).begin(),(a).end()
#define UNIQUE(a) (a).erase(unique((a).begin(),(a).end()),(a).end())
#define MP make_pair
#define PB push_back
#define EACH(i,c) REP(i,(int)(c).size())
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

#define dump(x) cerr << "[L " << __LINE__ << "] " << #x << " = " << (x) << "\n";
#define dump2(x,y) cerr << "[L " << __LINE__ << "] " << #x << " = " << (x)\
			<< " , " << #y << " = " << (y) << "\n";

const int INF = 1e9;
const double EPS = 1e-10;

int n,k;
int x[50],y[50];
P ps[50];

bool cmpX(P a, P b){
	return a.first < b.first;
}

bool cmpY(P a, P b){
	return a.second < b.second;
}

ll ans=(ll)INF*INF*4;

void solve(){
	REP(i, n-k+1){
		int mx=INF,Mx=-INF,my=INF,My=-INF;
		REP(j, k){
			mx = min(mx, ps[i+j].first);
			Mx = max(Mx, ps[i+j].first);
			my = min(my, ps[i+j].second);
			My = max(My, ps[i+j].second);
		}
		ans=min(ans, (ll)(Mx-mx) * (My-my));
	}
}

// O(N^2)
int main() {
	cin >> n >> k;
	REP(i, n){cin>>x[i]>>y[i];}
	REP(i, n)REP(j, n)REP(m, n)REP(f, n){
		int x1 = min(min(x[i], x[f]), min(x[j], x[m])),
				x2 = max(min(x[i], x[f]), max(x[j], x[m]));
		int y1 = min(min(y[i], y[f]), min(y[j], y[m])),
				y2 = max(max(y[i], y[f]), max(y[j], y[m]));
		int c = 0;
		REP(l, n){
			if(x1<=x[l] && x[l]<=x2 && y1<=y[l] && y[l]<=y2)
				c++;
		}
		if(c>=k){
			ans = min(ans, (ll)(x2-x1)*(y2-y1));
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int (i) = 0; (i) < (int)(n); i++) 
#define FOR(i, a, b) for(int (i) = a; (i) < (int)b; i++)
#define RREP(i, n) for(int (i)=((int)(n)-1); (i)>=0; i--)
#define RFOR(i, a, b) for(int (i) =((int)(b)-1); (i)>=(int)a; i--)
#define ALL(v) (v).begin(),(v).end()
#define MOD 1000000007
#define FT first
#define SC second

using namespace std ;
typedef long long ll;
typedef vector<int> vint;
typedef vector<vint> vvint;
typedef pair<int, int> pint;
const int INF = 1e9;
const double EPS = 1e-9;



int main()
{
    int a, b, c ;
    cin >> a >> b >> c ;
    if(a<b && b<c){
        cout <<"Yes"<<endl ;
    }
    else{
        cout <<"No"<<endl ;
    }

  return 0 ;
}


Measured memory_bytes: 3064
#include <iostream>
using namespace std;
int main()
{
    int X,A,B;
    cin >> X >> A >> B;
    int C = B-A;
    if(C<=0) cout << "delicious" << endl;
    else if(C<=X) cout << "safe" << endl;
    else cout << "dangerous" << endl;
	return 0;
}

Measured memory_bytes: 256
S = input()

from collections import defaultdict

dic = defaultdict(int)

for s in S:
    dic[s] += 1

if len(dic) == 2:
    for k, v in dic.items():
        if v == 2:
            continue
        else:
            print("No")
            exit()
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3316
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LS()
    return l
sys.setrecursionlimit(1000000)
mod = 1000000007

#A
def A():
    x = S()
    s = 0
    ans = len(x)
    for i in x:
        if i == "S":
            s += 1
        else:
            if s > 0:
                s -= 1
                ans -= 2
    print(ans)
    return

#B
def B():
    n = I()
    a = LI()
    f = [0 for i in range(n+1)]
    for i in range(n):
        f[a[i]] = i
    l = [i for i in range(n+1)]
    r = [i for i in range(n+1)]
    ans = 0
    for i in range(1,n+1)[::-1]:
        j = f[i]
        ans += (j-l[j]+1)*(r[j]-j+1)*i
        l[r[j]+1] = l[j]
        r[l[j]-1] = r[j]
    print(ans)
    return

#C
def C():
    n,x = LI()
    if x == 1 or x == 2*n-1:
        print("No")
        quit()
    else:
        ans = [i+1 for i in range(2*n-1)]
        k = x-n
        if k < 0:
            ans = ans[2*n-1+k:]+ans[:2*n-1+k]
        if k > 0:
            ans = ans[k:]+ans[:k]
        print("Yes")
        for i in ans:
            print(i)
    return

#D
def D():
    s = S()
    t = S()
    n = len(s)
    m = len(t)
    fs = [1 if s[i] == "A" else 2 for i in range(n)]
    ft = [1 if t[i] == "A" else 2 for i in range(m)]
    for i in range(n-1):
        fs[i+1] += fs[i]
        fs[i+1] %= mod
    for i in range(m-1):
        ft[i+1] += ft[i]
        ft[i+1] %= mod
    fs.insert(0,0)
    ft.insert(0,0)
    q = I()
    for i in range(q):
        a,b,c,d = LI()
        a -= 1
        c -= 1
        if (fs[b]-fs[a])%3 == (ft[d]-ft[c])%3:
            print("YES")
        else:
            print("NO")
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == "__main__":
    D()


Measured memory_bytes: 69000
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
*/

int main(){
    int H,W; cin >> H >> W;
    char field[H][W];
    char c[H][W];

    for(int i=0; i<H; i++) for(int j=0; j<W; j++) cin >> c[i][j];

    int height = 0;
    for(int i=0; i<H; i++){
        bool flg = false;
        for(int j=0; j<W; j++) if(c[i][j] == '#') flg = true;

        if(flg){
            for(int j=0; j<W; j++) field[height][j] = c[i][j];
            height++;
        }
    }

    // for(int i=0; i<height; i++){
    //     for(int j=0; j<W; j++) cout << field[i][j];
    //     cout << endl;
    // }

    vector<int> omit;
    for(int j=0; j<W; j++){
        bool flg = false;
        for(int i=0; i<height; i++) if(field[i][j] == '#') flg = true;
        if(!flg) omit.push_back(j);
    }

    for(int i=0; i<height; i++){
        for(int j=0; j<W; j++){

            bool flg = true;
            for(int k=0; k<omit.size(); k++) if(j == omit[k]) flg = false;

            if(flg) cout << field[i][j];
        }
        cout << endl;
    }

}

Measured memory_bytes: 256
def main():
    nvertices, nedges, s = map(int, input().split())
    edges = []
    for i in range(nedges):
        u, v, w = map(int, input().split())
        edges.append((u, v, w))

    INF = float('inf')
    weights = [INF] * nvertices
    weights[s] = 0
    for i in range(nvertices - 1):
        for u, v, w in edges:
            if weights[v] > weights[u] + w:
                weights[v] = weights[u] + w

    for u, v, w in edges:
        if weights[v] > weights[u] + w:
            print("NEGATIVE CYCLE")
            return

    for w in weights:
        print(w if w < INF else 'INF')


main()

Measured memory_bytes: 8132
import itertools

n = int(input())
p = int(''.join(input().split()))
q = int(''.join(input().split()))


# pcnt = 0
# qcnt = 0
# for i in range(n-3):
#     pcnt += (p[i] - 1 - )*math.factorial(n-i-1)
#     qcnt += (q[i] - 1)*math.factorial(n-i-1)
# ans = abs(pcnt-qcnt)
# print(pcnt,qcnt,ans)

seq = list(range(1,n+1))
leng =list(itertools.permutations(seq,n))

for i in range(len(leng)):
    a = int(''.join(map(str,leng[i])))
    # print(a)
    if a == p:
        pcnt = i
    if a == q:
        qcnt = i

ans = abs(pcnt-qcnt)
print(ans)


Measured memory_bytes: 8052
#include <iostream>

using namespace std;

#define PAD(x) (x+10-1)/10*10

int main(int argc, char* argv[])
{
    int duration = 0;
    int max_rest = 0;
    for (int i = 0; i < 5; i++) {
        int dish; cin >> dish;
        max_rest = max(max_rest, PAD(dish)-dish);
        duration += PAD(dish);
    }

    cout << duration-max_rest << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define endl '\n'
using namespace std;
const ll mod = (ll)1e9+7;
const ll INF = (ll)1e18+1;

void add(ll &x, ll y)
{
    x+=y;
    if(x>=mod)
    {
        x-=mod;
    }
}

vector<string> v(51);
vector<int> ar(51);

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

    int n;
    string ans="";
    cin >> n;
    for(int i=0; i<n; i++)
    {
        cin >> v[i];
        sort(v[i].begin(), v[i].end());
    }
    for(int i='a'; i<='z'; i++)
    {
        int mi=51;
        for(int j=0; j<n; j++)
        {
            int c=0;
            while(v[j][ar[j]]==i)
            {
                c++;
                ar[j]++;
                if(ar[j]>v[j].length()) break;
            }
            mi = min(mi, c);
        }
        while(mi--) ans+=i;
    }

    cout << ans;
}

//TODO: 56
//come back to 50D, 55D, DP-J


Measured memory_bytes: 256
//Catchharsh
    //I Luv Kunj017
    #include<bits/stdc++.h>
    #define ll long long int 
    #define ld long double
    #define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
    #define F first
    #define S second
    #define pb push_back
    #define endl '\n'
    const ll MOD = 1e9+7;
    const ll INF = 1011111111;
    const ll LLINF = 1000111000111000111LL;
    const ld EPS = 1e-10;
    const ld PI = 3.14159265358979323;
    using namespace std;
    ll power (int x,int n)
    {
        if(n==0)
        return 1;
        else if(n%2==0)
        return power((x*x),n/2);
        else
        return x*power((x*x),(n-1)/2); 
    }
    int main()
    {   
         IOS;
         ll n,i,j,k;
         cin>>n;
         vector<ll> v(n);
         map<ll,ll> m;
         set<ll> s;
         for(i=0;i<n;i++)
         {
           cin>>v[i];
           m[v[i]]++;
           s.insert(v[i]);
         }
         for(i=0;i<n;i++)
         {
          ll ch;
           m[v[i]]--;
           s.erase(s.find(v[i]));
           if(!s.empty())
            ch=*(--s.end());
         else
            ch=0;
           if(m[v[i]]>0&&v[i]>ch)
            cout<<v[i]<<endl;
          else
            cout<<ch<<endl;
          m[v[i]]++;
          s.insert(v[i]);
         }
         
    }

Measured memory_bytes: 16128
#include <iostream>
#include <string>
#include <algorithm>

#define ALL(x) x.begin(), x.end()
#define RALL(x) x.rbegin(), x.rend()

int main()
{
    using namespace std;

    string s, t;

    cin >> s >> t;

    sort(ALL(s));
    sort(RALL(t));

    if(s < t) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#define MAX 2000001
#define VMAX 10000 

int main(){
  unsigned short *A, *B;
  int C[VMAX+1];
  int n,i,j,k;

  scanf("%d", &n);
  
  A = malloc(sizeof(short)*n+1);
  B = malloc(sizeof(short)*n+1);

  /* your code */
  for(i=1;i<n+1;i++) scanf("%hu",&A[i]);
 
	k=A[1];

  for(i=1;i<n+1;i++){
    if(k<A[i]) k=A[i];
  }
  
  for(i=0;i<k+1;i++) C[i]=0;

  for(j=1;j<n+1;j++) C[A[j]]++;

  for(i=1;i<k+1;i++) C[i]=C[i]+C[i-1];

  for(j=n;j>0;j--){
    B[C[A[j]]]=A[j];
    C[A[j]]--;
  }

	for(i=1;i<n+1;i++) {
		if(i==n) printf("%d",B[i]);
		else printf("%d ",B[i]);
	}
  printf("\n");
  
  return 0;
}



Measured memory_bytes: 9648
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <string>
using namespace std;

int main(void) {
	string str;
	multimap<string, int> m;
	multimap<string, int>::iterator iter;
	int n;

	while(cin >> str >> n)
		m.insert(pair<string, int>(str, n));

	iter = m.begin();
	while(iter != m.end()) {
		pair<multimap<string, int>::iterator, multimap<string, int>::iterator> p;
		p = m.equal_range(iter->first);

		vector<pair<string,int> > v(p.first, p.second);
		sort(v.begin(), v.end());
		cout << v[0].first << endl;
		for(int i = 0; i < v.size() - 1; i++) {
			cout << v[i].second << " ";
		}
		cout << v[v.size() - 1].second << endl;
		iter = p.second;
	}
}

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

int main() {
  string s;
  cin >> s;
  
  string A;
  for ( int i = 0; i < s.size() ; i++ ){
    if (s.at(i) == '0' ){
      A.push_back('0');
    }
    else if (s.at(i) == '1' ){
      A.push_back('1');
    }
    else if (s.at(i) == 'B' && A.size() != 0){
      A.pop_back();
    }
  }
  cout << A ;
}

Measured memory_bytes: 256
program apc001
    use,intrinsic :: iso_fortran_env
    implicit none
    integer(int64):: n,i,c1=0,c2=0
    integer(int64), allocatable:: a(:), b(:)

    read*, n
    allocate(a(n), b(n))
    read*, a(:)
    read*, b(:)

    do i=1,n
        if (b(i) >= a(i))then
            c1=c1+(b(i)-a(i))/2
        else
            c2=c2+a(i)-b(i)
        end if
    end do

    if (c1 >= c2) then
        print'(a)', 'Yes'
    else
        print'(a)', 'No'
    end if
end program apc001

Measured memory_bytes: 640
ip1 = input()
ip1list = ip1.split(" ")
N = int(ip1list[0])
M = int(ip1list[1])
ip2 = input()
A_sub = ip2.split(" ")
A = []
for a in A_sub:A.append(int(a))
r = N-sum(A)
if r < 0:
    print(-1)
else:
    print(r)

Measured memory_bytes: 68104
#include<bits/stdc++.h>
#define REP(i,n) for(int i = 0;i < (n);i++)
#define P pair<int,int>
#define pb push_back
#define mk make_pair
using namespace std;
const int INF = 1 << 20;

typedef long long ll;




int main(){
  ll n;
  cin >> n;
  vector <ll> a;
  ll sum = 0;
  
  REP(i,n){
    ll b;
    cin >> b;
    a.pb(b);
  }
  REP(i,n-1){
    if(a[i] > a[i+1]){
      sum += a[i]/2;
      a[i] = a[i]%2;
      if(a[i] == 1 && a[i+1] > 0){
	sum++;
	a[i]--;
	a[i+1]--;
      }
    }
    else{
      sum += a[i];
      a[i+1] -= a[i];
      a[i] -= a[i];
      
    }
    /*
    REP(i,n){
      cout << a[i] << "  " ;
    }
    cout << endl;
    cout << "sum : " << sum << endl;
    */
  }
  sum += a[n-1]/2;
  cout << sum << endl;
  return 0;
}


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

int main()
{
    int N; cin >> N;
    int ans = 0;
    for (int i = 1; i <= N; i += 2) {
        int c = 0;
        for (int j = 1; j <= i; j += 2)
            if (i % j == 0)
                c++;
        if (c == 8)
            ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))

int a[110];
int main(){
	rep(i,0,3){
		ll n;
		scanf("%lld",&n);
		a[n]++;
	}
	ll ans=0;
	rep(i,0,105)ans+=!!a[i];
	printf("%lld",ans);
}

Measured memory_bytes: 128
def gcm(a, b):
    if a<b: a,b = b,a

    if (a%b ==0):
        return b
    else:
        return gcm(b, a%b)

def lcm(a, b):
    return a/gcm(a,b)*b

while True:
    try:
        a, b = map(int, raw_input().split())
    except:
        break
    print "%d %d" %(gcm(a,b), lcm(a,b))

Measured memory_bytes: 4220
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
#define dame { puts("-1"); return 0;}
#define yn {puts("YES");}else{puts("NO");}
  
int main() {
  int H,W;
  cin >> H >> W;
  v(v(char)) A(H,v(char)(W));
  rep(i,H) {
    rep(j,W) {
      cin >> A[i][j];
    }
  }
  vvi dp(H,vi(W,0));
  dp[0][0] = 1;
  rep(i,H) {
    rep(j,W) {
      if(A[i][j] == '#') continue;
      if(j == 0) {
        if(i == 0) continue;
        dp[i][j] = dp[i-1][j];
        continue;
      }
      if(i == 0) {
        dp[i][j] = dp[i][j-1];
        continue;
      }
      dp[i][j] = (dp[i-1][j] + dp[i][j-1]) % MOD;
    }
  }
  cout << dp[H-1][W-1] << endl;
  return 0;
}

Measured memory_bytes: 5248
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
#define fori(i,s,n) for(int i=s;i<=n;i++)
#define ford(j,s,n) for(int i=n;i>=s;i--)
#define pb push_back
#define TEST int t; cin>>t; for(int T=1;T<=t;T++)
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int a,b,c,k,ans=0;
    cin>>a>>b>>c>>k;
    if(k>a){
    	ans+=a;
    	k-=a;
    	if(k>b)
    		k-=b;
    	else k=0;
    	if(k>=c){
    		ans-=c;
    	}
    	else ans-=k;
    }
    else {
    	ans=k;
    }
    cout<<ans;
    return 0;
}


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

using namespace std;

int n,m;
int i,j,k;
string str;

int main(){
    cin >> str;
    long long ans = 0;
    j = 0;
    for(i = 0;i < str.length();i++){
        if(str[i] == 'W'){
            ans += i-j;
            j++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 640
from copy import deepcopy as dp
N = int(input())
B = [int(i) for i in input().split()]
ans = dp(B)
ans.insert(0,B[0])
cnt = 0
while cnt < len(B):
    for i in range(len(B)):
        if max(ans[i],ans[i+1]) <= B[i]:
            cnt+=1
        else:
            cnt = 0
            if ans[i] < B[i]:
                ans[i+1] = B[i]
            else:
                ans[i] = B[i] 
print(sum(ans))

Measured memory_bytes: 3700
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define pii pair <int, int>
#define F first
#define S second
#define ll long long
#define io ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define M_PI 3.14159265358979323846
const int N = 200005;
int main() {
    io;
    int a, b, c;
    cin >> a >> b >> c;
    if(c * b >= a) cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 3648
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>

template<class T> inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template<class T> inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}

using namespace std;
#define int long long
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repr(i,n) for(ll i=n;i>=0;i--)
#define P pair<ll, ll>
#define sz(x) (ll)x.size()
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define VE vector<ll>
#define COUT(x) cout<<(x)<<endl
#define MA map<ll,ll>
#define SE set<ll>
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,VE,greater<ll>>
#define COUT(x) cout<<(x)<<endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define EPS (1e-10)
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	unsigned r;
	while ((r = a % b)) {
		a = b;
		b = r;
	}
	return b;
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
bool prime(ll n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}
map<ll, ll> prime_factor(ll n) {
	map<ll, ll> ret;
	for (ll i = 2; i * i <= n; i++) {
		while (n % i == 0) {
			ret[i]++;
			n /= i;
		}
	}
	if (n != 1) ret[n] = 1;
	return ret;
}

const long long MOD = 1000000007;
//const long long MOD = 998244353;
const long long INF = 1LL << 60;



const long double PI = 3.14159265359;
const int MAX_N = 100010;


signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n, a, b; cin >> n >> a >> b;
	VE p(n); rep(i, n)cin >> p[i];
	int x = 0, y = 0, z = 0;
	rep(i, n) {
		if (p[i] <= a)x++;
		else if (a < p[i] && p[i] <= b)y++;
		else if (b < p[i])z++;
	}
	cout << min({ x,y,z }) << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define REP(i,a,b) for(i=a;i<b;i++)
#define rep(i,a) REP(i,0,a)
#define REV(i,a,b) for(i=a;i>b;i--)
#define rev(s) reverse(s.begin(),s.end())
#define pb push_back
#define mp make_pair
#define ord(v) sort(v.begin(),v.end());
const ll MAXN=1e5+10;
#define MAX 2*1e9;
#define fi first
#define se second
#define len(s) s.length();
ll con(string s)
{
	stringstream geek(s);
	ll x;
	geek>>x;
	return x;
}
int main()
{
	// #ifndef ONLINE_JUDGE
	// freopen("input.txt","r",stdin);
	// freopen("output.txt","w",stdout);
	// #endif
	string s;
	cin>>s;
	if(s=="ABC")
		cout<<"ARC"<<endl;
	else cout<<"ABC"<<endl;
	
	
	return 0;
}

Measured memory_bytes: 3600
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for(int i=0; i<n; i++)
#define reps(i, s, e) for(int i=s; i<e; i++)
#define repr(i, n) for(int i=n-1; i>=0; i--)
#define reprs(i, s, e) for(int i=s-1; i>=s; i--)

int main(){

    int n, q; cin >> n >> q;
    vector<int> g[n];
    rep(i, n-1){
        int a, b; cin >> a >> b;
        a--; b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    ll  x[n] = {};
    rep(i, q){
        int pt;
        ll  xt;
        cin >> pt >> xt;
        pt--;
        x[pt] += xt;
    }

    bool done[n];
    fill(done, done+n, false);
    queue<int> que;
    que.push(0);
    done[0] = true;
    while(!que.empty()){
        int now = que.front();
        que.pop();

        rep(i, g[now].size()){
            int next = g[now][i];
            if(done[next] == true) continue;

            x[next] += x[now];
            que.push(next);
            done[next] = true;
        }
    }

    rep(i, n){
        cout << x[i] << " ";
    }

    return 0;
}

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

int main() {
  int x[3000];
  int a, b, c, res = 0;
  
  for (int i = 0; i <= 1000; i++) x[i] = 0;
  
  for (int i = 0; i <= 1000; i++) {
  	cin >> a;
    x[a] += 1;
  }
  
  for (int i = 0; i <= 1000; i++) {
    if (x[i] != 0)
      res += 1;
  }
  
  cout << res << endl;
  
  return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
	    
		int n = sc.nextInt();
		int max = -1000000;
		int min = 1000000;
		long total = 0;
		
		for (int i = 0; i < n; i++){
			int temp = sc.nextInt();
			if (temp > max){ max = temp;}
			if (temp < min){ min = temp;}
			total += temp;
		}
		System.out.printf("%d %d %d\n", min, max, total);
	}
}

Measured memory_bytes: 31928
#include <bits/stdc++.h>
 
using namespace std;
 
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define Eunique(v) v.erase(unique(all(v)),v.end())
#define pvec(v) rep(i,v.size()){cout << v[i] << " ";};cout<<endl;
#define pb push_back
#define pf push_front
#define mod 1e9+7
 
typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;

const double pi = acos(-1.0);
 
ll gcd(ll x, ll y) { return (y == 0) ? x : gcd(y, x % y); }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }

int main()
{
	string s;
	int cnt=0,ans=0;
	cin >> s;
	rep(i,s.size()){
		if(s[i]=='A' || s[i]=='C' || s[i]=='G' || s[i]=='T') cnt++;
		else cnt=0;
		ans=max(cnt,ans);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define A first
#define B second
using namespace std;
typedef pair<int,int> PII;
int main(){
	int N,M;
	cin>>N>>M;
	vector<PII> arr(N);
	for(int i = 0 ; i < N ; ++i){
		cin>>arr[i].A>>arr[i].B;
	}
	sort(arr.begin(),arr.end());
	int res = M;
	long long cnt = 0;
	for(int i = 0 ; i < N; ++i){
		int how = min(res,arr[i].B);
		// cout<<"how = "<<how<<endl;
		cnt += 1ll*how*arr[i].A;
		res -= how;
		if(res == 0)break;
	}
	cout<<cnt<<endl;
	return 0;
}

Measured memory_bytes: 1024
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
//#define cerr if(false) cerr
#ifdef DEBUG
#define show(...) cerr << #__VA_ARGS__ << " = ", debug(__VA_ARGS__);
#else
#define show(...) 42
#endif
using namespace std;
using ll = long long;
using pii = pair<int, int>;
template <typename T, typename S>
ostream& operator<<(ostream& os, pair<T, S> a) {
    os << '(' << a.first << ',' << a.second << ')';
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> v) {
    for (auto x : v) os << x << ' ';
    return os;
}
void debug() {
    cerr << '\n';
}
template <typename H, typename... T>
void debug(H a, T... b) {
    cerr << a;
    if (sizeof...(b)) cerr << ", ";
    debug(b...);
}
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, k;
    cin >> n >> k;
    ll ans = 0;
    vector<int>a(n),b(n);
    rep(i,n){
        cin >> a[i] >> b[i];
        if(a[i] == 0)ans += b[i];
    }
    for(int i = 0; i < 30; i++){
        ll temp = 0;
        if(k >> i & 1){
            int num = ((k >> (i + 1)) << (i + 1)) + (1 << i) - 1;
            show(i, num);
            for(int j = 0; j < n; j++){
                if(num == (a[j] | num)){
                    temp += b[j];
                }
            }
        }
        show(i, temp);
        ans = max(ans, temp);
    }
    ll temp = 0;
    rep(i,n){
        if((k | a[i]) == k){
            temp += b[i];
        }
    }
    ans = max(ans, temp);
    cout << ans << endl;
}

Measured memory_bytes: 1024
#![allow(unused, non_snake_case, dead_code, non_upper_case_globals)]
use {
    proconio::{marker::*, *},
    std::{cmp::*, collections::*, mem::*},
};
macro_rules! chmax {
    ($ base : expr ,$ cmp : expr ) => {
        $base = max($base, $cmp);
    };
}
fn main() {
    input! {
        q:i64,h:i64,s:i64,d:i64,
        n:i64,
    }
    let mut litter = 0;
    litter = min(min(q * 4, h * 2), s);
    if litter * 2 < d {
        println!("{}", n * litter);
        return;
    } else {
        if n % 2 == 0 {
            println!("{}", n * d / 2);
        } else {
            let mut ans = litter;
            let n = n - 1;
            println!("{}", ans + (n * d) / 2);
        }
    }
}
const INF: i64 = 1 << 60;


Measured memory_bytes: 2124
#include <bits/stdc++.h>
#define rep(i,n) for (long long i = 0; i < (n); ++i)
const int INF = 2147483647;//int max
const int MOD = 1000000007;
using namespace std;
using ll = long long;
using P = pair<int,int>;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

int main() {
    ll n;
    cin >> n;
    vector<ll> a(n,0);
    map<ll,ll> m;
    rep(i,n){
        cin >> a.at(i);
        m[a.at(i)]++;
    }
    ll ans = 0;
    if(n == 1){
        cout << 1 << endl;
        return 0;
    }
    rep(i,n-1){
        ans = max(ans, m[i-1] + m[i] + m[i+1]);
    }
    cout << ans << endl;
    return 0;
}
/*
やっほい！
　　　　　　　やほほい！
　　　　+　　 　*
　　　 ∧∧　　. ∧∞∧　*
*　ヽ(=´ω｀)人(´ω｀*)ﾉ
　.～（ O x.） （ 　 O)～　+
。*　 　∪　　　　∪
*/

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

int main() {
    ll x,k,d; cin >> x >> k >> d;
    double p=abs(x),q=k,r=d;
    if(p>=q*r){
        cout << abs(x)-k*d << endl;
        return 0;
    }

    ll u=abs(x)/d;
    u *= d;
    ll v=abs(x)-u;
    if(k%2 == (abs(x)/d) % 2){
        cout << v << endl;
    }
    else cout << abs(d-v) << endl;

    return 0;
}


Measured memory_bytes: 3632
#include<stdio.h>
int main(void){
  int N,L[100];
  int max,max_i,sum;
  scanf("%d",&N);
  for(int i=0;i<N;i++){
    scanf("%d",&L[i]);
  }
  max=L[0];
  max_i=0;
  for(int i=0;i<N;i++){
    if(max<L[i]){
      max=L[i];
      max_i=i;
    }
  }
  for(int i=0;i<N;i++){
    if(i!=max_i){
      sum+=L[i];
    }
  }
  if(max<sum){
    printf("Yes");
  }else{
    printf("No");
  }
    return 0;
}

Measured memory_bytes: 128
#include <cstdio>
#include <iostream>
#include <vector>
#include <list>
#include <cmath>
#include <fstream>
#include <algorithm>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <complex>
#include <iterator>
#include <cstdlib>
#include <cstring>
#include <sstream>

using namespace std;

const double EPS=(1e-10);
typedef long long ll;
typedef pair<int,int> pii;
bool EQ(double a,double b){
  return abs((a)-(b))<EPS;
}
void fast_stream(){
	std::ios_base::sync_with_stdio(0);
}

int vs[101];
double rs[101];

void solve(){
    int t;
    cin>>t;
    double maxExp=0;
    for(int i=0;i<t;i++){
        int n,m;
        cin>>n>>m;
        double sumPer=0;
        for(int j=0;j<m;j++){
            cin>>vs[j]>>rs[j];
            sumPer+=rs[j];
        }
        double sum=0;
        for(int j=0;j<m;j++)sum+=vs[j]*(rs[j]/sumPer);
        maxExp=max(maxExp,sum);
    }
    int p,q;
    cin>>p>>q;
    double sumPer2=0;
    for(int j=0;j<q;j++){
        cin>>vs[j]>>rs[j];
        sumPer2+=rs[j];
    }
    double maxExp2=0;
    for(int j=0;j<q;j++)maxExp2+=vs[j]*(rs[j]/sumPer2);
    if(maxExp>maxExp2)cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
}

int main(){

    solve();

    return 0;
}

Measured memory_bytes: 0
// Last Change: 09/07/2019 21:35:53.
#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using ll = long long;

int main() {
  int N;
  cin >> N;
  vector<ll> B(N - 1);
  for (auto &&e : B) {
    cin >> e;
  }

  vector<ll> A(N);
  ll ans = 0;
  A[0] = B[0];
  A[N - 1] = B[N - 2];
  for (int i = 0; i < N - 2; ++i) {
    A[i + 1] = min(B[i], B[i + 1]);
  }

  for (auto &&e : A) {
    ans += e;
  }

  cout << ans << endl;
}


Measured memory_bytes: 888
#include <bits/stdc++.h>
#define ADD(a, b) a = (a + ll(b)) % mod
#define MUL(a, b) a = (a * ll(b)) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define all(a) (a).begin(), (a).end()
#define sz(v) (int)(v).size()
#define pb push_back
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<int, pi> ppi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> mat;
typedef complex<double> comp;
void Debug() {cout << '\n'; }
template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){
	cout<<arg<<" ";Debug(rest...);}
template<class T>ostream& operator<<(ostream& out,const vector<T>& v) {
	out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<<", ";out<<v.back();}out<<"]";return out;}
template<class S, class T>ostream& operator<<(ostream& out,const pair<S, T>& v){
	out<<"("<<v.first<<", "<<v.second<<")";return out;}
const int MAX_N = 200010;
const int MAX_V = 100010;
const double eps = 1e-6;
const ll mod = 1000000007;
const int inf = 1 << 29;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;
///////////////////////////////////////////////////////////////////////////////////////////////////

string S;
int N, M = 0;
int A[MAX_N];

void solve() {
	string str;
	cin >> str;
	N = sz(str);
	rep(i, 0, N) {
		if(str[i] == 'x') {
			A[M]++;
		}
		else {
			S += str[i];
			M++;
		}
	}
	// debug(str, S, M);
	// debug(vi(A, A + M + 1));
	rep(i, 0, M) {
		if(S[i] != S[M - i - 1]) {
			cout << "-1\n"; return;
		}
	}
	int ans = 0;
	rep(i, 0, M + 1) {
		int a = A[i], b = A[M - i];
		if(a > b) swap(a, b);
		ans += b - a;
	}
	cout << ans / 2 << "\n";
}

int main() {
#ifndef LOCAL
	ios::sync_with_stdio(false);
    cin.tie(0);
#endif
    cout << fixed;
	cout.precision(20);
	srand((unsigned int)time(NULL));
#ifdef LOCAL
	//freopen("in.txt", "wt", stdout); //for tester
    freopen("in.txt", "rt", stdin);
#endif	
	solve();
#ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}



Measured memory_bytes: 848
#include <stdio.h>

int judge(char A[], char B[]){
  int a=0, b=0, sw=0, ans=0;
  int i, j;
  int C[1001][1001];
  
  while(sw == 0){
    if(A[a] != '\0')
      a++;
    else
      sw = 1;
  }
  
  sw = 0;
  
  while(sw == 0){
    if(B[b] != '\0')
      b++;
    else
      sw = 1;
  }
  
  for(i=1; i<a+1; i++)
    C[i][0] = 0;
  for(i=1; i<b+1; i++)
    C[0][i] = 0;
  
  for(i=1; i<a+1; i++){
    for(j=1; j<b+1; j++){
      if(A[i-1] == B[j-1])
        C[i][j] = C[i-1][j-1] + 1;
      else if(C[i-1][j] >= C[i][j-1])
        C[i][j] = C[i-1][j];
      else
        C[i][j] = C[i][j-1];
      if(ans < C[i][j])
        ans = C[i][j];
    }
  }
  
  return ans;
}

int main(){
  char A[1000], B[1000];
  int n, i;
  
  scanf("%d", &n);
  
  for(i=0; i<n; i++){
    scanf("%s", A);
    scanf("%s", B);
    printf("%d\n", judge(A, B));
  }
  
  return 0;
}

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

int main(){
	long n, i;

	long min = 1000000;
	long max = -1000000;
	long sum = 0;
	
	cin >> n;

	while (cin >> i){
		sum += i;
		if (i < min){
			min = i;
		}
		if (i > max){
			max = i;
		}
	}
	cout << min << " " << max << " " << sum << endl;
	return 0;
}

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

// 多倍長テンプレ
/* ---------------------- ここから ---------------------- */
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
namespace mp = boost::multiprecision;
// 任意長整数型
using Bint = mp::cpp_int;
// 仮数部が1024ビットの浮動小数点数型(TLEしたら小さくする)
using Real = mp::number<mp::cpp_dec_float<1024>>;
/* ---------------------- ここまで ---------------------- */

int main() {
  Bint ans = 1, x = (long long int)1e18;
  int n; cin >> n;
  bool flg = false;

  for(int i=0;i<n;i++){
      long long int a; cin >> a;
      Bint aa = a;
      if(a==0)ans=0;
      if(flg == false)ans = ans*aa;
      
      if(ans > x){
          flg = true;
      }
  }
  if(ans==0 || flg==false)cout << ans << endl;
  else cout << "-1" << endl;

  return 0;
}

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

int main() {
  int N; cin>>N;
  int a[N+1];
  int b[N+1];
  int c[N+1];
  for(int i=1;i<=N;i++)cin>>a[i]>>b[i]>>c[i];
  int dp[N+1][3];
  dp[1][0]=a[1];
  dp[1][1]=b[1];
  dp[1][2]=c[1]; //１日目の幸福度の合計



  for(int i=2;i<=N;i++){
   dp[i][0]=max(dp[i-1][1]+a[i],dp[i-1][2]+a[i]);
   dp[i][1]=max(dp[i-1][0]+b[i],dp[i-1][2]+b[i]);
   dp[i][2]=max(dp[i-1][0]+c[i],dp[i-1][1]+c[i]); 


  }
  cout<<max(dp[N][0],max(dp[N][1],dp[N][2]))<<endl;
}

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

int main(){
    int n;
    cin >> n;
    int arr[n];
    for(int i=0;i<n;i++)cin >> arr[i];
    int ans=0;
    for(int i=n-1;i>=0;i--)
    {
        bool ok = true;
        for(int j=i-1;j>=0;j--){
            if(arr[i]<arr[j])
            {
                ok = false;
                break;
            }
        }
        if(ok)
        ans++;
                
    }

    cout << ans;
}

Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;
using static System.Console;
using static System.Math;
class Z { static void Main() => new K(); }
class K
{
	int F => int.Parse(Str);
	long FL => long.Parse(Str);
	int[] G => Strs.Select(int.Parse).ToArray();
	long[] GL => Strs.Select(long.Parse).ToArray();
	string Str => ReadLine();
	string[] Strs => Str.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
	const int MOD = 1000000007;
	public K()
	{
		SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
		Solve();
		Out.Flush();
	}
	void Solve()
	{
		var N = F;
		var S = Str;
		var min = N + 100;
		var cnt = new int[N + 1];
		for (var i = 0; i < N; i++) cnt[i + 1] = cnt[i] + (S[i] == 'E' ? 1 : 0);
		for (var i = 0; i < N; i++)
		{
			min = Min(min, (i - cnt[i] + cnt[0]) + (cnt[N] - cnt[i + 1]));
		}
		Console.WriteLine(min);
	}
}


Measured memory_bytes: 13280
N, T = map(int, input().split())
A = list(map(int, input().split()))

diff = -1
mini = A[0]
cnt = 0
ans = 0

for i in range(1, N):
	now = A[i]

	if mini > now:
		mini = now
	else:
		if now - mini == diff:
			cnt += 1
		elif now - mini > diff:
			diff = now - mini
			ans = max(ans, cnt)
			cnt = 1
ans = max(ans, cnt)
print(ans)


Measured memory_bytes: 63728
n, amari = gets.chomp.split(" ").map(&:to_i)
a = gets.chomp.split(" ").map(&:to_i)
kazu=[0,0]
a.each{|item| kazu[item%2]+=1} #gusu,kisu
if kazu[1]==0
    if amari==1 then
        puts 0
    else
        puts 2**n
    end
else
    puts 2**(n-1)
end

Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int b1max, b1_now, b2_now, b2_rest;
  
  cin >> b1max >> b1_now >> b2_now;
  
  if (b1max < (b1_now + b2_now)){
    b2_rest = b2_now - (b1max-b1_now);
    cout << b2_rest << endl;
  }
  
  else {
    b2_rest = 0;
    cout << b2_rest << endl;
  }
}

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

#1つの箱の中の数を数える
cnt1=0
for i in range(n):
    for j in range(i,n):
        if A[i]>A[j]:
            cnt1+=1

#2つの箱の大小を調べる
B=A
cnt2=0
for i in range(n):
    for j in range(n):
        if B[i]>A[j]:
            cnt2+=1
ans = (cnt1*k + cnt2 * k*(k-1)//2)%(10**9+7)
print(ans)

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

using namespace std;

typedef long long ll;

const int INF = 1000000000;

int main()
{
  int n;
  scanf("%d", &n);
  vector<ll> a(n + 2, 0);
  for (int i = 1; i < n + 1; ++i) {
    scanf("%lld", &a[i]);
  }
  ll total = 0;
  for (int i = 1; i < n + 2; ++i) {
    total += abs(a[i] - a[i - 1]);
  }
  for (int i = 1; i < n + 1; ++i) {
    ll sum = total - abs(a[i] - a[i - 1]) - abs(a[i + 1] - a[i]) + abs(a[i + 1] - a[i - 1]);
    printf("%lld\n", sum);
  }
  return 0;
}


Measured memory_bytes: 2048
//Swapping Two Numbers
#include <iostream>

int main()
{
  while (1) {
    int x = 0, y = 0;
    std::cin >> x >> y;

    if (!x && !y) break;

    if (x > y) {
      x ^= y;
      y ^= x;
      x ^= y;
    }

    std::cout << x << " " << y << std::endl;
  }

  return 0;
}

Measured memory_bytes: 1160
#include <stdio.h>

int n, m;
int a[271828];
int b[271828];

int asumisu;
int mizuhasu[271828];

int tomatuharuka;
int igutiyuka[271828 * 2];

int main(void) {
	int i, j;
	if (scanf("%d%d", &n, &m) != 2) return 1;
	for (i = 0; i < n; i++) {
		if (scanf("%d", &a[i]) != 1) return 1;
	}
	for (i = 0; i < m; i++) {
		if (scanf("%d", &b[i]) != 1) return 1;
	}

	asumisu = 0;
	for (i = j = 0; i < n && j < m; ) {
		if (a[i] == b[j]) {
			mizuhasu[asumisu++] = a[i];
			i++;
			j++;
		}
		else if (a[i] < b[j]) i++;
		else j++;
	}
	tomatuharuka = 0;
	for (i = j = 0; i < n && j < m; ) {
		if (a[i] == b[j]) {
			igutiyuka[tomatuharuka++] = a[i];
			i++;
			j++;
		} else if (a[i] < b[j]) {
			igutiyuka[tomatuharuka++] = a[i++];
		} else {
			igutiyuka[tomatuharuka++] = b[j++];
		}
	}
	while (i < n) igutiyuka[tomatuharuka++] = a[i++];
	while (j < m) igutiyuka[tomatuharuka++] = b[j++];

	printf("%d %d\n", asumisu, tomatuharuka);
	for (i = 0; i < asumisu; i++) printf("%d\n", mizuhasu[i]);
	for (i = 0; i < tomatuharuka; i++) printf("%d\n", igutiyuka[i]);
	return 0;
}



Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
    int n;
    cin>>n;


    vector<pair<int, int> > pairs(n);

    for (int i=0;i<n;i++) {
        int wk;
        cin>>wk;
        pairs[i] = make_pair(wk, i);
    }

    // firstが小さい順、secondが小さい順にソート
    sort(pairs.begin(), pairs.end());

    for(int i=0;i<n;i++){
        if(i==n-1)
            cout<<pairs[i].second+1<<endl;
        else
            cout<<pairs[i].second+1<<' ';
    }
    return 0;
}  

Measured memory_bytes: 1664
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();
// freopen("input.txt", "r", stdin);

int main() {
    int n, val;
    cin >> n;
    int four = 0, not_two = 0;
    for(int i = 0; i < n; i++) {
        cin >> val;
        if (val % 4 == 0)
            four += 1;
        else if (val % 2 != 0)
            not_two += 1;
    }
    int thres = 0;
    if (four + not_two == n)
        thres = -1;
    if (four - not_two >= thres)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}




Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;} return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;} return 0;}
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(vec) vec.begin(),vec.end()
typedef long long ll;
typedef pair<ll,ll> l_l;
typedef pair<int,int> i_i;
const ll mod=1e9+7;
const int inf=1<<30;

ll kiri(ll a,ll b){return a%b==0?a/b:a/b+1;}

int main(){
  ll n,d,a;
  cin >> n >> d >> a;
  vector<l_l> v(n);
  rep(i,n) cin >> v[i].first >> v[i].second;
  sort(all(v));
  ll damage=0;
  ll ans=0;
  queue<l_l> q;
  rep(i,n){
    ll x=v[i].first,h=v[i].second;
    if(q.size()&&x>q.front().first){
      while(q.size()&&x>q.front().first){
        damage-=q.front().second;
        q.pop();
      }
    }
    if(h>damage){
      q.push(l_l(x+2*d,a*kiri(h-damage,a)));
      ans+=kiri(h-damage,a);
      damage=a*kiri(h,a);
    }
    
  }
  cout << ans << endl;
}

Measured memory_bytes: 5120
import java.util.Scanner;

public class Main {
	
	private static void solve(int n, int k,int[] h) {
		
		long[] dp = new long[n];
		for (int i=0; i<n; i++) {
			dp[i] = Integer.MAX_VALUE;
		}
		dp[0] = 0;
		
		for (int i=1; i<n; i++) {
			for (int j=1; j<=k && (i-j) >= 0; j++) {
				dp[i] = Math.min(dp[i], dp[i-j] + Math.abs(h[i] - h[i-j]));
			}
		}

		System.out.println(dp[n-1]);
	}

	public static void main(String[] args) {
		
		Scanner scanner = new Scanner(System.in);
		
		int n = scanner.nextInt();
		int k = scanner.nextInt();
		
		int[] h = new int[n];
		
		for (int i=0; i<n; i++) {
			h[i] = scanner.nextInt();
		}
		
		solve(n, k, h);
		
		scanner.close();
	}
}

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

int main() {
  int a,b,k;
  cin >> a >> b >> k;
  int n = min(a, b);
  int cnt=0;
  int d=1;
  for (int i = n; i >= 1; --i) {
    d = i;
    if (a % i == 0 && b % i == 0) cnt++;
    if ( cnt == k ) break;
  }
  cout << d << endl;
}

Measured memory_bytes: 384
/*
    Test:
        geometry/antipodal_points.cpp

    Link:
        AIZU(judge.u-aizu.ac.jp) CGL.4B
*/

#include <bits/stdc++.h>

using namespace std;

typedef complex<double> point;
typedef vector<point> polygon;

#define NEXT(i) (((i) + 1) % n)

double cross(point a, point b) { return imag(conj(a) * b); }
double area2(point a, point b, point c) { return cross(b - a, c - a); }

vector<pair<int, int>> antipodal(const polygon &P)
{
    vector<pair<int, int>> ans;
    int n = P.size();

    if (P.size() == 2)
        ans.push_back({ 0, 1 });

    if (P.size() < 3)
        return ans;

    int q0 = 0;

    while (abs(area2(P[n - 1], P[0], P[NEXT(q0)]))
            > abs(area2(P[n - 1], P[0], P[q0])))
        ++q0;

    for (int q = q0, p = 0; q != 0 && p <= q0; ++p)
    {
        ans.push_back({ p, q });

        while (abs(area2(P[p], P[NEXT(p)], P[NEXT(q)]))
                > abs(area2(P[p], P[NEXT(p)], P[q])))
        {
            q = NEXT(q);
            if (p != q0 || q != 0)
                ans.push_back({ p, q });
            else
                return ans;
        }

        if (abs(area2(P[p], P[NEXT(p)], P[NEXT(q)]))
                == abs(area2(P[p], P[NEXT(p)], P[q])))
        {
            if (p != q0 || q != n - 1)
                ans.push_back({ p, NEXT(q) });
            else
                ans.push_back({ NEXT(p), q });
        }
    }

    return ans;
}

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

    polygon P(n);

    for (int i = 0; i < n; ++i){
        double x, y;
        cin >> x >> y;
        P[i] = point(x, y);
    }

    auto apod = antipodal(P);

    double diameter = 0.;

    for (auto a : apod)
        diameter = max(diameter, abs(P[a.first] - P[a.second]));

    cout.precision(17);

    cout << fixed << diameter << endl;
}


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

int main(){
  int a,b,c,n;
  int buhin[301],list[1000][4],cnt;

  while(cin >> a >> b >> c && a||b||c){
    fill_n(buhin,301,2);
    cin >> n;
    cnt = 0;
    for(int i=0;i<n;i++,cnt++){
      for(int j=0;j<4;j++){
	cin >> list[cnt][j];
      }
      if(list[cnt][3]==1){
	for(int k=0;k<3;k++) buhin[list[cnt][k]] = 1;
	cnt--;
      }
    }
    for(int i=0;i<cnt;i++){
	for(int j=0;j<3;j++){
	  if(buhin[list[i][j]]==1 && buhin[list[i][(j+1)%3]]==1){
	    buhin[list[i][(j+2)%3]] = 0;
	}
      }
    }
    for(int i=1;i<=a+b+c;i++) cout << buhin[i] << endl;
  }
}

Measured memory_bytes: 1176
// -*- coding:utf-8-unix -*-

use proconio::input;

fn main() {
    input! {
        mut a: i16,
        b: i16,
        mut c: i16,
        d: i16,
    }

    let mut is_a_attack = true;
    loop {
        if is_a_attack {
            c -= b;
            if c <= 0 {
                println!("Yes");
                break;
            }
        } else {
            a -= d;
            if a <= 0 {
                println!("No");
                break;
            }
        }
        is_a_attack = !is_a_attack;
    }
}


Measured memory_bytes: 2132
n,m = map(int,input().split())
ac = [False] * n
wa = [0] * n
for i in range(m):
    p, s = input().split()
    p = int(p) - 1
    if s == "AC":
        ac[p] = True
    else:
        if not ac[p]:
            wa[p]+=1
    
        
a = 0
b = 0
for i in range(n):
    if ac[i]:
        a += 1
        b += wa[i]
print(*[a, b])

Measured memory_bytes: 4596