akhauriyash/Code-Regression huggingface dataset:
let () =
    let main () =
        let n, a, b, c, d = Scanf.sscanf (read_line ()) "%d %d %d %d %d" (fun n a b c d -> n, a, b, c, d) in
        let s = read_line () in
        let reachable a b =
            let rec loop i prev =
                if i = b then true else
                    if s.[i - 1] = '.' then loop (i + 1) false else
                        if prev then false else loop (i + 1) true
            in
            loop a false
        in
        let three_space a b c d =
            let rec loop i =
                if i + 2 > c then 0 else
                    if s.[i - 1] = '.' && s.[i] = '.' && s.[i + 1] = '.' then i else
                        loop (i + 1)
            in
            let r = loop (b - 1) in
            if r = 0 || r + 1 > d then false else
                reachable b (r + 1) && reachable (r + 1) d &&
                reachable a r && reachable (r + 2) c
        in
        let flag =
            if c < d then reachable a c && reachable b d else
                three_space a b c d
        in
        Printf.printf "%s\n" (if flag then "Yes" else "No")
    in
    main ()

Measured memory_bytes: 2688
#include<iostream>
#define ll long long int 
using namespace std;
int n;
ll t[1000],dp[1000][1000];
ll func(int now,ll sum){
	if(dp[now][sum]!=-1)
	return dp[now][sum];
	if(sum<0||sum>20)
	return 0;
	if(now==n-1){
		if(sum==t[n-1])
		return dp[now][sum]=1;
		return dp[now][sum]=0;
	}
	ll pre=0;
	pre+=func(now+1,sum+t[now]);
	pre+=func(now+1,sum-t[now]);
	return dp[now][sum]=pre;
}
int main(){
	cin>>n;
	for(int i=0;i<n;i++){
		for(int j=0;j<=1000;j++)
		dp[i][j]=-1;
	cin>>t[i];
	}
	func(1,t[0]);
	cout<<dp[1][t[0]]<<endl;
	return 0;
}

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

int main(){
    string s;
    cin >> s;
    if (s == "AKIHABARA") cout << "YES" << endl;
    else if (s == "AKIHABAR") cout << "YES" << endl;
    else if (s == "AKIHABRA") cout << "YES" << endl;
    else if (s == "AKIHBARA") cout << "YES" << endl;
    else if (s == "KIHABARA") cout << "YES" << endl;
    else if (s == "AKIHABR") cout << "YES" << endl;
    else if (s == "AKIHBAR") cout << "YES" << endl;
    else if (s == "KIHABAR") cout << "YES" << endl;
    else if (s == "AKIHBRA") cout << "YES" << endl;
    else if (s == "KIHBARA") cout << "YES" << endl;
    else if (s == "KIHABRA") cout << "YES" << endl;
    else if (s == "AKIHBR") cout << "YES" << endl;
    else if (s == "KIHABR") cout << "YES" << endl;
    else if (s == "KIHBAR") cout << "YES" << endl;
    else if (s == "KIHBRA") cout << "YES" << endl;
    else if (s == "KIHBR") cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}

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

int main(){
    int a,b,c,k;
    cin >>a>>b>>c>>k;
    int sum=0;

    if(a>b && a>c)sum=a*pow(2,k)+b+c;
    else if(b>c){
        sum=a+b*pow(2,k)+c;
    }
    else{
        sum=a+c*pow(2,k)+b;
    }
    cout<<sum;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef vector<vector<int>> v2int;
typedef vector<ll> vll;
typedef vector<vector<ll>> v2ll;
typedef list<int> liint;
typedef pair<int, int> pint;
const int INF = int(2e9);
const ll LINF = ll(2e9) * ll(2e9);
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b) { a > b ? : a = b; }
template<class T, class C> void chmin(T& a, C b) { a < b ? : a = b; }



int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int N;
    cin >> N;
    string S;
    cin >> S;

    ll ans = 0;
    unordered_map<char, set<int>> cnt;
    rep(i, N) {
        cnt[S[i]].insert(i);
    }

    for (auto& i : cnt['R']) {
        for (auto& j : cnt['G']) {
            //if (i >= j) continue;
            int new_i = i, new_j = j;
            if (i > j) {
                int tmp = new_i;
                new_i = j;
                new_j = tmp;
            }
            int k = 2* new_j - new_i;
            ll add = ll(cnt['B'].size());

            if ((new_i + new_j) % 2 == 0 && cnt['B'].count((new_i + new_j)/2) > 0) {
                add--;
            }
            if (cnt['B'].count(new_j + (new_j - new_i)) > 0){
                add--;
            }
            if (cnt['B'].count(new_i - (new_j - new_i)) > 0) {
                add--;
            }
            ans += add;
        }
    }

    cout << ans << endl;
    return 0;
}

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

int n, m, a[100][100];
int k[100], p[100];
bool state[100];

bool cek(){
	for(int i = 0; i < m; ++i){
		int tmp = 0;
		for(int j = 0; j < k[i]; ++j){
			tmp += state[a[i][j]];
		}
		//printf("[%d]", tmp);
		if((tmp%2) != (p[i]%2)){
			//printf("\n");
			return false;
		}
	}
	return true;
}

int bf(int pos){
	if(pos == n){
		// Check
		//for(int i = 1; i <= n; ++i) printf("(%d)", state[i]); printf("\n");
		return cek();
	}else{
		int tmpAns = 0;
		state[pos+1] = 0;
		tmpAns += bf(pos+1);
		state[pos+1] = 1;
		tmpAns += bf(pos+1);
		return tmpAns;
	}
}

int main(){
	scanf("%d %d", &n, &m);
	for(int i = 0; i < m; ++i){
		scanf("%d", &k[i]);
		for(int j = 0; j < k[i]; ++j){
			scanf("%d", &a[i][j]);
		}
	}
	for(int i = 0; i < m; ++i){
		scanf("%d", &p[i]);
	}
	printf("%d\n", bf(0));
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long int dp[100000];
int bottomupdp(long long int a[],int n,int k)
{
	dp[0]=0;
	int i,j;
	dp[1]=0;
	for(i=2;i<=n;i++)
	{
		dp[i]=INT_MAX;
		for(j=1;j<=k;j++)
		{
			if(i-j>0)
			dp[i]=min(dp[i-j]+abs(a[i-1]-a[i-j-1]),dp[i]);
		}
	}
	return dp[n];
}
int main()
{
	memset(dp,0,sizeof(dp));
	int n,k;
	cin>>n>>k;
	long long int a[n];
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
	}
	cout<<bottomupdp(a,n,k);
}

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

