akhauriyash/Code-Regression huggingface dataset:
use std::error::Error;
use std::io;

pub fn main() {
    if let Err(_e) = run() {
        panic!("failed.");
    }
}

fn run() -> Result<(), Box< Error>> {
    let mut input = String::new();
    io::stdin().read_line(&mut input);
    let n = input.trim().parse::<usize>().unwrap();
    input.clear();
    io::stdin().read_line(&mut input);
    let s = input.trim().to_owned();
    input.clear();

    //solve
    let mut dp = vec![vec![0; n]; n];

    for i in 0..n as usize {
        dp[0][i] = 1;
    }

    let mut chars = s.chars();
    for i in 1..n as usize {
        let c = chars.next().unwrap();
        let mut bit = Bit {
                // from 1 to (n- i + 1) + 1 // 1 is due to i-1
                nodes: vec![0; n - i + 2],
            };
            for k in 0..n - i + 1 {
                bit.add(k + 1, dp[i - 1][k]);
            }
        for j in 0..n - i {
            
            if c == '>' {
                // dp[i][j] = dp[i-1][j+1] + .... dp[i-1][n-i];
                dp[i][j] = bit.sum_range(j + 1 + 1, n - i + 1);
            } else {
                // dp[i][j] = dp[i-1][0]...dp[i-1][j]
                dp[i][j] = bit.sum(j + 1);
            }
        }
    }
    println!("{}", dp[n - 1][0]);
    Ok(())
}

struct Bit {
    // from 1 to n(inclusive), 0 is not used
    nodes: Vec<i64>,
}

impl Bit {
    fn add(&mut self, index: usize, value: i64) {
        let mut index = index as i64;
        while index < self.nodes.len() as i64 {
            self.nodes[index as usize] += value;
            self.nodes[index as usize] %= 1_000_000_007;
            index += index & -index;
        }
    }

    fn sum_range(&self, from: usize, to: usize) -> i64 {
        if from == 0 {
            return self.sum(to);
        }
        let from = self.sum(from-1);
        let to = self.sum(to);
        return (to - from + 1_000_000_007) % 1_000_000_007;
    }

    fn sum(&self, index: usize) -> i64 {
        let mut index = index as i64;
        let mut result = 0;
        while index != 0 {
            result += self.nodes[index as usize];
            result %= 1_000_000_007;
            index -= index & -index;
        }
        result
    }
}


Measured memory_bytes: 90364
N, Y = map(int, input().split())

for x in reversed(range(N+1)):
    for y in reversed(range(N+1-x)):
        z = N - x - y
        if x*10000 + y*5000 + z*1000 == Y:
            print(x, y, z)
            break
    else:
        continue
    break
else:
    print(-1, -1, -1)


Measured memory_bytes: 3060
#include <stdio.h>

unsigned xor128() {
	static unsigned x = 123456789, y = 362436069, z = 521288629, w = 88675123;
	unsigned t = x ^ (x << 11);
	x = y; y = z; z = w;
	return w = w ^ (w >> 19) ^ (t ^ (t >> 8));
}

typedef struct node_t {
	int val;
	struct node_t *lch, *rch;
	int size;
	unsigned int pri;
} node;

node* new_node(int val) {
	static int it = 0;
	static node pool[200000];
	pool[it] = (node) { val, 0, 0, 1, xor128() };
	return &pool[it++];
}

int count(node *t) {
	return !t ? 0 : t->size;
}

node *update(node *t) {
	t->size = count(t->lch) + count(t->rch) + 1;
	return t;
}

node *merge(node *l, node *r) {
	if (!l || !r) return !l ? r : l;
	if (l->pri > r->pri) {
		l->rch = merge(l->rch, r);
		return update(l);
	}
	r->lch = merge(l, r->lch);
	return update(r);
}

typedef struct{ node *a, *b; } pnode;

pnode split(node *t, int k) {
	if (!t) return (pnode) { 0, 0 };
	if (k <= count(t->lch)) {
		pnode s = split(t->lch, k);
		t->lch = s.b;
		return (pnode) { s.a, update(t) };
	}
	pnode s = split(t->rch, k - count(t->lch) - 1);
	t->rch = s.a;
	return (pnode) { update(t), s.b };
}

node* find(node *t, int val) {
	while (t) {
		if (t->val == val) break;
		t = val < t->val ? t->lch : t->rch;
	}
	return t;
}

int count_lower(node *t, int v) {
	if (!t) return 0;
	if (t->val < v) return count(t->lch) + 1 + count_lower(t->rch, v);
	if (t->val == v) return count(t->lch);
	return count_lower(t->lch, v);
}

node *insert(node *t, int val) {
	int k = count_lower(t, val);
	pnode s = split(t, k);
	return merge(merge(s.a, new_node(val)), s.b);
}

int main(void)
{
	int q, com, x, cnt = 0;
	node *root = 0;
	scanf("%d", &q);
	while (q--) {
		scanf("%d%d", &com, &x);
		if (com == 0) {
			if (!find(root, x)) ++cnt, root = insert(root, x);
			printf("%d\n", cnt);
		}
		else {
			puts(find(root, x) ? "1" : "0");
		}
	}
	return 0;
}



Measured memory_bytes: 7924
N = int(input())

mod = 11
ans = 0

if N % mod == 0:
    ans = int(N / mod * 2)
elif N % mod >= 1 and N % mod <= 6:
    ans = N // mod * 2 + 1
else:
    ans = N // mod * 2 + 2

print(ans)

Measured memory_bytes: 3060
// include
// ----------------------------------------------------------------------------
#include<stdio.h>
#include<stdlib.h>
#include<ctype.h>
#include<math.h>
#include<string.h>
#include<stdbool.h>

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

// memory clear
// ----------------------------------------------------------------------------
#define CLRNUM(a) memset((a), 0, sizeof(a))
#define CLRBOOL(a, flag) memset((a), flag, sizeof(a))
#define CLRCHAR(a) memset((a), '\0', sizeof(a))

