akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
#include <cmath>

#define fi first
#define se second
#define all(x) x.begin(), x.end()
using namespace std;
using ull = unsigned long long;
using ll = long long;
constexpr int I_INF = INT_MAX;
constexpr ll L_INF = LLONG_MAX;

struct __INIT {
    __INIT() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(15);
    }
} __init;

int main() {
    int N, M;
    cin >> N >> M;
    vector<vector<int>> S(M);
    for (int i = 0; i < M; i++) {
        int k;
        cin >> k;
        S[i].resize(k);
        for (int j = 0; j < k; j++){cin >> S[i][j];S[i][j]--;}
    }
    vector<int> P(M);
    for (int i = 0; i < M; i++) cin >> P[i];

    ll sum = 0;
    for (int bit = 0; bit < (1 << N); bit++) {
        bool exist = true;
        for (int i = 0; i < M; i++) {
            int on = 0;
            for (int j : S[i]) {
                if (bit & (1 << j)) on++;
            }
            if (on % 2 != P[i]) {
                exist = false;
                break;
            }
        }
        if(exist) sum++;
    }
    cout << sum << endl;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(){
  int N,T,t1,t2;
  scanf("%d%d",&N,&T);
  long sum=0;
  scanf("%d",&t1);
  for (int i = 1; i < N; i++)
  {
    scanf("%d",&t2);
    if ((t2-t1)<=T)
    {
      sum+=t2-t1;
    }else
    {
      sum+=T;
    }
    t1=t2;
  }
  sum+=T;

  printf("%ld",sum);

  return 0;
}

Measured memory_bytes: 1720
#!/usr/bin/env python
import bisect
from collections import defaultdict

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

    S1 = 0
    S2 = sum(Ws)
    min_diff = S2
    for i in range(len(Ws)-1):
        S1 += Ws[i]
        S2 -= Ws[i]
        diff = S2 - S1
        diff = diff if diff >= 0 else -diff
        if diff < min_diff:
            min_diff = diff
    print(min_diff)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3444
#include<iostream>
#include<algorithm>
#include<vector> 
#define MAX 500001
using namespace std;
void Max_Heap(vector<long int> &max_heap,int i){
    long int l = i * 2;
    long int r = i * 2 + 1;
    long int largest;
    if(l<max_heap.size() && max_heap[i]<max_heap[l]){
        largest = l;
    }else{
        largest = i;
    }
    if(r<max_heap.size() && max_heap[largest]<max_heap[r]){
        largest = r;
    }
    if(largest != i){
        swap(max_heap[i],max_heap[largest]);
        Max_Heap(max_heap,largest);
    }
}
int main(void){
    int n;
    cin >> n;
    vector<long int> max_heap;
    vector<long int> &r_max_heap = max_heap;
    max_heap.push_back(0);
    for(int i=1;i<=n;i++){
        long int a;
        cin >> a;
        max_heap.push_back(a);
        //cout << ' ' << r_max_heap[i];
    }
    for(int i=n/2;i>=1;i--){
        Max_Heap(r_max_heap,i);
    }
    for(int i=1;i<=n;i++){
        cout << ' ' << max_heap[i];
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 6960
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <sstream>

#include <array>
#include <string>
#include <cstring>
#include <cmath>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <list>

#include <algorithm>
#include <numeric>

#include <cstdint>
#include <cctype>
#include <cmath>
#include <cassert>
#include <ctime>
#include <chrono>
#include <climits>
#include <fstream>
#include <ios>

#include <iterator>
#include <utility>
#include <complex>
#include <memory>

using namespace std;

//#define MY_DEBUG

#define DESYNC_IO


#ifdef MY_DEBUG
#define DEBUG_STDERR(x) cerr << x << endl;
#else
#define DEBUG_STDERR(x)
#endif // MY_DEBUG


void Solve() {
    int n;
    cin >> n;
    int t, a;
    cin >> t >> a;
    vector<int> h(n);
    for (int i = 0; i < n; ++i) {
        cin >> h[i];
    }
    double res{ t - h[0] * 0.006 };
    int ind{ 1 };
    for (int i = 1; i < n; ++i) {
        double temp{t - h[i] * 0.006};
        if (abs(temp - a) < abs(res - a)) {
            res = temp;
            ind = i + 1;
        }
    }
    cout << ind;
}

void Run() {
#ifdef MY_DEBUG
    chrono::high_resolution_clock::time_point start{ chrono::high_resolution_clock::now() };
#endif // MY_DEBUG

#ifdef DESYNC_IO
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
#endif // DESYNC_IO

#ifdef MY_DEBUG
    ifstream input{ "input.txt" };
    cin.rdbuf(input.rdbuf());
#endif // MY_DEBUG

    Solve();

#ifdef MY_DEBUG
    auto dt{ std::chrono::high_resolution_clock::now() - start };
    auto dt_millisec{ std::chrono::duration_cast<std::chrono::milliseconds>(dt) };
#endif // MY_DEBUG
    DEBUG_STDERR("\ntime spent: " << dt_millisec.count() << " miilliseconds");
}

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
static const double pi = 3.141592653589793;
#define MOD 1000000007
#define INF 10000000000000


signed main(){
  int u,k,id;
  cin>>u;
  vector<vector<int> > v(u,vector<int>(0));
  rep(i,u){
    cin>>id>>k;
      rep(j,k){
        int t;cin>>t;
        v[id-1].push_back(t);
  }
}
queue<int>q;
q.push(1);
vector<int>ans(u);
rep(i,u){ans[i]=-1;}
ans[0]=0;
int f;
while(!q.empty()){
  f=q.front();
  q.pop();
  rep(i,v[f-1].size()){
    if(ans[v[f-1][i]-1]<0){
    ans[v[f-1][i]-1]=ans[f-1]+1;
    q.push(v[f-1][i]);
  }
  }
}
  rep(i,u){
    cout<<i+1<<' '<<ans[i]<<endl;
  }
}



Measured memory_bytes: 3096
def resolve():
    # 整数 1 つ
    n = str(input())
    # 整数複数個
    # a, b = map(int, input().split())
    # 整数 N 個 (改行区切り)
    # N = [int(input()) for i in range(N)]
    # 整数 N 個 (スペース区切り)
    # N = list(map(int, input().split()))
    # 整数 (縦 H 横 W の行列)
    # A = [list(map(int, input().split())) for i in range(H)]

    if n[-1] == "3":
        print("bon")
    elif n[-1] == "0" or n[-1] == "1" or n[-1] == "6" or n[-1] == "8":
        print("pon")
    else:
        print("hon")

 #   print("n")


resolve()

Measured memory_bytes: 61672
s = input().split()
h = int(s[0])
w = int(s[1])
s = []
for i in range(h):
    s.append(input())

for i in range(h):
    row = ''
    for j in range(w):
        cnt = 0
        if s[i][j] == '#':
            row += '#'
            continue
        if i > 0 and j > 0 and s[i-1][j-1] == '#':
            cnt += 1
        if i > 0 and s[i-1][j] == '#':
            cnt += 1
        if i > 0 and j < w - 1 and s[i-1][j+1] == '#':
            cnt += 1
        if j > 0 and s[i][j-1] == '#':
            cnt += 1
        if j < w - 1 and s[i][j+1] == '#':
            cnt += 1
        if i < h - 1 and j > 0 and s[i+1][j-1] == '#':
            cnt += 1
        if i < h - 1 and s[i+1][j] == '#':
            cnt += 1
        if  i < h - 1 and j < w - 1 and s[i+1][j+1] == '#':
            cnt += 1
        row += str(cnt)
    print(row)


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

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using pll = pair<ll,ll>;

#define INF (1LL << 60)
#define MOD 1000000007
#define PI 3.14159265358979323846

#define REP(i,m,n) for(ll (i)=(m),(i_len)=(n);(i)<(i_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define REV(x) reverse(ALL((x)))
#define ASC(x) sort(ALL((x)))
#define DESC(x) ASC((x)); REV((x))
#define pb push_back
#define eb emplace_back

int main()
{
    ll N;
    string S;
    cin >> N >> S;

    ll ans = 1;
    vec A(26, 1);
    REP(i,0,N) ++A[S[i]-'a'];
    REP(i,0,26) ans = (ans * A[i]) % MOD;
    PR((ans-1+MOD)%MOD);

    return 0;
}

/*



*/

Measured memory_bytes: 3752
#include <stdio.h>

int main(void)
{
	double num1, num2, remainder, numerator, denominator;
	double gcd, lcm;
	
	while(scanf("%lf %lf\n", &num1, &num2) == 2) {
		if (num1 > num2) {
			numerator = num1;
			denominator = num2;
		} else {
			numerator = num2;
			denominator = num1;
		}
		remainder = fmod(numerator,denominator);
		while(!(fabs(remainder) < 0.00001)) {
			numerator = denominator;
			denominator = remainder;
			remainder = fmod(numerator,denominator);
		}
		gcd = denominator;
		lcm = num1 / gcd * num2;

		printf("%.0lf %.0lf\n", gcd, lcm);
	}
	return 0;
}

Measured memory_bytes: 648
#入力
n, m = map(int, input().split())
itv = []
for i in range(m):
    a, b = map(int, input().split())
    itv.append([b,a])
itv.sort()

cut = 0
ans = 0
for i in range(m):
    if itv[i][1] <= cut:
        i = i + 1
    else:
        cut = itv[i][0] - 1
        ans = ans + 1
        i = i + 1
        
print(ans)

Measured memory_bytes: 58712
#include <iostream>
#include <vector>
#include <queue>
static const int MAX=100000;
using namespace std;

vector<int> follow[MAX];
int color[MAX];  //-1 represent No Visited

void bfs(int i,int c)
{
    queue<int> Q;
    Q.push(i);color[i]=c;
    while(!Q.empty())
    {
        int p=Q.front();Q.pop();
        for(int j=0;j<follow[p].size();j++)
        {
            if(color[follow[p][j]]!=-1) continue;
            //else
            Q.push(follow[p][j]); color[follow[p][j]]=color[p];
        }
    }
}

int main()
{
   int n,m;
   cin>>n>>m;
   for(int i=0;i<n;i++) color[i]=-1;
   for(int i=0;i<m;i++)
   {
       int a,b;
       cin>>a>>b;
       follow[a].push_back(b);
       follow[b].push_back(a);
   }
   int c=0;
   for(int i=0;i<n;i++)
   {
       if(color[i]==-1)
       {
           bfs(i, c);
           c++;
       }
   }
   int order_num;cin>>order_num;
   for(int i=0;i< order_num;i++)
   {
       int a,b;
       cin>>a>>b;
       if(color[a]==color[b]) cout<<"yes"<<endl;
       else cout<<"no"<<endl;
   }
}

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

int main() {
    long long n, ret = 0, t = 0;
    std::cin >> n;
    // std::vector<long long> a(n + 1);
    std::map<long long, long long> m;
    m[t]++;
    for (int i = 0; i < n; i++) {
        long long t2;
        std::cin >> t2;
        t += t2;
        m[t]++;
    }
    for (auto el : m) ret += el.second * (el.second - 1) / 2;
    std::cout << ret << std::endl;
    return 0;
}

Measured memory_bytes: 12800
#include<bits/stdc++.h>
using namespace std;
#define TRACE
 
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

#define ll long long
#define pb push_back
#define mb make_pair
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const int mod = 1e9+7;
int dp[2][100010];
int p[100010];
int main(){
	IOS;
	int n,k ;  cin >> n >> k;
	
	int a[n];
	for(int i=0;i<n;i++)
		cin >> a[i];
	memset(dp,0,sizeof(dp));
	dp[0][0]=1;
	dp[1][0]=1;
	int r = 0;
	memset(p,0,sizeof(p));
	for(int i = 0 ; i < n; i++ ){
		p[0] = 0 ;
		for(int j = 1; j <= k+1 ; j++)
			p[j] = (dp[1-r][j-1] + p[j-1])%mod;
		for(int j = 1 ; j <= k ; j++)
			dp[r][j] = (p[j+1] - p[max(0,j-a[i])]+mod)%mod ;
		r^=1;
	}
	cout <<	dp[1-r][k];

	


	return 0;
}




Measured memory_bytes: 1408
def floor_sum(n, m, a, b)
  res = 0

  if a >= m
    res += (n - 1) * n * (a / m) / 2
    a %= m
  end

  if b >= m
    res += n * (b / m)
    b %= m
  end
  
  y_max = (a * n + b) / m
  x_max = (y_max * m - b)
  
  return res if y_max == 0
  
  res += (n - (x_max + a - 1) / a) * y_max
  res += floor_sum(y_max, a, m, (a - x_max % a) % a)
  res
end

t = gets.to_s.to_i

ans = []
t.times do
  n, m, a, b = gets.split.map { |e| e.to_i }
  ans << floor_sum(n, m, a, b)
end

puts ans

Measured memory_bytes: 15064
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.ArrayList;

public class Main {
    public static void main(String[] args) throws IOException {
        try (PrintWriter writer = new PrintWriter(System.out); InputReader reader = new InputReader(System.in)) {
            int n = reader.readInt();
            int[] x = reader.readIntsSplitByDelimiter(" ");
            int[] sorted = new int[n];

            for (int i = 0; i < n; i++) {
                sorted[i] = x[i];
            }
            Arrays.sort(sorted);

            int half2 = sorted[n / 2 - 1];
            int half3 = sorted[n / 2];

            // System.out.println(half2 + " h2");
            // System.out.println(half3 + " h3");
            for (int i = 0; i < n; i++) {
                // System.out.println(x[i] + "aa");
                if (half2 == half3) {
                    System.out.println(half2);
                } else if (x[i] < half3) {
                    System.out.println(half3);
                } else if (x[i] > half2) {
                    System.out.println(half2);
                }
            }
        }
    }
}

class InputReader implements Closeable, AutoCloseable {
    private final BufferedReader br;

    InputReader(InputStream inputStream) {
        this.br = new BufferedReader(new InputStreamReader(inputStream));
    }

    String readLine() throws IOException {
        return this.br.readLine();
    }

    int readInt() throws IOException {
        return Integer.parseInt(this.br.readLine());
    }

    long readLong() throws IOException {
        return Long.parseLong(this.br.readLine());
    }

    String[] readStringsSplitByDelimiter(String delimiter) throws IOException {
        return this.br.readLine().split(delimiter);
    }

    int[] readIntsSplitByDelimiter(String delimiter) throws IOException {
        String[] strings = this.br.readLine().split(delimiter);

        int stringsLength = strings.length;
        int[] ints = new int[stringsLength];
        for (int i = 0; i < stringsLength; i++) {
            ints[i] = Integer.parseInt(strings[i]);
        }

        return ints;
    }

    long[] readLongsSplitByDelimiter(String delimiter) throws IOException {
        String[] strings = this.br.readLine().split(delimiter);

        int stringsLength = strings.length;
        long[] longs = new long[stringsLength];
        for (int i = 0; i < stringsLength; i++) {
            longs[i] = Long.parseLong(strings[i]);
        }

        return longs;
    }

    @Override
    public void close() throws IOException {
        br.close();
    }
}

Measured memory_bytes: 84808
#include<stdio.h>
#include <stdlib.h>
#include<string.h>
#include<math.h>
#define loop(i, l, r) for(i=l; i<r; i++)/*Instead of function, (for).*/
#define rep(i,r) for(i=0; i<r; i++)
#define Max(a, b) ((a) > (b) ? (a) : (b))
#define Min(a, b) ((a) < (b) ? (a) : (b))
typedef long long int lli;
/*Return Combination ,(nCr)*/
int combi(int n, int r)
{
	if(r==0 || r==n) return 1;
	else return combi(n-1,r) + combi(n-1,r-1);
}
/*Return gcd(a, b)*/
int gcd(int a, int b){
	if(b == 0) return a;
	else return gcd(b, a % b);
}
int main(void)
{
	int n, i, cut=0;
	scanf("%d", &n);
	char s[n];
	scanf("%s", s);
	rep(i,n-2){
		if(s[i] =='A' && s[i+1] == 'B' && s[i+2] == 'C'){
			cut++;
		}
	}
	printf("%d", cut);
	return 0;
}

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

#define pi 3.141592654
#define fix(n) cout << fixed << setprecision(n)

#define rep(i,a,b) for(int i=a;i<b;i++)
#define ren(i,a,b) for(int i=a;i>=b;i--)

#define si(d)  scanf("%d",&d)
#define sll(d) scanf("%lld",&d)
#define pin(d) printf("%d\n",d)
#define pln(d) printf("%lld\n",d)
#define nl 	   printf("\n")

#define ll long long
#define ull unsigned long long

#define mp make_pair
#define pb push_back
#define fi first
#define se second

#define vi vector<int>
#define pii pair<int,int> 
#define piii pair<pair<int,int>,int> 
#define all(v) v.begin(), v.end()

#define chalne_de continue
int mod=1000000007;
const int N = 1000005;

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

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int n;
	cin >> n;
	ll a[n+1], pre[n+1];
	rep(i,0,n)
	{
		cin >> a[i];
		if ( i == 0)
			pre[i] = a[i];
		else
			pre[i] = pre[i-1] + a[i];
	}
	ll suf[n+1];
	for ( int i = n - 1; i >= 0; i--)
	{
		if ( i == n - 1)
			suf[i] = a[i];
		else
			suf[i] = suf[i+1] + a[i];
	}
	ll ans = 1e18;
	for ( int i = 0 ; i < n - 1; i++)
	{
		ll x = abs(pre[i] - suf[i+1] );
		ans = min(ans,x);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 4992
(defun coins ()
  (let ((a (read))
        (b (read))
        (c (read))
        (x (read))
        (ans 0))
    (dotimes (i (1+ a))
      (dotimes (j (1+ b))
        (dotimes (k (1+ c))
          (if (= x (+ (* 500 i) (* 100 j) (* 50 k)))
              (incf ans)))))
    ans))


(format t "~D~%" (coins))

Measured memory_bytes: 27108
#include <iostream>
#include <cstdint>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

int abs( int a ) { return a < 0 ? -a : a; }

int main() {
	int a, b;
	cin >> a >> b;
	if ( a < 13 ) b /= 2;
	if ( a < 6 ) b = 0;
	cout << b << endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#define N 100

int main(){
  int n,i,j;
  int tmp,key;
  int A[N];
  
  scanf("%d",&n);
  for(i=0 ; i<n ; i++) scanf("%d",&A[i]);

  for(i=1 ; i<=n ; i++){
    for(j=0 ; j<n-1 ; j++){
      printf("%d ",A[j]);
    }
    printf("%d",A[n-1]);
    printf("\n");
    
    key = A[i];
    j = i - 1;
    while(j>=0 && key<A[j]){
      A[j+1] = A[j];
      j--;
    }
    A[j+1] = key;
  }
  return 0;
}

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

using namespace std;
const int N = 2e5 + 5, LOG = 30;
int A[N], B[N], cnt[N], f[N], w[N], n;
bool a[N], b[N];

void Check() {
    int curr = 0;
    for (int i = 2; i <= n; i ++) {
        while (curr && b[curr] != b[i - 1]) curr = f[curr];
        if (b[curr] == b[i - 1]) curr++;
        f[i] = curr;
    }
    curr = 0;
    for (int i = 1; i <= n; i++) {
        while (curr && b[curr] != a[i - 1]) curr = f[curr];
        if (b[curr] == a[i - 1]) curr++;
    }
    memset(w, 0, sizeof w);
    while (curr) w[curr] = 1, curr = f[curr];
    w[0] = 1;
    for (int i = 2; i <= n; i ++) {
        while (curr && a[curr] != a[i - 1]) curr = f[curr];
        if (a[curr] == a[i - 1]) curr++;
        f[i] = curr;
    }
    curr = 0;
    for (int i = 1; i <= n; i++) {
        while (curr && a[curr] != b[i - 1]) curr = f[curr];
        if (a[curr] == b[i - 1]) curr++;
    }
    while (curr) {
        if (w[n - curr] == 1) cnt[curr]++;
        curr = f[curr];
    }
    if (w[n] == 1) cnt[0]++;
}

int main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin >> n;
    for (int i = 0; i < n; i++) cin >> A[i];
    for (int i = 0; i < n; i++) cin >> B[i];
    for (int j = 0; j < LOG; j++) {
        for (int i = 0; i < n; i++) a[i] = (A[i]>>j)&1, b[i] = (B[i]>>j)&1;
        Check();
        for (int i = 0; i < n; i++) a[i] ^= 1;
        Check();
    }
    for (int i = 0; i < n; i++) if (cnt[i] == LOG) cout << i << " " << (A[i]^B[0]) << "\n";
    return 0;
}


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

using namespace std;
using namespace std;
#define rep(i,n) for(long long i=0; i<(long long)(n);i++)
//rep…「0からn-1まで」の繰り返し
#define rep2(i,s,n) for(long long i=s; i<=(long long)(n);i++)
//rep2…「sからnまで」の繰り返し
#define repr(i,s,n) for(long long i=s;i>=(long long)(n);i--)
//repr…「ｓからnまで」の降順の繰り返し

typedef long long ll;

const ll inf = 1e9+7;
const ll mod = 1e9+7;

int main(){
    ll q,h,s,d,n;
    cin>>q>>h>>s>>d>>n;

    cout<<(n/2)*min({q*8,h*4,s*2,d})+(n%2)*
          min({q*4,h*2,s})<<endl;
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<map>

int h,w;
char m[500][500];

void dfs(int y, int x, int &bb, int &ww, char c) {
    if(!(0 <= x && x < w)) return;
    if(!(0 <= y && y < h)) return;
    if(m[y][x] != c) return;
    m[y][x] = '!';
    char ic = c == '#' ? '.' : '#';

    c == '#' ? bb++ : ww++;

    dfs(y+1, x, bb, ww, ic);
    dfs(y-1, x, bb, ww, ic);
    dfs(y, x+1, bb, ww, ic);
    dfs(y, x-1, bb, ww, ic);
    return;
}

int main(void) {
    scanf("%d%d",&h,&w);
    for(int i=0; i<h; i++)
        scanf("%s", m[i]);

    long long int r = 0;
    for(int i=0; i<h; i++)
        for(int j=0; j<w; j++) {
            int bb=0, ww=0;
            dfs(i, j, bb, ww, '.');
            dfs(i, j, bb, ww, '#');
            r += 1ULL*bb*ww;
        }

    printf("%lld\n", r);
}


Measured memory_bytes: 7808
use std::io::*;
use std::collections::BTreeSet;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

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

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

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

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

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

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

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

fn abc(n: usize, w: Vec<Vec<char>>) -> String {
    let mut res = true;
    if w.iter().collect::<BTreeSet<_>>().len() != n {
        res = false;
    }
    for i in 0..n-1 {
        if w[i].last() != w[i+1].first() {
            res = false;
        } 
    }
    return if res {"Yes".to_string()} else {"No".to_string()}
}

fn main() {
    /*
    assert_eq!(abc(), "Yes");
    assert_eq!(abc(101), "No");
    assert_eq!(abc(999999999), "Yes");
    */
    input!{
        n: usize,
        w: [chars; n],
    }
    let result = abc(n, w);
    println!("{}", result)
}



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

int main(void)
{
  char contest[3];
  
  scanf("%s",&contest);
  
  if(strcmp(contest,"ABC") == 0)
  {
    printf("ARC\n");
  }
  else if(strcmp(contest,"ARC") == 0)
  {
    printf("ABC\n");
  }
  else
  {
    
  }
  
  return 0;
}

Measured memory_bytes: 1660
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();

		if(a > b+b){
			System.out.println(a-(b+b));
		}else{
			System.out.println(0);
		}

	}

}

Measured memory_bytes: 23892
import math
a, b, x = map(int, input().split())

S = x / a
half = a * b / 2

if S > half:
  S = a * b - S
  y = math.atan(2*S/(a*a))
else:
  y = math.atan(b*b/(2*S))

print(math.degrees(y))


Measured memory_bytes: 2940
#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-1); i >= 0; --i)

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

const int MAX = 1e6 + 5;
const int INF = 1001001001;
const int MOD = 1000000007;

int main(){
    string s;
    cin >> s;

    if (s.size() % 2 != 0) {
        puts("No");
        return 0;
    }

    rep(i, s.size() / 2) {
        if (s[i*2] != 'h' || s[i*2+1] != 'i') {
            puts("No");
            return 0;
        }
    }
    puts("Yes");
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
  int a, b;
  int area, peri;
  scanf("%d", &a); scanf("%d", &b);
  area = a * b;
  peri = (2 * a) + (2 * b);
  printf("%d %d\n", area, peri);

  return 0;
}



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

struct Node{
  int key;
  struct Node *right,*left,*parent;
};

typedef struct Node node;

node *NIL;
node *root;

void insert(int k);
void inorder(node *p);
void preorder(node *p);



int main(void)
{
  int m,k;
  int i;
  char com[100];

  scanf("%d",&m);

  for(i = 0;i < m;i++){
    scanf("%s",com);
    if(strcmp(com,"insert") == 0){
      scanf("%d",&k);
      insert(k);
    } else if(strcmp(com,"print") == 0){
      inorder(root);
      puts("");
      preorder(root);
      puts("");
    }
  }
  return 0;
}
  
   

void insert(int k){
  node *x = root;
  node *y = NIL;
  node *z;

  z = (node *)malloc(sizeof(node));
  
  z->left = NIL;
  z->right = NIL;
  z->key = k;

  while(x != NIL){
    y = x;
    
    if(z->key  <   x->key){
      x = x->left;
    } else {
      x = x->right;
    }
  }

  z->parent = y;

  if(y == NIL){
    root = z;
  }
  if (y != NIL){
    if(y->key  >  z->key){
      y->left = z;
    } else {
      y->right = z;
    }
  }
  
}


void inorder(node *p){
  if(p != NIL){
    inorder(p->left);
    printf(" %d",p->key);
    inorder(p->right);
  } else {
    return;
  }
}


void preorder(node *p){
  if(p != NIL){
    printf(" %d",p->key);
    preorder(p->left);
    preorder(p->right);
  } else {
    return;
  }
}


   



Measured memory_bytes: 25140
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <list>
#include <stack>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#define pye cout << "yes" << endl;
#define pno cout << "no" << endl;
#define pYe cout << "Yes" << endl;
#define pNo cout << "No" << endl;
#define pYE cout << "YES" << endl;
#define pNO cout << "NO" << endl;
#define prin(num) cout << num << endl;
#define max(a, b) ((a)>(b) ? (a):(b))
#define min(a, b) ((a)<(b) ? (a):(b))
#define INF 100000000000
#define MOD 1000000007LL
#define MAX 200005
#define NIL -1
#define WHITE 0
#define BLACK 1
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef map<ll, ll> Map;

ll divi(ll n, ll k) {
    ll res, t;
    t=n/k+(n%k==0 ? 0 : 1);
    res=k*t-n;
    return res;
}

int main(void) {
    ll N;
    cin >> N;
    ll i, a[100000], b[100000];
    
    for(i=N-1; i>=0; i--) {
        cin >> a[i] >> b[i];
    }
    ll ans=0;
    ll t;
    
    for(i=0; i<N; i++) {
        a[i]+=ans;
        t=divi(a[i], b[i]);
        ans+=t;
    }
    
    prin(ans)
}


Measured memory_bytes: 1792
import sys
# input処理を高速化する
input = lambda: sys.stdin.readline().rstrip()

s = input()
K = int(input())

N = len(s)
subst = set()
for i in range(N):
    for j in range(1,K+1):
        subst.add(s[i:min(i+j, N)])
print(sorted(subst)[K-1])

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

#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define RFOR(i, a, b) for(int i=(a); i>=(b); i--)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) RFOR(i, n, 0)
#define dump(x)  cout << #x << " = " << (x) << endl;

typedef long long ll;
typedef pair<int, int> ii;
const ll INF = 1e18;
const int inf = 1e8;

const ll mod = 1000000007;

const int MAX = 510000;
ll fac[MAX], finv[MAX], inv[MAX];

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

ll com(ll n, ll k)
{
  if (n<k) return 0;
  if (n<0 || k<0) return 0;
  return fac[n] * (finv[k] * finv[n-k] % mod) % mod;
}

void solve()
{
  cominit();
  ll N;
  scanf("%lld",&N);
  ll K;
  scanf("%lld",&K);
  ll R = N-K;

  for (ll i=1; i<=K; i++) {
    cout << com(R+1,i)*com(K-1,i-1)%mod << endl;
  }
}

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


Measured memory_bytes: 12160
nums = input()
for i in range(2**3):
  binary=format(i, 'b').zfill(5)[2:]
  val = int(nums[0])
  val_str = nums[0]
  for j in range(1,len(nums)):
    if binary[j-1] == '1':
      val += int(nums[j])
      val_str += '+'+nums[j]
    else:
      val -= int(nums[j])
      val_str += '-'+nums[j]
  if val==7:
    print(val_str,'=7',sep='')
    break


Measured memory_bytes: 3064
import sys
def main():
    N,W=tuple(map(int,sys.stdin.readline().split()))
    w,v=[0],[0]
    for _ in [0]*N:
        wi,vi=tuple(map(int,sys.stdin.readline().split()))
        w.append(wi)
        v.append(vi)
    dp=[[0 for _ in [0]*(W+1)] for _ in [0]*(N+1)]
    for i in range(1,N+1):
        for j in range(1,W+1):
            dp[i][j]=max(dp[i-1][j], dp[i][j-1])
            if w[i]<=j:dp[i][j]=max(dp[i][j],dp[i-1][j-w[i]]+v[i])
    print(dp[N][W])
if __name__=='__main__':main()

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

void swap(int& x, int& y) {
	int temp;
	temp = x;
	x = y;
	y = temp;
}

int GCD(int x, int y) {
	int r;
	if (x%y == 0) { return y; }
	else {
		r = x % y;
		x = y;
		y = r;
		GCD(x, y);
	}
}

int main()
{
	int x, y;
	cin >> x >> y;
	if (x < y)
		swap(x, y);
	int ans = GCD(x, y);
	cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3108
# -*- coding: utf-8 -*-

def solve(N, A, B):
    loop = N // (A + B)
    delta = N % (A + B)
    return A * loop + min(delta, A)


def main():
    N, A, B = [int(n) for n in input().split()]
    print(solve(N, A, B))


if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
#include<iostream>
using namespace std;
int main(void)
{
	int a,b;
	cin>>a>>b;
	if(a+b>=a-b && a+b>=a*b) cout<<a+b<<endl;
	else if(a-b>=a+b && a-b>=a*b) cout<<a-b<<endl;
	else cout<<a*b<<endl;
	return 0;
}

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

int main(){
	int n;
	while(cin>>n and n>0){
		int a[n+1]={},ans=0;
		a[1]=1;
		for(int i=2;i<n;i++) a[i]=a[i-1]+i;
		for(int i=0;i<n-1;i++){
			for(int j=i+1;j<n;j++){
				if(a[j]-a[i]==n) ans++;
			}
		}
		cout<<ans<<endl;
	}
	return 0;
}



Measured memory_bytes: 2996
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
ll a,b;
int main(){
	int c,d; cin >> c >> d;
	a = c / __gcd(c,d);
	b = d;
	cout<< a*b <<endl;
}

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

#define rep(i,n) for(int i=0;i<(n);i++)

typedef long long ll;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)

#define INF 1000000000

#define PB push_back
#define MP make_pair
#define F first
#define S second
int main()
{
    int h,w,k;
    cin>>h>>w>>k;
    vector<string> s(h);
    vector<int> H(h),W(w);
    for(int i=0;i<h;i++)
    {
        cin>>s[i];
    }
     int ans=0;
     rep(is,1<<h)rep(js,1<<w){
         int cnt=0;
         rep(i,h)rep(j,w){
         if(is>>i&1)continue;
         if(js>>j&1)continue;
         if(s[i][j]=='#')cnt++;
     }
     if(cnt==k)
        ans++;
     }
     cout<<ans<<endl;
     return 0;

}


Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define pb push_back
#define fi first
#define se second
const int N = 3e6+6;
const int mod = 1e9+7;
const int inf = 1e8;
void solve(){
    int x = 0;
    int mx = 0;
    int n;
    cin>>n;
    string s;
    cin>>s;
    for(int i=0;i<n;i++){
        if(s[i]=='I')x++;
        else x--;
        mx = max(x,mx);
    }
    cout<<mx<<endl;
}
int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t=1;
//    cin>>t;
    while(t--)solve();
    return 0;
}


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

int main(void) {
    int n;
    cin >> n;
    long long a = 2, b = 1, c = 1;
    for (int i = 2; i <= n; i++) {
        c = b + a;
        a = b;
        b = c;
    }
    cout << c << endl;
    return 0;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 1e18
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define pb push_back
#define ff first
#define ss second
#define vll vector<ll>
#define pii pair<ll,ll>
#define sz(v) (v).size()
#define srt(v) sort(v.begin(),v.end())
#define ull unsigned long long
#define tell(a) cout<<a<<" "
#define el cout<<endl
#define rev(v) reverse(v.begin(),v.end())
#define rep(i,a,n) for(int i=a;i<n;i++)
#define M 1000000007
ll power(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()
{
	IOS;
	ll n;
	cin>>n;
	vector<int>v[n+1];
	rep(i,0,n)
	{
		int x;
		cin>>x;
		v[x].pb(i);
	}
	if(v[1].size()==0)
	{
		return cout<<-1,0;
	}
	int ind=v[1][0],count=1;
	for(int i=2;i<=n;i++)
	{
		int pos=lower_bound(v[i].begin(),v[i].end(),ind+1)-v[i].begin();
		if(pos==v[i].size())
		break;
		ind=v[i][pos];
		count++;
	}
	cout<<n-count;
}



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

using namespace std;

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vd = vector<double>;
using vs = vector<string>;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int N;
    cin >> N;
    vll A(N);
    for(int i=0;i<N;i++) cin >> A[i];

    vll dprow(N+1, 0);
    vvll dp(N+1, dprow);
    for(int w=1;w<=N;w++) {
        for(int i=0;i<=N-w;i++) {
            dp[i][i+w] = max(A[i] - dp[i+1][i+w],
                             A[i+w-1] - dp[i][i+w-1]);
        }
    }

    cout << dp[0][N] << endl;

    return 0;
}

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

int main(){
	int X,Y,Z,K;
	cin >> X >> Y >> Z >> K;
	vector<long long> A(X);
	vector<long long> B(Y);
	vector<long long> C(Z);
	for(auto &k:A)cin >> k;
	for(auto &k:B)cin >> k;
	for(auto &k:C)cin >> k;
	
	sort(A.begin(),A.end(),greater<long long>());
	sort(B.begin(),B.end(),greater<long long>());
	sort(C.begin(),C.end(),greater<long long>());
	
	vector<long long> AB;
	for(int i=0;i<X;i++){
		for(int j=0;j<Y;j++){
			AB.push_back(A[i]+B[j]);
		}
	}
	
	sort(AB.begin(),AB.end(),greater<long long>());
	
	if(X*Y>K)AB.erase(AB.begin()+K,AB.begin()+(X*Y));
	
	vector<long long> ABC;
	for(auto k:AB){
		for(int i=0;i<Z;i++){
			ABC.push_back(k+C[i]);
		}
	}
	
	sort(ABC.begin(),ABC.end(),greater<long long>());
	
	for(int i=0;i<K;i++)cout << ABC[i] << endl;
	
	return 0;
}

Measured memory_bytes: 43112
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef pair<int, int> pii;
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define vv(type, c, m, n, i) vector<vector<type>> c(m, vector<type>(n, i))
#define mat(type, c, m, n) vector<vector<type>> c(m, vector<type>(n));for(auto& r:c)for(auto& i:r)cin>>i;
#define rep(i,a,n) for(int i=(a), i##_len=(n); i<i##_len; ++i)
#define rrep(i,a,n) for(int i=(a), i##_len=(n); i>i##_len; --i)
#define each(x,y) for(auto &(x):(y))
#define var(type, ...)type __VA_ARGS__;Scan(__VA_ARGS__);
template<typename T> void Scan(T& t) { cin >> t; }
template<typename First, typename...Rest>void Scan(First& first, Rest&...rest) { cin >> first; Scan(rest...); }
#define vec(type, c, n) vector<type> c(n);for(auto& i:c) cin>>i;
#define len(x) ((int)(x).size())
#define mp make_pair
#define eb emplace_back
#define em emplace
#define pb pop_back
#define fi first
#define se second
#define get(a, i) get<i>(a)
#define bit_count __builtin_popcount
#define mt make_tuple
inline string zero(int a,string s,char c='0'){return string(a-len(s),c)+s;}
inline string zero(int a,int t,char c='0'){return zero(a, to_string(t), c);}
inline string zero(int a,ll t,char c='0'){return zero(a, to_string(t), c);}
#define mini min_element
#define maxi max_element
#define sum accumulate
#define chmax(a,b) if(a<b)a=b
#define chmin(a,b) if(a>b)a=b
template <class T> inline void print(T t){cout << t << '\n';}
template <class H, class... T> inline void print(H h, T... t){cout << h << " ";print(t...);}
int main() {
	var(ll, n);
	int ans = 0;
	while (n >= 10) {
		if (n != 9) {
			n -= 9;
		}
		ans += 9;
		n /= 10;
	}
	print(ans + n);
	return 0;
}


Measured memory_bytes: 256
X, Y = map(int, input().split())

def main(X, Y):
  if Y % 2 == 1:
    print("No")
    return
  if X*2 > Y:
    print("No")
    return
  if X*4 < Y:
    print("No")
    return
  
  print("Yes")

main(X, Y)

Measured memory_bytes: 9172
l = input().split()
m = int(l[0])
d = str(l[1])
cnt = 0 
for i in range(1, m+1):
  for j in range(22, int(d)+1):
    j = str(j)
    d10 = int(j[0])
    d1 = int(j[1])
    if i == d10 * d1 and d10 >= 2 and d1 >= 2:
      cnt += 1

print(cnt)

Measured memory_bytes: 3064
/*

*/
#include<bits/stdc++.h>

using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,a,n) for(int i=(a);i<(n);i++)
#define repe(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
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; }

int main(){
  cin.tie(nullptr);ios_base::sync_with_stdio(false);
  int n;cin>>n;
  int a,cnt=0;
  rep2(i,1,n+1){
    cin>>a;
    if(i%2==1&&a%2==1){
      //cout<<i<<" "<<a<<endl;
      cnt++;
    }
  }
  cout<<cnt<<endl;
}

Measured memory_bytes: 3572
#include <stdio.h>

typedef struct{
char name[10];
int time;
} process;

int main(){
int n,p,i=0,q;
int cnt=0,sum=0;
process Q[1000000];

scanf("%d%d",&n,&q);

for(i=0;i<n;i++){
scanf("%s%d",Q[i].name,&Q[i].time);
}
for(i=0;i<n;i++){
    Q[i].time -= q;

    if(Q[i].time <= 0){
        sum += Q[i].time + q;
        printf("%s %d\n",Q[i].name,sum);
    }
    else{
        Q[n] = Q[i];
        sum += q;
        n++;

    }

}
return 0;
}





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

#define fast ios::sync_with_stdio(0); cin.tie(NULL); 
#define fi first
#define se second
#define mp make_pair
#define pi 3.14159265359
#define MOD 1000000007
#define inf (ll)1e18
#define setbits(x) __builtin_popcountll(x)
typedef long long ll;
#define mp make_pair
#define ALL(v) v.begin(), v.end() 
#define F(i,s,n) for(i=s;i<n;++i)
#define pb push_back
#define tin freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define pll pair<ll,ll>
ll max(ll a,ll b)
{
    return a*(a>=b)+b*(b>a);
}
/*---------------------------------------------------------*/
ll n,w;vector<ll>we,va;
vector<vector<ll>>dp;
ll fun(ll i,ll v)
{
    if(v==0)return 0;
    if(i==-1)return inf;
    if(dp[i][v]!=-1)return dp[i][v];
    if(va[i]>v)return dp[i][v]=fun(i-1,v);
    return dp[i][v]=min(fun(i-1,v),we[i]+fun(i-1,v-va[i]));
}
void solve()
{
   cin>>n>>w;ll sum=0;
   we.resize(n);va.resize(n);
    for(ll i=0;i<n;++i)
    {
        cin>>we[i]>>va[i];sum+=va[i];
    }ll o;//cout<<"sum "<<sum<<endl;
    dp.resize(102,vector<ll>(sum+1,-1));
    for(ll i=sum;i>=0;--i)
    {
        o=fun(n-1,i);
       //cout<<o<<endl;
        if(o<=w){cout<<i;break;}
    }
}

int main()
{
    //tin
    fast
   
    ll tc=1;//cin>>tc;
   for(ll i=1;i<=tc;++i)
   {
    //cout<<"Case #"<<i<<": ";
    solve();
    if(i!=tc)cout<<"\n";
   }//*/cout<<inf;
return 0;
}
//End-Cases
//Precomputation
//Segmentation Fault
//Complexity
//Break it up
//Sub Problems


Measured memory_bytes: 83956
#include<stdio.h>
int main(void)
{
	int a,b,c,d,s,k;
	scanf("%d",&a);
	scanf("%d",&b);
	scanf("%d",&c);
	scanf("%d",&d);
	s=a*b;
	k=c*d;
	if(s>k)	{
		printf("%d\n",s);
	}
	else	{
		printf("%d\n",k);
	}
	return 0;
}

Measured memory_bytes: 128
N=int(input())
M=[]
A=[]
R=[]
C=[]
H=[]
for i in range(N):
  s=input()
  if s[0]=='M':
    M.append(s)
  elif s[0]=='A':
    A.append(s)
  elif s[0]=='R':
    R.append(s)
  elif s[0]=='C':
    C.append(s)
  elif s[0]=='H':
    H.append(s)
cnt=[len(M),len(A),len(R),len(C),len(H)]
res=sum(cnt)
res=int(res*(res-1)*(res-2)/6)

def dif(n):
  if cnt[n]==0 or cnt[n]==1:
    return 0
  else:
    a=0
    for i in range(5):
      if i!=n:
        a+=cnt[i]
  if cnt[n]==2:
    return a
  else:
    b=cnt[n]*(cnt[n]-1)*(cnt[n]-2)/6
    d=cnt[n]*(cnt[n]-1)/2
    d*=a
    return int(d+b)
for i in range(5):
  res-=dif(i)
c=0
for j in range(5):
  if cnt[j]==0:
    c+=1
if c>2:
  print(0)
else:
  print(res)

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

#define REP(i, n) for(ll i = 0; i < n; i++)
#define ALL(x) (x).begin(),(x).end()
#define MSG(x) cout << x << endl;
#define YN(x) x ? cout << "YES" << endl : cout << "NO" << endl;
#define Yn(x) x ? cout << "Yes" << endl : cout << "No" << endl;
#define yn(x) x ? cout << "yes" << endl : cout << "no" << endl;

using namespace std;
using ll = long long;

int main(int argc, char *argv[]) {
    string s;
    cin >> s;

    cout << s.replace(0, 4, "2018") << endl;

    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    private static final long MOD = 1000000007;
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        Long N = input.nextLong();
        Long K = input.nextLong();
        long min, max, sum = 0;
        for (long k = K; k <= N+1; k++) {
            min = k * (k - 1) / 2;
            max = (N * (N + 1) / 2) - ((N - k) * (N - k + 1) / 2);
            sum += max - min + 1;
        }

        System.out.println(sum % MOD);
    }
}


