akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;
template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}
int main() {
  cin.tie(0);
  cout << fixed << setprecision(10);
  ll a, b, c; cin >> a >> b >> c;
  if(a % 2 && b % 2 && c % 2) {
    cout << min(a * b, min(b * c, c * a)) << endl;
  } else {
    cout << 0 << endl;
  }
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<stack>
#include<bitset>
#include<cstdlib>
#include<cmath>
#include<set>
#include<list>
#include<deque>
#include<map>
#include<queue>
using namespace std;
typedef long long ll;
typedef pair<ll,ll>qq;
const ll maxn=1e6+5;
ll a[maxn];
int main()
{
    ll k,n,mn;
    mn=maxn;
    cin>>k>>n;
    for(ll i=0;i<n;i++)
    {
        cin>>a[i];
    }
    for(ll i=0;i<n-1;i++)
    {
        mn=min(mn,a[i]+k-a[i+1]);
    }
    mn=min(a[n-1]-a[0],mn);
    cout<<mn;
    return 0;
}
/*
10 6
8 3 7 8 2 9 3 8 2 4


20 20
*/


Measured memory_bytes: 1920
#include<bits/stdc++.h>
 
#define rep(i,n) for(ll i = 0;i < n;++i)
#define all(v) v.begin(),v.end()
using namespace std;
using ll = long long;
typedef pair<int,int> P;
 
const int INF = 1001001001;
const long double PI = (acos(-1));
const int mod = 1e9+7;

ll f(int y,int m,int d){
    ll res;
    res = (365*y) + (y/4) - (y/100) + (y/400) + (306*(m+1)/10) + d -429;
    return res;
}



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

    int n;
    cin >> n;
    vector<double> a(n);
    rep(i,n){
        cin >> a[i];
    }
    rep(i,n){
        a[i] = 1/a[i]; 
    }
    double sum=0;
    rep(i,n){
        sum += a[i];
    }
    sum = 1/sum;
    cout << fixed << setprecision(10) << sum << endl;

    return 0;
}


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

temp = 0

for i, j in enumerate(A):
    if i == N:
        break
    if j >= B[i]:
        temp += B[i]
        B[i] = 0
        continue
    else:
        temp += j
        B[i] = B[i] - j

    if A[i + 1] >= B[i]:
        A[i + 1] = A[i + 1] - B[i]
        temp += B[i]
    else:
        temp += A[i + 1]
        A[i + 1] = 0

print(temp)


Measured memory_bytes: 82020
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
	ll n;
	cin>>n;
	ll v;
	cin>>v;
	string s;
	cin>>s;
	s=" "+s;
	if(v<=n&&s[v]>=65&&s[v]<=90){
		s[v]=s[v]+32;
	}
	for(ll i=1;i<=n;i++)
	cout<<s[i];
} 

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define PI 3.14159265358979323

//void quick(int *,long long,long long);
//int comp(char *a,char *b);

int main(){
	
	int *a,i,j,n;
	a=(int *)malloc(sizeof(int)*1000001);
	for(i=3;i<=1000000;i++)
		a[i]=1;
	a[0]=0;
	a[1]=0;
	a[2]=1;
	i=2;
	while(i*i<=1000000){
		for(j=2;i*j<=1000000;j++)
			a[i*j]=0;
		i++;
		while(a[i]==0)
			i++;
	}
	
	while(scanf("%d",&n)!=EOF){
		j=0;
		for(i=0;i<=n;i++)
			if(a[i]==1)
				j++;
		printf("%d\n",j);
	}
	//for(i=0;i<=1000000000;i++);
	return 0;
}

Measured memory_bytes: 4504
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

public class Main {
    private static final int MAX_NUM_DIGIT_IN_BINARY = 40; // 10^12 < 2^40

    public static long process(TestCase testCase) {
        final long K = testCase.K;
        final List<Long> A = testCase.A;

        if (K == 0) {
            return A.stream().mapToLong(i -> i).sum();
        } else {
            return maxSumAfterXor(A, K);
        }
    }

    private static long maxSumAfterXor(List<Long> A, long K) {
        int[][] allDigits = covertToDigitsMatrix(A);
        final int N = A.size();

        long sum = 0;
        long base = 1L << MAX_NUM_DIGIT_IN_BINARY - 1;
        for (int j = 0; j < MAX_NUM_DIGIT_IN_BINARY; ++j) {
            int count = countOnes(allDigits, j);
            boolean isWithinK = base <= K;
            if (isWithinK) {
                int flippedCount = N - count;

                boolean shouldFlip = flippedCount > count;
                if (shouldFlip) {
                    count = flippedCount;
                    K -= base;
                }
            }
            sum += count * base;
            base = base >> 1;
        }
        return sum;
    }

    private static int countOnes(int[][] allDigits, int j) {
        return Arrays.stream(allDigits)
                .mapToInt(digits -> digits[j])
                .sum();
    }

    private static int[][] covertToDigitsMatrix(List<Long> A) {
        int[][] allDigits = new int[A.size()][MAX_NUM_DIGIT_IN_BINARY];
        for (int i = 0; i < A.size(); ++i) {
            String digits = Long.toBinaryString(A.get(i));
            final int numDigits = digits.length();
            for (int j = numDigits - 1; j >= 0; --j) {
                final int rightAlignedIndex = MAX_NUM_DIGIT_IN_BINARY - numDigits + j;
                final char digit = digits.charAt(j);
                allDigits[i][rightAlignedIndex] = Character.getNumericValue(digit);
            }
        }
        return allDigits;
    }

    // util func

    public static void main(String[] args) {
        TestCase testCase = readFromInput();

        final long result = process(testCase);

        output(result);
    }

    private static TestCase readFromInput() {
        Scanner sc = new Scanner(System.in);

        long N = sc.nextLong();
        long K = sc.nextLong();
        List<Long> A = new ArrayList<>();
        for (long i = 0; i < N; ++i) {
            A.add(sc.nextLong());
        }

        sc.close();
        return new TestCase(N, K, A);
    }

    private static void output(long result) {
        System.out.println(result);
    }

    public static class TestCase {
        final long N;
        final long K;
        final List<Long> A;

        public TestCase(long N, long K, List<Long> A) {
            this.N = N;
            this.K = K;
            this.A = A;
        }
    }
}


Measured memory_bytes: 82544
import java.util.*

