akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <vector>
#include <complex>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <cstring>
#include <stack>
#include <cmath>
#include <iomanip>
#include <sstream>

using namespace std;

typedef long long ll;
typedef ll li;
typedef pair<int,int> PI;

#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define REP(i,m,n) for(int i=m; i<=(int)(n); ++i)
#define F first
#define S second
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define SZ(a) (int)((a).size())
#define ALL(a) a.begin(),a.end()
#define FOR(it,a) for(__typeof(a.begin())it=a.begin();it!=a.end();++it)
int dx[]={0,1,0,-1,1,1,-1,-1};
int dy[]={1,0,-1,0,-1,1,1,-1};


int n;
int in[10][3];

void solve(){
  rep(i,n){
    rep(j,3) cin >> in[i][j];
    sort(in[i],in[i]+3);
  }

  vector<int> can[n];

  rep(i,n) rep(k,60*60*12){
    int s=k%60;
    int m=k/60%60;
    int h=k/60/12;
    int arr[]={s,m,h};
    sort(arr,arr+3);
    bool ok = false;
    do{
      if((arr[0]-in[i][0]+60)%60 == (arr[1]-in[i][1]+60)%60 &&
         (arr[0]-in[i][0]+60)%60 == (arr[2]-in[i][2]+60)%60) {
        ok=true;
        break;
      }
    }while(next_permutation(arr,arr+3));

    
    if(0){
      cout << arr[0] << ' ' << arr[1] << ' ' << arr[2] << endl;
      cout << in[i][0] << ' ' << in[i][1] << ' ' << in[i][2] << endl;
      exit(0);
    }
    
    if(ok){
      //cout << i << ' ' << h << ' ' << m  << ' ' << s << endl;
      can[i].pb(k);
    }
  }

  PI ans(0,60*60*12*10);
  rep(k,60*60*12){
    int owa=k;
    bool ok=true;
    rep(i,n){
      vector<int>::iterator p=lower_bound(ALL(can[i]),k);
      if(p==can[i].end()){
        ok=false;
        break;
      }
      owa=max(owa,*p);
    }
    if(ok && ans.S-ans.F>owa-k)
      ans=mp(k,owa);
  }

  printf("%02d:%02d:%02d %02d:%02d:%02d\n",
         ans.F/3600,ans.F/60%60,ans.F%60,
         ans.S/3600,ans.S/60%60,ans.S%60 );
}

main(){
  while(cin >> n, n) solve();
}

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

long long K;
vector<long long> nums;

int main(){
	cin >> K;

	queue<long long> q;
	queue<long long> qnext;
	for(long long i = 1; i < 10; i++) {
		nums.push_back(i);
		q.push(i);
	}


	while(1) {
		while(!q.empty()) {
			long long num = q.front();
			q.pop();

			if(num%10 == 0) {
				nums.push_back(num * 10 + 0);
				nums.push_back(num * 10 + 1);
				qnext.push(num * 10 + 0);
				qnext.push(num * 10 + 1);
			} else if (num%10 == 9) {
				nums.push_back(num * 10 + 8);
				nums.push_back(num * 10 + 9);
				qnext.push(num * 10 + 8);
				qnext.push(num * 10 + 9);
			} else {
				nums.push_back(num * 10 + num%10 - 1);
				nums.push_back(num * 10 + num%10);
				nums.push_back(num * 10 + num%10 + 1);
				qnext.push(num * 10 + num%10 - 1);
				qnext.push(num * 10 + num%10);
				qnext.push(num * 10 + num%10 + 1);
			}
		}
		swap(q, qnext);

		if(nums.size() > K) {
			sort(nums.begin(), nums.end());
			cout << nums[K-1] << endl;
			return 0;
		}
	}
}

Measured memory_bytes: 6144
#include<bits/stdc++.h>
using namespace std;
#define V vector
#define L long
#define W V<L>
L E=70,M=2e17,i,a,b;W S(V<W>p){if(!E)return{1,0};V<V<W>>T(2);for(W x:p){T[x[1]&1].push_back({x[0]/2,x[1]/2});if(x[0]&1)T[(x[1])&1].push_back({x[0]/2,(++x[1])/2});}for(L i;i<2;i++){L c=0;for(W x:T[!i])c^=(2*x[0]+x[1])%3+1;if(!c){E--;W A=S(T[i]);A[0]*=2;A[1]*=2;A[1]+=i;return A;}}for(W&v:p)v[0]++;W A=S(p);A[0]--;return A;}int main(){cin>>i;V<W>p(i);while(i--,cin>>a>>b)p[i]={a+M,b+M};W x=S(p);cout<<x[0]-M<<" "<<x[1]-M;}

Measured memory_bytes: 62908
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>

using namespace std;
const int MAX  = 5; 
int field[5][5];
bool check(int fx,int fy,int lx,int ly){
  int flag = 1;
  for(int i = fx;i <= lx;i++){
    for(int j = fy;j <= ly;j++){
      if(field[j][i] != 1){
	return false;
      }
    }
  }
  return true;
}
int solve(){
  int ans = 0;
  for(int i = 0;i < MAX;i++){
    for(int j = 0;j < MAX;j++){
      cin >> field[i][j];
    }
  }
  for(int i = 0;i < MAX;i++){
    for(int j = 0;j < MAX;j++){
      for(int k = i;k < MAX;k++){
	for(int l = j;l < MAX;l++){
	  if(check(i,j,k,l)){
	    ans = max(ans,(k-i+1)*(l-j+1));
	  }
	}
      }
    }
  }
  return ans;
  
}
int main(){ 
  int m;
  cin >> m;
  while(m--)cout << solve() << endl;
  
  return 0;
}

Measured memory_bytes: 1160
#include <algorithm>
#include <iostream>
#include <string>
#include <random>
#include <cassert>
#include <cstring>
#include <chrono>
#include <set>
#include <map>

using namespace std;

typedef long long ll;

const ll mod = 1000 * 1000 * 1000 + 7;

ll Pow(ll x, ll n) {
  ll result = 1;
  while (n > 0) {
    if (n % 2) {
      n--;
      result = result * x % mod;
    } else {
      n /= 2;
      x = x * x % mod;
    }
  }
  return result;
}

