akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for (int i =0;i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;

int debug=0;

ll combi(ll n){
    return n*(n-1)/2;
}

int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    // use the following as index
    rep(i,n) a[i]--;
    
    vector<int> cnt(n);
    rep(i,n) cnt[a[i]]++;

    ll tot=0;

    rep(i,n){
        tot +=combi(cnt[i]);
    }

    rep(i,n){
        ll ans = tot;
        ans -= combi(cnt[a[i]]);
        ans += combi(cnt[a[i]]-1);
        cout << ans << endl;
    }


    return 0;
}

Measured memory_bytes: 4096
program main
implicit none
integer(8) :: i, j, k
integer(8) :: n, m
integer(8), allocatable :: a(:), b(:)

read(*,*) n, m
allocate( a(n), b(n) )
do i = 1, n
   read(*,*) a(i), b(i)
end do
call heapsort2( n, a, b )

i = 0
j = 1
k = 0
do while( i+b(j) .le. m )
   k = k + a(j)*b(j)
   i = i + b(j)
   j = j + 1
end do
k = k + (m-i)*a(j)
write(*,'(i0)') k
      
stop
contains
subroutine heapsort2(n,array,array2)
  implicit none
  integer(8),intent(in) :: n
  integer(8),intent(inout) :: array(1:n), array2(1:n)
  integer(8) ::i,k,j,l
  integer(8) :: t, u

  l=n/2+1
  k=n
  do while(k.ne.1)
     if(l.gt.1)then
        l=l-1
        t=array(L)
        u=array2(L)
     else
        t=array(k)
        u=array2(k)
        array(k)=array(1)
        array2(k)=array2(1)
        k=k-1
        if(k.eq.1) then
           array(1)=t
           array2(1)=u
           exit
        end if
     end if
     i=l
     j=l+l
     do while(j.le.k)
        if(j.lt.k)then
           if(array(j).lt.array(j+1))j=j+1
        end if
        if (t.lt.array(j))then
           array(i)=array(j)
           array2(i)=array2(j)
           i=j
           j=j+j
        else
           j=k+1
        end if
     end do
     array(i)=t
     array2(i)=u
  end do
end subroutine heapsort2


end program main


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define ll  long long
#define scan(n) scanf("%d",&n)
#define ls(n) scanf("%lld",&n)
#define print(n) printf("%d ",n)
#define pln(n) printf("%d\n",n)
#define lpln(n) printf("%lld\n",n)
#define rep(i,a,n) for(int i=a;i<n;i++)
#define rev(i,a,n) for(int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define gcd __gcd
#define tc           ll t1; cin>>t1; while(t1--)
#define inp         ll n; cin>>n; ll arr[n]; rep(i,0,n) cin>>arr[i];
#define vect vector<ll>
#define sortv(v)       sort(v.begin(),v.end())
#define lower(v,n)    lower_bound(v.begin(),v.end(),n)-v.begin()
#define upper(v,n)    upper_bound(v.begin(),v.end(),n)-v.begin()
#define bitcount(n) __builtin_popcount(n)
#define ln <<endl
#define inf          1e12
#define ninf         LONG_MIN
#define fast()         ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
const   ll mod=1e9+7;
const ll N=1e5+5;




int main() 
{ 
         fast();
        
         int n;
         double d;

         cin >> n>>d;
         int count=0;
         while(n--)
         {
           double x,y;
           cin >> x >> y;
           double dist=sqrt(x*x+y*y);
           if(dist<=d)
            count++;
         }
         cout<<count;
         

  return 0; 
} 


Measured memory_bytes: 3792
#include <stdio.h>
#include <iostream>
#include <vector>
#include <string>
#include <list>
#include <algorithm>
#include <set>
#include <queue>
#include <math.h>

using namespace std;
#define ll long long

bool sortbysec(const pair<int,int> &a, const pair<int,int> &b) 
{ 
    return (a.second < b.second); 
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //freopen("aa_input.txt", "r", stdin);
    int n;
    cin>>n;
    int arr[n];
    for(int i=0; i<n; i++) cin>>arr[i];

    sort(arr, arr+n);

    int d = n/2-1;
    int first = arr[d]+1;
    int second = arr[d+1];
    cout<<(second-first)+1<<endl;
    
    
    return 0;
}
/*

riaadmorshed@gmail.com

*/

Measured memory_bytes: 640
#!/usr/bin/env python3
# -*- coding: utf-8 -*-


def main():
    N, M = map(int, input().split())

    KSS = [list(map(int, input().split())) for _ in range(M)]

    P = list(map(int, input().split()))

    cnt = 0

    for i in range(2 ** N):
        bin_i = '{:010b}'.format(i)[::-1]

        for i in range(M):
            ks = KSS[i]
            k = ks[0]
            s = ks[1:]

            sum_s = 0

            for j in range(k):
                sum_s += int(bin_i[s[j] - 1])

            if sum_s % 2 != P[i]:
                break
        else:
            cnt += 1

    print(cnt)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3188
import bisect
n=int(input())
l=list(map(int, input().split()))

i=1
j=0
k=0
ta=0
rb=0
tc=0
cnt=0
m=0
ls=sorted(l)



for i in range(0,len(ls)-2):

    for j in range(i+1,len(ls)-1):
        l1 = ls[i]
        l2 = ls[j]
        ll= l1+l2
        # mid = 0
        k = bisect.bisect_left(ls,ll) - 1

        cnt+=k-j
print(cnt)

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

int top, S[1000];

void push(int x) {
	/* top?????????????????????????????????????????\ */
	S[++top] = x;
}

int pop() {
	top--;
	/* top??????????????????????´?????????? */
	return S[top+1];
}

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

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

	return 0;
}

Measured memory_bytes: 548
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int h, w;
ll ans, aa, bb;
bool used[410][410];
char maze[410][410];
int dh[4] = {0,1,0,-1};
int dw[4] = {1,0,-1,0};

void dfs(int hh, int ww, char c) {
  if (used[hh][ww]) return;
  used[hh][ww] = 1;
  if (c == '#') aa++;
  else bb++;
  for (int i = 0; i < 4; i++) {
    int th = hh + dh[i], tw = ww + dw[i];
    if (0 <= th && th < h && 0 <= tw && tw < w && maze[th][tw] != c) {
      dfs(th, tw, maze[th][tw]);
    }
  }
}


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> h >> w;
  for (int i = 0; i < h; i++) cin >> maze[i];
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (!used[i][j]) {
        aa = 0, bb = 0;
        dfs(i, j, maze[i][j]);
        ans += aa * bb;
      }
    }
  }
  cout << ans << endl;
  return 0;
}


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

