akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <vector>
#include <functional> 
using namespace std;

#define int long long 
template <typename Monoid>
struct SegmentTree {
    using Function = function< Monoid(Monoid,Monoid) >;
    int size;
    vector<Monoid> segment;

    const Function f;
    const Monoid M_1; //Monoid の単位元?

    SegmentTree(int N, const Function f, const Monoid &M_1) : f(f), M_1(M_1) {
        size = 1;
        while (size < N) size <<= 1;
        segment.assign(2 * size , M_1);
    } 

    void set(int K, const Monoid &X){
        segment[K + size] = X;
    }

    void build(){
        for(int k = size - 1;k > 0;--k){
            segment[k] = f(segment[2 * k + 0],segment[2 * k + 1]);
        }
    }

    void update(int k, const Monoid &x){
        k += size;
        segment[k] = x;
        while(k >>= 1){
            segment[k] = f(segment[2 * k + 0],segment[2 * k + 1]);
        }
    }

    Monoid query(int a,int b){
        Monoid L = M_1, R = M_1;
        for(a += size, b += size; a < b; a >>= 1, b >>= 1){
            if(a & 1) L = f(L, segment[a++]);
            if(b & 1) R = f(segment[--b], R);
        }
        return f(L,R);
    }

    Monoid operator[](const int &k) const {
        return segment[k + size];
    }
};

signed main(){
    int N,Q;
    cin >> N >> Q;
    SegmentTree<int> segtree(N,[](int a,int b){ return min(a,b); }, ((1LL << 31) -1)); 
    for(int i=0;i<Q;++i){
        int com, x, y;
        cin >> com >> x >> y;
        if(com == 0) segtree.update(x,y);
        else cout << segtree.query(x, y + 1) << endl;
    }
}



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

int main() {
    string S;
    cin >> S;
    rep(i, 0, 7){
        string S2 = S.substr(0, i) + S.substr(S.size()-7+i, 7-i);
        if(S2 == "keyence"){
            cout << "YES" << endl;
            return 0;
        }
    }
     cout << "NO" << endl;
}

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

int const N = 100;
int x[N];

int main(){
	int n, v;
	scanf("%d%d", &n, &v);
	f(i, 0, n)scanf("%d", x + i);
	sort(x, x + n);
	int an = 0, i = 0;
	while (i < n){
		if (x[i] > v)break;
		v -= x[i];
		++an;
		++i;
	}
	if (v && an == n)--an;
	printf("%d\n", max(0, an));
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pb push_back
#define un unordered_map
#define us unordered_set
#define ll long long
#define l long 
using namespace std;
const int  mod= 1e9+7;
const int inf=1e9+3;
 int main()
 {
    
    l n,k;
     cin>>n>>k;
     vector<l>v(n);
      for(l i=0; i<n; i++)
      {
          cin>>v[i];
      }
      l dp[n];
       dp[0]=0;

        for(l i=1; i<n; i++)
        {
             l mini=inf;
              for(int j=1; j<=k; j++)
              {
                   if(i-j<0)
                    break;
                  
                  mini=min((dp[i-j]+abs(v[i]-v[i-j])),mini);
              }
              dp[i]=mini;
        }
        
        cout<<dp[n-1];
       return 0;
     
 }
  

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

#define ll long long
#define INF 99999999
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

template < typename T > std::string to_string( const T& n )
{
    std::ostringstream stm ;
    stm << n ;
    return stm.str() ;
}

int main()
{
    int N;
    cin >> N;
    vector<int> A(N);
    rep(i,N) cin >> A[i];

    double ans = 0;
    rep(i,N)
    {
        ans += (double) 1/A[i];
    }
    cout << 1/ans << endl;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define itn int
#define int long long
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
int x,a,b;
  cin>>x>>a>>b;
  if(abs(x-a)<abs(x-b)) cout<<"A\n";
  else cout<<"B\n";
}

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

int main(){
  int a,b,c;
  while(cin >> a >> b >> c){
    int sumtime=0;
    int sumhour=0;
    while(1){
      if(sumtime==0 && sumhour>0){cout << -1 << endl;break;}
      if((sumtime+a)>=c && sumtime<=c){
        cout << 60*sumhour + c << endl;break; 
      }
      sumtime += a;if(sumtime>=60){sumtime = sumtime%60; ++sumhour;}
      sumtime += b;if(sumtime>=60){sumtime = sumtime%60; ++sumhour;}
    }
  }
}



Measured memory_bytes: 3120
#include<bits/stdc++.h>
using namespace std;
int main(){
  long n,a,b,cnt(0),k(0);
  
  cin >> n >> a >> b;
  
  cnt += (n/(a+b))*a;
  if(n%(a+b)<a){
    cnt += n%(a+b);
  }else{
    cnt += a;
  }
  
  cout << cnt << endl;
}

Measured memory_bytes: 256
using System;
using System.Linq;//リストの使用
using System.Collections.Generic;
using System.Text;//テキストの高速出力に必要
class Program
{
	static void Main()
	{
		int n = int.Parse(Console.ReadLine());
		long[] nums = Array.ConvertAll(Console.ReadLine().Split(' '),long.Parse);
    long[] distances = new long[n-1];
    for(int i = 0; i < n-1; i++)
    {
      distances[i] = nums[i+1] -nums[i];
    }
		long answer = 0;
    long mod = 1000000007;
    long sum = 0;
    long fact = 1;
    for(int i = 0; i < n-1; i++)
    {
      fact *= i+1;
      fact %= mod;
    }

    for(int i = 0; i < n-1; i++)
    {
      sum += fact *DivideModReverse(i+1, mod);
      sum %= mod;

      long plus = sum*distances[i];
      plus %= mod;
      answer += sum*distances[i];
      answer %= mod;
    }

		Console.WriteLine(answer);
	}

  static long MathPow(long x, long a)//戻り値はx^a。O(loga)
  {
    long num = 2;
    long answer = 1;
    long check = a;
    long memo = x;
  
    while(check > 0)
    {
      if(check % num == num / 2)
      {
        check -= num / 2;
        answer *= memo;
      }
    memo *= memo;
    num *= 2;
    }
    return answer;
  }

  static long DivideMod(long x, long a, long p)//戻り値はx^a(mod p)。O(loga)
  {
    long num = 2;
    long answer = 1;
    long check = a;
    long memo = x%p;
    
    while(check > 0)
    {
      if(check % num == num / 2)
      {
        check -= num / 2;
        answer *= memo;
        answer %= p;
      }
    memo *= memo;
    memo %= p;
    num *= 2;
    }
    return answer;
  }

  static long DivideModReverse(long x, long p)//戻り値はx^-1(mod p), pは素数。O(logp)
  {
    long answer = DivideMod(x, p-2, p);
    return answer;
  }

  static long ModFactorial(long x, long p)//戻り値はx!(mod p)
  {
    long answer = 1;
    for(int i = 2; i <= x; i++)
    {
      answer *= i;
      answer %= p;
    }
    return answer;
  }

  static long DivideModFactorial(long x, long p)//戻り値はx!^-1(mod p), pは素数
  {
    long answer = 1;
    for(long i = x; i >= 2; i--)
    {
      answer *= DivideModReverse(i, p);
      answer %= p;
    }
    return answer;
  }

  static long Comb(long a, long b, long p)//戻り値は組み合わせC(a,b)のmod p
  {
    long answer = 1;
    for(long i = a; i > a-b; i--)
    {
      answer *= i;
      answer %= p;
    }
    answer *= DivideModFactorial(b, p);
    answer %= p;
    return answer;
  }

  
}

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

using namespace std;

using ll = long long;

ll Solve() {
    int n;
    cin >> n;

    vector<vector<ll>> a(n, vector<ll>(n));
    for (int i = 0; i < n; ++i)
        for (int j = 0; j < n; ++j)
            cin >> a[i][j];

    for (int k = 0; k < n; ++k)
        for (int i = 0; i < n; ++i)
            for (int j = 0; j < n; ++j)
                if (a[i][k] + a[k][j] < a[i][j]) return -1;

    struct Edge {
        int src, dst;
        ll w;
        Edge() {};
        Edge(int _s, int _d, ll _w) : src(_s), dst(_d), w(_w) {}
        bool operator<(const Edge &r) { return w > r.w; }
    };

    vector<Edge> edge;
    for (int i = 0; i < n; ++i)
        for (int j = i + 1; j < n; ++j)
            if (a[i][j] != 0) edge.emplace_back(Edge(i, j, a[i][j]));

    sort(edge.begin(), edge.end());
    for (auto e : edge) {
        if (a[e.src][e.dst] <= 0) continue;
        bool is_delete = false;
        for (int k = 0; k < n; ++k) {
            if (e.src != k && e.dst != k && a[e.src][k] != -1
                && a[k][e.dst] != -1 && a[e.src][k] + a[k][e.dst] == a[e.src][e.dst]) {
                is_delete = true;
                break;
            }
        }
        if (is_delete) {
            a[e.src][e.dst] = a[e.dst][e.src] = -1;
        }
    }

    ll len = 0;
    for (int i = 0; i < n; ++i)
        for (int j = i + 1; j < n; ++j) {
            if (a[i][j] != -1) len += a[i][j];
        }

    return len;
}

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

    cout << Solve() << endl;

    return 0;
}


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

