akhauriyash/Code-Regression huggingface dataset:
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
class UnionFind {
private:
  int siz;
  vector<int> a;

public:
  UnionFind(int x) : a(x, -1) {}

  int root(int x) {
    return a[x] < 0 ? x : a[x] = root(a[x]);
  }

  void unite(int x, int y) {
    x = root(x);
    y = root(y);
    if (x == y) return;
    siz--;
    if (a[x] > a[y]) swap(x, y);
    a[x] += a[y];
    a[y] =x;
  }

  bool same(int x, int y) {
    return root(x) == root(y);
  }

  int size(int x) {
    return -a[root(x)];
  }
};

signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  int n;
  cin >> n;
  vector<pair<int, int>> in, x, y;
  for (int i = 0; i < n; i++) {
    int s, t;
    cin >> s >> t;
    in.emplace_back(s, t);
    x.emplace_back(s, i);
    y.emplace_back(t, i);
  }
  sort(x.begin(), x.end());
  sort(y.begin(), y.end());
  vector<pair<int, pair<int, int>>> edge;
  for (int i = 0; i + 1 < n; i++) {
    int idx_x = x[i].second, idx_xx = x[i + 1].second;
    int idx_y = y[i].second, idx_yy = y[i + 1].second;
    edge.emplace_back(min(abs(in[idx_x].first - in[idx_xx].first), abs(in[idx_x].second - in[idx_xx].second)), make_pair(idx_x, idx_xx));
    edge.emplace_back(min(abs(in[idx_y].first - in[idx_yy].first), abs(in[idx_y].second - in[idx_yy].second)), make_pair(idx_y, idx_yy));
  }
  sort(edge.begin(), edge.end());
  long long ans = 0;
  UnionFind uf(n);
  for (int i = 0; i < (int) edge.size(); i++) {
    int u = edge[i].second.first, v = edge[i].second.second;
    if (uf.same(u, v)) continue;
    ans += edge[i].first;
    uf.unite(u, v);
  }
  cout << ans << endl;
  return 0;	
}

Measured memory_bytes: 7772
def main():
    N, C, K = map(int, input().split())
    i = 0
    T = []
    while i < N:
        T.append(int(input()))
        i += 1
    T.sort()
    T.reverse()

    c = 1
    i = 1
    bus = 1
    time = T[0]
    while i < N:
        if time - T[i] > K or c == C:
            bus += 1
            c = 1
            time = T[i]
        elif time - T[i] <= K:
            c += 1
        i += 1

    print(str(bus))

main()

Measured memory_bytes: 7384
#include <iostream>
#include <vector>
using namespace std;
vector<vector<int>> res = {
    {},
    {0,3,0,1,0,2,0,3},
    {0,0,3,2,0,0,1,3},
    {0,0,0,0,3,1,2,3}
};
int main() {
    int a[5], st;
    while (1) {
        st = 0;
        for (int i=0; i<5; ++i) {
            if (cin >> a[i] && a[i]) ; // pass
            else return 0;
            st |= 1 << (a[i] - 1);
        }
        for (int i=0; i<5; ++i) {
            cout << res[a[i]][st] << endl;
        }
    }
}

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

typedef long long ll;
typedef long double ld;
#define REP(i, n) for (int i = 0; i < n; i++)

/* print like python */
void print() {cout << endl;}
template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) {cout << head; if (sizeof...(tail) != 0) cout << " "; print(forward<Tail>(tail)...);}
template <class T> void print(vector<T> &vec) { for (auto& a : vec) { cout << a; if (&a != &vec.back()) cout << " "; } cout << endl; }
template <class T> void print(vector<vector<T>> &df) { for (auto& vec : df) { print(vec); } }