using namespace std ;

int a[210000] ;

int main() {
	int n;
	long long sum1 = 0 , sum2 = 0 , ans =numeric_limits<long long>::max() ;
	scanf("%d" , &n) ;
	for(int i = 0 ;i<n ; i++){
		scanf("%d" , a+i) ;
		sum2+=a[i] ;
	}
	
	for(int i = 0 ; i<n-1 ;i++) {
		sum2-=a[i]  , sum1+=a[i] ;
		if(abs(sum2-sum1) <ans) ans = abs(sum2-sum1) ;
	}
	cout << ans << endl ;
}

Measured memory_bytes: 1024
#include<cstdio>
#include<vector>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
const int INF=1000000007;
int f[101010],s[101010],a[101010],g[101010];
int ksm(int w,int x)
{
	int ans=1;
	while(x)
	{
		if(x&1)
			ans=(long long)ans*w%INF;
		x/=2;
		w=(long long)w*w%INF; 
	}
	return ans;
}
int main()
{
	int n,i,ans;
	scanf("%d",&n);
	f[0]=1;
	for(i=1;i<=n;i++)
		f[i]=(long long)f[i-1]*i%INF;
	for(i=1;i<=n;i++)
		scanf("%d",&a[i]);
	g[0]=0;
	for(i=1;i<=n;i++)
		g[i]=(g[i-1]+(long long)f[n]*ksm(i+1,INF-2)%INF)%INF;
	ans=0;
	for(i=1;i<=n;i++)
		ans=(ans+(long long)((long long)g[i-1]+g[n-i]+f[n])*a[i]%INF)%INF;
	printf("%d\n",ans);
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
 	return 0;
}


Measured memory_bytes: 1408
#include <iostream>

using namespace std;

int m,n;
int s;

int keiro(int g[][8],int past[],int now)
{
	int past2[8];
	int flag=0;
	for(int i=0;i<8;i++)
	{
		past2[i]=past[i];
	}
	past2[now]=1;
	for(int i=0;i<n;i++)
	{
		if(g[now][i]==1 && past2[i]==0)
		{
			s += keiro(g,past2,i);
		}
	}
	for(int i=0;i<n;i++)
	{
		if(past2[i]==0)
		{
			flag=1;
		}
	}
	if(flag==0)
	{
		return 1;
	}else{
		return 0;
	}
}