fun main(args: Array<String>) {
    val scanner = Scanner(System.`in`)
    val n = scanner.nextInt()
    for (i in 0..n-1) {
        val value = scanner.nextInt()
        if (value % 2 == 0 && (value % 3 != 0 && value % 5 != 0)) {
            println("DENIED")
            return
        }
    }

    println("APPROVED")
}

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

int main(){
  int h, w;
  cin >> h >> w;
  vector<string> v;
  for(int i=0;i<h;++i){
    string s;
    cin >> s;
    v.push_back(s);
  }
  
  for(int i=0;i<h;++i){
    cout << v[i] << endl << v[i] << endl;
  }
  
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        int W = scanner.nextInt();
        int H = scanner.nextInt();
        int C = scanner.nextInt();
        int x = W;
        int y = H;
        int z;

        while (x % y != 0) {
            z = x;
            x = y;
            y = z % y;
        }
        System.out.println(((W / y) * (H / y)) * C);

    }

}



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

int main(){
    int a=0,b=0,t=0;
    cin>>a>>b;
    t=2*b;
    if(b>a)
        cout<<0;
    else if(a<t)
        cout<<0;
    else
        cout<<a-t;
    return 0;
}


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

using namespace std;
typedef long long ll;
typedef vector<ll> vl ;

#define mp make_pair
#define pb push_back
#define f first
#define s second
#define all(v) (v).begin(),(v).end()

const int MOD = 1000000007;
const int N = 100005;
const double PI =4*atan(1);

ll dp[N];
vl v;
vl adj[N];
vl rev[N];
ll n,m,ans,x,y;
bool vis[N];

void dfs(ll src){
	if(vis[src])return ;
	vis[src]=1;
	for(auto t:adj[src]) {
		dfs(t);
	}
	v.pb(src);
}


int main(){
    ios::sync_with_stdio(0);
    //freopen("baklava.in","r",stdin);
    cin.tie(0);
    cout.tie(0);
    //start
    cin >> n >> m;
    for(int i=0;i<m;i++){
    	cin >> x >> y;
    	x--;y--;
    	adj[x].pb(y);
    	rev[y].pb(x);
    }
    memset(vis,0,sizeof(vis));
    for(int i=0;i<n;i++){
    	if(!vis[i])dfs(i);
    }
	reverse(v.begin(),v.end());
	ans=0;
	for(auto t: v){
		dp[t]=0;
		for(auto u:rev[t]){
			dp[t]=max(dp[t],dp[u]+1);
			
		}
		ans=max(ans,dp[t]);
	}
	cout << ans;
    return 0;
}


Measured memory_bytes: 15096
import sys
N=int(input())
A=list(map(int,input().split()))
for i in range(len(A)):
    if A[i]%2==0:
        if A[i]%3==0 or A[i]%5==0:
            continue
        else:
            print('DENIED')
            sys.exit()
    else:
        continue
else:
    print('APPROVED')

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back
#define mt make_tuple
#define ALL(a) (a).begin(),(a).end()
#define FST first
#define SEC second
#define DEB cerr<<"!"<<endl
#define SHOW(a,b) cerr<<(a)<<" "<<(b)<<endl
#define vi vector<int>

using ll = long long;
const int INF = (INT_MAX/2);
const ll LLINF = (LLONG_MAX/2);
const double eps = 1e-8;
const ll DIV =1e9+7;
//const double PI = M_PI;
inline ll pow(ll x,ll n,ll m){ll r=1;while(n>0){if((n&1)==1)r=r*x%m;x=x*x%m;n>>=1;}return r%m;}
inline ll lcm(ll d1, ll d2){return d1 / __gcd(d1, d2) * d2;}
inline ll inv(ll x, ll div){return pow(x, div - 2, div);}
#define chmax(a,b) a=max(a,b)
int gcj_out_cnt = 1;
#define gcj_put cout<<"Case #"<<gcj_out_cnt++<<": ";

/*Coding Space*/
int main(){
  ll in; cin >> in;
  ll ans = lcm(360,in);
  cout << ans/in << endl;
}


Measured memory_bytes: 3628
#include <stdio.h>
#include <math.h>
#define MAX 1000000
int main(){
    int i,j,max,ch[MAX];

    max=sqrt(MAX);

    for(i=0;i<MAX;i+=2){ch[i]=0;ch[i+1]=1;}

    ch[1]=0;
    ch[2]=1;

    for(i=3;i<max;i+=2) if(ch[i]) for(j=i+i;j<MAX;j+=i) ch[j]=0;

    for(i=3;i<MAX;i++) ch[i]+=ch[i-1];

    while(scanf("%d",&i)!=EOF) printf("%d\n",ch[i]);

    return 0;
}

Measured memory_bytes: 4500
#include <bits/stdc++.h>
using namespace std;
int main() {
	vector<int> vec(3);
	for(int i=0; i<3; i++){
		cin>>vec[i];
	}
	sort(vec.begin(),vec.end());
	cout<<vec[2]*10+vec[1]+vec[0]<<endl;
}
	

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

typedef long long ll;

#define rep(i, n) for (ll i = 0; i < (ll)n; ++i)
#define repr(i, n) for (ll i = n - 1; i >= 0; --i)
#define INF 10e7
#define MOD 1000000000 + 7
#define MAX 51000
#define all(x) (x).begin(), (x).end()
#define MX(x) *max_element(all(x))
#define MN(x) *min_element(all(x))
using namespace std;

void solve(void)
{
    string s;
    cin >> s;
    int len = s.length();
    vector<pair<int, int>> vp;
    vector<int> vi, ans(len);
    int r = 0, l = 0, m;
    rep(i, len)
    {
        if (s[i] == 'R')
            r++;
        if (s[i] == 'L')
            l++;
        if (s[i] == 'R' && s[i + 1] == 'L')
            m = i;
        if (s[i] == 'L' && s[i + 1] == 'R' || i == len - 1)
            vp.push_back({r, l}), vi.push_back(m), r = 0, l = 0;
    }
    rep(i, vi.size())
    {
        ans[vi[i] + 1] = vp[i].first / 2 + (vp[i].second + 1) / 2;
        ans[vi[i]] = (vp[i].first + 1) / 2 + vp[i].second / 2;
    }
    rep(i, len) cout << ans[i] << " ";
    cout << endl;
}
int main(void)
{
    solve();
}

