akhauriyash/Code-Regression huggingface dataset:
#include <cmath>
#include <limits>
#include <iostream>
#include <tuple>
#include <vector>
#include <algorithm>

int main(){
  int N,K;
  std::cin >> N >> K;

  std::vector<std::tuple<int, int>> xy_arr1(N), xy_arr2;
  for(int i = 0; i < N; i++){
    int x,y;
    std::cin >> x >> y;
    xy_arr1[i] = std::make_tuple(x,y);
  }
  xy_arr2 = xy_arr1;
  std::sort(xy_arr1.begin(), xy_arr1.end());
  std::sort(xy_arr2.begin(), xy_arr2.end(), [](const std::tuple<int,int>& l, const std::tuple<int,int>& r){ return std::get<1>(l)<std::get<1>(r);});

  long long min_rect = std::numeric_limits<long long>::max();
  for(int i1 = 0; i1 < N; i1++){
    long long x1 = std::get<0>(xy_arr1[i1]);
    for(int i2 = i1; i2 < N; i2++){
      long long x2 = std::get<0>(xy_arr1[i2]);
      for(int j1 = 0; j1 < N; j1++){
        long long y1 = std::get<1>(xy_arr2[j1]);
        for(int j2 = j1; j2 < N; j2++){
          long long y2 = std::get<1>(xy_arr2[j2]);
          int inner = 0;
          for(int j3 = j1; j3 <= j2; j3++){
            int x = std::get<0>(xy_arr2[j3]);
            if(x >= x1 && x <= x2) inner++;
          }
          if(inner >= K) min_rect = std::min(min_rect, (x2-x1)*(y2-y1));
        }
      }
    }
  }
  std::cout << min_rect << std::endl;

  return 0;
}



Measured memory_bytes: 384
import java.util.*;

@SuppressWarnings("unchecked")
public class Main {
	// public static void printArray(int[] a) {
	// 	for (int i = 0; i < a.length; i++) {
	// 		System.out.print(a[i] + ", ");
	// 	}
	// 	System.out.println();
	// }

	// public static<T> void printArrayT(T[] a) {
	// 	for (int i = 0; i < a.length; i++) {
	// 		System.out.print(a[i] + ", ");
	// 	}
	// 	System.out.println();
	// }

	public static String joinInt(int[] a, String separator) {
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < a.length; i++) {
			if (i > 0) {
				sb.append(separator);
			}
			sb.append(a[i]);
		}
		return sb.toString();		
	}

	static int[] nextIntArray(Scanner sc, int N) {
		int[] arr = new int[N];
		for (int i = 0; i < N; i++) {
			arr[i] = sc.nextInt();
		}
		return arr;
	}

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int T = sc.nextInt();
		int[] TS = new int[N];
		for (int i = 0; i < N; i++) {
			TS[i] = sc.nextInt();
		}
		long sum = T;
		for (int i = 1; i < N; i++) {
			int diff = TS[i] - TS[i-1];
			sum += Math.min(T, diff);
		}
		System.out.println(sum);
	}
}


Measured memory_bytes: 62824
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Random;
import java.util.Scanner;
import java.util.Stack;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.Vector;

public class Main {
	static class FastScanner{//用于快速读入大量数据
		BufferedReader br;
		StringTokenizer st;
		public FastScanner(InputStream in) {
			br = new BufferedReader(new InputStreamReader(in),16384);
			eat("");
		}
		public void eat(String s) {
			st = new StringTokenizer(s);
		}
		public String nextLine() {
			try {
				return br.readLine();
			} catch (IOException e) {
				return null;
			}
		}
		public boolean hasNext() {
			while(!st.hasMoreTokens()) {
				String s = nextLine();
				if(s==null) return false;
				eat(s);
			}
			return true;
		}
		public String next() {
			hasNext();
			return st.nextToken();
		}
		public int nextInt() {
			return Integer.parseInt(next());
		}
	}

	static FastScanner cin = new FastScanner(System.in);//快读
	static PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));//快速输出
	
	   public static void main(String args[]) {
		 int n;
		 n=cin.nextInt();
         
		 int ans=(1000-(n%1000))%1000;
		 out.println(ans);
		 out.flush();
	   }
}


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

int main() {
 double n,k;
 double sum=0;
 cin >> n >>k;
  vector<double> cnt(n);
  for(int i=1;i<=n;i++){
   for(int j=0;j<18;j++){
     if(i*pow(2,j)<k && i*pow(2,j+1)>=k){
     cnt[i-1]=j+1;
     }
   }
  }
  for(int i=0;i<n;i++){
   sum+=(double)(1/n)*(double)pow((double)1/2,cnt[i]);
  }
  cout << setprecision(20) << sum << endl;
}

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

using namespace std;
typedef long long ll;

ll N,K;
ll a[100];
ll b[100001];

int main(){
    cin >> N >> K;
    for(int i=0;i<N;i++) cin >> a[i];
    ll min_a = 1e12;
    for(int i=0;i<N;i++) min_a = min(min_a, a[i]);
    for(int i=0;i<=K;i++) b[i] = 0;
    for(int i=0;i<=K;i++){
        for(int j=0;j<N;j++){
            if(i-a[j] < 0) continue;
            if(b[i-a[j]] == 0){
                b[i] = 1;
                break;
            }
        }
    }
    if(b[K] == 0){
        cout << "Second" << endl;
    }else{
        cout << "First" << endl;
    }
    return 0;
}

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

int main(){
    long long x;
    cin >> x;
    long long cnt = 2*(x/11);
    x -= 11*(x/11);
    if(x > 6){
        cnt += 2;
    }else if(x > 0){
        cnt += 1;
    }
    cout << cnt;
    return EXIT_SUCCESS;
}