// debug
// ----------------------------------------------------------------------------
#define DEBUGINT(x) printf("%d\n", x);
#define DEBUGFLOAT(x) printf("%f\n", x);
#define DEBUGCHAR(x) printf("%c\n", x);
#define DEBUGSTR(x) printf("%s\n", x);
#define DEBUGFORINT(i, a, b, x) FOR(i, a, b){ printf("%d ", x[i]); }
#define DEBUGFORFLOAT(i, a, b,x ) FOR(i, a, b){ printf("%f ", x[i]); }
#define DEBUGFORCHAR(i, a, b, x) FOR(i, a, b){ printf("%c ", x[i]); }
#define DEBUGREPINT(i, n, x) REP(i, n){ printf("%d ", x[i]); }
#define DEBUGREPFLOAT(i, n, x) REP(i, n){ printf("%f ", x[i]); }
#define DEBUGREPCHAR(i, n, x) REP(i, n){ printf("%c ", x[i]); }

// other
// ----------------------------------------------------------------------------
#define PUTNL printf("\n")

// constant
// ----------------------------------------------------------------------------
#define INF 1000000000

int main(void)
{
    unsigned long long int n, ave, num;
    unsigned long long int i;

    scanf("%llu", &n);

    ave = 0;

    for (i = 0;i < n; ++i){
        scanf("%llu", &num);
        
        ave += num;
    }

    printf("%llu\n", ave / i);

    return 0;
}

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

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

    if(S[0]=='R' && S[1]=='R' && S[2]=='R'){
        cout << 3 << endl;
        return 0;
    }else if(S[0]=='R' && S[1]=='R'){
        cout << 2 << endl;
        return 0;
    }else if (S[1]=='R' && S[2]=='R'){
        cout << 2 << endl;
        return 0;
    }else if (S[0]=='R' || S[1]=='R' || S[2]=='R'){
        cout << 1 << endl;
        return 0;
    }   
    cout << 0 << endl;
    return 0;
}

Measured memory_bytes: 3632
#include<iostream>
#include<cstdio>
#include<cstring>
#define Rep(i,a,b) for (int i=a;i<=b;i++)
#define Mod (1000000007)
#define LL long long
#define CL(a) memset(a,0,sizeof(a))
using namespace std;
LL dp[2][610][610];
bool vis[610],Del[610];
int A[610],n;
void Upd(LL &x,LL a){ x=(x+a)%Mod; }
int main(){
	scanf("%d",&n);
	int num=0;
	Rep(i,1,2*n) scanf("%d",&A[i]);
	Rep(i,1,n){
		if (A[2*i-1]!=-1&&A[2*i]!=-1){
			Del[A[2*i-1]]=Del[A[2*i]]=1;
			continue;
		}
		if (A[2*i]==-1&&A[2*i-1]==-1){
			num++; continue;
		}
		if (A[2*i-1]!=-1) vis[A[2*i-1]]=1;
		if (A[2*i]!=-1) vis[A[2*i]]=1;
	}
	int Cur=0; dp[0][0][0]=1;
	for (int i=2*n;i>=1;i--){
		if (Del[i]) continue;
		Cur^=1; CL(dp[Cur]);
		if (vis[i]){
			Rep(j,0,2*n) Rep(k,1,2*n)
				Upd(dp[Cur][j][k],dp[Cur^1][j][k-1]);
			//不配对，等待更小的数匹配它 
			Rep(j,0,2*n-1) Rep(k,0,2*n)
				Upd(dp[Cur][j][k],dp[Cur^1][j+1][k]);
			//配对，由于和比它更大的不确定数匹配，所以min=i
			//所以对于B来说，只有一种方案 
		}
		else{
			Rep(j,1,2*n) Rep(k,0,2*n) 
				Upd(dp[Cur][j][k],dp[Cur^1][j-1][k]);
			//不配对，等待更小的数匹配它 
			Rep(j,0,2*n-1) Rep(k,0,2*n)	
				Upd(dp[Cur][j][k],dp[Cur^1][j+1][k]);
			//配对，和比i大的不确定数 
			Rep(j,0,2*n) Rep(k,0,2*n-1)
				Upd(dp[Cur][j][k],dp[Cur^1][j][k+1]*(LL)(k+1));
			//配对，和比i大的确定数 
		}
	}
	LL ans=dp[Cur][0][0];
	Rep(i,2,num) ans=(ans*(LL)i)%Mod;
	cout<<ans;
}

Measured memory_bytes: 6016
#include <bits/stdc++.h>
#define gc getchar_unlocked()
#define pc(x) putchar_unlocked(x)
template<typename T> void scan(T &x){x = 0;bool _=0;T c=gc;_=c==45;c=_?gc:c;while(c<48||c>57)c=gc;for(;c<48||c>57;c=gc);for(;c>47&&c<58;c=gc)x=(x<<3)+(x<<1)+(c&15);x=_?-x:x;}
template<typename T> void printn(T n){bool _=0;_=n<0;n=_?-n:n;char snum[65];int i=0;do{snum[i++]=n%10+48;n/= 10;}while(n);--i;if (_)pc(45);while(i>=0)pc(snum[i--]);}
template<typename First, typename ... Ints> void scan(First &arg, Ints&... rest){scan(arg);scan(rest...);}
template<typename T> void print(T n){printn(n);pc(10);}
template<typename First, typename ... Ints> void print(First arg, Ints... rest){printn(arg);pc(32);print(rest...);}

using namespace std;
using ll = long long;
const int MM = 1e5+5;

int n, k, s;

int main(){
    
    scan(n, k, s);
    
    if(s == 1e9){
        for(int i = 0; i < k; i++)
            printf("%d ", (int)1e9);
        for(int i = k; i < n; i++)
            printf("1 ");
        printf("\n");
        return 0;
    }
    
    for(int i = 0; i < k; i++){
        printf("%d ", s);
    }
    for(int i = k; i < n; i++)
        printf("%d ", (int)1e9);
    printf("\n");
    
    return 0;
}

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

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;++A)
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

/////////////////////////////////////////////////////

