akhauriyash/Code-Regression huggingface dataset:
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func check(ruiseki *[21]int) bool {
	for bit_num := uint(0); bit_num < 21; bit_num++ {
		if ruiseki[bit_num] > 1 {
			return false;
		}
	}
	return true;
}
func add(ruiseki *[21]int, val int ,is_add bool) {
	for bit_num := uint(0); bit_num < 21; bit_num++ {
		x := (val >> bit_num) & 1
		if x > 0 {
			if is_add {
				ruiseki[bit_num]++
			}else{
				ruiseki[bit_num]--
			}
		}
	}
}


func main() {
	sc := NewScanner()
	N := sc.NextInt();
	A := sc.NextIntArray()

	var ruiseki [21]int
	ans :=0
	ruiseki_length := 0
	for i := 0; i < N; i++ {
		tmp_input := A[i]
		A = append(A, tmp_input)
		add(&ruiseki,tmp_input,true)
		for ; !check(&ruiseki); ruiseki_length-- {
			add(&ruiseki, A[i - ruiseki_length],false)
		}
		ruiseki_length++
		//fmt.Println(i,ruiseki_length)
		//fmt.Println(ruiseki)
		ans += ruiseki_length
	}
	fmt.Println(ans)
	//fmt.Println(A)

}

// Copied

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}


func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *Scanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 0)
			result = append(result, int(v))
			start = s.p + 1
		}
	}

	return result
}
func (s *Scanner) NextInt64Array() []int64 {
	s.pre()
	start := s.p
	result := []int64{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 64)
			result = append(result, v)
			start = s.p + 1
		}
	}
	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}


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

using namespace std;

#define int long long

int n;
deque<string> s;
int md = 10000000007;
int A = 10007;
deque<int> row, col;
int pos[300];

inline int mod(int x){
    return (x % md + md) % md;
}

main()
{
    ios_base::sync_with_stdio(false);
    cin >> n;
    row.resize(n);
    col.resize(n);
    s.resize(n);
    int tmp = A;
    for(int i = 0; i < n; i++){
        pos[i] = tmp;
        tmp = mod(tmp * A);
    }
    for(int i = 0; i < n; i++){
        cin >> s[i];
    }
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            int c = s[i][j];
            row[i] = mod(row[i] + c * pos[j]);
            col[j] = mod(col[j] + c * pos[i]);
        }
    }
    int an = 0;
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            bool ok = true;
            for(int k = 0; k < n; k++) if(row[k] != col[k]) ok = false;
            an += ok;
            col.push_front(col.back());
            col.pop_back();
            for(int k = 0; k < n; k++){
                int curc = s[k][n - 1 - j];
                row[k] = mod((row[k] - curc * pos[n-1]) * A + curc * A);
            }
        }
        row.push_front(row.back());
        row.pop_back();
        for(int k = 0; k < n; k++){
            int curc = s.back()[k];
            col[k] = mod((col[k] - curc * pos[n-1]) * A + curc * A);
        }
        s.push_front(s.back());
        s.pop_back();
    }
    cout << an << endl;
}


Measured memory_bytes: 384
import sys
sys.setrecursionlimit(10**7)
n,q=map(int,input().split())
tree=[[] for _ in range(n)]
for _ in range(n-1):
    a,b=map(int,input().split())
    a-=1
    b-=1
    tree[a].append(b)
    tree[b].append(a)
cnt=[0]*n
for _ in range(q):
    p,x=map(int,input().split())
    cnt[p-1]+=x

def DFS(v,p_v):
    for next_v in tree[v]:
        if next_v==p_v:
            continue
        cnt[next_v]+=cnt[v]
        DFS(next_v,v)

DFS(0,-1)
print(*cnt)

Measured memory_bytes: 232972
weatherS = input()
p = weatherS[0] == 'R'
q = weatherS[1] == 'R'
r = weatherS[2] == 'R'

if p and q and r:
    serial = 3
elif (p and q) or (q and r):
    serial = 2
elif p or q or r:
    serial = 1
else:
    serial = 0

print(serial)

Measured memory_bytes: 8960
#include <bits/stdc++.h>
using namespace std;
int main(){
  string A, B, C;
  cin >> A >> B >> C;
  if (A[A.size()-1] == B[0] && B[B.size()-1] == C[0]) {
    cout << "YES" << endl;
  }
  else {
    cout << "NO" << endl;
  }
}

Measured memory_bytes: 256
import heapq

n,m = map(int, input().split())
to= [list() for _ in range(n)]
for i in range(m):
    l,r,c = map(int, input().split())
    l-=1
    r-=1
    to[l].append((r,c))

for i in range(1,n):
    to[i].append((i-1,0))

q = []
INF = 1001001001001001
d = [INF]*n
d[0]=0
heapq.heappush(q,(0,0))
while q:
    cost,u = heapq.heappop(q)
    if d[u]<cost:
        continue
    for v,c in to[u]:
        if d[v]>d[u]+c:
            d[v]=d[u]+c
            heapq.heappush(q,(d[v],v))

if d[-1]==INF:
    print(-1)
else:
    print(d[-1])
        



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

int main(){
  int n,a,ans;
  ans=1;
  cin>>n;
  for(int i=0;i<n;i++){
  	cin>>a;
    if(a%2==0)ans=ans*2;
  }
  cout<<pow(3,n)-ans<<endl;
  return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

using ll = long long;
using P = pair<int, int>;
using T = tuple<int, int, int>;

template <class T> inline T chmax(T &a, const T b) {return a = (a < b) ? b : a;}
template <class T> inline T chmin(T &a, const T b) {return a = (a > b) ? b : a;}

constexpr int MOD = 1e9 + 7;
constexpr int inf = 1e9;
constexpr long long INF = 1e18;

#define all(a) (a).begin(), (a).end()

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

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

    ll x; cin>>x;

    ll base = 100;
    int ans = 0;
    while(1){
        ans++;
        base = base + base * 0.01;
        if(x <= base){
            cout << ans << endl;
            return 0;
        }
    }

    return 0;
}

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

using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<string> vs;
using pll = pair<ll, ll>;
using vl = vector<ll>;
using vll = vector<vl>;
using vpll = vector<pll>;
struct Edge {
	ll to;
 	ll cost;
 };
