akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

struct proc {
  char name[10 + 1];
  int time;
  int fin;

  struct proc *fp;
  struct proc *bp;
};

struct proc list;
struct proc finished;

void add_last(struct proc *h, struct proc *p);
void remove_first(struct proc *h, struct proc *p);

int main(int argc, char *argv[])
{
  int n, q, i;
  int t = 0;
  struct proc *p, *ip;
  struct proc *exec;
  char tmpname[10 + 1];
  int tmptime;

  list.fp = &list;
  list.bp = &list;
  finished.fp = &finished;
  finished.bp = &finished;

  scanf("%d %d", &n, &q);

  p = (struct proc *)malloc(sizeof(struct proc) * n);

  for (i = 0; i < n; i++) {
    scanf("%s", &tmpname[0]);
    scanf("%d", &tmptime);
    strcpy(p[i].name, tmpname);
    p[i].time = tmptime;
    add_last(&list, &p[i]);
  }

  while (list.fp != &list) {
    exec = list.fp;
    remove_first(&list, exec);
    if (exec->time > q) {
      exec->time -= q;
      t += q;
      add_last(&list, exec);
    } else {
      t += exec->time;
      exec->fin = t;
      add_last(&finished, exec);
    }
  }

  for (ip = finished.fp; ip != &finished; ip = ip->fp) {
    printf("%s %d\n", ip->name, ip->fin);
  }

  free(p);
  
  return 0;
}

void add_last(struct proc *h, struct proc *p)
{
  p->fp = h;
  p->bp = h->bp;
  h->bp = p;
  p->bp->fp = p;
}

void remove_first(struct proc *h, struct proc *p)
{
  h->fp = p->fp;
  p->fp->bp = h;
  p->fp = NULL;
  p->bp = NULL;
}

Measured memory_bytes: 2472
#include<iostream>
using namespace std;
int main() {
	int a;
	cin >> a ;
	if (65 <= a&&a <= 90) {
		cout << 1 << endl;
	}
	else if (97 <= a&&a <= 122) {
		cout << 2 << endl;
	}
	else {
		cout << 0 << endl;
	}
}



Measured memory_bytes: 3112
#include <iostream>

using namespace std;

int main(){
	int c1; cin >> c1;
	int c5; cin >> c5;
	int c10; cin >> c10;
	int c50; cin >> c50;
	int c100; cin >> c100;
	int c500; cin >> c500;

	if(c1 + 5 * c5 + 10 * c10 + 50 * c50 + 100 * c100 + 500 * c500 >= 1000){
		cout << 1 << endl;
	}else{
		cout << 0 << endl;
	}
	return 0;
}

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

#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end() //使うときはsort(all())という感じで
#define PI 3.14159265359

using ll = long long;

bool rgbcheck(char a, char b, char c){
    if(a!=b && b!=c && c!=a){
        return true;
    }
    else{
        return false;
    }
}

