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

using namespace std;

typedef long long ll;
typedef pair<int, int> pp;
double PI=acos(-1);
int const N = 5e5 + 10,M=1e7+1, oo = 1e9;
const int mod = oo+7;
const ll  OO = 3e18;

int n,aa[N];
map<int,int > mp1,mp2;
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin>>n;
    for(int i=0;i<n;i++)cin>>aa[i];
    for(int i=0;i<n;i++){
        if(i&1)mp1[aa[i]]++;
        else mp2[aa[i]]++;
    }
    int mx1=0,mx2=0,mxx1=0,mxx2=0,a=0,c=0;
    for(auto v:mp1){
        if(v.second>mx1){
            mx2=mx1;
            mx1=v.second;
            a=v.first;
        }else if(v.second>mx2)mx2=v.second;
    }
    for(auto v:mp2){
        if(v.second>mxx1){
            mxx2=mxx1;
            mxx1=v.second;
            c=v.first;
        }else if(v.second>mxx2)mxx2=v.second;
    }
    if(a!=c)cout<<n-mx1-mxx1;
    else cout<<min(n-mx1-mxx2,n-mxx1-mx2);
    return 0;
}

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

N = int(input())
CITY = [[int(x) for x in input().split()] for _ in range(N)]

l = 0
for i in range(N):
    for j in range(N):
        if i == j:
            continue

        ci = CITY[i]
        cj = CITY[j]
        d = math.sqrt((ci[0] - cj[0]) ** 2 + (ci[1] - cj[1]) ** 2)
        l += math.factorial(N - 1) * d

print(l / math.factorial(N))


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

#define NREP() for(ll i = 0; i < n; i++)
#define MREP() for(ll j = 0; j < m; j++)
#define REP(i, n) for(ll i = 0; i < n; i++)
#define ALL(x) (x).begin(), (x).end()
#define MSG(x) cout << x << endl;
#define IPT(t, x) t ipt; cin >> ipt; x.push_back(ipt);
#define YN(x) x ? cout << "YES" << endl : cout << "NO" << endl;
#define Yn(x) x ? cout << "Yes" << endl : cout << "No" << endl;
#define yn(x) x ? cout << "yes" << endl : cout << "no" << endl;

using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;

const static ll MOD = 1e9 + 7;
ll n, cnt, ans, tmp, sum, a, b, c, d, k, m, h, w, q, x, y;
string s, t;

int main() {
    cin >> n >> m;
    vl h(n);
    vl mx(n);

    NREP() {
        cin >> h[i];
        mx[i] = 0;
    }

    MREP() {
        cin >> a >> b;
        mx[a - 1] = max(mx[a - 1], h[b - 1]);
        mx[b - 1] = max(mx[b - 1], h[a - 1]);
    }

    ans = 0;
    NREP() {
        if (h[i] > mx[i]) ans++;
    }

    MSG(ans)

}


Measured memory_bytes: 4788
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
#include <iomanip>
#define ALL(x) (x).begin(), (x).end()
#define rt return
#define dll(x) scanf("%I64d",&x)
#define xll(x) printf("%I64d\n",x)
#define sz(a) int(a.size())
#define all(a) a.begin(), a.end()
#define rep(i,x,n) for(int i=x;i<n;i++)
#define repd(i,x,n) for(int i=x;i<=n;i++)
#define pii pair<int,int>
#define pll pair<long long ,long long>
#define gbtb ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define MS0(X) memset((X), 0, sizeof((X)))
#define MSC0(X) memset((X), '\0', sizeof((X)))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define eps 1e-6
#define gg(x) getInt(&x)
#define db(x) cout<<"== [ "<<x<<" ] =="<<endl;
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll powmod(ll a,ll b,ll MOD){ll ans=1;while(b){if(b%2)ans=ans*a%MOD;a=a*a%MOD;b/=2;}return ans;}
inline void getInt(int* p);
const int maxn=1000010;
const int inf=0x3f3f3f3f;
/*** TEMPLATE CODE * * STARTS HERE ***/
int a[maxn];
int b[maxn];
int n;
int c[maxn];
int d[maxn];
int main()
{
    //freopen("D:\\common_text\\code_stream\\in.txt","r",stdin);
    //freopen("D:\\common_text\\code_stream\\out.txt","w",stdout);
    gbtb;
    cin>>n;
    repd(i,1,n)
    {
        cin>>a[i];
    }
    repd(i,1,n)
    {
        cin>>b[i];
    }
    int base=1;
    ll ans=0ll;
    for(int i=0;i<=28;i++)
    {
        repd(j,1,n)
        {
            c[j]=a[j]%(2*base);
            d[j]=b[j]%(2*base);
        }
        sort(d+1,d+1+n);
        int num=0;
        repd(j,1,n)
        {
            int r=lower_bound(d+1,d+1+n,2*base-c[j])-d-2;
            int l=lower_bound(d+1,d+1+n,base-c[j])-d-1;
            num+=r-l+1;
            r=lower_bound(d+1,d+1+n,4*base-c[j])-d-2;
            l=lower_bound(d+1,d+1+n,3*base-c[j])-d-1;
            num+=r-l+1;
        }
        if(num&1)
        {
            ans+=1ll*base;
        }
        base*=2;
    }
    cout<<ans<<endl;


    return 0;
}

inline void getInt(int* p) {
    char ch;
    do {
        ch = getchar();
    } while (ch == ' ' || ch == '\n');
    if (ch == '-') {
        *p = -(getchar() - '0');
        while ((ch = getchar()) >= '0' && ch <= '9') {
            *p = *p * 10 - ch + '0';
        }
    }
    else {
        *p = ch - '0';
        while ((ch = getchar()) >= '0' && ch <= '9') {
            *p = *p * 10 + ch - '0';
        }
    }
}



Measured memory_bytes: 13312
#include <stdio.h>