ll Inv(ll x) {
  return Pow(x, mod - 2);
}

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

  vector<int> rows(n);
  vector<bool> haveRow(n * m + 1);
  for (int i = 0; i < n; ++i) {
    cin >> rows[i];
    haveRow[rows[i]] = true;
  }

  vector<int> cols(m);
  vector<bool> haveCol(n * m + 1);
  for (int i = 0; i < m; ++i) {
    cin >> cols[i];
    haveCol[cols[i]] = true;
  }

  ll numRows = 0;
  ll numCols = 0;
  ll result = 1;

  //cerr << endl;

  for (int i = 0; i < n * m; ++i) {
    int cur = n * m - i;
    //cerr << "Processing " << cur << endl;
    //cerr << numRows << " " << numCols << " " << haveRow[cur] << " " << haveCol[cur] << endl;
    if (haveRow[cur] && haveCol[cur]) {
      numRows++;
      numCols++;
    } else if (!haveRow[cur] && !haveCol[cur]) {
      result = result * (numRows * numCols - i) % mod;
    } else if (haveRow[cur]) {
      result = result * numCols % mod;
      numRows++;
    } else {
      result = result * numRows % mod;
      numCols++;
    }
    //cerr << cur << " " << result << endl;
  }

  cout << result << endl;

  return 0;
}


Measured memory_bytes: 512
#include<cstdio>

int main(void) {
    int n,cnt=0;
    bool flag=true;
    scanf("%d",&n);
    for(int i=0; i<n; i++) {
        char s[3];
        scanf("%s",s);
        cnt += s[0]=='A' ? 1 : -1;
        if(cnt<0) flag=false;
    }
    if(cnt!=0) flag=false;
    printf(flag ? "YES\n" : "NO\n");
    return 0;
}

Measured memory_bytes: 2696
#include <bits/stdc++.h>
using namespace std;
string a, b, c;
int main() {
    cin >> a >> b >> c;
    int alast = a.length()-1;
    int blast = b.length()-1;

    if(a.at(alast) == b.at(0) && b.at(blast) == c.at(0)) {
        cout << "YES" << endl;
    }else {
        cout << "NO" << endl;
    }
}

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

a = list(map(int, input().split()))
b = list(map(int, input().split()))

P = 0
N = 0

for i in range(N2):
    if b[i]-a[i]>=0:
        P = P + ((b[i]-a[i])//2)*2
    else:
        N = N + a[i]-b[i]
       
P2 = P-2*N
        
if P2>=0:
    print('Yes')
else:
    print('No')
        

Measured memory_bytes: 4596
n = gets.chomp.to_i
ans = 0
sqrt = Math.sqrt(n).to_i
1.upto(sqrt) do |a|
    maxb = n / a
    a.upto(maxb) do |b|
        if a * b < n then
            # puts "a, b, c = #{a}, #{b}, #{n - (a * b)}"
            if a == b then
                ans += 1
            else
                ans += 2
            end
        end
    end
end
puts ans

Measured memory_bytes: 14408
#include<stdio.h>
int main()
{
int a,b,c;
scanf("%d %d %d",&a,&b,&c);
if(a<=b)
{
   if(b<=c)
   {
   printf("%d %d %d\n",a,b,c);
   }
   else if(a<=c)
   {
   printf("%d %d %d\n",a,c,b);
   }
   else
   {
   printf("%d %d %d\n",c,a,b);
   }
}
else
{
   if(a<=c)
   {
   printf("%d %d %d\n",b,a,c);
   }
   else if(b<=c)
   {
   printf("%d %d %d\n",b,c,a);
   }
   else
   {
   printf("%d %d %d\n",c,b,a);
   }
}
return 0;
}

Measured memory_bytes: 2656
#include<bits/stdc++.h>
namespace ZDY{
	#pragma GCC optimize(3)
	#define il __inline__ __attribute__ ((always_inline))
	#define rg register
	#define ll long long
	#define ull unsigned long long
	#define db double
	#define sht short
	#define MB template <class T>il
	#define Fur(i,x,y) for(int i=x;i<=y;i++)
	#define Fdr(i,x,y) for(int i=x;i>=y;i--)
	#define fl(i,x) for(int i=head[x],to;to=e[i].to,i;i=e[i].nxt)
	#define clr(x,y) memset(x,y,sizeof(x))
	#define cpy(x,y) memcpy(x,y,sizeof(x))
	#define fin(s) freopen(s".in","r",stdin)
	#define fout(s) freopen(s".out","w",stdout)
	#define fcin ios::sync_with_stdio(false)
	#define l2(n) (int(log2(n)))
	#define inf 0x3f3f3f3f
	MB T ABS(T x){return x>0?x:-x;}
	MB T MAX(T x,T y){return x>y?x:y;}
	MB T MIN(T x,T y){return x<y?x:y;}
	MB T GCD(T x,T y){return y?GCD(y,x%y):x;}
	MB void SWAP(T &x,T &y){T t=x;x=y;y=t;}
}using namespace ZDY;using namespace std;
namespace IO{const char* ln="\n";const int str=1<<20;struct IN{char buf[str],*s,*t;bool _;IN():s(buf),t(buf),_(0){}il char gc(){return s==t&&((t=(s=buf)+fread(buf,1,str,stdin))==s)?EOF:(*s++);}IN&operator>>(char&ch){if(_)return *this;char c;while((c=gc())!=EOF&&isspace(c));if(c==EOF)_=1;else ch=c;return *this;}IN& operator>>(char* ch){if(_)return *this;char c;while((c=gc())!=EOF&&isspace(c));if(c==EOF)return _=1,*this;*ch=c;ch++;while((c=gc())!=EOF&&!isspace(c))*ch=c,ch++;if(c==EOF)_=1;return *this;}IN& operator>>(string& ch){if(_)return *this;char c;while((c=gc())!=EOF&&isspace(c));if(c==EOF)return _=1,*this;ch+=c;while((c=gc())!=EOF&&!isspace(c))ch+=c;if(c==EOF)_=1;return *this;}template<typename T>IN&operator>>(T&x){if(_)return *this;char c=gc();bool ff=0;while(c!=EOF&&(c<'0'||c>'9'))ff^=(c=='-'),c=gc();if(c==EOF){_=1;return *this;}x=0;while(c!=EOF&&'0'<=c&&c<='9')x=(x<<3)+(x<<1)+c-48,c=gc();if(c==EOF)_=1;if(ff)x=-x;return *this;}}in;struct OUT{char buf[str],*s,*t;OUT():s(buf),t(buf+str){}~OUT(){fwrite(buf,1,s-buf,stdout);}void pt(char c){(s==t)?(fwrite(s=buf,1,str,stdout),*s++=c):(*s++=c);}OUT&operator<<(const char*s){while(*s)pt(*s++);return *this;}OUT&operator<<(char*s){while(*s)pt(*s++);return *this;}OUT&operator<<(string s){for(int i=0;s[i];i++)pt(s[i]);return *this;}template<typename T>OUT&operator<<(T x){if(!x)return pt('0'),*this;if(x<0)pt('-'),x=-x;char a[30],t=0;while(x)a[t++]=x%10,x/=10;while(t--)pt(a[t]+'0');return *this;}}out;}using namespace IO;
#define N 10011
int main(){
	int k,x;
	in>>k>>x;
	Fur(i,x-k+1,x+k-1)out<<i<<" ";
}

Measured memory_bytes: 256
/*
 * Copyright Narushima Hironori. All rights reserved.
 */
import java.io.*;

/**
 * http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0106
 */
public class Main {

	public static void main(String[] args) throws IOException {
		Calculator calculator = new Calculator(
				new Shop(200, 380, 0.20, 5),
				new Shop(300, 550, 0.15, 4),
				new Shop(500, 850, 0.12, 3)
		);
		
		BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
		for (String l; (l = r.readLine()).length() > 0;) {
			int volume = Integer.parseInt(l);
			if(volume == 0) {
				break;
			}
			System.out.println(calculator.calc(volume));
		}
	}

}

class Shop {
	
	int price, volume, discountedPrice, discountPer;
	
	Shop(int volume, int price, double discount, int per) {
		this.volume = volume;
		this.price = price;
		
		discountedPrice = (int) (price * per - price * per * discount);
		discountPer = per;
	}
	
	int calcPrice(int count) {
		int total = 0;
		while(count >= discountPer) {
			total += discountedPrice;
			count -= discountPer;
		}
		return total + price * count;
	}
	
	int maxBuyCount(int buyVolume) {
		return buyVolume / volume;
	}
	
}

class Calculator {
	
	Shop[] shops;
	
	Calculator(Shop ... s) {
		shops = s;
	}

	public int calc(int volume) {
		if(volume % 100 != 0) {
			throw new IllegalArgumentException();
		}
		
		int[] buyCounts = new int[shops.length + 1];
		buyCounts[shops.length] = Integer.MAX_VALUE;
		calc(buyCounts, 0, volume);
		return buyCounts[shops.length];
	}

	void calc(int[] count, int shopIndex, int buyVolume) {
		if(shops.length == shopIndex) {
			if(buyVolume == 0) {
				int total = 0;
				for (int i = 0; i < shops.length; i++) {
					total += shops[i].calcPrice(count[i]);
				}
				if(count[shopIndex] > total) {
					count[shopIndex] = total;
				}
			}
		} else {
			Shop shop = shops[shopIndex];
			int maxBuyCount = shop.maxBuyCount(buyVolume);
			for (int buyCount = 0; buyCount <= maxBuyCount; buyCount++) {
				count[shopIndex] = buyCount;
				int nextBuyVolume = buyVolume - shop.volume * buyCount;
				calc(count, shopIndex + 1, nextBuyVolume);
			}
		}
	}

}

Measured memory_bytes: 19544
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>

#define pb push_back
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define ll long long



using namespace std;

void file(){
	#ifndef ONLINE_JUDGE
    	freopen("in.txt", "r", stdin);
	#endif
}
int tc;
const int N=5e5+5,M=2e6+5,MOD=1e9+7,OO=1e9;

int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	//file();	

	std::vector<int> a = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
	int n;
	scanf("%d",&n);

	printf("%d\n",a[n-1] );
}		


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
#include<sstream>
#include<vector>
using namespace std;