Measured memory_bytes: 256
//g++ -std=gnu++14 a.cpp

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iostream>
#include <istream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <tuple>
#include <iomanip>
#include <random>
#include <math.h>
#include <stdio.h>

using namespace std;

#define ll long long
#define rep(i, n) for(ll i = 0; i < (n); i++)
ll MOD = 1e9 + 7;
int INF = 1 << 30;
ll INFL = 1LL << 60;
ll MODP = 998244353;

ll kai(ll x,ll y){
  if(y == 0)return 1;
  if(y == 1)return x;
  if(y&1){
    return (x*kai(x,y-1))%MOD;
  }else{
    ll t = kai(x,y/2);
    return (t*t)%MOD;
  }
}

ll comb(ll a,ll b,vector<ll> &p){
  if(a == 0)return 1;
  if(b == 0)return 1;
  ll ans = p[a+b];
  ans = (ans*kai(p[a],MOD-2))%MOD;
  ans = (ans*kai(p[b],MOD-2))%MOD;
  return ans;
}

ll mind(int x,vector<int> &v){
  int ok = v.size()-1,ng = -1;
  while(ok - ng > 1){
    int next = (ok+ng)/2;
    if(v[next] > x){
      ok = next;
    }else{
      ng = next;
    }
  }
  return ok;
}

ll maxd(int x,vector<int> &v){
  int ok = 0,ng = v.size();
  while(ng - ok > 1){
    int next = (ok+ng)/2;
    if(v[next] < x){
      ok = next;
    }else{
      ng = next;
    }
  }
  return ok;
}


int main(){
  vector<int> res(1000010,0);
  int K;
  cin >> K;
  int cur = 7%K,add = 7%K;
  int ans = 1;
  while(1){
    if(cur == 0){
      break;
    }else if(res[cur] > 0){
      ans = -1;
      break;
    }else{
      res[cur] = 1;
      add = (add*10)%K;
      cur = (cur + add)%K;
      ans++;
    }
  }

  cout << ans << endl;


  return 0;
}


Measured memory_bytes: 7040
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
#include<cmath>
#include<cstdio>
#include<tuple>
#include<bitset>
#include<map>

using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define ALL(x) x.begin(),x.end()
#define ll long long
typedef pair<int,int> P;
const int inf=1000000007;
const int MOD=1000000007;
signed main(){
  int n,k;cin>>n>>k;
  int res=0;
  vector<int> snuke(n+1,0);
  rep(i,k){
    int d;cin>>d;
    rep(j,d){
      int a;cin>>a;
      snuke[a]++;
    }
  }
  rep1(i,n){
    if(snuke[i]==0)res++;
  }
  cout<<res<<"\n";
  return 0;
}


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

using namespace std;
const int INF=1e9+5;
typedef long long ll;
const int MOD=1e9+7;
int main(){
	int n,a,b;
	cin>>n>>a>>b;
	for(int i=a;i<=b;i++){
		if(i%n==0){
			cout<<"OK\n";
			return 0;
		}
	}
		cout<<"NG\n";
		
	return 0;
}


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

int main() {
  int K , X;
  cin>> K >> X;
  int P = X-K+1;
  int Q = X+K-1;
  

  if(P>Q){
    for(int i=Q ; i < P ; i++){
      cout << i << " ";
    }
    cout << P << endl;
  }
  else if(P<Q){
    for(int i=P ; i < Q ; i++){
      cout << i << " ";
    }
    cout << Q << endl;
  }
  else {
    cout << P << endl;
  }
}

Measured memory_bytes: 256
N, K = [int(i) for i in input().split()]
A = [[] for _ in range(N)]
for i in range(K):
    a = int(input())
    b = input().split()
    for j in range(a):
        A[int(b[j])-1] = 1
j = 0
for i in range(len(A)):
    if A[i] != 1:
        j += 1
print(j)

Measured memory_bytes: 9196
import java.io.*;
import java.util.*;

public class Main {
    static PrintWriter out = new PrintWriter(System.out);
    static Scanner sc = new Scanner(System.in);
    static BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    long mod = 1000000000+7;
    int[] child,color,count;
    long[] res;
    ArrayList<Integer>[] tree;
    public static void main(String[] args) throws IOException {
        Main main = new Main();
        main.solve();
        out.flush();
    }
    void solve(){
        int n = sc.nextInt();
        child = new int[n]; color = new int[n]; count = new int[n]; res = new long[n];
        tree = new ArrayList[n];
        for(int i=0;i<n;i++) tree[i] = new ArrayList<>();
        for(int i=0;i<n;i++){
            color[i] = sc.nextInt()-1;
        }
        for(int i=0;i<n-1;i++){
            int a = sc.nextInt()-1, b = sc.nextInt()-1;
            tree[a].add(b); tree[b].add(a);
        }
        dfs(0,-1);
        long total = sum(n);
        for(int i=0;i<n;i++){
            long cur = total - sum(n-count[i]) - res[i];
            out.println(cur);
        }
    }
    void dfs(int cur, int from){
        int son = 1, temp = count[color[cur]];
        for(int to:tree[cur]){
            if(to==from) continue;
            count[color[cur]] = 0;
            dfs(to,cur);
            son += child[to];
            res[color[cur]] += sum(child[to]-count[color[cur]]);
        }
        child[cur] = son;
        count[color[cur]] = temp+son;
    }
    long sum(long n){return n*(n+1)/2;}
}



Measured memory_bytes: 124244
n, k = map(int, input().split())
a = list(map(lambda x: int(x) - 1, input().split()))

