akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#define MAX 100000

struct Node{
  int p,l,r;
};

struct Node T[MAX];
int dp[MAX],f[MAX];

void SetDe(int x,int c){
  if(x==-1)return;
  dp[x]=c;                                                        
  SetDe(T[x].r,c+1);
  SetDe(T[x].l,c+1);
}

int SetHei(int x){
  int k1=0,k2=0;
  if(T[x].l!=-1)k1=SetHei(T[x].l)+1;
  if(T[x].r!=-1)k2=SetHei(T[x].r)+1;
  if(k1>k2)return f[x]=k1;
  else return f[x]=k2;
}

int GetSibling(int x){
  if(T[x].p==-1)return -1;
  if(T[T[x].p].l!=x && T[T[x].p].l!=-1)return T[T[x].p].l;
  if(T[T[x].p].r!=x && T[T[x].p].r!=-1)return T[T[x].p].r;
  return -1;
}

int main(){

  int i,n,id;
  int le,ri,root,deg;
  
  scanf("%d",&n);
  for(i=0;i<n;i++)T[i].p=-1;

  for(i=0;i<n;i++){
    scanf("%d",&id);
    scanf("%d",&le);
    scanf("%d",&ri);
    T[id].l=le;
    T[id].r=ri;
    if(le!=-1)T[le].p=id;
    if(ri!=-1)T[ri].p=id;
  }
  for(i=0;i<n;i++){
    if(T[i].p==-1)root=i;
  }
  
  SetDe(root,0);
  SetHei(root);

  for(i=0;i<n;i++){
    deg=0;
    printf("node %d: ",i);
    printf("parent = %d, ",T[i].p);
    printf("sibling = %d, ",GetSibling(i));
    if(T[i].l!=-1) deg++;
    if(T[i].r!=-1) deg++;
    printf("degree = %d, ",deg);
    printf("depth = %d, ",dp[i]);
    printf("height = %d, ",f[i]);

    if(T[i].p==-1)printf("root\n");
    else if(T[i].l==-1 && T[i].r==-1)printf("leaf\n");
    else printf("internal node\n");
				       
    }
  return 0;
}



Measured memory_bytes: 2104
//Jacker0031
        //packages
        #if __has_include("C:/Sublime Text 3/debug.h")
            #include "C:/Sublime Text 3/debug.h"
        #else
            #include <bits/stdc++.h>
            using namespace std;
            #define d(...) 11
            #define cerr if(0) cerr
        #endif
        #define FAST ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);

            
        #define ll long long 
        #define ld long double
            
        #define all(a)      (a).begin(),(a).end()
        #define sz(x)       (int)x.size()
            
        #define ff first
        #define ss second
        #define mp make_pair
                 
        #define pb push_back
        #define endl "\n" 
                 
        #define loop(i,l,r) for(ll i=l;i<r;i++)
        #define rf(i,r,l) for(ll i=r;i>=l;i--)    
         
        #define bp __builtin_popcountll
        #define inf LLONG_MAX
            
        const int N=2e5+5; 
        const int M=1e9+7;
        ////////////

        //NOW CODE BEGIN.
        //DHARMSINH DESAI UNIVERSITY.
        #include <ext/pb_ds/assoc_container.hpp> 
        #include <ext/pb_ds/tree_policy.hpp> 
        using namespace __gnu_pbds; 
        #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 

        #define ar array
        int main()
        {
            ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
            #ifdef Jenish
            freopen("C:/Sublime Text 3/in.txt","r",stdin);
            freopen("C:/Sublime Text 3/out.txt","w",stdout);
            #endif
            ll n;
            cin>>n;
            ll a[n];
            loop(i,0,n)
            cin>>a[i];
            ll sum=0;
            ll ma=0;
            for(int i=0;i<n;i++)
            {
               ma=max(a[i],ma);
               if(a[i]<ma)
                sum+=(ma-a[i]);

            }
            cout<<sum<<endl;
           



        }       

Measured memory_bytes: 5176
N,Ma,Mb = map(int,input().split())
Data = []
for _ in range(N):
    a,b,c = map(int,input().split())
    Data.append([a,b,c])

DP = []
for _ in range(N+1):
    temp = [[-1]*(N*10+1) for _ in range(N*10+1)]
    DP.append(temp)
DP[0][0][0] = 0

for i in range(1,N+1):
    A,B,C = Data[i-1]
    for a in range(0,N*10+1):
        for b in range(0,N*10+1):
            if DP[i-1][a][b] != -1:
                # 使わない
                if DP[i][a][b] == -1:
                    DP[i][a][b] = DP[i-1][a][b]
                else:
                    DP[i][a][b] = min(DP[i][a][b],DP[i-1][a][b])

                #使う
                if DP[i][a+A][b+B] == -1:
                    DP[i][a+A][b+B] = DP[i-1][a][b]+C
                else:
                    DP[i][a+A][b+B] = min(DP[i][a+A][b+B],DP[i-1][a][b]+C)
ans = -1
for a in range(1,N*10+1):
    for b in range(1,N*10+1):
        if DP[N][a][b] != -1 and a * Mb == b * Ma:
            if ans == -1:
                ans = DP[N][a][b]
            else:
                ans = min(ans,DP[N][a][b])
print(ans)

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

int main()
{
	string s;
	cin>>s;
	int n=s.length();
	int f=1;
	for(int i=1;i<=n;i++)
	{
		if(i%2!=0)
		{
			if(s[i-1]=='L')
			{
				f=0;break;
			}
		}
		else{
			if(s[i-1]=='R')
			{
				f=0;break;
			}
		}
	}
	if(f==0) cout<<"No";
	else cout<<"Yes";
	
	
	
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<n;i++)
#define loop(i,a,n) for(i=a;i<n;i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef pair<int,int> pii;

int main(void) {
  int i,j;
  string s;
  cin>>s;
  rep(i,s.size())
    if(s[i]=='A')break;
  for(j=s.size()-1;j>=0;j--)
    if(s[j]=='Z')break;
  cout<<j-i+1<<endl;
}


Measured memory_bytes: 640
import sys
from collections import deque
from collections import defaultdict
import math
sys.setrecursionlimit(20000000)
input = sys.stdin.readline
n,m = map(int,input().split())
a = list(map(int,input().split()))
d = defaultdict(int)
for i in range(n):
    d[a[i]] += 1
