akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mod 1000000007

int main(){
    int n; cin >> n;
    int c = 0;
    while(n != 0){
        if(n%10 == 2) c++;
        n/=10;
    }
    cout << c << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T> void assign(V<T>& v, int n, const T& a = T()) { v.assign(n, a); }
template<class T, class... U> void assign(V<T>& v, int n, const U&... u) { v.resize(n); for (auto&& i : v) assign(i, u...); }

bool query(lint n) {
  cout << "? " << n << endl;
  char c; cin >> c;
  return c == 'Y';
}

template<class T> int ord(T n, int p) { return n % p ? 0 : ord(n / p, p) + 1; }

int main() {
  cin.tie(NULL); ios::sync_with_stdio(false);
  lint l = 1e9, r = 1e10 - 1;
  while (r - l > 1) {
    lint m = (l + r) / 2;
    if (query(10 * m)) r = m;
    else l = m;
  }
  lint t = 1;
  while (t < 1e13) {
    if (!query(t)) break;
    t *= 10;
  }
  if (t >= 1e12) {
    r = 1;
    while (!query(2 * r)) r *= 10;
  }
  cout << "! " << to_string(r).substr(0, ord(t, 10)) << '\n';
}

Measured memory_bytes: 624
InputValue = input().split(' ')

N = int(InputValue[0])
R = int(InputValue[1])

if 0<=R<=4111 and 1<=N<=100:
    if N>=10:
        IR = R
        print(IR,end='\n')
    elif N<10:
        IR = R + 100*(10-N)
        print(IR,end='\n')

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define f(i,a,b) for(register int i=a;i<=b;++i)
#define ff(i,a,b) for(register int i=a;i>=b;--i)
#define debug(x) cerr << #x << " : " << x << " " << endl
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<string, string> pss;
const ll mod = 998244353;
const ll mod1 = 1e16 + 7;
const double tiaohe = 0.57721566490153286060651209;
ll oula(ll x) { ll res = x;f(i, 2, x / i) { if (x % i == 0) { res = res / i * (i - 1);while (x % i == 0) x /= i; } }if (x > 1) res = res / x * (x - 1);return res; }
ll quickmod(ll a, ll n, ll m) { ll s = 1;while (n) { if (n & 1) { s = s * a % m; }a = (a*a) % m;n = n / 2; }return s; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
void ex_gcd(ll a, ll b, ll &x, ll &y, ll &d) { if (!b) { d = a, x = 1, y = 0; } else { ex_gcd(b, a % b, y, x, d);y -= x * (a / b); } }
ll inv(ll t, ll p) { ll d, x, y;ex_gcd(t, p, x, y, d);return d == 1 ? (x % p + p) % p : -1; }
bool isPrime(ll x) { if (x == 2)return true;if (x % 2 == 0)return false;for (ll i = 2;i*i <= x;i++) if (x % i == 0)return false; return true; }
//double a = log(n) +tiaohe + 1.0 / (2 * n);
double eqa = (1 + sqrt(5.0)) / 2.0;
// freopen("in.txt", "r", stdin);
const int N = 1e5 + 5;
int t;

int main()
{
	string a, b;
	while (cin >> a >> b)
	{
		int ans = 0;
		f(i,0, a.size() - 1)
		{
			if (a[i] != b[i])ans++;
		}
		cout << ans << endl;
	}
	return 0;
}


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

using namespace std;

#define rep(i, n) for (int i = 0; i < n; ++i)
#define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)
#define stl_repr(itr, x) for (auto itr = x.rbegin(); itr != x.rend(); ++itr)
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()

using llong = long long int;

const static int MAX = 999999;
const static int MOD = 1000000007;
const static int IINF = INT_MAX;
const static llong LINF = LLONG_MAX;
const static int dx[4] = {1, 0, -1, 0};
const static int dy[4] = {0, 1, 0, -1};

template<typename T> T my_gcd(T a, T b) {
    return (a ? my_gcd(b % a, a) : b);
}
template<typename T> T my_lcm(T a, T b){
    return a * b / my_gcd(a, b);    
}

int main (int argc, char *argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n, k;
    cin >> n >> k;
    vector<int> H(n);
    rep(i, n) cin >> H[i];
    if (k >= n) {
        cout << 0 << endl;
        return 0;
    }

    sort(all(H));
    llong sum = 0;
    rep(i, n - k) {
        sum += H[i];
    }

    cout << sum << endl;
    
    return 0;
}

Measured memory_bytes: 1024
program main
    implicit none
    integer(8) n
    integer(8) sum, n3, n5, n15
    integer(8) sub
    read(*,*) n

    sum = n*(n+1)/2
    
    n3 = (n - mod(n,3))/3
    n5 = (n - mod(n,5))/5
    n15 = (n - mod(n,15))/15
    
    sub = 3*n3*(n3+1)/2 + 5*n5*(n5+1)/2 - 15*n15*(n15+1)/2

    write(*,*) sum-sub
    
end program

Measured memory_bytes: 2800
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
 
int main() {
	cin.tie(0);
    ios::sync_with_stdio(false);

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

    for(int i = 0; i < S.length(); i++) {
        int pos = i;
        bool checker = false;
        for(int j = 0; j < S.length(); j++) {
            if(S[pos] != T[j]) {
                checker = true;
                break;
            }
            pos++;
            if(pos >= S.length())
                pos = 0;
        }
        if(checker) continue;
        cout << "Yes" << endl;
        return 0;
    }

    cout << "No" << endl;
}   

Measured memory_bytes: 256
#include <stdio.h>                                                                                       
                                                                                                         
int main() {                                                                                             
    int n, k;                                                                                            
    scanf("%d %d", &n, &k);                                                                              
    int tmp;                                                                                             
    int ans = 0;                                                                                         
    for (int i = 0; i < n; i++) {                                                                        
        scanf("%d", &tmp);                                                                               
        if (tmp >= k) ans++;                                                                             
    }                                                                                                    
    printf("%d\n", ans);                                                                                 
}

Measured memory_bytes: 128
import java.io.*;
import java.util.*;
import java.math.*;

public class Main {

	Scanner sc = new Scanner(System.in);

	void run() {
		String in = sc.next();
		int[] map = new int[4];
		for (char ch : in.toCharArray()) {
			if ("KUPC".indexOf(ch) != -1)
				map["KUPC".indexOf(ch)]++;
		}
		int min = Integer.MAX_VALUE;
		for (int a : map) {
			min = Math.min(a, min);
		}
		System.out.println(min);
	}

	public static void main(String[] args) {
		Main m = new Main();
		m.run();
	}

}

Measured memory_bytes: 0
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <stack>
#include <vector>
#include <stdio.h>
using namespace std;

int n;
string s;
char s1;
int k;

int main() {

	cin >> n >> s >> k;
	s1 = s[k - 1];

	for (int i = 0; i < n; i++) {
		if (s1 != s[i]) s[i] = '*';
	}

	cout << s << endl;


	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main (void)
{
    int i,a=0,k;
    int s;
    int b[2019]={0};
    int l[2019];
    while(1){
        s=getchar();
        if(s==10)break;
        k=s-'0';
        for(i=0;i<2019;i++)l[(i*10+k)%2019]=b[i];
        l[k]++;
        a+=l[0];
        for(i=0;i<2019;i++)b[i]=l[i];
    } 
    printf("%d",a);
}

Measured memory_bytes: 1620
import math

s = input()
half_len = math.ceil(len(s) / 2)

b_s = int(s, base=2)
b_10 = int(('10' * half_len)[:len(s)], base=2)
b_01 = int(('01' * half_len)[:len(s)], base=2)

print(min(["{0:b}".format(b_s ^ b_10).count('1'), "{0:b}".format(b_s ^ b_01).count('1')]))

Measured memory_bytes: 3316
n,m = map(int,input().split())
store = []
can_num = m
cost = 0

for i in range(n):
    store.append(tuple(map(int,input().split())))

store.sort()

while can_num > 0:
    lowest_store = store.pop(0)
    buy_num = lowest_store[1] if lowest_store[1] < can_num else can_num
    cost += buy_num * lowest_store[0]
    can_num -= buy_num

print(cost)



Measured memory_bytes: 17000
import java.util.*;
import java.lang.*;
import java.io.*;

class Main
{
	public static void main (String[] args) throws java.lang.Exception
	{
		Scanner scan = new Scanner(System.in);
		String S = scan.next();
		boolean ac = false;
		for(int i = 0; i < S.length() - 1; i++){
		    if(S.charAt(i) == 'A' && S.charAt(i + 1) == 'C') ac = true;
		}
		System.out.println(ac?"Yes":"No");
	}
}

Measured memory_bytes: 22996
#include <bits/stdc++.h>
typedef long long int ll;
using namespace std;
int main() {
    int n, m;
    string s;
    cin >> n >> m >> s;
    vector<int> ans;
    int start = n;
    while (start) {
        int deme = m;
        while (deme) {
            //cout << deme << endl;
            if ((start - deme >= 0) && (s[start - deme] == '0')) {
                start -= deme;
                ans.push_back(deme);
                break;
            }
            if (deme == 1) {
                cout << -1 << endl;
                return 0;
            }
            deme--;
        }
    }
    for (int i = ans.size() - 1; i >= 0; i--) {
        cout << ans[i] << " ";
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 4072
#include<bits/stdc++.h>
#include<vector>
using namespace std;
int main(void){

  while(true){
    int n, p;   cin >> n >> p;
    if(n == 0 && p == 0)    break;

    vector<int> koishi(n , 0);
    int ans = 0, remain = p;
    while(true){

      if(remain == 0){
        remain += koishi[ans];
        koishi[ans] = 0;
      }else{
        koishi[ans]++;
        remain--;
        if(koishi[ans] == p)   break;
      }

      ans = (n == ++ans) ? 0 : ans;
    }

    cout << ans << endl;

   }

  return 0;
}



Measured memory_bytes: 3096
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define SORT(a) sort(a.begin(), a.end())
#define REVERSE(a) reverse(a.begin(), a.end())
#define int long long
#define INF 1000000000000000000
using namespace std;

typedef vector<int> vec;
typedef vector<vec> mat;
typedef pair<int, int> Pii;

template<typename T>
void readvec(vector<T> &a);
void readindex(vector<int> &a);

bool check_condition(int l, int x, int i, int j, int k){
    if(x == 3){
        if(l <= i && l <= j && l <= k){
            return true;
        }else{
            return false;
        }
    }
    if(x == 2){
        if(l <= i && l <= j && k < l){
            return true;
        }else{
            return false;
        }
    }
    if(x == 1){
        if(l <= i && j < l && k < l){
            return true;
        }else{
            return false;
        }
    }
}

signed main(){

    int N, M; cin >> N >> M;
    vec l(M), r(M), x(M);
    REP(i, M) cin >> l[i] >> r[i] >> x[i];
    mat condition(N + 1, vec(0));
    REP(i, M) condition[r[i]].push_back(i);

    int mod = 1000000007;

    vector<mat> dp(N + 1, mat(N + 1, vec(N + 1, 0)));
    dp[0][0][0] = 1;

    FOR(i, 1, N + 1){
        FOR(j, 0, i){
            FOR(k, 0, j + 1){
                if(j == k && j > 0) continue;
                //dp[i][j][k]を求める
                bool satisfy = true;
                REP(c, condition[i].size()) if(!check_condition(l[condition[i][c]], x[condition[i][c]], i, j, k)) satisfy = false;
                if(!satisfy){
                    dp[i][j][k] = 0;
                }else{
                    if(i == j + 1){
                        REP(l, j + 1) dp[i][j][k] = (dp[i][j][k] + dp[l][j][k]) % mod;
                    }else{
                        dp[i][j][k] = dp[i - 1][j][k];
                    }
                }
                //対称性より
                dp[i][k][j] = dp[i][j][k];
                dp[j][i][k] = dp[i][j][k];
                dp[j][k][i] = dp[i][j][k];
                dp[k][i][j] = dp[i][j][k];
                dp[k][j][i] = dp[i][j][k];
            }
        }
    }

    int ans = 0;
    FOR(j, 0, N){
        FOR(k, 0, N){
            ans = (ans + dp[N][j][k]) % mod;
        }
    }
    ans = (ans * 3) % mod;

    cout << ans;

    return 0;
}


template<typename T>
void readvec(vector<T> &a){
    REP(i, a.size()){
        cin >> a[i];
    }
}
void readindex(vector<int> &a){
    REP(i, a.size()){
        cin >> a[i];
        a[i]--;
    }
}

Measured memory_bytes: 216832
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <algorithm>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,b) FOR(i,0,b)
#define PB push_back
#define MP make_pair
int main(){
  int n;
  while(cin>>n,n){
    int ans[2];
    ans[1]=0;
    for(int i=0;i<n;i++){
      int id,d1,d2;
      cin>>id>>d1>>d2;
      if(ans[1]<d1+d2){
        ans[0]=id;
        ans[1]=d1+d2;
      }
    }
    cout<<ans[0]<<" "<<ans[1]<<endl;
  }
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()

int main() {
    int A, B, C, X, Y;
    cin >> A >> B >> C >> X >> Y;
    int res = -1;
    rep(c, 0, 2 * (X > Y ? X : Y) + 1) {
        int m = A * max(X - c/2, 0) + B * max(0,Y - c/2) + C * c;
        if (m < res || res == -1) res = m;
    }
    cout << res << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
#define REP(i,b,n) for(int i=b;i<n;i++)
#define rep(i,n)   REP(i,0,n)

const int N = 14;
const int inf = (1 << 20);

int asum[1<<N],bsum[1<<N];
int dp[1<<N];

int cut;

int search(int n,int state,int r,int cost){
  if (dp[state] != -1){
    cut=min(cut,cost+dp[state]);
    return dp[state];
  }
  if (state == (1<<n)-1){
    cut=min(cut,cost);
    return 0;
  }

  if (cost >= cut)return inf-1;
  
  int ret = inf;
  int cnt=0;
  int cpy[n];
  /*  
  rep(i,n)if ( (state&(1<<i)) == 0)cpy[cnt++]=i;

  REP(i,1,1<<cnt){
    int next=0;
    rep(k,cnt)if ( (i&(1<<k)) != 0)next|=(1<<cpy[k])
;    if (r+asum[state]-bsum[state] >= bsum[next]){
      ret=min(ret,search(n,state|next,r)+1);
    }
  }
  */
  REP(i,1,1<<n){
    if (i&state)continue;
    int next=i;
    if (r+asum[state]-bsum[state] >= bsum[next]){
      ret=min(ret,search(n,state|next,r,cost+1)+1);
    }    
  }

  return dp[state] = ret;
}

main(){
  int n,r;
  while(cin>>n>>r){
    if (n == 0 && r == 0)break;
    int be[n],af[n];
    rep(i,n)cin>>be[i]>>af[i];


    rep(i,(1<<n)){
      dp[i]=-1;
      asum[i]=0;
      bsum[i]=0;
      rep(j,n)if ((i&(1<<j)) != 0)asum[i]+=be[j],bsum[i]+=af[j];
    }
  
    //    int ans = solve(n,r,be,af);
    cut = inf;
    int ans = search(n,0,r,0);
    if (ans == inf)cout << "Impossible"<<endl;
    else cout << ans << endl;
  }
}


/*
int solve(int n,int r,int *be,int *af){
  static int asum[1<<N],bsum[1<<N];
  static int dp[1<<N];
  static int cpy[N];

  rep(i,(1<<n)){
    dp[i]=inf;
    asum[i]=0;
    bsum[i]=0;
    rep(j,n)if ((i&(1<<j)) != 0)asum[i]+=be[j],bsum[i]+=af[j];
  }
  
  dp[0]=0;

  rep(i,1<<n){
    if (dp[i] == inf)continue;
    int cnt =0;
    rep(j,n)if ((i&(1<<j)) == 0 )cpy[cnt++]=j;
    rep(j,(1<<cnt)){
      int next=0;
      rep(k,cnt)if ( (j&(1<<k)) == 0)next|=(1<<cpy[k]);
      if (r+asum[i]-bsum[i] >= bsum[next]){
	dp[i|next]=min(dp[i|next],dp[i]+1);
      }
    }
  }
  return dp[(1<<n)-1];
}
*/

Measured memory_bytes: 1056
#include <stdio.h>

int main(){
    char s[4] = {0};
    int i = 0;
    
    scanf("%s",s);
    
    for(i = 0 ; i < 4 ;i++){
        if(i > 0 && s[i] == s[i-1]){
            printf("Bad\n");
            return 0;
        }
        /* 
        if(s[i] == s[i-1] && i > 0)
            break;
            */
    }
    
      printf("Good\n");
    
    
    return 0;

}

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

int main()
{
	string s;
	cin >> s;
	string alphabet = { "abcdefghijklmnopqrstuvwxyz" };
	string result;
	map<char, int> m;

	for(char c:s)m.emplace(c, 1);
	for (char c : alphabet) {
		if (m.count(c) == 0) {
			result = c;
			break;
		}
		else {
			result = "None";
		}
	}
	cout << result;
	cin >> s;

	return 0;
}


Measured memory_bytes: 512
#include <stdio.h>
int main(void){
	int W,H,x,y,r;
	scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);
	if(x-r>=0 && x+r<=W && y-r>=0 && y+r<=H){
		printf("Yes\n");
	}else{
		printf("No\n");
	}
	return 0;
}

Measured memory_bytes: 1012
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
constexpr int MOD = 1000000000 + 7;
constexpr int INF = 2000000000;
using namespace std;

long long N, a, b;
long long h[100001];
long long maxl = 0;

bool cond(long long n) {
	long long moreD = n;
	for (int i = 0; i < N; i++) {
		if (b*n < h[i]) {
			if ((h[i] - b*n) % (a - b) == 0)moreD -= (h[i] - b*n) / (a - b);
			else moreD -= (h[i] - b*n) / (a - b) + 1;
		}
	}
	return moreD >= 0;
}

int main() {
	cin >> N >> a >> b;
	for (int i = 0; i < N; i++)cin >> h[i],maxl=max(maxl,h[i]);

	long long left = 0, right = maxl;
	while (right - left > 1) {
		long long mid = (left + right) / 2;
		if (cond(mid)) right = mid;
		else left = mid;
	}
	cout << right << endl;
}

Measured memory_bytes: 1024
#include<stdio.h>

int main(void){
    int N, i;
    int max=0, sum=0;
    

    scanf("%d", &N);
    int L[N+1];


    for(i=0;i<N;i++){
	scanf("%d", &L[i]);
	sum += L[i];
	if (max < L[i]) max = L[i];
    }


    sum -= max;

    if(sum > max){
	printf("Yes");	
    }
    else{
	printf("No");
    }

    return 0;
}




Measured memory_bytes: 128
#!/usr/bin/env python3
import sys
try:
    from typing import List
except ImportError:
    pass


def f(b: "List[int]", l1: "List[int]", l2: "List[int]"):
    result = [0] * len(l2)
    i = 0
    t = 0
    for j, l2j in enumerate(l2):
        while i < len(l1) and l1[i] < l2j:
            t += b[i]
            i += 1
        result[j] = t
    return result


def solve(N: int, A: "List[int]", B: "List[int]", C: "List[int]"):
    A.sort()
    B.sort()
    C.sort()
    ba = [1] * N
    bb = f(ba, A, B)
    bc = f(bb, B, C)
    print(sum(bc))


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    B = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    C = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A, B, C)


if __name__ == '__main__':
    main()


Measured memory_bytes: 32996
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;
int main() {
	int n, m;
	cin >> n >> m;
	int a[n];
	int sum = 0;
	int res = 0;
	for (int i = 0; i < n; i++){
		cin >> a[i];
		sum += a[i];
	}
	float j = (float)sum / (4.0*m);
	for (int i = 0; i < n; i++){
		if (a[i] >= j) res++;
	}

	if (res >= m) cout << "Yes" << endl;
	else cout << "No" << endl;


}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
#include <cstdio>
#include <tuple>
#include <numeric>
using namespace std; using ll = long long; using ld = long double;  using pll = pair<ll, ll>;
using vl = vector<ll>; using vll = vector<vl>; using vpll = vector<pll>;
using vs = vector<string>; using tll = tuple<ll, ll, ll>; using vtll = vector<tll>;
const ld PI = 3.1415926535897932;
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define mp make_pair
#define mt make_tuple
void in() {}
void debug_out() { cerr << endl; }
template<typename Head, typename... Tail>
void debug_out(Head h, Tail... t) {
	cerr << " " << h;
	if (sizeof...(t) > 0) cerr << " :";
	debug_out(t...);
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> vec) {
	for (size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
	return os;
}
ll ctoi(char c) {
	switch (c) {
	case '0': return 0; case '1': return 1; case '2': return 2;
	case '3': return 3; case '4': return 4; case '5': return 5;
	case '6': return 6; case '7': return 7; case '8': return 8;
	case '9': return 9;  default: return 0;
	}
}
bool pairCompare(const pll firstElof, pll secondElof)
{
	return firstElof.first > secondElof.first;
}
//**Snippetリスト**//
//rep, vin, all, iteLoop, bitSearch, bitList, nod//
//gcdlcm, isPrime, eratos, primeFactorize, Npow, combination, divisor, modinv, doubling, digitDP//
//dfs, bfs, dijkstra, WarshallFloyd, BellmanFord, UnionFind, Kruskal ,RMQ, LCA//
ll i, j, k, l; ll N, M, K, H, W, L, X, Y, Z, R, Q;
ll MOD = 1000000007, INF = 1LL << 60, ans = 0, z = 0, o = 1;
vl flag, D; vpll path;
//***********//
int main() { 
	cin >> H >> W >> N;
	map<pll,ll> M;
	for (i = 0; i < N; i++) {
		ll a, b;
		cin >> a >> b;
		for (j = 0; j < 3; j++) {
			for (k = 0; k < 3; k++) {
				ll p=a, q=b;
				if (j == 0) p--; if (j == 2) p++;
				if (k == 0) q--; if (k == 2) q++;
				if(p>=2 && p<=H-1 && q>=2 && q<=W-1) M[mp(p,q)]++;
			}
		}
	}
	vl Ans(10, 0);
	Ans[0] = (H-2) * (W-2);
	//debug(M.size());
	for (auto x : M) {
		Ans[x.second]++;
		Ans[0]--;
	}
	for (i = 0; i < 10; i++) {
		cout << Ans[i] << endl;
	}
}

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

using namespace std;
int main(void){
    // Your code here!
    int a, b;
    cin >> a >> b;
    
    int seki = a * b;
    
    if ( seki % 2 != 0 ){
        cout << "Odd" << endl;
    } else if ( seki % 2 == 0){
        cout << "Even" << endl;
    } else {
        cout << "Even" << endl;
    }
}

Measured memory_bytes: 3636
#include<iostream>
#include<complex>
#include<vector>
#include<cmath>
#include<cstdio>
using namespace std;
typedef complex<double> P;
typedef vector<P> G;
const double PI=acos(-1);
const double EPS=1e-8;
const double inf=1e8;
#define rep(i,a) for(int i=0;i<a;i++)
double dp[20][20][10010];
int main(){
  rep(i,20)rep(j,20)rep(k,10010)dp[i][j][k]=inf;
  int n;
  double x,y;
  cin>>n>>x>>y;
  y*=PI/180;
  G g(n);
  rep(i,n){
    int a,b;
    cin>>a>>b;
    g[i]=P(a,b);
  }
  double D[20][20]={0};
  double A[20][20]={0};
  rep(i,n)rep(j,n)A[i][j]=arg(g[i]-g[j]);
  rep(i,n)rep(j,n)D[i][j]=abs(g[i]-g[j]);
  dp[0][0][0]=0;
  rep(i,10010)rep(j,n)rep(k,n)if(i==0||j!=k){
    rep(l,n)if(l!=k){
      double dis=D[l][k];//abs(g[k]-g[l]);
      //if(i==0)printf("%.9f %.9f\n",x,dis+dp[j][k][l]);
      if(dis+dp[j][k][i]>x)continue;
      double q=A[k][j]-A[l][k];// arg(g[k]-g[j])-arg(g[l]-g[k]);
      if(q<0)q*=-1;
      while(q>PI)q=2*PI-q;//q-=PI;
      if(i==0){
    q=0;//abs(arg(g[l]-g[k]));
      }
      if(q>y)continue;
      dp[k][l][i+1]=min(dp[k][l][i+1],dp[j][k][i]+dis);
    }
  }
  int out=0;
  rep(i,n)rep(j,n)rep(k,10010)if(abs(dp[i][j][k]-inf)>EPS)out=max(out,k);
  cout<<out<<endl;
}

Measured memory_bytes: 32608
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            int a = in.nextInt();
            out.println(n % 500 <= a ? "Yes" : "No");
        }

    }
}



Measured memory_bytes: 21972
//Jai Bhole Ki
#include <bits/stdc++.h>
using namespace std;
#define fast static int fastline = []() { std::ios::sync_with_stdio(false); cin.tie(NULL); return 0; }();
#define ll long long
#define LL unsigned ll
#define pb push_back
#define pi pair<ll,ll>
#define debug(x) cout<<x<<"\n";
#define debugg cout<<"debugged\n";
#define setpr(xval) cout<<fixed<<setprecision(12)<<xval<<endl;
#define minval -2e9
#define maxval 2e9
long double PI =3.14159265358979323846;
 
const ll M=1e9+7;
const ll inf=1e18;
const ll ms=2e5+5;
fast;
ll n,m,k,ans;
void solve()
{
    cin>>n;
    ll sum=0,maxi=0;
    for(ll i=0;i<n;i++)
    {
        cin>>k;
        maxi=max(maxi,k);
        sum+=k;
    }
    //cout<<sum<<" "<<maxi<<endl;
    if(sum>maxi*2)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
}

int main()
{
 // freopen("input.txt","r",stdin);
//  freopen("output.txt","w",stdout);
    //int t;cin>>t;while(t--)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#define N 100
int main(){
  int i,j,k,l,m,n;
  int G[N][N]={0};
  scanf("%d",&n);
  for(m=0;m<n;m++){
    scanf("%d%d",&i,&k);
    for(l=0;l<k;l++){
      scanf("%d",&j);
      G[i-1][j-1]=1;
    }
  }
   
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      if(j<n-1) printf("%d ",G[i][j]);
      else printf("%d\n",G[i][j]);
    }
  }
  return 0;
}


Measured memory_bytes: 2056
def run(r, D, x2000):
    x = x2000
    for i in range(10):
        x = r*x - D
        print(x)


def main():
    r, D, x2000 = map(int, input().split())
    run(r, D, x2000)


if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
def main():
    N = int(input())
    S=[i for i in input().rstrip()]
    ans_list=[]
    for s in S:
        data = int(ord(s))+N
        if data >= 91:
            data = data -26
        ans_list.append(chr(data))
    print(''.join(ans_list))


#    for string in S:
#    print(string_list)

if __name__ == "__main__":
    main()

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef long long ll;
const long long INF = 1LL << 60;
typedef pair<int, int> P;
int main()
{
    int N;
    cin >> N;
    vector<int> A(N);
    rep(i, N) cin >> A[i];

    vector<ll> X(N);
    X[0] = A[1];
    repd(i, 2, N) X[0] ^= A[i];

    rep(i, N - 1) {
        X[i + 1] = X[i] ^ A[i] ^ A[i + 1];
    }

    rep(i, N) cout << X[i] << endl; 
    return 0;
}

Measured memory_bytes: 5628
#include <bits/stdc++.h>
using namespace std;
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; }
using ll = long long;
using P = pair<ll, ll>;
ll GCD(ll a, ll b) { return b?GCD(b, a%b):a; }
ll LCM(ll a, ll b) { return a/GCD(a, b)*b; }