ll mk[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
ll K,i, j, k;
int main(){
    scanf("%lld", &K);
    printf("%lld", mk[K - 1]);
    return 0;
}

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

using namespace std;

typedef long long ll;

const int N = 105;

const int mod = 1e9+7;

int main() {
    int n , d;
    cin >> n >> d;
    int cnt = 0;
    for(int i = 1; i <= n; i++){
        int x , y;
        cin >> x >> y;
        if(hypot(x , y) <= d){
            cnt++;
        }
    }
    cout << cnt << "\n";
	return 0;
}


Measured memory_bytes: 3644
#include<iostream>
using std::cout;
using std::cin;
using std::endl;

int main()
{
  int a, b, c, d, e, k;
  cin >> a >> b >> c >> d >> e >> k;
  
  if (e - a > k) cout << ":(" << endl;
  else cout << "Yay!" << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<sstream>
#include<fstream>
#include<vector>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<functional>
#include<climits>
#include<utility>
#include <iomanip>
#include<map>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;

#define max(a,b) (a>b?a:b)
#define min(a,b) (a<b?a:b)
#define FOR(i,s,e) for (int i = int(s); i < int(e); i++)
#define REP(i,x) FOR(i,0,x)
#define CLR(a) memset((a), 0 ,sizeof(a))


const int MOD = 1e+9+7;
const double PI  = acos(-1.0);

int main(){
	ll n;
	cin>>n;
	ll ret=(n/11)*2;
	if(n%11>0) ret+=1;
	if(n%11>6) ret+=1;
	cout<<ret<<"\n";
}


Measured memory_bytes: 384
#include <iostream>
#include <map>
#include <algorithm>
#include <string>
#include <vector> 
#include <numeric>
#include <cmath>
#include <queue>
#include <iomanip>
#include <functional>

#define CHMAX(a,b) a = std::max(a,b)
#define CHMIN(a,b) a = std::min(a,b)
#define MAXMIN(a,b,c) std::max(a,min(b,c))
#define CHABS(a) a = std::abs(a) 
#define COUT(a) std::cout << a << std::endl
#define CERR(a) std::cerr << a << std::endl
#define FOR(n) for(lli i = 0; i < n; i++)

using namespace std;
using lli = long long int;
using pll = pair<lli, lli>;
using tlll = tuple<lli, lli, lli>;
using vll = vector<lli>;

lli mod197 = 1000000007LL;
lli INF = 10000000000000;

// ax + by = gcd(a,b) 最大公約数
template< typename T >
T extgcd(T a, T b, T& x, T& y) {
	T d = a;
	if (b != 0) {
		d = extgcd(b, a % b, y, x);
		y -= (a / b) * x;
	}
	else {
		x = 1;
		y = 0;
	}
	return d;
}

int arr[4] = {};

int main(void) {

	for (int i = 0; i < 6; i++) {
		int a;
		cin >> a;
		a--;
		arr[a]++;
	}


	for (int i = 0; i < 4; i++) {
		if (arr[i] == 3) {
			COUT("NO");
			return 0;
		}
	}
	COUT("YES");

	return 0;
}


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

namespace ALDS1_6_C_QuickSort
{
	class Program
	{
		static void Main ( string[] args )
		{
			//input
			int cardCount = int.Parse (Console.ReadLine ());
			Card[] cards = new Card[cardCount];

			for (int lp = 0; lp < cards.Length; lp++)
			{
				string[] inputStr = Console.ReadLine ().Split (' ');
				cards[lp] = new Card (inputStr[0], int.Parse (inputStr[1]));
			}

			//sort
			Card[] stableArray = new Card[cards.Length];
			cards.CopyTo (stableArray, 0);

			QuickSort (cards);
			stableArray = stableArray.OrderBy (item => item.Count).ToArray ();

			//compare
			bool isStable = true;
			for (int lp = 0; lp < cards.Length; lp++)
			{
				if (cards[lp] != stableArray[lp])
				{
					isStable = false;
					break;
				}
			}

			//output
			if (isStable)
				Console.WriteLine ("Stable");
			else
				Console.WriteLine ("Not stable");

			foreach (var item in cards)
			{
				Console.WriteLine (item.Mark + " " + item.Count);
			}

		}

		static void QuickSort ( Card[] array )
		{
			QuickSort (array, 0, array.Length - 1);
		}
		static void QuickSort ( Card[] array, int leftIndex, int rightIndex )
		{
			if (leftIndex < rightIndex)
			{
				int index = Partition (array, leftIndex, rightIndex);
				QuickSort (array, leftIndex, index - 1);
				QuickSort (array, index + 1, rightIndex);
			}
		}
		static int Partition ( Card[] array, int leftIndex, int rightIndex )
		{
			int baseValue = array[rightIndex].Count;
			int index = leftIndex - 1;

			for (int lp = leftIndex; lp < rightIndex; lp++)
			{
				if (array[lp].Count <= baseValue)
				{
					index++;

					var tmp = array[lp];
					array[lp] = array[index];
					array[index] = tmp;
				}
			}

			var tmp2 = array[index + 1];
			array[index + 1] = array[rightIndex];
			array[rightIndex] = tmp2;

			return index + 1;
		}
	}

	class Card
	{
		public Card ( string mark, int count )
		{
			this.Mark = mark;
			this.Count = count;
		}

		public string Mark { private set; get; }
		public int Count { private set; get; }
	}
}

Measured memory_bytes: 25540
N,M = map(int,input().split())
G = [[10**5 for _ in range(N)] for _ in range(N)]
E = []
Ans = 0

for i in range(M):
    a,b,c = map(int,input().split())
    G[a-1][b-1] = c
    G[b-1][a-1] = c
    E.append((a-1,b-1,c))

for k in range(N):
    for i in range(N):
        for j in range(N):
            if i==j:
                G[i][j] = 0
            else:
                G[i][j] = min(G[i][j], G[i][k]+G[k][j])


for i in range(M):
    a,b,c = E[i]
    for j in range(N):
        if G[j][b] == G[j][a] + c:
           break
    else:
        Ans += 1

print(Ans)



Measured memory_bytes: 3432
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 1000000007
#define EPS 1e-10

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;


int a, b;

int main(){
	REP(i, 7){
		cin >> a >> b;
		cout << a - b << endl;
	}
}

Measured memory_bytes: 1160
#define _USE_MATH_DEFINES
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>

using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 30;
const int MOD = 1e9 + 7;

const int N = 1e5 + 10;
int a[N];

int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%d", &a[i]);
  }
  sort(a, a + n);
  if (a[0] == a[n - 1]) {
    if (a[0] == n - 1) {
      puts("Yes");
      return 0;
    }
    puts(a[0] <= n / 2 ? "Yes" : "No");
    return 0;
  }
  for (int i = 0; i < n; ++i) {
    if (a[i] != a[0] && a[i] != a[n - 1]) {
      puts("No");
      return 0;
    }
  }
  if (a[n - 1] - a[0] != 1) {
    puts("No");
    return 0;
  }
  int u = 0;
  for (int i = 0; i < n; ++i) {
    u += a[i] == a[0];
  }
  int v = a[n - 1] - u;
  puts(u + 2 * v <= n && v >= 1 ? "Yes" : "No");
  return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
#define int long long
#define P pair<int,int>
#define PP pair<P,int>
#define F first
#define S second
#define f(i,n) for(int i=0;i<(n);i++)
#define INF LLONG_MAX/3
#define eps LDBL_EPSILON
#define mod (int)(1000000007)
#define pie 3.141592653589793238462643383279
#define Bpri priority_queue
#define Spri priority_queue<P,vector<P>,greater<P>>
using namespace std;
int cnt=0;
string s;
int mypow(int a,int b,int c){
	if(b==0) return 1;
	if(b%2)return mypow(a,b-1,c)*a%c;
	int z=mypow(a,b/2,c);
	return z*z%c;
}
int mutu(int z){
	if(z==s.size())return 1;
	if(s[z]=='1'){
		return (mypow(3,(int)(s.size())-1-z,mod)+mutu(z+1)*2)%mod;
	}
	else return mutu(z+1);
}
signed main(){
	cin>>s;
	f(i,s.size()){
		if(s[i]=='1')cnt++;
	}
	cout<<mutu(0)<<endl;
}


Measured memory_bytes: 3584
n, k = map(int, input().split())
a = list(map(int, input().split()))
MOD = 10**9+7

a_sort = sorted(a)

ans = 0
for i in range(n):
    a_back = a[i:]
    a_back.sort()
    x = a_sort.index(a[i])
    y = a_back.index(a[i])
    ans += k*(k-1)*x//2+ + k*y
    ans %= MOD

print(ans)

Measured memory_bytes: 3316
X, Y, A, B, C = map(int, input().split())
r = list(map(int, input().split()))
g = list(map(int, input().split()))
nc = list(map(int, input().split()))

r.sort(reverse=True)
g.sort(reverse=True)
nc.sort(reverse=True)

selected = r[:X] + g[:Y]
selected.sort()

if len(selected) > len(nc) or len(selected) == len(nc):
  L = len(nc)
else:
  L = len(selected)

for i in range(L):
  if selected[i] < nc[i]:
    selected[i] = nc[i]
    
print(sum(selected))

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

double solve(vector<double>& p, int N){
	int heads=N;
	vector<vector<double>>dp(N+1,vector<double>(N+1,0.0));
	dp[0][0]=1.0;
	for (int i=1;i<=N;i++){
		for (int j=0;j<=i;j++){
			if (j==0) dp[i][j]=dp[i-1][j]*(1.0-p[i-1]);
			else dp[i][j]=dp[i-1][j-1]*p[i-1]+dp[i-1][j]*(1.0-p[i-1]);
		}
	}
	double ans=0.0;
	for (int i = (N + 1) / 2; i <= N; i += 1) 
        ans += dp[N][i];
	return ans;

}
signed main() {
	int N;
    cin>>N;
    vector<double> prob(N);
    for (int i=0;i<N;i++){
    	cin>>prob[i];
    }
	cout<< setprecision(16)<<solve(prob,N)<<endl;
    return 0; 
}


Measured memory_bytes: 73808
A, B, C, X, Y = map(int, input().split())

if (A+B) <= 2*C: # 単品だけで購入
  print(X*A + Y*B)
else:
  # ABを買い残りを単品で補う
  if X >= Y:
    # ABでYは賄える
    print(min(X*2*C, Y*2*C + A*(X-Y)))
  else:
    # ABでXは賄える
    print(min(Y*2*C, X*(2*C)+B*(Y-X)))

Measured memory_bytes: 3060
x,n=map(int,input().split())
if n==0:
  print(x)
  exit()
p=list(map(int,input().split()))
a=[]
ans=100000
suu=100000

for i in range(-10,120):
  a.append(i)
for i in range(n):
  a.remove(p[i])
  
for i in range(len(a)):
  sa=abs(x-a[i])
  if sa<suu:
      suu=sa
      ans=a[i]
      
print(ans)

Measured memory_bytes: 9188
a = [list(map(int, input().split())) for i in range(3)]
b = [[0 for i in range(3)] for j in range(3)]
n = int(input())
for _ in range(n):
    c = int(input())
    for i in range(3):
        for j in range(3):
            if a[i][j] == c:
                b[i][j] = 1

if b[0][0] + b[1][1] + b[2][2] == 3:
    print('Yes')
elif b[0][0] + b[0][1] + b[0][2] == 3:
    print('Yes')
elif b[1][0] + b[1][1] + b[1][2] == 3:
    print('Yes')
elif b[2][0] + b[2][1] + b[2][2] == 3:
    print('Yes')

elif b[0][0] + b[1][0] + b[2][0] == 3:
    print('Yes')
elif b[0][1] + b[1][1] + b[2][1] == 3:
    print('Yes')
elif b[0][2] + b[1][2] + b[2][2] == 3:
    print('Yes')

elif b[2][0] + b[1][1] + b[0][2] == 3:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define np next_permutation
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define pi acos(-1.0)
const ll INF = 1LL<<61;
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; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
ll jou(ll N, ll P){if(P==0) return 1;
  if(P%2==0){ll t = jou(N, P/2);return t*t % mod;
  }return (N * jou(N, P-1)) % mod;}  //jou(n,mod-2)で逆元
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32;    で小文字に
//  cout << fixed << setprecision (20);   小数点以下2０桁まで
//実行時間制約2秒では２×10^8回くらいまで計算できる



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

  vector<ll> p(n+1);
  rep(i,n){
    cin>>p[i+1];
  }

  vector<ll> q(n+1);
  vector<ll> ans;
  for(ll i=n;i>=1;i--){
    if((p[i]+q[i])%2==1) {
      ans.pb(i);
      for(ll j=1;j*j<=i;j++){
        if(i%j==0) {
          q[j]++;
          if(j!=i/j) q[i/j]++;
        }
      }
    }
  }

  sort(all(ans));

  cout << ans.size() << endl;

  rep(i,ans.size()){
    cout << ans[i];
    if(i!=ans.size()-1) cout << " ";
    if(i==ans.size()-1) cout << endl;
  }

}

