akhauriyash/Code-Regression huggingface dataset:
#define TEST_MODE true

#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep2(i, a, b) for (int i = (a); i < (int)(b); ++i)
#define rrep(i, n) for (int i = (n)-1; i >= 0; --i)
#define rrep2(i, a, b) for (int i = (a)-1; i >= (int)b; --i)
#define range(i, a, b, c) for (int i = a;             \
                                   c > 0 ? i < b : i > b; \
                                   i += c)
#define chmax(a, b) (a = (a) < (b) ? (b) : (a))
#define chmin(a, b) (a = (a) > (b) ? (b) : (a))
using ll = long long;
using ull = unsigned long long;
using ld = long double;
#define all(a) begin(a), end(a)
#define ifnot(a) if (not(a))
#define int long long

#ifdef LOCAL_ENV

#if TEST_MODE == true
const bool test = true;
#define dump(x) cerr << #x << " = " << (x)
#define dumpl(x) dump(x) << endl
#else
const bool test = false;
#define dump(x) 
#define dumpl(x)
#endif

#else
const bool test = false;
#define dump(x) 
#define dumpl(x)
#endif

int dx[] = { 1, 0, -1, 0 };
int dy[] = { 0, 1, 0, -1 };
const int INF = (int)1 << 60;
const ll INFL = (ll)1 << 60;
ll mod_n = (int)1e9 + 7;
const double eps = 1e-10;
typedef long double Real;
// return -1, 0, 1
int sgn(const Real &r) { return (r > eps) - (r < -eps); }
int sgn(const Real &a, const Real &b) { return sgn(a - b); }

//.....................
const int MAX = (int)2e5 + 5;

vector<string> split(const string &str, char sep)
{
	vector<string> v;
	stringstream ss(str);
	string buffer;
	while (getline(ss, buffer, sep))
	{
		v.push_back(buffer);
	}
	return v;
}

template <class InputIterator>
int sum(InputIterator begin, InputIterator end)
{
	return accumulate(begin, end, 0ll);
}

template<typename T>
T gcd(T a, T b)
{
	T c;
	while (a != 0) {
		c = a; a = b%a;  b = c;
	}
	return b;
}

template<typename T>
T bit_count(T N) {
	T cnt = 0;
	while (N) {
		if (N & 1) cnt++;
		N >>= 1;
	}
	return cnt;
}

struct Point {
	int y, x;
	bool operator < (const Point& r) {
		if (x < r.x) return true;
		else return false;
	}
};

class Solver {
public:
	int N;
	int A[2][105];
	int dp[2][105] = {};

	void solve() {
		cin >> N;
		rep(i, 2) rep(j, N) cin >> A[i][j];
		rep(i, 2) rep(j, N) dp[i][j] = 0;

		dp[0][0] = A[0][0];
		dp[1][0] = dp[0][0] + A[1][0];
		rep(i, N-1) {
			dp[0][i + 1] = dp[0][i] + A[0][i + 1];
			int b = dp[0][i + 1];
			int c = dp[1][i];
			dp[1][i + 1] = max(b, c) + A[1][i + 1];
		}
		cout << dp[1][N - 1] << endl;
	}
};

signed main()
{
	srand((unsigned int)time(NULL));
	cout << fixed << setprecision(20);
	auto ptr = new Solver();
	ptr->solve();
	delete ptr;
	//while (true) {
	//	if (cin.eof() == true) break;
	//	auto ptr = new Solver();
	//	ptr->solve();
	//	delete ptr;
	//}
	return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
using namespace std;
int main() {
	int a;
	scanf("%d", &a);
	for (int i = 0;i < a;++i) {
		int b, c;
		int d = 1;
		scanf("%d%d", &b, &c);
		for (int q = b;q > 1;--q) {
			d++;
			if (d == c + 1) d = 1;
		}
		printf("%d\n", d);
	}
}


Measured memory_bytes: 1024
#include<iostream>
#include<cstring>
using namespace std;
int main(){
	int n,m;
	cin>>n>>m;
	int wa[n+1]={0};
	int ac[n+1]={0};
	int c=0,w=0;
	while(m--){
		int q;
		string s;
		cin>>q>>s;
		if(s=="WA")wa[q]++;
		else if(s=="AC" && ac[q]==0){
			ac[q]++;
			c++;
			w+=wa[q];
		}
	}
	cout<<c<<" "<<w;
	return 0;
}

Measured memory_bytes: 4408
import math

a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())

f = [a,b,c,d,e]
n = [math.ceil((i/10))*10 for i in f]
m = [math.ceil((i/10))*10-i for i in f]
s = sum(n)-max(m)
print(s)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define assn(n,a,b) assert(n<=b && n>=a)
using namespace std;
#define pb push_back
#define mp make_pair
#define clr(x) x.clear()
#define sz(x) ((int)(x).size())
#define F first
#define S second
#define REP(i,a,b) for(i=a;i<b;i++)
#define rep(i,b) for(i=0;i<b;i++)
#define rep1(i,b) for(i=1;i<=b;i++)
#define pdn(n) printf("%d\n",n)
#define sl(n) scanf("%lld",&n)
#define sd(n) scanf("%d",&n)
#define pn printf("\n")
typedef pair<int,int> PII;
typedef vector<PII> VPII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef long long LL;
#define MOD 1000000007
LL mpow(LL a, LL n)
{LL ret=1;LL b=a;while(n) {if(n&1)
    ret=(ret*b)%MOD;b=(b*b)%MOD;n>>=1;}
return (LL)ret;}
#define MAXK 100000
#define MAXN 1000000000
int ar[MAXK];
int get(int n, int k){
    int i=0;
    while(i<k and ar[i]<=n)i++;
    return n-i;
}
typedef unsigned long long int ULL;
#define SSTR( x ) static_cast< std::ostringstream & >( \
        ( std::ostringstream() << std::dec << x ) ).str()
 
bool isSafe(int r, int c, vector<vector<int> > arr) {
	int n = arr.size();
	int m = arr[0].size();
	return (r>=0 && r<n && c>=0 && c<m);
}
 
