akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<queue>
#include<stack>
#include<cmath>

using namespace std;

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

	for (int i = 0; i < 30 && 0 <= N; ++i) {
		if (N % 7 == 0) {
			cout << "Yes" << endl;
			return 0;
		}
		N -= 4;
	}

	cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
 
public class Main {
 
	public static void main(String args[]){
		
		Scanner cin = new Scanner(System.in);
		
		String A = cin.next();
		int lenA = A.length();
		String B = cin.next();
		int lenB = B.length();
		String C = cin.next();
		
		String result = "YES";
		
		if(A.charAt(lenA-1)==B.charAt(0)&&B.charAt(lenB-1)==C.charAt(0)){
			
		}else{
			result = "NO";
		}
		
		System.out.println(result);
	}
}

Measured memory_bytes: 22100
#include <bits/stdc++.h>
//#pragma GCC optimize(2)
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<cmath>
#include<cstring>
#include<bitset>
#include<stack>
#include<time.h>



#define X first
#define Y second
#define PB push_back
#define MP make_pair
#define scd(a) scanf("%d",&a)
#define scdd(a,b) scanf("%d%d",&a,&b)
#define scddd(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define ALL(x) x.begin(),x.end()
#define sz(a) ((int)a.size())
#define getmid ((l+r)>>1)
#define mst(var,val) memset(var,val,sizeof(var))
#define IOS ios::sync_with_stdio(false);cin.tie(0)
#define lowbit(x) x&(-x)
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define ls rt<<1
#define rs rt<<1|1
using namespace std;
#ifdef local
#define dbg(args...) cout << #args << " -> ", err(args);
void err(){ cout << endl; }
template<typename T, typename... Args>
void err(T a, Args... args){ cout << a << ' '; err(args...); }
#else
#define dbg(args...)
#endif // local

typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <double, double> pdd;
const int inf=0x3f3f3f3f;
const long long INF=0x3f3f3f3f3f3f3f3fLL;
const double PI=acos(-1.0);
const long double eps=1e-8;
const int mod=1e9+7;
const int maxn=3e5+100;
const int N=1e6+1000;
const int M=500+10;
const ll mm=(1LL<<32);

template <class T>
inline void read(T &x)
{
    x = 0;
    char c = getchar();
    bool f = 0;
    for (; !isdigit(c); c = getchar())
        f ^= c == '-';
    for (; isdigit(c); c = getchar())
        x = x * 10 + (c ^ 48);
    x = f ? -x : x;
}

template <class T>
inline void write(T x)
{
    if (x < 0)
    {
        putchar('-');
        x = -x;
    }
    T y = 1;
    int len = 1;
    for (; y <= x / 10; y *= 10)
        ++len;
    for (; len; --len, x %= y, y /= 10)
        putchar(x / y + 48);
}
ll qpow(ll a,ll b,ll mod)
{
    ll ans=1;
    while(b)
    {
        if(b&1)
            ans=(ans*a)%mod;
        b>>=1;
        a=(a*a)%mod;
    }
    return ans;
}