int main(){
	int n,q;
	int i,j;
	scanf("%d %d",&n,&q);
	char s[200004];
		scanf("%s",&s);
	char t[200001],d[200001];
	for(i=0;i<q;i++){
		scanf("\n%c %c",&t[i],&d[i]);
	}
	int check(int k){
		/*
		マス目kにあるゴレが生存するかどうかを調べる
		左に消える場合は1を返す
		右に消える場合は2を返す		
		消えない場合は0を返す
		*/
		int cur = k;
		for(i=0;i<q;i++){
			if(t[i]==s[cur]){
				switch(d[i]){
				case'R':
					if(cur==(n-1)){
						return 2;
					}
					cur++;
					break;
				case'L':
					if(cur==0){
						return 1;
					}
					cur--;
					break;
				}
			}
		}
		return 0;
	}
	/*
	左に消えるゴーレムのマス目を二分探索で調べる
	*/
	
	int checkleft(){
		int low  = 0;
		int high = n-1;
		int mid;
		if(check(low)!=1){
			return -1;
		}
		if(check(high)==1){
			return high;
			//すべて左に消える
		}
		mid = (low+high)/2;
		while(mid>low){
			if(check(mid) ==1){
				low = mid;
				mid = (low+high)/2;
			}else{
				high = mid;
				mid = (low+high)/2;
			}
		}
		return mid;
	}
	
	
	int checkright(){
		int low  = 0;
		int high = n-1;
		int mid;
		if(check(low)==2){
			return low;
			//すべて右に消える
		}
		if(check(high)!=2){
			return n;
			//一つも右に消えない
		}
		mid = (low+high)/2;
		while(mid>low){
			if(check(mid) ==2){
				high = mid;
				mid = (low+high)/2;
			}else{
				low = mid;
				mid = (low+high)/2;
			}
		}
		return mid+1;
	}
	
	/*
	左からleftまで消滅
	右からrightまで消滅
	*/
	int left =checkleft();
	int right=checkright();
	int ans = n - (left+1) -(n- right);
	//printf("left  = %d\n",left);
	//printf("right = %d\n",right);
	printf("%d",ans);
	return 0;
}


Measured memory_bytes: 768
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <numeric>
using namespace std;
typedef long long ll;

bool prime(ll n){
    if(n==1)return 1;
    for(ll i=2;i*i<=n;i++)if(n%i==0)return 0;
    return 1;
}

int main(){
    ll a,b;cin>>a>>b;
    ll k=__gcd(a,b),ans=0;
    for(ll i=1;i*i<=k;i++){
        if(k%i==0){
            ans+=(prime(i));
            if(k/i!=i)ans+=(prime(k/i));
        }
    }
    cout<<ans;
}

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 x = sc.nextInt();
		int a = sc.nextInt();
		int b = Math.abs(a - x);
		int gmf = b;
		for (int i = 1; i < n; i++) {
			int tmp = Math.abs(sc.nextInt() - x);
			gmf = getGmf(gmf, tmp);
		}
		System.out.println(gmf);
	}

	static int getGmf(
			int a,
			int b) {
		int tmp;
		while ((tmp = a % b) != 0) {
			a = b;
			b = tmp;
		}
		return b;
	}
}


Measured memory_bytes: 46672
///usr/bin/g++ -O2 $0 -o ${0%.cpp} && echo "----------" && ./${0%.cpp}; exit;
#include <bits/stdc++.h>
using namespace std;

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

int n, R, C; 

struct point {
    int x, y, c;
    int idx() {
        if(x == 0)      return 0; 
        else if(y == C) return 1; 
        else if(x == R) return 2; 
        else if(y == 0) return 3; 
        else            return -1;
    }
    bool operator < (point &p) {
        if(idx() != p.idx()) return idx() < p.idx(); 
        if(idx() == 0)      return y < p.y; 
        else if(idx() == 1) return x < p.x; 
        else if(idx() == 2) return y > p.y; 
        else                return x > p.x; 
    }
};

vector<point> v;

int main(int argc, char const *argv[]) {
#ifdef LOCAL
    freopen("in", "r", stdin);
#endif
    scanf("%d %d %d", &R, &C, &n); 
    for(int i = 1; i <= n; ++i) {
        point p1, p2;
        scanf("%d %d %d %d", &p1.x, &p1.y, &p2.x, &p2.y); 
        p1.c = p2.c = i;
        if(p1.idx() >= 0 && p2.idx() >= 0) {
            v.push_back(p1); 
            v.push_back(p2);
        }
    }
    sort(v.begin(), v.end()); 
    stack<int> st;
    for(point p : v) {
        int c = p.c; 
        if(st.size() && st.top() == c) st.pop(); 
        else st.push(c); 
    }
    if(st.size()) puts("NO"); 
    else puts("YES"); 
}

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


