akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int a, b;
void prians(bool answer) {
  if(answer)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

int main() {
  bool ans = 1;
  cin >> a >> b;
  if(a * b % 2 == 0) ans = 0;
  prians(ans);
  return 0;
}

Measured memory_bytes: 768
use std::io::{stdin, stdout, BufReader, BufRead, StdinLock, Write, BufWriter};

fn main() {
    let (std_in, std_out) = (stdin(), stdout());
    let mut br = BufReader::new(std_in.lock());
    let mut bw = BufWriter::new(std_out.lock());
    
    let n = rn::<usize>(&mut br);
    let mut a = Vec::<usize>::new();
    for _ in 0..n {
        a.push(rn(&mut br));
    }
    let mut mx = 0;
    let mut smx = 0;
    for x in &a {
        if *x > smx {
            smx = *x;
        }
        if *x > mx {
            smx = mx;
            mx = *x;
        }
    }
    for x in &a {
        if *x == mx {
            writeln!(&mut bw, "{}", smx);
        } else {
            writeln!(&mut bw, "{}", mx);
        }
    }
}


//////////////////////////////////////////////////////////////////////////////////
#[allow(dead_code)]
fn rs(br: &mut BufReader<StdinLock>) -> Vec<char> {
    let mut buf = String::new();
    br.read_line(&mut buf).ok();
    buf.trim().chars().collect()
}

#[allow(dead_code)]
fn rn<T: std::str::FromStr>(br: &mut BufReader<StdinLock>) -> T {
    let mut buf = String::new();
    br.read_line(&mut buf).ok();
    buf.trim().parse().ok().unwrap()
}

#[allow(dead_code)]
fn rvs(br: &mut BufReader<StdinLock>) -> Vec<Vec<char>> {
    let mut buf = String::new();
    br.read_line(&mut buf).ok();
    buf.trim().split_whitespace().map(|e| e.chars().collect()).collect()
}

#[allow(dead_code)]
fn rvn<T: std::str::FromStr>(br: &mut BufReader<StdinLock>) -> Vec<T> {
    let mut buf = String::new();
    br.read_line(&mut buf).ok();
    buf.trim().split_whitespace().map(|e| e.parse().ok().unwrap()).collect()
}

Measured memory_bytes: 7676
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,s,n) for(ll i = (s); i < (n); i++)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()



int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(18);
  
  string s;
  ll n;
  cin >> n;
  
  //vector<ll> a(n);  rep(i, 0, n) cin >> a[i];
  
  cout << n+n*n+n*n*n << "\n";
  
  //cout << (  ?"Yes" :"No") << "\n";

}

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

typedef long long ll;
using namespace std;
const ll mod = 1000000007;
const ll mod998 = 998244353;
const ll intmax = 2147483647;
const ll llmax = 9223372036854775807;
const char sp = ' ';

ll N, D, A, tree[1 << 19], res;
pair<ll, ll>P[200000];

ll calc(int x) {
	ll a = 0;
	x += (1 << 18);
	while (x) {
		a += tree[x];
		x /= 2;
	}
	return a;
}

void add(int p, int q, int l, int r, int k, ll x) {
	if (r < p || q < l)return;
	if (p <= l&&r <= q) {
		tree[k] += x;
		return;
	}
	add(p, q, l, (l + r) / 2, k + k, x);
	add(p, q, (l + r) / 2 + 1, r, k + k + 1, x);
}

int main() {
	cin >> N >> D >> A;
	for (int i = 0; i < N; i++) {
		cin >> P[i].first >> P[i].second;
	}
	sort(P, P + N);
	for (int i = 0; i < N; i++) {
		ll t = P[i].second - calc(i)*A;
		if (t > 0) {
			int L = i;
			int R = N;
			while (L + 1 != R) {
				int m = (L + R) / 2;
				if (P[m].first <= P[i].first + D + D)L = m;
				else R = m;
			}
			res += (t - 1) / A + 1;
			add(i, L, 0, (1 << 18) - 1, 1, (t - 1) / A + 1);
		}
	}
	cout << res << endl;
}

Measured memory_bytes: 7040
N = int(input())
ans = 0
i = 1
if (N % 2 == 1):
    k = (N + 1) // 2
    while (5**i <= k):
        ans -= k // (5**i)
        i += 1
    i = 1
    while (5**i <= 2*k):
        ans += k // (5**i)
        i += 1
else:
    k = N // 2
    while (5**i <= k):
        ans += k // (5**i)
        i += 1

print(ans)

Measured memory_bytes: 3060
H, W = map(int, input().split())
s = [["." for _ in range(W+2)]]
for _ in range(H):
	s.append(["."] + list(input()) + ["."])
s.append(["." for _ in range(W+2)])

ans = [["." for _ in range(W)] for _ in range(H)]

for h in range(1, H+1):
	for w in range(1, W+1):
		if s[h][w] == "#":
			ans[h-1][w-1] = "#"
		else:
			rinsetsu = [s[h-1][w-1], s[h-1][w], s[h-1][w+1], s[h][w-1], s[h][w+1], s[h+1][w-1], s[h+1][w], s[h+1][w+1]]
			ans[h-1][w-1] = str(rinsetsu.count("#"))

for h in range(H):
	print("".join(ans[h]))

Measured memory_bytes: 3188
#include <iostream>
using namespace	std;
#define	int long long
main(){

  int s,t,d,w[100000];
  cin>>s>>t>>d;
  for(int i=0,tmp;i<d;i++){
    cin>>tmp;
    if(i) w[i]=w[i-1]+tmp;
    else w[i]=tmp;
  }
  for(int i=0;i<d;i++){
    if(s+w[i]<=t){
      cout<<i+1<<endl;
      return 0;
    }
  }
  if(w[d-1]>=0){
    cout<<-1<<endl;
    return 0;
  }
  long long r=114514191911451419;
  for(int i=0;i<d;i++){
    r=min(r,(long long)(s-t+w[i]-w[d-1]-1)/-w[d-1]*d+i+1);
    //   cout<<r<<endl;                                                                                                        
  }
  cout<<r<<endl;
  return 0;
}

Measured memory_bytes: 3872
N = int(input())
A = [int(x) for x in input().split()]

last = 0
ans = 1

for i in range(N - 1):
    diff = A[i] - A[i + 1]
    if last == 0:
        if diff > 0:
            last = 1
        elif diff < 0:
            last = -1
    elif last * diff < 0:
        ans += 1
        last = 0

print(ans)