for i in range(m):
    b,c = map(int,input().split())
    d[c] += b
x = list(d.keys())
x.sort(key=lambda x:-x)
ans = 0
k = 0
for i in x:
    if k+ d[i] >= n:
        ans += (n-k)*i
        break
    else:
        k+= d[i]
        ans += d[i]*i
print(ans)

Measured memory_bytes: 94360
N = int(input())
tasks = []

for i in range(N):
    A, B = map(int, input().split())
    tasks.append((B, A))

tasks.sort()

ans = "Yes"
time = 0
for task in tasks:
    time += task[1]
    if time > task[0]:
        ans = "No"

print(ans)

Measured memory_bytes: 29388
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long

#define pi acos(-1.0)
#define mod 100000007

#define p_b push_back
#define m_p make_pair

#define fastio ios_base:: sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define FI freopen("input.txt", "r", stdin);
#define FO freopen("output.txt", "w", stdout);

#define MAX 10000000
#define all(x) x.begin(), x.end()
using namespace std;

struct Node
{
	ll val, pos;
};

vector<ll> v;
map<string, int> mp;

/*void pow(){
	v.clear();
	v.p_b(0);
	for(ll i=0; ; i++){
		ll value = pow(2, i);
		v.p_b(value);
		if(value >= 1000000000) break;
	}
}*/

/*void sieve(){
	ll arr[MAX];
	memset(arr, 0, sizeof(arr));
	prime.clear();
	prime.p_b(2);
	for(ll i=3; i*i <=MAX; i+=2){
		if(arr[i] == 0){
			for(ll j=i*i; j<=MAX; j+= i){
				arr[j] = 1;
			}
		}
	}
	for(ll i=3; i<=MAX; i+=2){
		if(arr[i] == 0) prime.p_b(i);
	}
}*/



bool pal_check(string s){

	string rs = s;
	reverse(all(rs));

	return rs == s;
}
// Driver function to sort the vector elements by  
// first element of pair in descending order 

bool sortinrev (const pair<int, string> &a, const pair<int, string> &b){
	return a.first > b.first;
}

int main (){
	//FI;
	//sieve();	
	int n;
	cin>>n;
	std::vector<string> s_vec;
	set<string> s_set, set2;
	unordered_multiset<string> s_mulset;

	for(int i=0; i<n; i++){
		string input;
		cin>>input;

		s_vec.push_back(input);
		s_set.insert(input);
		s_mulset.insert(input);
	}

	vector< pair< int, string> > p;
	int maxi = 0;
	for(int i=0; i<n; i++){
		if(s_set.count(s_vec[i])){
			int cnt = s_mulset.count(s_vec[i]);
			if(maxi < cnt) maxi = cnt;

			p.p_b(m_p(cnt, s_vec[i]));
			s_set.erase(s_vec[i]);
		}
		if(s_set.empty()) break;
	}

	sort(all(p), sortinrev);

	int p_size = p.size();

	std::vector<string> copy;
	//cout<<p[p_size-1].first<<" "<<p[p_size-1].second<<endl;
	for(int i =0 ;i<p_size ;i++ ){
		if(p[i].first >= maxi){
			//cout<<p[i].second<<endl;
			set2.insert(p[i].second);
		}
		//cout<<p[i].second<<endl;
		//copy.p_b(p[i].second);

	}
	for(auto it = set2.begin(); it != set2.end(); it++){
		cout<<*it<<endl;
	}
	/*sort(all(copy));
	for(int i=0; i<copy.size(); i++) cout<<copy[i]<<endl;*/


	return 0;
	
}

Measured memory_bytes: 36408
#include <iostream>
#include <vector>
#include <queue>
using namespace std;

#define PrintLn(X) cout << X << endl
#define Rep(i, n) for(int i = 0; i < (int)(n); ++i)

int N, M;
int a[50];
int b[50];
vector<int> vs[100];

int main(void)
{
	cin >> N >> M;

	Rep(i, M){
		cin >> a[i] >> b[i];
		a[i]--;
		b[i]--;
		vs[a[i]].push_back(b[i]);
		vs[b[i]].push_back(a[i]);
	}

	int ans = 0;
	Rep(i, M){
		int A = a[i];
		int B = b[i];
		int nums[50] = {0};

		queue<int> q;
		nums[A] = 1;
		for(auto &x: vs[A]){
			if(x != B){
				q.push(x);
				nums[x] = 2;
			}
		}
		while(!q.empty()){
			int X = q.front();
			int num = nums[X];
			q.pop();
			for(auto &x: vs[X]){
				if(x == B) goto F;
				if(nums[x] == 0){
					q.push(x);
					nums[x] = num + 1;
				}
			}
		}
		ans++;
F:;
	}

	PrintLn(ans);
	return 0;
}


Measured memory_bytes: 256
import sys
import math
import itertools
import collections
import heapq
import re
import numpy as np
from functools import reduce

rr = lambda: sys.stdin.readline().rstrip()
rs = lambda: sys.stdin.readline().split()
ri = lambda: int(sys.stdin.readline())
rm = lambda: map(int, sys.stdin.readline().split())
rl = lambda: list(map(int, sys.stdin.readline().split()))
inf = float('inf')
mod = 10**9 + 7

n, m = rm()
if n == m:
    print((math.factorial(n) * math.factorial(m) * 2) % mod)
elif abs(n-m) == 1:
    print((math.factorial(n) * math.factorial(m)) % mod)
else:
    print(0)




















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

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

    for (int i = 0; i < str.size(); i++) {
        // 偶数か奇数かの判定
        if ((i + 1) % 2 == 0) {
            // 偶数の場合の判定
            if (str[i] == 'R') {
                cout << "No" << endl;
                return 0;
            }
        } else {
            // 奇数の場合の判定
            if (str[i] == 'L') {
                cout << "No" << endl;
                return 0;
            }
        }
    }

    cout << "Yes" << endl;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
	"reflect"
)