Measured memory_bytes: 4656
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
#define PRINT(v) for (auto x : (V)) cout <<x <<" " <<endl;
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
const ll MOD = 1000000007;
const ll INF = 10000000000000000;
vector<int> x4 = {0, 1, 0, -1}, x8 = {0, 1, 1, 1, 0, -1, -1, -1};
vector<int> y4 = {1, 0, -1, 0}, y8 = {1, 1, 0, -1, -1, -1, 0, 1};
template<class T> struct edge { int from, to; T cost;};
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;}
template<class T> inline T powerM(T a,T b){if (b==0) return 1;
T tmp = powerM(a,b/2); if (b%2==0) return tmp*tmp%MOD; else return tmp*tmp%MOD*a%MOD; }
template<class T> inline T power(T a,T b,T m){ if (b==0) return 1;
  T tmp = power(a,b/2,m); if (b%2==0) return tmp*tmp%m; else return tmp*tmp%m*a%m; }
template<class T> inline T gcd(T a, T b){if (b==0) return a; return gcd(b, a%b);}
template<class T> inline T lcm(T a, T b){return a / gcd(a,b) * b;}
// ax+by=gcd(a,b)を解く
template<class T> inline T extgcd(T a,T b,T &x,T &y){if (b==0){x=1; y=0; return a;} T d=extgcd(b,a%b,y,x); y -= a/b*x; return d;}
void hey(){ cout <<"hey" <<endl; }


int main() {
  int a,b,q; cin >>a >>b >>q;
  vector<ll> s(a), t(b);
  rep(i, a) cin >>s[i];
  rep(i, b) cin >>t[i];
  rep(qq,q){
    ll x; cin >>x;
    // 地点 x から左右に近いもの各々が神社、寺の訪れるものの候補
    // 但し地点 x に丁度存在するときはややこしそう
    int s1,t1,s2,t2;
    if (lower_bound(all(s), x) == s.end()){
      // x 以上には神社は存在しない
      s1 = lower_bound(all(s), x) - s.begin() - 1;
      s2 = s1;
    }else{
      s2 = lower_bound(all(s), x) - s.begin(); // x 以上で一番近い神社のindex
      // s2 の地点が丁度 x だったり、s2より前の地点が存在しなければs1 = s2
      if (s2 == 0 || s[s2] == x) s1 = s2;
      else s1 = s2-1;
    }
    if (lower_bound(all(t), x) == t.end()){
      t1 = lower_bound(all(t), x) - t.begin() - 1;
      t2 = t1;
    }else{
      t2 = lower_bound(all(t), x) - t.begin(); // x 以上で一番近い寺のindex
      if (t2 == 0 || t[t2] == x) t1 = t2;
      else t1 = t2-1;
    }
    // 特殊な条件を除き、s1,s2は神社に関して、t1,t2は寺に関して、
    // 各々x以下、x以上で一番近い地点のindexを表す
    // とりあえず(s1,s2)*(t1,t2)を全部調べればいい
    ll res = 1000000000000000;
    int ss,tt;
    rep(i, 2){ rep(j, 2){
      ss = i == 0 ? s1 : s2;
      tt = j == 0 ? t1 : t2;
      // s[ss]とt[tt]を両方回るのに必要な移動距離は
      ll buf = abs(s[ss] - t[tt]); // 神社⇔寺
      buf += min(abs(x - s[ss]), abs(x - t[tt])); // 神社または寺の近い方にたどり着く
      chmin(res, buf);
    }}
    cout <<res <<endl;
  }
}


Measured memory_bytes: 2944
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <unordered_map>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
#include <assert.h>
#include <unordered_map>
#include <fstream>
#include <complex>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef pair<int,int> pii;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(int i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 510000;
ll dy[8] = {0,-1,0,1,1,-1,1,-1};
ll dx[8] = {1,0,-1,0,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
    if(a>b){
        a = b; return true;
    }
    else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
    if(a<b){
        a = b; return true;
    }
    else return false;
}
template<typename T> inline void print(T &a){
    rep(i,a.size()) cout << a[i] << " ";
    cout << "\n";
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << "\n";}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
    cout << a << " " << b << " " << c << "\n";
}
const ll mod = 1e9 + 7;
//const int mod = 998244353;

ll modpow(ll x, ll n, ll mod){
    ll res = 1;
    while(n > 0){
        if(n & 1) res = res * x % mod;
        x = x * x % mod;
        n >>= 1;
    }
    return res;
}

vector<ll> a(262144,-1);

ll dfs(int x){
    if(a[x] != -1) return a[x];
    int cnt = 0;
    int tmp = x;
    while(tmp > 0){
        if(tmp & 1) cnt++;
        tmp >>= 1;
    }
    return a[x] = dfs(x % cnt) + 1;
}

int main(){
    a[0] = 0;
    int n; cin >> n;
    string s; cin >> s;
    rep(i,262144) dfs(i);
    ll suma = 0, sumb = 0;
    ll nowa = 1, nowb = 1;
    ll p = 0;
    rep(i,n) if(s[i] == '1') p++;
    ll pa = p+1;
    ll pb = p-1;
    for(int i=n-1; i>=0; i--){
        if(s[i] == '1'){
            suma = (suma + nowa) % pa;
            if(pb > 0) sumb = (sumb + nowb) % pb;
        }
        nowa = nowa * 2 % pa;
        if(pb > 0) nowb = nowb * 2 % pb;
    }
    rep(i,n){
        if(s[i] == '1'){
            if(pb == 0) cout << 0 << "\n";
            else{
                ll t = modpow(2,n-1-i,pb);
                ll tmp = sumb - t;
                if(tmp < 0) tmp += pb;
                cout << a[tmp] + 1 << "\n";
            }
        }else{
            ll t = modpow(2,n-1-i,pa);
            ll tmp = (suma + t) % pa;
            cout << a[tmp] + 1 << "\n";
        }
    }
}

Measured memory_bytes: 5624
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cmath>
#include <set>
#include <queue>
#include <deque>
#include <vector>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;

