akhauriyash/Code-Regression huggingface dataset:
#[allow(unused_macros)]
macro_rules ! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; let mut next = || { iter . next ( ) . unwrap ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let stdin = std :: io :: stdin ( ) ; let mut bytes = std :: io :: Read :: bytes ( stdin . lock ( ) ) ; let mut next = move || -> String { bytes . by_ref ( ) . map ( | r | r . unwrap ( ) as char ) . skip_while ( | c | c . is_whitespace ( ) ) . take_while ( | c |! c . is_whitespace ( ) ) . collect ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! input_inner { ( $ next : expr ) => { } ; ( $ next : expr , ) => { } ; ( $ next : expr , mut $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let mut $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; ( $ next : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! read_value { ( $ next : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ next , $ t ) ) ,* ) } ; ( $ next : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ next , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ next : expr , chars ) => { read_value ! ( $ next , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ next : expr , usize1 ) => { read_value ! ( $ next , usize ) - 1 } ; ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) } ; }

fn main() {
    input! {
        n: u64, k: u64
    }

    let mut cnt = 0;
    if k % 2 == 0 {
        if n >= k/2 {
            cnt += ((n - k/2) / k + 1).pow(3);
        }
    }
    cnt += (n/k).pow(3);
    println!("{}", cnt);
}

Measured memory_bytes: 4352
from sys import stdin
input = stdin.readline

n = int(input())
*a, = map(int, input().split())
cnt = 0
for i in range(n):
	for j in range(i):
		for k in range(j):
			x, y, z = sorted([a[i], a[j], a[k]])
			if z < x + y and x != y and y != z:
				cnt += 1
print(cnt)


Measured memory_bytes: 73392
n,k=map(int,input().split())
p=[int(i) for i in input().split()]
s=[]
for i in range(10):
    if i not in p:
        s.append(str(i))
    
for x in range(n,10*n):
    flg=True
    for d in str(x):
        if d not in s:
            flg=False
    if flg:
        print(x)
        break

Measured memory_bytes: 40940
def main():
    strA = input()
    listA = strA.split(" ")

    N = int(listA[0])
    R = int(listA[1])

    nRate = 0
    if N >= 10:
        nRate = R
    else:
        nRate = R + (100 * (10 - N))

    print(nRate)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
A = int(input())
B = int(input())
C = int(input())
X = int(input())
 
res = 0
 
for i in range(A + 1):
  for j in range(B + 1):
    for k in range(C + 1):
      if 500*i + 100*j + 50*k == X:
        res += 1
 
print(res)

Measured memory_bytes: 3064
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
using namespace std;

int main() {
		int a, b, c, d, e;
		cin >> a >> b >> c >> d >> e;
		if (a > 0) {
			cout << (b - a)*e << endl;
		}
		else if (b < 0) {
			cout << (b - a)*c << endl;
		}
		else {
			cout << (-a)*c + b*e + d << endl;
		}
}

Measured memory_bytes: 3080
#include <stdio.h>
#include <math.h>

#define SQ(x) ((x) * (x))
#define EPS (1e-9)

double getAreaTriangle(int theta)
{
    return (sin(1.0 * theta * M_PI / 180));
}

int main(void)
{
    int i;
    int m, n;
    double area[2];
    int sum, theta;
    
    while (1){
        scanf("%d", &m);
        
        if (m == 0){
            break;
        }
        area[0] = area[1] = 0;
        
        sum = 360;
        for (i = 0; i < m - 1; i++){
            scanf("%d", &theta);
            area[0] += getAreaTriangle(theta);
            sum -= theta;
        }
        area[0] += getAreaTriangle(sum);
        
        scanf("%d", &n);
        
        sum = 360;
        for (i = 0; i < n - 1; i++){
            scanf("%d", &theta);
            area[1] += getAreaTriangle(theta);
            sum -= theta;
        }
        area[1] += getAreaTriangle(sum);
        
        if (fabs(area[0] - area[1]) < EPS){
            printf("0\n");
        }
        else if (area[0] > area[1]){
            printf("1\n");
        }
        else {
            printf("2\n");
        }
    }
    
    return (0);
}

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

typedef long long ll;

int main(){
    int N, K;
    cin >> N >> K;
    
    int m=1;
    for(int i=0; i<N; i++){
        m = min(m*2,m+K);
    }
    
    cout << m << endl;
}


Measured memory_bytes: 256
import java.util.Scanner

object Main extends App {
  val sc = new Scanner(System.in)
  val N = sc.nextInt()
  val a = List.fill(N)(sc.nextInt())

  println(calc(N, a))


  def calc(N: Int, a: List[Int]) : Int = {
    val alice, bob = 0
    a.sorted.foldLeft(0)((a, b) => b - a)
  }
}


Measured memory_bytes: 55488
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from itertools import permutations
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    n, k = LI()
    L = [[1]*n]
    ans = 1
    f = [1]
    N = 10**6
    for i in range(N):
        f.append(f[-1]*(i+1)%mod)
    inv = [None]*(N+1)
    inv[N] = pow(f[N],mod-2,mod)
    for i in range(N)[::-1]:
        inv[i] = inv[i+1]*(i+1)%mod
    def comb(a,b):
        return f[a]*inv[b]*inv[a-b]%mod
    ans = comb(2*n-1,n)
    if k + 1 >= n:
        print(ans)
    else:
        for t in range(k+1,n):
            ans -= comb(n,t)*comb(n-1,t)%mod
            ans %= mod
        print(ans)
    return

#Solve
if __name__ == "__main__":
    solve()


Measured memory_bytes: 116976
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
const int INF = 100000000;
const int MAX_N = 100;
typedef pair<int , int> P;
typedef long long ll;
 
int main () {
  ll X, A, B;
  cin >> X;
  int tmp = 0;
  for (ll i = 0; i <= 1000; ++i) {
    ll tmpA = i * i * i * i * i;
    for (ll j = 0; j <= 1000; ++j) {
      ll tmpB = j * j * j * j * j;
      if (tmpA - tmpB == X) {
        // printf("%lld %lld %lld\n", i, j, tmpA-tmpB);
        A = i;
        B = j;
        tmp = 1;
        break;
      }
      else if (tmpA + tmpB == X) {
        // printf("%lld %lld %lld\n", i, -j, tmpA+tmpB);
        A = i;
        B = 0 - j;
        tmp = 1;
        break;
      }
    }
    if (tmp != 0) {
      break;
    }
  }
  printf("%lld %lld\n", A, B);
  return 0;
}

Measured memory_bytes: 3728
S = str(input())
 
ans = 1
 
now = S[0]  # 最初は一文字目を取り出せばよい
pointa = 1
while True:
    if pointa >= len(S):
        break
    if len(now) == 2:
        now = S[pointa]  # 一文字取り出せば良い
        pointa += 1
        ans += 1
        continue
    # 今nowは一文字
    if now != S[pointa]:  # 文字が違うのであれば一文字取り出せばよい
        ans += 1
        now = S[pointa]
        pointa += 1
    elif now == S[pointa]:  # nowと今見ている文字が等しいなら二文字取り出すしかない
        if pointa >= len(S)-1:
            break
        now = S[pointa] + S[pointa+1]
        pointa += 2
        ans += 1
 
print(ans)

Measured memory_bytes: 3500
#include<stdio.h>
#include<string.h>
   
#define M 1046527
#define NIL (-1)
#define L 14
   
char H[M][L];
   
// 文字から数値に変換
int getChar(char ch) {
  if ( ch == 'A' ) return 1;
  else if ( ch == 'C' ) return 2;
  else if ( ch == 'G' ) return 3;
  else if ( ch == 'T' ) return 4;
  else return 0;
}
   
// 文字れt流から数値へ変換してkeyを生成する
long long getKey(char str[]) {
  long long sum = 0, p = 1, i;
  for ( i = 0; i < strlen(str); i++ ) {
    sum += p*(getChar(str[i]));
    p *= 5;
  }
  return sum;
}
   
int h1(int key){ return key % M; }
int h2(int key){ return 1 + (key % (M - 1)); }
   
int find(char str[]) {
  long long key, i, h;
  key = getKey(str);
  for ( i = 0;; i++) {
    h = (h1(key) + i * h2(key)) % M;
    if ( strcmp(H[h], str) == 0 ) return 1;
    else if (strlen(H[h]) == 0 ) return 0;
  }
  return 0;
}
   
int insert(char str[]) {
  long long key, i, h;
  key = getKey(str);
  for ( i = 0; ; i++ ) {
    h = (h1(key) + i * h2(key)) % M;
    if ( strcmp(H[h], str) == 0 ) return 1;
    else if ( strlen(H[h]) == 0 ) {
      strcpy(H[h], str);
      return 0;
    }
  }
  return 0;
}
  
int main() {
  int i, n, h;
  char str[L], com[9];
  for ( i = 0; i < M; i++ ) H[i][0] = '\0';
  scanf("%d", &n);
  for ( i = 0; i < n; i++ ) {
    scanf("%s %s", com, str);
   
    if ( com[0] == 'i' ) {
      insert(str);
    } else {
      if ( find(str) ) {
        printf("yes\n");
      }  else {
        printf("no\n");
      }
    }
  }
  return 0;
}


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

int main() {
  string str;
  cin >> str;
  int ans = 700;
  for (int i = 0; i < 3; i++) {
    if (str.at(i) == 'o') {
      ans += 100;
    }
  }
  cout << ans << endl;
}

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

typedef long long int ll;
const int maxn = 1e5 + 10;
ll a[maxn];
void solved(){
	int n,m;cin>>n>>m;
	ll sum = 0;
	for(int i = 1; i <= n; i++){
		cin>>a[i];sum += a[i];
	}
	double s = sum * 1.0 / (4 * m);
	int cnt = 0;
	for(int i = 1; i <= n; i++){
		if(a[i] >= s)cnt++;
	}
	if(cnt >= m)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
} 
int main(){
	solved();
	return 0;
} 


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


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

	int ans = 0;
	rep(i, n)if (h[i] >= k) ans++;

	cout << ans << endl;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define Set(a,b) memset(a,b,sizeof(a))
template<class T>inline void init(T&x){
	x=0;char ch=getchar();bool t=0;
	for(;ch>'9'||ch<'0';ch=getchar()) if(ch=='-') t=1;
	for(;ch>='0'&&ch<='9';ch=getchar()) x=(x<<1)+(x<<3)+(ch-48);
	if(t) x=-x;return;
}typedef long long ll;
const int N=51;
int n,m;
typedef pair<int,int> PA;
PA A[N];
map<PA,int> M;
int main()
{
	init(n);
	for(int i=1;i<=n;++i) init(A[i].first),init(A[i].second);
	sort(A+1,A+1+n);
	int Ans=n;
	for(int i=1;i<=n;++i) {
		for(int j=i+1;j<=n;++j) {
			M.clear();
			int p=A[j].first-A[i].first;
			int q=A[j].second-A[i].second;
			int ans=0;
			for(int l=1,r=1;l<=n;l=r){
				while(r<=n&&A[r].first==A[l].first) ++r;
				if(q>0) {
					for(int i=l;i<r;++i){
						if(M.count(PA(A[i].first-p,A[i].second-q))) ;
						else ++ans;
						M[A[i]]=1;
					}
				}else {
					for(int i=r-1;i>=l;--i) {
						if(M.count(PA(A[i].first-p,A[i].second-q))) ;
						else ++ans;
						M[A[i]]=1;
					}
				}
			}
			Ans=min(ans,Ans);
		}
	}
	cout<<Ans<<endl;
	return 0;
}


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

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

#define rep(i,cc,n) for(int i=cc;i<n;++i)
#define lrep(i,cc,n) for(long long i=cc;i<n;++i)
#define sqrep(i,cc,n) for(long long i=cc;i*i<=n;++i)
#define rrep(i,cc,n) for(long i=cc;i>n;--i)
#define pii pair<int, int>
#define pll pair<long long, long long>
 
using ll = long long;

const vector<int> dx = {1, 0, -1, 0};
const vector<int> dy = {0, 1, 0, -1};
const ll inf = 1001001001;
const ll e9  = 1000000000;
const ll mod = 1000000007;


int main(){
  vector<int>v(3);
  cin >> v[0] >> v[1] >> v[2];
  sort(v.begin(),v.end());
  cout << (v[1]-v[0])+(v[2]-v[1]) << endl;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
#define rep(i, start, end) for (long long i = start; i < end; ++i)
#define repreverse(i, start, end) for (long long i = start; i >= end; --i)
#define all(x) (x).begin(), (x).end()
#define len(x) ((long long)(x).size())

using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vllvll = vector<vll>;
using pll = pair<ll, ll>;
template<class T>void print1d(T x,ll n=-1){if(n==-1)n=x.size();rep(i,0,n){cout<<x[i]<<' ';}cout<<'\n';}
template<class T>void print2d(T x,ll r=-1,ll c=-1){if(r==-1)r=x.size();if(c==-1)c=x[0].size();rep(i,0,r)print1d(x[i],c);}
template<class T, class U>bool haskey(T mp, U key) { return mp.find(key) != mp.end(); }
template<class T, class U>bool isin(T el, U container) { return find(all(container), el) != container.end(); }
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
template<class T>ld deg2rad(T deg) { return M_PI * deg / 180.0; }
template<class T>ld rad2deg(T rad) { return 180.0 * rad / M_PI; }
const long double pi = M_PI;
const long long big = 1LL << 50;
const long long inf = 1LL << 60;
const long long mod = 1e9 + 7;

ll intpow(ll a,ll n){ll p=1;while(n){if(n&1)p=p*a%mod;a*=a;n>>=1;}return p;}

int main()
{
        ll N;
        cin >> N;
        vll A(N);
        rep(i, 0, N) cin >> A[i];

        ll ans = 0;
        rep(digit, 0, 60) {
                ll cnt0 = 0;
                ll cnt1 = 0;
                rep(i, 0, N) {
                        if (A[i] & 1LL<<digit) ++cnt1;
                        else ++cnt0;
                }
                ans = (ans + cnt0 * cnt1 % mod * intpow(2, digit) % mod) % mod;
        }
        cout << ans << endl;
}


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

// 総数を1000000007（素数）で割った余り
const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

int main(){
    int n, m;
    cin >> n >> m;
    vpii c(m);
    rep(i, m) cin >> c[i].first >> c[i].second;
    rep(x, 1000) {
        string xs = to_string(x);
        if (int(xs.size()) != n) continue;
        bool ans = true;
        rep(i, m) {
            if (xs[c[i].first-1] != c[i].second + '0') ans = false;
        }
        if (ans) {
            cout << x << endl;
            return 0;
        }
    }
    cout << -1 << endl;
    return 0;
}


Measured memory_bytes: 256
def find(l, e, start, end):
	mid = (start+end)//2
	if (l[mid] == e):
		return (e, e)
	elif (l[mid] > e):
		if (l[mid-1] < e): 
			return (l[mid-1], l[mid])
		return find(l, e, start, mid)
	elif (l[mid] < e):
		if (l[mid+1] > e): 
			return (l[mid], l[mid+1])
		return find(l, e, mid, end)

def print_sum(input):
	d, n, m = input[0], input[1], input[2]
	S, K = input[3:3+n-1], input[3+n-1:]
	S = [max(S)-d, 0] + sorted(S)+ [d]
	sum = 0
	for k in K:
		low, high = find(S, k, 0, len(S))
		sum += min(k-low, high-k)
	print sum

while (True):
	d = int(raw_input())
	if d == 0: break
	n, m = int(raw_input()), int(raw_input())
	input = [d, n, m]
	for i in range(n-1+m):
		next_int = int(raw_input())
		input.append(next_int)
	print_sum(input)

Measured memory_bytes: 14696
#include <bits/stdc++.h>
using namespace std;
 
int main() {
     cout << fixed << setprecision(6);
           int n,k;
           cin >>n>>k;
   vector<long double> vec(n+1);
  vec[0]=0;
  vector<long double> vecvec(n+1,0);
  
    for (int i = 1; i <n+1; i++) {
        cin>> vec.at(i);
      vecvec[i]=(vec[i]+1)/2;

    }
  
 long double a=0;
  for(int i=0;i<=k;i++){
  a+=vecvec[i];
  
  }
if(n==k)cout<<a<<endl;

  else{
 long double c=0;

  for(int i=2;i<=n-k+1;i++){
    a=a-vecvec[i-1]+vecvec[i+k-1];
    c=max(c,a);
    
   
  }
    
    
  
 
  
cout <<c<<endl;
    }
}


Measured memory_bytes: 9504
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
using P = pair<ll, ll>;
const ll INF = 5e15;
const ll MOD = 1e9 + 7;
int main(){
    string S;
    string ans = "1974";
    for(ll i = 0; i < 4; i++){
        char c;
        cin >> c;
        S += c;
    }
    sort(S.begin(), S.end());
    sort(ans.begin(), ans.end());
    cout << (S == ans ? "YES" : "NO") << endl;
    return 0;
}


Measured memory_bytes: 384
package main

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

const mod = 1000000007

// 1MB
const ioBufferSize = 1 * 1024 * 1024
var sc = func() *bufio.Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Buffer(make([]byte, ioBufferSize), ioBufferSize)
	sc.Split(bufio.ScanWords)
	return sc
}()

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	h := nextInt()
	fmt.Println(attack(h))
}