int main() {
  long long N;
  cin >> N;
  vector<long long> A(N);
  for(int i = 0; i < N; i++) {
    cin >> A.at(i);
  }
  long long ans = 0;
  long long std = A.at(0);
  for(int i = 1; i < N; i++) {
    if(A.at(i) < std) {
      ans += (std- A.at(i));
    }
    else {
      std = A.at(i);
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 4844
#include <algorithm>
#include <iostream>
#include <vector>

#include <limits.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;
}

const int INF = (int) ((1LL << 31) - 1);

// ref. arihon 3-3
// E: type of data, R: type of query result
template<typename E, typename R>
class SegmentTree {
    public:
        SegmentTree(const int _n, const E inf, R (*f)(E, E)): f(f), inf(inf) {
            n = 1;
            while (n < _n) n *= 2;
            data.resize(2 * n, inf);
        }

        // update data[k] with a
        // time complexity: O(n)
        void update(int k, E a) {
            k += n - 1;
            data[k] = a;
            while (k > 0) {
                k = (k - 1) / 2;
                data[k] = (*f)(data[k * 2 + 1], data[k * 2 + 2]);
            }
        }

        // query value from [a, b)
        // // time complexity: O(n)
        R query(int a, int b) {
            return query(a, b, 0, 0, n);
        }

    private:
        int n;
        R (*f)(E, E);
        const E inf;
        vector<E> data;

        R query(int a, int b, int k, int l, int r) {
            // if [a, b) intersect [l, r) = empty
            if (r <= a || b <= l) {
                return INF;
            }

            // if [a, b) includes [l, r)
            if (a <= l && r <= b) {
                return data[k];
            } else {
                R vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
                R vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
                return min(vl, vr);
            }
        }
};

const int MAX_N = 100000;

// ref. http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DSL_2_A
int main(void) {
    int n, q;
    cin >> n >> q;

    auto f = [](int x, int y) {
        return min(x, y);
    };
    SegmentTree<int, int> *st = new SegmentTree<int, int>(n, INF, f);

    for (int i = 0; i < q; i++) {
        int com, x, y;
        cin >> com >> x >> y;
        if (com == 0) {
            // update
            st->update(x, y);
        } else {
            // find
            cout << st->query(x, y + 1) << endl;
        }
    }

    delete st;
    return 0;
}



Measured memory_bytes: 3868
{-# LANGUAGE BangPatterns #-}
 
module Main
  ( main
  )
where
 
import           Control.Applicative
import           Control.Monad
import           Control.Monad.ST
import           Data.Bits
import qualified Data.ByteString.Char8         as BS
import           Data.Char
import           Data.List
import           Data.Maybe
import           Data.Ord
import qualified Data.Vector                   as V
import qualified Data.Vector.Mutable           as MV
import qualified Data.Vector.Unboxed           as UV

parse = fst . fromJust
parseInt = parse . BS.readInt
parseInteger = parse . BS.readInteger
readInt = parseInt <$> BS.getLine
readInteger = parseInteger <$> BS.getLine
readIntList = map parseInt . BS.words <$> BS.getLine
readIntegerList = map parseInteger . BS.words <$> BS.getLine


main = do
  s <- getLine
  putStrLn $ parseStr s ""

parseStr "" stack = reverse stack
parseStr ('0':rest) stack = parseStr rest ('0':stack)
parseStr ('1':rest) stack = parseStr rest ('1':stack)
parseStr ('B':rest) (x:stack) = parseStr rest stack
parseStr ('B':rest) stack = parseStr rest stack


Measured memory_bytes: 380
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define debug(var) do{cout << #var << " : "; view(var);}while(0)
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
template<class T> void view(T e) {cout << e << endl;}
template<class T> void view(const vector<T> &v) {for(const auto &e : v){cout << e << " ";} cout << endl;}
template<class T> void view(const vector<vector<T>> &vv) {for(const auto &v : vv){view(v);}}
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const int inf = 1e9;
const ll inf_l = 1e18;
const int MAX = 1e5;

struct topological_sort{
    vector<vector<int>> G;
    vector<int> indegree;
    vector<int> degree;
    int V;

    topological_sort(int V) : V(V) {
        G.resize(V); 
        indegree.resize(V);
        degree.resize(V);
    }
    void add_edge(int a, int b) {
        G[a].push_back(b);
        indegree[b]++;
    }
    vector<int> sort() {
        queue<int> q;
        vector<int> sorted;
        int deg = 1;
        for (int i = 0; i < V; i++) {
            if (indegree[i] == 0) {
                q.push(i);
                degree[i] = deg;
            }
        }
        while (!q.empty()) {
            queue<int> q_tmp;
            deg++;
            while (!q.empty()) {
                int v = q.front(); q.pop();
                for (int i = 0; i < G[v].size(); i++) {
                    int u = G[v][i];
                    indegree[u]--;
                    if (indegree[u] == 0) {
                        q_tmp.push(u);
                        degree[u] = deg;
                    }
                }
                sorted.push_back(v);
            }
            swap(q,q_tmp);
        }
        return sorted;
    }
};

int main() {
    int n; cin >> n;
    topological_sort ts(n*(n-1)/2);
    vvint to(n,vint(n));
    int num = 0;
    rep(i,n)rep(j,i) to[j][i] = to[i][j] = num++;
    vvint data(n,vint(n-1));
    rep(i,n)rep(j,n-1) {
        int x; cin >> x;
        x--;
        data[i][j] = x;
    }
    rep(i,n)rep(j,n-2) {
        ts.add_edge(to[i][data[i][j]],to[i][data[i][j+1]]);
    }
    vint res = ts.sort();
    if (res.size() != n*(n-1)/2) {cout << -1 << endl; return 0;}
    cout << ts.degree[res.back()] << endl;
}

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

int main() {
  
  int A, B, M; cin >> A >> B >> M;
  
  vector<int> vecA(A); vector<int> vecB(B);
  
  int minA = pow(10, 5) + 1; int minB = pow(10, 5) + 1;
  
  for (int i = 0; i < A; i++) {
    cin >> vecA[i];
    minA = min(minA, vecA[i]);
  }
  
  for (int i = 0; i < B; i++) {
    cin >> vecB[i];
    minB = min(minB, vecB[i]);
  }
  
  int minSum = minA + minB;
  
  for (int i = 0; i < M; i++) {
    
    int x, y, c; cin >> x >> y >> c;
    
    int tmpSum = vecA[x - 1] + vecB[y - 1] - c;
    
    minSum = min(minSum, tmpSum);
    
  }
  
  cout << minSum << endl;
  
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
 
using namespace std;
 
typedef struct card{
    char s;
    int v;
    int i;
}card;
 
card A[100000];
 
int partition(card A[], int p, int r);
void quickSort(card A[], int p, int r);
bool isStable(card A[], int n);
 
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i)  {
        cin >> A[i].s >> A[i].v;
        A[i].i = i;
    }
 
    quickSort(A, 0, n - 1);
    if (isStable(A, n)) cout << "Stable\n";
    else cout << "Not stable\n";
 
    for (int i = 0; i < n; i++){
        cout << A[i].s << ' ' << A[i].v << '\n';
    }
 
    return 0;
}
 
int partition(card A[], int p, int r)
{
    int x = A[r].v;
    int i = p;
 
    for (int j = p; j < r; ++j)
    {
        if (A[j].v <= x){
            swap(A[i], A[j]);
            ++i;
        }
    }
    swap(A[i], A[r]);
    return i;
}
 
void quickSort(card A[], int p, int r)
{
    if (p < r)
    {
        int q = partition(A, p, r);
        quickSort(A, p, q - 1);
        quickSort(A, q + 1, r);
    }
}
 
bool isStable(card A[], int n)
{
    for (int i = 1; i < n; i++) {
        if (A[i - 1].v == A[i].v && A[i - 1].i > A[i].i)
            return false;
    }
    return true;
}


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

int main() {
  int N, M;
  cin >> N;
  
  vector<string> blue(N);
  vector<string> red(M);
  
  for( int i = 0; i < N; i++ ) cin >> blue.at(i);
  cin >> M;
  for( int i = 0; i < M; i++ ) cin >> red.at(i);
  
  int okane;
  int maxen = 0;
  for( int i = 0; i < N; i++ ){
    okane = 1;
    for( int j = i+1; j < N; j++ ){
      if( blue.at(i) == blue.at(j) ) okane++;
    }
    for( int k = 0; k < M; k++ ){
      if( blue.at(i) == red.at(k) ) okane--;
    }
    if( okane > maxen ) maxen = okane;
  }
  cout << maxen << endl;
}


Measured memory_bytes: 512
import java.util.*;

public class Main {
    
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String[] N = sc.next().split("");
        if ((N[0].equals(N[1]) && N[1].equals(N[2])) || (N[2].equals(N[3]) && N[1].equals(N[2]))) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }   
}


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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

typedef long long ll;

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

const int maxn = 55;
const int inf = 0x3f3f3f3f;

int n,m;
string g[maxn];
int dist[maxn][maxn];
pair<int,int> prv[maxn][maxn];

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

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

  memset(dist, inf, sizeof dist);
  for (int i=0; i<n; i++) {
    for (int j=0; j<m; j++) {
      prv[i][j].first = -1;
      prv[i][j].second = -1;
    }
  }


  queue<pair<pair<int,int>,pair<int,pair<int,int>>>> q;
  q.push({ {0,0}, {0, {-1,-1}}});

  while (!q.empty()) {
    auto cur = q.front(); q.pop();
    auto at = cur.first;
    int dst = cur.second.first;
    auto previous = cur.second.second;
    dist[at.first][at.second] = dst;
    prv[at.first][at.second] = previous;

    vector<pair<int,int>> moves = { {-1,0}, {0,-1}, {1,0}, {0,1} };
    for (auto mo: moves) {
      int x = mo.first + at.first; int y = mo.second + at.second;
      if (x<0 || y<0 || x>=n || y>=m || dist[x][y] <= dst+1 || g[x][y]=='#') continue;
      dist[x][y] = dst+1;
      q.push({ {x,y}, {dst+1, at} });
    }
  }

  if (dist[n-1][m-1] == inf) out(-1);
  
  int x = n-1; int y = m-1;
  while (x!=-1 && y!=-1) {
    g[x][y] = '#';
    int x2 = prv[x][y].first;
    int y2 = prv[x][y].second;
    x = x2; y = y2;
  }

  int ans = 0;
  for (int i=0; i<n; i++) {
    for (int j=0; j<m; j++) {
      ans += (g[i][j] == '.');
    }
  }


  out(ans);

  return 0;
}


Measured memory_bytes: 896
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; --i)
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define FORR(i, a, b) for (int i = b - 1; i >= a; --i)
#define SORT(v) sort(v.begin(), v.end())
#define SORTR(v) sort(v.rbegin(), v.rend())
#define REV(v) reverse(v.begin(), v.end())
#define ITER(itr, v) for (auto itr = v.begin(); itr != v.end(); ++itr)
#define LB(v, x) (lower_bound(v.begin(), v.end(), x) - v.begin())
#define UB(v, x) (upper_bound(v.begin(), v.end(), x) - v.begin())
#define SZ(v) (int)v.size()
using namespace std;
using ll = long long;
using P = pair<int, int>;

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

    string s;
    cin >> s;
    int res = 0;
    REP(i, s.size()) {
        if (i % 2 == 0) {
            res -= (s[i] == 'p');
        } else {
            res += (s[i] == 'g');
        }
    }
    cout << res << endl;

    return 0;
}