int main()
{
	int N, M;
	cin >> N >> M;
	vector<int> p(N);
	for (auto i = 0; i < N; ++i)
	{
		cin >> p[i];
		--p[i];
	}

	vector<vector<int>> G(N);
	for (auto i = 0; i < M; ++i)
	{
		int x, y;
		cin >> x >> y;
		--x;
		--y;
		G[x].push_back(y);
		G[y].push_back(x);
	}

	auto ans = 0;
	vector<bool> used(N);
	for (auto i = 0; i < N; ++i)
	{
		if (used[i] != false)
		{
			continue;
		}

		queue<int> q;
		q.push(i);
		used[i] = true;
		set<int> s;
		while (!q.empty())
		{
			auto u = q.front();
			q.pop();

			s.insert(u);
			for (auto v : G[u])
			{
				if (used[v] != false)
				{
					continue;
				}
				used[v] = true;
				q.push(v);
			}
		}

		for (auto u : s)
		{
			if (s.find(p[u]) != s.end())
			{
				++ans;
			}
		}
	}

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

Measured memory_bytes: 10752
import heapq
from collections import deque

x,y,a,b,c = map(int,input().split())
p = list(map(int,input().split()))
q = list(map(int,input().split()))
r = sorted(list(map(lambda x:int(x),input().split())),reverse=True)

p = sorted(p)[a - x:a]
q = sorted(q)[b - y:b]
p+=q
p.sort()

for i in range(min(len(r),len(p))):
    p[i] = max(p[i],r[i])
print(sum(p))

Measured memory_bytes: 107116
#include <stdio.h>
#include <math.h>

int main(void) {
    int n, x, tmp;
    scanf("%d", &n);
    x = ceil((double)n / 1.08);
    tmp = x * 1.08;
    if (tmp == n) printf("%d\n", x);
    else printf(":(\n");
    
    return 0;
}

Measured memory_bytes: 128
fun main(args: Array<String>) {
    var chars = mutableMapOf<Char, Int>()
    val userInput: String = readLine()!!

    // 一文字ずつみる
    userInput.forEach {
        if (chars.containsKey(it)) {
            // 配列にぞんざいすればインクリメントする
            chars.put(it, chars.get(it)!!.plus(1))
        } else {
            // 配列に被りがなければカウント1で追加
            chars.put(it, 1)
        }
    }

    // 配列すべての文字列の出現回数が偶数ならいぇs
    chars.forEach {
        if (it.value % 2 != 0) {
            print("No")
            return
        }
    }
    print("Yes")

}

Measured memory_bytes: 33436
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		String s = sc.next();
		int n = s.length();
		long k = Long.parseLong(sc.next());
		sc.close();

		int idx = -1;
		char ans = '1';

		for (int i = 0; i < n; i++) {
			if (s.charAt(i) != '1') {
				idx = i + 1;
				ans = s.charAt(i);
				break;
			}
		}

		if (k < idx) {
			System.out.println(1);
			return;
		} else {
			System.out.println(ans);
		}
	}
}

Measured memory_bytes: 23764
#include <stdio.h>