const ll MAX_S = 1000000;
int D;

vector<ll> cvec(26, 0);
vector< vector<ll> > smap(365, vector<ll>(26, 0));
vector<int> lastvec(26, 0);

ll Scalc(int today, int no, ll now) {
    // その日のコンテストの満足度
    now += smap.at(today).at(no);
    // コンテストが行われた記録
    lastvec.at(no) = (today+1);
    // 行われなかったコンテストへの不満
    for(int i = 0; i < 26; ++i) {
        now -= (cvec.at(i)*((today+1) - lastvec.at(i)));
    }
    return now;
}

struct sdata {
    ll sss; int no;
    bool operator<(const sdata &r) const { return sss > r.sss; }
};

int main() {
    cin >> D;
    for(int i = 0; i < 26; ++i) cin >> cvec.at(i);
    for(int i = 0; i < D; ++i) {
        for(int j = 0; j < 26; ++j) {
            cin >> smap.at(i).at(j);
        }
    }

    vector<int> tvec(D, 0);
    ll ans = 0;
    for(int i = 0; i < D; ++i) {
        // 毎日どれを選ぶか決める
        ll sum = 0;
        int tmax = 0;
        for(int j = 0; j < 26; ++j) {
            ll chsum = Scalc(i, j, ans);
            if(sum < chsum) {
                // その日の一番を採用
                sum = chsum;
                tmax = j;
            }
        }
        tvec.at(i) = tmax+1;
    }
    
    for(int i = 0; i < D; ++i) {
        cout << tvec.at(i) << endl;
    }
}