bool check(char c){
    return string("ACGT").find(c) != string::npos;
}
int main()
{
    int a,b,t;
    cin >> a >> b >> t;
    print((t/a)*b);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fin ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ii pair<int,int>
#define F first
#define S second
#define pb push_back
#define pf push_front
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define fore(i,a,b) for(int i = a;i < b; i+= 1)
#define forr(i,a) for(int i = a; i >= 0; i--)
#define fori(i,m) for(auto i = m.begin(); i != m.end(); i++) 
#define w(t) while(t--)
#define sz(s) int(s.size())
#define cls(a,car) memset(a,car,sizeof (a))
#define what_is(x) cerr << #x << " is " << x << endl;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ii> vii;
const int N = 1 * 1e5 + 5;
const ll mod = 998244353;
const int INF = INT_MAX;
const ll INFCAD  = ll(INT_MAX) * 2 + 1;
const double E = 1e-9;
int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
// fflush(stdout)
// cout << flush
// a + b = a ^ b + 2 * (a & b)
int main(){
    //freopen("in","r",stdin);
    //freopen("out","w",stdout);
    fin;
    int n;
    cin >> n;
    int v[n];
    int mn = 1e9;
    fore(i, 0, n - 1)
        cin >> v[i];
    int ans = v[0] + v[n - 2];
    fore(i, 1, n - 1){
        ans += min(v[i - 1], v[i]);
    }
    cout << ans << '\n';

    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
    return 0;
}   

Measured memory_bytes: 512
import java.util.*; import java.io.*; import java.math.*;
public class Main{
	//Don't have to see. start------------------------------------------
	static class InputIterator{
		ArrayList<String> inputLine = new ArrayList<String>(1024);
		int index = 0; int max; String read;
		InputIterator(){
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
			try{
				while((read = br.readLine()) != null){
					inputLine.add(read);
				}
			}catch(IOException e){}
			max = inputLine.size();
		}
		boolean hasNext(){return (index < max);}
		String next(){
			if(hasNext()){
				return inputLine.get(index++);
			}else{
				throw new IndexOutOfBoundsException("There is no more input");
			}
		}
	}
	static HashMap<Integer, String> CONVSTR = new HashMap<Integer, String>();
	static InputIterator ii = new InputIterator();//This class cannot be used in reactive problem.
	static PrintWriter out = new PrintWriter(System.out);
	static void flush(){out.flush();}
	static void myout(Object t){out.println(t);}
	static void myerr(Object t){System.err.print("debug:");System.err.println(t);}
	static String next(){return ii.next();}
	static boolean hasNext(){return ii.hasNext();}
	static int nextInt(){return Integer.parseInt(next());}
	static long nextLong(){return Long.parseLong(next());}
	static double nextDouble(){return Double.parseDouble(next());}
	static ArrayList<String> nextStrArray(){return myconv(next(), 8);}
	static ArrayList<String> nextCharArray(){return myconv(next(), 0);}
	static ArrayList<Integer> nextIntArray(){
		ArrayList<String> input = nextStrArray(); ArrayList<Integer> ret = new ArrayList<Integer>(input.size());
		for(int i = 0; i < input.size(); i++){
			ret.add(Integer.parseInt(input.get(i)));
		}
		return ret;
	}
	static ArrayList<Long> nextLongArray(){
		ArrayList<String> input = nextStrArray(); ArrayList<Long> ret = new ArrayList<Long>(input.size());
		for(int i = 0; i < input.size(); i++){
			ret.add(Long.parseLong(input.get(i)));
		}
		return ret;
	}
	static String myconv(Object list, int no){//only join
		String joinString = CONVSTR.get(no);
		if(list instanceof String[]){
			return String.join(joinString, (String[])list);
		}else if(list instanceof ArrayList){
			return String.join(joinString, (ArrayList)list);
		}else{
			throw new ClassCastException("Don't join");
		}
	}
	static ArrayList<String> myconv(String str, int no){//only split
		String splitString = CONVSTR.get(no);
		return new ArrayList<String>(Arrays.asList(str.split(splitString)));
	}
	public static void main(String[] args){
		CONVSTR.put(8, " "); CONVSTR.put(9, "\n"); CONVSTR.put(0, "");
		solve();flush();
	}
	//Don't have to see. end------------------------------------------
	static void solve(){//Here is the main function
      ArrayList<Integer> one = nextIntArray();
      int A = one.get(0);
      int B = one.get(1);
      if(A <= 8 && B <= 8){
        myout("Yay!");
      }else{
        myout(":(");
      }
	}
	//Method addition frame start



	//Method addition frame end
}


Measured memory_bytes: 32664
n = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)
if n % 2 == 0:
    ans = sum(a[:n // 2]) * 2 - a[0]
else:
    ans = sum(a[:(n - 1) // 2]) * 2 - a[0] + a[(n - 1) // 2]
print(ans)

Measured memory_bytes: 31516
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ar array
#define db double
#define pi 3.14159265358979323846
#define pow pw
int pw(int a,int b){
    int ans=1;
    while(b){
    if (b%2) ans*=a;
    a*=a;
    b/=2;
    }
    return(ans);
}
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    string a,b;
    cin>>a>>b;
    int ans=0;
    for (int i=0;i<a.length();i++)
    {
        if (a[i]!=b[i]) ans++;
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 3872
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<cctype>
#include<iostream>
#include<algorithm>
#include<functional>
#include<vector>
#include<string>
#include<stack>
#include<queue>
#include<map>

using namespace std;
const int dx[] = {1,0,-1,0},dy[] = {0,1,0,-1};
#define INF 999999
#define rep(i,j) for(int i=0;i<(j);i++)
#define reps(i,j,k) for(int i=j;i<k;i++)
typedef long long ll;
typedef unsigned long long ull;
int sum;
int mem[32];
int mi = INF;
void rec(int num,int A,int B){
    if(A + B == sum){
        mi = min(mi,abs(A-B));
        return ;
    }
    rec(num+1,A+mem[num],B);
    rec(num+1,A,B+mem[num]);
}
int main(){
    int n;
    while(scanf("%d",&n), n){
        sum = 0;
        mi = INF;
        memset(mem,0,sizeof(mem));
        rep(i,n){
            scanf("%d",&mem[i]);
            sum += mem[i];
        }
        rec(0,0,0);
        printf("%d\n",mi);
    }
	return 0;
}

Measured memory_bytes: 1188
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
const ll mod=1000000007;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
// head

const int N=501000;
ll L,s[N],t[N];
int n,l[N];
ll dist(ll a,ll b) {
	if (a>b) swap(a,b);
	return max(b-a,L-(b-a));
}
ll gao1(int l,int r) {
	return s[min(r,n)]-s[max(l-1,0)];
}
ll gao2(int l,int r) {
	return t[min(r,n)]-t[max(l-1,0)];
}
int main() {
	scanf("%lld%d",&L,&n);
	for (int i=1;i<=n;i++) scanf("%d",l+i),s[i]=s[i-1]+l[i],t[i]=t[i-1]+L-l[i];
	if (n==1) {
		printf("%lld\n",dist(0,l[1]));
		return 0;
	}
	ll ans=0;
	for (int s=1;s<=n;s++) {
		int fl=s-1,r=n-s;
		if (fl>0) {
			// ting zai s-1
			int len=min(fl-1,r);
			ll w=2*(gao1(s-len-1,s-1)+gao2(s+1,s+len))-l[s-1]+dist(l[s-1],l[s]);
			ans=max(ans,w);
			len=min(fl,r);
			w=2*(gao1(s-len,s-1)+gao2(s+1,s+len))-l[s-1]+dist(l[s-1],l[s]);
			ans=max(ans,w);
		}
		if (r>0) {
			int len=min(r-1,fl);
			ll w=2*(gao2(s+1,s+len+1)+gao1(s-len,s-1))-(L-l[s+1])+dist(l[s],l[s+1]);
			ans=max(ans,w);
//			printf("%d %d %d %d %lld\n",s,s+1,len,len+1,w);
			len=min(r,fl);
			w=2*(gao2(s+1,s+len)+gao1(s-len,s-1))-(L-l[s+1])+dist(l[s],l[s+1]);
			ans=max(ans,w);
//			printf("%d %d %d %d %lld\n",s,s+1,len,len,w);
		}
	}
	printf("%lld\n",ans);
}


Measured memory_bytes: 7296
package main

import "fmt"

func main() {
	var a, b, c, k int
	fmt.Scan(&a, &b, &c, &k)

	if a >= k {
		fmt.Println(k)
	} else if a+b >= k {
		fmt.Println(a)
	} else {
		fmt.Println(a - (k-(a+b)))
	}
}


Measured memory_bytes: 1756
#include <cstdio>
#include <algorithm>
#include <functional>
#include <numeric>
using namespace std;

typedef long long int64;

const int MAX_N = 100000;

int N;
int64 as[MAX_N];

// a > b && a > c
bool is_ok(int64 a, int64 b, int64 c){
	return a < b + c;
}

int64 solve(){
	int64 ans = 0;

	sort(as, as+N, greater<int64>());

	//ツ閉ェツ猟」
	{
		int64 tmp = 0;
		for(int i=0; i+3 <= N; i++){
			if(is_ok(as[i], as[i+1], as[i+2])){
				if(tmp == 0){
					tmp = as[i] + as[i+1] + as[i+2];
					i += 2;
				}
				else{
					ans = tmp + as[i] + as[i+1] + as[i+2];
					break;
				}
			}
		}
	}

	//ツ連ツ堕ア
	for(int i=0; i+6<=N; i++){
		for(int bit=0; bit<(1<<6); bit++)if(__builtin_popcount(bit) == 3){
			int64 xs[3], ys[3];
			int p = 0, q = 0;
			for(int j=0; j<6; j++){
				if( (bit>>j)&1 ){
					xs[p++] = as[i + j];
				}
				else{
					ys[q++] = as[i + j];
				}
			}
			if(is_ok(xs[0], xs[1], xs[2]) && is_ok(ys[0], ys[1], ys[2])){
				return max(ans, accumulate(as+i, as+(i+6), 0LL));
			}
		}
	}

	return ans;
}

int main(){
	scanf("%d",&N);
	for(int i=0; i<N; i++){
		scanf("%lld", as+i);
	}

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

	return 0;
}

Measured memory_bytes: 1504
#include<iostream>
#include <stdio.h>
using namespace std;

double a,b=3.141592653589,c=3.141592653589;
int main(){
	cin>>a;
	b*=a*a;
	c*=a*2;
	printf("%f", b);
	cout<<" ";
	printf("%f\n", c);
	return 0;}


Measured memory_bytes: 1244
#include <iostream>
#include<algorithm>
using namespace std;
int main(void){
    int ill[100001]={0};
    int ren[100001]={0};
    int n,count=0;
    int ans=0;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>ill[i];
        if(i==0||ill[i-1]!=ill[i]){
            ren[count]++;
        }
        else{
            count++;
            ren[count]++;
        }
    }
    ans=max(ren[0]+ren[1],ren[count]+ren[count-1]);
    for(int i=1;i<=count-1;i++){
        ans=max(ans,ren[i-1]+ren[i]+ren[i+1]);
    }
    if(count==1)cout<<n<<endl;
    else cout<<ans<<endl;
    
}



Measured memory_bytes: 3888
N,W = map(int, input().split())
v = [0]*N; w = [0]*N
for i in range(N):
    v[i], w[i] = map(int, input().split())

DP = [0]*(W+1)
for i in range(N):
    value = v[i]; weight = w[i]
    for sum_w in range(W,0,-1):
        if sum_w - weight >= 0:
            DP[sum_w] = max(DP[sum_w], DP[sum_w - weight] + value)

print(DP[W])


Measured memory_bytes: 5720
#include <stdio.h>
int main(void)
{
    int n,i;
    int a[100000] = {};
    int min,max;
    long long int sum = 0;
 
    scanf("%d",&n);
    for(i=0;i<n;i++) scanf("%d",&a[i]);
 
    min = a[0];
    for(i=0;i<n;i++){
       if(min>a[i]) min = a[i];
    }
    max = a[0];
    for(i=0;i<n;i++){
       if(max<a[i]) max = a[i];
    }    
 
    for(i=0;i<n;i++){
      sum += a[i];
    }
     
    printf("%d %d %ld\n",min,max,sum);
    return 0;
}
 

Measured memory_bytes: 1000
#include<stdio.h>

int main(){
	while(1){
	int X[10]={},Y[10]={},Z=0;
	int a,i,j,x[10][10]={};
	scanf("%d",&a);
		if(a==0){
			break;
		}

	for(i=0;i<a;i++){
		for(j=0;j<a;j++){
			scanf("%d",&x[i][j]);
			X[i]=X[i]+x[i][j];
		}
	}


	for(i=0;i<a;i++){
		for(j=0;j<a;j++){
			Y[i]=Y[i]+x[j][i];
		}
	}


	for(i=0;i<a;i++){
		Z=Z+X[i];
	}


	for(i=0;i<a;i++){
		for(j=0;j<a;j++){
			printf("  ");
			if(x[i][j]!=100){
				printf(" ");
			}
			if(x[i][j]<10){
				printf(" ");
			}
			printf("%d",x[i][j]);
		}
		
		if(X[i]<10000){
			printf(" ");
		}
		if(X[i]<1000){
			printf(" ");
		}
		if(X[i]<100){
			printf(" ");
		}
		if(X[i]<10){
			printf(" ");
		}
		printf("%d\n",X[i]);
	}


	for(i=0;i<a;i++){
		if(Y[i]<10000){
			printf(" ");
		}
		if(Y[i]<1000){
			printf(" ");
		}
		if(Y[i]<100){
			printf(" ");
		}
		if(Y[i]<10){
			printf(" ");
		}
		printf("%d",Y[i]);
	}


	if(Z<10000){
		printf(" ");
	}
	if(Z<1000){
		printf(" ");
	}
	if(Z<100){
		printf(" ");
	}
	if(Z<10){
		printf(" ");
	}
	 printf("%d\n",Z);
	}
return 0;
}

Measured memory_bytes: 600
#include<stdio.h>
#include<math.h>
int main(void)
{
  char s[11];
  int a[9],b;
  scanf("%s",s);
  a[0]=(s[0]-48)*1e7;
  a[1]=(s[1]-48)*1e6;
  a[2]=(s[2]-48)*1e5;
  a[3]=(s[3]-48)*1e4;
  a[4]=(s[5]-48)*1e3;
  a[5]=(s[6]-48)*1e2;
  a[6]=(s[8]-48)*1e1;
  a[7]=(s[9]-48)*1;
  b=a[0]+a[1]+a[2]+a[3]+a[4]+a[5]+a[6]+a[7];
  if(b<=20190431){
    printf("Heisei");
  }else{
    printf("TBD");
  }


    
    return 0;
}


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

using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;

int main(void) {
    string s, t;
    cin >> s >> t;

    rep(i, s.size()) {
        if(s[i] != t[i]) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 3620
type bs_tree = Nil | Node of node and
     node = {
         key:int;
         mutable left:bs_tree;
         mutable right:bs_tree
       };;

let new_node key = {key=key;left=Nil;right=Nil};;

let insert t z =
  let rec loop y = function
      Nil -> y
    | Node x ->
       if z.key < x.key then
         loop (Node x) (x.left)
       else
         loop (Node x) (x.right)
  in
  let y = loop t t in
  match y with
    Nil -> (Node z)
  | Node y ->
     if z.key < y.key then
       y.left <- (Node z)
     else
       y.right <- (Node z)
    ;t
;;

let rec print_in = function
    Nil -> ()
  | Node x ->
     print_in (x.left);
     print_string " ";print_int  x.key;
     print_in (x.right)
;;

let rec print_pre = function
    Nil -> ()
  | Node x ->
     print_string " ";print_int x.key;
     print_pre (x.left);print_pre (x.right)
;;

let () =
  let n = read_int () in
  let rec read t = function
      0 -> ()
    | i ->
       let com = Scanf.scanf "%s" (fun x -> x) in
       if com = "insert" then begin
           let arg = Scanf.scanf " %d\n" (fun x -> x) in
           let z = new_node arg in
           read (insert t z) (i-1)
         end
       else if com = "print" then begin
           let _ = Scanf.scanf "%s\n" (fun x -> x) in
           print_in t;print_newline ();
           print_pre t;print_newline ();
           read t (i-1)
         end
       else ()
  in read Nil n
;;

Measured memory_bytes: 28128
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <functional>
#include <initializer_list>
#include <iostream>
#include <limits.h>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
#define REP(i, a, n) for (int i = (a); i < (int)(n); ++i)
#define REPC(i, a, n) for (int i = (a); i <= (int)(n); ++i)
#define ALL(t) t.begin(), t.end()
#define RALL(t) t.rbegin(), t.rend()
#define Yes(cond) cout << (cond ? "Yes" : "No") << endl;
#define YES(cond) cout << (cond ? "YES" : "NO") << endl;
#define DBG(str) cerr << (str) << endl;
using namespace std;
using LL = long long;
using ULL = unsigned long long;
template <class T>
using VEC = std::vector<T>;
template <class T>
using MAT = std::vector<std::vector<T>>;
void DUMP() { cerr << endl; }
template <class Head, class... Tail>
void DUMP(Head &&head, Tail &&... tail)
{
  cerr << head << ", ";
  dump_func(std::move(tail)...);
}
template <typename T>
ostream &operator<<(ostream &os, vector<T> &vec)
{
  os << "{";
  for (auto v : vec)
    os << v << ",";
  os << "}";
  return os;
}

int main()
{
  int n;
  cin >> n;
  string s;
  cin >> s;
  int ma = 0;
  int cur = 0;
  for (auto c : s)
  {
    if (c == 'I')
      cur++;
    else
      cur--;
    ma = max(ma, cur);
  }
  cout << ma << endl;

  return 0;
}


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

using namespace std;

typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int INF = 1000000000;
const ll LINF = (ll) 4000000000000000000;
const ll MOD = (ll) 1000000007;
const double PI = acos(1.0);
const int limit = 100010;

#define REP(i,m,n) for(int i = (int)m; i < (int)n; i++)
#define rep(i,n) REP(i,0,n)
#define rep2(i,n) REP(i,1,n+1)
#define rep3(i,n) REP(i,0,n+1)
#define REPM(i,m,n) for(int i = (int)m; i >= (int)n; i--)
#define REPLL(i,m,n) for(ll i=m;i<(ll)(n);i++)
#define repll(i,n) REPLL(i,0,n)
#define repll2(i,n) REPLL(i,1,n+1)
#define MP make_pair
#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 NP(v) next_permutation(v.begin(),v.end())
#define Size(s) (int) s.size()

//------------------------------------------------------

int main() {
    string s;
    cin >> s;
    int gu = 0, pa = 0, point = 0;

    for (auto c : s) {
        if (c == 'g' && pa + 1 <= gu) {
            point++;
            pa++;
        } else if (c == 'p' && pa + 1 <= gu) {
            pa++;
        } else if (c == 'g') {
            gu++;
        } else {
            point--;
            gu++;
        }
    }
    cout << point << endl;
    return 0;
}

Measured memory_bytes: 512
import numpy as np

def main():
    N, K = map(int, input().split())
    A = np.array(list(map(int, input().split())))
    F = np.array(list(map(int, input().split())))

    A.sort()
    F = np.sort(F)[::-1]

    time = A*F
    high = 10**12 + 1
    low = -1

    while high - low > 1:
        middle = (high + low) // 2

        temp = np.where(time>middle, time-middle, 0)
        temp = np.ceil(temp/F).sum()

        if temp <= K:
            high = middle
        else:
            low = middle

    print(high)


if __name__ == '__main__':
    main()


Measured memory_bytes: 37192
import java.util.*;

class Main {
	 
	public static void main(String[] args) {
		
		Scanner cin=new Scanner(System.in);
		
		Dice dice=new Dice();
		
		for(int i=0;i<6;i++) {
			dice.SurfaceNum[i]=cin.nextInt();
		}
		
		String str=cin.next();
		char Oder[]=str.toCharArray();
		
		for(int i=0;i<Oder.length;i++)dice.rotateDice(Oder[i]);
				
		System.out.println(dice.SurfaceNum[dice.gridX[0]-1]);
	}
	

}


class Dice {
	int SurfaceNum[]=new int[6];
	
	int gridX[]= {1,3,6,4},gridY[]= {1,5,6,2};
	
	int temp=1,i=0;
	
	void rotateDice(char odr) {
		if(odr=='N') {
			temp=gridY[3];
			System.arraycopy(gridY, 0, gridY, 1, gridY.length-1);
			gridY[0]=temp;
			gridX[0]=gridY[0];
			gridX[2]=gridY[2];
		}
		else if(odr=='S') {
			temp=gridY[0];
			System.arraycopy(gridY, 1, gridY, 0, gridY.length-1);
			gridY[3]=temp;
			gridX[0]=gridY[0];
			gridX[2]=gridY[2];
		}
		else if(odr=='E') {
			temp=gridX[3];
			System.arraycopy(gridX, 0, gridX, 1, gridX.length-1);
			gridX[0]=temp;
			gridY[0]=gridX[0];
			gridY[2]=gridX[2];
		}
		else if(odr=='W') {
			temp=gridX[0];
			System.arraycopy(gridX, 1, gridX, 0, gridX.length-1);
			gridX[3]=temp;
			gridY[0]=gridX[0];
			gridY[2]=gridX[2];
		}
	}
	

}


Measured memory_bytes: 26332
#include<bits/stdc++.h>
using namespace std;
#define int long long
typedef unsigned long long ull;
typedef long double ld;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define PI 3.14159265
const int MOD=1e9+7;
 
 
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(a)  (a).begin(),(a).end()

const int N=1e6+5;

int n,k;
int v[N][4];
int dp[N][4];
int go(int pos,int last)
{
    if(pos==n+1)
        return 0;
    int &ans=dp[pos][last];
    if(ans!=-1)
        return ans;
    ans=0;
    for(int i=1;i<=3;i++)
    {
        if(pos==1)
        {
            ans=max(ans,v[pos][i]+go(pos+1,i));
        }
        else
        {
            if(i==last) continue;
            ans=max(ans,v[pos][i]+go(pos+1,i));
        }
    }
    return ans;
}
int32_t main()
{
    IOS;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=3;j++)
        {
            cin>>v[i][j];
        }
    }
    memset(dp,-1,sizeof(dp));
    cout<<go(1,0)<<endl;


}

Measured memory_bytes: 42880
#include <algorithm>
#include <bitset>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define MOD (1000000007l)
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)

using namespace std;

ll dp[1010][1010];

void solve() {
  rep (i, 1010) rep (j, 1010) dp[i][j] = 0;

  ll N;
  cin >> N;

  unordered_map<ll, queue<ll>> schedule;
  rep (i, N) {
    rep (j, N-1) {
      ll A;
      cin >> A;
      schedule[i+1].push(A);
    }
  }

  unordered_map<ll, ll> indices;
  rep (i, N) indices[i+1] = 1;
  queue<ll> q;

  rep (i, N) q.push(i + 1);

  while (q.size() > 0) {
    ll current = q.front();
    q.pop();
    if (schedule[current].size() == 0) continue;
    ll opposite = schedule[current].front();
    if (current == schedule[opposite].front()) {
      ll day = max(dp[current][indices[current]-1], dp[opposite][indices[opposite]-1]) + 1;
      dp[current][indices[current]] = day;
      dp[opposite][indices[opposite]] = day;
      indices[current]++;
      indices[opposite]++;
      q.push(current);
      q.push(opposite);
      schedule[current].pop();
      schedule[opposite].pop();
    }
  }

  for (auto it: schedule) {
    if (it.second.size() != 0) {
      cout << -1 << endl;
      return;
    }
  }

  ll ans = -1;
  rep (i, N) {
    ans = max(ans, dp[i+1][N-1]);
  }
  cout << ans << endl;
}

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout.precision(12);
  solve();
  return 0;
}


Measured memory_bytes: 17024
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
ll a[200008];int oz=0;
void out(int t,int x,int y,int z){
	if(t) putchar('+');else putchar('<');
//	if(t) a[z]=a[x]+a[y];else a[z]=(a[x]<a[y]);
oz++;
	printf(" %d %d %d\n",x-1,y-1,z-1);
}
#define n 30

int cmp(int x,int y){
	for(int i=1247;i<=1248;i++) out(0,7777,7777,i);
	out(0,1248,x,1247);
	out(1,y,1247,1247);
	out(0,5,1247,1247);	
	return 1247;
}
	int a1=100,b1=400,c1=888;int t=36666;
	void mul(int x,int p){
		while(p--) out(1,x,x,x);
	}
	void solve(int xg){
		out(0,t-1,t-1,t);
		for(int i=n;i>=0;i--) {
			out(1,t-1,t,t+1);
			out(1,t,5+i,t);
			out(0,t,xg,a1+i);
			out(1,t-1,t+1,t);
			mul(a1+i,i);
			out(1,a1+i,t,t);
			out(0,t-1,a1+i,a1+i);
		}
	//	for(int i=0;i<=n;i++) cout<<a[a1+i];cout<<"\n";
	}
signed main(){
//	cin>>a[1]>>a[2];
printf("%d\n",8996);
	out(1,1,2,3);out(0,4,3,5);
	
	out(1,1,5,1);
	out(1,2,5,2);//to use < as <=
//	cout<<a[1]<<" "<<a[2]<<"\n";
	for(int i=1;i<=n;i++) out(1,4+i,4+i,5+i);
	solve(1);swap(a1,b1);solve(2);

	for(int i=0;i<=n;i++) for(int j=0;j<=n;j++) {
		out(1,cmp(a1+i,b1+j),c1+i+j,c1+i+j);
	}
	out(0,3,3,3);
	for(int i=0;i<=n+n;i++){
		mul(c1+i,i);
		out(1,c1+i,3,3);
	}
//	cout<<oz<<"\n";
//	cout<<a[2]<<"\n";
	return 0;
}

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

int N;
int A[20];
int x[20][20];
int y[20][20];

int counter(int x) {
    if(x == 0) return 0;
    return counter(x >> 1) + (x & 1);
}

void solve(){
    cin >>N;
    for(int i=1;i<=N;i++){
        cin >>A[i];
        for(int j=1;j<=A[i];j++){
            cin >>x[i][j]>>y[i][j];
        }
    }
    int ans=0;
    for(int bits=1;bits<(1<<N);bits++){
        bool ok=true;
        for(int i=1;i<=N;i++){
            if(!(bits &(1<<(i-1)))) continue;
            for(int j=1;j<=A[i];j++){
                if(((bits>>(x[i][j]-1))&1)^y[i][j])ok=false;
            }
        }
        if(ok)ans=max(ans,counter(bits));
    }
    cout<<ans<<endl;
}

signed main(){
    solve();
}

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

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repr(i, n) for(int i = (int)(n); i >= 0; i--)
#define repm(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define repmr(i, m, n) for(int i = (int)(n); i >= (int)(m); i--)
#define all(x) (x).begin(),(x).end()
#define inf 2e9
#define MOD 1000000007

using namespace std;
typedef long long int lli;
typedef long long ll;


int main(){
  lli n,k,q; cin >> n >> k >> q;
  vector<lli> point(n,0);
  rep(i,q){
    int a; cin >> a;
    a--;
    point[a]++;
  }

  rep(i,n){
    if(q-point[i] < k) cout << "Yes" << endl;
    else cout << "No" << endl;
  }

}


Measured memory_bytes: 1408
class Main
{
	public static void main( String[] args )
	{
		java.util.Scanner sc = new java.util.Scanner( System.in );
		
		while( sc.hasNext() )
		{
			int n = sc.nextInt();
			
			int count = 0;
			for( int a = 0 ; a < 10 ; a++ ){
				for( int b = 0 ; b < 10 ; b++ ){
					for( int c = 0 ; c < 10 ; c++ ){
						for( int d = 0 ; d < 10 ; d++ ){
							if( a+b+c+d == n ) count++;
						}
					}
				}
			}
			System.out.println( count );
		}
	}
}

Measured memory_bytes: 26504
n, x = gets.chomp.split(' ').map(&:to_i)
arr = gets.chomp.split(' ').map(&:to_i)
count = 0
(1...n).each do |i|
  sum = arr[i - 1] + arr[i]
  next if sum <= x
  if sum - x <= arr[i]
    count += sum - x
    arr[i] -= sum - x
  else
    count += sum - x - arr[i]
    count += arr[i]
    arr[i - 1] -= sum - x - arr[i]
    arr[i] = 0
  end
end
print count

Measured memory_bytes: 9612
InpStr=str(input())
result='Yes'
# 処理
if InpStr[0]=='A' and InpStr[1]=='A' and InpStr[2]=='A':
    result='No'

if InpStr[0]=='B' and InpStr[1]=='B' and InpStr[2]=='B':
    result='No'

print(result)

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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define mp(a,b) make_pair(a,b)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;
typedef pair<ll, ll> PL;
typedef pair<P, ll> PPL;

#define INF INT_MAX/3

#define MAX_N 1000

int h(char c){
  return (int)c-'0';
}

int n;
string input;
int vis[1<<10];
vector<int> g[1<<10];

bool dfs(int v,int dame){
  vis[v]=1;
  rep(i,g[v].size()){
    int nv=g[v][i];
    if(vis[nv]==1)return false;
    if(vis[nv]==0&&(dame&nv)==0&&!dfs(nv,dame|nv))return false;
  }
  vis[v]=2;
  return true;
}

int main(){
	cin.sync_with_stdio(false);
  while(1){
    cin>>n;
    if(n==0)break;
    rep(i,1<<10)g[i].clear();
    cin>>input;
    vector<string> s;
    int l=0;
    rep(i,n){
      if(input[i]=='u'){
        s.pb(input.substr(l,i-l));
        l=i+1;
      }
    }
    bool ok=true;
    n=s.size();
    rep(i,n){
      int len=s[i].length();
      bool used[10];
      memset(used,0,sizeof(used));
      rep(j,len){
        if(used[h(s[i][j])])ok=false;
        else used[h(s[i][j])]=true;
      }
    }
    if(!ok){
      cout<<"UNSAFE"<<endl;
      continue;
    }
    rep(i,n){
      int len=s[i].length();
      int nS=1<<h(s[i][0]);
      repl(j,1,len){
        rep(S,1<<10){
          if((S&nS)==0&&((S>>h(s[i][j]))&1)==1){
            g[nS].pb(S);
          }
        }
        nS|=(1<<h(s[i][j]));
      }
    }
    rep(S,1<<10){
      memset(vis,0,sizeof(vis));
      if(!dfs(S,S))ok=false;
    }
    if(ok)cout<<"SAFE"<<endl;
    else cout<<"UNSAFE"<<endl;
  }
	return 0;
}

Measured memory_bytes: 23092
#include <bits/stdc++.h>
using namespace std;
const int maxn=1e5+5;
#define ll long long
const int mod=1e9+7;
int a[maxn]; 
int r[maxn];
bool cmp(int a1,int b1){
	return a[a1]<a[b1];
}
int main()
{
	int n;
	cin>>n;
	for(int i=1;i<=n;i++){
	cin>>a[i];
	r[i]=i;
	}
	sort(r+1,r+n+1,cmp);
	for(int i=1;i<=n;i++)cout<<r[i]<<" ";
	cout<<endl;
	return 0;
}

Measured memory_bytes: 1536
N = int(input())
G = [[] for n in range(N)]

for n in range(N-1):
  a,b,c = map(int,input().split())
  G[a-1].append((b-1,c))
  G[b-1].append((a-1,c))

Q,K = map(int,input().split())
d = N*[-1]
d[K-1] = 0
q = [K-1]

while q:
  t = q.pop()
  for b,c in G[t]:
    if d[b]==-1:
      d[b] = d[t]+c
      q.append(b)

for q in range(Q):
  x,y = map(int,input().split())
  print(d[x-1]+d[y-1])

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

void input()
{ 
    #ifndef ONLINE_JUDGE 
    freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
    #endif
}
#define endl "\n"
#define ll long long int
#define vll vector<ll>
#define pb push_back
#define pll pair<ll,ll>
#define mp make_pair
#define ff first
#define ss second
#define tll tuple<ll,ll,ll>
#define mt make_tuple
#define INF LONG_LONG_MAX
#define mod 1000000007
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rrep(i,a,b) for(ll i=a;i>=b;i--)
#define cases ll t; cin>>t; while(t--)
#define array(a,n) ll a[n]; rep(i,0,n) cin>>a[i];
#define vector(a,n) vll a(n); rep(i,0,n) cin>>a[i];
#define sortall(a) sort(a.begin(),a.end())
#define printall(a,n) rep(i,0,n) cout<<a[i]<<" "; cout<<endl;

// --------------- My Template End --------------- //

int main()
{
    ios_base::sync_with_stdio(0); 
    cin.tie(0); cout.tie(0);
   	//input();
   	int n,m;
 	cin>>n>>m;
 	string str[n];
 	rep(i,0,n)
 	cin>>str[i];
 	ll dp[n][m];
 	dp[0][0]=1;
 	rep(i,0,n)
 	{	rep(j,0,m)
 		{
 			if(str[i][j]=='#')
 			{
 				dp[i][j]=0;
 				continue;
 			}
 			if(j==0)
 			{
 				if(i!=0)
 				dp[i][j]=dp[i-1][j];
 				else
 					dp[i][j]=1;
 			}
 			else if(i==0)
			{
				if(j!=0)
				dp[i][j]=dp[i][j-1];
				else dp[i][j]=1;
			}
 			else
 			dp[i][j]=(dp[i-1][j]%mod+dp[i][j-1]%mod)%mod;

 		}
 	}
 	cout<<dp[n-1][m-1];
}

 

Measured memory_bytes: 9088
//DPL_1C

#include <iostream>
using namespace std;

int main(){
  int N, W;
  cin >> N >> W;

  int v[N], w[N];
  for(int i=0; i<N; i++){
    cin >> v[i] >> w[i];
  }

  int DP[N+1][W+1];

  for(int j=0; j<=W; j++){
    DP[0][j] = 0;
  }

  for(int i=1; i<=N; i++){
    for(int j=0; j<=W; j++){
      if(j<w[i-1]){
        DP[i][j] = DP[i-1][j];
      }else{
        if(DP[i-1][j]>DP[i-1][j-w[i-1]]+v[i-1]){
          if(DP[i-1][j]>DP[i][j-w[i-1]]+v[i-1]){
            DP[i][j] = DP[i-1][j];
          }else{
            DP[i][j] = DP[i][j-w[i-1]]+v[i-1];
          }
        }else{
          if(DP[i-1][j-w[i-1]]+v[i-1] > DP[i][j-w[i-1]]+v[i-1]){
          DP[i][j] = DP[i-1][j-w[i-1]]+v[i-1];
        }else{
          DP[i][j] = DP[i][j-w[i-1]]+v[i-1];
        }
        }
      }
    }
  }

  cout << DP[N][W] <<endl;

  return 0;

}

Measured memory_bytes: 7020
n = int(input())
ans = [0]*(n+5)

for x in range(1,100):
    for y in range(1,100):
        for z in range(1,100):
            temp = x**2 + y**2 + z**2 + x*y + y*z + z*x
            if n>=temp:
                ans[temp]+=1


for i in range(1,n+1):
    print(ans[i])


Measured memory_bytes: 9120
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  
	int N;
  	cin >> N;
  
	int AC,WA,TLE,RE;
  	AC=0;
  	WA=0;
  	TLE=0;
  	RE=0;
  
  	string S;
	for (int i = 0; i < N; i++) {
       cin >> S;
      if(S=="AC"){
      	AC++;
      }else if(S=="WA"){
      	WA++;
      }else if(S=="TLE"){
      	TLE++;
      }else if(S=="RE"){
      	RE++;
      }
	}
  cout << "AC x  "<<AC<<endl;
  cout << "WA x  "<<WA<<endl;
  cout << "TLE x  "<<TLE<<endl;
  cout << "RE x  "<<RE<<endl;

}

Measured memory_bytes: 3588
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
using namespace std;
#define F first
#define S second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define SZ(x) (int)(x).size()
#define int ll

const int N = 1e5 + 10;
int a[N], suf[N];

signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  for (int i = 0; i <= n; i++) {
    cin >> a[i];
  }
  suf[n] =  a[n];
  for (int i = n - 1; i >= 0; i--) {
    suf[i] = suf[i + 1] + a[i];
  }
  if (a[0] > 1) {
    cout << -1 << '\n';
    exit(0);
  }  
  if (a[0] == 1) {
    cout << (n == 0 ? 1 : -1) << '\n';
    exit(0);
  }
  int ans = 1, to_cnt = min(2ll, suf[1]);
  for (int i = 1; i <= n; i++) {
    ans += to_cnt;
    if (a[i] > to_cnt) {
      cout << -1 << '\n';
      exit(0);
    }
    to_cnt -= a[i];
    to_cnt = min(to_cnt * 2, suf[i + 1]);
  }
  cout << ans << '\n';
}

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

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rept(i,n) for(int (i)=0;(i)<=(int)(n);(i)++)
#define reps(i,s,n) for(int (i)=(s);(i)<(int)(n);(i)++)
#define repst(i,s,n) for(int (i)=(s);(i)<=(int)(n);(i)++)
#define repr(i,n) for(int (i)=(n);(i)>=0;(i)--)
#define each(itr,v) for(auto (itr):(v))
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define mp(x,y) make_pair((x),(y))
#define fi first
#define se second
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln "\n"
#define dbg(x) cout<<#x" = "<<(x)<<ln

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<int> > mat;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