Measured memory_bytes: 20076
#include <iostream>

using namespace std;

int f(int a, int b) {
    if (b % a == 0) {
        return a + b;
    }
    return b - a;
}

int main() {

    int a, b;
    cin >> a >> b;

    int result = f(a, b);
    cout << result << endl;

    return 0;
}


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

int check(int N){
  int X = 0;
  while(true){
    X += N % 10;
    N /= 10;

    if (N == 0)
    {
      return X;
    }
    
  }
}

int main() {
  int N; cin >> N;
  int X = check(N);
  if (N % X == 0)
  {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  
}

Measured memory_bytes: 256
n,a,b,c = gets.chomp.split(" ").map(&:to_i)
target = [a,b,c].sort
l = n.times.map{gets.to_i}
comb = []
n.times do |i|
  comb << i
end
ans = 100000
comb.combination(3).each do |x,y,z|
  [0,1].repeated_permutation(n-3).each do |bit|
    kouho = []
    j = 0
    (n-3).times do |i|
      while j == x || j == y || j == z
        j += 1
      end
      kouho << l[j] if bit[i] == 1
      j += 1
    end
    len = kouho.length
    [x,y,z].repeated_permutation(len).each do |k|
      take1 = l[x]
      take2 = l[y]
      take3 = l[z]
      mp = 0
      len.times do |l|
        if k[l] == x
          take1 += kouho[l]
        elsif k[l] == y
          take2 += kouho[l]
        elsif k[l] == z
          take3 += kouho[l]
        end
        mp += 10
      end
      list = [take1,take2,take3].sort
      mp += (target[0] - list[0]).abs
      mp += (target[1] - list[1]).abs
      mp += (target[2] - list[2]).abs
      ans = mp if ans > mp
    end
  end
end
puts ans

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

int main() {
  int A[3][3];
  for(int i=0;i<3;i++) {
    for(int j=0;j<3;j++) {
      cin >> A[i][j];
    }
  }

  for(int i=0;i<3;i++) {
    for(int j=0;j<3;j++) {
      for(int k=0;k<3;k++) {
        for(int l=0;l<3;l++) {
          if(A[i][k] + A[j][l] != A[i][l] + A[j][k]) {
            cout << "No";
            return 0;
          }
        }
      }
    }
  }

  cout << "Yes";
  return 0;
}


Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>
#include <limits>
#define ALL(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define int_INF 2147483647
#define pint_INF 2000000000
#define ll_INF 	9223372036854775807
#define MOD 1000000007
#define vi vector<int>
#define vvi vector<vector<int>>
#define vvll vector<vector<long long>>
#define vvc vector<vector<char>>
#define vll vector<long long>
#define pii pair<int,int>
#define vpii vector<pair<int,int>>
#define sysp system("PAUSE")
#define pno cout << "no" << endl
#define pyes cout << "yes" << endl
#define pYes cout << "Yes" << endl
#define pNo cout << "No" << endl
using namespace std;
using ll = long long;
#define int ll

signed main() {
	int N; cin >> N;
	vi vec(N);
	rep(i, N) cin >> vec[i];
	vi acc(N);
	for (int i = N - 2; i > -1; i--) {
		acc[i] = acc[i + 1] + vec[i + 1];
	}

	int ans = 0;
	for (int i = 0; i < N; i++) {
		int temp = vec[i] * (acc[i] % MOD);
		temp %= MOD;
		ans += temp;
		ans %= MOD;
	}

	cout << ans << endl;
}

Measured memory_bytes: 6364
void main() {
	auto N = ri;
	auto A = readAs!(long[]);
	auto arr = new long[](N);
	foreach(v; A) arr[v-1]++;
	auto arr2 = arr.map!(i => i * (i-1)/2).array;
	auto base = arr2.sum;
	debug arr.writeln;
	debug arr2.writeln;

	foreach(i; 0..N) {
		auto n = arr[A[i]-1];
		debug writefln("%d, %d", A[i], n);
		long tmp = base;
		tmp -= n * (n-1) / 2;
		tmp += (n-1) * (n-2) / 2;
		tmp.writeln;
	}
}

// ===================================

import std.stdio;
import std.string;
import std.functional;
import std.algorithm;
import std.range;
import std.traits;
import std.math;
import std.container;
import std.bigint;
import std.numeric;
import std.conv;
import std.typecons;
import std.uni;
import std.ascii;
import std.bitmanip;
import core.bitop;

T readAs(T)() if (isBasicType!T) {
	return readln.chomp.to!T;
}
T readAs(T)() if (isArray!T) {
	return readln.split.to!T;
}

T[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		res[i] = readAs!(T[]);
	}
	return res;
}

T[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		auto s = rs;
		foreach(j; 0..width) res[i][j] = s[j].to!T;
	}
	return res;
}

int ri() {
	return readAs!int;
}

double rd() {
	return readAs!double;
}

string rs() {
	return readln.chomp;
}

Measured memory_bytes: 15976
import java.util.List;
import java.util.Scanner;

public class Main {

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

	void run() {
		 Scanner sc = new Scanner(System.in);
	        String s = sc.next();

	        s = s.replaceAll("eraser", "0");
	        s = s.replaceAll("erase", "0");
	        s = s.replaceAll("dreamer", "0");
	        s = s.replaceAll("dream", "0");
	        s = s.replaceAll("0", "");


	        if (s.length()== 0){
	            System.out.println("YES");
	        } else {
	            System.out.println("NO");
	        }
	}

	//以下テンプレート

	public static String numtoalpha(int i) {

		String alpha = "abcdefghijklmnopqrstuvwxyz";

		return alpha.substring(i, i + 1);

	}

	public static int[] extgcd(int a, int b) {

		int x0 = 1;
		int x1 = 0;

		int y0 = 0;
		int y1 = 1;

		while (b != 0) {
			int q = a / b;
			int r = a % b;

			int x2 = x0 - q * x1;
			int y2 = y0 - q * y1;

			a = b;
			b = r;

			x0 = x1;
			x1 = x2;

			y0 = y1;
			y1 = y2;
		}

		return new int[] { a, x0, y0 };

	}

	static int gcd(int a, int b) {

		if (b == 0)
			return a;

		if (a < b) {
			int t = a;
			a = b;
			b = t;
		}

		return gcd(b, a % b);

	}

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

	static void swap(int[] a) {
		int t;

		t = a[0];
		a[0] = a[1];
		a[1] = t;

		return;
	}