func main() {
	d1 := make([]int, 7)
	d2 := make([]int, 7)
	for i := 1; i <= 6; i++ {
		var x int
		fmt.Scan(&x)
		d1[i] = x
	}
	for i := 1; i <= 6; i++ {
		var x int
		fmt.Scan(&x)
		d2[i] = x
	}

	/*
	   1: 2, 3, 5, 4
	   2: 6, 3, 1, 4
	   3: 2, 6, 5, 1
	*/
	r := [][]int{
		{},
		{2, 3, 5, 4},
		{6, 3, 1, 4},
		{2, 6, 5, 1},
	}
	rightFace := func(tp, fr int) int {
		n := 1
		if tp > 3 {
			tp = 7 - tp
			n = 3
		}
		for k := 0; k < 4; k++ {
			if r[tp][k] == fr {
				k += n
				k %= 4
				return r[tp][k]
			}
		}
		return 0
	}

	for i := 1; i <= 6; i++ {
		for j := 1; j <= 6; j++ {
			k := rightFace(i, j)
			if k == 0 {
				continue
			}
			a := []int{d1[i], d1[j], d1[k], d1[7-k], d1[7-j], d1[7-i]}
			if reflect.DeepEqual(a, d2[1:]) {
				fmt.Println("Yes")
				return
			}
		}
	}
	fmt.Println("No")
}



Measured memory_bytes: 1204
sx, sy, tx, ty = map(int, input().split())

x = tx - sx
y = ty - sy

ans = "R" * x + "U" * y + "L" * x
ans += "D" * (y + 1) + "R" * (x + 1) + "U" * (y + 1) + "L" + "U"
ans += "L" * (x + 1) + "D" * (y + 1) + "R"

print(ans)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  int f1=0,f2=0;
  int a[4],cnt=0;
  while(n){
    a[cnt++]=n%10;
    n/=10;
  }
  if(a[1]==a[2])f1=1;
  if(a[0]==a[1])f2=1;
  if(a[2]==a[3])f2=1;
  if(f1&&f2)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
 
 
 
int main(){
    ios::sync_with_stdio(false);
	cin.tie(0);
 
    ll n;
    cin>>n;
    ll a[3],b[3];
    for(int i=0;i<3;i++){
        cin>>a[i];
    }
    for(int i=0;i<3;i++){
        cin>>b[i];
    }
    ll ans = n;
    
    
    for (long long bit = 0; bit < (1LL<<3); ++bit){
        int cnt = 0;
        for(int i=0;i<3;i++){
            if((bit>>i&1LL)){
                cnt++;
            }
        }
        if(cnt==3){
            for(int i=0;i*a[0]<=n;i++){
                for(int j=0;i*a[0]+j*a[1]<=n;j++){
                    ll ret = 0;
                    int k = (n-i*a[0]-j*a[1])/a[2];
                    ret += i*b[0] + j*b[1] + k*b[2] + n - (k*a[2]+i*a[0]+j*a[1]);
                    ans = max(ret,ans);
                }
            }
        }
        else if(cnt==2){
            int k=0,l=0,s;
            for(int i=0;i<3;i++){
                if((bit>>i&1LL)){
                    l=k,k=i;
                }
                else s=i;
            }
            for(int i=0;i*a[k]<=n;i++){
                ll ret = i*b[k] + (n-i*a[k])/a[l]*b[l] + n-(i*a[k] + (n-i*a[k])/a[l]*a[l]);
                ll t=ret/b[s];
                ret = t*a[s] + (ret - t*b[s]);
                ans = max(ret,ans);
            }
        }
        else if(cnt==1){
            int k,l,s;
            for(int i=0;i<3;i++){
                if((bit>>i&1LL)){
                    s=i;
                }
                else l=k,k=i;
            }
            ll ret = n-n/a[s]*a[s] + n/a[s]*b[s];
            for(int i=0;i*b[k]<=ret;i++){
                ll res = i*a[k] + (ret-i*b[k])/b[l]*a[l] + ret - (i*b[k] + (ret-i*b[k])/b[l]*b[l]);
                ans = max(res,ans);
            }
            
        }
        else {
            for(int i=0;i*b[0]<=n;i++){
                for(int j=0;i*b[0]+j*b[1]<=n;j++){
                    ll ret = 0;
                    int k = (n-i*b[0]-j*b[1])/b[2];
                    ret += i*a[0] + j*a[1] + k*a[2] + n - (k*b[2]+i*b[0]+j*b[1]);
                    ans = max(ret,ans);
                }
            }
        }
    }
 
    cout << ans << endl;
 
 
 
    
}

Measured memory_bytes: 384
#include <ext/pb_ds/assoc_container.hpp> 	// Common file
#include <ext/pb_ds/tree_policy.hpp> 		// Including tree_order_statistics_node_update
#include<bits/stdc++.h>
#define int            		long long
#define x              		first
#define y              		second
#define all(aaa)       		(aaa).begin(),(aaa).end()
#define REP(i,sss,eee) 		for(int i=sss;i<=eee;++i)
#define pb             		push_back
#define pii            		pair<int,int>
#define vi             		vector<int>
#define speed          		ios_base::sync_with_stdio(0);cin.tie(0);
#define N              		1000000007
using namespace __gnu_pbds;
using namespace std;
template <class T>
T MAX(T a, T b){return ((a>b)?a:b);}
template <class T>
T MIN(T a, T b){return ((a<b)?a:b);}
template <class T>
T MOD(T a){return ((a>=0)?a:(-1*a));}
template <class T>
void SWAP(T &a,T &b){T temp=a;a=b;b=temp;}

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

