akhauriyash/Code-Regression huggingface dataset:
H,W,N = map(int,input().split())
dic = {}
for i in range(N):
    a,b = map(int,input().split())
    for dh in range(3):
        for dw in range(3):
            if 0<a-dh<=H-2 and 0<b-dw<=W-2:
                if (a-dh,b-dw) not in dic.keys():
                    dic[(a-dh,b-dw)] = 1
                else:
                    dic[(a-dh,b-dw)] += 1

Ans = [0]*10
total = 0
for v in dic.values():
    Ans[v] += 1
    total += 1

Ans[0] = (H-2)*(W-2) - total

for ans in Ans:
    print(ans)



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

#define ll long long
#define setp setprecision
#define fix fixed
#define db double
#define pb push_back
int main() {
	int n,m;
	cin>>n>>m;
	int c[n+1];
	int ans=1,pos=0;
	for (int i=1;i<=n;i++) {
		cin>>c[i];
		if (pos+c[i]>m) {
			break;
		}
		pos+=c[i];
		ans++;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<climits>
#include<queue>
#include<set>
#include<cmath>
#include<map>
#include<bitset>
#include<fstream>
#include<tr1/unordered_map>

typedef long long LL;
using namespace std;
#define mp make_pair
#define pb push_back
#define x first
#define y second

void proc_status()
{
	ifstream t("/proc/self/status");
	cerr << string(istreambuf_iterator<char>(t), istreambuf_iterator<char>()) << endl;
}

int read()
{
	int x = 0, f = 1; int c = getchar();
	while(!isdigit(c)) { if(c == '-') f = 0; c = getchar(); }
	while(isdigit(c)) { x = (x * 10) + (c ^ 48); c = getchar(); }
	return f ? x : -x;
}

const int maxn = 1e6 + 10;
int u[maxn], v[maxn], c[maxn], f[maxn], can[2][maxn];

int find(int x) { return (x == f[x] ? f[x] : f[x] = find(f[x])); }

void uni(int x, int y)
{
	x = find(x); y = find(y);
	if(x == y) return ;
	f[x] = y;
}

int Id(int x, int y, int z) { return (x - 1) * 6 + y * 3 + z; }

int main()
{

	int n = read(), m = read(), Q = read(), mod = read();
	int g = 0;
	for(int i = 1; i <= m; ++i)
	{
		u[i] = read(); v[i] = read(); c[i] = read();
		g = __gcd(g, abs(c[i] - c[1]));
	}
	if(!g) g = mod; mod = __gcd(mod, 3 * g); int z = c[1] % g;
	for(int i = 0; i <= 6 * n; ++i) f[i] = i;

	for(int i = 1; i <= m; ++i)
	{
		int w = (c[i] - z) / g;
		for(int p = 0; p <= 1; ++p) for(int q = 0; q <= 2; ++q)
			uni(Id(u[i], p, q), Id(v[i], 1 - p, (2 * q + w) % 3)),
			uni(Id(v[i], p, q), Id(u[i], 1 - p, (2 * q + w) % 3));
	}

	for(int i = 0, j = z; i <= mod; ++i, (j <<= 1) %= mod) can[i & 1][j] = 1;

	while(Q--)
	{
		int s = read(), t = read(), r = read();
		int ret = 0;
		for(int p = 0; p <= 1; ++p) for(int q = 0; q <= 2; ++q)
			if(find(Id(t, 0, 0)) == find(Id(s, p, q))) 
				ret |= can[p][(r + z + (3 - q) * g) % mod];
		printf("%s\n", ret ? "YES" : "NO");
	}

	return 0;
}

Measured memory_bytes: 16768
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b)  for(int i=(a),i##formax=(b);i< i##formax;i++)
#define FORR(i,a,b) for(int i=(a),i##formin=(b);i>=i##formin;i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pcnt __builtin_popcount
#define sz(x) (int)(x).size()
#define maxs(x,y) x=max((x),(y))
#define mins(x,y) x=min((x),(y))
#define show(x) cout<<#x<<" = "<<(x)<<endl;
#define all(a) ((a).begin()),((a).end())
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define bit(n) (1LL<<(n))
typedef long long ll;
typedef __int128_t lll;
template<class T>using V=vector<T>;
template<class T>using VV=V<V<T>>;
template<class T,class Y>using P=pair<T,Y>;
template<class T,class Y>ostream& operator<<(ostream&o,P<T,Y>&p){return o<<"("<<p.fi<<","<<p.se<<")";}
template<class T>ostream& operator<<(ostream&o,V<T>&v){for(T&t:v)o<<t<<",";return o<<endl;}
template<class T>void uniq(V<T>&v){sort(all(v));v.erase(unique(all(v)), v.end());}

lll gcd(lll a,lll b,lll&x,lll&y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll modInv(ll a,ll m){lll x,y;gcd(a,m,x,y);return(x%m+m)%m;}
ll modPow(lll a,lll n,ll m){lll p=1;for(;n;n>>=1,a=a*a%m)if(n&1)p=p*a%m;return p;}
//V<ll>F,R;void setF(int n,int mod){F=R=V<ll>(++n);F[0]=1;FOR(i,1,n)F[i]=F[i-1]*i%mod;R[n-1]=modInv(F[n-1],mod);FORR(i,n-1,1)R[i-1]=R[i]*i%mod;}
//ll comb(int a,int b,int m){return a<b||b<0?0:F[a]*R[b]%m*R[a-b]%m;}

const int IINF = 1e9+6;
const ll LINF = 1e18;
const int MOD = 1e9+7; //998244353;
const int N = 1e5;
int n;
V<int> e[N];
int dfs(int a, int p){
  int ret = 0, z = 0;
  for(int b:e[a]) if(b!=p){
    int t = dfs(b, a);
    z += !t;
    ret += t;
  }
  return ret + max(0, z-1);
}
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n;
  FOR(i, 0, n-1){
    int a, b;
    cin >> a >> b;
    e[a].pb(b);
    e[b].pb(a);
  }
  FOR(i, 0, n) if(sz(e[i])>2){
    cout << dfs(i, -1) << endl;
    return 0;
  }
  cout << 1 << endl;
}

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

using namespace std;

typedef long long ll ;
const int maxn = 1e5 + 50 ;

ll v1[maxn] ,v2[maxn] ;

int main() {
	int n ;
	scanf("%d",&n) ;
	for (int i = 1 ; i <= n + 1 ; i ++ ) {
		scanf("%lld",&v1[i]) ;
	}
	for (int i = 1 ; i <= n ; i ++ ) {
		scanf("%lld",&v2[i]) ;
	}
	ll ans = 0 ;
	ll now = 0;
	for (int i = 1 ; i <= n ; i ++ ) {
		now = min(v1[i] ,v2[i]) ;
		ans += now ;
		v1[i] -= now ;
		v2[i] -= now ;
		now = min(v2[i] ,v1[i+1]) ;
		ans += now ;
		v1[i+1] -= now ;
		v2[i] -= now ;
	}
	printf("%lld\n",ans) ;
	return 0;
}


Measured memory_bytes: 1792
input = require('fs').readFileSync('/dev/stdin', 'utf8')
lines = input.split('\n')
line = lines.shift().split(' ')
N = line[0] * 1
M = line[1] * 1
b = []
r = []
for (i=1; i<=N; i++) {
    b[i] = 1
    r[i] = 0
}
r[1] = 1
for (i=0; i<M; i++) {
  l = lines[i].split(' ')
  x = l[0] * 1
  y = l[1] * 1
  if (r[x]) {
      r[y] += 1
  }
  if (r[x] && b[x] == 1) {
      r[x] = 0
  }
  b[x] -= 1
  b[y] += 1
}
cnt = 0
for (i=1; i<=N; i++) {
    if (r[i] > 0) {
        cnt++
    }
}
console.log(cnt)

Measured memory_bytes: 30780
N, M=map(int, input().split())
ks=[list(map(int, input().split())) for _ in range(M)]
p=list(map(int, input().split()))

ans=0
for i in range(1<<N):
    flag=0
    for j in range(M):
        t=0
        for k in range(ks[j][0]):
            t+= 1 & (i>>ks[j][k+1]-1)
        if t%2!=p[j]:
            flag=1
            break
    if flag:
        continue
    ans+=1
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
using namespace std;
 
int main(){
    int N, M;

    cin >> N >> M;

    vector<int> A(N);

    double sum =0;
    for(int i = 0; i < N ; i++){
        cin >> A[i];
        sum += A[i];
    }
    // cout << "s" <<sum << endl;
    sort(A.begin(),A.end(),std::greater<int>());
    
    if(A[M-1] >= (double)(sum / (4 * M)))
        cout << "Yes" << endl;
    else
        cout << "No" << endl;

}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <string>

using namespace std;

int top, S[101];

void initialize() {
	top = 0;
}
bool isEmpty() {
	return top == 0;
}
bool isFull() {
	return top == 100;
}
void push(int x) {
	if (isFull()) {
		printf("overflow\n");
	}
	else {
		top++;
		S[top] = x;
	}
}
int pop() {
	if (isEmpty()) {
		printf("underflow\n");
	}
	else {
		top--;
		return S[top + 1];
	}
}

int main() {
	initialize();
	int a, b;
	char s[100];

	while (scanf("%s", s) != EOF) {
		if (s[0] == '+') {
			a = pop();
			b = pop();
			push(a + b);
		}
		else if (s[0] == '-') {
			b = pop();
			a = pop();
			push(a - b);
		}
		else if (s[0] == '*') {
			b = pop();
			a = pop();
			push(a*b);
		}
		else {
			push(atoi(s));
		}
	}

	printf("%d\n", pop());

	return 0;
}

Measured memory_bytes: 2684
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
#define si scanf
#define so printf
#define N 100100
#define M 
#define INF  
template<typename TP>inline bool rd(TP& r)
{
	r=0;
	char tmp=getchar();
	while(tmp<'0'||tmp>'9')
	{
		if(tmp==EOF)
			return 0;
		tmp=getchar();
	}
	while('0'<=tmp&&tmp<='9')
	{
		r=(r<<3)+(r<<1)+tmp-'0';
		tmp=getchar();
	}
	return 1;
	
} 
int n;
char s[N];
int mid,ans;
int main()
{
	si("%s",s+1);
	n=strlen(s+1);
	if(n&1)
	{
		mid=n/2+1;
		ans+=n/2+1;
		for(int i=1;mid-i;++i)
			if(s[mid-i]==s[mid]&&s[mid+i]==s[mid])
				++ans;
			else
				break;
	}
	else
	{
		mid=n/2;
		ans+=n/2;
		if(s[mid]==s[mid+1])
		{
			++ans;
			for(int i=1;mid-i;++i)
				if(s[mid-i]==s[mid]&&s[mid+1+i]==s[mid])
					++ans;
				else
					break;
		}
	}
	so("%d\n",ans);
	return 0;
} 

Measured memory_bytes: 384
def main():
    inp = lambda: [int(x) for x in input().split()]    
    n, k = inp()
    a = inp()
    min_a = min(a)
    dp = [False] * (k+1)
    for i in range(k + 1):
        if i < min_a:
            dp[i] = False
        elif i in a:
            dp[i] = True
        else:
            for j in a:
                if i >= j and not dp[i-j]:
                    dp[i] = True
                    break

    ans = "First" if dp[k] else "Second"
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 40816
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define call(var) cout<<#var<<"="<<var<<endl;
#define dup(x,y) (((x)+(y)-1)/(y))
using ll=long long;
using vi = vector<int>;
using vl = vector<ll>;
using vb = vector<bool>;
using Graph = vector<vi>;
using P = pair<int,int>;
const int MOD=(int)1e9+7;
const int INF=(int)1e9;
const ll LINF=(ll)1e18;
template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}

int main(){
    int n;cin >> n;
    vl a(n);
    rep(i,n) cin >> a[i];
    ll sum = 0;
    rep(i,n){
        if(i&1) sum -= a[i];
        else sum += a[i];
    }
    ll A = sum/2;
    vl ans(n,0);
    ans[0] = 2*A;
    for(int i=1;i<n;i++){
        ans[i] = 2*(a[i-1]-(ans[i-1]/2));
    }
    rep(i,n) cout << ans[i] << endl;
}

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

int main() {
	int n, l[210], ans = 0;
	cin >> n;
	for (int i = 0; i < 2 * n; i++) cin >> l[i];
	sort(l, l + 2 * n);

	for (int i = 2 * n - 2; i >= 0; i -= 2) {
		ans += l[i];
	}
	cout << ans << endl;	

	return 0;
}

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int h, w, k;
    cin >> h >> w >> k;
    vector<vector<char>> c(h, vector<char>(w));
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            cin >> c[i][j];
        }
    }
    int ans = 0;
    for (int mr = 0; mr < (1 << h); mr++) {
        for (int mc = 0; mc < (1 << w); mc++) {
            int total = 0;
            for (int i = 0; i < h; i++) {
                for (int j = 0; j < w; j++) {
                    if (((mr >> i) & 1) && ((mc >> j) & 1) && (c[i][j] == '#')) {
                        ++total;
                    }
                }
            }
            if (total == k) {
                ++ans;
            }
        }
    }
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 3660
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigDecimal;
import java.util.Arrays;