using Graph = vector<vector<Edge>>;

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define ALL(a) (a).begin(), (a).end()
/***** define constant start *******/
const ll MOD = 1000000007;
const double PI = 2.0 * asin(1.0);
const ll INF = 1L<<60;
string abc = "abcdefghijklmnopqrstuvwxyz";
string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const ll MAX = 10000000;
/****** define constant end ********/
/****** define variable start ******/
ll n;
vl a;
/******* define variable end *******/
int solve() {
	cin >> n;
	a.resize(n+1);
	ll ma = 0;
	ll not_node = 0;
	REP(i, n+1){
		cin >> a[i];
		if(a[i] > ma) ma = a[i];
		not_node += a[i];
	}
	ll ans = 0;
	ll node = 0;
	if(n != 0 && a[0] == 1){
		cout << -1 << endl;
		return 0;
	}
	if(n == 0 && a[0] != 1){
		cout << -1 << endl;
		return 0;
	}
	REP(i, n+1){
		not_node -= a[i];
		if(i != 0){
			if((node-a[i-1]) * 2 < a[i]){
				cout << -1 << endl;
				return 0;
			}
		}
		if(i == 0){
			ll one = 1;
			node = min(not_node+a[i], one);
		}else if(i != n){
			node = min(not_node+a[i], (node-a[i-1])*2);
		}else{
			node = a[i];
		}
		ans += node;
	}
	cout << ans << endl;
	return 0;
}

int main() {
	//clock_t start = clock();
	cout << std::fixed << std::setprecision(10);
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int end_solve = solve();
	/*
	clock_t end = clock();
	const double time = static_cast<double>(end - start) / CLOCKS_PER_SEC *
	1000.0; printf("time %lf[ms]\n", time);
	*/

	return end_solve;
}


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

public class Main{
	static int n;
	static int []S;
	static int q;
	static int t;
	static int count;

	public static void main(String[] args) throws NumberFormatException, IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		n = Integer.parseInt(br.readLine());
		String [] temp = br.readLine().split(" ");
		S = new int[n];
		for(int i=0;i < n;i++){
			S[i] = Integer.parseInt(temp[i]);
		}

		q =Integer.parseInt(br.readLine());
		temp = br.readLine().split(" ");

		for(int i = 0;i < q;i++){
			t = Integer.parseInt(temp[i]);
			search(t);
		}

		System.out.println(count);

	}

	public static void search(int num){
		for(int i = 0;i < n;i++){
			if(S[i] == num){
				count++;
				return;
			}
		}
	}

}

Measured memory_bytes: 27032
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<cctype>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<ctime>
#include<vector>
#include<set>
#include<map>
#include<stack>
using namespace std;
const int mod=1e9+7;
int dp[3001][3001][2];
int n,m;
int main()
{     int i,j,k,ans=0;
      scanf("%d%d",&n,&m);
      dp[0][0][1]=1;
      for(i=1;i<=n;i++)
         dp[0][i][0]=1;
      	for (i=0;i<m;i++)
	{
		for (j=0;j<=n;j++)
		{
			for (k=0;k<=1;k++)
			{
				if(j) dp[i+1][j-1][k|(j==1)]=(dp[i][j][k]+dp[i+1][j-1][k|(j==1)])%mod;
				if(j) dp[i+1][j][k|(j==1)]=(dp[i][j][k]+dp[i+1][j][k|(j==1)])%mod;
				if(n-j) dp[i+1][j][k]=(dp[i][j][k]+dp[i+1][j][k])%mod;
				if(n-j) dp[i+1][j+1][k]=(dp[i][j][k]+dp[i+1][j+1][k])%mod;
			}
		}
	}
	for (i=0;i<=n;i++)ans=(ans+dp[m][i][1])%mod;
	  cout<<ans%mod<<endl;
	  return 0;
}


Measured memory_bytes: 70656
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }
    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int N = scan.nextInt();
        long[] summary = new long[N+1];
        for (int i = 1; i <= N; i++) {
            summary[i] = divisors(i);
        }
        long ans = 0;
        for (int C = 1; C <= N - 1; C++) {
            ans += summary[N-C];
        }
        System.out.println(ans);
    }
    private long divisors(int N) {
        int current = N;
        long ans = 1;
        for (int i = 2; i * i <= current; i++) {
            if (current % i != 0) {
                continue;
            }
            long count = 0;
            while (current % i == 0) {
                current /= i;
                count += 1;
            }
            ans *= (count + 1);
        }
        if (1 < current) {
            ans *= 2;
        }
        return ans;
    }
}


Measured memory_bytes: 43460
#include <bits/stdc++.h>
using namespace std;
 
int main() {
	int n;
	cin >> n;
	
	int ans  = 100000000;
	for(int i=0; i<=n; i++){
		int x;
		cin >> x;
		
		int tmp = 0;
		for(int j=0; j<ans; j++){
			if(x%2 == 0){
				x /= 2;
				tmp++;
			}else{
				break;
			}
		}
		ans = tmp;
		
		if(ans == 0){
			break;
		}
	}
	
	cout << ans << endl;
}

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

using namespace std;

int main(){
    int64_t H,W; cin>>H>>W;
    int64_t x,y; cin>>x>>y;
    int ans;

    if(x==(double)H/2 && y==(double)W/2) ans=1;
    else ans=0;

    printf("%.1f %d",(double)(H*W)/2,ans);


    return 0;
}

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

using namespace std;

#define MAX             100005
#define MOD             1000003
#define eps             1e-6
int fx[] =              {1,-1,0,0};
int fy[] =              {0,0,1,-1};

#define FastRead        ios_base::sync_with_stdio(0);cin.tie(0);
#define fRead           freopen("in.txt","r",stdin);
#define fWrite          freopen ("out.txt","w",stdout);

#define LL              long long
#define ULL             unsigned long long
#define ff              first
#define ss              second
#define pb              push_back
#define PI              acos(-1.0)
#define mk              make_pair
#define pii             pair<int,int>
#define pll             pair<LL,LL>
#define all(a)          a.begin(),a.end()

#define min3(a,b,c)     min(a,min(b,c))
#define max3(a,b,c)     max(a,max(b,c))
#define min4(a,b,c,d)   min(a,min(b,min(c,d)))
#define max4(a,b,c,d)   max(a,max(b,max(c,d)))

#define FOR(i,a,b)      for(int i=a;i<=b;i++)
#define ROF(i,a,b)      for(int i=a;i>=b;i--)
#define REP(i,b)        for(int i=0;i<b;i++)

#define MEM(a,x)        memset(a,x,sizeof(a))
#define ABS(x)          ((x)<0?-(x):(x))
#define SORT(v)         sort(v.begin(),v.end())
#define REV(v)          reverse(v.begin(),v.end())

