akhauriyash/Code-Regression huggingface dataset:
#![allow(unused_parens)]
#![allow(unused_imports)]
#![allow(non_upper_case_globals)]
#![allow(non_snake_case)]
#![allow(unused_mut)]
#![allow(unused_variables)]
#![allow(dead_code)]

use itertools::Itertools;
use proconio::input;
use proconio::marker::{Chars, Usize1};

#[allow(unused_macros)]
#[cfg(debug_assertions)]
macro_rules! mydbg {
    //($arg:expr) => (dbg!($arg))
    //($arg:expr) => (println!("{:?}",$arg));
      ($($a:expr),*) => {
          eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
      }
}
#[cfg(not(debug_assertions))]
macro_rules! mydbg {
    ($($arg:expr),*) => {};
}

macro_rules! echo {
    ($($a:expr),*) => {
          $(println!("{}",$a))*
      }
}

use std::cmp::*;
use std::collections::*;
use std::ops::{Add, Div, Mul, Sub};

#[allow(dead_code)]
static INF_I64: i64 = 92233720368547758;
#[allow(dead_code)]
static INF_I32: i32 = 21474836;
#[allow(dead_code)]
static INF_USIZE: usize = 18446744073709551;
#[allow(dead_code)]
static M_O_D: usize = 1000000007;
#[allow(dead_code)]
static PAI: f64 = 3.1415926535897932;

trait IteratorExt: Iterator {
    fn toVec(self) -> Vec<Self::Item>;
}

impl<T: Iterator> IteratorExt for T {
    fn toVec(self) -> Vec<Self::Item> {
        self.collect()
    }
}

trait CharExt {
    fn toNum(&self) -> usize;
    fn toAlphabetIndex(&self) -> usize;
    fn toNumIndex(&self) -> usize;
}
impl CharExt for char {
    fn toNum(&self) -> usize {
        return *self as usize;
    }
    fn toAlphabetIndex(&self) -> usize {
        return self.toNum() - 'a' as usize;
    }
    fn toNumIndex(&self) -> usize {
        return self.toNum() - '0' as usize;
    }
}

trait VectorExt {
    fn joinToString(&self, s: &str) -> String;
}
impl<T: ToString> VectorExt for Vec<T> {
    fn joinToString(&self, s: &str) -> String {
        return self
            .iter()
            .map(|x| x.to_string())
            .collect::<Vec<_>>()
            .join(s);
    }
}

trait StringExt {
    fn get_reverse(&self) -> String;
}
impl StringExt for String {
    fn get_reverse(&self) -> String {
        self.chars().rev().collect::<String>()
    }
}

trait UsizeExt {
    fn pow(&self, n: usize) -> usize;
}
impl UsizeExt for usize {
    fn pow(&self, n: usize) -> usize {
        return ((*self as u64).pow(n as u32)) as usize;
    }
}

fn main() {
    use itertools_num::ItertoolsNum as _;
    input! {
       N: usize,
       D:i64,
    }

    let mut ans: usize = 0;
    for i in 0..N {
        input! {
            x:i64,
            y:i64,
        }

        let d = x * x + y * y;
        if D * D >= d {
            ans += 1;
        }
    }

    echo!(ans);
}


Measured memory_bytes: 4904
def gcd(x, y):
    while y != 0:
        x, y = y, x % y
    return x
 
N = int(input())
lst = [int(x) for x in input().split()]
 
l = [0] * N
r = [0] * N
 
l[0] = lst[0]
r[-1] = lst[-1]
 
for i in range(1, N):
    l[i] = gcd(l[i-1], lst[i])
 
for i in range(N-2, -1, -1):
    r[i] = gcd(r[i+1], lst[i])

ret = max(r[1], l[-2])
for i in range(1, N-1):
    ret = max(ret, gcd(l[i-1], r[i+1]))
print(ret)

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

int main() {
  int n,m,sum=0;
  cin >> n >> m;
  
  vector<int> num(m);

  for (int i = 0; i < m; i++) {
    cin >> num.at(i);
    sum += num.at(i);
  }
  if (sum <= n) {
    cout << n - sum << endl;
  }
  else cout << -1 << endl;
}

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

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

bool is_palindrome(string s){
    string t(s.rbegin(),s.rend());
    return s == t;
}
 

int main(){
	string s;
    cin>>s;
    int n=s.size();
    if(is_palindrome(s) && is_palindrome(s.substr(0,(n-1)/2)) && is_palindrome(s.substr((n+1)/2))){
        cout<<"Yes"<<endl;
    }
    else cout<<"No"<<endl;

	return 0;
}


Measured memory_bytes: 3636
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int numA = sc.nextInt();
        int numB = sc.nextInt();
        int numC = sc.nextInt();


        int numCount = 0;
        for (int n = 0; n <= numC; n++) {
            while (numCount < numC) {
                if (numB / numA != 0) {
                    numB = numB - numA;
                    numCount = numCount + 1;
                }
                break;
            }
        }
        System.out.println(numCount);
    }
}

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