public class Main {

	/* several useful subroutines */
	private static final BigDecimal BD1000000007 = new BigDecimal(1000000007);
	private static BufferedReader brStdin = new BufferedReader(new InputStreamReader(System.in));
	private static String[] readBuf = null;
	private static int readPtr = 0;
	private static String getString() throws IOException {
		while ( readBuf == null || readPtr >= readBuf.length ) {
			readBuf = brStdin.readLine().split(" ");
			readPtr = 0;
		}
		return readBuf[readPtr++];
	}
	private static int getInt() throws IOException {
		return Integer.parseInt(getString());
	}
	private static long getLong() throws IOException {
		return Long.parseLong(getString());
	}
	private static BigDecimal getBD() throws IOException {
		return new BigDecimal(getString());
	}
	@SuppressWarnings("unused")
	private static String[] getStringArray(int size) throws IOException {
		String stringArray[] = new String[size];
		for (int i = 0; i < stringArray.length; i++) {
			stringArray[i] = getString();
		}
		return stringArray;
	}
	@SuppressWarnings("unused")
	private static int[] getIntArray(int size) throws IOException {
		int intArray[] = new int[size];
		for (int i = 0; i < intArray.length; i++) {
			intArray[i] = getInt();
		}
		return intArray;
	}
	@SuppressWarnings("unused")
	private static long[] getLongArray(int size) throws IOException {
		long longArray[] = new long[size];
		for (int i = 0; i < longArray.length; i++) {
			longArray[i] = getLong();
		}
		return longArray;
	}
	@SuppressWarnings("unused")
	private static BigDecimal[] getBDArray(int size) throws IOException {
		BigDecimal bdArray[] = new BigDecimal[size];
		for (int i = 0; i < bdArray.length; i++) {
			bdArray[i] = getBD();
		}
		return bdArray;
	}
	private static BigDecimal mod1000000007(BigDecimal bd) {
		return bd.subtract(BD1000000007.multiply(bd.divide(BD1000000007, BigDecimal.ROUND_DOWN))) ;
	}
	@SuppressWarnings("unused")
	private static BigDecimal mod1000000007(int i) {
		return mod1000000007(new BigDecimal(i)) ;
	}
	@SuppressWarnings("unused")
	private static BigDecimal mod1000000007(long l) {
		return mod1000000007(new BigDecimal(l)) ;
	}

	
	/* main routine */
	public static void main(String args[]) throws IOException {
		int n = getInt();
		int a[] = getIntArray(n);
		int b[] = new int[n];

		for ( int i = n ; i > 0 ; --i ) {
			int c = 0;
			for ( int j = i+i ; j <= n ; j += i ) {
				c += b[j-1];
			}
			if ( c % 2 != a[i-1] ) {
				b[i-1] = 1;
			}
		}
		int s = 0;
		for ( int c : b ) {
			s += c;
		}
		System.out.println( s );
		if ( s > 0 ) {
			for ( int i = 0 ; i < n ; i++ ) {
				if ( b[i] == 1 ) {
					System.out.printf( "%d ",  i+1 );
				}
			}
			System.out.println();
		}
	}
}