//// ***************************************************** TEMPLETE ***************************************************** ////

int main()
{
    FastRead
    int n;
    cin >> n;
    int cnt[MAX]={0};
    int temp,m=0;
    REP(i,n)
    {
        cin >> temp;
        cnt[temp]++;
        m=max(m,cnt[temp]);
        cnt[temp-1]++;
        m=max(m,cnt[temp-1]);
        cnt[temp+1]++;
        m=max(m,cnt[temp+1]);
    }
    cout << m << '\n';
    return 0;
}


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

int main(){
    int H,W; cin >> H >> W;
    char A[50][50];
    
    for(int i=1; i<=H; i++){
        for (int j=1; j<=W; j++) cin >> A[i][j];
    }
    
    for(int i=1; i<=H; i++){
        for(int j=1; j<=W; j++){
            if(A[i][j]=='#' && A[i][j-1]!='#' && A[i-1][j]!='#' && A[i][j+1]!='#' && A[i+1][j]!= '#'){
                cout << "No";
                return 0;
            }
        }
    }
    cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 256
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Scanner;

public class Main {
    void run() {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt(), m = sc.nextInt(), k = sc.nextInt();
        S[] s = new S[n];
        int[] sub = new int[n];
        for (int i = 0; i < n; i++) {
            s[i] = new S();
        }
        UnionFind fr = new UnionFind(n);

        for (int i = 0; i < m; i++) {
            int a = sc.nextInt() - 1, b = sc.nextInt() - 1;
            fr.unite(a, b);
            s[a].add(b);
            s[b].add(a);
            sub[a]++;
            sub[b]++;
        }
        for (int i = 0; i < k; i++) {
            int c = sc.nextInt() - 1, d = sc.nextInt() - 1;
            if (fr.same(c, d)) {
                sub[c]++;
                sub[d]++;
            }
        }

        PrintWriter out = new PrintWriter(System.out);

        out.print(fr.size(0) - sub[0] - 1);
        for (int i = 1; i < n; i++) {
            out.print(" " + (fr.size(i) - sub[i] - 1));
        }
        out.println();
        out.flush();


    }

    class S extends HashSet<Integer> {}

    void debug(Object... os) {
        System.err.println(Arrays.deepToString(os));
    }

    public class UnionFind {
        int[] parents, sizes;

        UnionFind(int n) {
            parents = new int[n];
            sizes = new int[n];
            for(int i = 0; i < n; i++) {
                parents[i] = i;
                sizes[i] = 1;
            }
        }

        public int find(int x) {
            if (x == parents[x]) return x;
            return parents[x] = find(parents[x]);
        }

        public void unite(int x, int y) {
            x = find(x);
            y = find(y);
            if (x == y) return;
            if (sizes[x] < sizes[y]) {
                int temp = x;
                x = y;
                y = temp;
            }
            parents[y] = x;
            sizes[x] += sizes[y];
        }

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

        public int size(int x) {
            return sizes[find(x)];
        }

    }

    public static void main(String[] args) {
        new Main().run();
    }

}


Measured memory_bytes: 162832
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; i++)
#define vv(T) vector<vector<T>>
using namespace std;
using ll = long long;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using vll = vector<long long>;
using vvll = vector<vector<long long>>;
using vbool = vector<bool>;
using vvbool = vector<vector<bool>>;
using qint = queue<int>;
using sint = stack<int>;
using pii = pair<int, int>;