int main(void){
    int r,g,b,n,cnt=0;
    scanf("%d%d%d%d",&r,&g,&b,&n);
    int i=n/r+1,j=n/g+1;
    for(i=0;i<=n;i++){
        for(j=0;j<=n;j++){
            if((n-r*i-g*j)==0||((n-r*i-g*j)>0&&(n-r*i-g*j)%b==0)){
                //printf("%d %d \n",i,j);
                cnt++;
            } 
        }
    }
    printf("%d\n",cnt);
    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> Pair;
#define MM 1000000000
#define MOD MM+7
#define MAX 10000
#define MAP_SIZE 10
int dx[4] = {-1, 0, 1, 0};
int dy[4] = {0, -1, 0, 1};
int main(){
    int n, m; cin >> n >> m;
    map<int, int> mp;
    int k;
    int a[n][k];
    for(int i = 1; i <= 30; i++){
        mp[i] = 0;
    }
    for(int i = 0; i < n; i++){
        cin >> k;
        for(int j = 0; j < k; j++){
            cin >> a[i][j];
            mp[a[i][j]]++;
        }
    }
    int ans = 0;
    for(int i = 1; i <= 30; i++){
        if(mp[i] == n) ans++;
    }
    cout << ans << endl;
}


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

int main(void)
{
    int i, j, ct;
    int p, q;
    static int mod[1000000], n[100], w[10000000];
    
    while (scanf("%d%d", &p, &q) != EOF){
        
        memset(mod, -1, sizeof(mod));
        memset(n, -1, sizeof(n));
        memset(w, -1, sizeof(p));
        
        p *= 10;
        w[p] = 1;
        i = ct = 0;
        while (mod[0] == -1) {
            if (mod[p % q] != -1){
                if (mod[p % q] != p / q){
                    printf("%d", p / q);
                    n[i++] = p % q;
                }
                else {
                    ct = 1;
                }
                break;
            }
            printf("%d", p / q);
            mod[p % q] = p / q;
            n[i++] = p % q;
            w[p] = p / q;
            p = (p % q) * 10;
        }
        printf("\n");
        if (mod[0] == -1){
            for (j = 0; j < i; j++){
                printf("%c", (n[j] == p % q && ct) ? '^' : ' ');
                if (n[j] == p % q){
                    ct = 1;
                    n[j + 1] = p % q;
                }
            }
            printf("\n");
        }
    }
    
    return (0);
}

Measured memory_bytes: 5116
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  for(int i = 0; i < n; i++) cin >> a[i];
  int num = (int)1e9;
  for(int i = 0; i < n; i++){
    int cnt = 0;
    while(a[i] % 2 == 0){
      cnt++;
      a[i] /= 2;
    }
    num = min(cnt, num);
  }
  cout << num << endl;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;

public class Main {
  private static boolean debug = false;
  private static boolean elapsed = false;

  private static PrintWriter _err = new PrintWriter(System.err);

  private void solve(Scanner sc, PrintWriter out) {
    String s = sc.nextLine();

    if (s.length() < 2) {
      out.println("-1 -1");
      return;
    }

    Map<Character, Integer> map = new HashMap<>();
    for (int i = 0; i < 2; ++i) {
      char ch = s.charAt(i);
      Integer cnt = map.get(ch);
      if (cnt == null) {
        cnt = 0;
      }
      map.put(ch, cnt + 1);
    }
    if (s.length() == 2) {
      if (map.size() == 1) {
        out.println("1 2");
        return;
      }
    }
    for (int i = 0; i < s.length() - 2; ++i) {
      if (i > 0) {
        char old = s.charAt(i - 1);
        Integer cnt = map.get(old);
        map.put(old, cnt - 1);
      }
      char ch = s.charAt(i + 2);
      Integer cnt = map.get(ch);
      if (cnt == null) {
        cnt = 0;
      }
      map.put(ch, cnt + 1);
      if (cnt + 1 >= 2) {
        out.println((i + 1) + " " + (i + 3));
        return;
      }
    }

    out.println("-1 -1");
  }
  private long C(long n, long r) {
    long res = 1;
    for (long i = n; i > n - r; --i) {
      res *= i;
    }
    for (long i = r; i > 1; --i) {
      res /= i;
    }
    return res;
  }
  private long P(long n, long r) {
    long res = 1;
    for (long i = n; i > n - r; --i) {
      res *= i;
    }
    return res;
  }
  private long ceil2pow(long n) {
    if (n == 0) {
      return 1;
    }
    n--;
    n |= (n >>> 1);
    n |= (n >>> 2);
    n |= (n >>> 4);
    n |= (n >>> 8);
    n |= (n >>> 16);
    n++;
    return n;
  }
  /*
   * 10^10 > Integer.MAX_VALUE = 2147483647 > 10^9
   * 10^19 > Long.MAX_VALUE = 9223372036854775807L > 10^18
   */
  public static void main(String[] args) {
    long S = System.currentTimeMillis();

    Scanner sc = new Scanner(System.in);
    PrintWriter out = new PrintWriter(System.out);
    new Main().solve(sc, out);
    out.flush();

    long G = System.currentTimeMillis();
    if (elapsed) {
      _err.println((G - S) + "ms");
    }
    _err.flush();
  }
}

Measured memory_bytes: 14012
import sys
readline = sys.stdin.readline
from operator import itemgetter

def main():
    N = int(readline())
    SP = [readline().rstrip().split() for _ in range(N)]
    SP = [(s, -int(p), i+1) for i, (s, p) in enumerate(SP)]
    SP = sorted(SP, key=itemgetter(0, 1))
    for i in range(N):
        print(SP[i][2])

if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define all(v) (v).begin(), (v).end()
typedef long long int lint;
using namespace std;

int main() {
    int h, w;
    cin >> h >> w;
    vector<string> s(h);
    for (int i = 0; i < h; i++) {
        cin >> s[i];
    }
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            if (s[i][j] != '#') {
                continue;
            }
            bool flag = false;
            if (i - 1 >= 0 && s[i - 1][j] == '#') {
                flag = true;
            }
            if (i + 1 < h && s[i + 1][j] == '#') {
                flag = true;
            }
            if (j - 1 >= 0 && s[i][j - 1] == '#') {
                flag = true;
            }
            if (j + 1 < w && s[i][j + 1] == '#') {
                flag = true;
            }
            if (!flag) {
                cout << "No" << endl;
                return 0;
            }
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 256
a0 = int(input())
an = [a0]
def f(n):
        if n%2 == 0:
                return n/2
        else:
                return 3*n + 1
frag = 0
term = 1
while frag == 0:
        an.append(f(an[-1]))
        term += 1
        for i in range(len(an)-1):
                if an[-1] == an[i]:
                        frag = 1
                        break
print(term)



Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <functional>
using namespace std;
using Int = long long;
#define REP(i,n) for(int i=0;i<n;i++)
#define P(r) do{for(auto i:r){cout<<i<<' ';}cout<<'\n';}while(0)
int main()
{
    int N; cin >> N;
    Int x = 1, y = 1;
    REP(i, N) {
        int t, a; cin >> t >> a;
        Int k = max((x + t - 1) / t, (y + a - 1) / a);
        x = k * t;
        y = k * a;
    }
    cout << x + y << endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main () 
{
  int A,B,C,D,min1=0,min2=0,result=0;

scanf("%d%d%d%d",&A,&B,&C,&D);

if(A>B)
{
  min1=B;
}
else
{
  min1=A;
}

if(C>D)
{
 min2=D;
}

else
{
  min2=C;
}

result=min1+min2;

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

return 0;

}

Measured memory_bytes: 1724
#include <bits/stdc++.h>
using namespace std;
long long  dp[100000001];
long long p=1000000007;
long long pow1(long long i,long long n){
  long long c; 
  if(n==1)
    return i;
  else{
    c=pow1(i,n/2);
    if(n%2==0){
      c*=c;
      c%=p;
    }
    else{
      c*=c;
      c%=p;
      c=c*i;
      c%=p;
    }
  }
  return c;
}
int main() {
  long long n,k,k1,k2;
  cin>>n>>k;
  for(long long i=k;i>=1;i--){
    dp[i]=pow1(k/i,n);
    dp[i]%=p;
    for(long long g=2*i;g<=k;g+=i)
      dp[i]-=dp[g];
    dp[i]%=p;
  }
  long long sum=0;
  for(long long i=1;i<=k;i++){
    sum+=i*dp[i];
    sum%=p;
  }
  cout<<sum;
}

Measured memory_bytes: 4372
#include<bits/stdc++.h>
using namespace std;
const int MAXN = (int) 1e6 + 10;
const int MOD = (int) 1e9 + 7;

int n;
struct node {
	int num;
	int k;
}a[MAXN];

bool cmp(node a, node b) {
	return a.num < b.num;
}

int main(){
	scanf("%d", &n);
	for (int i=1; i<=n; i++) {
		scanf("%d", &a[i].num);
		a[i].k = i;
	}
	sort(a+1, a+n+1, cmp);
	for (int i=1; i<=n; i++) 
	    printf("%d ", a[i].k);
	cout << '\n';
    return 0;
}


Measured memory_bytes: 1664
#include  <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define P pair<int,int>
//P pa(114,514);   ,vector<P>vec(N,0);
//vector<vector<int>> vec(縦, vector<int>(横));
#define REP(i,N) for(int i=0;i<N;i++)
int gcd(int a, int b) {
    if(a>b){
        swap(a,b);
        }
    while(b%a!=0){
        b%=a;
        swap(a,b);
    }
    return a;
}
//cout << setprecision(123);
int main(){
  int N,K;
  string S;
  cin >>N>>K>>S;
  
  if(S[K-1]=='A'){
    S[K-1]='a';
  }
  else if(S[K-1]=='B'){
    S[K-1]='b';
  }
  else{
    S[K-1]='c';
  }
  cout << S<<endl;
  
}

Measured memory_bytes: 256
n, p = map(int, input().split())

import math
def div(m):
    d = {}
    temp = int(math.sqrt(m))+1
    for i in range(2, temp):
        while m%i== 0:
            m //= i
            if i in d:
                d[i] += 1
            else:
                d[i] = 1
    if d == {}:
        d[m] = 1
    else:
        if m in d:
            d[m] += 1
        elif m != 1:
            d[m] =1
    return d

d = div(p)
#print(d)
ans = 1
for k, v in d.items():
    if v >= n:
        q = v//n
        ans *= k**q
print(ans)


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

int main() {
    int N, M;
    cin >> N >> M;
    vector<pair<int, int>> AB(M);
    for (int i = 0; i < M; i++) cin >> AB[i].first >> AB[i].second;

    int ans = 1;
    for (int i = 1; i < N; i++) ans *= i;
    vector<int> array(N - 1);
    for (int i = 0; i < N - 1; i++) array[i] = i + 2;
    do {
        vector<int> solve = {1};
        for (int i = 0; i < N - 1; i++) solve.push_back(array[i]);
        for (int i = 1; i < N; i++) {
            bool flag = false;
            for (int j = 0; j < M; j++) {
                if (make_pair(solve[i - 1], solve[i]) == AB[j] || make_pair(solve[i], solve[i - 1]) == AB[j]) {
                    flag = true;
                }
            }
            if (!flag) {
                ans--;
                break;
            }
        }
    } while (next_permutation(array.begin(), array.end()));

    cout << ans << endl;
}

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

int main(){
	string s;
	bool f = 0;
	cin >> s;

	for(int i = 0; i < s.length();++i)
		for(int j = i+1;j < s.length();++j)
			if(s[i] == s[j])
				f = 1;

	if(f)
		cout << "no" <<endl;
	else
		cout << "yes" <<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
using namespace std;
int main() {
  string s,t;
  int num = 0;
  cin >> s >> t;
  for (int i = 0; i < s.length(); ++i) {
  if (s[i] != t[i]) {
    num += 1;
  }
}
  cout << num << endl;
}


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

using namespace std;
typedef long long ll;

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

	string n;
	int s=0;
	cin >> n;
	for(auto c : n) {
		s+= c - '0';
	}
	if(s%9 == 0)
		cout << "Yes";
	else 
		cout << "No";

    return 0;
} 
 


Measured memory_bytes: 3712
#include <bits/stdc++.h>
const long long MOD = 1e9+7;
using namespace std;
#define ll long long
#define ar array

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

	string s;
	cin >> s;
	cout << s.at(0) << s.size()-2 << s.back() << endl;
	return 0;
}


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

int main(int argc, const char * argv[]) {
    int h,w;
    
    cin >> h >> w;
    string table[50];
    
    for (int k = 0; k < h; k++) {
        cin >> table[k];
    }
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            if (table[i][j] == '#') {
                continue;
            }
            
//            points around a point
            int x_points[8] = {0,1,0,-1,-1,1,1,-1};
            int y_points[8] = {1,0,-1,0,1,1,-1,-1};
            int total = 0;
            for (int l = 0; l < 8; l++) {
                int x = i + x_points[l];
                int y = j + y_points[l];
                
                if (x < 0 || x >= h) continue;
                if (y < 0 || y >= w) continue;
                if(table[x][y] == '#') total++;
            }
            table[i][j] = char(total + '0');
        }
    }
    
    for (int z = 0; z < h; z++) {
        cout <<table[z] << endl;
    }

    return 0;
}

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

