akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <iostream>
#include <cassert>
#include <string>
#include <algorithm>
#include <cstring>
#include <utility>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cmath>
#include <deque>
#include <unordered_map>
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
const int MAXN = 123;
int grid[MAXN][MAXN];
char s[MAXN];
int dp[MAXN][MAXN];

int main() {
    int H, W;
    scanf("%d %d", &H, &W);
    for (int i = 0; i < H; i++) {
        scanf("%s", s);
        for (int j = 0; j < W; j++) {
            if (s[j] == '#')
                grid[i][j] = 1;
            dp[i][j] = 10000;
        }
    }
    if (grid[0][0]) dp[0][0] = 1;
    else dp[0][0] = 0;
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            int offs1 = 0, offs2 = 0;
            if (grid[i][j] != grid[i + 1][j] && grid[i + 1][j])
                 offs1 = 1;
            if (grid[i][j] != grid[i][j + 1] && grid[i][j + 1])
                 offs2 = 1;
            dp[i + 1][j] = min(dp[i + 1][j], dp[i][j] + offs1);
            dp[i][j + 1] = min(dp[i][j + 1], dp[i][j] + offs2);
        }
    }
    printf("%d\n", dp[H - 1][W - 1]);
    return 0;
}

/* stuff you should look for
	* int overflow, array bounds
	* special cases (n=1?)
	* do smth instead of nothing and stay organized
	* WRITE STUFF DOWN
by Benq;
*/


Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <cstring>

using namespace std;

#define P 1000000007

bool isinA[1000001];
bool isinB[1000001];

int A[1000];
int B[1000];

