akhauriyash/Code-Regression huggingface dataset:
class UnionFind
  def initialize(n); @data = Array.new(n,-1); end
  def find(a); @data[a] < 0 ? a : @data[a] = find(@data[a]); end
  def same?(a,b); find(a) == find(b); end
  def size(a); -@data[find(a)]; end
  def unite(a,b)
    a = find(a); b = find(b)
    return if a == b
    a,b = b,a if @data[a] > @data[b]
    @data[a] += @data[b]; @data[b] = a
  end
end

n,m,k = gets.split.map &:to_i
UF = UnionFind.new(n)
FR = Array.new(n){[]}
BL = Array.new(n){[]}

m.times do
  a,b = gets.split.map &:to_i
  a -= 1; b -= 1
  UF.unite(a,b)
  FR[a] << b
  FR[b] << a
end

k.times do
  a,b = gets.split.map &:to_i
  a -= 1; b -= 1
  BL[a] << b
  BL[b] << a
end

ans = n.times.map do |i|
  cnt = UF.size(i)
  FR[i].each do |f|
    cnt -= 1 if UF.same?(i,f)
  end
  BL[i].each do |b|
    cnt -= 1 if UF.same?(i,b)
  end
  cnt -= 1
end

puts ans.join(" ")

Measured memory_bytes: 31864
# coding: utf-8
# Your code here!

A, B = map(int , input().split())

# print(A)
# print(B)

max_num = A + B

if max_num < A - B:
    max_num = A - B
    
if max_num < A * B:
    max_num = A * B

# print(A + B)
# print(A - B)
# print(A * B)

print(max_num)

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

long long n;

int main(){
    cin >> n;

    long long tmp=n,sum=0;

    while(tmp>0){
        sum+=tmp%10;
        tmp/=10;
    }

    if(n%sum == 0)
        cout << "Yes\n";
    else
        cout << "No\n";

    return 0;
}


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

struct dice
{
	int _1, _2, _3, _4, _5, _6;

	void throwdice(char c) {
		int temp;
		switch(c){
			case 'N':
				temp = _1;
			    _1 = _2;
			    _2 = _6;
			    _6 = _5;
			    _5 = temp; 
			break;
			case 'E':
				temp = _1;
	      		_1 = _4;
	      		_4 = _6;
	      		_6 = _3;
	      		_3 = temp;
			break;
			case 'W':
			    temp = _1;
			    _1 = _3;
			    _3 = _6;
			    _6 = _4;
			    _4 = temp;
		    break;
		    case 'S':
		      	temp = _1;
		      	_1 = _5;
		      	_5 = _6;
		      	_6 = _2;
		      	_2 = temp;
		    break;
		    case 'R':
		    	int t_2 = _2, t_3 = _3, t_4 = _4, t_5 = _5;
		      	_2 = t_4;
		      	_3 = t_2;	      	
		      	_4 = t_5;
		      	_5 = t_3;
		    break;
		}
	}
};

int main(int argc, char const *argv[])
{
	dice d;
	int q, up, front;
	bool upsame;

	cin >> d._1 >> d._2 >> d._3 >> d._4 >> d._5 >> d._6;
	cin >> q;

	for (int i = 0; i < q; ++i)
	{
		upsame = false;
		cin >> up >> front;
		for (int j = 0; j < 4; ++j)
		{
			d.throwdice('S');
			if(d._1 == up)
			{
				upsame = true;
				break;
			}
		}

		if(!upsame)
		{
			for (int j = 0; j < 4; ++j)
			{
				d.throwdice('W');
				if(d._1 == up)
					break;
			}
		}

		for (int j = 0; j < 4; ++j)
		{
			d.throwdice('R');
			if(d._2 == front)
				break;
		}
		cout << d._3 << endl;
	}
	
	return 0;
}

Measured memory_bytes: 3080
from bisect import bisect_left as bl
from collections import deque as dq
X, Y, Z, K = map(int, input().split())
ABC = [sorted(list(map(int, input().split()))) for _ in range(3)]
AB = []
for i in range(X):
  for j in range(Y):
    AB.append(ABC[0][i] + ABC[1][j])
AB.sort(reverse = True)
res = []
for i in range(min(K, X * Y)):
  for j in range(Z):
    res.append(AB[i] + ABC[2][j])
res.sort(reverse = True)
for i in range(K):
  print(res[i])

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

int H,W=5,B[11][5],i,j,R;

int del()
{
	int i,j,k,t,r=0;
	for(i=0;i<H;i++)
		for(j=0;j<W;j++)
		{
			if(B[i][j]!=-1)
			{
				for(k=j+1;k<W&&B[i][j]==B[i][k];k++);
				if(k-j>=3)
				{
					r+=B[i][j]*(k-j);
					for(t=j;t<k;t++)B[i][t]=-1;
				}
			}
		}
	R+=r;
	return r;
}

void fall()
{
	int i,j,k,t;
	for(i=0;i<W;i++)
		for(j=H-1;j>=0;j--)
			if(B[j][i]!=-1)
			{
				for(k=j+1;k<H&&B[k][i]==-1;k++);
				k--;
				t=B[k][i];
				B[k][i]=B[j][i];
				B[j][i]=t;
			}
}

int main()
{
	for(;scanf("%d",&H),H;)
	{
		R=0;
		memset(B,-1,sizeof(B));
		for(i=0;i<H;i++)
			for(j=0;j<5;j++)
				scanf("%d",&B[i][j]);
		while(del()!=0)
		{
			fall();
		}
		printf("%d\n",R);
	}
	return 0;
}

Measured memory_bytes: 600
#define _USE_MATH_DEFINES
#include <sstream> //string stream its useful!
#include<string>
#include<iostream>
#include<utility> //pair
#include <vector> // vector
#include <algorithm>    // swap,sort,binary_search
#include <functional>   // std::greater
#include <map> //map
#include<set> //set
#include<queue> //queue
#include<list> //list
#include<cmath>
#include<numeric>
#include<cassert>
#include <iomanip> //cout<<setprecision
#include <regex>

typedef long long ll;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define REP(i,n) for (int i=0;i<(n);i++)
ll W = 1000000007;

using namespace std;
void omajinai() {
    
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<setprecision(15);
    //freopen("txt.csv","r",stdin);
}