	static <T> void output(List<T> list) {

		for (int i = 0; i < list.size(); i++) {
			System.out.print(list.get(i));

			if (i != list.size() - 1) {
				System.out.print(" ");
			} else {
				nl();
			}
		}

	}

	static void output(String[][] str) {

		for (int i = 0; i < str.length; i++) {
			for (int j = 0; j < str[i].length; j++) {
				print(str[i][j]);
			}

			nl();
		}

	}

	static void output(boolean flg, String Yes, String No) {

		if (flg) {
			pln(Yes);
		} else {
			pln(No);
		}

	}

	static void output(String[][] str, int digit) {

		String dig = "%" + String.valueOf(digit) + "s";

		for (int i = 0; i < str.length; i++) {
			for (int j = 0; j < str[i].length; j++) {
				System.out.printf(dig, str[i][j]);
			}
			nl();
		}

	}

	static void pln(String str) {
		System.out.println(str);
	}

	static void pln(int x) {
		System.out.println(x);
	}

	static void print(String str) {
		System.out.print(str);
	}

	static void print(int x) {
		System.out.print(x);
	}

	static void print(String str, int times) {
		for (int i = 0; i < times; i++) {
			print(str);
		}
	}

	static void print(int x, int times) {
		for (int i = 0; i < times; i++) {
			print(x);
		}
	}

	static void nl() {
		System.out.println();
	}

}


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

int main(){
    ll a, b, n;
    cin >> a >> b >> n;
    if(n < b){
        cout << a*n/b << endl;
    }   
    else{
        cout << a*(b-1)/b << endl;
    }
}

Measured memory_bytes: 3628
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<map>
#include<stack>
#include<cmath>
#include<iomanip>
#include<set>
#include<numeric>
#include<sstream>
#include<random>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, st, n) for (int i = st; i < n; ++i)
using pii = pair<int, int>;
const int inf = 1e9 + 7;
int dy[] = {0, 0, -1, 1, -1, 1, -1, 1};
int dx[] = {1, -1, 0, 0, -1, 1, 1, -1};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s; cin >> s;
    if (s[0] != s[1] && s[1] != s[2] && s[2] != s[0]) cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include <cmath>
#include <map>
#include <algorithm>
#include <string>
using namespace std;
int main(void){
    int a , b , c ;
    cin >> a >> b >> c ;
    int x , count , ans  ;
    
    cin >> x;
    count = 0;
    for(int i = 0 ;i <= a ; i++ ){
        for(int j = 0 ; j <= b ; j++ ){
            for(int k = 0 ; k <= c ; k++ ){
                if( x == (500 * i + 100 * j + 50 * k)){
                      count ++ ;
                }
            }
        }
    }
    cout << count << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define rep2(i,n) for(int i = 1; i <= (n); ++i)
#define rrep2(i,n) for(int i = (n); i > 0; --i)
#define srep(i,s,n) for(int i = s; i < (n); ++i)
#define rsrep(i,s,n) for(int i = (n)-1; i >= s; --i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aall(a) (a), (a)+countof(a)//for array sorting
#define raall(a) (a), (a)+countof(a), greater<>()
#define show(x) cout<<#x<<" = "<<(x)<<endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) { if (f) puts("YES"); else puts("NO"); }
#define yns(f) { if (f) puts("Yes"); else puts("No"); }
#define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define show_pair(...) cout<<#__VA_ARGS__<<" = "<<endl; for (const auto& x : (__VA_ARGS__)) { cout<<"  "<<x.fi<<" : "<<x.se<<endl; }
#define out_ary(...) { int n = (__VA_ARGS__).size(); rep(i, n) printf("%d%s", (__VA_ARGS__)[i], i != n-1 ? " " : "\n"); }
#define argmax(v) distance((v).begin(), max_element(all(v)))
#define argmin(v) distance((v).begin(), min_element(all(v)))
#define vmax(v) *max_element(all(v))
#define vmin(v) *min_element(all(v))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<P> vpair;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef vector<vint> vvint;
typedef vector<vll> vvll;
typedef vector<vstr> vvstr;
typedef vector<vbool> vvbool;
const ll LINF = 2000000000000000000ll;
const int INF = 1000000100;
const ll MOD = 1e9+7;


ll calc(int a, int b) {
    return pow((ll)a, 5)-pow((ll)b, 5);
}

int main() {
    int x;
    cin >> x;

    for (int i = -1000; i <= 1000; ++i) {
        for (int j = -1000; j <= 1000; ++j) {
            if (calc(i, j) == x) {
                cout << i << " " << j << endl;
                return 0;
            }
        }
    }

    return 0;
}

Measured memory_bytes: 4068
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)
#define repa(i,n) for (auto& i: n)

template<class T> inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}

#ifdef DEBUG
template <class T, class N> void verr(const T& a, const N& n) { rep(i, n) cerr << a[i] << " "; cerr << "\n" << flush; }
ll dbgt = 1; void err() { cerr << "passed " << dbgt++ << "\n" << flush; }
template<class H, class... T> void err(H&& h,T&&... t){ cerr<< h << (sizeof...(t)?" ":"\n") << flush; if(sizeof...(t)>0) err(forward<T>(t)...); }
#endif

const ll INF = 4e18;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
//--------------------------------------------------------------------------------//



int main() {
    init();
    ll H, W, N;
    cin >> H >> W >> N;
    using P = pair<ll, ll>;
    map<P, ll> mp;
    rep(_, N){
        ll a, b;
        cin >> a >> b;
        rep(h, 3)rep(w, 3){
            mp[{a + h - 1, b + w - 1}]++;
        }
    }

    vl ans(10);
    for(auto[p, c]: mp){
        auto [h, w] = p;
        if (h < 2 or h > H - 1 or w < 2 or w > W - 1) continue;
        ans[c]++;
    }

    ll al = (H - 2) * (W - 2);
    cout << al - accumulate(all(ans), 0ll) << endl;
    repe(i, 1, 10)
        cout << ans[i] << endl;
}

Measured memory_bytes: 59876
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>
#include <tuple>
#include <queue>
#include <bitset>
#include <set>
#include <map>
#include <list>

using ll = long long;
using ld = long double;
using namespace std;
const int INF = 1e9+100;
const ll INF64 = 7e18l;
const int mod = 1000000007;
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(a) (a).begin(), (a).end()
#define FIN ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);