Measured memory_bytes: 4980
# -*- coding: utf-8 -*-
"""
Created on Tue Mar 31 01:29:10 2020

@author: liang
"""

N, X, Y = map(int,input().split())
length = [0]*(N)
for i in range(1,N+1):
    for j in range(i+1,N+1):
        ans = min(j-i,abs(i-X) + 1 + abs(j-Y))
        length[ans] += 1

for i in range(1,N):
    print(length[i])

Measured memory_bytes: 3444
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
#define INF 1007654321
#define PI 3.14159265358979
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define repp(i, s, e) for(int i = (s); i <= (e); ++i)
#define sz(x) ((int)x.size())
#define all(x) x.begin(), x.end()
#define FAST_IO() ios::sync_with_stdio(0); cin.tie(0)
template<typename T>
ostream& operator<<(ostream &os, const vector<T> &v) { for (auto x : v) os << x << " "; return os << "\n"; }

struct DisjointSet{
    int N;
    vector<int> p;
    DisjointSet(int n) : N(n) {
        p.resize(N, -1);
    }
    
    int find(int a) {
        if(p[a] < 0) return a;
        return p[a] = find(p[a]);
    }
    
    void merge(int a, int b) {
        a = find(a);
        b = find(b);
        if(a == b) return;
        if(p[a] > p[b]) swap(a, b);
        p[a] += p[b];
        p[b] = a;
    }
};