static function<ll(ll,ll)> sumfunc = [](ll l1,ll l2)->ll{return l1 + l2;};
class UF{
public:
    vector<ll> v;
    vector<ll> v2;
    function<ll(ll,ll)> func;
    UF(long t,function<ll(ll,ll)> func){
        v = vector<ll>(t);
        v2 = vector<ll>(t);
        for(int i = 0; i<v.size();i++) v[i] = i;
        this->func = func;
    }
    long getunion(long t){
        if(v[t] == t) return t;
        v[t] = getunion(v[t]);
        return v[t];
    }
    void unite(long a, long b){
        a = getunion(a), b = getunion(b);
        if(a>b) swap(a,b);
        v[b] = a;
        v2[a] = func(v2[b],v2[a]);
    }
};

class Main{
public:
    int N;
    int K,L;
    vector<pair<int,int> > p,r;
    map<pair<int,int> ,int> s;
    vector<int> ufp,ufq;
    
    int getunion(vector<int> &ar,int t){
        if(ar[t] == t ) return t;
        ar[t] = getunion(ar, ar[t]);
        return ar[t];
    }
    bool issameunion(vector<int> &ar, int a, int b){
        return getunion(ar,a) == getunion(ar,b);
    }
    
    Main(){
        cin>>N>>K>>L;
        p = vector<pair<int,int> >(K+1);
        r = vector<pair<int,int> >(L+1);
        FOR(i,1,K+1) cin>>p[i].first>>p[i].second;
        FOR(i,1,L+1) cin>>r[i].first>>r[i].second;
        UF ufp(N+1,sumfunc);
        UF ufq(N+1,sumfunc);
        FOR(i,1,K+1){ufp.unite(p[i].first,p[i].second);}
        FOR(i,1,L+1){ufq.unite(r[i].first,r[i].second);}
        FOR(i,1,N+1){
            pair<ll,ll> pp = make_pair(ufp.getunion(i),ufq.getunion(i));
            if(s.find(pp)== s.end()) s[pp] = 0;
            s[pp]++;
        }
        cout<<s[make_pair(ufp.getunion(1),ufq.getunion(1))];
        FOR(i,2,N+1) cout<<" "<<s[make_pair(ufp.getunion(i),ufq.getunion(i))];
        cout<<endl;
    }
    
    void run(){
    }
};

int main(){
    omajinai();
    Main().run();
}


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

namespace ABC099
{
    class Program
    {
        static void Main(string[] args)
        {
            List<string> list = new List<string>();
            while (true)
            {
                string line = Console.ReadLine();
                if (line == null) break;
                list.Add(line);
            }
            var result = list[1].Distinct().ToList();
            int count = 0;
            foreach (var item in result)
            {
                if (!(item.Equals(' ')))
                {
                    count++;
                }
            }
            switch (count)
            {
                case 3:
                    Console.WriteLine("Three");
                    break;
                case 4:
                    Console.WriteLine("Four");
                    break;
                default:
                    break;
            }
        }
    }
}


Measured memory_bytes: 13276
using System;
using System.Collections.Generic;
namespace std

{
    class Test 
    {
        static void Main(string[] args) {
            var input = Console.ReadLine().Split(' ');
            var x = int.Parse(input[0]);
            var y = int.Parse(input[1]);

            Test obj = new Test();
            int ans = obj. GCD(x, y);
            Console.WriteLine(ans);
       
       
        }

        public int GCD(int x, int y) {
            if (x < y) {
                int tmp;
                
                tmp = x;
                x = y;
                y = tmp;
            }
            while( y > 0) {
                int r;
               
                r = x % y;
                x = y;
                y = r;
            }

            return x;



        }

    }
}


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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int A, B, C, K;
    cin >> A >> B >> C >> K;
    for (int i = 0; i < K; ++i) {
        if (B <= A) {
            B *= 2;
        } else {
            C *= 2;
        }
    }
    if (C > B && B > A) {
        cout << "Yes\n";
    } else {
        cout << "No\n";
    }
    return 0;
}

Measured memory_bytes: 3648
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll (i) = 0; (i) < (n); (i)++)
#define rep1(i, n) for(ll (i) = 1; (i) <= (n); (i)++)
#define rrep(i, n) for(ll (i) = (n) - 1; (i) >= 0; (i)--)
#define rrep1(i, n) for(ll (i) = (n); (i) >= 1; (i)--)
const ll INF = 1145141919;
const ll MOD = 1000000007;
template<class T> void chmax(T &a, const T &b){if(a < b){a = b;}}
template<class T> void chmin(T &a, const T &b){if(a > b){a = b;}}

char mp[55][55];
ll ans[55][55];
ll dy[8] = {1, 1, 1, 0, -1, -1, -1, 0};
ll dx[8] = {-1, 0, 1, 1, 1, 0, -1, -1};

int main(){

    ll H, W;
    cin >> H >> W;
    rep1(y, H)rep1(x, W){
        cin >> mp[y][x];
    }
    rep1(y, H)rep1(x, W){
        rep(i, 8)if(mp[y + dy[i]][x + dx[i]] == '#')ans[y][x]++;
    }
    rep1(y, H){
        rep1(x, W){
            if(mp[y][x] == '#')cout << "#";
            else cout << ans[y][x];
        }    
        cout << endl;
    }
    
    

    return 0;
}

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

struct node{
  struct node *right;
  struct node *left;
  struct node *p;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x != NIL){
    y = x;
    if(z->key < x->key){
      x = x->left;
    }
    else{
      x = x->right;
    }
  }
  z->p = y;

  if(y == NIL){
    root = z;
  }
  else if(z->key < y->key){
    y->left = z;
  }
  else{
    y->right = z;
  }
}

void inorder(Node u){
  if(u == NIL){
    return;
  }
  inorder(u->left);
  printf(" %d",u->key);
  inorder(u->right);
}

void preorder(Node u){
  if(u == NIL){
    return;
  }
  printf(" %d",u->key);
  preorder(u->left);
  preorder(u->right);
}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);

    if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    }
    else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
  }
  return 0;
}