/////////////////////////////////////////////////////////////

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    LL n,m;
    cin>>n>>m;
    LL tot = 0;
    vector<LL> arr(n,0);
    for(LL i=0;i<n;i++) {
    	cin>>arr[i];
    	tot+=arr[i];
    }
    sort(arr.rbegin(),arr.rend());
    double req=(double)tot/(4*m);
    //cout<<"req:"<<req<<endl;
    LL cnt = 0;
    for(LL i=0;i<n && cnt<m;i++) {
    	if(arr[i]>=req) {
    		cnt++;
    		//cout<<arr[i]<<" ";
    	} else break;
    }
    //cout<<endl;
    if(cnt>=m) cout<<"Yes";
    else cout<<"No";
    return 0;
}


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

int main(){
    int a,b;
    cin >> a >> b;
    
    if(a == b){
        cout << "Draw" << endl;
    }else if(a == 1 || b == 1){
        if(a == 1){
            cout << "Alice" << endl;
        }else if(b == 1){
            cout << "Bob" << endl;
        }
    }else if(b < a){
        cout << "Alice" << endl;
    }else if(a < b){
        cout << "Bob" << endl;
    }
}


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

using namespace std;
#define ll long long
const int N  =200005;

int n, a[11][11];
ll ans;
int power (int x){
int v=1;
for ( int i=0; i<x; i++) v*=10;
return v;
}


int solve (string x){
int no =0, f=0, last;
for (int i= x.size()-1; i >=0; i--){
    no += (x[i]-48)* power(f);
    if (f) f++;
    if (x[i]-48 >0 && f==0) f++, last =x[i]-48;
}
if (no > n) return 0;
return last;
}

int main()
{
        cin >> n;

        for (int i=1; i<=9; i++){
        for (int j=0; j<=9; j++){
         for (int k=0; k<=9; k++){
         for (int l=0; l<=9; l++){
         for (int m=0; m<=9; m++){
         for (int r=0; r<=9; r++){
        char c; string x;
        c=i+48, x+= c, c= j+48, x+=c,c= k+48, x+=c,c= l+48, x+=c,c= m+48, x+=c,c= r+48, x+=c;
        int  h = solve(x);
        if (h)  a[i][h]++;

         }
        }
        }
        }
        }
        }

         for (int i=1; i<=9; i++){
        for (int j=0; j<=9; j++){
         for (int k=0; k<=9; k++){
         for (int l=0; l<=9; l++){
         for (int m=0; m<=9; m++){
         for (int r=0; r<=9; r++){
        char c; string x;
        c=i+48, x+= c, c= j+48, x+=c,c= k+48, x+=c,c= l+48, x+=c,c= m+48, x+=c,c= r+48, x+=c;
        int  h = solve(x);
        if (h)  ans +=a[h][i];
        }
        }
        }
        }
        }
        }

        cout << ans;
    return 0;
}


Measured memory_bytes: 3588
#include <iostream>

using namespace std;

int main() {

	int a[10000] = { 0 };
	int b[10000] = { 0 };

	for (int i = 0; i < 10000; i++) {

		cin >> a[i] >> b[i];

		if (a[i] == b[i] && b[i] == 0) {

			break;

		}

	}
	
	for (int i = 0; i < 10000; i++) {

		if (a[i] == b[i] && b[i] == 0) {

			break;

		}

		if (a[i] < b[i]) {

			cout << a[i] << " " << b[i] << endl;

		}
		else {

			cout << b[i] << " " << a[i] << endl;

		}

	}

	return 0;

}

Measured memory_bytes: 3132
def prime(p):
    memo = set()
    for i in range(2,(int(p**0.5)+1)):
        while p%i==0:
            p //= i
            memo.add(i)
    if p != 1:
        memo.add(p)
    return memo

from math import gcd

N = int(input())

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

tmp_gcd = A[0]

#最大公約数が２以上かを判定
for i in range(1,N):
    tmp_gcd = gcd(tmp_gcd, A[i])

if 1 < tmp_gcd:
    print('not coprime')
    exit()

#素因数に被りがあるか判定
servive_prime = set()
for a in A:
    now_prime = prime(a)
    ls,ln = len(servive_prime), len(now_prime)
    servive_prime.update(now_prime)
    if len(servive_prime) < ls + ln:
        print('setwise coprime')
        exit()
#素因数被りがない場合
print('pairwise coprime')

Measured memory_bytes: 181440
#include<bits/stdc++.h>
#define MAXN 100005
#define INF 1000000000
#define MOD 1000000007
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int n,k,a[MAXN];
int main()
{
	scanf("%d",&n);
	for(int i=0;i<n;i++)
		scanf("%d",&a[i]);
	sort(a,a+n);
	int id=lower_bound(a,a+n,a[n-1]/2)-a;
	if(id==0) printf("%d %d\n",a[n-1],a[id]);
	else if(id==n-1) printf("%d %d\n",a[n-1],a[n-2]);
	else 
	{
		int x=a[id],y=a[id-1];
		int res1=max(x*2-a[n-1],a[n-1]-x*2),res2=max(y*2-a[n-1],a[n-1]-y*2);
		if(res1<res2) printf("%d %d\n",a[n-1],x); else printf("%d %d\n",a[n-1],y);
	}
	return 0;
}

Measured memory_bytes: 640
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

#define debug(...) fprintf(stderr, __VA_ARGS__)
#define int long long int
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
typedef pair<int, int> pii;
typedef long long ll;
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;
 
signed main() {
    string s; cin >> s;
    stack<char> stk;

    int N = s.length();
    for(int i=0; i<N; i++) {
        if(stk.empty() or stk.top() == s[i]) {
            stk.push(s[i]);
        }
        else {
            stk.pop();
        }
    }

    int rem = stk.size();
    cout << N - rem << endl;
    return 0;
}


Measured memory_bytes: 512
#include<stdio.h>
#include<string.h>
 
int main(){
  char t[1000],h[1000];
  int n,i,f;
  int tp=0,hp=0;
 
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%s",t);
    scanf("%s",h);
    f=strcmp(t,h);
    if(f>0)
      tp+=3;
    else if(f<0)
      hp+=3;
    else{
      tp++;
      hp++;
    }
  }
  printf("%d %d\n",tp,hp);
 
  return 0;
}

Measured memory_bytes: 608
#include<stdio.h>
int main(){
    int a,b,av,r,nt;
    scanf("%d %d",&a,&b);
    av=(a+b)/2;
    if((a+b)%2!=0){
        nt=av+1;
        printf("%d\n",nt);
    }
    else printf("%d\n",av);
    return 0;
}