const int inf = (int)1e9;
const ll linf = (ll)1e18;
const int mod = (int)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};

struct oreno_initializer {
	oreno_initializer() {
		cin.tie(0);
		ios::sync_with_stdio(0);
	}
} oreno_initializer;

// ????????????????????\????????????????????\????????????????????\????????????????????\????????????????????\????????????????????\????????????????????\????????????????????\????????????????????\???
// .???.:( ^??^)?????????.???.:( ^??^)?????????.???.:( ^??^)?????????.???.:( ^??^)?????????.???.:( ^??^)?????????
// ?????\????????????????????\????????????????????\????????????????????\????????????????????\????????????????????\????????????????????\????????????????????\????????????????????\??????????????????

ll N, W, v[44], w[44], r;
pll ps[1<<20];

int main() {
	cin >> N >> W;
	rep(i,N) cin >> v[i] >> w[i];
	ll n1 = N/2;
	ll n2 = N - n1;
	rep(i,1<<n1) {
		ll sw = 0, sv = 0;
		rep(j,n1) if (i>>j & 1) sw += w[j], sv += v[j];
		ps[i] = mp(sw, sv);
	}
	
	// ???????????????????????????????´??????????
	sort(ps, ps+(1<<n1));
	int m = 1;
	reps(i,1,1<<n1) if (ps[m-1].se < ps[i].se) ps[m++] = ps[i];
	
	rep(i,1<<n2) {
		ll sw = 0, sv = 0;
		rep(j,n2) if (i>>j & 1) sw += w[n1+j], sv += v[n1+j];
		if (sw<=W) {
			ll tv = (lower_bound(ps, ps+m, mp(W-sw, linf))-1)->se;
			chmax(r, tv+sv);
		}
	}
	cout << r << ln;
}