int main(){
    int N, M;
    long ans = 1;
    cin >> N >> M;
    memset(isinA, false, N+1);
    memset(isinB, false, M+1);
    for(int i = 0; i < N; i++){
        cin >> A[i];
        isinA[A[i]] = true;
    }
    for(int i = 0; i < M; i++){
        cin >> B[i];
        isinB[B[i]] = true;
    }
    sort(A, A+N);
    sort(B, B+M);
    for(int i = 1; i < N; i++){
        if(A[i] == A[i-1]){
            cout << 0 << endl;
            return 0;
        }
    }
    for(int i = 1; i < M; i++){
        if(B[i] == B[i-1]){
            cout << 0 << endl;
            return 0;
        }
    }
    for(int i = N*M; i > 0; i--){
        if(isinA[i] && isinB[i]){
            continue;
        }else if(isinA[i]){
            int n = (B+M)-lower_bound(B, B+M, i);
            //cout << n << endl;
            ans = (ans*n)%P;
        }else if(isinB[i]){
            int n = (A+N)-lower_bound(A, A+N, i);
            //cout << n << endl;
            ans = (ans*n)%P;
        }else{
            int n = (B+M)-lower_bound(B, B+M, i);
            int m = (A+N)-lower_bound(A, A+N, i);
            //cout << n << ' ' << m << endl;
            ans = (ans*(n*m-(M*N-i)))%P;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,1,n+1)
#define RFOR(i,l,r) for(long long i=(l);i>=(r);--i)
#define RREP(i,n) RFOR(i,n-1,0)
#define RREPS(i,n) RFOR(i,n,1)
#define int long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
const int INF=1e18;
const int MOD=1e9+7;

signed main(){
    int n;cin>>n;
    double x[n],y[n];
    REP(i,n) cin>>x[i]>>y[i];
    double ans=0;
    REP(i,n)REP(j,n) ans+=sqrt((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]));
    ans/=(double)n;
    cout<<fixed<<setprecision(20.20)<<ans<<endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <sstream>
#include <queue>
#include <map>
#include <vector>
#include <set>
#include <cstdlib>
#include <stack>

using namespace std;

typedef long long LL;
typedef double db;
#define FAST ios::sync_with_stdio(false);
const int MaxN = 1e9 + 5;
const int mod = 1e9 + 7;
int main()
{
	int n , m , ans;
	int a[55],b[55],c[55],d[55], cnt[55];
	cin >> n >> m;
	for(int i = 1 ; i <= n ; i++)
	{
		scanf("%d",&a[i]);
		scanf("%d",&b[i]);
		}
	for(int i = 1 ; i <= m ; i++)
	{
		scanf("%d",&c[i]);
		scanf("%d",&d[i]);
		}
	for(int i = 1; i <= n ; i++)
	{
		int min1 = abs(a[i] - c[1]) + abs(b[i] - d[1]);
		ans = 1;
		for(int j = 2 ; j <= m ; j++)
		{
		int checkk = abs(a[i] - c[j]) + abs(b[i] - d[j]);
		if(checkk < min1)
		   { 
			min1 = checkk;
			ans = j;
		   }
		}
		printf("%d\n",ans);
		}
/*	printf("%d\n",abs(a[3] -  c[3]) + abs(b[3] - d[3]));

	for(int i = 1; i <= n ; i++)
	{
		printf("a[%d] = %d -- b[%d] = %d\n",i,a[i],i,b[i]);
		}
	for(int i = 1; i <= m ; i++)
	{
		printf("c[%d] = %d -- d[%d] = %d\n",i,c[i],i,d[i]);
		}*/
	return 0;
	}

Measured memory_bytes: 256
n=gets.to_i
as=[0]+gets.split.map(&:to_i)
lgcd=[0]*(n+2)
rgcd=[0]*(n+2)

(1..n).each do |i|
  lgcd[i]=lgcd[i-1].gcd(as[i])
end
n.downto(0) do |j|
  rgcd[j]=rgcd[j+1].gcd(as[j])
end

ans=0
(1..n).each do |k|
  kgcd=lgcd[k-1].gcd(rgcd[k+1])
  ans=[ans,kgcd].max
end
puts [ans,lgcd[-2]].max


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

//#define DEBUG
#define int long long
#define rep(i,n) for(int i=1;i<=n;i++)
int n,m;
int f[5010][5010];

void debug(){
  #ifdef DEBUG
  rep(i,n+2){
    rep(j,n+2)cout<<setw(2)<<right<<f[i-1][j-1]<<" ";
    cout<<endl;
  }
  cout<<endl;
  #endif
}

signed main(){
  cin>>n>>m;
  rep(_,m){
    int a,b,x;
    cin>>a>>b>>x;
    f[a-1][b-1]--;
    f[a-1][b]++;
    f[a+x][b-1]++;
    f[a+x+1][b]--;
    f[a+x][b+x+1]--;
    f[a+x+1][b+x+1]++;
  }
  int ans=0;
  debug();
  for(int k=n+1;k>=0;k--){
    for(int i=n,j=k;i>=0&&j>=0;i--,j--){
      f[i][j]+=f[i+1][j+1];
    }
  }
  debug();
  rep(j,n+2){
    rep(i,n+1){
      f[i][j-1]+=f[i-1][j-1];
    }
  }
  debug();
  rep(i,n){
    rep(j,i){
      f[i][j]+=f[i][j-1];
      if(f[i][j])ans++;
    }
  }
  debug();
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 198844
#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <vector>

const int MOD = 1e9 + 7;
const int iINF = 2147483647 / 2;
const long long int llINF = 9223372036854775807 / 2;

using namespace std;
using ll = long long int;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;

typedef pair<ll, ll> pll;
bool paircomp(const pll &a, const pll &b) {
  if (a.first == b.first)
    return a.second < b.second;
  return a.first < b.first;
}

#define REP(i, n) for (ll i = 0; i < (n); i++)
#define RREP(i, n) for (ll i = (n)-1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define AUTO(i, m) for (auto &i : m)
#define ALL(a) (a).begin(), (a).end()
#define MAX(vec) *std::max_element(vec.begin(), vec.end())
#define MIN(vec) *std::min_element(vec.begin(), vec.end())
#define ARGMAX(vec)                                                            \
  std::distance(vec.begin(), std::max_element(vec.begin(), vec.end()))
#define ARGMIN(vec)                                                            \
  std::distance(vec.begin(), std::min_element(vec.begin(), vec.end()))
#define REV(T) greater<T>()
#define PQ(T) priority_queue<T, vector<T>, greater<T>>
#define VVL(a, b, c) vector<vector<ll>>(a, vector<ll>(b, c))
#define VV(T, a, b, c) vector<vector<T>>(a, vector<T>(b, c))
#define VVVL(a, b, c, d)                                                       \
  vector<vector<vector<ll>>>(a, vector<vector<ll>>(b, vector<ll>(c, d)))
#define VVV(T, a, b, c, d)                                                     \
  vector<vector<vector<T>>>(a, vector<vector<T>>(b, vector<T>(c, d)))
#define SP(a) setprecision(a)
#define SQRT(a) sqrt((long double)(a))
#define DPOW(a, b) pow((long double)(a), (long double)(b))
#define UNIQUE(vec)                                                            \
  do {                                                                         \
    sort(ALL((vec)));                                                          \
    (vec).erase(std::unique(ALL((vec))), (vec).end());                         \
  } while (0)

ll MODPOW(ll n, ll m) {
  if (m == 0) {
    return 1;
  } else if (m % 2 == 0) {
    ll tmp = MODPOW(n, m / 2);
    return (tmp * tmp) % MOD;
  } else {
    return (n * MODPOW(n, m - 1)) % MOD;
  }
}

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

ll nCr(vl &f, ll n, ll r) {
  if (n < r)
    return 0LL;
  if (r > n / 2LL)
    r = n - r;
  ll res = (f[n] * MODPOW(f[n - r], MOD - 2LL)) % MOD;
  res = (res * MODPOW(f[r], MOD - 2LL)) % MOD;
  return res;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll N, K;
  cin >> N >> K;
  vl f(3e5 + 1, 0);
  f[0] = 1;
  FOR(i, 1, 3e5) f[i] = (f[i - 1] * i) % MOD;
  ll ans = 0;

  FOR(i, K, N + 2) {
    ll mi = (1 + i) * i / 2;
    ll ma = (N - i + 2 + N + 1) * i / 2;
    ans += (ma - mi + 1) % MOD;
    ans %= MOD;
  }
  cout << ans << endl;

  return 0;
}


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

int main() {
  int a[10000];
  for(int i=1; i<10001; i++) {
      cin >> a[i];
      if(a[i]==0) {
          return 0;
      }
  cout << "Case " << i << ": " << a[i] << endl;
  }
  return 0;
}


Measured memory_bytes: 3032
program match_matching
  implicit none
  integer :: n, m, i, j, dp(0:10000) = -1
  integer, dimension(9) :: a = 0, x = 0, p = (/2,5,5,4,5,6,3,7,6/)
  read(*,*) n, m
  read(*,*) a(1:m)
  do i = 1, m
    x(a(i)) = x(a(i))+1
  end do
  m = 0
  do i = 9, 1, -1
    if (x(i) == 0) cycle
    m = m+1
    a(m) = i
  end do
  dp(0) = 0
  do i = 1, n
    do j = 1, m
      if (i < p(a(j))) cycle
      dp(i) = max(dp(i),dp(i-p(a(j))))
    end do
    if (dp(i) >= 0) dp(i) = dp(i)+1
  end do
  i = n
  x = 0
  do while (i > 0)
    do j = 1, m
      if (i-p(a(j)) < 0 .or. dp(i-p(a(j))) /= dp(i)-1) cycle
      i = i-p(a(j))
      x(a(j)) = x(a(j))+1
      exit
    end do
  end do
  do i = 9, 1, -1
    do j = 1, x(i)
      write(*,'(i0)',advance='no') i
    end do
  end do
  write(*,*)
end program match_matching

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int n,N,sum;
  cin >> n;
  N = n;
  sum = 0;
  for (int i=0;;i++){
    sum += n%10;
    n/=10;
    if (n==0){
      break;
    }
  }
  if (N % sum ==0){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" <<endl;
  }
}

Measured memory_bytes: 256
import math
import sys

def getinputdata():

    # 配列初期化
    array_result = []
    
    data = input()

    
    array_result.append(data.split(" "))

    flg = 1

    try:


        while flg:

            data = input()

            array_temp = []

            if(data != ""):
                
                array_result.append(data.split(" "))

                flg = 1

            else:

                flg = 0
    finally:


        return array_result





arr_data = getinputdata()

s1 = arr_data[0][0]
s2 = arr_data[1][0]


if (s1[0]==s2[2] and s1[2]==s2[0] and s1[1]==s2[1]):
    
    print("YES")
    
else:
    
    print("NO")

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <math.h>
#include <iomanip>
#include <bitset>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <utility>
#include <set>
using namespace std;
typedef long long int ll;
typedef long double ld;
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 long long INF = 1LL << 60;
 
typedef pair<ll,ll> pairs;
vector<pairs> p;
bool pairCompare(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.first < secondElof.first;
}
#define MAX_N 1000100
bool x[MAX_N];
ll num[MAX_N];
ll fibl[MAX_N]={0};
 
ll fib(ll a){
    if (fibl[a]!=0)return fibl[a];
    if (a==0){
        return 0;
    }else if (a==1){
        return 1;
    }
    return fibl[a]=fib(a-1)+fib(a-2);
}
 
ll eratosthenes(ll n) {
    int p = 0;
    for (ll i=0; i<=n; ++i) x[i] = true;
    x[0] = x[1] = false;
    for(int i=2; i<=n; ++i) {
        if(x[i]) {
            p++;
            for(int j=2*i; j<=n; j+=i) x[j] = false;
        }
        
        num[i] = p;
    }
    return p;
}
 
ll gcd(ll a,ll b){
    if (a%b==0)return(b);
    else return(gcd(b,a%b));
}
 
ll keta(ll N){
    int tmp{};
    while( N > 0 ){
        tmp += ( N % 10 );
        N /= 10;
    }
    N = tmp;
    return N;
}

int main(){
    ll n,ans=0;
    cin >> n;
    vector<ll> a;
    for (ll i=0;i<n;i++){
        ll x;
        cin >> x;
        a.push_back(x);
    }
    sort(a.begin(),a.end());
    for (ll i=0;i<n;i++){
        ll count=0,flag=a[i];
        while(i<n and flag==a[i]){
            count++;
            i++;
        }
        i--;
        ans+=count%2;
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 1400
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }

const int MAX_N = 100;
int N;
int A[MAX_N];

void _main() {
  cin >> N;
  rep(i, 0, N) cin >> A[i];
  sort(A, A + N);
  cout << (A[N-1] - A[0]) << "\n";
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp5
{
    class Program
    {

        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            int[] B = new int[N - 1];
            String S = Console.ReadLine();
            String[] L = S.Split(' ');

            for(int i=0; i<N-1; i++)
            {
                B[i] = int.Parse(L[i]);
            }

            long res = B[0] + B[N-2];

            for(int i=0; i<N-2; i++)
            {
                res = res + Math.Min(B[i], B[i + 1]);
            }

            Console.WriteLine(res);
           
        }
    }
}

Measured memory_bytes: 13140
#include <stdio.h>
int main(){
 int n,a,b,max,min;
 scanf("%d%d%d",&n,&a,&b);
 max=(a>b?b:a);
 min=a+b-n;
 if(min<0)
   min=0;
 printf("%d %d",max,min);
 return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin>>s;
  int n=s.size();

  int ans=n;
  for(int i=0;i<n-1;i++){
    if(s[i]!=s[i+1]){
      ans=min(ans,max(i+1,n-i-1));
    }
  }

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


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

int main()
{
    int n;
    cin >> n;
    int S[n];
    for (int i = 0; i < n; i++) {
        cin >> S[i];
    }
    int q;
    cin >> q;
    int C = 0;
    for (int i = 0; i < q; i++) {
        int T;
        cin >> T;
        if (binary_search(S, S + n, T)) {
            C++;
        }
    }
   cout << C << endl;
    return 0;
}

Measured memory_bytes: 3484
import java.util.Scanner;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.Queue;

public class Main {	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		
		int c = 0;
		for(int i = 1; i <= 9; i++) {
			for(int j = 1; j <= 9; j++) {
				int m = i*j;
				if(m == n)
					c += 1;
			}
		}
		
		if(c >= 1)
			System.out.println("Yes");
		else
			System.out.println("No");
	}

}

Measured memory_bytes: 22868
#include <cstdio>
#include <cinttypes>
#include <sys/types.h>
using namespace std;

u_int64_t  f(u_int64_t n, u_int64_t m=1) {
  if (n == 1) {
    return m;
  } else {
    return m + f(n/2, m*2);
  }
}


int main() {
  u_int64_t H;
  scanf("%" PRId64, &H);
  fflush(stdout);
  printf ("%" PRId64 "\n", f(H));

  return 0;
}


Measured memory_bytes: 128
#!python3

iim = lambda: map(int, input().rstrip().split())

def resolve():
    H, W = iim()

    dp = [0] * W
    dp0 = [0] * W
    ans = 0
    for i in range(H):
        C = list(iim())

        dp[0] = C[0] ^ 1
        for i in range(1, W):
            ci = C[i]
            if ci:
                dp[i] = 0
            else:
                dp[i] = min(dp0[i-1], dp[i-1], dp0[i]) + 1
        #print(*dp)

        ans = max(ans, *dp)
        dp, dp0 = dp0, dp

    print(ans**2)




if __name__ == "__main__":
    resolve()



Measured memory_bytes: 5716
#include <iostream>
#include <cstdio>
#include <cstring>
#include <climits>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <sstream>
#include <numeric>
// #include <boost/multiprecision/cpp_dec_float.hpp>
// #include <boost/multiprecision/cpp_int.hpp>

///////////////////////////////////////////////////////////////
// namespace
///////////////////////////////////////////////////////////////
using namespace std;
// namespace mp = boost::multiprecision;

///////////////////////////////////////////////////////////////
// types
///////////////////////////////////////////////////////////////
using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
// using mpi = mp::cpp_int;
// using mpf = mp::number<mp::cpp_dec_float<1024>>;

///////////////////////////////////////////////////////////////
// mod https://qiita.com/drken/items/3b4fdf0a78e7a138cd9a
///////////////////////////////////////////////////////////////
// ll MOD = 1000000007;
//
// ll mod(long long val) {
//     long long res = val % MOD;
//     if (res < 0) res += MOD;
//     return res;
// }
//
// ll modinv(ll a) {
//     ll b = MOD, u = 1, v = 0;
//     while (b) {
//         ll t = a / b;
//         a -= t * b; swap(a, b);
//         u -= t * v; swap(u, v);
//     }
//     u %= MOD;
//     if (u < 0) u += MOD;
//     return u;
// }
//
// const int MAX = -1;
// ll fac[MAX], finv[MAX], inv[MAX];
// void com_init() {  // initialize nCk table with O(N)
//     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;
//     }
// }
// ll com(int n, int k){  // nCk
//     if (n < k) return 0;
//     if (n < 0 || k < 0) return 0;
//     return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
// }


int main() {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    while (true) {
        c -= b;
        if (c <= 0) {
            cout << "Yes" << endl;
            return 0;
        }
        a -= d;
        if (a <= 0) {
            cout << "No" << endl;
            return 0;
        }
    }
}


Measured memory_bytes: 3620
N, Y = list(map(int, input().split()))

flg = False
for i in range(N+1):
    for j in range(N+1-i):
        if 10000*i + 5000*j + 1000*(N-i-j) == Y:
            ans = i,j,N-i-j
            flg = True

if flg:
    print(*ans)
else:
    print(-1,-1,-1)


Measured memory_bytes: 3064
#pragma once
#include <string.h>
#include <stdio.h>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <deque>
using namespace std;
#define INF 1000000007
typedef long long ll;
typedef pair<int, int> pii;
int t[101];
int pri[26];
int res = 0;
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
int pr[100010];
void uini(int n) {
	for (size_t i = 0; i <= n; i++)
	{
		pr[i] = i;
	}
}

int parent(int x) {
	if (x == pr[x]) return x;
	return pr[x] = parent(pr[x]);
}

bool unit(int x, int y) {
	int px = parent(x);
	int py = parent(y);

	if (px == py) return false;
	if (px < py) {
		pr[y] = px;
	}
	else {
		pr[x] = py;
	}
	return true;
}

// dinic
struct max_flow {
	struct edge { int to, cap, rev;
	edge(int _to, int _cap, int _rev) : to(_to), cap(_cap), rev(_rev) {}
	};
	int V;
	vector<vector<edge>> G;
	vector<int> itr, level;

	max_flow(int V) : V(V) { G.assign(V, vector<edge>()); }

	void add_edge(int from, int to, int cap) {
		G[from].push_back(edge (to, cap, (int)G[to].size() ));
		G[to].push_back(edge (from, 0, (int)G[from].size() - 1 ));
	}

	void bfs(int s) {
		level.assign(V, -1);
		queue<int> q;
		level[s] = 0; q.push(s);
		while (!q.empty()) {
			int v = q.front(); q.pop();
			for (auto &e : G[v]) {
				if (e.cap > 0 and level[e.to] < 0) {
					level[e.to] = level[v] + 1;
					q.push(e.to);
				}
			}
		}
	}

	int dfs(int v, int t, int f) {
		if (v == t) return f;
		for (int& i = itr[v]; i < (int)G[v].size(); ++i) {
			edge& e = G[v][i];
			if (e.cap > 0 && level[v] < level[e.to]) {
				int d = dfs(e.to, t, min(f, e.cap));
				if (d > 0) {
					e.cap -= d;
					G[e.to][e.rev].cap += d;
					return d;
				}
			}
		}
		return 0;
	}

	int run(int s, int t) {
		int ret = 0, f;
		while (bfs(s), level[t] >= 0) {
			itr.assign(V, 0);
			while ((f = dfs(s, t, INF)) > 0) ret += f;
		}
		return ret;
	}
};
vector<vector<int> > calcNext(const string &S) {
	int n = (int)S.size();
	vector<vector<int> > res(n + 1, vector<int>(26, n));
	for (int i = n - 1; i >= 0; --i) {
		for (int j = 0; j < 26; ++j) res[i][j] = res[i + 1][j];
		res[i][S[i] - 'a'] = i;
	}
	return res;
}

const int MOD = 1000000007;
// mod 1000000007 の世界で a += b する関数
void add(long long &a, long long b) {
	a += b;
	if (a >= MOD) a -= MOD;
}


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

void solv() {
	int n, m, q;
	cin >> n >> m >> q;
	ll dp[501][501];
	memset(dp, 0, sizeof(dp));
	for (size_t i = 0; i < m; i++)
	{
		int l, r;
		cin >> l >> r;
		dp[l][r]++;
		dp[l][0]++;
		dp[0][r]++;
	}

	for (int j = 1; j <= n; j++)
		for (int i = j; i > 1; i--)
			dp[i - 1][j] += dp[i][j];


	for (int i = 1; i <= n; i++)
		for (int j = i; j < n; j++)
			dp[i][j + 1] += dp[i][j];

	for (size_t i = 0; i < q; i++)
	{
		int l, r;
		cin >> l >> r;
		cout << dp[l][r] << endl;
	}

}


int main() {
	solv();

	return 0;
}


Measured memory_bytes: 2944
#include<bits/stdc++.h>
#define F first
#define S second
#define endl '\n'
#define MP make_pair
#define pb push_back

using namespace std;

typedef pair<int, int> P;
typedef pair<int, P> i_P;
typedef long long LL;

static const int INF = INT_MAX;
static const int MIN = INT_MIN;
static const LL L_INF = LLONG_MAX;
static const int MOD = 1000000000 + 7;
static const int SIZE = 100005;

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

    int n, k;
    cin >> n >> k;
    ++n;
    int a[n];
    --n;
    for( int i = 1; i <= n; ++i ) {
        cin >> a[i];

    }

    int res = INF;
    --k;
    for( int i = 1; i <= n - k; ++i ) {
        if( a[i] < 0 && a[i + k] < 0 ) res = min( abs( a[i] ), res );
        else if( a[i] < 0 ) {
            int t = abs( a[i] );
            if( t < a[i + k] ) res = min( t * 2 + a[i + k], res );
            else res = min( t + a[i + k] * 2, res );

        } else res = min( res, abs( a[i + k] ) );

    }
    cout << res << endl;

    return 0;
}



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

using namespace std;

int main(void) {
	int k,s;
	cin >> k >> s;
	int count = 0;
	for (int x = 0; x <= k; x++) {
		for (int y = 0; y <= k; y++) {
			int z = s - x - y;
			if (z >= 0 && z <= k) {
				count++;
			}
		}
	}
	cout << count;
	return 0;
}

Measured memory_bytes: 256
#pragma region template 1.0
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll, ll> ii;
#define REP(i, n) for (ll i = 0; i < (n); ++i)
#define REP1(i, n) for (ll i = 1; i <= (n); ++i)
#define OUT(x) cout << (x) << endl;
#define OUTA(a) \
    REP(i, (a).size()) { cout << (a[i]) << (i == (a).size() - 1 ? "\n" : " "); }
#define ALL(a) (a).begin(), (a).end()
#define SORT(a) sort(ALL(a))
#define RSORT(a) \
    SORT(a);     \
    reverse(ALL(a))

const ll INF = 1e18;
const ll MOD = 1e9 + 7;

vector<vi> G;
vi dp;

ll f(ll i)
{
    if (dp[i] != -INF)
    {
        return dp[i];
    }
    dp[i] = 0;
    REP(k, G[i].size())
    {
        ll j = G[i][k];
        dp[i] = max(dp[i], 1 + f(j));
    }
    return dp[i];
}

int main()
{
    ll N, M;
    cin >> N >> M;
    vi x(M), y(M);
    REP(i, M) { cin >> x[i] >> y[i]; }

    G = vector<vi>(N + 1);
    REP(i, M)
    {
        G[x[i]].push_back(y[i]);
    }
    dp = vi(N + 1, -INF);
    ll ans = 0;
    REP1(i, N)
    {
        ans = max(ans, f(i));
    }
    OUT(ans);
}
#pragma endregion template

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

using Graph = vector<vector<int>>;

// 二部グラフ判定
vector<int> color;
bool dfs(const Graph &G, int v, int cur = 0) {
    color[v] = cur;
    for (auto next_v : G[v]) {
        // 隣接頂点がすでに色確定していた場合
        if (color[next_v] != -1) {
            if (color[next_v] == cur) return false; // 同じ色が隣接したらダメ
            continue;
        }

        // 隣接頂点の色を変えて、再帰的に探索 (一回でも false が返ってきたら false)
        if (!dfs(G, next_v , 1 - cur)) return false;
    }
    return true;
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);
    
    
    int n;
    cin>>n;
    string s[n];
    for(int i=0;i<n;i++){
        cin>>s[i];
    }
    int ans = 0;

    Graph G(n);
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            if(s[i][j]=='1'){
                G[i].push_back(j);
            }
        }
    }
    color.assign(n, -1);
    bool is_bipartite = true;
    for (int v = 0; v < n; ++v) {
        if (color[v] != -1) continue; // v が探索済みだったらスルー
        if (!dfs(G, v)) is_bipartite = false;
    }
    if (!is_bipartite){
        cout << -1 << endl;
        return 0;
    }

    for(int h=0;h<n;h++){
        int c[n]={};
        queue<int> st;
        st.push(h);
        c[h] = 1;
        while(!st.empty()){
            int t = st.front(); st.pop();
            for(int i=0;i<n;i++){
                if(s[t][i]=='0') continue;
                if(c[i]==0){
                    st.push(i);
                    c[i] = c[t] + 1;
                }
            }
        }
        for(int i=0;i<n;i++){
            ans = max(ans,c[i]);
        }
    }
    cout << ans << endl;


}