Measured memory_bytes: 128
package main

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

const (
	oneHour   = 60 * 60
	oneMinute = 60
)

func main() {
	input, err := scanInt()
	if err != nil {
		panic(err)
	}

	hour := (input / oneHour)
	minute := (input % oneHour) / oneMinute
	second := (input % oneMinute)

	fmt.Printf("%d:%d:%d\n", hour, minute, second)
}

func scanInt() (int, error) {
	scan := bufio.NewScanner(os.Stdin)
	scan.Scan()
	return strconv.Atoi(scan.Text())
}



Measured memory_bytes: 1112
import java.util.Scanner;
class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int[] A = new int[5];
        int count = 0;

        for (int i = 0; i < 5; i++) {
            A[i] = sc.nextInt();
        }
        int k = sc.nextInt();

        for (int i = 4; i > 0; i--) {
            for (int j = 3; j >= 0; j--) {
                if (A[i] - A[j] > k ) {
                    count++;
                } 
            }
        }

        if (count > 0) {
            System.out.println(":(");
        } else {
            System.out.println("Yay!");
        }
    }
}

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

int main(){
    string s; cin >> s;
    int c = 0;
    for(int i = 0; i < 6; i++){
        if(s[i] == '1') c++;
    }
    cout << c << endl;
    return 0;
}


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

namespace ziyuutyou
{
    class Program
    {
        static void Main(string[] args)
        {
            var str = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);


            if(str[2] - str[0] >= 0 && str[2] - str[0] <= str[1])
            {
                Console.WriteLine("YES");
            }
            else
            {
                Console.WriteLine("NO");
            }
        }
    }
}


Measured memory_bytes: 11092
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Main mainObj = new Main();
		mainObj.solve();
	}
	
	public void solve() {
		Scanner sc = new Scanner(System.in);
		int m1 = sc.nextInt();
		int d1 = sc.nextInt();
		int m2 = sc.nextInt();
		int d2 = sc.nextInt();
		sc.close();
		
		if(m1 != m2) {
			System.out.println(1);
		}else {
			System.out.println(0);
		}
	}
}

Measured memory_bytes: 23252
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0;i < (n);i++)
#define all(v) v.begin(),v.end()
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;

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

ll mod(ll a){
  return a % 1000000007;
}

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


int main(){
  ll n,m; cin >> n >> m; vector<pair<ll,ll>> y(n);
  ll energy = 0; ll money = 0; bool flag = false;
  
  rep(i,n){ ll a,b; cin >> a >> b; y[i] = make_pair(a,b); }

  sort(all(y));
  
  for(ll i=0; i < n; i++){
	for(ll j=0; j < y[i].second; j++){
      money += y[i].first;
      energy++;
      if(energy >= m){
        flag = true;
        break;
      }
    }
    
    if(flag) break;
  }
  
  cout << money << endl;
}

Measured memory_bytes: 1792
S = input()

S = list(S)

flg = 0

for i in range(1, len(S)+1, 1):


        if i%2!=0:
                if "L"==S[i-1]:
                        flg = 1
                        break
        elif i%2==0:
                if "R"==S[i-1]:
                        flg = 1
                        break



if flg == 0:
        print("Yes")
else:
        print("No")

Measured memory_bytes: 3060
#include <iostream>
#include <iomanip>
#include<math.h>
#include<list>
#include <algorithm>
#include<set>
#include<vector>
#include<math.h>
#include<map>
#include<string>
#include <numeric>
#include <queue>
#include <sstream>
#include <bitset>
#include<stack>

using namespace std;
using ll = long long;
using vll = vector<long long>;
using sll = set<long long>;

template<typename T>
T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template<typename T>
T lcm(T a, T b) { return a / gcd(a, b) * b; }

template<typename T>
map<T, T> getPrimeFactor(T n) {
	map<T, T> res;
	for (T i = 2; i * i <= n; ++i) {
		while (n % i == 0) {
			res[i] ++;
			n /= i;
		}
	}
	if (n != 1) res[n] = 1;
	return res;
}

template<typename T>
bool IsPrimeNumber(T num)
{
	if (num <= 2) return true;
	else if (num % 2 == 0) return false;

	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2)
	{
		if (num % i == 0)
		{
			return false;
		}
	}

	return true;
}

long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}

#define rep(i,s,e) for(ll i=s;i<e;i++)
#define repeq(i,s,e) for(ll i=s;i<=e;i++)


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

	ll cnt = 0;

	rep(i, 1, S.size()) {
		if (S[i] != S[i - 1]) {
			cnt++;
		}
	}
	cnt -= K + K;
	if (cnt > 0) {
		std::cout << S.size() - 1 - cnt << endl;
	}
	else {
		std::cout << S.size() - 1 << endl;
	}

	return 0;
}


Measured memory_bytes: 512
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();

    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n: u64 = read();
    let a: u64 = read();
    let b: u64 = read();

    if n <= a {
        println!("{}", n);
    }else if n <= a + b{
        println!("{}", a);
    }else{
        if a < n % (a + b) {
            println!("{}", (n / (a + b)) * a + a);
        }else{
            println!("{}", (n / (a + b)) * a + n % (a + b));
        }
    }



}


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

int n, m;
vector<vector<int>> adj;
vector<int> parent;
vector<bool> used;

int main() {
	int n, m;
	cin >> n >> m;
	parent = vector<int>(n, -1);
	adj = vector<vector<int>>(n);
    used = vector<bool>(n, false);

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

    queue<int> q;

    q.push(0);
    used[0] = true;
    while (!q.empty()) {
    	int v = q.front();
    	q.pop();

    	for (int u : adj[v]) {
    		if (used[u] == false) {
    			q.push(u);
    			used[u] = true;
    			parent[u] =  v;
    		}
    	}
    }

   
   for (int i = 1; i < n; i++) {
       if (parent[i] == -1) {
           cout << "No" << "\n";
           return 0;
       }
    }
	cout << "Yes" << "\n";
    for (int i = 1; i < n; i++) {
        cout << parent[i] + 1 << " "; 
    }
    return 0;

}