long long ex(long long a, long long b){
	if(b==0||a==1){return 1;}
	if(a==0||b==1){return a;}
	long long tmp=ex(a,(b/2));
	if(b%2){return ((((tmp*tmp)%N)*a)%N);}
	else{return ((tmp*tmp)%N);}
}
long long inv(long long k){
	if(k==1){return 1;}
	else{return ex(k,N-2);}
}
/*****************default********************/
vi inp;
vi dp;
int val(int bit,int b)
{
	int pp=__builtin_popcount(bit);
	return (MOD(dp[bit]-b)+((pp-1)*10));
}
int calc(int num)
{
	int ans=0;
	int ct=0;
	while(num)
	{
		if(num&1){
			ans+=inp[ct];
		}
		num>>=1;
		++ct;
	}
	return ans;
}
int solve()
{
	int n;cin>>n;
	int a,b,c;cin>>a>>b>>c;
	inp.resize(n);
	REP(i,0,n-1){cin>>inp[i];}
	int lim=((1<<n));
	dp.resize(lim);
	REP(i,1,lim-1){dp[i]=calc(i);}


	std::vector<int> v;
	int ans=10000000000000000;
	REP(i,1,lim-1)
	{
		REP(j,1,lim-1)
		{
			REP(k,1,lim-1)
			{
				if((!(i&j))&&(!(i&k))&&(!(j&k)))
				{
					int tans=(val(i,a)+val(j,b)+val(k,c));
					ans=MIN(ans,tans);
				}
			}
		}
	}
	cout<<ans<<"\n";
}
signed main(){
	speed
	int tt=1;
	//cin>>tt;
	while(tt--)
	{
		solve();
	}
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

void ReadInput(int *inputA, int *inputB, int *inputC, int *inputK)
{
    scanf("%d %d %d %d", inputA, inputB, inputC, inputK);
}

void CountA(int * inputA, int * inputK , int * outputVal)
{
    while(1)
    {
        if(*inputA == 0)
        {
            break;
        }
        else if (*inputK == 0)
        {
            break;
        }
        *inputA = *inputA - 1;
        *inputK = *inputK - 1;
        *outputVal = *outputVal + 1;
    }
}

void CountB(int *inputB, int * inputK, int *outputVal)
{
    while(1)
    {
        if(*inputB == 0)
        {
            break;
        }
        else if (*inputK == 0)
        {
            break;
        }
        
        *inputB = *inputB - 1;
        *inputK = *inputK - 1;
        *outputVal = *outputVal + 0;
    }
}

void CountC(int *inputC, int * inputK, int *outputVal)
{
    while(1)
    {
        if(*inputC == 0)
        {
            break;
        }
        else if (*inputK == 0)
        {
            break;
        }
        *inputC = *inputC - 1;
        *inputK = *inputK - 1;
        *outputVal = *outputVal + (-1);
    }
}
void FreeMemory(int *inputA, int *inputB,int *inputC, int * inputK)
{
    free(inputA);
    free(inputB);
    free(inputC);
    free(inputK);
}

int main(int argc, const char * argv[])
{
    int * inputA = malloc(100*sizeof(int));
    int *inputB = malloc(100*sizeof(int));
    int *inputC = malloc(100*sizeof(int));
    int *inputK = malloc(100*sizeof(int));
    int outputVal = 0;
    int * outputValP = &outputVal;
    
    ReadInput(inputA, inputB, inputC, inputK);
    CountA(inputA,inputK, outputValP);
    CountB(inputB,inputK, outputValP);
    CountC(inputC,inputK, outputValP);
    FreeMemory(inputA, inputB, inputC, inputK);
    
    printf("%d \n",outputVal);
    
    return 0;
}


Measured memory_bytes: 1728
#include <bits/stdc++.h>
using namespace std;
#define int         long long
#define MOD         1000000007
#define pb          push_back
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define endl        '\n'
#define PI          3.14159265359d
#define sz(x)       (int)x.size()
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define magic        109
#define INF         INT_MAX
using namespace std;
const int maxn = 200000;

int n;
int a[maxn], b[maxn];
priority_queue<int> pq;
void check_insert(int i)
{
    int i_prev = (i+n-1)%n, i_next = (i+1)%n;
    
    if(b[i]-a[i]>=b[i_prev]+b[i_next])
    {
        pq.push(i);
    }
}


void solve(){
    cin>>n;
    rep(i,0,n)cin>>a[i];    rep(i,0,n)cin>>b[i];
    int res  = 0;
    rep(i,0,n)
    {
        check_insert(i);
    }
    
    while(!pq.empty())
    {
        int i = pq.top();
        pq.pop();
         int i_prev = (i+n-1)%n, i_next = (i+1)%n;
         int k = (b[i]-a[i])/(b[i_prev] + b[i_next]);
         b[i] -= k*(b[i_prev] + b[i_next]);
         res+=k;
         check_insert(i_prev);
         check_insert(i);
         check_insert(i_next);
    }
    rep(i,0, n)
    if(a[i]!=b[i])
    {
        cout<<-1;return;
    }
    cout<<res;





}

signed main(){
    
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    
    int t=1;
    //cin>>t;

    while(t--)
        solve();
    
    return 0;
}

Measured memory_bytes: 4600
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
using namespace std;

int main(){
  vector<pair<int , pair<int,int> > > vppa;
  pair<int,int> pa;
  pair<int,pair<int,int> > ppa;
  int m,t,p,r,mm,tt,pp,jj,seikai[60],h[60][20];
  while(1){
    cin>>m>>t>>p>>r;
    if(m==0)break;
    for(int i=0;i<=t;i++){
      for(int j=0;j<=p;j++){
	h[i][j]=0;
      }
    }
    for(int i=0;i<=t;i++)seikai[i]=0;
    
    for(int i=0;i<r;i++){
      cin>>mm>>tt>>pp>>jj;
      if(jj!=0)h[tt][pp]--;
      else {
	h[tt][pp]=(h[tt][pp]*-1)*20+mm;
	seikai[tt]++;
      }
    }
    /* for(int i=0;i<=t;i++){////////////
      for(int j=0;j<=p;j++){
	cout<<h[i][j]<<" ";
      }
      cout<<endl;
      }*/

    vppa.clear();
    for(int i=1;i<=t;i++){
      pa.second=i*-1;
      pa.first=0;
      for(int j=1;j<=p;j++){
	if(h[i][j]>0) {
	  pa.first+=h[i][j];
	}
      }
      ppa.second=pa;
      ppa.first=seikai[i]*-1;
      vppa.push_back(ppa);
    }

    sort(vppa.begin() , vppa.end());

    for(int i=0;i<vppa.size()-1;i++){
      cout<<vppa[i].second.second*-1;
      if(vppa[i].first==vppa[i+1].first && vppa[i].second.first==vppa[i+1].second.first){
	cout<<"=";
      }else cout<<",";
    }
    cout<<vppa[vppa.size()-1 ].second.second*-1<<endl;
  }
  return 0;
}

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

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

  int n, m;
  cin >> n >> m;
  vector<int> a(n);
  int s = 0;
  for (int i = 0; i < n; i++) {
    int tmp;
    cin >> tmp;
    a[i] = tmp;
    s += tmp;
  }
  sort(a.begin(), a.end(), greater<int>());
  string ans = (a[m-1] * 4 * m >= s) ? "Yes" : "No";
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
 
int main()
{
    int n, x, max;
    int a, b, c;
    int ans;
 
    while (1) {
        scanf("%d%d", &n, &x);
        if (n == 0 && x == 0) break;
 
        ans = 0;
        max = x; if (max > n) max = n;
        for (a = 1; a <= max; a++) {
            for (b = a + 1; b <= max; b++) {
                c = x - a - b;
                if (c > b && c <= n) ans++;
            }
        }
        printf("%d\n", ans);
    }
    return 0;
}


Measured memory_bytes: 2052
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int M = 1e5+1;
int n, m;
vector < vector <int> > g;
int dp[M];
int dfs (int u) {
    int &ret = dp[u];
    if (ret + 1)return ret;
    ret = 0;
    for (int v:g[u]){
        ret = max(1 + dfs(v),ret);
    }
    return ret;
}
int main () {
    memset(dp, -1, sizeof dp);
    scanf("%d %d",&n,&m);
    g.resize(n);
    for (int i=0;i<m;i++){
        int u, v;
        scanf("%d %d",&u,&v);
        --u, --v;
        g[u].push_back(v);
    }
    int mx = 0;
    for (int i=0;i<n;i++){
        mx = max(mx, dfs(i));
    }
    cout << mx;
}


Measured memory_bytes: 7424
#include<iostream>
#include<algorithm>
#include<vector>
#include<numeric>
#include<string>
#include<cmath>
#include<set>
#include<queue>
#include<deque>
#include<bitset>
#include<iomanip>
#include<cctype>
#include<map>
#include<cstring>

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,a,b) for (int (i)=a;(i)<(b);(i)++)
#define all(x) (x).begin(),(x).end()