const int INF = 1001001001;
const int mod = 1000000007;

ll pow(ll base, ll order) {
	ll ans = 1;
	rep(i,order - 1) ans *= base;
	return ans;
}

int gcd(int a, int b) {
	if (a < b) {
		int c = a;
		a = b;
		b = c;
	}
	if (b == 0) return a;
	return gcd (b, a % b);
}

ll sum(ll x) { // sum of subsequent numbers from 0 to x
	return x*(x + 1)/2;
}

int main() {
	int n, x;
	cin >> n >> x;
	vector<int> l(n);
	rep(i, n) cin >> l.at(i);

	int d = 0, ans = 1;
	rep(i,n) {
		d += l.at(i);
		if (d > x) break;
		ans++;
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
void swap(int *a, int *b){
    int tmp;
    tmp = *a;
    *a = *b;
    *b = tmp;
}

int main(void){
    int a, b, c;
    cin >> a >> b >> c;
    if ( a > b ){
        swap(&a, &b);
    }
    if ( b > c ) {
        swap(&b, &c);
    }
    if ( a > b ){
        swap(&a, &b);
    }
    cout << a << " " << b << " "  << c << endl;
    return 0;
}


Measured memory_bytes: 3076
#include <bits/stdc++.h>
#include <unordered_map>
typedef long long ll;
#define rep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define print2(x,y) cout << (x) << " " << (y) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " \n"[i == n-1];}
#define printp(x,n) for(ll i = 0; i < n; i++){ cout << "(" << x[i].first << ", " << x[i].second << ") "; } cout << endl;
#define INF (1e18)
using namespace std;
const ll MOD = 1e9 + 7;
typedef pair<ll, ll> lpair;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N,M;
    cin >> N >> M;
    ll K[35];
    ll A[35][35];
    rep(i,0,N){
        cin >> K[i];
        rep(j,0,K[i]){
            cin >> A[i][j];
        }
    }
    ll m[35] = {};
    rep(i,0,N){
        rep(j,0,K[i]){
            m[A[i][j]]++;
        }
    }
    ll ans = 0;
    rep(i,1,M+1){
        if(m[i] == N) ans++;
    }
    print(ans);

}


Measured memory_bytes: 384
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>

using namespace std;

using ll = long long;
using ull = unsigned long long;


int main()
{
    int a[] = { 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51 };
    int k;
    cin >> k;
    k--;
    cout << a[k] << endl;
    return 0;
}


Measured memory_bytes: 256
/*
	##############################
	## Author: Pratyush Gaurav ###
	## College: NIT ROURKELA #####
	##############################
*/
#include <bits/stdc++.h>

using namespace std;

typedef long long/*--------------------*/lli;
typedef long double/*------------------*/ld;
typedef pair<lli, lli >/*--------------*/plli;
typedef vector<lli>/*------------------*/vlli;
typedef vector<plli >/*----------------*/vplli;

#define rep(i,a)/*---------------------*/for(i = 0 ; i < a ; i++)
#define repr(i,a)/*--------------------*/for(i = a ; i >= 0 ; i--)
#define REP(i,a,b)/*-------------------*/for(i = a ; i <= b ; i++)
#define REPR(i,a,b)/*------------------*/for(i = a ; i >= b ; i--)

#define scan(N)/*----------------------*/scanf("%lld",&N)
#define print(N)/*---------------------*/printf("%lld",N)
#define scan2(N1,N2)/*-----------------*/scanf("%lld %lld",&N1,&N2)
#define print2(N1,N2)/*----------------*/printf("%lld %lld",N1,N2)
#define scan3(N1,N2,N3)/*--------------*/scanf("%lld %lld %lld",&N1,&N2,&N3)
#define print3(N1,N2,N3)/*-------------*/printf("%lld %lld %lld",N1,N2,N3)

#define mem(a,b)/*---------------------*/memset(a,b,sizeof(a))
#define opt/*--------------------------*/ios_base::sync_with_stdio(false);cin.tie(NULL);
#define gcd(a, b)/*--------------------*/__gcd(a, b)
#define lcm(a, b)/*--------------------*/((a)*((b)/gcd(a,b)))
#define sqr(x)/*-----------------------*/(x)*(x)
#define all(a)/*-----------------------*/a.begin(),a.end()
#define makepair/*---------------------*/make_pair

#define endl/*-------------------------*/'\n'
#define inf/*--------------------------*/(lli)2000000000000
#define MOD/*--------------------------*/(lli)1000000007
#define MAXN/*-------------------------*/100005

template<class T> bool is_prime(T n)
{
	if((n%2 == 0 and n > 2) or n < 2 )
		return false;
	for(T i = 3; i*i <= n ; i += 2)
	{
		if( n % i == 0)
			return false;
	}
	return true;
}
lli power(lli a,lli b)
{
    lli value;
    if(!b)
    	return 1;
    else if(b%2==0)
    {
        value = power(a,b/2)%MOD;
        return (value * value)%MOD;
    }
    else
    {
        value = power(a,b/2)%MOD;
        return ((a*value)%MOD*(value))%MOD;
    }
}
lli getsum(lli x)
{
    lli res = 0;
    while(x > 0)
    {
        res += x%10;
        x /= 10;
    }
    return res;
}
int main()
{
	opt;
	lli x,y;
	cin >> x >> y;
	lli n = x,ans = 0;
	while(n >= x and n <= y)
    {
        n *= 2;
        ans++;
    }
    cout << ans << endl;
	return 0;
}










Measured memory_bytes: 256
#include <cstdio>
using namespace std;
#define INF (1<<29)

int N, M, R;
int d[201][201];
int r[9];
int A, B, C;
int res;
bool used[9];

void dfs(int c, int las, int dist) {
    if (c == R + 1) {
        if (res > dist) {
            res = dist;
            return;
        }
    }
    for (int i = 1; i <= R; i++) {
        if (!used[i]) {
            used[i] = true;
            if (las == -1) dfs(c + 1, i, 0);
            else dfs(c + 1, i,  dist + d[r[las]][r[i]]);
            used[i] = false;
        }
    }
}

int main() {
    scanf("%d%d%d", &N, &M, &R);
    for (int i = 1; i <= N; i++)
        for (int j = 1; j <= N; j++)
            if (i != j)
                d[i][j] = INF;
    
    for (int i = 1; i <= R; i++)
        scanf("%d", &r[i]);

    for (int i = 1; i <= M; i++) {
        scanf("%d%d%d", &A, &B, &C);
        if (d[A][B] > C)
            d[A][B] = d[B][A] = C;
    }

    for (int k = 1; k <= N; k++)
        for (int i = 1; i <= N; i++)
            for (int j = 1; j <= N; j++)
                if (d[i][j] > d[i][k] + d[k][j])
                    d[i][j] = d[i][k] + d[k][j];

    res = INF;
    dfs(1, -1, 0);
    printf("%d\n", res);
}

Measured memory_bytes: 256
A, B, C, K = map(int, input().split())

if K <= A:
    print(K)
elif K <= A + B:
    print(A)
elif K <= A + B + C:
    ans = A - (K - A - B)
    print(str(ans))
else:
    print(0)



# # https://atcoder.jp/contests/abs/tasks/abc081_b

# N = int(input())
# A = map(int, input().split())

# min_count = 1000000000000

# for a in A:
#     pow_count = 0

#     while a % 2 == 0:
#         pow_count += 1
#         a /= 2
#     # print(a, pow_count)

#     if pow_count < min_count:
#         min_count = pow_count

# print(min_count)


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

using namespace std;
using ll = long long;

template<class T> using V = vector<T>;
template<class T> using VV = V<V<T>>;

#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_V(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl;
#define DEBUG_M(v) cerr<<#v<<endl;for(int i=0;i<v.size();i++){for(int j=0;j<v[i].size();j++) {cerr<<v[i][j]<<" ";}cerr<<endl;}

int main() {
    int n, l;
    cin >> n >> l;
    V<int> p(n);
    for (int i = l; i < l + n; i++) {
        p[i - l] = i;
    }
    int sum = accumulate(p.begin(), p.end(), 0);
    int mn = 1e9, ans = 1e9;
    for (int i = 0; i < n; ++i) {
        if (mn > abs(p[i])) {
            ans = sum-p[i];
            mn = abs(p[i]);
        }
    }
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 256
def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 #出力の制限
N = 10**5
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

S = int(input())
ans = 0
for k in range(1,S//3+1):
    ans += cmb(S-2*k-1,k-1,mod)
    ans %= mod
    #print(k,ans)
    

print(ans)

Measured memory_bytes: 87188
#include<iostream>
#include<iomanip>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<cstring>
#include<sstream>
using namespace std;
 
#define P(p) cout<<(p)<<endl
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.begin(), v.end(),greater<int>());
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return
#define C(i) cin>>i
#define C2(i,j) cin>>i>>j
#define C3(i,j,k) cin>>i>>j>>k
#define C4(i,j,k,m) cin>>i>>j>>k>>m
////////////////////////////////////////////////////////////

int main(){
	int n;
	cin >> n;
	vector<long> a(n*3);
	rep(i,0,3*n)
		cin >> a[i];
	vsort(a);
	
	int f = 0;
	int b = a.size() - 1;
	long long ans = 0;
	rep(i,0,n){
		f++;
		b--;
		ans += a[b];
		b--;
	}
	P(ans);
	ret 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define ll long long
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define f(i, a, b) for(ll i=a; i<b; i++)
#define fr(i,a,b) for(ll i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define LB lower_bound
#define UB upper_bound
#define endl "\n"
#define PI 3.141592653589793
using namespace std;

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

ll maxSubArraySum(ll a[], ll size) 
{ 
    ll max_so_far = INT_MIN, max_ending_here = 0; 
  
    for (ll i = 0; i < size; i++) 
    { 
        max_ending_here = max_ending_here + a[i]; 
        if (max_so_far < max_ending_here) 
            max_so_far = max_ending_here; 
  
        if (max_ending_here < 0) 
            max_ending_here = 0; 
    } 
    return max_so_far; 
} 

ll findSubarraySum(ll arr[], ll n, ll sum = 0) 
{
    unordered_map<ll, ll> prevSum;
    ll res = 0;
    ll currsum = 0;
    for (ll i = 0; i < n; i++)
    {
        currsum += arr[i];
        if (currsum == sum) res++;
        if (prevSum.find(currsum - sum) != prevSum.end()) res += (prevSum[currsum - sum]);
        prevSum[currsum]++;
    }
    return res; 
} 
ll gcd(ll a, ll b) 
{ 
    if (a == 0) 
        return b; 
    return gcd(b % a, a); 
} 
  
ll powmp(ll x, ll y, ll p) 
{ 
    ll res = 1;     x = x % p;   
    while (y > 0) 
    {  
        if (y & 1)  res = (res*x) % p; 
        y = y>>1; 
        x = (x*x) % p;   
    } 
    return res; 
} 

int main()
{
    FAST
    ll h1,m1,h2,m2,k;cin>>h1>>m1>>h2>>m2>>k;
    ll s=60*h1+m1;
    ll e=60*h2+m2;
    cout<<e-k-s<<endl;
}


Measured memory_bytes: 3656
import sys
import math
import string
import fractions
import random
from operator import itemgetter
import itertools
from collections import deque
import copy
import heapq
import bisect

MOD = 10 ** 9 + 7
INF = float('inf')
input = lambda: sys.stdin.readline().strip()

sys.setrecursionlimit(10 ** 8)


def search(i, j):
    global ans
    if c[i][j] == 1:
        c[i][j] = -1
        search(i, j+1)
        search(i+1, j-1)
        search(i+1, j)
        search(i+1, j+1)
        search(i, j-1)
        search(i-1, j)
        search(i-1, j+1)
        search(i-1, j-1)


while True:
    w, h = map(int, input().split())
    if w == h == 0:
        break
    c = [[] for _ in range(h + 2)]
    c[0] = [0] * (w + 2)
    c[-1] = [0] * (w + 2)
    for i in range(h):
        c[i + 1] = [0] + list(map(int, input().split())) + [0]
    ans = 0
    for i in range(1, h + 1):
        for j in range(1, w + 1):
            if c[i][j] == 1:
                ans += 1
                search(i, j)
    print(ans)



Measured memory_bytes: 11116
#include<iostream>
#include<string>

using namespace std;

int main(){
    int D;
    std::string ans;
    cin >> D;
    if(D == 25) ans = "Christmas";
    else if(D == 24) ans = "Christmas Eve";
    else if(D == 23) ans = "Christmas Eve Eve";
    else if(D == 22) ans = "Christmas Eve Eve Eve";
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int K;
  cin >> K;
  int A, B;
  cin >> A >> B;
  if (B - A + 1 >= K) {
    cout << "OK" << endl;
  }
  else {
    for (int i = A; i <= B; i++) {
      if (i % K == 0) {
        cout << "OK" << endl;
        break;
      }
      if (i == B) {
        cout << "NG" << endl;
      }
    }
  }
}

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

int main() {
  int n;
  cin>>n;
  int d[n];
  for (int i=0; i<n; i++) cin>>d[i];
  int ans = 0;
  for (int i=0; i<n; i++) {
    for (int j=i+1; j<n; j++) {
      ans += d[i] * d[j];
    }
  }
  cout<<ans<<endl;

}

Measured memory_bytes: 256
import itertools

n = int(input())
a = list()
for i in range(1,n+1):
    a.append(i)
b = list(input().split())
c = list(input().split())
for i in range(0,n):
    b[i]=int(b[i])
    c[i]=int(c[i])
cnt = 1
for i in itertools.permutations(a):
    #print(i)
    if(tuple(b)==i):
        cnta = cnt
        #print('p is '+str(cnta))
    if(tuple(c)==i):
        cntb = cnt
        #print('q is '+str(cntb))
    cnt +=1
print(abs(cnta-cntb))


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

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

    static class DBannedK {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            int[] a = new int[n];
            HashMap<Integer, Integer> map = new HashMap<>();
            for (int i = 0; i < n; i++) {
                a[i] = in.nextInt();
                if (map.containsKey(a[i])) {
                    map.put(a[i], map.get(a[i]) + 1);
                } else {
                    map.put(a[i], 1);
                }
            }
            long sum = 0;
            for (int e : map.values()) {
                sum += (long) e * (e - 1) / 2;
            }
            long[] ans = new long[n];
            for (int i = 0; i < n; i++) {
                int v = map.get(a[i]);
                out.println(sum - v + 1);
            }
        }

    }
}



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

const int MOD = 998244353;

ll pw(ll n, ll k) {
	ll r = 1; for(; k; k >>= 1) {
		if(k & 1) r = r * n % MOD;
		n = n * n % MOD;
	}
	return r;
}
ll inv(ll n) { return pw(n, MOD-2); }

ll F[5000], RF[5000], TP[5000];

int N, K;

ll C(int a, int b) {
	if(a < 0 || b < 0 || a < b) return 0;
	return F[a] * RF[b] % MOD * RF[a-b] % MOD;
}
ll D(int a, int b) { return (a <= 0 || b < 0) ? 0 : C(a+b-1, b); }

int f(int a, bool flag) {
	ll ret = 0;
	for(int k = 0; k <= a; k++) {
		ll t = TP[k] * C(a, k) % MOD;
		ret += t * D(K-a*2+k-flag, N-k);
		if(flag) ret += t * D(K-a*2+k-1, N-k-1);
		ret %= MOD;
	}
	return ret;
}

int main() {
	F[0] = TP[0] = 1;
	for(int i = 1; i < 5000; i++) {
		F[i] = F[i-1] * i % MOD;
		TP[i] = TP[i-1] * 2 % MOD;
	}
	RF[4999] = inv(F[4999]);
	for(int i = 4999; i; i--) RF[i-1] = RF[i] * i % MOD;

	cin >> K >> N;

	for(int t = 2; t <= K*2; t++) {
		int a = 0;
		for(int i = 1; i <= K; i++)
			if(i < t-i && t-i <= K) a++;
		printf("%d\n", f(a, !(t&1)));
	}
	return 0;
}

Measured memory_bytes: 892
<?php

$score  = array_fill(0, 2, 0);


fscanf(STDIN, '%d', $n);

for ($i = 0; $i < $n; $i++) {
    $card = explode(' ', trim(fgets(STDIN)));

    foreach (getPoint($card) as $player => $point) {
        $score[$player] += $point;
    }
}

echo implode(' ', $score), PHP_EOL;


function getPoint($card)
{
    if (count(array_unique($card)) == 1) {
        return array(1, 1);
    }

    return array(array_search(max($card), $card) => 3);
}

Measured memory_bytes: 6636
import java.util.Scanner;

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

        String s = sc.nextLine();
        int ans = 0;
        String[] str = new String[4];
        str = s.split("");
        for (int i = 0; i < 4; i++) {
            if (str[i].equals("+"))
                ans++;
            else
                ans--;
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 21204
//09
#include<iostream>
#include<algorithm>

using namespace std;

int n,s,m[20];
bool u[(1<<13)+1][20];
bool mem[(1<<13)+1][20];

bool dfs(int s,int p){
  if(s==0){
    return true;
  }else if(u[s][p]){
    return mem[s][p];
  }else{
    u[s][p]=true;
    for(int i=1;i<=m[p];i++){
      if(s>=i){
	if(!dfs(s-i,(p+1)%(2*n))){
	  return mem[s][p]=true;
	}
      }
    }
    return mem[s][p]=false;
  }
}

int main(){
  while(cin>>n>>s,n){
    for(int i=0;i<2*n;i++){
      cin>>m[i];
    }
    fill(u[0],u[s+1],false);
    cout<<dfs(s,0)<<endl;
  }
  return 0;
}

Measured memory_bytes: 1640
N,M=map(int,input().split())
num=0
value=0
i=1
T=1
odds=(1/2)**M
time=(N-M)*100+1900*M
while 1:

    value+=time*i*(T*odds)
    T*=(1-odds)
    if num==value:
        break
    num=value
    i+=1
print(round(value))


Measured memory_bytes: 38768
#include<iostream>
#include<algorithm>
#include<vector>
#include<functional>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<cstdio>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;

int main() {
  int H, W;
  cin >> H >> W;
  vector<vector<int>> s(H * W, vector<int>(H * W, 0)), dp(H * W,vector<int>(H * W, 1001001001));
  int black = 0;
  for(int h = 0; h < H; h++) {
    string tmp;
    cin >> tmp;
    for(int w = 0; w < W; w++){
      if(tmp[w] == '.'){
        s[h][w] = 1;
      }else{
        black++;
      }
    }
  }
  if(s[0][0] == 0){
    cout << -1 << endl;
    return 0;
  }

  vector<vector<int>> dist(H, vector<int>(W, -1));
  queue<pair<int, int>> que;
  dist[0][0] = 0;
  que.push({0,0});
  int dh[4] = {1, 0, -1, 0};
  int dw[4] = {0, 1, 0, -1};
  while(!que.empty()) {
    int qh = que.front().first;
    int qw = que.front().second;
    que.pop();
    for(int i = 0; i < 4; i++){
      int nh = qh + dh[i];
      int nw = qw + dw[i];
      if(nh < 0 || nh >= H || nw < 0 || nw >= W){
        continue;
      }
      if(dist[nh][nw] != -1){
        continue;
      }
      if(s[nh][nw] == 0){
        continue;
      }
      que.push({nh, nw});
      dist[nh][nw] = dist[qh][qw] + 1;
    }
  }
  /*
  for(int i = 0; i < H * W; i++){
    cout << i << ":" << dist[i] << " ";
  }
  cout << endl;
  cout << dist[H * W - 1] << endl;
  */
  if(dist[H - 1][W - 1] == -1){
    cout << -1 << endl;
    return 0;
  }
  cout << H * W - (dist[H - 1][W - 1] + 1) - black << endl;
  return 0;
}

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

using ll = long long;

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

string str;

int a[26];

int main(){
	cin.tie(0);

    while(getline(cin, str)) {
        
        rep(i, str.size()) {
            if('a'<=str.at(i) && str.at(i)<='z')a[str.at(i)-'a']++;
            else if('A'<=str.at(i) && str.at(i)<='Z')a[str.at(i)-'A']++;
        }
    }
    
    rep(i, 26) {
        cout<<(char)(i+'a')<<" : "<<a[i]<<endl;
    }

	return 0;
}



Measured memory_bytes: 3188
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<queue>
#include<string>
#include<cstring>
#include<algorithm>
#include<set>
#include<map>
#include<iomanip>

#define REP(i,n) for(int i=0;i<(n);i++)
#define EPS (1e-7)
#define INF (2e9)
// cout << setprecision(10)

using namespace std;
typedef long long int ll;
const ll MOD = 1000000007;

ll A, B, V, W;
ll T;
int main(void){
    cin >> A >> V;
    cin >> B >> W;
    cin >> T;
    if (A < B){
        if (A + V*T >= B + T*W) cout << "YES" << endl;
        else cout << "NO" << endl;
    }else{
        if (A - V*T <= B - W*T) cout << "YES" << endl;
        else cout << "NO" << endl;
    }
    return 0;
}



Measured memory_bytes: 3672
import math

a=input()
a=a.split()
l1=int(a[0])
l2=int(a[1])
h=int(a[2])
m=int(a[3])

de1=math.radians(360*h/12+0.5*m)
de2=math.radians(360*m/60)

#print(de1,de2)

x1=l1*math.cos(de1)
y1=l1*math.sin(de1)

#print(x1,y1)

x2=l2*math.cos(de2)
y2=l2*math.sin(de2)

#print(x2,y2)

l_2=pow(x1-x2,2)+pow(y1-y2,2)
l=pow(l_2,0.5)

print(l)

Measured memory_bytes: 9476
# include <bits/stdc++.h>
# define ll int64_t
# define rep(i,n) for(ll i=0;i<n;i++)
# define rrep(i,n) for(ll i=1;i<=n;i++)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define mod 1000000007

using namespace std;

bool compare_by_b(pair<string,ll> a,pair<string,ll> b){
    if(a.second != b.second) return a.second<b.second;
    else return a.first<b.first;
}

bool my_compare(pair<string,ll> a,pair<string,ll> b){
    
    if(a.first != b.first) return a.first<b.first;
    if(a.second != b.second) return a.second>b.second;
    else return true;
}

ll factorial(ll n){
    ll x=1;
    rrep(i,n) x *= i;
    return x;
}

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

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

int main(){
    ll n,maxi=-100000;
    cin>>n;
    ll d[n+10];
    rep(i,n+10) d[i]=0;
    vector<ll> a(n);
    rep(i,n){
        cin>>a[i];
        d[a[i]]++;
        if(maxi<a[i]) maxi=a[i];
    }
    ll sum=0;
    rrep(j,maxi) if(d[j]>=1) sum+=d[j]*(d[j]-1)/2;
    rep(i,n){
        ll e=sum;
        e -= d[a[i]]*(d[a[i]]-1)/2;
        e += (d[a[i]]-2)*(d[a[i]]-1)/2;
        cout<<e<<endl;
        e=sum;
    }
    return 0;
}


Measured memory_bytes: 5760
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) {rep(_,v.size())printf("%d ",v[_]);cout<<"\n";}
#define show2d(v) {rep(__,v.size())show1d(v[__]);}
using namespace std;
//kaewasuretyuui
typedef long long ll;
#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<int,int,int,int> tp;
typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
//template<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};//RDLU
#define yes puts("YES")
#define no puts("NO")


signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int n,m;
	cin>>n>>m;
	vi a(n),b(m);
	rep(i,n)cin>>a[i];
	rep(i,m)cin>>b[i];
	sort(all(a));
	sort(all(b));
	int it1=n-1,it2=m-1;
	int out=1;
	int MOD=1000000007;
	for(int i=n*m;i>0;i--){
		if(it1>=0&&it2>=0&&a[it1]==i&&b[it2]==i){
			it1--;it2--;
		}else if(it1>=0&&a[it1]==i){
			if(m-it2-1<0)out=0;
			(out*=m-it2-1)%=MOD;
			it1--;
		}else if(it2>=0&&b[it2]==i){
			if(n-it1-1<0)out=0;
			(out*=n-it1-1)%=MOD;
			it2--;
		}else{
			if(n-it1-1<0||m-it2-1<0||(n-it1-1)*(m-it2-1)-n*m+i<0)out=0;
			(out*=(n-it1-1)*(m-it2-1)-n*m+i)%=MOD;
		}
	}
	cout<<out<<endl;
}









Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)

typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, double> Pid;
typedef pair<double, int> Pdi;
const double PI = 3.1415926535897932;   // acos(-1)
const double EPS = 1e-15;
const int INF = 1001001001;
const int mod = 1e+9 + 7;

int n;  // 入力

// dp[i][j][k] := 皿に乗っている寿司の個数が (1,2,3) の皿の個数が (i,j,k) 枚のとき
// 全て食べきるまでの操作回数の期待値
vector<vector<vector<double>>> dp(305, vector<vector<double>>(305, vector<double>(305, -1)));

// メモ化再帰
double memo_rec(int i, int j, int k){
    if(dp[i][j][k] != -1)   return dp[i][j][k];
    if(i == 0 && j == 0 & k == 0)   return dp[0][0][0] = 0;
    
    double res = 0;
    res += n;
    if(i > 0)   res += memo_rec(i-1, j, k) * i;
    if(j > 0)   res += memo_rec(i+1, j-1, k) * j;
    if(k > 0)   res += memo_rec(i, j+1, k-1) * k;
    res *= 1.0 / (i + j + k);

    return dp[i][j][k] = res;
}

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

    cin >> n;
    int cnt1 = 0, cnt2 = 0, cnt3 = 0;
    for(int i = 0; i < n; ++i){
        int a;
        cin >> a;
        if(a == 1)  ++cnt1;
        else if(a == 2) ++cnt2;
        else    ++cnt3;
    }

    cout << fixed << setprecision(10);
    cout << memo_rec(cnt1, cnt2, cnt3) << endl;
}

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