int main()
{
	int ret = 0;
	int m = 10;
	for (int i = 0; i < 5; ++i) {
		if (ret % 10 != 0) {
			m = min(ret % 10, m);
			ret += 10 - (ret % 10);
		}
		int t;
		cin >> t;
		ret += t;
	}

	if(m != 10 && (ret % 10) != m){
		int t = (ret % 10) == 0 ? 10 : (ret % 10);
		ret -= t - m;
	}

	cout << ret << endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>

#define max(x,y) (x)>(y) ? (x) : (y)

using namespace std;

int main()
{
	int N,Q,c[300001]={0},m=0,q;
	cin>>N>>Q;
	for (int i=0; i<N; i++) {
		int t;
		cin>>t;
		c[t]=1;
		m=max(m,t);
	}
	
	for (int i=0; i<Q; i++) {
		cin>>q;
		if (q>m) {
			cout<<m<<endl;
			continue;
		}
		bool flag=false;
		for (int j=q-1; j>=0; j--) {
			for (int k=0; k+j<=300000; k+=q) {
				if (c[k+j]==1&&(k!=0||j!=0)) {
					flag=true;
					break;
				}
			}
			if (flag) {
				cout<<j<<endl;
				break;
			}
		}
	}
}

Measured memory_bytes: 2340
# -*- coding: utf-8 -*-
import collections
N = int(input())
A = list(map(int, input().split()))
A_amount = dict(collections.Counter(A))

result = sum(A)

Q = int(input())
for q in range(Q):
    B, C = map(int, input().split())
    B_elem = A_amount.get(B, None)
    if B_elem is not None:
        C_elem = A_amount.get(C, None)
        if C_elem is not None:
            A_amount.pop(B)
            A_amount[C] = B_elem+C_elem
        else:
            A_amount.pop(B)
            A_amount[C] = B_elem

        result += (C-B)*B_elem

    print(result)

Measured memory_bytes: 21256
// AOJ ALDS1_7_C: http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_7_C

package main

import (
	"fmt"
)

var NULL = -1

type node struct {
	// 親ノード, 左子ノード, 右子ノード, 子の数, 兄弟ノード, 深さ, 高さ
	parent, left, right, degree, sibling, depth, height int
}

type tree []node

func (t tree) getRoot() int {
	for i, v := range t {
		if v.parent == NULL {
			return i
		}
	}
	return NULL
}

func (t tree) setDepthAll() {
	root := t.getRoot()
	t.setDepthUnder(root, 0)
}

func (t tree) setDepthUnder(id, depth int) {
	t[id].depth = depth
	if t[id].left != NULL {
		t.setDepthUnder(t[id].left, depth+1)
	}
	if t[id].right != NULL {
		t.setDepthUnder(t[id].right, depth+1)
	}
}

func (t tree) setHeightALL() {
	root := t.getRoot()
	t.setHeightUnder(root)
}

func (t tree) setHeightUnder(id int) int {
	// height: 子ノードのHeightが大きいほう+1
	lh, rh := 0, 0
	if t[id].left != NULL {
		lh = t.setHeightUnder(t[id].left) + 1
	}
	if t[id].right != NULL {
		rh = t.setHeightUnder(t[id].right) + 1
	}

	if lh > rh {
		t[id].height = lh
	} else {
		t[id].height = rh
	}
	return t[id].height
}

func (t tree) getType(id int) string {
	if t[id].parent == NULL {
		return "root"
	}
	if t[id].left == NULL && t[id].right == NULL {
		return "leaf"
	}
	return "internal node"
}

// Preorder tree walk.
// root -> left subtree -> right subtree
func (t tree) preParse(id int) {
	fmt.Printf(" %d", id)
	if t[id].left != NULL {
		t.preParse(t[id].left)
	}
	if t[id].right != NULL {
		t.preParse(t[id].right)
	}
}

// Inorder tree walk.
// left subtree -> root -> right subtree
func (t tree) inParse(id int) {
	if t[id].left != NULL {
		t.inParse(t[id].left)
	}
	fmt.Printf(" %d", id)
	if t[id].right != NULL {
		t.inParse(t[id].right)
	}
}

// Postorder tree walk.
// left subtree  -> right subtree -> root
func (t tree) postParse(id int) {
	if t[id].left != NULL {
		t.postParse(t[id].left)
	}
	if t[id].right != NULL {
		t.postParse(t[id].right)
	}
	fmt.Printf(" %d", id)
}

func main() {
	var n int
	fmt.Scanf("%d", &n)

	T := make(tree, n)
	for i := 0; i < n; i++ {
		T[i] = node{NULL, NULL, NULL, 0, NULL, NULL, 0}
	}

	var id, left, right int

	// struct binary tree
	for i := 0; i < n; i++ {
		fmt.Scanf("%d %d %d", &id, &left, &right)

		if left != NULL {
			T[left].parent = id
		}
		if right != NULL {
			T[right].parent = id
		}

		if left == NULL && right == NULL {
			// 子を持たない場合
			T[id].degree = 0
		} else if left != NULL && right != NULL {
			// 2つ子を持つ場合 兄弟も設定する
			T[left].sibling = right
			T[right].sibling = left
			T[id].degree = 2
		} else {
			// 1つ子を持つ場合
			T[id].degree = 1
		}

		T[id].left = left
		T[id].right = right
	}

	fmt.Println("Preorder")
	T.preParse(T.getRoot())
	fmt.Printf("\n")

	fmt.Println("Inorder")
	T.inParse(T.getRoot())
	fmt.Printf("\n")

	fmt.Println("Postorder")
	T.postParse(T.getRoot())
	fmt.Printf("\n")
}



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

int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;

  while ((A > 0) && (C > 0))
  {
      C -= B;
      if (C > 0)
      {
          A -= D;
      }
      
  }
  

  if (A <= 0)
  {
      cout << "No" << endl;
  } else
  {
      cout << "Yes" << endl;
  }
  return 0;
  
}


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

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

const ll INF = 1LL << 60;

vector<ll> dp(100010, 0);

int main() {
    int N, M;
    cin >> N >> M;
    vector<int> A(100010);
    for (int i = 0; i < M; i++) {
        scanf("%d", &A[i]);
    }
    dp[0] = 1;
    
    int j = 0;
    for (int i = 1; i <= N; i++) {
        if (i == A[j]) {
            dp[i] = 0;
            j++;
            continue;
        }
        dp[i] += dp[i - 1];
        if (i > 1) dp[i] += dp[i - 2];
        dp[i] %= mod;
    }

    cout << dp[N] % mod << endl;

    return 0;
}

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

ll modpow(ll a, ll n, ll mod) {
	ll r = 1;
	while(n > 0) {
		if(n & 1)
			r = r*a%mod;
		a = a*a%mod;
		n >>= 1;
	}
	return r;
}

int main() {
	ll N,z=0,A=0,B=0;
	string X;
	cin >> N >> X;
	vector<ll> f(N+1);

	f.at(0) = 0;
	rep(i,N) {
		ll x=i+1,c=0;
		rep(j,18)
			if(x & 1<<j)
				++c;
		f.at(x) = f.at(x%c)+1;
	}

	rep(i,N)
		z += (X.at(i) == '1');
	rep(i,N)
		if(X.at(i) == '1') {
			if(z != 1)
				A += modpow(2,N-i-1,z-1);
			B += modpow(2,N-i-1,z+1);
		}

	rep(i,N) {
		if(X.at(i) == '1') {
			if(z == 1)
				cout << 0;
			else
				cout << f.at((A-modpow(2,N-i-1,z-1))%(z-1))+1;
		} else
			cout << f.at((B+modpow(2,N-i-1,z+1))%(z+1))+1;
		cout << endl;
	}
}

Measured memory_bytes: 5192
while 1:
    try:
        n = int(input())
    except:break
    ans = 0
    for i in range(0,10):
        for j in range(0,10):
            for k in range(0,10):
                for l in range(0,10):
                    if i + j + k + l == n:
                        ans += 1

    print(ans)


Measured memory_bytes: 5588
import java.util.Scanner;

public class Main{
	public static void main(String srgs[]) {
		Scanner sc = new Scanner(System.in);
		int k_leftA = 0;
		int k_leftB = 0;
		int k_leftC = 0;
		int k_leftD = 0;
		int k_rightA = 0;
		int k_rightB = 0;
		int k_rightC = 0;
		int k_rightD = 0;

		while (sc.hasNext()) {
			double left = sc.nextDouble();
			double right = sc.nextDouble();

			if (1.1 <= left) {
				k_leftA++;
			} else if (0.6 <= left) {
				k_leftB++;
			} else if (0.2 <= left) {
				k_leftC++;
			} else {
				k_leftD++;
			}
			if (1.1 <= right) {
				k_rightA++;
			} else if (0.6 <= right) {
				k_rightB++;
			} else if (0.2 <= right) {
				k_rightC++;
			} else {
				k_rightD++;
			}
		}

		System.out.println(k_leftA + " " + k_rightA);
		System.out.println(k_leftB + " " + k_rightB);
		System.out.println(k_leftC + " " + k_rightC);
		System.out.println(k_leftD + " " + k_rightD);
	}
}

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