int main() {
	int n,i;
	long int av=0;
	cin >> n;
	int a[n];
	for(i=0;i<n;i++){
		cin >> a[i];
		av += a[i];
	}
	sort(a,a + n);
	cout << a[0] << " " << a[n-1] << " " << av << endl;
	return 0;
}

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

int main()
{
    int n;
    cin >> n;
    vector<long long> a(n);

    rep(i, n)
    {
        cin >> a.at(i);
    }

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

    int frag = 1;
    for (int i = 0; i < n - 1; i++)
    {
        if (a.at(i) == a.at(i + 1))
        {
            frag = 0;
        }
    }

    if (frag == 0)
    {
        cout << "NO" << endl;
    }
    else if (frag == 1)
    {
        cout << "YES" << endl;
    }
}


Measured memory_bytes: 1792
IDENTIFICATION                   DIVISION.
PROGRAM-ID.                      ABC_072_A.
ENVIRONMENT                      DIVISION.
DATA                             DIVISION.
WORKING-STORAGE                  SECTION.
    01 INP    PIC X(21).
    01 X      PIC S9(10).
    01 t      PIC 9(10).
    01 ans    PIC X(10).

    01 ZS     PIC Z(10)9.
    01 DUMMY  PIC X(1).

PROCEDURE                        DIVISION.
MAIN.
    ACCEPT INP.

    UNSTRING INP
    DELIMITED BY SPACE
    INTO X t.

    SUBTRACT t FROM X.

    IF X <= 0 THEN
        DISPLAY 0
    ELSE
        MOVE X TO ZS
        PERFORM UNANS
        DISPLAY ans(1:FUNCTION STORED-CHAR-LENGTH(ans))
    END-IF.

    STOP RUN.

UNANS                            SECTION.
    UNSTRING
        ZS DELIMITED BY ALL SPACE
        INTO DUMMY ans
    END-UNSTRING.


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


ll gcd(ll A, ll B){
    if(B == 0)return A;
    return gcd(B, A % B);
}
ll lcm(ll A, ll B){
    return A * B / gcd(A, B);
}
bool root(string s){
    int n=s.length();
    if(n==2){
        if(s[0]==s[1]){
            return true;
        }
        else return false;
    }
    if(n==3){
        if(s[0]==s[2]){
            return true;
        }
        else return false;
    }
 
    return false;
}
 
 
//深さ優先
vector<int> seen;
vector<ll> h;
 
//普通の深さ優先探索seenを返す感じ
void dfs(const Graph &G,int v){
    seen[v] = 0; //v探索済み
 
    P good=make_pair(v,h[v]);
    for(auto next_v :G[v]){
        if(seen[next_v]!=-1) continue;//もう探索していた
        if(h[next_v]>good.second){
            good=make_pair(next_v,h[next_v]);
        }
        dfs(G,next_v);
    }
 
    if(!(h[v]==good.second && v==good.first)){
        seen[good.first]=1;
    }
}
 
signed main(){
    /*
    int n,m;
    cin>>n>>m;
 
    h.assign(n,0);
    rep(i,0,n) cin>>h[i];
 
    Graph G(n);
    rep(i,0,m){
        int a,b; cin>>a>>b;
        G[a-1].push_back(b-1);
        G[b-1].push_back(a-1);
    }
 
    seen.assign(n,-1);
 
    rep(i,0,n){
        if(seen[i]==-1){
            dfs(G,i);
        }
    }
 
    int sum=accumulate(all(seen),0);
 
    cout<<sum<<endl;*/
 
    int n; cin>>n;
    int a[n+1],b[n];

    rep(i,0,n+1) cin>>a[i];
    rep(i,0,n) cin>>b[i];

    int ans=0;
    for(int i=0;i<n;i++){
        if(a[i]>=b[i]){
            ans+=b[i];
            a[i]-=b[i];
            b[i]=0;
        }else{
            ans+=a[i];
            b[i]-=a[i];
        }
        if(a[i+1]>=b[i]){
            ans+=b[i];
            a[i+1]-=b[i];
        }else{
            ans+=a[i+1];
            a[i+1]=0;
        }
    }

    cout<<ans<<endl;

}   

Measured memory_bytes: 1792
#pragma region RegionDefs
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0,i##_len=(n);i<i##_len;++i)
#define reps(i,l,r) for(int i=(l),i##_len=(r);i<i##_len;++i)
#define all(x) begin(x),end(x)
using namespace std;
const int INF = 1e9;
template<class T=int> using V = vector<T>;
template<class T=int> using PQ = priority_queue<T>;
template<class T=int> using PQG = priority_queue<T, V<T>, greater<T>>;
typedef long long ll;
const ll MOD = 10e9+7LL;
void in() {}
template<class Head, class... Tail>
void in(Head&& head, Tail&&... tail)
{
    cin >> head;
    in(move(tail)...);
}
#define IN(...) ll __VA_ARGS__; in(__VA_ARGS__)
//時間が厳しいとき使う
#define INI(...) int __VA_ARGS__; in(__VA_ARGS__)
#define INS(T, ...) T __VA_ARGS__; in(__VA_ARGS__)
#define VIN(T, v, n) V<T> v(n); for(auto& _elem:v)cin>>_elem
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 (a>b) {a=b; return 1;} return 0;}
#define y0 y__0
#define y1 y__1
#define j0 j__0
#define j1 j__1
#define YN(e) cout << ((e) ? "YES" : "NO") << endl
#define yn(e) cout << ((e) ? "Yes" : "No") << endl
#pragma endregion RegionDefs

int color(char c)
{
    if (c == 'R') return 0;
    if (c == 'G') return 1;
    if (c == 'B') return 2;
}
void solve()
{
    IN(n);
    string s; cin >> s;
    ll r = 0;
    ll g = 0;
    ll b = 0;
    rep(i, n)
    {
        if (s[i] == 'R') ++r;
        if (s[i] == 'G') ++g;
        if (s[i] == 'B') ++b;
    }
    ll sum = r * g * b;
    rep(i, n)
    {
        reps(j, 1, n)
        {
            if (i+2*j >= n) break;
            if (s[i] != s[i+j] && s[i+j] != s[i+2*j] && s[i+2*j] != s[i]) --sum;
        }
    }
    cout << sum << endl;
}

int main()
{
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(numeric_limits<double>::max_digits10);

    solve();

    return 0;
}

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