func attack(h int) int {
	if h == 1 {
		return 1
	} else {
		return attack(h/2) * 2 + 1
	}
}

Measured memory_bytes: 640
#include <cstdio>
#include <algorithm>
using namespace std;
int a,b,c,n,i,j,k;
int str[25];
int main()
{
    while(scanf("%d",&n)==1)
    {
        for(i=0;i<n;i++)
        {
            scanf("%d",&str[i]);
        }
        b=str[0];c=0;
        for(i=0;i<n;i++)
        {
            if(str[i]>=b)
                c++;
            if(str[i]>b)
                b=str[i];
        }
        printf("%d\n",c);
    }
    return 0;
}


Measured memory_bytes: 128
const main = (standardInput) => {
    const lengthList = standardInput.split('\n');
    lengthList.pop();

    // console.log(lengthList);

  for(var i=0;i<lengthList.length;i++){
    // console.log(lengthList[i]);
  var items = lengthList[i].split(' ');
  // console.log(items);
  items[0] = Number.parseInt(items[0])
  items[1] = Number.parseInt(items[1])

    // console.log(items);

    for(var j=0;j<items[0];j++){
      for(var k=0;k<items[1];k++){
        process.stdout.write("#")
      }
      console.log("")
    }
    if(i+1!=lengthList.length){
    console.log("")
  }
  }

}