using namespace std;

#define rep(i,n) for(int i=0;i<(n);i++)
#define repa(i,a,n) for(int i=(a);i<(n);i++)
#define rrep(i,n) for(int i=n;i>=0;i--)
#define rrepa(i,a,n) for(int i=n;i>=(a);i--)
#define all(a) (a).begin(),(a).end()
#define MOD 1000000007
#define cmax(a,b) a=max(a,b)
#define cmin(a,b) a=min(a,b)
#define vc vector

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<int,int> pi;

int main(){

    string s,t,u;
    int a,b;cin>>s>>t>>a>>b>>u;

    if(s==u)a--;
    else b--;
    cout<<a<<" "<<b<<"\n";

    return 0;

}

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

using namespace std;

#define FOR(i, j, k) for(int i = j; i <= k; i++)
#define PB push_back
#define MEM(n, val) memset((n), val, sizeof(n))
#define F first
#define S second
#define MP make_pair
#define LL long long
#define MOD 1000000007

int n;

LL dp[102][5][5][5][5];

LL func(int pos, int fir, int sec, int thir, int four)  {

    if(pos >= 3)    {
        ///agc
//        cout << fir << " " << sec << " " << thir << " " << four << "\n";
        if(((fir == 1) || (sec == 1)) && (thir == 3) && four == 2)    {
//            cout << "hi1\n";
            return 0;
        }
        if((fir == 1) && (sec == 3) && ((thir == 2) || (four == 2)))    {
//            cout << "hi2\n";
            return 0;
        }

//        if((sec == 1) && (thir == 3) && (four == 2))    {
//            return 0;
//        }

        if((sec == 3) && (thir == 1) && (four == 2))    {
//            cout << "hi3\n";
            return 0;
        }

        if((sec == 1) && (thir == 2) && (four == 3))    {
//            cout << "hi4\n";
            return 0;
        }
    }

    if(pos == n)    {
        return 1;
    }
    if(dp[pos][fir][sec][thir][four] != -1)    {
        return dp[pos][fir][sec][thir][four];
    }

    LL ans = 0;
    ///'a' boshiye
    ans += func(pos + 1, sec, thir, four, 1);
    ///'c' boshiye
    ans += func(pos + 1, sec, thir, four, 2);
    ///'g' boshiye
    ans += func(pos + 1, sec, thir, four, 3);
    ///'t' boshiye
    ans += func(pos + 1, sec, thir, four, 4);

    ans %= MOD;

    return dp[pos][fir][sec][thir][four] = ans;
}

int main()  {
//    freopen("in.txt", "r", stdin);
    cin >> n;
    MEM(dp, -1);
    cout << func(0, 0, 0, 0, 0) << "\n";

    return 0;
}
/**
*/


Measured memory_bytes: 768
N = int(input())
S = list(input())

W = S.count('.')
B = 0
ans = W
if W == 0:
    print (0)
else:
    for i in range(0,N):
#        print (i)
        if S[i] == '#':
            B += 1
        else:
            W -= 1
        ans = min(ans, B+W)
    print (ans)

Measured memory_bytes: 4840
#include<iostream>
#include<algorithm>
#include<queue>

using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
char maze[50][50];//迷路・マス

long long  INF=1000000000000000000;



int main(){
int H,W;
cin >>H >>W;
char m;
int white=0;
for(int i=0 ;i<H; i++){
    for(int k=0 ;k<W; k++){
        cin >> m;
        maze[i][k]=m;
        if(m=='.'){
            white++;
        }
    }
}





    long long  dist[50][50];
	rep(r, 50) rep(c, 50) dist[r][c] = INF;//全て巨大な値を入れておく
	
	dist[0][0] = 0;
	int dx[4] = { -1,0,0,1 };//左右
	int dy[4] = { 0,1,-1,0 };// 上下
	queue<int> q;
	q.push(0);
	q.push(0);

	while (q.size() != 0) {//queueが空になるまで=探索できるマスがなくなるまで
        //次に移動するx,y座標
		int x = q.front(); q.pop();
		int y = q.front(); q.pop();

		rep(i, 4) {//上下左右を探索
			int nx = x + dx[i];
			int ny = y + dy[i];
			if (0 <= nx && nx < W && 0 <= ny && ny < H && maze[ny][nx] != '#' && dist[ny][nx] == INF) {
				q.push(nx);
				q.push(ny);
				dist[ny][nx] = dist[y][x] + 1;
			}
		}
	}
    if(dist[H-1][W-1]==INF){
        cout << "-1"<<endl;
    return 0;
    }
	cout << white-(dist[H-1][W-1]+1) << endl;


 return 0;
}

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


int main() {
    ll n, x;
    cin >> n;
    for(int i = (int)(sqrt(n)); i > 0; i--) {
        if (n % i == 0) {
            x = i;
            break;
        }
    }

    ll y = n / x;
    cout << x + y - 2 << endl;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
constexpr int MOD=1000000007;
//constexpr int MOD=998244353;
#define INF (1<<30)
#define LINF (lint)(1LL<<56)
#define endl "\n"
#define rep(i,n) for(lint (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(lint (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcount(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
#define plint pair<lint,lint>
#define fi first
#define se second
typedef long long lint;
int dx[8]={1,1,0,-1,-1,-1,0,1};
int dy[8]={0,1,1,1,0,-1,-1,-1};
const int MAX_N=2e5+5;

int main(void){
    double A,B;
    double H,M;
    cin >> A >> B >> H >> M;
    double kaku1,kaku2;
    kaku1=H*30+M*0.5;
    kaku2=M*6;
    double kaku=abs(kaku1-kaku2);
    kaku=min(kaku,360-kaku);
    double div=180/M_PI;
    double ans=pow(A,2)+pow(B,2)-2*A*B*cos(kaku/div);
    ans=sqrt(ans);
    cout << ans << endl;
}

Measured memory_bytes: 4180
//%std
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
inline int read()
{
	int out=0,fh=1;
	char jp=getchar();
	while ((jp>'9'||jp<'0')&&jp!='-')
		jp=getchar();
	if (jp=='-')
		fh=-1,jp=getchar();
	while (jp>='0'&&jp<='9')
		out=out*10+jp-'0',jp=getchar();
	return out*fh;
}
const int P=1e9+7;
int add(int a,int b)
{
	return (a+b>=P)?(a+b-P):(a+b);
}
int mul(int a,int b)
{
	return 1LL * a * b % P;
}
const int MAXN=2e5+10;
int n,f[MAXN],lst[MAXN];
int main()
{
	n=read();
	f[0]=1;
	for(int i=1;i<=n;++i)
	{
		f[i]=f[i-1];
		int c=read();
		if(lst[c] && i-lst[c]>1)
			f[i]=add(f[i],f[lst[c]]);
		lst[c]=i;
	}
	cout<<f[n]<<endl;
	return 0;
}


Measured memory_bytes: 1792
import java.util.Scanner;

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();
        long[] x = new long[n];
        for (int i = 0; i < n; i++) {
            x[i] = sc.nextLong();
        }
        long pos = x[0];
        long ans = 0;
        for (int i = 1; i < n; i++) {
            long next = x[i];
            if ((next - pos) * a > b) {
                ans += b;
            } else {
                ans += (next - pos) * a;
            }
            pos = next;
        }
        System.out.println(ans);

        sc.close();
    }
}