int main()
{
  int N, K; cin >> N >> K;
  ll ans = K;
  
  rep(i, N-1) ans *= K-1;
  
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
	
using namespace std;
const int MAX_K=1000;
int K;
int main(){
	cin>>K;
	if(K==1){
		cout<<1<<endl<<1<<endl;
	}else{
		int n=(K+3)/4*2,k=2*n-K;
		cout<<n<<endl;
		REP(r,n){
			REP(c,n){
				if (c){
					cout<<" ";
				}
				int col=(r+c)%n;
				if(r%2==1){
					col+=n;
				}
				if (col>=2*n-k){
					col-=n;
				}
				cout<<col+1;
			}
			cout<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1152
#include <fstream>
#include <iostream>
#include <climits>
#include <algorithm>
using namespace std;
 
int main()
{
  int n, x, y;
  cin >> n >> x >> y;
  x = x - 1;
  y = y - 1;
  int dist_hist[n];
  int i, j, k;

  for (k=0; k<n; k++)
    dist_hist[k] = 0;
  
  for (i=0; i<n-1; i++)
    for (j=i+1; j<n; j++)
      dist_hist[min(j-i, abs(x-i)+1+abs(y-j))]++;

  for (k=1; k<n; k++)
    cout << dist_hist[k] << "\n";
 
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
const int N = 6e5+20;

vector <int> v;
int n, k, este, actual;
int arr [N];

void f(int actual)
{
    if(actual == 0) arr[0] = 0;
    else
    {
        for(int i = 0; i <= k; i++)
        {
            if(actual-i >= 0)
            {
                int peso = arr[actual-i] + abs(v[actual] - v[actual-i]);
                //cout<<peso1<<endl;
                if(peso < arr[actual])
                    arr[actual] = peso;
            } 
        }
        
    }
}
int main()
{
    cin>>n>>k;
    for(int i = 0; i < n; i++){cin>>este;v.push_back(este);}
    memset(arr, 1000000, sizeof arr);
    for(int i = 0; i < n; i++)f(i);
    cout<<arr[n-1]<<endl;
    //for(int i = 0; i < n; i++)cout<<arr[i]<<" - ";
}

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

#define printl(s) cout << s << endl;
#define print(s) cout << s << endl; return 0;
#define printFix(n,i) cout << fixed << setprecision(i) << n << endl; return 0;
#define yes cout << "Yes" << endl; return 0;
#define no cout << "No" << endl; return 0;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rep2(i,n) for (int i = 1; i < (n)+1; ++i)
#define bitrep(i,n) for (int i = 0; i < (1<<(n));i++)
#define isOne(bit,i) (bit & (1 << i))
using ll = long long;
using pii = pair<int, int>;
using si = set<int>;

const ll modSeed = pow(10,9) + 7;
const int INF = 100'000'000;

template <typename T>
vector<T> getValues(ll num){
    vector<T> values(num);
    for(ll i=0;i<num;i++){
        cin >> values.at(i);
    }
    return values;
}

template <typename T>
vector<T> getSumVec(vector<T> vec){
    vector<T> values(vec.size()+1,0);
    for(ll i=0;i<values.size()-1;i++){
      values.at(i+1) = values.at(i) + vec.at(i);
    }
    return values;
}

string S;
ll N,cnt;

int main(){
  cin >>N;
  ll ans = 0;
  auto inputs = getValues<ll>(N);
  auto sums = getSumVec<ll>(inputs);
  rep(i,N){
    ll sumMod = (sums.at(N) - sums.at(i+1)) % modSeed;
    ans += sumMod * inputs.at(i);
    ans %= modSeed;
  }
  printl(ans);
}


Measured memory_bytes: 8012
n=int(input())
H=list(map(int,input().split()))

dp=[float('inf')]*n
dp[0]=0
dp[1]=abs(H[1]-H[0])
for i in range(2,n):
  dp[i]=min(dp[i],dp[i-1]+abs(H[i]-H[i-1]))
  dp[i]=min(dp[i],dp[i-2]+abs(H[i]-H[i-2]))
print(dp[-1])

Measured memory_bytes: 13980
#include <bits/stdc++.h>
#define rep(a,n) for (ll a = 0; a < (n); ++a)
#define _GLIBCXX_DEBUG
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<vector<ll> > Graph;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll INF = 1e18;

int main(){
    int a,b;
    cin >> a >> b;
    cout << a*b << endl;

    return 0;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;
using namespace std;
#define ll long long int
#define ld long long double
#define vi vector<int>
#define vl vector<ll>
#define pi pair<int, int>
#define pl pair<ll, ll>
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define nl '\n'
#define mp make_pair
#define debug1(x) cout <<#x<<" "<<x<<'\n';
#define debug2(x,y) cout <<#x<<" "<<x <<" "<<#y<<" "<<y <<'\n';
#define debug3(x,y,z) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<" "<<#z<<" "<<z<<'\n';
#define fi first
#define se second
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define inf 1e18
const int mod = (int)1e9 + 7;
pair<ll, ll>s4[4] = {{ -1, 0}, {1, 0}, {0, -1}, {0, 1}};
pair<ll, ll>s8[8] = {{ -1, -1}, { -1, 0}, { -1, 1}, {0, -1}, {0, 1}, {1, 1}, {1, 0}, {1, -1}};

void judge() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}

void solve() {
    ll n;
    cin >> n;
    string ans = "";
    while (n > 0) {
        int rem = n % 26;
        if (rem == 0) {
            ans += "z";
            n /= 26;
            n--;

        }
        else {
            ans += rem - 1 + 'a';
            n /= 26;
        }
    }
    reverse(ans.begin(), ans.end());
    cout << ans << nl;
}

signed main() {
    judge();
    boost;
    solve();
}


Measured memory_bytes: 3656
import numpy as np
n,k=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
a = np.array(a,dtype="int64")
a_minus = a[a<0]
a_plus = a[a>0]
a_zero = a[a==0]
#print(a_plus)
l = - 10**19
r = 10**19


while r - l > 1:
  mid = (l+r)//2
  # mid以下の個数を調べる
  cnt = 0
  # 正の数の組み合わせでmid以下の個数を調べる
  cnt += a.searchsorted(mid//a_plus, side="right").sum()
  # 負の数で同様
  cnt += (n - a.searchsorted((-mid-1)//(-a_minus), side="right")).sum()
  # 同じ数の組み合わせ(差し引くよう)
  cnt -= np.count_nonzero(a*a<=mid)
  # ゼロも同様(mid>=0のときのみ)
  cnt += len(a_zero)*n if mid >= 0 else 0
  
  # 重複を割る
  cnt //= 2
  
  if cnt >= k:
    r = mid
  else:
    l = mid
  
print(r)

Measured memory_bytes: 47652
import java.util.Scanner;

class Main{
 public static void main(String[] args){
 Scanner sc = new Scanner(System.in);
 int a = sc.nextInt();
 int b = sc.nextInt();
if(a == b){
 System.out.println("a" + " "+ "==" +" " + "b");
 }else if(a > b){
 System.out.println("a" + " " + ">" +" " + "b");
 }else{
 System.out.println("a" + " " + "<"+ " "+ "b");
 }
}
}


Measured memory_bytes: 26164
#include <algorithm>
#include <bitset>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define MOD (1000000007l)
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)

using namespace std;

void solve() {
  ll N, R;
  cin >> N >> R;

  ll ans = 0;

  if (N >= 10) ans = R;
  else {
    ans = R + 100 * (10 - N);
  }

  cout << ans << endl;
}

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


Measured memory_bytes: 256
from math import sqrt

N = int(input())

search_max = int(sqrt(N))

min_number = 10**12
for x in range(1, search_max + 1):
    if N % x == 0:
        y = N // x
        if x + y < min_number:
            min_number = x + y

print(min_number-2)


Measured memory_bytes: 9124
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define fi first
#define se second
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define rep11(i, n) for (int i = 1; i < (int)(n); ++i)
#define repo(i, o, n) for (int i = o; i < (int)(n); ++i)
#define repm(i, n) for (int i = (int)(n)-1; i >= 0; --i)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define pb(n) push_back(n)
#define mp make_pair
#define MOD 1002000007
#define INF LONG_LONG_MAX

typedef pair<int, int> P;
int main(){
    int n;
    cin>>n;
    while(1){
        int p=n/100;
        if(p*1+p*10+p*100==n){
            cout<<n<<endl;
            break;
        }
        n++;
    }
}
    

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n, m;
    cin >> n>> m;
    long int a[n];
    long long int vote = 0;
    for(int i = 0 ;i < n ; i++){
    	cin>>a[i];
    	vote+=a[i];
    }
    long int k = (long int)(ceil)((long double)vote/(4*m));
    int cnt = 0 ;
    for(int i = 0; i< n ;i++){
    	if(a[i] >= k )cnt++;
    }
    if(cnt >= m)cout<<"Yes\n";
    else cout<<"No\n";
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt();
		boolean judge=false;
		for(int i=0; i<n; i++){
			long a=sc.nextLong();
			if(a%2!=0){
				judge=true;
			}
		}
		if(judge){
			System.out.println("first");
		}else{
			System.out.println("second");
		}
	}
}




Measured memory_bytes: 48424
#include<bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; i++)
#define repo(i, n) for(int i=1; i<=n; i++)
#define ssort(a) sort(a.begin(), a.end())
#define INF 1001001001
#define INFll 100100100100100
// debug用
#define PrintVec(x) for (auto elementPrintVec: x) { cout << elementPrintVec << " "; } cout << endl;

using namespace std;
using ull = unsigned long long;
using ll = long long;
using P = pair<int, int>;
const int mod = 1000000007;

int main(){
  int n, k;
  cin >> n >>k;
  ll ans=0;
  if(k==0){
    cout << (ll)n*n << endl;
    return 0;
  }
  for(int b=k+1; b<=n; b++){
    ans+=n/b*(b-k);
    ans+=max(n%b-k+1, 0);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3608
#include <stdio.h>
#include <stdlib.h>

int asc(const void *a, const void *b){
    return *(int *)a - *(int *)b;
}

int main(){
    int n, a[100], i;

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

    qsort(a, n, sizeof(int), asc);

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

    return 0;
}

Measured memory_bytes: 128
/*---Bismillahir Rahmanir Rahim---*/
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <unordered_map>
#include <queue>
#define mod 998244353
#define int long long
#define ld long double
#define pb push_back
#define sz(x) (int)x.size()
#define ff first
#define ss second
#define pii pair<int, int>
using namespace std; 

bool palindrome(int  n){
	int  p = n,s=0,i=10;
	while (n){
		s = s*i+(n%10);
		n /= 10; 
		// 123
	}
	//cout << s << " "<<p <<endl;
	if (s == p) return  true; 
	return  false; 
}

inline void solve()
{
	int  a, b, ans = 0; 
	cin >> a >> b ; 
	for (int i=a;i<=b;i++)
		if (palindrome(i)) ans++;
	cout << ans << endl;
}

signed main()
{
	int t=1; // cin>>t;
	while(t--) solve();
	return 0;
}

/*
31415 92653

*/


Measured memory_bytes: 3536
#include <stdio.h>



int main()
{
	int y, x, z, b, N, A[3][3], B[3][3] = {
											{0,0,0},
											{0,0,0},
											{0,0,0}
	};
	
	for (x = 0; x <= 2; x++)
	{
		scanf("%d %d %d", &A[x][0], &A[x][1], &A[x][2]);
	}
	scanf("%d", &N);
	for (y = 1; y <= N; y++) 
	{
		scanf("%d", &b);
		for (x = 0; x <= 2; x++)
		{
			for (z = 0; z <= 2; z++)
			{
				if (b == A[x][z]) 
				{
					B[x][z] = 1;
				}
			}
		}
	}
	/*
	for (x = 0; x <= 2; x++)
	{
		printf("%d %d %d\n", B[x][0], B[x][1], B[x][2]);
	}
	*/
	for (x = 0; x <= 2; x++)
	{
		if (B[x][0] & B[x][1] & B[x][2] == 1 || B[0][x] & B[1][x] & B[2][x] == 1 ||

			B[0][0] & B[1][1] & B[2][2] == 1 || B[0][2] & B[1][1] & B[2][0] == 1) 
		{
			printf("Yes\n");
			N = 0;
			break;
			
		}
		
		
	}
	if (N != 0)printf("No\n");
	


	
	return 0;
}


Measured memory_bytes: 128
import java.util.Scanner;

public class Main{
	static boolean rightA(int a, int b, int c){
		int max = a;
		if( b > a ){
			int temp = a;
			a = b;
			b = temp;
		}
		if( c > a ){
			int temp = a;
			a = c;
			c = temp;
		}
		
		if( a*a == b*b + c*c )
			return true;
		else return false;
	}

	public static void main(String[] args){
		Scanner stdIn = new Scanner(System.in);
		int n = stdIn.nextInt();
		
		String[] str = new String[n+1];
		String[][] s = new String[n][3];
		int[] a = new int[n];
		int[] b = new int[n];
		int[] c = new int[n];
		for(int i = 0; i < n+1; i++){
			str[i] = stdIn.nextLine();
		}
		for(int i = 0; i < n; i++){
			s[i] = str[i+1].split(" ", 3);
			a[i] = Integer.parseInt(s[i][0]);
			b[i] = Integer.parseInt(s[i][1]);
			c[i] = Integer.parseInt(s[i][2]);
		}
		
		for(int i = 0; i < n; i++){
			if( rightA(a[i], b[i], c[i]) ){
				System.out.println("YES");
			}
			else 
				System.out.println("NO");
		}
	}
}

Measured memory_bytes: 13000
// inputに入力データ全体が入る
function Main(input) {
  line = input.split(" ");
  var N = line[0];
  var L = +line[1];
  var array = [];
  var sum = 0;
  var min = 0;
  var includesZero = false;
  var lastIndexNegative = false;

  for(i=0; i<N; i++){
    array.push(L+i);
    sum += L+i
    if(L+i==0){
      min = 0;
      includesZero = true;
    }
    if(i+1 == N && L+i < 0){
      min = L+i;
      lastIndexNegative = true;
    }
  }
  
  if(includesZero == true){
  }else if(lastIndexNegative == true){
  }else{
    min = Math.min.apply(null, array);
  }
      
  console.log(sum-min);
  
}
  
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 7500
#include <bits/stdc++.h>
using namespace std;
#define int long long
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 P=pair<long long,long long>;
#define rep(i,n) for(long long i=0; i<(long long)n; i++)
#define FOR(i,a,b) for(long long i=a; i<b; i++)
#define ll long long
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((long long)(x).size())
#define COUT(x) cout << x << endl
#define PB(x) push_back(x)
#define MP make_pair
#define vint vector<int>
#define vvint vector<vector<int>>
#define vstr vector<string>
#define vp vector<pair<int,int>>
#define vb vector<bool>
#define SUM(x) accumulate(x.begin(),x.end(),0)
#define MAX(x) *max_element(x.begin(),x.end())
#define MIN(x) *min_element(x.begin(),x.end())
#define couty cout<<'Y'<<'e'<<'s'<<endl
#define coutn cout<<'N'<<'o'<<endl
#define coutY cout<<'Y'<<'E'<<'S'<<endl
#define coutN cout<<'N'<<'O'<<endl
#define yn(x) cout<<(x?"Yes":"No")<<endl
#define YN(x) cout<<(x?"YES":"NO")<<endl
long long gcd(long long a,long long b){return b?gcd(b,a%b):a;}
long long lcm(long long a, long long b){return a*b/gcd(a,b);}
const long long dx[4]={1,0,-1,0};
const long long dy[4]={0,1,0,-1};
const long long INF = 1e12;
const long long MOD = 1e9+7;
#define f first
#define s second
#define ld long double

vint x,y;
ld dist(int i,int j){
    ld dx=x[i]-x[j];
    ld dy=y[i]-y[j];
    return pow(dx*dx+dy*dy,0.5);

}

int fractal(int n){
    int ret=1;
    FOR(i,1,n+1) ret*=i;
    return ret;
}
signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(15);

    int n; cin >> n;
    x.resize(n); y.resize(n);
    rep(i,n) cin >> x[i] >> y[i];
    vint order(n);
    rep(i,n) order[i]=i;

    ld res=0.0;

    do{
        rep(i,n-1){
            res+=dist(order[i],order[i+1]);
        }
    }while(next_permutation(all(order)));
    //cout<<fractal(3)<<endl;
    cout<<res/fractal(n)<<endl;
}

Measured memory_bytes: 640
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#ifndef LOCAL
#define debug(x) ;
#else
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

template <typename T1, typename T2>
ostream &operator<<(ostream &out, const pair<T1, T2> &p) {
  out << "{" << p.first << ", " << p.second << "}";
  return out;
}

template <typename T>
ostream &operator<<(ostream &out, const vector<T> &v) {
  out << '{';
  for (const T &item : v) out << item << ", ";
  out << "\b\b}";
  return out;
}
#endif

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 200010


int main(){
  int n, a, b, c;
  int t[10];

  scanf("%d%d%d%d", &n, &a, &b, &c);

  for(int i=0;i<n;i++){
    scanf("%d", t+i);
  }

  sort(t, t+n);

  ll ans = LLINF;

  do{

    for(int i=0;i<n;i++){
      for(int j=i+1;j<n;j++){
        for(int k=j+1;k<n;k++){
          ll calc = 0, A = 0, B = 0, C = 0;

          calc += i*10 + (j-i-1)*10 + (k-j-1)*10;

          for(int p=0;p<=i;p++) A += t[p];
          for(int p=i+1;p<=j;p++) B += t[p];
          for(int p=j+1;p<=k;p++) C += t[p];

          calc += abs(A - a) + abs(B - b) + abs(C - c);

          ans = min(ans, calc);
        }
      }
    }

  }while(next_permutation(t, t+n));


  cout << ans << endl;

  return 0;
}


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

int main() {
  int N;
  cin >> N;
  vector<int> a(N),b(N),c(N);
  for(int i=0;i<N;++i) cin >> a[i];
  for(int i=0;i<N;++i) cin >> b[i];
  for(int i=0;i<N;++i) cin >> c[i];
  sort(a.begin(),a.end());
  sort(b.begin(),b.end());
  sort(c.begin(),c.end());
  
  int ci;
  vector<long long> bsum(N+1);
  bsum[N] = 0;
  for(int i=1;i<=N;++i){
    ci = upper_bound( c.begin(), c.end(), b[N-i]) - c.begin();
    bsum[N-i] = bsum[N-i+1] + N-ci;
    //cout<<i<<" "<<N-ci<<" "<<bsum[N-i]<<endl;
  }
  long long sum = 0;
  int bi;
  for(int i=0;i<N;++i){
    bi = upper_bound( b.begin(), b.end(), a[i]) - b.begin();
    //cout<<i<<" bi= "<<bi<<endl;
    sum += bsum[bi];
  }
 
    
  cout<<sum<<endl;
  
}

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

int main() {
    ll n, a, b, c, d;
    cin >> n >> a >> b >> c >> d;
    for (ll k = 0; k < n; k++) {
        ll lb = c * (n - 1 - k) - d * k;
        ll ub = -c * k + (n - 1 - k) * d;
        if (lb <= b - a && b - a <= ub) {
            puts("YES");
            return 0;
        }
    }
    puts("NO");
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,b,e) for(int i=(b);i<(e);++i)
#define RREP(i,b,e) for(int i=(b)-1;i>=e;--i)
#define rep(i,e) for(int i=0;i<(e);++i)

constexpr int MOD = 1000000007;
constexpr int INF = 1LL << 30;
constexpr long long LLINF = 1LL << 60;

template<typename T>
istream &operator>>(istream &is, vector<T> &vec) {
  for (T &x : vec) is >> x;
  return is;
}

template<typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  os << "[";
  for (auto it = vec.begin(); it != vec.end(); ++it) {
    if (it != vec.begin()) os << ", ";
    os << *it;
  }
  return os << "]";
}

inline void print(void) { cout<<'\n'; }
template<class T> inline void print(const T &x) { cout<<x<<'\n'; }
template<class T, class... U> inline void print(const T &x, const U&... y) { cout<<x<<" "; print(y...); }

long long dp[110][200010];
int main() {
  int n, w; cin>>n>>w;
  rep(i, 110) rep(j, 100010) dp[i][j] = LLINF;
  dp[0][0] = 0;
  rep(i, n) {
    int wt, v; cin>>wt>>v;
    rep(j, 100010) {
      dp[i+1][j+v] = min(dp[i+1][j+v], dp[i][j] + wt);
      dp[i+1][j] = min(dp[i+1][j], dp[i][j]);
    }
  }
  RREP(i, 100010, 0) {
    if (dp[n][i] <= w) {
      print(i);
      return 0;
    }
  }
  return 0;
}


Measured memory_bytes: 170240
# coding: utf-8
import itertools
import math
import bisect

N = int(input())
A = list(map(int, input().split(" ")))
A.sort()
B = list(map(int, input().split(" ")))
C = list(map(int, input().split(" ")))
C.sort()

res = 0
for bi in B:
    res += bisect.bisect_left(A, bi) * (N-bisect.bisect_right(C, bi))
print(res)



Measured memory_bytes: 29332
#include <vector>
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <limits.h>
#include <cmath>
#include <queue>
#include <map>
#include <iomanip>
#include <random>
#include <fstream>
#include <cassert>
#define rep(i, n) for (int i = 0; i < n; i++)
#define PI 3.14159265358979323846
#define MOD 1000000007
#define vi vector<int>
using namespace std;
using ll = long long;

// ----ここから下は以前競プロをやっていた時に使っていたものです----　

const int MAX = 1000000;

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

ll gcd(ll a, ll b)
{
  ll r;
  while ((r = a % b))
  {
    a = b;
    b = r;
  }
  return b;
}

template <class T> struct cord{
  T x,y;
};

template <class T> double dist(cord<T> a, cord<T> b){
  T dx=a.x-b.x;
  T dy=a.y-b.y;
  return sqrt(dx*dx+dy*dy);
}

struct s{
  int p,i,r;
};

//比較関数（降順）
bool cmpP(const s &a, const s &b){
  return a.p > b.p;
}

//比較関数（昇順）
bool cmpI(const s &a, const s &b){
  return a.i < b.i;
}

// ----本問について----
// 問題：Dinner
// 問題文URL：https://onlinejudge.u-aizu.ac.jp/problems/2642
// 所要時間：1時間
// 学んだこと：
// ------------------

// ----ここから本問のソースコード----

// グローバル変数（入力）
ll n,p,q,c[500010];

ll solve() {
  ll answer=LLONG_MIN;

  vector<ll> b(n);
  for (ll i=0; i<n; i++){
    b[i] = p*i+c[i];
  }
  sort(begin(b),end(b));

  ll s = 0;
  rep(i,n){
    s += c[i];
  }
  ll bSum = 0;
  ll sum;
  for(ll k=0; k<=n; k++){
    sum = s + k*p*(q+k-1) - bSum;
    if (sum > answer){ answer = sum; }
    if (k<n){bSum += b[k];}
  }

  return answer;
}

int main()
{
  //cout << fixed << setprecision(10);
  cin >> n >> p >> q;
  rep(i,n){cin >> c[i];}
  cout << solve() << endl;

  return 0;
}



Measured memory_bytes: 10756
#include <stdio.h>
int main()
{
	int m,f,r;
	while(1){
		scanf("%d %d %d",&m,&f,&r);
		if(m==-1&&f==-1&&r==-1)
			break;
		else if(m==-1||f==-1)
			printf("F\n");
		else if(m+f>=80)
			printf("A\n");
		else if(m+f>=65&&m+f<80)
			printf("B\n");
		else if(m+f>=50&&m+f<65)
			printf("C\n");
		else if(m+f>=30&&m+f<50){
			if(r>=50)
				printf("C\n");
			else
				printf("D\n");
		}
		else if(m+f<30)
			printf("F\n");
	}
	return 0;
}

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

long double abs(long double x)
{
  return (x < 0.0 ? -x : x);
}

long double sqrt(long double x)
{
  const long double EPS = 1e-8;
  long double x0 = x / 2.0, nx = 0.0;

  while (abs(nx - x0) > EPS){
    nx = x0;
    x0 = (x0 + x / x0) / 2.0;
  }

  return x0;
}

long double pi(int n = 1024)
{
  long double a = 1.0, b = 1.0 / sqrt(2.0), t = 1.0 / 4.0, p = 1;

  for (int i = 1; i < n; i++){
    long double na, nb, nt, np;
    na = (a + b) / 2.0;
    nb = sqrt(a * b);
    nt = t - p * (a - na) * (a - na);
    np = 2.0 * p;

    a = na;
    b = nb;
    t = nt;
    p = np;
  }

  return (a + b) * (a + b) / (4.0 * t);
}

long double fact(int n)
{
  long double ret = 1.0;
  for (int i = 1; i <= n; i++)
    ret *= (long double)i;
  return ret;
}

long double pow(long double x, int n)
{
  if (n == 0) return 1.0;
  long double a = pow(x, n / 2);
  if (n & 1){
    return a * a * x;
  } else {
    return a * a;
  }
}

long double sin(int x, int n = 1000)
{
  long double m_pi = pi();
  long double r = ((long double)x * m_pi) / 180.0;

  long double ret = 0.0;
  for (int i = 0; i < n; i++){
    long double p = pow(r, 2 * i + 1);
    long double f = fact(2 * i + 1);

    ret += ((long double)pow(r, 2 * i + 1) / (long double)fact(2 * i + 1)) * (i & 1 ? -1.0 : 1.0);
  }

  return ret;
}

long double cos(int x, int n = 1000)
{
  long double m_pi = pi();
  long double r = ((long double)x * m_pi) / 180.0;

  long double ret = 0.0;
  for (int i = 0; i< n; i++){
    ret += ((long double)pow(r, 2 * i) / (long double)fact(2 * i)) * (i & 1 ? -1.0 : 1.0);
  }

  return ret;
}

int main()
{
  long double x, y;
  int d, a;
  x = y = 0.0;

  int r = 90;
  while(true){
    int d, a;
    scanf("%d,%d", &d, &a);
    if (d == 0 && a == 0){
      break;
    }

    x += cos(r) * (double)d;
    y += sin(r) * (double)d;

    r -= a;
  }

  printf("%d\n%d\n", (int)x, (int)y);
}

Measured memory_bytes: 3136
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> vvl;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvec;
typedef vector<vector<bool>> vveb;
typedef vector<vector<string>> vves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pb push_back
#define pp pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
typedef long long int64;
//const int64 INF = 1LL << 58;
#define dame { puts("-1"); return 0;}
#define YES { cout << "YES" << endl; return 0; }
#define NO { cout << "NO" << endl; return 0; }
#define Yes { cout << "Yes" << endl; return 0; }
#define No { cout << "No" << endl; return 0; }
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 (a>b) { a=b; return 1; } return 0; }
int dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0, 0};

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

	int N; cin >> N;
	vector<l_l> v(N);
	rep(i,N) {
		cin >> v[i].fs >> v[i].sc;
	}
	ld ans = 0.0;
	vi v1; rep(i,N) v1.pb(i);
	do {
		rep(i,N-1) {

			ans += (ld) sqrt((v[v1[i]].fs - v[v1[i+1]].fs) * (v[v1[i]].fs - v[v1[i+1]].fs) + (v[v1[i]].sc - v[v1[i+1]].sc) * (v[v1[i]].sc - v[v1[i+1]].sc));
		}
	}while(next_permutation(v1.begin(),v1.end())); //(vectorは begin() end())でいい
	ll b = 1;
	rep(i,N) b *= (i+1);
	ans = (ld) ans / b;
	//cout << b << endl;
	cout << fixed << setprecision(10) << ans << endl;



    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstring>
using namespace std;
#define WMAX 12
#define HMAX 12

int area[14][14];

void solve(int w,int h)
{
    if(area[w][h]==1)
    {
        area[w][h] = 0;
        solve(w-1,h);
        solve(w,h-1);
        solve(w+1,h);
        solve(w,h+1);
    }
}

int main()
{
    while(1)
    {
        int ans = 0;
        char temp;
        memset(area,0,sizeof(area));
        for(int h=1;h<=12;h++)
        {
            for(int w=1;w<=12;w++)
            {
                cin >> temp;
                area[w][h] = (int)(temp-'0');
            }
        }
        if(cin.eof())break;

        for(int h=1;h<=12;h++)
        {
            for(int w=1;w<=12;w++)
            {
                if(area[w][h]==1)
                {
                    ans++;
                    solve(w,h);
                }
            }
        }
        
        cout << ans << endl;

    }
    
    return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
using namespace std;

typedef pair <int, int> pii;
typedef pair <pii, int> piii;

char a[810][810];
int ans;
queue <piii> q;
int dir[4][2] = {0, 1, 1, 0, -1, 0, 0, -1};
int n, m, k;

bool IN(int x, int y){return x >= 0 && x < n && y >= 0 && y < m;}

int main(){
	scanf("%d%d%d", &n, &m, &k);
	int x, y;
	for (int i = 0; i < n; i++){
		scanf("%s", a[i]);
		for (int j = 0; j < m; j++){
			if (a[i][j] == 'S') x = i, y = j;
		}
	}
	q.push(mp(mp(x, y), k)), a[x][y] = '#';
	int ans = 0x3f3f3f3f;
	while (!q.empty()){
		piii t = q.front(); q.pop();
		int x = t.fi.fi, y = t.fi.se, cnt = t.se;
		ans = min(ans, (min(min(x, y), min(n - x - 1, m - y - 1)) + k - 1) / k);
		if (t.se == 0) continue;
		for (int i = 0; i < 4; i++){
			int xx = x + dir[i][0], yy = y + dir[i][1];
			if (!IN(xx, yy) || a[xx][yy] != '.') continue;
			a[xx][yy] = '#';
			q.push(mp(mp(xx, yy), cnt - 1));
		}
	}
	printf("%d\n", ans + 1);
	return 0;
}


Measured memory_bytes: 896
#include <iostream>
#include <map>
#include <cstdio>
#include <cstring>
#include <cmath>

using namespace std;

typedef unsigned long long ull;

int main()
{
    ull a, b, x;
    
    cin >> a >> b >> x;
    
    ull base;
    ull sub = 0;
    
    base = b / x;
    if (a != 0)
    {
        sub = (a - 1) / x;
    }
    else
    {
        base++;
    }

#if 0
    printf("base=%lld, sub=%lld\n", base, sub);
#endif
    
    printf("%lld\n", base - sub);
    
    return 0;
}


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

int main()
{
    int n;
    cin >> n;
    int oddCnt = 0;
    int evenCnt = 0;
    int fourCnt = 0;
    for(int i = 0; i < n; ++i)
    {
        int t;
        cin >> t;
        if(t % 4 == 0)
        {
            ++fourCnt;
        }
        if(t % 2 == 0)
        {
            ++evenCnt;
        }
        else
        {
            ++oddCnt;
        }
    }
    
    int nhalf = n/2;
    if(n%2 != 0)
    {
        ++nhalf;
    }

    string str = "No";
    if( (n == 3 && fourCnt >= 1)
    ||  (oddCnt <= fourCnt)
    ||  (fourCnt >= n/2)
    ||  (evenCnt == n) )
    {
        str = "Yes";
    }

    cout << str << endl;


}

Measured memory_bytes: 256
a,b,c,k=map(int,input().split())
#print(a,b,c,k)
if(a<=k):
    if(a+b<=k):
        if(a+b+c<=k):
            print(a-c)
            exit()
        print(2*a+b-k)
        exit()
    print(a)
    exit()
print(k)


Measured memory_bytes: 9176
#include<bits/stdc++.h>
using namespace std;
char s[1010][1010];
int dp[1010][1010],n,m,mod=1000000007;
void solve(){
    cin>>n>>m;
    for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++)
            cin>>s[i][j];
    dp[1][1]=1;
    for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++){
            if(s[i-1][j]=='.')dp[i][j]=(dp[i][j]+dp[i-1][j])%mod;
            if(s[i][j-1]=='.')dp[i][j]=(dp[i][j]+dp[i][j-1])%mod;
        }
    cout<<dp[n][m];
}
main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);

    //freopen("FORM MAU.inp","r",stdin);
    //freopen("FORM MAU.out","w",stdout);

    //srand(time(0));

    //int t;cin>>t;while(t--)
    //cout << setprecision(2) <<fixed;
    solve();
}


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