main(require('fs').readFileSync('/dev/stdin', 'UTF-8'));



Measured memory_bytes: 32128
S = input()
ans = 0
N = len(S)
B = [0] * (N + 1)
if S[0] == "B":
    B[0] = 1

for i in range(1, N):
    B[i] = B[i - 1] + int(S[i] == "B")

for i in range(N):
    if S[i] == "W":
        ans += B[i]

print(ans)

Measured memory_bytes: 11240
import sys
N=int(input())

a_list=list(map(int,input().split()))

ans=1

if 0 in a_list:
    print(0)
    sys.exit(0)

for a in a_list:
    ans*=a

    if ans > 1000000000000000000:
        print(-1)
        sys.exit(0)

print(ans)

Measured memory_bytes: 84468
import sys
r={'I':1,'V':5,'X':10,'L':50,'C':100,'D':500,'M':1000}
for e in sys.stdin:
 n=[r[c]for c in e.strip()]
 print(sum(n[i]*[1,-1][i+1<len(n)and n[i]<n[i+1]]for i in range(len(n))))


Measured memory_bytes: 5576
#include<iostream>
#include<set>
#include<vector>
#include<algorithm>
#include<cstdint>
#include<cstdlib>
template<typename T>
void fin(T const& t){ std::cout << t << std::endl; exit(0); }