int main() {
    FAST_IO();
    int N, M; cin >> N >> M;
    vector<int> p(N);
    rep(i, N) cin >> p[i];
    DisjointSet djs(N);
    rep(i, M) {
        int u, v; cin >> u >> v;
        djs.merge(u-1, v-1);
    }
    int ans = 0;
    rep(i, N) {
        if(djs.find(i) == djs.find(p[i]-1)) ans++;
    }
    cout << ans << "\n";
}


Measured memory_bytes: 1024
"use strict";
    
const main = arg => {
    arg = arg.trim().split("\n");
    const S = arg[0].split("");
    
    let Rstock = 0;
    let Lstock = 0;
    let splitPoint;
    let splitCount = 0;
    
    let answer = [...Array(S.length)].fill(0);

    for(let i=0; i<S.length-1; i++) {
        if(S[i] === "R") Rstock++;
        if(S[i] === "L") Lstock++;
        
        // RL の部分であるかどうか
        if(S[i] !== S[parseInt(i) + 1]) {
            splitCount++;
            
            if(splitCount === 1) {
                splitPoint = i;
            }
        }
        
        if(splitCount === 2) {
            if((Rstock + Lstock) % 2 === 0) {
                answer[splitPoint]     = (Rstock + Lstock) / 2;
                answer[splitPoint + 1] = (Rstock + Lstock) / 2;
            } else {
                answer[splitPoint]     = Math.floor(Lstock / 2) + 1 + Math.floor((Rstock - 1) / 2) ;
                answer[splitPoint + 1] = Math.floor(Rstock / 2) + 1 + Math.floor((Lstock - 1) / 2);
            }
            
            splitCount = 0;
            
            Rstock = 0;
            Lstock = 0;
        }
        
        if(i === S.length - 2) {
            Lstock++;
            
           if((Rstock + Lstock) % 2 === 0) {
                answer[splitPoint]     = (Rstock + Lstock) / 2;
                answer[splitPoint + 1] = (Rstock + Lstock) / 2;
            } else {
                answer[splitPoint]     = Math.floor(Lstock / 2) + 1 + Math.floor((Rstock - 1) / 2) ;
                answer[splitPoint + 1] = Math.floor(Rstock / 2) + 1 + Math.floor((Lstock - 1) / 2);
            }
        }
    }
    
    console.log(answer.join(" "));
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


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

using namespace std;

string to_string(string s) {
  return '"' + s + '"';
}

string to_string(const char* s) {
  return to_string((string) s);
}

string to_string(bool b) {
  return (b ? "true" : "false");
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

typedef long long int ll;

const int N = 55;

vector < vector < int > > adj (N, vector < int > ());
vector < int > depth (N), euler, first (N), val (N);
int lca[N][N];
int pos = 0;

void dfs (int u, int p) {
  euler.push_back (u);
  first[u] = pos++;
  for (auto to : adj[u]) {
    if (to != p) {
      depth[to] = depth[u] + 1;
      dfs (to, u);
      euler.push_back (u);
      pos++;
    }
  }
}

void dfs1 (int u, int p) {
  for (auto to : adj[u]) {
    if (to != p) {
      dfs1 (to, u);
      val[u] += val[to];
    }
  }
}

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

  int n;
  cin >> n;
  for (int i = 0; i < n - 1; i++) {
    int u, v;
    cin >> u >> v;
    adj[u].push_back (v);
    adj[v].push_back (u);
  }

  if (n == 2) {
    cout << 1 << '\n';
    return 0;
  }

  int root = -1;
  for (int i = 1; i <= n; i++) {
    if ((int)adj[i].size() != 1) {
      root = i;
      break;
    }
  }

  dfs (root, root);

  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      if (i != j) {
        int mi = INT_MAX, u = i, v = j;
        if (first[u] > first[v]) swap (u, v);
        for (int k = first[u]; k <= first[v]; k++) {
          if (depth[euler[k]] < mi) {
            mi = depth[euler[k]];
            lca[i][j] = euler[k];
          }
        }
      }
    }
  }

  int m;
  cin >> m;
  vector < pair < int, int > > p (m);
  for (auto &i : p) cin >> i.first >> i.second;

  ll ans = 0;
  for (int msk = 1; msk < (1 << m); msk++) {
    val.assign (n + 1, 0);
    int c = 0;
    for (int bt = 0; bt < m; bt++) {
      if ((msk >> bt) & 1) {
        c++;
        int u = p[bt].first, v = p[bt].second, l = lca[u][v];
        val[l]--;
        val[u]++;
        val[l]--;
        val[v]++;
      }
    }
    int cnt = 0;
    dfs1 (root, root);

    for (int i = 1; i <= n; i++) if (val[i] > 0) cnt++;

    if (c & 1) {
      ans += ((ll)1 << (n - 1 - cnt));
    } else {
      ans -= ((ll)1 << (n - 1 - cnt));
    }
  }

  ans = ((ll)1 << (n - 1)) - ans;

  cout << ans << '\n';
}