const int N = 1e6 + 5;

int n , a[1005][1005] , dp[N];
bool on_stack[N];
vector < int > adj[N];

int Hash(int i , int j)
{
    if(i > j) swap(i,j);
    return i*n + j;
}

int dfs(int i)
{
    if(on_stack[i])
    {
        cout << "-1\n";
        exit(0);
    }
    if(dp[i] + 1) return dp[i];
    dp[i] = 0;
    on_stack[i] = 1;

    for(auto x : adj[i])
        dp[i] = max(dp[i] , dfs(x));

    on_stack[i] = 0;
    return dp[i] = dp[i]+1;
}
int main()
{
    ios::sync_with_stdio(false);    cin.tie(NULL);  cout.tie(NULL);
    cin >> n;
    for(int i = 0 ; i < n ; i++)
        for(int j = 0 ; j+1 < n ; j++)
            {
                cin >> a[i][j]; a[i][j]--;
                if(j)
                    adj[Hash(i,a[i][j])].push_back(Hash(i,a[i][j-1]));
            }

    memset(dp,-1,sizeof(dp));
    int ans = 0;
    for(int i = 0 ; i < n*n ; i++)
        ans = max( ans , dfs(i));

    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 48128
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
#[allow(unused_imports)]
use std::io::{stdin, stdout, BufWriter, Read, StdoutLock, Write};
#[allow(unused_imports)]
use std::iter::FromIterator;
#[allow(unused_imports)]
use std::str::FromStr;

// 755.rs --- 755
// author: Seong Yong-ju <sei40kr@gmail.com>

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_macros)]
macro_rules! debug {
  ($($a:expr),*) => {
    println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
  }
}