uint64_t getZ() {
  uint64_t v = 0; int c;
  while((c = getchar_unlocked()) >= '0') v=v*10+c-'0';
  return v;
}

int main() {
  int N = getZ();
  int p2N = 1<< N;
  std::multiset<int, std::greater<int>> S;
  std::vector<int> X;
  for(int i = 0; i < p2N; ++i) S.insert(getZ());
  p2N = 1;
  X.push_back(*S.begin());
  S.erase(S.begin());
  for(int i = 0; i < N; ++i) {
    std::sort(X.begin(), X.end(), std::greater<int>());
    for(int j = 0; j < p2N; ++j) {
      auto it = S.upper_bound(X[j]);
      if(it == S.end()) fin("No");
      X.push_back(*it);
      S.erase(it);
    }
    p2N *= 2;
  }
  fin("Yes");
  return 0;
}


Measured memory_bytes: 13692
i = []
c = 0

n, q = gets.split.map(&:to_i)

n.times do
  k, v = gets.split
  v = v.to_i
  c += v < q ? v : q
  v -= q
  v <= 0 ? (puts "#{k} #{c}") : i << [k, v]
end

until i.empty?
  k, v = i.shift
  c += v < q ? v : q
  v -= q
  v <= 0 ? (puts "#{k} #{c}") : i << [k, v]
end

Measured memory_bytes: 11400
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = (int)(a); i <= (int)(n); ++i)
#define rrep(i, a, n) for (int i = (int)(a); i >= (int)(n); --i)
#define debug(x) cerr << #x << " = " << x << "\n"
#define debugv(x) \
  rep(f, 0, (x.size() - 1)) cerr << x[f] << (f == (x.size() - 1) ? "\n" : " ")
#define debug2(x, y)                       \
  cerr << "(" << #x << "," << #y << ") = " \
       << "(" << x << "," << y << ")\n"
#define all(x) x.begin(), x.end()
#define each(a, x) for (auto& a : (x))
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define int long long
#define yn(x) puts((x ? "Yes" : "No"))
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
const int MX = 1e5 + 5, INF = 5LL << 57, MOD = 1e9 + 7;

int N, M;
string S;
int A[102][102];
int b[101];
map<int, pii> mp;
void input() {
  rep(i, 1, 3) {
    rep(j, 1, 3) {
      cin >> A[i][j];
      mp[A[i][j]] = pii(i, j);
    }
  }
  cin >> N;
  rep(i, 1, N) {
    cin >> b[i];
    A[mp[b[i]].first][mp[b[i]].second] = 0;
  }

  bool ans = false;
  rep(i, 1, 3) {
    bool tmp = true;
    rep(j, 1, 3) {
      if (A[i][j] != 0) {
        tmp = false;
      }
    }
    if (tmp) {
      ans = true;
      break;
    }
  }

  rep(j, 1, 3) {
    bool tmp = true;
    rep(i, 1, 3) {
      if (A[i][j] != 0) {
        tmp = false;
      }
    }
    if (tmp) {
      ans = true;
      break;
    }
  }

  bool tmp = true;
  rep(i, 1, 3) {
    if (A[i][i] != 0) {
      tmp = false;
      break;
    }
  }
  if (tmp) {
    ans = true;
  }

  if ((A[1][3] == 0) && (A[2][2] == 0) && (A[3][1] == 0)) {
    ans = true;
  }
  cout << (ans ? "Yes" : "No") << endl;

  ;
  ;
}
void solve() {
  ;
  ;
}
signed main() {
  cout << setprecision(12);
  input();
  solve();
  return 0;
}

Measured memory_bytes: 256
/*
{By GWj
*/
#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define rb(a,b,c) for(int a=b;a<=c;++a)
#define rl(a,b,c) for(int a=b;a>=c;--a)
#define LL long long
#define IT iterator
#define PB push_back
#define II(a,b) make_pair(a,b)
#define FIR first
#define SEC second
#define FREO freopen("check.out","w",stdout)
#define rep(a,b) for(int a=0;a<b;++a)
#define SRAND mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define random(a) rng()%a
#define ALL(a) a.begin(),a.end()
#define POB pop_back
#define ff fflush(stdout)
#define fastio ios::sync_with_stdio(false)
#define R(a) cin>>a
#define R2(a,b) cin>>a>>b
#define check_min(a,b) a=min(a,b)
#define check_max(a,b) a=max(a,b)
using namespace std;
const int INF=0x3f3f3f3f;
typedef pair<int,int> mp;
/*}
*/
int a[200000+20],b[200000+20];
int cnt[200000+20];
bool cmp(mp A,mp B){
	if(cnt[B.FIR]==cnt[A.FIR]){
		if(A.FIR!=B.FIR) return A.FIR>B.FIR;
		return A.SEC<B.SEC;
	}
	return cnt[A.FIR]>cnt[B.FIR]; 
}
int main(){
	fastio;
	int n;
	R(n);
	rb(i,1,n){
		R(a[i]);
		cnt[a[i]]++;
	}
	rb(i,1,n){
		R(b[i]);
		cnt[b[i]]++;
	}
	rb(i,1,n){
		if(cnt[i]>n){
			cout<<"No";
			return 0;
		}
	}
	int rest[200000+20];
	vector<mp> v;
	cout<<"Yes\n";
	memset(cnt,0,sizeof(cnt));
	rb(i,1,n){
		if(a[i]==b[i]){
			v.PB(II(a[i],i));
			cnt[a[i]]++;
		}
	}
	rb(i,1,n)
		rest[i]=b[i];
	sort(ALL(v),cmp);
	if(v.empty()){
		
		rb(i,1,n){
			cout<<rest[i]<<" ";
		}
		cout<<endl;
		return 0;
	}
	bool ok=0;
	rb(i,1,n){
		 if(cnt[i]*2>v.size()){
		 	ok=1;	
		 }
	}
	if(!ok){
		int iii=0;
		while(v[iii].FIR==v[0].FIR){
			iii++;
		}
		for(auto it:v){
			rest[it.SEC]=b[v[iii].SEC];
			iii++;
			iii%=v.size();
		}
	}
	else{
		int duo=0;
		rb(i,1,n){
			if(cnt[i]*2>v.size()){
				while(cnt[i]*2>v.size()){
					cnt[i]--;
					duo++;
				}
			}
		}
		if(duo==v.size()){
			int iii=0;
			rb(i,1,n){
				if(a[i]==v[0].FIR||v[0].FIR==b[i]) continue;
				swap(rest[v[iii].SEC],rest[i]);
				iii++;
				if(iii==v.size()) break;
			}
		}
		else{
			reverse(ALL(v));
			int iii=v.size()-duo;
			int l=0,r=iii-1;
			while(l<r){
				swap(rest[v[l].SEC],rest[v[r].SEC]);
				swap(b[v[l].SEC],b[v[r].SEC]);
				l++,r--;
			} 
			rb(i,1,n){
				if(a[i]==v.back().FIR||v.back().FIR==b[i]) continue;
				swap(rest[v[iii].SEC],rest[i]);
				iii++;
				if(iii==v.size()) break;
			}
		}
	}
	rb(i,1,n){
		cout<<rest[i]<<" ";
	}
	cout<<endl;
	return 0;
}