Measured memory_bytes: 3788
#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 Eback(s) s.erase(s.end()-1,s.end())
#define rev(v) reverse(all(v))
#define minvec(v) *min_element(all(v))
#define maxvec(v) *max_element(all(v))
#define sumvec(v) accumulate(all(v),0)
#define mapmax(v) v.rbegin()->first
#define mapmin(v) v.begin()->first
#define pb push_back
#define pf push_front
#define mod 1000000007
#define m_p make_pair
#define DOUBLE fixed << setprecision(15)
#define OK puts("OK")
#define OK1 puts("OK1")
#define OK2 puts("OK2")
#define SIZE(s) (int)s.size()
#define INF ((1LL<<62)-(1LL<<31))
#define zero(x,n) setw(x) << setfill('0') << n

typedef long long ll;

typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<double> vd;
typedef vector<char> vc;
typedef vector<string> vs;

typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef vector<pair<int,int>> vpii;
typedef vector<pair<ll,ll>> vpll;

const double pi = acos(-1.0);

template<class A, class B>
ostream& operator<<(ostream& ost, const pair<A, B>&p) {
	ost << "{" << p.first << ", " << p.second << "} ";
	return ost;
}

template<class T>
ostream& operator<<(ostream& ost, const vector<T>&v) {
	ost << "{";
	for (int i = 0; i<(int)v.size(); i++) {
		if (i)ost << " ";
		ost << v[i];
	}
	ost << "} \n";
	return ost;
}