Measured memory_bytes: 25236
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> iint;
typedef pair<ll,ll> llll;
#define ALL(x) (x).begin(),(x).end()
const ll zero = 0;
const ll INF = 9223372036854775807; //10^18
const int inINF = 2147483647; //10^9
const ll MOD = 1000000007; //10^9+7
const ll MOD2 = 998244353;
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int main(){
    string s;
    cin >> s;
    if(s == "zyxwvutsrqponmlkjihgfedcba"){
        printf("-1\n");
        return 0;
    }
    vector<int> c(26, 0);
    for (int i = 0; i < s.length(); i++) {
        c[s[i] - 'a']++;
    }
    int ii = 26;
    for (int i = 0; i < 26; i++) {
        if(c[i] == 0){
            ii = i;
            break;
        }
    }
    if(ii != 26){
        s += 'a' + ii;
        printf("%s\n", s.c_str());
        return 0;
    }

    int ind = s.length() - 1;
    while(true){
        while(s[ind] == 'z'){
            s = s.substr(0, ind);
            ind--;     
            c[25]--;     
        }
        auto t = s[ind] - 'a';
        t++;
        s[ind] = t + 'a';
        c[t-1]--;
        c[t]++;
        bool check = true;
        for (int i = 0; i < 26; i++) {
            if(c[i] > 1) check = false;   
        }
        if(check) break;
    }
    printf("%s\n", s.c_str());


}

Measured memory_bytes: 3632
#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>;