Measured memory_bytes: 19604
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
        Scanner scn =new Scanner(System.in);
        int n=scn.nextInt();
         int x =scn.nextInt();
          int t= scn.nextInt();
          int val = n/x;
          if(n%x!=0){
        	  val++;
          }
          System.out.println(val*t);
	}

}

Measured memory_bytes: 35580
def create_deck():
    marks = ["S","H","C","D"]
    deck = []
    for mark in marks:
        thirteen = [{mark:str(i+1)} for i in range(13)]
        deck.append(thirteen)
    return deck

li = create_deck()
n = int(input())

for i in range(n):
    mark,num = [x for x in input().split()]
    if mark == "S":
        li[0].remove({mark:num})
    if mark == "H":
        li[1].remove({mark:num})
    if mark == "C":
        li[2].remove({mark:num})
    if mark == "D":
        li[3].remove({mark:num})

for j in range(len(li)):
    for it in li[j]:
        for k,v in it.items():
            print(k,v)
        


Measured memory_bytes: 5616
#include<bits/stdc++.h>
//using namespace std;
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define rep(i,j,n) for(ll i=(ll)(j);i<(ll)(n);i++)
#define REP(i,j,n) for(ll i=(ll)(j);i<=(ll)(n);i++)
#define per(i,j,n) for(ll i=(ll)(j);(ll)(n)<=i;i--)
#define ll long long
#define ALL(a) (a).begin(),(a).end()
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(ll)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(ll)(key)))
#define pb emplace_back
#define mp std::make_pair
//
#define endl "\n"
//using std::endl;
using std::cin;
using std::cout;
using std::vector;
using std::string;
using std::upper_bound;
using std::lower_bound;
using vi=vector<ll>;
using vii=vector<vi>;
using pii=std::pair<ll,ll>;
//
constexpr ll MOD=1e9+7;
//constexpr ll MOD=998244353;
//constexpr ll MOD=10000000;
//constexpr ll MOD=1e5;
constexpr ll MAX=1e7;
constexpr ll INF=(1ll<<62);
template<class T>
class prique :public std::priority_queue<T, std::vector<T>, std::greater<T>> {};
const ll N=26;
ll solve(ll D,vii &A,vi &C,vi &S){
    vi last(N,-1);
    ll a=0;
    rep(i,0,D){
        ll memo; memo=S[i];
        last[memo]=i;
        a+=A[i][memo];
        rep(j,0,N) a-=(i-last[j])*C[j];
    }
    return a;
}
int main(){
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    srand((unsigned)time(NULL));
    ll D; cin>>D;
    vi C(N);
    rep(i,0,N) cin>>C[i];
    vii A(D,vi(N));
    rep(i,0,D){
        rep(j,0,N) cin>>A[i][j];
    }
    vi last(N,-1);
    vi ans(D);
    rep(i,0,D){
        ll max=0,memo=0;
        rep(j,0,N){
            if(max<A[i][j]+(i-last[j])*C[j]){
                max=A[i][j]+(i-last[j])*C[j];
                memo=j;
            }
        }
        last[memo]=i;
        ans[i]=memo;
    }
    ll max=solve(D,A,C,ans);
    rep(_,0,45){
        if(_%3==0){
            rep(i,0,D){
                rep(j,0,N){
                    vi S=ans;
                    S[i]=j;
                    ll X=solve(D,A,C,S);
                    if(max<X){
                        max=X;
                        ans[i]=j;
                    }
                }
            }
        }
        else{
            per(i,D-1,0){
                rep(j,0,N){
                    vi S=ans;
                    S[i]=j;
                    ll X=solve(D,A,C,S);
                    if(max<X){
                        max=X;
                        ans[i]=j;
                    }
                }
            }
        }
    }
    rep(i,0,D) cout<<ans[i]+1<<endl;
}


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