Measured memory_bytes: 35712
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
long long mo = 1e9 + 7;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<class A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}cout << "\n";}

int main(){
    ll N;
    string S;
    cin >> N;
    vector<ll> A(N);
    rep(i,N){
        cin >> A[i];
    }
    map<ll,ll> mp1,mp2;
    rep(i,N){
        mp1[A[i]]++;
        i++;
    }
    rep(i,N){
        i++;
        mp2[A[i]]++;
    }
    ll m1 = 0, m2 = 0;
    vector<Pll> v1,v2;
    for(auto& e:mp1){
        v1.push_back(Pll(e.second, e.first));
    }
    for(auto& e:mp2){
        v2.push_back(Pll(e.second, e.first));
    }
    sort(v1.begin(), v1.end(), greater<Pll>());
    sort(v2.begin(), v2.end(), greater<Pll>());
    ll dec = 0;
    if(v1[0].second != v2[0].second){
        dec = v1[0].first + v2[0].first;
    }else{
        if(N >= 4){
            dec = max(v1[0].first + v2[1].first, v1[1].first + v2[0].first);
        }else{
            dec = 1;
        }
    }

    cout << N - dec << endl;
}

Measured memory_bytes: 9592
#include <bits/stdc++.h>
#include <vector>
#include <cmath>
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP2(i, m, n) for (int i = (m); i < (int)(n); ++i)
#define REPR(i, n) for (int i = (n)-1; i >= 0; --i)
#define REPR2(i, m, n) for (int i = (n)-1; i >= (m); --i)
#define REPx(x, a) for(auto x : a)
#define ALL(a) a.begin(), a.end()
#define SORT(a) sort(ALL(a))
#define SORTR(a) sort(ALL(a), greater<int>())
#define REVERSE(a) reverse(ALL(a))
#define bit_search(bit, n) REP(bit, 1<<(n))
#define bit_check(bit, i) (bit>>(i)) & 1
#define setpre(n) fixed << setprecision((n))
#define UNIQUE(a) do {SORT(a); (a).erase(unique(ALL(a)), (a).end());} while(0)
#define MAX(a) *max_element(ALL(a))
#define MIN(a) *min_element(ALL(a))
#define bisect_left(a, x) lower_bound(ALL(a), (x)) - a.begin()
#define bisect_right(a, x) upper_bound(ALL(a), (x)) - a.begin()
#define INPUT(a) REP(i, a.size()) cin >> a[i];
#define INPUTP(a) REP(i, a.size()) cin >> a[i].first >> a[i].second;
#define ENDL cout << endl;
using namespace std;
using LL = long long;
using LD = long double;
using PII = pair<int, int>;
using VPII = vector<PII>;
using PLL = pair<LL, LL>;
using VPLL = vector<PLL>;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VC = vector<char>;
using VS = vector<string>;
using VB = vector<bool>;
const int INF = 1e9;
const LL MOD = 1e9 + 7;

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 main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  string s;
  cin >> n >> s;
  int R = 0;
  REPx(x, s) if (x == 'R') R++;
  if (R > n/2) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}