Measured memory_bytes: 60716
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main() {
    string s;
    cin>>s;
    int ans=10000000;
    for(int i=0;i<s.size()-2;i++){
        int a=s[i]-'0';
        a = a * 10;
        a = a + s[i+1]-'0';
        a = a * 10;
        a = a + s[i+2]-'0';
        ans = min(ans,abs(a-753));
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main{
	public static void main(String[] $){
		Scanner s=new Scanner(System.in);
		int n=s.nextInt(),q=s.nextInt();
		char[]a=s.next().toCharArray();
		int[]b=new int[n];
		for(int i=1;i<n;++i)
			b[i]=b[i-1]+(a[i]=='C'&&a[i-1]=='A'?1:0);
		//System.err.println(Arrays.toString(b));
		for(int i=0;i<q;++i)
			System.out.println(-b[s.nextInt()-1]+b[s.nextInt()-1]);
	}
}


Measured memory_bytes: 68752
# 3 3 10
# 60 2 2 4
# 70 8 7 9
# 50 2 3 9

# 70 8 7 9
# 60 2 2 4
# 50 2 3 9

# 120

# 180 12 12 22 OK
# 130 10 9 13 NO
# 120 10 10 18 OK
# 110 4 5 13 NO
# 70 8 7 9 NO
# 60 2 2 4 NO
# 50 2 3 9 NO
# 0 0 0 0 NO

from itertools import combinations
from operator import itemgetter

def get_min_price(N, M, X, C_i, A_i):
    combs = []
    min_price = 0

    for i in range(N+1):
        for comb in combinations(list(range(N)), i):
            price = sum([C_i[j] for j in comb])
            combs.append((price, comb))
    # print('N:', N)
    # print('combs:', combs)

    for price, comb in sorted(combs, key=itemgetter(0)):
        scores = [0] * M
        # print('comb:', comb)
        for j in comb:
            for k in range(M):
                scores[k] += A_i[j][k]
            
            if all(list(map(lambda score: score >= X, scores))):
                return price

            # print('scores:', scores)

    return -1


if __name__ == '__main__':
    N, M, X = map(int, input().split())
    C_i, A_i = [], []
    for i in range(N):
        temp = list(map(int, input().split()))
        # print(temp)
        C_i.append(temp[0])
        A_i.append(temp[1:])
    res = get_min_price(N, M, X, C_i, A_i)
    print(res)



Measured memory_bytes: 9880
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long
#define pii pair<int, int>
#define pll pair<long long, long long>
#define ull unsigned long long
#define mp make_pair
#define F first
#define S second
#define mod 1000000007

ll dp[405][405];

int main()
{
    int n;
    scanf("%d", &n);

    vector<int> v(n);
    for(int& x: v)
        scanf("%d", &x);

    ll p_sum[n+1];
    p_sum[0] = v[0];
    for(int i=1;i<n;i++)
        p_sum[i] = p_sum[i-1] + v[i];
    
    for(int l = n-1; l>=0; l--)
    {
        for(int r=l; r<n; r++)
        {
            if(r == l)
                dp[l][r] = 0;
            else
            {
                dp[l][r] = 1e18L;
                ll s = p_sum[r];
                if(l>0)
                    s -= p_sum[l-1];
                
                for(int i=l; i<r;i++)
                {
                    dp[l][r] = min(dp[l][r], dp[l][i] + dp[i+1][r] + s);
                }
            }
        }
    }

    printf("%lld\n", dp[0][n-1] );

}


Measured memory_bytes: 1536
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <complex>
#include <algorithm>
#include <numeric>
#include <utility>
#include <tuple>
#include <bitset>
#include <cstdint>
#include <cassert>
#include <random>
#include <iterator>

using namespace std;
using i64 = int64_t;
using i32 = int32_t;


int main() {
    i64 k;
    cin >> k;
    if (k <= 9) {
        cout << k << endl;
        return 0;
    }
    i64 ans = 0;
    vector<vector<i64>> ll(10);
    for (i64 i = 0; i <= 9; ++i) ll[i].push_back(i);
    for (i64 i = 9, j = 1, m = 10; i <= k; ) {
        vector<vector<i64>> rr(10);
        for (i64 t = 0; t <= 9; ++t) {
            for (i64 u = max(i64(0), t - 1); u <= min(t + 1, i64(9)); ++u) {
                for (i64 x : ll[u]) {
                    ans = m * t + x;
                    rr[t].push_back(ans);
                    if (t >= 1) {
                        ++i;
                        // cerr << i << ':' << ans << '\n';
                        if (i == k) {
                            cout << ans << endl;
                            return 0;
                        }
                    }
                }
            }
        }
        m *= 10;
        ll = rr;
    }
    return 0;
}

Measured memory_bytes: 1152
using System;
using System.Linq;

namespace ITP1_7_A
{
    class Program
    {
        static void Main(string[] args)
        {
            while (true)
            {
                string[] input = Console.ReadLine().Split(' ');
                if (input.All(s => s == "-1"))
                    break;

                int m = int.Parse(input[0]);
                int f = int.Parse(input[1]);
                int r = int.Parse(input[2]);
                Console.WriteLine(CheckRank(m, f, r));
            }
        }

        static string CheckRank(int m, int f, int r)
        {
            int score = m + f;
            if (m == -1 || f == -1)
                return "F";
            if (score >= 80)
                return "A";
            if (score >= 65)
                return "B";
            if (score >= 50)
                return "C";
            if (score >= 30)
                return r >= 50 ? "C" : "D";
            return "F";
        }
    }
}

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

using namespace std;
typedef long long ll;
typedef pair<int, int> pair2;
typedef pair<int, pair<int, int> > pair3;
typedef pair<int, pair<int, pair<int, int> > > pair4;
#define MAXN 200013
#define INF 1000000000000000000LL
#define MOD 1000000007LL
#define IINF 1000000000
#define mp make_pair
#define pb push_back
#define remove pop
#define all(x) x.begin(), x.end()

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef pair<int, int> pair2;
typedef pair<int, pair<int, int> > pair3;
typedef pair<int, pair<int, pair<int, int> > > pair4;
#define MAXN 200013
#define INF 1000000000000000000LL
#define MOD 1000000007LL
#define IINF 1000000000
#define mp make_pair
#define pb push_back
#define remove pop
#define all(x) x.begin(), x.end()

//Task: Find a cycle.


int n, m;

vector<int> adj[MAXN];

int seen[MAXN];
int par[MAXN];
int dist[MAXN];

int color[MAXN];

set<int> curSeen;
vector<int> curStack;
vector<int> answer;
bool cycle;

int bfs(int c) {

	queue<int> q;

	q.push(c);
	seen[c] = 1;

	//cout << "WHOLE" << c << endl;

	while (q.size() > 0) {
		int cur = q.front(); q.pop();
		//cout << "checking " << cur << endl;
		for (int next : adj[cur]) {
			if (seen[next]) {
				if (abs(seen[next] - seen[cur]) > 1) return 0;
				if (seen[next] == seen[cur]) return 0;
				continue;
			} 
			//cout << "assign next " << seen[cur] + 1 << endl;
			seen[next] = seen[cur] + 1;
			q.push(next);
		}
	}

	int ans = 0;
	for (int i = 0; i < n; i++) {
		if (seen[i] == 0) return 0;

		ans = max(ans, seen[i]);
	}
	return ans;
}

int main() {
	if (fopen("FILENAME.in", "r")) {
		freopen("FILENAME.in", "r", stdin);
		freopen("FILENAME.out", "w", stdout);
	}
	ios_base::sync_with_stdio(false); 
	cin.tie(NULL);

	cin >> n;

	for (int i = 0; i < n; i++) {
		string s;
		cin >> s;

		for (int j = 0; j < n; j++) {
			if (s[j] == '1') {
				adj[i].pb(j);
			}
		}
	}

	int bestAns = 0;

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			seen[j] = 0;par[j] = -1;dist[j] = 0;
		}
		//cout << "doing dfs from " << i << endl;
		int result = bfs(i);
		bestAns = max(bestAns, result);
	}


	cout << (bestAns == 0 ? -1 : bestAns ) << endl;
}