#define ll long long
using namespace std;

int x, y, N, ans[ 2003 ], ara[ 200000 + 3 ], hi;
vector <int> adj[ 2003 ];
int vis[ 2003 ], lev[ 2003 ];


void solve(int s)
{
  queue <int> q;
  q.push(s);
  for (int i=0; i<N+1; i++) {
    lev[ i ] = 0;
    vis[ i ] = 0;
  }
  vis[ s ] = 1;
  while ( !q.empty() ) {
    int u = q.front();
    for (int i=0; i<adj[ u ].size(); i++) {
      if ( !vis[ adj[ u ][ i ] ] ) {
       	q.push( adj[ u ][ i ] );
        vis[ adj[ u ][ i ] ] = 1;
        lev[ adj[ u ][ i ] ] = lev[ u ] + 1;
    	ans[ lev[ adj[ u ][ i ] ] ]++;// cout << lev[ adj[ u ][ i ] ] << " ";
      }
    }
    q.pop();
  }
}

int main()
{
  cin >> N >> x >> y;
  
  for (int i=0; i<N-1; i++){
    adj[ i ].push_back( i + 1 );
    adj[ i + 1 ].push_back( i );
  }
  
  adj[ x - 1 ].push_back( y - 1 );
  adj[ y - 1 ].push_back( x - 1 );
 
  for (int i=0; i<N; i++){
    solve(i);//cout << endl;
  }
  
  for (int i=1; i<N; i++)
  	cout << ans[ i ] / 2 << "\n";
  
  return 0;
}


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

int main() {
    int W, H, x, y, r;
    char* str;
    cin >> W >> H >> x >> y >> r;
    if( x - r >= 0 && x + r <= W && y - r >= 0 && y + r <= H ) {
        str = "Yes";
    } else {
        str = "No";
    }
    cout << str << endl;
}

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

long long mod = 1000000007;

long long f(long long i) 
{
	if (i == 0) {
		return 1;
	}

	long long t = f(i / 2);
	if (i % 2 == 0) {
		return t * t % mod;
	}
	else {
		return t * t * 2 % mod;
	}
}

// mod. m での a の逆元 a^{-1} を計算する
long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}

long long comb(long long n, long long r) {
	long long ret = 1;
	for (long long i = n; n - r < i; --i) {
		ret = ret * i % mod;
	}

	for (long long i = 2; i <= r; ++i) {
		ret = ret * modinv(i, mod) % mod;
	}
	return ret;
}

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

	//2^n - 1
	long long ret = f(n) - 1 - comb(n,a);
	if (ret < 0) {
		ret += mod;
	}
	ret -= comb(n,b);
	if (ret < 0) {
		ret += mod;
	}

	cout << ret << endl;

	return 0;
}

Measured memory_bytes: 256
use std::iter::Iterator;
use std::cmp::min;

fn read<T: std::str::FromStr>(
    stdin_lock: &mut std::io::StdinLock,
    buf: &mut Vec<u8>,
    delimiter: u8,
) -> T {
    buf.clear();
    let l = std::io::BufRead::read_until(stdin_lock, delimiter, buf).unwrap();
    buf.truncate(l - 1); // remove delimiter
    let s = unsafe { std::str::from_utf8_unchecked(&buf) };
    s.parse().unwrap_or_else(|_| panic!("read"))
}