template<class A, class B>
ostream& operator<<(ostream& ost, const map<A, B>&v) {
	ost << "{";
	for (auto p:v) {
		ost << "{" << p.first << ", " << p.second << "} ";
	}
	ost << "} ";
	return ost;
}

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;}

ll gcd(ll x, ll y) {return __gcd(x,y);}
ll lcm(ll x, ll y) {return x/__gcd(x,y)*y;}

int main()
{
	ll x,y,a,b,c,sum=0;
	cin >> x >> y >> a >> b >> c;
	vll p(a),q(b),r(c),tmp;
	rep(i,a) cin >> p[i];
	rep(i,b) cin >> q[i];
	rep(i,c) cin >> r[i];
	sort(rall(p));
	sort(rall(q));
	sort(rall(r));
	rep(i,x) tmp.pb(p[i]);
	rep(i,y) tmp.pb(q[i]);
	rep(i,c) tmp.pb(r[i]);
	cerr << tmp;
	sort(rall(tmp));
	rep(i,x+y) sum+=tmp[i];
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 8688
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>
#include <iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<P,P> PP;
const ll MOD=998244353;
const ll MAX_N=500010;
const ll INF=100100100100100;


int main(){
    int a,p;
    cin>>a>>p;
    int n=a*3+p;
    cout<<n/2<<endl;
}

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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = ((int)(n)-1); i >= 0; i--)
#define all(x) (x).begin(),(x).end()
 
using namespace std;
using ll = long long;
 
struct edge { int to, cost; };
 
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> P;
 
const int INF = ~(1<<31);
const int MOD = 1e9+7;
const double EPS = 1.0e-10;
const double PI = acos(-1.0);
 
const int mx4[] = {0,1,0,-1};
const int my4[] = {1,0,-1,0};
const int mx8[] = {0,1,1,1,0,-1,-1,-1};
const int my8[] = {1,1,0,-1,-1,-1,0,1};

double toRad(double deg){
	return deg*(PI/180.0);
}

double limit(int a,int b,double deg){
	if(a*sin(toRad(deg)) > b*sin(toRad(90-deg))){
		double s = a*b/tan(toRad(deg))*b/2.0;
		return s;
	}else{
		double s1 = a*a*sin(toRad(deg))*a/sin(toRad(90-deg))/2.0;
		double s2 = a*(b*sin(toRad(90-deg))-a*sin(toRad(deg)))*a/sin(toRad(90-deg));
		return s1+s2;
	}
}

int main()
{
	int a,b,x;
	cin >> a >> b >> x;
	double l = 0,r = 90;
	while(r-l > EPS){
		if(limit(a,b,(l+r)/2.0) > x) l = (l+r)/2.0;
		else r = (l+r)/2.0;
	}
	cout << fixed << setprecision(10) << l << endl;
 	return 0;
}


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

int bsearch(int key, int array[], int size){
        int mid = size/2;
        int left = 0;
        int right = size;

        while(left<right){
            mid = (left+right)/2;
            if(array[mid]==key){
                 return 1;
            }
            else if(key<array[mid]){
                 right = mid;
            }
            else{
                 left = mid+1;
            }
        }
        return 0;
}


int main() {

    int num_s;
    int num_t;
    int count = 0;
    int key;

    cin >> num_s;
    int S[num_s];

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

    cin >> num_t;
    int T[num_t];

    for(int j=0; j<num_t; j++){
        cin >> T[j];
    }


    for(int i=0; i<num_t; i++){
            key = T[i];
            int temp = bsearch(key, S, num_s);
            count = count + bsearch(key, S, num_s);
     }

    cout << count << endl;
    return 0;

}

Measured memory_bytes: 3552
#include <bits/stdc++.h>
typedef long long int lint;

#define PI acos(-1)
#define INF64 1LL << 60
#define INF32 1 << 29
#define all(a) (a).begin(), (a).end()
#define INV ((long long int)1000000007)

using namespace std;

void execute()
{
	int X, t;
	cin >> X >> t;
	cout << max(0, X - t) << endl;
	return;
}

int main()
{
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	execute();

	int stop;
	cin >> stop;

	return 0;
}

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

//ユークリッドの互除法
//最大公約数を返す
int GCD(int x, int y)
{
	int big = max(x, y), small = min(x, y);


	//ユークリッドの互除法
	while (big % small != 0) {//余り0で終了
		int amari = big % small;
		big = move(small);
		small = move(amari);
	}

	return small;
}

//最小公倍数
int LCM(int a, int b)
{
	//LCM = a*b/GCD

	return a * b / GCD(a, b);
}

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

	int a[10];

	cin >> a[0] >> a[1];

	ans = LCM(a[0], a[1]);

	for (int i = 2; i < n; i++) {
		cin >> a[i];

		ans = LCM(a[i], ans);

	}

	cout << ans << endl;

	return 0;
}


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

int main(){
    vector<int> time(5);
    rep(i,5) cin >> time[i];
    vector<int> si = time;
    rep(i,5){
        si[i]%=10;
    }
    rep(i,5){
        if(time[i]%10!=0)
            time[i]+=(10-si[i]);
    }
    sort(si.begin(),si.end());
    // rep(i,5) cout << time[i] << endl;
    if(si[0] != 0){
        cout << si[0]+time[0]+time[1]+time[2]+time[3]+time[4]-10 << endl;
        return 0;
    } else{
        rep(i,5){
            if(si[i]!=0){
                cout << si[i]+time[0]+time[1]+time[2]+time[3]+time[4]-10 << endl;
                return 0;
            }
        }
        cout << time[0]+time[1]+time[2]+time[3]+time[4] << endl;
        return 0;

    }
}

Measured memory_bytes: 384
import math
import collections

#n,m = 3,2
#a = [4,1,5]
n, m = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
b = [0 for i in range(n)]
for i,ai in enumerate(a):
    if i == 0:
        b[i] = ai % m
    else:
        b[i] = (ai + b[i-1]) % m