Measured memory_bytes: 96592
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<queue>
using namespace std;
const int maxn = 2e5+5;
int en[maxn],nt[maxn],la[maxn],v[maxn],owo;
//owo 1 !!!
long long len[maxn];
void adg(int x,int y,int vv,long long le) {
	en[++owo]=y; nt[owo]=la[x]; la[x] = owo; len[owo] = le; v[owo] = vv;
	en[++owo]=x; nt[owo]=la[y]; la[y] = owo; len[owo] = -le; v[owo] = 0;
}
long long ANS;
int N,M,tot,QD,ZD;
int X[maxn],Y[maxn];
long long V[maxn];
char ss[10],T[maxn];
int A[maxn],B[maxn];
int Lx[105],Rx[105];
int Ly[105],Ry[105];
int IDX[maxn],IDY[maxn],IDB[maxn];
queue<int>Q;
long long dis[maxn];
int path[maxn],epath[maxn];
bool rd[maxn];
long long MAXVAL;
bool spfa() {
	for(int i=1;i<=tot;i++) {
		dis[i] = -1e15; rd[i] = 0;
	}
	rd[QD] = 1; dis[QD] = 0;
	Q.push(QD);
	while(Q.size()) {
		int x = Q.front(); Q.pop(); rd[x] = 0;
		for(int it=la[x];it;it=nt[it]) {
			int y = en[it];
			if(v[it]&&dis[y] < dis[x] + len[it]) {
				dis[y] = dis[x] + len[it];
				path[y] = x; epath[y] = it;
				if(!rd[y]) Q.push(y),rd[y]=1;
			}
		}
	}
	if(dis[ZD]<=0) return 0;
	int p = ZD;
	for(;p!=QD;p=path[p])
		v[epath[p]]--,v[epath[p]^1]++;
	MAXVAL += dis[ZD];
	return 1;
}

void solve(int K) {
	for(int i=1;i<=tot;i++) la[i] = 0; 
	owo = 1; tot = 0;
	for(int i=1;i<=100;i++) {
		IDX[i] = ++tot; IDY[i] = ++tot; 
	}
	for(int i=1;i<=N;i++) {
		IDB[i] = ++tot;
		adg(IDX[X[i]],IDB[i],1,V[i]);
		adg(IDB[i],IDY[Y[i]],1,0);
	}
	
	fill(Lx+1,Lx+1+K,1); fill(Rx+1,Rx+1+K,100);
	fill(Ly+1,Ly+1+K,1); fill(Ry+1,Ry+1+K,100);
	
	for(int i=1;i<=M;i++) {
		if(T[i]=='L') Lx[B[i]+1] = max(Lx[B[i]+1],A[i]+1);
		else if(T[i]=='R'&&K>B[i]) Rx[K-B[i]] = min(Rx[K-B[i]],A[i]-1);
		else if(T[i]=='D') Ly[B[i]+1] = max(Ly[B[i]+1],A[i]+1);
		else if(T[i]=='U'&&K>B[i]) Ry[K-B[i]] = min(Ry[K-B[i]],A[i]-1);
	}
	for(int i=2;i<=K;i++) Lx[i] = max(Lx[i],Lx[i-1]),Ly[i] = max(Ly[i],Ly[i-1]);
	for(int i=K-1;i>=1;i--) Rx[i] = min(Rx[i],Rx[i+1]),Ry[i] = min(Ry[i],Ry[i+1]);
	QD = ++tot; ZD = ++tot;
	for(int i=1;i<=K;i++) {
		if( (Lx[i] > Rx[i]) || (Ly[i]>Ry[i]) ) return;
		int p = ++tot; int q = ++tot;
		adg(QD,p,1,0); 
		adg(q,ZD,1,0);
		for(int j=Lx[i];j<=Rx[i];j++) adg(p,IDX[j],1,0);
		for(int j=Ly[i];j<=Ry[i];j++) adg(IDY[j],q,1,0);
	}
	int flow = 0;
	MAXVAL = 0;
	while(spfa()) flow++;
	if(flow!=K) return;
	ANS = max(ANS,MAXVAL);
}
int main() {
	scanf("%d",&N);
	for(int i=1;i<=N;i++) {
		scanf("%d%d%lld",&X[i],&Y[i],&V[i]);
	}
	scanf("%d",&M);
	for(int i=1;i<=M;i++) {
		scanf("%s%d%d",&ss[1],&A[i],&B[i]);
		T[i] = ss[1];
	}
	for(int i=1;i<=N;i++) solve(i);
	printf("%lld",ANS);
}