Measured memory_bytes: 512
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) {
		BufferedReader input = new BufferedReader(new InputStreamReader(System.in));

        try{
        	   //?????±?????\???
        	   String az=input.readLine();
      	       int a=Integer.parseInt(az);
               //[0][0][0]0????????????????§??????????????????????
	           int Array[][][]=new int[5][4][11];
	           int b=0;
	           int f=0;
	           int r=0;
	           int v=0;
	           for(int i=0; i<a; i++){
	        	   String ab = input.readLine();
		           String []strAry = ab.split(" ");
	           //??´??°??\???
	           b=Integer.parseInt(strAry[0]);
	           //????±???\???
	           f=Integer.parseInt(strAry[1]);
	           //??¨?±??????\???
	           r=Integer.parseInt(strAry[2]);
	           //?????°??\???
	              v=Integer.parseInt(strAry[3]);
	             //Array???????????°????????????????¢????
	              if(Array[b][f][r]>0){
	            	  Array[b][f][r]+=v;
	              }else{
	            	  //??????Array???b??´f???r??¨?±??????\?????????????????????????´?
	                    Array[b][f][r]=v;
	              }

	           }
                 int count=1;
	           for(int u=1; u<5; u++){
	        	   for(int o=1; o<4; o++ ){
	        		   for(int q=1; q<11; q++){
	        			   //Array????????°????????\??£?????????????????????????????????????´??????????????????¨??????????????\??£?????????
	        			  System.out.print(" "+Array[u][o][q]);
	        			}
	        		   System.out.println("");
	        		 }
	        	       if(count<4){
                       System.out.print("####################");

	        		   System.out.println("");
	        	       }
	        		   count++;
	        	 }



       		      }catch(IOException e) {   System.out.println("Exception : " + e);
		    }



	}//240 Array?????£?????????????????????????????????

}