using namespace std;

#define  input freopen("in.txt","r",stdin)
#define  output freopen("out.txt","w",stdout)

int main()
{
	//input;
	//output;

	int L;
	cin >> L;

	int N = 20;
	int tmp = 1<<20;

	while(tmp>L)
	{
		N--;
		tmp = 1<<N;
	}
	int M = (2*N) + __builtin_popcount(L)-1;
	printf("%d %d\n", N+1, M);
	for(int i = 0; i < N; i++)
	{
		printf("%d %d %d\n", i+1, i+2, (1<<i));
		printf("%d %d %d\n", i+1, i+2, 0);
	}
	int cost = 1<<N;
	for(int i = 0; i < N; i++)
	{ 
		if(L&(1<<i))
		{
			printf("%d %d %d\n", i+1, N+1, cost);
			cost+=(1<<i);
		}
	}
	return 0;
}

Measured memory_bytes: 256
/**************** Geometrical Library ****************/

#include<cmath>
#include<vector>
#include<algorithm>

#define	EPS	1e-9

enum {CCW=1,CW=-1,ON=0};

#define	mp	make_pair
#define	pb	push_back

using namespace std;

class Point{
public:
	double x,y;
	Point(){}
	Point(double xx,double yy):x(xx),y(yy){}
};

class Line:public vector<Point>{
public:
	Line(const Point &a,const Point &b){
		pb(a),pb(b);
	}
};