Measured memory_bytes: 12672
#include <assert.h>
#include <limits>
#include <iostream>
#include <random>
#include <bitset>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <unordered_map>
#include <iterator>
#include <thread>
#include <stack>
#include <numeric>
#include <queue>
#include <unordered_set>
#include <set>
#include <sstream>
#include <iomanip>
#include <chrono>
#include <ctime>

using namespace std;

#define pv(x) printVector(x)
#define pvv(x) printVectorsOfVector(x)
#define f0(n) for(int i = 0; i < n; ++i)
#define f0e(n) for(int i = 0; i <= n; ++i)
#define f1(n) for(int i = 1; i < n; ++i)
#define f1e(n) for(int i = 1; i <= n; ++i)
#define eol cout<<endl

typedef vector<int> vi;
typedef vector<vector<int>> vvi;

template <class T>
void printVector(const vector<T>& v)
{
	for (T& i : v)
	{
		cout << i << " ";
	}
	cout << endl;
}

template <class T>
void printVectorsOfVector(const vector<vector<T>>& v)
{
	cout << " [ " << endl;
	for (size_t i = 0; i < v.size(); i++)
	{
		cout << "  ";
		cout << " [ ";
		for (size_t j = 0; j < v[i].size(); j++)
		{
			cout << v[i][j];
			if (j != v[i].size() - 1)
				cout << " , ";
		}
		cout << " ] ";
		cout << endl;
	}
	cout << " [ ";
	cout << endl;
}

////////////////////////////////////////////////////////////////////
// Write your code here onwards...
////////////////////////////////////////////////////////////////////

static int __ = []() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  std::cout.tie(nullptr);
  return 0;
}();


int main() {
  int t = 0;
  cin >> t;
	int arr[4] = { 0 };
  while (t--) {
		string v;
		cin >> v;
		if (v == "AC")
			arr[0]++;
		else if (v == "WA")
			arr[1]++;
		else if (v == "TLE")
			arr[2]++;
		else if (v == "RE")
			arr[3]++;
	}
	cout << "AC x " << arr[0] << endl;
	cout << "WA x " << arr[1] << endl;
	cout << "TLE x " << arr[2] << endl;
	cout << "RE x " << arr[3] << endl;

  return 0;
}

Measured memory_bytes: 3596
/* ex3_3
  bonbonc */

#include<stdio.h>

int main(void){
	int num,K;
	int count = 0;/*Kで何回割れるかを数える。*/
	scanf("%d %d", &num,&K);

	while(num>=K){
		num/=K;
		count++;
	}
	printf("%d\n",count+1);/*Kで割れた回数+1を出力*/

	return 0;
}

Measured memory_bytes: 128
#pragma warning(disable:4786)
#pragma warning(disable:4996)
#include<list>
#include<bitset>
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<functional>
#include<string>
#include<cstring>
#include<cstdlib>
#include<queue>
#include<utility>
#include<fstream>
#include<sstream>
#include<cmath>
#include<stack>
#include<assert.h>
using namespace std;

#define MEM(a, b) memset(a, (b), sizeof(a))
#define CLR(a) memset(a, 0, sizeof(a))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define ABS(X) ( (X) > 0 ? (X) : ( -(X) ) )
#define S(X) ( (X) * (X) )
#define SZ(V) (int )V.size()
#define FORN(i, n) for(i = 0; i < n; i++)
#define FORAB(i, a, b) for(i = a; i <= b; i++)
#define ALL(V) V.begin(), V.end()
#define IN(A, B, C)  ((B) <= (A) && (A) <= (C))

typedef pair<int,int> PII;
typedef pair<double, double> PDD;
typedef vector<int> VI;
typedef vector<PII > VP;

#define AIN(A, B, C) assert(IN(A, B, C))

//typedef int LL;
typedef long long int LL;
//typedef __int64 LL;

int p[100005], id[100005];
int x[100005], y[100005];

int find(int at) {
	if (p[at] == at) return at;
	return p[at] = find(p[at]);
}

int cmpx(int a, int b) {
	return x[a] < x[b];
}

int cmpy(int a, int b) {
	return y[a] < y[b];
}

int main()
{
	int n;
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		p[i] = i;
		scanf("%d %d", &x[i], &y[i]);
		id[i] = i;
	}
	sort(id, id + n, cmpx);
	vector<tuple<LL, int, int>> V;
	for (int i = 0; i < n - 1; i++) {
		V.push_back(make_tuple(x[id[i + 1]] - x[id[i]], id[i], id[i + 1]));
	}
	sort(id, id + n, cmpy);
	for (int i = 0; i < n - 1; i++) {
		V.push_back(make_tuple(y[id[i + 1]] - y[id[i]], id[i], id[i + 1]));
	}
	sort(ALL(V));
	LL cost = 0;
	for (tuple<LL, int, int>& q : V) {
		int a = std::get<1>(q);
		int b = std::get<2>(q);
		if (find(a) == find(b)) continue;
		cost += MIN(ABS(x[a] - x[b]), ABS(y[a] - y[b]));
		p[find(a)] = find(b);
	}
	printf("%lld\n", cost);
	return 0;
}


Measured memory_bytes: 8048
#include <bits/stdc++.h>
#define l_ength size
using ll = long long;
const ll infll = (1ll<<60);
const int mod = 1000000007;
using namespace std;

struct edge{
	int from;
	int to;
	ll cost;
};

vector<edge> graph;

vector<int> checkgraph[3000];
bool besucht[3000];

void checkdfs( int punkt ){
	if( besucht[punkt] ) return;
	besucht[punkt] = true;
	for( auto nextp : checkgraph[punkt] ){
		checkdfs( nextp );
	}
}

int main(){
	int n, m; ll p; cin >> n >> m >> p;
	const int s = 0, g = n-1;
	for( int i = 0; i < m; ++i ){
		int a, b, c; cin >> a >> b >> c;
		--a; --b;
		graph.push_back( (edge){a, b, -(c-p)} );
		checkgraph[a].push_back(b);
	}
	checkdfs(0); 
	vector<ll> d(n);
	fill_n( d.begin(), n, infll );
	// スタート地点を 0 にしておく
	d[s] = 0;
	int k = n-1;
	while( k-- ){
		for( auto e : graph ){
			if( !besucht[e.from] ) continue;
			d[e.to] = min(d[e.to], d[e.from]+e.cost);
		}
	}
	bool negativ[n];
	fill_n( negativ, n, false );
	for( auto e : graph ){
		if( !besucht[e.from] ) continue;
		if( d[e.to] > d[e.from]+e.cost ){
			d[e.to] = d[e.from]+e.cost;
			negativ[e.to] = true;
		}
	}
	k = n;
	while( k-- ){
		for( auto e : graph ){
			if( !besucht[e.from] ) continue;
			if( negativ[e.from] ) negativ[e.to] = true;
		}
	}
	if( negativ[g] ) cout << -1 << endl;
	else cout << max(0ll, -d[g]) << endl;
	return 0;
}