int main() {
    int n,s;
    cin >> n;
    vector<char> v(n+1);
    vector<int> r,g,b;
    rep(i,n){
        cin >> v[i+1];
        switch (v[i+1])
        {
        case 'R':
            r.push_back(i+1);
            break;
        case 'G':
            g.push_back(i+1);
            break;
        case 'B':
            b.push_back(i+1);
            break;   
        }
    }
    ll ans = r.size()*g.size()*b.size();
    if(r.size()==0||g.size()==0||b.size()==0){
        cout << 0 << endl;
    }
    else{
        rep(i,n){
            rep(j,n){
                if(i<j && j-i<=n/2 && 2*j-i<n){
                    int k = 2*j-i;
                    if(rgbcheck(v[i+1],v[j+1],v[k+1])){
                        ans--;
                    }
                }
            }
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 3632
#include <stdio.h>
#define MAX 100001

typedef struct tree{
  int parent,left,right;
}Node;

Node T[MAX];

int depth(int);
void print_degree(int);

int main(void){
  
  int n,i,j,k,id,child,sibling,tmp2;

  scanf("%d",&n);
  
  for(i=0;i<n;i++){
    T[i].parent=T[i].left=T[i].right=-1;
  }
  for(i=0;i<n;i++){
    scanf("%d %d",&id,&k);
    for(j=0;j<k;j++){
      scanf("%d",&child);
      T[child].parent=id;
      if(j==0){
	T[id].left=child;
      }
      else {
	T[sibling].right=child;
      }
      sibling = child;
    }
  }

  for(i = 0; i < n; i++){
    printf("node %d: parent = %d, depth = %d, ",i,T[i].parent,depth(i));
    if(T[i].parent == -1)
      printf("root, [");
    else if(T[i].left == -1)
      printf("leaf, [");
    else
      printf("internal node, [");
    print_degree(T[i].left);
    printf("]\n");
  }
  
  return 0;
}

int depth(int node){
    if(T[node].parent == -1){
      return 0;
    }
    else {
      return depth(T[node].parent) + 1;
    }
  }
  
void print_degree(int i){
  
  if(i != -1){
    if(T[i].right == -1)
      printf("%d",i);
    else printf("%d, ",i);
  print_degree(T[i].right);
  }
}

Measured memory_bytes: 1784
// A - ><

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const ll MOD = 1e9 + 7;

int l_min[500001];
int r_min[500001];

int main() {
	string S;
	cin >> S;

	int N = S.size();

	// from left
	l_min[0] = 0;
	for (int i=0; i<N; i++) {
		if (S[i] == '<') {
			l_min[i+1] = l_min[i] + 1;
		} else {
			l_min[i+1] = 0;
		}
	}

	// from right
	r_min[N] = 0;
	for (int i=N-1; i>=0; i--) {
		if (S[i] == '>') {
			r_min[i] = r_min[i+1] + 1;
		} else {
			r_min[i] = 0;
		}
	}

	ll ans = 0;

	for (int i=0; i<=N; i++) {
		//cout << l_min[i] << " " << r_min[i] << endl;
		ans += max(l_min[i], r_min[i]);
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 7656
#include <cstdint>
#include <iostream>

using namespace std;

int32_t main()
{
  int32_t x, a, b;
  cin >> x >> a >> b;

  if (b <= a)
    cout << "delicious" << endl;
  else if (b <= (a + x))
    cout << "safe" << endl;
  else
    cout << "dangerous" << endl;

  return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
  
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int X = sc.nextInt();
    
    if (X == 7 || X == 5 || X == 3) {
      System.out.println("YES");
    } else {
      System.out.println("NO");
    }
  }
}

Measured memory_bytes: 21716
# -*- coding:utf-8 -*-

def solve():
    import copy

    N, M, Q = list(map(int, input().split()))
    query = []
    for i in range(Q):
        a, b, c, d = list(map(int, input().split()))
        query.append((a,b,c,d))

    cands = []
    def rec(start, lst):
        if len(lst) == N:
            return lst

        for i in range(start, M+1):
            tmp_lst = copy.deepcopy(lst)
            tmp_lst.append(i)
            ret = rec(i, tmp_lst)
            if ret is not None:
                cands.append(ret)

    rec(1, [])

    ans = 0
    for cand in cands:
        total = 0
        for abcd in query:
            a,b,c,d = abcd
            if cand[b-1]-cand[a-1] == c:
                total += d
        ans = max(ans, total)

    print(ans)




if __name__ == "__main__":
    solve()


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

const int inf = 1000000000;

int main(void)
{
  int N;
  cin >> N;
  vector<int> X(N);
  for (int i = 0; i < N; i++)
  {
    cin >> X[i];
  }

  int L = X[0], R = X[0];
  for (int i = 0; i < N; i++)
  {
    L = min(L, X[i]);
    R = max(R, X[i]);
  }

  int ans = inf;
  for (int i = L; i <= R; i++)
  {
    int cost = 0;
    for (int j = 0; j < N; j++)
    {
      cost += (X[j] - i) * (X[j] - i);
    }
    ans = min(ans, cost);
  }
  cout << ans << endl;
  return 0;
}

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

int main(void){
    int n;
    cin >> n;
    int m = n, sum = 0;
    while(m > 0){
        sum += m%10;
        m /= 10;
    }
    if(n%sum == 0){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
from collections import deque


def main():
    N = int(input())
    A = [int(input())-1 for _ in range(N)]
    X = [True] * (N)
    p = 0
    ans = 0
    while X[p]:
        if p == 1:
            print(ans)
            return
        ans += 1
        X[p] = False
        p = A[p]
    print(-1)


if __name__ == "__main__":
    main()


Measured memory_bytes: 50392
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <map>
#include <set>
using namespace std;
int main(){
    int N;
    cin >> N;
    vector<long long> H(N);
    for(int i = 0; i < N; i++) cin >> H[i];
    if(N == 1) {
        cout << "Yes" << endl;
        return 0;
    }
    for(int i = N - 1; i >= 1; i--){
        if(H[i] < H[i - 1]) H[i - 1]--;
    }
    for(int i = 0; i < N - 1; i++){
        if(H[i] > H[i + 1]){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 4048
import java.io.*;
import java.util.*;

public class Main {
	public static void main(String[] args) throws IOException{
		Scanner sc=new Scanner(System.in);
		Reader reader=new Reader();
		int t=1;//sc.nextInt();
		while(t-->0) {
			String s1=reader.next();
			int n=s1.length();
			String s2=reader.next();
			int len=s2.length();
			int min=Integer.MAX_VALUE;
			for(int i=0;i<n-len+1;i++) {
				String temp=s1.substring(i,i+len);
				int count=0;
				for(int j=0;j<temp.length();j++) {
					if(temp.charAt(j)!=s2.charAt(j)) count++;
				}
				min=Math.min(count, min);
			}
			System.out.println(min);
		}
	}
}
class Reader{
	BufferedReader reader;
	Reader(){
		reader=new BufferedReader(new InputStreamReader(System.in));
	}
	int nextInt() throws IOException{
		String in=reader.readLine().trim();
		return Integer.parseInt(in);
	}
	long nextLong() throws IOException{
		String in=reader.readLine().trim();
		return Long.parseLong(in);
	}
	String next() throws IOException{
		return reader.readLine().trim();
	}
	String[] stringArray() throws IOException{
		return reader.readLine().trim().split("\\s+");
	}
	int[] intArray() throws IOException{
		String[] inp=this.stringArray();
		int[] arr=new int[inp.length];
		int i=0;
		for(String s:inp) {
			arr[i++]=Integer.parseInt(s);
		}
		return arr;
	}
}


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

typedef long long ll;
# define  pii pair<ll,ll> 
# define pb push_back
# define f first 
# define s second 



class Edge
{
    public:
    ll src;
    ll des;
    ll cost;
};

ll dist[100001];

const ll inf=1e18;


int main()
{
    ll n,m,p;
    cin>>n>>m>>p;
    
    vector<Edge> E;
   
    for(ll i=0;i<m;i++)
    {
       
        ll x,y,c;
        cin>>x>>y>>c;
        
        Edge node;
        
        node.src=x;
        node.des=y;
        node.cost=-c+p;
        
        E.pb(node);
    }
    
    fill(dist,dist+n+1,inf);
    
   
    
    dist[1]=0;
    
    for(int i=0;i<n-1;i++)
    {
        for(int j=0;j<E.size();j++)
        {
            ll sr=E[j].src;
            ll de=E[j].des;
            ll co=E[j].cost;
            
            if(dist[sr]!=inf && dist[de]>dist[sr]+co)
                {
                    dist[de]=dist[sr]+co;
                }
        }
    }
    
    
     for(int j=0;j<E.size();j++)
        {
            ll sr=E[j].src;
            ll de=E[j].des;
            ll co=E[j].cost;
            
            if(dist[sr]!=inf && dist[de]>dist[sr]+co)
                {
                    dist[de]=-inf;
                }
        }
        
        
       for(int i=0;i<n-1;i++)
    {
        for(int j=0;j<E.size();j++)
        {
            ll sr=E[j].src;
            ll de=E[j].des;
            ll co=E[j].cost;
            
            if(dist[sr]!=inf && dist[de]>dist[sr]+co)
                {
                    dist[de]=-inf;
                }
        }
    } 
    
    
    if(dist[n]==-inf) cout<<"-1"<<endl;
    else
    {
        cout<<max(-dist[n],(ll)0)<<endl;
    }
        
        
  
    
    
    

	
	return 0;
}


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

int main(){
    int h,w;
    while(1){
        cin>>h>>w;
        if(h==0&&w==0){
            break;
        }
        for(int i=0;i<h;i++){
            for(int j=0;j<w;j++){
                if((i+j)%2==0){
                    cout<<"#";
                }else{
                    cout<<".";
                }
            }
            cout<<endl;
        }
        cout<<endl;
    }
    return 0;
}


Measured memory_bytes: 3076
import scala.io.StdIn._
import scala.collection._

object Main {


  class Sieve(val n: Int){
    private[this] val top = (n - 5) / 2 + 2
    private[this] val cmpsts = new Array[Int]((top >>> 5) + 1)
    private[this] val sqrtLimit = (Math.sqrt(n).toInt - 3) / 2

    def isPrime(ci: Int): Boolean = (cmpsts(ci >>> 5) & (1 << (ci & 31))) == 0
    def setCmpst(ci: Int): Unit = cmpsts(ci >>> 5) |= 1 << (ci & 31)

    private def innerLoop(j: Int, p: Int): Unit = {
      if(j <= top){
        setCmpst(j)
        innerLoop(j + p, p)
      }
    }

    private def loop(i: Int): Unit = {
      if(i <= sqrtLimit){
        if(isPrime(i)){
          val p = 2 * i + 3
          innerLoop((p * p - 3) >>> 1, p)
        }
        loop(i + 1)
      }
    }

    private def next(i: Int): Int =
      if ((i > top) || isPrime(i)) 2 * i + 3 else next(i + 1)

    def exec: Iterator[Int] = {
      loop(0)
      Iterator.single(2) ++ Iterator.single(3) ++ Iterator.iterate(5)(p => next((p - 1) >>> 1)).takeWhile(_ <= n)
    }
  }

  def loop(s: String){
    if(s != null){
       val Array(n,_*) = s.split(" ").map(_.toInt)
       if(n<2) println(0)
       else if(n==2)println(1)
       else println(new Sieve(n).exec.size)
       loop(readLine)
    }
  }

  def main(args: Array[String]): Unit = loop(readLine)
}

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

int main(){

int N;
cin >> N;

long long ans = 1;
	for(int i = 0; i < N; i++){ 
		ans = ans * ( 1 + i );
		ans = ans % 1000000007;
	}
	
cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>

using namespace std;

int main() {
  int n;
  cin >> n;
  vector<int> fn(10001, 0);
  for (int i = 1; i <= 100; ++i)
    for (int j = 1; j <= 100; ++j)
      for (int z = 1; z <= 100; ++z) {
        int res = i * i + j * j + z * z + i * j + j * z + z * i;
        if (res <= 10000)
          ++fn[res];
      }
  for (int i = 1; i <= n; ++i)
    cout << fn[i] << endl;
}

Measured memory_bytes: 3632
n,q=map(int,input().split())
s=input()
d=[0]*(n+1)
for i in range(1,n):
  if s[i]=="C" and s[i-1]=="A":
    d[i]=d[i-1]+1
  else:
    d[i]=d[i-1]

for j in range(q):
  l,r=map(int,input().split())
  print(d[r-1]-d[l-1])


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

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

using namespace std;
#define int long long
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repr(i,n) for(ll i=n;i>=0;i--)
#define P pair<ll, ll>
#define sz(x) (ll)x.size()
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define VE vector<ll>
#define COUT(x) cout<<(x)<<endl
#define MA map<ll,ll>
#define SE set<ll>
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,VE,greater<ll>>
#define COUT(x) cout<<(x)<<endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define EPS (1e-10)


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


long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	unsigned r;
	while ((r = a % b)) {
		a = b;
		b = r;
	}
	return b;
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a * g / b;
}
bool prime(ll n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}




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

const int MAX = 110000;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}


signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	COMinit();
	int n, k; cin >> n >> k;
	VE a(n); rep(i, n)cin >> a[i];
	sort(ALL(a));
	int ans = 0;
	rep(i, n) {
		int tmp = COM(i, k - 1);
		ans += (a[i] * tmp) % MOD; ans %= MOD;
	}
	reverse(ALL(a));
	rep(i, n) {
		int tmp = -COM(i, k - 1);
		ans += (a[i] * tmp) % MOD; ans %= MOD;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3584
import collections

n, k = map(int, input().split())
a = list(map(int, input().split()))
ans = 0

list_a = list(collections.Counter(a).values())
dic = dict(zip(collections.Counter(a), list_a))
dic_sorted = sorted(dic.items(), key=lambda x: x[1])
del_num = dic_sorted[:len(dic_sorted)-k]

for i in del_num:
    ans += i[1]

print(ans)


Measured memory_bytes: 62372
#include<bits/stdc++.h>
#define int long long
using namespace std;
constexpr int mod=1e9+7;
signed main(){
    bool ab[4001]={},ac[4001]={},bc[4001]={};
    string a,b,c;
    cin>>a>>b>>c;
    for(int i=-(int)b.size();i<=(int)a.size();i++){
        int mn=max(0ll,i);
        int mx=min((int)a.size(),(int)b.size()+i);
        for(int j=mn;j<mx;j++){
            if(a[j]!=b[j-i]&&a[j]!='?'&&b[j-i]!='?'){
                ab[i+2000]=1;
                break;
            }
        }
    }
    for(int i=-(int)c.size();i<=(int)a.size();i++){
        int mn=max(0ll,i);
        int mx=min((int)a.size(),(int)c.size()+i);
        for(int j=mn;j<mx;j++){
            if(a[j]!=c[j-i]&&a[j]!='?'&&c[j-i]!='?'){
                ac[i+2000]=1;
                break;
            }
        }
    }
    for(int i=-(int)c.size();i<=(int)b.size();i++){
        int mn=max(0ll,i);
        int mx=min((int)b.size(),(int)c.size()+i);
        for(int j=mn;j<mx;j++){
            if(b[j]!=c[j-i]&&b[j]!='?'&&c[j-i]!='?'){
                bc[i+2000]=1;
                break;
            }
        }
    }
    int ans=6000;
    for(int i=-((int)b.size()+(int)c.size());i<=(int)a.size()+(int)c.size();i++){
        if(0<=i+2000&&i+2000<=4000)
            if(ab[i+2000])
                continue;
        for(int j=-((int)b.size()+(int)c.size());j<=(int)a.size()+(int)b.size();j++){
            if(0<=j+2000&&j+2000<=4000)
                if(ac[j+2000])
                    continue;
            if(0<=j-i+2000&&j-i+2000<=4000)
                if(bc[j-i+2000])
                    continue;
            int mn=min({0ll,i,j});
            int mx=max({(int)a.size(),(int)b.size()+i,(int)c.size()+j});
            ans=min(ans,mx-mn);
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
N = int(input().strip())
A = list(map(int, input().strip().split(' ')))

def sign(n):
  if n > 0:
    return 'pos'
  elif n < 0:
    return 'neg'
  else:
    return 'zero'

# +-+-+-+-...と-+-+-+-+を両方して操作回数が少ない方
# 1イテレーションで2パターン同時にできそう
result_pos = 0
result_neg = 0
now_sum_pos = 0
now_sum_neg = 0
for i,a in enumerate(A):
  now_sum_pos += a
  now_sum_neg += a
  if i%2 == 0:
    if not sign(now_sum_pos) == 'pos':
      result_pos += 1+abs(now_sum_pos)
      now_sum_pos = 1
    if not sign(now_sum_neg) == 'neg':
      result_neg += 1+abs(now_sum_neg)
      now_sum_neg = -1
  elif i%2 == 1:
    if not sign(now_sum_pos) == 'neg':
      result_pos += 1+abs(now_sum_pos)
      now_sum_pos = -1
    if not sign(now_sum_neg) == 'pos':
      result_neg += 1+abs(now_sum_neg)
      now_sum_neg = 1
print(min(result_pos, result_neg))
  

Measured memory_bytes: 14468
#include "bits/stdc++.h"
using namespace std;

#define ASC(vec) vec.begin(), vec.end()		// 昇順ソート 例：sort(ASC(vec));
#define DESC(vec) vec.rbegin(), vec.rend()	// 降順ソート 例:sort(DESC(vec));
#define rep(i, n) for(i = 0; i < n; i++)
#define Rep(i, n) for(i = 1; i < n; i++)
#define Ans(s) cout << s << endl;

const int inf = (int)1e9 + 7;
const long long INF = 1LL << 60;

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

typedef long long ll;

// 4,8方向に探索する際に用いる配列
//int dx[4] = { 0,  0, 1, -1 };
//int dy[4] = { 1, -1, 0,  0 };
//int dx[8] = { 1, 0, -1,  0, 1, -1, -1,  1 };
//int dy[8] = { 0, 1,  0, -1, 1,  1, -1, -1 };

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

	vector<int> l(n);
	for (int i = 0; i < n; i++) cin >> l[i];

	sort(DESC(l));

	int res = 0;

	for (int i = 0; i < k; i++)
	{
		res += l[i];
	}
	cout << res << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>

int main() {
	int n;
	std::string s;

	std::cin >> n;
	std::cin >> s;
	std::vector<int> v(n);

	for(int i = 0; i < n; ++i) {
		if(s[i] == '.') v[i] = 0;	// white
		else v[i] = 1;	// black
	}
	
	int n_change = 1141540;
	int n_change_buf = 0;
	for(int i = 0; i < n + 1; ++i) {
		if(i == 0) {
			for(int j = 0; j < n; ++j) {
				if(v[j] != 1) ++n_change_buf;
			}
		}
		else {
			if(v[i - 1] != 0) ++n_change_buf;
			else --n_change_buf;
		}
		n_change = (n_change_buf < n_change ? n_change_buf : n_change);
	}

	std::cout << n_change << std::endl;
	
	return 0;
}


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

int main()
{
  //入力
  long int num;
  cin>>num;

  //操作と出力
  long int count=0;
  
  for(size_t i=1;i<=num;i++)
  {
    if(i%3==0)continue;
    if(i%5==0)continue;

    count+=i;
  }

  cout<< count <<endl;
  
  return 0;
}

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

int min(int a,int b){
	if(a<b)return a;
	return b;
}

int compare_char(char *a,char *b){
	return strcmp(a,b);
}

int intsort(const void *a, const void *b){
	return *(int*)b - *(int*)a;
	/*qsort(a,aの配列数,sizeof(int),intsort);*/
}

int longsort(const void *a, const void *b){
	long *A=(long *)a;
	long *B=(long *)b;
	if(*A>*B) return -1;
	if(*A<*B) return 1;
	return 0;
}

int main(){
  int i,N;
  long smid,rmid;
  cin >>N;
  vector<long> v(N),sv(N);

  for(i=0;i<N;i++){
    cin >>v[i];
    sv[i]=v[i];
  }
  sort(sv.begin(),sv.end());

  smid=sv[N/2-1];
  rmid=sv[N/2];

  for(i=0;i<N;i++){
    if(v[i]<rmid){
      cout  <<rmid <<endl;
    }else{
      cout  <<smid <<endl;
    }
  }
  return 0;
}

Measured memory_bytes: 5376
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second

const int mx=200010;
const ll mod=1e9+7;


int main(){
  int x,a,b;
  cin >> x >> a >> b;
  b -= a;
  if(b<=0){
    cout << "delicious" << endl;
  } else if(b<=x){
    cout << "safe" << endl;
  } else {
    cout << "dangerous" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>  
#include <functional>
#define ll long long int
#define ld long double
#define pb push_back
#define pll pair<ll,ll>
#define pint pair<int,int>
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define mod 1000000007
#define MAX 100005
#define endl '\n'
#define mp make_pair
#define INF INT_MAX
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
#define ff first
#define ss second
#define ps(x,y) fixed<<setprecision(y)<<x
#define setbits(x) __builtin_popcountll(x)            //counts no of ones in binary representation
#define w(t)     int t; cin>>t; while(t--)
#define pi 3.141592653589793238
#define sortt(v)  sort(v.begin(),v.end())
#define lb(v,x) std::lower_bound(v.begin(),v.end(),x)
#define ub(v,x) std::upper_bound(v.begin(),v.end(),x)

using namespace std;

int main(){
	ll n,x,t;
	cin>>n>>x>>t;
	ll ans=(n/x)*t;
	if(n%x)		ans+=t;
	cout<<ans;
}

Measured memory_bytes: 3632
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<stdexcept>
using namespace std;
int main(){
  int N; cin >> N;
  float x[N]; string u[N]; float ans=0;
  for(int i=0;i<N;i++){
    cin >> x[i] >> u[i];
  if(u[i] == "JPY") {
    ans += x[i];
  }
  if(u[i] == "BTC") {
  ans += 380000*x[i];
  }
 }
  cout << ans <<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <map>
#include <deque>

int main(){
  int a[32] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  int K;
  scanf("%d", &K);
  std::cout << a[K-1] << std::endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
import java.util.Arrays;

public class Main{
  public static void main(String[] args){
    Scanner scanner = new Scanner(System.in);
    String c = scanner.next();
    if(c.equals("a") || c.equals("e")|| c.equals("i")|| c.equals("o")|| c.equals("u")){
      System.out.println("vowel");
    }else{
      System.out.println("consonant");
    }
  }
}


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

using namespace std;
using llong = long long;
using ldbl = long double;
using lpair = pair<llong, llong>;

#define ALL(x) x.begin(), x.end()

const llong inf = 1100100100100100ll;
const llong mod = 1e9+7;

int main() {
	llong N, K;
	vector<llong> A;
	map<llong, vector<int> > pos;

	cin >> N >> K;
	A.resize(N);
	for (int i = 0; i < N; ++i) {
		cin >> A[i];
		pos[A[i]].push_back(i);
	}

	llong cnt = 1;
	int now = -1;
	while (now != 0) {
		if (now == -1)
			now = 0;

		llong num = A[now];

		auto &check = pos[num];
		auto it = upper_bound(ALL(check), now);
		if (it == check.end())
			it = check.begin();

		if (now >= *it)
			cnt++;

		now = *it;
		now = (now + 1) % N;
	}


	K %= cnt;

	cerr << now << " " << cnt << " " << K << endl;

	while (K > 0) {
		// cerr << now << endl;
		llong num = A[now];

		auto &check = pos[num];
		auto it = upper_bound(ALL(check), now);
		if (it == check.end())
			it = check.begin();

		if (now >= *it)
			K--;
		if (K == 0) break;

		now = *it;
		now = (now+1)%N;
	}

	cerr << now << endl;

	vector<llong> ans;
	set<llong> exist;
	for (int i = now; i < N; ++i) {
		if (exist.count(A[i])) {
			while (exist.count(A[i])) {
				exist.erase(ans.back());
				ans.pop_back();
			}
		} else {
			ans.push_back(A[i]);
			exist.insert(A[i]);
		}
	}

	for (auto x : ans)
		cout << x << " ";
	cout << endl;

	return 0;
}

Measured memory_bytes: 35824
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cctype>
#include <vector>
#include <numeric>
#include<string>
#include <map>
#include <chrono>
#include <cstdlib>
#include <ctime>

using namespace std;

#define ll long long
#define rep(cnt,a,n) for(ll cnt=a;cnt<n+a;cnt++) //aから始めてn回ループ
#define vector2(type,name,a,b) vector<vector<type>> name(a, vector<type>(b))
#define PI 3.141592653589793





int main() {
    ll n, d;
    cin >> n;
    cin >> d;
    vector<ll>x(n);
    vector<ll>y(n);
    rep(cnt, 0, n) {
        cin >> x.at(cnt);
        cin >> y.at(cnt);
    }
    ll ans=0;
    rep(cnt, 0, n) {
        if (x.at(cnt) * x.at(cnt) + y.at(cnt) * y.at(cnt) <= d * d) {
            ans++;
        }
    }
    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 6424
n, m = map(int, input().split())

kind_list = []
for i in range(n):
   kind_list.append(list(map(int, input().split())))

count_list = [0] * 31 
for i in range(n):
    for j in range(1, len(kind_list[i])):
        count_list[kind_list[i][j]] = count_list[kind_list[i][j]] + 1

count = 0
for i in range(len(count_list)):
    if count_list[i] == n:
        count = count + 1

print(count)


Measured memory_bytes: 3064
with Ada.Text_IO, Ada.Integer_Text_IO, Ada.Float_Text_IO;
 use Ada.Text_IO, Ada.Integer_Text_IO, Ada.Float_Text_IO;

procedure main is
   N: Integer;
   M: Integer;
begin
   get(N);
   get(M);
   if (N * 500 >= M) then put_line("Yes");
   else put_line("No");
   end if;
end main;

Measured memory_bytes: 3660
def logic(S, K):
    if len(S) == 1:
        return int(S)
    if S[0:int(K)].replace("1","") == "":
        return 1
    a = S.replace("1", "")
    if len(a) == 0:
        return 1
    return int(a[0])


if __name__ == '__main__':
    print(logic(input(), input()))


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;

#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define range(i,a,n) for(int i=(a);i<(n);i++)

#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI 3.1415926535897932384

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

template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S acm(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
void YN(bool b){cout<<(b?"YES":"NO")<<"\n";}
void Yn(bool b){cout<<(b?"Yes":"No")<<"\n";}
void yn(bool b){cout<<(b?"yes":"no")<<"\n";}
int sgn(const double&r){return (r>EPS)-(r<-EPS);} // a>0  : sgn(a)>0
int sgn(const double&a,const double&b){return sgn(a-b);} // b<=c : sgn(b,c)<=0

ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s;a=0;} return os;}
int popcnt(ll x){return __builtin_popcountll(x);}
int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n,a,b,c,ans=0;
	cin>>n;
	vvl vv(n,vl(n));
	rep(i,n){
		cin>>a;
		rep(j,a){
			cin>>b>>c;
			if(c==1)vv[i][b-1]=1;
			else vv[i][b-1]=-1;
		}
	}
	rep(i,1ll<<n){
		bool ok=true;
		rep(j,n){
			if(i&(1ll<<j)){
				rep(k,n){
					if(vv[j][k]==1&&!((1ll<<k)&i))ok=false;
					if((vv[j][k]==-1)&&((1ll<<k)&i))ok=false;
				}
			}
		}
		if(ok){
			chmax(ans,(ll)popcnt(i));
		}
	}
	puta(ans);
}


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<limits>
#include<set>
#include<queue>
using namespace std;
#define int long  long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
typedef pair<int, int>P;
const int INF = 1e15;

signed main() {
	string S;
	cin >> S;
	for (int i = S.size() / 2 - 1; i >= 0; i--) {
		string a, b;
		for (int j = 0; j < i; j++)a.push_back(S[j]);
		for (int j = 0; j < i; j++)b.push_back(S[j + i]);
		if (a == b) {
			cout << 2 * i;
			return 0;
		}
	}
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;

class Main {
  static int solve(char [] s, int minPrefix) {
    int sum = 0, maxPrefix = 0;
    TreeSet <Integer> index = new TreeSet <> ();
    for(int i = 0; i < s.length; i++) {
      if(s[i] == '1') {
        sum += 1;
      } else {
        sum -= 1;
        if(s[i] == '?') {
          index.add(i);
          s[i] = '0';
        }
      }
      while(sum < minPrefix) {
        if(index.isEmpty()) return Integer.MAX_VALUE;
        int optIndex = index.last();
        index.remove(optIndex);
        s[optIndex] = '1';
        sum += 2;
      }
    }
    sum = 0;
    for(int i = 0; i < s.length; i++) {
      if(s[i] == '1') {
        sum += 1;
      } else {
        sum -= 1;
      }
      maxPrefix = Math.max(maxPrefix, sum);
    }
    return maxPrefix - minPrefix;
  }
  public static void main(String [] args) {
    Reader in = new Reader();
    char [] s = in.next().toCharArray();
    int sum = 0;
    int start = 0;
    for(int i = 0; i < s.length; i++) {
      if(s[i] == '0') sum -= 1;
      else sum += 1;
      start = Math.min(start, sum);
    }
    System.out.println(Math.min(solve(s.clone(), start), solve(s.clone(), start - 1)));
  }
}

class Reader {
  BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
  StringTokenizer s = new StringTokenizer("");
  Reader () {}
  String nextLine() {
    try {
      return in.readLine();
    } catch (Exception e) {
      e.printStackTrace();
      return "Error";
    }
  }
  String next() {
    while(!s.hasMoreTokens()) {
      s = new StringTokenizer(nextLine());
    }
    return s.nextToken();
  }
  int nextInt() {
    return Integer.parseInt(next());
  }
}



Measured memory_bytes: 103144
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define all(aaa) aaa.begin(), aaa.end()

const int N = 1e5 + 5;
int a[N];

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

    int n;
    cin >> n;

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

    sort(a, a + n);

    int ans = a[n - 1] - a[0];

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

    cout << ans << "\n";

    int anime = a[0];

    for (int i = 1; i + 1 < n; i++) {
        if (a[i] > 0) {
            cout << anime << " " << a[i] << "\n";
            anime -= a[i];
        }
    }

    cout << a[n - 1] << " " << anime << "\n";

    anime = a[n - 1] - anime;

    for (int i = 1; i + 1 < n; i++) {
        if (a[i] <= 0) {
            cout << anime << " " << a[i] << "\n";
            anime -= a[i];
        }
    }

    return 0;
}

Measured memory_bytes: 2304
use proconio::input;
use std::collections::BinaryHeap;
use std::cmp::Reverse;

fn main() {
  input! {
    n: usize,
    m: usize,
    values: [usize;n],
    mut changes: [(usize, usize);m]
  }  
  changes.sort_by(|a,b| a.1.cmp(&b.1));
  changes.reverse();
  
  let mut p_queue = BinaryHeap::new();
  for v in values {
    p_queue.push(Reverse(v));
  }
  
  let mut last_val = usize::max_value();
  for (i, v) in changes {
    for ii in 0..i {
      let val = p_queue.pop().unwrap();
      if v <= val.0 {
        p_queue.push(val);
        break;
      }
      p_queue.push(Reverse(v));
    }

    last_val = v;
  }
  
  println!("{}", p_queue.iter().map(|v| v.0).sum::<usize>());
}

Measured memory_bytes: 8092
#include<bits/stdc++.h>
using namespace std;
template<class T> void chmax(T& x, T y){if(x < y) x = y;}
template<class T> void chmin(T& x, T y){if(x > y) x = y;}
int N, M;
int A[310][310];
int cnt[310];
bool hold[310];
int idx[310];

int solve(){
    bool flag = false;
    for(int i = 1; i <= M; i++){
        if(hold[i]) flag = true;
    }
    if(!flag) return 1 << 30;

    for(int i = 1; i <= N; i++){
        if(hold[A[i][idx[i]]]) continue;
        for(int& j = idx[i]; j <= M; j++){
            if(hold[A[i][j]]){
                cnt[A[i][j]]++;
                break;
            }
        }
    }

    int mx = 0;
    for(int i = 1; i <= M; i++){
        chmax(mx, cnt[i]);
    }
    set<int> h;
    for(int i = 1; i <= M; i++){
        if(cnt[i] == mx){
            h.insert(i);
            hold[i] = false;
            cnt[i] = 0;
        }
    }
    return min(solve(), mx);
}


int main(){
    cin >> N >> M;
    for(int i = 1; i <= N; i++){
        for(int j = 1; j <= M; j++){
            cin >> A[i][j];
        }
    }
    for(int i = 1; i <= M; i++){
        hold[i] = true;
    }
    cout << solve() << endl;
    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <unordered_map>
#include <deque>
#include <list>
#include <set>
#include <random>
#include <deque>

using namespace std;
using ll = long long;
const int BIG = 100000007;


int main() {
    ll n;
    cin >> n;
    vector<ll> mem(10001,0);
    for(ll x = 1;x <= 100;++x){
        for(ll y = 1;y <= 100;++y){
            for(ll z = 1;z <= 100;++z){
                ll n = (x * x) + (y * y) + (z * z) + (x * y) + (x * z) + (y * z);
                if(n <= 10000)++mem[n];
            }
        }
    }

    for(ll i = 1;i <= n;++i){
        cout << mem[i] << endl;
    }

}




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

using namespace std;
using namespace std::chrono;

#define rep(i,a,b) for(int i = a;i<(b);++i)
#define trav(a,v) for(auto& a : v)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> vi;

ll big = 1000000007ll;
ll big2 = 1000000009ll;
ll n,m,T,k,q,p,w,h;

int main()
{
   // freopen("input.txt","r",stdin);
    //freopen("autput.txt","w",stdout);
    ll a,b,c,d,e;

    cin >> n;
    vector<ll> A;
    ll F[100001] = {0};
    for(ll c1 = 0; c1 < n; c1++){
        cin >> a;
        F[a]++;
    }
    ll ans = 0;
    for(ll c1 = 0; c1 <= 100000; c1++){

        a = 0;
        b = 0;
        c = 0;
        if(c1 > 0)a += F[c1-1];
        b += F[c1];
        if(c1 < 100000)c += F[c1+1];
        ans = max(ans,a+b+c);

    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ll n; cin>>n;
    if(n>=400&&n<=599)
        cout<<8<<endl;
    else if(n>=600&&n<=799)
        cout<<7<<endl;
    else if(n>=800&&n<=999)
        cout<<6<<endl;
    else if(n>=1000&&n<=1199)
        cout<<5<<endl;
    else if(n>=1200&&n<=1399)
        cout<<4<<endl;
    else if(n>=1400&&n<=1599)
        cout<<3<<endl;
    else if(n>=1600&&n<=1799)
        cout<<2<<endl;
    else 
        cout<<1<<endl;
    return 0;
}


Measured memory_bytes: 3564
#include <bits/stdc++.h>
using namespace std;
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; }

int n;
vector<int> pcnt(110, 0);

int main() {
    cin >> n;
    pcnt.at(1) = 1;
    for(int i = 2; i <= n; ++i) {
        int check = i;
        for(int j = 2; j <= n; ++j) {
            while(check % j == 0) {
                pcnt.at(j)++;
                check /= j; 
            }
        }
    }

    int ans = 0;
    // x^2 * y^24
    int cnt2 = 0; int cnt24 = 0;
    for(int i = 0; i <= n; ++i) {
        if(pcnt.at(i) >= 24) cnt24++;
        if(pcnt.at(i) >= 2) cnt2++;
    }
    int fircnt = cnt24 * max(0, (cnt2-cnt24)) + cnt24 * max(0, (cnt24 - 1));

    // x^4 * y^14
    int cnt4 = 0; int cnt14 = 0;
    for(int i = 0; i <= n; ++i) {
        if(pcnt.at(i) >= 14) cnt14++;
        if(pcnt.at(i) >= 4) cnt4++;
    }
    int scdcnt = cnt14 * max(0, (cnt4-cnt14)) + cnt14 * max(0, (cnt14 - 1));

    // x^2 * y^4 * z^4
    int cntl2 = 0; int cntl4 = 0;
    for(int i = 0; i <= n; ++i) {
        if(pcnt.at(i) >= 4) cntl4++;
        if(pcnt.at(i) >= 2) cntl2++;
    }
    int thdcnt = max(0, (cntl2-cntl4)) * cntl4 * max(0, (cntl4 - 1)) / 2;
    if(cntl4 >= 3) thdcnt += cntl4 * ((cntl4 - 1) * (cntl4 - 2) / 2);

    // y^75
    int cnt74 = 0;
    for(int i = 0; i <= n; ++i) if(pcnt.at(i) >= 74) cnt74++;

    ans = fircnt + scdcnt + thdcnt + cnt74;
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<tuple>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define Per(i,sta,n) for(int i=n-1;i>=sta;i--)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};

int n,q;
int v[300000],w[300000];
vector<P> bag[1200];

void rec(int s){
  if(s==0){
    bag[0]={P(0,0),P(w[0],v[0])};
    return;
  }
  for(P p:bag[(s-1)/2]){
    bag[s].push_back(p);
    bag[s].push_back(P(p.first+w[s],p.second+v[s]));
  }
  sort(bag[s].begin(),bag[s].end());
}

void solve(){
  cin >> n;
  rep(i,n){
    cin >> v[i] >> w[i];
  }
  int k=0;
  while(k*k<n){
      k++;
  }
  rep(i,k) rec(i);
  cin >> q;
  rep(_,q){
    int s,L;cin >> s >> L;s--;
    vector<P> f={P(0,0)};
    int m=1;
    while(s>=k){
      rep(j,m){
        f.push_back(P(w[s]+f[j].first,v[s]+f[j].second));
      }
      s=(s-1)/2;
      m*=2;
    }
    f.push_back(P(-mod,-mod));
    sort(f.begin(),f.end());
    int max_v=-mod;
    rep(j,f.size()){
      max_v=max(f[j].second,max_v);
      f[j].second=max_v;
    }
    int id=f.size()-1;
    int ans=0;
    for(P p:bag[s]){
      while(p.first+f[id].first>L){
        id--;
      }
      ans=max(ans,p.second+f[id].second);
    }
    cout << ans << endl;
  }
}

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


Measured memory_bytes: 6908
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <map>
#include <set>

using namespace std;

long long ans, n, m;
pair<int, int> ab[500000];

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> m;
    for (int i = 0; i < n; i++)
    {
        cin >> ab[i].first >> ab[i].second;
    }
    sort(ab, ab + n);
    multiset<int> x;
    int day = 1;
    for (int i = 0; i < n || day <= m;)
    {
        while (i < n && ab[i].first <= day)
        {
            x.insert(ab[i].second);
            i++;
        }
        if (x.size())
        {
            auto it = x.end();
            it--;
            ans = (ans + *it);
            x.erase(it);
        }
        day++;
        if (day == m + 1)
        {
            cout << ans;
            return 0;
        }
    }
    cout << ans;
}


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

int mod = 1e9 + 7;

int main(){
    long long N;
    std::cin >> N;
    
    long long num_not = 8;
    long long num0 = 1;
    long long num9 = 1;
    long long num09 = 0;
    
    for(int i=1; i<N; i++){
        num09 = ( num09 * 10 + num0 + num9 ) % mod;
        num0 = (num0 * 9 + num_not) % mod;
        num9 = (num9 * 9 + num_not) % mod;
        num_not = (num_not * 8) % mod;
    }
    
    
    std::cout << num09 << std::endl;
    
    return 0;
}



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

using namespace std;

map<string, int> mp;
int main() {
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++) {
        string s;
        cin >> s;
        mp[s]++;
    }
    cout << "AC x " << mp["AC"] << endl;
    cout << "WA x " << mp["WA"] << endl;
    cout << "TLE x " << mp["TLE"] << endl;
    cout << "RE x " << mp["RE"] << endl;

    return 0;
}

Measured memory_bytes: 3616
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		solve();
	}

	public static void solve() {
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
		int r = sc.nextInt();
        int g = sc.nextInt();
        sc.close();
		
        out.println(2*g-r);
        out.flush();
	}
}

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

char field[22][22];
int count;
void init()
{
	for(int i=0;i<22;i++){
		for(int j=0;j<22;j++){
			field[i][j] = '#';
		}
	}
	count = 0;
}

void DFS(int x,int y)
{
	count++;
	field[y][x] = '#';
	if(field[y][x+1] == '.')
		DFS(x+1,y);
	if(field[y+1][x] == '.')
		DFS(x,y+1);
	if(field[y][x-1] == '.')
		DFS(x-1,y);
	if(field[y-1][x] == '.')
		DFS(x,y-1);
}
int main()
{
	int w,h;
	while(cin >> w >> h){
		if(!w && !h){
			break;
		}
		init();
		int x,y;
		for(int i=0;i<h;i++){
			for(int j=0;j<w;j++){
				cin >> field[i+1][j+1];
				if(field[i+1][j+1] == '@'){
					x = j+1;y = i+1;
				}
			}
		}
		DFS(x,y);
		cout << count << endl;
	}
	return 0;
}

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

int main() {
  int N; cin >> N;
  int C[N-1], S[N-1], F[N-1];
  for (int i = 0; i < N-1; i++) cin >> C[i] >> S[i] >> F[i];
  for (int i = 0; i < N; i++) {
    int t = 0;
    for (int j = i; j < N-1; j++) {
      t = max(t, S[j]);
      t = ((t-1)/F[j] + 1) * F[j];
      t += C[j];
    }
    cout << t << endl;
  }
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
int main()
{
    char a[1000];
    scanf("%s",a);
    int s=0,n,i;
    n=strlen(a);
  
    for(i=0;i<n/2;i++)
    {
    	if(a[i]!=a[n-1-i])
    	    s++;
	}
	printf("%d",s);
} 

Measured memory_bytes: 256
def solve():
    N, M = map(int, input().split())
    FROM_1 = set()
    TO_N = set()
    for i in range(M):
        a, b = map(int, input().split())
        if a == 1:
            FROM_1.add(b)
        elif a == N:
            TO_N.add(b)
        if b == 1:
            FROM_1.add(a)
        elif b == N:
            TO_N.add(a)
    ans = FROM_1 & TO_N
    print('POSSIBLE') if ans else print('IMPOSSIBLE')

if __name__ == '__main__':
    solve()


Measured memory_bytes: 59096
#include <bits/stdc++.h>
#define rep(i,n) for(ll i = 0; i < (ll)(n); ++i)
#define MOD 1000000007

using namespace std;
using ll = long long;

int main() {
	int n;
	ll ans = 0;
	cin >> n;
	vector<int> a(n);
	rep(i, n) cin >> a[i];
	map<int, int> m;
	rep(i, n) {
		int low = i + a[i];
		int high = i - a[i];
		ans += m[high];
		m[low]++;
	}
	cout << ans << endl;
	return 0;
}
// (x > y) x - a[x] = y + a[y]
// x[1] = 4, x[7] = 2, x[8] = 3
// x[7] = 2; x[11] = 2


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

using namespace std;

//#define _FILES
#define PB push_back
#define MP make_pair
#define X first
#define Y second

long long solve(long long n, long long x)
{
    if (((n % 2) == 0) && (x == n/2))
    {
        return 3 * (n / 2);
    }

    if (x <= n / 2)
    {
        return  3 * x + solve(n - x, n - 2 * x);
    }

    long long ans = x + 2 * (x / (n - x)) * (n - x);
    long long ost = x % (n - x);

    if (!ost)
    {
        return ans;
    }

    ans += solve(ost + n - x, ost) - ost;
    return ans;
}

int main()
{
    ios_base::sync_with_stdio(false);

    #ifdef _FILES
        freopen("","r",stdin);
        freopen("","w",stdout);
    #endif // _FILES
    long long n, x;
    cin >> n >> x;
    cout << solve(n , x) << endl;
    return 0;
}



Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define num 100000

int main() {
    int n, m;
    cin >> n >> m;
    bitset<num> a;
    REP(i, m) {
        int L, R;
        cin >> L >> R;
        bitset<num> b;
        b.flip();
        b = (b >> L - 1) ^ (b >> R);
        if(i == 0)a = b;
        else a = a & b;
    }
    cout << a.count() << endl;
}


Measured memory_bytes: 384