using namespace std;
using ll = long long int;

const int inf = 1001001000;
const long long int Inf = 1001001001001001000;



void print(vector<vector<int>> a){
	for (int i = 0; i < a.size(); i++)
	{
		for (int j=0;j<a[i].size();j++){
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}

void print(vector<vector<long long int>> a){
	for (int i=0;i<a.size();i++){
		for (int j=0;j<a[i].size();j++){
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}

void print(vector<int> a){
    int n = a.size();
    for (int j=0;j<n;j++) {
        if (j != n-1) cout << a[j] << " ";
        else cout << a[j] << endl;
    }
}

void print(vector<long long int> a){
    int n = a.size();
    for (int j=0;j<n;j++) {
        if (j != n-1) cout << a[j] << " ";
        else cout << a[j] << endl;
    }
}

void print(set<int> a){
	for (auto x:a)
		cout << x << " ";
	cout << endl;
}


int main() {
  int n;
  string s;
  cin >> n >> s;
  vector<vector<int>> dp(n+1, vector<int>(n+1, 0));
  for (int i = n - 1; i >= 0; --i)
  {
	  for (int j = n - 1; j >= 0; --j)
	  {
		  if (s[i] != s[j])
			  dp[i][j] = 0;
		  else
			  dp[i][j] = dp[i + 1][j + 1] + 1;
	  }
  }
  int ans = 0;
  rep(i,n)rep(j,n) {
    if (i >= j) continue; // i < j;
    int now = min(dp[i][j], j-i);
    ans = max(ans, now);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 98176
def solve(a,b,k):
    if a==0 and b==0:
        return '0 0'
    if a>=k:
        str = '%d %d' % (a-k,b)
        return str
    else:
        b = b + a - k
        a = 0
        if b<0:
            return '0 0'
        str = '0 %d' % (b)
        return str 
        

a,b,k = map(int, input().split())
print(solve(a,b,k))



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

typedef long long ll;

void solve() {
    int N, p;
    cin >> N;
    vector<int> q(N);
    rep(i, N) {
        cin >> p;
        q[p - 1] = i;
    }
    rep(i, N) {
        cout << 30000 * i + 1;
        if (i == N - 1) cout << endl;
        else cout << " ";
    }
    rep(i, N) {
        cout << 30000 * (N - i) + 1 + q[i];
        if (i == N - 1) cout << endl;
        else cout << " ";
    }
    return;
}

int main() {
    solve();
}

Measured memory_bytes: 768
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    
    ll H, W;
    cin >> H >> W;
    
    if (H == 1 || W == 1) {
        cout << 1 << endl;
        return 0;
    }

    cout << ll(ceil(H * W / double(2))) << endl;
    
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>

#define N 1000000
#define L 14


char H[N][L];

int getChar(char v){
  if(v == 'A') return 1;
  else if(v =='C') return 2;
  else if(v =='G') return 3;
  else if(v =='T') return 4;
  else return 0;
}

int getKey(char str[]){
  int sum = 0,p=1,i;
  for(i=0;i<strlen(str);i++){
    sum += p*(getChar(str[i]));
    p*=5;
  }
  return sum;
}

int h1(int key){ return key%N; }
int h2(int key){ return 1+(key%(N-1));}
 
int find(char str[]){
  int key,i,h;
  key = getKey(str);
  i=0;
  while(1){
    h = (h1(key)+i*h2(key))%N;
    if(strcmp(H[h],str)==0) return 1;
    else if(strlen(H[h])==0) return 0;
    i++;
  }
  return 0;
}

int insert(char str[]){
  long long key,i,h;
  key = getKey(str);
  i=0;
  while(1){
    h = (h1(key)+i*h2(key))%N;
    if(strcmp(H[h],str)==0) return 1;
    else if(strlen(H[h])==0){
      strcpy(H[h],str);
      return 0;
    }
    i++;
  }
  return 0;
}
 

int main(){
  int n,i,h,z;
  char str[L],x[L];
  
  for(i=0;i<N;i++){
 H[i][0] = '\0';
  }
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%s%s",x,str);

    if(x[0]=='i'){
      insert(str);
    }
    else{
      if(find(str)){
	printf("yes\n");

    }  
      else{
	printf("no\n");

      }
    }
  }
  return 0;
}

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

namespace atcoderA
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] input = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
            var list = new HashSet<int>();
            for(int i = 0; i < 3; i++)
            {
                list.Add(input[i]);
            }
            Console.WriteLine(list.Count());
        }
    }
}

Measured memory_bytes: 13396
N, *d = map(int, open(0).read().split())
allmax = max(d)
allMaxCount = d.count(allmax)
for i in range(N):
    max = 0
    if(allMaxCount > 1 or d[i] != allmax):
        max = allmax
    else:
        for j in range(N):
            if(i == j):
                continue
            if d[j] > max:
                max = d[j]
                if max == allmax:
                    break
    print(max)

Measured memory_bytes: 25036
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair <int, int>;
const double PI = acos(-1);

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  vector<int> B(N);
  rep(i, N) {
    cin >> A[i];
    B[i] = A[i];
}

  sort(B.begin(), B.end());

  rep(i, N){
    if(B[N-1] == A[i]) cout << B[N-2] << endl;
    else cout << B[N-1] << endl;
  }
}