Measured memory_bytes: 640
#define _USE_MATH_DEFINES

//#include <bits/stdc++.h>
#include <cmath>
#include <iostream>
#include <vector>
    
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;

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

    if(k<=a){
        cout<<k<<endl;
        return 0;
    }else if(k<=a+b){
        cout<<a<<endl;
        return 0;
    }else{
        cout<<a-(k-a-b)<<endl;
        return 0;
    }


} // end of main
    
//実行は、Opt + Ctl + N


Measured memory_bytes: 3632
#include <iostream>
#include <vector>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <map>
#include <set>
#include <string>
#include <algorithm>


using namespace std;

int main() {
    string S;
    cin >> S;
    cout << ((S == "ABC") ? "ARC" : "ABC") << endl;
    return 0;
}

Measured memory_bytes: 3572
def main():
    N, K = (int(i) for i in input().split())
    R, S, P = (int(i) for i in input().split())
    T = input()
    pre = []
    win = {"r": "p", "s": "r", "p": "s"}
    ans = 0
    for i, t in enumerate(T):
        if K <= i and win[t] == pre[i-K]:
            pre.append("")
        else:
            if t == "r":
                ans += P
                pre.append("p")
            elif t == "s":
                ans += R
                pre.append("r")
            elif t == "p":
                ans += S
                pre.append("s")

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 46448
N = int(input())
W = list(map(int,input().split()))
sum_W = sum(W)
L = [W[0]]
for i in W[1:]:
    L.append(L[-1]+i)
for i in range(N):
    L[i] = abs(sum_W-2*L[i])
print(min(L))

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

deque<int> q;

long long dp[3000+1][3000+1];
bool visited[3000+1][3000+1]={};

long long ans(long long turn,long long start,long long end,long long a){
	if(start>end)
	return a;
	if(visited[start][end])
	return a+dp[start][end];
	long long b;
		if(turn==0)
		b=max(ans(1-turn,start+1,end,a+q[start]),ans(1-turn,start,end-1,a+q[end]));
		else
		b=min(ans(1-turn,start+1,end,a-q[start]),ans(1-turn,start,end-1,a-q[end]));
		dp[start][end]=b-a;
		visited[start][end]=true;
		return dp[start][end]+a;
}


int main() {
	int n,a;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a;
		q.push_back(a);
	}
	cout<<ans(0,0,n-1,0)<<endl;
	/*for(int i=0;i<n;i++){
		for(int j=0;j<n;j++)
		cout<<dp[i][j]<<" ";
		cout<<endl;
	}*/
	return 0;
}

Measured memory_bytes: 78464
x=int(input())
def judge(x):
    n=int(x**0.5)
    count=0
    while count==0:
        for i in range(2,n+2):
            if x%i==0:
                x+=1
                count=0
                break
            else:
                count=1
        
        if count==1:
            print(x)
if x==2:
    print(2)
else:
    judge(x)

Measured memory_bytes: 3060
/*    三玖天下第一！！！  */
#include<bits/stdc++.h>
using namespace std;
const int maxn=2e3;
int n,l[maxn+5]={};
long long ans=0;
inline int dread()
{
	int x=0;bool f=1;char ch=getchar();
	for(;ch<'0'||ch>'9';ch=getchar()) f^=(ch=='-');
	for(;ch>='0'&&ch<='9';ch=getchar()) x=(x<<1)+(x<<3)+(ch^48);
	return f?x:-x;
}
inline void Kaslana()
{
	n=dread();
	for(int i=1;i<=n;i++) l[i]=dread();
}
inline void Raiden()
{
	sort(l+1,l+1+n);
	for(int i=1;i<n-1;i++) for(int j=i+1;j<n;j++)
	{
		int temp=lower_bound(l+j+1,l+n+1,l[i]+l[j])-l;
		ans+=1LL*(temp-j-1);
	}
}
inline void Zaychik()
{
	printf("%lld\n",ans);
}
int main()
{
    Kaslana(),Raiden(),Zaychik();return 0;
}


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

// 1-indexed
template<typename T>
struct BIT{
    int n;
    vector<T> bit;
    BIT(int n_=0):n(n_),bit(n+1){}
    T sum(int i){
        T res=0;
        for(;i>0;i-=(i&-i))res+=bit[i];
        return res;
    }
    void add(int i,T a){
        if(i==0)return;
        for(;i<=n;i+=(i&-i)){bit[i]+=a;}
    }
    int lower_bound(T k){ // k<=sum(res)
        if(k<=0)return 0;
        int res=0,i=1;
        while((i<<1)<=n)i<<=1;
        for(;i;i>>=1){
            if(res+i<=n&&bit[res+i]<k)k-=bit[res+=i];
        }
        return res+1;
    }
};

struct UnionFind{
    vector<int> par,num;
    vector<bool> done;
    UnionFind(int n):par(n),num(n,1),done(n,false){
        iota(par.begin(),par.end(),0);  //include<numeric>
    }
    int find(int v){
        return (par[v]==v)?v:(par[v]=find(par[v]));
    }
    void unite(int u,int v){
        u=find(u),v=find(v);
        if(u==v)return;
        if(num[u]<num[v])swap(u,v);
        num[u]+=num[v];
        par[v]=u;
        done[u]=done[u]|done[v];
    }
    bool same(int u,int v){
        return find(u) == find(v);
    }
    bool ispar(int v){
        return v=find(v);
    }
    int size(int v){
        return num[find(v)];
    }
};

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int n; cin >> n;
	vector<int> x(n),y(n);
	vector<pair<pair<int,int>,int>> v;
	for(int i=0;i<n;i++){
		cin >> x[i] >> y[i];
		v.push_back(make_pair(make_pair(x[i],y[i]),i));
	}
	sort(v.begin(), v.end());
	// BIT<int> bit(n);
	UnionFind uf(n);
	priority_queue<pair<int,int>> pq;
	for(int i=0;i<n;i++){
		int k=v[i].second;
		if(i){
			auto p=pq.top(); pq.pop();
			if(-p.first<v[i].first.second){
				uf.unite(k,p.second);
			}
			while(pq.size()&&-pq.top().first<v[i].first.second){
				uf.unite(k,pq.top().second);
				pq.pop();
			}
			pq.push(p);
		}
		pq.push(make_pair(-v[i].first.second,k));
	}
	while(pq.size())pq.pop();
	reverse(v.begin(), v.end());
	for(int i=0;i<n;i++){
		int k=v[i].second;
		if(i){
			auto p=pq.top(); pq.pop();
			if(p.first>v[i].first.second){
				uf.unite(k,p.second);
			}
			while(pq.size()&&pq.top().first>v[i].first.second){
				uf.unite(k,pq.top().second);
				pq.pop();
			}
		}
		pq.push(make_pair(v[i].first.second,k));
	}
	for(int i=0;i<n;i++){
		printf("%d\n",uf.size(i));
	}
}