ans = 0

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

c = collections.Counter(b)
for i in c.values():
    if i >= 2:
        ans += combinations_count(i,2)

#for i in range(m):
#    c = b.count(i)    
#    if c >= 2:
#        ans += combinations_count(c,2)
ans += b.count(0)

print(ans)

Measured memory_bytes: 16592
#include<bits/stdc++.h>
#define Fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
int main()
{
    Fast;
    long long t,n,m,i,j,k,x=0,y=0,z;
    cin>>n>>m;
    x=n%m;
    y=n/m;
    if(x==0){
        cout<<y<<endl;
    }
    else{
        cout<<y+1<<endl;
    }
}


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

#define int long long
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

signed main(){
	int a[10];
	cin >> a[0] >> a[1] >> a[2] >> a[3] >> a[4];

	for(int i = 0;i < 5;i++){
		if(a[i] == 0){
			cout << i+1 << endl;
			return 0;
		}
	}


	return 0;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;
template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}
int main() {
  cin.tie(0);
  cout << fixed << setprecision(10);
  int n; cin >> n;
  string s; cin >> s;
  int cnt = 1;
  for(int i=1;i<n;++i) {
    if(s[i] != s[i-1]) {
      cnt++;
    }
  }
  cout << cnt << endl;
}


Measured memory_bytes: 512
#include<iostream>
#include<stdio.h>
static const int MAX = 100;
    
// 順番が逆になっている隣接要素がなくなるまで、次の処理を繰り返す
// -> 配列の末尾から隣接する要素を順番に比べていき、大小関係が逆ならば交換する。

void writeLine (int A[], int N) {
    for (int i = 0;i < N;i++) {
        if (i > 0) {
            printf(" ");
        }
        printf("%d", A[i]);
    }
    printf("\n");
}

int bubbleSort(int A[], int N, int acc) {
    int cnt = 0;
    for (int i = N - 1;i > 0;i--) {
        int r = A[i];
        int l = A[i - 1];
        if (l > r) {
            A[i] = l;
            A[i - 1] = r;
            cnt++;
        }
    }
    if (cnt > 0) {
        cnt = bubbleSort(A, N, cnt);
    }
    return acc + cnt;
}

int main() {
    int N;
    scanf("%d", &N);
    
    int A[N];
    for (int i = 0;i < N;i++) {
        scanf("%d", &A[i]);
    }
    
    int cnt = bubbleSort(A, N, 0);
    writeLine(A, N);
    printf("%d\n", cnt);
   
    return 0;
}



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

int D;
int C[26];
int S[365][26];

int64_t evaluate(const vector<int> &T) {
  int64_t res = 0;
  vector<int> last(26);
  for (int i = 0; i < T.size(); ++i) {
    res += S[i][T[i] - 1];
    last[T[i] - 1] = i + 1;
    for (int j = 0; j < 26; ++j) {
      res -= C[j] * (i + 1 - last[j]);
    }
  }
  return res;
}

int64_t evaluate_avg(const vector<int> &T) {
  int64_t res = 0;
  vector<int> last(26);
  for (int i = 0; i < T.size(); ++i) {
    res += S[i][T[i] - 1];
    last[T[i] - 1] = i + 1;
    for (int j = 0; j < 26; ++j) {
      res -= C[j] * (i + 1 - last[j]);
    }
  }
  for (int i = T.size(); i < min((int) T.size() + 13, D); ++i) {
    for (int j = 0; j < 26; ++j) {
      res -= C[j] * (i + 1 - last[j]);
    }
  }
  return res;
}

int main() {
  cin >> D;
  for (int i = 0; i < 26; ++i) cin >> C[i];
  for (int i = 0; i < D; ++i) for (int j = 0; j < 26; ++j) cin >> S[i][j];

  vector<int> T;
  for (int _ = 0; _ < D; ++_) {
    pair<int64_t, int> best = make_pair(numeric_limits<int64_t>::min(), 0);
    for (int n = 1; n <= 26; ++n) {
      T.push_back(n);
      best = max(best, make_pair(evaluate_avg(T), n));
      T.pop_back();
    }
    assert(best.second);
    T.push_back(best.second);
  }

  for (int i = 0; i < D; ++i) cout << T[i] << endl;

  return 0;
}



Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
//#include <boost/multiprecision/cpp_int.hpp>
//using multiInt = boost::multiprecision::cpp_int;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template <typename Q_type>
using smaller_queue = priority_queue<Q_type, vector<Q_type>, greater<Q_type>>;

const int MOD_TYPE = 1;
const ll MOD = (MOD_TYPE == 1 ? (ll)(1e9 + 7) : 998244353);
const int INF = (int)1e9;
const ll LINF = (ll)4e18;
const double PI = acos(-1.0);

#define REP(i, m, n) for (ll i = m; i < (ll)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define possible(n) cout << ((n) ? "possible" : "impossible") << endl
#define Yay(n) cout << ((n) ? "Yay!" : ":(") << endl
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x) cerr << #x << ":" << x << endl;

vector<int> Dx = {0, 0, -1, 1, -1, 1, -1, 1, 0};
vector<int> Dy = {1, -1, 0, 0, -1, -1, 1, 1, 0};

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(50) << setiosflags(ios::fixed);
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  int q;
  cin >> q;
  rep(qi, q)
  {
    int k;
    cin >> k;
    auto p = equal_range(all(a), k);
    cout << distance(a.begin(), p.first) << " ";
    cout << distance(a.begin(), p.second) << "\n";
  }
  return 0;
}



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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using pi = pair<int, int>;
const ll INF = 1LL << 60;