int main(){
    FIN;
    int h,w,k;
    cin >> h >> w >> k;
    vector<string> t(h);
    for(int i=0;i<h;i++){
        string s;
        cin >> s;
        t[i] = s;
    }
    int ans = 0;

    for(int bit1 = 0;bit1 < (1<<h); bit1++){
        for(int bit2 = 0;bit2 < (1<<w); bit2++){
            int cur = 0;
            for(int i=0;i<h;i++){
                if(bit1 & (1<<i)) continue;
                for(int j=0;j<w;j++){
                    if(bit2 & (1<<j)) continue;
                    if(t[i][j] == '#') cur++;
                }
            }

            if(cur == k) ans++;
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3656
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();
    if(n%500 <= a){
      System.out.println("Yes");
    }else{
      System.out.println("No");
    }
  }
}

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

int main()
{
  int N; cin >> N;
  vector<int> d(N);
  for (int i = 0; i < N; i++) cin >> d[i];

  sort(d.begin(), d.end());

  cout << d[N/2] - d[N/2 - 1] << endl;
}

Measured memory_bytes: 764
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <numeric>
#include <cmath>

#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
using P = pair<ll, ll>;

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

const ll MOD = 1000000007;
const int INF = 1<<30;
//const ll INF = (ll)1e18 + 1;

template <class Abel> struct BIT {
  vector<Abel> dat[2];
  Abel UNITY_SUM = 0;                     // to be set

  /* [1, n] */
  BIT(int n) { init(n); }
  void init(int n) { for (int iter = 0; iter < 2; ++iter) dat[iter].assign(n + 1, UNITY_SUM); }

  /* a, b are 1-indexed, [a, b) */
  inline void sub_add(int p, int a, Abel x) {
    for (int i = a; i < (int)dat[p].size(); i += i & -i)
      dat[p][i] = dat[p][i] + x;
  }
  inline void add(int a, int b, Abel x) {
    sub_add(0, a, x * -(a - 1)); sub_add(1, a, x); sub_add(0, b, x * (b - 1)); sub_add(1, b, x * (-1));
  }
  /* a is 1-indexed */
  inline void add_mono(int a, Abel x) {
      for (int i = a; i < (int)dat.size(); i += i & -i)
          dat[i] = dat[i] + x;
  }
  /* a is 1-indexed, [a, b) */
  inline Abel sub_sum(int p, int a) {
    Abel res = UNITY_SUM;
    for (int i = a; i > 0; i -= i & -i) res = res + dat[p][i];
    return res;
  }
  inline Abel sum(int a, int b) {
    return sub_sum(0, b - 1) + sub_sum(1, b - 1) * (b - 1) - sub_sum(0, a - 1) - sub_sum(1, a - 1) * (a - 1);
  }

  /* debug */
  void print() {
    for (int i = 1; i < (int)dat[0].size(); ++i) cout << sum(i, i + 1) << ",";
    cout << endl;
  }
};

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

  vector<BIT<int>> bit(26, BIT<int>(N + 10));
  rep(i, N){
    bit[S[i] - 'a'].add(i + 1, i + 2, 1);
  }
  for (int query = 0; query < Q; query++){
    int type; cin >> type;
    if (type == 1){
      int ind; char nc; cin >> ind >> nc; --ind;
      auto pc = S[ind];
      S[ind] = nc;
      bit[pc - 'a'].add(ind + 1, ind + 2, -1);
      bit[nc - 'a'].add(ind + 1, ind + 2, 1);
    }
    else {
      int l, r; cin >> l >> r; --l; --r;
      int ans = 0;
      rep(c, 26) if (bit[c].sum(l + 1, r + 2)) ++ans;
      cout << ans << endl;
    }
  }
}


Measured memory_bytes: 106500
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T, class U> using Pa = pair<T, U>;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vec<int> A(N);
    for(int i=0;i<N;i++) cin >> A[i];
    vvec<int> g(N);
    for(int i=0;i<N-1;i++){
        int a,b;
        cin >> a >> b;
        a--; b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    vec<Pa<int,int>> pre(N);
    vec<int> ans(N);
    int inf = 1e9;
    vec<int> v(N+1,inf);
    v[0] = 0;
    auto dfs = [&](auto&& self,int cur,int par,int res)->void{
        int id = lower_bound(v.begin(),v.end(),A[cur])-v.begin();
        bool update = false;
        if(v[id]>A[cur]){
            pre[cur] = {id,v[id]};
            v[id] = A[cur];
            update = true;
        }
        ans[cur] = max(res,id);
        for(auto& to:g[cur]) if(to!=par){
            self(self,to,cur,max(res,ans[cur]));
        }
        if(update) v[pre[cur].first] = pre[cur].second;

    };
    dfs(dfs,0,-1,-1);
    for(int i=0;i<N;i++) cout << ans[i] << "\n";
}

Measured memory_bytes: 35336
from math import factorial

N, M = list(map(int, input().split()))
THE_NUM = 10**9 + 7

combination_num = 0
# if N = M, the number of combination is 2N!M!.
if N == M:
  combination_num = 2 * factorial(N) * factorial(M)
# if |N - M| = 1, the number of combination is M!N!.
elif abs(N - M) == 1:
  combination_num = factorial(N) * factorial(M)
# if none of the above conditions,
# can't line up. so not change combination_num from 0.

print(combination_num % THE_NUM)

Measured memory_bytes: 5180
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(int)(a); (i)<(int)(b); ++(i))
#define rFor(i, a, b) for(int (i)=(int)(a)-1; (i)>=(int)(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<int, lint> pil;
typedef pair<lint, lint> pll;
template<class T>bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T>bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;}

constexpr lint mod = 1e9+7;
constexpr lint INF = mod*mod;
constexpr int MAX = 100010;

vector<int> min_factor, prime;

void sieve(int n){
    min_factor.resize(n+1, 0);
    For(i, 2, n+1){
        if(min_factor[i] == 0){
            min_factor[i] = i;
            prime.push_back(i);
        }
        for(int x: prime){
            if(x*i > n || x > i) break;
            min_factor[x*i] = x;
        }
    }
}

int main(){
    sieve(1300000);
    int n;
    while(scanf("%d", &n) && n){
        auto t = lower_bound(prime.begin(), prime.end(), n);
        printf("%d\n", *t == n ? 0 : *t-*(t-1));
    }
}