Measured memory_bytes: 8004
//#define _GLIBCXX_DEBUG

#include<bits/stdc++.h>
using namespace std;

#define endl '\n'
#define lfs cout<<fixed<<setprecision(10)
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define fi first
#define se second
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define EB emplace_back
#define rep(i,n,m) for(ll i = (n); i < (ll)(m); i++)
#define rrep(i,n,m) for(ll i = (ll)(m) - 1; i >= (ll)(n); i--)
using ll = long long;
using ld = long double;
const ll MOD1 = 1e9+7;
const ll MOD9 = 998244353;
const ll INF = 1e18;
using P = pair<ll, ll>;
template<typename T1, typename T2>
bool chmin(T1 &a,T2 b){if(a>b){a=b;return true;}else return false;}
template<typename T1, typename T2>
bool chmax(T1 &a,T2 b){if(a<b){a=b;return true;}else return false;}
ll median(ll a,ll b, ll c){return a+b+c-max({a,b,c})-min({a,b,c});}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
template<typename T1,typename T2>
void ans(bool x,T1 y,T2 z){if(x)cout<<y<<endl;else cout<<z<<endl;}  
template<typename T>
void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++)
{cout<<v[i][0];for(ll j=1;j<w;j++)cout spa v[i][j];cout<<endl;}};
void debug(vector<string>&v,ll h,ll w){for(ll i=0;i<h;i++)
{for(ll j=0;j<w;j++)cout<<v[i][j];cout<<endl;}};
template<typename T>
void debug(vector<T>&v,ll n){if(n!=0)cout<<v[0];
for(ll i=1;i<n;i++)cout spa v[i];cout<<endl;};
template<typename T>
vector<vector<T>>vec(ll x, ll y, T w){
  vector<vector<T>>v(x,vector<T>(y,w));return v;}
ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;}
vector<ll>dx={1,-1,0,0,1,1,-1,-1};
vector<ll>dy={0,0,1,-1,1,-1,1,-1};
template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2>&p){
  return os << p.first << " " << p.second;
}
//mt19937 mt(chrono::steady_clock::now().time_since_epoch().count());

int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  ll res=0,buf=0;
  bool judge = true;
  string s;cin>>s;
  cout<<s.substr(0,3)<<endl;
  return 0;
}

Measured memory_bytes: 3608
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")

#include <bits/stdc++.h>

using namespace std;

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
#define ll long long int

int main(){
    int n,m;
    scanf("%d%d",&n,&m);
    vector<int> a;
    for(int i=0;i<m;i++){
        int k;
        scanf("%d",&k);
        int temp=0;
        for(int j=0;j<k;j++){
            int pos;
            scanf("%d",&pos);
            pos--;
            temp=temp|(1<<pos);
        }
        a.push_back(temp);
    }
    debug(a);
    vector<int> parity(m);
    for(auto &x:parity)scanf("%d",&x);
    int cnt=0;
    for(int i=0;i<pow(2,n);i++){
        bool okay=true;
        for(int j=0;j<m;j++){
            int set_b=__builtin_popcount(a[j]&i);
            debug(i,j,a[j],set_b,parity[j]);
            if(set_b%2!=parity[j]%2){
                okay=false;
                break;
            }
        }
        if(okay){
            cnt++;
        }
    }
    printf("%d\n",cnt);
    return 0;
}


Measured memory_bytes: 4260
#include <iostream>
#include <vector>
using namespace std;
int main(){
  int n;
  while( cin >> n ){
    if(n == 1)break;
    vector<int> num(300001);
    fill(num.begin(),num.end(),0);
    for(int i = 6 ; i <= 300000 ; i++ ){
      if(i%7 == 6 || i%7 == 1)num[i] = 1;
    }

    num[0] = num[1] = 0;
    cout << n<<':';
    for(int i = 6 ; i <= n ; i++ ){
      if(n%i == 0 && num[i] == 1){
	cout <<' '<<i;
	for(int j = i*2 ; j <= n ; j+=i)num[j] = 0;
      }
    }
    cout << endl;
  }
  return 0;
}

Measured memory_bytes: 2364
#include<bits/stdc++.h>
#define ll long long
#define pll pair<ll,ll>
#define pii pair<int,int>
#define rep(i,a,b) for(int i=a;i<=b;++i)
#define per(i,a,b) for(int i=a;i>=b;--i)
#define mem0(x) memset(x,0,sizeof(x))
#define meminf(x) memset(x,0x3f,sizeof(x))
#define VI vector<int>
#define VL vector<ll>
using namespace  std;

const int N = 2e5+5;
const ll modd = 1e9+7;
ll a[N];
int main(){
    ios::sync_with_stdio(0);
    int n;cin>>n;ll sum = 0;
    rep(i,1,n){
        cin>>a[i]; sum  = (sum+a[i])%modd;
    }
    ll ans = 0;
    sum = ((sum - a[1])%modd + modd)%modd;
    rep(i,1,n-1){
        ans  = (ans + a[i]*sum)%modd;
        sum = ((sum - a[i+1])%modd + modd)%modd;
    }
    cout<<ans;
}


Measured memory_bytes: 5092
#include<bits/stdc++.h>
using namespace std;
map<int,int> mp;
map<int,int> watimes;
int main()
{
	int n,m;
	cin>>n>>m;
	int sum = 0;
	for(int i = 0;i<m;i++)
	{
		int ad;
		string as;
		cin>>ad>>as;
		if(as == "AC")
		{
			if(mp[ad]!=1)
			{
				sum+=watimes[ad];
			}
			mp[ad] = 1;
		}
		else
		{
			watimes[ad]++;
		}
	}
	cout<<mp.size()<<" "<<sum<<endl;
	return 0;
}

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