int main() {
	//cout << fixed << setprecision(10);
	long long int a, b, c, d, n, m, x[10] = {}, y[8] = {};
	for (int i = 0; i < 6; i++) {
		cin >> x[i];
		y[x[i]]++;
		if (y[x[i]] >= 3) { cout << "NO"; return 0; }
	}
	for (int i = 1; i <= 4; i++) {
		
		if (y[i] == 0) { cout << "NO"; return 0; }
	}
	cout << "YES";
}


Measured memory_bytes: 256
#include<iostream>

int main(){

    while(true){
        int m, f, r;
        std::cin >> m >> f >> r;

        if(m == -1 && f == -1 && r == -1) break;

        if(m == -1 || f == -1){
            std::cout << 'F' << std::endl;
        }else if(m + f >= 80){
            std::cout << 'A' << std::endl;
        }else if(m + f >= 65){
            std::cout << 'B' << std::endl;
        }else if(m + f >= 50){
            std::cout << 'C' << std::endl;
        }else if(m + f >= 30){
            if(r >= 50){
                std::cout << 'C' << std::endl;
            }else{
                std::cout << 'D' << std::endl;
            }
        }else{
            std::cout << 'F' << std::endl;
        }
    }

    return 0;
}



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

int main() {
	int n;
	long long a, minValue = 1000000, maxValue = -1000000, sum = 0;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a;
		if (a < minValue)minValue = a;
		if (a > maxValue)maxValue = a;
		sum += a;


	}
	cout << minValue << " " << maxValue << " " << sum << endl;
	return 0;
}

Measured memory_bytes: 1172
import os
import heapq
import sys,threading
import math
import operator
from collections import defaultdict,deque
from io import BytesIO, IOBase

sys.setrecursionlimit(10 ** 5)
threading.stack_size(2**27)


def gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, a % b)


"""def pw(a,b):
    result=1
    while(b>0):
        if(b%2==1): result*=a
        a*=a
        b//=2
    return result"""


def inpt():
    return [int(k) for k in input().split()]

global ct

def bfs(d,visited,s):
    global ct
    q=deque()
    q.append(s)
    visited[s]=True
    while(q):
        x=q.popleft()
        ct+=1
        for i in d[x]:
            if(not visited[i]):
                visited[i]=True
                q.append(i)