int main() {
    string s, t, tmp;
    cin >> s >> t;
    bool ans = false;
    int len = s.size() - 1;
    rep(i, len + 1) {
        if (s == t) {
            ans = true;
            break;
        }
        s += s[0];
        s = s.substr(1, len+1);
    }

    if (ans) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <math.h>
#include <complex>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <functional>
#include <assert.h>
#define int long
#define ll long long
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define eb emplace_back
#define all(x) x.begin(),x.end()
#define SZ(x) x.size()
#define fi first
#define se second
const int INF = 1e9;
using namespace std;

template<class t> using vc=vector<t>;
template<class t> using vvc=vc<vc<t>>;

using pi=pair<int,int>;
using vi=vc<int>;

template <typename T>
vector<T> dijkstra(int s,vector< vector< pair<int, T> > > & G){
  const T INF = numeric_limits<T>::max();
  using P = pair<T, int>;
  int n=G.size();
  vector<T> ds(n,INF);
  vector<int> bs(n,-1);
  priority_queue<P, vector<P>, greater<P> > pq;
  ds[s]=0;
  pq.emplace(ds[s],s);
  while(!pq.empty()){
    P p=pq.top();pq.pop();
    int v=p.second;
    if(ds[v]<p.first) continue;
    for(auto& e:G[v]){
      int u=e.first;
      T c=e.second;
      if(ds[u]>ds[v]+c){
        ds[u]=ds[v]+c;
        bs[u]=v;
        pq.emplace(ds[u],u);
      }
    }
  }
  return ds;
}

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

    int N,u,v; cin >> N >> u >> v;
    u--; v--;
    vvc<pi> G(N);
    rep(i,N-1){
        int a,b; cin >> a >> b;
        a--;b--;
        G[a].eb(b,1);
        G[b].eb(a,1);
    }

    vi A=dijkstra(u,G);
    vi B=dijkstra(v,G);
    int ans=0;
    rep(i,N){
        if(A[i]<B[i]){
            ans=max(ans,B[i]);
        }
    }
    cout << ans-1 << endl;
}

Measured memory_bytes: 10912
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <functional>

using namespace std;

int main()
{
    int n;
    cin >> n;
    vector<long long> a;
    long long temp;
    for (int i = 0; i < 3 * n; ++i) {
        cin >> temp;
        a.push_back(temp);
    }
    sort(a.begin(), a.end(), greater<long long>());

    long long sum = 0;

    for (int i = 1; i < 2 * n; i += 2) sum += a[i];
    cout << sum << endl;
}