Measured memory_bytes: 9252
use std::io;
use std::cmp;

const INF: usize = 10_000_000_000usize;

fn main() {
    let (n, m, l) = {
        let i = read::<usize>();
        (i[0], i[1], i[2])
    };
    let mut dist = vec![vec![0; n]; n];
    for _ in 0..m {
        let (a, b, c) = {
            let i = read::<usize>();
            (i[0] - 1, i[1] - 1, i[2])
        };
        dist[a][b] = c;
        dist[b][a] = c;
    }

    let mut dp = vec![vec![INF; n]; n];
    for i in 0..n { for j in 0..n {
        if dist[i][j] != 0 { dp[i][j] = dist[i][j]; }
    }}

    for k in 0..n { for i in 0..n { for j in 0..n {
        dp[i][j] = cmp::min(dp[i][j], dp[i][k] + dp[k][j]);
    }}}

    for i in 0..n { for j in 0..n {
        if dp[i][j] <= l { dp[i][j] = 1; }
        else { dp[i][j] = INF; }
    }}

    for k in 0..n { for i in 0..n { for j in 0..n {
        dp[i][j] = cmp::min(dp[i][j], dp[i][k] + dp[k][j]);
    }}}

    let q = read_one::<usize>();
    for _ in 0..q {
        let (s, t) = {
            let i = read::<usize>();
            (i[0] - 1, i[1] - 1)
        };
        if dp[s][t] == INF { println!("-1"); }
        else { println!("{}", dp[s][t] - 1); }
    }
}


#[allow(dead_code)]
fn read<T>() -> Vec<T>
where T:
std::str::FromStr,
T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.split_whitespace()
        .map(|s| s.trim().parse().unwrap())
        .collect()
}

#[allow(dead_code)]
fn read_one<T>() -> T
where T:
std::str::FromStr,
T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.trim().parse().unwrap()
}

Measured memory_bytes: 4604
n = gets.to_i
 
i = 1
 
while i < n
    i += 1
    x = i
 
    if x % 3 == 0
        print " #{i}"
        next
    end
 
    x *= 10
    while (x /= 10) > 0
        if x % 10 == 3
            print " #{i}"
            break
        end
    end
 
end
 
puts ""

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

// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// #include <ext/pb_ds/detail/standard_policies.hpp>

using namespace std;
// using namespace __gnu_pbds;

#define int long long int
#define endl "\n"
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(c) c.begin(), c.end()

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

signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	
	int n,w;
	cin>>n>>w;
	pair<int,int> item[n+1];
	for(int i=1;i<=n;i++) {
		cin>>item[i].ff;
		cin>>item[i].ss;
	}

	int dp[n+1][w+1];
	memset(dp,0,sizeof(dp));

	for(int i=1;i<=n;i++) {
		for(int j=1;j<=w;j++) {
			if(j>=item[i].ff) {
				dp[i][j] = max(dp[i-1][j], item[i].ss + dp[i-1][j-item[i].ff]);
			} else {
				dp[i][j] = dp[i-1][j];
			}
		}
	}

	cout<<dp[n][w];

	return 0;
}

Measured memory_bytes: 79232
import java.util.*;

public class Main{

    static Scanner sc = new Scanner(System.in);

    static int n = sc.nextInt();
    static int k = sc.nextInt();

    static int mod = (int)1e9 + 7 ;
    static Map<Integer, Set<Integer>> edge;

    static boolean visit[] = new boolean[n];



    public static void main(String args[]){

        edge = new HashMap<>();
        for (int i=0; i<n; i++){
            edge.put(i, new HashSet<>());
        }
        visit[0] = true;

        for (int i=0; i<n-1; i++){
            int a = sc.nextInt()-1;
            int b = sc.nextInt()-1;

            edge.get(a).add(b);
            edge.get(b).add(a);
        }

        System.out.println(bfs(0,0,0));



    }

    private static long bfs(int v, int parent, int other) {
        int d = 0;
        long r = k - parent - other;
        for (int i : edge.get(v)) {
            if (!visit[i]) {
                visit[i] = true;
                r = (r * bfs(i, 1, parent + d))%mod;
                d++;
            }
        }
        return r;
    }
}

Measured memory_bytes: 133768
#include <iostream>
#include <cassert>
#include <climits>
#include <bitset>
#include <stack>
#include <queue>
#include <iomanip>
#include <limits>
#include <string>
#include <cmath>
#include <set>
#include <map>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string.h>

using namespace std;

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

long long int INF = 3e18;
double Pi = 3.1415926535897932384626;

vector<ll> G[500005];
vector<P> tree[500010];
priority_queue <ll> pql;
priority_queue <P> pqp;
//big priority queue
priority_queue <ll,vector<ll>,greater<ll> > pqls;
priority_queue <P,vector<P>,greater<P> > pqps;
//small priority queue
//top pop

int dx[8]={1,0,-1,0,1,1,-1,-1};
int dy[8]={0,1,0,-1,1,-1,-1,1};
char dir[] = "DRUL";
//ll bit[500005];
//↓,→,↑,←


#define p(x) cout<<x<<endl;
#define el cout<<endl;
#define pe(x) cout<<x<<" ";
#define ps(x) cout<<fixed<<setprecision(25)<<x<<endl;
#define pu(x) cout<<x;
#define re(i,n) for(i=0;i<n;i++);
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define deba(x) cout<< #x << " = " << x <<endl


ll mod = 1000000007;
ll rui(ll abc,ll bed){
    //abcのbed乗を計算する
    if(bed==0){return 1;}
    else{
        ll ced = rui(abc,bed/2);
        ced *= ced;
        ced %= mod;
        if(bed%2==1){ced*=abc; ced%=mod;}
        return ced;
    }
}
ll gcd(ll number1,ll number2){
    if(number1 > number2){
        swap(number1,number2);
    }
    if(number1 == 0 || number1 == number2){
        return number2;
    }else{
        return gcd(number2 % number1,number1);
    }
}
void YES(bool condition){
    if(condition){
        p("YES");
    }else{
        p("NO");
    }
    return;
}
void Yes(bool condition){
    if(condition){
        p("Yes");
    }else{
        p("No");
    }
    return;
}

ll n,m,num,sum,b,c,d,e,f,g,h,i,j,k,w,ok,ng,l,r,ans;
long double a;
ll x[500005],y[500005];
bool flag,dame;