history = []
visited = set()
cur = 0
for i in range(k):
    if cur in visited:
        x = history.index(cur)
        y = len(history) - x
        print(history[x+(k-x)%y] + 1)
        exit()

    visited.add(cur)
    history.append(cur)
    cur = a[cur]

print(a[history[k-1]]+1)

Measured memory_bytes: 32268
// clang-format off
#include <bits/stdc++.h>

#define mp make_pair
#define fst first
#define snd second
#define forn(i,n) for (int i = 0; i < int(n); i++)
#define forn1(i,n) for (int i = 1; i <= int(n); i++)
#define popcnt __builtin_popcount
#define ffs __builtin_ffs
#define ctz __builtin_ctz
#define clz __builtin_clz
#define all(a) (a).begin(), (a).end()
 
using namespace std;

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pli = pair<ll,int>;
using pil = pair<int,ll>;
using pll = pair<ll,ll>;
template <typename T> using vec = vector<T>;
using vi = vec<int>;
using vl = vec<ll>;
template <typename T> using que = queue<T>;
template <typename T> using deq = deque<T>;

template <typename T> T id(T b) {return b;};
template <typename T> void chmax(T &x, T y) {if (x < y) x = y;}
template <typename T> void chmin(T &x, T y) {if (x > y) x = y;}
template <typename S, typename K> bool contains(S &s, K k) { return s.find(k) != s.end(); }
void fastio() { ios_base::sync_with_stdio(false); cin.tie(nullptr); }
constexpr ll TEN(int n) { if (n == 0) return 1LL; else return 10LL*TEN(n-1); }
// clang-format on

const int MAX_N = 100000;
int n, A, B, C;
string s[MAX_N];
vec<char> ans;

bool f(char c1, int& a, char c2, int& b, int i) {
    if (a == 0 && b == 0) {
        return false;
    }

    if (a == 0 || b == 0) {
        if (a > 0) {
            a--;
            b++;
            ans.push_back(c2);
        } else {
            a++;
            b--;
            ans.push_back(c1);
        }
        return true;
    }

    if (i < n - 1 && s[i] != s[i + 1]) {
        if (find(all(s[i + 1]), c1) != s[i + 1].end()) {
            a++;
            b--;
            ans.push_back(c1);
        } else {
            a--;
            b++;
            ans.push_back(c2);
        }

        return true;
    }

    if (a >= b) {
        a--;
        b++;
        ans.push_back(c2);
    } else {
        a++;
        b--;
        ans.push_back(c1);
    }

    return true;
}

int main() {
    fastio();

    cin >> n >> A >> B >> C;
    forn(i, n) cin >> s[i];

    forn(i, n) {
        bool ok;
        if (s[i] == "AB") {
            ok = f('A', A, 'B', B, i);
        } else if (s[i] == "AC") {
            ok = f('A', A, 'C', C, i);
        } else {
            ok = f('B', B, 'C', C, i);
        }

        if (!ok) {
            cout << "No\n";
            return 0;
        }
    }

    cout << "Yes\n";
    for (auto c : ans) {
        cout << c << "\n";
    }

    return 0;
}

Measured memory_bytes: 6876
import sys, re
from math import ceil, floor, sqrt, pi, factorial, gcd
from copy import deepcopy
from collections import Counter, deque
from heapq import heapify, heappop, heappush
from itertools import accumulate, product, combinations, combinations_with_replacement
from bisect import bisect, bisect_left, bisect_right
from functools import reduce
from decimal import Decimal, getcontext
# input = sys.stdin.readline 
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 6)
INF = float('inf')
MOD = 10 ** 9 + 7
num_list = []
str_list = []

def main():
    x, a, b = i_map()
   
    
    if a - b >= 0:
        print('delicious')
    elif x + a - b >= 0:
        print('safe')
    else:
        print('dangerous')

if __name__ == '__main__':
    main()


Measured memory_bytes: 77144
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
const int MOD=(int)1e9+7;
using namespace std;

int plus1(int n) {
      int sum = 0;
    while(n>0){
     sum += n % 10;
        n /= 10;
    }
    return sum;
}

int main(){
    int n,a,b;
    int ans = 0;
       cin >> n >> a >> b;
       REP(i,n+1){
         if(plus1(i) >= a && plus1(i) <= b){
             ans += i;
         }
       }
    cout << ans << endl;
    
}