Measured memory_bytes: 256
import heapq

n, m = map(int, input().split())
a = list(map(int, input().split()))
a = list(map(lambda x: x * (-1), a))

heapq.heapify(a)
for i in range(m):
    x = heapq.heappop(a)
    heapq.heappush(a, (-1) * (-x // 2))

print(-sum(a))

Measured memory_bytes: 20548
class Tiles
  def initialize
    @tiles = []
  end

  def add(row)
    x, y = -1, @tiles.length
    @tiles << row.map{|item|
      x += 1
      Tile.new(x, y, item)
    }
  end

  def set
    @tiles.each{|row|
      row.each{|item|
        x, y = item.next_ord
        item.set_parent(@tiles[y][x])
      }
    }
  end

  def solve
    normal, twice = @tiles[0][0].next, @tiles[0][0].next.next
    while normal != twice
      normal, twice = normal.next, twice.next.next
    end
    if normal.tip?
      puts normal.to_s
    else
      puts "LOOP"
    end
  end

end

class Tile
  attr_reader :x, :y
  @@condition = {">" => 5, "<" => 3, "^" => 1, "v"=> 7, "." => 4}
  def initialize(x, y, arrow)
    @x = x
    @y = y
    @parent = nil
    @condition = @@condition[arrow]
  end
  
  def set_parent(other)
    @parent = other
  end

  def ==(other)
    return ((@x == other.x) and (@y == other.y))
  end

  def next_ord
    return x + ((@condition % 3) <=> 1), y + ((@condition / 3) <=> 1)
  end

  def next
    return @parent
  end

  def tip?
    return @condition == 4
  end

  def to_s
    return "#{x} #{y}"
  end

  def inspect
    to_s
  end
  
  
end
def main
  while (h, w = gets.split(" ").map(&:to_i)) != [0, 0] # !> assigned but unused variable - w
    tiles = Tiles.new
    h.times do
      tiles.add(gets.chomp.split(""))
    end
    tiles.set
    tiles.solve
  end
end
main

Measured memory_bytes: 7328
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <limits.h>
#include <queue>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for(int i=0; i<n; i++)

bool black[100][100];
int H = 100;
int W = 100;

int main(){
    int A,B;
    cin >> A >> B;
    cout << H << " " << W << endl;
    for(int h = 50; h < 100; h++){
        for(int w = 0; w < 100; w++){
            black[h][w] = true;
        }
    }

    int b = 0;
    while(B > 1){
        black[2*(b/100)][b%100] = true;
        b += 2;
        B--;
    }

    int a = 0;
    while(A > 1){
        black[51 + 2*(a/100)][a%100] = false;
        a += 2;
        A--;
    }

    for(int h = 0; h < 100; h++){
        for(int w = 0; w < 100; w++){
            if(black[h][w]) printf("#");
            else printf(".");
        }
        printf("\n");
    }
    return 0;
}


Measured memory_bytes: 256