Measured memory_bytes: 3708
$<.readlines.map(&:to_i).each do |n|
  co = 0
  10.times do |a|
    10.times do |b|
      10.times do |c|
        10.times do |d|
          co += 1 if a + b + c + d == n
        end
      end
    end
  end
  puts co
end


Measured memory_bytes: 6872
package main

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

var nextString func() string

func init() {
	nextString = newReadString(os.Stdin)
}

func main() {
	x := nextInt()
	y := nextInt()
	z := nextInt()

	fmt.Println((x - z) / (y + z))
}

func nextInt() (result int) {
	result, _ = strconv.Atoi(nextString())
	return
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	return func() string {
		if !r.Scan() {
		}
		return r.Text()
	}
}


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <map>

using namespace std;

#define int long long

signed main() {
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; i++) cin >> a[i];

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

    for(int i = 0; i < n - 1; i++) {
        if(a[i] == a[i + 1]) {
            cout << "NO" << endl;
            return 0;
        }
    }

    cout << "YES" << endl;
    return 0;
}

Measured memory_bytes: 1920
def main():
    import sys
    input = sys.stdin.readline
    
    def f(a):
        if a < 10:
            return 1
        elif a < 100:
            return 0
        elif a < 1000:
            return 1
        elif a < 10000:
            return 0
        elif a < 100000:
            return 1
        else:
            return 0
        
        
    
    a = int(input())
    
    print(sum([f(i) for i in range(1, a + 1)]))
    
    return 0