#[allow(dead_code)]
fn with_bufwriter<F: FnOnce(BufWriter<StdoutLock>) -> ()>(f: F) {
    let out = stdout();
    let writer = BufWriter::new(out.lock());
    f(writer);
}

fn dfs(n: i64, cs: String) -> i64 {
    if n < i64::from_str(&cs).unwrap() {
        return 0;
    }

    return (if ['7', '5', '3']
        .into_iter()
        .all(|c| cs.chars().collect::<Vec<_>>().contains(c))
    {
        1
    } else {
        0
    }) + ['7', '5', '3']
        .into_iter()
        .map(|c| dfs(n, format!("{}{}", cs, c.to_string())))
        .sum::<i64>();
}

fn main() {
    input! {
      n: i64
    }

    with_bufwriter(|mut out| {
        writeln!(out, "{}", dfs(n, String::from("0")));
    });
}


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

#define REP(i,n) for(int i=0; i < (n); ++i)
#define REPR(i,n) for(int i=(n); i >=0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)

typedef long long ll;
#define INF 1e9

int main(){
  int A, B, C, D, E, F, sugar=0 , water;
  cin >> A >> B >> C >> D >> E >> F;
  A*=100;
  B*=100;
  water = A;
  for(int i = 0; i * A <=F; ++i){
    for(int j = 0; i*A+j*B <= F; ++j){
      for(int k = 0; i*A+j*B+k*C <= F; ++k){
        for(int h = 0; i*A+j*B+k*C+h*D <= F; ++h){
          int s = k*C + h*D;
          int w = i*A + j*B;
          if((i || j || k || h )&& (s*(100+E) <= E*(s+w))){
            if(sugar*(s+w) < s*(sugar+water)){
              sugar = s;
              water = w;
            }
          }
        }
      }
    }
  }
  cout << water+sugar << " " << sugar << endl;
  return 0;
}