Measured memory_bytes: 3200
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define MAXN 100005
int a[MAXN], dp[MAXN];
int n;
int main(){
    scanf("%d", &n);
    for(int i = 1; i <= n; i++)
        scanf("%d", &a[i]);
    memset(dp, 0x3F, sizeof dp);
    dp[1] = 0;
    for(int i = 1; i < n; i++){
        dp[i+1] = min(dp[i+1], dp[i]+abs(a[i+1]-a[i]));
        dp[i+2] = min(dp[i+2], dp[i]+abs(a[i+2]-a[i]));
    }
    printf("%d\n", dp[n]);
} 

Measured memory_bytes: 896
#include <iostream>
#include <math.h>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()

typedef long long lint;

using namespace std;

int main(){
  int A,B,K;
  cin>>A>>B>>K;
  if(B-A+1<2*K){
    FOR(i,A,B+1)cout<<i<<endl;
  }else{
    REP(i,K)cout<<A+i<<endl;
    REP(i,K)cout<<B+1-K+i<<endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
typedef long long ll;
vector<ll> idx[200005];
ll memo[200005]={0};
signed main(){
  ll n;
  cin>>n;
  ll k;
  cin>>k;
  ll fk=k;

  ll seq=1;
  vector<ll> vec;
  vec.push_back(0);
  for(int i=1;i<=n;i++){
    ll a;
    cin>>a;
    vec.push_back(a);
  }
  for(int i=1;i<=n;i++) vec.push_back(vec[i]);
  for(int i=1;i<=2*n;i++){
    idx[vec[i]].push_back(i);
  }
  ll pos=1;
  memo[1]=0;
//  if(k>50000000){
    do{
      ll num=vec[pos];
      ll kpos=upper_bound(idx[num].begin(),idx[num].end(),pos)-idx[num].begin();
      ll npos=idx[num][kpos];
      if(npos>n){
        npos-=n;
        seq++;
      }
      if(npos==n) {
        pos=1;
        break;
      }
      npos++;
      pos=npos;
      if(pos>n) {
        pos-=n;
        seq++;
      }
    //  cout<<pos<<endl;
  /*    pos=npos;
      if(memo[pos]!=0||pos==1){
        //seq-=memo[pos];
        break;
      } */
      //memo[pos]=seq;
    }while(1);
    if(k<memo[pos]){
      pos=1;
    }
    else{
      k-=memo[pos];
      k%=seq;
    }
//  }
  if(k==0){
    cout<<" "<<endl;
    return 0;
  }
  ll cnt=1;
  while(cnt<k){
    ll num=vec[pos];
    ll kpos=upper_bound(idx[num].begin(),idx[num].end(),pos)-idx[num].begin();
    ll npos=idx[num][kpos];
    npos++;
    if(npos>n){
      npos-=n;
      cnt++;
    }
    pos=npos;
  }
  vector<ll> ans;
  while(pos<=n){
    ll num=vec[pos];
    auto itr=upper_bound(idx[num].begin(),idx[num].end(),pos);
    ll npos=*itr;
    if(npos>n) {
      ans.push_back(num);
      pos++;
    }
    else{
      pos=npos+1;
    }
  }
  for(int i=0;i<ans.size();i++) cout<<ans[i]<<" ";
  cout<<endl;
}


Measured memory_bytes: 19308
X,N=map(int,input().split())
if N==0:
    print(X)
    exit()

P_ori=list(map(int,input().split()))
if P_ori.count(X)==0:
    print(X)
    exit()


P1=sorted(P_ori)
N=list(range(0,102))
PZ=[]
for i in range(len(N)):
    if P1.count(N[i])==0:
        PZ.append(N[i])

PZ.append(X)
P2=sorted(PZ)
t=P2.index(X)
if P2[t]==P2[0]:
    print(P2[1])
    exit()
elif P2[t]==P2[-1]:
    print(P2[-2])
    exit()
else:
    dist1=abs(P2[t-1]-P2[t])
    dist2=abs(P2[t]-P2[t+1])
    if dist1<=dist2:
        print(P2[t-1])
        exit()
    else:
        print(P2[t+1])
        exit()
print(0)

Measured memory_bytes: 9260
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define INF 10000000000
using namespace std;
using ll = long long;
int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    map<int, int> mp;
    vector<int> v;
    rep(i,n){
        cin >> a[i];
        if(!mp[a[i]]){
            v.push_back(a[i]);
        }
        mp[a[i]]++;
    }
    int ans = 0;
    for(auto e:v){
        if(mp[e]<e){
            ans += mp[e];
        }else{
            ans += mp[e] - e;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 5496
#include<stdio.h>

int main(void)
{
  int a,b;
  char op;
  
  for(;;){
    scanf("%d %c %d",&a,&op,&b);
    if(op=='?'){
      break;
    }else if(op=='/'){
      printf("%d\n",a/b);
    }else if(op=='*'){
      printf("%d\n",a*b);
    }else if(op=='+'){
      printf("%d\n",a+b);
    }else if(op=='-'){
       printf("%d\n",a-b);
    } 
  }
  return 0;
}


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

int main(){
    string a, b;
    cin >> a >> b;
    
    a += b;
    
    int n=0, k=1;
    
    for(int i=a.length()-1; i>=0; i--){
        n += (a[i]-'0')*k;
        k *= 10;
    }
    int sqn = sqrt(n);
    if(n==sqn*sqn)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}


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

const long long MOD = 1000000007;

int main(void) {
    string S;
    cin >> S;
    int size = S.length();
    int dp[100010][13];
    for (int i = 0; i < 100005; ++i) {
        for (int j = 0; j < 13; ++j) {
            dp[i][j] = 0;
        }
    }
    dp[0][0] = 1;
    for (int i = 1; i <= size; ++i) {
        for (int j = 0; j < 13; ++j) {
            if (S[i - 1] == '?') {
                for (int k = 0; k < 10; ++k) {
                    dp[i][(j * 10 + k) % 13] += dp[i - 1][j];
                    dp[i][(j * 10 + k) % 13] %= MOD;
                }
            } else {
                int k = S[i - 1] - '0';
                dp[i][(j * 10 + k) % 13] += dp[i - 1][j];
                dp[i][(j * 10 + k) % 13] %= MOD;
            }
        }
    }
    printf("%d\n", dp[size][5]);

    return 0;
}


Measured memory_bytes: 5504
#include<cstdio>

using namespace std;

#define rep(i, n) for(i = 0;i < n;++i)
#define int2(x, y) int x, y; scanf("%d%d",&x, &y)

int G[100][100] = {0};
int inf = 0;
bool warshallfloyd(int v){
  int i, j, k;
  rep(k, v)rep(i, v)rep(j, v)if(G[i][k] != inf && G[k][j] != inf && G[i][j] > G[i][k] + G[k][j])G[i][j] = G[i][k] + G[k][j];
  rep(i, v)if(G[i][i] < 0)return false;
  return true;
}

signed main(void){
  int i, j;
  int2(v, e);
  rep(i, e){
    int2(a, b);
    G[a][b] = -1;
  }
  puts(warshallfloyd(v) ? "0" : "1");

  return 0;
}

Measured memory_bytes: 2688
#define _USE_MATH_DEFINES
#define INF 100000000
#include <iostream>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>

using namespace std;

typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P> PP;

static const double EPS = 1e-8;

const int tx[] = {0,1,0,-1};
const int ty[] = {1,0,-1,0};

bool isPrime[1000000];

int main(){

	fill_n(isPrime,sizeof(isPrime),true);
	isPrime[0] = false;
	isPrime[1] = false;
	for(int i=1;i*i<=1000000;i++){
		if(isPrime[i]){
			for(int j=i+i;j<=1000000;j+=i){
				isPrime[j] = false;
			}
		}
	}

	int a,d,n;
	while(~scanf("%d %d %d",&a,&d,&n)){
		if(a==d && d==n && n==0) break;
		int c=0;
		int res=0;
		for(int i=a;i<=1000000;i+=d){
			if(isPrime[i]) {
				c++;
				if(c==n){
					res=i;
					break;
				}
			}
		}

		printf("%d\n",res);
	}
}

Measured memory_bytes: 0
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::{Write, BufWriter};
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, [ $t:tt ]) => {{
        let len = read_value!($next, usize);
        (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    }};

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused)]
macro_rules! debug {
    ($($format:tt)*) => (write!(std::io::stderr(), $($format)*).unwrap());
}
#[allow(unused)]
macro_rules! debugln {
    ($($format:tt)*) => (writeln!(std::io::stderr(), $($format)*).unwrap());
}

fn solve() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (write!(out,$($format)*).unwrap());
    }
    input! {
        m: usize,
        dc: [(i64, i64); m],
    }
    let mut tot: i64 = -1;
    let mut sum: i64 = 0;
    for (d, c) in dc {
        sum += d * c;
        tot += c;
        let q = (sum - 1) / 9;
        tot += q;
        sum -= 9 * q;
    }
    puts!("{}\n", tot);
}