Measured memory_bytes: 24624
N, totalWt = list(map(int, input().split()))
itemsVal = [0]
itemsWt = [0]
for i in range(0, N):
    val, weight = list(map(int, input().split()))
    itemsVal.append(val)
    itemsWt.append(weight)

mylist = [[0 for _ in range(totalWt+1)] for _ in range(N + 1)]


for i in range(1, N + 1):
    for j in range(1, totalWt+1):
        if j >= itemsWt[i]:
            mylist[i][j] = max(mylist[i-1][j], mylist[i-1][j-itemsWt[i]] + itemsVal[i])
        else:
            mylist[i][j] = mylist[i-1][j]

print(mylist[len(itemsWt)-1][totalWt])


Measured memory_bytes: 25940
// AUTHOR : Kishan Srivastav
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
#define in freopen("input.txt", "r", stdin)
#define out freopen("output.txt", "w", stdout)
#define ios ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);


int main() {
	ios
#ifndef ONLINE_JUDGE
	in;
	out;
#endif
	string s,t;
	cin>>s>>t;
	int count = 0;
	for (int i = 0; i < s.length(); i++){
		if(s[i] == t[i]){
			count++;
		}
	}
	cout<<count<<endl;

}

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

using namespace std;

int main(){
  long long h,w;
  cin >> h >> w;
  if(h%3==0 || w%3==0){
    cout << 0 << endl;
    return 0;
  }
  long long dx[2]={h/3,h/3+1};
  long long dy[2]={w/3,w/3+1};
  long long m=10000000000;
  for(long long i=1;i<w;i++){
    long long s1,s2,s3;
    long long p,q;
    s1=h*i;
    s2=(w-i)*(h/2);
    s3=h*w-s1-s2;
    p=max(s1,max(s2,s3));
    q=min(s1,min(s2,s3));
    m=min(m,p-q);
  }
  for(long long i=1;i<h;i++){
    long long s1,s2,s3;
    long long p,q;
    s1=w*i;
    s2=(h-i)*(w/2);
    s3=h*w-s1-s2;
    p=max(s1,max(s2,s3));
    q=min(s1,min(s2,s3));
    m=min(m,p-q);
  }
  m=min(m,min(h,w));
  cout << m << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rrepi(i,a,b) for(int i=((int)(b)-1);i>=(a);--i)
#define rep(i,n) repi(i,0,n)
#define rrep(i,n) rrepi(i,0,n)
#define ALL(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define ZERO(x) memset(x,0,sizeof(x))
#define MINUS(x) memset(x,-1,sizeof(x))
#define UNIQUE(x) (x).erase(unique(ALL(x)), (x).end())
#define TOUPPER(x) transform(ALL(x), (x).begin(), ::toupper)
#define TOLOWER(x) transform(ALL(x), (x).begin(), ::tolower)
#define debug(var)  do{std::cout << #var << " : "; view(var);}while(0)
#define fi first
#define se second
using namespace std;
using ll = long long;
using P = pair<int,int>;
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){for(const auto& v : vv){ view(v); } }
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void viewarr(T arr[], int n) { for(int i = 0; i < n; ++i) std::cout << arr[i] << " "; std::cout << std::endl; }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll qp(ll a,ll b){ll ans=1;do{if(b&1)ans=1ll*ans*a;a=1ll*a*a;}while(b>>=1);return ans;}
ll qp(ll a,ll b,ll mo){ll ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
const int INF = 1e9;
const ll INFL = 1e18;
const int MOD = 1e9 + 7;
const int MAX_N = 1e5;

bool if_end(vector<int> &A, int N, int M) {
    bool res = true;
    rep(i,N) if(A[i] != M) res = false;
    return res;
}

bool nextnum(vector<int> &A, int N, int M) {
    if(if_end(A,N,M)) return false;
    rrep(i,N) {
        if(A[i] < M) {
            A[i]++;
            break;
        } else if(A[i-1] < M) {
            A[i-1]++;
            repi(j,i,N) A[j] = A[i-1];
            break;
        }
    }
    return true;
}

ll calc(vector<int> A, int Q, vector<int> a, vector<int> b, vector<int> c, vector<int> d) {
    ll res = 0;
    rep(i,Q) {
        if(A[b[i]] - A[a[i]] == c[i]) res += d[i];
    }
    return res;
}


int main() {
    int N, M, Q;
    cin >> N >> M >> Q;
    vector<int> a(Q),b(Q),c(Q),d(Q);
    rep(i,Q) {
        cin >> a[i] >> b[i] >> c[i] >> d[i];
        a[i]--; b[i]--;
    }
    ll ans = 0;
    vector<int> A(N);
    rep(i,N)  A[i] = 1;
    do {
        chmax(ans, calc(A,Q,a,b,c,d));
    } while(nextnum(A,N,M));
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3632
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>

int main(){
    char a, b;
    std::cin>>a>>b;

    char c = 'D';
    if((a == 'H' && b == 'H') || (a == 'D' && b == 'D')){
        c = 'H';
    }
    std::cout<<c<<std::endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <algorithm>
#include <functional>
#include <string.h>

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

int Par[100001];
int Rank[100001];
long long Sum[100001];

void init(long long n)
{
	for (int i = 0; i < n; ++i)
	{
		Par[i] = i;
		Rank[i] = 1;
	}
}

int find(int x)
{
	if (Par[x] == x)
	{
		return(x);
	}
	else
	{
		return(Par[x] = find(Par[x]));
	}
}

void unite(long long x, long long y)
{
	x = find(x);
	y = find(y);
	if (x == y)
	{
		return;
	}
	if (Rank[x] > Rank[y])
	{
		swap(x, y);
	}
	Par[x] = y;
	Rank[y] += Rank[x];
}

bool same(int x, int y)
{
	return(find(x) == find(y));
}

void solve()
{
	long long N, M;
	cin >> N >> M;
	vector<long long> A(M);
	vector<long long> B(M);
	vector<long long> ans;
	init(N);
	long long sum = N * (N - 1) / 2;
	for (int i = 0; i < M; ++i)
	{
		cin >> A[i] >> B[i];
		--A[i];
		--B[i];
	}
	reverse(A.begin(), A.end());
	reverse(B.begin(), B.end());
	for(int i = 0; i < M; ++i)
	{
		ans.push_back(sum);
		if(!same(A[i], B[i]))
		{
			sum = sum - Rank[find(A[i])] * Rank[find(B[i])];
		}
		unite(A[i], B[i]);
	}
	reverse(ans.begin(), ans.end());
	for (int i = 0; i < ans.size(); ++i)
	{
		cout << ans[i] << endl;
	}
}

int main()
{
	solve();
	return(0);
}

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

using namespace std;

const int N = 100000 + 77;
int n , m , d[N] , A;
vector < int > a[N];
bool M[N];
void dfs(int v){
   M[v] = 1;
   d[v] = 1;
   for(int u : a[v]){
      if(! M[u])
         dfs(u);
      d[v] = max(d[v] , d[u] + 1);
   }
   A = max(A , d[v]);
}
int main(){
   ios::sync_with_stdio(0);cin.tie(0);
   cin >> n >> m;
   for(int u , v , i = 1;i <= m;++ i){
      cin >> v >> u;
      a[v].push_back(u);
   }
   for(int i = 1;i <= n;++ i)
      if(! M[i])
         dfs(i);
   cout << A - 1;
   return 0;
}


Measured memory_bytes: 8320
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string N;
    cin >> N;
    vector<int> nums(N.size() + 1);
    vector<int> ruisekiNums(N.size() + 1);
    vector<int> oturiNums(N.size() + 1);
    for(int i = N.size(); i > 0; i--)
    {
        int num = N.at(i - 1) - '0';
        nums.at(i) += num;
        if(nums.at(i) > 5 || (nums.at(i) == 5 && i > 1 && N.at(i - 2) - '0' >= 5))
        {
            oturiNums.at(i) = 10 - nums.at(i);
            nums.at(i - 1) = 1;
            nums.at(i) = 0;
        }
    }
    ll answer = 0;
    for(int i = 0; i < N.size() + 1; i++)
    {
        answer += nums.at(i) + oturiNums.at(i);
    }
    cout << answer << endl;
    return 0;
}


Measured memory_bytes: 13084
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = Integer.parseInt(scan.next());
        int m = Integer.parseInt(scan.next());
        int[] a = new int[m];
        int[] b = new int[m];
        for (int i = 0; i < m; i++) {
            a[i] = Integer.parseInt(scan.next());
            b[i] = Integer.parseInt(scan.next());
            a[i]--;
            b[i]--;
        }
        scan.close();

        int ans = 0;
        for (int i = 0; i < m; i++) {
            UnionFind uf = new UnionFind(n);
            for (int j = 0; j < m; j++) {
                if (i == j) {
                    continue;
                }
                uf.unite(a[j], b[j]);
            }

            int root = uf.getRoot(0);
            for (int k = 1; k < n; k++) {
                if (uf.getRoot(k) != root) {
                    ans++;
                    break;
                }
            }
        }

        System.out.println(ans);
    }

    static class UnionFind {

        /** ルートノード */
        private int[] roots;

        /**
         * コンストラクタ.
         *
         * @param n ノード数
         */
        public UnionFind(int n) {
            roots = new int[n];
            for (int i = 0; i < n; i++) {
                roots[i] = i;
            }
        }

        /**
         * 各々のノードが属するグループを結合する.
         *
         * @param x
         * @param y
         */
        public void unite(int x, int y) {
            roots[getRoot(y)] = getRoot(x);
        }

        /**
         * 各々のノードが属するグループが同じかどうかを判定する.
         *
         * @param x
         * @param y
         * @return 同じグループに属するならtrue
         */
        public boolean same(int x, int y) {
            return getRoot(x) == getRoot(y);
        }

        /**
         * ルートノードを返す.<br>
         * 再帰によって経路圧縮を行っている.
         *
         * @param x
         * @return ルートノード
         */
        public int getRoot(int x) {
            int parent = roots[x];
            if (x != parent) {
                roots[x] = getRoot(parent);
            }
            return roots[x];
        }

    }

}


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

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