Measured memory_bytes: 256
#include<set>
#include<map>
#include<deque>
#include<queue>
#include<stack>
#include<cmath>
#include<ctime>
#include<bitset>
#include<string>
#include<vector>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<complex>
#include<iostream>
#include<algorithm>
#define ll long long
using namespace std;

const int maxn = 110000;

int n;
int a[maxn],b[maxn],c[maxn];

ll s1[maxn],s2[maxn];

int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]); sort(a+1,a+n+1);
	for(int i=1;i<=n;i++) scanf("%d",&b[i]); sort(b+1,b+n+1);
	for(int i=1;i<=n;i++) scanf("%d",&c[i]); sort(c+1,c+n+1);
	
	int now=0;
	for(int i=1;i<=n;i++)
	{
		while(b[i]>a[now+1]&&now<n) now++;
		s1[i]=now;
	}
	for(int i=2;i<=n;i++) s1[i]+=s1[i-1];
	now=0;
	for(int i=1;i<=n;i++)
	{
		while(c[i]>b[now+1]&&now<n) now++;
		s2[i]=s1[now];
	}
	ll re=0;
	for(int i=1;i<=n;i++) re+=s2[i];
	printf("%lld\n",re);
	
	return 0;
}


Measured memory_bytes: 2944
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <bitset>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>