main()

Measured memory_bytes: 3864
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#include<algorithm>//next_permutation
#define rep(i,n) for (int i = 0;i < (n);i++)
#define all(v) v.begin(),v.end()
#define dec(n) cout << fixed << setprecision(n);
#define large "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
#define small "abcdefghijklmnopqrstuvwxyz"
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;

ll gcd(ll a,ll b){
  if(b == 0) return a;
  return gcd(b , a % b);
}

const ll MOD = 1000000007;
const ll MAX = 2000001;

ll mod(ll a){
  return a % MOD;
}

ll lcm(ll a,ll b){
  return (a*b)/gcd(a,b);
}

ll fac[MAX], finv[MAX], inv[MAX];

void nCrprep() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

ll nCr(ll n, ll r){
    if (n < r) return 0;
    if (n < 0 || r < 0) return 0;
    return fac[n] * (finv[r] * finv[n - r] % MOD) % MOD;
}

ll nCrcheep(ll n,ll r){
  if(r == 0) return 1;
  else if(r == 1) return n;
  else return nCrcheep(n-1,r-1)*n/r;
}

vector<pair<ll,ll>> prime_factorize(ll n){
  vector<pair<ll,ll>> res;
  
  for(ll i=2; i*i <= n; i++){
    if(n % i != 0) continue;
    
    ll ex = 0;
    while(n % i == 0){
      ex++;
      n /= i;
    }
    
    res.push_back({i,ex});
  }
  
  if(n != 1) res.push_back({n,1});
  
  return res;
  
}