int main(){
    int k, n;
    cin >> n >> k;
    vector<int> p(n);
    rep(i, n){
        cin >> p[i];
    }

    // for(auto x:p) cout << x << endl;
    sort(p.begin(), p.end());

    int ans = 0;
    for(int i = 0; i < k; i++){
        ans += p[i];
        // cout << p[i] << endl;
    }

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


Measured memory_bytes: 3576
using System;

class Program
{
    static void Main(string[] args)
    {
        var n = int.Parse(Console.ReadLine());
        var d = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
        var ans = rec(d, 0, d.Length);
        Console.WriteLine(ans);
    }

    static int rec(int[] d, int x, int y)
    {
        if (x == y) return 0;

        var min = int.MaxValue;
        for (int i = x; i < y; i++)
        {
            min = Math.Min(min, d[i]);
        }

        for (int i = x; i < y; i++)
        {
            d[i] -= min;
        }

        var ans = min;
        for (int l = x, r = x; r <= y; r++)
        {
            if (r != y && d[r] != 0) continue;
            if (l < r) ans += rec(d, l, r);
            l = r + 1;
        }

        return ans;
    }
}

Measured memory_bytes: 11092
#include "bits/stdc++.h"
#define YES "YES"
#define NO "NO"
#define Yes "Yes"
#define No "No"
#define DEFAULT LL ans=solve();\
 	if(ans==NONE){\
 	}else{\
 		cout << ans << endl;\
 	}
#define YESNO three(solve(),OUT(YES),OUT(NO))
#define YesNo three(solve(),OUT(Yes),OUT(No))
#define ECHO OUT(solve())
#define three(A,B,C) ((A)?(B):(C))
#define FOR(i,a,b)  for(LL i=(a);i< (LL)(b);i++)
#define EFOR(i,a,b) for(LL i=(a);i<=(LL)(b);i++)
#define RFOR(i,a,b) for(LL i=(b-1);i>=(LL)(a);i--)
#define REP(i,b) FOR(i,zero,b)
#define rep REP
#define EREP(i,b) EFOR(i,zero,b)
#define RREP(i,b) RFOR(i,zero,b)
#define ALL(c) c.begin(),c.end()
#define UNIQUE(c) sort(ALL(c));c.erase(unique(ALL(c)),c.end())
#define MAX(c) (*max_element(ALL(c)))
#define MIN(c) (*min_element(ALL(c)))
#define MP make_pair
#define FI first
#define SE second
#define SI(x) (LL(x.size()))
#define PB push_back
#define DEBUG(a) OUT(a)
#define DEBUG2(a,b) OUT2(a,b)
#define cat cout << __LINE__ << endl
#define OUT(a) cout << (a) << endl
#define OUT2(a,b) cout << (a) <<" "<<(b) << endl
#define zero 0LL
#define all ALL
#define pb emplace_back
#define eb pb
#define int long long
using namespace std;
template<typename T> inline void maximize(T &a, T b) { a = max(a, b); }
template<typename T> inline void minimize(T &a, T b) { a = min(a, b); }
template<typename T> inline bool middle(T a, T b, T c) { return b <= a && a <= c; }
template<class T> inline bool MX(T &l, const T &r) { return l < r ? l = r, 1 : 0; }
template<class T> inline bool MN(T &l, const T &r) { return l > r ? l = r, 1 : 0; }
typedef int LL;
typedef double ld;
typedef int ut;
typedef vector<ut> VI;
typedef vector<VI> VII;
typedef pair<ut, ut> pr;
typedef pair<ut, pr> ppr;
typedef vector<pr> Vpr;
typedef vector<ppr> Vppr;
typedef tuple<int, int, int, int> tapu;
typedef vector<tapu> Vtapu;
typedef priority_queue<pr, Vpr > PQ;
inline void outputVI(VI x) { REP(i, SI(x)) { cout << three(i, " ", "") << x[i]; }OUT(""); }
const int SIZE1 = 5e5 + 1000;
const int SIZE2 = 2010;
const int SIZE3 = 430;
const int SIZE = SIZE1;
const int MAPSIZE = 40;
const LL p = 1000000007;
const LL INF = 1LL << 60;
const long double EPS = 1e-7;
const LL NONE=-2;
#define endl "\n"
ut N, M,K,  Q, D, H, W;
VI edges[SIZE];
LL vals[SIZE], answer = zero;
LL A[SIZE],B[SIZE],C[SIZE];string s;
LL T[2];
LL solve(){
	REP(i,2) cin >> T[i];
	REP(i,2) cin >> A[i];
	REP(i,2) cin >> B[i];
	if(A[0]<B[0]){
		swap(A[0],B[0]);
		swap(A[1],B[1]);
	}
	assert(A[0]>B[0]);
	LL alla=A[0]*T[0]+A[1]*T[1];
	LL allb=B[0]*T[0]+B[1]*T[1];
	if(alla==allb){
		cout << "infinity" << endl;
		return NONE;
	}
	if(alla>allb) return 0;
	assert(alla<allb);
	LL sta=(A[0]-B[0])*T[0];
	LL c=(sta/(allb-alla))+1;
	//cout <<c << endl;
	if(sta%(allb-alla)==0) return c*2-2;
	return c*2-1;
	
	return NONE;
}
 signed main() {
 
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(10);
	string s;
	LL T;
	DEFAULT;
	
	
//	YesNo;
//	YESNO;
//	three(solve(),OUT("First"),OUT("Second"));
	//cin >> N;
	return 0;
 
}


Measured memory_bytes: 17536
var
 i,ss,s1,s2:longint;
 s:string;
begin
 readln(s);
 for i:=1 to length(s) do
  if s1=s2 then begin if s[i]='p' then dec(ss); inc(s1); end
  else begin if s[i]='g' then inc(ss); inc(s2); end;
 writeln(ss);
end.

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

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define INF  numeric_limits<int>::max()
#define NINF numeric_limits<int>::min()

using namespace std;
using ll = long long;

const int N_MAX = 8;
int N, M;
bool edge[N_MAX][N_MAX];
bool reached_vertex[N_MAX];

int dfs(int vertex) {
    bool all_vertex_was_reached = true;
    REP(i, N) {
        if(!reached_vertex[i]) {
            all_vertex_was_reached = false;
        }
    }

    if(all_vertex_was_reached) {
        return 1;
    }

    int ret = 0;
    REP(i, N) {
        if(!edge[vertex][i] || reached_vertex[i]) continue;

        reached_vertex[i] = true;
        ret += dfs(i);
        reached_vertex[i] = false;
    }

    return ret;
}

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

    std::cin >> N >> M;
    REP(i, N) {
        reached_vertex[i] = false;
    }

    REP(i, M) {
        int a, b;
        std::cin >> a >> b;
        edge[a - 1][b - 1] = edge[b - 1][a - 1] = true;
    }

    reached_vertex[0] = true;
    std::cout << dfs(0) << std::endl;

    return 0;
}


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

int main(){
  int a,b,c;
  cin >> a >> b >> c;
  if(a==b&&a!=c){
    cout << "Yes" << endl;
    return 0;
  }
  if(a==c&&a!=b){
    cout << "Yes" << endl;
    return 0;
  }
  if(b==c&&a!=b){
    cout << "Yes" << endl;
    return 0;
  }
  cout << "No" << endl; 
}  

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

// 1-indexed
template <class T>
struct BIT {
  vector<T> lst;
  int treesize;
  // constructor
  BIT(int newn = 0) {
    treesize = newn;
    lst.resize(treesize + 1);
    for(int i = 0; i <= treesize; ++i) lst[i] = 0;
  }
  // a_place += num
  bool add(int place, T num) {
    while(place <= treesize) {
      lst[place] += num;
      place += place & -place;
    }
    return 1;
  }
  // add wide ver.(add num between l and r)
  bool addw(int left, int right, T num) {
    while(left <= right && left >= 1 && right <= treesize)
      add(left++, num);
    return 1;
  }
  // sum between [1,place]
  T calcsum(int place) {
    T answer = 0;
    while(place > 0) {
      answer += lst[place];
      place -= place & -place;
    }
    return answer;
  }
  // sum [l,r]
  T calcsumw(int left, int right) {
    return calcsum(right) - calcsum(left - 1);
  }
};

long long n, m, l;
vector<long long> k;
BIT<long long> bit;
vector<vector<vector<long long>>> dp;

long long solve();

int main() {
  cin >> n >> m >> l;
  bit = BIT<long long>(m);
  k.resize(n);
  for(int i = 0; i < n; ++i) cin >> k[i];
  for(int i = 0; i < m; ++i) {
    long long x;
    cin >> x;
    bit.add(i + 1, x);
  }
  cout << solve() << endl;
  return 0;
}

long long solve() {
  long long res = 1e17;
  sort(k.begin(), k.end());
  dp.assign(n,
            vector<vector<long long>>(
                2, vector<long long>(n, (long long)1e17)));
  dp[0][0][0] = dp[0][1][0] = 0;
  for(int i = 1; i < n; ++i)
    for(int f = 0; f < 2; ++f)
      for(int j = 0; j < i; ++j) {
        dp[i][f][j] = dp[i - 1][f][j] +
                      bit.calcsumw(k[i - 1], k[i]) / l;
        if(j == i - 1)
          for(int x = 0; x < j; ++x)
            dp[i][f][j] =
                min(dp[i][f][j],
                    dp[i - 1][1 - f][x] +
                        bit.calcsumw(k[x], k[i]) / l);
      }
  for(int i = 0; i < n; ++i)
    res = min(res, dp[n - 1][0][i] +
                       bit.calcsumw(k[i], k[n - 1]) / l);
  return res;
}