ll sa[40];
void solve(ll reside,ll a,ll b,bool first){
	//pe(reside);pe(a);p(b);
	if(a == 0){
		//p(reside);
		if(reside == 0){
			ans += b;
			//p(b);
		}
		return;
	}
	if(reside < -1 * 10 * a || 10 * a < reside)return;
	for(int i=-9;i<=9;i++){
		if((reside - i * a) % 10 == 0){
			if(a == 99){
				solve((reside - i * a)/10,a / 100,b * (sa[i + 10] - first) * 10,0);
			}else{
				solve((reside - i * a)/10,a / 100,b * (sa[i + 10] - first),0);
			}
		}
	}
}

int main(){
    cin >> n;
	num = 9;
	ans = 0;
	if(n % 9 != 0){                      
		p(0);return 0;                    
	}
	for(i=0;i<20;i++){
		sa[i] = 10 - abs(10 - i);
	}
	for(int i=0;i<18;i++){
		solve(n,num,1,1);
		//p(num);
		num *= 10;
		num += 9;
	}
	p(ans);
	return 0;
}


Measured memory_bytes: 25344
import sys
from decimal import Decimal
for l in sys.stdin:
  x1,y1,x2,y2,xq,yq=list(map(Decimal,l.split(",")))
  a=x1-x2
  b=y1-y2
  c=xq-2*x1
  d=yq-2*y1
  e=yq-y1
  X=(xq*a**2-c*b**2+2*e*a*b)/(a**2+b**2)
  try:
    Y=b/a*(X+c)-d
  except:
    Y=-a/b*(X-xq)+yq
  print(" ".join(["{:.6f}".format(i) for i in [X,Y]]))