class Segment:public Line{
public:
	Segment(const Point &a,const Point &b):Line(a,b){}
};

class Polygon:public vector<Point>{};

class Circle{
public:
	Point c;
	double r;
	Circle(){}
	Circle(const Point &cc,double rr):c(cc),r(rr){}
};

Point &operator +=(Point &a,const Point &b){
	a.x+=b.x,a.y+=b.y;
	return a;
}

Point &operator -=(Point &a,const Point &b){
	a.x-=b.x,a.y-=b.y;
	return a;
}

Point &operator *=(Point &a,double c){
	a.x*=c,a.y*=c;
	return a;
}

Point &operator /=(Point &a,double c){
	a.x/=c,a.y/=c;
	return a;
}

Point operator +(const Point &a,const Point &b){
	Point c=a;
	return c+=b;
}

Point operator -(const Point &a,const Point &b){
	Point c=a;
	return c-=b;
}

Point operator *(double c,const Point &a){
	Point b=a;
	return b*=c;
}

Point operator /(const Point &a,double c){
	Point b=a;
	return b/=c;
}

bool operator <(const Point &a,const Point &b){
	return (a.x==b.x)?(a.y<b.y):(a.x<b.x);
}

bool operator >(const Point &a,const Point &b){
	return b<a;
}

double dot(const Point &a,const Point &b){
	return a.x*b.x+a.y*b.y;
}