Measured memory_bytes: 66516
fun main() = abc166c()

@OptIn(ExperimentalStdlibApi::class)
fun abc166c() {
    val (n, m) = readLine()!!.split(' ').map { it.toInt() }
    val hList = readLine()!!.split(' ').map { it.toLong() }.toLongArray()
    val abList = (1..m).map { readLine()!!.split(' ').map { it.toInt() - 1 } }

    val good = BooleanArray(n) { true }

    for ((a, b) in abList) {
        if (hList[a] <= hList[b]) good[a] = false
        if (hList[b] <= hList[a]) good[b] = false
    }

    val answer = good.count { it }

    println(answer)
}


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

int main() {
  int N,M;
  cin >> N;
  cin >> M;
  int a[N],b[N];
  for (int i = 0; i < N; ++i) {
    cin >> a[i];
    cin >> b[i];
  }

  map<int, long long>m;

  for(int i=0;i<N;i++){
    m[a[i]] += b[i];
  }

  long long count = 0;

  long long ans = 0;
  for(auto x : m){
    long long buy = min((long long)M,x.second);
    count += buy*x.first;
    M -= (int)buy;
  }

  cout << count << endl;

}

Measured memory_bytes: 7296
program main
    implicit none
    integer i
    character n*3
    logical :: flag = .false.
    read *, n
    do i = 1, 3
        if (n(i:i) == "7") then
            flag = .true.
            exit
        end if
    end do
    if (flag) then
        print "(A)", "Yes"
    else
        print "(A)", "No"
    end if
 end program main

Measured memory_bytes: 2888
#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>
#include <queue>
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;
}
bool pairCompareSecond(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.second < secondElof.second;
}
#define MAX_N 100100
#define MOD 1000000007
bool x[MAX_N];
ll num[MAX_N];
ll fibl[MAX_N]={0};
// 四方向への移動ベクトル
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

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

void  base_num(ll data,ll base){
    if(data==0) return;
    ll next=abs(data)%abs(base);
    if(data<0) next=(abs(base)-next)%abs(base);
    base_num((data-next)/base,base);
    cout << next;
}



int main(){
    ll a,b,c,x,y,ans=0,an1=0,an2=0;
    cin >> a >> b >> c >> x >> y;
    ans=c*2*(max(x,y));
    an1+=min(x,y)*c*2;
    ll z=min(x,y),x1,y1;
    x1=x-z;
    y1=y-z;
    an1+=x1*a;
    an1+=y1*b;
    an2+=x*a;
    an2+=y*b;
    cout << min(ans,min(an1,an2)) << endl;
    return 0;
}




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

int main () {
    string s,t;
    cin>>s>>t;
    if(s==t.substr(0,t.length()-1)){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }
  return 0;
}

Measured memory_bytes: 3584
#include <algorithm>
#include <iostream>
#include <queue>
#include <vector>

#define X first
#define Y second
#define all(c) (c).begin(), (c).end()

using namespace std;

typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;

int compress ( VI &va, VI &vb, int wh )
{
	int n = va.size();
	VI vc;
	for (int i = 0; i < n; ++i) {
		for (int d = -1; d <= 1; ++d) {
			int ta = va[i] + d, tb = vb[i] + d;
			if (0 <= ta && ta <= wh) { vc.push_back(ta); }
			if (0 <= tb && tb <= wh) { vc.push_back(tb); }
		}
	}
	sort(all(vc));
	vc.erase(unique(all(vc)), vc.end());
	for (int i = 0; i < n; ++i) {
		va[i] = find(all(vc), va[i]) - vc.begin();
		vb[i] = find(all(vc), vb[i]) - vc.begin();
	}
	return vc.size();
}