fn main() {
    let stdin = std::io::stdin();
    let mut stdin_lock = stdin.lock();
    let mut buf: Vec<u8> = Vec::new();
    let n: i32 = read(&mut stdin_lock, &mut buf, b'\n');
    let mut ws: Vec<i32> = Vec::new();
    for _ in 0..(n - 1) {
        ws.push(read(&mut stdin_lock, &mut buf, b' '));
    }
    ws.push(read(&mut stdin_lock, &mut buf, b'\n'));

    let sum: i32 = ws.iter().sum();
    let mut s1 = 0;
    let mut ans = sum;
    for w in ws {
        s1 += w;
        let s2 = sum - s1;
        ans = min(ans, (s1 - s2).abs());
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
int main()
{
  long long int H,N;
  cin>>H>>N;
  long long int A[N];
  long long int sum=0;
  for(int i=0;i<N;i++)
  {cin>>A[i];
   sum+=A[i];
  }
  if(sum>=H)
    cout<<"Yes"<<endl;
  else
    cout<<"No"<<endl;
  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
#define reps(i,n) for(int i = 1; i <= n; i++)
#define rrep(i,n) for(int i = n-1; i >= 0; i--)
#define rreps(i,n) for(int i = n; i >= 1; i--)
#define mrep(i,from,n) for(int i = from; i < n; i++)
#define mreps(i,from,n) for(int i = from; i <= n; i++)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define ERASE(x,val) x.erase(remove(ALL(x), val), x.end())
typedef long long ll;
typedef pair<ll, ll> P;
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; }
ll mod = 1000000007;

void solve()
{
	int n,m; cin >> n >> m;
	vector<vector<int>> p(m+1);
	rep(i, n)
	{
		int a,b; cin >> a>>b;
		if(a<=m)p[a].push_back(b);
	}
	priority_queue<int> q;
	int ans = 0;
	reps(i, m)
	{
		rep(j, sz(p[i]))q.push(p[i][j]);
		if(q.empty())continue;
		ans+=q.top();
		q.pop();
	}
	cout << ans << endl;
	return;	
}

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	solve();
	return 0;
}


Measured memory_bytes: 5632
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define show(x) {for(auto i: x){cout << i << " ";} cout << endl;}
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> P(N);
  rep(i, N) cin >> P[i];
  int ans = 0;
  int temp = 0;
  for (int i = 0; i < N; i++) {
    temp += (1 + P[i]);
    if (i >= K) temp -= (1 + P[i-K]);
    ans = max(ans, temp);
  }
  double x = double(ans) / 2.0;
  printf("%.8f\n", x);
  return 0;
}

Measured memory_bytes: 3980
# 各錘の重量を取得
A,B,C,D = map(int,input().split())

# 左と右の皿の重さを計算
LWeight = A + B
RWeight = C + D

# 比較結果にもどづいて各メッセージを出力
if LWeight > RWeight:
    print("Left")
elif LWeight < RWeight:
    print("Right")
else:
    print("Balanced")

Measured memory_bytes: 9164
#include<cstdio>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
inline int read()
{
	int x;char c;
	while((c=getchar())<'0'||c>'9');
	for(x=c-'0';(c=getchar())>='0'&&c<='9';)x=x*10+c-'0';
	return x;
}
#define MN 100000
priority_queue< pair<int,int> > pq;
vector<int> v[MN+5]; 
int a[MN+5];
int main()
{
	int n,m,i,j;
	long long s=0,ss=0,ans=0;
	n=read();m=read();
	for(i=1;i<=n;++i)a[i]=read();
	for(i=1;i<n;++i)
		if(a[i+1]>a[i])s+=a[i+1]-a[i],v[a[i]].push_back(a[i+1]);
		else s+=a[i+1]+m-a[i],pq.push(make_pair(-a[i+1],a[i]-m)),ss+=a[i]-m,v[a[i]].push_back(a[i+1]+m);
	for(i=1;i<=m;++i)
	{
		ans=max(ans,(long long)pq.size()*(i-1)-ss);
		while(pq.size()&&-pq.top().first==i)ss-=pq.top().second,pq.pop();
		for(j=0;j<v[i].size();++j)pq.push(make_pair(-v[i][j],i)),ss+=i;
	}
	printf("%lld",s-ans);
}

Measured memory_bytes: 6132
#include <iostream>
#include <vector>
#include <cmath>
#include <map>
#include <set>
 
using namespace std;
typedef long long int ll;

int N;

map<ll, ll> L,R;
//vector<int> A;

int main()
{
  int i, p;
  int a;
  ll ans=0;
  unsigned long c;

  cin >> N;
  for (i=1; i<=N; i++) {
    cin >> a;
    auto itl = L.find(i+a);
    if (itl == L.end())
      L.emplace(i+a, 1);
    else {
      p = itl->second+1;
      L.erase(itl);
      L.emplace(i+a, p);
    }
    auto itr = R.find(i-a);
    if (itr == R.end())
      R.emplace(i-a, 1);
    else {
      p = itr->second+1;
      R.erase(itr);
      R.emplace(i-a, p);
    }

//    A[i] = a;
  }

  auto itl_last = L.end();
  for (auto itl=L.begin(); itl!=itl_last; itl++) {
    auto itr = R.find(itl->first);
    if (itr != R.end()) {
      ans += itl->second * itr->second;
    }
  }

  printf("%lld\n", ans);

  return 0;
}


Measured memory_bytes: 26716
#include<bits/stdc++.h>
#define int long long
using namespace std;
int vc=1000000007;
int h,w,n;
int node[1000010];
int a,b;
int cnt=0,z;
int ans[11];
signed main(){
	cin>>h>>w>>n;
	z=(h-2)*(w-2);
	while(n--){
		cin>>a>>b;
		for (int i=-2;i<=0;i++){
			for (int j=-2;j<=0;j++){
				if(a+i>=1&&a+i<=h-2&&b+j>=1&&b+j<=w-2){
					node[cnt++]=vc*(a+i)+(b+j);
				}
			}
		}
	}
	sort(node,node+cnt);
	for (int i=0,t=1;i<cnt;i++){
		if(node[i]==node[i+1])	t++;
		else{
			ans[t]++;
			z--;
			t=1;
		}	
	}
	cout<<z<<"\n";
	for (int i=1;i<10;i++)	cout<<ans[i]<<"\n";
}