int main() {
  int A, B;
  cin >> A >> B;
  for (int i = 1; i <= 10000; i++) {
    if ((int)(i * 0.08) == A && (int)(i * 0.1) == B) {
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}


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

ll f(ll a, ll b){
	return (b%3 == 0) ? 0 : a;
}

ll g(ll n, ll m){
	ll ret = (1LL << 60);
	for(ll x=m/3-5; x<=m/3+5; ++x){
		if(x<=0 || m-x<=0) continue;
		for(ll y=n/2-3; y<=n/2+3; ++y){
			if(y<=0 || n-y<=0) continue;
			ll a = n*x;
			ll b = y*(m-x);
			ll c = (m-x)*(n-y);
			ret = min(ret, max({a, b, c}) - min({a, b, c}));
		}
	}
	return ret;
}

int main()
{
	ll n, m;
	cin >> n >> m;
	ll ans = (1LL << 60);
	
	ans = min(ans, f(n, m));
	ans = min(ans, f(m, n));
	ans = min(ans, g(n, m));
	ans = min(ans, g(m, n));
	
	cout << ans << endl;
    return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
const int N=1e6+7;
const double eps=1e-5;
int i,j,k,m,n,tot,d;
int a[N],b[N],ver[N],nxt[N],head[N],edge[N]; 
int v[100][100];
void add(int x,int y,int w)
{
	ver[++tot]=y,edge[tot]=w,nxt[tot]=head[x],head[x]=tot;
}
int main()
{
	scanf("%d%d",&n,&d);
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=d;j++)
			scanf("%d",&v[i][j]);
	}
	for(int i=1;i<=n;i++)
	{
		for(int j=i+1;j<=n;j++)
		{
			double ans=0;
			for(int k=1;k<=d;k++)
			{
				ans+=(v[i][k]-v[j][k])*(v[i][k]-v[j][k]);
			}
			int x=sqrt(ans);
			if(ans-x*x<=eps) tot++;
		}
	}
	printf("%d",tot);
}

Measured memory_bytes: 256
# include <bits/stdc++.h>
# define speed ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
// # pragma GCC optimize "-O3"
# define int long long
using namespace std;
  
const int N = 2 * 1e6 + 7;
const int mod = 1e9 + 7;

int p[N], used[N];
vector < int > adj[N]; 

void solve() {
	int n, m;
	cin >> n >> m;
	for ( int i = 0; i < m; i++ ) {
		int u, v;
		cin >> u >> v;
		adj[u].push_back( v );
		adj[v].push_back( u );
	}
	queue < int > q;
	q.push( 1 );
	p[1] = 1; 
	used[1] = 1;
	while ( !q.empty() ) {
		int v = q.front();
		q.pop();
		for ( auto u: adj[v] ) {
			if ( !used[u] ) {
				used[u] = 1;
				p[u] = v;
				q.push( u );
			}
		}
	}
	for ( int i = 2; i <= n; i++ ) {
		if ( !used[i] ) {
			cout << "No\n";
			return;
		}
	}
	cout << "Yes\n";
	for ( int i = 2; i <= n; i++ ) {
		cout << p[i] << "\n";
	}
}

int32_t main() {
    speed;
    int T = 1;
    // cin >> T;
    while ( T-- ) {
    	solve();
    }
}


Measured memory_bytes: 58412
#include<iostream>

using namespace std;

int main(){
    long long int a,b,c,d, p1,p2,p3,p4,pM,pM2,res;
    cin >> a >> b >> c >> d;
    p1 = a*c;
    p2 = a*d;
    p3 = b*c;
    p4 = b*d;
    pM = max(p1,p2);
    pM2 = max(p3,p4);
    res = max(pM,pM2);
    cout << res << endl;
}


Measured memory_bytes: 3164
#include<bits/stdc++.h>
using namespace std;
#define all(vec) vec.begin(),vec.end()
typedef long long int ll;
const ll MOD=1000000007;
const ll INF=1000000010;
const ll LINF=4000000000000000010LL;
const int MAX=310;
const double EPS=1e-9;
int dx[4]={0,0,1,-1};
int dy[4]={-1,1,0,0};
int main(){
	double mi=10000000;
	double ma=0;
	double h;
	while(cin>>h){
		mi=min(mi,h);
		ma=max(ma,h);
	}
	cout<<ma-mi<<endl;
}



Measured memory_bytes: 3124
# -*- coding: utf-8 -*-
N,K=map(int,input().split())
S=input()
count=0
ans=0
for i in range(N-1):
    if S[i]==S[i+1]:
        ans=ans+1
    elif S[i]!=S[i+1]:
        count=count+0.5
        if K>=count:
            ans=ans+1
print(ans)

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

int main()
{
  long long N, r, q;
  char c;
  cin >> N;
  vector<char> p = {};
  while (N != 0) {
    q = N / 26;
    r = N % 26;
    if (r != 0) {
      c = r - 1 + 'a';
      N /= 26;
    } else {
      c = 'z';
      N -= 26;
      N /= 26;
    }
    p.push_back(c);
  }
  for (int i = p.size() - 1; i >= 0; i--) {
    cout << p.at(i);
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 3620
#include<iostream>
#include<cstdio>
using namespace std;
long long return1(long long n);
int main(){
	long long h;
	scanf("%lld",&h);
	cout<<return1(h);
} 
long long return1(long long n){
		if(n==1) return 1;
		return(1+2*return1(n/2)) ;
}

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

int main() {
  int k, n;
  vector<int> a;
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    int tmp_a;
    cin >> tmp_a;
    a.push_back(tmp_a);
  }
  sort(a.begin(), a.end());
  int sum = 0;
  for (int i = 0; i < k; i++) {
    sum += a[i];
  }
  printf("%d", sum);
  return 0;
}

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

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define between(a,x,b) ((a)<=(x)&&(x)<=(b))
using namespace std;

int main(){
  bool f = true;
  int n, m;
  string tmp;
  char in[16];
  scanf("%d", &n);
  vector<string>str(n);
  rep(i, n){
    scanf("%s", in);
    str.push_back(string(in));
  }
  scanf("%d", &m);
  rep(i, m){
    scanf("%s", in);
    if(find(str.begin(), str.end(), in) != str.end()){
      if(f) printf("Opened by %s\n", in), f = 0;
      else printf("Closed by %s\n", in), f = 1;
    }else printf("Unknown %s\n", in);
  }
  return 0;
}

Measured memory_bytes: 1248
#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>;

int main()
{
	ll N;
	cin >> N;
	vector<ll> L;
	char str[2] = {'S','R'};

	for (int i = 0; i < N; ++i)
	{
		ll tmp;
		cin >> tmp;
		L.push_back(tmp);
	}
	ll count = 0;
	for (int i = 0; i < N-2; ++i)
	{
		for (int j = i + 1; j < N-1; ++j)
		{
			for (int k = j + 1; k < N; ++k)
			{
				if (L[i] + L[j] > L[k] && L[j] + L[k] > L[i] && L[k] + L[i] > L[j] && L[i] != L[j] && L[j] != L[k] && L[k] != L[i])
				{
					count++;
				}
			}
		}
	}

	

	cout << count << endl;

	return 0;

}

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

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

    stack<char> s;
    for (int i = 0; i < X.size(); i++) {
        if (s.empty()) {
            s.push(X[i]);
        } else {
            if (s.top() == 'S' && X[i] == 'T') {
                s.pop();
            } else {
                s.push(X[i]);
            }
        }
    }

    cout << s.size() << endl;
    return 0;
}

Measured memory_bytes: 644
#include <iostream>
#include <algorithm>
using namespace std;
const int maxn = 100 + 10;
int h[maxn];

int main(){
    int n = 0;
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> h[i];
    }
    int ans = 1, hn = h[0];
    for(int i = 1; i < n; i++){
        if(hn <= h[i]){
            //cout << h[i] << ' ' << i << endl;
            ans++;
        }
        hn = max(hn, h[i]);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void){
  int cook[2][5];
  int time = 0, count = 0, max = 10;
  int i, mxin;
  
  for(i = 0;i < 5;i++){
    scanf("%d", &cook[0][i]);
    cook[1][i] = cook[0][i] % 10;
    if(cook[1][i] != 0){
      count++;
      if(max > cook[1][i]){
        max = cook[1][i];
        mxin = i;
      }
    }
  }
  
  for(i = 0;i < 5;i++){
    if(cook[1][i] != 0 && i != mxin){
      if(count > 1){
        time += cook[0][i];
        time += 10 - cook[1][i];
        cook[0][i] = 0;
        count--;
      }
    }
  }
  for(i = 0;i < 5;i++){
    time += cook[0][i];
  }
  
  printf("%d\n", time);
  return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#include <stdlib.h>


int main(){
  int i,j,k;
  int key;
  int N;
  int *A;
  int v;

  scanf("%d",&N);
  
  A =(int *)malloc(N*sizeof(int ));
  for(i=0;i<N;i++){
    scanf("%d",&A[i]);
  }
  for(k=0;k<N-1;k++)printf("%d ",A[k]);
  printf("%d\n",A[k]);
  
  for(i=1;i<N;i++){
    v=A[i];
    j=i-1;
    while(j>=0&&A[j]>v){
      A[j+1]=A[j];
      j--;
    }
    A[j+1]=v;
    for(k=0;k<N-1;k++)printf("%d ",A[k]);
    printf("%d\n",A[k]);
  }


return 0;
}



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

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

  int sum = 0;

  for( int i = 0; i < N.size(); i++ )
    sum += N.at( i ) - '0';

  if( sum % 9 == 0 )
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

Measured memory_bytes: 3724
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,m;
    cin >> n >> m;
    map<ll,ll> mp1,mp;
    REP(i,n){
        ll x;
        cin >> x;
        mp1[x]++;
        mp[x%m]++;
    }
    ll ans = 0;
    ans += mp[0]/2;
    mp[0]%=2;
    for(ll i=1;i<m-i;++i){
        ll t = min(mp[i],mp[m-i]);
        ans += t;
        mp[i] -= t;
        mp[m-i] -= t;
    }
    if(m%2==0){
        ans += mp[m/2]/2;
        mp[m/2]%=2;
    }
    for(ll i=1;i<=100000;++i){
        ll t = min(mp[i%m]/2, mp1[i]/2);
        ans += t;
        mp[i%m] -= t*2;
    }
    cout << ans << endl;
    return 0;
}

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

typedef long long ll;

string S;
ll N;
vector<ll> Min;
ll R;

int main() {
  cin >> S;
  N = S.size() + 1;
  Min.resize(N);
  Min[N - 1] = 0;
  for (ll i = N - 2; i >= 0; --i) {
    if (S[i] == '<')
      Min[i] = 0;
    else if (S[i] == '>')
      Min[i] = Min[i + 1] + 1;
  }
  ll now;
  for (ll i = 0; i < N; ++i) {
    if (i == 0)
      now = Min[0];
    else if (S[i - 1] == '<')
      now = max(Min[i], now + 1);
    else if (S[i - 1] == '>') {
      assert(now > Min[i]);
      now = Min[i];
    }
    R += now;
  }
  cout << R << endl;
  return 0;
}


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

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

 if(abs(a - b) <= k && abs(a - c) <= k && abs(a - d) <= k && abs(a - e) <= k && abs(b - c) <= k && abs(b - d) <= k && abs(b - e) <= k && abs(c - d) <= k && abs(c - e) <= k && abs(d - e) <= k) {
     cout << "Yay!"; return 0;
 }

 cout << ":(";
    return 0;
}

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