Measured memory_bytes: 256
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
	int N, M;
	cin >> N >> M;
	vector<vector<pair<int, int> > > G(N);
	for (int i = 0; i < M; ++i) {
		int A, B, X;
		cin >> A >> B >> X;
		G[A - 1].push_back(make_pair(B - 1, X + 1));
	}
	vector<int> dp;
	int ans = 0;
	for (int i = 0; i < N; ++i) {
		vector<int> ndp(i + 1);
		for (int j = 0; j < i; ++j) {
			ndp[j] = max(ndp[j], dp[j] - 1);
			ndp[j + 1] = max(ndp[j + 1], dp[j] - 1);
		}
		for (pair<int, int> j : G[i]) {
			ndp[j.first] = max(ndp[j.first], j.second);
		}
		dp = ndp;
		for (int j = 0; j <= i; ++j) {
			if (dp[j] >= 1) ++ans;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 10016
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<iomanip>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,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 fi first
#define sc second
#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll 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())

const int MAX = 510000;
const int MOD = 1000000007;

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

  map<ll,ll> sa;
  vector<ll> wa(N);
  vector<ll> s(N);

  rep(i,N){
    s[i] = (i + 1) - a[i];
    sa[s[i]]++;
    ll w = a[i] + (i + 1);
    wa[i] = w;
    // cout<<s[i]<<" "<<w<<endl;
  }

  ll ans = 0;
  rep(i,N){
    sa[s[i]]--;
    ans += sa[wa[i]];
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 30716
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;
 
public class Main {
	private static FastScanner sc = new FastScanner();
	
	public static void main(String[] args) {
		int N = sc.nextInt();
		int W = sc.nextInt();
		int[] v = new int[N];
		int[] w = new int[N];
		for(int i=0; i<N; i++) {
			v[i] = sc.nextInt();
			w[i] = sc.nextInt();
		}
		
		int[] dp = new int[W+1];
		for(int i=0; i<N; i++) {
			for(int j=0; j<=W; j++) {
				if(j-w[i] >= 0 && dp[j-w[i]] + v[i] > dp[j]) {
					dp[j] = dp[j-w[i]] + v[i];
				}
			}
		}
		
		int max = 0;
		for(int j=0; j<=W; j++) {
			if(dp[j] > max) {
				max = dp[j];
			}
		}
		System.out.println(max);
	}
	
	static class FastScanner {
        private final InputStream in = System.in;
        private final byte[] buffer = new byte[1024];
        private int ptr = 0;
        private int buflen = 0;
        private boolean hasNextByte() {
            if(ptr < buflen) {
                return true;
            } else {
                ptr = 0;
                try {
                    buflen = in.read(buffer);
                } catch(IOException e) {
                    e.printStackTrace();
                }
                if(buflen <= 0) {
                    return false;
                }
            }
            return true;
        }
        private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
        private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
        private void skipUnprintable() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;}
        public boolean hasNext() { skipUnprintable(); return hasNextByte();}
        public String next() {
            if (!hasNext()) throw new NoSuchElementException();
            StringBuilder sb = new StringBuilder();
            int b = readByte();
            while(isPrintableChar(b)) {
                sb.appendCodePoint(b);
                b = readByte();
            }
            return sb.toString();
        }
        public long nextLong() {
            return Long.parseLong(next());
        }
        public int nextInt(){
            return Integer.parseInt(next());
        }
        public double nextDouble(){
            return Double.parseDouble(next());
        }
    }
}

Measured memory_bytes: 25016
#include<bits/stdc++.h>
#include <stdio.h>
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#include <limits.h>
#include <math.h>
#include <algorithm>
#include <deque>
#include <queue>
#include <stack>
#include <list>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <string>
#include <vector>
#include <bitset>
#include <functional>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef double db;
typedef long double ldb;
#define rep(i,a,b) for(i=a;i<b;i++)
#define repu(i,a,b) for(i=a;i<=b;i++)
#define repd(i,a,b) for(i=a;i>=b;i--)
#define repc(i,a,b,c) for(i=a;i<b;i+=c)
#define repcu(i,a,b,c) for(i=a;i<=b;i+=c)
#define repcd(i,a,b,c) for(i=a;i>=b;i-=c)
#define FIN freopen("input.in","r",stdin)
#define FOUT freopen("output.out","w",stdout)
#define CC(a) memset(a,0,sizeof(a))
#define PII pair<int,int>
#define PLL pair<LL,LL>
#define VI vector<int>
#define VII vector<PII>
#define VLL vector<PLL>
#define all(x) x.begin(),x.end()
#define mp make_pair
#define pb push_back
#define pf push_front
#define fi first
#define se second

template<typename T>inline void gn(T &x){
	x=0;T f=1;char ch=getchar();
	while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
	while(isdigit(ch)){x=x*10+ch-'0';ch=getchar();}
	x*=f;
}
template<typename T>inline void gt(T x){
	if(!x)return;
	gt(x/10);putchar(x%10+'0');
}

struct TT{
	LL a,b;
}tt,ss;
LL t,n,m,ans;
LL MOD=1e9+7;
char vis[11];

LL check(LL x){
	LL i,j,k,l,res;
	while(x){
		k=x%10;
		if(vis[k])return 0;
		x/=10;
	}
	return 1;
}

int main()
{
	LL i,j,k,l,res;
	cin>>n>>m;
	for(i=0;i<m;i++)cin>>k,vis[k]=1;
	for(i=n;;i++){
		if(check(i)){
			ans=i;break;
		}
	}
	cout<<ans<<endl;
	return 0;
}

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

#define int long long
#define itn int
#define For(i, a, b) for (int i = (a); i <= static_cast<int>(b); i++)
#define Forr(i, a, b) for (int i = (a); i >= static_cast<int>(b); i--)
#define rep(i, n) For(i, 0, n - 1)
#define repall(i, arr) for (auto& i : (arr))
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define dump(x) cerr << #x << " = " << (x) << '\n'
#define dump2(x, y) \
    cerr << #x << " = " << (x) << " " << #y << " = " << (y) << '\n'
#define SZ(x) ((int)(x).size())
#define bit(n) (1LL << (n))
constexpr int MOD = 1e9 + 7;

template <typename T>
using pq = priority_queue<T>;
template <typename T>
using pqr = priority_queue<T, vector<T>, greater<T>>;
const int INF = LLONG_MAX / 2;
using P = pair<int, int>;
using vec = vector<int>;
template <typename T>
using mat = vector<vector<T>>;

// clang-format off
template <typename T1, typename T2>
ostream& operator<<(ostream& stream, const pair<T1, T2>& p) { return stream << p.first << "," << p.second; }
template <typename T>
void print(const vector<T> vec) { rep (i, vec.size() - 1) cout << vec[i] << ' '; cout << vec[vec.size() - 1] << '\n'; }
template <typename Arg>
void print(const Arg arg) { cout << arg << '\n'; }
template <typename Head, typename... Args>
void print(const Head head, const Args... args) { cout << head << " "; print(args...); }
template <typename T, typename U>
void init(vector<T>& v, vector<U>& w) { rep (i, v.size()) cin >> v[i] >> w[i]; }
template <typename T>
void init(vector<T>& v) { rep (i, v.size()) cin >> v[i]; }
template <typename T>
T sum_(vector<T> vec, T init = 0) { return std::accumulate(all(vec), T(init)); }
template<typename T>
bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } return false; }
template<typename T>
bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } return false; }
template <typename T>
int index(const T& vec, const typename T::iterator it) { return distance(vec.begin(), it); }
template <typename T = int>
mat<T> mmat(int n, int m=0) { return mat<T>(n, vector<T>(m)); }
template <typename T = int>
vector<T> ivec(int n) { vector<T> v(n); init(v); return v; }
// clang-format on