Measured memory_bytes: 7296
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("no-stack-protector")
//#pragma GCC target("popcnt")
//#pragma GCC target("sse4")
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define rng(a) a.begin(),a.end()
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define sz(a) (int)(a.size())
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef long double ld;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
signed main(){
	int n, k;
	cin >> n >> k;
	int a[n];
	for (int i = 0; i < n; i++){
		cin >> a[i];
	}
	int l = 0, r = 1e9;
	while(r - l > 1){
		int m = (l + r) / 2;
		int sum = 0;
		for (int i = 0; i < n; i++){
			sum += (a[i] - 1)/m;
		}
		if (sum <= k) r = m;
		else l = m;
	}
	cout << r;







}

Measured memory_bytes: 4372
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define repLRE(i, l, r) for (ll i = (l); i <= (r); ++i)
#define rrepLRE(i, l, r) for (ll i = (l); i >= (r); --i)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

ll dx[9] = {-1, 1, 0, 0, -1, -1, 1, 1, 0};
ll dy[9] = {0, 0, -1, 1, -1, 1, -1, 1, 0};

/* Macros reg. ends here */

const ll INF = 1LL << 50;

static const long long mod = 1000000007;

int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cout << fixed << setprecision(15);

  ll k;
  string s;
  cin >> k >> s;

  if((ll)s.size() <= k){
    cout << s << endl;
    return 0;
  }

  string ans = s.substr(0, k);
  ans += "...";

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3656
N=60
def f(t):
    c,t=t%N,t/N
    b,a=t%N,t/N
    print "%02d:%02d:%02d"%(a,b,c)
    return

t1=2*N*N
while 1:
    h,m,s=map(int,raw_input().split())
    if [h,m,s]==[-1,-1,-1]: break
    t2=(h*N+m)*N+s
    t=t1-t2
    f(t)
    f(t*3)

Measured memory_bytes: 4216
#include<iostream>
#include<string>
#include<vector>

long long calcComb(long long n, long long r){
	long long numer=1;
	long long denom=1;

	for(long long i=0; i<r; i++)
		numer*= (n-i);

	for(long long i=0; i<r; i++)
		denom*= (r-i);

	return numer/denom;
}

int main(){
	std::string s;
	long long n;

	long long ans= 0;

	std::cin>>s;
	std::cin>>n;

	std::vector<long long> pow9(n+1, 1);
	for(long long i=0; i<n; i++) 
		pow9[i+1]= pow9[i]*9;

	long long digit= s.size();
	long long fixdeg= 0;

	for(long long i=0; i<digit; i++){
		long long top= s[i]-'0';

		if(top>0){
			ans+= pow9[n-fixdeg] * calcComb(digit-i-1, n-fixdeg);
			ans+= pow9[n-fixdeg-1] * (top-1) * calcComb(digit-i-1, n-fixdeg-1);
			fixdeg++;
		}

		if(fixdeg>= n){
			ans++;
			break;
		}
	}

	std::cout<<ans<<std::endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
struct Edge {
  ll to;
  ll cost;
};
int main() {
  int N;
  cin >> N;
  vector<int> A(8);
  int over3200 = 0;
  bool t = false;
  REP(i, N) {
    int a;
    cin >> a;
    if(a<3200){
      A[a / 400]++;
      t = true;
    }else{
      over3200++;
    }
  }
  if(!t){
    over3200--;
    A[0]++;
  }
  int ans = 0;
  REP(i, 8) ans += A[i] != 0 ? 1 : 0;
  cout << ans << " " << ans + over3200 << endl;
}

Measured memory_bytes: 256
//#include <bits/stdc++.h>
//#include <stdio.h>
#include<iostream>
#include<cstdio>
#include<bitset>
#include<algorithm>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<string>
#include<string.h>
#include<cmath>
#include<utility>
#include<functional>
#include<map>
#include<set>
#include<cctype>
#include<fstream>


#define FOR(i, a, b) for( int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for( int i=(a);i>=(b);i--)
#define LFOR(i, a, b) for( long long int i=(a);i<=(b);i++)
#define LRFOR(i, a, b) for(long long int i=(a);i>=(b);i--)
#define MOD 1000000007
#define INF 1000000000 //2000000000
#define LINF 1000000000000000000 //9000000000000000000
#define PI 3.14159265358979
#define MAXI 7500000

using namespace std;
typedef long long int ll;
typedef pair< long long int, long long  int> P;

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


int main(void) {
	int a, b;
	char op;

	cin >> a >> op >> b;

	if (op == '+') {
		cout << a + b << endl;
	}
	else {
		cout << a - b << endl;
	}



	return 0;
}

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

int main(){
    while(true){
        int n;
        cin >> n;
        if(n == 0)
            break;
        
        vector< pair<double, string> > v(n);
        for(int i=0; i<n; i++){
            string l;
            int p, a, b, c, d, e, f, s, m;
            cin >> l >> p >> a >> b >> c >> d >> e >> f >> s >> m;
            v[i].first = -(double)(m * f * s -p) / (double)(a + b + c + m*(d + e));
            v[i].second = l;
        }
        sort(v.begin(), v.end());
        for(int i=0; i<n; i++){
            cout << v[i].second << endl;
        }
        cout << '#' << endl;
    }
  
    return 0;
}

Measured memory_bytes: 3160
#include "iostream"
using namespace std;

int LinearSearch(int x, int S[], int N) {
	S[N] = x;
	for (int i = 0; ; i++) {
		if (S[i] == x)
			if (i < N) {
				return 0;
			}
			else
				return 1;
	}
}

int main()
{
	while (1) {
		int h[4000] = { 0 };
		int m[4000] = { 0 };
		int a = 0;
		int n;
		cin >> n;
		if (n == 0)
			break;
		int number, nedan, amount;
		for (int i = 0; i < n; i++) {
			cin >> number >> nedan >> amount;
			h[number] += nedan*amount;
			if (h[number] >= 1000000) {
				if (LinearSearch(number, m, a)) {
					m[a] = number;
					a++;
				}
			}
		}
		if (a == 0)
			cout << "NA"<<endl;
		for (int i = 0; i < a; i++) {
			cout << m[i] << endl;
		}
	}
		return 0;
}

Measured memory_bytes: 3076