// 比較関数
bool my_compare(pair<string, int> a, pair<string, int> b) {
    // 基本はfirstで比較
    if(a.second != b.second){
        // return a.first < b.first; // 昇順
        return a.second > b.second; // 降順
    }

    // それ以外はsecondで比較
    if(a.first != b.first){
        return a.first < b.first;
    }else{
        // どちらも同じ
        return true;
    }
}
int main(void){
 
    int N;
    cin >> N;
    string S;
    map<string,int> m;
    vector<pair<string,int>> v;
    
    for(int i = 0; i < N; i++){
        cin >> S;
        m[S]++;
    }
    
    for (auto i = m.begin();i != m.end();i++){
        //cout << i->first << " => " << i->second << "\n";
        v.push_back(make_pair(i->first,i->second));
    }
 
    sort(v.begin(),v.end(),my_compare);
 
    bool flag = true;
    int k;
    pair<string,int> item;
    for ( int i = 0; i < v.size();i++ ) {
        
        item = v[i];
        
        if(flag){
            k = item.second;
            flag = false;
        }
        
        if(item.second!=k)break;
        cout << item.first << endl;
        
    }
    
    
}
 

Measured memory_bytes: 28912
H,N = map(int,input().split())
AB = [list(map(int, input().split())) for i in range(N)]

M = max(a for a,b in AB)

dp = [0]*(H+M)

for i in range(1,H+M):
    dp[i] = min(dp[i-a]+b for a,b in AB)
    
print(min(dp[H:]))

Measured memory_bytes: 3668
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll INF = 1LL << 60;
const int MAX = 1000000010;
const ll MOD = 1000000007;
const double PI = acos(-1);

int main() {
    int N; cin >> N;
    string S; cin >> S;
    int ans = 0;
    int x = 0;
    for (int i = 0; i < N; i++) {
        if (S[i] == 'I') x++;
        if (S[i] == 'D') x--;
        chmax(ans, x);
    }

    cout << ans << endl;
    return 0;
}

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

using namespace std;