int main() {
    int n; cin >> n;
    int a[n]; for (int i = 0; i < n; ++i) cin >> a[i];
    
    printf("%d", a[0]);
    for (int i = 1; i < n; ++i) printf(" %d", a[i]);
    printf("\n");
    
    for (int i = 0; i < n - 1; ++i) {
        int sort_idx = i + 1;
        
        for (int j = i; j >= 0; --j) {
            if (a[sort_idx] < a[j]) {
                swap(a[sort_idx], a[j]);
                sort_idx = j;
            }
            else break;
        }
        
        printf("%d", a[0]);
        for (int i = 1; i < n; ++i) printf(" %d", a[i]);
        printf("\n");
    }
    
    return 0;
}


Measured memory_bytes: 3228
import java.util.*;

  public class Main {
      public static void main (String[]args){

          Scanner scanner = new Scanner(System.in);

          // 入力回数の取得
          int N = scanner.nextInt();

          double all = 0;

          for (int i = 0; N > i ; i++) {
            //　入力回数分の数値入力を求め、逆数に変換する
            all +=  1 / scanner.nextDouble();
          }

          // 逆数として出力
          System.out.println(1 / all);
              
      }
  } 

Measured memory_bytes: 23252
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int d = sc.nextInt();
		String s = sc.next();
	    char front='o';
		boolean ch=false;
		for(int i=0; i<n; i++){
			if(s.charAt(i)=='#'){
				if(front=='#' && i>a-1){
					System.out.println("No");
					return;
				}
				front='#';
			}else{
				front='.';
				if(i==b-1){
					ch=true;
				}
				if(ch){
					if(i!=n-1 && s.charAt(i-1)=='.' && s.charAt(i+1)=='.' ){
						System.out.println("Yes");
						return;
					}
				}
				if(i==d-1){
					break;
				}
			}
		}
		if(c<d){
			System.out.println("Yes");
		}else{
			System.out.println("No");
		}
	}
}


Measured memory_bytes: 28448
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner scan = new Scanner(System.in);
    int h[] = new int[2];
    for (int j = 0; j < 2; j++) {
      h[j] = scan.nextInt();
    }
    int c =1;
    for (int i = 1; h[1] < h[0]; i++) {
      h[0] -= h[1];
      c++;
    }
    System.out.println(c);
  }
}

Measured memory_bytes: 22740
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pli = pair<ll, int>;

const ll INF = 1e17;

const pli id(INF, -1);

class segment_tree
{
	using T = pli;
	T op(T a, T b) const {
		return min(a, b);
	}

	int expand(int x) {
		int res;
		for (res = 1; res < x; res <<= 1);
		return res;
	}
	const int n;
	vector<T> dat;
public:
	segment_tree(int n_)
		: n(expand(n_)), dat(n + n_, id) {}
	segment_tree(int n_, T val_)
		: segment_tree(vector<T>(n_, val_)) {}
	segment_tree(const vector<T>& dat_)
		: n(expand(dat_.size())), dat(n) {
		copy(dat_.begin(), dat_.end(), back_inserter(dat));
		for (int i = n - 1; i > 0; --i)
			dat[i] = op(dat[i << 1], dat[(i << 1) | 1]);
	}
	void update(int p, T val) {
		dat[p += n] = val;
		while (p >>= 1) dat[p] = op(dat[p << 1], dat[(p << 1) | 1]);
	}
	T find(int l, int r) const {
		T res1 = id, res2 = id;
		for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
			if (l & 1) res1 = op(res1, dat[l++]);
			if (r & 1) res2 = op(dat[--r], res2);
		}
		return op(res1, res2);
	}
};

class quick_find {
	vector<int> rt;
public:
	vector<vector<int>> vs;
	quick_find(int n) : rt(n), vs(n) {
		for (int i = 0; i < n; i++) rt[i] = i, vs[i].push_back(i);
	}
	int find(int a) {
		return rt[a];
	}
	bool same(int a, int b) {
		return rt[a] == rt[b];
	}
	void unite(int a, int b) {
		a = rt[a], b = rt[b];
		if (a == b) return;
		if (vs[a].size() < vs[b].size()) swap(a, b);
		for (auto& v : vs[b]) rt[v] = a;
		copy(vs[b].begin(), vs[b].end(), back_inserter(vs[a]));
	}
	int size(int a) {
		return vs[rt[a]].size();
	}
};

int main()
{
	int N;
	ll D;
	cin >> N >> D;
	vector<ll> A(N);
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}
	ll res = 0;
	quick_find uf(N);
	segment_tree lst(N), rst(N);
	for (int i = 0; i < N; i++) {
		lst.update(i, make_pair(A[i] - i * D, i));
		rst.update(i, make_pair(A[i] + i * D, i));
	}
	while (uf.size(0) < N) {
		vector<tuple<ll, int, int>> es;
		for (int i = 0; i < N; i++) if (uf.find(i) == i) {
			for (auto v : uf.vs[i]) {
				lst.update(v, make_pair(INF, -1));
				rst.update(v, make_pair(INF, -1));
			}
			ll c = INF;
			int to = -1;
			for (auto v : uf.vs[i]) {
				int u = lst.find(0, v).second;
				if (u != -1) {
					ll cost = A[v] + A[u] + abs(v - u) * D;
					if (cost < c) {
						c = cost;
						to = u;
					}
				}
				u = rst.find(v, N).second;
				if (u != -1) {
					ll cost = A[v] + A[u] + abs(v - u) * D;
					if (cost < c) {
						c = cost;
						to = u;
					}
				}
			}
			for (auto v : uf.vs[i]) {
				lst.update(v, make_pair(A[v] - v * D, v));
				rst.update(v, make_pair(A[v] + v * D, v));
			}
			es.emplace_back(c, i, uf.find(to));
		}
		sort(es.begin(), es.end());
		for (auto e : es) {
			int u, v; ll c;
			tie(c, u, v) = e;
			if (uf.same(u, v)) continue;
			uf.unite(u, v);
			res += c;
		}
	}
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 37948
N,M=map(int,input().split())
H=list(map(int,input().split()))

graph=[0]*N
for i in range(M):
    A,B=map(int,input().split())
    A,B=A-1,B-1
    if H[A]<H[B]:
        graph[A]+=1
    elif H[B]<H[A]:
        graph[B]+=1
    else:
        graph[A]+=1
        graph[B]+=1

ans=graph.count(0)
print(ans)

Measured memory_bytes: 20096
#include "bits/stdc++.h"
using namespace std;