Measured memory_bytes: 6384
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define fi first
#define se second
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define rep11(i, n) for (int i = 1; i < (int)(n); ++i)
#define repo(i, o, n) for (int i = o; i < (int)(n); ++i)
#define repm(i, n) for (int i = (int)(n)-1; i >= 0; --i)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define pb(n) push_back(n)
#define mp make_pair
#define MOD 1002000007
#define INF LONG_LONG_MAX
int main(){
    int n;
    cin>>n;
    int a[n];
    rep(i,n){
        cin>>a[i];
    }
    int flag=0;
    rep(i,n){
        if (a[i]%2==0){
            if(a[i]%3!=0 && a[i]%5!=0){
                flag=1;
            }
        }
    }
    if (flag==0){
        cout<<"APPROVED"<<endl;
    }
    else{
        cout<<"DENIED"<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
import sys
from heapq import heappush, heappop
input = sys.stdin.readline

N, M = map(int, input().split())
A = [int(v) for v in input().split()]
LR = [list(map(int, input().split())) for _ in range(M)]

heap = []
for v in A:
    heappush(heap, (v * -1, 1))

for c, p in LR:
    heappush(heap, (p * -1, c))
    
res = 0
while N > 0:
    v, c = heappop(heap)
    v *= -1
    
    if N < c:
        res += v * N
        N = 0
    else:
        res += v * c
        N -= c
        
print(res)

Measured memory_bytes: 53368
n=int(input())
h = int(input())
w = int(input())

def con(a):
    hw = 0
    b = n%a
    if a==1:
        return n
   
    for i in reversed(range(n+1-a,n+1)):
        ans = i/a
        hw+=int(ans)
        if ans<=1:
            break
    return hw

re1 = con(h)
re2 = con(w)
print(re2*re1)


Measured memory_bytes: 3060
GI = lambda: int(raw_input()); GIS = lambda: map(int, raw_input().split())

def main():
  A = GI()
  B = GI()
  C = GI()
  X = GI()

  waze = 0
  for a in xrange(A+1):
    for b in xrange(B+1):
      left = X - (a * 500 + b * 100)
      if left >= 0 and left / 50 <= C:
        waze += 1

  print(waze)

main()

Measured memory_bytes: 29548
#include<bits/stdc++.h>
using namespace std;
const int maxn = 105;
int a[maxn];
int main(){
    int n;
    cin >> n;
    int flag = 1;
    for(int i = 0; i < n; i++){
        cin >> a[i];
        if(a[i] % 2 == 0)
        	if((a[i] % 3 == 0) || (a[i] % 5 == 0))
            	continue;
        else
            flag = 0;
    }
    if(flag)
        cout << "APPROVED" << '\n';
    else
        cout << "DENIED" << '\n';
}

Measured memory_bytes: 256
#include<bits/stdc++.h> 
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace std;
using namespace __gnu_pbds;  
#define ordered_set tree<ll, null_type , less<ll> , rb_tree_tag , tree_order_statistics_node_update> 
#define ll long long
#define ull unsigned long long
#define pb push_back
#define inf 1e18
#define mk make_pair
#define ld long double
#define mod 1000000007
#define fi first
#define se second
#define fastIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define test ll t; cin>>t; while(t--)
#define setbits __builtin_popcount
#define endl '\n'
int main()
{
    fastIO;
    ll n,w;
    cin>>n>>w;
    ll a[n],b[n];
    for(int i=0;i<n;i++)
    {
        cin>>a[i]>>b[i];
    }
    ll x,y,val,val1;
    val=INT_MIN;
    ll ans[n+1][w+1];
    memset(ans,0,sizeof(ans));
    for(int i=1;i<=n;i++)
    {
        x=a[i-1];
        val1=b[i-1];
        for(int j=1;j<=w;j++)
        {
            y=j-x;
            if(y<0)
            {   
                ans[i][j]=ans[i-1][j];
            }
            else
            {
                ans[i][j]=max(ans[i-1][j],val1+ans[i-1][j-x]);
            }
        }
    }
    cout<<ans[n][w]<<endl;
}

Measured memory_bytes: 79104
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

int main (void) {

    int ox[4] = {-1, 0, 1, 0};
    int oy[4] = {0, 1, 0, -1};

    do {
        unsigned int data_size;
        cin >> data_size;
        if (data_size == 0) { break; }

        int xs[data_size];
        int ys[data_size];

        xs[0] = 0;
        ys[0] = 0;

        int n, d;
        unsigned int i = 1;
        while (i < data_size) {
            cin >> n >> d;

            xs[i] = xs[n] + ox[d];
            ys[i] = ys[n] + oy[d];

            i++;
        }

        int xmin=0, xmax=0, ymin=0, ymax=0;

        for (int j=0; j<data_size; j++) {
            xmin = min(xmin, xs[j]);
            xmax = max(xmax, xs[j]);
            ymin = min(ymin, ys[j]);
            ymax = max(ymax, ys[j]);
        }

        cout << abs(xmin) + xmax + 1 << ' ' << abs(ymin) + ymax + 1<< endl;

    } while (true);

    return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <bits/stdc++.h>
#include <string>
#include <vector>
#include <set>

using namespace std;

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

    long long tmp = 1 ;

    for (int i = 1; i <= n; i++)
    {
        tmp = (i*tmp)%1000000007 ;
    }
    
   cout << tmp << endl ;

  return 0 ;
}

Measured memory_bytes: 256
#include<iostream>
#include<climits>
#include<math.h>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<stdio.h>
#include <string>
#include <complex>
#include <functional>
using namespace std;
typedef pair<int,int> P;
double dat[100][100];
int dp[6][1010];//動的計画法
int prime[10000001];
char str[1010][1010];
vector<pair<int,int> > pc[100001];
int ABS(int a){return max(a,-a);}
int main(){
	string a,s,b;
	cin>>a>>s>>b;
	cout<<"A"<<s[0]<<"C"<<endl;
	return 0;
}

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

using namespace std;

typedef long long ll;

#define int ll

#define FOR(i, l, r) for(int i = l; i <= r; ++i)
#define FORD(i, l, r) for(int i = l; i >= r; --i)

const int Nmax = 2e5 + 10;

int n, res;
int a[Nmax], b[Nmax], c[Nmax], ps[Nmax];

int cnpa(int d){
    int left = 1, right = n; int mid = (left + right)/2;
    while(left != mid && right != mid){
        if(a[mid] < d) left = mid;
            else right = mid;
        mid = (left + right)/2;
    }
    FORD(mid, right, left) if(a[mid] < d) return mid;
    return 0;
}

int cnpb(int d){
    int left = 1, right = n; int mid = (left + right)/2;
    while(left != mid && right != mid){
        if(b[mid] < d) left = mid;
            else right = mid;
        mid = (left + right)/2;
    }
    FORD(mid, right, left) if(b[mid] < d) return ps[mid];
    return 0;
}

int32_t main(){
    //freopen("test.inp", "r", stdin);
    cin >> n;
    FOR(i, 1, n) cin >> a[i];
    FOR(i, 1, n) cin >> b[i];
    FOR(i, 1, n) cin >> c[i];
    sort(a + 1, a + n + 1); sort(b + 1, b + n + 1); sort(c + 1, c + n + 1);
    FOR(i, 1, n){
        ps[i] = ps[i-1] + cnpa(b[i]);
    }
    FOR(i, 1, n){
        res += cnpb(c[i]);
    }
    cout << res;
}


Measured memory_bytes: 5632
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
   
  char ch;
  int ta[200000];
  int n,a,b,c,time,mx,cnt;
  while(1){
    cin>>n;
    if(n==0)break;
    for(int i=0;i<n*2;i++){
      cin>>a>>ch>>b>>ch>>c;
      time=a*100000+b*1000+c*10;
      //cout<<time<<endl;
      if(i%2==0)time+=1;
      ta[i]=time;
    }
    sort(ta,ta+n*2);
    mx=cnt=0;
    for(int i=0;i<n*2;i++){
      if(ta[i]%10){
    cnt++;
      }else{
    cnt--;
      }
      if(mx<cnt)mx=cnt;
    }
    cout<<mx<<endl;
  }
  return 0;
}

Measured memory_bytes: 1260
import java.util.*;
import java.util.Arrays;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

public class Main{

	public static void main(String[] args){

		Scanner sc = new Scanner(System.in);
        int N  = sc.nextInt();
      
        Map<Integer,String> m = new TreeMap<>(new Comparator<Integer>(){
           public int compare(Integer m , Integer n){
             return((Integer)m).compareTo(n) *-1;
           }
        });
      
        String[] shop01 = new String[N];
        int[] score01 = new int[N];
        
         for(int i = 0; i < N ; i++){
           shop01[i] = sc.next();
           score01[i] = sc.nextInt();
         }
          
        for(int i = 0; i < N ; i++){
           m.put(score01[i],shop01[i]);
        }
         
        String[] shop02 = shop01.clone();
        Arrays.sort(shop01);
      
       List<Integer> ans = new ArrayList<>();
       for(int i = 0; i < N ; i++){
         String same = shop01[i];
         for(Map.Entry<Integer,String> m1 : m.entrySet()){
           if(same.equals(m1.getValue())){
             int num = m1.getKey();
             for(int j = 0; j < N ; j++){
               if(score01[j] == num){
                 ans.add(j+1);
               }
             }
           }
         }
       }
      
      List<Integer> answer = ans.stream().distinct().collect(Collectors.toList());
      for(int i = 0; i < N; i++){
        System.out.println(answer.get(i));
      }
      
	}
}

Measured memory_bytes: 36700