int dp[100];

//最大公約数
int gcd(int x, int y){
  if(x % y == 0) return y;
  return gcd(y, x % y);
}
//最小公倍数
int lcm(int x, int y){
  return x * y / gcd(x, y);
}
//フィボナッチ数列
//配列dpを-1で初期化する
int fib(int n){
  if(n == 0 || n == 1) return dp[n] = 1;
  if(dp[n] != -1) return dp[n];
  return dp[n] = fib(n - 1) + fib(n - 2);
}
//階乗計算(factorial)
int fact(int n){
  if(n = 1) return 1;
  return n * fact(n - 1);
}
//累乗計算(Exponentiation)
//x**y
ll expo(int x, int y){
  ll ans = 1;
  rep(i, y){
    ans *= x;
  }
  return ans;
}
//桁数
int keta(ll x){
  if(x == 0) return 1;
  int res = 0;
  while(x){
    x /= 10;
    res++;
  }
  return res;
}


int main(){
  double a, b;
  cin >> a >> b;
  double ans = a / b;
  printf("%10f", ans);
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#include "math.h"
#include "string.h"
#include "algorithm"
 
using namespace std;
typedef int64_t ll;
typedef vector<int64_t> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vin;
typedef pair<ll,ll> P;
typedef vector<P> vp;
typedef vector<double> vd;
typedef vector<vd> vvd;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SIZE(a) int((a).size())
int main(){
  ll n,k;
  cin>>n>>k;
  ll x=n/k-1;
  n-=k*x;
  while(n>k/2){
    n=abs(n-k);
  }
  n=min(n,abs(n-k));
  cout<<n<<endl;
}

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

#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define SORT(c) sort((c).begin(),(c).end())
#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG false

typedef long long ll;
typedef pair<int, int> ii;

int main() {
	ll n, k;
	cin >> n >> k;
	vector<ll> a(n);
	rep(i, n) cin >> a[i];
	SORT(a);
	reverse(a.begin(), a.end());

	set<ll> st;
  st.insert(0);

	ll ans = 0;
	rep(i, n){
		set<ll> tmp(st);
		for(auto it : st){
			if(a[i] + it >= k) ans = i + 1;
      else tmp.insert(a[i] + it);
		}
		st = tmp;
	}

  cout << n - ans << endl;

	return 0;
}


Measured memory_bytes: 768
integer(16)N
integer(16),allocatable,dimension(:)::A
integer(16)tmp,tmpcnt,ans
read*,N
allocate(A(N))
do i=1,N
  read*,A(i)
end do
call heapsort(N,A)
tmp=0;tmpcnt=0;ans=0
do i=1,N
  if(A(i)==tmp)then
    tmpcnt=xor(tmpcnt,1)
  else
    ans=ans+tmpcnt
    tmp=A(i)
    tmpcnt=1
   endif
end do
ans=ans+tmpcnt
print"(i0)",ans
contains
subroutine heapsort(n,array)
  implicit none
!ここの入力は状況に応じて変更すること
  integer(16),intent(in) :: n
  integer(16),intent(inout) :: array(1:n)
  integer(16)::i,k,j,l
  integer(16):: t

  l=n/2+1
  k=n
  do while(k /= 1)
     if(l > 1)then
        l=l-1
        t=array(L)
     else
        t=array(k)
        array(k)=array(1)
        k=k-1
        if(k == 1) then
           array(1)=t
           exit
        endif
     endif
     i=l
     j=l+l
     do while(j<=k)
        if(j < k)then
           if(array(j) < array(j+1))j=j+1
        endif
        if (t < array(j))then
           array(i)=array(j)
           i=j
           j=j+j
        else
           j=k+1
        endif
     enddo
     array(i)=t
  enddo
  return
end subroutine heapsort
end

Measured memory_bytes: 1792
#include <iostream>
#include <string>
using namespace std;
int main(void){
    string a,b,c;
    
    cin >> a >> b >> c;
    
    if(a[a.length()-1] == b[0] && b[b.length()-1] == c[0]) cout << "YES" << endl; else cout << "NO" << endl;
    
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std ;
#define ll long long int 
#define pb push_back 
#define mp make_pair 
#define pii pair <int , int > 
#define pll pair < ll , ll >
int main(){
	ios_base::sync_with_stdio(false) ;
	cin.tie(NULL) ;
	int a ;
  string s ;
  cin >> a >> s ;
  if(a < 3200){
    cout << "red" ;
  }
  else cout << s ;
}

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

int main() {
  int N; long K; cin >> N >> K;
  int A[N]; for (int i = 0; i < N; i++) cin >> A[i];
  vector<int> V; V.push_back(1);
  int loop_return;
  bool visited[N]; for (int i = 0; i < N; i++) visited[i] = false;
  visited[0] = true;
  while (true) {
    int next = A[V.back()-1];
    if (visited[next-1]) {
      loop_return = distance(V.begin(), find(V.begin(), V.end(), next));
      break;
    } else {
      V.push_back(next);
      visited[next-1] = true;
    }
  }
  if (K < V.size()) cout << V[K] << endl;
  else cout << V[loop_return + (K - V.size()) % (V.size() - loop_return)] << endl;
}

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

class UnionFind {
private:
  vector<ll> par_;
public:
  UnionFind(ll n) {
    //par_[i]がiの集合サイズ
    par_.resize(n, -1);
  }

  //根を求める
  //集合の要素数はマイナスで表すから、、マイナスになる前の数が根の値
  ll root(ll x) {
    return (par_[x]<0 ? x : par_[x]=root(par_[x]));
  }

  //xとyの属する集合を併合
  void unite(ll x, ll y) {
    x=root(x);
    y=root(y);
    if(x==y) {
      return;
    }
    par_[x]+=par_[y];
    par_[y]=x;
  }

  //xが属する集合のサイズを取得
  ll size(ll x) {
    return -par_[root(x)];
  }

  //xとyが同じ集合に属するか否かを判定
  bool same(ll x, ll y) {
    return (root(x) == root(y));
  }
};

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

  UnionFind uf(N);
  vector<ll> ans(M);
  ans[M-1]=N*(N-1)/2;
  for (ll i=M-1;i>0;i--) {
    //同じ属性に属する場合、ansは増えない
    if (uf.same(A[i], B[i])) {
      ans[i-1]=ans[i];
      continue;
    }
    //違う属性の場合
    //属性の要素の個数を記録
    ll size1=uf.size(A[i]);
    ll size2=uf.size(B[i]);

    //異なる２つの属性を足し合わせる
    ans[i-1]=ans[i]-size1*size2;
    uf.unite(A[i], B[i]);
  }
  for (auto a : ans) {
    cout << a << endl;
  }
}

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

int main() {

    int N;
    cin >> N;
    vector<int> n_vec;
    //map<string,int> n_map;

    for (int i = 0; i < N; i++) {
        int a;
        cin >> a ;
        n_vec.push_back(a);
    }

    sort(n_vec.begin(), n_vec.end(),greater<int>());

    int a_sum = 0;
    int b_sum = 0;

    for (int i = 0; i < n_vec.size(); i++) {
        //cout << n_vec.at(i) << endl;
        if(i % 2 == 0){
            a_sum += n_vec.at(i);
        }else{
            b_sum += n_vec.at(i);
        }
    }

    cout << a_sum - b_sum << endl;

    
}


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

int main() {
  int n;
  cin >> n;
  if(n/100 == 7)
    cout << "Yes";
  else if(n/10-n/100*10 == 7)
    cout << "Yes";
  else if(n-n/10*10 == 7)
    cout << "Yes";
  else
    cout << "No";
}

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

int main() {
	int a, b; char op;
	while(1) {
		cin >> a >> op >> b;
		if (op == '?') break;
		else if (op == '+') cout << a + b << endl;
		else if (op == '-') cout << a - b << endl;
		else if (op == '*') cout << a * b << endl;
		else if (op == '/') cout << (int)(a / b) << endl;
	}
	return 0;
}


Measured memory_bytes: 3092
// https://atcoder.jp/contests/abc084/tasks/abc084_d

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <tuple>
#include <vector>
using namespace std;

typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
#define INF (1e9)
#define MOD (1000000007)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOREACH(x, a) for (auto &(x) : (a))
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define LEN(x) (sizeof(x) / sizeof(*(x)))

int dp[100001];
// constexprな素数列挙(エラトステネスの篩)
template <int N> struct calc_prime {
    bool b[N + 1];

    constexpr calc_prime() : b() {
        for (int_fast64_t i = 0; i <= N; ++i)
            b[i] = true;
        b[0] = b[1] = false;
        for (int_fast64_t i = 2; i <= N; ++i) {
            for (int_fast64_t j = i * i; j <= N; j += i)
                b[j] = false;
        }
    }
};
calc_prime<200000> prime;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<int> l(n), r(n);
    REP(i, n) cin >> l[i] >> r[i];
    for (int i = 1; i <= 100000; i++) {
        dp[i] = dp[i - 1] + (prime.b[i] & prime.b[(i + 1) / 2]);
    }

    for (int i = 0; i < n; i++) {
        cout << dp[r[i]] - dp[l[i] - 1] << endl;
    }

    return 0;
}

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