Measured memory_bytes: 10140
#include <cstdio>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int solve(int y, int m, int d)
{
    int ret = (y - 1) * 195;
    ret += (y - 1) / 3 * 5;

    ret += (m - 1) * 20;
    if(y % 3 != 0)
        ret -= (m - 1) / 2;

    ret += d;

    return ret;
}

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

    while(--n >= 0){
        int y, m, d;
        cin >> y >> m >> d;

        cout << (solve(1000, 1, 1) - solve(y, m, d)) << endl;
    }

    return 0;
}

Measured memory_bytes: 0
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Atc_0035
{
    class Program
    {
        static void Main(string[] args)
        {
            var s = Console.ReadLine();

            int K = int.Parse(s.Split(' ')[0]);
            int N = int.Parse(s.Split(' ')[1]);

            var det = Console.ReadLine().Split(' ').Select(int.Parse).ToList<int>();

            det.Sort();

            List<int> cc = new List<int>();

            for (int i = 0; i < det.Count() - 1; i++)
            {
                cc.Add(det[i + 1] - det[i]);
            }

            cc.Add(det[0] + (K - det[det.Count() - 1]));

            cc.Sort();

            cc.RemoveAt(cc.Count() - 1);

            Console.WriteLine(cc.Sum());

        }
    }
}


Measured memory_bytes: 45596
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<list>
#include<cstdint>
#include<bits/stdc++.h>
#include<queue>
#include<set>

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep_r(i, n) for(int i = n-1; i >= 0; i--)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((ll)(x).size())
#define bit(n) (1LL<<(n))
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define INF bit(60)
#define pb push_back
#define mod 1000000007

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

using namespace std;
using uif=uint_fast64_t;
using ll=long long int;

int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a%mod;a=1ll*a*a%mod;}while(b>>=1);return ans;}
int qp(int a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}

int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};


int main(void){

  int a,b,c;
  cin>>a>>b>>c;
  
cout << min({a+b,b+c,c+a}) << endl;

  return 0;

}


Measured memory_bytes: 256
#include<iostream>
#include<string>

using namespace std;

int field[16][16]={0},path[16][16]={0};
const int LEFT=1,UP=2;
/*
path[a][b]&LEFT==0???[a][b]??????????????????????????????
path[a][b]&LEFT!=0???[a][b]??????????????????????????????
path[a][b]&UP==0???[a][b]??????????????????????????????
path[a][b]&UP!=0???[a][b]??????????????????????????????
*/

using namespace std;

int main(){
	int n=0;
	cin>>n;
	while(n-->0){
		for(int i=0;i<16;i++){
			for(int j=0;j<16;j++){
				field[i][j]=0;
				path[i][j]=0;
			}
		}
		field[0][0]=1;
		for(int i=0;i<16;i++){
			path[0][i]|=LEFT;
			path[i][0]|=UP;
			//??????????????????????????????????????????????????????????????????????????????????????????????????¨??????????????¨??§?????????????????????????°???\?????????
		}
		int gx=0,gy=0,p=0;
		cin>>gx>>gy>>p;
		while(p-->0){
			int x1=0,y1=0,x2=0,y2=0;
			cin>>x1>>y1>>x2>>y2;
			if(x1==x2){
				path[x1][y1>y2?y1:y2]|=UP;
			}
			if(y1==y2){
				path[x1>x2?x1:x2][y1]|=LEFT;
			}
		}
		for(int i=0;i<=gx;i++){
			for(int j=0;j<=gy;j++){
				if((path[i][j]&LEFT)==0){field[i][j]+=field[i-1][j];}
				if((path[i][j]&UP)==0){field[i][j]+=field[i][j-1];}
			}
		}
		if(field[gx][gy]){cout<<field[gx][gy]<<endl;}
		else{cout<<"Miserable Hokusai!"<<endl;}
	}
	return 0;
}

Measured memory_bytes: 1160
#include<iostream>
#include<algorithm>
#include<cstring>
#include<stdio.h>
#include<cstdio>
#include<string.h>
#include<cmath>
using namespace std;
bool prime(int n) {
	if (n == 1)return false;
	if (n == 2)return true;
	if (n == 3)return true;
	if (n == 4)return false;
	for (int i = 2; i < ceil(sqrt(n)); i++) {
		if (n % i == 0) {
			return false;
		}
	}
	return true;
}
int lst[110];
int main() {
	int n,x,rec;
	cin >> n>>x;
	long long sum=0;
	int ans = 0;
	for (int i = 0; i < n; i++) {
		cin >> lst[i];
	}
	sort(lst, lst + n);
	for (int i = 0; i < n; i++) {
		sum += lst[i];
		if (sum <= x)ans++;
		else break;
	}
	if (sum < x) {
		cout << ans - 1 << endl;
	}
	else cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3604
#!/usr/bin/env python3
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


def sum_of_arithmetic_progression(s, d, n):
    return n * (2 * s + (n - 1) * d) // 2


def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)


def lcm(a, b):
    g = gcd(a, b)
    return a / g * b


def solve(N, K, H):
    ans = 0
    for i in range(N):
        ans += H[i] >= K
    return ans


def main():
    N, K = map(int, input().split())
    H = list(map(int, input().split()))

    print(solve(N, K, H))


if __name__ == '__main__':
    main()


Measured memory_bytes: 12776
#include<stdio.h>
int main(){
	int s, hours, minutes, seconds;
	scanf("%d", &s);
	hours = s / 3600;
	minutes = s % 3600 / 60;
	seconds = s % 3600 % 60;
	printf("%d:%d:%d\n", hours, minutes, seconds);
	return 0;
}

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

int main()
{
    int N, K;
    cin >> N >> K;
    vector<int> X(N);
    vector<int> costs;

    rep(i, N)
    {
        cin >> X[i];
    }

    rep(i, N - K + 1)
    {
        int left = X[i];
        int right = X[i + K - 1];

        if (left <= 0 && right <= 0)
        {
            costs.push_back(-1 * left);
        }
        else if (left <= 0 && right >= 0)
        {
            costs.push_back(-1 * left + right + min(-1 * left, right));
        }
        else
        {
            costs.push_back(right);
        }
    }

    sort(costs.begin(), costs.end());
    cout << costs.front() << endl;
}


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

char s[111];