int main ( void )
{
	int dx[] = { 0, 0, -1, 1 }, dy[] = { -1, 1, 0, 0 };
	int w, h, n;
	while (cin >> w >> h, w|h) {
		cin >> n;
		VI xa(n), xb(n), ya(n), yb(n);
		for (int i = 0; i < n; ++i) {
			cin >> xa[i] >> ya[i] >> xb[i] >> yb[i];
		}
		w = compress(xa, xb, w) - 1;
		h = compress(ya, yb, h) - 1;

		vector<vector<bool> > fld(h, vector<bool>(w, false));
		for (int i = 0; i < n; ++i) {
			for (int y = ya[i]; y < yb[i]; ++y) {
				for (int x = xa[i]; x < xb[i]; ++x) {
					fld[y][x] = true;
				}
			}
		}

		int ans = 0;
		for (int y = 0; y < h; ++y) {
			for (int x = 0; x < w; ++x) {
				if (fld[y][x]) { continue; }
				++ans;

				queue<PII> que;
				que.push(PII(x, y));
				while (!que.empty()) {
					PII p = que.front(); que.pop();

					for (int d = 0; d < 4; ++d) {
						PII t(p.X + dx[d], p.Y + dy[d]);
						if (t.X < 0 || t.X >= w || t.Y < 0 || t.Y >= h) { continue; }
						if (fld[t.Y][t.X]) { continue; }
						que.push(t);
						fld[t.Y][t.X] = true;
					}
				}
			}
		}

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

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

int main(){
	string s;
	int dir=1;
	int Rpos,chi=1;
	bool fir=true;
	cin>>s;
	for(int i=1;i<s.size();i++){
		if(dir==1){//toR
			if(s[i]=='R'){
				chi++;
				if(fir){
					cout<<0;
					fir=false;
				}else{
					cout<<" "<<0;
				}
			}else{
				Rpos=chi;
				chi++;
				dir=0;
			}
		}else{
			if(s[i]=='L'){
				chi++;
			}else{
				if(fir){
					if(Rpos%2==1){
						cout<<(chi+1)/2<<" "<<chi-(chi+1)/2;
					}else{
						cout<<chi/2<<" "<<chi-chi/2;
					}
					fir=false;
				}else{
					if(Rpos%2==1){
						cout<<" "<<(chi+1)/2<<" "<<chi-(chi+1)/2;
					}else{
						cout<<" "<<chi/2<<" "<<chi-chi/2;
					}
				}
				for(int i=Rpos+1;i<chi;i++){
					cout<<" "<<0;
				}
				chi=1;
				dir=1;
			}
		}
	}
	if(fir){
		if(Rpos%2==1){
			cout<<(chi+1)/2<<" "<<chi-(chi+1)/2;
		}else{
			cout<<chi/2<<" "<<chi-chi/2;
		}
		fir=false;
	}else{
		if(Rpos%2==1){
			cout<<" "<<(chi+1)/2<<" "<<chi-(chi+1)/2;
		}else{
			cout<<" "<<chi/2<<" "<<chi-chi/2;
		}
	}
	for(int i=Rpos+1;i<chi;i++){
		cout<<" "<<0;
	}
	cout<<endl;
	return 0;
}

Measured memory_bytes: 640
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;


namespace Test1 {

    


    class ClassMain {

       
        public static char[] after = new char[26]{
        'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R',
        'S','T','U','V','W','X','Y','Z'
        };

        public static char[] before = new char[26]{
        'D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U', 'V',
        'W','X', 'Y','Z','A','B','C'
        };

        public static int indexOfBef(char ch) {
            for (int i = 0; i < 26; i++) {
                if (before[i] == ch) { return i; }
            }
            return -1;
        }

        public static void Main(String[] args) {
            string line;
            while ((line = Console.ReadLine()) != null) {
                //int n = int.Parse(line);
                //if (n == 0) { break; }
                for (int i = 0; i < line.Length; i++) {
                    Console.Write(after[indexOfBef(line[i])]);
                }
                Console.WriteLine();
                //break;
            }
        }

        
    }



    
}

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

using namespace std;

int main() {
    int n;
    cin>>n;
    int arr[n+1];
    for(int i=1;i<=n;i++) cin>>arr[i];
    int dp[n+1];
    dp[1] = 0, dp[2] = abs(arr[2] - arr[1]);
    
    for(int i=3;i<=n;i++){
        dp[i] = min(dp[i-1] + abs(arr[i]-arr[i-1]), dp[i-2] + abs(arr[i]-arr[i-2]));
    }
    
    cout<<dp[n];
}

Measured memory_bytes: 1024
N, X = map(int, input().split())

# a : レベル i バーガーの層数
# p : レベル i バーガーに含まれるパティの層数
a, p = [1], [1] 
for i in range(N):
  a.append(a[i] * 2 + 3)
  p.append(p[i] * 2 + 1)
  
def f(N, X): # X <= 0 や X > a_N を許容し解説本文から簡略化
  if N == 0:
    return 0 if X <= 0 else 1
  elif X <= 1 + a[N-1]:
    return f(N-1, X-1)
  else:
    return p[N-1] + 1 + f(N-1, X-2-a[N-1])

print(f(N, X))

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

#ifdef _DEBUG
#define debug(x) cerr << "line: " << __LINE__ << ", func: " << __func__ << " ->  " << #x << " = " << x << endl
#define INFILE freopen("input.txt", "r", stdin)
#else
#define debug(x)
#define INFILE
#endif

#define ALL(s) begin(s), end(s)
#define RALL(s) rbegin(s), rend(s)
#define REP(i, a, b) for (int i = (a); i < (b); i++)
#define RREP(i, a, b) for (int i = (a); i >= (b); i--)

using namespace std;

using ll = long long;
using ull = unsigned long long;
using i_i = pair<int, int>;
using ll_ll = pair<ll, ll>;
using d_ll = pair<double, ll>;
using ll_d = pair<ll, double>;
using d_d = pair<double, double>;

static constexpr ll LL9_MOD = 1000000009LL;
static constexpr ll LL7_MOD = 1000000007LL;
static constexpr ll INF = 1LL << 60;
static constexpr double PI = static_cast<double>(3.14159265358979323846264338327950288);
static constexpr double EPS = numeric_limits<double>::epsilon();

static map<type_index, const char* const> scanType = {
    {typeid(int), "%d"}, {typeid(ll), "%lld"}, {typeid(double), "%lf"}, {typeid(char), "%c"}};

template <class T> static void scan(vector<T>& v);
[[maybe_unused]] static void scan(vector<string>& v, bool isWord = true);
template <class T> static inline bool chmax(T& a, T b);
template <class T> static inline bool chmin(T& a, T b);
template <class A, size_t N, class T> static void Fill(A (&arr)[N], const T& val);

int main(int argc, char* argv[]) {
  ll a, b;
  cin >> a >> b;

  cout << max(a + b, max(a - b, a * b)) << endl;
  return 0;
}

template <class T> static void scan(vector<T>& v) {
  auto tFormat = scanType[typeid(T)];
  for (T& n : v) {
    scanf(tFormat, &n);
  }
}

static void scan(vector<string>& v, bool isWord) {
  if (isWord) {
    for (auto& n : v) {
      cin >> n;
    }
    return;
  }

  int i = 0, size = v.size();
  string s;
  getline(cin, s);

  if (s.size() != 0) {
    i++;
    v[0] = s;
  }

  for (; i < size; ++i) {
    getline(cin, v[i]);
  }
}

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

template <class A, size_t N, class T> void Fill(A (&arr)[N], const T& val) {
  std::fill((T*)arr, (T*)(arr + N), val);
}


Measured memory_bytes: 256
sx,sy,tx,ty = map(int,input().split())

ans = []


ans += ["U"] * (ty - sy)
ans += ["R"] * (tx - sx)
ans += ["D"] * (ty - sy)
ans += ["L"] * (tx - sx)

ans += ["L"]
ans += ["U"] * (ty - sy + 1)
ans += ["R"] * (tx - sx + 1)
ans += ["D"]

ans += ["R"]
ans += ["D"] * (ty - sy + 1)
ans += ["L"] * (tx - sx + 1)
ans += ["U"]

print ("".join(ans))


Measured memory_bytes: 3188
#n = int(input())
#n,k = map(int,input().split())
#x = list(map(int,input().split()))


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

flg1 = 1
flg2 = 0
for i in range(N-M+1):
    if flg2:
        break
    for j in range(N-M+1):
        if flg2:
            break
        flg1 = 1
        
        for k in range(M):
            if not(flg1):
                break
            for l in range(M):
                if A[i+k][j+l]==B[k][l]:
                    continue
                else:
                    flg1 = 0
        else:
            if flg1:
                print("Yes")
                flg2 = 1
else:
    if not(flg2):
        print("No")

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
const int N = 1e2+100;
const int P = 998244353;
#define fr(i,a,b) for(int i = a;i <= b; ++i)
#define nfr(i,a,b) for(int i = a;i >= b; --i)
#define pb push_back

int n,m;

inline void add(int &x,int y){
   x += y; if(x >= P)x -= P;
}

map<vector<int>,int> m1;
map<vector<int>,int> vis;

int dfs(vector<int> S){
   if(S.size() == 0)return 1;
   if(vis[S])return m1[S];

   vector<int> v1;
   fr(i,1,(int)S.size()-1){
      v1.pb(S[i]);
   }

   int res = 0;
   if(S[0] == 0)add(res,dfs(v1));
   if(S[0] == 1)add(res,2*dfs(v1));

   fr(i,1,(int)S.size()/2){
      vector<int> v2;
      v2.resize(i);
      fr(j,0,i-1)v2[j] = S[j];
      fr(j,2,(int)S.size()/i){
         fr(k,0,i-1){
            v2[k] &= S[(j-1)*i+k];
         }
         vector<int> v3;
         fr(k,j*i,(int)S.size()-1)v3.pb(S[k]);
         add(res,1LL*dfs(v2)*dfs(v3)%P);
      }
   }
   vis[S] = 1; m1[S] = res;
   return res;
}

char ch[N];
vector<int> S;
int main(){
   scanf("%s",ch+1);
   n = strlen(ch+1);

   fr(i,1,n)S.pb(ch[i]-'0');
   printf("%d\n",dfs(S));
   return 0;
}


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

int main() {
  int X, Y, Z, K;
  cin >> X >> Y >> Z >> K;
  vector<long long> A(X), B(Y), C(Z);
  for (int i = 0; i < X; i++) cin >> A[i];
  for (int i = 0; i < Y; i++) cin >> B[i];
  for (int i = 0; i < Z; i++) cin >> C[i];
  
  sort(A.begin(), A.end());
  reverse(A.begin(), A.end());
  sort(B.begin(), B.end());
  reverse(B.begin(), B.end());
  sort(C.begin(), C.end());
  reverse(C.begin(), C.end());
  
  vector<long long> ABC = {};
  for (int i = 0; i < X; i++) {
    for (int j = 0; j < Y; j++) {
      if ((i + 1) * (j + 1) > 3000) break;
      for (int k = 0; k < Z; k++) {
        if((i + 1) * (j + 1) * (k + 1) > 3000) break;
        ABC.push_back(A[i] + B[j] + C[k]);
      }
    }
  }
  
  sort(ABC.begin(), ABC.end());
  reverse(ABC.begin(), ABC.end());
  
  for (int i = 0; i < K; i++) cout << ABC[i] << endl;
}

Measured memory_bytes: 1404
package main

import (
	"fmt"
)

func main() {
	var s string
	fmt.Scan(&s)

	ss := map[string]int{}
	for _, w := range []string{"eraser", "erase", "dreamer", "dream"} {
		ss[w] = len(w)
	}

	ll := len(s)
	for ll > 0 {
		flag := false
		for w, l := range ss {
			if ll >= l && s[ll-l:] == w {
				s = s[:ll-l]
				ll -= l
				flag = true
			}
		}
		if !flag {
			fmt.Println("NO")
			return
		}
	}

	fmt.Println("YES")
}

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

int main () {
  int a, b, c, x;
  int ans = 0;

  cin >> a >> b >> c >> x;

  for (int i=0; i<=a; i++) {
    for (int j=0; j<=b; j++) {
      for (int k=0; k<=c; k++) {
        if (500 * i + 100 * j + 50 * k == x) ans++;
      }
    }
  }

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

Measured memory_bytes: 256
H, W = map(int, input().split())
area = [list(input()) for i in range(H)]
def calc(area):
    count = 0
    for i in range(H):
        for j in range(W):
            if area[i][j] == '#':
                count += 1
    
    return count

dist = [[-1 for i in range(W)] for i in range(H)]
dist[0][0] = 0
que = [[0,0]]

dh = [1,0,-1,0]
dw = [0,1,0,-1]

while len(que) != 0:
    idx = que.pop(0)
    
    for i in range(4):
        h = idx[0] + dh[i]
        w = idx[1] + dw[i]
        
        if h >= 0 and h < H and w >= 0 and w < W and dist[h][w] == -1 and area[h][w] != '#':
            que.append([h, w])
            dist[h][w] = dist[idx[0]][idx[1]] + 1
   
neededWhiteNum = dist[H-1][W-1] + 1 
if neededWhiteNum == 0:
    print(-1)
else:
    print(H*W - dist[H-1][W-1] - calc(area) -1)

Measured memory_bytes: 3064
/*
    Author : Nishant Gupta 2.0
*/
#include<bits/stdc++.h>

#define LL long long int
#define getcx getchar_unlocked
#define X first
#define Y second
#define PB push_back
#define MP make_pair
#define MAX 100005
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL (LL(1e18))
#define rep(i, a, n) for(i=a;i<n;i++)
#define rev(i, a, n) for(i=a;i>=n;i--)
#define MSV(A,a) memset(A, a, sizeof(A))
#define rep_itr(itr, c) for(itr = (c).begin(); itr != (c).end(); itr++)

using namespace std;

inline void inp( int &n ) { 
	n=0;    int ch=getcx();int sign=1;   
	while( ch < '0' || ch > '9' ){if(ch=='-')sign=-1; ch=getcx();} 
	while(  ch >= '0' && ch <= '9' )    
	n = (n<<3)+(n<<1) + ch-'0', ch=getcx();
	n=n*sign;
}

inline void inp1( LL &n ) { 
	n=0;    LL ch=getcx();LL sign=1;   
	while( ch < '0' || ch > '9' ){if(ch=='-')sign=-1; ch=getcx();} 
	while(  ch >= '0' && ch <= '9' )    
	n = (n<<3)+(n<<1) + ch-'0', ch=getcx();
	n=n*sign;
}

int main() {
	int n;
	cin>>n;
	int r = n%10;
	
	if(r == 2 || r == 4 || r == 5||r ==7 || r == 9) cout<<"hon";
	else if(r == 0|| r == 1|| r == 6 || r == 8) cout<<"pon";
	else cout<<"bon";
	cout<<endl;

    return 0;
}



Measured memory_bytes: 3636
#include <iostream>
using namespace std;
bool find(int* p,int N,int tag){
	for(int i=0;i<N;i++){if(p[i]==tag){return false;}}
	return true;
}

int main() {
	int X,N;
	cin>>X>>N;
	if(N==0){cout<<X<<endl;return 0;}
	int* p=(int*)malloc(N);
	for(int i=0;i<N;i++){cin>>p[i];}
	int k=0;
	while(1){
		if(find(p,N,X-k)){cout<<X-k<<endl;break;}
		if(find(p,N,X+k)){cout<<X+k<<endl;break;}
		k++;
	}
	return 0;
}

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

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

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

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

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

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

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

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

use std::collections::HashSet;
fn main() {
    input! {
        s: chars,
    };
    let map = s.iter().map(|c| *c as u8).collect::<HashSet<_>>();
    let ans = ('a' as u8..'z' as u8 + 1)
        .filter(|c| !map.contains(c))
        .min();
    println!(
        "{}",
        match ans {
            Some(u) => (u as char).to_string(),
            None => "None".to_string(),
        }
    );
}


Measured memory_bytes: 6396
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
long long n, d, power[17]; pair<long long, long long>a[30];
vector<pair<long long, long long> > vec1, vec2, c1, c2;

// ------ RMQ Class ------ //
template<typename Type>
class RMQ {
private:
	int size_; std::vector<Type> dat;
public:
	RMQ() : size_(0), dat(std::vector<Type>()) {};
	RMQ(int size__) {
		for (size_ = 1; size_ < size__; ) size_ <<= 1;
		dat.resize(size_ << 1, std::numeric_limits<Type>::max());
	}
	template<class T>
	RMQ(T begin_, T end_) {
		int n = end_ - begin_;
		for (size_ = 1; size_ < n; size_ <<= 1); dat.resize(size_ << 1, std::numeric_limits<Type>::max());
		for (int i = 0; i < n; i++) dat[i + size_] = *(begin_ + i);
		for (int i = size_ - 1; i > 0; i--) dat[i] = std::min(dat[i << 1], dat[(i << 1) + 1]);
	}
	inline unsigned size() { return size_; }
	inline void update(unsigned i, Type x) {
		i += size_; dat[i] = x;
		while (i > 1) {
			i >>= 1;
			dat[i] = std::min(dat[i << 1], dat[i << 1 | 1]);
		}
	}
	inline Type query(unsigned l, unsigned r) {
		Type ret = std::numeric_limits<Type>::max();
		l += size_; r += size_;
		while (l != r) {
			if (l & 1) ret = std::min(ret, dat[l++]); l >>= 1;
			if (r & 1) ret = std::min(ret, dat[--r]); r >>= 1;
		}
		return ret;
	}
};
int main() {
	cin >> n >> d;
	for (int i = 0; i < n; i++)cin >> a[i].first >> a[i].second;
	int Mid = n / 2; sort(a, a + n);
	for (int i = 0; i < Mid; i++)vec1.push_back(make_pair(a[i].first, a[i].second));
	for (int i = Mid; i < n; i++)vec2.push_back(make_pair(a[i].first, a[i].second));
	power[0] = 1; for (int i = 1; i < 17; i++)power[i] = power[i - 1] * 3;
	for (int i = 0; i < power[vec1.size()]; i++) {
		if (i % 48 == 1)continue;
		long long Ax = 0, Bx = 0, Ay = 0, By = 0;
		for (int j = 0; j < vec1.size(); j++) {
			int Y = (i / power[j]) % 3;
			if (Y == 0) { Ax += vec1[j].first; Ay += vec1[j].second; }
			if (Y == 1) { Bx += vec1[j].first; By += vec1[j].second; }
		}
		c1.push_back(make_pair(Ax - Bx, Ay - By));
	}
	for (int i = 0; i < power[vec2.size()]; i++) {
		if (i % 48 == 1)continue;
		long long Ax = 0, Bx = 0, Ay = 0, By = 0;
		for (int j = 0; j < vec2.size(); j++) {
			int Y = (i / power[j]) % 3;
			if (Y == 0) { Ax += vec2[j].first; Ay += vec2[j].second; }
			if (Y == 1) { Bx += vec2[j].first; By += vec2[j].second; }
		}
		c2.push_back(make_pair(Ax - Bx, Ay - By));
	}
	sort(c1.begin(), c1.end());
	sort(c2.begin(), c2.end());
	RMQ<long long> seg(c2.size());
	for (int i = 0; i < c2.size(); i++)seg.update(i, c2[i].second);
	long long minx = 1LL << 62, pos1 = c2.size(), pos2 = c2.size();
	for (int i = 0; i < c1.size(); i++) {
		while (pos1 > 0 && c2[pos1 - 1] > make_pair(-c1[i].first - d, -1LL << 62))pos1--;
		while (pos2 > 0 && c2[pos2 - 1] > make_pair(-c1[i].first + d + 1, -1LL << 62))pos2--;
		if (pos1 < pos2) {
			long long pos3 = seg.query(pos1, pos2);
			minx = min(c1[i].second + pos3, minx);
		}
	}
	cout << -minx << endl;
	return 0;
}

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

using namespace std;

#define N 5200

int n,ans,a[N],b[N];
char s[N],t[N];

void solve(char s[],char t[]){
	memset(a,0,sizeof a); memset(b,0,sizeof b);
	for (int i=1;i<n;++i){
		if (s[i]=='0'&&s[i+1]=='1') a[i]=-1;
		if (s[i]=='1'&&s[i+1]=='0') a[i]=1;
		if (t[i]=='0'&&t[i+1]=='1') b[i]=-1;
		if (t[i]=='1'&&t[i+1]=='0') b[i]=1;
	}
	for (int k=1;k<=n;++k){
		int sum=0;
		for (int i=1;i<k;++i) if (b[i]) sum+=i;
		int i=1,j=k;
		for (;i<n;++i) if (a[i]){
			for (;j<n&&b[j]!=a[i];++j)
				if (b[j]) sum+=j;
			sum+=abs(i-j);
			j+=j<n;
		}
		for (;j<n;++j) if (b[j]) sum+=n-j;
		ans=min(ans,sum);
	}
}

int main(){
	scanf("%d%s%s",&n,s+1,t+1);
	if (n<=2){
		for (int i=1;i<=n;++i) ans+=s[i]!=t[i];
		printf("%d\n",ans);
		return 0;
	}
	ans=n*n;
	solve(s,t); solve(t,s);
	reverse(s+1,s+n+1); reverse(t+1,t+n+1);
	solve(s,t); solve(t,s);
	printf("%d\n",ans);
	
	return 0;
}
			

Measured memory_bytes: 256