using namespace std;

#define MAX_N 50000
#define MAX_M 20
#define INF INT_MAX / 2

int C[MAX_M];
int T[MAX_N + 1];

void printv(int v[], int len) {
	for (int i = 0; i < len; i++)
		cout << v[i] << " ";
	cout << endl;
}

int getTheNumberOfCoin(int n, int m) {
	fill_n(T, n + 1, INF);
	T[0] = 0;

	for (int i = 0; i < m; i++) {
		for (int j = C[i]; j <= n; j++) {
			T[j] = min(T[j], T[j - C[i]] + 1);
		}
//		printv(T, n + 1);
	}

	return T[n];
}

int main() {
	int n, m;
	cin >> n >> m;
	for (int i = 0; i < m; i++)
		cin >> C[i];
	cout << getTheNumberOfCoin(n, m) << endl;
	return 0;
}

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

using namespace std;

int main() {
	long long int n,c;
	cin >> n >> c;
	long long int x[n],v[n];
	for(int i = 0; i < n; i++) {
		cin >> x[i] >> v[i];
	}

	// cw
	long long int sum_1[n];
	// ccw
	long long int sum_2[n];

	for(int i = 0; i < n; i++) {
		if(i == 0) {
			sum_1[i] = v[i] - x[i];
		} else {
			sum_1[i] = sum_1[i - 1] + v[i] - (x[i] - x[i - 1]);
		}
	}

	for(int i = n - 1; i >= 0; i--) {
		if(i == n-1) {
			sum_2[i] = v[i] - (c - x[i]);
		} else {
			sum_2[i] = sum_2[i + 1] + v[i] - (x[i+1] - x[i]);
		}
	}

	long long int MAX_CW_originTOI[n];
	long long int MAX_CCW_originTOI[n];
	for(int i = 0; i < n; i++) {
		MAX_CW_originTOI[i] = 0;
		MAX_CCW_originTOI[i] = 0;
	}

	for(int i = 0; i < n; i++) {
		if(i == 0) MAX_CW_originTOI[i] = max(sum_1[i],0LL);
		else       MAX_CW_originTOI[i] = max(sum_1[i],MAX_CW_originTOI[i - 1]);
	}
	for(int i = n - 1; i >= 0; i--) {
		if(i == n-1) MAX_CCW_originTOI[i] = max(sum_2[i],0LL);
		else         MAX_CCW_originTOI[i] = max(sum_2[i],MAX_CCW_originTOI[i + 1]);
	}
	long long int ans = 0LL;
	for(int i = 0; i < n; i++) {
		//CW ONLY
		ans = max(ans,MAX_CW_originTOI[i]);


		//CW ORIGIN - > I AND CCW ORIGIN - > I + 1
		if(i != n - 1)
		ans = max(ans,MAX_CW_originTOI[i] + MAX_CCW_originTOI[i + 1] - x[i]);
		//CCW ONLY
		ans = max(ans,MAX_CCW_originTOI[i]);

		//CCW ORIGIN - > I AND CW ORIGIN - > I - 1
		if(i != 0)
		ans = max(ans,MAX_CCW_originTOI[i] + MAX_CW_originTOI[i - 1] - (c - x[i]));
	}






	cout << ans << endl;



}