int main(){
    scanf("%s", s);
    if (strlen(s)==2)
        printf("%s", s);
    else {
        for(int i=2; i>=0; i--)
            printf("%c", s[i]);
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
string ALP = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
string alp = "abcdefghijklmnopqrstuvwxyz";
vi d1 = {1, 0, -1, 0}, d2 = {0, 1, 0, -1};
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}
void neg() {cout << -1 << endl;}

int main() {
  int n, d, x;
  cin >> n >> d >> x;
  vi a(n);
  for (int i = 0; i < n; i++) cin >> a.at(i);
  int sum = n;
  for (int i = 0; i < n; i++) {
    sum += (d - 1) / a.at(i);
  }
  cout << sum + x << endl;
}

Measured memory_bytes: 256
using System;

class Program {
	static void Main(string[] args){
		int M = 52;
		int N = 2503;
		long[,,] tb = new long[M,M,N];
		for(int i=0;i<M;i++){
			for(int j=0;j<M;j++){
				for(int k=0;k<N;k++){
					tb[i,j,k] = 0;
				}
			}
		}
		string[] str = Console.ReadLine().Split(' ');
		int  n = int.Parse(str[0]);
		long  a = long.Parse(str[1]);
		long[] x = new long[n];
		str = Console.ReadLine().Split(' ');
		for(int i=0;i<n;i++){
			x[i] = long.Parse(str[i]);
		}
		
		long ans = 0;
		for(int j=0;j<n+1;j++){
			for(int k=0;k<N;k++){
				tb[0,j,k] = 0;
			}
		}
		tb[0,0,0] = 1;
		for(int i=1;i<n+1;i++){
			for(int j=0;j<n+1;j++){
				for(int k=0;k<N;k++){
					tb[i,j,k] = tb[i-1,j,k];
					if(k-x[i-1]>=0 && j>0) tb[i,j,k] += tb[i-1,j-1,k-x[i-1]];
				}
			}
		}
		for(int i=1;i<n+1;i++) ans += tb[n,i,i*a];
		Console.WriteLine(ans);
	}
}

Measured memory_bytes: 55640
// E - Colorful Hats 2
#include <bits/stdc++.h>

using namespace std;

#define	MOD	1000000007

int main(int argc, char *argv[])
{
	ios::sync_with_stdio(false); cin.tie(0);
	int n;
	cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; i++) cin >> a[i];
	vector<long long> dp(n), c(n);
	for (int i = 0; i < n; i++) {
		int x = a[i];
		dp[i] = (i == 0 ? 1LL : dp[i - 1]) * ((x == 0 ? 3LL : c[x - 1]) - c[x]) % MOD;
		c[x]++;
	}

	cout << dp[n - 1] << endl;

	return 0;
}


Measured memory_bytes: 2176
#include<stdio.h>

int n,A[50];

int solve(int i,int m){
	if(m==0)
		return 1;
	if(i>=n)
		return 0;
	int res=solve(i+1,m) || solve(i+1,m-A[i]);
	return res;
}
int main(){
	int q,M,i;

	scanf("%d",&n);
	for(i=0;i<n;i++)
		scanf("%d",&A[i]);
	scanf("%d",&q);
	for(i=0;i<q;i++){
		scanf("%d",&M);
		if(solve(0,M))
			printf("yes\n");
		else
			printf("no\n");
	}

	return 0;
}

Measured memory_bytes: 580
#!/usr/bin/env ruby
_n, m, q = gets.chomp.split.map(&:to_i)


a = []
b = []
c = []
d = []

1.upto(q) do |i|
  input = gets.chomp.split.map(&:to_i)
  a << input[0]
  b << input[1]
  c << input[2]
  d << input[3]
end

ans = 0

1.upto(m) do |i_1|
  a_1 = i_1
  i_1.upto(m) do |i_2|
    a_2 = i_2
    i_2.upto(m) do |i_3|
      a_3 = i_3
      i_3.upto(m) do |i_4|
        a_4 = i_4
        i_4.upto(m) do |i_5|
          a_5 = i_5
          i_5.upto(m) do |i_6|
            a_6 = i_6
            i_6.upto(m) do |i_7|
              a_7 = i_7
              i_7.upto(m) do |i_8|
                a_8 = i_8
                i_8.upto(m) do |i_9|
                  a_9 = i_9
                  i_9.upto(m) do |i_10|
                    a_10 = i_10

                    arr = [nil, a_1, a_2, a_3, a_4, a_5, a_6, a_7, a_8, a_9, a_10]
                    score = 0
                    a.each_with_index do |a_i, i|
                      score += d[i] if arr[b[i]] - arr[a_i] == c[i]
                    end
                    ans = [score, ans].max
                  end
                end
              end
            end
          end
        end
      end
    end
  end
end

puts ans


Measured memory_bytes: 14368
#include <bits/stdc++.h>
#include <string>
#include <algorithm>
#include <string.h>
#include <ctype.h>
#include <math.h>
#include <float.h>
#include <iomanip>
#include <iostream>
using namespace std;
 
int gcd(int x,int y){
    if(y==0)return x;

    return gcd(y,x%y);
}
int lcm(int x,int y){
    return x*y/gcd(x,y);
}

int main(){

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

    if(a==b&&b==c){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }

    return 0;
}

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

//#define int long long
struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);}} fast;

/* cpp template {{{ */

/* short */
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define X real()
#define Y imag()

/* REPmacro */
#define REPS(i, a, n) for (ll i = (a); i < (ll)(n); ++i)
#define rep(i, n) REPS(i, 0, n)
#define REP0(i,n) for (ll i = 0; i <= (ll)(n); ++i)
#define REP1(i,n) for (ll i = 1; i <= (ll)(n); ++i)
#define RREP(i, n) REPS(i, 1, n + 1)
#define DEPS(i, a, n) for (ll i = (a); i >= (ll)(n); --i)
#define DEP(i, n) DEPS(i, n, 0)
#define EACH(i, n) for (auto&& i : n)

/* debug */
#define debug(x) cerr << x << " " << "(L:" << __LINE__ << ")" << '\n';

/* alias */
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using pii = pair<int, int>;
using D = double;
using P = complex<D>;
using vs = vector<string>;
template <typename T> using PQ = priority_queue<T>;
template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

/* const */
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7;
const D EPS = 1e-9;
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