def main():
    n,m=inpt()
    st=set()
    d=defaultdict(list)
    for _ in range(m):
        a,b=inpt()
        if((min(a,b),max(a,b)) not in st):
            st.add((min(a,b),max(a,b)))
            d[a].append(b)
            d[b].append(a)

    visited=[False]*(n+1)
    ans=0
    for i in range(1,n+1):
        global ct
        ct=0
        if(not visited[i]):
            bfs(d,visited,i)
            ans=max(ans,ct)
    print(ans)







BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

if __name__ == "__main__":
    main()
    #threading.Thread(target=main).start()


Measured memory_bytes: 79328
from collections import deque
n, q = map(int, input().split())

graph = [[] for _ in range(n + 1)]
for i in range(n - 1):
    a, b = map(int, input().split())
    graph[a].append(b)
    graph[b].append(a)
    # print(a, b)

nodes = [0 for _ in range(n + 1)]
for i in range(q):
    p, x = map(int, input().split())
    nodes[p] += x

# print(nodes)
result = [0 for _ in range(n + 1)]

# que = [(1, nodes[1])]
que = deque([(1, nodes[1])])

visited = [False] * (n + 1)
while que:
    i, cost = que.popleft()
    if visited[i]:
        continue
    result[i] = cost
    visited[i] = True
    for sub in graph[i]:
        que.append((sub, cost + nodes[sub]))
print(*result[1:])


Measured memory_bytes: 117280
import itertools
import math
import fractions
import functools
import copy
from collections import deque
from functools import reduce
from decimal import Decimal


def main():

    n, k = map(int, input().split())
    p = list(map(int, input().split()))

    p.sort()
    result = 0
    for i in range(k):
        result += p[i]
    print(result)



if __name__ == '__main__':
    main()


Measured memory_bytes: 77500
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <iostream>
using namespace std;

char s1[101010];

int main()
{
	scanf("%s", s1);
	int l = strlen(s1);
	int ans= 0;
	for(int i = 1; i < l; ++i)
	{
		ans += s1[i] != s1[i - 1];
	}
	printf("%d\n", ans);

	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
template<class T>inline bool chmax(T &a, const T &b){if(a < b){a = b; return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(a > b){a = b; return 1;}return 0;}
typedef long long ll;
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll H; cin >> H;
  if(H == 1){
    cout << 1 << endl;
    return 0;
  }
  ll cnt = 0, mon = 1;
  while(H > 1){
    H /= 2;
    cnt += mon;
    mon *= 2;
  }
  cnt += mon;
  cout << cnt << endl;
}

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

int main(){
	unordered_map<int, int> candidate;
	int N, M;
	cin >> N;
	for(int i = 0; i < N; i++){
		int d;
		cin >> d;
		if (candidate.find(d) != candidate.end()){
			candidate[d] ++;
		}
		else{
			candidate[d] = 1;
		}
	}
	cin >> M;
	bool flag = true;
	for(int i = 0; i < M; i++){
		int t;
		cin >> t;
		if (candidate.find(t) == candidate.end()){
			flag = false;
		}
		else if (candidate[t] <= 0){
			flag = false;
		}
		else{
			candidate[t] --;
		}
	}
	if (flag){
		cout << "YES" << endl;
	}
	else cout << "NO" << endl;

	return 0;
}

Measured memory_bytes: 8520
import sys


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    n = int(readline())
    x = list(map(int, readline().split()))
    x.sort()
    mt = 10 ** 10
    for i in range(x[0], x[-1] + 1):
        t = 0
        for v in x:
            t += (v - i) ** 2
        mt = min(mt, t)
    print(mt)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 38512
#include<algorithm>
#include<iostream>
#include<stdio.h>
#include<iostream>
#include<stdio.h>
#include<vector>
#include<set>
#include<string>
#include<iomanip>
#include<queue>
#include<functional>
#include<cmath>
#include<map>
#define rep(i,n) for(int i=0; i<(int)n; i++)//n回繰り返す
#define rrep(i,n)for(int i=n-1;i>=0;i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using graph = vector<vector<int>>;
const ll mod = pow(10, 9) + 7;
const int INF = 1e9;
const ll LINF = 1e18;
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; }

int main() {
    int S, V; cin >> S >> V;
    if (S <= V) {
        cout << "unsafe" << endl;
    }
    else {
        cout << "safe" << endl;
    }
    



}

   

    
    



    
                

 













































































































































Measured memory_bytes: 3624
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <cmath>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <functional>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define ITER( c ) __typeof( c ).begin()
#define REP( i, m, n ) for ( int i = m; i < n; i++ )
#define UREP( i, m, n ) for ( unsigned int i = m; i < n; i++ )
#define IREP( c, it ) for ( ITER(c) it = c.begin(); it != c.end(); ++it )
#define ALL( c ) c.begin(), c.end()
#define PB( n ) push_back( n );
#define MP( a, b ) make_pair( a, b )
#define fst first
#define snd second

int main()
{
	int n;
	cin >> n;
	cin.ignore( 1 );

	REP( ni, 0, n )
	{
		int runner = 0, out = 0, point = 0;

		while ( out < 3 )
		{
			string e;
			cin >> e;

			if ( e == "HIT" )
			{
				runner++;
				if ( 4 <= runner )
				{
					point++;
					runner--;
				}
			}
			else if ( e == "HOMERUN" )
			{
				point += runner + 1;
				runner = 0;
			}
			else
			{
				out++;
			}
		}
		
		cout << point << endl;
	}

	return 0;
}

Measured memory_bytes: 0
#include<cstdio>
#include<cmath>
#include<cstring>
#include<queue>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
using namespace std;
int main(){
	int A,B;
	scanf("%d%d",&A,&B);
	if(2*B >= A) printf("0\n");
	else
		printf("%d\n",A-2*B);
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
	int n, x = 100000;
	scanf( "%d", &n );
	while(n--){
		x *= 1.05;
		if( x % 1000 > 0)
			x += 1000 - x % 1000;
	}
	printf( "%d\n", x );
	return 0;
}