double norm2(const Point &a){
	return dot(a,a);
}

/**************** Library END ****************/

#include<cstdio>

int main(){
	int n;	scanf("%d",&n);
	while(n--){
		Circle c1,c2;
		scanf("%lf%lf%lf%lf%lf%lf",&c1.c.x,&c1.c.y,&c1.r,&c2.c.x,&c2.c.y,&c2.r);
		double d=sqrt(norm2(c1.c-c2.c));
		if(c1.r+c2.r+EPS<d)			puts("0");
		else if(d+EPS<c1.r-c2.r)	puts("2");
		else if(d+EPS<c2.r-c1.r)	puts("-2");
		else						puts("1");
	}
	return 0;
}

Measured memory_bytes: 0
#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>;

const int MOD = 1000000007;
struct mint {
    ll x; // typedef long long ll;
    mint(ll x=0):x((x%MOD+MOD)%MOD){}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += MOD-a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator*=(const mint a) { (x *= a.x) %= MOD; return *this;}
    mint operator+(const mint a) const { return mint(*this) += a;}
    mint operator-(const mint a) const { return mint(*this) -= a;}
    mint operator*(const mint a) const { return mint(*this) *= a;}
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }

    // for prime MOD
    mint inv() const { return pow(MOD-2);}
    mint& operator/=(const mint a) { return *this *= a.inv();}
    mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