/* func */
inline bool inside(int y, int x, int H, int W) {return y >= 0 && x >= 0 && y < H && x < W;}
inline int in() {int x; cin >> x; return x;}
inline ll IN() {ll x; cin >> x; return x;}
inline vs split(const string& t, char c) {vs v; stringstream s(t); string b; while(getline(s, b, c)) v.eb(b); return v;}
template <typename T> inline bool chmin(T& a, const T& b) {if (a > b) a = b; return a > b;}
template <typename T> inline bool chmax(T& a, const T& b) {if (a < b) a = b; return a < b;}
template <typename T, typename S> inline void print(const pair<T, S>& p) {cout << p.first << " " << p.second << endl;}
template <typename T> inline void print(const T& x) {cout << x << '\n';}
template <typename T, typename S> inline void print(const vector<pair<T, S>>& v) {for (auto&& p : v) print(p);}
template <typename T> inline void print(const vector<T>& v, string s = " ") {rep(i, v.size()) cout << v[i] << (i != (ll)v.size() - 1 ? s : "\n");}
template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
  for(T& x: vec) is >> x;
  //for(int i=0; i<vec.size(); i++) is >> x[i]; とかでもいいです。
  return is;
}
template<typename T>
ostream& operator << (ostream& os, vector<T>& vec){
  for(int i=0; i<vec.size(); i++){
    os << vec[i] << ( i+1 == vec.size() ? "" : " " );
  }
  return os;
}
/* }}} */
signed main() 
{
  string s;
  cin >> s;
  int ans;
  rep(i,s.length())
  {
    int len=s.length()-1-i;
    if(len%2==1) continue;
    else 
    {
      if(s.substr(0,len/2-1)==s.substr(len/2,len/2-1)) 
      {
        ans=len;
        break;
      }
    }
  }
  print(ans);

  return 0;
}

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

int main() {
  int a, b;
  cin >> a;

  if (( a / 1000 == (a % 1000) / 100 ) && ( a / 1000 == (a % 100) / 10 )) {
    cout << "Yes" << endl;
  } else {
    if (( (a % 1000) / 100 == (a % 100) / 10 ) && ( (a % 1000) / 100 == (a % 10)  )) {
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
  }
 
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, b;
  cin >> a >> b;
  int c = a;
  vector<string> v(a);
  for (int i = 0; i < a; i++) cin >> v.at(i);
  for (int i = 0; i < c;) {
    bool flag = true;
    char k = v.at(i)[0];
    for (int j = 0; j < b; j++) {
      if (k != v.at(i)[j] || v.at(i)[j] == '#') flag = false;
    }
    if (flag) {
      v.erase(v.begin() + i);
      c--;
    }
    else i++;
  }
  
  for (int i = b - 1; i >= 0; i--) {
    bool flag = true;
    char k = v.at(0)[i];
    for (int j = 0; j < c; j++) {
      if (k != v.at(j)[i] || v.at(j)[i] == '#') flag = false;
    }
    if (flag) {
      for (int q = 0; q < c; q++) v.at(q).erase(v.at(q).begin() + i);
    }
  }
  
  for (int i = 0; i < c; i++) cout << v.at(i) << endl;
}

Measured memory_bytes: 256
#include <cmath>
#include <iostream>
#include <vector>

#define MAXN 5005
#define K 15

using namespace std;
typedef long long ll;
const ll LO = -1e16;
int n, k;

ll st[MAXN * 2][K];

ll query(int l, int r) {
    int len = r - l + 1;
    int j = log2(len);
    return min(st[l][j], st[r - (1 << j) + 1][j]);
}

ll solve(vector<int> &v) {
    int len = v.size();
    vector<ll> s = {0};
    for (int i = 0; i < 2 * len; ++i)
        s.emplace_back(s.back() + v[i % len]);
    int slen = s.size();
    for (int i = 0; i < slen; ++i)
        st[i][0] = s[i];
    for (int j = 1; j <= log2(slen); ++j)
        for (int i = 0; i < slen; ++i) {
            st[i][j] = st[i][j - 1];
            int right = i + (1 << (j - 1));
            if (right < slen)
                st[i][j] = min(st[i][j], st[right][j - 1]);
        }
    ll sum = s[len], hi_r = LO, hi_all = LO;
    int r = k % len;
    for (int i = 1; i < slen; ++i) {
        if (r)
            hi_r = max(hi_r, s[i] - query(max(0, i - r), i - 1));
        hi_all = max(hi_all, s[i] - query(max(0, i - len), i - 1));
    }
    if (k < len)
        return hi_r;
    return max(hi_all, max(sum * (k / len - 1) + hi_all, sum * (k / len) + hi_r));
}

int main() {
    cin >> n >> k;
    vector<int> p(n), c(n);
    for (int i = 0; i < n; ++i)
        cin >> p[i];
    for (int i = 0; i < n; ++i)
        cin >> c[i];
    ll ans = LO;
    vector<bool> vis(n);
    for (int i = 0; i < n; ++i) {
        if (vis[i])
            continue;
        vector<int> v;
        int idx = i;
        while (!vis[p[idx] - 1]) {
            idx = p[idx] - 1;
            vis[idx] = true;
            v.emplace_back(c[idx]);
        }
        ans = max(ans, solve(v));
    }
    cout << ans;
}


Measured memory_bytes: 5208
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#define IOS ios::sync_with_stdio(false)
using namespace std;
#define inf (0x3f3f3f3f)
typedef long long int LL;

#include <iostream>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>

const int maxn = 1e5 + 20;
char str[maxn];
int dp[maxn][2];
void work() {
    memset(dp, 0x3f, sizeof dp);
    cin >> str + 1;
    int lenstr = strlen(str + 1);
    for (int i = 1; i <= lenstr; ++i) {
        if (str[i] == str[i - 1]) {
            dp[i][0] = dp[i - 1][0];
            dp[i][1] = dp[i - 1][1];
        } else {
            for (int j = i + 1; j <= lenstr; ++j) {
                if (str[j] != str[i]) {
                    dp[i][1] = j;
                    break;
                }
            }
            for (int j = i + 1; j <= lenstr; ++j) {
                if (str[j] == str[i]) {
                    dp[i][0] = j;
                    break;
                }
            }
        }
    }
    int ans = 0;
    int now = 1;
    for (int i = 1; i <= lenstr; ) {
        i = dp[i][now];
        if (i > lenstr) break;
        ans++;
//        now = !now;
    }
    cout << ans << endl;
}

int main() {
#ifdef local
    freopen("data.txt","r",stdin);
#endif
    work();
    return 0;
}


Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
int h,w;
vector<string> s(1024);
queue<pair<int,int>> calc(queue<pair<int,int>> que){
  int n=que.size();
  for(int _=0;_<n;_++){
    pair<int,int> p=que.front();
    que.pop();
    if(s[p.first][p.second]!='#') continue;
    s[p.first][p.second]='x';
    if(p.first>0){if(s[p.first-1][p.second]=='.')que.push(make_pair(p.first-1,p.second));}
    if(p.first<h-1){if(s[p.first+1][p.second]=='.')que.push(make_pair(p.first+1,p.second));}
    if(p.second>0){if(s[p.first][p.second-1]=='.')que.push(make_pair(p.first,p.second-1));}
    if(p.second<w-1){if(s[p.first][p.second+1]=='.')que.push(make_pair(p.first,p.second+1));}     
  }
  n=que.size();
  for(int _=0;_<n;_++){
    pair<int,int> p=que.front();
    que.pop();
    s[p.first][p.second]='#';
    que.push(p);
  }
  return que;
}
int main(){
  cin>>h>>w;
  for(int i=0;i<h;i++)cin>>s[i];
  queue<pair<int,int>> que;
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++) if(s[i][j]=='#') que.push(make_pair(i,j));
  }
  int ans=0;
  while(!que.empty()){
    ans++;
    que=calc(que);
  }
  cout<<ans-1<<endl;
}