void yn(bool tf) { print(tf ? "Yes" : "No"); }
void YN(bool tf) { print(tf ? "YES" : "NO"); }

int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
// -------------------------------------------------------------------
// sort 1 2 3 4
// pqr 1 2 3 must impl >

signed main() {
    cin.tie(0), cout.tie(0), ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    vec a = ivec(n);
    rep (i, n)
        a[i] /= 2;

    int tmp = 1;
    rep (i, n) {
        if (tmp > a[i])
            tmp = tmp * a[i] / gcd(tmp, a[i]);
        else
            tmp = tmp * a[i] / gcd(a[i], tmp);
    }
    bool ok = true;
    repall (x, a) {
        if ((tmp / x) % 2 == 0) {
            ok = false;
            break;
        }
    }
    if (not ok) {
        print(0);
        return 0;
    }

    int ans = m / tmp;
    if (ans % 2 == 0)
        print(ans / 2);
    else
        print((ans + 1) / 2);

    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long l;
l o=100;
int main()
{
	l n;
	cin>>n;
	int i=0;
	for(;o<n;i++)
	{
		o+=o/100;
	}
	cout<<i<<endl;
	return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <string>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#define re register
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define MAXN 4000007
#define ll long long
#define mo 19930726
#define ls rt<<1
#define rs rt<<1|1
using namespace std;
typedef unsigned long long ull;
int n,k;
int main()
{
	cin>>n>>k;
	int ans=1;
	n-=k;
	ans+=n/(k-1);
	n%=(k-1);
	if(n) ans+=1;
	cout<<ans;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main()
{
	string s;
	cin>>s;
	for(int i=0;i<s.length();i++)
	if(s[i]==s[i+1])
	{
		printf("%d %d\n",i+1,i+2);
		return 0;
	}
	for(int i=0;i<s.length()-1;i++)
	if(s[i]==s[i+2])
	{
		printf("%d %d\n",i+1,i+3);
		return 0;
	}
	printf("-1 -1\n");
	return 0;
}

Measured memory_bytes: 512
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
using namespace std;


int main(int argc, char* argv[])
{
    int n;
    scanf("%d", &n);
    map<int,int> z0;
    int i;
    for(i=0; i<n; i++) {
        int tmp;
        scanf("%d", &tmp);
        z0[tmp]++;
    }

    map<int,int> z1;
    int m;
    scanf("%d", &m);
    for(i=0; i<m; i++) {
        int tmp;
        scanf("%d", &tmp);
        z1[tmp]++;
    }

    auto it=z1.begin();
    for(; it!=z1.end(); ++it) {
        auto it2=z0.find(it->first);
        if(it2==z0.end()) {
            printf("NO\n"); return 0;
        }
        if(it2->second<it->second) {
            printf("NO\n"); return 0;
        }
    }
    printf("YES\n");

    return 0;
}


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

const ll zero = 0;

int main() {
    ll N, K; cin >> N >> K;
    ll A[N];
    ll F[N];
    REP(i, N) cin >> A[i];
    REP(i, N) cin >> F[i];
    sort(A, A+N);
    ll l=-1, r=0, m;
    REP(i, N){
        if (A[i]*F[i] > r){
            r = A[i]*F[i];
        }
    }
    r += 1;
    priority_queue<ll> q;
    ll cost;
    while (r-l>1){
        m = (l+r)/2;
        REP(i, N){
            q.push(-(m/F[i]));
        }
        cost = 0;
        REP(i, N){
            if (A[i] > -q.top()){
                cost += A[i] + q.top();
            }
            q.pop();
        }
        if (cost <= K){
            r = m;
        }
        else{
            l = m;
        }
    }

    cout << r << endl;

}

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

int n,dp[35];

int func(){
	n+=2;
	dp[2]=1;
	for(int i=3;i<=n;i++){
		dp[i]=dp[i-3]+dp[i-2]+dp[i-1];
	}
	int ans=((dp[n]-1)/10)/365+1;
	return ans;
}

int main(){
	while(1){
		cin>>n;
		if(n==0) break;
		cout<<func()<<endl;
	}
}

Measured memory_bytes: 1160
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
#include <random>
#include <cassert>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
#define MEM(a,b) memset((a),(b),sizeof(a))
const LL INF = 1e9 + 7;
const int N = 2e5 + 10;
class UnionFind
{
public:
	int p[N];
	void init(int n = N)
	{
		memset(p, -1, sizeof(int) * n);
	}
	int treesize(int x)
	{
		return -p[Find(x)];
	}
	int Find(int x)
	{
		int s = x;
		while (p[s] >= 0) s = p[s];
		while (x != s)
		{
			int t = p[x];
			p[x] = s;
			x = t;
		}
		return s;
	}
	void Union(int x, int y)
	{
		int px = Find(x);
		int py = Find(y);
		if (p[px] > p[py]) swap(px, py);
		p[px] += p[py];
		p[py] = px;
	}
} uf;
int a[N];
map<int, int> mc1[N], mc2[N];
int check(map<int,int> &mc1, map<int,int> &mc2)
{
	int ans = 0;
	for (auto& p : mc1)
	{
		if (mc2.count(p.first))
			ans++;
	}
	return ans;
}
int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int n, m;
	cin >> n >> m;
	uf.init();
	for (int i = 1; i <= n; i++) cin >> a[i];
	while (m--)
	{
		int x, y;
		cin >> x >> y;
		if (uf.Find(x) != uf.Find(y))
			uf.Union(x, y);
	}
	for (int i = 1; i <= n; i++)
	{
		mc1[uf.Find(i)][i] = 1;
		mc2[uf.Find(i)][a[i]] = 1;
	}
	int ans = 0;
	for (int i = 1; i <= n; i++)
		ans += check(mc1[i], mc2[i]);
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 29568
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cfloat>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
#define int long long
#define ll long long
#define eps LDBL_EPSILON
#define mod (ll)1000000007
#define INF LLONG_MAX/10
#define P pair<int,int>
#define prique priority_queue
using namespace std;
int n, b[110], a[110];
signed main() {
	cin >> n;
	rep(i, n - 1)cin >> b[i];
	a[0] = b[0];
	REP(i, n - 1) {
		a[i] = max(a[i], b[i - 1]);
		a[i - 1] = min(a[i - 1], b[i - 1]);
	}
	int ans = 0;
	rep(i, n)ans += a[i];
	cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,a;
vector<int> v;
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)cin>>a,v.push_back(a-1);
	vector<int> ans;
	while(!v.empty())
	{
		bool f=1;
		for(int i=v.size()-1;i>=0;i--)
			if(v[i]==i)
			{
				ans.push_back(i+1);
				v.erase(v.begin()+i);
				f=0;
				break;
			}
		if(f)cout<<"-1\n",exit(0);
	}
	reverse(ans.begin(),ans.end());
	for(int i:ans)cout<<i<<'\n';
}


Measured memory_bytes: 256
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.bigint, std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static File _f;
void file_io(string fn) { _f = File(fn, "r"); }
static string[] s_rd;
T _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }
T RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }
T[] RDA(T = long)(T fix = 0) { if (_f.isOpen)  return _RDA!T(_f, fix); else return _RDA!T(fix); }