Measured memory_bytes: 8344
#include <bits/stdc++.h>
#include <stdio.h>
#include <numeric>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define repone(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define Rep(j,n) for(int j=0;j<(int)(n);++j)
#define Repo(j,o,n) for(int j=o;j<(int)(n);++j)
#define Repone(j,n) for(int j=1;j<(int)(n);++j)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define int long long
#define pb(a) push_back(a)
#define pbpair(a,b) push_back(make_pair(a,b))
#define MOD 1000000007
#define INF 9223372036854775807
#define pairint pair<int,int>
typedef pair< int , int> P;
int gcd( int x, int y ){
   return y ? gcd(y, x%y) : x;
 }
bool pairCompare(const P& firstElof, const P& secondElof)
{
  if(firstElof.second!= secondElof.second)    return firstElof.second> secondElof.second;
  else return firstElof.first< secondElof.first;
}
signed main() {
int x=0,y=0,z=0,w=0,n=0,m=0;
std::vector< pairint > v(101);
string k;
while(std::cin >> x){
v[x].first=x;
v[x].second++;
}
sort(all(v),pairCompare);
std::cout << v[0].first << '\n';
repone(i,101){
  if(v[0].second==v[i].second){
    std::cout << v[i].first << '\n';
  }else {
    return 0;
  }
}
}



Measured memory_bytes: 3052
/* Simplicity and Goodness */

#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>

using namespace std;
// using namespace __gnu_pbds;
// typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;

void my_dbg() { cout << endl; }
template<typename Arg, typename... Args> void my_dbg(Arg A, Args... B) { cout << ' ' << A; my_dbg(B...); }
#define dbg(...)  cout << "(" << #__VA_ARGS__ << "):", my_dbg(__VA_ARGS__)

#define scn(n) scanf("%d", &n)
#define lscn(n) scanf("%lld", &n)
#define pri(n) printf("%d ", (int)(n))
#define prin(n) printf("%d\n", (int)(n))
#define lpri(n) printf("%lld ", n)
#define lprin(n) printf("%lld\n", n)
#define rep(i,a,b) for(int i=a; i<(int)b; i++)
#define pb push_back
#define mp make_pair
#define F first
#define S second

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;

const int inf = INT_MAX;
const int ninf = INT_MIN;
const int mod = 1e9+7;
const int maxN = 1e6+2;


int main()
{
   ll a, b, c, d;
   cin >> a >> b >> c >> d;

   ll ans = max({a * c, a * d, b * c, b * d});

   lprin(ans);

   return 0;
}

Measured memory_bytes: 3760
#include<iostream>
using namespace std;
int main()
{
	int N, i, j, * sort,flag=1,num=0,temp;
	cin >> N;
	sort = (int*)malloc(sizeof(int) * N);
	for (i = 0; i < N; i++)
		cin >> sort[i];
	for(i=0;i<N&&flag==1;i++)
		for(j=N-1,flag=0;j>i;j--)
			if (sort[j - 1] > sort[j])
			{
				temp = sort[j - 1];
				sort[j - 1] = sort[j];
				sort[j] = temp;
				num++;
				flag = 1;
			}
	for (i = 0; i < N - 1; i++)
		cout << sort[i] << ' ';
	cout << sort[N - 1] << endl;
	cout << num << endl;
	return 0;
}


Measured memory_bytes: 3092
import java.util.*;

class Main {
    final Scanner sc = new Scanner(System.in);

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

    private void run() {
        System.out.println(sc.nextInt() + sc.nextInt() + sc.nextInt() >= 22 ? "bust" : "win");
    }
}



Measured memory_bytes: 21716
#include <bits/stdc++.h>
	#include <set>
	#define ll long long 
	#include <string>
	#define pb push_back
	#define mp make_pair
	# define pi 3.14159265358979323846
	#define mod 1000000007
    #define rep(i,n) for(i=0;i<n;i++)
    #define rep1(i,n) for(i=1;i<n;i++)
	using namespace std;
	ll int multiply(ll int a,ll int b)
{
	ll int ans=(a%mod*b%mod)%mod;
	return ans;
}
ll int add(ll int a, ll int b)
{
	ll int ans=(a%mod+b%mod)% mod;	
	return ans;
}

	int power(ll int x,  ll int y, ll int p)  
{  
    ll int res = 1;     // Initialize result  
  
    x = x % p; // Update x if it is more than or  
                // equal to p 
   
    if (x == 0) return 0; // In case x is divisible by p; 
  
    while (y > 0)  
    {  
        // If y is odd, multiply x with result  
        if (y & 1)  
            res = (res*x) % p;  
  
        // y must be even now  
        y = y>>1; // y = y/2  
        x = (x*x) % p;  
    }  
    return res;  
}  
	void fastio()
	{					
		#ifndef ONLINE_JUDGE
	    // for getting input from input.txt
	    freopen("input.txt", "r", stdin);
	    // for writing output to output.txt
	    freopen("output.txt", "w", stdout);
	    #endif
	    ios_base::sync_with_stdio(false);
	    cin.tie(NULL);
	    cout.tie(NULL);

	}
	 ll int dp[101][100001];
	void solve()
	{
		ll int n,w,i,j;cin>>n>>w;
		ll int weights[n],values[n];
		rep(i,n)
		{
			cin>>weights[i]>>values[i];

		}
		
		rep(i,101)
		rep(j,100001)
		dp[i][j]=1e10;
		

		// rep(i,100001)
		// dp[0][i]=0;

		rep(i,101)
		dp[i][0]=0;

		for(i=1;i<=n;i++)
		{
			for(j=0;j<=100000;j++)
			{
				ll int op1=(values[i-1]>j)?1e10:weights[i-1]+dp[i-1][j-values[i-1]];
				ll int op2=dp[i-1][j];
				dp[i][j]=min(op1,op2);	
				

			}
			

		}
		 
		
		ll int ans=-1;
		for(i=0;i<=n;i++)
		{
			for(j=0;j<=100000;j++)
			{
				if (dp[i][j]<=w)
					ans=max(ans,j);
			}
		}
		cout<<ans<<endl;
    }
	int main()
	{
		fastio();
		ll int t;
		t=1;
		// cin>>t;
		
		while(t--)
		{
			solve();
		}
			
	}
			

Measured memory_bytes: 82508
//#include <tourist>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = 1e9;
const ll LINF = ll(1e18);
const int MOD = 1000000007;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define debug(v)          \
    cout << #v << ":";    \
    for (auto x : v)      \
    {                     \
        cout << x << ' '; \
    }                     \
    cout << endl;
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
//cout<<fixed<<setprecision(15);有効数字15桁
//-std=c++14
//-std=gnu++17
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a,b,c;
    cin>>a>>b>>c;
    if(abs(b-a)<=abs(c-a))cout<<'A'<<"\n";
    else
        cout << 'B' << "\n";
}


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