int main(){
  int k,a,b;
  cin >> k >> a >> b;

  for(int i = a; i <= b; i++){
    if(i%k==0){
      cout << "OK" << endl;
      return 0;
    }
  }

  cout << "NG" << endl;

  return 0;
}

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

// clang-format off
template <typename T> T gcd(T a, T b) { return b == 0 ? a : gcd(b, a % b); }
template <typename T> T lcm(T a, T b) { return a * b / gcd(a, b); }
template <typename T> T clamp(T val, T min, T max) { return val < min ? min : (max < val ? max : val); }
char capitalize(char c) { return static_cast<char>(std::toupper(static_cast<unsigned char>(c))); }
// template <typename T> size_t max_index(T begin, T end) { return distance(begin, max_element(begin, end)); }
// template <typename T> size_t min_index(T begin, T end) { return distance(begin, min_element(begin, end)); }
// clang-format on

// #define int long long
#define YES "Yes"
#define NO  "No"

using namespace std;

signed main(void) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);

  int num = 0;
  // num = numeric_limits<int>::max();
  // num = numeric_limits<int>::min();
  bool flag = false;
  // flag = true;

  int a, b, c; cin >> a >> b >> c;

  if (a == b && b == c) num = 1;
  else if (a != b && b != c && c != a) num = 3;
  else num = 2;

  cout << num << endl;
  // cout << (flag ? YES : NO) << endl;
  
  return 0;
}