int main(){
  ll n,k; cin >> n >> k;
  vl p(n);
  
  ll cnt = 0;
  for(ll i=1; i <= n; i++){
    cnt = 0;
    
    ll pnt = i;
    
    while(pnt < k){
      cnt++;
      pnt *= 2;
    }
    p[i-1] = cnt;
  }
  
  ll sum = 0;
  
  vl p2(30); p2[0] = 1; rep(i,29) p2[i+1] = p2[i] *2;
  
  rep(i,n){
    sum += p2[p[0]-p[i]];
  }
  
  dec(15);
  cout << sum/(long double)(n)/(long double)(p2[p[0]]) << endl;
  
}

Measured memory_bytes: 3948
#include <bits/stdc++.h>
using namespace std;
#define boost ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define rando mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define fi first
#define se second
#define debug(x) cerr << " - " << #x << ": " << x << endl;
#define debugs(x, y) cerr << " - " << #x << ": " << x << " " << #y << ": " << y << endl;
#define debugii(x) cerr << " - " << #x << ": " << x.fi<<","<<x.se << endl;
#define sep() cerr << "--------------------" << endl;
#define all(x) (x).begin(),(x).end()
#define sz(x) (ll)x.size()
#define ll long long
#define ii pair<int,int>
#define v vector<int>
#define vii vector<ii>
#define vv vector<vector<int> >
#define mp make_pair
#define INF 1000000000
#define pb push_back
#define EPS 1e-9
const int MOD = 1000000007; // 998244353
int close[100001][2];
int ans[100001];
int main(){
	boost;
	string ph;
	cin>>ph;
	int prev=0;
	for (int i = 1; i < sz(ph); ++i)
	{
		if(ph[i]=='L')close[i][0]=prev;
		else prev=i;
	}
	prev=sz(ph)-1;
	for (int i = sz(ph)-2; i >= 0; i--)
	{
		if(ph[i]=='R')close[i][1]=prev;
		else prev=i;
	}
	for (int i = 0; i < sz(ph); ++i)
	{
		if(ph[i]=='L'){if((i-(close[i][0]+1))&1)ans[close[i][0]]++;else ans[close[i][0]+1]++;}
		else{if((close[i][1]-i-1)&1)ans[close[i][1]]++;else ans[close[i][1]-1]++;}
	}
	for (int i = 0; i < sz(ph); ++i)
		cout<<ans[i]<<" ";
	return 0;
}
//long long
//array bounds
//special cases
//binary search