using namespace std;

const int N = 1e5+6, M = 1e5+5, OO = 0x3f3f3f3f;
int n , arr[N] ,op1 ,op2 , dp[N];
int frog(int i){

  if(i <= 0) return 0;
  if(dp[i] != -1) return dp[i];
      op1 = abs(arr[i]-arr[i-1])+frog(i-1);
      op2 = abs(arr[i]-arr[i-2])+frog(i-2);
  return dp[i] =min(op1,op2);
}

int main(){
  dp[0] = 0;

  scanf("%d",&n );
  memset(dp ,-1 , sizeof dp);
  for(int i = 0 ; i<n ;i++)
    scanf("%d",arr+i );
    dp[1] = abs(arr[1] -arr[0]);
  printf("%d\n",frog(n-1) );
    return 0;
}


Measured memory_bytes: 4096
#include <bits/stdc++.h>  
using namespace std;  
#define INF 0x3f3f3f3f  
typedef long long ll;  
const int N =  1000100;  
const int mod = 1e9 + 7;
#define FI first
#define SE second
typedef pair<int, int>pii;
 
int main()  
{  
 // freopen("in.txt","r",stdin);
 	int n;
 	while (~scanf("%d", &n))
 	{
 		int ans = 1, cnt = 0;;
 		for (int i = 2; i <= n; i++)
 		{
 			int tmp = 0;
 			int cur = i;
 			while (cur%2 == 0)
 			{
 				tmp++;
 				cur /= 2;
 			}
 			if (cnt < tmp)
 			{
 				cnt = tmp;
 				ans = i;
 			}
 		}
 		printf("%d\n", ans);
 	}
   
 
   return 0;  
}  

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

int main(){
  int n,m;
  cin >> n >> m;
  vector<int> a(n);
  long long sum = 0;
  int p = 0;
  for(int i = 0; i < n; i++){
    cin >> a[i];
    sum += a[i];
  }
  for(int i = 0; i < n; i++){
    if( a[i] * 4 * m >= sum ) p++;
  }
  cout << ( p >= m ? "Yes" : "No" ) << endl;
}

Measured memory_bytes: 3616
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef vector<pi> vii;

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

  int n;
  cin>>n;
  if( n>=1000){
    cout<<"ABD\n";
  }else{
    cout<<"ABC\n";
  }



  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main() {
int aa;
char bb[aa];
scanf("%d %s", &aa, bb);
if (aa%2 != 0){
    printf("No");
    return 0;
}
for(int j=0; j<aa/2; j++){
    if(bb[j] != bb[aa / 2 +j]){
        printf("No");
        return 0;
    }
}
printf("Yes");



    return 0;
}

Measured memory_bytes: 1736
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main {
    public static void main(final String[] args) {
        final Scanner scanner = new Scanner(System.in);
        final int n = scanner.nextInt();
        final int m = scanner.nextInt();

        final int sum = IntStream.range(0, m)
                .mapToObj(i -> scanner.nextInt())
                .mapToInt(Integer::intValue)
                .sum();

        System.out.println(n - sum >= 0 ? n - sum : -1);
    }
}


Measured memory_bytes: 46860
def nearest(x,ar):
  i=0;t=x
  while t in ar:
    t-=1
  v=t
  t=x
  while (t in ar):
    t+=1
  if x-v>t-x:return t
  else: return v
  

def main():
  x,n=map(int,input().split())
  if n==0:
    print(x)
  else:
    ar=list(map(int,input().split()))
    print(nearest(x,ar))
main()

Measured memory_bytes: 61764
#include "stdio.h"
#include <string.h>
int main(void)
{
    char inp[10];
	long len = 0;
	long cnt = 0;
	
	scanf("%s", inp);
    
    if (0 == strcmp(inp, "Sunny")) {
    	printf("Cloudy\n");
    } else if (0 == strcmp(inp, "Cloudy")) {
        printf("Rainy\n");
    } else if (0 == strcmp(inp, "Rainy")) {
        printf("Sunny\n");
    } else {
    	;/**/
    }
 
	return 0;
}

Measured memory_bytes: 128
c=[[int(i) for i in input().split()]for i in range(3)]
a=[0]*3
b=[0]*3
for i in range(3):
    for j in range(3):
        b[j]=c[i][j]-a[0]
for i in range(3):
    for j in range(3):
        a[j]=c[j][0]-b[0]
judge=True
for i in range(3):
    for j in range(3):
        if a[j]+b[i]!=c[j][i]:
            judge=False
if judge:
    print("Yes")
else:
    print("No")
        


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i = (a); i <= (b); ++i)
#define FORD(i,a,b) for(int i = (a); i >= (b); --i)
#define RI(i,n) FOR(i,1,(n))
#define REP(i,n) FOR(i,0,(n)-1)
#define mini(a,b) a=min(a,b)
#define maxi(a,b) a=max(a,b)
#define mp make_pair
#define pb push_back
#define st first
#define nd second
#define sz(w) (int) w.size()
typedef vector<int> vi;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
const int inf = 1e9 + 5;
const int nax = 1e6 + 5;

vector<pair<int,int>> w;