int main()
{
#ifdef local
    freopen("in.txt","r",stdin);
#endif // local
    IOS;cout.tie(0);
    string s,t;cin>>s>>t;
    int n=sz(s),m=sz(t);
    int ans=inf;
    for(int i=0;i<=n-m;++i)
    {
        int tmp=0,l=i,r=i+m-1;
        for(int j=l;j<=r;++j)
        {
            if(s[j]!=t[j-i]) tmp++;
        }
        ans=min(ans,tmp);
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 3632
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <set>

using namespace std;
#define MAXN 200000
#define ll long long
#define INFLL 0x3f3f3f3f3f3f3f3fll
#define rint register int
#define gc() getchar()
inline int read(rint ans = 0, rint sgn = ' ', rint ch = gc())
{
	for(; ch < '0' || ch > '9'; sgn = ch, ch = gc());
	for(; ch >='0' && ch <='9';(ans*=10)+=ch-'0', ch = gc());
	return sgn-'-'?ans:-ans;
}
#define BUF_SIZE 1000000
#define _END fwrite(_Ob,1,_O-_Ob,stdout), _O = _Ob
#define Outc(a) (*_O++ = a)
char _Ob[BUF_SIZE+5], *_O = _Ob, _Os[25], *_Ot;
template <typename T> inline void Out(T x)
{
	if(!x){Outc('0'); return;} if(x < 0) Outc('-'), x = -x;
	for(_Ot = _Os; x; *_Ot++ = x%10+'0', x /= 10);
	for(; _Ot != _Os; Outc(*--_Ot)); if(_O-_Ob >= BUF_SIZE-50) _END;
}
int n, q, a[MAXN+5], b[MAXN+5]; multiset<int> Pos, Neg; multiset<int>::iterator it; ll base, sum;
int main()
{
	n = read()<<1, q = read(); for(rint i = 1; i <= n; base += (a[i++]=read())); for(rint i = 1; i <= n; b[i++] = read());
	for(rint i = 2; i < n; b[i]>=a[i] ? sum += b[i]-a[i], Pos.insert(b[i]-a[i]) : Neg.insert(b[i]-a[i]), i++);
	for(rint p; q--; Out(base+(Pos.size()&1?max(sum+(Neg.size()?*--Neg.end():INFLL),sum-*Pos.begin()):sum)), Outc('\n'))
	{
		p = read(), base -= a[p], p>1&&p<n ? it = (b[p]>=a[p] ? sum -= b[p]-a[p], Pos.find(b[p]-a[p]) : Neg.find(b[p]-a[p])), (b[p]>=a[p]?Pos:Neg).erase(it),0 : 0;
		a[p] = read(), b[p] = read(), base += a[p], p>1&&p<n ? b[p]>=a[p] ? sum += b[p]-a[p], Pos.insert(b[p]-a[p]) : Neg.insert(b[p]-a[p]),0 : 0;
	}	_END; return 0;
}

Measured memory_bytes: 13568
N, M, K= map(int, input().split())
A=list(map(int, input().split()))
B=list(map(int, input().split()))

Asum=[0]
Bsum=[0]

for i in range(N):
    Asum.append(Asum[-1]+A[i])
        
for i in range(M):
    Bsum.append(Bsum[-1]+B[i])
    
m=0
j=M

for i in range(len(Asum)):
    if Asum[i]>K:
        break
    while Asum[i]+Bsum[j]>K:
        j-=1
    if m<i+j:
        m=i+j
        
print(m)

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

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, x;
	cin >> n >> x;
	vector<int> m(n);
	rep(i, n) cin >> m[i];
	sort(m.begin(), m.end());
	int res = 0;
	rep(i,n) res += m[i];
	int ans = n;
	int res2 = x - res;
	bool elf = true;
	while (elf) {
		rep(i, n) {
			if (res2 - m[i] >= 0) {
				res2 -= m[i];
				ans++;
			}
			else elf = false; break;
		}
	}
	cout << ans << endl;
	return 0;
}

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


int main(){
	int M[2],D[2];
	cin >> M[0] >> D[0] >> M[1] >> D[1];
	
	if(M[0] != M[1]){
		cout << "1" << endl;
	}
	else{
		cout << "0" << endl;
	}

	return 0;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9 + 7
input = sys.stdin.readline

def inp():
    return int(input())
def inpl():
    return list(map(int,input().split()))
def inpm():
    return map(int,input().split())

a,b,c,k = inpm()

print(min(min(k,a),2*a+b-k))


Measured memory_bytes: 9068
import java.util.*;

public class Main {

  public static void main (String[] args) {

    Scanner sc = new Scanner(System.in);
    
    int N = sc.nextInt();
    
    int[] H = new int[N];

    for (int i = 0; i < N; i++) {
      H[i] = sc.nextInt();
    }

    sc.close();

    for (int i = N-2; 0 <= i; i--) {

      if (H[i] > H[i+1]) {
        if (H[i] - H[i+1] == 1) {
          H[i]--;
        } else {
          System.out.println("No");
          return;
        }
      }
    }

    System.out.println("Yes");
    
  }

}

Measured memory_bytes: 48768
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main{
	public static void main(String[] args) throws IOException {
		try (BufferedReader br = new BufferedReader(
				new InputStreamReader(System.in))) {

			String in = br.readLine();
			String chr[] = in.split(" ");
			int a = Integer.parseInt(chr[0]);
			int p = Integer.parseInt(chr[1]);

			 System.out.println((a*3+p)/2);
		}
	}
}

Measured memory_bytes: 25236
#include <iostream>
#include <string>
#include <vector>
#include <numeric>
#include <algorithm>
#include <set>
#include <cmath>
#include <iomanip>
#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 FORR(i, m, n) for(int i=m; i>=n; i--)
#define INF 999999999
#define ll long long
#define VSORT(v) sort(v.begin(), v.end())
#define pb(a) push_back(a)
using namespace std;

#ifdef INPUT
#include <sstream>
stringstream input(R"(
5 7
)");
#define cin input
#endif

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

	cout << (a-1)*(b-1) << endl;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import re

s = input()
s = s.replace('BC', 'D')

ans = 0
num_a = 0
for char in s:
    if char == 'A':
        num_a += 1
    elif char == 'D':
        ans += num_a
    else:
        num_a = 0

print(ans)

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

int read()
{
	int ans=0;
	char ch=getchar();
	for(;(ch<'0' || ch>'9') && ch!='-';ch=getchar());
	bool flag=false;
	if(ch=='-')
	{
		flag=true;
		ch=getchar();
	}
	for(;ch>='0' && ch<='9';ch=getchar())ans=ans*10+ch-'0';
	return flag?-ans:ans;
}

long long rell()
{
	long long ans=0;
	char ch=getchar();
	for(;(ch<'0' || ch>'9') && ch!='-';ch=getchar());
	bool flag=false;
	if(ch=='-')
	{
		flag=true;
		ch=getchar();
	}
	for(;ch>='0' && ch<='9';ch=getchar())ans=ans*10ll+(long long)(ch-'0');
	return flag?-ans:ans;
}

void write(int a)
{
	if(!a)
	{
		putchar('0');
		return;
	}
	static char ans[233];
	int n=0;
	for(;a;a/=10)ans[n++]=a%10+'0';
	for(;n;)putchar(ans[--n]);
}

void write(long long a)
{
	if(!a)
	{
		putchar('0');
		return;
	}
	static char ans[233];
	int n=0;
	for(;a;a/=10)ans[n++]=a%10+'0';
	for(;n;)putchar(ans[--n]);
}
int x[2333],y[2333],c[2333],d[2333],a[2333],b[2333];
bool flag[2333];

bool cmp(int i,int j)
{
	return x[i]>x[j];
}

int main()
{
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	{
		scanf("%d%d",&x[i],&y[i]);
		c[i]=i;
	}
	sort(c,c+n,cmp);
	for(int i=0;i<n;i++)
	{
		scanf("%d%d",a+i,b+i);
	}
	int ans=0;
	memset(flag,true,sizeof(flag));
	for(int i=0;i<n;i++)
	{
		int k=-1;
		for(int j=0;j<n;j++)if(flag[j] && a[j]>x[c[i]] && b[j]>y[c[i]])
		{
			if(k==-1 || b[j]<b[k])k=j;
		}
		if(k!=-1)
		{
			ans++;
			flag[k]=false;
		}
	}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 256
N, K = list(map(int, input().split()))
h = list()
for i in range(N):
    h.append(int(input()))

h.sort()

ans_l = list()
for i in range(N-K+1):
    ans_l.append(h[i+K-1]- h[i])

print(min(ans_l))

Measured memory_bytes: 17092
#include<iostream>
#include<stdio.h>
#define DROP(x,y) if(x>=0&&y>=0&&x<10&&y<10)++cloth[x][y]
using namespace std;

int main(){

	int x, y, size;
	int cloth[10][10];
	int count, max;
	
	for (int i = 0; i < 10; ++i)
	for (int j = 0; j < 10; ++j)
		cloth[i][j] = 0;

	while (scanf("%d,%d,%d", &x, &y, &size) + 1){
		if (size == 1){
			DROP(x, y);
			DROP(x + 1, y);
			DROP(x, y + 1);
			DROP(x - 1, y);
			DROP(x, y - 1);
		}

		else if (size == 2){
			DROP(x, y);
			DROP(x, y - 1);
			DROP(x, y + 1);
			DROP(x - 1, y - 1);
			DROP(x - 1, y);
			DROP(x - 1, y + 1);
			DROP(x + 1, y - 1);
			DROP(x + 1, y);
			DROP(x + 1, y + 1);
		}

		else if (size == 3){
			DROP(x, y);
			DROP(x, y - 1);
			DROP(x, y + 1);
			DROP(x - 1, y - 1);
			DROP(x - 1, y);
			DROP(x - 1, y + 1);
			DROP(x + 1, y - 1);
			DROP(x + 1, y);
			DROP(x + 1, y + 1);
			DROP(x + 2, y);
			DROP(x - 2, y);
			DROP(x, y + 2);
			DROP(x, y - 2);
		}
	}

	for (int i = 0; i < 10; ++i)
	for (int j = 0; j < 10; ++j){
		if (cloth[i][j] == 0)++count;
		if (cloth[i][j] > max)max = cloth[i][j];
	}

	cout << count << endl << max << endl;

	



}

Measured memory_bytes: 1208
#include <iostream>
#include <vector>
#include <string>
#include <math.h>
#include <algorithm>
#include <set>
#include <iomanip>
#include <stdio.h>
#include <sstream>
#include <bits/stdc++.h>
using namespace std;
  vector<int> c;
  vector<int> s;
  vector<int> f;
  long long int n;
void saiki(int now,int t){
  if(now==n-1){
    cout<<t<<endl;
    return;
  }
  if(t<s.at(now)){
    saiki(now+1,s.at(now)+c.at(now));
  }else{
    while(true){
      if(t%f.at(now)==0) break;
      t++;
    }
    saiki(now+1,t+c.at(now));
  }
}
int main(void){
  cin>>n;
  c.resize(n-1);
  s.resize(n-1);
  f.resize(n-1);
  for (int i = 0; i < n-1; i++)
  {
    cin>>c.at(i)>>s.at(i)>>f.at(i);
  }
  
  for(int i=0; i<n; i++){
    saiki(i,0);
  }
}

Measured memory_bytes: 384
#include <vector>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>
#include <ctime>
#include <map>
#include <stack>
#include <sstream>
#include <set>
#include <cmath>
#include <functional>
#include <memory.h>

// pi = atan(1)*4;

#define INTMAX 2100000000
const int Mod = 100000007;

using namespace std;

int main(void)
{
	vector <string> grid;
	string t;

	for (int i = 0; i < 2; i++)
	{
		cin >> t;
		grid.push_back(t);
	}

	if (grid[0][2] != grid[1][0])
	{
		cout << "NO" << endl;
	}
	else if (grid[0][1] != grid[1][1])
	{
		cout << "NO" << endl;
	}
	else if (grid[0][0] != grid[1][2])
	{
		cout << "NO" << endl;
	}
	else
	{
		cout << "YES" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
K,N=map(int,input().split())

A = list(map(int,input().split()))
# 家どうしの距離
dis = [A[i+1] - A[i] for i in range(N-1)]
dis.append(A[0]+K-A[N-1])
# 家どうしの距離が最長になるものを選んで，それをKから引く[
print(K-max(dis))


Measured memory_bytes: 26420
#include <bits/stdc++.h>
using namespace std;
void factorization(long long n,map<long long ,long long>& mp){
    for(int i=2;i<=sqrt(n);i++){
        while(n%i==0){
            mp[i]++;
            n/=i;
        }

    }
    if(!(n==1))mp[n]++;
}
int main() {
    long long n;
    cin >> n;
map<long long,long long> factor;
for(int k=1;k<=n;k++){
factorization(k,factor);
}
long long ans=1;
for(auto i:factor){
    ans*=(i.second+1);
    ans%=1000000007;
}
cout << ans << endl;
}


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

using namespace std;
int main() {
	int N;
	cin >> N;
	long long ans = 0;
	long long nowmax = 0;
	for (int i = 0; i < N; ++i) {
		long long num;
		cin >> num;
		if (num < nowmax) {
			ans += (nowmax - num);
		}
		else {
			nowmax = num;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3616
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define all(x) x.begin(), x.end()
#define pb(x) push_back(x)
#define INF 1000000000000000000
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define x first 
#define y second
const int maxx = 1000006;
const int maxlog = 20;
const ll mod = 1000000007;

int main() {
    IOS
    int N;
    cin >> N;
    ll arr[N];
    ll brr[N];
    ll sum = 0;
    for (int i = 0; i < N; i++) {
        cin >> arr[i];
        brr[i] = arr[i];
    }
    for (int i = N - 2; i >= 0; i--) brr[i] += brr[i + 1];
    for (int i = 0; i < N - 1; i++) sum += arr[i] * brr[i + 1];
    cout << sum;
}


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

dist = A[0]
visited = {1}
_v = [1]
stop = 0
while True:
    if dist in visited:
        stop = dist
        break
    visited.add(dist)
    _v.append(dist)
    dist = A[dist-1]

made = 0
l = len(_v)
for i in range(l):
    if _v[i] == stop:
        break
    made += 1

# print(stop)
# print(loop)
# print(made)
# print(_v)

if K <= made:
    print(_v[K])
else:
    loop = l - made
    _v = _v[made:]
    K -= made
    K %= loop
    print(_v[K])

Measured memory_bytes: 125100
#include <iostream>
using namespace std;
 
void divStr(const string& s, string& s1, string& s2) {
  int n = s.size();
  int retain = 0;
  for(int pos=1; ; pos++) {
    if(s[pos] == '(') retain++;
    if(s[pos] == ')') retain--;
    else if(retain == 0) {
      s1 = s.substr(1, pos-1);
      s2 = s.substr(pos+1, n-pos-2);
      return;
    }
  }
}
 
string make(string op, string s, string t) {
  if(s == "" || t == "") {
    if(op == "i") return "";
    else return s == "" ? t : s;
  }
 
  string sL, sR, tL, tR;
  divStr(s, sL, sR);
  divStr(t, tL, tR);
 
  return '(' + make(op, sL, tL) + ',' + make(op, sR, tR) + ')';
}
 
int main() {
  string op, sL, sR;
 
  while(cin >> op >> sL >> sR)
    cout << make(op, sL, sR) << endl;
 
  return 0;
}

Measured memory_bytes: 1200
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iostream>
#include <iterator>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define FOR(i,k,n) for(int(i)=(k);(i)<(n);++(i))
#define rep(i,n) FOR(i,0,n)
#define all(v) begin(v),end(v)
#define debug(x) std::cerr<<#x<<": "<<x<<"\n"
#define debug2(x,y) std::cerr<<#x<<": "<<x<<", "<<#y<<": "<<y<<"\n"
#define debug3(x,y,z) std::cerr<<#x<<": "<<x<<", "<<#y<<": "<<y<<", "<<#z<<": "<<z<<"\n"

using ll=long long;
using vi=std::vector<int>;
using vvi=std::vector<vi>;
using vll=std::vector<ll>;
using vvll=std::vector<vll>;
template<typename T> using vvec=std::vector<std::vector<T>>;
template<typename T>
auto make_v(size_t sz){return std::vector<T>(sz);}
template<typename T,typename... Ts>
auto make_v(size_t sz,Ts...ts){return std::vector<decltype(make_v<T>(ts...))>(sz,make_v<T>(ts...));}
template<typename T>
void fill_v(T&var,const T&x){var=x;}
template<typename V,typename T>
void fill_v(V&v,const T&x){for(auto&& w:v){fill_v(w,x);}}

template<typename T> std::ostream& operator<<(std::ostream&s,const std::vector<T>&v){
  int sz=v.size();s<<"\n";rep(i,sz){s<<v[i];if(i<sz-1){s<<"\t";}}s<<"\n";return s;}
template<typename T> std::ostream& operator<<(std::ostream&s,const std::vector<std::vector<T>>&v){
  for(auto&& w:v){s<<w;}return s;}
template<typename T> std::ostream& operator<<(std::ostream&s,const std::deque<T>&v){
  int sz=v.size();s<<"\n";rep(i,sz){s<<v[i];if(i<sz-1){s<<"\t";}}s<<"\n";return s;}
template<typename T> std::ostream& operator<<(std::ostream&s,const std::deque<std::deque<T>>&v){
  for(auto&& w:v){s<<w;}return s;}
template<typename T> std::ostream& operator<<(std::ostream&s, const std::set<T>&v){
  s<<"\n";for(auto&& elm:v){s<<elm<<"\t";}s<<"\n";return s;}

inline void scan(int&a){scanf("%d",&a);}
inline void scan(ll&a){scanf("%lld",&a);}
inline void scan(char&a){scanf(" %c",&a);}
inline void scan(double&a){scanf("%lf",&a);}
inline void scan(std::string&s){char BUF[3000000];scanf(" %s",BUF);s=std::string(BUF);}
template<typename T>
inline void scan(std::vector<T>&v){for(auto&& sv:v){scan(sv);}}
template<typename First,typename...Args>
inline void scan(First&f,Args&...args){scan(f);scan(args...);}
inline void print(int a){printf("%d\n",a);}
inline void print(ll a){printf("%lld\n",a);}
inline void print(double a){printf("%.12f\n",a);}
inline void print(std::string s){std::cout<<s<<"\n";}

using namespace std;

int mod = 1000000007;
int main() {
  string s;
  scan(s);
  int n = s.length();
  reverse(all(s));
  vll leq(n+1, 0);
  leq[0] = 1;
  vll gt(n+1, 0);
  rep (i, n) {
    if (s[i] == '0') {
      leq[i+1] = (leq[i+1] + leq[i]) % mod;
      gt[i+1] = (gt[i+1] + leq[i] * 2 + gt[i] * 3) % mod;
    } else {
      leq[i+1] = (leq[i+1] + leq[i] * 3 + gt[i]) % mod;
      gt[i+1] = (gt[i+1] + gt[i] * 2) % mod;
    }
  }
  print(leq[n]);

  return 0;
}


Measured memory_bytes: 4096
#include <cstdio>
#include <map>
#include <utility>
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)

using ll = long long;
using P = std::pair<int, int>;

int H, W, N;
std::map<P, ll> m;
ll cnt[10];

int main()
{
  scanf( "%d%d%d", &H, &W, &N );
  rep( i, N )
  {
    int a, b;
    scanf( "%d%d", &a, &b );

    for( int j = -1; j <= 1; ++j ) for( int k = -1; k <= 1; ++k ) if( a+j >= 2 && a+j <= H-1 && b+k >= 2 && b+k <= W-1 )
      ++m[P(a+j,b+k)];
  }

  for( auto it = m.begin(); it != m.end(); ++it )
    ++cnt[it->second];
    
  cnt[0] = (ll)(H-2)*(W-2);
  repi( i, 1, 10 )
    cnt[0] -= cnt[i];

  rep( i, 10 )
    printf( "%lld\n", cnt[i] );

  return 0;
}

Measured memory_bytes: 56448
#include<iostream>
#include<deque>
using namespace std;
const int INF=1000000009;
int n,d[100005];
int main()
{
	int n;
	cin>>n;
	for(int i=0;i<n;i++)
	    d[i]=INF;
	deque <int> q;
	d[1]=1;
    q.push_back(d[1]);
    while(q.size())
    {
    	int u=q.front();
    	q.pop_front();
    	int a=(u*10)%n;
    	if(d[a]>d[u])
    	{
    		q.push_front(a);
    		d[a]=d[u];
		}
		int b=(u+1)%n;
		if(d[b]>d[u]+1)
		{
			q.push_back(b);
			d[b]=d[u]+1;
		}
	}
	cout<<d[0];
	return 0;
}

Measured memory_bytes: 896
#include <map>
#include <queue>
#include <cmath>
#include <ctime>
#include <vector>
#include <cstdio>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <tr1/unordered_map>
#define mo 1000000007
#define num(x) (x>='0' && x<='9')
typedef unsigned long long ull;
typedef long long ll;
using namespace std::tr1;
using namespace std;
int read(){
    int p=0, q=1;
    char ch=getchar();
    while (!num(ch))
        (ch=='-'?q=-1:0),
        ch=getchar();
    while (num(ch)) p=p*10+ch-'0', ch=getchar();
    return p*q;
}
int power(ll a, int b){
	ll c=1;
	while (b){
		if (b&1) c=c*a%mo;
		a=a*a%mo;
		b>>=1;
	}
	return c;
}
void add(int &a, int b){
	a+=b;
	if (a>=mo) a-=mo;
}
int f[2004];
int main(){
	int s=read();
	int ans=0;
	for (int i=1;i<=s/3;i++){
		int m=s-i*3;
		f[0]=1;
		for (int k=1;k<=m;k++) f[k]=0;
		for (int j=1;j<=i;j++)
			for (int k=1;k<=m;k++)
				add(f[k],f[k-1]);
		add(ans,f[m]);
	}
	cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
int len,score;
char s[100005];
int main()
{
    cin>>s;
    len=strlen(s);
    for(register int i=0;i<len;i++)
    {
        if(i%2==0)
        {
            if(s[i]=='p')
                score--;
        }
        else
            if(s[i]=='g')
                score++;
    }
    printf("%d\n",score);
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define printVec(v) printf("{"); for (const auto& i : v) { std::cout << i << ", "; } printf("}\n");
#define degreeToRadian(deg) (((deg)/360)*2*M_PI)
#define radianTodegree(rad) (((rad)/2/M_PI)*360)
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; }
using namespace std;
using P = pair<int,int>;
using ll = long long;
const ll INF = 1LL<<60;
const int MOD = 1e9 + 7;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//cin.tie(0);ios::sync_with_stdio(false);
//cout << fixed << setprecision(15) << y << endl;
int main() {
  int n; cin >> n;
  vector<int> a(n);
  rep (i, n) cin >> a[i];

  bool ok = true;
  for (int i = 0; i < n - 1; i++) {
    if (a[i] <= a[i + 1]) continue;
    else if (a[i] == ++a[i + 1]) continue;
    else ok = false;
  }

  if (ok) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


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


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

	sort(s.begin(), s.end());
	sort(t.begin(), t.end());
	reverse(t.begin(), t.end());

	if (s<t)
	{
		cout << "Yes" << endl;
	}
	else
	{
		cout << "No" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
while True:
	flag = 0
	line = input().split()
	h = int(line[0])
	w = int(line[1])
	
	if h == 0 and w == 0:
		break
	
	for i in range(h):
		if i % 2 == 0:
			for j in range(w):
				if(j%2==0):
					print("#",end='')
				else:
					print(".",end='')
		else:
			for j in range(w):
				if(j%2==0):
					print(".",end='')
				else:
					print("#",end='')
		print()
	print()


Measured memory_bytes: 7008
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashSet;

class Main {
	public static void main(String args[]) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		Solver solver = new Solver();
		solver.init();
		solver.readHead(in.readLine());
		// for (; solver.hasNext();) {
		// solver.readBody(in.readLine());
		// }
	}
}

class Solver {
	int N;
	int cnt;

	public void init() {
		N = 0;
		cnt = 0;
	}

	private class Cookie {
		int min;
		int mid;
		int max;

		Cookie(int a, int b, int c) {
			min = a;
			mid = b;
			max = c;
			if (min > mid) {
				int bk = mid;
				mid = min;
				min = bk;
			}
			if (mid > max) {
				int bk = max;
				max = mid;
				mid = bk;
			}
			if (min > mid) {
				int bk = mid;
				mid = min;
				min = bk;
			}
		}

		@Override
		public int hashCode() {
			final int prime = 31;
			int result = 1;
			result = prime * result + getOuterType().hashCode();
			result = prime * result + max;
			result = prime * result + mid;
			result = prime * result + min;
			return result;
		}

		@Override
		public boolean equals(Object obj) {
			if (this == obj)
				return true;
			if (obj == null)
				return false;
			if (getClass() != obj.getClass())
				return false;
			Cookie other = (Cookie) obj;
			if (!getOuterType().equals(other.getOuterType()))
				return false;
			if (max != other.max)
				return false;
			if (mid != other.mid)
				return false;
			if (min != other.min)
				return false;
			return true;
		}

		private Solver getOuterType() {
			return Solver.this;
		}
	}

	public void readHead(String str) {
		String[] strArr = str.split(" ");
		int a = Integer.parseInt(strArr[0]);
		int b = Integer.parseInt(strArr[1]);
		int c = Integer.parseInt(strArr[2]);
		HashSet<Cookie> cookieSet = new HashSet<Cookie>();
		int cnt = 0;
		for (; a % 2 == 0 && b % 2 == 0 && c % 2 == 0;) {
			Cookie cookie = new Cookie(a, b, c);
			if (cookieSet.contains(cookie)) {
				cnt = -1;
				break;
			}
			cookieSet.add(cookie);
			cnt++;
			int ah = a / 2;
			int bh = b / 2;
			int ch = c / 2;
			a = bh + ch;
			b = ah + ch;
			c = ah + bh;
		}
		System.out.println(cnt);
	}

	public boolean hasNext() {
		return cnt < N;
	}

	public void readBody(String str) {
		// System.out.println(str);
		cnt++;
	}
}


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

typedef long long ll;
typedef long double ld;

#define n1		      "\n"
#define B                     begin()
#define E                     end()
#define F                     first
#define S                     second
#define pb                    push_back
#define pf                    push_front
#define popb                  pop_back()
#define popf                  pop_front()

const int BIG=1e5+55;
const int BIGG=1e9+7;
const ll BIGGE=1e12+55;
const double SML=(1e-7);

using namespace std;

    int a[5],ans;

int main()
{
    ios::sync_with_stdio(false); cin.tie(NULL);
    cout.tie(NULL);
    for (int i=0; i<5; i++) {
        int x; cin >>x;
        if (x == 0)
            ans = i+1;
    }
    cout <<ans;



    return 0;
}


Measured memory_bytes: 3636
#146A

# S(今日の曜日）：標準入力
S = input()

# SはSUN,MON,TUE,WED,THU,FRI,SAT のいずれか
#　次の日曜日が何日後か、if-else
# 条件分岐その2：if-else
# 条件分岐その3：if-elif-else
# ある条件の時は○○,他の条件の時は△△

if S == 'SUN':
    print(7)
elif S == 'MON':
    print(6)
elif S == 'TUE':
    print(5)
elif S == 'WED':
    print(4)
elif S == 'THU':
    print(3)
elif S == 'FRI':
    print(2)
elif S == 'SAT':
    print(1)

Measured memory_bytes: 9040
#!/usr/bin/env python3
import sys


def solve(K: int, X: int):

    print(" ".join(map(str,[i for i in range(X-K+1,X+K) if abs(i) <= 1000000])))
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    K = int(next(tokens))  # type: int
    X = int(next(tokens))  # type: int
    solve(K, X)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
// ConsoleApplication1.cpp : Defines the entry point for the console application.
//
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

#define MAXCHAR 255

using namespace std;

int numberOfBooks = 0;
int numberOfAlgs = 0;
int minimumLev = 0;
int cost = -1;
vector<pair<int, vector<int>>> AlgExpVector; // Vector of combination of books, which has total exp for each algorithms
vector<int> costVec;

void func()
{
	for (int i = 0; i < AlgExpVector.size(); i++)
	{
		bool passed = true;
		for (int j = 0; j < numberOfAlgs; j++)
		{
			if (AlgExpVector[i].second.size() == 0)
			{
				passed = false;
				break;
			}
			if (AlgExpVector[i].second[j] < minimumLev)
				passed = false;
		}
		if (passed)
		{
			cost = AlgExpVector[i].first;
			break;
		}
	}
}

void SortAccordingToCost()
{
	vector<pair<int, vector<int>>> copy;
	int len = AlgExpVector.size();
	for (int i = 0; i < len; i++)
	{
		bool inserted = false;
		for (auto it = copy.begin(); it != copy.end(); it++)
		{
			if (AlgExpVector[i].first < (*it).first)
			{
				copy.insert(it, AlgExpVector[i]);
				inserted = true;
				break;
			}
		}
		if (!inserted)
			copy.push_back(AlgExpVector[i]);
	}
	AlgExpVector = copy;
}

void CalcExp(vector<vector<int>> input)
{
	// Combination of books to buy is 2^N
	for (int j = 0; j < (1 << numberOfBooks); j++)
	{
		AlgExpVector.push_back(pair<int,vector<int>>());
		// Loop thru each books
		for (int i = 0; i < numberOfBooks; i++)
		{
			// 1<<i represents filled binary container at i th (1~N) index
			int binary = 1 << i;
			if (binary & j)
			{
				// first pair contains cost of the selction of books
				AlgExpVector[j].first += costVec[i];
				//AlgExpVector[j].second = vector<int>(numberOfAlgs);
				for (int k = 0; k < numberOfAlgs; k++)
				{
					if (AlgExpVector[j].second.size() < numberOfAlgs)
					{
						AlgExpVector[j].second.push_back(input[i][k]);
						continue;
					}
					AlgExpVector[j].second[k] += input[i][k];
				}
			}
		}
	}
}

int main()
{
	cin >> numberOfBooks;
	cin >> numberOfAlgs;
	cin >> minimumLev;

	vector<vector<int>> expFromBooks;

	for (int i = 0; i < numberOfBooks; i++)
	{
		for (int j = 0; j <= numberOfAlgs; j++)
		{
			int input = 0;
			cin >> input;

			if (j == 0)
			{
				costVec.push_back(input);
				expFromBooks.push_back(vector<int>());
				continue;
			}
			expFromBooks[i].push_back(input);
		}
	}
	CalcExp(expFromBooks);
	SortAccordingToCost();
	func();

	cout << cost << endl;

	return 0;
}



Measured memory_bytes: 4232
MOD = 10 ** 9 + 7
S = list(input())

n = 1
a = 0
ab = 0
abc = 0
for s in S:
    if s == 'A':
        a += n
    elif s == 'B':
        ab += a
    elif s == 'C':
        abc += ab
    else: #s == '?'
        abc = 3 * abc + ab
        ab = 3 * ab + a
        a = 3 * a + n
        n *= 3
    abc %= MOD
    ab %= MOD
    a %= MOD
    n %= MOD
    # print (a, ab, abc)
# print (a)
# print (ab)
print (abc)

Measured memory_bytes: 3956
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
using namespace std;
//const long long mod=1000000007;
//const long long inf=mod*mod;
//const long long d2=(mod+1)/2;
const long double EPS=1e-9;
const long double PI=acos(-1.0);
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
long double ABS(long double a){return max(a,-a);}

long long mod;
long long fact[11000];
long long inv[11000];
long long finv[11000];
long long C(int a,int b){
	if(a<0||a<b)return 0;
	return fact[a]*finv[b]%mod*finv[a-b]%mod;
}
long long pw(long long a,long long b,long long c){
	long long ret=1;
	while(b){
		if(b%2)ret=ret*a%c;
		a=a*a%c;
		b/=2;
	}
	return ret;
}
long long dp[3100][3100];
long long pc[3100];
int main(){
	int a;
	scanf("%d%lld",&a,&mod);
	fact[0]=finv[0]=inv[1]=1;
	for(int i=2;i<11000;i++){
		inv[i]=(mod-(mod/i)*inv[mod%i]%mod)%mod;
	}
	for(int i=1;i<11000;i++){
		fact[i]=fact[i-1]*i%mod;
		finv[i]=finv[i-1]*inv[i]%mod;
	}
	for(int i=0;i<=a;i++){
		pc[i]=pw(2,pw(2,a-i,mod-1),mod);
	}
	dp[0][0]=1;
	for(int i=0;i<a;i++){
		for(int j=0;j<=i;j++){
			if(dp[i][j]==0)continue;
			dp[i+1][j]=(dp[i+1][j]+dp[i][j]*(j+1))%mod;
			dp[i+1][j+1]=(dp[i+1][j+1]+dp[i][j])%mod;
		}
	}
	long long ret=0;
	for(int i=0;i<=a;i++){
		long long ks=C(a,i);
		long long tmp=0;
		for(int j=0;j<=i;j++){
			tmp=(tmp+dp[i][j]*pw(2,(a-i)*j,mod)%mod*pc[i])%mod;
		}
		if(i%2==0){
			ret=(ret+tmp*ks)%mod;
		}else{
			ret=(ret+mod-tmp*ks%mod)%mod;
		}
	}
	printf("%lld\n",ret);
}


Measured memory_bytes: 72448
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>

using namespace std;

int main(){
  long long unsigned int N;
  cin >> N;
  
  vector<long long unsigned int> A(5);
  for(int i = 0; i < 5; i++) cin >> A[i];
  vector<pair<long long unsigned int, int>> P(5);
  for(int i = 0; i < 5; i++){
    P[i] = make_pair(A[i],i);
  }
  sort(P.begin(),P.end());
  long long unsigned int ans = 0;
  long long unsigned int bneck = P[0].first;
  //if(N <= bneck){
  //  ans = 5;
  //}else{
    ans = (N + bneck - 1)/bneck + 4;
  //}
  cout << ans;
}

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

int main()
{
string s ;
cin >> s ;
if(s=="ABC")s="ARC";
else s="ABC";
cout << s << endl;
return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
 
typedef pair<ll, int> p;

#define MOD 1000000007
 
int main() {
	cin.tie(0);
    ios::sync_with_stdio(false);

    string S, T;
    cin >> S >> T;

    int ans = 0;

    for(int i = 0; i < S.length(); i++) {
        if(S[i] != T[i]) ans++;
    }

    cout << ans << endl;
}

Measured memory_bytes: 3772
#include <iostream>
#include <math.h>
#include <algorithm>
#include <vector>
#include <numeric>
#include <string>
using namespace std;
const double PI = acos(-1.0);
const string alp = "abcdefghijklmnopqrstuvwxyz";
const string ALP = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const int INTMAX = 2147483647;
const int INTMIN = -2147483648;
const unsigned int UINTMAX = 4294967295;
const long LONGMAX = 9223372036854775807;
const long LONGMIN = -9223372036854775808;
const unsigned long ULONGMAX = 18446744073709551615;
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define REP1(i,n) FOR(i,1,n+1)
#define SUM(c) accumulate((c).begin(),(c).end(),0)
#define UNIQ(c) (c).erase(unique((c).begin(), (c).end()), (c).end());
#define Yn(b) puts(b?"Yes":"No")
#define YN(b) puts(b?"YES":"NO")

bool isprime(int p) {
  if (p==1) return false;
  FOR(i,2,p) {
    if (p%i==0) return false;
  }
  return true;
}

int dig(int n, int a) {return n/(int)pow(10,a)%10;}
int digl(long n, int a) {return n/(long)pow(10,a)%10;}
int digsum(int n) {int r=0;REP(i,10){r+=dig(n,i);}return r;}
int digsuml(long n) {int r=0;REP(i,19){r+=digl(n,i);}return r;}
int dignum(int n) {return n?to_string(n).length():0;}
int dignuml(long n) {return n?to_string(n).length():0;}

int main(){
  string s,r;
  cin >> s;
  r="";
  REP(i,s.length()){
    if(s[i]=='0'){
      r+="0";
    }
    if(s[i]=='1'){
      r+="1";
    }
    if(s[i]=='B'&&s!=""){
      r=r.substr(0,r.length()-1);
    }
  }
  cout << r;
  return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS

#include <vector>
#include <iostream>
#include <string>
#include <functional>
#include <set>
#include <map>
#include <unordered_map>
#include <fstream>
#include <iomanip>
#include <ctime>
#include <queue>
#include <deque>
#include <math.h>
#include <cmath>
#include <stack>
#include <algorithm>
#include <list>
#include <array>
#include <valarray>
#include <unordered_map>
#include <cassert>
#include <random>
#include <cstring>
#include <bitset>

using namespace std;

typedef long double ld;
typedef long long li;
typedef vector<li> vec;
typedef vector<vector<li>> mt;
typedef pair<int, int> pii;

#define X first
#define Y second
#define all(a) a.begin(), a.end()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)

const double PI = 3.14159265358979323846;
const double EPS = 1e-9;
const int INF = 1e9 + 7;
const li LINF = 1e18 + 7;

int main() {
#ifdef _DEBUG
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
#endif
	cin.tie(0);
	ios_base::sync_with_stdio(0);
	cout.tie(0);

	int n;
	cin >> n;

	set<int> c;
	for (int i = 1; i <= 10000; i++) {
		c.insert(i);
	}

	vector<int> a(n);
	forn(i, n) {
		cin >> a[i];
		c.erase(a[i]);
	}

	int ans = 0;
	for (int i = 1; i < n; ++i) {
		if (a[i] == a[i - 1]) {
			a[i] = *c.begin();
			c.erase(c.begin());
			ans++;
		}
	}

	cout << ans << endl;
}

Measured memory_bytes: 1276
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <bitset>
#include <map>
#include <tuple>
#include <unordered_map>
#include <list>
#include <numeric>
#include <utility>
#include <iterator>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <ctime>
#include <cassert>
#include <random>

#define INF 1000000000
#define LINF 9000000000000000000
#define mod  1000000007

#define rep(i,n) for(int i=0;i<int(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define REP(i,a,b) for(int i=(a);i<int(b);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back
#define mp make_pair

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef pair<int,int> pi;

int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int ddx[8]={-1,-1,0,1,1,1,0,-1};
int ddy[8]={0,1,1,1,0,-1,-1,-1};
bool debug=false;

/*---------------------------------------------------*/

int main(){
  int N, x;
  cin >> N >> x;
  vector<int> a(N);
  for(int i = 0; i < N ; i++){
    cin >> a[i];
  }

  ll ans = 0;
  for(int i = 1; i < N; i++){
    ll sum = max(0, a[i - 1] + a[i] - x);
    ans += sum;
    a[i] = max(a[i] - sum, 0LL);
  }
  cout << ans << endl;
}


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

//while(x!=0){
            //sum+=x%10;
           // x/=10;
        //}
        //各桁の和


#define rep(i,n) for(long long int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(long long int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(long long int i=(a);i>(b);i--)

long long int n,cnt=0,a,b,c,cmp[100000],ans[55][55],m,h;

char s[55][55],w;

int main(void){
      cin >> a >> b;
      rrep(i,1,a+1){
          rrep(j,1,b+1){
              cin >> s[i][j];
              if(s[i][j]=='#'){
                  ans[i-1][j-1]++;
                  ans[i-1][j]++;
                  ans[i-1][j+1]++;
                  ans[i][j-1]++;
                  ans[i][j+1]++;
                  ans[i+1][j-1]++;
                  ans[i+1][j]++;
                  ans[i+1][j+1]++;
              }
          }
      }
      rrep(i,1,a+1){
          rrep(j,1,b+1){
              if(s[i][j]=='#'){
                  cout << '#';
              }
              else{
                  cout << ans[i][j];
              }
          }
          cout << endl;
      }
return 0;
}


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

int main()
{
    int n, m;
    cin >> n >> m;
    vector<P> a(n);
    rep(i, 0, n) cin >> a[i].first >> a[i].second;
    sort(a.begin(), a.end());
    int cnt = 0;
    int cnt_1 = 0;
    int idx = 0;
    ll ans = 0;
    while(cnt < m){
        ans += a[cnt_1].first;
        idx++;
        if(idx >= a[cnt_1].second) {
            cnt_1++;
            idx = 0;
        }
        cnt++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3984
#include "iostream"
#include "vector"
#include "string"
#include "algorithm"
#include "math.h"
#include "cstring"
#include "stack"
#include "queue"

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<vector<int> > mat;

int main()
{
  int a, b, q;
  cin >> a >> b >> q;
  vector<ll> s(a), t(b), x(q);
  for (int i = 0; i < a; i++)
  {
    cin >> s[i];
  }
  for (int i = 0; i < b; i++)
  {
    cin >> t[i];
  }
  for (int i = 0; i < q; i++)
  {
    cin >> x[i];
  }
  for (int i = 0; i < q; i++)
  {
    int ar = lower_bound(s.begin(), s.end(), x[i]) - s.begin();
    int br = lower_bound(t.begin(), t.end(), x[i]) - t.begin();
    if (x[i] <= s[0])
    {
      ar = 1;
    }
    if (x[i] >= s[a - 1])
    {
      ar = a - 1;
    }
    if (x[i] <= t[0])
    {
      br = 1;
    }
    if (x[i] >= t[b - 1])
    {
      br = b - 1;
    }

    ll da[2] = {s[max(ar - 1, 0)], s[min(ar, a - 1)]};
    ll db[2] = {t[max(br - 1, 0)], t[min(br, b - 1)]};
    ll ans = 1e12;

    for (auto ax:da)
    {
      for (auto bx:db)
      {
        ans = min(ans, min(abs(x[i] - ax), abs(x[i] - bx)) + abs(bx - ax));
      }
    }
    cout << ans << "\n";
  }
}

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

typedef struct _Node {
  int key;
  struct _Node *next, *prev;
} Node;

Node *nil;

Node* listSearch(int key) {
  Node *cur = nil->next;
  while(cur != nil && cur->key != key) {
    cur = cur->next;
  }
  return cur;
}

void init(void) {
  nil = (Node *)malloc(sizeof(Node));
  nil->next = nil;
  nil->prev = nil;
}

void printList(void) {
  Node *cur = nil->next;
  int isf = 0;
  while(1) {
    if(cur == nil) break;
    if(isf++>0) printf(" ");
    printf("%d",cur->key);
    cur = cur->next;
  }
  printf("\n");
}

void deleteNode(Node *t) {
  if(t==nil) return;
  t->prev->next = t->next;
  t->next->prev = t->prev;
  free(t);
}

void deleteFirst(void) {
  deleteNode(nil->next);
}

void deleteLast(void) {
  deleteNode(nil->prev);
}

void deleteKey(int key) {
  deleteNode(listSearch(key));
}

void insert(int key) {
  Node *x = (Node *)malloc(sizeof(Node));
  x->key = key;
  x->next = nil->next;
  nil->next->prev = x;
  nil->next = x;
  x->prev = nil;
}

int main(void) {
  int key, n, i;
  int size = 0;
  int np = 0, nd = 0;
  char com[20];
  scanf("%d", &n);
  init();
  for(i=0;i<n;i++) {
    scanf("%s%d",com, &key);
    if (com[0] == 'i') {
      insert(key);
      np++;
      size++;
    } else if(com[0] == 'd') {
      if(strlen(com) > 6) {
        if(com[6] == 'F')
          deleteFirst();
        else if(com[6] == 'L')
          deleteLast();
      } else {
        deleteKey(key);
        nd++;
      }
      size--;
    }
  }
  printList();
  return 0;
}



Measured memory_bytes: 33828
#include <bits/stdc++.h>  // clang-format off
using Int = long long;
#define REP_(i, a_, b_, a, b, ...) for (Int i = (a), lim##i = (b); i < lim##i; i++)
#define REP(i, ...) REP_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
struct SetupIO { SetupIO() { std::cin.tie(nullptr), std::ios::sync_with_stdio(false), std::cout << std::fixed << std::setprecision(13); } } setup_io;
#ifndef dump
#define dump(...)
#endif  // clang-format on

/**
 *    author:  knshnb
 *    created: Tue May  5 02:33:19 JST 2020
 **/

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

const Int K = 300, INF = 1e18;
signed main() {
    Int n, Q;
    std::cin >> n >> Q;
    std::vector<Int> a(n + K, (1LL << 31) - 1), acc(n / K + 1, (1LL << 31) - 1);
    REP(q, Q) {
        Int t, x, y;
        std::cin >> t >> x >> y;
        if (t == 0) {
            // update a[x] <- y
            a[x] = y;
            Int idx = x / K;
            acc[idx] = INF;
            REP(i, K * idx, K * (idx + 1)) chmin(acc[idx], a[i]);
        } else {
            y++;
            // get min [x, y)
            Int ans = INF;
            for (Int i = x; i < y; i++) {
                if (i % K == 0 && i + K <= y) {
                    chmin(ans, acc[i / K]);
                    i += K - 1;
                } else {
                    chmin(ans, a[i]);
                }
            }
            std::cout << ans << "\n";
        }
    }
}



Measured memory_bytes: 3592
# import itertools
# import math
# import sys
# sys.setrecursionlimit(500*500)
# import numpy as np

N = int(input())
# S = input()
# n, *a = map(int, open(0))
# N, M = map(int, input().split())
A = list(map(int, input().split()))
# B = list(map(int, input().split()))
# tree = [[] for _ in range(N + 1)]
# B_C = [list(map(int,input().split())) for _ in range(M)]
# S = input()

# B_C = sorted(B_C, reverse=True, key=lambda x:x[1])
# all_cases = list(itertools.permutations(P))
# a = list(itertools.combinations_with_replacement(range(1, M + 1), N))
# itertools.product((0,1), repeat=n)

# A = np.array(A)
# cum_A = np.cumsum(A)
# cum_A = np.insert(cum_A, 0, 0)

# def dfs(tree, s):
#     for l in tree[s]:
#         if depth[l[0]] == -1:
#             depth[l[0]] = depth[s] + l[1]
#             dfs(tree, l[0])
# dfs(tree, 1)

# def factorization(n):
#     arr = []
#     temp = n
#     for i in range(2, int(-(-n**0.5//1))+1):
#         if temp%i==0:
#             cnt=0
#             while temp%i==0:
#                 cnt+=1
#                 temp //= i
#             arr.append([i, cnt])
#     if temp!=1:
#         arr.append([temp, 1])
#     if arr==[]:
#         arr.append([n, 1])
#     return arr

num = 1
for i in A:
    if i == num:
        num += 1
if num == 1:
    print(-1)
else:
    print(N - (num - 1))


Measured memory_bytes: 32324
loop do
    n, p = gets.split.map(&:to_i)
    pp = p
    break if n == 0 && p == 0
    h = Array.new(n,0)
    i = 0
    loop do
        if p > 0
            h[i] += 1
            p -= 1
            break if h[i] == pp
        else
            p += h[i]
            h[i] = 0
        end
        i += 1
        i = 0 if i == n
    end
    puts i
end

Measured memory_bytes: 6100
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

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

    int n;
    cin >> n;

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

    vector<string> field(n*2);
    for(int i = 0; i < n; ++i){
        field[i] = input[i] + input[i];
    }
    for(int i = 0; i < n; ++i){
        field[n+i] = input[i] + input[i];
    }

    int ans = 0;
    for (int i = 0; i < n; ++i) {
        int a = 0, b = i;

        bool isOK = true;
        for (int x = 0; x < n; ++x) {
            for (int y = 0; y < n; ++y) {
                int ax = a+x, ay = b+y;
                int bx = a+y, by = b+x;

                if (field[ax][ay] != field[bx][by]) {
                    isOK = false;
                }
            }
        }
        if (isOK) {
            ans += n - i;
        }
    }

    for (int i = 1; i < n; ++i) {
        int a = i, b = 0;

        bool isOK = true;
        for (int x = 0; x < n; ++x) {
            for (int y = 0; y < n; ++y) {
                int ax = a+x, ay = b+y;
                int bx = a+y, by = b+x;

                if (field[ax][ay] != field[bx][by]) {
                    isOK = false;
                }
            }
        }
        if (isOK) {
            ans += n - i;
        }
    }

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

Measured memory_bytes: 768
/**
 *   author: malviyanshiv
 *   created: 09 January 2019  23:27:27
**/

#include <bits/stdc++.h>

using namespace std;

#define REP(i, a, b) for(int i = a; i < b; i++)
#define RREP(i, a, b) for(int i = a-1; i >= b; i--)
#define PB push_back
#define MP make_pair
#define MOD 1000000007
#define INF 0x7fffffff
#define MAX 100005

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

void fastscan(int &x){
    bool neg=false;
    register int c;
    x =0;
    c=getchar();
    if(c=='-'){
        neg = true;
        c=getchar();
    }
    for(;(c>47 && c<58);c=getchar())
        x = (x<<1) + (x<<3) +c -48;
    if(neg)
        x *=-1;
}

void optimizeIO(){
	ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
}

vector< vector<ll> > dp(MAX, vector<ll>(101, -1));
vector< ll > inp(101);


int main(){
	optimizeIO();
    
    int n, k, x;
    cin >> n >> k;
    REP(i, 0, n)
        cin >> inp[i];

    // filling the first row
    REP(i, 0, n)
        dp[0][i] = 1;

    // filling the first column
    REP(i, 1, k+1)
        if( i <= inp[0])
            dp[i][0] = 1;
        else
            dp[i][0] = 0;

    REP(i, 1, n){
        REP(j, 1, inp[i]+1)
            dp[j][i] = (dp[j][i-1]%MOD + dp[j-1][i]%MOD)%MOD;
        x = 0;
        REP(j, inp[i]+1, k+1){
            dp[j][i] = ((dp[j][i-1]%MOD + dp[j-1][i]%MOD)%MOD - dp[x++][i-1]%MOD)%MOD;
            if( dp[j][i] < 0 )
                dp[j][i] += MOD;
        }
    }
    cout << (dp[k][n-1])%MOD << endl;

	return 0;
}

Measured memory_bytes: 82304