Measured memory_bytes: 256
n = int(input())

s = ['' for i in range(n)]
def dfs(k, c):
    if k == n:
        print("".join(s))
        return
    for i in range(c):
        s[k] = chr(i+ord('a'))
        dfs(k+1, c)
    s[k] = chr(c+ord('a'))
    dfs(k+1, c+1)

dfs(0, 0)

Measured memory_bytes: 4340
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;


class Main{

	public static void main(String[] a){
		int sankaku=0;
		int eikaku=0;
		int donkaku=0;
		int cyokkaku=0;
		int maximum,middle,minimal;
		int[] hen=new int[3];

	    BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		String str="";
		try{
			while(true) {
			str=br.readLine();
			if(str==null) {
				System.out.println(sankaku+" "+cyokkaku+" "+eikaku+" "+donkaku);
			}
			StringTokenizer st=new StringTokenizer(str," ");

			for(int i=0; i<3; i++) {
				hen[i]=Integer.parseInt(st.nextToken());
			}

			maximum=Math.max(hen[0],Math.max(hen[1],hen[2]));
			if(hen[0]==maximum) hen[0]=0;
			else if(hen[1]==maximum) hen[1]=0;
			else if(hen[2]==maximum) hen[2]=0;
			middle=Math.max(hen[0],Math.max(hen[1],hen[2]));
			if(hen[0]==middle) hen[0]=0;
			else if(hen[1]==middle) hen[1]=0;
			else if(hen[2]==middle) hen[2]=0;
			minimal=Math.max(hen[0],Math.max(hen[1],hen[2]));

			if(maximum>=middle+minimal || minimal<=maximum-middle) {
				System.out.println(sankaku+" "+cyokkaku+" "+eikaku+" "+donkaku);
				System.exit(0);
				}
			else if(maximum*maximum==(minimal*minimal+middle*middle)) {
				sankaku++;
				cyokkaku++;
			}
			else if(maximum*maximum>minimal*minimal+middle*middle) {
				sankaku++;
				donkaku++;
			}
			else if(maximum*maximum<minimal*minimal+middle*middle) {
				sankaku++;
				eikaku++;
			}
		}

		}catch(Exception e){
			System.exit(0);
		}
	}
}