Measured memory_bytes: 3620
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<vector>
#include<cmath>
typedef long long ll;
typedef unsigned un;
typedef std::string str;
typedef std::pair<ll,ll> pll;
ll read(){ll x=0,f=1;char c=getchar();while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}return f*x;}
ll max(ll a,ll b){return a>b?a:b;}
ll min(ll a,ll b){return a<b?a:b;}
void umax(ll& a,ll t){if(t>a)a=t;}
void umin(ll& a,ll t){if(t<a)a=t;}
#define MAXN 200011
ll a[MAXN],b[MAXN];
int main()
{
	ll n=read(),k=read(),l1=0,l2=0,zero=0;
	for(ll i=1;i<=n;++i)
	{
		ll x=read();
		if(x==0)++zero;
		else if(x>0)a[++l1]=x;
		else b[++l2]=x;
	}
	std::sort(a+1,a+l1+1),std::sort(b+1,b+l2+1);
	if(l1*l2>=k)
	{
		ll l=-ll(1e18),r=-1;
		while(l<r)
		{
			ll mid=(l+r)>>1;
			ll cnt=0,it=1;
			for(ll i=1;i<=l2;++i)//negative to positive
			{
				while(it<=l1&&a[it]*b[i]>mid)
					++it;
				cnt+=l1-it+1;
			}
			if(cnt<k)l=mid+1;
			else r=mid;
		}
		printf("%lld\n",l );
		return 0;
	}
	k-=l1*l2;
	ll tmp=zero*(n-zero)+zero*(zero-1)/2;
	if(tmp>=k)return puts("0"),0;
	k-=tmp;
	std::reverse(b+1,b+l2+1);
	ll l=1,r=ll(1e18);
	while(l<r)
	{
		ll mid=(l+r)>>1;
		ll cnt=0,it=l1;//positive to positive
		for(ll i=1;i<=l1;++i)
		{
			while(it&&a[it]*a[i]>mid)--it;
			cnt+=max(it-i,0);
		}
		it=l2;
		for(ll i=1;i<=l2;++i)
		{
			while(it&&b[it]*b[i]>mid)--it;
			cnt+=max(it-i,0);
		}
		if(cnt<k)l=mid+1;
		else r=mid;
	}
	printf("%lld\n",l );
	return 0;
}

Measured memory_bytes: 4500
package main

import (
	"fmt"
	"math"
)

func main() {
	var n, k int
	fmt.Scan(&n, &k)
	arr := make([]int, n)
	for i := 0; i < n; i++ {
		var tmp int
		fmt.Scan(&tmp)
		arr[i] = tmp
	}
	dp := make([]int, n)
	dp[0] = 0
	for i := 0; i < n - 1; i++ {
		dp[i + 1] = dp[i] + abs(arr[i + 1] - arr[i])
		for j := 1; j < k && i - j >= 0; j++ {
			dp[i + 1] = min1(dp[i + 1], dp[i - j] + abs(arr[i + 1] - arr[i - j]))
		}
	}
	fmt.Println(dp[len(dp) - 1])
}

func min1(a, b int) int {
	if a < b {
		return a
	} else {
		return b
	}
}

func abs(x int) int {
	return int(math.Abs(float64(x)))
}

Measured memory_bytes: 5504
l = input().split()
N = int(l[0])
W = int(l[1])
products = [] # [[value, weight]]
for i in range(N):
    l = input().split()
    products.append([int(l[0]),int(l[1])])

DP = [0 for _ in range(W + 1)]
p_flag = [[False for _ in range(N)] for _ in range(W + 1)]
for i in range(N):
    new_DP = [DP[j] if j < products[i][1] else 0 for j in range(W + 1)]
    for j in range(products[i][1], W + 1):
        product_in = DP[j - products[i][1]] + products[i][0]
        if product_in >= DP[j]:
            new_DP[j] = product_in
        else:
            new_DP[j] = DP[j]
    DP = [v for v in new_DP]
print(DP[W])

Measured memory_bytes: 17888
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;

int n,m,Ex,Ey,Ans,f[2][110][110][110];
int g[110][110],row[110][110],line[110][110];

inline int Row(int id,int L,int R) {return row[id][R]-row[id][L-1];}
inline int Line(int U,int D,int id) {return line[D][id]-line[U-1][id];}

int main()
{
//#ifdef h10
//	freopen("robots.in","r",stdin);
//	freopen("robots.out","w",stdout);
//#endif
	int i,j,U,D,L,R;
	char c;
	scanf("%d%d",&n,&m);
	for (i=1;i<=n;i++)
	for (j=1;j<=m;j++)
	{
		c=getchar();
		while (c!='.'&&c!='o'&&c!='E') c=getchar();
		if (c=='o') g[i][j]=1;
		if (c=='E') Ex=i,Ey=j;
		row[i][j]=row[i][j-1]+g[i][j];
		line[i][j]=line[i-1][j]+g[i][j];
	}
	for (U=0;U<Ex;U++)
	for (D=0;D<=n-Ex;D++)
	for (L=0;L<Ey;L++)
	for (R=0;R<=m-Ey;R++)
	{
		int X=U&1,Y=X^1,&val=f[X][D][L][R];
		int u=max(D+1,Ex-U),d=min(Ex+D,n-U);
		int l=max(R+1,Ey-L),r=min(Ey+R,m-L);
		if (U&&Ex-U-D>0) val=max(val,f[Y][D][L][R]+Row(Ex-U,l,r));
		if (D&&Ex+D+U<=n) val=max(val,f[X][D-1][L][R]+Row(Ex+D,l,r));
		if (L&&Ey-L-R>0) val=max(val,f[X][D][L-1][R]+Line(u,d,Ey-L));
		if (R&&Ey+R+L<=m) val=max(val,f[X][D][L][R-1]+Line(u,d,Ey+R));
		Ans=max(Ans,val);
	}
	printf("%d\n",Ans);
}


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

int main(){
    int N;
    cin >> N;
    string names[N];
    string X_name;
    for(int i = 0; i < N; i++){
        cin >> names[i];
    }
    cin >> X_name;
    int front_X = 0;
    int either = 0;
    for(int i = 0; i < N; i++){
        string min_name;
        string max_name;
        for(int j = 0; j < names[i].size(); j++){
            if(names[i][j] == '?'){
                min_name.push_back('a');
                max_name.push_back('z');
            }else{
                min_name.push_back(names[i][j]);
                max_name.push_back(names[i][j]);
            }
        }
        if(min_name <= X_name && X_name <= max_name){
            either++;
        }else if(min_name <= X_name){
            front_X++;
        }
    }
    string ans_text = "";
    for(int i = front_X + 1; i <= front_X + either + 1; i++){
        ans_text += to_string(i) + " ";
    }
    ans_text.pop_back();
    cout << ans_text << endl;
}