Measured memory_bytes: 6272
// In the name of God

#include <bits/stdc++.h>
using namespace std;
int main() {
	ios_base::sync_with_stdio(0), cin.tie(0);
	int m, d;	
	cin >> m >> d;
	int ans = 0;
	for(int i=1;i<=m;i++) {
		for(int j=2;j<=9;j++) {
			for(int k=2;k<=9;k++) {
				if(10*j+k>d) continue;
				if(j*k==i) ans++;
			}
		}
	}
	cout << ans;
	return 0;
}


Measured memory_bytes: 256
N = int(input())
a = []
b = []
for _ in range(N):
    ai,bi = list(map(int,input().split()))
    a.append(ai)
    b.append(bi)
ans = 0
for i in range(N-1,-1,-1):
    a[i] += ans
    t = (b[i] - a[i] ) % b[i]
    ans += t
print(ans)

Measured memory_bytes: 21660
using System;

namespace UOA_PCKWU
{
    internal class Program
    {
        public static void Main(string[] args)
        {
            var sum = 0;
            while (true)
            {
                var n = int.Parse(Console.ReadLine());
                if (n == 0) break;
                
                for (var i = 0; i < n / 4; i++)
                {
                    sum += int.Parse(Console.ReadLine());
                }

                Console.WriteLine(sum);
                sum = 0;
            }

        }
    }
}


Measured memory_bytes: 13816
import math

k = int(input())

gcd_list = [[0 for j in range(k)] for i in range(k)]
for i in range(k):
    for j in range(k):
        gcd_list[i][j] = math.gcd(i+1,j+1)

app_list =[0 for i in range(k)]
summation = 0

for i in range(k):
    for j in range(k):
        app_list[gcd_list[i][j]-1] += 1

for i in range(k):
    for j in range(k):
        summation += app_list[j] * gcd_list[i][j]
    
print(summation)

Measured memory_bytes: 9492
#include <bits/stdc++.h>
#define pb push_back
#define cmin(a,b) (a>b?a=b:a)
#define cmax(a,b) (a<b?a=b:a)
#define mem(a,k) memset(a,k,sizeof(a))
#define lop(i,s,t) for(int i=s;i<(t);++i)
#define rep(i,s,t) for(int i=s;i<=(t);++i)
#define dec(i,s,t) for(int i=s;i>=(t);--i)
#define fore(i,v) for(int i=g[v],d=es[i].d;i;i=es[i].nxt,d=es[i].d)
using namespace std;

#define Pr(f,...) fprintf(stderr,f,##__VA_ARGS__),fflush(stderr)

typedef long long ll;

template<typename T>
void read(T &x){
	x=0; 
	char c;
	for(c=getchar();!isdigit(c);c=getchar()); 
	for(;isdigit(c);c=getchar())x=x*10+c-'0'; 
}

const int N=805;

int n,m,k,ans,qx[N*N],qy[N*N],h,t,dis[N][N]; 
char a[N][N]; 

bool chk(int x,int y){
	return a[x][y]!='#'&&1<=x&&x<=n&&1<=y&&y<=m&&dis[x][y]<0;
}

void push(int x,int y,int d){
	qx[t]=x,qy[t]=y;
	dis[x][y]=d,++t;
}

void bfs(int sx,int sy){
	h=0,t=0; 
	mem(dis,-1); 
	push(sx,sy,0); 
	while(h!=t){
		int x=qx[h],y=qy[h],d=dis[x][y]; ++h;
		if(d<=k)cmin(ans,min(min(x-1,n-x),min(y-1,m-y))); 
		if(chk(x-1,y))push(x-1,y,d+1); 
		if(chk(x+1,y))push(x+1,y,d+1); 
		if(chk(x,y+1))push(x,y+1,d+1); 
		if(chk(x,y-1))push(x,y-1,d+1); 
	}
}

int main(int argc,char *argv[]){
#ifdef CURIOUSCAT
#endif
	scanf("%d%d%d",&n,&m,&k); 
	ans=n*m;
	rep(i,1,n)scanf("%s",a[i]+1); 
	rep(i,1,n)rep(j,1,m){
		if(a[i][j]=='S'){
			bfs(i,j);
		}
	}
	printf("%d\n",(ans+k-1)/k+1); 
	return 0;
}