Measured memory_bytes: 592
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <string>
#include <functional>
#include <set>
#define DB cerr<<"D"<<endl
#define pb push_back
using namespace std; using ll=long long; using ld=long double; const int INF=1e9; const ll LINF=1e18; const double dINF = 1e18; const ld ldINF = 1e18; const double EPS = 1e-6;
template<typename T, typename U, typename O> void caut(T a, U b, O c){cout<<"("<<a<<","<<b<<","<<c<<") ";} template<typename T, typename U> void caut(T a, U b){cout<<"("<<a<<","<<b<<") ";} template<typename T> void caut(T a){cout<<"("<<a<<") ";}
using P=pair<double,int>;
const ll M = 998244353;
void add(ll& x, ll y) {x+=y; x%=M;}
void chmax(ll& x, ll y) {if (x<y) x=y;}

int main() {
  string s; cin>>s;
  string t="AKIHABARA_";
  int n=s.size();
  int i,j;
  for(i=0,j=0;i<n;i++) {
    if (s[i]==t[j]) j++;
    else {
      if (t[j]=='A') j++,i--;
      else {
        cout<<"NO"<<endl;
        return 0;
      }
    }
  }
  if (j >= 8) {
    cout<<"YES"<<endl;
  } else {
    cout<<"NO"<<endl;
  }
}

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

using namespace std;
bool wat[3005], sug[3005];

int main()
{
    //freopen("", "r", stdin);
    //freopen("", "w", stdout);
    ios_base::sync_with_stdio(0); cin.tie(0);
    int a, b, c, d, e, f, anss, ansb;
    cin >> a >> b >> c >> d >> e >> f;
    wat[0] = true;
    for (int i = 0; i <= f; i++)
    {
        if (wat[i])
        {
            if (i + 100 * a <= f)
                wat[i + 100 * a] = true;
            if (i + 100 * b <= f)
                wat[i + 100 * b] = true;
        }
    }

    sug[0] = true;
    for (int i = 0; i <= f; i++)
    {
        if (sug[i])
        {
            if (i + c <= f)
                sug[i + c] = true;
            if (i + d <= f)
                sug[i + d] = true;
        }
    }

    double maxs = -1;
    for (int A = 100; A <= f; A += 100)
    {
        for (int B = 0; B <= f - A; B++)
        {
            if (wat[A] && sug[B] && B <= A / 100 * e)
            {
                if (maxs < 1.0 * B / (A + B))
                {
                    maxs = 1.0 * B / (A + B);
                    anss = A + B;
                    ansb = B;
                }
            }
        }
    }
    cout << anss << ' ' << ansb;
    return 0;
}


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

int main()
{
  string S[3];
  for(int i = 0; i < 3; i++)
    cin >> S[i];
  map<char,int> m;
  m['a'] = 0;
  m['b'] = 1;
  m['c'] = 2;
  char t = 'a';
  while(1){
    if(S[m[t]].size() == 0) break;
    char c = S[m[t]][0];
    S[m[t]].erase(0,1);
    t = c;
  }
  cout << char(t-32) << endl;
}

Measured memory_bytes: 256
//BY: YASH JAIN, CF: yashjain0333
#include <bits/stdc++.h>
using namespace std;
#define May_the_fork_be_with_you ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define MOD 1000000007
#define INF 1e18
#define ll long long
#define f first
#define s second
#define pb push_back
#define eb emplace_back
#define endl "\n"
#define int long long
#define N 200005

void solve(){
    int n; cin>>n;
    if(n<2){
        cout<<0; return;
    }
    int t1 = 1;
    for(int i=0;i<n;i++){
        t1 = (t1*10)%MOD;
    }
    int t2 = 1;
    for(int i=0;i<n;i++){
        t2 = (t2*9)%MOD;
    }
    int t3 = 1;
    for(int i=0;i<n;i++){
        t3 = (t3*8)%MOD;
    }
    int res = (t1-(2*t2)%MOD+t3+MOD)%MOD;
    cout<<res;
}

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