Measured memory_bytes: 896
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repe(i,n) for (int i = 0; i <= (n); ++i)
#define repe1(i,n) for (int i = 0; i <= (n); ++i)
#define all(x) (x).begin(),(x).end()
#define pb(x) push_back(x)
#define eb(k,v) emplace_back(k,v)
#define ct(res) cout << res << "\n";
#define vi vector<int>
#define vl vector<ll>
using namespace std;
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; }
const int INF = 1e9;
const ll MOD = 1000000007;
using Graph = vector<vector<int>>;
ll gcd(ll a, ll b) {return (a%b) ? gcd(b, a%b) : b;}
ll modPow(ll x, ll n) {
    if(n==0) return 1;
    ll res = modPow(x*x%MOD, n/2);
    if(n&1) res=res*x%MOD;
    return res;
}
ll mul(ll l, ll r) {
    ll ret =1;
    for(int i=0; i<l-r+1; ++i) {
        ret*=i+r;
        ret%=MOD;
    }
    return ret;
}
ll com(ll n, ll k) {
    ll ret1 = mul(n,n-k+1);
    ll ret2 = mul(k,1);
    ll ret3 = modPow(ret2, MOD-2);
    return ret1*ret3%MOD;
}


int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    string s;cin>>s;
    if (s[2]==s[3] && s[4]==s[5]) {
        ct("Yes");
        return 0;
    }
    ct("No");
}


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

int main() {
  ll X,i=0;
  cin>>X;
  vector<ll> s,dp;
  while(1){s.push_back(i*(i+1)/2);if(s[i]>=X){break;} i++;}
  cout<<s.size()-1<<endl;
}


Measured memory_bytes: 892
Sr = list(input())
Sl = []
Q = int(input())


for i in range(Q):
    s = list(input().split())
    if len(s) == 1:
        Sr,Sl = Sl,Sr
    elif s[1] == '1':
        Sl.append(s[2])
    else:
        Sr.append(s[2])
Sl.reverse()
print('%s' % (''.join(Sl) + ''.join(Sr)))



Measured memory_bytes: 6292
#include<cstdio>
#include<algorithm>

using namespace std;

int a[3];

int main(){
  for(int i = 0; i < 3; i++)
    scanf("%d", &a[i]);

  sort(a, a+3);

  bool f = true;
  int b[3];
  b[0] = 5;
  b[1] = 5;
  b[2] = 7;
  
  for(int i = 0; i < 3; i++)
    f = f && a[i] == b[i];

  if(f)
    printf("YES\n");
  else
    printf("NO\n");
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <tuple>
#include <cmath>
using namespace std;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;

int main(){
    int a,b,c;
    cin>>a>>b>>c;
    if(b-a==c-b){
        cout<<"YES"<<endl;
    }else{
        cout<<"NO"<<endl;
    }
    return 0;
}

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

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,n) FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);i--)
#define rrep(i,n) RFOR(i,n,0)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

const int max_n = 1e5 + 10;
int n, m;
vector<int> g[max_n];
int d[max_n];

int dfs(int x){
	if(d[x] > 0) return d[x];
	int mx = 0;
	rep(i, g[x].size()){
		mx = max(mx, dfs(g[x][i]) + 1);
	}

	d[x] = mx;
	return mx;
}

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

	cin >> n >> m;
	rep(i, m){
		int x, y;
		cin >> x >> y;
		x--;
		y--;
		g[x].push_back(y);
	}

	rep(i, n) d[i] = 0;

	int ans = 0;
	rep(i, n){
		if(d[i] == 0) ans = max(ans, dfs(i));
	}

	cout << ans << endl;
}


Measured memory_bytes: 8192
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
const double PI = acos(-1);
const ll MOD = 1000000007;
using Graph = vector<vector<int>>;

int main() {
  string s; cin >> s;
  int N = s.size();
  
  int count = 0;
  for (int i = 0; i < N; i++) {
    if (i < (N+1) / 2) {
      if (s[i] == 'p') count--; 
    } else {
      if (s[i] == 'g') count++;
    }
  }

  cout << count << endl;
}

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