Measured memory_bytes: 1872
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<functional>
#include<math.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pf(n) printf("%d\n",n)
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = 1001001001;
const double PI = acos(-1);

int main() {
	int n;
	cin >> n;
	vector<int> a(n - 1);
	rep(i, n-1) cin >> a[i];

	map<int, int> b;
	rep(i, n - 1) {
		a[i]--;
		b[a[i]]++;
	}
	rep(i, n) {
		pf(b[i]);
	}

	return 0;
}

Measured memory_bytes: 13644
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>

using namespace std;

#define reps(i,f,n) for(int i=f;i<int(n);i++)
#define rep(i,n) reps(i,0,n)
#define pb push_back

int a,b,c;
bool input(){
	cin>>a>>b>>c;
	if(c==0)return false;
	return true;
}

int calc(int zei, int val){
	return val * (zei+100)/100;
}

void solve(){
	
	int maxi = -1;
	reps(i,1,1001){
		reps(j,1,1001){
			int t1 = calc(a,i) + calc(a,j);
			int t2 = calc(b,i) + calc(b,j);
			
			if(t1==c){
				if(t2==27){
				}
				maxi = max(maxi, t2);
			}
		}
	}
	cout<<maxi<<endl;
}

int main(){
	while(input())solve();
}

Measured memory_bytes: 1164
import fractions

n, start = [int(i) for i in input().split()]
x = [int(i) for i in input().split()]

if n == 1:
    print(abs(x[0]-start))
    exit()
dist = [0 for i in range(n)]
for i in range(n):
    dist[i] = abs(start-x[i])
max_div = 1000000000
for i in range(1, n):
    max_div = min(max_div, fractions.gcd(dist[i-1], dist[i]))
print(max_div)

Measured memory_bytes: 16276
#include <algorithm>
#include <iostream>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
typedef long long ll;

using namespace std;