int main(){
  int h,w,d; cin>>h>>w>>d;
  vector<pair<int,int>> num(h*w+1);
  num[0]=pair<int,int>(0,0);
  for(int y=1;y<=h;y++){
    for(int x=1;x<=w;x++){
      int a; cin>>a;
      num[a]=pair<int,int>(x,y);
    }
  }
  vector<int> sum(h*w+1,0);
  for(int i=0;i<d;i++){
    for(int j=1;j*d+i<=h*w;j++){
      int now=j*d+i;
      sum[now]=sum[now-d]+abs(num[now].first-num[now-d].first)+abs(num[now].second-num[now-d].second);
    }
  }
  int q; cin>>q;
  for(int i=0;i<q;i++){
    int l,r; cin>>l>>r;
    cout<<sum[r]-sum[l]<<endl;
  }
}

Measured memory_bytes: 2176
n=int(input())
a=list(map(int,input().split()))
mod=10**9+7
ans=0
d=1
for i in range(61):
  s=0
  for j in a:
    s+=(j>>i)&1
  ans+=s*(n-s)*d%mod
  ans%=mod
  d*=2
  d%=mod
print(ans)

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

// a,bは最大10^100
int main(){
    long double a, b;
    cin >> a >> b;
    if(a>b){
        cout << "GREATER" << endl;
    }
    else if (a<b){
        cout << "LESS" << endl;
    }
    else{
        cout << "EQUAL" << endl;
    }
    
    
}

Measured memory_bytes: 256