int main() {
	int A, B;
	scanf("%d%d", &A, &B);
	for(int i = 0; i < A; ++i) {
		int a;
		scanf("%d", &a);
		w.push_back({a, 0});
	}
	for(int i = 0; i < B; ++i) {
		int a;
		scanf("%d", &a);
		w.push_back({a, 1});
	}
	sort(w.begin(), w.end());
	long long ans = 0;
	for(pair<int,int> p : w) {
		int x = p.first;
		if(p.second == 0) {
			ans += (long long) (B+1) * x;
			A--;
		}
		else {
			ans += (long long) (A+1) * x;
			B--;
		}
	}
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 2420
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>

using namespace std;

int main() {
	int n, k;  cin >> n >> k;
	string s; cin >> s;
	vector<int> cnt;
	int t = 1;
	for (int i = 1; i < n; ++i) {
		if (s[i] == s[i - 1]) ++t;
		else {
			cnt.push_back(t);
			t = 1;
		}
	}
	if (t) cnt.push_back(t);
	int ans = 0, now = 0, i;
	for (i = 0; i < min(2 * k + (s[0] == '0' ? 0 : 1), (int)cnt.size()); ++i) ans += cnt[i];
	int tmp = ans;
	for (; i < cnt.size(); ++i) {
		tmp += cnt[i];
		if (s[0] == '0' && i % 2 == 0) {
			tmp -= cnt[i - 2 * k];
			if (i != 2 * k) tmp -= cnt[i - 2 * k - 1];
		}
		else if (s[0] == '1' && (i & 1)) tmp -= cnt[i - 2 * k - 1] + cnt[i - 2 * k];
		ans = max(ans, tmp);
	}
	cout << ans << endl;

	return 0;
}

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

using namespace std;

const int inf = 0x3f3f3f3f;
const long long mod = 1e9+7;

string matriz[1010];
long long pd[1010][1010];
int n, m;

bool ins(int x, int y){
  return x>=0 && x<n && y>=0 && y<m;
}

long long solve(int x, int y){
  if(pd[x][y] != -1) return pd[x][y];
  if(x == n-1 && y == m-1){
    pd[x][y] = 1;
    return pd[x][y];
  }
  
  pd[x][y] = 0;

  if(ins(x+1, y) && matriz[x+1][y] == '.')pd[x][y] = (pd[x][y] + solve(x+1, y)) % mod;
  if(ins(x, y+1) && matriz[x][y+1] == '.')pd[x][y] = (pd[x][y] + solve(x, y+1)) % mod;

  return pd[x][y];
}

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

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

  memset(pd, -1, sizeof pd);

  cout<<solve(0,0);
}

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

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

    if (count(s.begin(), s.end(), 'a') && count(s.begin(), s.end(), 'b') &&
        count(s.begin(), s.end(), 'c'))
        cout << "Yes" << endl;
    else
        cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 256
n, m  = map(int, input().split())

a = []
b = []

for _ in range(n):
  a.append(list(input()))

for _ in range(m):
  b.append(list(input()))

for i in range(n-m+1):
  for j in range(n-m+1):
   flag = True
   for k in range(m):
     for l in range(m):
       if(a[i+k][j+l] != b[k][l]):
         flag = False
         break
     if(flag == False):
       break

   if(flag == True):
     print("Yes")
     exit()


print("No")

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

map< vector<int> , int > dp[101];
int n;
int D[100];
int A[100];



int calc(vector<int> &vec,int key){
  bool flg=false;
  int res=0;
  for(int i=0;i<(int)vec.size();i++){
    if(vec[i]==key){
      flg=true;
    }else if(flg){
      if(key-vec[i]<=D[key]){
        res+=A[key];
      }
    }else{
      if(key-vec[i]<=D[vec[i]]){
        res+=A[vec[i]];
      }
    }
  }
  return res;
}