int main() {
  int n;
  cin >> n;
  int ans = 0;
  if (n % 2 == 0) {
    ans = n / 2 - 1;
  } else {
    ans = n / 2;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define REP(i,n) for(int i=0;i< (n);i++)
#define REPR(i, n) for(int i = (n);i >= 0;i--)
#define FOR(i, m, n) for(int i = (m);i < (n);i++)
#define FORR(i, m, n) for(int i = (m);i >= (n);i--)
#define SORT(v, n) std::sort(v, v+n);
#define VSORT(v) std::sort(v.begin(), v.end());
#define VRSORT(v) std::sort(v.rbegin(), v.rend());
#define ll long long
#define pb(a) push_back(a)
#define ALL(obj) (obj).begin(),(obj).end()

using namespace std;

const int INF = 99999999;
const ll LINF = 9999999999999;

typedef pair<int, int> P;
typedef pair<ll, ll> LP;
int vx[4] = { 0,1,0,-1 };
int vy[4] = { 1,0,-1,0 };


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

	ll x, y;
	cin >> x >> y;
	ll a = x;
	ll num = 0;
	while (a <= y) {
		a *= 2;
		num++;
	}

	cout << num;
	
	return 0;

}

Measured memory_bytes: 256
N = int(input())
T = 0
pos = [0, 0]
for i in range(N):
  t, x, y = map(int, input().split())
  if (t - T) >= abs(x - pos[0]) + abs(y - pos[1]) and ((t - T) - abs(x - pos[0]) - abs(y - pos[1])) % 2 == 0:
    T = t
    pos = [x, y]
  else:
    print('No')
    break
else:
  print('Yes')

Measured memory_bytes: 3064
c[5004],d[5004],m,u,i,f="%d\n";main(t){for(scanf("%d%*d",c);i<*c;scanf(f,++i+c));for(;~scanf(f,d);)for(u=i=t=0;i++<*c;t=d[i],d[i]=m<u?m=u:u)u=*d-c[i]?u:t+1;m=!printf(f,m);}

Measured memory_bytes: 404
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define mod 1000000007
#define MAX  1e18
#define ss 1e15
#define pb push_back

int main() {
    int n,k;
    cin>>n>>k;
    string s;
    cin>>s;
    k-=1;
    s[k] = (char)(s[k]-'A'+'a');
    cout<<s<<"\n";
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main(void)
{
  char str[1010],*p;
  int n;
  scanf("%d\n",&n);
  while(n--){
    fgets(str,sizeof(str),stdin);
    while(p=strstr(str,"Hoshino"))*(p+6)='a';
    printf(str);
  }
  return 0;
}

Measured memory_bytes: 0
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;
int n,w[1005],sum1[105],sum2[105],minn=0x7fffffff;
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;++i){
		scanf("%d",w+i);
		sum1[i]=sum1[i-1]+w[i];
	}
	for(int i=n;i>=0;--i){
		sum2[i]=sum2[i+1]+w[i];
		minn=min(abs(sum2[i+1]-sum1[i]),minn);
	}
	printf("%d\n",minn);
	return 0;
}


Measured memory_bytes: 1716
#include <stdio.h>

int main()
{
	int N,M;
	int C;

	scanf("%d%d%d", &N,&M,&C);

	int A[N][M];
	int B[M];
	int i,j;

	for (i=0; i<M ; i++){
		scanf("%d", &B[i]);
	}

	for (i=0; i<N ; i++){
		for (j=0; j<M ; j++){
			scanf("%d", &A[i][j]);
		}
	}


	int count=0;
	int tot = C;
	for (i=0; i<N ; i++){
		tot = C;
		for (j=0; j<M ; j++){
			tot += A[i][j] * B[j] ;
		}
		if (tot > 0 ){
			count += 1;
		}
	}


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



	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
constexpr int MOD = 1000000007;
constexpr int INF = numeric_limits<int>::max() / 2;
typedef pair<int,int> P;
using Graph = vector<vector<int>>;



signed main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);

    int N, K;
    cin >> N >> K;
    int A[N];
    rep(i,N) cin >> A[i];

    int ans = 0;
    rep(i,K+1){
        priority_queue<int, vector<int>, greater<int>> que1;
        int num = 0;
        if(i >= N){
            rep(j,N) que1.push(A[j]);

            rep(j,K-i){
                if(!que1.empty()){
                    if(que1.top() < 0) que1.pop();
                }
                else break;
            }
            while(!que1.empty()){
                num += que1.top();
                que1.pop();
            }
            ans = max(ans, num);
        }
        else{
            rep(k,i+1){
                num = 0;
                rep(l,k){
                    que1.push(A[l]);
                }
                rep(l,i-k){
                    que1.push(A[N-1-l]);
                }

                rep(j,K-i){
                    if(!que1.empty()){
                        if(que1.top() < 0) que1.pop();
                    }
                    else break;
                }
                while(!que1.empty()){
                    num += que1.top();
                    que1.pop();
                }
                ans = max(ans, num);
            }
        }
    }
    cout << ans << endl;
}

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