Measured memory_bytes: 8448
#include<bits/stdc++.h>
using namespace std;
int a[100010];
int main()
{
	int n,maxx=0,minn=1e9,t=0,sum=0;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",a+i),maxx=max(maxx,a[i]),minn=min(minn,a[i]);
	if(maxx-minn>1)
	{
		puts("No");
		return 0;
	}
	if(maxx==minn&&minn==n-1)
	{
		puts("Yes");
		return 0;
	}
	for(int i=1;i<=n;i++)
		if(a[i]==maxx)t++;
		else sum++;
	if(sum>=maxx)
	{
		puts("No");
		return 0;
	}
	sum=maxx-sum;
	if(sum*2<=t)puts("Yes");
	else puts("No");
	return 0;
}

Measured memory_bytes: 640
#include<stdio.h>
int main()
{
    int n,x,y;
    for(n=0;n<2999;n++){
        scanf("%d %d",&x,&y);
        if(x < y){
            printf("%d %d\n",x,y);
        }
        else if(x == 0 && y == 0)
            break;
        else{
            printf("%d %d\n",y,x);
        }

    }
    return 0;
}

Measured memory_bytes: 600
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define int long long
#define mkp make_pair
#define pb push_back
#define ff first
#define ss second
#define debug1(a) cout<<a<<endl;
#define debug2(a,b) cout<<a<<' '<<b<<endl;
#define debug3(a,b,c) cout<<a<' '<<b<<' '<<c<<endl;
#define rep(i,n) for(int i=0;i<n;i++)
#define repre(i,a,b)for(int i=a;i<=b;i++)
#define clr1(arr) memset(arr,-1,sizeof(arr));
#define clr0(arr) memset(arr,0,sizeof(arr));
#define pi pair<int,int>
#define pii pair<int,pi>
#define aint(v) v.begin(),v.end()
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace __gnu_pbds;
using namespace std;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> orderedSet;
typedef tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update> orderedMSet;
struct custom_hash {
static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
#define ump gp_hash_table<int,int,custom_hash>
//*p.find_by_order(index) return value at index
//p.order_of_key(key) return index
/*int **dp,in main function,int row,col;dp=new int*[n];rep(i,n)dp[i]=new int[m]*/
//**** Maths Section*******/
int power(int x,int y);
bool isPrime(int n);
int modInv(int a,int b);
int gcdExtended(int a,int b,int *x,int* y);
int mpower(int a,int b,int p);
/***************************/
int32_t main()
{
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
  fastio
  int n,a,b;
  cin>>n>>a>>b;
  if(b==0)
  {
    cout<<n<<endl;
    exit(0);
  }
  else if(a==0)
  {
    cout<<0<<endl;
    exit(0);
  }
  int temp=n/(a+b);
  int ans=temp*a;
  int left=n-temp*(a+b);
  if(left>a)ans+=a;
  else ans+=left;
  cout<<ans<<endl;
  return 0;
}

int modInv(int a, int m)
{
int x, y;
int g = gcdExtended(a, m, &x, &y);
int res = (x%m + m) % m;
return res;
}

int gcdExtended(int a, int b, int *x, int *y)
{
if (a == 0){
    *x = 0, *y = 1;
    return b;
  }
  int x1, y1;
  int gcd = gcdExtended(b%a, a, &x1, &y1);
  *x = y1 - (b/a) * x1;
  *y = x1;
  return gcd;
}

int mpower(int x, int y, int p)
{
int res = 1;
x = x % p;
while(y > 0){
    if(y & 1) res = (res*x) % p;
      y = y>>1;
      x = (x*x) % p;
    }
    return res;
}
int power(int x, int y)
{
int res = 1;
while (y > 0){
    if (y & 1) res = res*x;
      y = y>>1;
      x = x*x;
    }
    return res;
}

bool isPrime(int n)
{
if (n <= 1)  return false;
  if (n <= 3)  return true;
    if (n%2 == 0 || n%3 == 0) return false;
      int p=sqrt(n);
      for(int i=5;i<=p;i=i+6)
        if (n%i == 0 || n%(i+2) == 0)
          return false;
      return true;
}


Measured memory_bytes: 256
#ifdef DEBUG

#else

#    pragma GCC optimize("O3,no-stack-protector")
#    pragma GCC optimize("unroll-loops")

#    if __cplusplus >= 201703L
#        pragma GCC target("avx2")
#    else
#        pragma GCC target("avx")
#    endif

#endif
// 実数の場合
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define dump(x) cout << x << endl
typedef int64_t Int;
typedef long double Ld;

using namespace std;
using Graph = vector<vector<Int>>;

const double pi = M_PI;
const Int MOD = 1000000007;

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

    int a, b, c, d;
    cin >> a >> b >> c >> d;