#define ASC(vec) vec.begin(), vec.end()		// 昇順ソート 例：sort(ASC(vec));
#define DESC(vec) vec.rbegin(), vec.rend()	// 降順ソート 例:sort(DESC(vec));
#define rep(i, n) for(int i = 0; i < n; i++)
#define Rep(i, n) for(int i = 1; i < n; i++)
#define In(vec) rep(i, n) cin>>vec[i];
#define ANS(s) cout << s << endl
#define inc(a, b) cin >> a >> b;

const int mod = 1000000007;
const int inf = (int)1e9 + 7;
const long long INF = 1LL << 60;

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vd = vector<double>;
using vvi = vector<vector<int>>;
using vii = vector<pair<int, int>>;

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 a, ll b) { return b ? GCD(b, a % b) : a; }
int round_int(int a, int b) { return (a + (b - 1)) / b; }


// 4,8方向に探索する際に用いる配列
//int dx[4] = { 0,  0, 1, -1 };
//int dy[4] = { 1, -1, 0,  0 };
//int dx[8] = { 1, 0, -1,  0, 1, -1, -1,  1 };
//int dy[8] = { 0, 1,  0, -1, 1,  1, -1, -1 };

constexpr auto MAX = 100010;

// ────────────────────────────────────────────────────

int main() {
	int n, m; cin >> n >> m;
	cout << --n * --m << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long long dp[101][100005], N, M, m[105], w[105], maksw, ans;
int main (){
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin >> N >> M;
for (int i=0;i<N;i++){
	cin >> m[i] >> w[i];
	maksw += w[i];
}
for (int i=0;i<N;i++) for (int j=0;j<=maksw;j++) dp[i][j]=-1;
dp[0][0]=0;
dp[0][w[0]]=m[0];
for (int i=1;i<N;i++){
	for (int j=0;j<=maksw;j++){
		if (j<w[i]) dp[i][j]=dp[i-1][j];
		else{
			int ok=0,kk=0;
			if (dp[i-1][j-w[i]]>=0) kk++;
			if (dp[i-1][j] >= 0) ok++;
			if (ok==1 and kk==1) dp[i][j]=min(dp[i-1][j-w[i]] + m[i],dp[i-1][j]); 
			else if (ok==1) dp[i][j]=dp[i-1][j];
			else if (kk==1) dp[i][j]=dp[i-1][j-w[i]] + m[i];
			else dp[i][j]=-1;
		}
	}
}
//for (int i=0;i<N;i++){for (int j=0;j<=maksw;j++) cout << " " << dp[i][j]; cout << endl;}
for (int j=0;j<=maksw;j++) if (dp[N-1][j] <= M and dp[N-1][j]>=0) ans=j;
cout << ans;
return 0;
}

Measured memory_bytes: 78336
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
 
#define SWAP(a, b) (a += b,b = a - b,a -= b)
#define rng(i, a, b) for(int i = int(a); i < int(b); i++)
#define rep(i, b) rng(i, 0, b)
#define urng(i, a, b) for(int i = int(b) - 1; i >= int(a); i--)
#define urep(i, b) urng(i, 0, b)
#define pb push_back
#define eb emplace_back
#define F first
#define S second
#define bg begin()
#define ed end()
#define all(x) x.bg,x.ed
 
main() {
  int n, a, b, ans = 0;
  //string s;
  cin >> b >> a;
  //vector<int> v(n), c(n);
  //rep(i, n)
  if(b % a == 0) cout << b / a << endl;
  else cout << b / a + 1 << endl;
  //cout <<  << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T>
using dijkstra = priority_queue<T, vector<T>, greater<T>>;

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define fbo find_by_order  // k th index
#define ook order_of_key   // strictly smaller than k
#define PI acos(-1.0)
#define inf 0x3f3f3f3f
#define max_ull 18446744073709551615
#define max_ll 9223372036854775807
#define lead_zero(x) __builtin_clzll(x)
#define trail_zero(x) __builtin_ctzll(x)
#define total_1s(x) __builtin_popcountll(x)
#define first_1(x) __builtin_ffsll(x)
#define log2_(x) __builtin_clz(1) - __builtin_clz(x)
#define isLeap(x) ((x % 400 == 0) || (x % 100 ? x % 4 == 0 : false))
#define QUERY           \
    int test;           \
    scanf("%d", &test); \
    for (int _T = 1; _T <= test; _T++)
#define FAST ios_base::sync_with_stdio(0), cin.tie(0)
#define all(v) v.begin(), v.end()
#define reunique(v) v.resize(std::unique(all(v)) - v.begin())
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pul pair<ull, ull>
#define ff first
#define ss second
#define MERGE(v1, v2, v) merge(all(v1), all(v2), back_inserter(v))
#define MP make_pair
#define EB emplace_back
#define read freopen("input.txt", "r", stdin)
#define write freopen("output.txt", "w", stdout)
#define in_range(v, r, l) upper_bound(all(v), r) - lower_bound(all(v), l)
#define LCM(a, b) (a / __gcd(a, b)) * b;

ll rdn(int y, int m, int d) {
    /* Rata Die day one is 0001-01-01 */
    if (m < 3)
        y--, m += 12;
    return 365 * y + y / 4 - y / 100 + y / 400 + (153 * m - 457) / 5 + d - 306;
}
/* Direction arrays */
/*int dx[] = {1,-1,0,0}, dy[] = {0,0,1,-1};                             */  // 4Direction
/*int dx[] = {1,-1,0,0,1,1,-1,-1}, dy[] = {0,0,1,-1,1,-1,1,-1};         */  // 8Direction
/* int dx[] = {1,-1,1,-1,2,2,-2,-2} , dy[] = {2,2,-2,-2,1,-1,1,-1};     */  // KnightDirection
/* int dx[] = {2,-2,1,1,-1,-1} , dy[] = {0,0,1,-1,1,-1};                */  // HexagonalDirection
/* int day[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; */

ll bigmod(ll base,ll power,ll mod)
{
    ll res=1,x=base%mod;
    while(power)
    {
        if(power &1)
            res*=x,res%=mod;
        x=(x*x)%mod;
        power>>=1;
    }
    return res;
}
const int N = 1e5+9;
ll dp[N];
int main() {
    ll n,k;
    ll mod = 1e9+7;
    cin>>n>>k;
    ll ans = 0;
    for(int i=k;i>=1;i--){
        ll tmp = bigmod(k/i,n,mod);
        for(int j=2*i;j<=k;j+=i){
            tmp-=dp[j];
            tmp = (tmp+mod)%mod;
        }
        dp[i] = tmp;
        ans = (ans+(i*dp[i])%mod)%mod;
    }
    cout<<ans<<"\n";
}


Measured memory_bytes: 4404
import java.util.*;

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


	public void run() {
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt();
		int m=sc.nextInt();
		int a[] = new int[n];
		for(int i=0; i<n; i++) {
			a[i]=sc.nextInt();
		}

		int sum[] = new int[n+1];
		sum[0]=0;
		for(int i=0; i<n; i++) {
			sum[i+1]=(sum[i]+a[i])%m;
		}

		long ans = 0;
		HashMap<Integer,Integer>map = new HashMap<Integer, Integer>();
		for(int i=0; i<=n; i++) {
			int v = sum[i];
			ans += map.containsKey(v) ? map.get(v) : 0;
			map.put(v, map.containsKey(v) ? map.get(v)+1 : 1);
		}
		System.out.println(ans);
		sc.close();
	}


}


Measured memory_bytes: 53560
// https://atcoder.jp/contests/abc114/tasks/abc114_a
#include <bits/stdc++.h>
using namespace std;

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

  if (X==3||X==5||X==7)
    cout << "YES" << endl;
  else
    cout << "NO";
}

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