Measured memory_bytes: 4992
using System.Linq;
using System.Collections.Generic;
using System;

public class Hello
{
    static int BC;
    public const int Height = 5000;

    public static void Main()
    {
        while (true)
        {
            var n = int.Parse(Console.ReadLine().Trim());
            if (n == 0) break;
            BC = 0;
            var map = new bool[5, Height];
            for (int i = 0; i < n; i++)
            {
                string[] line = Console.ReadLine().Trim().Split(' ');
                var d = int.Parse(line[0]);
                var p = int.Parse(line[1]);
                BC += p;
                var q = int.Parse(line[2]) - 1;
                if (d == 1) putH(map, p, q);
                else putV(map, p, q);
                var ret = eraseLine(map);
                if (ret.Count() > 0)
                    foreach (var x in ret) down(map, x);
            }
            Console.WriteLine(BC);
        }
    }
    public static void down(bool[,] map, int a)
    {
        for (int i = a; i < Height - 1; i++)
        {
            map[0, i] = map[0, i + 1];
            map[1, i] = map[1, i + 1];
            map[2, i] = map[2, i + 1];
            map[3, i] = map[3, i + 1];
            map[4, i] = map[4, i + 1];
        }
    }
    public static List<int> eraseLine(bool[,] map)
    {
        var ret = new List<int>();
        var nexti = -1;
        for (int i = 0; i < Height; i++)
            if (canErase(map, i))
            {
                nexti = i + 1;
                ret.Add(i);
                map[0, i] = false; map[1, i] = false; map[2, i] = false; map[3, i] = false; map[4, i] = false;
                BC -= 5;
                break;
            }
        if (nexti != -1)
            for (int i = nexti; i <= nexti + 4; i++)
                if (canErase(map, i)) { map[0, i] = false; map[1, i] = false; map[2, i] = false; map[3, i] = false; map[4, i] = false; ret.Add(i); BC -= 5; }
        ret.Reverse();
        return ret;
    }
    public static bool canErase(bool[,] map, int a)
    {
        return map[0, a] && map[1, a] && map[2, a] && map[3, a] && map[4, a];
    }
    public static void putH(bool[,] map, int p, int q)
    {
        var hmax = -1;
        for (int i = q; i < p + q; i++)
            for (int j = Height - 1; j >= 0; j--)
                if (map[i, j]) hmax = Math.Max(hmax, j);
        for (int i = q; i < p + q; i++)
            map[i, hmax + 1] = true;
    }
    public static void putV(bool[,] map, int p, int q)
    {
        var hmax = -1;
        for (int i = Height - 1; i >= 0; i--)
            if (map[q, i]) { hmax = i; break; }
        for (int i = 0; i < p; i++)
            map[q, hmax + 1 + i] = true;
    }
}



Measured memory_bytes: 9608
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    abc176_a();
  }

  private static void abc176_a() {
    try (Scanner sc = new Scanner(System.in)) {
      double nAll = sc.nextInt();
      double xOneTime = sc.nextInt();
      int tMinute = sc.nextInt();

      System.out.println((int) Math.ceil(nAll / xOneTime) * tMinute);

    } catch (Exception e) {
      System.out.println("エラー" + e);
    }
  }

  // int 2147483648 [ 2 * 10(9)]
  // long 9223372036854775808 [ 9 * 10(18)]

  public static int parseI(String value) {
    return Integer.parseInt(value);
  }

  public static long parseL(String value) {
    return Long.parseLong(value);
  }

  public static double parseD(String value) {
    return Double.parseDouble(value);
  }

  public static <T> String parseS(T value) {
    return String.valueOf(value);
  }

  public static BigDecimal parseBigD(String value) {
    return new BigDecimal(value);
  }

  public static BigInteger parseBigI(String value) {
    return new BigInteger(value);
  }

}


Measured memory_bytes: 35948