size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

void chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
T lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }

//long mod = 10^^9 + 7;
long mod = 998_244_353;
//long mod = 1_000_003;
void moda(T)(ref T x, T y) { x = (x + y) % mod; }
void mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(T)(ref T x, T y) { x = (x * y) % mod; }
void modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }
void modd(T)(ref T x, T y) { x.modm(y.modpow(mod - 2)); }

void main()
{
	auto S = RD!string;

	writeln(S[2] == S[3] && S[4] == S[5] ? "Yes" : "No");
	stdout.flush;
	debug readln;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for (int i = s; i < (int)(n); i++)
#define out(x) cout << x << endl
#define INF 1000000;
#include <map>
#include <math.h>
 
using ll = long long;
using namespace std;

ll n, k;
const ll mod = 1000000007;


int main(){
    string s;
    cin >> s;
    sort(s.begin(), s.end());
    if(s[0]==s[1]&&s[2]==s[3]&&s[1]!=s[2]) out("Yes");
    else out("No");
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		//List<String> list= new ArrayList<String>(Arrays.asList(s.split("")));
		//List<Integer> list=new ArrayList<Integer>();
		//Integer[] array = new Integer[m];
		int n = sc.nextInt();
		while(true) {
			Integer w = new Integer(n);
			String s = w.toString();
			List<String> list= new ArrayList<String>(Arrays.asList(s.split("")));
			int count=0;
			for(int i=0;list.size()-1>i;i++) {
				if(list.get(i).equals(list.get(i+1)))
					count++;
			}
			if(count==list.size()-1) {
				System.out.println(n);
				System.exit(0);
			}
			n++;
		}
	}
}

Measured memory_bytes: 21972
var
a:array[0..105] of integer;
n,i,j,x,y:integer;
begin
readln(n);
for i:=1 to n do read(a[i]);
for i:=1 to n-1 do
  for j:=i+1 to n do
    if a[i]<a[j] then
      begin
        a[0]:=a[i];
        a[i]:=a[j];
        a[j]:=a[0];
      end;
x:=0;
y:=0;
for i:=1 to n do
  if odd(i) then x:=x+a[i]
            else y:=y+a[i];
writeln(x-y);
end.

Measured memory_bytes: 128
/*
これを入れて実行
g++ code.cpp
./a.out
*/

#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <cmath>
#include <math.h>
#include <tuple>
#include <iomanip>
#include <stack>

using namespace std;
typedef long long ll;
typedef long double ld;

int dy4[4] = { -1, 0, +1, 0 };
int dx4[4] = { 0, +1, 0, -1 };
int dy8[8] = { -1, -1, 0, 1, 1, 1, 0, -1 };
int dx8[8] = { 0, 1, 1, 1, 0, -1, -1, -1 };

const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;

bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
	return f.second > s.second;
}

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

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

ll nCr(ll n, ll r){
	if (r == 0 || r == n){
		return 1;
	}
	else if (r == 1){
		return n;
	}
	return (nCr(n - 1, r) + nCr(n - 1, r - 1));
}

ll nPr(ll n, ll r){
	r = n - r;
	ll ret = 1;
	for (ll i = n; i >= r + 1; i--) ret *= i;
	return ret;
}

//-----------------------ここから-----------