Measured memory_bytes: 24256
#include <bits/stdc++.h>
using namespace std;
#define int long long

signed main() {
  string s;
  cin>>s;
  int a=0,b=0,c=0;
  for(int i=0;i<s.size();i++){
      if(s[i]=='a')a++;
      if(s[i]=='b')b++;
      if(s[i]=='c')c++;
  }
  if(max(a,max(b,c))-min(a,min(b,c))<=1)cout<<"YES";
  else cout<<"NO";
}


Measured memory_bytes: 512
#include<stdio.h>

int main(void){
  int N,M,sum=0;
  int a[10009];
  scanf("%d %d\n",&N,&M );
  for(int i=0; i<M; i++){
    scanf("%d",&a[i] );
    sum += a[i];
  }
  if(N < sum){
    printf("-1" );
  }else{
    printf("%d\n",N - sum );
  }
  return 0;
}


Measured memory_bytes: 1736
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
using namespace __gnu_pbds;
using namespace std;
/*
int dx[]={-1,1,0,0};
int dy[]={0,0,-1,1};
*/
#define ull unsigned long long int
#define ll long long int
#define MAX 1000000007
//1e9+7
#define pll pair<ll,ll>
#define pii pair<int,int>
#define IO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define FO ifstream fin("a.in");ofstream fout("a.out");
#define TEST int testcase;cin>>testcase;while(testcase--)
#define all(x) (x).begin(),(x).end()
#define mset0(x) memset((x), 0, sizeof((x)));
#define mset1(x) memset((x), -1, sizeof((x)));
#define endl "\n"
#define plll pair<ll,pll>
#define piii pair<int,pii>
const ll MAXN=2e5;
const ll mod=998244353;
typedef tree<ll,null_type,less<ll>,rb_tree_tag, tree_order_statistics_node_update> indexed_set;