int main()
{
    size_t n, k;
    list<int> p;
    cin >> n >> k;

    for (size_t i = 0; i < k; i++) {
        int tmp_p;
        cin >> tmp_p;

        if (p.size() < k) {
            p.push_back(tmp_p);
        }
    }

    p.sort();
    for (size_t i = k; i < n; i++){
        int tmp_p;
        cin >> tmp_p;

        if (tmp_p < p.back()) {
            auto it = lower_bound(p.begin(), p.end(), tmp_p);
            p.insert(it, tmp_p);
            p.pop_back();
        }
    }

    int64_t sum = 0;
    for (auto it = p.begin(); it != p.end(); ++it) {
        sum += *it;
    }
    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
 
int main () {
  int N, M, C;
  cin >> N >> M >> C;
  vector<int> B(M);
  for (int i = 0; i < M; i++) {
    cin >> B.at(i);
  }
  int ans = 0;
  for (int i = 0; i < N; i++) {
    vector<int> A(M);
    int64_t memo = C;
    for (int j = 0; j < M; j++) {
      cin >> A.at(j);
      memo += A.at(j) * B.at(j);
    }
    if (memo > 0) {
      ans++;
    }
  }
  cout << ans << endl;
}
      

Measured memory_bytes: 3568
n = int(input())
ab = [map(int, input().split()) for _ in range(n)]
a, b = [list(i) for i in zip(*ab)]
 
a.reverse()
b.reverse()
ans = 0
 
for j in range(n):
  a[j] += ans
  if a[j] % b[j] != 0:
    ans += b[j] -(a[j] % b[j])
 
print(ans)

Measured memory_bytes: 62840
#include<iostream>
#include<vector>
#include<algorithm>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<climits>
#include<set>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
using namespace std;
typedef pair<int, int> pii;
typedef long long int ll;
typedef pair<ll,ll> pll;
int dx[4] = {1,0,0,-1};
int dy[4] = {0,1,-1,0};
#define MOD 1000000007
#define ARRAY_MAX 100005

const int INF = 1e9+7;


int main(){

    string s;
    cin >> s;
    int month = (s[5]-'0')*10 + s[6]-'0';
    int day = (s[8]-'0')*10 + s[9]-'0';
    //cout << month << " " << day << endl;
    if(month >= 5){
        cout << "TBD" << endl;
    }else{
        cout << "Heisei" << endl;
    }



    return 0;
}


Measured memory_bytes: 256
X, K, D = map(int, input().split())
current_position = X

times = abs(X) // D

if times < K:
    if times > 0 :
        if current_position >= 0:
            current_position = current_position - D*times
        elif current_position < 0:
            current_position = current_position + D*times
    K = K - times
    if K % 2 == 1:
        if current_position >= 0:
            current_position = current_position - D
        elif current_position < 0:
            current_position = current_position + D
else:
    if current_position >= 0:
        current_position = current_position - D * K
    elif current_position < 0:
        current_position = current_position + D * K
print(abs(current_position))



Measured memory_bytes: 9188
import sys


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    n, t = list(map(int, readline().split()))
    ab = [list(map(int, readline().split())) for _ in range(n)]
    ab.sort()
    dp = [0] * (t + 1)
    for a, b in ab:
        dp[-1] = max(dp[-1], dp[-2] + b)
        for i in range(t - a - 1, -1, -1):
            dp[i + a] = max(dp[i + a], dp[i] + b)
    print(dp[-1])


if __name__ == '__main__':
    solve()


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

void f(int n, int i, int k, string s) //n文字 i文字目 k種類
{
	//cout << n << " " << i << " " << k << " " << s << endl;
	if (i == n)
	{
		cout << s << endl;
		return;
	}
	else
	{
		char c;
		rep(j,k)
		{
			string temp = s;
			c = 'a' + j;
			temp += c;
			f(n,i+1,k,temp);
		}
		c = 'a' + k;
		s += c;
		f(n,i+1,k+1,s);
	}
}

int main()
{
	int N;
	cin >> N;
	f(N,0,0,"");
	return 0;
}

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

#define rep(i, N) for (int i = 0; i < (N); i++)
#define all(a) (a).begin(), (a).end()
#define pb push_back

using ll = long long;
using i_i = tuple<int, int>;

int main() {
    int N, M, K;
    cin >> N >> M >> K;
    vector<int> a(1000000);
    while (K--) {
        int i, j;
        scanf("%d%d", &i, &j);
        i--; j--;
        if (j >= M) j++;
        a[N - i + abs(j - M)]++;
    }
    int ans = 0;
    rep(d, 1000000) {
        if (a[d]) {
            ans = d;
            a[d + 1] += a[d] - 1;
        }
    }
    cout << ans << endl;
}



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

//typedef
//------------------------------------------
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int MOD = 1000000007;

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

//main code

int main(int argc, char const* argv[])
{
	int a,b,q;
	cin >> a >> b >> q;
	VL s(a), t(b), x(q);
	for (int i = 0; i < a; i++) {
		cin >> s[i];
	}
	for (int i = 0; i < b; i++) {
		cin >> t[i];
	}
	for (int i = 0; i < q; i++) {
		cin >> x[i];
	}
	s.push_back(-10000000000);
	s.push_back(100000000000);
	t.push_back(-10000000000);
	t.push_back(100000000000);
	VL invs = s, invt = t;
	SORT(s);
	SORT(t);
	sort(RALL(invs));
	sort(RALL(invt));

	for (int i = 0; i < q; i++) {
		LL ans = INT64_MAX;
	    LL highs = *lower_bound(ALL(s),x[i]);
		LL hight = *lower_bound(ALL(t),x[i]);
		LL lows =  *(lower_bound(ALL(s),x[i])-1);
		LL lowt =  *(lower_bound(ALL(t),x[i])-1);
		ans = min(ans, max(x[i] - lows, x[i] - lowt));
		ans = min(ans, max(highs - x[i],hight - x[i]));
		ans = min(ans, hight - x[i] + x[i] - lows + min(hight - x[i] , x[i] - lows));
		ans = min(ans, highs - x[i] + x[i] - lowt + min(highs - x[i] , x[i] - lowt));
		cout << ans << endl;
	}

	return 0;
}


Measured memory_bytes: 6296
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<string>
#include<stack>
#include<map>
#include<set>
#include<queue>
#include<iostream>
#include<algorithm>
#include<unordered_map>
#include<unordered_set>
#define PI acos(-1)
#define pb push_back
#define all(x) x.begin(),x.end()
#define INF 0x3f3f3f3f
#define dd(x) cout<<#x<<" = "<<x<<","
#define de(x) cout<<#x<<" = "<<x<<"\n"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
int main()
{
	int a,b;
	scanf("%d%d",&a,&b);
	if(b>=a){
		printf("unsafe");
	}
	else{
		printf("safe");
	}
}


Measured memory_bytes: 3828
(function(input) {
  var n = Number(input.replace(/\n$/, ''));
  console.log(factorial(n));
})(require('fs').readFileSync('/dev/stdin', 'utf8'));

function factorial(n) {
  if (n === 1) {
    return 1;
  }
  return n * factorial(n - 1);
}

Measured memory_bytes: 7384
#include<cstdio>
#include<algorithm>
using namespace std;
int main(void)
{
	char s[4];
	int i,c=0;
	for(i=0;i<4;i++){
		scanf("%c",&s[i]);
		if(s[i]=='+') c++;
		if(s[i]=='-') c--;
	}
	printf("%d\n",c);
	return 0;
}


Measured memory_bytes: 1656
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const ll MOD = 1000000007;


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

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

    vector<int> a(N), b(N);
    for(int i=0;i<N;i++){
        a[i] = 30000 * (i+1);
        b[i] = 30000 * (N-i);
    }
    for(int i=0;i<N;i++){
        b[p[i]-1] += i;
    }

    for(int i=0;i<N;i++){
        cout << (i ? " " : "") << a[i] << endl;
    }
    for(int i=0;i<N;i++){
        cout << (i ? " " : "") << b[i] << endl;
    }

    return 0;
}

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

#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define FOR(e, c) for (auto &e : c)
#define SORT(v, n) sort(v, v + n);
#define vsort(v) sort(v.begin(), v.end());
#define rvisort(v) sort(v.begin(), v.end(), greater<int>());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
// #define int long long
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) int(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using ul = unsigned long;

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

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

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

inline bool inside(int y, int x, int H, int W) {
    return (y >= 0 && x >= 0 && y < H && x < W);
}

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  ll n; cin>>n;
  int ans=11;
  for(ll i=1; i*i<=n; i++){
    if(!(n%i)){
      ll m=n/i;
      int tmp=0;
      while(m){
        tmp++;
        m/=10;
      }
      chmin(ans,tmp);
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256