// combination MOD prime
struct combination {
    vector<mint> fact, ifact;
    combination(int n):fact(n+1),ifact(n+1) {
        assert(n < MOD);
        fact[0] = 1;
        for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
        ifact[n] = fact[n].inv();
        for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
    }
    mint operator()(int n, int k) {
        if (k < 0 || k > n) return 0;
        return fact[n]*ifact[k]*ifact[n-k];
    }
    mint p(int n, int k) {
        if (k < 0 || k > n) return 0;
        return fact[n]*ifact[n-k];
    }
} ; //comb(10000007);
// comb(5, 2) → 10, comb.p(5, 2) → 20
// comb.fact[4] → 24, 2のN乗 → mint(2).pow(N)

int main() {
    // dp, seine net algo
    string S;
    cin >> S;
    int M = 13;
    vector<mint> dp(M);
    fill(dp.begin(), dp.end(), 0);
    dp[0] = 1;
    for (char c : S) {
        vector<mint> prev(M);
        fill(prev.begin(), prev.end(), 0);
        swap(dp, prev);
        for (int i = 0; i < 10; i++) {
            if (c == i + '0' || c == '?'){
                for (int j = 0; j < M; j++) {
                    dp[(j*10 + i) % M] += prev[j];                    
                }
            }
        }
    }
    cout << dp[5] << '\n';
    return 0;
}

Measured memory_bytes: 3772
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
typedef long long ll;
const int INF = (int)1e9;

int a[1001];
int main() {
#ifdef WIN32
	//freopen("input.txt", "rt", stdin);
#endif

	int n, m; scanf("%d%d", &n, &m);
	int sum = 0;
	for (int i = 0; i < n; i++) scanf("%d", a + i), sum+=a[i];
	sort(a, a + n);
	int mth = a[n - m];
	printf("%s\n", 4 * m * mth >= sum ? "Yes" : "No");
	//pop >= sum * 1/4m 
	//4*m*pop >= sum


	return 0;
}

Measured memory_bytes: 256