int main(){
  cin>>n;
  for(int i=0;i<n;i++)cin>>D[i];
  for(int i=0;i<n;i++)cin>>A[i];
  map<vector<int>,int> :: iterator it;
  vector<int> vec,vec2;
  int cost;
  vec.push_back(0);
  dp[0][vec]=0;

  for(int i=0;i+1<n;i++){

    for(it=dp[i].begin();it!=dp[i].end();it++){
      vec=it->first;
      cost=it->second;
      
      vec.push_back(i+1);
      int size=vec.size();
      for(int j=size-1;j>=0;j--){
        if(j+1<size)swap(vec[j],vec[j+1]);        
        vector<int> next=vec;
        vector<int> :: iterator it2;
        it2=find(next.begin(),next.end(),i+1-7);
        if(it2!=next.end())next.erase(it2);        
        int ncost=cost+calc(vec,i+1);
        dp[i+1][next]=max(dp[i+1][next],ncost);
      }      
    }
  }

  int ans=0;
  for(it=dp[n-1].begin();it!=dp[n-1].end();it++){
    ans=max(ans, it->second);
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 60536
# AOJ 1060: No Story
# Python3 2018.6.8 bal4u

MAX = 1000004
ptbl = [ 3,   5,   7,  11,  13,  17,  19,  23,  29,
   31,  37,  41,  43,  47,  53,  59,  61,  67,  71,
   73,  79,  83,  89,  97, 101, 103, 107, 109, 113,
  127, 131, 137, 139, 149, 151, 157, 163, 167, 173,
  179, 181, 191, 193, 197, 199, 211, 223, 227, 229,
  233, 239, 241, 251, 257, 263, 269, 271, 277, 281,
  283, 293, 307, 311, 313, 317, 331, 337, 347, 349,
  353, 359, 367, 373, 379, 383, 389, 397, 401, 409,
  419, 421, 431, 433, 439, 443, 449, 457, 461, 463,
  467, 479, 487, 491, 499, 503, 509, 521, 523, 541,
  547, 557, 563, 569, 571, 577, 587, 593, 599, 601,
  607, 613, 617, 619, 631, 641, 643, 647, 653, 659,
  661, 673, 677, 683, 691, 701, 709, 719, 727, 733,
  739, 743, 751, 757, 761, 769, 773, 787, 797, 809,
  811, 821, 823, 827, 829, 839, 853, 857, 859, 863,
  877, 881, 883, 887, 907, 911, 919, 929, 937, 941,
  947, 953, 967, 971, 977, 983, 991, 997 ]
 
def sieve():
	for p in ptbl:
		for i in range(p*p, MAX, p): tbl[i] = 1
	for i in range(997, MAX, 2):
		if tbl[i] == 0: ptbl.append(i)
 
def prime_factor(n):
	power = []
	if (n & 1) == 0:
		c = 0
		while True:
			n >>= 1
			c += 1
			if n & 1: break
		power.append(c)
	if n <= 1: return power
	if n <= MAX and tbl[n] == 0:
		power.append(1)
		return power
	k = int(n**0.5)
	for p in ptbl:
		if n <= 1: break
		if p > k or (n <= MAX and tbl[n] == 0):
			power.append(1)
			break
		if n % p: continue
		c = 0
		while True:
			n //= p
			c += 1
			if n % p: break
		power.append(c)
	return power

tbl = [0]*MAX
sieve()
while True:
	n = int(input())
	if n == 0: break
	if n == 1:
		print(1)
		continue
	if n <= MAX and (n & 1) and tbl[n] == 0:
		print(2)
		continue
	power = prime_factor(n)
	ans = 1
	for p in power: ans = ans*(1+(p<<1))
	print((ans+1)>>1)


Measured memory_bytes: 16608
import math
Input = list(map(int,input().split()))
a = Input[0]
b = Input[1]
x = Input[2]

taiseki = a**2*b

if x<=taiseki/2:
    theta = 90-math.degrees(math.atan(2*x/(a*b**2)))
else:
    theta = math.degrees(math.atan(-2*(x-a**2*b)/a**3))
print(theta)


Measured memory_bytes: 3064
def main():
    N, M = map(int, input().split())
    X = [list(map(int, input().split())) for _ in range(N)]

    ans = 0
    for i in [-1,1]:
        for j in [-1,1]:
            for k in [-1,1]:
                tmp = []
                for x, y, z in X:
                    tmp.append(i*x + j*y + k*z)
                tmp.sort(reverse=True)
                ans = max(ans, sum(tmp[:M]))
    
    print(ans)

main()

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

#define mem( arr, i ) fill( arr, arr + sizeof (arr), i )
#define MEM( arr, i ) memset( arr, i, sizeof (arr) )
#define Push push_back
#define Pair make_pair
typedef unsigned long long ull;
typedef long long lli;
typedef pair<int,int> pii;
typedef pair<lli,lli> pll;
typedef vector<int> vcI;
typedef vector<lli> vcL;
typedef vector<pii> vPI;
typedef vector<pll> vPL;
//typedef priority_queue<T> prior_S<T>;
//typedef priority_queue< T, vector<T>, greater<T> > prior_B<T>;
const double PI = 3.141592653589793;
const lli I_MAX = 1LL << 60;
const lli mod = 1000000007;


void precal() {

	return;
}

void solve() {
	lli n, m, q, k;
	cin >> n >> m >> q;
	
	int pre[ n+5 ][ n+5 ]; // starts at i and last for j
	MEM( pre, 0 );
	
	for (int i = 0; i < m; ++i) {
		lli l, r;
		cin >> l >> r;
		pre[l][ r-l ]++ ;
	}
	
	for (int i = 1; i <= n; ++i) {
		for (int j = 1; j < n; ++j) {
			pre[i][j] += pre[i][ j-1 ];
		}
	}
	
	for (int i = 0; i < q; ++i) {
		lli l, r, ans = 0;
		cin >> l >> r;
		
		for (int i = l; i <= r; ++i) {
			ans += pre[i][ r-i ];
		}
		
		cout << ans << '\n';
	}
}

int main() {
	precal();
	int t = 1;
//	cin >> t;
	for (int i = 1; i <= t; ++i) {
//		printf("Case #%d: ", i );
		solve();
	}
	return 0;
}



Measured memory_bytes: 1920
#include <bits/stdc++.h>
  
using namespace std;
  
template<class T> void ckmin(T &a, T b) { a = min(a, b); }
template<class T> void ckmax(T &a, T b) { a = max(a, b); }
  
#define pb push_back
#define mp make_pair
#define cotu cout
#define itn int
#define Red ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define F first
#define S second
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int i = 0; i < n; ++i)
#define repr(i,n) for(int i = n - 1; i >= 0; --i)
#define Rep(i, a, n) for(int i = (a); i <=(n); ++i)
#define repst(i, n) for(auto it = n.begin(); it != n.end(); ++it)
#define Repr(i, a, n) for(int i = (n); i >= (a); --i)
  
#define ordered_set tree<int , null_type,less<int >, rb_tree_tag,tree_order_statistics_node_update> 
  
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
  
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
  
const int inf = int(1e9);
const int mod = inf + 7;
const int N = 1e6 + 555; // TL MB
const double PI = acos(-1.0);
 
void mul(ll &x, ll y){
	x = (x * y) % mod;
}
 
void add(ll &x, ll y){
	x += y;
	if(x >= mod) x -= mod;
	if(x < 0) x += mod;
}
ll bp(ll a, ll n){
	ll r = 1;
	while(n){
		if(n & 1) mul(r, a);
		mul(a, a);
		n >>= 1;
	}
	return r;
}
ll inv(ll n){
	return bp(n, mod - 2);
}
ll c[N];
void solve(){
	ll n, a, b;
	cin >> n >> a >> b;
	c[0] = 1;
	for(int i = 1; i <= max(a, b); ++i) c[i] = c[i - 1] * (n - i + 1) % mod * inv(i) % mod;
	ll cur = bp(2, n);
	ll x = c[a];
	ll y = c[b];
	add(cur, -1);
	add(cur, -x);
	add(cur, -y);
	cout << cur << endl;
}


 
 
int main()
{
    Red;
  	// int T; cin >> T; while(T--)
    solve();
    return 0;
}

Measured memory_bytes: 1792
#include"bits/stdc++.h"
using namespace std;
#define REP(k,m,n) for(int (k)=(m);(k)<(n);(k)++)
#define rep(i,n) REP((i),0,(n))
using ll = long long;
constexpr ll INF = 1ll << 60;

int main()
{
	// input
	ll N, M;
	cin >> N >> M;
	vector<pair<ll, ll>> acs;
	rep(i, M) {
		ll a, b, way = 0;
		cin >> a >> b;
		rep(j, b) {
			ll c;
			cin >> c;
			c--;
			way |= (1 << c);
		}
		acs.push_back({ a,way });
	}

	// dp
	ll siz = 1 << N;
	vector<ll> dp(siz, INF);
	dp[0] = 0;
	for (auto ac : acs) {
		ll a, c;
		tie(a, c) = ac;
		rep(way, siz)dp[way | c] = min(dp[way | c], dp[way] + a);
	}

	// output
	cout << (dp.back() == INF ? -1 : dp.back()) << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <limits.h>
#include <float.h>
#include <numeric>
#include <queue>

using namespace std;

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

#define fs first
#define sc second

ll si[51];
ll pa[51];

ll calc(int n, ll x){
    if(n == 0){
        return 1LL;
    }
    else{
        ll total = si[n];
        if(x == 0){
            return 0LL;
        }
        else if(x < total / 2){
            return calc(n-1, x-1);
        }
        else if(x == total / 2){
            return pa[n-1] + 1LL;
        }
        else if(x < total - 1){
            return pa[n-1] + 1LL + calc(n-1, x-si[n-1]-2);
        }
        else{
            return pa[n-1] * 2 + 1;
        }
    }
}


int main(){
    ll N, X;
    cin >> N >> X;
    si[0] = 1;
    pa[0] = 1;
    for(int i = 1; i <= N; i++){
        si[i] = si[i-1] * 2 + 3;
        pa[i] = pa[i-1] * 2 + 1;
    }

    cout << calc(N, X-1) << endl;


    return 0;
}

Measured memory_bytes: 256