int main(void){
	int n;
	cin >> n;

	vector<int> p(n);
	for (int i = 0; i < n; i++) cin >> p[i];

	int mi = p[0];
	int ans = 1;
	for (int i = 1; i < n; i++){
		if (mi >= p[i]){
			ans++;
		}
		mi = min(mi, p[i]);
	}

	cout << ans << endl;
}



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

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

  int x = 0;
  int ans = 0;
  for (int i = 0; i < N; i++) {
    if (S[i] == 'I') x++;
    if (S[i] == 'D') x--;
    ans = max(x, ans);
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)  for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define pb emplace_back
#define eb emplace_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
#define fi first
#define se second
#define pi M_PI
#define PQ(T) priority_queue<T>
#define SPQ(T) priority_queue<T,vector<T>,greater<T>>
#define dame(a) {out(a);return 0;}
#define decimal cout<<fixed<<setprecision(15);
#define dupli(a) a.erase(unique(all(a)),a.end())
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef tuple<ll,ll,ll,ll> PPP;
typedef multiset<ll> S;
using vi=vector<ll>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;
using vvvvi=vector<vvvi>;
using vp=vector<P>;
using vvp=vector<vp>;
using vb=vector<bool>;
using vvb=vector<vb>;
const ll inf=1001001001001001001;
const ll INF=1001001001;
const ll mod=1000000007;
const double eps=1e-10;
template<class T> bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<'\n';}
template<class T> void outvp(T v){rep(i,v.size())cout<<'('<<v[i].fi<<','<<v[i].se<<')';cout<<'\n';}
template<class T> void outvvp(T v){rep(i,v.size())outvp(v[i]);}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<'\n';}
template<class T> void outvv(T v){rep(i,v.size())outv(v[i]);}
template<class T> bool isin(T x,T l,T r){return (l)<=(x)&&(x)<=(r);}
template<class T> void yesno(T b){if(b)out("yes");else out("no");}
template<class T> void YesNo(T b){if(b)out("Yes");else out("No");}
template<class T> void YESNO(T b){if(b)out("YES");else out("NO");}
template<class T> void noyes(T b){if(b)out("no");else out("yes");}
template<class T> void NoYes(T b){if(b)out("No");else out("Yes");}
template<class T> void NOYES(T b){if(b)out("NO");else out("YES");}
void outs(ll a,ll b){if(a>=inf-100)out(b);else out(a);}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll modpow(ll a,ll b){ll res=1;a%=mod;while(b){if(b&1)res=res*a%mod;a=a*a%mod;b>>=1;}return res;}

int main(){
    ll n;cin>>n;
    vector<double> v(n);
    rep(i,n)cin>>v[i];
    vector<vector<double>> dp(n+1,vector<double>(n+1));
    dp[0][0]=1;
    rep(i,n)rep(j,n){
        if(i+j>=n)break;
        dp[i+1][j]+=dp[i][j]*v[i+j];
        dp[i][j+1]+=dp[i][j]*(1-v[i+j]);
    }
    double ans=0;
    rep(i,n/2+1)ans+=dp[n-i][i];
    decimal;
    out(ans);
}

Measured memory_bytes: 73716
#include<bits/stdc++.h>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define rrep(i,a) for(int i=(int)a-1;i>=0;--i)
#define REP(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RREP(i,a,b) for(int i=(int)a-1;i>=b;--i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;
 
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;
}


ll gcd(ll n, ll m) {
    ll tmp;
    while (m!=0) {
        tmp = n % m;
        n = m;
        m = tmp;
    }
    return n;
}
 
ll lcm(ll n, ll m) {
    return abs(n) / gcd(n, m)*abs(m);//gl=xy
}

using namespace std;

void solve()
{
	int n;
	cin>>n;
	vector<ll>a(n);
	rep(i,n)cin>>a[i];
	rep(i,n){
		if(a[i]==0){
			cout<<0;
			return;
		}
	}
	const ll m=1000000000000000000;
	ll mul=1;
	rep(i,n){
		if(mul>(m+a[i]-1)/a[i]){
			cout<<-1;
			return;
		}
		mul*=a[i];
		if(mul>m){
			cout<<-1;
			return;
		}
	}
	cout<<mul;
}

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


Measured memory_bytes: 3988
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <string.h>
#include <utility>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>

using namespace std;
typedef long long ll;

#define INT_MAX std::numeric_limits<int>().max()
#define INT_MIN std::numeric_limits<int>().min()
#define REP(i,n) for(int i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())

ll N, W;
ll w1;
pair<ll, ll> obj[110];
ll dp[110][410][110] = { 0 };

// i 個目の品物を見ているときに基準からの重さの差が j で入れたものの数が k だった場合
// 価値を返す
ll search(ll i, ll j, ll k) {
    printf("i %lld j %lld k %lld\n", i, j, k);
    if(i >= N) { printf("return\n"); return 0; }
    ll ret = 0;
    if((j + obj[i].first) + (w1 * (k+1)) <= W) {
        printf("in k=%lld\n", k);
        ret = max(ret, search(i+1, j + obj[i].first, k+1) + obj[i].second);
        printf("1 ret %lld\n", ret);
    }
    printf("in2\n");
    ret = max(ret, search(i+1, j, k) );
    printf("2 ret %lld\n", ret);
    return ret;
}

int main()
{
    cin >> N >> W;
    REP(i, N) {
        ll w, v;
        cin >> w >> v;
        if(i == 0){ w1 = w; }
        obj[i] = make_pair(w - w1, v);
    }
    for(ll i=N-1; i>=0; --i) {
        for(ll j=409; j>=0; --j) {
            for(ll k=N; k>=0; --k) {
                if((j + obj[i].first) + (w1 * (k+1)) <= W) {
                    dp[i][j][k] = max(dp[i][j][k], dp[i+1][j + obj[i].first][k+1] + obj[i].second);
                }
                dp[i][j][k] = max(dp[i][j][k], dp[i+1][j][k]);
            }
        }
    }
    printf("%lld\n", dp[0][0][0]);
    //printf("%lld\n", search(0, 0, 0));

    return 0;
}


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