Measured memory_bytes: 17680
#include<iostream>
#include<algorithm>
#include<cstdint>

int const MAXN = 1e5;
int N;
int64_t M, A[MAXN], sum[MAXN+1];

int64_t count(int th) {
  int64_t c = 0;
  int j = N-1;
  for(int i = 0; i < N; ++i) {
    if(A[i]*2 < th) break;
    while(j > i && A[i]+A[j] < th) --j;
    ++j;
    c += (int64_t)(j-i)*2-1;
    j = std::min(j, N-1);
  }
  return c;
}

int64_t calc(int th) {
  int64_t res = 0;
  int j = N-1;
  for(int i = 0; i < N; ++i) {
    if(A[i]*2 < th) break;
    while(j > i && A[i]+A[j] < th) --j;
    ++j;
    res += (sum[j-1] - sum[i] + (j-i)*A[i])*2;
    j = std::min(j, N-1);
  }
  return res;
}

int main() {
  std::cin >> N >> M;
  for(int i = 0; i < N; ++i) std::cin >> A[i];
  std::sort(A, A+N, [](int l, int r){ return l > r; });
  // 
  int ok = A[N-1]*2, ng = A[0]*2+1;
  while(ng - ok > 1) {
    int mid = (ng + ok)/2;
    if(count(mid) >= M) ok = mid;
    else ng = mid;
  }
  sum[0] = A[0];
  for(int i = 1; i < N; ++i) sum[i] = sum[i-1]+A[i];
  int64_t ans =  calc(ok) - (count(ok) - M)*ok;
  std::cout << ans << std::endl;
  return 0;
}



Measured memory_bytes: 1792
void main() {
  problem();
}

void problem() {
  const N = scan!ulong;
  const K = scan!int;
  const steps = K.iota.map!(x => [scan!ulong, 1 + scan!ulong]).array;
  steps.deb;

  ulong solve() {
    ulong ans;
    auto dp = new ulong[N + 1];
    dp[N - 1] = 1;

    auto acc = new ulong[2 * N + 2];
    acc[N - 1] = 1;

    foreach_reverse(i; 0..N-1) {
      ulong cur = 0;

      foreach(s; steps) {
        const l = i + s[0];
        const r = i + s[1];

        const t = (acc[r] > acc[l] ? MOD : 0) + acc[l] - acc[r];
        cur += t;
        cur %= MOD;
      }

      dp[i] = cur;
      acc[i] = (cur + acc[i + 1]) % MOD;
    }

    dp.deb;
    return dp[0];
  }

  solve().writeln;
}

// ----------------------------------------------

import std.stdio, std.conv, std.array, std.string, std.algorithm, std.container, std.range, core.stdc.stdlib, std.math, std.typecons, std.numeric;
T[][] combinations(T)(T[] s, in int m) {   if (!m) return [[]];   if (s.empty) return [];   return s[1 .. $].combinations(m - 1).map!(x => s[0] ~ x).array ~ s[1 .. $].combinations(m); }
string scan(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
T scan(T)(){ return scan.to!T; }
T[] scan(T)(int n){ return n.iota.map!(i => scan!T()).array; }
void deb(T ...)(T t){ debug writeln(t); }
alias Point = Tuple!(long, "x", long, "y");
const MOD = 998244353;

// -----------------------------------------------


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

#define int long long
#define uint unsigned int
#define pii pair<int, int>
#define fi first
#define se second

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FORR(i, a, b) for (int i = (a); i >= (b); --i)
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) FORR(i, n, 0)
#define ALL(a) (a).begin(), (a).end()
#define SZ(a) ((int)(a).size())

#define PF(a) push_front(a)
#define PB(a) push_back(a)
#define EMPF(...) emplace_front(__VA_ARGS__)
#define EMPB(...) emplace_back(__VA_ARGS__)
#define EMP(...) emplace(__VA_ARGS__)
#define MP(a, b) make_pair(a, b)
#define MT(...) make_tuple(__VA_ARGS__)

#define ZERO(a) memset(a, 0, sizeof(a))
#define MINUS(a) memset(a, -1, sizeof(a))

#define PW(n) (1LL << (n))
#define NUM(x) char(x + '0')
#define ALP(x) char(x + 'a')

using namespace std;