Measured memory_bytes: 3612
// Created by code_sm
//
#include<bits/stdc++.h>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp> 
//using namespace __gnu_pbds;
//typedef tree<int,null_type,less<int>,rb_tree_tag, tree_order_statistics_node_update> pseudo_set;
#define ll long long
#define vi vector<int>
#define si set<int> 
#define mii map<int,int>
#define pb push_back
#define pf push_front
#define pii pair<int,int>
#define extract_word(s)  stringstream str(s); while(str>>word)
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define SET(s) cout<<fixed<<setprecision(s)
#define chotu 1000000007
#define set0(a) memset(a,0,sizeof(a))
#define endl "\n"
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define lower_string(s) transform(all(s),s.begin(),::tolower())
#define upper_string(s) transform(all(s),s.begin(),::toupper())
#define size(s) s.size()
template<class T> bool umin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool umax(T &a, T b) { return a < b ? (a = b, true) : false; }
template<typename T,typename U>
bool compare(T x,U y){return(abs(x-y)<=1e-9);}
void solve()
{
fastio
	int x,y;
	cin>>x>>y;
	int chk1=4*x-y;
	int chk2=y-2*x;
	if(chk1>=0&&chk2>=0)
	{
		if((!(chk1&1))&&(!(chk2&1)))
			cout<<"Yes";
		else
			cout<<"No";
	}
	else
		cout<<"No";
}
int main()
{
//code
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif
fastio	
int t;
t=1;
while(t--)
{
	solve();
	cout<<endl;
}
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
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 int INF=1001001001;
vector<pair<int64_t,int64_t>>prime_factorize(int64_t x){
  vector<pair<int64_t,int64_t>>p;
  for(int64_t i=2;i*i<=x;i++){
    int cnt=0;
    if(x%i==0){
    while(x%i==0){cnt++;x/=i;}
    p.push_back(make_pair(i,cnt));
    }
  }
  if(x!=1){p.push_back(make_pair(x,1));}
  return p; 
}

int main() {
  int64_t a,b,c;
  cin>>a>>b>>c;
  if(c-a-b>=0&&4*a*b<(c-a-b)*(c-a-b)){cout<<"Yes"<<endl;}
  else{cout<<"No"<<endl;}
  return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll MOD = 1000000007;
const long long INF = 1LL << 60;

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

int f(int n){
    if(n%2)return 3*n+1;
    else return n/2;
}
int main()
{   
    int s; cin >> s;
    vector<ll> n(1000001,0);
    n[0] = s;
    map<int,int> m;
    m[s]++;
    int res;
    for(int i=1;i<= 1000000;i++){
        n[i] = f(n[i-1]);
        m[n[i]]++;
        if(m[n[i]] >= 2){
            res = i+1;
            break;
        }
    }
    cout << res << endl;
}
    

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

void prime(int a){
  int cnt1=a+1;
  int cnt2=a-1;
  bool is_prime[1000000];
  is_prime[0] = is_prime[1] = false;
  for(int i=2;i<1000000;i++){
    is_prime[i] = true;
  }
  for(int i=2;i*i<1000000;i++){
    if(is_prime[i]){
      for(int j=i*i;j<1000000;j+=i){
        is_prime[j] = false;
      }
    }
  }
  while(1){
    if(is_prime[cnt2]){
      cout << cnt2 << " ";
      break;
    }
    cnt2--;
  }

  while(1){
    if(is_prime[cnt1]){
      cout << cnt1 << endl;
      break;
    }
    cnt1++;
  }

}

int main(){
  while(1){
    int num;
    cin >> num;
    if(cin.eof())
      break;

    prime(num);
  }
  return 0;
}


Measured memory_bytes: 4052
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+10,inf=1e9;
int dp[maxn][3],n,m;
bool vis[maxn][3];
vector<int> a[maxn];
struct pa{
    int val, nod, l;
    bool operator<(const pa x)const{
        return !(val<x.val);
    }
}p;
int main(){
    int u,v;
    scanf("%d%d",&n,&m);
    for(int i=1;i<=m;i++){
        scanf("%d%d",&u,&v);
        a[u].push_back(v);
    }
    for(int i=1;i<=n;i++)
        for(int j=0;j<3;j++)
        dp[i][j]=inf;
    scanf("%d%d",&u,&v);
    dp[u][0]=0;
    priority_queue<pa> q;
    q.push({0,u,0});
    while(!q.empty()){
        p=q.top();q.pop();
        if(vis[p.nod][p.l])continue;
        vis[p.nod][p.l]=true;
        for(int i:a[p.nod]){
            if(!vis[i][(p.l+1)%3]){
                if(dp[i][(p.l+1)%3]>dp[p.nod][p.l]+(p.l==2?1:0)){
                    dp[i][(p.l+1)%3]=dp[p.nod][p.l]+(p.l==2?1:0);
                    q.push({dp[i][(p.l+1)%3],i,(p.l+1)%3});
                }
            }
        }
    }
    printf("%d\n",dp[v][0]==inf?-1:dp[v][0]);
}


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

int main(){
  int N,M;
  cin >> N >> M;
  vector<long> H(N);
  vector<bool> highest(N,true);
  for(int i = 0; i < N; i++){
    cin >> H[i];
  }
  for(int i = 0; i < M; i++){
    int a,b;
    cin >> a >> b;
    if(H[a-1] > H[b-1]){
      highest[b-1] = false;
    }else if(H[a-1] < H[b-1]){
      highest[a-1] = false;
    }else{
      highest[a-1] = false;
      highest[b-1] = false;
    }
  }
  int count = 0;
  for(int i = 0; i < N; i++){
    if(highest[i]){
      count += 1;
    }
  }
  cout << count << endl;
}

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

void solve() 
{
    int mx=0;
    string s,t;cin>>s>>t;
    REP(i,s.size()-t.size()+1){
        int cnt=0;
        REP(j,t.size()){
            if(s[i+j]==t[j])cnt++;
        }
        mx=max(mx,cnt);
    }
    cout<<t.size()-mx<<endl;
}

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

Measured memory_bytes: 3620
#include <cstdio>
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

struct node{
	int num;
	node *parent,*left,*right;
};
node *root,*NIL;

node *treemin(node *x){
	while(x->left!=NIL)
		x=x->left;
	return x;
}

node *nextnode(node *x){
	if(x->right!=NIL) return treemin(x->right);
	node *y=x->parent;
	while(y!=NIL && x==y->right){
		x=y;
		x=y->parent;
	}
	return y;
}

void denode(node *z){//case1，2：有0/1个子树 case3：有2个子树
	node *x,*y;// y是即将被替换掉的节点，即要删除掉的节点
	if(z->left==NIL || z->right==NIL) y=z;
	else y=nextnode(z);
	if(y->left!=NIL) x=y->left;
	else x=y->right;
	if(x!=NIL) x->parent=y->parent;
	if(y->parent==NIL) root=x;
	else{
		if(y==y->parent->left) y->parent->left=x;
		else y->parent->right=x;
	}
	if(y!=z) z->num=y->num;
	delete y;
	return ;
}

node *find(int a){
	node *x=root;
	while(x!=NIL){
		if(x->num<a) x=x->right;
		else if(x->num>a) x=x->left;
		else return x;
	}
	return NIL;
}

void print_inorder(node *x){
	if(x==NIL) return ;
	print_inorder(x->left);
	printf(" %d",x->num);
	print_inorder(x->right);
	return ;
}

void print_preorder(node *x){
	if(x==NIL) return ;
	printf(" %d",x->num);
	print_preorder(x->left);
	print_preorder(x->right);
	return ;
}

void insert(int a){
	node *x=root,*y=NIL;
	node *z=new node();
	z->num=a;z->left=NIL;z->right=NIL;
	while(x!=NIL){
		y=x;
		if(z->num < x->num) x=x->left;
		else x=x->right;
	}
	z->parent=y;
	if(y==NIL) root=z;
	else {
		if(z->num < y->num) y->left=z;
		else y->right=z;
	}
	return ;
}

int main(){
	int n;
	cin>>n;
	string s;
	node *f;
	int a;
	for(int i=0;i<n;i++){
		cin>>s;
		if(s[0]=='i') cin>>a,insert(a);
		else if(s[0]=='p'){
			print_inorder(root);
			printf("\n");
			print_preorder(root);
			printf("\n");
		}
		else if(s[0]=='f'){
			cin>>a;
			f=find(a);
			if(f==NIL) printf("no\n");
			else printf("yes\n");
		}
		else{
			cin>>a;
			denode(find(a));
		}
	}
	return 0;
}


Measured memory_bytes: 21840
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <vector>
#define REP(i, n) for(int i = 0; i < (n); ++i)
typedef long long ll;
const ll MOD = 1000000007;
using namespace std;

int main(){
    string s; cin >> s;
    int n = s.length(); n /= 2;
    for(int i = n-1; i; --i){
        if(s.substr(0, i) == s.substr(i, i)){
            cout << 2 * i << endl;
            return 0;
        }
    }
    return 0;
}

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

ll g(ll n) { return n * (n + 1) / 2; }

int main() {
  ll n;
  cin >> n;
  ll ans = 0;
  rep2(i, 1, n + 1) {
    ll r = n / i;
    ans += i * g(r);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3592
def check(d, x):
    x = str(x)
    for xx in x:
        if int(xx) not in d:
            return False
    return True
    
n, k = map(int, input().split())
d = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9} ^ set(map(int, input().split()))

i = n
while 1:
    if check(d, i):
        break
    i += 1
print(i)


Measured memory_bytes: 2940
w = gets.chomp.to_i
n = gets.chomp.to_i
result = [*(1..w)]

n.times do
  swap = gets.chomp.split(',')
  result[swap[0].to_i-1], result[swap[1].to_i-1] = result[swap[1].to_i-1], result[swap[0].to_i-1]
end

puts result


Measured memory_bytes: 6844
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <numeric>
#include <cmath>

#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
using P = pair<ll, ll>;

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

const ll MOD = 1000000007;
const int INF = 1<<30;
//const ll INF = (ll)1e18 + 1;

int main(){
  int N, M, C; cin >> N >> M >> C;
  vector<int> b(M);
  rep(i, M) cin >> b[i];
  vector<vector<int>> a(N, vector<int>(M));
  rep(i, N) rep(j, M) cin >> a[i][j];

  int ans = 0;
  rep(i, N){
    int sum = 0;
    rep(j, M) sum += a[i][j] * b[j];
    sum += C;
    if (sum > 0) ans++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#ifdef ENABLE_DEBUG
#define dump(a) cerr<<#a<<"="<<a<<endl
#define dumparr(a,n) cerr<<#a<<"["<<n<<"]="<<a[n]<<endl
#else
#define dump(a) 
#define dumparr(a,n) 
#endif
#define FOR(i, a, b) for(int i = a;i < b;i++)
#define For(i, a) FOR(i, 0, a)
#define REV(i, a, b) for(int i = b-1;i >= a;i--)
#define Rev(i, a) REV(i, 0, a)
#define REP(a) For(i, a)

typedef long long int ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef pair<ll, ll> pll;
typedef pair<ll,pll> ppll;
typedef vector<ll> vll;

const ll INF=(1LL<<50);

deque<ll> stones;
void solve(long long N, std::string S){
    char prev='b';
    int n=0;
    for (auto &&i : S)
    {
        if(i==prev){
            n++;
        }else{
            prev=i;
            if(n!=0)stones.push_back(n);
            n=1;
        }
    }
    if(n!=0)stones.push_back(n);
    
    if(S[0]=='.')stones.pop_front();
    if(S.back()=='#')stones.pop_back();
    ll l=0,r=0;
    for(long long i = 1; i < stones.size(); i+=2){
        r+=stones[i];
    }
    dump(r);
    ll ans=l+r;
    for(long long i = 0; i < stones.size(); i+=2){
        l+=stones[i];
        r-=stones[i+1];
        ans=min(ans,l+r);
    }
    cout<<ans<<endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    std::string S;
    std::cin >> S;
    solve(N, S);
    return 0;
}


Measured memory_bytes: 2308
#include <iostream>
#include <string.h>
#include <iomanip>
using namespace std;
int main(){
  char input[64];
  cin >> setw(sizeof(input)) >> input;

  char day[64];
  strncpy(day, input+8, 2);
  day[3] = '\0';

  cout << "2018/01/" << day << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip>
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define fi first
#define se second
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
typedef pair<int,int> P;
//小数点以下　cout << fixed << setprecision(10) << num << endl;
//桁数はlog10(mid)でやれ　log(mid)/log(10)はWA

int main(){
    int h,w; cin >> h >> w;
    char a[h][w];
    int res=0;
    queue<P> q1;
    queue<P> q2;
    rep(i,h){
        rep(j,w){
            cin >> a[i][j];
            if(a[i][j]=='#'){
                q1.push({i,j});
                res++;
            }
        }
    }
    int ans=0;
    int dy[4]={0,1,0,-1};
    int dx[4]={1,0,-1,0};
    while(res!=h*w){
        ans++;
        while(!q1.empty()){
            P d=q1.front(); q1.pop();
            rep(i,4){
                int ny=d.fi+dy[i]; int nx=d.se+dx[i];
                if(0<=ny && ny<h && 0<=nx && nx<w && a[ny][nx]=='.'){
                    res++;
                    a[ny][nx]='#';
                    q2.push({ny,nx});
                }
            }
        }
        if(res==h*w) break;
        ans++;
        while(!q2.empty()){
            P d=q2.front(); q2.pop();
            rep(i,4){
                int ny=d.fi+dy[i]; int nx=d.se+dx[i];
                if(0<=ny && ny<h && 0<=nx && nx<w && a[ny][nx]=='.'){
                    res++;
                    a[ny][nx]='#';
                    q1.push({ny,nx});
                }
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 9360
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<ll> VI;
typedef vector<VI> VVI;
const ll MOD = 1000000007;
const ll INF = 2147483647;
const ll LLINF = 9223372036854775807;
#define REP(i, n) for(int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()

int main() {
	int n; cin >> n;
	VI a(n); REP(i, n)cin >> a[i];
	sort(ALL(a));
	cout << a[n - 1] - a[0];
}

Measured memory_bytes: 256
# coding: utf-8
# Your code here!
k = int(input())
count = 0
ans = []
minN = 10**15

for i in reversed(range(13)):
    minN = 10**15
    for j in reversed(range(1,10**3)):
        num = str(j)+"9"*i
        n = sum([int(k) for k in num])
        n = int(num)/n
        if(minN > n or n==1):
            minN = n
            ans.append(int(num))

for i in list(sorted(list(set(ans))))[:k]:
    print(i)

Measured memory_bytes: 3188
import sys
# import math
# import bisect
# import numpy as np
# from decimal import Decimal
# from numba import njit, i8, u1, b1 #JIT compiler
# from itertools import combinations, product
# from collections import Counter, deque, defaultdict

# sys.setrecursionlimit(10 ** 6)
MOD = 10 ** 9 + 7
INF = 10 ** 9
PI = 3.14159265358979323846

def read_str():      return sys.stdin.readline().strip()
def read_int():      return int(sys.stdin.readline().strip())
def read_ints():     return map(int, sys.stdin.readline().strip().split())
def read_ints2(x):   return map(lambda num: int(num) - x, sys.stdin.readline().strip().split())
def read_str_list(): return list(sys.stdin.readline().strip().split())
def read_int_list(): return list(map(int, sys.stdin.readline().strip().split()))
def GCD(a: int, b: int) -> int: return b if a%b==0 else GCD(b, a%b)
def LCM(a: int, b: int) -> int: return (a * b) // GCD(a, b)

def f(n):
    if n <= 2:
        return n
    return f(n - 2) * n

def Main():
    n = read_int()
    if n % 2:
        print(0)
        sys.exit()

    ans = 0
    n //= 2
    while n >= 5:
        n //= 5
        ans += n
    print(ans)

if __name__ == '__main__':
    Main()

Measured memory_bytes: 9192
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef long double ld;
const ll MAX = 200000;
const ll MOD = 1000000007;
ll k, n;
//string s;

int main() {
    cin >> n >> k;
    ld m = 0.0;
    ld mmax = 0.0;
    ll s[n];
    for(ll i=0;i<n;i++){
        ll p;
        cin >> p;
        s[i] = p+1;
        if(i<k){
            m += p+1;
            mmax += p+1;
        }else{
            m += p+1;
            m -= s[i-k];
            mmax = max(m,mmax);
        }
    }
    cout << setprecision(10) << mmax/2.0 << endl;
    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
REP(i,v.size()){if(i)os<<" ";os<<v[i];}return os;}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
REP(i,v.size()){if(i)os<<endl;os<<v[i];}return os;}

int main() {
    ll a,b,c;cin>>a>>b>>c;
    if(a+b+c>=22){
                  cout<<"bust"<<endl;
                  }
    else{
         cout<<"win"<<endl;
         }
         

}



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

#define all(x)  x.begin(), x.end()
#define mp      make_pair
#define pii     pair<int, int>
#define pll     pair<long long, long long>
#define ll      long long

int dp[3030][3030];

int main() {
        int a, b, c, d, e, f;
        cin >> a >> b >> c >> d >> e >> f;
        dp[0][0] = 1;
        for (int i = 0; i <= f; i ++) {
                for (int j = 0; j <= i; j ++) {
                        if (!dp[i][j]) continue;
                        if (i + a * 100 <= f) dp[i + a * 100][j] = 1;
                        if (i + b * 100 <= f) dp[i + b * 100][j] = 1;
                        if (i + c <= f) dp[i + c][j + c] = 1;
                        if (i + d <= f) dp[i + d][j + d] = 1;
                }
        }
        int w = 100 * a, s = 0;
        for (int i = 1; i <= f; i ++) {
                for (int j = 0; j <= i; j ++) {
                        if (dp[i][j] && e * i >= (e + 100) * j) {
                                if (j * w >= i * s) {
                                        w = i;
                                        s = j;
                                }
                        }
                }
        }
        cout << w << ' ' << s << endl;
        return 0;
}


Measured memory_bytes: 33536
import java.util.*;
import java.io.*;
import static java.lang.System.*;

class FastScanner {
  private final InputStream in = System.in;
  private final byte[] buffer = new byte[1024];
  private int ptr = 0;
  private int buflen = 0;
  private boolean hasNextByte() {
      if (ptr < buflen) {
          return true;
      }else{
          ptr = 0;
          try {
              buflen = in.read(buffer);
          } catch (IOException e) {
              e.printStackTrace();
          }
          if (buflen <= 0) {
              return false;
          }
      }
      return true;
  }
  private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
  private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
  public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
  public String next() {
      if (!hasNext()) throw new NoSuchElementException();
      StringBuilder sb = new StringBuilder();
      int b = readByte();
      while(isPrintableChar(b)) {
          sb.appendCodePoint(b);
          b = readByte();
      }
      return sb.toString();
  }
  public long nextLong() {
      if (!hasNext()) throw new NoSuchElementException();
      long n = 0;
      boolean minus = false;
      int b = readByte();
      if (b == '-') {
          minus = true;
          b = readByte();
      }
      if (b < '0' || '9' < b) {
          throw new NumberFormatException();
      }
      while(true){
          if ('0' <= b && b <= '9') {
              n *= 10;
              n += b - '0';
          }else if(b == -1 || !isPrintableChar(b)){
              return minus ? -n : n;
          }else{
              throw new NumberFormatException();
          }
          b = readByte();
      }
  }
  public int nextInt() {
      long nl = nextLong();
      if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
      return (int) nl;
  }
  public double nextDouble() { return Double.parseDouble(next());}
}

class Main {
  public static final int MOD = 1000000007;
  public static final int INF = 1000000000;
  public static void main(String[] args) {
    FastScanner sc = new FastScanner();
    int N = sc.nextInt();
    int A[] = new int[N];
    for(int i=0; i<N; i++) A[i] = sc.nextInt() - 1;
    int B[] = new int[N];
    for(int i=0; i<N; i++) B[i] = sc.nextInt();
    int C[] = new int[N-1];
    for(int i=0; i<N-1; i++) C[i] = sc.nextInt();
    int ans = 0;
    for(int i=0; i<N-1; i++){
      ans += B[A[i]];
      if(A[i] + 1 == A[i+1]) ans += C[A[i]];
    }
    ans += B[A[N-1]];
    out.println(ans);
  }
}

Measured memory_bytes: 22356
n, m ,l = map(int, input().split())
A, B = [], []
C = [[0]*l for i in range(n)]
for i in range(n):
    A.append(list(map(int, input().split())))
for i in range(m):
    B.append(list(map(int, input().split())))
for i in range(n):
    for j in range(l):
        temp = 0
        for k in range(m):
            temp += A[i][k] * B[k][j]
        C[i][j] = temp
for i in range(n):
    print(' '.join(str(x) for x in C[i]))


Measured memory_bytes: 6904