fn main() {
    // In order to avoid potential stack overflow, spawn a new thread.
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}


Measured memory_bytes: 12540
N, M = gets.split.map &:to_i
AB = $<.map{|s|
  s.split.map &:to_i
}
AB.sort_by!{|a, b|
  a
}

ans = 0
work = []
(1..M).each{|day|
  # p AB
  # break if AB.empty?
  while !AB.empty? && AB[0][0] == day
    a, b = AB.shift
    idx = work.bsearch_index{|n| n > b } || work.size
    work[idx, 0] = b
  end
  next if work.empty?
  # p work
  ans += work.pop
}
p ans

Measured memory_bytes: 14072
#include<iostream>
#include<string>
#include<array>
#include<algorithm>
using namespace std;

int main() 
{
	int a, b;
	cin >> a >> b;
	if (a % 2 == 0 || b % 2 == 0) {
		cout << "No" << endl;
	}
	else {
		cout << "Yes" << endl;
	}
}

Measured memory_bytes: 256
H,W = map(int,input().split())
Ch,Cw = map(int,input().split())
Dh,Dw = map(int,input().split())
S = [list(input()) for i in range(H)]
 
res_S = [[-1]*W for i in range(H)]
dx = [1,-1,0,0]
ddx = [-2,-1,0,1,2,-2,-1,1,2,-2,2,-2,-1,1,2,-2,-1,0,1,2]
dy = [0,0,1,-1]
ddy = [-2,-2,-2,-2,-2,-1,-1,-1,-1,0,0,1,1,1,1,2,2,2,2,2]
count = 0
 
que = [(Ch,Cw)]
que_warp =[(Ch,Cw)]
res_S[Ch-1][Cw-1] = 0
 
while (que or que_warp):
    l = len(que)
    while (que):
        if l > 0:
            que_warp.append(que[0])
            l -= 1
        for i in range(4):
            nx = int(que[0][0]+dx[i])
            ny = int(que[0][1]+dy[i])
            if (1<=nx<=H) and (1<=ny<=W):
                if res_S[nx-1][ny-1]<0 and S[nx-1][ny-1]=='.':
                    res_S[nx-1][ny-1]=count
                    que.append((nx,ny))
                    que_warp.append((nx,ny))
        que.pop(0)
 
    count += 1
 
    while(que_warp):
        for i in range(len(ddx)):
            nx = int(que_warp[0][0] + ddx[i])
            ny = int(que_warp[0][1] + ddy[i])
            if (1 <= nx <= H) and (1 <= ny <= W):
                if res_S[nx-1][ny-1]<0 and S[nx-1][ny-1]=='.':
                    res_S[nx-1][ny-1] = count
                    que.append((nx, ny))
        que_warp.pop(0)
 
print (res_S[Dh-1][Dw-1])


Measured memory_bytes: 122616
#include <iostream>

using namespace std;

int main() {
    int N;
    cin >> N;
    int a[N];
    for (int i = 0; i < N; ++i) {
        cin >> a[i];
    }
    int min = 1000;
    int max = 0;
    for (int i = 0; i < N; ++i) {
        if (min > a[i]) {
            min = a[i];
        }
        if (max < a[i]) {
            max = a[i];
        }
    }
    cout << max - min << endl;
    return 0;
}