int main()
{
    double head,legs;
    cin>>head>>legs;
    if((int)legs%2!=0)
    {
        cout<<"No"<<endl;
    }
    else
    {
        if(legs/head<=4 && legs/head>=2)
        {
            cout<<"Yes"<<endl;
        }
        else
        {
            cout<<"No"<<endl;
        }
    }
    
    
    return 0;
}

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

int main(){
  int N,M;
  cin>>N>>M;
  vector<multiset<int>> A(N);
  for (int i=0; i<N; i++){
    int K;
    cin>>K;
    for (int j=0; j<K; j++){
      int Aj;
      cin>>Aj;
      A.at(i).insert(Aj);
    }
  }
  int total_count=0;
  for (int j=1; j<=M; j++){
    int count=0;
    for (int i=0; i<N; i++){
      if (A.at(i).find(j)!=A.at(i).end()){
        count++;
      }
    }
    if (count==N){
      total_count++;
    }   
  }
  cout<<total_count<<endl;
}
  

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ADD(a, b) a = (a + ll(b)) % mod
#define MUL(a, b) a = (a * ll(b)) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define all(a) (a).begin(), (a).end()
#define sz(v) (int)(v).size()
#define pb push_back
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<int, pi> ppi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> mat;
typedef complex<double> comp;
void Debug() {cerr << '\n'; }
template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){
	cerr<<arg<<" ";Debug(rest...);}
template<class T>ostream& operator<<(ostream& out,const vector<T>& v) {
	out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<<", ";out<<v.back();}out<<"]";return out;}
template<class S, class T>ostream& operator<<(ostream& out,const pair<S, T>& v){
	out<<"("<<v.first<<", "<<v.second<<")";return out;}
const int MAX_N = 500010;
const int MAX_V = 100010;
const double eps = 1e-6;
const ll mod = 1000000007;
const int inf = 1 << 30;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;
mt19937 rng; //use it by rng() % mod, shuffle(all(vec), rng)
///////////////////////////////////////////////////////////////////////////////////////////////////

int N, K;
string S;

void solve() {
	cin >> N >> K;
	S.resize(N + 2);
	S[0] = 'R';
	rep(i, 1, N + 1) {
		cin >> S[i];
	}
	S[N + 1] = 'L';
	int cnt = 0;
	rep(i, 1, N + 1) {
		if(S[i] == 'L') {
			cnt += (S[i - 1] == 'R');
		}
		else {
			cnt += (S[i + 1] == 'L');
		}
	}
	// debug(cnt);
	cout << N - max(cnt - 2 * K, 1) << "\n";
}

uint32_t rd() {
	uint32_t res;
#ifdef __MINGW32__
	asm volatile("rdrand %0" :"=a"(res) ::"cc");
#else
	res = std::random_device()();
#endif
	return res;
}

int main() {
#ifndef LOCAL
	ios::sync_with_stdio(false);
    cin.tie(0);
#endif
    cout << fixed;
	cout.precision(20);
    cerr << fixed;
	cerr.precision(6);
	rng.seed(rd());
#ifdef LOCAL
	//freopen("in.txt", "wt", stdout); //for tester
	if(!freopen("in.txt", "rt", stdin)) return 1;
#endif	
	solve();
    cerr << "Time: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
	return 0;
}



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

typedef long long ll;

#define        optimize           ios::sync_with_stdio(0); cin.tie(0);
#define PI    acos(-1.0)
#define pb push_back
#define YES cout<<"YES"<<endl;
#define NO cout<<"NO"<<endl;
#define RESET(a, b) memset(a, b, sizeof(a))
#define pii pair <int, int>
#define gcd(a, b) __gcd(a, b)
#define min3(a, b, c) min(c, min(a, b))
#define max3(a, b, c) max(c, max(a, b))

#define        MX        200005

vector <int> ara;

int main()
{
    optimize
    ll x, k, d;
    cin>>x>>k>>d;
    x = abs(x);

    ll p = (x/d);
    ll ans = (x%d);

    if(p == k){
        cout<<ans<<endl;
    }
    else if(p < k){
        k -= p;
        if(k & 1) cout<<abs(ans-d)<<endl;
        else cout<<ans<<endl;
    }
    else{
        cout<<x-(k*d)<<endl;
    }

}


Measured memory_bytes: 3648
n, k = map(int, input().split())
p = list(map(int, input().split()))
maxI = 0
maxT = 0
t = 0
for i in range(n):
    t += p[i]
    if k <= i:
        t -= p[i-k]
    if maxT < t:
        maxT = t
        maxI = i
ans = 0


def calc(n):
    return n*(n+1)/2/n
    ans = 0
    for i in range(1, n+1):
        ans += i/n
    return ans


for i in range(maxI-k+1, maxI+1):
    #print(i, p[i])
    ans += calc(p[i])
# print(p)
#print(maxT, maxI)
print(ans)


Measured memory_bytes: 32184
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long N = sc.nextLong();
		long M = sc.nextLong();
		if (N==1&&M ==1) {
			System.out.println(1);
		} else if (N==1) {
			System.out.println(M-2);
		} else if (M==1) {
			System.out.println(N-2);
		} else {
			long temp = N*M;
			temp = temp-N*2-M*2+4;
			System.out.println(temp);
		}
	}
}


Measured memory_bytes: 21588