int main() {
  long long h, w;
  cin >> h >> w;

  long long res = 1e18;
  for (int i = 0; i < 2; i++) {
    swap(h, w);
    for (long long y = 1; y < h - 1; y++) {
      long long a = y * w;
      long long b = ((h - y) / 2) * w;
      long long c = ((h - y + 1) / 2) * w;
      long long smax = max({a, b, c});
      long long smin = min({a, b, c});
      res = min(res, smax - smin);
    }
  }
  for (int i = 0; i < 2; i++) {
    swap(h, w);
    for (long long y = 1; y < h; y++) {
      long long a = y * w;
      long long b = (h - y) * (w / 2);
      long long c = (h - y) * ((w + 1) / 2);
      long long smax = max({a, b, c});
      long long smin = min({a, b, c});
      res = min(res, smax - smin);
    }
  }
  cout << res << endl;

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<iomanip>
#include<ctime>
#include<set>
#include<map>
#include<queue>
#include<stack>
#define sqr(x) ((x)*(x))
#define fz1(i,n) for ((i)=1;(i)<=(n);(i)++)
#define fd1(i,n) for ((i)=(n);(i)>=1;(i)--)
#define fz0g(i,n) for ((i)=0;(i)<=(n);(i)++)
#define fd0g(i,n) for ((i)=(n);(i)>=0;(i)--)
#define fz0k(i,n) for ((i)=0;(i)<(n);(i)++)
#define fd0k(i,n) for ((i)=(long long)((n)-1);(i)>=0;(i)--)
#define fz(i,x,y) for ((i)=(x);(i)<=(y);(i)++)
#define fd(i,y,x) for ((i)=(y);(i)>=(x);(i)--)
#define fzin fz1(i,n)
#define fzim fz1(i,m)
#define fzjn fz1(j,n)
#define fzjm fz1(j,m)
#define ff(c,itr) for (__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
#define rdst(st,len){static char ss[len];scanf(" %s",ss);(st)=ss;}
#define inc(x,y) {x+=(y);if(x>=mod)x-=mod;}
#define dec(x,y) {x-=(y);if(x<0)x+=mod;}
using namespace std;
int n,m,i,j,x,y,ioc,w[100005],w2[100005],vis[100005],px,py;
vector<int> bi[100005],seq;
void dfs(int x,int fa)
{
	vis[x]=1;
	ff(bi[x],it){
		if(*it!=fa){
			if(vis[*it]){
				px=x;
				py=*it;
			}
			else{
				w[*it]=-w[x];
				dfs(*it,x);
			}
		}
	}
}
void dfs2(int x,int fa)
{
	ff(bi[x],it){
		if(*it==fa)continue;
		if(px==x&&py==*it)continue;
		if(py==x&&px==*it)continue;
		dfs2(*it,x);
		w[x]+=w[*it];
		w2[x]+=w2[*it];
	}
}
int main()
{
	scanf("%d%d",&n,&m);
	fz1(i,m){
		scanf("%d%d",&x,&y);
		bi[x].push_back(y);
		bi[y].push_back(x);
	}
	w[1]=1;
	dfs(1,0);
	int cnt=0,ans=0;
	fz1(i,n){
		cnt+=w[i];
	}
	if(n!=m){
		if(cnt){
			puts("-1");
			return 0;
		}
	}
	else{
		if(w[px]==w[py]){
			if(cnt&1){
				puts("-1");
				return 0;
			}
			ans=abs(cnt)/2;
			w[px]-=cnt/2;
			w[py]-=cnt/2;
		}
		else{
			if(cnt){
				puts("-1");
				return 0;
			}
			w2[px]=1;w2[py]=-1;
		}
	}
	dfs2(1,0);
	seq.push_back(0);
	fz1(i,n){
		if(!w2[i]){
			ans+=abs(w[i]);
		}
		else{
			seq.push_back(w[i]);
		}
	}
	sort(seq.begin(),seq.end());
	int t=seq[seq.size()/2];
	ff(seq,it){
		ans+=abs(*it-t);
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 12156
from collections import deque
n,m=map(int,input().split())
A=[[0]*2 for i in range(m)]
for i in range(m):
  A[i]=list(map(int,input().split()))
ans=0
for i in range(m):
  B=[[] for i in range(n)]
  for j in range(m):
    if j==i:
      continue
    B[A[j][0]-1].append(A[j][1]-1)
    B[A[j][1]-1].append(A[j][0]-1)
  C=[0]*n
  C[0]=1
  D=deque([0])
  while len(D)>0:
    x=D[0]
    D.popleft()
    for j in range(len(B[x])):
      if C[B[x][j]]==0:
        D.append(B[x][j])
        C[B[x][j]]=1
  if C!=[1]*n:
    ans=ans+1
print(ans)

Measured memory_bytes: 3316
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
m = 0
for i in range(n):
    m += b[i]
    if i != n-1 and a[i+1] == a[i] + 1:
        m += c[a[i]-1]
print(m)

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

int main()
{
	const int line_num = 100, column_num = 100;
	int n,m;
	int a[line_num][column_num] = { 0 },
		b[column_num] = { 0 },c[line_num] = { 0 };

	cin >> n >> m;

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

	for(int i = 0; i < n; i++){
		for(int j = 0; j < m; j++){
			c[i] += a[i][j] * b[j];
		}
		cout << c[i] << endl;
	}

	return 0;
}

Measured memory_bytes: 1208
def main():
    K = int(input())
    A, B = map(int, input().split())

    possible = False

    for i in range(A, B+1):
        if i % K == 0:
            possible = True

    if possible:
        print("OK")
    else:
        print("NG")
if __name__ == "__main__":
    main()

Measured memory_bytes: 9172
require 'pp'

# 入力値を数値で返却する
def gets_i()
  gets.chomp.to_i
end

# 空白区切の入力値を数値の配列で返却する
def gets_i_list()
  gets.chomp.split(" ").map(&:to_i)
end

N = gets_i
a_list, b_list = [], []
N.times do
  a, b = gets_i_list
  a_list.push(a)
  b_list.push(b)
end
a_list.reverse!
b_list.reverse!

total = 0
0.upto(N-1) do |i|
  a = a_list[i] + total
  b = b_list[i]
  diff = 0
  diff = b - (a % b) if a % b != 0
  total += diff
end

puts total

Measured memory_bytes: 4104
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1000003;
const int maxn = 1e6+5;
string s;
int n;
int judge(int x,int y)
{
    for(int i = x-1; i < y-1; ++i)
    {
        if(s[i] == '.')continue;
        if(s[i] == s[i+1])return 0;
    }
    return 1;
}
int main()
{
    int a,b,c,d;
    while(cin>>n>>a>>b>>c>>d)
    {
        cin>>s;
        int have1 = 0,have2 = 0;
        have1 = judge(a,c);
        have2 = judge(b,d);
        if(!have1||!have2)
        {
            cout<<"No"<<endl;
            continue;
        }
        if(c < d)
        {
            cout<<"Yes"<<endl;
        }
        else
        {
            int have = 0;
            for(int i = b-1; i <= d-1; ++i)
            {
                if(s[i-1] == '.')
                    if(s[i] == '.')
                        if(s[i+1] == '.')
                            have = 1;
            }
            if(have)cout<<"Yes"<<endl;
            else cout<<"No"<<endl;
        }
    }
}























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

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

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

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

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

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(20) << setiosflags(ios::fixed);
  int n, x;
  cin >> n >> x;
  Yes(n * 500 >= x);
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define INF 1e9
#define pb push_back
#define mp  make_pair
#define loop(a,n) for(long long i=a;i<n;i++)
#define vil vector<long long int>
#define vi vector<int>
#define sz(v) v.size()
#define setbits(x)          __builtin_popcountll(x)
#define ff first
#define ss second
using namespace std;

int nCrevenoroddfinder(int n,int r)
{
    int a=r;
    int b=n-r;
    for(int i=0;i<30;i++)
    {
        int x=1<<i;
        if((x&a)&&(x&b))
        {
            return 0;//even
        }
    }
    return 1;//odd
}

ll gcd(ll a, ll b) {
  if (a == 0)return b;
  return gcd(b % a, a);
}
bool isperfect(ll n) {
  ll y = sqrt(n);
  if (n % y == 0 && y * y == n)return true;
  return false;
}
bool comp(pair<int,int> a, pair<int,int> b) {
    if(a.first == b.first) return a.second>b.second;
  return a.first < b.first;
}
 ll powi(ll a, ll b) {
  ll ans = 1;
  while (b > 0) {
    if (b & 1)ans = (ans * a);
    b = b >> 1;
    a = (a * a);
  }
  return ans;
}
bool isprime(ll n) {
  for (int i = 2; i * i <= n; i++) {
    if (n % i == 0)return false;
  }
  return true;
}
bool prime[10000000];
void seive() {

  prime[1] = true;
  for (int i = 2; i * i < 10000000; i++) {

    if (prime[i])continue;
    for (int j = i * i; j < 10000000; j += i) {
      prime[j] = true;
    }

  }
}

int main()
{
  ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  string st;cin>>st;
  ll s=0;
  for(int i=0;i<st.size();i++) s+=st[i]-'0';
  if(s%9){
      cout<<"No";
  }else cout<<"Yes";
}



  

Measured memory_bytes: 3748
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        try(Scanner sc = new Scanner(System.in)){
            while(true){
                int n = sc.nextInt();
                if(n == 0) break;
                int[] scores = new int[n];
                int sum = 0;
                for(int i=0; i < scores.length; i++){
                    scores[i] = sc.nextInt();
                    sum += scores[i];
                }
                double average,variance;
                average = 0; variance = 0;
                average = (double)sum / scores.length;
                double number = 0;
                for(int j=0; j < scores.length; j++){
                    number += ((double)scores[j] - average) * ((double)scores[j] - average);
                }
                variance = number / scores.length;
                System.out.println(Math.sqrt(variance));
            }
        }
    }   
}


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

void dfs(int a, int b, int C, int D, string buff = ""){
  if(a == C && b == D){
    cout << buff << endl;
    return;
  } else if((a == 5 && b <= 3) || (b == 5 && a <= 3) || a == 6 || b == 6){
    return;
  } else {
    dfs( a + 1, b, C, D, buff + "A");
    dfs( a, b + 1, C, D, buff + "B");
    return;
  }
}

int main(){
  int j, y;
  cin >> j >> y;
  dfs( 0, 0, j, y);
}

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

int main(){
  long long N;
  cin >> N;
  string S="";
  while(N){
    N--;
    char C='a'+N%26;
    S.push_back(C);
    N/=26;
  }
  reverse(S.begin(),S.end());
  cout << S << endl;
}

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

#define pb push_back
#define ff first
#define ss second

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

const int MAXN = 100 * 1000 + 17;

int n, m;
vector<int> adj[MAXN];
bool mark[MAXN];
deque<int> ans;

void dfs_1(int v) {
	mark[v] = true;
	for (auto i : adj[v])
		if (!mark[i]) {
			ans.pb(i);
			dfs_1(i);
			break;
		}
}
void dfs_2(int v) {
	mark[v] = true;
	for (auto i : adj[v])
		if (!mark[i]) {
			ans.push_front(i);
			dfs_2(i);
			break;
		}
}

int main() {
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> n >> m;
	for (int i = 1; i <= m; i++) {
		int v, u;
		cin >> v >> u;
		adj[v].pb(u);
		adj[u].pb(v);
	}
	ans.pb(1);
	dfs_1(1);
	dfs_2(1);
	cout << ans.size() << endl;
	for (auto i : ans)
		cout << i << ' ';
	return 0;
}


Measured memory_bytes: 9600
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

func main() {
	sc := bufio.NewScanner(os.Stdin)

	var (
		n   int
		err error
	)
	if sc.Scan() {
		n, err = strconv.Atoi(sc.Text())
		if err != nil {
			panic(err)
		}
	}

	list := make([]int, n)
	if sc.Scan() {
		splited := strings.Split(sc.Text(), " ")
		for i, v := range splited {
			vv, err := strconv.Atoi(v)
			if err != nil {
				panic(err)
			}

			list[i] = vv
		}
	}

	cnt, sorted := selectionSort(list)

	s := ""
	for _, ss := range sorted {
		s = s + strconv.Itoa(ss) + " "
	}
	s = strings.TrimRight(s, " ")

	fmt.Println(s)
	fmt.Println(cnt)
}

func selectionSort(list []int) (int, []int) {
	cnt := 0
	for i := 0; i < len(list); i++ {
		min := i
		for j := i + 1; j < len(list); j++ {
			if list[min] > list[j] {
				min = j
			}
		}
		if i != min {
			tmp := list[i]
			list[i] = list[min]
			list[min] = tmp
			cnt++
		}
	}

	return cnt, list
}



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

using namespace std;

//#define FILE_IO

int N, V;
int p[200005], d[200005];
int K, v[25];
int rgt[200005];
int bst[400005];
bool can[200005];

class Solver
{
public:
    int dst[200005];
    int lgt[200005][22];
    int dp[400005];

    Solver()
    {
        memset(dst, 0, sizeof(dst));
        memset(lgt, 0, sizeof(lgt));
        memset(dp, 0, sizeof(dp));
        for(int i = 1; i < N; i++)  dst[i] = d[i];
    }

    void precalc()
    {
        for(int i = N; i >= 1; i--)
            for(int j = 0; j <= K; j++)
            {
                if(dst[i] <= v[j])  lgt[i][j] = lgt[i + 1][j] + 1;
                else    lgt[i][j] = 1;
            }
        for(int msk = 1; msk < (1 << K); msk++)
        {
            for(int b = 0; b < K; b++)
                if( (1 << b) & msk )
                {
                    int mmsk = msk ^ (1 << b);
                    int pos = dp[mmsk];
                    dp[msk] = max(dp[msk], pos + lgt[pos + 1][b]);
                }
        }
    }
};

void possible() {printf("Possible\n");}
void impossible() {printf("Impossible\n");}

int main()
{
    #ifdef FILE_IO
    freopen("1.in", "r", stdin);
    freopen("1.out", "w", stdout);
    #endif

    scanf("%d%d", &N, &V);
    for(int i = 1; i <= N; i++) scanf("%d", &p[i]);
    for(int i = 1; i < N; i++)  d[i] = p[i + 1] - p[i];

    K = -1;
    int aux = V;
    while(aux)
    {
        aux /= 2;
        v[++K] = aux;
    }
    reverse(v, v + K + 1);
    v[++K] = V;

    Solver pfx;
    reverse(d + 1, d + N);
    Solver sfx;
    reverse(d + 1, d + N);

    pfx.precalc();
    sfx.precalc();

    int mskmax = (1 << K) - 1;
    for(int msk = mskmax; msk >= 0; msk--)
    {
        can[ pfx.dp[msk] ] = 1;
        bst[msk] = max(bst[msk], sfx.dp[msk ^ mskmax]);
        int st = pfx.dp[msk];
        int dr = bst[msk];
        rgt[st] = max(rgt[st], dr);
    }

    for(int i = N - 1; i >= 0; i--) rgt[i] = max(rgt[i], rgt[i + 1]);

    for(int i = 1; i <= N; i++)
    {
        int st = i - 1;
        int dr = N - rgt[st] + 1;
        int posmax = i + pfx.lgt[i][K] - 1;
        if(dr - 1 <= posmax && can[st])
            for(int j = 1; j <= pfx.lgt[i][K]; j++)  possible();
        else
            for(int j = 1; j <= pfx.lgt[i][K]; j++)  impossible();
        i = posmax;
    }

    return 0;
}


Measured memory_bytes: 44928
#include <iostream>

using namespace std;

int main(){
    
    int a;
    
    cin >> a;
    
    int sum=0,i;
    
    while(a!=0){
        i=a%10;
        sum+=i;
        a/=10;
    }
    
    cout << sum;
    
    return 0;
}

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


int main(){
    double l;
    vector<double>a(100);
    for(int i=0;i<50;i++){
        cin>>a[i];
        if(cin.eof()){
            break;
        }
    }
    sort(a.begin(),a.end(),greater<>());
    for(int i=0;i<51;i++){
        if(a[i]==0){
            l=a[i-1];
            break;
        }
    }
    cout<<a[0]-l<<endl;
    return 0;
}


Measured memory_bytes: 3180
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const ll ZERO = 0;
const ll INF = 1e14;
const ll MOD = 1000000007;
const double PI = 3.1415926535897;

int main() {
    int N,K;
    cin >> N >> K;
    int R, S, P;
    cin >> R >> S >> P;
    string T;
    cin >> T;
    vector<int> vec(N);
    for(int i = 0;i < N;i++) {
        if(T.at(i) == 'r') {
            vec.at(i) = 0;
        }
        else if(T.at(i) == 's') {
            vec.at(i) = 1;
        }
        else {
            vec.at(i) = 2;
        }
    }
    int ret = 0;
    char A = 'a';
    int cnt = 1;
    for(int i = 0;i < K;i++) {
        A = T.at(i);
        for(int j = i;j < N - K;j += K) {
            if(T.at(j) == T.at(j + K)) {
                cnt++;
            }
            else {
                if(A == 'r') {
                    ret += (cnt + 1) / 2 * P;
                }
                else if(A == 's') {
                    ret += (cnt + 1) / 2 * R;
                }
                else {
                    ret += (cnt + 1) / 2 * S;
                }
                cnt = 1;
                A = T.at(j + K);
            }
            
        }
        if(A == 'r') {
            ret += (cnt + 1) / 2 * P;
        }
        else if(A == 's') {
            ret += (cnt + 1) / 2 * R;
        }
        else {
            ret += (cnt + 1) / 2 * S;
        }
        cnt = 1;
    }
    cout << ret << endl;
}

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

int main()
{
   int n;
   cin>>n;
   vector<int> v(n);
   map<int,int> m;
   
   for(int i=0;i<n-1;i++)
   {
       cin>>v[i];
       m[v[i]]++;
   }
   
    for(int i=1;i<=n;i++)
   {
       cout<<m[i]<<endl;
   }
   
  
  
}


Measured memory_bytes: 13552
#include <bits/stdc++.h>
#define repl(i,l,r)for(long long i=(l);i<(r);i++)
#define rep(i,n) for (long long i = 0; i < (n); ++i)
const int INF = 2147483647;//int max
const long long int MOD = 1000000007;
using namespace std;
using ll = long long;
using P = pair<int,int>;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//ミョ(-ω- ?)
int main() {
    ll n;
    cin >> n;
    ll s = 0;
    vector<ll> a(n,0);
    rep(i,n){cin >> a[i];s += a[i];}
    ll res = LONG_LONG_MAX;
    ll sum = 0;
    rep(i,n){
        sum += a[i];
        res = min(res,abs(sum - (s - sum)));
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;

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

int abs(int n)
{
	if (n < 0) return (-n);
	else return (n);
}

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

	int x[n];
	REP(i, n) cin >> x[i];

	int sum = 0;
	REP(i, n){
		if (abs(x[i] - k) < abs(x[i])) sum  += abs(x[i] - k);
		else sum += abs(x[i]);
	}

	cout << sum * 2 << endl;

}


Measured memory_bytes: 256
#pragma optimization_level 3
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")

#include<bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);cout<<fixed;cout<<setprecision(10);
#define randomINIT mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define ll long long 
#define gcj cout<<"Case #"<<tc<<": "
#define ld long double
#define pll pair<ll,ll>
#define vll vector<pll>
#define vl vector<ll>
#define f first
#define s second
#define pb push_back
#define MAP map<ll,ll>
#define MAPs map<ll,sl>
#define MAPv map<ll,vl>
#define mset1(x,val,n) foo(i,0,n+5) x[i]=val;
#define mset2(x,val,n,m) foo(i,0,n+5) foo(j,0,n+5) x[i][j]=val;
#define mod 1000000007
#define foo(i,a,b) for(ll i=(a);i<=(b);i++)
#define rep(i,a,b) for(ll i=(a);i>=(b);i--)
#define FOR(i,v) for(auto &(i):(v))
#define OUTv(v) for(auto &i:(v)) cout<<i<<" ";
#define deb1(a) cout<<a<<"\n";
#define deb2(a,b) cout<<a<<" "<<b<<"\n";
#define deb3(a,b,c) cout<<a<<" "<<b<<" "<<c<<"\n";
#define deb4(a,b,c,d) cout<<a<<" "<<b<<" "<<c<<" "<<d<<"\n";
#define sl set<ll> 
#define sll set<pll>
#define ub upper_bound
#define lb lower_bound
using namespace std;

const ll   INF = 0x7f7f7f7f7f7f7f7f;
const ll NINF = -INF;
const ll MAXN  = 1e+6+8;
const ll N=1e+5+7;

int dx8[]={0,1,1,1,0,-1,-1,-1}, dy8[]={1,1,0,-1,-1,-1,0,1};
int dx4[]={0,1,0,-1}, dy4[]={1,0,-1,0};

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }
    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

#define UMAP unordered_map<ll,ll,custom_hash>

ll t=1;randomINIT;
//<<-----Declare Variable Here------->>//
ll n,k,a[205],dp[N];
 
//<<-----Implement Functions Here---->>//
 
 
//<<-----Start of Main--------------->>//
void MAIN(ll tc){
	cin>>n>>k;
	foo(i,1,n) cin>>a[i];
	memset(dp,0,sizeof(dp));
	foo(i,1,n) dp[a[i]]=1;
	foo(i,1,k){
		foo(j,1,n){
			if(i-a[j]<0) break;
			if(!dp[i-a[j]]) dp[i]=1;
		}
	}
	if(dp[k]) cout<<"First\n";
	else cout<<"Second\n";


}

int main(){
	fastio;
	// cin>>t;
	foo(i,1,t){
		MAIN(i);
	}
 
    // #ifndef ONLINE_JUDGE
    // cout<<"\nTime Elapsed: " << 1.0*clock() / CLOCKS_PER_SEC << " sec\n";
    // #endif
}

Measured memory_bytes: 1024
import java.util.*;
 
public class Main{
  public static void main(String[]args){
    Scanner sc = new Scanner(System.in);
    int A = Integer.parseInt(sc.nextLine());
    int B = Integer.parseInt(sc.nextLine());
    int C = Integer.parseInt(sc.nextLine());
    int X = Integer.parseInt(sc.nextLine());
    
    int ans = 0;
    for(int i = 0; i <= A; i++){
      for(int j = 0; j <= B; j++){
        int z = i*500+j*100;
        if(z > X){
          continue;
        }
        if((X-z)/50 <= C){
          ans++;
        }
      }
    }
    
    System.out.println(ans);
  }
}

Measured memory_bytes: 23892