using namespace std;

#define INF 1001000100010001000
#define MOD 1000000007
#define EPS 1e-10
#define int long long
#define rep(i, N) for (int i = 0; i < N; i++)
#define Rep(i, N) for (int i = 1; i < N; i++)
#define For(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define pii pair<int, int>
#define vi vector<int>
#define vvi vector<vi >
#define vb vector<bool>
#define vvb vector<vb >
#define vp vector< pii >
#define all(a) (a).begin(), (a).end()
#define Int(x) int x; cin >> x;
#define int2(x, y) Int(x); Int(y);
#define int3(x, y, z) Int(x); int2(y, z);
#define in(x, a, b) ((a) <= (x) && (x) < (b))
#define fir first
#define sec second
#define ffir first.first
#define fsec first.second
#define sfir second.first
#define ssec second.second
#define Decimal fixed << setprecision(10)

//int dxy[5] = {0, 1, 0, -1, 0};
// cmd

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

    int2(n, m);
    string st;
    cin >> st;
    
    vector<pair<char, int>> data(m);
    rep(i, m) {
        string a;
        cin >> a;
        data[i].fir = a[0];
        string b;
        cin >> b;
        if (b == "R") {
            data[i].sec = 0;
        } else {
            data[i].sec = 1;
        }
    }

    reverse(all(data));

    vi ans(n, 0);
    int p1 = -1, pn = n;
    rep(i, data.size()) {
        if (data[i].sec) {
            if (in(p1 + 1, 0, n) && st[p1+1] == data[i].fir) {
                p1++;
                //ans[p1] = 1;
            }
            if (in(pn, 0, n) && st[pn] == data[i].fir) {
                pn++;
                //ans[pn] = 1;
            }
        } else {
            if (in(p1, 0, n) && st[p1] == data[i].fir) {
                p1--;
                //ans[p1] = 1;
            }
            if (in(pn - 1, 0, n) && st[pn-1] == data[i].fir) {
                pn--;
                //ans[pn] = 1;
            }
        }
        //std::cout << p1 << " " << pn << std::endl;
    }

    int yui = 0;
    rep(i, n) {
        //yui += ans[i];
        //std::cout << ans[i] << " ";
    }
    //cout << endl;

    std::cout << n - (n - pn) - (p1 + 1) << std::endl;



    return 0;
}





Measured memory_bytes: 5328
#include<iostream>
using namespace std;
int main()
{
    int a,b;
    cin>>a>>b;
    if ( a % 2 == 0 || b % 2 == 0 )
        cout<<"Even";
    else
        if ( a % 2 == 1 || b % 2 == 1 )
        cout<<"Odd";
    return 0;
}


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

int main(void) {
  ll N, K;
  cin >> N >> K;
  vector<ll> A(N);
  REP(i, 0, N) cin >> A[i];

  vector<ll> b;
  while (K > 0) {
    b.push_back(K % 2);
    K /= 2;
  }
  while (b.size() < 60) {
    b.push_back(0);
  }

  vector<ll> cnt0(60), cnt1(60);
  REP(k, 0, 60) {
    REP(i, 0, N) {
      if ((A[i] & (1LL << k)) == 0) {
        cnt0[k]++;
      } else {
        cnt1[k]++;
      }
    }
  }

  ll ans = 0;
  REP(i, 0, b.size()) {
    if (b[i] == 0) {
      ans += (1LL << i) * cnt1[i];
    } else {
      ans += (1LL << i) * cnt0[i];
    }
  }

  for (ll k = (ll) b.size() - 1; k >= 0; k--) {
    if (b[k] == 1) {
      ll p = 0;
      for (ll i = (ll) b.size() - 1; i > k; i--) {
        if (b[i] == 0) {
          p += (1LL << i) * cnt1[i];
        } else {
          p += (1LL << i) * cnt0[i];
        }
      }

      p += (1LL << k) * cnt1[k];

      for (ll i = k - 1; i >= 0; i--) {
        p += (1LL << i) * max(cnt0[i], cnt1[i]);
      }

      ans = max(ans, p);
    }
  }

  cout << ans << endl;
}

Measured memory_bytes: 1024
#pragma GCC optimize("Ofast") 
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(a) a.begin(),a.end()
#define lb lower_bound
#define ub upper_bound
#define owo ios_base::sync_with_stdio(0);cin.tie(0);
#define MOD (ll)(1e6+3)
#define INF (ll)(1e18)
#define debug(...) fprintf(stderr, __VA_ARGS__),fflush(stderr)
#define time__(d) for(long blockTime = 0; (blockTime == 0 ? (blockTime=clock()) != 0 : false);\
debug("%s time : %.4fs\n", d, (double)(clock() - blockTime) / CLOCKS_PER_SEC))
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> PII;
typedef pair<int,int> pii;
typedef vector<vector<int>> vii;
typedef vector<vector<ll>> VII;
int main()
{
  string s,t;
  cin>>s>>t;
  int n = s.length();
  ll ans = 0;
  for(int i=0;i<n;i++)if(s[i] != t[i])ans++;
  cout<<ans;
}


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

using namespace std;
#define ll  long long
#define ld  long double

#define endl '\n'
#define FAST ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const ll mod = 1000000007;
const double PI = 3.141592653589793238463;
const int MAXN=1e5 + 5;
string h;
int a,b,k;
ll fastPow(ll x,ll b)
{
    if(b==0)
        return 1;
    else if(!(b & 1))
    {
        return fastPow(x*x,b/2);
    } else
        return x*fastPow(x*x,(b-1)/2);
}
//__builtin_popcount ();
int main() {
    FAST
double a,b;
    cin>>a>>b;
    cout<<ceil(a/b)<<endl;
    return 0;
}

Measured memory_bytes: 256