template <class T> inline bool CHMIN(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template <class T> inline bool CHMAX(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> inline void SORT(T &a) { sort(a.begin(), a.end()); }
template <class T> inline void REV(T &a) { reverse(a.begin(), a.end()); }
template <class T> inline void UNIQUE(T &a) { sort(a.begin(), a.end()); a.erase(unique(a.begin(), a.end()), a.end()); }

template <class S, class T> ostream& operator << (ostream& os, const pair<S, T> v) {
  os << "(" << v.first << ", " << v.second << ")"; return os;
}

const int MOD = 1000000007;
const int INF = 1LL << 30;
const double EPS = 1e-10;

/* ---------------------------------------------------------------------------------------------------- */



signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  int N; cin >> N;
  vector<int> A(N), B(N);
  int sa = 0, sb = 0;
  REP(i, N) cin >> A[i], sa += A[i];
  REP(i, N) cin >> B[i], sb += B[i];
  if (sa < sb) {
    cout << -1 << endl;
    return 0;
  }
  int ans = 0;
  int sum = 0;
  vector<int> w;
  REP(i, N) {
    if (A[i] < B[i]) ans++, sum += B[i]-A[i];
    else w.PB(A[i]-B[i]);
  }
  if (ans == 0) {
    cout << 0 << endl;
    return 0;
  }
  SORT(w); REV(w);
  int tmp = 0;
  REP(i, SZ(w)) {
    ans++;
    tmp += w[i];
    if (tmp >= sum) break;
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 2936
#include <bits/stdc++.h>
#define rep(i, n) for(int i= 0; i < (n); i++)
using ll= long long int;
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
ll mod= 1e9 + 7;

ll dp[10101][101][2]={};//左からの桁数、modD,数値未満かどうか

int main(){
  string k;
  int D,n;
  cin >>k;
  cin >>D;
  n=k.size();
  dp[0][0][0]=1;

  rep(dgt,n){
    rep(d,D){
      rep(less,2){
        int c=k[dgt]-'0';
        rep(nxt,10){
          if (nxt < c) dp[dgt + 1][(d + nxt) % D][1] += dp[dgt][d][less]%mod;
          else if(nxt == c) dp[dgt + 1][(d + nxt) % D][less] += dp[dgt][d][less]%mod;
          else {
            if(less) dp[dgt + 1][(d + nxt) % D][less] += dp[dgt][d][less]%mod;
          }
        }
      }
    }
  }

  cout << (dp[n][0][0]+dp[n][0][1]-1)%mod << endl;
}

Measured memory_bytes: 19376
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {
		String A = sc.next();
		String B = sc.next();
		int N = A.length();
		int[] as = new int[N];
		int[] bs = new int[N];
		for (int i = 0; i < N; ++i) {
			as[i] = A.charAt(i) - '0';
		}
		for (int i = 0; i < B.length(); ++i) {
			bs[N - B.length() + i] = B.charAt(i) - '0';
		}
		int K = sc.nextInt();
		int[][][] dp = new int[N + 1][K + 1][2];
		for (int[][] aa : dp) {
			for (int[] a : aa) {
				Arrays.fill(a, Integer.MIN_VALUE);
			}
		}
		int base = 1;
		dp[0][0][0] = 0;
		for (int i = 1; i <= N; ++i, base *= 10) {
			if (as[N - i] >= bs[N - i]) {
				for (int j = 0; j <= K; ++j) {
					dp[i][j][0] = Math.max(dp[i][j][0], dp[i - 1][j][0] + base * (as[N - i] - bs[N - i]));
				}
			} else {
				for (int j = 0; j <= K; ++j) {
					dp[i][j][1] = Math.max(dp[i][j][1], dp[i - 1][j][0] + base * (10 + as[N - i] - bs[N - i]));
					if (j != 0) {
						dp[i][j][0] = Math.max(dp[i][j][0], dp[i - 1][j - 1][0] + base * (10 + as[N - i] - bs[N - i]));
					}
				}
			}
			if (as[N - i] - 1 >= bs[N - i]) {
				for (int j = 0; j <= K; ++j) {
					dp[i][j][0] = Math.max(dp[i][j][0], dp[i - 1][j][1] + base * (as[N - i] - 1 - bs[N - i]));
				}
			} else {
				for (int j = 0; j <= K; ++j) {
					dp[i][j][1] = Math.max(dp[i][j][1], dp[i - 1][j][1] + base * (10 + as[N - i] - 1 - bs[N - i]));
					if (j != 0) {
						dp[i][j][0] = Math.max(dp[i][j][0], dp[i - 1][j - 1][1] + base * (10 + as[N - i] - 1 - bs[N - i]));
					}
				}
			}
		}
		int ans = 0;
		for (int i = 0; i <= K; ++i) {
			ans = Math.max(ans, dp[N][i][0]);
			ans = Math.max(ans, dp[N][i][1]);
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 12000
import math
def py():
    print("Yes")
def pn():
    print("No")
def iin():
    x = int(input())
    return x

neko = 0
nya = 0
n,m,c = map(int,input().split())
b = [int(x) for x in input().split()]
a = []
for i in range(n):
    a.append([int(x) for x in input().split()])
for i in range(n):
    for j in range(m):
        neko = neko + (a[i][j] * b[j])
    neko = neko + c
    if neko > 0:
        nya = nya + 1
    neko = 0
print(nya)

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

ll pow5(int n){
	return (ll)n*n*n*n*n;
}

int main(){
	ll x;
	cin >> x;
	for(int i = -1000; i<= 1000; i++){
		for(int j = -1000; j<= 1000; j++){
			if(pow5(i) - pow5(j) == x){
				cout << i << " " << j;
				return 0;
			}
		}
	}
	return 0;
} 

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

int main(){
    int n,b,f,r,v; 
    int house[4][3][10];
    
    for (int i = 0; i < 4; i++) {
        for (int j = 0; j < 3; j++) {
            for (int k = 0; k < 10; k++){
                house[i][j][k] = 0;
            }
        }
    }
    
    cin >> n;
    for (int x = 0 ; x < n; x++) {
        cin >> b >> f >> r >> v;
        
        house[b-1][f-1][r-1] += v;
        
    }  
    
    for (int i = 0; i < 4; i++) {
        if(i > 0) {
         for (int m = 0; m < 20; m++) {
             cout << "#";
         }
            cout << "\n";
        }
        for (int b = 0; b < 3; b++) {
            for (int r = 0; r < 10; r++){
                cout << " " << house[i][b][r];
            }
            cout << endl;
        }
        
    }
    
   
    return 0;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double dd;
const int N = 5e5+5;
const dd eps = 1e-5;
const ll mod = 1e9+7;

int a[1000],n;

int main(){
  // freopen("input.txt","r",stdin);
  cin>>n;
  for(int i = 1;i <= n;i++) cin>>a[i];
  for(int i = 1;i <= n;i++){
    if(a[i]&1) continue;
    if(a[i]%5 == 0 || a[i]%3 == 0) continue;
    cout<<"DENIED"<<endl;
    return 0;
  }
  cout<<"APPROVED"<<endl;
  return 0;
}


Measured memory_bytes: 256