int main()
{
	int a[28];
	int b[28];
	int g[8][8];
	int past[8];
	s=0;
	cin >> n >> m;
	for(int i=0;i<8;i++)
	{
		past[i]=0;
		for(int j=0;j<8;j++)
		{
			g[i][j]=0;
		}
	}
	for(int i=0;i<m;i++)
	{
		cin >> a[i] >> b[i];
		g[a[i]-1][b[i]-1]=1;
		g[b[i]-1][a[i]-1]=1;
	}
	
	s += keiro(g,past,0);

	cout << s << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <random>
#include <cassert>
#include <numeric>
#define ll long long int
#define LL unsigned long long
#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
using namespace std;

int mx8[] = {0,0,1,-1,-1,1,-1,1};
int my8[] = {-1,1,0,0,-1,-1,1,1};
int mx4[] = {1,-1,0,0};
int my4[] = {0,0,-1,1};
const int MOD = 1000000007;

ll y[10000005];

int main() {
    ll n,k; cin >> n >> k;
    vector<pair<int,ll>> v(n);

    rep(i,n){
        cin >> v[i].first >> v[i].second;
    }
    sort(v.begin(),v.end());

    int i = 0;
    while(k>0){
        k -= v[i].second;
        i++;
    }
    cout << v[i-1].first << endl;
}


Measured memory_bytes: 4760
#include<bits/stdc++.h>
#define up(j,k,i) for(i=j;i<k;i++)
#define down(j,k,i) for(i=j;i>k;i--)
#define pp(n) printf("%lld\n",n)
#define pps(n) printf("%lld ",n)
#define all(x) x.begin(),x.end()
#define ps(s) printf("%s",s)
#define is(n) scanf("%lld",&n)
#define ips(n) scanf("%lld",n)
#define ss(s) scanf("%s",s)
#define cool 0
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define f(i) cout<<i<<endl;
#define pll pair<lld,lld> 
#define pi acos(-1)
#define isset(mask,bit) ((mask&(1LL<<bit))!=0)
#ifdef G
#define dg(x) cout<<#x<<' '<<x<<endl;
#define dg2(x,y) cout<<#x<<' '<<x<<' '<<#y<<' '<<y<<endl;
#define dg3(x,y,z) cout<<#x<<' '<<x<<' '<<#y<<' '<<y<<' '<<#z<<' '<<z<<endl;
#define dg4(x,y,z,zz) cout<<#x<<' '<<x<<' '<<#y<<' '<<y<<' '<<#z<<' '<<z<<' '<<#zz<<' '<<zz<<endl;
#else
#define dg(x) ;
#define dg2(x,y) ;
#define dg3(x,y,z) ;
#define dg4(x,y,z,zz) ;
#endif
#define ds(n,m) scanf("%lld %lld",&n,&m)
#define ts(n,m,k) scanf("%lld %lld %lld",&n,&m,&k)
#define yes printf("YES\n")
#define no printf("NO\n")
typedef long double ld;
typedef long long int lld;
using namespace std;
const lld M =2e5+10;
const lld mod=1e9+7;
const lld infi =LLONG_MAX;
lld ans,k,n,x,y,m,mymax=LLONG_MIN,mymin=LLONG_MAX,b,c,z,sum;
vector<lld> v[M];
lld cn1=0,cnt2=0;
int main()
{
  lld i,j;
  is(n);
  ds(b,c);
  up(1,n+1,i){
  	is(x);
  	if(x<=b){
  		cn1++;
  	}
  	else if(x<=c){
  		cnt2++;
  	}
  }
  pp(min(cn1,min(cnt2,n-cn1-cnt2)));
  return 0;
}

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

typedef long long ll;
typedef pair<int,int> P;
int dx[] = {-1, 1, 0,  0};
int dy[] = { 0, 0, 1, -1};
 
int main(){
  string n;
  cin >> n;
  int tmp = 0;
  string ans;
  for(int i=0; i<n.length(); i++){
    tmp += n[i]-'0';
  }
  int num = stoi(n);
  if(num%tmp==0) ans = "Yes";
  else ans = "No";
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <climits>
#include <set>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#define MAX 1000000007


using namespace std;
#define ll long long
#define dbg if(0)
#define ISRANGE(val,lo,hi) ((lo<=val)&&(val<hi))

int main(){
    ll ans=0,n,k;
    cin >>n;
    ans=((n-1)/111+1)*111;
    cout <<ans<<endl;

    return 0;

}


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

int main()
{
    double n,k,p=0;
    cin >> n >> k;
    double s=1/n;
    for(int j=1;j<=n;j++){
        if(k<=j){
        p+=s;
        continue;
        }
        int o=j;
        for(int i=1;;i++){
            o*=2;
            if(k<=o){
                p+=s*pow(0.5000000,i);
                break;
            }
        }
    }
    cout << fixed << setprecision(10) << p << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; --i)
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define FORR(i, a, b) for (int i = b - 1; i >= a; --i)
#define SORT(v) sort(v.begin(), v.end())
#define SORTR(v) sort(v.rbegin(), v.rend())
#define REV(v) reverse(v.begin(), v.end())
#define ITER(itr, v) for (auto itr = v.begin(); itr != v.end(); ++itr)
#define LB(v, x) (lower_bound(v.begin(), v.end(), x) - v.begin())
#define UB(v, x) (upper_bound(v.begin(), v.end(), x) - v.begin())
#define SZ(v) (int)v.size()
using namespace std;
using ll = long long;
using P = pair<int, int>;

vector<int> a;
vector<vector<int>> edge;
vector<int> dp;
vector<int> res;

void dfs(int i = 0, int p = -1) {
    int l = LB(dp, a[i]);
    int tmp = dp[l];
    dp[l] = a[i];
    res[i] = LB(dp, INT_MAX);
    for (auto &j : edge[i]) {
        if (j == p) continue;
        dfs(j, i);
    }
    dp[l] = tmp;
}

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

    int X, Y, Z, K;
    cin >> X >> Y >> Z >> K;
    vector<ll> A(X), B(Y), C(Z);
    REP(i, X) cin >> A[i];
    REP(i, Y) cin >> B[i];
    REP(i, Z) cin >> C[i];
    SORTR(A);
    SORTR(B);
    SORTR(C);
    using T = tuple<ll, int, int, int>;
    priority_queue<T> pq;
    set<T> st;
    pq.emplace(A[0] + B[0] + C[0], 0, 0, 0);
    st.emplace(A[0] + B[0] + C[0], 0, 0, 0);
    REP(x, K) {
        ll sum;
        int i, j, k;
        tie(sum, i, j, k) = pq.top();
        pq.pop();
        cout << A[i] + B[j] + C[k] << endl;
        if (i < X - 1 && !st.count(T(A[i + 1] + B[j] + C[k], i + 1, j, k))) {
            pq.emplace(A[i + 1] + B[j] + C[k], i + 1, j, k);
            st.insert(T(A[i + 1] + B[j] + C[k], i + 1, j, k));
        }
        if (j < Y - 1 && !st.count(T(A[i] + B[j + 1] + C[k], i, j + 1, k))) {
            pq.emplace(A[i] + B[j + 1] + C[k], i, j + 1, k);
            st.insert(T(A[i] + B[j + 1] + C[k], i, j + 1, k));
        }
        if (k < Z - 1 && !st.count(T(A[i] + B[j] + C[k + 1], i, j, k + 1))) {
            pq.emplace(A[i] + B[j] + C[k + 1], i, j, k + 1);
            st.insert(T(A[i] + B[j] + C[k + 1], i, j, k + 1));
        }
    }

    return 0;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define LLINF 100000000000000000ll
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define all(x) (x).begin(),(x).end()
#define sq(x) ((x)*(x))
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repn(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define EQ(a,b) (abs((a)-(b))<eps)
template<class T> void chmin(T& a,const T& b){if(a>b)a=b;}
template<class T> void chmax(T& a,const T& b){if(a<b)a=b;}
int N,K,Q;
int A[2010];
vector<int> v;
int main(){
	scanf("%d %d %d",&N,&K,&Q);
	for(int i=0;i<N;i++){
		scanf("%d",&A[i]);
		v.pb(A[i]);
	}
	sort(all(v));
	v.erase(unique(all(v)),v.end());
	int ans = INF;
	for(int i=0;i<v.size();i++){
		int cnt = 0;
		int pc = 0;
		priority_queue<int,vector<int>,greater<int> >p,q;
		for(int j=0;j<N;j++){
			if(A[j]<v[i]){
				if(cnt>=K){
					for(int k=0;k<=cnt-K;k++){
						p.push(q.top());
						q.pop();
					}
					pc += cnt-K+1;
				}
				while(!q.empty())q.pop();
				cnt = 0;
			}else{
				q.push(A[j]);
				cnt++;
			}
		}
		if(cnt>=K){
			for(int j=0;j<=cnt-K;j++){
				p.push(q.top());
				q.pop();
			}
			pc += cnt-K+1;
		}
		if(pc<Q)continue;
		for(int j=0;j<Q-1;j++)p.pop();
		//cout << v[i] << ' ' << p.top() << endl; 
		ans = min(ans,p.top()-v[i]);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<string.h>
#include<algorithm>
using namespace std;

string str;
int n;
bool vis[200];
bool tmp[200];
int main()
{
    cin>>n;
    cin>>str;
    int ans=0;
    for (int i=0; i<=n; i++)
    {
        string str1=str.substr(0,i);
        string str2=str.substr(i,n-i);
        memset(vis,false,sizeof(vis));
        memset(tmp,false,sizeof(tmp));
        int len1=str1.length();
        int len2=str2.length();
        int sum=0;
        for (int i=0; i<len1; i++)
        {
            vis[str1[i]-'0']=true;
        }
        for (int i=0; i<len2; i++)
        {
            if (vis[str2[i]-'0'])
            {
                if (!tmp[str2[i]-'0'])
                {
                    sum++;
                    tmp[str2[i]-'0']=true;
                }
            }
        }
        ans=max(ans,sum);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
    string S, T;
    cin >> S >> T;
    int A, B;
    cin >> A >> B;
    string U;
    cin >> U;
    if(U == S) A--;
    else B--;
    cout << A << " " << B << "\n";
    return 0;
}


Measured memory_bytes: 256
use std::io::Read;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

    println!("{}", answer);
}

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    let n: usize = iterator.next().unwrap().parse().unwrap();
    let m: usize = iterator.next().unwrap().parse().unwrap();

    let ans = comb(n, 2) + comb(m, 2);
    return ans.to_string();
}

fn comb(mut n: usize, mut r: usize) -> usize {
    if n < r {
        return 0;
    }
    let mut numerator = 1;
    let mut denominator = 1;
    while r > 0 {
        numerator *= n;
        denominator *= r;
        n -= 1;
        r -= 1;
    }
    return numerator / denominator;
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
int main()
{
  long long n,k;cin>>n>>k;
  vector<long long>h(n);
  for(int i=0;i<n;i++)cin>>h[i];
  sort(h.begin(),h.end());
  long long ans=0;
  for(int i=0;i<n-k;i++){
    while(h[i]!=0){
      h[i]--;
      ans++;
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 1792
/*
*          Name : chaitanya
*
*     Institute : ANITS,Visakhapatnam
*
*/
#include<cstdio>
#include<iostream>
#include<sstream>
#include<fstream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<complex>
#include<cstring>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<numeric>
#include<limits>
#include<climits>
#include<cfloat>
#include<functional>
#include<iterator>
#include <random>
#define inf  1000000000
const long long int N = 6999999;
#define all(x) begin(x),end(x)
#define ll long long int
const ll mod = 1000000007;
#pragma GCC optimization ("O3")
using namespace std;

int main()
{
 
  // freopen("input.txt","r",stdin);
  // freopen("output.txt","w",stdout);
  //ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  ll n,m,c=mod,a;
  cin >> n >> m;
  a =  n%m;
  a = min(a,abs(m-a));
  cout << a;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<queue>

using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int> >;
using pii = pair<int, int>;
using ppi = pair<pii, int>;

int main(){
  ll n; cin >> n;
  ll k; cin >> k;
  vector<ll> a(n);
  for(int i = 0; i < n; i++) cin >> a[i];

  auto solve = [=](ll t){
    ll ret = 0;
    for(int i = 0; i < n; i++){
      ret += (ll)ceil((double)a[i]/(double)t) - 1;
    }
    return ret;
  };

  ll ok = *max_element(a.begin(), a.end());
  ll ng = 0;
  ll now = 0;

  while(ok - ng > 1){
    now = (ng + ok) / 2;
    if(solve(now) <= k){
      ok = now;
    }
    else{
      ng = now;
    }
  }
  cout << ok << endl;
}


Measured memory_bytes: 6320
n = int(input())
a = list(map(int, input().split()))

all_ = sum(a)

x1 = all_ - 2 * (sum([a[i] for i in range(1, n, 2)]))
x = [x1]

for i in range(1, n):
  x_i = 2 * a[i-1] - x[i-1]
  x.append(x_i)

print(' '.join(list(map(str, x))))


Measured memory_bytes: 19088
n=int(input())
lists=list(map(int,input().split()))
lists.insert(0,0)
anslists=[0]*(n+1)
for j in range(n,0,-1):
# j=n,n-1,.......,2,1という感じ
    numbers=n//j
    if numbers==1:
        anslists[j]=lists[j]
    else:
        check=0
        for i in range(2,numbers+1):
            check+=anslists[i*j]
            
        if check%2==0:
            anslists[j]=lists[j]
            
        else:
            
            if lists[j]==1:
                anslists[j]=0
                
            if lists[j]==0:
                anslists[j]=1
                

printA=0

del anslists[0]


Anslist=[]
for k in range(n):
    if anslists[k]==1:
        printA+=1
        Anslist.append(k+1)
print(printA)
print(*Anslist)  

Measured memory_bytes: 14132
#include <stdio.h>

int main(void){
    int i=1;
    while(1){
        int x;
        scanf("%d", &x);
        if(x == 0){
            break;
        }
        printf("Case %d: %d\n",i,x);
        i = i+1;
    }
    return 0;
}


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

typedef long long ll;
typedef pair<ll, ll> pll;

#define m0(x) memset(x, 0, sizeof(x))
#define all(x) x.begin(), x.end()
#define rep(i, n) for(int i = 0; i < (n); i++)
#define asort(x) sort(all(x));
#define dsort(x, t) sort(x.begin(), x.end(), greater<t>());
#define vuni(v) v.erase(unique(v.begin(), v.end()), v.end());
#define mins(m, s) m.insert(make_pair(s, 1));
#define mfin(m, s) m.find(s) != m.end()

#define dump(x)  cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO" ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No" ) << endl

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

int main(){
    int n, a, b;
    cin >> n >> a >> b;
    int ans = a * n;
    if(ans > b){
        cout << b << endl;
    }else{
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 3636
from collections import defaultdict

h, w = map(int, input().split())
a = [list(input()) for _ in range(h)]

cnt = defaultdict(int)
for i in range(h):
    for j in range(w):
        cnt[a[i][j]] += 1

flag1 = w % 2
flag2 = h % 2
even = h * flag1 + w * flag2 - flag1 * flag2 * 2
odd = flag1 * flag2

ans = True
for k, v in cnt.items():
    even -= ((v % 4) // 2) * 2
    odd -= v % 2
    if even < 0 or odd < 0:
        ans = False
        break

print("Yes" if ans else "No")


Measured memory_bytes: 3444
#include<bits/stdc++.h>
using namespace std;
int main(void){
	int a,b,c,d,e;
	cin>>a>>b>>c>>d>>e;
	int sum=0;
	if(a<=0){
		int x=0-a;
		sum+=x*c;
		sum+=d;
		sum+=b*e;
	}
	else{
		sum+=(b-a)*e;
	}
	cout<<sum<<endl;;
	return 0;
}


Measured memory_bytes: 3124
n = int(input())

a = list(map(int, input().split())) #i_1 i_2を取得し、iに値を入れる
b = list(map(int, input().split()))
c = list(map(int, input().split()))

ans = sum(b)
#print(ans)
for i in range(0,n-1):
    #print(i)
    if a[i+1] == (a[i] + 1):
        ans = ans + c[a[i]-1]
print(ans)


Measured memory_bytes: 3060
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)

int main() {
  string s;
  cin >> s;
  if (s.substr(0, 4) == "YAKI")
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
map<int,int> e;	//<end,start>

bool insert(int x){
	//  <0>
	if(e.find(0)!=e.end())return false;

	auto itr = e.lower_bound(x);
	bool touchleft = (e.find(x-1)!=e.end());

	if(itr==e.end()){
		//  <  >X]
		if(touchleft){
			e[x]=e[x-1];
			e.erase(x-1);
		}
		//  __X__]
		else e[x]=x;
		return true;
	}
	
	//  <left    right>
	int left=itr->second, right=itr->first;

	//  0<__X__ >  or  0<  X>  <  >
	if(left==1 && (x<right || (int)e.size()>1)) return false;

	if(left<=x){
		//  <   X>
		if(x==right)e.erase(itr);
		//  <__X >
		else e[right] = x+1;
		return insert(left-1);
	}

	// __X__<  >
	e[x]=x;

	// <  >X__<  >
	if(touchleft){
		e[x]=e[x-1];
		e.erase(x-1);
	}	

	//  X<  >
	if(x==left-1){
		e[right] = e[x];
		e.erase(x);
	}
	return true;
}

int main(void){
	int n,x;
	cin>>n;
	while(n--){
		cin>>x;
		if(insert(x))cout<<"Yes"<<endl;
		else cout<<"No"<<endl;
	}
	return 0;
}

Measured memory_bytes: 9884
n=int(input())
ans=[]

def dfs(i,c,d):
	if i==n:
		ans.append(c)
		return
	for j in range(0,d+1):
		dfs(i+1,c+chr(97+j),d+(j==d))

dfs(0,"",0)

print("\n".join(ans))

Measured memory_bytes: 15128
#include <stdio.h>
#include <string.h>

int main(void){
    char s[100];
    scanf("%s",s);
    int n;
    n=strlen(s);
    // 1
    int i;
    for(i=0;i<n/2;i++){
        if(s[i]!=s[n-i-1]){
            printf("No\n");
            return 0;
        }
    }

    // 2
    for(i=0;i<(n-1)/4;i++){
        if(s[i]!=s[(n-1)/2-i-1]){
            printf("No\n");
            return 0;
        }
    }

    // 3
    for(i=0;i<(n-1)/4;i++){
        if(s[((n+3)/2)-1+i]!=s[n-1-i]){
            printf("No\n");
            return 0;
        }
    }

    printf("Yes\n");
    return 0;
}

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

#ifdef NON_SUBMIT
#define TEST(n) (n)
#define tout cerr
#else
#define TEST(n) ((void)0)
#define tout cin
#endif

using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	TEST(freopen("input.txt","r",stdin));
	TEST(freopen("output.txt","w",stdout));
	TEST(freopen("debug.txt","w",stderr));
	string s;
	cin>>s;
	for(auto &c: s) if(c=='?') c='D';
	cout<<s<<'\n';
	return 0;
}

Measured memory_bytes: 3780
# coding: utf-8
# Your code here!
a = list(map(int,input().split()))
b = list(map(int,input().split()))
b.sort()

c = []
if len(b) != 1:
  for i in range(len(b) - 1):
    c.append(b[i+1] - b[i])

if len(b) == 1:
  print(0)
  
    
else:  
  c.sort()
  for j in range(min(a[0] - 1,a[1])):
    c[len(c)- 1 - j] = 0
  print(sum(c))



Measured memory_bytes: 13968
import java.util.*;
import java.io.*;

public class Main {
    static class FS {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer("");

        String next() {
            while (!st.hasMoreTokens())
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        int[] readArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = nextInt();
            return a;
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        public long[] readLongArray(int n) {
            long[] a = new long[n];
            for (int i = 0; i < n; i++)
                a[i] = nextLong();
            return a;
        }
    }

    static final FS sc = new FS();
    static final PrintWriter out = new PrintWriter(System.out);
    static final int mod = 1000000007;

    public static void main(String[] args) {
        int n = sc.nextInt();
        if (n >= 30) {
            out.println("Yes");
        } else {
            out.println("No");
        }
        out.close();
    }
}


Measured memory_bytes: 32864
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <iterator>
#pragma warning(disable:4996)
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define MOD 1000000007
using namespace std;

 
int main(int argc, char* argv[])
{
    long n, a;
    scanf("%ld", &n);
    scanf("%ld", &a);

    if(n%500<=a) {
        printf("Yes\n");
    }
    else {
        printf("No\n");
    }
 
    return 0;
}


Measured memory_bytes: 128
s = input()
q = int(input())
for i in range(q):
    inp = input().split()
    order = inp[0]
    params = inp[1:]
    if order == "print":
        a,b = map(int,params)
        print(s[a:b+1])
    elif order == "reverse":
        a,b = map(int,params)
        s = s[:a] + s[a:b+1][::-1] + s[b+1:]
    elif order == "replace":
        a,b,p = params
        a = int(a)
        b = int(b)
        s = s[:a] + p  + s[b+1:]

Measured memory_bytes: 7712
#include <bits/stdc++.h>
#define rep(a,n) for (int a = 0; a < (n); ++a)
using namespace std;
using ll = long long;
typedef pair<int,int> P;
typedef pair<ll,P> PP;
typedef vector<vector<int> > Graph;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll INF = 1e18;

// auto mod int
// depends on Template

const int mod = 1000000007;
//const int mod = 998244353;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

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

//input
ll n;

int main(){
    cin >> n;
    ll k=-1;
    for(int i=1;i*(i-1)<=2*n;i++){
        if(i*(i-1)==2*n){
            k=i;
        }
    }
    if(k==-1){
        cout << "No" << endl;
        return 0;
    }
    cout << "Yes" << endl;
    cout << k << endl;
    int id=1;
    vector<vector<ll> >ans(k);
    rep(i,k){
        for(int j=0;j<i;j++){
            ans[i].push_back(ans[j][i-1]);
        }
        rep(j,k-1-i){
            ans[i].push_back(id++);
        }
    }
    rep(i,k){
        cout << k-1 << ' ';
        rep(j,k-2){
            cout << ans[i][j] << ' ';
        }
        cout << ans[i][k-2] << endl;
    }

    return 0;
}



Measured memory_bytes: 4868
import math

# インプットデータを受け取る
a, b, c = map(float, input().split())

# 面積Sを求める
S = a * b * math.sin(math.radians(c)) / 2
print(S)

# 周の長さLを求める
L = a + b + math.sqrt(a ** 2 + b ** 2 - (2 * a * b * math.cos(math.radians(c))))
print(L)

# 高さhを求める
h = b * math.sin(math.radians(c))
print(h)



Measured memory_bytes: 5692
#include <iostream>
#include <vector>
#include <algorithm>
#define INF 1000000000;
using namespace std;
int n,m,a[11];
vector <int> coin;
int used[11];
void mk_coin(int sum,int k){
  for(int i=k;i<n;i++) {
    if(used[i]==1) continue;
    used[i]=1;
    coin.push_back(sum+a[i]);
    mk_coin(sum+a[i],i+1);
    used[i] = 0;
  }
}

int main() {
  while(1){
    cin >> n >> m;
    if(n==0&&m==0) break;
    coin.clear();
    for(int i=0;i<n;i++)cin >> a[i];
    mk_coin(0,0);
    
    int dp[100010]={};
    for(int i=1;i<=m;i++) dp[i] = INF;
    for(int i=0;i<coin.size();i++)
      for(int j=0;j<=m-coin[i];j++) dp[j+coin[i]] = min(dp[j]+1,dp[j+coin[i]]); 
    cout <<dp[m]<<endl;
  }
  return 0;
}

Measured memory_bytes: 1616
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <string>
#include <stdio.h>
#include <bits/stdc++.h>
using namespace std;

int main()
{
    long double a, b, h, m, ans, rad;
    cin >> a >> b >> h >> m;
    rad = (60 * h - 11 * m ) * M_PI * 2 / 720;
    ans = sqrt(pow(a, 2) + pow(b, 2) - 2.0 * a * b * cos(rad));
    cout << setprecision(10) << double(ans) << endl;
    return 0;
}

Measured memory_bytes: 4172
#include<bits/stdc++.h>
//#include<bits/extc++.h>
//using namespace __gnu_pbds;
using namespace std;
#define F(i,L,R) for (int i = L; i < R; i++)
#define FE(i,L,R) for (int i = L; i <= R; i++)
#define getI(a) scanf("%d", &a)
#define getII(a,b) scanf("%d%d", &a, &b)
#define getIII(a,b,c) scanf("%d%d%d", &a, &b, &c)
#define VgetI(n) int (n); scanf("%d",&(n))
#define VgetII(n,m) int (n),(m); scanf("%d %d",&(n),&(m))
#define VgetIII(n,m,k) int (n),(m),(k); scanf("%d %d %d",&(n),&(m),&(k))
#define pb push_back
#define pii pair<int,int>
#define ll long long
#define INF 2000000000
#define PI 3.1415926535897932384626
const ll MOD=1e9+7;
int main(){
        int a,b;
        while(~getII(a,b)){
                ll product=(ll)a*b;
                printf("%lld\n",product/__gcd(a,b));
        }
}

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

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

  int number = a * 100 + b * 10 + c;

  if (number % 4 == 0) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
}


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

using namespace std;
using ll=long long;
using ull=unsigned long long;
using pii=pair<int,int>;

#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()
#define endl "\n"

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

  int H,W;
  cin>>H>>W;
  vector<string>s(H);
  for(int i=0;i<H;i++)cin>>s[i];
  vector<vector<int>>dp(H,vector<int>(W,INT_MAX));
  if(s[0][0]=='#')dp[0][0]=1;
  else dp[0][0]=0;
  int dx[2]={0,-1};
  int dy[2]={-1,0};
  for(int y=0;y<H;y++){
    for(int x=0;x<W;x++){
      if(x==0&&y==0)continue;
      for(int k=0;k<2;k++){
        int nx=x+dx[k];
        int ny=y+dy[k];
        if(0<=nx&&nx<W&&0<=ny&&ny<H){
          if(s[y][x]=='.')dp[y][x]=min(dp[ny][nx],dp[y][x]);
          else if(s[y][x]=='#'&&s[ny][nx]=='#')dp[y][x]=min(dp[ny][nx],dp[y][x]);
          else if(s[y][x]=='#'&&s[ny][nx]=='.')dp[y][x]=min(dp[ny][nx]+1,dp[y][x]);
        }
      }
    }
  }


  cout<<dp[H-1][W-1]<<endl;
  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0;i<n;i++)
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (b>a) { 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 long long INF = 2LL << 60;
using ll = long long;
using P = pair<ll, ll>;

int main(int argc, char const *argv[]) {
    int n, k, c;
    string s;
    cin >> n >> k >> c >> s;
    vector<int> v(k), r(k);
    int idx=0;
    for(int i=0;i<n&&idx<k;i++){
        if(s[i]=='o'){
            v.at(idx)=i;
            idx++;
            i+=c;
        }
    }
    idx=k-1;
    for(int i=n-1;i>=0&&idx>=0;i--){
        if(s[i]=='o'){
            r.at(idx)=i;
            idx--;
            i-=c;
        }
    }
    rep(i,k){
        if(v.at(i)==r.at(i)){
            cout << v.at(i)+1 << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 3332
#include <cstdio>
#include <cstring>
#define ele long long
using namespace std;
int main(){
	ele x,y;
	scanf("%lld%lld",&x,&y);
	ele ans=0;
	for (; x<=y; x<<=1,++ans);
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 128
import java.util.*;

public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		if(A == B) {
			System.out.println("Draw");
			return;
		}
		if(A == 1) {
			System.out.println("Alice");
			return;
		}
		if(B == 1) {
			System.out.println("Bob");
			return;
		}
		if(A > B) {
			System.out.println("Alice");
		} else {
			System.out.println("Bob");
		}
	}
}


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

int main()
{
  ll n;
  cin >> n;
  
  map<ll,ll> a, b;

  REP(i, n)
  {
    ll h;
    cin >> h;
    a[i+h+1]++;
    b[i-h+1]++;
  }
  ll ans = 0;
  for(auto itr : a)
  {
    ans += b[itr.first] * itr.second;
  }
  
  cout << ans << endl;
  return 0;
}

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    string s, t;
    cin >> s >> t;

    if (t.substr(0, s.length()) == s)
        cout << "Yes\n";
    else
        cout << "No\n";

    return 0;
}


Measured memory_bytes: 3636
n,y=[int(i) for i in input().split()]
A=-1
B=-1
C=-1
for a in range(n+1):
  for b in range(n-a+1):
      Y=1000*a+5000*b+10000*(n-a-b)
      if Y==y:
        c=n-a-b
        A=c
        B=b
        C=a
        break
print(A,B,C)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int k=0,r=0,c=0 ,r2=1;
  cin >> k >> r;
while(1){
    c++;
    r2=r2*r;
    if(k<r2){
        cout << c << endl;
        break;
    }
    
}
  
}

Measured memory_bytes: 256
from collections import defaultdict

N, M = map(int, input().split())
edges = defaultdict(set)

for _ in range(M):
    a, b = map(lambda x:int(x)-1, input().split())
    edges[a].add(b)
    edges[b].add(a)

ans = 0
visited = [False] * N

def dfs(i):
    stack = [i]
    ans = 0
    while stack:
        i = stack.pop()
        if visited[i]:
            continue
        ans += 1
        visited[i] = True
        for dest in edges[i]:
            stack.append(dest)
    return ans

for i in range(N):
    ans = max(ans, dfs(i))
print(ans)



Measured memory_bytes: 177576
//Author - Soumik Roy
//Date & Time - September 19, 2020 6:01 PM
//Problem name - A - Plural Form
//Problem url - https://atcoder.jp/contests/abc179/tasks/abc179_a
//Time limit - 2000 ms
//Memory Limit - 1024 MB    
//Parsed with ai-virtual-assistant https://github.com/Saurav-Paul/AI-virtual-assistant-python
#include<bits/stdc++.h>
#define ll                    long long int
#define pb                    push_back
#define F                     first
#define S                     second
#define mp                    make_pair
#define MOD                   1000000007
#define vi                    vector<int>
#define vll                   vector<ll>
#define pll                   pair<ll,ll>
#define pii                   pair<int,int>
#define all(p)                p.begin(),p.end()
#define mid(s,e)              (s+(e-s)/2)
#define eb                    emplace_back
#define ull                   unsigned long long
#define bug(x)				  cout<<"  [ "#x<<" = "<<x<<" ]"<<endl;
#define KAMEHAMEHA            ios_base::sync_with_stdio(0);
#define RASENGAN              ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
int dir[]={0,1,0,-1,1,0,-1,0};
void solve()
{
	string s;
	cin>>s;
	int sz=(int)s.size();
	if(s[sz-1]=='s')
		s+="es";
	else
	{
		s+='s';
	}
	cout<<s<<endl;
}
int main()
{
    KAMEHAMEHA
	int t=1;
	//cin>>t;
	for(int cn=1;cn<=t;cn++)
	{
		solve();
	}
    return 0;
}



Measured memory_bytes: 3652
import           Control.Monad

main :: IO ()
main = do
    [n, _, c] <- fmap (map read . words) getLine :: IO [Int]
    bs        <- fmap (map read . words) getLine :: IO [Int]
    ass       <- replicateM n $ fmap (map read . words) getLine :: IO [[Int]]
    print $ solve c bs ass

solve :: Int -> [Int] -> [[Int]] -> Int
solve c bs ass = length $ filter (judge c bs) ass

judge :: Int -> [Int] -> [Int] -> Bool
judge c bs as = prod bs as + c > 0

prod :: [Int] -> [Int] -> Int
prod bs as = sum $ zipWith (*) bs as


Measured memory_bytes: 1020
#include <cstdio>

const int N=202;
int a[N],mx=-1,t;
long long n;

int main(){
	scanf("%lld",&n);
	for(int i=40;~i;--i)
		if((n>>i)&1)
			if(~mx)a[i]=mx+(++t);
			else mx=i;
	printf("%d\n",mx+mx+2+t+t);
	if(a[0])printf("%d ",a[0]);
	for(int i=1;i<=mx;++i){
		printf("%d ",i);
		if(a[i])printf("%d ",a[i]);
	}
	for(int i=1;i<=mx+t;++i)printf("%d ",i);
	printf("%d %d\n",mx+t+1,mx+t+1);
}

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

using namespace std;

typedef long long ll;
typedef long double Double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

// chmax, chmin
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;
}

void solve(long long A, long long B, long long C, long long D, long long E,
           long long F) {

    double answer = -1;
    int ans1 = A;
    int ans2 = A;

    rep(a, 31) {
        rep(b, 31) {
            rep(c, 3001) {
                int dMax = F - (a * A * 100 + b * B * 100 + c * C);
                dMax = min<int>(dMax, E * (a * A * 100 + b * B * 100) / 100 - c * C);
                if (dMax >= 0) {
                    int d = dMax / D;
                    int S = d * D + c * C;
                    int W = a * A * 100 + b * B * 100;
                    double sub = 1. * S / (S+W);
                    if( answer < sub ){
                        answer = sub;
                        ans1 = S + W;
                        ans2 = S;
                    }
                }
            }
        }
    }
    cout << ans1 << " " << ans2 << endl;
}

int main() {
    long long A;
    scanf("%lld", &A);
    long long B;
    scanf("%lld", &B);
    long long C;
    scanf("%lld", &C);
    long long D;
    scanf("%lld", &D);
    long long E;
    scanf("%lld", &E);
    long long F;
    scanf("%lld", &F);
    solve(A, B, C, D, E, F);
    return 0;
}


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

int main(){

int a,b,c,t;

cin >> a>>b>>c;

if(a>b){t=a; a=b; b=t;}
if(b>c){t=b; b=c; c=t;}
if(a>b){t=a; a=b; b=t;} 

cout<<a<<" "<<b<<" "<<c<<endl; 

return 0;

}



Measured memory_bytes: 3084
#include<bits/stdc++.h>
#define ll long long
#define here cout<<"here\n"
#define pb push_back
#define mp make_pair
#define si(x) scanf("%d",&x)
#define sl(x) scanf("%lld",&x)
#define pf printf
#define pfi(x) printf("%d\n",x)
#define pfl(x) printf("%lld\n",x)
using namespace std;

const ll mod = 1e9+7;

const int MAX = 100005;

ll modexp(ll x, ll n)
{
    if(n==0)
        return 1LL;
    if(n%2==0)
    {
        ll y = modexp(x,n/2)%mod;
        return (y*y)%mod;
    }
    return (x*modexp(x,n-1)%mod)%mod;
}

ll powr(ll x, ll n)
{
    ll ans = 1;
    for(int i=1;i<=n;i++)
        ans=ans*x;
    return ans;
}

int main()
{

    int n,k;
    si(n),si(k);
    int a[n];
    for(int i=0;i<n;i++)
        si(a[i]);
    int dp[n];
    for(int i=0;i<n;i++)
        dp[i] = mod;
    dp[0] = 0;
    for(int i=0;i<n;i++)
    {
        for(int j=i+1;j<min(n,i+k+1);j++)
        {
            dp[j] = min(dp[j],dp[i]+abs(a[j]-a[i]));
        }
        // cout<<dp[i]<<endl;
    }
    pfi(dp[n-1]);
    return 0;
}

Measured memory_bytes: 1024
#pragma GCC optimize("O3")
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;
using base = complex<double>;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define M 1000000007
#define M2 998244353
#define ll long long
#define pll pair<long, long>
#define REP(i, a, b) for (ll i = a; i < b; i++)
#define REPI(i, a, b) for (ll i = b - 1; i >= a; i--)
#define ff first
#define ss second
#define pb push_back
#define db pop_back
#define mp make_pair
#define mt make_tuple
#define g(a, b) get<a>(b)
#define INF (ll)1e18 + 100
#define vl vector<ll>
#define vi vector<int>
#define vll vector<pair<ll, ll>>
#define vii vector<pair<int, int>>
#define all(v) v.begin(), v.end()
#define bset(a, p) ((a) | (1ll << (p)))
#define bchk(a, p) ((a) & (1ll << (p)))
#define bxor(a, p) ((a) ^ (1ll << (p)));
#define brem(a, p) (bchk(a, p) ? (bxor(a, p)) : (a))
#define INT_SIZE 32

void solve() {
	ll n;
	cin >> n;
	vl v(n);
	ll s = 0;
	REP(i, 0, n) {
		cin >> v[i];
		s += v[i];
	}
	ll m;
	cin >> m;
	while (m--) {
		ll p , x;
		cin >> p >> x;
		p--;
		cout << s + (x - v[p]) << "\n";
	}
}

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
	ll ntc;
	// cin >> ntc;
	ntc = 1;
	REP(tc, 1, ntc + 1)
	{
		// cout << "Case #" << tc << ": ";
		solve();
	}
}

Measured memory_bytes: 3600
#include<iostream>
#include<algorithm>
 
using namespace std;
  
int main(){
    int a[10];
    for(int i=0;i<10;i++){
        cin>>a[i];
    }
    sort(a,a+10);
 
    cout<<a[9]<<endl<<a[8]<<endl<<a[7]<<endl;
 
}
 

Measured memory_bytes: 1176
#include <iostream>
#include <iomanip>
// std::cout << std::setprecision(2) << 3.141; // "3.1"
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <map>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef pair<double, ll> pdlg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef tuple<double, double, double> tddd;

static const int giga = pow(10,9);
// double pi = 3.141592653589793238463;

int main(void){
  int n,k;
  cin >> n >> k;
  int ans = 1;
  for(int i = 0; i < n; i++){
    if(ans + k > ans * 2){
      ans *= 2;
    } else {
      ans += k;
    }
  }

  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
n,m,c=[int(i) for i in input().split()]
b=[int(i) for i in input().split()]
ans=0
for i in range(n):
    a=[int(i) for i in input().split()]
    total=c
    for j in range(m):
        total+=a[j]*b[j]
    if total>0:
        ans+=1
print(ans)

Measured memory_bytes: 3060
#include<cmath>
#include<iomanip>
#include<iostream>

using namespace std;

int main() {
	int count;
	bool inputOver = false;
	while (!inputOver) {
		cin >> count;
		if (count) {
			int *list = new int[count];
			double sum = 0.0;
			for (int i = 0; i < count; i++) {
				int temp;
				cin >> temp;
				list[i] = temp;
				sum += temp;
			}

			double mid = sum/count;
			sum = 0.0;
			
			for (int i = 0; i < count; i++) {
				sum += pow(list[i] - mid, 2);
			}
			sum = sum / count;
			cout.setf(ios::fixed);
			cout << setprecision(8) << sqrt(sum) << endl;

			delete[] list;
		}
		else {
			inputOver = true;
			break;
		}

	}


	return 0;
}

Measured memory_bytes: 3256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <bitset>
typedef long long ll;
#define rep(i,n) for(int i = 0;i<n;++i)
#define repnc(bit,k,n) for (int bit = (1<<k)-1;bit < (1<<n); bit = next_combination(bit))
#define repi(itr,vec) for(auto itr = vec.begin();itr!=vec.end();++itr)
using namespace std;

/* next combination */
int next_combination(int sub) {
  int x = sub & -sub, y = sub + x;
  return (((sub & ~y) / x) >> 1) | y;
}

long str2long(string S, int beg, int end){
  //cout << S.substr(beg+1,end-beg)<<'\n';
  return stol(S.substr(beg+1,end-beg));
}
int main(){
        ios::sync_with_stdio(false);
        cin.tie(nullptr);
  string S;
  cin >> S;
  int n = S.length();
  long ans = 0;
  rep(bit, 1<<n-1){
    int beg=-1;
    int end;
    rep(i, n-1){
      if(bit&1<<i){
        end = i;
        ans+=str2long(S,beg,end);
        beg = i;
      }
    }
    ans+=str2long(S,beg,n);
  }
  cout << ans << '\n';
        return 0;
}

Measured memory_bytes: 3124
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)

int main(){
  int a,b;
  cin >> a >> b;
  
  if(a+b>=10) cout << "error" << endl;
  else cout << a+b << endl;
  return 0;

}


Measured memory_bytes: 256
import heapq as hp

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

B = []
for a in A:
    hp.heappush(B, a)

ans = 1
for _ in range(N-1):
    ans += 1
    a1 = hp.heappop(B)
    a2 = hp.heappop(B)
    if a1*2 < a2:
        ans = 1
    hp.heappush(B, a1+a2)
print(ans)

Measured memory_bytes: 14316
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int m,d,cnt=0;
	cin >> m >> d;
	for(int i=1;i<=m;i++){
		for(int j=1;j<=d;j++){
			int a=j/10;
			int b=j%10;
			if(i==a*b&&a!=1&&b!=1){
				//printf("%d %d%d\n",i,a,b);
				cnt++;
			}
		}
	}
	cout << cnt << endl;
	return 0;
}


Measured memory_bytes: 256