ll mul(ll a,ll b){
    ll ans=0;
    while(b){
        if(b&1) ans=(ans+a)%mod;
        a=(a+a)%mod;
        b/=2;
    }
    return(ans);
}

ll power(ll a,ll b){
    ll ans=1;
    while(b){
        if(b&1) ans=(ans*a)%mod;
        a=(a*a)%mod;
        b/=2;
    }
    return(ans);
}

ll fact[MAXN+1];
void init(){
    fact[0]=1;
    for(int i=1;i<=MAXN;i++){
        fact[i]=(fact[i-1]*i)%mod;
    }
    return;
}
ll C(ll a,ll b){
    ll ans=fact[a];
    ll p=power(fact[b],mod-2),q=power(fact[a-b],mod-2);
    ans=mul(ans,p);
    ans=mul(ans,q);
    return(ans);

}
void solve(){

    ll N,M,K;
    cin>>N>>M>>K;
    ll tot=0;
    for(ll adj=0;adj<=K;adj++){
        ll number_of_block=N-adj;


        ll ways_to_choose_blocks=C(N-1,adj);


        ll ways_to_colour_blocks=M*power(M-1,number_of_block-1);

        //cout<<ways_to_choose_blocks<<" "<<ways_to_colour_blocks<<endl;
        ll ways=mul(ways_to_choose_blocks,ways_to_colour_blocks);
        tot=(tot + ways) % mod;
        if(tot<0) tot+=mod;
    }
    cout<<tot;


    return;
}
int main(){
    IO
    //TEST
    init();
    solve();

    return(0);
}


Measured memory_bytes: 5216
n, x = map(int, input().split())

ans = n

longer = max(x, n-x)
shorter = min(x, n-x)

while True:
    m = longer // shorter
    l = longer % shorter
    ans += m*shorter*2
    if l == 0:
        ans -= shorter
        break
    longer = shorter
    shorter = l
    
print(ans)

Measured memory_bytes: 3064
n,k = map(int,input().split())

data = list(map(int,input().split()))

d = dict()

for item in data:
    if d.__contains__(item):
        d[item]+=1
    else:
        d[item]=1

l = list(d.values())

l.sort()

i = 0
res = 0

if len(l)>k:
    res += sum(l[:len(l)-k])

print(res)


Measured memory_bytes: 32184
#include <bits/stdc++.h>
using namespace std;
    
int main(){
    int a, b, k;
    cin >> a >> b >> k;
    int gc = __gcd(a, b);
    int cnt = 0;
    for(int i=gc; ;i--)
    {
        if(gc % i == 0) cnt++;
        if(cnt==k){
            cout << i << endl;
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 256