Measured memory_bytes: 6388
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
using Graph = vector<vector<int>>;
using Graphl = vector<vector<ll>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Rep(i, k, n) for (int i = k; i < (int)(n); i++)
#define RRep(i, k, n) for (int i = k; i > (int)(n); i--)
#define FOR(itr, v) for (auto itr = (v).begin(); itr != (v).end(); ++itr)
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define ALL(a)  (a).begin(),(a).end()
#define rALL(a)  (a).rbegin(),(a).rend()
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; }
template<class T> void PrintVector(const vector<T> &vec) {for (auto val : vec) cout << val << " "; cout << endl;}
const long long INF = 1LL << 60;
const long long minusINF = -(1LL << 40);
const int MOD = 1000000007;
const double PI = acos(-1); //3.14~
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int main()
{
    int n, k; cin >> n >> k;
    vector<int> p(n);
    rep(i, n) cin >> p[i];
    sort(ALL(p));
    int ans = 0;
    rep(i, k)
    {
        ans += p[i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int arr[n];
    for(int i=0;i<n;i++)
    {
        cin>>arr[i];
    }
    sort(arr,arr+n);
    int ans=0;
    for(int i=0;i<n;i++)
    {
        for(int j=i+1;j<n;j++)
        {
            if(arr[i]!=arr[j])
            {
            for(int k=j+1;k<n;k++)
            {
                if(arr[j]!=arr[k])
                {
                if(arr[i]+arr[j]>arr[k])
                {
                    ans++;
                }
                else
                {
                    break;
                }
                }
                
            }
            }
            
        }
    }
    cout<<ans<<endl;





    return 0;
}

Measured memory_bytes: 3636
import bisect
import heapq
import itertools
import math
import operator
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter, mul, add, xor

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353


N = int(sys.stdin.buffer.readline())
S = [list(sys.stdin.buffer.readline().decode().rstrip() * 2) for _ in range(N)] * 2
S = np.array(S, dtype='U1')

ans = 0
for h in range(N):
        s = S[h: h + N, 0: 0 + N]
        if np.all(s == s.T):
            ans += N
print(ans)


Measured memory_bytes: 21920
#include <vector>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <cassert>
using namespace std;
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define EACH(t,i,c) for(t::iterator i=(c).begin(); i!=(c).end(); ++i)
const double EPS = 1e-10;
const double PI  = acos(-1.0);

struct man{
	int m,a,b;
	man(int m,int a,int b):m(m),a(a),b(b){}
	bool operator<(const man &other)const{
		if(a==other.a){
			if(b==other.b){
				return m<other.m;
			}else{
				return b<other.b;
			}
		}else{
			return a<other.a;
		}
	}
};

int main(){
	int n;
	while(cin>>n,n){
		vector<man> men;
		REP(i,n){
			int m,a,b;
			cin>>m>>a>>b;
			men.push_back(man(m,a,b));
		}

		sort(ALL(men));
		vi done(n);
		int total=0;
		REP(i,n){
			total+=men[i].m;
			REP(j,n){
				if(!done[j]&&men[j].b<=men[i].a){
					total-=men[j].m;
					done[j]=1;
				}
			}
			if(total>150){
				cout<<"NG"<<endl;
				goto cont;
			}
		}
		cout<<"OK"<<endl;
		cont:1;
	}
}

Measured memory_bytes: 1192
#include<stdio.h>
int main()
{
    long long int n, a, b,c,d;
    scanf("%lld%lld%lld", &n, &a, &b);
    if (a == 0)
    {
        printf("0");
    }
    else
    {
        c = n / (a + b);
        d = n - (a + b) * c;
        if (a >= d)
        {
            printf("%lld", a * c + d);
        }
        else
        {
            printf("%lld", a * c + a);
        }
    }
    return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;

public class Main{

		public static void main(String[] args) {
			Scanner sc = new Scanner(System.in);
		    int A = sc.nextInt();
		    int B = sc.nextInt();
			int C = sc.nextInt();
			int a = 0, b = 0;

			if(A == 5) a++;
			else if(A == 7) b++;

			if(B == 5) a++;
			else if(B == 7) b++;

			if(C == 5) a++;
			else if(C == 7) b++;

			if(a == 2 && b == 1) System.out.println("YES");
			else System.out.println("NO");
		}
	

}

Measured memory_bytes: 21076
using System;
using System.Linq;

namespace A
{
    class Program
    {
        static void Main(string[] args)
        {
            var AB = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            var A = AB[0];
            var B = AB[1];

            if (A >= 13)
            {
                Console.WriteLine(B);
            }
            else if (A >= 6)
            {
                Console.WriteLine(B / 2);
            }
            else
            {
                Console.WriteLine(0);
            }
        }

        static int NumberOfDigits(long x)
        {
            if (x < 10) return 1;

            var result = 0;
            while (x > 0)
            {
                result++;
                x /= 10;
            }

            return result;
        }

        static int SumOfDigits(int x)
        {
            var sum = 0;
            while (x > 0)
            {
                sum += x % 10;
                x /= 10;
            }

            return sum;
        }
    }
}


Measured memory_bytes: 13268
#include <bits/stdc++.h>
#define ALL(obj) begin(obj), end(obj)
#define debug(x) cerr << #x << ": " << x << '\n'
using namespace std;
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template <class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}

using ll = long long;
using ull = unsigned long long;
const int INF = 2100100100;
// const int MOD = 1e9 + 7;
using P = pair<ll, ll>;
int main() {
    int Q;
    cin >> Q;
    vector<P> ans;
    priority_queue<ll, vector<ll>, greater<ll>> gq;
    priority_queue<ll> lq;
    ll B = 0;
    ll G = 0;
    ll L = 0;
    for (int q = 0; q < Q; q++) {
        int c;
        cin >> c;

        if (c == 1) {
            int a, b;
            cin >> a >> b;
            B += b;
            if (lq.empty() || gq.empty()) {
                lq.push(a);
                L += a;
            } else {
                if (gq.top() <= a) {
                    gq.push(a);
                    G += a;
                } else {
                    lq.push(a);
                    L += a;
                }
            }
            if (lq.size() + 1 <= gq.size()) {  // g が多くなっている
                ll now = gq.top();
                gq.pop();
                lq.push(now);
                L += now;
                G -= now;
            } else if (lq.size() > gq.size() + 1) {
                ll now = lq.top();
                lq.pop();
                gq.push(now);
                L -= now;
                G += now;
            }
            //cout << lq.size() << " " << gq.size() << " " << L << " " << G << " " << B << endl;
        } else if (c == 2) {
            ll now = lq.top();
            ans.push_back(make_pair(now, B + G - now * gq.size() + now * lq.size() - L));
        }
    }
    for (auto i : ans) {
        cout << i.first << " " << i.second << "\n";
    }
}


Measured memory_bytes: 5868
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
 
signed main(){
	int A, B, C, K;
	cin >> A >> B >> C >> K;
	//a < b < c
	bool flg = false;
	for(int i = 0; i < K; i++){
		if(B <= A){
			B*=2;
		}else if(C <= B){
			C*=2;
		}
		if(A < B && B < C){
			flg = true;
		}
	}
	cout << (flg?"Yes":"No") << endl;

 
	return 0;
}

Measured memory_bytes: 3540
#include<bits/stdc++.h>
#define LL long long
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPA(i,n) for(int i=1;i<(n);++i)
#define PII pair<int,int>
#define PLI pair<long long, int>
#define PLL pair<long long, long long>
#define MOD ((int)1e9 + 7)
#define INF ((int)1e9)
#define INFLL ((LL)1e18)
#define ALL(x) (x).begin(),(x).end()
#define CTOI(x) (x - 'A') 
#define ctoi(x) (x - 'a')
#define BIT(x) (1 << (x))
using namespace std;

LL modinv(LL a){
    LL b = MOD, u = 1, v = 0;
    while(b){
        LL t = a / b;
        a -= t * b;swap(a, b);
        u -= t * v;swap(u, v);
    }
    u%=MOD;
    if(u < 0) u += MOD;
    return u;
}

LL exp(LL a, LL b){
    LL res = 1;
    LL sum = a;
    while(b){
        if(b&1)res = (res * sum) % MOD;
        sum = (sum * sum) % MOD;
        b>>=1;
    }
    return res;
}
int n;
map<int, vector<int> > m;
vector<int> color;
vector<int> dp;

int func(int place){
    if(place == n){
        return 1;
    }
    if(dp[place]>=0)return dp[place];
    int res = 0;
    if(upper_bound(ALL(m[color[place]]), place) != m[color[place]].end()){
        res = res + func(*upper_bound(ALL(m[color[place]]), place));
    }
    res = res + func(place + 1);
    res %= MOD;
    return dp[place] = res;
}

int main(){
    cin >> n;
    dp.resize(n, -1);
    int bc = -1;
    int count = 0;
    REP(i, n){
        int d;
        cin >> d;
        if(d != bc){
            color.push_back(d);
            m[d].push_back(count++);
            bc = d;
        }
    }
    n = count;
    cout << func(0) << endl;
    return 0;
}


Measured memory_bytes: 45556
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <math.h>
#include <complex>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <functional>
#include <assert.h>
using ll=long long;
#define int ll
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define eb emplace_back
#define all(x) x.begin(),x.end()
#define SZ(x) ((int)x.size())
#define fi first
#define se second
const int INF = 1e15;
using namespace std;

template<class T> using vc=vector<T>;
template<class T> using vvc=vc<vc<T>>;

using pi=pair<int,int>;
using vi=vc<int>;

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

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout<<fixed<<setprecision(20);

    vi ans(26,INF);
    int N; cin >> N;
    rep(i,N){
        vi cnt(26,0);
        string S; cin >> S;
        rep(j,SZ(S)){
            cnt[S[j]-'a']++;
        }
        rep(j,26){
            chmin(ans[j],cnt[j]);
        }
    }
    rep(i,26){
        rep(j,ans[i]) cout << (char)('a'+i);
    }
    cout << endl;
}

Measured memory_bytes: 256
N, Y = map(int, input().split())
key = 0
for i in range(N + 1):
    for j in range(N - i + 1):
        if 1000 * i + 5000 * j + 10000 * (N - i - j) == Y:
            print(N - i - j, j, i)
            key = 1
            break
    if key:
        break
if not key:
    print(-1, -1, -1)


Measured memory_bytes: 40684
#include<iostream>
#include<bits/stdc++.h>
#include<iomanip>
#include<math.h>
#include<vector>
#include<cctype>
#include<string>
#include<set>
#include<map>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
std::string line;
typedef long long ll;

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

   int flg = 0;
   int cnt = 0;
   int num = 0;
   if(s[0] == 'A') flg++;
   for(int i=2;i<s.size()-1;i++) {
      if(s[i]=='C') {
         cnt++;
         num = i;
      }
   }
   if(cnt == 1) flg++;

   int ccnt = 0;
   rep(i,s.size()){
      if((s[i]>=65)&&(s[i]<=90)) ccnt++;
   }
   if(ccnt == 2) flg++;

   if(flg == 3) cout << "AC" << endl;
   else cout << "WA" << endl;



   return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long int ll;
#define forn(i,p,n); for(long long i=p;i<n;++i)

void solve(){
	ll n;
	cin >> n;
	if(n>=400 && n<=599) cout<<'8';
	if(n>=600 && n<=799) cout<<'7';
	if(n>=800 && n<=999) cout<<'6';
	if(n>=1000 && n<=1199) cout<<'5';
	if(n>=1200 && n<=1399) cout<<'4';
	if(n>=1400 && n<=1599) cout<<'3';
	if(n>=1600 && n<=1799) cout<<'2';
	if(n>=1800 && n<=1999) cout<<'1';
	return ;
}

int main()
{
	fast;
	// int test;
	// cin >> test;
	// while(test--){
		solve();
	// 	cout<<"\n";
	// }
}

Measured memory_bytes: 3644