    cout << max(0, min(b, d) - max(a, c)) << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INT long long int
using namespace std;
int n, a[60], pv, mv;
vector<int> p, m;
int main()
{
    cin>>n;
    for(int i =1 ; i <= n ; i++ ) cin>>a[i];
    for(int i = 1 ; i <= n ; i++ )
        if( a[i] >= 0 )
        {
            p.push_back(i);
            pv += a[i];
        }
        else
        {
            m.push_back(i);
            mv += a[i];
        }
    if( pv+mv >= 0 )
    {
        cout<<p.size()+m.size()+n-2<<endl;
        for(int i = 1 ; i < p.size() ; i++ )
            cout<<p[i-1]<<" "<<p[i]<<endl;
        for(int i = 0 ; i <m.size() ; i++ )
            cout<<p[p.size()-1]<<" "<<m[i]<<endl;
        for(int i = 2 ; i <= n ; i++ )
            cout<<i-1<<" "<<i<<endl;
    }
    else
    {

        cout<<p.size()+m.size()+n-2<<endl;
        for(int i = 1 ; i < m.size() ; i++ )
            cout<<m[i-1]<<" "<<m[i]<<endl;
        for(int i = 0 ; i < p.size() ; i++ )
            cout<<m[m.size()-1]<<" "<<p[i]<<endl;
        for(int i = n-1 ; i > 0 ; i-- )
            cout<<i+1<<" "<<i<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize("O3", "unroll-loops")
#pragma GCC target("avx")
using namespace std;
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }

constexpr int b = 80 * 80 + 3;
constexpr int M = b * 2 + 3;

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

    int H, W;
    cin >> H >> W;
    vector<vector<int>> A(H, vector<int>(W));
    vector<vector<int>> B(H, vector<int>(W));
    cin >> A >> B;

    vector<bitset<M>> dp(W + 1);
    dp[1][b] = 1;
    for (int i = 0; i < H; i++)
    {
        for (int j = 0; j < W; j++)
        {
            int d = abs(A[i][j] - B[i][j]);
            dp[j + 1] |= dp[j];
            dp[j + 1] = (dp[j + 1] << d) | (dp[j + 1] >> d);
        }
    }
    printf("%d", dp.back()._Find_next(b - 1) - b);
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define INF 1e12

#define PB push_back
#define PF push_front
#define fi first
#define se second
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vpi vector<pii>
#define vll vector<ll>
#define vpl vector<pll>
#define vvi vector<vector<int>>
#define vvl vector<vector<ll>>
#define ios ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define ud(c, x) distance(c.begin(), upper_bound(all(c), x))
#define ud(c, x) distance(c.begin(), lower_bound(all(c), x))
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rep2(i, a, b) for (int i = a, i < b; ++i)
#define rep3(i, n) for (int i = n - 1; i >= 0; ++i)
bool odd(int i) { return i % 2; }

#define all(v) v.begin(), v.end()
#define size(x) int(x.size())

int gcd(int a, int b) { return __gcd(a, b); }
int lcm(int a, int b) { return a * (b / gcd(a, b)); }
//赤，白の順番にする
void solve(void) {
  int n;
  string s;
  cin >> n >> s;
  int cta = 0;
  rep(i, n) if (s[i] == 'R') cta++;
  int cta_w = 0, cta_r = 0;
  rep(i, cta) if (s[i] == 'W') cta_w++;
  for (int i = cta; i < n; ++i)
    if (s[i] == 'R') cta_r++;
  //   cout << cta << " " << cta_w << " " << cta_r << endl;
  cout << min(cta_r, cta_w) + abs(cta_r - cta_w) << endl;
}
int main(void) { solve(); }


Measured memory_bytes: 3764
#include<stdio.h>

long long dp[102][10][1001] = {{{1}}};

int main(void){
    int n,s,i,j,k;
    for(i=0;i<=100;i++){
        for(j=0;j<=9;j++){
            for(k=0;k<=1000;k++){
                if(k+i<=1000&&j+1<10)dp[i+1][j+1][k+i]+=dp[i][j][k];
                dp[i+1][j][k]+=dp[i][j][k];
            }
        }
    }
    while(1){
        scanf("%d %d",&n,&s);
        if(n==0&&s==0)break;
        printf("%lld\n",dp[101][n][s]);

    }
    return 0;
}

Measured memory_bytes: 8576
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
lli mod=1000000007;

int main()
{
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    lli a,b,c,d;
    cin>>a>>b>>c>>d;
    while(a>0&&c>0){
    	c-=b;
    	if(c<=0)
    		break;
    	a-=d;
    }
    if(a>0)
    	cout<<"Yes"<<endl;
    else
    	cout<<"No"<<endl;
}

Measured memory_bytes: 3652
local s = io.read()
local k = io.read("*n")
local t = {}
local left = 1
for i = 2, #s do
  if s:byte(i) ~= s:byte(left) then
    table.insert(t, i - left)
    left = i
  end
end
table.insert(t, #s + 1 - left)
if #t == 1 then
  local tot = k * #s
  print(tot // 2)
elseif s:byte(1, 1) == s:byte(#s, #s) then
  local first = t[1]
  local last = t[#t]
  local ret = 0
  for i = 2, #t - 1 do
    ret = ret + t[i] // 2
  end
  ret = ret * k + first // 2 + last // 2
  ret = ret + ((first + last) // 2) * (k - 1)
  print(ret)
else
  local ret = 0
  for i = 1, #t do
    ret = ret + t[i] // 2
  end
  print(ret * k)
end


Measured memory_bytes: 2760
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <math.h>
#include <utility>
#include <algorithm>
#include <functional>
#include <vector>
#include <numeric>
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using vi = vector <int>;

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

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

    int n; cin >> n;
    int fact[n];
    fact[0] = 1;
    FOR(i, 1, n) {
        fact[i] = fact[i-1]*i;
    }
    int p = 0;
    int q = 0;
    int b = (1 << n) - 1;
    REP(i, n) {
        int tmp; cin >> tmp;
        b ^= (1 << (tmp-1));
        int bit = 0;
        REP(j, tmp-1) {
            bit |= (1 << j);
        }
        p += __builtin_popcount(b & bit) * fact[n-1-i];
    }
    b = (1 << n) - 1;
    REP(i, n) {
        int tmp; cin >> tmp;
        b ^= (1 << (tmp-1));
        int bit = 0;
        REP(j, tmp-1) {
            bit |= (1 << j);
        }
        q += __builtin_popcount(b & bit) * fact[n-1-i];
    }
    int ret = (p < q) ? q-p : p-q;

    cout << ret << "\n";
}


Measured memory_bytes: 3516
#include<bits/stdc++.h>
using namespace std;
vector<int> ga[200100];
int n,m;
int a,b;
queue<pair<int,int> > q;
int vis[200100];
int main(){
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>n>>m;
	for(int i=1;i<=m;i++){
		cin>>a>>b;
		ga[a].push_back(b);
	}
	q.push(make_pair(1,0));
	while(!q.empty()){
		int u=q.front().first;
		int stp=q.front().second;
		if(stp>1){
			break;
		}
		q.pop();
		for(int i=0;i<ga[u].size();i++){
			vis[ga[u][i]]=stp+1;
			q.push(make_pair(ga[u][i],stp+1));
		}
	}
	if(vis[n]==2){
		cout<<"POSSIBLE"<<endl;
		return 0;
	}
	else{
		cout<<"IMPOSSIBLE"<<endl;
		return 0;
	}
	return 0;
}


Measured memory_bytes: 10104
#include <bits/stdc++.h>
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,s,e) for (int i=s;i<(e);i++)
#define All(v) (v).begin(),(v).end()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
using namespace std;
typedef long long llint;
typedef pair<int, int> P;
const int MOD = (int)1e9 + 7;
const int INF = 999999999;

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

    string s;
    cin >> s;
    REP(i, 26){
        bool f = true;
        REP(j, s.size()){
            if(((s[j]-'a')%26) == i){
                f = false;
                break;
            }
        }
        if(f){
            cout << (char)(i+'a') << "\n";
            return 0;
        }
    }
    cout << "None" << "\n";
    return 0;
}

Measured memory_bytes: 512
A, B, C, D = map(int, input().split())
ctr = 0

while True:
    if C <= 0:
        print("Yes")
        break
    if A <= 0:
        print("No")
        break
    if ctr % 2 == 0:
        C -= B
    else:
        A -= D
    ctr += 1


Measured memory_bytes: 61932
H,W = map(int, input().split())


h = 0
w = 0
w1 = w2 = 0

if H == 1 or W ==1:
    print(1)


elif W % 2 == 1:#横が奇数
    w = int(W /2) + 1
    if H % 2 == 1:#縦が奇数
        h = int(H / 2) + 1
        w1 = h * w
        w2 = (w-1) * (h-1)
        print(w1 + w2)
    else:#縦が偶数
        h = int(H / 2)
        w1 = w * h
        w2 = (w-1) * h
        print(w1 + w2)
        
        
else:#横が偶数
    w = int(W / 2)
    print(w * H)



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

int main(){
    ll n,a,b;
    cin>>n>>a>>b;
    ll x,nowx,ans=0;
    cin>>nowx;
    rep(i,n-1){
        cin>>x;
        if((x-nowx)*a<b) ans+=(x-nowx)*a;
        else ans+=b; 
        nowx=x;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
A  =   list(map(int, input().split()))
BC = [tuple(map(int, input().split())) for _ in range(M)]

A.sort()
BC.sort(key=lambda x: x[1], reverse=True)
s = sum(A)

rewriting = (c for b, c in BC for _ in range(b))

for a, c in zip(A, rewriting):
    if c <= a:
        break
    s += c - a  # rewrite A[i]

print(s)


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

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

  int dp[n + 1][n + 1];
  rep(i, n + 1) dp[i][n] = 0;
  rep(j, n + 1) dp[n][j] = 0;

  rep(i, n) rep(j, n) {
    int ii = n - i - 1;
    int jj = n - j - 1;
    if(s[ii] == s[jj])
      dp[ii][jj] = dp[ii + 1][jj + 1] + 1;
    else
      dp[ii][jj] = 0;
  }
  int ans = 0;
  rep(i, n) rep(j, i) {
    int now = min(i - j, dp[i][j]);
    ans = max(ans, now);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 97920
n, m, x = gets.split.map(&:to_i)
books = n.times.map {gets.split.map(&:to_i)}

min = 1200001

(1..n).each do |i|
  [*0...n].combination(i) do |selected|
    cost = 0
    f = books.values_at(*selected).map {|price, *up|
      cost += price
      up
    }.transpose.map(&:sum).all? {|e| e >= x}
    if f
      min = cost if cost < min
    end
  end
end

puts (min == 1200001) ? -1 : min

Measured memory_bytes: 14692
import sys
def input():
	return sys.stdin.buffer.readline()[:-1]

class BIT():#1-indexed
	def __init__(self, size):
		self.table = [0 for _ in range(size+2)]
		self.size = size

	def Sum(self, i):#1からiまでの和
		s = 0
		while i > 0:
			s += self.table[i]
			i -= (i & -i)
		return s

	def PointAdd(self, i, x):#
		while i <= self.size:
			self.table[i] += x
			i += (i & -i)
		return

n, Q = map(int, input().split())
c = list(map(int, input().split()))
q = []
for i in range(Q):
	l, r = map(int, input().split())
	q.append((i, l, r))
q.sort(key=lambda x: x[2])
ans = [-1 for _ in range(Q)]
b = BIT(n+1)
last_appeared = [0 for _ in range(n+1)]
rm = 0
for i, l, r in q:
	for j in range(rm+1, r+1):
		if last_appeared[c[j-1]] > 0:
			b.PointAdd(last_appeared[c[j-1]], -1)
		last_appeared[c[j-1]] = j
		b.PointAdd(j, 1)
	rm = j
	ans[i] = b.Sum(r) - b.Sum(l-1)
print(*ans, sep="\n")

Measured memory_bytes: 199292
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

unsigned long diff(vector<unsigned long> a) {
	return *max_element(a.begin(), a.end()) - *min_element(a.begin(), a.end());
}

int main() {
	unsigned long H, W;
	vector<vector<unsigned long>> div(6, vector<unsigned long>(3));
	cin >> H >> W;
	if (H % 3 == 0 or W % 3 == 0) {
		cout << 0 << endl;
		return 0;
	}
	div[0][0] = W / 3 * H;
	div[0][1] = (W - W / 3) * (H / 2);
	div[0][2] = (W - W / 3) * (H / 2);
	if (H % 2 != 0) div[0][2] += W - W / 3;
	
	div[1][0] = (W / 3 + 1) * H;
	div[1][1] = (W - W / 3 - 1) * (H / 2);
	div[1][2] = (W - W / 3 - 1) * (H / 2);
	if (H % 2 != 0) div[1][2] += W - W / 3 - 1;


	div[2][0] = H / 3 * W;
	div[2][1] = (H - H / 3) * (W / 2);
	div[2][2] = (H - H / 3) * (W / 2);
	if (W % 2 != 0) div[2][2] += H - H / 3;
	
	div[3][0] = (H / 3 + 1) * W;
	div[3][1] = (H - H / 3 - 1) * (W / 2);
	div[3][2] = (H - H / 3 - 1) * (W / 2);
	if (W % 2 != 0) div[3][2] += H - H / 3 - 1;


	div[4][0] = (W / 3) * H;
	div[4][1] = (W / 3) * H;
	if (W % 3 == 2) div[4][1] += H;
	div[4][2] = (W / 3 + 1) * H;

	div[5][0] = (H / 3) * W;
	div[5][1] = (H / 3) * W;
	if (H % 3 == 2) div[5][1] += W;
	div[5][2] = (H / 3 + 1) * W;

	cout << min({diff(div[0]), diff(div[1]), diff(div[2]), diff(div[3]), diff(div[4]), diff(div[5])}) << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		for (int i = 1; i <= 9; i++){
			for (int j = 1; j <= 9; j++){
				System.out.println(i + "x" + j + "=" + (i * j));
			}
		}
	}
}

Measured memory_bytes: 16852
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef vector<vector<long long> > vvll;
typedef vector<pair<int, int> > vpii;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<ll, ll> pll;
#define INF 1000000000
#define MOD 1000000007
#define EPSILON 0.00001
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define p_q priority_queue
 
#define FOR(i, a, b) for (int i=(a); i<=(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define RFOR(i, a, b) for (int i=(a); i >= b; i--)
 
#define MN 200005
int n, q;
string s;
pair<char, char> td[MN];

bool chlf(int loc){
    int cl = loc;
    F0R(i, q){
        if(s[cl] == td[i].f){
            if(td[i].s == 'L') cl--;
            else cl++;
        }
        if(cl == -1) return true;
        if(cl == n) return false;
    }
    return false;
}
bool chrt(int loc){
    int cl = loc;
    F0R(i, q){
        if(s[cl] == td[i].f){
            if(td[i].s == 'L') cl--;
            else cl++;
        }
        if(cl == -1) return false;
        if(cl == n) return true;
    }
    return false;
}

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

    cin >> n >> q;
    cin >> s;
    F0R(i, q){
        cin >> td[i].f >> td[i].s;
    }

    int l = -1, r = n;
    while(l+1 < r){
        int mid = (l+r)/2;
        if(chlf(mid)) l = mid;
        else r = mid;
    }

    int l2 = -1, r2 = n;
    while(l2+1 < r2){
        int mid = (l2+r2)/2;
        if(chrt(mid)) r2 = mid;
        else l2 = mid;
    }

    int lst = l+1, rst = r2-1;
    //cout << l << " " << r2 << "\n";
    cout << max(rst-lst+1, 0) << "\n";

    return 0;
}


Measured memory_bytes: 976