Measured memory_bytes: 256
import sys
import numpy as np
import itertools
def main():
    input = sys.stdin.readline

    N = int(input())
    P = list(map(int, input().split()))
    #print(P)
    P = np.array(P)
    #print(P)
    ans = np.arange(start=1, step=1, stop=N+1)
    #print(ans)
    if np.all(P == ans):
        print('YES')
    else:
        dels_comb = list(itertools.combinations(P,2))
        #print(dels_comb)

        length = len(dels_comb)
        for i in range(length):
            dels = dels_comb [i]
            a, b = dels

            _P = P[(P != a) & (P != b)]
            _ans = ans[(ans != a) & (ans != b)]
            
            #print(_P)
            #print(_ans)
            if np.all(_P == _ans):
                if np.where(P == a)[0] == np.where(ans == b)[0]:
                    if np.where(P == b)[0] == np.where(ans == a)[0]:
                        print('YES')
                        break
            if i + 1 == length:
                print('NO')
if __name__ == '__main__':
    main()

Measured memory_bytes: 18720
#include <bits/stdc++.h>
#define LOCAL
using namespace std;
template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
out << "(" << a.first << "," << a.second << ")";
return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << ": " << arg1 << " |";
__f(comma + 1, args...);
}
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
#define int long long
using P = pair<int,int>;
//#########################################
signed main(){
    int n;cin >>n;
    string s;cin >> s;
    int ret = 0;
    int now = 0;
    rep(i,n){
        
        if(s[i] == 'I')now++;
        else now--;
        ret = max(ret,now);
        

    }
    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 3612
a,b,k = map(int,input().split())
l = []
for i in range(a,a + k):
	if a <= i <= b:l.append(i)
for i in range(b,b - k,-1):
	if a <= i <= b:l.append(i)
l = sorted(set(l))
for i in l:print(i)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fod(i,a,b) for(int i=a;i>=b;i--)
#define me0(a) memset(a,0,sizeof(a))
#define me1(a) memset(a,-1,sizeof(a))
#define op freopen("in.txt", "r", stdin)
#define pii pair<int,int>
#define mp(x,y) make_pair(x,y)
using namespace std;
const int INF = 0x3f3f3f3f;
typedef unsigned long long ULL;
typedef long long LL;
void read(int& val) { int x = 0; int bz = 1; char c; for (c = getchar(); (c<'0' || c>'9') && c != '-'; c = getchar()); if (c == '-') { bz = -1; c = getchar(); }for (; c >= '0' && c <= '9'; c = getchar()) x = x * 10 + c - 48; val = x * bz; }
const int mod=1e9+7;
const int maxn =1e6+11;
int n,m,k;
int a[maxn];
struct node{
    int l,r;
    bool operator<(const node b)const{
        return (min(l,r))<(min(b.r,b.l));
    }
};
priority_queue<node>p;

int main(){

    LL ans=0;
    read(n);
    fo(i,1,n) read(a[i]);
    sort(a+1,a+1+n);
    reverse(a+1,a+1+n);

    ans = a[1];
    p.push({a[1],a[2]});p.push({a[1],a[2]});

    fo(i,3,n){
        node tp = p.top();p.pop();
        ans+=min(tp.l,tp.r);
        p.push({a[i],tp.l});p.push({a[i],tp.r});
    }
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 6056
#include<stdio.h>
 int main(void){
  int x,i;
    int a[4];
  for(x=0,i=0;i<4;i++){
    scanf("%d",&a[i]);
    x+=a[i];
  }
  printf("%d\n%d\n", x/60,x%60);
  return 0;
}

Measured memory_bytes: 596
#include <stdio.h>
int data[100];
int sp = 0;
int pop() {
  printf("%d\n", data[sp - 1]);
  data[sp - 1] = 0;
  sp--;
}
void push(int v) {
  data[sp] = v;
  sp++;
}
int main() {
  int j, k;
  int i, l = 0;
  int data2[100];
  while(j != EOF) {
    j = scanf("%d", &data2[i]);
    i++;
  }
  for (k = 0; k < i; k++) {
    if (data2[k] > 0) push(data2[k]);
    else {
      pop();
	}
  }
  return 0;
}

Measured memory_bytes: 600
import math
a, b, C = map(int, input().split())
C2 = math.radians(C)

sin = math.sin(C2)
cos = math.cos(C2)
c = math.sqrt(a**2 + b**2 - 2*a*b*cos)

S =(a*b*sin) / 2
L = a+b+c
#L**2 = a**2 + b**2 - 2*a*b*cos
h = (a*b*sin/2)/(a/2)

print("{0:.8f}".format(S))
print("{0:.8f}".format(L))
print("{0:.8f}".format(h))

Measured memory_bytes: 7836
#include <stdio.h>
#define MAX 1000000

int main(void) {
  int n;
  int sosuu[MAX];
  int i, j;
  int getsuyou, doyou;
  int count = 0; // 素数の数

  sosuu[0] = 6;
  count++;
  
  for (i=1; i<42857; i++) { 
    // debug
    // printf("**%d**\n",i);

    getsuyou = i*7 +1;
    for (j=0; j<count; j++) {
      if (getsuyou % sosuu[j] == 0)
	break;
    }
    if (j == count) {
      sosuu[count++] = getsuyou;
    }

    doyou = i*7 + 6;
    for (j=0; j<count; j++) {
      if (doyou % sosuu[j] == 0)
	break;
    }
    if (j == count) {
      sosuu[count++] = doyou;
    }
  }

  // debug
  // for (j=0; j<count; j++)
  //  printf("%d ", sosuu[j]);
  // putchar('\n');
  
  // debug
  //printf("count:%d\n", count);
  

  while(scanf("%d", &n) == 1) {

    if (n == 1)
      break;

    

    printf("%d:", n);
    
    for (j=0; j<count; j++) {
      if (n < sosuu[j])
	break;

      if (n % sosuu[j] == 0)
	printf(" %d", sosuu[j]);
    }

    putchar('\n');
  }
  return 0;
  
}

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

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> H(N);
  for (int i = 0; i < N; i++) cin >> H.at(i);
  vector<int> DP(N, 2e9);
  DP.at(0) = 0;
  for (int i = 0; i < N; i++) {
    for (int k = 1; k <= K; k++) {
      if (i + k < N) DP.at(i + k) = min(DP.at(i + k), DP.at(i) + abs(H.at(i) - H.at(i + k)));
    }
  }
  cout << DP.at(N - 1) << "\n";
}

Measured memory_bytes: 1024