int main()
{
	int a, b, c, k;
	cin >> a >> b >> c >> k;
	if (k <= a)
	{
		cout << k << "\n";
	}
	else if (k<=b+a)
	{
		cout << a << "\n";
	}
	else
	{
		cout << a - (k - a - b) << "\n";
	}
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define pob pop_back
#define fi first
#define se second
#define REPP(i,l,r,c) for (int i=l;i<r;i+=c)
#define REP(i,l,r) REPP(i,l,r,1)
#define REPS(i,l,r) REP(i,l,r+1)
#define FOR(i,n) REP(i,0,n)
#define FORS(i,n) REPS(i,1,n)
#define REPD(i,l,r) for (int i=r-1;i>=l;i--)
#define FORD(i,n) REPD(i,0,n)
#define FOREACH(x,v) for(auto x:v)
using namespace std;

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

const int INF=1E9;
const ll INFLL=1E15;
const double INFD=1E9;
const ll MOD=1E9+7;
const double EPS=1E-9;
const double PI=acos(-1.0);

inline bool between(int x,int l,int r) {
	return (l<=x && x<=r);
}

ll n,m;

ll hitung (ll x,ll y,ll z) {
	vector<ll> V; V.pb(x); V.pb(y); V.pb(z); sort(V.begin(),V.end()); return V.back()-V[0];
}

inline ll work() {
	ll ret=INF;
	REP(i,1,n) {
		int sisa=n-i;
		if (sisa&1) ret=min(ret,hitung(i*m,(sisa/2)*m,(sisa/2+1)*m));
		else ret=min(ret,hitung(i*m,(sisa/2)*m,(sisa/2)*m));
		if (m&1) ret=min(ret,hitung(i*m,(m/2)*sisa,(m/2+1)*sisa));
		else ret=min(ret,hitung(i*m,(m/2)*sisa,(m/2)*sisa));
	}
	return ret;
}

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin>>n>>m; ll ans=work(); swap(n,m); ans=min(ans,work()); cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i < n; ++i)
#define repe(i, n) for(int i=0; i <= n; ++i)
#define repr(i, n) for(int i=n-1; i > 0; --i)
#define all(x) (x).begin(), (x).end()
#define pb(x) push_back(x)
#define eb(x,y) emplace_back(x,y)
#define PI 3.14159265359
using namespace std;
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;}
template <class T> using V=vector<T>;
typedef long long ll;
const int INF = 1e9;
const ll MOD = 1000000007;
const ll MAX = 510000;
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a * b / gcd(a, b); }
long long fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
vector<int> Eratosthenes(const int N)
{
    vector<bool> is_prime(N+1, true);
    vector<int> P;
    for(int i=2; i<=N; i++) {
        if (is_prime[i]) {
            for(int j=2*i; j<=N; j+=i) {
                is_prime[j] = false;
            }
            P.emplace_back(i);
        }
    }
    return P;
}
 
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,k,q;
    cin >> n >> k >> q;
    vector<ll> point(n,k);
    vector<ll> A(n);
    ll a;
    for(ll i=0; i<q; ++i) {
        cin >> a;
        point[a-1]++;
    }
    rep(i,n) {
        point[i] -= q;
        if (point[i] >= 1) {
            cout << "Yes" << "\n";
        } else {
            cout << "No" << "\n";
        }
    }
}

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

#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define ll long long
using namespace std;


int main() {
  int a, b, h, m;
  cin >> a >> b >> h >> m;
  static const double pi = 3.141592653589793;
    if (30 * h + 0.5 * m >= 6 * m) {
      if (30 * h + 0.5 * m - 6 * m < 180) {
        double w = 2 * pi * (30 * h + 0.5 * m - 6 * m) / 360;
        cout << setprecision(10) << double (sqrtl (a * a + b * b - 2 * a * b * cos(w))) << endl;
      }
      else {
        double x =  2 * pi * (360 - (30 * h + 0.5 * m - 6 * m)) / 360;
        cout << setprecision(10) << double (sqrtl (a * a + b * b - 2 * a * b * cos(x))) << endl;
      }
    }
    else {
      if (6 * m - 0.5 * m - 30 * m < 180) {
        double y = 2 * pi * (6 * m - 0.5 * m - 30 * h) / 360;
        cout << setprecision(10) << double (sqrtl (a * a + b * b - 2 * a * b * cos(y))) << endl;
      }
      else {
        double z = 2 * pi * (360 - (6 * m - 0.5 * m - 30 * h)) / 360;
        cout << setprecision(10) << double (sqrtl (a * a + b * b - 2 * a * b * cos(z))) << endl;
      }
    }
}



Measured memory_bytes: 4140
from collections import defaultdict

class UnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n + 1)]
        self.rank = [0] * (n + 1)
        self.size = [1] * (n + 1)

    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def same_check(self, x, y):
        return self.find(x) == self.find(y)

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if self.rank[x] < self.rank[y]:
            if self.same_check(x, y) != True:
                self.size[y] += self.size[x]
                self.size[x] = 0
            self.par[x] = y
        else:
            if self.same_check(x, y) != True:
               self.size[x] += self.size[y]
               self.size[y] = 0
            self.par[y] = x
            if self.rank[x] == self.rank[y]:
               self.rank[x] += 1

    def siz(self, x):
        x = self.find(x)
        return self.size[x]

def getlist():
    return list(map(int, input().split()))

N, M = getlist()
U = UnionFind(N)
for i in range(M):
    X, Y, Z = getlist()
    U.union(X, Y)

D = defaultdict(int)


for i in range(1, N + 1):
    n = U.find(i)
    D[n] += 1

print(len(D))

Measured memory_bytes: 20968
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

int main(){
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  rep(i, n) cin >> a.at(i);
  int bf = a.front();
  rep2(i, k, n){
    int now = a.at(i);
    // cerr << bf << " " << now << endl;
    if(bf >= now){
      cout << "No" << endl;
    }else{
      cout << "Yes" << endl;
    }
    bf = a.at(i-k+1);
  }
  return 0;
}

Measured memory_bytes: 4048
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = std::io::stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let (n, w_max): (usize, usize) = (read(), read());
    let (mut v, mut w): (Vec<usize>, Vec<usize>) = (Vec::new(), Vec::new());
    for _ in 0..n {
        v.push(read());
        w.push(read());
    }

    // dp[i + 1][j]はi番目までの荷物で、重さの総量がj以下となる組み合わせのうちの最大価値
    let mut dp = vec![vec![0; w_max + 1]; n + 1];
    for i in 0..n {
        for j in 0..w_max + 1 {
            dp[i + 1][j] =
                if j < w[i] {
                    dp[i][j]
                } else {
                    std::cmp::max(dp[i][j], dp[i + 1][j - w[i]] + v[i])
                    // 個数が1個までの場合は
                    // std::cmp::max(dp[i][j], dp[i][j - w[i]] + v[i])
                }
        }
    }

    println!("{}", dp[n][w_max]);
}



Measured memory_bytes: 13116
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Main main = new Main();
		main.solve();
	}

	void solve() {
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		int n = S.length();
		int[]a = new int[n];
		for(int i=0;i<n;i++) {
			a[i]=Integer.parseInt(S.substring(i, i+1));
		}
		sc.close();

		//偶数i と 奇数i
		int Even0 = 0,Odd1 = 0,Even1 = 0,Odd0 = 0;
		//偶数i
		for(int i=0;i<n;i+=2) {
			if(a[i]==0) Even0++;
			else Even1++;
		}
		//奇数i
		for(int i=1;i<n;i+=2) {
			if(a[i]==0) Odd0++;
			else Odd1++;
		}

		int cntA = Even0+Odd1;
		int cntB = Even1+Odd0;
		System.out.println((n-Math.max(cntA, cntB)));
	}

}


Measured memory_bytes: 31972